mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
commit
639cb1ac33
22 changed files with 1081 additions and 200 deletions
3
.github/workflows/main.yml
vendored
3
.github/workflows/main.yml
vendored
|
|
@ -16,6 +16,9 @@ jobs:
|
|||
fetch-depth: 0
|
||||
- name: Setup MSBuild
|
||||
uses: microsoft/setup-msbuild@v1.0.2
|
||||
- uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: '8.0.100'
|
||||
- name: Define VERSION
|
||||
run: |
|
||||
$env:COMMIT = $env:GITHUB_SHA.Substring(0, 7)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
|
|||
/// Initializes a new instance of the <see cref="GameVersion"/> class.
|
||||
/// </summary>
|
||||
/// <param name="version">Version string to parse.</param>
|
||||
[JsonConstructor]
|
||||
public GameVersion(string version)
|
||||
{
|
||||
var ver = Parse(version);
|
||||
|
|
@ -42,20 +41,9 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
|
|||
/// <param name="day">The day.</param>
|
||||
/// <param name="major">The major version.</param>
|
||||
/// <param name="minor">The minor version.</param>
|
||||
public GameVersion(int year, int month, int day, int major, int minor)
|
||||
[JsonConstructor]
|
||||
public GameVersion(int year, int month, int day, int major, int minor) : this(year, month, day, major)
|
||||
{
|
||||
if ((this.Year = year) < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(year));
|
||||
|
||||
if ((this.Month = month) < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(month));
|
||||
|
||||
if ((this.Day = day) < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(day));
|
||||
|
||||
if ((this.Major = major) < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(major));
|
||||
|
||||
if ((this.Minor = minor) < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(minor));
|
||||
}
|
||||
|
|
@ -67,17 +55,8 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
|
|||
/// <param name="month">The month.</param>
|
||||
/// <param name="day">The day.</param>
|
||||
/// <param name="major">The major version.</param>
|
||||
public GameVersion(int year, int month, int day, int major)
|
||||
public GameVersion(int year, int month, int day, int major) : this(year, month, day)
|
||||
{
|
||||
if ((this.Year = year) < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(year));
|
||||
|
||||
if ((this.Month = month) < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(month));
|
||||
|
||||
if ((this.Day = day) < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(day));
|
||||
|
||||
if ((this.Major = major) < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(major));
|
||||
}
|
||||
|
|
@ -88,14 +67,8 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
|
|||
/// <param name="year">The year.</param>
|
||||
/// <param name="month">The month.</param>
|
||||
/// <param name="day">The day.</param>
|
||||
public GameVersion(int year, int month, int day)
|
||||
public GameVersion(int year, int month, int day) : this(year, month)
|
||||
{
|
||||
if ((this.Year = year) < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(year));
|
||||
|
||||
if ((this.Month = month) < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(month));
|
||||
|
||||
if ((this.Day = day) < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(day));
|
||||
}
|
||||
|
|
@ -105,11 +78,8 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
|
|||
/// </summary>
|
||||
/// <param name="year">The year.</param>
|
||||
/// <param name="month">The month.</param>
|
||||
public GameVersion(int year, int month)
|
||||
public GameVersion(int year, int month) : this(year)
|
||||
{
|
||||
if ((this.Year = year) < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(year));
|
||||
|
||||
if ((this.Month = month) < 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(month));
|
||||
}
|
||||
|
|
@ -139,26 +109,31 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
|
|||
/// <summary>
|
||||
/// Gets the year component.
|
||||
/// </summary>
|
||||
[JsonRequired]
|
||||
public int Year { get; } = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the month component.
|
||||
/// </summary>
|
||||
[JsonRequired]
|
||||
public int Month { get; } = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the day component.
|
||||
/// </summary>
|
||||
[JsonRequired]
|
||||
public int Day { get; } = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the major version component.
|
||||
/// </summary>
|
||||
[JsonRequired]
|
||||
public int Major { get; } = -1;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the minor version component.
|
||||
/// </summary>
|
||||
[JsonRequired]
|
||||
public int Minor { get; } = -1;
|
||||
|
||||
public static implicit operator GameVersion(string ver)
|
||||
|
|
@ -183,17 +158,13 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
|
|||
|
||||
public static bool operator <(GameVersion v1, GameVersion v2)
|
||||
{
|
||||
if (v1 is null)
|
||||
throw new ArgumentNullException(nameof(v1));
|
||||
|
||||
ArgumentNullException.ThrowIfNull(v1);
|
||||
return v1.CompareTo(v2) < 0;
|
||||
}
|
||||
|
||||
public static bool operator <=(GameVersion v1, GameVersion v2)
|
||||
{
|
||||
if (v1 is null)
|
||||
throw new ArgumentNullException(nameof(v1));
|
||||
|
||||
ArgumentNullException.ThrowIfNull(v1);
|
||||
return v1.CompareTo(v2) <= 0;
|
||||
}
|
||||
|
||||
|
|
@ -209,8 +180,7 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
|
|||
|
||||
public static GameVersion operator +(GameVersion v1, TimeSpan v2)
|
||||
{
|
||||
if (v1 == null)
|
||||
throw new ArgumentNullException(nameof(v1));
|
||||
ArgumentNullException.ThrowIfNull(v1);
|
||||
|
||||
if (v1.Year == -1 || v1.Month == -1 || v1.Day == -1)
|
||||
return v1;
|
||||
|
|
@ -222,8 +192,7 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
|
|||
|
||||
public static GameVersion operator -(GameVersion v1, TimeSpan v2)
|
||||
{
|
||||
if (v1 == null)
|
||||
throw new ArgumentNullException(nameof(v1));
|
||||
ArgumentNullException.ThrowIfNull(v1);
|
||||
|
||||
if (v1.Year == -1 || v1.Month == -1 || v1.Day == -1)
|
||||
return v1;
|
||||
|
|
@ -240,18 +209,18 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
|
|||
/// <returns>GameVersion object.</returns>
|
||||
public static GameVersion Parse(string input)
|
||||
{
|
||||
if (input == null)
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
ArgumentNullException.ThrowIfNull(input);
|
||||
|
||||
if (input.ToLower(CultureInfo.InvariantCulture) == "any")
|
||||
return new GameVersion();
|
||||
return Any;
|
||||
|
||||
var parts = input.Split('.');
|
||||
var tplParts = parts.Select(p =>
|
||||
{
|
||||
var result = int.TryParse(p, out var value);
|
||||
return (result, value);
|
||||
}).ToArray();
|
||||
var tplParts = parts.Select(
|
||||
p =>
|
||||
{
|
||||
var result = int.TryParse(p, out var value);
|
||||
return (result, value);
|
||||
}).ToArray();
|
||||
|
||||
if (tplParts.Any(t => !t.result))
|
||||
throw new FormatException("Bad formatting");
|
||||
|
|
@ -259,18 +228,15 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
|
|||
var intParts = tplParts.Select(t => t.value).ToArray();
|
||||
var len = intParts.Length;
|
||||
|
||||
if (len == 1)
|
||||
return new GameVersion(intParts[0]);
|
||||
else if (len == 2)
|
||||
return new GameVersion(intParts[0], intParts[1]);
|
||||
else if (len == 3)
|
||||
return new GameVersion(intParts[0], intParts[1], intParts[2]);
|
||||
else if (len == 4)
|
||||
return new GameVersion(intParts[0], intParts[1], intParts[2], intParts[3]);
|
||||
else if (len == 5)
|
||||
return new GameVersion(intParts[0], intParts[1], intParts[2], intParts[3], intParts[4]);
|
||||
else
|
||||
throw new ArgumentException("Too many parts");
|
||||
return len switch
|
||||
{
|
||||
1 => new GameVersion(intParts[0]),
|
||||
2 => new GameVersion(intParts[0], intParts[1]),
|
||||
3 => new GameVersion(intParts[0], intParts[1], intParts[2]),
|
||||
4 => new GameVersion(intParts[0], intParts[1], intParts[2], intParts[3]),
|
||||
5 => new GameVersion(intParts[0], intParts[1], intParts[2], intParts[3], intParts[4]),
|
||||
_ => throw new ArgumentException("Too many parts"),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -299,17 +265,12 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
|
|||
/// <inheritdoc/>
|
||||
public int CompareTo(object? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
return 1;
|
||||
|
||||
if (obj is GameVersion value)
|
||||
return obj switch
|
||||
{
|
||||
return this.CompareTo(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("Argument must be a GameVersion");
|
||||
}
|
||||
null => 1,
|
||||
GameVersion value => this.CompareTo(value),
|
||||
_ => throw new ArgumentException("Argument must be a GameVersion", nameof(obj)),
|
||||
};
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
@ -342,16 +303,14 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
|
|||
if (this.Minor != value.Minor)
|
||||
return this.Minor > value.Minor ? 1 : -1;
|
||||
|
||||
// This should never happen
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is not GameVersion value)
|
||||
return false;
|
||||
|
||||
return this.Equals(value);
|
||||
return obj is GameVersion value && this.Equals(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
@ -373,16 +332,8 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
|
|||
/// <inheritdoc/>
|
||||
public override int GetHashCode()
|
||||
{
|
||||
var accumulator = 0;
|
||||
|
||||
// This might be horribly wrong, but it isn't used heavily.
|
||||
accumulator |= this.Year.GetHashCode();
|
||||
accumulator |= this.Month.GetHashCode();
|
||||
accumulator |= this.Day.GetHashCode();
|
||||
accumulator |= this.Major.GetHashCode();
|
||||
accumulator |= this.Minor.GetHashCode();
|
||||
|
||||
return accumulator;
|
||||
// https://learn.microsoft.com/en-us/dotnet/api/system.object.gethashcode?view=net-8.0#notes-to-inheritors
|
||||
return HashCode.Combine(this.Year, this.Month, this.Day, this.Major, this.Minor);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
@ -396,11 +347,11 @@ public sealed class GameVersion : ICloneable, IComparable, IComparable<GameVersi
|
|||
return "any";
|
||||
|
||||
return new StringBuilder()
|
||||
.Append(string.Format("{0:D4}.", this.Year == -1 ? 0 : this.Year))
|
||||
.Append(string.Format("{0:D2}.", this.Month == -1 ? 0 : this.Month))
|
||||
.Append(string.Format("{0:D2}.", this.Day == -1 ? 0 : this.Day))
|
||||
.Append(string.Format("{0:D4}.", this.Major == -1 ? 0 : this.Major))
|
||||
.Append(string.Format("{0:D4}", this.Minor == -1 ? 0 : this.Minor))
|
||||
.Append($"{(this.Year == -1 ? 0 : this.Year):D4}.")
|
||||
.Append($"{(this.Month == -1 ? 0 : this.Month):D2}.")
|
||||
.Append($"{(this.Day == -1 ? 0 : this.Day):D2}.")
|
||||
.Append($"{(this.Major == -1 ? 0 : this.Major):D4}.")
|
||||
.Append($"{(this.Minor == -1 ? 0 : this.Minor):D4}")
|
||||
.ToString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,17 +15,16 @@ public sealed class GameVersionConverter : JsonConverter
|
|||
/// <param name="serializer">The calling serializer.</param>
|
||||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||
{
|
||||
if (value == null)
|
||||
switch (value)
|
||||
{
|
||||
writer.WriteNull();
|
||||
}
|
||||
else if (value is GameVersion)
|
||||
{
|
||||
writer.WriteValue(value.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonSerializationException("Expected GameVersion object value");
|
||||
case null:
|
||||
writer.WriteNull();
|
||||
break;
|
||||
case GameVersion:
|
||||
writer.WriteValue(value.ToString());
|
||||
break;
|
||||
default:
|
||||
throw new JsonSerializationException("Expected GameVersion object value");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,24 +42,20 @@ public sealed class GameVersionConverter : JsonConverter
|
|||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
|
||||
if (reader.TokenType == JsonToken.String)
|
||||
{
|
||||
if (reader.TokenType == JsonToken.String)
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
return new GameVersion((string)reader.Value!);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new JsonSerializationException($"Error parsing GameVersion string: {reader.Value}", ex);
|
||||
}
|
||||
return new GameVersion((string)reader.Value!);
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new JsonSerializationException($"Unexpected token or value when parsing GameVersion. Token: {reader.TokenType}, Value: {reader.Value}");
|
||||
throw new JsonSerializationException($"Error parsing GameVersion string: {reader.Value}", ex);
|
||||
}
|
||||
}
|
||||
|
||||
throw new JsonSerializationException($"Unexpected token or value when parsing GameVersion. Token: {reader.TokenType}, Value: {reader.Value}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<AssemblyName>Dalamud.CorePlugin</AssemblyName>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Platforms>x64</Platforms>
|
||||
<LangVersion>10.0</LangVersion>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup Label="Target">
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<Platforms>x64;AnyCPU</Platforms>
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup Label="Target">
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<Platforms>x64;AnyCPU</Platforms>
|
||||
<LangVersion>9.0</LangVersion>
|
||||
<LangVersion>11.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Label="Feature">
|
||||
|
|
|
|||
138
Dalamud.Test/Game/GameVersionConverterTests.cs
Normal file
138
Dalamud.Test/Game/GameVersionConverterTests.cs
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
using Dalamud.Common.Game;
|
||||
|
||||
using JetBrains.Annotations;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace Dalamud.Test.Game;
|
||||
|
||||
public class GameVersionConverterTests
|
||||
{
|
||||
[Fact]
|
||||
public void ReadJson_ConvertsFromString()
|
||||
{
|
||||
var serialized = """
|
||||
{
|
||||
"Version": "2020.06.15.0000.0000"
|
||||
}
|
||||
""";
|
||||
var deserialized = JsonConvert.DeserializeObject<TestSerializationClass>(serialized);
|
||||
|
||||
Assert.NotNull(deserialized);
|
||||
Assert.Equal(GameVersion.Parse("2020.06.15.0000.0000"), deserialized.Version);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void ReadJson_ConvertsFromNull()
|
||||
{
|
||||
var serialized = """
|
||||
{
|
||||
"Version": null
|
||||
}
|
||||
""";
|
||||
var deserialized = JsonConvert.DeserializeObject<TestSerializationClass>(serialized);
|
||||
|
||||
Assert.NotNull(deserialized);
|
||||
Assert.Null(deserialized.Version);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadJson_WhenInvalidType_Throws()
|
||||
{
|
||||
var serialized = """
|
||||
{
|
||||
"Version": 2
|
||||
}
|
||||
""";
|
||||
Assert.Throws<JsonSerializationException>(
|
||||
() => JsonConvert.DeserializeObject<TestSerializationClass>(serialized));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadJson_WhenInvalidVersion_Throws()
|
||||
{
|
||||
var serialized = """
|
||||
{
|
||||
"Version": "junk"
|
||||
}
|
||||
""";
|
||||
Assert.Throws<JsonSerializationException>(
|
||||
() => JsonConvert.DeserializeObject<TestSerializationClass>(serialized));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteJson_ConvertsToString()
|
||||
{
|
||||
var deserialized = new TestSerializationClass
|
||||
{
|
||||
Version = GameVersion.Parse("2020.06.15.0000.0000"),
|
||||
};
|
||||
var serialized = JsonConvert.SerializeObject(deserialized);
|
||||
|
||||
Assert.Equal("""{"Version":"2020.06.15.0000.0000"}""", RemoveWhitespace(serialized));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteJson_ConvertsToNull()
|
||||
{
|
||||
var deserialized = new TestSerializationClass
|
||||
{
|
||||
Version = null,
|
||||
};
|
||||
var serialized = JsonConvert.SerializeObject(deserialized);
|
||||
|
||||
Assert.Equal("""{"Version":null}""", RemoveWhitespace(serialized));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteJson_WhenInvalidVersion_Throws()
|
||||
{
|
||||
var deserialized = new TestWrongTypeSerializationClass
|
||||
{
|
||||
Version = 42,
|
||||
};
|
||||
Assert.Throws<JsonSerializationException>(() => JsonConvert.SerializeObject(deserialized));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanConvert_WhenGameVersion_ReturnsTrue()
|
||||
{
|
||||
var converter = new GameVersionConverter();
|
||||
Assert.True(converter.CanConvert(typeof(GameVersion)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanConvert_WhenNotGameVersion_ReturnsFalse()
|
||||
{
|
||||
var converter = new GameVersionConverter();
|
||||
Assert.False(converter.CanConvert(typeof(int)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanConvert_WhenNull_ReturnsFalse()
|
||||
{
|
||||
var converter = new GameVersionConverter();
|
||||
Assert.False(converter.CanConvert(null!));
|
||||
}
|
||||
|
||||
private static string RemoveWhitespace(string input)
|
||||
{
|
||||
return input.Replace(" ", "").Replace("\r", "").Replace("\n", "");
|
||||
}
|
||||
|
||||
private class TestSerializationClass
|
||||
{
|
||||
[JsonConverter(typeof(GameVersionConverter))]
|
||||
[CanBeNull]
|
||||
public GameVersion Version { get; init; }
|
||||
}
|
||||
|
||||
private class TestWrongTypeSerializationClass
|
||||
{
|
||||
[JsonConverter(typeof(GameVersionConverter))]
|
||||
public int Version { get; init; }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,71 @@
|
|||
using System;
|
||||
|
||||
using Dalamud.Common.Game;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace Dalamud.Test.Game
|
||||
{
|
||||
public class GameVersionTests
|
||||
{
|
||||
[Fact]
|
||||
public void VersionComparisons()
|
||||
{
|
||||
var v1 = GameVersion.Parse("2021.01.01.0000.0000");
|
||||
var v2 = GameVersion.Parse("2021.01.01.0000.0000");
|
||||
Assert.True(v1 == v2);
|
||||
Assert.False(v1 != v2);
|
||||
Assert.False(v1 < v2);
|
||||
Assert.True(v1 <= v2);
|
||||
Assert.False(v1 > v2);
|
||||
Assert.True(v1 >= v2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionAddition()
|
||||
{
|
||||
var v1 = GameVersion.Parse("2021.01.01.0000.0000");
|
||||
var v2 = GameVersion.Parse("2021.01.05.0000.0000");
|
||||
Assert.Equal(v2, v1 + TimeSpan.FromDays(4));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionAdditionAny()
|
||||
{
|
||||
Assert.Equal(GameVersion.Any, GameVersion.Any + TimeSpan.FromDays(4));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionSubtraction()
|
||||
{
|
||||
var v1 = GameVersion.Parse("2021.01.05.0000.0000");
|
||||
var v2 = GameVersion.Parse("2021.01.01.0000.0000");
|
||||
Assert.Equal(v2, v1 - TimeSpan.FromDays(4));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionSubtractionAny()
|
||||
{
|
||||
Assert.Equal(GameVersion.Any, GameVersion.Any - TimeSpan.FromDays(4));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionClone()
|
||||
{
|
||||
var v1 = GameVersion.Parse("2021.01.01.0000.0000");
|
||||
var v2 = v1.Clone();
|
||||
Assert.NotSame(v1, v2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionCast()
|
||||
{
|
||||
var v = GameVersion.Parse("2021.01.01.0000.0000");
|
||||
Assert.Equal("2021.01.01.0000.0000", v);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("any", "any")]
|
||||
[InlineData("2021.01.01.0000.0000", "2021.01.01.0000.0000")]
|
||||
|
|
@ -14,6 +75,18 @@ namespace Dalamud.Test.Game
|
|||
var v2 = GameVersion.Parse(ver2);
|
||||
|
||||
Assert.Equal(v1, v2);
|
||||
Assert.Equal(0, v1.CompareTo(v2));
|
||||
Assert.Equal(v1.GetHashCode(), v2.GetHashCode());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionNullEquality()
|
||||
{
|
||||
// Tests `Equals(GameVersion? value)`
|
||||
Assert.False(GameVersion.Parse("2021.01.01.0000.0000").Equals(null));
|
||||
|
||||
// Tests `Equals(object? value)`
|
||||
Assert.False(GameVersion.Parse("2021.01.01.0000.0000").Equals((object)null));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -31,6 +104,67 @@ namespace Dalamud.Test.Game
|
|||
Assert.True(v1.CompareTo(v2) < 0);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("any", "2020.06.15.0000.0000")]
|
||||
public void VersionComparisonInverse(string ver1, string ver2)
|
||||
{
|
||||
var v1 = GameVersion.Parse(ver1);
|
||||
var v2 = GameVersion.Parse(ver2);
|
||||
|
||||
Assert.True(v1.CompareTo(v2) > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionComparisonNull()
|
||||
{
|
||||
var v = GameVersion.Parse("2020.06.15.0000.0000");
|
||||
|
||||
// Tests `CompareTo(GameVersion? value)`
|
||||
Assert.True(v.CompareTo(null) > 0);
|
||||
|
||||
// Tests `CompareTo(object? value)`
|
||||
Assert.True(v.CompareTo((object)null) > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionComparisonBoxed()
|
||||
{
|
||||
var v1 = GameVersion.Parse("2020.06.15.0000.0000");
|
||||
var v2 = GameVersion.Parse("2020.06.15.0000.0000");
|
||||
Assert.Equal(0, v1.CompareTo((object)v2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionComparisonBoxedInvalid()
|
||||
{
|
||||
var v = GameVersion.Parse("2020.06.15.0000.0000");
|
||||
Assert.Throws<ArgumentException>(() => v.CompareTo(42));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("2020.06.15.0000.0000")]
|
||||
[InlineData("2021.01.01.0000")]
|
||||
[InlineData("2021.01.01")]
|
||||
[InlineData("2021.01")]
|
||||
[InlineData("2021")]
|
||||
public void VersionParse(string ver)
|
||||
{
|
||||
var v = GameVersion.Parse(ver);
|
||||
Assert.NotNull(v);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("2020.06.15.0000.0000")]
|
||||
[InlineData("2021.01.01.0000")]
|
||||
[InlineData("2021.01.01")]
|
||||
[InlineData("2021.01")]
|
||||
[InlineData("2021")]
|
||||
public void VersionTryParse(string ver)
|
||||
{
|
||||
Assert.True(GameVersion.TryParse(ver, out var v));
|
||||
Assert.NotNull(v);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("2020.06.15.0000.0000")]
|
||||
[InlineData("2021.01.01.0000")]
|
||||
|
|
@ -39,9 +173,8 @@ namespace Dalamud.Test.Game
|
|||
[InlineData("2021")]
|
||||
public void VersionConstructor(string ver)
|
||||
{
|
||||
var v = GameVersion.Parse(ver);
|
||||
|
||||
Assert.True(v != null);
|
||||
var v = new GameVersion(ver);
|
||||
Assert.NotNull(v);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -54,5 +187,89 @@ namespace Dalamud.Test.Game
|
|||
Assert.False(result);
|
||||
Assert.Null(v);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("any", "any")]
|
||||
[InlineData("2020.06.15.0000.0000", "2020.06.15.0000.0000")]
|
||||
[InlineData("2021.01.01.0000", "2021.01.01.0000.0000")]
|
||||
[InlineData("2021.01.01", "2021.01.01.0000.0000")]
|
||||
[InlineData("2021.01", "2021.01.00.0000.0000")]
|
||||
[InlineData("2021", "2021.00.00.0000.0000")]
|
||||
public void VersionToString(string ver1, string ver2)
|
||||
{
|
||||
var v1 = GameVersion.Parse(ver1);
|
||||
Assert.Equal(ver2, v1.ToString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionIsSerializationSafe()
|
||||
{
|
||||
var v = GameVersion.Parse("2020.06.15.0000.0000");
|
||||
var serialized = JsonConvert.SerializeObject(v);
|
||||
var deserialized = JsonConvert.DeserializeObject<GameVersion>(serialized);
|
||||
Assert.Equal(v, deserialized);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionInvalidDeserialization()
|
||||
{
|
||||
var serialized = """
|
||||
{
|
||||
"Year": -1,
|
||||
"Month": -1,
|
||||
"Day": -1,
|
||||
"Major": -1,
|
||||
"Minor": -1,
|
||||
}
|
||||
""";
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => JsonConvert.DeserializeObject<GameVersion>(serialized));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionInvalidTypeDeserialization()
|
||||
{
|
||||
var serialized = """
|
||||
{
|
||||
"Value": "Hello"
|
||||
}
|
||||
""";
|
||||
Assert.Throws<JsonSerializationException>(() => JsonConvert.DeserializeObject<GameVersion>(serialized));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionConstructorNegativeYear()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new GameVersion(-2024));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionConstructorNegativeMonth()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new GameVersion(2024, -3));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionConstructorNegativeDay()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new GameVersion(2024, 3, -13));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionConstructorNegativeMajor()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new GameVersion(2024, 3, 13, -1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionConstructorNegativeMinor()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new GameVersion(2024, 3, 13, 0, -1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void VersionParseNull()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => GameVersion.Parse(null!));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
386
Dalamud.Test/Storage/ReliableFileStorageTests.cs
Normal file
386
Dalamud.Test/Storage/ReliableFileStorageTests.cs
Normal file
|
|
@ -0,0 +1,386 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Dalamud.Storage;
|
||||
|
||||
using Xunit;
|
||||
|
||||
namespace Dalamud.Test.Storage;
|
||||
|
||||
public class ReliableFileStorageTests
|
||||
{
|
||||
private const string DbFileName = "dalamudVfs.db";
|
||||
private const string TestFileName = "file.txt";
|
||||
private const string TestFileContent1 = "hello from señor dalamundo";
|
||||
private const string TestFileContent2 = "rewritten";
|
||||
|
||||
[Fact]
|
||||
public async Task IsConcurrencySafe()
|
||||
{
|
||||
var dbDir = CreateTempDir();
|
||||
using var rfs = new ReliableFileStorage(dbDir);
|
||||
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
|
||||
// Do reads/writes/deletes on the same file on many threads at once and
|
||||
// see if anything throws
|
||||
await Task.WhenAll(
|
||||
Enumerable.Range(1, 6)
|
||||
.Select(
|
||||
i => Parallel.ForEachAsync(
|
||||
Enumerable.Range(1, 100),
|
||||
(j, _) =>
|
||||
{
|
||||
if (i % 2 == 0)
|
||||
{
|
||||
// ReSharper disable once AccessToDisposedClosure
|
||||
rfs.WriteAllText(tempFile, j.ToString());
|
||||
}
|
||||
else if (i % 3 == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
// ReSharper disable once AccessToDisposedClosure
|
||||
rfs.ReadAllText(tempFile);
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
// this is fine
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
File.Delete(tempFile);
|
||||
}
|
||||
|
||||
return ValueTask.CompletedTask;
|
||||
})));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_Dispose_Works()
|
||||
{
|
||||
var dbDir = CreateTempDir();
|
||||
var dbPath = Path.Combine(dbDir, DbFileName);
|
||||
using var rfs = new ReliableFileStorage(dbDir);
|
||||
|
||||
Assert.True(File.Exists(dbPath));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Exists_ThrowsIfPathIsEmpty()
|
||||
{
|
||||
using var rfs = CreateRfs();
|
||||
Assert.Throws<ArgumentException>(() => rfs.Exists(""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Exists_ThrowsIfPathIsNull()
|
||||
{
|
||||
using var rfs = CreateRfs();
|
||||
Assert.Throws<ArgumentNullException>(() => rfs.Exists(null!));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Exists_WhenFileMissing_ReturnsFalse()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
using var rfs = CreateRfs();
|
||||
|
||||
Assert.False(rfs.Exists(tempFile));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Exists_WhenFileMissing_WhenDbFailed_ReturnsFalse()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
using var rfs = CreateFailedRfs();
|
||||
|
||||
Assert.False(rfs.Exists(tempFile));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Exists_WhenFileOnDisk_ReturnsTrue()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
await File.WriteAllTextAsync(tempFile, TestFileContent1);
|
||||
using var rfs = CreateRfs();
|
||||
|
||||
Assert.True(rfs.Exists(tempFile));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Exists_WhenFileInBackup_ReturnsTrue()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
using var rfs = CreateRfs();
|
||||
|
||||
rfs.WriteAllText(tempFile, TestFileContent1);
|
||||
|
||||
File.Delete(tempFile);
|
||||
Assert.True(rfs.Exists(tempFile));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Exists_WhenFileInBackup_WithDifferentContainerId_ReturnsFalse()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
using var rfs = CreateRfs();
|
||||
|
||||
rfs.WriteAllText(tempFile, TestFileContent1);
|
||||
|
||||
File.Delete(tempFile);
|
||||
Assert.False(rfs.Exists(tempFile, Guid.NewGuid()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteAllText_ThrowsIfPathIsEmpty()
|
||||
{
|
||||
using var rfs = CreateRfs();
|
||||
Assert.Throws<ArgumentException>(() => rfs.WriteAllText("", TestFileContent1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteAllText_ThrowsIfPathIsNull()
|
||||
{
|
||||
using var rfs = CreateRfs();
|
||||
Assert.Throws<ArgumentNullException>(() => rfs.WriteAllText(null!, TestFileContent1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WriteAllText_WritesToDbAndDisk()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
using var rfs = CreateRfs();
|
||||
|
||||
rfs.WriteAllText(tempFile, TestFileContent1);
|
||||
|
||||
Assert.True(File.Exists(tempFile));
|
||||
Assert.Equal(TestFileContent1, rfs.ReadAllText(tempFile, forceBackup: true));
|
||||
Assert.Equal(TestFileContent1, await File.ReadAllTextAsync(tempFile));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteAllText_SeparatesContainers()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
var containerId = Guid.NewGuid();
|
||||
|
||||
using var rfs = CreateRfs();
|
||||
rfs.WriteAllText(tempFile, TestFileContent1);
|
||||
rfs.WriteAllText(tempFile, TestFileContent2, containerId);
|
||||
File.Delete(tempFile);
|
||||
|
||||
Assert.Equal(TestFileContent1, rfs.ReadAllText(tempFile, forceBackup: true));
|
||||
Assert.Equal(TestFileContent2, rfs.ReadAllText(tempFile, forceBackup: true, containerId));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WriteAllText_WhenDbFailed_WritesToDisk()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
using var rfs = CreateFailedRfs();
|
||||
|
||||
rfs.WriteAllText(tempFile, TestFileContent1);
|
||||
|
||||
Assert.True(File.Exists(tempFile));
|
||||
Assert.Equal(TestFileContent1, await File.ReadAllTextAsync(tempFile));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WriteAllText_CanUpdateExistingFile()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
using var rfs = CreateRfs();
|
||||
|
||||
rfs.WriteAllText(tempFile, TestFileContent1);
|
||||
rfs.WriteAllText(tempFile, TestFileContent2);
|
||||
|
||||
Assert.True(File.Exists(tempFile));
|
||||
Assert.Equal(TestFileContent2, rfs.ReadAllText(tempFile, forceBackup: true));
|
||||
Assert.Equal(TestFileContent2, await File.ReadAllTextAsync(tempFile));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteAllText_SupportsNullContent()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
using var rfs = CreateRfs();
|
||||
|
||||
rfs.WriteAllText(tempFile, null);
|
||||
|
||||
Assert.True(File.Exists(tempFile));
|
||||
Assert.Equal("", rfs.ReadAllText(tempFile));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadAllText_ThrowsIfPathIsEmpty()
|
||||
{
|
||||
using var rfs = CreateRfs();
|
||||
Assert.Throws<ArgumentException>(() => rfs.ReadAllText(""));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadAllText_ThrowsIfPathIsNull()
|
||||
{
|
||||
using var rfs = CreateRfs();
|
||||
Assert.Throws<ArgumentNullException>(() => rfs.ReadAllText(null!));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAllText_WhenFileOnDisk_ReturnsContent()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
await File.WriteAllTextAsync(tempFile, TestFileContent1);
|
||||
using var rfs = CreateRfs();
|
||||
|
||||
Assert.Equal(TestFileContent1, rfs.ReadAllText(tempFile));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadAllText_WhenFileMissingWithBackup_ReturnsContent()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
using var rfs = CreateRfs();
|
||||
|
||||
rfs.WriteAllText(tempFile, TestFileContent1);
|
||||
File.Delete(tempFile);
|
||||
|
||||
Assert.Equal(TestFileContent1, rfs.ReadAllText(tempFile));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadAllText_WhenFileMissingWithBackup_ThrowsWithDifferentContainerId()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
var containerId = Guid.NewGuid();
|
||||
using var rfs = CreateRfs();
|
||||
|
||||
rfs.WriteAllText(tempFile, TestFileContent1);
|
||||
File.Delete(tempFile);
|
||||
|
||||
Assert.Throws<FileNotFoundException>(() => rfs.ReadAllText(tempFile, containerId: containerId));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadAllText_WhenFileMissing_ThrowsIfDbFailed()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
using var rfs = CreateFailedRfs();
|
||||
Assert.Throws<FileNotFoundException>(() => rfs.ReadAllText(tempFile));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAllText_WithReader_WhenFileOnDisk_ReadsContent()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
await File.WriteAllTextAsync(tempFile, TestFileContent1);
|
||||
using var rfs = CreateRfs();
|
||||
rfs.ReadAllText(tempFile, text => Assert.Equal(TestFileContent1, text));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAllText_WithReader_WhenReaderThrows_ThrowsIfBackupMissing()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
await File.WriteAllTextAsync(tempFile, TestFileContent1);
|
||||
|
||||
var readerCalledOnce = false;
|
||||
|
||||
using var rfs = CreateRfs();
|
||||
Assert.Throws<FileReadException>(() => rfs.ReadAllText(tempFile, Reader));
|
||||
|
||||
return;
|
||||
|
||||
void Reader(string text)
|
||||
{
|
||||
var wasReaderCalledOnce = readerCalledOnce;
|
||||
readerCalledOnce = true;
|
||||
if (!wasReaderCalledOnce) throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReadAllText_WithReader_WhenReaderThrows_ReadsContentFromBackup()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
|
||||
var readerCalledOnce = false;
|
||||
var assertionCalled = false;
|
||||
|
||||
using var rfs = CreateRfs();
|
||||
rfs.WriteAllText(tempFile, TestFileContent1);
|
||||
File.Delete(tempFile);
|
||||
|
||||
rfs.ReadAllText(tempFile, Reader);
|
||||
Assert.True(assertionCalled);
|
||||
|
||||
return;
|
||||
|
||||
void Reader(string text)
|
||||
{
|
||||
var wasReaderCalledOnce = readerCalledOnce;
|
||||
readerCalledOnce = true;
|
||||
if (!wasReaderCalledOnce) throw new Exception();
|
||||
Assert.Equal(TestFileContent1, text);
|
||||
assertionCalled = true;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ReadAllText_WithReader_RethrowsFileNotFoundException()
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
await File.WriteAllTextAsync(tempFile, TestFileContent1);
|
||||
using var rfs = CreateRfs();
|
||||
Assert.Throws<FileNotFoundException>(() => rfs.ReadAllText(tempFile, _ => throw new FileNotFoundException()));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void ReadAllText_WhenFileDoesNotExist_Throws(bool forceBackup)
|
||||
{
|
||||
var tempFile = Path.Combine(CreateTempDir(), TestFileName);
|
||||
using var rfs = CreateRfs();
|
||||
Assert.Throws<FileNotFoundException>(() => rfs.ReadAllText(tempFile, forceBackup));
|
||||
}
|
||||
|
||||
private static ReliableFileStorage CreateRfs()
|
||||
{
|
||||
var dbDir = CreateTempDir();
|
||||
return new ReliableFileStorage(dbDir);
|
||||
}
|
||||
|
||||
private static ReliableFileStorage CreateFailedRfs()
|
||||
{
|
||||
var dbDir = CreateTempDir();
|
||||
var dbPath = Path.Combine(dbDir, DbFileName);
|
||||
|
||||
// Create a corrupt DB deliberately, and hold its handle until
|
||||
// the end of the scope
|
||||
using var f = File.Open(dbPath, FileMode.CreateNew);
|
||||
f.Write("broken"u8);
|
||||
|
||||
// Throws an SQLiteException initially, and then throws an
|
||||
// IOException when attempting to delete the file because
|
||||
// there's already an active handle associated with it
|
||||
return new ReliableFileStorage(dbDir);
|
||||
}
|
||||
|
||||
private static string CreateTempDir()
|
||||
{
|
||||
string tempDir;
|
||||
do
|
||||
{
|
||||
// Generate temp directories until we get a new one (usually happens on the first try)
|
||||
tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
||||
}
|
||||
while (File.Exists(tempDir));
|
||||
|
||||
Directory.CreateDirectory(tempDir);
|
||||
return tempDir;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup Label="Target">
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<Platforms>x64;AnyCPU</Platforms>
|
||||
<LangVersion>11.0</LangVersion>
|
||||
<LangVersion>12.0</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Label="Feature">
|
||||
|
|
@ -75,7 +75,6 @@
|
|||
<PrivateAssets>all</PrivateAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="MinSharp" Version="1.0.4" />
|
||||
<PackageReference Include="MonoModReorg.RuntimeDetour" Version="23.1.2-prerelease.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
|
||||
<PackageReference Include="Serilog" Version="2.11.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
|
||||
|
|
@ -119,14 +118,6 @@
|
|||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<Target Name="ChangeAliasesOfNugetRefs" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
|
||||
<ItemGroup>
|
||||
<ReferencePath Condition="'%(FileName)' == 'MonoMod.Iced'">
|
||||
<Aliases>monomod</Aliases>
|
||||
</ReferencePath>
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
<PropertyGroup>
|
||||
<!-- Needed temporarily for CI -->
|
||||
<TempVerFile>$(OutputPath)TEMP_gitver.txt</TempVerFile>
|
||||
|
|
|
|||
|
|
@ -1,15 +1,22 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
using Dalamud.Game.ClientState.Objects.Enums;
|
||||
using Dalamud.Game.ClientState.Objects.SubKinds;
|
||||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
using Dalamud.IoC;
|
||||
using Dalamud.IoC.Internal;
|
||||
using Dalamud.Plugin.Internal;
|
||||
using Dalamud.Plugin.Services;
|
||||
using Dalamud.Utility;
|
||||
|
||||
using Microsoft.Extensions.ObjectPool;
|
||||
|
||||
using Serilog;
|
||||
|
||||
using CSGameObject = FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject;
|
||||
|
||||
namespace Dalamud.Game.ClientState.Objects;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -25,18 +32,41 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable
|
|||
{
|
||||
private const int ObjectTableLength = 599;
|
||||
|
||||
private readonly ClientStateAddressResolver address;
|
||||
private readonly ClientState clientState;
|
||||
private readonly CachedEntry[] cachedObjectTable = new CachedEntry[ObjectTableLength];
|
||||
|
||||
private readonly ObjectPool<Enumerator> multiThreadedEnumerators =
|
||||
new DefaultObjectPoolProvider().Create<Enumerator>();
|
||||
|
||||
private readonly Enumerator?[] frameworkThreadEnumerators = new Enumerator?[4];
|
||||
|
||||
private long nextMultithreadedUsageWarnTime;
|
||||
|
||||
[ServiceManager.ServiceConstructor]
|
||||
private ObjectTable(ClientState clientState)
|
||||
private unsafe ObjectTable(ClientState clientState)
|
||||
{
|
||||
this.address = clientState.AddressResolver;
|
||||
this.clientState = clientState;
|
||||
|
||||
Log.Verbose($"Object table address 0x{this.address.ObjectTable.ToInt64():X}");
|
||||
var nativeObjectTableAddress = (CSGameObject**)this.clientState.AddressResolver.ObjectTable;
|
||||
for (var i = 0; i < this.cachedObjectTable.Length; i++)
|
||||
this.cachedObjectTable[i] = new(nativeObjectTableAddress, i);
|
||||
|
||||
for (var i = 0; i < this.frameworkThreadEnumerators.Length; i++)
|
||||
this.frameworkThreadEnumerators[i] = new(this, i);
|
||||
|
||||
Log.Verbose($"Object table address 0x{this.clientState.AddressResolver.ObjectTable.ToInt64():X}");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IntPtr Address => this.address.ObjectTable;
|
||||
public nint Address
|
||||
{
|
||||
get
|
||||
{
|
||||
_ = this.WarnMultithreadedUsage();
|
||||
|
||||
return this.clientState.AddressResolver.ObjectTable;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int Length => ObjectTableLength;
|
||||
|
|
@ -46,50 +76,49 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable
|
|||
{
|
||||
get
|
||||
{
|
||||
var address = this.GetObjectAddress(index);
|
||||
return this.CreateObjectReference(address);
|
||||
_ = this.WarnMultithreadedUsage();
|
||||
|
||||
return index is >= ObjectTableLength or < 0 ? null : this.cachedObjectTable[index].Update();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public GameObject? SearchById(ulong objectId)
|
||||
{
|
||||
_ = this.WarnMultithreadedUsage();
|
||||
|
||||
if (objectId is GameObject.InvalidGameObjectId or 0)
|
||||
return null;
|
||||
|
||||
foreach (var obj in this)
|
||||
foreach (var e in this.cachedObjectTable)
|
||||
{
|
||||
if (obj == null)
|
||||
continue;
|
||||
|
||||
if (obj.ObjectId == objectId)
|
||||
return obj;
|
||||
if (e.Update() is { } o && o.ObjectId == objectId)
|
||||
return o;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public unsafe IntPtr GetObjectAddress(int index)
|
||||
public unsafe nint GetObjectAddress(int index)
|
||||
{
|
||||
if (index < 0 || index >= ObjectTableLength)
|
||||
return IntPtr.Zero;
|
||||
_ = this.WarnMultithreadedUsage();
|
||||
|
||||
return *(IntPtr*)(this.address.ObjectTable + (8 * index));
|
||||
return index is < 0 or >= ObjectTableLength ? nint.Zero : (nint)this.cachedObjectTable[index].Address;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public unsafe GameObject? CreateObjectReference(IntPtr address)
|
||||
public unsafe GameObject? CreateObjectReference(nint address)
|
||||
{
|
||||
var clientState = Service<ClientState>.GetNullable();
|
||||
_ = this.WarnMultithreadedUsage();
|
||||
|
||||
if (clientState == null || clientState.LocalContentId == 0)
|
||||
if (this.clientState.LocalContentId == 0)
|
||||
return null;
|
||||
|
||||
if (address == IntPtr.Zero)
|
||||
if (address == nint.Zero)
|
||||
return null;
|
||||
|
||||
var obj = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)address;
|
||||
var obj = (CSGameObject*)address;
|
||||
var objKind = (ObjectKind)obj->ObjectKind;
|
||||
return objKind switch
|
||||
{
|
||||
|
|
@ -104,6 +133,82 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable
|
|||
_ => new GameObject(address),
|
||||
};
|
||||
}
|
||||
|
||||
[Api10ToDo("Use ThreadSafety.AssertMainThread() instead of this.")]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private bool WarnMultithreadedUsage()
|
||||
{
|
||||
if (ThreadSafety.IsMainThread)
|
||||
return false;
|
||||
|
||||
var n = Environment.TickCount64;
|
||||
if (this.nextMultithreadedUsageWarnTime < n)
|
||||
{
|
||||
this.nextMultithreadedUsageWarnTime = n + 30000;
|
||||
|
||||
Log.Warning(
|
||||
"{plugin} is accessing {objectTable} outside the main thread. This is deprecated.",
|
||||
Service<PluginManager>.Get().FindCallingPlugin()?.Name ?? "<unknown plugin>",
|
||||
nameof(ObjectTable));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Stores an object table entry, with preallocated concrete types.</summary>
|
||||
internal readonly unsafe struct CachedEntry
|
||||
{
|
||||
private readonly CSGameObject** gameObjectPtrPtr;
|
||||
private readonly PlayerCharacter playerCharacter;
|
||||
private readonly BattleNpc battleNpc;
|
||||
private readonly Npc npc;
|
||||
private readonly EventObj eventObj;
|
||||
private readonly GameObject gameObject;
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="CachedEntry"/> struct.</summary>
|
||||
/// <param name="ownerTable">The object table that this entry should be pointing to.</param>
|
||||
/// <param name="slot">The slot index inside the table.</param>
|
||||
public CachedEntry(CSGameObject** ownerTable, int slot)
|
||||
{
|
||||
this.gameObjectPtrPtr = ownerTable + slot;
|
||||
this.playerCharacter = new(nint.Zero);
|
||||
this.battleNpc = new(nint.Zero);
|
||||
this.npc = new(nint.Zero);
|
||||
this.eventObj = new(nint.Zero);
|
||||
this.gameObject = new(nint.Zero);
|
||||
}
|
||||
|
||||
/// <summary>Gets the address of the underlying native object. May be null.</summary>
|
||||
public CSGameObject* Address
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get => *this.gameObjectPtrPtr;
|
||||
}
|
||||
|
||||
/// <summary>Updates and gets the wrapped game object pointed by this struct.</summary>
|
||||
/// <returns>The pointed object, or <c>null</c> if no object exists at that slot.</returns>
|
||||
public GameObject? Update()
|
||||
{
|
||||
var address = this.Address;
|
||||
if (address is null)
|
||||
return null;
|
||||
|
||||
var activeObject = (ObjectKind)address->ObjectKind switch
|
||||
{
|
||||
ObjectKind.Player => this.playerCharacter,
|
||||
ObjectKind.BattleNpc => this.battleNpc,
|
||||
ObjectKind.EventNpc => this.npc,
|
||||
ObjectKind.Retainer => this.npc,
|
||||
ObjectKind.EventObj => this.eventObj,
|
||||
ObjectKind.Companion => this.npc,
|
||||
ObjectKind.MountType => this.npc,
|
||||
ObjectKind.Ornament => this.npc,
|
||||
_ => this.gameObject,
|
||||
};
|
||||
activeObject.Address = (nint)address;
|
||||
return activeObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -117,17 +222,90 @@ internal sealed partial class ObjectTable
|
|||
/// <inheritdoc/>
|
||||
public IEnumerator<GameObject> GetEnumerator()
|
||||
{
|
||||
for (var i = 0; i < ObjectTableLength; i++)
|
||||
// If something's trying to enumerate outside the framework thread, we use the ObjectPool.
|
||||
if (this.WarnMultithreadedUsage())
|
||||
{
|
||||
var obj = this[i];
|
||||
|
||||
if (obj == null)
|
||||
continue;
|
||||
|
||||
yield return obj;
|
||||
// let's not
|
||||
var e = this.multiThreadedEnumerators.Get();
|
||||
e.InitializeForPooledObjects(this);
|
||||
return e;
|
||||
}
|
||||
|
||||
// If we're on the framework thread, see if there's an already allocated enumerator available for use.
|
||||
foreach (ref var x in this.frameworkThreadEnumerators.AsSpan())
|
||||
{
|
||||
if (x is not null)
|
||||
{
|
||||
var t = x;
|
||||
x = null;
|
||||
t.Reset();
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
// No reusable enumerator is available; allocate a new temporary one.
|
||||
return new Enumerator(this, -1);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
|
||||
|
||||
private sealed class Enumerator : IEnumerator<GameObject>, IResettable
|
||||
{
|
||||
private readonly int slotId;
|
||||
private ObjectTable? owner;
|
||||
|
||||
private int index = -1;
|
||||
|
||||
public Enumerator() => this.slotId = -1;
|
||||
|
||||
public Enumerator(ObjectTable owner, int slotId)
|
||||
{
|
||||
this.owner = owner;
|
||||
this.slotId = slotId;
|
||||
}
|
||||
|
||||
public GameObject Current { get; private set; } = null!;
|
||||
|
||||
object IEnumerator.Current => this.Current;
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (this.index == ObjectTableLength)
|
||||
return false;
|
||||
|
||||
var cache = this.owner!.cachedObjectTable.AsSpan();
|
||||
for (this.index++; this.index < ObjectTableLength; this.index++)
|
||||
{
|
||||
if (cache[this.index].Update() is { } ao)
|
||||
{
|
||||
this.Current = ao;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void InitializeForPooledObjects(ObjectTable ot) => this.owner = ot;
|
||||
|
||||
public void Reset() => this.index = -1;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (this.owner is not { } o)
|
||||
return;
|
||||
|
||||
if (this.slotId == -1)
|
||||
o.multiThreadedEnumerators.Return(this);
|
||||
else
|
||||
o.frameworkThreadEnumerators[this.slotId] = this;
|
||||
}
|
||||
|
||||
public bool TryReset()
|
||||
{
|
||||
this.Reset();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public unsafe partial class GameObject : IEquatable<GameObject>
|
|||
/// <summary>
|
||||
/// Gets the address of the game object in memory.
|
||||
/// </summary>
|
||||
public IntPtr Address { get; }
|
||||
public IntPtr Address { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Dalamud instance.
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ namespace Dalamud.Game;
|
|||
internal sealed class Framework : IInternalDisposableService, IFramework
|
||||
{
|
||||
private static readonly ModuleLog Log = new("Framework");
|
||||
|
||||
|
||||
private static readonly Stopwatch StatsStopwatch = new();
|
||||
|
||||
|
||||
private readonly GameLifecycle lifecycle;
|
||||
|
||||
private readonly Stopwatch updateStopwatch = new();
|
||||
|
|
@ -87,6 +87,11 @@ internal sealed class Framework : IInternalDisposableService, IFramework
|
|||
/// <inheritdoc/>
|
||||
public event IFramework.OnUpdateDelegate? Update;
|
||||
|
||||
/// <summary>
|
||||
/// Executes during FrameworkUpdate before all <see cref="Update"/> delegates.
|
||||
/// </summary>
|
||||
internal event IFramework.OnUpdateDelegate BeforeUpdate;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the collection of stats is enabled.
|
||||
/// </summary>
|
||||
|
|
@ -333,7 +338,7 @@ internal sealed class Framework : IInternalDisposableService, IFramework
|
|||
this.updateStopwatch.Reset();
|
||||
StatsStopwatch.Reset();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Adds a update time to the stats history.
|
||||
/// </summary>
|
||||
|
|
@ -360,7 +365,7 @@ internal sealed class Framework : IInternalDisposableService, IFramework
|
|||
internal void ProfileAndInvoke(IFramework.OnUpdateDelegate? eventDelegate, IFramework frameworkInstance)
|
||||
{
|
||||
if (eventDelegate is null) return;
|
||||
|
||||
|
||||
var invokeList = eventDelegate.GetInvocationList();
|
||||
|
||||
// Individually invoke OnUpdate handlers and time them.
|
||||
|
|
@ -392,6 +397,8 @@ internal sealed class Framework : IInternalDisposableService, IFramework
|
|||
|
||||
ThreadSafety.MarkMainThread();
|
||||
|
||||
this.BeforeUpdate?.InvokeSafely(this);
|
||||
|
||||
this.hitchDetector.Start();
|
||||
|
||||
try
|
||||
|
|
@ -476,7 +483,7 @@ internal sealed class Framework : IInternalDisposableService, IFramework
|
|||
|
||||
this.hitchDetector.Stop();
|
||||
|
||||
original:
|
||||
original:
|
||||
return this.updateHook.OriginalDisposeSafe(framework);
|
||||
}
|
||||
|
||||
|
|
@ -529,19 +536,19 @@ internal class FrameworkPluginScoped : IInternalDisposableService, IFramework
|
|||
|
||||
/// <inheritdoc/>
|
||||
public DateTime LastUpdate => this.frameworkService.LastUpdate;
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public DateTime LastUpdateUTC => this.frameworkService.LastUpdateUTC;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public TimeSpan UpdateDelta => this.frameworkService.UpdateDelta;
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool IsInFrameworkUpdateThread => this.frameworkService.IsInFrameworkUpdateThread;
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool IsFrameworkUnloading => this.frameworkService.IsFrameworkUnloading;
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
void IInternalDisposableService.DisposeService()
|
||||
{
|
||||
|
|
@ -576,27 +583,27 @@ internal class FrameworkPluginScoped : IInternalDisposableService, IFramework
|
|||
/// <inheritdoc/>
|
||||
public Task<T> RunOnFrameworkThread<T>(Func<T> func)
|
||||
=> this.frameworkService.RunOnFrameworkThread(func);
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task RunOnFrameworkThread(Action action)
|
||||
=> this.frameworkService.RunOnFrameworkThread(action);
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task<T> RunOnFrameworkThread<T>(Func<Task<T>> func)
|
||||
=> this.frameworkService.RunOnFrameworkThread(func);
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task RunOnFrameworkThread(Func<Task> func)
|
||||
=> this.frameworkService.RunOnFrameworkThread(func);
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task<T> RunOnTick<T>(Func<T> func, TimeSpan delay = default, int delayTicks = default, CancellationToken cancellationToken = default)
|
||||
=> this.frameworkService.RunOnTick(func, delay, delayTicks, cancellationToken);
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task RunOnTick(Action action, TimeSpan delay = default, int delayTicks = default, CancellationToken cancellationToken = default)
|
||||
=> this.frameworkService.RunOnTick(action, delay, delayTicks, cancellationToken);
|
||||
|
||||
|
||||
/// <inheritdoc/>
|
||||
public Task<T> RunOnTick<T>(Func<Task<T>> func, TimeSpan delay = default, int delayTicks = default, CancellationToken cancellationToken = default)
|
||||
=> this.frameworkService.RunOnTick(func, delay, delayTicks, cancellationToken);
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ internal class TaskTracker : IInternalDisposableService
|
|||
[ServiceManager.ServiceDependency]
|
||||
private readonly Framework framework = Service<Framework>.Get();
|
||||
|
||||
private MonoMod.RuntimeDetour.Hook? scheduleAndStartHook;
|
||||
// NET8 CHORE
|
||||
// private MonoMod.RuntimeDetour.Hook? scheduleAndStartHook;
|
||||
private bool enabled = false;
|
||||
|
||||
[ServiceManager.ServiceConstructor]
|
||||
|
|
@ -121,7 +122,8 @@ internal class TaskTracker : IInternalDisposableService
|
|||
/// <inheritdoc/>
|
||||
void IInternalDisposableService.DisposeService()
|
||||
{
|
||||
this.scheduleAndStartHook?.Dispose();
|
||||
// NET8 CHORE
|
||||
// this.scheduleAndStartHook?.Dispose();
|
||||
|
||||
this.framework.Update -= this.FrameworkOnUpdate;
|
||||
}
|
||||
|
|
@ -170,7 +172,8 @@ internal class TaskTracker : IInternalDisposableService
|
|||
return;
|
||||
}
|
||||
|
||||
this.scheduleAndStartHook = new MonoMod.RuntimeDetour.Hook(targetMethod, patchMethod);
|
||||
// NET8 CHORE
|
||||
// this.scheduleAndStartHook = new MonoMod.RuntimeDetour.Hook(targetMethod, patchMethod);
|
||||
|
||||
Log.Information("AddToActiveTasks Hooked!");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,7 +145,8 @@ internal partial class PluginManager : IInternalDisposableService
|
|||
this.configuration.PluginTestingOptIns ??= new();
|
||||
this.MainRepo = PluginRepository.CreateMainRepo(this.happyHttpClient);
|
||||
|
||||
this.ApplyPatches();
|
||||
// NET8 CHORE
|
||||
//this.ApplyPatches();
|
||||
|
||||
registerStartupBlocker(
|
||||
Task.Run(this.LoadAndStartLoadSyncPlugins),
|
||||
|
|
@ -422,8 +423,9 @@ internal partial class PluginManager : IInternalDisposableService
|
|||
}
|
||||
}
|
||||
|
||||
this.assemblyLocationMonoHook?.Dispose();
|
||||
this.assemblyCodeBaseMonoHook?.Dispose();
|
||||
// NET8 CHORE
|
||||
// this.assemblyLocationMonoHook?.Dispose();
|
||||
// this.assemblyCodeBaseMonoHook?.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -842,7 +844,8 @@ internal partial class PluginManager : IInternalDisposableService
|
|||
this.installedPluginsList.Remove(plugin);
|
||||
}
|
||||
|
||||
PluginLocations.Remove(plugin.AssemblyName?.FullName ?? string.Empty, out _);
|
||||
// NET8 CHORE
|
||||
// PluginLocations.Remove(plugin.AssemblyName?.FullName ?? string.Empty, out _);
|
||||
|
||||
this.NotifyinstalledPluginsListChanged();
|
||||
this.NotifyAvailablePluginsChanged();
|
||||
|
|
@ -1583,7 +1586,8 @@ internal partial class PluginManager : IInternalDisposableService
|
|||
}
|
||||
catch (InvalidPluginException)
|
||||
{
|
||||
PluginLocations.Remove(plugin.AssemblyName?.FullName ?? string.Empty, out _);
|
||||
// NET8 CHORE
|
||||
// PluginLocations.Remove(plugin.AssemblyName?.FullName ?? string.Empty, out _);
|
||||
throw;
|
||||
}
|
||||
catch (BannedPluginException)
|
||||
|
|
@ -1629,7 +1633,8 @@ internal partial class PluginManager : IInternalDisposableService
|
|||
}
|
||||
else
|
||||
{
|
||||
PluginLocations.Remove(plugin.AssemblyName?.FullName ?? string.Empty, out _);
|
||||
// NET8 CHORE
|
||||
// PluginLocations.Remove(plugin.AssemblyName?.FullName ?? string.Empty, out _);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
@ -1756,6 +1761,8 @@ internal partial class PluginManager : IInternalDisposableService
|
|||
}
|
||||
}
|
||||
|
||||
// NET8 CHORE
|
||||
/*
|
||||
/// <summary>
|
||||
/// Class responsible for loading and unloading plugins.
|
||||
/// This contains the assembly patching functionality to resolve assembly locations.
|
||||
|
|
@ -1863,3 +1870,4 @@ internal partial class PluginManager
|
|||
this.assemblyCodeBaseMonoHook = new MonoMod.RuntimeDetour.Hook(codebaseTarget, codebasePatch);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -404,7 +404,8 @@ internal class LocalPlugin : IDisposable
|
|||
}
|
||||
|
||||
// Update the location for the Location and CodeBase patches
|
||||
PluginManager.PluginLocations[this.pluginType.Assembly.FullName] = new PluginPatchData(this.DllFile);
|
||||
// NET8 CHORE
|
||||
// PluginManager.PluginLocations[this.pluginType.Assembly.FullName] = new PluginPatchData(this.DllFile);
|
||||
|
||||
this.DalamudInterface =
|
||||
new DalamudPluginInterface(this, reason);
|
||||
|
|
|
|||
|
|
@ -1,24 +1,27 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
using Dalamud.Utility;
|
||||
|
||||
namespace Dalamud.Plugin.Services;
|
||||
|
||||
/// <summary>
|
||||
/// This collection represents the currently spawned FFXIV game objects.
|
||||
/// </summary>
|
||||
[Api10ToDo(
|
||||
"Make it an IEnumerable<GameObject> instead. Skipping null objects make IReadOnlyCollection<T>.Count yield incorrect values.")]
|
||||
public interface IObjectTable : IReadOnlyCollection<GameObject>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the address of the object table.
|
||||
/// </summary>
|
||||
public nint Address { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the length of the object table.
|
||||
/// </summary>
|
||||
public int Length { get; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Get an object at the specified spawn index.
|
||||
/// </summary>
|
||||
|
|
@ -32,14 +35,14 @@ public interface IObjectTable : IReadOnlyCollection<GameObject>
|
|||
/// <param name="objectId">Object ID to find.</param>
|
||||
/// <returns>A game object or null.</returns>
|
||||
public GameObject? SearchById(ulong objectId);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the address of the game object at the specified index of the object table.
|
||||
/// </summary>
|
||||
/// <param name="index">The index of the object.</param>
|
||||
/// <returns>The memory address of the object.</returns>
|
||||
public nint GetObjectAddress(int index);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create a reference to an FFXIV game object.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ internal static class SignatureHelper
|
|||
|
||||
switch (sig.UseFlags)
|
||||
{
|
||||
case SignatureUseFlags.Auto when actualType == typeof(IntPtr) || actualType.IsPointer || actualType.IsAssignableTo(typeof(Delegate)):
|
||||
case SignatureUseFlags.Auto when actualType == typeof(IntPtr) || actualType.IsFunctionPointer || actualType.IsUnmanagedFunctionPointer || actualType.IsPointer || actualType.IsAssignableTo(typeof(Delegate)):
|
||||
case SignatureUseFlags.Pointer:
|
||||
{
|
||||
if (actualType.IsAssignableTo(typeof(Delegate)))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"sdk": {
|
||||
"version": "7.0.0",
|
||||
"rollForward": "latestMajor",
|
||||
"version": "8.0.0",
|
||||
"rollForward": "latestMinor",
|
||||
"allowPrerelease": true
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit ac2ced26fc98153c65f5b8f0eaf0f464258ff683
|
||||
Subproject commit 2c885a35e0edf8ab7a335e3296f06642837afbec
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Platforms>x64</Platforms>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue