Simple IPC for external control (#3345)

* add simple IPC protocol

to allow communication via stdin/stdout

* ipc: add PATCH_MEMORY command

enables patches & cheates
This commit is contained in:
Vinicius Rangel
2025-08-04 20:32:50 -03:00
committed by GitHub
parent 77410fd228
commit 0044a27c1f
7 changed files with 179 additions and 11 deletions

View File

@@ -29,6 +29,7 @@ EXPORT uintptr_t g_eboot_address;
uint64_t g_eboot_image_size;
std::string g_game_serial;
std::string patchFile;
bool patches_applied = false;
std::vector<patchInfo> pending_patches;
std::string toHex(u64 value, size_t byteSize) {
@@ -119,6 +120,8 @@ std::string convertValueToHex(const std::string type, const std::string valueStr
return result;
}
void ApplyPendingPatches();
void OnGameLoaded() {
if (!patchFile.empty()) {
@@ -377,20 +380,26 @@ void OnGameLoaded() {
}
void AddPatchToQueue(patchInfo patchToAdd) {
if (patches_applied) {
PatchMemory(patchToAdd.modNameStr, patchToAdd.offsetStr, patchToAdd.valueStr,
patchToAdd.targetStr, patchToAdd.sizeStr, patchToAdd.isOffset,
patchToAdd.littleEndian, patchToAdd.patchMask, patchToAdd.maskOffset);
return;
}
pending_patches.push_back(patchToAdd);
}
void ApplyPendingPatches() {
patches_applied = true;
for (size_t i = 0; i < pending_patches.size(); ++i) {
patchInfo currentPatch = pending_patches[i];
const patchInfo& currentPatch = pending_patches[i];
if (currentPatch.gameSerial != g_game_serial)
if (currentPatch.gameSerial != "*" && currentPatch.gameSerial != g_game_serial)
continue;
PatchMemory(currentPatch.modNameStr, currentPatch.offsetStr, currentPatch.valueStr, "", "",
currentPatch.isOffset, currentPatch.littleEndian, currentPatch.patchMask,
currentPatch.maskOffset);
PatchMemory(currentPatch.modNameStr, currentPatch.offsetStr, currentPatch.valueStr,
currentPatch.targetStr, currentPatch.sizeStr, currentPatch.isOffset,
currentPatch.littleEndian, currentPatch.patchMask, currentPatch.maskOffset);
}
pending_patches.clear();

View File

@@ -30,19 +30,18 @@ struct patchInfo {
std::string modNameStr;
std::string offsetStr;
std::string valueStr;
std::string targetStr;
std::string sizeStr;
bool isOffset;
bool littleEndian;
PatchMask patchMask;
int maskOffset;
};
extern std::vector<patchInfo> pending_patches;
std::string convertValueToHex(const std::string type, const std::string valueStr);
void OnGameLoaded();
void AddPatchToQueue(patchInfo patchToAdd);
void ApplyPendingPatches();
void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr,
std::string targetStr, std::string sizeStr, bool isOffset, bool littleEndian,