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

Sword Fixes #2

Merged
merged 4 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion code/mm.ld
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,18 @@ SECTIONS{
*(.patch_DoNotRemoveKeys)
}

.patch_DoNotGiveSwordBackOnReset 0x1C98FC : {
.patch_DoNotGiveSwordBackOnReset 0x1C98DC : {
*(.patch_DoNotGiveSwordBackOnReset)
}

.patch_RemoveItemBUsabilityOnReset 0x1C99F4 : {
*(.patch_RemoveItemBUsabilityOnReset)
}

.patch_RemoveSwordFlagsOnReset 0x1C9900 : {
*(.patch_RemoveSwordFlagsOnReset)
}

.patch_RemoveDekuMaskCheckSoT 0x1D8008 : {
*(.patch_RemoveDekuMaskCheckSoT)
}
Expand Down Expand Up @@ -163,6 +167,10 @@ SECTIONS{
*(.patch_SecondZoraSwimCheck)
}

.patch_ForceSwordUpgradeOnHuman 0x233D88 : {
*(.patch_ForceSwordUpgradeOnHuman)
}

.patch_CheckDungeonItems 0x233F30 : {
*(.patch_CheckDungeonItems)
}
Expand Down
15 changes: 15 additions & 0 deletions code/source/asm/hooks.s
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ hook_ChangeSOHToCustomText:
pop {r0-r2, lr}
b 0x186814

.global hook_DoNotGiveSwordBackOnReset
hook_DoNotGiveSwordBackOnReset:
bhi 0x1C9958 @ original instruction, if gilded sword ignore these.
push {r0-r12, lr}
bl SongOfTimeSwordPlacement @ See rnd/link.cpp
pop {r0-r12, lr}
bx lr

.global hook_DoNotGiveSwordBackOnResetTwo
hook_DoNotGiveSwordBackOnResetTwo:
push {r0-r12, lr}
bl SongOfTimeSwordPlacement @ See rnd/link.cpp
pop {r0-r12, lr}
bx lr

.global hook_SpawnFastElegyStatues
hook_SpawnFastElegyStatues:
push {r0-r12, lr}
Expand Down
14 changes: 11 additions & 3 deletions code/source/asm/patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,16 @@ patch_DoNotRemoveKeys:
.section .patch_DoNotGiveSwordBackOnReset
.global patch_DoNotGiveSwordBackOnReset
patch_DoNotGiveSwordBackOnReset:
nop
nop
nop
bl hook_DoNotGiveSwordBackOnReset

.section .patch_RemoveItemBUsabilityOnReset
.global patch_RemoveItemBUsabilityOnReset
patch_RemoveItemBUsabilityOnReset:
bl hook_DoNotGiveSwordBackOnResetTwo

.section .patch_RemoveSwordFlagsOnReset
.global patch_RemoveSwordFlagsOnReset
patch_RemoveSwordFlagsOnReset:
nop

.section .patch_RemoveDekuMaskCheckSoT
Expand All @@ -145,6 +148,11 @@ patch_SpawnFastElegyStatues:
patch_CheckCurrentInventoryOverrideItem:
b hook_CheckCurrentInventory

.section .patch_ForceSwordUpgradeOnHuman
.global patch_ForceSwordUpgradeOnHuman
patch_ForceSwordUpgradeOnHuman:
mov r0,#0x0

.section .patch_CheckDungeonItems
.global patch_CheckDungeonItems
patch_CheckDungeonItems:
Expand Down
2 changes: 2 additions & 0 deletions code/source/rnd/item_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ namespace rnd {
}
comData->save.player.razor_sword_hp = 100; // Set to 100 hits. Maybe randomize?
comData->save.equipment.sword_shield.sword = game::SwordType::RazorSword; // Set sword to razor.
comData->save.equipment.data[0].item_btn_b = game::ItemId::RazorSword;
}

void ItemEffect_GiveGildedSword(game::CommonData* comData, s16 arg1, s16 arg2) {
comData->save.equipment.sword_shield.sword = game::SwordType::GildedSword; // Set sword to gilded.
comData->save.equipment.data[0].item_btn_b = game::ItemId::GildedSword;
}

void ItemEffect_GiveBottle(game::CommonData* comData, s16 bottleItemId, s16 arg2) {
Expand Down
6 changes: 3 additions & 3 deletions code/source/rnd/item_override.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ namespace rnd {
rItemOverrides[0].key.type = ItemOverride_Type::OVR_COLLECTABLE;
rItemOverrides[0].value.getItemId = 0x26;
rItemOverrides[0].value.looksLikeItemId = 0x26;
rItemOverrides[1].key.scene = 0x26;
rItemOverrides[1].key.scene = 0x38;
rItemOverrides[1].key.type = ItemOverride_Type::OVR_COLLECTABLE;
rItemOverrides[1].value.getItemId = 0xB9;
rItemOverrides[1].value.looksLikeItemId = 0xB9;
rItemOverrides[1].value.getItemId = 0x38;
rItemOverrides[1].value.looksLikeItemId = 0x38;
rItemOverrides[2].key.scene = 0x12;
rItemOverrides[2].key.type = ItemOverride_Type::OVR_COLLECTABLE;
rItemOverrides[2].value.getItemId = 0x37;
Expand Down
25 changes: 25 additions & 0 deletions code/source/rnd/link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,31 @@ namespace rnd::link {
game::SaveData& saveData = game::GetCommonData().save;
return static_cast<u8>(saveData.inventory.masks[17]);
}

void SongOfTimeSwordPlacement() {
game::SaveData& saveData = game::GetCommonData().save;
if (gSettingsContext.startingKokiriSword == (u8)StartingSwordSetting::STARTINGSWORD_NONE &&
saveData.equipment.sword_shield.sword == game::SwordType::NoSword) {
return;
}

#if defined ENABLE_DEBUG || defined DEBUG_PRINT
rnd::util::Print("%s: Sword is %u and starting sword is %u\n", __func__, saveData.equipment.sword_shield.sword,
gSettingsContext.startingKokiriSword);
#endif
// Check sword/shield flag to see what sword to give back. Once we do that, set the form[0] of player
// equipment to that sword and return.
if (saveData.equipment.sword_shield.sword == game::SwordType::NoSword &&
gSettingsContext.startingKokiriSword == (u8)StartingSwordSetting::STARTINGSWORD_KOKIRI) {
saveData.equipment.data[0].item_btn_b = game::ItemId::KokiriSword;
saveData.equipment.sword_shield.sword = game::SwordType::KokiriSword;
} else if (saveData.equipment.sword_shield.sword == game::SwordType::NoSword &&
gSettingsContext.startingKokiriSword == (u8)StartingSwordSetting::STARTINGSWORD_RAZOR) {
saveData.equipment.data[0].item_btn_b = game::ItemId::RazorSword;
saveData.equipment.sword_shield.sword = game::SwordType::RazorSword;
}
return;
}
}

} // namespace rnd::link
10 changes: 5 additions & 5 deletions code/source/rnd/savefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ namespace rnd {
if (gSettingsContext.skipBombersMinigame) {
// Not sure if bombers code is used elsewhere in the game's code
saveData.bomberscode[0] = 0x01;
saveData.bomberscode[1] = 0x01;
saveData.bomberscode[2] = 0x01;
saveData.bomberscode[3] = 0x01;
saveData.bomberscode[4] = 0x01;
saveData.bomberscode[1] = 0x02;
saveData.bomberscode[2] = 0x03;
saveData.bomberscode[3] = 0x04;
saveData.bomberscode[4] = 0x05;
saveData.clock_town_temp_flags.bomber_open_hideout = 1; // Currently gets reset by Song of time
}

Expand Down Expand Up @@ -509,7 +509,7 @@ namespace rnd {
}
if (gSettingsContext.startingKokiriSword == (u8)StartingSwordSetting::STARTINGSWORD_NONE) {
equipmentData.sword_shield.sword = game::SwordType::NoSword;
saveData.equipment.data->item_btn_b = game::ItemId::None;
saveData.equipment.data[0].item_btn_b = game::ItemId::None;
} else if (gSettingsContext.startingKokiriSword == (u8)StartingSwordSetting::STARTINGSWORD_KOKIRI) {
equipmentData.sword_shield.sword = game::SwordType::KokiriSword;
saveData.equipment.data[0].item_btn_b = game::ItemId::KokiriSword;
Expand Down