Callbacks

This commit is contained in:
Luminyx 2026-02-07 02:49:19 -05:00
parent fb2e8c1c1d
commit b072a7e9fc
No known key found for this signature in database
GPG Key ID: C590EEF718016830
5 changed files with 47 additions and 2 deletions

View File

@ -123,6 +123,8 @@ public:
const std::vector<uint64_t>& GetTitleIds() const { return m_title_ids; }
bool HasCustomVSyncFrequency() const { return m_vsync_frequency >= 1; }
sint32 GetCustomVSyncFrequency() const { return m_vsync_frequency; }
const std::vector<MPTR>& GetCallbacks() const { return m_callbacks; }
// texture rules
const std::vector<TextureRule>& GetTextureRules() const { return m_texture_rules; }
@ -230,7 +232,7 @@ private:
bool m_activated = false; // set if the graphic pack is currently used by the running game
std::vector<uint64_t> m_title_ids;
bool m_patchedFilesLoaded = false; // set to true once patched files are loaded
bool m_universal = false; // set if this pack applies to every titl eid
bool m_universal = false; // set if this pack applies to every title id
sint32 m_vsync_frequency = -1;
sint32 m_fs_priority = 100;
@ -284,6 +286,8 @@ private:
void LogPatchesSyntaxError(sint32 lineNumber, std::string_view errorMsg);
std::vector<PatchGroup*> list_patchGroups;
std::vector<MPTR> m_callbacks;
static std::recursive_mutex mtx_patches;
static std::vector<const RPLModule*> list_modules;

View File

@ -256,6 +256,7 @@ private:
std::string name;
std::vector<uint32> list_moduleMatches;
std::vector<PatchEntry*> list_patches;
std::vector<std::string> list_callbacks;
uint32 codeCaveSize;
MEMPTR<void> codeCaveMem;
bool m_isApplied{};

View File

@ -710,6 +710,21 @@ void GraphicPack2::ApplyPatchGroups(std::vector<PatchGroup*>& groups, const RPLM
continue;
patchInstruction->applyPatch();
}
for (const auto& name : patchGroup->list_callbacks)
{
auto it = patchContext.map_values.find(name);
if (it != patchContext.map_values.end())
{
m_callbacks.push_back(it->second);
}
else
{
patchContext.errorHandler.printError(patchGroup, -1, fmt::format("Failed to resolve .callback symbol: {}", name));
patchContext.errorHandler.showStageErrorMessageBox();
return;
}
}
}
// mark groups as applied
for (auto patchGroup : groups)

View File

@ -425,7 +425,23 @@ bool GraphicPack2::ParseCemuPatchesTxtInternal(MemStreamReader& patchesStream)
}
continue;
}
else if (parser.matchWordI(".callback"))
{
const char* symbolStr;
sint32 symbolLen;
if (parser.parseSymbolName(symbolStr, symbolLen))
{
currentGroup->list_callbacks.push_back({symbolStr, static_cast<size_t>(symbolLen)});
continue;
}
else
{
LogPatchesSyntaxError(lineNumber, "'.callback' must be followed by a symbol");
CancelParsingPatches();
return false;
}
}
// next we attempt to parse symbol assignment
// symbols can be labels or variables. The type is determined by what comes after the symbol name
// <symbolName> = <expression> defines a variable

View File

@ -11,6 +11,7 @@
#include "Cafe/OS/libs/coreinit/coreinit_MEM.h"
#include "Cafe/OS/libs/coreinit/coreinit_FG.h"
#include "Cafe/CafeSystem.h"
#include "Cafe/GraphicPack/GraphicPack2.h"
extern MPTR _entryPoint;
extern RPLModule* applicationRPX;
@ -211,6 +212,14 @@ void coreinit_start(PPCInterpreter_t* hCPU)
padscore::start();
vpad::start();
for (const auto gp : GraphicPack2::GetActiveGraphicPacks())
{
for (MPTR callback : gp->GetCallbacks())
{
PPCCoreCallback(callback);
}
}
// continue at main executable entrypoint
hCPU->gpr[4] = memory_getVirtualOffsetFromPointer(_coreinitInfo->argv);
hCPU->gpr[3] = _coreinitInfo->argc;