Skip to content

Commit

Permalink
Refactor patches and hooks to be spread across more files. (#42)
Browse files Browse the repository at this point in the history
This allows for better organization and locating patches/hooks instead of trying to find a patch in one large file.

Adjust song of time reset for no swords to actually reset the sword on B when resetting a cycle.
  • Loading branch information
PhlexPlexico authored Feb 24, 2024
1 parent 3944441 commit ffa1f85
Show file tree
Hide file tree
Showing 13 changed files with 538 additions and 520 deletions.
14 changes: 14 additions & 0 deletions code/source/asm/fairy_patches.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.arm

.section .patch_OverrideFairyGiveItem
.global OverrideFairyItemID_patch
OverrideFairyItemID_patch:
b hook_OverrideFairyItem

.section .patch_OverrideGreatFairySpawn
.global OverrideGreatFairySpawn_patch
OverrideGreatFairySpawn_patch:
nop
@ldmia sp!,{r4 - r6, pc}
@ldmia sp !, {r4 - r6, lr}
@ bx lr
6 changes: 6 additions & 0 deletions code/source/asm/hms_patches.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.arm

.section .patch_HMSGiveItem
.global patch_HMSGiveItem
patch_HMSGiveItem:
b hook_OverrideHMSDekuMask
303 changes: 0 additions & 303 deletions code/source/asm/hooks.s
Original file line number Diff line number Diff line change
@@ -1,22 +1,6 @@
.arm
.text

.global rActiveItemTextId
.rActiveItemTextId_addr:
.word rActiveItemTextId

.global rActiveItemRow
.rActiveItemRow_addr:
.word rActiveItemRow

.global rActiveItemGraphicId
.rActiveItemGraphicId_addr:
.word rActiveItemGraphicId

.global rStoredTextId
.rStoredTextId_addr:
.word rStoredTextId

.global rCustomDungeonItemRetrieved
.rCustomDungeonItemRetrieved_addr:
.word rCustomDungeonItemRetrieved
Expand Down Expand Up @@ -79,28 +63,6 @@ hook_DoNotResetTempleFlags:
mov r0,#0x0
bx lr

.global hook_ChangeSOHToCustomText
hook_ChangeSOHToCustomText:
push {r0-r2, lr}
bl ItemOverride_SwapSoHGetItemText
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 All @@ -111,13 +73,6 @@ hook_SpawnFastElegyStatues:
beq 0x1E9FBC
bx lr

.global hook_CheckCurrentInventory
hook_CheckCurrentInventory:
push {r1-r12, lr}
bl ItemOverride_CheckInventoryItemOverride
pop {r1-r12, lr}
b 0x1F3D6C

.global hook_CheckOcarinaDive
hook_CheckOcarinaDive:
push {r0-r12, lr}
Expand Down Expand Up @@ -151,23 +106,6 @@ hook_CheckDungeonSmallKeys:
ldrh r0, [r2, #0x52]
bx lr

.global hook_SaveFile_Load
hook_SaveFile_Load:
push {r0-r12, lr}
bl SaveFile_LoadExtSaveData
pop {r0-r12, lr}
str r5,[r1,#0x61C]
b 0x48C764

.global hook_SaveFile_Init
hook_SaveFile_Init:
push {r0-r12, lr}
cpy r0,r4
bl SaveFile_Init
pop {r0-r12, lr}
mov r3,#0x0
b 0x5b8b28

.global hook_BlastMaskCooldown
hook_BlastMaskCooldown:
push {r0-r12, lr}
Expand Down Expand Up @@ -201,21 +139,6 @@ instBlastCd:
subne r0,r0,r0
bx lr

.global hook_OverrideItemIdIndex
hook_OverrideItemIdIndex:
push {r0}
ldr r0,.rActiveItemGraphicId_addr
ldr r0,[r0]
cmp r0,#0x0
pop {r0}
beq noOverrideItemIdIndex
ldr r0,.rActiveItemGraphicId_addr
ldr r0,[r0]
bx lr
noOverrideItemIdIndex:
ldrsh r0, [r0, #-6]
bx lr

@ State handler calls 0x5D for masks, check this value and ignore states where that is equal, since this function
@ is also used by song of soaring and get_item.
.global hook_RemainsCheckValue
Expand All @@ -227,43 +150,6 @@ hook_RemainsCheckValue:
noIgnoreValues:
b 0x22B814

.global hook_OverrideDrawIndex
hook_OverrideDrawIndex:
ldr r0,.rActiveItemGraphicId_addr
ldr r0,[r0]
cmp r0,#0x0
beq noOverrideGraphicId
b 0x22F254
noOverrideGraphicId:
ldrsh r0,[r7,#0x2]
b 0x22F250

.global hook_OverrideDrawIndexSecond
hook_OverrideDrawIndexSecond:
ldr r0,.rActiveItemGraphicId_addr
ldr r0,[r0]
cmp r0,#0x0
beq noOverrideGraphicIdSecond
b 0x22F47C
noOverrideGraphicIdSecond:
ldrsh r0, [r8,#2]
b 0x22F478

.global hook_OverrideTextID
hook_OverrideTextID:
push {r3}
ldr r3,.rActiveItemTextId_addr
ldr r3,[r3]
cmp r3,#0x0
pop {r3}
beq noOverrideTextID
b 0x231104
noOverrideTextID:
@cpy r2, r5
cpy r0, r7
b 0x231100


.global hook_OverrideBomberTextID
hook_OverrideBomberTextID:
cmp r1, #0x5F
Expand All @@ -274,23 +160,6 @@ noBomberOverride:
cmp r1,r0
b 0x1D2768

.global hook_OverrideItemID
hook_OverrideItemID:
push {r1}
ldr r1,.rActiveItemRow_addr
ldr r1,[r1]
cmp r1,#0x0
pop {r1}
beq noOverrideItemID
push {r0-r12, lr}
bl ItemOverride_GetItemTextAndItemID
pop {r0-r12, lr}
b 0x231110
noOverrideItemID:
LDRB R1, [R4,#0x0]
cpy r0,r7
b 0x23110C

.global hook_EnteringLocation
hook_EnteringLocation:
push {r0-r12, lr}
Expand All @@ -299,39 +168,6 @@ hook_EnteringLocation:
cpy r9,r0
bx lr

.global hook_DarmaniRewardCheck
hook_DarmaniRewardCheck:
push {r0-r12, lr}
bl ItemOverride_CheckDarmaniGivenItem
cmp r0,#0x1
pop {r0-r12, lr}
beq doNotSpawnDarmani
b 0x2DE794
doNotSpawnDarmani:
nop
b 0x2DE96C

.global hook_CheckOshExtData
hook_CheckOshExtData:
push {lr}
bl ItemOverride_GetOshExtData
pop {lr}
cmp r0,#0x0
bx lr

.global hook_IncomingGetItemID
hook_IncomingGetItemID:
push {r0-r12, lr}
@ According to Ghidra, r6 r5 r4 are the required
@ values needed for the GetItem header, if it isn't clear.
cpy r0,r7
cpy r1,r6
cpy r2,r5
cpy r3,r4
bl ItemOverride_GetItem
pop {r0-r12, lr}
bx lr

.global hook_readGamePad
hook_readGamePad:
push {r0-r12, lr}
Expand All @@ -352,34 +188,6 @@ hook_HandleOcarina:
cmp r0, #0x16 @ original instruction
b 0x604d90

.global hook_GaboraCheckExtDataNotSword
hook_GaboraCheckExtDataNotSword:
push {r0-r12, lr}
bl ItemOverride_GetGaboraExtData
cmp r0, #0x0
beq giveRazorSwordReward
cmp r0, #0x1
beq giveGildedSword
pop {r0-r12,lr}
cmp r0,r0
bx lr
giveRazorSwordReward:
pop {r0-r12,lr}
cmp r0,#0xFF
b 0x2CBB3C
giveGildedSword:
pop {r0-r12,lr}
cmp r0,r0
b 0x2CBB38

.global hook_OwlExtDataSave
hook_OwlExtDataSave:
push {r0-r12, lr}
bl SaveFile_SaveExtSaveData
pop {r0-r12, lr}
cpy r6,r0
b 0x317008

.global hook_checkChestContentSetting
hook_checkChestContentSetting:
push {r0-r12, lr}
Expand Down Expand Up @@ -435,117 +243,6 @@ hook_CheckMoTSetting:
bl SettingsMaskOfTruthCheck
b 0x35C42C

.global hook_GoronMaskGiveItem
hook_GoronMaskGiveItem:
push {r0-r12, lr}
cpy r0,r5
cpy r1,r4
mov r2,#0x79
bl ItemOverride_GetSoHItem
ldr r5,.rActiveItemRow_addr
ldr r5,[r5]
cmp r5,#0x0
pop {r0-r12, lr}
beq noOverrideDarmaniItemID
push {r0-r12, lr}
cpy r0,r5
cpy r1,r4
bl ItemOverride_GetItemTextAndItemID
pop {r0-r12, lr}
cpy r0,r5
b 0x41DAB4
noOverrideDarmaniItemID:
cpy r0,r5
bl 0x233BEC
b 0x41DAB4

.global hook_ZoraMaskGiveItem
hook_ZoraMaskGiveItem:
push {r0-r12, lr}
cpy r0,r5
cpy r1,r4
mov r2,#0x7A
bl ItemOverride_GetSoHItem
ldr r5,.rActiveItemRow_addr
ldr r5,[r5]
cmp r5,#0x0
pop {r0-r12, lr}
beq noOverrideMikauItemID
push {r0-r12, lr}
cpy r0,r5
cpy r1,r4
bl ItemOverride_GetItemTextAndItemID
pop {r0-r12, lr}
cpy r0,r5
b 0x41DB84
noOverrideMikauItemID:
cpy r0,r5
bl 0x233BEC
b 0x41DB84

.global hook_GibdoMaskGiveItem
hook_GibdoMaskGiveItem:
push {r0-r12, lr}
cpy r0,r5
cpy r1,r4
mov r2,#0x87
bl ItemOverride_GetSoHItem
ldr r5,.rActiveItemRow_addr
ldr r5,[r5]
cmp r5,#0x0
pop {r0-r12, lr}
beq noOverrideGibdoItemID
push {r0-r12, lr}
cpy r0,r5
cpy r1,r4
bl ItemOverride_GetItemTextAndItemID
pop {r0-r12, lr}
cpy r0,r5
b 0x41DC4C
noOverrideGibdoItemID:
cpy r0,r5
bl 0x233BEC
b 0x41DC4C

.global hook_CouplesMaskGiveItem
hook_CouplesMaskGiveItem:
push {r0-r12, lr}
cpy r0,r5
cpy r1,r4
mov r2,#0x85
bl ItemOverride_GetSoHItem
ldr r5,.rActiveItemRow_addr
ldr r5,[r5]
cmp r5,#0x0
pop {r0-r12, lr}
beq noOverrideCouplesItemID
push {r0-r12, lr}
cpy r0,r5
cpy r1,r4
bl ItemOverride_GetItemTextAndItemID
pop {r0-r12, lr}
b 0x46e264
noOverrideCouplesItemID:
b 0x46e22c

.global hook_AdjustCouplesMaskMessage
hook_AdjustCouplesMaskMessage:
push {r1}
ldr r1,.rStoredTextId_addr
ldr r1,[r1]
cmp r1,#0x0
pop {r1}
beq normalText
ldr r1,.rStoredTextId_addr
ldr r1,[r1]
push {r0-r12,lr}
bl ItemOverride_RemoveTextId
pop {r0-r12, lr}
b 0x1867C8
normalText:
mov r1,#0xA2
b 0x1867C8

.section .loader
.global hook_into_loader
hook_into_loader:
Expand Down
Loading

0 comments on commit ffa1f85

Please sign in to comment.