Skip to content

Commit

Permalink
Fixed crashing when shooting missiles at multiple enemies
Browse files Browse the repository at this point in the history
  • Loading branch information
UltiNaruto committed Oct 31, 2024
2 parents cbd0c31 + b169126 commit d5918b8
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions src/patches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit d5918b8

Please sign in to comment.