Skip to content

Commit

Permalink
Fix Save State Slots menu crash (#526)
Browse files Browse the repository at this point in the history
* Update options.rs

* Update save_states.rs

* Update options.rs
  • Loading branch information
jugeeya authored Apr 29, 2023
1 parent 9b9070c commit dbfa60b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/training/save_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ unsafe fn get_slot() -> usize {
if MENU.randomize_slots == OnOff::On {
RANDOM_SLOT
} else {
MENU.save_state_slot as u32 as usize
MENU.save_state_slot.as_idx() as usize
}
}

Expand Down Expand Up @@ -594,8 +594,8 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor)
{
// Don't begin saving state if Nana's delayed input is captured
MIRROR_STATE = 1.0;
save_state_player(MENU.save_state_slot as u32 as usize).state = Save;
save_state_cpu(MENU.save_state_slot as u32 as usize).state = Save;
save_state_player(MENU.save_state_slot.as_idx() as usize).state = Save;
save_state_cpu(MENU.save_state_slot.as_idx() as usize).state = Save;
notifications::clear_notifications("Save State");
notifications::notification(
"Save State".to_string(),
Expand Down
14 changes: 9 additions & 5 deletions training_mod_consts/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,11 +1112,11 @@ impl_serde_for_bitflags!(SaveDamage);
Debug, Clone, Copy, PartialEq, FromPrimitive, EnumIter, Serialize_repr, Deserialize_repr,
)]
pub enum SaveStateSlot {
One = 0,
Two = 1,
Three = 2,
Four = 3,
Five = 4,
One = 0x0,
Two = 0x1,
Three = 0x2,
Four = 0x4,
Five = 0x8,
}

impl SaveStateSlot {
Expand All @@ -1129,6 +1129,10 @@ impl SaveStateSlot {
SaveStateSlot::Five => "5",
})
}

pub fn as_idx(self) -> u32 {
log_2(self as i32 as u32)
}
}

impl ToggleTrait for SaveStateSlot {
Expand Down

0 comments on commit dbfa60b

Please sign in to comment.