Skip to content

Commit

Permalink
fix: Update En_St to not spawn if the item it was holding was previou…
Browse files Browse the repository at this point in the history
…sly collected. (#97)

Special case required for ocean side spiderhouse, as there is an individual chest.
  • Loading branch information
PhlexPlexico authored Sep 28, 2024
1 parent 37de1db commit 3c06d72
Showing 5 changed files with 88 additions and 21 deletions.
2 changes: 2 additions & 0 deletions code/include/rnd/item_override.h
Original file line number Diff line number Diff line change
@@ -453,6 +453,8 @@ namespace rnd {
bool ItemOverride_CheckTingleMaps(u16, game::GlobalContext*);
u32 ItemOverride_GetGaboraExtData();
u32 ItemOverride_GetOshExtData();
void ItemOverride_SetSkullCollected(u16, game::SceneId);
u8 ItemOverride_IsSkullCollected(game::act::Actor*, game::SceneId);
u8 ItemOverride_OverrideSkullToken(game::act::Actor*);
u8 ItemOverride_CheckBossStatus();
}
42 changes: 23 additions & 19 deletions code/mm.ld
Original file line number Diff line number Diff line change
@@ -85,24 +85,6 @@ SECTIONS{
*(.patch_FastTransformPatchFive)
}

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

/*2bec9c GOOD DREAM */
/*
.patch_RemoveMeetMaskCutScene 0x2bec9c : {
*(.patch_RemoveMeetMaskCutScene)
} */

.patch_GiveTempSwordForHandD 0x2B523C : {
*(.patch_GiveTempSwordForHandD)
}

.patch_RemoveTempSwordForHandD 0x2DDAF0 : {
*(.patch_RemoveTempSwordForHandD)
}

.patch_KeepBowOnEpona 0x188794 : {
*(.patch_KeepBowOnEpona)
}
@@ -135,7 +117,7 @@ SECTIONS{
*(.patch_DoNotResetPermFlags)
}

.patch_DoNotRemoveTradeItems 0x1c9AA8 : {
.patch_DoNotRemoveTradeItems 0x1C9AA8 : {
*(.patch_DoNotRemoveTradeItems)
}

@@ -351,10 +333,24 @@ SECTIONS{
*(.patch_TwinmoldConsistentDamage)
}

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

/*2bec9c GOOD DREAM */
/*
.patch_RemoveMeetMaskCutScene 0x2bec9c : {
*(.patch_RemoveMeetMaskCutScene)
} */

.patch_FasterBlockMovement 0x2AC634 : {
*(.patch_FasterBlockMovement)
}

.patch_GiveTempSwordForHandD 0x2B523C : {
*(.patch_GiveTempSwordForHandD)
}

.patch_GaboraCheckExtDataNotSword 0x2CBB14 : {
*(.patch_GaboraCheckExtDataNotSword)
}
@@ -395,10 +391,18 @@ SECTIONS{
*(.patch_TingleCheckStoneTowerMap)
}

.patch_RemoveTempSwordForHandD 0x2DDAF0 : {
*(.patch_RemoveTempSwordForHandD)
}

.patch_RemoveGoronMaskCheckDarmani 0x2DE788 : {
*(.patch_RemoveGoronMaskCheckDarmani)
}

.patch_RemoveSkulltulaSpawnIfCollectedItem 0x2E8384 : {
*(.patch_RemoveSkulltulaSpawnIfCollectedItem)
}

.patch_SaveExtDataOnOwl 0x317004 : {
*(.patch_SaveExtDataOnOwl)
}
12 changes: 12 additions & 0 deletions code/source/asm/item_override_hooks.s
Original file line number Diff line number Diff line change
@@ -159,6 +159,18 @@ doNotSpawnDarmani:
nop
b 0x2DE96C

.global hook_RemoveSkulltulaSpawnIfCollectedItem
hook_RemoveSkulltulaSpawnIfCollectedItem:
push {r0-r12,lr}
cpy r0,r4
cpy r1,r6
mov r1,#0x148
ldrsh r1, [r1,r6]
bl ItemOverride_IsSkullCollected
cmp r0, #0x0
pop {r0-r12,lr}
bx lr

.global hook_CheckOshExtData
hook_CheckOshExtData:
push {lr}
5 changes: 5 additions & 0 deletions code/source/asm/item_override_patches.s
Original file line number Diff line number Diff line change
@@ -57,6 +57,11 @@ patch_RemoveAddingSkulltulaTokenIfOverridden:
patch_RemoveGoronMaskCheckDarmani:
b hook_DarmaniRewardCheck

.section .patch_RemoveSkulltulaSpawnIfCollectedItem
.global patch_RemoveSkulltulaSpawnIfCollectedItem
patch_RemoveSkulltulaSpawnIfCollectedItem:
bl hook_RemoveSkulltulaSpawnIfCollectedItem

.section .patch_CheckOshExtData
.global patch_CheckOshExtData
patch_CheckOshExtData:
48 changes: 46 additions & 2 deletions code/source/rnd/item_override.cpp
Original file line number Diff line number Diff line change
@@ -36,6 +36,13 @@ namespace rnd {

static u8 rSatisfiedPendingFrames = 0;

static u8 skulltulaMapSSH[30] = {0x03, 0x07, 0x0B, 0x13, 0x15, 0x1B, 0x1F, 0x23, 0x25, 0x29,
0x2D, 0x31, 0x37, 0x3B, 0x3F, 0x41, 0x45, 0x49, 0x4F, 0x53,
0x56, 0x5B, 0x5D, 0x62, 0x67, 0x69, 0x6D, 0x71, 0x76, 0x79};
static u8 skulltulaMapOSH[30] = {0x07, 0x0B, 0x0F, 0x13, 0x17, 0x1B, 0x1F, 0x23, 0x27, 0x2B,
0x2D, 0x33, 0x37, 0x3B, 0x3F, 0x42, 0x46, 0x4A, 0x4F, 0x53,
0x57, 0x59, 0x5D, 0x61, 0x65, 0x69, 0x6D, 0x73, 0x77, 0x7B};

void ItemOverride_Init(void) {
#ifdef ENABLE_DEBUG
// Manual overide example code
@@ -45,8 +52,8 @@ namespace rnd {
rItemOverrides[0].value.looksLikeItemId = 0x56;
rItemOverrides[1].key.scene = 0x6F;
rItemOverrides[1].key.type = ItemOverride_Type::OVR_COLLECTABLE;
rItemOverrides[1].value.getItemId = 0x01;
rItemOverrides[1].value.looksLikeItemId = 0x01;
rItemOverrides[1].value.getItemId = 0x46;
rItemOverrides[1].value.looksLikeItemId = 0x46;
rItemOverrides[2].key.scene = 0x12;
rItemOverrides[2].key.type = ItemOverride_Type::OVR_COLLECTABLE;
rItemOverrides[2].value.getItemId = 0x37;
@@ -1048,9 +1055,46 @@ namespace rnd {
return (u32)gExtSaveData.givenItemChecks.enOshGivenItem;
}

void ItemOverride_SetSkullCollected(u16 params, game::SceneId scene) {
for (u8 i = 0; i < 30; i++) {
if (scene == game::SceneId::SwampSpiderHouse) {
if (skulltulaMapSSH[i] == (params & 0xFF)) {
gExtSaveData.chestRewarded[(u8)game::SceneId::SwampSpiderHouse][i] = 1;
return;
}
} else if (scene == game::SceneId::OceansideSpiderHouse) {
if (skulltulaMapOSH[i] == (params & 0xFF)) {
gExtSaveData.chestRewarded[(u8)game::SceneId::OceansideSpiderHouse][i] = 1;
return;
}
}
}
}

u8 ItemOverride_IsSkullCollected(game::act::Actor * actor, game::SceneId scene) {
#if defined ENABLE_DEBUG || defined DEBUG_PRINT
rnd::util::Print("%s: Our scene is %#06x\n", __func__, scene);
#endif
for (u8 i = 0; i < 30; i++) {
if (scene == game::SceneId::SwampSpiderHouse) {
if (skulltulaMapSSH[i] == (actor->params & 0xFF)) {
return gExtSaveData.chestRewarded[(u8)game::SceneId::SwampSpiderHouse][i];
}
} else if (scene == game::SceneId::OceansideSpiderHouse) {
// Special case - since OSH has one chest, let's remove
if ((i+1) == 30) break;
if (skulltulaMapOSH[i+1] == (actor->params & 0xFF)) {
return gExtSaveData.chestRewarded[(u8)game::SceneId::OceansideSpiderHouse][i+1];
}
}
}
return 0;
}

u8 ItemOverride_OverrideSkullToken(game::act::Actor* actor) {
game::GlobalContext* gctx = GetContext().gctx;
s16 getItemId = gctx->scene == game::SceneId::SwampSpiderHouse ? 0x44 : 0x6D;
ItemOverride_SetSkullCollected(actor->params, gctx->scene);
ItemOverride_GetItem(gctx, actor, gctx->GetPlayerActor(), getItemId);
if (rActiveItemRow != NULL) {
ItemOverride_GetItemTextAndItemID(gctx->GetPlayerActor());

0 comments on commit 3c06d72

Please sign in to comment.