diff --git a/KKdMainLib/F2nd/ENRS.cs b/KKdBaseLib/F2/ENRS.cs similarity index 97% rename from KKdMainLib/F2nd/ENRS.cs rename to KKdBaseLib/F2/ENRS.cs index 98bd175..9fb21be 100644 --- a/KKdMainLib/F2nd/ENRS.cs +++ b/KKdBaseLib/F2/ENRS.cs @@ -1,6 +1,4 @@ -using KKdBaseLib; - -namespace KKdMainLib.F2nd +namespace KKdBaseLib.F2 { public struct ENRS { @@ -10,22 +8,13 @@ namespace KKdMainLib.F2nd public int Repeat; public SubENRS[] Sub; - public struct SubENRS - { - public int Skip; - public int Reverse; - public Type Type; - - public override string ToString() => "Skip: " + Skip + "; Reverse: " + Reverse + "; Type: " + Type; - } - public static unsafe ENRS[] Read(byte[] data) { byte* ptr = data.GetPtr(); int i, i0; int ENRSCount = ((int*)ptr)[1]; ENRS[] ENRSArr = new ENRS[ENRSCount]; - ptr = ptr + 0x10; + ptr += 0x10; ENRS ENR = new ENRS(); for (i = 0; i < ENRSCount; i++) @@ -98,6 +87,15 @@ namespace KKdMainLib.F2nd Invalid = 0b11000000, } + public struct SubENRS + { + public int Skip; + public int Reverse; + public Type Type; + + public override string ToString() => "Skip: " + Skip + "; Reverse: " + Reverse + "; Type: " + Type; + } + public override string ToString() => "Offset: " + Offset + "; Count: " + Count + "; " + "Size: " + Size + "; Repeat: " + Repeat; } diff --git a/KKdMainLib/F2nd/Header.cs b/KKdBaseLib/F2/Header.cs similarity index 91% rename from KKdMainLib/F2nd/Header.cs rename to KKdBaseLib/F2/Header.cs index 84bbe80..5aea5c1 100644 --- a/KKdMainLib/F2nd/Header.cs +++ b/KKdBaseLib/F2/Header.cs @@ -1,6 +1,4 @@ -using KKdBaseLib; - -namespace KKdMainLib.F2nd +namespace KKdBaseLib.F2 { public struct Header { diff --git a/KKdMainLib/F2nd/POF.cs b/KKdBaseLib/F2/POF.cs similarity index 98% rename from KKdMainLib/F2nd/POF.cs rename to KKdBaseLib/F2/POF.cs index 5a22cca..b2797fd 100644 --- a/KKdMainLib/F2nd/POF.cs +++ b/KKdBaseLib/F2/POF.cs @@ -1,6 +1,4 @@ -using KKdBaseLib; - -namespace KKdMainLib.F2nd +namespace KKdBaseLib.F2 { public struct POF { diff --git a/KKdBaseLib/F2/Struct.cs b/KKdBaseLib/F2/Struct.cs new file mode 100644 index 0000000..1036e94 --- /dev/null +++ b/KKdBaseLib/F2/Struct.cs @@ -0,0 +1,18 @@ +namespace KKdBaseLib.F2 +{ + public struct Struct + { + public Header Header; + public byte[] Data; + public Struct[] SubStructs; + public bool EOFC; + public ENRS[] ENRS; + public KKdList POF; + + public long DataOffset; + + public override string ToString() => Header.ToString() + (SubStructs != null ? + "; SubStructs: " + SubStructs.Length : "") + (ENRS != null ? "; Has ENRS" : "") + + (POF.NotNull ? "; Has POF" : "") + (EOFC ? "; Has EOFC" : ""); + } +} diff --git a/KKdBaseLib/Half.cs b/KKdBaseLib/Half.cs index 5b176e6..8a69c02 100644 --- a/KKdBaseLib/Half.cs +++ b/KKdBaseLib/Half.cs @@ -10,6 +10,8 @@ namespace KKdBaseLib public static explicit operator ushort(Half bits) => bits._value; + public static explicit operator float(Half h) => (float)(double)h; + public static explicit operator double(Half h) { if (h._value == 0x0000) return +0; @@ -29,6 +31,8 @@ namespace KKdBaseLib return d; } + public static explicit operator Half( float val) => (Half)(double)val; + public static explicit operator Half(double val) { Half h = new Half(); diff --git a/KKdBaseLib/IKF.cs b/KKdBaseLib/IKF.cs new file mode 100644 index 0000000..d936081 --- /dev/null +++ b/KKdBaseLib/IKF.cs @@ -0,0 +1,115 @@ +namespace KKdBaseLib +{ + public interface IKF + { + TKey F { get; set; } + + IKF Check(); + string ToString(); + string ToString(bool Brackets); + } + + public struct KFT0 : IKF + { + public TKey F { get; set; } + + public KFT0(TKey F = default) + { this.F = F; } + + public KFT0 ToT0() => this; + public KFT1 ToT1() => new KFT1(F); + public KFT2 ToT2() => new KFT2(F); + public KFT3 ToT3() => new KFT3(F); + + public IKF Check() => this; + + public override string ToString() => ToString(true); + public string ToString(bool Brackets = true) => + Extensions.ToString(F); + } + + public struct KFT1 : IKF + { + public TKey F { get; set; } + public TVal V; + + public KFT1(TKey F = default, TVal V = default) + { this.F = F; this.V = V; } + + public KFT0 ToT0() => new KFT0(F); + public KFT1 ToT1() => this; + public KFT2 ToT2() => new KFT2(F, V); + public KFT3 ToT3() => new KFT3(F, V); + + public IKF Check() => + V.Equals(default(TVal)) ? (IKF)ToT0() : this; + + public override string ToString() => ToString(true); + public string ToString(bool Brackets = true) => + (Brackets ? "(" : "") + Extensions.ToString(F) + "," + + Extensions.ToString(V) + (Brackets ? ")" : ""); + } + + public struct KFT2 : IKF + { + public TKey F { get; set; } + public TVal V; + public TVal T; + + public KFT2(TKey F = default, TVal V = default, TVal T = default) + { this.F = F; this.V = V; this.T = T; } + + public KFT0 ToT0() => new KFT0(F); + public KFT1 ToT1() => new KFT1(F, V); + public KFT2 ToT2() => this; + public KFT3 ToT3() => new KFT3(F, V, T, T); + + public KFT3 ToT3(IKF Previous) => + Previous is KFT2 PreviousT2 ? + new KFT3(F, V, PreviousT2.T, T) : + new KFT3(F, V, T, T); + + public IKF Check() => + T.Equals(default(TVal)) ? (V.Equals(default(TVal)) ? + (IKF)ToT0() : ToT1()) : this; + + public override string ToString() => ToString(true); + public string ToString(bool Brackets) => + (Brackets ? "(" : "") + Extensions.ToString(F) + "," + Extensions. + ToString(V) + "," + Extensions.ToString(T) + (Brackets ? ")" : ""); + } + + public struct KFT3 : IKF + { + public TKey F { get; set; } + public TVal V; + public TVal T1; + public TVal T2; + + public KFT3(TKey F = default, TVal V = default, TVal T1 = default, TVal T2 = default) + { this.F = F; this.V = V; this.T1 = T1; this.T2 = T2; } + + public KFT0 ToT0() => new KFT0(F); + public KFT1 ToT1() => new KFT1(F, V); + public KFT2 ToT2() => new KFT2(F, V, T1); + public KFT3 ToT3() => this; + + public IKF Check() => + T1.Equals(default(TVal)) && T2.Equals(default(TVal)) ? + (V.Equals(default(TVal)) ? ToT0() : (IKF)ToT1()) : + T1.Equals(T2) ? (IKF)ToT2() : this; + + public override string ToString() => ToString(true); + public string ToString(bool Brackets) => + (Brackets ? "(" : "") + Extensions.ToString(F) + "," + Extensions.ToString(V) + "," + + Extensions.ToString(T1) + "," + Extensions.ToString(T2) + (Brackets ? ")" : ""); + + public IKF ToT2(IKF Previous, out IKF Current) + { + Current = Previous is KFT2 PreviousT2 + ? new KFT2(PreviousT2.F, PreviousT2.V, T1) + : new KFT2(F, V, T1); + return new KFT2(F, V, T2); + } + } +} diff --git a/KKdBaseLib/IKeyFrame.cs b/KKdBaseLib/IKeyFrame.cs deleted file mode 100644 index 1896754..0000000 --- a/KKdBaseLib/IKeyFrame.cs +++ /dev/null @@ -1,142 +0,0 @@ -namespace KKdBaseLib -{ - public interface IKeyFrame - { - TKey Frame { get; set; } - - IKeyFrame Check(); - IKeyFrame ToKeyFrameT0(); - IKeyFrame ToKeyFrameT1(); - IKeyFrame ToKeyFrameT2(); - IKeyFrame ToKeyFrameT3(); - string ToString(); - string ToString(bool Brackets); - } - - public struct KeyFrameT0 : IKeyFrame - { - public TKey Frame { get; set; } - - public IKeyFrame ToKeyFrameT0() => - new KeyFrameT0 { Frame = Frame }; - public IKeyFrame ToKeyFrameT1() => - new KeyFrameT1 { Frame = Frame }; - public IKeyFrame ToKeyFrameT2() => - new KeyFrameT2 { Frame = Frame }; - public IKeyFrame ToKeyFrameT3() => - new KeyFrameT3 { Frame = Frame }; - - public IKeyFrame Check() => this; - - public override string ToString() => - Extensions.ToString(Frame); - public string ToString(bool Brackets) => - Extensions.ToString(Frame); - } - - public struct KeyFrameT1 : IKeyFrame - { - public TKey Frame { get; set; } - public TVal Value; - - public IKeyFrame ToKeyFrameT0() => - new KeyFrameT0 { Frame = Frame }; - public IKeyFrame ToKeyFrameT1() => - new KeyFrameT1 { Frame = Frame, Value = Value }; - public IKeyFrame ToKeyFrameT2() => - new KeyFrameT2 { Frame = Frame, Value = Value }; - public IKeyFrame ToKeyFrameT3() => - new KeyFrameT3 { Frame = Frame, Value = Value }; - - public IKeyFrame Check() => - Value.Equals(default(TVal)) ? ToKeyFrameT0() : (this); - - public override string ToString() => ToString(true); - public string ToString(bool Brackets) => - (Brackets ? "(" : "") + Extensions.ToString(Frame) + "," + - Extensions.ToString(Value) + (Brackets ? ")" : ""); - } - - public struct KeyFrameT2 : IKeyFrame - { - public TKey Frame { get; set; } - public TVal Value; - public TVal Interpolation; - - public IKeyFrame ToKeyFrameT0() => - new KeyFrameT0 { Frame = Frame }; - public IKeyFrame ToKeyFrameT1() => - new KeyFrameT1 { Frame = Frame, Value = Value }; - public IKeyFrame ToKeyFrameT2() => - new KeyFrameT2 { Frame = Frame, Value = Value, - Interpolation = Interpolation}; - public IKeyFrame ToKeyFrameT3() => - new KeyFrameT3 { Frame = Frame, Value = Value, - Interpolation1 = Interpolation, Interpolation2 = Interpolation }; - - public IKeyFrame ToKeyFrameT3(IKeyFrame Previous) => - Previous is KeyFrameT2 PreviousT2 ? - new KeyFrameT3 { Frame = Frame, Value = Value, - Interpolation1 = PreviousT2.Interpolation, Interpolation2 = Interpolation } : - new KeyFrameT3 { Frame = Frame, Value = Value, - Interpolation1 = Interpolation, Interpolation2 = Interpolation }; - - public IKeyFrame Check() - { - if (Value.Equals(default(TVal)) && Interpolation.Equals(default(TVal))) return ToKeyFrameT0(); - else if ( Interpolation.Equals(default(TVal))) return ToKeyFrameT1(); - return this; - } - - public override string ToString() => ToString(true); - public string ToString(bool Brackets) => - (Brackets ? "(" : "") + Extensions.ToString(Frame) + "," + Extensions. - ToString(Value) + "," + Extensions.ToString(Interpolation) + (Brackets ? ")" : ""); - } - - public struct KeyFrameT3 : IKeyFrame - { - public TKey Frame { get; set; } - public TVal Value; - public TVal Interpolation1; - public TVal Interpolation2; - - public IKeyFrame ToKeyFrameT0() => - new KeyFrameT0 { Frame = Frame }; - public IKeyFrame ToKeyFrameT1() => - new KeyFrameT1 { Frame = Frame, Value = Value }; - public IKeyFrame ToKeyFrameT2() => - new KeyFrameT2 { Frame = Frame, Value = Value, Interpolation = Interpolation1 }; - public IKeyFrame ToKeyFrameT3() => - new KeyFrameT3 { Frame = Frame, Value = Value, - Interpolation1 = Interpolation1, Interpolation2 = Interpolation2 }; - - public IKeyFrame Check() - { - if (Value.Equals(default(TVal)) && Interpolation1.Equals(default(TVal)) && - Interpolation2.Equals(default(TVal))) return ToKeyFrameT0(); - else if (Interpolation1.Equals(default(TVal)) && - Interpolation2.Equals(default(TVal))) return ToKeyFrameT1(); - else if (Interpolation1.Equals(Interpolation2)) - return ToKeyFrameT2(); - return this; - } - - public override string ToString() => ToString(true); - public string ToString(bool Brackets) => - (Brackets ? "(" : "") + Extensions.ToString(Frame) + "," + Extensions.ToString(Value) + "," + - Extensions.ToString(Interpolation1) + "," + Extensions.ToString(Interpolation2) + (Brackets ? ")" : ""); - - public IKeyFrame ToKeyFrameT2(IKeyFrame - Previous, out IKeyFrame Current) - { - Current = Previous is KeyFrameT2 PreviousT2 - ? new KeyFrameT2 { Frame = PreviousT2.Frame, - Value = PreviousT2.Value, Interpolation = Interpolation1 } - : new KeyFrameT2 { Frame = Frame, - Value = Value, Interpolation = Interpolation1 }; - return new KeyFrameT2 { Frame = Frame, - Value = Value, Interpolation = Interpolation2 }; - } - } -} diff --git a/KKdBaseLib/KKdBaseLib.csproj b/KKdBaseLib/KKdBaseLib.csproj index e244ba1..0a4c9e4 100644 --- a/KKdBaseLib/KKdBaseLib.csproj +++ b/KKdBaseLib/KKdBaseLib.csproj @@ -39,11 +39,15 @@ IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006 + + + + - + diff --git a/KKdBaseLib/MsgPack.cs b/KKdBaseLib/MsgPack.cs index c3a50a3..c9e5b37 100644 --- a/KKdBaseLib/MsgPack.cs +++ b/KKdBaseLib/MsgPack.cs @@ -119,30 +119,126 @@ namespace KKdBaseLib public float ReadSingle(string Name) => ReadNSingle(Name).GetValueOrDefault(); public double ReadDouble(string Name) => ReadNDouble(Name).GetValueOrDefault(); - public bool? ReadNBoolean(string Name) => - Element(Name, out MsgPack MsgPack) ? MsgPack.ReadNBoolean() : null; - public sbyte? ReadNInt8(string Name) => - Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNInt8 () : null; - public byte? ReadNUInt8(string Name) => - Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNUInt8 () : null; - public short? ReadNInt16(string Name) => - Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNInt16() : null; - public ushort? ReadNUInt16(string Name) => - Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNUInt16() : null; - public int? ReadNInt32(string Name) => - Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNInt32() : null; - public uint? ReadNUInt32(string Name) => - Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNUInt32() : null; - public long? ReadNInt64(string Name) => - Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNInt64() : null; - public ulong? ReadNUInt64(string Name) => - Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNUInt64() : null; - public float? ReadNSingle(string Name) => - Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNSingle() : null; - public double? ReadNDouble(string Name) => - Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNDouble() : null; - public string ReadString(string Name) => - Element(Name, out MsgPack MsgPack) ? MsgPack. ReadString() : null; + public bool? ReadNBoolean(string Name) + { + if (Element(Name, out MsgPack MsgPack)) + if (MsgPack.Object is bool Boolean) return Boolean; + return null; + } + public sbyte? ReadNInt8(string Name) + { + if (Element(Name, out MsgPack MsgPack)) + if (MsgPack.Object is sbyte Int8 ) return Int8 ; + else if (MsgPack.Object is byte UInt8 ) return ( sbyte) UInt8 ; + return null; + } + public byte? ReadNUInt8(string Name) + { + if (Element(Name, out MsgPack MsgPack)) + if (MsgPack.Object is sbyte Int8 ) return ( byte) Int8 ; + else if (MsgPack.Object is byte UInt8 ) return UInt8 ; + return null; + } + public short? ReadNInt16(string Name) + { + if (Element(Name, out MsgPack MsgPack)) + if (MsgPack.Object is sbyte Int8 ) return Int8 ; + else if (MsgPack.Object is byte UInt8 ) return UInt8 ; + else if (MsgPack.Object is short Int16) return Int16; + else if (MsgPack.Object is ushort UInt16) return ( short) UInt16; + return null; + } + public ushort? ReadNUInt16(string Name) + { + if (Element(Name, out MsgPack MsgPack)) + if (MsgPack.Object is sbyte Int8 ) return (ushort) Int8 ; + else if (MsgPack.Object is byte UInt8 ) return UInt8 ; + else if (MsgPack.Object is short Int16) return (ushort) Int16; + else if (MsgPack.Object is ushort UInt16) return UInt16; + return null; + } + public int? ReadNInt32(string Name) + { + if (Element(Name, out MsgPack MsgPack)) + if (MsgPack.Object is sbyte Int8 ) return Int8 ; + else if (MsgPack.Object is byte UInt8 ) return UInt8 ; + else if (MsgPack.Object is short Int16) return Int16; + else if (MsgPack.Object is ushort UInt16) return UInt16; + else if (MsgPack.Object is int Int32) return Int32; + else if (MsgPack.Object is uint UInt32) return ( int) UInt32; + return null; + } + public uint? ReadNUInt32(string Name) + { + if (Element(Name, out MsgPack MsgPack)) + if (MsgPack.Object is sbyte Int8 ) return ( uint) Int8 ; + else if (MsgPack.Object is byte UInt8 ) return UInt8 ; + else if (MsgPack.Object is short Int16) return ( uint) Int16; + else if (MsgPack.Object is ushort UInt16) return UInt16; + else if (MsgPack.Object is int Int32) return ( uint) Int32; + else if (MsgPack.Object is uint UInt32) return UInt32; + return null; + } + public long? ReadNInt64(string Name) + { + if (Element(Name, out MsgPack MsgPack)) + if (MsgPack.Object is sbyte Int8 ) return Int8 ; + else if (MsgPack.Object is byte UInt8 ) return UInt8 ; + else if (MsgPack.Object is short Int16) return Int16; + else if (MsgPack.Object is ushort UInt16) return UInt16; + else if (MsgPack.Object is int Int32) return Int32; + else if (MsgPack.Object is uint UInt32) return UInt32; + else if (MsgPack.Object is long Int64) return Int64; + else if (MsgPack.Object is ulong UInt64) return ( long) UInt64; + return null; + } + public ulong? ReadNUInt64(string Name) + { + if (Element(Name, out MsgPack MsgPack)) + if (MsgPack.Object is sbyte Int8 ) return ( ulong) Int8 ; + else if (MsgPack.Object is byte UInt8 ) return UInt8 ; + else if (MsgPack.Object is short Int16) return ( ulong) Int16; + else if (MsgPack.Object is ushort UInt16) return UInt16; + else if (MsgPack.Object is int Int32) return ( ulong) Int32; + else if (MsgPack.Object is uint UInt32) return UInt32; + else if (MsgPack.Object is long Int64) return ( ulong) Int64; + else if (MsgPack.Object is ulong UInt64) return UInt64; + return null; + } + public float? ReadNSingle(string Name) + { + if (Element(Name, out MsgPack MsgPack)) + if (MsgPack.Object is sbyte Int8 ) return Int8 ; + else if (MsgPack.Object is byte UInt8 ) return UInt8 ; + else if (MsgPack.Object is short Int16) return Int16; + else if (MsgPack.Object is ushort UInt16) return UInt16; + else if (MsgPack.Object is int Int32) return Int32; + else if (MsgPack.Object is uint UInt32) return UInt32; + else if (MsgPack.Object is long Int64) return Int64; + else if (MsgPack.Object is float Float32) return Float32; + else if (MsgPack.Object is double Float64) return ( float)Float64; + return null; + } + public double? ReadNDouble(string Name) + { + if (Element(Name, out MsgPack MsgPack)) + if (MsgPack.Object is sbyte Int8 ) return Int8 ; + else if (MsgPack.Object is byte UInt8 ) return UInt8 ; + else if (MsgPack.Object is short Int16) return Int16; + else if (MsgPack.Object is ushort UInt16) return UInt16; + else if (MsgPack.Object is int Int32) return Int32; + else if (MsgPack.Object is uint UInt32) return UInt32; + else if (MsgPack.Object is long Int64) return Int64; + else if (MsgPack.Object is float Float32) return Float32; + else if (MsgPack.Object is double Float64) return Float64; + return null; + } + public string ReadString(string Name) + { + if (Element(Name, out MsgPack MsgPack)) + if (MsgPack.Object is string String) return String; + return null; + } public bool ReadBoolean() => ReadNBoolean().GetValueOrDefault(); public sbyte ReadInt8() => ReadNInt8().GetValueOrDefault(); diff --git a/KKdBaseLib/Pointer.cs b/KKdBaseLib/Pointer.cs index 4bd391b..f61c166 100644 --- a/KKdBaseLib/Pointer.cs +++ b/KKdBaseLib/Pointer.cs @@ -11,7 +11,7 @@ public struct CountPointer { public int Count { get => Entries != null ? Entries.Length : 0; - set => Entries = new T[value]; } + set => Entries = value < 0 ? null : new T[value]; } public int Offset; public T[] Entries; diff --git a/KKdBaseLib/Properties/AssemblyInfo.cs b/KKdBaseLib/Properties/AssemblyInfo.cs index 170a8c3..e10f814 100644 --- a/KKdBaseLib/Properties/AssemblyInfo.cs +++ b/KKdBaseLib/Properties/AssemblyInfo.cs @@ -11,5 +11,5 @@ using System.Runtime.InteropServices; [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: Guid("437F63F1-8C23-429E-AB14-38B85C9EDB16")] -[assembly: AssemblyVersion("0.0.1.1")] -[assembly: AssemblyFileVersion("0.0.1.1")] +[assembly: AssemblyVersion("0.4.7.2")] +[assembly: AssemblyFileVersion("0.4.7.2")] diff --git a/KKdBaseLib/Vector3.cs b/KKdBaseLib/Vector3.cs index 90cb26f..9157b20 100644 --- a/KKdBaseLib/Vector3.cs +++ b/KKdBaseLib/Vector3.cs @@ -71,6 +71,7 @@ public bool Equals(Vector3 other) => X == other.X && Y == other.Y && Z == other.Z; - public override string ToString() => "X: " + X + "; Y: " + Y + "; Z: " + Z; + public override string ToString() => $"{X},{Y},{Z}"; + public string ToString(int d) => $"{X.Round(d)},{Y.Round(d)},{Z.Round(d)}"; } } diff --git a/KKdBaseLib/Vector4.cs b/KKdBaseLib/Vector4.cs index a76716d..9961aa6 100644 --- a/KKdBaseLib/Vector4.cs +++ b/KKdBaseLib/Vector4.cs @@ -71,6 +71,7 @@ public bool Equals(Vector4 other) => X == other.X && Y == other.Y && Z == other.Z && W == other.W; - public override string ToString() => "X: " + X + "; Y: " + Y + "; Z: " + Z + "; W: " + W; + public override string ToString() => $"{X},{Y},{Z},{W}"; + public string ToString(int d) => $"{X.Round(d)},{Y.Round(d)},{Z.Round(d)},{W.Round(d)}"; } } diff --git a/KKdBaseLib/bin/KKdBaseLib.dll b/KKdBaseLib/bin/KKdBaseLib.dll deleted file mode 100644 index cc7a89e..0000000 Binary files a/KKdBaseLib/bin/KKdBaseLib.dll and /dev/null differ diff --git a/KKdMainLib/A3DA.cs b/KKdMainLib/A3DA.cs index 808c63e..37bc534 100644 --- a/KKdMainLib/A3DA.cs +++ b/KKdMainLib/A3DA.cs @@ -1,8 +1,8 @@ using System; using System.Collections.Generic; using KKdBaseLib; +using KKdBaseLib.F2; using KKdMainLib.IO; -using KKdMainLib.F2nd; using Extensions = KKdBaseLib.Extensions; namespace KKdMainLib.A3DA @@ -1252,13 +1252,13 @@ namespace KKdMainLib.A3DA private void Write(ref Key Key, bool F16 = false) { - if (Key == null) return; + if (Key == null || Key.Type == null) return; int i = 0; if (Key.Trans != null) { Key.BinOffset = IO.Position; - int Type = Key.Type.Value; + int Type = (int)Key.Type & 0xFF; if (Key.EPTypePost.HasValue) Type |= (Key.EPTypePost.Value & 0xF) << 12; if (Key.EPTypePre .HasValue) Type |= (Key.EPTypePre .Value & 0xF) << 8; IO.Write(Type); @@ -1267,46 +1267,15 @@ namespace KKdMainLib.A3DA IO.Write(Key.Trans.Length); for (i = 0; i < Key.Trans.Length; i++) { - if (Key.Trans[i] is KeyFrameT0 TransT0) - { - if (F16 && CompressF16 > 0) - { IO.Write((ushort)TransT0.Frame); IO.Write((ushort)0); } - else - { IO.Write(( float)TransT0.Frame); IO.Write(( float)0); } - if (F16 && CompressF16 == 2) IO.Write(0 ); - else IO.Write(0L); - } - else if (Key.Trans[i] is KeyFrameT1 TransT1) - { - if (F16 && CompressF16 > 0) - { IO.Write((ushort)TransT1.Frame); IO.Write(( Half)TransT1.Value); } - else - { IO.Write(( float)TransT1.Frame); IO.Write((float)TransT1.Value); } - if (F16 && CompressF16 == 2) IO.Write(0 ); - else IO.Write(0L); - } - else if (Key.Trans[i] is KeyFrameT2 TransT2) - { - if (F16 && CompressF16 > 0) - { IO.Write((ushort)TransT2.Frame); IO.Write(( Half)TransT2.Value); } - else - { IO.Write(( float)TransT2.Frame); IO.Write((float)TransT2.Value); } - if (F16 && CompressF16 == 2) - { IO.Write(( Half)TransT2.Interpolation); IO.Write(( Half)TransT2.Interpolation); } - else - { IO.Write(( float)TransT2.Interpolation); IO.Write((float)TransT2.Interpolation); } - } - else if (Key.Trans[i] is KeyFrameT3 TransT3) - { - if (F16 && CompressF16 > 0) - { IO.Write((ushort)TransT3.Frame); IO.Write(( Half)TransT3.Value); } - else - { IO.Write(( float)TransT3.Frame); IO.Write((float)TransT3.Value); } - if (F16 && CompressF16 == 2) - { IO.Write(( Half)TransT3.Interpolation1); IO.Write(( Half)TransT3.Interpolation2); } - else - { IO.Write(( float)TransT3.Interpolation1); IO.Write((float)TransT3.Interpolation2); } - } + ref KFT3 KF = ref Key.Trans[i]; + if (F16 && CompressF16 > 0) + { IO.Write((ushort)KF.F ); IO.Write(( Half)KF.V ); } + else + { IO.Write(( float)KF.F ); IO.Write((float)KF.V ); } + if (F16 && CompressF16 == 2) + { IO.Write(( Half)KF.T1); IO.Write(( Half)KF.T2); } + else + { IO.Write(( float)KF.T1); IO.Write((float)KF.T2); } } } else @@ -1314,8 +1283,8 @@ namespace KKdMainLib.A3DA if (!UsedValues.ContainsValue(Key.Value) || !A3DCOpt) { Key.BinOffset = IO.Position; - IO.Write( Key.Type ); - IO.Write((float?)Key.Value); + IO.Write(( int)Key.Type ); + IO.Write((float)Key.Value); if (A3DCOpt) { UsedValues.Add(Key.BinOffset, Key.Value); } return; @@ -1328,7 +1297,7 @@ namespace KKdMainLib.A3DA public void MsgPackReader(string file, bool JSON) { MsgPack MsgPack = file.ReadMPAllAtOnce(JSON); - if (!MsgPack.Element("A3D", out MsgPack A3D)) { MsgPack = MsgPack.New; return; } + if (!MsgPack.Element("A3D", out MsgPack A3D)) { MsgPack.Dispose(); return; } MsgPackReader(A3D); } @@ -1989,14 +1958,13 @@ namespace KKdMainLib.A3DA public static Key ReadKey(this Dictionary Dict, string Temp) { Key Key = new Key(); - Dict.FindValue(out Key.BinOffset, Temp + BO ); - Dict.FindValue(out Key.Type , Temp + "type"); + if ( Dict.FindValue(out Key.BinOffset, Temp + BO )) return Key; + if (!Dict.FindValue(out int Type , Temp + "type")) return null; - if (Key.BinOffset == null && Key.Type == null) return null; - if (Key.Type == null) return Key; - if (Key.Type == 0x0000) return Key; - - if (Key.Type == 0x0001) { Dict.FindValue(out Key.Value, Temp + "value"); return Key; } + if (Key.BinOffset != null) return null; + Key.Type = (Key.Interpolation)Type; + if (Type == 0x0000) return Key; + if (Type == 0x0001) { Dict.FindValue(out Key.Value, Temp + "value"); return Key; } int i = 0; Dict.FindValue(out Key.EPTypePost, Temp + "ep_type_post"); @@ -2006,66 +1974,60 @@ namespace KKdMainLib.A3DA if (Dict.StartsWith(Temp + "raw_data")) Dict.FindValue(out Key.RawData.KeyType, Temp + "raw_data_key_type"); - if (Key.Length != null) - { - int Type; - Key.Trans = new IKeyFrame[(int)Key.Length]; - for (i = 0; i < Key.Length; i++) - if (Dict.FindValue(out value, Temp + "key" + d + i + d + "data")) - { - dataArray = value.Replace("(", "").Replace(")", "").Split(','); - Type = dataArray.Length - 1; - if (Type == 0) Key.Trans[i] = new KeyFrameT0 - { Frame = dataArray[0].ToDouble() }; - else if (Type == 1) Key.Trans[i] = new KeyFrameT1 - { Frame = dataArray[0].ToDouble(), Value = dataArray[1].ToDouble() }; - else if (Type == 2) Key.Trans[i] = new KeyFrameT2 - { Frame = dataArray[0].ToDouble(), Value = dataArray[1].ToDouble(), - Interpolation = dataArray[2].ToDouble() }; - else if (Type == 3) Key.Trans[i] = new KeyFrameT3 - { Frame = dataArray[0].ToDouble(), Value = dataArray[1].ToDouble(), - Interpolation1 = dataArray[2].ToDouble(), - Interpolation2 = dataArray[3].ToDouble() }; - Key.Trans[i] = Key.Trans[i].Check(); - } - } - else if (Key.RawData.KeyType != null) + if (Key.RawData.KeyType != 0) { + ref string[] ValueList = ref Key.RawData.ValueList; Dict.FindValue(out Key.RawData.ValueType, Temp + "raw_data.value_type"); if (Dict.FindValue(out value, Temp + "raw_data.value_list")) - Key.RawData.ValueList = value.Split(','); + ValueList = value.Split(','); Dict.FindValue(out Key.RawData.ValueListSize, Temp + "raw_data.value_list_size"); value = ""; - int DS = (int)Key.RawData.KeyType + 1; + int DS = Key.RawData.KeyType + 1; Key.Length = Key.RawData.ValueListSize / DS; - Key.Trans = new IKeyFrame[(int)Key.Length]; + Key.Trans = new KFT3[Key.Length]; if (Key.RawData.KeyType == 0) for (i = 0; i < Key.Length; i++) - Key.Trans[i] = new KeyFrameT0 - { Frame = Key.RawData.ValueList[i * DS + 0].ToDouble() }.Check(); + Key.Trans[i] = new KFT3 + (ValueList[i * DS + 0].ToDouble()); else if (Key.RawData.KeyType == 1) for (i = 0; i < Key.Length; i++) - Key.Trans[i] = new KeyFrameT1 - { Frame = Key.RawData.ValueList[i * DS + 0].ToDouble(), - Value = Key.RawData.ValueList[i * DS + 1].ToDouble() }.Check(); + Key.Trans[i] = new KFT3 + (ValueList[i * DS + 0].ToDouble(), ValueList[i * DS + 1].ToDouble()); else if (Key.RawData.KeyType == 2) for (i = 0; i < Key.Length; i++) - Key.Trans[i] = new KeyFrameT2 - { Frame = Key.RawData.ValueList[i * DS + 0].ToDouble(), - Value = Key.RawData.ValueList[i * DS + 1].ToDouble(), - Interpolation = Key.RawData.ValueList[i * DS + 2].ToDouble() }.Check(); + Key.Trans[i] = new KFT3 + (ValueList[i * DS + 0].ToDouble(), ValueList[i * DS + 1].ToDouble(), + ValueList[i * DS + 2].ToDouble(), ValueList[i * DS + 2].ToDouble()); else if (Key.RawData.KeyType == 3) for (i = 0; i < Key.Length; i++) - Key.Trans[i] = new KeyFrameT3 - { Frame = Key.RawData.ValueList[i * DS + 0].ToDouble(), - Value = Key.RawData.ValueList[i * DS + 1].ToDouble(), - Interpolation1 = Key.RawData.ValueList[i * DS + 2].ToDouble(), - Interpolation2 = Key.RawData.ValueList[i * DS + 3].ToDouble() }.Check(); + Key.Trans[i] = new KFT3 + (ValueList[i * DS + 0].ToDouble(), ValueList[i * DS + 1].ToDouble(), + ValueList[i * DS + 2].ToDouble(), ValueList[i * DS + 3].ToDouble()); - for (i = 0; i < Key.Length; i++) Key.Trans[i].Check(); Key.RawData.ValueList = null; } + else + { + Key.Trans = new KFT3[Key.Length]; + for (i = 0; i < Key.Length; i++) + { + if (!Dict.FindValue(out value, Temp + "key" + d + i + d + "data")) continue; + + dataArray = value.Replace("(", "").Replace(")", "").Split(','); + Type = dataArray.Length - 1; + if (Type == 0) Key.Trans[i] = new KFT3 + (dataArray[0].ToDouble()); + else if (Type == 1) Key.Trans[i] = new KFT3 + (dataArray[0].ToDouble(), dataArray[1].ToDouble()); + else if (Type == 2) Key.Trans[i] = new KFT3 + (dataArray[0].ToDouble(), dataArray[1].ToDouble(), + dataArray[2].ToDouble(), dataArray[2].ToDouble()); + else if (Type == 3) Key.Trans[i] = new KFT3 + (dataArray[0].ToDouble(), dataArray[1].ToDouble(), + dataArray[2].ToDouble(), dataArray[3].ToDouble()); + } + } return Key; } @@ -2105,7 +2067,7 @@ namespace KKdMainLib.A3DA public static void Write(this Stream IO, Key Key, string Temp, bool A3DC = false) { - if (Key == null) return; + if (Key == null || Key.Type == null) return; if (A3DC) { IO.Write(Temp + BO + "=", Key.BinOffset); return; } @@ -2113,69 +2075,65 @@ namespace KKdMainLib.A3DA if (Key.Trans != null) if (Key.Trans.Length == 0) { - IO.Write(Temp + "type=", Key.Type); + IO.Write(Temp + "type=", (int)Key.Type); if (Key.Type > 0) IO.Write(Temp + "value=", Key.Value); return; } if (Key.EPTypePost != null) IO.Write(Temp + "ep_type_post=", Key.EPTypePost); if (Key.EPTypePre != null) IO.Write(Temp + "ep_type_pre=" , Key.EPTypePre ); - if (Key.RawData.KeyType == null && Key.Trans != null) + if (Key.RawData.KeyType == 0 && Key.Trans != null) { + IKF KF; SO = Key.Trans.Length.SortWriter(); for (i = 0; i < Key.Trans.Length; i++) { SOi = SO[i]; - IO.Write(Temp + "key" + d + SOi + d + "data=", Key.Trans[SOi].ToString()); - if (Key.Trans[SOi] is KeyFrameT0) - IO.Write(Temp + "key" + d + SOi + d + "type=", 0); - else if (Key.Trans[SOi] is KeyFrameT1) - IO.Write(Temp + "key" + d + SOi + d + "type=", 1); - else if (Key.Trans[SOi] is KeyFrameT2) - IO.Write(Temp + "key" + d + SOi + d + "type=", 2); - else if (Key.Trans[SOi] is KeyFrameT3) - IO.Write(Temp + "key" + d + SOi + d + "type=", 3); + KF = Key.Trans[SOi].Check(); + IO.Write(Temp + "key" + d + SOi + d + "data=", KF.ToString()); + int Type = 0; + if (KF is KFT0) Type = 0; + else if (KF is KFT1) Type = 1; + else if (KF is KFT2) Type = 2; + else if (KF is KFT3) Type = 3; + IO.Write(Temp + "key" + d + SOi + d + "type=", Type); } IO.Write(Temp + "key.length=", Key.Length); if (Key.Max != null) IO.Write(Temp + "max=", Key.Max); } else if (Key.Trans != null) { - Key.RawData.KeyType = 0; + int Length = Key.Trans.Length; + ref int KeyType = ref Key.RawData.KeyType; + KeyType = 0; + IKF KF; if (Key.Max != null) IO.Write(Temp + "max=", Key.Max); - for (i = 0; i < Key.Trans.Length; i++) + for (i = 0; i < Length; i++) { - if (Key.Trans[i] is KeyFrameT0 && - Key.RawData.KeyType < 0) Key.RawData.KeyType = 0; - else if (Key.Trans[i] is KeyFrameT1 && - Key.RawData.KeyType < 1) Key.RawData.KeyType = 1; - else if (Key.Trans[i] is KeyFrameT2 && - Key.RawData.KeyType < 2) Key.RawData.KeyType = 2; - else if (Key.Trans[i] is KeyFrameT3 && - Key.RawData.KeyType < 3) break; + KF = Key.Trans[i].Check(); + if (KF is KFT0 && KeyType < 0) KeyType = 0; + else if (KF is KFT1 && KeyType < 1) KeyType = 1; + else if (KF is KFT2 && KeyType < 2) KeyType = 2; + else if (KF is KFT3 && KeyType < 3) break; } - Key.RawData.ValueListSize = Key.Trans.Length * (Key.RawData.KeyType + 1); + Key.RawData.ValueListSize = Length * KeyType + Length; IO.Write(Temp + "raw_data.value_list="); - if (Key.RawData.KeyType == 0) for (i = 0; i < Key.Trans.Length; i++) - IO.Write(Key.Trans[i].ToKeyFrameT0().ToString(false) + - ((i + 1 < Key.Trans.Length) ? "," : "")); - else if (Key.RawData.KeyType == 1) for (i = 0; i < Key.Trans.Length; i++) - IO.Write(Key.Trans[i].ToKeyFrameT1().ToString(false) + - ((i + 1 < Key.Trans.Length) ? "," : "")); - else if (Key.RawData.KeyType == 2) for (i = 0; i < Key.Trans.Length; i++) - IO.Write(Key.Trans[i].ToKeyFrameT2().ToString(false) + - ((i + 1 < Key.Trans.Length) ? "," : "")); - else if (Key.RawData.KeyType == 3) for (i = 0; i < Key.Trans.Length; i++) - IO.Write(Key.Trans[i].ToKeyFrameT3().ToString(false) + - ((i + 1 < Key.Trans.Length) ? "," : "")); + if (KeyType == 0) for (i = 0; i < Length; i++) + IO.Write(Key.Trans[i].ToT0().ToString(false) + ((i + 1 < Length) ? "," : "")); + else if (KeyType == 1) for (i = 0; i < Length; i++) + IO.Write(Key.Trans[i].ToT1().ToString(false) + ((i + 1 < Length) ? "," : "")); + else if (KeyType == 2) for (i = 0; i < Length; i++) + IO.Write(Key.Trans[i].ToT2().ToString(false) + ((i + 1 < Length) ? "," : "")); + else if (KeyType == 3) for (i = 0; i < Length; i++) + IO.Write(Key.Trans[i].ToT3().ToString(false) + ((i + 1 < Length) ? "," : "")); IO.Position--; IO.Write('\n'); IO.Write(Temp + "raw_data.value_list_size=", Key.RawData.ValueListSize); IO.Write(Temp + "raw_data.value_type=" , Key.RawData.ValueType ); IO.Write(Temp + "raw_data_key_type=" , Key.RawData. KeyType ); } - IO.Write(Temp + "type=", Key.Type & 0xFF); - if (Key.RawData.KeyType == null && Key.Trans == null && Key.Value != null) + IO.Write(Temp + "type=", (int)Key.Type); + if (Key.RawData.KeyType == 0 && Key.Trans == null && Key.Value != null) if (Key.Value != 0) IO.Write(Temp + "value=", Key.Value); } @@ -2213,38 +2171,36 @@ namespace KKdMainLib.A3DA if (Key.BinOffset == null || Key.BinOffset < 0) return; IO.Position = (int)Key.BinOffset; - Key.Type = IO.ReadInt32(); + int Type = IO.ReadInt32(); Key.Value = IO.ReadSingle(); - if (Key.Type == 0x0000 || Key.Type == 0x0001) return; + Key.Type = (Key.Interpolation)(Type & 0xFF); + if (Key.Type < Key.Interpolation.Lerp) return; Key.Max = IO.ReadSingle(); Key.Length = IO.ReadInt32 (); - if (Key.Type >> 8 != 0) + if (Type >> 8 != 0) { - Key.EPTypePost = (Key.Type >> 12) & 0xF; - Key.EPTypePre = (Key.Type >> 8) & 0xF; + Key.EPTypePost = (Type >> 12) & 0xF; + Key.EPTypePre = (Type >> 8) & 0xF; if (Key.EPTypePost == 0) Key.EPTypePost = null; if (Key.EPTypePre == 0) Key.EPTypePre = null; } - Key.Type &= 0xFF; - Key.Trans = new IKeyFrame[(int)Key.Length]; - KeyFrameT3 Temp; + Key.Trans = new KFT3[Key.Length]; + KFT3 Temp; for (int i = 0; i < Key.Length; i++) { - Temp = new KeyFrameT3(); + Temp = new KFT3(); if (F16 && C_F16 > 0) - { Temp.Frame = IO.ReadUInt16(); Temp.Value = (double)IO.ReadHalf (); } + { Temp.F = IO.ReadUInt16(); Temp.V = (double)IO.ReadHalf (); } else - { Temp.Frame = IO.ReadSingle(); Temp.Value = IO.ReadSingle(); } + { Temp.F = IO.ReadSingle(); Temp.V = IO.ReadSingle(); } if (F16 && C_F16 == 2) - { Temp.Interpolation1 = (double)IO.ReadHalf (); - Temp.Interpolation2 = (double)IO.ReadHalf (); } + { Temp.T1 = (double)IO.ReadHalf (); Temp.T2 = (double)IO.ReadHalf (); } else - { Temp.Interpolation1 = IO.ReadSingle(); - Temp.Interpolation2 = IO.ReadSingle(); } + { Temp.T1 = IO.ReadSingle(); Temp.T2 = IO.ReadSingle(); } - Key.Trans[i] = Temp.Check(); + Key.Trans[i] = Temp; } } @@ -2310,47 +2266,36 @@ namespace KKdMainLib.A3DA { if (k.Object == null) return null; - Key Key = new Key { EPTypePost = k.ReadNInt32("EPTypePost"), - EPTypePre = k.ReadNInt32("EPTypePre"), Max = k.ReadNDouble("Max"), - Type = k.ReadNInt32("Type"), Value = k.ReadNDouble("Value") }; + Key Key = new Key { EPTypePost = k.ReadNInt32("EPTypePost"), EPTypePre = + k.ReadNInt32("EPTypePre"), Max = k.ReadNDouble("Max"), Value = k.ReadNDouble("Value") }; + if (!Enum.TryParse(k.ReadString("Type"), out Key.Interpolation Type)) { Key.Value = null; return Key; } + Key.Type = Type; + if (Key.Type == 0) { Key.Value = 0; return Key; } + else if (Key.Type < Key.Interpolation.Lerp) return Key; + if (k.ReadBoolean("RawData")) Key.RawData = new Key.RawD() { KeyType = -1, ValueType = "float" }; - if (Key.Type == 0) Key.Value = 0.0; - - if (Key.Type < 2) return Key; - if (!k.ElementArray("Trans", out MsgPack Trans)) return Key; Key.Length = Trans.Array.Length; - Key.Trans = new IKeyFrame[Key.Length.Value]; + Key.Trans = new KFT3[Key.Length]; for (int i = 0; i < Key.Length; i++) { if (Trans[i].Array == null) continue; else if (Trans[i].Array.Length == 0) continue; else if (Trans[i].Array.Length == 1) - Key.Trans[i] = new KeyFrameT0 - { Frame = Trans[i][0].ReadDouble() }; + Key.Trans[i] = new KFT3 + (Trans[i][0].ReadDouble()); else if (Trans[i].Array.Length == 2) - Key.Trans[i] = new KeyFrameT1 - { - Frame = Trans[i][0].ReadDouble(), - Value = Trans[i][1].ReadDouble(), - }; + Key.Trans[i] = new KFT3 + (Trans[i][0].ReadDouble(), Trans[i][1].ReadDouble()); else if (Trans[i].Array.Length == 3) - Key.Trans[i] = new KeyFrameT2 - { - Frame = Trans[i][0].ReadDouble(), - Value = Trans[i][1].ReadDouble(), - Interpolation = Trans[i][2].ReadDouble(), - }; + Key.Trans[i] = new KFT3 + (Trans[i][0].ReadDouble(), Trans[i][1].ReadDouble(), + Trans[i][2].ReadDouble(), Trans[i][2].ReadDouble()); else if (Trans[i].Array.Length == 4) - Key.Trans[i] = new KeyFrameT3 - { - Frame = Trans[i][0].ReadDouble(), - Value = Trans[i][1].ReadDouble(), - Interpolation1 = Trans[i][2].ReadDouble(), - Interpolation2 = Trans[i][3].ReadDouble(), - }; - Key.Trans[i] = Key.Trans[i].Check(); + Key.Trans[i] = new KFT3 + (Trans[i][0].ReadDouble(), Trans[i][1].ReadDouble(), + Trans[i][2].ReadDouble(), Trans[i][3].ReadDouble()); } return Key; } @@ -2381,32 +2326,32 @@ namespace KKdMainLib.A3DA public static MsgPack Add(this MsgPack MsgPack, string name, Key Key) { - if (Key == null) return MsgPack; - if (Key.Type == null) return MsgPack; + if (Key == null || Key.Type == null) return MsgPack; - MsgPack Keys = new MsgPack(name).Add("Type", Key.Type); - if (Key.Trans != null) + MsgPack Keys = new MsgPack(name).Add("Type", Key.Type.ToString()); + if (Key.Trans != null && Key.Type != Key.Interpolation.Null) { Keys = Keys.Add("Max", Key.Max).Add("EPTypePost", Key.EPTypePost).Add("EPTypePre", Key.EPTypePre); - if (Key.RawData.KeyType != null) Keys.Add("RawData", true); + if (Key.RawData.KeyType != 0) Keys.Add("RawData", true); MsgPack Trans = new MsgPack(Key.Trans.Length, "Trans"); for (int i = 0; i < Key.Trans.Length; i++) - if (Key.Trans[i] is KeyFrameT0 KeyFrameT0) + { + IKF KF = Key.Trans[i].Check(); + if (KF is KFT0 KFT0) Trans[i] = new MsgPack(null, new MsgPack[] - { (MsgPack)KeyFrameT0.Frame }); - else if (Key.Trans[i] is KeyFrameT1 KeyFrameT1) + { (MsgPack)KFT0.F }); + else if (KF is KFT1 KFT1) Trans[i] = new MsgPack(null, new MsgPack[] - { (MsgPack)KeyFrameT1.Frame, (MsgPack)KeyFrameT1.Value }); - else if (Key.Trans[i] is KeyFrameT2 KeyFrameT2) + { (MsgPack)KFT1.F, (MsgPack)KFT1.V }); + else if (KF is KFT2 KFT2) Trans[i] = new MsgPack(null, new MsgPack[] - { (MsgPack)KeyFrameT2.Frame, (MsgPack)KeyFrameT2.Value, - (MsgPack)KeyFrameT2.Interpolation }); - else if (Key.Trans[i] is KeyFrameT3 KeyFrameT3) + { (MsgPack)KFT2.F, (MsgPack)KFT2.V, (MsgPack)KFT2.T }); + else if (KF is KFT3 KFT3) Trans[i] = new MsgPack(null, new MsgPack[] - { (MsgPack)KeyFrameT3.Frame, (MsgPack)KeyFrameT3.Value, - (MsgPack)KeyFrameT3.Interpolation1, (MsgPack)KeyFrameT3.Interpolation2 }); + { (MsgPack)KFT3.F, (MsgPack)KFT3.V, (MsgPack)KFT3.T1, (MsgPack)KFT3.T2, }); + } Keys.Add(Trans); } else if (Key.Value != 0) Keys.Add("Value", Key.Value); @@ -2550,23 +2495,32 @@ namespace KKdMainLib.A3DA public class Key { - public int? Type; - public int? Length; + public Interpolation? Type; + public int Length; public int? BinOffset; public int? EPTypePre; public int? EPTypePost; public double? Max; public double? Value; public RawD RawData; - public IKeyFrame[] Trans; + public KFT3[] Trans; public struct RawD { - public int? KeyType; - public int? ValueListSize; + public int KeyType; + public int ValueListSize; public string ValueType; public string[] ValueList; } + + public enum Interpolation + { + Null = 0, + Value = 1, + Lerp = 2, + Hermite = 3, + Hold = 4, + } } public struct Light diff --git a/KKdMainLib/Aet.cs b/KKdMainLib/Aet.cs index ad29ae2..c1714b1 100644 --- a/KKdMainLib/Aet.cs +++ b/KKdMainLib/Aet.cs @@ -1,8 +1,8 @@ //Original: AetSet.bt Version: 2.0 by samyuu using KKdBaseLib; +using KKdMainLib.F2; using KKdMainLib.IO; -using KKdMainLib.F2nd; namespace KKdMainLib.Aet { @@ -200,8 +200,7 @@ namespace KKdMainLib.Aet { IO.Align(0x10); Aet.Unknown.Offset = IO.Position; - for (i = 0; i < Aet.Unknown.Count * 10; i++) - IO.Write(0L); + for (i = 0; i < Aet.Unknown.Count * 10; i++) IO.Write(0L); } IO.Align(0x10); @@ -213,7 +212,7 @@ namespace KKdMainLib.Aet for (i = 0; i < NullValPointers.Count; i++) { IO.Position = NullValPointers[i]; - IO.Write(ReturnPosition + i * 4); + IO.Write(ReturnPosition + i << 2); } for (i = 0; i < Aet.Layers.Count; i++) @@ -861,7 +860,6 @@ namespace KKdMainLib.Aet public struct AetHeader { public Pointer[] Data; - public POF POF; } public struct AetData diff --git a/KKdMainLib/DB/Aet.cs b/KKdMainLib/DB/Aet.cs index 7b78d99..0700119 100644 --- a/KKdMainLib/DB/Aet.cs +++ b/KKdMainLib/DB/Aet.cs @@ -198,7 +198,7 @@ namespace KKdMainLib.DB for (int i = 0; i < AetSets.Length; i++) AetSets[i].ReadMsgPack(AetDB[i]); } - MsgPack = MsgPack.New; + MsgPack.Dispose(); } diff --git a/KKdMainLib/DB/Auth.cs b/KKdMainLib/DB/Auth.cs index 28000e1..cde7e0e 100644 --- a/KKdMainLib/DB/Auth.cs +++ b/KKdMainLib/DB/Auth.cs @@ -117,7 +117,7 @@ namespace KKdMainLib.DB } } } - MsgPack = MsgPack.New; + MsgPack.Dispose(); } public void MsgPackWriter(string file, bool JSON) diff --git a/KKdMainLib/DB/Spr.cs b/KKdMainLib/DB/Spr.cs index 6fdd90b..3522f65 100644 --- a/KKdMainLib/DB/Spr.cs +++ b/KKdMainLib/DB/Spr.cs @@ -143,13 +143,13 @@ namespace KKdMainLib.DB if (set.Id == null) while (true) { if (!SetIds.Contains(i1)) { SpriteSets[i].Id = i1; SetIds.Add(i1); break; } i1++; } - for (i0 = 0, i1 = 0; i0 < set. Sprites.Length; i0++) - if (set. Sprites[i0].Id == null) while (true) { if (!Ids.Contains(i1)) - { SpriteSets[i]. Sprites[i0].Id = i1; Ids.Add(i1); break; } i1++; } - for (i0 = 0, i1 = 0; i0 < set.Textures.Length; i0++) - if (set.Textures[i0].Id == null) while (true) { if (!Ids.Contains(i1)) - { SpriteSets[i].Textures[i0].Id = i1; Ids.Add(i1); break; } i1++; } + while (set.Textures[i0].Id == null) + if (!Ids.Contains(i1)) Ids.Add((int)(SpriteSets[i].Textures[i0].Id = i1)); else i1++; + + for (i0 = 0, i1 = 0; i0 < set. Sprites.Length; i0++) + while (set. Sprites[i0].Id == null) + if (!Ids.Contains(i1)) Ids.Add((int)(SpriteSets[i]. Sprites[i0].Id = i1)); else i1++; } Ids = null; @@ -175,18 +175,20 @@ namespace KKdMainLib.DB for (i = 0; i < SpriteSets.Length; i++) { if (NotAdd.Contains(i)) continue; - SpriteSets[i]. NameOffset = IO.Position; IO.Write(SpriteSets[i]. Name + "\0"); - SpriteSets[i].FileNameOffset = IO.Position; IO.Write(SpriteSets[i].FileName + "\0"); + for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++) + { SpriteSets[i].Textures[i0].NameOffset = IO.Position; + IO.Write(SpriteSets[i].Textures[i0].Name + "\0"); } + + for (i0 = 0; i0 < SpriteSets[i]. Sprites.Length; i0++) + { SpriteSets[i]. Sprites[i0].NameOffset = IO.Position; + IO.Write(SpriteSets[i]. Sprites[i0].Name + "\0"); } } for (i = 0; i < SpriteSets.Length; i++) { if (NotAdd.Contains(i)) continue; - for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++) - { SpriteSets[i].Textures[i0].NameOffset = IO.Position; IO.Write(SpriteSets[i].Textures[i0].Name + "\0"); } - - for (i0 = 0; i0 < SpriteSets[i]. Sprites.Length; i0++) - { SpriteSets[i]. Sprites[i0].NameOffset = IO.Position; IO.Write(SpriteSets[i]. Sprites[i0].Name + "\0"); } + SpriteSets[i]. NameOffset = IO.Position; IO.Write(SpriteSets[i]. Name + "\0"); + SpriteSets[i].FileNameOffset = IO.Position; IO.Write(SpriteSets[i].FileName + "\0"); } IO.Align(0x08, true); @@ -235,7 +237,7 @@ namespace KKdMainLib.DB for (int i = 0; i < SpriteSets.Length; i++) SpriteSets[i].ReadMsgPack(SprDB[i]); } - MsgPack = MsgPack.New; + MsgPack.Dispose(); } public void MsgPackWriter(string file, bool JSON) diff --git a/KKdMainLib/DEX.cs b/KKdMainLib/DEX.cs index e569e64..040be1d 100644 --- a/KKdMainLib/DEX.cs +++ b/KKdMainLib/DEX.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using KKdBaseLib; +using KKdBaseLib.F2; using KKdMainLib.IO; -using KKdMainLib.F2nd; namespace KKdMainLib { @@ -24,18 +24,16 @@ namespace KKdMainLib Header.Format = Format.F; Header.SectionSignature = IO.ReadInt32(); if (Header.SectionSignature == 0x43505845) - Header = IO.ReadHeader(true); - if (Header.SectionSignature != 0x64) - return 0; + Header = IO.ReadHeader(true, true); + if (Header.SectionSignature != 0x64) return 0; - Offset = IO.Position - 0x4; + IO.Offset = IO.Position - 0x4; Dex = new EXP[IO.ReadInt32()]; int DEXOffset = IO.ReadInt32(); - if (IO.ReadInt32() == 0x00) Header.Format = Format.X; int DEXNameOffset = IO.ReadInt32(); - if (Header.IsX) IO.ReadInt32(); + if (DEXNameOffset == 0x00) { Header.Format = Format.X; DEXNameOffset = (int)IO.ReadInt64(); } - IO.Seek(DEXOffset + Offset, 0); + IO.Seek(DEXOffset, 0); for (int i0 = 0; i0 < Dex.Length; i0++) Dex[i0] = new EXP { Main = new List(), Eyes = new List() }; @@ -46,7 +44,7 @@ namespace KKdMainLib Dex[i0].EyesOffset = IO.ReadInt32(); if (Header.IsX) IO.ReadInt32(); } - IO.Seek(DEXNameOffset + Offset, 0); + IO.Seek(DEXNameOffset, 0); for (int i0 = 0; i0 < Dex.Length; i0++) { Dex[i0].NameOffset = IO.ReadInt32(); @@ -70,7 +68,7 @@ namespace KKdMainLib break; } - IO.Seek(Dex[i0].EyesOffset + Offset, 0); + IO.Seek(Dex[i0].EyesOffset, 0); while(true) { element.Frame = IO.ReadSingle(); @@ -80,12 +78,10 @@ namespace KKdMainLib element.Trans = IO.ReadSingle(); Dex[i0].Eyes.Add(element); - if (element.Frame == 999999 || element.Both == 0xFFFF) - break; + if (element.Frame == 999999 || element.Both == 0xFFFF) break; } - IO.Seek(Dex[i0].NameOffset + Offset, 0); - Dex[i0].Name = IO.NullTerminatedUTF8(); + Dex[i0].Name = IO.ReadStringAtOffset(Dex[i0].NameOffset); } IO.Close(); @@ -172,7 +168,7 @@ namespace KKdMainLib IO.Close(); } - public void MsgPackReader(string file, bool JSON) + public int MsgPackReader(string file, bool JSON) { int i0 = 0; int i1 = 0; @@ -180,7 +176,7 @@ namespace KKdMainLib Header = new Header(); MsgPack MsgPack = file.ReadMPAllAtOnce(JSON); - if (!MsgPack.ElementArray("Dex", out MsgPack Dex)) return; + if (!MsgPack.ElementArray("Dex", out MsgPack Dex)) return 0; this.Dex = new EXP[Dex.Array.Length]; for (i0 = 0; i0 < this.Dex.Length; i0++) @@ -191,23 +187,19 @@ namespace KKdMainLib { this.Dex[i0].Main = new List(); for (i1 = 0; i1 < Main.Array.Length; i1++) - this.Dex[i0].Main.Add(ReadEXP(Main[i1])); + this.Dex[i0].Main.Add(EXPElement.Read(Main[i1])); } if (Dex[i0].ElementArray("Eyes", out MsgPack Eyes)) { this.Dex[i0].Eyes = new List(); for (i1 = 0; i1 < Eyes.Array.Length; i1++) - this.Dex[i0].Eyes.Add(ReadEXP(Eyes[i1])); + this.Dex[i0].Eyes.Add(EXPElement.Read(Eyes[i1])); } } - MsgPack = MsgPack.New; + MsgPack.Dispose(); + return 1; } - private EXPElement ReadEXP(MsgPack mp) => - new EXPElement() { Frame = mp.ReadSingle("F"), Both = mp.ReadUInt16("B"), - ID = mp.ReadUInt16("I"), Value = mp.ReadSingle("V"), - Trans = mp.ReadSingle("T") }; - public void MsgPackWriter(string file, bool JSON) { int i0 = 0; @@ -218,12 +210,12 @@ namespace KKdMainLib MsgPack EXP = MsgPack.New.Add("Name", this.Dex[i0].Name); MsgPack Main = new MsgPack(this.Dex[i0].Main.Count, "Main"); for (i1 = 0; i1 < this.Dex[i0].Main.Count; i1++) - Main[i1] = WriteEXP(this.Dex[i0].Main[i1]); + Main[i1] = this.Dex[i0].Main[i1].Write(); EXP.Add(Main); MsgPack Eyes = new MsgPack(this.Dex[i0].Eyes.Count, "Eyes"); for (i1 = 0; i1 < this.Dex[i0].Eyes.Count; i1++) - Eyes[i1] = WriteEXP(this.Dex[i0].Eyes[i1]); + Eyes[i1] = this.Dex[i0].Eyes[i1].Write(); EXP.Add(Eyes); Dex[i0] = EXP; } @@ -231,10 +223,6 @@ namespace KKdMainLib Dex.Write(true, file, JSON); } - private MsgPack WriteEXP(EXPElement element) => - MsgPack.New.Add("F", element.Frame).Add("B", element.Both ).Add("I", element.ID ) - .Add("V", element.Value).Add("T", element.Trans); - public struct EXP { public int MainOffset; @@ -243,6 +231,8 @@ namespace KKdMainLib public string Name; public List Main; public List Eyes; + + public override string ToString() => Name; } public struct EXPElement @@ -252,6 +242,16 @@ namespace KKdMainLib public ushort ID; public float Value; public float Trans; + + public static EXPElement Read(MsgPack msg) => + new EXPElement() { Frame = msg.ReadSingle("F"), Both = msg.ReadUInt16("B"), + ID = msg.ReadUInt16("I"), Value = msg.ReadSingle("V"), + Trans = msg.ReadSingle("T"), }; + + public MsgPack Write() => + MsgPack.New.Add("F", Frame).Add("B", Both ) + .Add("I", ID).Add("V", Value) + .Add("T", Trans); } } } diff --git a/KKdMainLib/DIVAFILE.cs b/KKdMainLib/DIVAFILE.cs index 16ccf36..7b6d763 100644 --- a/KKdMainLib/DIVAFILE.cs +++ b/KKdMainLib/DIVAFILE.cs @@ -14,7 +14,6 @@ namespace KKdMainLib public static void Decrypt(this string file) { - Console.Title = "DIVAFILE Decrypt - File: " + Path.GetFileName(file); Stream IO = File.OpenReader(file); if (IO.ReadInt64() != 0x454C494641564944) { IO.Close(); return; } @@ -39,7 +38,6 @@ namespace KKdMainLib public static void Encrypt(this string file) { - Console.Title = "DIVAFILE Encrypt - File: " + Path.GetFileName(file); Stream IO = File.OpenReader(file); int FileLengthOrigin = IO.Length; int FileLength = FileLengthOrigin.Align(16); diff --git a/KKdMainLib/DataBank.cs b/KKdMainLib/DataBank.cs index a3efbb6..6173261 100644 --- a/KKdMainLib/DataBank.cs +++ b/KKdMainLib/DataBank.cs @@ -100,13 +100,13 @@ namespace KKdMainLib Success = true; } - MsgPack = MsgPack.New; + MsgPack.Dispose(); } public void MsgPackWriter(string file, bool JSON, bool Compact = true) { if (!Success) return; - MsgPack msgPack = MsgPack.New; + MsgPack MsgPack = MsgPack.New; if (file.Contains("psrData")) { @@ -114,23 +114,23 @@ namespace KKdMainLib { MsgPack psrData = new MsgPack(psrDat.Length, "psrData"); for (i = 0; i < psrDat.Length; i++) psrData[i] = psrDat[i].WriteMP(); - msgPack.Add(psrData); + MsgPack.Add(psrData); } - else msgPack.Add(new MsgPack("psrData", null)); + else MsgPack.Add(new MsgPack("psrData", null)); } else if (file.Contains("PvList")) { if (pvList != null) { - if (Compact) msgPack.Add("Compact", Compact); + if (Compact) MsgPack.Add("Compact", Compact); MsgPack PvList = new MsgPack(pvList.Length, "PvList"); for (i = 0; i < pvList.Length; i++) PvList[i] = pvList[i].WriteMP(Compact); - msgPack.Add(PvList); + MsgPack.Add(PvList); } - else msgPack.Add(new MsgPack("PvList", null)); + else MsgPack.Add(new MsgPack("PvList", null)); } - msgPack.Write(file, JSON).Dispose(); + MsgPack.Write(file, JSON).Dispose(); } public static string UrlEncode(string value) => @@ -278,25 +278,25 @@ namespace KKdMainLib public MsgPack WriteMP(bool Compact) { - MsgPack msgPack = MsgPack.New; - msgPack.Add("ID", PV_ID); - if (!Enable) msgPack.Add("Enable", Enable); - if ( Extra ) msgPack.Add("Extra" , Extra ); + MsgPack MsgPack = MsgPack.New; + MsgPack.Add("ID", PV_ID); + if (!Enable) MsgPack.Add("Enable", Enable); + if ( Extra ) MsgPack.Add("Extra" , Extra ); if (Compact) { - if (AdvDemoStart.WriteLower) msgPack.Add("AdvDemoStart", AdvDemoStart.WriteInt()); - if (AdvDemoEnd .WriteLower) msgPack.Add("AdvDemoEnd" , AdvDemoEnd .WriteInt()); - if (StartShow .WriteLower) msgPack.Add("StartShow" , StartShow .WriteInt()); - if ( EndShow .WriteUpper) msgPack.Add( "EndShow" , EndShow .WriteInt()); + if (AdvDemoStart.WriteLower) MsgPack.Add("AdvDemoStart", AdvDemoStart.WriteInt()); + if (AdvDemoEnd .WriteLower) MsgPack.Add("AdvDemoEnd" , AdvDemoEnd .WriteInt()); + if (StartShow .WriteLower) MsgPack.Add("StartShow" , StartShow .WriteInt()); + if ( EndShow .WriteUpper) MsgPack.Add( "EndShow" , EndShow .WriteInt()); } else { - if (AdvDemoStart.WriteLower) msgPack.Add(AdvDemoStart.WriteMP("AdvDemoStart")); - if (AdvDemoEnd .WriteLower) msgPack.Add(AdvDemoEnd .WriteMP("AdvDemoEnd" )); - if (StartShow .WriteLower) msgPack.Add(StartShow .WriteMP("StartShow" )); - if ( EndShow .WriteUpper) msgPack.Add( EndShow .WriteMP( "EndShow" )); + if (AdvDemoStart.WriteLower) MsgPack.Add(AdvDemoStart.WriteMP("AdvDemoStart")); + if (AdvDemoEnd .WriteLower) MsgPack.Add(AdvDemoEnd .WriteMP("AdvDemoEnd" )); + if (StartShow .WriteLower) MsgPack.Add(StartShow .WriteMP("StartShow" )); + if ( EndShow .WriteUpper) MsgPack.Add( EndShow .WriteMP( "EndShow" )); } - return msgPack; + return MsgPack; } public override string ToString() => diff --git a/KKdMainLib/Extensions.cs b/KKdMainLib/Extensions.cs index 0d136dd..ecf351c 100644 --- a/KKdMainLib/Extensions.cs +++ b/KKdMainLib/Extensions.cs @@ -1,6 +1,6 @@ using KKdBaseLib; +using KKdBaseLib.F2; using KKdMainLib.IO; -using KKdMainLib.F2nd; namespace KKdMainLib { @@ -76,6 +76,57 @@ namespace KKdMainLib stream.WriteEOFC(ID); } } + + public static class StructExtensions + { + public static Struct ReadStruct(byte[] Data) + { + Stream stream = File.OpenReader(Data); + Struct Struct = stream.ReadStruct(stream.ReadHeader(false)); + stream.Close(); + return Struct; + } + + public static Struct ReadStruct(this Stream stream, Header Header) + { + Struct Struct = new Struct { Header = Header, DataOffset = + stream.Position, Data = stream.ReadBytes(Header.SectionSize) }; + int ID = Header.ID; + + KKdList SubStructs = KKdList.New; + long Length = stream.Length - stream.Position; + long Position = 0; + while (Length > Position) + { + Header = stream.ReadHeader(false); + Position += Header.Length + Header.DataSize; + if (Header.ID == ID && Header.Signature == 0x43464F45) + { Struct.EOFC = true; break; } + else if (Header.ID == 0 && (Header.Signature == 0x30464F50 || + Header.Signature == 0x31464F50 || Header.Signature == 0x53524E45)) + SubStructs.Add(new Struct { Header = Header, DataOffset = + stream.Position, Data = stream.ReadBytes(Header.SectionSize) }); + else if (Header.ID <= ID) + { stream.LongPosition -= Header.Length; break; } + else SubStructs.Add(stream.ReadStruct(Header)); + } + + for (int i = 0; i < SubStructs.Capacity; i++) + { + string Sig = SubStructs[i].Header.ToString(); + if (Sig == "ENRS" || Sig == "EOFC" || Sig == "POF0" || Sig == "POF1") + { + if (Sig == "EOFC") Struct.EOFC = true; + else if (Sig == "ENRS") Struct.ENRS = ENRS.Read(SubStructs[i].Data); + else Struct.POF = POF .Read(SubStructs[i].Data, Sig == "POF1"); + SubStructs.RemoveAt(i); SubStructs.Capacity--; i--; + } + } + + if (SubStructs.Capacity > 0) Struct.SubStructs = SubStructs.ToArray(); + return Struct; + } + } public static class MPExt { @@ -84,10 +135,10 @@ namespace KKdMainLib MsgPack MsgPack; if (JSON) { JSON IO = new JSON(File.OpenReader(array)); - MsgPack = IO.Read(); IO.Close(); } + MsgPack = IO.Read( ); IO.Close(); } else { MP IO = new MP(File.OpenReader(array)); - MsgPack = IO.Read(); IO.Close(); } + MsgPack = IO.Read(true); IO.Close(); } return MsgPack; } @@ -96,10 +147,10 @@ namespace KKdMainLib MsgPack MsgPack; if (JSON) { JSON IO = new JSON(File.OpenReader(file + ".json", true)); - MsgPack = IO.Read(); IO.Close(); } + MsgPack = IO.Read( ); IO.Close(); } else { MP IO = new MP(File.OpenReader(file + ".mp" , true)); - MsgPack = IO.Read(); IO.Close(); } + MsgPack = IO.Read(true); IO.Close(); } return MsgPack; } @@ -108,10 +159,10 @@ namespace KKdMainLib MsgPack MsgPack; if (JSON) { JSON IO = new JSON(File.OpenReader(file + ".json")); - MsgPack = IO.Read(); IO.Close(); } + MsgPack = IO.Read( ); IO.Close(); } else { MP IO = new MP(File.OpenReader(file + ".mp" )); - MsgPack = IO.Read(); IO.Close(); } + MsgPack = IO.Read(true); IO.Close(); } return MsgPack; } diff --git a/KKdMainLib/F2/Bloom.cs b/KKdMainLib/F2/Bloom.cs new file mode 100644 index 0000000..1236a8e --- /dev/null +++ b/KKdMainLib/F2/Bloom.cs @@ -0,0 +1,65 @@ +using KKdBaseLib; +using KKdBaseLib.F2; +using KKdMainLib.IO; + +namespace KKdMainLib.F2 +{ + public struct Bloom + { + public CountPointer BLTs; + private Stream IO; + private Header Header; + private int i; + + public void BLTReader(string file) + { + BLTs = default; + IO = File.OpenReader(file + ".blt", true); + Header = IO.ReadHeader(); + if (Header.Signature != 0x544D4C42 || Header.InnerSignature != 0x3) return; + IO.Position -= 0x4; + + BLTs = IO.ReadCountPointerEndian(); + if (BLTs.Count < 1) { IO.Close(); BLTs.Count = -1; return; } + + if (BLTs.Count > 0 && BLTs.Offset == 0) { IO.Close(); BLTs.Count = -1; return; } + + IO.Position = BLTs.Offset; + for (i = 0; i < BLTs.Count; i++) + { + ref BLT BLT = ref BLTs.Entries[i]; + IO.ReadInt32Endian(); + BLT.Color .X = IO.ReadSingleEndian(); + BLT.Color .Y = IO.ReadSingleEndian(); + BLT.Color .Z = IO.ReadSingleEndian(); + BLT.Brightpass.X = IO.ReadSingleEndian(); + BLT.Brightpass.Y = IO.ReadSingleEndian(); + BLT.Brightpass.Z = IO.ReadSingleEndian(); + BLT.Range = IO.ReadSingleEndian(); + } + IO.Close(); + } + + public void TXTWriter(string file) + { + if (BLTs.Count < 1) return; + + IO = File.OpenWriter(); + IO.WriteShiftJIS("ID,ColorR,ColorG,ColorB,BrightpassR,BrightpassG,BrightpassB,Range\n"); + for (i = 0; i < BLTs.Count; i++) + IO.Write(i + "," + BLTs[i] + "\n"); + File.WriteAllBytes(file + "_bloom.txt", IO.ToArray(true)); + } + + public struct BLT + { + public Vector3 Color; + public Vector3 Brightpass; + public float Range; + + public override string ToString() => Color .ToString(6) + "," + + Brightpass.ToString(6) + "," + + Range .ToString(6); + } + } +} diff --git a/KKdMainLib/F2/ColorCorrection.cs b/KKdMainLib/F2/ColorCorrection.cs new file mode 100644 index 0000000..10fac8a --- /dev/null +++ b/KKdMainLib/F2/ColorCorrection.cs @@ -0,0 +1,73 @@ +using KKdBaseLib; +using KKdBaseLib.F2; +using KKdMainLib.IO; + +namespace KKdMainLib.F2 +{ + public struct ColorCorrection + { + public CountPointer CCTs; + private Stream IO; + private Header Header; + private int i; + + public void CCTReader(string file) + { + CCTs = default; + IO = File.OpenReader(file + ".cct", true); + Header = IO.ReadHeader(); + if (Header.Signature != 0x54524343 || Header.InnerSignature != 0x3) return; + IO.Position -= 0x4; + + CCTs = IO.ReadCountPointerEndian(); + if (CCTs.Count < 1) { IO.Close(); CCTs.Count = -1; return; } + + if (CCTs.Count > 0 && CCTs.Offset == 0) { IO.Close(); CCTs.Count = -1; return; } + + IO.Position = CCTs.Offset; + for (i = 0; i < CCTs.Count; i++) + { + ref CCT CCT = ref CCTs.Entries[i]; + IO.ReadInt32Endian(); + CCT.Hue = IO.ReadSingleEndian(); + CCT.Saturation = IO.ReadSingleEndian(); + CCT.Lightness = IO.ReadSingleEndian(); + CCT.Exposure = IO.ReadSingleEndian(); + CCT.Gamma.X = IO.ReadSingleEndian(); + CCT.Gamma.Y = IO.ReadSingleEndian(); + CCT.Gamma.Z = IO.ReadSingleEndian(); + CCT.Contrast = IO.ReadSingleEndian(); + } + + IO.Close(); + } + + public void TXTWriter(string file) + { + if (CCTs.Count < 1) return; + + IO = File.OpenWriter(); + IO.WriteShiftJIS("ID,Hue,Saturation,Lightness,Exposure,GammaR,GammaG,GammaB,Contrast\n"); + for (i = 0; i < CCTs.Count; i++) + IO.Write(i + "," + CCTs[i] + "\n"); + File.WriteAllBytes(file + "_cc.txt", IO.ToArray(true)); + } + + public struct CCT + { + public float Hue; + public float Saturation; + public float Lightness; + public float Exposure; + public Vector3 Gamma; + public float Contrast; + + public override string ToString() => Hue .ToString(6) + "," + + Saturation.ToString(6) + "," + + Lightness .ToString(6) + "," + + Exposure .ToString(6) + "," + + Gamma .ToString(6) + "," + + Contrast .ToString(6); + } + } +} diff --git a/KKdMainLib/F2/DOF.cs b/KKdMainLib/F2/DOF.cs new file mode 100644 index 0000000..529426d --- /dev/null +++ b/KKdMainLib/F2/DOF.cs @@ -0,0 +1,69 @@ +using KKdBaseLib; +using KKdBaseLib.F2; +using KKdMainLib.IO; + +namespace KKdMainLib.F2 +{ + public struct DOF + { + public CountPointer DFTs; + private Stream IO; + private Header Header; + private int i; + + public void DFTReader(string file) + { + DFTs = default; + IO = File.OpenReader(file + ".dft", true); + Header = IO.ReadHeader(); + if (Header.Signature != 0x54464F44 || Header.InnerSignature != 0x3) return; + IO.Position -= 0x4; + + DFTs = IO.ReadCountPointerEndian(); + if (DFTs.Count < 1) { IO.Close(); DFTs.Count = -1; return; } + + if (DFTs.Count > 0 && DFTs.Offset == 0) { IO.Close(); DFTs.Count = -1; return; } + + IO.Position = DFTs.Offset; + for (i = 0; i < DFTs.Count; i++) + { + ref DFT DFT = ref DFTs.Entries[i]; + IO.ReadInt32Endian(); + DFT. Focus = IO.ReadSingleEndian(); + DFT. FocusRange = IO.ReadSingleEndian(); + DFT.FuzzingRange = IO.ReadSingleEndian(); + DFT.Ratio = IO.ReadSingleEndian(); + DFT.Quality = IO.ReadSingleEndian(); + if (IO.IsX) IO.ReadInt32(); + } + + IO.Close(); + } + + public void TXTWriter(string file) + { + if (DFTs.Count < 1) return; + + IO = File.OpenWriter(); + IO.WriteShiftJIS("ID,Focus,FocusRange,FuzzingRange,Ratio,Quality\n"); + for (i = 0; i < DFTs.Count; i++) + IO.Write(i + "," + DFTs[i] + "\n"); + File.WriteAllBytes(file + "_dof.txt", IO.ToArray(true)); + } + + public struct DFT + { + public float Focus; + public float FocusRange; + public float FuzzingRange; + public float Ratio; + public float Quality; + + public override string ToString() => Focus .ToString(6) + "," + + FocusRange.ToString(6) + "," + + FuzzingRange.ToString(6) + "," + + Ratio .ToString(6) + "," + + Quality .ToString(6); + } + } +} diff --git a/KKdMainLib/F2/Light.cs b/KKdMainLib/F2/Light.cs new file mode 100644 index 0000000..f2e3253 --- /dev/null +++ b/KKdMainLib/F2/Light.cs @@ -0,0 +1,130 @@ +using KKdBaseLib; +using KKdBaseLib.F2; +using KKdMainLib.IO; + +namespace KKdMainLib.F2 +{ + public struct Light + { + public CountPointer> LITs; + private Stream IO; + private Header Header; + private int i, i0; + + public void LITReader(string file) + { + LITs = default; + IO = File.OpenReader(file + ".lit", true); + Header = IO.ReadHeader(); + if (Header.Signature != 0x4354494C || Header.InnerSignature != 0x2 || + Header.SectionSignature != 0x2) return; + + LITs = IO.ReadCountPointerEndian>(); + if (LITs.Count < 1) { IO.Close(); LITs.Count = -1; return; } + + IO.Position = LITs.Offset; + for (i = 0; i < LITs.Count; i++) + { + LITs[i] = IO.ReadCountPointerX(); + if ((LITs[i].Count > 0 || LITs[i].Offset == 0) && !IO.IsX) { IO.Close(); LITs.Count = -1; return; } + } + + for (i = 0; i < LITs.Count; i++) + { + IO.Position = LITs[i].Offset; + for (i0 = 0; i0 < LITs[i].Count; i0++) + { + ref LIT LIT = ref LITs.Entries[i].Entries[i0]; + LIT.Id = (Id )IO.ReadInt32Endian(); + LIT.Flags = (Flags)IO.ReadInt32Endian(); + LIT.Type = (Type )IO.ReadInt32Endian(); + if (IO.IsX) { IO.ReadInt64(); IO.ReadInt64(); IO.ReadInt64(); } + LIT.Ambient .X = IO.ReadSingleEndian(); + LIT.Ambient .Y = IO.ReadSingleEndian(); + LIT.Ambient .Z = IO.ReadSingleEndian(); + LIT.Ambient .W = IO.ReadSingleEndian(); + LIT.Diffuse .X = IO.ReadSingleEndian(); + LIT.Diffuse .Y = IO.ReadSingleEndian(); + LIT.Diffuse .Z = IO.ReadSingleEndian(); + LIT.Diffuse .W = IO.ReadSingleEndian(); + LIT.Specular .X = IO.ReadSingleEndian(); + LIT.Specular .Y = IO.ReadSingleEndian(); + LIT.Specular .Z = IO.ReadSingleEndian(); + LIT.Specular .W = IO.ReadSingleEndian(); + LIT.Position .X = IO.ReadSingleEndian(); + LIT.Position .Y = IO.ReadSingleEndian(); + LIT.Position .Z = IO.ReadSingleEndian(); + LIT.ToneCurve.X = IO.ReadSingleEndian(); + LIT.ToneCurve.Y = IO.ReadSingleEndian(); + LIT.ToneCurve.Z = IO.ReadSingleEndian(); + if (IO.IsX) { IO.ReadInt64(); IO.ReadInt64(); IO.ReadInt64(); + IO.ReadInt64(); IO.ReadInt64(); IO.ReadInt32(); } + } + } + IO.Close(); + } + + public void TXTWriter(string file) + { + i = 0; + if (LITs.Count < 1) return; + + IO = File.OpenWriter(); + IO.WriteShiftJIS("Type,AmbientR,AmbientG,AmbientB,DiffuseR,DiffuseG,DiffuseB,SpecularR,SpecularG," + + "SpecularB,SpecularA,PosX,PosY,PosZ,ToneCurveBegin,ToneCurveEnd,ToneCurveBlendRate," + + (file.EndsWith("_chara") ? "コメント" : "ID") + "\n"); + for (i0 = 0; i0 < LITs[i].Count; i0++) + IO.Write(LITs[i][i0] + "," + i + "\n"); + File.WriteAllBytes(file + "_light.txt", IO.ToArray(true)); + } + + public struct LIT + { + public Id Id; + public Flags Flags; + public Type Type; + public Vector4 Ambient; + public Vector4 Diffuse; + public Vector4 Specular; + public Vector3 Position; + public Vector3 ToneCurve; + + public override string ToString() => Flags == 0 ? ",,,,,,,,,,,,,,,," : Type + "," + + ((Flags & Flags.Ambient ) == 0 ? ",,," : Ambient .ToString(6) + ",") + + ((Flags & Flags.Diffuse ) == 0 ? ",,," : Diffuse .ToString(6) + ",") + + ((Flags & Flags.Specular ) == 0 ? ",,,," : Specular .ToString(6) + ",") + + ((Flags & Flags.Position ) == 0 ? ",,," : Position .ToString(6) + ",") + + ((Flags & Flags.ToneCurve) == 0 ? ",,," : ToneCurve.ToString(6)); + } + + public enum Id : int + { + CHARA = 0, + STAGE = 1, + SUN = 2, + REFLECT = 3, + SHADOW = 4, + CHARA_COLOR = 5, + CHARA_F = 6, + PROJECTION = 7, + } + + public enum Type : int + { + OFF = 0, + PARALLEL = 1, + POINT = 2, + SPOT = 3, + } + + public enum Flags : int + { + Type = 0b0000000001, + Ambient = 0b0000000010, + Diffuse = 0b0000000100, + Specular = 0b0000001000, + Position = 0b0000010000, + ToneCurve = 0b1000000000, + } + } +} diff --git a/KKdMainLib/F2nd/Struct.cs b/KKdMainLib/F2nd/Struct.cs deleted file mode 100644 index 402d14a..0000000 --- a/KKdMainLib/F2nd/Struct.cs +++ /dev/null @@ -1,69 +0,0 @@ -using KKdBaseLib; -using KKdMainLib.IO; - -namespace KKdMainLib.F2nd -{ - public struct Struct - { - public Header Header; - public byte[] Data; - public Struct[] SubStructs; - public bool EOFC; - public ENRS[] ENRS; - public KKdList POF; - - public long DataOffset; - - public override string ToString() => Header.ToString() + (SubStructs != null ? - "; SubStructs: " + SubStructs.Length : "")+ (ENRS != null ? "; Has ENRS" : "") + - (POF.NotNull ? "; Has POF" : "") + (EOFC ? "; Has EOFC" : ""); - - public static Struct ReadStruct(byte[] Data) - { - Stream stream = File.OpenReader(Data); - Struct Struct = ReadStruct(ref stream, stream.ReadHeader(false)); - stream.Close(); - return Struct; - } - - private static Struct ReadStruct(ref Stream stream, Header Header) - { - Struct Struct = new Struct { Header = Header, DataOffset = - stream.Position, Data = stream.ReadBytes(Header.SectionSize) }; - int ID = Header.ID; - - KKdList SubStructs = KKdList.New; - long Length = stream.Length - stream.Position; - long Position = 0; - while (Length > Position) - { - Header = stream.ReadHeader(false); - Position += Header.Length + Header.DataSize; - if (Header.ID == ID && Header.Signature == 0x43464F45) - { Struct.EOFC = true; break; } - else if (Header.ID == 0 && (Header.Signature == 0x30464F50 || - Header.Signature == 0x31464F50 || Header.Signature == 0x53524E45)) - SubStructs.Add(new Struct { Header = Header, DataOffset = - stream.Position, Data = stream.ReadBytes(Header.SectionSize) }); - else if (Header.ID <= ID) - { stream.LongPosition -= Header.Length; break; } - else SubStructs.Add(ReadStruct(ref stream, Header)); - } - - for (int i = 0; i < SubStructs.Capacity; i++) - { - string Sig = SubStructs[i].Header.ToString(); - if (Sig == "ENRS" || Sig == "EOFC" || Sig == "POF0" || Sig == "POF1") - { - if (Sig == "EOFC") Struct.EOFC = true; - else if (Sig == "ENRS") Struct.ENRS = F2nd.ENRS.Read(SubStructs[i].Data); - else Struct.POF = F2nd.POF .Read(SubStructs[i].Data, Sig == "POF1"); - SubStructs.RemoveAt(i); SubStructs.Capacity--; i--; - } - } - - if (SubStructs.Capacity > 0) Struct.SubStructs = SubStructs.ToArray(); - return Struct; - } - } -} diff --git a/KKdMainLib/IO/Extensions.cs b/KKdMainLib/IO/Extensions.cs index af3e5ef..351a746 100644 --- a/KKdMainLib/IO/Extensions.cs +++ b/KKdMainLib/IO/Extensions.cs @@ -19,9 +19,15 @@ namespace KKdMainLib.IO } return s.ToArray(); } + + public static byte PeekByte(this Stream stream) + { byte val = stream.ReadByte(); stream.LongPosition--; return val; } + public static char PeekCharASCII(this Stream stream) + { byte val = stream.ReadByte(); stream.LongPosition--; return (char)val; } public static char PeekCharUTF8(this Stream stream) { long LongPosition = stream.LongPosition; char val = stream.ReadCharUTF8(); stream.LongPosition = LongPosition; return val; } + public static Stream SkipWhitespace(this Stream stream) { while (true) @@ -29,6 +35,25 @@ namespace KKdMainLib.IO else break; return stream; } + + public static bool Assert(this Stream stream, byte next) + { if (stream.PeekByte() == next) { stream.PeekByte(); return true; } else return false; } + public static bool Assert(this Stream stream, byte[] next) + { + for (var i = 0; i < next.Length; i++) + if (!stream.Assert(next[i])) return false; + return true; + } + + public static bool AssertASCII(this Stream stream, char next) + { if (stream.PeekCharUTF8() == next) { stream.ReadCharUTF8(); return true; } else return false; } + public static bool AssertASCII(this Stream stream, string next) + { + for (var i = 0; i < next.Length; i++) + if (!stream.AssertASCII(next[i])) return false; + return true; + } + public static bool Assert(this Stream stream, char next) { if (stream.PeekCharUTF8() == next) { stream.ReadCharUTF8(); return true; } else return false; } public static bool Assert(this Stream stream, string next) diff --git a/KKdMainLib/IO/JSON.cs b/KKdMainLib/IO/JSON.cs index 9208928..e551afd 100644 --- a/KKdMainLib/IO/JSON.cs +++ b/KKdMainLib/IO/JSON.cs @@ -173,11 +173,11 @@ namespace KKdMainLib.IO { string s = ""; while (char.IsDigit(_IO.SkipWhitespace(). PeekCharUTF8())) s += _IO.ReadCharUTF8(); return s; } - public JSON Write(MsgPack MsgPack, string End = "\n", string TabChar = " ") - { Write(MsgPack, End, TabChar, "", true); return this; } + public JSON Write(MsgPack MsgPack, string End = "\n", string TabChar = " ") => + Write(MsgPack, End, TabChar, "", true); - public JSON Write(MsgPack MsgPack, bool Style = false) - { Write(MsgPack, "\n", " ", "", Style); return this; } + public JSON Write(MsgPack MsgPack, bool Style = false) => + Write(MsgPack, "\n", " ", "", Style); private JSON Write(MsgPack MsgPack, string End, string TabChar, string Tab, bool Style, bool IsArray = false) { @@ -185,7 +185,7 @@ namespace KKdMainLib.IO Tab += TabChar; if (MsgPack.Name != null && !IsArray) _IO.Write("\"" + MsgPack.Name + "\":" + (Style ? " " : "")); if (MsgPack.Object == null) { WriteNil(); return this; } - + if (MsgPack.List.NotNull) { WriteMap(); @@ -228,33 +228,13 @@ namespace KKdMainLib.IO if (Style) _IO.Write(OldTab); WriteArr(true); } - else if (MsgPack.Object is MsgPack msg) - Write(msg, End, TabChar, Tab, Style); - else Write(MsgPack.Object, End, TabChar, Tab, Style); + else if (MsgPack.Object is MsgPack msg) Write(msg, End, TabChar, Tab, Style); + else if (MsgPack.Object is string str) Write(str); + else _IO.Write(BaseExtensions.ToString(MsgPack.Object)); return this; } - private void Write(object obj, string End, string TabChar, string Tab, bool Style) - { - if (obj == null) { WriteNil(); return; } - switch (obj) - { - case MsgPack val: Write(val, End, TabChar, Tab, Style); break; - case string val: Write(val); break; - case bool Boolean: - case sbyte Int8 : - case byte UInt8 : - case short Int16: - case ushort UInt16: - case int Int32: - case uint UInt32: - case long Int64: - case ulong UInt64: - case float Float32: - case double Float64: _IO.Write(BaseExtensions.ToString(obj)); break; - } - } private void Write(string val) => _IO.Write("\"" + val .Replace("\\", "\\\\").Replace("/" , "\\/").Replace("\"", "\\\"") .Replace("\0", "\\0" ).Replace("\b", "\\b").Replace("\f", "\\f" ) diff --git a/KKdMainLib/IO/MP.cs b/KKdMainLib/IO/MP.cs index 05ca9fe..8959ca8 100644 --- a/KKdMainLib/IO/MP.cs +++ b/KKdMainLib/IO/MP.cs @@ -16,8 +16,8 @@ namespace KKdMainLib.IO public MsgPack Read(bool Array = false) { MsgPack MsgPack = MsgPack.New; - if (!Array) MsgPack.Name = ReadString((Types)_IO.ReadByte()); byte Unk = _IO.ReadByte(); + if (!Array) { MsgPack.Name = ReadString((Types)Unk); Unk = _IO.ReadByte(); } Types Type = (Types)Unk; if (Type >= Types.FixMap && Type <= Types.FixMapMax) @@ -30,7 +30,7 @@ namespace KKdMainLib.IO MsgPack.Object = new MsgPack[Unk - (byte)Types.FixArr]; for (int i = 0; i < Unk - (byte)Types.FixArr; i++) MsgPack[i] = Read( true); } - else if (Type >= Types.FixStr && Type <= Types.FixStrMax) MsgPack.Object = ReadString( Type); + else if (Type >= Types.FixStr && Type <= Types.FixStrMax) MsgPack.Object = ReadString(Type); else if (Type >= Types.PosInt && Type <= Types.PosIntMax) MsgPack.Object = Unk; else if (Type >= Types.NegInt && Type <= Types.NegIntMax) MsgPack.Object = (sbyte)Unk; else diff --git a/KKdMainLib/IO/Stream.cs b/KKdMainLib/IO/Stream.cs index 8097d46..e560c07 100644 --- a/KKdMainLib/IO/Stream.cs +++ b/KKdMainLib/IO/Stream.cs @@ -368,8 +368,8 @@ namespace KKdMainLib.IO ValWrite &= 0xFF; } - public void CheckRead () { if (BitRead > 0) ValRead = 0; BitRead = 8; } - public void CheckWrited() { if (BitWrite > 0) { Write(ValWrite); ValWrite = 0; BitWrite = 0; } } + public void CheckRead () { if (BitRead > 0) ValRead = 0; BitRead = 8; } + public void CheckWrited() { if (BitWrite > 0) { WriteByte((byte)ValWrite); ValWrite = 0; BitWrite = 0; } } public byte[] ToArray(bool Close) { byte[] Data = ToArray(); if (Close) this.Close(); return Data; } diff --git a/KKdMainLib/KKdMainLib.csproj b/KKdMainLib/KKdMainLib.csproj index 6222a4d..af1199e 100644 --- a/KKdMainLib/KKdMainLib.csproj +++ b/KKdMainLib/KKdMainLib.csproj @@ -42,10 +42,10 @@ - - - - + + + + @@ -61,6 +61,7 @@ + diff --git a/KKdMainLib/Main.cs b/KKdMainLib/Main.cs index 894cfaa..4860e3e 100644 --- a/KKdMainLib/Main.cs +++ b/KKdMainLib/Main.cs @@ -82,35 +82,33 @@ namespace KKdMainLib Multiselect = true, Title = "Choose file(s) to open:" }; ofd.Filter = GetArgs("All;", false, "*"); - if (filetype == "a3da") ofd.Filter = GetArgs("A3DA", "a3da", "farc", "json", "mp") + - GetArgs("A3DA", true, "a3da") + GetArgs("FARC", true, "farc") + JSON + MsgPack; + if (filetype == "a3da") ofd.Filter = GetArgs("A3DA", "a3da", "farc", "json", "mp") + + GetArgs("A3DA", true, "a3da") + GetArgs("FARC", true, "farc") + JSON + MsgPack; else if (filetype == "bin" ) ofd.Filter = GetArgs("BIN" , "bin", "json", "mp") + BIN + JSON + MsgPack; + else if (filetype == "blt" ) ofd.Filter = GetArgs("BLT" , "blt"); else if (filetype == "bon" ) ofd.Filter = GetArgs("BON" , "bon", "bin", "json", "mp") + GetArgs("BON", true, "bon") + BIN + JSON + MsgPack; + else if (filetype == "cct" ) ofd.Filter = GetArgs("CCT" , "cct"); else if (filetype == "databank") ofd.Filter = GetArgs("DAT", "dat", "json", "mp") + GetArgs("DAT", true, "dat") + JSON + MsgPack; else if (filetype == "dex" ) ofd.Filter = GetArgs("DEX" , "dex", "bin", "json", "mp") + GetArgs("DEX", true, "dex") + BIN + JSON + MsgPack; + else if (filetype == "dft") ofd.Filter = GetArgs("DFT" , "dft"); else if (filetype == "diva") ofd.Filter = GetArgs("DIVA", "diva", "wav") + GetArgs("DIVA", true, "diva") + GetArgs("WAV", true, "wav"); else if (filetype == "dsc" ) ofd.Filter = GetArgs("DSC" , "dsc", "json", "mp") + GetArgs("DSC", true, "dsc") + JSON + MsgPack; else if (filetype == "farc") ofd.Filter = "FARC Archives (*.farc)|*.farc"; - else if (filetype == "image") ofd.Filter = GetArgs("Image", "dds", "png") + - GetArgs("DDS", true, "dds") + GetArgs("PNG", true, "png"); else if (filetype == "json") ofd.Filter = "JSON (*.json)|*.json"; - else if (filetype == "kki" ) ofd.Filter = GetArgs("KKI", "kki"); else if (filetype == "mp" ) ofd.Filter = GetArgs("MessagePack", "mp"); - else if (filetype == "ppd" ) ofd.Filter = GetArgs("PPD", "ppd", "pak", "mod") + - GetArgs("PPD", true, "ppd") + GetArgs("PAK", true, "pak") + GetArgs("MOD", true, "mod"); - else if (filetype == "str" ) ofd.Filter = GetArgs("STR", "str", "bin", "json", "mp") + + else if (filetype == "lit") ofd.Filter = GetArgs("LIT" , "lit"); + else if (filetype == "str" ) ofd.Filter = GetArgs("STR" , "str", "bin", "json", "mp") + GetArgs("STR", true, "str") + BIN + JSON + MsgPack; - else if (filetype == "vag" ) ofd.Filter = GetArgs("VAG", "vag", "wav") + + else if (filetype == "vag" ) ofd.Filter = GetArgs("VAG" , "vag", "wav") + GetArgs("VAG", true, "vag") + GetArgs("WAV", true, "wav"); - if (ofd.ShowDialog() == DialogResult.OK) - FileNames = ofd.FileNames; + if (ofd.ShowDialog() == DialogResult.OK) FileNames = ofd.FileNames; ofd.Dispose(); } else if (code == 2) @@ -126,27 +124,6 @@ namespace KKdMainLib } return ""; } - - public static void ChooseSave(string filetype, - out string InitialDirectory, out string[] FileNames) - { - InitialDirectory = ""; - FileNames = new string[0]; - Console.WriteLine("Choose file to save:"); - SaveFileDialog sfd = new SaveFileDialog { InitialDirectory = Application.StartupPath }; - switch (filetype) - { - case "kki": - sfd.Filter = "KKI file (*.kki)|*.kki"; - break; - } - if (sfd.ShowDialog() == DialogResult.OK) - { - InitialDirectory = sfd.InitialDirectory.ToString(); - FileNames = sfd.FileNames; - } - sfd.Dispose(); - } public static string NullTerminated(this string Source, ref int i, byte End) { diff --git a/KKdMainLib/Mot.cs b/KKdMainLib/Mot.cs new file mode 100644 index 0000000..6e72cd8 --- /dev/null +++ b/KKdMainLib/Mot.cs @@ -0,0 +1,327 @@ +//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/ + +using KKdBaseLib; +using KKdMainLib.IO; + +namespace KKdMainLib +{ + public struct Mot + { + private int i, i0, i1; + private MotHeader[] MOT; + private Stream IO; + + public void MOTReader(string file) + { + IO = File.OpenReader(file + ".bin"); + + i = 0; + while (true) + if (IO.ReadInt64() == 0) break; + else { IO.ReadInt64(); i++; } + if (i == 0) return; + + int MOTCount = i; + MsgPack m = new MsgPack(MOTCount, "Mot"); + MOT = new MotHeader[MOTCount]; + for (i = 0; i < MOTCount; i++) + { + ref MotHeader Mot = ref MOT[i]; + Mot.KeySet .Offset = IO.ReadInt32(); + Mot.KeySetTypesOffset = IO.ReadInt32(); + Mot. KeySetOffset = IO.ReadInt32(); + Mot.BoneInfo .Offset = IO.ReadInt32(); + } + + for (i = 0; i < MOTCount; i++) + { + ref MotHeader Mot = ref MOT[i]; + + i0 = 1; + IO.Position = Mot.BoneInfo.Offset; + IO.ReadUInt16(); + while (IO.ReadUInt16() != 0) i0++; + + Mot.BoneInfo.Value = new BoneInfo[i0]; + IO.Position = Mot.BoneInfo.Offset; + for (i0 = 0; i0 < Mot.BoneInfo.Value.Length; i0++) + Mot.BoneInfo.Value[i0].Id = IO.ReadUInt16(); + + IO.Position = Mot.KeySet.Offset; + int info = IO.ReadUInt16(); + Mot.HighBits = info >> 14; + Mot.FrameCount = IO.ReadUInt16(); + + Mot.KeySet.Value = new KeySet[info & 0x3FFF]; + IO.Position = Mot.KeySetTypesOffset; + for (i0 = 0; i0 < Mot.KeySet.Value.Length; i0++) + { + if (i0 % 8 == 0) i1 = IO.ReadUInt16(); + + Mot.KeySet.Value[i0] = new KeySet { Type = (KeySetType)((i1 >> (i0 % 8 * 2)) & 0b11) }; + } + + IO.Position = Mot.KeySetOffset; + for (i0 = 0; i0 < Mot.KeySet.Value.Length; i0++) + { + ref KeySet Key = ref Mot.KeySet.Value[i0]; + if (Key.Type == KeySetType.Static) + { Key.Keys = new KFT2[1]; + Key.Keys[0].V = IO.ReadSingle(); } + else if (Key.Type == KeySetType.Linear) + { + Key.Keys = new KFT2[IO.ReadUInt16()]; + for (i1 = 0; i1 < Key.Keys.Length; i1++) + Key.Keys[i1].F = IO.ReadUInt16(); + IO.Align(0x4); + for (i1 = 0; i1 < Key.Keys.Length; i1++) + Key.Keys[i1].V = IO.ReadSingle(); + } + else if (Key.Type == KeySetType.Interpolated) + { + Key.Keys = new KFT2[IO.ReadUInt16()]; + for (i1 = 0; i1 < Key.Keys.Length; i1++) + Key.Keys[i].F = IO.ReadUInt16(); + IO.Align(0x4); + for (i1 = 0; i1 < Key.Keys.Length; i1++) + { Key.Keys[i1].V = IO.ReadSingle(); Key.Keys[i1].T = IO.ReadSingle(); } + } + } + } + IO.Close(); + } + + public void MOTWriter(string file) + { + if (MOT == null) return; + IO = File.OpenWriter(file + ".bin"); + + int MOTCount = MOT.Length; + IO.Position = (MOTCount + 1) << 4; + for (i = 0; i < MOTCount; i++) + { + ref MotHeader Mot = ref MOT[i]; + Mot.KeySet.Offset = IO.Position; + IO.Write((ushort)((Mot.HighBits << 14) | (Mot.KeySet.Value.Length & 0x3FFF))); + IO.Write((ushort)Mot.FrameCount); + + Mot.KeySetTypesOffset = IO.Position; + for (i0 = 0, i1 = 0; i0 < Mot.KeySet.Value.Length; i0++) + { + i1 |= ((byte)Mot.KeySet.Value[i0].Type << (i0 % 8 * 2)) & (0b11 << (i0 % 8 * 2)); + + if (i0 % 8 == 7) { IO.Write((ushort)i1); i1 = 0; } + } + IO.Write((ushort)i1); + + IO.Align(0x4); + Mot.KeySetOffset = IO.Position; + for (i0 = 0; i0 < Mot.KeySet.Value.Length; i0++) + { + ref KeySet Key = ref Mot.KeySet.Value[i0]; + if (Key.Type == KeySetType.Static) + IO.Write(Key.Keys[0].V); + else if (Key.Type == KeySetType.Linear) + { + IO.Write((ushort)Key.Keys.Length); + for (i1 = 0; i1 < Key.Keys.Length; i1++) + IO.Write(Key.Keys[i1].F); + IO.Align(0x4); + for (i1 = 0; i1 < Key.Keys.Length; i1++) + IO.Write(Key.Keys[i1].V); + } + else if (Key.Type == KeySetType.Interpolated) + { + IO.Write((ushort)Key.Keys.Length); + for (i1 = 0; i1 < Key.Keys.Length; i1++) + IO.Write(Key.Keys[i1].F); + IO.Align(0x4); + for (i1 = 0; i1 < Key.Keys.Length; i1++) + { IO.Write(Key.Keys[i1].V); IO.Write(Key.Keys[i1].T); } + } + } + IO.Align(0x4); + + Mot.BoneInfo.Offset = IO.Position; + for (i0 = 0; i0 < Mot.BoneInfo.Value.Length; i0++) + IO.Write((ushort)Mot.BoneInfo.Value[i0].Id); + IO.Write((ushort)0); + } + IO.Align(0x4, true); + + IO.Position = 0; + for (i = 0; i < MOTCount; i++) + { + ref MotHeader Mot = ref MOT[i]; + IO.Write(Mot.KeySet .Offset); + IO.Write(Mot.KeySetTypesOffset); + IO.Write(Mot. KeySetOffset); + IO.Write(Mot.BoneInfo .Offset); + } + + IO.Close(); + } + + public void MsgPackReader(string file, bool JSON) + { + MOT = null; + + MsgPack MsgPack = file.ReadMP(JSON); + if (!MsgPack.ElementArray("MOT", out MsgPack MOTS)) { MsgPack.Dispose(); return; } + + if (MOTS.Array != null) + if (MOTS.Array.Length > 0) + { + MOT = new MotHeader[MOTS.Array.Length]; + for (int i = 0; i < MOT.Length; i++) + MsgPackReader(MOTS.Array[i], ref MOT[i]); + } + + MsgPack.Dispose(); + } + + public void MsgPackWriter(string file, bool JSON) + { + int MOTCount = MOT.Length; + MsgPack MOTS = new MsgPack(MOTCount, "MOT"); + for (i = 0; i < MOTCount; i++) + MOTS[i] = MsgPackWriter(ref MOT[i]); + MOTS.Write(true, file, JSON); + } + + public void MsgPackReader(MsgPack MOT, ref MotHeader Mot) + { + MsgPack Temp = MsgPack.New; + Mot.HighBits = MOT.ReadInt32("HighBits" ); + Mot.FrameCount = MOT.ReadInt32("FrameCount"); + + if (!MOT.ElementArray("KeySets", out Temp)) return; + + Mot.KeySet.Value = new KeySet[Temp.Array.Length]; + for (i0 = 0; i0 < Mot.KeySet.Value.Length; i0++) + { + ref KeySet KeySet = ref Mot.KeySet.Value[i0]; + + if (Temp.Array[i0].Array == null || Temp.Array[i0].Array.Length != 2) continue; + KeySet.Type = (KeySetType)Temp.Array[i0].Array[0].ReadInt32(); + + MsgPack keySet = Temp.Array[i0].Array[1]; + + if (keySet.Array == null) { KeySet.Type = 0; continue; } + else if (KeySet.Type == KeySetType.None) continue; + else if (KeySet.Type == KeySetType.Static) + { + KeySet.Keys = new KFT2[1]; + KeySet.Keys[0].F = keySet.Array[0][0].ReadUInt16(); + KeySet.Keys[0].V = keySet.Array[0][1].ReadSingle(); + } + else if (KeySet.Type == KeySetType.Linear) + { + KeySet.Keys = new KFT2[keySet.Array.Length]; + for (i1 = 0; i1 < keySet.Array.Length; i1++) + { + KeySet.Keys[i1].F = keySet.Array[i1][0].ReadUInt16(); + KeySet.Keys[i1].V = keySet.Array[i1][1].ReadSingle(); + } + } + else if (KeySet.Type == KeySetType.Interpolated) + { + KeySet.Keys = new KFT2[keySet.Array.Length]; + for (i1 = 0; i1 < keySet.Array.Length; i1++) + { + KeySet.Keys[i1].F = keySet.Array[i1][0].ReadUInt16(); + KeySet.Keys[i1].V = keySet.Array[i1][1].ReadSingle(); + KeySet.Keys[i1].T = keySet.Array[i1][2].ReadSingle(); + } + } + } + + if (MOT.ElementArray("BoneInfo", out Temp)) + { + Mot.BoneInfo.Value = new BoneInfo[Temp.Array.Length]; + for (i = 0; i < Mot.BoneInfo.Value.Length; i++) + Mot.BoneInfo.Value[i].Id = Temp[i].ReadInt32(); + } + else return; + } + + public MsgPack MsgPackWriter(ref MotHeader Mot) + { + MsgPack MOT = MsgPack.NewReserve(4).Add("FrameCount", Mot.FrameCount).Add("HighBits", Mot.HighBits); + + MsgPack KeySets = new MsgPack(Mot.KeySet.Value.Length, "KeySets"); + for (i0 = 0; i0 < Mot.KeySet.Value.Length; i0++) + { + ref KeySet KeySet = ref Mot.KeySet.Value[i0]; + if (KeySet.Type == KeySetType.None) continue; + + KeySets[i0] = new MsgPack(2); + KeySets[i0].Array[0] = (MsgPack)(byte)KeySet.Type; + KeySets[i0].Array[1] = new MsgPack(KeySet.Keys.Length); + if (KeySet.Type == KeySetType.Static) + { + KeySets[i0].Array[1][0] = new MsgPack(2); + KeySets[i0].Array[1][0].Array[0] = (MsgPack)KeySet.Keys[0].F; + KeySets[i0].Array[1][0].Array[1] = (MsgPack)KeySet.Keys[0].V; + } + else if (KeySet.Type == KeySetType.Linear) + for (i1 = 0; i1 < KeySet.Keys.Length; i1++) + { + KeySets[i0].Array[1][i1] = new MsgPack(2); + KeySets[i0].Array[1][i1].Array[0] = (MsgPack)KeySet.Keys[i1].F; + KeySets[i0].Array[1][i1].Array[1] = (MsgPack)KeySet.Keys[i1].V; + } + else + for (i1 = 0; i1 < KeySet.Keys.Length; i1++) + { + KeySets[i0].Array[1][i1] = new MsgPack(3); + KeySets[i0].Array[1][i1].Array[0] = (MsgPack)KeySet.Keys[i1].F; + KeySets[i0].Array[1][i1].Array[1] = (MsgPack)KeySet.Keys[i1].V; + KeySets[i0].Array[1][i1].Array[2] = (MsgPack)KeySet.Keys[i1].T; + } + } + MOT.Add(KeySets); + + MsgPack BoneInfo = new MsgPack(Mot.BoneInfo.Value.Length, "BoneInfo"); + for (i0 = 0; i0 < Mot.BoneInfo.Value.Length; i0++) + BoneInfo[i0] = (MsgPack)Mot.BoneInfo.Value[i0].Id; + MOT.Add(BoneInfo); + + return MOT; + } + + public struct MotHeader + { + public int KeySetOffset; + public int KeySetTypesOffset; + public Pointer< KeySet []> KeySet ; + public Pointer BoneInfo; + + public int HighBits; + public int FrameCount; + } + + public struct KeySet + { + public KFT2[] Keys; + public KeySetType Type; + + public override string ToString() => $"Type: {Type}" + (Type == KeySetType.Static ? + $"; Value: {Keys[0].Check()}" : Type > KeySetType.Static ? $"; Keys: {Keys.Length}" : ""); + } + + public enum KeySetType : byte + { + None = 0b00, + Static = 0b01, + Linear = 0b10, + Interpolated = 0b11, + } + + public struct BoneInfo + { + public string Name; + public int Id; + } + } +} diff --git a/KKdMainLib/Properties/AssemblyInfo.cs b/KKdMainLib/Properties/AssemblyInfo.cs index 5b03fc6..8b73bc5 100644 --- a/KKdMainLib/Properties/AssemblyInfo.cs +++ b/KKdMainLib/Properties/AssemblyInfo.cs @@ -11,5 +11,5 @@ using System.Runtime.InteropServices; [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: Guid("2BA7EFC6-91D1-8BBC-C487-06C7F36CC789")] -[assembly: AssemblyVersion("0.4.7.1")] -[assembly: AssemblyFileVersion("0.4.7.1")] +[assembly: AssemblyVersion("0.4.7.2")] +[assembly: AssemblyFileVersion("0.4.7.2")] diff --git a/KKdMainLib/STR.cs b/KKdMainLib/STR.cs index c22ae3a..d012e3e 100644 --- a/KKdMainLib/STR.cs +++ b/KKdMainLib/STR.cs @@ -1,6 +1,6 @@ using KKdBaseLib; +using KKdBaseLib.F2; using KKdMainLib.IO; -using KKdMainLib.F2nd; namespace KKdMainLib { @@ -183,7 +183,7 @@ namespace KKdMainLib if (STRs[i].Str.Value == null) STRs[i].Str.Value = ""; } - MsgPack = MsgPack.New; + MsgPack.Dispose(); } public void MsgPackWriter(string file, bool JSON) diff --git a/KKdSoundLib/VAG.cs b/KKdSoundLib/VAG.cs index 07884d8..2ce3e03 100644 --- a/KKdSoundLib/VAG.cs +++ b/KKdSoundLib/VAG.cs @@ -89,7 +89,6 @@ namespace KKdSoundLib VAGData.DataPtr[i * ch + c] = temp_bufferPtr[i ]; VAGData.DataPtr[i2 * ch + c] = temp_bufferPtr[i2]; } - } else for (i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS) diff --git a/PD_Tool/PD_Tool.csproj b/PD_Tool/PD_Tool.csproj index 879b0c6..ee41724 100644 --- a/PD_Tool/PD_Tool.csproj +++ b/PD_Tool/PD_Tool.csproj @@ -39,14 +39,19 @@ IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006 - + + + + + + diff --git a/PD_Tool/Program.cs b/PD_Tool/Program.cs index 02bcd6b..4bb44d6 100644 --- a/PD_Tool/Program.cs +++ b/PD_Tool/Program.cs @@ -1,4 +1,5 @@ using System; +using KKdMainLib; using KKdMainLib.IO; using KKdMain = KKdMainLib.Main; using KKdFARC = KKdMainLib.FARC; @@ -7,11 +8,16 @@ namespace PD_Tool { public static class Program { + [System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)] + static extern bool SetProcessDPIAware(); + [ThreadStatic] public static string function = ""; [STAThread] public static void Main(string[] args) { + SetProcessDPIAware(); + Console.Title = "PD_Tool"; if (args.Length == 0) { @@ -41,6 +47,9 @@ namespace PD_Tool private static void MainMenu() { + GC.Collect(); + Console. InputEncoding = System.Text.Encoding.Unicode; + Console.OutputEncoding = System.Text.Encoding.Unicode; Console.Title = "PD_Tool"; Console.Clear(); @@ -52,8 +61,9 @@ namespace PD_Tool KKdMain.ConsoleDesign("3. Decrypt from DIVAFILE"); KKdMain.ConsoleDesign("4. Encrypt to DIVAFILE"); KKdMain.ConsoleDesign("5. DB_Tools"); - KKdMain.ConsoleDesign("6. Converting Tools"); - KKdMain.ConsoleDesign(JSON ? "7. MsgPack to JSON" : "7. JSON to MsgPack"); + KKdMain.ConsoleDesign("6. AC/DT/F/AFT/FT Converting Tools"); + KKdMain.ConsoleDesign("7. F/F2/X/FT Converting Tools"); + KKdMain.ConsoleDesign(JSON ? "8. MsgPack to JSON" : "9. JSON to MsgPack"); KKdMain.ConsoleDesign(false); KKdMain.ConsoleDesign(JSON ? "M. MessagePack" : "J. JSON"); KKdMain.ConsoleDesign("Q. Quit"); @@ -81,17 +91,17 @@ namespace PD_Tool else if (function == "6") { Console.Clear(); - Console.Title = "Converter Tools"; + Console.Title = "AC/DT/F/AFT/FT Converting Tools"; KKdMain.ConsoleDesign(true); - KKdMain.ConsoleDesign(" Choose tool:"); + KKdMain.ConsoleDesign(" Choose converter:"); KKdMain.ConsoleDesign(false); - KKdMain.ConsoleDesign("1. A3DA Converter"); - KKdMain.ConsoleDesign("2. AET Converter"); - KKdMain.ConsoleDesign("3. DataBank Converter"); - KKdMain.ConsoleDesign("4. DEX Converter"); - KKdMain.ConsoleDesign("5. DIVA Converter"); - KKdMain.ConsoleDesign("6. STR Converter"); - KKdMain.ConsoleDesign("7. VAG Converter"); + KKdMain.ConsoleDesign("1. A3DA" ); + KKdMain.ConsoleDesign("2. AET" ); + KKdMain.ConsoleDesign("3. DataBank"); + KKdMain.ConsoleDesign("4. DEX" ); + KKdMain.ConsoleDesign("5. DIVA" ); + KKdMain.ConsoleDesign("6. MOT" ); + KKdMain.ConsoleDesign("7. STR" ); KKdMain.ConsoleDesign(false); KKdMain.ConsoleDesign("R. Return to Main Menu"); KKdMain.ConsoleDesign(false); @@ -104,17 +114,56 @@ namespace PD_Tool else if (Function == "3") Tools.DB .Processor(JSON); else if (Function == "4") Tools.DEX.Processor(JSON); else if (Function == "5") Tools.DIV.Processor(); - else if (Function == "6") Tools.STR.Processor(JSON); - else if (Function == "7") Tools.VAG.Processor(); + else if (Function == "6") Tools.MOT.Processor(JSON); + else if (Function == "7") Tools.STR.Processor(JSON); else function = Function; } else if (function == "7") + { + Console.Clear(); + Console.Title = "F/F2/X/FT Converting Tools"; + KKdMain.ConsoleDesign(true); + KKdMain.ConsoleDesign(" Choose converter:"); + KKdMain.ConsoleDesign(false); + KKdMain.ConsoleDesign("1. A3DA" ); + KKdMain.ConsoleDesign("2. Bloom" ); + KKdMain.ConsoleDesign("3. Color Correction"); + KKdMain.ConsoleDesign("4. DEX" ); + KKdMain.ConsoleDesign("5. DOF" ); + KKdMain.ConsoleDesign("6. Light" ); + KKdMain.ConsoleDesign("7. STR" ); + KKdMain.ConsoleDesign("8. VAG" ); + KKdMain.ConsoleDesign(false); + KKdMain.ConsoleDesign("R. Return to Main Menu"); + KKdMain.ConsoleDesign(false); + KKdMain.ConsoleDesign(true); + Console.WriteLine(); + string Function = Console.ReadLine(); + Console.Clear(); + if (Function == "1") Tools.A3D.Processor(JSON); + else if (Function == "2") Tools.BLT.Processor(); + else if (Function == "3") Tools.CCT.Processor(); + else if (Function == "4") Tools.DEX.Processor(JSON); + else if (Function == "5") Tools.DFT.Processor(); + else if (Function == "6") Tools.LIT.Processor(); + else if (Function == "7") Tools.STR.Processor(JSON); + else if (Function == "8") Tools.VAG.Processor(); + else function = Function; + } + else if (function == "8") { KKdMain.Choose(1, JSON ? "mp" : "json", out string[] FileNames); - if (JSON) foreach (string file in FileNames) - KKdMainLib.MPExt.ToJSON (file.Replace(Path.GetExtension(file), "")); - else foreach (string file in FileNames) - KKdMainLib.MPExt.ToMsgPack(file.Replace(Path.GetExtension(file), "")); + foreach (string file in FileNames) + if (JSON) + { + Console.Title = "MsgPack to JSON: " + Path.GetFileNameWithoutExtension(file); + MPExt.ToJSON (file.Replace(Path.GetExtension(file), "")); + } + else + { + Console.Title = "JSON to MsgPack: " + Path.GetFileNameWithoutExtension(file); + MPExt.ToMsgPack(file.Replace(Path.GetExtension(file), "")); + } } } diff --git a/PD_Tool/Properties/AssemblyInfo.cs b/PD_Tool/Properties/AssemblyInfo.cs index ea2ff75..784a998 100644 --- a/PD_Tool/Properties/AssemblyInfo.cs +++ b/PD_Tool/Properties/AssemblyInfo.cs @@ -11,5 +11,5 @@ using System.Runtime.InteropServices; [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")] -[assembly: AssemblyVersion("0.4.7.1")] -[assembly: AssemblyFileVersion("0.4.7.1")] +[assembly: AssemblyVersion("0.4.7.2")] +[assembly: AssemblyFileVersion("0.4.7.2")] diff --git a/PD_Tool/classes/Tools/BLT.cs b/PD_Tool/classes/Tools/BLT.cs new file mode 100644 index 0000000..ce7cf7b --- /dev/null +++ b/PD_Tool/classes/Tools/BLT.cs @@ -0,0 +1,33 @@ +using System; +using KKdMainLib; +using KKdMainLib.IO; +using KKdMainLib.F2; + +namespace PD_Tool.Tools +{ + public class BLT + { + public static void Processor() + { + Console.Title = "Bloom Converter"; + Bloom Bloom; + Main.Choose(1, "blt", out string[] FileNames); + if (FileNames.Length < 1) return; + string filepath = ""; + string ext = ""; + + foreach (string file in FileNames) + { + Bloom = new Bloom(); + ext = Path.GetExtension(file); + filepath = file.Replace(ext, ""); + ext = ext.ToLower(); + + Console.Title = "Bloom Converter: " + Path.GetFileNameWithoutExtension(file); + if (ext == ".blt") { Bloom.BLTReader(filepath); Bloom.TXTWriter(filepath); } + //else if (ext == ".txt") { Bloom.TXTReader(filepath); Bloom.BLTWriter(filepath); } + Bloom = new Bloom(); + } + } + } +} diff --git a/PD_Tool/classes/Tools/CCT.cs b/PD_Tool/classes/Tools/CCT.cs new file mode 100644 index 0000000..09529fb --- /dev/null +++ b/PD_Tool/classes/Tools/CCT.cs @@ -0,0 +1,33 @@ +using System; +using KKdMainLib; +using KKdMainLib.IO; +using KKdMainLib.F2; + +namespace PD_Tool.Tools +{ + public class CCT + { + public static void Processor() + { + Console.Title = "Color Correction Converter"; + ColorCorrection ColorCorrection; + Main.Choose(1, "cct", out string[] FileNames); + if (FileNames.Length < 1) return; + string filepath = ""; + string ext = ""; + + foreach (string file in FileNames) + { + ColorCorrection = new ColorCorrection(); + ext = Path.GetExtension(file); + filepath = file.Replace(ext, ""); + ext = ext.ToLower(); + + Console.Title = "Color Correction Converter: " + Path.GetFileNameWithoutExtension(file); + if (ext == ".cct") { ColorCorrection.CCTReader(filepath); ColorCorrection.TXTWriter(filepath); } + //else if (ext == ".txt") { ColorCorrection.TXTReader(filepath); ColorCorrection.BLTWriter(filepath); } + ColorCorrection = new ColorCorrection(); + } + } + } +} diff --git a/PD_Tool/classes/Tools/DEX.cs b/PD_Tool/classes/Tools/DEX.cs index 6db7442..96863d0 100644 --- a/PD_Tool/classes/Tools/DEX.cs +++ b/PD_Tool/classes/Tools/DEX.cs @@ -31,7 +31,7 @@ namespace PD_Tool.Tools Main.ConsoleDesign(" Choose type of exporting file:"); Main.ConsoleDesign(false); Main.ConsoleDesign("1. F/FT PS3/PS4/PSVita"); - Main.ConsoleDesign("2. F2nd PS3/PSVita"); + Main.ConsoleDesign("2. F2 PS3/PSVita"); Main.ConsoleDesign("3. X PS4/PSVita"); if ( MP && !JSON) Main.ConsoleDesign("9. MessagePack"); if (_JSON && JSON) Main.ConsoleDesign("9. JSON"); @@ -47,6 +47,7 @@ namespace PD_Tool.Tools else if (format == "9" && (MP && _JSON)) Format = Format.NULL; else return; + int state; foreach (string file in FileNames) { DEX = new KKdDEX(); @@ -56,12 +57,15 @@ namespace PD_Tool.Tools Console.Title = "DEX Converter: " + Path.GetFileNameWithoutExtension(file); if (ext == ".bin" || ext == ".dex") - DEX. DEXReader(filepath, ext ); - else DEX.MsgPackReader(filepath, JSON); + state = DEX. DEXReader(filepath, ext ); + else state = DEX.MsgPackReader(filepath, JSON); - if (Format > Format.NULL) - DEX. DEXWriter(filepath, Format); - else DEX.MsgPackWriter(filepath, JSON ); + if (state == 1) + { + if (Format > Format.NULL) + DEX. DEXWriter(filepath, Format); + else DEX.MsgPackWriter(filepath, JSON); + } DEX = null; } } diff --git a/PD_Tool/classes/Tools/DFT.cs b/PD_Tool/classes/Tools/DFT.cs new file mode 100644 index 0000000..4d44278 --- /dev/null +++ b/PD_Tool/classes/Tools/DFT.cs @@ -0,0 +1,33 @@ +using System; +using KKdMainLib; +using KKdMainLib.IO; +using KKdMainLib.F2; + +namespace PD_Tool.Tools +{ + public class DFT + { + public static void Processor() + { + Console.Title = "DOF Converter"; + DOF DOF; + Main.Choose(1, "dft", out string[] FileNames); + if (FileNames.Length < 1) return; + string filepath = ""; + string ext = ""; + + foreach (string file in FileNames) + { + DOF = new DOF(); + ext = Path.GetExtension(file); + filepath = file.Replace(ext, ""); + ext = ext.ToLower(); + + Console.Title = "DOF Converter: " + Path.GetFileNameWithoutExtension(file); + if (ext == ".dft") { DOF.DFTReader(filepath); DOF.TXTWriter(filepath); } + //else if (ext == ".txt") { DOF.TXTReader(filepath); DOF.DFTWriter(filepath); } + DOF = new DOF(); + } + } + } +} diff --git a/PD_Tool/classes/Tools/LIT.cs b/PD_Tool/classes/Tools/LIT.cs new file mode 100644 index 0000000..f9dea83 --- /dev/null +++ b/PD_Tool/classes/Tools/LIT.cs @@ -0,0 +1,33 @@ +using System; +using KKdMainLib; +using KKdMainLib.IO; +using KKdMainLib.F2; + +namespace PD_Tool.Tools +{ + public class LIT + { + public static void Processor() + { + Console.Title = "Light Converter"; + Light LIT; + Main.Choose(1, "lit", out string[] FileNames); + if (FileNames.Length < 1) return; + string filepath = ""; + string ext = ""; + + foreach (string file in FileNames) + { + LIT = new Light(); + ext = Path.GetExtension(file); + filepath = file.Replace(ext, ""); + ext = ext.ToLower(); + + Console.Title = "Light Converter: " + Path.GetFileNameWithoutExtension(file); + if (ext == ".lit") { LIT.LITReader(filepath); LIT.TXTWriter(filepath); } + //else if (ext == ".txt") { LIT.TXTReader(filepath); LIT.LITWriter(filepath); } + LIT = new Light(); + } + } + } +} diff --git a/PD_Tool/classes/Tools/MOT.cs b/PD_Tool/classes/Tools/MOT.cs new file mode 100644 index 0000000..8383c4b --- /dev/null +++ b/PD_Tool/classes/Tools/MOT.cs @@ -0,0 +1,40 @@ +using System; +using KKdMainLib; +using KKdMainLib.IO; + +namespace PD_Tool.Tools +{ + public class MOT + { + public static void Processor(bool JSON) + { + Console.Title = "MOT Converter"; + Mot Mot; + Main.Choose(1, "bin", out string[] FileNames); + if (FileNames.Length < 1) return; + string filepath = ""; + string ext = ""; + + foreach (string file in FileNames) + { + Mot = new Mot(); + ext = Path.GetExtension(file); + filepath = file.Replace(ext, ""); + ext = ext.ToLower(); + + Console.Title = "MOT Converter: " + Path.GetFileNameWithoutExtension(file); + if (ext == ".bin") + { + Mot. MOTReader(filepath); + Mot.MsgPackWriter(filepath, JSON); + } + else if (ext == ".mp" || ext == ".json") + { + Mot.MsgPackReader(filepath, ext == ".json"); + Mot. MOTWriter(filepath); + } + Mot = new Mot(); + } + } + } +}