From 96ed22534c35b95fba32e5f3b5e874c6eacf3379 Mon Sep 17 00:00:00 2001 From: goat <16760685+goaaats@users.noreply.github.com> Date: Mon, 25 Apr 2022 20:04:17 +0200 Subject: [PATCH] chore: fix some warnings, cleanup --- Dalamud.CorePlugin/PluginWindow.cs | 2 - Dalamud.Injector/EntryPoint.cs | 7 +- Dalamud.Injector/ExistingProcess.cs | 34 + Dalamud.Injector/NativeAclFix.cs | 715 +++++++++--------- .../Internal/DalamudConfiguration.cs | 2 +- Dalamud/EntryPoint.cs | 3 - Dalamud/Game/ChatHandlers.cs | 1 - .../ClientState/JobGauge/Types/DRGGauge.cs | 2 - Dalamud/Game/ClientState/Party/PartyMember.cs | 1 - Dalamud/Game/FrameworkAddressResolver.cs | 2 - Dalamud/Game/Gui/ChatGuiAddressResolver.cs | 2 - .../Gui/ContextMenus/GameObjectContext.cs | 4 +- Dalamud/Game/Gui/GameGuiAddressResolver.cs | 1 - .../PartyFinder/Types/JobFlagsExtensions.cs | 2 - .../Game/Libc/LibcFunctionAddressResolver.cs | 2 - .../Network/GameNetworkAddressResolver.cs | 2 - .../Game/Network/Internal/WinSockHandlers.cs | 1 - .../Payloads/EmphasisItalicPayload.cs | 1 - .../SeStringHandling/Payloads/ItemPayload.cs | 1 - .../Text/SeStringHandling/SeStringManager.cs | 4 - Dalamud/Hooking/Hook.cs | 1 - Dalamud/Hooking/Internal/HookManager.cs | 2 - Dalamud/Interface/GameFonts/FdtReader.cs | 3 - Dalamud/Interface/GameFonts/GameFontFamily.cs | 6 - .../Interface/GameFonts/GameFontLayoutPlan.cs | 3 - .../Interface/GameFonts/GameFontManager.cs | 1 - Dalamud/Interface/GameFonts/GameFontStyle.cs | 4 - .../ImGuiFileDialog/FileDialog.Files.cs | 2 - .../ImGuiFileDialog/FileDialog.Structs.cs | 1 - .../ImGuiFileDialog/ImGuiFileDialogFlags.cs | 4 - .../Interface/Internal/InterfaceManager.cs | 2 - Dalamud/Interface/Internal/UiDebug.cs | 10 +- .../Internal/Windows/ChangelogWindow.cs | 1 - .../Internal/Windows/CreditsWindow.cs | 1 - .../Interface/Internal/Windows/DataWindow.cs | 4 +- .../PluginInstaller/DalamudChangelogEntry.cs | 2 - .../PluginInstaller/IChangelogEntry.cs | 2 - .../PluginInstaller/PluginChangelogEntry.cs | 1 - .../PluginInstaller/PluginInstallerWindow.cs | 1 - .../Internal/Windows/PluginStatWindow.cs | 2 - .../Windows/SelfTest/SelfTestWindow.cs | 1 - .../Internal/Windows/SettingsWindow.cs | 1 - .../Internal/Windows/TitleScreenMenuWindow.cs | 1 - Dalamud/Logging/Internal/TaskTracker.cs | 1 - Dalamud/Plugin/DalamudPluginInterface.cs | 1 - .../Exceptions/InvalidPluginException.cs | 1 - .../InvalidPluginOperationException.cs | 2 - Dalamud/Plugin/Internal/PluginManager.cs | 2 + Dalamud/Utility/Util.cs | 1 - 49 files changed, 413 insertions(+), 440 deletions(-) create mode 100644 Dalamud.Injector/ExistingProcess.cs diff --git a/Dalamud.CorePlugin/PluginWindow.cs b/Dalamud.CorePlugin/PluginWindow.cs index 6a45941f2..27be82f41 100644 --- a/Dalamud.CorePlugin/PluginWindow.cs +++ b/Dalamud.CorePlugin/PluginWindow.cs @@ -1,8 +1,6 @@ using System; using System.Numerics; -using Dalamud.Interface; -using Dalamud.Interface.Colors; using Dalamud.Interface.Windowing; using ImGuiNET; diff --git a/Dalamud.Injector/EntryPoint.cs b/Dalamud.Injector/EntryPoint.cs index 933edec26..8896dc293 100644 --- a/Dalamud.Injector/EntryPoint.cs +++ b/Dalamud.Injector/EntryPoint.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Text; -using System.Threading; using Dalamud.Game; using Newtonsoft.Json; @@ -573,7 +572,7 @@ namespace Dalamud.Injector return null; } - return new NativeAclFix.ExistingProcess(inheritableCurrentProcessHandle); + return new ExistingProcess(inheritableCurrentProcessHandle); } private static int ProcessLaunchTestCommand(List args) @@ -605,7 +604,7 @@ namespace Dalamud.Injector var result = JsonSerializer.CreateDefault().Deserialize>(new JsonTextReader(helperProcess.StandardOutput)); var pid = result["pid"]; var handle = (IntPtr)result["handle"]; - var resultProcess = new NativeAclFix.ExistingProcess(handle); + var resultProcess = new ExistingProcess(handle); Console.WriteLine("PID: {0}, Handle: {1}", pid, handle); Console.WriteLine("Press Enter to force quit"); Console.ReadLine(); @@ -682,7 +681,7 @@ namespace Dalamud.Injector /// /// Supplies the argument to encode. /// - /// Supplies an indication of whether we should quote the argument even if it + /// Supplies an indication of whether we should quote the argument even if it /// does not contain any characters that would ordinarily require quoting. /// private static string EncodeParameterArgument(string argument, bool force = false) diff --git a/Dalamud.Injector/ExistingProcess.cs b/Dalamud.Injector/ExistingProcess.cs new file mode 100644 index 000000000..24ee3bc64 --- /dev/null +++ b/Dalamud.Injector/ExistingProcess.cs @@ -0,0 +1,34 @@ +using System; +using System.Diagnostics; +using System.Reflection; + +using Microsoft.Win32.SafeHandles; + +namespace Dalamud.Injector; + +/// +/// Class representing an already held process handle. +/// +internal class ExistingProcess : Process +{ + /// + /// Initializes a new instance of the class. + /// + /// The existing held process handle. + public ExistingProcess(IntPtr handle) + { + this.SetHandle(handle); + } + + private void SetHandle(IntPtr handle) + { + var baseType = this.GetType().BaseType; + if (baseType == null) + return; + + var setProcessHandleMethod = baseType.GetMethod( + "SetProcessHandle", + BindingFlags.NonPublic | BindingFlags.Instance); + setProcessHandleMethod?.Invoke(this, new object[] { new SafeProcessHandle(handle, true) }); + } +} diff --git a/Dalamud.Injector/NativeAclFix.cs b/Dalamud.Injector/NativeAclFix.cs index ec93b6d63..d3798cfde 100644 --- a/Dalamud.Injector/NativeAclFix.cs +++ b/Dalamud.Injector/NativeAclFix.cs @@ -1,21 +1,262 @@ using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Runtime.InteropServices; -using System.Linq; using System.Diagnostics; -using System.Reflection; -using Microsoft.Win32.SafeHandles; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.InteropServices; using System.Threading; + using Serilog; // ReSharper disable InconsistentNaming namespace Dalamud.Injector { + /// + /// Class responsible for stripping ACL protections from processes. + /// public static class NativeAclFix { + /// + /// Start a process without ACL protections. + /// + /// The working directory. + /// The path to the executable file. + /// Arguments to pass to the executable file. + /// Action to execute before the process is started. + /// The started process. + /// Thrown when a win32 error occurs. + /// Thrown when the process did not start correctly. + public static Process LaunchGame(string workingDir, string exePath, string arguments, Action beforeResume) + { + Process process = null; + + var userName = Environment.UserName; + + var pExplicitAccess = default(PInvoke.EXPLICIT_ACCESS); + PInvoke.BuildExplicitAccessWithName( + ref pExplicitAccess, + userName, + PInvoke.STANDARD_RIGHTS_ALL | PInvoke.SPECIFIC_RIGHTS_ALL & ~PInvoke.PROCESS_VM_WRITE, + PInvoke.GRANT_ACCESS, + 0); + + if (PInvoke.SetEntriesInAcl(1, ref pExplicitAccess, IntPtr.Zero, out var newAcl) != 0) + { + throw new Win32Exception(Marshal.GetLastWin32Error()); + } + + if (!PInvoke.InitializeSecurityDescriptor(out var secDesc, PInvoke.SECURITY_DESCRIPTOR_REVISION)) + { + throw new Win32Exception(Marshal.GetLastWin32Error()); + } + + if (!PInvoke.SetSecurityDescriptorDacl(ref secDesc, true, newAcl, false)) + { + throw new Win32Exception(Marshal.GetLastWin32Error()); + } + + var psecDesc = Marshal.AllocHGlobal(Marshal.SizeOf()); + Marshal.StructureToPtr(secDesc, psecDesc, true); + + var lpProcessInformation = default(PInvoke.PROCESS_INFORMATION); + try + { + var lpProcessAttributes = new PInvoke.SECURITY_ATTRIBUTES + { + nLength = Marshal.SizeOf(), + lpSecurityDescriptor = psecDesc, + bInheritHandle = false, + }; + + var lpStartupInfo = new PInvoke.STARTUPINFO + { + cb = Marshal.SizeOf(), + }; + + var compatLayerPrev = Environment.GetEnvironmentVariable("__COMPAT_LAYER"); + + Environment.SetEnvironmentVariable("__COMPAT_LAYER", "RunAsInvoker"); + try + { + if (!PInvoke.CreateProcess( + null, + $"\"{exePath}\" {arguments}", + ref lpProcessAttributes, + IntPtr.Zero, + false, + PInvoke.CREATE_SUSPENDED, + IntPtr.Zero, + workingDir, + ref lpStartupInfo, + out lpProcessInformation)) + { + throw new Win32Exception(Marshal.GetLastWin32Error()); + } + } + finally + { + Environment.SetEnvironmentVariable("__COMPAT_LAYER", compatLayerPrev); + } + + DisableSeDebug(lpProcessInformation.hProcess); + + process = new ExistingProcess(lpProcessInformation.hProcess); + + beforeResume?.Invoke(process); + + PInvoke.ResumeThread(lpProcessInformation.hThread); + + // Ensure that the game main window is prepared + try + { + do + { + process.WaitForInputIdle(); + + Thread.Sleep(100); + } + while (TryFindGameWindow(process) == IntPtr.Zero); + } + catch (InvalidOperationException) + { + throw new GameExitedException(); + } + + if (PInvoke.GetSecurityInfo( + PInvoke.GetCurrentProcess(), + PInvoke.SE_OBJECT_TYPE.SE_KERNEL_OBJECT, + PInvoke.SECURITY_INFORMATION.DACL_SECURITY_INFORMATION, + IntPtr.Zero, + IntPtr.Zero, + out var pACL, + IntPtr.Zero, + IntPtr.Zero) != 0) + { + throw new Win32Exception(Marshal.GetLastWin32Error()); + } + + if (PInvoke.SetSecurityInfo( + lpProcessInformation.hProcess, + PInvoke.SE_OBJECT_TYPE.SE_KERNEL_OBJECT, + PInvoke.SECURITY_INFORMATION.DACL_SECURITY_INFORMATION | PInvoke.SECURITY_INFORMATION.UNPROTECTED_DACL_SECURITY_INFORMATION, + IntPtr.Zero, + IntPtr.Zero, + pACL, + IntPtr.Zero) != 0) + { + throw new Win32Exception(Marshal.GetLastWin32Error()); + } + } + catch (Exception ex) + { + Log.Error(ex, "[NativeAclFix] Uncaught error during initialization, trying to kill process"); + + try + { + process?.Kill(); + } + catch (Exception killEx) + { + Log.Error(killEx, "[NativeAclFix] Could not kill process"); + } + + throw; + } + finally + { + Marshal.FreeHGlobal(psecDesc); + PInvoke.CloseHandle(lpProcessInformation.hThread); + } + + return process; + } + + private static void DisableSeDebug(IntPtr processHandle) + { + if (!PInvoke.OpenProcessToken(processHandle, PInvoke.TOKEN_QUERY | PInvoke.TOKEN_ADJUST_PRIVILEGES, out var tokenHandle)) + { + throw new Win32Exception(Marshal.GetLastWin32Error()); + } + + var luidDebugPrivilege = default(PInvoke.LUID); + if (!PInvoke.LookupPrivilegeValue(null, "SeDebugPrivilege", ref luidDebugPrivilege)) + { + throw new Win32Exception(Marshal.GetLastWin32Error()); + } + + var requiredPrivileges = new PInvoke.PRIVILEGE_SET + { + PrivilegeCount = 1, + Control = PInvoke.PRIVILEGE_SET_ALL_NECESSARY, + Privilege = new PInvoke.LUID_AND_ATTRIBUTES[1], + }; + + requiredPrivileges.Privilege[0].Luid = luidDebugPrivilege; + requiredPrivileges.Privilege[0].Attributes = PInvoke.SE_PRIVILEGE_ENABLED; + + if (!PInvoke.PrivilegeCheck(tokenHandle, ref requiredPrivileges, out bool bResult)) + { + throw new Win32Exception(Marshal.GetLastWin32Error()); + } + + // SeDebugPrivilege is enabled; try disabling it + if (bResult) + { + var tokenPrivileges = new PInvoke.TOKEN_PRIVILEGES + { + PrivilegeCount = 1, + Privileges = new PInvoke.LUID_AND_ATTRIBUTES[1], + }; + + tokenPrivileges.Privileges[0].Luid = luidDebugPrivilege; + tokenPrivileges.Privileges[0].Attributes = PInvoke.SE_PRIVILEGE_REMOVED; + + if (!PInvoke.AdjustTokenPrivileges(tokenHandle, false, ref tokenPrivileges, 0, IntPtr.Zero, 0)) + { + throw new Win32Exception(Marshal.GetLastWin32Error()); + } + } + + PInvoke.CloseHandle(tokenHandle); + } + + private static IntPtr TryFindGameWindow(Process process) + { + IntPtr hwnd = IntPtr.Zero; + while ((hwnd = PInvoke.FindWindowEx(IntPtr.Zero, hwnd, "FFXIVGAME", IntPtr.Zero)) != IntPtr.Zero) + { + PInvoke.GetWindowThreadProcessId(hwnd, out uint pid); + + if (pid == process.Id && PInvoke.IsWindowVisible(hwnd)) + { + break; + } + } + + return hwnd; + } + + /// + /// Exception thrown when the process has exited before a window could be found. + /// + public class GameExitedException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public GameExitedException() + : base("Game exited prematurely.") + { + } + } + // Definitions taken from PInvoke.net (with some changes) + [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "WINAPI conventions")] + [SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1121:Use built-in type alias", Justification = "WINAPI conventions")] + [SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1400:Access modifier should be declared", Justification = "WINAPI conventions")] + [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1306:Field names should begin with lower-case letter", Justification = "WINAPI conventions")] + [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "WINAPI conventions")] + [SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1124:Do not use regions", Justification = "WINAPI conventions")] private static class PInvoke { #region Constants @@ -37,11 +278,10 @@ namespace Dalamud.Injector public const UInt32 SE_PRIVILEGE_ENABLED = 0x00000002; public const UInt32 SE_PRIVILEGE_REMOVED = 0x00000004; - public enum MULTIPLE_TRUSTEE_OPERATION { NO_MULTIPLE_TRUSTEE, - TRUSTEE_IS_IMPERSONATE + TRUSTEE_IS_IMPERSONATE, } public enum TRUSTEE_FORM @@ -50,7 +290,7 @@ namespace Dalamud.Injector TRUSTEE_IS_NAME, TRUSTEE_BAD_FORM, TRUSTEE_IS_OBJECTS_AND_SID, - TRUSTEE_IS_OBJECTS_AND_NAME + TRUSTEE_IS_OBJECTS_AND_NAME, } public enum TRUSTEE_TYPE @@ -63,7 +303,7 @@ namespace Dalamud.Injector TRUSTEE_IS_WELL_KNOWN_GROUP, TRUSTEE_IS_DELETED, TRUSTEE_IS_INVALID, - TRUSTEE_IS_COMPUTER + TRUSTEE_IS_COMPUTER, } public enum SE_OBJECT_TYPE @@ -80,8 +320,10 @@ namespace Dalamud.Injector SE_DS_OBJECT_ALL, SE_PROVIDER_DEFINED_OBJECT, SE_WMIGUID_OBJECT, - SE_REGISTRY_WOW64_32KEY + SE_REGISTRY_WOW64_32KEY, } + + [Flags] public enum SECURITY_INFORMATION { OWNER_SECURITY_INFORMATION = 1, @@ -90,12 +332,120 @@ namespace Dalamud.Injector SACL_SECURITY_INFORMATION = 8, UNPROTECTED_SACL_SECURITY_INFORMATION = 0x10000000, UNPROTECTED_DACL_SECURITY_INFORMATION = 0x20000000, - PROTECTED_SACL_SECURITY_INFORMATION = 0x40000000 + PROTECTED_SACL_SECURITY_INFORMATION = 0x40000000, } #endregion + #region Methods + + [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Auto)] + public static extern void BuildExplicitAccessWithName( + ref EXPLICIT_ACCESS pExplicitAccess, + string pTrusteeName, + uint accessPermissions, + uint accessMode, + uint inheritance); + + [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Auto)] + public static extern int SetEntriesInAcl( + int cCountOfExplicitEntries, + ref EXPLICIT_ACCESS pListOfExplicitEntries, + IntPtr oldAcl, + out IntPtr newAcl); + + [DllImport("advapi32.dll", SetLastError = true)] + public static extern bool InitializeSecurityDescriptor( + out SECURITY_DESCRIPTOR pSecurityDescriptor, + uint dwRevision); + + [DllImport("advapi32.dll", SetLastError = true)] + public static extern bool SetSecurityDescriptorDacl( + ref SECURITY_DESCRIPTOR pSecurityDescriptor, + bool bDaclPresent, + IntPtr pDacl, + bool bDaclDefaulted); + + [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] + public static extern bool CreateProcess( + string lpApplicationName, + string lpCommandLine, + ref SECURITY_ATTRIBUTES lpProcessAttributes, + IntPtr lpThreadAttributes, + bool bInheritHandles, + UInt32 dwCreationFlags, + IntPtr lpEnvironment, + string lpCurrentDirectory, + [In] ref STARTUPINFO lpStartupInfo, + out PROCESS_INFORMATION lpProcessInformation); + + [DllImport("kernel32.dll", SetLastError = true)] + public static extern bool CloseHandle(IntPtr hObject); + + [DllImport("kernel32.dll", SetLastError = true)] + public static extern uint ResumeThread(IntPtr hThread); + + [DllImport("advapi32.dll", SetLastError = true)] + public static extern bool OpenProcessToken( + IntPtr processHandle, + UInt32 desiredAccess, + out IntPtr tokenHandle); + + [DllImport("advapi32.dll", SetLastError = true)] + public static extern bool LookupPrivilegeValue(string lpSystemName, string lpName, ref LUID lpLuid); + + [DllImport("advapi32.dll", SetLastError = true)] + public static extern bool PrivilegeCheck( + IntPtr clientToken, + ref PRIVILEGE_SET requiredPrivileges, + out bool pfResult); + + [DllImport("advapi32.dll", SetLastError = true)] + public static extern bool AdjustTokenPrivileges( + IntPtr tokenHandle, + bool disableAllPrivileges, + ref TOKEN_PRIVILEGES newState, + UInt32 bufferLengthInBytes, + IntPtr previousState, + UInt32 returnLengthInBytes); + + [DllImport("advapi32.dll", SetLastError = true)] + public static extern uint GetSecurityInfo( + IntPtr handle, + SE_OBJECT_TYPE objectType, + SECURITY_INFORMATION securityInfo, + IntPtr pSidOwner, + IntPtr pSidGroup, + out IntPtr pDacl, + IntPtr pSacl, + IntPtr pSecurityDescriptor); + + [DllImport("advapi32.dll", SetLastError = true)] + public static extern uint SetSecurityInfo( + IntPtr handle, + SE_OBJECT_TYPE objectType, + SECURITY_INFORMATION securityInfo, + IntPtr psidOwner, + IntPtr psidGroup, + IntPtr pDacl, + IntPtr pSacl); + + [DllImport("kernel32.dll", SetLastError = true)] + public static extern IntPtr GetCurrentProcess(); + + [DllImport("user32.dll", SetLastError = true)] + public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr hWndChildAfter, string className, IntPtr windowTitle); + + [DllImport("user32.dll", SetLastError = true)] + public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); + + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool IsWindowVisible(IntPtr hWnd); + + #endregion #region Structures + [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 0)] public struct TRUSTEE : IDisposable { @@ -105,12 +455,16 @@ namespace Dalamud.Injector public TRUSTEE_TYPE TrusteeType; private IntPtr ptstrName; + public string Name => Marshal.PtrToStringAuto(this.ptstrName) ?? string.Empty; + +#pragma warning disable CA1416 + void IDisposable.Dispose() { - if (ptstrName != IntPtr.Zero) Marshal.Release(ptstrName); + if (this.ptstrName != IntPtr.Zero) Marshal.Release(this.ptstrName); } - public string Name { get { return Marshal.PtrToStringAuto(ptstrName); } } +#pragma warning restore CA1416 } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Pack = 0)] @@ -204,341 +558,6 @@ namespace Dalamud.Injector public LUID_AND_ATTRIBUTES[] Privileges; } #endregion - - - #region Methods - [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Auto)] - public static extern void BuildExplicitAccessWithName( - ref EXPLICIT_ACCESS pExplicitAccess, - string pTrusteeName, - uint AccessPermissions, - uint AccessMode, - uint Inheritance); - - [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Auto)] - public static extern int SetEntriesInAcl( - int cCountOfExplicitEntries, - ref EXPLICIT_ACCESS pListOfExplicitEntries, - IntPtr OldAcl, - out IntPtr NewAcl); - - [DllImport("advapi32.dll", SetLastError = true)] - public static extern bool InitializeSecurityDescriptor( - out SECURITY_DESCRIPTOR pSecurityDescriptor, - uint dwRevision); - - [DllImport("advapi32.dll", SetLastError = true)] - public static extern bool SetSecurityDescriptorDacl( - ref SECURITY_DESCRIPTOR pSecurityDescriptor, - bool bDaclPresent, - IntPtr pDacl, - bool bDaclDefaulted); - - [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] - public static extern bool CreateProcess( - string lpApplicationName, - string lpCommandLine, - ref SECURITY_ATTRIBUTES lpProcessAttributes, - IntPtr lpThreadAttributes, - bool bInheritHandles, - UInt32 dwCreationFlags, - IntPtr lpEnvironment, - string lpCurrentDirectory, - [In] ref STARTUPINFO lpStartupInfo, - out PROCESS_INFORMATION lpProcessInformation); - - [DllImport("kernel32.dll", SetLastError = true)] - public static extern bool CloseHandle(IntPtr hObject); - - [DllImport("kernel32.dll", SetLastError = true)] - public static extern uint ResumeThread(IntPtr hThread); - - [DllImport("advapi32.dll", SetLastError = true)] - public static extern bool OpenProcessToken( - IntPtr ProcessHandle, - UInt32 DesiredAccess, - out IntPtr TokenHandle); - - [DllImport("advapi32.dll", SetLastError = true)] - public static extern bool LookupPrivilegeValue(string lpSystemName, string lpName, ref LUID lpLuid); - - [DllImport("advapi32.dll", SetLastError = true)] - public static extern bool PrivilegeCheck( - IntPtr ClientToken, - ref PRIVILEGE_SET RequiredPrivileges, - out bool pfResult); - - [DllImport("advapi32.dll", SetLastError = true)] - public static extern bool AdjustTokenPrivileges( - IntPtr TokenHandle, - bool DisableAllPrivileges, - ref TOKEN_PRIVILEGES NewState, - UInt32 BufferLengthInBytes, - IntPtr PreviousState, - UInt32 ReturnLengthInBytes); - - [DllImport("advapi32.dll", SetLastError = true)] - public static extern uint GetSecurityInfo( - IntPtr handle, - SE_OBJECT_TYPE ObjectType, - SECURITY_INFORMATION SecurityInfo, - IntPtr pSidOwner, - IntPtr pSidGroup, - out IntPtr pDacl, - IntPtr pSacl, - IntPtr pSecurityDescriptor); - - [DllImport("advapi32.dll", SetLastError = true)] - public static extern uint SetSecurityInfo( - IntPtr handle, - SE_OBJECT_TYPE ObjectType, - SECURITY_INFORMATION SecurityInfo, - IntPtr psidOwner, - IntPtr psidGroup, - IntPtr pDacl, - IntPtr pSacl); - - [DllImport("kernel32.dll", SetLastError = true)] - public static extern IntPtr GetCurrentProcess(); - #endregion - } - - public class ExistingProcess : Process - { - public ExistingProcess(IntPtr handle) - { - SetHandle(handle); - } - - private void SetHandle(IntPtr handle) - { - var baseType = GetType().BaseType; - if (baseType == null) - return; - - var setProcessHandleMethod = baseType.GetMethod("SetProcessHandle", - BindingFlags.NonPublic | BindingFlags.Instance); - setProcessHandleMethod?.Invoke(this, new object[] {new SafeProcessHandle(handle, true)}); - } - } - - public class GameExitedException : Exception - { - public GameExitedException() - : base("Game exited prematurely.") - { - } - } - - public static Process LaunchGame(string workingDir, string exePath, string arguments, Action beforeResume) - { - Process process = null; - - var userName = Environment.UserName; - - var pExplicitAccess = new PInvoke.EXPLICIT_ACCESS(); - PInvoke.BuildExplicitAccessWithName( - ref pExplicitAccess, - userName, - PInvoke.STANDARD_RIGHTS_ALL | PInvoke.SPECIFIC_RIGHTS_ALL & ~PInvoke.PROCESS_VM_WRITE, - PInvoke.GRANT_ACCESS, - 0); - - if (PInvoke.SetEntriesInAcl(1, ref pExplicitAccess, IntPtr.Zero, out var newAcl) != 0) - { - throw new Win32Exception(Marshal.GetLastWin32Error()); - } - - var secDesc = new PInvoke.SECURITY_DESCRIPTOR(); - if (!PInvoke.InitializeSecurityDescriptor(out secDesc, PInvoke.SECURITY_DESCRIPTOR_REVISION)) - { - throw new Win32Exception(Marshal.GetLastWin32Error()); - } - - if (!PInvoke.SetSecurityDescriptorDacl(ref secDesc, true, newAcl, false)) - { - throw new Win32Exception(Marshal.GetLastWin32Error()); - } - - var psecDesc = Marshal.AllocHGlobal(Marshal.SizeOf()); - Marshal.StructureToPtr(secDesc, psecDesc, true); - - var lpProcessInformation = new PInvoke.PROCESS_INFORMATION(); - try - { - var lpProcessAttributes = new PInvoke.SECURITY_ATTRIBUTES - { - nLength = Marshal.SizeOf(), - lpSecurityDescriptor = psecDesc, - bInheritHandle = false - }; - - var lpStartupInfo = new PInvoke.STARTUPINFO - { - cb = Marshal.SizeOf() - }; - - var compatLayerPrev = Environment.GetEnvironmentVariable("__COMPAT_LAYER"); - - Environment.SetEnvironmentVariable("__COMPAT_LAYER", "RunAsInvoker"); - try - { - if (!PInvoke.CreateProcess( - null, - $"\"{exePath}\" {arguments}", - ref lpProcessAttributes, - IntPtr.Zero, - false, - PInvoke.CREATE_SUSPENDED, - IntPtr.Zero, - workingDir, - ref lpStartupInfo, - out lpProcessInformation)) - { - throw new Win32Exception(Marshal.GetLastWin32Error()); - } - } - finally - { - Environment.SetEnvironmentVariable("__COMPAT_LAYER", compatLayerPrev); - } - - DisableSeDebug(lpProcessInformation.hProcess); - - process = new ExistingProcess(lpProcessInformation.hProcess); - - beforeResume?.Invoke(process); - - PInvoke.ResumeThread(lpProcessInformation.hThread); - - // Ensure that the game main window is prepared - try - { - do - { - process.WaitForInputIdle(); - - Thread.Sleep(100); - } while (IntPtr.Zero == TryFindGameWindow(process)); - } - catch (InvalidOperationException) - { - throw new GameExitedException(); - } - - if (PInvoke.GetSecurityInfo( - PInvoke.GetCurrentProcess(), - PInvoke.SE_OBJECT_TYPE.SE_KERNEL_OBJECT, - PInvoke.SECURITY_INFORMATION.DACL_SECURITY_INFORMATION, - IntPtr.Zero, IntPtr.Zero, - out var pACL, - IntPtr.Zero, IntPtr.Zero) != 0) - { - throw new Win32Exception(Marshal.GetLastWin32Error()); - } - - if (PInvoke.SetSecurityInfo( - lpProcessInformation.hProcess, - PInvoke.SE_OBJECT_TYPE.SE_KERNEL_OBJECT, - PInvoke.SECURITY_INFORMATION.DACL_SECURITY_INFORMATION | PInvoke.SECURITY_INFORMATION.UNPROTECTED_DACL_SECURITY_INFORMATION, - IntPtr.Zero, IntPtr.Zero, pACL, IntPtr.Zero) != 0) - { - throw new Win32Exception(Marshal.GetLastWin32Error()); - } - } - catch (Exception ex) - { - Log.Error(ex, "[NativeAclFix] Uncaught error during initialization, trying to kill process"); - - try - { - process?.Kill(); - } - catch (Exception killEx) - { - Log.Error(killEx, "[NativeAclFix] Could not kill process"); - } - - throw; - } - finally - { - Marshal.FreeHGlobal(psecDesc); - PInvoke.CloseHandle(lpProcessInformation.hThread); - } - - return process; - } - - private static void DisableSeDebug(IntPtr ProcessHandle) - { - if (!PInvoke.OpenProcessToken(ProcessHandle, PInvoke.TOKEN_QUERY | PInvoke.TOKEN_ADJUST_PRIVILEGES, out var TokenHandle)) - { - throw new Win32Exception(Marshal.GetLastWin32Error()); - } - - var luidDebugPrivilege = new PInvoke.LUID(); - if (!PInvoke.LookupPrivilegeValue(null, "SeDebugPrivilege", ref luidDebugPrivilege)) - { - throw new Win32Exception(Marshal.GetLastWin32Error()); - } - - var RequiredPrivileges = new PInvoke.PRIVILEGE_SET - { - PrivilegeCount = 1, - Control = PInvoke.PRIVILEGE_SET_ALL_NECESSARY, - Privilege = new PInvoke.LUID_AND_ATTRIBUTES[1] - }; - - RequiredPrivileges.Privilege[0].Luid = luidDebugPrivilege; - RequiredPrivileges.Privilege[0].Attributes = PInvoke.SE_PRIVILEGE_ENABLED; - - if (!PInvoke.PrivilegeCheck(TokenHandle, ref RequiredPrivileges, out bool bResult)) - { - throw new Win32Exception(Marshal.GetLastWin32Error()); - } - - if (bResult) // SeDebugPrivilege is enabled; try disabling it - { - var TokenPrivileges = new PInvoke.TOKEN_PRIVILEGES - { - PrivilegeCount = 1, - Privileges = new PInvoke.LUID_AND_ATTRIBUTES[1] - }; - - TokenPrivileges.Privileges[0].Luid = luidDebugPrivilege; - TokenPrivileges.Privileges[0].Attributes = PInvoke.SE_PRIVILEGE_REMOVED; - - if (!PInvoke.AdjustTokenPrivileges(TokenHandle, false, ref TokenPrivileges, 0, IntPtr.Zero, 0)) - { - throw new Win32Exception(Marshal.GetLastWin32Error()); - } - } - - PInvoke.CloseHandle(TokenHandle); - } - - [DllImport("user32.dll", SetLastError = true)] - private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr hWndChildAfter, string className, IntPtr windowTitle); - [DllImport("user32.dll", SetLastError = true)] - private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId); - [DllImport("user32.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - static extern bool IsWindowVisible(IntPtr hWnd); - - private static IntPtr TryFindGameWindow(Process process) - { - IntPtr hwnd = IntPtr.Zero; - while (IntPtr.Zero != (hwnd = FindWindowEx(IntPtr.Zero, hwnd, "FFXIVGAME", IntPtr.Zero))) - { - GetWindowThreadProcessId(hwnd, out uint pid); - - if (pid == process.Id && IsWindowVisible(hwnd)) - { - break; - } - } - return hwnd; } } } diff --git a/Dalamud/Configuration/Internal/DalamudConfiguration.cs b/Dalamud/Configuration/Internal/DalamudConfiguration.cs index dbfb5488c..cecc46921 100644 --- a/Dalamud/Configuration/Internal/DalamudConfiguration.cs +++ b/Dalamud/Configuration/Internal/DalamudConfiguration.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; + using Dalamud.Game.Text; -using Dalamud.Interface.GameFonts; using Dalamud.Interface.Style; using Newtonsoft.Json; using Serilog; diff --git a/Dalamud/EntryPoint.cs b/Dalamud/EntryPoint.cs index 37cbcb473..f8e952d7b 100644 --- a/Dalamud/EntryPoint.cs +++ b/Dalamud/EntryPoint.cs @@ -1,15 +1,12 @@ using System; using System.Diagnostics; using System.IO; -using System.Linq; using System.Net; using System.Runtime.InteropServices; -using System.Text; using System.Threading; using System.Threading.Tasks; using Dalamud.Configuration.Internal; -using Dalamud.Game; using Dalamud.Logging.Internal; using Dalamud.Support; using Dalamud.Utility; diff --git a/Dalamud/Game/ChatHandlers.cs b/Dalamud/Game/ChatHandlers.cs index 701e7624e..66c366734 100644 --- a/Dalamud/Game/ChatHandlers.cs +++ b/Dalamud/Game/ChatHandlers.cs @@ -18,7 +18,6 @@ using Dalamud.Interface.Internal.Windows; using Dalamud.IoC; using Dalamud.IoC.Internal; using Dalamud.Plugin.Internal; -using Dalamud.Plugin.Internal.Types; using Dalamud.Utility; using Serilog; diff --git a/Dalamud/Game/ClientState/JobGauge/Types/DRGGauge.cs b/Dalamud/Game/ClientState/JobGauge/Types/DRGGauge.cs index 26b9137c2..1003d2cd5 100644 --- a/Dalamud/Game/ClientState/JobGauge/Types/DRGGauge.cs +++ b/Dalamud/Game/ClientState/JobGauge/Types/DRGGauge.cs @@ -1,7 +1,5 @@ using System; -using Dalamud.Game.ClientState.JobGauge.Enums; - namespace Dalamud.Game.ClientState.JobGauge.Types { /// diff --git a/Dalamud/Game/ClientState/Party/PartyMember.cs b/Dalamud/Game/ClientState/Party/PartyMember.cs index 9d70592f7..64e6fda64 100644 --- a/Dalamud/Game/ClientState/Party/PartyMember.cs +++ b/Dalamud/Game/ClientState/Party/PartyMember.cs @@ -7,7 +7,6 @@ using Dalamud.Game.ClientState.Resolvers; using Dalamud.Game.ClientState.Statuses; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Memory; -using JetBrains.Annotations; namespace Dalamud.Game.ClientState.Party { diff --git a/Dalamud/Game/FrameworkAddressResolver.cs b/Dalamud/Game/FrameworkAddressResolver.cs index 7bcae5045..87ebb6aa7 100644 --- a/Dalamud/Game/FrameworkAddressResolver.cs +++ b/Dalamud/Game/FrameworkAddressResolver.cs @@ -1,8 +1,6 @@ using System; using System.Runtime.InteropServices; -using Dalamud.Game.Internal; - namespace Dalamud.Game { /// diff --git a/Dalamud/Game/Gui/ChatGuiAddressResolver.cs b/Dalamud/Game/Gui/ChatGuiAddressResolver.cs index 07c154f1f..f11f8b2f0 100644 --- a/Dalamud/Game/Gui/ChatGuiAddressResolver.cs +++ b/Dalamud/Game/Gui/ChatGuiAddressResolver.cs @@ -1,7 +1,5 @@ using System; -using Dalamud.Game.Internal; - namespace Dalamud.Game.Gui { /// diff --git a/Dalamud/Game/Gui/ContextMenus/GameObjectContext.cs b/Dalamud/Game/Gui/ContextMenus/GameObjectContext.cs index a6280dde5..076888f6a 100644 --- a/Dalamud/Game/Gui/ContextMenus/GameObjectContext.cs +++ b/Dalamud/Game/Gui/ContextMenus/GameObjectContext.cs @@ -1,6 +1,4 @@ -using Dalamud.Game.Text.SeStringHandling; - -namespace Dalamud.Game.Gui.ContextMenus +namespace Dalamud.Game.Gui.ContextMenus { /// /// Provides game object context to a context menu. diff --git a/Dalamud/Game/Gui/GameGuiAddressResolver.cs b/Dalamud/Game/Gui/GameGuiAddressResolver.cs index 299d59ce2..c81f9fd5c 100644 --- a/Dalamud/Game/Gui/GameGuiAddressResolver.cs +++ b/Dalamud/Game/Gui/GameGuiAddressResolver.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.InteropServices; namespace Dalamud.Game.Gui { diff --git a/Dalamud/Game/Gui/PartyFinder/Types/JobFlagsExtensions.cs b/Dalamud/Game/Gui/PartyFinder/Types/JobFlagsExtensions.cs index c39822eb7..67469f6aa 100644 --- a/Dalamud/Game/Gui/PartyFinder/Types/JobFlagsExtensions.cs +++ b/Dalamud/Game/Gui/PartyFinder/Types/JobFlagsExtensions.cs @@ -1,5 +1,3 @@ -using System; - using Dalamud.Data; using Lumina.Excel.GeneratedSheets; diff --git a/Dalamud/Game/Libc/LibcFunctionAddressResolver.cs b/Dalamud/Game/Libc/LibcFunctionAddressResolver.cs index 4d30a1e74..02b031b44 100644 --- a/Dalamud/Game/Libc/LibcFunctionAddressResolver.cs +++ b/Dalamud/Game/Libc/LibcFunctionAddressResolver.cs @@ -1,7 +1,5 @@ using System; -using Dalamud.Game.Internal; - namespace Dalamud.Game.Libc { /// diff --git a/Dalamud/Game/Network/GameNetworkAddressResolver.cs b/Dalamud/Game/Network/GameNetworkAddressResolver.cs index 130986197..565a1e2b9 100644 --- a/Dalamud/Game/Network/GameNetworkAddressResolver.cs +++ b/Dalamud/Game/Network/GameNetworkAddressResolver.cs @@ -1,7 +1,5 @@ using System; -using Dalamud.Game.Internal; - namespace Dalamud.Game.Network { /// diff --git a/Dalamud/Game/Network/Internal/WinSockHandlers.cs b/Dalamud/Game/Network/Internal/WinSockHandlers.cs index 82f2f0d91..2abe4a326 100644 --- a/Dalamud/Game/Network/Internal/WinSockHandlers.cs +++ b/Dalamud/Game/Network/Internal/WinSockHandlers.cs @@ -3,7 +3,6 @@ using System.Net.Sockets; using System.Runtime.InteropServices; using Dalamud.Hooking; -using Dalamud.Hooking.Internal; namespace Dalamud.Game.Network.Internal { diff --git a/Dalamud/Game/Text/SeStringHandling/Payloads/EmphasisItalicPayload.cs b/Dalamud/Game/Text/SeStringHandling/Payloads/EmphasisItalicPayload.cs index b6c3bbd76..0a61f5ef3 100644 --- a/Dalamud/Game/Text/SeStringHandling/Payloads/EmphasisItalicPayload.cs +++ b/Dalamud/Game/Text/SeStringHandling/Payloads/EmphasisItalicPayload.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.IO; diff --git a/Dalamud/Game/Text/SeStringHandling/Payloads/ItemPayload.cs b/Dalamud/Game/Text/SeStringHandling/Payloads/ItemPayload.cs index 8ab3d2484..06e4dfc76 100644 --- a/Dalamud/Game/Text/SeStringHandling/Payloads/ItemPayload.cs +++ b/Dalamud/Game/Text/SeStringHandling/Payloads/ItemPayload.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/Dalamud/Game/Text/SeStringHandling/SeStringManager.cs b/Dalamud/Game/Text/SeStringHandling/SeStringManager.cs index 16f2b4209..68403b39e 100644 --- a/Dalamud/Game/Text/SeStringHandling/SeStringManager.cs +++ b/Dalamud/Game/Text/SeStringHandling/SeStringManager.cs @@ -1,10 +1,6 @@ using System; using System.Collections.Generic; -using System.IO; -using System.Linq; -using Dalamud.Data; -using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.IoC; using Dalamud.IoC.Internal; using Lumina.Excel.GeneratedSheets; diff --git a/Dalamud/Hooking/Hook.cs b/Dalamud/Hooking/Hook.cs index a61e366f8..9c1cbaa06 100644 --- a/Dalamud/Hooking/Hook.cs +++ b/Dalamud/Hooking/Hook.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Reflection; using Dalamud.Configuration.Internal; diff --git a/Dalamud/Hooking/Internal/HookManager.cs b/Dalamud/Hooking/Internal/HookManager.cs index d9237c156..9cc73da3b 100644 --- a/Dalamud/Hooking/Internal/HookManager.cs +++ b/Dalamud/Hooking/Internal/HookManager.cs @@ -4,11 +4,9 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; -using Dalamud.Configuration.Internal; using Dalamud.Logging.Internal; using Dalamud.Memory; using Iced.Intel; -using Microsoft.Win32; namespace Dalamud.Hooking.Internal { diff --git a/Dalamud/Interface/GameFonts/FdtReader.cs b/Dalamud/Interface/GameFonts/FdtReader.cs index 5d28041b9..155766ded 100644 --- a/Dalamud/Interface/GameFonts/FdtReader.cs +++ b/Dalamud/Interface/GameFonts/FdtReader.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace Dalamud.Interface.GameFonts { diff --git a/Dalamud/Interface/GameFonts/GameFontFamily.cs b/Dalamud/Interface/GameFonts/GameFontFamily.cs index 2aa836927..cb3e84a59 100644 --- a/Dalamud/Interface/GameFonts/GameFontFamily.cs +++ b/Dalamud/Interface/GameFonts/GameFontFamily.cs @@ -1,9 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace Dalamud.Interface.GameFonts { /// diff --git a/Dalamud/Interface/GameFonts/GameFontLayoutPlan.cs b/Dalamud/Interface/GameFonts/GameFontLayoutPlan.cs index 482ef22e2..93fe5ab87 100644 --- a/Dalamud/Interface/GameFonts/GameFontLayoutPlan.cs +++ b/Dalamud/Interface/GameFonts/GameFontLayoutPlan.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Numerics; -using System.Text; -using System.Threading.Tasks; using ImGuiNET; diff --git a/Dalamud/Interface/GameFonts/GameFontManager.cs b/Dalamud/Interface/GameFonts/GameFontManager.cs index 5a885bc8d..ae45b7226 100644 --- a/Dalamud/Interface/GameFonts/GameFontManager.cs +++ b/Dalamud/Interface/GameFonts/GameFontManager.cs @@ -5,7 +5,6 @@ using System.Numerics; using System.Runtime.InteropServices; using System.Text; -using Dalamud.Configuration.Internal; using Dalamud.Data; using Dalamud.Interface.Internal; using ImGuiNET; diff --git a/Dalamud/Interface/GameFonts/GameFontStyle.cs b/Dalamud/Interface/GameFonts/GameFontStyle.cs index bd3a378f3..6ec078d69 100644 --- a/Dalamud/Interface/GameFonts/GameFontStyle.cs +++ b/Dalamud/Interface/GameFonts/GameFontStyle.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Dalamud.Interface.GameFonts { diff --git a/Dalamud/Interface/ImGuiFileDialog/FileDialog.Files.cs b/Dalamud/Interface/ImGuiFileDialog/FileDialog.Files.cs index 6630c0439..05e69b4f5 100644 --- a/Dalamud/Interface/ImGuiFileDialog/FileDialog.Files.cs +++ b/Dalamud/Interface/ImGuiFileDialog/FileDialog.Files.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using Dalamud.Interface; - namespace Dalamud.Interface.ImGuiFileDialog { /// diff --git a/Dalamud/Interface/ImGuiFileDialog/FileDialog.Structs.cs b/Dalamud/Interface/ImGuiFileDialog/FileDialog.Structs.cs index 475147518..e6dd5e3a4 100644 --- a/Dalamud/Interface/ImGuiFileDialog/FileDialog.Structs.cs +++ b/Dalamud/Interface/ImGuiFileDialog/FileDialog.Structs.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Numerics; diff --git a/Dalamud/Interface/ImGuiFileDialog/ImGuiFileDialogFlags.cs b/Dalamud/Interface/ImGuiFileDialog/ImGuiFileDialogFlags.cs index fe189c77c..7ed959796 100644 --- a/Dalamud/Interface/ImGuiFileDialog/ImGuiFileDialogFlags.cs +++ b/Dalamud/Interface/ImGuiFileDialog/ImGuiFileDialogFlags.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Dalamud.Interface.ImGuiFileDialog { diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index d0f76e0fb..c2ee00fdc 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -15,11 +15,9 @@ using Dalamud.Game.ClientState.Keys; using Dalamud.Game.Gui.Internal; using Dalamud.Game.Internal.DXGI; using Dalamud.Hooking; -using Dalamud.Hooking.Internal; using Dalamud.Interface.GameFonts; using Dalamud.Interface.Internal.ManagedAsserts; using Dalamud.Interface.Internal.Notifications; -using Dalamud.Interface.Internal.Windows.StyleEditor; using Dalamud.Interface.Style; using Dalamud.Interface.Windowing; using Dalamud.Utility; diff --git a/Dalamud/Interface/Internal/UiDebug.cs b/Dalamud/Interface/Internal/UiDebug.cs index 3b02a1b8d..51e2b6b42 100644 --- a/Dalamud/Interface/Internal/UiDebug.cs +++ b/Dalamud/Interface/Internal/UiDebug.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; -using System.Diagnostics; using System.Numerics; -using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Dalamud.Game; @@ -19,7 +15,7 @@ namespace Dalamud.Interface.Internal /// /// This class displays a debug window to inspect native addons. /// - internal unsafe class UIDebug + internal unsafe class UiDebug { private const int UnitListCount = 18; @@ -52,9 +48,9 @@ namespace Dalamud.Interface.Internal private AtkUnitBase* selectedUnitBase = null; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public UIDebug() + public UiDebug() { var sigScanner = Service.Get(); var getSingletonAddr = sigScanner.ScanText("E8 ?? ?? ?? ?? 41 B8 01 00 00 00 48 8D 15 ?? ?? ?? ?? 48 8B 48 20 E8 ?? ?? ?? ?? 48 8B CF"); diff --git a/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs b/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs index 448397f62..468bdb3f3 100644 --- a/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs +++ b/Dalamud/Interface/Internal/Windows/ChangelogWindow.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.IO; using System.Numerics; diff --git a/Dalamud/Interface/Internal/Windows/CreditsWindow.cs b/Dalamud/Interface/Internal/Windows/CreditsWindow.cs index 4e2a8d847..9dd7fa4cb 100644 --- a/Dalamud/Interface/Internal/Windows/CreditsWindow.cs +++ b/Dalamud/Interface/Internal/Windows/CreditsWindow.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using System.Numerics; -using Dalamud.Game; using Dalamud.Game.Gui; using Dalamud.Interface.Windowing; using Dalamud.Plugin.Internal; diff --git a/Dalamud/Interface/Internal/Windows/DataWindow.cs b/Dalamud/Interface/Internal/Windows/DataWindow.cs index 1cacc7f38..2783d00ce 100644 --- a/Dalamud/Interface/Internal/Windows/DataWindow.cs +++ b/Dalamud/Interface/Internal/Windows/DataWindow.cs @@ -72,7 +72,7 @@ namespace Dalamud.Interface.Internal.Windows private bool resolveGameData = false; private bool resolveObjects = false; - private UIDebug addonInspector = null; + private UiDebug addonInspector = null; private Hook? messageBoxMinHook; private bool hookUseMinHook = false; @@ -877,7 +877,7 @@ namespace Dalamud.Interface.Internal.Windows private void DrawAddonInspector() { - this.addonInspector ??= new UIDebug(); + this.addonInspector ??= new UiDebug(); this.addonInspector.Draw(); } diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/DalamudChangelogEntry.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/DalamudChangelogEntry.cs index 7d9f4b5ab..7a060d34f 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/DalamudChangelogEntry.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/DalamudChangelogEntry.cs @@ -1,7 +1,5 @@ using System; -using ImGuiScene; - namespace Dalamud.Interface.Internal.Windows.PluginInstaller { /// diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/IChangelogEntry.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/IChangelogEntry.cs index 9e5c6b2ab..21143e5c0 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/IChangelogEntry.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/IChangelogEntry.cs @@ -1,7 +1,5 @@ using System; -using ImGuiScene; - namespace Dalamud.Interface.Internal.Windows.PluginInstaller { /// diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginChangelogEntry.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginChangelogEntry.cs index 4008ed4b4..ce2353ec8 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginChangelogEntry.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginChangelogEntry.cs @@ -2,7 +2,6 @@ using Dalamud.Plugin.Internal; using Dalamud.Utility; -using ImGuiScene; namespace Dalamud.Interface.Internal.Windows.PluginInstaller { diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs index 893577754..838f03345 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs @@ -5,7 +5,6 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; -using System.Net.Http; using System.Numerics; using System.Threading.Tasks; diff --git a/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs b/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs index 9bceef857..0fcedc48e 100644 --- a/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginStatWindow.cs @@ -4,8 +4,6 @@ using System.Linq; using System.Reflection; using Dalamud.Game; -using Dalamud.Game.Internal; -using Dalamud.Hooking; using Dalamud.Hooking.Internal; using Dalamud.Interface.Windowing; using Dalamud.Plugin.Internal; diff --git a/Dalamud/Interface/Internal/Windows/SelfTest/SelfTestWindow.cs b/Dalamud/Interface/Internal/Windows/SelfTest/SelfTestWindow.cs index a26368d47..0af8bf1bb 100644 --- a/Dalamud/Interface/Internal/Windows/SelfTest/SelfTestWindow.cs +++ b/Dalamud/Interface/Internal/Windows/SelfTest/SelfTestWindow.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Numerics; diff --git a/Dalamud/Interface/Internal/Windows/SettingsWindow.cs b/Dalamud/Interface/Internal/Windows/SettingsWindow.cs index dec061a9b..8678b26bb 100644 --- a/Dalamud/Interface/Internal/Windows/SettingsWindow.cs +++ b/Dalamud/Interface/Internal/Windows/SettingsWindow.cs @@ -12,7 +12,6 @@ using Dalamud.Game.Gui.Dtr; using Dalamud.Game.Text; using Dalamud.Interface.Colors; using Dalamud.Interface.Components; -using Dalamud.Interface.GameFonts; using Dalamud.Interface.Windowing; using Dalamud.Plugin.Internal; using Dalamud.Utility; diff --git a/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs b/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs index 40bb29672..628f52f2f 100644 --- a/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs +++ b/Dalamud/Interface/Internal/Windows/TitleScreenMenuWindow.cs @@ -9,7 +9,6 @@ using Dalamud.Game; using Dalamud.Game.ClientState; using Dalamud.Game.Gui; using Dalamud.Interface.Animation.EasingFunctions; -using Dalamud.Interface.GameFonts; using Dalamud.Interface.Windowing; using ImGuiNET; using ImGuiScene; diff --git a/Dalamud/Logging/Internal/TaskTracker.cs b/Dalamud/Logging/Internal/TaskTracker.cs index 3888d55db..1f465b4a5 100644 --- a/Dalamud/Logging/Internal/TaskTracker.cs +++ b/Dalamud/Logging/Internal/TaskTracker.cs @@ -6,7 +6,6 @@ using System.Reflection; using System.Threading.Tasks; using Dalamud.Game; -using Serilog; namespace Dalamud.Logging.Internal { diff --git a/Dalamud/Plugin/DalamudPluginInterface.cs b/Dalamud/Plugin/DalamudPluginInterface.cs index 8bff19d7b..2be81eaf5 100644 --- a/Dalamud/Plugin/DalamudPluginInterface.cs +++ b/Dalamud/Plugin/DalamudPluginInterface.cs @@ -14,7 +14,6 @@ using Dalamud.Game.Text.Sanitizer; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Interface; -using Dalamud.Interface.Internal; using Dalamud.Plugin.Internal; using Dalamud.Plugin.Ipc; using Dalamud.Plugin.Ipc.Exceptions; diff --git a/Dalamud/Plugin/Internal/Exceptions/InvalidPluginException.cs b/Dalamud/Plugin/Internal/Exceptions/InvalidPluginException.cs index 6b5c8920a..0488f5539 100644 --- a/Dalamud/Plugin/Internal/Exceptions/InvalidPluginException.cs +++ b/Dalamud/Plugin/Internal/Exceptions/InvalidPluginException.cs @@ -1,4 +1,3 @@ -using System; using System.IO; namespace Dalamud.Plugin.Internal.Exceptions diff --git a/Dalamud/Plugin/Internal/Exceptions/InvalidPluginOperationException.cs b/Dalamud/Plugin/Internal/Exceptions/InvalidPluginOperationException.cs index a80d6d51d..a2d8e7361 100644 --- a/Dalamud/Plugin/Internal/Exceptions/InvalidPluginOperationException.cs +++ b/Dalamud/Plugin/Internal/Exceptions/InvalidPluginOperationException.cs @@ -1,5 +1,3 @@ -using System; - namespace Dalamud.Plugin.Internal.Exceptions { /// diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index 2893f6ab2..f98e122f5 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -1126,7 +1126,9 @@ namespace Dalamud.Plugin.Internal this.assemblyLocationMonoHook = new MonoMod.RuntimeDetour.Hook(locationTarget, locationPatch); #pragma warning disable CS0618 + #pragma warning disable SYSLIB0012 var codebaseTarget = targetType.GetProperty(nameof(Assembly.CodeBase))?.GetGetMethod(); + #pragma warning restore SYSLIB0012 #pragma warning restore CS0618 var codebasePatch = typeof(PluginManager).GetMethod(nameof(AssemblyCodeBasePatch), BindingFlags.NonPublic | BindingFlags.Static); this.assemblyCodeBaseMonoHook = new MonoMod.RuntimeDetour.Hook(codebaseTarget, codebasePatch); diff --git a/Dalamud/Utility/Util.cs b/Dalamud/Utility/Util.cs index 4cc1f8cee..9c02efe2c 100644 --- a/Dalamud/Utility/Util.cs +++ b/Dalamud/Utility/Util.cs @@ -8,7 +8,6 @@ using System.Net.Http; using System.Numerics; using System.Reflection; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using System.Text; using Dalamud.Configuration.Internal;