Skip to content

Commit

Permalink
Undo Obsidian's serialized I/O code (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
WallSoGB authored Dec 15, 2024
1 parent f13d6f1 commit 95fe2b3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "FaceGenExporter.h"
#include "ONAMFix.h"
#include "SCOLConsistencyFix.h"
#include "UnserializedIO.h"
#include "Allocator/MemoryManager.hpp"
#include "Allocator/BSMemory.hpp"

Expand Down Expand Up @@ -99,6 +100,8 @@ bool NVSEPlugin_Load(const NVSEInterface* nvse)

PrintReplacer::InitHooks();

UnserializedIO::InitHooks();

CreateLogFile();

_DMESSAGE("Geck Extender Base Address: %08X", GetModuleHandle("ZeGaryHax.dll"));
Expand Down
37 changes: 37 additions & 0 deletions UnserializedIO.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include "SafeWrite.h"
#include <xutil.h>

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);
}
}
1 change: 1 addition & 0 deletions ZeGaryHax.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ copy "$(TargetDir)$(TargetName).pdb" "$(FalloutNVPath)\Data\NVSE\Plugins\$(Targe
</SubType>
</ClInclude>
<ClInclude Include="UISpeedHooks.h" />
<ClInclude Include="UnserializedIO.h" />
<ClInclude Include="xutil.h" />
<ClInclude Include="DialogResizing.h" />
<ClInclude Include="Main.h" />
Expand Down
1 change: 1 addition & 0 deletions ZeGaryHax.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@
<Filter>libs</Filter>
</ClInclude>
<ClInclude Include="PrintReplacer.hpp" />
<ClInclude Include="UnserializedIO.h" />
<ClInclude Include="Allocator\BSMemory.hpp">
<Filter>allocator</Filter>
</ClInclude>
Expand Down

0 comments on commit 95fe2b3

Please sign in to comment.