From 80230ca8b8b6a62cfcb3dc890e57f74bedc4a5bc Mon Sep 17 00:00:00 2001 From: Matt Stanley <5354790+mstan@users.noreply.github.com> Date: Sun, 8 Nov 2026 11:14:12 -0800 Subject: [PATCH 1/2] Add independent X damage dealt and player damage received mods --- CMakeLists.txt | 23 +++- README.md | 10 ++ .../1.0.0/manifest.toml | 2 +- .../1.0.0/manifest.toml | 92 +++++++++++++ .../1.0.0/manifest.toml | 92 +++++++++++++ src/mmx_damage.c | 54 ++++++++ src/mmx_damage.h | 13 ++ src/mods/mmx_damage_plugin.c | 55 ++++++++ src/mods/mmx_zero_plugin.c | 7 +- tests/mmx_adaptive_state_test.c | 2 + tests/mmx_damage_runtime_test.inc | 124 ++++++++++++++++++ tests/mmx_damage_test.c | 61 +++++++++ tools/apply_damage_hooks.py | 52 ++++++++ tools/apply_zero_hooks.py | 4 +- 14 files changed, 584 insertions(+), 7 deletions(-) create mode 100644 mods/preloaded/packages/megaman-x.gameplay.damage-dealt/1.0.0/manifest.toml create mode 100644 mods/preloaded/packages/megaman-x.gameplay.damage-received/1.0.0/manifest.toml create mode 100644 src/mmx_damage.c create mode 100644 src/mmx_damage.h create mode 100644 src/mods/mmx_damage_plugin.c create mode 100644 tests/mmx_damage_runtime_test.inc create mode 100644 tests/mmx_damage_test.c create mode 100644 tools/apply_damage_hooks.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 63a1bf0a..5a344136 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.20) -project(MegaManXSNESRecomp VERSION 2.3.12 LANGUAGES C CXX) +project(MegaManXSNESRecomp VERSION 2.3.13 LANGUAGES C CXX) # Qualified Windows x64 default; retain explicit selections and other-target floors. set(_MMX_RASTER_IMPL_DEFAULT "LLE") string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" _MMX_RASTER_IMPL_PROCESSOR) @@ -99,6 +99,7 @@ function(add_mmx_variant TARGET GEN_DIR CFG_DIR) src/main.c src/mmx_startup.c src/mmx_netplay.c src/mmx_display.c ${MMX_RENDERER_SOURCE} src/mmx_render_assets.c src/mmx_wide_policy.c src/mmx_00.c src/gen_stubs.c src/mmx_cpu_infra.c src/mmx_rtl.c src/mmx_spc_player.c src/mmx_replay.c src/mods/mmx_diagnostics_plugin.c + src/mmx_damage.c src/mods/mmx_damage_plugin.c src/mods/mmx_widescreen_plugin.c src/mods/mmx_msu1_plugin.c src/mods/mmx_hadouken_plugin.c src/mods/mmx_password_plugin.c src/mods/mmx_boss_rush_plugin.c src/mmx_password_save.cpp src/mods/mmx_zero_plugin.c src/mods/mmx_armor_plugin.c src/mmx_zero.c src/mmx_armor.c src/mmx_armor_launcher.c src/mmx_weapons.c src/mmx_weapon_combat.c src/mmx_knc_bugfix.c src/mmx_coop.c src/mmx_coop_trace.c src/mmx_coop_view.c @@ -141,6 +142,7 @@ function(add_mmx_variant TARGET GEN_DIR CFG_DIR) ${CMAKE_CURRENT_SOURCE_DIR}/tools/apply_renderer_capture.py ${CMAKE_CURRENT_SOURCE_DIR}/tools/apply_password_hooks.py ${CMAKE_CURRENT_SOURCE_DIR}/tools/apply_zero_hooks.py + ${CMAKE_CURRENT_SOURCE_DIR}/tools/apply_damage_hooks.py ${CMAKE_CURRENT_SOURCE_DIR}/tools/apply_coop_hooks.py ${CMAKE_CURRENT_SOURCE_DIR}/tools/apply_weapon_hooks.py ${CMAKE_CURRENT_SOURCE_DIR}/tools/apply_boss_rush_hooks.py) @@ -159,6 +161,8 @@ function(add_mmx_variant TARGET GEN_DIR CFG_DIR) --gen-dir ${GEN_DIR} COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/apply_boss_rush_hooks.py --gen-dir ${GEN_DIR} + COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/tools/apply_damage_hooks.py + --gen-dir ${GEN_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Applying Mega Man X generated-code mod hooks" VERBATIM) add_dependencies(${TARGET} ${TARGET}_widescreen_overrides) @@ -191,6 +195,14 @@ add_mmx_variant(RockmanXSNESRecomp "${CMAKE_CURRENT_SOURCE_DIR}/variants/jp/gen" include(CTest) if(BUILD_TESTING) + add_executable(mmx_damage_test tests/mmx_damage_test.c src/mmx_damage.c) + target_include_directories(mmx_damage_test PRIVATE src) + add_test(NAME mmx_damage_multipliers COMMAND mmx_damage_test) + if(MSVC) + target_compile_options(mmx_damage_test PRIVATE /UNDEBUG) + else() + target_compile_options(mmx_damage_test PRIVATE -UNDEBUG) + endif() add_executable(mmx_armor_launcher_test tests/mmx_armor_launcher_test.c src/mmx_armor_launcher.c) target_include_directories(mmx_armor_launcher_test PRIVATE src ${RECOMP_UI_ROOT}/src) target_compile_definitions(mmx_armor_launcher_test PRIVATE RECOMP_LAUNCHER=1) @@ -355,6 +367,15 @@ if(TARGET mmx_state_tests) set_property(TARGET mmx_state_tests PROPERTY SOURCES tests/mmx_adaptive_state_test.c ${mmx_state_sources}) if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/mmx.sfc") + set(damage_test_dir "${CMAKE_CURRENT_BINARY_DIR}/damage-runtime") + file(MAKE_DIRECTORY "${damage_test_dir}") + file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/mods/preloaded/" DESTINATION "${damage_test_dir}/catalog") + add_test(NAME mmx_damage_runtime + COMMAND ${CMAKE_COMMAND} -E env SDL_AUDIODRIVER=dummy SDL_VIDEODRIVER=dummy + MMX_REPLAY_RECORD=0 MMX_DAMAGE_TEST=1 + $ "${CMAKE_CURRENT_SOURCE_DIR}/mmx.sfc") + set_tests_properties(mmx_damage_runtime PROPERTIES + WORKING_DIRECTORY "${damage_test_dir}" LABELS "rom;damage") set(rush_report_dir "${CMAKE_CURRENT_BINARY_DIR}/boss-rush-reports") set(render_rollback_dir "${CMAKE_CURRENT_BINARY_DIR}/render-rollback") file(MAKE_DIRECTORY "${render_rollback_dir}") diff --git a/README.md b/README.md index fdac6c08..9ed61f63 100644 --- a/README.md +++ b/README.md @@ -96,6 +96,7 @@ Rev 1 build. | ☑ | **[Boss Rush](docs/boss-rush.md)** | Endless fights against two different Mavericks, solo or co-op, from the game's title menu. | | ☑ | **X2 weapons** | All eight boss weapons and their charged attacks, adapted for X and Zero. | | ☑ | **X3 weapons** | All eight boss weapons and their charged attacks, adapted for X and Zero. | +| ☑ | **Damage multipliers** | Separate mods for X's damage dealt and player damage received, from 0.1x to 10x. | | ☑ | **X2 / X3 Armor (experimental)** | Donor X graphics and abilities, unlocked through X1's armor capsules. X3 Gold Armor is awarded by the Hadouken capsule. | | ☑ | **Netplay** | Two-player online co-op with lobbies and rollback, plus optional fixed widescreen. | @@ -139,6 +140,15 @@ No ROMs or extracted assets are included in the downloads. For Storm Eagle's speedrun trick and local practice saves, see the [Magic Carpet guide](docs/magic-carpet.md). +In **Mods > Gameplay**, enable **X damage dealt** or **Player damage received** +and choose its **Damage multiplier**. The two mods are independent: 0.5x halves +damage, 1x keeps normal damage, and 2x doubles it. Choices range from 0.1x to +10x; both mods start disabled with 1x selected. X's multiplier includes native +and imported weapons and leaves Zero's attacks unchanged. Received damage +applies to both characters after armor reduction. Positive damage rounds to +the nearest whole HP (halves round up), with a minimum of 1 and maximum of 127. +Immunities and instant-death hazards keep their native behavior. + ### Which ROM? The game needs the **v1.1 (Rev 1)** cartridge dump. The original v1.0 release diff --git a/mods/preloaded/packages/megaman-x.enhancement.widescreen/1.0.0/manifest.toml b/mods/preloaded/packages/megaman-x.enhancement.widescreen/1.0.0/manifest.toml index e75d9b07..26b36d31 100644 --- a/mods/preloaded/packages/megaman-x.enhancement.widescreen/1.0.0/manifest.toml +++ b/mods/preloaded/packages/megaman-x.enhancement.widescreen/1.0.0/manifest.toml @@ -17,7 +17,7 @@ id = "widescreen" name = "Widescreen" description = "Extend the stage view with live enemies, preserved encounter timing, and anchored health bars." group = "Display" -default_enabled = false +default_enabled = true [[option]] feature = "widescreen" diff --git a/mods/preloaded/packages/megaman-x.gameplay.damage-dealt/1.0.0/manifest.toml b/mods/preloaded/packages/megaman-x.gameplay.damage-dealt/1.0.0/manifest.toml new file mode 100644 index 00000000..976925a5 --- /dev/null +++ b/mods/preloaded/packages/megaman-x.gameplay.damage-dealt/1.0.0/manifest.toml @@ -0,0 +1,92 @@ +format_version = 1 +id = "megaman-x.gameplay.damage-dealt" +version = "1.0.0" +name = "X damage dealt" +author = "mstan" +description = "Multiply damage dealt by X, including native and imported weapons. Zero retains his own damage." +license = "PolyForm-Noncommercial-1.0.0" +resolver = "declarative" +save_compatibility = "requires-same-mods" + +[[target]] +game_id = "megaman-x-us" +rom_sha256 = "b8f70a6e7fb93819f79693578887e2c11e196bdf1ac6ddc7cb924b1ad0be2d32" + +[[feature]] +id = "damage" +name = "X damage dealt" +description = "Multiply damage dealt by X, including native and imported weapons. Zero retains his own damage." +group = "Gameplay" +default_enabled = false + +[[option]] +feature = "damage" +id = "multiplier" +label = "Damage multiplier" +description = "1x is normal, 0.5x is half, 2x is double. Rounded to the nearest HP with a minimum of 1 for damaging hits and a maximum of 127. Immunities remain unchanged." +type = "choice" +default = "1" + +[[option.choice]] +value = "0.1" +label = "0.1x" + +[[option.choice]] +value = "0.25" +label = "0.25x" + +[[option.choice]] +value = "0.5" +label = "0.5x" + +[[option.choice]] +value = "0.75" +label = "0.75x" + +[[option.choice]] +value = "1" +label = "1x" + +[[option.choice]] +value = "1.25" +label = "1.25x" + +[[option.choice]] +value = "1.5" +label = "1.5x" + +[[option.choice]] +value = "1.75" +label = "1.75x" + +[[option.choice]] +value = "2" +label = "2x" + +[[option.choice]] +value = "2.5" +label = "2.5x" + +[[option.choice]] +value = "3" +label = "3x" + +[[option.choice]] +value = "4" +label = "4x" + +[[option.choice]] +value = "5" +label = "5x" + +[[option.choice]] +value = "7.5" +label = "7.5x" + +[[option.choice]] +value = "10" +label = "10x" + +[[plugin]] +feature = "damage" +id = "megaman-x.damage-dealt" diff --git a/mods/preloaded/packages/megaman-x.gameplay.damage-received/1.0.0/manifest.toml b/mods/preloaded/packages/megaman-x.gameplay.damage-received/1.0.0/manifest.toml new file mode 100644 index 00000000..b69a4bb1 --- /dev/null +++ b/mods/preloaded/packages/megaman-x.gameplay.damage-received/1.0.0/manifest.toml @@ -0,0 +1,92 @@ +format_version = 1 +id = "megaman-x.gameplay.damage-received" +version = "1.0.0" +name = "Player damage received" +author = "mstan" +description = "Multiply damage received by either player after armor reduction. Instant-death hazards retain their native behavior." +license = "PolyForm-Noncommercial-1.0.0" +resolver = "declarative" +save_compatibility = "requires-same-mods" + +[[target]] +game_id = "megaman-x-us" +rom_sha256 = "b8f70a6e7fb93819f79693578887e2c11e196bdf1ac6ddc7cb924b1ad0be2d32" + +[[feature]] +id = "damage" +name = "Player damage received" +description = "Multiply damage received by either player after armor reduction. Instant-death hazards retain their native behavior." +group = "Gameplay" +default_enabled = false + +[[option]] +feature = "damage" +id = "multiplier" +label = "Damage multiplier" +description = "1x is normal, 0.5x is half, 2x is double. Rounded to the nearest HP with a minimum of 1 for damaging hits and a maximum of 127. Immunities remain unchanged." +type = "choice" +default = "1" + +[[option.choice]] +value = "0.1" +label = "0.1x" + +[[option.choice]] +value = "0.25" +label = "0.25x" + +[[option.choice]] +value = "0.5" +label = "0.5x" + +[[option.choice]] +value = "0.75" +label = "0.75x" + +[[option.choice]] +value = "1" +label = "1x" + +[[option.choice]] +value = "1.25" +label = "1.25x" + +[[option.choice]] +value = "1.5" +label = "1.5x" + +[[option.choice]] +value = "1.75" +label = "1.75x" + +[[option.choice]] +value = "2" +label = "2x" + +[[option.choice]] +value = "2.5" +label = "2.5x" + +[[option.choice]] +value = "3" +label = "3x" + +[[option.choice]] +value = "4" +label = "4x" + +[[option.choice]] +value = "5" +label = "5x" + +[[option.choice]] +value = "7.5" +label = "7.5x" + +[[option.choice]] +value = "10" +label = "10x" + +[[plugin]] +feature = "damage" +id = "megaman-x.damage-received" diff --git a/src/mmx_damage.c b/src/mmx_damage.c new file mode 100644 index 00000000..35a9dc8c --- /dev/null +++ b/src/mmx_damage.c @@ -0,0 +1,54 @@ +#include "mmx_damage.h" +#include "mmx_coop.h" + +static unsigned dealt = MMX_DAMAGE_NORMAL, received = MMX_DAMAGE_NORMAL; + +static unsigned bound(unsigned value) { + return value < MMX_DAMAGE_MIN ? MMX_DAMAGE_MIN : + value > MMX_DAMAGE_MAX ? MMX_DAMAGE_MAX : value; +} + +unsigned MmxDamageParseMultiplier(const char *value) { + /* Locale-independent fixed point; reject signs, exponents, NaN, infinity, + * trailing text and excessive precision rather than converting to float. */ + if (!value || *value < '0' || *value > '9') return MMX_DAMAGE_NORMAL; + unsigned whole = 0, fraction = 0, digits = 0; + while (*value >= '0' && *value <= '9') { + if (whole > 100) return MMX_DAMAGE_NORMAL; + whole = whole * 10 + (unsigned)(*value++ - '0'); + } + if (*value == '.') { + ++value; + while (*value >= '0' && *value <= '9') { + if (++digits > 2) return MMX_DAMAGE_NORMAL; + fraction = fraction * 10 + (unsigned)(*value++ - '0'); + } + if (!digits) return MMX_DAMAGE_NORMAL; + } + if (*value || whole > 10) return MMX_DAMAGE_NORMAL; + if (digits == 1) fraction *= 10; + return bound(whole * 100 + fraction); +} + +void MmxDamageSetDealt(unsigned value) { dealt = bound(value); } +void MmxDamageSetReceived(unsigned value) { received = bound(value); } +void MmxDamageReset(void) { dealt = received = MMX_DAMAGE_NORMAL; } +bool MmxDamageDealtEnabled(void) { return dealt != MMX_DAMAGE_NORMAL; } + +static unsigned scale(unsigned damage, unsigned multiplier) { + if (!damage || multiplier == MMX_DAMAGE_NORMAL) return damage; + /* HP uses seven bits. Bound the input before multiplying and round half up. + * A positive hit stays positive; immunity and suppressed repeat hits stay 0. */ + if (damage > 127) damage = 127; + unsigned result = (damage * multiplier + 50) / 100; + return result < 1 ? 1 : result > 127 ? 127 : result; +} + +unsigned MmxDamageDealt(unsigned damage) { + return dealt != MMX_DAMAGE_NORMAL && MmxCoopActorIsX() ? scale(damage, dealt) : damage; +} +unsigned MmxDamageReceived(unsigned damage, bool lethal) { + /* Spikes, pits and crushers retain their native fatal result, including + * the armor-reduced operand. Learner Mode's zero damage remains zero. */ + return lethal ? damage : scale(damage, received); +} diff --git a/src/mmx_damage.h b/src/mmx_damage.h new file mode 100644 index 00000000..e8d8b6a4 --- /dev/null +++ b/src/mmx_damage.h @@ -0,0 +1,13 @@ +#pragma once +#include + +/* Multipliers use hundredths: 50 = 0.5x, 100 = 1x, 200 = 2x. + * Configuration is fixed for a session; the mod identity carries it for netplay. */ +enum { MMX_DAMAGE_MIN = 10, MMX_DAMAGE_NORMAL = 100, MMX_DAMAGE_MAX = 1000 }; +unsigned MmxDamageParseMultiplier(const char *value); +void MmxDamageSetDealt(unsigned hundredths); +void MmxDamageSetReceived(unsigned hundredths); +void MmxDamageReset(void); +bool MmxDamageDealtEnabled(void); +unsigned MmxDamageDealt(unsigned damage); +unsigned MmxDamageReceived(unsigned damage, bool lethal); diff --git a/src/mods/mmx_damage_plugin.c b/src/mods/mmx_damage_plugin.c new file mode 100644 index 00000000..ad96af8f --- /dev/null +++ b/src/mods/mmx_damage_plugin.c @@ -0,0 +1,55 @@ +#include "mmx_damage.h" +#include "mod_runtime.h" +#include "snes/interp_bridge.h" +#include + +extern uint8_t g_ram[0x20000]; +extern void MmxZeroRegisterHooks(void); + +static void received_hook(CpuState *cpu, uint32_t pc) { + bool contact = (pc & 65535) == 0x9d59; + unsigned original = g_ram[0]; + bool lethal = (contact ? g_ram[(cpu->D + 0x26) & 65535] : g_ram[0xbce]) >= 127; + unsigned damage = MmxDamageReceived(original, lethal); + if (damage == original) return; + /* Post-SBC / pre-STA: keep guest instruction timing, carry/overflow and + * both accumulator bytes identical to a native SBC using the new operand. */ + unsigned hp = g_ram[0xbcf] & 127, result; + if (cpu->_flag_D) { + unsigned complement = damage ^ 255; + int decimal = (hp & 15) + (complement & 15) + 1; + if (decimal < 16) decimal = (decimal - 6) & (decimal < 6 ? 15 : 31); + decimal += (hp & 240) + (complement & 240); + cpu->_flag_V = ((hp & 128) == (complement & 128)) && ((complement & 128) != (decimal & 128)); + if (decimal < 256) decimal -= 96; + cpu->_flag_C = decimal > 255; result = (unsigned)decimal & 255; + } else { + result = (hp - damage) & 255; + cpu->_flag_C = hp >= damage; + cpu->_flag_V = ((hp ^ damage) & (hp ^ result) & 128) != 0; + } + cpu->A = (cpu->A & 0xff00) | result; + cpu->_flag_Z = result == 0; cpu->_flag_N = (result & 128) != 0; + cpu->P = (cpu->P & ~0xc3) | cpu->_flag_C | (cpu->_flag_Z ? 2 : 0) | + (cpu->_flag_V ? 64 : 0) | (cpu->_flag_N ? 128 : 0); +} + +static unsigned multiplier(const char *package) { + char value[32] = {0}; + snes_mod_runtime_feature_option_value_c(package, "damage", "multiplier", value, sizeof(value)); + return MmxDamageParseMultiplier(value); +} +static void activate_dealt(void) { + MmxDamageSetDealt(multiplier("megaman-x.gameplay.damage-dealt")); + MmxZeroRegisterHooks(); +} +static void activate_received(void) { + MmxDamageSetReceived(multiplier("megaman-x.gameplay.damage-received")); + interp_bridge_add_pre_opcode_hook(0x849d59, received_hook); + interp_bridge_add_pre_opcode_hook(0x849f62, received_hook); +} +SNES_MOD_CONSTRUCTOR(mmx_register_damage_plugins) { + snes_mod_register_reset_callback(MmxDamageReset); + snes_mod_register_activation_plugin("megaman-x.damage-dealt", activate_dealt); + snes_mod_register_activation_plugin("megaman-x.damage-received", activate_received); +} diff --git a/src/mods/mmx_zero_plugin.c b/src/mods/mmx_zero_plugin.c index 0cdbb552..c13574c1 100644 --- a/src/mods/mmx_zero_plugin.c +++ b/src/mods/mmx_zero_plugin.c @@ -5,6 +5,7 @@ #include "mmx_renderer.h" #include "mmx_zero.h" #include "mmx_armor.h" +#include "mmx_damage.h" #include "mmx_weapons.h" #include "mmx_weapon_combat.h" #include "mmx_source_assets.h" @@ -62,7 +63,7 @@ static void weapon_menu_hook(CpuState *cpu, uint32_t pc) { cpu->P = (cpu->P & ~0x82) | (cpu->_flag_Z ? 2 : 0) | (cpu->_flag_N ? 128 : 0); } static void hook(CpuState *cpu, uint32_t pc) { - if (!MmxZeroEnabled() && !MmxWeaponsEnabled() && !MmxArmorEnabled()) return; + if (!MmxZeroEnabled() && !MmxWeaponsEnabled() && !MmxArmorEnabled() && !MmxDamageDealtEnabled()) return; switch (pc & 0x7fffff) { case 0x019ef9: /* Intercept the STA, which preserves the native ADC flags. */ @@ -177,8 +178,8 @@ static void hook(CpuState *cpu, uint32_t pc) { } case 0x049e76: { unsigned original = cpu_read8(cpu, cpu->DB, (uint16_t)(0xef37 + cpu->Y)); - unsigned damage = MmxWeaponsDamage(g_ram, cpu->D, cpu->X, - MmxZeroDamage(g_ram, cpu->D, cpu->X, original)); + unsigned damage = MmxDamageDealt(MmxWeaponsDamage(g_ram, cpu->D, cpu->X, + MmxZeroDamage(g_ram, cpu->D, cpu->X, original))); if (damage == original) break; /* Post-SBC: retain the interpreter's instruction timing, but recompute * its value and all arithmetic flags with our damage operand. The HP diff --git a/tests/mmx_adaptive_state_test.c b/tests/mmx_adaptive_state_test.c index 4bc41fbc..fa6ef1dd 100644 --- a/tests/mmx_adaptive_state_test.c +++ b/tests/mmx_adaptive_state_test.c @@ -1679,6 +1679,7 @@ static void zero_charge_visual_checks(const char *fixture,uint8 *start,uint8 *ex #include "mmx_weapon_parasitic_test.inc" #include "mmx_weapon_stage_test.inc" #include "mmx_weapon_weakness_test.inc" +#include "mmx_damage_runtime_test.inc" static void zero_state_checks(const char *assets, const char *fixture, uint8 *start, uint8 *expected, uint8 *actual, size_t cap) { check(fixture != NULL && MmxZeroLoad(assets), "Zero local assets load"); @@ -1989,6 +1990,7 @@ int main(int argc, char **argv) { check(SnesInit(rom, rom_size) != NULL, "game initializes"); g_spc_player = SmwSpcPlayer_Create(); g_spc_player->initialize(g_spc_player); + if (getenv("MMX_DAMAGE_TEST")) { damage_runtime_checks(argv[1]); return 0; } if (getenv("MMX_WEAKNESS_TEST")) { weapon_weakness_checks(); return 0; diff --git a/tests/mmx_damage_runtime_test.inc b/tests/mmx_damage_runtime_test.inc new file mode 100644 index 00000000..9a71567c --- /dev/null +++ b/tests/mmx_damage_runtime_test.inc @@ -0,0 +1,124 @@ +#include "mmx_damage.h" +extern RecompReturn bank_84_9B03_M1X0(CpuState *cpu); +extern RecompReturn bank_84_9F2A_M1X1(CpuState *cpu); + +static void damage_call(unsigned path, unsigned kind, unsigned enemy) { + CpuState cpu = g_cpu; + cpu.S = 0x1ff; cpu.D = kind == 1 ? (uint16_t)enemy : 0xe68; + cpu.X = 0x1228; cpu.Y = 0; cpu.DB = kind == 2 ? 0 : 0x86; + cpu.PB = path == 2 ? 4 : 0x84; + cpu.P = kind == 2 ? 0x30 : 0x20; cpu.emulation = 0; + cpu_p_to_mirrors(&cpu); cpu_push_jsl_return_frame(&cpu); + interp_bridge_set_master_deadline(0); + unsigned pc = kind == 2 ? 0x849f2a : kind == 1 ? 0x849b03 : 0x849e15; + int ok = path == 0 ? interp_bridge_run(&cpu, pc) : kind == 2 ? + bank_84_9F2A_M1X1(&cpu) == RECOMP_RETURN_NORMAL : kind == 1 ? + bank_84_9B03_M1X0(&cpu) == RECOMP_RETURN_NORMAL : path == 2 ? + cpu_dispatch_call_pc_pushed(&cpu,0x049e15,0x048000,3,NULL) == RECOMP_RETURN_NORMAL : + bank_84_9E15_M1X0(&cpu) == RECOMP_RETURN_NORMAL; + check(ok && cpu.S == 0x1ff, "damage routine returns with balanced stack"); +} + +static void damage_runtime_checks(const char *rom_path) { + const char *catalog = "catalog"; + /* Only the test's copied catalog is writable; no player profile is used. */ + remove("catalog/state.toml"); + check(catalog && snes_mod_runtime_initialize_c(catalog, "megaman-x-us", + "b8f70a6e7fb93819f79693578887e2c11e196bdf1ac6ddc7cb924b1ad0be2d32"), + "damage catalog parses"); + const RecompLauncherCModProvider *p = snes_mod_runtime_launcher_provider_c(); + const char *out = "megaman-x.gameplay.damage-dealt"; + const char *in = "megaman-x.gameplay.damage-received"; + check(!snes_mod_runtime_feature_enabled_c(out,"damage") && + !snes_mod_runtime_feature_enabled_c(in,"damage"), "both damage mods default off"); + check(snes_mod_runtime_feature_enabled_c("megaman-x.enhancement.widescreen","widescreen"), + "fresh packaged catalog enables adaptive widescreen"); + check(p->feature_enable(p->ctx,out,"damage",1) && + p->feature_set_option(p->ctx,out,"damage","multiplier","2") && + p->feature_enable(p->ctx,in,"damage",1) && + p->feature_set_option(p->ctx,in,"damage","multiplier","0.5") && + p->commit(p->ctx,rom_path), "launcher commits independent multipliers"); + snes_mod_runtime_activate_plugins_c(); + check(MmxDamageDealt(4) == 8 && MmxDamageReceived(4,false) == 2, + "real plugins activate outgoing 2x and incoming 0.5x"); + check(!p->feature_set_option(p->ctx,out,"damage","multiplier","100000"), + "launcher rejects out-of-range multiplier"); + const unsigned scales[] = {10,25,50,100,125,200,1000}; + for (unsigned path = 0; path < 3; ++path) for (unsigned i = 0; i < 7; ++i) { + MmxDamageSetDealt(scales[i]); + weakness_actor_setup(2,9,0,4,0); /* Fire Wave against Chill Penguin: 3 HP. */ + damage_call(path,0,0); + unsigned expected = (3 * scales[i] + 50) / 100; + if (!expected) expected = 1; + check((g_ram[0xe8f]&127) == 32-expected,"native X1 weakness damage scales in each execution path"); + for (unsigned row = 0; row <= 5; row += 5) { + weakness_actor_setup(2,row,0,4,0); damage_call(path,0,0); + check((g_ram[0xe8f]&127) == 32,"multipliers preserve immunity and reflection"); + } + } + const char *x2=getenv("MMX_DAMAGE_X2_ASSETS"), *x3=getenv("MMX_DAMAGE_X3_ASSETS"); + if (x2 && x3) { + check(MmxWeaponsLoadPage(x2,1) && MmxWeaponsLoadPage(x3,2),"damage test loads imported weapons"); + for (unsigned path=0;path<3;++path) for (unsigned i=0;iboss,w->row,w->page,w->weapon,charged); + damage_call(path,0,0); + check((g_ram[0xe8f]&127)==32-2*(charged?w->charged:w->normal), + "imported normal and charged weakness damage is multiplied once"); + } + } + MmxWeaponsDisable(); + } + const char *zero = getenv("MMX_DAMAGE_ZERO_ASSETS"); + if (zero) { + check(MmxZeroLoad(zero), "damage test loads Zero's original assets"); + for (unsigned character=0;character<2;++character) for (unsigned path=0;path<3;++path) { + MmxZeroState z={0}; z.active_x=character==0; MmxZeroSetState(z); + MmxDamageSetDealt(200); weakness_actor_setup(2,9,0,4,0); damage_call(path,0,0); + check((g_ram[0xe8f]&127)==(character?29:26), + "real character selection multiplies X attacks and preserves Zero attacks"); + } + MmxZeroDisable(); + } + MmxDamageReset(); + hitbox_boot(); + unsigned enemy=0; + for (unsigned i=0;i<400 && !enemy;++i) { + frame(SNES_PAD_RIGHT); + if (!g_ram[0xbb6] || g_ram[0xba9]!=2 || g_ram[0xbaa]==4) continue; + for (unsigned d=0xe68;d<0x1228;d+=64) + if (g_ram[d] && g_ram[d+14] && (g_ram[d+0x27]&127) && + (g_ram[d+0x20]|g_ram[d+0x21])) { enemy=d; break; } + } + check(enemy!=0,"real native enemy found for damage contact"); + static uint8_t world[0x20000]; memcpy(world,g_ram,sizeof(world)); + for (unsigned kind=1;kind<=2;++kind) for (unsigned path=0;path<2;++path) + for (unsigned armor=0;armor<2;++armor) for (unsigned i=0;i<7;++i) { + memcpy(g_ram,world,sizeof(world)); + MmxDamageSetReceived(scales[i]); + memcpy(g_ram+0xbad,g_ram+enemy+5,2);memcpy(g_ram+0xbb0,g_ram+enemy+8,2); + g_ram[0xc30]=g_ram[0xc32]=0;g_ram[0xbcf]=32;g_ram[0xbce]=8; + g_ram[enemy+0x26]=8;g_ram[0x1f99]=armor?4:0; + damage_call(path,kind,enemy); + unsigned expected=((armor?4:8)*scales[i]+50)/100; + if (!expected) expected=1; + if ((g_ram[0xbcf]&127)!=(expected>=32?0:32-expected)) + fprintf(stderr,"damage mismatch kind=%u path=%u armor=%u scale=%u enemy=%04x class=%02x HP=%u expected=%u scratch=%u hurt=%u\n", + kind,path,armor,scales[i],enemy,g_ram[enemy+10],g_ram[0xbcf]&127, + expected>=32?0:32-expected,g_ram[0],g_ram[0xbaa]); + check((g_ram[0xbcf]&127)==(expected>=32?0:32-expected), + "native enemy and scripted damage scale after armor without health wrap"); + } + for (unsigned path=0;path<2;++path) for (unsigned armor=0;armor<2;++armor) { + memcpy(g_ram,world,sizeof(world));g_ram[0xbcf]=32;g_ram[0xbce]=127;g_ram[0x1f99]=armor?4:0; + MmxDamageSetReceived(10);damage_call(path,2,enemy); + check(!(g_ram[0xbcf]&127),"0.1x keeps native instant-death hazards fatal with or without armor"); + } + check(p->feature_enable(p->ctx,out,"damage",0) && p->feature_enable(p->ctx,in,"damage",0) && + p->commit(p->ctx,rom_path),"launcher disables both mods"); + snes_mod_runtime_activate_plugins_c(); + check(MmxDamageDealt(4)==4 && MmxDamageReceived(4,false)==4, + "disabling mods resets both multipliers to native behavior"); + puts("MMX DAMAGE RUNTIME CHECKS PASSED"); +} diff --git a/tests/mmx_damage_test.c b/tests/mmx_damage_test.c new file mode 100644 index 00000000..6f65640c --- /dev/null +++ b/tests/mmx_damage_test.c @@ -0,0 +1,61 @@ +#include "mmx_damage.h" +#include +#include +#include + +static bool actor_x = true; +bool MmxCoopActorIsX(void) { return actor_x; } + +int main(void) { + assert(MmxDamageParseMultiplier("0.1") == 10); + assert(MmxDamageParseMultiplier("0.25") == 25); + assert(MmxDamageParseMultiplier("0.5") == 50); + assert(MmxDamageParseMultiplier("1") == 100); + assert(MmxDamageParseMultiplier("1.25") == 125); + assert(MmxDamageParseMultiplier("2") == 200); + assert(MmxDamageParseMultiplier("10") == 1000); + assert(MmxDamageParseMultiplier("0") == 10); + const char *invalid[] = {NULL,"","-1","nan","inf","1e9","1x",".5","1.","0.001","99999999999999999999"}; + for (unsigned i = 0; i < sizeof(invalid)/sizeof(*invalid); ++i) + assert(MmxDamageParseMultiplier(invalid[i]) == 100); + MmxDamageReset(); + assert(!MmxDamageDealtEnabled()); + for (unsigned damage = 0; damage <= 127; ++damage) { + assert(MmxDamageDealt(damage) == damage); + assert(MmxDamageReceived(damage, false) == damage); + } + MmxDamageSetDealt(200); + assert(MmxDamageDealt(4) == 8); + assert(MmxDamageReceived(4, false) == 4); + actor_x = false; + assert(MmxDamageDealt(4) == 4); + actor_x = true; + MmxDamageSetReceived(50); + assert(MmxDamageReceived(4, false) == 2); + assert(MmxDamageReceived(3, false) == 2); + assert(MmxDamageReceived(1, false) == 1); + assert(MmxDamageReceived(64, true) == 64); + assert(MmxDamageReceived(127, true) == 127); + MmxDamageSetDealt(50); + assert(MmxDamageDealt(4) == 2); + /* Exhaust the supported operand/multiplier range: monotonic, bounded, + * positive hits cannot wrap or become immune, and zero stays zero. */ + for (unsigned multiplier = 10; multiplier <= 1000; ++multiplier) { + MmxDamageSetDealt(multiplier); MmxDamageSetReceived(multiplier); + unsigned previous = 0; + for (unsigned damage = 0; damage <= 127; ++damage) { + unsigned result = MmxDamageDealt(damage); + assert(result <= 127 && result >= previous); + assert((result == 0) == (damage == 0)); + assert(result == MmxDamageReceived(damage, false)); + previous = result; + } + } + MmxDamageSetDealt(UINT_MAX); MmxDamageSetReceived(0); + assert(MmxDamageDealt(UINT_MAX) == 127); + assert(MmxDamageReceived(10, false) == 1); + MmxDamageReset(); + assert(MmxDamageDealt(4) == 4 && MmxDamageReceived(4, false) == 4); + puts("MMX DAMAGE ARITHMETIC CHECKS PASSED"); + return 0; +} diff --git a/tools/apply_damage_hooks.py b/tools/apply_damage_hooks.py new file mode 100644 index 00000000..afc97511 --- /dev/null +++ b/tools/apply_damage_hooks.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +"""Scale the final player hurt operand after native armor reduction.""" +import argparse +from pathlib import Path +import re + +MARKER = '/*MMX-DAMAGE*/' +REQUIRED = {0x049d50, 0x849d50, 0x849f59} + + +def apply(text): + output, found, pc = [], set(), 0 + for line in text.splitlines(keepends=True): + if MARKER in line: + continue + output.append(line) + block = re.search(r'cpu_trace_block\(cpu, 0x([0-9a-fA-F]+)\)', line) + if block: + pc = int(block[1], 16) + if (pc & 0x7fffff) not in (0x049d50, 0x049f59): + continue + load = re.search(r'uint8 (_v\d+) = cpu_read8\(cpu, cpu->DB, \(uint16\)\(0x0000\)\);', line) + if load: + lethal = 'g_ram[(cpu->D + 0x26) & 65535]' if (pc & 65535) == 0x9d50 else 'g_ram[0xbce]' + output.append(f' {MARKER} {{ extern uint8_t g_ram[0x20000]; extern unsigned MmxDamageReceived(unsigned, bool); {load[1]} = (uint8)MmxDamageReceived({load[1]}, {lethal} >= 127); }}\n') + found.add(pc) + return ''.join(output), found + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--gen-dir', type=Path, required=True) + args = parser.parse_args() + found = set() + for path in args.gen_dir.glob('bank*04*_v2.c'): + updated, hits = apply(path.read_text(encoding='utf-8')) + found |= hits + if updated != path.read_text(encoding='utf-8'): + path.write_text(updated, encoding='utf-8', newline='\n') + for path in args.gen_dir.glob('bank84*_v2.c'): + original = path.read_text(encoding='utf-8') + updated, hits = apply(original) + found |= hits + if updated != original: + path.write_text(updated, encoding='utf-8', newline='\n') + if REQUIRED - found: + raise SystemExit(f'Missing damage operand hooks: {REQUIRED - found}') + print(f'MMX damage: {len(found)} native operand blocks verified') + + +if __name__ == '__main__': + main() diff --git a/tools/apply_zero_hooks.py b/tools/apply_zero_hooks.py index ecbebbc8..2879b1e5 100644 --- a/tools/apply_zero_hooks.py +++ b/tools/apply_zero_hooks.py @@ -131,9 +131,9 @@ def apply(text): found.add(pc) # The ordinary damage table still decides immunity and reflection. # Override only the final subtraction in the positive-damage path. - if pc == 0x849e6e and 'uint8 ' in line and 'cpu_read8' in line and '0xef37' in line: + if (pc & 0x7fffff) == 0x049e6e and 'uint8 ' in line and 'cpu_read8' in line and '0xef37' in line: variable = re.search(r'uint8 (_v\d+)', line)[1] - output.append(f' {MARKER} {{ extern uint8_t g_ram[0x20000]; extern unsigned MmxZeroDamage(uint8_t *, unsigned, unsigned, unsigned); extern unsigned MmxWeaponsDamage(uint8_t *, unsigned, unsigned, unsigned); {variable} = (uint8)MmxWeaponsDamage(g_ram, cpu->D, cpu->X, MmxZeroDamage(g_ram, cpu->D, cpu->X, {variable})); }}\n') + output.append(f' {MARKER} {{ extern uint8_t g_ram[0x20000]; extern unsigned MmxZeroDamage(uint8_t *, unsigned, unsigned, unsigned); extern unsigned MmxWeaponsDamage(uint8_t *, unsigned, unsigned, unsigned); extern unsigned MmxDamageDealt(unsigned); {variable} = (uint8)MmxDamageDealt(MmxWeaponsDamage(g_ram, cpu->D, cpu->X, MmxZeroDamage(g_ram, cpu->D, cpu->X, {variable}))); }}\n') found.add(0x849e73) if pc in PCS: load = re.search(r'uint8 (_v\d+) = cpu_read8\(cpu, cpu->DB, \(uint16\)\(0x1f99\)\);', line) From 48f8a0e0fe37ffa842bb39d5b2ee939e67f06e2d Mon Sep 17 00:00:00 2001 From: Matt Stanley <5354790+mstan@users.noreply.github.com> Date: Sun, 8 Nov 2026 23:19:49 -0800 Subject: [PATCH 2/2] Carry fractional damage between hits and preserve it in snapshots --- README.md | 8 +- .../{1.0.0 => 1.0.1}/manifest.toml | 4 +- .../{1.0.0 => 1.0.1}/manifest.toml | 4 +- src/mmx_coop.c | 5 + src/mmx_damage.c | 88 ++++++++++++-- src/mmx_damage.h | 19 ++- src/mmx_rtl.c | 20 ++- src/mods/mmx_damage_plugin.c | 2 +- src/mods/mmx_zero_plugin.c | 2 +- tests/mmx_damage_runtime_test.inc | 40 +++++- tests/mmx_damage_test.c | 115 ++++++++++-------- tools/apply_damage_hooks.py | 2 +- tools/apply_zero_hooks.py | 2 +- tools/make_release.ps1 | 2 +- 14 files changed, 229 insertions(+), 84 deletions(-) rename mods/preloaded/packages/megaman-x.gameplay.damage-dealt/{1.0.0 => 1.0.1}/manifest.toml (88%) rename mods/preloaded/packages/megaman-x.gameplay.damage-received/{1.0.0 => 1.0.1}/manifest.toml (89%) diff --git a/README.md b/README.md index 9ed61f63..3f4e5ebd 100644 --- a/README.md +++ b/README.md @@ -145,9 +145,11 @@ and choose its **Damage multiplier**. The two mods are independent: 0.5x halves damage, 1x keeps normal damage, and 2x doubles it. Choices range from 0.1x to 10x; both mods start disabled with 1x selected. X's multiplier includes native and imported weapons and leaves Zero's attacks unchanged. Received damage -applies to both characters after armor reduction. Positive damage rounds to -the nearest whole HP (halves round up), with a minimum of 1 and maximum of 127. -Immunities and instant-death hazards keep their native behavior. +applies to both characters after armor reduction. Fractional damage carries +between hits, separately for each enemy and player: at 0.1x, five 2-HP hits +cost 1 HP in total. Individual hits can cause no HP loss while retaining their +normal hurt reaction. Damage caps safely at 127 HP. Immunities and instant-death +hazards keep their native behavior. Save states and rewind preserve fractions. ### Which ROM? diff --git a/mods/preloaded/packages/megaman-x.gameplay.damage-dealt/1.0.0/manifest.toml b/mods/preloaded/packages/megaman-x.gameplay.damage-dealt/1.0.1/manifest.toml similarity index 88% rename from mods/preloaded/packages/megaman-x.gameplay.damage-dealt/1.0.0/manifest.toml rename to mods/preloaded/packages/megaman-x.gameplay.damage-dealt/1.0.1/manifest.toml index 976925a5..cddfd763 100644 --- a/mods/preloaded/packages/megaman-x.gameplay.damage-dealt/1.0.0/manifest.toml +++ b/mods/preloaded/packages/megaman-x.gameplay.damage-dealt/1.0.1/manifest.toml @@ -1,6 +1,6 @@ format_version = 1 id = "megaman-x.gameplay.damage-dealt" -version = "1.0.0" +version = "1.0.1" name = "X damage dealt" author = "mstan" description = "Multiply damage dealt by X, including native and imported weapons. Zero retains his own damage." @@ -23,7 +23,7 @@ default_enabled = false feature = "damage" id = "multiplier" label = "Damage multiplier" -description = "1x is normal, 0.5x is half, 2x is double. Rounded to the nearest HP with a minimum of 1 for damaging hits and a maximum of 127. Immunities remain unchanged." +description = "1x is normal, 0.5x is half, 2x is double. Fractional damage carries between hits; some hits cost no HP. Maximum 127 HP per hit. Immunities remain unchanged." type = "choice" default = "1" diff --git a/mods/preloaded/packages/megaman-x.gameplay.damage-received/1.0.0/manifest.toml b/mods/preloaded/packages/megaman-x.gameplay.damage-received/1.0.1/manifest.toml similarity index 89% rename from mods/preloaded/packages/megaman-x.gameplay.damage-received/1.0.0/manifest.toml rename to mods/preloaded/packages/megaman-x.gameplay.damage-received/1.0.1/manifest.toml index b69a4bb1..ff89d87f 100644 --- a/mods/preloaded/packages/megaman-x.gameplay.damage-received/1.0.0/manifest.toml +++ b/mods/preloaded/packages/megaman-x.gameplay.damage-received/1.0.1/manifest.toml @@ -1,6 +1,6 @@ format_version = 1 id = "megaman-x.gameplay.damage-received" -version = "1.0.0" +version = "1.0.1" name = "Player damage received" author = "mstan" description = "Multiply damage received by either player after armor reduction. Instant-death hazards retain their native behavior." @@ -23,7 +23,7 @@ default_enabled = false feature = "damage" id = "multiplier" label = "Damage multiplier" -description = "1x is normal, 0.5x is half, 2x is double. Rounded to the nearest HP with a minimum of 1 for damaging hits and a maximum of 127. Immunities remain unchanged." +description = "1x is normal, 0.5x is half, 2x is double. Fractional damage carries between hits; some hits cost no HP. Maximum 127 HP per hit. Immunities remain unchanged." type = "choice" default = "1" diff --git a/src/mmx_coop.c b/src/mmx_coop.c index 551d3af9..082f1c94 100644 --- a/src/mmx_coop.c +++ b/src/mmx_coop.c @@ -1,4 +1,5 @@ #include "mmx_coop.h" +#include "mmx_damage.h" #include "mmx_coop_view.h" #include "mmx_renderer.h" #include "mmx_coop_trace.h" @@ -1903,6 +1904,7 @@ static struct { uint8_t pass,kind,p,db;uint16_t a,x,y,s,d;uint32_t resume; uint8_t body[0x90]; MmxWeaponCombatState combat;MmxZeroState zero;MmxRendererPieceMark pieces; + MmxDamageState damage; MmxCoopViewWorldState world; } shot_ghost; static MmxBossRushAudioState shot_ghost_audio; @@ -1975,6 +1977,7 @@ static void shot_ghost_begin(CpuState *cpu,unsigned kind,uint32_t resume) { shot_ghost.kind=(uint8_t)kind;shot_ghost.resume=resume; memcpy(shot_ghost_ram,g_ram,sizeof(shot_ghost_ram)); shot_ghost.combat=MmxWeaponsGetCombatState();shot_ghost.zero=MmxZeroGetState(); + shot_ghost.damage=MmxDamageGetState(); shot_ghost.pieces=MmxRendererMarkPieces();shot_ghost.world=MmxCoopViewsGetWorldState(); shot_ghost_state=state;shot_ghost_audio=MmxBossRushAudioGetState(); memcpy(shot_ghost_lift,&lift,sizeof(lift));memcpy(shot_ghost_cart,&cart,sizeof(cart)); @@ -1994,6 +1997,8 @@ static void shot_ghost_end(CpuState *cpu,uint32_t pc) { memcpy(g_ram,shot_ghost_ram,sizeof(shot_ghost_ram)); memcpy(g_ram+GHOST_SPC_MIRROR,spc,sizeof(spc)); MmxWeaponsSetCombatState(shot_ghost.combat);MmxZeroSelectState(shot_ghost.zero); + if(shot_ghost.kind==GHOST_SHOTS) MmxDamageSetState(&shot_ghost.damage); + else MmxDamageRestoreWorld(&shot_ghost.damage); MmxRendererRewindPieces(shot_ghost.pieces);MmxCoopViewsSetWorldState(&shot_ghost.world); state=shot_ghost_state;MmxBossRushAudioSetState(&shot_ghost_audio); memcpy(&lift,shot_ghost_lift,sizeof(lift));memcpy(&cart,shot_ghost_cart,sizeof(cart)); diff --git a/src/mmx_damage.c b/src/mmx_damage.c index 35a9dc8c..068e0c91 100644 --- a/src/mmx_damage.c +++ b/src/mmx_damage.c @@ -1,7 +1,9 @@ #include "mmx_damage.h" #include "mmx_coop.h" +#include static unsigned dealt = MMX_DAMAGE_NORMAL, received = MMX_DAMAGE_NORMAL; +static MmxDamageState state; static unsigned bound(unsigned value) { return value < MMX_DAMAGE_MIN ? MMX_DAMAGE_MIN : @@ -30,25 +32,87 @@ unsigned MmxDamageParseMultiplier(const char *value) { return bound(whole * 100 + fraction); } -void MmxDamageSetDealt(unsigned value) { dealt = bound(value); } -void MmxDamageSetReceived(unsigned value) { received = bound(value); } -void MmxDamageReset(void) { dealt = received = MMX_DAMAGE_NORMAL; } +void MmxDamageSetDealt(unsigned value) { + dealt = bound(value); memset(state.enemies,0,sizeof(state.enemies)); +} +void MmxDamageSetReceived(unsigned value) { + received = bound(value); memset(state.received,0,sizeof(state.received)); state.hp_valid=0; +} +void MmxDamageClearState(void) { memset(&state,0,sizeof(state)); } +void MmxDamageReset(void) { dealt = received = MMX_DAMAGE_NORMAL; MmxDamageClearState(); } bool MmxDamageDealtEnabled(void) { return dealt != MMX_DAMAGE_NORMAL; } -static unsigned scale(unsigned damage, unsigned multiplier) { +MmxDamageState MmxDamageGetState(void) { return state; } +bool MmxDamageValidState(const MmxDamageState *s) { + if(!s || s->hp_valid>3 || s->stage_valid>1) return false; + for(unsigned i=0;i<2;++i) if(s->received[i]>=100 || s->hp[i]>127) return false; + for(unsigned i=0;i<15;++i) + if(s->enemies[i].fraction>=100 || s->enemies[i].hp>127 || s->enemies[i].active>1) return false; + return true; +} +void MmxDamageSetState(const MmxDamageState *s) { + if(MmxDamageValidState(s)) state=*s; else MmxDamageClearState(); +} +void MmxDamageRestoreWorld(const MmxDamageState *s) { + memcpy(state.enemies,s->enemies,sizeof(state.enemies)); + state.stage=s->stage; state.stage_valid=s->stage_valid; +} +static void stage(const uint8_t *r) { + if(!state.stage_valid || state.stage!=r[0x1f7a]) { + MmxDamageClearState(); state.stage=r[0x1f7a]; state.stage_valid=1; + } +} +static void health(const uint8_t *r,unsigned actor,unsigned hp) { + if(!hp || ((state.hp_valid&(1u<state.hp[actor] && hp>=r[0x1f9a])) + state.received[actor]=0; + state.hp[actor]=(uint8_t)hp; state.hp_valid|=(uint8_t)(1u<active && (r[d+10]!=e->kind || (r[d+0x27]&127)>e->hp))) + memset(e,0,sizeof(*e)); + } + if(received%100) { + if(MmxCoopEnabled()) for(unsigned actor=0;actor<2;++actor) { + const uint8_t *body=MmxCoopCharacterBody((uint8_t *)r,actor); + health(r,actor,body?body[0x27]&127:0); + } else health(r,MmxCoopActorIsX()?0:1,r[0xbcf]&127); + } +} +static unsigned scale(unsigned damage, unsigned multiplier, uint8_t *fraction) { if (!damage || multiplier == MMX_DAMAGE_NORMAL) return damage; - /* HP uses seven bits. Bound the input before multiplying and round half up. - * A positive hit stays positive; immunity and suppressed repeat hits stay 0. */ + /* Carry hundredths between actual hits. Zero HP loss still keeps the native + * hurt reaction; weak hits cannot be promoted to a full HP on every contact. */ if (damage > 127) damage = 127; - unsigned result = (damage * multiplier + 50) / 100; - return result < 1 ? 1 : result > 127 ? 127 : result; + unsigned scaled = damage * multiplier + *fraction; + unsigned result = scaled / 100; + *fraction=(uint8_t)(result>=127?0:scaled%100); + return result > 127 ? 127 : result; } -unsigned MmxDamageDealt(unsigned damage) { - return dealt != MMX_DAMAGE_NORMAL && MmxCoopActorIsX() ? scale(damage, dealt) : damage; +unsigned MmxDamageDealt(const uint8_t *r,unsigned enemy,unsigned damage) { + if(!damage || dealt==100 || !MmxCoopActorIsX()) return damage; + stage(r); + if(enemy<0xe68 || enemy>=0x1228 || (enemy-0xe68)%64) return damage; + unsigned hp=r[enemy+0x27]&127; + MmxDamageEnemy *e=state.enemies+(enemy-0xe68)/64; + if(!e->active || e->kind!=r[enemy+10] || hp>e->hp) e->fraction=0; + e->active=1; e->kind=r[enemy+10]; + unsigned result=scale(damage,dealt,&e->fraction); + e->hp=(uint8_t)(result>=hp?0:hp-result); + return result; } -unsigned MmxDamageReceived(unsigned damage, bool lethal) { +unsigned MmxDamageReceived(const uint8_t *r,unsigned damage, bool lethal) { /* Spikes, pits and crushers retain their native fatal result, including * the armor-reduced operand. Learner Mode's zero damage remains zero. */ - return lethal ? damage : scale(damage, received); + if(!damage || received==100) return damage; + stage(r); unsigned actor=MmxCoopActorIsX()?0:1, hp=r[0xbcf]&127; + health(r,actor,hp); + if(lethal) {state.received[actor]=0;state.hp[actor]=0;return damage;} + unsigned result=scale(damage,received,&state.received[actor]); + state.hp[actor]=(uint8_t)(result>=hp?0:hp-result); + return result; } diff --git a/src/mmx_damage.h b/src/mmx_damage.h index e8d8b6a4..86f03e51 100644 --- a/src/mmx_damage.h +++ b/src/mmx_damage.h @@ -1,5 +1,6 @@ #pragma once #include +#include /* Multipliers use hundredths: 50 = 0.5x, 100 = 1x, 200 = 2x. * Configuration is fixed for a session; the mod identity carries it for netplay. */ @@ -8,6 +9,20 @@ unsigned MmxDamageParseMultiplier(const char *value); void MmxDamageSetDealt(unsigned hundredths); void MmxDamageSetReceived(unsigned hundredths); void MmxDamageReset(void); +typedef struct MmxDamageEnemy { + uint8_t fraction, kind, hp, active; +} MmxDamageEnemy; +typedef struct MmxDamageState { + MmxDamageEnemy enemies[15]; + uint8_t received[2], hp[2], hp_valid, stage, stage_valid; +} MmxDamageState; +void MmxDamageClearState(void); +void MmxDamageFrame(const uint8_t *ram); +MmxDamageState MmxDamageGetState(void); +bool MmxDamageValidState(const MmxDamageState *state); +void MmxDamageSetState(const MmxDamageState *state); +/* Ghost world hits are rolled back, while actual partner hurt is retained. */ +void MmxDamageRestoreWorld(const MmxDamageState *state); bool MmxDamageDealtEnabled(void); -unsigned MmxDamageDealt(unsigned damage); -unsigned MmxDamageReceived(unsigned damage, bool lethal); +unsigned MmxDamageDealt(const uint8_t *ram, unsigned enemy, unsigned damage); +unsigned MmxDamageReceived(const uint8_t *ram, unsigned damage, bool lethal); diff --git a/src/mmx_rtl.c b/src/mmx_rtl.c index 50fe3372..81d43b75 100644 --- a/src/mmx_rtl.c +++ b/src/mmx_rtl.c @@ -2,6 +2,7 @@ #include "mmx_wide_policy.h" #include "mmx_renderer.h" #include "mmx_zero.h" +#include "mmx_damage.h" #include "mmx_armor.h" #include "mmx_weapons.h" #include "mmx_weapon_combat.h" @@ -368,7 +369,7 @@ void mmx_host_yield(uint8_t countdown) { #include "snes/saveload.h" #define MMX_SAV_CHUNK_MAGIC 0x4D4D5854u /* "MMXT" */ -#define MMX_SAV_CHUNK_VERSION 25u /* independent native camera pan history */ +#define MMX_SAV_CHUNK_VERSION 26u /* fractional damage accumulation */ typedef struct MmxSavChunk { uint32_t magic, version; @@ -404,6 +405,7 @@ static MmxWeaponCombatState g_load_weapon_combat; static MmxCoopState g_load_coop; static MmxKncBugfixState g_load_knc_bugfix; static MmxArmorState g_load_armor; +static MmxDamageState g_load_damage; static MmxCoopViewWorldState g_load_views; static MmxCoopViewBoundsState g_load_view_bounds; static uint8_t g_load_zero_extension[MMX_ZERO_EXTENSION_STATE_BYTES]; @@ -470,6 +472,8 @@ void MmxStateSaveExtra(struct SaveLoadInfo *sli) { sli->func(sli,&bounds,sizeof(bounds)); MmxArmorState armor=MmxArmorGetState(); sli->func(sli,&armor,sizeof(armor)); + MmxDamageState damage=MmxDamageGetState(); + sli->func(sli,&damage,sizeof(damage)); } void MmxStateLoadExtra(struct SaveLoadInfo *sli, uint32_t version) { @@ -482,6 +486,7 @@ void MmxStateLoadExtra(struct SaveLoadInfo *sli, uint32_t version) { memset(&g_load_coop, 0, sizeof(g_load_coop)); memset(&g_load_knc_bugfix,0,sizeof(g_load_knc_bugfix)); memset(&g_load_armor,0,sizeof(g_load_armor)); + memset(&g_load_damage,0,sizeof(g_load_damage)); memset(&g_load_views,0,sizeof(g_load_views)); memset(&g_load_view_bounds,0,sizeof(g_load_view_bounds)); memset(g_load_zero_extension,0,sizeof(g_load_zero_extension)); @@ -574,7 +579,8 @@ void MmxStateLoadExtra(struct SaveLoadInfo *sli, uint32_t version) { bool rush=g_load_chunk.version>=21 || !extension; size_t expected=(extension?sizeof(g_load_zero_extension):0)+(rush?rush_bytes:0)+ (g_load_chunk.version>=22?sizeof(g_load_view_bounds):0)+ - (g_load_chunk.version>=24?sizeof(g_load_armor):0); + (g_load_chunk.version>=24?sizeof(g_load_armor):0)+ + (g_load_chunk.version>=26?sizeof(g_load_damage):0); if(remaining!=expected) g_load_chunk_ok=0; if(g_load_chunk_ok && extension) sli->func(sli,g_load_zero_extension,sizeof(g_load_zero_extension)); @@ -604,6 +610,13 @@ void MmxStateLoadExtra(struct SaveLoadInfo *sli, uint32_t version) { if(!MmxArmorValidState(&g_load_armor))g_load_chunk_ok=0; } } + if(g_load_complete && g_load_chunk_ok && g_load_chunk.version>=26) { + if(RtlStateBytesRemaining(sli)func(sli,&g_load_damage,sizeof(g_load_damage)); + if(!MmxDamageValidState(&g_load_damage))g_load_chunk_ok=0; + } + } if (!g_load_chunk_ok) fprintf(stderr, "[mmx_state] load: bad game chunk (magic=%08x ver=%u)\n", g_load_chunk.magic, g_load_chunk.version); @@ -641,6 +654,7 @@ void MmxOnStateLoaded(uint32_t version) { MmxWideStateApply(complete); MmxZeroSetState(g_load_zero); MmxArmorSetState(g_load_armor); + MmxDamageSetState(complete?&g_load_damage:NULL); if (complete) MmxZeroExtLoadState(g_load_zero_extension); MmxWeaponsSetState(g_load_weapons); MmxWeaponsSetCombatState(g_load_weapon_combat); @@ -948,6 +962,7 @@ void MmxDrawPpuFrame(void) { } void RunOneFrameOfGame(void) { + MmxDamageFrame(g_ram); RtlSetPadState(0,MmxBossRushFilterInput(RtlGetPadState(0))); s_graphics_frame_start = g_cpu.master_cycles; s_graphics_frame_active = g_did_reset; @@ -2073,6 +2088,7 @@ static void MmxWideStateApply(bool loaded) { * recovers (GitHub #45). Runs on the main fiber, never inside a slot fiber, * so every slot fiber can be deleted here. */ void MmxOnHardwareReset(void) { + MmxDamageClearState(); MmxArmorResetState(); MmxBossRushReset();MmxBossRushAudioReset(); MmxCoopReset(); diff --git a/src/mods/mmx_damage_plugin.c b/src/mods/mmx_damage_plugin.c index ad96af8f..ea55e9f8 100644 --- a/src/mods/mmx_damage_plugin.c +++ b/src/mods/mmx_damage_plugin.c @@ -10,7 +10,7 @@ static void received_hook(CpuState *cpu, uint32_t pc) { bool contact = (pc & 65535) == 0x9d59; unsigned original = g_ram[0]; bool lethal = (contact ? g_ram[(cpu->D + 0x26) & 65535] : g_ram[0xbce]) >= 127; - unsigned damage = MmxDamageReceived(original, lethal); + unsigned damage = MmxDamageReceived(g_ram, original, lethal); if (damage == original) return; /* Post-SBC / pre-STA: keep guest instruction timing, carry/overflow and * both accumulator bytes identical to a native SBC using the new operand. */ diff --git a/src/mods/mmx_zero_plugin.c b/src/mods/mmx_zero_plugin.c index c13574c1..a45cac7b 100644 --- a/src/mods/mmx_zero_plugin.c +++ b/src/mods/mmx_zero_plugin.c @@ -178,7 +178,7 @@ static void hook(CpuState *cpu, uint32_t pc) { } case 0x049e76: { unsigned original = cpu_read8(cpu, cpu->DB, (uint16_t)(0xef37 + cpu->Y)); - unsigned damage = MmxDamageDealt(MmxWeaponsDamage(g_ram, cpu->D, cpu->X, + unsigned damage = MmxDamageDealt(g_ram,cpu->D,MmxWeaponsDamage(g_ram, cpu->D, cpu->X, MmxZeroDamage(g_ram, cpu->D, cpu->X, original))); if (damage == original) break; /* Post-SBC: retain the interpreter's instruction timing, but recompute diff --git a/tests/mmx_damage_runtime_test.inc b/tests/mmx_damage_runtime_test.inc index 9a71567c..4ff6b2f7 100644 --- a/tests/mmx_damage_runtime_test.inc +++ b/tests/mmx_damage_runtime_test.inc @@ -39,7 +39,7 @@ static void damage_runtime_checks(const char *rom_path) { p->feature_set_option(p->ctx,in,"damage","multiplier","0.5") && p->commit(p->ctx,rom_path), "launcher commits independent multipliers"); snes_mod_runtime_activate_plugins_c(); - check(MmxDamageDealt(4) == 8 && MmxDamageReceived(4,false) == 2, + check(MmxDamageDealt(g_ram,0xe68,4) == 8 && MmxDamageReceived(g_ram,4,false) == 2, "real plugins activate outgoing 2x and incoming 0.5x"); check(!p->feature_set_option(p->ctx,out,"damage","multiplier","100000"), "launcher rejects out-of-range multiplier"); @@ -48,8 +48,7 @@ static void damage_runtime_checks(const char *rom_path) { MmxDamageSetDealt(scales[i]); weakness_actor_setup(2,9,0,4,0); /* Fire Wave against Chill Penguin: 3 HP. */ damage_call(path,0,0); - unsigned expected = (3 * scales[i] + 50) / 100; - if (!expected) expected = 1; + unsigned expected = 3 * scales[i] / 100; check((g_ram[0xe8f]&127) == 32-expected,"native X1 weakness damage scales in each execution path"); for (unsigned row = 0; row <= 5; row += 5) { weakness_actor_setup(2,row,0,4,0); damage_call(path,0,0); @@ -101,8 +100,7 @@ static void damage_runtime_checks(const char *rom_path) { g_ram[0xc30]=g_ram[0xc32]=0;g_ram[0xbcf]=32;g_ram[0xbce]=8; g_ram[enemy+0x26]=8;g_ram[0x1f99]=armor?4:0; damage_call(path,kind,enemy); - unsigned expected=((armor?4:8)*scales[i]+50)/100; - if (!expected) expected=1; + unsigned expected=(armor?4:8)*scales[i]/100; if ((g_ram[0xbcf]&127)!=(expected>=32?0:32-expected)) fprintf(stderr,"damage mismatch kind=%u path=%u armor=%u scale=%u enemy=%04x class=%02x HP=%u expected=%u scratch=%u hurt=%u\n", kind,path,armor,scales[i],enemy,g_ram[enemy+10],g_ram[0xbcf]&127, @@ -110,6 +108,36 @@ static void damage_runtime_checks(const char *rom_path) { check((g_ram[0xbcf]&127)==(expected>=32?0:32-expected), "native enemy and scripted damage scale after armor without health wrap"); } + for(unsigned kind=1;kind<=2;++kind) for(unsigned path=0;path<2;++path) { + memcpy(g_ram,world,sizeof(world));MmxDamageSetReceived(10); + memcpy(g_ram+0xbad,g_ram+enemy+5,2);memcpy(g_ram+0xbb0,g_ram+enemy+8,2); + g_ram[0xbcf]=16;g_ram[0xbce]=2;g_ram[enemy+0x26]=2;g_ram[0x1f99]=0; + uint8_t *snapshot=malloc(2*1024*1024);size_t saved=0; + check(snapshot!=NULL,"fractional damage snapshot allocates"); + for(unsigned hit=0;hit<10;++hit) { + g_ram[0xc30]=g_ram[0xc32]=0;g_ram[0xbcf]&=127; + damage_call(path,kind,enemy); + if((g_ram[0xbcf]&127)!=16-(hit+1)*2/10) + fprintf(stderr,"fraction hit=%u kind=%u path=%u HP=%u carry=%u scratch=%u contact=%u actor=%u\n", + hit,kind,path,g_ram[0xbcf]&127,MmxDamageGetState().received[0],g_ram[0xbce],g_ram[enemy+0x26],g_ram[0xbaa]); + check((g_ram[0xbcf]&127)==16-(hit+1)*2/10, + "0.1x native damage loses exactly 1 HP per five 2-HP hits"); + if(hit==2) { + frame(0); + saved=RtlSaveSnapshotToMemory(snapshot,2*1024*1024); + check(saved!=0 && MmxDamageGetState().received[0]==60, + "save captures a partial incoming HP"); + } + } + check(RtlLoadSnapshotFromMemory(snapshot,saved) && MmxDamageGetState().received[0]==60, + "current-build save/load restores fractional damage"); + for(unsigned hit=0;hit<2;++hit) { + g_ram[0xc30]=g_ram[0xc32]=0;g_ram[0xbcf]&=127;damage_call(path,kind,enemy); + } + check((g_ram[0xbcf]&127)==15 && MmxDamageGetState().received[0]==0, + "replaying restored fractional damage reaches the same HP"); + free(snapshot); + } for (unsigned path=0;path<2;++path) for (unsigned armor=0;armor<2;++armor) { memcpy(g_ram,world,sizeof(world));g_ram[0xbcf]=32;g_ram[0xbce]=127;g_ram[0x1f99]=armor?4:0; MmxDamageSetReceived(10);damage_call(path,2,enemy); @@ -118,7 +146,7 @@ static void damage_runtime_checks(const char *rom_path) { check(p->feature_enable(p->ctx,out,"damage",0) && p->feature_enable(p->ctx,in,"damage",0) && p->commit(p->ctx,rom_path),"launcher disables both mods"); snes_mod_runtime_activate_plugins_c(); - check(MmxDamageDealt(4)==4 && MmxDamageReceived(4,false)==4, + check(MmxDamageDealt(g_ram,0xe68,4)==4 && MmxDamageReceived(g_ram,4,false)==4, "disabling mods resets both multipliers to native behavior"); puts("MMX DAMAGE RUNTIME CHECKS PASSED"); } diff --git a/tests/mmx_damage_test.c b/tests/mmx_damage_test.c index 6f65640c..bf0d67ab 100644 --- a/tests/mmx_damage_test.c +++ b/tests/mmx_damage_test.c @@ -2,60 +2,75 @@ #include #include #include +#include -static bool actor_x = true; +static bool actor_x=true; +static uint8_t ram[0x20000]; bool MmxCoopActorIsX(void) { return actor_x; } - +bool MmxCoopEnabled(void) { return false; } +uint8_t *MmxCoopCharacterBody(uint8_t *r,unsigned actor) { (void)r;(void)actor;return NULL; } +static void fixture(void) { + memset(ram,0,sizeof(ram));ram[0xe68]=ram[0xea8]=1; + ram[0xe8f]=ram[0xecf]=ram[0xbcf]=ram[0x1f9a]=127;actor_x=true;MmxDamageClearState(); +} +static unsigned dealt(unsigned damage) { + unsigned result=MmxDamageDealt(ram,0xe68,damage); + ram[0xe8f]=(uint8_t)(result>=ram[0xe8f]?0:ram[0xe8f]-result);return result; +} +static unsigned received(unsigned damage) { + unsigned result=MmxDamageReceived(ram,damage,false); + ram[0xbcf]=(uint8_t)(result>=ram[0xbcf]?0:ram[0xbcf]-result);return result; +} int main(void) { - assert(MmxDamageParseMultiplier("0.1") == 10); - assert(MmxDamageParseMultiplier("0.25") == 25); - assert(MmxDamageParseMultiplier("0.5") == 50); - assert(MmxDamageParseMultiplier("1") == 100); - assert(MmxDamageParseMultiplier("1.25") == 125); - assert(MmxDamageParseMultiplier("2") == 200); - assert(MmxDamageParseMultiplier("10") == 1000); - assert(MmxDamageParseMultiplier("0") == 10); - const char *invalid[] = {NULL,"","-1","nan","inf","1e9","1x",".5","1.","0.001","99999999999999999999"}; - for (unsigned i = 0; i < sizeof(invalid)/sizeof(*invalid); ++i) - assert(MmxDamageParseMultiplier(invalid[i]) == 100); - MmxDamageReset(); - assert(!MmxDamageDealtEnabled()); - for (unsigned damage = 0; damage <= 127; ++damage) { - assert(MmxDamageDealt(damage) == damage); - assert(MmxDamageReceived(damage, false) == damage); + assert(MmxDamageParseMultiplier("0.1")==10); + assert(MmxDamageParseMultiplier("0.25")==25); + assert(MmxDamageParseMultiplier("1.25")==125); + assert(MmxDamageParseMultiplier("2")==200); + assert(MmxDamageParseMultiplier("10")==1000); + assert(MmxDamageParseMultiplier("0")==10); + const char *invalid[]={NULL,"","-1","nan","inf","1e9","1x",".5","1.","0.001","99999999999999999999"}; + for(unsigned i=0;i127)expected=127; + assert(dealt(d)==expected && received(d)==expected); } - MmxDamageSetDealt(200); - assert(MmxDamageDealt(4) == 8); - assert(MmxDamageReceived(4, false) == 4); - actor_x = false; - assert(MmxDamageDealt(4) == 4); - actor_x = true; - MmxDamageSetReceived(50); - assert(MmxDamageReceived(4, false) == 2); - assert(MmxDamageReceived(3, false) == 2); - assert(MmxDamageReceived(1, false) == 1); - assert(MmxDamageReceived(64, true) == 64); - assert(MmxDamageReceived(127, true) == 127); - MmxDamageSetDealt(50); - assert(MmxDamageDealt(4) == 2); - /* Exhaust the supported operand/multiplier range: monotonic, bounded, - * positive hits cannot wrap or become immune, and zero stays zero. */ - for (unsigned multiplier = 10; multiplier <= 1000; ++multiplier) { - MmxDamageSetDealt(multiplier); MmxDamageSetReceived(multiplier); - unsigned previous = 0; - for (unsigned damage = 0; damage <= 127; ++damage) { - unsigned result = MmxDamageDealt(damage); - assert(result <= 127 && result >= previous); - assert((result == 0) == (damage == 0)); - assert(result == MmxDamageReceived(damage, false)); - previous = result; + const unsigned multipliers[]={10,25,50,75,125,150,175,200}; + for(unsigned i=0;iDB, \(uint16\)\(0x0000\)\);', line) if load: lethal = 'g_ram[(cpu->D + 0x26) & 65535]' if (pc & 65535) == 0x9d50 else 'g_ram[0xbce]' - output.append(f' {MARKER} {{ extern uint8_t g_ram[0x20000]; extern unsigned MmxDamageReceived(unsigned, bool); {load[1]} = (uint8)MmxDamageReceived({load[1]}, {lethal} >= 127); }}\n') + output.append(f' {MARKER} {{ extern uint8_t g_ram[0x20000]; extern unsigned MmxDamageReceived(const uint8_t *, unsigned, bool); {load[1]} = (uint8)MmxDamageReceived(g_ram, {load[1]}, {lethal} >= 127); }}\n') found.add(pc) return ''.join(output), found diff --git a/tools/apply_zero_hooks.py b/tools/apply_zero_hooks.py index 2879b1e5..bf972785 100644 --- a/tools/apply_zero_hooks.py +++ b/tools/apply_zero_hooks.py @@ -133,7 +133,7 @@ def apply(text): # Override only the final subtraction in the positive-damage path. if (pc & 0x7fffff) == 0x049e6e and 'uint8 ' in line and 'cpu_read8' in line and '0xef37' in line: variable = re.search(r'uint8 (_v\d+)', line)[1] - output.append(f' {MARKER} {{ extern uint8_t g_ram[0x20000]; extern unsigned MmxZeroDamage(uint8_t *, unsigned, unsigned, unsigned); extern unsigned MmxWeaponsDamage(uint8_t *, unsigned, unsigned, unsigned); extern unsigned MmxDamageDealt(unsigned); {variable} = (uint8)MmxDamageDealt(MmxWeaponsDamage(g_ram, cpu->D, cpu->X, MmxZeroDamage(g_ram, cpu->D, cpu->X, {variable}))); }}\n') + output.append(f' {MARKER} {{ extern uint8_t g_ram[0x20000]; extern unsigned MmxZeroDamage(uint8_t *, unsigned, unsigned, unsigned); extern unsigned MmxWeaponsDamage(uint8_t *, unsigned, unsigned, unsigned); extern unsigned MmxDamageDealt(const uint8_t *, unsigned, unsigned); {variable} = (uint8)MmxDamageDealt(g_ram,cpu->D,MmxWeaponsDamage(g_ram, cpu->D, cpu->X, MmxZeroDamage(g_ram, cpu->D, cpu->X, {variable}))); }}\n') found.add(0x849e73) if pc in PCS: load = re.search(r'uint8 (_v\d+) = cpu_read8\(cpu, cpu->DB, \(uint16\)\(0x1f99\)\);', line) diff --git a/tools/make_release.ps1 b/tools/make_release.ps1 index d75a3576..90922293 100644 --- a/tools/make_release.ps1 +++ b/tools/make_release.ps1 @@ -34,7 +34,7 @@ param( $ErrorActionPreference = 'Stop' $root = Split-Path -Parent $PSScriptRoot -$build = Join-Path $root $BuildDir +$build = if ([IO.Path]::IsPathRooted($BuildDir)) { $BuildDir } else { Join-Path $root $BuildDir } $exe = Join-Path $build 'MegaManXSNESRecomp.exe' $assets = Join-Path $build 'assets' # Stage the checked-in catalog, never a player's writable mods/state/cache.