Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4de7bd32f7 | ||
|
|
93f905d3e1 |
+262
-308
@@ -46,7 +46,7 @@ namespace KKdMainLib.A3DA
|
||||
Data.Header.Format = IO.Format = Main.Format.F;
|
||||
Data.Header.Signature = IO.ReadInt32();
|
||||
if (Data.Header.Signature == 0x41443341) Data.Header = IO.ReadHeader(true);
|
||||
if (Data.Header.Signature != 0x44334123) return 0;
|
||||
if (Data.Header.Signature != 0x44334123) { IO.Close(); return 0; }
|
||||
|
||||
IO.Offset = IO.Position - 4;
|
||||
Data.Header.Signature = IO.ReadInt32();
|
||||
@@ -59,23 +59,23 @@ namespace KKdMainLib.A3DA
|
||||
else if (Data.Header.Signature == 0x5F5F5F43)
|
||||
{
|
||||
Data.Head = new Header();
|
||||
IO.Position = IO.Offset + 0x10;
|
||||
IO.Position = 0x10;
|
||||
IO.ReadInt32();
|
||||
IO.ReadInt32();
|
||||
Data.Head.HeaderOffset = IO.ReadInt32Endian(true);
|
||||
|
||||
IO.Position = IO.Offset + Data.Head.HeaderOffset;
|
||||
if (IO.ReadInt32() != 0x50) return 0;
|
||||
IO.Position = Data.Head.HeaderOffset;
|
||||
if (IO.ReadInt32() != 0x50) { IO.Close(); return 0; }
|
||||
Data.Head.StringOffset = IO.ReadInt32Endian(true);
|
||||
Data.Head.StringLength = IO.ReadInt32Endian(true);
|
||||
Data.Head.Count = IO.ReadInt32Endian(true);
|
||||
if (IO.ReadInt32() != 0x4C42) return 0;
|
||||
if (IO.ReadInt32() != 0x4C42) { IO.Close(); return 0; }
|
||||
Data.Head.BinaryOffset = IO.ReadInt32Endian(true);
|
||||
Data.Head.BinaryLength = IO.ReadInt32Endian(true);
|
||||
|
||||
IO.Position = IO.Offset + Data.Head.StringOffset;
|
||||
IO.Position = Data.Head.StringOffset;
|
||||
}
|
||||
else return 0;
|
||||
else { IO.Close(); return 0; }
|
||||
|
||||
if (Data.Header.Format < Main.Format.F || Data.Header.Format == Main.Format.FT)
|
||||
Data.Head.StringLength = IO.Length - 0x10;
|
||||
@@ -95,6 +95,7 @@ namespace KKdMainLib.A3DA
|
||||
{
|
||||
IO.Position = IO.Offset + Data.Head.BinaryOffset;
|
||||
IO.Offset = IO.Position;
|
||||
IO.Position = 0;
|
||||
A3DCReader();
|
||||
}
|
||||
|
||||
@@ -520,7 +521,8 @@ namespace KKdMainLib.A3DA
|
||||
IO.Write(Data.CameraRoot[SOi0].MT, name, A3DC, IsX, 0b11110);
|
||||
IO.Write(nameView + "aspect=", Data.CameraRoot[i0].ViewPoint.Aspect);
|
||||
if (Data.CameraRoot[i0].ViewPoint.CameraApertureH != null)
|
||||
IO.Write(nameView + "camera_aperture_h=", Data.CameraRoot[i0].ViewPoint.CameraApertureH);
|
||||
IO.Write(nameView + "camera_aperture_h=",
|
||||
Data.CameraRoot[i0].ViewPoint.CameraApertureH);
|
||||
if (Data.CameraRoot[i0].ViewPoint.CameraApertureW != null)
|
||||
IO.Write(nameView + "camera_aperture_w=", Data.CameraRoot[i0].ViewPoint.CameraApertureW);
|
||||
IO.Write(Data.CameraRoot[SOi0].ViewPoint.FocalLength, nameView + "focal_length" + d, A3DC);
|
||||
@@ -1284,14 +1286,46 @@ namespace KKdMainLib.A3DA
|
||||
IO.Write(Key.Trans.Length);
|
||||
for (i = 0; i < Key.Trans.Length; i++)
|
||||
{
|
||||
if (F16 && CompressF16 > 0)
|
||||
{ IO.Write((ushort)Key.Trans[i].Frame ); IO.Write(( Half)Key.Trans[i].Value[0]); }
|
||||
else
|
||||
{ IO.Write(( float)Key.Trans[i].Frame ); IO.Write((float)Key.Trans[i].Value[0]); }
|
||||
if (F16 && CompressF16 == 2)
|
||||
{ IO.Write(( Half)Key.Trans[i].Value[1]); IO.Write(( Half)Key.Trans[i].Value[2]); }
|
||||
else
|
||||
{ IO.Write(( float)Key.Trans[i].Value[1]); IO.Write((float)Key.Trans[i].Value[2]); }
|
||||
if (Key.Trans[i] is KeyFrameT0<double, double> TransT0)
|
||||
{
|
||||
if (F16 && CompressF16 > 0)
|
||||
{ IO.Write((ushort)TransT0.Frame); IO.Write((ushort)0); }
|
||||
else
|
||||
{ IO.Write(( float)TransT0.Frame); IO.Write(( float)0); }
|
||||
if (F16 && CompressF16 == 2) IO.Write(0 );
|
||||
else IO.Write(0L);
|
||||
}
|
||||
else if (Key.Trans[i] is KeyFrameT1<double, double> TransT1)
|
||||
{
|
||||
if (F16 && CompressF16 > 0)
|
||||
{ IO.Write((ushort)TransT1.Frame); IO.Write(( Half)TransT1.Value); }
|
||||
else
|
||||
{ IO.Write(( float)TransT1.Frame); IO.Write((float)TransT1.Value); }
|
||||
if (F16 && CompressF16 == 2) IO.Write(0 );
|
||||
else IO.Write(0L);
|
||||
}
|
||||
else if (Key.Trans[i] is KeyFrameT2<double, double> TransT2)
|
||||
{
|
||||
if (F16 && CompressF16 > 0)
|
||||
{ IO.Write((ushort)TransT2.Frame); IO.Write(( Half)TransT2.Value); }
|
||||
else
|
||||
{ IO.Write(( float)TransT2.Frame); IO.Write((float)TransT2.Value); }
|
||||
if (F16 && CompressF16 == 2)
|
||||
{ IO.Write(( Half)TransT2.Interpolation); IO.Write(( Half)TransT2.Interpolation); }
|
||||
else
|
||||
{ IO.Write(( float)TransT2.Interpolation); IO.Write((float)TransT2.Interpolation); }
|
||||
}
|
||||
else if (Key.Trans[i] is KeyFrameT3<double, double> TransT3)
|
||||
{
|
||||
if (F16 && CompressF16 > 0)
|
||||
{ IO.Write((ushort)TransT3.Frame); IO.Write(( Half)TransT3.Value); }
|
||||
else
|
||||
{ IO.Write(( float)TransT3.Frame); IO.Write((float)TransT3.Value); }
|
||||
if (F16 && CompressF16 == 2)
|
||||
{ IO.Write(( Half)TransT3.Interpolation1); IO.Write(( Half)TransT3.Interpolation2); }
|
||||
else
|
||||
{ IO.Write(( float)TransT3.Interpolation1); IO.Write((float)TransT3.Interpolation2); }
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1316,13 +1350,12 @@ namespace KKdMainLib.A3DA
|
||||
int i0 = 0;
|
||||
int i1 = 0;
|
||||
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
|
||||
if (!MsgPack.Element("A3D", out MsgPack A3D)) { MsgPack = null; return; }
|
||||
if (!MsgPack.Element("A3D", out MsgPack A3D)) { MsgPack = MsgPack.New; return; }
|
||||
|
||||
Data.Header = new PDHead();
|
||||
Enum.TryParse(A3D.ReadString("Format"), out Data.Header.Format);
|
||||
MsgPack Temp = new MsgPack();
|
||||
MsgPack Temp = MsgPack.New;
|
||||
|
||||
if (A3D.Element("_", out Temp))
|
||||
{
|
||||
@@ -1335,21 +1368,17 @@ namespace KKdMainLib.A3DA
|
||||
};
|
||||
}
|
||||
|
||||
if (A3D.Element<MsgPack>("Ambient", out Temp))
|
||||
if (A3D.ElementArray("Ambient", out Temp))
|
||||
{
|
||||
Data.Ambient = new Ambient[Temp.Array.Length];
|
||||
MsgPack Ambient;
|
||||
|
||||
for (i = 0; i < Data.Ambient.Length; i++)
|
||||
{
|
||||
Ambient = Temp[i] as MsgPack;
|
||||
Data.Ambient[i] = new Ambient
|
||||
{
|
||||
Name = Ambient.ReadString ( "Name"),
|
||||
LightDiffuse = Ambient.ReadRGBAKey( "LightDiffuse"),
|
||||
RimLightDiffuse = Ambient.ReadRGBAKey("RimLightDiffuse"),
|
||||
Name = Temp[i].ReadString ( "Name"),
|
||||
LightDiffuse = Temp[i].ReadRGBAKey( "LightDiffuse"),
|
||||
RimLightDiffuse = Temp[i].ReadRGBAKey("RimLightDiffuse"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (A3D.Element("CameraAuxiliary", out Temp))
|
||||
@@ -1362,19 +1391,17 @@ namespace KKdMainLib.A3DA
|
||||
Saturate = Temp.ReadKey("Saturate" ),
|
||||
};
|
||||
|
||||
if (A3D.Element<MsgPack>("CameraRoot", out Temp))
|
||||
if (A3D.ElementArray("CameraRoot", out Temp))
|
||||
{
|
||||
Data.CameraRoot = new CameraRoot[Temp.Array.Length];
|
||||
MsgPack _Root;
|
||||
for (i = 0; i < Data.CameraRoot.Length; i++)
|
||||
{
|
||||
_Root = Temp[i] as MsgPack;
|
||||
Data.CameraRoot[i] = new CameraRoot
|
||||
{
|
||||
MT = _Root.ReadMT(),
|
||||
Interest = _Root.ReadMT("Interest"),
|
||||
MT = Temp[i].ReadMT(),
|
||||
Interest = Temp[i].ReadMT("Interest"),
|
||||
};
|
||||
if (!_Root.Element("ViewPoint", out MsgPack ViewPoint)) continue;
|
||||
if (!Temp[i].Element("ViewPoint", out MsgPack ViewPoint)) continue;
|
||||
|
||||
Data.CameraRoot[i].ViewPoint = new ViewPoint
|
||||
{
|
||||
@@ -1390,26 +1417,22 @@ namespace KKdMainLib.A3DA
|
||||
}
|
||||
}
|
||||
|
||||
if (A3D.Element<MsgPack>("Chara", out Temp))
|
||||
if (A3D.ElementArray("Chara", out Temp))
|
||||
{
|
||||
Data.Chara = new ModelTransform[Temp.Array.Length];
|
||||
for (i = 0; i < Data.Chara.Length; i++)
|
||||
Data.Chara[i] = (Temp[i] as MsgPack).ReadMT();
|
||||
Data.Chara[i] = Temp[i].ReadMT();
|
||||
}
|
||||
|
||||
if (A3D.Element<MsgPack>("Curve", out Temp))
|
||||
if (A3D.ElementArray("Curve", out Temp))
|
||||
{
|
||||
Data.Curve = new Curve[Temp.Array.Length];
|
||||
MsgPack Curve;
|
||||
for (i = 0; i < Data.Curve.Length; i++)
|
||||
{
|
||||
Curve = Temp[i] as MsgPack;
|
||||
Data.Curve[i] = new Curve
|
||||
{
|
||||
Name = Curve.ReadString("Name"),
|
||||
CV = Curve.ReadKey ("CV"),
|
||||
Name = Temp[i].ReadString("Name"),
|
||||
CV = Temp[i].ReadKey ("CV" ),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (A3D.Element("DOF", out Temp))
|
||||
@@ -1419,102 +1442,82 @@ namespace KKdMainLib.A3DA
|
||||
Name = Temp.ReadString("Name"),
|
||||
};
|
||||
|
||||
if (A3D.Element<MsgPack>("Event", out Temp))
|
||||
if (A3D.ElementArray("Event", out Temp))
|
||||
{
|
||||
Data.Event = new Event[Temp.Array.Length];
|
||||
MsgPack Event;
|
||||
for (i = 0; i < Data.Event.Length; i++)
|
||||
{
|
||||
Event = Temp[i] as MsgPack;
|
||||
Data.Event[i] = new Event
|
||||
{
|
||||
Begin = Event.ReadNDouble( "Begin" ),
|
||||
ClipBegin = Event.ReadNDouble("ClipBegin" ),
|
||||
ClipEnd = Event.ReadNDouble("ClipEnd" ),
|
||||
End = Event.ReadNDouble( "End" ),
|
||||
Name = Event.ReadString ("Name" ),
|
||||
Param1 = Event.ReadString ("Param1" ),
|
||||
Ref = Event.ReadString ("Ref" ),
|
||||
TimeRefScale = Event.ReadNDouble("TimeRefScale"),
|
||||
Type = Event.ReadNInt32 ("Type" ),
|
||||
Begin = Temp[i].ReadNDouble( "Begin" ),
|
||||
ClipBegin = Temp[i].ReadNDouble("ClipBegin" ),
|
||||
ClipEnd = Temp[i].ReadNDouble("ClipEnd" ),
|
||||
End = Temp[i].ReadNDouble( "End" ),
|
||||
Name = Temp[i].ReadString ("Name" ),
|
||||
Param1 = Temp[i].ReadString ("Param1" ),
|
||||
Ref = Temp[i].ReadString ("Ref" ),
|
||||
TimeRefScale = Temp[i].ReadNDouble("TimeRefScale"),
|
||||
Type = Temp[i].ReadNInt32 ("Type" ),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (A3D.Element<MsgPack>("Fog", out Temp))
|
||||
if (A3D.ElementArray("Fog", out Temp))
|
||||
{
|
||||
Data.Fog = new Fog[Temp.Array.Length];
|
||||
MsgPack Fog;
|
||||
for (i = 0; i < Data.Fog.Length; i++)
|
||||
{
|
||||
Fog = Temp[i] as MsgPack;
|
||||
Data.Fog[i] = new Fog
|
||||
{
|
||||
Id = Fog.ReadNInt32 ("Id" ),
|
||||
Density = Fog.ReadKey ("Density"),
|
||||
Diffuse = Fog.ReadRGBAKey("Diffuse"),
|
||||
End = Fog.ReadKey ("End" ),
|
||||
Start = Fog.ReadKey ("Start" ),
|
||||
Id = Temp[i].ReadNInt32 ("Id" ),
|
||||
Density = Temp[i].ReadKey ("Density"),
|
||||
Diffuse = Temp[i].ReadRGBAKey("Diffuse"),
|
||||
End = Temp[i].ReadKey ("End" ),
|
||||
Start = Temp[i].ReadKey ("Start" ),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (A3D.Element<MsgPack>("Light", out Temp))
|
||||
if (A3D.ElementArray("Light", out Temp))
|
||||
{
|
||||
Data.Light = new Light[Temp.Array.Length];
|
||||
MsgPack Light = new MsgPack();
|
||||
for (i = 0; i < Data.Light.Length; i++)
|
||||
{
|
||||
Light = Temp[i] as MsgPack;
|
||||
Data.Light[i] = new Light
|
||||
{
|
||||
Id = Light.ReadNInt32 ("Id" ),
|
||||
Name = Light.ReadString ("Name" ),
|
||||
Type = Light.ReadString ("Type" ),
|
||||
Ambient = Light.ReadRGBAKey("Ambient" ),
|
||||
Diffuse = Light.ReadRGBAKey("Diffuse" ),
|
||||
Incandescence = Light.ReadRGBAKey("Incandescence"),
|
||||
Position = Light.ReadMT ("Position" ),
|
||||
Specular = Light.ReadRGBAKey("Specular" ),
|
||||
SpotDirection = Light.ReadMT ("SpotDirection"),
|
||||
Id = Temp[i].ReadNInt32 ("Id" ),
|
||||
Name = Temp[i].ReadString ("Name" ),
|
||||
Type = Temp[i].ReadString ("Type" ),
|
||||
Ambient = Temp[i].ReadRGBAKey("Ambient" ),
|
||||
Diffuse = Temp[i].ReadRGBAKey("Diffuse" ),
|
||||
Incandescence = Temp[i].ReadRGBAKey("Incandescence"),
|
||||
Position = Temp[i].ReadMT ("Position" ),
|
||||
Specular = Temp[i].ReadRGBAKey("Specular" ),
|
||||
SpotDirection = Temp[i].ReadMT ("SpotDirection"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (A3D.Element<MsgPack>("MaterialList", out Temp))
|
||||
if (A3D.ElementArray("MaterialList", out Temp))
|
||||
{
|
||||
Data.MaterialList = new MaterialList[Temp.Array.Length];
|
||||
MsgPack MaterialList = new MsgPack();
|
||||
for (i = 0; i < Data.MaterialList.Length; i++)
|
||||
{
|
||||
MaterialList = Temp[i] as MsgPack;
|
||||
Data.MaterialList[i] = new MaterialList
|
||||
{
|
||||
HashName = MaterialList.ReadString ( "HashName"),
|
||||
Name = MaterialList.ReadString ( "Name"),
|
||||
BlendColor = MaterialList.ReadRGBAKey( "BlendColor"),
|
||||
GlowIntensity = MaterialList.ReadKey ("GlowIntensity"),
|
||||
Incandescence = MaterialList.ReadRGBAKey("Incandescence"),
|
||||
HashName = Temp[i].ReadString ( "HashName"),
|
||||
Name = Temp[i].ReadString ( "Name"),
|
||||
BlendColor = Temp[i].ReadRGBAKey( "BlendColor"),
|
||||
GlowIntensity = Temp[i].ReadKey ("GlowIntensity"),
|
||||
Incandescence = Temp[i].ReadRGBAKey("Incandescence"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (A3D.Element<MsgPack>("MObjectHRC", out Temp))
|
||||
if (A3D.ElementArray("MObjectHRC", out Temp))
|
||||
{
|
||||
Data.MObjectHRC = new MObjectHRC[Temp.Array.Length];
|
||||
MsgPack _Node = new MsgPack();
|
||||
MsgPack _Instance = new MsgPack();
|
||||
MsgPack MObjectHRC = new MsgPack();
|
||||
for (i0 = 0; i0 < Data.MObjectHRC.Length; i0++)
|
||||
{
|
||||
MObjectHRC = Temp[i0] as MsgPack;
|
||||
Data.MObjectHRC[i0] = new MObjectHRC
|
||||
{
|
||||
MT = MObjectHRC.ReadMT(),
|
||||
Name = MObjectHRC.ReadString("Name"),
|
||||
MT = Temp[i].ReadMT(),
|
||||
Name = Temp[i].ReadString("Name"),
|
||||
};
|
||||
|
||||
if (MObjectHRC.Element("JointOrient", out MsgPack JointOrient))
|
||||
if (Temp[i].Element("JointOrient", out MsgPack JointOrient))
|
||||
Data.MObjectHRC[i0].JointOrient = new Vector3<double?>
|
||||
{
|
||||
X = JointOrient.ReadDouble("X"),
|
||||
@@ -1522,125 +1525,105 @@ namespace KKdMainLib.A3DA
|
||||
Z = JointOrient.ReadDouble("Z"),
|
||||
};
|
||||
|
||||
if (MObjectHRC.Element<MsgPack>("Instance", out MsgPack Instance))
|
||||
if (Temp[i].ElementArray("Instance", out MsgPack Instance))
|
||||
{
|
||||
Data.MObjectHRC[i0].Instance = new Instance[Instance.Array.Length];
|
||||
for (i1 = 0; i1 < Data.MObjectHRC[i0].Instance.Length; i1++)
|
||||
{
|
||||
_Instance = Instance[i1] as MsgPack;
|
||||
Data.MObjectHRC[i0].Instance[i1] = new Instance
|
||||
{
|
||||
MT = _Instance.ReadMT(),
|
||||
Name = _Instance.ReadString( "Name"),
|
||||
Shadow = _Instance.ReadNInt32( "Shadow"),
|
||||
UIDName = _Instance.ReadString("UIDName"),
|
||||
MT = Instance[i1].ReadMT(),
|
||||
Name = Instance[i1].ReadString( "Name"),
|
||||
Shadow = Instance[i1].ReadNInt32( "Shadow"),
|
||||
UIDName = Instance[i1].ReadString("UIDName"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (MObjectHRC.Element<MsgPack>("Node", out MsgPack Node))
|
||||
if (Temp[i].ElementArray("Node", out MsgPack Node))
|
||||
{
|
||||
Data.MObjectHRC[i0].Node = new Node[Temp.Array.Length];
|
||||
for (i1 = 0; i1 < Data.MObjectHRC[i0].Node.Length; i1++)
|
||||
{
|
||||
_Node = Node[i1] as MsgPack;
|
||||
Data.MObjectHRC[i0].Node[i1] = new Node
|
||||
{
|
||||
MT = _Node.ReadMT(),
|
||||
Name = _Node.ReadString( "Name"),
|
||||
Parent = _Node.ReadNInt32("Parent"),
|
||||
MT = Node[i1].ReadMT(),
|
||||
Name = Node[i1].ReadString( "Name"),
|
||||
Parent = Node[i1].ReadNInt32("Parent"),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (A3D.Element<MsgPack>("MObjectHRCList", out Temp))
|
||||
if (A3D.ElementArray("MObjectHRCList", out Temp))
|
||||
{
|
||||
Data.MObjectHRCList = new string[Temp.Array.Length];
|
||||
for (i = 0; i < Data.MObjectHRCList.Length; i++)
|
||||
Data.MObjectHRCList[i] = (Temp[i] as MsgPack).ReadString();
|
||||
Data.MObjectHRCList[i] = Temp[i].ReadString();
|
||||
}
|
||||
|
||||
if (A3D.Element<MsgPack>("Motion", out Temp))
|
||||
if (A3D.ElementArray("Motion", out Temp))
|
||||
{
|
||||
Data.Motion = new string[Temp.Array.Length];
|
||||
for (i = 0; i < Data.Motion.Length; i++)
|
||||
Data.Motion[i] = (Temp[i] as MsgPack).ReadString();
|
||||
Data.Motion[i] = Temp[i].ReadString();
|
||||
}
|
||||
|
||||
if (A3D.Element<MsgPack>("Object", out Temp))
|
||||
if (A3D.ElementArray("Object", out Temp))
|
||||
{
|
||||
Data.Object = new Object[Temp.Array.Length];
|
||||
MsgPack _TP = new MsgPack();
|
||||
MsgPack _TT = new MsgPack();
|
||||
MsgPack Object = new MsgPack();
|
||||
for (i0 = 0; i0 < Data.Object.Length; i0++)
|
||||
{
|
||||
Object = Temp[i0] as MsgPack;
|
||||
Data.Object[i0] = new Object
|
||||
{
|
||||
MT = Object.ReadMT(),
|
||||
Morph = Object.ReadString("Morph" ),
|
||||
MorphOffset = Object.ReadNInt32("MorphOffset"),
|
||||
Name = Object.ReadString( "Name"),
|
||||
ParentName = Object.ReadString( "ParentName"),
|
||||
UIDName = Object.ReadString( "UIDName"),
|
||||
MT = Temp[i].ReadMT(),
|
||||
Morph = Temp[i].ReadString("Morph" ),
|
||||
MorphOffset = Temp[i].ReadNInt32("MorphOffset"),
|
||||
Name = Temp[i].ReadString( "Name"),
|
||||
ParentName = Temp[i].ReadString( "ParentName"),
|
||||
UIDName = Temp[i].ReadString( "UIDName"),
|
||||
};
|
||||
|
||||
if (Object.Element<MsgPack>("TP", out MsgPack TP))
|
||||
if (Temp[i].ElementArray("TP", out MsgPack TP))
|
||||
{
|
||||
Data.Object[i0].TP = new Object.TexturePattern[TP.Array.Length];
|
||||
for (i1 = 0; i1 < Data.Object[i0].TP.Length; i1++)
|
||||
{
|
||||
_TP = TP[i1] as MsgPack;
|
||||
Data.Object[i0].TP[i1] = new Object.TexturePattern
|
||||
{
|
||||
Name = _TP.ReadString("Name" ),
|
||||
Pat = _TP.ReadString("Pat" ),
|
||||
PatOffset = _TP.ReadNInt32("PatOffset"),
|
||||
Name = TP[i1].ReadString("Name" ),
|
||||
Pat = TP[i1].ReadString("Pat" ),
|
||||
PatOffset = TP[i1].ReadNInt32("PatOffset"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.Element<MsgPack>("TT", out MsgPack TT))
|
||||
if (Temp[i].ElementArray("TT", out MsgPack TT))
|
||||
{
|
||||
Data.Object[i0].TT = new Object.TextureTransform[TT.Array.Length];
|
||||
for (i1 = 0; i1 < Data.Object[i0].TT.Length; i1++)
|
||||
{
|
||||
_TT = TT[i1] as MsgPack;
|
||||
Data.Object[i0].TT[i1] = new Object.TextureTransform
|
||||
{
|
||||
Name = _TT.ReadString("Name"),
|
||||
C = _TT.ReadKeyUV ("C" ),
|
||||
O = _TT.ReadKeyUV ("O" ),
|
||||
R = _TT.ReadKeyUV ("R" ),
|
||||
Ro = _TT.ReadKey ("Ro" ),
|
||||
RF = _TT.ReadKey ("RF" ),
|
||||
TF = _TT.ReadKeyUV ("TF" ),
|
||||
Name = TT[i1].ReadString("Name"),
|
||||
C = TT[i1].ReadKeyUV ("C" ),
|
||||
O = TT[i1].ReadKeyUV ("O" ),
|
||||
R = TT[i1].ReadKeyUV ("R" ),
|
||||
Ro = TT[i1].ReadKey ("Ro" ),
|
||||
RF = TT[i1].ReadKey ("RF" ),
|
||||
TF = TT[i1].ReadKeyUV ("TF" ),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (A3D.Element<MsgPack>("ObjectHRC", out Temp))
|
||||
if (A3D.ElementArray("ObjectHRC", out Temp))
|
||||
{
|
||||
Data.ObjectHRC = new ObjectHRC[Temp.Array.Length];
|
||||
MsgPack _Node = new MsgPack();
|
||||
MsgPack _Instance = new MsgPack();
|
||||
MsgPack ObjectHRC = new MsgPack();
|
||||
for (i0 = 0; i0 < Data.ObjectHRC.Length; i0++)
|
||||
{
|
||||
ObjectHRC = Temp[i0] as MsgPack;
|
||||
Data.ObjectHRC[i0] = new ObjectHRC
|
||||
{
|
||||
Name = ObjectHRC.ReadString ( "Name"),
|
||||
Shadow = ObjectHRC.ReadNDouble( "Shadow"),
|
||||
UIDName = ObjectHRC.ReadString ("UIDName"),
|
||||
Name = Temp[i].ReadString ( "Name"),
|
||||
Shadow = Temp[i].ReadNDouble( "Shadow"),
|
||||
UIDName = Temp[i].ReadString ("UIDName"),
|
||||
};
|
||||
|
||||
if (ObjectHRC.Element("JointOrient", out MsgPack JointOrient))
|
||||
if (Temp[i].Element("JointOrient", out MsgPack JointOrient))
|
||||
Data.ObjectHRC[i0].JointOrient = new Vector3<double?>
|
||||
{
|
||||
X = JointOrient.ReadDouble("X"),
|
||||
@@ -1648,35 +1631,32 @@ namespace KKdMainLib.A3DA
|
||||
Z = JointOrient.ReadDouble("Z"),
|
||||
};
|
||||
|
||||
if (ObjectHRC.Element<MsgPack>("Node", out MsgPack Node))
|
||||
if (Temp[i].ElementArray("Node", out MsgPack Node))
|
||||
{
|
||||
Data.ObjectHRC[i0].Node = new Node[Node.Array.Length];
|
||||
for (i1 = 0; i1 < Data.ObjectHRC[i0].Node.Length; i1++)
|
||||
{
|
||||
_Node = Node[i1] as MsgPack;
|
||||
Data.ObjectHRC[i0].Node[i1] = new Node
|
||||
{
|
||||
MT = _Node.ReadMT(),
|
||||
Name = _Node.ReadString( "Name"),
|
||||
Parent = _Node.ReadInt32 ("Parent"),
|
||||
MT = Node[i1].ReadMT(),
|
||||
Name = Node[i1].ReadString( "Name"),
|
||||
Parent = Node[i1].ReadInt32 ("Parent"),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (A3D.Element<MsgPack>("ObjectHRCList", out Temp))
|
||||
if (A3D.ElementArray("ObjectHRCList", out Temp))
|
||||
{
|
||||
Data.ObjectHRCList = new string[Temp.Array.Length];
|
||||
for (i = 0; i < Data.ObjectHRCList.Length; i++)
|
||||
Data.ObjectHRCList[i] = (Temp[i] as MsgPack).ReadString();
|
||||
Data.ObjectHRCList[i] = Temp[i].ReadString();
|
||||
}
|
||||
|
||||
if (A3D.Element<MsgPack>("ObjectList", out Temp))
|
||||
if (A3D.ElementArray("ObjectList", out Temp))
|
||||
{
|
||||
Data.ObjectList = new string[Temp.Array.Length];
|
||||
for (i = 0; i < Data.ObjectList.Length; i++)
|
||||
Data.ObjectList[i] = (Temp[i] as MsgPack).ReadString();
|
||||
Data.ObjectList[i] = Temp[i].ReadString();
|
||||
}
|
||||
|
||||
if (A3D.Element("PlayControl", out Temp))
|
||||
@@ -1689,11 +1669,11 @@ namespace KKdMainLib.A3DA
|
||||
Size = Temp.ReadNDouble("Size" ),
|
||||
};
|
||||
|
||||
if (A3D.Element<MsgPack>("Point", out Temp))
|
||||
if (A3D.ElementArray("Point", out Temp))
|
||||
{
|
||||
Data.Point = new ModelTransform[Temp.Array.Length];
|
||||
for (i = 0; i < Data.Point.Length; i++)
|
||||
Data.Point[i] = (Temp[i] as MsgPack).ReadMT();
|
||||
Data.Point[i] = Temp[i].ReadMT();
|
||||
}
|
||||
|
||||
if (A3D.Element("PostProcess", out Temp))
|
||||
@@ -1706,9 +1686,6 @@ namespace KKdMainLib.A3DA
|
||||
LensShaft = Temp.ReadKey ("LensShaft"),
|
||||
Specular = Temp.ReadRGBAKey("Specular" ),
|
||||
};
|
||||
|
||||
Temp = null;
|
||||
MsgPack = null;
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
@@ -1718,7 +1695,6 @@ namespace KKdMainLib.A3DA
|
||||
int i1 = 0;
|
||||
|
||||
MsgPack A3D = new MsgPack("A3D")
|
||||
.Add("Format", Data.Header.Format.ToString())
|
||||
.Add(new MsgPack("_").Add("CompressF16" , Data._.CompressF16 )
|
||||
.Add("ConverterVersion", Data._.ConverterVersion)
|
||||
.Add("FileName" , Data._.FileName )
|
||||
@@ -1726,112 +1702,111 @@ namespace KKdMainLib.A3DA
|
||||
|
||||
if (Data.Ambient != null)
|
||||
{
|
||||
MsgPack Ambient = new MsgPack("Ambient", Data.Ambient.Length);
|
||||
MsgPack Ambient = new MsgPack(Data.Ambient.Length, "Ambient");
|
||||
for (i = 0; i < Data.Ambient.Length; i++)
|
||||
Ambient[i] = new MsgPack()
|
||||
.Add(Data.Ambient[i]. LightDiffuse.WriteMP( "LightDiffuse"))
|
||||
.Add("Name", Data.Ambient[i].Name)
|
||||
.Add(Data.Ambient[i].RimLightDiffuse.WriteMP("RimLightDiffuse"));
|
||||
Ambient[i] = MsgPack.New.Add( "LightDiffuse", Data.Ambient[i]. LightDiffuse)
|
||||
.Add("Name" , Data.Ambient[i].Name )
|
||||
.Add("RimLightDiffuse", Data.Ambient[i].RimLightDiffuse);
|
||||
A3D.Add(Ambient);
|
||||
}
|
||||
|
||||
if (Data.CameraAuxiliary != null)
|
||||
A3D.Add(new MsgPack("CameraAuxiliary")
|
||||
.Add(Data.CameraAuxiliary.AutoExposure.WriteMP("AutoExposure"))
|
||||
.Add(Data.CameraAuxiliary. Exposure.WriteMP( "Exposure"))
|
||||
.Add(Data.CameraAuxiliary.Gamma .WriteMP("Gamma" ))
|
||||
.Add(Data.CameraAuxiliary.GammaRate .WriteMP("GammaRate" ))
|
||||
.Add(Data.CameraAuxiliary.Saturate .WriteMP("Saturate" )));
|
||||
.Add("AutoExposure", Data.CameraAuxiliary.AutoExposure)
|
||||
.Add( "Exposure", Data.CameraAuxiliary. Exposure)
|
||||
.Add("Gamma" , Data.CameraAuxiliary.Gamma )
|
||||
.Add("GammaRate" , Data.CameraAuxiliary.GammaRate )
|
||||
.Add("Saturate" , Data.CameraAuxiliary.Saturate ));
|
||||
|
||||
if (Data.CameraRoot != null)
|
||||
{
|
||||
MsgPack CameraRoot = new MsgPack("CameraRoot", Data.CameraRoot.Length);
|
||||
MsgPack CameraRoot = new MsgPack(Data.CameraRoot.Length, "CameraRoot");
|
||||
for (i = 0; i < Data.CameraRoot.Length; i++)
|
||||
{
|
||||
CameraRoot[i] = Data.CameraRoot[i].MT.WriteMP()
|
||||
.Add(Data.CameraRoot[i].Interest .WriteMP("Interest"))
|
||||
.Add(Data.CameraRoot[i].ViewPoint.MT.WriteMP("ViewPoint")
|
||||
.Add("Aspect" , Data.CameraRoot[i].ViewPoint.Aspect )
|
||||
.Add("CameraApertureH", Data.CameraRoot[i].ViewPoint.CameraApertureH)
|
||||
.Add("CameraApertureW", Data.CameraRoot[i].ViewPoint.CameraApertureW)
|
||||
.Add("FOVHorizontal" , Data.CameraRoot[i].ViewPoint.FOVHorizontal )
|
||||
.Add(Data.CameraRoot[i].ViewPoint.FocalLength.WriteMP("FocalLength"))
|
||||
.Add(Data.CameraRoot[i].ViewPoint.FOV .WriteMP("FOV" ))
|
||||
.Add(Data.CameraRoot[i].ViewPoint.Roll .WriteMP("Roll" )));
|
||||
CameraRoot[i] = MsgPack.New
|
||||
.Add(null, Data.CameraRoot[i].MT)
|
||||
.Add("Interest" , Data.CameraRoot[i].Interest )
|
||||
.Add(new MsgPack("ViewPoint")
|
||||
.Add(null, Data.CameraRoot[i].ViewPoint.MT)
|
||||
.Add("Aspect" , Data.CameraRoot[i].ViewPoint.Aspect )
|
||||
.Add("CameraApertureH", Data.CameraRoot[i].ViewPoint.CameraApertureH)
|
||||
.Add("CameraApertureW", Data.CameraRoot[i].ViewPoint.CameraApertureW)
|
||||
.Add("FOVHorizontal" , Data.CameraRoot[i].ViewPoint.FOVHorizontal )
|
||||
.Add("FocalLength" , Data.CameraRoot[i].ViewPoint.FocalLength )
|
||||
.Add("FOV" , Data.CameraRoot[i].ViewPoint.FOV )
|
||||
.Add("Roll" , Data.CameraRoot[i].ViewPoint.Roll ));
|
||||
}
|
||||
A3D.Add(CameraRoot);
|
||||
}
|
||||
|
||||
if (Data.Chara != null)
|
||||
{
|
||||
MsgPack Chara = new MsgPack("Chara", Data.Chara.Length);
|
||||
for (i = 0; i < Data.Curve.Length; i++) Chara[i] = Data.Chara[i].WriteMP();
|
||||
MsgPack Chara = new MsgPack(Data.Chara.Length, "Chara");
|
||||
for (i = 0; i < Data.Curve.Length; i++) Chara[i] = MsgPack.New.Add(null, Data.Chara[i]);
|
||||
A3D.Add(Chara);
|
||||
}
|
||||
|
||||
if (Data.Curve != null)
|
||||
{
|
||||
MsgPack Curve = new MsgPack("Curve", Data.Curve.Length);
|
||||
MsgPack Curve = new MsgPack(Data.Curve.Length, "Curve");
|
||||
for (i = 0; i < Data.Curve.Length; i++)
|
||||
Curve[i] = new MsgPack().Add("Name", Data.Curve[i].Name)
|
||||
.Add(Data.Curve[i].CV.WriteMP("CV"));
|
||||
Curve[i] = MsgPack.New.Add("Name", Data.Curve[i].Name).Add("CV", Data.Curve[i].CV);
|
||||
A3D.Add(Curve);
|
||||
}
|
||||
|
||||
if (Data.DOF != null)
|
||||
A3D.Add(new MsgPack("DOF").Add("Name", Data.DOF.Name).Add(Data.DOF.MT.WriteMP("MT")));
|
||||
A3D.Add(new MsgPack("DOF").Add("Name", Data.DOF.Name).Add("MT", Data.DOF.MT));
|
||||
|
||||
if (Data.Event != null)
|
||||
{
|
||||
MsgPack Event = new MsgPack("Events", Data.Event.Length);
|
||||
MsgPack Event = new MsgPack(Data.Event.Length, "Events");
|
||||
for (i = 0; i < Data.Event.Length; i++)
|
||||
Event[i] = new MsgPack().Add("Begin" , Data.Event[i].Begin )
|
||||
.Add("ClipBegin" , Data.Event[i].ClipBegin )
|
||||
.Add("ClipEnd" , Data.Event[i].ClipEnd )
|
||||
.Add("End" , Data.Event[i].End )
|
||||
.Add("Name" , Data.Event[i].Name )
|
||||
.Add("Param1" , Data.Event[i].Param1 )
|
||||
.Add("Ref" , Data.Event[i].Ref )
|
||||
.Add("TimeRefScale", Data.Event[i].TimeRefScale)
|
||||
.Add("Type" , Data.Event[i].Type );
|
||||
Event[i] = MsgPack.New.Add("Begin" , Data.Event[i].Begin )
|
||||
.Add("ClipBegin" , Data.Event[i].ClipBegin )
|
||||
.Add("ClipEnd" , Data.Event[i].ClipEnd )
|
||||
.Add("End" , Data.Event[i].End )
|
||||
.Add("Name" , Data.Event[i].Name )
|
||||
.Add("Param1" , Data.Event[i].Param1 )
|
||||
.Add("Ref" , Data.Event[i].Ref )
|
||||
.Add("TimeRefScale", Data.Event[i].TimeRefScale)
|
||||
.Add("Type" , Data.Event[i].Type );
|
||||
A3D.Add(Event);
|
||||
}
|
||||
|
||||
if (Data.Fog != null)
|
||||
{
|
||||
MsgPack Fog = new MsgPack("Fog", Data.Fog.Length);
|
||||
MsgPack Fog = new MsgPack(Data.Fog.Length, "Fog");
|
||||
for (i = 0; i < Data.Fog.Length; i++)
|
||||
Fog[i] = new MsgPack().Add("Id", Data.Fog[i].Id)
|
||||
.Add(Data.Fog[i].Density.WriteMP("Density"))
|
||||
.Add(Data.Fog[i].Diffuse.WriteMP("Diffuse"))
|
||||
.Add(Data.Fog[i].End .WriteMP("End" ))
|
||||
.Add(Data.Fog[i].Start .WriteMP("Start" ));
|
||||
Fog[i] = MsgPack.New.Add("Id" , Data.Fog[i].Id )
|
||||
.Add("Density", Data.Fog[i].Density)
|
||||
.Add("Diffuse", Data.Fog[i].Diffuse)
|
||||
.Add("End" , Data.Fog[i].End )
|
||||
.Add("Start" , Data.Fog[i].Start );
|
||||
A3D.Add(Fog);
|
||||
}
|
||||
|
||||
if (Data.Light != null)
|
||||
{
|
||||
MsgPack Light = new MsgPack("Light", Data.Light.Length);
|
||||
MsgPack Light = new MsgPack(Data.Light.Length, "Light");
|
||||
for (i = 0; i < Data.Light.Length; i++)
|
||||
Light[i] = new MsgPack()
|
||||
.Add("Id", Data.Light[i].Id)
|
||||
.Add("Name", Data.Light[i].Name)
|
||||
.Add("Type", Data.Light[i].Type)
|
||||
.Add(Data.Light[i].Ambient .WriteMP("Ambient" ))
|
||||
.Add(Data.Light[i].Diffuse .WriteMP("Diffuse" ))
|
||||
.Add(Data.Light[i].Incandescence.WriteMP("Incandescence"))
|
||||
.Add(Data.Light[i].Position .WriteMP("Position" ))
|
||||
.Add(Data.Light[i].Specular .WriteMP("Specular" ))
|
||||
.Add(Data.Light[i].SpotDirection.WriteMP("SpotDirection"));
|
||||
Light[i] = MsgPack.New.Add("Id" , Data.Light[i].Id )
|
||||
.Add("Name" , Data.Light[i].Name )
|
||||
.Add("Type" , Data.Light[i].Type )
|
||||
.Add("Ambient" , Data.Light[i].Ambient )
|
||||
.Add("Diffuse" , Data.Light[i].Diffuse )
|
||||
.Add("Incandescence", Data.Light[i].Incandescence)
|
||||
.Add("Position" , Data.Light[i].Position )
|
||||
.Add("Specular" , Data.Light[i].Specular )
|
||||
.Add("SpotDirection", Data.Light[i].SpotDirection);
|
||||
A3D.Add(Light);
|
||||
}
|
||||
|
||||
if (Data.MObjectHRC != null)
|
||||
{
|
||||
MsgPack MObjectHRC = new MsgPack("MObjectHRC", Data.MObjectHRC.Length);
|
||||
MsgPack MObjectHRC = new MsgPack(Data.MObjectHRC.Length, "MObjectHRC");
|
||||
for (i0 = 0; i0 < Data.MObjectHRC.Length; i0++)
|
||||
{
|
||||
MsgPack _MObjectHRC = new MsgPack().Add("Name", Data.MObjectHRC[i0].Name);
|
||||
MsgPack _MObjectHRC = MsgPack.New.Add("Name", Data.MObjectHRC[i0].Name);
|
||||
|
||||
if (IsX && Data.MObjectHRC[i0].JointOrient != null)
|
||||
_MObjectHRC.Add(new MsgPack("JointOrient")
|
||||
@@ -1841,88 +1816,89 @@ namespace KKdMainLib.A3DA
|
||||
|
||||
if (Data.MObjectHRC[i0].Instance != null)
|
||||
{
|
||||
MsgPack Instance = new MsgPack("Instance", Data.MObjectHRC[i0].Instance.Length);
|
||||
MsgPack Instance = new MsgPack(Data.MObjectHRC[i0].Instance.Length, "Instance");
|
||||
for (i1 = 0; i1 < Data.MObjectHRC[i0].Instance.Length; i1++)
|
||||
Instance[i1] = Data.MObjectHRC[i0].Instance[i1].MT.WriteMP(new MsgPack()
|
||||
Instance[i1] = MsgPack.New.Add(null, Data.MObjectHRC[i0].Instance[i1].MT)
|
||||
.Add( "Name", Data.MObjectHRC[i0].Instance[i1]. Name)
|
||||
.Add("Shadow" , Data.MObjectHRC[i0].Instance[i1].Shadow )
|
||||
.Add("UIDName", Data.MObjectHRC[i0].Instance[i1].UIDName));
|
||||
.Add("UIDName", Data.MObjectHRC[i0].Instance[i1].UIDName);
|
||||
_MObjectHRC.Add(Instance);
|
||||
}
|
||||
|
||||
if (Data.MObjectHRC[i0].Node != null)
|
||||
{
|
||||
MsgPack Node = new MsgPack("Node", Data.MObjectHRC[i0].Node.Length);
|
||||
MsgPack Node = new MsgPack(Data.MObjectHRC[i0].Node.Length, "Node");
|
||||
for (i1 = 0; i1 < Data.MObjectHRC[i0].Node.Length; i1++)
|
||||
Node[i1] = Data.MObjectHRC[i0].Node[i1].MT.WriteMP(new MsgPack()
|
||||
Node[i1] = MsgPack.New.Add(null, Data.MObjectHRC[i0].Node[i1].MT)
|
||||
.Add("Name" , Data.MObjectHRC[i0].Node[i1].Name )
|
||||
.Add("Parent", Data.MObjectHRC[i0].Node[i1].Parent));
|
||||
.Add("Parent", Data.MObjectHRC[i0].Node[i1].Parent);
|
||||
_MObjectHRC.Add(Node);
|
||||
}
|
||||
|
||||
MObjectHRC[i0] = Data.MObjectHRC[i0].MT.WriteMP(_MObjectHRC);
|
||||
MObjectHRC[i0] = _MObjectHRC.Add(null, Data.MObjectHRC[i0].MT);
|
||||
}
|
||||
A3D.Add(MObjectHRC);
|
||||
}
|
||||
|
||||
if (Data.MObjectHRCList != null)
|
||||
{
|
||||
MsgPack MObjectHRCList = new MsgPack("MObjectHRCList", Data.MObjectHRCList.Length);
|
||||
for (i = 0; i < Data.MObjectHRCList.Length; i++) MObjectHRCList[i] = Data.MObjectHRCList[i];
|
||||
MsgPack MObjectHRCList = new MsgPack(Data.MObjectHRCList.Length, "MObjectHRCList");
|
||||
for (i = 0; i < Data.MObjectHRCList.Length; i++)
|
||||
MObjectHRCList[i] = (MsgPack)Data.MObjectHRCList[i];
|
||||
A3D.Add(MObjectHRCList);
|
||||
}
|
||||
|
||||
if (Data.MaterialList != null)
|
||||
{
|
||||
MsgPack MaterialList = new MsgPack("MaterialList", Data.MaterialList.Length);
|
||||
MsgPack MaterialList = new MsgPack(Data.MaterialList.Length, "MaterialList");
|
||||
for (i = 0; i < Data.MaterialList.Length; i++)
|
||||
MaterialList[i] = new MsgPack("Material")
|
||||
.Add("HashName", Data.MaterialList[i].HashName)
|
||||
.Add( "Name", Data.MaterialList[i]. Name)
|
||||
.Add(Data.MaterialList[i].BlendColor .WriteMP("BlendColor" ))
|
||||
.Add(Data.MaterialList[i].GlowIntensity.WriteMP("GlowIntensity"))
|
||||
.Add(Data.MaterialList[i].Incandescence.WriteMP("Incandescence"));
|
||||
.Add("HashName" , Data.MaterialList[i].HashName )
|
||||
.Add( "Name" , Data.MaterialList[i]. Name )
|
||||
.Add("BlendColor" , Data.MaterialList[i].BlendColor )
|
||||
.Add("GlowIntensity", Data.MaterialList[i].GlowIntensity)
|
||||
.Add("Incandescence", Data.MaterialList[i].Incandescence);
|
||||
A3D.Add(MaterialList);
|
||||
}
|
||||
|
||||
if (Data.Motion != null)
|
||||
{
|
||||
MsgPack Motion = new MsgPack("Motion", Data.Motion.Length);
|
||||
for (i = 0; i < Data.Motion.Length; i++) Motion[i] = Data.Motion[i];
|
||||
MsgPack Motion = new MsgPack(Data.Motion.Length, "Motion");
|
||||
for (i = 0; i < Data.Motion.Length; i++) Motion[i] = (MsgPack)Data.Motion[i];
|
||||
A3D.Add(Motion);
|
||||
}
|
||||
|
||||
if (Data.Object != null)
|
||||
{
|
||||
MsgPack Object = new MsgPack("Object", Data.Object.Length);
|
||||
MsgPack Object = new MsgPack(Data.Object.Length, "Object");
|
||||
for (i0 = 0; i0 < Data.Object.Length; i0++)
|
||||
{
|
||||
MsgPack _Object = Data.Object[i0].MT.WriteMP(
|
||||
new MsgPack().Add("Morph" , Data.Object[i0].Morph )
|
||||
.Add("MorphOffset", Data.Object[i0].MorphOffset)
|
||||
.Add( "Name" , Data.Object[i0]. Name )
|
||||
.Add("ParentName" , Data.Object[i0].ParentName )
|
||||
.Add( "UIDName" , Data.Object[i0]. UIDName ));
|
||||
MsgPack _Object = MsgPack.New.Add(null, Data.Object[i0].MT)
|
||||
.Add("Morph" , Data.Object[i0].Morph )
|
||||
.Add("MorphOffset", Data.Object[i0].MorphOffset)
|
||||
.Add( "Name" , Data.Object[i0]. Name )
|
||||
.Add("ParentName" , Data.Object[i0].ParentName )
|
||||
.Add( "UIDName" , Data.Object[i0]. UIDName );
|
||||
if (Data.Object[i0].TP != null)
|
||||
{
|
||||
MsgPack TP = new MsgPack("TP", Data.Object[i0].TP.Length);
|
||||
MsgPack TP = new MsgPack(Data.Object[i0].TP.Length, "TP");
|
||||
for (i1 = 0; i1 < Data.Object[i0].TP.Length; i1++)
|
||||
TP[i1] = new MsgPack().Add("Name" , Data.Object[i0].TP[i1].Name )
|
||||
.Add("Pat" , Data.Object[i0].TP[i1].Pat )
|
||||
.Add("PatOffset", Data.Object[i0].TP[i1].PatOffset);
|
||||
TP[i1] = MsgPack.New.Add("Name" , Data.Object[i0].TP[i1].Name )
|
||||
.Add("Pat" , Data.Object[i0].TP[i1].Pat )
|
||||
.Add("PatOffset", Data.Object[i0].TP[i1].PatOffset);
|
||||
_Object.Add(TP);
|
||||
}
|
||||
if (Data.Object[i0].TT != null)
|
||||
{
|
||||
MsgPack TT = new MsgPack("TT", Data.Object[i0].TT.Length);
|
||||
MsgPack TT = new MsgPack(Data.Object[i0].TT.Length, "TT");
|
||||
for (i1 = 0; i1 < Data.Object[i0].TT.Length; i1++)
|
||||
TT[i1] = new MsgPack().Add("Name", Data.Object[i0].TT[i1].Name)
|
||||
.Add(Data.Object[i0].TT[i1].C .WriteMP("C" ))
|
||||
.Add(Data.Object[i0].TT[i1].O .WriteMP("O" ))
|
||||
.Add(Data.Object[i0].TT[i1].R .WriteMP("R" ))
|
||||
.Add(Data.Object[i0].TT[i1].Ro.WriteMP("Ro"))
|
||||
.Add(Data.Object[i0].TT[i1].RF.WriteMP("RF"))
|
||||
.Add(Data.Object[i0].TT[i1].TF.WriteMP("TF"));
|
||||
TT[i1] = MsgPack.New.Add("Name", Data.Object[i0].TT[i1].Name)
|
||||
.Add("C" , Data.Object[i0].TT[i1].C )
|
||||
.Add("O" , Data.Object[i0].TT[i1].O )
|
||||
.Add("R" , Data.Object[i0].TT[i1].R )
|
||||
.Add("Ro" , Data.Object[i0].TT[i1].Ro )
|
||||
.Add("RF" , Data.Object[i0].TT[i1].RF )
|
||||
.Add("TF" , Data.Object[i0].TT[i1].TF );
|
||||
_Object.Add(TT);
|
||||
}
|
||||
Object[i0] = _Object;
|
||||
@@ -1932,12 +1908,12 @@ namespace KKdMainLib.A3DA
|
||||
|
||||
if (Data.ObjectHRC != null)
|
||||
{
|
||||
MsgPack ObjectHRC = new MsgPack("ObjectHRC", Data.ObjectHRC.Length);
|
||||
MsgPack ObjectHRC = new MsgPack(Data.ObjectHRC.Length, "ObjectHRC");
|
||||
for (i0 = 0; i0 < Data.ObjectHRC.Length; i0++)
|
||||
{
|
||||
MsgPack _ObjectHRC = new MsgPack().Add( "Name", Data.ObjectHRC[i0]. Name)
|
||||
.Add("Shadow" , Data.ObjectHRC[i0].Shadow )
|
||||
.Add("UIDName", Data.ObjectHRC[i0].UIDName);
|
||||
MsgPack _ObjectHRC = MsgPack.New.Add( "Name", Data.ObjectHRC[i0]. Name)
|
||||
.Add("Shadow" , Data.ObjectHRC[i0].Shadow )
|
||||
.Add("UIDName", Data.ObjectHRC[i0].UIDName);
|
||||
|
||||
if (IsX && Data.ObjectHRC[i0].JointOrient != null)
|
||||
_ObjectHRC.Add(new MsgPack("JointOrient")
|
||||
@@ -1947,11 +1923,11 @@ namespace KKdMainLib.A3DA
|
||||
|
||||
if (Data.ObjectHRC[i0].Node != null)
|
||||
{
|
||||
MsgPack Node = new MsgPack("Node", Data.ObjectHRC[i0].Node.Length);
|
||||
MsgPack Node = new MsgPack(Data.ObjectHRC[i0].Node.Length, "Node");
|
||||
for (i1 = 0; i1 < Data.ObjectHRC[i0].Node.Length; i1++)
|
||||
Node[i1] = Data.ObjectHRC[i0].Node[i1].MT.WriteMP(new MsgPack()
|
||||
Node[i1] = MsgPack.New.Add(null, Data.ObjectHRC[i0].Node[i1].MT)
|
||||
.Add("Name" , Data.ObjectHRC[i0].Node[i1].Name )
|
||||
.Add("Parent", Data.ObjectHRC[i0].Node[i1].Parent));
|
||||
.Add("Parent", Data.ObjectHRC[i0].Node[i1].Parent);
|
||||
_ObjectHRC.Add(Node);
|
||||
}
|
||||
ObjectHRC[i0] = _ObjectHRC;
|
||||
@@ -1961,15 +1937,15 @@ namespace KKdMainLib.A3DA
|
||||
|
||||
if (Data.ObjectHRCList != null)
|
||||
{
|
||||
MsgPack ObjectHRCList = new MsgPack("ObjectHRCList", Data.ObjectHRCList.Length);
|
||||
for (i = 0; i < Data.ObjectHRCList.Length; i++) ObjectHRCList[i] = Data.ObjectHRCList[i];
|
||||
MsgPack ObjectHRCList = new MsgPack(Data.ObjectHRCList.Length, "ObjectHRCList");
|
||||
for (i = 0; i < Data.ObjectHRCList.Length; i++) ObjectHRCList[i] = (MsgPack)Data.ObjectHRCList[i];
|
||||
A3D.Add(ObjectHRCList);
|
||||
}
|
||||
|
||||
if (Data.ObjectList != null)
|
||||
{
|
||||
MsgPack ObjectList = new MsgPack("ObjectList", Data.ObjectList.Length);
|
||||
for (i = 0; i < Data.ObjectList.Length; i++) ObjectList[i] = Data.ObjectList[i];
|
||||
MsgPack ObjectList = new MsgPack(Data.ObjectList.Length, "ObjectList");
|
||||
for (i = 0; i < Data.ObjectList.Length; i++) ObjectList[i] = (MsgPack)Data.ObjectList[i];
|
||||
A3D.Add(ObjectList);
|
||||
}
|
||||
|
||||
@@ -1983,19 +1959,19 @@ namespace KKdMainLib.A3DA
|
||||
|
||||
if (Data.Point != null)
|
||||
{
|
||||
MsgPack Point = new MsgPack("Point", Data.Point.Length);
|
||||
MsgPack Point = new MsgPack(Data.Point.Length, "Point");
|
||||
for (i = 0; i < Data.Point.Length; i++)
|
||||
Point[i] = Data.Point[i].WriteMP();
|
||||
Point[i] = MsgPack.New.Add(null, Data.Point[i]);
|
||||
A3D.Add(Point);
|
||||
}
|
||||
|
||||
if (Data.PostProcess != null)
|
||||
A3D.Add(new MsgPack("PostProcess").Add(Data.PostProcess.Ambient .WriteMP("Ambient" ))
|
||||
.Add(Data.PostProcess.Diffuse .WriteMP("Diffuse" ))
|
||||
.Add(Data.PostProcess.LensFlare.WriteMP("LensFlare"))
|
||||
.Add(Data.PostProcess.LensGhost.WriteMP("LensGhost"))
|
||||
.Add(Data.PostProcess.LensShaft.WriteMP("LensShaft"))
|
||||
.Add(Data.PostProcess.Specular .WriteMP("Specular" )));
|
||||
A3D.Add(new MsgPack("PostProcess").Add("Ambient" , Data.PostProcess.Ambient )
|
||||
.Add("Diffuse" , Data.PostProcess.Diffuse )
|
||||
.Add("LensFlare", Data.PostProcess.LensFlare)
|
||||
.Add("LensGhost", Data.PostProcess.LensGhost)
|
||||
.Add("LensShaft", Data.PostProcess.LensShaft)
|
||||
.Add("Specular" , Data.PostProcess.Specular ));
|
||||
|
||||
A3D.Write(true, file, JSON);
|
||||
}
|
||||
@@ -2113,37 +2089,15 @@ namespace KKdMainLib.A3DA
|
||||
public double? EPTypePost;
|
||||
public double? EPTypePre;
|
||||
public RawD RawData;
|
||||
public Transform[] Trans;
|
||||
public IKeyFrame<double, double>[] Trans;
|
||||
|
||||
public class RawD
|
||||
public struct RawD
|
||||
{
|
||||
public int? KeyType;
|
||||
public int? ValueListSize;
|
||||
public string ValueType;
|
||||
public string[] ValueList;
|
||||
}
|
||||
|
||||
public struct Transform
|
||||
{
|
||||
public int Type;
|
||||
public double Frame;
|
||||
public double[] Value;
|
||||
|
||||
public override string ToString() => ToString(true);
|
||||
public string ToString(bool Brackets)
|
||||
{
|
||||
if (Value == null) return Main.ToString(Frame);
|
||||
|
||||
string s = "";
|
||||
if (Brackets && Type > 0) s += "(";
|
||||
s += Main.ToString(Frame);
|
||||
if (Type > 0 && Value.Length > 0) s += "," + Main.ToString(Value[0]);
|
||||
if (Type > 1 && Value.Length > 1) s += "," + Main.ToString(Value[1]);
|
||||
if (Type > 2 && Value.Length > 2) s += "," + Main.ToString(Value[2]);
|
||||
if (Brackets && Type > 0) s += ")";
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct Instance
|
||||
|
||||
+180
-98
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.Types;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.A3DA
|
||||
@@ -51,7 +52,6 @@ namespace KKdMainLib.A3DA
|
||||
if (Key.Type == 0x0001) { Dict.FindValue(out Key.Value, Temp + "value"); return Key; }
|
||||
|
||||
int i = 0, i0 = 0;
|
||||
byte i1 = 0;
|
||||
Dict.FindValue(out Key.EPTypePost, Temp + "ep_type_post");
|
||||
Dict.FindValue(out Key.EPTypePre , Temp + "ep_type_pre" );
|
||||
Dict.FindValue(out Key.Length , Temp + "key.length" );
|
||||
@@ -61,39 +61,62 @@ namespace KKdMainLib.A3DA
|
||||
|
||||
if (Key.Length != null)
|
||||
{
|
||||
Key.Trans = new Key.Transform[(int)Key.Length];
|
||||
int Type;
|
||||
Key.Trans = new IKeyFrame<double, double>[(int)Key.Length];
|
||||
for (i0 = 0; i0 < Key.Length; i0++)
|
||||
if (Dict.FindValue(out value, Temp + "key" + d + i0 + d + "data"))
|
||||
{
|
||||
Key.Trans[i0] = new Key.Transform();
|
||||
dataArray = value.Replace("(", "").Replace(")", "").Split(',');
|
||||
Key.Trans[i0].Type = dataArray.Length - 1;
|
||||
Key.Trans[i0].Frame = dataArray[0].ToDouble();
|
||||
Key.Trans[i0].Value = new double[Key.Trans[i0].Type];
|
||||
for (i1 = 1; i1 < dataArray.Length; i1++)
|
||||
Key.Trans[i0].Value[i1 - 1] = dataArray[i1].ToDouble();
|
||||
Type = dataArray.Length - 1;
|
||||
if (Type == 0) Key.Trans[i0] = new KeyFrameT0<double, double>
|
||||
{ Frame = dataArray[0].ToDouble() };
|
||||
else if (Type == 1) Key.Trans[i0] = new KeyFrameT1<double, double>
|
||||
{ Frame = dataArray[0].ToDouble(), Value = dataArray[1].ToDouble() };
|
||||
else if (Type == 2) Key.Trans[i0] = new KeyFrameT2<double, double>
|
||||
{ Frame = dataArray[0].ToDouble(), Value = dataArray[1].ToDouble(),
|
||||
Interpolation = dataArray[2].ToDouble() };
|
||||
else if (Type == 3) Key.Trans[i0] = new KeyFrameT3<double, double>
|
||||
{ Frame = dataArray[0].ToDouble(), Value = dataArray[1].ToDouble(),
|
||||
Interpolation1 = dataArray[2].ToDouble(),
|
||||
Interpolation2 = dataArray[3].ToDouble() };
|
||||
Key.Trans[i0] = Key.Trans[i0].Check();
|
||||
}
|
||||
}
|
||||
else if (Key.RawData.KeyType != null)
|
||||
{
|
||||
Key.RawData = new Key.RawD();
|
||||
Dict.FindValue(out Key.RawData.ValueType, Temp + "raw_data.value_type");
|
||||
if (Dict.FindValue(out value, Temp + "raw_data.value_list"))
|
||||
Key.RawData.ValueList = value.Split(',');
|
||||
Dict.FindValue(out Key.RawData.ValueListSize, Temp + "raw_data.value_list_size");
|
||||
value = "";
|
||||
|
||||
int DataSize = (int)Key.RawData.KeyType + 1;
|
||||
Key.Length = Key.RawData.ValueListSize / DataSize;
|
||||
Key.Trans = new Key.Transform[(int)Key.Length];
|
||||
for (i = 0; i < Key.Length; i++)
|
||||
{
|
||||
Key.Trans[i].Type = (int)Key.RawData.KeyType;
|
||||
Key.Trans[i].Frame = Key.RawData.ValueList[i * DataSize + 0].ToDouble();
|
||||
Key.Trans[i].Value = new double[Key.Trans[i0].Type];
|
||||
for (i1 = 1; i1 < Key.Trans[i].Type; i1++)
|
||||
Key.Trans[i].Value[i1 - 1] = Key.RawData.ValueList[i * DataSize + i1].ToDouble();
|
||||
}
|
||||
int DS = (int)Key.RawData.KeyType + 1;
|
||||
Key.Length = Key.RawData.ValueListSize / DS;
|
||||
Key.Trans = new IKeyFrame<double, double>[(int)Key.Length];
|
||||
if (Key.RawData.KeyType == 0)
|
||||
for (i = 0; i < Key.Length; i++)
|
||||
Key.Trans[i] = new KeyFrameT0<double, double>
|
||||
{ Frame = Key.RawData.ValueList[i * DS + 0].ToDouble() }.Check();
|
||||
else if (Key.RawData.KeyType == 1)
|
||||
for (i = 0; i < Key.Length; i++)
|
||||
Key.Trans[i] = new KeyFrameT1<double, double>
|
||||
{ Frame = Key.RawData.ValueList[i * DS + 0].ToDouble(),
|
||||
Value = Key.RawData.ValueList[i * DS + 1].ToDouble() }.Check();
|
||||
else if (Key.RawData.KeyType == 2)
|
||||
for (i = 0; i < Key.Length; i++)
|
||||
Key.Trans[i] = new KeyFrameT2<double, double>
|
||||
{ Frame = Key.RawData.ValueList[i * DS + 0].ToDouble(),
|
||||
Value = Key.RawData.ValueList[i * DS + 1].ToDouble(),
|
||||
Interpolation = Key.RawData.ValueList[i * DS + 2].ToDouble() }.Check();
|
||||
else if (Key.RawData.KeyType == 3)
|
||||
for (i = 0; i < Key.Length; i++)
|
||||
Key.Trans[i] = new KeyFrameT3<double, double>
|
||||
{ Frame = Key.RawData.ValueList[i * DS + 0].ToDouble(),
|
||||
Value = Key.RawData.ValueList[i * DS + 1].ToDouble(),
|
||||
Interpolation1 = Key.RawData.ValueList[i * DS + 2].ToDouble(),
|
||||
Interpolation2 = Key.RawData.ValueList[i * DS + 3].ToDouble() }.Check();
|
||||
|
||||
for (i = 0; i < Key.Length; i++) Key.Trans[i].Check();
|
||||
Key.RawData.ValueList = null;
|
||||
}
|
||||
return Key;
|
||||
@@ -117,8 +140,10 @@ namespace KKdMainLib.A3DA
|
||||
{
|
||||
if (RGBA.R == null && RGBA.B == null && RGBA.G == null && RGBA.A == null) return;
|
||||
IO.Write(Temp + Data + "=", "true");
|
||||
IO.Write(RGBA.A, Temp + Data + d + "a" + d, A3DC); IO.Write(RGBA.B, Temp + Data + d + "b" + d, A3DC);
|
||||
IO.Write(RGBA.G, Temp + Data + d + "g" + d, A3DC); IO.Write(RGBA.R, Temp + Data + d + "r" + d, A3DC);
|
||||
IO.Write(RGBA.A, Temp + Data + d + "a" + d, A3DC);
|
||||
IO.Write(RGBA.B, Temp + Data + d + "b" + d, A3DC);
|
||||
IO.Write(RGBA.G, Temp + Data + d + "g" + d, A3DC);
|
||||
IO.Write(RGBA.R, Temp + Data + d + "r" + d, A3DC);
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, Vector3<Key> Key, string Temp, bool A3DC = false)
|
||||
@@ -148,31 +173,54 @@ namespace KKdMainLib.A3DA
|
||||
|
||||
if (Key.EPTypePost != null) IO.Write(Temp + "ep_type_post=", Key.EPTypePost);
|
||||
if (Key.EPTypePre != null) IO.Write(Temp + "ep_type_pre=" , Key.EPTypePre );
|
||||
if (Key.RawData == null && Key.Trans != null)
|
||||
if (Key.RawData.KeyType == null && Key.Trans != null)
|
||||
{
|
||||
SO = Key.Trans.Length.SortWriter();
|
||||
for (i = 0; i < Key.Trans.Length; i++)
|
||||
{
|
||||
SOi = SO[i];
|
||||
IO.Write(Temp + "key" + d + SOi + d + "data=", Key.Trans[SOi].ToString());
|
||||
IO.Write(Temp + "key" + d + SOi + d + "type=", Key.Trans[SOi].Type );
|
||||
if (Key.Trans[SOi] is KeyFrameT0<double, double>)
|
||||
IO.Write(Temp + "key" + d + SOi + d + "type=", 0);
|
||||
else if (Key.Trans[SOi] is KeyFrameT1<double, double>)
|
||||
IO.Write(Temp + "key" + d + SOi + d + "type=", 1);
|
||||
else if (Key.Trans[SOi] is KeyFrameT2<double, double>)
|
||||
IO.Write(Temp + "key" + d + SOi + d + "type=", 2);
|
||||
else if (Key.Trans[SOi] is KeyFrameT3<double, double>)
|
||||
IO.Write(Temp + "key" + d + SOi + d + "type=", 3);
|
||||
}
|
||||
IO.Write(Temp + "key.length=", Key.Length);
|
||||
if (Key.Max != null) IO.Write(Temp + "max=", Key.Max);
|
||||
}
|
||||
else if (Key.Trans != null)
|
||||
{
|
||||
Key.RawData.KeyType = 0;
|
||||
if (Key.Max != null) IO.Write(Temp + "max=", Key.Max);
|
||||
for (i = 0; i < Key.Trans.Length; i++)
|
||||
{
|
||||
if (Key.RawData.KeyType < Key.Trans[i].Type || Key.RawData.KeyType == null)
|
||||
Key.RawData.KeyType = Key.Trans[i].Type;
|
||||
if (Key.RawData.KeyType == 3) break;
|
||||
if (Key.Trans[i] is KeyFrameT0<double, double> &&
|
||||
Key.RawData.KeyType < 0) Key.RawData.KeyType = 0;
|
||||
else if (Key.Trans[i] is KeyFrameT1<double, double> &&
|
||||
Key.RawData.KeyType < 1) Key.RawData.KeyType = 1;
|
||||
else if (Key.Trans[i] is KeyFrameT2<double, double> &&
|
||||
Key.RawData.KeyType < 2) Key.RawData.KeyType = 2;
|
||||
else if (Key.Trans[i] is KeyFrameT3<double, double> &&
|
||||
Key.RawData.KeyType < 3) break;
|
||||
}
|
||||
Key.RawData.ValueListSize = Key.Trans.Length * (Key.RawData.KeyType + 1);
|
||||
IO.Write(Temp + "raw_data.value_list=");
|
||||
for (i = 0; i < Key.Trans.Length; i++)
|
||||
IO.Write(Key.Trans[i].ToString(false));
|
||||
if (Key.RawData.KeyType == 0) for (i = 0; i < Key.Trans.Length; i++)
|
||||
IO.Write(Key.Trans[i].ToKeyFrameT0().ToString(false) +
|
||||
((i + 1 < Key.Trans.Length) ? "," : ""));
|
||||
else if (Key.RawData.KeyType == 1) for (i = 0; i < Key.Trans.Length; i++)
|
||||
IO.Write(Key.Trans[i].ToKeyFrameT1().ToString(false) +
|
||||
((i + 1 < Key.Trans.Length) ? "," : ""));
|
||||
else if (Key.RawData.KeyType == 2) for (i = 0; i < Key.Trans.Length; i++)
|
||||
IO.Write(Key.Trans[i].ToKeyFrameT2().ToString(false) +
|
||||
((i + 1 < Key.Trans.Length) ? "," : ""));
|
||||
else if (Key.RawData.KeyType == 3) for (i = 0; i < Key.Trans.Length; i++)
|
||||
IO.Write(Key.Trans[i].ToKeyFrameT3().ToString(false) +
|
||||
((i + 1 < Key.Trans.Length) ? "," : ""));
|
||||
IO.Position = IO.Position - 1;
|
||||
IO.Write('\n');
|
||||
IO.Write(Temp + "raw_data.value_list_size=", Key.RawData.ValueListSize);
|
||||
@@ -180,7 +228,7 @@ namespace KKdMainLib.A3DA
|
||||
IO.Write(Temp + "raw_data_key_type=" , Key.RawData. KeyType );
|
||||
}
|
||||
IO.Write(Temp + "type=", Key.Type & 0xFF);
|
||||
if (Key.RawData == null && Key.Trans == null && Key.Value != null)
|
||||
if (Key.RawData.KeyType == null && Key.Trans == null && Key.Value != null)
|
||||
if (Key.Value != 0) IO.Write(Temp + "value=", Key.Value);
|
||||
}
|
||||
|
||||
@@ -225,22 +273,24 @@ namespace KKdMainLib.A3DA
|
||||
|
||||
Key.Max = IO.ReadSingle();
|
||||
Key.Length = IO.ReadInt32 ();
|
||||
Key.Trans = new Key.Transform[(int)Key.Length];
|
||||
int Ke = (int)Key.Length;
|
||||
Key.Trans = new IKeyFrame<double, double>[(int)Key.Length];
|
||||
KeyFrameT3<double, double> Temp;
|
||||
for (int i = 0; i < Key.Length; i++)
|
||||
{
|
||||
Key.Trans[i] = new Key.Transform { Type = 3, Value = new double[3] };
|
||||
Temp = new KeyFrameT3<double, double>();
|
||||
if (F16 && C_F16 > 0)
|
||||
{ Key.Trans[i].Frame = IO.ReadUInt16(); Key.Trans[i].Value[0] = (double)IO.ReadHalf (); }
|
||||
{ Temp.Frame = IO.ReadUInt16(); Temp.Value = (double)IO.ReadHalf (); }
|
||||
else
|
||||
{ Key.Trans[i].Frame = IO.ReadSingle(); Key.Trans[i].Value[0] = IO.ReadSingle(); }
|
||||
{ Temp.Frame = IO.ReadSingle(); Temp.Value = IO.ReadSingle(); }
|
||||
|
||||
if (F16 && C_F16 == 2)
|
||||
{ Key.Trans[i].Value[1] = (double)IO.ReadHalf ();
|
||||
Key.Trans[i].Value[2] = (double)IO.ReadHalf (); }
|
||||
{ Temp.Interpolation1 = (double)IO.ReadHalf ();
|
||||
Temp.Interpolation2 = (double)IO.ReadHalf (); }
|
||||
else
|
||||
{ Key.Trans[i].Value[1] = IO.ReadSingle();
|
||||
Key.Trans[i].Value[2] = IO.ReadSingle(); }
|
||||
{ Temp.Interpolation1 = IO.ReadSingle();
|
||||
Temp.Interpolation2 = IO.ReadSingle(); }
|
||||
|
||||
Key.Trans[i] = Temp.Check();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +313,7 @@ namespace KKdMainLib.A3DA
|
||||
{
|
||||
MT.BinOffset = IO.Position;
|
||||
IO.Position += 0x30;
|
||||
IO.Length += 0x30;
|
||||
IO.Length += 0x30;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,93 +354,125 @@ namespace KKdMainLib.A3DA
|
||||
|
||||
public static Key ReadKey(this MsgPack k)
|
||||
{
|
||||
if (k == null) return null;
|
||||
if (k.Object == null) return null;
|
||||
|
||||
Key Key = new Key { EPTypePost = k.ReadNDouble("Post"),
|
||||
EPTypePre = k.ReadNDouble("Pre"), Max = k.ReadNDouble("M"),
|
||||
Type = k.ReadNInt32("T"), Value = k.ReadNDouble("V") };
|
||||
if (k.ReadBoolean("RD")) Key.RawData = new Key.RawD();
|
||||
if (k.ReadBoolean("RD")) Key.RawData = new Key.RawD() { KeyType = -1, ValueType = "float" };
|
||||
if (Key.Type == 0) Key.Value = 0.0;
|
||||
|
||||
if (Key.Type < 2) return Key;
|
||||
|
||||
if (!k.Element<MsgPack>("Trans", out MsgPack Trans)) return Key;
|
||||
if (!k.ElementArray("Trans", out MsgPack Trans)) return Key;
|
||||
|
||||
Key.Length = Trans.Array.Length;
|
||||
Key.Trans = new Key.Transform[Key.Length.Value];
|
||||
byte i1 = 0;
|
||||
Key.Trans = new IKeyFrame<double, double>[Key.Length.Value];
|
||||
for (int i = 0; i < Key.Length; i++)
|
||||
{
|
||||
Key.Trans[i] = new Key.Transform();
|
||||
if (Trans[i] is MsgPack _Trans)
|
||||
{
|
||||
if (_Trans.Array == null) continue;
|
||||
Key.Trans[i].Type = _Trans.Array.Length - 1;
|
||||
Key.Trans[i].Value = new double[Key.Trans[i].Type];
|
||||
|
||||
Key.Trans[i].Frame = (_Trans[0] as MsgPack).ReadDouble();
|
||||
|
||||
for (i1 = 0; i1 < Key.Trans[i].Type; i1++)
|
||||
Key.Trans[i].Value[i1] = ((MsgPack)_Trans[i1 + 1]).ReadDouble();
|
||||
}
|
||||
if (Trans[i].Array == null) continue;
|
||||
else if (Trans[i].Array.Length == 0) continue;
|
||||
else if (Trans[i].Array.Length == 1)
|
||||
Key.Trans[i] = new KeyFrameT0<double, double>
|
||||
{ Frame = Trans[i][0].ReadDouble() };
|
||||
else if (Trans[i].Array.Length == 2)
|
||||
Key.Trans[i] = new KeyFrameT1<double, double>
|
||||
{
|
||||
Frame = Trans[i][0].ReadDouble(),
|
||||
Value = Trans[i][1].ReadDouble(),
|
||||
};
|
||||
else if (Trans[i].Array.Length == 3)
|
||||
Key.Trans[i] = new KeyFrameT2<double, double>
|
||||
{
|
||||
Frame = Trans[i][0].ReadDouble(),
|
||||
Value = Trans[i][1].ReadDouble(),
|
||||
Interpolation = Trans[i][2].ReadDouble(),
|
||||
};
|
||||
else if (Trans[i].Array.Length == 4)
|
||||
Key.Trans[i] = new KeyFrameT3<double, double>
|
||||
{
|
||||
Frame = Trans[i][0].ReadDouble(),
|
||||
Value = Trans[i][1].ReadDouble(),
|
||||
Interpolation1 = Trans[i][2].ReadDouble(),
|
||||
Interpolation2 = Trans[i][3].ReadDouble(),
|
||||
};
|
||||
Key.Trans[i] = Key.Trans[i].Check();
|
||||
}
|
||||
return Key;
|
||||
}
|
||||
|
||||
public static MsgPack WriteMP(this ModelTransform MT, string name) =>
|
||||
MT.WriteMP(new MsgPack(name));
|
||||
public static MsgPack Add(this MsgPack MsgPack, string name, ModelTransform MT) =>
|
||||
name == null ?
|
||||
MsgPack.Add("Rot" , MT.Rot )
|
||||
.Add("Scale" , MT.Scale )
|
||||
.Add("Trans" , MT.Trans )
|
||||
.Add("Visibility", MT.Visibility):
|
||||
MsgPack.Add(new MsgPack(name).Add("Rot" , MT.Rot )
|
||||
.Add("Scale" , MT.Scale )
|
||||
.Add("Trans" , MT.Trans )
|
||||
.Add("Visibility", MT.Visibility));
|
||||
|
||||
public static MsgPack WriteMP(this ModelTransform MT) =>
|
||||
MT.WriteMP(new MsgPack( ));
|
||||
public static MsgPack Add(this MsgPack MsgPack, string name, RGBAKey RGBA) =>
|
||||
(RGBA.R == null && RGBA.G == null && RGBA.B == null && RGBA.A == null) ? MsgPack :
|
||||
MsgPack.Add(new MsgPack(name).Add("R", RGBA.R).Add("G", RGBA.G)
|
||||
.Add("B", RGBA.B).Add("A", RGBA.A));
|
||||
|
||||
public static MsgPack WriteMP(this ModelTransform MT, MsgPack MTs) =>
|
||||
MTs.Add(MT.Rot .WriteMP("Rot" ))
|
||||
.Add(MT.Scale .WriteMP("Scale" ))
|
||||
.Add(MT.Trans .WriteMP("Trans" ))
|
||||
.Add(MT.Visibility.WriteMP("Visibility"));
|
||||
public static MsgPack Add(this MsgPack MsgPack, string name, Vector3<Key> Key) =>
|
||||
MsgPack.Add(new MsgPack(name).Add("X", Key.X).Add("Y", Key.Y).Add("Z", Key.Z));
|
||||
|
||||
public static MsgPack WriteMP(this RGBAKey RGBA, string name)
|
||||
public static MsgPack Add(this MsgPack MsgPack, string name, KeyUV UV) =>
|
||||
(UV.U == null && UV.V == null) ? MsgPack :
|
||||
MsgPack.Add(new MsgPack(name).Add("U", UV.U).Add("V", UV.V));
|
||||
|
||||
public static MsgPack Add(this MsgPack MsgPack, string name, Key Key)
|
||||
{
|
||||
if (RGBA.R == null && RGBA.G == null && RGBA.B == null && RGBA.A == null) return MsgPack.Null;
|
||||
return new MsgPack(name).Add(RGBA.R.WriteMP("R")).Add(RGBA.G.WriteMP("G"))
|
||||
.Add(RGBA.B.WriteMP("B")).Add(RGBA.A.WriteMP("A"));
|
||||
}
|
||||
|
||||
public static MsgPack WriteMP(this Vector3<Key> Key, string name) =>
|
||||
new MsgPack(name).Add(Key.X.WriteMP("X")).Add(Key.Y.WriteMP("Y")).Add(Key.Z.WriteMP("Z"));
|
||||
|
||||
public static MsgPack WriteMP(this KeyUV UV, string name)
|
||||
{
|
||||
if (UV.U == null && UV.V == null) return MsgPack.Null;
|
||||
return new MsgPack(name).Add(UV.U.WriteMP("U")).Add(UV.V.WriteMP("V"));
|
||||
}
|
||||
|
||||
public static MsgPack WriteMP(this Key Key, string name)
|
||||
{
|
||||
if (Key == null) return MsgPack.Null;
|
||||
if (Key.Type == null) return MsgPack.Null;
|
||||
if (Key == null) return MsgPack;
|
||||
if (Key.Type == null) return MsgPack;
|
||||
|
||||
MsgPack Keys = new MsgPack(name).Add("T", Key.Type);
|
||||
if (Key.Trans != null)
|
||||
{
|
||||
Keys.Add("Post", Key.EPTypePost).Add("Pre", Key.EPTypePre).Add("M", Key.Max);
|
||||
Keys.Add("M", Key.Max).Add("Post", Key.EPTypePost).Add("Pre", Key.EPTypePre);
|
||||
|
||||
if (Key.RawData != null) Keys.Add("RD", true);
|
||||
|
||||
byte i0 = 0;
|
||||
MsgPack Trans = new MsgPack("Trans", Key.Trans.Length);
|
||||
if (Key.RawData.KeyType != null) Keys.Add("RD", true);
|
||||
|
||||
MsgPack Trans = new MsgPack(Key.Trans.Length, "Trans");
|
||||
MsgPack K;
|
||||
for (int i = 0; i < Key.Trans.Length; i++)
|
||||
{
|
||||
MsgPack K = new MsgPack(Key.Trans[i].Type + 1);
|
||||
K[0] = Key.Trans[i].Frame;
|
||||
for (i0 = 1; i0 < Key.Trans[i].Type + 1; i0++)
|
||||
K[i0] = Key.Trans[i].Value[i0 - 1];
|
||||
Trans[i] = K;
|
||||
}
|
||||
if (Key.Trans[i] is KeyFrameT0<double, double> KeyFrameT0)
|
||||
{
|
||||
K = new MsgPack(1);
|
||||
K[0] = (MsgPack)KeyFrameT0.Frame;
|
||||
Trans[i] = K;
|
||||
}
|
||||
else if (Key.Trans[i] is KeyFrameT1<double, double> KeyFrameT1)
|
||||
{
|
||||
K = new MsgPack(2);
|
||||
K[0] = (MsgPack)KeyFrameT1.Frame;
|
||||
K[1] = (MsgPack)KeyFrameT1.Value;
|
||||
Trans[i] = K;
|
||||
}
|
||||
else if (Key.Trans[i] is KeyFrameT2<double, double> KeyFrameT2)
|
||||
{
|
||||
K = new MsgPack(3);
|
||||
K[0] = (MsgPack)KeyFrameT2.Frame;
|
||||
K[1] = (MsgPack)KeyFrameT2.Value;
|
||||
K[2] = (MsgPack)KeyFrameT2.Interpolation;
|
||||
Trans[i] = K;
|
||||
}
|
||||
else if (Key.Trans[i] is KeyFrameT3<double, double> KeyFrameT3)
|
||||
{
|
||||
K = new MsgPack(4);
|
||||
K[0] = (MsgPack)KeyFrameT3.Frame;
|
||||
K[1] = (MsgPack)KeyFrameT3.Value;
|
||||
K[2] = (MsgPack)KeyFrameT3.Interpolation1;
|
||||
K[3] = (MsgPack)KeyFrameT3.Interpolation2;
|
||||
Trans[i] = K;
|
||||
}
|
||||
Keys.Add(Trans);
|
||||
}
|
||||
else if (Key.Value != 0) Keys.Add("V", Key.Value);
|
||||
return Keys;
|
||||
return MsgPack.Add(Keys);
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, string Data, ref bool? val)
|
||||
|
||||
+541
-590
File diff suppressed because it is too large
Load Diff
+247
-263
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.Types;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.Aet
|
||||
@@ -8,24 +7,7 @@ namespace KKdMainLib.Aet
|
||||
public static class AetExt
|
||||
{
|
||||
private static System.Text.Encoding ShiftJIS = System.Text.Encoding.GetEncoding(932);
|
||||
|
||||
public static Dictionary<TKey, int> GetIndDict<TKey, TVal>(this Dictionary<TKey, TVal> Dict)
|
||||
{
|
||||
List<TKey> Keys = Dict.Keys.ToList();
|
||||
Dictionary<TKey, int> IndDict = new Dictionary<TKey, int>();
|
||||
for (int i = 0; i < Keys.Count; i++)
|
||||
IndDict.Add(Keys[i], i);
|
||||
return IndDict;
|
||||
}
|
||||
|
||||
public static Pointer<T>[] ToPointerArray<T>(this Dictionary<int, T> val)
|
||||
{
|
||||
Pointer<T>[] arr = new Pointer<T>[val.Count];
|
||||
for (int i = 0; i < val.Count; i++)
|
||||
arr[i] = val.ElementAt(i).ToPointer();
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
public static Pointer<T> ReadPointer<T>(this Stream IO) =>
|
||||
new Pointer<T> { Offset = IO.ReadInt32() };
|
||||
|
||||
@@ -40,50 +22,42 @@ namespace KKdMainLib.Aet
|
||||
public static void WriteShiftJIS(this Stream IO, string String) =>
|
||||
IO.Write(ShiftJIS.GetBytes(String));
|
||||
|
||||
public static CountPointer<T> ReadCountPointer<T>(this Stream IO)
|
||||
{ CountPointer<T> val = new CountPointer<T> { Count = IO.ReadInt32(),
|
||||
Offset = IO.ReadInt32() }; val.Entries = new T[val.Count]; return val; }
|
||||
|
||||
|
||||
public static Pointer<T> ToPointer<T>(this KeyValuePair<int, T> val) =>
|
||||
new Pointer<T> { Offset = val.Key, Value = val.Value };
|
||||
public static CountPointer<T> ReadCountPointer<T>(this Stream IO) =>
|
||||
new CountPointer<T> { Count = IO.ReadInt32(), Offset = IO.ReadInt32() };
|
||||
|
||||
public static void ReadMP(this MsgPack msg, ref CountPointer<float> val, string Name)
|
||||
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.Entries[0] = msg.ReadSingle(Name);
|
||||
val[0] = msg.ReadSingle(Name);
|
||||
}
|
||||
else if(msg.Element<MsgPack>(Name, out MsgPack Temp))
|
||||
else if(msg.ElementArray(Name, out MsgPack Temp))
|
||||
{
|
||||
val.Count = Temp.Array.Length;
|
||||
for (int i = 0; i < val.Count; i++)
|
||||
if (Temp[i] is MsgPack temp)
|
||||
val.Entries[i] = temp.ReadSingle();
|
||||
|
||||
val[i] = Temp[i].ReadSingle();
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static MsgPack WriteMP(this CountPointer<float> val, string Name)
|
||||
public static MsgPack Add(this MsgPack MsgPack, string Name, CountPointer<float> val)
|
||||
{
|
||||
if (val.Count == 1) return new MsgPack(Name, MsgPack.Types.Float32, val.Entries[0]);
|
||||
if (val.Count == 1) return MsgPack.Add(new MsgPack(Name, val[0]));
|
||||
else if (val.Count > 1)
|
||||
{
|
||||
MsgPack Val = new MsgPack(Name, val.Count);
|
||||
for (int i = 0; i < val.Count; i++) Val[i] = val.Entries[i];
|
||||
return Val;
|
||||
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.Null;
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
public static int ReadAetObject(this Stream IO, ref Dictionary<int, AetObject> ObjectsDict)
|
||||
public static AetObject ReadAetObject(this Stream IO)
|
||||
{
|
||||
AetObject Anim = new AetObject();
|
||||
int AnimOffset = IO.Position;
|
||||
if (ObjectsDict.ContainsKey(AnimOffset)) return AnimOffset;
|
||||
AetObject Anim = new AetObject() { Offset = IO.Position };
|
||||
Anim.Name = IO.ReadPointerString();
|
||||
Anim.StartTime0 = IO.ReadSingle();
|
||||
Anim.LoopDuration = IO.ReadSingle();
|
||||
@@ -92,43 +66,132 @@ namespace KKdMainLib.Aet
|
||||
Anim.Unk0 = IO.ReadByte();
|
||||
Anim.Unk1 = IO.ReadByte();
|
||||
Anim.Unk2 = IO.ReadByte();
|
||||
Anim.Type = (ObjType)IO.ReadByte();
|
||||
if (Anim.Type == ObjType.Pic) Anim.Pic = IO.ReadPic(ref ObjectsDict);
|
||||
else if (Anim.Type == ObjType.Aif) Anim.Aif = IO.ReadAif();
|
||||
else if (Anim.Type == ObjType.Eff) Anim.Eff = IO.ReadEff(ref ObjectsDict);
|
||||
IO.Position = AnimOffset + 0x30;
|
||||
if (!ObjectsDict.ContainsKey(AnimOffset))
|
||||
ObjectsDict.Add(AnimOffset, Anim);
|
||||
return AnimOffset;
|
||||
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 List<int> NullValPointers)
|
||||
public static void Write(this Stream IO, ref AetObject Anim, ref KKdList<int> NullValPointers)
|
||||
{
|
||||
if (Anim.Type == ObjType.Pic)
|
||||
if (Anim.Type == AetObject.ObjType.Pic)
|
||||
{
|
||||
if (Anim.Pic.Value.Marker.Count > 0)
|
||||
ref AetObject.Picture Pic = ref Anim.Pic.Value;
|
||||
if (Pic.Marker.Count > 0)
|
||||
{
|
||||
Anim.Pic.Value.Marker.Offset = IO.Position;
|
||||
for (int i = 0; i < Anim.Pic.Value.Marker.Count; i++) IO.Write(0L);
|
||||
Pic.Marker.Offset = IO.Position;
|
||||
for (int i = 0; i < Pic.Marker.Count; i++) IO.Write(0L);
|
||||
}
|
||||
IO.Write(ref Anim.Pic.Value.Data, ref NullValPointers);
|
||||
IO.Write(ref Pic.Data, ref NullValPointers);
|
||||
}
|
||||
else if (Anim.Type == ObjType.Aif) IO.Write(ref Anim.Aif);
|
||||
else if (Anim.Type == ObjType.Eff)
|
||||
else if (Anim.Type == AetObject.ObjType.Aif)
|
||||
{
|
||||
if (Anim.Eff.Value.Marker.Count > 0)
|
||||
{
|
||||
Anim.Eff.Value.Marker.Offset = IO.Position;
|
||||
for (int i = 0; i < Anim.Eff.Value.Marker.Count; i++) IO.Write(0L);
|
||||
}
|
||||
IO.Write(ref Anim.Eff.Value.Data, ref NullValPointers);
|
||||
}
|
||||
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, ref int Offset)
|
||||
public static void Write(this Stream IO, ref AetObject Anim)
|
||||
{
|
||||
Offset = IO.Position;
|
||||
Anim.Offset = IO.Position;
|
||||
IO.Write(0);
|
||||
IO.Write(Anim.StartTime0 );
|
||||
IO.Write(Anim.LoopDuration );
|
||||
@@ -138,8 +201,20 @@ namespace KKdMainLib.Aet
|
||||
IO.Write(Anim.Unk1);
|
||||
IO.Write(Anim.Unk2);
|
||||
IO.Write((byte)Anim.Type);
|
||||
if (Anim.Type == ObjType.Pic) IO.Write(ref Anim.Pic);
|
||||
else if (Anim.Type == ObjType.Aif)
|
||||
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);
|
||||
@@ -147,173 +222,30 @@ namespace KKdMainLib.Aet
|
||||
IO.Write(0L);
|
||||
IO.Write(Anim.Aif.Value.Pointer);
|
||||
}
|
||||
else if (Anim.Type == ObjType.Eff) IO.Write(ref Anim.Eff);
|
||||
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 Pointer<Pic> ReadPic(this Stream IO, ref Dictionary<int, AetObject> ObjectsDict)
|
||||
{
|
||||
Pointer<Pic> Pic = new Pointer<Pic> { Offset = IO.Position,
|
||||
Value = new Pic
|
||||
{
|
||||
SpriteEntryID = IO.ReadInt32(),
|
||||
ParentObjectID = IO.ReadInt32(),
|
||||
Marker = IO.ReadCountPointer<Marker>()
|
||||
}
|
||||
};
|
||||
Pic.Value.Data.Offset = IO.ReadInt32();
|
||||
IO.ReadAnimData(ref Pic.Value.Data);
|
||||
|
||||
IO.Position = Pic.Value.Marker.Offset;
|
||||
for (int i = 0; i < Pic.Value.Marker.Count; i++)
|
||||
{
|
||||
Pic.Value.Marker.Entries[i].Frame = IO.ReadSingle();
|
||||
Pic.Value.Marker.Entries[i]. Name = IO.ReadPointerStringShiftJIS();
|
||||
}
|
||||
|
||||
return Pic;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ref Pointer<Pic> Pic)
|
||||
{
|
||||
Pic.Offset = IO.Position;
|
||||
IO.Write(0L);
|
||||
if (Pic.Value.Marker.Count > 0)
|
||||
{
|
||||
IO.Write(Pic.Value.Marker.Count );
|
||||
IO.Write(Pic.Value.Marker.Offset);
|
||||
}
|
||||
else IO.Write(0L);
|
||||
IO.Write(Pic.Value.Data .Offset);
|
||||
IO.Write(0);
|
||||
}
|
||||
|
||||
public static Pointer<Aif> ReadAif(this Stream IO)
|
||||
{
|
||||
Pointer<Aif> Aif = new Pointer<Aif> { Offset = IO.Position,
|
||||
Value = new Aif
|
||||
{
|
||||
Value = IO.ReadPointer<int>(),
|
||||
Zero0 = IO.ReadInt32(),
|
||||
Zero1 = IO.ReadInt32(),
|
||||
Zero2 = IO.ReadInt32(),
|
||||
Zero3 = IO.ReadInt32(),
|
||||
Pointer = IO.ReadInt32(),
|
||||
}
|
||||
};
|
||||
|
||||
IO.Position = Aif.Value.Value.Offset;
|
||||
Aif.Value.Value.Value = IO.ReadInt32();
|
||||
|
||||
IO.Position = Aif.Value.Pointer;
|
||||
Aif.Value.Unk0 = IO.ReadCountPointer<float>();
|
||||
Aif.Value.Unk1 = IO.ReadCountPointer<float>();
|
||||
Aif.Value.Unk2 = IO.ReadCountPointer<float>();
|
||||
Aif.Value.Unk3 = IO.ReadCountPointer<float>();
|
||||
|
||||
IO.Position = Aif.Value.Unk0.Offset;
|
||||
for (int i = 0; i < Aif.Value.Unk0.Count; i++) Aif.Value.Unk0.Entries[i] = IO.ReadSingle();
|
||||
IO.Position = Aif.Value.Unk1.Offset;
|
||||
for (int i = 0; i < Aif.Value.Unk1.Count; i++) Aif.Value.Unk1.Entries[i] = IO.ReadSingle();
|
||||
IO.Position = Aif.Value.Unk2.Offset;
|
||||
for (int i = 0; i < Aif.Value.Unk2.Count; i++) Aif.Value.Unk2.Entries[i] = IO.ReadSingle();
|
||||
IO.Position = Aif.Value.Unk3.Offset;
|
||||
for (int i = 0; i < Aif.Value.Unk3.Count; i++) Aif.Value.Unk3.Entries[i] = IO.ReadSingle();
|
||||
|
||||
return Aif;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ref Pointer<Aif> Aif)
|
||||
{
|
||||
if (Aif.Value.Unk0.Count > 0) { Aif.Value.Unk0.Offset = IO.Position;
|
||||
for (int i = 0; i < Aif.Value.Unk0.Count; i++) IO.Write(Aif.Value.Unk0.Entries[i]); }
|
||||
if (Aif.Value.Unk1.Count > 0) { Aif.Value.Unk1.Offset = IO.Position;
|
||||
for (int i = 0; i < Aif.Value.Unk1.Count; i++) IO.Write(Aif.Value.Unk1.Entries[i]); }
|
||||
if (Aif.Value.Unk2.Count > 0) { Aif.Value.Unk2.Offset = IO.Position;
|
||||
for (int i = 0; i < Aif.Value.Unk2.Count; i++) IO.Write(Aif.Value.Unk2.Entries[i]); }
|
||||
if (Aif.Value.Unk3.Count > 0) { Aif.Value.Unk3.Offset = IO.Position;
|
||||
for (int i = 0; i < Aif.Value.Unk3.Count; i++) IO.Write(Aif.Value.Unk3.Entries[i]); }
|
||||
|
||||
IO.Align(0x10);
|
||||
Aif.Value.Value.Offset = IO.Position;
|
||||
IO.Write(Aif.Value.Value.Value);
|
||||
|
||||
IO.Align(0x10);
|
||||
Aif.Value.Pointer = IO.Position;
|
||||
if (Aif.Value.Unk0.Count > 0) { IO.Write(Aif.Value.Unk0.Count); IO.Write(Aif.Value.Unk0.Offset); }
|
||||
else IO.Write(0L);
|
||||
if (Aif.Value.Unk1.Count > 0) { IO.Write(Aif.Value.Unk1.Count); IO.Write(Aif.Value.Unk1.Offset); }
|
||||
else IO.Write(0L);
|
||||
if (Aif.Value.Unk2.Count > 0) { IO.Write(Aif.Value.Unk2.Count); IO.Write(Aif.Value.Unk2.Offset); }
|
||||
else IO.Write(0L);
|
||||
if (Aif.Value.Unk3.Count > 0) { IO.Write(Aif.Value.Unk3.Count); IO.Write(Aif.Value.Unk3.Offset); }
|
||||
else IO.Write(0L);
|
||||
}
|
||||
|
||||
public static Pointer<Eff> ReadEff(this Stream IO, ref Dictionary<int, AetObject> ObjectsDict)
|
||||
{
|
||||
Pointer<Eff> Eff = new Pointer<Eff> { Offset = IO.Position,
|
||||
Value = new Eff
|
||||
{
|
||||
LayerID = IO.ReadInt32(),
|
||||
ParentObjectID = IO.ReadInt32(),
|
||||
Marker = IO.ReadCountPointer<Marker>()
|
||||
}
|
||||
};
|
||||
Eff.Value.Data.Offset = IO.ReadInt32();
|
||||
IO.Position = Eff.Value.LayerID;
|
||||
CountPointer<AetObject> AetObjEntry = IO.ReadCountPointer<AetObject>();
|
||||
IO.Position = AetObjEntry.Offset;
|
||||
for (int i = 0; i < AetObjEntry.Count; i++) IO.ReadAetObject(ref ObjectsDict);
|
||||
IO.Position = Eff.Value.Marker.Offset;
|
||||
for (int i = 0; i < Eff.Value.Marker.Count; i++)
|
||||
{
|
||||
Eff.Value.Marker.Entries[i].Frame = IO.ReadSingle();
|
||||
Eff.Value.Marker.Entries[i]. Name = IO.ReadPointerStringShiftJIS();
|
||||
}
|
||||
IO.ReadAnimData(ref Eff.Value.Data);
|
||||
|
||||
return Eff;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ref Pointer<Eff> Eff)
|
||||
{
|
||||
Eff.Offset = IO.Position;
|
||||
IO.Write(0L);
|
||||
if (Eff.Value.Marker.Count > 0)
|
||||
{
|
||||
IO.Write(Eff.Value.Marker.Count );
|
||||
IO.Write(Eff.Value.Marker.Offset);
|
||||
}
|
||||
else IO.Write(0L);
|
||||
IO.Write(Eff.Value.Data.Offset);
|
||||
IO.Write(0);
|
||||
}
|
||||
|
||||
public static void ReadAnimData(this Stream IO, ref Pointer<AnimationData> Anim)
|
||||
{
|
||||
ref AnimationData Data = ref Anim.Value;
|
||||
IO.Position = Anim.Offset;
|
||||
Data.BlendMode = (BlendMode)IO.ReadByte();
|
||||
Data.Mode = (AnimationData.BlendMode)IO.ReadByte();
|
||||
Data.Unk0 = IO.ReadByte();
|
||||
Data.UseTextureMask = IO.ReadBoolean();
|
||||
Data.Unk1 = IO.ReadByte();
|
||||
Data.Anim = IO.ReadSubAnimData();
|
||||
Data.SubAnim = IO.ReadPointer<SubAnimationData>();
|
||||
|
||||
IO.ReadSubAnimData(ref Data.Anim);
|
||||
|
||||
if (Data.SubAnim.Offset > 0)
|
||||
{
|
||||
IO.Position = Data.SubAnim.Offset;
|
||||
Data.SubAnim.Value = IO.ReadSubAnimData();
|
||||
IO.ReadSubAnimData(ref Data.SubAnim.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public static SubAnimationData ReadSubAnimData(this Stream IO)
|
||||
{
|
||||
SubAnimationData Data = new SubAnimationData() { };
|
||||
Data. OriginX = IO.ReadKeyFrameEntry();
|
||||
Data. OriginY = IO.ReadKeyFrameEntry();
|
||||
Data.PositionX = IO.ReadKeyFrameEntry();
|
||||
@@ -322,11 +254,8 @@ namespace KKdMainLib.Aet
|
||||
Data. ScaleX = IO.ReadKeyFrameEntry();
|
||||
Data. ScaleY = IO.ReadKeyFrameEntry();
|
||||
Data.Opacity = IO.ReadKeyFrameEntry();
|
||||
return Data;
|
||||
}
|
||||
Data._3D = IO.ReadPointer<AnimationData3D>();
|
||||
|
||||
public static void ReadSubAnimData(this Stream IO, ref SubAnimationData Data)
|
||||
{
|
||||
IO.ReadKeyFrameEntry(ref Data. OriginX);
|
||||
IO.ReadKeyFrameEntry(ref Data. OriginY);
|
||||
IO.ReadKeyFrameEntry(ref Data.PositionX);
|
||||
@@ -335,38 +264,47 @@ namespace KKdMainLib.Aet
|
||||
IO.ReadKeyFrameEntry(ref Data. ScaleX);
|
||||
IO.ReadKeyFrameEntry(ref Data. ScaleY);
|
||||
IO.ReadKeyFrameEntry(ref Data.Opacity );
|
||||
|
||||
if (Data._3D.Offset > 0)
|
||||
{
|
||||
IO.Position = Data._3D.Offset;
|
||||
Data._3D.Value.Unk1 = IO.ReadKeyFrameEntry();
|
||||
Data._3D.Value.Unk2 = IO.ReadKeyFrameEntry();
|
||||
Data._3D.Value.RotReturnX = IO.ReadKeyFrameEntry();
|
||||
Data._3D.Value.RotReturnY = IO.ReadKeyFrameEntry();
|
||||
Data._3D.Value.RotReturnZ = IO.ReadKeyFrameEntry();
|
||||
Data._3D.Value. RotationX = IO.ReadKeyFrameEntry();
|
||||
Data._3D.Value. RotationY = IO.ReadKeyFrameEntry();
|
||||
Data._3D.Value. ScaleZ = IO.ReadKeyFrameEntry();
|
||||
|
||||
IO.ReadKeyFrameEntry(ref Data._3D.Value.Unk1 );
|
||||
IO.ReadKeyFrameEntry(ref Data._3D.Value.Unk2 );
|
||||
IO.ReadKeyFrameEntry(ref Data._3D.Value.RotReturnX);
|
||||
IO.ReadKeyFrameEntry(ref Data._3D.Value.RotReturnY);
|
||||
IO.ReadKeyFrameEntry(ref Data._3D.Value.RotReturnZ);
|
||||
IO.ReadKeyFrameEntry(ref Data._3D.Value. RotationX);
|
||||
IO.ReadKeyFrameEntry(ref Data._3D.Value. RotationY);
|
||||
IO.ReadKeyFrameEntry(ref Data._3D.Value. ScaleZ);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ref Pointer<AnimationData> Anim, ref List<int> NullValPointers)
|
||||
public static void Write(this Stream IO, ref Pointer<AnimationData> Anim, ref KKdList<int> NullValPointers)
|
||||
{
|
||||
ref AnimationData Data = ref Anim.Value;
|
||||
|
||||
byte SubFlags = 0;
|
||||
if (Data.SubAnim.Offset > -1)
|
||||
SubFlags = IO.Write(ref Data.SubAnim.Value);
|
||||
|
||||
byte Flags = IO.Write(ref Data.Anim);
|
||||
|
||||
if (Data.SubAnim.Offset > -1)
|
||||
int SubFlags = 0;
|
||||
if (Data._3D.Offset > -1)
|
||||
{
|
||||
IO.Align(0x20);
|
||||
Data.SubAnim.Offset = IO.Position;
|
||||
IO.Write(ref Data.SubAnim.Value, ref NullValPointers, Flags);
|
||||
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;
|
||||
}
|
||||
|
||||
IO.Align(0x20);
|
||||
Anim.Offset = IO.Position;
|
||||
IO.WriteByte((byte) Data.BlendMode);
|
||||
IO.WriteByte( Data.Unk0);
|
||||
IO.WriteByte((byte)(Data.UseTextureMask ? 1 : 0));
|
||||
IO.WriteByte( Data.Unk1);
|
||||
|
||||
IO.Write(ref Data.Anim, ref NullValPointers, Flags);
|
||||
IO.Write(Data.SubAnim.Offset > -1 ? Data.SubAnim.Offset : 0);
|
||||
}
|
||||
|
||||
public static byte Write(this Stream IO, ref SubAnimationData Data)
|
||||
{
|
||||
int Flags = 0;
|
||||
Flags |= IO.Write(ref Data. OriginX) ? 0b10000000 : 0;
|
||||
Flags |= IO.Write(ref Data. OriginY) ? 0b01000000 : 0;
|
||||
@@ -376,10 +314,27 @@ namespace KKdMainLib.Aet
|
||||
Flags |= IO.Write(ref Data. ScaleX) ? 0b00000100 : 0;
|
||||
Flags |= IO.Write(ref Data. ScaleY) ? 0b00000010 : 0;
|
||||
Flags |= IO.Write(ref Data.Opacity ) ? 0b00000001 : 0;
|
||||
return (byte)Flags;
|
||||
|
||||
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 SubAnimationData Data, ref List<int> NullValPointers, byte Flags)
|
||||
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);
|
||||
@@ -407,6 +362,35 @@ namespace KKdMainLib.Aet
|
||||
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() };
|
||||
|
||||
@@ -430,8 +414,8 @@ namespace KKdMainLib.Aet
|
||||
|
||||
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; }
|
||||
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++)
|
||||
@@ -446,16 +430,16 @@ namespace KKdMainLib.Aet
|
||||
mark.Count = 1;
|
||||
mark.Entries[0].ReadMP(Marker);
|
||||
}
|
||||
else if (msg.Element<MsgPack>("Markers", out MsgPack Markers))
|
||||
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] as MsgPack);
|
||||
mark.Entries[i].ReadMP(Markers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WritePointerString(this Stream IO,
|
||||
ref Dictionary<string, int> Dict, ref Pointer<string> Str)
|
||||
ref System.Collections.Generic.Dictionary<string, int> Dict, ref Pointer<string> Str)
|
||||
{
|
||||
if (Dict.ContainsKey(Str.Value)) Str.Offset = Dict[Str.Value];
|
||||
else
|
||||
|
||||
@@ -192,13 +192,13 @@ namespace KKdMainLib.DB
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
|
||||
if (MsgPack.Element<MsgPack>("AetDB", out MsgPack AetDB))
|
||||
if (MsgPack.ElementArray("AetDB", out MsgPack AetDB))
|
||||
{
|
||||
AetSets = new AetSet[AetDB.Array.Length];
|
||||
for (int i = 0; i < AetSets.Length; i++)
|
||||
AetSets[i].ReadMsgPack(AetDB[i] as MsgPack);
|
||||
AetSets[i].ReadMsgPack(AetDB[i]);
|
||||
}
|
||||
MsgPack = null;
|
||||
MsgPack = MsgPack.New;
|
||||
}
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ namespace KKdMainLib.DB
|
||||
if (AetSets == null) return;
|
||||
if (AetSets.Length == 0) return;
|
||||
|
||||
MsgPack AetDB = new MsgPack("AetDB", AetSets.Length);
|
||||
MsgPack AetDB = new MsgPack(AetSets.Length, "AetDB");
|
||||
for (i = 0; i < AetSets.Length; i++)
|
||||
AetDB[i] = AetSets[i].WriteMsgPack();
|
||||
|
||||
@@ -224,7 +224,7 @@ namespace KKdMainLib.DB
|
||||
{ Id = msg.ReadNUInt16("Id"); Name = msg.ReadString("Name"); }
|
||||
|
||||
public MsgPack WriteMsgPack() =>
|
||||
new MsgPack().Add("Id", Id).Add("Name", Name);
|
||||
MsgPack.New.Add("Id", Id).Add("Name", Name);
|
||||
}
|
||||
|
||||
public struct AetSet
|
||||
@@ -246,21 +246,21 @@ namespace KKdMainLib.DB
|
||||
NewId = msg.ReadBoolean("NewId" );
|
||||
SpriteSetId = msg.ReadNUInt16("SpriteSetId");
|
||||
|
||||
if (msg.Element<MsgPack>("Aets", out MsgPack Aets))
|
||||
if (msg.ElementArray("Aets", out MsgPack Aets))
|
||||
{
|
||||
this.Aets = new AET[Aets.Array.Length];
|
||||
for (int i0 = 0; i0 < this.Aets.Length; i0++)
|
||||
this.Aets[i0].ReadMsgPack(Aets[i0] as MsgPack);
|
||||
this.Aets[i0].ReadMsgPack(Aets[i0]);
|
||||
}
|
||||
}
|
||||
|
||||
public MsgPack WriteMsgPack()
|
||||
{
|
||||
MsgPack Aets = new MsgPack("Aets", this.Aets.Length);
|
||||
MsgPack Aets = new MsgPack(this.Aets.Length, "Aets");
|
||||
for (int i0 = 0; i0 < this.Aets.Length; i0++)
|
||||
Aets[i0] = this.Aets[i0].WriteMsgPack();
|
||||
|
||||
return new MsgPack().Add("FileName", FileName).Add("Id", Id)
|
||||
return MsgPack.New.Add("FileName", FileName).Add("Id", Id)
|
||||
.Add("Name", Name).Add("SpriteSetId", SpriteSetId).Add(Aets);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-16
@@ -103,28 +103,26 @@ namespace KKdMainLib.DB
|
||||
|
||||
if (MsgPack.Element("AuthDB", out MsgPack AuthDB))
|
||||
{
|
||||
if (AuthDB.Element("Category", out MsgPack Temp))
|
||||
if (AuthDB.ElementArray("Category", out MsgPack Temp))
|
||||
{
|
||||
this.Category = new string[Temp.Array.Length];
|
||||
for (int i = 0; i < this.Category.Length; i++)
|
||||
this.Category[i] = (Temp[i] as MsgPack).ReadString();
|
||||
Category = new string[Temp.Array.Length];
|
||||
for (int i = 0; i < Category.Length; i++)
|
||||
Category[i] = Temp[i].ReadString();
|
||||
}
|
||||
|
||||
if (AuthDB.Element("UID", out Temp))
|
||||
if (AuthDB.ElementArray("UID", out Temp))
|
||||
{
|
||||
_UID = new UID[Temp.Array.Length];
|
||||
MsgPack UID;
|
||||
for (int i = 0; i < _UID.Length; i++)
|
||||
{
|
||||
UID = Temp[i] as MsgPack;
|
||||
_UID[i].Category = UID.ReadString("C");
|
||||
_UID[i].OrgUid = UID.ReadNInt32("O");
|
||||
_UID[i].Size = UID.ReadNInt32("S");
|
||||
_UID[i].Value = UID.ReadString("V");
|
||||
_UID[i].Category = Temp[i].ReadString("C");
|
||||
_UID[i].OrgUid = Temp[i].ReadNInt32("O");
|
||||
_UID[i].Size = Temp[i].ReadNInt32("S");
|
||||
_UID[i].Value = Temp[i].ReadString("V");
|
||||
}
|
||||
}
|
||||
}
|
||||
MsgPack = null;
|
||||
MsgPack = MsgPack.New;
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
@@ -132,17 +130,17 @@ namespace KKdMainLib.DB
|
||||
MsgPack AuthDB = new MsgPack("AuthDB");
|
||||
if (Category != null)
|
||||
{
|
||||
MsgPack Category = new MsgPack("Category", this.Category.Length);
|
||||
MsgPack Category = new MsgPack(this.Category.Length, "Category");
|
||||
for (int i = 0; i < this.Category.Length; i++)
|
||||
Category[i] = this.Category[i];
|
||||
Category[i] = (MsgPack)this.Category[i];
|
||||
AuthDB.Add(Category);
|
||||
}
|
||||
|
||||
if (_UID != null)
|
||||
{
|
||||
MsgPack UID = new MsgPack("UID", _UID.Length);
|
||||
MsgPack UID = new MsgPack(_UID.Length, "UID");
|
||||
for (int i = 0; i < _UID.Length; i++)
|
||||
UID[i] = new MsgPack()
|
||||
UID[i] = MsgPack.New
|
||||
.Add("C", _UID[i].Category)
|
||||
.Add("O", _UID[i].OrgUid )
|
||||
.Add("S", _UID[i].Size )
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
// Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary
|
||||
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.Types;
|
||||
using KKdMainLib.MessagePack;
|
||||
using MPIO = KKdMainLib.MessagePack.IO;
|
||||
|
||||
namespace KKdMainLib.DB
|
||||
{
|
||||
public class BoneData
|
||||
{
|
||||
public Stream IO;
|
||||
public BONE Data;
|
||||
|
||||
private int i, i0;
|
||||
|
||||
public BoneData()
|
||||
{ Data = new BONE(); }
|
||||
|
||||
public void BONReader(string file, string ext)
|
||||
{
|
||||
Data = new BONE { Header = new PDHead() };
|
||||
IO = File.OpenReader(file + ext);
|
||||
|
||||
IO.Format = Main.Format.F;
|
||||
Data.Header.Signature = IO.ReadInt32();
|
||||
if (Data.Header.Signature == 0x454E4F42)
|
||||
{
|
||||
Data.Header = IO.ReadHeader(true);
|
||||
Data.POF = Data.Header.AddPOF();
|
||||
}
|
||||
if (Data.Header.Signature != 0x09102720)
|
||||
return;
|
||||
|
||||
Data.Skeleton = new SkeletonEntry[IO.ReadInt32Endian()];
|
||||
Data.SkeletonsOffset = IO.ReadUInt32Endian(ref Data.POF);
|
||||
Data.SkeletonNamesOffset = IO.ReadUInt32Endian();
|
||||
if (Data.SkeletonNamesOffset == 0)
|
||||
{
|
||||
IO.IsX = true;
|
||||
IO.Format = Main.Format.X;
|
||||
Data.POF.POFOffsets = new List<long>();
|
||||
IO.Seek(Data.Header.Lenght, 0);
|
||||
IO.LongOffset = Data.Header.Lenght;
|
||||
Data.Header.Signature = IO.ReadInt32();
|
||||
Data.Skeleton = new SkeletonEntry[IO.ReadInt32Endian()];
|
||||
Data.SkeletonsOffset = IO.ReadInt64();
|
||||
Data.SkeletonNamesOffset = IO.ReadInt64(ref Data.POF);
|
||||
}
|
||||
else
|
||||
{
|
||||
IO.LongPosition -= 4;
|
||||
IO.GetOffset(ref Data.POF);
|
||||
IO.LongPosition += 4;
|
||||
}
|
||||
|
||||
Data.SkeletonEntryOffset = new long[Data.Skeleton.Length];
|
||||
IO.LongPosition = Data.SkeletonsOffset;
|
||||
for (i0 = 0; i0 < Data.Skeleton.Length; i0++)
|
||||
Data.SkeletonEntryOffset[i0] = IO.ReadIntX(ref Data.POF);
|
||||
|
||||
for (i0 = 0; i0 < Data.Skeleton.Length; i0++)
|
||||
{
|
||||
Data.Skeleton[i0] = new SkeletonEntry();
|
||||
IO.LongPosition = Data.SkeletonEntryOffset[i0];
|
||||
|
||||
Data.Skeleton[i0].BoneOffset = IO.ReadIntX(ref Data.POF);
|
||||
Data.Skeleton[i0].Position = new Vector3<float>[IO.ReadIntX()];
|
||||
Data.Skeleton[i0].PositionOffset = IO.ReadIntX(ref Data.POF);
|
||||
Data.Skeleton[i0].Field02Offset = IO.ReadIntX(ref Data.POF);
|
||||
Data.Skeleton[i0].BoneName1 = new string[IO.ReadIntX()];
|
||||
Data.Skeleton[i0].BoneName1Offset = IO.ReadIntX(ref Data.POF);
|
||||
Data.Skeleton[i0].BoneName2 = new string[IO.ReadIntX()];
|
||||
Data.Skeleton[i0].BoneName2Offset = IO.ReadIntX(ref Data.POF);
|
||||
Data.Skeleton[i0].ParentIndiceOffset = IO.ReadIntX(ref Data.POF);
|
||||
|
||||
IO.LongPosition = Data.SkeletonNamesOffset + i0 << (IO.IsX ? 3 : 2);
|
||||
|
||||
Data.Skeleton[i0].Name = IO.ReadStringAtOffset(ref Data.POF);
|
||||
IO.LongPosition = Data.Skeleton[i0].BoneOffset;
|
||||
|
||||
long Count = 0;
|
||||
string Name = "";
|
||||
while (true)
|
||||
{
|
||||
IO.ReadUInt64();
|
||||
Name = IO.ReadStringAtOffset(ref Data.POF);
|
||||
if (Name == "End") break;
|
||||
Count++;
|
||||
}
|
||||
|
||||
Data.Skeleton[i0].Bone = new BoneEntry[Count];
|
||||
for (i = 0; i < Count; i++)
|
||||
{
|
||||
Data.Skeleton[i0].Bone[i].Type = (BoneType)IO.ReadByte ();
|
||||
Data.Skeleton[i0].Bone[i].HasParent = IO.ReadBoolean();
|
||||
Data.Skeleton[i0].Bone[i].ParentNameIndex = IO.ReadByte ();
|
||||
Data.Skeleton[i0].Bone[i].Field01 = IO.ReadByte ();
|
||||
Data.Skeleton[i0].Bone[i].PairNameIndex = IO.ReadByte ();
|
||||
Data.Skeleton[i0].Bone[i].Field02 = IO.ReadByte ();
|
||||
IO.ReadInt16Endian();
|
||||
Data.Skeleton[i0].Bone[i].Name = IO.ReadStringAtOffset(ref Data.POF);
|
||||
}
|
||||
|
||||
IO.LongPosition = Data.Skeleton[i0].PositionOffset;
|
||||
for (i = 0; i < Data.Skeleton[i0].Position.Length; i++)
|
||||
Data.Skeleton[i0].Position[i] = new Vector3<float>(IO.ReadSingleEndian(),
|
||||
IO.ReadSingleEndian(), IO.ReadSingleEndian());
|
||||
|
||||
IO.LongPosition = Data.Skeleton[i0].Field02Offset;
|
||||
Data.Skeleton[i0].Field02 = IO.ReadIntX();
|
||||
|
||||
IO.LongPosition = Data.Skeleton[i0].BoneName1Offset;
|
||||
for (i = 0; i < Data.Skeleton[i0].BoneName1.Length; i++)
|
||||
Data.Skeleton[i0].BoneName1[i] = IO.ReadStringAtOffset(ref Data.POF);
|
||||
|
||||
IO.LongPosition = Data.Skeleton[i0].BoneName2Offset;
|
||||
for (i = 0; i < Data.Skeleton[i0].BoneName2.Length; i++)
|
||||
Data.Skeleton[i0].BoneName2[i] = IO.ReadStringAtOffset(ref Data.POF);
|
||||
|
||||
IO.LongPosition = Data.Skeleton[i0].ParentIndiceOffset;
|
||||
for (i = 0; i < Data.Skeleton[i0].BoneName2.Length; i++)
|
||||
Data.Skeleton[i0].ParentIndice[i] = IO.ReadInt16Endian();
|
||||
}
|
||||
if (IO.Format > Main.Format.F)
|
||||
{
|
||||
IO.LongPosition = Data.POF.Offset;
|
||||
IO.ReadPOF(ref Data.POF);
|
||||
}
|
||||
IO.Close();
|
||||
}
|
||||
|
||||
public void BONWriter(string file, Main.Format Format)
|
||||
{
|
||||
IO = File.OpenWriter(file + ".bon", true);
|
||||
IO.Close();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
|
||||
MsgPack = null;
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
{
|
||||
MsgPack BoneDB = new MsgPack("BoneDB", Data.Skeleton.Length);
|
||||
for (i0 = 0; i0 < Data.Skeleton.Length; i0++)
|
||||
{
|
||||
MsgPack Skeleton = new MsgPack().Add("Name" , Data.Skeleton[i0].Name )
|
||||
.Add("Field02", Data.Skeleton[i0].Field02);
|
||||
|
||||
MsgPack Bone = new MsgPack("Bone", Data.Skeleton[i0].Bone.Length);
|
||||
for (i = 0; i < Data.Skeleton[i0].Bone.Length; i++)
|
||||
Bone[i] = new MsgPack().Add("Type" , (byte) Data.Skeleton[i0].Bone[i].Type )
|
||||
.Add("HasParent" , Data.Skeleton[i0].Bone[i].HasParent )
|
||||
.Add("ParentNameIndex", Data.Skeleton[i0].Bone[i].ParentNameIndex)
|
||||
.Add("Field01" , Data.Skeleton[i0].Bone[i].Field01 )
|
||||
.Add("PairNameIndex" , Data.Skeleton[i0].Bone[i].PairNameIndex )
|
||||
.Add("Field02" , Data.Skeleton[i0].Bone[i].Field02 )
|
||||
.Add("Name" , Data.Skeleton[i0].Bone[i].Name );
|
||||
Skeleton.Add(Bone);
|
||||
|
||||
MsgPack Position = new MsgPack("Position", Data.Skeleton[i0].Position.Length);
|
||||
for (i = 0; i < Data.Skeleton[i0].Position.Length; i++)
|
||||
Position[i] = new MsgPack().Add("X", Data.Skeleton[i0].Position[i].X)
|
||||
.Add("Y", Data.Skeleton[i0].Position[i].Y)
|
||||
.Add("Z", Data.Skeleton[i0].Position[i].Z);
|
||||
Skeleton.Add(Position);
|
||||
|
||||
MsgPack BoneName1 = new MsgPack("BoneName1", Data.Skeleton[i0].BoneName1.Length);
|
||||
for (i = 0; i < Data.Skeleton[i0].BoneName1.Length; i++)
|
||||
BoneName1[i] = Data.Skeleton[i0].BoneName1[i];
|
||||
Skeleton.Add(BoneName1);
|
||||
|
||||
MsgPack BoneName2 = new MsgPack("BoneName2", Data.Skeleton[i0].BoneName2.Length);
|
||||
for (i = 0; i < Data.Skeleton[i0].BoneName2.Length; i++)
|
||||
BoneName2[i] = Data.Skeleton[i0].BoneName2[i];
|
||||
Skeleton.Add(BoneName2);
|
||||
|
||||
MsgPack ParentIndice = new MsgPack("ParentIndice", Data.Skeleton[i0].ParentIndice.Length);
|
||||
for (i = 0; i < Data.Skeleton[i0].ParentIndice.Length; i++)
|
||||
ParentIndice[i] = Data.Skeleton[i0].ParentIndice[i];
|
||||
BoneDB[i0] = Skeleton.Add(ParentIndice);
|
||||
}
|
||||
|
||||
BoneDB.Write(true, file, JSON);
|
||||
}
|
||||
|
||||
/*public struct Bone
|
||||
{
|
||||
public List<string> Names;
|
||||
public List<long> Offsets;
|
||||
}*/
|
||||
|
||||
public struct BONE
|
||||
{
|
||||
public long SkeletonsOffset;
|
||||
public long SkeletonNamesOffset;
|
||||
public POF POF;
|
||||
public PDHead Header;
|
||||
public long[] SkeletonEntryOffset;
|
||||
public SkeletonEntry[] Skeleton;
|
||||
}
|
||||
|
||||
public struct BoneEntry
|
||||
{
|
||||
public bool HasParent;
|
||||
public byte Field01;
|
||||
public byte Field02;
|
||||
public byte PairNameIndex;
|
||||
public byte ParentNameIndex;
|
||||
public string Name;
|
||||
public BoneType Type;
|
||||
}
|
||||
|
||||
public enum BoneType : byte
|
||||
{
|
||||
Rotation = 0,
|
||||
Type1 = 1,
|
||||
Position = 2,
|
||||
Type3 = 3,
|
||||
Type4 = 4,
|
||||
Type5 = 5,
|
||||
Type6 = 6,
|
||||
};
|
||||
|
||||
public struct SkeletonEntry
|
||||
{
|
||||
public long BoneOffset;
|
||||
public long Field02Offset;
|
||||
public long PositionOffset;
|
||||
public long BoneName1Offset;
|
||||
public long BoneName2Offset;
|
||||
public long ParentIndiceOffset;
|
||||
|
||||
public long Field02;
|
||||
public string Name;
|
||||
public short[] ParentIndice;
|
||||
public string[] BoneName1;
|
||||
public string[] BoneName2;
|
||||
public BoneEntry[] Bone;
|
||||
public Vector3<float>[] Position;
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
-14
@@ -249,13 +249,13 @@ namespace KKdMainLib.DB
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
|
||||
if (MsgPack.Element<MsgPack>("SprDB", out MsgPack SprDB))
|
||||
if (MsgPack.ElementArray("SprDB", out MsgPack SprDB))
|
||||
{
|
||||
SpriteSets = new SpriteSet[SprDB.Array.Length];
|
||||
for (int i = 0; i < SpriteSets.Length; i++)
|
||||
SpriteSets[i].ReadMsgPack(SprDB[i] as MsgPack);
|
||||
SpriteSets[i].ReadMsgPack(SprDB[i]);
|
||||
}
|
||||
MsgPack = null;
|
||||
MsgPack = MsgPack.New;
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
@@ -263,7 +263,7 @@ namespace KKdMainLib.DB
|
||||
if (SpriteSets == null) return;
|
||||
if (SpriteSets.Length == 0) return;
|
||||
|
||||
MsgPack SprDB = new MsgPack("SprDB", SpriteSets.Length);
|
||||
MsgPack SprDB = new MsgPack(SpriteSets.Length, "SprDB");
|
||||
for (i = 0; i < SpriteSets.Length; i++) SprDB[i] = SpriteSets[i].WriteMsgPack();
|
||||
|
||||
SprDB.Write(true, file, JSON);
|
||||
@@ -279,7 +279,7 @@ namespace KKdMainLib.DB
|
||||
{ Id = msg.ReadNInt32("Id"); Name = msg.ReadString("Name"); }
|
||||
|
||||
public MsgPack WriteMsgPack() =>
|
||||
new MsgPack().Add("Id", Id).Add("Name", Name);
|
||||
MsgPack.New.Add("Id", Id).Add("Name", Name);
|
||||
}
|
||||
|
||||
public struct SpriteSet
|
||||
@@ -300,32 +300,32 @@ namespace KKdMainLib.DB
|
||||
Name = msg.ReadString ("Name" );
|
||||
NewId = msg.ReadBoolean("NewId" );
|
||||
|
||||
if (msg.Element<MsgPack>( "Sprites", out MsgPack Sprites))
|
||||
if (msg.ElementArray( "Sprites", out MsgPack Sprites))
|
||||
{
|
||||
this .Sprites = new SpriteTexture[Sprites.Array.Length];
|
||||
this.Sprites = new SpriteTexture[Sprites.Array.Length];
|
||||
for (int i0 = 0; i0 < this.Sprites.Length; i0++)
|
||||
this.Sprites[i0].ReadMsgPack(Sprites[i0] as MsgPack);
|
||||
this.Sprites[i0].ReadMsgPack(Sprites[i0]);
|
||||
}
|
||||
|
||||
if (msg.Element<MsgPack>("Textures", out MsgPack Textures))
|
||||
if (msg.ElementArray("Textures", out MsgPack Textures))
|
||||
{
|
||||
this .Textures = new SpriteTexture[Textures.Array.Length];
|
||||
this.Textures = new SpriteTexture[Textures.Array.Length];
|
||||
for (int i0 = 0; i0 < this.Textures.Length; i0++)
|
||||
this.Textures[i0].ReadMsgPack(Textures[i0] as MsgPack);
|
||||
this.Textures[i0].ReadMsgPack(Textures[i0]);
|
||||
}
|
||||
}
|
||||
|
||||
public MsgPack WriteMsgPack()
|
||||
{
|
||||
MsgPack Sprites = new MsgPack( "Sprites", this.Sprites.Length);
|
||||
MsgPack Sprites = new MsgPack(this. Sprites.Length, "Sprites");
|
||||
for (int i0 = 0; i0 < this.Sprites.Length; i0++)
|
||||
Sprites[i0] = this.Sprites[i0].WriteMsgPack();
|
||||
|
||||
MsgPack Textures = new MsgPack("Textures", this.Textures.Length);
|
||||
MsgPack Textures = new MsgPack(this.Textures.Length, "Textures");
|
||||
for (int i0 = 0; i0 < this.Textures.Length; i0++)
|
||||
Textures[i0] = this.Textures[i0].WriteMsgPack();
|
||||
|
||||
return new MsgPack().Add("FileName", FileName).Add("Id", Id).Add("Name", Name).Add(Sprites).Add(Textures);
|
||||
return MsgPack.New.Add("FileName", FileName).Add("Id", Id).Add("Name", Name).Add(Sprites).Add(Textures);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+23
-26
@@ -95,7 +95,7 @@ namespace KKdMainLib
|
||||
public void DEXWriter(string filepath, Main.Format Format)
|
||||
{
|
||||
Header = new PDHead() { Format = Format };
|
||||
IO = File.OpenWriter(filepath + (Header.Format > Main.Format.F ? ".Dex" : ".bin"), true);
|
||||
IO = File.OpenWriter(filepath + (Header.Format > Main.Format.F ? ".dex" : ".bin"), true);
|
||||
IO.Format = Header.Format;
|
||||
|
||||
if (IO.Format > Main.Format.F)
|
||||
@@ -196,31 +196,28 @@ namespace KKdMainLib
|
||||
this.Dex = new EXP[0];
|
||||
Header = new PDHead();
|
||||
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
if (!MsgPack.Element<MsgPack>("Dex", out MsgPack Dex)) return;
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
if (!MsgPack.ElementArray("Dex", out MsgPack Dex)) return;
|
||||
|
||||
this.Dex = new EXP[Dex.Array.Length];
|
||||
for (i0 = 0; i0 < this.Dex.Length; i0++)
|
||||
if (Dex[i0] is MsgPack EXP)
|
||||
{
|
||||
this.Dex[i0] = new EXP { Name = EXP.ReadString("Name") };
|
||||
{
|
||||
this.Dex[i0] = new EXP { Name = Dex[i0].ReadString("Name") };
|
||||
|
||||
if (EXP.Element<MsgPack>("Main", out MsgPack Main))
|
||||
{
|
||||
this.Dex[i0].Main = new List<EXPElement>();
|
||||
for (i1 = 0; i1 < Main.Array.Length; i1++)
|
||||
if (Main[i1] is MsgPack Exp)
|
||||
this.Dex[i0].Main.Add(ReadEXP(Exp));
|
||||
}
|
||||
if (EXP.Element<MsgPack>("Eyes", out MsgPack Eyes))
|
||||
{
|
||||
this.Dex[i0].Eyes = new List<EXPElement>();
|
||||
for (i1 = 0; i1 < Eyes.Array.Length; i1++)
|
||||
if (Eyes[i1] is MsgPack Exp)
|
||||
this.Dex[i0].Eyes.Add(ReadEXP(Exp));
|
||||
}
|
||||
if (Dex[i0].ElementArray("Main", out MsgPack Main))
|
||||
{
|
||||
this.Dex[i0].Main = new List<EXPElement>();
|
||||
for (i1 = 0; i1 < Main.Array.Length; i1++)
|
||||
this.Dex[i0].Main.Add(ReadEXP(Main[i1]));
|
||||
}
|
||||
MsgPack = null;
|
||||
if (Dex[i0].ElementArray("Eyes", out MsgPack Eyes))
|
||||
{
|
||||
this.Dex[i0].Eyes = new List<EXPElement>();
|
||||
for (i1 = 0; i1 < Eyes.Array.Length; i1++)
|
||||
this.Dex[i0].Eyes.Add(ReadEXP(Eyes[i1]));
|
||||
}
|
||||
}
|
||||
MsgPack = MsgPack.New;
|
||||
}
|
||||
|
||||
private EXPElement ReadEXP(MsgPack mp) =>
|
||||
@@ -232,16 +229,16 @@ namespace KKdMainLib
|
||||
{
|
||||
int i0 = 0;
|
||||
int i1 = 0;
|
||||
MsgPack Dex = new MsgPack("Dex", this.Dex.Length);
|
||||
MsgPack Dex = new MsgPack(this.Dex.Length, "Dex");
|
||||
for (i0 = 0; i0 < this.Dex.Length; i0++)
|
||||
{
|
||||
MsgPack EXP = new MsgPack().Add("Name", this.Dex[i0].Name);
|
||||
MsgPack Main = new MsgPack("Main", this.Dex[i0].Main.Count);
|
||||
MsgPack EXP = MsgPack.New.Add("Name", this.Dex[i0].Name);
|
||||
MsgPack Main = new MsgPack(this.Dex[i0].Main.Count, "Main");
|
||||
for (i1 = 0; i1 < this.Dex[i0].Main.Count; i1++)
|
||||
Main[i1] = WriteEXP(this.Dex[i0].Main[i1]);
|
||||
EXP.Add(Main);
|
||||
|
||||
MsgPack Eyes = new MsgPack("Eyes", this.Dex[i0].Eyes.Count);
|
||||
MsgPack Eyes = new MsgPack(this.Dex[i0].Eyes.Count, "Eyes");
|
||||
for (i1 = 0; i1 < this.Dex[i0].Eyes.Count; i1++)
|
||||
Eyes[i1] = WriteEXP(this.Dex[i0].Eyes[i1]);
|
||||
EXP.Add(Eyes);
|
||||
@@ -252,7 +249,7 @@ namespace KKdMainLib
|
||||
}
|
||||
|
||||
private MsgPack WriteEXP(EXPElement element) =>
|
||||
new MsgPack().Add("F", element.Frame).Add("B", element.Both ).Add("I", element.ID )
|
||||
MsgPack.New.Add("F", element.Frame).Add("B", element.Both ).Add("I", element.ID )
|
||||
.Add("V", element.Value).Add("T", element.Trans);
|
||||
|
||||
public struct EXP
|
||||
|
||||
+149
-24
@@ -12,7 +12,8 @@ namespace KKdMainLib
|
||||
private Stream IO;
|
||||
private int i;
|
||||
|
||||
private PvList[] pvList;
|
||||
private PvList[] pvList;
|
||||
private psrData[] psrDat;
|
||||
|
||||
private const string d = ".";
|
||||
private const string c = ",";
|
||||
@@ -27,7 +28,13 @@ namespace KKdMainLib
|
||||
while (text.Contains("%")) text = WebUtility.UrlDecode(text);
|
||||
string[] array = text.Split(',');
|
||||
|
||||
if (file.Contains("PvList") && array.Length % 7 < 2)
|
||||
if (file.Contains("psrData") && array.Length % 13 < 2)
|
||||
{
|
||||
psrDat = new psrData[array.Length / 13];
|
||||
for (i = 0; i < psrDat.Length; i++) psrDat[i].SetValue(array, i);
|
||||
Success = true;
|
||||
}
|
||||
else if (file.Contains("PvList") && array.Length % 7 < 2)
|
||||
{
|
||||
pvList = new PvList[array.Length / 7];
|
||||
for (i = 0; i < pvList.Length; i++) pvList[i].SetValue(array, i);
|
||||
@@ -40,16 +47,18 @@ namespace KKdMainLib
|
||||
if (!Success) return;
|
||||
|
||||
IO = File.OpenWriter();
|
||||
if (file.Contains("PvList"))
|
||||
{
|
||||
if (file.Contains("psrData"))
|
||||
for (i = 0; i < psrDat.Length; i++)
|
||||
IO.Write(psrDat[i].ToString() + ",");
|
||||
else if (file.Contains("PvList"))
|
||||
if (pvList.Length != 0)
|
||||
for (i = 0; i < pvList.Length; i++)
|
||||
IO.Write(UrlEncode(pvList[i].ToString() +
|
||||
((i + 1 != pvList.Length) ? "," : "")));
|
||||
else IO.Write("%2A%2A%2A");
|
||||
}
|
||||
|
||||
|
||||
byte[] data = IO.ToArray(Close: true);
|
||||
byte[] data = IO.ToArray(true);
|
||||
ushort num = DCC.CalculateChecksum(data);
|
||||
uint num2 = (uint)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||||
File.WriteAllBytes(file + "_" + num + "_" + num2 + ".dat", data);
|
||||
@@ -58,29 +67,42 @@ namespace KKdMainLib
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
{
|
||||
Success = false;
|
||||
MsgPack msgPack = file.ReadMP(JSON);
|
||||
bool compact = msgPack.ReadBoolean("Compact");
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
bool compact = MsgPack.ReadBoolean("Compact");
|
||||
|
||||
if (file.Contains("PvList") && msgPack.Element<MsgPack>("PvList", out MsgPack PvList))
|
||||
if (file.Contains("psrData") && MsgPack.ElementArray("psrData", out MsgPack psrData))
|
||||
{
|
||||
psrDat = new psrData[psrData.Array.Length];
|
||||
for (i = 0; i < psrDat.Length; i++)
|
||||
psrDat[i].SetValue(psrData[i]);
|
||||
Success = true;
|
||||
}
|
||||
else if (file.Contains("PvList") && MsgPack.ElementArray("PvList", out MsgPack PvList))
|
||||
{
|
||||
pvList = new PvList[PvList.Array.Length];
|
||||
for (i = 0; i < pvList.Length; i++)
|
||||
pvList[i].SetValue((MsgPack)PvList[i], compact);
|
||||
pvList[i].SetValue(PvList[i], compact);
|
||||
Success = true;
|
||||
}
|
||||
msgPack = null;
|
||||
MsgPack = MsgPack.New;
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON, bool Compact = true)
|
||||
{
|
||||
if (!Success) return;
|
||||
MsgPack msgPack = new MsgPack();
|
||||
MsgPack msgPack = MsgPack.New;
|
||||
|
||||
if (file.Contains("PvList"))
|
||||
if (file.Contains("psrData"))
|
||||
{
|
||||
MsgPack psrData = new MsgPack(psrDat.Length, "psrData");
|
||||
for (i = 0; i < psrDat.Length; i++) psrData[i] = psrDat[i].WriteMP();
|
||||
msgPack.Add(psrData);
|
||||
}
|
||||
else if (file.Contains("PvList"))
|
||||
{
|
||||
if (Compact) msgPack.Add("Compact", Compact);
|
||||
|
||||
MsgPack PvList = new MsgPack("PvList", pvList.Length);
|
||||
MsgPack PvList = new MsgPack(pvList.Length, "PvList");
|
||||
for (i = 0; i < pvList.Length; i++) PvList[i] = pvList[i].WriteMP(Compact);
|
||||
msgPack.Add(PvList);
|
||||
}
|
||||
@@ -90,9 +112,102 @@ namespace KKdMainLib
|
||||
public static string UrlEncode(string value) =>
|
||||
WebUtility.UrlEncode(value).Replace("+", "%20");
|
||||
|
||||
|
||||
public struct psrData
|
||||
{
|
||||
public Player p1;
|
||||
public Player p2;
|
||||
public Player p3;
|
||||
public int PV_ID;
|
||||
|
||||
public void SetValue(string[] data, int i = 0)
|
||||
{
|
||||
p1.SetValue(data, i, 0);
|
||||
p2.SetValue(data, i, 1);
|
||||
p3.SetValue(data, i, 2);
|
||||
PV_ID = int.Parse(data[i * 13 + 12]);
|
||||
}
|
||||
|
||||
public void SetValue(MsgPack msg)
|
||||
{
|
||||
int? ID = msg.ReadNInt32("PV_ID");
|
||||
if (ID != null) PV_ID = (int)ID;
|
||||
else { ID = msg.ReadNInt32("ID"); if (ID != null) PV_ID = (int)ID; }
|
||||
if (msg.Element("P1", out MsgPack P1)) p1.SetValue(P1);
|
||||
if (msg.Element("P2", out MsgPack P2)) p2.SetValue(P2);
|
||||
if (msg.Element("P3", out MsgPack P3)) p3.SetValue(P3);
|
||||
}
|
||||
|
||||
public MsgPack WriteMP() =>
|
||||
MsgPack.New.Add("PV_ID", PV_ID).Add(p1.WriteMP("P1"))
|
||||
.Add(p2.WriteMP("P2")).Add(p3.WriteMP("P3"));
|
||||
|
||||
public override string ToString() =>
|
||||
UrlEncode(p1.ToString() + "," + p2.ToString() + "," + p3.ToString() + "," + PV_ID);
|
||||
}
|
||||
|
||||
public struct Player
|
||||
{
|
||||
public int Score0;
|
||||
public int Score1;
|
||||
public string Name0;
|
||||
public string Name1;
|
||||
public Difficulty Diff;
|
||||
public bool Has2P => Name1 != null;
|
||||
|
||||
public void SetValue(string[] data, int i = 0, int offset = 0)
|
||||
{
|
||||
string[] array = data[i * 13 + offset * 4].Split('.');
|
||||
Score0 = int.Parse(array[0]);
|
||||
if (array.Length > 1) Score1 = int.Parse(array[1]);
|
||||
string text = "";
|
||||
for (int j = 0; j < data[i * 13 + 1 + offset * 4].Length; j++)
|
||||
{
|
||||
text += data[i * 13 + 1 + offset * 4][j].ToString();
|
||||
if (text.EndsWith("xxx"))
|
||||
{
|
||||
Name0 = text.Remove(text.Length - 3);
|
||||
text = "";
|
||||
}
|
||||
}
|
||||
if (array.Length == 1) Name0 = text;
|
||||
else Name1 = text;
|
||||
if (int.TryParse(data[i * 13 + 2 + offset * 4], out int Diff))
|
||||
this.Diff = (Difficulty)Diff;
|
||||
else
|
||||
Enum.TryParse(data[i * 13 + 2 + offset * 4], out this.Diff);
|
||||
}
|
||||
|
||||
public void SetValue(MsgPack msg)
|
||||
{
|
||||
Diff = (Difficulty)msg.ReadInt32("Diff");
|
||||
Score0 = msg.ReadInt32 ("Score");
|
||||
Name0 = msg.ReadString( "Name");
|
||||
if (Name0 == null)
|
||||
{
|
||||
Score0 = msg.ReadInt32 ("Score0");
|
||||
Score1 = msg.ReadInt32 ("Score1");
|
||||
Name0 = msg.ReadString( "Name0");
|
||||
Name1 = msg.ReadString( "Name1");
|
||||
}
|
||||
else Name1 = null;
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(string name) =>
|
||||
Has2P ? new MsgPack(name).Add("Diff", (int)Diff).Add("Score0", Score0)
|
||||
.Add("Score1", Score1).Add("Name0", Name0).Add("Name1", Name1) :
|
||||
new MsgPack(name).Add("Diff", (int)Diff)
|
||||
.Add("Score" , Score0).Add("Name" , Name0);
|
||||
|
||||
public override string ToString() =>
|
||||
(Score0 + (Has2P ? ("." + Score1) : "") + "," + UrlEncode(Name0) +
|
||||
(Has2P ? ("xxx" + UrlEncode(Name1)) : "") + "," +
|
||||
Diff + "," + (Has2P ? "0.1" : "0")).Replace("*", "%2A");
|
||||
}
|
||||
|
||||
public struct PvList
|
||||
{
|
||||
public int ID;
|
||||
public int PV_ID;
|
||||
public bool Enable;
|
||||
public bool Extra;
|
||||
public Date AdvDemoStart;
|
||||
@@ -102,9 +217,9 @@ namespace KKdMainLib
|
||||
|
||||
public void SetValue(string[] data, int i = 0)
|
||||
{
|
||||
ID = int.Parse(data[i * 7]);
|
||||
PV_ID = int.Parse(data[i * 7]);
|
||||
Enable = int.Parse(data[i * 7 + 1]) == 1;
|
||||
Extra = int.Parse(data[i * 7 + 2]) == 1;
|
||||
Extra = int.Parse(data[i * 7 + 2]) == 1;
|
||||
AdvDemoStart.SetValue(data[i * 7 + 3]);
|
||||
AdvDemoEnd .SetValue(data[i * 7 + 4]);
|
||||
StartShow .SetValue(data[i * 7 + 5]);
|
||||
@@ -113,15 +228,17 @@ namespace KKdMainLib
|
||||
|
||||
public void SetValue(MsgPack msg, bool Compact)
|
||||
{
|
||||
MsgPack Temp = new MsgPack();
|
||||
MsgPack Temp = MsgPack.New;
|
||||
this.Enable = true;
|
||||
this.Extra = false;
|
||||
|
||||
ID = msg.ReadInt32("ID");
|
||||
int? ID = msg.ReadNInt32("PV_ID");
|
||||
if (ID != null) PV_ID = (int)ID;
|
||||
else { ID = msg.ReadNInt32("ID"); if (ID != null) PV_ID = (int)ID; }
|
||||
bool? Enable = msg.ReadNBoolean("Enable");
|
||||
bool? Extra = msg.ReadNBoolean("Extra");
|
||||
if (Enable.HasValue) this.Enable = (bool)Enable;
|
||||
if (Extra .HasValue) 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);
|
||||
@@ -138,8 +255,8 @@ namespace KKdMainLib
|
||||
|
||||
public MsgPack WriteMP(bool Compact)
|
||||
{
|
||||
MsgPack msgPack = new MsgPack();
|
||||
msgPack.Add("ID", ID);
|
||||
MsgPack msgPack = MsgPack.New;
|
||||
msgPack.Add("PV_ID", PV_ID);
|
||||
if (!Enable) msgPack.Add("Enable", Enable);
|
||||
if ( Extra ) msgPack.Add("Extra" , Extra );
|
||||
if (Compact)
|
||||
@@ -160,7 +277,7 @@ namespace KKdMainLib
|
||||
}
|
||||
|
||||
public override string ToString() =>
|
||||
UrlEncode(ID + "," + (Enable ? 1 : 0) + "," + (Extra ? 1 : 0) + "," +
|
||||
UrlEncode(PV_ID + "," + (Enable ? 1 : 0) + "," + (Extra ? 1 : 0) + "," +
|
||||
AdvDemoStart.ToString() + "," + AdvDemoEnd.ToString() + "," +
|
||||
StartShow.ToString() + "," + EndShow.ToString());
|
||||
}
|
||||
@@ -244,5 +361,13 @@ namespace KKdMainLib
|
||||
public override string ToString() =>
|
||||
Year.ToString("d4") + "-" + Month.ToString("d2") + "-" + Day.ToString("d2");
|
||||
}
|
||||
|
||||
public enum Difficulty
|
||||
{
|
||||
Easy = 0,
|
||||
Normal = 1,
|
||||
Hard = 2,
|
||||
Extreme = 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+173
-186
@@ -10,12 +10,18 @@ namespace KKdMainLib
|
||||
{
|
||||
public class FARC
|
||||
{
|
||||
public FARC() { Files = new FARCFile[0]; Signature = Farc.FArC; FT = false; }
|
||||
public FARC() => NewFARC();
|
||||
public FARC(string File, bool IsDirectory = false)
|
||||
{ if (IsDirectory) DirectoryPath = File; else FilePath = File; NewFARC(); }
|
||||
|
||||
public FARCFile[] Files = new FARCFile[0];
|
||||
private void NewFARC() { Files = null; Signature = Farc.FArC; CBC = FT = false; }
|
||||
|
||||
public FARCFile[] Files = null;
|
||||
public Type FARCType;
|
||||
public Farc Signature = Farc.FArC;
|
||||
public string FilePath, DirectoryPath;
|
||||
|
||||
private bool FT = false;
|
||||
private bool CBC, FT;
|
||||
|
||||
private readonly byte[] Key = Text.ToASCII("project_diva.bin");
|
||||
|
||||
@@ -29,141 +35,147 @@ namespace KKdMainLib
|
||||
Padding = PaddingMode.Zeros, IV = iv ?? new byte[16] };
|
||||
return AesManaged;
|
||||
}
|
||||
|
||||
public void UnPack(string file, bool SaveToDisk = true)
|
||||
|
||||
public void UnPack(bool SaveToDisk = true)
|
||||
{
|
||||
Files = null;
|
||||
Signature = Farc.FArC;
|
||||
FT = false;
|
||||
Console.Title = "FARC Extractor - Archive: " + Path.GetFileName(file);
|
||||
if (!File.Exists(file))
|
||||
{
|
||||
Console.WriteLine("File {0} doesn't exist.", Path.GetFileName(file));
|
||||
Console.Clear();
|
||||
return;
|
||||
}
|
||||
HeaderReader().FileReader();
|
||||
if (SaveToDisk) this.SaveToDisk();
|
||||
}
|
||||
|
||||
Stream reader = File.OpenReader(file);
|
||||
string directory = Path.GetFullPath(file).Replace(Path.GetExtension(file), "");
|
||||
private FARC HeaderReader()
|
||||
{
|
||||
NewFARC();
|
||||
Console.Title = "FARC Extractor - Archive: " + Path.GetFileName(FilePath);
|
||||
if (!File.Exists(FilePath))
|
||||
{ Console.WriteLine("File {0} doesn't exist.", Path.GetFileName(FilePath)); return this; }
|
||||
|
||||
Stream reader = File.OpenReader(FilePath);
|
||||
DirectoryPath = Path.GetFullPath(FilePath).Replace(Path.GetExtension(FilePath), "");
|
||||
Signature = (Farc)reader.ReadInt32Endian(true);
|
||||
if (Signature != Farc.FArc && Signature != Farc.FArC && Signature != Farc.FARC)
|
||||
{ Console.WriteLine("Unknown signature"); reader.Close(); return this; }
|
||||
|
||||
int HeaderLength = reader.ReadInt32Endian(true);
|
||||
if (Signature == Farc.FARC)
|
||||
{
|
||||
Console.WriteLine("Unknown signature"); reader.Close();
|
||||
Console.Clear();
|
||||
return;
|
||||
FARCType = (Type)reader.ReadInt32Endian(true);
|
||||
reader.ReadInt32();
|
||||
|
||||
int FARCMode = reader.ReadInt32Endian(true);
|
||||
FT = FARCMode == 0x10;
|
||||
CBC = FARCMode != 0x10 && FARCMode != 0x40;
|
||||
|
||||
if (CBC && FARCType.HasFlag(Type.ECB))
|
||||
{
|
||||
reader.Close();
|
||||
byte[] Header = new byte[HeaderLength - 0x08];
|
||||
MSIO.FileStream stream = new MSIO.FileStream(FilePath, MSIO.FileMode.Open,
|
||||
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite) { Position = 0x10 };
|
||||
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Header, 0x00, HeaderLength - 0x08);
|
||||
Header = SkipData(Header, 0x10);
|
||||
reader = File.OpenReader(Header);
|
||||
|
||||
FARCMode = reader.ReadInt32Endian(true);
|
||||
FT = FARCMode == 0x10;
|
||||
}
|
||||
}
|
||||
|
||||
MSIO.Directory.CreateDirectory(directory);
|
||||
int HeaderLength = reader.ReadInt32Endian(true);
|
||||
if (Signature == Farc.FARC)
|
||||
if (reader.ReadInt32Endian(true) == 1)
|
||||
Files = new FARCFile[reader.ReadInt32Endian(true)];
|
||||
reader.ReadInt32();
|
||||
|
||||
if (Files == null)
|
||||
{
|
||||
int Count = 0;
|
||||
long Position = reader.LongPosition;
|
||||
while (reader.LongPosition < HeaderLength)
|
||||
{
|
||||
reader.NullTerminated();
|
||||
reader.ReadInt32();
|
||||
if (Signature != Farc.FArc ) reader.ReadInt32();
|
||||
reader.ReadInt32();
|
||||
if (Signature == Farc.FARC && FT) reader.ReadInt32();
|
||||
Count++;
|
||||
}
|
||||
reader.LongPosition = Position;
|
||||
Files = new FARCFile[Count];
|
||||
}
|
||||
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
Files[i].Name = reader.NullTerminatedUTF8();
|
||||
Files[i].Offset = reader.ReadInt32Endian(true);
|
||||
if (Signature != Farc.FArc) Files[i].SizeComp = reader.ReadInt32Endian(true);
|
||||
Files[i].SizeUnc = reader.ReadInt32Endian(true);
|
||||
if (Signature == Farc.FARC && FT)
|
||||
Files[i].Type = (Type)reader.ReadInt32Endian(true);
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
return this;
|
||||
}
|
||||
|
||||
private FARC FileReader()
|
||||
{
|
||||
if (Files == null) return this;
|
||||
if (Files.Length < 1) return this;
|
||||
if (Signature != Farc.FARC)
|
||||
{
|
||||
reader.ReadUInt32();
|
||||
HeaderReader(HeaderLength, ref Files, ref reader);
|
||||
reader.Close();
|
||||
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
if (Signature == Farc.FArC)
|
||||
using (MSIO.MemoryStream memorystream = new MSIO.MemoryStream(
|
||||
File.ReadAllBytes(file, Files[i].SizeComp, Files[i].Offset)))
|
||||
File.ReadAllBytes(FilePath, Files[i].SizeComp, Files[i].Offset)))
|
||||
{
|
||||
GZipStream gZipStream = new GZipStream(memorystream, CompressionMode.Decompress);
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
}
|
||||
else
|
||||
Files[i].Data = File.ReadAllBytes(file, Files[i].SizeUnc, Files[i].Offset);
|
||||
|
||||
if (SaveToDisk)
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(directory, Files[i].Name), Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
}
|
||||
}
|
||||
Console.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
int Mode = reader.ReadInt32Endian(true);
|
||||
reader.ReadUInt32();
|
||||
bool GZip = (Mode & 2) == 2;
|
||||
bool ECB = (Mode & 4) == 4;
|
||||
|
||||
int FARCType = reader.ReadInt32Endian(true);
|
||||
FT = FARCType == 0x10;
|
||||
bool CBC = !FT && FARCType != 0x40;
|
||||
if (ECB && CBC)
|
||||
{
|
||||
byte[] Header = new byte[HeaderLength - 0x08];
|
||||
FT = true;
|
||||
reader.Close();
|
||||
MSIO.FileStream stream = new MSIO.FileStream(file, MSIO.FileMode.Open,
|
||||
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite);
|
||||
stream.Seek(0x10, 0);
|
||||
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Header, 0x00, HeaderLength - 0x08);
|
||||
Header = SkipData(Header, 0x10);
|
||||
Stream CBCreader = new Stream(new MSIO.MemoryStream(Header));
|
||||
CBCreader.BaseStream.Seek(0, 0);
|
||||
|
||||
FARCType = CBCreader.ReadInt32Endian(true);
|
||||
FT = FARCType == 0x10;
|
||||
if (CBCreader.ReadInt32Endian(true) == 1)
|
||||
Files = new FARCFile[CBCreader.ReadInt32Endian(true)];
|
||||
CBCreader.ReadUInt32();
|
||||
HeaderReader(HeaderLength, ref Files, ref CBCreader);
|
||||
CBCreader.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (reader.ReadInt32Endian(true) == 1)
|
||||
Files = new FARCFile[reader.ReadInt32Endian(true)];
|
||||
reader.ReadUInt32();
|
||||
HeaderReader(HeaderLength, ref Files, ref reader);
|
||||
reader.Close();
|
||||
else Files[i].Data = File.ReadAllBytes(FilePath, Files[i].SizeUnc, Files[i].Offset);
|
||||
return this;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
int FileSize = ECB || Files[i].ECB ? Files[i].SizeComp.Align(0x10) : Files[i].SizeComp;
|
||||
MSIO.FileStream stream = new MSIO.FileStream(file, MSIO.FileMode.Open,
|
||||
int FileSize = FARCType.HasFlag(Type.ECB) || Files[i].Type.HasFlag(Type.ECB) ?
|
||||
Files[i].SizeComp.Align(0x10) : Files[i].SizeComp;
|
||||
MSIO.FileStream stream = new MSIO.FileStream(FilePath, MSIO.FileMode.Open,
|
||||
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite);
|
||||
stream.Seek(Files[i].Offset, 0);
|
||||
Files[i].Data = new byte[FileSize];
|
||||
|
||||
bool Encrypted = false;
|
||||
if (ECB)
|
||||
if (FARCType.HasFlag(Type.ECB))
|
||||
{
|
||||
if ((FT && Files[i].ECB) || CBC)
|
||||
if ((FT && Files[i].Type.HasFlag(Type.ECB)) || CBC)
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Files[i].Data, 0, FileSize);
|
||||
Files[i].Data = SkipData(Files[i].Data, 0x10);
|
||||
}
|
||||
else
|
||||
else if (Files[i].Type.HasFlag(Type.ECB))
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(false, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Files[i].Data, 0, FileSize);
|
||||
else stream.Read(Files[i].Data, 0, FileSize);
|
||||
Encrypted = true;
|
||||
}
|
||||
|
||||
bool Compressed = false;
|
||||
bool LocalGZip = (FT && Files[i].GZip) || GZip && Files[i].SizeUnc != 0;
|
||||
if (LocalGZip)
|
||||
if (((FT && Files[i].Type.HasFlag(Type.GZip)) ||
|
||||
FARCType.HasFlag(Type.GZip)) && Files[i].SizeUnc > 0)
|
||||
{
|
||||
GZipStream gZipStream;
|
||||
if (Encrypted)
|
||||
{
|
||||
gZipStream = new GZipStream(new MSIO.MemoryStream(
|
||||
Files[i].Data), CompressionMode.Decompress);
|
||||
stream.Close();
|
||||
}
|
||||
if (Encrypted) { gZipStream = new GZipStream(new MSIO.MemoryStream(Files[i].Data),
|
||||
CompressionMode.Decompress); stream.Close(); }
|
||||
else gZipStream = new GZipStream(stream, CompressionMode.Decompress);
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
byte[] Temp = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Temp, 0, Files[i].SizeUnc);
|
||||
Files[i].Data = Temp;
|
||||
|
||||
Compressed = true;
|
||||
}
|
||||
@@ -174,64 +186,33 @@ namespace KKdMainLib
|
||||
stream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
if (SaveToDisk)
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(directory, Files[i].Name), Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
}
|
||||
|
||||
}
|
||||
Console.Clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
byte[] SkipData(byte[] Data, int Skip)
|
||||
private void SaveToDisk()
|
||||
{
|
||||
if (DirectoryPath == null || Files == null) return;
|
||||
if (DirectoryPath == "" || Files.Length < 1) return;
|
||||
MSIO.Directory.CreateDirectory(DirectoryPath);
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(DirectoryPath, Files[i].Name), Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] SkipData(byte[] Data, int Skip)
|
||||
{
|
||||
byte[] SkipData = new byte[Data.Length - Skip];
|
||||
for (int i = 0; i < Data.Length - Skip; i++) SkipData[i] = Data[i + Skip];
|
||||
return SkipData;
|
||||
}
|
||||
|
||||
void HeaderReader(int HeaderLenght, ref FARCFile[] Files, ref Stream reader)
|
||||
public void Pack()
|
||||
{
|
||||
if (Files == null)
|
||||
{
|
||||
int Count = 0;
|
||||
long Position = reader.BaseStream.Position;
|
||||
while (reader.BaseStream.Position < HeaderLenght)
|
||||
{
|
||||
reader.NullTerminated();
|
||||
reader.ReadInt32();
|
||||
if (Signature != Farc.FArc ) reader.ReadInt32();
|
||||
reader.ReadInt32();
|
||||
if (Signature == Farc.FARC && FT) reader.ReadInt32();
|
||||
Count++;
|
||||
}
|
||||
reader.Seek(Position, 0);
|
||||
Files = new FARCFile[Count];
|
||||
}
|
||||
|
||||
int LocalMode = 0;
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
Files[i].Name = reader.NullTerminatedUTF8();
|
||||
Files[i].Offset = reader.ReadInt32Endian(true);
|
||||
if (Signature != Farc.FArc) Files[i].SizeComp = reader.ReadInt32Endian(true);
|
||||
Files[i].SizeUnc = reader.ReadInt32Endian(true);
|
||||
if (Signature == Farc.FARC && FT)
|
||||
{
|
||||
LocalMode = reader.ReadInt32Endian(true);
|
||||
Files[i].GZip = (LocalMode & 2) == 2;
|
||||
Files[i].ECB = (LocalMode & 4) == 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Pack(string file)
|
||||
{
|
||||
Files = null;
|
||||
FT = false;
|
||||
string[] files = Directory.GetFiles(file);
|
||||
NewFARC();
|
||||
string[] files = Directory.GetFiles(DirectoryPath);
|
||||
Files = new FARCFile[files.Length];
|
||||
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
@@ -242,19 +223,18 @@ namespace KKdMainLib
|
||||
}
|
||||
files = null;
|
||||
|
||||
Stream writer = File.OpenWriter(file + ".farc", true);
|
||||
Stream writer = File.OpenWriter(DirectoryPath + ".farc", true);
|
||||
writer.WriteEndian((int)Signature, true);
|
||||
|
||||
Stream HeaderWriter = File.OpenWriter();
|
||||
for (int i = 0; i < 3; i++) HeaderWriter.WriteByte(0x00);
|
||||
if (Signature == Farc.FArc) HeaderWriter.WriteByte(0x20);
|
||||
else if (Signature == Farc.FArC) HeaderWriter.WriteByte(0x10);
|
||||
if (Signature == Farc.FArc) HeaderWriter.WriteEndian(0x20, true);
|
||||
else if (Signature == Farc.FArC) HeaderWriter.WriteEndian(0x10, true);
|
||||
else if (Signature == Farc.FARC)
|
||||
{
|
||||
HeaderWriter.WriteByte(0x06);
|
||||
for (int i = 0; i < 7; i++) HeaderWriter.WriteByte(0x00);
|
||||
HeaderWriter.WriteByte(0x40);
|
||||
for (int i = 0; i < 8; i++) HeaderWriter.WriteByte(0x00);
|
||||
HeaderWriter.WriteEndian((int)FARCType, true);
|
||||
HeaderWriter.Write (0x00);
|
||||
HeaderWriter.WriteEndian(0x40 , true);
|
||||
HeaderWriter.Write (0x00);
|
||||
}
|
||||
int HeaderPartLength = Signature == Farc.FArc ? 0x09 : 0x0D;
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
@@ -271,8 +251,8 @@ namespace KKdMainLib
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
CompressStuff(i, ref Files, ref writer);
|
||||
|
||||
if (Signature == Farc.FARC) writer.Seek(0x1C, 0);
|
||||
else writer.Seek(0x0C, 0);
|
||||
if (Signature == Farc.FARC) writer.Position = 0x1C;
|
||||
else writer.Position = 0x0C;
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
writer.Write(Path.GetFileName(Files[i].Name) + "\0");
|
||||
@@ -284,35 +264,34 @@ namespace KKdMainLib
|
||||
writer.Close();
|
||||
}
|
||||
|
||||
void CompressStuff(int i, ref FARCFile[] Files, ref Stream writer)
|
||||
private void CompressStuff(int i, ref FARCFile[] Files, ref Stream writer)
|
||||
{
|
||||
Files[i].Offset = writer.Position;
|
||||
Files[i].Data = File.ReadAllBytes(Files[i].Name);
|
||||
Files[i].SizeUnc = Files[i].Data.Length;
|
||||
Files[i].Type = Type.None;
|
||||
|
||||
if (Signature != Farc.FArc)
|
||||
if (Signature == Farc.FArC || (Signature == Farc.FARC && FARCType.HasFlag(Type.GZip)))
|
||||
{
|
||||
if (Signature != Farc.FArc)
|
||||
{
|
||||
MSIO.MemoryStream stream = new MSIO.MemoryStream();
|
||||
using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Compress))
|
||||
gZipStream.Write(Files[i].Data, 0, Files[i].Data.Length);
|
||||
Files[i].Data = stream.ToArray();
|
||||
stream.Dispose();
|
||||
Files[i].SizeComp = Files[i].Data.Length;
|
||||
}
|
||||
else if (Signature == Farc.FARC)
|
||||
{
|
||||
int AlignData = Files[i].Data.Length.Align(0x40);
|
||||
byte[] Data = new byte[AlignData];
|
||||
for (int i1 = 0; i1 < Files[i].Data.Length; i1++)
|
||||
Data[i1] = Files[i].Data[i1];
|
||||
for (int i1 = Files[i].Data.Length; i1 < AlignData; i1++)
|
||||
Data[i1] = 0x78;
|
||||
|
||||
Files[i].Data = Encrypt(Data, false);
|
||||
}
|
||||
Files[i].Type |= Type.GZip;
|
||||
MSIO.MemoryStream stream = new MSIO.MemoryStream();
|
||||
using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Compress))
|
||||
gZipStream.Write(Files[i].Data, 0, Files[i].Data.Length);
|
||||
Files[i].Data = stream.ToArray();
|
||||
stream.Dispose();
|
||||
Files[i].SizeComp = Files[i].Data.Length;
|
||||
}
|
||||
|
||||
if (Signature == Farc.FARC && FARCType.HasFlag(Type.ECB))
|
||||
{
|
||||
int AlignData = Files[i].Data.Length.Align(0x40);
|
||||
byte[] Data = new byte[AlignData];
|
||||
for (int i1 = 0; i1 < AlignData ; i1++) Data[i1] = 0x78;
|
||||
for (int i1 = 0; i1 < Files[i].Data.Length; i1++) Data[i1] = Files[i].Data[i1];
|
||||
|
||||
Files[i].Data = Encrypt(Data, false);
|
||||
}
|
||||
|
||||
writer.Write(Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
|
||||
@@ -325,31 +304,39 @@ namespace KKdMainLib
|
||||
}
|
||||
}
|
||||
|
||||
byte[] Encrypt(byte[] Data, bool isFT)
|
||||
private byte[] Encrypt(byte[] Data, bool isFT)
|
||||
{
|
||||
MSIO.MemoryStream stream = new MSIO.MemoryStream();
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(isFT, null).CreateEncryptor(),CryptoStreamMode.Write))
|
||||
GetAes(isFT, null).CreateEncryptor(), CryptoStreamMode.Write))
|
||||
cryptoStream.Write(Data, 0, Data.Length);
|
||||
return stream.ToArray();
|
||||
}
|
||||
|
||||
public enum Farc
|
||||
{
|
||||
FArc = 0x46417263,
|
||||
FArC = 0x46417243,
|
||||
FARC = 0x46415243,
|
||||
}
|
||||
|
||||
public struct FARCFile
|
||||
{
|
||||
public int Offset;
|
||||
public int SizeComp;
|
||||
public int SizeUnc;
|
||||
public bool GZip;
|
||||
public bool ECB;
|
||||
public Type Type;
|
||||
public byte[] Data;
|
||||
public string Name;
|
||||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
public enum Farc : int
|
||||
{
|
||||
FArc = 0x46417263,
|
||||
FArC = 0x46417243,
|
||||
FARC = 0x46415243,
|
||||
}
|
||||
|
||||
public enum Type : int
|
||||
{
|
||||
None = 0b000,
|
||||
GZip = 0b010,
|
||||
ECB = 0b100,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,10 +24,9 @@ namespace KKdMainLib.IO
|
||||
stream.LongPosition = LongPosition; return val; }
|
||||
public static Stream SkipWhitespace(this Stream stream)
|
||||
{
|
||||
long LongPosition = stream.LongPosition;
|
||||
while (true)
|
||||
if (char.IsWhiteSpace(stream.ReadCharUTF8())) LongPosition = stream.LongPosition;
|
||||
else { stream.LongPosition = LongPosition; break; }
|
||||
if (char.IsWhiteSpace(stream.PeekCharUTF8())) stream.ReadCharUTF8();
|
||||
else break;
|
||||
return stream;
|
||||
}
|
||||
public static bool Assert(this Stream stream, char next)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using MSIO = System.IO;
|
||||
using MSIO = System.IO;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
@@ -21,5 +20,7 @@ namespace KKdMainLib.IO
|
||||
MSIO.Path.Combine(path1, path2, path3, path4);
|
||||
public static string Combine(params string[] paths) =>
|
||||
MSIO.Path.Combine(paths);
|
||||
public static string GetDirectoryName(string path) =>
|
||||
MSIO.Path.GetDirectoryName(path);
|
||||
}
|
||||
}
|
||||
|
||||
+22
-11
@@ -176,17 +176,28 @@ namespace KKdMainLib.IO
|
||||
public void Write( float? val) => Write(val.GetValueOrDefault());
|
||||
public void Write(double? val) => Write(val.GetValueOrDefault());
|
||||
|
||||
public void Write( bool* val, int Length) { for (i = 0; i < Length; i++) stream.WriteByte((byte)(val[i] ? 1 : 0)); }
|
||||
public void Write( sbyte* val, int Length) { for (i = 0; i < Length; i++) stream.WriteByte((byte) val[i]); }
|
||||
public void Write( byte* val, int Length) { for (i = 0; i < Length; i++) stream.WriteByte( val[i]); }
|
||||
public void Write( short* val, int Length) { for (i = 0; i < Length; i++) ToArray(2, val[i]); }
|
||||
public void Write(ushort* val, int Length) { for (i = 0; i < Length; i++) ToArray(2, val[i]); }
|
||||
public void Write( int* val, int Length) { for (i = 0; i < Length; i++) ToArray(4, val[i]); }
|
||||
public void Write( uint* val, int Length) { for (i = 0; i < Length; i++) ToArray(4, val[i]); }
|
||||
public void Write( long* val, int Length) { for (i = 0; i < Length; i++) ToArray(8, val[i]); }
|
||||
public void Write( ulong* val, int Length) { for (i = 0; i < Length; i++) ToArray(8, val[i]); }
|
||||
public void Write( float* val, int Length) { for (i = 0; i < Length; i++) ToArray(4, *( uint*)&val[i]); }
|
||||
public void Write(double* val, int Length) { for (i = 0; i < Length; i++) ToArray(4, *(ulong*)&val[i]); }
|
||||
public void Write( bool* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) stream.WriteByte((byte)(val[i] ? 1 : 0)); }
|
||||
public void Write( sbyte* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) stream.WriteByte((byte) val[i]); }
|
||||
public void Write( byte* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) stream.WriteByte( val[i]); }
|
||||
public void Write( short* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(2, val[i]); }
|
||||
public void Write(ushort* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(2, val[i]); }
|
||||
public void Write( int* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, val[i]); }
|
||||
public void Write( uint* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, val[i]); }
|
||||
public void Write( long* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(8, val[i]); }
|
||||
public void Write( ulong* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(8, val[i]); }
|
||||
public void Write( float* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, *( uint*)&val[i]); }
|
||||
public void Write(double* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, *(ulong*)&val[i]); }
|
||||
|
||||
public void WriteEndian( short* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(2, Endian(val[i], 2, IsBE)); }
|
||||
|
||||
@@ -52,8 +52,10 @@
|
||||
<Compile Include="MessagePack\MsgPack.cs" />
|
||||
<Compile Include="MessagePack\IO.cs" />
|
||||
<Compile Include="Types\Half.cs" />
|
||||
<Compile Include="Types\Vector2.cs" />
|
||||
<Compile Include="Types\Vector3.cs" />
|
||||
<Compile Include="Types\IKeyFrame.cs" />
|
||||
<Compile Include="Types\KKdList.cs" />
|
||||
<Compile Include="Types\Pointer.cs" />
|
||||
<Compile Include="Types\Vector.cs" />
|
||||
<Compile Include="DataBank.cs" />
|
||||
<Compile Include="DCC.cs" />
|
||||
<Compile Include="DEX.cs" />
|
||||
|
||||
+17
-9
@@ -3,6 +3,7 @@ using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
@@ -76,9 +77,8 @@ namespace KKdMainLib
|
||||
FileNames = new string[0];
|
||||
if (code == 1)
|
||||
{
|
||||
Console.WriteLine("Choose file(s) to open:");
|
||||
OpenFileDialog ofd = new OpenFileDialog { InitialDirectory =
|
||||
Application.StartupPath, Multiselect = true };
|
||||
OpenFileDialog ofd = new OpenFileDialog { InitialDirectory = Application.StartupPath,
|
||||
Multiselect = true, Title = "Choose file(s) to open:" };
|
||||
|
||||
if (filetype == "a3da") ofd.Filter = GetArgs("A3DA", "a3da", "json", "mp") +
|
||||
GetArgs("A3DA", true, "a3da") + JSON + MsgPack;
|
||||
@@ -99,6 +99,7 @@ namespace KKdMainLib
|
||||
GetArgs("DDS", true, "dds") + GetArgs("PNG", true, "png");
|
||||
else if (filetype == "json") ofd.Filter = "JSON (*.json)|*.json";
|
||||
else if (filetype == "kki" ) ofd.Filter = GetArgs("KKI", "kki");
|
||||
else if (filetype == "mp" ) ofd.Filter = GetArgs("MessagePack", "mp");
|
||||
else if (filetype == "ppd" ) ofd.Filter = GetArgs("PPD", "ppd", "pak", "mod") +
|
||||
GetArgs("PPD", true, "ppd") + GetArgs("PAK", true, "pak") + GetArgs("MOD", true, "mod");
|
||||
else if (filetype == "str" ) ofd.Filter = GetArgs("STR", "str", "bin", "json", "mp") +
|
||||
@@ -112,11 +113,11 @@ namespace KKdMainLib
|
||||
}
|
||||
else if (code == 2)
|
||||
{
|
||||
FolderBrowserDialog fbd = new FolderBrowserDialog();
|
||||
Console.WriteLine("Choose folder:");
|
||||
fbd.SelectedPath = Application.StartupPath;
|
||||
if (fbd.ShowDialog() == DialogResult.OK)
|
||||
return fbd.SelectedPath.ToString();
|
||||
OpenFileDialog ofd = new OpenFileDialog { InitialDirectory = Application.StartupPath,
|
||||
ValidateNames = false, CheckFileExists = false, Filter = " | ", CheckPathExists = true,
|
||||
Title = "Choose any file in folder:", FileName = "Folder Selection." };
|
||||
if (ofd.ShowDialog() == DialogResult.OK)
|
||||
return Path.GetDirectoryName(ofd.FileName);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@@ -299,7 +300,14 @@ namespace KKdMainLib
|
||||
|
||||
private static readonly string NumberDecimalSeparator =
|
||||
NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
|
||||
|
||||
|
||||
public static string ToString(this object d)
|
||||
{
|
||||
if (d == null) return "Null";
|
||||
else if (d is float F32) return ToString(F32);
|
||||
else if (d is double F64) return ToString(F64);
|
||||
return d.ToString();
|
||||
}
|
||||
public static string ToString(this bool? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this bool d) => d.ToString().ToLower();
|
||||
public static string ToString(this sbyte? d) => d.GetValueOrDefault().ToString();
|
||||
|
||||
@@ -160,8 +160,8 @@ namespace KKdMainLib
|
||||
else if (c < 0x00000000) c = 0x00000000;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static double Round(this double c) => Math.Round(c);
|
||||
|
||||
public static double Round(this double c, int d = 0) => Math.Round(c, d);
|
||||
|
||||
public static unsafe sbyte* GetPtr(this sbyte[] array)
|
||||
{ sbyte* Ptr; fixed ( sbyte* tempPtr = array) Ptr = tempPtr; return Ptr; }
|
||||
|
||||
+170
-135
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.Types;
|
||||
|
||||
namespace KKdMainLib.MessagePack
|
||||
{
|
||||
@@ -13,189 +13,178 @@ namespace KKdMainLib.MessagePack
|
||||
|
||||
public void Close() => _IO.Close();
|
||||
|
||||
public MsgPack Read(bool NotArray = true)
|
||||
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
|
||||
|
||||
public MsgPack Read(bool Array = false)
|
||||
{
|
||||
MsgPack MsgPack = new MsgPack();
|
||||
MsgPack MsgPack = MsgPack.New;
|
||||
byte Unk = _IO.ReadByte();
|
||||
MsgPack.Type = (MsgPack.Types)Unk;
|
||||
if (NotArray)
|
||||
Types Type = (Types)Unk;
|
||||
if (!Array)
|
||||
{
|
||||
MsgPack.Name = ReadString(MsgPack.Type);
|
||||
if (MsgPack.Name != null) { Unk = _IO.ReadByte(); MsgPack.Type = (MsgPack.Types)Unk; }
|
||||
MsgPack.Name = ReadString(Type);
|
||||
if (MsgPack.Name != null) { Unk = _IO.ReadByte(); Type = (Types)Unk; }
|
||||
}
|
||||
|
||||
bool FixArr = MsgPack.Type >= MsgPack.Types.FixArr && MsgPack.Type <= MsgPack.Types.FixArrMax;
|
||||
bool FixMap = MsgPack.Type >= MsgPack.Types.FixMap && MsgPack.Type <= MsgPack.Types.FixMapMax;
|
||||
bool FixStr = MsgPack.Type >= MsgPack.Types.FixStr && MsgPack.Type <= MsgPack.Types.FixStrMax;
|
||||
bool PosInt = MsgPack.Type >= MsgPack.Types.PosInt && MsgPack.Type <= MsgPack.Types.PosIntMax;
|
||||
bool NegInt = MsgPack.Type >= MsgPack.Types.NegInt && MsgPack.Type <= MsgPack.Types.NegIntMax;
|
||||
bool FixArr = Type >= Types.FixArr && Type <= Types.FixArrMax;
|
||||
bool FixMap = Type >= Types.FixMap && Type <= Types.FixMapMax;
|
||||
bool FixStr = Type >= Types.FixStr && Type <= Types.FixStrMax;
|
||||
bool PosInt = Type >= Types.PosInt && Type <= Types.PosIntMax;
|
||||
bool NegInt = Type >= Types.NegInt && Type <= Types.NegIntMax;
|
||||
if (FixArr || FixMap || FixStr || PosInt || NegInt)
|
||||
{
|
||||
if (FixArr || FixMap)
|
||||
if (FixMap)
|
||||
{
|
||||
MsgPack.Type = FixMap ? MsgPack.Types.FixMap : MsgPack.Types.FixArr;
|
||||
if (FixMap)
|
||||
{
|
||||
MsgPack.Object = new List<object>();
|
||||
for (int i = 0; i < Unk - (byte)MsgPack.Type; i++)
|
||||
MsgPack.Add(Read());
|
||||
}
|
||||
else
|
||||
{
|
||||
MsgPack.Object = new object[Unk - (byte)MsgPack.Type];
|
||||
for (int i = 0; i < Unk - (byte)MsgPack.Type; i++)
|
||||
MsgPack[i] = Read(false);
|
||||
}
|
||||
MsgPack.Object = KKdList<MsgPack>.New;
|
||||
for (int i = 0; i < Unk - (byte)Types.FixMap; i++) MsgPack.Add( Read(false));
|
||||
}
|
||||
else if (FixStr)
|
||||
{ MsgPack.Object = ReadString(MsgPack.Type); MsgPack.Type = MsgPack.Types.FixStr; }
|
||||
else if (PosInt)
|
||||
{ MsgPack.Object = (ulong) Unk; MsgPack.Type = MsgPack.Types.PosInt; }
|
||||
else if (NegInt)
|
||||
{ MsgPack.Object = ( long)(sbyte)Unk; MsgPack.Type = MsgPack.Types.NegInt; }
|
||||
else if (FixArr)
|
||||
{
|
||||
MsgPack.Object = new MsgPack[Unk - (byte)Types.FixArr];
|
||||
for (int i = 0; i < Unk - (byte)Types.FixArr; i++) MsgPack[i] = Read( true);
|
||||
}
|
||||
else if (FixStr) MsgPack.Object = ReadString( Type);
|
||||
else if (PosInt) MsgPack.Object = Unk;
|
||||
else if (NegInt) MsgPack.Object = (sbyte)Unk;
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (ReadNil (ref MsgPack)) break;
|
||||
if (ReadArr (ref MsgPack)) break;
|
||||
if (ReadMap (ref MsgPack)) break;
|
||||
if (ReadExt (ref MsgPack)) break;
|
||||
if (ReadString (ref MsgPack)) break;
|
||||
if (ReadBoolean(ref MsgPack)) break;
|
||||
if (ReadBytes (ref MsgPack)) break;
|
||||
if (ReadInt (ref MsgPack)) break;
|
||||
if (ReadUInt (ref MsgPack)) break;
|
||||
if (ReadFloat (ref MsgPack)) break;
|
||||
if (ReadNil (ref MsgPack, ref Type)) break;
|
||||
if (ReadArr (ref MsgPack, ref Type)) break;
|
||||
if (ReadMap (ref MsgPack, ref Type)) break;
|
||||
if (ReadExt (ref MsgPack, ref Type)) break;
|
||||
if (ReadString (ref MsgPack, ref Type)) break;
|
||||
if (ReadBoolean(ref MsgPack, ref Type)) break;
|
||||
if (ReadBytes (ref MsgPack, ref Type)) break;
|
||||
if (ReadInt (ref MsgPack, ref Type)) break;
|
||||
if (ReadUInt (ref MsgPack, ref Type)) break;
|
||||
if (ReadFloat (ref MsgPack, ref Type)) break;
|
||||
break;
|
||||
}
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
private bool ReadInt(ref MsgPack MsgPack)
|
||||
private bool ReadInt (ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.Int8 ) MsgPack.Object = (long)_IO.ReadSByte();
|
||||
else if (MsgPack.Type == MsgPack.Types.Int16) MsgPack.Object = (long)_IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Int32) MsgPack.Object = (long)_IO.ReadInt32Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Int64) MsgPack.Object = (long)_IO.ReadInt64Endian(true);
|
||||
if (Type == Types.Int8 ) MsgPack.Object = _IO.ReadSByte();
|
||||
else if (Type == Types.Int16) MsgPack.Object = _IO.ReadInt16Endian(true);
|
||||
else if (Type == Types.Int32) MsgPack.Object = _IO.ReadInt32Endian(true);
|
||||
else if (Type == Types.Int64) MsgPack.Object = _IO.ReadInt64Endian(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadUInt(ref MsgPack MsgPack)
|
||||
private bool ReadUInt (ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.UInt8 ) MsgPack.Object = (ulong)_IO.ReadByte();
|
||||
else if (MsgPack.Type == MsgPack.Types.UInt16) MsgPack.Object = (ulong)_IO.ReadUInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.UInt32) MsgPack.Object = (ulong)_IO.ReadUInt32Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.UInt64) MsgPack.Object = (ulong)_IO.ReadUInt64Endian(true);
|
||||
if (Type == Types.UInt8 ) MsgPack.Object = _IO.ReadByte();
|
||||
else if (Type == Types.UInt16) MsgPack.Object = _IO.ReadUInt16Endian(true);
|
||||
else if (Type == Types.UInt32) MsgPack.Object = _IO.ReadUInt32Endian(true);
|
||||
else if (Type == Types.UInt64) MsgPack.Object = _IO.ReadUInt64Endian(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadFloat(ref MsgPack MsgPack)
|
||||
private bool ReadFloat (ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.Float32) MsgPack.Object = _IO.ReadSingleEndian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Float64) MsgPack.Object = _IO.ReadDoubleEndian(true);
|
||||
if (Type == Types.Float32) MsgPack.Object = _IO.ReadSingleEndian(true);
|
||||
else if (Type == Types.Float64) MsgPack.Object = _IO.ReadDoubleEndian(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadBoolean(ref MsgPack MsgPack)
|
||||
private bool ReadBoolean(ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.False) MsgPack.Object = false;
|
||||
else if (MsgPack.Type == MsgPack.Types.True ) MsgPack.Object = true ;
|
||||
if (Type == Types.False) MsgPack.Object = false;
|
||||
else if (Type == Types.True ) MsgPack.Object = true ;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadBytes(ref MsgPack MsgPack)
|
||||
private bool ReadBytes (ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.Bin8 ) Length = _IO.ReadByte();
|
||||
else if (MsgPack.Type == MsgPack.Types.Bin16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Bin32) Length = _IO.ReadInt32Endian(true);
|
||||
if (Type == Types.Bin8 ) Length = _IO.ReadByte();
|
||||
else if (Type == Types.Bin16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (Type == Types.Bin32) Length = _IO.ReadInt32Endian(true);
|
||||
else return false;
|
||||
MsgPack.Object = _IO.ReadBytes(Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadString(ref MsgPack MsgPack)
|
||||
private bool ReadString (ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
string val = ReadString(MsgPack.Type);
|
||||
string val = ReadString(Type);
|
||||
if (val != null) MsgPack.Object = val;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private string ReadString(MsgPack.Types Val)
|
||||
private string ReadString(Types Val)
|
||||
{
|
||||
if (Val >= MsgPack.Types.FixStr && Val <= MsgPack.Types.FixStrMax)
|
||||
return _IO.ReadString(Val - MsgPack.Types.FixStr);
|
||||
else if (Val >= MsgPack.Types.Str8 && Val <= MsgPack.Types.Str32)
|
||||
if (Val >= Types.FixStr && Val <= Types.FixStrMax)
|
||||
return _IO.ReadString(Val - Types.FixStr);
|
||||
else if (Val >= Types. Str8 && Val <= Types. Str32 )
|
||||
{
|
||||
Enum.TryParse(Val.ToString(), out MsgPack.Types Type);
|
||||
Enum.TryParse(Val.ToString(), out Types Type);
|
||||
int Length = 0;
|
||||
if (Type == MsgPack.Types.Str8 ) Length = _IO.ReadByte();
|
||||
else if (Type == MsgPack.Types.Str16) Length = _IO.ReadInt16Endian(true);
|
||||
if (Type == Types.Str8 ) Length = _IO.ReadByte();
|
||||
else if (Type == Types.Str16) Length = _IO.ReadInt16Endian(true);
|
||||
else Length = _IO.ReadInt32Endian(true);
|
||||
return _IO.ReadString(Length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool ReadNil(ref MsgPack MsgPack)
|
||||
private bool ReadNil(ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.Nil)
|
||||
MsgPack.Object = null;
|
||||
if (Type == Types.Nil) MsgPack.Object = null;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadArr(ref MsgPack MsgPack)
|
||||
private bool ReadArr(ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.Arr16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Arr32) Length = _IO.ReadInt32Endian(true);
|
||||
if (Type == Types.Arr16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (Type == Types.Arr32) Length = _IO.ReadInt32Endian(true);
|
||||
else return false;
|
||||
MsgPack.Object = new object[Length];
|
||||
for (int i = 0; i < Length; i++) MsgPack[i] = Read(false);
|
||||
MsgPack.Object = new MsgPack[Length];
|
||||
for (int i = 0; i < Length; i++) MsgPack[i] = Read(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadMap(ref MsgPack MsgPack)
|
||||
private bool ReadMap(ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.Map16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Map32) Length = _IO.ReadInt32Endian(true);
|
||||
if (Type == Types.Map16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (Type == Types.Map32) Length = _IO.ReadInt32Endian(true);
|
||||
else return false;
|
||||
MsgPack.Object = new List<object>();
|
||||
MsgPack.Object = KKdList<MsgPack>.New;
|
||||
for (int i = 0; i < Length; i++) MsgPack.Add(Read());
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadExt(ref MsgPack MsgPack)
|
||||
private bool ReadExt(ref MsgPack MsgPack, ref Types Type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.FixExt1 ) Length = 1 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt2 ) Length = 2 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt4 ) Length = 4 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt8 ) Length = 8 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt16) Length = 16;
|
||||
else if (MsgPack.Type == MsgPack.Types. Ext8 ) Length = _IO.ReadByte();
|
||||
else if (MsgPack.Type == MsgPack.Types. Ext16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types. Ext32) Length = _IO.ReadInt32Endian(true);
|
||||
if (Type == Types.FixExt1 ) Length = 1 ;
|
||||
else if (Type == Types.FixExt2 ) Length = 2 ;
|
||||
else if (Type == Types.FixExt4 ) Length = 4 ;
|
||||
else if (Type == Types.FixExt8 ) Length = 8 ;
|
||||
else if (Type == Types.FixExt16) Length = 16;
|
||||
else if (Type == Types. Ext8 ) Length = _IO.ReadByte();
|
||||
else if (Type == Types. Ext16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (Type == Types. Ext32) Length = _IO.ReadInt32Endian(true);
|
||||
else return false;
|
||||
MsgPack.Object = new MsgPack.Ext { Type = _IO.ReadSByte(), Data = _IO.ReadBytes(Length) };
|
||||
return true;
|
||||
}
|
||||
|
||||
public IO Write(MsgPack MsgPack, bool Close)
|
||||
{ Write(MsgPack); if (Close) this.Close(); return this; }
|
||||
|
||||
public IO Write(MsgPack MsgPack)
|
||||
public IO Write(MsgPack MsgPack, bool IsArray = false)
|
||||
{
|
||||
if (MsgPack.Name != null) Write(MsgPack.Name);
|
||||
if (MsgPack.Name != null && !IsArray) Write(MsgPack.Name);
|
||||
Write(MsgPack.Object);
|
||||
return this;
|
||||
}
|
||||
@@ -205,10 +194,10 @@ namespace KKdMainLib.MessagePack
|
||||
if (obj == null) { WriteNil(); return; }
|
||||
switch (obj)
|
||||
{
|
||||
case List<object> val: WriteMap(val.Count );
|
||||
foreach (object Val in val) Write(Val); break;
|
||||
case object[] val: WriteArr(val.Length);
|
||||
foreach (object Val in val) Write(Val); break;
|
||||
case KKdList<MsgPack> val: WriteMap(val.Count );
|
||||
for (int i = 0; i < val.Count ; i++) Write(val[i]); break;
|
||||
case MsgPack[] val: WriteArr(val.Length);
|
||||
for (int i = 0; i < val.Length; i++) Write(val[i]); break;
|
||||
case MsgPack val: Write(val); break;
|
||||
case byte[] val: Write(val); break;
|
||||
case bool val: Write(val); break;
|
||||
@@ -227,42 +216,42 @@ namespace KKdMainLib.MessagePack
|
||||
}
|
||||
}
|
||||
|
||||
private void Write( sbyte val) { if (val < -0x20) _IO.Write((byte)0xD0); _IO.Write(val); }
|
||||
private void Write( byte val) { if (val >= 0x80) _IO.Write((byte)0xCC); _IO.Write(val); }
|
||||
private void Write( sbyte val) { if (val < -0x20) _IO.WriteByte(0xD0); _IO.Write(val); }
|
||||
private void Write( byte val) { if (val >= 0x80) _IO.WriteByte(0xCC); _IO.Write(val); }
|
||||
private void Write( short val) { if (( sbyte)val == val) Write(( sbyte)val);
|
||||
else if (( byte)val == val) Write(( byte)val);
|
||||
else { _IO.Write((byte)0xD1); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xD1); _IO.WriteEndian(val, true); } }
|
||||
private void Write(ushort val) { if (( byte)val == val) Write(( byte)val);
|
||||
else { _IO.Write((byte)0xCD); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xCD); _IO.WriteEndian(val, true); } }
|
||||
private void Write( int val) { if (( short)val == val) Write(( short)val);
|
||||
else if ((ushort)val == val) Write((ushort)val);
|
||||
else { _IO.Write((byte)0xD2); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xD2); _IO.WriteEndian(val, true); } }
|
||||
private void Write( uint val) { if ((ushort)val == val) Write((ushort)val);
|
||||
else { _IO.Write((byte)0xCE); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xCE); _IO.WriteEndian(val, true); } }
|
||||
private void Write( long val) { if (( int)val == val) Write(( int)val);
|
||||
else if (( uint)val == val) Write(( uint)val);
|
||||
else { _IO.Write((byte)0xD3); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xD3); _IO.WriteEndian(val, true); } }
|
||||
private void Write( ulong val) { if (( uint)val == val) Write(( uint)val);
|
||||
else { _IO.Write((byte)0xCF); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xCF); _IO.WriteEndian(val, true); } }
|
||||
private void Write( float val) { if (( long)val == val) Write(( long)val);
|
||||
else { _IO.Write((byte)0xCA); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xCA); _IO.WriteEndian(val, true); } }
|
||||
private void Write(double val) { if (( long)val == val) Write(( long)val);
|
||||
else if (( float)val == val) Write(( float)val);
|
||||
else { _IO.Write((byte)0xCB); _IO.WriteEndian(val, true); } }
|
||||
else { _IO.WriteByte(0xCB); _IO.WriteEndian(val, true); } }
|
||||
|
||||
private void Write( bool val)
|
||||
{ _IO.Write((byte)(val ? 0xC3 : 0xC2)); }
|
||||
private void Write( bool val) =>
|
||||
_IO.WriteByte((byte)(val ? 0xC3 : 0xC2));
|
||||
|
||||
private void Write(byte[] val)
|
||||
{
|
||||
if (val == null) { WriteNil(); return; }
|
||||
|
||||
if (val.Length < 0x100)
|
||||
{ _IO.Write((byte)0xC4); _IO.Write (( byte)val.Length ); }
|
||||
{ _IO.WriteByte(0xC4); _IO.WriteByte (( byte)val.Length ); }
|
||||
else if (val.Length < 0x10000)
|
||||
{ _IO.Write((byte)0xC5); _IO.WriteEndian((ushort)val.Length, true); }
|
||||
{ _IO.WriteByte(0xC5); _IO.WriteEndian((ushort)val.Length, true); }
|
||||
else
|
||||
{ _IO.Write((byte)0xC6); _IO.WriteEndian( val.Length, true); }
|
||||
{ _IO.WriteByte(0xC6); _IO.WriteEndian( val.Length, true); }
|
||||
_IO.Write(val);
|
||||
}
|
||||
|
||||
@@ -272,32 +261,32 @@ namespace KKdMainLib.MessagePack
|
||||
|
||||
byte[] array = Text.ToUTF8(val);
|
||||
if (array.Length < 0x20)
|
||||
_IO.Write((byte)(0xA0 | (array.Length & 0x1F)));
|
||||
_IO.WriteByte((byte)(0xA0 | (array.Length & 0x1F)));
|
||||
else if (array.Length < 0x100)
|
||||
{ _IO.Write((byte) 0xD9); _IO.Write (( byte)array.Length); }
|
||||
{ _IO.WriteByte(0xD9); _IO.WriteByte (( byte)array.Length); }
|
||||
else if (array.Length < 0x10000)
|
||||
{ _IO.Write((byte )0xDA); _IO.WriteEndian((ushort)array.Length, true); }
|
||||
{ _IO.WriteByte(0xDA); _IO.WriteEndian((ushort)array.Length, true); }
|
||||
else
|
||||
{ _IO.Write((byte) 0xDB); _IO.WriteEndian( array.Length, true); }
|
||||
{ _IO.WriteByte(0xDB); _IO.WriteEndian( array.Length, true); }
|
||||
_IO.Write(array);
|
||||
}
|
||||
|
||||
private void WriteNil() => _IO.Write((byte)0xC0);
|
||||
private void WriteNil() => _IO.WriteByte(0xC0);
|
||||
|
||||
private void WriteArr(int val)
|
||||
{
|
||||
if (val == 0) { WriteNil(); return; }
|
||||
else if (val < 0x10) _IO.Write((byte)(0x90 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.Write((byte) 0xDC); _IO.WriteEndian((ushort)val, true); }
|
||||
else { _IO.Write((byte) 0xDD); _IO.WriteEndian( val, true); }
|
||||
else if (val < 0x10) _IO.WriteByte((byte)(0x90 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.WriteByte(0xDC); _IO.WriteEndian((ushort)val, true); }
|
||||
else { _IO.WriteByte(0xDD); _IO.WriteEndian( val, true); }
|
||||
}
|
||||
|
||||
private void WriteMap(int val)
|
||||
{
|
||||
if (val == 0) { WriteNil(); return; }
|
||||
else if (val < 0x10) _IO.Write((byte)(0x80 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.Write((byte) 0xDE); _IO.WriteEndian((ushort)val, true); }
|
||||
else { _IO.Write((byte) 0xDF); _IO.WriteEndian( val, true); }
|
||||
else if (val < 0x10) _IO.WriteByte((byte)(0x80 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.WriteByte(0xDE); _IO.WriteEndian((ushort)val, true); }
|
||||
else { _IO.WriteByte(0xDF); _IO.WriteEndian( val, true); }
|
||||
}
|
||||
|
||||
private void Write(MsgPack.Ext val)
|
||||
@@ -305,22 +294,68 @@ namespace KKdMainLib.MessagePack
|
||||
if (val.Data == null) { WriteNil(); return; }
|
||||
|
||||
if (val.Data.Length < 1 ) { WriteNil(); return; }
|
||||
else if (val.Data.Length == 1 ) _IO.Write((byte)0xD4);
|
||||
else if (val.Data.Length == 2 ) _IO.Write((byte)0xD5);
|
||||
else if (val.Data.Length == 4 ) _IO.Write((byte)0xD6);
|
||||
else if (val.Data.Length == 8 ) _IO.Write((byte)0xD7);
|
||||
else if (val.Data.Length == 16) _IO.Write((byte)0xD8);
|
||||
else if (val.Data.Length == 1 ) _IO.WriteByte(0xD4);
|
||||
else if (val.Data.Length == 2 ) _IO.WriteByte(0xD5);
|
||||
else if (val.Data.Length == 4 ) _IO.WriteByte(0xD6);
|
||||
else if (val.Data.Length == 8 ) _IO.WriteByte(0xD7);
|
||||
else if (val.Data.Length == 16) _IO.WriteByte(0xD8);
|
||||
else
|
||||
{
|
||||
if (val.Data.Length < 0x100)
|
||||
{ _IO.Write((byte)0xC7); _IO.Write (( byte)val.Data.Length); }
|
||||
{ _IO.WriteByte(0xC7); _IO.WriteByte (( byte)val.Data.Length); }
|
||||
else if (val.Data.Length < 0x10000)
|
||||
{ _IO.Write((byte)0xC8); _IO.WriteEndian((ushort)val.Data.Length, true); }
|
||||
{ _IO.WriteByte(0xC8); _IO.WriteEndian((ushort)val.Data.Length, true); }
|
||||
else
|
||||
{ _IO.Write((byte)0xC9); _IO.WriteEndian( val.Data.Length, true); }
|
||||
{ _IO.WriteByte(0xC9); _IO.WriteEndian( val.Data.Length, true); }
|
||||
}
|
||||
_IO.Write(val.Type);
|
||||
_IO.Write(val.Data);
|
||||
}
|
||||
}
|
||||
|
||||
public enum Types : byte
|
||||
{
|
||||
PosInt = 0b00000000,
|
||||
FixMap = 0b10000000,
|
||||
FixArr = 0b10010000,
|
||||
FixStr = 0b10100000,
|
||||
Nil = 0b11000000,
|
||||
NeverUsed = 0b11000001,
|
||||
False = 0b11000010,
|
||||
True = 0b11000011,
|
||||
Bin8 = 0b11000100,
|
||||
Bin16 = 0b11000101,
|
||||
Bin32 = 0b11000110,
|
||||
Ext8 = 0b11000111,
|
||||
Ext16 = 0b11001000,
|
||||
Ext32 = 0b11001001,
|
||||
Float32 = 0b11001010,
|
||||
Float64 = 0b11001011,
|
||||
UInt8 = 0b11001100,
|
||||
UInt16 = 0b11001101,
|
||||
UInt32 = 0b11001110,
|
||||
UInt64 = 0b11001111,
|
||||
Int8 = 0b11010000,
|
||||
Int16 = 0b11010001,
|
||||
Int32 = 0b11010010,
|
||||
Int64 = 0b11010011,
|
||||
FixExt1 = 0b11010100,
|
||||
FixExt2 = 0b11010101,
|
||||
FixExt4 = 0b11010110,
|
||||
FixExt8 = 0b11010111,
|
||||
FixExt16 = 0b11011000,
|
||||
Str8 = 0b11011001,
|
||||
Str16 = 0b11011010,
|
||||
Str32 = 0b11011011,
|
||||
Arr16 = 0b11011100,
|
||||
Arr32 = 0b11011101,
|
||||
Map16 = 0b11011110,
|
||||
Map32 = 0b11011111,
|
||||
NegInt = 0b11100000,
|
||||
PosIntMax = 0b01111111,
|
||||
FixMapMax = 0b10001111,
|
||||
FixArrMax = 0b10011111,
|
||||
FixStrMax = 0b10111111,
|
||||
NegIntMax = 0b11111111,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
//Original or reader part: https://github.com/MarcosLopezC/LightJson/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.Types;
|
||||
|
||||
namespace KKdMainLib.MessagePack
|
||||
{
|
||||
@@ -15,19 +14,13 @@ namespace KKdMainLib.MessagePack
|
||||
|
||||
public void Close() => _IO.Close();
|
||||
|
||||
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
|
||||
|
||||
public MsgPack Read() => ReadValue();
|
||||
|
||||
private string ReadKey() => ReadString();
|
||||
|
||||
private MsgPack ReadValue()
|
||||
{
|
||||
char c = _IO.SkipWhitespace().PeekCharUTF8();
|
||||
object obj = null;
|
||||
if (c == '{') obj = ReadObject();
|
||||
return new MsgPack(null, true, obj);
|
||||
}
|
||||
|
||||
private MsgPack ReadValue(string Key)
|
||||
private MsgPack ReadValue(string Key = null)
|
||||
{
|
||||
char c = _IO.SkipWhitespace().PeekCharUTF8();
|
||||
object obj = null;
|
||||
@@ -44,7 +37,7 @@ namespace KKdMainLib.MessagePack
|
||||
case 'f': obj = ReadBoolean(); break;
|
||||
case 'n': obj = ReadNull (); break;
|
||||
}
|
||||
return new MsgPack(Key, true, obj);
|
||||
return new MsgPack(Key, obj);
|
||||
}
|
||||
|
||||
private string ReadString()
|
||||
@@ -88,36 +81,36 @@ namespace KKdMainLib.MessagePack
|
||||
private int ReadHexDigit() => byte.Parse(_IO.ReadCharUTF8().ToString(),
|
||||
System.Globalization.NumberStyles.HexNumber);
|
||||
|
||||
private List<object> ReadObject()
|
||||
private KKdList<MsgPack> ReadObject()
|
||||
{
|
||||
List<object> Obj = new List<object>();
|
||||
if (!_IO.Assert('{')) return null;
|
||||
if (_IO.SkipWhitespace().PeekCharUTF8() == '}') { _IO.ReadCharUTF8(); return null; }
|
||||
KKdList<MsgPack> Obj = KKdList<MsgPack>.New;
|
||||
if (!_IO.Assert('{')) return KKdList<MsgPack>.Null;
|
||||
if (_IO.SkipWhitespace().PeekCharUTF8() == '}') { _IO.ReadCharUTF8(); return KKdList<MsgPack>.Null; }
|
||||
|
||||
string key;
|
||||
char c;
|
||||
while (true)
|
||||
{
|
||||
_IO.SkipWhitespace();
|
||||
|
||||
key = ReadString();
|
||||
if (!_IO.SkipWhitespace().Assert(':')) return null;
|
||||
if (!_IO.SkipWhitespace().Assert(':'))
|
||||
return KKdList<MsgPack>.Null;
|
||||
|
||||
Obj.Add(ReadValue(key));
|
||||
|
||||
_IO.SkipWhitespace();
|
||||
|
||||
var next = _IO.ReadCharUTF8();
|
||||
|
||||
if (next == '}') break;
|
||||
else if (next == ',') continue;
|
||||
else return null;
|
||||
c = _IO.SkipWhitespace().PeekCharUTF8();
|
||||
|
||||
if (c == '}') { _IO.ReadCharUTF8(); break; }
|
||||
else if (c == ',') { _IO.ReadCharUTF8(); continue; }
|
||||
else return KKdList<MsgPack>.Null;
|
||||
}
|
||||
|
||||
return Obj;
|
||||
}
|
||||
|
||||
private object[] ReadArray()
|
||||
private MsgPack[] ReadArray()
|
||||
{
|
||||
List<object> Obj = new List<object>();
|
||||
KKdList<MsgPack> Obj = KKdList<MsgPack>.New;
|
||||
if (!_IO.Assert('[')) return null;
|
||||
if (_IO.SkipWhitespace().PeekCharUTF8() == ']') { _IO.ReadCharUTF8(); return null; }
|
||||
|
||||
@@ -125,10 +118,10 @@ namespace KKdMainLib.MessagePack
|
||||
while (true)
|
||||
{
|
||||
Obj.Add(ReadValue(null));
|
||||
c = _IO.SkipWhitespace().ReadCharUTF8();
|
||||
c = _IO.SkipWhitespace().PeekCharUTF8();
|
||||
|
||||
if (c == ']') break;
|
||||
else if (c == ',') continue;
|
||||
if (c == ']') { _IO.ReadCharUTF8(); break; }
|
||||
else if (c == ',') { _IO.ReadCharUTF8(); continue; }
|
||||
else return null;
|
||||
}
|
||||
return Obj.ToArray();
|
||||
@@ -141,8 +134,18 @@ namespace KKdMainLib.MessagePack
|
||||
if (_IO.PeekCharUTF8() == '-') s += _IO.ReadCharUTF8();
|
||||
if (_IO.PeekCharUTF8() == '0') s += _IO.ReadCharUTF8();
|
||||
else s += ReadDigits ();
|
||||
if (_IO.PeekCharUTF8() == '.') s += _IO.ReadCharUTF8() + ReadDigits();
|
||||
else return long.Parse(s);
|
||||
if (_IO.PeekCharUTF8() == '.') s += _IO.ReadCharUTF8() + ReadDigits();
|
||||
else
|
||||
{
|
||||
long val = long.Parse(s);
|
||||
if (val >= 0x000000 && val < 0x0000100) return ( byte)val;
|
||||
else if (val >= -0x000080 && val < 0x0000080) return ( sbyte)val;
|
||||
else if (val >= -0x008000 && val < 0x0008000) return ( short)val;
|
||||
else if (val >= 0x000000 && val < 0x0010000) return (ushort)val;
|
||||
else if (val >= -0x800000 && val < 0x0800000) return ( int)val;
|
||||
else if (val >= 0x000000 && val < 0x1000000) return ( uint)val;
|
||||
else return val;
|
||||
}
|
||||
|
||||
char c = _IO.PeekCharUTF8();
|
||||
if (c == 'e' || c == 'E')
|
||||
@@ -152,7 +155,8 @@ namespace KKdMainLib.MessagePack
|
||||
if (c == '+' || c == '-') s += _IO.ReadCharUTF8();
|
||||
s += ReadDigits();
|
||||
}
|
||||
return s.ToDouble();
|
||||
double d = s.ToDouble();
|
||||
return (float)d == d ? (float)d : d;
|
||||
}
|
||||
|
||||
private bool ReadBoolean()
|
||||
@@ -169,28 +173,35 @@ namespace KKdMainLib.MessagePack
|
||||
{ string s = ""; while (char.IsDigit(_IO.SkipWhitespace().
|
||||
PeekCharUTF8())) s += _IO.ReadCharUTF8(); return s; }
|
||||
|
||||
public JSONIO Write(MsgPack MsgPack, bool Close, string End = "\n", string TabChar = " ")
|
||||
{ Write(MsgPack, End, TabChar, "", true); if (Close) this.Close(); return this; }
|
||||
public JSONIO Write(MsgPack MsgPack, string End = "\n", string TabChar = " ")
|
||||
{ Write(MsgPack, End, TabChar, "", true); return this; }
|
||||
|
||||
public JSONIO Write(MsgPack MsgPack, bool Close, bool Style = false)
|
||||
{ Write(MsgPack, "\n", " ", "", Style); if (Close) this.Close(); return this; }
|
||||
public JSONIO Write(MsgPack MsgPack, bool Style = false)
|
||||
{ Write(MsgPack, "\n", " ", "", Style); return this; }
|
||||
|
||||
private JSONIO Write(MsgPack MsgPack, string End, string TabChar, string Tab, bool Style)
|
||||
private JSONIO Write(MsgPack MsgPack, string End, string TabChar, string Tab, bool Style, bool IsArray = false)
|
||||
{
|
||||
string OldTab = Tab;
|
||||
Tab += TabChar;
|
||||
if (MsgPack.Name != null) _IO.Write("\"" + MsgPack.Name + "\":" + (Style ? " " : ""));
|
||||
if (MsgPack.Name != null && !IsArray) _IO.Write("\"" + MsgPack.Name + "\":" + (Style ? " " : ""));
|
||||
if (MsgPack.Object == null) { WriteNil(); return this; }
|
||||
|
||||
if (MsgPack.List != null)
|
||||
if (MsgPack.List.NotNull)
|
||||
{
|
||||
WriteMap();
|
||||
if (Style) _IO.Write(End);
|
||||
for (int i = 0; i < MsgPack.List.Count; i++)
|
||||
if (MsgPack.List.Count > 1)
|
||||
for (int i = 0; i < MsgPack.List.Count; i++)
|
||||
{
|
||||
if (Style) _IO.Write(Tab);
|
||||
Write(MsgPack.List[i], End, TabChar, Tab, Style);
|
||||
if (i + 1 < MsgPack.List.Count) _IO.Write(',');
|
||||
if (Style) _IO.Write(End);
|
||||
}
|
||||
else if (MsgPack.List.Count == 1)
|
||||
{
|
||||
if (Style) _IO.Write(Tab);
|
||||
Write(MsgPack.List[i], End, TabChar, Tab, Style);
|
||||
if (i + 1 < MsgPack.List. Count) _IO.Write(',');
|
||||
Write(MsgPack.List[0], End, TabChar, Tab, Style);
|
||||
if (Style) _IO.Write(End);
|
||||
}
|
||||
if (Style) _IO.Write(OldTab);
|
||||
@@ -200,11 +211,18 @@ namespace KKdMainLib.MessagePack
|
||||
{
|
||||
WriteArr();
|
||||
if (Style) _IO.Write(End);
|
||||
for (int i = 0; i < MsgPack.Array.Length; i++)
|
||||
if (MsgPack.Array.Length > 1)
|
||||
for (int i = 0; i < MsgPack.Array.Length; i++)
|
||||
{
|
||||
if (Style) _IO.Write(Tab);
|
||||
Write(MsgPack.Array[i], End, TabChar, Tab, Style, true);
|
||||
if (i + 1 < MsgPack.Array.Length) _IO.Write(',');
|
||||
if (Style) _IO.Write(End);
|
||||
}
|
||||
else if (MsgPack.Array.Length == 1)
|
||||
{
|
||||
if (Style) _IO.Write(Tab);
|
||||
Write(MsgPack.Array[i], End, TabChar, Tab, Style);
|
||||
if (i + 1 < MsgPack.Array.Length) _IO.Write(',');
|
||||
Write(MsgPack.Array[0], End, TabChar, Tab, Style, true);
|
||||
if (Style) _IO.Write(End);
|
||||
}
|
||||
if (Style) _IO.Write(OldTab);
|
||||
|
||||
@@ -5,6 +5,17 @@ namespace KKdMainLib.MessagePack
|
||||
{
|
||||
public static class MPExt
|
||||
{
|
||||
public static MsgPack ReadMPAllAtOnce(this string file, bool JSON = false)
|
||||
{
|
||||
MsgPack MsgPack;
|
||||
if (JSON)
|
||||
{ JSONIO IO = new JSONIO(File.OpenReader(file + ".json", true));
|
||||
MsgPack = IO.Read(); IO.Close(); IO = null; }
|
||||
else
|
||||
{ MPIO IO = new MPIO(File.OpenReader(file + ".mp" , true));
|
||||
MsgPack = IO.Read(); IO.Close(); IO = null; }
|
||||
return MsgPack;
|
||||
}
|
||||
public static MsgPack ReadMP(this string file, bool JSON = false)
|
||||
{
|
||||
MsgPack MsgPack;
|
||||
@@ -16,9 +27,24 @@ namespace KKdMainLib.MessagePack
|
||||
MsgPack = IO.Read(); IO.Close(); IO = null; }
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
public static void Write(this MsgPack mp, bool Temp, string file, bool JSON = false)
|
||||
{ if (Temp) MsgPack.New.Add(mp).Write(file, JSON).Dispose();
|
||||
else mp .Write(file, JSON); }
|
||||
|
||||
public static MsgPack Write(this MsgPack mp, string file, bool JSON = false)
|
||||
{
|
||||
if (JSON)
|
||||
{ JSONIO IO = new JSONIO(File.OpenWriter(file + ".json", true));
|
||||
IO.Write(mp, "\n", " ").Close(); IO = null; }
|
||||
else
|
||||
{ MPIO IO = new MPIO(File.OpenWriter(file + ".mp" , true));
|
||||
IO.Write(mp ).Close(); IO = null; }
|
||||
return mp;
|
||||
}
|
||||
|
||||
public static void WriteAfterAll(this MsgPack mp, bool Temp, string file, bool JSON = false)
|
||||
{ if (Temp) new MsgPack().Add(mp).WriteAfterAll(file, JSON).Dispose();
|
||||
{ if (Temp) MsgPack.New.Add(mp).WriteAfterAll(file, JSON).Dispose();
|
||||
else mp .WriteAfterAll(file, JSON); }
|
||||
|
||||
public static MsgPack WriteAfterAll(this MsgPack mp, string file, bool JSON = false)
|
||||
@@ -26,30 +52,14 @@ namespace KKdMainLib.MessagePack
|
||||
byte[] data = null;
|
||||
if (JSON)
|
||||
{ JSONIO IO = new JSONIO(File.OpenWriter());
|
||||
IO.Write(mp, false, true); data = IO._IO.ToArray(true); }
|
||||
IO.Write(mp, true); data = IO.ToArray(true); }
|
||||
else
|
||||
{ MPIO IO = new MPIO(File.OpenWriter());
|
||||
IO.Write(mp, false ); data = IO._IO.ToArray(true); }
|
||||
IO.Write(mp ); data = IO.ToArray(true); }
|
||||
File.WriteAllBytes(file + (JSON ? ".json" : ".mp"), data);
|
||||
return mp;
|
||||
}
|
||||
|
||||
|
||||
public static void Write(this MsgPack mp, bool Temp, string file, bool JSON = false)
|
||||
{ if (Temp) new MsgPack().Add(mp).Write(file, JSON).Dispose();
|
||||
else mp .Write(file, JSON); }
|
||||
|
||||
public static MsgPack Write(this MsgPack mp, string file, bool JSON = false)
|
||||
{
|
||||
if (JSON)
|
||||
{ JSONIO IO = new JSONIO(File.OpenWriter(file + ".json", true));
|
||||
IO.Write(mp, true, true); IO = null; }
|
||||
else
|
||||
{ MPIO IO = new MPIO(File.OpenWriter(file + ".mp" , true));
|
||||
IO.Write(mp, true ); IO = null; }
|
||||
return mp;
|
||||
}
|
||||
|
||||
public static void ToJSON (this string file) =>
|
||||
file.ReadMP( ).Write(file, true).Dispose();
|
||||
|
||||
|
||||
+187
-234
@@ -1,147 +1,114 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.Types;
|
||||
|
||||
namespace KKdMainLib.MessagePack
|
||||
{
|
||||
public class MsgPack : IDisposable
|
||||
public struct MsgPack : IDisposable, IEquatable<MsgPack>
|
||||
{
|
||||
public Types Type;
|
||||
public string Name;
|
||||
public object Object;
|
||||
|
||||
public object[] Array => Object is object[] List ? List : null;
|
||||
public List<object> List => Object is List<object> Array ? Array : null;
|
||||
|
||||
public MsgPack( Types Type = Types.Map32) => NewMsgPack(null, Type);
|
||||
public MsgPack(string Name, Types Type = Types.Map32) => NewMsgPack(Name, Type);
|
||||
public MsgPack( long Count) => NewMsgPack(null, Count);
|
||||
public MsgPack(string Name, long Count) => NewMsgPack(Name, Count);
|
||||
public MsgPack(string Name, Types Type, object Object)
|
||||
{ this.Name = Name; this.Type = Type; this.Object = Object; }
|
||||
public MsgPack(string Name, bool TypeIsntKnown, object Object)
|
||||
{
|
||||
switch (Object)
|
||||
{
|
||||
case List<object> val: Type = Types. Map32; break;
|
||||
case object[] val: Type = Types. Arr32; break;
|
||||
case MsgPack val: Type = Types. Map32; break;
|
||||
case byte[] val: Type = Types. Bin32; break;
|
||||
case bool val: Type = val ? Types.True : Types.False; break;
|
||||
case sbyte val: Type = Types. Int8 ; break;
|
||||
case byte val: Type = Types. UInt8 ; break;
|
||||
case short val: Type = Types. Int16; break;
|
||||
case ushort val: Type = Types. UInt16; break;
|
||||
case int val: Type = Types. Int32; break;
|
||||
case uint val: Type = Types. UInt32; break;
|
||||
case long val: Type = Types. Int64; break;
|
||||
case ulong val: Type = Types. UInt64; break;
|
||||
case float val: Type = Types.Float32; break;
|
||||
case double val: Type = Types.Float64; break;
|
||||
case string val: Type = Types. Str32; break;
|
||||
case Ext val: Type = Types. Ext32; break;
|
||||
case null: Type = Types. Nil; break;
|
||||
}
|
||||
this.Name = Name; this.Object = Object;
|
||||
}
|
||||
public MsgPack[] Array => Object is MsgPack[] List ?
|
||||
List : null;
|
||||
public KKdList<MsgPack> List => Object is KKdList<MsgPack> List ?
|
||||
List : default(KKdList<MsgPack>);
|
||||
|
||||
public static MsgPack Null => null;
|
||||
public static MsgPack New => new MsgPack { Object = KKdList<MsgPack>.New };
|
||||
public static MsgPack NewReserve(int Capacity) =>
|
||||
new MsgPack { Object = KKdList<MsgPack>.NewReserve(Capacity) };
|
||||
|
||||
public object this[int index]
|
||||
{ get { if (Array != null) return Array[index]; return null; }
|
||||
set { if (Array != null) Array[index] = value; } }
|
||||
public MsgPack( string Name = null)
|
||||
{ Object = KKdList<MsgPack>.New; this.Name = Name; }
|
||||
|
||||
public MsgPack(long Count, string Name = null)
|
||||
{ if (Count > 0) { Object = new MsgPack[Count]; }
|
||||
else Object = null; this.Name = Name; }
|
||||
|
||||
public MsgPack(string Name, object Object)
|
||||
{ this.Name = Name; this.Object = Object; }
|
||||
|
||||
public static MsgPack Null => new MsgPack();
|
||||
|
||||
public MsgPack this[int index]
|
||||
{ get { if (Object is MsgPack[] Array) return Array[index]; return default(MsgPack); }
|
||||
set { if (Object is MsgPack[] Array) { Array[index] = value; Object = Array; } } }
|
||||
|
||||
public MsgPack Add(object obj)
|
||||
{ if (obj != null && List != null) List.Add(obj); return this; }
|
||||
|
||||
public MsgPack(List<object> Object, string Name, Types Type)
|
||||
{ this.Object = Object; this.Name = Name; this.Type = Type; }
|
||||
|
||||
private void NewMsgPack(string Name, Types Type)
|
||||
{ Object = new List<object>(); this.Name = Name; this.Type = Type; }
|
||||
|
||||
private void NewMsgPack(string Name, long Count)
|
||||
{ if (Count > 0) { Object = new object[Count]; }
|
||||
else Object = null; this.Name = Name; Type = Types.Arr32; }
|
||||
public MsgPack Add(MsgPack obj)
|
||||
{ if (Object is KKdList<MsgPack> List) { List.Add(obj); Object = List; } return this; }
|
||||
|
||||
public void Dispose()
|
||||
{ Type = 0; Name = null; Object = null; }
|
||||
{ Name = null; Object = null; }
|
||||
|
||||
public MsgPack Add( sbyte? val) => Add(null, val);
|
||||
public MsgPack Add( byte? val) => Add(null, val);
|
||||
public MsgPack Add( short? val) => Add(null, val);
|
||||
public MsgPack Add(ushort? val) => Add(null, val);
|
||||
public MsgPack Add( int? val) => Add(null, val);
|
||||
public MsgPack Add( uint? val) => Add(null, val);
|
||||
public MsgPack Add( long? val) => Add(null, val);
|
||||
public MsgPack Add( ulong? val) => Add(null, val);
|
||||
public MsgPack Add( float? val) => Add(null, val);
|
||||
public MsgPack Add(double? val) => Add(null, val);
|
||||
public bool Equals(MsgPack msg) =>
|
||||
Name == msg.Name && Object == msg.Object;
|
||||
|
||||
public override string ToString() => Name ?? "" +
|
||||
(List. NotNull ? ((Name != null ? " " : "") + "Elements Count: " + List .Count ) :
|
||||
(Array != null ? ((Name != null ? " " : "") + "Elements Count: " + Array.Length) : Object.ToString()));
|
||||
|
||||
public static explicit operator MsgPack(byte[] val) => new MsgPack(null, val);
|
||||
public static explicit operator MsgPack(string val) => new MsgPack(null, val);
|
||||
public static explicit operator MsgPack( sbyte val) => new MsgPack(null, val);
|
||||
public static explicit operator MsgPack( byte val) => new MsgPack(null, val);
|
||||
public static explicit operator MsgPack( short val) => new MsgPack(null, val);
|
||||
public static explicit operator MsgPack(ushort val) => new MsgPack(null, val);
|
||||
public static explicit operator MsgPack( int val) => new MsgPack(null, val);
|
||||
public static explicit operator MsgPack( uint val) => new MsgPack(null, val);
|
||||
public static explicit operator MsgPack( long val) => new MsgPack(null, val);
|
||||
public static explicit operator MsgPack( ulong val) => new MsgPack(null, val);
|
||||
public static explicit operator MsgPack( float val) => new MsgPack(null, val);
|
||||
public static explicit operator MsgPack(double val) => new MsgPack(null, val);
|
||||
|
||||
public MsgPack Add( sbyte? val) => val != null ? Add(new MsgPack(null, ( sbyte)val)) : this;
|
||||
public MsgPack Add( byte? val) => val != null ? Add(new MsgPack(null, ( byte)val)) : this;
|
||||
public MsgPack Add( short? val) => val != null ? Add(new MsgPack(null, ( short)val)) : this;
|
||||
public MsgPack Add(ushort? val) => val != null ? Add(new MsgPack(null, (ushort)val)) : this;
|
||||
public MsgPack Add( int? val) => val != null ? Add(new MsgPack(null, ( int)val)) : this;
|
||||
public MsgPack Add( uint? val) => val != null ? Add(new MsgPack(null, ( uint)val)) : this;
|
||||
public MsgPack Add( long? val) => val != null ? Add(new MsgPack(null, ( long)val)) : this;
|
||||
public MsgPack Add( ulong? val) => val != null ? Add(new MsgPack(null, ( ulong)val)) : this;
|
||||
public MsgPack Add( float? val) => val != null ? Add(new MsgPack(null, ( float)val)) : this;
|
||||
public MsgPack Add(double? val) => val != null ? Add(new MsgPack(null, (double)val)) : this;
|
||||
|
||||
public MsgPack Add(byte[] val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add(string val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( bool val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( sbyte val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( byte val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( short val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add(ushort val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( int val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( uint val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( long val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( ulong val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( float val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add(double val) => Add(new MsgPack(null, val));
|
||||
|
||||
public MsgPack Add(byte[] val) => Add(null, val);
|
||||
public MsgPack Add(string val) => Add(null, val);
|
||||
public MsgPack Add( bool val) => Add(null, val);
|
||||
public MsgPack Add( sbyte val) => Add(null, val);
|
||||
public MsgPack Add( byte val) => Add(null, val);
|
||||
public MsgPack Add( short val) => Add(null, val);
|
||||
public MsgPack Add(ushort val) => Add(null, val);
|
||||
public MsgPack Add( int val) => Add(null, val);
|
||||
public MsgPack Add( uint val) => Add(null, val);
|
||||
public MsgPack Add( long val) => Add(null, val);
|
||||
public MsgPack Add( ulong val) => Add(null, val);
|
||||
public MsgPack Add( float val) => Add(null, val);
|
||||
public MsgPack Add(double val) => Add(null, val);
|
||||
|
||||
public MsgPack Add(string Val, sbyte? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( sbyte)val); return this; }
|
||||
public MsgPack Add(string Val, byte? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( byte)val); return this; }
|
||||
public MsgPack Add(string Val, short? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( short)val); return this; }
|
||||
public MsgPack Add(string Val, ushort? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, (ushort)val); return this; }
|
||||
public MsgPack Add(string Val, int? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( int)val); return this; }
|
||||
public MsgPack Add(string Val, uint? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( uint)val); return this; }
|
||||
public MsgPack Add(string Val, long? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( long)val); return this; }
|
||||
public MsgPack Add(string Val, ulong? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( ulong)val); return this; }
|
||||
public MsgPack Add(string Val, float? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( float)val); return this; }
|
||||
public MsgPack Add(string Val, double? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, (double)val); return this; }
|
||||
public 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, byte[] val)
|
||||
{ if (val == null) Add(Null); else
|
||||
Add(new MsgPack(Val, Types. Bin32, val)); return this; }
|
||||
public MsgPack Add(string Val, string val)
|
||||
{ if (val == null) Add(Null); else
|
||||
Add(new MsgPack(Val, Types. Str32, val)); return this; }
|
||||
public MsgPack Add(string Val, bool val)
|
||||
{ Add(new MsgPack(Val, val ?
|
||||
Types.True : Types. False, val)); return this; }
|
||||
public MsgPack Add(string Val, sbyte val)
|
||||
{ Add(new MsgPack(Val, Types. Int8, val)); return this; }
|
||||
public MsgPack Add(string Val, byte val)
|
||||
{ Add(new MsgPack(Val, Types. UInt8, val)); return this; }
|
||||
public MsgPack Add(string Val, short val)
|
||||
{ Add(new MsgPack(Val, Types. Int16, val)); return this; }
|
||||
public MsgPack Add(string Val, ushort val)
|
||||
{ Add(new MsgPack(Val, Types. UInt16, val)); return this; }
|
||||
public MsgPack Add(string Val, int val)
|
||||
{ Add(new MsgPack(Val, Types. Int32, val)); return this; }
|
||||
public MsgPack Add(string Val, uint val)
|
||||
{ Add(new MsgPack(Val, Types. UInt32, val)); return this; }
|
||||
public MsgPack Add(string Val, long val)
|
||||
{ Add(new MsgPack(Val, Types. Int64, val)); return this; }
|
||||
public MsgPack Add(string Val, ulong val)
|
||||
{ Add(new MsgPack(Val, Types. UInt64, val)); return this; }
|
||||
public MsgPack Add(string Val, float val)
|
||||
{ Add(new MsgPack(Val, Types.Float32, val)); return this; }
|
||||
public MsgPack Add(string Val, double val)
|
||||
{ Add(new MsgPack(Val, Types.Float64, val)); return this; }
|
||||
public MsgPack Add(string Val, bool val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, sbyte val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, byte val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, short val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, ushort val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, int val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, uint val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, long val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, ulong val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, float val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, double val) => Add(new MsgPack(Val, val));
|
||||
|
||||
public bool ReadBoolean(string Name) => ReadNBoolean(Name).GetValueOrDefault();
|
||||
public sbyte ReadInt8(string Name) => ReadNInt8(Name).GetValueOrDefault();
|
||||
@@ -155,30 +122,30 @@ namespace KKdMainLib.MessagePack
|
||||
public float ReadSingle(string Name) => ReadNSingle(Name).GetValueOrDefault();
|
||||
public double ReadDouble(string Name) => ReadNDouble(Name).GetValueOrDefault();
|
||||
|
||||
public bool? ReadNBoolean(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack.ReadNBoolean(); return null; }
|
||||
public sbyte? ReadNInt8(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt8(); return null; }
|
||||
public byte? ReadNUInt8(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt8(); return null; }
|
||||
public short? ReadNInt16(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt16(); return null; }
|
||||
public ushort? ReadNUInt16(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt16(); return null; }
|
||||
public int? ReadNInt32(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt32(); return null; }
|
||||
public uint? ReadNUInt32(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt32(); return null; }
|
||||
public long? ReadNInt64(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt64(); return null; }
|
||||
public ulong? ReadNUInt64(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt64(); return null; }
|
||||
public float? ReadNSingle(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNSingle(); return null; }
|
||||
public double? ReadNDouble(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNDouble(); return null; }
|
||||
public string ReadString(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadString(); return null; }
|
||||
public bool? ReadNBoolean(string Name) =>
|
||||
Element(Name, out MsgPack MsgPack) ? MsgPack.ReadNBoolean() : null;
|
||||
public sbyte? ReadNInt8(string Name) =>
|
||||
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNInt8 () : null;
|
||||
public byte? ReadNUInt8(string Name) =>
|
||||
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNUInt8 () : null;
|
||||
public short? ReadNInt16(string Name) =>
|
||||
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNInt16() : null;
|
||||
public ushort? ReadNUInt16(string Name) =>
|
||||
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNUInt16() : null;
|
||||
public int? ReadNInt32(string Name) =>
|
||||
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNInt32() : null;
|
||||
public uint? ReadNUInt32(string Name) =>
|
||||
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNUInt32() : null;
|
||||
public long? ReadNInt64(string Name) =>
|
||||
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNInt64() : null;
|
||||
public ulong? ReadNUInt64(string Name) =>
|
||||
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNUInt64() : null;
|
||||
public float? ReadNSingle(string Name) =>
|
||||
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNSingle() : null;
|
||||
public double? ReadNDouble(string Name) =>
|
||||
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNDouble() : null;
|
||||
public string ReadString(string Name) =>
|
||||
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadString() : null;
|
||||
|
||||
public bool ReadBoolean() => ReadNBoolean().GetValueOrDefault();
|
||||
public sbyte ReadInt8() => ReadNInt8().GetValueOrDefault();
|
||||
@@ -195,50 +162,81 @@ namespace KKdMainLib.MessagePack
|
||||
public bool? ReadNBoolean()
|
||||
{ if (Object is bool Boolean) return Boolean; return null; }
|
||||
public sbyte? ReadNInt8()
|
||||
{ if (Object is long Int64) return ( sbyte) Int64;
|
||||
else if (Object is ulong UInt64) return ( sbyte) UInt64; return null; }
|
||||
{ if (Object is sbyte Int8 ) return Int8 ;
|
||||
else if (Object is byte UInt8 ) return ( sbyte) UInt8 ; return null; }
|
||||
public byte? ReadNUInt8()
|
||||
{ if (Object is long Int64) return ( byte) Int64;
|
||||
else if (Object is ulong UInt64) return ( byte) UInt64; return null; }
|
||||
{ if (Object is sbyte Int8 ) return ( byte) Int8 ;
|
||||
else if (Object is byte UInt8 ) return UInt8 ; return null; }
|
||||
public short? ReadNInt16()
|
||||
{ if (Object is long Int64) return ( short) Int64;
|
||||
else if (Object is ulong UInt64) return ( short) UInt64; return null; }
|
||||
{ if (Object is sbyte Int8 ) return Int8 ;
|
||||
else if (Object is byte UInt8 ) return UInt8 ;
|
||||
else if (Object is short Int16) return Int16;
|
||||
else if (Object is ushort UInt16) return ( short) UInt16; return null; }
|
||||
public ushort? ReadNUInt16()
|
||||
{ if (Object is long Int64) return (ushort) Int64;
|
||||
else if (Object is ulong UInt64) return (ushort) UInt64; return null; }
|
||||
{ if (Object is sbyte Int8 ) return (ushort) Int8 ;
|
||||
else if (Object is byte UInt8 ) return UInt8 ;
|
||||
else if (Object is short Int16) return (ushort) Int16;
|
||||
else if (Object is ushort UInt16) return UInt16; return null; }
|
||||
public int? ReadNInt32()
|
||||
{ if (Object is long Int64) return ( int) Int64;
|
||||
else if (Object is ulong UInt64) return ( int) UInt64; return null; }
|
||||
{ if (Object is sbyte Int8 ) return Int8 ;
|
||||
else if (Object is byte UInt8 ) return UInt8 ;
|
||||
else if (Object is short Int16) return Int16;
|
||||
else if (Object is ushort UInt16) return UInt16;
|
||||
else if (Object is int Int32) return Int32;
|
||||
else if (Object is uint UInt32) return ( int) UInt32; return null; }
|
||||
public uint? ReadNUInt32()
|
||||
{ if (Object is long Int64) return ( uint) Int64;
|
||||
else if (Object is ulong UInt64) return ( uint) UInt64; return null; }
|
||||
{ if (Object is sbyte Int8 ) return ( uint) Int8 ;
|
||||
else if (Object is byte UInt8 ) return UInt8 ;
|
||||
else if (Object is short Int16) return ( uint) Int16;
|
||||
else if (Object is ushort UInt16) return UInt16;
|
||||
else if (Object is int Int32) return ( uint) Int32;
|
||||
else if (Object is uint UInt32) return UInt32; return null; }
|
||||
public long? ReadNInt64()
|
||||
{ if (Object is long Int64) return ( long) Int64;
|
||||
{ if (Object is sbyte Int8 ) return Int8 ;
|
||||
else if (Object is byte UInt8 ) return UInt8 ;
|
||||
else if (Object is short Int16) return Int16;
|
||||
else if (Object is ushort UInt16) return UInt16;
|
||||
else if (Object is int Int32) return Int32;
|
||||
else if (Object is uint UInt32) return UInt32;
|
||||
else if (Object is long Int64) return Int64;
|
||||
else if (Object is ulong UInt64) return ( long) UInt64; return null; }
|
||||
public ulong? ReadNUInt64()
|
||||
{ if (Object is long Int64) return ( ulong) Int64;
|
||||
else if (Object is ulong UInt64) return ( ulong) UInt64; return null; }
|
||||
{ if (Object is sbyte Int8 ) return ( ulong) Int8 ;
|
||||
else if (Object is byte UInt8 ) return UInt8 ;
|
||||
else if (Object is short Int16) return ( ulong) Int16;
|
||||
else if (Object is ushort UInt16) return UInt16;
|
||||
else if (Object is int Int32) return ( ulong) Int32;
|
||||
else if (Object is uint UInt32) return UInt32;
|
||||
else if (Object is long Int64) return ( ulong) Int64;
|
||||
else if (Object is ulong UInt64) return UInt64; return null; }
|
||||
public float? ReadNSingle()
|
||||
{ if (Object is long Int64) return ( float) Int64;
|
||||
else if (Object is ulong UInt64) return ( float) UInt64;
|
||||
else if (Object is float Float32) return ( float)Float32;
|
||||
{ if (Object is sbyte Int8 ) return Int8 ;
|
||||
else if (Object is byte UInt8 ) return UInt8 ;
|
||||
else if (Object is short Int16) return Int16;
|
||||
else if (Object is ushort UInt16) return UInt16;
|
||||
else if (Object is int Int32) return Int32;
|
||||
else if (Object is uint UInt32) return UInt32;
|
||||
else if (Object is long Int64) return Int64;
|
||||
else if (Object is float Float32) return Float32;
|
||||
else if (Object is double Float64) return ( float)Float64; return null; }
|
||||
public double? ReadNDouble()
|
||||
{ if (Object is long Int64) return (double) Int64;
|
||||
else if (Object is ulong UInt64) return (double) UInt64;
|
||||
else if (Object is float Float32) return (double)Float32;
|
||||
else if (Object is double Float64) return (double)Float64; return null; }
|
||||
{ if (Object is sbyte Int8 ) return Int8 ;
|
||||
else if (Object is byte UInt8 ) return UInt8 ;
|
||||
else if (Object is short Int16) return Int16;
|
||||
else if (Object is ushort UInt16) return UInt16;
|
||||
else if (Object is int Int32) return Int32;
|
||||
else if (Object is uint UInt32) return UInt32;
|
||||
else if (Object is long Int64) return Int64;
|
||||
else if (Object is float Float32) return Float32;
|
||||
else if (Object is double Float64) return Float64; return null; }
|
||||
public string ReadString()
|
||||
{ if (Object is string String) return String; return null; }
|
||||
{ if (Object is string String) return String; return null; }
|
||||
|
||||
public bool Element<T>(string Name, out MsgPack MsgPack)
|
||||
public bool ElementArray(string Name, out MsgPack MsgPack)
|
||||
{
|
||||
if (Element(Name, out MsgPack))
|
||||
{
|
||||
if (MsgPack.Array == null) return false;
|
||||
|
||||
for (int i = 0; i < MsgPack.Array.Length; i++)
|
||||
if (!(MsgPack[i] is T)) return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -246,72 +244,27 @@ namespace KKdMainLib.MessagePack
|
||||
|
||||
public bool Element(string Name, out MsgPack MsgPack)
|
||||
{
|
||||
MsgPack = null;
|
||||
if (List != null)
|
||||
foreach (object obj in List)
|
||||
if (obj is MsgPack msg) if (msg.Name == Name) { MsgPack = msg; return true; }
|
||||
MsgPack = New;
|
||||
if (List.IsNull) return false;
|
||||
|
||||
for (int i = 0; i < List.Count; i++)
|
||||
if (List[i].Name == Name) { MsgPack = List[i]; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool ContainsKey(string Name)
|
||||
{
|
||||
if (List == null) return false;
|
||||
if (List.IsNull) return false;
|
||||
|
||||
foreach (object obj in List)
|
||||
if (obj is MsgPack msg) if (msg.Name == Name) return true;
|
||||
for (int i = 0; i < List.Count ; i++)
|
||||
if (List[i].Name == Name) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public enum Types : byte
|
||||
{
|
||||
PosInt = 0b00000000,
|
||||
FixMap = 0b10000000,
|
||||
FixArr = 0b10010000,
|
||||
FixStr = 0b10100000,
|
||||
Nil = 0b11000000,
|
||||
NeverUsed = 0b11000001,
|
||||
False = 0b11000010,
|
||||
True = 0b11000011,
|
||||
Bin8 = 0b11000100,
|
||||
Bin16 = 0b11000101,
|
||||
Bin32 = 0b11000110,
|
||||
Ext8 = 0b11000111,
|
||||
Ext16 = 0b11001000,
|
||||
Ext32 = 0b11001001,
|
||||
Float32 = 0b11001010,
|
||||
Float64 = 0b11001011,
|
||||
UInt8 = 0b11001100,
|
||||
UInt16 = 0b11001101,
|
||||
UInt32 = 0b11001110,
|
||||
UInt64 = 0b11001111,
|
||||
Int8 = 0b11010000,
|
||||
Int16 = 0b11010001,
|
||||
Int32 = 0b11010010,
|
||||
Int64 = 0b11010011,
|
||||
FixExt1 = 0b11010100,
|
||||
FixExt2 = 0b11010101,
|
||||
FixExt4 = 0b11010110,
|
||||
FixExt8 = 0b11010111,
|
||||
FixExt16 = 0b11011000,
|
||||
Str8 = 0b11011001,
|
||||
Str16 = 0b11011010,
|
||||
Str32 = 0b11011011,
|
||||
Arr16 = 0b11011100,
|
||||
Arr32 = 0b11011101,
|
||||
Map16 = 0b11011110,
|
||||
Map32 = 0b11011111,
|
||||
NegInt = 0b11100000,
|
||||
PosIntMax = 0b01111111,
|
||||
FixMapMax = 0b10001111,
|
||||
FixArrMax = 0b10011111,
|
||||
FixStrMax = 0b10111111,
|
||||
NegIntMax = 0b11111111,
|
||||
}
|
||||
|
||||
|
||||
public struct Ext
|
||||
{
|
||||
public byte[] Data;
|
||||
public sbyte Type;
|
||||
public sbyte Type;
|
||||
public byte[] Data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,200 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.Types;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public class Mot
|
||||
{
|
||||
private int i, i0, i1;
|
||||
private Stream IO;
|
||||
|
||||
public Mot()
|
||||
{ i = i0 = i1 = 0; IO = null; }
|
||||
|
||||
public unsafe void MOTReader(string file, bool JSON)
|
||||
{
|
||||
IO = File.OpenReader(file + ".bin");
|
||||
|
||||
i = 0;
|
||||
while (true)
|
||||
{
|
||||
if (IO.ReadInt32() == 0) break;
|
||||
IO.ReadInt32();
|
||||
IO.ReadInt32();
|
||||
IO.ReadInt32();
|
||||
i++;
|
||||
}
|
||||
if (i == 0) return;
|
||||
|
||||
int MOTCount = i;
|
||||
MsgPack m = new MsgPack(MOTCount, "Mot");
|
||||
MotHeader[] MMOT = new MotHeader[MOTCount];
|
||||
for (i = 0; i < MOTCount; i++)
|
||||
{
|
||||
ref MotHeader Mot = ref MMOT[i];
|
||||
IO.Position = 0x10 * i;
|
||||
Mot. KeySet.Offset = IO.ReadInt32();
|
||||
Mot.KeySetTypesOffset = IO.ReadInt32();
|
||||
Mot. KeySetOffset = IO.ReadInt32();
|
||||
Mot. BoneInfo.Offset = IO.ReadInt32();
|
||||
|
||||
i0 = 1;
|
||||
IO.Position = Mot.BoneInfo.Offset;
|
||||
IO.ReadUInt16();
|
||||
while (true) { if (IO.ReadUInt16() == 0) break; i0++; }
|
||||
|
||||
Mot.BoneInfo.Value = new BoneInfo[i0];
|
||||
IO.Position = Mot.BoneInfo.Offset;
|
||||
for (i0 = 0; i0 < Mot.BoneInfo.Value.Length; i0++)
|
||||
Mot.BoneInfo.Value[i0].Id = IO.ReadUInt16();
|
||||
|
||||
IO.Position = Mot.KeySet.Offset;
|
||||
int info = IO.ReadUInt16();
|
||||
Mot.HighBits = info >> 14;
|
||||
Mot.FrameCount = IO.ReadUInt16();
|
||||
|
||||
Mot.KeySet.Value = new KeySet[info & 0x3FFF];
|
||||
IO.Position = Mot.KeySetTypesOffset;
|
||||
for (i0 = 0; i0 < Mot.KeySet.Value.Length; i0++)
|
||||
{
|
||||
if (i0 % 8 == 0) i1 = IO.ReadUInt16();
|
||||
|
||||
Mot.KeySet.Value[i0] = new KeySet
|
||||
{ Type = (KeySetType)((i1 >> (i0 % 8 * 2)) & 3) };
|
||||
}
|
||||
|
||||
IO.Position = Mot.KeySetOffset;
|
||||
for (i0 = 0; i0 < Mot.KeySet.Value.Length; i0++)
|
||||
Mot.KeySet.Value[i0].Read(IO);
|
||||
|
||||
|
||||
m[i] = MsgPackWriter(ref MMOT[i]);
|
||||
m[i].Write(true, file + "." + i.ToString("d2"), JSON);
|
||||
}
|
||||
IO.Close();
|
||||
//for (i = 0; i < MOTCount; i++)
|
||||
// m[i] = MsgPackWriter(ref MMOT[i]);
|
||||
|
||||
m.Write(true, file, JSON);
|
||||
MMOT = null;
|
||||
m = new MsgPack();
|
||||
System.GC.Collect();
|
||||
}
|
||||
|
||||
public MsgPack MsgPackWriter(ref MotHeader Mot)
|
||||
{
|
||||
MsgPack MOT = MsgPack.NewReserve(3).Add("FrameCount", Mot.FrameCount).Add("HighBits", Mot.HighBits);
|
||||
|
||||
MsgPack KeySets = new MsgPack(Mot.KeySet.Value.Length, "KeySets");
|
||||
for (i0 = 0; i0 < Mot.KeySet.Value.Length; i0++)
|
||||
{
|
||||
ref KeySet KeySet = ref Mot.KeySet.Value[i0];
|
||||
if (KeySet.Type != KeySetType.None)
|
||||
{
|
||||
MsgPack keySet = MsgPack.NewReserve(2).Add("T", KeySet.Type.ToString());
|
||||
|
||||
if (KeySet.Type == KeySetType.Interpolated)
|
||||
{
|
||||
MsgPack Keys = new MsgPack(KeySet.Keys.Length, "K");
|
||||
for (i1 = 0; i1 < KeySet.Keys.Length; i1++)
|
||||
if (KeySet.Keys[i1] is KeyFrameT0<ushort, float> KeyT0)
|
||||
Keys[i1] = MsgPack.NewReserve(1).Add("F", KeyT0.Frame);
|
||||
else if (KeySet.Keys[i1] is KeyFrameT1<ushort, float> KeyT1)
|
||||
Keys[i1] = MsgPack.NewReserve(2).Add("F", KeyT1.Frame).Add("V", KeyT1.Value);
|
||||
else if (KeySet.Keys[i1] is KeyFrameT2<ushort, float> KeyT2)
|
||||
Keys[i1] = MsgPack.NewReserve(3).Add("F", KeyT2.Frame).Add("V",
|
||||
KeyT2.Value).Add("I", KeyT2.Interpolation);
|
||||
keySet.Add(Keys);
|
||||
}
|
||||
else if(KeySet.Type == KeySetType.Linear)
|
||||
{
|
||||
MsgPack Keys = new MsgPack(KeySet.Keys.Length, "K");
|
||||
for (i1 = 0; i1 < KeySet.Keys.Length; i1++)
|
||||
if (KeySet.Keys[i1] is KeyFrameT0<ushort, float> KeyT0)
|
||||
Keys[i1] = MsgPack.NewReserve(1).Add("F", KeyT0.Frame);
|
||||
else if (KeySet.Keys[i1] is KeyFrameT1<ushort, float> KeyT1)
|
||||
Keys[i1] = MsgPack.NewReserve(2).Add("F", KeyT1.Frame).Add("V", KeyT1.Value);
|
||||
keySet.Add(Keys);
|
||||
}
|
||||
else if (KeySet.Type == KeySetType.Static)
|
||||
if (KeySet.Keys[0] is KeyFrameT1<ushort, float> Key) keySet.Add("K", Key.Value);
|
||||
|
||||
KeySets[i0] = keySet;
|
||||
}
|
||||
}
|
||||
MOT.Add(KeySets);
|
||||
|
||||
MsgPack BoneInfo = new MsgPack(Mot.BoneInfo.Value.Length, "BoneInfo");
|
||||
for (i0 = 0; i0 < Mot.BoneInfo.Value.Length; i0++)
|
||||
BoneInfo[i0] = (MsgPack)Mot.BoneInfo.Value[i0].Id;
|
||||
MOT.Add(BoneInfo);
|
||||
|
||||
return MOT;
|
||||
}
|
||||
|
||||
public struct MotHeader
|
||||
{
|
||||
public int KeySetOffset;
|
||||
public int KeySetTypesOffset;
|
||||
public Pointer< KeySet []> KeySet ;
|
||||
public Pointer<BoneInfo[]> BoneInfo;
|
||||
|
||||
public int HighBits;
|
||||
public int FrameCount;
|
||||
}
|
||||
|
||||
public struct KeySet
|
||||
{
|
||||
public IKeyFrame<ushort, float>[] Keys;
|
||||
public KeySetType Type;
|
||||
|
||||
public void Read(Stream IO)
|
||||
{
|
||||
if (Type == KeySetType.None ) return;
|
||||
else if (Type == KeySetType.Static) { Keys = new IKeyFrame<ushort, float>[]
|
||||
{ new KeyFrameT1<ushort, float> { Value = IO.ReadSingle() } }; return; }
|
||||
|
||||
Keys = new IKeyFrame<ushort, float>[IO.ReadUInt16()];
|
||||
if (Type == KeySetType.Interpolated)
|
||||
{
|
||||
for (int i = 0; i < Keys.Length; i++)
|
||||
Keys[i] = new KeyFrameT2<ushort, float>{ Frame = IO.ReadUInt16() };
|
||||
IO.Align(0x4);
|
||||
for (int i = 0; i < Keys.Length; i++)
|
||||
if (Keys[i] is KeyFrameT2<ushort, float> Key)
|
||||
{
|
||||
Key.Value = IO.ReadSingle();
|
||||
Key.Interpolation = IO.ReadSingle();
|
||||
Keys[i] = Key.Check();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < Keys.Length; i++)
|
||||
Keys[i] = new KeyFrameT1<ushort, float> { Frame = IO.ReadUInt16() };
|
||||
IO.Align(0x4);
|
||||
for (int i = 0; i < Keys.Length; i++)
|
||||
if (Keys[i] is KeyFrameT1<ushort, float> Key)
|
||||
{ Key.Value = IO.ReadSingle(); Keys[i] = Key; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum KeySetType : byte
|
||||
{
|
||||
None = 0b00,
|
||||
Static = 0b01,
|
||||
Linear = 0b10,
|
||||
Interpolated = 0b11,
|
||||
}
|
||||
|
||||
public struct BoneInfo
|
||||
{
|
||||
public string Name;
|
||||
public int Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,10 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("KKdMainLib")]
|
||||
[assembly: AssemblyCopyright("Copyright korenkonder © 2018-2019")]
|
||||
[assembly: AssemblyCopyright("korenkonder © 2018-2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("2BA7EFC6-91D1-8BBC-C487-06C7F36CC789")]
|
||||
[assembly: AssemblyVersion("0.4.5.10")]
|
||||
[assembly: AssemblyFileVersion("0.4.5.10")]
|
||||
[assembly: AssemblyVersion("0.4.6.1")]
|
||||
[assembly: AssemblyFileVersion("0.4.6.1")]
|
||||
|
||||
+10
-12
@@ -173,33 +173,31 @@ namespace KKdMainLib
|
||||
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
|
||||
if (!MsgPack.Element("STR", out MsgPack STR)) return;
|
||||
|
||||
if (!STR.Element<MsgPack>("Strings", out MsgPack Strings)) return;
|
||||
if (!STR.ElementArray("Strings", out MsgPack Strings)) return;
|
||||
|
||||
STRs = new String[Strings.Array.Length];
|
||||
for (int i = 0; i < STRs.Length; i++)
|
||||
if (Strings[i] is MsgPack String)
|
||||
{
|
||||
String = (MsgPack)Strings[i];
|
||||
STRs[i].ID = String.ReadInt32("ID");
|
||||
STRs[i].Str = String.ReadString("Str");
|
||||
}
|
||||
{
|
||||
STRs[i].ID = Strings[i].ReadInt32 ("ID" );
|
||||
STRs[i].Str = Strings[i].ReadString("Str");
|
||||
}
|
||||
|
||||
MsgPack = null;
|
||||
MsgPack = MsgPack.New;
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
{
|
||||
MsgPack STR_ = new MsgPack("STR").Add("Format", Header.Format.ToString());
|
||||
MsgPack Strings = new MsgPack("Strings", STRs.Length);
|
||||
MsgPack Strings = new MsgPack(STRs.Length, "Strings");
|
||||
for (int i = 0; i < STRs.Length; i++)
|
||||
{
|
||||
Strings[i] = new MsgPack().Add("ID", STRs[i].ID);
|
||||
Strings[i] = MsgPack.New.Add("ID", STRs[i].ID);
|
||||
if (STRs[i].Str != null) if (STRs[i].Str != "")
|
||||
((MsgPack)Strings[i]).Add("S", STRs[i].Str); ;
|
||||
Strings[i].Add("S", STRs[i].Str); ;
|
||||
}
|
||||
STR_.Add(Strings);
|
||||
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
namespace KKdMainLib.Types
|
||||
{
|
||||
public interface IKeyFrame<TKey, TVal>
|
||||
{
|
||||
IKeyFrame<TKey, TVal> Check();
|
||||
IKeyFrame<TKey, TVal> ToKeyFrameT0();
|
||||
IKeyFrame<TKey, TVal> ToKeyFrameT1();
|
||||
IKeyFrame<TKey, TVal> ToKeyFrameT2();
|
||||
IKeyFrame<TKey, TVal> ToKeyFrameT3();
|
||||
string ToString();
|
||||
string ToString(bool Brackets);
|
||||
}
|
||||
|
||||
public struct KeyFrameT0<TKey, TVal> : IKeyFrame<TKey, TVal>
|
||||
{
|
||||
public TKey Frame;
|
||||
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
|
||||
new KeyFrameT0<TKey, TVal> { Frame = Frame };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
|
||||
new KeyFrameT1<TKey, TVal> { Frame = Frame };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
|
||||
new KeyFrameT2<TKey, TVal> { Frame = Frame };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
|
||||
new KeyFrameT3<TKey, TVal> { Frame = Frame };
|
||||
|
||||
public IKeyFrame<TKey, TVal> Check() => this;
|
||||
|
||||
public override string ToString() =>
|
||||
Main.ToString(Frame);
|
||||
public string ToString(bool Brackets) =>
|
||||
Main.ToString(Frame);
|
||||
}
|
||||
|
||||
public struct KeyFrameT1<TKey, TVal> : IKeyFrame<TKey, TVal>
|
||||
{
|
||||
public TKey Frame;
|
||||
public TVal Value;
|
||||
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
|
||||
new KeyFrameT0<TKey, TVal> { Frame = Frame };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
|
||||
new KeyFrameT1<TKey, TVal> { Frame = Frame, Value = Value };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
|
||||
new KeyFrameT2<TKey, TVal> { Frame = Frame, Value = Value };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
|
||||
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value };
|
||||
|
||||
public IKeyFrame<TKey, TVal> Check()
|
||||
{
|
||||
if (Value.Equals(default(TVal))) return ToKeyFrameT0();
|
||||
return this;
|
||||
}
|
||||
|
||||
public override string ToString() => ToString(true);
|
||||
public string ToString(bool Brackets) =>
|
||||
(Brackets ? "(" : "") + Main.ToString(Frame) + "," +
|
||||
Main.ToString(Value) + (Brackets ? ")" : "");
|
||||
}
|
||||
|
||||
public struct KeyFrameT2<TKey, TVal> : IKeyFrame<TKey, TVal>
|
||||
{
|
||||
public TKey Frame;
|
||||
public TVal Value;
|
||||
public TVal Interpolation;
|
||||
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
|
||||
new KeyFrameT0<TKey, TVal> { Frame = Frame };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
|
||||
new KeyFrameT1<TKey, TVal> { Frame = Frame, Value = Value };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
|
||||
new KeyFrameT2<TKey, TVal> { Frame = Frame, Value = Value,
|
||||
Interpolation = Interpolation};
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
|
||||
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
|
||||
Interpolation1 = Interpolation, Interpolation2 = Interpolation };
|
||||
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT3(IKeyFrame<TKey, TVal> Previous) =>
|
||||
Previous is KeyFrameT2<TKey, TVal> PreviousT2 ?
|
||||
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
|
||||
Interpolation1 = PreviousT2.Interpolation, Interpolation2 = Interpolation } :
|
||||
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
|
||||
Interpolation1 = Interpolation, Interpolation2 = Interpolation };
|
||||
|
||||
public IKeyFrame<TKey, TVal> Check()
|
||||
{
|
||||
if (Value.Equals(default(TVal)) && Interpolation.Equals(default(TVal)))
|
||||
return ToKeyFrameT0();
|
||||
else if (Value.Equals(default(TVal))) return ToKeyFrameT1();
|
||||
return this;
|
||||
}
|
||||
|
||||
public override string ToString() => ToString(true);
|
||||
public string ToString(bool Brackets) =>
|
||||
(Brackets ? "(" : "") + Main.ToString(Frame) + "," + Main.
|
||||
ToString(Value) + "," + Main.ToString(Interpolation) + (Brackets ? ")" : "");
|
||||
}
|
||||
|
||||
public struct KeyFrameT3<TKey, TVal> : IKeyFrame<TKey, TVal>
|
||||
{
|
||||
public TKey Frame;
|
||||
public TVal Value;
|
||||
public TVal Interpolation1;
|
||||
public TVal Interpolation2;
|
||||
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
|
||||
new KeyFrameT0<TKey, TVal> { Frame = Frame };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
|
||||
new KeyFrameT1<TKey, TVal> { Frame = Frame, Value = Value };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
|
||||
new KeyFrameT2<TKey, TVal> { Frame = Frame, Value = Value, Interpolation = Interpolation1 };
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
|
||||
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
|
||||
Interpolation1 = Interpolation1, Interpolation2 = Interpolation2 };
|
||||
|
||||
public IKeyFrame<TKey, TVal> Check()
|
||||
{
|
||||
if (Value.Equals(default(TVal)) && Interpolation1.Equals(default(TVal)) &&
|
||||
Interpolation2.Equals(default(TVal))) return ToKeyFrameT0();
|
||||
else if (Interpolation1.Equals(default(TVal)) &&
|
||||
Interpolation2.Equals(default(TVal))) return ToKeyFrameT1();
|
||||
else if (Interpolation1.Equals(Interpolation2))
|
||||
return ToKeyFrameT2();
|
||||
return this;
|
||||
}
|
||||
|
||||
public override string ToString() => ToString(true);
|
||||
public string ToString(bool Brackets) =>
|
||||
(Brackets ? "(" : "") + Main.ToString(Frame) + "," + Main.ToString(Value) + "," +
|
||||
Main.ToString(Interpolation1) + "," + Main.ToString(Interpolation2) + (Brackets ? ")" : "");
|
||||
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT2(IKeyFrame<TKey, TVal>
|
||||
Previous, out KeyFrameT2<TKey, TVal> Current)
|
||||
{
|
||||
if (Previous is KeyFrameT2<TKey, TVal> PreviousT2)
|
||||
Current = new KeyFrameT2<TKey, TVal> { Frame = PreviousT2.Frame,
|
||||
Value = PreviousT2.Value, Interpolation = Interpolation1 };
|
||||
else
|
||||
Current = new KeyFrameT2<TKey, TVal> { Frame = Frame,
|
||||
Value = Value, Interpolation = Interpolation1 };
|
||||
return new KeyFrameT2<TKey, TVal> { Frame = Frame,
|
||||
Value = Value, Interpolation = Interpolation2 };
|
||||
}
|
||||
public IKeyFrame<TKey, TVal> ToKeyFrameT2(IKeyFrame<TKey, TVal>
|
||||
Previous, out IKeyFrame<TKey, TVal> Current)
|
||||
{
|
||||
if (Previous is KeyFrameT2<TKey, TVal> PreviousT2)
|
||||
Current = new KeyFrameT2<TKey, TVal> { Frame = PreviousT2.Frame,
|
||||
Value = PreviousT2.Value, Interpolation = Interpolation1 };
|
||||
else
|
||||
Current = new KeyFrameT2<TKey, TVal> { Frame = Frame,
|
||||
Value = Value, Interpolation = Interpolation1 };
|
||||
return new KeyFrameT2<TKey, TVal> { Frame = Frame,
|
||||
Value = Value, Interpolation = Interpolation2 };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace KKdMainLib.Types
|
||||
{
|
||||
public struct KKdList<T> : IEnumerator, IEnumerable
|
||||
{
|
||||
public static KKdList<T> Null => new KKdList<T>();
|
||||
public static KKdList<T> New => new KKdList<T>() { Capacity = 0 };
|
||||
public static KKdList<T> NewReserve(int Capacity) => new KKdList<T>() { Capacity = Capacity };
|
||||
|
||||
private int index;
|
||||
private T[] array;
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public bool IsNull => array == null;
|
||||
public bool NotNull => array != null;
|
||||
|
||||
public int Capacity { get => array != null ? array.Length : -1;
|
||||
set
|
||||
{
|
||||
if (array != null) System.Array.Resize(ref array, value);
|
||||
else array = new T[value];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public KKdList(T[] Array)
|
||||
{
|
||||
index = 0;
|
||||
Count = Array.Length;
|
||||
this.array = Array;
|
||||
}
|
||||
|
||||
public T Current => index < Count ? array[index] : default(T);
|
||||
|
||||
object IEnumerator.Current => Current;
|
||||
|
||||
public T this[int index]
|
||||
{ get { if (array != null) return array[index]; return default(T); }
|
||||
set { if (array != null) array[index] = value; } }
|
||||
|
||||
public bool MoveNext()
|
||||
{ if (index == (Count - 1)) { index = 0; return false; }
|
||||
else { index++ ; return true; } }
|
||||
|
||||
public IEnumerator GetEnumerator() => this;
|
||||
|
||||
public void Dispose() { array = null; Count = 0; index = 0; }
|
||||
|
||||
public void Reset() => index = 0;
|
||||
|
||||
public void Add(T item)
|
||||
{
|
||||
if (IsNull) return;
|
||||
|
||||
Count++;
|
||||
if (array.Length < Count)
|
||||
System.Array.Resize(ref array, Count);
|
||||
array[Count - 1] = item;
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if (IsNull) return;
|
||||
|
||||
for (int i = index; i < Count; i++)
|
||||
array[i] = array[i + 1];
|
||||
}
|
||||
|
||||
public void RemoveRange(int IndexStart, int IndexEnd)
|
||||
{
|
||||
if (IndexEnd - IndexStart < 1) return;
|
||||
if (IsNull) return;
|
||||
|
||||
for (int i = IndexStart; i < Count; i++)
|
||||
array[i] = array[i + IndexEnd - IndexStart];
|
||||
}
|
||||
|
||||
public T[] ToArray() => array;
|
||||
|
||||
public bool Contains(T val)
|
||||
{
|
||||
if (IsNull) return false;
|
||||
for (int i = 0; i < Count; i++)
|
||||
if (array[i].Equals(val)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public int IndexOf(T val)
|
||||
{
|
||||
if (IsNull) return -1;
|
||||
for (int i = 0; i < Count; i++)
|
||||
if (array[i].Equals(val)) return i;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
namespace KKdMainLib.Types
|
||||
{
|
||||
public struct Pointer<T>
|
||||
{
|
||||
public int Offset;
|
||||
public T Value;
|
||||
|
||||
public override string ToString() => Main.ToString(Value);
|
||||
}
|
||||
|
||||
public struct CountPointer<T>
|
||||
{
|
||||
public int Count { get => Entries != null ? Entries.Length : 0;
|
||||
set => Entries = new T[value]; }
|
||||
public int Offset;
|
||||
public T[] Entries;
|
||||
|
||||
public T this[int index]
|
||||
{
|
||||
get { if (Count > 0) return Entries[index]; return default(T); }
|
||||
set { if (Count > 0) { Entries[index] = value; } }
|
||||
}
|
||||
|
||||
public override string ToString() => Count < 1 ? "No Entries" :
|
||||
Count == 1 ? Entries[0].ToString() : "Count: " + Count;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace KKdMainLib.Types
|
||||
{
|
||||
public struct Vector2<T>
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
|
||||
public Vector2(T X, T Y)
|
||||
{ this.X = X; this.Y = Y; }
|
||||
|
||||
public override string ToString() => "X: " + X + "; Y: " + Y;
|
||||
}
|
||||
|
||||
public struct Vector3<T>
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
public T Z;
|
||||
|
||||
public Vector3(T X, T Y, T Z)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; }
|
||||
|
||||
public override string ToString() => "X: " + X + "; Y: " + Y + "; Z: " + Z;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.Types
|
||||
{
|
||||
public class Vector2<T>
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
public T Z;
|
||||
|
||||
public Vector2()
|
||||
{ X = default(T); Y = default(T); Z = default(T); }
|
||||
|
||||
public Vector2(T X, T Y, T Z)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; }
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.Types
|
||||
{
|
||||
public class Vector3<T>
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
public T Z;
|
||||
|
||||
public Vector3()
|
||||
{ X = default(T); Y = default(T); Z = default(T); }
|
||||
|
||||
public Vector3(T X, T Y, T Z)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; }
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("KKdSoundLib")]
|
||||
[assembly: AssemblyCopyright("Copyright korenkonder © 2019")]
|
||||
[assembly: AssemblyCopyright("korenkonder © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
+5
-8
@@ -10,7 +10,6 @@ namespace PD_Tool
|
||||
public static class Program
|
||||
{
|
||||
public static string function = "";
|
||||
public static List<string> ProcessedFiles = new List<string>();
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
@@ -18,19 +17,17 @@ namespace PD_Tool
|
||||
Console.Title = "PD_Tool";
|
||||
if (args.Length == 0)
|
||||
{
|
||||
GC.Collect();
|
||||
while (function != "Q") MainMenu();
|
||||
Exit();
|
||||
}
|
||||
|
||||
long header;
|
||||
Stream reader;
|
||||
KKdFARC Farc;
|
||||
|
||||
foreach (string arg in args)
|
||||
{
|
||||
Farc = new KKdFARC();
|
||||
if (Directory.Exists(arg)) Farc.Pack(arg);
|
||||
else if (File.Exists(arg) && Path.GetExtension(arg) == ".farc") Farc.UnPack(arg, true);
|
||||
if (Directory.Exists(arg)) new KKdFARC(arg, true).Pack();
|
||||
else if (File.Exists(arg) && Path.GetExtension(arg) == ".farc") new KKdFARC(arg).UnPack(true);
|
||||
else if (File.Exists(arg))
|
||||
{
|
||||
reader = File.OpenReader(arg);
|
||||
@@ -42,7 +39,7 @@ namespace PD_Tool
|
||||
Exit();
|
||||
}
|
||||
|
||||
private static bool JSON = false;
|
||||
private static bool JSON = true;
|
||||
|
||||
private static void MainMenu()
|
||||
{
|
||||
@@ -76,7 +73,7 @@ namespace PD_Tool
|
||||
private static void Functions()
|
||||
{
|
||||
Console.Clear();
|
||||
if (function == "1" || function == "2") FARC.Processor(function == "1");
|
||||
if (function == "1" || function == "2") FARC.Processor(function == "1");
|
||||
else if (function == "3" || function == "4")
|
||||
{
|
||||
KKdMain.Choose(1, "", out string[] FileNames);
|
||||
|
||||
@@ -6,10 +6,10 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("PD_Tool")]
|
||||
[assembly: AssemblyCopyright("Copyright korenkonder © 2017-2019")]
|
||||
[assembly: AssemblyCopyright("korenkonder © 2017-2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
|
||||
[assembly: AssemblyVersion("0.4.5.10")]
|
||||
[assembly: AssemblyFileVersion("0.4.5.10")]
|
||||
[assembly: AssemblyVersion("0.4.6.1")]
|
||||
[assembly: AssemblyFileVersion("0.4.6.1")]
|
||||
|
||||
+29
-10
@@ -17,7 +17,7 @@ namespace PD_Tool
|
||||
Main.Choose(1, "farc", out string[] FileNames);
|
||||
foreach (string FileName in FileNames)
|
||||
if (FileName != "" && File.Exists(FileName))
|
||||
FARC.UnPack(FileName);
|
||||
new KKdFARC(FileName).UnPack();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -26,27 +26,46 @@ namespace PD_Tool
|
||||
Console.Title = "FARC Creator";
|
||||
if (file != "")
|
||||
{
|
||||
FARC = new KKdFARC();
|
||||
Main.ConsoleDesign(true);
|
||||
Main.ConsoleDesign(" Choose type of created FARC:");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("1. FArc [DT/DT2nd/DTex/F/F2nd/X]");
|
||||
Main.ConsoleDesign("2. FArC [DT/DT2nd/DTex/F/F2nd/X] (Compressed)");
|
||||
Main.ConsoleDesign("3. FARC [F/F2nd/X] (Compressed)");
|
||||
Main.ConsoleDesign("4. FARC [FT] (Compressed)");
|
||||
Main.ConsoleDesign("3. FARC [F/F2nd/X]");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("Note: Creating FT FARCs currently not supported.");
|
||||
Main.ConsoleDesign("R. Return to Main Menu");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Choosed folder: {0}", file);
|
||||
Console.WriteLine();
|
||||
int.TryParse(Console.ReadLine(), out int type);
|
||||
if (type == 1) FARC.Signature = KKdFARC.Farc.FArc;
|
||||
else if (type == 3) FARC.Signature = KKdFARC.Farc.FARC;
|
||||
else FARC.Signature = KKdFARC.Farc.FArC;
|
||||
Console.Clear();
|
||||
string type = Console.ReadLine().ToUpper();
|
||||
if (type == "1") FARC.Signature = KKdFARC.Farc.FArc;
|
||||
else if (type == "3" || type == "4")
|
||||
{
|
||||
FARC.Signature = KKdFARC.Farc.FARC;
|
||||
|
||||
Console.WriteLine();
|
||||
Main.ConsoleDesign(true);
|
||||
Main.ConsoleDesign(" Choose type of FARC:");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("1. FARC");
|
||||
Main.ConsoleDesign("2. FARC (Compressed)");
|
||||
Main.ConsoleDesign("3. FARC (Encrypted)");
|
||||
Main.ConsoleDesign("4. FARC (Compressed & Encrypted)");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
type = Console.ReadLine();
|
||||
if (type == "2" || type == "4") FARC.FARCType |= KKdFARC.Type.GZip;
|
||||
if (type == "3" || type == "4") FARC.FARCType |= KKdFARC.Type.ECB ;
|
||||
}
|
||||
else if (type == "R") return;
|
||||
else FARC.Signature = KKdFARC.Farc.FArC;
|
||||
Console.Title = "FARC Creator - Directory: " + Path.GetDirectoryName(file);
|
||||
FARC.Pack(file);
|
||||
FARC.DirectoryPath = file;
|
||||
FARC.Pack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,8 @@ namespace PD_Tool.Tools
|
||||
|
||||
bool MP = true;
|
||||
foreach (string file in FileNames)
|
||||
if (file.EndsWith(".mp" )) { MP = false; break; }
|
||||
if (file.EndsWith(".mp" )) { MP = false; break; }
|
||||
else if (file.EndsWith(".json")) { MP = false; break; }
|
||||
|
||||
Main.Format Format = Main.Format.NULL;
|
||||
if (!MP)
|
||||
@@ -63,7 +64,7 @@ namespace PD_Tool.Tools
|
||||
{
|
||||
A.MsgPackReader(filepath, ext == ".json");
|
||||
A.IO = File.OpenWriter(filepath + ".a3da", true);
|
||||
if (A.Data.Header.Format < Main.Format.F2LE)
|
||||
if (A.Data.Header.Format >= Main.Format.F2LE)
|
||||
A.Data._.CompressF16 = Format == Main.Format.MGF ? 2 : 1;
|
||||
A.Data.Header.Format = Format;
|
||||
|
||||
|
||||
+21
-13
@@ -14,17 +14,25 @@ namespace PD_Tool.Tools
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
Console.Clear();
|
||||
string format = "";
|
||||
Main.ConsoleDesign(true);
|
||||
Main.ConsoleDesign(" Choose type of exporting file:");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("1. Compact");
|
||||
Main.ConsoleDesign("2. Normal");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
format = Console.ReadLine();
|
||||
bool MP = true;
|
||||
foreach (string file in FileNames)
|
||||
if (file.EndsWith(".mp" )) { MP = false; break; }
|
||||
else if (file.EndsWith(".json")) { MP = false; break; }
|
||||
|
||||
string format = "1";
|
||||
if (MP)
|
||||
{
|
||||
Console.Clear();
|
||||
Main.ConsoleDesign(true);
|
||||
Main.ConsoleDesign(" Choose type of exporting file:");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("1. Compact");
|
||||
Main.ConsoleDesign("2. Normal");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
format = Console.ReadLine();
|
||||
}
|
||||
|
||||
DataBank DB;
|
||||
string[] file_split;
|
||||
@@ -38,7 +46,7 @@ namespace PD_Tool.Tools
|
||||
string filename = Path.GetFileNameWithoutExtension(file);
|
||||
file_split = filename.Split('_');
|
||||
DB = new DataBank();
|
||||
if (file_split.Length == 5 && ext == ".dat")
|
||||
if (file_split.Length == 5 && ext == ".dat" && MP)
|
||||
{
|
||||
if (!int.TryParse(file_split[3], out File_Checksum)) continue;
|
||||
|
||||
@@ -51,7 +59,7 @@ namespace PD_Tool.Tools
|
||||
DB.MsgPackWriter(filepath + file_split[0] + "_" +
|
||||
file_split[1] + "_" + file_split[2], JSON, format != "2");
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
else if (ext == ".mp" || ext == ".json" && !MP)
|
||||
{
|
||||
Console.Title = "DataBank Converter: " + filename;
|
||||
DB.MsgPackReader(filepath, JSON);
|
||||
|
||||
Reference in New Issue
Block a user