Skip to content

Commit

Permalink
Localized content folder support
Browse files Browse the repository at this point in the history
  • Loading branch information
epfly6 committed Oct 30, 2024
1 parent 013dd2a commit 126f0ca
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libzhl/functions/ModEntry.zhl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


"538bdc83ec0883e4f883c404558b6b??896c24??8bec6aff68????????64a1????????505383ec58a1????????33c58945??5657508d45??64a3????????8b51":
__thiscall void ModEntry::GetContentPath(char**param_1,std_string* param_2); //doesnt work but it's a thing that exists and its at this sig, probably wrong params?
__thiscall void ModEntry::GetContentPath(std_string& param_1,std_string& param_2); //doesnt work but it's a thing that exists and its at this sig, probably wrong params?

"558bec6aff68????????64a1????????50b874000100":
__thiscall void ModEntry::WriteMetadata();
Expand Down
83 changes: 80 additions & 3 deletions repentogon/Patches/ASMPatches/ASMLocalization.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include "IsaacRepentance.h"
#include "HookSystem.h"

#include "ASMPatcher.hpp"
#include "../ASMPatches.h"

//to-do:
/*
* Add content support
* Add DLC3 support for resources/content folders
*/
bool __stdcall TryToRedirectToLocalizedResources(std::string& resFileString, std::string& targetFile, ModEntry** modEntry, RedirectedPath* redirectPath) {
Expand All @@ -15,7 +17,7 @@ bool __stdcall TryToRedirectToLocalizedResources(std::string& resFileString, std
return false;
}

std::cout << targetFile << std::endl;
//std::cout << targetFile << std::endl;
copyOfFileString = resFileString + "." + langCode + "/" + targetFile;

//printf("[RGON] kinda string filename: %s %s \n", copyOfFileString.c_str(), g_FileManager_kinda->GetExpandedPath(copyOfFileString.c_str()));
Expand Down Expand Up @@ -44,7 +46,7 @@ void ASMPatchRedirectToLocalizedResources() {
signature.Scan();

void* addr = signature.GetAddress();
printf("[REPENTOGON] Patching ModManager::TryRedirectPath for testing at %p\n", addr);
printf("[REPENTOGON] Patching ModManager::TryRedirectPath for resources folder redirect at %p\n", addr);

patch.PreserveRegisters(savedRegisters)
.Push(ASMPatch::Registers::EBP, -0xa0) // RedirectedPath*
Expand All @@ -60,6 +62,81 @@ void ASMPatchRedirectToLocalizedResources() {
sASMPatcher.PatchAt(addr, &patch);
}

bool __stdcall TryToRedirectToLocalizedContent(std::string& resFileString, std::string& targetFile) {
auto copyOfFileString = resFileString;
auto* manager = g_Manager->GetModManager();
auto* langCode = g_Manager->GetLanguage();

if (g_Manager->_stringTable.language == 0 || targetFile[0] == '\0') {
return false;
}

//std::cout << targetFile << std::endl;
copyOfFileString = resFileString + "." + langCode + "/" + targetFile;

//printf("[RGON] kinda string filename: %s %s \n", copyOfFileString.c_str(), g_FileManager_kinda->GetExpandedPath(copyOfFileString.c_str()));

if (g_FileManager_kinda->GetExpandedPath(copyOfFileString.c_str()) != NULL) {

resFileString = copyOfFileString;

std::cout << "[REPENTOGON] Patched path: " << resFileString << std::endl;

return true;
}


return false;
}

//need to push to esp+4 carefully somehow, maybe will tweak later. For now using method hooking to redirect path.
void ASMPatchRedirectToLocalizedContents() {
ASMPatch::SavedRegisters savedRegisters(ASMPatch::SavedRegisters::Registers::GP_REGISTERS, true);
ASMPatch patch;

SigScan signature("6a0668????????8d4d??c745??00000000");
signature.Scan();

void* addr = signature.GetAddress();
printf("[REPENTOGON] Patching ModEntry::GetContentPath for content folder redirect at %p\n", addr);

patch.PreserveRegisters(savedRegisters)
.Push(ASMPatch::Registers::ESI) // Target file
.Push(ASMPatch::Registers::EAX) //Mod content folder
.AddInternalCall(TryToRedirectToLocalizedContent)
.AddBytes("\x84\xC0") // test al, al
.RestoreRegisters(savedRegisters)
.AddBytes("\x74\x08")
.CopyRegister(ASMPatch::Registers::EDI, ASMPatch::Registers::EAX)
.AddConditionalRelativeJump(ASMPatcher::CondJumps::JNZ, (char*)addr + 0x16D) // jump for true
.AddBytes(ByteBuffer().AddAny((char*)addr, 0x7)) // Restore the commands we overwrote
.AddRelativeJump((char*)addr + 0x7);
sASMPatcher.PatchAt(addr, &patch);
}

HOOK_METHOD(ModEntry, GetContentPath, (std::string& resFileString, std::string& targetFile) -> void) {
super(resFileString, targetFile);
auto* manager = g_Manager->GetModManager();
auto* langCode = g_Manager->GetLanguage();

if (g_Manager->_stringTable.language == 0 || targetFile[0] == '\0') {
return;
}

auto copyOfContentDirectory = _contentDirectory.substr(0, _contentDirectory.length() - 1);

copyOfContentDirectory = copyOfContentDirectory + "." + langCode + "/" + targetFile;

if (g_FileManager_kinda->GetExpandedPath(copyOfContentDirectory.c_str()) != NULL) {

resFileString = copyOfContentDirectory;

std::cout << "[REPENTOGON] Patched path: " << resFileString << std::endl;
}

}

void ASMPatchRedirectToLocalizationFolders() {
ASMPatchRedirectToLocalizedResources();
//ASMPatchRedirectToLocalizedContents();
}

0 comments on commit 126f0ca

Please sign in to comment.