feat: add option to open window on login
This commit is contained in:
parent
1f230b79de
commit
1f9ac4972c
|
@ -37,6 +37,7 @@ namespace PeepingTom {
|
|||
public string SoundPath { get; set; } = null;
|
||||
public float SoundCooldown { get; set; } = 10f;
|
||||
|
||||
public bool OpenOnLogin { get; set; } = false;
|
||||
public bool AllowMovement { get; set; } = true;
|
||||
public bool ShowInCombat { get; set; } = false;
|
||||
public bool ShowInInstance { get; set; } = false;
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
using Dalamud.Hooking;
|
||||
using Dalamud.Plugin;
|
||||
using System;
|
||||
|
||||
namespace PeepingTom {
|
||||
class HookManager : IDisposable {
|
||||
private readonly DalamudPluginInterface pi;
|
||||
private readonly PluginUI ui;
|
||||
private readonly Configuration config;
|
||||
|
||||
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(DalamudPluginInterface pi, PluginUI ui, Configuration config) {
|
||||
this.pi = pi ?? throw new ArgumentNullException(nameof(pi), "DalamudPluginInterface cannot be null");
|
||||
this.ui = ui ?? throw new ArgumentNullException(nameof(ui), "PluginUI cannot be null");
|
||||
this.config = config ?? throw new ArgumentNullException(nameof(config), "Configuration cannot be null");
|
||||
|
||||
IntPtr loginPtr = this.pi.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.pi.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.config.OpenOnLogin) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.ui.Visible = true;
|
||||
}
|
||||
|
||||
private void OnLogout(IntPtr ptr) {
|
||||
this.logoutHook.Original(ptr);
|
||||
|
||||
this.ui.Visible = false;
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
this.loginHook?.Dispose();
|
||||
this.logoutHook?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -62,6 +62,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="Configuration.cs" />
|
||||
<Compile Include="GlobalSuppressions.cs" />
|
||||
<Compile Include="HookManager.cs" />
|
||||
<Compile Include="Plugin.cs" />
|
||||
<Compile Include="PluginUI.cs" />
|
||||
<Compile Include="Targeting.cs" />
|
||||
|
|
|
@ -9,25 +9,27 @@ namespace PeepingTom {
|
|||
private DalamudPluginInterface pi;
|
||||
private Configuration config;
|
||||
private PluginUI ui;
|
||||
private HookManager hookManager;
|
||||
|
||||
public void Initialize(DalamudPluginInterface pluginInterface) {
|
||||
this.pi = pluginInterface ?? throw new ArgumentNullException(nameof(pluginInterface), "DalamudPluginInterface argument was null");
|
||||
this.config = this.pi.GetPluginConfig() as Configuration ?? new Configuration();
|
||||
this.config.Initialize(this.pi);
|
||||
this.ui = new PluginUI(this, this.config, this.pi);
|
||||
this.hookManager = new HookManager(this.pi, this.ui, this.config);
|
||||
|
||||
this.pi.CommandManager.AddHandler("/ppeepingtom", new CommandInfo(OnCommand) {
|
||||
this.pi.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"
|
||||
});
|
||||
this.pi.CommandManager.AddHandler("/ptom", new CommandInfo(OnCommand) {
|
||||
this.pi.CommandManager.AddHandler("/ptom", new CommandInfo(this.OnCommand) {
|
||||
HelpMessage = "Alias for /ppeepingtom"
|
||||
});
|
||||
this.pi.CommandManager.AddHandler("/ppeep", new CommandInfo(OnCommand) {
|
||||
this.pi.CommandManager.AddHandler("/ppeep", new CommandInfo(this.OnCommand) {
|
||||
HelpMessage = "Alias for /ppeepingtom"
|
||||
});
|
||||
|
||||
this.pi.UiBuilder.OnBuildUi += DrawUI;
|
||||
this.pi.UiBuilder.OnOpenConfigUi += ConfigUI;
|
||||
this.pi.UiBuilder.OnBuildUi += this.DrawUI;
|
||||
this.pi.UiBuilder.OnOpenConfigUi += this.ConfigUI;
|
||||
}
|
||||
|
||||
private void OnCommand(string command, string args) {
|
||||
|
@ -39,6 +41,7 @@ namespace PeepingTom {
|
|||
}
|
||||
|
||||
protected virtual void Dispose(bool includeManaged) {
|
||||
this.hookManager.Dispose();
|
||||
this.pi.UiBuilder.OnBuildUi -= DrawUI;
|
||||
this.pi.UiBuilder.OnOpenConfigUi -= ConfigUI;
|
||||
this.pi.CommandManager.RemoveHandler("/ppeepingtom");
|
||||
|
|
|
@ -92,7 +92,6 @@ namespace PeepingTom {
|
|||
}
|
||||
|
||||
private void ShowSettings() {
|
||||
|
||||
// 700x250 if setting a size
|
||||
ImGui.SetNextWindowSize(new Vector2(700, 250));
|
||||
if (ImGui.Begin($"{this.plugin.Name} settings", ref this.settingsVisible)) {
|
||||
|
@ -202,6 +201,12 @@ namespace PeepingTom {
|
|||
}
|
||||
|
||||
if (ImGui.BeginTabItem("Window")) {
|
||||
bool openOnLogin = this.config.OpenOnLogin;
|
||||
if (ImGui.Checkbox("Open on login", ref openOnLogin)) {
|
||||
this.config.OpenOnLogin = openOnLogin;
|
||||
this.config.Save();
|
||||
}
|
||||
|
||||
bool allowMovement = this.config.AllowMovement;
|
||||
if (ImGui.Checkbox("Allow moving the main window", ref allowMovement)) {
|
||||
this.config.AllowMovement = allowMovement;
|
||||
|
|
Loading…
Reference in New Issue