Compare commits

..
5 Commits
Author SHA1 Message Date
KujiKita 3f883c4c77 Release v0.4.6.4
A3DA, DataBank, DEX, FARC, KKdList, MsgPack, POF, SprDB fix
2019-07-08 21:45:57 +03:00
KujiKita 0863721dc4 Release v0.4.6.3
A3DA and FARC fix
Added converting A3DA in FARC
2019-07-03 17:54:04 +03:00
KujiKita e0d651bd55 Release v0.4.6.2p1
A3DA Key fix
2019-07-03 14:52:16 +03:00
KujiKita 3bbbea9536 Release v0.4.6.2
Some fixes and changes
2019-07-03 01:08:18 +03:00
KujiKita 4de7bd32f7 Release v0.4.6.1
Some fixes and changes
2019-07-01 03:53:20 +03:00
44 changed files with 3219 additions and 3539 deletions
File diff suppressed because it is too large Load Diff
-504
View File
@@ -1,504 +0,0 @@
using System.Collections.Generic;
using KKdMainLib.IO;
using KKdMainLib.Types;
using KKdMainLib.MessagePack;
namespace KKdMainLib.A3DA
{
public static class A3DAExt
{
private const string d = ".";
private const string BO = "bin_offset";
private const string MTBO = "model_transform" + d + BO;
private static string value;
private static string[] dataArray;
private static int SOi;
private static int[] SO;
public static ModelTransform ReadMT(this Dictionary<string, object> Dict, string Temp)
{
ModelTransform MT = new ModelTransform();
Dict.FindValue(out MT.BinOffset, Temp + MTBO);
MT.Rot = Dict.ReadVec3(Temp + "rot" + d);
MT.Scale = Dict.ReadVec3(Temp + "scale" + d);
MT.Trans = Dict.ReadVec3(Temp + "trans" + d);
MT.Visibility = Dict.ReadKey (Temp + "visibility" + d);
return MT;
}
public static RGBAKey ReadRGBAKey(this Dictionary<string, object> Dict, string Temp) =>
new RGBAKey { A = Dict.ReadKey(Temp + "a" + d), B = Dict.ReadKey(Temp + "b" + d),
G = Dict.ReadKey(Temp + "g" + d), R = Dict.ReadKey(Temp + "r" + d) };
public static Vector3<Key> ReadVec3(this Dictionary<string, object> Dict, string Temp) =>
new Vector3<Key> { X = Dict.ReadKey(Temp + "x" + d), Y =
Dict.ReadKey(Temp + "y" + d), Z = Dict.ReadKey(Temp + "z" + d) };
public static KeyUV ReadKeyUV(this Dictionary<string, object> Dict, string Temp) =>
new KeyUV { U = Dict.ReadKey(Temp + "U" + d), V = Dict.ReadKey(Temp + "V" + d) };
public static Key ReadKey(this Dictionary<string, object> Dict, string Temp)
{
Key Key = new Key();
Dict.FindValue(out Key.BinOffset, Temp + BO );
Dict.FindValue(out Key.Type , Temp + "type");
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; }
int i = 0, i0 = 0;
Dict.FindValue(out Key.EPTypePost, Temp + "ep_type_post");
Dict.FindValue(out Key.EPTypePre , Temp + "ep_type_pre" );
Dict.FindValue(out Key.Length , Temp + "key.length" );
Dict.FindValue(out Key.Max , Temp + "max" );
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 KeyFrame<double, double>[(int)Key.Length];
for (i0 = 0; i0 < Key.Length; i0++)
if (Dict.FindValue(out value, Temp + "key" + d + i0 + d + "data"))
{
dataArray = value.Replace("(", "").Replace(")", "").Split(',');
Type = dataArray.Length - 1;
if (Type == 0) Key.Trans[i0] = new KeyFrameT0<double, double>
{ Frame = dataArray[0].ToDouble() };
else if (Type == 1) Key.Trans[i0] = new KeyFrameT1<double, double>
{ Frame = dataArray[0].ToDouble(), Value = dataArray[1].ToDouble() };
else if (Type == 2) Key.Trans[i0] = new KeyFrameT2<double, double>
{ Frame = dataArray[0].ToDouble(), Value = dataArray[1].ToDouble(),
Interpolation = dataArray[2].ToDouble() };
else if (Type == 3) Key.Trans[i0] = new KeyFrameT3<double, double>
{ Frame = dataArray[0].ToDouble(), Value = dataArray[1].ToDouble(),
Interpolation1 = dataArray[2].ToDouble(),
Interpolation2 = dataArray[3].ToDouble() };
Key.Trans[i0] = Key.Trans[i0].Check();
}
}
else if (Key.RawData.KeyType != null)
{
Key.RawData = new Key.RawD();
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(',');
Dict.FindValue(out Key.RawData.ValueListSize, Temp + "raw_data.value_list_size");
value = "";
int DS = (int)Key.RawData.KeyType + 1;
Key.Length = Key.RawData.ValueListSize / DS;
Key.Trans = new KeyFrame<double, double>[(int)Key.Length];
if (Key.RawData.KeyType == 0)
for (i = 0; i < Key.Length; i++)
Key.Trans[i] = new KeyFrameT0<double, double>
{ Frame = Key.RawData.ValueList[i * DS + 0].ToDouble() };
else if (Key.RawData.KeyType == 1)
for (i = 0; i < Key.Length; i++)
Key.Trans[i] = new KeyFrameT1<double, double>
{ Frame = Key.RawData.ValueList[i * DS + 0].ToDouble(),
Value = dataArray[i * DS + 1].ToDouble() };
else if (Key.RawData.KeyType == 2)
for (i = 0; i < Key.Length; i++)
Key.Trans[i] = new KeyFrameT2<double, double>
{ Frame = Key.RawData.ValueList[i * DS + 0].ToDouble(),
Value = dataArray[i * DS + 1].ToDouble(),
Interpolation = dataArray[i * DS + 2].ToDouble() };
else if (Key.RawData.KeyType == 3)
for (i = 0; i < Key.Length; i++)
Key.Trans[i] = new KeyFrameT3<double, double>
{ Frame = Key.RawData.ValueList[i * DS + 0].ToDouble(),
Value = dataArray[i * DS + 1].ToDouble(),
Interpolation1 = dataArray[i * DS + 2].ToDouble(),
Interpolation2 = dataArray[i * DS + 3].ToDouble() };
for (i = 0; i < Key.Length; i++) Key.Trans[i].Check();
Key.RawData.ValueList = null;
}
return Key;
}
public static void Write(this Stream IO, ModelTransform MT,
string Temp, bool A3DC, bool IsX = false, byte Flags = 0b11111)
{
if (A3DC && !MT.Writed && (Flags & 0b10000) == 0b10000)
{ IO.Write(Temp + MTBO + "=", MT.BinOffset); MT.Writed = true; }
if (A3DC) return;
if ((Flags & 0b01000) == 0b01000) IO.Write(MT.Rot , Temp + "rot" + d, A3DC);
if ((Flags & 0b00100) == 0b00100) IO.Write(MT.Scale , Temp + "scale" + d, A3DC);
if ((Flags & 0b00010) == 0b00010) IO.Write(MT.Trans , Temp + "trans" + d, A3DC);
if ((Flags & 0b00001) == 0b00001) IO.Write(MT.Visibility, Temp + "visibility" + d, A3DC);
}
public static void Write(this Stream IO, RGBAKey RGBA, string Temp, string Data, bool A3DC = false)
{
if (RGBA.R == null && RGBA.B == null && RGBA.G == null && RGBA.A == null) return;
IO.Write(Temp + Data + "=", "true");
IO.Write(RGBA.A, Temp + Data + d + "a" + d, A3DC);
IO.Write(RGBA.B, Temp + Data + d + "b" + d, A3DC);
IO.Write(RGBA.G, Temp + Data + d + "g" + d, A3DC);
IO.Write(RGBA.R, Temp + Data + d + "r" + d, A3DC);
}
public static void Write(this Stream IO, Vector3<Key> Key, string Temp, bool A3DC = false)
{ IO.Write(Key.X, Temp + "x" + d, A3DC); IO.Write(Key.Y,
Temp + "y" + d, A3DC); IO.Write(Key.Z, Temp + "z" + d, A3DC); }
public static void Write(this Stream IO, KeyUV UV, string Temp, string Data, bool A3DC = false)
{ IO.Write(UV.U, Temp, Data + "U", A3DC); IO.Write(UV.V, Temp, Data + "V", A3DC); }
public static void Write(this Stream IO, Key Key, string Temp, string Data, bool A3DC = false)
{ if (Key != null) { IO.Write(Temp + Data + "=", "true"); IO.Write(Key, Temp + Data + d, A3DC); } }
public static void Write(this Stream IO, Key Key, string Temp, bool A3DC = false)
{
if (Key == null) return;
if (A3DC) { IO.Write(Temp + BO + "=", Key.BinOffset); return; }
int i = 0;
if (Key.Trans != null)
if (Key.Trans.Length == 0)
{
IO.Write(Temp + "type=", 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 == null && Key.Trans != null)
{
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<double, double>)
IO.Write(Temp + "key" + d + SOi + d + "type=", 0);
else if (Key.Trans[SOi] is KeyFrameT1<double, double>)
IO.Write(Temp + "key" + d + SOi + d + "type=", 1);
else if (Key.Trans[SOi] is KeyFrameT2<double, double>)
IO.Write(Temp + "key" + d + SOi + d + "type=", 2);
else if (Key.Trans[SOi] is KeyFrameT3<double, double>)
IO.Write(Temp + "key" + d + SOi + d + "type=", 3);
}
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;
if (Key.Max != null) IO.Write(Temp + "max=", Key.Max);
for (i = 0; i < Key.Trans.Length; i++)
{
if (Key.Trans[SOi] is KeyFrameT0<double, double> &&
Key.RawData.KeyType < 0) Key.RawData.KeyType = 0;
else if (Key.Trans[SOi] is KeyFrameT1<double, double> &&
Key.RawData.KeyType < 1) Key.RawData.KeyType = 1;
else if (Key.Trans[SOi] is KeyFrameT2<double, double> &&
Key.RawData.KeyType < 2) Key.RawData.KeyType = 2;
else if (Key.Trans[SOi] is KeyFrameT3<double, double> &&
Key.RawData.KeyType < 3) break;
}
Key.RawData.ValueListSize = Key.Trans.Length * (Key.RawData.KeyType + 1);
IO.Write(Temp + "raw_data.value_list=");
for (i = 0; i < Key.Trans.Length; i++) IO.Write(Key.Trans[i].ToString(false));
IO.Position = IO.Position - 1;
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 == null && Key.Trans == null && Key.Value != null)
if (Key.Value != 0) IO.Write(Temp + "value=", Key.Value);
}
public static void ReadMT(this Stream IO, ref ModelTransform MT, int C_F16)
{
if (MT.BinOffset == null) return;
IO.Position = (int)MT.BinOffset;
IO.ReadOffset(out MT.Scale);
IO.ReadOffset(out MT.Rot );
IO.ReadOffset(out MT.Trans);
MT.Visibility = new Key { BinOffset = IO.ReadInt32() };
IO.ReadVec3(ref MT.Scale , C_F16);
IO.ReadVec3(ref MT.Rot , C_F16, true);
IO.ReadVec3(ref MT.Trans , C_F16);
IO.ReadKey (ref MT.Visibility, C_F16);
}
public static void ReadRGBAKey(this Stream IO, ref RGBAKey RGBA, int C_F16)
{ IO.ReadKey(ref RGBA.R, C_F16); IO.ReadKey(ref RGBA.G, C_F16);
IO.ReadKey(ref RGBA.B, C_F16); IO.ReadKey(ref RGBA.A, C_F16); }
public static void ReadVec3(this Stream IO, ref Vector3<Key> Key, int C_F16, bool F16 = false)
{ IO.ReadKey(ref Key.X, C_F16, F16); IO.ReadKey(ref Key.Y,
C_F16, F16); IO.ReadKey(ref Key.Z, C_F16, F16); }
public static void ReadKeyUV(this Stream IO, ref KeyUV UV, int C_F16)
{ IO.ReadKey(ref UV.U, C_F16); IO.ReadKey(ref UV.V, C_F16); }
public static void ReadKey(this Stream IO, ref Key Key, int C_F16, bool F16 = false)
{
if (Key == null) return;
if (Key.BinOffset == null || Key.BinOffset < 0) return;
IO.Position = (int)Key.BinOffset;
Key.Type = IO.ReadInt32();
Key.Value = IO.ReadSingle();
if (Key.Type == 0x0000 || Key.Type == 0x0001) return;
Key.Max = IO.ReadSingle();
Key.Length = IO.ReadInt32 ();
Key.Trans = new KeyFrame<double, double>[(int)Key.Length];
KeyFrameT3<double, double> Temp;
for (int i = 0; i < Key.Length; i++)
{
Temp = new KeyFrameT3<double, double>();
if (F16 && C_F16 > 0)
{ Temp.Frame = IO.ReadUInt16(); Temp.Value = (double)IO.ReadHalf (); }
else
{ Temp.Frame = IO.ReadSingle(); Temp.Value = IO.ReadSingle(); }
if (F16 && C_F16 == 2)
{ Temp.Interpolation1 = (double)IO.ReadHalf ();
Temp.Interpolation2 = (double)IO.ReadHalf (); }
else
{ Temp.Interpolation1 = IO.ReadSingle();
Temp.Interpolation2 = IO.ReadSingle(); }
Key.Trans[i] = Temp.Check();
}
}
public static void ReadOffset(this Stream IO, out Vector3<Key> Key)
{ Key = new Vector3<Key> { X = new Key { BinOffset = IO.ReadInt32() },
Y = new Key { BinOffset = IO.ReadInt32() },
Z = new Key { BinOffset = IO.ReadInt32() }, }; }
public static void WriteOffset(this Stream IO, ref ModelTransform MT, bool ReturnToOffset)
{
if (ReturnToOffset)
{
IO.Position = (int)MT.BinOffset;
IO.WriteOffset(MT.Scale);
IO.WriteOffset(MT.Rot );
IO.WriteOffset(MT.Trans);
IO.Write(MT.Visibility.BinOffset);
}
else
{
MT.BinOffset = IO.Position;
IO.Position += 0x30;
IO.Length += 0x30;
}
}
public static void WriteOffset(this Stream IO, Vector3<Key> Key)
{
IO.Write(Key.X.BinOffset);
IO.Write(Key.Y.BinOffset);
IO.Write(Key.Z.BinOffset);
}
public static ModelTransform ReadMT(this MsgPack k, string name)
{ if (k.Element(name, out MsgPack Name)) return Name.ReadMT(); return new ModelTransform(); }
public static ModelTransform ReadMT(this MsgPack k) =>
new ModelTransform { Rot = k.ReadVec3("Rot" ), Scale = k.ReadVec3("Scale" ),
Trans = k.ReadVec3("Trans"), Visibility = k.ReadKey ("Visibility") };
public static RGBAKey ReadRGBAKey(this MsgPack k, string name)
{ if (k.Element(name, out MsgPack Name)) return Name.ReadRGBAKey(); return new RGBAKey(); }
public static RGBAKey ReadRGBAKey(this MsgPack k) =>
new RGBAKey { R = k.ReadKey("R"), G = k.ReadKey("G"), B = k.ReadKey("B"), A = k.ReadKey("A") };
public static Vector3<Key> ReadVec3(this MsgPack k, string name)
{ if (k.Element(name, out MsgPack Name)) return Name.ReadVec3(); return new Vector3<Key>(); }
public static Vector3<Key> ReadVec3(this MsgPack k) =>
new Vector3<Key> { X = k.ReadKey("X"), Y = k.ReadKey("Y"), Z = k.ReadKey("Z") };
public static KeyUV ReadKeyUV(this MsgPack k, string name)
{ if (k.Element(name, out MsgPack Name)) return Name.ReadKeyUV(); return new KeyUV(); }
public static KeyUV ReadKeyUV(this MsgPack k) =>
new KeyUV { U = k.ReadKey("U"), V = k.ReadKey("V") };
public static Key ReadKey(this MsgPack k, string name)
{ if (k.Element(name, out MsgPack Name)) return Name.ReadKey(); return null; }
public static Key ReadKey(this MsgPack k)
{
if (k.Object == null) return null;
Key Key = new Key { EPTypePost = k.ReadNDouble("Post"),
EPTypePre = k.ReadNDouble("Pre"), Max = k.ReadNDouble("M"),
Type = k.ReadNInt32("T"), Value = k.ReadNDouble("V") };
if (k.ReadBoolean("RD")) Key.RawData = new Key.RawD();
if (Key.Type == 0) Key.Value = 0.0;
if (Key.Type < 2) return Key;
if (!k.Element<MsgPack>("Trans", out MsgPack Trans)) return Key;
Key.Length = Trans.Array.Length;
Key.Trans = new KeyFrame<double, double>[Key.Length.Value];
for (int i = 0; i < Key.Length; i++)
if (Trans[i] is MsgPack _Trans)
{
if (_Trans.Array == null) continue;
else if (_Trans.Array.Length == 0) continue;
else if (_Trans.Array.Length == 1)
{
if (_Trans[0] is MsgPack Frame)
Key.Trans[i] = new KeyFrameT0<double, double> { Frame = Frame.ReadDouble() };
}
else if (_Trans.Array.Length == 2)
{
KeyFrameT1<double, double> KeyFrameT1 = new KeyFrameT1<double, double>();
if (_Trans[0] is MsgPack Frame) KeyFrameT1.Frame = Frame.ReadDouble();
if (_Trans[1] is MsgPack Value) KeyFrameT1.Value = Value.ReadDouble();
Key.Trans[i] = KeyFrameT1;
}
else if (_Trans.Array.Length == 3)
{
KeyFrameT2<double, double> KeyFrameT2 = new KeyFrameT2<double, double>();
if (_Trans[0] is MsgPack Frame )
KeyFrameT2.Frame = Frame .ReadDouble();
if (_Trans[1] is MsgPack Value )
KeyFrameT2.Value = Value .ReadDouble();
if (_Trans[2] is MsgPack Interpolation)
KeyFrameT2.Interpolation = Interpolation.ReadDouble();
Key.Trans[i] = KeyFrameT2;
}
else if (_Trans.Array.Length == 4)
{
KeyFrameT3<double, double> KeyFrameT3 = new KeyFrameT3<double, double>();
if (_Trans[0] is MsgPack Frame )
KeyFrameT3.Frame = Frame .ReadDouble();
if (_Trans[1] is MsgPack Value )
KeyFrameT3.Value = Value .ReadDouble();
if (_Trans[2] is MsgPack Interpolation1)
KeyFrameT3.Interpolation1 = Interpolation1.ReadDouble();
if (_Trans[3] is MsgPack Interpolation2)
KeyFrameT3.Interpolation2 = Interpolation2.ReadDouble();
Key.Trans[i] = KeyFrameT3;
}
Key.Trans[i] = Key.Trans[i].Check();
}
return Key;
}
public static MsgPack Add(this MsgPack MsgPack, string name, ModelTransform MT) =>
name == null ?
MsgPack.Add("Rot" , MT.Rot )
.Add("Scale" , MT.Scale )
.Add("Trans" , MT.Trans )
.Add("Visibility", MT.Visibility):
MsgPack.Add(new MsgPack(name).Add("Rot" , MT.Rot )
.Add("Scale" , MT.Scale )
.Add("Trans" , MT.Trans )
.Add("Visibility", MT.Visibility));
public static MsgPack Add(this MsgPack MsgPack, string name, RGBAKey RGBA) =>
(RGBA.R == null && RGBA.G == null && RGBA.B == null && RGBA.A == null) ? MsgPack :
MsgPack.Add(new MsgPack(name).Add("R", RGBA.R).Add("G", RGBA.G)
.Add("B", RGBA.B).Add("A", RGBA.A));
public static MsgPack Add(this MsgPack MsgPack, string name, Vector3<Key> Key) =>
MsgPack.Add(new MsgPack(name).Add("X", Key.X).Add("Y", Key.Y).Add("Z", Key.Z));
public static MsgPack Add(this MsgPack MsgPack, string name, KeyUV UV) =>
(UV.U == null && UV.V == null) ? MsgPack :
MsgPack.Add(new MsgPack(name).Add("U", UV.U).Add("V", UV.V));
public static MsgPack Add(this MsgPack MsgPack, string name, Key Key)
{
if (Key == null) return MsgPack;
if (Key.Type == null) return MsgPack;
MsgPack Keys = new MsgPack(name).Add("T", Key.Type);
if (Key.Trans != null)
{
Keys.Add("Post", Key.EPTypePost).Add("Pre", Key.EPTypePre).Add("M", Key.Max);
if (Key.RawData != null) Keys.Add("RD", true);
MsgPack Trans = new MsgPack(Key.Trans.Length, "Trans");
MsgPack K;
for (int i = 0; i < Key.Trans.Length; i++)
if (Key.Trans[i] is KeyFrameT0<double, double> KeyFrameT0)
{
K = new MsgPack(1);
K[0] = KeyFrameT0.Frame;
Trans[i] = K;
}
else if (Key.Trans[i] is KeyFrameT1<double, double> KeyFrameT1)
{
K = new MsgPack(2);
K[0] = KeyFrameT1.Frame;
K[1] = KeyFrameT1.Value;
Trans[i] = K;
}
else if (Key.Trans[i] is KeyFrameT2<double, double> KeyFrameT2)
{
K = new MsgPack(3);
K[0] = KeyFrameT2.Frame;
K[1] = KeyFrameT2.Value;
K[2] = KeyFrameT2.Interpolation;
Trans[i] = K;
}
else if (Key.Trans[i] is KeyFrameT3<double, double> KeyFrameT3)
{
K = new MsgPack(4);
K[0] = KeyFrameT3.Frame;
K[1] = KeyFrameT3.Value;
K[2] = KeyFrameT3.Interpolation1;
K[3] = KeyFrameT3.Interpolation2;
Trans[i] = K;
}
Keys.Add(Trans);
}
else if (Key.Value != 0) Keys.Add("V", Key.Value);
return MsgPack.Add(Keys);
}
public static void Write(this Stream IO, string Data, ref bool? val)
{ if (val != null) IO.Write(Data, ( bool)val ); }
public static void Write(this Stream IO, string Data, long? val)
{ if (val != null) IO.Write(Data, ( long)val ); }
public static void Write(this Stream IO, string Data, ulong? val)
{ if (val != null) IO.Write(Data, ( ulong)val ); }
public static void Write(this Stream IO, string Data, double? val)
{ if (val != null) IO.Write(Data, (double)val ); }
public static void Write(this Stream IO, string Data, double? val, byte r)
{ if (val != null) IO.Write(Data, (double)val, r); }
public static void Write(this Stream IO, string Data, ref bool val) =>
IO.Write(Data, Main.ToString(val));
public static void Write(this Stream IO, string Data, long val) =>
IO.Write(Data, val.ToString( ));
public static void Write(this Stream IO, string Data, ulong val) =>
IO.Write(Data, val.ToString( ));
public static void Write(this Stream IO, string Data, double val) =>
IO.Write(Data, val.ToString( ));
public static void Write(this Stream IO, string Data, double val, byte r) =>
IO.Write(Data, val.ToString(r ));
public static void Write(this Stream IO, string Data, string val)
{ if (val != null) IO.Write((Data + val + "\n").ToUTF8()); }
}
}
+1366
View File
File diff suppressed because it is too large Load Diff
-969
View File
@@ -1,969 +0,0 @@
//Original: AetSet.bt Version: 2.0 by samyuu
using System.Collections.Generic;
using KKdMainLib.IO;
using KKdMainLib.Types;
using KKdMainLib.MessagePack;
namespace KKdMainLib.Aet
{
public class Aet
{
public Aet()
{ AET = new AetHeader(); i = i0 = 0; IO = null; }
public AetHeader AET;
private int i, i0;
private Stream IO;
private const string x00 = "\0";
public void AETReader(string file)
{
AET = new AetHeader();
IO = File.OpenReader(file + ".bin", true);
i = 0;
int Pos = -1;
while (true) { Pos = IO.ReadInt32(); if (Pos != 0 && Pos < IO.Length) i++; else break; }
IO.Position = 0;
AET.Data = new Pointer<AetData>[i];
for (int i = 0; i < AET.Data.Length; i++) AET.Data[i] = IO.ReadPointer<AetData>();
for (int i = 0; i < AET.Data.Length; i++) AETReader(ref AET.Data[i]);
IO.Close();
}
public void AETWriter(string file)
{
if (AET.Data == null) return;
if (AET.Data.Length == 0) return;
IO = File.OpenWriter(file + ".bin", true);
for (int i = 0; i < AET.Data.Length; i++)
{
IO.Position = IO.Length + 0x20;
AETWriter(ref AET.Data[i]);
}
IO.Position = 0;
for (int i = 0; i < AET.Data.Length; i++) IO.Write(AET.Data[i].Offset);
IO.Close();
}
public void AETReader(ref Pointer<AetData> AET)
{
IO.Position = AET.Offset;
ref AetData Aet = ref AET.Value;
Aet.Name = IO.ReadPointerString();
Aet.Unk = IO.ReadSingle();
Aet.Duration = IO.ReadSingle();
Aet.FrameRate = IO.ReadSingle();
IO.ReadInt32();
Aet.Width = IO.ReadInt32();
Aet.Height = IO.ReadInt32();
Aet.DontChange = IO.ReadInt32();
if (Aet.DontChange != 0) { IO.Close(); return; }
Aet.LayObjPointers = IO.ReadCountPointer<CountPointer<int>>();
CountPointer<SpriteEntry> Sprites = IO.ReadCountPointer<SpriteEntry>();
Aet.Unknown = IO.ReadCountPointer<int>();
Aet.LayObjDict = new Dictionary<int, int>();
Aet.ObjectsDict = new Dictionary<int, AetObject>();
Aet.SprEntsDict = new Dictionary<int, SpriteEntry>();
Aet.SpritesDict = new Dictionary<int, Sprite>();
IO.Position = Aet.LayObjPointers.Offset;
for (i = 0; i < Aet.LayObjPointers.Count; i++)
{
Aet.LayObjDict.Add(i, IO.Position);
Aet.LayObjPointers.Entries[i] = IO.ReadCountPointer<int>();
}
for (i = 0; i < Aet.LayObjPointers.Count; i++)
{
IO.Position = Aet.LayObjPointers.Entries[i].Offset;
for (i0 = 0; i0 < Aet.LayObjPointers.Entries[i].Count; i0++)
Aet.LayObjPointers.Entries[i].Entries[i0] = IO.ReadAetObject(ref Aet.ObjectsDict);
}
IO.Position = Sprites.Offset;
for (i = 0; i < Sprites.Count; i++)
{
SpriteEntry SprEnt = new SpriteEntry();
int Offset = IO.Position;
SprEnt.Unknown = IO.ReadInt32();
SprEnt.Width = IO.ReadInt16();
SprEnt.Height = IO.ReadInt16();
SprEnt.Frames = IO.ReadSingle();
SprEnt.Sprites = IO.ReadCountPointer<int>();
long Position = IO.LongPosition;
IO.Position = SprEnt.Sprites.Offset;
for (i0 = 0; i0 < SprEnt.Sprites.Count; i0++)
{
Sprite Spr = new Sprite();
int OffsetLocal = IO.Position;
Spr.Name = IO.ReadPointerString();
Spr.ID = IO.ReadInt32();
Aet.SpritesDict.Add(OffsetLocal, Spr);
SprEnt.Sprites.Entries[i0] = OffsetLocal;
}
IO.LongPosition = Position;
Aet.SprEntsDict.Add(Offset, SprEnt);
}
}
public void AETWriter(ref Pointer<AetData> AET)
{
ref AetData Aet = ref AET.Value;
if (Aet.SpritesArr != null)
{
List<int> WrittenSprites = new List<int>();
for (i = 0; i < Aet.SprEntsArr.Length; i++)
{
ref SpriteEntry SprEnt = ref Aet.SprEntsArr[i].Value;
if (SprEnt.Sprites.Count < 1) continue;
SprEnt.Sprites.Offset = IO.Position;
for (i0 = 0; i0 < SprEnt.Sprites.Count; i0++)
{
ref int I = ref SprEnt.Sprites.Entries[i0];
Aet.SpritesArr[Aet.SpritesIndDict[I]].Offset = IO.Position;
IO.Write(0);
IO.Write(Aet.SpritesArr[Aet.SpritesIndDict[I]].Value.ID);
WrittenSprites.Add(Aet.SpritesIndDict[I]);
}
}
for (i = 0; i < Aet.SpritesArr.Length; i++)
if (!WrittenSprites.Contains(i))
{
Aet.SpritesArr[i].Offset = IO.Position;
IO.Write(0);
IO.Write(Aet.SpritesArr[i].Value.ID);
WrittenSprites.Add(i);
}
}
IO.Align(0x20);
for (i = 0; i < Aet.SprEntsArr.Length; i++)
{
Aet.SprEntsArr[i].Offset = IO.Position;
ref SpriteEntry SprEnt = ref Aet.SprEntsArr[i].Value;
IO.Write(SprEnt.Unknown);
IO.Write(SprEnt.Width);
IO.Write(SprEnt.Height);
IO.Write(SprEnt.Frames);
IO.Write(SprEnt.Sprites.Count);
IO.Write(SprEnt.Sprites.Offset);
}
IO.Align(0x20);
Aet.LayObjPointers.Offset = IO.Position;
for (i = 0; i < Aet.LayObjPointers.Count; i++)
{
Aet.LayObjPointers.Entries[i].Offset = IO.Position;
IO.Write(0L);
}
List<int> NullValPointers = new List<int>();
for (i = 0; i < Aet.LayObjPointers.Count; i++)
{
for (i0 = 0; i0 < Aet.LayObjPointers.Entries[i].Count; i0++)
{
ref int I = ref Aet.LayObjPointers.Entries[i].Entries[i0];
IO.Write(ref Aet.ObjectsArr[I].Value, ref NullValPointers);
}
IO.Align(0x20);
for (i0 = 0; i0 < Aet.LayObjPointers.Entries[i].Count; i0++)
{
ref int I = ref Aet.LayObjPointers.Entries[i].Entries[i0];
IO.Write(ref Aet.ObjectsArr[I].Value, ref Aet.ObjectsArr[I].Offset);
}
}
IO.Align(0x20);
AET.Offset = IO.Position;
IO.Write(0L);
IO.Write(Aet.Duration);
IO.Write(Aet.FrameRate);
IO.Write(0);
IO.Write(Aet.Width);
IO.Write(Aet.Height);
IO.Write(0);
IO.Write(0L);
IO.Write(0L);
IO.Write(0L);
IO.Write(0L);
IO.Align(0x10);
{
Dictionary<string, int> UsedValues = new Dictionary<string, int>();
if (Aet.SpritesArr != null)
for (i = 0; i < Aet.SpritesArr.Length; i++)
IO.WritePointerString(ref UsedValues, ref Aet.SpritesArr[i].Value.Name);
//IO.Align(0x4);
for (i = 0; i < Aet.ObjectsArr.Length; i++)
{
ref AetObject Obj = ref Aet.ObjectsArr[i].Value;
if (Obj.Type == ObjType.Pic)
for (i0 = 0; i0 < Obj.Pic.Value.Marker.Count; i0++)
IO.WritePointerString(ref UsedValues, ref Obj.Pic.Value.Marker.Entries[i0].Name);
else if (Obj.Type == ObjType.Eff)
for (i0 = 0; i0 < Obj.Eff.Value.Marker.Count; i0++)
IO.WritePointerString(ref UsedValues, ref Obj.Eff.Value.Marker.Entries[i0].Name);
IO.WritePointerString(ref UsedValues, ref Obj.Name);
}
//IO.Align(0x4);
Aet.Name.Offset = IO.Position;
IO.Write(Aet.Name.Value + x00);
}
if (Aet.Unknown.Count > 0)
{
IO.Align(0x10);
Aet.Unknown.Offset = IO.Position;
for (i = 0; i < Aet.Unknown.Count * 10; i++)
IO.Write(0L);
}
IO.Align(0x10);
int ReturnPosition = IO.Position;
for (i = 0; i < NullValPointers.Count; i++)
{
IO.Position = NullValPointers[i];
IO.Write(ReturnPosition + i * 4);
}
IO.Position = ReturnPosition;
for (i = 0; i < NullValPointers.Count; i++) IO.Write(0);
IO.Align(1, true);
for (i = 0; i < Aet.ObjectsArr.Length; i++)
{
ref AetObject Obj = ref Aet.ObjectsArr[i].Value;
if (Obj.Type == ObjType.Pic)
{
IO.Position = Obj.Pic.Offset;
IO.Write(Aet.SprEntsArr[Aet.SprEntsIndDict[Obj.Pic.Value.SpriteEntryID]].Offset);
IO.Write(Obj.Pic.Value.ParentObjectID > -1 ?
Aet.ObjectsArr[Obj.Pic.Value.ParentObjectID].Offset : 0);
IO.Write(Obj.Eff.Value.Marker.Count );
IO.Write(Obj.Eff.Value.Marker.Offset);
ref CountPointer<Marker> Marker = ref Obj.Pic.Value.Marker;
IO.Position = Marker.Offset;
for (i0 = 0; i0 < Marker.Count; i0++)
{
IO.Write(Marker.Entries[i0].Frame);
IO.Write(Marker.Entries[i0]. Name.Offset);
}
}
else if (Obj.Type == ObjType.Eff)
{
IO.Position = Obj.Eff.Offset;
IO.Write(Aet.LayObjPointers.Entries[Obj.Eff.Value.LayerID].Offset);
IO.Write(Obj.Eff.Value.ParentObjectID > -1 ?
Aet.ObjectsArr[Obj.Eff.Value.ParentObjectID].Offset : 0);
IO.Write(Obj.Eff.Value.Marker.Count );
IO.Write(Obj.Eff.Value.Marker.Offset);
ref CountPointer<Marker> Marker = ref Obj.Eff.Value.Marker;
IO.Position = Marker.Offset;
for (i0 = 0; i0 < Marker.Count; i0++)
{
IO.Write(Marker.Entries[i0].Frame);
IO.Write(Marker.Entries[i0]. Name.Offset);
}
}
IO.Position = Aet.ObjectsArr[i].Offset;
IO.Write(Obj.Name.Offset);
}
if (Aet.SpritesArr != null)
for (i = 0; i < Aet.SpritesArr.Length; i++)
{
IO.Position = Aet.SpritesArr[i].Offset;
IO.Write(Aet.SpritesArr[i].Value.Name.Offset);
}
for (i = 0; i < Aet.LayObjPointers.Count; i++)
{
IO.Position = Aet.LayObjPointers.Entries[i].Offset;
IO.Write(Aet.LayObjPointers.Entries[i].Count);
IO.Write(Aet.LayObjPointers.Entries[i].Count > 0 ?
Aet.ObjectsArr[Aet.ObjectsIndDict[Aet.LayObjPointers.Entries[i].Entries[0]]].Offset : 0);
}
IO.Position = AET.Offset;
IO.Write(Aet.Name.Offset);
IO.Position = AET.Offset + 0x20;
IO.Write(Aet.LayObjPointers.Count );
IO.Write(Aet.LayObjPointers.Offset);
IO.Write(Aet.SprEntsArr.Length);
IO.Write(Aet.SprEntsArr[0].Offset);
if (Aet.Unknown.Count > 0)
{ IO.Write(Aet.Unknown.Count); IO.Write(Aet.Unknown.Offset); }
else IO.Write(0L);
}
public void MsgPackReader(string file, bool JSON)
{
AET = new AetHeader();
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
if (!MsgPack.Element<MsgPack>("Aet", out MsgPack Aet)) { MsgPack = MsgPack.New; return; }
if (Aet.Array != null)
if (Aet.Array.Length > 0)
{
AET.Data = new Pointer<AetData>[Aet.Array.Length];
for (int i = 0; i < AET.Data.Length; i++)
if (Aet.Array[i] is MsgPack SubAet ) MsgPackReader(SubAet, ref AET.Data[i] );
}
MsgPack = MsgPack.New;
}
public void MsgPackWriter(string file, bool JSON)
{
if (this.AET.Data == null) return;
if (this.AET.Data.Length == 0) return;
MsgPack AET = new MsgPack(this.AET.Data.Length, "Aet");
for (int i = 0; i < this.AET.Data.Length; i++) AET[i] = MsgPackWriter(ref this.AET.Data[i]);
AET.WriteAfterAll(true, file, JSON);
}
public void MsgPackReader(MsgPack AET, ref Pointer<AetData> AetData)
{
MsgPack Temp = MsgPack.New;
AetData.Offset = -1;
ref AetData Aet = ref AetData.Value;
Aet.Name.Value = AET.ReadString("Name" );
Aet.Unk = AET.ReadSingle("Unk" );
Aet.Duration = AET.ReadSingle("Duration" );
Aet.FrameRate = AET.ReadSingle("FrameRate");
Aet.Width = AET.ReadInt32("Width" );
Aet.Height = AET.ReadInt32("Height");
if (AET.Element<MsgPack>("Layers", out MsgPack Layers))
{
Aet.LayObjPointers.Count = Layers.Array.Length;
for (i = 0; i < Aet.LayObjPointers.Count; i++)
if (Layers[i] is MsgPack ObjectID)
{
Aet.LayObjPointers.Entries[i].Count =
ObjectID.Array == null ? 0 : ObjectID.Array.Length;
for (i0 = 0; i0 < Aet.LayObjPointers.Entries[i].Count; i0++)
if (ObjectID.Array[i0] is MsgPack msg)
Aet.LayObjPointers.Entries[i].Entries[i0] = msg.ReadInt32();
}
}
else return;
Aet.ObjectsIndDict = new Dictionary<int, int>();
Aet.SprEntsIndDict = new Dictionary<int, int>();
Aet.SpritesIndDict = new Dictionary<int, int>();
int? ID = null;
if (AET.Element("SpriteEntry", out Temp))
{
Aet.SprEntsArr = new Pointer<SpriteEntry>[1];
ID = Aet.SprEntsArr[0].Value.ReadMP(Temp);
if (ID != null) Aet.SprEntsIndDict.Add(ID.Value, 0);
}
else if (AET.Element<MsgPack>("SpriteEntries", out Temp))
{
Aet.SprEntsArr = new Pointer<SpriteEntry>[Temp.Array.Length];
for (i = 0; i < Aet.SprEntsArr.Length; i++)
if (Temp[i] is MsgPack SpriteEntry)
{
ID = Aet.SprEntsArr[i].Value.ReadMP(SpriteEntry);
if (ID != null) Aet.SprEntsIndDict.Add(ID.Value, i);
}
}
else return;
if (AET.Element("Object", out Temp))
{
Aet.ObjectsArr = new Pointer<AetObject>[1];
ID = Aet.ObjectsArr[0].Value.ReadMP(Temp, 0, ref Aet);
if (ID != null) Aet.ObjectsIndDict.Add(ID.Value, 0);
}
else if (AET.Element<MsgPack>("Objects", out Temp))
{
Aet.ObjectsArr = new Pointer<AetObject>[Temp.Array.Length];
for (i = 0; i < Aet.ObjectsArr.Length; i++)
if (Temp[i] is MsgPack Object)
{
ID = Aet.ObjectsArr[i].Value.ReadMP(Object, i, ref Aet);
if (ID != null) Aet.ObjectsIndDict.Add(ID.Value, i);
}
}
else return;
if (AET.Element("Sprite", out Temp))
{
Aet.SpritesArr = new Pointer<Sprite>[1];
ID = Aet.SpritesArr[0].Value.ReadMP(Temp);
if (ID != null) Aet.SpritesIndDict.Add(ID.Value, 0);
}
else if (AET.Element<MsgPack>("Sprites", out Temp))
{
Aet.SpritesArr = new Pointer<Sprite>[Temp.Array.Length];
for (i = 0; i < Aet.SpritesArr.Length; i++)
if (Temp[i] is MsgPack Sprite)
{
ID = Aet.SpritesArr[i].Value.ReadMP(Sprite);
if (ID != null) Aet.SpritesIndDict.Add(ID.Value, i);
}
}
if (AET.Element("Unknown", out Temp))
Aet.Unknown.Count = Temp.ReadInt32();
AetData.Offset = 0;
}
public MsgPack MsgPackWriter(ref Pointer<AetData> AetData)
{
if (AetData.Offset <= 0) return MsgPack.New;
ref AetData Aet = ref AetData.Value;
Aet.ObjectsIndDict = Aet.ObjectsDict.GetIndDict();
Aet.SpritesIndDict = Aet.SpritesDict.GetIndDict();
Aet.SprEntsIndDict = Aet.SprEntsDict.GetIndDict();
Aet.ObjectsArr = Aet.ObjectsDict.ToPointerArray();
Aet.SpritesArr = Aet.SpritesDict.ToPointerArray();
Aet.SprEntsArr = Aet.SprEntsDict.ToPointerArray();
Aet.ObjectsDict = null;
Aet.SpritesDict = null;
Aet.SprEntsDict = null;
MsgPack AET = MsgPack.New.Add("Name", Aet.Name.Value).Add("Duration",
Aet.Duration).Add("FrameRate", Aet.FrameRate).Add("Width",
Aet.Width).Add("Height", Aet.Height).Add("Unk", Aet.Unk);
if (Aet.LayObjPointers.Count > 0)
{
MsgPack Layers = new MsgPack(Aet.LayObjPointers.Count, "Layers");
for (i = 0; i < Aet.LayObjPointers.Count; i++)
if (Aet.LayObjPointers.Entries[i].Count > 0)
{
MsgPack Objects = new MsgPack(Aet.LayObjPointers.Entries[i].Count);
for (i0 = 0; i0 < Aet.LayObjPointers.Entries[i].Count; i0++)
Objects[i0] = Aet.ObjectsIndDict[Aet.LayObjPointers.Entries[i].Entries[i0]];
Layers[i] = Objects;
}
AET.Add(Layers);
}
if (Aet.SprEntsArr.Length == 1)
AET.Add(Aet.SprEntsArr[0].Value.WriteMP(0, ref Aet.SpritesIndDict, "SpriteEntry"));
else if (Aet.SprEntsArr.Length > 0)
{
MsgPack SpriteEntries = new MsgPack(Aet.SprEntsArr.Length, "SpriteEntries");
for (i = 0; i < Aet.SprEntsArr.Length; i++)
SpriteEntries[i] = Aet.SprEntsArr[i].Value.WriteMP(i, ref Aet.SpritesIndDict);
AET.Add(SpriteEntries);
}
if (Aet.ObjectsArr.Length == 1)
AET.Add(Aet.ObjectsArr[0].Value.WriteMP(0, ref Aet, "Object"));
else if (Aet.ObjectsArr.Length > 1)
{
MsgPack Objects = new MsgPack(Aet.ObjectsArr.Length, "Objects");
for (i = 0; i < Aet.ObjectsArr.Length; i++)
Objects[i] = Aet.ObjectsArr[i].Value.WriteMP(i, ref Aet);
AET.Add(Objects);
}
if (Aet.SpritesArr.Length == 1)
AET.Add(Aet.SpritesArr[0].Value.WriteMP(0, "Sprite"));
else if (Aet.SpritesArr.Length > 1)
{
MsgPack Sprites = new MsgPack(Aet.SpritesArr.Length, "Sprites");
for (i = 0; i < Aet.SpritesArr.Length; i++)
Sprites[i] = Aet.SpritesArr[i].Value.WriteMP(i);
AET.Add(Sprites);
}
if (Aet.Unknown.Count > 0)
AET.Add("Unknown", Aet.Unknown.Count);
return AET;
}
}
public struct AetHeader
{
public Pointer<AetData>[] Data;
public POF POF;
}
public struct AetData
{
public Pointer<string> Name;
public float Unk;
public float Duration;
public float FrameRate;
public int Width;
public int Height;
public int DontChange;
public CountPointer<CountPointer<int>> LayObjPointers;
public CountPointer<int> Unknown;
public Dictionary<int, int> LayObjDict;
public Dictionary<int, int> ObjectsIndDict;
public Dictionary<int, int> SpritesIndDict;
public Dictionary<int, int> SprEntsIndDict;
public Pointer< AetObject>[] ObjectsArr;
public Pointer<SpriteEntry>[] SprEntsArr;
public Pointer< Sprite>[] SpritesArr;
public Dictionary<int, AetObject> ObjectsDict;
public Dictionary<int, SpriteEntry> SprEntsDict;
public Dictionary<int, Sprite> SpritesDict;
}
public struct AetObject
{
public int Offset;
public Pointer<string> Name;
public float StartTime0;
public float LoopDuration;
public float StartTime1;
public float PlaybackSpeed;
public byte Unk0;
public byte Unk1;
public byte Unk2;
public ObjType Type;
public Pointer<Pic> Pic;
public Pointer<Aif> Aif;
public Pointer<Eff> Eff;
public int? ReadMP(MsgPack msg, int i, ref AetData Aet)
{
Name.Value = msg.ReadString("Name" );
StartTime0 = msg.ReadSingle("StartTime0" );
LoopDuration = msg.ReadSingle("LoopDuration" );
StartTime1 = msg.ReadSingle("StartTime1" );
PlaybackSpeed = msg.ReadSingle("PlaybackSpeed");
Unk0 = msg.ReadUInt8("Unk0");
Unk1 = msg.ReadUInt8("Unk1");
Unk2 = msg.ReadUInt8("Unk2");
if (msg.Element("Pic", out MsgPack Pic))
{ Type = ObjType.Pic; this.Pic = new Pointer<Pic>() { Value = new Pic().ReadMP(Pic, i, ref Aet) }; }
else if (msg.Element("Aif", out MsgPack Aif))
{ Type = ObjType.Aif; this.Aif = new Pointer<Aif>() { Value = new Aif().ReadMP(Aif) }; }
else if (msg.Element("Eff", out MsgPack Eff))
{ Type = ObjType.Eff; this.Eff = new Pointer<Eff>() { Value = new Eff().ReadMP(Eff, i, ref Aet) }; }
else Type = ObjType.Nop;
return msg.ReadNInt32("ID");
}
public MsgPack WriteMP(int Id, ref AetData Aet, string name = null)
{
MsgPack AetObject = new MsgPack(name).Add("ID", Id).Add("Name", Name.Value)
.Add("StartTime0", StartTime0).Add("LoopDuration", LoopDuration)
.Add("StartTime1", StartTime1).Add("PlaybackSpeed", PlaybackSpeed)
.Add("Unk0", Unk0).Add("Unk1", Unk1).Add("Unk2", Unk2);
if (Type == ObjType.Pic) AetObject.Add(Pic.Value.WriteMP(ref Aet));
else if (Type == ObjType.Aif) AetObject.Add(Aif.Value.WriteMP());
else if (Type == ObjType.Eff) AetObject.Add(Eff.Value.WriteMP(ref Aet));
return AetObject;
}
}
public struct Pic
{
public int SpriteEntryID;
public int ParentObjectID;
public CountPointer<Marker> Marker;
public Pointer<AnimationData> Data;
public Pic ReadMP(MsgPack msg, int i, ref AetData Aet)
{
int SpriteEntryID = msg.ReadInt32("SpriteEntryID");
if (Aet.SprEntsIndDict.ContainsValue(SpriteEntryID))
this.SpriteEntryID = Aet.SprEntsIndDict.GetKey(SpriteEntryID);
this.ParentObjectID = -1;
int? ParentObjectID = msg.ReadNInt32("ParentObjectID");
if (ParentObjectID != null)
this.ParentObjectID = ParentObjectID.Value;
if (msg.Element("Marker", out MsgPack Marker))
{
this.Marker.Count = 1;
this.Marker.Entries[0].ReadMP(Marker);
}
else if (msg.Element<MsgPack>("Markers", out MsgPack Markers))
{
this.Marker.Count = Markers.Array.Length;
for (i = 0; i < Markers.Array.Length; i++)
if (Markers[i] is MsgPack Object)
this.Marker.Entries[i].ReadMP(Object);
}
else this.Marker.Entries = null;
Data.Value.ReadMP(msg);
return this;
}
public MsgPack WriteMP(ref AetData Aet)
{
MsgPack Pic = new MsgPack("Pic");
if (Aet.SprEntsIndDict.ContainsKey(SpriteEntryID))
Pic.Add("SpriteEntryID", Aet.SprEntsIndDict[SpriteEntryID]);
if (ParentObjectID > 0)
if (Aet.ObjectsIndDict.ContainsKey(ParentObjectID))
Pic.Add("ParentObjectID", Aet.ObjectsIndDict[ParentObjectID]);
if (Marker.Count == 1)
Pic.Add(Marker.Entries[0].WriteMP("Marker"));
else if (Marker.Count > 1)
{
MsgPack Markers = new MsgPack(Marker.Count, "Markers");
for (int i = 0; i < Marker.Count; i++)
Markers[i] = Marker.Entries[i].WriteMP();
Pic.Add(Markers);
}
Pic.Add(Data.Value.WriteMP());
return Pic;
}
}
public struct Aif
{
public Pointer<int> Value;
public int Zero0;
public int Zero1;
public int Zero2;
public int Zero3;
public int Pointer;
public CountPointer<float> Unk0;
public CountPointer<float> Unk1;
public CountPointer<float> Unk2;
public CountPointer<float> Unk3;
public Aif ReadMP(MsgPack msg)
{
Value.Value = msg.ReadInt32("Value");
msg.ReadMP(ref Unk0, "Unk0");
msg.ReadMP(ref Unk1, "Unk1");
msg.ReadMP(ref Unk2, "Unk2");
msg.ReadMP(ref Unk3, "Unk3");
return this;
}
public MsgPack WriteMP() =>
new MsgPack("Aif").Add("Value", Value.Value).Add("Unk0", Unk0)
.Add("Unk1", Unk0).Add("Unk2", Unk2).Add("Unk3", Unk3);
}
public struct Eff
{
public int LayerID;
public int ParentObjectID;
public CountPointer<Marker> Marker;
public Pointer<AnimationData> Data;
public Eff ReadMP(MsgPack msg, int i, ref AetData Aet)
{
LayerID = msg.ReadInt32("LayerID");
this.ParentObjectID = -1;
int? ParentObjectID = msg.ReadNInt32("ParentObjectID");
if (ParentObjectID != null)
this.ParentObjectID = ParentObjectID.Value;
if (msg.Element("Marker", out MsgPack Marker))
{
this.Marker.Count = 1;
this.Marker.Entries[0].ReadMP(Marker);
}
else if (msg.Element<MsgPack>("Markers", out MsgPack Markers))
{
this.Marker.Count = Markers.Array.Length;
for (i = 0; i < Markers.Array.Length; i++)
if (Markers[i] is MsgPack Object)
this.Marker.Entries[i].ReadMP(Object);
}
else this.Marker.Entries = null;
Data.Value.ReadMP(msg);
return this;
}
public MsgPack WriteMP(ref AetData Aet)
{
MsgPack Eff = new MsgPack("Eff");
if (Aet.LayObjDict.ContainsValue(LayerID))
Eff.Add("LayerID", Aet.LayObjDict.GetKey(LayerID));
if (ParentObjectID > 0)
if (Aet.ObjectsIndDict.ContainsKey(ParentObjectID))
Eff.Add("ParentObjectID", Aet.ObjectsIndDict[ParentObjectID]);
if (Marker.Count == 1)
Eff.Add(Marker.Entries[0].WriteMP("Marker"));
else if (Marker.Count > 1)
{
MsgPack Markers = new MsgPack(Marker.Count, "Markers");
for (int i = 0; i < Marker.Count; i++)
Markers[i] = Marker.Entries[i].WriteMP();
Eff.Add(Markers);
}
Eff.Add(Data.Value.WriteMP());
return Eff;
}
}
public struct Marker
{
public float Frame;
public Pointer<string> Name;
public void ReadMP(MsgPack mp)
{ Frame = mp.ReadSingle("Frame"); Name.Value = mp.ReadString("Name"); }
public MsgPack WriteMP(string name = null) =>
new MsgPack(name).Add("Frame", Frame).Add("Name", Name.Value);
}
public struct AnimationData3D
{
public KeyFrameEntry Unk1 ;
public KeyFrameEntry Unk2 ;
public KeyFrameEntry RotReturnX;
public KeyFrameEntry RotReturnY;
public KeyFrameEntry RotReturnZ;
public KeyFrameEntry RotationX;
public KeyFrameEntry RotationY;
public KeyFrameEntry ScaleZ;
public void ReadMP(MsgPack msg)
{
Unk1 .ReadMP(msg, "Unk1" );
Unk2 .ReadMP(msg, "Unk2" );
RotReturnX.ReadMP(msg, "RotReturnX");
RotReturnY.ReadMP(msg, "RotReturnY");
RotReturnZ.ReadMP(msg, "RotReturnZ");
RotationX.ReadMP(msg, "RotationX");
RotationY.ReadMP(msg, "RotationY");
ScaleZ.ReadMP(msg, "ScaleZ");
}
public MsgPack WriteMP()
{
MsgPack _3D = new MsgPack("3D");
_3D.Add(Unk1 .WriteMP("Unk1" ));
_3D.Add(Unk2 .WriteMP("Unk2" ));
_3D.Add(RotReturnX.WriteMP("RotReturnX"));
_3D.Add(RotReturnY.WriteMP("RotReturnY"));
_3D.Add(RotReturnZ.WriteMP("RotReturnZ"));
_3D.Add( RotationX.WriteMP( "RotationX"));
_3D.Add( RotationY.WriteMP( "RotationY"));
_3D.Add( ScaleZ.WriteMP( "ScaleZ"));
return _3D;
}
}
public struct AnimationData
{
public BlendMode BlendMode;
public byte Unk0;
public bool UseTextureMask;
public byte Unk1;
public KeyFrameEntry OriginX;
public KeyFrameEntry OriginY;
public KeyFrameEntry PositionX;
public KeyFrameEntry PositionY;
public KeyFrameEntry Rotation;
public KeyFrameEntry ScaleX;
public KeyFrameEntry ScaleY;
public KeyFrameEntry Opacity;
public Pointer<AnimationData3D> _3D;
public void ReadMP(MsgPack msg)
{
if (!msg.Element("AnimationData", out MsgPack Data)) return;
System.Enum.TryParse(Data.ReadString("BlendMode"), out BlendMode);
Unk0 = Data.ReadUInt8 ("Unk0");
UseTextureMask = Data.ReadBoolean("UseTextureMask");
Unk1 = Data.ReadUInt8 ("Unk1");
OriginX.ReadMP(Data, "OriginX");
OriginY.ReadMP(Data, "OriginY");
PositionX.ReadMP(Data, "PositionX");
PositionY.ReadMP(Data, "PositionY");
Rotation .ReadMP(Data, "Rotation" );
ScaleX.ReadMP(Data, "ScaleX");
ScaleY.ReadMP(Data, "ScaleY");
Opacity .ReadMP(Data, "Opacity" );
this._3D.Offset = -1;
if (Data.Element("3D", out MsgPack _3D))
{ this._3D.Offset = 0; this._3D.Value.ReadMP(_3D); }
}
public MsgPack WriteMP()
{
MsgPack AnimationData = new MsgPack("AnimationData")
.Add("BlendMode", BlendMode.ToString()).Add("Unk0", Unk0)
.Add("UseTextureMask", UseTextureMask) .Add("Unk1", Unk1);
AnimationData.Add( OriginX.WriteMP( "OriginX"));
AnimationData.Add( OriginY.WriteMP( "OriginY"));
AnimationData.Add(PositionX.WriteMP("PositionX"));
AnimationData.Add(PositionY.WriteMP("PositionY"));
AnimationData.Add(Rotation .WriteMP("Rotation" ));
AnimationData.Add( ScaleX.WriteMP( "ScaleX"));
AnimationData.Add( ScaleY.WriteMP( "ScaleY"));
AnimationData.Add(Opacity .WriteMP("Opacity" ));
if (_3D.Offset > 0)
AnimationData.Add(_3D.Value.WriteMP());
return AnimationData;
}
}
public struct KeyFrameEntry
{
public int Count;
public int Offset;
public float Value;
public float[] ArrValue;
public float[] KeyFrame;
public float[] Interpolation;
public void ReadMP(MsgPack msg, string name)
{
float? Value = msg.ReadNSingle(name);
if (Value != null) { Count = 1; this.Value = Value.Value; return; }
if (!msg.Element<MsgPack>(name, out MsgPack Temp)) return;
Count = Temp.Array.Length;
if (Count == 0) return;
ArrValue = new float[Count];
KeyFrame = new float[Count];
Interpolation = new float[Count];
for (int i = 0; i < Count; i++)
if (Temp[i] is MsgPack KeyFrame)
{
this.KeyFrame[i] = KeyFrame.ReadSingle("KeyFrame" );
ArrValue [i] = KeyFrame.ReadSingle("Value" );
Interpolation[i] = KeyFrame.ReadSingle("Interpolation");
}
}
public MsgPack WriteMP(string name)
{
if (Count < 1) return MsgPack.Null;
if (Count == 1) return new MsgPack(name, Value);
MsgPack KFE = new MsgPack(Count, name);
for (int i = 0; i < Count; i++) KFE[i] = MsgPack.New.Add("KeyFrame", KeyFrame[i])
.Add("Value", ArrValue[i]).Add("Interpolation", Interpolation[i]);
return KFE;
}
}
public struct SpriteEntry
{
public int Unknown;
public short Width;
public short Height;
public float Frames;
public CountPointer<int> Sprites;
public int? ReadMP(MsgPack msg)
{
Unknown = msg.ReadInt32 ("Unknown");
Width = msg.ReadInt16 ("Width" );
Height = msg.ReadInt16 ("Height" );
Frames = msg.ReadSingle("Frames" );
if (msg.Element("SpriteID", out MsgPack SpriteID))
{
Sprites = new CountPointer<int> { Count = 1 };
Sprites.Entries[0] = SpriteID.ReadInt32();
}
else if (msg.Element<MsgPack>("SpriteIDs", out MsgPack SpriteIDs))
{
Sprites = new CountPointer<int> { Count = SpriteIDs.Array.Length };
for (int i0 = 0; i0 < Sprites.Count; i0++)
if (SpriteIDs[i0] is MsgPack ID)
Sprites.Entries[i0] = ID.ReadInt32();
}
return msg.ReadNInt32("ID");
}
public MsgPack WriteMP(int Id, ref Dictionary<int, int> SpritesIndDict, string Name = null)
{
MsgPack SpriteEntry = new MsgPack(Name).Add("ID", Id)
.Add("Width", Width).Add("Height", Height).Add("Unknown", Unknown);
if (Sprites.Count > 0) SpriteEntry.Add("Frames", Frames);
if (Sprites.Count == 1)
SpriteEntry.Add("SpriteID", SpritesIndDict[Sprites.Entries[0]]);
else if (Sprites.Count > 1)
{
MsgPack SpriteIDs = new MsgPack(Sprites.Count, "SpriteIDs");
for (int i0 = 0; i0 < Sprites.Count; i0++)
SpriteIDs[i0] = SpritesIndDict[Sprites.Entries[i0]];
SpriteEntry.Add(SpriteIDs);
}
return SpriteEntry;
}
}
public struct Sprite
{
public Pointer<string> Name;
public int ID;
public MsgPack WriteMP(int Id, string name = null) =>
new MsgPack(name).Add("ID", Id).Add("Name", Name.Value).Add("SprDB_ID", ID);
public int? ReadMP(MsgPack mp)
{ ID = mp.ReadInt32("SprDB_ID"); Name.Value = mp.ReadString("Name"); return mp.ReadNInt32("ID"); }
}
public enum ObjType : byte
{
Nop = 0,
Pic = 1,
Aif = 2,
Eff = 3,
}
public enum BlendMode : byte
{
Alpha = 3,
Additive = 5,
DstColorZero = 6,
SrcAlphaOneMinusSrcColor = 7,
Transparent = 8,
}
}
-496
View File
@@ -1,496 +0,0 @@
using System.Collections.Generic;
using System.Linq;
using KKdMainLib.IO;
using KKdMainLib.Types;
using KKdMainLib.MessagePack;
namespace KKdMainLib.Aet
{
public static class AetExt
{
private static System.Text.Encoding ShiftJIS = System.Text.Encoding.GetEncoding(932);
public static Dictionary<TKey, int> GetIndDict<TKey, TVal>(this Dictionary<TKey, TVal> Dict)
{
List<TKey> Keys = Dict.Keys.ToList();
Dictionary<TKey, int> IndDict = new Dictionary<TKey, int>();
for (int i = 0; i < Keys.Count; i++)
IndDict.Add(Keys[i], i);
return IndDict;
}
public static Pointer<T>[] ToPointerArray<T>(this Dictionary<int, T> val)
{
Pointer<T>[] arr = new Pointer<T>[val.Count];
for (int i = 0; i < val.Count; i++)
arr[i] = val.ElementAt(i).ToPointer();
return arr;
}
public static Pointer<T> ReadPointer<T>(this Stream IO) =>
new Pointer<T> { Offset = IO.ReadInt32() };
public static Pointer<string> ReadPointerString(this Stream IO)
{ Pointer<string> val = IO.ReadPointer<string>();
val.Value = IO.ReadStringAtOffset(val.Offset); return val; }
public static Pointer<string> ReadPointerStringShiftJIS(this Stream IO)
{ Pointer<string> val = IO.ReadPointer<string>();
val.Value = ShiftJIS.GetString(IO.ReadAtOffset(val.Offset)); return val; }
public static void WriteShiftJIS(this Stream IO, string String) =>
IO.Write(ShiftJIS.GetBytes(String));
public static CountPointer<T> ReadCountPointer<T>(this Stream IO)
{ CountPointer<T> val = new CountPointer<T> { Count = IO.ReadInt32(),
Offset = IO.ReadInt32() }; val.Entries = new T[val.Count]; return val; }
public static Pointer<T> ToPointer<T>(this KeyValuePair<int, T> val) =>
new Pointer<T> { Offset = val.Key, Value = val.Value };
public static void ReadMP(this MsgPack msg, ref CountPointer<float> val, string Name)
{
val.Offset = 0;
val.Entries = null;
if (msg.ContainsKey(Name))
{
val.Count = 1;
val.Entries[0] = msg.ReadSingle(Name);
}
else if(msg.Element<MsgPack>(Name, out MsgPack Temp))
{
val.Count = Temp.Array.Length;
for (int i = 0; i < val.Count; i++)
if (Temp[i] is MsgPack temp)
val.Entries[i] = temp.ReadSingle();
}
}
public static MsgPack Add(this MsgPack MsgPack, string Name, CountPointer<float> val)
{
if (val.Count == 1) return MsgPack.Add(new MsgPack(Name, val.Entries[0]));
else if (val.Count > 1)
{
MsgPack Val = new MsgPack(val.Count, Name);
for (int i = 0; i < val.Count; i++) Val[i] = val.Entries[i];
return MsgPack.Add(Val);
}
return MsgPack;
}
public static int ReadAetObject(this Stream IO, ref Dictionary<int, AetObject> ObjectsDict)
{
AetObject Anim = new AetObject();
int AnimOffset = IO.Position;
if (ObjectsDict.ContainsKey(AnimOffset)) return AnimOffset;
Anim.Name = IO.ReadPointerString();
Anim.StartTime0 = IO.ReadSingle();
Anim.LoopDuration = IO.ReadSingle();
Anim.StartTime1 = IO.ReadSingle();
Anim.PlaybackSpeed = IO.ReadSingle();
Anim.Unk0 = IO.ReadByte();
Anim.Unk1 = IO.ReadByte();
Anim.Unk2 = IO.ReadByte();
Anim.Type = (ObjType)IO.ReadByte();
if (Anim.Type == ObjType.Pic) Anim.Pic = IO.ReadPic(ref ObjectsDict);
else if (Anim.Type == ObjType.Aif) Anim.Aif = IO.ReadAif();
else if (Anim.Type == ObjType.Eff) Anim.Eff = IO.ReadEff(ref ObjectsDict);
IO.Position = AnimOffset + 0x30;
if (!ObjectsDict.ContainsKey(AnimOffset))
ObjectsDict.Add(AnimOffset, Anim);
return AnimOffset;
}
public static void Write(this Stream IO, ref AetObject Anim, ref List<int> NullValPointers)
{
if (Anim.Type == ObjType.Pic)
{
if (Anim.Pic.Value.Marker.Count > 0)
{
Anim.Pic.Value.Marker.Offset = IO.Position;
for (int i = 0; i < Anim.Pic.Value.Marker.Count; i++) IO.Write(0L);
}
IO.Write(ref Anim.Pic.Value.Data, ref NullValPointers);
}
else if (Anim.Type == ObjType.Aif) IO.Write(ref Anim.Aif);
else if (Anim.Type == ObjType.Eff)
{
if (Anim.Eff.Value.Marker.Count > 0)
{
Anim.Eff.Value.Marker.Offset = IO.Position;
for (int i = 0; i < Anim.Eff.Value.Marker.Count; i++) IO.Write(0L);
}
IO.Write(ref Anim.Eff.Value.Data, ref NullValPointers);
}
}
public static void Write(this Stream IO, ref AetObject Anim, ref int Offset)
{
Offset = IO.Position;
IO.Write(0);
IO.Write(Anim.StartTime0 );
IO.Write(Anim.LoopDuration );
IO.Write(Anim.StartTime1 );
IO.Write(Anim.PlaybackSpeed);
IO.Write(Anim.Unk0);
IO.Write(Anim.Unk1);
IO.Write(Anim.Unk2);
IO.Write((byte)Anim.Type);
if (Anim.Type == ObjType.Pic)
{
Anim.Pic.Offset = IO.Position;
IO.Write(0L);
if (Anim.Pic.Value.Marker.Count > 0)
{
IO.Write(Anim.Pic.Value.Marker.Count );
IO.Write(Anim.Pic.Value.Marker.Offset);
}
else IO.Write(0L);
IO.Write(Anim.Pic.Value.Data .Offset);
IO.Write(0);
}
else if (Anim.Type == ObjType.Aif)
{
Anim.Aif.Offset = IO.Position;
IO.Write(Anim.Aif.Value.Value.Offset);
IO.Write(0L);
IO.Write(0L);
IO.Write(Anim.Aif.Value.Pointer);
}
else if (Anim.Type == ObjType.Eff)
{
Anim.Eff.Offset = IO.Position;
IO.Write(0L);
if (Anim.Eff.Value.Marker.Count > 0)
{
IO.Write(Anim.Eff.Value.Marker.Count );
IO.Write(Anim.Eff.Value.Marker.Offset);
}
else IO.Write(0L);
IO.Write(Anim.Eff.Value.Data.Offset);
IO.Write(0);
}
else { IO.Write(0L); IO.Write(0L); IO.Write(0L); }
}
public static Pointer<Pic> ReadPic(this Stream IO, ref Dictionary<int, AetObject> ObjectsDict)
{
Pointer<Pic> Pic = new Pointer<Pic> { Offset = IO.Position,
Value = new Pic
{
SpriteEntryID = IO.ReadInt32(),
ParentObjectID = IO.ReadInt32(),
Marker = IO.ReadCountPointer<Marker>()
}
};
Pic.Value.Data.Offset = IO.ReadInt32();
IO.ReadAnimData(ref Pic.Value.Data);
IO.Position = Pic.Value.Marker.Offset;
for (int i = 0; i < Pic.Value.Marker.Count; i++)
{
Pic.Value.Marker.Entries[i].Frame = IO.ReadSingle();
Pic.Value.Marker.Entries[i]. Name = IO.ReadPointerStringShiftJIS();
}
return Pic;
}
public static Pointer<Aif> ReadAif(this Stream IO)
{
Pointer<Aif> Aif = new Pointer<Aif> { Offset = IO.Position,
Value = new Aif
{
Value = IO.ReadPointer<int>(),
Zero0 = IO.ReadInt32(),
Zero1 = IO.ReadInt32(),
Zero2 = IO.ReadInt32(),
Zero3 = IO.ReadInt32(),
Pointer = IO.ReadInt32(),
}
};
IO.Position = Aif.Value.Value.Offset;
Aif.Value.Value.Value = IO.ReadInt32();
IO.Position = Aif.Value.Pointer;
Aif.Value.Unk0 = IO.ReadCountPointer<float>();
Aif.Value.Unk1 = IO.ReadCountPointer<float>();
Aif.Value.Unk2 = IO.ReadCountPointer<float>();
Aif.Value.Unk3 = IO.ReadCountPointer<float>();
IO.Position = Aif.Value.Unk0.Offset;
for (int i = 0; i < Aif.Value.Unk0.Count; i++) Aif.Value.Unk0.Entries[i] = IO.ReadSingle();
IO.Position = Aif.Value.Unk1.Offset;
for (int i = 0; i < Aif.Value.Unk1.Count; i++) Aif.Value.Unk1.Entries[i] = IO.ReadSingle();
IO.Position = Aif.Value.Unk2.Offset;
for (int i = 0; i < Aif.Value.Unk2.Count; i++) Aif.Value.Unk2.Entries[i] = IO.ReadSingle();
IO.Position = Aif.Value.Unk3.Offset;
for (int i = 0; i < Aif.Value.Unk3.Count; i++) Aif.Value.Unk3.Entries[i] = IO.ReadSingle();
return Aif;
}
public static void Write(this Stream IO, ref Pointer<Aif> Aif)
{
if (Aif.Value.Unk0.Count > 0) { Aif.Value.Unk0.Offset = IO.Position;
for (int i = 0; i < Aif.Value.Unk0.Count; i++) IO.Write(Aif.Value.Unk0.Entries[i]); }
if (Aif.Value.Unk1.Count > 0) { Aif.Value.Unk1.Offset = IO.Position;
for (int i = 0; i < Aif.Value.Unk1.Count; i++) IO.Write(Aif.Value.Unk1.Entries[i]); }
if (Aif.Value.Unk2.Count > 0) { Aif.Value.Unk2.Offset = IO.Position;
for (int i = 0; i < Aif.Value.Unk2.Count; i++) IO.Write(Aif.Value.Unk2.Entries[i]); }
if (Aif.Value.Unk3.Count > 0) { Aif.Value.Unk3.Offset = IO.Position;
for (int i = 0; i < Aif.Value.Unk3.Count; i++) IO.Write(Aif.Value.Unk3.Entries[i]); }
IO.Align(0x10);
Aif.Value.Value.Offset = IO.Position;
IO.Write(Aif.Value.Value.Value);
IO.Align(0x10);
Aif.Value.Pointer = IO.Position;
if (Aif.Value.Unk0.Count > 0) { IO.Write(Aif.Value.Unk0.Count); IO.Write(Aif.Value.Unk0.Offset); }
else IO.Write(0L);
if (Aif.Value.Unk1.Count > 0) { IO.Write(Aif.Value.Unk1.Count); IO.Write(Aif.Value.Unk1.Offset); }
else IO.Write(0L);
if (Aif.Value.Unk2.Count > 0) { IO.Write(Aif.Value.Unk2.Count); IO.Write(Aif.Value.Unk2.Offset); }
else IO.Write(0L);
if (Aif.Value.Unk3.Count > 0) { IO.Write(Aif.Value.Unk3.Count); IO.Write(Aif.Value.Unk3.Offset); }
else IO.Write(0L);
}
public static Pointer<Eff> ReadEff(this Stream IO, ref Dictionary<int, AetObject> ObjectsDict)
{
Pointer<Eff> Eff = new Pointer<Eff> { Offset = IO.Position,
Value = new Eff
{
LayerID = IO.ReadInt32(),
ParentObjectID = IO.ReadInt32(),
Marker = IO.ReadCountPointer<Marker>()
}
};
Eff.Value.Data.Offset = IO.ReadInt32();
IO.Position = Eff.Value.LayerID;
CountPointer<AetObject> AetObjEntry = IO.ReadCountPointer<AetObject>();
IO.Position = AetObjEntry.Offset;
for (int i = 0; i < AetObjEntry.Count; i++) IO.ReadAetObject(ref ObjectsDict);
IO.Position = Eff.Value.Marker.Offset;
for (int i = 0; i < Eff.Value.Marker.Count; i++)
{
Eff.Value.Marker.Entries[i].Frame = IO.ReadSingle();
Eff.Value.Marker.Entries[i]. Name = IO.ReadPointerStringShiftJIS();
}
IO.ReadAnimData(ref Eff.Value.Data);
return Eff;
}
public static void ReadAnimData(this Stream IO, ref Pointer<AnimationData> Anim)
{
ref AnimationData Data = ref Anim.Value;
IO.Position = Anim.Offset;
Data.BlendMode = (BlendMode)IO.ReadByte();
Data.Unk0 = IO.ReadByte();
Data.UseTextureMask = IO.ReadBoolean();
Data.Unk1 = IO.ReadByte();
Data. OriginX = IO.ReadKeyFrameEntry();
Data. OriginY = IO.ReadKeyFrameEntry();
Data.PositionX = IO.ReadKeyFrameEntry();
Data.PositionY = IO.ReadKeyFrameEntry();
Data.Rotation = IO.ReadKeyFrameEntry();
Data. ScaleX = IO.ReadKeyFrameEntry();
Data. ScaleY = IO.ReadKeyFrameEntry();
Data.Opacity = IO.ReadKeyFrameEntry();
Data._3D = IO.ReadPointer<AnimationData3D>();
IO.ReadKeyFrameEntry(ref Data. OriginX);
IO.ReadKeyFrameEntry(ref Data. OriginY);
IO.ReadKeyFrameEntry(ref Data.PositionX);
IO.ReadKeyFrameEntry(ref Data.PositionY);
IO.ReadKeyFrameEntry(ref Data.Rotation );
IO.ReadKeyFrameEntry(ref Data. ScaleX);
IO.ReadKeyFrameEntry(ref Data. ScaleY);
IO.ReadKeyFrameEntry(ref Data.Opacity );
if (Data._3D.Offset > 0)
{
IO.Position = Data._3D.Offset;
Data._3D.Value.Unk1 = IO.ReadKeyFrameEntry();
Data._3D.Value.Unk2 = IO.ReadKeyFrameEntry();
Data._3D.Value.RotReturnX = IO.ReadKeyFrameEntry();
Data._3D.Value.RotReturnY = IO.ReadKeyFrameEntry();
Data._3D.Value.RotReturnZ = IO.ReadKeyFrameEntry();
Data._3D.Value. RotationX = IO.ReadKeyFrameEntry();
Data._3D.Value. RotationY = IO.ReadKeyFrameEntry();
Data._3D.Value. ScaleZ = IO.ReadKeyFrameEntry();
IO.ReadKeyFrameEntry(ref Data._3D.Value.Unk1 );
IO.ReadKeyFrameEntry(ref Data._3D.Value.Unk2 );
IO.ReadKeyFrameEntry(ref Data._3D.Value.RotReturnX);
IO.ReadKeyFrameEntry(ref Data._3D.Value.RotReturnY);
IO.ReadKeyFrameEntry(ref Data._3D.Value.RotReturnZ);
IO.ReadKeyFrameEntry(ref Data._3D.Value. RotationX);
IO.ReadKeyFrameEntry(ref Data._3D.Value. RotationY);
IO.ReadKeyFrameEntry(ref Data._3D.Value. ScaleZ);
}
}
public static void Write(this Stream IO, ref Pointer<AnimationData> Anim, ref List<int> NullValPointers)
{
ref AnimationData Data = ref Anim.Value;
int SubFlags = 0;
if (Data._3D.Offset > -1)
{
SubFlags |= IO.Write(ref Data._3D.Value.Unk1 ) ? 0b10000000 : 0;
SubFlags |= IO.Write(ref Data._3D.Value.Unk2 ) ? 0b01000000 : 0;
SubFlags |= IO.Write(ref Data._3D.Value.RotReturnX) ? 0b00100000 : 0;
SubFlags |= IO.Write(ref Data._3D.Value.RotReturnY) ? 0b00010000 : 0;
SubFlags |= IO.Write(ref Data._3D.Value.RotReturnZ) ? 0b00001000 : 0;
SubFlags |= IO.Write(ref Data._3D.Value. RotationX) ? 0b00000100 : 0;
SubFlags |= IO.Write(ref Data._3D.Value. RotationY) ? 0b00000010 : 0;
SubFlags |= IO.Write(ref Data._3D.Value. ScaleZ) ? 0b00000001 : 0;
}
int Flags = 0;
Flags |= IO.Write(ref Data. OriginX) ? 0b10000000 : 0;
Flags |= IO.Write(ref Data. OriginY) ? 0b01000000 : 0;
Flags |= IO.Write(ref Data.PositionX) ? 0b00100000 : 0;
Flags |= IO.Write(ref Data.PositionY) ? 0b00010000 : 0;
Flags |= IO.Write(ref Data.Rotation ) ? 0b00001000 : 0;
Flags |= IO.Write(ref Data. ScaleX) ? 0b00000100 : 0;
Flags |= IO.Write(ref Data. ScaleY) ? 0b00000010 : 0;
Flags |= IO.Write(ref Data.Opacity ) ? 0b00000001 : 0;
if (Data._3D.Offset > -1)
{
IO.Align(0x20);
Data._3D.Offset = IO.Position;
IO.Write(ref Data._3D.Value, ref NullValPointers, SubFlags);
}
IO.Align(0x20);
Anim.Offset = IO.Position;
IO.WriteByte((byte) Data.BlendMode);
IO.WriteByte( Data.Unk0);
IO.WriteByte((byte)(Data.UseTextureMask ? 1 : 0));
IO.WriteByte( Data.Unk1);
IO.Write(ref Data, ref NullValPointers, Flags);
IO.Write(Data._3D.Offset > -1 ? Data._3D.Offset : 0);
}
public static void Write(this Stream IO, ref AnimationData Data, ref List<int> NullValPointers, int Flags)
{
IO.Write(Data. OriginX.Count );
if ((Flags & 0b10000000) == 0b10000000) NullValPointers.Add(IO.Position);
IO.Write(Data. OriginX.Offset);
IO.Write(Data. OriginY.Count );
if ((Flags & 0b01000000) == 0b01000000) NullValPointers.Add(IO.Position);
IO.Write(Data. OriginY.Offset);
IO.Write(Data.PositionX.Count );
if ((Flags & 0b00100000) == 0b00100000) NullValPointers.Add(IO.Position);
IO.Write(Data.PositionX.Offset);
IO.Write(Data.PositionY.Count );
if ((Flags & 0b00010000) == 0b00010000) NullValPointers.Add(IO.Position);
IO.Write(Data.PositionY.Offset);
IO.Write(Data.Rotation .Count );
if ((Flags & 0b00001000) == 0b00001000) NullValPointers.Add(IO.Position);
IO.Write(Data.Rotation .Offset);
IO.Write(Data. ScaleX.Count );
if ((Flags & 0b00000100) == 0b00000100) NullValPointers.Add(IO.Position);
IO.Write(Data. ScaleX.Offset);
IO.Write(Data. ScaleY.Count );
if ((Flags & 0b00000010) == 0b00000010) NullValPointers.Add(IO.Position);
IO.Write(Data. ScaleY.Offset);
IO.Write(Data.Opacity .Count );
if ((Flags & 0b00000001) == 0b00000001) NullValPointers.Add(IO.Position);
IO.Write(Data.Opacity .Offset);
}
public static void Write(this Stream IO, ref AnimationData3D Data, ref List<int> NullValPointers, int Flags)
{
IO.Write(Data.Unk1 .Count );
if ((Flags & 0b10000000) == 0b10000000) NullValPointers.Add(IO.Position);
IO.Write(Data.Unk1 .Offset);
IO.Write(Data.Unk2 .Count );
if ((Flags & 0b01000000) == 0b01000000) NullValPointers.Add(IO.Position);
IO.Write(Data.Unk2 .Offset);
IO.Write(Data.RotReturnX.Count );
if ((Flags & 0b00100000) == 0b00100000) NullValPointers.Add(IO.Position);
IO.Write(Data.RotReturnX.Offset);
IO.Write(Data.RotReturnY.Count );
if ((Flags & 0b00010000) == 0b00010000) NullValPointers.Add(IO.Position);
IO.Write(Data.RotReturnY.Offset);
IO.Write(Data.RotReturnZ.Count );
if ((Flags & 0b00001000) == 0b00001000) NullValPointers.Add(IO.Position);
IO.Write(Data.RotReturnZ.Offset);
IO.Write(Data. RotationX.Count );
if ((Flags & 0b00000100) == 0b00000100) NullValPointers.Add(IO.Position);
IO.Write(Data. RotationX.Offset);
IO.Write(Data. RotationY.Count );
if ((Flags & 0b00000010) == 0b00000010) NullValPointers.Add(IO.Position);
IO.Write(Data. RotationY.Offset);
IO.Write(Data. ScaleZ.Count );
if ((Flags & 0b00000001) == 0b00000001) NullValPointers.Add(IO.Position);
IO.Write(Data. ScaleZ.Offset);
}
public static KeyFrameEntry ReadKeyFrameEntry(this Stream IO) =>
new KeyFrameEntry { Count = IO.ReadInt32(), Offset = IO.ReadInt32() };
public static void ReadKeyFrameEntry(this Stream IO, ref KeyFrameEntry entry)
{
if (entry.Count < 1) return;
IO.Position = entry.Offset;
if (entry.Count == 1) { entry.Value = IO.ReadSingle(); return; }
entry.Interpolation = new float[entry.Count];
entry.KeyFrame = new float[entry.Count];
entry.ArrValue = new float[entry.Count];
for (int i = 0; i < entry.Count; i++) entry.KeyFrame [i] = IO.ReadSingle();
for (int i = 0; i < entry.Count; i++)
{ entry.ArrValue[i] = IO.ReadSingle(); entry.Interpolation[i] = IO.ReadSingle(); }
}
public static bool Write(this Stream IO, ref KeyFrameEntry entry)
{
if (entry.Count == 0) return false;
if (entry.Count > 2) IO.Align(0x20);
entry.Offset = IO.Position;
if (entry.Count == 1) if (entry.Value == 0) return true;
else { IO.Write(entry.Value); return false; }
for (int i = 0; i < entry.Count; i++) IO.Write(entry.KeyFrame [i]);
for (int i = 0; i < entry.Count; i++)
{ IO.Write(entry.ArrValue[i]); IO.Write(entry.Interpolation[i]); }
return false;
}
public static void ReadMP(this CountPointer<Marker> mark, MsgPack msg)
{
if (msg.Element("Marker", out MsgPack Marker))
{
mark.Count = 1;
mark.Entries[0].ReadMP(Marker);
}
else if (msg.Element<MsgPack>("Markers", out MsgPack Markers))
{
mark.Count = Markers.Array.Length;
for (int i = 0; i < mark.Count; i++)
if (Markers[i] is MsgPack marker)
mark.Entries[i].ReadMP(marker);
}
}
public static void WritePointerString(this Stream IO,
ref Dictionary<string, int> Dict, ref Pointer<string> Str)
{
if (Dict.ContainsKey(Str.Value)) Str.Offset = Dict[Str.Value];
else
{ Str.Offset = IO.Position; Dict.Add(Str.Value, Str.Offset); IO.WriteShiftJIS(Str.Value + "\0"); }
}
}
}
+5 -7
View File
@@ -190,14 +190,13 @@ namespace KKdMainLib.DB
public void MsgPackReader(string file, bool JSON)
{
MsgPack MsgPack = file.ReadMP(JSON);
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
if (MsgPack.Element<MsgPack>("AetDB", out MsgPack AetDB))
if (MsgPack.ElementArray("AetDB", out MsgPack AetDB))
{
AetSets = new AetSet[AetDB.Array.Length];
for (int i = 0; i < AetSets.Length; i++)
if (AetDB[i] is MsgPack Aet)
AetSets[i].ReadMsgPack(Aet);
AetSets[i].ReadMsgPack(AetDB[i]);
}
MsgPack = MsgPack.New;
}
@@ -247,12 +246,11 @@ namespace KKdMainLib.DB
NewId = msg.ReadBoolean("NewId" );
SpriteSetId = msg.ReadNUInt16("SpriteSetId");
if (msg.Element<MsgPack>("Aets", out MsgPack Aets))
if (msg.ElementArray("Aets", out MsgPack Aets))
{
this.Aets = new AET[Aets.Array.Length];
for (int i0 = 0; i0 < this.Aets.Length; i0++)
if (Aets[i0] is MsgPack Aet)
this.Aets[i0].ReadMsgPack(Aet);
this.Aets[i0].ReadMsgPack(Aets[i0]);
}
}
+22 -30
View File
@@ -70,8 +70,7 @@ namespace KKdMainLib.DB
{
int[] SO = Category.Length.SortWriter();
for (int i = 0; i < Category.Length; i++)
if (Category[SO[i]] != null)
IO.Write("category." + SO[i] + ".value=", Category[SO[i]]);
IO.Write("category." + SO[i] + ".value=", Category[SO[i]]);
IO.Write("category.length=", Category.Length);
}
@@ -80,16 +79,12 @@ namespace KKdMainLib.DB
int[] SO = _UID.Length.SortWriter();
for (int i = 0; i < _UID.Length; i++)
{
if (_UID[SO[i]].Category != null)
if (_UID[SO[i]].Category != "")
IO.Write("uid." + SO[i] + ".category=", _UID[SO[i]].Category);
if (_UID[SO[i]].OrgUid != null)
IO.Write("uid." + SO[i] + ".org_uid=" , _UID[SO[i]].OrgUid );
if (_UID[SO[i]].Size != null)
IO.Write("uid." + SO[i] + ".size=" , _UID[SO[i]].Size );
if (_UID[SO[i]].Value != null)
if (_UID[SO[i]].Value != "")
IO.Write("uid." + SO[i] + ".value=" , _UID[SO[i]].Value );
if (_UID[SO[i]].Category != "")
IO.Write("uid." + SO[i] + ".category=", _UID[SO[i]].Category);
IO.Write("uid." + SO[i] + ".org_uid=" , _UID[SO[i]].OrgUid );
IO.Write("uid." + SO[i] + ".size=" , _UID[SO[i]].Size );
if (_UID[SO[i]].Value != "")
IO.Write("uid." + SO[i] + ".value=" , _UID[SO[i]].Value );
}
IO.Write("uid.length=", _UID.Length);
}
@@ -99,29 +94,27 @@ namespace KKdMainLib.DB
public void MsgPackReader(string file, bool JSON)
{
MsgPack MsgPack = file.ReadMP(JSON);
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
if (MsgPack.Element("AuthDB", out MsgPack AuthDB))
{
if (AuthDB.Element<MsgPack>("Category", out MsgPack Temp))
if (AuthDB.ElementArray("Category", out MsgPack Temp))
{
Category = new string[Temp.Array.Length];
for (int i = 0; i < Category.Length; i++)
if (Temp is MsgPack Category)
this.Category[i] = Category.ReadString();
Category[i] = Temp[i].ReadString();
}
if (AuthDB.Element<MsgPack>("UID", out Temp))
if (AuthDB.ElementArray("UID", out Temp))
{
_UID = new UID[Temp.Array.Length];
for (int i = 0; i < _UID.Length; i++)
if (Temp[i] is MsgPack UID)
{
_UID[i].Category = UID.ReadString("C");
_UID[i].OrgUid = UID.ReadNInt32("O");
_UID[i].Size = UID.ReadNInt32("S");
_UID[i].Value = UID.ReadString("V");
}
{
_UID[i].Category = Temp[i].ReadString("Category");
_UID[i].OrgUid = Temp[i].ReadNInt32("OrgUid" );
_UID[i].Size = Temp[i].ReadNInt32("Size" );
_UID[i].Value = Temp[i].ReadString("Value" );
}
}
}
MsgPack = MsgPack.New;
@@ -134,7 +127,7 @@ namespace KKdMainLib.DB
{
MsgPack Category = new MsgPack(this.Category.Length, "Category");
for (int i = 0; i < this.Category.Length; i++)
Category[i] = this.Category[i];
Category[i] = (MsgPack)this.Category[i];
AuthDB.Add(Category);
}
@@ -142,11 +135,10 @@ namespace KKdMainLib.DB
{
MsgPack UID = new MsgPack(_UID.Length, "UID");
for (int i = 0; i < _UID.Length; i++)
UID[i] = MsgPack.New
.Add("C", _UID[i].Category)
.Add("O", _UID[i].OrgUid )
.Add("S", _UID[i].Size )
.Add("V", _UID[i].Value );
UID[i] = MsgPack.New.Add("Category", _UID[i].Category)
.Add("OrgUid" , _UID[i].OrgUid )
.Add("Size" , _UID[i].Size )
.Add("Value" , _UID[i].Value );
AuthDB.Add(UID);
}
+10 -33
View File
@@ -15,26 +15,6 @@ namespace KKdMainLib.DB
public void BINReader(string file)
{
/*Stream IO0 = File.OpenReader(file + "0.bin");
Stream IO1 = File.OpenReader(file + "1.bin");
List<int> _0 = new List<int>();
List<int> _1 = new List<int>();
IO0.Position = 0x20;
for (i = 0; i < 124; i++)
{ _0.Add(IO0.ReadInt32()); IO0.LongPosition += 8; }
IO1.Position = 0x20;
for (i = 0; i < 124; i++)
{ _1.Add(IO1.ReadInt32()); IO1.LongPosition += 8; }
IO0.Close();
IO1.Close();
IO = File.OpenWriter(@"F:\Source\MikuMikuModel\DatabaseConverter\msgpack-json-tools\aet_gam_pv643.bin");
IO.Position = 0x10;
for (i = 0; i < 108; i++)
{ IO.ReadInt32(); i1 = _1[_0.IndexOf(IO.ReadInt32())]; IO.Position -= 4; IO.Write(i1); }
IO.Close();*/
IO = File.OpenReader(file + ".bin");
int spriteSetsLength = IO.ReadInt32();
@@ -140,7 +120,7 @@ namespace KKdMainLib.DB
if ( Ids.Contains((int)temp.Id)) { NotAdd.Add(i); break; }
else Ids.Add ((int)temp.Id);
}
if (i0 + 1 != set.Sprites.Length) continue;
if (i0 < set.Sprites.Length) continue;
for (i0 = 0; i0 < set.Textures.Length; i0++)
{
@@ -247,14 +227,13 @@ namespace KKdMainLib.DB
public void MsgPackReader(string file, bool JSON = false)
{
MsgPack MsgPack = file.ReadMP(JSON);
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
if (MsgPack.Element<MsgPack>("SprDB", out MsgPack SprDB))
if (MsgPack.ElementArray("SprDB", out MsgPack SprDB))
{
SpriteSets = new SpriteSet[SprDB.Array.Length];
for (int i = 0; i < SpriteSets.Length; i++)
if (SprDB[i] is MsgPack Spr)
SpriteSets[i].ReadMsgPack(Spr);
SpriteSets[i].ReadMsgPack(SprDB[i]);
}
MsgPack = MsgPack.New;
}
@@ -301,20 +280,18 @@ namespace KKdMainLib.DB
Name = msg.ReadString ("Name" );
NewId = msg.ReadBoolean("NewId" );
if (msg.Element<MsgPack>( "Sprites", out MsgPack Sprites))
if (msg.ElementArray( "Sprites", out MsgPack Sprites))
{
this .Sprites = new SpriteTexture[Sprites.Array.Length];
this.Sprites = new SpriteTexture[Sprites.Array.Length];
for (int i0 = 0; i0 < this.Sprites.Length; i0++)
if (Sprites[i0] is MsgPack Sprite)
this.Sprites[i0].ReadMsgPack(Sprite);
this.Sprites[i0].ReadMsgPack(Sprites[i0]);
}
if (msg.Element<MsgPack>("Textures", out MsgPack Textures))
if (msg.ElementArray("Textures", out MsgPack Textures))
{
this .Textures = new SpriteTexture[Textures.Array.Length];
this.Textures = new SpriteTexture[Textures.Array.Length];
for (int i0 = 0; i0 < this.Textures.Length; i0++)
if (Textures[i0] is MsgPack Texture)
this.Textures[i0].ReadMsgPack(Texture);
this.Textures[i0].ReadMsgPack(Textures[i0]);
}
}
+45 -65
View File
@@ -12,8 +12,8 @@ namespace KKdMainLib
private int Offset = 0;
private PDHead Header;
public Stream IO;
private Stream IO;
public EXP[] Dex;
public int DEXReader(string filepath, string ext)
@@ -22,10 +22,10 @@ namespace KKdMainLib
IO = File.OpenReader(filepath + ext);
Header.Format = Main.Format.F;
Header.Signature = IO.ReadInt32();
if (Header.Signature == 0x43505845)
Header.SectionSignature = IO.ReadInt32();
if (Header.SectionSignature == 0x43505845)
Header = IO.ReadHeader(true);
if (Header.Signature != 0x64)
if (Header.SectionSignature != 0x64)
return 0;
Offset = IO.Position - 0x4;
@@ -95,39 +95,27 @@ namespace KKdMainLib
public void DEXWriter(string filepath, Main.Format Format)
{
Header = new PDHead() { Format = Format };
IO = File.OpenWriter(filepath + (Header.Format > Main.Format.F ? ".dex" : ".bin"), true);
IO.Format = Header.Format;
if (IO.Format > Main.Format.F)
{
Header.Lenght = 0x20;
Header.DataSize = 0x00;
Header.Signature = 0x43505845;
Header.SectionSize = 0x00;
IO.Write(Header);
}
IO = File.OpenWriter(filepath + (Format > Main.Format.F ? ".dex" : ".bin"), true);
IO.Format = Format;
IO.Offset = Format > Main.Format.F ? 0x20 : 0;
IO.Write(0x64);
IO.Write(Dex.Length);
if (Header.IsX) IO.Write((long)0x28);
else IO.Write( 0x20);
if (Header.IsX) IO.Write((long)0x00);
else IO.Write( 0x00);
IO.WriteX(Header.IsX ? 0x28 : 0x20);
IO.WriteX(0x00);
int Position0 = IO.Position;
IO.Write((long)0x00);
IO.Write((long)0x00);
IO.Write(0x00L);
IO.Write(0x00L);
for (int i = 0; i < Dex.Length * 3; i++)
if (Header.IsX) IO.Write((long)0x00);
else IO.Write( 0x00);
for (int i = 0; i < Dex.Length * 3; i++) IO.WriteX(0x00);
IO.Align(0x20, true);
for (int i0 = 0; i0 < Dex.Length; i0++)
{
Dex[i0].MainOffset = IO.Position - Header.Lenght;
Dex[i0].MainOffset = IO.Position;
for (int i1 = 0; i1 < Dex[i0].Main.Count; i1++)
{
IO.Write(Dex[i0].Main[i1].Frame);
@@ -138,7 +126,7 @@ namespace KKdMainLib
}
IO.Align(0x20, true);
Dex[i0].EyesOffset = IO.Position - Header.Lenght;
Dex[i0].EyesOffset = IO.Position;
for (int i1 = 0; i1 < Dex[i0].Eyes.Count; i1++)
{
IO.Write(Dex[i0].Eyes[i1].Frame);
@@ -151,40 +139,35 @@ namespace KKdMainLib
}
for (int i0 = 0; i0 < Dex.Length; i0++)
{
Dex[i0].NameOffset = IO.Position - Header.Lenght;
Dex[i0].NameOffset = IO.Position;
IO.Write(Dex[i0].Name + "\0");
}
IO.Align(0x10, true);
if (Header.IsX) IO.Seek(Header.Lenght + 0x28, 0);
else IO.Seek(Header.Lenght + 0x20, 0);
IO.Position = Header.IsX ? 0x28 : 0x20;
for (int i0 = 0; i0 < Dex.Length; i0++)
{
IO.Write(Dex[i0].MainOffset);
if (Header.IsX) IO.Write(0x00);
IO.Write(Dex[i0].EyesOffset);
if (Header.IsX) IO.Write(0x00);
IO.WriteX(Dex[i0].MainOffset);
IO.WriteX(Dex[i0].EyesOffset);
}
int Position1 = IO.Position - Header.Lenght;
int Position1 = IO.Position;
for (int i0 = 0; i0 < Dex.Length; i0++)
{
IO.Write(Dex[i0].NameOffset);
if (Header.IsX) IO.Write(0x00);
}
IO.WriteX(Dex[i0].NameOffset);
if (Header.IsX) IO.Seek(Position0 - 8, 0);
else IO.Seek(Position0 - 4, 0);
IO.Position = Position0 - (Header.IsX ? 8 : 4);
IO.Write(Position1);
if (IO.Format > Main.Format.F)
if (Format > Main.Format.F)
{
Offset = IO.Length - Header.Lenght;
IO.Seek(IO.Length, 0);
Offset = IO.Length;
IO.Offset = 0;
IO.Position = IO.Length;
IO.WriteEOFC(0);
IO.Seek(0, 0);
IO.Position = 0;
Header.DataSize = Offset;
Header.SectionSize = Offset;
IO.Write(Header);
Header.Signature = 0x43505845;
IO.Write(Header, true);
}
IO.Close();
}
@@ -197,29 +180,26 @@ namespace KKdMainLib
Header = new PDHead();
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
if (!MsgPack.Element<MsgPack>("Dex", out MsgPack Dex)) return;
if (!MsgPack.ElementArray("Dex", out MsgPack Dex)) return;
this.Dex = new EXP[Dex.Array.Length];
for (i0 = 0; i0 < this.Dex.Length; i0++)
if (Dex[i0] is MsgPack EXP)
{
this.Dex[i0] = new EXP { Name = EXP.ReadString("Name") };
{
this.Dex[i0] = new EXP { Name = Dex[i0].ReadString("Name") };
if (EXP.Element<MsgPack>("Main", out MsgPack Main))
{
this.Dex[i0].Main = new List<EXPElement>();
for (i1 = 0; i1 < Main.Array.Length; i1++)
if (Main[i1] is MsgPack Exp)
this.Dex[i0].Main.Add(ReadEXP(Exp));
}
if (EXP.Element<MsgPack>("Eyes", out MsgPack Eyes))
{
this.Dex[i0].Eyes = new List<EXPElement>();
for (i1 = 0; i1 < Eyes.Array.Length; i1++)
if (Eyes[i1] is MsgPack Exp)
this.Dex[i0].Eyes.Add(ReadEXP(Exp));
}
if (Dex[i0].ElementArray("Main", out MsgPack Main))
{
this.Dex[i0].Main = new List<EXPElement>();
for (i1 = 0; i1 < Main.Array.Length; i1++)
this.Dex[i0].Main.Add(ReadEXP(Main[i1]));
}
if (Dex[i0].ElementArray("Eyes", out MsgPack Eyes))
{
this.Dex[i0].Eyes = new List<EXPElement>();
for (i1 = 0; i1 < Eyes.Array.Length; i1++)
this.Dex[i0].Eyes.Add(ReadEXP(Eyes[i1]));
}
}
MsgPack = MsgPack.New;
}
+3 -1
View File
@@ -7,7 +7,9 @@ namespace KKdMainLib
{
public static class DIVAFILE
{
private static readonly byte[] Key = "file access deny".ToASCII();
private static readonly byte[] Key = new byte[]
{ 0x66, 0x69, 0x6C, 0x65, 0x20, 0x61, 0x63, 0x63,
0x65, 0x73, 0x73, 0x20, 0x64, 0x65, 0x6E, 0x79 };
public static void Decrypt(this string file)
{
+55 -32
View File
@@ -7,7 +7,7 @@ namespace KKdMainLib
{
public class DataBank
{
public DataBank() { Success = false; IO = null; pvList = null; }
public DataBank() { Success = false; IO = null; pvList = null; psrDat = null; }
private Stream IO;
private int i;
@@ -34,12 +34,14 @@ namespace KKdMainLib
for (i = 0; i < psrDat.Length; i++) psrDat[i].SetValue(array, i);
Success = true;
}
else if (file.Contains("psrData")) { psrDat = null; Success = true; }
else if (file.Contains("PvList") && array.Length % 7 < 2)
{
pvList = new PvList[array.Length / 7];
for (i = 0; i < pvList.Length; i++) pvList[i].SetValue(array, i);
Success = true;
}
else if (file.Contains("PvList")) { pvList = null; Success = true; }
}
public void DBWriter(string file)
@@ -48,14 +50,19 @@ namespace KKdMainLib
IO = File.OpenWriter();
if (file.Contains("psrData"))
for (i = 0; i < psrDat.Length; i++)
IO.Write(psrDat[i].ToString() + ",");
{
if (psrDat != null || psrDat.Length > 0)
for (i = 0; i < psrDat.Length; i++)
IO.Write(psrDat[i].ToString() + c);
}
else if (file.Contains("PvList"))
if (pvList.Length != 0)
{
if (pvList != null || pvList.Length > 0)
for (i = 0; i < pvList.Length; i++)
IO.Write(UrlEncode(pvList[i].ToString() +
((i + 1 != pvList.Length) ? "," : "")));
else IO.Write("%2A%2A%2A");
(i < pvList.Length ? c : "")));
}
else IO.Write("%2A%2A%2A");
byte[] data = IO.ToArray(true);
@@ -70,20 +77,29 @@ namespace KKdMainLib
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
bool compact = MsgPack.ReadBoolean("Compact");
if (file.Contains("psrData") && MsgPack.Element<MsgPack>("psrData", out MsgPack psrData))
if (file.Contains("psrData"))
{
psrDat = new psrData[psrData.Array.Length];
for (i = 0; i < psrDat.Length; i++)
psrDat[i].SetValue((MsgPack)psrData[i]);
if (MsgPack.ElementArray("psrData", out MsgPack psrData))
{
psrDat = new psrData[psrData.Array.Length];
for (i = 0; i < psrDat.Length; i++)
psrDat[i].SetValue(psrData[i]);
}
else if (MsgPack.ContainsKey("psrData")) psrDat = null;
Success = true;
}
else if (file.Contains("PvList") && MsgPack.Element<MsgPack>("PvList", out MsgPack PvList))
else if (file.Contains("PvList"))
{
pvList = new PvList[PvList.Array.Length];
for (i = 0; i < pvList.Length; i++)
pvList[i].SetValue((MsgPack)PvList[i], compact);
if (MsgPack.ElementArray("PvList", out MsgPack PvList))
{
pvList = new PvList[PvList.Array.Length];
for (i = 0; i < pvList.Length; i++)
pvList[i].SetValue(PvList[i], compact);
}
else if (MsgPack.ContainsKey("PvList")) pvList = null;
Success = true;
}
MsgPack = MsgPack.New;
}
@@ -94,17 +110,25 @@ namespace KKdMainLib
if (file.Contains("psrData"))
{
MsgPack psrData = new MsgPack(psrDat.Length, "psrData");
for (i = 0; i < psrDat.Length; i++) psrData[i] = psrDat[i].WriteMP();
msgPack.Add(psrData);
if (psrDat != null)
{
MsgPack psrData = new MsgPack(psrDat.Length, "psrData");
for (i = 0; i < psrDat.Length; i++) psrData[i] = psrDat[i].WriteMP();
msgPack.Add(psrData);
}
else msgPack.Add(new MsgPack("psrData", null));
}
else if (file.Contains("PvList"))
{
if (Compact) msgPack.Add("Compact", Compact);
if (psrDat != null)
{
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 PvList = new MsgPack(pvList.Length, "PvList");
for (i = 0; i < pvList.Length; i++) PvList[i] = pvList[i].WriteMP(Compact);
msgPack.Add(PvList);
}
else msgPack.Add(new MsgPack("PvList", null));
}
msgPack.Write(file, JSON).Dispose();
}
@@ -112,7 +136,6 @@ namespace KKdMainLib
public static string UrlEncode(string value) =>
WebUtility.UrlEncode(value).Replace("+", "%20");
public struct psrData
{
public Player p1;
@@ -143,7 +166,7 @@ namespace KKdMainLib
.Add(p2.WriteMP("P2")).Add(p3.WriteMP("P3"));
public override string ToString() =>
UrlEncode(p1.ToString() + "," + p2.ToString() + "," + p3.ToString() + "," + PV_ID);
UrlEncode(p1.ToString() + c + p2.ToString() + c + p3.ToString() + c + PV_ID);
}
public struct Player
@@ -200,9 +223,9 @@ namespace KKdMainLib
.Add("Score" , Score0).Add("Name" , Name0);
public override string ToString() =>
(Score0 + (Has2P ? ("." + Score1) : "") + "," + UrlEncode(Name0) +
(Has2P ? ("xxx" + UrlEncode(Name1)) : "") + "," +
Diff + "," + (Has2P ? "0.1" : "0")).Replace("*", "%2A");
(Score0 + (Has2P ? (d + Score1) : "") + c + UrlEncode(Name0) +
(Has2P ? ("xxx" + UrlEncode(Name1)) : "") + c +
Diff + c + (Has2P ? "0.1" : "0")).Replace("*", "%2A");
}
public struct PvList
@@ -237,8 +260,8 @@ namespace KKdMainLib
else { ID = msg.ReadNInt32("ID"); if (ID != null) PV_ID = (int)ID; }
bool? Enable = msg.ReadNBoolean("Enable");
bool? Extra = msg.ReadNBoolean("Extra");
if (Enable == null) this.Enable = (bool)Enable;
if (Extra == null) this.Extra = (bool)Extra ;
if (Enable != null) this.Enable = (bool)Enable;
if (Extra != null) this.Extra = (bool)Extra ;
if (Compact)
{
AdvDemoStart.SetValue(msg.ReadNInt32("AdvDemoStart"), true);
@@ -256,7 +279,7 @@ namespace KKdMainLib
public MsgPack WriteMP(bool Compact)
{
MsgPack msgPack = MsgPack.New;
msgPack.Add("PV_ID", PV_ID);
msgPack.Add("ID", PV_ID);
if (!Enable) msgPack.Add("Enable", Enable);
if ( Extra ) msgPack.Add("Extra" , Extra );
if (Compact)
@@ -277,9 +300,9 @@ namespace KKdMainLib
}
public override string ToString() =>
UrlEncode(PV_ID + "," + (Enable ? 1 : 0) + "," + (Extra ? 1 : 0) + "," +
AdvDemoStart.ToString() + "," + AdvDemoEnd.ToString() + "," +
StartShow.ToString() + "," + EndShow.ToString());
UrlEncode(PV_ID + c + (Enable ? 1 : 0) + c + (Extra ? 1 : 0) + c +
AdvDemoStart.ToString() + c + AdvDemoEnd.ToString() + c +
StartShow.ToString() + c + EndShow.ToString());
}
public struct Date
+82 -87
View File
@@ -1,6 +1,5 @@
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
using System;
using System.IO.Compression;
using System.Security.Cryptography;
using KKdMainLib.IO;
@@ -20,6 +19,7 @@ namespace KKdMainLib
public Type FARCType;
public Farc Signature = Farc.FArC;
public string FilePath, DirectoryPath;
public bool HasFiles => Files == null ? false : Files.Length > 0;
private bool CBC, FT;
@@ -37,23 +37,18 @@ namespace KKdMainLib
}
public void UnPack(bool SaveToDisk = true)
{
HeaderReader().FileReader();
if (SaveToDisk) this.SaveToDisk();
}
{ if (HeaderReader()) { FileReader(); if (SaveToDisk) this.SaveToDisk(); } }
private FARC HeaderReader()
public bool HeaderReader()
{
NewFARC();
Console.Title = "FARC Extractor - Archive: " + Path.GetFileName(FilePath);
if (!File.Exists(FilePath))
{ Console.WriteLine("File {0} doesn't exist.", Path.GetFileName(FilePath)); return this; }
if (!File.Exists(FilePath)) return false;
Stream reader = File.OpenReader(FilePath);
DirectoryPath = Path.GetFullPath(FilePath).Replace(Path.GetExtension(FilePath), "");
Signature = (Farc)reader.ReadInt32Endian(true);
if (Signature != Farc.FArc && Signature != Farc.FArC && Signature != Farc.FARC)
{ Console.WriteLine("Unknown signature"); reader.Close(); return this; }
{ reader.Close(); return false; }
int HeaderLength = reader.ReadInt32Endian(true);
if (Signature == Farc.FARC)
@@ -116,78 +111,76 @@ namespace KKdMainLib
}
reader.Close();
return this;
return true;
}
private FARC FileReader()
private void FileReader()
{ for (int i = 0; i < Files.Length; i++) FileReader(i); }
public byte[] FileReader(int i)
{
if (Files == null) return this;
if (Files.Length < 1) return this;
if (!HasFiles) return null;
if (i >= Files.Length) return null;
if (Signature != Farc.FARC)
{
for (int i = 0; i < Files.Length; i++)
if (Signature == Farc.FArC)
using (MSIO.MemoryStream memorystream = new MSIO.MemoryStream(
File.ReadAllBytes(FilePath, Files[i].SizeComp, Files[i].Offset)))
{
GZipStream gZipStream = new GZipStream(memorystream, CompressionMode.Decompress);
Files[i].Data = new byte[Files[i].SizeUnc];
gZipStream.Read(Files[i].Data, 0, Files[i].SizeUnc);
}
else Files[i].Data = File.ReadAllBytes(FilePath, Files[i].SizeUnc, Files[i].Offset);
return this;
}
for (int i = 0; i < Files.Length; i++)
{
int FileSize = FARCType.HasFlag(Type.ECB) || Files[i].Type.HasFlag(Type.ECB) ?
Files[i].SizeComp.Align(0x10) : Files[i].SizeComp;
MSIO.FileStream stream = new MSIO.FileStream(FilePath, MSIO.FileMode.Open,
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite);
stream.Seek(Files[i].Offset, 0);
Files[i].Data = new byte[FileSize];
bool Encrypted = false;
if (FARCType.HasFlag(Type.ECB))
{
if ((FT && Files[i].Type.HasFlag(Type.ECB)) || CBC)
if (Signature == Farc.FArC)
using (MSIO.MemoryStream memorystream = new MSIO.MemoryStream(
File.ReadAllBytes(FilePath, Files[i].SizeComp, Files[i].Offset)))
{
using (CryptoStream cryptoStream = new CryptoStream(stream,
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
cryptoStream.Read(Files[i].Data, 0, FileSize);
Files[i].Data = SkipData(Files[i].Data, 0x10);
GZipStream gZipStream = new GZipStream(memorystream, CompressionMode.Decompress);
Files[i].Data = new byte[Files[i].SizeUnc];
gZipStream.Read(Files[i].Data, 0, Files[i].SizeUnc);
}
else if (Files[i].Type.HasFlag(Type.ECB))
using (CryptoStream cryptoStream = new CryptoStream(stream,
GetAes(false, null).CreateDecryptor(), CryptoStreamMode.Read))
cryptoStream.Read(Files[i].Data, 0, FileSize);
else stream.Read(Files[i].Data, 0, FileSize);
Encrypted = true;
}
bool Compressed = false;
if (((FT && Files[i].Type.HasFlag(Type.GZip)) ||
FARCType.HasFlag(Type.GZip)) && Files[i].SizeUnc > 0)
{
GZipStream gZipStream;
if (Encrypted) { gZipStream = new GZipStream(new MSIO.MemoryStream(Files[i].Data),
CompressionMode.Decompress); stream.Close(); }
else gZipStream = new GZipStream(stream, CompressionMode.Decompress);
byte[] Temp = new byte[Files[i].SizeUnc];
gZipStream.Read(Temp, 0, Files[i].SizeUnc);
Files[i].Data = Temp;
Compressed = true;
}
if (!Encrypted && !Compressed)
{
Files[i].Data = new byte[Files[i].SizeUnc];
stream.Read(Files[i].Data, 0, Files[i].SizeUnc);
stream.Close();
}
else Files[i].Data = File.ReadAllBytes(FilePath, Files[i].SizeUnc, Files[i].Offset);
return Files[i].Data;
}
return this;
int FileSize = FARCType.HasFlag(Type.ECB) || Files[i].Type.HasFlag(Type.ECB) ?
Files[i].SizeComp.Align(0x10) : Files[i].SizeComp;
MSIO.FileStream stream = new MSIO.FileStream(FilePath, MSIO.FileMode.Open,
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite);
stream.Seek(Files[i].Offset, 0);
Files[i].Data = new byte[FileSize];
bool Encrypted = false;
if (FARCType.HasFlag(Type.ECB))
{
if ((FT && Files[i].Type.HasFlag(Type.ECB)) || CBC)
{
using (CryptoStream cryptoStream = new CryptoStream(stream,
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
cryptoStream.Read(Files[i].Data, 0, FileSize);
Files[i].Data = SkipData(Files[i].Data, 0x10);
}
else
using (CryptoStream cryptoStream = new CryptoStream(stream,
GetAes(false, null).CreateDecryptor(), CryptoStreamMode.Read))
cryptoStream.Read(Files[i].Data, 0, FileSize);
Encrypted = true;
}
bool Compressed = false;
if (((FT && Files[i].Type.HasFlag(Type.GZip)) ||
FARCType.HasFlag(Type.GZip)) && Files[i].SizeUnc > 0)
{
GZipStream gZipStream;
if (Encrypted) { gZipStream = new GZipStream(new MSIO.MemoryStream(Files[i].Data),
CompressionMode.Decompress); stream.Close(); }
else gZipStream = new GZipStream(stream, CompressionMode.Decompress);
byte[] Temp = new byte[Files[i].SizeUnc];
gZipStream.Read(Temp, 0, Files[i].SizeUnc);
Files[i].Data = Temp;
Compressed = true;
}
if (!Encrypted && !Compressed)
{
Files[i].Data = new byte[Files[i].SizeUnc];
stream.Read(Files[i].Data, 0, Files[i].SizeUnc);
stream.Close();
}
return Files[i].Data;
}
private void SaveToDisk()
@@ -197,7 +190,8 @@ namespace KKdMainLib
MSIO.Directory.CreateDirectory(DirectoryPath);
for (int i = 0; i < Files.Length; i++)
{
File.WriteAllBytes(Path.Combine(DirectoryPath, Files[i].Name), Files[i].Data);
if (Files[i].Data != null)
File.WriteAllBytes(Path.Combine(DirectoryPath, Files[i].Name), Files[i].Data);
Files[i].Data = null;
}
}
@@ -214,14 +208,19 @@ namespace KKdMainLib
NewFARC();
string[] files = Directory.GetFiles(DirectoryPath);
Files = new FARCFile[files.Length];
for (int i = 0; i < files.Length; i++)
Files[i] = new FARCFile { Name = Path.GetFileName(files[i]), Data = File.ReadAllBytes(files[i]) };
files = null;
Save();
}
public void Save()
{
for (int i = 0; i < Files.Length; i++)
{
Files[i] = new FARCFile { Name = files[i] };
string ext = Path.GetExtension(files[i]).ToLower();
string ext = Path.GetExtension(Files[i].Name).ToLower();
if (ext == ".a3da" || ext == ".diva" || ext == ".vag") Signature = Farc.FArc;
}
files = null;
Stream writer = File.OpenWriter(DirectoryPath + ".farc", true);
writer.WriteEndian((int)Signature, true);
@@ -233,7 +232,7 @@ namespace KKdMainLib
{
HeaderWriter.WriteEndian((int)FARCType, true);
HeaderWriter.Write (0x00);
HeaderWriter.WriteEndian(0x40 , true);
HeaderWriter.WriteEndian(0x40, true);
HeaderWriter.Write (0x00);
}
int HeaderPartLength = Signature == Farc.FArc ? 0x09 : 0x0D;
@@ -245,14 +244,12 @@ namespace KKdMainLib
int Align = writer.Position.Align(0x10) - writer.Position;
for (int i1 = 0; i1 < Align; i1++)
if (Signature == Farc.FArc) writer.WriteByte(0x00);
else writer.WriteByte(0x78);
writer.WriteByte((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
for (int i = 0; i < Files.Length; i++)
CompressStuff(i, ref Files, ref writer);
if (Signature == Farc.FARC) writer.Position = 0x1C;
else writer.Position = 0x0C;
writer.Position = Signature == Farc.FARC ? 0x1C : 0x0C;
for (int i = 0; i < Files.Length; i++)
{
writer.Write(Path.GetFileName(Files[i].Name) + "\0");
@@ -267,7 +264,6 @@ namespace KKdMainLib
private void CompressStuff(int i, ref FARCFile[] Files, ref Stream writer)
{
Files[i].Offset = writer.Position;
Files[i].Data = File.ReadAllBytes(Files[i].Name);
Files[i].SizeUnc = Files[i].Data.Length;
Files[i].Type = Type.None;
@@ -299,8 +295,7 @@ namespace KKdMainLib
{
int Align = writer.Position.Align(0x20) - writer.Position;
for (int i1 = 0; i1 < Align; i1++)
if (Signature == Farc.FArc) writer.WriteByte(0x00);
else writer.WriteByte(0x78);
writer.WriteByte((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
}
}
+2 -2
View File
@@ -5,7 +5,7 @@ namespace KKdMainLib.IO
{
public static class File
{
public static Stream OpenReader(byte[] Data) => new Stream(new MSIO.MemoryStream(Data), Data);
public static Stream OpenReader(byte[] Data) => new Stream(new MSIO.MemoryStream(Data));
public static Stream OpenWriter( ) => new Stream(new MSIO.MemoryStream( ));
public static Stream OpenReader(string file, bool ReadAllAtOnce)
@@ -14,7 +14,7 @@ namespace KKdMainLib.IO
{ Stream IO = new Stream(new MSIO.FileStream(file, MSIO.FileMode.Open, MSIO.FileAccess.ReadWrite,
MSIO.FileShare.ReadWrite)) { File = file }; return IO; }
public static Stream OpenWriter(string file, bool SetLength0)
{ Stream IO = OpenWriter(file); IO.SetLength(0 ); return IO; }
{ Stream IO = OpenWriter(file); if (SetLength0) IO.SetLength(0); return IO; }
public static Stream OpenWriter(string file, int SetLength)
{ Stream IO = OpenWriter(file); IO.SetLength(SetLength); return IO; }
public static Stream OpenWriter(string file)
+7
View File
@@ -43,6 +43,13 @@ namespace KKdMainLib.IO
public static long ReadIntX(this Stream stream, bool IsBE) => stream.IsX ?
stream.ReadInt64() : stream.ReadUInt32Endian(IsBE);
public static void WriteX(this Stream stream, long val)
{ if (stream.IsX) stream.Write ( val);
else stream.WriteEndian((int)val); }
public static void WriteX(this Stream stream, long val, bool IsBE)
{ if (stream.IsX) stream.Write ( val );
else stream.WriteEndian((int)val, IsBE); }
public static byte[] ReadAtOffset(this Stream stream, long Offset = 0, long Length = 0)
{
byte[] arr = null;
+36 -27
View File
@@ -11,7 +11,6 @@ namespace KKdMainLib.IO
private ushort ValRead;
private byte BitRead, BitWrite, ValWrite;
private byte[] buf;
private byte[] data;
private Main.Format _format = Main.Format.NULL;
@@ -28,9 +27,9 @@ namespace KKdMainLib.IO
public uint UIntOffset { get => (uint)LongOffset; set => LongOffset = value; }
public long LongOffset;
public int Length { get => ( int)stream.Length; set => stream.SetLength(value); }
public uint UIntLength { get => (uint)stream.Length; set => stream.SetLength(value); }
public long LongLength { get => stream.Length; set => stream.SetLength(value); }
public int Length { get => ( int)stream.Length - Offset; set => stream.SetLength(value + Offset); }
public uint UIntLength { get => (uint)stream.Length - UIntOffset; set => stream.SetLength(value + UIntOffset); }
public long LongLength { get => stream.Length - LongOffset; set => stream.SetLength(value + LongOffset); }
public int Position
{ get => ( int)stream.Position - Offset; set => stream.Position = value + Offset; }
@@ -46,7 +45,7 @@ namespace KKdMainLib.IO
public string File = null;
public Stream(MSIO.Stream output = null, byte[] Data = null, bool isBE = false)
public Stream(MSIO.Stream output = null, bool isBE = false)
{
if (output == null) output = MSIO.Stream.Null;
LongOffset = 0;
@@ -56,7 +55,6 @@ namespace KKdMainLib.IO
Format = Main.Format.NULL;
buf = new byte[128];
IsBE = isBE;
data = Data;
}
public void Close() => Dispose();
@@ -75,7 +73,7 @@ namespace KKdMainLib.IO
{ CheckWrited(); Dispose(true); }
private void Dispose(bool disposing)
{ if (disposing && stream != MSIO.Stream.Null) stream.Flush(); stream.Dispose(); data = null; }
{ if (disposing && stream != MSIO.Stream.Null) stream.Flush(); stream.Dispose(); }
public MSIO.Stream BaseStream
{ get { stream.Flush(); return stream; } set { stream = value; } }
@@ -84,23 +82,23 @@ namespace KKdMainLib.IO
{
long Al = Align - Position % Align;
if (Position % Align != 0)
stream.Seek(Position + Al, 0);
stream.Seek(Position + Offset + Al, 0);
}
public void Align(long Align, bool SetLength)
{
if (SetLength) stream.SetLength(Position);
if (SetLength) stream.SetLength(Position + Offset);
long Al = Align - Position % Align;
if (Position % Align != 0) stream.Seek(Position + Al, 0);
if (SetLength) stream.SetLength(Position);
if (Position % Align != 0) stream.Seek(Position + Offset + Al, 0);
if (SetLength) stream.SetLength(Position + Offset);
}
public void Align(long Align, bool SetLength0, bool SetLength1)
{
if (SetLength0) stream.SetLength(Position);
if (SetLength0) stream.SetLength(Position + Offset);
long Al = Align - Position % Align;
if (Position % Align != 0) stream.Seek(Position + Al, 0);
if (SetLength1) stream.SetLength(Position);
if (SetLength1) stream.SetLength(Position + Offset);
}
public bool ReadBoolean() => stream.ReadByte() == 1;
@@ -176,17 +174,28 @@ namespace KKdMainLib.IO
public void Write( float? val) => Write(val.GetValueOrDefault());
public void Write(double? val) => Write(val.GetValueOrDefault());
public void Write( bool* val, int Length) { for (i = 0; i < Length; i++) stream.WriteByte((byte)(val[i] ? 1 : 0)); }
public void Write( sbyte* val, int Length) { for (i = 0; i < Length; i++) stream.WriteByte((byte) val[i]); }
public void Write( byte* val, int Length) { for (i = 0; i < Length; i++) stream.WriteByte( val[i]); }
public void Write( short* val, int Length) { for (i = 0; i < Length; i++) ToArray(2, val[i]); }
public void Write(ushort* val, int Length) { for (i = 0; i < Length; i++) ToArray(2, val[i]); }
public void Write( int* val, int Length) { for (i = 0; i < Length; i++) ToArray(4, val[i]); }
public void Write( uint* val, int Length) { for (i = 0; i < Length; i++) ToArray(4, val[i]); }
public void Write( long* val, int Length) { for (i = 0; i < Length; i++) ToArray(8, val[i]); }
public void Write( ulong* val, int Length) { for (i = 0; i < Length; i++) ToArray(8, val[i]); }
public void Write( float* val, int Length) { for (i = 0; i < Length; i++) ToArray(4, *( uint*)&val[i]); }
public void Write(double* val, int Length) { for (i = 0; i < Length; i++) ToArray(4, *(ulong*)&val[i]); }
public void Write( bool* val, int Length)
{ for (i = 0; i < Length; i++) stream.WriteByte((byte)(val[i] ? 1 : 0)); }
public void Write( sbyte* val, int Length)
{ for (i = 0; i < Length; i++) stream.WriteByte((byte) val[i]); }
public void Write( byte* val, int Length)
{ for (i = 0; i < Length; i++) stream.WriteByte( val[i]); }
public void Write( short* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(2, val[i]); }
public void Write(ushort* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(2, val[i]); }
public void Write( int* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(4, val[i]); }
public void Write( uint* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(4, val[i]); }
public void Write( long* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(8, val[i]); }
public void Write( ulong* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(8, val[i]); }
public void Write( float* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(4, *( uint*)&val[i]); }
public void Write(double* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(4, *(ulong*)&val[i]); }
public void WriteEndian( short* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(2, Endian(val[i], 2, IsBE)); }
@@ -364,10 +373,10 @@ namespace KKdMainLib.IO
public byte[] ToArray()
{
long Offset = stream.Position;
LongPosition = 0;
long Position = stream.Position;
stream.Position = 0;
byte[] Data = ReadBytes(stream.Length);
LongPosition = Offset;
stream.Position = Position;
return Data;
}
}
+7 -5
View File
@@ -22,6 +22,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -33,12 +35,10 @@
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="A3DA\A3DAExt.cs" />
<Compile Include="A3DA\A3DA.cs" />
<Compile Include="Aet\Aet.cs" />
<Compile Include="Aet\AetExt.cs" />
<Compile Include="DB\Aet.cs" />
<Compile Include="DB\Auth.cs" />
<Compile Include="DB\Spr.cs" />
@@ -52,10 +52,12 @@
<Compile Include="MessagePack\MsgPack.cs" />
<Compile Include="MessagePack\IO.cs" />
<Compile Include="Types\Half.cs" />
<Compile Include="Types\KeyFrame.cs" />
<Compile Include="Types\IKeyFrame.cs" />
<Compile Include="Types\KKdList.cs" />
<Compile Include="Types\Pointer.cs" />
<Compile Include="Types\Vector.cs" />
<Compile Include="A3DA.cs" />
<Compile Include="Aet.cs" />
<Compile Include="DataBank.cs" />
<Compile Include="DCC.cs" />
<Compile Include="DEX.cs" />
+12 -15
View File
@@ -80,8 +80,9 @@ namespace KKdMainLib
OpenFileDialog ofd = new OpenFileDialog { InitialDirectory = Application.StartupPath,
Multiselect = true, Title = "Choose file(s) to open:" };
if (filetype == "a3da") ofd.Filter = GetArgs("A3DA", "a3da", "json", "mp") +
GetArgs("A3DA", true, "a3da") + JSON + MsgPack;
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;
else if (filetype == "bin" ) ofd.Filter = GetArgs("BIN" , "bin", "json", "mp") +
BIN + JSON + MsgPack;
else if (filetype == "bon" ) ofd.Filter = GetArgs("BON" , "bon", "bin", "json", "mp") +
@@ -106,7 +107,6 @@ namespace KKdMainLib
GetArgs("STR", true, "str") + BIN + JSON + MsgPack;
else if (filetype == "vag" ) ofd.Filter = GetArgs("VAG", "vag", "wav") +
GetArgs("VAG", true, "vag") + GetArgs("WAV", true, "wav");
else ofd.Filter = GetArgs("All;", false, "*");
if (ofd.ShowDialog() == DialogResult.OK)
FileNames = ofd.FileNames;
@@ -122,7 +122,7 @@ namespace KKdMainLib
return "";
}
public static void ChooseSave(int code, string filetype,
public static void ChooseSave(string filetype,
out string InitialDirectory, out string[] FileNames)
{
InitialDirectory = "";
@@ -179,24 +179,21 @@ namespace KKdMainLib
}
public static bool FindValue(this Dictionary<string, object> Dict,
ref bool value, char Split, string args)
{ if (Dict.FindValue(out string val, args.Split(Split)))
return bool.TryParse(val, out value); return false; }
ref bool value, char Split, string args) =>
Dict.FindValue(out string val, args.Split(Split)) ? bool.TryParse(val, out value) : false;
public static bool FindValue(this Dictionary<string, object> Dict,
ref int value, char Split, string args)
{ if (Dict.FindValue(out string val, args.Split(Split)))
return int.TryParse(val, out value); return false; }
ref int value, char Split, string args) =>
Dict.FindValue(out string val, args.Split(Split)) ? int.TryParse(val, out value) : false;
public static bool FindValue(this Dictionary<string, object> Dict,
ref double value, char Split, string args)
{ if (Dict.FindValue(out string val, args.Split(Split)))
return val.ToDouble(out value); return false; }
ref double value, char Split, string args) =>
Dict.FindValue(out string val, args.Split(Split)) ? val.ToDouble( out value) : false;
public static bool FindValue(this Dictionary<string, object> Dict,
ref string value, char Split, string args)
{ if (Dict.FindValue(out string val, args.Split(Split)))
{ value = val; return true; } return false; }
{ value = val; return true; } return false; }
public static bool FindValue(this Dictionary<string, object> Dict,
out bool value, string args)
@@ -217,7 +214,7 @@ namespace KKdMainLib
out int? value, string args)
{ if (Dict.FindValue(out string val, args.Split('.' )))
{ bool Val = int.TryParse(val, out int _value);
value = _value; return Val; } value = null; return false; }
value = _value; return Val; } value = null; return false; }
public static bool FindValue(this Dictionary<string, object> Dict,
out double? value, string args)
+38 -8
View File
@@ -4,13 +4,45 @@ namespace KKdMainLib
{
public static class MathExtensions
{
public static void FloorCeiling(ref double Value)
{ if (Value % 1 >= 0.5) Value = (long)(Value + 0.5);
else Value = (long) Value; }
private const double RadPi = 180 / Math.PI;
public static double ToDegrees(this double val) => val * RadPi;
public static double ToRadians(this double val) => val / RadPi;
public static long FloorCeiling(this double Value)
{ if (Value % 1 >= 0.5) return (long)(Value + 0.5);
else return (long) Value; }
public static double Acos (this double d ) => Math.Acos (d );
public static double Asin (this double d ) => Math.Asin (d );
public static double Atan (this double d ) => Math.Atan (d );
public static double Aсtg (this double d ) => 1 / Math.Atan (d );
public static double Cos (this double d ) => Math.Cos (d );
public static double Cosh (this double val) => Math.Cosh (val);
public static double Sin (this double a ) => Math.Sin (a );
public static double Sinh (this double val) => Math.Sinh (val);
public static double Tan (this double a ) => Math.Tan (a );
public static double Tanh (this double val) => Math.Tanh (val);
public static double Ctg (this double a ) => 1 / Math.Tan (a );
public static double Ctgh (this double val) => 1 / Math.Tanh (val);
public static double Abs (this double val) => Math.Abs (val);
public static double Ceiling(this double a ) => Math.Ceiling(a );
public static double Exp (this double d ) => Math.Exp (d );
public static double Log (this double d ) => Math.Log (d );
public static double Log10 (this double d ) => Math.Log10 (d );
public static double Round (this double d ) => Math.Round (d );
public static int Sign (this double val) => Math.Sign (val);
public static double Sqrt (this double d ) => Math.Sqrt (d );
public static double Atan2(this double y , double x ) => Math.Atan2(y , x );
public static double Log (this double val , double newBase) => Math.Log (val , newBase);
public static double Max (this double val1, double val2 ) => Math.Max (val1, val2 );
public static double Min (this double val1, double val2 ) => Math.Min (val1, val2 );
public static double Pow (this double x , double y ) => Math.Pow (x , y );
public static double Round(this double val , int d ) => Math.Round(val , d );
public static void FloorCeiling( ref double Value) =>
Value = Value % 1 >= 0.5 ? (long)(Value + 0.5) : (long) Value;
public static long FloorCeiling(this double Value) =>
Value % 1 >= 0.5 ? (long)(Value + 0.5) : (long) Value;
public static int Align(this int value, int alignement, int divide = 1) =>
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
@@ -161,8 +193,6 @@ namespace KKdMainLib
return (uint)c;
}
public static double Round(this double c) => Math.Round(c);
public static unsafe sbyte* GetPtr(this sbyte[] array)
{ sbyte* Ptr; fixed ( sbyte* tempPtr = array) Ptr = tempPtr; return Ptr; }
+11 -12
View File
@@ -13,6 +13,8 @@ namespace KKdMainLib.MessagePack
public void Close() => _IO.Close();
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
public MsgPack Read(bool Array = false)
{
MsgPack MsgPack = MsgPack.New;
@@ -33,12 +35,12 @@ namespace KKdMainLib.MessagePack
{
if (FixMap)
{
MsgPack.Object = KKdList<object>.New;
MsgPack.Object = KKdList<MsgPack>.New;
for (int i = 0; i < Unk - (byte)Types.FixMap; i++) MsgPack.Add( Read(false));
}
else if (FixArr)
{
MsgPack.Object = new object[Unk - (byte)Types.FixArr];
MsgPack.Object = new MsgPack[Unk - (byte)Types.FixArr];
for (int i = 0; i < Unk - (byte)Types.FixArr; i++) MsgPack[i] = Read( true);
}
else if (FixStr) MsgPack.Object = ReadString( Type);
@@ -129,7 +131,7 @@ namespace KKdMainLib.MessagePack
int Length = 0;
if (Type == Types.Str8 ) Length = _IO.ReadByte();
else if (Type == Types.Str16) Length = _IO.ReadInt16Endian(true);
else Length = _IO.ReadInt32Endian(true);
else Length = _IO.ReadInt32Endian(true);
return _IO.ReadString(Length);
}
return null;
@@ -148,7 +150,7 @@ namespace KKdMainLib.MessagePack
if (Type == Types.Arr16) Length = _IO.ReadInt16Endian(true);
else if (Type == Types.Arr32) Length = _IO.ReadInt32Endian(true);
else return false;
MsgPack.Object = new object[Length];
MsgPack.Object = new MsgPack[Length];
for (int i = 0; i < Length; i++) MsgPack[i] = Read(true);
return true;
}
@@ -159,7 +161,7 @@ namespace KKdMainLib.MessagePack
if (Type == Types.Map16) Length = _IO.ReadInt16Endian(true);
else if (Type == Types.Map32) Length = _IO.ReadInt32Endian(true);
else return false;
MsgPack.Object = KKdList<object>.New;
MsgPack.Object = KKdList<MsgPack>.New;
for (int i = 0; i < Length; i++) MsgPack.Add(Read());
return true;
}
@@ -179,13 +181,10 @@ namespace KKdMainLib.MessagePack
MsgPack.Object = new MsgPack.Ext { Type = _IO.ReadSByte(), Data = _IO.ReadBytes(Length) };
return true;
}
public IO Write(MsgPack MsgPack, bool Close)
{ Write(MsgPack); if (Close) this.Close(); return this; }
public IO Write(MsgPack MsgPack)
public IO Write(MsgPack MsgPack, bool IsArray = false)
{
if (MsgPack.Name != null) Write(MsgPack.Name);
if (MsgPack.Name != null && !IsArray) Write(MsgPack.Name);
Write(MsgPack.Object);
return this;
}
@@ -195,9 +194,9 @@ namespace KKdMainLib.MessagePack
if (obj == null) { WriteNil(); return; }
switch (obj)
{
case KKdList<object> val: WriteMap(val.Count );
case KKdList<MsgPack> val: WriteMap(val.Count );
for (int i = 0; i < val.Count ; i++) Write(val[i]); break;
case object[] val: WriteArr(val.Length);
case MsgPack[] val: WriteArr(val.Length);
for (int i = 0; i < val.Length; i++) Write(val[i]); break;
case MsgPack val: Write(val); break;
case byte[] val: Write(val); break;
+45 -32
View File
@@ -1,6 +1,5 @@
//Original or reader part: https://github.com/MarcosLopezC/LightJson/
using System;
using KKdMainLib.IO;
using KKdMainLib.Types;
@@ -15,9 +14,9 @@ namespace KKdMainLib.MessagePack
public void Close() => _IO.Close();
public MsgPack Read() => ReadValue();
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
private string ReadKey() => ReadString();
public MsgPack Read() => ReadValue();
private MsgPack ReadValue(string Key = null)
{
@@ -80,11 +79,11 @@ namespace KKdMainLib.MessagePack
private int ReadHexDigit() => byte.Parse(_IO.ReadCharUTF8().ToString(),
System.Globalization.NumberStyles.HexNumber);
private KKdList<object> ReadObject()
private KKdList<MsgPack> ReadObject()
{
KKdList<object> Obj = KKdList<object>.New;
if (!_IO.Assert('{')) return KKdList<object>.Null;
if (_IO.SkipWhitespace().PeekCharUTF8() == '}') { _IO.ReadCharUTF8(); return KKdList<object>.Null; }
KKdList<MsgPack> Obj = KKdList<MsgPack>.New;
if (!_IO.Assert('{')) return KKdList<MsgPack>.Null;
if (_IO.SkipWhitespace().PeekCharUTF8() == '}') { _IO.ReadCharUTF8(); return KKdList<MsgPack>.Null; }
string key;
char c;
@@ -94,22 +93,22 @@ namespace KKdMainLib.MessagePack
key = ReadString();
if (!_IO.SkipWhitespace().Assert(':'))
return KKdList<object>.Null;
return KKdList<MsgPack>.Null;
Obj.Add(ReadValue(key));
c = _IO.SkipWhitespace().PeekCharUTF8();
if (c == '}') { _IO.ReadCharUTF8(); break; }
else if (c == ',') { _IO.ReadCharUTF8(); continue; }
else return KKdList<object>.Null;
else return KKdList<MsgPack>.Null;
}
return Obj;
}
private object[] ReadArray()
private MsgPack[] ReadArray()
{
KKdList<object> Obj = KKdList<object>.New;
KKdList<MsgPack> Obj = KKdList<MsgPack>.New;
if (!_IO.Assert('[')) return null;
if (_IO.SkipWhitespace().PeekCharUTF8() == ']') { _IO.ReadCharUTF8(); return null; }
@@ -137,13 +136,13 @@ namespace KKdMainLib.MessagePack
else
{
long val = long.Parse(s);
if (val >= 0x000000 && val < 0x0000100) return ( byte)val;
else if (val >= -0x000080 && val < 0x0000080) return ( sbyte)val;
else if (val >= -0x008000 && val < 0x0008000) return ( short)val;
else if (val >= 0x000000 && val < 0x0010000) return (ushort)val;
else if (val >= -0x800000 && val < 0x0800000) return ( int)val;
else if (val >= 0x000000 && val < 0x1000000) return ( uint)val;
else return val;
if (val >= 0x00000000 && val < 0x000000100) return ( byte)val;
else if (val >= -0x00000080 && val < 0x000000080) return ( sbyte)val;
else if (val >= -0x00008000 && val < 0x000008000) return ( short)val;
else if (val >= 0x00000000 && val < 0x000010000) return (ushort)val;
else if (val >= -0x80000000 && val < 0x000800000) return ( int)val;
else if (val >= 0x00000000 && val < 0x100000000) return ( uint)val;
else return val;
}
char c = _IO.PeekCharUTF8();
@@ -172,28 +171,35 @@ namespace KKdMainLib.MessagePack
{ string s = ""; while (char.IsDigit(_IO.SkipWhitespace().
PeekCharUTF8())) s += _IO.ReadCharUTF8(); return s; }
public JSONIO Write(MsgPack MsgPack, bool Close, string End = "\n", string TabChar = " ")
{ Write(MsgPack, End, TabChar, "", true); if (Close) this.Close(); return this; }
public JSONIO Write(MsgPack MsgPack, string End = "\n", string TabChar = " ")
{ Write(MsgPack, End, TabChar, "", true); return this; }
public JSONIO Write(MsgPack MsgPack, bool Close, bool Style = false)
{ Write(MsgPack, "\n", " ", "", Style); if (Close) this.Close(); return this; }
public JSONIO Write(MsgPack MsgPack, bool Style = false)
{ Write(MsgPack, "\n", " ", "", Style); return this; }
private JSONIO Write(MsgPack MsgPack, string End, string TabChar, string Tab, bool Style)
private JSONIO Write(MsgPack MsgPack, string End, string TabChar, string Tab, bool Style, bool IsArray = false)
{
string OldTab = Tab;
Tab += TabChar;
if (MsgPack.Name != null) _IO.Write("\"" + MsgPack.Name + "\":" + (Style ? " " : ""));
if (MsgPack.Name != null && !IsArray) _IO.Write("\"" + MsgPack.Name + "\":" + (Style ? " " : ""));
if (MsgPack.Object == null) { WriteNil(); return this; }
if (MsgPack.List.NotNull)
{
WriteMap();
if (Style) _IO.Write(End);
for (int i = 0; i < MsgPack.List.Count; i++)
if (MsgPack.List.Count > 1)
for (int i = 0; i < MsgPack.List.Count; i++)
{
if (Style) _IO.Write(Tab);
Write(MsgPack.List[i], End, TabChar, Tab, Style);
if (i + 1 < MsgPack.List.Count) _IO.Write(',');
if (Style) _IO.Write(End);
}
else if (MsgPack.List.Count == 1)
{
if (Style) _IO.Write(Tab);
Write(MsgPack.List[i], End, TabChar, Tab, Style);
if (i + 1 < MsgPack.List. Count) _IO.Write(',');
Write(MsgPack.List[0], End, TabChar, Tab, Style);
if (Style) _IO.Write(End);
}
if (Style) _IO.Write(OldTab);
@@ -203,11 +209,18 @@ namespace KKdMainLib.MessagePack
{
WriteArr();
if (Style) _IO.Write(End);
for (int i = 0; i < MsgPack.Array.Length; i++)
if (MsgPack.Array.Length > 1)
for (int i = 0; i < MsgPack.Array.Length; i++)
{
if (Style) _IO.Write(Tab);
Write(MsgPack.Array[i], End, TabChar, Tab, Style, true);
if (i + 1 < MsgPack.Array.Length) _IO.Write(',');
if (Style) _IO.Write(End);
}
else if (MsgPack.Array.Length == 1)
{
if (Style) _IO.Write(Tab);
Write(MsgPack.Array[i], End, TabChar, Tab, Style);
if (i + 1 < MsgPack.Array.Length) _IO.Write(',');
Write(MsgPack.Array[0], End, TabChar, Tab, Style, true);
if (Style) _IO.Write(End);
}
if (Style) _IO.Write(OldTab);
@@ -242,8 +255,8 @@ namespace KKdMainLib.MessagePack
}
private void Write( bool val) => _IO.Write(val ? "true" : "false");
private void Write(string val) => _IO.Write("\"" + val
.Replace("\\", "\\\\").Replace("/" , "\\/").Replace("\'", "\\\'").Replace("\"", "\\\"")
.Replace("\0", "\\0" ).Replace("\a", "\\a").Replace("\b", "\\b" ).Replace("\f", "\\f" )
.Replace("\\", "\\\\").Replace("/" , "\\/").Replace("\"", "\\\"")
.Replace("\0", "\\0" ).Replace("\b", "\\b").Replace("\f", "\\f" )
.Replace("\n", "\\n" ).Replace("\r", "\\r").Replace("\t", "\\t" ) + "\"");
private void WriteNil() => _IO.Write("null");
+5 -4
View File
@@ -16,6 +16,7 @@ namespace KKdMainLib.MessagePack
MsgPack = IO.Read(); IO.Close(); IO = null; }
return MsgPack;
}
public static MsgPack ReadMP(this string file, bool JSON = false)
{
MsgPack MsgPack;
@@ -36,10 +37,10 @@ namespace KKdMainLib.MessagePack
{
if (JSON)
{ JSONIO IO = new JSONIO(File.OpenWriter(file + ".json", true));
IO.Write(mp, true, "\n", " "); IO = null; }
IO.Write(mp, "\n", " ").Close(); IO = null; }
else
{ MPIO IO = new MPIO(File.OpenWriter(file + ".mp" , true));
IO.Write(mp, true ); IO = null; }
IO.Write(mp ).Close(); IO = null; }
return mp;
}
@@ -52,10 +53,10 @@ namespace KKdMainLib.MessagePack
byte[] data = null;
if (JSON)
{ JSONIO IO = new JSONIO(File.OpenWriter());
IO.Write(mp, false, true); data = IO._IO.ToArray(true); }
IO.Write(mp, true); data = IO.ToArray(true); }
else
{ MPIO IO = new MPIO(File.OpenWriter());
IO.Write(mp, false ); data = IO._IO.ToArray(true); }
IO.Write(mp ); data = IO.ToArray(true); }
File.WriteAllBytes(file + (JSON ? ".json" : ".mp"), data);
return mp;
}
+153 -159
View File
@@ -3,91 +3,99 @@ using KKdMainLib.Types;
namespace KKdMainLib.MessagePack
{
public struct MsgPack : IDisposable
public struct MsgPack : IDisposable, IEquatable<MsgPack>
{
public string Name;
public object Object;
public object[] Array => Object is object[] List ?
List : null;
public KKdList<object> List => Object is KKdList<object> List ?
List : default(KKdList<object>);
public MsgPack[] Array => Object is MsgPack[] List ? List : null;
public KKdList<MsgPack> List => Object is KKdList<MsgPack> List ? List : default;
public static MsgPack New => new MsgPack { Object = KKdList<object>.New };
public static MsgPack New => new MsgPack { Object = KKdList<MsgPack>.New };
public static MsgPack NewReserve(int Capacity) =>
new MsgPack { Object = KKdList<object>.NewReserve(Capacity) };
new MsgPack { Object = KKdList<MsgPack>.NewReserve(Capacity) };
public MsgPack( string Name = null)
{ Object = KKdList<object>.New; this.Name = Name; }
{ Object = KKdList<MsgPack>.New; this.Name = Name; }
public MsgPack(long Count, string Name = null)
{ if (Count > 0) { Object = new object[Count]; }
else Object = null; this.Name = Name; }
{ Object = Count > 0 ? new MsgPack[Count] : null; this.Name = Name; }
public MsgPack(string Name, object Object)
{ this.Name = Name; this.Object = Object; }
public static MsgPack Null => new MsgPack();
public object this[int index]
{ get { if (Object is object[] Array) return Array[index]; return null; }
set { if (Object is object[] Array) { Array[index] = value; Object = Array; }} }
public MsgPack this[int index]
{ get => Object is MsgPack[] Array ? Array[index] : default;
set { if (Object is MsgPack[] Array) { Array[index] = value; Object = Array; } } }
public MsgPack Add(object obj)
{ if (obj != null && Object is KKdList<object> List)
{ List.Add(obj); Object = List; } return this; }
public MsgPack Add(MsgPack obj)
{ if (Object is KKdList<MsgPack> List) { List.Add(obj); Object = List; } return this; }
public void Dispose()
{ Name = null; Object = null; }
public MsgPack Add( sbyte? val) => Add(null, val);
public MsgPack Add( byte? val) => Add(null, val);
public MsgPack Add( short? val) => Add(null, val);
public MsgPack Add(ushort? val) => Add(null, val);
public MsgPack Add( int? val) => Add(null, val);
public MsgPack Add( uint? val) => Add(null, val);
public MsgPack Add( long? val) => Add(null, val);
public MsgPack Add( ulong? val) => Add(null, val);
public MsgPack Add( float? val) => Add(null, val);
public MsgPack Add(double? val) => Add(null, val);
public bool Equals(MsgPack msg) =>
Name == msg.Name && Object == msg.Object;
public override string ToString() => Name ?? "" +
(List. NotNull ? ((Name != null ? " " : "") + "Elements Count: " + List .Count ) :
(Array != null ? ((Name != null ? " " : "") + "Elements Count: " + Array.Length) :
Object.ToString()));
public MsgPack Add(string Val, byte[] val) => val != null ? Add(new MsgPack(Val, val)) : this;
public MsgPack Add(string Val, string val) => val != null ? Add(new MsgPack(Val, val)) : this;
public static explicit operator MsgPack(byte[] val) => new MsgPack(null, val);
public static explicit operator MsgPack(string val) => new MsgPack(null, val);
public static explicit operator MsgPack( sbyte val) => new MsgPack(null, val);
public static explicit operator MsgPack( byte val) => new MsgPack(null, val);
public static explicit operator MsgPack( short val) => new MsgPack(null, val);
public static explicit operator MsgPack(ushort val) => new MsgPack(null, val);
public static explicit operator MsgPack( int val) => new MsgPack(null, val);
public static explicit operator MsgPack( uint val) => new MsgPack(null, val);
public static explicit operator MsgPack( long val) => new MsgPack(null, val);
public static explicit operator MsgPack( ulong val) => new MsgPack(null, val);
public static explicit operator MsgPack( float val) => new MsgPack(null, val);
public static explicit operator MsgPack(double val) => new MsgPack(null, val);
public MsgPack Add( sbyte? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( byte? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( short? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add(ushort? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( int? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( uint? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( long? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( ulong? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( float? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add(double? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add(byte[] val) => Add(new MsgPack(null, val));
public MsgPack Add(string val) => Add(new MsgPack(null, val));
public MsgPack Add( bool val) => Add(new MsgPack(null, val));
public MsgPack Add( sbyte val) => Add(new MsgPack(null, val));
public MsgPack Add( byte val) => Add(new MsgPack(null, val));
public MsgPack Add( short val) => Add(new MsgPack(null, val));
public MsgPack Add(ushort val) => Add(new MsgPack(null, val));
public MsgPack Add( int val) => Add(new MsgPack(null, val));
public MsgPack Add( uint val) => Add(new MsgPack(null, val));
public MsgPack Add( long val) => Add(new MsgPack(null, val));
public MsgPack Add( ulong val) => Add(new MsgPack(null, val));
public MsgPack Add( float val) => Add(new MsgPack(null, val));
public MsgPack Add(double val) => Add(new MsgPack(null, val));
public MsgPack Add(byte[] val) => Add(null, val);
public MsgPack Add(string val) => Add(null, val);
public MsgPack Add( bool val) => Add(null, val);
public MsgPack Add( sbyte val) => Add(null, val);
public MsgPack Add( byte val) => Add(null, val);
public MsgPack Add( short val) => Add(null, val);
public MsgPack Add(ushort val) => Add(null, val);
public MsgPack Add( int val) => Add(null, val);
public MsgPack Add( uint val) => Add(null, val);
public MsgPack Add( long val) => Add(null, val);
public MsgPack Add( ulong val) => Add(null, val);
public MsgPack Add( float val) => Add(null, val);
public MsgPack Add(double val) => Add(null, val);
public MsgPack Add(string Val, sbyte? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, byte? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, short? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, ushort? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, int? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, uint? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, long? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, ulong? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, float? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, double? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, sbyte? val)
{ if (val != null) Add(Val, ( sbyte)val); return this; }
public MsgPack Add(string Val, byte? val)
{ if (val != null) Add(Val, ( byte)val); return this; }
public MsgPack Add(string Val, short? val)
{ if (val != null) Add(Val, ( short)val); return this; }
public MsgPack Add(string Val, ushort? val)
{ if (val != null) Add(Val, (ushort)val); return this; }
public MsgPack Add(string Val, int? val)
{ if (val != null) Add(Val, ( int)val); return this; }
public MsgPack Add(string Val, uint? val)
{ if (val != null) Add(Val, ( uint)val); return this; }
public MsgPack Add(string Val, long? val)
{ if (val != null) Add(Val, ( long)val); return this; }
public MsgPack Add(string Val, ulong? val)
{ if (val != null) Add(Val, ( ulong)val); return this; }
public MsgPack Add(string Val, float? val)
{ if (val != null) Add(Val, ( float)val); return this; }
public MsgPack Add(string Val, double? val)
{ if (val != null) Add(Val, (double)val); return this; }
public MsgPack Add(string Val, byte[] val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, string val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, bool val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, sbyte val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, byte val) => Add(new MsgPack(Val, val));
@@ -112,30 +120,30 @@ namespace KKdMainLib.MessagePack
public float ReadSingle(string Name) => ReadNSingle(Name).GetValueOrDefault();
public double ReadDouble(string Name) => ReadNDouble(Name).GetValueOrDefault();
public bool? ReadNBoolean(string Name)
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack.ReadNBoolean(); return null; }
public sbyte? ReadNInt8(string Name)
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt8(); return null; }
public byte? ReadNUInt8(string Name)
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt8(); return null; }
public short? ReadNInt16(string Name)
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt16(); return null; }
public ushort? ReadNUInt16(string Name)
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt16(); return null; }
public int? ReadNInt32(string Name)
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt32(); return null; }
public uint? ReadNUInt32(string Name)
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt32(); return null; }
public long? ReadNInt64(string Name)
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt64(); return null; }
public ulong? ReadNUInt64(string Name)
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt64(); return null; }
public float? ReadNSingle(string Name)
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNSingle(); return null; }
public double? ReadNDouble(string Name)
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNDouble(); return null; }
public string ReadString(string Name)
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadString(); return null; }
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 ReadBoolean() => ReadNBoolean().GetValueOrDefault();
public sbyte ReadInt8() => ReadNInt8().GetValueOrDefault();
@@ -150,55 +158,55 @@ namespace KKdMainLib.MessagePack
public double ReadDouble() => ReadNDouble().GetValueOrDefault();
public bool? ReadNBoolean()
{ if (Object is bool Boolean) return Boolean; return null; }
{ if (Object is bool Boolean) return Boolean; return null; }
public sbyte? ReadNInt8()
{ if (Object is sbyte Int8 ) return Int8;
else if (Object is byte UInt8 ) return (sbyte)UInt8; return null; }
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return ( sbyte) UInt8 ; return null; }
public byte? ReadNUInt8()
{ if (Object is sbyte Int8 ) return (byte) Int8;
else if (Object is byte UInt8 ) return UInt8; return null; }
{ if (Object is sbyte Int8 ) return ( byte) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ; return null; }
public short? ReadNInt16()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return (short)UInt16; return null; }
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return ( short) UInt16; return null; }
public ushort? ReadNUInt16()
{ if (Object is sbyte Int8 ) return (ushort) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return (ushort) Int16;
else if (Object is ushort UInt16) return UInt16; return null; }
{ if (Object is sbyte Int8 ) return (ushort) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return (ushort) Int16;
else if (Object is ushort UInt16) return UInt16; return null; }
public int? ReadNInt32()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return (int)UInt32; return null; }
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return ( int) UInt32; return null; }
public uint? ReadNUInt32()
{ if (Object is sbyte Int8 ) return (uint) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return (uint) Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return (uint) Int32;
else if (Object is uint UInt32) return UInt32; return null; }
{ if (Object is sbyte Int8 ) return ( uint) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return ( uint) Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return ( uint) Int32;
else if (Object is uint UInt32) return UInt32; return null; }
public long? ReadNInt64()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return Int64;
else if (Object is ulong UInt64) return (long)UInt64; return null; }
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return Int64;
else if (Object is ulong UInt64) return ( long) UInt64; return null; }
public ulong? ReadNUInt64()
{ if (Object is sbyte Int8 ) return (ulong) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return (ulong) Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return (ulong) Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return (ulong) Int64;
else if (Object is ulong UInt64) return UInt64; return null; }
{ if (Object is sbyte Int8 ) return ( ulong) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return ( ulong) Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return ( ulong) Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return ( ulong) Int64;
else if (Object is ulong UInt64) return UInt64; return null; }
public float? ReadNSingle()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
@@ -210,30 +218,20 @@ namespace KKdMainLib.MessagePack
else if (Object is float Float32) return Float32;
else if (Object is double Float64) return ( float)Float64; return null; }
public double? ReadNDouble()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return Int64;
else if (Object is float Float32) return Float32;
else if (Object is double Float64) return Float64; return null; }
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return Int64;
else if (Object is float Float32) return Float32;
else if (Object is double Float64) return Float64; return null; }
public string ReadString()
{ if (Object is string String) return String; return null; }
{ if (Object is string String) return String; return null; }
public bool Element<T>(string Name, out MsgPack MsgPack)
{
if (Element(Name, out MsgPack))
{
if (MsgPack.Array == null) return false;
for (int i = 0; i < MsgPack.Array.Length; i++)
if (!(MsgPack[i] is T)) return false;
return true;
}
return false;
}
public bool ElementArray(string Name, out MsgPack MsgPack) =>
Element(Name, out MsgPack) ? MsgPack.Array != null : false;
public bool Element(string Name, out MsgPack MsgPack)
{
@@ -241,7 +239,7 @@ namespace KKdMainLib.MessagePack
if (List.IsNull) return false;
for (int i = 0; i < List.Count; i++)
if (List[i] is MsgPack msg) if (msg.Name == Name) { MsgPack = msg; return true; }
if (List[i].Name == Name) { MsgPack = List[i]; return true; }
return false;
}
@@ -249,19 +247,15 @@ namespace KKdMainLib.MessagePack
{
if (List.IsNull) return false;
for (int i = 0; i < List.Count ; i++)
if (List[i] is MsgPack msg) if (msg.Name == Name) return true;
for (int i = 0; i < List.Count ; i++)
if (List[i].Name == Name) return true;
return false;
}
public override string ToString() => Name ?? "" +
( List.NotNull ? ((Name != null ? " " : "") + "Elements Count: " + List .Count ) :
(Array != null ? ((Name != null ? " " : "") + "Elements Count: " + Array.Length) : Object.ToString()));
public struct Ext
{
public byte[] Data;
public sbyte Type;
public sbyte Type;
public byte[] Data;
}
}
}
-202
View File
@@ -1,202 +0,0 @@
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
using KKdMainLib.IO;
using KKdMainLib.Types;
using KKdMainLib.MessagePack;
namespace KKdMainLib
{
public class Mot
{
private int i, i0, i1;
private Stream IO;
public Mot()
{ i = i0 = i1 = 0; IO = null; }
public void MOTReader(string file, bool JSON)
{
IO = File.OpenReader(file + ".bin");
i = 0;
while (true)
{
if (IO.ReadInt32() == 0) break;
IO.ReadInt32();
IO.ReadInt32();
IO.ReadInt32();
i++;
}
if (i == 0) return;
int MOTCount = i;
MsgPack m = new MsgPack(MOTCount, "Mot");
MotHeader[] MMOT = new MotHeader[MOTCount];
for (i = 0; i < MOTCount; i++)
{
ref MotHeader Mot = ref MMOT[i];
IO.Position = 0x10 * i;
Mot. KeySet.Offset = IO.ReadInt32();
Mot.KeySetTypesOffset = IO.ReadInt32();
Mot. KeySetOffset = IO.ReadInt32();
Mot. BoneInfo.Offset = IO.ReadInt32();
i0 = 1;
IO.Position = Mot.BoneInfo.Offset;
IO.ReadUInt16();
while (true) { if (IO.ReadUInt16() == 0) break; 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)) & 3) };
}
IO.Position = Mot.KeySetOffset;
for (i0 = 0; i0 < Mot.KeySet.Value.Length; i0++)
Mot.KeySet.Value[i0].Read(IO);
m[i] = MsgPackWriter(ref MMOT[i]);
((MsgPack)m[i]).Write(true, file + "." + i.ToString("d2"), JSON);
}
IO.Close();
//for (i = 0; i < MOTCount; i++)
// m[i] = MsgPackWriter(ref MMOT[i]);
//m.Write(true, file, JSON);
MMOT = null;
m = new MsgPack();
System.GC.Collect();
}
public MsgPack MsgPackWriter(ref MotHeader Mot)
{
MsgPack MOT = MsgPack.NewReserve(3).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)
{
MsgPack keySet = MsgPack.NewReserve(2).Add("T", KeySet.Type.ToString());
if (KeySet.Type == KeySetType.Interpolated)
{
MsgPack Keys = new MsgPack(KeySet.Keys.Length, "K");
for (i1 = 0; i1 < KeySet.Keys.Length; i1++)
if (KeySet.Keys[i1] is KeyFrameT0<ushort, float> KeyT0)
Keys[i1] = MsgPack.NewReserve(1).Add("F", KeyT0.Frame);
else if (KeySet.Keys[i1] is KeyFrameT1<ushort, float> KeyT1)
Keys[i1] = MsgPack.NewReserve(2).Add("F", KeyT1.Frame).Add("V", KeyT1.Value);
else if (KeySet.Keys[i1] is KeyFrameT2<ushort, float> KeyT2)
Keys[i1] = MsgPack.NewReserve(3).Add("F", KeyT2.Frame).Add("V",
KeyT2.Value).Add("I", KeyT2.Interpolation);
keySet.Add(Keys);
}
else if(KeySet.Type == KeySetType.Linear)
{
MsgPack Keys = new MsgPack(KeySet.Keys.Length, "K");
for (i1 = 0; i1 < KeySet.Keys.Length; i1++)
if (KeySet.Keys[i1] is KeyFrameT0<ushort, float> KeyT0)
Keys[i1] = MsgPack.NewReserve(1).Add("F", KeyT0.Frame);
else if (KeySet.Keys[i1] is KeyFrameT1<ushort, float> KeyT1)
Keys[i1] = MsgPack.NewReserve(2).Add("F", KeyT1.Frame).Add("V", KeyT1.Value);
keySet.Add(Keys);
}
else if (KeySet.Type == KeySetType.Static)
if (KeySet.Keys[0] is KeyFrameT1<ushort, float> Key) keySet.Add("K", Key.Value);
KeySets[i0] = keySet;
}
}
MOT.Add(KeySets);
MsgPack BoneInfo = new MsgPack(Mot.BoneInfo.Value.Length, "BoneInfo");
for (i0 = 0; i0 < Mot.BoneInfo.Value.Length; i0++)
BoneInfo[i0] = 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[]> BoneInfo;
public int HighBits;
public int FrameCount;
}
public struct KeySet
{
public KeyFrame<ushort, float>[] Keys;
public KeySetType Type;
public void Read(Stream IO)
{
if (Type == KeySetType.None ) return;
else if (Type == KeySetType.Static) { Keys = new KeyFrame<ushort, float>[]
{ new KeyFrameT1<ushort, float> { Value = IO.ReadSingle() } }; return; }
Keys = new KeyFrame<ushort, float>[IO.ReadUInt16()];
if (Type == KeySetType.Interpolated)
{
for (int i = 0; i < Keys.Length; i++)
Keys[i] = new KeyFrameT2<ushort, float> { Frame = IO.ReadUInt16() };
IO.Align(0x4);
for (int i = 0; i < Keys.Length; i++)
if (Keys[i] is KeyFrameT2<ushort, float> Key)
{
Key.Value = IO.ReadSingle();
Key.Interpolation = IO.ReadSingle();
if (Key.Interpolation == 0) Keys[i] = Key.ToKeyFrameT1();
else Keys[i] = Key;
}
}
else
{
for (int i = 0; i < Keys.Length; i++)
Keys[i] = new KeyFrameT1<ushort, float> { Frame = IO.ReadUInt16() };
IO.Align(0x4);
for (int i = 0; i < Keys.Length; i++)
if (Keys[i] is KeyFrameT1<ushort, float> Key)
{ Key.Value = IO.ReadSingle(); Keys[i] = Key; }
}
}
}
public enum KeySetType : byte
{
None = 0b00,
Static = 0b01,
Linear = 0b10,
Interpolated = 0b11,
}
public struct BoneInfo
{
public string Name;
public int Id;
}
}
}
+25 -9
View File
@@ -9,7 +9,8 @@ namespace KKdMainLib
public int DataSize;
public int Signature;
public int SectionSize;
public int RealSignature;
public int InnerSignature;
public int SectionSignature;
public Main.Format Format;
public bool IsBE => Format == Main.Format.F2BE;
public bool IsX => Format == Main.Format.X || Format == Main.Format.XHD;
@@ -20,8 +21,8 @@ namespace KKdMainLib
public static PDHead ReadHeader(this Stream stream, bool Seek)
{
if (Seek)
if (stream.Position >= 4) stream.Seek(-4, SeekOrigin.Current);
else stream.Seek( 0, 0);
if (stream.Position > 4) stream.LongPosition -= 4;
else stream.LongPosition = 0;
return stream.ReadHeader();
}
@@ -35,29 +36,44 @@ namespace KKdMainLib
{ Header.Format = Main.Format.F2BE; }
Header.ID = stream.ReadInt32();
Header.SectionSize = stream.ReadInt32();
if (Header.Lenght == 0x40)
{
stream.Position = 0x30;
Header.InnerSignature = stream.ReadInt32();
}
stream.IsBE = Header.Format == Main.Format.F2BE;
stream.Format = Header.Format;
stream.LongPosition = Position + Header.Lenght;
Header.Signature = stream.ReadInt32Endian();
Header.SectionSignature = stream.ReadInt32Endian();
return Header;
}
public static void Write(this Stream stream, PDHead Header)
public static void Write(this Stream stream, PDHead Header, bool X = false)
{
stream.Write(Header.Signature);
stream.Write(Header.DataSize);
stream.Write(Header.Lenght);
stream.Write((Header.Format < Main.Format.X && !X) ? 0x40 : 0x20);
if (Header.Format == Main.Format.F2BE) stream.Write(0x18000000);
else stream.Write(0x10000000);
stream.Write(Header.ID);
stream.Write(Header.SectionSize);
stream.Write(0x00);
stream.Write(0x00);
if (Header.Format < Main.Format.X && !X)
{
stream.Write(Header.Format < Main.Format.MGF ? (int)((Header.SectionSignature ^
(Header.DataSize * (long)Header.Signature)) - Header.ID + Header.SectionSize) : 0);
stream.Write(0x00);
stream.Write(0x00L);
stream.Write(Header.InnerSignature);
stream.Write(0x00);
stream.Write(0x00L);
}
}
public static void WriteEOFC(this Stream stream, int ID)
{ PDHead Header = new PDHead { Format = Main.Format.F2LE, ID = ID,
Lenght = 0x20, Signature = 0x43464F45, }; stream.Write(Header); }
public static void WriteEOFC(this Stream stream, int ID = 0) =>
stream.Write(new PDHead { ID = ID,
Lenght = 0x20, Signature = 0x43464F45 }, true);
}
}
+7 -13
View File
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using KKdMainLib.IO;
namespace KKdMainLib
@@ -30,7 +29,7 @@ namespace KKdMainLib
public static Stream GetOffset(this Stream stream, ref POF POF)
{
if (POF != null) if (stream.Format > Main.Format.F)
POF.POFOffsets.Add(stream.Position - (stream.IsX ? stream.Offset : 0x00));
POF.POFOffsets.Add(stream.Position + (stream.IsX ? stream.Offset : 0x00));
return stream;
}
@@ -69,7 +68,7 @@ namespace KKdMainLib
for (int i = 0; i < POF.Offsets.Count && i < POF.POFOffsets.Count; i++)
if (POF.Offsets[i] != POF.POFOffsets[i])
Console.WriteLine("Not right POF{0} offset table.\n" +
System.Console.WriteLine("Not right POF{0} offset table.\n" +
" Expected: {1}\n Got: {2}", POF.Type,
POF.Offsets[i].ToString("X8"), POF.POFOffsets[i].ToString("X8"));
}
@@ -98,7 +97,7 @@ namespace KKdMainLib
POF.Header = new PDHead { DataSize = (int)POFLenghtAling, ID = ID, Format = Main.Format.F2LE,
Lenght = 0x20, SectionSize = (int)POFLenghtAling, Signature = 0x30464F50 };
POF.Header.Signature += POF.Type << 24;
stream.Write(POF.Header);
stream.Write(POF.Header, true);
stream.Write(POF.Lenght);
for (int i = 0; i < POF.POFOffsets.Count; i++)
@@ -113,18 +112,13 @@ namespace KKdMainLib
stream.WriteEOFC(ID);
}
public static long ReadUInt32Endian(this Stream IO, ref POF POF) =>
IO.GetOffset(ref POF).ReadUInt32Endian();
public static long ReadUInt32Endian(this Stream IO, ref POF POF ) =>
IO.GetOffset(ref POF).ReadUInt32Endian( );
public static long ReadUInt32Endian(this Stream IO, ref POF POF, bool IsBE) =>
IO.GetOffset(ref POF).ReadUInt32Endian(IsBE);
public static long ReadInt64(this Stream IO, ref POF POF) =>
public static long ReadInt64 (this Stream IO, ref POF POF) =>
IO.GetOffset(ref POF).ReadInt64();
public static long ReadIntX(this Stream IO, ref POF POF ) =>
IO.IsX ? IO.ReadInt64() : IO.ReadUInt32Endian( );
public static long ReadIntX(this Stream IO, ref POF POF, bool IsBE) =>
IO.IsX ? IO.ReadInt64() : IO.ReadUInt32Endian(IsBE);
public static string ReadStringAtOffset(this Stream IO, ref POF POF, long Offset = 0, long Length = 0) =>
IO.GetOffset(ref POF).ReadStringAtOffset(Offset, Length);
}
+3 -3
View File
@@ -2,7 +2,7 @@
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("KKdMainLib")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("A simple library for working with Project Diva AC/DT/F/AFT/F2/X/FT files")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KKdMainLib")]
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("2BA7EFC6-91D1-8BBC-C487-06C7F36CC789")]
[assembly: AssemblyVersion("0.4.6.0")]
[assembly: AssemblyFileVersion("0.4.6.0")]
[assembly: AssemblyVersion("0.4.6.4")]
[assembly: AssemblyFileVersion("0.4.6.4")]
+14 -19
View File
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using KKdMainLib.IO;
using KKdMainLib.IO;
using KKdMainLib.Types;
using KKdMainLib.MessagePack;
using MPIO = KKdMainLib.MessagePack.IO;
namespace KKdMainLib
{
@@ -112,17 +110,16 @@ namespace KKdMainLib
writer.GetOffset(ref POF).Write(0x00);
writer.WriteEndian(STRs[i].ID);
}
writer.Align(16);
writer.Align(0x10);
}
else
{
for (int i = 0; i < Count; i++)
writer.Write(0x00);
writer.Align(32);
for (int i = 0; i < Count; i++) writer.Write(0x00);
writer.Align(0x20);
}
List<string> UsedSTR = new List<string>();
List<int> UsedSTRPos = new List<int>();
KKdList<string> UsedSTR = KKdList<string>.New;
KKdList<int> UsedSTRPos = KKdList<int>.New;
int[] STRPos = new int[Count];
for (int i1 = 0; i1 < Count; i1++)
{
@@ -143,7 +140,7 @@ namespace KKdMainLib
}
if (writer.Format > Main.Format.FT)
{
writer.Align(16);
writer.Align(0x10);
Offset = writer.UIntPosition;
writer.Position = 0x80;
}
@@ -177,16 +174,14 @@ namespace KKdMainLib
if (!MsgPack.Element("STR", out MsgPack STR)) return;
if (!STR.Element<MsgPack>("Strings", out MsgPack Strings)) return;
if (!STR.ElementArray("Strings", out MsgPack Strings)) return;
STRs = new String[Strings.Array.Length];
for (int i = 0; i < STRs.Length; i++)
if (Strings[i] is MsgPack String)
{
String = (MsgPack)Strings[i];
STRs[i].ID = String.ReadInt32("ID");
STRs[i].Str = String.ReadString("Str");
}
{
STRs[i].ID = Strings[i].ReadInt32 ("ID" );
STRs[i].Str = Strings[i].ReadString("Str");
}
MsgPack = MsgPack.New;
}
@@ -199,7 +194,7 @@ namespace KKdMainLib
{
Strings[i] = MsgPack.New.Add("ID", STRs[i].ID);
if (STRs[i].Str != null) if (STRs[i].Str != "")
((MsgPack)Strings[i]).Add("S", STRs[i].Str); ;
Strings[i].Add("S", STRs[i].Str); ;
}
STR_.Add(Strings);
+7 -10
View File
@@ -1,17 +1,14 @@
using System;
using System.Text;
using System.Text;
namespace KKdMainLib
{
public static class Text
{
public static string ToASCII(this byte[] Array) => Encoding.ASCII.GetString(Array);
public static string ToUTF8 (this byte[] Array) => Encoding.UTF8 .GetString(Array);
public static byte[] ToASCII(this string Data ) => Encoding.ASCII.GetBytes (Data );
public static byte[] ToUTF8 (this string Data ) => Encoding.UTF8 .GetBytes (Data );
public static byte[] ToASCII(this char[] Data ) => Encoding.ASCII.GetBytes (Data );
public static byte[] ToUTF8 (this char[] Data ) => Encoding.UTF8 .GetBytes (Data );
public static string ToBase64(this byte[] Array) => Convert. ToBase64String(Array);
public static byte[] FromBase64(this string Data ) => Convert.FromBase64String(Data );
public static string ToASCII(this byte[] Array) => Encoding.ASCII.GetString(Array ?? new byte[0]);
public static string ToUTF8 (this byte[] Array) => Encoding.UTF8 .GetString(Array ?? new byte[0]);
public static byte[] ToASCII(this string Data ) => Encoding.ASCII.GetBytes (Data ?? "" );
public static byte[] ToUTF8 (this string Data ) => Encoding.UTF8 .GetBytes (Data ?? "" );
public static byte[] ToASCII(this char[] Data ) => Encoding.ASCII.GetBytes (Data ?? new char[0]);
public static byte[] ToUTF8 (this char[] Data ) => Encoding.UTF8 .GetBytes (Data ?? new char[0]);
}
}
+16 -34
View File
@@ -12,18 +12,12 @@ namespace KKdMainLib.Types
public static explicit operator double(Half h)
{
if (h._value == 0x0000)
return +0;
else if (h._value == 0x8000)
return (-0);
else if (h._value == 0x7C00)
return double.PositiveInfinity;
else if (h._value == 0xFC00)
return double.NegativeInfinity;
else if (h._value >> 10 == 0x1F)
return double.NaN;
else if (h._value >> 10 == 0x3F)
return -double.NaN;
if (h._value == 0x0000) return +0;
else if (h._value == 0x8000) return -0;
else if (h._value == 0x7C00) return double.PositiveInfinity;
else if (h._value == 0xFC00) return double.NegativeInfinity;
else if (h._value >> 10 == 0x001F) return double.NaN;
else if (h._value >> 10 == 0x003F) return -double.NaN;
long exponent = ((h._value >> 10) & 0x1F);
long mantissa = (h._value & 0x3FF);
@@ -38,20 +32,13 @@ namespace KKdMainLib.Types
public static explicit operator Half(double val)
{
Half h = new Half();
if (val == +0)
h._value = 0x0000;
else if (val == -0)
h._value = 0x8000;
else if (val == double.NaN)
h._value = 0x7FFF;
else if (val == -double.NaN)
h._value = 0xFFFF;
else if (val == double.PositiveInfinity)
h._value = 0x7C00;
else if (val == double.NegativeInfinity)
h._value = 0xFC00;
else
h._value = ToDouble(val);
if (val == +0 ) h._value = 0x0000;
else if (val == -0 ) h._value = 0x8000;
else if (val == double.NaN ) h._value = 0x7FFF;
else if (val == -double.NaN ) h._value = 0xFFFF;
else if (val == double.PositiveInfinity) h._value = 0x7C00;
else if (val == double.NegativeInfinity) h._value = 0xFC00;
else h._value = ToDouble(val);
return h;
}
@@ -76,10 +63,8 @@ namespace KKdMainLib.Types
{
ushort exponent_max = (ushort)Math.Ceiling(x * Pow2);
ushort exponent_min = (ushort)Math.Floor (x * Pow2);
ushort exponent = 0;
if (Math.Abs(x - exponent_max / Pow2) > Math.Abs(x - exponent_min / Pow2))
exponent = exponent_max;
else exponent = exponent_min;
ushort exponent = Math.Abs(x - exponent_max / Pow2) >
Math.Abs(x - exponent_min / Pow2) ? exponent_max : exponent_min;
ushort mantissa = (ushort)(i + MaxPow - 1);
ushort d = (ushort)(Sign | ((mantissa & 0x001F) << 10) | (exponent & 0x03FF));
return d;
@@ -88,10 +73,7 @@ namespace KKdMainLib.Types
else i++;
}
if (i >= +0)
return 0x7C00;
else
return 0xFC00;
return i >= +0 ? (ushort)0x7C00 : (ushort)0xFC00;
}
public override string ToString() => ((double)this).ToString();
@@ -1,56 +1,53 @@
namespace KKdMainLib.Types
{
public interface KeyFrame<TKey, TVal>
public interface IKeyFrame<TKey, TVal>
{
KeyFrame<TKey, TVal> Check();
KeyFrame<TKey, TVal> ToKeyFrameT0();
KeyFrame<TKey, TVal> ToKeyFrameT1();
KeyFrame<TKey, TVal> ToKeyFrameT2();
KeyFrame<TKey, TVal> ToKeyFrameT3();
IKeyFrame<TKey, TVal> Check();
IKeyFrame<TKey, TVal> ToKeyFrameT0();
IKeyFrame<TKey, TVal> ToKeyFrameT1();
IKeyFrame<TKey, TVal> ToKeyFrameT2();
IKeyFrame<TKey, TVal> ToKeyFrameT3();
string ToString();
string ToString(bool Brackets);
}
public struct KeyFrameT0<TKey, TVal> : KeyFrame<TKey, TVal>
public struct KeyFrameT0<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public KeyFrame<TKey, TVal> ToKeyFrameT0() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
new KeyFrameT0<TKey, TVal> { Frame = Frame };
public KeyFrame<TKey, TVal> ToKeyFrameT1() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
new KeyFrameT1<TKey, TVal> { Frame = Frame };
public KeyFrame<TKey, TVal> ToKeyFrameT2() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
new KeyFrameT2<TKey, TVal> { Frame = Frame };
public KeyFrame<TKey, TVal> ToKeyFrameT3() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
new KeyFrameT3<TKey, TVal> { Frame = Frame };
public KeyFrame<TKey, TVal> Check() => this;
public IKeyFrame<TKey, TVal> Check() => this;
public override string ToString() =>
Main.ToString(Frame);
public string ToString(bool Brackets) =>
Main.ToString(Frame);
}
public struct KeyFrameT1<TKey, TVal> : KeyFrame<TKey, TVal>
public struct KeyFrameT1<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public TVal Value;
public KeyFrame<TKey, TVal> ToKeyFrameT0() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
new KeyFrameT0<TKey, TVal> { Frame = Frame };
public KeyFrame<TKey, TVal> ToKeyFrameT1() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
new KeyFrameT1<TKey, TVal> { Frame = Frame, Value = Value };
public KeyFrame<TKey, TVal> ToKeyFrameT2() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
new KeyFrameT2<TKey, TVal> { Frame = Frame, Value = Value };
public KeyFrame<TKey, TVal> ToKeyFrameT3() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value };
public KeyFrame<TKey, TVal> Check()
{
if (Value.Equals(default(TVal))) return ToKeyFrameT0();
return this;
}
public IKeyFrame<TKey, TVal> Check() =>
Value.Equals(default(TVal)) ? ToKeyFrameT0() : (this);
public override string ToString() => ToString(true);
public string ToString(bool Brackets) =>
@@ -58,31 +55,31 @@
Main.ToString(Value) + (Brackets ? ")" : "");
}
public struct KeyFrameT2<TKey, TVal> : KeyFrame<TKey, TVal>
public struct KeyFrameT2<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public TVal Value;
public TVal Interpolation;
public KeyFrame<TKey, TVal> ToKeyFrameT0() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
new KeyFrameT0<TKey, TVal> { Frame = Frame };
public KeyFrame<TKey, TVal> ToKeyFrameT1() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
new KeyFrameT1<TKey, TVal> { Frame = Frame, Value = Value };
public KeyFrame<TKey, TVal> ToKeyFrameT2() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
new KeyFrameT2<TKey, TVal> { Frame = Frame, Value = Value,
Interpolation = Interpolation};
public KeyFrame<TKey, TVal> ToKeyFrameT3() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
Interpolation1 = Interpolation, Interpolation2 = Interpolation };
public KeyFrame<TKey, TVal> ToKeyFrameT3(KeyFrame<TKey, TVal> Previous) =>
public IKeyFrame<TKey, TVal> ToKeyFrameT3(IKeyFrame<TKey, TVal> Previous) =>
Previous is KeyFrameT2<TKey, TVal> PreviousT2 ?
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
Interpolation1 = PreviousT2.Interpolation, Interpolation2 = Interpolation } :
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
Interpolation1 = Interpolation, Interpolation2 = Interpolation };
public KeyFrame<TKey, TVal> Check()
public IKeyFrame<TKey, TVal> Check()
{
if (Value.Equals(default(TVal)) && Interpolation.Equals(default(TVal)))
return ToKeyFrameT0();
@@ -95,25 +92,25 @@
(Brackets ? "(" : "") + Main.ToString(Frame) + "," + Main.
ToString(Value) + "," + Main.ToString(Interpolation) + (Brackets ? ")" : "");
}
public struct KeyFrameT3<TKey, TVal> : KeyFrame<TKey, TVal>
public struct KeyFrameT3<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public TVal Value;
public TVal Interpolation1;
public TVal Interpolation2;
public KeyFrame<TKey, TVal> ToKeyFrameT0() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
new KeyFrameT0<TKey, TVal> { Frame = Frame };
public KeyFrame<TKey, TVal> ToKeyFrameT1() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
new KeyFrameT1<TKey, TVal> { Frame = Frame, Value = Value };
public KeyFrame<TKey, TVal> ToKeyFrameT2() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
new KeyFrameT2<TKey, TVal> { Frame = Frame, Value = Value, Interpolation = Interpolation1 };
public KeyFrame<TKey, TVal> ToKeyFrameT3() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
Interpolation1 = Interpolation1, Interpolation2 = Interpolation2 };
public KeyFrame<TKey, TVal> Check()
public IKeyFrame<TKey, TVal> Check()
{
if (Value.Equals(default(TVal)) && Interpolation1.Equals(default(TVal)) &&
Interpolation2.Equals(default(TVal))) return ToKeyFrameT0();
@@ -129,26 +126,13 @@
(Brackets ? "(" : "") + Main.ToString(Frame) + "," + Main.ToString(Value) + "," +
Main.ToString(Interpolation1) + "," + Main.ToString(Interpolation2) + (Brackets ? ")" : "");
public KeyFrame<TKey, TVal> ToKeyFrameT2(KeyFrame<TKey, TVal>
Previous, out KeyFrameT2<TKey, TVal> Current)
public IKeyFrame<TKey, TVal> ToKeyFrameT2(IKeyFrame<TKey, TVal>
Previous, out IKeyFrame<TKey, TVal> Current)
{
if (Previous is KeyFrameT2<TKey, TVal> PreviousT2)
Current = new KeyFrameT2<TKey, TVal> { Frame = PreviousT2.Frame,
Value = PreviousT2.Value, Interpolation = Interpolation1 };
else
Current = new KeyFrameT2<TKey, TVal> { Frame = Frame,
Value = Value, Interpolation = Interpolation1 };
return new KeyFrameT2<TKey, TVal> { Frame = Frame,
Value = Value, Interpolation = Interpolation2 };
}
public KeyFrame<TKey, TVal> ToKeyFrameT2(KeyFrame<TKey, TVal>
Previous, out KeyFrame<TKey, TVal> Current)
{
if (Previous is KeyFrameT2<TKey, TVal> PreviousT2)
Current = new KeyFrameT2<TKey, TVal> { Frame = PreviousT2.Frame,
Value = PreviousT2.Value, Interpolation = Interpolation1 };
else
Current = new KeyFrameT2<TKey, TVal> { Frame = Frame,
Current = Previous is KeyFrameT2<TKey, TVal> PreviousT2
? new KeyFrameT2<TKey, TVal> { Frame = PreviousT2.Frame,
Value = PreviousT2.Value, Interpolation = Interpolation1 }
: new KeyFrameT2<TKey, TVal> { Frame = Frame,
Value = Value, Interpolation = Interpolation1 };
return new KeyFrameT2<TKey, TVal> { Frame = Frame,
Value = Value, Interpolation = Interpolation2 };
+32 -31
View File
@@ -5,70 +5,67 @@ namespace KKdMainLib.Types
public struct KKdList<T> : IEnumerator, IEnumerable
{
public static KKdList<T> Null => new KKdList<T>();
public static KKdList<T> New => new KKdList<T>() { Capacity = 0 };
public static KKdList<T> New => new KKdList<T>() { Capacity = 0 };
public static KKdList<T> NewReserve(int Capacity) => new KKdList<T>() { Capacity = Capacity };
private int Index;
private int ArrayLength;
private T[] Array;
public bool IsNull => Array == null;
public bool NotNull => Array != null;
private int index;
private T[] array;
public int Count { get; private set; }
public int Capacity { get => ArrayLength;
public bool IsNull => array == null;
public bool NotNull => array != null;
public int Capacity { get => array != null ? array.Length : -1;
set
{
ArrayLength = value;
if (Array != null) System.Array.Resize(ref Array, ArrayLength);
else Array = new T[ArrayLength];
if (array != null) System.Array.Resize(ref array, value);
else array = new T[value];
}
}
public KKdList(T[] Array)
{
Index = 0;
index = 0;
Count = Array.Length;
ArrayLength = Array.Length;
this.Array = Array;
array = Array;
}
public T Current => Index < Count ? Array[Index] : default(T);
public T Current => index < Count ? array[index] : default;
object IEnumerator.Current => Current;
public T this[int index]
{ get { if (Array != null) return Array[index]; return default(T); }
set { if (Array != null) Array[index] = value; } }
{ get => array != null ? array[index] : default;
set { if (array != null) array[index] = value; } }
public bool MoveNext()
{ if (Index == (Count - 1)) { Index = 0; return false; }
else { Index++ ; return true; } }
{ if (index == (Count - 1)) { index = 0; return false; }
else { index++ ; return true; } }
public IEnumerator GetEnumerator() => this;
public void Dispose() { Array = null; ArrayLength = 0; Count = 0; Index = 0; }
public void Dispose() { array = null; Count = 0; index = 0; }
public void Reset() => Index = 0;
public void Reset() => index = 0;
public void Add(T item)
{
if (IsNull) return;
Count++;
if (ArrayLength < Count)
System.Array.Resize(ref Array, ArrayLength = Count);
Array[Count - 1] = item;
if (array.Length < Count)
System.Array.Resize(ref array, Count);
array[Count - 1] = item;
}
public void RemoveAt(int Index)
public void RemoveAt(int index)
{
if (IsNull) return;
for (int i = Index; i < Count; i++)
Array[i] = Array[i + 1];
for (int i = index; i < Count; i++)
array[i] = array[i + 1];
}
public void RemoveRange(int IndexStart, int IndexEnd)
@@ -77,16 +74,18 @@ namespace KKdMainLib.Types
if (IsNull) return;
for (int i = IndexStart; i < Count; i++)
Array[i] = Array[i + IndexEnd - IndexStart];
array[i] = array[i + IndexEnd - IndexStart];
}
public T[] ToArray() => Array;
public T[] ToArray() => array;
public bool Contains(T val)
{
if (IsNull) return false;
for (int i = 0; i < Count; i++)
if (Array[i].Equals(val)) return true;
if (array[i] == null && val == null) return true;
else if ( val == null) continue;
else if (array[i] .Equals(val) ) return true;
return false;
}
@@ -94,7 +93,9 @@ namespace KKdMainLib.Types
{
if (IsNull) return -1;
for (int i = 0; i < Count; i++)
if (Array[i].Equals(val)) return i;
if (array[i] == null && val == null) return i;
else if ( val == null) continue;
else if (array[i] .Equals(val) ) return i;
return -1;
}
}
+29 -3
View File
@@ -1,17 +1,43 @@
namespace KKdMainLib.Types
using KKdMainLib.IO;
namespace KKdMainLib.Types
{
public struct Pointer<T>
{
public int Offset;
public T Value;
}
public override string ToString() => Main.ToString(Value);
}
public struct CountPointer<T>
{
public int Count { get => Entries != null ? Entries.Length : 0;
set => Entries = new T[value]; }
public int Offset;
public T[] Entries;
public T this[int index]
{ get => Count > 0 ? Entries[index] : default;
set { if (Count > 0) Entries[index] = value; } }
public override string ToString() => Count < 1 ? "No Entries" :
Count == 1 ? Entries[0].ToString() : "Count: " + Count;
}
public static class PointerExt
{
public static Pointer<T> ReadPointer<T>(this Stream IO) =>
new Pointer<T> { Offset = IO.ReadInt32() };
public static Pointer<string> ReadPointerString(this Stream IO)
{
Pointer<string> val = IO.ReadPointer<string>();
val.Value = IO.ReadStringAtOffset(val.Offset); return val;
}
public static CountPointer<T> ReadCountPointer<T>(this Stream IO) =>
new CountPointer<T> { Count = IO.ReadInt32(), Offset = IO.ReadInt32() };
}
}
+27 -11
View File
@@ -1,28 +1,44 @@
namespace KKdMainLib.Types
{
public class Vector2<T>
public struct Vector2<T>
{
public T X;
public T Y;
public T Z;
public Vector2()
{ X = default(T); Y = default(T); Z = default(T); }
public Vector2(T X, T Y)
{ this.X = X; this.Y = Y; }
public Vector2(T X, T Y, T Z)
{ this.X = X; this.Y = Y; this.Z = Z; }
public bool NotNull => X != null && Y != null;
public override string ToString() => "X: " + X + "; Y: " + Y;
}
public class Vector3<T>
public struct Vector3<T>
{
public T X;
public T Y;
public T Z;
public Vector3()
{ X = default(T); Y = default(T); Z = default(T); }
public Vector3(T X, T Y, T Z)
{ this.X = X; this.Y = Y; this.Z = Z; }
public bool NotNull => X != null && Y != null && Z != null;
public override string ToString() => "X: " + X + "; Y: " + Y + "; Z: " + Z;
}
public struct Vector4<T>
{
public T X;
public T Y;
public T Z;
public T W;
public Vector4(T X, T Y, T Z, T W)
{ this.X = X; this.Y = Y; this.Z = Z; this.W = W; }
public bool NotNull => X != null && Y != null && Z != null && W != null;
public override string ToString() => "X: " + X + "; Y: " + Y + "; Z: " + Z + "; W: " + W;
}
}
+1 -2
View File
@@ -1,5 +1,4 @@
using System;
using KKdMainLib;
using KKdMainLib;
using KKdMainLib.IO;
namespace KKdSoundLib
+4
View File
@@ -22,6 +22,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -33,6 +35,8 @@
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="Extensions.cs" />
+1 -1
View File
@@ -2,7 +2,7 @@
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("KKdSoundLib")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("A simple library for working with Project Diva F/AFT/F2/X/FT audio files")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KKdSoundLib")]
+1 -7
View File
@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KKdSoundLib
namespace KKdSoundLib
{
public static class WAV
{
+2 -2
View File
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2003
# Visual Studio Version 16
VisualStudioVersion = 16.0.29025.244
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PD_Tool", "PD_Tool\PD_Tool.csproj", "{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}"
EndProject
+4
View File
@@ -22,6 +22,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -33,6 +35,8 @@
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="classes\DataBase.cs" />
+2 -4
View File
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using KKdMainLib.IO;
using KKdMainLib.Types;
using KKdMain = KKdMainLib.Main;
using KKdFARC = KKdMainLib.FARC;
@@ -9,7 +7,7 @@ namespace PD_Tool
{
public static class Program
{
public static string function = "";
[ThreadStatic] public static string function = "";
[STAThread]
public static void Main(string[] args)
@@ -39,7 +37,7 @@ namespace PD_Tool
Exit();
}
private static bool JSON = true;
[ThreadStatic] private static bool JSON = true;
private static void MainMenu()
{
+3 -3
View File
@@ -2,7 +2,7 @@
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("PD_Tool")]
[assembly: AssemblyDescription("A simple tool for working with Project Diva A/DT/F/AFT/F2/X/FT files")]
[assembly: AssemblyDescription("A simple tool for working with Project Diva AC/DT/F/AFT/F2/X/FT files")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PD_Tool")]
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
[assembly: AssemblyVersion("0.4.6.0")]
[assembly: AssemblyFileVersion("0.4.6.0")]
[assembly: AssemblyVersion("0.4.6.4")]
[assembly: AssemblyFileVersion("0.4.6.4")]
+1 -2
View File
@@ -64,8 +64,7 @@ namespace PD_Tool
else if (type == "R") return;
else FARC.Signature = KKdFARC.Farc.FArC;
Console.Title = "FARC Creator - Directory: " + Path.GetDirectoryName(file);
FARC.DirectoryPath = file;
FARC.Pack();
new KKdFARC(file, true).Pack();
}
}
}
+56 -25
View File
@@ -1,7 +1,9 @@
using System;
using KKdMainLib;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
using KKdA3DA = KKdMainLib.A3DA.A3DA;
using KKdFARC = KKdMainLib.FARC;
namespace PD_Tool.Tools
{
@@ -15,38 +17,43 @@ namespace PD_Tool.Tools
string filepath = "";
string ext = "";
bool MP = true;
bool MP = false;
foreach (string file in FileNames)
if (file.EndsWith(".mp" )) { MP = false; break; }
else if (file.EndsWith(".json")) { MP = false; break; }
if (file.EndsWith(".mp" )) { MP = true; break; }
else if (file.EndsWith(".json")) { MP = true; break; }
else if (file.EndsWith(".farc")) { MP = true; break; }
Main.Format Format = Main.Format.NULL;
if (!MP)
string format = "";
if (MP)
{
Console.Clear();
Main.ConsoleDesign(true);
Main.ConsoleDesign(" Choose type of format to export:");
Main.ConsoleDesign(false);
Main.ConsoleDesign("1. DT PS3");
Main.ConsoleDesign("2. F PS3/PSV");
Main.ConsoleDesign("3. FT PS4");
Main.ConsoleDesign("4. F2nd PS3/PSV");
Main.ConsoleDesign("5. MGF PSV");
Main.ConsoleDesign("6. X PS4/PSV");
Main.ConsoleDesign("1. A3DA [DT/AC/F]");
Main.ConsoleDesign("2. A3DC [DT/AC/F]");
Main.ConsoleDesign("3. A3DA [AFT/FT] ");
Main.ConsoleDesign("4. A3DC [AFT/FT] ");
Main.ConsoleDesign("5. A3DC [F2] ");
Main.ConsoleDesign("6. A3DC [MGF] ");
Main.ConsoleDesign("7. A3DC [X] ");
Main.ConsoleDesign(false);
Main.ConsoleDesign(true);
Console.WriteLine();
string format = Console.ReadLine();
format = Console.ReadLine();
if (format == "1") Format = Main.Format.DT ;
else if (format == "2") Format = Main.Format.F ;
else if (format == "3") Format = Main.Format.FT ;
else if (format == "4") Format = Main.Format.F2LE;
else if (format == "5") Format = Main.Format.MGF ;
else if (format == "6") Format = Main.Format.X ;
else if (format == "4") Format = Main.Format.FT ;
else if (format == "5") Format = Main.Format.F2LE;
else if (format == "6") Format = Main.Format.MGF ;
else if (format == "7") Format = Main.Format.X ;
else return;
}
KKdA3DA A;
int state;
foreach (string file in FileNames)
{
A = new KKdA3DA();
@@ -55,23 +62,47 @@ namespace PD_Tool.Tools
ext = ext.ToLower();
Console.Title = "A3DA Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".a3da")
if (ext == ".farc")
{
A.A3DAReader (filepath);
A.MsgPackWriter(filepath, JSON);
KKdFARC FARC = new KKdFARC(file);
if (!FARC.HeaderReader()) continue;
if (!FARC.HasFiles) continue;
MsgPack A3DA = MsgPack.Null;
byte[] data = null;
for (int i = 0; i < FARC.Files.Length; i++)
{
data = FARC.FileReader(i);
state = A.A3DAReader(data);
if (state == 1)
{
A3DA = A.MsgPackWriter();
A = new KKdA3DA();
A.MsgPackReader(A3DA);
A.IO = File.OpenWriter();
A.Data._.CompressF16 = Format > Main.Format.FT ?
Format == Main.Format.MGF ? 2 : 1 : 0;
A.Data.Format = Format;
FARC.Files[i].Data = (format != "1" &&
format != "3") ? A.A3DCWriter() : A.A3DAWriter();
}
}
FARC.Save();
}
else if (ext == ".a3da")
{
state = A.A3DAReader(filepath);
if (state == 1) A.MsgPackWriter(filepath, JSON);
}
else if (ext == ".mp" || ext == ".json")
{
A.MsgPackReader(filepath, ext == ".json");
A.IO = File.OpenWriter(filepath + ".a3da", true);
if (A.Data.Header.Format >= Main.Format.F2LE)
A.Data._.CompressF16 = Format == Main.Format.MGF ? 2 : 1;
A.Data.Header.Format = Format;
A.Data._.CompressF16 = Format > Main.Format.FT ?
Format == Main.Format.MGF ? 2 : 1 : 0;
A.Data.Format = Format;
if (A.Data.Header.Format > Main.Format.DT && A.Data.Header.Format != Main.Format.FT)
A.A3DCWriter(filepath);
else
A.A3DAWriter();
File.WriteAllBytes(filepath + ".a3da", (format != "1" &&
format != "3") ? A.A3DCWriter() : A.A3DAWriter());
}
A = null;
}
+2 -2
View File
@@ -29,9 +29,9 @@ namespace PD_Tool.Tools
Data.STRReader (filepath, ext);
Data.MsgPackWriter(filepath, JSON);
}
else if (ext == ".mp")
else if (ext == ".json" || ext == ".mp")
{
Data.MsgPackReader(filepath, JSON);
Data.MsgPackReader(filepath, ext == ".json");
Data.STRWriter (filepath);
}
Data = null;