refactor: use new Dalamud login hooks
This commit is contained in:
parent
fcc5dfd1ff
commit
24d486ea39
|
@ -1,57 +0,0 @@
|
||||||
using Dalamud.Hooking;
|
|
||||||
using Dalamud.Plugin;
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace PeepingTom {
|
|
||||||
class HookManager : IDisposable {
|
|
||||||
private readonly PeepingTomPlugin plugin;
|
|
||||||
|
|
||||||
private readonly Hook<LoginDelegate> loginHook;
|
|
||||||
private readonly Hook<LogoutDelegate> 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<LoginDelegate>(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<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);
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -62,7 +62,6 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Configuration.cs" />
|
<Compile Include="Configuration.cs" />
|
||||||
<Compile Include="GlobalSuppressions.cs" />
|
<Compile Include="GlobalSuppressions.cs" />
|
||||||
<Compile Include="HookManager.cs" />
|
|
||||||
<Compile Include="Plugin.cs" />
|
<Compile Include="Plugin.cs" />
|
||||||
<Compile Include="PluginUI.cs" />
|
<Compile Include="PluginUI.cs" />
|
||||||
<Compile Include="Targeting.cs" />
|
<Compile Include="Targeting.cs" />
|
||||||
|
|
|
@ -10,7 +10,6 @@ namespace PeepingTom {
|
||||||
internal Configuration Config { get; private set; }
|
internal Configuration Config { get; private set; }
|
||||||
internal PluginUI Ui { get; private set; }
|
internal PluginUI Ui { get; private set; }
|
||||||
internal TargetWatcher Watcher { get; private set; }
|
internal TargetWatcher Watcher { get; private set; }
|
||||||
private HookManager hookManager;
|
|
||||||
|
|
||||||
public void Initialize(DalamudPluginInterface pluginInterface) {
|
public void Initialize(DalamudPluginInterface pluginInterface) {
|
||||||
this.Interface = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface argument was null");
|
this.Interface = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface argument was null");
|
||||||
|
@ -18,7 +17,6 @@ namespace PeepingTom {
|
||||||
this.Config.Initialize(this.Interface);
|
this.Config.Initialize(this.Interface);
|
||||||
this.Watcher = new TargetWatcher(this);
|
this.Watcher = new TargetWatcher(this);
|
||||||
this.Ui = new PluginUI(this);
|
this.Ui = new PluginUI(this);
|
||||||
this.hookManager = new HookManager(this);
|
|
||||||
|
|
||||||
this.Interface.CommandManager.AddHandler("/ppeepingtom", new CommandInfo(this.OnCommand) {
|
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"
|
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.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.OnBuildUi += this.DrawUI;
|
||||||
this.Interface.UiBuilder.OnOpenConfigUi += this.ConfigUI;
|
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) {
|
protected virtual void Dispose(bool includeManaged) {
|
||||||
this.hookManager.Dispose();
|
|
||||||
this.Interface.Framework.OnUpdateEvent -= this.Watcher.OnFrameworkUpdate;
|
this.Interface.Framework.OnUpdateEvent -= this.Watcher.OnFrameworkUpdate;
|
||||||
|
this.Interface.ClientState.OnLogin -= this.OnLogin;
|
||||||
|
this.Interface.ClientState.OnLogout -= this.OnLogout;
|
||||||
this.Watcher.WaitStopThread();
|
this.Watcher.WaitStopThread();
|
||||||
this.Watcher.Dispose();
|
this.Watcher.Dispose();
|
||||||
this.Interface.UiBuilder.OnBuildUi -= DrawUI;
|
this.Interface.UiBuilder.OnBuildUi -= DrawUI;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user