Skip to content

Commit

Permalink
Add Triforce Hunt
Browse files Browse the repository at this point in the history
squash head: 31c3e2f
  • Loading branch information
HylianFreddy committed Mar 2, 2024
1 parent 3d5291f commit 721be0e
Show file tree
Hide file tree
Showing 42 changed files with 520 additions and 192 deletions.
4 changes: 4 additions & 0 deletions code/include/z3D/z3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -863,4 +863,8 @@ typedef void (*Animation_Change_proc)(SkelAnime* anime, s32 animation_index, f32
#define Animation_Change_addr 0x375C08
#define Animation_Change ((Animation_Change_proc)Animation_Change_addr)

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

#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 @@ -12,6 +12,7 @@ The following custom objectIds are currently being used:
126: GTG Small Key
127: Ganon Small Key
128: Boss Keys
366: Triforce Piece

To use a custom asset, currently:
- choose an unused objectId to be repurposed for the custom item
Expand All @@ -20,4 +21,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 @@ -708,20 +708,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 @@ -1244,8 +1236,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 @@ -1568,6 +1564,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 @@ -708,20 +708,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 @@ -1244,8 +1236,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 @@ -1568,6 +1564,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 @@ -61,6 +61,7 @@
#define OBJECT_GI_HEARTS 189
#define OBJECT_GI_OCARINA 222
#define OBJECT_GI_OCARINA_0 270
#define OBJECT_TRIFORCE 149

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

// Define object 128 to be by default the same as object 185
strncpy(gObjectTable[OBJECT_CUSTOM_BOSS_KEYS].filename, gObjectTable[OBJECT_GI_BOSSKEY].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
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 @@ -227,6 +227,14 @@ static void CustomModel_SetBossKeyToRGBA565(void* bossKeyCMB) {
EDIT_BYTE(0x44B, 0x00);
}

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 @@ -266,6 +274,10 @@ void CustomModels_EditItemCMB(void* ZARBuf, u16 objectId, s8 special) {
cmb = ((char*)ZARBuf) + 0x78;
CustomModel_SetBossKeyToRGBA565(cmb);
break;
case OBJECT_CUSTOM_TRIFORCE_PIECE:
cmb = ((char*)ZARBuf) + 0xF0;
CustomModel_EditTriforce(cmb);
break;
}
}

Expand Down Expand Up @@ -296,3 +308,26 @@ void CustomModels_ApplyItemCMAB(SkeletonAnimationModel* model, u16 objectId, s8
break;
}
}

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 @@ -22,6 +23,7 @@ void CustomModels_ApplyItemCMAB(SkeletonAnimationModel* model, u16 objectId, s8
#define OBJECT_CUSTOM_SMALL_KEY_GANON 127
#define OBJECT_CUSTOM_BOSS_KEYS 128
#define OBJECT_CUSTOM_GENERAL_ASSETS 182
#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 @@ -368,6 +368,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.extInf[EXTINF_TRIFORCE_PIECES] >= gSettingsContext.triforcePiecesRequired;
Draw_DrawFormattedString(
10 + (SPACING_X * 4), 16 + (SPACING_Y * offsetY++), triforceDone ? COLOR_YELLOW : COLOR_WHITE, "%d / %d",
gExtSaveData.extInf[EXTINF_TRIFORCE_PIECES],
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 721be0e

Please sign in to comment.