From 67ddce5cba357476b4ca408245d09d16590d0c86 Mon Sep 17 00:00:00 2001 From: Archez Date: Sun, 19 May 2024 13:46:38 -0400 Subject: [PATCH] clean up masterquest copy paste (#424) --- mm/2s2h/BenPort.cpp | 102 ++++++---------------------------------- mm/2s2h/BenPort.h | 5 -- mm/2s2h/z_scene_2SH.cpp | 4 +- 3 files changed, 16 insertions(+), 95 deletions(-) diff --git a/mm/2s2h/BenPort.cpp b/mm/2s2h/BenPort.cpp index c8d7bc1fd..9cb170a11 100644 --- a/mm/2s2h/BenPort.cpp +++ b/mm/2s2h/BenPort.cpp @@ -109,10 +109,6 @@ Color_RGB8 zoraColor = { 0x00, 0xEC, 0x64 }; OTRGlobals::OTRGlobals() { std::vector archiveFiles; - //std::string mqPath = Ship::Context::LocateFileAcrossAppDirs("oot-mq.otr", appShortName); - //if (std::filesystem::exists(mqPath)) { - // OTRFiles.push_back(mqPath); - //} std::string mmPath = Ship::Context::LocateFileAcrossAppDirs("mm.zip", appShortName); if (std::filesystem::exists(mmPath)) { archiveFiles.push_back(mmPath); @@ -415,7 +411,6 @@ extern "C" void InitOTR() { exit(1); } - bool generatedOtrIsMQ = false; if (Extractor::ShowYesNoBox("No OTR Files", "No OTR files found. Generate one now?") == IDYES) { Extractor extract; if (!extract.Run()) { @@ -423,7 +418,6 @@ extern "C" void InitOTR() { exit(1); } extract.CallZapd(installPath, Ship::Context::GetAppDirectoryPath(appShortName)); - generatedOtrIsMQ = extract.IsMasterQuest(); } else { exit(1); } @@ -789,53 +783,6 @@ extern "C" uint32_t ResourceMgr_GetGameRegion(int index) { } } -uint32_t IsSceneMasterQuest(s16 sceneNum) { - return false; - uint32_t value = 0; - //uint8_t mqMode = CVarGetInteger("gBetterDebugWarpScreenMQMode", WARP_MODE_OVERRIDE_OFF); - //if (mqMode == WARP_MODE_OVERRIDE_MQ_AS_VANILLA) { - // return 1; - //} else if (mqMode == WARP_MODE_OVERRIDE_VANILLA_AS_MQ) { - // return 0; - //} else { - // if (OTRGlobals::Instance->HasMasterQuest()) { - // if (!OTRGlobals::Instance->HasOriginal()) { - // value = 1; - // } else if (IS_MASTER_QUEST) { - // value = 1; - // } else { - // value = 0; - // if (IS_RANDO && !OTRGlobals::Instance->gRandomizer->masterQuestDungeons.empty() && - // OTRGlobals::Instance->gRandomizer->masterQuestDungeons.contains(sceneNum)) { - // value = 1; - // } - // } - // } - //} - return value; -} - -uint32_t IsGameMasterQuest() { - return false; - //return gPlayState != NULL ? IsSceneMasterQuest(gPlayState->sceneNum) : 0; -} - -extern "C" uint32_t ResourceMgr_GameHasMasterQuest() { - return OTRGlobals::Instance->HasMasterQuest(); -} - -extern "C" uint32_t ResourceMgr_GameHasOriginal() { - return OTRGlobals::Instance->HasOriginal(); -} - -extern "C" uint32_t ResourceMgr_IsSceneMasterQuest(s16 sceneNum) { - return IsSceneMasterQuest(sceneNum); -} - -extern "C" uint32_t ResourceMgr_IsGameMasterQuest() { - return IsGameMasterQuest(); -} - extern "C" void ResourceMgr_LoadDirectory(const char* resName) { Ship::Context::GetInstance()->GetResourceManager()->LoadDirectory(resName); } @@ -873,25 +820,8 @@ extern "C" void ResourceMgr_LoadFile(const char* resName) { Ship::Context::GetInstance()->GetResourceManager()->LoadResource(resName); } -std::shared_ptr GetResourceByNameHandlingMQ(const char* path) { - std::string Path = path; - if (ResourceMgr_IsGameMasterQuest()) { - size_t pos = 0; - if ((pos = Path.find("/nonmq/", 0)) != std::string::npos) { - Path.replace(pos, 7, "/mq/"); - } - } - return Ship::Context::GetInstance()->GetResourceManager()->LoadResource(Path.c_str()); -} - -extern "C" char* GetResourceDataByNameHandlingMQ(const char* path) { - auto res = GetResourceByNameHandlingMQ(path); - - if (res == nullptr) { - return nullptr; - } - - return (char*)res->GetRawPointer(); +std::shared_ptr GetResourceByName(const char* path) { + return Ship::Context::GetInstance()->GetResourceManager()->LoadResource(path); } extern "C" char* ResourceMgr_LoadFileFromDisk(const char* filePath) { @@ -909,7 +839,7 @@ extern "C" char* ResourceMgr_LoadFileFromDisk(const char* filePath) { } extern "C" uint8_t ResourceMgr_ResourceIsBackground(char* texPath) { - auto res = GetResourceByNameHandlingMQ(texPath); + auto res = GetResourceByName(texPath); return res->GetInitData()->Type == static_cast(SOH::ResourceType::SOH_Background); } @@ -955,19 +885,19 @@ 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 = GetResourceByNameHandlingMQ(filePath); + auto res = GetResourceByName(filePath); if (res->GetInitData()->Type == static_cast(LUS::ResourceType::DisplayList)) return (char*)&((std::static_pointer_cast(res))->Instructions[0]); else if (res->GetInitData()->Type == static_cast(LUS::ResourceType::Array)) return (char*)(std::static_pointer_cast(res))->Vertices.data(); else { - return (char*)GetResourceDataByNameHandlingMQ(filePath); + return (char*)ResourceGetDataByName(filePath); } } extern "C" char* ResourceMgr_LoadIfDListByName(const char* filePath) { - auto res = GetResourceByNameHandlingMQ(filePath); + auto res = GetResourceByName(filePath); if (res->GetInitData()->Type == static_cast(LUS::ResourceType::DisplayList)) return (char*)&((std::static_pointer_cast(res))->Instructions[0]); @@ -980,7 +910,7 @@ extern "C" char* ResourceMgr_LoadIfDListByName(const char* filePath) { //} extern "C" char* ResourceMgr_LoadPlayerAnimByName(const char* animPath) { - auto anim = std::static_pointer_cast(GetResourceByNameHandlingMQ(animPath)); + auto anim = std::static_pointer_cast(GetResourceByName(animPath)); return (char*)&anim->limbRotData[0]; } @@ -990,7 +920,7 @@ extern "C" void ResourceMgr_PushCurrentDirectory(char* path) { } extern "C" Gfx* ResourceMgr_LoadGfxByName(const char* path) { - auto res = std::static_pointer_cast(GetResourceByNameHandlingMQ(path)); + auto res = std::static_pointer_cast(GetResourceByName(path)); return (Gfx*)&res->Instructions[0]; } @@ -1073,32 +1003,30 @@ extern "C" void ResourceMgr_UnpatchGfxByName(const char* path, const char* patch } extern "C" char* ResourceMgr_LoadVtxArrayByName(const char* path) { - auto res = std::static_pointer_cast(GetResourceByNameHandlingMQ(path)); + auto res = std::static_pointer_cast(GetResourceByName(path)); return (char*)res->Vertices.data(); } extern "C" size_t ResourceMgr_GetVtxArraySizeByName(const char* path) { - auto res = std::static_pointer_cast(GetResourceByNameHandlingMQ(path)); + auto res = std::static_pointer_cast(GetResourceByName(path)); return res->Vertices.size(); - // } } extern "C" char* ResourceMgr_LoadArrayByName(const char* path) { - auto res = std::static_pointer_cast(GetResourceByNameHandlingMQ(path)); + auto res = std::static_pointer_cast(GetResourceByName(path)); return (char*)res->Scalars.data(); } extern "C" size_t ResourceMgr_GetArraySizeByName(const char* path) { - auto res = std::static_pointer_cast(GetResourceByNameHandlingMQ(path)); + auto res = std::static_pointer_cast(GetResourceByName(path)); return res->Scalars.size(); - // } } extern "C" char* ResourceMgr_LoadArrayByNameAsVec3s(const char* path) { - auto res = std::static_pointer_cast(GetResourceByNameHandlingMQ(path)); + auto res = std::static_pointer_cast(GetResourceByName(path)); // if (res->CachedGameAsset != nullptr) // return (char*)res->CachedGameAsset; @@ -1270,7 +1198,7 @@ extern "C" void ResourceMgr_ClearSkeletons(SkelAnime* skelAnime) { } extern "C" s32* ResourceMgr_LoadCSByName(const char* path) { - return (s32*)GetResourceDataByNameHandlingMQ(path); + return (s32*)ResourceGetDataByName(path); } std::filesystem::path GetSaveFile(std::shared_ptr Conf) { @@ -1574,7 +1502,7 @@ extern "C" void Gfx_TextureCacheDelete(const uint8_t* texAddr) { } if (ResourceMgr_OTRSigCheck(imgName)) { - texAddr = (const uint8_t*)GetResourceDataByNameHandlingMQ(imgName); + texAddr = (const uint8_t*)ResourceGetDataByName(imgName); } gfx_texture_cache_delete(texAddr); diff --git a/mm/2s2h/BenPort.h b/mm/2s2h/BenPort.h index b76d92c0c..be6ddd671 100644 --- a/mm/2s2h/BenPort.h +++ b/mm/2s2h/BenPort.h @@ -64,10 +64,6 @@ void OTRGfxPrint(const char* str, void* printer, void (*printImpl)(void*, char)) void OTRGetPixelDepthPrepare(float x, float y); uint16_t OTRGetPixelDepth(float x, float y); int32_t OTRGetLastScancode(); -uint32_t ResourceMgr_IsGameMasterQuest(); -uint32_t ResourceMgr_IsSceneMasterQuest(s16 sceneNum); -uint32_t ResourceMgr_GameHasMasterQuest(); -uint32_t ResourceMgr_GameHasOriginal(); uint32_t ResourceMgr_GetNumGameVersions(); uint32_t ResourceMgr_GetGameVersion(int index); uint32_t ResourceMgr_GetGamePlatform(int index); @@ -75,7 +71,6 @@ uint32_t ResourceMgr_GetGameRegion(int index); void ResourceMgr_LoadDirectory(const char* resName); char** ResourceMgr_ListFiles(const char* searchMask, int* resultSize); uint8_t ResourceMgr_FileExists(const char* resName); -char* GetResourceDataByNameHandlingMQ(const char* path); void ResourceMgr_LoadFile(const char* resName); char* ResourceMgr_LoadFileFromDisk(const char* filePath); uint8_t ResourceMgr_ResourceIsBackground(char* texPath); diff --git a/mm/2s2h/z_scene_2SH.cpp b/mm/2s2h/z_scene_2SH.cpp index d6f448ead..acc7023fa 100644 --- a/mm/2s2h/z_scene_2SH.cpp +++ b/mm/2s2h/z_scene_2SH.cpp @@ -488,8 +488,6 @@ s32 OTRScene_ExecuteCommands(PlayState* play, SOH::Scene* scene) { } -std::shared_ptr GetResourceByNameHandlingMQ(const char* path); - extern "C" s32 OTRfunc_8009728C(PlayState* play, RoomContext* roomCtx, s32 roomNum) { u32 size; @@ -513,7 +511,7 @@ extern "C" s32 OTRfunc_8009728C(PlayState* play, RoomContext* roomCtx, s32 roomN //&roomCtx->loadQueue, NULL, __FILE__, __LINE__); printf("File Name %s\n", play->roomList[roomNum].fileName); auto roomData = - std::static_pointer_cast(GetResourceByNameHandlingMQ(play->roomList[roomNum].fileName)); + std::static_pointer_cast(ResourceLoad(play->roomList[roomNum].fileName)); roomCtx->status = 1; roomCtx->activeRoomVram = roomData.get();