diff --git a/Peeping Tom/HookManager.cs b/Peeping Tom/HookManager.cs deleted file mode 100644 index c19f2be..0000000 --- a/Peeping Tom/HookManager.cs +++ /dev/null @@ -1,57 +0,0 @@ -using Dalamud.Hooking; -using Dalamud.Plugin; -using System; - -namespace PeepingTom { - class HookManager : IDisposable { - private readonly PeepingTomPlugin plugin; - - private readonly Hook loginHook; - private readonly Hook logoutHook; - - private delegate void LoginDelegate(IntPtr ptr, IntPtr ptr2); - private delegate void LogoutDelegate(IntPtr ptr); - - public HookManager(PeepingTomPlugin plugin) { - this.plugin = plugin ?? throw new ArgumentNullException(nameof(plugin), "PeepingTomPlugin cannot be null"); - - 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"); - if (loginPtr != IntPtr.Zero) { - this.loginHook = new Hook(loginPtr, new LoginDelegate(this.OnLogin), this); - this.loginHook.Enable(); - } else { - PluginLog.Log("Could not hook LoginDelegate"); - } - - 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"); - if (logoutPtr != IntPtr.Zero) { - this.logoutHook = new Hook(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); - - if (!this.plugin.Config.OpenOnLogin) { - return; - } - - this.plugin.Ui.WantsOpen = true; - } - - private void OnLogout(IntPtr ptr) { - this.logoutHook.Original(ptr); - - this.plugin.Ui.WantsOpen = false; - this.plugin.Watcher.ClearPrevious(); - } - - public void Dispose() { - this.loginHook?.Dispose(); - this.logoutHook?.Dispose(); - } - } -} diff --git a/Peeping Tom/Peeping Tom.csproj b/Peeping Tom/Peeping Tom.csproj index 08c28dd..7a6db6c 100644 --- a/Peeping Tom/Peeping Tom.csproj +++ b/Peeping Tom/Peeping Tom.csproj @@ -62,7 +62,6 @@ - diff --git a/Peeping Tom/Plugin.cs b/Peeping Tom/Plugin.cs index 4df7462..0cd7d21 100644 --- a/Peeping Tom/Plugin.cs +++ b/Peeping Tom/Plugin.cs @@ -10,7 +10,6 @@ namespace PeepingTom { internal Configuration Config { get; private set; } internal PluginUI Ui { get; private set; } internal TargetWatcher Watcher { get; private set; } - private HookManager hookManager; public void Initialize(DalamudPluginInterface pluginInterface) { this.Interface = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface argument was null"); @@ -18,7 +17,6 @@ namespace PeepingTom { this.Config.Initialize(this.Interface); this.Watcher = new TargetWatcher(this); this.Ui = new PluginUI(this); - this.hookManager = new HookManager(this); this.Interface.CommandManager.AddHandler("/ppeepingtom", new CommandInfo(this.OnCommand) { HelpMessage = "Use with no arguments to show the list. Use with \"c\" or \"config\" to show the config" @@ -31,6 +29,8 @@ namespace PeepingTom { }); this.Interface.Framework.OnUpdateEvent += this.Watcher.OnFrameworkUpdate; + this.Interface.ClientState.OnLogin += this.OnLogin; + this.Interface.ClientState.OnLogout += this.OnLogout; this.Interface.UiBuilder.OnBuildUi += this.DrawUI; this.Interface.UiBuilder.OnOpenConfigUi += this.ConfigUI; @@ -45,9 +45,23 @@ namespace PeepingTom { } } + private void OnLogin(object sender, EventArgs args) { + if (!this.Config.OpenOnLogin) { + return; + } + + this.Ui.WantsOpen = true; + } + + private void OnLogout(object sender, EventArgs args) { + this.Ui.WantsOpen = false; + this.Watcher.ClearPrevious(); + } + protected virtual void Dispose(bool includeManaged) { - this.hookManager.Dispose(); this.Interface.Framework.OnUpdateEvent -= this.Watcher.OnFrameworkUpdate; + this.Interface.ClientState.OnLogin -= this.OnLogin; + this.Interface.ClientState.OnLogout -= this.OnLogout; this.Watcher.WaitStopThread(); this.Watcher.Dispose(); this.Interface.UiBuilder.OnBuildUi -= DrawUI;