diff --git a/Dalamud.Common/ClientLanguage.cs b/Dalamud.Common/ClientLanguage.cs new file mode 100644 index 000000000..1fd58dce1 --- /dev/null +++ b/Dalamud.Common/ClientLanguage.cs @@ -0,0 +1,27 @@ +namespace Dalamud.Common; + +/// +/// Enum describing the language the game loads in. +/// +public enum ClientLanguage +{ + /// + /// Indicating a Japanese game client. + /// + Japanese, + + /// + /// Indicating an English game client. + /// + English, + + /// + /// Indicating a German game client. + /// + German, + + /// + /// Indicating a French game client. + /// + French, +} diff --git a/Dalamud.Common/Dalamud.Common.csproj b/Dalamud.Common/Dalamud.Common.csproj new file mode 100644 index 000000000..ac5d3fdba --- /dev/null +++ b/Dalamud.Common/Dalamud.Common.csproj @@ -0,0 +1,13 @@ + + + + net7.0 + enable + enable + + + + + + + diff --git a/Dalamud/DalamudStartInfo.cs b/Dalamud.Common/DalamudStartInfo.cs similarity index 96% rename from Dalamud/DalamudStartInfo.cs rename to Dalamud.Common/DalamudStartInfo.cs index f22388e9b..069a0ef9f 100644 --- a/Dalamud/DalamudStartInfo.cs +++ b/Dalamud.Common/DalamudStartInfo.cs @@ -1,17 +1,13 @@ -using System; -using System.Collections.Generic; - -using Dalamud.Game; +using Dalamud.Common.Game; using Newtonsoft.Json; -namespace Dalamud; +namespace Dalamud.Common; /// /// Struct containing information needed to initialize Dalamud. /// [Serializable] -[ServiceManager.Service] -public record DalamudStartInfo : IServiceType +public record DalamudStartInfo { /// /// Initializes a new instance of the class. @@ -97,7 +93,7 @@ public record DalamudStartInfo : IServiceType /// /// Gets or sets troubleshooting information to attach when generating a tspack file. /// - public string TroubleshootingPackData { get; set; } + public string? TroubleshootingPackData { get; set; } /// /// Gets or sets a value that specifies how much to wait before a new Dalamud session. diff --git a/Dalamud/Game/GameVersion.cs b/Dalamud.Common/Game/GameVersion.cs similarity index 97% rename from Dalamud/Game/GameVersion.cs rename to Dalamud.Common/Game/GameVersion.cs index 2b2021e60..26ff0e48f 100644 --- a/Dalamud/Game/GameVersion.cs +++ b/Dalamud.Common/Game/GameVersion.cs @@ -1,11 +1,9 @@ -using System; using System.Globalization; -using System.Linq; using System.Text; using Newtonsoft.Json; -namespace Dalamud.Game; +namespace Dalamud.Common.Game; /// /// A GameVersion object contains give hierarchical numeric components: year, month, @@ -168,14 +166,14 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable new GameVersion(this.Year, this.Month, this.Day, this.Major, this.Minor); /// - public int CompareTo(object obj) + public int CompareTo(object? obj) { if (obj == null) return 1; @@ -315,7 +313,7 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable - public int CompareTo(GameVersion value) + public int CompareTo(GameVersion? value) { if (value == null) return 1; @@ -348,7 +346,7 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj is not GameVersion value) return false; @@ -357,7 +355,7 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable - public bool Equals(GameVersion value) + public bool Equals(GameVersion? value) { if (value == null) { diff --git a/Dalamud/Game/GameVersionConverter.cs b/Dalamud.Common/Game/GameVersionConverter.cs similarity index 98% rename from Dalamud/Game/GameVersionConverter.cs rename to Dalamud.Common/Game/GameVersionConverter.cs index f307b6fb9..a1876869a 100644 --- a/Dalamud/Game/GameVersionConverter.cs +++ b/Dalamud.Common/Game/GameVersionConverter.cs @@ -1,8 +1,6 @@ -using System; - using Newtonsoft.Json; -namespace Dalamud.Game; +namespace Dalamud.Common.Game; /// /// Converts a to and from a string (e.g. "2010.01.01.1234.5678"). diff --git a/Dalamud.Injector/Dalamud.Injector.csproj b/Dalamud.Injector/Dalamud.Injector.csproj index ea9e4f0a3..d8a74e58d 100644 --- a/Dalamud.Injector/Dalamud.Injector.csproj +++ b/Dalamud.Injector/Dalamud.Injector.csproj @@ -81,12 +81,6 @@ - - - - - - - + diff --git a/Dalamud.Injector/EntryPoint.cs b/Dalamud.Injector/EntryPoint.cs index a35248062..bd9fa87f8 100644 --- a/Dalamud.Injector/EntryPoint.cs +++ b/Dalamud.Injector/EntryPoint.cs @@ -9,7 +9,8 @@ using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; -using Dalamud.Game; +using Dalamud.Common; +using Dalamud.Common.Game; using Newtonsoft.Json; using Reloaded.Memory.Buffers; using Serilog; diff --git a/Dalamud.Injector/Hacks.cs b/Dalamud.Injector/Hacks.cs deleted file mode 100644 index 7bc4468af..000000000 --- a/Dalamud.Injector/Hacks.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; - -// ReSharper disable once CheckNamespace -namespace Dalamud; - -// TODO: Get rid of this! Move StartInfo to another assembly, make this good - -/// -/// Class to initialize Service<T>s. -/// -internal static class ServiceManager -{ - /// - /// Indicates that the class is a service. - /// - [AttributeUsage(AttributeTargets.Class)] - public class Service : Attribute - { - } -} diff --git a/Dalamud.Test/Game/GameVersionTests.cs b/Dalamud.Test/Game/GameVersionTests.cs index 44a5813c8..dcace4279 100644 --- a/Dalamud.Test/Game/GameVersionTests.cs +++ b/Dalamud.Test/Game/GameVersionTests.cs @@ -1,4 +1,4 @@ -using Dalamud.Game; +using Dalamud.Common.Game; using Xunit; namespace Dalamud.Test.Game diff --git a/Dalamud.sln b/Dalamud.sln index 443f38496..200238a83 100644 --- a/Dalamud.sln +++ b/Dalamud.sln @@ -38,6 +38,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FFXIVClientStructs.InteropS EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DalamudCrashHandler", "DalamudCrashHandler\DalamudCrashHandler.vcxproj", "{317A264C-920B-44A1-8A34-F3A6827B0705}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dalamud.Common", "Dalamud.Common\Dalamud.Common.csproj", "{F21B13D2-D7D0-4456-B70F-3F8D695064E2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -202,6 +204,18 @@ Global {317A264C-920B-44A1-8A34-F3A6827B0705}.Release|x64.Build.0 = Release|x64 {317A264C-920B-44A1-8A34-F3A6827B0705}.Release|x86.ActiveCfg = Release|x64 {317A264C-920B-44A1-8A34-F3A6827B0705}.Release|x86.Build.0 = Release|x64 + {F21B13D2-D7D0-4456-B70F-3F8D695064E2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F21B13D2-D7D0-4456-B70F-3F8D695064E2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F21B13D2-D7D0-4456-B70F-3F8D695064E2}.Debug|x64.ActiveCfg = Debug|Any CPU + {F21B13D2-D7D0-4456-B70F-3F8D695064E2}.Debug|x64.Build.0 = Debug|Any CPU + {F21B13D2-D7D0-4456-B70F-3F8D695064E2}.Debug|x86.ActiveCfg = Debug|Any CPU + {F21B13D2-D7D0-4456-B70F-3F8D695064E2}.Debug|x86.Build.0 = Debug|Any CPU + {F21B13D2-D7D0-4456-B70F-3F8D695064E2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F21B13D2-D7D0-4456-B70F-3F8D695064E2}.Release|Any CPU.Build.0 = Release|Any CPU + {F21B13D2-D7D0-4456-B70F-3F8D695064E2}.Release|x64.ActiveCfg = Release|Any CPU + {F21B13D2-D7D0-4456-B70F-3F8D695064E2}.Release|x64.Build.0 = Release|Any CPU + {F21B13D2-D7D0-4456-B70F-3F8D695064E2}.Release|x86.ActiveCfg = Release|Any CPU + {F21B13D2-D7D0-4456-B70F-3F8D695064E2}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Dalamud/ClientLanguage.cs b/Dalamud/ClientLanguage.cs index 4e04d4a54..8f2c52456 100644 --- a/Dalamud/ClientLanguage.cs +++ b/Dalamud/ClientLanguage.cs @@ -1,5 +1,7 @@ namespace Dalamud; +// TODO(v10): Delete this, and use Dalamud.Common.ClientLanguage instead for everything. + /// /// Enum describing the language the game loads in. /// diff --git a/Dalamud/Dalamud.cs b/Dalamud/Dalamud.cs index a9a3a511a..8a75049ad 100644 --- a/Dalamud/Dalamud.cs +++ b/Dalamud/Dalamud.cs @@ -1,4 +1,3 @@ -using System; using System.Diagnostics; using System.IO; using System.Linq; @@ -7,6 +6,7 @@ using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; +using Dalamud.Common; using Dalamud.Configuration.Internal; using Dalamud.Game; using Dalamud.Game.Gui.Internal; @@ -14,6 +14,7 @@ using Dalamud.Interface.Internal; using Dalamud.Plugin.Internal; using Dalamud.Storage; using Dalamud.Utility; +using Dalamud.Utility.Timing; using PInvoke; using Serilog; @@ -47,10 +48,28 @@ internal sealed class Dalamud : IServiceType /// Event used to signal the main thread to continue. public Dalamud(DalamudStartInfo info, ReliableFileStorage fs, DalamudConfiguration configuration, IntPtr mainThreadContinueEvent) { + this.StartInfo = info; + this.unloadSignal = new ManualResetEvent(false); this.unloadSignal.Reset(); + + // Directory resolved signatures(CS, our own) will be cached in + var cacheDir = new DirectoryInfo(Path.Combine(this.StartInfo.WorkingDirectory!, "cachedSigs")); + if (!cacheDir.Exists) + cacheDir.Create(); + + // Set up the SigScanner for our target module + TargetSigScanner scanner; + using (Timings.Start("SigScanner Init")) + { + scanner = new TargetSigScanner( + true, new FileInfo(Path.Combine(cacheDir.FullName, $"{this.StartInfo.GameVersion}.json"))); + } - ServiceManager.InitializeProvidedServicesAndClientStructs(this, info, fs, configuration); + ServiceManager.InitializeProvidedServices(this, fs, configuration, scanner); + + // Set up FFXIVClientStructs + this.SetupClientStructsResolver(cacheDir); if (!configuration.IsResumeGameAfterPluginLoad) { @@ -97,11 +116,16 @@ internal sealed class Dalamud : IServiceType }); } } + + /// + /// Gets the start information for this Dalamud instance. + /// + internal DalamudStartInfo StartInfo { get; private set; } /// /// Gets location of stored assets. /// - internal DirectoryInfo AssetDirectory => new(Service.Get().AssetDirectory!); + internal DirectoryInfo AssetDirectory => new(this.StartInfo.AssetDirectory!); /// /// Signal to the crash handler process that we should restart the game. @@ -176,4 +200,13 @@ internal sealed class Dalamud : IServiceType var oldFilter = NativeFunctions.SetUnhandledExceptionFilter(releaseFilter); Log.Debug("Reset ExceptionFilter, old: {0}", oldFilter); } + + private void SetupClientStructsResolver(DirectoryInfo cacheDir) + { + using (Timings.Start("CS Resolver Init")) + { + FFXIVClientStructs.Interop.Resolver.GetInstance.SetupSearchSpace(Service.Get().SearchBase, new FileInfo(Path.Combine(cacheDir.FullName, $"{this.StartInfo.GameVersion}_cs.json"))); + FFXIVClientStructs.Interop.Resolver.GetInstance.Resolve(); + } + } } diff --git a/Dalamud/Dalamud.csproj b/Dalamud/Dalamud.csproj index 7ae97e1a6..69d08f517 100644 --- a/Dalamud/Dalamud.csproj +++ b/Dalamud/Dalamud.csproj @@ -89,6 +89,7 @@ + diff --git a/Dalamud/Data/DataManager.cs b/Dalamud/Data/DataManager.cs index f1f98229a..6195532ab 100644 --- a/Dalamud/Data/DataManager.cs +++ b/Dalamud/Data/DataManager.cs @@ -7,6 +7,7 @@ using System.Threading; using Dalamud.IoC; using Dalamud.IoC.Internal; using Dalamud.Plugin.Services; +using Dalamud.Utility; using Dalamud.Utility.Timing; using JetBrains.Annotations; using Lumina; @@ -32,9 +33,9 @@ internal sealed class DataManager : IDisposable, IServiceType, IDataManager private readonly CancellationTokenSource luminaCancellationTokenSource; [ServiceManager.ServiceConstructor] - private DataManager(DalamudStartInfo dalamudStartInfo, Dalamud dalamud) + private DataManager(Dalamud dalamud) { - this.Language = dalamudStartInfo.Language; + this.Language = (ClientLanguage)dalamud.StartInfo.Language; // Set up default values so plugins do not null-reference when data is being loaded. this.ClientOpCodes = this.ServerOpCodes = new ReadOnlyDictionary(new Dictionary()); @@ -82,17 +83,20 @@ internal sealed class DataManager : IDisposable, IServiceType, IDataManager Log.Information("Lumina is ready: {0}", this.GameData.DataPath); - try + if (!dalamud.StartInfo.TroubleshootingPackData.IsNullOrEmpty()) { - var tsInfo = - JsonConvert.DeserializeObject( - dalamudStartInfo.TroubleshootingPackData); - this.HasModifiedGameDataFiles = - tsInfo?.IndexIntegrity is LauncherTroubleshootingInfo.IndexIntegrityResult.Failed or LauncherTroubleshootingInfo.IndexIntegrityResult.Exception; - } - catch - { - // ignored + try + { + var tsInfo = + JsonConvert.DeserializeObject( + dalamud.StartInfo.TroubleshootingPackData); + this.HasModifiedGameDataFiles = + tsInfo?.IndexIntegrity is LauncherTroubleshootingInfo.IndexIntegrityResult.Failed or LauncherTroubleshootingInfo.IndexIntegrityResult.Exception; + } + catch + { + // ignored + } } } diff --git a/Dalamud/EntryPoint.cs b/Dalamud/EntryPoint.cs index 6b53ee3a6..c9537eda6 100644 --- a/Dalamud/EntryPoint.cs +++ b/Dalamud/EntryPoint.cs @@ -1,4 +1,3 @@ -using System; using System.Diagnostics; using System.IO; using System.Net; @@ -6,6 +5,7 @@ using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; +using Dalamud.Common; using Dalamud.Configuration.Internal; using Dalamud.Logging.Internal; using Dalamud.Logging.Retention; @@ -163,6 +163,9 @@ public sealed class EntryPoint Log.Information(new string('-', 80)); Log.Information("Initializing a session.."); + if (string.IsNullOrEmpty(info.WorkingDirectory)) + throw new Exception("Working directory was invalid"); + Reloaded.Hooks.Tools.Utilities.FasmBasePath = new DirectoryInfo(info.WorkingDirectory); // This is due to GitHub not supporting TLS 1.0, so we enable all TLS versions globally diff --git a/Dalamud/Game/ChatHandlers.cs b/Dalamud/Game/ChatHandlers.cs index 896d296fc..d2f4b30c7 100644 --- a/Dalamud/Game/ChatHandlers.cs +++ b/Dalamud/Game/ChatHandlers.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -14,8 +13,6 @@ using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Interface.Internal; using Dalamud.Interface.Internal.Notifications; using Dalamud.Interface.Internal.Windows; -using Dalamud.IoC; -using Dalamud.IoC.Internal; using Dalamud.Plugin.Internal; using Dalamud.Utility; using Serilog; @@ -104,6 +101,9 @@ internal class ChatHandlers : IServiceType private readonly DalamudLinkPayload openInstallerWindowLink; + [ServiceManager.ServiceDependency] + private readonly Dalamud dalamud = Service.Get(); + [ServiceManager.ServiceDependency] private readonly DalamudConfiguration configuration = Service.Get(); @@ -160,7 +160,6 @@ internal class ChatHandlers : IServiceType private void OnChatMessage(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled) { - var startInfo = Service.Get(); var clientState = Service.GetNullable(); if (clientState == null) return; @@ -182,7 +181,7 @@ internal class ChatHandlers : IServiceType if (type == XivChatType.RetainerSale) { - foreach (var regex in this.retainerSaleRegexes[startInfo.Language]) + foreach (var regex in this.retainerSaleRegexes[(ClientLanguage)this.dalamud.StartInfo.Language]) { var matchInfo = regex.Match(message.TextValue); diff --git a/Dalamud/Game/ClientState/ClientState.cs b/Dalamud/Game/ClientState/ClientState.cs index ccb87ff0e..3b3f65128 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(TargetSigScanner sigScanner, DalamudStartInfo startInfo, GameLifecycle lifecycle) + private ClientState(TargetSigScanner sigScanner, Dalamud dalamud, GameLifecycle lifecycle) { this.lifecycle = lifecycle; this.address = new ClientStateAddressResolver(); @@ -49,7 +49,7 @@ internal sealed class ClientState : IDisposable, IServiceType, IClientState Log.Verbose("===== C L I E N T S T A T E ====="); - this.ClientLanguage = startInfo.Language; + this.ClientLanguage = (ClientLanguage)dalamud.StartInfo.Language; Log.Verbose($"SetupTerritoryType address 0x{this.address.SetupTerritoryType.ToInt64():X}"); diff --git a/Dalamud/Game/Command/CommandManager.cs b/Dalamud/Game/Command/CommandManager.cs index 218b89676..6b67f1892 100644 --- a/Dalamud/Game/Command/CommandManager.cs +++ b/Dalamud/Game/Command/CommandManager.cs @@ -35,15 +35,15 @@ internal sealed class CommandManager : IServiceType, IDisposable, ICommandManage private readonly ChatGui chatGui = Service.Get(); [ServiceManager.ServiceConstructor] - private CommandManager(DalamudStartInfo startInfo) + private CommandManager(Dalamud dalamud) { - this.currentLangCommandRegex = startInfo.Language switch + this.currentLangCommandRegex = (ClientLanguage)dalamud.StartInfo.Language switch { ClientLanguage.Japanese => this.commandRegexJp, ClientLanguage.English => this.commandRegexEn, ClientLanguage.German => this.commandRegexDe, ClientLanguage.French => this.commandRegexFr, - _ => this.currentLangCommandRegex, + _ => this.commandRegexEn, }; this.chatGui.CheckMessageHandled += this.OnCheckMessageHandled; diff --git a/Dalamud/Interface/Internal/DalamudInterface.cs b/Dalamud/Interface/Internal/DalamudInterface.cs index cfaae485a..9e4c215b3 100644 --- a/Dalamud/Interface/Internal/DalamudInterface.cs +++ b/Dalamud/Interface/Internal/DalamudInterface.cs @@ -635,9 +635,7 @@ internal class DalamudInterface : IDisposable, IServiceType ImGui.EndMenu(); } - - var startInfo = Service.Get(); - + var logSynchronously = configuration.LogSynchronously; if (ImGui.MenuItem("Log Synchronously", null, ref logSynchronously)) { @@ -645,10 +643,10 @@ internal class DalamudInterface : IDisposable, IServiceType configuration.QueueSave(); EntryPoint.InitLogging( - startInfo.LogPath!, - startInfo.BootShowConsole, + dalamud.StartInfo.LogPath!, + dalamud.StartInfo.BootShowConsole, configuration.LogSynchronously, - startInfo.LogName); + dalamud.StartInfo.LogName); } var antiDebug = Service.Get(); @@ -767,7 +765,7 @@ internal class DalamudInterface : IDisposable, IServiceType } ImGui.MenuItem(Util.AssemblyVersion, false); - ImGui.MenuItem(startInfo.GameVersion?.ToString() ?? "Unknown version", false); + ImGui.MenuItem(dalamud.StartInfo.GameVersion?.ToString() ?? "Unknown version", false); ImGui.MenuItem($"D: {Util.GetGitHash()}[{Util.GetGitCommitCount()}] CS: {Util.GetGitHashClientStructs()}[{FFXIVClientStructs.Interop.Resolver.Version}]", false); ImGui.MenuItem($"CLR: {Environment.Version}", false); diff --git a/Dalamud/Interface/Internal/InterfaceManager.cs b/Dalamud/Interface/Internal/InterfaceManager.cs index d00f33180..dd85f1db4 100644 --- a/Dalamud/Interface/Internal/InterfaceManager.cs +++ b/Dalamud/Interface/Internal/InterfaceManager.cs @@ -563,10 +563,10 @@ internal class InterfaceManager : IDisposable, IServiceType return; } - var startInfo = Service.Get(); + var startInfo = Service.Get().StartInfo; var configuration = Service.Get(); - var iniFileInfo = new FileInfo(Path.Combine(Path.GetDirectoryName(startInfo.ConfigurationPath), "dalamudUI.ini")); + var iniFileInfo = new FileInfo(Path.Combine(Path.GetDirectoryName(startInfo.ConfigurationPath)!, "dalamudUI.ini")); try { diff --git a/Dalamud/Interface/Internal/TextureManager.cs b/Dalamud/Interface/Internal/TextureManager.cs index 7c773bd36..9fecf74f4 100644 --- a/Dalamud/Interface/Internal/TextureManager.cs +++ b/Dalamud/Interface/Internal/TextureManager.cs @@ -39,7 +39,8 @@ internal class TextureManager : IDisposable, IServiceType, ITextureProvider, ITe private readonly Framework framework; private readonly DataManager dataManager; private readonly InterfaceManager im; - private readonly DalamudStartInfo startInfo; + + private readonly ClientLanguage language; private readonly Dictionary activeTextures = new(); @@ -48,17 +49,18 @@ internal class TextureManager : IDisposable, IServiceType, ITextureProvider, ITe /// /// Initializes a new instance of the class. /// + /// Dalamud instance. /// Framework instance. /// DataManager instance. /// InterfaceManager instance. - /// DalamudStartInfo instance. [ServiceManager.ServiceConstructor] - public TextureManager(Framework framework, DataManager dataManager, InterfaceManager im, DalamudStartInfo startInfo) + public TextureManager(Dalamud dalamud, Framework framework, DataManager dataManager, InterfaceManager im) { this.framework = framework; this.dataManager = dataManager; this.im = im; - this.startInfo = startInfo; + + this.language = (ClientLanguage)dalamud.StartInfo.Language; this.framework.Update += this.FrameworkOnUpdate; @@ -115,7 +117,7 @@ internal class TextureManager : IDisposable, IServiceType, ITextureProvider, ITe if (this.dataManager.FileExists(path)) return path; - language ??= this.startInfo.Language; + language ??= this.language; var languageFolder = language switch { ClientLanguage.Japanese => "ja/", diff --git a/Dalamud/Interface/Internal/Windows/BranchSwitcherWindow.cs b/Dalamud/Interface/Internal/Windows/BranchSwitcherWindow.cs index 05d8d04e8..dcde7d008 100644 --- a/Dalamud/Interface/Internal/Windows/BranchSwitcherWindow.cs +++ b/Dalamud/Interface/Internal/Windows/BranchSwitcherWindow.cs @@ -66,7 +66,7 @@ public class BranchSwitcherWindow : Window return; } - var si = Service.Get(); + var si = Service.Get().StartInfo; var itemsArray = this.branches.Select(x => x.Key).ToArray(); ImGui.ListBox("Branch", ref this.selectedBranchIndex, itemsArray, itemsArray.Length); diff --git a/Dalamud/Interface/Internal/Windows/Data/Widgets/StartInfoWidget.cs b/Dalamud/Interface/Internal/Windows/Data/Widgets/StartInfoWidget.cs index 65ed65e03..4dee316c5 100644 --- a/Dalamud/Interface/Internal/Windows/Data/Widgets/StartInfoWidget.cs +++ b/Dalamud/Interface/Internal/Windows/Data/Widgets/StartInfoWidget.cs @@ -26,7 +26,7 @@ internal class StartInfoWidget : IDataWindowWidget /// public void Draw() { - var startInfo = Service.Get(); + var startInfo = Service.Get().StartInfo; ImGui.Text(JsonConvert.SerializeObject(startInfo, Formatting.Indented)); } diff --git a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs index 6e2ad862c..7ff2f61e0 100644 --- a/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs +++ b/Dalamud/Interface/Internal/Windows/PluginInstaller/PluginInstallerWindow.cs @@ -1994,7 +1994,6 @@ internal class PluginInstallerWindow : Window, IDisposable { var configuration = Service.Get(); var pluginManager = Service.Get(); - var startInfo = Service.Get(); if (ImGui.BeginPopupContextItem("ItemContextMenu")) { @@ -2022,10 +2021,10 @@ internal class PluginInstallerWindow : Window, IDisposable Task.Run(() => { pluginManager.PluginConfigs.Delete(manifest.InternalName); + var dir = pluginManager.PluginConfigs.GetDirectory(manifest.InternalName); - var path = Path.Combine(startInfo.PluginDirectory, manifest.InternalName); - if (Directory.Exists(path)) - Directory.Delete(path, true); + if (Directory.Exists(dir)) + Directory.Delete(dir, true); }) .ContinueWith(task => { diff --git a/Dalamud/Plugin/Internal/PluginManager.cs b/Dalamud/Plugin/Internal/PluginManager.cs index 49608ac9b..dc658792c 100644 --- a/Dalamud/Plugin/Internal/PluginManager.cs +++ b/Dalamud/Plugin/Internal/PluginManager.cs @@ -74,7 +74,7 @@ internal partial class PluginManager : IDisposable, IServiceType private readonly DalamudConfiguration configuration = Service.Get(); [ServiceManager.ServiceDependency] - private readonly DalamudStartInfo startInfo = Service.Get(); + private readonly Dalamud dalamud = Service.Get(); [ServiceManager.ServiceDependency] private readonly ProfileManager profileManager = Service.Get(); @@ -90,12 +90,12 @@ internal partial class PluginManager : IDisposable, IServiceType [ServiceManager.ServiceConstructor] private PluginManager() { - this.pluginDirectory = new DirectoryInfo(this.startInfo.PluginDirectory!); + this.pluginDirectory = new DirectoryInfo(this.dalamud.StartInfo.PluginDirectory!); if (!this.pluginDirectory.Exists) this.pluginDirectory.Create(); - this.SafeMode = EnvironmentConfiguration.DalamudNoPlugins || this.configuration.PluginSafeMode || this.startInfo.NoLoadPlugins; + this.SafeMode = EnvironmentConfiguration.DalamudNoPlugins || this.configuration.PluginSafeMode || this.dalamud.StartInfo.NoLoadPlugins; try { @@ -119,9 +119,9 @@ internal partial class PluginManager : IDisposable, IServiceType this.configuration.QueueSave(); } - this.PluginConfigs = new PluginConfigurations(Path.Combine(Path.GetDirectoryName(this.startInfo.ConfigurationPath) ?? string.Empty, "pluginConfigs")); + this.PluginConfigs = new PluginConfigurations(Path.Combine(Path.GetDirectoryName(this.dalamud.StartInfo.ConfigurationPath) ?? string.Empty, "pluginConfigs")); - var bannedPluginsJson = File.ReadAllText(Path.Combine(this.startInfo.AssetDirectory!, "UIRes", "bannedplugin.json")); + var bannedPluginsJson = File.ReadAllText(Path.Combine(this.dalamud.StartInfo.AssetDirectory!, "UIRes", "bannedplugin.json")); this.bannedPlugins = JsonConvert.DeserializeObject(bannedPluginsJson); if (this.bannedPlugins == null) { @@ -1168,7 +1168,7 @@ internal partial class PluginManager : IDisposable, IServiceType } // Applicable version - if (manifest.ApplicableVersion < this.startInfo.GameVersion) + if (manifest.ApplicableVersion < this.dalamud.StartInfo.GameVersion) { Log.Verbose($"Game version: {manifest.InternalName} - {manifest.AssemblyVersion} - {manifest.TestingAssemblyVersion}"); return false; diff --git a/Dalamud/Plugin/Internal/Types/LocalPlugin.cs b/Dalamud/Plugin/Internal/Types/LocalPlugin.cs index 80d6edfd3..57bea0f57 100644 --- a/Dalamud/Plugin/Internal/Types/LocalPlugin.cs +++ b/Dalamud/Plugin/Internal/Types/LocalPlugin.cs @@ -1,10 +1,10 @@ -using System; using System.IO; using System.Linq; using System.Reflection; using System.Threading; using System.Threading.Tasks; +using Dalamud.Common.Game; using Dalamud.Configuration.Internal; using Dalamud.Game; using Dalamud.Game.Gui.Dtr; @@ -336,7 +336,7 @@ internal class LocalPlugin : IDisposable var framework = await Service.GetAsync(); var ioc = await Service.GetAsync(); var pluginManager = await Service.GetAsync(); - var startInfo = await Service.GetAsync(); + var dalamud = await Service.GetAsync(); // UiBuilder constructor requires the following two. await Service.GetAsync(); @@ -392,7 +392,7 @@ internal class LocalPlugin : IDisposable if (pluginManager.IsManifestBanned(this.manifest) && !this.IsDev) throw new BannedPluginException($"Unable to load {this.Name}, banned"); - if (this.manifest.ApplicableVersion < startInfo.GameVersion) + if (this.manifest.ApplicableVersion < dalamud.StartInfo.GameVersion) throw new InvalidPluginOperationException($"Unable to load {this.Name}, no applicable version"); if (this.manifest.DalamudApiLevel < PluginManager.DalamudApiLevel && !pluginManager.LoadAllApiLevels) @@ -624,7 +624,7 @@ internal class LocalPlugin : IDisposable /// Whether or not this plugin shouldn't load. public bool CheckPolicy() { - var startInfo = Service.Get(); + var startInfo = Service.Get().StartInfo; var manager = Service.Get(); if (startInfo.NoLoadPlugins) diff --git a/Dalamud/Plugin/Internal/Types/PluginManifest.cs b/Dalamud/Plugin/Internal/Types/PluginManifest.cs index 0b5ec26fc..34fa04f6e 100644 --- a/Dalamud/Plugin/Internal/Types/PluginManifest.cs +++ b/Dalamud/Plugin/Internal/Types/PluginManifest.cs @@ -1,7 +1,6 @@ -using System; using System.Collections.Generic; -using Dalamud.Game; +using Dalamud.Common.Game; using Dalamud.Plugin.Internal.Types.Manifest; using Newtonsoft.Json; diff --git a/Dalamud/ServiceManager.cs b/Dalamud/ServiceManager.cs index bb680127c..e8512e854 100644 --- a/Dalamud/ServiceManager.cs +++ b/Dalamud/ServiceManager.cs @@ -1,7 +1,5 @@ -using System; using System.Collections.Generic; using System.Diagnostics; -using System.IO; using System.Linq; using System.Reflection; using System.Threading; @@ -83,16 +81,11 @@ internal static class ServiceManager /// Initializes Provided Services and FFXIVClientStructs. /// /// Instance of . - /// Instance of . /// Instance of . /// Instance of . - public static void InitializeProvidedServicesAndClientStructs(Dalamud dalamud, DalamudStartInfo startInfo, ReliableFileStorage fs, DalamudConfiguration configuration) + /// Instance of . + public static void InitializeProvidedServices(Dalamud dalamud, ReliableFileStorage fs, DalamudConfiguration configuration, TargetSigScanner scanner) { - // Initialize the process information. - var cacheDir = new DirectoryInfo(Path.Combine(startInfo.WorkingDirectory!, "cachedSigs")); - if (!cacheDir.Exists) - cacheDir.Create(); - lock (LoadedServices) { void ProvideService(T service) where T : IServiceType @@ -103,19 +96,10 @@ internal static class ServiceManager } ProvideService(dalamud); - ProvideService(startInfo); ProvideService(fs); ProvideService(configuration); ProvideService(new ServiceContainer()); - ProvideService( - new TargetSigScanner( - true, new FileInfo(Path.Combine(cacheDir.FullName, $"{startInfo.GameVersion}.json")))); - } - - 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.Resolve(); + ProvideService(scanner); } } diff --git a/Dalamud/Support/Troubleshooting.cs b/Dalamud/Support/Troubleshooting.cs index 9893451f4..59ebcaa16 100644 --- a/Dalamud/Support/Troubleshooting.cs +++ b/Dalamud/Support/Troubleshooting.cs @@ -58,7 +58,7 @@ public static class Troubleshooting /// internal static void LogTroubleshooting() { - var startInfo = Service.Get(); + var startInfo = Service.Get().StartInfo; var configuration = Service.Get(); var interfaceManager = Service.GetNullable(); var pluginManager = Service.GetNullable(); @@ -72,7 +72,7 @@ public static class Troubleshooting EverStartedLoadingPlugins = pluginManager?.InstalledPlugins.Where(x => x.HasEverStartedLoad).Select(x => x.InternalName).ToList(), DalamudVersion = Util.AssemblyVersion, DalamudGitHash = Util.GetGitHash(), - GameVersion = startInfo.GameVersion.ToString(), + GameVersion = startInfo.GameVersion?.ToString() ?? "Unknown", Language = startInfo.Language.ToString(), BetaKey = configuration.DalamudBetaKey, DoPluginTest = configuration.DoPluginTest,