diff --git a/MiloLib/Assets/Rnd/RndCam.cs b/MiloLib/Assets/Rnd/RndCam.cs index d340bbe..a26148b 100644 --- a/MiloLib/Assets/Rnd/RndCam.cs +++ b/MiloLib/Assets/Rnd/RndCam.cs @@ -60,6 +60,7 @@ public RndCam Read(EndianReader reader, bool standalone, DirectoryMeta parent, D if (revision == 8) { + reader.ReadUInt32(); // coll version objectsCount = reader.ReadUInt32(); for (int i = 0; i < objectsCount; i++) { diff --git a/MiloLib/Assets/Rnd/RndLight.cs b/MiloLib/Assets/Rnd/RndLight.cs index 37b7491..0af59c6 100644 --- a/MiloLib/Assets/Rnd/RndLight.cs +++ b/MiloLib/Assets/Rnd/RndLight.cs @@ -64,9 +64,9 @@ public enum Type public uint unkInt1; public uint unkInt2; - public uint unkInt3; - public uint unkInt4; - public uint unkInt5; + public float constant_atten; + public float linear_atten; + public float quadratic_atten; public RndLight Read(EndianReader reader, bool standalone, DirectoryMeta parent, DirectoryMeta.Entry entry) { @@ -75,18 +75,25 @@ public RndLight Read(EndianReader reader, bool standalone, DirectoryMeta parent, else (altRevision, revision) = ((ushort)(combinedRevision & 0xFFFF), (ushort)((combinedRevision >> 16) & 0xFFFF)); - base.objFields.Read(reader, parent, entry); + if (revision > 3) base.objFields.Read(reader, parent, entry); trans.Read(reader, false, parent, entry); color = color.Read(reader); + + if (revision < 3) + { + reader.ReadFloat(); // inner angle + reader.ReadFloat(); // outer angle + } + range = reader.ReadFloat(); if (revision < 3) { - unkInt3 = reader.ReadUInt32(); - unkInt4 = reader.ReadUInt32(); - unkInt5 = reader.ReadUInt32(); + constant_atten = reader.ReadFloat(); + linear_atten = reader.ReadFloat(); + quadratic_atten = reader.ReadFloat(); } if (revision != 0) @@ -179,9 +186,9 @@ public override void Write(EndianWriter writer, bool standalone, DirectoryMeta p if (revision < 3) { - writer.WriteUInt32(unkInt3); - writer.WriteUInt32(unkInt4); - writer.WriteUInt32(unkInt5); + writer.WriteFloat(constant_atten); + writer.WriteFloat(linear_atten); + writer.WriteFloat(quadratic_atten); } if (revision != 0) diff --git a/MiloLib/Assets/Rnd/RndMat.cs b/MiloLib/Assets/Rnd/RndMat.cs index 3f1a522..65bfd98 100644 --- a/MiloLib/Assets/Rnd/RndMat.cs +++ b/MiloLib/Assets/Rnd/RndMat.cs @@ -116,6 +116,41 @@ public void Write(EndianWriter writer) Symbol.Write(writer, name); } } + + public class TextureEntry_Amp + { + public Blend blendMode; + public int coordIndex; + public TexGen genMode; + public Matrix texXfm = new Matrix(); + public bool useXfm; + public int wrapMode; // differs from TexWrap + public Symbol tex_name = new Symbol(0, ""); + + public TextureEntry_Amp Read(EndianReader reader) + { + blendMode = (Blend)reader.ReadInt32(); + coordIndex = reader.ReadInt32(); + genMode = (TexGen)reader.ReadInt32(); + texXfm = new Matrix().Read(reader); + useXfm = reader.ReadBoolean(); + wrapMode = reader.ReadInt32(); + tex_name = Symbol.Read(reader); + return this; + } + + public void Write(EndianWriter writer) + { + writer.WriteInt32((int)blendMode); + writer.WriteInt32(coordIndex); + writer.WriteInt32((int)genMode); + texXfm.Write(writer); + writer.WriteBoolean(useXfm); + writer.WriteInt32(wrapMode); + Symbol.Write(writer, tex_name); + } + } + private ushort altRevision; private ushort revision; @@ -292,6 +327,9 @@ public void Write(EndianWriter writer) private uint textureCount; public List textures = new(); + private uint textureCountAmp; + public List textures_amp = new(); + public int unkInt1; public int unkInt2; public int unkInt3; @@ -314,6 +352,11 @@ public RndMat Read(EndianReader reader, bool standalone, DirectoryMeta parent, D if (revision <= 9) { + textureCountAmp = reader.ReadUInt32(); + for (int i = 0; i < textureCountAmp; i++) + { + textures_amp.Add(new TextureEntry_Amp().Read(reader)); + } } else if (revision <= 21) { @@ -324,12 +367,33 @@ public RndMat Read(EndianReader reader, bool standalone, DirectoryMeta parent, D } } - base.Read(reader, false, parent, entry); + if (revision > 21) { + base.Read(reader, false, parent, entry); + } blend = (Blend)reader.ReadInt32(); color = new HmxColor4().Read(reader); - if (revision <= 21) + if (revision <= 15) + { + HmxColor4 light_color = new HmxColor4().Read(reader); + HmxColor4 edge_color = new HmxColor4().Read(reader); + reader.ReadByte(); // mat enable? + reader.ReadByte(); // unk + reader.ReadByte(); // do vert lighting + reader.ReadByte(); // do edge highlights + reader.ReadUInt32(); // cull winding dir + reader.ReadUInt32(); // do multipass processing(?) + reader.ReadByte(); // "normalize" + reader.ReadByte(); // do flat shading + reader.ReadByte(); // "base ambient" + if (standalone) + { + if ((reader.Endianness == Endian.BigEndian ? 0xADDEADDE : 0xDEADDEAD) != reader.ReadUInt32()) throw new Exception("Got to end of standalone asset but didn't find the expected end bytes, read likely did not succeed"); + } + return this; + } + else if (revision <= 21) { reader.ReadByte(); reader.ReadUInt16(); diff --git a/MiloLib/Assets/Rnd/RndMatAnim.cs b/MiloLib/Assets/Rnd/RndMatAnim.cs index f0ae3e1..d14c1bb 100644 --- a/MiloLib/Assets/Rnd/RndMatAnim.cs +++ b/MiloLib/Assets/Rnd/RndMatAnim.cs @@ -128,7 +128,67 @@ public override string ToString() public class RndMatAnimStage { + public List transKeys = new List(); + public List scaleKeys = new List(); + public List rotKeys = new List(); + public List texKeys = new List(); + public RndMatAnimStage Read(EndianReader reader) + { + uint transKeysCount = reader.ReadUInt32(); + for (uint i = 0; i < transKeysCount; i++) + { + Vec3Key transKey = new(); + transKey.Read(reader); + transKeys.Add(transKey); + } + uint scaleKeysCount = reader.ReadUInt32(); + for (uint i = 0; i < scaleKeysCount; i++) + { + Vec3Key scaleKey = new(); + scaleKey.Read(reader); + scaleKeys.Add(scaleKey); + } + uint rotKeysCount = reader.ReadUInt32(); + for (uint i = 0; i < rotKeysCount; i++) + { + Vec3Key rotKey = new(); + rotKey.Read(reader); + rotKeys.Add(rotKey); + } + uint texKeysCount = reader.ReadUInt32(); + for (uint i = 0; i < texKeysCount; i++) + { + SymbolKey texKey = new(); + texKey.Read(reader); + texKeys.Add(texKey); + } + return this; + } + + public void Write(EndianWriter writer) + { + writer.WriteUInt32((uint)transKeys.Count); + foreach (Vec3Key transKey in transKeys) + { + transKey.Write(writer); + } + writer.WriteUInt32((uint)scaleKeys.Count); + foreach (Vec3Key scaleKey in scaleKeys) + { + scaleKey.Write(writer); + } + writer.WriteUInt32((uint)rotKeys.Count); + foreach (Vec3Key rotKey in rotKeys) + { + rotKey.Write(writer); + } + writer.WriteUInt32((uint)texKeys.Count); + foreach (SymbolKey texKey in texKeys) + { + texKey.Write(writer); + } + } } private ushort altRevision; @@ -175,8 +235,8 @@ public class RndMatAnimStage private uint colorKeysCount3; [MaxVersion(3)] public List colorKeys3 = new(); - - + [MaxVersion(3)] + public List stages = new(); @@ -195,6 +255,16 @@ public RndMatAnim Read(EndianReader reader, bool standalone, DirectoryMeta paren material = Symbol.Read(reader); + if (revision <= 3) + { + uint stage_ct = reader.ReadUInt32(); + for (uint i = 0; i < stage_ct; i++) { + RndMatAnimStage stage = new(); + stage.Read(reader); + stages.Add(stage); + } + } + keysOwner = Symbol.Read(reader); if (revision > 1) diff --git a/MiloLib/Assets/Rnd/RndMesh.cs b/MiloLib/Assets/Rnd/RndMesh.cs index 9fa17ff..a86b9b4 100644 --- a/MiloLib/Assets/Rnd/RndMesh.cs +++ b/MiloLib/Assets/Rnd/RndMesh.cs @@ -633,12 +633,25 @@ public RndMesh Read(EndianReader reader, bool standalone, DirectoryMeta parent, if (BitConverter.IsLittleEndian) (revision, altRevision) = ((ushort)(combinedRevision & 0xFFFF), (ushort)((combinedRevision >> 16) & 0xFFFF)); else (altRevision, revision) = ((ushort)(combinedRevision & 0xFFFF), (ushort)((combinedRevision >> 16) & 0xFFFF)); - base.Read(reader, false, parent, entry); + if (revision > 25) base.Read(reader, false, parent, entry); trans = trans.Read(reader, false, parent, entry); draw = draw.Read(reader, false, parent, entry); + if (revision < 15) + { + uint collideable_rev = reader.ReadUInt32(); + uint collideable_refs_siz = reader.ReadUInt32(); + for (uint i = 0; i < collideable_refs_siz; i++) + { + Symbol.Read(reader); + } + + uint z_mode = reader.ReadUInt32(); + uint z_comparison_func = reader.ReadUInt32(); + } + mat = Symbol.Read(reader); if (revision == 27) @@ -673,8 +686,6 @@ public RndMesh Read(EndianReader reader, bool standalone, DirectoryMeta parent, unkFloat = reader.ReadFloat(); } - - if (revision < 16) { if (revision > 11) @@ -706,6 +717,15 @@ public RndMesh Read(EndianReader reader, bool standalone, DirectoryMeta parent, faces.Add(new Face().Read(reader)); } + if (revision < 15) { + uint edgeCount = reader.ReadUInt32(); + for (int i = 0; i < edgeCount; i++) + { + reader.ReadUInt16(); + reader.ReadUInt16(); + } + } + if (revision > 0x17) { groupSizesCount = reader.ReadUInt32(); diff --git a/MiloLib/Assets/Rnd/RndParticleSys.cs b/MiloLib/Assets/Rnd/RndParticleSys.cs index 6b9ce1c..732adb5 100644 --- a/MiloLib/Assets/Rnd/RndParticleSys.cs +++ b/MiloLib/Assets/Rnd/RndParticleSys.cs @@ -222,7 +222,7 @@ public RndParticleSys Read(EndianReader reader, bool standalone, DirectoryMeta p life.Read(reader); - if (35 < revision) + if (revision >= 35) heightRatio = reader.ReadFloat(); posLow.Read(reader); @@ -233,7 +233,7 @@ public RndParticleSys Read(EndianReader reader, bool standalone, DirectoryMeta p yaw.Read(reader); emitRate.Read(reader); - if (32 < revision) + if (revision >= 32) { maxBursts = reader.ReadUInt32(); burstInterval.Read(reader); @@ -243,7 +243,7 @@ public RndParticleSys Read(EndianReader reader, bool standalone, DirectoryMeta p startSize.Read(reader); - if (15 < revision) + if (revision >= 15) deltaSize.Read(reader); startColorLow.Read(reader); @@ -252,7 +252,20 @@ public RndParticleSys Read(EndianReader reader, bool standalone, DirectoryMeta p endColorLow.Read(reader); endColorHigh.Read(reader); - bounce = Symbol.Read(reader); + if (revision > 9) + { + bounce = Symbol.Read(reader); + } + else + { + reader.ReadBoolean(); // collide + reader.ReadFloat(); // ???? + reader.ReadFloat(); + reader.ReadFloat(); + reader.ReadFloat(); + reader.ReadFloat(); + reader.ReadFloat(); + } force.Read(reader); @@ -279,7 +292,7 @@ public RndParticleSys Read(EndianReader reader, bool standalone, DirectoryMeta p maxParticles = reader.ReadUInt32(); - if (2 < revision) + if (revision >= 2) { if (revision < 7) { @@ -287,18 +300,26 @@ public RndParticleSys Read(EndianReader reader, bool standalone, DirectoryMeta p } else if (revision < 13) { - unkInt4 = reader.ReadUInt32(); + unkInt4 = reader.ReadUInt32(); // line len } } - if (3 < revision) + if (revision >= 3) { bubblePeriod.Read(reader); bubbleSize.Read(reader); bubble = reader.ReadBoolean(); } - if (29 < revision) + if (revision <= 9) { + reader.ReadBoolean(); // read z + Symbol.Read(reader); + if (standalone) + if ((reader.Endianness == Endian.BigEndian ? 0xADDEADDE : 0xDEADDEAD) != reader.ReadUInt32()) throw new Exception("Got to end of standalone asset but didn't find the expected end bytes, read likely did not succeed"); + return this; + } + + if (revision >= 29) { rotate = reader.ReadBoolean(); rotSpeed.Read(reader); @@ -311,7 +332,7 @@ public RndParticleSys Read(EndianReader reader, bool standalone, DirectoryMeta p drag = reader.ReadUInt32(); } - if (31 < revision) + if (revision >= 31) { swingArmStart.Read(reader); swingArmEnd.Read(reader); @@ -323,17 +344,17 @@ public RndParticleSys Read(EndianReader reader, bool standalone, DirectoryMeta p stretchScale = reader.ReadFloat(); } - if (33 < revision) + if (revision >= 33) { perspectiveStretch = reader.ReadBoolean(); } relativeMotion = reader.ReadFloat(); - if (26 < revision) + if (revision >= 26) relativeParent = Symbol.Read(reader); - if (18 < revision) + if (revision >= 18) mesh = Symbol.Read(reader); if (30 < revision || revision == 21) diff --git a/MiloLib/Assets/Rnd/RndTex.cs b/MiloLib/Assets/Rnd/RndTex.cs index 17c5f6a..752e81c 100644 --- a/MiloLib/Assets/Rnd/RndTex.cs +++ b/MiloLib/Assets/Rnd/RndTex.cs @@ -39,6 +39,8 @@ public enum Type [MinVersion(8)] public float mipMapK; + [MinVersion(5), MaxVersion(5)] + public uint mipMapK_i; public Type type; [MinVersion(11)] @@ -95,7 +97,7 @@ public RndTex Read(EndianReader reader, bool standalone, DirectoryMeta parent, D } else if (revision > 4) { - isRegular = reader.ReadBoolean(); + mipMapK_i = reader.ReadUInt32(); } if (revision >= 11 && parent.revision != 25) @@ -106,7 +108,7 @@ public RndTex Read(EndianReader reader, bool standalone, DirectoryMeta parent, D else useExternalPath = reader.ReadUInt32() == 1; - if (revision == 5) + if (revision == 5 || useExternalPath) { if (standalone) { diff --git a/MiloLib/Assets/Rnd/RndTrans.cs b/MiloLib/Assets/Rnd/RndTrans.cs index cfddaf0..978ad5e 100644 --- a/MiloLib/Assets/Rnd/RndTrans.cs +++ b/MiloLib/Assets/Rnd/RndTrans.cs @@ -99,7 +99,12 @@ public RndTrans Read(EndianReader reader, bool standalone, DirectoryMeta parent, if (revision > 6) preserveScale = reader.ReadBoolean(); - parentObj = Symbol.Read(reader); + if (revision > 5) parentObj = Symbol.Read(reader); + + if (revision <= 5) { + reader.ReadUInt32(); // "billboard" + new Vector3().Read(reader); // "origin" + } if (standalone)