2020-08-07 23:37:01 +00:00
|
|
|
|
using Dalamud.Hooking;
|
|
|
|
|
using Dalamud.Plugin;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace PeepingTom {
|
|
|
|
|
class HookManager : IDisposable {
|
2020-08-08 10:11:52 +00:00
|
|
|
|
private readonly PeepingTomPlugin plugin;
|
2020-08-07 23:37:01 +00:00
|
|
|
|
|
|
|
|
|
private readonly Hook<LoginDelegate> loginHook;
|
|
|
|
|
private readonly Hook<LogoutDelegate> logoutHook;
|
|
|
|
|
|
|
|
|
|
private delegate void LoginDelegate(IntPtr ptr, IntPtr ptr2);
|
|
|
|
|
private delegate void LogoutDelegate(IntPtr ptr);
|
|
|
|
|
|
2020-08-08 10:11:52 +00:00
|
|
|
|
public HookManager(PeepingTomPlugin plugin) {
|
|
|
|
|
this.plugin = plugin ?? throw new ArgumentNullException(nameof(plugin), "PeepingTomPlugin cannot be null");
|
2020-08-07 23:37:01 +00:00
|
|
|
|
|
2020-08-08 10:11:52 +00:00
|
|
|
|
IntPtr loginPtr = this.plugin.Interface.TargetModuleScanner.ScanText("48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 48 89 7C 24 ?? 41 54 41 56 41 57 48 83 EC 20 48 8B F2");
|
2020-08-07 23:37:01 +00:00
|
|
|
|
if (loginPtr != IntPtr.Zero) {
|
|
|
|
|
this.loginHook = new Hook<LoginDelegate>(loginPtr, new LoginDelegate(this.OnLogin), this);
|
|
|
|
|
this.loginHook.Enable();
|
|
|
|
|
} else {
|
|
|
|
|
PluginLog.Log("Could not hook LoginDelegate");
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-08 10:11:52 +00:00
|
|
|
|
IntPtr logoutPtr = this.plugin.Interface.TargetModuleScanner.ScanText("48 89 5C 24 ?? 48 89 6C 24 ?? 48 89 74 24 ?? 57 48 83 EC 20 48 8B D9 E8 ?? ?? ?? ?? 33 ED 66 C7 03 00 00");
|
2020-08-07 23:37:01 +00:00
|
|
|
|
if (logoutPtr != IntPtr.Zero) {
|
|
|
|
|
this.logoutHook = new Hook<LogoutDelegate>(logoutPtr, new LogoutDelegate(this.OnLogout), this);
|
|
|
|
|
this.logoutHook.Enable();
|
|
|
|
|
} else {
|
|
|
|
|
PluginLog.Log("Could not hook LogoutDelegate");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnLogin(IntPtr ptr, IntPtr ptr2) {
|
|
|
|
|
this.loginHook.Original(ptr, ptr2);
|
|
|
|
|
|
2020-08-08 10:11:52 +00:00
|
|
|
|
if (!this.plugin.Config.OpenOnLogin) {
|
2020-08-07 23:37:01 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-08 10:11:52 +00:00
|
|
|
|
this.plugin.Ui.Visible = true;
|
2020-08-07 23:37:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnLogout(IntPtr ptr) {
|
|
|
|
|
this.logoutHook.Original(ptr);
|
|
|
|
|
|
2020-08-08 10:11:52 +00:00
|
|
|
|
this.plugin.Ui.Visible = false;
|
2020-08-08 10:21:57 +00:00
|
|
|
|
this.plugin.Watcher.ClearPrevious();
|
2020-08-07 23:37:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose() {
|
|
|
|
|
this.loginHook?.Dispose();
|
|
|
|
|
this.logoutHook?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|