hook Present and ResizeBuffers immediately when InterfaceManager is created

Also seems to resolve the aforementioned issue without breaking wine support
This commit is contained in:
goat 2023-05-27 19:02:40 +02:00
parent 37fc9d7284
commit e1a56d6d64
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B

View file

@ -76,7 +76,7 @@ internal class InterfaceManager : IDisposable, IServiceType
private bool isOverrideGameCursor = true; private bool isOverrideGameCursor = true;
[ServiceManager.ServiceConstructor] [ServiceManager.ServiceConstructor]
private InterfaceManager() private InterfaceManager(SigScanner sigScanner)
{ {
this.dispatchMessageWHook = Hook<DispatchMessageWDelegate>.FromImport( this.dispatchMessageWHook = Hook<DispatchMessageWDelegate>.FromImport(
null, "user32.dll", "DispatchMessageW", 0, this.DispatchMessageWDetour); null, "user32.dll", "DispatchMessageW", 0, this.DispatchMessageWDetour);
@ -86,6 +86,24 @@ internal class InterfaceManager : IDisposable, IServiceType
this.fontBuildSignal = new ManualResetEvent(false); this.fontBuildSignal = new ManualResetEvent(false);
this.address = new SwapChainVtableResolver(); this.address = new SwapChainVtableResolver();
this.address.Setup();
this.presentHook = Hook<PresentDelegate>.FromAddress(this.address.Present, this.PresentDetour);
this.resizeBuffersHook = Hook<ResizeBuffersDelegate>.FromAddress(this.address.ResizeBuffers, this.ResizeBuffersDetour);
Log.Verbose("===== S W A P C H A I N =====");
Log.Verbose($"Present address 0x{this.presentHook!.Address.ToInt64():X}");
Log.Verbose($"ResizeBuffers address 0x{this.resizeBuffersHook!.Address.ToInt64():X}");
var wndProcAddress = sigScanner.ScanText("E8 ?? ?? ?? ?? 80 7C 24 ?? ?? 74 ?? B8");
Log.Verbose($"WndProc address 0x{wndProcAddress.ToInt64():X}");
this.processMessageHook = Hook<ProcessMessageDelegate>.FromAddress(wndProcAddress, this.ProcessMessageDetour);
this.setCursorHook.Enable();
this.presentHook.Enable();
this.resizeBuffersHook.Enable();
this.dispatchMessageWHook.Enable();
this.processMessageHook.Enable();
} }
[UnmanagedFunctionPointer(CallingConvention.ThisCall)] [UnmanagedFunctionPointer(CallingConvention.ThisCall)]
@ -982,10 +1000,9 @@ internal class InterfaceManager : IDisposable, IServiceType
} }
[ServiceManager.CallWhenServicesReady] [ServiceManager.CallWhenServicesReady]
private void ContinueConstruction(SigScanner sigScanner, Framework framework) private void ContinueConstruction()
{ {
this.address.Setup(sigScanner); this.framework.RunOnFrameworkThread(() =>
framework.RunOnFrameworkThread(() =>
{ {
while ((this.GameWindowHandle = NativeFunctions.FindWindowEx(IntPtr.Zero, this.GameWindowHandle, "FFXIVGAME", IntPtr.Zero)) != IntPtr.Zero) while ((this.GameWindowHandle = NativeFunctions.FindWindowEx(IntPtr.Zero, this.GameWindowHandle, "FFXIVGAME", IntPtr.Zero)) != IntPtr.Zero)
{ {
@ -1004,23 +1021,6 @@ internal class InterfaceManager : IDisposable, IServiceType
{ {
Log.Error(ex, "Could not enable immersive mode"); Log.Error(ex, "Could not enable immersive mode");
} }
this.presentHook = Hook<PresentDelegate>.FromAddress(this.address.Present, this.PresentDetour, true);
this.resizeBuffersHook = Hook<ResizeBuffersDelegate>.FromAddress(this.address.ResizeBuffers, this.ResizeBuffersDetour, true);
Log.Verbose("===== S W A P C H A I N =====");
Log.Verbose($"Present address 0x{this.presentHook!.Address.ToInt64():X}");
Log.Verbose($"ResizeBuffers address 0x{this.resizeBuffersHook!.Address.ToInt64():X}");
var wndProcAddress = sigScanner.ScanText("E8 ?? ?? ?? ?? 80 7C 24 ?? ?? 74 ?? B8");
Log.Verbose($"WndProc address 0x{wndProcAddress.ToInt64():X}");
this.processMessageHook = Hook<ProcessMessageDelegate>.FromAddress(wndProcAddress, this.ProcessMessageDetour);
this.setCursorHook.Enable();
this.presentHook.Enable();
this.resizeBuffersHook.Enable();
this.dispatchMessageWHook.Enable();
this.processMessageHook.Enable();
}); });
} }