Move AssetReader to the shader module

This commit is contained in:
Jeremy Pritts 2023-11-06 23:02:47 -05:00
parent e272e6f9df
commit b82be98c65
12 changed files with 47 additions and 92 deletions

View File

@ -1,31 +0,0 @@
using AssetRipper.Assets.Collections;
using AssetRipper.IO.Endian;
namespace AssetRipper.Assets.IO.Reading
{
public sealed class AssetReader : EndianReader
{
public AssetReader(Stream stream, AssetCollection assetCollection) : base(stream, assetCollection.EndianType, false)
{
AssetCollection = assetCollection;
}
public override string ReadString()
{
int length = ReadInt32();
if (length == 0)
{
return string.Empty;
}
string ret = ReadString(length);
AlignStream();
//Strings have supposedly been aligned since 2.1.0,
//which is earlier than the beginning of AssetRipper version support.
return ret;
}
public AssetCollection AssetCollection { get; }
}
}

View File

@ -1,19 +0,0 @@
using AssetRipper.IO.Endian;
using AssetRipper.IO.Files.SerializedFiles;
namespace AssetRipper.Assets.IO.Reading;
public static class EndianSpanReadableExtensions
{
public static void Read(this IEndianSpanReadable asset, ref EndianSpanReader reader, TransferInstructionFlags flags)
{
if (flags.IsRelease())
{
asset.ReadRelease(ref reader);
}
else
{
asset.ReadEditor(ref reader);
}
}
}

View File

@ -1,29 +0,0 @@
using AssetRipper.IO.Files.SerializedFiles;
namespace AssetRipper.Assets.IO.Reading
{
public interface IAssetReadable
{
void ReadEditor(AssetReader reader);
void ReadRelease(AssetReader reader);
}
public static class AssetReadableExtensions
{
public static void Read(this IAssetReadable asset, AssetReader reader)
{
asset.Read(reader, reader.AssetCollection.Flags);
}
public static void Read(this IAssetReadable asset, AssetReader reader, TransferInstructionFlags flags)
{
if (flags.IsRelease())
{
asset.ReadRelease(reader);
}
else
{
asset.ReadEditor(reader);
}
}
}
}

View File

@ -4,6 +4,7 @@ using AssetRipper.Assets.IO.Serialization;
using AssetRipper.Assets.IO.Writing; using AssetRipper.Assets.IO.Writing;
using AssetRipper.Assets.Metadata; using AssetRipper.Assets.Metadata;
using AssetRipper.IO.Endian; using AssetRipper.IO.Endian;
using AssetRipper.IO.Files.SerializedFiles;
using System.Text.Json.Nodes; using System.Text.Json.Nodes;
namespace AssetRipper.Assets; namespace AssetRipper.Assets;
@ -33,3 +34,17 @@ public interface IUnityAssetBase : IEndianSpanReadable, IAssetWritable, IYamlExp
JsonNode SerializeReleaseFields(IUnityAssetSerializer serializer, SerializationOptions options); JsonNode SerializeReleaseFields(IUnityAssetSerializer serializer, SerializationOptions options);
IEnumerable<(string, PPtr)> FetchDependencies(); IEnumerable<(string, PPtr)> FetchDependencies();
} }
public static class UnityAssetBaseExtensions
{
public static void Read(this IUnityAssetBase asset, ref EndianSpanReader reader, TransferInstructionFlags flags)
{
if (flags.IsRelease())
{
asset.ReadRelease(ref reader);
}
else
{
asset.ReadEditor(ref reader);
}
}
}

View File

@ -1,6 +1,5 @@
using AssetRipper.Assets.Collections; using AssetRipper.Assets.Collections;
using AssetRipper.Assets.Export; using AssetRipper.Assets.Export;
using AssetRipper.Assets.IO.Reading;
using AssetRipper.Assets.Metadata; using AssetRipper.Assets.Metadata;
using AssetRipper.IO.Endian; using AssetRipper.IO.Endian;
using AssetRipper.Yaml; using AssetRipper.Yaml;

View File

@ -1,6 +1,5 @@
using AssetRipper.Assets.Cloning; using AssetRipper.Assets.Cloning;
using AssetRipper.Assets.Export; using AssetRipper.Assets.Export;
using AssetRipper.Assets.IO.Reading;
using AssetRipper.Assets.IO.Serialization; using AssetRipper.Assets.IO.Serialization;
using AssetRipper.Assets.IO.Writing; using AssetRipper.Assets.IO.Writing;
using AssetRipper.Assets.Metadata; using AssetRipper.Assets.Metadata;
@ -14,12 +13,8 @@ namespace AssetRipper.Assets;
/// <summary> /// <summary>
/// The artificial base class for all generated Unity classes /// The artificial base class for all generated Unity classes
/// </summary> /// </summary>
public abstract class UnityAssetBase : IUnityAssetBase, IAssetReadable public abstract class UnityAssetBase : IUnityAssetBase
{ {
public virtual void ReadEditor(AssetReader reader) => throw MethodNotSupported();
public virtual void ReadRelease(AssetReader reader) => throw MethodNotSupported();
public virtual void ReadEditor(ref EndianSpanReader reader) => throw MethodNotSupported(); public virtual void ReadEditor(ref EndianSpanReader reader) => throw MethodNotSupported();
public virtual void ReadRelease(ref EndianSpanReader reader) => throw MethodNotSupported(); public virtual void ReadRelease(ref EndianSpanReader reader) => throw MethodNotSupported();

View File

@ -0,0 +1,30 @@
using AssetRipper.Assets.Collections;
using AssetRipper.IO.Endian;
namespace AssetRipper.Export.Modules.Shaders;
public sealed class AssetReader : EndianReader
{
public AssetReader(Stream stream, AssetCollection assetCollection) : base(stream, assetCollection.EndianType, false)
{
AssetCollection = assetCollection;
}
public override string ReadString()
{
int length = ReadInt32();
if (length == 0)
{
return string.Empty;
}
string ret = ReadString(length);
AlignStream();
//Strings have supposedly been aligned since 2.1.0,
//which is earlier than the beginning of AssetRipper version support.
return ret;
}
public AssetCollection AssetCollection { get; }
}

View File

@ -1,4 +1,3 @@
using AssetRipper.Assets.IO.Reading;
using AssetRipper.Assets.IO.Writing; using AssetRipper.Assets.IO.Writing;
using AssetRipper.Export.Modules.Shaders.ShaderBlob.Parameters; using AssetRipper.Export.Modules.Shaders.ShaderBlob.Parameters;
using AssetRipper.Primitives; using AssetRipper.Primitives;

View File

@ -1,6 +1,5 @@
using AssetRipper.Assets.Collections; using AssetRipper.Assets.Collections;
using AssetRipper.Assets.Generics; using AssetRipper.Assets.Generics;
using AssetRipper.Assets.IO.Reading;
using AssetRipper.Assets.IO.Writing; using AssetRipper.Assets.IO.Writing;
using K4os.Compression.LZ4; using K4os.Compression.LZ4;

View File

@ -1,5 +1,4 @@
using AssetRipper.Assets.IO.Reading; using AssetRipper.Assets.IO.Writing;
using AssetRipper.Assets.IO.Writing;
using AssetRipper.Primitives; using AssetRipper.Primitives;
namespace AssetRipper.Export.Modules.Shaders.ShaderBlob namespace AssetRipper.Export.Modules.Shaders.ShaderBlob

View File

@ -1,7 +1,6 @@
using AssetRipper.Assets; using AssetRipper.Assets;
using AssetRipper.Assets.Generics; using AssetRipper.Assets.Generics;
using AssetRipper.Assets.IO; using AssetRipper.Assets.IO;
using AssetRipper.Assets.IO.Reading;
using AssetRipper.Assets.Metadata; using AssetRipper.Assets.Metadata;
using AssetRipper.Import.Logging; using AssetRipper.Import.Logging;
using AssetRipper.Import.Structure.Assembly.Managers; using AssetRipper.Import.Structure.Assembly.Managers;

View File

@ -2,7 +2,6 @@ using AssetRipper.Assets;
using AssetRipper.Assets.Cloning; using AssetRipper.Assets.Cloning;
using AssetRipper.Assets.Export; using AssetRipper.Assets.Export;
using AssetRipper.Assets.Export.Yaml; using AssetRipper.Assets.Export.Yaml;
using AssetRipper.Assets.IO.Reading;
using AssetRipper.Assets.IO.Writing; using AssetRipper.Assets.IO.Writing;
using AssetRipper.Assets.Metadata; using AssetRipper.Assets.Metadata;
using AssetRipper.IO.Endian; using AssetRipper.IO.Endian;