Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f883c4c77 | ||
|
|
0863721dc4 |
File diff suppressed because it is too large
Load Diff
@@ -1,507 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.Types;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.A3DA
|
||||
{
|
||||
public static class A3DAExt
|
||||
{
|
||||
private const string d = ".";
|
||||
private const string BO = "bin_offset";
|
||||
private const string MTBO = "model_transform" + d + BO;
|
||||
|
||||
private static string value;
|
||||
private static string[] dataArray;
|
||||
private static int SOi;
|
||||
private static int[] SO;
|
||||
|
||||
public static ModelTransform ReadMT(this Dictionary<string, object> Dict, string Temp)
|
||||
{
|
||||
ModelTransform MT = new ModelTransform();
|
||||
Dict.FindValue(out MT.BinOffset, Temp + MTBO);
|
||||
|
||||
MT.Rot = Dict.ReadVec3(Temp + "rot" + d);
|
||||
MT.Scale = Dict.ReadVec3(Temp + "scale" + d);
|
||||
MT.Trans = Dict.ReadVec3(Temp + "trans" + d);
|
||||
MT.Visibility = Dict.ReadKey (Temp + "visibility" + d);
|
||||
return MT;
|
||||
}
|
||||
|
||||
public static RGBAKey ReadRGBAKey(this Dictionary<string, object> Dict, string Temp) =>
|
||||
new RGBAKey { A = Dict.ReadKey(Temp + "a" + d), B = Dict.ReadKey(Temp + "b" + d),
|
||||
G = Dict.ReadKey(Temp + "g" + d), R = Dict.ReadKey(Temp + "r" + d) };
|
||||
|
||||
public static Vector3<Key> ReadVec3(this Dictionary<string, object> Dict, string Temp) =>
|
||||
new Vector3<Key> { X = Dict.ReadKey(Temp + "x" + d), Y =
|
||||
Dict.ReadKey(Temp + "y" + d), Z = Dict.ReadKey(Temp + "z" + d) };
|
||||
|
||||
public static KeyUV ReadKeyUV(this Dictionary<string, object> Dict, string Temp) =>
|
||||
new KeyUV { U = Dict.ReadKey(Temp + "U" + d), V = Dict.ReadKey(Temp + "V" + d) };
|
||||
|
||||
public static Key ReadKey(this Dictionary<string, object> Dict, string Temp)
|
||||
{
|
||||
Key Key = new Key();
|
||||
Dict.FindValue(out Key.BinOffset, Temp + BO );
|
||||
Dict.FindValue(out Key.Type , Temp + "type");
|
||||
|
||||
if (Key.BinOffset == null && Key.Type == null) return null;
|
||||
if (Key.Type == null) return Key;
|
||||
if (Key.Type == 0x0000) return Key;
|
||||
|
||||
if (Key.Type == 0x0001) { Dict.FindValue(out Key.Value, Temp + "value"); return Key; }
|
||||
|
||||
int i = 0, i0 = 0;
|
||||
Dict.FindValue(out Key.EPTypePost, Temp + "ep_type_post");
|
||||
Dict.FindValue(out Key.EPTypePre , Temp + "ep_type_pre" );
|
||||
Dict.FindValue(out Key.Length , Temp + "key.length" );
|
||||
Dict.FindValue(out Key.Max , Temp + "max" );
|
||||
if (Dict.StartsWith(Temp + "raw_data"))
|
||||
Dict.FindValue(out Key.RawData.KeyType, Temp + "raw_data_key_type");
|
||||
|
||||
if (Key.Length != null)
|
||||
{
|
||||
int Type;
|
||||
Key.Trans = new IKeyFrame<double, double>[(int)Key.Length];
|
||||
for (i0 = 0; i0 < Key.Length; i0++)
|
||||
if (Dict.FindValue(out value, Temp + "key" + d + i0 + d + "data"))
|
||||
{
|
||||
dataArray = value.Replace("(", "").Replace(")", "").Split(',');
|
||||
Type = dataArray.Length - 1;
|
||||
if (Type == 0) Key.Trans[i0] = new KeyFrameT0<double, double>
|
||||
{ Frame = dataArray[0].ToDouble() };
|
||||
else if (Type == 1) Key.Trans[i0] = new KeyFrameT1<double, double>
|
||||
{ Frame = dataArray[0].ToDouble(), Value = dataArray[1].ToDouble() };
|
||||
else if (Type == 2) Key.Trans[i0] = new KeyFrameT2<double, double>
|
||||
{ Frame = dataArray[0].ToDouble(), Value = dataArray[1].ToDouble(),
|
||||
Interpolation = dataArray[2].ToDouble() };
|
||||
else if (Type == 3) Key.Trans[i0] = new KeyFrameT3<double, double>
|
||||
{ Frame = dataArray[0].ToDouble(), Value = dataArray[1].ToDouble(),
|
||||
Interpolation1 = dataArray[2].ToDouble(),
|
||||
Interpolation2 = dataArray[3].ToDouble() };
|
||||
Key.Trans[i0] = Key.Trans[i0].Check();
|
||||
}
|
||||
}
|
||||
else if (Key.RawData.KeyType != null)
|
||||
{
|
||||
Dict.FindValue(out Key.RawData.ValueType, Temp + "raw_data.value_type");
|
||||
if (Dict.FindValue(out value, Temp + "raw_data.value_list"))
|
||||
Key.RawData.ValueList = value.Split(',');
|
||||
Dict.FindValue(out Key.RawData.ValueListSize, Temp + "raw_data.value_list_size");
|
||||
value = "";
|
||||
|
||||
int DS = (int)Key.RawData.KeyType + 1;
|
||||
Key.Length = Key.RawData.ValueListSize / DS;
|
||||
Key.Trans = new 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;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ModelTransform MT,
|
||||
string Temp, bool A3DC, bool IsX = false, byte Flags = 0b11111)
|
||||
{
|
||||
if (A3DC && !MT.Writed && (Flags & 0b10000) == 0b10000)
|
||||
{ IO.Write(Temp + MTBO + "=", MT.BinOffset); MT.Writed = true; }
|
||||
|
||||
if (A3DC && !IsX) return;
|
||||
|
||||
if ((Flags & 0b01000) == 0b01000) IO.Write(MT.Rot , Temp + "rot" + d, A3DC);
|
||||
if ((Flags & 0b00100) == 0b00100) IO.Write(MT.Scale , Temp + "scale" + d, A3DC);
|
||||
if ((Flags & 0b00010) == 0b00010) IO.Write(MT.Trans , Temp + "trans" + d, A3DC);
|
||||
if ((Flags & 0b00001) == 0b00001) IO.Write(MT.Visibility, Temp + "visibility" + d, A3DC);
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, RGBAKey RGBA, string Temp, string Data, bool A3DC = false)
|
||||
{
|
||||
if (RGBA.R == null && RGBA.B == null && RGBA.G == null && RGBA.A == null) return;
|
||||
IO.Write(Temp + Data + "=", "true");
|
||||
IO.Write(RGBA.A, Temp + Data + d + "a" + d, A3DC);
|
||||
IO.Write(RGBA.B, Temp + Data + d + "b" + d, A3DC);
|
||||
IO.Write(RGBA.G, Temp + Data + d + "g" + d, A3DC);
|
||||
IO.Write(RGBA.R, Temp + Data + d + "r" + d, A3DC);
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, Vector3<Key> Key, string Temp, bool A3DC = false)
|
||||
{ IO.Write(Key.X, Temp + "x" + d, A3DC); IO.Write(Key.Y,
|
||||
Temp + "y" + d, A3DC); IO.Write(Key.Z, Temp + "z" + d, A3DC); }
|
||||
|
||||
public static void Write(this Stream IO, KeyUV UV, string Temp, string Data, bool A3DC = false)
|
||||
{ IO.Write(UV.U, Temp, Data + "U", A3DC); IO.Write(UV.V, Temp, Data + "V", A3DC); }
|
||||
|
||||
public static void Write(this Stream IO, Key Key, string Temp, string Data, bool A3DC = false)
|
||||
{ if (Key != null) { IO.Write(Temp + Data + "=", "true"); IO.Write(Key, Temp + Data + d, A3DC); } }
|
||||
|
||||
public static void Write(this Stream IO, Key Key, string Temp, bool A3DC = false)
|
||||
{
|
||||
if (Key == null) return;
|
||||
|
||||
if (A3DC) { IO.Write(Temp + BO + "=", Key.BinOffset); return; }
|
||||
|
||||
int i = 0;
|
||||
if (Key.Trans != null)
|
||||
if (Key.Trans.Length == 0)
|
||||
{
|
||||
IO.Write(Temp + "type=", Key.Type);
|
||||
if (Key.Type > 0) IO.Write(Temp + "value=", Key.Value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Key.EPTypePost != null) IO.Write(Temp + "ep_type_post=", Key.EPTypePost);
|
||||
if (Key.EPTypePre != null) IO.Write(Temp + "ep_type_pre=" , Key.EPTypePre );
|
||||
if (Key.RawData.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());
|
||||
if (Key.Trans[SOi] is KeyFrameT0<double, double>)
|
||||
IO.Write(Temp + "key" + d + SOi + d + "type=", 0);
|
||||
else if (Key.Trans[SOi] is KeyFrameT1<double, double>)
|
||||
IO.Write(Temp + "key" + d + SOi + d + "type=", 1);
|
||||
else if (Key.Trans[SOi] is KeyFrameT2<double, double>)
|
||||
IO.Write(Temp + "key" + d + SOi + d + "type=", 2);
|
||||
else if (Key.Trans[SOi] is KeyFrameT3<double, double>)
|
||||
IO.Write(Temp + "key" + d + SOi + d + "type=", 3);
|
||||
}
|
||||
IO.Write(Temp + "key.length=", Key.Length);
|
||||
if (Key.Max != null) IO.Write(Temp + "max=", Key.Max);
|
||||
}
|
||||
else if (Key.Trans != null)
|
||||
{
|
||||
Key.RawData.KeyType = 0;
|
||||
if (Key.Max != null) IO.Write(Temp + "max=", Key.Max);
|
||||
for (i = 0; i < Key.Trans.Length; i++)
|
||||
{
|
||||
if (Key.Trans[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=");
|
||||
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);
|
||||
IO.Write(Temp + "raw_data.value_type=" , Key.RawData.ValueType );
|
||||
IO.Write(Temp + "raw_data_key_type=" , Key.RawData. KeyType );
|
||||
}
|
||||
IO.Write(Temp + "type=", Key.Type & 0xFF);
|
||||
if (Key.RawData.KeyType == null && Key.Trans == null && Key.Value != null)
|
||||
if (Key.Value != 0) IO.Write(Temp + "value=", Key.Value);
|
||||
}
|
||||
|
||||
public static void ReadMT(this Stream IO, ref ModelTransform MT, int C_F16)
|
||||
{
|
||||
if (MT.BinOffset == null) return;
|
||||
|
||||
IO.Position = (int)MT.BinOffset;
|
||||
|
||||
IO.ReadOffset(out MT.Scale);
|
||||
IO.ReadOffset(out MT.Rot );
|
||||
IO.ReadOffset(out MT.Trans);
|
||||
MT.Visibility = new Key { BinOffset = IO.ReadInt32() };
|
||||
|
||||
IO.ReadVec3(ref MT.Scale , C_F16);
|
||||
IO.ReadVec3(ref MT.Rot , C_F16, true);
|
||||
IO.ReadVec3(ref MT.Trans , C_F16);
|
||||
IO.ReadKey (ref MT.Visibility, C_F16);
|
||||
}
|
||||
|
||||
public static void ReadRGBAKey(this Stream IO, ref RGBAKey RGBA, int C_F16)
|
||||
{ IO.ReadKey(ref RGBA.R, C_F16); IO.ReadKey(ref RGBA.G, C_F16);
|
||||
IO.ReadKey(ref RGBA.B, C_F16); IO.ReadKey(ref RGBA.A, C_F16); }
|
||||
|
||||
public static void ReadVec3(this Stream IO, ref Vector3<Key> Key, int C_F16, bool F16 = false)
|
||||
{ IO.ReadKey(ref Key.X, C_F16, F16); IO.ReadKey(ref Key.Y,
|
||||
C_F16, F16); IO.ReadKey(ref Key.Z, C_F16, F16); }
|
||||
|
||||
public static void ReadKeyUV(this Stream IO, ref KeyUV UV, int C_F16)
|
||||
{ IO.ReadKey(ref UV.U, C_F16); IO.ReadKey(ref UV.V, C_F16); }
|
||||
|
||||
public static void ReadKey(this Stream IO, ref Key Key, int C_F16, bool F16 = false)
|
||||
{
|
||||
if (Key == null) return;
|
||||
if (Key.BinOffset == null || Key.BinOffset < 0) return;
|
||||
|
||||
IO.Position = (int)Key.BinOffset;
|
||||
Key.Type = IO.ReadInt32();
|
||||
|
||||
Key.Value = IO.ReadSingle();
|
||||
if (Key.Type == 0x0000 || Key.Type == 0x0001) return;
|
||||
Key.Max = IO.ReadSingle();
|
||||
Key.Length = IO.ReadInt32 ();
|
||||
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++)
|
||||
{
|
||||
Temp = new KeyFrameT3<double, double>();
|
||||
if (F16 && C_F16 > 0)
|
||||
{ Temp.Frame = IO.ReadUInt16(); Temp.Value = (double)IO.ReadHalf (); }
|
||||
else
|
||||
{ Temp.Frame = IO.ReadSingle(); Temp.Value = IO.ReadSingle(); }
|
||||
|
||||
if (F16 && C_F16 == 2)
|
||||
{ Temp.Interpolation1 = (double)IO.ReadHalf ();
|
||||
Temp.Interpolation2 = (double)IO.ReadHalf (); }
|
||||
else
|
||||
{ Temp.Interpolation1 = IO.ReadSingle();
|
||||
Temp.Interpolation2 = IO.ReadSingle(); }
|
||||
|
||||
Key.Trans[i] = Temp.Check();
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReadOffset(this Stream IO, out Vector3<Key> Key)
|
||||
{ Key = new Vector3<Key> { X = new Key { BinOffset = IO.ReadInt32() },
|
||||
Y = new Key { BinOffset = IO.ReadInt32() },
|
||||
Z = new Key { BinOffset = IO.ReadInt32() }, }; }
|
||||
|
||||
public static void WriteOffset(this Stream IO, ref ModelTransform MT, bool ReturnToOffset)
|
||||
{
|
||||
if (ReturnToOffset)
|
||||
{
|
||||
IO.Position = (int)MT.BinOffset;
|
||||
IO.WriteOffset(MT.Scale);
|
||||
IO.WriteOffset(MT.Rot );
|
||||
IO.WriteOffset(MT.Trans);
|
||||
IO.Write(MT.Visibility.BinOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
MT.BinOffset = IO.Position;
|
||||
IO.Position += 0x30;
|
||||
IO.Length += 0x30;
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteOffset(this Stream IO, Vector3<Key> Key)
|
||||
{
|
||||
IO.Write(Key.X.BinOffset);
|
||||
IO.Write(Key.Y.BinOffset);
|
||||
IO.Write(Key.Z.BinOffset);
|
||||
}
|
||||
|
||||
public static ModelTransform ReadMT(this MsgPack k, string name)
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadMT(); return new ModelTransform(); }
|
||||
|
||||
public static ModelTransform ReadMT(this MsgPack k) =>
|
||||
new ModelTransform { Rot = k.ReadVec3("Rot" ), Scale = k.ReadVec3("Scale" ),
|
||||
Trans = k.ReadVec3("Trans"), Visibility = k.ReadKey ("Visibility") };
|
||||
|
||||
public static RGBAKey ReadRGBAKey(this MsgPack k, string name)
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadRGBAKey(); return new RGBAKey(); }
|
||||
|
||||
public static RGBAKey ReadRGBAKey(this MsgPack k) =>
|
||||
new RGBAKey { R = k.ReadKey("R"), G = k.ReadKey("G"), B = k.ReadKey("B"), A = k.ReadKey("A") };
|
||||
|
||||
public static Vector3<Key> ReadVec3(this MsgPack k, string name)
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadVec3(); return new Vector3<Key>(); }
|
||||
|
||||
public static Vector3<Key> ReadVec3(this MsgPack k) =>
|
||||
new Vector3<Key> { X = k.ReadKey("X"), Y = k.ReadKey("Y"), Z = k.ReadKey("Z") };
|
||||
|
||||
public static KeyUV ReadKeyUV(this MsgPack k, string name)
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadKeyUV(); return new KeyUV(); }
|
||||
|
||||
public static KeyUV ReadKeyUV(this MsgPack k) =>
|
||||
new KeyUV { U = k.ReadKey("U"), V = k.ReadKey("V") };
|
||||
|
||||
public static Key ReadKey(this MsgPack k, string name)
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadKey(); return null; }
|
||||
|
||||
public static Key ReadKey(this MsgPack k)
|
||||
{
|
||||
if (k.Object == null) return null;
|
||||
|
||||
Key Key = new Key { EPTypePost = k.ReadNInt32("EPTypePost"),
|
||||
EPTypePre = k.ReadNInt32("EPTypePre"), Max = k.ReadNDouble("Max"),
|
||||
Type = k.ReadNInt32("Type"), Value = k.ReadNDouble("Value") };
|
||||
if (k.ReadBoolean("RawData")) Key.RawData = new Key.RawD() { KeyType = -1, ValueType = "float" };
|
||||
if (Key.Type == 0) Key.Value = 0.0;
|
||||
|
||||
if (Key.Type < 2) return Key;
|
||||
|
||||
if (!k.ElementArray("Trans", out MsgPack Trans)) return Key;
|
||||
|
||||
Key.Length = Trans.Array.Length;
|
||||
Key.Trans = new IKeyFrame<double, double>[Key.Length.Value];
|
||||
for (int i = 0; i < Key.Length; i++)
|
||||
{
|
||||
if (Trans[i].Array == null) continue;
|
||||
else if (Trans[i].Array.Length == 0) continue;
|
||||
else if (Trans[i].Array.Length == 1)
|
||||
Key.Trans[i] = new KeyFrameT0<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 Add(this MsgPack MsgPack, ModelTransform MT) =>
|
||||
MsgPack.Add("Rot" , MT.Rot )
|
||||
.Add("Scale" , MT.Scale )
|
||||
.Add("Trans" , MT.Trans )
|
||||
.Add("Visibility", MT.Visibility);
|
||||
|
||||
public static MsgPack Add(this MsgPack MsgPack, string name, ModelTransform MT) =>
|
||||
MsgPack.Add(new MsgPack(name).Add("Rot" , MT.Rot )
|
||||
.Add("Scale" , MT.Scale )
|
||||
.Add("Trans" , MT.Trans )
|
||||
.Add("Visibility", MT.Visibility));
|
||||
|
||||
public static MsgPack Add(this MsgPack MsgPack, string name, RGBAKey RGBA) =>
|
||||
(RGBA.R == null && RGBA.G == null && RGBA.B == null && RGBA.A == null) ? MsgPack :
|
||||
MsgPack.Add(new MsgPack(name).Add("R", RGBA.R).Add("G", RGBA.G)
|
||||
.Add("B", RGBA.B).Add("A", RGBA.A));
|
||||
|
||||
public static MsgPack Add(this MsgPack MsgPack, string name, Vector3<Key> Key) =>
|
||||
MsgPack.Add(new MsgPack(name).Add("X", Key.X).Add("Y", Key.Y).Add("Z", Key.Z));
|
||||
|
||||
public static MsgPack Add(this MsgPack MsgPack, string name, KeyUV UV) =>
|
||||
(UV.U == null && UV.V == null) ? MsgPack :
|
||||
MsgPack.Add(new MsgPack(name).Add("U", UV.U).Add("V", UV.V));
|
||||
|
||||
public static MsgPack Add(this MsgPack MsgPack, string name, Key Key)
|
||||
{
|
||||
if (Key == null) return MsgPack;
|
||||
if (Key.Type == null) return MsgPack;
|
||||
|
||||
MsgPack Keys = new MsgPack(name).Add("Type", Key.Type);
|
||||
if (Key.Trans != null)
|
||||
{
|
||||
Keys = Keys.Add("Max", Key.Max).Add("EPTypePost", Key.EPTypePost).Add("EPTypePre", Key.EPTypePre);
|
||||
|
||||
if (Key.RawData.KeyType != null) Keys.Add("RawData", true);
|
||||
|
||||
MsgPack Trans = new MsgPack(Key.Trans.Length, "Trans");
|
||||
MsgPack K;
|
||||
for (int i = 0; i < Key.Trans.Length; i++)
|
||||
if (Key.Trans[i] is KeyFrameT0<double, double> KeyFrameT0)
|
||||
{
|
||||
K = new MsgPack(1);
|
||||
K[0] = (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("Value", Key.Value);
|
||||
return MsgPack.Add(Keys);
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, string Data, ref bool? val)
|
||||
{ if (val != null) IO.Write(Data, ( bool)val ); }
|
||||
public static void Write(this Stream IO, string Data, long? val)
|
||||
{ if (val != null) IO.Write(Data, ( long)val ); }
|
||||
public static void Write(this Stream IO, string Data, ulong? val)
|
||||
{ if (val != null) IO.Write(Data, ( ulong)val ); }
|
||||
public static void Write(this Stream IO, string Data, double? val)
|
||||
{ if (val != null) IO.Write(Data, (double)val ); }
|
||||
public static void Write(this Stream IO, string Data, double? val, byte r)
|
||||
{ if (val != null) IO.Write(Data, (double)val, r); }
|
||||
public static void Write(this Stream IO, string Data, ref bool val) =>
|
||||
IO.Write(Data, Main.ToString(val));
|
||||
public static void Write(this Stream IO, string Data, long val) =>
|
||||
IO.Write(Data, val.ToString( ));
|
||||
public static void Write(this Stream IO, string Data, ulong val) =>
|
||||
IO.Write(Data, val.ToString( ));
|
||||
public static void Write(this Stream IO, string Data, double val) =>
|
||||
IO.Write(Data, val.ToString( ));
|
||||
public static void Write(this Stream IO, string Data, double val, byte r) =>
|
||||
IO.Write(Data, val.ToString(r ));
|
||||
public static void Write(this Stream IO, string Data, string val)
|
||||
{ if (val != null) IO.Write((Data + val + "\n").ToUTF8()); }
|
||||
}
|
||||
}
|
||||
@@ -329,7 +329,7 @@ namespace KKdMainLib.Aet
|
||||
{
|
||||
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] );
|
||||
MsgPackReader(Aet.Array[i], ref AET.Data[i]);
|
||||
}
|
||||
|
||||
MsgPack.Dispose();
|
||||
@@ -433,6 +433,439 @@ namespace KKdMainLib.Aet
|
||||
return AET;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AetExt
|
||||
{
|
||||
private readonly static System.Text.Encoding ShiftJIS = System.Text.Encoding.GetEncoding(932);
|
||||
|
||||
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 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"); }
|
||||
}
|
||||
}
|
||||
|
||||
public struct AetHeader
|
||||
{
|
||||
@@ -1,449 +0,0 @@
|
||||
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"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ namespace KKdMainLib.DB
|
||||
if ( Ids.Contains((int)temp.Id)) { NotAdd.Add(i); break; }
|
||||
else Ids.Add ((int)temp.Id);
|
||||
}
|
||||
if (i0 + 1 != set.Sprites.Length) continue;
|
||||
if (i0 < set.Sprites.Length) continue;
|
||||
|
||||
for (i0 = 0; i0 < set.Textures.Length; i0++)
|
||||
{
|
||||
|
||||
+25
-36
@@ -12,8 +12,8 @@ namespace KKdMainLib
|
||||
|
||||
private int Offset = 0;
|
||||
private PDHead Header;
|
||||
|
||||
public Stream IO;
|
||||
private Stream IO;
|
||||
|
||||
public EXP[] Dex;
|
||||
|
||||
public int DEXReader(string filepath, string ext)
|
||||
@@ -22,10 +22,10 @@ namespace KKdMainLib
|
||||
IO = File.OpenReader(filepath + ext);
|
||||
|
||||
Header.Format = Main.Format.F;
|
||||
Header.Signature = IO.ReadInt32();
|
||||
if (Header.Signature == 0x43505845)
|
||||
Header.SectionSignature = IO.ReadInt32();
|
||||
if (Header.SectionSignature == 0x43505845)
|
||||
Header = IO.ReadHeader(true);
|
||||
if (Header.Signature != 0x64)
|
||||
if (Header.SectionSignature != 0x64)
|
||||
return 0;
|
||||
|
||||
Offset = IO.Position - 0x4;
|
||||
@@ -95,18 +95,10 @@ namespace KKdMainLib
|
||||
public void DEXWriter(string filepath, Main.Format Format)
|
||||
{
|
||||
Header = new PDHead() { Format = Format };
|
||||
IO = File.OpenWriter(filepath + (Header.Format > Main.Format.F ? ".dex" : ".bin"), true);
|
||||
IO.Format = Header.Format;
|
||||
|
||||
if (IO.Format > Main.Format.F)
|
||||
{
|
||||
Header.Lenght = 0x20;
|
||||
Header.DataSize = 0x00;
|
||||
Header.Signature = 0x43505845;
|
||||
Header.SectionSize = 0x00;
|
||||
IO.Write(Header);
|
||||
}
|
||||
IO = File.OpenWriter(filepath + (Format > Main.Format.F ? ".dex" : ".bin"), true);
|
||||
IO.Format = Format;
|
||||
|
||||
IO.Offset = Format > Main.Format.F ? 0x20 : 0;
|
||||
IO.Write(0x64);
|
||||
IO.Write(Dex.Length);
|
||||
|
||||
@@ -114,8 +106,8 @@ namespace KKdMainLib
|
||||
IO.WriteX(0x00);
|
||||
|
||||
int Position0 = IO.Position;
|
||||
IO.Write((long)0x00);
|
||||
IO.Write((long)0x00);
|
||||
IO.Write(0x00L);
|
||||
IO.Write(0x00L);
|
||||
|
||||
for (int i = 0; i < Dex.Length * 3; i++) IO.WriteX(0x00);
|
||||
|
||||
@@ -123,7 +115,7 @@ namespace KKdMainLib
|
||||
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
Dex[i0].MainOffset = IO.Position - Header.Lenght;
|
||||
Dex[i0].MainOffset = IO.Position;
|
||||
for (int i1 = 0; i1 < Dex[i0].Main.Count; i1++)
|
||||
{
|
||||
IO.Write(Dex[i0].Main[i1].Frame);
|
||||
@@ -134,7 +126,7 @@ namespace KKdMainLib
|
||||
}
|
||||
IO.Align(0x20, true);
|
||||
|
||||
Dex[i0].EyesOffset = IO.Position - Header.Lenght;
|
||||
Dex[i0].EyesOffset = IO.Position;
|
||||
for (int i1 = 0; i1 < Dex[i0].Eyes.Count; i1++)
|
||||
{
|
||||
IO.Write(Dex[i0].Eyes[i1].Frame);
|
||||
@@ -147,38 +139,35 @@ namespace KKdMainLib
|
||||
}
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
Dex[i0].NameOffset = IO.Position - Header.Lenght;
|
||||
Dex[i0].NameOffset = IO.Position;
|
||||
IO.Write(Dex[i0].Name + "\0");
|
||||
}
|
||||
IO.Align(0x10, true);
|
||||
|
||||
IO.Position = Header.Lenght + (Header.IsX ? 0x28 : 0x20);
|
||||
IO.Position = Header.IsX ? 0x28 : 0x20;
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
IO.Write(Dex[i0].MainOffset);
|
||||
if (Header.IsX) IO.Write(0x00);
|
||||
IO.Write(Dex[i0].EyesOffset);
|
||||
if (Header.IsX) IO.Write(0x00);
|
||||
IO.WriteX(Dex[i0].MainOffset);
|
||||
IO.WriteX(Dex[i0].EyesOffset);
|
||||
}
|
||||
int Position1 = IO.Position - Header.Lenght;
|
||||
int Position1 = IO.Position;
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
IO.Write(Dex[i0].NameOffset);
|
||||
if (Header.IsX) IO.Write(0x00);
|
||||
}
|
||||
IO.WriteX(Dex[i0].NameOffset);
|
||||
|
||||
IO.Position = Position0 - (Header.IsX ? 8 : 4);
|
||||
IO.Write(Position1);
|
||||
|
||||
if (IO.Format > Main.Format.F)
|
||||
if (Format > Main.Format.F)
|
||||
{
|
||||
Offset = IO.Length - Header.Lenght;
|
||||
IO.Seek(IO.Length, 0);
|
||||
Offset = IO.Length;
|
||||
IO.Offset = 0;
|
||||
IO.Position = IO.Length;
|
||||
IO.WriteEOFC(0);
|
||||
IO.Seek(0, 0);
|
||||
IO.Position = 0;
|
||||
Header.DataSize = Offset;
|
||||
Header.SectionSize = Offset;
|
||||
IO.Write(Header);
|
||||
Header.Signature = 0x43505845;
|
||||
IO.Write(Header, true);
|
||||
}
|
||||
IO.Close();
|
||||
}
|
||||
|
||||
+48
-25
@@ -7,7 +7,7 @@ namespace KKdMainLib
|
||||
{
|
||||
public class DataBank
|
||||
{
|
||||
public DataBank() { Success = false; IO = null; pvList = null; }
|
||||
public DataBank() { Success = false; IO = null; pvList = null; psrDat = null; }
|
||||
|
||||
private Stream IO;
|
||||
private int i;
|
||||
@@ -34,12 +34,14 @@ namespace KKdMainLib
|
||||
for (i = 0; i < psrDat.Length; i++) psrDat[i].SetValue(array, i);
|
||||
Success = true;
|
||||
}
|
||||
else if (file.Contains("psrData")) { psrDat = null; Success = true; }
|
||||
else if (file.Contains("PvList") && array.Length % 7 < 2)
|
||||
{
|
||||
pvList = new PvList[array.Length / 7];
|
||||
for (i = 0; i < pvList.Length; i++) pvList[i].SetValue(array, i);
|
||||
Success = true;
|
||||
}
|
||||
else if (file.Contains("PvList")) { pvList = null; Success = true; }
|
||||
}
|
||||
|
||||
public void DBWriter(string file)
|
||||
@@ -48,14 +50,19 @@ namespace KKdMainLib
|
||||
|
||||
IO = File.OpenWriter();
|
||||
if (file.Contains("psrData"))
|
||||
for (i = 0; i < psrDat.Length; i++)
|
||||
IO.Write(psrDat[i].ToString() + c);
|
||||
{
|
||||
if (psrDat != null || psrDat.Length > 0)
|
||||
for (i = 0; i < psrDat.Length; i++)
|
||||
IO.Write(psrDat[i].ToString() + c);
|
||||
}
|
||||
else if (file.Contains("PvList"))
|
||||
if (pvList.Length != 0)
|
||||
{
|
||||
if (pvList != null || pvList.Length > 0)
|
||||
for (i = 0; i < pvList.Length; i++)
|
||||
IO.Write(UrlEncode(pvList[i].ToString() +
|
||||
((i + 1 != pvList.Length) ? c : "")));
|
||||
else IO.Write("%2A%2A%2A");
|
||||
(i < pvList.Length ? c : "")));
|
||||
}
|
||||
else IO.Write("%2A%2A%2A");
|
||||
|
||||
|
||||
byte[] data = IO.ToArray(true);
|
||||
@@ -70,20 +77,29 @@ namespace KKdMainLib
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
bool compact = MsgPack.ReadBoolean("Compact");
|
||||
|
||||
if (file.Contains("psrData") && MsgPack.ElementArray("psrData", out MsgPack psrData))
|
||||
if (file.Contains("psrData"))
|
||||
{
|
||||
psrDat = new psrData[psrData.Array.Length];
|
||||
for (i = 0; i < psrDat.Length; i++)
|
||||
psrDat[i].SetValue(psrData[i]);
|
||||
if (MsgPack.ElementArray("psrData", out MsgPack psrData))
|
||||
{
|
||||
psrDat = new psrData[psrData.Array.Length];
|
||||
for (i = 0; i < psrDat.Length; i++)
|
||||
psrDat[i].SetValue(psrData[i]);
|
||||
}
|
||||
else if (MsgPack.ContainsKey("psrData")) psrDat = null;
|
||||
Success = true;
|
||||
}
|
||||
else if (file.Contains("PvList") && MsgPack.ElementArray("PvList", out MsgPack PvList))
|
||||
else if (file.Contains("PvList"))
|
||||
{
|
||||
pvList = new PvList[PvList.Array.Length];
|
||||
for (i = 0; i < pvList.Length; i++)
|
||||
pvList[i].SetValue(PvList[i], compact);
|
||||
if (MsgPack.ElementArray("PvList", out MsgPack PvList))
|
||||
{
|
||||
pvList = new PvList[PvList.Array.Length];
|
||||
for (i = 0; i < pvList.Length; i++)
|
||||
pvList[i].SetValue(PvList[i], compact);
|
||||
}
|
||||
else if (MsgPack.ContainsKey("PvList")) pvList = null;
|
||||
Success = true;
|
||||
}
|
||||
|
||||
MsgPack = MsgPack.New;
|
||||
}
|
||||
|
||||
@@ -94,17 +110,25 @@ namespace KKdMainLib
|
||||
|
||||
if (file.Contains("psrData"))
|
||||
{
|
||||
MsgPack psrData = new MsgPack(psrDat.Length, "psrData");
|
||||
for (i = 0; i < psrDat.Length; i++) psrData[i] = psrDat[i].WriteMP();
|
||||
msgPack.Add(psrData);
|
||||
if (psrDat != null)
|
||||
{
|
||||
MsgPack psrData = new MsgPack(psrDat.Length, "psrData");
|
||||
for (i = 0; i < psrDat.Length; i++) psrData[i] = psrDat[i].WriteMP();
|
||||
msgPack.Add(psrData);
|
||||
}
|
||||
else msgPack.Add(new MsgPack("psrData", null));
|
||||
}
|
||||
else if (file.Contains("PvList"))
|
||||
{
|
||||
if (Compact) msgPack.Add("Compact", Compact);
|
||||
if (psrDat != null)
|
||||
{
|
||||
if (Compact) msgPack.Add("Compact", Compact);
|
||||
|
||||
MsgPack PvList = new MsgPack(pvList.Length, "PvList");
|
||||
for (i = 0; i < pvList.Length; i++) PvList[i] = pvList[i].WriteMP(Compact);
|
||||
msgPack.Add(PvList);
|
||||
MsgPack PvList = new MsgPack(pvList.Length, "PvList");
|
||||
for (i = 0; i < pvList.Length; i++) PvList[i] = pvList[i].WriteMP(Compact);
|
||||
msgPack.Add(PvList);
|
||||
}
|
||||
else msgPack.Add(new MsgPack("PvList", null));
|
||||
}
|
||||
msgPack.Write(file, JSON).Dispose();
|
||||
}
|
||||
@@ -112,7 +136,6 @@ namespace KKdMainLib
|
||||
public static string UrlEncode(string value) =>
|
||||
WebUtility.UrlEncode(value).Replace("+", "%20");
|
||||
|
||||
|
||||
public struct psrData
|
||||
{
|
||||
public Player p1;
|
||||
@@ -237,8 +260,8 @@ namespace KKdMainLib
|
||||
else { ID = msg.ReadNInt32("ID"); if (ID != null) PV_ID = (int)ID; }
|
||||
bool? Enable = msg.ReadNBoolean("Enable");
|
||||
bool? Extra = msg.ReadNBoolean("Extra");
|
||||
if (Enable == null) this.Enable = (bool)Enable;
|
||||
if (Extra == null) this.Extra = (bool)Extra ;
|
||||
if (Enable != null) this.Enable = (bool)Enable;
|
||||
if (Extra != null) this.Extra = (bool)Extra ;
|
||||
if (Compact)
|
||||
{
|
||||
AdvDemoStart.SetValue(msg.ReadNInt32("AdvDemoStart"), true);
|
||||
@@ -256,7 +279,7 @@ namespace KKdMainLib
|
||||
public MsgPack WriteMP(bool Compact)
|
||||
{
|
||||
MsgPack msgPack = MsgPack.New;
|
||||
msgPack.Add("PV_ID", PV_ID);
|
||||
msgPack.Add("ID", PV_ID);
|
||||
if (!Enable) msgPack.Add("Enable", Enable);
|
||||
if ( Extra ) msgPack.Add("Extra" , Extra );
|
||||
if (Compact)
|
||||
|
||||
+72
-74
@@ -19,6 +19,7 @@ namespace KKdMainLib
|
||||
public Type FARCType;
|
||||
public Farc Signature = Farc.FArC;
|
||||
public string FilePath, DirectoryPath;
|
||||
public bool HasFiles => Files == null ? false : Files.Length > 0;
|
||||
|
||||
private bool CBC, FT;
|
||||
|
||||
@@ -36,21 +37,18 @@ namespace KKdMainLib
|
||||
}
|
||||
|
||||
public void UnPack(bool SaveToDisk = true)
|
||||
{
|
||||
HeaderReader().FileReader();
|
||||
if (SaveToDisk) this.SaveToDisk();
|
||||
}
|
||||
{ if (HeaderReader()) { FileReader(); if (SaveToDisk) this.SaveToDisk(); } }
|
||||
|
||||
private FARC HeaderReader()
|
||||
public bool HeaderReader()
|
||||
{
|
||||
NewFARC();
|
||||
if (!File.Exists(FilePath)) return this;
|
||||
if (!File.Exists(FilePath)) return false;
|
||||
|
||||
Stream reader = File.OpenReader(FilePath);
|
||||
DirectoryPath = Path.GetFullPath(FilePath).Replace(Path.GetExtension(FilePath), "");
|
||||
Signature = (Farc)reader.ReadInt32Endian(true);
|
||||
if (Signature != Farc.FArc && Signature != Farc.FArC && Signature != Farc.FARC)
|
||||
{ reader.Close(); return this; }
|
||||
{ reader.Close(); return false; }
|
||||
|
||||
int HeaderLength = reader.ReadInt32Endian(true);
|
||||
if (Signature == Farc.FARC)
|
||||
@@ -113,77 +111,76 @@ namespace KKdMainLib
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
return this;
|
||||
return true;
|
||||
}
|
||||
|
||||
private FARC FileReader()
|
||||
private void FileReader()
|
||||
{ for (int i = 0; i < Files.Length; i++) FileReader(i); }
|
||||
|
||||
public byte[] FileReader(int i)
|
||||
{
|
||||
if (Files == null) return this;
|
||||
if (Files.Length < 1) return this;
|
||||
if (!HasFiles) return null;
|
||||
if (i >= Files.Length) return null;
|
||||
if (Signature != Farc.FARC)
|
||||
{
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
if (Signature == Farc.FArC)
|
||||
using (MSIO.MemoryStream memorystream = new MSIO.MemoryStream(
|
||||
File.ReadAllBytes(FilePath, Files[i].SizeComp, Files[i].Offset)))
|
||||
{
|
||||
GZipStream gZipStream = new GZipStream(memorystream, CompressionMode.Decompress);
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
}
|
||||
else Files[i].Data = File.ReadAllBytes(FilePath, Files[i].SizeUnc, Files[i].Offset);
|
||||
return this;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
int FileSize = FARCType.HasFlag(Type.ECB) || Files[i].Type.HasFlag(Type.ECB) ?
|
||||
Files[i].SizeComp.Align(0x10) : Files[i].SizeComp;
|
||||
MSIO.FileStream stream = new MSIO.FileStream(FilePath, MSIO.FileMode.Open,
|
||||
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite);
|
||||
stream.Seek(Files[i].Offset, 0);
|
||||
Files[i].Data = new byte[FileSize];
|
||||
|
||||
bool Encrypted = false;
|
||||
if (FARCType.HasFlag(Type.ECB))
|
||||
{
|
||||
if ((FT && Files[i].Type.HasFlag(Type.ECB)) || CBC)
|
||||
if (Signature == Farc.FArC)
|
||||
using (MSIO.MemoryStream memorystream = new MSIO.MemoryStream(
|
||||
File.ReadAllBytes(FilePath, Files[i].SizeComp, Files[i].Offset)))
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Files[i].Data, 0, FileSize);
|
||||
Files[i].Data = SkipData(Files[i].Data, 0x10);
|
||||
GZipStream gZipStream = new GZipStream(memorystream, CompressionMode.Decompress);
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
}
|
||||
else
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(false, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Files[i].Data, 0, FileSize);
|
||||
Encrypted = true;
|
||||
}
|
||||
|
||||
bool Compressed = false;
|
||||
if (((FT && Files[i].Type.HasFlag(Type.GZip)) ||
|
||||
FARCType.HasFlag(Type.GZip)) && Files[i].SizeUnc > 0)
|
||||
{
|
||||
GZipStream gZipStream;
|
||||
if (Encrypted) { gZipStream = new GZipStream(new MSIO.MemoryStream(Files[i].Data),
|
||||
CompressionMode.Decompress); stream.Close(); }
|
||||
else gZipStream = new GZipStream(stream, CompressionMode.Decompress);
|
||||
byte[] Temp = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Temp, 0, Files[i].SizeUnc);
|
||||
Files[i].Data = Temp;
|
||||
|
||||
Compressed = true;
|
||||
}
|
||||
|
||||
if (!Encrypted && !Compressed)
|
||||
{
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
stream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
stream.Close();
|
||||
}
|
||||
else Files[i].Data = File.ReadAllBytes(FilePath, Files[i].SizeUnc, Files[i].Offset);
|
||||
return Files[i].Data;
|
||||
}
|
||||
return this;
|
||||
|
||||
int FileSize = FARCType.HasFlag(Type.ECB) || Files[i].Type.HasFlag(Type.ECB) ?
|
||||
Files[i].SizeComp.Align(0x10) : Files[i].SizeComp;
|
||||
MSIO.FileStream stream = new MSIO.FileStream(FilePath, MSIO.FileMode.Open,
|
||||
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite);
|
||||
stream.Seek(Files[i].Offset, 0);
|
||||
Files[i].Data = new byte[FileSize];
|
||||
|
||||
bool Encrypted = false;
|
||||
if (FARCType.HasFlag(Type.ECB))
|
||||
{
|
||||
if ((FT && Files[i].Type.HasFlag(Type.ECB)) || CBC)
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Files[i].Data, 0, FileSize);
|
||||
Files[i].Data = SkipData(Files[i].Data, 0x10);
|
||||
}
|
||||
else
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(false, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Files[i].Data, 0, FileSize);
|
||||
Encrypted = true;
|
||||
}
|
||||
|
||||
bool Compressed = false;
|
||||
if (((FT && Files[i].Type.HasFlag(Type.GZip)) ||
|
||||
FARCType.HasFlag(Type.GZip)) && Files[i].SizeUnc > 0)
|
||||
{
|
||||
GZipStream gZipStream;
|
||||
if (Encrypted) { gZipStream = new GZipStream(new MSIO.MemoryStream(Files[i].Data),
|
||||
CompressionMode.Decompress); stream.Close(); }
|
||||
else gZipStream = new GZipStream(stream, CompressionMode.Decompress);
|
||||
byte[] Temp = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Temp, 0, Files[i].SizeUnc);
|
||||
Files[i].Data = Temp;
|
||||
|
||||
Compressed = true;
|
||||
}
|
||||
|
||||
if (!Encrypted && !Compressed)
|
||||
{
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
stream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
stream.Close();
|
||||
}
|
||||
return Files[i].Data;
|
||||
}
|
||||
|
||||
private void SaveToDisk()
|
||||
@@ -193,7 +190,8 @@ namespace KKdMainLib
|
||||
MSIO.Directory.CreateDirectory(DirectoryPath);
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(DirectoryPath, Files[i].Name), Files[i].Data);
|
||||
if (Files[i].Data != null)
|
||||
File.WriteAllBytes(Path.Combine(DirectoryPath, Files[i].Name), Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
}
|
||||
}
|
||||
@@ -205,7 +203,7 @@ namespace KKdMainLib
|
||||
return SkipData;
|
||||
}
|
||||
|
||||
public FARC Pack()
|
||||
public void Pack()
|
||||
{
|
||||
NewFARC();
|
||||
string[] files = Directory.GetFiles(DirectoryPath);
|
||||
@@ -213,10 +211,10 @@ namespace KKdMainLib
|
||||
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;
|
||||
Save();
|
||||
}
|
||||
|
||||
public void CompressStuff()
|
||||
public void Save()
|
||||
{
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace KKdMainLib.IO
|
||||
{
|
||||
public static class File
|
||||
{
|
||||
public static Stream OpenReader(byte[] Data) => new Stream(new MSIO.MemoryStream(Data), Data);
|
||||
public static Stream OpenReader(byte[] Data) => new Stream(new MSIO.MemoryStream(Data));
|
||||
public static Stream OpenWriter( ) => new Stream(new MSIO.MemoryStream( ));
|
||||
|
||||
public static Stream OpenReader(string file, bool ReadAllAtOnce)
|
||||
@@ -14,7 +14,7 @@ namespace KKdMainLib.IO
|
||||
{ Stream IO = new Stream(new MSIO.FileStream(file, MSIO.FileMode.Open, MSIO.FileAccess.ReadWrite,
|
||||
MSIO.FileShare.ReadWrite)) { File = file }; return IO; }
|
||||
public static Stream OpenWriter(string file, bool SetLength0)
|
||||
{ Stream IO = OpenWriter(file); IO.SetLength(0 ); return IO; }
|
||||
{ Stream IO = OpenWriter(file); if (SetLength0) IO.SetLength(0); return IO; }
|
||||
public static Stream OpenWriter(string file, int SetLength)
|
||||
{ Stream IO = OpenWriter(file); IO.SetLength(SetLength); return IO; }
|
||||
public static Stream OpenWriter(string file)
|
||||
|
||||
+11
-13
@@ -11,7 +11,6 @@ namespace KKdMainLib.IO
|
||||
private ushort ValRead;
|
||||
private byte BitRead, BitWrite, ValWrite;
|
||||
private byte[] buf;
|
||||
private byte[] data;
|
||||
|
||||
private Main.Format _format = Main.Format.NULL;
|
||||
|
||||
@@ -46,7 +45,7 @@ namespace KKdMainLib.IO
|
||||
|
||||
public string File = null;
|
||||
|
||||
public Stream(MSIO.Stream output = null, byte[] Data = null, bool isBE = false)
|
||||
public Stream(MSIO.Stream output = null, bool isBE = false)
|
||||
{
|
||||
if (output == null) output = MSIO.Stream.Null;
|
||||
LongOffset = 0;
|
||||
@@ -56,7 +55,6 @@ namespace KKdMainLib.IO
|
||||
Format = Main.Format.NULL;
|
||||
buf = new byte[128];
|
||||
IsBE = isBE;
|
||||
data = Data;
|
||||
}
|
||||
|
||||
public void Close() => Dispose();
|
||||
@@ -75,7 +73,7 @@ namespace KKdMainLib.IO
|
||||
{ CheckWrited(); Dispose(true); }
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{ if (disposing && stream != MSIO.Stream.Null) stream.Flush(); stream.Dispose(); data = null; }
|
||||
{ if (disposing && stream != MSIO.Stream.Null) stream.Flush(); stream.Dispose(); }
|
||||
|
||||
public MSIO.Stream BaseStream
|
||||
{ get { stream.Flush(); return stream; } set { stream = value; } }
|
||||
@@ -84,23 +82,23 @@ namespace KKdMainLib.IO
|
||||
{
|
||||
long Al = Align - Position % Align;
|
||||
if (Position % Align != 0)
|
||||
stream.Seek(Position + Al, 0);
|
||||
stream.Seek(Position + Offset + Al, 0);
|
||||
}
|
||||
|
||||
public void Align(long Align, bool SetLength)
|
||||
{
|
||||
if (SetLength) stream.SetLength(Position);
|
||||
if (SetLength) stream.SetLength(Position + Offset);
|
||||
long Al = Align - Position % Align;
|
||||
if (Position % Align != 0) stream.Seek(Position + Al, 0);
|
||||
if (SetLength) stream.SetLength(Position);
|
||||
if (Position % Align != 0) stream.Seek(Position + Offset + Al, 0);
|
||||
if (SetLength) stream.SetLength(Position + Offset);
|
||||
}
|
||||
|
||||
public void Align(long Align, bool SetLength0, bool SetLength1)
|
||||
{
|
||||
if (SetLength0) stream.SetLength(Position);
|
||||
if (SetLength0) stream.SetLength(Position + Offset);
|
||||
long Al = Align - Position % Align;
|
||||
if (Position % Align != 0) stream.Seek(Position + Al, 0);
|
||||
if (SetLength1) stream.SetLength(Position);
|
||||
if (SetLength1) stream.SetLength(Position + Offset);
|
||||
}
|
||||
|
||||
public bool ReadBoolean() => stream.ReadByte() == 1;
|
||||
@@ -375,10 +373,10 @@ namespace KKdMainLib.IO
|
||||
|
||||
public byte[] ToArray()
|
||||
{
|
||||
long Offset = stream.Position;
|
||||
LongPosition = 0;
|
||||
long Position = stream.Position;
|
||||
stream.Position = 0;
|
||||
byte[] Data = ReadBytes(stream.Length);
|
||||
LongPosition = Offset;
|
||||
stream.Position = Position;
|
||||
return Data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,10 +39,6 @@
|
||||
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="A3DA\A3DAExt.cs" />
|
||||
<Compile Include="A3DA\A3DA.cs" />
|
||||
<Compile Include="Aet\Aet.cs" />
|
||||
<Compile Include="Aet\AetExt.cs" />
|
||||
<Compile Include="DB\Aet.cs" />
|
||||
<Compile Include="DB\Auth.cs" />
|
||||
<Compile Include="DB\Spr.cs" />
|
||||
@@ -60,6 +56,8 @@
|
||||
<Compile Include="Types\KKdList.cs" />
|
||||
<Compile Include="Types\Pointer.cs" />
|
||||
<Compile Include="Types\Vector.cs" />
|
||||
<Compile Include="A3DA.cs" />
|
||||
<Compile Include="Aet.cs" />
|
||||
<Compile Include="DataBank.cs" />
|
||||
<Compile Include="DCC.cs" />
|
||||
<Compile Include="DEX.cs" />
|
||||
|
||||
+2
-2
@@ -81,8 +81,8 @@ namespace KKdMainLib
|
||||
Multiselect = true, Title = "Choose file(s) to open:" };
|
||||
|
||||
ofd.Filter = GetArgs("All;", false, "*");
|
||||
if (filetype == "a3da") ofd.Filter = GetArgs("A3DA", "a3da", "json", "mp") +
|
||||
GetArgs("A3DA", true, "a3da") + JSON + MsgPack;
|
||||
if (filetype == "a3da") ofd.Filter = GetArgs("A3DA", "a3da", "farc", "json", "mp") +
|
||||
GetArgs("A3DA", true, "a3da") + GetArgs("FARC", true, "farc") + JSON + MsgPack;
|
||||
else if (filetype == "bin" ) ofd.Filter = GetArgs("BIN" , "bin", "json", "mp") +
|
||||
BIN + JSON + MsgPack;
|
||||
else if (filetype == "bon" ) ofd.Filter = GetArgs("BON" , "bon", "bin", "json", "mp") +
|
||||
|
||||
@@ -136,13 +136,13 @@ namespace KKdMainLib.MessagePack
|
||||
else
|
||||
{
|
||||
long val = long.Parse(s);
|
||||
if (val >= 0x000000 && val < 0x0000100) return ( byte)val;
|
||||
else if (val >= -0x000080 && val < 0x0000080) return ( sbyte)val;
|
||||
else if (val >= -0x008000 && val < 0x0008000) return ( short)val;
|
||||
else if (val >= 0x000000 && val < 0x0010000) return (ushort)val;
|
||||
else if (val >= -0x800000 && val < 0x0800000) return ( int)val;
|
||||
else if (val >= 0x000000 && val < 0x1000000) return ( uint)val;
|
||||
else return val;
|
||||
if (val >= 0x00000000 && val < 0x000000100) return ( byte)val;
|
||||
else if (val >= -0x00000080 && val < 0x000000080) return ( sbyte)val;
|
||||
else if (val >= -0x00008000 && val < 0x000008000) return ( short)val;
|
||||
else if (val >= 0x00000000 && val < 0x000010000) return (ushort)val;
|
||||
else if (val >= -0x80000000 && val < 0x000800000) return ( int)val;
|
||||
else if (val >= 0x00000000 && val < 0x100000000) return ( uint)val;
|
||||
else return val;
|
||||
}
|
||||
|
||||
char c = _IO.PeekCharUTF8();
|
||||
@@ -255,8 +255,8 @@ namespace KKdMainLib.MessagePack
|
||||
}
|
||||
private void Write( bool val) => _IO.Write(val ? "true" : "false");
|
||||
private void Write(string val) => _IO.Write("\"" + val
|
||||
.Replace("\\", "\\\\").Replace("/" , "\\/").Replace("\'", "\\\'").Replace("\"", "\\\"")
|
||||
.Replace("\0", "\\0" ).Replace("\a", "\\a").Replace("\b", "\\b" ).Replace("\f", "\\f" )
|
||||
.Replace("\\", "\\\\").Replace("/" , "\\/").Replace("\"", "\\\"")
|
||||
.Replace("\0", "\\0" ).Replace("\b", "\\b").Replace("\f", "\\f" )
|
||||
.Replace("\n", "\\n" ).Replace("\r", "\\r").Replace("\t", "\\t" ) + "\"");
|
||||
|
||||
private void WriteNil() => _IO.Write("null");
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace KKdMainLib.MessagePack
|
||||
MsgPack = IO.Read(); IO.Close(); IO = null; }
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
public static MsgPack ReadMP(this string file, bool JSON = false)
|
||||
{
|
||||
MsgPack MsgPack;
|
||||
|
||||
@@ -44,6 +44,9 @@ namespace KKdMainLib.MessagePack
|
||||
(Array != null ? ((Name != null ? " " : "") + "Elements Count: " + Array.Length) :
|
||||
Object.ToString()));
|
||||
|
||||
public MsgPack Add(string Val, byte[] val) => val != null ? Add(new MsgPack(Val, val)) : this;
|
||||
public MsgPack Add(string Val, string val) => val != null ? Add(new MsgPack(Val, val)) : this;
|
||||
|
||||
public static explicit operator MsgPack(byte[] val) => new MsgPack(null, val);
|
||||
public static explicit operator MsgPack(string val) => new MsgPack(null, val);
|
||||
public static explicit operator MsgPack( sbyte val) => new MsgPack(null, val);
|
||||
@@ -57,17 +60,17 @@ namespace KKdMainLib.MessagePack
|
||||
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( sbyte? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( byte? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( short? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add(ushort? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( int? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( uint? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( long? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( ulong? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( float? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add(double? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
|
||||
public MsgPack Add(byte[] val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add(string val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( bool val) => Add(new MsgPack(null, val));
|
||||
@@ -82,19 +85,16 @@ namespace KKdMainLib.MessagePack
|
||||
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, sbyte? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, byte? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, short? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, ushort? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, int? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, uint? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, long? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, ulong? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, float? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, double? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
|
||||
public MsgPack Add(string Val, bool val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, sbyte val) => Add(new MsgPack(Val, val));
|
||||
|
||||
+24
-8
@@ -9,7 +9,8 @@ namespace KKdMainLib
|
||||
public int DataSize;
|
||||
public int Signature;
|
||||
public int SectionSize;
|
||||
public int RealSignature;
|
||||
public int InnerSignature;
|
||||
public int SectionSignature;
|
||||
public Main.Format Format;
|
||||
public bool IsBE => Format == Main.Format.F2BE;
|
||||
public bool IsX => Format == Main.Format.X || Format == Main.Format.XHD;
|
||||
@@ -20,8 +21,8 @@ namespace KKdMainLib
|
||||
public static PDHead ReadHeader(this Stream stream, bool Seek)
|
||||
{
|
||||
if (Seek)
|
||||
if (stream.Position >= 4) stream.LongPosition -= 4;
|
||||
else stream.LongPosition = 0;
|
||||
if (stream.Position > 4) stream.LongPosition -= 4;
|
||||
else stream.LongPosition = 0;
|
||||
return stream.ReadHeader();
|
||||
}
|
||||
|
||||
@@ -35,29 +36,44 @@ namespace KKdMainLib
|
||||
{ Header.Format = Main.Format.F2BE; }
|
||||
Header.ID = stream.ReadInt32();
|
||||
Header.SectionSize = stream.ReadInt32();
|
||||
if (Header.Lenght == 0x40)
|
||||
{
|
||||
stream.Position = 0x30;
|
||||
Header.InnerSignature = stream.ReadInt32();
|
||||
}
|
||||
stream.IsBE = Header.Format == Main.Format.F2BE;
|
||||
stream.Format = Header.Format;
|
||||
stream.LongPosition = Position + Header.Lenght;
|
||||
Header.Signature = stream.ReadInt32Endian();
|
||||
Header.SectionSignature = stream.ReadInt32Endian();
|
||||
return Header;
|
||||
}
|
||||
|
||||
public static void Write(this Stream stream, PDHead Header)
|
||||
public static void Write(this Stream stream, PDHead Header, bool X = false)
|
||||
{
|
||||
stream.Write(Header.Signature);
|
||||
stream.Write(Header.DataSize);
|
||||
stream.Write(Header.Lenght);
|
||||
stream.Write((Header.Format < Main.Format.X && !X) ? 0x40 : 0x20);
|
||||
if (Header.Format == Main.Format.F2BE) stream.Write(0x18000000);
|
||||
else stream.Write(0x10000000);
|
||||
stream.Write(Header.ID);
|
||||
stream.Write(Header.SectionSize);
|
||||
stream.Write(0x00);
|
||||
stream.Write(0x00);
|
||||
if (Header.Format < Main.Format.X && !X)
|
||||
{
|
||||
stream.Write(Header.Format < Main.Format.MGF ? (int)((Header.SectionSignature ^
|
||||
(Header.DataSize * (long)Header.Signature)) - Header.ID + Header.SectionSize) : 0);
|
||||
stream.Write(0x00);
|
||||
stream.Write(0x00L);
|
||||
stream.Write(Header.InnerSignature);
|
||||
stream.Write(0x00);
|
||||
stream.Write(0x00L);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteEOFC(this Stream stream, int ID = 0) =>
|
||||
stream.Write(new PDHead { Format = Main.Format.F2LE, ID = ID,
|
||||
Lenght = 0x20, Signature = 0x43464F45, });
|
||||
stream.Write(new PDHead { ID = ID,
|
||||
Lenght = 0x20, Signature = 0x43464F45 }, true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ namespace KKdMainLib
|
||||
public static Stream GetOffset(this Stream stream, ref POF POF)
|
||||
{
|
||||
if (POF != null) if (stream.Format > Main.Format.F)
|
||||
POF.POFOffsets.Add(stream.Position - (stream.IsX ? stream.Offset : 0x00));
|
||||
POF.POFOffsets.Add(stream.Position + (stream.IsX ? stream.Offset : 0x00));
|
||||
return stream;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace KKdMainLib
|
||||
POF.Header = new PDHead { DataSize = (int)POFLenghtAling, ID = ID, Format = Main.Format.F2LE,
|
||||
Lenght = 0x20, SectionSize = (int)POFLenghtAling, Signature = 0x30464F50 };
|
||||
POF.Header.Signature += POF.Type << 24;
|
||||
stream.Write(POF.Header);
|
||||
stream.Write(POF.Header, true);
|
||||
|
||||
stream.Write(POF.Lenght);
|
||||
for (int i = 0; i < POF.POFOffsets.Count; i++)
|
||||
|
||||
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("2BA7EFC6-91D1-8BBC-C487-06C7F36CC789")]
|
||||
[assembly: AssemblyVersion("0.4.6.2")]
|
||||
[assembly: AssemblyFileVersion("0.4.6.2")]
|
||||
[assembly: AssemblyVersion("0.4.6.4")]
|
||||
[assembly: AssemblyFileVersion("0.4.6.4")]
|
||||
|
||||
+7
-8
@@ -1,15 +1,14 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public static class Text
|
||||
{
|
||||
public static string ToASCII(this byte[] Array) => Encoding.ASCII.GetString(Array);
|
||||
public static string ToUTF8 (this byte[] Array) => Encoding.UTF8 .GetString(Array);
|
||||
public static byte[] ToASCII(this string Data ) => Encoding.ASCII.GetBytes (Data );
|
||||
public static byte[] ToUTF8 (this string Data ) => Encoding.UTF8 .GetBytes (Data );
|
||||
public static byte[] ToASCII(this char[] Data ) => Encoding.ASCII.GetBytes (Data );
|
||||
public static byte[] ToUTF8 (this char[] Data ) => Encoding.UTF8 .GetBytes (Data );
|
||||
public static string ToASCII(this byte[] Array) => Encoding.ASCII.GetString(Array ?? new byte[0]);
|
||||
public static string ToUTF8 (this byte[] Array) => Encoding.UTF8 .GetString(Array ?? new byte[0]);
|
||||
public static byte[] ToASCII(this string Data ) => Encoding.ASCII.GetBytes (Data ?? "" );
|
||||
public static byte[] ToUTF8 (this string Data ) => Encoding.UTF8 .GetBytes (Data ?? "" );
|
||||
public static byte[] ToASCII(this char[] Data ) => Encoding.ASCII.GetBytes (Data ?? new char[0]);
|
||||
public static byte[] ToUTF8 (this char[] Data ) => Encoding.UTF8 .GetBytes (Data ?? new char[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace KKdMainLib.Types
|
||||
public struct KKdList<T> : IEnumerator, IEnumerable
|
||||
{
|
||||
public static KKdList<T> Null => new KKdList<T>();
|
||||
public static KKdList<T> New => new KKdList<T>() { Capacity = 0 };
|
||||
public static KKdList<T> New => new KKdList<T>() { Capacity = 0 };
|
||||
public static KKdList<T> NewReserve(int Capacity) => new KKdList<T>() { Capacity = Capacity };
|
||||
|
||||
private int index;
|
||||
@@ -83,7 +83,9 @@ namespace KKdMainLib.Types
|
||||
{
|
||||
if (IsNull) return false;
|
||||
for (int i = 0; i < Count; i++)
|
||||
if (array[i].Equals(val)) return true;
|
||||
if (array[i] == null && val == null) return true;
|
||||
else if ( val == null) continue;
|
||||
else if (array[i] .Equals(val) ) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -91,7 +93,9 @@ namespace KKdMainLib.Types
|
||||
{
|
||||
if (IsNull) return -1;
|
||||
for (int i = 0; i < Count; i++)
|
||||
if (array[i].Equals(val)) return i;
|
||||
if (array[i] == null && val == null) return i;
|
||||
else if ( val == null) continue;
|
||||
else if (array[i] .Equals(val) ) return i;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace KKdMainLib.Types
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib.Types
|
||||
{
|
||||
public struct Pointer<T>
|
||||
{
|
||||
@@ -23,4 +25,19 @@
|
||||
public override string ToString() => Count < 1 ? "No Entries" :
|
||||
Count == 1 ? Entries[0].ToString() : "Count: " + Count;
|
||||
}
|
||||
|
||||
public static class PointerExt
|
||||
{
|
||||
public static Pointer<T> ReadPointer<T>(this Stream IO) =>
|
||||
new Pointer<T> { Offset = IO.ReadInt32() };
|
||||
|
||||
public static Pointer<string> ReadPointerString(this Stream IO)
|
||||
{
|
||||
Pointer<string> val = IO.ReadPointer<string>();
|
||||
val.Value = IO.ReadStringAtOffset(val.Offset); return val;
|
||||
}
|
||||
|
||||
public static CountPointer<T> ReadCountPointer<T>(this Stream IO) =>
|
||||
new CountPointer<T> { Count = IO.ReadInt32(), Offset = IO.ReadInt32() };
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@
|
||||
public Vector2(T X, T Y)
|
||||
{ this.X = X; this.Y = Y; }
|
||||
|
||||
public bool NotNull => X != null && Y != null;
|
||||
|
||||
public override string ToString() => "X: " + X + "; Y: " + Y;
|
||||
}
|
||||
|
||||
@@ -20,6 +22,23 @@
|
||||
public Vector3(T X, T Y, T Z)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; }
|
||||
|
||||
public bool NotNull => X != null && Y != null && Z != null;
|
||||
|
||||
public override string ToString() => "X: " + X + "; Y: " + Y + "; Z: " + Z;
|
||||
}
|
||||
|
||||
public struct Vector4<T>
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
public T Z;
|
||||
public T W;
|
||||
|
||||
public Vector4(T X, T Y, T Z, T W)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; this.W = W; }
|
||||
|
||||
public bool NotNull => X != null && Y != null && Z != null && W != null;
|
||||
|
||||
public override string ToString() => "X: " + X + "; Y: " + Y + "; Z: " + Z + "; W: " + W;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27130.2003
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29025.244
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PD_Tool", "PD_Tool\PD_Tool.csproj", "{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}"
|
||||
EndProject
|
||||
|
||||
+2
-4
@@ -1,7 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.Types;
|
||||
using KKdMain = KKdMainLib.Main;
|
||||
using KKdFARC = KKdMainLib.FARC;
|
||||
|
||||
@@ -9,7 +7,7 @@ namespace PD_Tool
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static string function = "";
|
||||
[ThreadStatic] public static string function = "";
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
@@ -39,7 +37,7 @@ namespace PD_Tool
|
||||
Exit();
|
||||
}
|
||||
|
||||
private static bool JSON = true;
|
||||
[ThreadStatic] private static bool JSON = true;
|
||||
|
||||
private static void MainMenu()
|
||||
{
|
||||
|
||||
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
|
||||
[assembly: AssemblyVersion("0.4.6.2")]
|
||||
[assembly: AssemblyFileVersion("0.4.6.2")]
|
||||
[assembly: AssemblyVersion("0.4.6.4")]
|
||||
[assembly: AssemblyFileVersion("0.4.6.4")]
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
using KKdA3DA = KKdMainLib.A3DA.A3DA;
|
||||
using KKdFARC = KKdMainLib.FARC;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
{
|
||||
@@ -19,6 +21,7 @@ namespace PD_Tool.Tools
|
||||
foreach (string file in FileNames)
|
||||
if (file.EndsWith(".mp" )) { MP = true; break; }
|
||||
else if (file.EndsWith(".json")) { MP = true; break; }
|
||||
else if (file.EndsWith(".farc")) { MP = true; break; }
|
||||
|
||||
Main.Format Format = Main.Format.NULL;
|
||||
string format = "";
|
||||
@@ -50,6 +53,7 @@ namespace PD_Tool.Tools
|
||||
}
|
||||
|
||||
KKdA3DA A;
|
||||
int state;
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
A = new KKdA3DA();
|
||||
@@ -58,20 +62,47 @@ namespace PD_Tool.Tools
|
||||
ext = ext.ToLower();
|
||||
|
||||
Console.Title = "A3DA Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".a3da")
|
||||
if (ext == ".farc")
|
||||
{
|
||||
A.A3DAReader (filepath);
|
||||
A.MsgPackWriter(filepath, JSON);
|
||||
KKdFARC FARC = new KKdFARC(file);
|
||||
if (!FARC.HeaderReader()) continue;
|
||||
if (!FARC.HasFiles) continue;
|
||||
|
||||
MsgPack A3DA = MsgPack.Null;
|
||||
byte[] data = null;
|
||||
for (int i = 0; i < FARC.Files.Length; i++)
|
||||
{
|
||||
data = FARC.FileReader(i);
|
||||
state = A.A3DAReader(data);
|
||||
if (state == 1)
|
||||
{
|
||||
A3DA = A.MsgPackWriter();
|
||||
A = new KKdA3DA();
|
||||
A.MsgPackReader(A3DA);
|
||||
A.IO = File.OpenWriter();
|
||||
A.Data._.CompressF16 = Format > Main.Format.FT ?
|
||||
Format == Main.Format.MGF ? 2 : 1 : 0;
|
||||
A.Data.Format = Format;
|
||||
FARC.Files[i].Data = (format != "1" &&
|
||||
format != "3") ? A.A3DCWriter() : A.A3DAWriter();
|
||||
}
|
||||
}
|
||||
FARC.Save();
|
||||
}
|
||||
else if (ext == ".a3da")
|
||||
{
|
||||
state = A.A3DAReader(filepath);
|
||||
if (state == 1) A.MsgPackWriter(filepath, JSON);
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
{
|
||||
A.MsgPackReader(filepath, ext == ".json");
|
||||
A.IO = File.OpenWriter(filepath + ".a3da", true);
|
||||
A.Data._.CompressF16 = A.Data.Header.Format > Main.Format.FT ? Format == Main.Format.MGF ? 2 : 1 : 0;
|
||||
A.Data.Header.Format = Format;
|
||||
A.Data._.CompressF16 = Format > Main.Format.FT ?
|
||||
Format == Main.Format.MGF ? 2 : 1 : 0;
|
||||
A.Data.Format = Format;
|
||||
|
||||
if (format != "1" && format != "3") A.A3DCWriter(filepath);
|
||||
else A.A3DAWriter();
|
||||
File.WriteAllBytes(filepath + ".a3da", (format != "1" &&
|
||||
format != "3") ? A.A3DCWriter() : A.A3DAWriter());
|
||||
}
|
||||
A = null;
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,9 +29,9 @@ namespace PD_Tool.Tools
|
||||
Data.STRReader (filepath, ext);
|
||||
Data.MsgPackWriter(filepath, JSON);
|
||||
}
|
||||
else if (ext == ".mp")
|
||||
else if (ext == ".json" || ext == ".mp")
|
||||
{
|
||||
Data.MsgPackReader(filepath, JSON);
|
||||
Data.MsgPackReader(filepath, ext == ".json");
|
||||
Data.STRWriter (filepath);
|
||||
}
|
||||
Data = null;
|
||||
|
||||
Reference in New Issue
Block a user