5 Commits
Author SHA1 Message Date
ds5678 51873aaef9 Bump version 2024-08-28 21:27:29 -07:00
ds5678 a43a560f9a Use string instead of UnityGuid on NET Standard 2024-08-28 21:27:23 -07:00
ds5678 54eb41b856 EngineResourceData deserialization improvements 2024-08-15 21:49:21 -07:00
ds5678 2b22375c90 Improve Unity 2 and 3 support 2024-06-01 08:41:50 -07:00
ds5678 d989f9f16a Use SerializableValue indexer property 2024-05-31 20:36:45 -07:00
11 changed files with 63 additions and 33 deletions

No files matched your search

@@ -48,6 +48,10 @@ internal static class Program
private static Dictionary<long, Object> ReadDictionary(string path)
{
if (!File.Exists(path))
{
return [];
}
return LoadAllAssetInfo(path).OrderBy(pair => pair.Key).ToDictionary(pair => pair.Key, pair => pair.Value);
}
@@ -108,7 +112,9 @@ internal static class Program
obj = new Mesh()
{
Name = asset.Name(),
VertexCount = asset.ReleaseFields["m_VertexData"].AsStructure["m_VertexCount"].AsInt32,
VertexCount = asset.ReleaseFields.ContainsField("m_VertexData")
? asset.ReleaseFields["m_VertexData"]["m_VertexCount"].AsInt32
: asset.ReleaseFields["m_CompressedMesh"]["m_Vertices"]["m_NumItems"].AsInt32,
SubMeshCount = asset.ReleaseFields["m_SubMeshes"].AsAssetArray.Length,
LocalAABB = asset.ReleaseFields["m_LocalAABB"].AsAxisAlignedBoundingBox(),
};
@@ -124,7 +130,7 @@ internal static class Program
}
else
{
IUnityAssetBase[] propsList = serializedShader["m_PropInfo"].AsStructure["m_Props"].AsAssetArray;
IUnityAssetBase[] propsList = serializedShader["m_PropInfo"]["m_Props"].AsAssetArray;
if (propsList.Length == 0)
{
propertyNames = Array.Empty<string>();
@@ -189,7 +195,7 @@ internal static class Program
obj = new Sprite()
{
Name = asset.Name(),
Texture = asset.ResolveAsset(asset.ReleaseFields["m_RD"].AsStructure["texture"].AsPPtr)?.Name(),
Texture = asset.ResolveAsset(asset.ReleaseFields["m_RD"]["texture"].AsPPtr)?.Name(),
};
}
break;
@@ -8,16 +8,11 @@ internal static class SerializableValueExtensions
{
public static Vector3 AsVector3(this SerializableValue value)
{
return new Vector3(
value.AsStructure["x"].AsSingle,
value.AsStructure["y"].AsSingle,
value.AsStructure["z"].AsSingle);
return new Vector3(value["x"].AsSingle, value["y"].AsSingle, value["z"].AsSingle);
}
public static AxisAlignedBoundingBox AsAxisAlignedBoundingBox(this SerializableValue value)
{
return new AxisAlignedBoundingBox(
value.AsStructure["m_Center"].AsVector3(),
value.AsStructure["m_Extent"].AsVector3());
return new AxisAlignedBoundingBox(value["m_Center"].AsVector3(), value["m_Extent"].AsVector3());
}
}
@@ -11,10 +11,10 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="NUnit" Version="4.2.1" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
@@ -65,4 +65,21 @@ public class Tests
Vector3 result = new Vector3(1.0f, 2.0f, 3.0f);
Assert.That(JsonSerializer.Deserialize(json, MiningSerializerContext.Default.Vector3), Is.EqualTo(result));
}
[TestCase("")]
[TestCase("{}")]
public void EmptyEngineResourceDataDeserialization(string json)
{
EngineResourceData result = EngineResourceData.FromJson(json);
Assert.Multiple(() =>
{
Assert.That(result.DefaultResources, Is.Not.Null);
Assert.That(result.ExtraResources, Is.Not.Null);
});
Assert.Multiple(() =>
{
Assert.That(result.DefaultResources, Is.Empty);
Assert.That(result.ExtraResources, Is.Empty);
});
}
}
@@ -1,5 +1,4 @@
using AssetRipper.Primitives;
using System.Collections;
using System.Collections;
namespace AssetRipper.Mining.PredefinedAssets;
@@ -9,7 +9,7 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<Authors>ds5678</Authors>
<Company>AssetRipper</Company>
<Version>1.3.2</Version>
<Version>1.4.0</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<PackageId>AssetRipper.Mining.PredefinedAssets</PackageId>
<PackageTags>C# Unity</PackageTags>
@@ -26,7 +26,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AssetRipper.Primitives" Version="3.1.2" />
<PackageReference Include="AssetRipper.Primitives" Version="3.1.3" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -35,7 +35,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>
</Project>
@@ -1,11 +1,24 @@
using System.Text.Json;
using System.Text.Json.Serialization;
namespace AssetRipper.Mining.PredefinedAssets;
public readonly record struct EngineResourceData(Dictionary<long, Object> DefaultResources, Dictionary<long, Object> ExtraResources)
public readonly record struct EngineResourceData
{
public EngineResourceData() : this(new(), new())
{
public Dictionary<long, Object> DefaultResources { get; }
public Dictionary<long, Object> ExtraResources { get; }
public EngineResourceData()
{
DefaultResources = new();
ExtraResources = new();
}
[JsonConstructor]
public EngineResourceData(Dictionary<long, Object>? defaultResources, Dictionary<long, Object>? extraResources)
{
DefaultResources = defaultResources ?? new();
ExtraResources = extraResources ?? new();
}
public readonly string ToJson()
@@ -15,6 +28,8 @@ public readonly record struct EngineResourceData(Dictionary<long, Object> Defaul
public static EngineResourceData FromJson(string text)
{
return JsonSerializer.Deserialize(text, MiningSerializerContext.Default.EngineResourceData);
return string.IsNullOrEmpty(text)
? new()
: JsonSerializer.Deserialize(text, MiningSerializerContext.Default.EngineResourceData);
}
}
@@ -20,6 +20,6 @@ public sealed record class MonoScript : Object
public static MonoScript FromType(Type type)
{
return new MonoScript(type.Assembly.GetName().Name, type.Namespace, type.Name);
return new MonoScript(type.Assembly.GetName().Name ?? "", type.Namespace ?? "", type.Name);
}
}
+1 -3
View File
@@ -1,6 +1,4 @@
using AssetRipper.Primitives;
namespace AssetRipper.Mining.PredefinedAssets;
namespace AssetRipper.Mining.PredefinedAssets;
/// <summary>
/// A data structure representing a reference to an asset.
@@ -1,9 +1,4 @@
using System.Text.Json;
#if NET5_0_OR_GREATER
using AssemblyDictionary = System.Collections.Generic.Dictionary<string, AssetRipper.Primitives.UnityGuid>;
#else
using AssemblyDictionary = System.Collections.Generic.Dictionary<string, string>;
#endif
namespace AssetRipper.Mining.PredefinedAssets;
@@ -22,7 +17,7 @@ public readonly record struct UnityPackageData(
string Name,
string Version,
bool UsedInPackageJson,
AssemblyDictionary Assemblies,
Dictionary<string, UnityGuid> Assemblies,
AssetDictionary Assets)
{
public UnityPackageData(string name, string version, bool usedInPackageJson) : this(name, version, usedInPackageJson, new(), new())
@@ -1 +1,6 @@
global using System.Diagnostics.CodeAnalysis;
#if NET5_0_OR_GREATER
global using UnityGuid = AssetRipper.Primitives.UnityGuid;
#else
global using UnityGuid = string;
#endif