diff --git a/KKdMainLib/A3DA/A3DA.cs b/KKdMainLib/A3DA/A3DA.cs index 7e6405f..fa00cb0 100644 --- a/KKdMainLib/A3DA/A3DA.cs +++ b/KKdMainLib/A3DA/A3DA.cs @@ -11,8 +11,6 @@ namespace KKdMainLib.A3DA { private const bool A3DCOpt = true; private const string d = "."; - private const string BO = "bin_offset"; - private const string MTBO = "model_transform.bin_offset"; private int SOi0; private int SOi1; @@ -77,7 +75,7 @@ namespace KKdMainLib.A3DA } else { IO.Close(); return 0; } - if (Data.Header.Format < Main.Format.F || Data.Header.Format == Main.Format.FT) + if (Data.Header.Format == Main.Format.DT) Data.Head.StringLength = IO.Length - 0x10; string[] STRData = IO.ReadString(Data.Head.StringLength).Replace("\r", "").Split('\n'); @@ -91,7 +89,7 @@ namespace KKdMainLib.A3DA A3DAReader(); - if (Data.Header.Format == Main.Format.F || Data.Header.Format > Main.Format.FT) + if (Data.Header.Format >= Main.Format.F && Data.Header.Format != Main.Format.FT) { IO.Position = IO.Offset + Data.Head.BinaryOffset; IO.Offset = IO.Position; @@ -1251,10 +1249,10 @@ namespace KKdMainLib.A3DA IO.WriteEndian(Data.Head.BinaryOffset, true); IO.WriteEndian(Data.Head.BinaryLength, true); IO.WriteEndian(0x20, true); - if (Data.Header.Format != Main.Format.F) + if (Data.Header.Format > Main.Format.FT) { IO.Position = A3DCEnd; - IO.WriteEOFC(0); + IO.WriteEOFC(); } IO.Close(); @@ -1280,7 +1278,10 @@ namespace KKdMainLib.A3DA if (Key.Trans != null) { Key.BinOffset = IO.Position; - IO.Write(Key.Type); + int Type = Key.Type.Value; + if (Key.EPTypePost.HasValue) Type |= (Key.EPTypePost.Value & 0xF) << 12; + if (Key.EPTypePre .HasValue) Type |= (Key.EPTypePre .Value & 0xF) << 12; + IO.Write(Type); IO.Write(0x00); IO.Write((float)Key.Max); IO.Write(Key.Trans.Length); @@ -1513,11 +1514,11 @@ namespace KKdMainLib.A3DA { Data.MObjectHRC[i0] = new MObjectHRC { - MT = Temp[i].ReadMT(), - Name = Temp[i].ReadString("Name"), + MT = Temp[i0].ReadMT(), + Name = Temp[i0].ReadString("Name"), }; - if (Temp[i].Element("JointOrient", out MsgPack JointOrient)) + if (Temp[i0].Element("JointOrient", out MsgPack JointOrient)) Data.MObjectHRC[i0].JointOrient = new Vector3 { X = JointOrient.ReadDouble("X"), @@ -1525,7 +1526,7 @@ namespace KKdMainLib.A3DA Z = JointOrient.ReadDouble("Z"), }; - if (Temp[i].ElementArray("Instance", out MsgPack Instance)) + if (Temp[i0].ElementArray("Instance", out MsgPack Instance)) { Data.MObjectHRC[i0].Instance = new Instance[Instance.Array.Length]; for (i1 = 0; i1 < Data.MObjectHRC[i0].Instance.Length; i1++) @@ -1538,7 +1539,7 @@ namespace KKdMainLib.A3DA }; } - if (Temp[i].ElementArray("Node", out MsgPack Node)) + if (Temp[i0].ElementArray("Node", out MsgPack Node)) { Data.MObjectHRC[i0].Node = new Node[Temp.Array.Length]; for (i1 = 0; i1 < Data.MObjectHRC[i0].Node.Length; i1++) @@ -1573,15 +1574,15 @@ namespace KKdMainLib.A3DA { Data.Object[i0] = new Object { - MT = Temp[i].ReadMT(), - Morph = Temp[i].ReadString("Morph" ), - MorphOffset = Temp[i].ReadNInt32("MorphOffset"), - Name = Temp[i].ReadString( "Name"), - ParentName = Temp[i].ReadString( "ParentName"), - UIDName = Temp[i].ReadString( "UIDName"), + MT = Temp[i0].ReadMT(), + Morph = Temp[i0].ReadString("Morph" ), + MorphOffset = Temp[i0].ReadNInt32("MorphOffset"), + Name = Temp[i0].ReadString( "Name"), + ParentName = Temp[i0].ReadString( "ParentName"), + UIDName = Temp[i0].ReadString( "UIDName"), }; - if (Temp[i].ElementArray("TP", out MsgPack TP)) + if (Temp[i0].ElementArray("TP", out MsgPack TP)) { Data.Object[i0].TP = new Object.TexturePattern[TP.Array.Length]; for (i1 = 0; i1 < Data.Object[i0].TP.Length; i1++) @@ -1593,7 +1594,7 @@ namespace KKdMainLib.A3DA }; } - if (Temp[i].ElementArray("TT", out MsgPack TT)) + if (Temp[i0].ElementArray("TT", out MsgPack TT)) { Data.Object[i0].TT = new Object.TextureTransform[TT.Array.Length]; for (i1 = 0; i1 < Data.Object[i0].TT.Length; i1++) @@ -1618,12 +1619,12 @@ namespace KKdMainLib.A3DA { Data.ObjectHRC[i0] = new ObjectHRC { - Name = Temp[i].ReadString ( "Name"), - Shadow = Temp[i].ReadNDouble( "Shadow"), - UIDName = Temp[i].ReadString ("UIDName"), + Name = Temp[i0].ReadString ( "Name"), + Shadow = Temp[i0].ReadNDouble( "Shadow"), + UIDName = Temp[i0].ReadString ("UIDName"), }; - if (Temp[i].Element("JointOrient", out MsgPack JointOrient)) + if (Temp[i0].Element("JointOrient", out MsgPack JointOrient)) Data.ObjectHRC[i0].JointOrient = new Vector3 { X = JointOrient.ReadDouble("X"), @@ -1631,7 +1632,7 @@ namespace KKdMainLib.A3DA Z = JointOrient.ReadDouble("Z"), }; - if (Temp[i].ElementArray("Node", out MsgPack Node)) + if (Temp[i0].ElementArray("Node", out MsgPack Node)) { Data.ObjectHRC[i0].Node = new Node[Node.Array.Length]; for (i1 = 0; i1 < Data.ObjectHRC[i0].Node.Length; i1++) @@ -1742,7 +1743,7 @@ namespace KKdMainLib.A3DA if (Data.Chara != null) { MsgPack Chara = new MsgPack(Data.Chara.Length, "Chara"); - for (i = 0; i < Data.Curve.Length; i++) Chara[i] = MsgPack.New.Add(null, Data.Chara[i]); + for (i = 0; i < Data.Chara.Length; i++) Chara[i] = MsgPack.New.Add(null, Data.Chara[i]); A3D.Add(Chara); } @@ -2084,10 +2085,10 @@ namespace KKdMainLib.A3DA public int? Type; public int? Length; public int? BinOffset; + public int? EPTypePre; + public int? EPTypePost; public double? Max; public double? Value; - public double? EPTypePost; - public double? EPTypePre; public RawD RawData; public IKeyFrame[] Trans; diff --git a/KKdMainLib/A3DA/A3DAExt.cs b/KKdMainLib/A3DA/A3DAExt.cs index 2e0e4b7..4a9aac2 100644 --- a/KKdMainLib/A3DA/A3DAExt.cs +++ b/KKdMainLib/A3DA/A3DAExt.cs @@ -270,9 +270,14 @@ namespace KKdMainLib.A3DA Key.Value = IO.ReadSingle(); if (Key.Type == 0x0000 || Key.Type == 0x0001) return; - Key.Max = IO.ReadSingle(); Key.Length = IO.ReadInt32 (); + if (Key.Type >> 8 != 0) + { + Key.EPTypePost = (Key.Type >> 12) & 0xF; + Key.EPTypePre = (Key.Type >> 8) & 0xF; + } + Key.Type = Key.Type & 0xFF; Key.Trans = new IKeyFrame[(int)Key.Length]; KeyFrameT3 Temp; for (int i = 0; i < Key.Length; i++) @@ -356,8 +361,8 @@ namespace KKdMainLib.A3DA { if (k.Object == null) return null; - Key Key = new Key { EPTypePost = k.ReadNDouble("Post"), - EPTypePre = k.ReadNDouble("Pre"), Max = k.ReadNDouble("M"), + Key Key = new Key { EPTypePost = k.ReadNInt32("Post"), + EPTypePre = k.ReadNInt32("Pre"), Max = k.ReadNDouble("M"), Type = k.ReadNInt32("T"), Value = k.ReadNDouble("V") }; if (k.ReadBoolean("RD")) Key.RawData = new Key.RawD() { KeyType = -1, ValueType = "float" }; if (Key.Type == 0) Key.Value = 0.0; diff --git a/KKdMainLib/Aet/Aet.cs b/KKdMainLib/Aet/Aet.cs index 4970d12..5eac7d3 100644 --- a/KKdMainLib/Aet/Aet.cs +++ b/KKdMainLib/Aet/Aet.cs @@ -1,6 +1,5 @@ //Original: AetSet.bt Version: 2.0 by samyuu -//using System.Collections.Generic; using KKdMainLib.IO; using KKdMainLib.Types; using KKdMainLib.MessagePack; @@ -82,7 +81,7 @@ namespace KKdMainLib.Aet for (i0 = 0; i0 < Aet.Layers[i].Count; i0++, i1++) { Aet.Layers[i].Objects[i0] = IO.ReadAetObject(); - Aet.Layers[i].ObjectIDs[i0] = i1; + Aet.Layers[i].Objects[i0].ID = i1; } } @@ -230,7 +229,7 @@ namespace KKdMainLib.Aet bool Found = false; for (int I = 0; I < Aet.Layers.Count; I++) for (int I0 = 0; I0 < Aet.Layers.Entries[I].Count; I0++) - if (Aet.Layers.Entries[I].ObjectIDs[I0] == Obj.Pic.Value.ParentObjectID) + if (Aet.Layers[I][I0].ID == Obj.Pic.Value.ParentObjectID) { Found = true; IO.Write(Aet.Layers.Entries[I].Objects[I0].Offset); @@ -258,7 +257,7 @@ namespace KKdMainLib.Aet bool Found = false; for (int I = 0; I < Aet.Layers.Count; I++) for (int I0 = 0; I0 < Aet.Layers.Entries[I].Count; I0++) - if (Aet.Layers.Entries[I].ObjectIDs[I0] == Obj.Eff.Value.ParentObjectID) + if (Aet.Layers[I][I0].ID == Obj.Eff.Value.ParentObjectID) { Found = true; IO.Write(Aet.Layers.Entries[I].Objects[I0].Offset); @@ -323,7 +322,7 @@ namespace KKdMainLib.Aet AET = new AetHeader(); MsgPack MsgPack = file.ReadMPAllAtOnce(JSON); - if (!MsgPack.ElementArray("Aet", out MsgPack Aet)) { MsgPack = MsgPack.New; return; } + if (!MsgPack.ElementArray("Aet", out MsgPack Aet)) { MsgPack.Dispose(); return; } if (Aet.Array != null) if (Aet.Array.Length > 0) @@ -333,7 +332,7 @@ namespace KKdMainLib.Aet MsgPackReader(Aet.Array[i], ref AET.Data[i] ); } - MsgPack = MsgPack.New; + MsgPack.Dispose(); } public void MsgPackWriter(string file, bool JSON) @@ -385,12 +384,15 @@ namespace KKdMainLib.Aet i = Aet.Layers.Count - 1; if (AET.ElementArray("RootLayer", out Temp)) { - Aet.Layers.Entries[i].Objects = new AetObject[Temp.Array.Length]; + Aet.Layers.Entries[i].Count = Temp.Array.Length; for (i0 = 0; i0 < Aet.Layers[i].Count; i0++) Aet.Layers.Entries[i].Objects[i0].ReadMP(Temp[i0]); } else if (AET.Element("RootLayer", out Temp)) + { + Aet.Layers.Entries[i].Count = 1; Aet.Layers.Entries[i].Objects[0].ReadMP(Temp); + } else return; AetData.Offset = 0; @@ -409,12 +411,12 @@ namespace KKdMainLib.Aet i = Aet.Layers.Count - 1; if (Aet.Layers[i].Count == 1) - AET.Add(Aet.Layers[i][0].WriteMP(ref Aet, Aet.Layers[i].ObjectIDs[0], "RootLayer")); + AET.Add(Aet.Layers[i][0].WriteMP(ref Aet, "RootLayer")); if (Aet.Layers[i].Count > 1) { MsgPack RootLayer = new MsgPack(Aet.Layers[i].Count, "RootLayer"); for (i0 = 0; i0 < Aet.Layers[i].Count; i0++) - RootLayer[i0] = Aet.Layers[i][i0].WriteMP(ref Aet, Aet.Layers[i].ObjectIDs[i0]); + RootLayer[i0] = Aet.Layers[i][i0].WriteMP(ref Aet); AET.Add(RootLayer); } @@ -458,10 +460,9 @@ namespace KKdMainLib.Aet public int Count { get => Objects != null ? Objects.Length : 0; - set { ObjectIDs = new int[value]; Objects = new AetObject[value]; } + set => Objects = new AetObject[value]; } public int Offset; - public int[] ObjectIDs; public AetObject[] Objects; public void ReadMP(MsgPack msg) @@ -484,17 +485,17 @@ namespace KKdMainLib.Aet if (Count < 1) return MsgPack.New.Add("ID", Id); else if (Count == 1) - return MsgPack.New.Add("ID", Id).Add(this.Objects[0].WriteMP(ref Aet, ObjectIDs[0], "Object")); + return MsgPack.New.Add("ID", Id).Add(this.Objects[0].WriteMP(ref Aet, "Object")); MsgPack Objects = new MsgPack(Count, "Objects"); for (int i = 0; i < Count; i++) - Objects[i] = this.Objects[i].WriteMP(ref Aet, ObjectIDs[i]); + Objects[i] = this.Objects[i].WriteMP(ref Aet); return MsgPack.New.Add("ID", Id).Add(Objects); } public AetObject this[int index] { - get { if (Count > 0) return Objects[index]; return default(AetObject); } - set { if (Count > 0) { Objects[index] = value; } } + get => Count > 0 ? Objects[index] : default; + set { if (Count > 0) { Objects[index] = value; } } } public override string ToString() => "Count: " + Count; @@ -502,6 +503,7 @@ namespace KKdMainLib.Aet public struct AetObject { + public int ID; public int Offset; public Pointer Name; public float StartTime0; @@ -516,8 +518,9 @@ namespace KKdMainLib.Aet public Pointer