Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bbbea9536 | ||
|
|
4de7bd32f7 | ||
|
|
93f905d3e1 | ||
|
|
4c8b293beb | ||
|
|
72141ef603 | ||
|
|
d405f05f0b | ||
|
|
8b5a939dee |
+535
-628
File diff suppressed because it is too large
Load Diff
+229
-113
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.Types;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.A3DA
|
||||
@@ -44,13 +45,13 @@ namespace KKdMainLib.A3DA
|
||||
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;
|
||||
byte i1 = 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" );
|
||||
@@ -60,39 +61,62 @@ namespace KKdMainLib.A3DA
|
||||
|
||||
if (Key.Length != null)
|
||||
{
|
||||
Key.Trans = new Key.Transform[(int)Key.Length];
|
||||
int Type;
|
||||
Key.Trans = new IKeyFrame<double, double>[(int)Key.Length];
|
||||
for (i0 = 0; i0 < Key.Length; i0++)
|
||||
if (Dict.FindValue(out value, Temp + "key" + d + i0 + d + "data"))
|
||||
{
|
||||
Key.Trans[i0] = new Key.Transform();
|
||||
dataArray = value.Replace("(", "").Replace(")", "").Split(',');
|
||||
Key.Trans[i0].Type = dataArray.Length - 1;
|
||||
Key.Trans[i0].Frame = dataArray[0].ToDouble();
|
||||
Key.Trans[i0].Value = new double[Key.Trans[i0].Type];
|
||||
for (i1 = 1; i1 < dataArray.Length; i1++)
|
||||
Key.Trans[i0].Value[i1 - 1] = dataArray[i1].ToDouble();
|
||||
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 DataSize = (int)Key.RawData.KeyType + 1;
|
||||
Key.Length = Key.RawData.ValueListSize / DataSize;
|
||||
Key.Trans = new Key.Transform[(int)Key.Length];
|
||||
for (i = 0; i < Key.Length; i++)
|
||||
{
|
||||
Key.Trans[i].Type = (int)Key.RawData.KeyType;
|
||||
Key.Trans[i].Frame = Key.RawData.ValueList[i * DataSize + 0].ToDouble();
|
||||
Key.Trans[i].Value = new double[Key.Trans[i0].Type];
|
||||
for (i1 = 1; i1 < Key.Trans[i].Type; i1++)
|
||||
Key.Trans[i].Value[i1 - 1] = Key.RawData.ValueList[i * DataSize + i1].ToDouble();
|
||||
}
|
||||
int DS = (int)Key.RawData.KeyType + 1;
|
||||
Key.Length = Key.RawData.ValueListSize / DS;
|
||||
Key.Trans = new IKeyFrame<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() }.Check();
|
||||
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 = Key.RawData.ValueList[i * DS + 1].ToDouble() }.Check();
|
||||
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 = Key.RawData.ValueList[i * DS + 1].ToDouble(),
|
||||
Interpolation = Key.RawData.ValueList[i * DS + 2].ToDouble() }.Check();
|
||||
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 = Key.RawData.ValueList[i * DS + 1].ToDouble(),
|
||||
Interpolation1 = Key.RawData.ValueList[i * DS + 2].ToDouble(),
|
||||
Interpolation2 = Key.RawData.ValueList[i * DS + 3].ToDouble() }.Check();
|
||||
|
||||
for (i = 0; i < Key.Length; i++) Key.Trans[i].Check();
|
||||
Key.RawData.ValueList = null;
|
||||
}
|
||||
return Key;
|
||||
@@ -114,9 +138,12 @@ namespace KKdMainLib.A3DA
|
||||
|
||||
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);
|
||||
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)
|
||||
@@ -146,31 +173,54 @@ namespace KKdMainLib.A3DA
|
||||
|
||||
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)
|
||||
if (Key.RawData.KeyType == 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());
|
||||
IO.Write(Temp + "key" + d + SOi + d + "type=", Key.Trans[SOi].Type );
|
||||
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.RawData.KeyType < Key.Trans[i].Type || Key.RawData.KeyType == null)
|
||||
Key.RawData.KeyType = Key.Trans[i].Type;
|
||||
if (Key.RawData.KeyType == 3) break;
|
||||
if (Key.Trans[i] is KeyFrameT0<double, double> &&
|
||||
Key.RawData.KeyType < 0) Key.RawData.KeyType = 0;
|
||||
else if (Key.Trans[i] is KeyFrameT1<double, double> &&
|
||||
Key.RawData.KeyType < 1) Key.RawData.KeyType = 1;
|
||||
else if (Key.Trans[i] is KeyFrameT2<double, double> &&
|
||||
Key.RawData.KeyType < 2) Key.RawData.KeyType = 2;
|
||||
else if (Key.Trans[i] 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));
|
||||
if (Key.RawData.KeyType == 0) for (i = 0; i < Key.Trans.Length; i++)
|
||||
IO.Write(Key.Trans[i].ToKeyFrameT0().ToString(false) +
|
||||
((i + 1 < Key.Trans.Length) ? "," : ""));
|
||||
else if (Key.RawData.KeyType == 1) for (i = 0; i < Key.Trans.Length; i++)
|
||||
IO.Write(Key.Trans[i].ToKeyFrameT1().ToString(false) +
|
||||
((i + 1 < Key.Trans.Length) ? "," : ""));
|
||||
else if (Key.RawData.KeyType == 2) for (i = 0; i < Key.Trans.Length; i++)
|
||||
IO.Write(Key.Trans[i].ToKeyFrameT2().ToString(false) +
|
||||
((i + 1 < Key.Trans.Length) ? "," : ""));
|
||||
else if (Key.RawData.KeyType == 3) for (i = 0; i < Key.Trans.Length; i++)
|
||||
IO.Write(Key.Trans[i].ToKeyFrameT3().ToString(false) +
|
||||
((i + 1 < Key.Trans.Length) ? "," : ""));
|
||||
IO.Position = IO.Position - 1;
|
||||
IO.Write('\n');
|
||||
IO.Write(Temp + "raw_data.value_list_size=", Key.RawData.ValueListSize);
|
||||
@@ -178,18 +228,20 @@ namespace KKdMainLib.A3DA
|
||||
IO.Write(Temp + "raw_data_key_type=" , Key.RawData. KeyType );
|
||||
}
|
||||
IO.Write(Temp + "type=", Key.Type & 0xFF);
|
||||
if (Key.RawData.KeyType == null && Key.Trans == null && Key.Value != null)
|
||||
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 = IO.Offset + (int)MT.BinOffset;
|
||||
IO.Position = (int)MT.BinOffset;
|
||||
|
||||
IO.ReadOffset(ref MT.Scale);
|
||||
IO.ReadOffset(ref MT.Rot );
|
||||
IO.ReadOffset(ref MT.Trans);
|
||||
MT.Visibility.BinOffset = IO.ReadInt32();
|
||||
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);
|
||||
@@ -202,44 +254,55 @@ namespace KKdMainLib.A3DA
|
||||
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); }
|
||||
{ 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 = IO.Offset + (int)Key.BinOffset;
|
||||
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 Key.Transform[(int)Key.Length];
|
||||
int Ke = (int)Key.Length;
|
||||
if (Key.Type >> 8 != 0)
|
||||
{
|
||||
Key.EPTypePost = (Key.Type >> 12) & 0xF;
|
||||
Key.EPTypePre = (Key.Type >> 8) & 0xF;
|
||||
}
|
||||
Key.Type = Key.Type & 0xFF;
|
||||
Key.Trans = new IKeyFrame<double, double>[(int)Key.Length];
|
||||
KeyFrameT3<double, double> Temp;
|
||||
for (int i = 0; i < Key.Length; i++)
|
||||
{
|
||||
Key.Trans[i] = new Key.Transform { Type = 3, Value = new double[3] };
|
||||
Temp = new KeyFrameT3<double, double>();
|
||||
if (F16 && C_F16 > 0)
|
||||
{ Key.Trans[i].Frame = IO.ReadUInt16(); Key.Trans[i].Value[0] = (double)IO.ReadHalf (); }
|
||||
{ Temp.Frame = IO.ReadUInt16(); Temp.Value = (double)IO.ReadHalf (); }
|
||||
else
|
||||
{ Key.Trans[i].Frame = IO.ReadSingle(); Key.Trans[i].Value[0] = IO.ReadSingle(); }
|
||||
{ Temp.Frame = IO.ReadSingle(); Temp.Value = IO.ReadSingle(); }
|
||||
|
||||
if (F16 && C_F16 == 2)
|
||||
{ Key.Trans[i].Value[1] = (double)IO.ReadHalf ();
|
||||
Key.Trans[i].Value[2] = (double)IO.ReadHalf (); }
|
||||
{ Temp.Interpolation1 = (double)IO.ReadHalf ();
|
||||
Temp.Interpolation2 = (double)IO.ReadHalf (); }
|
||||
else
|
||||
{ Key.Trans[i].Value[1] = IO.ReadSingle();
|
||||
Key.Trans[i].Value[2] = IO.ReadSingle(); }
|
||||
{ Temp.Interpolation1 = IO.ReadSingle();
|
||||
Temp.Interpolation2 = IO.ReadSingle(); }
|
||||
|
||||
Key.Trans[i] = Temp.Check();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReadOffset(this Stream IO, ref Vector3<Key> Key)
|
||||
{ Key.X.BinOffset = IO.ReadInt32(); Key.Y.BinOffset = IO.ReadInt32(); Key.Z.BinOffset = IO.ReadInt32(); }
|
||||
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)
|
||||
{
|
||||
@@ -255,7 +318,7 @@ namespace KKdMainLib.A3DA
|
||||
{
|
||||
MT.BinOffset = IO.Position;
|
||||
IO.Position += 0x30;
|
||||
IO.Length += 0x30;
|
||||
IO.Length += 0x30;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,99 +355,152 @@ namespace KKdMainLib.A3DA
|
||||
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 new Key(); }
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadKey(); return null; }
|
||||
|
||||
public static Key ReadKey(this MsgPack k)
|
||||
{
|
||||
if (k == null) return new Key();
|
||||
if (k.Object == null) return null;
|
||||
|
||||
Key Key = new Key { EPTypePost = k.ReadNDouble("Post"),
|
||||
EPTypePre = k.ReadNDouble("Pre"), Max = k.ReadNDouble("M"),
|
||||
Key Key = new Key { EPTypePost = k.ReadNInt32("Post"),
|
||||
EPTypePre = k.ReadNInt32("Pre"), Max = k.ReadNDouble("M"),
|
||||
Type = k.ReadNInt32("T"), Value = k.ReadNDouble("V") };
|
||||
if (k.ReadBoolean("RD")) Key.RawData = new Key.RawD();
|
||||
if (k.ReadBoolean("RD")) Key.RawData = new Key.RawD() { KeyType = -1, ValueType = "float" };
|
||||
if (Key.Type == 0) Key.Value = 0.0;
|
||||
|
||||
if (Key.Type < 2) return Key;
|
||||
|
||||
if (!k.Element("Trans", out MsgPack Trans, typeof(object[]))) return Key;
|
||||
if (!k.ElementArray("Trans", out MsgPack Trans)) return Key;
|
||||
|
||||
Key.Length = ((object[])Trans.Object).Length;
|
||||
Key.Trans = new Key.Transform[Key.Length.Value];
|
||||
MsgPack _Trans = new MsgPack();
|
||||
byte i1 = 0;
|
||||
Key.Length = Trans.Array.Length;
|
||||
Key.Trans = new IKeyFrame<double, double>[Key.Length.Value];
|
||||
for (int i = 0; i < Key.Length; i++)
|
||||
{
|
||||
Key.Trans[i] = new Key.Transform();
|
||||
if (Trans[i].GetType() != typeof(MsgPack)) continue;
|
||||
|
||||
_Trans = (MsgPack)Trans[i];
|
||||
if (_Trans.Object.GetType() != typeof(object[])) continue;
|
||||
Key.Trans[i].Type = ((object[])_Trans.Object).Length - 1;
|
||||
Key.Trans[i].Value = new double[Key.Trans[i].Type];
|
||||
|
||||
if (_Trans[0].GetType() != typeof(MsgPack)) continue;
|
||||
Key.Trans[i].Frame = ((MsgPack)_Trans[0]).ReadDouble();
|
||||
|
||||
for (i1 = 0; i1 < Key.Trans[i].Type; i1++)
|
||||
Key.Trans[i].Value[i1] = ((MsgPack)_Trans[i1 + 1]).ReadDouble();
|
||||
if (Trans[i].Array == null) continue;
|
||||
else if (Trans[i].Array.Length == 0) continue;
|
||||
else if (Trans[i].Array.Length == 1)
|
||||
Key.Trans[i] = new KeyFrameT0<double, double>
|
||||
{ Frame = Trans[i][0].ReadDouble() };
|
||||
else if (Trans[i].Array.Length == 2)
|
||||
Key.Trans[i] = new KeyFrameT1<double, double>
|
||||
{
|
||||
Frame = Trans[i][0].ReadDouble(),
|
||||
Value = Trans[i][1].ReadDouble(),
|
||||
};
|
||||
else if (Trans[i].Array.Length == 3)
|
||||
Key.Trans[i] = new KeyFrameT2<double, double>
|
||||
{
|
||||
Frame = Trans[i][0].ReadDouble(),
|
||||
Value = Trans[i][1].ReadDouble(),
|
||||
Interpolation = Trans[i][2].ReadDouble(),
|
||||
};
|
||||
else if (Trans[i].Array.Length == 4)
|
||||
Key.Trans[i] = new KeyFrameT3<double, double>
|
||||
{
|
||||
Frame = Trans[i][0].ReadDouble(),
|
||||
Value = Trans[i][1].ReadDouble(),
|
||||
Interpolation1 = Trans[i][2].ReadDouble(),
|
||||
Interpolation2 = Trans[i][3].ReadDouble(),
|
||||
};
|
||||
Key.Trans[i] = Key.Trans[i].Check();
|
||||
}
|
||||
return Key;
|
||||
}
|
||||
|
||||
public static MsgPack WriteMP(this ModelTransform MT, string name) =>
|
||||
MT.WriteMP(new MsgPack(name));
|
||||
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 WriteMP(this ModelTransform MT) =>
|
||||
MT.WriteMP(new MsgPack( ));
|
||||
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 WriteMP(this ModelTransform MT, MsgPack MTs) =>
|
||||
MTs.Add(MT.Rot .WriteMP("Rot" ))
|
||||
.Add(MT.Scale .WriteMP("Scale" ))
|
||||
.Add(MT.Trans .WriteMP("Trans" ))
|
||||
.Add(MT.Visibility.WriteMP("Visibility"));
|
||||
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 WriteMP(this RGBAKey RGBA, string name)
|
||||
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 (RGBA.R == null && RGBA.G == null && RGBA.B == null && RGBA.A == null) return MsgPack.Null;
|
||||
return new MsgPack(name).Add(RGBA.R.WriteMP("R")).Add(RGBA.G.WriteMP("G"))
|
||||
.Add(RGBA.B.WriteMP("B")).Add(RGBA.A.WriteMP("A"));
|
||||
}
|
||||
|
||||
public static MsgPack WriteMP(this Vector3<Key> Key, string name) =>
|
||||
new MsgPack(name).Add(Key.X.WriteMP("X")).Add(Key.Y.WriteMP("Y")).Add(Key.Z.WriteMP("Z"));
|
||||
|
||||
public static MsgPack WriteMP(this KeyUV UV, string name)
|
||||
{
|
||||
if (UV.U == null && UV.V == null) return MsgPack.Null;
|
||||
return new MsgPack(name).Add(UV.U.WriteMP("U")).Add(UV.V.WriteMP("V"));
|
||||
}
|
||||
|
||||
public static MsgPack WriteMP(this Key Key, string name)
|
||||
{
|
||||
if (Key == null) return MsgPack.Null;
|
||||
if (Key.Type == null) return MsgPack.Null;
|
||||
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);
|
||||
Keys.Add("M", Key.Max).Add("Post", Key.EPTypePost).Add("Pre", Key.EPTypePre);
|
||||
|
||||
if (Key.RawData != null) Keys.Add("RD", true);
|
||||
|
||||
byte i0 = 0;
|
||||
MsgPack Trans = new MsgPack("Trans", Key.Trans.Length);
|
||||
if (Key.RawData.KeyType != null) Keys.Add("RD", true);
|
||||
|
||||
MsgPack Trans = new MsgPack(Key.Trans.Length, "Trans");
|
||||
MsgPack K;
|
||||
for (int i = 0; i < Key.Trans.Length; i++)
|
||||
{
|
||||
MsgPack K = new MsgPack(Key.Trans[i].Type + 1);
|
||||
K[0] = Key.Trans[i].Frame;
|
||||
for (i0 = 1; i0 < Key.Trans[i].Type + 1; i0++)
|
||||
K[i0] = Key.Trans[i].Value[i0 - 1];
|
||||
Trans[i] = K;
|
||||
}
|
||||
if (Key.Trans[i] is KeyFrameT0<double, double> KeyFrameT0)
|
||||
{
|
||||
K = new MsgPack(1);
|
||||
K[0] = (MsgPack)KeyFrameT0.Frame;
|
||||
Trans[i] = K;
|
||||
}
|
||||
else if (Key.Trans[i] is KeyFrameT1<double, double> KeyFrameT1)
|
||||
{
|
||||
K = new MsgPack(2);
|
||||
K[0] = (MsgPack)KeyFrameT1.Frame;
|
||||
K[1] = (MsgPack)KeyFrameT1.Value;
|
||||
Trans[i] = K;
|
||||
}
|
||||
else if (Key.Trans[i] is KeyFrameT2<double, double> KeyFrameT2)
|
||||
{
|
||||
K = new MsgPack(3);
|
||||
K[0] = (MsgPack)KeyFrameT2.Frame;
|
||||
K[1] = (MsgPack)KeyFrameT2.Value;
|
||||
K[2] = (MsgPack)KeyFrameT2.Interpolation;
|
||||
Trans[i] = K;
|
||||
}
|
||||
else if (Key.Trans[i] is KeyFrameT3<double, double> KeyFrameT3)
|
||||
{
|
||||
K = new MsgPack(4);
|
||||
K[0] = (MsgPack)KeyFrameT3.Frame;
|
||||
K[1] = (MsgPack)KeyFrameT3.Value;
|
||||
K[2] = (MsgPack)KeyFrameT3.Interpolation1;
|
||||
K[3] = (MsgPack)KeyFrameT3.Interpolation2;
|
||||
Trans[i] = K;
|
||||
}
|
||||
Keys.Add(Trans);
|
||||
}
|
||||
else if (Key.Value != 0) Keys.Add("V", Key.Value);
|
||||
return Keys;
|
||||
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()); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,933 @@
|
||||
//Original: AetSet.bt Version: 2.0 by samyuu
|
||||
|
||||
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, i1;
|
||||
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.Layers = IO.ReadCountPointer< AetLayer>();
|
||||
Aet.SpriteEntries = IO.ReadCountPointer<SpriteEntry>();
|
||||
Aet.Unknown = IO.ReadCountPointer<int>();
|
||||
|
||||
IO.Position = Aet.Layers.Offset;
|
||||
for (i = 0; i < Aet.Layers.Count; i++)
|
||||
Aet.Layers[i] = new AetLayer() { Pointer = IO.Position,
|
||||
Count = IO.ReadInt32(), Offset = IO.ReadInt32()};
|
||||
|
||||
for (i = 0, i1 = 0; i < Aet.Layers.Count; i++)
|
||||
{
|
||||
IO.Position = Aet.Layers[i].Offset;
|
||||
for (i0 = 0; i0 < Aet.Layers[i].Count; i0++, i1++)
|
||||
{
|
||||
Aet.Layers[i].Objects[i0] = IO.ReadAetObject();
|
||||
Aet.Layers[i].Objects[i0].ID = i1;
|
||||
}
|
||||
}
|
||||
|
||||
IO.Position = Aet.SpriteEntries.Offset;
|
||||
for (i = 0; i < Aet.SpriteEntries.Count; i++)
|
||||
Aet.SpriteEntries[i] = new SpriteEntry
|
||||
{ Offset = IO.Position, Unknown = IO.ReadInt32(), Width = IO.ReadInt16(),
|
||||
Height = IO.ReadInt16(), Frames = IO.ReadSingle(), Sprites = IO.ReadCountPointer<Sprite>() };
|
||||
|
||||
for (i = 0; i < Aet.SpriteEntries.Count; i++)
|
||||
{
|
||||
IO.Position = Aet.SpriteEntries[i].Sprites.Offset;
|
||||
for (i0 = 0; i0 < Aet.SpriteEntries[i].Sprites.Count; i0++)
|
||||
Aet.SpriteEntries.Entries[i].Sprites[i0] =
|
||||
new Sprite { Name = IO.ReadPointerString(), ID = IO.ReadInt32() };
|
||||
}
|
||||
}
|
||||
|
||||
public void AETWriter(ref Pointer<AetData> AET)
|
||||
{
|
||||
ref AetData Aet = ref AET.Value;
|
||||
|
||||
for (i = 0; i < Aet.SpriteEntries.Count; i++)
|
||||
{
|
||||
ref SpriteEntry SprEnt = ref Aet.SpriteEntries.Entries[i];
|
||||
if (SprEnt.Sprites.Count == 0) { SprEnt.Sprites.Offset = 0; continue; }
|
||||
if (SprEnt.Sprites.Count > 1) IO.Align(0x20);
|
||||
SprEnt.Sprites.Offset = IO.Position;
|
||||
for (i0 = 0; i0 < SprEnt.Sprites.Count; i0++)
|
||||
IO.Write(0L);
|
||||
}
|
||||
|
||||
IO.Align(0x20);
|
||||
Aet.SpriteEntries.Offset = IO.Position;
|
||||
for (i = 0; i < Aet.SpriteEntries.Count; i++)
|
||||
{
|
||||
ref SpriteEntry SprEnt = ref Aet.SpriteEntries.Entries[i];
|
||||
SprEnt.Offset = IO.Position;
|
||||
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.Layers.Offset = IO.Position;
|
||||
for (i = 0; i < Aet.Layers.Count; i++)
|
||||
{
|
||||
Aet.Layers.Entries[i].Offset = IO.Position;
|
||||
IO.Write(0L);
|
||||
}
|
||||
|
||||
KKdList<int> NullValPointers = KKdList<int>.New;
|
||||
for (i = 0; i < Aet.Layers.Count; i++)
|
||||
{
|
||||
if (Aet.Layers.Entries[i].Count < 1) continue;
|
||||
|
||||
for (i0 = 0; i0 < Aet.Layers.Entries[i].Count; i0++)
|
||||
IO.Write(ref Aet.Layers.Entries[i].Objects[i0], ref NullValPointers);
|
||||
|
||||
IO.Align(0x20);
|
||||
Aet.Layers.Entries[i].Objects[0].Offset = IO.Position;
|
||||
for (i0 = 0; i0 < Aet.Layers.Entries[i].Count; i0++)
|
||||
IO.Write(ref Aet.Layers.Entries[i].Objects[i0]);
|
||||
}
|
||||
|
||||
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);
|
||||
{
|
||||
System.Collections.Generic.Dictionary<string, int> UsedValues =
|
||||
new System.Collections.Generic.Dictionary<string, int>();
|
||||
|
||||
for (i = 0; i < Aet.SpriteEntries.Count; i++)
|
||||
{
|
||||
ref SpriteEntry SprEnt = ref Aet.SpriteEntries.Entries[i];
|
||||
for (i0 = 0; i0 < SprEnt.Sprites.Count; i0++)
|
||||
IO.WritePointerString(ref UsedValues, ref SprEnt.Sprites.Entries[i0].Name);
|
||||
}
|
||||
|
||||
//IO.Align(0x4);
|
||||
for (i = 0; i < Aet.Layers.Count; i++)
|
||||
for (i0 = 0; i0 < Aet.Layers.Entries[i].Count; i0++)
|
||||
{
|
||||
ref AetObject Obj = ref Aet.Layers.Entries[i].Objects[i0];
|
||||
if (Obj.Type == AetObject.ObjType.Pic)
|
||||
for (i1 = 0; i1 < Obj.Pic.Value.Marker.Count; i1++)
|
||||
IO.WritePointerString(ref UsedValues, ref Obj.Pic.Value.Marker.Entries[i1].Name);
|
||||
else if (Obj.Type == AetObject.ObjType.Eff)
|
||||
for (i1 = 0; i1 < Obj.Eff.Value.Marker.Count; i1++)
|
||||
IO.WritePointerString(ref UsedValues, ref Obj.Eff.Value.Marker.Entries[i1].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.Write(0);
|
||||
|
||||
IO.Align(0x10, true);
|
||||
|
||||
for (i = 0; i < NullValPointers.Count; i++)
|
||||
{
|
||||
IO.Position = NullValPointers[i];
|
||||
IO.Write(ReturnPosition + i * 4);
|
||||
}
|
||||
|
||||
for (i = 0; i < Aet.Layers.Count; i++)
|
||||
for (i0 = 0; i0 < Aet.Layers.Entries[i].Count; i0++)
|
||||
{
|
||||
ref AetObject Obj = ref Aet.Layers.Entries[i].Objects[i0];
|
||||
if (Obj.Type == AetObject.ObjType.Pic)
|
||||
{
|
||||
IO.Position = Obj.Pic.Offset;
|
||||
IO.Write(Aet.SpriteEntries[Obj.Pic.Value.SpriteEntryID].Offset);
|
||||
if (Obj.Pic.Value.ParentObjectID > -1)
|
||||
{
|
||||
bool Found = false;
|
||||
for (int I = 0; I < Aet.Layers.Count; I++)
|
||||
for (int I0 = 0; I0 < Aet.Layers.Entries[I].Count; I0++)
|
||||
if (Aet.Layers[I][I0].ID == Obj.Pic.Value.ParentObjectID)
|
||||
{
|
||||
Found = true;
|
||||
IO.Write(Aet.Layers.Entries[I].Objects[I0].Offset);
|
||||
break;
|
||||
}
|
||||
if (!Found) IO.Write(0);
|
||||
}
|
||||
else IO.Write(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 (i1 = 0; i1 < Marker.Count; i1++)
|
||||
{
|
||||
IO.Write(Marker[i1].Frame);
|
||||
IO.Write(Marker[i1].Name.Offset);
|
||||
}
|
||||
}
|
||||
else if (Obj.Type == AetObject.ObjType.Eff)
|
||||
{
|
||||
IO.Position = Obj.Eff.Offset;
|
||||
IO.Write(Aet.Layers[Obj.Eff.Value.LayerID].Offset);
|
||||
if (Obj.Eff.Value.ParentObjectID > -1)
|
||||
{
|
||||
bool Found = false;
|
||||
for (int I = 0; I < Aet.Layers.Count; I++)
|
||||
for (int I0 = 0; I0 < Aet.Layers.Entries[I].Count; I0++)
|
||||
if (Aet.Layers[I][I0].ID == Obj.Eff.Value.ParentObjectID)
|
||||
{
|
||||
Found = true;
|
||||
IO.Write(Aet.Layers.Entries[I].Objects[I0].Offset);
|
||||
break;
|
||||
}
|
||||
if (!Found) IO.Write(0);
|
||||
}
|
||||
else IO.Write(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 (i1 = 0; i1 < Marker.Count; i1++)
|
||||
{
|
||||
IO.Write(Marker[i1].Frame);
|
||||
IO.Write(Marker[i1].Name.Offset);
|
||||
}
|
||||
}
|
||||
|
||||
IO.Position = Obj.Offset;
|
||||
IO.Write(Obj.Name.Offset);
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < Aet.SpriteEntries.Count; i++)
|
||||
{
|
||||
ref SpriteEntry SprEnt = ref Aet.SpriteEntries.Entries[i];
|
||||
if (SprEnt.Sprites.Count == 0) continue;
|
||||
IO.Position = SprEnt.Sprites.Offset;
|
||||
for (i0 = 0; i0 < SprEnt.Sprites.Count; i0++)
|
||||
{
|
||||
IO.Write(SprEnt.Sprites[i0].Name.Offset);
|
||||
IO.Write(SprEnt.Sprites[i0].ID);
|
||||
}
|
||||
}
|
||||
|
||||
IO.Position = Aet.Layers.Offset;
|
||||
for (i = 0; i < Aet.Layers.Count; i++)
|
||||
{
|
||||
if (Aet.Layers[i].Count > 0)
|
||||
{
|
||||
IO.Write(Aet.Layers[i].Count);
|
||||
IO.Write(Aet.Layers[i].Objects[0].Offset);
|
||||
}
|
||||
else IO.Write(0L);
|
||||
}
|
||||
|
||||
IO.Position = AET.Offset;
|
||||
IO.Write(Aet.Name.Offset);
|
||||
IO.Position = AET.Offset + 0x20;
|
||||
IO.Write(Aet.Layers.Count );
|
||||
IO.Write(Aet.Layers.Offset);
|
||||
IO.Write(Aet.SpriteEntries.Count );
|
||||
IO.Write(Aet.SpriteEntries.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.ElementArray("Aet", out MsgPack Aet)) { MsgPack.Dispose(); 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++)
|
||||
MsgPackReader(Aet.Array[i], ref AET.Data[i] );
|
||||
}
|
||||
|
||||
MsgPack.Dispose();
|
||||
}
|
||||
|
||||
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("Unknown", out Temp))
|
||||
Aet.Unknown.Count = Temp.ReadInt32();
|
||||
|
||||
|
||||
if (AET.ElementArray("SpriteEntries", out Temp))
|
||||
{
|
||||
Aet.SpriteEntries.Count = Temp.Array.Length;
|
||||
for (i = 0; i < Aet.SpriteEntries.Count; i++)
|
||||
Aet.SpriteEntries.Entries[i].ReadMP(Temp[i]);
|
||||
}
|
||||
else return;
|
||||
|
||||
|
||||
if (AET.ElementArray("Layers", out Temp))
|
||||
{
|
||||
Aet.Layers.Count = Temp.Array.Length + 1;
|
||||
for (i = 0; i < Aet.Layers.Count - 1; i++)
|
||||
Aet.Layers.Entries[i].ReadMP(Temp[i]);
|
||||
}
|
||||
else return;
|
||||
|
||||
|
||||
i = Aet.Layers.Count - 1;
|
||||
if (AET.ElementArray("RootLayer", out Temp))
|
||||
{
|
||||
Aet.Layers.Entries[i].Count = Temp.Array.Length;
|
||||
for (i0 = 0; i0 < Aet.Layers[i].Count; i0++)
|
||||
Aet.Layers.Entries[i].Objects[i0].ReadMP(Temp[i0]);
|
||||
}
|
||||
else if (AET.Element("RootLayer", out Temp))
|
||||
{
|
||||
Aet.Layers.Entries[i].Count = 1;
|
||||
Aet.Layers.Entries[i].Objects[0].ReadMP(Temp);
|
||||
}
|
||||
else return;
|
||||
|
||||
AetData.Offset = 0;
|
||||
}
|
||||
|
||||
public MsgPack MsgPackWriter(ref Pointer<AetData> AetData)
|
||||
{
|
||||
if (AetData.Offset <= 0) return MsgPack.New;
|
||||
ref AetData Aet = ref AetData.Value;
|
||||
|
||||
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.Unknown.Count > 0)
|
||||
AET.Add("Unknown", Aet.Unknown.Count);
|
||||
|
||||
i = Aet.Layers.Count - 1;
|
||||
if (Aet.Layers[i].Count == 1)
|
||||
AET.Add(Aet.Layers[i][0].WriteMP(ref Aet, "RootLayer"));
|
||||
if (Aet.Layers[i].Count > 1)
|
||||
{
|
||||
MsgPack RootLayer = new MsgPack(Aet.Layers[i].Count, "RootLayer");
|
||||
for (i0 = 0; i0 < Aet.Layers[i].Count; i0++)
|
||||
RootLayer[i0] = Aet.Layers[i][i0].WriteMP(ref Aet);
|
||||
AET.Add(RootLayer);
|
||||
}
|
||||
|
||||
MsgPack Layers = new MsgPack(Aet.Layers.Count - 1, "Layers");
|
||||
for (i = 0; i < Aet.Layers.Count - 1; i++)
|
||||
Layers[i] = Aet.Layers[i].WriteMP(i, ref Aet);
|
||||
AET.Add(Layers);
|
||||
|
||||
MsgPack SpriteEntries = new MsgPack(Aet.SpriteEntries.Count, "SpriteEntries");
|
||||
for (i = 0; i < Aet.SpriteEntries.Count; i++)
|
||||
SpriteEntries[i] = Aet.SpriteEntries[i].WriteMP(i);
|
||||
AET.Add(SpriteEntries);
|
||||
|
||||
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< AetLayer> Layers;
|
||||
public CountPointer<SpriteEntry> SpriteEntries;
|
||||
public CountPointer<int> Unknown;
|
||||
}
|
||||
|
||||
public struct AetLayer
|
||||
{
|
||||
public int Pointer;
|
||||
public int Count
|
||||
{
|
||||
get => Objects != null ? Objects.Length : 0;
|
||||
set => Objects = new AetObject[value];
|
||||
}
|
||||
public int Offset;
|
||||
public AetObject[] Objects;
|
||||
|
||||
public void ReadMP(MsgPack msg)
|
||||
{
|
||||
if (msg.Element("Object", out MsgPack Object))
|
||||
{
|
||||
Count = 1;
|
||||
Objects[0].ReadMP(Object);
|
||||
}
|
||||
else if (msg.ElementArray("Objects", out MsgPack Objects))
|
||||
{
|
||||
Count = Objects.Array.Length;
|
||||
for (int i0 = 0; i0 < Count; i0++)
|
||||
this.Objects[i0].ReadMP(Objects[i0]);
|
||||
}
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(int Id, ref AetData Aet)
|
||||
{
|
||||
if (Count < 1)
|
||||
return MsgPack.New.Add("ID", Id);
|
||||
else if (Count == 1)
|
||||
return MsgPack.New.Add("ID", Id).Add(this.Objects[0].WriteMP(ref Aet, "Object"));
|
||||
MsgPack Objects = new MsgPack(Count, "Objects");
|
||||
for (int i = 0; i < Count; i++)
|
||||
Objects[i] = this.Objects[i].WriteMP(ref Aet);
|
||||
return MsgPack.New.Add("ID", Id).Add(Objects);
|
||||
}
|
||||
|
||||
public AetObject this[int index]
|
||||
{
|
||||
get => Count > 0 ? Objects[index] : default;
|
||||
set { if (Count > 0) { Objects[index] = value; } }
|
||||
}
|
||||
|
||||
public override string ToString() => "Count: " + Count;
|
||||
}
|
||||
|
||||
public struct AetObject
|
||||
{
|
||||
public int ID;
|
||||
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<Picture> Pic;
|
||||
public Pointer<Audio > Aif;
|
||||
public Pointer<Effect > Eff;
|
||||
|
||||
public void ReadMP(MsgPack msg)
|
||||
{
|
||||
ID = msg.ReadInt32 ("ID" );
|
||||
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.Value.ReadMP(Pic); }
|
||||
else if (msg.Element("Aif", out MsgPack Aif))
|
||||
{ Type = ObjType.Aif; this.Aif.Value.ReadMP(Aif); }
|
||||
else if (msg.Element("Eff", out MsgPack Eff))
|
||||
{ Type = ObjType.Eff; this.Eff.Value.ReadMP(Eff); }
|
||||
else Type = ObjType.Nop;
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(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 enum ObjType : byte
|
||||
{
|
||||
Nop = 0,
|
||||
Pic = 1,
|
||||
Aif = 2,
|
||||
Eff = 3,
|
||||
}
|
||||
|
||||
public struct Picture
|
||||
{
|
||||
public int SpriteEntryID;
|
||||
public int ParentObjectID;
|
||||
public CountPointer<Marker> Marker;
|
||||
public Pointer<AnimationData> Data;
|
||||
|
||||
public Picture ReadMP(MsgPack msg)
|
||||
{
|
||||
SpriteEntryID = msg.ReadInt32("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.ElementArray("Markers", out MsgPack Markers))
|
||||
{
|
||||
this.Marker.Count = Markers.Array.Length;
|
||||
for (int i = 0; i < Markers.Array.Length; i++)
|
||||
this.Marker.Entries[i].ReadMP(Markers[i]);
|
||||
}
|
||||
else this.Marker.Entries = null;
|
||||
|
||||
Data.Value.ReadMP(msg);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(ref AetData Aet)
|
||||
{
|
||||
MsgPack Pic = new MsgPack("Pic");
|
||||
for (int i = 0; i < Aet.SpriteEntries.Count; i++)
|
||||
if (Aet.SpriteEntries[i].Offset == SpriteEntryID)
|
||||
{ Pic.Add("SpriteEntryID", i); break; }
|
||||
|
||||
if (ParentObjectID > 0)
|
||||
for (int i = 0; i < Aet.Layers.Count; i++)
|
||||
for (int i1 = 0; i1 < Aet.Layers[i].Count; i1++)
|
||||
if (Aet.Layers[i][i1].Offset == ParentObjectID)
|
||||
{ Pic.Add("ParentObjectID", Aet.Layers[i][i1].ID); break; }
|
||||
|
||||
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 Audio
|
||||
{
|
||||
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 void ReadMP(MsgPack msg) =>
|
||||
Value.Value = msg.ReadMP(ref Unk0, "Unk0").ReadMP(ref Unk1, "Unk1")
|
||||
.ReadMP(ref Unk2, "Unk2").ReadMP(ref Unk3, "Unk3").ReadInt32("Value");
|
||||
|
||||
public MsgPack WriteMP() =>
|
||||
new MsgPack("Aif").Add("Value", Value.Value).Add("Unk0", Unk0)
|
||||
.Add("Unk1", Unk0).Add("Unk2", Unk2).Add("Unk3", Unk3);
|
||||
}
|
||||
|
||||
public struct Effect
|
||||
{
|
||||
public int LayerID;
|
||||
public int ParentObjectID;
|
||||
public CountPointer<Marker> Marker;
|
||||
public Pointer<AnimationData> Data;
|
||||
|
||||
public void ReadMP(MsgPack msg)
|
||||
{
|
||||
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.ElementArray("Markers", out MsgPack Markers))
|
||||
{
|
||||
this.Marker.Count = Markers.Array.Length;
|
||||
for (int i = 0; i < Markers.Array.Length; i++)
|
||||
this.Marker.Entries[i].ReadMP(Markers[i]);
|
||||
}
|
||||
else this.Marker.Entries = null;
|
||||
|
||||
Data.Value.ReadMP(msg);
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(ref AetData Aet)
|
||||
{
|
||||
MsgPack Eff = new MsgPack("Eff");
|
||||
for (int i = 0; i < Aet.Layers.Count; i++)
|
||||
if (Aet.Layers[i].Pointer == LayerID)
|
||||
{ Eff.Add("LayerID", i); break; }
|
||||
if (ParentObjectID > 0)
|
||||
for (int i = 0; i < Aet.Layers.Count; i++)
|
||||
for (int i1 = 0; i1 < Aet.Layers[i].Count; i1++)
|
||||
if (Aet.Layers[i][i1].Offset == ParentObjectID)
|
||||
{ Eff.Add("ParentObjectID", Aet.Layers[i][i1].ID); break; }
|
||||
|
||||
if (Marker.Count == 1)
|
||||
Eff.Add(Marker[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[i].WriteMP();
|
||||
Eff.Add(Markers);
|
||||
}
|
||||
|
||||
Eff.Add(Data.Value.WriteMP());
|
||||
|
||||
return Eff;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() => Name.Value;
|
||||
}
|
||||
|
||||
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 Mode;
|
||||
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 Mode);
|
||||
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", Mode.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 enum BlendMode : byte
|
||||
{
|
||||
Alpha = 3,
|
||||
Additive = 5,
|
||||
DstColorZero = 6,
|
||||
SrcAlphaOneMinusSrcColor = 7,
|
||||
Transparent = 8,
|
||||
}
|
||||
}
|
||||
|
||||
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.ElementArray(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++)
|
||||
{
|
||||
KeyFrame [i] = Temp[i].ReadSingle("KeyFrame" );
|
||||
ArrValue [i] = Temp[i].ReadSingle("Value" );
|
||||
Interpolation[i] = Temp[i].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 Offset;
|
||||
public int Unknown;
|
||||
public short Width;
|
||||
public short Height;
|
||||
public float Frames;
|
||||
public CountPointer<Sprite> Sprites;
|
||||
|
||||
public void ReadMP(MsgPack msg)
|
||||
{
|
||||
Unknown = msg.ReadInt32 ("Unknown");
|
||||
Width = msg.ReadInt16 ("Width" );
|
||||
Height = msg.ReadInt16 ("Height" );
|
||||
Frames = msg.ReadSingle("Frames" );
|
||||
|
||||
if (msg.Element("Sprite", out MsgPack Sprite))
|
||||
{
|
||||
Sprites.Count = 1;
|
||||
Sprites[0] = new Sprite() { Name = new Pointer<string>()
|
||||
{ Value = Sprite.ReadString("Name") }, ID = Sprite.ReadInt32("ID") };
|
||||
}
|
||||
else if (msg.ElementArray("Sprites", out MsgPack Sprites))
|
||||
{
|
||||
this.Sprites.Count = Sprites.Array.Length;
|
||||
for (int i0 = 0; i0 < this.Sprites.Count; i0++)
|
||||
this.Sprites[i0] = new Sprite() { Name = new Pointer<string>()
|
||||
{ Value = Sprites[i0].ReadString("Name") }, ID = Sprites[i0].ReadInt32("ID") };
|
||||
}
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(int Id)
|
||||
{
|
||||
MsgPack SpriteEntry = MsgPack.New.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(new MsgPack("Sprite").Add("Name",
|
||||
Sprites[0].Name.Value).Add("ID", Sprites[0].ID));
|
||||
else if (Sprites.Count > 1)
|
||||
{
|
||||
MsgPack Sprites = new MsgPack(this.Sprites.Count, "Sprites");
|
||||
for (int i0 = 0; i0 < this.Sprites.Count; i0++)
|
||||
Sprites[i0] = MsgPack.New.Add("Name",
|
||||
this.Sprites[i0].Name.Value).Add("ID", this.Sprites[i0].ID);
|
||||
SpriteEntry.Add(Sprites);
|
||||
}
|
||||
|
||||
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 override string ToString() => "ID: " + ID + "; Name: " + Name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,449 @@
|
||||
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 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) =>
|
||||
new CountPointer<T> { Count = IO.ReadInt32(), Offset = IO.ReadInt32() };
|
||||
|
||||
public static MsgPack ReadMP(this MsgPack msg, ref CountPointer<float> val, string Name)
|
||||
{
|
||||
val.Offset = 0;
|
||||
val.Entries = null;
|
||||
if (msg.ContainsKey(Name))
|
||||
{
|
||||
val.Count = 1;
|
||||
val[0] = msg.ReadSingle(Name);
|
||||
}
|
||||
else if(msg.ElementArray(Name, out MsgPack Temp))
|
||||
{
|
||||
val.Count = Temp.Array.Length;
|
||||
for (int i = 0; i < val.Count; i++)
|
||||
val[i] = Temp[i].ReadSingle();
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static MsgPack Add(this MsgPack MsgPack, string Name, CountPointer<float> val)
|
||||
{
|
||||
if (val.Count == 1) return MsgPack.Add(new MsgPack(Name, val[0]));
|
||||
else if (val.Count > 1)
|
||||
{
|
||||
MsgPack Val = new MsgPack(val.Count, Name);
|
||||
for (int i = 0; i < val.Count; i++) Val[i] = (MsgPack)val[i];
|
||||
return MsgPack.Add(Val);
|
||||
}
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
public static AetObject ReadAetObject(this Stream IO)
|
||||
{
|
||||
AetObject Anim = new AetObject() { Offset = IO.Position };
|
||||
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 = (AetObject.ObjType)IO.ReadByte();
|
||||
if (Anim.Type == AetObject.ObjType.Pic)
|
||||
{
|
||||
Anim.Pic = new Pointer<AetObject.Picture> { Offset = IO.Position,
|
||||
Value = new AetObject.Picture
|
||||
{
|
||||
SpriteEntryID = IO.ReadInt32(),
|
||||
ParentObjectID = IO.ReadInt32(),
|
||||
Marker = IO.ReadCountPointer<Marker>()
|
||||
}
|
||||
};
|
||||
ref AetObject.Picture Pic = ref Anim.Pic.Value;
|
||||
Pic.Data.Offset = IO.ReadInt32();
|
||||
IO.ReadAnimData(ref Pic.Data);
|
||||
|
||||
IO.Position = Pic.Marker.Offset;
|
||||
for (int i = 0; i < Pic.Marker.Count; i++)
|
||||
Pic.Marker[i] = new Marker()
|
||||
{ Frame = IO.ReadSingle(), Name = IO.ReadPointerStringShiftJIS() };
|
||||
}
|
||||
else if (Anim.Type == AetObject.ObjType.Aif)
|
||||
{
|
||||
Anim.Aif = new Pointer<AetObject.Audio> { Offset = IO.Position,
|
||||
Value = new AetObject.Audio
|
||||
{
|
||||
Value = IO.ReadPointer<int>(),
|
||||
Zero0 = IO.ReadInt32(),
|
||||
Zero1 = IO.ReadInt32(),
|
||||
Zero2 = IO.ReadInt32(),
|
||||
Zero3 = IO.ReadInt32(),
|
||||
Pointer = IO.ReadInt32(),
|
||||
}
|
||||
};
|
||||
|
||||
ref AetObject.Audio Aif = ref Anim.Aif.Value;
|
||||
|
||||
IO.Position = Aif.Value.Offset;
|
||||
Aif.Value.Value = IO.ReadInt32();
|
||||
|
||||
IO.Position = Aif.Pointer;
|
||||
Aif.Unk0 = IO.ReadCountPointer<float>();
|
||||
Aif.Unk1 = IO.ReadCountPointer<float>();
|
||||
Aif.Unk2 = IO.ReadCountPointer<float>();
|
||||
Aif.Unk3 = IO.ReadCountPointer<float>();
|
||||
|
||||
IO.Position = Aif.Unk0.Offset;
|
||||
for (int i = 0; i < Aif.Unk0.Count; i++) Aif.Unk0[i] = IO.ReadSingle();
|
||||
IO.Position = Aif.Unk1.Offset;
|
||||
for (int i = 0; i < Aif.Unk1.Count; i++) Aif.Unk1[i] = IO.ReadSingle();
|
||||
IO.Position = Aif.Unk2.Offset;
|
||||
for (int i = 0; i < Aif.Unk2.Count; i++) Aif.Unk2[i] = IO.ReadSingle();
|
||||
IO.Position = Aif.Unk3.Offset;
|
||||
for (int i = 0; i < Aif.Unk3.Count; i++) Aif.Unk3[i] = IO.ReadSingle();
|
||||
}
|
||||
else if (Anim.Type == AetObject.ObjType.Eff)
|
||||
{
|
||||
Anim.Eff = new Pointer<AetObject.Effect> { Offset = IO.Position,
|
||||
Value = new AetObject.Effect
|
||||
{
|
||||
LayerID = IO.ReadInt32(),
|
||||
ParentObjectID = IO.ReadInt32(),
|
||||
Marker = IO.ReadCountPointer<Marker>()
|
||||
}
|
||||
};
|
||||
ref AetObject.Effect Eff = ref Anim.Eff.Value;
|
||||
Eff.Data.Offset = IO.ReadInt32();
|
||||
IO.Position = Eff.Marker.Offset;
|
||||
for (int i = 0; i < Eff.Marker.Count; i++)
|
||||
Eff.Marker[i] = new Marker()
|
||||
{ Frame = IO.ReadSingle(), Name = IO.ReadPointerStringShiftJIS() };
|
||||
IO.ReadAnimData(ref Eff.Data);
|
||||
}
|
||||
IO.Position = Anim.Offset + 0x30;
|
||||
return Anim;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ref AetObject Anim, ref KKdList<int> NullValPointers)
|
||||
{
|
||||
if (Anim.Type == AetObject.ObjType.Pic)
|
||||
{
|
||||
ref AetObject.Picture Pic = ref Anim.Pic.Value;
|
||||
if (Pic.Marker.Count > 0)
|
||||
{
|
||||
Pic.Marker.Offset = IO.Position;
|
||||
for (int i = 0; i < Pic.Marker.Count; i++) IO.Write(0L);
|
||||
}
|
||||
IO.Write(ref Pic.Data, ref NullValPointers);
|
||||
}
|
||||
else if (Anim.Type == AetObject.ObjType.Aif)
|
||||
{
|
||||
ref AetObject.Audio Aif = ref Anim.Aif.Value;
|
||||
if (Aif.Unk0.Count > 0) { Aif.Unk0.Offset = IO.Position;
|
||||
for (int i = 0; i < Aif.Unk0.Count; i++) IO.Write(Aif.Unk0[i]); }
|
||||
if (Aif.Unk1.Count > 0) { Aif.Unk1.Offset = IO.Position;
|
||||
for (int i = 0; i < Aif.Unk1.Count; i++) IO.Write(Aif.Unk1[i]); }
|
||||
if (Aif.Unk2.Count > 0) { Aif.Unk2.Offset = IO.Position;
|
||||
for (int i = 0; i < Aif.Unk2.Count; i++) IO.Write(Aif.Unk2[i]); }
|
||||
if (Aif.Unk3.Count > 0) { Aif.Unk3.Offset = IO.Position;
|
||||
for (int i = 0; i < Aif.Unk3.Count; i++) IO.Write(Aif.Unk3[i]); }
|
||||
|
||||
IO.Align(0x10);
|
||||
Aif.Value.Offset = IO.Position;
|
||||
IO.Write(Aif.Value.Value);
|
||||
|
||||
IO.Align(0x10);
|
||||
Aif.Pointer = IO.Position;
|
||||
if (Aif.Unk0.Count > 0) { IO.Write(Aif.Unk0.Count); IO.Write(Aif.Unk0.Offset); } else IO.Write(0L);
|
||||
if (Aif.Unk1.Count > 0) { IO.Write(Aif.Unk1.Count); IO.Write(Aif.Unk1.Offset); } else IO.Write(0L);
|
||||
if (Aif.Unk2.Count > 0) { IO.Write(Aif.Unk2.Count); IO.Write(Aif.Unk2.Offset); } else IO.Write(0L);
|
||||
if (Aif.Unk3.Count > 0) { IO.Write(Aif.Unk3.Count); IO.Write(Aif.Unk3.Offset); } else IO.Write(0L);
|
||||
}
|
||||
else if (Anim.Type == AetObject.ObjType.Eff)
|
||||
{
|
||||
ref AetObject.Effect Eff = ref Anim.Eff.Value;
|
||||
if (Eff.Marker.Count > 0)
|
||||
{
|
||||
Eff.Marker.Offset = IO.Position;
|
||||
for (int i = 0; i < Eff.Marker.Count; i++) IO.Write(0L);
|
||||
}
|
||||
IO.Write(ref Eff.Data, ref NullValPointers);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ref AetObject Anim)
|
||||
{
|
||||
Anim.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 == AetObject.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 == AetObject.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 == AetObject.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 void ReadAnimData(this Stream IO, ref Pointer<AnimationData> Anim)
|
||||
{
|
||||
ref AnimationData Data = ref Anim.Value;
|
||||
IO.Position = Anim.Offset;
|
||||
Data.Mode = (AnimationData.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 KKdList<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.Mode);
|
||||
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 KKdList<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 KKdList<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.ElementArray("Markers", out MsgPack Markers))
|
||||
{
|
||||
mark.Count = Markers.Array.Length;
|
||||
for (int i = 0; i < mark.Count; i++)
|
||||
mark.Entries[i].ReadMP(Markers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WritePointerString(this Stream IO,
|
||||
ref System.Collections.Generic.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"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,268 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.DB
|
||||
{
|
||||
public class Aet
|
||||
{
|
||||
public AetSet[] AetSets;
|
||||
|
||||
private Stream IO;
|
||||
private int i, i0, i1, i2;
|
||||
|
||||
public void BINReader(string file)
|
||||
{
|
||||
IO = File.OpenReader(file + ".bin");
|
||||
|
||||
int aetSetsLength = IO.ReadInt32();
|
||||
int aetSetsOffset = IO.ReadInt32();
|
||||
int aetsLength = IO.ReadInt32();
|
||||
int aetsOffset = IO.ReadInt32();
|
||||
|
||||
IO.Position = aetSetsOffset;
|
||||
AetSets = new AetSet[aetSetsLength];
|
||||
for (i = 0; i < aetSetsLength; i++)
|
||||
{
|
||||
AetSets[i].Id = IO.ReadInt32();
|
||||
AetSets[i].Name = IO.ReadStringAtOffset();
|
||||
AetSets[i].FileName = IO.ReadStringAtOffset();
|
||||
IO.ReadInt32();
|
||||
AetSets[i].SpriteSetId = IO.ReadInt32();
|
||||
}
|
||||
|
||||
int setIndex;
|
||||
AET aet = new AET();
|
||||
int[] AetCount = new int[aetSetsLength];
|
||||
|
||||
IO.Position = aetsOffset;
|
||||
for (i = 0; i < aetsLength; i++)
|
||||
{
|
||||
IO.LongPosition += 10;
|
||||
setIndex = IO.ReadInt16();
|
||||
AetCount[setIndex]++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < aetSetsLength; i++)
|
||||
{
|
||||
AetSets[i].Aets = new AET[AetCount[i]];
|
||||
AetCount[i] = 0;
|
||||
}
|
||||
|
||||
IO.Position = aetsOffset;
|
||||
for (i = 0; i < aetsLength; i++)
|
||||
{
|
||||
aet.Id = IO.ReadInt32();
|
||||
aet.Name = IO.ReadStringAtOffset();
|
||||
IO.ReadInt16();
|
||||
setIndex = IO.ReadInt16();
|
||||
|
||||
AetSets[setIndex].Aets[AetCount[setIndex]] = aet; AetCount[setIndex]++;
|
||||
}
|
||||
|
||||
IO.Close();
|
||||
}
|
||||
|
||||
|
||||
public void BINWriter(string file)
|
||||
{
|
||||
if (AetSets == null) return;
|
||||
if (AetSets.Length == 0) return;
|
||||
|
||||
List<string> SetName = new List<string>();
|
||||
List<string> SetFileName = new List<string>();
|
||||
|
||||
List<int> Ids = new List<int>();
|
||||
List<int> SetIds = new List<int>();
|
||||
|
||||
List<int> NotAdd = new List<int>();
|
||||
AET temp;
|
||||
AetSet set;
|
||||
|
||||
for (i = 0; i < AetSets.Length; i++)
|
||||
{
|
||||
set = AetSets[i];
|
||||
if (set. Name != null)
|
||||
if (SetName .Contains(set. Name)) { NotAdd.Add(i); continue; }
|
||||
else SetName .Add (set. Name);
|
||||
if (set.FileName != null)
|
||||
if (SetFileName.Contains(set.FileName)) { NotAdd.Add(i); continue; }
|
||||
else SetFileName.Add (set.FileName);
|
||||
|
||||
if (set.NewId)
|
||||
{
|
||||
AetSets[i].Id = null;
|
||||
for (i0 = 0; i0 < set.Aets.Length; i0++) AetSets[i].Aets[i0].Id = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (set.Id != null)
|
||||
if (SetIds.Contains((int)set.Id)) { NotAdd.Add(i); continue; }
|
||||
else SetIds.Add ((int)set.Id);
|
||||
|
||||
for (i0 = 0; i0 < set.Aets.Length; i0++)
|
||||
{
|
||||
temp = set.Aets[i0];
|
||||
if (temp.Id != null)
|
||||
if ( Ids.Contains((int)temp.Id)) { NotAdd.Add(i); break; }
|
||||
else Ids.Add ((int)temp.Id);
|
||||
}
|
||||
}
|
||||
SetName = null;
|
||||
SetFileName = null;
|
||||
|
||||
for (i = 0; i < AetSets.Length; i++)
|
||||
{
|
||||
set = AetSets[i];
|
||||
if (NotAdd.Contains(i)) continue;
|
||||
if (!set.NewId) continue;
|
||||
|
||||
i1 = 0;
|
||||
if (set.Id == null) while (true)
|
||||
{ if (!SetIds.Contains(i1)) { AetSets[i].Id = i1; SetIds.Add(i1); break; } i1++; }
|
||||
|
||||
for (i0 = 0, i1 = 0; i0 < set.Aets.Length; i0++)
|
||||
if (set.Aets[i0].Id == null) while (true) { if (!Ids.Contains(i1))
|
||||
{ AetSets[i].Aets[i0].Id = i1; Ids.Add(i1); break; } i1++; }
|
||||
}
|
||||
|
||||
Ids = null;
|
||||
SetIds = null;
|
||||
|
||||
for (i = 0, i0 = 0, i2 = 0; i < AetSets.Length; i++)
|
||||
if (!NotAdd.Contains(i)) { i0 += AetSets[i].Aets.Length; i2++; }
|
||||
|
||||
i1 = i0 * 12;
|
||||
i1 = i1.Align(0x20) + 0x20;
|
||||
|
||||
IO = File.OpenWriter(file + ".bin", true);
|
||||
IO.Write(i2);
|
||||
IO.Write(i1);
|
||||
IO.Write(i0);
|
||||
IO.Write(0x20);
|
||||
IO.Write(0x9066906690669066);
|
||||
IO.Write(0x9066906690669066);
|
||||
|
||||
IO.Position = (i1 + i2 * 0x14).Align(0x20);
|
||||
for (i = 0; i < AetSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) continue;
|
||||
AetSets[i]. NameOffset = IO.Position; IO.Write(AetSets[i]. Name + "\0");
|
||||
AetSets[i].FileNameOffset = IO.Position; IO.Write(AetSets[i].FileName + "\0");
|
||||
}
|
||||
|
||||
for (i = 0; i < AetSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) continue;
|
||||
for (i0 = 0; i0 < AetSets[i].Aets.Length; i0++)
|
||||
{ AetSets[i].Aets[i0].NameOffset = IO.Position; IO.Write(AetSets[i].Aets[i0].Name + "\0"); }
|
||||
}
|
||||
IO.Align(0x08, true);
|
||||
|
||||
IO.Position = 0x20;
|
||||
for (i = 0, i2 = 0; i < AetSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) { i2++; continue; }
|
||||
|
||||
for (i0 = 0; i0 < AetSets[i].Aets.Length; i0++)
|
||||
{
|
||||
IO.Write(AetSets[i].Aets[i0].Id );
|
||||
IO.Write(AetSets[i].Aets[i0].NameOffset);
|
||||
IO.Write((ushort) i0 );
|
||||
IO.Write((ushort)(i - i2));
|
||||
}
|
||||
}
|
||||
IO.Align(0x20);
|
||||
for (i = 0, i2 = 0; i < AetSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) { i2++; continue; }
|
||||
|
||||
IO.Write(AetSets[i].Id );
|
||||
IO.Write(AetSets[i]. NameOffset);
|
||||
IO.Write(AetSets[i].FileNameOffset);
|
||||
IO.Write(i - i2);
|
||||
IO.Write(AetSets[i].SpriteSetId );
|
||||
}
|
||||
IO.Close();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
|
||||
if (MsgPack.ElementArray("AetDB", out MsgPack AetDB))
|
||||
{
|
||||
AetSets = new AetSet[AetDB.Array.Length];
|
||||
for (int i = 0; i < AetSets.Length; i++)
|
||||
AetSets[i].ReadMsgPack(AetDB[i]);
|
||||
}
|
||||
MsgPack = MsgPack.New;
|
||||
}
|
||||
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
{
|
||||
if (AetSets == null) return;
|
||||
if (AetSets.Length == 0) return;
|
||||
|
||||
MsgPack AetDB = new MsgPack(AetSets.Length, "AetDB");
|
||||
for (i = 0; i < AetSets.Length; i++)
|
||||
AetDB[i] = AetSets[i].WriteMsgPack();
|
||||
|
||||
AetDB.Write(true, file, JSON);
|
||||
}
|
||||
|
||||
public struct AET
|
||||
{
|
||||
public int NameOffset;
|
||||
public int? Id;
|
||||
public string Name;
|
||||
|
||||
public void ReadMsgPack(MsgPack msg)
|
||||
{ Id = msg.ReadNUInt16("Id"); Name = msg.ReadString("Name"); }
|
||||
|
||||
public MsgPack WriteMsgPack() =>
|
||||
MsgPack.New.Add("Id", Id).Add("Name", Name);
|
||||
}
|
||||
|
||||
public struct AetSet
|
||||
{
|
||||
public int NameOffset;
|
||||
public int FileNameOffset;
|
||||
public int? Id;
|
||||
public int? SpriteSetId;
|
||||
public bool NewId;
|
||||
public string Name;
|
||||
public string FileName;
|
||||
public AET[] Aets;
|
||||
|
||||
public void ReadMsgPack(MsgPack msg)
|
||||
{
|
||||
FileName = msg.ReadString ("FileName" );
|
||||
Id = msg.ReadNUInt16( "Id");
|
||||
Name = msg.ReadString ( "Name" );
|
||||
NewId = msg.ReadBoolean("NewId" );
|
||||
SpriteSetId = msg.ReadNUInt16("SpriteSetId");
|
||||
|
||||
if (msg.ElementArray("Aets", out MsgPack Aets))
|
||||
{
|
||||
this.Aets = new AET[Aets.Array.Length];
|
||||
for (int i0 = 0; i0 < this.Aets.Length; i0++)
|
||||
this.Aets[i0].ReadMsgPack(Aets[i0]);
|
||||
}
|
||||
}
|
||||
|
||||
public MsgPack WriteMsgPack()
|
||||
{
|
||||
MsgPack Aets = new MsgPack(this.Aets.Length, "Aets");
|
||||
for (int i0 = 0; i0 < this.Aets.Length; i0++)
|
||||
Aets[i0] = this.Aets[i0].WriteMsgPack();
|
||||
|
||||
return MsgPack.New.Add("FileName", FileName).Add("Id", Id)
|
||||
.Add("Name", Name).Add("SpriteSetId", SpriteSetId).Add(Aets);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+38
-55
@@ -1,19 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.A3DA;
|
||||
using KKdMainLib.MessagePack;
|
||||
using MPIO = KKdMainLib.MessagePack.IO;
|
||||
|
||||
namespace KKdMainLib.DB
|
||||
{
|
||||
public struct Auth
|
||||
public class Auth
|
||||
{
|
||||
public int Signature { get; private set; }
|
||||
public string[] Category { get; private set; }
|
||||
public UID[] _UID { get; private set; }
|
||||
public Stream IO { get; private set; }
|
||||
|
||||
public int BINReader(string file)
|
||||
public void BINReader(string file)
|
||||
{
|
||||
Dictionary<string, object> Dict = new Dictionary<string, object>();
|
||||
string[] dataArray;
|
||||
@@ -22,9 +22,9 @@ namespace KKdMainLib.DB
|
||||
|
||||
IO.Format = Main.Format.F;
|
||||
Signature = IO.ReadInt32();
|
||||
if (Signature != 0x44334123) return 0;
|
||||
if (Signature != 0x44334123) return;
|
||||
Signature = IO.ReadInt32();
|
||||
if (Signature != 0x5F5F5F41) return 0;
|
||||
if (Signature != 0x5F5F5F41) return;
|
||||
IO.ReadInt64();
|
||||
|
||||
string[] STRData = IO.ReadString(IO.Length - IO.Position).Replace("\r", "").Split('\n');
|
||||
@@ -49,13 +49,13 @@ namespace KKdMainLib.DB
|
||||
for (int i0 = 0; i0 < _UID.Length; i0++)
|
||||
{
|
||||
Dict.FindValue(out _UID[i0].Category, "uid." + i0 + ".category");
|
||||
Dict.FindValue(out _UID[i0].OrgUid , "uid." + i0 + ".org_uid" );
|
||||
Dict.FindValue(out _UID[i0].Size , "uid." + i0 + ".size" );
|
||||
Dict.FindValue(out _UID[i0].Value , "uid." + i0 + ".value" );
|
||||
}
|
||||
}
|
||||
|
||||
IO.Close();
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void BINWriter(string 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,14 +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]].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);
|
||||
}
|
||||
@@ -95,77 +92,63 @@ namespace KKdMainLib.DB
|
||||
IO.Close();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file)
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
{
|
||||
MPIO IO = new MPIO(File.OpenReader(file + ".mp"));
|
||||
MsgPack MsgPack = IO.Read();
|
||||
IO.Close();
|
||||
IO = null;
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
|
||||
if (MsgPack.Element("AuthDB", out MsgPack AuthDB))
|
||||
{
|
||||
if (AuthDB.Element("Category", out MsgPack Temp, typeof(object[])))
|
||||
if (AuthDB.ElementArray("Category", out MsgPack Temp))
|
||||
{
|
||||
this.Category = new string[((object[])Temp.Object).Length];
|
||||
MsgPack Category = new MsgPack();
|
||||
for (int i = 0; i < this.Category.Length; i++)
|
||||
if (Temp[i].GetType() == typeof(MsgPack))
|
||||
{
|
||||
Category = (MsgPack)Temp[i];
|
||||
this.Category[i] = Category.ReadString();
|
||||
}
|
||||
Category = new string[Temp.Array.Length];
|
||||
for (int i = 0; i < Category.Length; i++)
|
||||
Category[i] = Temp[i].ReadString();
|
||||
}
|
||||
|
||||
if (AuthDB.Element("UID", out Temp, typeof(object[])))
|
||||
if (AuthDB.ElementArray("UID", out Temp))
|
||||
{
|
||||
_UID = new UID[((object[])Temp.Object).Length];
|
||||
MsgPack UID = new MsgPack();
|
||||
_UID = new UID[Temp.Array.Length];
|
||||
for (int i = 0; i < _UID.Length; i++)
|
||||
if (Temp[i].GetType() == typeof(MsgPack))
|
||||
{
|
||||
UID = (MsgPack)Temp[i];
|
||||
_UID[i].Category = UID.ReadString("C");
|
||||
_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 = null;
|
||||
MsgPack = MsgPack.New;
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file)
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
{
|
||||
MsgPack AuthDB = new MsgPack("AuthDB");
|
||||
if (Category != null)
|
||||
{
|
||||
MsgPack Category = new MsgPack("Category", this.Category.Length);
|
||||
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);
|
||||
}
|
||||
|
||||
if (_UID != null)
|
||||
{
|
||||
MsgPack UID = new MsgPack("UID", _UID.Length);
|
||||
MsgPack UID = new MsgPack(_UID.Length, "UID");
|
||||
for (int i = 0; i < _UID.Length; i++)
|
||||
UID[i] = new MsgPack()
|
||||
.Add("C", _UID[i].Category)
|
||||
.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);
|
||||
}
|
||||
|
||||
MsgPack MsgPack = new MsgPack(MsgPack.Types.FixMap).Add(AuthDB);
|
||||
|
||||
MPIO IO = new MPIO(File.OpenWriter(file + ".mp", true));
|
||||
IO.Write(MsgPack, true);
|
||||
IO = null;
|
||||
MsgPack = null;
|
||||
AuthDB.Write(true, file, JSON);
|
||||
}
|
||||
|
||||
public struct UID
|
||||
{
|
||||
public int? Size;
|
||||
public int? OrgUid;
|
||||
public string Value;
|
||||
public string Category;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,312 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.DB
|
||||
{
|
||||
public class Spr
|
||||
{
|
||||
public SpriteSet[] SpriteSets;
|
||||
|
||||
private Stream IO;
|
||||
private int i, i0, i1, i2;
|
||||
|
||||
public void BINReader(string file)
|
||||
{
|
||||
IO = File.OpenReader(file + ".bin");
|
||||
|
||||
int spriteSetsLength = IO.ReadInt32();
|
||||
int spriteSetsOffset = IO.ReadInt32();
|
||||
int spritesLength = IO.ReadInt32();
|
||||
int spritesOffset = IO.ReadInt32();
|
||||
|
||||
IO.Position = spriteSetsOffset;
|
||||
SpriteSets = new SpriteSet[spriteSetsLength];
|
||||
for (i = 0; i < spriteSetsLength; i++)
|
||||
{
|
||||
SpriteSets[i].Id = IO.ReadInt32();
|
||||
SpriteSets[i].Name = IO.ReadStringAtOffset();
|
||||
SpriteSets[i].FileName = IO.ReadStringAtOffset();
|
||||
IO.ReadInt32();
|
||||
}
|
||||
|
||||
int setIndex;
|
||||
bool IsTexture;
|
||||
SpriteTexture st = new SpriteTexture();
|
||||
int[] SprCount = new int[spriteSetsLength];
|
||||
int[] TexCount = new int[spriteSetsLength];
|
||||
|
||||
IO.Position = spritesOffset;
|
||||
for (i = 0; i < spritesLength; i++)
|
||||
{
|
||||
IO.LongPosition += 10;
|
||||
setIndex = IO.ReadInt16();
|
||||
IsTexture = (setIndex & 0x1000) == 0x1000;
|
||||
setIndex &= 0xFFF;
|
||||
|
||||
if (IsTexture) TexCount[setIndex]++;
|
||||
else SprCount[setIndex]++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < spriteSetsLength; i++)
|
||||
{
|
||||
SpriteSets[i].Sprites = new SpriteTexture[SprCount[i]];
|
||||
SpriteSets[i].Textures = new SpriteTexture[TexCount[i]];
|
||||
|
||||
SprCount[i] = 0;
|
||||
TexCount[i] = 0;
|
||||
}
|
||||
|
||||
IO.Position = spritesOffset;
|
||||
for (i = 0; i < spritesLength; i++)
|
||||
{
|
||||
st.Id = IO.ReadInt32();
|
||||
st.Name = IO.ReadStringAtOffset();
|
||||
IO.ReadInt16();
|
||||
setIndex = IO.ReadInt16();
|
||||
IsTexture = (setIndex & 0x1000) == 0x1000;
|
||||
setIndex &= 0xFFF;
|
||||
|
||||
if (IsTexture) { SpriteSets[setIndex].Textures[TexCount[setIndex]] = st; TexCount[setIndex]++; }
|
||||
else { SpriteSets[setIndex]. Sprites[SprCount[setIndex]] = st; SprCount[setIndex]++; }
|
||||
}
|
||||
|
||||
IO.Close();
|
||||
}
|
||||
|
||||
public void BINWriter(string file)
|
||||
{
|
||||
if (SpriteSets == null) return;
|
||||
if (SpriteSets.Length == 0) return;
|
||||
|
||||
List<string> SetName = new List<string>();
|
||||
List<string> SetFileName = new List<string>();
|
||||
|
||||
List<int> Ids = new List<int>();
|
||||
List<int> SetIds = new List<int>();
|
||||
|
||||
List<int> NotAdd = new List<int>();
|
||||
SpriteTexture temp;
|
||||
SpriteSet set;
|
||||
|
||||
for (i = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
set = SpriteSets[i];
|
||||
if (set. Name != null)
|
||||
if (SetName .Contains(set. Name)) { NotAdd.Add(i); continue; }
|
||||
else SetName .Add (set. Name);
|
||||
if (set.FileName != null)
|
||||
if (SetFileName.Contains(set.FileName)) { NotAdd.Add(i); continue; }
|
||||
else SetFileName.Add (set.FileName);
|
||||
|
||||
if (set.NewId)
|
||||
{
|
||||
SpriteSets[i].Id = null;
|
||||
for (i0 = 0; i0 < set.Textures.Length; i0++) SpriteSets[i].Textures[i0].Id = null;
|
||||
for (i0 = 0; i0 < set. Sprites.Length; i0++) SpriteSets[i]. Sprites[i0].Id = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (set.Id != null)
|
||||
if (SetIds.Contains((int)set.Id)) { NotAdd.Add(i); continue; }
|
||||
else SetIds.Add ((int)set.Id);
|
||||
|
||||
for (i0 = 0; i0 < set. Sprites.Length; i0++)
|
||||
{
|
||||
temp = set. Sprites[i0];
|
||||
if (temp.Id != null)
|
||||
if ( Ids.Contains((int)temp.Id)) { NotAdd.Add(i); break; }
|
||||
else Ids.Add ((int)temp.Id);
|
||||
}
|
||||
if (i0 + 1 != set.Sprites.Length) continue;
|
||||
|
||||
for (i0 = 0; i0 < set.Textures.Length; i0++)
|
||||
{
|
||||
temp = set.Textures[i0];
|
||||
if (temp.Id != null)
|
||||
if ( Ids.Contains((int)temp.Id)) { NotAdd.Add(i); break; }
|
||||
else Ids.Add ((int)temp.Id);
|
||||
}
|
||||
}
|
||||
SetName = null;
|
||||
SetFileName = null;
|
||||
|
||||
for (i = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
set = SpriteSets[i];
|
||||
if (NotAdd.Contains(i)) continue;
|
||||
if (!set.NewId) continue;
|
||||
|
||||
i1 = 0;
|
||||
if (set.Id == null) while (true)
|
||||
{ if (!SetIds.Contains(i1)) { SpriteSets[i].Id = i1; SetIds.Add(i1); break; } i1++; }
|
||||
|
||||
for (i0 = 0, i1 = 0; i0 < set. Sprites.Length; i0++)
|
||||
if (set. Sprites[i0].Id == null) while (true) { if (!Ids.Contains(i1))
|
||||
{ SpriteSets[i]. Sprites[i0].Id = i1; Ids.Add(i1); break; } i1++; }
|
||||
|
||||
for (i0 = 0, i1 = 0; i0 < set.Textures.Length; i0++)
|
||||
if (set.Textures[i0].Id == null) while (true) { if (!Ids.Contains(i1))
|
||||
{ SpriteSets[i].Textures[i0].Id = i1; Ids.Add(i1); break; } i1++; }
|
||||
}
|
||||
|
||||
Ids = null;
|
||||
SetIds = null;
|
||||
|
||||
|
||||
|
||||
for (i = 0, i0 = 0, i2 = 0; i < SpriteSets.Length; i++)
|
||||
if (!NotAdd.Contains(i)) { i0 += SpriteSets[i].Sprites.Length + SpriteSets[i].Textures.Length; i2++; }
|
||||
|
||||
i1 = i0 * 12;
|
||||
i1 = i1.Align(0x20) + 0x20;
|
||||
|
||||
IO = File.OpenWriter(file + ".bin", true);
|
||||
IO.Write(i2);
|
||||
IO.Write(i1);
|
||||
IO.Write(i0);
|
||||
IO.Write(0x20);
|
||||
IO.Write(0x9066906690669066);
|
||||
IO.Write(0x9066906690669066);
|
||||
|
||||
IO.Position = (i1 + i2 * 0x10).Align(0x20);
|
||||
for (i = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) continue;
|
||||
SpriteSets[i]. NameOffset = IO.Position; IO.Write(SpriteSets[i]. Name + "\0");
|
||||
SpriteSets[i].FileNameOffset = IO.Position; IO.Write(SpriteSets[i].FileName + "\0");
|
||||
}
|
||||
|
||||
for (i = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) continue;
|
||||
for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++)
|
||||
{ SpriteSets[i].Textures[i0].NameOffset = IO.Position; IO.Write(SpriteSets[i].Textures[i0].Name + "\0"); }
|
||||
|
||||
for (i0 = 0; i0 < SpriteSets[i]. Sprites.Length; i0++)
|
||||
{ SpriteSets[i]. Sprites[i0].NameOffset = IO.Position; IO.Write(SpriteSets[i]. Sprites[i0].Name + "\0"); }
|
||||
}
|
||||
|
||||
IO.Align(0x08, true);
|
||||
IO.Position = 0x20;
|
||||
for (i = 0, i2 = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) { i2++; continue; }
|
||||
|
||||
for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++)
|
||||
{
|
||||
IO.Write(SpriteSets[i].Textures[i0].Id );
|
||||
IO.Write(SpriteSets[i].Textures[i0].NameOffset);
|
||||
IO.Write((ushort) i0 );
|
||||
IO.Write((ushort)(0x1000 | (i - i2)));
|
||||
}
|
||||
|
||||
for (i0 = 0; i0 < SpriteSets[i]. Sprites.Length; i0++)
|
||||
{
|
||||
IO.Write(SpriteSets[i]. Sprites[i0].Id );
|
||||
IO.Write(SpriteSets[i]. Sprites[i0].NameOffset);
|
||||
IO.Write((ushort) i0 );
|
||||
IO.Write((ushort)(i - i2));
|
||||
}
|
||||
}
|
||||
IO.Align(0x20);
|
||||
for (i = 0, i2 = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) { i2++; continue; }
|
||||
|
||||
IO.Write(SpriteSets[i].Id );
|
||||
IO.Write(SpriteSets[i]. NameOffset);
|
||||
IO.Write(SpriteSets[i].FileNameOffset);
|
||||
IO.Write(i - i2);
|
||||
}
|
||||
|
||||
IO.Close();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool JSON = false)
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
|
||||
if (MsgPack.ElementArray("SprDB", out MsgPack SprDB))
|
||||
{
|
||||
SpriteSets = new SpriteSet[SprDB.Array.Length];
|
||||
for (int i = 0; i < SpriteSets.Length; i++)
|
||||
SpriteSets[i].ReadMsgPack(SprDB[i]);
|
||||
}
|
||||
MsgPack = MsgPack.New;
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
{
|
||||
if (SpriteSets == null) return;
|
||||
if (SpriteSets.Length == 0) return;
|
||||
|
||||
MsgPack SprDB = new MsgPack(SpriteSets.Length, "SprDB");
|
||||
for (i = 0; i < SpriteSets.Length; i++) SprDB[i] = SpriteSets[i].WriteMsgPack();
|
||||
|
||||
SprDB.Write(true, file, JSON);
|
||||
}
|
||||
|
||||
public struct SpriteTexture
|
||||
{
|
||||
public int NameOffset;
|
||||
public int? Id;
|
||||
public string Name;
|
||||
|
||||
public void ReadMsgPack(MsgPack msg)
|
||||
{ Id = msg.ReadNInt32("Id"); Name = msg.ReadString("Name"); }
|
||||
|
||||
public MsgPack WriteMsgPack() =>
|
||||
MsgPack.New.Add("Id", Id).Add("Name", Name);
|
||||
}
|
||||
|
||||
public struct SpriteSet
|
||||
{
|
||||
public int NameOffset;
|
||||
public int FileNameOffset;
|
||||
public int? Id;
|
||||
public bool NewId;
|
||||
public string Name;
|
||||
public string FileName;
|
||||
public SpriteTexture[] Sprites;
|
||||
public SpriteTexture[] Textures;
|
||||
|
||||
public void ReadMsgPack(MsgPack msg)
|
||||
{
|
||||
FileName = msg.ReadString ("FileName");
|
||||
Id = msg.ReadNInt32 ( "Id" );
|
||||
Name = msg.ReadString ("Name" );
|
||||
NewId = msg.ReadBoolean("NewId" );
|
||||
|
||||
if (msg.ElementArray( "Sprites", out MsgPack Sprites))
|
||||
{
|
||||
this.Sprites = new SpriteTexture[Sprites.Array.Length];
|
||||
for (int i0 = 0; i0 < this.Sprites.Length; i0++)
|
||||
this.Sprites[i0].ReadMsgPack(Sprites[i0]);
|
||||
}
|
||||
|
||||
if (msg.ElementArray("Textures", out MsgPack Textures))
|
||||
{
|
||||
this.Textures = new SpriteTexture[Textures.Array.Length];
|
||||
for (int i0 = 0; i0 < this.Textures.Length; i0++)
|
||||
this.Textures[i0].ReadMsgPack(Textures[i0]);
|
||||
}
|
||||
}
|
||||
|
||||
public MsgPack WriteMsgPack()
|
||||
{
|
||||
MsgPack Sprites = new MsgPack(this. Sprites.Length, "Sprites");
|
||||
for (int i0 = 0; i0 < this.Sprites.Length; i0++)
|
||||
Sprites[i0] = this.Sprites[i0].WriteMsgPack();
|
||||
|
||||
MsgPack Textures = new MsgPack(this.Textures.Length, "Textures");
|
||||
for (int i0 = 0; i0 < this.Textures.Length; i0++)
|
||||
Textures[i0] = this.Textures[i0].WriteMsgPack();
|
||||
|
||||
return MsgPack.New.Add("FileName", FileName).Add("Id", Id).Add("Name", Name).Add(Sprites).Add(Textures);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
//Original research by Samyuu
|
||||
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public static class DCC //Databank_Checksum_Calculator
|
||||
{
|
||||
private static readonly ushort[] ChecksumLookupTable = {
|
||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
|
||||
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
|
||||
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
|
||||
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
|
||||
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
|
||||
0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
|
||||
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
|
||||
0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
|
||||
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
|
||||
0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
|
||||
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
|
||||
0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
|
||||
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
|
||||
0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
|
||||
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
|
||||
0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
|
||||
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
|
||||
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
|
||||
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
|
||||
0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
|
||||
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
|
||||
0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
||||
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
|
||||
0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
|
||||
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
|
||||
0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
|
||||
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
|
||||
0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
|
||||
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
|
||||
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
|
||||
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
|
||||
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0,
|
||||
};
|
||||
|
||||
public static ushort CalculateChecksum(string file) => CalculateChecksum(File.ReadAllBytes(file));
|
||||
|
||||
public static ushort CalculateChecksum(byte[] data)
|
||||
{
|
||||
ushort result = 0xFFFF;
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
result = (ushort)(ChecksumLookupTable[(result >> 8) ^ data[i]] ^ (result << 8));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
+35
-60
@@ -12,8 +12,7 @@ namespace KKdMainLib
|
||||
|
||||
private int Offset = 0;
|
||||
private PDHead Header;
|
||||
|
||||
private MsgPack MsgPack;
|
||||
|
||||
public Stream IO;
|
||||
public EXP[] Dex;
|
||||
|
||||
@@ -96,7 +95,7 @@ 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 = File.OpenWriter(filepath + (Header.Format > Main.Format.F ? ".dex" : ".bin"), true);
|
||||
IO.Format = Header.Format;
|
||||
|
||||
if (IO.Format > Main.Format.F)
|
||||
@@ -110,19 +109,15 @@ namespace KKdMainLib
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
@@ -157,8 +152,7 @@ namespace KKdMainLib
|
||||
}
|
||||
IO.Align(0x10, true);
|
||||
|
||||
if (Header.IsX) IO.Seek(Header.Lenght + 0x28, 0);
|
||||
else IO.Seek(Header.Lenght + 0x20, 0);
|
||||
IO.Position = Header.Lenght + (Header.IsX ? 0x28 : 0x20);
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
IO.Write(Dex[i0].MainOffset);
|
||||
@@ -173,8 +167,7 @@ namespace KKdMainLib
|
||||
if (Header.IsX) IO.Write(0x00);
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -190,49 +183,35 @@ namespace KKdMainLib
|
||||
IO.Close();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string filepath)
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
{
|
||||
int i0 = 0;
|
||||
int i1 = 0;
|
||||
this.Dex = new EXP[0];
|
||||
Header = new PDHead();
|
||||
|
||||
MPIO IO = new MPIO(File.OpenReader(filepath + ".mp"));
|
||||
MsgPack = IO.Read();
|
||||
IO.Close();
|
||||
IO = null;
|
||||
|
||||
if (MsgPack.Element("Dex", out MsgPack Dex, typeof(object[])))
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
if (!MsgPack.ElementArray("Dex", out MsgPack Dex)) return;
|
||||
|
||||
this.Dex = new EXP[Dex.Array.Length];
|
||||
for (i0 = 0; i0 < this.Dex.Length; i0++)
|
||||
{
|
||||
MsgPack Temp = new MsgPack();
|
||||
this.Dex[i0] = new EXP { Name = Dex[i0].ReadString("Name") };
|
||||
|
||||
this.Dex = new EXP[((object[])Dex.Object).Length];
|
||||
MsgPack EXP = new MsgPack();
|
||||
for (i0 = 0; i0 < this.Dex.Length; i0++)
|
||||
if (Dex[i0].GetType() == typeof(MsgPack))
|
||||
{
|
||||
this.Dex[i0] = new EXP();
|
||||
EXP = (MsgPack)Dex[i0];
|
||||
this.Dex[i0].Name = EXP.ReadString("Name");
|
||||
if (EXP.Element("Main", out Temp, typeof(object[])))
|
||||
{
|
||||
this.Dex[i0].Main = new List<EXPElement>
|
||||
{ Capacity = ((object[])Temp.Object).Length };
|
||||
for (i1 = 0; i1 < this.Dex[i0].Main.Capacity; i1++)
|
||||
if (Temp[i1].GetType() == typeof(MsgPack))
|
||||
this.Dex[i0].Main.Add(ReadEXP((MsgPack)Temp[i1]));
|
||||
}
|
||||
if (EXP.Element("Eyes", out Temp, typeof(object[])))
|
||||
{
|
||||
this.Dex[i0].Eyes = new List<EXPElement>
|
||||
{ Capacity = ((object[])Temp.Object).Length };
|
||||
for (i1 = 0; i1 < this.Dex[i0].Eyes.Capacity; i1++)
|
||||
if (Temp[i1].GetType() == typeof(MsgPack))
|
||||
this.Dex[i0].Eyes.Add(ReadEXP((MsgPack)Temp[i1]));
|
||||
}
|
||||
}
|
||||
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 = null;
|
||||
MsgPack = MsgPack.New;
|
||||
}
|
||||
|
||||
private EXPElement ReadEXP(MsgPack mp) =>
|
||||
@@ -240,35 +219,31 @@ namespace KKdMainLib
|
||||
ID = mp.ReadUInt16("I"), Value = mp.ReadSingle("V"),
|
||||
Trans = mp.ReadSingle("T") };
|
||||
|
||||
public void MsgPackWriter(string filepath)
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
{
|
||||
int i0 = 0;
|
||||
int i1 = 0;
|
||||
MsgPack Dex = new MsgPack("Dex", this.Dex.Length);
|
||||
MsgPack Dex = new MsgPack(this.Dex.Length, "Dex");
|
||||
for (i0 = 0; i0 < this.Dex.Length; i0++)
|
||||
{
|
||||
MsgPack EXP = new MsgPack().Add("Name", this.Dex[i0].Name);
|
||||
MsgPack Main = new MsgPack("Main", this.Dex[i0].Main.Count);
|
||||
MsgPack EXP = MsgPack.New.Add("Name", this.Dex[i0].Name);
|
||||
MsgPack Main = new MsgPack(this.Dex[i0].Main.Count, "Main");
|
||||
for (i1 = 0; i1 < this.Dex[i0].Main.Count; i1++)
|
||||
Main[i1] = WriteEXP(this.Dex[i0].Main[i1]);
|
||||
EXP.Add(Main);
|
||||
|
||||
MsgPack Eyes = new MsgPack("Eyes", this.Dex[i0].Eyes.Count);
|
||||
MsgPack Eyes = new MsgPack(this.Dex[i0].Eyes.Count, "Eyes");
|
||||
for (i1 = 0; i1 < this.Dex[i0].Eyes.Count; i1++)
|
||||
Eyes[i1] = WriteEXP(this.Dex[i0].Eyes[i1]);
|
||||
EXP.Add(Eyes);
|
||||
Dex[i0] = EXP;
|
||||
}
|
||||
|
||||
MsgPack = new MsgPack(MsgPack.Types.FixMap).Add(Dex);
|
||||
|
||||
MPIO IO = new MPIO(File.OpenWriter(filepath + ".mp", true));
|
||||
IO.Write(MsgPack, true);
|
||||
IO = null;
|
||||
Dex.Write(true, file, JSON);
|
||||
}
|
||||
|
||||
private MsgPack WriteEXP(EXPElement element) =>
|
||||
new MsgPack().Add("F", element.Frame).Add("B", element.Both ).Add("I", element.ID )
|
||||
MsgPack.New.Add("F", element.Frame).Add("B", element.Both ).Add("I", element.ID )
|
||||
.Add("V", element.Value).Add("T", element.Trans);
|
||||
|
||||
public struct EXP
|
||||
|
||||
@@ -7,11 +7,13 @@ 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)
|
||||
{
|
||||
Console.Title = "DIVAFILE Decrypt - File: " + MSIO.Path.GetFileName(file);
|
||||
Console.Title = "DIVAFILE Decrypt - File: " + Path.GetFileName(file);
|
||||
Stream reader = File.OpenReader(file);
|
||||
if (reader.ReadInt64() != 0x454C494641564944)
|
||||
{ reader.Close(); return; }
|
||||
@@ -35,7 +37,7 @@ namespace KKdMainLib
|
||||
|
||||
public static void Encrypt(this string file)
|
||||
{
|
||||
Console.Title = "DIVAFILE Encrypt - File: " + MSIO.Path.GetFileName(file);
|
||||
Console.Title = "DIVAFILE Encrypt - File: " + Path.GetFileName(file);
|
||||
Stream reader = File.OpenReader(file);
|
||||
int FileLenghtOrigin = reader.Length;
|
||||
int FileLenght = FileLenghtOrigin.Align(16);
|
||||
|
||||
@@ -0,0 +1,373 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public class DataBank
|
||||
{
|
||||
public DataBank() { Success = false; IO = null; pvList = null; }
|
||||
|
||||
private Stream IO;
|
||||
private int i;
|
||||
|
||||
private PvList[] pvList;
|
||||
private psrData[] psrDat;
|
||||
|
||||
private const string d = ".";
|
||||
private const string c = ",";
|
||||
|
||||
public bool Success { get; private set; }
|
||||
|
||||
public void DBReader(string file)
|
||||
{
|
||||
Success = false;
|
||||
if (!File.Exists(file)) return;
|
||||
string text = File.ReadAllText(file);
|
||||
while (text.Contains("%")) text = WebUtility.UrlDecode(text);
|
||||
string[] array = text.Split(',');
|
||||
|
||||
if (file.Contains("psrData") && array.Length % 13 < 2)
|
||||
{
|
||||
psrDat = new psrData[array.Length / 13];
|
||||
for (i = 0; i < psrDat.Length; i++) psrDat[i].SetValue(array, i);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public void DBWriter(string file)
|
||||
{
|
||||
if (!Success) return;
|
||||
|
||||
IO = File.OpenWriter();
|
||||
if (file.Contains("psrData"))
|
||||
for (i = 0; i < psrDat.Length; i++)
|
||||
IO.Write(psrDat[i].ToString() + c);
|
||||
else if (file.Contains("PvList"))
|
||||
if (pvList.Length != 0)
|
||||
for (i = 0; i < pvList.Length; i++)
|
||||
IO.Write(UrlEncode(pvList[i].ToString() +
|
||||
((i + 1 != pvList.Length) ? c : "")));
|
||||
else IO.Write("%2A%2A%2A");
|
||||
|
||||
|
||||
byte[] data = IO.ToArray(true);
|
||||
ushort num = DCC.CalculateChecksum(data);
|
||||
uint num2 = (uint)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||||
File.WriteAllBytes(file + "_" + num + "_" + num2 + ".dat", data);
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
{
|
||||
Success = false;
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
bool compact = MsgPack.ReadBoolean("Compact");
|
||||
|
||||
if (file.Contains("psrData") && MsgPack.ElementArray("psrData", out MsgPack psrData))
|
||||
{
|
||||
psrDat = new psrData[psrData.Array.Length];
|
||||
for (i = 0; i < psrDat.Length; i++)
|
||||
psrDat[i].SetValue(psrData[i]);
|
||||
Success = true;
|
||||
}
|
||||
else if (file.Contains("PvList") && 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);
|
||||
Success = true;
|
||||
}
|
||||
MsgPack = MsgPack.New;
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON, bool Compact = true)
|
||||
{
|
||||
if (!Success) return;
|
||||
MsgPack msgPack = MsgPack.New;
|
||||
|
||||
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);
|
||||
}
|
||||
else if (file.Contains("PvList"))
|
||||
{
|
||||
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.Write(file, JSON).Dispose();
|
||||
}
|
||||
|
||||
public static string UrlEncode(string value) =>
|
||||
WebUtility.UrlEncode(value).Replace("+", "%20");
|
||||
|
||||
|
||||
public struct psrData
|
||||
{
|
||||
public Player p1;
|
||||
public Player p2;
|
||||
public Player p3;
|
||||
public int PV_ID;
|
||||
|
||||
public void SetValue(string[] data, int i = 0)
|
||||
{
|
||||
p1.SetValue(data, i, 0);
|
||||
p2.SetValue(data, i, 1);
|
||||
p3.SetValue(data, i, 2);
|
||||
PV_ID = int.Parse(data[i * 13 + 12]);
|
||||
}
|
||||
|
||||
public void SetValue(MsgPack msg)
|
||||
{
|
||||
int? ID = msg.ReadNInt32("PV_ID");
|
||||
if (ID != null) PV_ID = (int)ID;
|
||||
else { ID = msg.ReadNInt32("ID"); if (ID != null) PV_ID = (int)ID; }
|
||||
if (msg.Element("P1", out MsgPack P1)) p1.SetValue(P1);
|
||||
if (msg.Element("P2", out MsgPack P2)) p2.SetValue(P2);
|
||||
if (msg.Element("P3", out MsgPack P3)) p3.SetValue(P3);
|
||||
}
|
||||
|
||||
public MsgPack WriteMP() =>
|
||||
MsgPack.New.Add("PV_ID", PV_ID).Add(p1.WriteMP("P1"))
|
||||
.Add(p2.WriteMP("P2")).Add(p3.WriteMP("P3"));
|
||||
|
||||
public override string ToString() =>
|
||||
UrlEncode(p1.ToString() + c + p2.ToString() + c + p3.ToString() + c + PV_ID);
|
||||
}
|
||||
|
||||
public struct Player
|
||||
{
|
||||
public int Score0;
|
||||
public int Score1;
|
||||
public string Name0;
|
||||
public string Name1;
|
||||
public Difficulty Diff;
|
||||
public bool Has2P => Name1 != null;
|
||||
|
||||
public void SetValue(string[] data, int i = 0, int offset = 0)
|
||||
{
|
||||
string[] array = data[i * 13 + offset * 4].Split('.');
|
||||
Score0 = int.Parse(array[0]);
|
||||
if (array.Length > 1) Score1 = int.Parse(array[1]);
|
||||
string text = "";
|
||||
for (int j = 0; j < data[i * 13 + 1 + offset * 4].Length; j++)
|
||||
{
|
||||
text += data[i * 13 + 1 + offset * 4][j].ToString();
|
||||
if (text.EndsWith("xxx"))
|
||||
{
|
||||
Name0 = text.Remove(text.Length - 3);
|
||||
text = "";
|
||||
}
|
||||
}
|
||||
if (array.Length == 1) Name0 = text;
|
||||
else Name1 = text;
|
||||
if (int.TryParse(data[i * 13 + 2 + offset * 4], out int Diff))
|
||||
this.Diff = (Difficulty)Diff;
|
||||
else
|
||||
Enum.TryParse(data[i * 13 + 2 + offset * 4], out this.Diff);
|
||||
}
|
||||
|
||||
public void SetValue(MsgPack msg)
|
||||
{
|
||||
Diff = (Difficulty)msg.ReadInt32("Diff");
|
||||
Score0 = msg.ReadInt32 ("Score");
|
||||
Name0 = msg.ReadString( "Name");
|
||||
if (Name0 == null)
|
||||
{
|
||||
Score0 = msg.ReadInt32 ("Score0");
|
||||
Score1 = msg.ReadInt32 ("Score1");
|
||||
Name0 = msg.ReadString( "Name0");
|
||||
Name1 = msg.ReadString( "Name1");
|
||||
}
|
||||
else Name1 = null;
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(string name) =>
|
||||
Has2P ? new MsgPack(name).Add("Diff", (int)Diff).Add("Score0", Score0)
|
||||
.Add("Score1", Score1).Add("Name0", Name0).Add("Name1", Name1) :
|
||||
new MsgPack(name).Add("Diff", (int)Diff)
|
||||
.Add("Score" , Score0).Add("Name" , Name0);
|
||||
|
||||
public override string ToString() =>
|
||||
(Score0 + (Has2P ? (d + Score1) : "") + c + UrlEncode(Name0) +
|
||||
(Has2P ? ("xxx" + UrlEncode(Name1)) : "") + c +
|
||||
Diff + c + (Has2P ? "0.1" : "0")).Replace("*", "%2A");
|
||||
}
|
||||
|
||||
public struct PvList
|
||||
{
|
||||
public int PV_ID;
|
||||
public bool Enable;
|
||||
public bool Extra;
|
||||
public Date AdvDemoStart;
|
||||
public Date AdvDemoEnd;
|
||||
public Date StartShow;
|
||||
public Date EndShow;
|
||||
|
||||
public void SetValue(string[] data, int i = 0)
|
||||
{
|
||||
PV_ID = int.Parse(data[i * 7]);
|
||||
Enable = int.Parse(data[i * 7 + 1]) == 1;
|
||||
Extra = int.Parse(data[i * 7 + 2]) == 1;
|
||||
AdvDemoStart.SetValue(data[i * 7 + 3]);
|
||||
AdvDemoEnd .SetValue(data[i * 7 + 4]);
|
||||
StartShow .SetValue(data[i * 7 + 5]);
|
||||
EndShow .SetValue(data[i * 7 + 6]);
|
||||
}
|
||||
|
||||
public void SetValue(MsgPack msg, bool Compact)
|
||||
{
|
||||
MsgPack Temp = MsgPack.New;
|
||||
this.Enable = true;
|
||||
this.Extra = false;
|
||||
|
||||
int? ID = msg.ReadNInt32("PV_ID");
|
||||
if (ID != null) PV_ID = (int)ID;
|
||||
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 (Compact)
|
||||
{
|
||||
AdvDemoStart.SetValue(msg.ReadNInt32("AdvDemoStart"), true);
|
||||
AdvDemoEnd .SetValue(msg.ReadNInt32("AdvDemoEnd" ), false);
|
||||
StartShow .SetValue(msg.ReadNInt32("StartShow" ), false);
|
||||
EndShow .SetValue(msg.ReadNInt32( "EndShow" ), true);
|
||||
return;
|
||||
}
|
||||
if (msg.Element("AdvDemoStart", out Temp)) AdvDemoStart.SetValue(Temp, true);
|
||||
if (msg.Element("AdvDemoEnd" , out Temp)) AdvDemoEnd .SetValue(Temp, false);
|
||||
if (msg.Element("StartShow" , out Temp)) StartShow .SetValue(Temp, false);
|
||||
if (msg.Element( "EndShow" , out Temp)) EndShow .SetValue(Temp, true);
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(bool Compact)
|
||||
{
|
||||
MsgPack msgPack = MsgPack.New;
|
||||
msgPack.Add("PV_ID", PV_ID);
|
||||
if (!Enable) msgPack.Add("Enable", Enable);
|
||||
if ( Extra ) msgPack.Add("Extra" , Extra );
|
||||
if (Compact)
|
||||
{
|
||||
if (AdvDemoStart.WriteLower) msgPack.Add("AdvDemoStart", AdvDemoStart.WriteInt());
|
||||
if (AdvDemoEnd .WriteLower) msgPack.Add("AdvDemoEnd" , AdvDemoEnd .WriteInt());
|
||||
if (StartShow .WriteLower) msgPack.Add("StartShow" , StartShow .WriteInt());
|
||||
if ( EndShow .WriteUpper) msgPack.Add( "EndShow" , EndShow .WriteInt());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (AdvDemoStart.WriteLower) msgPack.Add(AdvDemoStart.WriteMP("AdvDemoStart"));
|
||||
if (AdvDemoEnd .WriteLower) msgPack.Add(AdvDemoEnd .WriteMP("AdvDemoEnd" ));
|
||||
if (StartShow .WriteLower) msgPack.Add(StartShow .WriteMP("StartShow" ));
|
||||
if ( EndShow .WriteUpper) msgPack.Add( EndShow .WriteMP( "EndShow" ));
|
||||
}
|
||||
return msgPack;
|
||||
}
|
||||
|
||||
public override string 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
|
||||
{
|
||||
private int year;
|
||||
private int month;
|
||||
private int day;
|
||||
|
||||
public int Year { get => year; set { year = value; CheckDate(); } }
|
||||
|
||||
public int Month { get => month; set { month = value; CheckDate(); } }
|
||||
|
||||
public int Day { get => day; set { day = value; CheckDate(); } }
|
||||
|
||||
public bool WriteUpper => Year != 2029 || Month != 1 || Day != 1;
|
||||
public bool WriteLower => Year != 2000 || Month != 1 || Day != 1;
|
||||
|
||||
public void SetDefaultLower() => Year = 2000;
|
||||
public void SetDefaultUpper() => Year = 2029;
|
||||
|
||||
public void SetValue(string data)
|
||||
{
|
||||
string[] array = data.Split('-');
|
||||
if (array.Length == 3)
|
||||
{
|
||||
Year = int.Parse(array[0]);
|
||||
Month = int.Parse(array[1]);
|
||||
Day = int.Parse(array[2]);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetValue(int? YMD, bool SetDefaultUpper)
|
||||
{
|
||||
if (!SetDefaultUpper) SetDefaultLower();
|
||||
else this.SetDefaultUpper();
|
||||
if (YMD != null)
|
||||
{
|
||||
year = YMD.Value / 10000;
|
||||
month = YMD.Value / 100 % 100;
|
||||
day = YMD.Value % 100;
|
||||
CheckDate();
|
||||
}
|
||||
}
|
||||
|
||||
public void SetValue(MsgPack msg, bool SetDefaultUpper)
|
||||
{
|
||||
if (!SetDefaultUpper) SetDefaultLower();
|
||||
else this.SetDefaultUpper();
|
||||
int? Year = msg.ReadNInt32( "Year");
|
||||
int? Month = msg.ReadNInt32("Month");
|
||||
int? Day = msg.ReadNInt32( "Day");
|
||||
if ( Year != null) year = Year.Value;
|
||||
if (Month != null) month = Month.Value;
|
||||
if ( Day != null) day = Day.Value;
|
||||
CheckDate();
|
||||
}
|
||||
|
||||
public int WriteInt() =>
|
||||
(Year * 100 + Month) * 100 + Day;
|
||||
|
||||
public MsgPack WriteMP(string name) =>
|
||||
new MsgPack(name).Add("Year", Year).Add("Month", Month).Add("Day", Day);
|
||||
|
||||
private void CheckDate()
|
||||
{
|
||||
if (year < 2000) { year = 2000; month = 1; day = 1; return; }
|
||||
if (year >= 2029) { year = 2029; month = 1; day = 1; return; }
|
||||
if (month < 1) month = 1;
|
||||
else if (month > 12) month = 12;
|
||||
if (day < 1) day = 1;
|
||||
else if (day > 31 && (month == 1 || month == 3 || month == 5 ||
|
||||
month == 7 || month == 8 || month == 10 || month == 12)) day = 31;
|
||||
else if (day > 30 && (month == 4 || month == 6 ||
|
||||
month == 9 || month == 11)) day = 30;
|
||||
else if (day > 29 && month == 2 && year % 4 == 0) day = 29;
|
||||
else if (day > 28 && month == 2 && year % 4 != 0) day = 28;
|
||||
}
|
||||
|
||||
public override string ToString() =>
|
||||
Year.ToString("d4") + "-" + Month.ToString("d2") + "-" + Day.ToString("d2");
|
||||
}
|
||||
|
||||
public enum Difficulty
|
||||
{
|
||||
Easy = 0,
|
||||
Normal = 1,
|
||||
Hard = 2,
|
||||
Extreme = 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
+181
-198
@@ -1,6 +1,5 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using System;
|
||||
using System.IO.Compression;
|
||||
using System.Security.Cryptography;
|
||||
using KKdMainLib.IO;
|
||||
@@ -10,12 +9,18 @@ namespace KKdMainLib
|
||||
{
|
||||
public class FARC
|
||||
{
|
||||
public FARC() { Files = new FARCFile[0]; Signature = Farc.FArC; FT = false; }
|
||||
public FARC() => NewFARC();
|
||||
public FARC(string File, bool IsDirectory = false)
|
||||
{ if (IsDirectory) DirectoryPath = File; else FilePath = File; NewFARC(); }
|
||||
|
||||
public FARCFile[] Files = new FARCFile[0];
|
||||
private void NewFARC() { Files = null; Signature = Farc.FArC; CBC = FT = false; }
|
||||
|
||||
public FARCFile[] Files = null;
|
||||
public Type FARCType;
|
||||
public Farc Signature = Farc.FArC;
|
||||
public string FilePath, DirectoryPath;
|
||||
|
||||
private bool FT = false;
|
||||
private bool CBC, FT;
|
||||
|
||||
private readonly byte[] Key = Text.ToASCII("project_diva.bin");
|
||||
|
||||
@@ -29,114 +34,120 @@ namespace KKdMainLib
|
||||
Padding = PaddingMode.Zeros, IV = iv ?? new byte[16] };
|
||||
return AesManaged;
|
||||
}
|
||||
|
||||
public void UnPack(string file, bool SaveToDisk = true)
|
||||
|
||||
public void UnPack(bool SaveToDisk = true)
|
||||
{
|
||||
Files = null;
|
||||
Signature = Farc.FArC;
|
||||
FT = false;
|
||||
Console.Title = "FARC Extractor - Archive: " + MSIO.Path.GetFileName(file);
|
||||
if (!MSIO.File.Exists(file))
|
||||
{
|
||||
Console.WriteLine("File {0} doesn't exist.", MSIO.Path.GetFileName(file));
|
||||
Console.Clear();
|
||||
return;
|
||||
}
|
||||
HeaderReader().FileReader();
|
||||
if (SaveToDisk) this.SaveToDisk();
|
||||
}
|
||||
|
||||
Stream reader = File.OpenReader(file);
|
||||
string directory = MSIO.Path.GetFullPath(file).Replace(MSIO.Path.GetExtension(file), "");
|
||||
private FARC HeaderReader()
|
||||
{
|
||||
NewFARC();
|
||||
if (!File.Exists(FilePath)) return this;
|
||||
|
||||
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)
|
||||
{ reader.Close(); return this; }
|
||||
|
||||
int HeaderLength = reader.ReadInt32Endian(true);
|
||||
if (Signature == Farc.FARC)
|
||||
{
|
||||
Console.WriteLine("Unknown signature"); reader.Close();
|
||||
Console.Clear();
|
||||
return;
|
||||
FARCType = (Type)reader.ReadInt32Endian(true);
|
||||
reader.ReadInt32();
|
||||
|
||||
int FARCMode = reader.ReadInt32Endian(true);
|
||||
FT = FARCMode == 0x10;
|
||||
CBC = FARCMode != 0x10 && FARCMode != 0x40;
|
||||
|
||||
if (CBC && FARCType.HasFlag(Type.ECB))
|
||||
{
|
||||
reader.Close();
|
||||
byte[] Header = new byte[HeaderLength - 0x08];
|
||||
MSIO.FileStream stream = new MSIO.FileStream(FilePath, MSIO.FileMode.Open,
|
||||
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite) { Position = 0x10 };
|
||||
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Header, 0x00, HeaderLength - 0x08);
|
||||
Header = SkipData(Header, 0x10);
|
||||
reader = File.OpenReader(Header);
|
||||
|
||||
FARCMode = reader.ReadInt32Endian(true);
|
||||
FT = FARCMode == 0x10;
|
||||
}
|
||||
}
|
||||
|
||||
MSIO.Directory.CreateDirectory(directory);
|
||||
int HeaderLength = reader.ReadInt32Endian(true);
|
||||
if (Signature == Farc.FARC)
|
||||
if (reader.ReadInt32Endian(true) == 1)
|
||||
Files = new FARCFile[reader.ReadInt32Endian(true)];
|
||||
reader.ReadInt32();
|
||||
|
||||
if (Files == null)
|
||||
{
|
||||
int Count = 0;
|
||||
long Position = reader.LongPosition;
|
||||
while (reader.LongPosition < HeaderLength)
|
||||
{
|
||||
reader.NullTerminated();
|
||||
reader.ReadInt32();
|
||||
if (Signature != Farc.FArc ) reader.ReadInt32();
|
||||
reader.ReadInt32();
|
||||
if (Signature == Farc.FARC && FT) reader.ReadInt32();
|
||||
Count++;
|
||||
}
|
||||
reader.LongPosition = Position;
|
||||
Files = new FARCFile[Count];
|
||||
}
|
||||
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
Files[i].Name = reader.NullTerminatedUTF8();
|
||||
Files[i].Offset = reader.ReadInt32Endian(true);
|
||||
if (Signature != Farc.FArc) Files[i].SizeComp = reader.ReadInt32Endian(true);
|
||||
Files[i].SizeUnc = reader.ReadInt32Endian(true);
|
||||
if (Signature == Farc.FARC && FT)
|
||||
Files[i].Type = (Type)reader.ReadInt32Endian(true);
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
return this;
|
||||
}
|
||||
|
||||
private FARC FileReader()
|
||||
{
|
||||
if (Files == null) return this;
|
||||
if (Files.Length < 1) return this;
|
||||
if (Signature != Farc.FARC)
|
||||
{
|
||||
reader.ReadUInt32();
|
||||
HeaderReader(HeaderLength, ref Files, ref reader);
|
||||
reader.Close();
|
||||
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
if (Signature == Farc.FArC)
|
||||
using (MSIO.MemoryStream memorystream = new MSIO.MemoryStream(
|
||||
File.ReadAllBytes(file, Files[i].SizeComp, Files[i].Offset)))
|
||||
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(file, Files[i].SizeUnc, Files[i].Offset);
|
||||
|
||||
if (SaveToDisk)
|
||||
{
|
||||
File.WriteAllBytes(MSIO.Path.Combine(directory, Files[i].Name), Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
}
|
||||
}
|
||||
Console.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
int Mode = reader.ReadInt32Endian(true);
|
||||
reader.ReadUInt32();
|
||||
bool GZip = (Mode & 2) == 2;
|
||||
bool ECB = (Mode & 4) == 4;
|
||||
|
||||
int FARCType = reader.ReadInt32Endian(true);
|
||||
FT = FARCType == 0x10;
|
||||
bool CBC = !FT && FARCType != 0x40;
|
||||
if (ECB && CBC)
|
||||
{
|
||||
byte[] Header = new byte[HeaderLength - 0x08];
|
||||
FT = true;
|
||||
reader.Close();
|
||||
MSIO.FileStream stream = new MSIO.FileStream(file, MSIO.FileMode.Open,
|
||||
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite);
|
||||
stream.Seek(0x10, 0);
|
||||
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Header, 0x00, HeaderLength - 0x08);
|
||||
Header = SkipData(Header, 0x10);
|
||||
Stream CBCreader = new Stream(new MSIO.MemoryStream(Header));
|
||||
CBCreader.BaseStream.Seek(0, 0);
|
||||
|
||||
FARCType = CBCreader.ReadInt32Endian(true);
|
||||
FT = FARCType == 0x10;
|
||||
if (CBCreader.ReadInt32Endian(true) == 1)
|
||||
Files = new FARCFile[CBCreader.ReadInt32Endian(true)];
|
||||
CBCreader.ReadUInt32();
|
||||
HeaderReader(HeaderLength, ref Files, ref CBCreader);
|
||||
CBCreader.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (reader.ReadInt32Endian(true) == 1)
|
||||
Files = new FARCFile[reader.ReadInt32Endian(true)];
|
||||
reader.ReadUInt32();
|
||||
HeaderReader(HeaderLength, ref Files, ref reader);
|
||||
reader.Close();
|
||||
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 = ECB || Files[i].ECB ? Files[i].SizeComp.Align(0x10) : Files[i].SizeComp;
|
||||
MSIO.FileStream stream = new MSIO.FileStream(file, MSIO.FileMode.Open,
|
||||
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 (ECB)
|
||||
if (FARCType.HasFlag(Type.ECB))
|
||||
{
|
||||
if ((FT && Files[i].ECB) || CBC)
|
||||
if ((FT && Files[i].Type.HasFlag(Type.ECB)) || CBC)
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
@@ -151,19 +162,16 @@ namespace KKdMainLib
|
||||
}
|
||||
|
||||
bool Compressed = false;
|
||||
bool LocalGZip = (FT && Files[i].GZip) || GZip && Files[i].SizeUnc != 0;
|
||||
if (LocalGZip)
|
||||
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();
|
||||
}
|
||||
if (Encrypted) { gZipStream = new GZipStream(new MSIO.MemoryStream(Files[i].Data),
|
||||
CompressionMode.Decompress); stream.Close(); }
|
||||
else gZipStream = new GZipStream(stream, CompressionMode.Decompress);
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
byte[] Temp = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Temp, 0, Files[i].SizeUnc);
|
||||
Files[i].Data = Temp;
|
||||
|
||||
Compressed = true;
|
||||
}
|
||||
@@ -174,109 +182,79 @@ namespace KKdMainLib
|
||||
stream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
if (SaveToDisk)
|
||||
{
|
||||
File.WriteAllBytes(MSIO.Path.Combine(directory, Files[i].Name), Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
}
|
||||
|
||||
}
|
||||
Console.Clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
byte[] SkipData(byte[] Data, int Skip)
|
||||
private void SaveToDisk()
|
||||
{
|
||||
if (DirectoryPath == null || Files == null) return;
|
||||
if (DirectoryPath == "" || Files.Length < 1) return;
|
||||
MSIO.Directory.CreateDirectory(DirectoryPath);
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(DirectoryPath, Files[i].Name), Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] SkipData(byte[] Data, int Skip)
|
||||
{
|
||||
byte[] SkipData = new byte[Data.Length - Skip];
|
||||
for (int i = 0; i < Data.Length - Skip; i++) SkipData[i] = Data[i + Skip];
|
||||
return SkipData;
|
||||
}
|
||||
|
||||
void HeaderReader(int HeaderLenght, ref FARCFile[] Files, ref Stream reader)
|
||||
public FARC Pack()
|
||||
{
|
||||
if (Files == null)
|
||||
{
|
||||
int Count = 0;
|
||||
long Position = reader.BaseStream.Position;
|
||||
while (reader.BaseStream.Position < HeaderLenght)
|
||||
{
|
||||
reader.NullTerminated();
|
||||
reader.ReadInt32();
|
||||
if (Signature != Farc.FArc ) reader.ReadInt32();
|
||||
reader.ReadInt32();
|
||||
if (Signature == Farc.FARC && FT) reader.ReadInt32();
|
||||
Count++;
|
||||
}
|
||||
reader.Seek(Position, 0);
|
||||
Files = new FARCFile[Count];
|
||||
}
|
||||
|
||||
int LocalMode = 0;
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
Files[i].Name = reader.NullTerminatedUTF8();
|
||||
Files[i].Offset = reader.ReadInt32Endian(true);
|
||||
if (Signature != Farc.FArc) Files[i].SizeComp = reader.ReadInt32Endian(true);
|
||||
Files[i].SizeUnc = reader.ReadInt32Endian(true);
|
||||
if (Signature == Farc.FARC && FT)
|
||||
{
|
||||
LocalMode = reader.ReadInt32Endian(true);
|
||||
Files[i].GZip = (LocalMode & 2) == 2;
|
||||
Files[i].ECB = (LocalMode & 4) == 4;
|
||||
}
|
||||
}
|
||||
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;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Pack(string file)
|
||||
public void CompressStuff()
|
||||
{
|
||||
Files = null;
|
||||
FT = false;
|
||||
string[] files = MSIO.Directory.GetFiles(file);
|
||||
Files = new FARCFile[files.Length];
|
||||
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
Files[i] = new FARCFile { Name = files[i] };
|
||||
string ext = MSIO.Path.GetExtension(files[i]).ToLower();
|
||||
if (ext == ".a3da" || ext == ".mot" || ext == ".vag")
|
||||
Signature = Farc.FArc;
|
||||
string ext = Path.GetExtension(Files[i].Name).ToLower();
|
||||
if (ext == ".a3da" || ext == ".diva" || ext == ".vag") Signature = Farc.FArc;
|
||||
}
|
||||
files = null;
|
||||
|
||||
Stream writer = File.OpenWriter(file + ".farc", true);
|
||||
Stream writer = File.OpenWriter(DirectoryPath + ".farc", true);
|
||||
writer.WriteEndian((int)Signature, true);
|
||||
|
||||
Stream HeaderWriter = File.OpenWriter();
|
||||
for (int i = 0; i < 3; i++) HeaderWriter.WriteByte(0x00);
|
||||
if (Signature == Farc.FArc) HeaderWriter.WriteByte(0x20);
|
||||
else if (Signature == Farc.FArC) HeaderWriter.WriteByte(0x10);
|
||||
if (Signature == Farc.FArc) HeaderWriter.WriteEndian(0x20, true);
|
||||
else if (Signature == Farc.FArC) HeaderWriter.WriteEndian(0x10, true);
|
||||
else if (Signature == Farc.FARC)
|
||||
{
|
||||
HeaderWriter.WriteByte(0x06);
|
||||
for (int i = 0; i < 7; i++) HeaderWriter.WriteByte(0x00);
|
||||
HeaderWriter.WriteByte(0x40);
|
||||
for (int i = 0; i < 8; i++) HeaderWriter.WriteByte(0x00);
|
||||
HeaderWriter.WriteEndian((int)FARCType, true);
|
||||
HeaderWriter.Write (0x00);
|
||||
HeaderWriter.WriteEndian(0x40, true);
|
||||
HeaderWriter.Write (0x00);
|
||||
}
|
||||
int HeaderPartLength = Signature == Farc.FArc ? 0x09 : 0x0D;
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
HeaderWriter.Length += MSIO.Path.GetFileName(Files[i].Name).Length + HeaderPartLength;
|
||||
HeaderWriter.Length += Path.GetFileName(Files[i].Name).Length + HeaderPartLength;
|
||||
writer.WriteEndian(HeaderWriter.Length, true);
|
||||
writer.Write(HeaderWriter.ToArray(true));
|
||||
HeaderWriter = null;
|
||||
|
||||
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.Seek(0x1C, 0);
|
||||
else writer.Seek(0x0C, 0);
|
||||
writer.Position = Signature == Farc.FARC ? 0x1C : 0x0C;
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
writer.Write(MSIO.Path.GetFileName(Files[i].Name) + "\0");
|
||||
writer.Write(Path.GetFileName(Files[i].Name) + "\0");
|
||||
writer.WriteEndian(Files[i].Offset, true);
|
||||
if (Signature != Farc.FArc)
|
||||
writer.WriteEndian(Files[i].SizeComp, true);
|
||||
@@ -285,35 +263,33 @@ namespace KKdMainLib
|
||||
writer.Close();
|
||||
}
|
||||
|
||||
void CompressStuff(int i, ref FARCFile[] Files, ref Stream writer)
|
||||
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;
|
||||
|
||||
if (Signature != Farc.FArc)
|
||||
if (Signature == Farc.FArC || (Signature == Farc.FARC && FARCType.HasFlag(Type.GZip)))
|
||||
{
|
||||
if (Signature != Farc.FArc)
|
||||
{
|
||||
MSIO.MemoryStream stream = new MSIO.MemoryStream();
|
||||
using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Compress))
|
||||
gZipStream.Write(Files[i].Data, 0, Files[i].Data.Length);
|
||||
Files[i].Data = stream.ToArray();
|
||||
stream.Dispose();
|
||||
Files[i].SizeComp = Files[i].Data.Length;
|
||||
}
|
||||
else if (Signature == Farc.FARC)
|
||||
{
|
||||
int AlignData = Files[i].Data.Length.Align(0x40);
|
||||
byte[] Data = new byte[AlignData];
|
||||
for (int i1 = 0; i1 < Files[i].Data.Length; i1++)
|
||||
Data[i1] = Files[i].Data[i1];
|
||||
for (int i1 = Files[i].Data.Length; i1 < AlignData; i1++)
|
||||
Data[i1] = 0x78;
|
||||
|
||||
Files[i].Data = Encrypt(Data, false);
|
||||
}
|
||||
Files[i].Type |= Type.GZip;
|
||||
MSIO.MemoryStream stream = new MSIO.MemoryStream();
|
||||
using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Compress))
|
||||
gZipStream.Write(Files[i].Data, 0, Files[i].Data.Length);
|
||||
Files[i].Data = stream.ToArray();
|
||||
stream.Dispose();
|
||||
Files[i].SizeComp = Files[i].Data.Length;
|
||||
}
|
||||
|
||||
if (Signature == Farc.FARC && FARCType.HasFlag(Type.ECB))
|
||||
{
|
||||
int AlignData = Files[i].Data.Length.Align(0x40);
|
||||
byte[] Data = new byte[AlignData];
|
||||
for (int i1 = 0; i1 < AlignData ; i1++) Data[i1] = 0x78;
|
||||
for (int i1 = 0; i1 < Files[i].Data.Length; i1++) Data[i1] = Files[i].Data[i1];
|
||||
|
||||
Files[i].Data = Encrypt(Data, false);
|
||||
}
|
||||
|
||||
writer.Write(Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
|
||||
@@ -321,36 +297,43 @@ 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));
|
||||
}
|
||||
}
|
||||
|
||||
byte[] Encrypt(byte[] Data, bool isFT)
|
||||
private byte[] Encrypt(byte[] Data, bool isFT)
|
||||
{
|
||||
MSIO.MemoryStream stream = new MSIO.MemoryStream();
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(isFT, null).CreateEncryptor(),CryptoStreamMode.Write))
|
||||
GetAes(isFT, null).CreateEncryptor(), CryptoStreamMode.Write))
|
||||
cryptoStream.Write(Data, 0, Data.Length);
|
||||
return stream.ToArray();
|
||||
}
|
||||
|
||||
public enum Farc
|
||||
{
|
||||
FArc = 0x46417263,
|
||||
FArC = 0x46417243,
|
||||
FARC = 0x46415243,
|
||||
}
|
||||
|
||||
public struct FARCFile
|
||||
{
|
||||
public int Offset;
|
||||
public int SizeComp;
|
||||
public int SizeUnc;
|
||||
public bool GZip;
|
||||
public bool ECB;
|
||||
public Type Type;
|
||||
public byte[] Data;
|
||||
public string Name;
|
||||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
public enum Farc : int
|
||||
{
|
||||
FArc = 0x46417263,
|
||||
FArC = 0x46417243,
|
||||
FARC = 0x46415243,
|
||||
}
|
||||
|
||||
public enum Type : int
|
||||
{
|
||||
None = 0b000,
|
||||
GZip = 0b010,
|
||||
ECB = 0b100,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using MSIO = System.IO;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public static class Directory
|
||||
{
|
||||
public static bool Exists(string path) => MSIO.Directory.Exists(path);
|
||||
public static void Delete(string path) => MSIO.Directory.Delete(path);
|
||||
public static string GetCurrentDirectory() => MSIO.Directory.GetCurrentDirectory();
|
||||
public static string[] GetFiles(string path) => MSIO.Directory.GetFiles(path);
|
||||
public static string[] GetDirectories(string path) => MSIO.Directory.GetDirectories(path);
|
||||
public static MSIO.DirectoryInfo CreateDirectory(string path) => MSIO.Directory.CreateDirectory(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,13 +38,16 @@ namespace KKdMainLib.IO
|
||||
return Data.Replace("\r", "").Split('\n'); }
|
||||
|
||||
public static void WriteAllBytes(string file, byte[] data)
|
||||
{ Stream IO = OpenWriter(file); IO.Write(data); IO.Close(); }
|
||||
{ Stream IO = OpenWriter(file, true); IO.Write(data); IO.Close(); }
|
||||
|
||||
public static void WriteAllText (string file, string data)
|
||||
{ Stream IO = OpenWriter(file); IO.Write(data); IO.Close(); }
|
||||
{ Stream IO = OpenWriter(file, true); IO.Write(data); IO.Close(); }
|
||||
|
||||
public static void WriteAllLines(string file, string[] data)
|
||||
{ Stream IO = OpenWriter(file); for (int i = 0; i < data.Length; i++) IO.Write(data[i] + "\r\n"); IO.Close(); }
|
||||
{ Stream IO = OpenWriter(file, true); for (int i = 0; i < data.Length; i++)
|
||||
IO.Write(data[i] + "\r\n"); IO.Close(); }
|
||||
|
||||
public static bool Exists(string file) => MSIO.File.Exists(file);
|
||||
public static void Delete(string file) => MSIO.File.Delete(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@ namespace KKdMainLib.IO
|
||||
{
|
||||
public static class IOExtensions
|
||||
{
|
||||
public static string NullTerminatedASCII(this Stream stream, byte End = 0) => stream.NullTerminated(End).ToASCII();
|
||||
public static string NullTerminatedUTF8 (this Stream stream, byte End = 0) => stream.NullTerminated(End).ToUTF8 ();
|
||||
public static string NullTerminatedASCII(this Stream stream, byte End = 0) =>
|
||||
stream.NullTerminated(End).ToASCII();
|
||||
public static string NullTerminatedUTF8 (this Stream stream, byte End = 0) =>
|
||||
stream.NullTerminated(End).ToUTF8 ();
|
||||
public static byte[] NullTerminated (this Stream stream, byte End = 0)
|
||||
{
|
||||
List<byte> s = new List<byte>();
|
||||
while (true && stream.LongPosition > 0 && stream.LongPosition < stream.LongLength)
|
||||
while (stream.LongPosition < stream.LongLength)
|
||||
{
|
||||
byte a = stream.ReadByte();
|
||||
if (a == End) break;
|
||||
@@ -17,5 +19,59 @@ namespace KKdMainLib.IO
|
||||
}
|
||||
return s.ToArray();
|
||||
}
|
||||
public static char PeekCharUTF8(this Stream stream)
|
||||
{ long LongPosition = stream.LongPosition; char val = stream.ReadCharUTF8();
|
||||
stream.LongPosition = LongPosition; return val; }
|
||||
public static Stream SkipWhitespace(this Stream stream)
|
||||
{
|
||||
while (true)
|
||||
if (char.IsWhiteSpace(stream.PeekCharUTF8())) stream.ReadCharUTF8();
|
||||
else break;
|
||||
return stream;
|
||||
}
|
||||
public static bool Assert(this Stream stream, char next)
|
||||
{ if (stream.PeekCharUTF8() == next) { stream.ReadCharUTF8(); return true; } else return false; }
|
||||
public static bool Assert(this Stream stream, string next)
|
||||
{
|
||||
for (var i = 0; i < next.Length; i++)
|
||||
if (!stream.Assert(next[i])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static long ReadIntX(this Stream stream ) => stream.IsX ?
|
||||
stream.ReadInt64() : stream.ReadUInt32Endian( );
|
||||
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;
|
||||
long Position = stream.LongPosition;
|
||||
if (Offset == 0) { Position += stream.IsX ? 8 : 4; Offset = stream.ReadIntX(); }
|
||||
stream.LongPosition = Offset;
|
||||
if (Length == 0) arr = stream.NullTerminated();
|
||||
else arr = stream.ReadBytes(Length);
|
||||
stream.LongPosition = Position;
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static string ReadStringAtOffset(this Stream stream, long Offset = 0, long Length = 0)
|
||||
{
|
||||
string s = null;
|
||||
long Position = stream.LongPosition;
|
||||
if (Offset == 0) { Position += stream.IsX ? 8 : 4; Offset = stream.ReadIntX(); }
|
||||
stream.LongPosition = Offset;
|
||||
if (Length == 0) s = stream.NullTerminatedUTF8();
|
||||
else s = stream.ReadStringUTF8(Length);
|
||||
stream.LongPosition = Position;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using MSIO = System.IO;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public static class Path
|
||||
{
|
||||
public static string GetFileName(string path) =>
|
||||
MSIO.Path.GetFileName(path);
|
||||
public static string GetFileNameWithoutExtension(string path) =>
|
||||
MSIO.Path.GetFileNameWithoutExtension(path);
|
||||
public static string GetExtension(string path) =>
|
||||
MSIO.Path.GetExtension(path);
|
||||
public static string GetFullPath(string path) =>
|
||||
MSIO.Path.GetFullPath(path);
|
||||
public static string Combine(string path1, string path2) =>
|
||||
MSIO.Path.Combine(path1, path2);
|
||||
public static string Combine(string path1, string path2, string path3) =>
|
||||
MSIO.Path.Combine(path1, path2, path3);
|
||||
public static string Combine(string path1, string path2, string path3, string path4) =>
|
||||
MSIO.Path.Combine(path1, path2, path3, path4);
|
||||
public static string Combine(params string[] paths) =>
|
||||
MSIO.Path.Combine(paths);
|
||||
public static string GetDirectoryName(string path) =>
|
||||
MSIO.Path.GetDirectoryName(path);
|
||||
}
|
||||
}
|
||||
+88
-95
@@ -7,7 +7,7 @@ namespace KKdMainLib.IO
|
||||
public unsafe class Stream : IDisposable
|
||||
{
|
||||
private MSIO.Stream stream;
|
||||
private int i, i0, TempBitRead, TempBitWrite;
|
||||
private int I, i, i0, TempBitRead, TempBitWrite;
|
||||
private ushort ValRead;
|
||||
private byte BitRead, BitWrite, ValWrite;
|
||||
private byte[] buf;
|
||||
@@ -28,12 +28,16 @@ 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 Position { get => ( int)stream.Position; set => stream.Position = value ; }
|
||||
public uint UIntPosition { get => (uint)stream.Position; set => stream.Position = value ; }
|
||||
public long LongPosition { get => stream.Position; set => stream.Position = 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; }
|
||||
public uint UIntPosition
|
||||
{ get => (uint)stream.Position - UIntOffset; set => stream.Position = value + UIntOffset; }
|
||||
public long LongPosition
|
||||
{ get => stream.Position - LongOffset; set => stream.Position = value + LongOffset; }
|
||||
|
||||
public bool CanRead => stream.CanRead;
|
||||
public bool CanSeek => stream.CanSeek;
|
||||
@@ -45,11 +49,12 @@ namespace KKdMainLib.IO
|
||||
public Stream(MSIO.Stream output = null, byte[] Data = null, bool isBE = false)
|
||||
{
|
||||
if (output == null) output = MSIO.Stream.Null;
|
||||
LongOffset = 0;
|
||||
BitRead = 8;
|
||||
ValRead = ValRead = BitWrite = 0;
|
||||
stream = output;
|
||||
Format = Main.Format.NULL;
|
||||
buf = new byte[16];
|
||||
buf = new byte[128];
|
||||
IsBE = isBE;
|
||||
data = Data;
|
||||
}
|
||||
@@ -121,12 +126,9 @@ namespace KKdMainLib.IO
|
||||
public uint ReadUInt32Endian() => ( uint)UIntFromArray(4, IsBE);
|
||||
public long ReadInt64Endian() => IntFromArray(8, IsBE);
|
||||
public ulong ReadUInt64Endian() => UIntFromArray(8, IsBE);
|
||||
public Half ReadHalfEndian()
|
||||
{ ushort a = ReadUInt16Endian(); return ( Half ) a; }
|
||||
public float ReadSingleEndian()
|
||||
{ uint a = ReadUInt32Endian(); return *( float*)&a; }
|
||||
public double ReadDoubleEndian()
|
||||
{ ulong a = ReadUInt64Endian(); return *(double*)&a; }
|
||||
public Half ReadHalfEndian() { ushort a = ReadUInt16Endian(); return ( Half ) a; }
|
||||
public float ReadSingleEndian() { uint a = ReadUInt32Endian(); return *( float*)&a; }
|
||||
public double ReadDoubleEndian() { ulong a = ReadUInt64Endian(); return *(double*)&a; }
|
||||
|
||||
public short ReadInt16Endian(bool IsBE) => ( short) IntFromArray(2, IsBE);
|
||||
public ushort ReadUInt16Endian(bool IsBE) => (ushort)UIntFromArray(2, IsBE);
|
||||
@@ -175,78 +177,66 @@ namespace KKdMainLib.IO
|
||||
public void Write(double? val) => Write(val.GetValueOrDefault());
|
||||
|
||||
public void Write( bool* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
{ 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++) Write(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) stream.WriteByte((byte) val[i]); }
|
||||
public void Write( byte* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) stream.WriteByte( val[i]); }
|
||||
public void Write( short* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(2, val[i]); }
|
||||
public void Write(ushort* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(2, val[i]); }
|
||||
public void Write( int* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, val[i]); }
|
||||
public void Write( uint* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, val[i]); }
|
||||
public void Write( long* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(8, val[i]); }
|
||||
public void Write( ulong* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(8, val[i]); }
|
||||
public void Write( float* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, *( uint*)&val[i]); }
|
||||
public void Write(double* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, *(ulong*)&val[i]); }
|
||||
|
||||
public void WriteEndian( short* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(2, Endian(val[i], 2, IsBE)); }
|
||||
public void WriteEndian(ushort* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(2, Endian(val[i], 2, IsBE)); }
|
||||
public void WriteEndian( int* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, Endian(val[i], 4, IsBE)); }
|
||||
public void WriteEndian( uint* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, Endian(val[i], 4, IsBE)); }
|
||||
public void WriteEndian( long* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(8, Endian(val[i], 8, IsBE)); }
|
||||
public void WriteEndian( ulong* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(8, Endian(val[i], 8, IsBE)); }
|
||||
public void WriteEndian( float* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, Endian(*( uint*)&val[i], 4, IsBE)); }
|
||||
public void WriteEndian(double* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
|
||||
{ for (i = 0; i < Length; i++) ToArray(8, Endian(*(ulong*)&val[i], 8, IsBE)); }
|
||||
|
||||
public void WriteEndian( short* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(2, Endian(val[i], 2, IsBE)); }
|
||||
public void WriteEndian(ushort* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(2, Endian(val[i], 2, IsBE)); }
|
||||
public void WriteEndian( int* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, Endian(val[i], 4, IsBE)); }
|
||||
public void WriteEndian( uint* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, Endian(val[i], 4, IsBE)); }
|
||||
public void WriteEndian( long* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(8, Endian(val[i], 8, IsBE)); }
|
||||
public void WriteEndian( ulong* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(8, Endian(val[i], 8, IsBE)); }
|
||||
public void WriteEndian( float* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, Endian(*( uint*)&val[i], 4, IsBE)); }
|
||||
public void WriteEndian(double* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
{ for (i = 0; i < Length; i++) ToArray(8, Endian(*(ulong*)&val[i], 8, IsBE)); }
|
||||
|
||||
public void Write( char val, bool UTF8 = true)
|
||||
{ if (UTF8) Write(val.ToString().ToUTF8()); else Write(val.ToString().ToASCII()); }
|
||||
public void Write(string val, bool UTF8 = true)
|
||||
{ if (UTF8) Write(val .ToUTF8()); else Write(val .ToASCII()); }
|
||||
|
||||
public void Write(string Data, ref bool? val) => Write(Data, val.GetValueOrDefault() );
|
||||
public void Write(string Data, long? val) => Write(Data, val.GetValueOrDefault() );
|
||||
public void Write(string Data, ulong? val) => Write(Data, val.GetValueOrDefault() );
|
||||
public void Write(string Data, double? val) => Write(Data, val.ToString( ));
|
||||
public void Write(string Data, double? val, byte r) => Write(Data, val.ToString(r ));
|
||||
public void Write(string Data, ref bool val) => Write(Data, Main.ToString(val));
|
||||
public void Write(string Data, long val) => Write(Data, val.ToString( ));
|
||||
public void Write(string Data, ulong val) => Write(Data, val.ToString( ));
|
||||
public void Write(string Data, double val) => Write(Data, val.ToString( ));
|
||||
public void Write(string Data, double val, byte r) => Write(Data, val.ToString(r ));
|
||||
public void Write(string Data, string val) => Write((Data + val + "\n").ToUTF8());
|
||||
|
||||
public void WriteEndian( short val) => ToArray(2, Endian(val, 2, IsBE));
|
||||
public void WriteEndian(ushort val) => ToArray(2, Endian(val, 2, IsBE));
|
||||
@@ -267,58 +257,61 @@ namespace KKdMainLib.IO
|
||||
public void WriteEndian(double val, bool IsBE) => ToArray(8, Endian(*(ulong*)&val, 8, IsBE));
|
||||
|
||||
public long Endian( long BE, byte Length, bool IsBE)
|
||||
{ if (IsBE) { for (byte i = 0; i < Length; i++) { buf[i] = (byte)BE; BE >>= 8; } BE = 0;
|
||||
for (byte i = 0; i < Length; i++) { BE |= buf[i]; if (i < Length - 1) BE <<= 8; } } return BE; }
|
||||
{ if (IsBE) { for (I = 0; I < Length; I++) { buf[I] = (byte)BE; BE >>= 8; } BE = 0;
|
||||
for (I = 0; I < Length; I++) { BE |= buf[I]; if (I < Length - 1) BE <<= 8; } } return BE; }
|
||||
|
||||
public ulong Endian( ulong BE, byte Length, bool IsBE)
|
||||
{ if (IsBE) { for (byte i = 0; i < Length; i++) { buf[i] = (byte)BE; BE >>= 8; } BE = 0;
|
||||
for (byte i = 0; i < Length; i++) { BE |= buf[i]; if (i < Length - 1) BE <<= 8; } } return BE; }
|
||||
|
||||
/*public void WriteEndian( short val) => ToArrayEndian(2, val, IsBE);
|
||||
public void WriteEndian(ushort val) => ToArrayEndian(2, val, IsBE);
|
||||
public void WriteEndian( int val) => ToArrayEndian(4, val, IsBE);
|
||||
public void WriteEndian( uint val) => ToArrayEndian(4, val, IsBE);
|
||||
public void WriteEndian( long val) => ToArrayEndian(8, val, IsBE);
|
||||
public void WriteEndian( ulong val) => ToArrayEndian(8, val, IsBE);
|
||||
public void WriteEndian( float val) => ToArrayEndian(4, *( uint*)&val, IsBE);
|
||||
public void WriteEndian(double val) => ToArrayEndian(8, *(ulong*)&val, IsBE);
|
||||
|
||||
public void WriteEndian( short val, bool IsBE) => ToArrayEndian(2, val, IsBE);
|
||||
public void WriteEndian(ushort val, bool IsBE) => ToArrayEndian(2, val, IsBE);
|
||||
public void WriteEndian( int val, bool IsBE) => ToArrayEndian(4, val, IsBE);
|
||||
public void WriteEndian( uint val, bool IsBE) => ToArrayEndian(4, val, IsBE);
|
||||
public void WriteEndian( long val, bool IsBE) => ToArrayEndian(8, val, IsBE);
|
||||
public void WriteEndian( ulong val, bool IsBE) => ToArrayEndian(8, val, IsBE);
|
||||
public void WriteEndian( float val, bool IsBE) => ToArrayEndian(4, *( uint*)&val, IsBE);
|
||||
public void WriteEndian(double val, bool IsBE) => ToArrayEndian(8, *(ulong*)&val, IsBE);
|
||||
|
||||
private void ToArrayEndian(byte L, long val, bool IsBE = false)
|
||||
{ CheckWrited(); if (IsBE) for (i = L; i > 0; i--) { buf[i - 1] = (byte)val; val >>= 8; }
|
||||
else for (i = 0; i < L; i++) { buf[i ] = (byte)val; val >>= 8; } Write(buf, L); }
|
||||
|
||||
private void ToArrayEndian(byte L, ulong val, bool IsBE = false)
|
||||
{ CheckWrited(); if (IsBE) for (i = L; i > 0; i--) { buf[i - 1] = (byte)val; val >>= 8; }
|
||||
else for (i = 0; i < L; i++) { buf[i ] = (byte)val; val >>= 8; } Write(buf, L); }*/
|
||||
{ if (IsBE) { for (I = 0; I < Length; I++) { buf[I] = (byte)BE; BE >>= 8; } BE = 0;
|
||||
for (I = 0; I < Length; I++) { BE |= buf[I]; if (I < Length - 1) BE <<= 8; } } return BE; }
|
||||
|
||||
private void ToArray(byte L, long val)
|
||||
{ CheckWrited(); for (i = 0; i < L; i++) { buf[i] = (byte)val; val >>= 8; } Write(buf, L); }
|
||||
{ CheckWrited(); for (I = 0; I < L; I++) { buf[I] = (byte)val; val >>= 8; } stream.Write(buf, 0, L); }
|
||||
|
||||
private void ToArray(byte L, ulong val)
|
||||
{ CheckWrited(); for (i = 0; i < L; i++) { buf[i] = (byte)val; val >>= 8; } Write(buf, L); }
|
||||
{ CheckWrited(); for (I = 0; I < L; I++) { buf[I] = (byte)val; val >>= 8; } stream.Write(buf, 0, L); }
|
||||
|
||||
private long IntFromArray(byte L, bool IsBE = false) { Read(L); long val = 0; if (IsBE)
|
||||
for (i = 0; i < L; i++) { val <<= 8; val |= buf[i ]; } else
|
||||
for (i = L; i > 0; i--) { val <<= 8; val |= buf[i - 1]; } return val; }
|
||||
private long IntFromArray(byte L) { stream.Read(buf, 0, L); long val = 0;
|
||||
for (I = L; I > 0; I--) { val <<= 8; val |= buf[I - 1]; } return val; }
|
||||
|
||||
private ulong UIntFromArray(byte L, bool IsBE = false) { Read(L); ulong val = 0; if (IsBE)
|
||||
for (i = 0; i < L; i++) { val <<= 8; val |= buf[i ]; } else
|
||||
for (i = L; i > 0; i--) { val <<= 8; val |= buf[i - 1]; } return val; }
|
||||
private ulong UIntFromArray(byte L) { stream.Read(buf, 0, L); ulong val = 0;
|
||||
for (I = L; I > 0; I--) { val <<= 8; val |= buf[I - 1]; } return val; }
|
||||
|
||||
private void Read(byte Length) => stream.Read(buf, 0, Length);
|
||||
private long IntFromArray(byte L, bool IsBE) { stream.Read(buf, 0, L); long val = 0; if (IsBE)
|
||||
for (I = 0; I < L; I++) { val <<= 8; val |= buf[I ]; } else
|
||||
for (I = L; I > 0; I--) { val <<= 8; val |= buf[I - 1]; } return val; }
|
||||
|
||||
private ulong UIntFromArray(byte L, bool IsBE) { stream.Read(buf, 0, L); ulong val = 0; if (IsBE)
|
||||
for (I = 0; I < L; I++) { val <<= 8; val |= buf[I ]; } else
|
||||
for (I = L; I > 0; I--) { val <<= 8; val |= buf[I - 1]; } return val; }
|
||||
|
||||
public char ReadChar(bool UTF8 = true)
|
||||
{ if (UTF8) return ReadCharUTF8();
|
||||
else return (char)stream.ReadByte(); }
|
||||
|
||||
public char ReadCharUTF8()
|
||||
{
|
||||
byte t;
|
||||
int T;
|
||||
int val = 0;
|
||||
for (I = 0, i0 = 4; I < i0; I++)
|
||||
{
|
||||
T = stream.ReadByte();
|
||||
if (T == -1) return '\uFFFF';
|
||||
t = (byte)T;
|
||||
|
||||
if ((t & 0xC0) == 0x80 && I > 0) val = (val << 6) | (t & 0x3F);
|
||||
else if ((t & 0x80) == 0x00 && I == 0) return (char)t;
|
||||
else if ((t & 0xE0) == 0xC0 && I == 0) { val = t & 0x1F; i0 = 2; }
|
||||
else if ((t & 0xF0) == 0xE0 && I == 0) { val = t & 0x0F; i0 = 3; }
|
||||
else if ((t & 0xF8) == 0xF0 && I == 0) { val = t & 0x07; i0 = 4; }
|
||||
else return '\uFFFF';
|
||||
}
|
||||
return (char)val;
|
||||
}
|
||||
|
||||
public string ReadString(long Length, bool UTF8 = true)
|
||||
{ if (UTF8) return ReadStringUTF8 (Length);
|
||||
else return ReadStringASCII(Length); }
|
||||
else return ReadStringASCII(Length); }
|
||||
|
||||
public string ReadStringUTF8 (long Length) => ReadBytes(Length).ToUTF8 ();
|
||||
public string ReadStringASCII(long Length) => ReadBytes(Length).ToASCII();
|
||||
@@ -326,7 +319,7 @@ namespace KKdMainLib.IO
|
||||
|
||||
public string ReadString(long? Length, bool UTF8 = true)
|
||||
{ if (UTF8) return ReadStringUTF8 (Length);
|
||||
else return ReadStringASCII(Length); }
|
||||
else return ReadStringASCII(Length); }
|
||||
|
||||
public string ReadStringUTF8 (long? Length) => ReadBytes(Length).ToUTF8 ();
|
||||
public string ReadStringASCII(long? Length) => ReadBytes(Length).ToASCII();
|
||||
|
||||
@@ -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,27 +35,42 @@
|
||||
<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="DEX.cs" />
|
||||
<Compile Include="DIVAFILE.cs" />
|
||||
<Compile Include="DB\Spr.cs" />
|
||||
<Compile Include="IO\Directory.cs" />
|
||||
<Compile Include="IO\File.cs" />
|
||||
<Compile Include="IO\IOExtensions.cs" />
|
||||
<Compile Include="IO\Path.cs" />
|
||||
<Compile Include="IO\Stream.cs" />
|
||||
<Compile Include="MathExtensions.cs" />
|
||||
<Compile Include="MessagePack\JSONIO.cs" />
|
||||
<Compile Include="MessagePack\MPExt.cs" />
|
||||
<Compile Include="MessagePack\MsgPack.cs" />
|
||||
<Compile Include="MessagePack\IO.cs" />
|
||||
<Compile Include="STR.cs" />
|
||||
<Compile Include="Types\Half.cs" />
|
||||
<Compile Include="A3DA\A3DA.cs" />
|
||||
<Compile Include="Types\IKeyFrame.cs" />
|
||||
<Compile Include="Types\KKdList.cs" />
|
||||
<Compile Include="Types\Pointer.cs" />
|
||||
<Compile Include="Types\Vector.cs" />
|
||||
<Compile Include="DataBank.cs" />
|
||||
<Compile Include="DCC.cs" />
|
||||
<Compile Include="DEX.cs" />
|
||||
<Compile Include="DIVAFILE.cs" />
|
||||
<Compile Include="FARC.cs" />
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="MathExtensions.cs" />
|
||||
<Compile Include="PDHeader.cs" />
|
||||
<Compile Include="POF.cs" />
|
||||
<Compile Include="STR.cs" />
|
||||
<Compile Include="Text.cs" />
|
||||
<Compile Include="Xml.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -61,8 +78,6 @@
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
+70
-63
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
@@ -68,58 +70,59 @@ namespace KKdMainLib
|
||||
public static string Choose(int code, string filetype, out string[] FileNames)
|
||||
{
|
||||
string MsgPack = GetArgs("MessagePack", true, "mp");
|
||||
string JSON = GetArgs("JSON", true, "json");
|
||||
string BIN = GetArgs("BIN", true, "bin");
|
||||
string XML = GetArgs("XML", true, "xml");
|
||||
|
||||
string WAV = GetArgs("WAV", true, "wav");
|
||||
|
||||
FileNames = new string[0];
|
||||
if (code == 1)
|
||||
{
|
||||
Console.WriteLine("Choose file(s) to open:");
|
||||
OpenFileDialog ofd = new OpenFileDialog { InitialDirectory =
|
||||
Application.StartupPath, Multiselect = true };
|
||||
OpenFileDialog ofd = new OpenFileDialog { InitialDirectory = Application.StartupPath,
|
||||
Multiselect = true, Title = "Choose file(s) to open:" };
|
||||
|
||||
if (filetype == "a3da") ofd.Filter = GetArgs("A3DA", "a3da", "mp") +
|
||||
GetArgs("A3DA", true, "a3da") + MsgPack;
|
||||
else if (filetype == "bin" ) ofd.Filter = GetArgs("BIN" , "bin", "mp") +
|
||||
BIN + MsgPack;
|
||||
else if (filetype == "bon" ) ofd.Filter = GetArgs("BON" , "bon", "bin", "mp") +
|
||||
GetArgs("BON", true, "bon") + BIN + MsgPack;
|
||||
else if (filetype == "dex" ) ofd.Filter = GetArgs("DEX" , "dex", "bin", "mp") +
|
||||
GetArgs("DEX", true, "dex") + BIN + MsgPack;
|
||||
ofd.Filter = GetArgs("All;", false, "*");
|
||||
if (filetype == "a3da") ofd.Filter = GetArgs("A3DA", "a3da", "json", "mp") +
|
||||
GetArgs("A3DA", true, "a3da") + 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") +
|
||||
GetArgs("BON", true, "bon") + BIN + JSON + MsgPack;
|
||||
else if (filetype == "databank") ofd.Filter = GetArgs("DAT", "dat", "json", "mp") +
|
||||
GetArgs("DAT", true, "dat") + JSON + MsgPack;
|
||||
else if (filetype == "dex" ) ofd.Filter = GetArgs("DEX" , "dex", "bin", "json", "mp") +
|
||||
GetArgs("DEX", true, "dex") + BIN + JSON + MsgPack;
|
||||
else if (filetype == "diva") ofd.Filter = GetArgs("DIVA", "diva", "wav") +
|
||||
GetArgs("DIVA", true, "diva") + GetArgs("WAV", true, "wav");
|
||||
else if (filetype == "dsc" ) ofd.Filter = GetArgs("DSC" , "dsc", "mp") +
|
||||
GetArgs("DSC", true, "dsc") + MsgPack;
|
||||
else if (filetype == "dsc" ) ofd.Filter = GetArgs("DSC" , "dsc", "json", "mp") +
|
||||
GetArgs("DSC", true, "dsc") + JSON + MsgPack;
|
||||
else if (filetype == "farc") ofd.Filter = "FARC Archives (*.farc)|*.farc";
|
||||
else if (filetype == "image") ofd.Filter = GetArgs("Image", "dds", "png") +
|
||||
GetArgs("DDS", true, "dds") + GetArgs("PNG", true, "png");
|
||||
else if (filetype == "kki") ofd.Filter = GetArgs("KKI", "kki");
|
||||
else if (filetype == "mot") ofd.Filter = GetArgs("MOT", "mot", "mp") +
|
||||
GetArgs("MOT", true, "mot") + MsgPack;
|
||||
else if (filetype == "ppd") ofd.Filter = GetArgs("PPD", "ppd", "pak", "mod") +
|
||||
else if (filetype == "json") ofd.Filter = "JSON (*.json)|*.json";
|
||||
else if (filetype == "kki" ) ofd.Filter = GetArgs("KKI", "kki");
|
||||
else if (filetype == "mp" ) ofd.Filter = GetArgs("MessagePack", "mp");
|
||||
else if (filetype == "ppd" ) ofd.Filter = GetArgs("PPD", "ppd", "pak", "mod") +
|
||||
GetArgs("PPD", true, "ppd") + GetArgs("PAK", true, "pak") + GetArgs("MOD", true, "mod");
|
||||
else if (filetype == "str") ofd.Filter = GetArgs("STR", "str", "bin", "mp") +
|
||||
GetArgs("STR", true, "str") + BIN + MsgPack;
|
||||
else if (filetype == "vag") ofd.Filter = GetArgs("VAG", "vag", "wav") +
|
||||
else if (filetype == "str" ) ofd.Filter = GetArgs("STR", "str", "bin", "json", "mp") +
|
||||
GetArgs("STR", true, "str") + BIN + JSON + MsgPack;
|
||||
else if (filetype == "vag" ) ofd.Filter = GetArgs("VAG", "vag", "wav") +
|
||||
GetArgs("VAG", true, "vag") + GetArgs("WAV", true, "wav");
|
||||
else if (filetype == "xml") ofd.Filter = GetArgs("XML", "xml");
|
||||
else ofd.Filter = GetArgs("All;", false, "*");
|
||||
|
||||
if (ofd.ShowDialog() == DialogResult.OK)
|
||||
FileNames = ofd.FileNames;
|
||||
}
|
||||
else if (code == 2)
|
||||
{
|
||||
FolderBrowserDialog fbd = new FolderBrowserDialog();
|
||||
Console.WriteLine("Choose folder:");
|
||||
fbd.SelectedPath = Application.StartupPath;
|
||||
if (fbd.ShowDialog() == DialogResult.OK)
|
||||
return fbd.SelectedPath.ToString();
|
||||
OpenFileDialog ofd = new OpenFileDialog { InitialDirectory = Application.StartupPath,
|
||||
ValidateNames = false, CheckFileExists = false, Filter = " | ", CheckPathExists = true,
|
||||
Title = "Choose any file in folder:", FileName = "Folder Selection." };
|
||||
if (ofd.ShowDialog() == DialogResult.OK)
|
||||
return Path.GetDirectoryName(ofd.FileName);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void ChooseSave(int code, string filetype,
|
||||
public static void ChooseSave(string filetype,
|
||||
out string InitialDirectory, out string[] FileNames)
|
||||
{
|
||||
InitialDirectory = "";
|
||||
@@ -176,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)
|
||||
@@ -214,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)
|
||||
@@ -277,7 +277,10 @@ namespace KKdMainLib
|
||||
}
|
||||
else if (!Dict.ContainsKey(args[0])) Dict.Add(args[0], value);
|
||||
}
|
||||
|
||||
|
||||
public static TKey GetKey<TKey, TVal>(this Dictionary<TKey, TVal> Dict, TVal val) =>
|
||||
Dict.First((KeyValuePair<TKey, TVal> x) => x.Value.Equals(val)).Key;
|
||||
|
||||
public static string ToTitleCase(this string s)
|
||||
{ return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s); }
|
||||
|
||||
@@ -294,44 +297,54 @@ namespace KKdMainLib
|
||||
|
||||
private static readonly string NumberDecimalSeparator =
|
||||
NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
|
||||
|
||||
public static string ToString(this bool? d) => d.GetValueOrDefault().ToString();
|
||||
|
||||
public static string ToString(this bool d) => d.ToString().ToLower();
|
||||
|
||||
public static string ToString(this object d)
|
||||
{
|
||||
if (d == null) return "Null";
|
||||
else if (d is float F32) return ToString(F32);
|
||||
else if (d is double F64) return ToString(F64);
|
||||
return d.ToString();
|
||||
}
|
||||
public static string ToString(this bool? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this bool d) => d.ToString().ToLower();
|
||||
public static string ToString(this sbyte? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this sbyte d) => d.ToString();
|
||||
public static string ToString(this byte? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this byte d) => d.ToString();
|
||||
public static string ToString(this short? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this short d) => d.ToString();
|
||||
public static string ToString(this ushort? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this ushort d) => d.ToString();
|
||||
public static string ToString(this int? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this int d) => d.ToString();
|
||||
public static string ToString(this uint? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this uint d) => d.ToString();
|
||||
public static string ToString(this long? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this long d) => d.ToString();
|
||||
public static string ToString(this ulong? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this ulong d) => d.ToString();
|
||||
public static string ToString(this float? d, byte round) => d.GetValueOrDefault().ToString(round);
|
||||
public static string ToString(this float? d) => d.GetValueOrDefault().ToString();
|
||||
|
||||
public static string ToString(this float d, byte round) =>
|
||||
Math.Round(d, round).ToString().ToLower().Replace(NumberDecimalSeparator, ".");
|
||||
|
||||
public static string ToString(this float d) =>
|
||||
d .ToString().ToLower().Replace(NumberDecimalSeparator, ".");
|
||||
|
||||
public static string ToString(this double? d, byte round) => d.GetValueOrDefault().ToString(round);
|
||||
public static string ToString(this double? d) => d.GetValueOrDefault().ToString();
|
||||
|
||||
public static string ToString(this double d, byte round) =>
|
||||
Math.Round(d, round).ToString().ToLower().Replace(NumberDecimalSeparator, ".");
|
||||
|
||||
public static string ToString(this double d) =>
|
||||
d .ToString().ToLower().Replace(NumberDecimalSeparator, ".");
|
||||
|
||||
public static float ToSingle(this string s) =>
|
||||
float. Parse(s.Replace(".", NumberDecimalSeparator));
|
||||
|
||||
public static bool ToSingle(this string s, out float value) =>
|
||||
float.TryParse(s.Replace(".", NumberDecimalSeparator), out value);
|
||||
|
||||
public static double ToDouble(this string s) =>
|
||||
double. Parse(s.Replace(".", NumberDecimalSeparator));
|
||||
|
||||
public static bool ToDouble(this string s, out double value) =>
|
||||
double.TryParse(s.Replace(".", NumberDecimalSeparator), out value);
|
||||
|
||||
public static bool ToSingle(this string s, out float? value)
|
||||
{ bool Val = ToSingle(s, out float val); value = val; return Val; }
|
||||
|
||||
public static bool ToDouble(this string s, out double? value)
|
||||
{ bool Val = ToDouble(s, out double val); value = val; return Val; }
|
||||
|
||||
@@ -350,11 +363,5 @@ namespace KKdMainLib
|
||||
X = 10,
|
||||
XHD = 11,
|
||||
}
|
||||
|
||||
public struct ThreadArgs
|
||||
{
|
||||
public int Thread;
|
||||
public int ID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,11 @@ 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; }
|
||||
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)
|
||||
{ if (Value % 1 >= 0.5) return (long)(Value + 0.5);
|
||||
else return (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;
|
||||
@@ -160,8 +158,8 @@ namespace KKdMainLib
|
||||
else if (c < 0x00000000) c = 0x00000000;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static double Round(this double c) => Math.Round(c);
|
||||
|
||||
public static double Round(this double c, int d = 0) => Math.Round(c, d);
|
||||
|
||||
public static unsafe sbyte* GetPtr(this sbyte[] array)
|
||||
{ sbyte* Ptr; fixed ( sbyte* tempPtr = array) Ptr = tempPtr; return Ptr; }
|
||||
|
||||
+193
-171
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.Types;
|
||||
|
||||
namespace KKdMainLib.MessagePack
|
||||
{
|
||||
@@ -13,269 +13,245 @@ namespace KKdMainLib.MessagePack
|
||||
|
||||
public void Close() => _IO.Close();
|
||||
|
||||
public MsgPack Read(bool NotArray = true)
|
||||
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
|
||||
|
||||
public MsgPack Read(bool Array = false)
|
||||
{
|
||||
MsgPack MsgPack = new MsgPack();
|
||||
MsgPack MsgPack = MsgPack.New;
|
||||
byte Unk = _IO.ReadByte();
|
||||
MsgPack.Type = (MsgPack.Types)Unk;
|
||||
if (NotArray)
|
||||
Types Type = (Types)Unk;
|
||||
if (!Array)
|
||||
{
|
||||
MsgPack.Name = ReadString(MsgPack.Type);
|
||||
if (MsgPack.Name != null) { Unk = _IO.ReadByte(); MsgPack.Type = (MsgPack.Types)Unk; }
|
||||
MsgPack.Name = ReadString(Type);
|
||||
if (MsgPack.Name != null) { Unk = _IO.ReadByte(); Type = (Types)Unk; }
|
||||
}
|
||||
|
||||
bool FixArr = MsgPack.Type >= MsgPack.Types.FixArr && MsgPack.Type <= MsgPack.Types.FixArrMax;
|
||||
bool FixMap = MsgPack.Type >= MsgPack.Types.FixMap && MsgPack.Type <= MsgPack.Types.FixMapMax;
|
||||
bool FixStr = MsgPack.Type >= MsgPack.Types.FixStr && MsgPack.Type <= MsgPack.Types.FixStrMax;
|
||||
bool PosInt = MsgPack.Type >= MsgPack.Types.PosInt && MsgPack.Type <= MsgPack.Types.PosIntMax;
|
||||
bool NegInt = MsgPack.Type >= MsgPack.Types.NegInt && MsgPack.Type <= MsgPack.Types.NegIntMax;
|
||||
bool FixArr = Type >= Types.FixArr && Type <= Types.FixArrMax;
|
||||
bool FixMap = Type >= Types.FixMap && Type <= Types.FixMapMax;
|
||||
bool FixStr = Type >= Types.FixStr && Type <= Types.FixStrMax;
|
||||
bool PosInt = Type >= Types.PosInt && Type <= Types.PosIntMax;
|
||||
bool NegInt = Type >= Types.NegInt && Type <= Types.NegIntMax;
|
||||
if (FixArr || FixMap || FixStr || PosInt || NegInt)
|
||||
{
|
||||
if (FixArr || FixMap)
|
||||
if (FixMap)
|
||||
{
|
||||
MsgPack.Type = FixMap ? MsgPack.Types.FixMap : MsgPack.Types.FixArr;
|
||||
if (FixMap)
|
||||
{
|
||||
MsgPack.Object = new List<object>();
|
||||
for (int i = 0; i < Unk - (byte)MsgPack.Type; i++)
|
||||
MsgPack.Add(Read());
|
||||
}
|
||||
else
|
||||
{
|
||||
MsgPack.Object = new object[Unk - (byte)MsgPack.Type];
|
||||
for (int i = 0; i < Unk - (byte)MsgPack.Type; i++)
|
||||
MsgPack[i] = Read(false);
|
||||
}
|
||||
MsgPack.Object = KKdList<MsgPack>.New;
|
||||
for (int i = 0; i < Unk - (byte)Types.FixMap; i++) MsgPack.Add( Read(false));
|
||||
}
|
||||
else if (FixStr)
|
||||
{ MsgPack.Object = ReadString(MsgPack.Type); MsgPack.Type = MsgPack.Types.FixStr; }
|
||||
else if (PosInt)
|
||||
{ MsgPack.Object = (ulong) Unk; MsgPack.Type = MsgPack.Types.PosInt; }
|
||||
else if (NegInt)
|
||||
{ MsgPack.Object = ( long)(sbyte)Unk; MsgPack.Type = MsgPack.Types.NegInt; }
|
||||
else if (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);
|
||||
else if (PosInt) MsgPack.Object = Unk;
|
||||
else if (NegInt) MsgPack.Object = (sbyte)Unk;
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
bool Boolean = false;
|
||||
while (!Boolean)
|
||||
|
||||
while (true)
|
||||
{
|
||||
Boolean = ReadNil (ref MsgPack);
|
||||
Boolean = ReadArr (ref MsgPack);
|
||||
Boolean = ReadMap (ref MsgPack);
|
||||
Boolean = ReadExt (ref MsgPack);
|
||||
Boolean = ReadString (ref MsgPack);
|
||||
Boolean = ReadBoolean(ref MsgPack);
|
||||
Boolean = ReadBytes (ref MsgPack);
|
||||
Boolean = ReadInt (ref MsgPack);
|
||||
Boolean = ReadUInt (ref MsgPack);
|
||||
Boolean = ReadFloat (ref MsgPack);
|
||||
if (ReadNil (ref MsgPack, ref Type)) break;
|
||||
if (ReadArr (ref MsgPack, ref Type)) break;
|
||||
if (ReadMap (ref MsgPack, ref Type)) break;
|
||||
if (ReadExt (ref MsgPack, ref Type)) break;
|
||||
if (ReadString (ref MsgPack, ref Type)) break;
|
||||
if (ReadBoolean(ref MsgPack, ref Type)) break;
|
||||
if (ReadBytes (ref MsgPack, ref Type)) break;
|
||||
if (ReadInt (ref MsgPack, ref Type)) break;
|
||||
if (ReadUInt (ref MsgPack, ref Type)) break;
|
||||
if (ReadFloat (ref MsgPack, ref Type)) break;
|
||||
break;
|
||||
}
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
private bool ReadInt(ref MsgPack MsgPack)
|
||||
private bool ReadInt (ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.Int8 ) MsgPack.Object = (long)_IO.ReadSByte();
|
||||
else if (MsgPack.Type == MsgPack.Types.Int16) MsgPack.Object = (long)_IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Int32) MsgPack.Object = (long)_IO.ReadInt32Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Int64) MsgPack.Object = (long)_IO.ReadInt64Endian(true);
|
||||
if (Type == Types.Int8 ) MsgPack.Object = _IO.ReadSByte();
|
||||
else if (Type == Types.Int16) MsgPack.Object = _IO.ReadInt16Endian(true);
|
||||
else if (Type == Types.Int32) MsgPack.Object = _IO.ReadInt32Endian(true);
|
||||
else if (Type == Types.Int64) MsgPack.Object = _IO.ReadInt64Endian(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadUInt(ref MsgPack MsgPack)
|
||||
private bool ReadUInt (ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.UInt8 ) MsgPack.Object = (ulong)_IO.ReadByte();
|
||||
else if (MsgPack.Type == MsgPack.Types.UInt16) MsgPack.Object = (ulong)_IO.ReadUInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.UInt32) MsgPack.Object = (ulong)_IO.ReadUInt32Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.UInt64) MsgPack.Object = (ulong)_IO.ReadUInt64Endian(true);
|
||||
if (Type == Types.UInt8 ) MsgPack.Object = _IO.ReadByte();
|
||||
else if (Type == Types.UInt16) MsgPack.Object = _IO.ReadUInt16Endian(true);
|
||||
else if (Type == Types.UInt32) MsgPack.Object = _IO.ReadUInt32Endian(true);
|
||||
else if (Type == Types.UInt64) MsgPack.Object = _IO.ReadUInt64Endian(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadFloat(ref MsgPack MsgPack)
|
||||
private bool ReadFloat (ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.Float32) MsgPack.Object = _IO.ReadSingleEndian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Float64) MsgPack.Object = _IO.ReadDoubleEndian(true);
|
||||
if (Type == Types.Float32) MsgPack.Object = _IO.ReadSingleEndian(true);
|
||||
else if (Type == Types.Float64) MsgPack.Object = _IO.ReadDoubleEndian(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadBoolean(ref MsgPack MsgPack)
|
||||
private bool ReadBoolean(ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.False) MsgPack.Object = false;
|
||||
else if (MsgPack.Type == MsgPack.Types.True ) MsgPack.Object = true ;
|
||||
if (Type == Types.False) MsgPack.Object = false;
|
||||
else if (Type == Types.True ) MsgPack.Object = true ;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadBytes(ref MsgPack MsgPack)
|
||||
private bool ReadBytes (ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.Bin8 ) Length = _IO.ReadByte();
|
||||
else if (MsgPack.Type == MsgPack.Types.Bin16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Bin32) Length = _IO.ReadInt32Endian(true);
|
||||
if (Type == Types.Bin8 ) Length = _IO.ReadByte();
|
||||
else if (Type == Types.Bin16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (Type == Types.Bin32) Length = _IO.ReadInt32Endian(true);
|
||||
else return false;
|
||||
MsgPack.Object = _IO.ReadBytes(Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadString(ref MsgPack MsgPack)
|
||||
private bool ReadString (ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
string val = ReadString(MsgPack.Type);
|
||||
string val = ReadString(Type);
|
||||
if (val != null) MsgPack.Object = val;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private string ReadString(MsgPack.Types Val)
|
||||
private string ReadString(Types Val)
|
||||
{
|
||||
if (Val >= MsgPack.Types.FixStr && Val <= MsgPack.Types.FixStrMax)
|
||||
return _IO.ReadString(Val - MsgPack.Types.FixStr);
|
||||
else if (Val >= MsgPack.Types.Str8 && Val <= MsgPack.Types.Str32)
|
||||
if (Val >= Types.FixStr && Val <= Types.FixStrMax)
|
||||
return _IO.ReadString(Val - Types.FixStr);
|
||||
else if (Val >= Types. Str8 && Val <= Types. Str32 )
|
||||
{
|
||||
Enum.TryParse(Val.ToString(), out MsgPack.Types Type);
|
||||
Enum.TryParse(Val.ToString(), out Types Type);
|
||||
int Length = 0;
|
||||
if (Type == MsgPack.Types.Str8 ) Length = _IO.ReadByte();
|
||||
else if (Type == MsgPack.Types.Str16) Length = _IO.ReadInt16Endian(true);
|
||||
else Length = _IO.ReadInt32Endian(true);
|
||||
if (Type == Types.Str8 ) Length = _IO.ReadByte();
|
||||
else if (Type == Types.Str16) Length = _IO.ReadInt16Endian(true);
|
||||
else Length = _IO.ReadInt32Endian(true);
|
||||
return _IO.ReadString(Length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool ReadNil(ref MsgPack MsgPack)
|
||||
private bool ReadNil(ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.Nil)
|
||||
MsgPack.Object = null;
|
||||
if (Type == Types.Nil) MsgPack.Object = null;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadArr(ref MsgPack MsgPack)
|
||||
private bool ReadArr(ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.Arr16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Arr32) Length = _IO.ReadInt32Endian(true);
|
||||
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];
|
||||
for (int i = 0; i < Length; i++) MsgPack[i] = Read(false);
|
||||
MsgPack.Object = new MsgPack[Length];
|
||||
for (int i = 0; i < Length; i++) MsgPack[i] = Read(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadMap(ref MsgPack MsgPack)
|
||||
private bool ReadMap(ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.Map16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Map32) Length = _IO.ReadInt32Endian(true);
|
||||
if (Type == Types.Map16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (Type == Types.Map32) Length = _IO.ReadInt32Endian(true);
|
||||
else return false;
|
||||
MsgPack.Object = new List<object>();
|
||||
MsgPack.Object = KKdList<MsgPack>.New;
|
||||
for (int i = 0; i < Length; i++) MsgPack.Add(Read());
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadExt(ref MsgPack MsgPack)
|
||||
private bool ReadExt(ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.FixExt1 ) Length = 1 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt2 ) Length = 2 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt4 ) Length = 4 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt8 ) Length = 8 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt16) Length = 16;
|
||||
else if (MsgPack.Type == MsgPack.Types. Ext8 ) Length = _IO.ReadByte();
|
||||
else if (MsgPack.Type == MsgPack.Types. Ext16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types. Ext32) Length = _IO.ReadInt32Endian(true);
|
||||
if (Type == Types.FixExt1 ) Length = 1 ;
|
||||
else if (Type == Types.FixExt2 ) Length = 2 ;
|
||||
else if (Type == Types.FixExt4 ) Length = 4 ;
|
||||
else if (Type == Types.FixExt8 ) Length = 8 ;
|
||||
else if (Type == Types.FixExt16) Length = 16;
|
||||
else if (Type == Types. Ext8 ) Length = _IO.ReadByte();
|
||||
else if (Type == Types. Ext16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (Type == Types. Ext32) Length = _IO.ReadInt32Endian(true);
|
||||
else return false;
|
||||
MsgPack.Object = new MsgPack.Ext { Type = _IO.ReadSByte(), Data = _IO.ReadBytes(Length) };
|
||||
return true;
|
||||
}
|
||||
|
||||
public IO Write(MsgPack MsgPack, bool Close = false)
|
||||
{ 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.Object == null) { WriteNil(); return this; }
|
||||
|
||||
if (MsgPack.Object.GetType() == typeof(List<object>))
|
||||
{
|
||||
List<object> Obj = (List<object>)MsgPack.Object;
|
||||
WriteMap(Obj.Count);
|
||||
foreach (object obj in Obj) Write(obj);
|
||||
}
|
||||
else if (MsgPack.Object.GetType() == typeof(object[]))
|
||||
{
|
||||
object[] Obj = (object[])MsgPack.Object;
|
||||
WriteArr(Obj.Length);
|
||||
foreach (object obj in Obj) Write(obj);
|
||||
}
|
||||
else Write(MsgPack.Object);
|
||||
|
||||
if (MsgPack.Name != null && !IsArray) Write(MsgPack.Name);
|
||||
Write(MsgPack.Object);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void Write(object obj)
|
||||
{
|
||||
if (obj == null ) WriteNil ();
|
||||
else if (obj.GetType() == typeof(MsgPack)) Write((MsgPack)obj);
|
||||
else
|
||||
if (obj == null) { WriteNil(); return; }
|
||||
switch (obj)
|
||||
{
|
||||
Type type = obj.GetType();
|
||||
if (type == typeof(byte[])) Write((byte[])obj);
|
||||
else if (type == typeof( bool)) Write(( bool)obj);
|
||||
else if (type == typeof( sbyte)) Write(( sbyte)obj);
|
||||
else if (type == typeof( byte)) Write(( byte)obj);
|
||||
else if (type == typeof( short)) Write(( short)obj);
|
||||
else if (type == typeof(ushort)) Write((ushort)obj);
|
||||
else if (type == typeof( int)) Write(( int)obj);
|
||||
else if (type == typeof( uint)) Write(( uint)obj);
|
||||
else if (type == typeof( long)) Write(( long)obj);
|
||||
else if (type == typeof( ulong)) Write(( ulong)obj);
|
||||
else if (type == typeof( float)) Write(( float)obj);
|
||||
else if (type == typeof(double)) Write((double)obj);
|
||||
else if (type == typeof(string)) Write((string)obj);
|
||||
else if (type == typeof(MsgPack.Ext)) Write((MsgPack.Ext)obj);
|
||||
case KKdList<MsgPack> val: WriteMap(val.Count );
|
||||
for (int i = 0; i < val.Count ; i++) Write(val[i]); break;
|
||||
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;
|
||||
case bool val: Write(val); break;
|
||||
case sbyte val: Write(val); break;
|
||||
case byte val: Write(val); break;
|
||||
case short val: Write(val); break;
|
||||
case ushort val: Write(val); break;
|
||||
case int val: Write(val); break;
|
||||
case uint val: Write(val); break;
|
||||
case long val: Write(val); break;
|
||||
case ulong val: Write(val); break;
|
||||
case float val: Write(val); break;
|
||||
case double val: Write(val); break;
|
||||
case string val: Write(val); break;
|
||||
case MsgPack.Ext val: Write(val); break;
|
||||
}
|
||||
}
|
||||
|
||||
private void Write( sbyte val) { if (val < -0x20) _IO.Write((byte)0xD0); _IO.Write(val); }
|
||||
private void Write( byte val) { if (val >= 0x80) _IO.Write((byte)0xCC); _IO.Write(val); }
|
||||
private void Write( sbyte val) { if (val < -0x20) _IO.WriteByte(0xD0); _IO.Write(val); }
|
||||
private void Write( byte val) { if (val >= 0x80) _IO.WriteByte(0xCC); _IO.Write(val); }
|
||||
private void Write( short val) { if (( sbyte)val == val) Write(( sbyte)val);
|
||||
else if (( byte)val == val) Write(( byte)val);
|
||||
else { _IO.Write((byte)0xD1); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xD1); _IO.WriteEndian(val, true); } }
|
||||
private void Write(ushort val) { if (( byte)val == val) Write(( byte)val);
|
||||
else { _IO.Write((byte)0xCD); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xCD); _IO.WriteEndian(val, true); } }
|
||||
private void Write( int val) { if (( short)val == val) Write(( short)val);
|
||||
else if ((ushort)val == val) Write((ushort)val);
|
||||
else { _IO.Write((byte)0xD2); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xD2); _IO.WriteEndian(val, true); } }
|
||||
private void Write( uint val) { if ((ushort)val == val) Write((ushort)val);
|
||||
else { _IO.Write((byte)0xCE); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xCE); _IO.WriteEndian(val, true); } }
|
||||
private void Write( long val) { if (( int)val == val) Write(( int)val);
|
||||
else if (( uint)val == val) Write(( uint)val);
|
||||
else { _IO.Write((byte)0xD3); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xD3); _IO.WriteEndian(val, true); } }
|
||||
private void Write( ulong val) { if (( uint)val == val) Write(( uint)val);
|
||||
else { _IO.Write((byte)0xCF); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xCF); _IO.WriteEndian(val, true); } }
|
||||
private void Write( float val) { if (( long)val == val) Write(( long)val);
|
||||
else { _IO.Write((byte)0xCA); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xCA); _IO.WriteEndian(val, true); } }
|
||||
private void Write(double val) { if (( long)val == val) Write(( long)val);
|
||||
else if (( float)val == val) Write(( float)val);
|
||||
else { _IO.Write((byte)0xCB); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xCB); _IO.WriteEndian(val, true); } }
|
||||
|
||||
private void Write( bool val)
|
||||
{ _IO.Write((byte)(val ? 0xC3 : 0xC2)); }
|
||||
private void Write( bool val) =>
|
||||
_IO.WriteByte((byte)(val ? 0xC3 : 0xC2));
|
||||
|
||||
private void Write(byte[] val)
|
||||
{
|
||||
if (val == null) { WriteNil(); return; }
|
||||
|
||||
if (val.Length < 0x100)
|
||||
{ _IO.Write((byte)0xC4); _IO.Write (( byte)val.Length ); }
|
||||
{ _IO.WriteByte(0xC4); _IO.WriteByte (( byte)val.Length ); }
|
||||
else if (val.Length < 0x10000)
|
||||
{ _IO.Write((byte)0xC5); _IO.WriteEndian((ushort)val.Length, true); }
|
||||
{ _IO.WriteByte(0xC5); _IO.WriteEndian((ushort)val.Length, true); }
|
||||
else
|
||||
{ _IO.Write((byte)0xC6); _IO.WriteEndian( val.Length, true); }
|
||||
{ _IO.WriteByte(0xC6); _IO.WriteEndian( val.Length, true); }
|
||||
_IO.Write(val);
|
||||
}
|
||||
|
||||
@@ -285,55 +261,101 @@ namespace KKdMainLib.MessagePack
|
||||
|
||||
byte[] array = Text.ToUTF8(val);
|
||||
if (array.Length < 0x20)
|
||||
_IO.Write((byte)(0xA0 | (array.Length & 0x1F)));
|
||||
_IO.WriteByte((byte)(0xA0 | (array.Length & 0x1F)));
|
||||
else if (array.Length < 0x100)
|
||||
{ _IO.Write((byte) 0xD9); _IO.Write (( byte)array.Length); }
|
||||
{ _IO.WriteByte(0xD9); _IO.WriteByte (( byte)array.Length); }
|
||||
else if (array.Length < 0x10000)
|
||||
{ _IO.Write((byte )0xDA); _IO.WriteEndian((ushort)array.Length, true); }
|
||||
{ _IO.WriteByte(0xDA); _IO.WriteEndian((ushort)array.Length, true); }
|
||||
else
|
||||
{ _IO.Write((byte) 0xDB); _IO.WriteEndian( array.Length, true); }
|
||||
{ _IO.WriteByte(0xDB); _IO.WriteEndian( array.Length, true); }
|
||||
_IO.Write(array);
|
||||
}
|
||||
|
||||
private void WriteNil() => _IO.Write((byte)0xC0);
|
||||
private void WriteNil() => _IO.WriteByte(0xC0);
|
||||
|
||||
private void WriteArr(int val)
|
||||
{
|
||||
if (val == 0) { WriteNil(); return; }
|
||||
else if (val < 0x10) _IO.Write((byte)(0x90 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.Write((byte) 0xDC); _IO.WriteEndian((ushort)val, true); }
|
||||
else { _IO.Write((byte) 0xDD); _IO.WriteEndian( val, true); }
|
||||
else if (val < 0x10) _IO.WriteByte((byte)(0x90 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.WriteByte(0xDC); _IO.WriteEndian((ushort)val, true); }
|
||||
else { _IO.WriteByte(0xDD); _IO.WriteEndian( val, true); }
|
||||
}
|
||||
|
||||
private void WriteMap(int val)
|
||||
{
|
||||
if (val == 0) { WriteNil(); return; }
|
||||
else if (val < 0x10) _IO.Write((byte)(0x80 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.Write((byte) 0xDE); _IO.WriteEndian((ushort)val, true); }
|
||||
else { _IO.Write((byte) 0xDF); _IO.WriteEndian( val, true); }
|
||||
else if (val < 0x10) _IO.WriteByte((byte)(0x80 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.WriteByte(0xDE); _IO.WriteEndian((ushort)val, true); }
|
||||
else { _IO.WriteByte(0xDF); _IO.WriteEndian( val, true); }
|
||||
}
|
||||
|
||||
private void WriteExt(MsgPack.Ext val)
|
||||
private void Write(MsgPack.Ext val)
|
||||
{
|
||||
if (val.Data == null) { WriteNil(); return; }
|
||||
|
||||
if (val.Data.Length < 1 ) { WriteNil(); return; }
|
||||
else if (val.Data.Length == 1 ) _IO.Write((byte)0xD4);
|
||||
else if (val.Data.Length == 2 ) _IO.Write((byte)0xD5);
|
||||
else if (val.Data.Length == 4 ) _IO.Write((byte)0xD6);
|
||||
else if (val.Data.Length == 8 ) _IO.Write((byte)0xD7);
|
||||
else if (val.Data.Length == 16) _IO.Write((byte)0xD8);
|
||||
else if (val.Data.Length == 1 ) _IO.WriteByte(0xD4);
|
||||
else if (val.Data.Length == 2 ) _IO.WriteByte(0xD5);
|
||||
else if (val.Data.Length == 4 ) _IO.WriteByte(0xD6);
|
||||
else if (val.Data.Length == 8 ) _IO.WriteByte(0xD7);
|
||||
else if (val.Data.Length == 16) _IO.WriteByte(0xD8);
|
||||
else
|
||||
{
|
||||
if (val.Data.Length < 0x100)
|
||||
{ _IO.Write((byte)0xC7); _IO.Write (( byte)val.Data.Length); }
|
||||
{ _IO.WriteByte(0xC7); _IO.WriteByte (( byte)val.Data.Length); }
|
||||
else if (val.Data.Length < 0x10000)
|
||||
{ _IO.Write((byte)0xC8); _IO.WriteEndian((ushort)val.Data.Length, true); }
|
||||
{ _IO.WriteByte(0xC8); _IO.WriteEndian((ushort)val.Data.Length, true); }
|
||||
else
|
||||
{ _IO.Write((byte)0xC9); _IO.WriteEndian( val.Data.Length, true); }
|
||||
{ _IO.WriteByte(0xC9); _IO.WriteEndian( val.Data.Length, true); }
|
||||
}
|
||||
_IO.Write(val.Type);
|
||||
_IO.Write(val.Data);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Types : byte
|
||||
{
|
||||
PosInt = 0b00000000,
|
||||
FixMap = 0b10000000,
|
||||
FixArr = 0b10010000,
|
||||
FixStr = 0b10100000,
|
||||
Nil = 0b11000000,
|
||||
NeverUsed = 0b11000001,
|
||||
False = 0b11000010,
|
||||
True = 0b11000011,
|
||||
Bin8 = 0b11000100,
|
||||
Bin16 = 0b11000101,
|
||||
Bin32 = 0b11000110,
|
||||
Ext8 = 0b11000111,
|
||||
Ext16 = 0b11001000,
|
||||
Ext32 = 0b11001001,
|
||||
Float32 = 0b11001010,
|
||||
Float64 = 0b11001011,
|
||||
UInt8 = 0b11001100,
|
||||
UInt16 = 0b11001101,
|
||||
UInt32 = 0b11001110,
|
||||
UInt64 = 0b11001111,
|
||||
Int8 = 0b11010000,
|
||||
Int16 = 0b11010001,
|
||||
Int32 = 0b11010010,
|
||||
Int64 = 0b11010011,
|
||||
FixExt1 = 0b11010100,
|
||||
FixExt2 = 0b11010101,
|
||||
FixExt4 = 0b11010110,
|
||||
FixExt8 = 0b11010111,
|
||||
FixExt16 = 0b11011000,
|
||||
Str8 = 0b11011001,
|
||||
Str16 = 0b11011010,
|
||||
Str32 = 0b11011011,
|
||||
Arr16 = 0b11011100,
|
||||
Arr32 = 0b11011101,
|
||||
Map16 = 0b11011110,
|
||||
Map32 = 0b11011111,
|
||||
NegInt = 0b11100000,
|
||||
PosIntMax = 0b01111111,
|
||||
FixMapMax = 0b10001111,
|
||||
FixArrMax = 0b10011111,
|
||||
FixStrMax = 0b10111111,
|
||||
NegIntMax = 0b11111111,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
//Original or reader part: https://github.com/MarcosLopezC/LightJson/
|
||||
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.Types;
|
||||
|
||||
namespace KKdMainLib.MessagePack
|
||||
{
|
||||
public class JSONIO
|
||||
{
|
||||
public Stream _IO;
|
||||
|
||||
public JSONIO( ) => _IO = File.OpenWriter();
|
||||
public JSONIO(Stream IO) => _IO = IO;
|
||||
|
||||
public void Close() => _IO.Close();
|
||||
|
||||
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
|
||||
|
||||
public MsgPack Read() => ReadValue();
|
||||
|
||||
private MsgPack ReadValue(string Key = null)
|
||||
{
|
||||
char c = _IO.SkipWhitespace().PeekCharUTF8();
|
||||
object obj = null;
|
||||
if (char.IsDigit(c))
|
||||
obj = ReadNumber ();
|
||||
else
|
||||
switch (c)
|
||||
{
|
||||
case '"': obj = ReadString (); break;
|
||||
case '{': obj = ReadObject (); break;
|
||||
case '[': obj = ReadArray (); break;
|
||||
case '-': obj = ReadNumber (); break;
|
||||
case 't':
|
||||
case 'f': obj = ReadBoolean(); break;
|
||||
case 'n': obj = ReadNull (); break;
|
||||
}
|
||||
return new MsgPack(Key, obj);
|
||||
}
|
||||
|
||||
private string ReadString()
|
||||
{
|
||||
if (!_IO.Assert('"')) return null;
|
||||
char c;
|
||||
string s = "";
|
||||
while (true)
|
||||
{
|
||||
c = _IO.ReadCharUTF8();
|
||||
|
||||
if (c == '\\')
|
||||
{
|
||||
c = _IO.ReadCharUTF8();
|
||||
|
||||
switch (char.ToLower(c))
|
||||
{
|
||||
case '"' :
|
||||
case '\\':
|
||||
case '/' : s += c; break;
|
||||
case 'b' : s += '\b'; break;
|
||||
case 'f' : s += '\f'; break;
|
||||
case 'n' : s += '\n'; break;
|
||||
case 'r' : s += '\r'; break;
|
||||
case 't' : s += '\t'; break;
|
||||
case 'u' : s += ReadUnicodeLiteral(); break;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
else if (c == '"') break;
|
||||
else if (char.IsControl(c)) return null;
|
||||
else s += c;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private char ReadUnicodeLiteral() =>
|
||||
(char)((((((ReadHexDigit() << 4) | ReadHexDigit()) << 4) | ReadHexDigit()) << 4) | ReadHexDigit());
|
||||
|
||||
private int ReadHexDigit() => byte.Parse(_IO.ReadCharUTF8().ToString(),
|
||||
System.Globalization.NumberStyles.HexNumber);
|
||||
|
||||
private KKdList<MsgPack> ReadObject()
|
||||
{
|
||||
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;
|
||||
while (true)
|
||||
{
|
||||
_IO.SkipWhitespace();
|
||||
|
||||
key = ReadString();
|
||||
if (!_IO.SkipWhitespace().Assert(':'))
|
||||
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<MsgPack>.Null;
|
||||
}
|
||||
|
||||
return Obj;
|
||||
}
|
||||
|
||||
private MsgPack[] ReadArray()
|
||||
{
|
||||
KKdList<MsgPack> Obj = KKdList<MsgPack>.New;
|
||||
if (!_IO.Assert('[')) return null;
|
||||
if (_IO.SkipWhitespace().PeekCharUTF8() == ']') { _IO.ReadCharUTF8(); return null; }
|
||||
|
||||
char c;
|
||||
while (true)
|
||||
{
|
||||
Obj.Add(ReadValue(null));
|
||||
c = _IO.SkipWhitespace().PeekCharUTF8();
|
||||
|
||||
if (c == ']') { _IO.ReadCharUTF8(); break; }
|
||||
else if (c == ',') { _IO.ReadCharUTF8(); continue; }
|
||||
else return null;
|
||||
}
|
||||
return Obj.ToArray();
|
||||
}
|
||||
|
||||
private object ReadNumber()
|
||||
{
|
||||
string s = " ";
|
||||
_IO.SkipWhitespace();
|
||||
if (_IO.PeekCharUTF8() == '-') s += _IO.ReadCharUTF8();
|
||||
if (_IO.PeekCharUTF8() == '0') s += _IO.ReadCharUTF8();
|
||||
else s += ReadDigits ();
|
||||
if (_IO.PeekCharUTF8() == '.') s += _IO.ReadCharUTF8() + ReadDigits();
|
||||
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;
|
||||
}
|
||||
|
||||
char c = _IO.PeekCharUTF8();
|
||||
if (c == 'e' || c == 'E')
|
||||
{
|
||||
s += _IO.ReadCharUTF8();
|
||||
c = _IO.PeekCharUTF8();
|
||||
if (c == '+' || c == '-') s += _IO.ReadCharUTF8();
|
||||
s += ReadDigits();
|
||||
}
|
||||
double d = s.ToDouble();
|
||||
return (float)d == d ? (float)d : d;
|
||||
}
|
||||
|
||||
private bool ReadBoolean()
|
||||
{
|
||||
char c = _IO.PeekCharUTF8();
|
||||
if (c == 't' && _IO.Assert( "true")) return true;
|
||||
else if (c == 'f' && _IO.Assert("false")) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
private object ReadNull() { _IO.Assert("null"); return null; }
|
||||
|
||||
private string ReadDigits()
|
||||
{ string s = ""; while (char.IsDigit(_IO.SkipWhitespace().
|
||||
PeekCharUTF8())) s += _IO.ReadCharUTF8(); return s; }
|
||||
|
||||
public JSONIO Write(MsgPack MsgPack, string End = "\n", string TabChar = " ")
|
||||
{ Write(MsgPack, End, TabChar, "", true); 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, bool IsArray = false)
|
||||
{
|
||||
string OldTab = Tab;
|
||||
Tab += TabChar;
|
||||
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);
|
||||
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[0], End, TabChar, Tab, Style);
|
||||
if (Style) _IO.Write(End);
|
||||
}
|
||||
if (Style) _IO.Write(OldTab);
|
||||
WriteMap(true);
|
||||
}
|
||||
else if (MsgPack.Array != null)
|
||||
{
|
||||
WriteArr();
|
||||
if (Style) _IO.Write(End);
|
||||
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[0], End, TabChar, Tab, Style, true);
|
||||
if (Style) _IO.Write(End);
|
||||
}
|
||||
if (Style) _IO.Write(OldTab);
|
||||
WriteArr(true);
|
||||
}
|
||||
else if (MsgPack.Object is MsgPack msg)
|
||||
Write(msg, End, TabChar, Tab, Style);
|
||||
else Write(MsgPack.Object, End, TabChar, Tab, Style);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private void Write(object obj, string End, string TabChar, string Tab, bool Style)
|
||||
{
|
||||
if (obj == null) { WriteNil(); return; }
|
||||
switch (obj)
|
||||
{
|
||||
case MsgPack val: Write(val, End, TabChar, Tab, Style); break;
|
||||
case bool val: Write(val); break;
|
||||
case string val: Write(val); break;
|
||||
case sbyte val: _IO.Write(Main.ToString(val)); break;
|
||||
case byte val: _IO.Write(Main.ToString(val)); break;
|
||||
case short val: _IO.Write(Main.ToString(val)); break;
|
||||
case ushort val: _IO.Write(Main.ToString(val)); break;
|
||||
case int val: _IO.Write(Main.ToString(val)); break;
|
||||
case uint val: _IO.Write(Main.ToString(val)); break;
|
||||
case long val: _IO.Write(Main.ToString(val)); break;
|
||||
case ulong val: _IO.Write(Main.ToString(val)); break;
|
||||
case float val: _IO.Write(Main.ToString(val)); break;
|
||||
case double val: _IO.Write(Main.ToString(val)); break;
|
||||
}
|
||||
}
|
||||
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("\n", "\\n" ).Replace("\r", "\\r").Replace("\t", "\\t" ) + "\"");
|
||||
|
||||
private void WriteNil() => _IO.Write("null");
|
||||
private void WriteArr(bool End = false) => _IO.Write(End ? "]" : "[");
|
||||
private void WriteMap(bool End = false) => _IO.Write(End ? "}" : "{");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using KKdMainLib.IO;
|
||||
using MPIO = KKdMainLib.MessagePack.IO;
|
||||
|
||||
namespace KKdMainLib.MessagePack
|
||||
{
|
||||
public static class MPExt
|
||||
{
|
||||
public static MsgPack ReadMPAllAtOnce(this string file, bool JSON = false)
|
||||
{
|
||||
MsgPack MsgPack;
|
||||
if (JSON)
|
||||
{ JSONIO IO = new JSONIO(File.OpenReader(file + ".json", true));
|
||||
MsgPack = IO.Read(); IO.Close(); IO = null; }
|
||||
else
|
||||
{ MPIO IO = new MPIO(File.OpenReader(file + ".mp" , true));
|
||||
MsgPack = IO.Read(); IO.Close(); IO = null; }
|
||||
return MsgPack;
|
||||
}
|
||||
public static MsgPack ReadMP(this string file, bool JSON = false)
|
||||
{
|
||||
MsgPack MsgPack;
|
||||
if (JSON)
|
||||
{ JSONIO IO = new JSONIO(File.OpenReader(file + ".json"));
|
||||
MsgPack = IO.Read(); IO.Close(); IO = null; }
|
||||
else
|
||||
{ MPIO IO = new MPIO(File.OpenReader(file + ".mp" ));
|
||||
MsgPack = IO.Read(); IO.Close(); IO = null; }
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
public static void Write(this MsgPack mp, bool Temp, string file, bool JSON = false)
|
||||
{ if (Temp) MsgPack.New.Add(mp).Write(file, JSON).Dispose();
|
||||
else mp .Write(file, JSON); }
|
||||
|
||||
public static MsgPack Write(this MsgPack mp, string file, bool JSON = false)
|
||||
{
|
||||
if (JSON)
|
||||
{ JSONIO IO = new JSONIO(File.OpenWriter(file + ".json", true));
|
||||
IO.Write(mp, "\n", " ").Close(); IO = null; }
|
||||
else
|
||||
{ MPIO IO = new MPIO(File.OpenWriter(file + ".mp" , true));
|
||||
IO.Write(mp ).Close(); IO = null; }
|
||||
return mp;
|
||||
}
|
||||
|
||||
public static void WriteAfterAll(this MsgPack mp, bool Temp, string file, bool JSON = false)
|
||||
{ if (Temp) MsgPack.New.Add(mp).WriteAfterAll(file, JSON).Dispose();
|
||||
else mp .WriteAfterAll(file, JSON); }
|
||||
|
||||
public static MsgPack WriteAfterAll(this MsgPack mp, string file, bool JSON = false)
|
||||
{
|
||||
byte[] data = null;
|
||||
if (JSON)
|
||||
{ JSONIO IO = new JSONIO(File.OpenWriter());
|
||||
IO.Write(mp, true); data = IO.ToArray(true); }
|
||||
else
|
||||
{ MPIO IO = new MPIO(File.OpenWriter());
|
||||
IO.Write(mp ); data = IO.ToArray(true); }
|
||||
File.WriteAllBytes(file + (JSON ? ".json" : ".mp"), data);
|
||||
return mp;
|
||||
}
|
||||
|
||||
public static void ToJSON (this string file) =>
|
||||
file.ReadMP( ).Write(file, true).Dispose();
|
||||
|
||||
public static void ToMsgPack(this string file) =>
|
||||
file.ReadMP(true).Write(file ).Dispose();
|
||||
}
|
||||
}
|
||||
+192
-222
@@ -1,105 +1,112 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.Types;
|
||||
|
||||
namespace KKdMainLib.MessagePack
|
||||
{
|
||||
public class MsgPack
|
||||
public struct MsgPack : IDisposable, IEquatable<MsgPack>
|
||||
{
|
||||
public Types Type;
|
||||
public string Name;
|
||||
public object Object;
|
||||
|
||||
public MsgPack( Types Type = Types.Map32) => NewMsgPack(null, Type);
|
||||
public MsgPack(string Name, Types Type = Types.Map32) => NewMsgPack(Name, Type);
|
||||
public MsgPack( long Count) => NewMsgPack(null, Count);
|
||||
public MsgPack(string Name, long Count) => NewMsgPack(Name, Count);
|
||||
public MsgPack(string Name, Types Type, object Object) { this.Name = Name; this.Type = Type; this.Object = Object; }
|
||||
public MsgPack[] Array => Object is MsgPack[] List ? List : null;
|
||||
public KKdList<MsgPack> List => Object is KKdList<MsgPack> List ? List : default;
|
||||
|
||||
public static MsgPack Null => null;
|
||||
public static MsgPack New => new MsgPack { Object = KKdList<MsgPack>.New };
|
||||
public static MsgPack NewReserve(int Capacity) =>
|
||||
new MsgPack { Object = KKdList<MsgPack>.NewReserve(Capacity) };
|
||||
|
||||
public object this[int index]
|
||||
{ get { return ((object[])Object)[index]; }
|
||||
set { object[] Data = (object[])Object; Data[index] = value; Object = Data; } }
|
||||
public MsgPack( string Name = null)
|
||||
{ Object = KKdList<MsgPack>.New; this.Name = Name; }
|
||||
|
||||
public MsgPack(List<object> Object, string Name, Types Type)
|
||||
{ this.Object = Object; this.Name = Name; this.Type = Type; }
|
||||
public MsgPack(long Count, string Name = null)
|
||||
{ Object = Count > 0 ? new MsgPack[Count] : null; this.Name = Name; }
|
||||
|
||||
private void NewMsgPack(string Name, Types Type)
|
||||
{ Object = new List<object>(); this.Name = Name; this.Type = Type; }
|
||||
public MsgPack(string Name, object Object)
|
||||
{ this.Name = Name; this.Object = Object; }
|
||||
|
||||
private void NewMsgPack(string Name, long Count)
|
||||
{ if (Count > 0) Object = new object[Count]; else Object = null; this.Name = Name; Type = Types.Arr32; }
|
||||
public static MsgPack Null => new MsgPack();
|
||||
|
||||
|
||||
public MsgPack Add(object obj)
|
||||
{ if (obj != null) if (typeof(List<object>) == Object.GetType())
|
||||
{ List<object> Obj = (List<object>)Object; Obj.Add(obj); Object = Obj; } return this; }
|
||||
|
||||
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 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(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(MsgPack obj)
|
||||
{ if (Object is KKdList<MsgPack> List) { List.Add(obj); Object = List; } return this; }
|
||||
|
||||
public MsgPack Add(string Val, sbyte? val) { if (val == null) Add(Null); else Add(Val, ( sbyte)val); return this; }
|
||||
public MsgPack Add(string Val, byte? val) { if (val == null) Add(Null); else Add(Val, ( byte)val); return this; }
|
||||
public MsgPack Add(string Val, short? val) { if (val == null) Add(Null); else Add(Val, ( short)val); return this; }
|
||||
public MsgPack Add(string Val, ushort? val) { if (val == null) Add(Null); else Add(Val, (ushort)val); return this; }
|
||||
public MsgPack Add(string Val, int? val) { if (val == null) Add(Null); else Add(Val, ( int)val); return this; }
|
||||
public MsgPack Add(string Val, uint? val) { if (val == null) Add(Null); else Add(Val, ( uint)val); return this; }
|
||||
public MsgPack Add(string Val, long? val) { if (val == null) Add(Null); else Add(Val, ( long)val); return this; }
|
||||
public MsgPack Add(string Val, ulong? val) { if (val == null) Add(Null); else Add(Val, ( ulong)val); return this; }
|
||||
public MsgPack Add(string Val, float? val) { if (val == null) Add(Null); else Add(Val, ( float)val); return this; }
|
||||
public MsgPack Add(string Val, double? val) { if (val == null) Add(Null); else Add(Val, (double)val); return this; }
|
||||
public void Dispose()
|
||||
{ Name = null; Object = null; }
|
||||
|
||||
public MsgPack Add(string Val, byte[] val)
|
||||
{ if (val == null) Add(Null); else
|
||||
Add(new MsgPack(Val, Types. Bin32, val)); return this; }
|
||||
public MsgPack Add(string Val, string val)
|
||||
{ if (val == null) Add(Null); else
|
||||
Add(new MsgPack(Val, Types. Str32, val)); return this; }
|
||||
public MsgPack Add(string Val, bool val)
|
||||
{ Add(new MsgPack(Val, val ?
|
||||
Types.True : Types. False, val)); return this; }
|
||||
public MsgPack Add(string Val, sbyte val)
|
||||
{ Add(new MsgPack(Val, Types. Int8, val)); return this; }
|
||||
public MsgPack Add(string Val, byte val)
|
||||
{ Add(new MsgPack(Val, Types. UInt8, val)); return this; }
|
||||
public MsgPack Add(string Val, short val)
|
||||
{ Add(new MsgPack(Val, Types. Int16, val)); return this; }
|
||||
public MsgPack Add(string Val, ushort val)
|
||||
{ Add(new MsgPack(Val, Types. UInt16, val)); return this; }
|
||||
public MsgPack Add(string Val, int val)
|
||||
{ Add(new MsgPack(Val, Types. Int32, val)); return this; }
|
||||
public MsgPack Add(string Val, uint val)
|
||||
{ Add(new MsgPack(Val, Types. UInt32, val)); return this; }
|
||||
public MsgPack Add(string Val, long val)
|
||||
{ Add(new MsgPack(Val, Types. Int64, val)); return this; }
|
||||
public MsgPack Add(string Val, ulong val)
|
||||
{ Add(new MsgPack(Val, Types. UInt64, val)); return this; }
|
||||
public MsgPack Add(string Val, float val)
|
||||
{ Add(new MsgPack(Val, Types.Float32, val)); return this; }
|
||||
public MsgPack Add(string Val, double val)
|
||||
{ Add(new MsgPack(Val, Types.Float64, val)); return this; }
|
||||
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 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 != null ? Add(new MsgPack(null, ( sbyte)val)) : this;
|
||||
public MsgPack Add( byte? val) => val != null ? Add(new MsgPack(null, ( byte)val)) : this;
|
||||
public MsgPack Add( short? val) => val != null ? Add(new MsgPack(null, ( short)val)) : this;
|
||||
public MsgPack Add(ushort? val) => val != null ? Add(new MsgPack(null, (ushort)val)) : this;
|
||||
public MsgPack Add( int? val) => val != null ? Add(new MsgPack(null, ( int)val)) : this;
|
||||
public MsgPack Add( uint? val) => val != null ? Add(new MsgPack(null, ( uint)val)) : this;
|
||||
public MsgPack Add( long? val) => val != null ? Add(new MsgPack(null, ( long)val)) : this;
|
||||
public MsgPack Add( ulong? val) => val != null ? Add(new MsgPack(null, ( ulong)val)) : this;
|
||||
public MsgPack Add( float? val) => val != null ? Add(new MsgPack(null, ( float)val)) : this;
|
||||
public MsgPack Add(double? val) => val != null ? Add(new MsgPack(null, (double)val)) : 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(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 MsgPack Add(string Val, sbyte? val) => val != null ? Add(Val, ( sbyte)val) : this;
|
||||
public MsgPack Add(string Val, byte? val) => val != null ? Add(Val, ( byte)val) : this;
|
||||
public MsgPack Add(string Val, short? val) => val != null ? Add(Val, ( short)val) : this;
|
||||
public MsgPack Add(string Val, ushort? val) => val != null ? Add(Val, (ushort)val) : this;
|
||||
public MsgPack Add(string Val, int? val) => val != null ? Add(Val, ( int)val) : this;
|
||||
public MsgPack Add(string Val, uint? val) => val != null ? Add(Val, ( uint)val) : this;
|
||||
public MsgPack Add(string Val, long? val) => val != null ? Add(Val, ( long)val) : this;
|
||||
public MsgPack Add(string Val, ulong? val) => val != null ? Add(Val, ( ulong)val) : this;
|
||||
public MsgPack Add(string Val, float? val) => val != null ? Add(Val, ( float)val) : this;
|
||||
public MsgPack Add(string Val, double? val) => val != null ? Add(Val, (double)val) : this;
|
||||
|
||||
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));
|
||||
public MsgPack Add(string Val, short val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, ushort val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, int val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, uint val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, long val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, ulong val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, float val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, double val) => Add(new MsgPack(Val, val));
|
||||
|
||||
public bool ReadBoolean(string Name) => ReadNBoolean(Name).GetValueOrDefault();
|
||||
public sbyte ReadInt8(string Name) => ReadNInt8(Name).GetValueOrDefault();
|
||||
@@ -113,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();
|
||||
@@ -151,141 +158,104 @@ namespace KKdMainLib.MessagePack
|
||||
public double ReadDouble() => ReadNDouble().GetValueOrDefault();
|
||||
|
||||
public bool? ReadNBoolean()
|
||||
{ if (Object == null) return null;
|
||||
if (Object.GetType() == typeof( bool)) return ( bool) Object; return null; ; }
|
||||
{ if (Object is bool Boolean) return Boolean; return null; }
|
||||
public sbyte? ReadNInt8()
|
||||
{ if (Object == null) return null;
|
||||
if (Object.GetType() == typeof( long)) return ( sbyte)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return ( sbyte)(ulong)Object; 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 == null) return null;
|
||||
if (Object.GetType() == typeof( long)) return ( byte)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return ( byte)(ulong)Object; 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 == null) return null;
|
||||
if (Object.GetType() == typeof( long)) return ( short)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return ( short)(ulong)Object; 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 == null) return null;
|
||||
if (Object.GetType() == typeof( long)) return (ushort)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return (ushort)(ulong)Object; 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 == null) return null;
|
||||
if (Object.GetType() == typeof( long)) return ( int)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return ( int)(ulong)Object; 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 == null) return null;
|
||||
if (Object.GetType() == typeof( long)) return ( uint)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return ( uint)(ulong)Object; 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 == null) return null;
|
||||
if (Object.GetType() == typeof( long)) return ( long) Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return ( long)(ulong)Object; 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 == null) return null;
|
||||
if (Object.GetType() == typeof( ulong)) return ( ulong) Object;
|
||||
else if (Object.GetType() == typeof( long)) return ( ulong)( long)Object; 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 == null) return null;
|
||||
if (Object.GetType() == typeof(double)) return (float)(double)Object;
|
||||
else if (Object.GetType() == typeof( float)) return (float) Object;
|
||||
else if (Object.GetType() == typeof( long)) return (float)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return (float)( ulong)Object; 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 ( float)Float64; return null; }
|
||||
public double? ReadNDouble()
|
||||
{ if (Object == null) return null;
|
||||
if (Object.GetType() == typeof(double)) return (double) Object;
|
||||
else if (Object.GetType() == typeof( float)) return (double)(float)Object;
|
||||
else if (Object.GetType() == typeof( long)) return (double)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return (double)(ulong)Object; 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 == null) return null;
|
||||
if (Object.GetType() == typeof(string)) return (string) Object; return null; }
|
||||
|
||||
public bool Element(string Name, out MsgPack MsgPack, Type Type)
|
||||
{ if (Element(out MsgPack, Name)) return MsgPack.Object.GetType() == Type; return false; }
|
||||
{ if (Object is string String) return String; return null; }
|
||||
|
||||
public bool ElementArray(string Name, out MsgPack MsgPack) =>
|
||||
Element(Name, out MsgPack) ? MsgPack.Array != null : false;
|
||||
|
||||
public bool Element(string Name, out MsgPack MsgPack)
|
||||
{ if (Element(out MsgPack, Name)) return MsgPack != null; return false; }
|
||||
|
||||
public bool Element(out MsgPack MsgPack, string Name)
|
||||
{
|
||||
MsgPack = null;
|
||||
if (Object == null) return false;
|
||||
MsgPack = New;
|
||||
if (List.IsNull) return false;
|
||||
|
||||
Type type = Object.GetType();
|
||||
if (type == typeof(List<object>))
|
||||
{
|
||||
List<object> Obj = (List<object>)Object;
|
||||
foreach (object obj in Obj)
|
||||
{
|
||||
if (obj == null) continue; type = obj.GetType();
|
||||
if (type == typeof(MsgPack)) if (((MsgPack)obj).Name == Name)
|
||||
{ MsgPack = (MsgPack)obj; return true; }
|
||||
}
|
||||
}
|
||||
else if (type == typeof(object[]))
|
||||
{
|
||||
object[] Obj = (object[])Object;
|
||||
foreach (object obj in Obj)
|
||||
{
|
||||
if (obj == null) continue; type = obj.GetType();
|
||||
if (type == typeof(MsgPack)) if (((MsgPack)obj).Name == Name)
|
||||
{ MsgPack = (MsgPack)obj; return true; }
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < List.Count; i++)
|
||||
if (List[i].Name == Name) { MsgPack = List[i]; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
public enum Types : byte
|
||||
public bool ContainsKey(string Name)
|
||||
{
|
||||
PosInt = 0b00000000,
|
||||
FixMap = 0b10000000,
|
||||
FixArr = 0b10010000,
|
||||
FixStr = 0b10100000,
|
||||
Nil = 0b11000000,
|
||||
NeverUsed = 0b11000001,
|
||||
False = 0b11000010,
|
||||
True = 0b11000011,
|
||||
Bin8 = 0b11000100,
|
||||
Bin16 = 0b11000101,
|
||||
Bin32 = 0b11000110,
|
||||
Ext8 = 0b11000111,
|
||||
Ext16 = 0b11001000,
|
||||
Ext32 = 0b11001001,
|
||||
Float32 = 0b11001010,
|
||||
Float64 = 0b11001011,
|
||||
UInt8 = 0b11001100,
|
||||
UInt16 = 0b11001101,
|
||||
UInt32 = 0b11001110,
|
||||
UInt64 = 0b11001111,
|
||||
Int8 = 0b11010000,
|
||||
Int16 = 0b11010001,
|
||||
Int32 = 0b11010010,
|
||||
Int64 = 0b11010011,
|
||||
FixExt1 = 0b11010100,
|
||||
FixExt2 = 0b11010101,
|
||||
FixExt4 = 0b11010110,
|
||||
FixExt8 = 0b11010111,
|
||||
FixExt16 = 0b11011000,
|
||||
Str8 = 0b11011001,
|
||||
Str16 = 0b11011010,
|
||||
Str32 = 0b11011011,
|
||||
Arr16 = 0b11011100,
|
||||
Arr32 = 0b11011101,
|
||||
Map16 = 0b11011110,
|
||||
Map32 = 0b11011111,
|
||||
NegInt = 0b11100000,
|
||||
PosIntMax = 0b01111111,
|
||||
FixMapMax = 0b10001111,
|
||||
FixArrMax = 0b10011111,
|
||||
FixStrMax = 0b10111111,
|
||||
NegIntMax = 0b11111111,
|
||||
if (List.IsNull) return false;
|
||||
|
||||
for (int i = 0; i < List.Count ; i++)
|
||||
if (List[i].Name == Name) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public struct Ext
|
||||
{
|
||||
public byte[] Data;
|
||||
public sbyte Type;
|
||||
public sbyte Type;
|
||||
public byte[] Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,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();
|
||||
}
|
||||
|
||||
@@ -55,9 +55,9 @@ namespace KKdMainLib
|
||||
stream.Write(0x00);
|
||||
}
|
||||
|
||||
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 { Format = Main.Format.F2LE, ID = ID,
|
||||
Lenght = 0x20, Signature = 0x43464F45, });
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+17
-5
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
@@ -28,7 +27,11 @@ namespace KKdMainLib
|
||||
return POF;
|
||||
}
|
||||
public static Stream GetOffset(this Stream stream, ref POF POF)
|
||||
{if (stream.Format > Main.Format.F) POF.POFOffsets.Add(stream.Position - (stream.IsX ? stream.Offset : 0x00)); return stream; }
|
||||
{
|
||||
if (POF != null) if (stream.Format > Main.Format.F)
|
||||
POF.POFOffsets.Add(stream.Position - (stream.IsX ? stream.Offset : 0x00));
|
||||
return stream;
|
||||
}
|
||||
|
||||
public static void ReadPOF(this Stream stream, ref POF POF)
|
||||
{
|
||||
@@ -65,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"));
|
||||
}
|
||||
@@ -108,6 +111,15 @@ namespace KKdMainLib
|
||||
stream.Align(16, true);
|
||||
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, bool IsBE) =>
|
||||
IO.GetOffset(ref POF).ReadUInt32Endian(IsBE);
|
||||
public static long ReadInt64 (this Stream IO, ref POF POF) =>
|
||||
IO.GetOffset(ref POF).ReadInt64();
|
||||
|
||||
public static string ReadStringAtOffset(this Stream IO, ref POF POF, long Offset = 0, long Length = 0) =>
|
||||
IO.GetOffset(ref POF).ReadStringAtOffset(Offset, Length);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
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")]
|
||||
[assembly: AssemblyCopyright("Copyright korenkonder © 2018-2019")]
|
||||
[assembly: AssemblyCopyright("korenkonder © 2018-2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("2BA7EFC6-91D1-8BBC-C487-06C7F36CC789")]
|
||||
[assembly: AssemblyVersion("0.4.5.7")]
|
||||
[assembly: AssemblyFileVersion("0.4.5.7")]
|
||||
[assembly: AssemblyVersion("0.4.6.2")]
|
||||
[assembly: AssemblyFileVersion("0.4.6.2")]
|
||||
|
||||
+33
-56
@@ -1,9 +1,6 @@
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.Types;
|
||||
using KKdMainLib.MessagePack;
|
||||
using MPIO = KKdMainLib.MessagePack.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
@@ -17,9 +14,8 @@ namespace KKdMainLib
|
||||
}
|
||||
|
||||
public STR()
|
||||
{ Count = 0; Offset = 0; OffsetX = 0; STRs = null; POF = null; Header = new PDHead(); }
|
||||
|
||||
public long Count;
|
||||
{ Offset = 0; OffsetX = 0; STRs = null; POF = null; Header = new PDHead(); }
|
||||
|
||||
private long Offset;
|
||||
private long OffsetX;
|
||||
public String[] STRs;
|
||||
@@ -39,7 +35,7 @@ namespace KKdMainLib
|
||||
POF = Header.AddPOF();
|
||||
reader.Position = Header.Lenght;
|
||||
|
||||
Count = reader.ReadInt32Endian();
|
||||
long Count = reader.ReadInt32Endian();
|
||||
Offset = reader.ReadInt32Endian();
|
||||
|
||||
if (Offset == 0)
|
||||
@@ -72,7 +68,7 @@ namespace KKdMainLib
|
||||
else
|
||||
{
|
||||
reader.Position -= 4;
|
||||
Count = 0;
|
||||
int Count = 0;
|
||||
for (int a = 0, i = 0; reader.Position > 0 && reader.Position < reader.Length; i++, Count++)
|
||||
{
|
||||
a = reader.ReadInt32();
|
||||
@@ -102,6 +98,7 @@ namespace KKdMainLib
|
||||
POF = new POF();
|
||||
writer.IsBE = writer.Format == Main.Format.F2BE;
|
||||
|
||||
long Count = STRs.LongLength;
|
||||
if (writer.Format > Main.Format.FT)
|
||||
{
|
||||
writer.Position = 0x40;
|
||||
@@ -113,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++)
|
||||
{
|
||||
@@ -144,7 +140,7 @@ namespace KKdMainLib
|
||||
}
|
||||
if (writer.Format > Main.Format.FT)
|
||||
{
|
||||
writer.Align(16);
|
||||
writer.Align(0x10);
|
||||
Offset = writer.UIntPosition;
|
||||
writer.Position = 0x80;
|
||||
}
|
||||
@@ -172,56 +168,37 @@ namespace KKdMainLib
|
||||
writer.Close();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string filepath)
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
{
|
||||
//STRs = new List<String>();
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
|
||||
Xml Xml = new Xml();
|
||||
Xml.OpenXml(filepath + ".xml", true);
|
||||
Xml.Compact = true;
|
||||
int i = 0;
|
||||
foreach (XElement STR_ in Xml.doc.Elements("STR"))
|
||||
if (!MsgPack.Element("STR", out MsgPack STR)) return;
|
||||
|
||||
if (!STR.ElementArray("Strings", out MsgPack Strings)) return;
|
||||
|
||||
STRs = new String[Strings.Array.Length];
|
||||
for (int i = 0; i < STRs.Length; i++)
|
||||
{
|
||||
foreach (XAttribute Entry in STR_.Attributes())
|
||||
if (Entry.Name == "Format")
|
||||
Enum.TryParse(Entry.Value, out Header.Format);
|
||||
foreach (XElement STREntry in STR_.Elements())
|
||||
{
|
||||
if (STREntry.Name == "STREntry")
|
||||
{
|
||||
String Str = new String();
|
||||
foreach (XAttribute Entry in STREntry.Attributes())
|
||||
{
|
||||
if (Entry.Name == "ID" ) Str.ID = int.Parse(Entry.Value);
|
||||
if (Entry.Name == "String") Str.Str = Entry.Value ;
|
||||
}
|
||||
//STRs.Add(Str);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
STRs[i].ID = Strings[i].ReadInt32 ("ID" );
|
||||
STRs[i].Str = Strings[i].ReadString("Str");
|
||||
}
|
||||
Count = i;
|
||||
|
||||
MsgPack = MsgPack.New;
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string filepath)
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
{
|
||||
MsgPack STR_ = new MsgPack("STR").Add("Format", Header.Format.ToString()).Add("Count", Count);
|
||||
MsgPack Strings = new MsgPack("Strings", Count);
|
||||
for (int i = 0; i < Count; i++)
|
||||
MsgPack STR_ = new MsgPack("STR").Add("Format", Header.Format.ToString());
|
||||
MsgPack Strings = new MsgPack(STRs.Length, "Strings");
|
||||
for (int i = 0; i < STRs.Length; i++)
|
||||
{
|
||||
Strings[i] = new MsgPack().Add("ID", STRs[i].ID);
|
||||
if (STRs[i].Str != null)
|
||||
if (STRs[i].Str != "")
|
||||
((MsgPack)Strings[i]).Add("S", STRs[i].Str); ;
|
||||
Strings[i] = MsgPack.New.Add("ID", STRs[i].ID);
|
||||
if (STRs[i].Str != null) if (STRs[i].Str != "")
|
||||
Strings[i].Add("S", STRs[i].Str); ;
|
||||
}
|
||||
STR_.Add(Strings);
|
||||
|
||||
MsgPack MsgPack = new MsgPack(MsgPack.Types.FixMap).Add(STR_);
|
||||
|
||||
MPIO IO = new MPIO(File.OpenWriter(filepath + ".mp", true));
|
||||
IO.Write(MsgPack, true);
|
||||
IO = null;
|
||||
MsgPack = null;
|
||||
STR_.Write(true, file, JSON);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,5 @@ namespace KKdMainLib
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
+16
-34
@@ -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();
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
namespace KKdMainLib.Types
|
||||
{
|
||||
public interface IKeyFrame<TKey, TVal>
|
||||
{
|
||||
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> : IKeyFrame<TKey, TVal>
|
||||
{
|
||||
public TKey Frame;
|
||||
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
|
||||
new KeyFrameT0<TKey, TVal> { Frame = Frame };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
|
||||
new KeyFrameT1<TKey, TVal> { Frame = Frame };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
|
||||
new KeyFrameT2<TKey, TVal> { Frame = Frame };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
|
||||
new KeyFrameT3<TKey, TVal> { Frame = Frame };
|
||||
|
||||
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> : IKeyFrame<TKey, TVal>
|
||||
{
|
||||
public TKey Frame;
|
||||
public TVal Value;
|
||||
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
|
||||
new KeyFrameT0<TKey, TVal> { Frame = Frame };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
|
||||
new KeyFrameT1<TKey, TVal> { Frame = Frame, Value = Value };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
|
||||
new KeyFrameT2<TKey, TVal> { Frame = Frame, Value = Value };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
|
||||
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value };
|
||||
|
||||
public IKeyFrame<TKey, TVal> Check() =>
|
||||
Value.Equals(default(TVal)) ? ToKeyFrameT0() : (this);
|
||||
|
||||
public override string ToString() => ToString(true);
|
||||
public string ToString(bool Brackets) =>
|
||||
(Brackets ? "(" : "") + Main.ToString(Frame) + "," +
|
||||
Main.ToString(Value) + (Brackets ? ")" : "");
|
||||
}
|
||||
|
||||
public struct KeyFrameT2<TKey, TVal> : IKeyFrame<TKey, TVal>
|
||||
{
|
||||
public TKey Frame;
|
||||
public TVal Value;
|
||||
public TVal Interpolation;
|
||||
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
|
||||
new KeyFrameT0<TKey, TVal> { Frame = Frame };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
|
||||
new KeyFrameT1<TKey, TVal> { Frame = Frame, Value = Value };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
|
||||
new KeyFrameT2<TKey, TVal> { Frame = Frame, Value = Value,
|
||||
Interpolation = Interpolation};
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
|
||||
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
|
||||
Interpolation1 = Interpolation, Interpolation2 = Interpolation };
|
||||
|
||||
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 IKeyFrame<TKey, TVal> Check()
|
||||
{
|
||||
if (Value.Equals(default(TVal)) && Interpolation.Equals(default(TVal)))
|
||||
return ToKeyFrameT0();
|
||||
else if (Value.Equals(default(TVal))) return ToKeyFrameT1();
|
||||
return this;
|
||||
}
|
||||
|
||||
public override string ToString() => ToString(true);
|
||||
public string ToString(bool Brackets) =>
|
||||
(Brackets ? "(" : "") + Main.ToString(Frame) + "," + Main.
|
||||
ToString(Value) + "," + Main.ToString(Interpolation) + (Brackets ? ")" : "");
|
||||
}
|
||||
|
||||
public struct KeyFrameT3<TKey, TVal> : IKeyFrame<TKey, TVal>
|
||||
{
|
||||
public TKey Frame;
|
||||
public TVal Value;
|
||||
public TVal Interpolation1;
|
||||
public TVal Interpolation2;
|
||||
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
|
||||
new KeyFrameT0<TKey, TVal> { Frame = Frame };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
|
||||
new KeyFrameT1<TKey, TVal> { Frame = Frame, Value = Value };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
|
||||
new KeyFrameT2<TKey, TVal> { Frame = Frame, Value = Value, Interpolation = Interpolation1 };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
|
||||
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
|
||||
Interpolation1 = Interpolation1, Interpolation2 = Interpolation2 };
|
||||
|
||||
public IKeyFrame<TKey, TVal> Check()
|
||||
{
|
||||
if (Value.Equals(default(TVal)) && Interpolation1.Equals(default(TVal)) &&
|
||||
Interpolation2.Equals(default(TVal))) return ToKeyFrameT0();
|
||||
else if (Interpolation1.Equals(default(TVal)) &&
|
||||
Interpolation2.Equals(default(TVal))) return ToKeyFrameT1();
|
||||
else if (Interpolation1.Equals(Interpolation2))
|
||||
return ToKeyFrameT2();
|
||||
return this;
|
||||
}
|
||||
|
||||
public override string ToString() => ToString(true);
|
||||
public string ToString(bool Brackets) =>
|
||||
(Brackets ? "(" : "") + Main.ToString(Frame) + "," + Main.ToString(Value) + "," +
|
||||
Main.ToString(Interpolation1) + "," + Main.ToString(Interpolation2) + (Brackets ? ")" : "");
|
||||
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT2(IKeyFrame<TKey, TVal>
|
||||
Previous, out IKeyFrame<TKey, TVal> Current)
|
||||
{
|
||||
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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using System.Collections;
|
||||
|
||||
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> NewReserve(int Capacity) => new KKdList<T>() { Capacity = Capacity };
|
||||
|
||||
private int index;
|
||||
private T[] array;
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public bool IsNull => array == null;
|
||||
public bool NotNull => array != null;
|
||||
|
||||
public int Capacity { get => array != null ? array.Length : -1;
|
||||
set
|
||||
{
|
||||
if (array != null) System.Array.Resize(ref array, value);
|
||||
else array = new T[value];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public KKdList(T[] Array)
|
||||
{
|
||||
index = 0;
|
||||
Count = Array.Length;
|
||||
array = Array;
|
||||
}
|
||||
|
||||
public T Current => index < Count ? array[index] : default;
|
||||
|
||||
object IEnumerator.Current => Current;
|
||||
|
||||
public T this[int index]
|
||||
{ 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; } }
|
||||
|
||||
public IEnumerator GetEnumerator() => this;
|
||||
|
||||
public void Dispose() { array = null; Count = 0; index = 0; }
|
||||
|
||||
public void Reset() => index = 0;
|
||||
|
||||
public void Add(T item)
|
||||
{
|
||||
if (IsNull) return;
|
||||
|
||||
Count++;
|
||||
if (array.Length < Count)
|
||||
System.Array.Resize(ref array, Count);
|
||||
array[Count - 1] = item;
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if (IsNull) return;
|
||||
|
||||
for (int i = index; i < Count; i++)
|
||||
array[i] = array[i + 1];
|
||||
}
|
||||
|
||||
public void RemoveRange(int IndexStart, int IndexEnd)
|
||||
{
|
||||
if (IndexEnd - IndexStart < 1) return;
|
||||
if (IsNull) return;
|
||||
|
||||
for (int i = IndexStart; i < Count; i++)
|
||||
array[i] = array[i + IndexEnd - IndexStart];
|
||||
}
|
||||
|
||||
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;
|
||||
return false;
|
||||
}
|
||||
|
||||
public int IndexOf(T val)
|
||||
{
|
||||
if (IsNull) return -1;
|
||||
for (int i = 0; i < Count; i++)
|
||||
if (array[i].Equals(val)) return i;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace KKdMainLib.Types
|
||||
{
|
||||
public struct Vector2<T>
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
|
||||
public Vector2(T X, T Y)
|
||||
{ this.X = X; this.Y = Y; }
|
||||
|
||||
public override string ToString() => "X: " + X + "; Y: " + Y;
|
||||
}
|
||||
|
||||
public struct Vector3<T>
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
public T Z;
|
||||
|
||||
public Vector3(T X, T Y, T Z)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; }
|
||||
|
||||
public override string ToString() => "X: " + X + "; Y: " + Y + "; Z: " + Z;
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public class Xml
|
||||
{
|
||||
public XDocument doc;
|
||||
|
||||
public bool Compact = false;
|
||||
|
||||
public Xml() { doc = new XDocument(); }
|
||||
|
||||
public void OpenXml(string file, bool compact)
|
||||
{
|
||||
doc = XDocument.Load(file);
|
||||
Compact = compact;
|
||||
}
|
||||
|
||||
public void SaveXml(string file)
|
||||
{
|
||||
XmlWriter writer = XmlWriter.Create(file, settings);
|
||||
doc.Save(writer);
|
||||
writer.Dispose();
|
||||
Compact = false;
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
public readonly XmlWriterSettings settings = new XmlWriterSettings
|
||||
{ Encoding = Encoding.UTF8, NewLineChars = "\n", Indent = true, IndentChars = "\t" };
|
||||
|
||||
public void Reader(XElement Child, ref bool value, string localName)
|
||||
{ if (Child.Name == localName) value = bool.Parse(Child.Value); }
|
||||
|
||||
public void Reader(XAttribute Entry, ref bool value, string localName)
|
||||
{ if (Entry.Name == localName) value = bool.Parse(Entry.Value); }
|
||||
|
||||
public void Reader(XElement Child, ref int value, string localName)
|
||||
{ if (Child.Name == localName) value = int.Parse(Child.Value); }
|
||||
|
||||
public void Reader(XAttribute Entry, ref int value, string localName)
|
||||
{ if (Entry.Name == localName) value = int.Parse(Entry.Value); }
|
||||
|
||||
public void Reader(XElement Child, ref uint value, string localName)
|
||||
{ if (Child.Name == localName) value = uint.Parse(Child.Value); }
|
||||
|
||||
public void Reader(XAttribute Entry, ref uint value, string localName)
|
||||
{ if (Entry.Name == localName) value = uint.Parse(Entry.Value); }
|
||||
|
||||
public void Reader(XElement Child, ref long value, string localName)
|
||||
{ if (Child.Name == localName) value = long.Parse(Child.Value); }
|
||||
|
||||
public void Reader(XAttribute Entry, ref long value, string localName)
|
||||
{ if (Entry.Name == localName) value = long.Parse(Entry.Value); }
|
||||
|
||||
public void Reader(XElement Child, ref ulong value, string localName)
|
||||
{ if (Child.Name == localName) value = ulong.Parse(Child.Value); }
|
||||
|
||||
public void Reader(XAttribute Entry, ref ulong value, string localName)
|
||||
{ if (Entry.Name == localName) value = ulong.Parse(Entry.Value); }
|
||||
|
||||
public void Reader(XElement Child, ref double value, string localName)
|
||||
{ if (Child.Name == localName) value = Child.Value.ToDouble(); }
|
||||
|
||||
public void Reader(XAttribute Entry, ref double value, string localName)
|
||||
{ if (Entry.Name == localName) value = Entry.Value.ToDouble(); }
|
||||
|
||||
public void Reader(XElement Child, ref string value, string localName)
|
||||
{ if (Child.Name == localName) value = Child.Value; }
|
||||
|
||||
public void Reader(XAttribute Entry, ref string value, string localName)
|
||||
{ if (Entry.Name == localName) value = Entry.Value; }
|
||||
|
||||
public void Reader(XElement Child, ref string[] value, string localName, params char[] Separate)
|
||||
{ if (Child.Name == localName) value = Child.Value.Split(Separate); }
|
||||
|
||||
public void Reader(XAttribute Entry, ref string[] value, string localName, params char[] Separate)
|
||||
{ if (Entry.Name == localName) value = Entry.Value.Split(Separate); }
|
||||
|
||||
public void Writer(XElement element, bool value, string localName) =>
|
||||
Writer(element, value.ToString().ToLower(), localName);
|
||||
|
||||
public void Writer(XElement element, long value, string localName) =>
|
||||
Writer(element, value.ToString().ToLower(), localName);
|
||||
|
||||
public void Writer(XElement element, ulong value, string localName) =>
|
||||
Writer(element, value.ToString().ToLower(), localName);
|
||||
|
||||
public void Writer(XElement element, double value, string localName) =>
|
||||
Writer(element, value.ToString(), localName);
|
||||
|
||||
public void Writer(XElement element, string value, string localName)
|
||||
{
|
||||
if (Compact && value != "" && value != null)
|
||||
element.Add(new XAttribute(localName, value));
|
||||
else if (!Compact)
|
||||
element.Add(new XElement(localName, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
+87
-103
@@ -1,129 +1,113 @@
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
using MSIO = System.IO;
|
||||
|
||||
namespace KKdSoundLib
|
||||
{
|
||||
public unsafe class DIVA
|
||||
{
|
||||
public DIVAFile Data = new DIVAFile();
|
||||
|
||||
public string file = "";
|
||||
private int c, i;
|
||||
|
||||
public DIVA() { Data = new DIVAFile(); file = ""; }
|
||||
public DIVA(string filepath) { Data = new DIVAFile(); file = filepath; }
|
||||
public DIVA() { Data = new DIVAFile(); }
|
||||
|
||||
public void DIVAReader(bool ToArray = false)
|
||||
public void DIVAReader(string file, bool ToArray = false)
|
||||
{
|
||||
if (MSIO.File.Exists(file + ".diva"))
|
||||
{
|
||||
Data = new DIVAFile();
|
||||
Stream reader = File.OpenReader(file + ".diva");
|
||||
if (!File.Exists(file + ".diva")) return;
|
||||
|
||||
if (reader.ReadString(0x04) == "DIVA")
|
||||
{
|
||||
reader.ReadInt32();
|
||||
Data.Size = reader.ReadUInt32();
|
||||
Data.SampleRate = reader.ReadUInt32();
|
||||
Data.SamplesCount = reader.ReadUInt32();
|
||||
reader.ReadInt64();
|
||||
Data.Channels = reader.ReadUInt16();
|
||||
reader.ReadUInt16();
|
||||
Data.Name = reader.ReadString(0x20);
|
||||
Data = new DIVAFile();
|
||||
Stream reader = File.OpenReader(file + ".diva");
|
||||
|
||||
Stream writer = File.OpenWriter();
|
||||
if (!ToArray) writer = File.OpenWriter(file + ".wav", true);
|
||||
writer.LongPosition = 0x2C;
|
||||
if (reader.ReadString(0x04) != "DIVA") { reader.Close(); return; }
|
||||
|
||||
byte value = 0;
|
||||
int[] current = new int[Data.Channels];
|
||||
int[] currentclamp = new int[Data.Channels];
|
||||
sbyte[] stepindex = new sbyte[Data.Channels];
|
||||
float f;
|
||||
reader.ReadInt32();
|
||||
Data.Size = reader.ReadUInt32();
|
||||
Data.SampleRate = reader.ReadUInt32();
|
||||
Data.SamplesCount = reader.ReadUInt32();
|
||||
reader.ReadInt64();
|
||||
Data.Channels = reader.ReadUInt16();
|
||||
reader.ReadUInt16();
|
||||
Data.Name = reader.ReadString(0x20);
|
||||
|
||||
int* currentPtr = current.GetPtr();
|
||||
int* currentclampPtr = currentclamp.GetPtr();
|
||||
sbyte* stepindexPtr = stepindex.GetPtr();
|
||||
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Data.Channels; c++)
|
||||
{
|
||||
value = reader.ReadHalfByte();
|
||||
IMADecoder(value, ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
|
||||
f = (float)(currentPtr[c] / 32768.0);
|
||||
writer.Write(f);
|
||||
}
|
||||
|
||||
WAV.Header Header = new WAV.Header
|
||||
{ Bytes = 4, Channels = Data.Channels, Format = 3,
|
||||
SampleRate = Data.SampleRate, Size = Data.SamplesCount * Data.Channels * 4};
|
||||
writer.Write(Header, 0);
|
||||
if (ToArray) Data.Data = writer.ToArray();
|
||||
writer.Close();
|
||||
}
|
||||
reader.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] BuildWavHeader(WAV.Header Header, short Bytes)
|
||||
{
|
||||
Stream writer = File.OpenWriter();
|
||||
writer.Write(Header);
|
||||
byte[] Data = writer.ToArray();
|
||||
if (!ToArray) writer = File.OpenWriter(file + ".wav", true);
|
||||
writer.LongPosition = 0x2C;
|
||||
|
||||
byte value = 0;
|
||||
int[] current = new int[Data.Channels];
|
||||
int[] currentclamp = new int[Data.Channels];
|
||||
sbyte[] stepindex = new sbyte[Data.Channels];
|
||||
float f;
|
||||
|
||||
int* currentPtr = current.GetPtr();
|
||||
int* currentclampPtr = currentclamp.GetPtr();
|
||||
sbyte* stepindexPtr = stepindex.GetPtr();
|
||||
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Data.Channels; c++)
|
||||
{
|
||||
value = reader.ReadHalfByte();
|
||||
IMADecoder(value, ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
|
||||
f = (float)(currentPtr[c] / 32768.0);
|
||||
writer.Write(f);
|
||||
}
|
||||
|
||||
WAV.Header Header = new WAV.Header { Bytes = 4, Channels = Data.Channels, Format = 3,
|
||||
SampleRate = Data.SampleRate, Size = Data.SamplesCount * Data.Channels * 4 };
|
||||
writer.Write(Header, 0);
|
||||
if (ToArray) Data.Data = writer.ToArray();
|
||||
writer.Close();
|
||||
return Data;
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
|
||||
public void DIVAWriter()
|
||||
public void DIVAWriter(string file)
|
||||
{
|
||||
if (MSIO.File.Exists(file + ".wav"))
|
||||
{
|
||||
Stream reader = File.OpenReader(file + ".wav");
|
||||
Stream writer = File.OpenWriter(file + ".diva", true);
|
||||
|
||||
Data = new DIVAFile();
|
||||
WAV.Header Header = reader.ReadWAVHeader();
|
||||
if (Header.IsSupported)
|
||||
if (!File.Exists(file + ".wav")) return;
|
||||
|
||||
Stream reader = File.OpenReader(file + ".wav");
|
||||
|
||||
Data = new DIVAFile();
|
||||
WAV.Header Header = reader.ReadWAVHeader();
|
||||
if (!Header.IsSupported) { reader.Close(); return; }
|
||||
|
||||
Stream writer = File.OpenWriter(file + ".diva", true);
|
||||
Data.Channels = Header.Channels;
|
||||
Data.SampleRate = Header.SampleRate;
|
||||
writer.LongPosition = 0x40;
|
||||
|
||||
byte value = 0;
|
||||
int[] sample = new int[Data.Channels];
|
||||
int[] current = new int[Data.Channels];
|
||||
int[] currentclamp = new int[Data.Channels];
|
||||
sbyte[] stepindex = new sbyte[Data.Channels];
|
||||
|
||||
int* samplePtr = sample.GetPtr();
|
||||
int* currentPtr = current.GetPtr();
|
||||
int* currentclampPtr = currentclamp.GetPtr();
|
||||
sbyte* stepindexPtr = stepindex.GetPtr();
|
||||
Data.SamplesCount = Header.Size / Header.Channels / Header.Bytes;
|
||||
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Header.Channels; c++)
|
||||
{
|
||||
Data.Channels = Header.Channels;
|
||||
Data.SampleRate = Header.SampleRate;
|
||||
writer.LongPosition = 0x40;
|
||||
|
||||
byte value = 0;
|
||||
int[] sample = new int[Data.Channels];
|
||||
int[] current = new int[Data.Channels];
|
||||
int[] currentclamp = new int[Data.Channels];
|
||||
sbyte[] stepindex = new sbyte[Data.Channels];
|
||||
|
||||
int* samplePtr = sample.GetPtr();
|
||||
int* currentPtr = current.GetPtr();
|
||||
int* currentclampPtr = currentclamp.GetPtr();
|
||||
sbyte* stepindexPtr = stepindex.GetPtr();
|
||||
Data.SamplesCount = Header.Size / Header.Channels / Header.Bytes;
|
||||
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Header.Channels; c++)
|
||||
{
|
||||
samplePtr[c] = (reader.ReadWAVSample(Header.Bytes, Header.Format) * 0x8000).CFTI();
|
||||
value = IMAEncoder(samplePtr[c], ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
|
||||
writer.Write(value, 4);
|
||||
}
|
||||
writer.CheckWrited();
|
||||
|
||||
writer.LongPosition = 0x00;
|
||||
writer.Write("DIVA");
|
||||
writer.Write(0x00);
|
||||
writer.Write((Data.SamplesCount * Data.Channels).Align(2, 2));
|
||||
writer.Write(Data.SampleRate);
|
||||
writer.Write(Data.SamplesCount);
|
||||
writer.Write(0x00);
|
||||
writer.Write(0x00);
|
||||
writer.Write(Data.Channels);
|
||||
samplePtr[c] = (reader.ReadWAVSample(Header.Bytes, Header.Format) * 0x8000).CFTI();
|
||||
value = IMAEncoder(samplePtr[c], ref currentPtr[c],
|
||||
ref currentclampPtr[c], ref stepindexPtr[c]);
|
||||
writer.Write(value, 4);
|
||||
}
|
||||
reader.Close();
|
||||
writer.Close();
|
||||
}
|
||||
writer.CheckWrited();
|
||||
|
||||
writer.LongPosition = 0x00;
|
||||
writer.Write("DIVA");
|
||||
writer.Write(0x00);
|
||||
writer.Write((Data.SamplesCount * Data.Channels).Align(2, 2));
|
||||
writer.Write(Data.SampleRate);
|
||||
writer.Write(Data.SamplesCount);
|
||||
writer.Write(0x00);
|
||||
writer.Write(0x00);
|
||||
writer.Write(Data.Channels);
|
||||
writer.Close();
|
||||
reader.Close();
|
||||
}
|
||||
|
||||
private void IMADecoder(byte value, ref int current, ref int currentclamp, ref sbyte stepindex)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdSoundLib
|
||||
{
|
||||
@@ -15,10 +16,10 @@ namespace KKdSoundLib
|
||||
|
||||
public static void Write(this Stream IO, double Sample, ushort Bytes, ushort Format)
|
||||
{
|
||||
if (Bytes == 2) IO.Write ((ushort)(Sample * 0x00008000));
|
||||
else if (Bytes == 4 && Format == 0x01) IO.Write (( int)(Sample * 0x80000000));
|
||||
else if (Bytes == 4 && Format == 0x03) IO.Write ((float) Sample);
|
||||
else if (Bytes == 8 && Format == 0x03) IO.Write ( Sample);
|
||||
if (Bytes == 2) IO.Write((Sample * 0x00008000).CFTS());
|
||||
else if (Bytes == 4 && Format == 0x01) IO.Write((Sample * 0x80000000).CFTI());
|
||||
else if (Bytes == 4 && Format == 0x03) IO.Write((float)Sample);
|
||||
else if (Bytes == 8 && Format == 0x03) IO.Write( Sample);
|
||||
}
|
||||
|
||||
public static WAV.Header ReadWAVHeader(this Stream IO)
|
||||
@@ -46,7 +47,7 @@ namespace KKdSoundLib
|
||||
Header.Format = IO.ReadUInt16();
|
||||
}
|
||||
if (Header.Bytes < 1 || (Header.Bytes > 4 && Header.Bytes != 8)) return Header;
|
||||
if (Header.Bytes > 0 && Header.Bytes < 4 && Header.Format == 3) return Header;
|
||||
if (Header.Bytes > 0 && Header.Bytes < 4 && Header.Format == 3 ) return Header;
|
||||
if (Header.Bytes == 8 && Header.Format == 1) return Header;
|
||||
IO.Seek(Offset + 0x14, 0);
|
||||
if (IO.ReadString(4) != "data") return Header;
|
||||
@@ -70,7 +71,9 @@ namespace KKdSoundLib
|
||||
else IO.Write(Header.Size + 0x3C);
|
||||
IO.Write("WAVE");
|
||||
IO.Write("fmt ");
|
||||
IO.Write(0x10);
|
||||
if (Header.Format != 0xFFFE) IO.Write(0x10);
|
||||
else IO.Write(0x28);
|
||||
|
||||
IO.Write(Header.Format);
|
||||
IO.Write((short)Header.Channels);
|
||||
IO.Write(Header.SampleRate);
|
||||
|
||||
@@ -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" />
|
||||
@@ -46,8 +50,6 @@
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KKdMainLib\KKdMainLib.csproj">
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
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")]
|
||||
[assembly: AssemblyCopyright("Copyright korenkonder © 2019")]
|
||||
[assembly: AssemblyCopyright("korenkonder © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA")]
|
||||
[assembly: AssemblyVersion("0.0.2.1")]
|
||||
[assembly: AssemblyFileVersion("0.0.2.1")]
|
||||
[assembly: AssemblyVersion("0.0.2.3")]
|
||||
[assembly: AssemblyFileVersion("0.0.2.3")]
|
||||
|
||||
+76
-49
@@ -1,6 +1,5 @@
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
using MSIO = System.IO;
|
||||
|
||||
namespace KKdSoundLib
|
||||
{
|
||||
@@ -13,20 +12,18 @@ namespace KKdSoundLib
|
||||
private const uint BS = 28; //VAGBlockSize
|
||||
private int[] Samp1, Samp2, Samp3, Samp4;
|
||||
private int* S1Ptr, S2Ptr, S3Ptr, S4Ptr;
|
||||
private bool Success = false;
|
||||
|
||||
public VAGFile VAGData = new VAGFile();
|
||||
public string file = "";
|
||||
|
||||
public VAG() { VAGData = new VAGFile(); file = "";
|
||||
public VAG() { VAGData = new VAGFile();
|
||||
HEVAG1Ptr = HEVAG1.GetPtr(); HEVAG2Ptr = HEVAG2.GetPtr();
|
||||
HEVAG3Ptr = HEVAG3.GetPtr(); HEVAG4Ptr = HEVAG4.GetPtr();
|
||||
}
|
||||
|
||||
public VAG(string filepath) { VAGData = new VAGFile(); file = filepath; }
|
||||
HEVAG3Ptr = HEVAG3.GetPtr(); HEVAG4Ptr = HEVAG4.GetPtr(); }
|
||||
|
||||
public void VAGReader()
|
||||
public void VAGReader(string file)
|
||||
{
|
||||
if (!MSIO.File.Exists(file + ".vag")) return;
|
||||
Success = false;
|
||||
if (!File.Exists(file + ".vag")) return;
|
||||
|
||||
VAGData = new VAGFile();
|
||||
Stream reader = File.OpenReader(file + ".vag", true);
|
||||
@@ -147,6 +144,7 @@ namespace KKdSoundLib
|
||||
|
||||
VAGData.DataPtr = VAGData.OriginDataPtr;
|
||||
reader.Close();
|
||||
Success = true;
|
||||
}
|
||||
|
||||
private void DecodeHEVAG()
|
||||
@@ -176,33 +174,44 @@ namespace KKdSoundLib
|
||||
}
|
||||
}
|
||||
|
||||
public void WAVWriterStraight()
|
||||
public void WAVWriterStraight(string file, bool IgnoreEndFlags = false)
|
||||
{
|
||||
if (!Success) return;
|
||||
byte Flag = VAGData.Flags[0];
|
||||
if (Flag == 7) return;
|
||||
WAV.Header Header = new WAV.Header();
|
||||
Stream writer = File.OpenWriter(file + ".wav", true);
|
||||
writer.LongPosition = 0x2C;
|
||||
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
{
|
||||
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
|
||||
writer.Write(f);
|
||||
}
|
||||
|
||||
for (i1 = 0, i2 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
|
||||
{
|
||||
Flag = VAGData.Flags[i1];
|
||||
if (Flag == 5 || Flag > 6) break;
|
||||
|
||||
if (Flag < 8)
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
{
|
||||
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
|
||||
writer.Write(f);
|
||||
}
|
||||
else
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
writer.Write(0f);
|
||||
|
||||
if (Flag == 1) break;
|
||||
for (i1 = 0, i2 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
|
||||
{
|
||||
Flag = VAGData.Flags[i1];
|
||||
if (!IgnoreEndFlags && Flag == 5 || Flag == 7) break;
|
||||
if (Flag < 8)
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
{
|
||||
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
|
||||
writer.Write(f);
|
||||
}
|
||||
else
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
writer.Write(0f);
|
||||
|
||||
if (!IgnoreEndFlags && Flag == 1) break;
|
||||
}
|
||||
VAGData.DataPtr = VAGData.OriginDataPtr;
|
||||
|
||||
@@ -212,29 +221,36 @@ namespace KKdSoundLib
|
||||
writer.Close();
|
||||
}
|
||||
|
||||
public void WAVWriter()
|
||||
public void WAVWriter(string file, bool IgnoreEndFlags = false)
|
||||
{
|
||||
if (!Success) return;
|
||||
byte Flag = VAGData.Flags[0];
|
||||
if (Flag == 7) return;
|
||||
WAV.Header Header = new WAV.Header();
|
||||
Stream writer;
|
||||
if (Flag == 6) writer = File.OpenWriter(file + ".loop.0.wav", true);
|
||||
else writer = File.OpenWriter(file + ".0.wav", true);
|
||||
if (!IgnoreEndFlags && Flag == 6) writer = File.OpenWriter(file + ".loop.0.wav", true);
|
||||
else writer = File.OpenWriter(file + ".0.wav", true);
|
||||
writer.LongPosition = 0x2C;
|
||||
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
{
|
||||
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
|
||||
writer.Write(f);
|
||||
}
|
||||
if (Flag < 8)
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
{
|
||||
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
|
||||
writer.Write(f);
|
||||
}
|
||||
else
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
writer.Write(0f);
|
||||
|
||||
VAGData.DataPtr += VBS;
|
||||
|
||||
for (i1 = 1, i2 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
|
||||
{
|
||||
Flag = VAGData.Flags[i1];
|
||||
if (Flag == 5 || Flag > 6) break;
|
||||
else if (Flag == 6)
|
||||
if (!IgnoreEndFlags && Flag == 5 || Flag == 7) break;
|
||||
else if (!IgnoreEndFlags && Flag == 6)
|
||||
{
|
||||
Header = new WAV.Header { Bytes = 4, Channels = ch, Format = 3, SampleRate =
|
||||
VAGData.SampleRate, Size = writer.UIntPosition - 0x2C };
|
||||
@@ -246,15 +262,20 @@ namespace KKdSoundLib
|
||||
writer.LongPosition = 0x2C;
|
||||
}
|
||||
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
{
|
||||
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
|
||||
writer.Write(f);
|
||||
}
|
||||
if (!IgnoreEndFlags && Flag < 8)
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
{
|
||||
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
|
||||
writer.Write(f);
|
||||
}
|
||||
else
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
writer.Write(0f);
|
||||
|
||||
if (Flag == 1) break;
|
||||
else if (Flag == 3)
|
||||
if (!IgnoreEndFlags && Flag == 1) break;
|
||||
else if (!IgnoreEndFlags && Flag == 3)
|
||||
{
|
||||
Header = new WAV.Header { Bytes = 4, Channels = ch, Format = 3, SampleRate =
|
||||
VAGData.SampleRate, Size = writer.UIntPosition - 0x2C };
|
||||
@@ -277,8 +298,9 @@ namespace KKdSoundLib
|
||||
writer.Close();
|
||||
}
|
||||
|
||||
public int WAVReaderStraight(bool ExtendedFlagging = false)
|
||||
public int WAVReaderStraight(string file, bool ExtendedFlagging = false)
|
||||
{
|
||||
Success = false;
|
||||
VAGData = new VAGFile();
|
||||
Stream reader = File.OpenReader(file + ".wav");
|
||||
WAV.Header Header = reader.ReadWAVHeader();
|
||||
@@ -319,16 +341,18 @@ namespace KKdSoundLib
|
||||
VAGData.Flags[VAGData.Size - 1] = 0x1;
|
||||
|
||||
reader.Close();
|
||||
Success = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int WAVReader(bool ExtendedFlagging = false)
|
||||
public int WAVReader(string file, bool ExtendedFlagging = false)
|
||||
{
|
||||
Success = false;
|
||||
string[] Files;
|
||||
bool HasLoop = false;
|
||||
bool[] Loop;
|
||||
{
|
||||
if (!file.EndsWith(".0")) return WAVReaderStraight();
|
||||
if (!file.EndsWith(".0")) return WAVReaderStraight(file);
|
||||
file = file.Remove(file.Length - 2);
|
||||
i2 = 0;
|
||||
System.Collections.Generic.List<string> files =
|
||||
@@ -337,12 +361,12 @@ namespace KKdSoundLib
|
||||
new System.Collections.Generic.List< bool>();
|
||||
while (true)
|
||||
{
|
||||
if (MSIO.File.Exists(file + "." + i2 + ".wav"))
|
||||
if (File.Exists(file + "." + i2 + ".wav"))
|
||||
{
|
||||
files.Add(file + "." + i2 + ".wav");
|
||||
loop.Add(false);
|
||||
}
|
||||
else if (MSIO.File.Exists(file + "." + i2 + ".loop.wav"))
|
||||
else if (File.Exists(file + "." + i2 + ".loop.wav"))
|
||||
{
|
||||
files.Add(file + "." + i2 + ".loop.wav");
|
||||
loop.Add(true);
|
||||
@@ -431,12 +455,14 @@ namespace KKdSoundLib
|
||||
VAGData.Channels = ch;
|
||||
VAGData.SampleRate = SampleRate;
|
||||
|
||||
Success = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void VAGWriter(bool HEVAG = true)
|
||||
public void VAGWriter(string file, bool HEVAG = true)
|
||||
{
|
||||
VAGData.Name = MSIO.Path.GetFileName(file);
|
||||
if (!Success) return;
|
||||
VAGData.Name = Path.GetFileName(file);
|
||||
Stream writer = File.OpenWriter(file + ".vag", true);
|
||||
Samp1 = new int[ch]; S1Ptr = Samp1.GetPtr();
|
||||
Samp2 = new int[ch]; S2Ptr = Samp2.GetPtr();
|
||||
@@ -466,6 +492,7 @@ namespace KKdSoundLib
|
||||
if (HEVAG) writer.Write(VAGData.Channels);
|
||||
else writer.Write((ushort)0x1);
|
||||
writer.Write(VAGData.Name);
|
||||
writer.LongLength = 0x30;
|
||||
writer.LongPosition = 0x30;
|
||||
|
||||
if (HEVAG)
|
||||
|
||||
+1
-7
@@ -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
|
||||
{
|
||||
|
||||
@@ -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,10 +35,14 @@
|
||||
<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" />
|
||||
<Compile Include="classes\Tools\A3D.cs" />
|
||||
<Compile Include="classes\Tools\AET.cs" />
|
||||
<Compile Include="classes\Tools\DB.cs" />
|
||||
<Compile Include="classes\Tools\DEX.cs" />
|
||||
<Compile Include="classes\Tools\DIV.cs" />
|
||||
<Compile Include="classes\Tools\STR.cs" />
|
||||
@@ -51,8 +57,6 @@
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KKdMainLib\KKdMainLib.csproj">
|
||||
|
||||
+39
-27
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using MSIO = System.IO;
|
||||
using KKdMainLib.Types;
|
||||
using KKdMain = KKdMainLib.Main;
|
||||
using KKdFARC = KKdMainLib.FARC;
|
||||
|
||||
@@ -10,39 +10,37 @@ namespace PD_Tool
|
||||
public static class Program
|
||||
{
|
||||
public static string function = "";
|
||||
public static List<string> ProcessedFiles = new List<string>();
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.Title = "PD_Tool";
|
||||
|
||||
if (args.Length == 0)
|
||||
{
|
||||
GC.Collect();
|
||||
while (function != "Q") MainMenu();
|
||||
Exit();
|
||||
}
|
||||
|
||||
string header;
|
||||
long header;
|
||||
Stream reader;
|
||||
KKdFARC Farc;
|
||||
|
||||
foreach (string arg in args)
|
||||
{
|
||||
Farc = new KKdFARC();
|
||||
if (MSIO.Directory.Exists(arg)) Farc.Pack(arg);
|
||||
else if (MSIO.File.Exists(arg) && MSIO.Path.GetExtension(arg) == ".farc") Farc.UnPack(arg, true);
|
||||
else if (MSIO.File.Exists(arg))
|
||||
if (Directory.Exists(arg)) new KKdFARC(arg, true).Pack();
|
||||
else if (File.Exists(arg) && Path.GetExtension(arg) == ".farc") new KKdFARC(arg).UnPack(true);
|
||||
else if (File.Exists(arg))
|
||||
{
|
||||
reader = File.OpenReader(arg);
|
||||
header = reader.ReadString(8);
|
||||
header = reader.ReadInt64();
|
||||
reader.Close();
|
||||
if (header.ToUpper() == "DIVAFILE") DIVAFILE.Decrypt(arg);
|
||||
if (header == 0x454C494641564944) KKdMainLib.DIVAFILE.Decrypt(arg);
|
||||
}
|
||||
}
|
||||
Exit();
|
||||
}
|
||||
|
||||
private static bool JSON = true;
|
||||
|
||||
private static void MainMenu()
|
||||
{
|
||||
Console.Title = "PD_Tool";
|
||||
@@ -57,7 +55,9 @@ namespace PD_Tool
|
||||
KKdMain.ConsoleDesign("4. Encrypt to DIVAFILE");
|
||||
KKdMain.ConsoleDesign("5. DB_Tools");
|
||||
KKdMain.ConsoleDesign("6. Converting Tools");
|
||||
KKdMain.ConsoleDesign(JSON ? "7. MsgPack to JSON" : "7. JSON to MsgPack");
|
||||
KKdMain.ConsoleDesign(false);
|
||||
KKdMain.ConsoleDesign(JSON ? "M. MessagePack" : "J. JSON");
|
||||
KKdMain.ConsoleDesign("Q. Quit");
|
||||
KKdMain.ConsoleDesign(false);
|
||||
KKdMain.ConsoleDesign(true);
|
||||
@@ -66,19 +66,20 @@ namespace PD_Tool
|
||||
function = Console.ReadLine().ToUpper();
|
||||
bool isNumber = int.TryParse(function, out int result);
|
||||
if (isNumber) Functions();
|
||||
if (function == "M") JSON = false;
|
||||
else if (function == "J") JSON = true ;
|
||||
}
|
||||
|
||||
private static void Functions()
|
||||
{
|
||||
Console.Clear();
|
||||
if (function == "1" || function == "2")
|
||||
FARC.Processor(function == "1");
|
||||
if (function == "1" || function == "2") FARC.Processor(function == "1");
|
||||
else if (function == "3" || function == "4")
|
||||
{
|
||||
KKdMain.Choose(1, "", out string[] FileNames);
|
||||
foreach (string FileName in FileNames) DIVAFILE.Decrypt(FileName);
|
||||
}
|
||||
else if (function == "5") DataBase.Processor();
|
||||
else if (function == "5") DataBase.Processor(JSON);
|
||||
else if (function == "6")
|
||||
{
|
||||
Console.Clear();
|
||||
@@ -86,26 +87,37 @@ namespace PD_Tool
|
||||
KKdMain.ConsoleDesign(true);
|
||||
KKdMain.ConsoleDesign(" Choose tool:");
|
||||
KKdMain.ConsoleDesign(false);
|
||||
KKdMain.ConsoleDesign("1. A3DA Converter");
|
||||
KKdMain.ConsoleDesign("2. DEX Converter");
|
||||
KKdMain.ConsoleDesign("3. DIVA Converter");
|
||||
KKdMain.ConsoleDesign("4. STR Converter");
|
||||
KKdMain.ConsoleDesign("5. VAG Converter");
|
||||
KKdMain.ConsoleDesign("1. A3DA Converter");
|
||||
KKdMain.ConsoleDesign("2. AET Converter");
|
||||
KKdMain.ConsoleDesign("3. DataBank Converter");
|
||||
KKdMain.ConsoleDesign("4. DEX Converter");
|
||||
KKdMain.ConsoleDesign("5. DIVA Converter");
|
||||
KKdMain.ConsoleDesign("6. STR Converter");
|
||||
KKdMain.ConsoleDesign("7. VAG Converter");
|
||||
KKdMain.ConsoleDesign(false);
|
||||
KKdMain.ConsoleDesign("R. Return to Main Menu");
|
||||
KKdMain.ConsoleDesign("Q. Quit");
|
||||
KKdMain.ConsoleDesign(false);
|
||||
KKdMain.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
string Function = Console.ReadLine();
|
||||
Console.Clear();
|
||||
if (Function == "1") Tools.A3D.Processor();
|
||||
else if (Function == "2") Tools.DEX.Processor();
|
||||
else if (Function == "3") Tools.DIV.Processor();
|
||||
else if (Function == "4") Tools.STR.Processor();
|
||||
else if (Function == "5") Tools.VAG.Processor();
|
||||
if (Function == "1") Tools.A3D.Processor(JSON);
|
||||
else if (Function == "2") Tools.AET.Processor(JSON);
|
||||
else if (Function == "3") Tools.DB .Processor(JSON);
|
||||
else if (Function == "4") Tools.DEX.Processor(JSON);
|
||||
else if (Function == "5") Tools.DIV.Processor();
|
||||
else if (Function == "6") Tools.STR.Processor(JSON);
|
||||
else if (Function == "7") Tools.VAG.Processor();
|
||||
else function = Function;
|
||||
}
|
||||
else if (function == "7")
|
||||
{
|
||||
KKdMain.Choose(1, JSON ? "mp" : "json", out string[] FileNames);
|
||||
if (JSON) foreach (string file in FileNames)
|
||||
KKdMainLib.MessagePack.MPExt.ToJSON (file.Replace(Path.GetExtension(file), ""));
|
||||
else foreach (string file in FileNames)
|
||||
KKdMainLib.MessagePack.MPExt.ToMsgPack(file.Replace(Path.GetExtension(file), ""));
|
||||
}
|
||||
}
|
||||
|
||||
public static void Exit() => Environment.Exit(0);
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
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")]
|
||||
[assembly: AssemblyCopyright("Copyright korenkonder © 2017-2019")]
|
||||
[assembly: AssemblyCopyright("korenkonder © 2017-2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
|
||||
[assembly: AssemblyVersion("0.4.5.7")]
|
||||
[assembly: AssemblyFileVersion("0.4.5.7")]
|
||||
[assembly: AssemblyVersion("0.4.6.2")]
|
||||
[assembly: AssemblyFileVersion("0.4.6.2")]
|
||||
|
||||
+77
-10
@@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.DB;
|
||||
using DB = KKdMainLib.DB;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
public class DataBase
|
||||
{
|
||||
public static void Processor()
|
||||
public static void Processor(bool JSON)
|
||||
{
|
||||
Console.Title = "DB Converter";
|
||||
Console.Clear();
|
||||
@@ -15,17 +15,23 @@ namespace PD_Tool
|
||||
Main.ConsoleDesign(" Choose type of DataBase file:");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("1. Auth DB Converter");
|
||||
Main.ConsoleDesign("2. AET DB Converter");
|
||||
Main.ConsoleDesign("3. SPR DB Converter");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("R. Return to Main Menu");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
string format = Console.ReadLine();
|
||||
if (format == "1") AuthDBProcessor();
|
||||
if (format == "1") AuthDBProcessor(JSON);
|
||||
if (format == "2") AETDBProcessor(JSON);
|
||||
if (format == "3") SPRDBProcessor(JSON);
|
||||
}
|
||||
|
||||
public static void AuthDBProcessor()
|
||||
public static void AuthDBProcessor(bool JSON)
|
||||
{
|
||||
Console.Title = "Auth DB Converter";
|
||||
Auth Auth = new Auth();
|
||||
DB.Auth Auth;
|
||||
Main.Choose(1, "bin", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
@@ -33,21 +39,82 @@ namespace PD_Tool
|
||||
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
Console.Title = "Auth: DB Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
Auth = new Auth();
|
||||
Console.Title = "Auth DB Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
Auth = new DB.Auth();
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
filepath = file.Replace(Path.GetExtension(file), "");
|
||||
|
||||
if (ext == ".bin")
|
||||
{
|
||||
Auth.BINReader (filepath);
|
||||
Auth.MsgPackWriter(filepath);
|
||||
Auth.MsgPackWriter(filepath, JSON);
|
||||
}
|
||||
else if (ext == ".mp")
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
{
|
||||
Auth.MsgPackReader(filepath);
|
||||
Auth.MsgPackReader(filepath, ext == ".json");
|
||||
Auth.BINWriter (filepath);
|
||||
}
|
||||
Auth = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void AETDBProcessor(bool JSON)
|
||||
{
|
||||
Console.Title = "AET DB Converter";
|
||||
DB.Aet Aet;
|
||||
Main.Choose(1, "bin", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
Console.Title = "AET DB Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
Aet = new DB.Aet();
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
filepath = file.Replace(Path.GetExtension(file), "");
|
||||
|
||||
if (ext == ".bin")
|
||||
{
|
||||
Aet.BINReader (filepath);
|
||||
Aet.MsgPackWriter(filepath, JSON);
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
{
|
||||
Aet.MsgPackReader(filepath, ext == ".json");
|
||||
Aet.BINWriter (filepath);
|
||||
}
|
||||
Aet = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SPRDBProcessor(bool JSON)
|
||||
{
|
||||
Console.Title = "SPR DB Converter";
|
||||
DB.Spr Spr;
|
||||
Main.Choose(1, "bin", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
Console.Title = "SPR DB Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
Spr = new DB.Spr();
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
filepath = file.Replace(Path.GetExtension(file), "");
|
||||
|
||||
if (ext == ".bin")
|
||||
{
|
||||
Spr.BINReader (filepath);
|
||||
Spr.MsgPackWriter(filepath, JSON);
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
{
|
||||
Spr.MsgPackReader(filepath, ext == ".json");
|
||||
Spr.BINWriter (filepath);
|
||||
}
|
||||
Spr = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+28
-10
@@ -17,7 +17,7 @@ namespace PD_Tool
|
||||
Main.Choose(1, "farc", out string[] FileNames);
|
||||
foreach (string FileName in FileNames)
|
||||
if (FileName != "" && File.Exists(FileName))
|
||||
FARC.UnPack(FileName);
|
||||
new KKdFARC(FileName).UnPack();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -26,27 +26,45 @@ namespace PD_Tool
|
||||
Console.Title = "FARC Creator";
|
||||
if (file != "")
|
||||
{
|
||||
FARC = new KKdFARC();
|
||||
Main.ConsoleDesign(true);
|
||||
Main.ConsoleDesign(" Choose type of created FARC:");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("1. FArc [DT/DT2nd/DTex/F/F2nd/X]");
|
||||
Main.ConsoleDesign("2. FArC [DT/DT2nd/DTex/F/F2nd/X] (Compressed)");
|
||||
Main.ConsoleDesign("3. FARC [F/F2nd/X] (Compressed)");
|
||||
Main.ConsoleDesign("4. FARC [FT] (Compressed)");
|
||||
Main.ConsoleDesign("3. FARC [F/F2nd/X]");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("Note: Creating FT FARCs currently not supported.");
|
||||
Main.ConsoleDesign("R. Return to Main Menu");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Choosed folder: {0}", file);
|
||||
Console.WriteLine();
|
||||
int.TryParse(Console.ReadLine(), out int type);
|
||||
if (type == 1) FARC.Signature = KKdFARC.Farc.FArc;
|
||||
else if (type == 3) FARC.Signature = KKdFARC.Farc.FARC;
|
||||
else FARC.Signature = KKdFARC.Farc.FArC;
|
||||
Console.Clear();
|
||||
string type = Console.ReadLine().ToUpper();
|
||||
if (type == "1") FARC.Signature = KKdFARC.Farc.FArc;
|
||||
else if (type == "3" || type == "4")
|
||||
{
|
||||
FARC.Signature = KKdFARC.Farc.FARC;
|
||||
|
||||
Console.WriteLine();
|
||||
Main.ConsoleDesign(true);
|
||||
Main.ConsoleDesign(" Choose type of FARC:");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("1. FARC");
|
||||
Main.ConsoleDesign("2. FARC (Compressed)");
|
||||
Main.ConsoleDesign("3. FARC (Encrypted)");
|
||||
Main.ConsoleDesign("4. FARC (Compressed & Encrypted)");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
type = Console.ReadLine();
|
||||
if (type == "2" || type == "4") FARC.FARCType |= KKdFARC.Type.GZip;
|
||||
if (type == "3" || type == "4") FARC.FARCType |= KKdFARC.Type.ECB ;
|
||||
}
|
||||
else if (type == "R") return;
|
||||
else FARC.Signature = KKdFARC.Farc.FArC;
|
||||
Console.Title = "FARC Creator - Directory: " + Path.GetDirectoryName(file);
|
||||
FARC.Pack(file);
|
||||
new KKdFARC(file, true).Pack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
using MSIO = System.IO;
|
||||
using KKdA3DA = KKdMainLib.A3DA.A3DA;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
{
|
||||
class A3D
|
||||
{
|
||||
public static void Processor()
|
||||
public static void Processor(bool JSON)
|
||||
{
|
||||
Console.Title = "A3DA Converter";
|
||||
Main.Choose(1, "a3da", out string[] FileNames);
|
||||
@@ -16,67 +15,66 @@ 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; }
|
||||
if (file.EndsWith(".mp" )) { MP = true; break; }
|
||||
else if (file.EndsWith(".json")) { 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;
|
||||
foreach (string file in FileNames)
|
||||
try
|
||||
{
|
||||
ext = MSIO.Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
Console.Title = "A3DA Converter: " +
|
||||
MSIO.Path.GetFileNameWithoutExtension(file);
|
||||
A = new KKdA3DA();
|
||||
if (ext == ".a3da")
|
||||
{
|
||||
A.A3DAReader (filepath);
|
||||
A.MsgPackWriter(filepath);
|
||||
}
|
||||
else if (ext == ".mp" )
|
||||
{
|
||||
A.MsgPackReader(filepath);
|
||||
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 = new KKdA3DA();
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
|
||||
if (A.Data.Header.Format > Main.Format.DT && A.Data.Header.Format != Main.Format.FT)
|
||||
A.A3DCWriter(filepath);
|
||||
else
|
||||
A.A3DAWriter();
|
||||
}
|
||||
Console.Title = "A3DA Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".a3da")
|
||||
{
|
||||
A.A3DAReader (filepath);
|
||||
A.MsgPackWriter(filepath, JSON);
|
||||
}
|
||||
catch (Exception e)
|
||||
{ Console.WriteLine(e); }
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
{
|
||||
A.MsgPackReader(filepath, ext == ".json");
|
||||
A.IO = File.OpenWriter(filepath + ".a3da", true);
|
||||
A.Data._.CompressF16 = A.Data.Header.Format > Main.Format.FT ? Format == Main.Format.MGF ? 2 : 1 : 0;
|
||||
A.Data.Header.Format = Format;
|
||||
|
||||
if (format != "1" && format != "3") A.A3DCWriter(filepath);
|
||||
else A.A3DAWriter();
|
||||
}
|
||||
A = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdAet = KKdMainLib.Aet.Aet;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
{
|
||||
public class AET
|
||||
{
|
||||
public static void Processor(bool JSON)
|
||||
{
|
||||
Console.Title = "AET Converter";
|
||||
KKdAet Aet;
|
||||
Main.Choose(1, "bin", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
Aet = new KKdAet();
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
|
||||
Console.Title = "AET Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".bin")
|
||||
{
|
||||
Aet. AETReader(filepath);
|
||||
Aet.MsgPackWriter(filepath, JSON);
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
{
|
||||
Aet.MsgPackReader(filepath, ext == ".json");
|
||||
Aet. AETWriter(filepath);
|
||||
}
|
||||
Aet = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
{
|
||||
public class DB
|
||||
{
|
||||
public static void Processor(bool JSON)
|
||||
{
|
||||
Console.Title = "DataBank Converter";
|
||||
Main.Choose(1, "databank", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
bool MP = true;
|
||||
foreach (string file in FileNames)
|
||||
if (file.EndsWith(".mp" )) { MP = false; break; }
|
||||
else if (file.EndsWith(".json")) { MP = false; break; }
|
||||
|
||||
string format = "1";
|
||||
if (MP)
|
||||
{
|
||||
Console.Clear();
|
||||
Main.ConsoleDesign(true);
|
||||
Main.ConsoleDesign(" Choose type of exporting file:");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("1. Compact");
|
||||
Main.ConsoleDesign("2. Normal");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
format = Console.ReadLine();
|
||||
}
|
||||
|
||||
DataBank DB;
|
||||
string[] file_split;
|
||||
int File_Checksum = 0, Get_Checksum;
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
|
||||
string filename = Path.GetFileNameWithoutExtension(file);
|
||||
file_split = filename.Split('_');
|
||||
DB = new DataBank();
|
||||
if (file_split.Length == 5 && ext == ".dat" && MP)
|
||||
{
|
||||
if (!int.TryParse(file_split[3], out File_Checksum)) continue;
|
||||
|
||||
Get_Checksum = DCC.CalculateChecksum(file);
|
||||
if (File_Checksum != Get_Checksum) continue;
|
||||
|
||||
filepath = file.Replace(filename + ".dat", "");
|
||||
Console.Title = "DataBank Converter: " + filename;
|
||||
DB. DBReader(file);
|
||||
DB.MsgPackWriter(filepath + file_split[0] + "_" +
|
||||
file_split[1] + "_" + file_split[2], JSON, format != "2");
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json" && !MP)
|
||||
{
|
||||
Console.Title = "DataBank Converter: " + filename;
|
||||
DB.MsgPackReader(filepath, JSON);
|
||||
DB. DBWriter(filepath);
|
||||
}
|
||||
DB = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using MSIO = System.IO;
|
||||
using KKdMainLib.IO;
|
||||
using KKdDEX = KKdMainLib.DEX;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
{
|
||||
public class DEX
|
||||
{
|
||||
public static void Processor()
|
||||
public static void Processor(bool JSON)
|
||||
{
|
||||
Console.Title = "DEX Converter";
|
||||
KKdDEX DEX;
|
||||
@@ -16,10 +16,13 @@ namespace PD_Tool.Tools
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
bool MP = true;
|
||||
bool MP = true;
|
||||
bool _JSON = true;
|
||||
foreach (string file in FileNames)
|
||||
if (file.EndsWith(".mp" ))
|
||||
{ MP = false; break; }
|
||||
{ MP = false; break; }
|
||||
else if (file.EndsWith(".json"))
|
||||
{ _JSON = false; break; }
|
||||
|
||||
Console.Clear();
|
||||
string format = "";
|
||||
@@ -29,7 +32,8 @@ namespace PD_Tool.Tools
|
||||
Main.ConsoleDesign("1. F/FT PS3/PS4/PSVita");
|
||||
Main.ConsoleDesign("2. F2nd PS3/PSVita");
|
||||
Main.ConsoleDesign("3. X PS4/PSVita");
|
||||
if (MP) Main.ConsoleDesign("9. MessagePack");
|
||||
if ( MP && !JSON) Main.ConsoleDesign("9. MessagePack");
|
||||
if (_JSON && JSON) Main.ConsoleDesign("9. JSON");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
@@ -39,22 +43,25 @@ namespace PD_Tool.Tools
|
||||
if (format == "1") Format = Main.Format.F ;
|
||||
else if (format == "2") Format = Main.Format.F2LE;
|
||||
else if (format == "3") Format = Main.Format.X ;
|
||||
else if (format == "9" && MP ) Format = Main.Format.NULL;
|
||||
else if (format == "9" && (MP && _JSON)) Format = Main.Format.NULL;
|
||||
else return;
|
||||
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
DEX = new KKdDEX();
|
||||
ext = MSIO.Path.GetExtension(file).ToLower();
|
||||
filepath = file.Replace(MSIO.Path.GetExtension(file), "");
|
||||
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
|
||||
Console.Title = "DEX Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".bin" || ext == ".dex")
|
||||
DEX.DEXReader(filepath, ext);
|
||||
else DEX.MsgPackReader(filepath);
|
||||
DEX. DEXReader(filepath, ext );
|
||||
else DEX.MsgPackReader(filepath, JSON);
|
||||
|
||||
if (Format > Main.Format.NULL)
|
||||
DEX.DEXWriter(filepath, Format);
|
||||
else DEX.MsgPackWriter(filepath);
|
||||
DEX. DEXWriter(filepath, Format);
|
||||
else DEX.MsgPackWriter(filepath, JSON );
|
||||
DEX = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,28 +11,23 @@ namespace PD_Tool.Tools
|
||||
{
|
||||
Console.Title = "DIVA Converter";
|
||||
Main.Choose(1, "diva", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
DIVA DIVA;
|
||||
foreach (string file in FileNames)
|
||||
try
|
||||
{
|
||||
string filepath = file.Replace(Path.GetExtension(file), "");
|
||||
string ext = Path.GetExtension(file);
|
||||
Console.Title = "DIVA Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
DIVA = new DIVA(filepath);
|
||||
switch (ext.ToLower())
|
||||
{
|
||||
case ".diva":
|
||||
DIVA.DIVAReader();
|
||||
break;
|
||||
case ".wav":
|
||||
DIVA.DIVAWriter();
|
||||
break;
|
||||
}
|
||||
GC.Collect();
|
||||
}
|
||||
catch (Exception e) { Console.WriteLine(e.Message); }
|
||||
{
|
||||
DIVA = new DIVA();
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
|
||||
Console.Title = "DIVA Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".diva") DIVA.DIVAReader(filepath);
|
||||
else if (ext == ".wav" ) DIVA.DIVAWriter(filepath);
|
||||
DIVA = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMot = KKdMainLib.Mot;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
{
|
||||
public class MOT
|
||||
{
|
||||
public static void Processor(bool JSON)
|
||||
{
|
||||
Console.Title = "MOT Converter";
|
||||
KKdMot Mot;
|
||||
Main.Choose(1, "bin", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
Mot = new KKdMot();
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
|
||||
Console.Title = "MOT Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".bin") Mot.MOTReader(filepath, JSON);
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
{
|
||||
//Mot.MsgPackReader(filepath, ext == ".json");
|
||||
//Mot. AETWriter(filepath);
|
||||
}
|
||||
Mot = new KKdMot();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using MSIO = System.IO;
|
||||
using KKdMainLib.IO;
|
||||
using KKdSTR = KKdMainLib.STR;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
{
|
||||
public class STR
|
||||
{
|
||||
public static void Processor()
|
||||
public static void Processor(bool JSON)
|
||||
{
|
||||
Console.Title = "STR Converter";
|
||||
Main.Choose(1, "str", out string[] FileNames);
|
||||
@@ -17,22 +17,24 @@ namespace PD_Tool.Tools
|
||||
string ext = "";
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
filepath = file.Replace(MSIO.Path.GetExtension(file), "");
|
||||
ext = MSIO.Path.GetExtension(file).ToLower();
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
Data = new KKdSTR();
|
||||
|
||||
Console.Title = "PD_Tool: Converter Tools: STR Reader: " +
|
||||
MSIO.Path.GetFileNameWithoutExtension(file);
|
||||
Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".str" || ext == ".bin")
|
||||
{
|
||||
Data.STRReader (filepath, ext);
|
||||
Data.MsgPackWriter(filepath);
|
||||
Data.MsgPackWriter(filepath, JSON);
|
||||
}
|
||||
else if (ext == ".mp")
|
||||
{
|
||||
Data.MsgPackReader(filepath);
|
||||
Data.MsgPackReader(filepath, JSON);
|
||||
Data.STRWriter (filepath);
|
||||
}
|
||||
Data = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@ namespace PD_Tool.Tools
|
||||
{
|
||||
Console.Title = "VAG Converter";
|
||||
Main.Choose(1, "vag", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
bool InputWAV = false;
|
||||
foreach (string file in FileNames)
|
||||
if (Path.GetExtension(file) == ".wav")
|
||||
@@ -34,26 +38,17 @@ namespace PD_Tool.Tools
|
||||
|
||||
KKdVAG VAG;
|
||||
foreach (string file in FileNames)
|
||||
try
|
||||
{
|
||||
string ext = Path.GetExtension(file);
|
||||
string filepath = file.Remove(file.Length - ext.Length);
|
||||
Console.Title = "VAG Converter: " +
|
||||
Path.GetFileNameWithoutExtension(file);
|
||||
VAG = new KKdVAG() { file = filepath };
|
||||
switch (ext.ToLower())
|
||||
{
|
||||
case ".vag":
|
||||
VAG.VAGReader();
|
||||
VAG.WAVWriter();
|
||||
break;
|
||||
case ".wav":
|
||||
VAG.WAVReader();
|
||||
VAG.VAGWriter(HE_VAG);
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception e) { Console.WriteLine(e.Message); }
|
||||
{
|
||||
VAG = new KKdVAG();
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
|
||||
Console.Title = "VAG Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".vag") { VAG.VAGReader(filepath); VAG.WAVWriter(filepath ); }
|
||||
else if (ext == ".wav") { VAG.WAVReader(filepath); VAG.VAGWriter(filepath, HE_VAG); }
|
||||
VAG = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,14 @@ A simple tool for working with Project Diva DT/FT/F/F2/X files
|
||||
- `FARC Extract/Create`
|
||||
- `DIVAFILE Encrypt/Decrypt`
|
||||
- `DB_Tools`
|
||||
- `Aet DB Converter`
|
||||
- `Auth DB Converter`
|
||||
- `Spr DB Converter`
|
||||
- `Converting Tools`
|
||||
- `A3DA Converter`
|
||||
- `DataBank Converter`
|
||||
- `DEX Converter`
|
||||
- `DIVA Converter`
|
||||
- `STR Converter`
|
||||
- `VAG Converter`
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user