From 2cb4a6ee7e69c921ac510cfcbdb0d3214a28f9bb Mon Sep 17 00:00:00 2001 From: David Chavez Date: Mon, 27 Feb 2023 02:55:40 +0100 Subject: [PATCH] [Resources] Cleanup old hacks and rename (#2546) --- soh/soh/OTRGlobals.cpp | 40 +++++++++---------- soh/soh/OTRGlobals.h | 1 + soh/soh/z_scene_otr.cpp | 4 +- .../actors/ovl_Boss_Dodongo/z_boss_dodongo.c | 5 +-- .../actors/ovl_Boss_Ganon/z_boss_ganon.c | 6 +-- 5 files changed, 24 insertions(+), 32 deletions(-) diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index d06d0aab9..f29a8cbef 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -873,7 +873,7 @@ extern "C" void ResourceMgr_LoadFile(const char* resName) { OTRGlobals::Instance->context->GetResourceManager()->LoadResource(resName); } -std::shared_ptr ResourceMgr_LoadResource(const char* path) { +std::shared_ptr GetResourceByNameHandlingMQ(const char* path) { std::string Path = path; if (ResourceMgr_IsGameMasterQuest()) { size_t pos = 0; @@ -884,6 +884,16 @@ std::shared_ptr ResourceMgr_LoadResource(const char* path) { return OTRGlobals::Instance->context->GetResourceManager()->LoadResource(Path.c_str()); } +extern "C" char* GetResourceDataByNameHandlingMQ(const char* path) { + auto res = GetResourceByNameHandlingMQ(path); + + if (res == nullptr) { + return nullptr; + } + + return (char*)res->GetPointer(); +} + extern "C" char* ResourceMgr_LoadFileRaw(const char* resName) { // TODO: This should not exist. Anywhere we are loading textures with this function should be Resources instead. // We are not currently packing our otr archive with certain textures as resources with otr headers. @@ -961,21 +971,14 @@ extern "C" uint16_t ResourceMgr_LoadTexWidthByName(char* texPath); extern "C" uint16_t ResourceMgr_LoadTexHeightByName(char* texPath); extern "C" char* ResourceMgr_LoadTexOrDListByName(const char* filePath) { - auto res = ResourceMgr_LoadResource(filePath); + auto res = GetResourceByNameHandlingMQ(filePath); if (res->Type == Ship::ResourceType::DisplayList) return (char*)&((std::static_pointer_cast(res))->Instructions[0]); else if (res->Type == Ship::ResourceType::Array) return (char*)(std::static_pointer_cast(res))->Vertices.data(); else { - std::string Path = filePath; - if (ResourceMgr_IsGameMasterQuest()) { - size_t pos = 0; - if ((pos = Path.find("/nonmq/", 0)) != std::string::npos) { - Path.replace(pos, 7, "/mq/"); - } - } - return (char*)GetResourceDataByName(Path.c_str(), false); + return (char*)GetResourceDataByNameHandlingMQ(filePath); } } @@ -984,14 +987,14 @@ extern "C" Sprite* GetSeedTexture(uint8_t index) { } extern "C" char* ResourceMgr_LoadPlayerAnimByName(const char* animPath) { - auto anim = std::static_pointer_cast(ResourceMgr_LoadResource(animPath)); + auto anim = std::static_pointer_cast(GetResourceByNameHandlingMQ(animPath)); return (char*)&anim->limbRotData[0]; } extern "C" Gfx* ResourceMgr_LoadGfxByName(const char* path) { - auto res = std::static_pointer_cast(ResourceMgr_LoadResource(path)); + auto res = std::static_pointer_cast(GetResourceByNameHandlingMQ(path)); return (Gfx*)&res->Instructions[0]; } @@ -1052,13 +1055,13 @@ extern "C" void ResourceMgr_UnpatchGfxByName(const char* path, const char* patch extern "C" char* ResourceMgr_LoadArrayByName(const char* path) { - auto res = std::static_pointer_cast(ResourceMgr_LoadResource(path)); + auto res = std::static_pointer_cast(GetResourceByNameHandlingMQ(path)); return (char*)res->Scalars.data(); } extern "C" char* ResourceMgr_LoadArrayByNameAsVec3s(const char* path) { - auto res = std::static_pointer_cast(ResourceMgr_LoadResource(path)); + auto res = std::static_pointer_cast(GetResourceByNameHandlingMQ(path)); // if (res->CachedGameAsset != nullptr) // return (char*)res->CachedGameAsset; @@ -1186,14 +1189,7 @@ extern "C" SkeletonHeader* ResourceMgr_LoadSkeletonByName(const char* path) { } extern "C" s32* ResourceMgr_LoadCSByName(const char* path) { - // Handle mq vs nonmq for cutscenes due to scene/ paths - auto res = ResourceMgr_LoadResource(path); - - if (res == nullptr) { - return nullptr; - } - - return (s32*)res->GetPointer(); + return (s32*)GetResourceDataByNameHandlingMQ(path); } std::filesystem::path GetSaveFile(std::shared_ptr Conf) { diff --git a/soh/soh/OTRGlobals.h b/soh/soh/OTRGlobals.h index 6b393f177..d6a8182bf 100644 --- a/soh/soh/OTRGlobals.h +++ b/soh/soh/OTRGlobals.h @@ -59,6 +59,7 @@ uint32_t ResourceMgr_GetNumGameVersions(); uint32_t ResourceMgr_GetGameVersion(int index); void ResourceMgr_CacheDirectory(const char* resName); char** ResourceMgr_ListFiles(const char* searchMask, int* resultSize); +char* GetResourceDataByNameHandlingMQ(const char* path); void ResourceMgr_LoadFile(const char* resName); char* ResourceMgr_LoadFileFromDisk(const char* filePath); char* ResourceMgr_LoadJPEG(char* data, int dataSize); diff --git a/soh/soh/z_scene_otr.cpp b/soh/soh/z_scene_otr.cpp index 97de7ff61..cab4d1c69 100644 --- a/soh/soh/z_scene_otr.cpp +++ b/soh/soh/z_scene_otr.cpp @@ -50,7 +50,7 @@ std::shared_ptr ResourceMgr_LoadFile(const char* path) { } // Forward Declaration of function declared in OTRGlobals.cpp -std::shared_ptr ResourceMgr_LoadResource(const char* path); +std::shared_ptr GetResourceByNameHandlingMQ(const char* path); bool Scene_CommandSpawnList(PlayState* play, Ship::SceneCommand* cmd) { @@ -566,7 +566,7 @@ extern "C" s32 OTRfunc_8009728C(PlayState* play, RoomContext* roomCtx, s32 roomN //DmaMgr_SendRequest2(&roomCtx->dmaRequest, roomCtx->unk_34, play->roomList[roomNum].vromStart, size, 0, //&roomCtx->loadQueue, NULL, __FILE__, __LINE__); - auto roomData = std::static_pointer_cast(ResourceMgr_LoadResource(play->roomList[roomNum].fileName)); + auto roomData = std::static_pointer_cast(GetResourceByNameHandlingMQ(play->roomList[roomNum].fileName)); roomCtx->status = 1; roomCtx->roomToLoad = roomData.get(); diff --git a/soh/src/overlays/actors/ovl_Boss_Dodongo/z_boss_dodongo.c b/soh/src/overlays/actors/ovl_Boss_Dodongo/z_boss_dodongo.c index 0c3760d63..63896bc92 100644 --- a/soh/src/overlays/actors/ovl_Boss_Dodongo/z_boss_dodongo.c +++ b/soh/src/overlays/actors/ovl_Boss_Dodongo/z_boss_dodongo.c @@ -118,10 +118,7 @@ void func_808C12C4(u8* arg1, s16 arg2) { } void func_808C1554(void* arg0, void* floorTex, s32 arg2, f32 arg3) { - // Entering the King Dodongo boss battle was crashing when using only an mq otr - // because it was trying to load a texture from a non-mq path - // HACK: GetResourceDataByName doesn't account for mq vs non-mq paths, LoadTexOrDListByName does. - arg0 = ResourceMgr_LoadTexOrDListByName(arg0); + arg0 = GetResourceDataByNameHandlingMQ(arg0); floorTex = GetResourceDataByName(floorTex, false); u16* temp_s3 = SEGMENTED_TO_VIRTUAL(arg0); diff --git a/soh/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c b/soh/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c index 546f615ab..f919628bd 100644 --- a/soh/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c +++ b/soh/src/overlays/actors/ovl_Boss_Ganon/z_boss_ganon.c @@ -1210,10 +1210,8 @@ void BossGanon_SetupTowerCutscene(BossGanon* this, PlayState* play) { void BossGanon_ShatterWindows(u8 windowShatterState) { s16 i; - // Temporary solution: using LoadTexOrDList to ensure we actually have the texture available - // based on mq/nonmq. This will be handled properly with LUS 1.0 - u8* tex1 = ResourceMgr_LoadTexOrDListByName(SEGMENTED_TO_VIRTUAL(ganon_boss_sceneTex_006C18)); - u8* tex2 = ResourceMgr_LoadTexOrDListByName(SEGMENTED_TO_VIRTUAL(ganon_boss_sceneTex_007418)); + u8* tex1 = GetResourceDataByNameHandlingMQ(SEGMENTED_TO_VIRTUAL(ganon_boss_sceneTex_006C18)); + u8* tex2 = GetResourceDataByNameHandlingMQ(SEGMENTED_TO_VIRTUAL(ganon_boss_sceneTex_007418)); u8* templateTex = GetResourceDataByName(SEGMENTED_TO_VIRTUAL(gGanondorfWindowShatterTemplateTex), false); for (i = 0; i < 2048; i++) {