refactor: move examine function into XivCommon
This commit is contained in:
parent
bed788ea1c
commit
0e0a0143d2
|
@ -1,75 +0,0 @@
|
||||||
using Dalamud.Game.ClientState.Actors.Types;
|
|
||||||
using Dalamud.Plugin;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace PeepingTom {
|
|
||||||
public class GameFunctions {
|
|
||||||
private delegate IntPtr GetListDelegate(IntPtr basePtr);
|
|
||||||
private delegate long RequestCharInfoDelegate(IntPtr ptr);
|
|
||||||
|
|
||||||
private PeepingTomPlugin Plugin { get; }
|
|
||||||
|
|
||||||
private readonly RequestCharInfoDelegate? _requestCharInfo;
|
|
||||||
|
|
||||||
public GameFunctions(PeepingTomPlugin plugin) {
|
|
||||||
this.Plugin = plugin ?? throw new ArgumentNullException(nameof(plugin), "PeepingTomPlugin cannot be null");
|
|
||||||
|
|
||||||
IntPtr rciPtr;
|
|
||||||
try {
|
|
||||||
// got this by checking what accesses rciData below
|
|
||||||
rciPtr = this.Plugin.Interface.TargetModuleScanner.ScanText("48 89 5C 24 ?? 57 48 83 EC 40 BA ?? ?? ?? ?? 48 8B D9 E8 ?? ?? ?? ?? 48 8B F8 48 85 C0 74 16");
|
|
||||||
} catch (KeyNotFoundException) {
|
|
||||||
rciPtr = IntPtr.Zero;
|
|
||||||
}
|
|
||||||
if (rciPtr == IntPtr.Zero) {
|
|
||||||
PluginLog.Log("Could not find the signature for the examine window function - will not be able to open examine window.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._requestCharInfo = Marshal.GetDelegateForFunctionPointer<RequestCharInfoDelegate>(rciPtr);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IntPtr FollowPtrChain(IntPtr start, IEnumerable<int> offsets) {
|
|
||||||
foreach (var offset in offsets) {
|
|
||||||
start = Marshal.ReadIntPtr(start, offset);
|
|
||||||
if (start == IntPtr.Zero) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OpenExamineWindow(Actor actor) {
|
|
||||||
if (this._requestCharInfo == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTES LAST UPDATED: 5.45
|
|
||||||
|
|
||||||
// offsets and stuff come from the beginning of case 0x2c (around line 621 in IDA)
|
|
||||||
// if 29f8 ever changes, I'd just scan for it in old binary and find what it is in the new binary at the same spot
|
|
||||||
// 40 55 53 57 41 54 41 55 41 56 48 8D 6C 24 ??
|
|
||||||
var uiModule = this.Plugin.Interface.Framework.Gui.GetUIModule();
|
|
||||||
var getListPtr = FollowPtrChain(uiModule, new[] {0, 0x110});
|
|
||||||
var getList = Marshal.GetDelegateForFunctionPointer<GetListDelegate>(getListPtr);
|
|
||||||
var list = getList(uiModule);
|
|
||||||
var rciData = Marshal.ReadIntPtr(list + 0x1A0);
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
// offsets at sig E8 ?? ?? ?? ?? 33 C0 EB 4C
|
|
||||||
// this is called at the end of the 2c case
|
|
||||||
var raw = (int*) rciData;
|
|
||||||
*(raw + 10) = actor.ActorId;
|
|
||||||
*(raw + 11) = actor.ActorId;
|
|
||||||
*(raw + 12) = actor.ActorId;
|
|
||||||
*(raw + 13) = -536870912;
|
|
||||||
*(raw + 311) = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
this._requestCharInfo(rciData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -44,5 +44,6 @@
|
||||||
<PackageReference Include="ILMerge.Fody" Version="1.16.0" PrivateAssets="all"/>
|
<PackageReference Include="ILMerge.Fody" Version="1.16.0" PrivateAssets="all"/>
|
||||||
<PackageReference Include="NAudio" Version="2.0.0"/>
|
<PackageReference Include="NAudio" Version="2.0.0"/>
|
||||||
<PackageReference Include="Resourcer.Fody" Version="1.8.0" PrivateAssets="all"/>
|
<PackageReference Include="Resourcer.Fody" Version="1.8.0" PrivateAssets="all"/>
|
||||||
|
<PackageReference Include="XivCommon" Version="1.2.0"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -3,6 +3,7 @@ using Dalamud.Plugin;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Lumina.Excel.GeneratedSheets;
|
using Lumina.Excel.GeneratedSheets;
|
||||||
|
using XivCommon;
|
||||||
|
|
||||||
namespace PeepingTom {
|
namespace PeepingTom {
|
||||||
public class PeepingTomPlugin : IDalamudPlugin {
|
public class PeepingTomPlugin : IDalamudPlugin {
|
||||||
|
@ -12,16 +13,16 @@ namespace PeepingTom {
|
||||||
internal Configuration Config { get; private set; } = null!;
|
internal Configuration Config { get; private set; } = null!;
|
||||||
internal PluginUi Ui { get; private set; } = null!;
|
internal PluginUi Ui { get; private set; } = null!;
|
||||||
internal TargetWatcher Watcher { get; private set; } = null!;
|
internal TargetWatcher Watcher { get; private set; } = null!;
|
||||||
internal GameFunctions GameFunctions { get; private set; } = null!;
|
internal XivCommonBase Common { get; private set; } = null!;
|
||||||
|
|
||||||
internal bool InPvp { get; private set; }
|
internal bool InPvp { get; private set; }
|
||||||
|
|
||||||
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;
|
||||||
|
this.Common = new XivCommonBase(this.Interface);
|
||||||
this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration();
|
this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration();
|
||||||
this.Config.Initialize(this.Interface);
|
this.Config.Initialize(this.Interface);
|
||||||
this.Watcher = new TargetWatcher(this);
|
this.Watcher = new TargetWatcher(this);
|
||||||
this.GameFunctions = new GameFunctions(this);
|
|
||||||
this.Ui = new PluginUi(this);
|
this.Ui = new PluginUi(this);
|
||||||
|
|
||||||
this.Interface.CommandManager.AddHandler("/ppeepingtom", new CommandInfo(this.OnCommand) {
|
this.Interface.CommandManager.AddHandler("/ppeepingtom", new CommandInfo(this.OnCommand) {
|
||||||
|
@ -44,6 +45,21 @@ namespace PeepingTom {
|
||||||
this.Watcher.StartThread();
|
this.Watcher.StartThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
this.Common.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 -= this.DrawUi;
|
||||||
|
this.Interface.UiBuilder.OnOpenConfigUi -= this.ConfigUi;
|
||||||
|
this.Interface.CommandManager.RemoveHandler("/ppeepingtom");
|
||||||
|
this.Interface.CommandManager.RemoveHandler("/ptom");
|
||||||
|
this.Interface.CommandManager.RemoveHandler("/ppeep");
|
||||||
|
this.Ui.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
private void OnTerritoryChange(object sender, ushort e) {
|
private void OnTerritoryChange(object sender, ushort e) {
|
||||||
try {
|
try {
|
||||||
var territory = this.Interface.Data.GetExcelSheet<TerritoryType>().GetRow(e);
|
var territory = this.Interface.Data.GetExcelSheet<TerritoryType>().GetRow(e);
|
||||||
|
@ -74,20 +90,6 @@ namespace PeepingTom {
|
||||||
this.Watcher.ClearPrevious();
|
this.Watcher.ClearPrevious();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void 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 -= this.DrawUi;
|
|
||||||
this.Interface.UiBuilder.OnOpenConfigUi -= this.ConfigUi;
|
|
||||||
this.Interface.CommandManager.RemoveHandler("/ppeepingtom");
|
|
||||||
this.Interface.CommandManager.RemoveHandler("/ptom");
|
|
||||||
this.Interface.CommandManager.RemoveHandler("/ppeep");
|
|
||||||
this.Ui.Dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DrawUi() {
|
private void DrawUi() {
|
||||||
this.Ui.Draw();
|
this.Ui.Draw();
|
||||||
}
|
}
|
||||||
|
|
|
@ -544,7 +544,7 @@ namespace PeepingTom {
|
||||||
if (left) {
|
if (left) {
|
||||||
if (this.Plugin.Config.OpenExamine && ImGui.GetIO().KeyAlt) {
|
if (this.Plugin.Config.OpenExamine && ImGui.GetIO().KeyAlt) {
|
||||||
if (actor != null) {
|
if (actor != null) {
|
||||||
this.Plugin.GameFunctions.OpenExamineWindow(actor);
|
this.Plugin.Common.Functions.Examine.OpenExamineWindow(actor);
|
||||||
} else {
|
} else {
|
||||||
var error = new SeString(new Payload[] {
|
var error = new SeString(new Payload[] {
|
||||||
new PlayerPayload(this.Plugin.Interface.Data, targeter.Name, targeter.HomeWorld.Id),
|
new PlayerPayload(this.Plugin.Interface.Data, targeter.Name, targeter.HomeWorld.Id),
|
||||||
|
|
Loading…
Reference in New Issue