From 257bc039129dc2e6fc0aefd2158f9de872f6c95a Mon Sep 17 00:00:00 2001 From: RoadrunnerWMC Date: Tue, 3 Mar 2026 03:51:24 -0500 Subject: [PATCH 1/2] Use new Kamek injection commands --- code/src/nsmbwup_bowsers_castle_door.cpp | 2 +- code/src/nsmbwup_direct_pipes.cpp | 37 ++++++++++--------- code/src/nsmbwup_event_controllers.cpp | 12 +++--- code/src/nsmbwup_red_ring.cpp | 2 +- code/src/nsmbwup_rotation_controlled_coin.cpp | 4 +- ...on_controlled_event_deactivation_block.cpp | 4 +- ...ion_controlled_q_block_and_brick_block.cpp | 4 +- code/src/nsmbwup_star_coin.cpp | 2 +- code/src/nsmbwup_switch.cpp | 2 +- ...sed_rotation_controlled_solid_platform.cpp | 2 +- code/src/nsmbwup_water_current_controller.cpp | 4 +- 11 files changed, 38 insertions(+), 37 deletions(-) diff --git a/code/src/nsmbwup_bowsers_castle_door.cpp b/code/src/nsmbwup_bowsers_castle_door.cpp index e22125d..455f892 100644 --- a/code/src/nsmbwup_bowsers_castle_door.cpp +++ b/code/src/nsmbwup_bowsers_castle_door.cpp @@ -57,6 +57,6 @@ // category. Note that both the code being patched and the patch itself // rely on the fact that these three profile IDs are sequential. -kmWrite32(0x8013f41c, 0x28000002); // cmplwi r0, 2 +kmWriteDefAsm(0x8013f41c) { nofralloc; cmplwi r0, 2 } #endif // !NSMBWUP_C00700_OFF diff --git a/code/src/nsmbwup_direct_pipes.cpp b/code/src/nsmbwup_direct_pipes.cpp index 5698cd0..f68abec 100644 --- a/code/src/nsmbwup_direct_pipes.cpp +++ b/code/src/nsmbwup_direct_pipes.cpp @@ -93,25 +93,28 @@ class dCdFile_c { // the same assembly instructions, shuffled into the correct order. // First line (initializing the next-path-node index) - /* 0x800508f8 */ // lhz r0, 0x10(r30) // r0 = destEntrance->flags; -kmWrite32(0x800508fc, 0x540007ff); // clrlwi. r0, r0, 0x1f // r0 &= 0xff; -kmWrite32(0x80050900, 0x41820014); // beq NOT_DIRECT_PIPE_END // if (r0 & DIRECT_PIPE_END) { -kmWrite32(0x80050904, 0xa0e30004); // lhz r7, 4(r3) // this->nextPathNodeIndex = path->numNodes - 2; -kmWrite32(0x80050908, 0x3807fffe); // subi r0, r7, 0x2 // -kmWrite32(0x8005090c, 0xb01f042c); // sth r0, 0x42c(r31) // -kmWrite32(0x80050910, 0x4800000c); // b AFTER_DIRECT_PIPE_END_CHECK // } - // NOT_DIRECT_PIPE_END: // else { -kmWrite32(0x80050914, 0x38000001); // li r0, 1 // this->nextPathNodeIndex = 1; -kmWrite32(0x80050918, 0xb01f042c); // sth r0, 0x42c(r31) // - // AFTER_DIRECT_PIPE_END_CHECK: // } + /* 800508f8 */ // lhz r0, 0x10(r30) // r0 = destEntrance->flags; +kmWriteDefAsm(0x800508fc, 0x80050930) { + nofralloc + /* 800508fc */ clrlwi. r0, r0, 0x1f // r0 &= 0xff; + /* 80050900 */ beq NOT_DIRECT_PIPE_END // if (r0 & DIRECT_PIPE_END) { + /* 80050904 */ lhz r7, 4(r3) // this->nextPathNodeIndex = path->numNodes - 2; + /* 80050908 */ subi r0, r7, 0x2 // + /* 8005090c */ sth r0, 0x42c(r31) // + /* 80050910 */ b AFTER_DIRECT_PIPE_END_CHECK // } + NOT_DIRECT_PIPE_END: // else { + /* 80050914 */ li r0, 1 // this->nextPathNodeIndex = 1; + /* 80050918 */ sth r0, 0x42c(r31) // + AFTER_DIRECT_PIPE_END_CHECK: // } // Second line (calculating the first-node pointer) -kmWrite32(0x8005091c, 0xa0a30002); // lhz r5, 2(r3) // r5 = path->startNodeIndex; -kmWrite32(0x80050920, 0xa89f042c); // lha r4, 0x42c(r31) // r4 = this->nextPathNodeIndex; -kmWrite32(0x80050924, 0x80c6003c); // lwz r6, 0x3c(r6) // r6 = area->pathNodesBlock; -kmWrite32(0x80050928, 0x7c052214); // add r0, r5, r4 // r0 = path->startNodeIndex + this->nextPathNodeIndex; -kmWrite32(0x8005092c, 0x54002036); // slwi r0, r0, 4 // (left-shift to prepare for indexing) -kmWrite32(0x80050930, 0x7ca60214); // add r5, r6, r0 // r5 = area->pathNodesBlock[r0]; + /* 8005091c */ lhz r5, 2(r3) // r5 = path->startNodeIndex; + /* 80050920 */ lha r4, 0x42c(r31) // r4 = this->nextPathNodeIndex; + /* 80050924 */ lwz r6, 0x3c(r6) // r6 = area->pathNodesBlock; + /* 80050928 */ add r0, r5, r4 // r0 = path->startNodeIndex + this->nextPathNodeIndex; + /* 8005092c */ slwi r0, r0, 4 // (left-shift to prepare for indexing) + /* 80050930 */ add r5, r6, r0 // r5 = area->pathNodesBlock[r0]; +} #endif // !NSMBWUP_C01100_OFF diff --git a/code/src/nsmbwup_event_controllers.cpp b/code/src/nsmbwup_event_controllers.cpp index efec180..1b8c9e8 100644 --- a/code/src/nsmbwup_event_controllers.cpp +++ b/code/src/nsmbwup_event_controllers.cpp @@ -44,14 +44,14 @@ #ifndef NSMBWUP_C01401_OFF // Zone Enter: -kmWrite32(0x807eb210, 0x39200001); // li r9, 1 -kmWrite32(0x807eb248, 0x39200001); // li r9, 1 +kmWriteDefAsm(0x807eb210) { nofralloc; li r9, 1 } +kmWriteDefAsm(0x807eb248) { nofralloc; li r9, 1 } #endif // !NSMBWUP_C01401_OFF #ifndef NSMBWUP_C01402_OFF // Chainer: -kmWrite32(0x807ebaa0, 0x39200001); // li r9, 1 -kmWrite32(0x807ebac8, 0x39200001); // li r9, 1 -kmWrite32(0x807ebb28, 0x39200001); // li r9, 1 -kmWrite32(0x807ebb50, 0x39200001); // li r9, 1 +kmWriteDefAsm(0x807ebaa0) { nofralloc; li r9, 1 } +kmWriteDefAsm(0x807ebac8) { nofralloc; li r9, 1 } +kmWriteDefAsm(0x807ebb28) { nofralloc; li r9, 1 } +kmWriteDefAsm(0x807ebb50) { nofralloc; li r9, 1 } #endif // !NSMBWUP_C01402_OFF diff --git a/code/src/nsmbwup_red_ring.cpp b/code/src/nsmbwup_red_ring.cpp index ed9a020..1ed4061 100644 --- a/code/src/nsmbwup_red_ring.cpp +++ b/code/src/nsmbwup_red_ring.cpp @@ -38,6 +38,6 @@ // More information on this type of bug can be found in // nsmbwup_timed_events_canceling_p_switch_music.h. -kmWrite32(0x80a93034, 0x39200001); // li r9, 1 +kmWriteDefAsm(0x80a93034) { nofralloc; li r9, 1 } #endif // !NSMBWUP_C01403_OFF diff --git a/code/src/nsmbwup_rotation_controlled_coin.cpp b/code/src/nsmbwup_rotation_controlled_coin.cpp index 81399a4..4ea5f6f 100644 --- a/code/src/nsmbwup_rotation_controlled_coin.cpp +++ b/code/src/nsmbwup_rotation_controlled_coin.cpp @@ -49,7 +49,7 @@ // the only one where the blocks and coins end up upside-down.) // The stages should be modified (under this same bug ID) to compensate. -kmWrite32(0x809e55f4, 0x3860c000); // li r3, -0x4000 -kmWrite32(0x809e560c, 0x3860c000); // li r3, -0x4000 +kmWriteDefAsm(0x809e55f4) { nofralloc; li r3, -0x4000 } +kmWriteDefAsm(0x809e560c) { nofralloc; li r3, -0x4000 } #endif // !NSMBWUP_C00002_OFF diff --git a/code/src/nsmbwup_rotation_controlled_event_deactivation_block.cpp b/code/src/nsmbwup_rotation_controlled_event_deactivation_block.cpp index d3f96c9..8c1b84d 100644 --- a/code/src/nsmbwup_rotation_controlled_event_deactivation_block.cpp +++ b/code/src/nsmbwup_rotation_controlled_event_deactivation_block.cpp @@ -38,7 +38,7 @@ // More information on this type of bug can be found in // nsmbwup_rotation_controlled_actors_starting_rotation.h. -kmWrite32(0x80a7b558, 0x3860c000); // li r3, -0x4000 -kmWrite32(0x80a7b570, 0x3860c000); // li r3, -0x4000 +kmWriteDefAsm(0x80a7b558) { nofralloc; li r3, -0x4000 } +kmWriteDefAsm(0x80a7b570) { nofralloc; li r3, -0x4000 } #endif // !NSMBWUP_C00001_OFF diff --git a/code/src/nsmbwup_rotation_controlled_q_block_and_brick_block.cpp b/code/src/nsmbwup_rotation_controlled_q_block_and_brick_block.cpp index 69d2d09..f0b7db0 100644 --- a/code/src/nsmbwup_rotation_controlled_q_block_and_brick_block.cpp +++ b/code/src/nsmbwup_rotation_controlled_q_block_and_brick_block.cpp @@ -47,7 +47,7 @@ // of the stage. // The stages should be modified (under this same bug ID) to compensate. -kmWrite32(0x809c15c4, 0x3860c000); // li r3, -0x4000 -kmWrite32(0x809c15dc, 0x3860c000); // li r3, -0x4000 +kmWriteDefAsm(0x809c15c4) { nofralloc; li r3, -0x4000 } +kmWriteDefAsm(0x809c15dc) { nofralloc; li r3, -0x4000 } #endif // !NSMBWUP_C00003_OFF diff --git a/code/src/nsmbwup_star_coin.cpp b/code/src/nsmbwup_star_coin.cpp index 75f2a2d..ab03cc3 100644 --- a/code/src/nsmbwup_star_coin.cpp +++ b/code/src/nsmbwup_star_coin.cpp @@ -37,6 +37,6 @@ // More information on this type of bug can be found in // nsmbwup_timed_events_canceling_p_switch_music.h. -kmWrite32(0x80aaa488, 0x39200001); // li r9, 1 +kmWriteDefAsm(0x80aaa488) { nofralloc; li r9, 1 } #endif // !NSMBWUP_C01400_OFF diff --git a/code/src/nsmbwup_switch.cpp b/code/src/nsmbwup_switch.cpp index 4c009e6..dbcc74b 100644 --- a/code/src/nsmbwup_switch.cpp +++ b/code/src/nsmbwup_switch.cpp @@ -44,6 +44,6 @@ // exist in that game, it's probably unlikely (but admittedly not // impossible) that it still does here. -kmWrite32(0x80a19a7c, 0x60000000); // nop +kmWriteNop(0x80a19a7c); #endif // !NSMBWUP_C00200_OFF diff --git a/code/src/nsmbwup_unused_rotation_controlled_solid_platform.cpp b/code/src/nsmbwup_unused_rotation_controlled_solid_platform.cpp index 5f08eb6..756bc2d 100644 --- a/code/src/nsmbwup_unused_rotation_controlled_solid_platform.cpp +++ b/code/src/nsmbwup_unused_rotation_controlled_solid_platform.cpp @@ -37,6 +37,6 @@ // More information on this type of bug can be found in // nsmbwup_rotation_controlled_actors_starting_rotation.h. -kmWrite32(0x80a5d980, 0x38a0c000); // li r5, -0x4000 +kmWriteDefAsm(0x80a5d980) { nofralloc; li r5, -0x4000 } #endif // !NSMBWUP_C00000_OFF diff --git a/code/src/nsmbwup_water_current_controller.cpp b/code/src/nsmbwup_water_current_controller.cpp index 7203210..f514708 100644 --- a/code/src/nsmbwup_water_current_controller.cpp +++ b/code/src/nsmbwup_water_current_controller.cpp @@ -68,8 +68,6 @@ // unchanged and replace 80131404 with fmr f0, f5 instead of with nop. kmWrite8(0x80131401, 0xa3); // "lfs f0, OFFSET(r3)" -> "lfs f5, OFFSET(r3)" -kmWrite32(0x80131404, 0x60000000); // nop -kmWrite32(0x80131408, 0x60000000); // nop -kmWrite32(0x8013140c, 0x60000000); // nop +kmWriteNops(0x80131404, 0x8013140c); #endif // !NSMBWUP_C01500_OFF From d28398d3ddf8a318c95ca471dcc80035abb8c074 Mon Sep 17 00:00:00 2001 From: RoadrunnerWMC Date: Tue, 3 Mar 2026 04:03:07 -0500 Subject: [PATCH 2/2] Remove nofrallocs in most kmWriteDefAsm calls --- code/src/nsmbwup_bowsers_castle_door.cpp | 2 +- code/src/nsmbwup_event_controllers.cpp | 12 ++++++------ code/src/nsmbwup_red_ring.cpp | 2 +- code/src/nsmbwup_rotation_controlled_coin.cpp | 4 ++-- ..._rotation_controlled_event_deactivation_block.cpp | 4 ++-- ...p_rotation_controlled_q_block_and_brick_block.cpp | 4 ++-- code/src/nsmbwup_star_coin.cpp | 2 +- ...wup_unused_rotation_controlled_solid_platform.cpp | 2 +- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/code/src/nsmbwup_bowsers_castle_door.cpp b/code/src/nsmbwup_bowsers_castle_door.cpp index 455f892..0fc878c 100644 --- a/code/src/nsmbwup_bowsers_castle_door.cpp +++ b/code/src/nsmbwup_bowsers_castle_door.cpp @@ -57,6 +57,6 @@ // category. Note that both the code being patched and the patch itself // rely on the fact that these three profile IDs are sequential. -kmWriteDefAsm(0x8013f41c) { nofralloc; cmplwi r0, 2 } +kmWriteDefAsm(0x8013f41c) { cmplwi r0, 2 } #endif // !NSMBWUP_C00700_OFF diff --git a/code/src/nsmbwup_event_controllers.cpp b/code/src/nsmbwup_event_controllers.cpp index 1b8c9e8..a73a310 100644 --- a/code/src/nsmbwup_event_controllers.cpp +++ b/code/src/nsmbwup_event_controllers.cpp @@ -44,14 +44,14 @@ #ifndef NSMBWUP_C01401_OFF // Zone Enter: -kmWriteDefAsm(0x807eb210) { nofralloc; li r9, 1 } -kmWriteDefAsm(0x807eb248) { nofralloc; li r9, 1 } +kmWriteDefAsm(0x807eb210) { li r9, 1 } +kmWriteDefAsm(0x807eb248) { li r9, 1 } #endif // !NSMBWUP_C01401_OFF #ifndef NSMBWUP_C01402_OFF // Chainer: -kmWriteDefAsm(0x807ebaa0) { nofralloc; li r9, 1 } -kmWriteDefAsm(0x807ebac8) { nofralloc; li r9, 1 } -kmWriteDefAsm(0x807ebb28) { nofralloc; li r9, 1 } -kmWriteDefAsm(0x807ebb50) { nofralloc; li r9, 1 } +kmWriteDefAsm(0x807ebaa0) { li r9, 1 } +kmWriteDefAsm(0x807ebac8) { li r9, 1 } +kmWriteDefAsm(0x807ebb28) { li r9, 1 } +kmWriteDefAsm(0x807ebb50) { li r9, 1 } #endif // !NSMBWUP_C01402_OFF diff --git a/code/src/nsmbwup_red_ring.cpp b/code/src/nsmbwup_red_ring.cpp index 1ed4061..1f849dd 100644 --- a/code/src/nsmbwup_red_ring.cpp +++ b/code/src/nsmbwup_red_ring.cpp @@ -38,6 +38,6 @@ // More information on this type of bug can be found in // nsmbwup_timed_events_canceling_p_switch_music.h. -kmWriteDefAsm(0x80a93034) { nofralloc; li r9, 1 } +kmWriteDefAsm(0x80a93034) { li r9, 1 } #endif // !NSMBWUP_C01403_OFF diff --git a/code/src/nsmbwup_rotation_controlled_coin.cpp b/code/src/nsmbwup_rotation_controlled_coin.cpp index 4ea5f6f..a67f97e 100644 --- a/code/src/nsmbwup_rotation_controlled_coin.cpp +++ b/code/src/nsmbwup_rotation_controlled_coin.cpp @@ -49,7 +49,7 @@ // the only one where the blocks and coins end up upside-down.) // The stages should be modified (under this same bug ID) to compensate. -kmWriteDefAsm(0x809e55f4) { nofralloc; li r3, -0x4000 } -kmWriteDefAsm(0x809e560c) { nofralloc; li r3, -0x4000 } +kmWriteDefAsm(0x809e55f4) { li r3, -0x4000 } +kmWriteDefAsm(0x809e560c) { li r3, -0x4000 } #endif // !NSMBWUP_C00002_OFF diff --git a/code/src/nsmbwup_rotation_controlled_event_deactivation_block.cpp b/code/src/nsmbwup_rotation_controlled_event_deactivation_block.cpp index 8c1b84d..de8496c 100644 --- a/code/src/nsmbwup_rotation_controlled_event_deactivation_block.cpp +++ b/code/src/nsmbwup_rotation_controlled_event_deactivation_block.cpp @@ -38,7 +38,7 @@ // More information on this type of bug can be found in // nsmbwup_rotation_controlled_actors_starting_rotation.h. -kmWriteDefAsm(0x80a7b558) { nofralloc; li r3, -0x4000 } -kmWriteDefAsm(0x80a7b570) { nofralloc; li r3, -0x4000 } +kmWriteDefAsm(0x80a7b558) { li r3, -0x4000 } +kmWriteDefAsm(0x80a7b570) { li r3, -0x4000 } #endif // !NSMBWUP_C00001_OFF diff --git a/code/src/nsmbwup_rotation_controlled_q_block_and_brick_block.cpp b/code/src/nsmbwup_rotation_controlled_q_block_and_brick_block.cpp index f0b7db0..9dea3fa 100644 --- a/code/src/nsmbwup_rotation_controlled_q_block_and_brick_block.cpp +++ b/code/src/nsmbwup_rotation_controlled_q_block_and_brick_block.cpp @@ -47,7 +47,7 @@ // of the stage. // The stages should be modified (under this same bug ID) to compensate. -kmWriteDefAsm(0x809c15c4) { nofralloc; li r3, -0x4000 } -kmWriteDefAsm(0x809c15dc) { nofralloc; li r3, -0x4000 } +kmWriteDefAsm(0x809c15c4) { li r3, -0x4000 } +kmWriteDefAsm(0x809c15dc) { li r3, -0x4000 } #endif // !NSMBWUP_C00003_OFF diff --git a/code/src/nsmbwup_star_coin.cpp b/code/src/nsmbwup_star_coin.cpp index ab03cc3..01411b0 100644 --- a/code/src/nsmbwup_star_coin.cpp +++ b/code/src/nsmbwup_star_coin.cpp @@ -37,6 +37,6 @@ // More information on this type of bug can be found in // nsmbwup_timed_events_canceling_p_switch_music.h. -kmWriteDefAsm(0x80aaa488) { nofralloc; li r9, 1 } +kmWriteDefAsm(0x80aaa488) { li r9, 1 } #endif // !NSMBWUP_C01400_OFF diff --git a/code/src/nsmbwup_unused_rotation_controlled_solid_platform.cpp b/code/src/nsmbwup_unused_rotation_controlled_solid_platform.cpp index 756bc2d..d01de41 100644 --- a/code/src/nsmbwup_unused_rotation_controlled_solid_platform.cpp +++ b/code/src/nsmbwup_unused_rotation_controlled_solid_platform.cpp @@ -37,6 +37,6 @@ // More information on this type of bug can be found in // nsmbwup_rotation_controlled_actors_starting_rotation.h. -kmWriteDefAsm(0x80a5d980) { nofralloc; li r5, -0x4000 } +kmWriteDefAsm(0x80a5d980) { li r5, -0x4000 } #endif // !NSMBWUP_C00000_OFF