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

@ -1,5 +1,6 @@
using System;
using System.Runtime.InteropServices;
using ImGuiNET;
namespace Dalamud.Game
{
@ -9,47 +10,36 @@ namespace Dalamud.Game
public sealed class FrameworkAddressResolver : BaseAddressResolver
{
/// <summary>
/// Gets the base address native Framework class.
/// Gets the address for the function that is called once the Framework is destroyed.
/// </summary>
public IntPtr BaseAddress { get; private set; }
public IntPtr DestroyAddress { get; private set; }
/// <summary>
/// Gets the address for the native GuiManager class.
/// Gets the address for the function that is called once the Framework is free'd.
/// </summary>
public IntPtr GuiManager { get; private set; }
public IntPtr FreeAddress { get; private set; }
/// <summary>
/// Gets the address for the native ScriptManager class.
/// Gets the function that is called every tick.
/// </summary>
public IntPtr ScriptManager { get; private set; }
public IntPtr TickAddress { get; private set; }
/// <inheritdoc/>
protected override void Setup64Bit(SigScanner sig)
{
this.SetupFramework(sig);
// Xiv__Framework__GetGuiManager+8 000 mov rax, [rcx+2C00h]
// Xiv__Framework__GetGuiManager+F 000 retn
this.GuiManager = Marshal.ReadIntPtr(this.BaseAddress, 0x2C08);
// Called from Framework::Init
this.ScriptManager = this.BaseAddress + 0x2C68; // note that no deref here
}
private void SetupFramework(SigScanner scanner)
{
// Dissasembly of part of the .dtor
// 00007FF701AD665A | 48 C7 05 ?? ?? ?? ?? 00 00 00 00 | MOV QWORD PTR DS:[g_mainFramework],0
// 00007FF701AD6665 | E8 ?? ?? ?? ?? | CALL ffxiv_dx11.7FF701E27130
// 00007FF701AD666A | 48 8D ?? ?? ?? 00 00 | LEA RCX,QWORD PTR DS:[RBX + 2C38]
// 00007FF701AD6671 | E8 ?? ?? ?? ?? | CALL ffxiv_dx11.7FF701E2A7D0
// 00007FF701AD6676 | 48 8D ?? ?? ?? ?? ?? | LEA RAX,QWORD PTR DS:[7FF702C31F80
var fwDtor = scanner.ScanText("48 C7 05 ?? ?? ?? ?? 00 00 00 00 E8 ?? ?? ?? ?? 48 8D ?? ?? ?? 00 00 E8 ?? ?? ?? ?? 48 8D");
var fwOffset = Marshal.ReadInt32(fwDtor + 3);
var pFramework = scanner.ResolveRelativeAddress(fwDtor + 11, fwOffset);
this.DestroyAddress =
scanner.ScanText("48 89 5C 24 ?? 48 89 74 24 ?? 57 48 83 EC 20 48 8B 3D ?? ?? ?? ?? 48 8B D9 48 85 FF");
// Framework does not change once initialized in startup so don't bother to deref again and again.
this.BaseAddress = Marshal.ReadIntPtr(pFramework);
this.FreeAddress =
scanner.ScanText("48 89 5C 24 ?? 48 89 74 24 ?? 57 48 83 EC 20 48 8B D9 48 8B 0D ?? ?? ?? ??");
this.TickAddress =
scanner.ScanText("40 53 48 83 EC 20 FF 81 ?? ?? ?? ?? 48 8B D9 48 8D 4C 24 ??");
}
}
}