Skip to content

Commit

Permalink
Updates for graphic overrides and item table (#712)
Browse files Browse the repository at this point in the history
* Fix some models rotation

* Update graphic overrides

Override access to gDrawItemTable instead of index, update rItemTable to drop graphicId

Remove extra GetItemRow function

Move editing functions for item models to reduce code duplication

Rewrite custom items explanation
  • Loading branch information
HylianFreddy authored Jan 30, 2024
1 parent d66ab65 commit e4d4603
Show file tree
Hide file tree
Showing 17 changed files with 592 additions and 537 deletions.
4 changes: 3 additions & 1 deletion code/include/z3D/z3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,9 @@ typedef struct {
typedef struct {
/* 0x00 */ s16 objectId;
/* 0x02 */ u8 objectModelIdx;
/* 0x03 */ char unk_03[0x3];
/* 0x03 */ u8 cmabIndex;
/* 0x04 */ u8 objectModelIdx2;
/* 0x05 */ u8 cmabIndex2;
} DrawItemTableEntry;

typedef struct {
Expand Down
4 changes: 3 additions & 1 deletion code/include/z3D/z3Dactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ typedef struct {
/* 0x2227 */ s8 meleeWeaponState;
/* 0x2228 */ char unk_2228[0x0020];
/* 0x2248 */ s16 fishingState; // 1: casting line, 2: can reel, 3: holding catch
/* 0x224A */ char unk_224A[0x023E];
/* 0x224A */ char unk_224A[0x0004];
/* 0x224E */ s16 giDrawIdPlusOne; // used to change mesh for rupee models
/* 0x2250 */ char unk_2250[0x0238];
/* 0x2488 */ s8 invincibilityTimer; // prevents damage when nonzero
// (positive = visible, counts towards zero each frame)
/* 0x2489 */ char unk_2489[0x27B];
Expand Down
115 changes: 114 additions & 1 deletion code/include/z3D/z3Ditem.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,120 @@ typedef enum {
/* 0x7B */ GI_BULLET_BAG_50,
/* 0x7C */ GI_ICE_TRAP, // freezes link when opened from a chest
/* 0x7D */ GI_TEXT_0, // no model appears over Link, shows text id 0 (pocket egg)
/* 0x7E */ GI_SWORD_MASTER

// The following values are custom items added by the randomizer

/* 0x7E */ GI_SWORD_MASTER,

/* 0x7F */ GI_7F, // unused

/* 0x80 */ GI_PROG_HOOKSHOT,
/* 0x81 */ GI_PROG_STRENGTH,
/* 0x82 */ GI_PROG_BOMB_BAG,
/* 0x83 */ GI_PROG_BOW,
/* 0x84 */ GI_PROG_SLINGSHOT,
/* 0x85 */ GI_PROG_WALLET,
/* 0x86 */ GI_PROG_SCALE,
/* 0x87 */ GI_PROG_NUT_UPGRADE,
/* 0x88 */ GI_PROG_STICK_UPGRADE,
/* 0x89 */ GI_PROG_BOMBCHUS,
/* 0x8A */ GI_PROG_MAGIC_METER,
/* 0x8B */ GI_PROG_OCARINA,

/* 0x8C */ GI_BOTTLE_RED_POTION,
/* 0x8D */ GI_BOTTLE_GREEN_POTION,
/* 0x8E */ GI_BOTTLE_BLUE_POTION,
/* 0x8F */ GI_BOTTLE_FAIRY,
/* 0x90 */ GI_BOTTLE_FISH,
/* 0x91 */ GI_BOTTLE_BLUE_FIRE,
/* 0x92 */ GI_BOTTLE_BUGS,
/* 0x93 */ GI_BOTTLE_BIG_POE,
/* 0x94 */ GI_BOTTLE_POE,

/* 0x95 */ GI_FOREST_BOSS_KEY,
/* 0x96 */ GI_FIRE_BOSS_KEY,
/* 0x97 */ GI_WATER_BOSS_KEY,
/* 0x98 */ GI_SPIRIT_BOSS_KEY,
/* 0x99 */ GI_SHADOW_BOSS_KEY,
/* 0x9A */ GI_GANON_BOSS_KEY,

/* 0x9B */ GI_DEKU_COMPASS,
/* 0x9C */ GI_DODONGO_COMPASS,
/* 0x9D */ GI_JABU_COMPASS,
/* 0x9E */ GI_FOREST_COMPASS,
/* 0x9F */ GI_FIRE_COMPASS,
/* 0xA0 */ GI_WATER_COMPASS,
/* 0xA1 */ GI_SPIRIT_COMPASS,
/* 0xA2 */ GI_SHADOW_COMPASS,
/* 0xA3 */ GI_BOTW_COMPASS,
/* 0xA4 */ GI_ICE_CAVERN_COMPASS,

/* 0xA5 */ GI_DEKU_MAP,
/* 0xA6 */ GI_DODONGO_MAP,
/* 0xA7 */ GI_JABU_MAP,
/* 0xA8 */ GI_FOREST_MAP,
/* 0xA9 */ GI_FIRE_MAP,
/* 0xAA */ GI_WATER_MAP,
/* 0xAB */ GI_SPIRIT_MAP,
/* 0xAC */ GI_SHADOW_MAP,
/* 0xAD */ GI_BOTW_MAP,
/* 0xAE */ GI_ICE_CAVERN_MAP,

/* 0xAF */ GI_FOREST_SMALL_KEY,
/* 0xB0 */ GI_FIRE_SMALL_KEY,
/* 0xB1 */ GI_WATER_SMALL_KEY,
/* 0xB2 */ GI_SPIRIT_SMALL_KEY,
/* 0xB3 */ GI_SHADOW_SMALL_KEY,
/* 0xB4 */ GI_BOTW_SMALL_KEY,
/* 0xB5 */ GI_GTG_SMALL_KEY,
/* 0xB6 */ GI_FORTRESS_SMALL_KEY,
/* 0xB7 */ GI_GANON_SMALL_KEY,

/* 0xB8 */ GI_DOUBLE_DEFENSE,
/* 0xB9 */ GI_MAGIC_METER,
/* 0xBA */ GI_DOUBLE_MAGIC,

/* 0xBB */ GI_MINUET,
/* 0xBC */ GI_BOLERO,
/* 0xBD */ GI_SERENADE,
/* 0xBE */ GI_REQUIEM,
/* 0xBF */ GI_NOCTURNE,
/* 0xC0 */ GI_PRELUDE,
/* 0xC1 */ GI_ZELDA_LULLABY,
/* 0xC2 */ GI_EPONA_SONG,
/* 0xC3 */ GI_SARIA_SONG,
/* 0xC4 */ GI_SUN_SONG,
/* 0xC5 */ GI_SONG_OF_TIME,
/* 0xC6 */ GI_SONG_OF_STORMS,

/* 0xC7 */ GI_TYCOON_WALLET,
/* 0xC8 */ GI_LETTER_RUTO_2,
/* 0xC9 */ GI_MAGIC_BEAN_PACK,
/* 0xCA */ GI_TRIFORCE_PIECE, // unused

/* 0xCB */ GI_KOKIRI_EMERALD,
/* 0xCC */ GI_GORON_RUBY,
/* 0xCD */ GI_ZORA_SAPPHIRE,

/* 0xCE */ GI_FOREST_MEDALLION,
/* 0xCF */ GI_FIRE_MEDALLION,
/* 0xD0 */ GI_WATER_MEDALLION,
/* 0xD1 */ GI_SPIRIT_MEDALLION,
/* 0xD2 */ GI_SHADOW_MEDALLION,
/* 0xD3 */ GI_LIGHT_MEDALLION,

/* 0xD4 */ GI_PROG_GORON_SWORD,

/* 0xD5 */ GI_FOREST_KEY_RING,
/* 0xD6 */ GI_FIRE_KEY_RING,
/* 0xD7 */ GI_WATER_KEY_RING,
/* 0xD8 */ GI_SPIRIT_KEY_RING,
/* 0xD9 */ GI_SHADOW_KEY_RING,
/* 0xDA */ GI_BOTW_KEY_RING,
/* 0xDB */ GI_GTG_KEY_RING,
/* 0xDC */ GI_FORTRESS_KEY_RING,
/* 0xDD */ GI_GANON_KEY_RING,
/* 0xDE */ GI_CHEST_GAME_KEY,
} GetItemID;

typedef enum {
Expand Down
20 changes: 7 additions & 13 deletions code/object_and_gi_usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@ The following custom objectIds are currently being used:
127: Ganon Small Key
128: Boss Keys

The following custom graphicIds are currently being used:
4: Double Defense
5: Child Songs
6: Adult Songs
7: Small Keys
8: Boss Keys

To use a custom asset, currently:
-make an editing function in custom_models.c
-assign it an objectId and graphicId in item_table.c
-add it to gObjectTable and gDrawItemTable in Actor_Init
-add a case for the objectId in Model_Init
-add a case for the graphicId in ItemOverride_EditDrawGetItem
-add it to this txt file
- choose an unused objectId to be repurposed for the custom item
- in Actor_Init, edit the unused entry in the gObjectTable to be a copy of another object (which will be the base for the modifications)
- in CustomModels_EditItemCMB, add a case for the objectId and make a function to edit the CMB model inside the ZAR object file
- 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
- add the objectId to this txt file
32 changes: 16 additions & 16 deletions code/oot.ld
Original file line number Diff line number Diff line change
Expand Up @@ -740,18 +740,26 @@ SECTIONS
*(.patch_CorrectCompassChestsTwo)
}

.patch_SaveFileSwordless 0x2FDCE4 : {
*(.patch_SaveFileSwordless)
.patch_OverrideDrawItemOne 0x2F7498 : {
*(.patch_OverrideDrawItemOne)
}

.patch_SaveGame 0x2FBFA8 : {
*(.patch_SaveGame)
}

.patch_SaveFileSwordless 0x2FDCE4 : {
*(.patch_SaveFileSwordless)
}

.patch_Gfx_Update 0x310254 : {
*(.patch_Gfx_Update)
}

.patch_OverrideDrawItemTwo 0x3148A8 : {
*(.patch_OverrideDrawItemTwo)
}

.patch_OoBBombchuOne 0x315120 : {
*(.patch_OoBBombchuOne)
}
Expand Down Expand Up @@ -844,14 +852,6 @@ SECTIONS
*(.patch_ApplyDamageMultiplier)
}

.patch_OverrideGraphicID_35495C 0x35495C : {
*(.patch_OverrideGraphicID_35495C)
}

.patch_OverrideGraphicID_354BB8 0x354BB8 : {
*(.patch_OverrideGraphicID_354BB8)
}

.patch_FastChests 0x354CD4 : {
*(.patch_FastChests)
}
Expand Down Expand Up @@ -984,6 +984,10 @@ SECTIONS
*(.patch_LullabyLocation)
}

.patch_OverrideDrawItemThree 0x3A0EA8 : {
*(.patch_OverrideDrawItemThree)
}

.patch_KokiriCheckOpenForest 0x3ACCFC : {
*(.patch_KokiriCheckOpenForest)
}
Expand Down Expand Up @@ -1552,12 +1556,8 @@ SECTIONS
*(.patch_CriticalHealthCheckThree)
}

.patch_OverrideGraphicID_4BC604 0x4BC604 : {
*(.patch_OverrideGraphicID_4BC604)
}

.patch_OverrideGraphicID_4BD5D0 0x4BD5D0 : {
*(.patch_OverrideGraphicID_4BD5D0)
.patch_OverrideGiDrawIdPlusOne 0x4BC610 : {
*(.patch_OverrideGiDrawIdPlusOne)
}

.patch_EditDrawGetItemBeforeModelSpawn 0x4C0FD0 : {
Expand Down
28 changes: 14 additions & 14 deletions code/oot_e.ld
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,10 @@ SECTIONS
*(.patch_CorrectCompassChestsTwo)
}

.patch_OverrideDrawItemOne 0x2F7498 : {
*(.patch_OverrideDrawItemOne)
}

.patch_SaveGame 0x2FBFA8 : {
*(.patch_SaveGame)
}
Expand All @@ -752,6 +756,10 @@ SECTIONS
*(.patch_Gfx_Update)
}

.patch_OverrideDrawItemTwo 0x3148A8 : {
*(.patch_OverrideDrawItemTwo)
}

.patch_OoBBombchuOne 0x315120 : {
*(.patch_OoBBombchuOne)
}
Expand Down Expand Up @@ -844,14 +852,6 @@ SECTIONS
*(.patch_ApplyDamageMultiplier)
}

.patch_OverrideGraphicID_35495C 0x35495C : {
*(.patch_OverrideGraphicID_35495C)
}

.patch_OverrideGraphicID_354BB8 0x354BB8 : {
*(.patch_OverrideGraphicID_354BB8)
}

.patch_FastChests 0x354CD4 : {
*(.patch_FastChests)
}
Expand Down Expand Up @@ -984,6 +984,10 @@ SECTIONS
*(.patch_LullabyLocation)
}

.patch_OverrideDrawItemThree 0x3A0EA8 : {
*(.patch_OverrideDrawItemThree)
}

.patch_KokiriCheckOpenForest 0x3ACCFC : {
*(.patch_KokiriCheckOpenForest)
}
Expand Down Expand Up @@ -1552,12 +1556,8 @@ SECTIONS
*(.patch_CriticalHealthCheckThree)
}

.patch_OverrideGraphicID_4BC604 0x4BC604 : {
*(.patch_OverrideGraphicID_4BC604)
}

.patch_OverrideGraphicID_4BD5D0 0x4BD5D0 : {
*(.patch_OverrideGraphicID_4BD5D0)
.patch_OverrideGiDrawIdPlusOne 0x4BC610 : {
*(.patch_OverrideGiDrawIdPlusOne)
}

.patch_EditDrawGetItemBeforeModelSpawn 0x4C0FD0 : {
Expand Down
20 changes: 0 additions & 20 deletions code/src/actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,26 +253,6 @@ 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 draw item 3 (corresponding to gid 4) to be double defense custom model
gDrawItemTable[3].objectId = OBJECT_CUSTOM_DOUBLE_DEFENSE;
gDrawItemTable[3].objectModelIdx = 0;

// Define draw item 4 (corresponding to gid 5) to be a child song custom model
gDrawItemTable[4].objectId = OBJECT_CUSTOM_CHILD_SONGS;
gDrawItemTable[4].objectModelIdx = 2;

// Define draw item 5 (corresponding to gid 6) to be an adult song custom model
gDrawItemTable[5].objectId = OBJECT_CUSTOM_ADULT_SONGS;
gDrawItemTable[5].objectModelIdx = 0;

// Define draw item 6 (corresponding to gid 7) to be small key custom model
gDrawItemTable[6].objectId = OBJECT_CUSTOM_SMALL_KEY_FOREST;
gDrawItemTable[6].objectModelIdx = 0;

// Define draw item 7 (corresponding to gid 8) to be boss key custom model
gDrawItemTable[7].objectId = OBJECT_CUSTOM_BOSS_KEYS;
gDrawItemTable[7].objectModelIdx = 0;
}

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 @@ -52,7 +52,7 @@ void Chest_ChangeAppearance(Actor* thisx, GlobalContext* globalCtx) {
ItemOverride thisOverride = ItemOverride_Lookup(thisx, globalCtx->sceneNum, 0);
ItemRow* thisItemRow;
if (thisOverride.key.all == 0) {
thisItemRow = ItemTable_GetItemRowFromIndex((thisx->params & 0x0FE0) >> 5); // get type from vanilla item table
thisItemRow = ItemTable_GetItemRow((thisx->params & 0x0FE0) >> 5); // get type from vanilla item table
} else {
thisItemRow = ItemTable_GetItemRow(ItemTable_ResolveUpgrades(thisOverride.value.itemId));
}
Expand Down
Loading

0 comments on commit e4d4603

Please sign in to comment.