1
0
Fork 0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2024-11-20 00:46:34 +00:00

Save State Random Slots, other bugfixes (#649)

* Fix UI function hook

* Save State Slot Changes

* Random Slots need a static >.<

* Cargo optimization changes

* fix early return (again)
This commit is contained in:
GradualSyrup 2023-10-06 22:18:38 -05:00 committed by GitHub
parent f34f2b0cbb
commit 82a0cf1d35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 40 deletions

View file

@ -48,6 +48,7 @@ nnsdk = { git = "https://github.com/ultimate-research/nnsdk-rs" }
[profile.dev]
panic = "abort"
lto = "off"
[profile.release]
panic = "abort"

View file

@ -759,7 +759,7 @@ pub unsafe fn handle_reused_ui(
mut param_2: u32, // In Little Mac's case, the meter value as an integer
) {
if !is_training_mode() {
original!()(fighter_data, param_2);
return original!()(fighter_data, param_2);
}
if save_states::is_loading() {

View file

@ -9,7 +9,7 @@ use smash::hash40;
use smash::lib::lua_const::*;
use smash::phx::{Hash40, Vector3f};
use std::ptr;
use training_mod_consts::{CharacterItem, SaveDamage};
use training_mod_consts::{CharacterItem, SaveDamage, SaveStateSlot};
use SaveState::*;
@ -229,7 +229,8 @@ static mut MIRROR_STATE: f32 = 1.0;
static mut RANDOM_SLOT: usize = 0;
unsafe fn get_slot() -> usize {
if MENU.randomize_slots == OnOff::On {
let random_slot = MENU.randomize_slots.get_random();
if random_slot != SaveStateSlot::empty() {
RANDOM_SLOT
} else {
MENU.save_state_slot.as_idx() as usize
@ -449,8 +450,9 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor)
}
if (autoload_reset || triggered_reset) && !fighter_is_nana {
if save_state.state == NoAction {
let slot = if MENU.randomize_slots == OnOff::On {
RANDOM_SLOT = get_random_int(NUM_SAVE_STATE_SLOTS as i32) as usize;
let random_slot = MENU.randomize_slots.get_random();
let slot = if random_slot != SaveStateSlot::empty() {
RANDOM_SLOT = random_slot.as_idx();
RANDOM_SLOT
} else {
selected_slot

View file

@ -54,7 +54,7 @@ pub struct TrainingModpackMenu {
pub save_state_autoload: OnOff,
pub save_state_enable: OnOff,
pub save_state_slot: SaveStateSlot,
pub randomize_slots: OnOff,
pub randomize_slots: SaveStateSlot,
pub save_state_mirroring: SaveStateMirroring,
pub save_state_playback: PlaybackSlot,
pub sdi_state: Direction,
@ -162,8 +162,8 @@ pub static DEFAULTS_MENU: TrainingModpackMenu = TrainingModpackMenu {
save_damage_limits_player: DamagePercent::default(),
save_state_autoload: OnOff::Off,
save_state_enable: OnOff::On,
save_state_slot: SaveStateSlot::One,
randomize_slots: OnOff::Off,
save_state_slot: SaveStateSlot::S1,
randomize_slots: SaveStateSlot::empty(),
save_state_mirroring: SaveStateMirroring::None,
save_state_playback: PlaybackSlot::empty(),
sdi_state: Direction::empty(),
@ -770,14 +770,14 @@ pub unsafe fn ui_menu(menu: TrainingModpackMenu) -> UiMenu {
"save_state_slot".to_string(),
"Save State Slot: Save and load states from different slots.".to_string(),
true,
&(menu.save_state_slot as u32),
&(menu.save_state_slot.bits() as u32),
);
save_state_tab.add_submenu_with_toggles::<OnOff>(
save_state_tab.add_submenu_with_toggles::<SaveStateSlot>(
"Randomize Slots".to_string(),
"randomize_slots".to_string(),
"Randomize Slots: Randomize slot when loading save state.".to_string(),
true,
&(menu.randomize_slots as u32),
"Randomize Slots: Slots to randomize when loading save state.".to_string(),
false,
&(menu.randomize_slots.bits() as u32),
);
save_state_tab.add_submenu_with_toggles::<CharacterItem>(
"Character Item".to_string(),

View file

@ -1359,50 +1359,62 @@ impl fmt::Display for SaveDamage {
extra_bitflag_impls! {SaveDamage}
impl_serde_for_bitflags!(SaveDamage);
/// Save State Slots
#[repr(i32)]
#[derive(
Debug, Clone, Copy, PartialEq, FromPrimitive, EnumIter, Serialize_repr, Deserialize_repr,
)]
pub enum SaveStateSlot {
One = 0x0,
Two = 0x1,
Three = 0x2,
Four = 0x4,
Five = 0x8,
// Save State Slots
bitflags! {
pub struct SaveStateSlot : u32
{
const S1 = 0x1;
const S2 = 0x2;
const S3 = 0x4;
const S4 = 0x8;
const S5 = 0x10;
}
}
impl SaveStateSlot {
pub fn as_idx(self) -> u32 {
log_2(self as i32 as u32)
pub fn into_idx(self) -> Option<usize> {
Some(match self {
SaveStateSlot::S1 => 0,
SaveStateSlot::S2 => 1,
SaveStateSlot::S3 => 2,
SaveStateSlot::S4 => 3,
SaveStateSlot::S5 => 4,
_ => return None,
})
}
pub fn as_idx(self) -> usize {
match self {
SaveStateSlot::S1 => 0,
SaveStateSlot::S2 => 1,
SaveStateSlot::S3 => 2,
SaveStateSlot::S4 => 3,
SaveStateSlot::S5 => 4,
_ => 0,
}
}
}
impl fmt::Display for SaveStateSlot {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let combination_string = self.combination_string();
write!(
f,
"{}",
match *self {
SaveStateSlot::One => "1",
SaveStateSlot::Two => "2",
SaveStateSlot::Three => "3",
SaveStateSlot::Four => "4",
SaveStateSlot::Five => "5",
SaveStateSlot::S1 => "1",
SaveStateSlot::S2 => "2",
SaveStateSlot::S3 => "3",
SaveStateSlot::S4 => "4",
SaveStateSlot::S5 => "5",
_ => combination_string.as_str(),
}
)
}
}
impl ToggleTrait for SaveStateSlot {
fn to_toggle_vals() -> Vec<u32> {
SaveStateSlot::iter().map(|i| i as u32).collect()
}
fn to_toggle_strings() -> Vec<String> {
SaveStateSlot::iter().map(|i| i.to_string()).collect()
}
}
extra_bitflag_impls! {SaveStateSlot}
impl_serde_for_bitflags!(SaveStateSlot);
// Input Recording Slot
#[repr(u32)]