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

Fix Remains not appearing if collected outside of boss room #83

Merged
merged 2 commits into from
Jul 13, 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
31 changes: 18 additions & 13 deletions code/include/rnd/item_override.h
Original file line number Diff line number Diff line change
Expand Up @@ -440,22 +440,27 @@ namespace rnd {
void ItemOverride_RevealMapBasedOnId(u8);
void SetExtData(void);
u8 ItemOverride_SetProgressiveItemDraw(ItemOverride);
extern "C" bool ItemOverride_CheckAromaGivenItem();
extern "C" bool ItemOverride_CheckMikauGivenItem();
extern "C" bool ItemOverride_CheckDarmaniGivenItem();
extern "C" void ItemOverride_GetItemTextAndItemID(game::act::Player*);
extern "C" void ItemOverride_GetItem(game::GlobalContext*, game::act::Actor*, game::act::Player*, s16);
extern "C" void ItemOverride_GetFairyRewardItem(game::GlobalContext*, game::act::GreatFairy*, s16);
extern "C" void ItemOverride_GetSoHItem(game::GlobalContext*, game::act::Actor*, s16);
extern "C" int ItemOverride_CheckInventoryItemOverride(game::ItemId);
extern "C" void ItemOverride_SwapSoHGetItemText(game::GlobalContext*, u16, game::act::Actor*);
extern "C" bool ItemOverride_CheckTingleMaps(u16, game::GlobalContext*);
extern "C" u32 ItemOverride_GetGaboraExtData();
extern "C" u32 ItemOverride_GetOshExtData();
extern "C" u8 ItemOverride_OverrideSkullToken(game::GlobalContext*, game::act::Actor*);
extern "C" {
bool ItemOverride_CheckAromaGivenItem();
bool ItemOverride_CheckMikauGivenItem();
bool ItemOverride_CheckDarmaniGivenItem();
void ItemOverride_GetItemTextAndItemID(game::act::Player*);
void ItemOverride_GetItem(game::GlobalContext*, game::act::Actor*, game::act::Player*, s16);
void ItemOverride_GetFairyRewardItem(game::GlobalContext*, game::act::GreatFairy*, s16);
void ItemOverride_GetSoHItem(game::GlobalContext*, game::act::Actor*, s16);
int ItemOverride_CheckInventoryItemOverride(game::ItemId);
void ItemOverride_SwapSoHGetItemText(game::GlobalContext*, u16, game::act::Actor*);
bool ItemOverride_CheckTingleMaps(u16, game::GlobalContext*);
u32 ItemOverride_GetGaboraExtData();
u32 ItemOverride_GetOshExtData();
u8 ItemOverride_OverrideSkullToken(game::GlobalContext*, game::act::Actor*);
u8 ItemOverride_CheckBossStatus();

}
extern "C" u32 rActiveItemGraphicId;
extern "C" ItemOverride rItemOverrides[640];
extern "C" u16 rStoredTextId;

} // namespace rnd

#endif
22 changes: 15 additions & 7 deletions code/include/rnd/savefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ namespace rnd {
void SaveFile_SetSceneDiscovered(u16 sceneNum);
void SaveFile_LoadExtSaveData(u32 saveNumber);
u8 SaveFile_GetIsSceneDiscovered(u8 sceneNum);
extern "C" void SaveFile_SaveExtSaveData();
extern "C" void SaveFile_RemoveStoredTradeItem(u16, u8);
extern "C" void SaveFile_RemoveTradeItemFromSlot(u16, u8);
extern "C" u8 SaveFile_GetItemCurrentlyInSlot(u8);
extern "C" void SaveFile_SetNextTradeSlotItem(u8);
extern "C" u16 CurrentMasksInInventory();
extern "C" {
void SaveFile_Init(game::GlobalContext*, game::SaveFile*);
void SaveFile_SaveExtSaveData();
void SaveFile_RemoveStoredTradeItem(u16, u8);
void SaveFile_RemoveTradeItemFromSlot(u16, u8);
u8 SaveFile_GetItemCurrentlyInSlot(u8);
void SaveFile_SetNextTradeSlotItem(u8);
u16 CurrentMasksInInventory();
void SaveFile_UpdateBossExtData();
}

typedef struct {
u32 version; // Needs to always be the first field of the structure
Expand Down Expand Up @@ -98,7 +102,11 @@ namespace rnd {
BitField<51, 1, u64> letterToMamaGiven;
BitField<52, 1, u64> pendantGiven;
BitField<53, 1, u64> enJsGivenItem;
BitField<54, 10, u64> unused;
BitField<54, 1, u64> odolwaDefeated;
BitField<55, 1, u64> gohtDefeated;
BitField<56, 1, u64> gyorgDefeated;
BitField<57, 1, u64> twinmoldDefeated;
BitField<58, 6, u64> unused;
};
GivenItemRegister givenItemChecks;
union FairyCollectRegister {
Expand Down
11 changes: 11 additions & 0 deletions code/mm.ld
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ SECTIONS{
*(.patch_FastTransformPatchFive)
}

.patch_UpdateBossLairExtData 0x29CF30 : {
*(.patch_UpdateBossLairExtData)
}

/*2bec9c GOOD DREAM */
/*
Expand Down Expand Up @@ -429,6 +432,10 @@ SECTIONS{
*(.patch_OverrideItem00Init)
}

.patch_OverrideRemainSpawn 0x3DE1A0 : {
*(.patch_OverrideRemainSpawn)
}

.patch_TingleCheckClocktownMapTwo 0x3F5F00 : {
*(.patch_TingleCheckClocktownMapTwo)
}
Expand Down Expand Up @@ -545,6 +552,10 @@ SECTIONS{
*(.patch_LoadExtData)
}

.patch_OverrideRemainSpawnTwo 0x4ABF10 : {
*(.patch_OverrideRemainSpawnTwo)
}

.patch_RemoveKafeiItemFromExtSlot 0x4AD1B8 : {
*(.patch_RemoveKafeiItemFromExtSlot)
}
Expand Down
8 changes: 8 additions & 0 deletions code/source/asm/item_override_hooks.s
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ hook_CheckOshExtData:
cmp r0,#0x0
bx lr

.global hook_OverrideRemainSpawn
hook_OverrideRemainSpawn:
push {r1-r12,lr}
bl ItemOverride_CheckBossStatus
cmp r0,#0x0
pop {r1-r12,lr}
bx lr

.global hook_GoronMaskGiveItem
hook_GoronMaskGiveItem:
push {r0-r12, lr}
Expand Down
10 changes: 10 additions & 0 deletions code/source/asm/item_override_patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ patch_OverrideQuiverArchery:
patch_OverrideQuiverArcheryTwo:
mov r2,#0x47

.section .patch_OverrideRemainSpawn
.global patch_OverrideRemainSpawn
patch_OverrideRemainSpawn:
bl hook_OverrideRemainSpawn

.section .patch_OverrideRemainSpawnTwo
.global patch_OverrideRemainSpawnTwo
patch_OverrideRemainSpawnTwo:
bl hook_OverrideRemainSpawn

.section .patch_OverrideWalletSpiderHouseTwo
.global patch_OverrideWalletSpiderHouseTwo
patch_OverrideWalletSpiderHouseTwo:
Expand Down
7 changes: 7 additions & 0 deletions code/source/asm/save_hooks.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
.arm
.text

.global hook_UpdateBossLairExtData
hook_UpdateBossLairExtData:
ldrsh r2,[r1,r5]
push {r0-r12,lr}
bl SaveFile_UpdateBossExtData
pop {r0-r12,lr}
bx lr

.global hook_SaveFile_Load
hook_SaveFile_Load:
Expand Down
5 changes: 5 additions & 0 deletions code/source/asm/save_patches.s
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
.arm

.section .patch_UpdateBossLairExtData
.global patch_UpdateBossLairExtData
patch_UpdateBossLairExtData:
bl hook_UpdateBossLairExtData

.section .patch_LoadExtData
.global patch_LoadExtData
patch_LoadExtData:
Expand Down
1 change: 1 addition & 0 deletions code/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ namespace rnd {
// const u32 newButtons = gctx->pad_state.input.new_buttons.flags;
#if defined ENABLE_DEBUG || defined DEBUG_PRINT
if (pressedButtons == (u32)game::pad::Button::ZR) {
gExtSaveData.givenItemChecks.odolwaDefeated = 1;
yPos += 10.00f;
} else if (pressedButtons == (u32)game::pad::Button::ZL) {
yPos -= 10.00f;
Expand Down
16 changes: 16 additions & 0 deletions code/source/rnd/item_override.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1054,5 +1054,21 @@ namespace rnd {
}
return false;
}

u8 ItemOverride_CheckBossStatus() {
game::SceneId scene = GetContext().gctx->scene;
switch(scene) {
case game::SceneId::OdolwaLair:
return gExtSaveData.givenItemChecks.odolwaDefeated == 0 ? 1 : 0;
case game::SceneId::GohtLair:
return gExtSaveData.givenItemChecks.gohtDefeated == 0 ? 1 : 0;
case game::SceneId::GyorgLair:
return gExtSaveData.givenItemChecks.gyorgDefeated == 0 ? 1 : 0;
case game::SceneId::TwinmoldLair:
return gExtSaveData.givenItemChecks.twinmoldDefeated == 0 ? 1 : 0;
default:
return 0;
}
}
}
} // namespace rnd
40 changes: 30 additions & 10 deletions code/source/rnd/savefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,8 @@ namespace rnd {
}
}

extern "C" void SaveFile_LoadExtSaveData() {
extern "C" {
void SaveFile_LoadExtSaveData() {
char path[] = "/0.bin";
u32 version;
u64 fileSize;
Expand Down Expand Up @@ -927,8 +928,7 @@ namespace rnd {
extDataWriteFileDirectly(fsa, path, &gExtSaveData, 0, sizeof(gExtSaveData));
extDataUnmount(fsa);
}

extern "C" void SaveFile_RemoveStoredTradeItem(u16 item, u8 slot) {
void SaveFile_RemoveStoredTradeItem(u16 item, u8 slot) {
#if defined ENABLE_DEBUG
return;
#endif
Expand All @@ -955,7 +955,8 @@ namespace rnd {
game::SaveData& saveData = game::GetCommonData().save;
saveData.inventory.items[slot] = firstItem;
}
extern "C" void SaveFile_RemoveTradeItemFromSlot(u16 item, u8 slot) {

void SaveFile_RemoveTradeItemFromSlot(u16 item, u8 slot) {
#if defined ENABLE_DEBUG
return;
#endif
Expand All @@ -971,14 +972,14 @@ namespace rnd {
}
}

extern "C" u8 SaveFile_GetItemCurrentlyInSlot(u8 slot) {
u8 SaveFile_GetItemCurrentlyInSlot(u8 slot) {
if (game::GetCommonData().save.inventory.items[slot] == game::ItemId::MysteryMilk) {
gExtSaveData.givenItemChecks.bottleMysteryGivenToEnGm = 1;
}
return (u8)game::GetCommonData().save.inventory.items[slot];
}

extern "C" void SaveFile_SetNextTradeSlotItem(u8 slot) {
void SaveFile_SetNextTradeSlotItem(u8 slot) {
if (slot != 5 && slot != 17)
return;
game::ItemId firstItem = game::ItemId::None;
Expand All @@ -997,11 +998,8 @@ namespace rnd {
game::SaveData& saveData = game::GetCommonData().save;
saveData.inventory.items[slot] = firstItem;
}
// SaveFile_DrawAndShowUIMessage() {

// }

extern "C" u16 CurrentMasksInInventory() {
u16 CurrentMasksInInventory() {
// I can see why the original devs did this, because they did not want to count specific masks (transform + FD)
u16 count = 0;
if (game::HasMask(game::ItemId::MaskOfTruth))
Expand Down Expand Up @@ -1046,4 +1044,26 @@ namespace rnd {
count += 1;
return count;
}

void SaveFile_UpdateBossExtData() {
game::SceneId scene = GetContext().gctx->scene;
switch (scene) {
case game::SceneId::OdolwaLair:
gExtSaveData.givenItemChecks.odolwaDefeated = 1;
break;
case game::SceneId::GohtLair:
gExtSaveData.givenItemChecks.gohtDefeated = 1;
break;
case game::SceneId::GyorgLair:
gExtSaveData.givenItemChecks.gyorgDefeated = 1;
break;
case game::SceneId::TwinmoldLair:
gExtSaveData.givenItemChecks.twinmoldDefeated = 1;
break;
default:
return;
}
}
}

} // namespace rnd
Loading