mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-21 16:09:19 +01:00
chore: make SigScanner public, have separate service TargetSigScanner that resolves via ISigScanner (closes #1426)
This commit is contained in:
parent
1d0b61e32b
commit
ebabb7bd04
26 changed files with 55 additions and 41 deletions
|
|
@ -167,7 +167,7 @@ internal sealed class Dalamud : IServiceType
|
||||||
internal void ReplaceExceptionHandler()
|
internal void ReplaceExceptionHandler()
|
||||||
{
|
{
|
||||||
var releaseSig = "40 55 53 56 48 8D AC 24 ?? ?? ?? ?? B8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 2B E0 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 85 ?? ?? ?? ?? 48 83 3D ?? ?? ?? ?? ??";
|
var releaseSig = "40 55 53 56 48 8D AC 24 ?? ?? ?? ?? B8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 2B E0 48 8B 05 ?? ?? ?? ?? 48 33 C4 48 89 85 ?? ?? ?? ?? 48 83 3D ?? ?? ?? ?? ??";
|
||||||
var releaseFilter = Service<SigScanner>.Get().ScanText(releaseSig);
|
var releaseFilter = Service<TargetSigScanner>.Get().ScanText(releaseSig);
|
||||||
Log.Debug($"SE debug filter at {releaseFilter.ToInt64():X}");
|
Log.Debug($"SE debug filter at {releaseFilter.ToInt64():X}");
|
||||||
|
|
||||||
var oldFilter = NativeFunctions.SetUnhandledExceptionFilter(releaseFilter);
|
var oldFilter = NativeFunctions.SetUnhandledExceptionFilter(releaseFilter);
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ internal unsafe class AddonEventManager : IDisposable, IServiceType
|
||||||
private AddonCursorType? cursorOverride;
|
private AddonCursorType? cursorOverride;
|
||||||
|
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private AddonEventManager(SigScanner sigScanner)
|
private AddonEventManager(TargetSigScanner sigScanner)
|
||||||
{
|
{
|
||||||
this.address = new AddonEventManagerAddressResolver();
|
this.address = new AddonEventManagerAddressResolver();
|
||||||
this.address.Setup(sigScanner);
|
this.address.Setup(sigScanner);
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType
|
||||||
private readonly List<AddonLifecycleEventListener> eventListeners = new();
|
private readonly List<AddonLifecycleEventListener> eventListeners = new();
|
||||||
|
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private AddonLifecycle(SigScanner sigScanner)
|
private AddonLifecycle(TargetSigScanner sigScanner)
|
||||||
{
|
{
|
||||||
this.address = new AddonLifecycleAddressResolver();
|
this.address = new AddonLifecycleAddressResolver();
|
||||||
this.address.Setup(sigScanner);
|
this.address.Setup(sigScanner);
|
||||||
|
|
|
||||||
|
|
@ -22,15 +22,6 @@ internal abstract class BaseAddressResolver
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected bool IsResolved { get; set; }
|
protected bool IsResolved { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Setup the resolver, calling the appropriate method based on the process architecture,
|
|
||||||
/// using the default SigScanner.
|
|
||||||
///
|
|
||||||
/// For plugins. Not intended to be called from Dalamud Service{T} constructors.
|
|
||||||
/// </summary>
|
|
||||||
[UsedImplicitly]
|
|
||||||
public void Setup() => this.Setup(Service<SigScanner>.Get());
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Setup the resolver, calling the appropriate method based on the process architecture.
|
/// Setup the resolver, calling the appropriate method based on the process architecture.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ internal sealed class ClientState : IDisposable, IServiceType, IClientState
|
||||||
private bool lastFramePvP;
|
private bool lastFramePvP;
|
||||||
|
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private ClientState(SigScanner sigScanner, DalamudStartInfo startInfo, GameLifecycle lifecycle)
|
private ClientState(TargetSigScanner sigScanner, DalamudStartInfo startInfo, GameLifecycle lifecycle)
|
||||||
{
|
{
|
||||||
this.lifecycle = lifecycle;
|
this.lifecycle = lifecycle;
|
||||||
this.address = new ClientStateAddressResolver();
|
this.address = new ClientStateAddressResolver();
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ internal class KeyState : IServiceType, IKeyState
|
||||||
private VirtualKey[]? validVirtualKeyCache;
|
private VirtualKey[]? validVirtualKeyCache;
|
||||||
|
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private KeyState(SigScanner sigScanner, ClientState clientState)
|
private KeyState(TargetSigScanner sigScanner, ClientState clientState)
|
||||||
{
|
{
|
||||||
var moduleBaseAddress = sigScanner.Module.BaseAddress;
|
var moduleBaseAddress = sigScanner.Module.BaseAddress;
|
||||||
var addressResolver = clientState.AddressResolver;
|
var addressResolver = clientState.AddressResolver;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ internal sealed class GameConfig : IServiceType, IGameConfig, IDisposable
|
||||||
private Hook<ConfigChangeDelegate>? configChangeHook;
|
private Hook<ConfigChangeDelegate>? configChangeHook;
|
||||||
|
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private unsafe GameConfig(Framework framework, SigScanner sigScanner)
|
private unsafe GameConfig(Framework framework, TargetSigScanner sigScanner)
|
||||||
{
|
{
|
||||||
framework.RunOnTick(() =>
|
framework.RunOnTick(() =>
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ internal unsafe class DutyState : IDisposable, IServiceType, IDutyState
|
||||||
private readonly ClientState.ClientState clientState = Service<ClientState.ClientState>.Get();
|
private readonly ClientState.ClientState clientState = Service<ClientState.ClientState>.Get();
|
||||||
|
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private DutyState(SigScanner sigScanner)
|
private DutyState(TargetSigScanner sigScanner)
|
||||||
{
|
{
|
||||||
this.address = new DutyStateAddressResolver();
|
this.address = new DutyStateAddressResolver();
|
||||||
this.address.Setup(sigScanner);
|
this.address.Setup(sigScanner);
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ internal sealed class Framework : IDisposable, IServiceType, IFramework
|
||||||
private Thread? frameworkUpdateThread;
|
private Thread? frameworkUpdateThread;
|
||||||
|
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private Framework(SigScanner sigScanner, GameLifecycle lifecycle)
|
private Framework(TargetSigScanner sigScanner, GameLifecycle lifecycle)
|
||||||
{
|
{
|
||||||
this.lifecycle = lifecycle;
|
this.lifecycle = lifecycle;
|
||||||
this.hitchDetector = new HitchDetector("FrameworkUpdate", this.configuration.FrameworkUpdateHitch);
|
this.hitchDetector = new HitchDetector("FrameworkUpdate", this.configuration.FrameworkUpdateHitch);
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ internal sealed class ChatGui : IDisposable, IServiceType, IChatGui
|
||||||
private IntPtr baseAddress = IntPtr.Zero;
|
private IntPtr baseAddress = IntPtr.Zero;
|
||||||
|
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private ChatGui(SigScanner sigScanner)
|
private ChatGui(TargetSigScanner sigScanner)
|
||||||
{
|
{
|
||||||
this.address = new ChatGuiAddressResolver();
|
this.address = new ChatGuiAddressResolver();
|
||||||
this.address.Setup(sigScanner);
|
this.address.Setup(sigScanner);
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ internal sealed class FlyTextGui : IDisposable, IServiceType, IFlyTextGui
|
||||||
private readonly Hook<CreateFlyTextDelegate> createFlyTextHook;
|
private readonly Hook<CreateFlyTextDelegate> createFlyTextHook;
|
||||||
|
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private FlyTextGui(SigScanner sigScanner)
|
private FlyTextGui(TargetSigScanner sigScanner)
|
||||||
{
|
{
|
||||||
this.Address = new FlyTextGuiAddressResolver();
|
this.Address = new FlyTextGuiAddressResolver();
|
||||||
this.Address.Setup(sigScanner);
|
this.Address.Setup(sigScanner);
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ internal sealed unsafe class GameGui : IDisposable, IServiceType, IGameGui
|
||||||
private OpenMapWithFlagDelegate? openMapWithFlag;
|
private OpenMapWithFlagDelegate? openMapWithFlag;
|
||||||
|
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private GameGui(SigScanner sigScanner)
|
private GameGui(TargetSigScanner sigScanner)
|
||||||
{
|
{
|
||||||
this.address = new GameGuiAddressResolver();
|
this.address = new GameGuiAddressResolver();
|
||||||
this.address.Setup(sigScanner);
|
this.address.Setup(sigScanner);
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ internal sealed class PartyFinderGui : IDisposable, IServiceType, IPartyFinderGu
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sigScanner">Sig scanner to use.</param>
|
/// <param name="sigScanner">Sig scanner to use.</param>
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private PartyFinderGui(SigScanner sigScanner)
|
private PartyFinderGui(TargetSigScanner sigScanner)
|
||||||
{
|
{
|
||||||
this.address = new PartyFinderAddressResolver();
|
this.address = new PartyFinderAddressResolver();
|
||||||
this.address.Setup(sigScanner);
|
this.address.Setup(sigScanner);
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ internal sealed partial class ToastGui : IDisposable, IServiceType, IToastGui
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sigScanner">Sig scanner to use.</param>
|
/// <param name="sigScanner">Sig scanner to use.</param>
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private ToastGui(SigScanner sigScanner)
|
private ToastGui(TargetSigScanner sigScanner)
|
||||||
{
|
{
|
||||||
this.address = new ToastGuiAddressResolver();
|
this.address = new ToastGuiAddressResolver();
|
||||||
this.address.Setup(sigScanner);
|
this.address.Setup(sigScanner);
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ internal sealed partial class AntiDebug : IServiceType
|
||||||
private IntPtr debugCheckAddress;
|
private IntPtr debugCheckAddress;
|
||||||
|
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private AntiDebug(SigScanner sigScanner)
|
private AntiDebug(TargetSigScanner sigScanner)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ internal sealed unsafe partial class DalamudAtkTweaks : IServiceType
|
||||||
private readonly string locDalamudSettings;
|
private readonly string locDalamudSettings;
|
||||||
|
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private DalamudAtkTweaks(SigScanner sigScanner)
|
private DalamudAtkTweaks(TargetSigScanner sigScanner)
|
||||||
{
|
{
|
||||||
var openSystemMenuAddress = sigScanner.ScanText("E8 ?? ?? ?? ?? 32 C0 4C 8B AC 24 ?? ?? ?? ?? 48 8B 8D ?? ?? ?? ??");
|
var openSystemMenuAddress = sigScanner.ScanText("E8 ?? ?? ?? ?? 32 C0 4C 8B AC 24 ?? ?? ?? ?? 48 8B 8D ?? ?? ?? ??");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ internal sealed class LibcFunction : IServiceType, ILibcFunction
|
||||||
private readonly StdStringDeallocateDelegate stdStringDeallocate;
|
private readonly StdStringDeallocateDelegate stdStringDeallocate;
|
||||||
|
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private LibcFunction(SigScanner sigScanner)
|
private LibcFunction(TargetSigScanner sigScanner)
|
||||||
{
|
{
|
||||||
this.address = new LibcFunctionAddressResolver();
|
this.address = new LibcFunctionAddressResolver();
|
||||||
this.address.Setup(sigScanner);
|
this.address.Setup(sigScanner);
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ internal sealed class GameNetwork : IDisposable, IServiceType, IGameNetwork
|
||||||
private IntPtr baseAddress;
|
private IntPtr baseAddress;
|
||||||
|
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private GameNetwork(SigScanner sigScanner)
|
private GameNetwork(TargetSigScanner sigScanner)
|
||||||
{
|
{
|
||||||
this.hitchDetectorUp = new HitchDetector("GameNetworkUp", this.configuration.GameNetworkUpHitch);
|
this.hitchDetectorUp = new HitchDetector("GameNetworkUp", this.configuration.GameNetworkUpHitch);
|
||||||
this.hitchDetectorDown = new HitchDetector("GameNetworkDown", this.configuration.GameNetworkDownHitch);
|
this.hitchDetectorDown = new HitchDetector("GameNetworkDown", this.configuration.GameNetworkDownHitch);
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,7 @@ namespace Dalamud.Game;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A SigScanner facilitates searching for memory signatures in a given ProcessModule.
|
/// A SigScanner facilitates searching for memory signatures in a given ProcessModule.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[PluginInterface]
|
public class SigScanner : IDisposable, ISigScanner
|
||||||
[InterfaceVersion("1.0")]
|
|
||||||
#pragma warning disable SA1015
|
|
||||||
[ResolveVia<ISigScanner>]
|
|
||||||
#pragma warning restore SA1015
|
|
||||||
internal class SigScanner : IDisposable, IServiceType, ISigScanner
|
|
||||||
{
|
{
|
||||||
private readonly FileInfo? cacheFile;
|
private readonly FileInfo? cacheFile;
|
||||||
|
|
||||||
|
|
|
||||||
28
Dalamud/Game/TargetSigScanner.cs
Normal file
28
Dalamud/Game/TargetSigScanner.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
using Dalamud.IoC;
|
||||||
|
using Dalamud.IoC.Internal;
|
||||||
|
|
||||||
|
namespace Dalamud.Game;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A SigScanner facilitates searching for memory signatures in a given ProcessModule.
|
||||||
|
/// </summary>
|
||||||
|
[PluginInterface]
|
||||||
|
[InterfaceVersion("1.0")]
|
||||||
|
#pragma warning disable SA1015
|
||||||
|
[ResolveVia<ISigScanner>]
|
||||||
|
#pragma warning restore SA1015
|
||||||
|
internal class TargetSigScanner : SigScanner, IServiceType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="TargetSigScanner"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="doCopy">Whether or not to copy the module upon initialization for search operations to use, as to not get disturbed by possible hooks.</param>
|
||||||
|
/// <param name="cacheFile">File used to cached signatures.</param>
|
||||||
|
public TargetSigScanner(bool doCopy = false, FileInfo? cacheFile = null)
|
||||||
|
: base(Process.GetCurrentProcess().MainModule!, doCopy, cacheFile)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -33,7 +33,7 @@ internal class GameInteropProviderPluginScoped : IGameInteropProvider, IServiceT
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="plugin">Plugin this instance belongs to.</param>
|
/// <param name="plugin">Plugin this instance belongs to.</param>
|
||||||
/// <param name="scanner">SigScanner instance for target module.</param>
|
/// <param name="scanner">SigScanner instance for target module.</param>
|
||||||
public GameInteropProviderPluginScoped(LocalPlugin plugin, SigScanner scanner)
|
public GameInteropProviderPluginScoped(LocalPlugin plugin, TargetSigScanner scanner)
|
||||||
{
|
{
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.scanner = scanner;
|
this.scanner = scanner;
|
||||||
|
|
|
||||||
|
|
@ -1055,7 +1055,7 @@ internal class InterfaceManager : IDisposable, IServiceType
|
||||||
}
|
}
|
||||||
|
|
||||||
[ServiceManager.CallWhenServicesReady]
|
[ServiceManager.CallWhenServicesReady]
|
||||||
private void ContinueConstruction(SigScanner sigScanner, Framework framework)
|
private void ContinueConstruction(TargetSigScanner sigScanner, Framework framework)
|
||||||
{
|
{
|
||||||
this.address.Setup(sigScanner);
|
this.address.Setup(sigScanner);
|
||||||
framework.RunOnFrameworkThread(() =>
|
framework.RunOnFrameworkThread(() =>
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ internal class AddressesWidget : IDataWindowWidget
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var sigScanner = Service<SigScanner>.Get();
|
var sigScanner = Service<TargetSigScanner>.Get();
|
||||||
this.sigResult = sigScanner.ScanText(this.inputSig);
|
this.sigResult = sigScanner.ScanText(this.inputSig);
|
||||||
}
|
}
|
||||||
catch (KeyNotFoundException)
|
catch (KeyNotFoundException)
|
||||||
|
|
|
||||||
|
|
@ -623,7 +623,7 @@ internal partial class PluginManager : IDisposable, IServiceType
|
||||||
Log.Error(e, "Failed to load at least one plugin");
|
Log.Error(e, "Failed to load at least one plugin");
|
||||||
}
|
}
|
||||||
|
|
||||||
var sigScanner = await Service<SigScanner>.GetAsync().ConfigureAwait(false);
|
var sigScanner = await Service<TargetSigScanner>.GetAsync().ConfigureAwait(false);
|
||||||
this.PluginsReady = true;
|
this.PluginsReady = true;
|
||||||
this.NotifyinstalledPluginsListChanged();
|
this.NotifyinstalledPluginsListChanged();
|
||||||
sigScanner.Save();
|
sigScanner.Save();
|
||||||
|
|
|
||||||
|
|
@ -105,15 +105,15 @@ internal static class ServiceManager
|
||||||
Service<ServiceContainer>.Provide(new ServiceContainer());
|
Service<ServiceContainer>.Provide(new ServiceContainer());
|
||||||
LoadedServices.Add(typeof(ServiceContainer));
|
LoadedServices.Add(typeof(ServiceContainer));
|
||||||
|
|
||||||
Service<SigScanner>.Provide(
|
Service<TargetSigScanner>.Provide(
|
||||||
new SigScanner(
|
new TargetSigScanner(
|
||||||
true, new FileInfo(Path.Combine(cacheDir.FullName, $"{startInfo.GameVersion}.json"))));
|
true, new FileInfo(Path.Combine(cacheDir.FullName, $"{startInfo.GameVersion}.json"))));
|
||||||
LoadedServices.Add(typeof(SigScanner));
|
LoadedServices.Add(typeof(TargetSigScanner));
|
||||||
}
|
}
|
||||||
|
|
||||||
using (Timings.Start("CS Resolver Init"))
|
using (Timings.Start("CS Resolver Init"))
|
||||||
{
|
{
|
||||||
FFXIVClientStructs.Interop.Resolver.GetInstance.SetupSearchSpace(Service<SigScanner>.Get().SearchBase, new FileInfo(Path.Combine(cacheDir.FullName, $"{startInfo.GameVersion}_cs.json")));
|
FFXIVClientStructs.Interop.Resolver.GetInstance.SetupSearchSpace(Service<TargetSigScanner>.Get().SearchBase, new FileInfo(Path.Combine(cacheDir.FullName, $"{startInfo.GameVersion}_cs.json")));
|
||||||
FFXIVClientStructs.Interop.Resolver.GetInstance.Resolve();
|
FFXIVClientStructs.Interop.Resolver.GetInstance.Resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ internal static class SignatureHelper
|
||||||
/// <returns>Collection of created IDalamudHooks.</returns>
|
/// <returns>Collection of created IDalamudHooks.</returns>
|
||||||
internal static IEnumerable<IDalamudHook> Initialize(object self, bool log = true)
|
internal static IEnumerable<IDalamudHook> Initialize(object self, bool log = true)
|
||||||
{
|
{
|
||||||
var scanner = Service<SigScanner>.Get();
|
var scanner = Service<TargetSigScanner>.Get();
|
||||||
var selfType = self.GetType();
|
var selfType = self.GetType();
|
||||||
var fields = selfType.GetFields(Flags).Select(field => (IFieldOrPropertyInfo)new FieldInfoWrapper(field))
|
var fields = selfType.GetFields(Flags).Select(field => (IFieldOrPropertyInfo)new FieldInfoWrapper(field))
|
||||||
.Concat(selfType.GetProperties(Flags).Select(prop => new PropertyInfoWrapper(prop)))
|
.Concat(selfType.GetProperties(Flags).Select(prop => new PropertyInfoWrapper(prop)))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue