Skip to content
This repository has been archived by the owner on May 11, 2024. It is now read-only.

Commit

Permalink
v1.00.00
Browse files Browse the repository at this point in the history
  • Loading branch information
Razmoth committed Sep 22, 2023
1 parent d594f90 commit 6ebeaee
Show file tree
Hide file tree
Showing 48 changed files with 5,886 additions and 81 deletions.
756 changes: 699 additions & 57 deletions AssetStudio/Classes/AnimationClip.cs

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions AssetStudio/Classes/Avatar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ public Skeleton(ObjectReader reader)

public class SkeletonPose
{
public xform[] m_X;
public XForm[] m_X;

public SkeletonPose(ObjectReader reader)
{
int numXforms = reader.ReadInt32();
m_X = new xform[numXforms];
m_X = new XForm[numXforms];
for (int i = 0; i < numXforms; i++)
{
m_X[i] = new xform(reader);
m_X[i] = reader.ReadXForm(reader.version);
}
}
}
Expand All @@ -118,21 +118,21 @@ public Hand(ObjectReader reader)

public class Handle
{
public xform m_X;
public XForm m_X;
public uint m_ParentHumanIndex;
public uint m_ID;

public Handle(ObjectReader reader)
{
m_X = new xform(reader);
m_X = reader.ReadXForm(reader.version);
m_ParentHumanIndex = reader.ReadUInt32();
m_ID = reader.ReadUInt32();
}
}

public class Collider
{
public xform m_X;
public XForm m_X;
public uint m_Type;
public uint m_XMotionType;
public uint m_YMotionType;
Expand All @@ -144,7 +144,7 @@ public class Collider

public Collider(ObjectReader reader)
{
m_X = new xform(reader);
m_X = reader.ReadXForm(reader.version);
m_Type = reader.ReadUInt32();
m_XMotionType = reader.ReadUInt32();
m_YMotionType = reader.ReadUInt32();
Expand All @@ -158,7 +158,7 @@ public Collider(ObjectReader reader)

public class Human
{
public xform m_RootX;
public XForm m_RootX;
public Skeleton m_Skeleton;
public SkeletonPose m_SkeletonPose;
public Hand m_LeftHand;
Expand All @@ -183,7 +183,7 @@ public class Human
public Human(ObjectReader reader)
{
var version = reader.version;
m_RootX = new xform(reader);
m_RootX = reader.ReadXForm(reader.version);
m_Skeleton = new Skeleton(reader);
m_SkeletonPose = new SkeletonPose(reader);
m_LeftHand = new Hand(reader);
Expand Down Expand Up @@ -243,7 +243,7 @@ public class AvatarConstant
public int[] m_HumanSkeletonIndexArray;
public int[] m_HumanSkeletonReverseIndexArray;
public int m_RootMotionBoneIndex;
public xform m_RootMotionBoneX;
public XForm m_RootMotionBoneX;
public Skeleton m_RootMotionSkeleton;
public SkeletonPose m_RootMotionSkeletonPose;
public int[] m_RootMotionSkeletonIndexArray;
Expand Down Expand Up @@ -271,7 +271,7 @@ public AvatarConstant(ObjectReader reader)
}

m_RootMotionBoneIndex = reader.ReadInt32();
m_RootMotionBoneX = new xform(reader);
m_RootMotionBoneX = reader.ReadXForm(reader.version);

if (version[0] > 4 || (version[0] == 4 && version[1] >= 3)) //4.3 and up
{
Expand Down
3 changes: 2 additions & 1 deletion AssetStudio/Classes/Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ public BlendShapeVertex(ObjectReader reader)

public class MeshBlendShape
{
public string name;
public uint firstVertex;
public uint vertexCount;
public bool hasNormals;
Expand All @@ -308,7 +309,7 @@ public MeshBlendShape(ObjectReader reader)

if (version[0] == 4 && version[1] < 3) //4.3 down
{
var name = reader.ReadAlignedString();
name = reader.ReadAlignedString();
}
firstVertex = reader.ReadUInt32();
vertexCount = reader.ReadUInt32();
Expand Down
23 changes: 21 additions & 2 deletions AssetStudio/Classes/PPtr.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
using System;
using System.IO;
using System.Collections.Generic;
using static AssetStudio.AssetsHelper;

namespace AssetStudio
{
public sealed class PPtr<T> where T : Object
public sealed class PPtr<T> : IYAMLExportable where T : Object
{
public int m_FileID;
public long m_PathID;

private SerializedFile assetsFile;
private int index = -2; //-2 - Prepare, -1 - Missing

public PPtr(int m_FileID, long m_PathID, SerializedFile assetsFile)
{
this.m_FileID = m_FileID;
this.m_PathID = m_PathID;
this.assetsFile = assetsFile;
}

public PPtr(ObjectReader reader)
{
m_FileID = reader.ReadInt32();
m_PathID = reader.m_Version < SerializedFileFormatVersion.Unknown_14 ? reader.ReadInt32() : reader.ReadInt64();
assetsFile = reader.assetsFile;
}

public YAMLNode ExportYAML(int[] version)
{
var node = new YAMLMappingNode();
node.Style = MappingStyle.Flow;
node.Add("fileID", m_FileID);
return node;
}

private bool TryGetAssetsFile(out SerializedFile result)
{
result = null;
Expand Down Expand Up @@ -129,6 +143,11 @@ public void Set(T m_Object)
m_PathID = m_Object.m_PathID;
}

public PPtr<T2> Cast<T2>() where T2 : Object
{
return new PPtr<T2>(m_FileID, m_PathID, assetsFile);
}

public bool IsNull => m_PathID == 0 || m_FileID < 0;
}
}
24 changes: 24 additions & 0 deletions AssetStudio/EndianBinaryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,20 @@ public Matrix4x4 ReadMatrix()
return new Matrix4x4(ReadSingleArray(16));
}

public XForm ReadXForm(int[] version, bool isVector4 = false)
{
var t = (version[0] > 5 || (version[0] == 5 && version[1] >= 4)) && !isVector4 ? ReadVector3() : (Vector3)ReadVector4();//5.4 and up
var q = ReadQuaternion();
var s = (version[0] > 5 || (version[0] == 5 && version[1] >= 4)) && !isVector4 ? ReadVector3() : (Vector3)ReadVector4();//5.4 and up

return new XForm(t, q, s);
}

public Float ReadFloat()
{
return new Float(ReadSingle());
}

public int ReadMhy0Int()
{
var buffer = ReadBytes(6);
Expand Down Expand Up @@ -224,6 +238,16 @@ public byte[] ReadUInt8Array()
return ReadBytes(ReadInt32());
}

public short[] ReadInt16Array()
{
return ReadArray(ReadInt16, ReadInt32());
}

public short[] ReadInt16Array(int length)
{
return ReadArray(ReadInt16, length);
}

public ushort[] ReadUInt16Array()
{
return ReadArray(ReadUInt16, ReadInt32());
Expand Down
24 changes: 24 additions & 0 deletions AssetStudio/Extensions/StreamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,29 @@ public static void CopyTo(this Stream source, Stream destination, long size)
}
}
}

public static void AlignStream(this Stream stream)
{
stream.AlignStream(4);
}

public static void AlignStream(this Stream stream, int alignment)
{
var pos = stream.Position;
var mod = pos % alignment;
if (mod != 0)
{
var rem = alignment - mod;
for (int _ = 0; _ < rem; _++)
{
if (!stream.CanWrite)
{
throw new IOException("End of stream");
}

stream.WriteByte(0);
}
}
}
}
}
27 changes: 27 additions & 0 deletions AssetStudio/Math/Float.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace AssetStudio
{
public struct Float : IYAMLExportable
{
public float Value;

public Float(float value)
{
Value = value;
}

public static implicit operator Float(float value)
{
return new Float(value);
}

public static implicit operator float(Float value)
{
return value.Value;
}

public YAMLNode ExportYAML(int[] version)
{
return new YAMLScalarNode(Value);
}
}
}
12 changes: 11 additions & 1 deletion AssetStudio/Math/Quaternion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace AssetStudio
{
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct Quaternion : IEquatable<Quaternion>
public struct Quaternion : IEquatable<Quaternion>, IYAMLExportable
{
public float X;
public float Y;
Expand Down Expand Up @@ -83,6 +83,16 @@ private static bool IsEqualUsingDot(float dot)
{
return !(lhs == rhs);
}
public YAMLNode ExportYAML(int[] version)
{
var node = new YAMLMappingNode();
node.Style = MappingStyle.Flow;
node.Add("x", X);
node.Add("y", Y);
node.Add("z", Z);
node.Add("w", W);
return node;
}

private const float kEpsilon = 0.000001F;
}
Expand Down
12 changes: 11 additions & 1 deletion AssetStudio/Math/Vector3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace AssetStudio
{
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct Vector3 : IEquatable<Vector3>
public struct Vector3 : IEquatable<Vector3>, IYAMLExportable
{
public float X;
public float Y;
Expand Down Expand Up @@ -87,6 +87,16 @@ public float LengthSquared()
return X * X + Y * Y + Z * Z;
}

public YAMLNode ExportYAML(int[] version)
{
var node = new YAMLMappingNode();
node.Style = MappingStyle.Flow;
node.Add("x", X);
node.Add("y", Y);
node.Add("z", Z);
return node;
}

public static Vector3 Zero => new Vector3();

public static Vector3 One => new Vector3(1.0f, 1.0f, 1.0f);
Expand Down
71 changes: 71 additions & 0 deletions AssetStudio/Math/XForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Runtime.InteropServices;

namespace AssetStudio
{
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct XForm : IEquatable<XForm>
{
public Vector3 t;
public Quaternion q;
public Vector3 s;

public XForm(Vector3 t, Quaternion q, Vector3 s)
{
this.t = t;
this.q = q;
this.s = s;
}
public float this[int index]
{
get
{
switch (index)
{
case 0: return t.X;
case 1: return t.Y;
case 2: return t.Z;
case 3: return q.X;
case 4: return q.Y;
case 5: return q.Z;
case 6: return q.W;
case 7: return s.X;
case 8: return s.Y;
case 9: return s.Z;
default: throw new ArgumentOutOfRangeException(nameof(index), "Invalid xform index!");
}
}

set
{
switch (index)
{
case 0: t.X = value; break;
case 1: t.Y = value; break;
case 2: t.Z = value; break;
case 3: q.X = value; break;
case 4: q.Y = value; break;
case 5: q.Z = value; break;
case 6: q.W = value; break;
case 7: s.X = value; break;
case 8: s.Y = value; break;
case 9: s.Z = value; break;
default:
throw new ArgumentOutOfRangeException(nameof(index), "Invalid xform index!");
}
}
}

public override int GetHashCode()
{
return t.GetHashCode() ^ (q.GetHashCode() << 2) ^ (s.GetHashCode() >> 2);
}

bool IEquatable<XForm>.Equals(XForm other)
{
return t.Equals(other.t) && q.Equals(other.q) && s.Equals(other.s);
}

public static XForm Zero => new XForm(Vector3.Zero, Quaternion.Zero, Vector3.One);
}
}
Loading

0 comments on commit 6ebeaee

Please sign in to comment.