Skip to content

Commit

Permalink
Merge pull request #10 from Z3DR/extdata-checks
Browse files Browse the repository at this point in the history
More extdata fixes
  • Loading branch information
PhlexPlexico authored Jan 25, 2024
2 parents febb038 + 8939fd6 commit b4bc697
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 17 deletions.
8 changes: 7 additions & 1 deletion code/include/game/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,18 @@ namespace game::act {
DayTimer = 0x00F5,
// Elegy of Emptiness statue
ObjElegyStatue = 0x001F,
// En_Gm - Gorman Bros Race
// En_Im - Gorman Bros Race - Ingo
EnIn = 0x004D,
// Clear Tag (?)
ClearTag = 0x0073,
// Gorman
EnGm = 0x0074,
// En_Hs - Grog The Chicken Man
EnHs = 0x0076,
// Cursed Man Spider House
EnSsh = 0x0090,
// Biggoron
EnDai = 0x00D5,
// [1] Deku Palace / Woodfall Temple moving platforms (after player lands on them)
ObjRailLift = 0x00D8,
// Shooting Gallery - Man
Expand Down Expand Up @@ -79,6 +83,8 @@ namespace game::act {
EnMaYto = 0x01AF,
// [7] Owl statue
ObjOwlStatue = 0x01B2,
// Gabora
EnKgy = 0x018F,
// [4] Old Lady from Bomb Shop
NpcEnBaba = 0x01C5,
// Granny
Expand Down
3 changes: 2 additions & 1 deletion code/include/rnd/item_override.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,8 @@ namespace rnd {
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" void ItemOverride_SetGrogExtData();
extern "C" u32 ItemOverride_GetGaboraExtData();
extern "C" u32 ItemOverride_GetOshExtData();
extern "C" u32 rActiveItemGraphicId;
extern "C" ItemOverride rItemOverrides[640];
extern "C" u16 rStoredTextId;
Expand Down
7 changes: 6 additions & 1 deletion code/include/rnd/savefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ namespace rnd {
BitField<22, 1, u32> enMaYtoGivenItem;
BitField<23, 1, u32> enOskGivenItem;
BitField<24, 1, u32> enPstGivenItem;
BitField<25, 7, u32> unused;
BitField<25, 2, u32> enKgyGivenItem;
BitField<27, 1, u32> enGmGivenItem;
BitField<28, 1, u32> enFsnANMGivenItem;
BitField<29, 1, u32> enOshGivenItem;
BitField<30, 1, u32> enDaiGivenItem;
BitField<31, 1, u32> unused;
};
GivenItemRegister givenItemChecks;
union FairyCollectRegister {
Expand Down
10 changes: 9 additions & 1 deletion code/mm.ld
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,16 @@ SECTIONS{
*(.patch_FasterBlockMovement)
}

.patch_GaboraCheckExtDataNotSword 0x2CBB14 : {
*(.patch_GaboraCheckExtDataNotSword)
}

.patch_DoNotRemoveSwordGaboraOne 0x2CBCB0 : {
*(.patch_DoNotRemoveSwordGabora)
}

.patch_DoNotRemoveSwordGaboraTwo 0x2CBCC0 : {
*(.patch_DoNotRemoveSwordGabora)
*(.patch_DoNotRemoveSwordGaboraTwo)
}

.patch_FasterBlockMovementBack 0x2D0C0C : {
Expand Down Expand Up @@ -311,6 +315,10 @@ SECTIONS{
*(.patch_RemoveGoronMaskCheckDarmani)
}

.patch_CheckOshExtData 0x3BF224 : {
*(.patch_CheckOshExtData)
}

.patch_OverrideQuiverArcheryTown 0x3E50E4 : {
*(.patch_OverrideQuiverArchery)
}
Expand Down
28 changes: 28 additions & 0 deletions code/source/asm/hooks.s
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ 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}
Expand Down Expand Up @@ -302,6 +310,26 @@ 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}
Expand Down
16 changes: 16 additions & 0 deletions code/source/asm/patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ patch_EnteringLocation:
patch_RemoveGoronMaskCheckDarmani:
b hook_DarmaniRewardCheck

.section .patch_CheckOshExtData
.global patch_CheckOshExtData
patch_CheckOshExtData:
bl hook_CheckOshExtData

.section .patch_OverrideQuiverArchery
.global patch_OverrideQuiverArchery
patch_OverrideQuiverArchery:
Expand Down Expand Up @@ -342,12 +347,23 @@ patch_HandleOcarinaHooks:
patch_FasterBlockMovement:
.float 50.0

.section .patch_GaboraCheckExtDataNotSword
.global patch_GaboraCheckExtDataNotSword
patch_GaboraCheckExtDataNotSword:
bl hook_GaboraCheckExtDataNotSword

@ Removes sword being removed from inventory during
.section .patch_DoNotRemoveSwordGabora
.global patch_DoNotRemoveSwordGabora
patch_DoNotRemoveSwordGabora:
nop

@ Removes sword being removed from inventory during
.section .patch_DoNotRemoveSwordGaboraTwo
.global patch_DoNotRemoveSwordGaboraTwo
patch_DoNotRemoveSwordGaboraTwo:
nop

.section .patch_FasterBlockMovementBack
.global patch_FasterBlockMovementBack
patch_FasterBlockMovementBack:
Expand Down
51 changes: 41 additions & 10 deletions code/source/rnd/item_override.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern "C" {
namespace rnd {
static s32 rItemOverrides_Count = 0;
static game::act::Id storedActorId = game::act::Id::Player;
static rnd::GetItemID storedGetItemId = rnd::GetItemID::GI_NONE;
ItemOverride rItemOverrides[640] = {0};
static game::act::Actor* rDummyActor = NULL;
static ItemOverride rPendingOverrideQueue[3] = {0};
Expand Down Expand Up @@ -44,8 +45,8 @@ namespace rnd {
rItemOverrides[0].value.looksLikeItemId = 0x26;
rItemOverrides[1].key.scene = 0x6F;
rItemOverrides[1].key.type = ItemOverride_Type::OVR_COLLECTABLE;
rItemOverrides[1].value.getItemId = 0xB6;
rItemOverrides[1].value.looksLikeItemId = 0xB6;
rItemOverrides[1].value.getItemId = 0x12;
rItemOverrides[1].value.looksLikeItemId = 0x12;
rItemOverrides[2].key.scene = 0x12;
rItemOverrides[2].key.type = ItemOverride_Type::OVR_COLLECTABLE;
rItemOverrides[2].value.getItemId = 0x37;
Expand Down Expand Up @@ -165,6 +166,7 @@ namespace rnd {
rActiveItemFastChest = 0;
rCustomDungeonItemRetrieved = 0;
storedActorId = game::act::Id::Player;
storedGetItemId = rnd::GetItemID::GI_NONE;
}

static void ItemOverride_PushPendingOverride(ItemOverride override) {
Expand Down Expand Up @@ -430,7 +432,11 @@ namespace rnd {
} else if (storedActorId == game::act::Id::NpcEnBaba) {
gExtSaveData.givenItemChecks.enBabaGivenItem = 1;
} else if (storedActorId == game::act::Id::NpcEnFsn) {
gExtSaveData.givenItemChecks.enFsnGivenItem = 1;
if (storedGetItemId == rnd::GetItemID::GI_MASK_ALL_NIGHT) {
gExtSaveData.givenItemChecks.enFsnANMGivenItem = 1;
} else {
gExtSaveData.givenItemChecks.enFsnGivenItem = 1;
}
} else if (storedActorId == game::act::Id::NpcEnPm) {
gExtSaveData.givenItemChecks.enPmGivenItem = 1;
} else if (storedActorId == game::act::Id::EnSsh) {
Expand All @@ -449,6 +455,18 @@ namespace rnd {
gExtSaveData.givenItemChecks.enTruGivenItem = 1;
} else if (storedActorId == game::act::Id::EnPst) {
gExtSaveData.givenItemChecks.enPstGivenItem = 1;
} else if (storedActorId == game::act::Id::EnKgy) {
if (gExtSaveData.givenItemChecks.enKgyGivenItem == 1) {
gExtSaveData.givenItemChecks.enKgyGivenItem = 2;
} else {
gExtSaveData.givenItemChecks.enKgyGivenItem = 1;
}
} else if (storedActorId == game::act::Id::EnGm) {
gExtSaveData.givenItemChecks.enGmGivenItem = 1;
} else if (storedActorId == game::act::Id::EnOsh) {
gExtSaveData.givenItemChecks.enOshGivenItem = 1;
} else if (storedActorId == game::act::Id::EnDai) {
gExtSaveData.givenItemChecks.enDaiGivenItem = 1;
}
}

Expand All @@ -467,10 +485,10 @@ namespace rnd {
}

ItemOverride_PushPendingOverride(override);
if (override.value.getItemId == 0x12) {
rActiveItemRow->effectArg1 = override.key.all >> 16;
rActiveItemRow->effectArg2 = override.key.all & 0xFFFF;
}
// if (override.value.getItemId == 0x12) {
// rActiveItemRow->effectArg1 = override.key.all >> 16;
// rActiveItemRow->effectArg2 = override.key.all & 0xFFFF;
// }
return;
}

Expand Down Expand Up @@ -565,6 +583,7 @@ namespace rnd {
// #endif
s16 getItemId = ItemOverride_CheckNpc(fromActor->id, incomingGetItemId, incomingNegative);
storedActorId = fromActor->id;
storedGetItemId = (rnd::GetItemID)incomingGetItemId;
override = ItemOverride_Lookup(fromActor, (u16)gctx->scene, getItemId);
}
if (override.key.all == 0) {
Expand Down Expand Up @@ -701,6 +720,15 @@ namespace rnd {
} else if (currentItem == game::ItemId::CaptainHat) {
return givenItems.enOskGivenItem ? (int)currentItem
: (int)0xFF;
} else if (currentItem == game::ItemId::CircusLeaderMask) {
return givenItems.enGmGivenItem ? (int) currentItem
: (int)0xFF;
} else if (currentItem == game::ItemId::AllNightMask) {
return givenItems.enFsnANMGivenItem ? (int) currentItem
: (int)0xFF;
} else if (currentItem == game::ItemId::PowderKeg) {
return givenItems.enDaiGivenItem ? (int) currentItem
: (int)0xFF;
}
auto& inventory = game::GetCommonData().save.inventory.items;
return (int)inventory[(int)currentItem];
Expand Down Expand Up @@ -763,9 +791,12 @@ namespace rnd {
return false;
}

void ItemOverride_SetGrogExtData() {
gExtSaveData.givenItemChecks.enHsGivenItem = 1;
return;
u32 ItemOverride_GetGaboraExtData() {
return (u32)gExtSaveData.givenItemChecks.enKgyGivenItem;
}

u32 ItemOverride_GetOshExtData() {
return (u32)gExtSaveData.givenItemChecks.enOshGivenItem;
}
}
} // namespace rnd
7 changes: 4 additions & 3 deletions code/source/rnd/savefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ namespace rnd {
#ifdef ENABLE_DEBUG
saveData.player.razor_sword_hp = 0x64;
saveData.skulltulas_collected.swamp_count = 30;
saveData.skulltulas_collected.ocean_count = 30;
saveData.anonymous_162 = saveData.anonymous_162 | 0x6000;
rnd::util::GetPointer<void(game::ItemId)>(0x22b14c)(game::ItemId::MaskOfTruth);
rnd::util::GetPointer<void(game::ItemId)>(0x22b14c)(game::ItemId::PictographBox);
rnd::util::GetPointer<void(game::ItemId)>(0x22b14c)(game::ItemId::PowderKeg);
// saveData.inventory.inventory_count_register.quiver_upgrade = game::Quiver::Quiver50;
saveData.inventory.inventory_count_register.bomb_bag_upgrade = game::BombBag::BombBag40;
saveData.inventory.inventory_count_register.wallet_upgrade = 2;
saveData.inventory.inventory_count_register.stick_upgrades = 2;
saveData.inventory.inventory_count_register.nut_upgrade = 2;
saveData.player.rupee_count = 500;
saveData.player.rupee_count = 5000;
saveData.inventory.items[1] = game::ItemId::Arrow;
saveData.inventory.items[2] = game::ItemId::FireArrow;
saveData.inventory.items[3] = game::ItemId::IceArrow;
Expand Down Expand Up @@ -108,7 +110,6 @@ namespace rnd {
gSettingsContext.skipBombersMinigame = 1;
gSettingsContext.freeScarecrow = 1;
saveData.activate_dungeon_skip_portal_0xF0_for_all = 0xF0;

SaveFile_FillOverWorldMapData();

#endif
Expand Down Expand Up @@ -137,7 +138,7 @@ namespace rnd {
// saveData.inventory.collect_register.song_of_healing = 1; // until happy mask salesman is overridden
saveData.player.owl_statue_flags.clock_town = 1;
#ifdef ENABLE_DEBUG
gSettingsContext.startingKokiriSword = 0;
gSettingsContext.startingKokiriSword = 2;
gSettingsContext.startingShield = 0;
#endif
SaveFile_SetStartingInventory();
Expand Down

0 comments on commit b4bc697

Please sign in to comment.