3 Commits
Author SHA1 Message Date
ds5678 c009d0cab9 Use string version in UnityPackageData and bump version 2024-01-15 20:36:30 -05:00
ds5678 f5d62fccf5 Bump version 2024-01-15 01:14:31 -05:00
ds5678 68a7e1fd2b Add more framework targets 2024-01-15 01:11:04 -05:00
10 changed files with 179 additions and 13 deletions

No files matched your search

@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net5.0;net7.0;net8.0</TargetFrameworks>
<LangVersion>Latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AssetRipper.Mining.PredefinedAssets\AssetRipper.Mining.PredefinedAssets.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,20 @@
namespace AssetRipper.Mining.PredefinedAssets.Tests;
public class Tests
{
[Test]
public void TextAssetSerializesConsistently()
{
//This test ensures that the TextAsset hash is serialized consistently on all the test target frameworks.
TextAsset asset = new TextAsset("Example", "Hello, World!"u8);
string json = asset.ToJson().Replace(Environment.NewLine, "\n");
Assert.That(json, Is.EqualTo("""
{
"$type": "TextAsset",
"Length": 13,
"Hash": 281850845012336186393611809232225740901,
"Name": "Example"
}
""".Replace(Environment.NewLine, "\n")));
}
}
@@ -0,0 +1 @@
global using NUnit.Framework;
@@ -1,14 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>Latest</LangVersion>
<Nullable>enable</Nullable>
<IsTrimmable>true</IsTrimmable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<Authors>ds5678</Authors>
<Company>AssetRipper</Company>
<Version>1.0.0</Version>
<Version>1.0.2</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<PackageId>AssetRipper.Mining.PredefinedAssets</PackageId>
<PackageTags>C# Unity</PackageTags>
@@ -16,7 +17,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl>
<Copyright>Copyright (c) 2023 ds5678</Copyright>
<Copyright>Copyright (c) 2023 - 2024 ds5678</Copyright>
<Description>Library for storing datamined asset information.</Description>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
@@ -25,12 +26,16 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AssetRipper.Primitives" Version="2.0.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PackageReference Include="AssetRipper.Primitives" Version="2.1.1" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="8.0.0-rc.1.23419.4" />
<PackageReference Include="PolySharp" Version="1.14.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="8.0.1" />
</ItemGroup>
</Project>
+12 -1
View File
@@ -1,4 +1,5 @@
using System.Text.Json.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace AssetRipper.Mining.PredefinedAssets;
@@ -55,4 +56,14 @@ public abstract record class Object
_ => 0,
};
}
public string ToJson()
{
return JsonSerializer.Serialize(this, InternalSerializerContext.Default.Object);
}
public static Object? FromJson(string text)
{
return JsonSerializer.Deserialize(text, InternalSerializerContext.Default.Object);
}
}
@@ -31,10 +31,22 @@ public sealed record class TextAsset : NamedObject
private static UInt128 HashData(ReadOnlySpan<byte> data)
{
Span<byte> buffer = stackalloc byte[16];
MD5.HashData(data, buffer);
HashData(data, buffer);
#if NET8_0_OR_GREATER
return BinaryPrimitives.ReadUInt128LittleEndian(buffer);
#else
return new UInt128(
BinaryPrimitives.ReadUInt64LittleEndian(buffer[8..]),
BinaryPrimitives.ReadUInt64LittleEndian(buffer));
//On .NET 8, replace with ReadUInt128LittleEndian
#endif
}
}
private static void HashData(ReadOnlySpan<byte> data, Span<byte> buffer)
{
#if NET5_0_OR_GREATER
MD5.HashData(data, buffer);
#else
MD5.Create().ComputeHash(data.ToArray()).AsSpan().CopyTo(buffer);
#endif
}
}
@@ -0,0 +1,64 @@
#if NET7_0_OR_GREATER
[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(UInt128))]
#else
using AssetRipper.Mining.PredefinedAssets;
using System.Numerics;
using System.Text.Json.Serialization;
namespace System;
/// <summary>
/// A limited polyfill for the UInt128 struct.
/// </summary>
[JsonConverter(typeof(UInt128JsonConverter))]
public readonly record struct UInt128
{
private readonly ulong _lower;
private readonly ulong _upper;
/// <summary>Initializes a new instance of the <see cref="UInt128" /> struct.</summary>
/// <param name="upper">The upper 64-bits of the 128-bit value.</param>
/// <param name="lower">The lower 64-bits of the 128-bit value.</param>
public UInt128(ulong upper, ulong lower)
{
_lower = lower;
_upper = upper;
}
public override string ToString()
{
return _upper == 0 ? _lower.ToString() : ToBigInteger().ToString();
}
public static UInt128 Parse(string value)
{
return TryParse(value, out UInt128 result) ? result : throw new FormatException("Input string was not in a correct format.");
}
public static bool TryParse(string value, out UInt128 result)
{
if (BigInteger.TryParse(value, out BigInteger bigInteger))
{
result = FromBigInteger(bigInteger);
return true;
}
else
{
result = default;
return false;
}
}
private BigInteger ToBigInteger()
{
return (new BigInteger(_upper) << 64) | new BigInteger(_lower);
}
private static UInt128 FromBigInteger(BigInteger value)
{
ulong upper = (ulong)(value >> 64);
ulong lower = (ulong)value;
return new UInt128(upper, lower);
}
}
#endif
@@ -0,0 +1,19 @@
#if !NET7_0_OR_GREATER
using System.Text.Json;
using System.Text.Json.Serialization;
namespace AssetRipper.Mining.PredefinedAssets;
public sealed class UInt128JsonConverter : JsonConverter<UInt128>
{
public override UInt128 Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return UInt128.Parse(reader.GetString() ?? throw new JsonException("String was read as null"));
}
public override void Write(Utf8JsonWriter writer, UInt128 value, JsonSerializerOptions options)
{
writer.WriteRawValue(value.ToString());
}
}
#endif
@@ -10,14 +10,14 @@ namespace AssetRipper.Mining.PredefinedAssets;
/// File extensions are not included in any names.
/// </remarks>
/// <param name="Name">The name of this Unity package.</param>
/// <param name="Version">The version of this Unity package. Only applicable if <paramref name="UsedInPackageJson"/> is true.</param>
/// <param name="Version">The version or git url of this Unity package. Only applicable if <paramref name="UsedInPackageJson"/> is true.</param>
/// <param name="UsedInPackageJson">If true, this Unity package should be referenced in the project's package json file.</param>
/// <param name="Assemblies">A dictionary of compiled dll assemblies in the package.</param>
/// <param name="Scripts">A dictionary of loose cs scripts in the package. Assembly name : { Full name : Guid }</param>
/// <param name="Assets">A dictionary of assets in the package.</param>
public readonly record struct UnityPackageData(
string Name,
Version Version,
string Version,
bool UsedInPackageJson,
Dictionary<string, UnityGuid> Assemblies,
Dictionary<string, Dictionary<string, UnityGuid>> Scripts,
+6
View File
@@ -14,6 +14,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AssetRipper.Mining.Predefin
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AssetRipper.Mining.EngineFileExtractor", "AssetRipper.Mining.EngineFileExtractor\AssetRipper.Mining.EngineFileExtractor.csproj", "{DAD9BA2F-8A03-43D8-A3E5-73493A10AF0B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AssetRipper.Mining.PredefinedAssets.Tests", "AssetRipper.Mining.PredefinedAssets.Tests\AssetRipper.Mining.PredefinedAssets.Tests.csproj", "{C3E8E9EA-1710-4346-B96A-EA757FB13301}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -28,6 +30,10 @@ Global
{DAD9BA2F-8A03-43D8-A3E5-73493A10AF0B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAD9BA2F-8A03-43D8-A3E5-73493A10AF0B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DAD9BA2F-8A03-43D8-A3E5-73493A10AF0B}.Release|Any CPU.Build.0 = Release|Any CPU
{C3E8E9EA-1710-4346-B96A-EA757FB13301}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3E8E9EA-1710-4346-B96A-EA757FB13301}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3E8E9EA-1710-4346-B96A-EA757FB13301}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C3E8E9EA-1710-4346-B96A-EA757FB13301}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE