Skip to content

Commit

Permalink
Add Triforce Hunt (#720)
Browse files Browse the repository at this point in the history
* Add Triforce Hunt

squash head: 31c3e2f

* Move piece counter outside of extInf

* Add system to trigger Triforce Warp in multiplayer

* Don't reset TriforceWarpStatus on title screen

* Remove useless includes

* Add translations

* Add Triforce Piece to ignored items for playthrough hints
  • Loading branch information
HylianFreddy authored Apr 23, 2024
1 parent 7ef3233 commit ca479cd
Show file tree
Hide file tree
Showing 48 changed files with 629 additions and 194 deletions.
8 changes: 8 additions & 0 deletions code/include/z3D/z3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ extern const char DungeonNames[][25];
#define gRestrictionFlags ((RestrictionFlags*)0x539DC4)
#define PLAYER ((Player*)gGlobalContext->actorCtx.actorList[ACTORTYPE_PLAYER].first)
#define gMainClass ((MainClass*)0x5BE5B8)
#define gIsBottomScreenDimmed (*(s32*)0x5043EC)

#define GearSlot(X) (X - ITEM_SWORD_KOKIRI)

Expand Down Expand Up @@ -898,4 +899,11 @@ typedef void (*EffectSsDeadDb_Spawn_proc)(GlobalContext* globalCtx, Vec3f* posit
#define EffectSsDeadDb_Spawn_addr 0x3642F4
#define EffectSsDeadDb_Spawn ((EffectSsDeadDb_Spawn_proc)EffectSsDeadDb_Spawn_addr)

typedef void (*SaveGame_proc)(GlobalContext* globalCtx, u8 isSaveFileCreation);
#define SaveGame_addr 0x2FDAC8
#define SaveGame ((SaveGame_proc)SaveGame_addr)

typedef s32 (*Message_GetState_proc)(void);
#define Message_GetState ((Message_GetState_proc)0x3769d8)

#endif //_Z3D_H_
4 changes: 3 additions & 1 deletion code/include/z3D/z3Dactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ typedef struct {
/* 0x01C0 */ void* leftHandDLists;
/* 0x01C4 */ void* sheathDLists;
/* 0x01C8 */ void* waistDLists;
/* 0x01CC */ char unk_1CC[0x80];
/* 0x01CC */ char unk_1CC[0x78];
/* 0x0244 */ SkeletonAnimationModel* giModel1;
/* 0x0248 */ SkeletonAnimationModel* giModel2;
/* 0x024C */ void* giDrawSpace;
/* 0x0250 */ char unk_250[0x0004];
/* 0x0254 */ struct SkelAnime skelAnime;
Expand Down
2 changes: 1 addition & 1 deletion code/include/z3D/z3Ditem.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ typedef enum {
/* 0xC7 */ GI_TYCOON_WALLET,
/* 0xC8 */ GI_LETTER_RUTO_2,
/* 0xC9 */ GI_MAGIC_BEAN_PACK,
/* 0xCA */ GI_TRIFORCE_PIECE, // unused
/* 0xCA */ GI_TRIFORCE_PIECE,

/* 0xCB */ GI_KOKIRI_EMERALD,
/* 0xCC */ GI_GORON_RUBY,
Expand Down
10 changes: 10 additions & 0 deletions code/include/z3D/z3Dmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@ typedef f32 (*Math_SinS_proc)(s16 angle) __attribute__((pcs("aapcs-vfp")));
typedef f32 (*Math_CosS_proc)(s16 angle) __attribute__((pcs("aapcs-vfp")));
#define Math_CosS ((Math_CosS_proc)0x338F60)

typedef void (*Matrix_Multiply_proc)(nn_math_MTX34* dst, nn_math_MTX34* lhs, nn_math_MTX44* rhs)
__attribute__((pcs("aapcs-vfp")));
#define Matrix_Multiply_addr 0x36C174
#define Matrix_Multiply ((Matrix_Multiply_proc)Matrix_Multiply_addr)

typedef void (*Matrix_UpdatePosition_proc)(nn_math_MTX34* dst, nn_math_MTX34* src, Vec3f* vec)
__attribute__((pcs("aapcs-vfp")));
#define Matrix_UpdatePosition_addr 0x372070
#define Matrix_UpdatePosition ((Matrix_UpdatePosition_proc)Matrix_UpdatePosition_addr)

#endif
2 changes: 2 additions & 0 deletions code/object_and_gi_usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The following custom objectIds are currently being used:
128: Boss Keys
228: Enemy Souls
291: Ocarina Note Buttons
366: Triforce Piece

To use a custom asset, currently:
- choose an unused objectId to be repurposed for the custom item
Expand All @@ -22,4 +23,5 @@ To use a custom asset, currently:
- if you need to apply a custom texture to the model:
- add a CMAB file with the new texture in the custom archive (romfs/zelda_gi_melody.zar)
- in CustomModels_ApplyItemCMAB, add a case for the objectId
- if you need to edit the scale or position of the model, add a case in Model_Create (for overworld models) and in CustomModels_UpdateMatrix (for shop and GetItem models)
- add the objectId to this txt file
28 changes: 14 additions & 14 deletions code/oot.ld
Original file line number Diff line number Diff line change
Expand Up @@ -728,20 +728,12 @@ SECTIONS
*(.patch_CamRoll)
}

.patch_InstantTextFirstLine 0x2E049C : {
*(.patch_InstantTextFirstLine)
.patch_CheckForTextControlCode 0x2E0490 : {
* (.patch_CheckForTextControlCode)
}

.patch_InstantTextBoxBreak 0x2E0664 : {
*(.patch_InstantTextBoxBreak)
}

.patch_InstantTextRemoveOff 0x2E06C8 : {
*(.patch_InstantTextRemoveOff)
}

.patch_SkippableText 0x2E09BC : {
*(.patch_SkippableText)
.patch_HandleTextControlCode 0x2E057C : {
* (.patch_HandleTextControlCode)
}

.patch_SceneInitAfterCopyScenes 0x2EAFDC : {
Expand Down Expand Up @@ -1276,8 +1268,12 @@ SECTIONS
*(.patch_GearMenuEmptySlot)
}

.patch_LoadGame 0x447380 : {
*(.patch_LoadGame)
.patch_BeforeLoadGame 0x447380 : {
*(.patch_BeforeLoadGame)
}

.patch_AfterLoadGame 0x449F00 : {
*(.patch_AfterLoadGame)
}

.patch_DontSetMotionSetting 0x447410 : {
Expand Down Expand Up @@ -1600,6 +1596,10 @@ SECTIONS
*(.patch_HookshotRotation)
}

.patch_EditDrawGetItemAfterMatrixUpdate 0x4C4D14 : {
*(.patch_EditDrawGetItemAfterMatrixUpdate)
}

.patch_EditDrawGetItemAfterModelSpawn 0x4C61A4 : {
*(.patch_EditDrawGetItemAfterModelSpawn)
}
Expand Down
28 changes: 14 additions & 14 deletions code/oot_e.ld
Original file line number Diff line number Diff line change
Expand Up @@ -728,20 +728,12 @@ SECTIONS
*(.patch_CamRoll)
}

.patch_InstantTextFirstLine 0x2E049C : {
*(.patch_InstantTextFirstLine)
.patch_CheckForTextControlCode 0x2E0490 : {
* (.patch_CheckForTextControlCode)
}

.patch_InstantTextBoxBreak 0x2E0664 : {
*(.patch_InstantTextBoxBreak)
}

.patch_InstantTextRemoveOff 0x2E06C8 : {
*(.patch_InstantTextRemoveOff)
}

.patch_SkippableText 0x2E09BC : {
*(.patch_SkippableText)
.patch_HandleTextControlCode 0x2E057C : {
* (.patch_HandleTextControlCode)
}

.patch_SceneInitAfterCopyScenes 0x2EAFDC : {
Expand Down Expand Up @@ -1276,8 +1268,12 @@ SECTIONS
*(.patch_GearMenuEmptySlot)
}

.patch_LoadGame 0x4473A0 : {
*(.patch_LoadGame)
.patch_BeforeLoadGame 0x4473A0 : {
*(.patch_BeforeLoadGame)
}

.patch_AfterLoadGame 0x449F20 : {
*(.patch_AfterLoadGame)
}

.patch_DontSetMotionSetting 0x447430 : {
Expand Down Expand Up @@ -1600,6 +1596,10 @@ SECTIONS
*(.patch_HookshotRotation)
}

.patch_EditDrawGetItemAfterMatrixUpdate 0x4C4D14 : {
*(.patch_EditDrawGetItemAfterMatrixUpdate)
}

.patch_EditDrawGetItemAfterModelSpawn 0x4C61A4 : {
*(.patch_EditDrawGetItemAfterModelSpawn)
}
Expand Down
4 changes: 4 additions & 0 deletions code/src/actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#define OBJECT_GI_OCARINA_0 270
#define OBJECT_GI_SHOP_FAIRY 375
#define OBJECT_GI_SOLD_OUT 328
#define OBJECT_TRIFORCE 149

typedef void (*TitleCard_Update_proc)(GlobalContext* globalCtx, TitleCardContext* titleCtx);
#ifdef Version_EUR
Expand Down Expand Up @@ -271,6 +272,9 @@ void Actor_Init() {

// Define object 291 to be by default the same as object 328
strncpy(gObjectTable[OBJECT_CUSTOM_OCARINA_BUTTON].filename, gObjectTable[OBJECT_GI_SOLD_OUT].filename, 0x40);

// Define object 366 to be by default the same as object 149
strncpy(gObjectTable[OBJECT_CUSTOM_TRIFORCE_PIECE].filename, gObjectTable[OBJECT_TRIFORCE].filename, 0x40);
}

void ActorSetup_Extra() {
Expand Down
2 changes: 1 addition & 1 deletion code/src/actors/chest.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void EnBox_rUpdate(Actor* thisx, GlobalContext* globalCtx) {
u8 Chest_OverrideAnimation() {

if ((gSettingsContext.chestAnimations == CHESTANIMATIONS_ALWAYSFAST) ||
(rActiveItemActionId == 0)) // The animation is always fast for unused chests that aren't randomized
(!isItemOverrideActive)) // The animation is always fast for unused chests that aren't randomized
return FALSE;

switch (rActiveItemChestType) {
Expand Down
13 changes: 13 additions & 0 deletions code/src/actors/shops.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ s32 numShopItemsLoaded = 0; // Used to determine params. Reset this to 0 in ossa

#define EnGirlA_InitializeItemAction ((EnGirlAActionFunc)0x14D5C8)

void ShopsanityItem_Draw(Actor* itemx, GlobalContext* globalCtx);

// Checks for if item is of a certain type

u8 ShopsanityItem_IsBombs(u8 id) {
Expand Down Expand Up @@ -223,6 +225,7 @@ void ShopsanityItem_InitializeItem(EnGirlA* item, GlobalContext* globalCtx) {
u16 index = ShopsanityItem_GetIndex(shopItem);
item->actor.textId = 0x9200 + index * 2;
item->itemBuyPromptTextId = 0x9200 + index * 2 + 1;
item->actor.draw = ShopsanityItem_Draw;
}
}

Expand Down Expand Up @@ -318,6 +321,16 @@ void ShopsanityItem_Init(Actor* itemx, GlobalContext* globalCtx) {
}
}

void ShopsanityItem_Draw(Actor* itemx, GlobalContext* globalCtx) {
ShopsanityItem* item = (ShopsanityItem*)itemx;
ItemOverride override = ItemOverride_Lookup(&item->super.actor, globalCtx->sceneNum, item->getItemId);

u16 itemId = override.value.looksLikeItemId ? override.value.looksLikeItemId : override.value.itemId;
CustomModels_UpdateMatrix(&item->super.actor.modelMtx, ItemTable_GetItemRow(itemId)->objectId);

EnGirlA_Draw(itemx, globalCtx);
}

void ShopsanityItem_SellOut(Actor* itemx, u16 index) {
ShopsanityItem* item = (ShopsanityItem*)itemx;

Expand Down
35 changes: 35 additions & 0 deletions code/src/custom_models.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ static void CustomModel_SetSoldOutToRGBA565(void* soldOutCMB) {
EDIT_BYTE(0x274, 0x5B); // ImageFormat: 0x6758 -> 0x675B
}

static void CustomModel_EditTriforce(void* triforceCMB) {
char* BASE_ = (char*)triforceCMB;

// Set number of vertices from 0x120 to 0x60 so only one triangle will be drawn.
EDIT_BYTE(0x3FC, 0x60);
EDIT_BYTE(0x3FD, 0x00);
}

void CustomModel_Update(void) {
// Make sure custom_assets is loaded
if (ExtendedObject_GetIndex(&gGlobalContext->objectCtx, OBJECT_CUSTOM_GENERAL_ASSETS) < 0) {
Expand Down Expand Up @@ -306,6 +314,10 @@ void CustomModels_EditItemCMB(void* ZARBuf, u16 objectId, s8 special) {
cmb = ((char*)ZARBuf) + 0xA4;
CustomModel_SetSoldOutToRGBA565(cmb);
break;
case OBJECT_CUSTOM_TRIFORCE_PIECE:
cmb = ((char*)ZARBuf) + 0xF0;
CustomModel_EditTriforce(cmb);
break;
}
}

Expand Down Expand Up @@ -342,3 +354,26 @@ void CustomModels_ApplyItemCMAB(SkeletonAnimationModel* model, u16 objectId, s8
model->unk_0C->curFrame = special;
}
}

void CustomModels_UpdateMatrix(nn_math_MTX34* modelMtx, u16 objectId) {
f32 scale;
Vec3f posOffset;

switch (objectId) {
case OBJECT_CUSTOM_TRIFORCE_PIECE:
scale = 0.05f;
posOffset = (Vec3f){ 0.0f, -800.0f, 0.0f };
break;
default:
return;
}

nn_math_MTX44 scaleMtx = { 0 };
scaleMtx.data[0][0] = scale;
scaleMtx.data[1][1] = scale;
scaleMtx.data[2][2] = scale;
scaleMtx.data[3][3] = 1.0f;

Matrix_Multiply(modelMtx, modelMtx, &scaleMtx);
Matrix_UpdatePosition(modelMtx, modelMtx, &posOffset);
}
2 changes: 2 additions & 0 deletions code/src/custom_models.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ void CustomModel_EditTitleScreenLogo(void* titleScreenZAR);
void CustomModel_Update(void);
void CustomModels_EditItemCMB(void* ZARBuf, u16 objectId, s8 special);
void CustomModels_ApplyItemCMAB(SkeletonAnimationModel* model, u16 objectId, s8 special);
void CustomModels_UpdateMatrix(nn_math_MTX34* modelMtx, u16 objectId);

#define OBJECT_CUSTOM_DOUBLE_DEFENSE 4
#define OBJECT_CUSTOM_CHILD_SONGS 5
Expand All @@ -24,6 +25,7 @@ void CustomModels_ApplyItemCMAB(SkeletonAnimationModel* model, u16 objectId, s8
#define OBJECT_CUSTOM_GENERAL_ASSETS 182
#define OBJECT_CUSTOM_ENEMY_SOUL 228
#define OBJECT_CUSTOM_OCARINA_BUTTON 291
#define OBJECT_CUSTOM_TRIFORCE_PIECE 366

typedef enum {
TEXANIM_COPY_NINTENDO,
Expand Down
10 changes: 10 additions & 0 deletions code/src/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,16 @@ static void Gfx_DrawSeedHash(void) {
minutes, seconds);
offsetY++;

if (gSettingsContext.triforceHunt) {
Draw_DrawString(10, 16 + (SPACING_Y * offsetY++), COLOR_TITLE, "Triforce Pieces:");
u8 triforceDone = gExtSaveData.triforcePieces >= gSettingsContext.triforcePiecesRequired;
Draw_DrawFormattedString(10 + (SPACING_X * 4), 16 + (SPACING_Y * offsetY++),
triforceDone ? COLOR_YELLOW : COLOR_WHITE, "%d / %d", gExtSaveData.triforcePieces,
triforceDone ? gSettingsContext.triforcePiecesTotal
: gSettingsContext.triforcePiecesRequired);
offsetY++;
}

if (gSettingsContext.mp_Enabled) {
Draw_DrawFormattedString(10, 16 + (SPACING_Y * offsetY++), COLOR_TITLE, "Multiplayer:");
s16 playerCount = Multiplayer_PlayerCount();
Expand Down
Loading

0 comments on commit ca479cd

Please sign in to comment.