[Resources] Cleanup old hacks and rename (#2546)

This commit is contained in:
David Chavez 2023-02-27 02:55:40 +01:00 committed by GitHub
parent 448b4e49d3
commit 2cb4a6ee7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 32 deletions

View File

@ -873,7 +873,7 @@ extern "C" void ResourceMgr_LoadFile(const char* resName) {
OTRGlobals::Instance->context->GetResourceManager()->LoadResource(resName);
}
std::shared_ptr<Ship::Resource> ResourceMgr_LoadResource(const char* path) {
std::shared_ptr<Ship::Resource> GetResourceByNameHandlingMQ(const char* path) {
std::string Path = path;
if (ResourceMgr_IsGameMasterQuest()) {
size_t pos = 0;
@ -884,6 +884,16 @@ std::shared_ptr<Ship::Resource> 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<Ship::DisplayList>(res))->Instructions[0]);
else if (res->Type == Ship::ResourceType::Array)
return (char*)(std::static_pointer_cast<Ship::Array>(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<Ship::PlayerAnimation>(ResourceMgr_LoadResource(animPath));
auto anim = std::static_pointer_cast<Ship::PlayerAnimation>(GetResourceByNameHandlingMQ(animPath));
return (char*)&anim->limbRotData[0];
}
extern "C" Gfx* ResourceMgr_LoadGfxByName(const char* path)
{
auto res = std::static_pointer_cast<Ship::DisplayList>(ResourceMgr_LoadResource(path));
auto res = std::static_pointer_cast<Ship::DisplayList>(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<Ship::Array>(ResourceMgr_LoadResource(path));
auto res = std::static_pointer_cast<Ship::Array>(GetResourceByNameHandlingMQ(path));
return (char*)res->Scalars.data();
}
extern "C" char* ResourceMgr_LoadArrayByNameAsVec3s(const char* path) {
auto res = std::static_pointer_cast<Ship::Array>(ResourceMgr_LoadResource(path));
auto res = std::static_pointer_cast<Ship::Array>(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<Mercury> Conf) {

View File

@ -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);

View File

@ -50,7 +50,7 @@ std::shared_ptr<Ship::OtrFile> ResourceMgr_LoadFile(const char* path) {
}
// Forward Declaration of function declared in OTRGlobals.cpp
std::shared_ptr<Ship::Resource> ResourceMgr_LoadResource(const char* path);
std::shared_ptr<Ship::Resource> 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<Ship::Scene>(ResourceMgr_LoadResource(play->roomList[roomNum].fileName));
auto roomData = std::static_pointer_cast<Ship::Scene>(GetResourceByNameHandlingMQ(play->roomList[roomNum].fileName));
roomCtx->status = 1;
roomCtx->roomToLoad = roomData.get();

View File

@ -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);

View File

@ -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++) {