From 1a9dea2f52ae50fa4c2ef9cdb3a9d89b430b44ec Mon Sep 17 00:00:00 2001 From: techyCoder81 <42820193+techyCoder81@users.noreply.github.com> Date: Sat, 28 Jan 2023 22:06:35 -0500 Subject: [PATCH] Update infinite shield logic to work for modded gameplay (#460) * update infinite shield logic uses the originally loaded shield mul param rather than a hardcoded vanilla param that may be different than what the game (read: mods) had loaded initially. * use option instead of a magic float --- src/training/mod.rs | 3 +++ src/training/shield.rs | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/training/mod.rs b/src/training/mod.rs index 465dea9..6f59115 100644 --- a/src/training/mod.rs +++ b/src/training/mod.rs @@ -86,6 +86,9 @@ pub unsafe fn handle_get_command_flag_cat( ) -> i32 { let mut flag = original!()(module_accessor, category); + // this must be run even outside of training mode + // because otherwise it won't reset the shield_damage_mul + // back to "normal" once you leave training mode. if category == FIGHTER_PAD_COMMAND_CATEGORY1 { shield::param_installer(); } diff --git a/src/training/shield.rs b/src/training/shield.rs index 80bd2cc..36c893e 100644 --- a/src/training/shield.rs +++ b/src/training/shield.rs @@ -145,13 +145,33 @@ fn handle_shield_decay(param_type: u64, param_hash: u64) -> Option { None } +/// This is the cached shield damage multiplier. +/// Vanilla is 1.19, but mods can change this. +static mut CACHED_SHIELD_DAMAGE_MUL: Option = None; + + +/// sets/resets the shield_damage_mul within +/// the game's internal structure. +/// +/// `common_params` is effectively a mutable reference +/// to the game's own internal data structure for params. pub unsafe fn param_installer() { if crate::training::COMMON_PARAMS as usize != 0 { let common_params = &mut *crate::training::COMMON_PARAMS; + + // cache the original shield damage multiplier once + if CACHED_SHIELD_DAMAGE_MUL.is_none() { + CACHED_SHIELD_DAMAGE_MUL = Some(common_params.shield_damage_mul); + } + if is_training_mode() && (MENU.shield_state == Shield::Infinite) { + // if you are in training mode and have infinite shield enabled, + // set the game's shield_damage_mul to 0.0 common_params.shield_damage_mul = 0.0; } else { - common_params.shield_damage_mul = 1.19; + // reset the game's shield_damage_mul back to what + // it originally was at game boot. + common_params.shield_damage_mul = CACHED_SHIELD_DAMAGE_MUL.unwrap(); } } }