Skip to content

Commit 23ccc57

Browse files
committed
Tweak mod reroute patches to no longer overwrite the folder initialization
1 parent a678d70 commit 23ccc57

2 files changed

Lines changed: 23 additions & 21 deletions

File tree

libzhl/functions/ASM.zhl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,10 @@ asm InlinedGetStatusEffectTarget_Weakness "e8????????84c074??8b8e????????85c974?
144144
// Separate RGON save files / Save Syncing
145145
asm SetSaveSlotLocalFilePath "68????????680004000050e8????????83c414";
146146
asm SetSaveSlotSteamCloudFileName "68????????680004000050e8????????8d95";
147+
147148
asm SetupSaveDirectoryFinalFallback "68????????680004000068????????e8????????83c40c";
149+
asm SetupSaveDirectoryModFolder "83c4446a0068????????ffd7";
150+
asm SetupSaveDirectoryModSaveDataFolder "83c4246a0068????????ffd7803d????????00";
148151

149152
asm CanPickupMelee "e8????????84c075??8b4f";
150153
asm CanPickupBoomerang "e8????????0fb6d085d20f84????????8b8d????????e8????????83f814";

repentogon/Patches/ASMPatches.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "ASMPatches/ASMCamera.h"
5151

5252
#include "ASMPatcher.hpp"
53+
#include "ASMDefinition.h"
5354

5455
/* This patch hooks KAGE_LogMessage by hand. LibZHL can't properly hook functions with varargs, and we need varargs to properly get log messages.
5556
* So, we'll just do it manually, not a big deal.
@@ -131,36 +132,33 @@ void ModSavesReReoute() {
131132
}
132133

133134
void ASMPatchModReRoute() {
134-
SigScan scanner("83c4446a0068????????ffd7");
135-
scanner.Scan();
136-
void* addr = scanner.GetAddress();
135+
void* addr = sASMDefinitionHolder->GetDefinition(&AsmDefinitions::SetupSaveDirectoryModFolder);
137136

138-
printf("[REPENTOGON] Patching Mod Dir::Point to original mods dir %p\n", addr);
137+
printf("[REPENTOGON] Patching SetupSaveDirectory to redirect to original 'mods/' dir %p\n", addr);
139138

140-
ASMPatch::SavedRegisters savedRegisters(ASMPatch::SavedRegisters::GP_REGISTERS, true);
139+
ASMPatch::SavedRegisters savedRegisters(ASMPatch::SavedRegisters::GP_REGISTERS_STACKLESS, true);
141140
ASMPatch patch;
142141
patch.PreserveRegisters(savedRegisters)
143142
.AddInternalCall(ModReReoute)
144-
.RestoreRegisters(savedRegisters);
145-
sASMPatcher.FlatPatch(addr, &patch);
146-
147-
//Mod save data
143+
.RestoreRegisters(savedRegisters)
144+
.AddBytes(ByteBuffer().AddAny((char*)addr, 0x5)) // Restore overwritten bytes
145+
.AddRelativeJump((char*)addr + 0x5);
146+
sASMPatcher.PatchAt(addr, &patch);
147+
}
148148

149-
SigScan scanner2("83c4246a0068????????ffd7803d????????00");
150-
scanner2.Scan();
151-
void* addr2 = scanner2.GetAddress();
149+
void ASMPatchModDataReRoute() {
150+
void* addr = sASMDefinitionHolder->GetDefinition(&AsmDefinitions::SetupSaveDirectoryModSaveDataFolder);
152151

153-
printf("[REPENTOGON] Patching Mod SaveData Dir::Point to original data dir %p\n", addr);
152+
printf("[REPENTOGON] Patching SetupSaveDirectory to redirect to original mod 'data/' dir %p\n", addr);
154153

155-
ASMPatch::SavedRegisters savedRegisters2(ASMPatch::SavedRegisters::GP_REGISTERS, true);
156-
ASMPatch patch2;
157-
patch2.PreserveRegisters(savedRegisters2)
154+
ASMPatch::SavedRegisters savedRegisters2(ASMPatch::SavedRegisters::GP_REGISTERS_STACKLESS, true);
155+
ASMPatch patch;
156+
patch.PreserveRegisters(savedRegisters2)
158157
.AddInternalCall(ModSavesReReoute)
159-
.RestoreRegisters(savedRegisters2);
160-
sASMPatcher.FlatPatch(addr2, &patch2);
161-
printf("%s \n", &g_ModSaveDataPath);
162-
163-
158+
.RestoreRegisters(savedRegisters2)
159+
.AddBytes(ByteBuffer().AddAny((char*)addr, 0x5)) // Restore overwritten bytes
160+
.AddRelativeJump((char*)addr + 0x5);
161+
sASMPatcher.PatchAt(addr, &patch);
164162
}
165163

166164
void PerformASMPatches() {
@@ -304,6 +302,7 @@ void PerformASMPatches() {
304302

305303
//Mod folder redirect
306304
ASMPatchModReRoute();
305+
ASMPatchModDataReRoute();
307306

308307
// Tweaks (bug crashes)
309308
if (!ASMPatches::FixGodheadEntityPartition()) {

0 commit comments

Comments
 (0)