mirror of
https://github.com/gopher64/gopher64.git
synced 2026-07-11 01:25:20 +02:00
use sized savestate functions (#730)
* use sized savestate functions * fix lint
This commit is contained in:
@@ -311,18 +311,20 @@ size_t ra_state_size() {
|
||||
return rc_client_progress_size(g_client);
|
||||
}
|
||||
|
||||
void ra_save_state(uint8_t *state) {
|
||||
void ra_save_state(uint8_t *state, size_t state_size) {
|
||||
if (!g_game_loaded)
|
||||
return;
|
||||
if (rc_client_serialize_progress(g_client, state) != RC_OK) {
|
||||
if (rc_client_serialize_progress_sized(g_client, state, state_size) !=
|
||||
RC_OK) {
|
||||
printf("RetroAchievements: Failed to serialize progress\n");
|
||||
}
|
||||
}
|
||||
|
||||
void ra_load_state(const uint8_t *state) {
|
||||
void ra_load_state(const uint8_t *state, size_t state_size) {
|
||||
if (!g_game_loaded)
|
||||
return;
|
||||
if (rc_client_deserialize_progress(g_client, state) != RC_OK) {
|
||||
if (rc_client_deserialize_progress_sized(g_client, state, state_size) !=
|
||||
RC_OK) {
|
||||
printf("RetroAchievements: Failed to deserialize progress\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,5 +19,5 @@ bool ra_is_user_logged_in();
|
||||
const char *ra_get_username();
|
||||
const char *ra_get_token();
|
||||
size_t ra_state_size();
|
||||
void ra_save_state(uint8_t *state);
|
||||
void ra_load_state(const uint8_t *state);
|
||||
void ra_save_state(uint8_t *state, size_t state_size);
|
||||
void ra_load_state(const uint8_t *state, size_t state_size);
|
||||
|
||||
@@ -301,10 +301,10 @@ pub fn state_size() -> usize {
|
||||
unsafe { ra_state_size() }
|
||||
}
|
||||
|
||||
pub fn save_state(state: *mut u8) {
|
||||
unsafe { ra_save_state(state) };
|
||||
pub fn save_state(state: *mut u8, state_size: usize) {
|
||||
unsafe { ra_save_state(state, state_size) };
|
||||
}
|
||||
|
||||
pub fn load_state(state: *const u8) {
|
||||
unsafe { ra_load_state(state) };
|
||||
pub fn load_state(state: *const u8, state_size: usize) {
|
||||
unsafe { ra_load_state(state, state_size) };
|
||||
}
|
||||
|
||||
+6
-2
@@ -74,7 +74,7 @@ pub fn create_savestate(device: &device::Device) {
|
||||
ui::video::save_state(rdp_state.as_mut_ptr());
|
||||
|
||||
let mut ra_state: Vec<u8> = vec![0; retroachievements::state_size()];
|
||||
retroachievements::save_state(ra_state.as_mut_ptr());
|
||||
retroachievements::save_state(ra_state.as_mut_ptr(), ra_state.len());
|
||||
|
||||
let data: &[(&[u8], &str)] = &[
|
||||
(&postcard::to_stdvec(device).unwrap(), "device"),
|
||||
@@ -207,7 +207,11 @@ pub fn load_savestate(device: &mut device::Device) {
|
||||
ui::audio::init_game_audio(&mut device.ui, device.ai.freq);
|
||||
ui::video::load_state(device, rdp_state.as_ptr());
|
||||
|
||||
retroachievements::load_state(ra_state.as_ptr());
|
||||
if !ra_state.is_empty() {
|
||||
retroachievements::load_state(ra_state.as_ptr(), ra_state.len());
|
||||
} else {
|
||||
retroachievements::load_state(std::ptr::null(), 0);
|
||||
}
|
||||
|
||||
if device.cheats.enabled {
|
||||
cheats::execute_cheats(device, device.cheats.cheats.clone());
|
||||
|
||||
Reference in New Issue
Block a user