From 95fe2b3040e347a7ee24de311c46c8e746d2e839 Mon Sep 17 00:00:00 2001 From: Wall SoGB <11296448+WallSoGB@users.noreply.github.com> Date: Sun, 15 Dec 2024 11:20:01 +0100 Subject: [PATCH] Undo Obsidian's serialized I/O code (#26) --- Main.cpp | 3 +++ UnserializedIO.h | 37 +++++++++++++++++++++++++++++++++++++ ZeGaryHax.vcxproj | 1 + ZeGaryHax.vcxproj.filters | 1 + 4 files changed, 42 insertions(+) create mode 100644 UnserializedIO.h diff --git a/Main.cpp b/Main.cpp index fa1362a..deb2671 100644 --- a/Main.cpp +++ b/Main.cpp @@ -45,6 +45,7 @@ #include "FaceGenExporter.h" #include "ONAMFix.h" #include "SCOLConsistencyFix.h" +#include "UnserializedIO.h" #include "Allocator/MemoryManager.hpp" #include "Allocator/BSMemory.hpp" @@ -99,6 +100,8 @@ bool NVSEPlugin_Load(const NVSEInterface* nvse) PrintReplacer::InitHooks(); + UnserializedIO::InitHooks(); + CreateLogFile(); _DMESSAGE("Geck Extender Base Address: %08X", GetModuleHandle("ZeGaryHax.dll")); diff --git a/UnserializedIO.h b/UnserializedIO.h new file mode 100644 index 0000000..a1b73ae --- /dev/null +++ b/UnserializedIO.h @@ -0,0 +1,37 @@ +#pragma once + +#include "SafeWrite.h" +#include + +namespace UnserializedIO +{ + namespace ToReplace + { + constexpr static UInt32 fseekAddr = 0x85207B; + constexpr static UInt32 freadAddr[] = { 0x851EE3, 0x85210F, 0x85212F }; + constexpr static UInt32 fwriteAddr[] = { 0x851F2D, 0x8521E1 }; + } + + namespace FunctionsAddr + { + constexpr static UInt32 fseek = 0xC63400; + constexpr static UInt32 fread = 0xC62A6D; + constexpr static UInt32 fwrite = 0xC62686; + } + + // Undoes Obsidian's serialization of the I/O functions by replacing them with the original ones + // Technically we patched this in GECK.exe itself - this serves as a documentation + void InitHooks() + { + // Remove the initializator for the serialized I/O functions + XUtil::PatchMemoryNop(0x8532CA, 5); + + WriteRelCall(ToReplace::fseekAddr, FunctionsAddr::fseek); + + for (UInt32 addr : ToReplace::freadAddr) + WriteRelCall(addr, FunctionsAddr::fread); + + for (UInt32 addr : ToReplace::fwriteAddr) + WriteRelCall(addr, FunctionsAddr::fwrite); + } +} \ No newline at end of file diff --git a/ZeGaryHax.vcxproj b/ZeGaryHax.vcxproj index bc84de8..274211d 100644 --- a/ZeGaryHax.vcxproj +++ b/ZeGaryHax.vcxproj @@ -313,6 +313,7 @@ copy "$(TargetDir)$(TargetName).pdb" "$(FalloutNVPath)\Data\NVSE\Plugins\$(Targe + diff --git a/ZeGaryHax.vcxproj.filters b/ZeGaryHax.vcxproj.filters index 9324eb3..bf9af59 100644 --- a/ZeGaryHax.vcxproj.filters +++ b/ZeGaryHax.vcxproj.filters @@ -201,6 +201,7 @@ libs + allocator