feat: switch framework hooks from vtable to sigs

This commit is contained in:
goaaats 2022-06-20 22:08:50 +02:00
parent 92518e22b0
commit 3397b608d0
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
8 changed files with 21 additions and 94 deletions

View file

@ -49,14 +49,9 @@ namespace Dalamud.Game
this.Address = new FrameworkAddressResolver();
this.Address.Setup();
Log.Verbose($"Framework address 0x{this.Address.BaseAddress.ToInt64():X}");
if (this.Address.BaseAddress == IntPtr.Zero)
{
throw new InvalidOperationException("Framework is not initalized yet.");
}
// Hook virtual functions
this.HookVTable();
this.updateHook = new Hook<OnUpdateDetour>(this.Address.TickAddress, this.HandleFrameworkUpdate);
this.destroyHook = new Hook<OnDestroyDetour>(this.Address.FreeAddress, this.HandleFrameworkDestroy);
this.realDestroyHook = new Hook<OnRealDestroyDelegate>(this.Address.DestroyAddress, this.HandleRealDestroy);
}
/// <summary>
@ -241,26 +236,6 @@ namespace Dalamud.Game
statsStopwatch.Reset();
}
private void HookVTable()
{
var vtable = Marshal.ReadIntPtr(this.Address.BaseAddress);
// Virtual function layout:
// .rdata:00000001411F1FE0 dq offset Xiv__Framework___dtor
// .rdata:00000001411F1FE8 dq offset Xiv__Framework__init
// .rdata:00000001411F1FF0 dq offset Xiv__Framework__destroy
// .rdata:00000001411F1FF8 dq offset Xiv__Framework__free
// .rdata:00000001411F2000 dq offset Xiv__Framework__update
var pUpdate = Marshal.ReadIntPtr(vtable, IntPtr.Size * 4);
this.updateHook = new Hook<OnUpdateDetour>(pUpdate, this.HandleFrameworkUpdate);
var pDestroy = Marshal.ReadIntPtr(vtable, IntPtr.Size * 3);
this.destroyHook = new Hook<OnDestroyDetour>(pDestroy, this.HandleFrameworkDestroy);
var pRealDestroy = Marshal.ReadIntPtr(vtable, IntPtr.Size * 2);
this.realDestroyHook = new Hook<OnRealDestroyDelegate>(pRealDestroy, this.HandleRealDestroy);
}
private bool HandleFrameworkUpdate(IntPtr framework)
{
// If any of the tier loads failed, just go to the original code.