diff --git a/soh/CMakeLists.txt b/soh/CMakeLists.txt index a8693eb35..67308ec1a 100644 --- a/soh/CMakeLists.txt +++ b/soh/CMakeLists.txt @@ -181,6 +181,7 @@ set(Header_Files__soh__Enhancements__randomizer "soh/Enhancements/randomizer/randomizer_item_tracker.h" "soh/Enhancements/randomizer/adult_trade_shuffle.h" "soh/Enhancements/randomizer/randomizer_check_objects.h" + "soh/Enhancements/randomizer/draw.h" ) source_group("Header Files\\soh\\Enhancements\\randomizer" FILES ${Header_Files__soh__Enhancements__randomizer}) @@ -288,6 +289,7 @@ set(Source_Files__soh__Enhancements__randomizer "soh/Enhancements/randomizer/randomizer_item_tracker.cpp" "soh/Enhancements/randomizer/adult_trade_shuffle.c" "soh/Enhancements/randomizer/randomizer_check_objects.cpp" + "soh/Enhancements/randomizer/draw.cpp" ) source_group("Source Files\\soh\\Enhancements\\randomizer" FILES ${Source_Files__soh__Enhancements__randomizer}) diff --git a/soh/soh/Enhancements/item-tables/ItemTableTypes.h b/soh/soh/Enhancements/item-tables/ItemTableTypes.h index 7e5f1a9a3..f10d94dc2 100644 --- a/soh/soh/Enhancements/item-tables/ItemTableTypes.h +++ b/soh/soh/Enhancements/item-tables/ItemTableTypes.h @@ -7,12 +7,20 @@ #define CHEST_ANIM_LONG 1 #define GET_ITEM(itemId, objectId, drawId, textId, field, chestAnim, modIndex, getItemId) \ - { itemId, field, (chestAnim != CHEST_ANIM_SHORT ? 1 : -1) * (drawId + 1), textId, objectId, modIndex, getItemId, drawId, true } + { itemId, field, (chestAnim != CHEST_ANIM_SHORT ? 1 : -1) * (drawId + 1), textId, objectId, modIndex, getItemId, drawId, true, NULL } #define GET_ITEM_NONE \ - { ITEM_NONE, 0, 0, 0, 0, 0, 0, 0, false } + { ITEM_NONE, 0, 0, 0, 0, 0, 0, 0, false, NULL } -typedef struct { +#define GET_ITEM_CUSTOM_DRAW(itemId, objectId, drawId, textId, field, chestAnim, modIndex, getItemId, drawFunc) \ + { itemId, field (chestAnim != CHEST_ANIM_SHORT ? 1 : -1) * (drawId + 1), textId, objectId, modIndex, getItemId, drawId, true, drawFunc } + +typedef struct GlobalContext GlobalContext; +typedef struct GetItemEntry GetItemEntry; + +typedef void (*CustomDrawFunc)(GlobalContext* globalCtx, GetItemEntry* getItemEntry); + +typedef struct GetItemEntry { /* 0x00 */ uint16_t itemId; /* 0x01 */ uint16_t field; // various bit-packed data /* 0x02 */ int16_t gi; // defines the draw id and chest opening animation @@ -22,4 +30,5 @@ typedef struct { /* 0x08 */ int16_t getItemId; /* 0x0A */ uint16_t gid; // Stores the GID value unmodified for future reference. /* 0x0C */ uint16_t collectable; // determines whether the item can be collected on the overworld. Will be true in most cases. -} GetItemEntry; // size = 0x0F + CustomDrawFunc drawFunc; +}; // size = 0x0F diff --git a/soh/soh/Enhancements/randomizer/draw.cpp b/soh/soh/Enhancements/randomizer/draw.cpp new file mode 100644 index 000000000..fbf97c671 --- /dev/null +++ b/soh/soh/Enhancements/randomizer/draw.cpp @@ -0,0 +1,114 @@ +#include "draw.h" +#include "z64.h" +#include "macros.h" +#include "functions.h" +#include "randomizerTypes.h" +#include +#include "objects/object_gi_key/object_gi_key.h" +#include "objects/object_gi_bosskey/object_gi_bosskey.h" + +extern "C" void Randomizer_DrawSmallKey(GlobalContext* globalCtx, GetItemEntry* getItemEntry) { + s32 pad; + + std::array color; + switch(getItemEntry->getItemId) { + case RG_FOREST_TEMPLE_SMALL_KEY: + color = {4, 195, 46}; + break; + case RG_FIRE_TEMPLE_SMALL_KEY: + color = {237, 95, 95}; + break; + case RG_WATER_TEMPLE_SMALL_KEY: + color = {85, 180, 223}; + break; + case RG_SPIRIT_TEMPLE_SMALL_KEY: + color = {222, 158, 47}; + break; + case RG_SHADOW_TEMPLE_SMALL_KEY: + color = {126, 16, 177}; + break; + case RG_GERUDO_TRAINING_GROUNDS_SMALL_KEY: + color = {221, 212, 60}; + break; + case RG_BOTTOM_OF_THE_WELL_SMALL_KEY: + color = {227, 110, 255}; + break; + case RG_GANONS_CASTLE_SMALL_KEY: + color = {80, 80, 80}; + break; + } + + OPEN_DISPS(globalCtx->state.gfxCtx); + + func_80093D18(globalCtx->state.gfxCtx); + + gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__), + G_MTX_MODELVIEW | G_MTX_LOAD); + + gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__), + G_MTX_MODELVIEW | G_MTX_LOAD); + + gsDPSetGrayscaleColor(POLY_OPA_DISP++, color[0], color[1], color[2], 255); + gsSPGrayscale(POLY_OPA_DISP++, true); + + gSPDisplayList(POLY_OPA_DISP++, (Gfx*)gGiSmallKeyDL); + + gsSPGrayscale(POLY_OPA_DISP++, false); + + CLOSE_DISPS(globalCtx->state.gfxCtx); +} + +extern "C" void Randomizer_DrawBossKey(GlobalContext* globalCtx, GetItemEntry* getItemEntry) { + s32 pad; + s16 color_slot; + color_slot = getItemEntry->getItemId - RG_FOREST_TEMPLE_BOSS_KEY; + s16 colors[6][3] = { + { 4, 195, 46 }, // Forest Temple + { 237, 95, 95 }, // Fire Temple + { 85, 180, 223 }, // Water Temple + { 222, 158, 47 }, // Spirit Temple + { 126, 16, 177 }, // Shadow Temple + { 210, 0, 0 } // Ganon's Castle + }; + + OPEN_DISPS(globalCtx->state.gfxCtx); + + func_80093D18(globalCtx->state.gfxCtx); + gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__), + G_MTX_MODELVIEW | G_MTX_LOAD); + + gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__), + G_MTX_MODELVIEW | G_MTX_LOAD); + + if (color_slot == 5) { // Ganon's Boss Key + gsDPSetGrayscaleColor(POLY_OPA_DISP++, 80, 80, 80, 255); + gsSPGrayscale(POLY_OPA_DISP++, true); + } + + gSPDisplayList(POLY_OPA_DISP++, (Gfx*)gGiBossKeyDL); + + if (color_slot == 5) { // Ganon's Boss Key + gsSPGrayscale(POLY_OPA_DISP++, false); + } + + func_80093D84(globalCtx->state.gfxCtx); + gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__), + G_MTX_MODELVIEW | G_MTX_LOAD); + + gSPMatrix(POLY_XLU_DISP++, Matrix_NewMtx(globalCtx->state.gfxCtx, (char*)__FILE__, __LINE__), + G_MTX_MODELVIEW | G_MTX_LOAD); + + if (color_slot >= 0) { + gsDPSetGrayscaleColor(POLY_XLU_DISP++, colors[color_slot][0], colors[color_slot][1], colors[color_slot][2], + 255); + gsSPGrayscale(POLY_XLU_DISP++, true); + } + + gSPDisplayList(POLY_XLU_DISP++, (Gfx*)gGiBossKeyGemDL); + + if (color_slot >= 0) { + gsSPGrayscale(POLY_XLU_DISP++, false); + } + + CLOSE_DISPS(globalCtx->state.gfxCtx); +} \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/draw.h b/soh/soh/Enhancements/randomizer/draw.h new file mode 100644 index 000000000..a703fb600 --- /dev/null +++ b/soh/soh/Enhancements/randomizer/draw.h @@ -0,0 +1,12 @@ +#ifndef RANDODRAW_H +#define RANDODRAW_H +#pragma once + +#include "../item-tables/ItemTableTypes.h" + +typedef struct GlobalContext GlobalContext; + +extern "C" void Randomizer_DrawSmallKey(GlobalContext* globalCtx, GetItemEntry* getItemEntry); +extern "C" void Randomizer_DrawBossKey(GlobalContext* globalCtx, GetItemEntry* getItemEntry); + +#endif \ No newline at end of file diff --git a/soh/soh/Enhancements/randomizer/randomizer.cpp b/soh/soh/Enhancements/randomizer/randomizer.cpp index 60c198ed4..dbb441702 100644 --- a/soh/soh/Enhancements/randomizer/randomizer.cpp +++ b/soh/soh/Enhancements/randomizer/randomizer.cpp @@ -20,6 +20,7 @@ #include #include "randomizer_check_objects.h" #include +#include "draw.h" using json = nlohmann::json; using namespace std::literals::string_literals; @@ -3889,6 +3890,11 @@ void InitRandoItemTable() { ItemTableManager::Instance->AddItemEntry(MOD_RANDOMIZER, extendedVanillaGetItemTable[i].getItemId, extendedVanillaGetItemTable[i]); } for (int i = 0; i < ARRAY_COUNT(randoGetItemTable); i++) { + if (randoGetItemTable[i].itemId >= RG_FOREST_TEMPLE_SMALL_KEY && randoGetItemTable[i].itemId <= RG_GANONS_CASTLE_SMALL_KEY) { + randoGetItemTable[i].drawFunc = (CustomDrawFunc)Randomizer_DrawSmallKey; + } else if (randoGetItemTable[i].itemId >= RG_FOREST_TEMPLE_BOSS_KEY && randoGetItemTable[i].itemId <= RG_GANONS_CASTLE_BOSS_KEY) { + randoGetItemTable[i].drawFunc = (CustomDrawFunc)Randomizer_DrawBossKey; + } ItemTableManager::Instance->AddItemEntry(MOD_RANDOMIZER, randoGetItemTable[i].itemId, randoGetItemTable[i]); } } diff --git a/soh/src/code/z_en_item00.c b/soh/src/code/z_en_item00.c index a50c74e87..60e33b0bd 100644 --- a/soh/src/code/z_en_item00.c +++ b/soh/src/code/z_en_item00.c @@ -1360,7 +1360,11 @@ void EnItem00_DrawCollectible(EnItem00* this, GlobalContext* globalCtx) { GetItemEntry randoGetItemEntry = Randomizer_GetRandomizedItem(this->getItemId, this->actor.id, this->ogParams, globalCtx->sceneNum); EnItem00_CustomItemsParticles(&this->actor, globalCtx, randoGetItemEntry); - GetItem_Draw(globalCtx, randoGetItemEntry.gid); + if (randoGetItemEntry.drawFunc != NULL) { + randoGetItemEntry.drawFunc(globalCtx, &randoGetItemEntry); + } else { + GetItem_Draw(globalCtx, randoGetItemEntry.gid); + } } else { s32 texIndex = this->actor.params - 3; @@ -1419,7 +1423,11 @@ void EnItem00_DrawHeartPiece(EnItem00* this, GlobalContext* globalCtx) { GetItemEntry randoGetItemEntry = Randomizer_GetRandomizedItem(GI_HEART_PIECE, this->actor.id, this->ogParams, globalCtx->sceneNum); EnItem00_CustomItemsParticles(&this->actor, globalCtx, randoGetItemEntry); - GetItem_Draw(globalCtx, randoGetItemEntry.gid); + if (randoGetItemEntry.drawFunc != NULL) { + randoGetItemEntry.drawFunc(globalCtx, &randoGetItemEntry); + } else { + GetItem_Draw(globalCtx, randoGetItemEntry.gid); + } } else { s32 pad; diff --git a/soh/src/code/z_player_lib.c b/soh/src/code/z_player_lib.c index 99425bd8d..f30c493da 100644 --- a/soh/src/code/z_player_lib.c +++ b/soh/src/code/z_player_lib.c @@ -1170,7 +1170,11 @@ void Player_DrawGetItemImpl(GlobalContext* globalCtx, Player* this, Vec3f* refPo Matrix_RotateZYX(0, globalCtx->gameplayFrames * 1000, 0, MTXMODE_APPLY); Matrix_Scale(0.2f, 0.2f, 0.2f, MTXMODE_APPLY); - GetItem_Draw(globalCtx, drawIdPlusOne - 1); + if(this->getItemEntry.drawFunc != NULL) { + this->getItemEntry.drawFunc(globalCtx, &this->getItemEntry); + } else { + GetItem_Draw(globalCtx, drawIdPlusOne - 1); + } CLOSE_DISPS(globalCtx->state.gfxCtx); }