Release v0.4.6.1

Some fixes and changes
This commit is contained in:
KujiKita
2019-07-01 03:53:20 +03:00
parent 93f905d3e1
commit 4de7bd32f7
24 changed files with 1216 additions and 1306 deletions
+194 -214
View File
@@ -1368,18 +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];
for (i = 0; i < Data.Ambient.Length; i++)
if (Temp[i] is MsgPack Ambient)
Data.Ambient[i] = new Ambient
{
Name = Ambient.ReadString ( "Name"),
LightDiffuse = Ambient.ReadRGBAKey( "LightDiffuse"),
RimLightDiffuse = Ambient.ReadRGBAKey("RimLightDiffuse"),
};
Data.Ambient[i] = new Ambient
{
Name = Temp[i].ReadString ( "Name"),
LightDiffuse = Temp[i].ReadRGBAKey( "LightDiffuse"),
RimLightDiffuse = Temp[i].ReadRGBAKey("RimLightDiffuse"),
};
}
if (A3D.Element("CameraAuxiliary", out Temp))
@@ -1392,51 +1391,48 @@ 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];
for (i = 0; i < Data.CameraRoot.Length; i++)
if (Temp[i] is MsgPack _Root)
{
Data.CameraRoot[i] = new CameraRoot
{
Data.CameraRoot[i] = new CameraRoot
{
MT = _Root.ReadMT(),
Interest = _Root.ReadMT("Interest"),
};
if (!_Root.Element("ViewPoint", out MsgPack ViewPoint)) continue;
MT = Temp[i].ReadMT(),
Interest = Temp[i].ReadMT("Interest"),
};
if (!Temp[i].Element("ViewPoint", out MsgPack ViewPoint)) continue;
Data.CameraRoot[i].ViewPoint = new ViewPoint
{
MT = ViewPoint.ReadMT(),
Aspect = ViewPoint.ReadNDouble("Aspect" ),
CameraApertureH = ViewPoint.ReadNDouble("CameraApertureH"),
CameraApertureW = ViewPoint.ReadNDouble("CameraApertureW"),
FOVHorizontal = ViewPoint.ReadNDouble("FOVHorizontal" ),
FocalLength = ViewPoint.ReadKey ("FocalLength" ),
FOV = ViewPoint.ReadKey ("FOV" ),
Roll = ViewPoint.ReadKey ("Roll" ),
};
Data.CameraRoot[i].ViewPoint = new ViewPoint
{
MT = ViewPoint.ReadMT(),
Aspect = ViewPoint.ReadNDouble("Aspect" ),
CameraApertureH = ViewPoint.ReadNDouble("CameraApertureH"),
CameraApertureW = ViewPoint.ReadNDouble("CameraApertureW"),
FOVHorizontal = ViewPoint.ReadNDouble("FOVHorizontal" ),
FocalLength = ViewPoint.ReadKey ("FocalLength" ),
FOV = ViewPoint.ReadKey ("FOV" ),
Roll = ViewPoint.ReadKey ("Roll" ),
};
}
}
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++)
if (Temp[i] is MsgPack Chara)
Data.Chara[i] = Chara.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];
for (i = 0; i < Data.Curve.Length; i++)
if (Temp[i] is MsgPack Curve)
Data.Curve[i] = new Curve
{
Name = Curve.ReadString("Name"),
CV = Curve.ReadKey ("CV" ),
};
Data.Curve[i] = new Curve
{
Name = Temp[i].ReadString("Name"),
CV = Temp[i].ReadKey ("CV" ),
};
}
if (A3D.Element("DOF", out Temp))
@@ -1446,237 +1442,221 @@ 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];
for (i = 0; i < Data.Event.Length; i++)
if (Temp[i] is MsgPack Event)
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" ),
};
Data.Event[i] = new Event
{
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];
for (i = 0; i < Data.Fog.Length; i++)
if (Temp[i] is MsgPack Fog)
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" ),
};
Data.Fog[i] = new Fog
{
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];
for (i = 0; i < Data.Light.Length; i++)
if (Temp[i] is MsgPack Light)
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"),
};
Data.Light[i] = new Light
{
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];
for (i = 0; i < Data.MaterialList.Length; i++)
if (Temp[i] is MsgPack Material)
Data.MaterialList[i] = new MaterialList
{
HashName = Material.ReadString ( "HashName"),
Name = Material.ReadString ( "Name"),
BlendColor = Material.ReadRGBAKey( "BlendColor"),
GlowIntensity = Material.ReadKey ("GlowIntensity"),
Incandescence = Material.ReadRGBAKey("Incandescence"),
};
Data.MaterialList[i] = new MaterialList
{
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];
for (i0 = 0; i0 < Data.MObjectHRC.Length; i0++)
if (Temp[i0] is MsgPack MObjectHRC)
{
Data.MObjectHRC[i0] = new MObjectHRC
{
Data.MObjectHRC[i0] = new MObjectHRC
MT = Temp[i].ReadMT(),
Name = Temp[i].ReadString("Name"),
};
if (Temp[i].Element("JointOrient", out MsgPack JointOrient))
Data.MObjectHRC[i0].JointOrient = new Vector3<double?>
{
MT = MObjectHRC.ReadMT(),
Name = MObjectHRC.ReadString("Name"),
X = JointOrient.ReadDouble("X"),
Y = JointOrient.ReadDouble("Y"),
Z = JointOrient.ReadDouble("Z"),
};
if (MObjectHRC.Element("JointOrient", out MsgPack JointOrient))
Data.MObjectHRC[i0].JointOrient = new Vector3<double?>
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++)
Data.MObjectHRC[i0].Instance[i1] = new Instance
{
X = JointOrient.ReadDouble("X"),
Y = JointOrient.ReadDouble("Y"),
Z = JointOrient.ReadDouble("Z"),
MT = Instance[i1].ReadMT(),
Name = Instance[i1].ReadString( "Name"),
Shadow = Instance[i1].ReadNInt32( "Shadow"),
UIDName = Instance[i1].ReadString("UIDName"),
};
}
if (MObjectHRC.Element<MsgPack>("Instance", out MsgPack Instance))
{
Data.MObjectHRC[i0].Instance = new Instance[Instance.Array.Length];
for (i1 = 0; i1 < Data.MObjectHRC[i0].Instance.Length; i1++)
if (Instance[i1] is MsgPack _Instance)
Data.MObjectHRC[i0].Instance[i1] = new Instance
{
MT = _Instance.ReadMT(),
Name = _Instance.ReadString( "Name"),
Shadow = _Instance.ReadNInt32( "Shadow"),
UIDName = _Instance.ReadString("UIDName"),
};
}
if (MObjectHRC.Element<MsgPack>("Node", out MsgPack Node))
{
Data.MObjectHRC[i0].Node = new Node[Temp.Array.Length];
for (i1 = 0; i1 < Data.MObjectHRC[i0].Node.Length; i1++)
if (Node[i1] is MsgPack _Node)
Data.MObjectHRC[i0].Node[i1] = new Node
{
MT = _Node.ReadMT(),
Name = _Node.ReadString( "Name"),
Parent = _Node.ReadNInt32("Parent"),
};
}
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++)
Data.MObjectHRC[i0].Node[i1] = new Node
{
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++)
if (Temp[i] is MsgPack MObjectHRC)
Data.MObjectHRCList[i] = MObjectHRC.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++)
if (Temp[i] is MsgPack Motion)
Data.Motion[i] = Motion.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];
for (i0 = 0; i0 < Data.Object.Length; i0++)
if (Temp[i0] is MsgPack Object)
{
Data.Object[i0] = new Object
{
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))
{
Data.Object[i0].TP = new Object.TexturePattern[TP.Array.Length];
for (i1 = 0; i1 < Data.Object[i0].TP.Length; i1++)
if (TP[i1] is MsgPack _TP)
Data.Object[i0].TP[i1] = new Object.TexturePattern
{
Name = _TP.ReadString("Name" ),
Pat = _TP.ReadString("Pat" ),
PatOffset = _TP.ReadNInt32("PatOffset"),
};
}
if (Object.Element<MsgPack>("TT", out MsgPack TT))
{
Data.Object[i0].TT = new Object.TextureTransform[TT.Array.Length];
for (i1 = 0; i1 < Data.Object[i0].TT.Length; i1++)
if (TT[i1] is MsgPack _TT)
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" ),
};
}
}
}
if (A3D.Element<MsgPack>("ObjectHRC", out Temp))
{
Data.ObjectHRC = new ObjectHRC[Temp.Array.Length];
for (i0 = 0; i0 < Data.ObjectHRC.Length; i0++)
if (Temp[i0] is MsgPack ObjectHRC)
if (Temp[i].ElementArray("TP", out MsgPack TP))
{
Data.ObjectHRC[i0] = new ObjectHRC
{
Name = ObjectHRC.ReadString ( "Name"),
Shadow = ObjectHRC.ReadNDouble( "Shadow"),
UIDName = ObjectHRC.ReadString ("UIDName"),
};
if (ObjectHRC.Element("JointOrient", out MsgPack JointOrient))
Data.ObjectHRC[i0].JointOrient = new Vector3<double?>
Data.Object[i0].TP = new Object.TexturePattern[TP.Array.Length];
for (i1 = 0; i1 < Data.Object[i0].TP.Length; i1++)
Data.Object[i0].TP[i1] = new Object.TexturePattern
{
X = JointOrient.ReadDouble("X"),
Y = JointOrient.ReadDouble("Y"),
Z = JointOrient.ReadDouble("Z"),
Name = TP[i1].ReadString("Name" ),
Pat = TP[i1].ReadString("Pat" ),
PatOffset = TP[i1].ReadNInt32("PatOffset"),
};
}
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++)
Data.Object[i0].TT[i1] = new Object.TextureTransform
{
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 (ObjectHRC.Element<MsgPack>("Node", out MsgPack Node))
{
Data.ObjectHRC[i0].Node = new Node[Node.Array.Length];
for (i1 = 0; i1 < Data.ObjectHRC[i0].Node.Length; i1++)
if (Node[i1] is MsgPack _Node)
Data.ObjectHRC[i0].Node[i1] = new Node
{
MT = _Node.ReadMT(),
Name = _Node.ReadString( "Name"),
Parent = _Node.ReadInt32 ("Parent"),
};
}
}
}
if (A3D.Element<MsgPack>("ObjectHRCList", out Temp))
if (A3D.ElementArray("ObjectHRC", out Temp))
{
Data.ObjectHRC = new ObjectHRC[Temp.Array.Length];
for (i0 = 0; i0 < Data.ObjectHRC.Length; i0++)
{
Data.ObjectHRC[i0] = new ObjectHRC
{
Name = Temp[i].ReadString ( "Name"),
Shadow = Temp[i].ReadNDouble( "Shadow"),
UIDName = Temp[i].ReadString ("UIDName"),
};
if (Temp[i].Element("JointOrient", out MsgPack JointOrient))
Data.ObjectHRC[i0].JointOrient = new Vector3<double?>
{
X = JointOrient.ReadDouble("X"),
Y = JointOrient.ReadDouble("Y"),
Z = JointOrient.ReadDouble("Z"),
};
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++)
Data.ObjectHRC[i0].Node[i1] = new Node
{
MT = Node[i1].ReadMT(),
Name = Node[i1].ReadString( "Name"),
Parent = Node[i1].ReadInt32 ("Parent"),
};
}
}
}
if (A3D.ElementArray("ObjectHRCList", out Temp))
{
Data.ObjectHRCList = new string[Temp.Array.Length];
for (i = 0; i < Data.ObjectHRCList.Length; i++)
if (Temp[i] is MsgPack ObjectHRC)
Data.ObjectHRCList[i] = ObjectHRC.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++)
if (Temp[i] is MsgPack Object)
Data.ObjectList[i] = Object.ReadString();
Data.ObjectList[i] = Temp[i].ReadString();
}
if (A3D.Element("PlayControl", out Temp))
@@ -1689,12 +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++)
if (Temp[i] is MsgPack Point)
Data.Point[i] = Point.ReadMT();
Data.Point[i] = Temp[i].ReadMT();
}
if (A3D.Element("PostProcess", out Temp))
@@ -1864,7 +1843,8 @@ namespace KKdMainLib.A3DA
if (Data.MObjectHRCList != null)
{
MsgPack MObjectHRCList = new MsgPack(Data.MObjectHRCList.Length, "MObjectHRCList");
for (i = 0; i < Data.MObjectHRCList.Length; i++) MObjectHRCList[i] = Data.MObjectHRCList[i];
for (i = 0; i < Data.MObjectHRCList.Length; i++)
MObjectHRCList[i] = (MsgPack)Data.MObjectHRCList[i];
A3D.Add(MObjectHRCList);
}
@@ -1884,7 +1864,7 @@ namespace KKdMainLib.A3DA
if (Data.Motion != null)
{
MsgPack Motion = new MsgPack(Data.Motion.Length, "Motion");
for (i = 0; i < Data.Motion.Length; i++) Motion[i] = Data.Motion[i];
for (i = 0; i < Data.Motion.Length; i++) Motion[i] = (MsgPack)Data.Motion[i];
A3D.Add(Motion);
}
@@ -1958,14 +1938,14 @@ namespace KKdMainLib.A3DA
if (Data.ObjectHRCList != null)
{
MsgPack ObjectHRCList = new MsgPack(Data.ObjectHRCList.Length, "ObjectHRCList");
for (i = 0; i < Data.ObjectHRCList.Length; i++) ObjectHRCList[i] = Data.ObjectHRCList[i];
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(Data.ObjectList.Length, "ObjectList");
for (i = 0; i < Data.ObjectList.Length; i++) ObjectList[i] = Data.ObjectList[i];
for (i = 0; i < Data.ObjectList.Length; i++) ObjectList[i] = (MsgPack)Data.ObjectList[i];
A3D.Add(ObjectList);
}
@@ -2109,9 +2089,9 @@ namespace KKdMainLib.A3DA
public double? EPTypePost;
public double? EPTypePre;
public RawD RawData;
public KeyFrame<double, double>[] Trans;
public IKeyFrame<double, double>[] Trans;
public class RawD
public struct RawD
{
public int? KeyType;
public int? ValueListSize;
+69 -72
View File
@@ -62,7 +62,7 @@ namespace KKdMainLib.A3DA
if (Key.Length != null)
{
int Type;
Key.Trans = new KeyFrame<double, double>[(int)Key.Length];
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"))
{
@@ -84,7 +84,6 @@ namespace KKdMainLib.A3DA
}
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(',');
@@ -93,29 +92,29 @@ namespace KKdMainLib.A3DA
int DS = (int)Key.RawData.KeyType + 1;
Key.Length = Key.RawData.ValueListSize / DS;
Key.Trans = new KeyFrame<double, double>[(int)Key.Length];
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() };
{ 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 = dataArray[i * DS + 1].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 = dataArray[i * DS + 1].ToDouble(),
Interpolation = dataArray[i * DS + 2].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 = dataArray[i * DS + 1].ToDouble(),
Interpolation1 = dataArray[i * DS + 2].ToDouble(),
Interpolation2 = dataArray[i * DS + 3].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;
@@ -174,7 +173,7 @@ 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++)
@@ -199,18 +198,29 @@ namespace KKdMainLib.A3DA
if (Key.Max != null) IO.Write(Temp + "max=", Key.Max);
for (i = 0; i < Key.Trans.Length; i++)
{
if (Key.Trans[SOi] is KeyFrameT0<double, double> &&
if (Key.Trans[i] is KeyFrameT0<double, double> &&
Key.RawData.KeyType < 0) Key.RawData.KeyType = 0;
else if (Key.Trans[SOi] is KeyFrameT1<double, double> &&
else if (Key.Trans[i] is KeyFrameT1<double, double> &&
Key.RawData.KeyType < 1) Key.RawData.KeyType = 1;
else if (Key.Trans[SOi] is KeyFrameT2<double, double> &&
else if (Key.Trans[i] is KeyFrameT2<double, double> &&
Key.RawData.KeyType < 2) Key.RawData.KeyType = 2;
else if (Key.Trans[SOi] is KeyFrameT3<double, double> &&
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);
@@ -218,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);
}
@@ -263,7 +273,7 @@ namespace KKdMainLib.A3DA
Key.Max = IO.ReadSingle();
Key.Length = IO.ReadInt32 ();
Key.Trans = new KeyFrame<double, double>[(int)Key.Length];
Key.Trans = new IKeyFrame<double, double>[(int)Key.Length];
KeyFrameT3<double, double> Temp;
for (int i = 0; i < Key.Length; i++)
{
@@ -349,58 +359,45 @@ namespace KKdMainLib.A3DA
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 KeyFrame<double, double>[Key.Length.Value];
Key.Trans = new IKeyFrame<double, double>[Key.Length.Value];
for (int i = 0; i < Key.Length; i++)
if (Trans[i] is MsgPack _Trans)
{
if (_Trans.Array == null) continue;
else if (_Trans.Array.Length == 0) continue;
else if (_Trans.Array.Length == 1)
{
if (Trans[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>
{
if (_Trans[0] is MsgPack Frame)
Key.Trans[i] = new KeyFrameT0<double, double> { Frame = Frame.ReadDouble() };
}
else if (_Trans.Array.Length == 2)
Frame = Trans[i][0].ReadDouble(),
Value = Trans[i][1].ReadDouble(),
};
else if (Trans[i].Array.Length == 3)
Key.Trans[i] = new KeyFrameT2<double, double>
{
KeyFrameT1<double, double> KeyFrameT1 = new KeyFrameT1<double, double>();
if (_Trans[0] is MsgPack Frame) KeyFrameT1.Frame = Frame.ReadDouble();
if (_Trans[1] is MsgPack Value) KeyFrameT1.Value = Value.ReadDouble();
Key.Trans[i] = KeyFrameT1;
}
else if (_Trans.Array.Length == 3)
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>
{
KeyFrameT2<double, double> KeyFrameT2 = new KeyFrameT2<double, double>();
if (_Trans[0] is MsgPack Frame )
KeyFrameT2.Frame = Frame .ReadDouble();
if (_Trans[1] is MsgPack Value )
KeyFrameT2.Value = Value .ReadDouble();
if (_Trans[2] is MsgPack Interpolation)
KeyFrameT2.Interpolation = Interpolation.ReadDouble();
Key.Trans[i] = KeyFrameT2;
}
else if (_Trans.Array.Length == 4)
{
KeyFrameT3<double, double> KeyFrameT3 = new KeyFrameT3<double, double>();
if (_Trans[0] is MsgPack Frame )
KeyFrameT3.Frame = Frame .ReadDouble();
if (_Trans[1] is MsgPack Value )
KeyFrameT3.Value = Value .ReadDouble();
if (_Trans[2] is MsgPack Interpolation1)
KeyFrameT3.Interpolation1 = Interpolation1.ReadDouble();
if (_Trans[3] is MsgPack Interpolation2)
KeyFrameT3.Interpolation2 = Interpolation2.ReadDouble();
Key.Trans[i] = KeyFrameT3;
}
Key.Trans[i] = Key.Trans[i].Check();
}
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;
}
@@ -435,9 +432,9 @@ namespace KKdMainLib.A3DA
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);
if (Key.RawData.KeyType != null) Keys.Add("RD", true);
MsgPack Trans = new MsgPack(Key.Trans.Length, "Trans");
MsgPack K;
@@ -445,31 +442,31 @@ namespace KKdMainLib.A3DA
if (Key.Trans[i] is KeyFrameT0<double, double> KeyFrameT0)
{
K = new MsgPack(1);
K[0] = KeyFrameT0.Frame;
K[0] = (MsgPack)KeyFrameT0.Frame;
Trans[i] = K;
}
else if (Key.Trans[i] is KeyFrameT1<double, double> KeyFrameT1)
{
K = new MsgPack(2);
K[0] = KeyFrameT1.Frame;
K[1] = KeyFrameT1.Value;
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] = KeyFrameT2.Frame;
K[1] = KeyFrameT2.Value;
K[2] = KeyFrameT2.Interpolation;
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] = KeyFrameT3.Frame;
K[1] = KeyFrameT3.Value;
K[2] = KeyFrameT3.Interpolation1;
K[3] = KeyFrameT3.Interpolation2;
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);
+445 -483
View File
File diff suppressed because it is too large Load Diff
+138 -185
View File
@@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using KKdMainLib.IO;
using KKdMainLib.IO;
using KKdMainLib.Types;
using KKdMainLib.MessagePack;
@@ -9,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() };
@@ -41,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 Add(this MsgPack MsgPack, string Name, CountPointer<float> val)
{
if (val.Count == 1) return MsgPack.Add(new MsgPack(Name, val.Entries[0]));
if (val.Count == 1) return MsgPack.Add(new MsgPack(Name, val[0]));
else if (val.Count > 1)
{
MsgPack Val = new MsgPack(val.Count, Name);
for (int i = 0; i < val.Count; i++) Val[i] = val.Entries[i];
for (int i = 0; i < val.Count; i++) Val[i] = (MsgPack)val[i];
return MsgPack.Add(Val);
}
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();
@@ -93,42 +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)
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)
{
Anim.Eff.Value.Marker.Offset = IO.Position;
for (int i = 0; i < Anim.Eff.Value.Marker.Count; i++) IO.Write(0L);
Eff.Marker.Offset = IO.Position;
for (int i = 0; i < Eff.Marker.Count; i++) IO.Write(0L);
}
IO.Write(ref Anim.Eff.Value.Data, ref NullValPointers);
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,7 +201,7 @@ namespace KKdMainLib.Aet
IO.Write(Anim.Unk1);
IO.Write(Anim.Unk2);
IO.Write((byte)Anim.Type);
if (Anim.Type == ObjType.Pic)
if (Anim.Type == AetObject.ObjType.Pic)
{
Anim.Pic.Offset = IO.Position;
IO.Write(0L);
@@ -151,7 +214,7 @@ namespace KKdMainLib.Aet
IO.Write(Anim.Pic.Value.Data .Offset);
IO.Write(0);
}
else if (Anim.Type == ObjType.Aif)
else if (Anim.Type == AetObject.ObjType.Aif)
{
Anim.Aif.Offset = IO.Position;
IO.Write(Anim.Aif.Value.Value.Offset);
@@ -159,7 +222,7 @@ namespace KKdMainLib.Aet
IO.Write(0L);
IO.Write(Anim.Aif.Value.Pointer);
}
else if (Anim.Type == ObjType.Eff)
else if (Anim.Type == AetObject.ObjType.Eff)
{
Anim.Eff.Offset = IO.Position;
IO.Write(0L);
@@ -175,122 +238,11 @@ namespace KKdMainLib.Aet
else { IO.Write(0L); IO.Write(0L); IO.Write(0L); }
}
public static Pointer<Pic> ReadPic(this Stream IO, ref Dictionary<int, AetObject> ObjectsDict)
{
Pointer<Pic> Pic = new Pointer<Pic> { Offset = IO.Position,
Value = new Pic
{
SpriteEntryID = IO.ReadInt32(),
ParentObjectID = IO.ReadInt32(),
Marker = IO.ReadCountPointer<Marker>()
}
};
Pic.Value.Data.Offset = IO.ReadInt32();
IO.ReadAnimData(ref Pic.Value.Data);
IO.Position = Pic.Value.Marker.Offset;
for (int i = 0; i < Pic.Value.Marker.Count; i++)
{
Pic.Value.Marker.Entries[i].Frame = IO.ReadSingle();
Pic.Value.Marker.Entries[i]. Name = IO.ReadPointerStringShiftJIS();
}
return Pic;
}
public static Pointer<Aif> ReadAif(this Stream IO)
{
Pointer<Aif> Aif = new Pointer<Aif> { Offset = IO.Position,
Value = new Aif
{
Value = IO.ReadPointer<int>(),
Zero0 = IO.ReadInt32(),
Zero1 = IO.ReadInt32(),
Zero2 = IO.ReadInt32(),
Zero3 = IO.ReadInt32(),
Pointer = IO.ReadInt32(),
}
};
IO.Position = Aif.Value.Value.Offset;
Aif.Value.Value.Value = IO.ReadInt32();
IO.Position = Aif.Value.Pointer;
Aif.Value.Unk0 = IO.ReadCountPointer<float>();
Aif.Value.Unk1 = IO.ReadCountPointer<float>();
Aif.Value.Unk2 = IO.ReadCountPointer<float>();
Aif.Value.Unk3 = IO.ReadCountPointer<float>();
IO.Position = Aif.Value.Unk0.Offset;
for (int i = 0; i < Aif.Value.Unk0.Count; i++) Aif.Value.Unk0.Entries[i] = IO.ReadSingle();
IO.Position = Aif.Value.Unk1.Offset;
for (int i = 0; i < Aif.Value.Unk1.Count; i++) Aif.Value.Unk1.Entries[i] = IO.ReadSingle();
IO.Position = Aif.Value.Unk2.Offset;
for (int i = 0; i < Aif.Value.Unk2.Count; i++) Aif.Value.Unk2.Entries[i] = IO.ReadSingle();
IO.Position = Aif.Value.Unk3.Offset;
for (int i = 0; i < Aif.Value.Unk3.Count; i++) Aif.Value.Unk3.Entries[i] = IO.ReadSingle();
return Aif;
}
public static void Write(this Stream IO, ref Pointer<Aif> Aif)
{
if (Aif.Value.Unk0.Count > 0) { Aif.Value.Unk0.Offset = IO.Position;
for (int i = 0; i < Aif.Value.Unk0.Count; i++) IO.Write(Aif.Value.Unk0.Entries[i]); }
if (Aif.Value.Unk1.Count > 0) { Aif.Value.Unk1.Offset = IO.Position;
for (int i = 0; i < Aif.Value.Unk1.Count; i++) IO.Write(Aif.Value.Unk1.Entries[i]); }
if (Aif.Value.Unk2.Count > 0) { Aif.Value.Unk2.Offset = IO.Position;
for (int i = 0; i < Aif.Value.Unk2.Count; i++) IO.Write(Aif.Value.Unk2.Entries[i]); }
if (Aif.Value.Unk3.Count > 0) { Aif.Value.Unk3.Offset = IO.Position;
for (int i = 0; i < Aif.Value.Unk3.Count; i++) IO.Write(Aif.Value.Unk3.Entries[i]); }
IO.Align(0x10);
Aif.Value.Value.Offset = IO.Position;
IO.Write(Aif.Value.Value.Value);
IO.Align(0x10);
Aif.Value.Pointer = IO.Position;
if (Aif.Value.Unk0.Count > 0) { IO.Write(Aif.Value.Unk0.Count); IO.Write(Aif.Value.Unk0.Offset); }
else IO.Write(0L);
if (Aif.Value.Unk1.Count > 0) { IO.Write(Aif.Value.Unk1.Count); IO.Write(Aif.Value.Unk1.Offset); }
else IO.Write(0L);
if (Aif.Value.Unk2.Count > 0) { IO.Write(Aif.Value.Unk2.Count); IO.Write(Aif.Value.Unk2.Offset); }
else IO.Write(0L);
if (Aif.Value.Unk3.Count > 0) { IO.Write(Aif.Value.Unk3.Count); IO.Write(Aif.Value.Unk3.Offset); }
else IO.Write(0L);
}
public static Pointer<Eff> ReadEff(this Stream IO, ref Dictionary<int, AetObject> ObjectsDict)
{
Pointer<Eff> Eff = new Pointer<Eff> { Offset = IO.Position,
Value = new Eff
{
LayerID = IO.ReadInt32(),
ParentObjectID = IO.ReadInt32(),
Marker = IO.ReadCountPointer<Marker>()
}
};
Eff.Value.Data.Offset = IO.ReadInt32();
IO.Position = Eff.Value.LayerID;
CountPointer<AetObject> AetObjEntry = IO.ReadCountPointer<AetObject>();
IO.Position = AetObjEntry.Offset;
for (int i = 0; i < AetObjEntry.Count; i++) IO.ReadAetObject(ref ObjectsDict);
IO.Position = Eff.Value.Marker.Offset;
for (int i = 0; i < Eff.Value.Marker.Count; i++)
{
Eff.Value.Marker.Entries[i].Frame = IO.ReadSingle();
Eff.Value.Marker.Entries[i]. Name = IO.ReadPointerStringShiftJIS();
}
IO.ReadAnimData(ref Eff.Value.Data);
return Eff;
}
public static void ReadAnimData(this Stream IO, ref Pointer<AnimationData> Anim)
{
ref AnimationData Data = ref Anim.Value;
IO.Position = Anim.Offset;
Data.BlendMode = (BlendMode)IO.ReadByte();
Data.Mode = (AnimationData.BlendMode)IO.ReadByte();
Data.Unk0 = IO.ReadByte();
Data.UseTextureMask = IO.ReadBoolean();
Data.Unk1 = IO.ReadByte();
@@ -336,7 +288,7 @@ namespace KKdMainLib.Aet
}
}
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;
@@ -372,7 +324,7 @@ namespace KKdMainLib.Aet
IO.Align(0x20);
Anim.Offset = IO.Position;
IO.WriteByte((byte) Data.BlendMode);
IO.WriteByte((byte) Data.Mode);
IO.WriteByte( Data.Unk0);
IO.WriteByte((byte)(Data.UseTextureMask ? 1 : 0));
IO.WriteByte( Data.Unk1);
@@ -381,7 +333,8 @@ namespace KKdMainLib.Aet
IO.Write(Data._3D.Offset > -1 ? Data._3D.Offset : 0);
}
public static void Write(this Stream IO, ref AnimationData Data, ref List<int> NullValPointers, int Flags)
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);
@@ -409,7 +362,8 @@ namespace KKdMainLib.Aet
IO.Write(Data.Opacity .Offset);
}
public static void Write(this Stream IO, ref AnimationData3D Data, ref List<int> NullValPointers, int Flags)
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);
@@ -476,17 +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++)
if (Markers[i] is MsgPack marker)
mark.Entries[i].ReadMP(marker);
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
+4 -6
View File
@@ -192,12 +192,11 @@ 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++)
if (AetDB[i] is MsgPack Aet)
AetSets[i].ReadMsgPack(Aet);
AetSets[i].ReadMsgPack(AetDB[i]);
}
MsgPack = MsgPack.New;
}
@@ -247,12 +246,11 @@ namespace KKdMainLib.DB
NewId = msg.ReadBoolean("NewId" );
SpriteSetId = msg.ReadNUInt16("SpriteSetId");
if (msg.Element<MsgPack>("Aets", out MsgPack Aets))
if (msg.ElementArray("Aets", out MsgPack Aets))
{
this.Aets = new AET[Aets.Array.Length];
for (int i0 = 0; i0 < this.Aets.Length; i0++)
if (Aets[i0] is MsgPack Aet)
this.Aets[i0].ReadMsgPack(Aet);
this.Aets[i0].ReadMsgPack(Aets[i0]);
}
}
+10 -12
View File
@@ -103,25 +103,23 @@ namespace KKdMainLib.DB
if (MsgPack.Element("AuthDB", out MsgPack AuthDB))
{
if (AuthDB.Element<MsgPack>("Category", out MsgPack Temp))
if (AuthDB.ElementArray("Category", out MsgPack Temp))
{
Category = new string[Temp.Array.Length];
for (int i = 0; i < Category.Length; i++)
if (Temp is MsgPack Category)
this.Category[i] = Category.ReadString();
Category[i] = Temp[i].ReadString();
}
if (AuthDB.Element<MsgPack>("UID", out Temp))
if (AuthDB.ElementArray("UID", out Temp))
{
_UID = new UID[Temp.Array.Length];
for (int i = 0; i < _UID.Length; i++)
if (Temp[i] is MsgPack UID)
{
_UID[i].Category = UID.ReadString("C");
_UID[i].OrgUid = UID.ReadNInt32("O");
_UID[i].Size = UID.ReadNInt32("S");
_UID[i].Value = UID.ReadString("V");
}
{
_UID[i].Category = Temp[i].ReadString("C");
_UID[i].OrgUid = Temp[i].ReadNInt32("O");
_UID[i].Size = Temp[i].ReadNInt32("S");
_UID[i].Value = Temp[i].ReadString("V");
}
}
}
MsgPack = MsgPack.New;
@@ -134,7 +132,7 @@ namespace KKdMainLib.DB
{
MsgPack Category = new MsgPack(this.Category.Length, "Category");
for (int i = 0; i < this.Category.Length; i++)
Category[i] = this.Category[i];
Category[i] = (MsgPack)this.Category[i];
AuthDB.Add(Category);
}
+8 -11
View File
@@ -249,12 +249,11 @@ 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++)
if (SprDB[i] is MsgPack Spr)
SpriteSets[i].ReadMsgPack(Spr);
SpriteSets[i].ReadMsgPack(SprDB[i]);
}
MsgPack = MsgPack.New;
}
@@ -301,20 +300,18 @@ namespace KKdMainLib.DB
Name = msg.ReadString ("Name" );
NewId = msg.ReadBoolean("NewId" );
if (msg.Element<MsgPack>( "Sprites", out MsgPack Sprites))
if (msg.ElementArray( "Sprites", out MsgPack Sprites))
{
this .Sprites = new SpriteTexture[Sprites.Array.Length];
this.Sprites = new SpriteTexture[Sprites.Array.Length];
for (int i0 = 0; i0 < this.Sprites.Length; i0++)
if (Sprites[i0] is MsgPack Sprite)
this.Sprites[i0].ReadMsgPack(Sprite);
this.Sprites[i0].ReadMsgPack(Sprites[i0]);
}
if (msg.Element<MsgPack>("Textures", out MsgPack Textures))
if (msg.ElementArray("Textures", out MsgPack Textures))
{
this .Textures = new SpriteTexture[Textures.Array.Length];
this.Textures = new SpriteTexture[Textures.Array.Length];
for (int i0 = 0; i0 < this.Textures.Length; i0++)
if (Textures[i0] is MsgPack Texture)
this.Textures[i0].ReadMsgPack(Texture);
this.Textures[i0].ReadMsgPack(Textures[i0]);
}
}
+15 -18
View File
@@ -197,29 +197,26 @@ namespace KKdMainLib
Header = new PDHead();
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
if (!MsgPack.Element<MsgPack>("Dex", out MsgPack Dex)) return;
if (!MsgPack.ElementArray("Dex", out MsgPack Dex)) return;
this.Dex = new EXP[Dex.Array.Length];
for (i0 = 0; i0 < this.Dex.Length; i0++)
if (Dex[i0] is MsgPack EXP)
{
this.Dex[i0] = new EXP { Name = EXP.ReadString("Name") };
{
this.Dex[i0] = new EXP { Name = Dex[i0].ReadString("Name") };
if (EXP.Element<MsgPack>("Main", out MsgPack Main))
{
this.Dex[i0].Main = new List<EXPElement>();
for (i1 = 0; i1 < Main.Array.Length; i1++)
if (Main[i1] is MsgPack Exp)
this.Dex[i0].Main.Add(ReadEXP(Exp));
}
if (EXP.Element<MsgPack>("Eyes", out MsgPack Eyes))
{
this.Dex[i0].Eyes = new List<EXPElement>();
for (i1 = 0; i1 < Eyes.Array.Length; i1++)
if (Eyes[i1] is MsgPack Exp)
this.Dex[i0].Eyes.Add(ReadEXP(Exp));
}
if (Dex[i0].ElementArray("Main", out MsgPack Main))
{
this.Dex[i0].Main = new List<EXPElement>();
for (i1 = 0; i1 < Main.Array.Length; i1++)
this.Dex[i0].Main.Add(ReadEXP(Main[i1]));
}
if (Dex[i0].ElementArray("Eyes", out MsgPack Eyes))
{
this.Dex[i0].Eyes = new List<EXPElement>();
for (i1 = 0; i1 < Eyes.Array.Length; i1++)
this.Dex[i0].Eyes.Add(ReadEXP(Eyes[i1]));
}
}
MsgPack = MsgPack.New;
}
+4 -4
View File
@@ -70,18 +70,18 @@ namespace KKdMainLib
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
bool compact = MsgPack.ReadBoolean("Compact");
if (file.Contains("psrData") && MsgPack.Element<MsgPack>("psrData", out MsgPack psrData))
if (file.Contains("psrData") && MsgPack.ElementArray("psrData", out MsgPack psrData))
{
psrDat = new psrData[psrData.Array.Length];
for (i = 0; i < psrDat.Length; i++)
psrDat[i].SetValue((MsgPack)psrData[i]);
psrDat[i].SetValue(psrData[i]);
Success = true;
}
else if (file.Contains("PvList") && MsgPack.Element<MsgPack>("PvList", out MsgPack PvList))
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 = MsgPack.New;
+22 -11
View File
@@ -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)); }
+1 -1
View File
@@ -52,7 +52,7 @@
<Compile Include="MessagePack\MsgPack.cs" />
<Compile Include="MessagePack\IO.cs" />
<Compile Include="Types\Half.cs" />
<Compile Include="Types\KeyFrame.cs" />
<Compile Include="Types\IKeyFrame.cs" />
<Compile Include="Types\KKdList.cs" />
<Compile Include="Types\Pointer.cs" />
<Compile Include="Types\Vector.cs" />
+2 -2
View File
@@ -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; }
+10 -11
View File
@@ -13,6 +13,8 @@ namespace KKdMainLib.MessagePack
public void Close() => _IO.Close();
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
public MsgPack Read(bool Array = false)
{
MsgPack MsgPack = MsgPack.New;
@@ -33,12 +35,12 @@ namespace KKdMainLib.MessagePack
{
if (FixMap)
{
MsgPack.Object = KKdList<object>.New;
MsgPack.Object = KKdList<MsgPack>.New;
for (int i = 0; i < Unk - (byte)Types.FixMap; i++) MsgPack.Add( Read(false));
}
else if (FixArr)
{
MsgPack.Object = new object[Unk - (byte)Types.FixArr];
MsgPack.Object = new MsgPack[Unk - (byte)Types.FixArr];
for (int i = 0; i < Unk - (byte)Types.FixArr; i++) MsgPack[i] = Read( true);
}
else if (FixStr) MsgPack.Object = ReadString( Type);
@@ -148,7 +150,7 @@ namespace KKdMainLib.MessagePack
if (Type == Types.Arr16) Length = _IO.ReadInt16Endian(true);
else if (Type == Types.Arr32) Length = _IO.ReadInt32Endian(true);
else return false;
MsgPack.Object = new object[Length];
MsgPack.Object = new MsgPack[Length];
for (int i = 0; i < Length; i++) MsgPack[i] = Read(true);
return true;
}
@@ -159,7 +161,7 @@ namespace KKdMainLib.MessagePack
if (Type == Types.Map16) Length = _IO.ReadInt16Endian(true);
else if (Type == Types.Map32) Length = _IO.ReadInt32Endian(true);
else return false;
MsgPack.Object = KKdList<object>.New;
MsgPack.Object = KKdList<MsgPack>.New;
for (int i = 0; i < Length; i++) MsgPack.Add(Read());
return true;
}
@@ -179,13 +181,10 @@ namespace KKdMainLib.MessagePack
MsgPack.Object = new MsgPack.Ext { Type = _IO.ReadSByte(), Data = _IO.ReadBytes(Length) };
return true;
}
public IO Write(MsgPack MsgPack, bool Close)
{ Write(MsgPack); if (Close) this.Close(); return this; }
public IO Write(MsgPack MsgPack)
public IO Write(MsgPack MsgPack, bool IsArray = false)
{
if (MsgPack.Name != null) Write(MsgPack.Name);
if (MsgPack.Name != null && !IsArray) Write(MsgPack.Name);
Write(MsgPack.Object);
return this;
}
@@ -195,9 +194,9 @@ namespace KKdMainLib.MessagePack
if (obj == null) { WriteNil(); return; }
switch (obj)
{
case KKdList<object> val: WriteMap(val.Count );
case KKdList<MsgPack> val: WriteMap(val.Count );
for (int i = 0; i < val.Count ; i++) Write(val[i]); break;
case object[] val: WriteArr(val.Length);
case MsgPack[] val: WriteArr(val.Length);
for (int i = 0; i < val.Length; i++) Write(val[i]); break;
case MsgPack val: Write(val); break;
case byte[] val: Write(val); break;
+36 -21
View File
@@ -1,6 +1,5 @@
//Original or reader part: https://github.com/MarcosLopezC/LightJson/
using System;
using KKdMainLib.IO;
using KKdMainLib.Types;
@@ -15,6 +14,8 @@ 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();
@@ -80,11 +81,11 @@ namespace KKdMainLib.MessagePack
private int ReadHexDigit() => byte.Parse(_IO.ReadCharUTF8().ToString(),
System.Globalization.NumberStyles.HexNumber);
private KKdList<object> ReadObject()
private KKdList<MsgPack> ReadObject()
{
KKdList<object> Obj = KKdList<object>.New;
if (!_IO.Assert('{')) return KKdList<object>.Null;
if (_IO.SkipWhitespace().PeekCharUTF8() == '}') { _IO.ReadCharUTF8(); return KKdList<object>.Null; }
KKdList<MsgPack> Obj = KKdList<MsgPack>.New;
if (!_IO.Assert('{')) return KKdList<MsgPack>.Null;
if (_IO.SkipWhitespace().PeekCharUTF8() == '}') { _IO.ReadCharUTF8(); return KKdList<MsgPack>.Null; }
string key;
char c;
@@ -94,22 +95,22 @@ namespace KKdMainLib.MessagePack
key = ReadString();
if (!_IO.SkipWhitespace().Assert(':'))
return KKdList<object>.Null;
return KKdList<MsgPack>.Null;
Obj.Add(ReadValue(key));
c = _IO.SkipWhitespace().PeekCharUTF8();
if (c == '}') { _IO.ReadCharUTF8(); break; }
else if (c == ',') { _IO.ReadCharUTF8(); continue; }
else return KKdList<object>.Null;
else return KKdList<MsgPack>.Null;
}
return Obj;
}
private object[] ReadArray()
private MsgPack[] ReadArray()
{
KKdList<object> Obj = KKdList<object>.New;
KKdList<MsgPack> Obj = KKdList<MsgPack>.New;
if (!_IO.Assert('[')) return null;
if (_IO.SkipWhitespace().PeekCharUTF8() == ']') { _IO.ReadCharUTF8(); return null; }
@@ -172,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.NotNull)
{
WriteMap();
if (Style) _IO.Write(End);
for (int i = 0; i < MsgPack.List.Count; i++)
if (MsgPack.List.Count > 1)
for (int i = 0; i < MsgPack.List.Count; i++)
{
if (Style) _IO.Write(Tab);
Write(MsgPack.List[i], End, TabChar, Tab, Style);
if (i + 1 < MsgPack.List.Count) _IO.Write(',');
if (Style) _IO.Write(End);
}
else if (MsgPack.List.Count == 1)
{
if (Style) _IO.Write(Tab);
Write(MsgPack.List[i], End, TabChar, Tab, Style);
if (i + 1 < MsgPack.List. Count) _IO.Write(',');
Write(MsgPack.List[0], End, TabChar, Tab, Style);
if (Style) _IO.Write(End);
}
if (Style) _IO.Write(OldTab);
@@ -203,11 +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);
+4 -4
View File
@@ -36,10 +36,10 @@ namespace KKdMainLib.MessagePack
{
if (JSON)
{ JSONIO IO = new JSONIO(File.OpenWriter(file + ".json", true));
IO.Write(mp, true, "\n", " "); IO = null; }
IO.Write(mp, "\n", " ").Close(); IO = null; }
else
{ MPIO IO = new MPIO(File.OpenWriter(file + ".mp" , true));
IO.Write(mp, true ); IO = null; }
IO.Write(mp ).Close(); IO = null; }
return mp;
}
@@ -52,10 +52,10 @@ namespace KKdMainLib.MessagePack
byte[] data = null;
if (JSON)
{ JSONIO IO = new JSONIO(File.OpenWriter());
IO.Write(mp, false, true); data = IO._IO.ToArray(true); }
IO.Write(mp, true); data = IO.ToArray(true); }
else
{ MPIO IO = new MPIO(File.OpenWriter());
IO.Write(mp, false ); data = IO._IO.ToArray(true); }
IO.Write(mp ); data = IO.ToArray(true); }
File.WriteAllBytes(file + (JSON ? ".json" : ".mp"), data);
return mp;
}
+151 -148
View File
@@ -3,25 +3,25 @@ using KKdMainLib.Types;
namespace KKdMainLib.MessagePack
{
public struct MsgPack : IDisposable
public struct MsgPack : IDisposable, IEquatable<MsgPack>
{
public string Name;
public object Object;
public object[] Array => Object is object[] List ?
public MsgPack[] Array => Object is MsgPack[] List ?
List : null;
public KKdList<object> List => Object is KKdList<object> List ?
List : default(KKdList<object>);
public KKdList<MsgPack> List => Object is KKdList<MsgPack> List ?
List : default(KKdList<MsgPack>);
public static MsgPack New => new MsgPack { Object = KKdList<object>.New };
public static MsgPack New => new MsgPack { Object = KKdList<MsgPack>.New };
public static MsgPack NewReserve(int Capacity) =>
new MsgPack { Object = KKdList<object>.NewReserve(Capacity) };
new MsgPack { Object = KKdList<MsgPack>.NewReserve(Capacity) };
public MsgPack( string Name = null)
{ Object = KKdList<object>.New; this.Name = Name; }
{ Object = KKdList<MsgPack>.New; this.Name = Name; }
public MsgPack(long Count, string Name = null)
{ if (Count > 0) { Object = new object[Count]; }
{ if (Count > 0) { Object = new MsgPack[Count]; }
else Object = null; this.Name = Name; }
public MsgPack(string Name, object Object)
@@ -29,65 +29,75 @@ namespace KKdMainLib.MessagePack
public static MsgPack Null => new MsgPack();
public object this[int index]
{ get { if (Object is object[] Array) return Array[index]; return null; }
set { if (Object is object[] Array) { Array[index] = value; Object = Array; }} }
public MsgPack this[int index]
{ get { 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 && Object is KKdList<object> List)
{ List.Add(obj); Object = List; } return this; }
public MsgPack Add(MsgPack obj)
{ if (Object is KKdList<MsgPack> List) { List.Add(obj); Object = List; } return this; }
public void Dispose()
{ Name = null; Object = null; }
public MsgPack Add( sbyte? val) => Add(null, val);
public MsgPack Add( byte? val) => Add(null, val);
public MsgPack Add( short? val) => Add(null, val);
public MsgPack Add(ushort? val) => Add(null, val);
public MsgPack Add( int? val) => Add(null, val);
public MsgPack Add( uint? val) => Add(null, val);
public MsgPack Add( long? val) => Add(null, val);
public MsgPack Add( ulong? val) => Add(null, val);
public MsgPack Add( float? val) => Add(null, val);
public MsgPack Add(double? val) => Add(null, val);
public bool Equals(MsgPack msg) =>
Name == msg.Name && Object == msg.Object;
public override string ToString() => Name ?? "" +
(List. NotNull ? ((Name != null ? " " : "") + "Elements Count: " + List .Count ) :
(Array != null ? ((Name != null ? " " : "") + "Elements Count: " + Array.Length) : Object.ToString()));
public 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(Val, ( sbyte)val); return this; }
public MsgPack Add(string Val, byte? val)
{ if (val != null) Add(Val, ( byte)val); return this; }
public MsgPack Add(string Val, short? val)
{ if (val != null) Add(Val, ( short)val); return this; }
public MsgPack Add(string Val, ushort? val)
{ if (val != null) Add(Val, (ushort)val); return this; }
public MsgPack Add(string Val, int? val)
{ if (val != null) Add(Val, ( int)val); return this; }
public MsgPack Add(string Val, uint? val)
{ if (val != null) Add(Val, ( uint)val); return this; }
public MsgPack Add(string Val, long? val)
{ if (val != null) Add(Val, ( long)val); return this; }
public MsgPack Add(string Val, ulong? val)
{ if (val != null) Add(Val, ( ulong)val); return this; }
public MsgPack Add(string Val, float? val)
{ if (val != null) Add(Val, ( float)val); return this; }
public MsgPack Add(string Val, double? val)
{ if (val != null) Add(Val, (double)val); return this; }
public MsgPack Add(string Val, byte[] val) => 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) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, string val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, bool val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, sbyte val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, byte val) => Add(new MsgPack(Val, val));
@@ -112,30 +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();
@@ -150,55 +160,55 @@ namespace KKdMainLib.MessagePack
public double ReadDouble() => ReadNDouble().GetValueOrDefault();
public bool? ReadNBoolean()
{ if (Object is bool Boolean) return Boolean; return null; }
{ if (Object is bool Boolean) return Boolean; return null; }
public sbyte? ReadNInt8()
{ if (Object is sbyte Int8 ) return Int8;
else if (Object is byte UInt8 ) return (sbyte)UInt8; return null; }
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return ( sbyte) UInt8 ; return null; }
public byte? ReadNUInt8()
{ if (Object is sbyte Int8 ) return (byte) Int8;
else if (Object is byte UInt8 ) return UInt8; return null; }
{ if (Object is sbyte Int8 ) return ( byte) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ; return null; }
public short? ReadNInt16()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return (short)UInt16; return null; }
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return ( short) UInt16; return null; }
public ushort? ReadNUInt16()
{ if (Object is sbyte Int8 ) return (ushort) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return (ushort) Int16;
else if (Object is ushort UInt16) return UInt16; return null; }
{ if (Object is sbyte Int8 ) return (ushort) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return (ushort) Int16;
else if (Object is ushort UInt16) return UInt16; return null; }
public int? ReadNInt32()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return (int)UInt32; return null; }
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return ( int) UInt32; return null; }
public uint? ReadNUInt32()
{ if (Object is sbyte Int8 ) return (uint) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return (uint) Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return (uint) Int32;
else if (Object is uint UInt32) return UInt32; return null; }
{ if (Object is sbyte Int8 ) return ( uint) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return ( uint) Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return ( uint) Int32;
else if (Object is uint UInt32) return UInt32; return null; }
public long? ReadNInt64()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return Int64;
else if (Object is ulong UInt64) return (long)UInt64; return null; }
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return Int64;
else if (Object is ulong UInt64) return ( long) UInt64; return null; }
public ulong? ReadNUInt64()
{ if (Object is sbyte Int8 ) return (ulong) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return (ulong) Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return (ulong) Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return (ulong) Int64;
else if (Object is ulong UInt64) return UInt64; return null; }
{ if (Object is sbyte Int8 ) return ( ulong) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return ( ulong) Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return ( ulong) Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return ( ulong) Int64;
else if (Object is ulong UInt64) return UInt64; return null; }
public float? ReadNSingle()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
@@ -210,26 +220,23 @@ namespace KKdMainLib.MessagePack
else if (Object is float Float32) return Float32;
else if (Object is double Float64) return ( float)Float64; return null; }
public double? ReadNDouble()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return Int64;
else if (Object is float Float32) return Float32;
else if (Object is double Float64) return Float64; return null; }
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return Int64;
else if (Object is float Float32) return Float32;
else if (Object is double Float64) return Float64; return null; }
public string ReadString()
{ if (Object is string String) return String; return null; }
{ if (Object is string String) return String; return null; }
public bool Element<T>(string Name, out MsgPack MsgPack)
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;
@@ -241,7 +248,7 @@ namespace KKdMainLib.MessagePack
if (List.IsNull) return false;
for (int i = 0; i < List.Count; i++)
if (List[i] is MsgPack msg) if (msg.Name == Name) { MsgPack = msg; return true; }
if (List[i].Name == Name) { MsgPack = List[i]; return true; }
return false;
}
@@ -249,19 +256,15 @@ namespace KKdMainLib.MessagePack
{
if (List.IsNull) return false;
for (int i = 0; i < List.Count ; i++)
if (List[i] is MsgPack msg) if (msg.Name == Name) return true;
for (int i = 0; i < List.Count ; i++)
if (List[i].Name == Name) return true;
return false;
}
public override string ToString() => Name ?? "" +
( List.NotNull ? ((Name != null ? " " : "") + "Elements Count: " + List .Count ) :
(Array != null ? ((Name != null ? " " : "") + "Elements Count: " + Array.Length) : Object.ToString()));
public struct Ext
{
public byte[] Data;
public sbyte Type;
public sbyte Type;
public byte[] Data;
}
}
}
+10 -12
View File
@@ -14,7 +14,7 @@ namespace KKdMainLib
public Mot()
{ i = i0 = i1 = 0; IO = null; }
public void MOTReader(string file, bool JSON)
public unsafe void MOTReader(string file, bool JSON)
{
IO = File.OpenReader(file + ".bin");
@@ -72,13 +72,13 @@ namespace KKdMainLib
m[i] = MsgPackWriter(ref MMOT[i]);
((MsgPack)m[i]).Write(true, file + "." + i.ToString("d2"), JSON);
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);
m.Write(true, file, JSON);
MMOT = null;
m = new MsgPack();
System.GC.Collect();
@@ -129,7 +129,7 @@ namespace KKdMainLib
MsgPack BoneInfo = new MsgPack(Mot.BoneInfo.Value.Length, "BoneInfo");
for (i0 = 0; i0 < Mot.BoneInfo.Value.Length; i0++)
BoneInfo[i0] = Mot.BoneInfo.Value[i0].Id;
BoneInfo[i0] = (MsgPack)Mot.BoneInfo.Value[i0].Id;
MOT.Add(BoneInfo);
return MOT;
@@ -148,29 +148,27 @@ namespace KKdMainLib
public struct KeySet
{
public KeyFrame<ushort, float>[] Keys;
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 KeyFrame<ushort, float>[]
{ new KeyFrameT1<ushort, float> { Value = IO.ReadSingle() } }; return; }
else if (Type == KeySetType.Static) { Keys = new IKeyFrame<ushort, float>[]
{ new KeyFrameT1<ushort, float> { Value = IO.ReadSingle() } }; return; }
Keys = new KeyFrame<ushort, float>[IO.ReadUInt16()];
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() };
Keys[i] = new KeyFrameT2<ushort, float>{ Frame = IO.ReadUInt16() };
IO.Align(0x4);
for (int i = 0; i < Keys.Length; i++)
if (Keys[i] is KeyFrameT2<ushort, float> Key)
{
Key.Value = IO.ReadSingle();
Key.Interpolation = IO.ReadSingle();
if (Key.Interpolation == 0) Keys[i] = Key.ToKeyFrameT1();
else Keys[i] = Key;
Keys[i] = Key.Check();
}
}
else
+2 -2
View File
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("2BA7EFC6-91D1-8BBC-C487-06C7F36CC789")]
[assembly: AssemblyVersion("0.4.6.0")]
[assembly: AssemblyFileVersion("0.4.6.0")]
[assembly: AssemblyVersion("0.4.6.1")]
[assembly: AssemblyFileVersion("0.4.6.1")]
+6 -8
View File
@@ -177,16 +177,14 @@ namespace KKdMainLib
if (!MsgPack.Element("STR", out MsgPack STR)) return;
if (!STR.Element<MsgPack>("Strings", out MsgPack Strings)) return;
if (!STR.ElementArray("Strings", out MsgPack Strings)) return;
STRs = new String[Strings.Array.Length];
for (int i = 0; i < STRs.Length; i++)
if (Strings[i] is MsgPack String)
{
String = (MsgPack)Strings[i];
STRs[i].ID = String.ReadInt32("ID");
STRs[i].Str = String.ReadString("Str");
}
{
STRs[i].ID = Strings[i].ReadInt32 ("ID" );
STRs[i].Str = Strings[i].ReadString("Str");
}
MsgPack = MsgPack.New;
}
@@ -199,7 +197,7 @@ namespace KKdMainLib
{
Strings[i] = MsgPack.New.Add("ID", STRs[i].ID);
if (STRs[i].Str != null) if (STRs[i].Str != "")
((MsgPack)Strings[i]).Add("S", STRs[i].Str); ;
Strings[i].Add("S", STRs[i].Str); ;
}
STR_.Add(Strings);
@@ -1,52 +1,52 @@
namespace KKdMainLib.Types
{
public interface KeyFrame<TKey, TVal>
public interface IKeyFrame<TKey, TVal>
{
KeyFrame<TKey, TVal> Check();
KeyFrame<TKey, TVal> ToKeyFrameT0();
KeyFrame<TKey, TVal> ToKeyFrameT1();
KeyFrame<TKey, TVal> ToKeyFrameT2();
KeyFrame<TKey, TVal> ToKeyFrameT3();
IKeyFrame<TKey, TVal> Check();
IKeyFrame<TKey, TVal> ToKeyFrameT0();
IKeyFrame<TKey, TVal> ToKeyFrameT1();
IKeyFrame<TKey, TVal> ToKeyFrameT2();
IKeyFrame<TKey, TVal> ToKeyFrameT3();
string ToString();
string ToString(bool Brackets);
}
public struct KeyFrameT0<TKey, TVal> : KeyFrame<TKey, TVal>
public struct KeyFrameT0<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public KeyFrame<TKey, TVal> ToKeyFrameT0() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
new KeyFrameT0<TKey, TVal> { Frame = Frame };
public KeyFrame<TKey, TVal> ToKeyFrameT1() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
new KeyFrameT1<TKey, TVal> { Frame = Frame };
public KeyFrame<TKey, TVal> ToKeyFrameT2() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
new KeyFrameT2<TKey, TVal> { Frame = Frame };
public KeyFrame<TKey, TVal> ToKeyFrameT3() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
new KeyFrameT3<TKey, TVal> { Frame = Frame };
public KeyFrame<TKey, TVal> Check() => this;
public IKeyFrame<TKey, TVal> Check() => this;
public override string ToString() =>
Main.ToString(Frame);
public string ToString(bool Brackets) =>
Main.ToString(Frame);
}
public struct KeyFrameT1<TKey, TVal> : KeyFrame<TKey, TVal>
public struct KeyFrameT1<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public TVal Value;
public KeyFrame<TKey, TVal> ToKeyFrameT0() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
new KeyFrameT0<TKey, TVal> { Frame = Frame };
public KeyFrame<TKey, TVal> ToKeyFrameT1() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
new KeyFrameT1<TKey, TVal> { Frame = Frame, Value = Value };
public KeyFrame<TKey, TVal> ToKeyFrameT2() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
new KeyFrameT2<TKey, TVal> { Frame = Frame, Value = Value };
public KeyFrame<TKey, TVal> ToKeyFrameT3() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value };
public KeyFrame<TKey, TVal> Check()
public IKeyFrame<TKey, TVal> Check()
{
if (Value.Equals(default(TVal))) return ToKeyFrameT0();
return this;
@@ -58,31 +58,31 @@
Main.ToString(Value) + (Brackets ? ")" : "");
}
public struct KeyFrameT2<TKey, TVal> : KeyFrame<TKey, TVal>
public struct KeyFrameT2<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public TVal Value;
public TVal Interpolation;
public KeyFrame<TKey, TVal> ToKeyFrameT0() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
new KeyFrameT0<TKey, TVal> { Frame = Frame };
public KeyFrame<TKey, TVal> ToKeyFrameT1() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
new KeyFrameT1<TKey, TVal> { Frame = Frame, Value = Value };
public KeyFrame<TKey, TVal> ToKeyFrameT2() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
new KeyFrameT2<TKey, TVal> { Frame = Frame, Value = Value,
Interpolation = Interpolation};
public KeyFrame<TKey, TVal> ToKeyFrameT3() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
Interpolation1 = Interpolation, Interpolation2 = Interpolation };
public KeyFrame<TKey, TVal> ToKeyFrameT3(KeyFrame<TKey, TVal> Previous) =>
public IKeyFrame<TKey, TVal> ToKeyFrameT3(IKeyFrame<TKey, TVal> Previous) =>
Previous is KeyFrameT2<TKey, TVal> PreviousT2 ?
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
Interpolation1 = PreviousT2.Interpolation, Interpolation2 = Interpolation } :
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
Interpolation1 = Interpolation, Interpolation2 = Interpolation };
public KeyFrame<TKey, TVal> Check()
public IKeyFrame<TKey, TVal> Check()
{
if (Value.Equals(default(TVal)) && Interpolation.Equals(default(TVal)))
return ToKeyFrameT0();
@@ -95,25 +95,25 @@
(Brackets ? "(" : "") + Main.ToString(Frame) + "," + Main.
ToString(Value) + "," + Main.ToString(Interpolation) + (Brackets ? ")" : "");
}
public struct KeyFrameT3<TKey, TVal> : KeyFrame<TKey, TVal>
public struct KeyFrameT3<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public TVal Value;
public TVal Interpolation1;
public TVal Interpolation2;
public KeyFrame<TKey, TVal> ToKeyFrameT0() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
new KeyFrameT0<TKey, TVal> { Frame = Frame };
public KeyFrame<TKey, TVal> ToKeyFrameT1() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
new KeyFrameT1<TKey, TVal> { Frame = Frame, Value = Value };
public KeyFrame<TKey, TVal> ToKeyFrameT2() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
new KeyFrameT2<TKey, TVal> { Frame = Frame, Value = Value, Interpolation = Interpolation1 };
public KeyFrame<TKey, TVal> ToKeyFrameT3() =>
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
Interpolation1 = Interpolation1, Interpolation2 = Interpolation2 };
public KeyFrame<TKey, TVal> Check()
public IKeyFrame<TKey, TVal> Check()
{
if (Value.Equals(default(TVal)) && Interpolation1.Equals(default(TVal)) &&
Interpolation2.Equals(default(TVal))) return ToKeyFrameT0();
@@ -129,7 +129,7 @@
(Brackets ? "(" : "") + Main.ToString(Frame) + "," + Main.ToString(Value) + "," +
Main.ToString(Interpolation1) + "," + Main.ToString(Interpolation2) + (Brackets ? ")" : "");
public KeyFrame<TKey, TVal> ToKeyFrameT2(KeyFrame<TKey, TVal>
public IKeyFrame<TKey, TVal> ToKeyFrameT2(IKeyFrame<TKey, TVal>
Previous, out KeyFrameT2<TKey, TVal> Current)
{
if (Previous is KeyFrameT2<TKey, TVal> PreviousT2)
@@ -141,8 +141,8 @@
return new KeyFrameT2<TKey, TVal> { Frame = Frame,
Value = Value, Interpolation = Interpolation2 };
}
public KeyFrame<TKey, TVal> ToKeyFrameT2(KeyFrame<TKey, TVal>
Previous, out KeyFrame<TKey, TVal> Current)
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,
+27 -30
View File
@@ -8,67 +8,64 @@ namespace KKdMainLib.Types
public static KKdList<T> New => new KKdList<T>() { Capacity = 0 };
public static KKdList<T> NewReserve(int Capacity) => new KKdList<T>() { Capacity = Capacity };
private int Index;
private int ArrayLength;
private T[] Array;
public bool IsNull => Array == null;
public bool NotNull => Array != null;
private int index;
private T[] array;
public int Count { get; private set; }
public int Capacity { get => ArrayLength;
public bool IsNull => array == null;
public bool NotNull => array != null;
public int Capacity { get => array != null ? array.Length : -1;
set
{
ArrayLength = value;
if (Array != null) System.Array.Resize(ref Array, ArrayLength);
else Array = new T[ArrayLength];
if (array != null) System.Array.Resize(ref array, value);
else array = new T[value];
}
}
public KKdList(T[] Array)
{
Index = 0;
index = 0;
Count = Array.Length;
ArrayLength = Array.Length;
this.Array = Array;
this.array = Array;
}
public T Current => Index < Count ? Array[Index] : default(T);
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; } }
{ 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; } }
{ if (index == (Count - 1)) { index = 0; return false; }
else { index++ ; return true; } }
public IEnumerator GetEnumerator() => this;
public void Dispose() { Array = null; ArrayLength = 0; Count = 0; Index = 0; }
public void Dispose() { array = null; Count = 0; index = 0; }
public void Reset() => Index = 0;
public void Reset() => index = 0;
public void Add(T item)
{
if (IsNull) return;
Count++;
if (ArrayLength < Count)
System.Array.Resize(ref Array, ArrayLength = Count);
Array[Count - 1] = item;
if (array.Length < Count)
System.Array.Resize(ref array, Count);
array[Count - 1] = item;
}
public void RemoveAt(int Index)
public void RemoveAt(int index)
{
if (IsNull) return;
for (int i = Index; i < Count; i++)
Array[i] = Array[i + 1];
for (int i = index; i < Count; i++)
array[i] = array[i + 1];
}
public void RemoveRange(int IndexStart, int IndexEnd)
@@ -77,16 +74,16 @@ namespace KKdMainLib.Types
if (IsNull) return;
for (int i = IndexStart; i < Count; i++)
Array[i] = Array[i + IndexEnd - IndexStart];
array[i] = array[i + IndexEnd - IndexStart];
}
public T[] ToArray() => Array;
public T[] ToArray() => array;
public bool Contains(T val)
{
if (IsNull) return false;
for (int i = 0; i < Count; i++)
if (Array[i].Equals(val)) return true;
if (array[i].Equals(val)) return true;
return false;
}
@@ -94,7 +91,7 @@ namespace KKdMainLib.Types
{
if (IsNull) return -1;
for (int i = 0; i < Count; i++)
if (Array[i].Equals(val)) return i;
if (array[i].Equals(val)) return i;
return -1;
}
}
+12 -2
View File
@@ -4,14 +4,24 @@
{
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;
}
}
+8 -11
View File
@@ -1,28 +1,25 @@
namespace KKdMainLib.Types
{
public class Vector2<T>
public struct Vector2<T>
{
public T X;
public T Y;
public T Z;
public Vector2()
{ X = default(T); Y = default(T); Z = default(T); }
public Vector2(T X, T Y)
{ this.X = X; this.Y = Y; }
public Vector2(T X, T Y, T Z)
{ this.X = X; this.Y = Y; this.Z = Z; }
public override string ToString() => "X: " + X + "; Y: " + Y;
}
public class Vector3<T>
public struct Vector3<T>
{
public T X;
public T Y;
public T Z;
public Vector3()
{ X = default(T); Y = default(T); Z = default(T); }
public Vector3(T X, T Y, T Z)
{ this.X = X; this.Y = Y; this.Z = Z; }
public override string ToString() => "X: " + X + "; Y: " + Y + "; Z: " + Z;
}
}
+2 -2
View File
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
[assembly: AssemblyVersion("0.4.6.0")]
[assembly: AssemblyFileVersion("0.4.6.0")]
[assembly: AssemblyVersion("0.4.6.1")]
[assembly: AssemblyFileVersion("0.4.6.1")]