Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed crash when shooting multiple enemies with missiles #98

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 59 additions & 20 deletions src/patches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11509,53 +11509,76 @@ 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 r0, r3;
lis r3, r3_backup@h;
addi r3, r3, r3_backup@l;
stw r0, 0x0(r3);
mr r0, r4;
lis r4, r4_backup@h;
addi r4, r4, r4_backup@l;
stw r0, 0x0(r4);

// 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);
lis r4, r3_backup@h;
addi r4, r4, r3_backup@l;
lwz r4, 0x0(r4);
li r3, { PickupType::UnknownItem2.kind() };
rlwinm r3, r3, 0x3, 0x0, 0x1c;
add r3, r4, r3;
addi r3, r3, 0x2c;
lwz r3, 0x0(r3);
mr r0, r3;

lis r4, r4_backup@h;
addi r4, r4, r4_backup@l;
lwz r4, 0x0(r4);
cmpwi r4, { PickupType::Missile.kind() };
bne check_power_bomb;
// check for missile launcher
andi r22, r3, { PickupType::MissileLauncher.custom_item_value() };
andi r0, r3, { PickupType::MissileLauncher.custom_item_value() };
cmpwi r3, 0;
beq no_launcher;
// check for missile capacity
lis r4, r3_backup@h;
addi r4, r4, r3_backup@l;
lwz r4, 0x0(r4);
li r3, { PickupType::Missile.kind() };
rlwinm r0, r3, 0x3, 0x0, 0x1c;
add r3, r21, r0;
rlwinm r3, r3, 0x3, 0x0, 0x1c;
add r3, r4, 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 r0, r3, { PickupType::UnlimitedMissiles.custom_item_value() };
cmpwi r3, 0;
beq not_unlimited_or_not_pb_missiles;
li r3, 255;
b is_unlimited;

check_power_bomb:
lis r4, r4_backup@h;
addi r4, r4, r4_backup@l;
lwz r4, 0x0(r4);
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 r0, r3, { PickupType::PowerBombLauncher.custom_item_value() };
cmpwi r3, 0;
beq no_launcher;
// check for power bomb capacity
lis r4, r3_backup@h;
addi r4, r4, r3_backup@l;
lwz r4, 0x0(r4);
li r3, { PickupType::PowerBomb.kind() };
rlwinm r0, r3, 0x3, 0x0, 0x1c;
add r3, r21, r0;
rlwinm r3, r3, 0x3, 0x0, 0x1c;
add r3, r4, 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 r0, r3, { PickupType::UnlimitedPowerBombs.custom_item_value() };
cmpwi r3, 0;
beq not_unlimited_or_not_pb_missiles;
li r3, 8;
Expand All @@ -11564,17 +11587,33 @@ fn patch_dol(
no_launcher:
li r3, 0;
is_unlimited:
andi r21, r21, 0;
andi r22, r22, 0;
lis r3, r3_backup@h;
addi r3, r3, r3_backup@l;
lwz r3, 0x0(r3);
lis r4, r4_backup@h;
addi r4, r4, r4_backup@l;
lwz r4, 0x0(r4);
blr;

not_unlimited_or_not_pb_missiles:
// restore previous context
mr r3, r21;
andi r21, r21, 0;
andi r22, r22, 0;
lis r3, r3_backup@h;
addi r3, r3, r3_backup@l;
lwz r3, 0x0(r3);
lis r4, r4_backup@h;
addi r4, r4, r4_backup@l;
lwz r4, 0x0(r4);
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;

r3_backup:
.long 0;
r4_backup:
.long 0;
});

new_text_section_end += custom_item_get_item_amount_patch.encoded_bytes().len() as u32;
Expand Down
Loading