Unify IconReplacer and IconReplaceChecker, cleanup

This commit is contained in:
goat 2019-10-18 22:01:35 +09:00
parent a3fe81d310
commit 1bd4eed72c
5 changed files with 29 additions and 78 deletions

View file

@ -42,8 +42,6 @@ namespace Dalamud {
public readonly IconReplacer IconReplacer; public readonly IconReplacer IconReplacer;
public readonly IconReplaceChecker IconReplaceChecker;
public Dalamud(DalamudStartInfo info) { public Dalamud(DalamudStartInfo info) {
this.StartInfo = info; this.StartInfo = info;
@ -71,9 +69,7 @@ namespace Dalamud {
this.PluginManager = new PluginManager(this, info.PluginDirectory, info.DefaultPluginDirectory); this.PluginManager = new PluginManager(this, info.PluginDirectory, info.DefaultPluginDirectory);
this.IconReplaceChecker = new IconReplaceChecker(this.targetModule, this.sigScanner); this.IconReplacer = new IconReplacer(this, this.sigScanner);
this.IconReplacer = new IconReplacer(this, this.targetModule, this.sigScanner);
try { try {
this.PluginManager.LoadPlugins(); this.PluginManager.LoadPlugins();
@ -89,8 +85,6 @@ namespace Dalamud {
this.BotManager.Start(); this.BotManager.Start();
this.IconReplaceChecker.Enable();
this.IconReplacer.Enable(); this.IconReplacer.Enable();
} }
@ -109,8 +103,6 @@ namespace Dalamud {
this.unloadSignal.Dispose(); this.unloadSignal.Dispose();
this.IconReplaceChecker.Dispose();
this.IconReplacer.Dispose(); this.IconReplacer.Dispose();
} }

View file

@ -1,38 +0,0 @@
using System;
using System.Diagnostics;
using Dalamud.Hooking;
namespace Dalamud.Game.Internal.Gui {
public class IconReplaceChecker {
private IconReplaceCheckerAddressResolver address;
private Hook<OnCheckDetour> checkerHook;
public IconReplaceChecker(ProcessModule module, SigScanner scanner) {
this.address = new IconReplaceCheckerAddressResolver();
this.address.Setup(scanner);
hookChecker();
}
private void hookChecker() {
this.checkerHook = new Hook<OnCheckDetour>(this.address.BaseAddress, (Delegate)new OnCheckDetour(this.HandleChecker), (object)this);
}
public void Enable() {
this.checkerHook.Enable();
}
public void Dispose() {
this.checkerHook.Dispose();
}
// I hate this function. This is the dumbest function to exist in the game. Just return 1.
// Determines which abilities are allowed to have their icons updated.
private ulong HandleChecker(int actionID) {
return 1;
}
private delegate ulong OnCheckDetour(int actionID);
public delegate ulong OnCheckDelegate(int actionID);
}
}

View file

@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Dalamud.Game.Internal.Gui {
class IconReplaceCheckerAddressResolver : BaseAddressResolver {
public IntPtr BaseAddress { get; private set; }
protected bool IsResolved { get; set; }
protected override void Setup64Bit(SigScanner sig)
{
this.BaseAddress = sig.ScanText("81 f9 d4 08 00 00 7f 33 0f 84 fa 01 00 00 83 c1 eb 81 f9 a3 00 00 00");
}
}
}

View file

@ -9,8 +9,14 @@ using System.Runtime.InteropServices;
namespace Dalamud.Game.Internal.Gui { namespace Dalamud.Game.Internal.Gui {
public class IconReplacer { public class IconReplacer {
private IconReplacerAddressResolver address; public delegate ulong OnGetIconDelegate(byte param1, uint param2);
private Hook<OnIconDetour> iconHook; public delegate ulong OnCheckIsIconReplaceableDelegate(int actionID);
private Hook<OnGetIconDelegate> iconHook;
private Hook<OnCheckIsIconReplaceableDelegate> checkerHook;
private IconReplacerAddressResolver Address;
private IntPtr comboTimer; private IntPtr comboTimer;
private IntPtr lastComboMove; private IntPtr lastComboMove;
private IntPtr activeBuffArray = IntPtr.Zero; private IntPtr activeBuffArray = IntPtr.Zero;
@ -19,28 +25,39 @@ namespace Dalamud.Game.Internal.Gui {
private Dalamud dalamud; private Dalamud dalamud;
private PlayerCharacter localCharacter = null; private PlayerCharacter localCharacter = null;
public unsafe IconReplacer(Dalamud dalamud, ProcessModule module, SigScanner scanner) { public unsafe IconReplacer(Dalamud dalamud, SigScanner scanner) {
this.dalamud = dalamud; this.dalamud = dalamud;
this.address = new IconReplacerAddressResolver(); this.Address = new IconReplacerAddressResolver();
this.address.Setup(scanner); this.Address.Setup(scanner);
this.byteBase = scanner.Module.BaseAddress; this.byteBase = scanner.Module.BaseAddress;
this.jobInfo = byteBase + 0x1b2d4b4; this.jobInfo = byteBase + 0x1b2d4b4;
this.comboTimer = byteBase + 0x1AE1B10; this.comboTimer = byteBase + 0x1AE1B10;
this.lastComboMove = byteBase + 0x1AE1B14; this.lastComboMove = byteBase + 0x1AE1B14;
this.iconHook = new Hook<OnIconDetour>(this.address.BaseAddress, (Delegate)new OnIconDetour(this.HandleIconUpdate), (object)this); Log.Verbose("===== H O T B A R S =====");
Log.Verbose("IsIconReplaceable address {IsIconReplaceable}", Address.IsIconReplaceable);
Log.Verbose("GetIcon address {GetIcon}", Address.GetIcon);
this.iconHook = new Hook<OnGetIconDelegate>(this.Address.GetIcon, new OnGetIconDelegate(GetIconDetour), this);
this.checkerHook = new Hook<OnCheckIsIconReplaceableDelegate>(this.Address.IsIconReplaceable, new OnCheckIsIconReplaceableDelegate(CheckIsIconReplaceableDetour), this);
} }
public void Enable() { public void Enable() {
this.iconHook.Enable(); this.iconHook.Enable();
this.checkerHook.Enable();
} }
public void Dispose() { public void Dispose() {
this.iconHook.Dispose(); this.iconHook.Dispose();
this.checkerHook.Dispose();
} }
// I hate this function. This is the dumbest function to exist in the game. Just return 1.
// Determines which abilities are allowed to have their icons updated.
private ulong CheckIsIconReplaceableDetour(int actionID) {
return 1;
}
/// <summary> /// <summary>
/// Replace an ability with another ability /// Replace an ability with another ability
@ -51,7 +68,7 @@ namespace Dalamud.Game.Internal.Gui {
/// For example, Souleater combo on DRK happens by dragging Souleater /// For example, Souleater combo on DRK happens by dragging Souleater
/// onto your bar and mashing it. /// onto your bar and mashing it.
/// </summary> /// </summary>
private unsafe ulong HandleIconUpdate(byte self, uint actionID) { private unsafe ulong GetIconDetour(byte self, uint actionID) {
// TODO: BRD, RDM, level checking for everything. // TODO: BRD, RDM, level checking for everything.
@ -498,10 +515,6 @@ namespace Dalamud.Game.Internal.Gui {
return false; return false;
} }
private delegate ulong OnIconDetour(byte param1, uint param2);
public delegate ulong OnIconDelegate(byte param1, uint param2);
private unsafe delegate int* getArray(long* address); private unsafe delegate int* getArray(long* address);
private unsafe IntPtr FindBuffAddress() { private unsafe IntPtr FindBuffAddress() {

View file

@ -6,11 +6,12 @@ using System.Threading.Tasks;
namespace Dalamud.Game.Internal.Gui { namespace Dalamud.Game.Internal.Gui {
class IconReplacerAddressResolver : BaseAddressResolver { class IconReplacerAddressResolver : BaseAddressResolver {
public IntPtr BaseAddress { get; private set; } public IntPtr GetIcon { get; private set; }
protected bool IsResolved { get; set; } public IntPtr IsIconReplaceable { get; private set; }
protected override void Setup64Bit(SigScanner sig) { protected override void Setup64Bit(SigScanner sig) {
this.BaseAddress = sig.ScanText("81 fa d4 08 00 00 7f 4b 74 44 8d 42 eb 3d a3 00 00 00"); this.GetIcon = sig.ScanText("81 fa d4 08 00 00 7f 4b 74 44 8d 42 eb 3d a3 00 00 00");
this.IsIconReplaceable = sig.ScanText("81 f9 d4 08 00 00 7f 33 0f 84 fa 01 00 00 83 c1 eb 81 f9 a3 00 00 00");
} }
} }
} }