chore: tidy-up, move files shared between dalamud and injector into separate assembly

This commit is contained in:
goat 2023-09-30 16:11:52 +02:00
parent 6f99cfe48c
commit f44c6794e7
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
29 changed files with 174 additions and 129 deletions

View file

@ -0,0 +1,27 @@
namespace Dalamud.Common;
/// <summary>
/// Enum describing the language the game loads in.
/// </summary>
public enum ClientLanguage
{
/// <summary>
/// Indicating a Japanese game client.
/// </summary>
Japanese,
/// <summary>
/// Indicating an English game client.
/// </summary>
English,
/// <summary>
/// Indicating a German game client.
/// </summary>
German,
/// <summary>
/// Indicating a French game client.
/// </summary>
French,
}

View file

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>
</Project>

View file

@ -1,17 +1,13 @@
using System; using Dalamud.Common.Game;
using System.Collections.Generic;
using Dalamud.Game;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Dalamud; namespace Dalamud.Common;
/// <summary> /// <summary>
/// Struct containing information needed to initialize Dalamud. /// Struct containing information needed to initialize Dalamud.
/// </summary> /// </summary>
[Serializable] [Serializable]
[ServiceManager.Service] public record DalamudStartInfo
public record DalamudStartInfo : IServiceType
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="DalamudStartInfo"/> class. /// Initializes a new instance of the <see cref="DalamudStartInfo"/> class.
@ -97,7 +93,7 @@ public record DalamudStartInfo : IServiceType
/// <summary> /// <summary>
/// Gets or sets troubleshooting information to attach when generating a tspack file. /// Gets or sets troubleshooting information to attach when generating a tspack file.
/// </summary> /// </summary>
public string TroubleshootingPackData { get; set; } public string? TroubleshootingPackData { get; set; }
/// <summary> /// <summary>
/// Gets or sets a value that specifies how much to wait before a new Dalamud session. /// Gets or sets a value that specifies how much to wait before a new Dalamud session.

View file

@ -1,11 +1,9 @@
using System;
using System.Globalization; using System.Globalization;
using System.Linq;
using System.Text; using System.Text;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Dalamud.Game; namespace Dalamud.Common.Game;
/// <summary> /// <summary>
/// A GameVersion object contains give hierarchical numeric components: year, month, /// A GameVersion object contains give hierarchical numeric components: year, month,
@ -168,14 +166,14 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
return Parse(ver); return Parse(ver);
} }
public static bool operator ==(GameVersion v1, GameVersion v2) public static bool operator ==(GameVersion? v1, GameVersion? v2)
{ {
if (v1 is null) if (v1 is null)
{ {
return v2 is null; return v2 is null;
} }
return v1.Equals(v2); return v2 is not null && v1.Equals(v2);
} }
public static bool operator !=(GameVersion v1, GameVersion v2) public static bool operator !=(GameVersion v1, GameVersion v2)
@ -290,7 +288,7 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
} }
catch catch
{ {
result = null; result = null!;
return false; return false;
} }
} }
@ -299,7 +297,7 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
public object Clone() => new GameVersion(this.Year, this.Month, this.Day, this.Major, this.Minor); public object Clone() => new GameVersion(this.Year, this.Month, this.Day, this.Major, this.Minor);
/// <inheritdoc/> /// <inheritdoc/>
public int CompareTo(object obj) public int CompareTo(object? obj)
{ {
if (obj == null) if (obj == null)
return 1; return 1;
@ -315,7 +313,7 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
} }
/// <inheritdoc/> /// <inheritdoc/>
public int CompareTo(GameVersion value) public int CompareTo(GameVersion? value)
{ {
if (value == null) if (value == null)
return 1; return 1;
@ -348,7 +346,7 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
} }
/// <inheritdoc/> /// <inheritdoc/>
public override bool Equals(object obj) public override bool Equals(object? obj)
{ {
if (obj is not GameVersion value) if (obj is not GameVersion value)
return false; return false;
@ -357,7 +355,7 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
} }
/// <inheritdoc/> /// <inheritdoc/>
public bool Equals(GameVersion value) public bool Equals(GameVersion? value)
{ {
if (value == null) if (value == null)
{ {

View file

@ -1,8 +1,6 @@
using System;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace Dalamud.Game; namespace Dalamud.Common.Game;
/// <summary> /// <summary>
/// Converts a <see cref="GameVersion"/> to and from a string (e.g. <c>"2010.01.01.1234.5678"</c>). /// Converts a <see cref="GameVersion"/> to and from a string (e.g. <c>"2010.01.01.1234.5678"</c>).

View file

@ -81,12 +81,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<!-- This prevents us from having to include Dalamud itself as a dependency --> <ProjectReference Include="..\Dalamud.Common\Dalamud.Common.csproj" />
<!-- If the files move just update the paths here -->
<Compile Include="..\Dalamud\ClientLanguage.cs" Link="Included\%(Filename)%(Extension)" />
<Compile Include="..\Dalamud\IServiceType.cs" Link="Included\%(Filename)%(Extension)" />
<Compile Include="..\Dalamud\DalamudStartInfo.cs" Link="Included\%(Filename)%(Extension)" />
<Compile Include="..\Dalamud\Game\GameVersion.cs" Link="Included\Game\%(Filename)%(Extension)" />
<Compile Include="..\Dalamud\Game\GameVersionConverter.cs" Link="Included\Game\%(Filename)%(Extension)" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View file

@ -9,7 +9,8 @@ using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Dalamud.Game; using Dalamud.Common;
using Dalamud.Common.Game;
using Newtonsoft.Json; using Newtonsoft.Json;
using Reloaded.Memory.Buffers; using Reloaded.Memory.Buffers;
using Serilog; using Serilog;

View file

@ -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
/// <summary>
/// Class to initialize Service&lt;T&gt;s.
/// </summary>
internal static class ServiceManager
{
/// <summary>
/// Indicates that the class is a service.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
public class Service : Attribute
{
}
}

View file

@ -1,4 +1,4 @@
using Dalamud.Game; using Dalamud.Common.Game;
using Xunit; using Xunit;
namespace Dalamud.Test.Game namespace Dalamud.Test.Game

View file

@ -38,6 +38,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FFXIVClientStructs.InteropS
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DalamudCrashHandler", "DalamudCrashHandler\DalamudCrashHandler.vcxproj", "{317A264C-920B-44A1-8A34-F3A6827B0705}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DalamudCrashHandler", "DalamudCrashHandler\DalamudCrashHandler.vcxproj", "{317A264C-920B-44A1-8A34-F3A6827B0705}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dalamud.Common", "Dalamud.Common\Dalamud.Common.csproj", "{F21B13D2-D7D0-4456-B70F-3F8D695064E2}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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|x64.Build.0 = Release|x64
{317A264C-920B-44A1-8A34-F3A6827B0705}.Release|x86.ActiveCfg = Release|x64 {317A264C-920B-44A1-8A34-F3A6827B0705}.Release|x86.ActiveCfg = Release|x64
{317A264C-920B-44A1-8A34-F3A6827B0705}.Release|x86.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View file

@ -1,5 +1,7 @@
namespace Dalamud; namespace Dalamud;
// TODO(v10): Delete this, and use Dalamud.Common.ClientLanguage instead for everything.
/// <summary> /// <summary>
/// Enum describing the language the game loads in. /// Enum describing the language the game loads in.
/// </summary> /// </summary>

View file

@ -1,4 +1,3 @@
using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -7,6 +6,7 @@ using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dalamud.Common;
using Dalamud.Configuration.Internal; using Dalamud.Configuration.Internal;
using Dalamud.Game; using Dalamud.Game;
using Dalamud.Game.Gui.Internal; using Dalamud.Game.Gui.Internal;
@ -14,6 +14,7 @@ using Dalamud.Interface.Internal;
using Dalamud.Plugin.Internal; using Dalamud.Plugin.Internal;
using Dalamud.Storage; using Dalamud.Storage;
using Dalamud.Utility; using Dalamud.Utility;
using Dalamud.Utility.Timing;
using PInvoke; using PInvoke;
using Serilog; using Serilog;
@ -47,10 +48,28 @@ internal sealed class Dalamud : IServiceType
/// <param name="mainThreadContinueEvent">Event used to signal the main thread to continue.</param> /// <param name="mainThreadContinueEvent">Event used to signal the main thread to continue.</param>
public Dalamud(DalamudStartInfo info, ReliableFileStorage fs, DalamudConfiguration configuration, IntPtr mainThreadContinueEvent) public Dalamud(DalamudStartInfo info, ReliableFileStorage fs, DalamudConfiguration configuration, IntPtr mainThreadContinueEvent)
{ {
this.StartInfo = info;
this.unloadSignal = new ManualResetEvent(false); this.unloadSignal = new ManualResetEvent(false);
this.unloadSignal.Reset(); 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) if (!configuration.IsResumeGameAfterPluginLoad)
{ {
@ -97,11 +116,16 @@ internal sealed class Dalamud : IServiceType
}); });
} }
} }
/// <summary>
/// Gets the start information for this Dalamud instance.
/// </summary>
internal DalamudStartInfo StartInfo { get; private set; }
/// <summary> /// <summary>
/// Gets location of stored assets. /// Gets location of stored assets.
/// </summary> /// </summary>
internal DirectoryInfo AssetDirectory => new(Service<DalamudStartInfo>.Get().AssetDirectory!); internal DirectoryInfo AssetDirectory => new(this.StartInfo.AssetDirectory!);
/// <summary> /// <summary>
/// Signal to the crash handler process that we should restart the game. /// 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); var oldFilter = NativeFunctions.SetUnhandledExceptionFilter(releaseFilter);
Log.Debug("Reset ExceptionFilter, old: {0}", oldFilter); Log.Debug("Reset ExceptionFilter, old: {0}", oldFilter);
} }
private void SetupClientStructsResolver(DirectoryInfo cacheDir)
{
using (Timings.Start("CS Resolver Init"))
{
FFXIVClientStructs.Interop.Resolver.GetInstance.SetupSearchSpace(Service<TargetSigScanner>.Get().SearchBase, new FileInfo(Path.Combine(cacheDir.FullName, $"{this.StartInfo.GameVersion}_cs.json")));
FFXIVClientStructs.Interop.Resolver.GetInstance.Resolve();
}
}
} }

View file

@ -89,6 +89,7 @@
<PackageReference Include="System.Resources.Extensions" Version="7.0.0" /> <PackageReference Include="System.Resources.Extensions" Version="7.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Dalamud.Common\Dalamud.Common.csproj" />
<ProjectReference Include="..\lib\FFXIVClientStructs\FFXIVClientStructs\FFXIVClientStructs.csproj" /> <ProjectReference Include="..\lib\FFXIVClientStructs\FFXIVClientStructs\FFXIVClientStructs.csproj" />
<ProjectReference Include="..\lib\ImGuiScene\deps\ImGui.NET\src\ImGui.NET-472\ImGui.NET-472.csproj" /> <ProjectReference Include="..\lib\ImGuiScene\deps\ImGui.NET\src\ImGui.NET-472\ImGui.NET-472.csproj" />
<ProjectReference Include="..\lib\ImGuiScene\deps\SDL2-CS\SDL2-CS.csproj" /> <ProjectReference Include="..\lib\ImGuiScene\deps\SDL2-CS\SDL2-CS.csproj" />

View file

@ -7,6 +7,7 @@ using System.Threading;
using Dalamud.IoC; using Dalamud.IoC;
using Dalamud.IoC.Internal; using Dalamud.IoC.Internal;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using Dalamud.Utility;
using Dalamud.Utility.Timing; using Dalamud.Utility.Timing;
using JetBrains.Annotations; using JetBrains.Annotations;
using Lumina; using Lumina;
@ -32,9 +33,9 @@ internal sealed class DataManager : IDisposable, IServiceType, IDataManager
private readonly CancellationTokenSource luminaCancellationTokenSource; private readonly CancellationTokenSource luminaCancellationTokenSource;
[ServiceManager.ServiceConstructor] [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. // Set up default values so plugins do not null-reference when data is being loaded.
this.ClientOpCodes = this.ServerOpCodes = new ReadOnlyDictionary<string, ushort>(new Dictionary<string, ushort>()); this.ClientOpCodes = this.ServerOpCodes = new ReadOnlyDictionary<string, ushort>(new Dictionary<string, ushort>());
@ -82,17 +83,20 @@ internal sealed class DataManager : IDisposable, IServiceType, IDataManager
Log.Information("Lumina is ready: {0}", this.GameData.DataPath); Log.Information("Lumina is ready: {0}", this.GameData.DataPath);
try if (!dalamud.StartInfo.TroubleshootingPackData.IsNullOrEmpty())
{ {
var tsInfo = try
JsonConvert.DeserializeObject<LauncherTroubleshootingInfo>( {
dalamudStartInfo.TroubleshootingPackData); var tsInfo =
this.HasModifiedGameDataFiles = JsonConvert.DeserializeObject<LauncherTroubleshootingInfo>(
tsInfo?.IndexIntegrity is LauncherTroubleshootingInfo.IndexIntegrityResult.Failed or LauncherTroubleshootingInfo.IndexIntegrityResult.Exception; dalamud.StartInfo.TroubleshootingPackData);
} this.HasModifiedGameDataFiles =
catch tsInfo?.IndexIntegrity is LauncherTroubleshootingInfo.IndexIntegrityResult.Failed or LauncherTroubleshootingInfo.IndexIntegrityResult.Exception;
{ }
// ignored catch
{
// ignored
}
} }
} }

View file

@ -1,4 +1,3 @@
using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Net; using System.Net;
@ -6,6 +5,7 @@ using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dalamud.Common;
using Dalamud.Configuration.Internal; using Dalamud.Configuration.Internal;
using Dalamud.Logging.Internal; using Dalamud.Logging.Internal;
using Dalamud.Logging.Retention; using Dalamud.Logging.Retention;
@ -163,6 +163,9 @@ public sealed class EntryPoint
Log.Information(new string('-', 80)); Log.Information(new string('-', 80));
Log.Information("Initializing a session.."); 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); 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 // This is due to GitHub not supporting TLS 1.0, so we enable all TLS versions globally

View file

@ -1,4 +1,3 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
@ -14,8 +13,6 @@ using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Interface.Internal; using Dalamud.Interface.Internal;
using Dalamud.Interface.Internal.Notifications; using Dalamud.Interface.Internal.Notifications;
using Dalamud.Interface.Internal.Windows; using Dalamud.Interface.Internal.Windows;
using Dalamud.IoC;
using Dalamud.IoC.Internal;
using Dalamud.Plugin.Internal; using Dalamud.Plugin.Internal;
using Dalamud.Utility; using Dalamud.Utility;
using Serilog; using Serilog;
@ -104,6 +101,9 @@ internal class ChatHandlers : IServiceType
private readonly DalamudLinkPayload openInstallerWindowLink; private readonly DalamudLinkPayload openInstallerWindowLink;
[ServiceManager.ServiceDependency]
private readonly Dalamud dalamud = Service<Dalamud>.Get();
[ServiceManager.ServiceDependency] [ServiceManager.ServiceDependency]
private readonly DalamudConfiguration configuration = Service<DalamudConfiguration>.Get(); private readonly DalamudConfiguration configuration = Service<DalamudConfiguration>.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) private void OnChatMessage(XivChatType type, uint senderId, ref SeString sender, ref SeString message, ref bool isHandled)
{ {
var startInfo = Service<DalamudStartInfo>.Get();
var clientState = Service<ClientState.ClientState>.GetNullable(); var clientState = Service<ClientState.ClientState>.GetNullable();
if (clientState == null) if (clientState == null)
return; return;
@ -182,7 +181,7 @@ internal class ChatHandlers : IServiceType
if (type == XivChatType.RetainerSale) 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); var matchInfo = regex.Match(message.TextValue);

View file

@ -41,7 +41,7 @@ internal sealed class ClientState : IDisposable, IServiceType, IClientState
private bool lastFramePvP; private bool lastFramePvP;
[ServiceManager.ServiceConstructor] [ServiceManager.ServiceConstructor]
private ClientState(TargetSigScanner sigScanner, DalamudStartInfo startInfo, GameLifecycle lifecycle) private ClientState(TargetSigScanner sigScanner, Dalamud dalamud, GameLifecycle lifecycle)
{ {
this.lifecycle = lifecycle; this.lifecycle = lifecycle;
this.address = new ClientStateAddressResolver(); 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 ====="); 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}"); Log.Verbose($"SetupTerritoryType address 0x{this.address.SetupTerritoryType.ToInt64():X}");

View file

@ -35,15 +35,15 @@ internal sealed class CommandManager : IServiceType, IDisposable, ICommandManage
private readonly ChatGui chatGui = Service<ChatGui>.Get(); private readonly ChatGui chatGui = Service<ChatGui>.Get();
[ServiceManager.ServiceConstructor] [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.Japanese => this.commandRegexJp,
ClientLanguage.English => this.commandRegexEn, ClientLanguage.English => this.commandRegexEn,
ClientLanguage.German => this.commandRegexDe, ClientLanguage.German => this.commandRegexDe,
ClientLanguage.French => this.commandRegexFr, ClientLanguage.French => this.commandRegexFr,
_ => this.currentLangCommandRegex, _ => this.commandRegexEn,
}; };
this.chatGui.CheckMessageHandled += this.OnCheckMessageHandled; this.chatGui.CheckMessageHandled += this.OnCheckMessageHandled;

View file

@ -635,9 +635,7 @@ internal class DalamudInterface : IDisposable, IServiceType
ImGui.EndMenu(); ImGui.EndMenu();
} }
var startInfo = Service<DalamudStartInfo>.Get();
var logSynchronously = configuration.LogSynchronously; var logSynchronously = configuration.LogSynchronously;
if (ImGui.MenuItem("Log Synchronously", null, ref logSynchronously)) if (ImGui.MenuItem("Log Synchronously", null, ref logSynchronously))
{ {
@ -645,10 +643,10 @@ internal class DalamudInterface : IDisposable, IServiceType
configuration.QueueSave(); configuration.QueueSave();
EntryPoint.InitLogging( EntryPoint.InitLogging(
startInfo.LogPath!, dalamud.StartInfo.LogPath!,
startInfo.BootShowConsole, dalamud.StartInfo.BootShowConsole,
configuration.LogSynchronously, configuration.LogSynchronously,
startInfo.LogName); dalamud.StartInfo.LogName);
} }
var antiDebug = Service<AntiDebug>.Get(); var antiDebug = Service<AntiDebug>.Get();
@ -767,7 +765,7 @@ internal class DalamudInterface : IDisposable, IServiceType
} }
ImGui.MenuItem(Util.AssemblyVersion, false); 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($"D: {Util.GetGitHash()}[{Util.GetGitCommitCount()}] CS: {Util.GetGitHashClientStructs()}[{FFXIVClientStructs.Interop.Resolver.Version}]", false);
ImGui.MenuItem($"CLR: {Environment.Version}", false); ImGui.MenuItem($"CLR: {Environment.Version}", false);

View file

@ -563,10 +563,10 @@ internal class InterfaceManager : IDisposable, IServiceType
return; return;
} }
var startInfo = Service<DalamudStartInfo>.Get(); var startInfo = Service<Dalamud>.Get().StartInfo;
var configuration = Service<DalamudConfiguration>.Get(); var configuration = Service<DalamudConfiguration>.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 try
{ {

View file

@ -39,7 +39,8 @@ internal class TextureManager : IDisposable, IServiceType, ITextureProvider, ITe
private readonly Framework framework; private readonly Framework framework;
private readonly DataManager dataManager; private readonly DataManager dataManager;
private readonly InterfaceManager im; private readonly InterfaceManager im;
private readonly DalamudStartInfo startInfo;
private readonly ClientLanguage language;
private readonly Dictionary<string, TextureInfo> activeTextures = new(); private readonly Dictionary<string, TextureInfo> activeTextures = new();
@ -48,17 +49,18 @@ internal class TextureManager : IDisposable, IServiceType, ITextureProvider, ITe
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="TextureManager"/> class. /// Initializes a new instance of the <see cref="TextureManager"/> class.
/// </summary> /// </summary>
/// <param name="dalamud">Dalamud instance.</param>
/// <param name="framework">Framework instance.</param> /// <param name="framework">Framework instance.</param>
/// <param name="dataManager">DataManager instance.</param> /// <param name="dataManager">DataManager instance.</param>
/// <param name="im">InterfaceManager instance.</param> /// <param name="im">InterfaceManager instance.</param>
/// <param name="startInfo">DalamudStartInfo instance.</param>
[ServiceManager.ServiceConstructor] [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.framework = framework;
this.dataManager = dataManager; this.dataManager = dataManager;
this.im = im; this.im = im;
this.startInfo = startInfo;
this.language = (ClientLanguage)dalamud.StartInfo.Language;
this.framework.Update += this.FrameworkOnUpdate; this.framework.Update += this.FrameworkOnUpdate;
@ -115,7 +117,7 @@ internal class TextureManager : IDisposable, IServiceType, ITextureProvider, ITe
if (this.dataManager.FileExists(path)) if (this.dataManager.FileExists(path))
return path; return path;
language ??= this.startInfo.Language; language ??= this.language;
var languageFolder = language switch var languageFolder = language switch
{ {
ClientLanguage.Japanese => "ja/", ClientLanguage.Japanese => "ja/",

View file

@ -66,7 +66,7 @@ public class BranchSwitcherWindow : Window
return; return;
} }
var si = Service<DalamudStartInfo>.Get(); var si = Service<Dalamud>.Get().StartInfo;
var itemsArray = this.branches.Select(x => x.Key).ToArray(); var itemsArray = this.branches.Select(x => x.Key).ToArray();
ImGui.ListBox("Branch", ref this.selectedBranchIndex, itemsArray, itemsArray.Length); ImGui.ListBox("Branch", ref this.selectedBranchIndex, itemsArray, itemsArray.Length);

View file

@ -26,7 +26,7 @@ internal class StartInfoWidget : IDataWindowWidget
/// <inheritdoc/> /// <inheritdoc/>
public void Draw() public void Draw()
{ {
var startInfo = Service<DalamudStartInfo>.Get(); var startInfo = Service<Dalamud>.Get().StartInfo;
ImGui.Text(JsonConvert.SerializeObject(startInfo, Formatting.Indented)); ImGui.Text(JsonConvert.SerializeObject(startInfo, Formatting.Indented));
} }

View file

@ -1994,7 +1994,6 @@ internal class PluginInstallerWindow : Window, IDisposable
{ {
var configuration = Service<DalamudConfiguration>.Get(); var configuration = Service<DalamudConfiguration>.Get();
var pluginManager = Service<PluginManager>.Get(); var pluginManager = Service<PluginManager>.Get();
var startInfo = Service<DalamudStartInfo>.Get();
if (ImGui.BeginPopupContextItem("ItemContextMenu")) if (ImGui.BeginPopupContextItem("ItemContextMenu"))
{ {
@ -2022,10 +2021,10 @@ internal class PluginInstallerWindow : Window, IDisposable
Task.Run(() => Task.Run(() =>
{ {
pluginManager.PluginConfigs.Delete(manifest.InternalName); pluginManager.PluginConfigs.Delete(manifest.InternalName);
var dir = pluginManager.PluginConfigs.GetDirectory(manifest.InternalName);
var path = Path.Combine(startInfo.PluginDirectory, manifest.InternalName); if (Directory.Exists(dir))
if (Directory.Exists(path)) Directory.Delete(dir, true);
Directory.Delete(path, true);
}) })
.ContinueWith(task => .ContinueWith(task =>
{ {

View file

@ -74,7 +74,7 @@ internal partial class PluginManager : IDisposable, IServiceType
private readonly DalamudConfiguration configuration = Service<DalamudConfiguration>.Get(); private readonly DalamudConfiguration configuration = Service<DalamudConfiguration>.Get();
[ServiceManager.ServiceDependency] [ServiceManager.ServiceDependency]
private readonly DalamudStartInfo startInfo = Service<DalamudStartInfo>.Get(); private readonly Dalamud dalamud = Service<Dalamud>.Get();
[ServiceManager.ServiceDependency] [ServiceManager.ServiceDependency]
private readonly ProfileManager profileManager = Service<ProfileManager>.Get(); private readonly ProfileManager profileManager = Service<ProfileManager>.Get();
@ -90,12 +90,12 @@ internal partial class PluginManager : IDisposable, IServiceType
[ServiceManager.ServiceConstructor] [ServiceManager.ServiceConstructor]
private PluginManager() private PluginManager()
{ {
this.pluginDirectory = new DirectoryInfo(this.startInfo.PluginDirectory!); this.pluginDirectory = new DirectoryInfo(this.dalamud.StartInfo.PluginDirectory!);
if (!this.pluginDirectory.Exists) if (!this.pluginDirectory.Exists)
this.pluginDirectory.Create(); 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 try
{ {
@ -119,9 +119,9 @@ internal partial class PluginManager : IDisposable, IServiceType
this.configuration.QueueSave(); 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<BannedPlugin[]>(bannedPluginsJson); this.bannedPlugins = JsonConvert.DeserializeObject<BannedPlugin[]>(bannedPluginsJson);
if (this.bannedPlugins == null) if (this.bannedPlugins == null)
{ {
@ -1168,7 +1168,7 @@ internal partial class PluginManager : IDisposable, IServiceType
} }
// Applicable version // 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}"); Log.Verbose($"Game version: {manifest.InternalName} - {manifest.AssemblyVersion} - {manifest.TestingAssemblyVersion}");
return false; return false;

View file

@ -1,10 +1,10 @@
using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Dalamud.Common.Game;
using Dalamud.Configuration.Internal; using Dalamud.Configuration.Internal;
using Dalamud.Game; using Dalamud.Game;
using Dalamud.Game.Gui.Dtr; using Dalamud.Game.Gui.Dtr;
@ -336,7 +336,7 @@ internal class LocalPlugin : IDisposable
var framework = await Service<Framework>.GetAsync(); var framework = await Service<Framework>.GetAsync();
var ioc = await Service<ServiceContainer>.GetAsync(); var ioc = await Service<ServiceContainer>.GetAsync();
var pluginManager = await Service<PluginManager>.GetAsync(); var pluginManager = await Service<PluginManager>.GetAsync();
var startInfo = await Service<DalamudStartInfo>.GetAsync(); var dalamud = await Service<Dalamud>.GetAsync();
// UiBuilder constructor requires the following two. // UiBuilder constructor requires the following two.
await Service<InterfaceManager>.GetAsync(); await Service<InterfaceManager>.GetAsync();
@ -392,7 +392,7 @@ internal class LocalPlugin : IDisposable
if (pluginManager.IsManifestBanned(this.manifest) && !this.IsDev) if (pluginManager.IsManifestBanned(this.manifest) && !this.IsDev)
throw new BannedPluginException($"Unable to load {this.Name}, banned"); 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"); throw new InvalidPluginOperationException($"Unable to load {this.Name}, no applicable version");
if (this.manifest.DalamudApiLevel < PluginManager.DalamudApiLevel && !pluginManager.LoadAllApiLevels) if (this.manifest.DalamudApiLevel < PluginManager.DalamudApiLevel && !pluginManager.LoadAllApiLevels)
@ -624,7 +624,7 @@ internal class LocalPlugin : IDisposable
/// <returns>Whether or not this plugin shouldn't load.</returns> /// <returns>Whether or not this plugin shouldn't load.</returns>
public bool CheckPolicy() public bool CheckPolicy()
{ {
var startInfo = Service<DalamudStartInfo>.Get(); var startInfo = Service<Dalamud>.Get().StartInfo;
var manager = Service<PluginManager>.Get(); var manager = Service<PluginManager>.Get();
if (startInfo.NoLoadPlugins) if (startInfo.NoLoadPlugins)

View file

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Dalamud.Game; using Dalamud.Common.Game;
using Dalamud.Plugin.Internal.Types.Manifest; using Dalamud.Plugin.Internal.Types.Manifest;
using Newtonsoft.Json; using Newtonsoft.Json;

View file

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
@ -83,16 +81,11 @@ internal static class ServiceManager
/// Initializes Provided Services and FFXIVClientStructs. /// Initializes Provided Services and FFXIVClientStructs.
/// </summary> /// </summary>
/// <param name="dalamud">Instance of <see cref="Dalamud"/>.</param> /// <param name="dalamud">Instance of <see cref="Dalamud"/>.</param>
/// <param name="startInfo">Instance of <see cref="DalamudStartInfo"/>.</param>
/// <param name="fs">Instance of <see cref="ReliableFileStorage"/>.</param> /// <param name="fs">Instance of <see cref="ReliableFileStorage"/>.</param>
/// <param name="configuration">Instance of <see cref="DalamudConfiguration"/>.</param> /// <param name="configuration">Instance of <see cref="DalamudConfiguration"/>.</param>
public static void InitializeProvidedServicesAndClientStructs(Dalamud dalamud, DalamudStartInfo startInfo, ReliableFileStorage fs, DalamudConfiguration configuration) /// <param name="scanner">Instance of <see cref="TargetSigScanner"/>.</param>
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) lock (LoadedServices)
{ {
void ProvideService<T>(T service) where T : IServiceType void ProvideService<T>(T service) where T : IServiceType
@ -103,19 +96,10 @@ internal static class ServiceManager
} }
ProvideService(dalamud); ProvideService(dalamud);
ProvideService(startInfo);
ProvideService(fs); ProvideService(fs);
ProvideService(configuration); ProvideService(configuration);
ProvideService(new ServiceContainer()); ProvideService(new ServiceContainer());
ProvideService( ProvideService(scanner);
new TargetSigScanner(
true, new FileInfo(Path.Combine(cacheDir.FullName, $"{startInfo.GameVersion}.json"))));
}
using (Timings.Start("CS Resolver Init"))
{
FFXIVClientStructs.Interop.Resolver.GetInstance.SetupSearchSpace(Service<TargetSigScanner>.Get().SearchBase, new FileInfo(Path.Combine(cacheDir.FullName, $"{startInfo.GameVersion}_cs.json")));
FFXIVClientStructs.Interop.Resolver.GetInstance.Resolve();
} }
} }

View file

@ -58,7 +58,7 @@ public static class Troubleshooting
/// </summary> /// </summary>
internal static void LogTroubleshooting() internal static void LogTroubleshooting()
{ {
var startInfo = Service<DalamudStartInfo>.Get(); var startInfo = Service<Dalamud>.Get().StartInfo;
var configuration = Service<DalamudConfiguration>.Get(); var configuration = Service<DalamudConfiguration>.Get();
var interfaceManager = Service<InterfaceManager>.GetNullable(); var interfaceManager = Service<InterfaceManager>.GetNullable();
var pluginManager = Service<PluginManager>.GetNullable(); var pluginManager = Service<PluginManager>.GetNullable();
@ -72,7 +72,7 @@ public static class Troubleshooting
EverStartedLoadingPlugins = pluginManager?.InstalledPlugins.Where(x => x.HasEverStartedLoad).Select(x => x.InternalName).ToList(), EverStartedLoadingPlugins = pluginManager?.InstalledPlugins.Where(x => x.HasEverStartedLoad).Select(x => x.InternalName).ToList(),
DalamudVersion = Util.AssemblyVersion, DalamudVersion = Util.AssemblyVersion,
DalamudGitHash = Util.GetGitHash(), DalamudGitHash = Util.GetGitHash(),
GameVersion = startInfo.GameVersion.ToString(), GameVersion = startInfo.GameVersion?.ToString() ?? "Unknown",
Language = startInfo.Language.ToString(), Language = startInfo.Language.ToString(),
BetaKey = configuration.DalamudBetaKey, BetaKey = configuration.DalamudBetaKey,
DoPluginTest = configuration.DoPluginTest, DoPluginTest = configuration.DoPluginTest,