From 939a1547b3fc01b692fb65b663646a0defd1ab10 Mon Sep 17 00:00:00 2001 From: UltiNaruto Date: Thu, 31 Oct 2024 13:15:11 +0100 Subject: [PATCH] Fixed crash when shooting multiple enemies with missiles --- src/patches.rs | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/patches.rs b/src/patches.rs index 8e793e8b..d60065ff 100644 --- a/src/patches.rs +++ b/src/patches.rs @@ -11509,31 +11509,31 @@ fn patch_dol( dol_patcher.ppcasm_patch(&custom_item_get_item_amount_hook)?; let custom_item_get_item_amount_patch = ppcasm!(new_text_section_end, { // backup arguments - mr r21, r3; + mr r22, r3; // preload unknown item 2 for future checks in the function - li r22, { PickupType::UnknownItem2.kind() }; - rlwinm r0, r22, 0x3, 0x0, 0x1c; - add r22, r3, r0; - addi r22, r22, 0x2c; - lwz r22, 0x0(r22); + li r23, { PickupType::UnknownItem2.kind() }; + rlwinm r23, r23, 0x3, 0x0, 0x1c; + add r23, r22, r23; + addi r23, r23, 0x2c; + lwz r23, 0x0(r23); cmpwi r4, { PickupType::Missile.kind() }; bne check_power_bomb; // check for missile launcher - andi r22, r3, { PickupType::MissileLauncher.custom_item_value() }; + andi r23, r3, { PickupType::MissileLauncher.custom_item_value() }; cmpwi r3, 0; beq no_launcher; // check for missile capacity li r3, { PickupType::Missile.kind() }; - rlwinm r0, r3, 0x3, 0x0, 0x1c; - add r3, r21, r0; + rlwinm r3, r3, 0x3, 0x0, 0x1c; + add r3, r22, r3; addi r3, r3, 0x2c; lwz r3, 0x0(r3); cmpwi r3, 0; ble no_launcher; // check for unlimited missiles - andi r22, r3, { PickupType::UnlimitedMissiles.custom_item_value() }; + andi r23, r3, { PickupType::UnlimitedMissiles.custom_item_value() }; cmpwi r3, 0; beq not_unlimited_or_not_pb_missiles; li r3, 255; @@ -11543,19 +11543,19 @@ fn patch_dol( cmpwi r4, { PickupType::PowerBomb.kind() }; bne not_unlimited_or_not_pb_missiles; // check for power bomb launcher - andi r22, r3, { PickupType::PowerBombLauncher.custom_item_value() }; + andi r23, r3, { PickupType::PowerBombLauncher.custom_item_value() }; cmpwi r3, 0; beq no_launcher; // check for power bomb capacity li r3, { PickupType::PowerBomb.kind() }; - rlwinm r0, r3, 0x3, 0x0, 0x1c; - add r3, r21, r0; + rlwinm r3, r3, 0x3, 0x0, 0x1c; + add r3, r22, r3; addi r3, r3, 0x2c; lwz r3, 0x0(r3); cmpwi r3, 0; ble no_launcher; // check for unlimited power bombs - andi r22, r3, { PickupType::UnlimitedPowerBombs.custom_item_value() }; + andi r23, r3, { PickupType::UnlimitedPowerBombs.custom_item_value() }; cmpwi r3, 0; beq not_unlimited_or_not_pb_missiles; li r3, 8; @@ -11564,17 +11564,21 @@ fn patch_dol( no_launcher: li r3, 0; is_unlimited: - andi r21, r21, 0; andi r22, r22, 0; + andi r23, r23, 0; blr; not_unlimited_or_not_pb_missiles: // restore previous context - mr r3, r21; - andi r21, r21, 0; + mr r3, r22; andi r22, r22, 0; + andi r23, r23, 0; cmpwi r4, 0; - b { symbol_addr!("GetItemAmount__12CPlayerStateCFQ212CPlayerState9EItemType", version) + 0x4 }; + blt item_type_negative; + b { symbol_addr!("GetItemAmount__12CPlayerStateCFQ212CPlayerState9EItemType", version) + 0x8 }; + item_type_negative: + li r3, 0; + blr; }); new_text_section_end += custom_item_get_item_amount_patch.encoded_bytes().len() as u32;