diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index ec5d826a..e10c09d2 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -56,7 +56,7 @@ jobs: cache-all-crates: true - name: Install Skyline run: | - cargo install --git https://github.com/jugeeya/cargo-skyline --branch patch-3 --force + cargo install --git https://github.com/jam1garner/cargo-skyline --force cargo-skyline skyline update-std - name: Build release NRO id: build_release diff --git a/src/common/menu.rs b/src/common/menu.rs index 9541ef28..ecb5e6e3 100644 --- a/src/common/menu.rs +++ b/src/common/menu.rs @@ -64,11 +64,13 @@ pub fn set_menu_from_json(message: &str) { // Includes both MENU and DEFAULTS_MENU assign(&MENU, message_json.menu); assign(&DEFAULTS_MENU, message_json.defaults_menu); - fs::write( - MENU_OPTIONS_PATH, - serde_json::to_string_pretty(&message_json).unwrap(), - ) - .expect("Failed to write menu settings file"); + std::thread::spawn(move || { + fs::write( + MENU_OPTIONS_PATH, + serde_json::to_string_pretty(&message_json).unwrap(), + ) + .expect("Failed to write menu settings file"); + }); } else { skyline::error::show_error( 0x70, diff --git a/src/common/mod.rs b/src/common/mod.rs index 701cd74a..1d855a26 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -289,7 +289,9 @@ pub unsafe fn get_player_dmg_digits(p: FighterId) -> (u8, u8, u8, u8) { pub unsafe fn get_fighter_distance() -> f32 { let player_module_accessor = get_module_accessor(FighterId::Player); - if StatusModule::status_kind(player_module_accessor) == *FIGHTER_STATUS_KIND_NONE { return f32::MAX } + if StatusModule::status_kind(player_module_accessor) == *FIGHTER_STATUS_KIND_NONE { + return f32::MAX; + } let cpu_module_accessor = get_module_accessor(FighterId::CPU); let player_pos = *PostureModule::pos(player_module_accessor); let cpu_pos = *PostureModule::pos(cpu_module_accessor); diff --git a/src/common/offsets.rs b/src/common/offsets.rs index a1d9e528..ffe14da4 100644 --- a/src/common/offsets.rs +++ b/src/common/offsets.rs @@ -15,7 +15,7 @@ pub fn byte_search(needle: &[u8]) -> (Option, Option) { use memchr::memmem; let first = memmem::find(haystack, needle); let last = memmem::rfind(haystack, needle); - return (first, last); + (first, last) } // Wrapper around byte_search() with some additional logging diff --git a/src/training/character_specific/ptrainer.rs b/src/training/character_specific/ptrainer.rs index c4896d9e..0c25e1c6 100644 --- a/src/training/character_specific/ptrainer.rs +++ b/src/training/character_specific/ptrainer.rs @@ -145,13 +145,12 @@ unsafe fn handle_pokemon_decide(ctx: &mut InlineCtx) { if !is_training_mode() || !save_states::is_loading() { return; } - let x20 = ctx.registers[20].x.as_mut(); - let fighter = *x20 as *mut u64 as *mut app::Fighter; + let x20 = ctx.registers[20].x(); + let fighter = x20 as *mut app::Fighter; let module_accessor = (*fighter).battle_object.module_accessor; let pokemon_value = save_states::get_state_pokemon(module_accessor); if pokemon_value <= 2 { - let w8 = ctx.registers[8].w.as_mut(); - *w8 = pokemon_value; + ctx.registers[8].set_w(pokemon_value); } } diff --git a/src/training/mod.rs b/src/training/mod.rs index e63e8d32..edcd2289 100644 --- a/src/training/mod.rs +++ b/src/training/mod.rs @@ -427,7 +427,7 @@ pub unsafe fn handle_add_damage( // This function already checks for training mode, so we don't need to check for training mode here #[skyline::hook(offset = *OFFSET_TRAINING_RESET_CHECK, inline)] unsafe fn lra_handle(ctx: &mut InlineCtx) { - let x8 = ctx.registers[8].x.as_mut(); + let x8 = ctx.registers[8].x() as *mut u64; if !(read(&MENU).lra_reset.as_bool()) { *x8 = 0; } @@ -437,8 +437,7 @@ unsafe fn lra_handle(ctx: &mut InlineCtx) { // One instruction after stale moves toggle register is set to 0 #[skyline::hook(offset = *OFFSET_STALE, inline)] unsafe fn stale_handle(ctx: &mut InlineCtx) { - let x22 = ctx.registers[22].x.as_mut(); - TRAINING_MENU_ADDR = (*x22) as *mut PauseMenu; + TRAINING_MENU_ADDR = ctx.registers[22].x() as *mut PauseMenu; (*TRAINING_MENU_ADDR).stale_move_toggle = 1; } @@ -448,8 +447,7 @@ unsafe fn stale_handle(ctx: &mut InlineCtx) { unsafe fn stale_menu_handle(ctx: &mut InlineCtx) { // Set the text pointer to where "mel_training_on" is located let on_text_ptr = (getRegionAddress(Region::Text) as u64) + 0x42b315e; - let x1 = ctx.registers[1].x.as_mut(); - *x1 = on_text_ptr; + ctx.registers[1].set_x(on_text_ptr); } #[skyline::hook(replace = SoundModule::play_se)] // hooked to prevent death sfx from playing when loading save states diff --git a/src/training/save_states.rs b/src/training/save_states.rs index cb431414..c5fa51bd 100644 --- a/src/training/save_states.rs +++ b/src/training/save_states.rs @@ -762,7 +762,7 @@ pub unsafe fn save_states(module_accessor: &mut app::BattleObjectModuleAccessor) if save_state_player(selected_slot).state != Save && save_state_cpu(selected_slot).state != Save { - save_to_file(); + std::thread::spawn(move || save_to_file()); } } } diff --git a/src/training/ui/mod.rs b/src/training/ui/mod.rs index 886671c6..69a3bd59 100644 --- a/src/training/ui/mod.rs +++ b/src/training/ui/mod.rs @@ -135,8 +135,8 @@ unsafe fn handle_layout_arc_malloc(ctx: &mut skyline::hooks::InlineCtx) { return; } - let decompressed_file = *ctx.registers[21].x.as_ref() as *const u8; - let decompressed_size = *ctx.registers[1].x.as_ref() as usize; + let decompressed_file = ctx.registers[21].x() as *const u8; + let decompressed_size = ctx.registers[1].x() as usize; let layout_arc = SarcFile::read(std::slice::from_raw_parts( decompressed_file, @@ -177,13 +177,12 @@ unsafe fn handle_layout_arc_malloc(ctx: &mut skyline::hooks::InlineCtx) { } // Decompressed file pointer - let decompressed_file = ctx.registers[21].x.as_mut(); - *decompressed_file = inject_arc as u64; + ctx.registers[21].set_x(inject_arc as u64); // Decompressed size is in each of these registers - *ctx.registers[1].x.as_mut() = inject_arc_size; - *ctx.registers[23].x.as_mut() = inject_arc_size; - *ctx.registers[24].x.as_mut() = inject_arc_size; + ctx.registers[1].set_x(inject_arc_size); + ctx.registers[23].set_x(inject_arc_size); + ctx.registers[24].set_x(inject_arc_size); } pub fn init() { diff --git a/training_mod_sync/src/lib.rs b/training_mod_sync/src/lib.rs index 235e1876..a582d06d 100644 --- a/training_mod_sync/src/lib.rs +++ b/training_mod_sync/src/lib.rs @@ -24,13 +24,13 @@ pub fn assign(rwlock: &RwLock, new_val: T) { /// Locks a RwLock for writing and returns the guard /// /// Don't forget to drop the guard as soon as you're finished with it -pub fn lock_write(rwlock: &RwLock) -> RwLockWriteGuard { +pub fn lock_write(rwlock: &RwLock) -> RwLockWriteGuard<'_, T> { rwlock.write().unwrap() } /// Locks a RwLock for reading and returns the guard /// /// Don't forget to drop the guard as soon as you're finished with it -pub fn lock_read(rwlock: &RwLock) -> RwLockReadGuard { +pub fn lock_read(rwlock: &RwLock) -> RwLockReadGuard<'_, T> { rwlock.read().unwrap() } diff --git a/training_mod_tui/src/structures/stateful_list.rs b/training_mod_tui/src/structures/stateful_list.rs index fbc47bfd..6ae482f5 100644 --- a/training_mod_tui/src/structures/stateful_list.rs +++ b/training_mod_tui/src/structures/stateful_list.rs @@ -118,7 +118,7 @@ impl StatefulList { pub fn iter(&self) -> impl Iterator + '_ { self.items.iter() } - pub fn iter_mut(&mut self) -> std::slice::IterMut { + pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, T> { self.items.iter_mut() } } diff --git a/training_mod_tui/src/structures/stateful_table.rs b/training_mod_tui/src/structures/stateful_table.rs index 4b6d2c5f..17280c8d 100644 --- a/training_mod_tui/src/structures/stateful_table.rs +++ b/training_mod_tui/src/structures/stateful_table.rs @@ -246,7 +246,7 @@ impl<'a, T: Clone + Serialize> Iterator for StatefulTableIterator<'a, T> { } impl StatefulTable { - pub fn iter(&self) -> StatefulTableIterator { + pub fn iter(&self) -> StatefulTableIterator<'_, T> { StatefulTableIterator { stateful_table: self, index: 0,