1
0
mirror of https://github.com/jugeeya/UltimateTrainingModpack.git synced 2025-11-08 16:02:40 +00:00

During runtime, don't block for file write operations (#743)

* During runtime, don't block for file write operations

* Fix build and warnings

* Fix build and warnings again
This commit is contained in:
asimon-1
2025-09-21 11:58:09 -07:00
committed by GitHub
parent db5775bce8
commit 387ac40a8a
11 changed files with 29 additions and 29 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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);

View File

@@ -15,7 +15,7 @@ pub fn byte_search(needle: &[u8]) -> (Option<usize>, Option<usize>) {
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

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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());
}
}
}

View File

@@ -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() {

View File

@@ -24,13 +24,13 @@ pub fn assign<T>(rwlock: &RwLock<T>, 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<T>(rwlock: &RwLock<T>) -> RwLockWriteGuard<T> {
pub fn lock_write<T>(rwlock: &RwLock<T>) -> 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<T>(rwlock: &RwLock<T>) -> RwLockReadGuard<T> {
pub fn lock_read<T>(rwlock: &RwLock<T>) -> RwLockReadGuard<'_, T> {
rwlock.read().unwrap()
}

View File

@@ -118,7 +118,7 @@ impl<T: Serialize> StatefulList<T> {
pub fn iter(&self) -> impl Iterator<Item = &T> + '_ {
self.items.iter()
}
pub fn iter_mut(&mut self) -> std::slice::IterMut<T> {
pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, T> {
self.items.iter_mut()
}
}

View File

@@ -246,7 +246,7 @@ impl<'a, T: Clone + Serialize> Iterator for StatefulTableIterator<'a, T> {
}
impl<T: Clone + Serialize> StatefulTable<T> {
pub fn iter(&self) -> StatefulTableIterator<T> {
pub fn iter(&self) -> StatefulTableIterator<'_, T> {
StatefulTableIterator {
stateful_table: self,
index: 0,