Skip to content

Commit

Permalink
chore: tidy-up, move files shared between dalamud and injector into s…
Browse files Browse the repository at this point in the history
…eparate assembly
  • Loading branch information
goaaats committed Sep 30, 2023
1 parent 6f99cfe commit f44c679
Show file tree
Hide file tree
Showing 29 changed files with 174 additions and 129 deletions.
27 changes: 27 additions & 0 deletions Dalamud.Common/ClientLanguage.cs
Original file line number Diff line number Diff line change
@@ -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,
}
13 changes: 13 additions & 0 deletions Dalamud.Common/Dalamud.Common.csproj
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Struct containing information needed to initialize Dalamud.
/// </summary>
[Serializable]
[ServiceManager.Service]
public record DalamudStartInfo : IServiceType
public record DalamudStartInfo
{
/// <summary>
/// Initializes a new instance of the <see cref="DalamudStartInfo"/> class.
Expand Down Expand Up @@ -97,7 +93,7 @@ public DalamudStartInfo(DalamudStartInfo other)
/// <summary>
/// Gets or sets troubleshooting information to attach when generating a tspack file.
/// </summary>
public string TroubleshootingPackData { get; set; }
public string? TroubleshootingPackData { get; set; }

/// <summary>
/// Gets or sets a value that specifies how much to wait before a new Dalamud session.
Expand Down
18 changes: 8 additions & 10 deletions Dalamud/Game/GameVersion.cs → Dalamud.Common/Game/GameVersion.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// A GameVersion object contains give hierarchical numeric components: year, month,
Expand Down Expand Up @@ -168,14 +166,14 @@ public static implicit operator GameVersion(string ver)
return Parse(ver);
}

public static bool operator ==(GameVersion v1, GameVersion v2)
public static bool operator ==(GameVersion? v1, GameVersion? v2)
{
if (v1 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)
Expand Down Expand Up @@ -290,7 +288,7 @@ public static bool TryParse(string input, out GameVersion result)
}
catch
{
result = null;
result = null!;
return false;
}
}
Expand All @@ -299,7 +297,7 @@ public static bool TryParse(string input, out GameVersion result)
public object Clone() => new GameVersion(this.Year, this.Month, this.Day, this.Major, this.Minor);

/// <inheritdoc/>
public int CompareTo(object obj)
public int CompareTo(object? obj)
{
if (obj == null)
return 1;
Expand All @@ -315,7 +313,7 @@ public int CompareTo(object obj)
}

/// <inheritdoc/>
public int CompareTo(GameVersion value)
public int CompareTo(GameVersion? value)
{
if (value == null)
return 1;
Expand Down Expand Up @@ -348,7 +346,7 @@ public int CompareTo(GameVersion value)
}

/// <inheritdoc/>
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
if (obj is not GameVersion value)
return false;
Expand All @@ -357,7 +355,7 @@ public override bool Equals(object obj)
}

/// <inheritdoc/>
public bool Equals(GameVersion value)
public bool Equals(GameVersion? value)
{
if (value == null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;

using Newtonsoft.Json;

namespace Dalamud.Game;
namespace Dalamud.Common.Game;

/// <summary>
/// Converts a <see cref="GameVersion"/> to and from a string (e.g. <c>"2010.01.01.1234.5678"</c>).
Expand Down
8 changes: 1 addition & 7 deletions Dalamud.Injector/Dalamud.Injector.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@
</ItemGroup>

<ItemGroup>
<!-- This prevents us from having to include Dalamud itself as a dependency -->
<!-- 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)" />
<ProjectReference Include="..\Dalamud.Common\Dalamud.Common.csproj" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion Dalamud.Injector/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
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;
Expand Down
20 changes: 0 additions & 20 deletions Dalamud.Injector/Hacks.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Dalamud.Test/Game/GameVersionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Dalamud.Game;
using Dalamud.Common.Game;
using Xunit;

namespace Dalamud.Test.Game
Expand Down
14 changes: 14 additions & 0 deletions Dalamud.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Dalamud/ClientLanguage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace Dalamud;

// TODO(v10): Delete this, and use Dalamud.Common.ClientLanguage instead for everything.

/// <summary>
/// Enum describing the language the game loads in.
/// </summary>
Expand Down
39 changes: 36 additions & 3 deletions Dalamud/Dalamud.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
Expand All @@ -7,13 +6,15 @@
using System.Threading;
using System.Threading.Tasks;

using Dalamud.Common;
using Dalamud.Configuration.Internal;
using Dalamud.Game;
using Dalamud.Game.Gui.Internal;
using Dalamud.Interface.Internal;
using Dalamud.Plugin.Internal;
using Dalamud.Storage;
using Dalamud.Utility;
using Dalamud.Utility.Timing;
using PInvoke;
using Serilog;

Expand Down Expand Up @@ -47,10 +48,28 @@ internal sealed class Dalamud : IServiceType
/// <param name="mainThreadContinueEvent">Event used to signal the main thread to continue.</param>
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)
{
Expand Down Expand Up @@ -97,11 +116,16 @@ public Dalamud(DalamudStartInfo info, ReliableFileStorage fs, DalamudConfigurati
});
}
}

/// <summary>
/// Gets the start information for this Dalamud instance.
/// </summary>
internal DalamudStartInfo StartInfo { get; private set; }

/// <summary>
/// Gets location of stored assets.
/// </summary>
internal DirectoryInfo AssetDirectory => new(Service<DalamudStartInfo>.Get().AssetDirectory!);
internal DirectoryInfo AssetDirectory => new(this.StartInfo.AssetDirectory!);

/// <summary>
/// Signal to the crash handler process that we should restart the game.
Expand Down Expand Up @@ -176,4 +200,13 @@ internal void ReplaceExceptionHandler()
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<TargetSigScanner>.Get().SearchBase, new FileInfo(Path.Combine(cacheDir.FullName, $"{this.StartInfo.GameVersion}_cs.json")));
FFXIVClientStructs.Interop.Resolver.GetInstance.Resolve();
}
}
}
1 change: 1 addition & 0 deletions Dalamud/Dalamud.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<PackageReference Include="System.Resources.Extensions" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Dalamud.Common\Dalamud.Common.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\SDL2-CS\SDL2-CS.csproj" />
Expand Down
28 changes: 16 additions & 12 deletions Dalamud/Data/DataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Dalamud.IoC;
using Dalamud.IoC.Internal;
using Dalamud.Plugin.Services;
using Dalamud.Utility;
using Dalamud.Utility.Timing;
using JetBrains.Annotations;
using Lumina;
Expand All @@ -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<string, ushort>(new Dictionary<string, ushort>());
Expand Down Expand Up @@ -82,17 +83,20 @@ private DataManager(DalamudStartInfo dalamudStartInfo, Dalamud dalamud)

Log.Information("Lumina is ready: {0}", this.GameData.DataPath);

try
if (!dalamud.StartInfo.TroubleshootingPackData.IsNullOrEmpty())
{
var tsInfo =
JsonConvert.DeserializeObject<LauncherTroubleshootingInfo>(
dalamudStartInfo.TroubleshootingPackData);
this.HasModifiedGameDataFiles =
tsInfo?.IndexIntegrity is LauncherTroubleshootingInfo.IndexIntegrityResult.Failed or LauncherTroubleshootingInfo.IndexIntegrityResult.Exception;
}
catch
{
// ignored
try
{
var tsInfo =
JsonConvert.DeserializeObject<LauncherTroubleshootingInfo>(
dalamud.StartInfo.TroubleshootingPackData);
this.HasModifiedGameDataFiles =
tsInfo?.IndexIntegrity is LauncherTroubleshootingInfo.IndexIntegrityResult.Failed or LauncherTroubleshootingInfo.IndexIntegrityResult.Exception;
}
catch
{
// ignored
}
}
}

Expand Down
Loading

0 comments on commit f44c679

Please sign in to comment.