diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index c38594771..a9d822f55 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -167,7 +167,7 @@ internal sealed class Dalamud : IServiceType 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 releaseFilter = Service.Get().ScanText(releaseSig); + var releaseFilter = Service.Get().ScanText(releaseSig); Log.Debug($"SE debug filter at {releaseFilter.ToInt64():X}"); var oldFilter = NativeFunctions.SetUnhandledExceptionFilter(releaseFilter); diff --git a/Dalamud/Game/Addon/Events/AddonEventManager.cs b/Dalamud/Game/Addon/Events/AddonEventManager.cs index 8ec77b10d..a91f5437c 100644 --- a/Dalamud/Game/Addon/Events/AddonEventManager.cs +++ b/Dalamud/Game/Addon/Events/AddonEventManager.cs @@ -41,7 +41,7 @@ internal unsafe class AddonEventManager : IDisposable, IServiceType private AddonCursorType? cursorOverride; [ServiceManager.ServiceConstructor] - private AddonEventManager(SigScanner sigScanner) + private AddonEventManager(TargetSigScanner sigScanner) { this.address = new AddonEventManagerAddressResolver(); this.address.Setup(sigScanner); diff --git a/Dalamud/Game/Addon/Lifecycle/AddonLifecycle.cs b/Dalamud/Game/Addon/Lifecycle/AddonLifecycle.cs index f1ee69f2b..d4e45688d 100644 --- a/Dalamud/Game/Addon/Lifecycle/AddonLifecycle.cs +++ b/Dalamud/Game/Addon/Lifecycle/AddonLifecycle.cs @@ -38,7 +38,7 @@ internal unsafe class AddonLifecycle : IDisposable, IServiceType private readonly List eventListeners = new(); [ServiceManager.ServiceConstructor] - private AddonLifecycle(SigScanner sigScanner) + private AddonLifecycle(TargetSigScanner sigScanner) { this.address = new AddonLifecycleAddressResolver(); this.address.Setup(sigScanner); diff --git a/Dalamud/Game/BaseAddressResolver.cs b/Dalamud/Game/BaseAddressResolver.cs index 9935aac7b..cd1ef8fd2 100644 --- a/Dalamud/Game/BaseAddressResolver.cs +++ b/Dalamud/Game/BaseAddressResolver.cs @@ -22,15 +22,6 @@ internal abstract class BaseAddressResolver /// protected bool IsResolved { get; set; } - /// - /// 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. - /// - [UsedImplicitly] - public void Setup() => this.Setup(Service.Get()); - /// /// Setup the resolver, calling the appropriate method based on the process architecture. /// diff --git a/Dalamud/Game/ClientState/ClientState.cs b/Dalamud/Game/ClientState/ClientState.cs index baf6f6634..ccb87ff0e 100644 --- a/Dalamud/Game/ClientState/ClientState.cs +++ b/Dalamud/Game/ClientState/ClientState.cs @@ -41,7 +41,7 @@ internal sealed class ClientState : IDisposable, IServiceType, IClientState private bool lastFramePvP; [ServiceManager.ServiceConstructor] - private ClientState(SigScanner sigScanner, DalamudStartInfo startInfo, GameLifecycle lifecycle) + private ClientState(TargetSigScanner sigScanner, DalamudStartInfo startInfo, GameLifecycle lifecycle) { this.lifecycle = lifecycle; this.address = new ClientStateAddressResolver(); diff --git a/Dalamud/Game/ClientState/Keys/KeyState.cs b/Dalamud/Game/ClientState/Keys/KeyState.cs index 03c5d59b9..76bee51bf 100644 --- a/Dalamud/Game/ClientState/Keys/KeyState.cs +++ b/Dalamud/Game/ClientState/Keys/KeyState.cs @@ -39,7 +39,7 @@ internal class KeyState : IServiceType, IKeyState private VirtualKey[]? validVirtualKeyCache; [ServiceManager.ServiceConstructor] - private KeyState(SigScanner sigScanner, ClientState clientState) + private KeyState(TargetSigScanner sigScanner, ClientState clientState) { var moduleBaseAddress = sigScanner.Module.BaseAddress; var addressResolver = clientState.AddressResolver; diff --git a/Dalamud/Game/Config/GameConfig.cs b/Dalamud/Game/Config/GameConfig.cs index 831c1157b..ea988525c 100644 --- a/Dalamud/Game/Config/GameConfig.cs +++ b/Dalamud/Game/Config/GameConfig.cs @@ -19,7 +19,7 @@ internal sealed class GameConfig : IServiceType, IGameConfig, IDisposable private Hook? configChangeHook; [ServiceManager.ServiceConstructor] - private unsafe GameConfig(Framework framework, SigScanner sigScanner) + private unsafe GameConfig(Framework framework, TargetSigScanner sigScanner) { framework.RunOnTick(() => { diff --git a/Dalamud/Game/DutyState/DutyState.cs b/Dalamud/Game/DutyState/DutyState.cs index 3890a1f8b..6dda95a66 100644 --- a/Dalamud/Game/DutyState/DutyState.cs +++ b/Dalamud/Game/DutyState/DutyState.cs @@ -28,7 +28,7 @@ internal unsafe class DutyState : IDisposable, IServiceType, IDutyState private readonly ClientState.ClientState clientState = Service.Get(); [ServiceManager.ServiceConstructor] - private DutyState(SigScanner sigScanner) + private DutyState(TargetSigScanner sigScanner) { this.address = new DutyStateAddressResolver(); this.address.Setup(sigScanner); diff --git a/Dalamud/Game/Framework.cs b/Dalamud/Game/Framework.cs index 08b97edbc..22343fd8e 100644 --- a/Dalamud/Game/Framework.cs +++ b/Dalamud/Game/Framework.cs @@ -51,7 +51,7 @@ internal sealed class Framework : IDisposable, IServiceType, IFramework private Thread? frameworkUpdateThread; [ServiceManager.ServiceConstructor] - private Framework(SigScanner sigScanner, GameLifecycle lifecycle) + private Framework(TargetSigScanner sigScanner, GameLifecycle lifecycle) { this.lifecycle = lifecycle; this.hitchDetector = new HitchDetector("FrameworkUpdate", this.configuration.FrameworkUpdateHitch); diff --git a/Dalamud/Game/Gui/ChatGui.cs b/Dalamud/Game/Gui/ChatGui.cs index 55c919ab5..5bf6232fa 100644 --- a/Dalamud/Game/Gui/ChatGui.cs +++ b/Dalamud/Game/Gui/ChatGui.cs @@ -42,7 +42,7 @@ internal sealed class ChatGui : IDisposable, IServiceType, IChatGui private IntPtr baseAddress = IntPtr.Zero; [ServiceManager.ServiceConstructor] - private ChatGui(SigScanner sigScanner) + private ChatGui(TargetSigScanner sigScanner) { this.address = new ChatGuiAddressResolver(); this.address.Setup(sigScanner); diff --git a/Dalamud/Game/Gui/FlyText/FlyTextGui.cs b/Dalamud/Game/Gui/FlyText/FlyTextGui.cs index 64de4b2dd..3da8dc2a9 100644 --- a/Dalamud/Game/Gui/FlyText/FlyTextGui.cs +++ b/Dalamud/Game/Gui/FlyText/FlyTextGui.cs @@ -30,7 +30,7 @@ internal sealed class FlyTextGui : IDisposable, IServiceType, IFlyTextGui private readonly Hook createFlyTextHook; [ServiceManager.ServiceConstructor] - private FlyTextGui(SigScanner sigScanner) + private FlyTextGui(TargetSigScanner sigScanner) { this.Address = new FlyTextGuiAddressResolver(); this.Address.Setup(sigScanner); diff --git a/Dalamud/Game/Gui/GameGui.cs b/Dalamud/Game/Gui/GameGui.cs index 349d2a424..9796effc5 100644 --- a/Dalamud/Game/Gui/GameGui.cs +++ b/Dalamud/Game/Gui/GameGui.cs @@ -48,7 +48,7 @@ internal sealed unsafe class GameGui : IDisposable, IServiceType, IGameGui private OpenMapWithFlagDelegate? openMapWithFlag; [ServiceManager.ServiceConstructor] - private GameGui(SigScanner sigScanner) + private GameGui(TargetSigScanner sigScanner) { this.address = new GameGuiAddressResolver(); this.address.Setup(sigScanner); diff --git a/Dalamud/Game/Gui/PartyFinder/PartyFinderGui.cs b/Dalamud/Game/Gui/PartyFinder/PartyFinderGui.cs index 4bd93cdf0..61c0f62e4 100644 --- a/Dalamud/Game/Gui/PartyFinder/PartyFinderGui.cs +++ b/Dalamud/Game/Gui/PartyFinder/PartyFinderGui.cs @@ -27,7 +27,7 @@ internal sealed class PartyFinderGui : IDisposable, IServiceType, IPartyFinderGu /// /// Sig scanner to use. [ServiceManager.ServiceConstructor] - private PartyFinderGui(SigScanner sigScanner) + private PartyFinderGui(TargetSigScanner sigScanner) { this.address = new PartyFinderAddressResolver(); this.address.Setup(sigScanner); diff --git a/Dalamud/Game/Gui/Toast/ToastGui.cs b/Dalamud/Game/Gui/Toast/ToastGui.cs index 9624e3e72..362edb3be 100644 --- a/Dalamud/Game/Gui/Toast/ToastGui.cs +++ b/Dalamud/Game/Gui/Toast/ToastGui.cs @@ -33,7 +33,7 @@ internal sealed partial class ToastGui : IDisposable, IServiceType, IToastGui /// /// Sig scanner to use. [ServiceManager.ServiceConstructor] - private ToastGui(SigScanner sigScanner) + private ToastGui(TargetSigScanner sigScanner) { this.address = new ToastGuiAddressResolver(); this.address.Setup(sigScanner); diff --git a/Dalamud/Game/Internal/AntiDebug.cs b/Dalamud/Game/Internal/AntiDebug.cs index ba482ef48..2f4ec28c0 100644 --- a/Dalamud/Game/Internal/AntiDebug.cs +++ b/Dalamud/Game/Internal/AntiDebug.cs @@ -19,7 +19,7 @@ internal sealed partial class AntiDebug : IServiceType private IntPtr debugCheckAddress; [ServiceManager.ServiceConstructor] - private AntiDebug(SigScanner sigScanner) + private AntiDebug(TargetSigScanner sigScanner) { try { diff --git a/Dalamud/Game/Internal/DalamudAtkTweaks.cs b/Dalamud/Game/Internal/DalamudAtkTweaks.cs index 60e61b2f7..b45b35c4d 100644 --- a/Dalamud/Game/Internal/DalamudAtkTweaks.cs +++ b/Dalamud/Game/Internal/DalamudAtkTweaks.cs @@ -41,7 +41,7 @@ internal sealed unsafe partial class DalamudAtkTweaks : IServiceType private readonly string locDalamudSettings; [ServiceManager.ServiceConstructor] - private DalamudAtkTweaks(SigScanner sigScanner) + private DalamudAtkTweaks(TargetSigScanner sigScanner) { var openSystemMenuAddress = sigScanner.ScanText("E8 ?? ?? ?? ?? 32 C0 4C 8B AC 24 ?? ?? ?? ?? 48 8B 8D ?? ?? ?? ??"); diff --git a/Dalamud/Game/Libc/LibcFunction.cs b/Dalamud/Game/Libc/LibcFunction.cs index b0bd4950c..f1cd07080 100644 --- a/Dalamud/Game/Libc/LibcFunction.cs +++ b/Dalamud/Game/Libc/LibcFunction.cs @@ -24,7 +24,7 @@ internal sealed class LibcFunction : IServiceType, ILibcFunction private readonly StdStringDeallocateDelegate stdStringDeallocate; [ServiceManager.ServiceConstructor] - private LibcFunction(SigScanner sigScanner) + private LibcFunction(TargetSigScanner sigScanner) { this.address = new LibcFunctionAddressResolver(); this.address.Setup(sigScanner); diff --git a/Dalamud/Game/Network/GameNetwork.cs b/Dalamud/Game/Network/GameNetwork.cs index 7c900ece4..9ea3e491e 100644 --- a/Dalamud/Game/Network/GameNetwork.cs +++ b/Dalamud/Game/Network/GameNetwork.cs @@ -30,7 +30,7 @@ internal sealed class GameNetwork : IDisposable, IServiceType, IGameNetwork private IntPtr baseAddress; [ServiceManager.ServiceConstructor] - private GameNetwork(SigScanner sigScanner) + private GameNetwork(TargetSigScanner sigScanner) { this.hitchDetectorUp = new HitchDetector("GameNetworkUp", this.configuration.GameNetworkUpHitch); this.hitchDetectorDown = new HitchDetector("GameNetworkDown", this.configuration.GameNetworkDownHitch); diff --git a/Dalamud/Game/SigScanner.cs b/Dalamud/Game/SigScanner.cs index ace4654be..fe2d9083e 100644 --- a/Dalamud/Game/SigScanner.cs +++ b/Dalamud/Game/SigScanner.cs @@ -20,12 +20,7 @@ namespace Dalamud.Game; /// /// A SigScanner facilitates searching for memory signatures in a given ProcessModule. /// -[PluginInterface] -[InterfaceVersion("1.0")] -#pragma warning disable SA1015 -[ResolveVia] -#pragma warning restore SA1015 -internal class SigScanner : IDisposable, IServiceType, ISigScanner +public class SigScanner : IDisposable, ISigScanner { private readonly FileInfo? cacheFile; diff --git a/Dalamud/Game/TargetSigScanner.cs b/Dalamud/Game/TargetSigScanner.cs new file mode 100644 index 000000000..0360f95cc --- /dev/null +++ b/Dalamud/Game/TargetSigScanner.cs @@ -0,0 +1,28 @@ +using System.Diagnostics; +using System.IO; + +using Dalamud.IoC; +using Dalamud.IoC.Internal; + +namespace Dalamud.Game; + +/// +/// A SigScanner facilitates searching for memory signatures in a given ProcessModule. +/// +[PluginInterface] +[InterfaceVersion("1.0")] +#pragma warning disable SA1015 +[ResolveVia] +#pragma warning restore SA1015 +internal class TargetSigScanner : SigScanner, IServiceType +{ + /// + /// Initializes a new instance of the class. + /// + /// Whether or not to copy the module upon initialization for search operations to use, as to not get disturbed by possible hooks. + /// File used to cached signatures. + public TargetSigScanner(bool doCopy = false, FileInfo? cacheFile = null) + : base(Process.GetCurrentProcess().MainModule!, doCopy, cacheFile) + { + } +} diff --git a/Dalamud/Hooking/Internal/GameInteropProviderPluginScoped.cs b/Dalamud/Hooking/Internal/GameInteropProviderPluginScoped.cs index 96172e5b2..59f2d2684 100644 --- a/Dalamud/Hooking/Internal/GameInteropProviderPluginScoped.cs +++ b/Dalamud/Hooking/Internal/GameInteropProviderPluginScoped.cs @@ -33,7 +33,7 @@ internal class GameInteropProviderPluginScoped : IGameInteropProvider, IServiceT /// /// Plugin this instance belongs to. /// SigScanner instance for target module. - public GameInteropProviderPluginScoped(LocalPlugin plugin, SigScanner scanner) + public GameInteropProviderPluginScoped(LocalPlugin plugin, TargetSigScanner scanner) { this.plugin = plugin; this.scanner = scanner; diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index be6ca3528..d00f33180 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -1055,7 +1055,7 @@ internal class InterfaceManager : IDisposable, IServiceType } [ServiceManager.CallWhenServicesReady] - private void ContinueConstruction(SigScanner sigScanner, Framework framework) + private void ContinueConstruction(TargetSigScanner sigScanner, Framework framework) { this.address.Setup(sigScanner); framework.RunOnFrameworkThread(() => diff --git a/Dalamud/Interface/Internal/Windows/Data/Widgets/AddressesWidget.cs b/Dalamud/Interface/Internal/Windows/Data/Widgets/AddressesWidget.cs index 0955c1183..dfa6f173d 100644 --- a/Dalamud/Interface/Internal/Windows/Data/Widgets/AddressesWidget.cs +++ b/Dalamud/Interface/Internal/Windows/Data/Widgets/AddressesWidget.cs @@ -36,7 +36,7 @@ internal class AddressesWidget : IDataWindowWidget { try { - var sigScanner = Service.Get(); + var sigScanner = Service.Get(); this.sigResult = sigScanner.ScanText(this.inputSig); } catch (KeyNotFoundException) diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index 691d5f729..f91d4cd56 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -623,7 +623,7 @@ internal partial class PluginManager : IDisposable, IServiceType Log.Error(e, "Failed to load at least one plugin"); } - var sigScanner = await Service.GetAsync().ConfigureAwait(false); + var sigScanner = await Service.GetAsync().ConfigureAwait(false); this.PluginsReady = true; this.NotifyinstalledPluginsListChanged(); sigScanner.Save(); diff --git a/Dalamud/ServiceManager.cs b/Dalamud/ServiceManager.cs index d1c1002bd..ecb58d48b 100644 --- a/Dalamud/ServiceManager.cs +++ b/Dalamud/ServiceManager.cs @@ -105,15 +105,15 @@ internal static class ServiceManager Service.Provide(new ServiceContainer()); LoadedServices.Add(typeof(ServiceContainer)); - Service.Provide( - new SigScanner( + Service.Provide( + new TargetSigScanner( true, new FileInfo(Path.Combine(cacheDir.FullName, $"{startInfo.GameVersion}.json")))); - LoadedServices.Add(typeof(SigScanner)); + LoadedServices.Add(typeof(TargetSigScanner)); } using (Timings.Start("CS Resolver Init")) { - FFXIVClientStructs.Interop.Resolver.GetInstance.SetupSearchSpace(Service.Get().SearchBase, new FileInfo(Path.Combine(cacheDir.FullName, $"{startInfo.GameVersion}_cs.json"))); + FFXIVClientStructs.Interop.Resolver.GetInstance.SetupSearchSpace(Service.Get().SearchBase, new FileInfo(Path.Combine(cacheDir.FullName, $"{startInfo.GameVersion}_cs.json"))); FFXIVClientStructs.Interop.Resolver.GetInstance.Resolve(); } } diff --git a/Dalamud/Utility/Signatures/SignatureHelper.cs b/Dalamud/Utility/Signatures/SignatureHelper.cs index e2c9926a8..51f59bba2 100755 --- a/Dalamud/Utility/Signatures/SignatureHelper.cs +++ b/Dalamud/Utility/Signatures/SignatureHelper.cs @@ -29,7 +29,7 @@ internal static class SignatureHelper /// Collection of created IDalamudHooks. internal static IEnumerable Initialize(object self, bool log = true) { - var scanner = Service.Get(); + var scanner = Service.Get(); var selfType = self.GetType(); var fields = selfType.GetFields(Flags).Select(field => (IFieldOrPropertyInfo)new FieldInfoWrapper(field)) .Concat(selfType.GetProperties(Flags).Select(prop => new PropertyInfoWrapper(prop)))