mirror of
https://github.com/AssetRipper/AssetRipper.Mining.git
synced 2026-11-14 06:18:09 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
51873aaef9 | ||
|
|
a43a560f9a | ||
|
|
54eb41b856 | ||
|
|
2b22375c90 | ||
|
|
d989f9f16a | ||
|
|
19fb8b36dd | ||
|
|
9479c1aa66 | ||
|
|
5bb396ffda | ||
|
|
e014834c04 | ||
|
|
bf8806c154 |
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,8 +112,11 @@ 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(),
|
||||
};
|
||||
}
|
||||
break;
|
||||
@@ -123,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>();
|
||||
@@ -188,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;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using AssetRipper.Import.Structure.Assembly.Serializable;
|
||||
using AssetRipper.Mining.PredefinedAssets;
|
||||
using System.Numerics;
|
||||
|
||||
namespace AssetRipper.Mining.EngineFileExtractor;
|
||||
|
||||
internal static class SerializableValueExtensions
|
||||
{
|
||||
public static Vector3 AsVector3(this SerializableValue value)
|
||||
{
|
||||
return new Vector3(value["x"].AsSingle, value["y"].AsSingle, value["z"].AsSingle);
|
||||
}
|
||||
|
||||
public static AxisAlignedBoundingBox AsAxisAlignedBoundingBox(this SerializableValue value)
|
||||
{
|
||||
return new AxisAlignedBoundingBox(value["m_Center"].AsVector3(), value["m_Extent"].AsVector3());
|
||||
}
|
||||
}
|
||||
+9
-6
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>net5.0;net7.0;net8.0</TargetFrameworks>
|
||||
<TargetFrameworks>net4.8;net7.0;net8.0</TargetFrameworks>
|
||||
<LangVersion>Latest</LangVersion>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
@@ -11,14 +11,17 @@
|
||||
</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">
|
||||
<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>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
using System.Numerics;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace AssetRipper.Mining.PredefinedAssets.Tests;
|
||||
|
||||
public class Tests
|
||||
@@ -40,4 +43,43 @@ public class Tests
|
||||
return package.ToJson();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Vector3Serialization()
|
||||
{
|
||||
string result = """
|
||||
{
|
||||
"X": 1,
|
||||
"Y": 2,
|
||||
"Z": 3
|
||||
}
|
||||
""".Replace("\r", null);
|
||||
Vector3 vector = new Vector3(1.0f, 2.0f, 3.0f);
|
||||
Assert.That(JsonSerializer.Serialize(vector, MiningSerializerContext.Default.Vector3).Replace("\r", null), Is.EqualTo(result));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Vector3Deserialization()
|
||||
{
|
||||
string json = """{ "X": 1.0, "Y": 2.0, "Z": 3.0 }""";
|
||||
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.0</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.1" />
|
||||
<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>
|
||||
@@ -2,4 +2,4 @@ using System.Numerics;
|
||||
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
|
||||
public record struct AxisAlignedBoundingBox(Vector3 Center, Vector3 Extents);
|
||||
public record struct AxisAlignedBoundingBox(Vector3 Center, Vector3 Extent);
|
||||
@@ -1,20 +1,35 @@
|
||||
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()
|
||||
{
|
||||
return JsonSerializer.Serialize(this, InternalSerializerContext.Default.EngineResourceData);
|
||||
return JsonSerializer.Serialize(this, MiningSerializerContext.Default.EngineResourceData);
|
||||
}
|
||||
|
||||
public static EngineResourceData FromJson(string text)
|
||||
{
|
||||
return JsonSerializer.Deserialize(text, InternalSerializerContext.Default.EngineResourceData);
|
||||
return string.IsNullOrEmpty(text)
|
||||
? new()
|
||||
: JsonSerializer.Deserialize(text, MiningSerializerContext.Default.EngineResourceData);
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -2,10 +2,10 @@
|
||||
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
|
||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||
[JsonSourceGenerationOptions(WriteIndented = true, IncludeFields = true)]
|
||||
[JsonSerializable(typeof(EngineResourceData))]
|
||||
[JsonSerializable(typeof(UnityPackageData))]
|
||||
[JsonSerializable(typeof(ReferenceAssemblyData))]
|
||||
internal sealed partial class InternalSerializerContext : JsonSerializerContext
|
||||
public sealed partial class MiningSerializerContext : JsonSerializerContext
|
||||
{
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -59,11 +59,11 @@ public abstract record class Object
|
||||
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonSerializer.Serialize(this, InternalSerializerContext.Default.Object);
|
||||
return JsonSerializer.Serialize(this, MiningSerializerContext.Default.Object);
|
||||
}
|
||||
|
||||
public static Object? FromJson(string text)
|
||||
{
|
||||
return JsonSerializer.Deserialize(text, InternalSerializerContext.Default.Object);
|
||||
return JsonSerializer.Deserialize(text, MiningSerializerContext.Default.Object);
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -6,11 +6,11 @@ public readonly record struct ReferenceAssemblyData(List<string> Unity, List<str
|
||||
{
|
||||
public string ToJson()
|
||||
{
|
||||
return JsonSerializer.Serialize(this, InternalSerializerContext.Default.ReferenceAssemblyData);
|
||||
return JsonSerializer.Serialize(this, MiningSerializerContext.Default.ReferenceAssemblyData);
|
||||
}
|
||||
|
||||
public static ReferenceAssemblyData FromJson(string json)
|
||||
{
|
||||
return JsonSerializer.Deserialize<ReferenceAssemblyData>(json, InternalSerializerContext.Default.ReferenceAssemblyData);
|
||||
return JsonSerializer.Deserialize<ReferenceAssemblyData>(json, MiningSerializerContext.Default.ReferenceAssemblyData);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,4 @@
|
||||
using AssetRipper.Primitives;
|
||||
using System.Text.Json;
|
||||
#if NETSTANDARD
|
||||
using AssemblyDictionary = System.Collections.Generic.Dictionary<string, string>;
|
||||
#else
|
||||
using AssemblyDictionary = System.Collections.Generic.Dictionary<string, AssetRipper.Primitives.UnityGuid>;
|
||||
#endif
|
||||
using System.Text.Json;
|
||||
|
||||
namespace AssetRipper.Mining.PredefinedAssets;
|
||||
|
||||
@@ -23,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())
|
||||
@@ -36,11 +30,11 @@ public readonly record struct UnityPackageData(
|
||||
|
||||
public readonly string ToJson()
|
||||
{
|
||||
return JsonSerializer.Serialize(this, InternalSerializerContext.Default.UnityPackageData);
|
||||
return JsonSerializer.Serialize(this, MiningSerializerContext.Default.UnityPackageData);
|
||||
}
|
||||
|
||||
public static UnityPackageData FromJson(string text)
|
||||
{
|
||||
return JsonSerializer.Deserialize(text, InternalSerializerContext.Default.UnityPackageData);
|
||||
return JsonSerializer.Deserialize(text, MiningSerializerContext.Default.UnityPackageData);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
Reference in new issue
Block a user