From e33fa05b6ee3effbd11a373955db1e641fcb5504 Mon Sep 17 00:00:00 2001 From: Patrick12115 Date: Sun, 26 Jan 2025 19:11:45 -0500 Subject: [PATCH] Re-add Custom GFX Patch --- soh/soh/Enhancements/mods.cpp | 5 ----- soh/soh/ResourceManagerHelpers.cpp | 13 +++++++++++++ soh/soh/ResourceManagerHelpers.h | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/soh/soh/Enhancements/mods.cpp b/soh/soh/Enhancements/mods.cpp index 08c7ee219..c60691213 100644 --- a/soh/soh/Enhancements/mods.cpp +++ b/soh/soh/Enhancements/mods.cpp @@ -52,12 +52,7 @@ extern "C" { #include "variables.h" #include "functions.h" #include "src/overlays/actors/ovl_En_Door/z_en_door.h" -void ResourceMgr_PatchGfxByName(const char* path, const char* patchName, int index, Gfx instruction); -void ResourceMgr_PatchCustomGfxByName(const char* path, const char* patchName, int index, Gfx instruction); -void ResourceMgr_UnpatchGfxByName(const char* path, const char* patchName); -uint8_t ResourceGetIsCustomByName(const char* name); uint8_t Player_IsCustomLinkModel(); -uint8_t ResourceMgr_FileExists(const char* resName); extern SaveContext gSaveContext; extern PlayState* gPlayState; extern void Overlay_DisplayText(float duration, const char* text); diff --git a/soh/soh/ResourceManagerHelpers.cpp b/soh/soh/ResourceManagerHelpers.cpp index 2ab345861..1fffedcf2 100644 --- a/soh/soh/ResourceManagerHelpers.cpp +++ b/soh/soh/ResourceManagerHelpers.cpp @@ -347,6 +347,19 @@ extern "C" void ResourceMgr_PatchGfxByName(const char* path, const char* patchNa *gfx = instruction; } +extern "C" void ResourceMgr_PatchCustomGfxByName(const char* path, const char* patchName, int index, Gfx instruction) { + auto res = std::static_pointer_cast( + Ship::Context::GetInstance()->GetResourceManager()->LoadResource(path)); + + Gfx* gfx = (Gfx*)&res->Instructions[index]; + + if (!originalGfx.contains(path) || !originalGfx[path].contains(patchName)) { + originalGfx[path][patchName] = { index, *gfx }; + } + + *gfx = instruction; +} + extern "C" void ResourceMgr_PatchGfxCopyCommandByName(const char* path, const char* patchName, int destinationIndex, int sourceIndex) { auto res = std::static_pointer_cast( Ship::Context::GetInstance()->GetResourceManager()->LoadResource(path)); diff --git a/soh/soh/ResourceManagerHelpers.h b/soh/soh/ResourceManagerHelpers.h index 3b14188b7..69c31d867 100644 --- a/soh/soh/ResourceManagerHelpers.h +++ b/soh/soh/ResourceManagerHelpers.h @@ -46,6 +46,7 @@ extern "C" { Gfx* ResourceMgr_LoadGfxByName(const char* path); uint8_t ResourceMgr_FileIsCustomByName(const char* path); void ResourceMgr_PatchGfxByName(const char* path, const char* patchName, int index, Gfx instruction); + void ResourceMgr_PatchCustomGfxByName(const char* path, const char* patchName, int index, Gfx instruction); void ResourceMgr_UnpatchGfxByName(const char* path, const char* patchName); char* ResourceMgr_LoadArrayByNameAsVec3s(const char* path); Vtx* ResourceMgr_LoadVtxByCRC(uint64_t crc);