parent
c8f485cd93
commit
93bf103f03
1
build.rs
1
build.rs
@ -174,7 +174,6 @@ fn main() {
|
||||
.allowlist_function("ra_state_size")
|
||||
.allowlist_function("ra_save_state")
|
||||
.allowlist_function("ra_load_state")
|
||||
.allowlist_function("ra_get_game_info")
|
||||
.allowlist_function("ra_get_rich_presence");
|
||||
|
||||
if cfg!(feature = "gui") {
|
||||
|
||||
@ -130,9 +130,12 @@ static void load_game_callback(int result, const char *error_message,
|
||||
notify_load_game(userdata);
|
||||
}
|
||||
|
||||
void ra_welcome() {
|
||||
if (!g_client)
|
||||
void ra_welcome(const char **game_title, const char **game_image_url) {
|
||||
if (!g_client) {
|
||||
*game_title = NULL;
|
||||
*game_image_url = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
char buffer[512];
|
||||
|
||||
@ -142,11 +145,16 @@ void ra_welcome() {
|
||||
rdp_onscreen_message(buffer, MESSAGE_LONG);
|
||||
free(error_message);
|
||||
rc_client_set_userdata(g_client, NULL);
|
||||
|
||||
*game_title = NULL;
|
||||
*game_image_url = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
const rc_client_game_t *game = rc_client_get_game_info(g_client);
|
||||
if (!game) {
|
||||
*game_title = NULL;
|
||||
*game_image_url = NULL;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -166,15 +174,7 @@ void ra_welcome() {
|
||||
"Game has no achievements");
|
||||
}
|
||||
rdp_onscreen_message(buffer, MESSAGE_LONG);
|
||||
}
|
||||
|
||||
void ra_get_game_info(const char **game_title, const char **game_image_url) {
|
||||
const rc_client_game_t *game = rc_client_get_game_info(g_client);
|
||||
if (!game) {
|
||||
*game_title = NULL;
|
||||
*game_image_url = NULL;
|
||||
return;
|
||||
}
|
||||
*game_title = game->title;
|
||||
*game_image_url = game->badge_url;
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
void ra_init_client(bool hardcore, bool challenge, bool leaderboard);
|
||||
void ra_shutdown_client();
|
||||
void ra_welcome();
|
||||
void ra_welcome(const char **game_title, const char **game_image_url);
|
||||
bool ra_get_hardcore();
|
||||
void ra_load_game(const uint8_t *rom, size_t rom_size, void *userdata);
|
||||
void ra_unload_game();
|
||||
@ -24,7 +24,6 @@ void ra_save_state(uint8_t *state, size_t state_size);
|
||||
void ra_load_state(const uint8_t *state, size_t state_size);
|
||||
|
||||
const char *ra_get_rich_presence();
|
||||
void ra_get_game_info(const char **game_title, const char **game_image_url);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@ -47,7 +47,12 @@ pub mod tlb;
|
||||
pub mod unmapped;
|
||||
pub mod vi;
|
||||
|
||||
pub fn run_game(device: &mut Device, rom_contents: &[u8], game_settings: ui::GameSettings) {
|
||||
pub async fn run_game(
|
||||
device: &mut Device,
|
||||
rom_contents: &[u8],
|
||||
game_settings: ui::GameSettings,
|
||||
discord_rich_presence: bool,
|
||||
) {
|
||||
device.cpu.overclock = game_settings.overclock;
|
||||
if game_settings.disable_expansion_pak {
|
||||
device.rdram.size = 0x400000;
|
||||
@ -69,7 +74,8 @@ pub fn run_game(device: &mut Device, rom_contents: &[u8], game_settings: ui::Gam
|
||||
ui::input::init(&mut device.ui);
|
||||
|
||||
// must be after video init
|
||||
retroachievements::welcome();
|
||||
let (discord_watch_tx, discord_handle) =
|
||||
retroachievements::load_game(rom_contents, rom_contents.len(), discord_rich_presence).await;
|
||||
|
||||
mi::init(device);
|
||||
pif::init(device);
|
||||
@ -93,7 +99,7 @@ pub fn run_game(device: &mut Device, rom_contents: &[u8], game_settings: ui::Gam
|
||||
|
||||
cpu::run(device);
|
||||
|
||||
retroachievements::unload_game();
|
||||
retroachievements::unload_game(discord_watch_tx, discord_handle).await;
|
||||
|
||||
ui::storage::write_saves(device);
|
||||
ui::input::close(&mut device.ui);
|
||||
|
||||
15
src/lib.rs
15
src/lib.rs
@ -216,13 +216,6 @@ pub async fn run() -> std::io::Result<()> {
|
||||
}
|
||||
}
|
||||
|
||||
let (discord_watch_tx, discord_handle) = retroachievements::load_game(
|
||||
&rom_contents,
|
||||
rom_contents.len(),
|
||||
args.discord_rich_presence,
|
||||
)
|
||||
.await;
|
||||
|
||||
device::run_game(
|
||||
&mut device,
|
||||
&rom_contents,
|
||||
@ -232,9 +225,11 @@ pub async fn run() -> std::io::Result<()> {
|
||||
cheats,
|
||||
load_savestate_slot: args.load_state,
|
||||
},
|
||||
);
|
||||
args.discord_rich_presence,
|
||||
)
|
||||
.await;
|
||||
|
||||
retroachievements::shutdown_client(discord_watch_tx, discord_handle).await;
|
||||
retroachievements::shutdown_client();
|
||||
|
||||
if device.netplay.is_some() {
|
||||
netplay::close(&mut device);
|
||||
@ -308,7 +303,7 @@ pub async fn run() -> std::io::Result<()> {
|
||||
{
|
||||
retroachievements::init_client(false, false, false);
|
||||
ui::gui::app_window();
|
||||
retroachievements::shutdown_client(None, None).await;
|
||||
retroachievements::shutdown_client();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -151,9 +151,11 @@ pub async fn load_game(
|
||||
ra_load_game(rom.as_ptr(), rom_size, tx_ptr);
|
||||
};
|
||||
rx.await.unwrap();
|
||||
|
||||
let mut c_title = std::ptr::null();
|
||||
let mut c_image_url = std::ptr::null();
|
||||
unsafe { ra_get_game_info(&mut c_title, &mut c_image_url) };
|
||||
unsafe { ra_welcome(&mut c_title, &mut c_image_url) };
|
||||
|
||||
if !discord_rich_presence || c_title.is_null() || c_image_url.is_null() {
|
||||
(None, None)
|
||||
} else {
|
||||
@ -175,14 +177,19 @@ pub async fn load_game(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn unload_game() {
|
||||
pub async fn unload_game(
|
||||
discord_watch_tx: Option<tokio::sync::watch::Sender<()>>,
|
||||
discord_handle: Option<tokio::task::JoinHandle<()>>,
|
||||
) {
|
||||
if let Some(discord_handle) = discord_handle
|
||||
&& let Some(discord_watch_tx) = discord_watch_tx
|
||||
{
|
||||
let _ = discord_watch_tx.send(());
|
||||
discord_handle.await.unwrap();
|
||||
}
|
||||
unsafe { ra_unload_game() };
|
||||
}
|
||||
|
||||
pub fn welcome() {
|
||||
unsafe { ra_welcome() };
|
||||
}
|
||||
|
||||
pub fn get_rich_presence() -> Option<String> {
|
||||
let c_rich_presence = unsafe { ra_get_rich_presence() };
|
||||
if c_rich_presence.is_null() {
|
||||
@ -213,16 +220,7 @@ pub fn init_client(hardcore: bool, challenge: bool, leaderboard: bool) {
|
||||
unsafe { ra_init_client(hardcore, challenge, leaderboard) };
|
||||
}
|
||||
|
||||
pub async fn shutdown_client(
|
||||
discord_watch_tx: Option<tokio::sync::watch::Sender<()>>,
|
||||
discord_handle: Option<tokio::task::JoinHandle<()>>,
|
||||
) {
|
||||
if let Some(discord_handle) = discord_handle
|
||||
&& let Some(discord_watch_tx) = discord_watch_tx
|
||||
{
|
||||
let _ = discord_watch_tx.send(());
|
||||
discord_handle.await.unwrap();
|
||||
}
|
||||
pub fn shutdown_client() {
|
||||
unsafe { ra_shutdown_client() };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user