Skip to content

Commit

Permalink
Correctly handle ExtData when copying savefiles (#735)
Browse files Browse the repository at this point in the history
  • Loading branch information
HylianFreddy committed May 23, 2024
1 parent 5600a68 commit e2012dc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions code/oot.ld
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,10 @@ SECTIONS
*(.patch_ChildCanOpenBowSubMenu)
}

.patch_FileSelect_CopyFile 0x2EDA04 : {
*(.patch_FileSelect_CopyFile)
}

.patch_CorrectCompassChests 0x2F161C : {
*(.patch_CorrectCompassChests)
}
Expand Down
8 changes: 8 additions & 0 deletions code/src/hooks.s
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,14 @@ hook_AfterLoadGame:
pop {r0-r12, lr}
pop {r4-r6, pc}

.global hook_FileSelect_CopyFile
hook_FileSelect_CopyFile:
push {r0-r12, lr}
bl SaveFile_BeforeCopy
pop {r0-r12, lr}
sub sp,sp,#0x240
bx lr

.global hook_SaveGame
hook_SaveGame:
cmp r5, #0
Expand Down
5 changes: 5 additions & 0 deletions code/src/patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -1577,6 +1577,11 @@ BeforeLoadGame_patch:
AfterLoadGame_patch:
b hook_AfterLoadGame

.section .patch_FileSelect_CopyFile
.global FileSelect_CopyFile_patch
FileSelect_CopyFile_patch:
bl hook_FileSelect_CopyFile

.section .patch_SaveGame
.global .SaveGame_patch
SaveGame_patch:
Expand Down
6 changes: 6 additions & 0 deletions code/src/savefile.c
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,12 @@ void SaveFile_SaveExtSaveData(u32 saveNumber) {
extDataUnmount(fsa);
}

void SaveFile_BeforeCopy(s32 srcFileNum) {
// When the game writes the copied savefile, it calls SaveFile_SaveExtSaveData,
// so in order to properly copy the ExtData they first need to be loaded from the source savefile.
SaveFile_LoadExtSaveData(srcFileNum);
}

void SaveFile_EnforceHealthLimit(void) {
u16 healthLimit = (gSaveContext.healthCapacity == 0) ? 2 : gSaveContext.healthCapacity;
if (gSaveContext.health > healthLimit) {
Expand Down

0 comments on commit e2012dc

Please sign in to comment.