-
Notifications
You must be signed in to change notification settings - Fork 38
Modded resources/content-repentogon support #766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 27 commits
013dd2a
126f0ca
a73e91a
4ce8e20
9f45914
f994d9e
e7f1eaa
d90dba1
912066d
bb25eec
ea02f3f
af24ba9
4c49394
92d7558
8e8d7c2
ba8abc2
6ba563a
a4134a5
ecdedb8
ffa0bf0
832deaf
3ea3ad1
f40d513
910cb9d
f1263fa
4fea8b5
5ce89a7
eb42923
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| struct RedirectedPath depends (ModEntry) { | ||
| uint32_t _primaryHash : 0x0; | ||
| uint32_t _secondaryHash : 0x4; | ||
| ModEntry* _modEntry : 0x8; | ||
| std_string _filePath : 0xc; | ||
| } : 0x24; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| #include "IsaacRepentance.h" | ||
| #include "HookSystem.h" | ||
|
|
||
| #include "ASMPatcher.hpp" | ||
| #include "../ASMPatches.h" | ||
| #include "ASMDefinition.h" | ||
|
|
||
| bool __stdcall TryToRedirectToLocalizedResources(std::string& resFileString, std::string& targetFile, ModEntry** modEntry, RedirectedPath* redirectPath) { | ||
| auto* manager = g_Manager->GetModManager(); | ||
|
||
| auto* langCode = g_Manager->GetLanguage(); | ||
|
|
||
| if (targetFile[0] == '\0') { | ||
| return false; | ||
| } | ||
|
|
||
| auto buildAndCheckPath = [&](const std::string& postfix, bool useLangCode) -> bool { | ||
| std::string potentialPath = resFileString + postfix; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. resFileString always ends in "/resources" at this stage? |
||
|
|
||
| if (useLangCode && g_Manager->_stringTable.language != 0 && langCode && langCode[0] != '\0') { | ||
| potentialPath = potentialPath + "." + langCode; | ||
ConnorForan marked this conversation as resolved.
Show resolved
Hide resolved
ConnorForan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| potentialPath = potentialPath + "/" + targetFile; | ||
|
|
||
| if (g_ContentManager.GetMountedFilePath(potentialPath.c_str()) != NULL) { | ||
| resFileString = potentialPath; | ||
| redirectPath->_modEntry = *modEntry; | ||
| redirectPath->_filePath = resFileString; | ||
| std::cout << "[REPENTOGON] Patched " << resFileString << std::endl; | ||
|
||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| if (buildAndCheckPath("-repentogon", false)) return true; | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| void ASMPatchRedirectToLocalizedResources() { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this trigger every time the file is accessed, or does the game do this once, cache the path in _redirectedPathsMap, and then it wont trigger redirection again?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I remember correctly, once the game successfully finds resources file, it will cache it to redirected path and it won't look for other mods |
||
| ASMPatch::SavedRegisters savedRegisters(ASMPatch::SavedRegisters::Registers::GP_REGISTERS, true); | ||
| ASMPatch patch; | ||
|
|
||
| void* addr = sASMDefinitionHolder->GetDefinition(&AsmDefinitions::RedirectToLocalizedResources); | ||
| printf("[REPENTOGON] Patching ModManager::TryRedirectPath for resources folder redirect at %p\n", addr); | ||
|
|
||
| patch.PreserveRegisters(savedRegisters) | ||
| .Push(ASMPatch::Registers::EBP, -0xa0) // RedirectedPath* | ||
| .Push(ASMPatch::Registers::ESI) // ModEntry | ||
| .Push(ASMPatch::Registers::EBP, -0xa4) // Target file | ||
| .Push(ASMPatch::Registers::EAX) //Mod resources folder | ||
| .AddInternalCall(TryToRedirectToLocalizedResources) | ||
| .AddBytes("\x84\xC0") // test al, al | ||
| .RestoreRegisters(savedRegisters) | ||
| .AddConditionalRelativeJump(ASMPatcher::CondJumps::JNE, (char*)addr + 0x2D4) // 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, const std::string* targetFile) -> void) { | ||
| super(resFileString, targetFile); | ||
| auto* manager = g_Manager->GetModManager(); | ||
| auto* langCode = g_Manager->GetLanguage(); | ||
|
|
||
| if (targetFile->empty()) { | ||
| return; | ||
| } | ||
|
|
||
| auto buildAndCheckPath = [&](const std::string& postfix, bool useLangCode) -> bool { | ||
| auto copyOfContentDirectory = _contentDirectory.substr(0, _contentDirectory.length() - 1); | ||
|
||
| std::string potentialPath = copyOfContentDirectory + postfix; | ||
|
|
||
| if (useLangCode && g_Manager->_stringTable.language != 0 && langCode && langCode[0] != '\0') { | ||
| potentialPath = potentialPath + "." + langCode; | ||
| } | ||
|
|
||
| potentialPath = potentialPath + "/" + *targetFile; | ||
|
|
||
| if (g_ContentManager.GetMountedFilePath(potentialPath.c_str()) != NULL) { | ||
| *resFileString = potentialPath; | ||
| std::cout << "[REPENTOGON] Patched path: " << *resFileString << std::endl; | ||
| return true; | ||
| } | ||
| return false; | ||
| }; | ||
|
|
||
| if (buildAndCheckPath("-repentogon", false)) return; | ||
|
|
||
| } | ||
|
|
||
| void ASMPatchRedirectToLocalizationFolders() { | ||
| ASMPatchRedirectToLocalizedResources(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #pragma once | ||
|
|
||
| void ASMPatchRedirectToLocalizationFolders(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wacky looking thing. So the game can "only" remember 32768 redirected paths?
Is there something we will need to access this directly for?