Skip to content

Commit f72b89b

Browse files
jsgnextortexSylmir
authored andcommitted
"/Repentogon" Adaptations (requires last ver of the launcher)
1 parent e9b910b commit f72b89b

File tree

6 files changed

+78
-7
lines changed

6 files changed

+78
-7
lines changed

libzhl/functions/Global.zhl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2536,6 +2536,10 @@ reference char* g_KAGEInputController; // This is very likely not correct, but I
25362536
"558bec6aff68????????64a1????????5081ece8010000a1????????33c58945??5657508d45??64a3????????8bc2":
25372537
__cdecl void IsaacStartup(int param_1, int param_2);
25382538

2539+
"558bec6aff68????????64a1????????50b838190000":
2540+
__stdcall void SetupSaveDirectories();
2541+
2542+
25392543
"a1(????????)895d??8945":
25402544
reference char* ModReferences; // ModReference data from RegisterMod
25412545

@@ -2544,4 +2548,10 @@ struct GlobalPost {
25442548
}} };
25452549

25462550
"68(????????)68????????8d89????????e8????????50":
2547-
reference const char g_GameVersionString;
2551+
reference const char g_GameVersionString;
2552+
2553+
"68(????????)68????????56e8????????56":
2554+
reference char g_ModsDirectory;
2555+
2556+
"68(????????)ffd7803d????????0074??68????????ffd683f8ff74??24113c1074??6800040000e8????????68????????68????????8bf0680004000056e8????????83c4146a0068????????56ff15????????50ff15????????56e8????????8b35????????83c40468":
2557+
reference char g_ModSaveDataPath;

repentogon/Patches/ASMPatches.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,64 @@ void ASMPatchConsoleRunCommand() {
8181
sASMPatcher.FlatPatch(addr, &patch);
8282
}
8383

84+
85+
86+
void goUpTogon(char* str) {
87+
const char* variants[] = {
88+
"/Repentogon/",
89+
"\\Repentogon/",
90+
"\\Repentogon\\"
91+
};
92+
93+
for (const char* variant : variants) {
94+
size_t len = std::strlen(variant);
95+
char* pos;
96+
while ((pos = std::strstr(str, variant)) != nullptr) {
97+
std::memmove(pos+1, pos + len, std::strlen(pos + len) + 1);
98+
}
99+
}
100+
}
101+
102+
void ModReReoute() {
103+
goUpTogon(&g_ModsDirectory);
104+
}
105+
void ModSavesReReoute() {
106+
goUpTogon(&g_ModSaveDataPath);
107+
}
108+
109+
void ASMPatchModReRoute() {
110+
SigScan scanner("83c4446a0068????????ffd7");
111+
scanner.Scan();
112+
void* addr = scanner.GetAddress();
113+
114+
printf("[REPENTOGON] Patching Mod Dir::Point to original mods dir %p\n", addr);
115+
116+
ASMPatch::SavedRegisters savedRegisters(ASMPatch::SavedRegisters::GP_REGISTERS, true);
117+
ASMPatch patch;
118+
patch.PreserveRegisters(savedRegisters)
119+
.AddInternalCall(ModReReoute)
120+
.RestoreRegisters(savedRegisters);
121+
sASMPatcher.FlatPatch(addr, &patch);
122+
123+
//Mod save data
124+
125+
SigScan scanner2("83c4246a0068????????ffd7803d????????00");
126+
scanner2.Scan();
127+
void* addr2 = scanner2.GetAddress();
128+
129+
printf("[REPENTOGON] Patching Mod SaveData Dir::Point to original data dir %p\n", addr);
130+
131+
ASMPatch::SavedRegisters savedRegisters2(ASMPatch::SavedRegisters::GP_REGISTERS, true);
132+
ASMPatch patch2;
133+
patch2.PreserveRegisters(savedRegisters2)
134+
.AddInternalCall(ModSavesReReoute)
135+
.RestoreRegisters(savedRegisters2);
136+
sASMPatcher.FlatPatch(addr2, &patch2);
137+
printf("%s \n", &g_ModSaveDataPath);
138+
139+
140+
}
141+
84142
void PerformASMPatches() {
85143
ASMPatchLogMessage();
86144
ASMPatchConsoleRunCommand();
@@ -187,6 +245,9 @@ void PerformASMPatches() {
187245
// Sprite
188246
ASMPatchesForANM2Extras();
189247

248+
//Mod folder redirect
249+
ASMPatchModReRoute();
250+
190251
// Tweaks (bug crashes)
191252
if (!ASMPatches::FixGodheadEntityPartition()) {
192253
ZHL::Log("[ERROR] Unable to find signature for Godhead EntityPartition patch\n");

repentogon/Patches/ConsoleHooks.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void LuaReset() {
5555
}
5656
// This is an ordered map and we stored by mod name, so the load order should be identical to the vanilla game.
5757
for (auto& mod : modsToReload) {
58-
std::string modPath = std::filesystem::current_path().string() + "/mods/" + mod.second + "/main.lua";
58+
std::string modPath = string(&g_ModsDirectory) + mod.second + "/main.lua";
5959
if (std::filesystem::exists(modPath))
6060
g_LuaEngine->RunScript(modPath.c_str());
6161
}

repentogon/Patches/ModsMenuStuff.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void RestoreEnabledStates() {
7474
for each (ModEntry * mod in modman->_mods) {
7575
if (mod->IsEnabled() != enabledtstates[i]) {
7676
mod->SetEnabled(enabledtstates[i]);
77-
string disablepath = std::filesystem::current_path().string() + "\\mods\\" + mod->GetDir().c_str() + "\\disable.it";
77+
string disablepath = string(&g_ModsDirectory) + mod->GetDir() + "\\disable.it";
7878
if (mod->IsEnabled()) {
7979
std::remove(disablepath.c_str());
8080
}
@@ -104,7 +104,7 @@ HOOK_METHOD(Menu_Mods, Update, () -> void) {
104104
if (g_InputManagerBase.IsActionTriggered(14,-1,0)) {
105105
if ((lastvalid > -1) && (!issearching) && (this->SelectedElement <= lastvalid) && (this->SelectedElement >= 0) && (!(IsKeytriggered(opensearchkey)))) {
106106
this->_pointerToSelectedMod->SetEnabled(!this->_pointerToSelectedMod->IsEnabled());
107-
string disablepath = std::filesystem::current_path().string() + "\\mods\\" + this->_pointerToSelectedMod->GetDir().c_str() + "\\disable.it";
107+
string disablepath = string(&g_ModsDirectory) + this->_pointerToSelectedMod->GetDir().c_str() + "\\disable.it";
108108
if (this->_pointerToSelectedMod->IsEnabled()) {
109109
std::remove(disablepath.c_str());
110110
}

repentogon/Patches/XMLData.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,7 +3242,7 @@ char * BuildModdedXML(char * xml,const string &filename,bool needsresourcepatch)
32423242
if (needsresourcepatch) {
32433243
for (ModEntry* mod : g_Manager->GetModManager()->_mods) {
32443244
if (mod->IsEnabled()) {
3245-
string dir = std::filesystem::current_path().string() + "\\mods\\" + mod->GetDir();
3245+
string dir = string(&g_ModsDirectory) + mod->GetDir();
32463246
string resourcesdir = dir + "\\resources\\" + filename;
32473247
char* xmlaux = GetResources(xml, dir, filename);
32483248
if (strlen(xmlaux) > 1) {
@@ -3292,7 +3292,7 @@ char * BuildModdedXML(char * xml,const string &filename,bool needsresourcepatch)
32923292
lastmodid = string(mod->GetDir());
32933293
}
32943294

3295-
string dir = std::filesystem::current_path().string() + "\\mods\\" + mod->GetDir();
3295+
string dir = string(&g_ModsDirectory) + mod->GetDir();
32963296
string contentsdir = dir + "\\content\\" + filename;
32973297
// Skip this mod if it does not even have the corresponding XML, to save time and memory during startup.
32983298
// However, DON'T skip if we are in the middle of hijacking a cutscenes XML reload as part of the custom cutscenes support,

repentogon/REPENTOGONFileMap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ namespace REPENTOGONFileMap {
125125
return;
126126
};
127127
map_init = true;
128-
auto basepath = fs::current_path() / L"mods";
128+
auto basepath = std::filesystem::path(&g_ModsDirectory);
129129
_modsPath = basepath.wstring();
130130
auto start_time = std::chrono::high_resolution_clock::now();
131131
if (g_Manager && g_Manager->GetModManager()) {

0 commit comments

Comments
 (0)