diff --git a/src/Cafe/GraphicPack/GraphicPack2Patches.h b/src/Cafe/GraphicPack/GraphicPack2Patches.h index 45505062..c5bdca19 100644 --- a/src/Cafe/GraphicPack/GraphicPack2Patches.h +++ b/src/Cafe/GraphicPack/GraphicPack2Patches.h @@ -225,6 +225,8 @@ class PatchGroup friend class GraphicPack2; public: + static constexpr uint32 CODECAVE_MAX_OFFSET = 8 * 1024 * 1024; + PatchGroup(class GraphicPack2* gp, const char* nameStr, sint32 nameLength) : graphicPack(gp) { name = std::string(nameStr, nameLength); diff --git a/src/Cafe/GraphicPack/GraphicPack2PatchesApply.cpp b/src/Cafe/GraphicPack/GraphicPack2PatchesApply.cpp index 783d2f07..da1ddb44 100644 --- a/src/Cafe/GraphicPack/GraphicPack2PatchesApply.cpp +++ b/src/Cafe/GraphicPack/GraphicPack2PatchesApply.cpp @@ -8,7 +8,7 @@ bool _relocateAddress(PatchGroup* group, PatchContext_t* ctx, uint32 addr, uint32& relocatedAddress) { - if (addr >= 0 && addr <= 1024 * 1024 * 8) + if (addr <= PatchGroup::CODECAVE_MAX_OFFSET) { // codecave address relocatedAddress = group->getCodeCaveBase() + addr; @@ -574,6 +574,12 @@ void GraphicPack2::ApplyPatchGroups(std::vector& groups, const RPLM if (patchGroup->codeCaveSize > 0) { auto codeCaveMem = RPLLoader_AllocateCodeCaveMem(256, patchGroup->codeCaveSize); + if (!codeCaveMem) + { + patchContext.errorHandler.printError(patchGroup, -1, fmt::format("Not enough code cave memory for {} bytes, the code caves of all graphic packs share {} bytes", patchGroup->codeCaveSize, MEMORY_CODECAVEAREA_SIZE)); + patchContext.errorHandler.showStageErrorMessageBox(); + return; + } cemuLog_log(LogType::Force, "Applying patch group \'{}\' (Codecave: {:08x}-{:08x})", patchGroup->name, codeCaveMem.GetMPTR(), codeCaveMem.GetMPTR() + patchGroup->codeCaveSize); patchGroup->codeCaveMem = codeCaveMem; } diff --git a/src/Cafe/GraphicPack/GraphicPack2PatchesParser.cpp b/src/Cafe/GraphicPack/GraphicPack2PatchesParser.cpp index d93cc151..31682f2e 100644 --- a/src/Cafe/GraphicPack/GraphicPack2PatchesParser.cpp +++ b/src/Cafe/GraphicPack/GraphicPack2PatchesParser.cpp @@ -56,9 +56,9 @@ void GraphicPack2::AddPatchGroup(PatchGroup* group) if (patchData) { uint32 patchAddr = patchData->getAddr(); - if (patchAddr < 0x00100000) + if (patchAddr < PatchGroup::CODECAVE_MAX_OFFSET) { - // everything in low 1MB of memory we consider part of the code cave + // everything that gets relocated relative to the code cave needs to be part of it codeCaveMaxAddr = std::max(codeCaveMaxAddr, patchAddr + patchData->getSize()); } }