Compare commits

...
3 Commits
Author SHA1 Message Date
KujiKita 4c8b293beb Release v0.4.5.10
Some fixes and changes
2019-06-14 05:39:46 +03:00
korenkonder 72141ef603 Update README.md 2019-06-02 00:45:40 +03:00
KujiKita d405f05f0b Release v0.4.5.9
Some fixes and changes
2019-06-02 00:43:54 +03:00
47 changed files with 4340 additions and 1229 deletions
+401 -452
View File
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using KKdMainLib;
using KKdMainLib.IO;
using KKdMainLib.Types;
using KKdMainLib.MessagePack;
using MPIO = KKdMainLib.MessagePack.IO;
namespace KKdMainLib.A3DA
{
@@ -22,8 +22,7 @@ namespace KKdMainLib.A3DA
private string nameView;
private string value;
private string[] dataArray;
private MsgPack MsgPack;
private Values UsedValues;
private Dictionary<int?, double?> UsedValues;
private Dictionary<string, object> Dict;
private bool IsX => Data.Header.Format == Main.Format.X || Data.Header.Format == Main.Format.XHD;
@@ -33,7 +32,7 @@ namespace KKdMainLib.A3DA
public A3DA()
{ Data = new A3DAData(); Dict = new Dictionary<string, object>();
IO = File.OpenWriter(); UsedValues = new Values(); }
IO = File.OpenWriter(); UsedValues = new Dictionary<int?, double?>(); }
public int A3DAReader(string file)
{
@@ -901,7 +900,7 @@ namespace KKdMainLib.A3DA
IO.ReadKey(ref Data.CameraAuxiliary.Saturate , CompressF16);
}
if (Data.CameraRoot != null)
if (Data.CameraRoot != null)
for (i0 = 0; i0 < Data.CameraRoot.Length; i0++)
{
IO.ReadMT(ref Data.CameraRoot[i0].MT , CompressF16);
@@ -1007,7 +1006,7 @@ namespace KKdMainLib.A3DA
{
int i0 = 0;
int i1 = 0;
if (A3DCOpt) { UsedValues.BinOffset = new List<int?>(); UsedValues.Value = new List<double?>(); }
if (A3DCOpt) UsedValues = new Dictionary<int?, double?>();
if (Data.Header.Format > Main.Format.FT)
{
@@ -1297,461 +1296,422 @@ namespace KKdMainLib.A3DA
}
else
{
if (!UsedValues.Value.Contains(Key.Value) || !A3DCOpt)
if (!UsedValues.ContainsValue(Key.Value) || !A3DCOpt)
{
Key.BinOffset = IO.Position;
IO.Write( Key.Type );
IO.Write((float?)Key.Value);
if (A3DCOpt)
{ UsedValues.BinOffset.Add(Key.BinOffset); UsedValues.Value.Add(Key.Value); }
{ UsedValues.Add(Key.BinOffset, Key.Value); }
return;
}
for (i = 0; i < UsedValues.Value.Count; i++)
if (UsedValues.Value[i] == Key.Value)
{ Key.BinOffset = UsedValues.BinOffset[i]; return; }
else if (UsedValues.ContainsValue(Key.Value))
{ Key.BinOffset = UsedValues.GetKey(Key.Value); return; }
}
}
public void MsgPackReader(string file)
public void MsgPackReader(string file, bool JSON)
{
int i = 0;
int i0 = 0;
int i1 = 0;
MPIO IO = new MPIO(File.OpenReader(file + ".mp"));
MsgPack = IO.Read();
IO.Close();
IO = null;
MsgPack MsgPack = file.ReadMP(JSON);
if (MsgPack.Element("A3D", out MsgPack A3D))
if (!MsgPack.Element("A3D", out MsgPack A3D)) { MsgPack = null; return; }
Data.Header = new PDHead();
Enum.TryParse(A3D.ReadString("Format"), out Data.Header.Format);
MsgPack Temp = new MsgPack();
if (A3D.Element("_", out Temp))
{
Data.Header = new PDHead();
Enum.TryParse(A3D.ReadString("Format"), out Data.Header.Format);
MsgPack Temp = new MsgPack();
if (A3D.Element("_", out Temp))
Data._ = new _
{
Data._ = new _
{
CompressF16 = Temp.ReadNInt32("CompressF16" ),
ConverterVersion = Temp.ReadString("ConverterVersion"),
FileName = Temp.ReadString("FileName" ),
PropertyVersion = Temp.ReadString("PropertyVersion" ),
};
}
if (A3D.Element("Ambient", out Temp, typeof(object[])))
{
Data.Ambient = new Ambient[((object[])Temp.Object).Length];
MsgPack Ambient = new MsgPack();
for (i = 0; i < Data.Ambient.Length; i++)
if (Temp[i].GetType() == typeof(MsgPack))
{
Ambient = (MsgPack)Temp[i];
Data.Ambient[i] = new Ambient
{
Name = Ambient.ReadString ( "Name"),
LightDiffuse = Ambient.ReadRGBAKey( "LightDiffuse"),
RimLightDiffuse = Ambient.ReadRGBAKey("RimLightDiffuse"),
};
}
}
if (A3D.Element("CameraAuxiliary", out MsgPack CameraAuxiliary))
Data.CameraAuxiliary = new CameraAuxiliary
{
AutoExposure = CameraAuxiliary.ReadKey("AutoExposure"),
Exposure = CameraAuxiliary.ReadKey( "Exposure"),
Gamma = CameraAuxiliary.ReadKey("Gamma" ),
GammaRate = CameraAuxiliary.ReadKey("GammaRate" ),
Saturate = CameraAuxiliary.ReadKey("Saturate" ),
};
if (A3D.Element("CameraRoot", out MsgPack CameraRoot, typeof(object[])))
{
Data.CameraRoot = new CameraRoot[((object[])CameraRoot.Object).Length];
MsgPack _Root = new MsgPack();
for (i = 0; i < Data.CameraRoot.Length; i++)
if (CameraRoot[i].GetType() == typeof(MsgPack))
{
_Root = (MsgPack)CameraRoot[i];
Data.CameraRoot[i] = new CameraRoot
{
MT = _Root.ReadMT(),
Interest = _Root.ReadMT("Interest"),
};
if (!_Root.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" ),
};
}
}
if (A3D.Element("Chara", out Temp, typeof(object[])))
{
Data.Chara = new ModelTransform[((object[])Temp.Object).Length];
for (i = 0; i < Data.Chara.Length; i++)
if (Temp[i].GetType() == typeof(MsgPack))
Data.Chara[i] = ((MsgPack)Temp[i]).ReadMT();
}
if (A3D.Element("Curve", out Temp, typeof(object[])))
{
Data.Curve = new Curve[((object[])Temp.Object).Length];
MsgPack Curve = new MsgPack();
for (i = 0; i < Data.Curve.Length; i++)
if (Temp[i].GetType() == typeof(MsgPack))
{
Curve = (MsgPack)Temp[i];
Data.Curve[i] = new Curve
{
Name = Curve.ReadString("Name"),
CV = Curve.ReadKey ("CV"),
};
}
}
if (A3D.Element("DOF", out Temp, typeof(object[])))
Data.DOF = new DOF
{
MT = Temp.ReadMT(),
Name = Temp.ReadString("Name"),
};
if (A3D.Element("Event", out Temp, typeof(object[])))
{
Data.Event = new Event[((object[])Temp.Object).Length];
MsgPack Event = new MsgPack();
for (i = 0; i < Data.Event.Length; i++)
if (Temp[i].GetType() == typeof(MsgPack))
{
Event = (MsgPack)Temp[i];
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" ),
};
}
}
if (A3D.Element("Fog", out Temp, typeof(object[])))
{
Data.Fog = new Fog[((object[])Temp.Object).Length];
MsgPack Fog = new MsgPack();
for (i = 0; i < Data.Fog.Length; i++)
if (Temp[i].GetType() == typeof(MsgPack))
{
Fog = (MsgPack)Temp[i];
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" ),
};
}
}
if (A3D.Element("Light", out Temp, typeof(object[])))
{
Data.Light = new Light[((object[])Temp.Object).Length];
MsgPack Light = new MsgPack();
for (i = 0; i < Data.Light.Length; i++)
if (Temp[i].GetType() == typeof(MsgPack))
{
Light = (MsgPack)Temp[i];
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"),
};
}
}
if (A3D.Element("MaterialList", out Temp, typeof(object[])))
{
Data.MaterialList = new MaterialList[((object[])Temp.Object).Length];
MsgPack MaterialList = new MsgPack();
for (i = 0; i < Data.MaterialList.Length; i++)
if (Temp[i].GetType() == typeof(MsgPack))
{
MaterialList = (MsgPack)Temp[i];
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"),
};
}
}
if (A3D.Element("MObjectHRC", out Temp, typeof(object[])))
{
Data.MObjectHRC = new MObjectHRC[((object[])Temp.Object).Length];
MsgPack _Node = new MsgPack();
MsgPack _Instance = new MsgPack();
MsgPack MObjectHRC = new MsgPack();
for (i0 = 0; i0 < Data.MObjectHRC.Length; i0++)
{
if (Temp[i0].GetType() == typeof(MsgPack))
{
MObjectHRC = (MsgPack)Temp[i0];
Data.MObjectHRC[i0] = new MObjectHRC
{
MT = MObjectHRC.ReadMT(),
Name = MObjectHRC.ReadString("Name"),
};
if (MObjectHRC.Element("JointOrient", out MsgPack JointOrient, typeof(MsgPack)))
{
Data.MObjectHRC[i0].JointOrient = new Vector3<double?>
{
X = JointOrient.ReadDouble("X"),
Y = JointOrient.ReadDouble("Y"),
Z = JointOrient.ReadDouble("Z"),
};
}
if (MObjectHRC.Element("Instance", out MsgPack Instance, typeof(object[])))
{
Data.MObjectHRC[i0].Instance =
new Instance[((object[])Instance.Object).Length];
for (i1 = 0; i1 < Data.MObjectHRC[i0].Instance.Length; i1++)
{
if (Instance[i1].GetType() != typeof(MsgPack)) continue;
_Instance = (MsgPack)Instance[i1];
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("Node", out MsgPack Node, typeof(object[])))
{
Data.MObjectHRC[i0].Node = new Node[((object[])Node.Object).Length];
for (i1 = 0; i1 < Data.MObjectHRC[i0].Node.Length; i1++)
{
if (Node[i1].GetType() != typeof(MsgPack)) continue;
_Node = (MsgPack)Node[i1];
Data.MObjectHRC[i0].Node[i1] = new Node
{
MT = _Node.ReadMT(),
Name = _Node.ReadString( "Name"),
Parent = _Node.ReadNInt32("Parent"),
};
}
}
}
}
}
if (A3D.Element("MObjectHRCList", out Temp, typeof(object[])))
{
Data.MObjectHRCList = new string[((object[])Temp.Object).Length];
for (i = 0; i < Data.MObjectHRCList.Length; i++)
if (Temp[i].GetType() == typeof(MsgPack))
Data.MObjectHRCList[i] = ((MsgPack)Temp[i]).ReadString();
}
if (A3D.Element("Motion", out Temp, typeof(object[])))
{
Data.Motion = new string[((object[])Temp.Object).Length];
for (i = 0; i < Data.Motion.Length; i++)
if (Temp[i].GetType() == typeof(MsgPack))
Data.Motion[i] = ((MsgPack)Temp[i]).ReadString();
}
if (A3D.Element("Object", out Temp, typeof(object[])))
{
Data.Object = new Object[((object[])Temp.Object).Length];
MsgPack _TP = new MsgPack();
MsgPack _TT = new MsgPack();
MsgPack Object = new MsgPack();
for (i0 = 0; i0 < Data.Object.Length; i0++)
if (Temp[i0].GetType() == typeof(MsgPack))
{
Object = (MsgPack)Temp[i0];
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"),
};
if (Object.Element("TP", out MsgPack TP, typeof(object[])))
{
Data.Object[i0].TP = new Object.TexturePattern[((object[])TP.Object).Length];
for (i1 = 0; i1 < Data.Object[i0].TP.Length; i1++)
{
if (TP[i1].GetType() != typeof(MsgPack)) continue;
_TP = (MsgPack)TP[i1];
Data.Object[i0].TP[i1] = new Object.TexturePattern
{
Name = _TP.ReadString("Name" ),
Pat = _TP.ReadString("Pat" ),
PatOffset = _TP.ReadNInt32("PatOffset"),
};
}
}
if (Object.Element("TT", out MsgPack TT, typeof(object[])))
{
Data.Object[i0].TT = new Object.TextureTransform[((object[])TT.Object).Length];
for (i1 = 0; i1 < Data.Object[i0].TT.Length; i1++)
{
if (TT[i1].GetType() != typeof(MsgPack)) continue;
_TT = (MsgPack)TT[i1];
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("ObjectHRC", out Temp, typeof(object[])))
{
Data.ObjectHRC = new ObjectHRC[((object[])Temp.Object).Length];
MsgPack _Node = new MsgPack();
MsgPack _Instance = new MsgPack();
MsgPack ObjectHRC = new MsgPack();
for (i0 = 0; i0 < Data.ObjectHRC.Length; i0++)
if (Temp[i0].GetType() == typeof(MsgPack))
{
ObjectHRC = (MsgPack)Temp[i0];
Data.ObjectHRC[i0] = new ObjectHRC
{
Name = ObjectHRC.ReadString ( "Name"),
Shadow = ObjectHRC.ReadNDouble( "Shadow"),
UIDName = ObjectHRC.ReadString ("UIDName"),
};
if (ObjectHRC.Element("JointOrient", out MsgPack JointOrient, typeof(MsgPack)))
{
Data.ObjectHRC[i0].JointOrient = new Vector3<double?>
{
X = JointOrient.ReadDouble("X"),
Y = JointOrient.ReadDouble("Y"),
Z = JointOrient.ReadDouble("Z"),
};
}
if (ObjectHRC.Element("Node", out MsgPack Node, typeof(object[])))
{
Data.ObjectHRC[i0].Node = new Node[((object[])Node.Object).Length];
for (i1 = 0; i1 < Data.ObjectHRC[i0].Node.Length; i1++)
{
if (Node[i1].GetType() != typeof(MsgPack)) continue;
_Node = (MsgPack)Node[i1];
Data.ObjectHRC[i0].Node[i1] = new Node
{
MT = _Node.ReadMT(),
Name = _Node.ReadString( "Name"),
Parent = _Node.ReadInt32 ("Parent"),
};
}
}
}
}
if (A3D.Element("ObjectHRCList", out Temp, typeof(object[])))
{
Data.ObjectHRCList = new string[((object[])Temp.Object).Length];
for (i = 0; i < Data.ObjectHRCList.Length; i++)
if (Temp[i].GetType() == typeof(MsgPack))
Data.ObjectHRCList[i] = ((MsgPack)Temp[i]).ReadString();
}
if (A3D.Element("ObjectList", out Temp, typeof(object[])))
{
Data.ObjectList = new string[((object[])Temp.Object).Length];
for (i = 0; i < Data.ObjectList.Length; i++)
if (Temp[i].GetType() == typeof(MsgPack))
Data.ObjectList[i] = ((MsgPack)Temp[i]).ReadString();
}
if (A3D.Element("PlayControl", out Temp))
Data.PlayControl = new PlayControl
{
Begin = Temp.ReadNDouble("Begin" ),
Div = Temp.ReadNDouble("Div" ),
FPS = Temp.ReadNDouble("FPS" ),
Offset = Temp.ReadNDouble("Offset"),
Size = Temp.ReadNDouble("Size" ),
};
if (A3D.Element("Point", out Temp, typeof(object[])))
{
Data.Point = new ModelTransform[((object[])Temp.Object).Length];
for (i = 0; i < Data.Point.Length; i++)
if (Temp[i].GetType() == typeof(MsgPack))
Data.Point[i] = ((MsgPack)Temp[i]).ReadMT();
}
if (A3D.Element("PostProcess", out Temp))
Data.PostProcess = new PostProcess
{
Ambient = Temp.ReadRGBAKey("Ambient" ),
Diffuse = Temp.ReadRGBAKey("Diffuse" ),
LensFlare = Temp.ReadKey ("LensFlare"),
LensGhost = Temp.ReadKey ("LensGhost"),
LensShaft = Temp.ReadKey ("LensShaft"),
Specular = Temp.ReadRGBAKey("Specular" ),
};
Temp = null;
CompressF16 = Temp.ReadNInt32("CompressF16" ),
ConverterVersion = Temp.ReadString("ConverterVersion"),
FileName = Temp.ReadString("FileName" ),
PropertyVersion = Temp.ReadString("PropertyVersion" ),
};
}
if (A3D.Element<MsgPack>("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"),
};
}
}
if (A3D.Element("CameraAuxiliary", out Temp))
Data.CameraAuxiliary = new CameraAuxiliary
{
AutoExposure = Temp.ReadKey("AutoExposure"),
Exposure = Temp.ReadKey( "Exposure"),
Gamma = Temp.ReadKey("Gamma" ),
GammaRate = Temp.ReadKey("GammaRate" ),
Saturate = Temp.ReadKey("Saturate" ),
};
if (A3D.Element<MsgPack>("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"),
};
if (!_Root.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" ),
};
}
}
if (A3D.Element<MsgPack>("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();
}
if (A3D.Element<MsgPack>("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"),
};
}
}
if (A3D.Element("DOF", out Temp))
Data.DOF = new DOF
{
MT = Temp.ReadMT(),
Name = Temp.ReadString("Name"),
};
if (A3D.Element<MsgPack>("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" ),
};
}
}
if (A3D.Element<MsgPack>("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" ),
};
}
}
if (A3D.Element<MsgPack>("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"),
};
}
}
if (A3D.Element<MsgPack>("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"),
};
}
}
if (A3D.Element<MsgPack>("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"),
};
if (MObjectHRC.Element("JointOrient", out MsgPack JointOrient))
Data.MObjectHRC[i0].JointOrient = new Vector3<double?>
{
X = JointOrient.ReadDouble("X"),
Y = JointOrient.ReadDouble("Y"),
Z = JointOrient.ReadDouble("Z"),
};
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++)
{
_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"),
};
}
}
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++)
{
_Node = Node[i1] as MsgPack;
Data.MObjectHRC[i0].Node[i1] = new Node
{
MT = _Node.ReadMT(),
Name = _Node.ReadString( "Name"),
Parent = _Node.ReadNInt32("Parent"),
};
}
}
}
}
if (A3D.Element<MsgPack>("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();
}
if (A3D.Element<MsgPack>("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();
}
if (A3D.Element<MsgPack>("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"),
};
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++)
{
_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"),
};
}
}
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++)
{
_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" ),
};
}
}
}
}
if (A3D.Element<MsgPack>("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"),
};
if (ObjectHRC.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 (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++)
{
_Node = Node[i1] as MsgPack;
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))
{
Data.ObjectHRCList = new string[Temp.Array.Length];
for (i = 0; i < Data.ObjectHRCList.Length; i++)
Data.ObjectHRCList[i] = (Temp[i] as MsgPack).ReadString();
}
if (A3D.Element<MsgPack>("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();
}
if (A3D.Element("PlayControl", out Temp))
Data.PlayControl = new PlayControl
{
Begin = Temp.ReadNDouble("Begin" ),
Div = Temp.ReadNDouble("Div" ),
FPS = Temp.ReadNDouble("FPS" ),
Offset = Temp.ReadNDouble("Offset"),
Size = Temp.ReadNDouble("Size" ),
};
if (A3D.Element<MsgPack>("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();
}
if (A3D.Element("PostProcess", out Temp))
Data.PostProcess = new PostProcess
{
Ambient = Temp.ReadRGBAKey("Ambient" ),
Diffuse = Temp.ReadRGBAKey("Diffuse" ),
LensFlare = Temp.ReadKey ("LensFlare"),
LensGhost = Temp.ReadKey ("LensGhost"),
LensShaft = Temp.ReadKey ("LensShaft"),
Specular = Temp.ReadRGBAKey("Specular" ),
};
Temp = null;
MsgPack = null;
}
public void MsgPackWriter(string file)
public void MsgPackWriter(string file, bool JSON)
{
int i = 0;
int i0 = 0;
@@ -2036,13 +1996,8 @@ namespace KKdMainLib.A3DA
.Add(Data.PostProcess.LensGhost.WriteMP("LensGhost"))
.Add(Data.PostProcess.LensShaft.WriteMP("LensShaft"))
.Add(Data.PostProcess.Specular .WriteMP("Specular" )));
MsgPack = new MsgPack(MsgPack.Types.FixMap).Add(A3D);
MPIO IO = new MPIO(File.OpenWriter(file + ".mp", true));
IO.Write(MsgPack, true);
IO = null;
MsgPack = null;
A3D.Write(true, file, JSON);
}
}
@@ -2319,12 +2274,6 @@ namespace KKdMainLib.A3DA
public Key A;
}
public struct Values
{
public List< int?> BinOffset;
public List<double?> Value;
}
public class Vector3<T>
{
public T X;
+14 -16
View File
@@ -188,7 +188,7 @@ namespace KKdMainLib.A3DA
{
if (MT.BinOffset == null) return;
IO.Position = IO.Offset + (int)MT.BinOffset;
IO.Position = (int)MT.BinOffset;
IO.ReadOffset(out MT.Scale);
IO.ReadOffset(out MT.Rot );
@@ -217,7 +217,7 @@ namespace KKdMainLib.A3DA
if (Key == null) return;
if (Key.BinOffset == null || Key.BinOffset < 0) return;
IO.Position = IO.Offset + (int)Key.BinOffset;
IO.Position = (int)Key.BinOffset;
Key.Type = IO.ReadInt32();
Key.Value = IO.ReadSingle();
@@ -314,27 +314,25 @@ namespace KKdMainLib.A3DA
if (Key.Type < 2) return Key;
if (!k.Element("Trans", out MsgPack Trans, typeof(object[]))) return Key;
if (!k.Element<MsgPack>("Trans", out MsgPack Trans)) return Key;
Key.Length = ((object[])Trans.Object).Length;
Key.Length = Trans.Array.Length;
Key.Trans = new Key.Transform[Key.Length.Value];
MsgPack _Trans = new MsgPack();
byte i1 = 0;
for (int i = 0; i < Key.Length; i++)
{
Key.Trans[i] = new Key.Transform();
if (Trans[i].GetType() != typeof(MsgPack)) continue;
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();
_Trans = (MsgPack)Trans[i];
if (_Trans.Object.GetType() != typeof(object[])) continue;
Key.Trans[i].Type = ((object[])_Trans.Object).Length - 1;
Key.Trans[i].Value = new double[Key.Trans[i].Type];
if (_Trans[0].GetType() != typeof(MsgPack)) continue;
Key.Trans[i].Frame = ((MsgPack)_Trans[0]).ReadDouble();
for (i1 = 0; i1 < Key.Trans[i].Type; i1++)
Key.Trans[i].Value[i1] = ((MsgPack)_Trans[i1 + 1]).ReadDouble();
for (i1 = 0; i1 < Key.Trans[i].Type; i1++)
Key.Trans[i].Value[i1] = ((MsgPack)_Trans[i1 + 1]).ReadDouble();
}
}
return Key;
}
+980
View File
@@ -0,0 +1,980 @@
//Original: AetSet.bt Version: 2.0 by samyuu
using System.Collections.Generic;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
namespace KKdMainLib.Aet
{
public class Aet
{
public Aet()
{ AET = new AetHeader(); i = i0 = 0; IO = null; }
public AetHeader AET;
private int i, i0;
private Stream IO;
private const string x00 = "\0";
public void AETReader(string file)
{
IO = File.OpenReader(file + ".bin", true);
AET.MAIN = IO.ReadPointer<AetData>();
AET.TOUCH = IO.ReadPointer<AetData>();
if (AET.MAIN.Offset > 0)
{
AETReader(ref AET.MAIN);
if (AET.TOUCH.Offset > 0)
AETReader(ref AET.TOUCH);
}
IO.Close();
}
public void AETWriter(string file)
{
if (AET.MAIN.Offset < 0) return;
IO = File.OpenWriter(file + ".bin", true);
IO.Position = 0x20;
AETWriter(ref AET.MAIN );
if (AET.TOUCH.Offset >= 0)
{
IO.Position = IO.Length + 0x20;
AETWriter(ref AET.TOUCH);
}
IO.Position = 0;
IO.Write(AET.MAIN.Offset);
if (AET.TOUCH.Offset > 0) IO.Write(AET.TOUCH.Offset);
IO.Close();
}
public void AETReader(ref Pointer<AetData> AET)
{
IO.Position = AET.Offset;
ref AetData Aet = ref AET.Value;
Aet.Name = IO.ReadPointerString();
Aet.Unk = IO.ReadSingle();
Aet.Duration = IO.ReadSingle();
Aet.FrameRate = IO.ReadSingle();
IO.ReadInt32();
Aet.Width = IO.ReadInt32();
Aet.Height = IO.ReadInt32();
Aet.DontChange = IO.ReadInt32();
if (Aet.DontChange != 0) { IO.Close(); return; }
Aet.LayObjPointers = IO.ReadCountPointer<CountPointer<int>>();
CountPointer<SpriteEntry> Sprites = IO.ReadCountPointer<SpriteEntry>();
Aet.Unknown = IO.ReadCountPointer<int>();
Aet.LayObjDict = new Dictionary<int, int>();
Aet.ObjectsDict = new Dictionary<int, AetObject>();
Aet.SprEntsDict = new Dictionary<int, SpriteEntry>();
Aet.SpritesDict = new Dictionary<int, Sprite>();
IO.Position = Aet.LayObjPointers.Offset;
for (i = 0; i < Aet.LayObjPointers.Count; i++)
{
Aet.LayObjDict.Add(i, IO.Position);
Aet.LayObjPointers.Entries[i] = IO.ReadCountPointer<int>();
}
for (i = 0; i < Aet.LayObjPointers.Count; i++)
{
IO.Position = Aet.LayObjPointers.Entries[i].Offset;
for (i0 = 0; i0 < Aet.LayObjPointers.Entries[i].Count; i0++)
Aet.LayObjPointers.Entries[i].Entries[i0] = IO.ReadAetObject(ref Aet.ObjectsDict);
}
IO.Position = Sprites.Offset;
for (i = 0; i < Sprites.Count; i++)
{
SpriteEntry SprEnt = new SpriteEntry();
int Offset = IO.Position;
SprEnt.Unknown = IO.ReadInt32();
SprEnt.Width = IO.ReadInt16();
SprEnt.Height = IO.ReadInt16();
SprEnt.Frames = IO.ReadSingle();
SprEnt.Sprites = IO.ReadCountPointer<int>();
long Position = IO.LongPosition;
IO.Position = SprEnt.Sprites.Offset;
for (i0 = 0; i0 < SprEnt.Sprites.Count; i0++)
{
Sprite Spr = new Sprite();
int OffsetLocal = IO.Position;
Spr.Name = IO.ReadPointerString();
Spr.ID = IO.ReadInt32();
Aet.SpritesDict.Add(OffsetLocal, Spr);
SprEnt.Sprites.Entries[i0] = OffsetLocal;
}
IO.LongPosition = Position;
Aet.SprEntsDict.Add(Offset, SprEnt);
}
}
public void AETWriter(ref Pointer<AetData> AET)
{
ref AetData Aet = ref AET.Value;
if (Aet.SpritesArr != null)
{
List<int> WrittenSprites = new List<int>();
for (i = 0; i < Aet.SprEntsArr.Length; i++)
{
ref SpriteEntry SprEnt = ref Aet.SprEntsArr[i].Value;
if (SprEnt.Sprites.Count < 1) continue;
SprEnt.Sprites.Offset = IO.Position;
for (i0 = 0; i0 < SprEnt.Sprites.Count; i0++)
{
ref int I = ref SprEnt.Sprites.Entries[i0];
Aet.SpritesArr[Aet.SpritesIndDict[I]].Offset = IO.Position;
IO.Write(0);
IO.Write(Aet.SpritesArr[Aet.SpritesIndDict[I]].Value.ID);
WrittenSprites.Add(Aet.SpritesIndDict[I]);
}
}
for (i = 0; i < Aet.SpritesArr.Length; i++)
if (!WrittenSprites.Contains(i))
{
Aet.SpritesArr[i].Offset = IO.Position;
IO.Write(0);
IO.Write(Aet.SpritesArr[i].Value.ID);
WrittenSprites.Add(i);
}
}
IO.Align(0x20);
for (i = 0; i < Aet.SprEntsArr.Length; i++)
{
Aet.SprEntsArr[i].Offset = IO.Position;
ref SpriteEntry SprEnt = ref Aet.SprEntsArr[i].Value;
IO.Write(SprEnt.Unknown);
IO.Write(SprEnt.Width);
IO.Write(SprEnt.Height);
IO.Write(SprEnt.Frames);
IO.Write(SprEnt.Sprites.Count);
IO.Write(SprEnt.Sprites.Offset);
}
IO.Align(0x20);
Aet.LayObjPointers.Offset = IO.Position;
for (i = 0; i < Aet.LayObjPointers.Count; i++)
{
Aet.LayObjPointers.Entries[i].Offset = IO.Position;
IO.Write(0L);
}
List<int> NullValPointers = new List<int>();
for (i = 0; i < Aet.LayObjPointers.Count; i++)
{
for (i0 = 0; i0 < Aet.LayObjPointers.Entries[i].Count; i0++)
{
ref int I = ref Aet.LayObjPointers.Entries[i].Entries[i0];
IO.Write(ref Aet.ObjectsArr[I].Value, ref NullValPointers);
}
IO.Align(0x20);
for (i0 = 0; i0 < Aet.LayObjPointers.Entries[i].Count; i0++)
{
ref int I = ref Aet.LayObjPointers.Entries[i].Entries[i0];
IO.Write(ref Aet.ObjectsArr[I].Value, ref Aet.ObjectsArr[I].Offset);
}
}
IO.Align(0x20);
AET.Offset = IO.Position;
IO.Write(0L);
IO.Write(Aet.Duration);
IO.Write(Aet.FrameRate);
IO.Write(0);
IO.Write(Aet.Width);
IO.Write(Aet.Height);
IO.Write(0);
IO.Write(0L);
IO.Write(0L);
IO.Write(0L);
IO.Write(0L);
IO.Align(0x10);
{
Dictionary<string, int> UsedValues = new Dictionary<string, int>();
if (Aet.SpritesArr != null)
for (i = 0; i < Aet.SpritesArr.Length; i++)
IO.WritePointerString(ref UsedValues, ref Aet.SpritesArr[i].Value.Name);
//IO.Align(0x4);
for (i = 0; i < Aet.ObjectsArr.Length; i++)
{
ref AetObject Obj = ref Aet.ObjectsArr[i].Value;
if (Obj.Type == ObjType.Pic)
for (i0 = 0; i0 < Obj.Pic.Value.Marker.Count; i0++)
IO.WritePointerString(ref UsedValues, ref Obj.Pic.Value.Marker.Entries[i0].Name);
else if (Obj.Type == ObjType.Eff)
for (i0 = 0; i0 < Obj.Eff.Value.Marker.Count; i0++)
IO.WritePointerString(ref UsedValues, ref Obj.Eff.Value.Marker.Entries[i0].Name);
IO.WritePointerString(ref UsedValues, ref Obj.Name);
}
//IO.Align(0x4);
Aet.Name.Offset = IO.Position;
IO.Write(Aet.Name.Value + x00);
}
if (Aet.Unknown.Count > 0)
{
IO.Align(0x10);
Aet.Unknown.Offset = IO.Position;
for (i = 0; i < Aet.Unknown.Count * 10; i++)
IO.Write(0L);
}
IO.Align(0x10);
int ReturnPosition = IO.Position;
for (i = 0; i < NullValPointers.Count; i++)
{
IO.Position = NullValPointers[i];
IO.Write(ReturnPosition + i * 4);
}
IO.Position = ReturnPosition;
for (i = 0; i < NullValPointers.Count; i++) IO.Write(0);
IO.Align(1, true);
for (i = 0; i < Aet.ObjectsArr.Length; i++)
{
ref AetObject Obj = ref Aet.ObjectsArr[i].Value;
if (Obj.Type == ObjType.Pic)
{
IO.Position = Obj.Pic.Offset;
IO.Write(Aet.SprEntsArr[Aet.SprEntsIndDict[Obj.Pic.Value.SpriteEntryID]].Offset);
IO.Write(Obj.Pic.Value.ParentObjectID > -1 ?
Aet.ObjectsArr[Obj.Pic.Value.ParentObjectID].Offset : 0);
IO.Write(Obj.Eff.Value.Marker.Count );
IO.Write(Obj.Eff.Value.Marker.Offset);
ref CountPointer<Marker> Marker = ref Obj.Pic.Value.Marker;
IO.Position = Marker.Offset;
for (i0 = 0; i0 < Marker.Count; i0++)
{
IO.Write(Marker.Entries[i0].Frame);
IO.Write(Marker.Entries[i0]. Name.Offset);
}
}
else if (Obj.Type == ObjType.Eff)
{
IO.Position = Obj.Eff.Offset;
IO.Write(Aet.LayObjPointers.Entries[Obj.Eff.Value.LayerID].Offset);
IO.Write(Obj.Eff.Value.ParentObjectID > -1 ?
Aet.ObjectsArr[Obj.Eff.Value.ParentObjectID].Offset : 0);
IO.Write(Obj.Eff.Value.Marker.Count );
IO.Write(Obj.Eff.Value.Marker.Offset);
ref CountPointer<Marker> Marker = ref Obj.Eff.Value.Marker;
IO.Position = Marker.Offset;
for (i0 = 0; i0 < Marker.Count; i0++)
{
IO.Write(Marker.Entries[i0].Frame);
IO.Write(Marker.Entries[i0]. Name.Offset);
}
}
IO.Position = Aet.ObjectsArr[i].Offset;
IO.Write(Obj.Name.Offset);
}
if (Aet.SpritesArr != null)
for (i = 0; i < Aet.SpritesArr.Length; i++)
{
IO.Position = Aet.SpritesArr[i].Offset;
IO.Write(Aet.SpritesArr[i].Value.Name.Offset);
}
for (i = 0; i < Aet.LayObjPointers.Count; i++)
{
IO.Position = Aet.LayObjPointers.Entries[i].Offset;
IO.Write(Aet.LayObjPointers.Entries[i].Count);
IO.Write(Aet.LayObjPointers.Entries[i].Count > 0 ?
Aet.ObjectsArr[Aet.ObjectsIndDict[Aet.LayObjPointers.Entries[i].Entries[0]]].Offset : 0);
}
IO.Position = AET.Offset;
IO.Write(Aet.Name.Offset);
IO.Position = AET.Offset + 0x20;
IO.Write(Aet.LayObjPointers.Count );
IO.Write(Aet.LayObjPointers.Offset);
IO.Write(Aet.SprEntsArr.Length);
IO.Write(Aet.SprEntsArr[0].Offset);
if (Aet.Unknown.Count > 0)
{ IO.Write(Aet.Unknown.Count); IO.Write(Aet.Unknown.Offset); }
else IO.Write(0L);
}
public void MsgPackReader(string file, bool JSON)
{
AET = new AetHeader();
AET.MAIN .Offset = -1;
AET.TOUCH.Offset = -1;
MsgPack MsgPack = file.ReadMP(JSON);
if (!MsgPack.Element<MsgPack>("Aet", out MsgPack Aet)) { MsgPack = null; return; }
if (Aet.Array != null)
if (Aet.Array.Length == 1)
{
if (Aet.Array[0] is MsgPack MAIN ) MsgPackReader(MAIN , ref AET.MAIN );
}
else if (Aet.Array.Length == 2)
{
if (Aet.Array[0] is MsgPack MAIN ) MsgPackReader(MAIN , ref AET.MAIN );
if (Aet.Array[1] is MsgPack TOUCH) MsgPackReader(TOUCH, ref AET.TOUCH);
}
MsgPack = null;
}
public void MsgPackWriter(string file, bool JSON)
{
if (this.AET.MAIN .Offset <= 0) return;
MsgPack AET = new MsgPack("Aet", this.AET.TOUCH.Offset > 0 ? 2 : 1);
AET[0] = MsgPackWriter(ref this.AET.MAIN);
if (this.AET.TOUCH.Offset > 0) AET[1] = MsgPackWriter(ref this.AET.TOUCH);
AET.WriteAfterAll(true, file, JSON);
}
public void MsgPackReader(MsgPack AET, ref Pointer<AetData> AetData)
{
MsgPack Temp = new MsgPack();
AetData.Offset = -1;
ref AetData Aet = ref AetData.Value;
Aet.Name.Value = AET.ReadString("Name" );
Aet.Unk = AET.ReadSingle("Unk" );
Aet.Duration = AET.ReadSingle("Duration" );
Aet.FrameRate = AET.ReadSingle("FrameRate");
Aet.Width = AET.ReadInt32("Width" );
Aet.Height = AET.ReadInt32("Height");
if (AET.Element<MsgPack>("Layers", out MsgPack Layers))
{
Aet.LayObjPointers.Count = Layers.Array.Length;
for (i = 0; i < Aet.LayObjPointers.Count; i++)
if (Layers[i] is MsgPack ObjectID)
{
Aet.LayObjPointers.Entries[i].Count =
ObjectID.Array == null ? 0 : ObjectID.Array.Length;
for (i0 = 0; i0 < Aet.LayObjPointers.Entries[i].Count; i0++)
if (ObjectID.Array[i0] is MsgPack msg)
Aet.LayObjPointers.Entries[i].Entries[i0] = msg.ReadInt32();
}
}
else return;
Aet.ObjectsIndDict = new Dictionary<int, int>();
Aet.SprEntsIndDict = new Dictionary<int, int>();
Aet.SpritesIndDict = new Dictionary<int, int>();
int? ID = null;
if (AET.Element("SpriteEntry", out Temp))
{
Aet.SprEntsArr = new Pointer<SpriteEntry>[1];
ID = Aet.SprEntsArr[0].Value.ReadMP(Temp);
if (ID != null) Aet.SprEntsIndDict.Add(ID.Value, 0);
}
else if (AET.Element<MsgPack>("SpriteEntries", out Temp))
{
Aet.SprEntsArr = new Pointer<SpriteEntry>[Temp.Array.Length];
for (i = 0; i < Aet.SprEntsArr.Length; i++)
if (Temp[i] is MsgPack SpriteEntry)
{
ID = Aet.SprEntsArr[i].Value.ReadMP(SpriteEntry);
if (ID != null) Aet.SprEntsIndDict.Add(ID.Value, i);
}
}
else return;
if (AET.Element("Object", out Temp))
{
Aet.ObjectsArr = new Pointer<AetObject>[1];
ID = Aet.ObjectsArr[0].Value.ReadMP(Temp, 0, ref Aet);
if (ID != null) Aet.ObjectsIndDict.Add(ID.Value, 0);
}
else if (AET.Element<MsgPack>("Objects", out Temp))
{
Aet.ObjectsArr = new Pointer<AetObject>[Temp.Array.Length];
for (i = 0; i < Aet.ObjectsArr.Length; i++)
if (Temp[i] is MsgPack Object)
{
ID = Aet.ObjectsArr[i].Value.ReadMP(Object, i, ref Aet);
if (ID != null) Aet.ObjectsIndDict.Add(ID.Value, i);
}
}
else return;
if (AET.Element("Sprite", out Temp))
{
Aet.SpritesArr = new Pointer<Sprite>[1];
ID = Aet.SpritesArr[0].Value.ReadMP(Temp);
if (ID != null) Aet.SpritesIndDict.Add(ID.Value, 0);
}
else if (AET.Element<MsgPack>("Sprites", out Temp))
{
Aet.SpritesArr = new Pointer<Sprite>[Temp.Array.Length];
for (i = 0; i < Aet.SpritesArr.Length; i++)
if (Temp[i] is MsgPack Sprite)
{
ID = Aet.SpritesArr[i].Value.ReadMP(Sprite);
if (ID != null) Aet.SpritesIndDict.Add(ID.Value, i);
}
}
if (AET.Element("Unknown", out Temp))
Aet.Unknown.Count = Temp.ReadInt32();
AetData.Offset = 0;
}
public MsgPack MsgPackWriter(ref Pointer<AetData> AetData)
{
if (AetData.Offset <= 0) return null;
ref AetData Aet = ref AetData.Value;
Aet.ObjectsIndDict = Aet.ObjectsDict.GetIndDict();
Aet.SpritesIndDict = Aet.SpritesDict.GetIndDict();
Aet.SprEntsIndDict = Aet.SprEntsDict.GetIndDict();
Aet.ObjectsArr = Aet.ObjectsDict.ToPointerArray();
Aet.SpritesArr = Aet.SpritesDict.ToPointerArray();
Aet.SprEntsArr = Aet.SprEntsDict.ToPointerArray();
Aet.ObjectsDict = null;
Aet.SpritesDict = null;
Aet.SprEntsDict = null;
MsgPack AET = new MsgPack().Add("Name", Aet.Name.Value).Add("Duration",
Aet.Duration).Add("FrameRate", Aet.FrameRate).Add("Width",
Aet.Width).Add("Height", Aet.Height).Add("Unk", Aet.Unk);
if (Aet.LayObjPointers.Count > 0)
{
MsgPack Layers = new MsgPack("Layers", Aet.LayObjPointers.Count);
for (i = 0; i < Aet.LayObjPointers.Count; i++)
if (Aet.LayObjPointers.Entries[i].Count > 0)
{
MsgPack Objects = new MsgPack(Aet.LayObjPointers.Entries[i].Count);
for (i0 = 0; i0 < Aet.LayObjPointers.Entries[i].Count; i0++)
Objects[i0] = Aet.ObjectsIndDict[Aet.LayObjPointers.Entries[i].Entries[i0]];
Layers[i] = Objects;
}
AET.Add(Layers);
}
if (Aet.SprEntsArr.Length == 1)
AET.Add(Aet.SprEntsArr[0].Value.WriteMP(0, ref Aet.SpritesIndDict, "SpriteEntry"));
else if (Aet.SprEntsArr.Length > 0)
{
MsgPack SpriteEntries = new MsgPack("SpriteEntries", Aet.SprEntsArr.Length);
for (i = 0; i < Aet.SprEntsArr.Length; i++)
SpriteEntries[i] = Aet.SprEntsArr[i].Value.WriteMP(i, ref Aet.SpritesIndDict);
AET.Add(SpriteEntries);
}
if (Aet.ObjectsArr.Length == 1)
AET.Add(Aet.ObjectsArr[0].Value.WriteMP(0, ref Aet, "Object"));
else if (Aet.ObjectsArr.Length > 1)
{
MsgPack Objects = new MsgPack("Objects", Aet.ObjectsArr.Length);
for (i = 0; i < Aet.ObjectsArr.Length; i++)
Objects[i] = Aet.ObjectsArr[i].Value.WriteMP(i, ref Aet);
AET.Add(Objects);
}
if (Aet.SpritesArr.Length == 1)
AET.Add(Aet.SpritesArr[0].Value.WriteMP(0, "Sprite"));
else if (Aet.SpritesArr.Length > 1)
{
MsgPack Sprites = new MsgPack("Sprites", Aet.SpritesArr.Length);
for (i = 0; i < Aet.SpritesArr.Length; i++)
Sprites[i] = Aet.SpritesArr[i].Value.WriteMP(i);
AET.Add(Sprites);
}
if (Aet.Unknown.Count > 0)
AET.Add("Unknown", Aet.Unknown.Count);
return AET;
}
}
public struct AetHeader
{
public Pointer<AetData> MAIN ;
public Pointer<AetData> TOUCH;
}
public struct AetData
{
public Pointer<string> Name;
public float Unk;
public float Duration;
public float FrameRate;
public int Width;
public int Height;
public int DontChange;
public CountPointer<CountPointer<int>> LayObjPointers;
public CountPointer<int> Unknown;
public Dictionary<int, int> LayObjDict;
public Dictionary<int, int> ObjectsIndDict;
public Dictionary<int, int> SpritesIndDict;
public Dictionary<int, int> SprEntsIndDict;
public Pointer< AetObject>[] ObjectsArr;
public Pointer<SpriteEntry>[] SprEntsArr;
public Pointer< Sprite>[] SpritesArr;
public Dictionary<int, AetObject> ObjectsDict;
public Dictionary<int, SpriteEntry> SprEntsDict;
public Dictionary<int, Sprite> SpritesDict;
}
public struct AetObject
{
public int Offset;
public Pointer<string> Name;
public float StartTime0;
public float LoopDuration;
public float StartTime1;
public float PlaybackSpeed;
public byte Unk0;
public byte Unk1;
public byte Unk2;
public ObjType Type;
public Pointer<Pic> Pic;
public Pointer<Aif> Aif;
public Pointer<Eff> Eff;
public int? ReadMP(MsgPack msg, int i, ref AetData Aet)
{
Name.Value = msg.ReadString("Name" );
StartTime0 = msg.ReadSingle("StartTime0" );
LoopDuration = msg.ReadSingle("LoopDuration" );
StartTime1 = msg.ReadSingle("StartTime1" );
PlaybackSpeed = msg.ReadSingle("PlaybackSpeed");
Unk0 = msg.ReadUInt8("Unk0");
Unk1 = msg.ReadUInt8("Unk1");
Unk2 = msg.ReadUInt8("Unk2");
if (msg.Element("Pic", out MsgPack Pic))
{ Type = ObjType.Pic; this.Pic = new Pointer<Pic>() { Value = new Pic().ReadMP(Pic, i, ref Aet) }; }
else if (msg.Element("Aif", out MsgPack Aif))
{ Type = ObjType.Aif; this.Aif = new Pointer<Aif>() { Value = new Aif().ReadMP(Aif) }; }
else if (msg.Element("Eff", out MsgPack Eff))
{ Type = ObjType.Eff; this.Eff = new Pointer<Eff>() { Value = new Eff().ReadMP(Eff, i, ref Aet) }; }
else Type = ObjType.Nop;
return msg.ReadNInt32("ID");
}
public MsgPack WriteMP(int Id, ref AetData Aet, string name = null)
{
MsgPack AetObject = new MsgPack(name).Add("ID", Id).Add("Name", Name.Value)
.Add("StartTime0", StartTime0).Add("LoopDuration", LoopDuration)
.Add("StartTime1", StartTime1).Add("PlaybackSpeed", PlaybackSpeed)
.Add("Unk0", Unk0).Add("Unk1", Unk1).Add("Unk2", Unk2);
if (Type == ObjType.Pic) AetObject.Add(Pic.Value.WriteMP(ref Aet));
else if (Type == ObjType.Aif) AetObject.Add(Aif.Value.WriteMP());
else if (Type == ObjType.Eff) AetObject.Add(Eff.Value.WriteMP(ref Aet));
return AetObject;
}
}
public struct Pic
{
public int SpriteEntryID;
public int ParentObjectID;
public CountPointer<Marker> Marker;
public Pointer<AnimationData> Data;
public Pic ReadMP(MsgPack msg, int i, ref AetData Aet)
{
int SpriteEntryID = msg.ReadInt32("SpriteEntryID");
if (Aet.SprEntsIndDict.ContainsValue(SpriteEntryID))
this.SpriteEntryID = Aet.SprEntsIndDict.GetKey(SpriteEntryID);
this.ParentObjectID = -1;
int? ParentObjectID = msg.ReadNInt32("ParentObjectID");
if (ParentObjectID != null)
this.ParentObjectID = ParentObjectID.Value;
if (msg.Element("Marker", out MsgPack Marker))
{
this.Marker.Count = 1;
this.Marker.Entries[0].ReadMP(Marker);
}
else if (msg.Element<MsgPack>("Markers", out MsgPack Markers))
{
this.Marker.Count = Markers.Array.Length;
for (i = 0; i < Markers.Array.Length; i++)
if (Markers[i] is MsgPack Object)
this.Marker.Entries[i].ReadMP(Object);
}
else this.Marker.Entries = null;
Data.Value.ReadMP(msg);
return this;
}
public MsgPack WriteMP(ref AetData Aet)
{
MsgPack Pic = new MsgPack("Pic");
if (Aet.SprEntsIndDict.ContainsKey(SpriteEntryID))
Pic.Add("SpriteEntryID", Aet.SprEntsIndDict[SpriteEntryID]);
if (ParentObjectID > 0)
if (Aet.ObjectsIndDict.ContainsKey(ParentObjectID))
Pic.Add("ParentObjectID", Aet.ObjectsIndDict[ParentObjectID]);
if (Marker.Count == 1)
Pic.Add(Marker.Entries[0].WriteMP("Marker"));
else if (Marker.Count > 1)
{
MsgPack Markers = new MsgPack("Markers", Marker.Count);
for (int i = 0; i < Marker.Count; i++)
Markers[i] = Marker.Entries[i].WriteMP();
Pic.Add(Markers);
}
Pic.Add(Data.Value.WriteMP());
return Pic;
}
}
public struct Aif
{
public Pointer<int> Value;
public int Zero0;
public int Zero1;
public int Zero2;
public int Zero3;
public int Pointer;
public CountPointer<float> Unk0;
public CountPointer<float> Unk1;
public CountPointer<float> Unk2;
public CountPointer<float> Unk3;
public Aif ReadMP(MsgPack msg)
{
Value.Value = msg.ReadInt32("Value");
msg.ReadMP(ref Unk0, "Unk0");
msg.ReadMP(ref Unk1, "Unk1");
msg.ReadMP(ref Unk2, "Unk2");
msg.ReadMP(ref Unk3, "Unk3");
return this;
}
public MsgPack WriteMP() =>
new MsgPack("Aif").Add("Value", Value.Value).Add(Unk0.WriteMP("Unk0")).Add(Unk1
.WriteMP("Unk1")).Add(Unk2.WriteMP("Unk2")).Add(Unk3.WriteMP("Unk3"));
}
public struct Eff
{
public int LayerID;
public int ParentObjectID;
public CountPointer<Marker> Marker;
public Pointer<AnimationData> Data;
public Eff ReadMP(MsgPack msg, int i, ref AetData Aet)
{
LayerID = msg.ReadInt32("LayerID");
this.ParentObjectID = -1;
int? ParentObjectID = msg.ReadNInt32("ParentObjectID");
if (ParentObjectID != null)
this.ParentObjectID = ParentObjectID.Value;
if (msg.Element("Marker", out MsgPack Marker))
{
this.Marker.Count = 1;
this.Marker.Entries[0].ReadMP(Marker);
}
else if (msg.Element<MsgPack>("Markers", out MsgPack Markers))
{
this.Marker.Count = Markers.Array.Length;
for (i = 0; i < Markers.Array.Length; i++)
if (Markers[i] is MsgPack Object)
this.Marker.Entries[i].ReadMP(Object);
}
else this.Marker.Entries = null;
Data.Value.ReadMP(msg);
return this;
}
public MsgPack WriteMP(ref AetData Aet)
{
MsgPack Eff = new MsgPack("Eff");
if (Aet.LayObjDict.ContainsValue(LayerID))
Eff.Add("LayerID", Aet.LayObjDict.GetKey(LayerID));
if (ParentObjectID > 0)
if (Aet.ObjectsIndDict.ContainsKey(ParentObjectID))
Eff.Add("ParentObjectID", Aet.ObjectsIndDict[ParentObjectID]);
if (Marker.Count == 1)
Eff.Add(Marker.Entries[0].WriteMP("Marker"));
else if (Marker.Count > 1)
{
MsgPack Markers = new MsgPack("Markers", Marker.Count);
for (int i = 0; i < Marker.Count; i++)
Markers[i] = Marker.Entries[i].WriteMP();
Eff.Add(Markers);
}
Eff.Add(Data.Value.WriteMP());
return Eff;
}
}
public struct Marker
{
public float Frame;
public Pointer<string> Name;
public void ReadMP(MsgPack mp)
{ Frame = mp.ReadSingle("Frame"); Name.Value = mp.ReadString("Name"); }
public MsgPack WriteMP(string name = null) =>
new MsgPack(name).Add("Frame", Frame).Add("Name", Name.Value);
}
public struct SubAnimationData
{
public KeyFrameEntry OriginX;
public KeyFrameEntry OriginY;
public KeyFrameEntry PositionX;
public KeyFrameEntry PositionY;
public KeyFrameEntry Rotation;
public KeyFrameEntry ScaleX;
public KeyFrameEntry ScaleY;
public KeyFrameEntry Opacity;
public void ReadMP(MsgPack msg)
{
OriginX.ReadMP(msg, "OriginX");
OriginY.ReadMP(msg, "OriginY");
PositionX.ReadMP(msg, "PositionX");
PositionY.ReadMP(msg, "PositionY");
Rotation .ReadMP(msg, "Rotation" );
ScaleX.ReadMP(msg, "ScaleX");
ScaleY.ReadMP(msg, "ScaleY");
Opacity .ReadMP(msg, "Opacity" );
}
public MsgPack WriteMP()
{
MsgPack AnimationData = new MsgPack("SubAnimationData");
WriteMP(ref AnimationData);
return AnimationData;
}
public void WriteMP(ref MsgPack msg)
{
msg.Add( OriginX.WriteMP( "OriginX"));
msg.Add( OriginY.WriteMP( "OriginY"));
msg.Add(PositionX.WriteMP("PositionX"));
msg.Add(PositionY.WriteMP("PositionY"));
msg.Add(Rotation .WriteMP("Rotation" ));
msg.Add( ScaleX.WriteMP( "ScaleX"));
msg.Add( ScaleY.WriteMP( "ScaleY"));
msg.Add(Opacity .WriteMP("Opacity" ));
}
}
public struct AnimationData
{
public BlendMode BlendMode;
public byte Unk0;
public bool UseTextureMask;
public byte Unk1;
public SubAnimationData Anim;
public Pointer<SubAnimationData> SubAnim;
public void ReadMP(MsgPack msg)
{
if (!msg.Element("AnimationData", out MsgPack Data)) return;
System.Enum.TryParse(Data.ReadString("BlendMode"), out BlendMode);
Unk0 = Data.ReadUInt8 ("Unk0");
UseTextureMask = Data.ReadBoolean("UseTextureMask");
Unk1 = Data.ReadUInt8 ("Unk1");
Anim.ReadMP(Data);
SubAnim.Offset = -1;
if (Data.Element("SubAnimationData", out MsgPack SubAnimationData))
{ SubAnim.Offset = 0; SubAnim.Value.ReadMP(SubAnimationData); }
}
public MsgPack WriteMP()
{
MsgPack AnimationData = new MsgPack("AnimationData")
.Add("BlendMode", BlendMode.ToString()).Add("Unk0", Unk0)
.Add("UseTextureMask", UseTextureMask) .Add("Unk1", Unk1);
Anim.WriteMP(ref AnimationData);
if (SubAnim.Offset > 0)
AnimationData.Add(SubAnim.Value.WriteMP());
return AnimationData;
}
}
public struct KeyFrameEntry
{
public int Count;
public int Offset;
public float Value;
public float[] ArrValue;
public float[] KeyFrame;
public float[] Interpolation;
public void ReadMP(MsgPack msg, string name)
{
float? Value = msg.ReadNSingle(name);
if (Value != null) { Count = 1; this.Value = Value.Value; return; }
if (!msg.Element<MsgPack>(name, out MsgPack Temp)) return;
MsgPack temp;
Count = Temp.Array.Length;
if (Count == 0) return;
ArrValue = new float[Count];
KeyFrame = new float[Count];
Interpolation = new float[Count];
for (int i = 0; i < Count; i++)
{
temp = Temp[i] as MsgPack;
KeyFrame [i] = temp.ReadSingle("KeyFrame" );
ArrValue [i] = temp.ReadSingle("Value" );
Interpolation[i] = temp.ReadSingle("Interpolation");
}
}
public MsgPack WriteMP(string name)
{
if (Count < 1) return MsgPack.Null;
if (Count == 1) return new MsgPack(name, MsgPack.Types.Float32, Value);
MsgPack KFE = new MsgPack(name, Count);
for (int i = 0; i < Count; i++) KFE[i] = new MsgPack().Add("KeyFrame", KeyFrame[i])
.Add("Value", ArrValue[i]).Add("Interpolation", Interpolation[i]);
return KFE;
}
}
public struct SpriteEntry
{
public int Unknown;
public short Width;
public short Height;
public float Frames;
public CountPointer<int> Sprites;
public int? ReadMP(MsgPack msg)
{
Unknown = msg.ReadInt32 ("Unknown");
Width = msg.ReadInt16 ("Width" );
Height = msg.ReadInt16 ("Height" );
Frames = msg.ReadSingle("Frames" );
if (msg.Element("SpriteID", out MsgPack SpriteID))
{
Sprites = new CountPointer<int> { Count = 1 };
Sprites.Entries[0] = SpriteID.ReadInt32();
}
else if (msg.Element<MsgPack>("SpriteIDs", out MsgPack SpriteIDs))
{
Sprites = new CountPointer<int> { Count = SpriteIDs.Array.Length };
for (int i0 = 0; i0 < Sprites.Count; i0++)
Sprites.Entries[i0] = (SpriteIDs[i0] as MsgPack).ReadInt32();
}
return msg.ReadNInt32("ID");
}
public MsgPack WriteMP(int Id, ref Dictionary<int, int> SpritesIndDict, string Name = null)
{
MsgPack SpriteEntry = new MsgPack(Name).Add("ID", Id)
.Add("Width", Width).Add("Height", Height).Add("Unknown", Unknown);
if (Sprites.Count > 0) SpriteEntry.Add("Frames", Frames);
if (Sprites.Count == 1)
SpriteEntry.Add("SpriteID", SpritesIndDict[Sprites.Entries[0]]);
else if (Sprites.Count > 1)
{
MsgPack SpriteIDs = new MsgPack("SpriteIDs", Sprites.Count);
for (int i0 = 0; i0 < Sprites.Count; i0++)
SpriteIDs[i0] = SpritesIndDict[Sprites.Entries[i0]];
SpriteEntry.Add(SpriteIDs);
}
return SpriteEntry;
}
}
public struct Sprite
{
public Pointer<string> Name;
public int ID;
public MsgPack WriteMP(int Id, string name = null) =>
new MsgPack(name).Add("ID", Id).Add("Name", Name.Value).Add("SprDB_ID", ID);
public int? ReadMP(MsgPack mp)
{ ID = mp.ReadInt32("SprDB_ID"); Name.Value = mp.ReadString("Name"); return mp.ReadNInt32("ID"); }
}
public struct CountPointer<T>
{
public int Count { get => Entries == null ? 0 : Entries.Length; set => Entries = new T[value]; }
public int Offset;
public T[] Entries;
public override string ToString() => Entries.ToString();
}
public struct Pointer<T>
{
public int Offset;
public T Value;
public override string ToString() => Value.ToString();
}
public enum ObjType : byte
{
Nop = 0,
Pic = 1,
Aif = 2,
Eff = 3,
}
public enum BlendMode : byte
{
Alpha = 3,
Additive = 5,
DstColorZero = 6,
SrcAlphaOneMinusSrcColor = 7,
Transparent = 8,
}
}
+465
View File
@@ -0,0 +1,465 @@
using System.Collections.Generic;
using System.Linq;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
namespace KKdMainLib.Aet
{
public static class AetExt
{
private static System.Text.Encoding ShiftJIS = System.Text.Encoding.GetEncoding(932);
public static Dictionary<TKey, int> GetIndDict<TKey, TVal>(this Dictionary<TKey, TVal> Dict)
{
List<TKey> Keys = Dict.Keys.ToList();
Dictionary<TKey, int> IndDict = new Dictionary<TKey, int>();
for (int i = 0; i < Keys.Count; i++)
IndDict.Add(Keys[i], i);
return IndDict;
}
public static Pointer<T>[] ToPointerArray<T>(this Dictionary<int, T> val)
{
Pointer<T>[] arr = new Pointer<T>[val.Count];
for (int i = 0; i < val.Count; i++)
arr[i] = val.ElementAt(i).ToPointer();
return arr;
}
public static Pointer<T> ReadPointer<T>(this Stream IO) =>
new Pointer<T> { Offset = IO.ReadInt32() };
public static Pointer<string> ReadPointerString(this Stream IO)
{ Pointer<string> val = IO.ReadPointer<string>();
val.Value = IO.ReadStringAtOffset(val.Offset); return val; }
public static Pointer<string> ReadPointerStringShiftJIS(this Stream IO)
{ Pointer<string> val = IO.ReadPointer<string>();
val.Value = ShiftJIS.GetString(IO.ReadAtOffset(val.Offset)); return val; }
public static void WriteShiftJIS(this Stream IO, string String) =>
IO.Write(ShiftJIS.GetBytes(String));
public static CountPointer<T> ReadCountPointer<T>(this Stream IO)
{ CountPointer<T> val = new CountPointer<T> { Count = IO.ReadInt32(),
Offset = IO.ReadInt32() }; val.Entries = new T[val.Count]; return val; }
public static Pointer<T> ToPointer<T>(this KeyValuePair<int, T> val) =>
new Pointer<T> { Offset = val.Key, Value = val.Value };
public static void ReadMP(this MsgPack msg, ref CountPointer<float> val, string Name)
{
val.Offset = 0;
val.Entries = null;
if (msg.ContainsKey(Name))
{
val.Count = 1;
val.Entries[0] = msg.ReadSingle(Name);
}
else if(msg.Element<MsgPack>(Name, out MsgPack Temp))
{
val.Count = Temp.Array.Length;
for (int i = 0; i < val.Count; i++)
if (Temp[i] is MsgPack temp)
val.Entries[i] = temp.ReadSingle();
}
}
public static MsgPack WriteMP(this CountPointer<float> val, string Name)
{
if (val.Count == 1) return new MsgPack(Name, MsgPack.Types.Float32, val.Entries[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;
}
return MsgPack.Null;
}
public static int ReadAetObject(this Stream IO, ref Dictionary<int, AetObject> ObjectsDict)
{
AetObject Anim = new AetObject();
int AnimOffset = IO.Position;
if (ObjectsDict.ContainsKey(AnimOffset)) return AnimOffset;
Anim.Name = IO.ReadPointerString();
Anim.StartTime0 = IO.ReadSingle();
Anim.LoopDuration = IO.ReadSingle();
Anim.StartTime1 = IO.ReadSingle();
Anim.PlaybackSpeed = IO.ReadSingle();
Anim.Unk0 = IO.ReadByte();
Anim.Unk1 = IO.ReadByte();
Anim.Unk2 = IO.ReadByte();
Anim.Type = (ObjType)IO.ReadByte();
if (Anim.Type == ObjType.Pic) Anim.Pic = IO.ReadPic(ref ObjectsDict);
else if (Anim.Type == ObjType.Aif) Anim.Aif = IO.ReadAif();
else if (Anim.Type == ObjType.Eff) Anim.Eff = IO.ReadEff(ref ObjectsDict);
IO.Position = AnimOffset + 0x30;
if (!ObjectsDict.ContainsKey(AnimOffset))
ObjectsDict.Add(AnimOffset, Anim);
return AnimOffset;
}
public static void Write(this Stream IO, ref AetObject Anim, ref List<int> NullValPointers)
{
if (Anim.Type == ObjType.Pic)
{
if (Anim.Pic.Value.Marker.Count > 0)
{
Anim.Pic.Value.Marker.Offset = IO.Position;
for (int i = 0; i < Anim.Pic.Value.Marker.Count; i++) IO.Write(0L);
}
IO.Write(ref Anim.Pic.Value.Data, ref NullValPointers);
}
else if (Anim.Type == ObjType.Aif) IO.Write(ref Anim.Aif);
else if (Anim.Type == ObjType.Eff)
{
if (Anim.Eff.Value.Marker.Count > 0)
{
Anim.Eff.Value.Marker.Offset = IO.Position;
for (int i = 0; i < Anim.Eff.Value.Marker.Count; i++) IO.Write(0L);
}
IO.Write(ref Anim.Eff.Value.Data, ref NullValPointers);
}
}
public static void Write(this Stream IO, ref AetObject Anim, ref int Offset)
{
Offset = IO.Position;
IO.Write(0);
IO.Write(Anim.StartTime0 );
IO.Write(Anim.LoopDuration );
IO.Write(Anim.StartTime1 );
IO.Write(Anim.PlaybackSpeed);
IO.Write(Anim.Unk0);
IO.Write(Anim.Unk1);
IO.Write(Anim.Unk2);
IO.Write((byte)Anim.Type);
if (Anim.Type == ObjType.Pic) IO.Write(ref Anim.Pic);
else if (Anim.Type == ObjType.Aif)
{
Anim.Aif.Offset = IO.Position;
IO.Write(Anim.Aif.Value.Value.Offset);
IO.Write(0L);
IO.Write(0L);
IO.Write(Anim.Aif.Value.Pointer);
}
else if (Anim.Type == ObjType.Eff) IO.Write(ref Anim.Eff);
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.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();
Data.PositionY = IO.ReadKeyFrameEntry();
Data.Rotation = IO.ReadKeyFrameEntry();
Data. ScaleX = IO.ReadKeyFrameEntry();
Data. ScaleY = IO.ReadKeyFrameEntry();
Data.Opacity = IO.ReadKeyFrameEntry();
return Data;
}
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);
IO.ReadKeyFrameEntry(ref Data.PositionY);
IO.ReadKeyFrameEntry(ref Data.Rotation );
IO.ReadKeyFrameEntry(ref Data. ScaleX);
IO.ReadKeyFrameEntry(ref Data. ScaleY);
IO.ReadKeyFrameEntry(ref Data.Opacity );
}
public static void Write(this Stream IO, ref Pointer<AnimationData> Anim, ref List<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)
{
IO.Align(0x20);
Data.SubAnim.Offset = IO.Position;
IO.Write(ref Data.SubAnim.Value, ref NullValPointers, Flags);
}
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;
Flags |= IO.Write(ref Data.PositionX) ? 0b00100000 : 0;
Flags |= IO.Write(ref Data.PositionY) ? 0b00010000 : 0;
Flags |= IO.Write(ref Data.Rotation ) ? 0b00001000 : 0;
Flags |= IO.Write(ref Data. ScaleX) ? 0b00000100 : 0;
Flags |= IO.Write(ref Data. ScaleY) ? 0b00000010 : 0;
Flags |= IO.Write(ref Data.Opacity ) ? 0b00000001 : 0;
return (byte)Flags;
}
public static void Write(this Stream IO, ref SubAnimationData Data, ref List<int> NullValPointers, byte Flags)
{
IO.Write(Data. OriginX.Count );
if ((Flags & 0b10000000) == 0b10000000) NullValPointers.Add(IO.Position);
IO.Write(Data. OriginX.Offset);
IO.Write(Data. OriginY.Count );
if ((Flags & 0b01000000) == 0b01000000) NullValPointers.Add(IO.Position);
IO.Write(Data. OriginY.Offset);
IO.Write(Data.PositionX.Count );
if ((Flags & 0b00100000) == 0b00100000) NullValPointers.Add(IO.Position);
IO.Write(Data.PositionX.Offset);
IO.Write(Data.PositionY.Count );
if ((Flags & 0b00010000) == 0b00010000) NullValPointers.Add(IO.Position);
IO.Write(Data.PositionY.Offset);
IO.Write(Data.Rotation .Count );
if ((Flags & 0b00001000) == 0b00001000) NullValPointers.Add(IO.Position);
IO.Write(Data.Rotation .Offset);
IO.Write(Data. ScaleX.Count );
if ((Flags & 0b00000100) == 0b00000100) NullValPointers.Add(IO.Position);
IO.Write(Data. ScaleX.Offset);
IO.Write(Data. ScaleY.Count );
if ((Flags & 0b00000010) == 0b00000010) NullValPointers.Add(IO.Position);
IO.Write(Data. ScaleY.Offset);
IO.Write(Data.Opacity .Count );
if ((Flags & 0b00000001) == 0b00000001) NullValPointers.Add(IO.Position);
IO.Write(Data.Opacity .Offset);
}
public static KeyFrameEntry ReadKeyFrameEntry(this Stream IO) =>
new KeyFrameEntry { Count = IO.ReadInt32(), Offset = IO.ReadInt32() };
public static void ReadKeyFrameEntry(this Stream IO, ref KeyFrameEntry entry)
{
if (entry.Count < 1) return;
IO.Position = entry.Offset;
if (entry.Count == 1) { entry.Value = IO.ReadSingle(); return; }
entry.Interpolation = new float[entry.Count];
entry.KeyFrame = new float[entry.Count];
entry.ArrValue = new float[entry.Count];
for (int i = 0; i < entry.Count; i++) entry.KeyFrame [i] = IO.ReadSingle();
for (int i = 0; i < entry.Count; i++)
{ entry.ArrValue[i] = IO.ReadSingle(); entry.Interpolation[i] = IO.ReadSingle(); }
}
public static bool Write(this Stream IO, ref KeyFrameEntry entry)
{
if (entry.Count == 0) return false;
if (entry.Count > 2) IO.Align(0x20);
entry.Offset = IO.Position;
if (entry.Count == 1) if (entry.Value == 0) return true;
else { IO.Write(entry.Value); return false; }
for (int i = 0; i < entry.Count; i++) IO.Write(entry.KeyFrame [i]);
for (int i = 0; i < entry.Count; i++)
{ IO.Write(entry.ArrValue[i]); IO.Write(entry.Interpolation[i]); }
return false;
}
public static void ReadMP(this CountPointer<Marker> mark, MsgPack msg)
{
if (msg.Element("Marker", out MsgPack Marker))
{
mark.Count = 1;
mark.Entries[0].ReadMP(Marker);
}
else if (msg.Element<MsgPack>("Markers", out MsgPack Markers))
{
mark.Count = Markers.Array.Length;
for (int i = 0; i < mark.Count; i++)
mark.Entries[i].ReadMP(Markers[i] as MsgPack);
}
}
public static void WritePointerString(this Stream IO,
ref Dictionary<string, int> Dict, ref Pointer<string> Str)
{
if (Dict.ContainsKey(Str.Value)) Str.Offset = Dict[Str.Value];
else
{ Str.Offset = IO.Position; Dict.Add(Str.Value, Str.Offset); IO.WriteShiftJIS(Str.Value + "\0"); }
}
}
}
+268
View File
@@ -0,0 +1,268 @@
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
using System.Collections.Generic;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
namespace KKdMainLib.DB
{
public class Aet
{
public AetSet[] AetSets;
private Stream IO;
private int i, i0, i1, i2;
public void BINReader(string file)
{
IO = File.OpenReader(file + ".bin");
int aetSetsLength = IO.ReadInt32();
int aetSetsOffset = IO.ReadInt32();
int aetsLength = IO.ReadInt32();
int aetsOffset = IO.ReadInt32();
IO.Position = aetSetsOffset;
AetSets = new AetSet[aetSetsLength];
for (i = 0; i < aetSetsLength; i++)
{
AetSets[i].Id = IO.ReadInt32();
AetSets[i].Name = IO.ReadStringAtOffset();
AetSets[i].FileName = IO.ReadStringAtOffset();
IO.ReadInt32();
AetSets[i].SpriteSetId = IO.ReadInt32();
}
int setIndex;
AET aet = new AET();
int[] AetCount = new int[aetSetsLength];
IO.Position = aetsOffset;
for (i = 0; i < aetsLength; i++)
{
IO.LongPosition += 10;
setIndex = IO.ReadInt16();
AetCount[setIndex]++;
}
for (int i = 0; i < aetSetsLength; i++)
{
AetSets[i].Aets = new AET[AetCount[i]];
AetCount[i] = 0;
}
IO.Position = aetsOffset;
for (i = 0; i < aetsLength; i++)
{
aet.Id = IO.ReadInt32();
aet.Name = IO.ReadStringAtOffset();
IO.ReadInt16();
setIndex = IO.ReadInt16();
AetSets[setIndex].Aets[AetCount[setIndex]] = aet; AetCount[setIndex]++;
}
IO.Close();
}
public void BINWriter(string file)
{
if (AetSets == null) return;
if (AetSets.Length == 0) return;
List<string> SetName = new List<string>();
List<string> SetFileName = new List<string>();
List<int> Ids = new List<int>();
List<int> SetIds = new List<int>();
List<int> NotAdd = new List<int>();
AET temp;
AetSet set;
for (i = 0; i < AetSets.Length; i++)
{
set = AetSets[i];
if (set. Name != null)
if (SetName .Contains(set. Name)) { NotAdd.Add(i); continue; }
else SetName .Add (set. Name);
if (set.FileName != null)
if (SetFileName.Contains(set.FileName)) { NotAdd.Add(i); continue; }
else SetFileName.Add (set.FileName);
if (set.NewId)
{
AetSets[i].Id = null;
for (i0 = 0; i0 < set.Aets.Length; i0++) AetSets[i].Aets[i0].Id = null;
continue;
}
if (set.Id != null)
if (SetIds.Contains((int)set.Id)) { NotAdd.Add(i); continue; }
else SetIds.Add ((int)set.Id);
for (i0 = 0; i0 < set.Aets.Length; i0++)
{
temp = set.Aets[i0];
if (temp.Id != null)
if ( Ids.Contains((int)temp.Id)) { NotAdd.Add(i); break; }
else Ids.Add ((int)temp.Id);
}
}
SetName = null;
SetFileName = null;
for (i = 0; i < AetSets.Length; i++)
{
set = AetSets[i];
if (NotAdd.Contains(i)) continue;
if (!set.NewId) continue;
i1 = 0;
if (set.Id == null) while (true)
{ if (!SetIds.Contains(i1)) { AetSets[i].Id = i1; SetIds.Add(i1); break; } i1++; }
for (i0 = 0, i1 = 0; i0 < set.Aets.Length; i0++)
if (set.Aets[i0].Id == null) while (true) { if (!Ids.Contains(i1))
{ AetSets[i].Aets[i0].Id = i1; Ids.Add(i1); break; } i1++; }
}
Ids = null;
SetIds = null;
for (i = 0, i0 = 0, i2 = 0; i < AetSets.Length; i++)
if (!NotAdd.Contains(i)) { i0 += AetSets[i].Aets.Length; i2++; }
i1 = i0 * 12;
i1 = i1.Align(0x20) + 0x20;
IO = File.OpenWriter(file + ".bin", true);
IO.Write(i2);
IO.Write(i1);
IO.Write(i0);
IO.Write(0x20);
IO.Write(0x9066906690669066);
IO.Write(0x9066906690669066);
IO.Position = (i1 + i2 * 0x14).Align(0x20);
for (i = 0; i < AetSets.Length; i++)
{
if (NotAdd.Contains(i)) continue;
AetSets[i]. NameOffset = IO.Position; IO.Write(AetSets[i]. Name + "\0");
AetSets[i].FileNameOffset = IO.Position; IO.Write(AetSets[i].FileName + "\0");
}
for (i = 0; i < AetSets.Length; i++)
{
if (NotAdd.Contains(i)) continue;
for (i0 = 0; i0 < AetSets[i].Aets.Length; i0++)
{ AetSets[i].Aets[i0].NameOffset = IO.Position; IO.Write(AetSets[i].Aets[i0].Name + "\0"); }
}
IO.Align(0x08, true);
IO.Position = 0x20;
for (i = 0, i2 = 0; i < AetSets.Length; i++)
{
if (NotAdd.Contains(i)) { i2++; continue; }
for (i0 = 0; i0 < AetSets[i].Aets.Length; i0++)
{
IO.Write(AetSets[i].Aets[i0].Id );
IO.Write(AetSets[i].Aets[i0].NameOffset);
IO.Write((ushort) i0 );
IO.Write((ushort)(i - i2));
}
}
IO.Align(0x20);
for (i = 0, i2 = 0; i < AetSets.Length; i++)
{
if (NotAdd.Contains(i)) { i2++; continue; }
IO.Write(AetSets[i].Id );
IO.Write(AetSets[i]. NameOffset);
IO.Write(AetSets[i].FileNameOffset);
IO.Write(i - i2);
IO.Write(AetSets[i].SpriteSetId );
}
IO.Close();
}
public void MsgPackReader(string file, bool JSON)
{
MsgPack MsgPack = file.ReadMP(JSON);
if (MsgPack.Element<MsgPack>("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);
}
MsgPack = null;
}
public void MsgPackWriter(string file, bool JSON)
{
if (AetSets == null) return;
if (AetSets.Length == 0) return;
MsgPack AetDB = new MsgPack("AetDB", AetSets.Length);
for (i = 0; i < AetSets.Length; i++)
AetDB[i] = AetSets[i].WriteMsgPack();
AetDB.Write(true, file, JSON);
}
public struct AET
{
public int NameOffset;
public int? Id;
public string Name;
public void ReadMsgPack(MsgPack msg)
{ Id = msg.ReadNUInt16("Id"); Name = msg.ReadString("Name"); }
public MsgPack WriteMsgPack() =>
new MsgPack().Add("Id", Id).Add("Name", Name);
}
public struct AetSet
{
public int NameOffset;
public int FileNameOffset;
public int? Id;
public int? SpriteSetId;
public bool NewId;
public string Name;
public string FileName;
public AET[] Aets;
public void ReadMsgPack(MsgPack msg)
{
FileName = msg.ReadString ("FileName" );
Id = msg.ReadNUInt16( "Id");
Name = msg.ReadString ( "Name" );
NewId = msg.ReadBoolean("NewId" );
SpriteSetId = msg.ReadNUInt16("SpriteSetId");
if (msg.Element<MsgPack>("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);
}
}
public MsgPack WriteMsgPack()
{
MsgPack Aets = new MsgPack("Aets", this.Aets.Length);
for (int i0 = 0; i0 < this.Aets.Length; i0++)
Aets[i0] = this.Aets[i0].WriteMsgPack();
return new MsgPack().Add("FileName", FileName).Add("Id", Id)
.Add("Name", Name).Add("SpriteSetId", SpriteSetId).Add(Aets);
}
}
}
}
+26 -36
View File
@@ -3,18 +3,17 @@ using System.Collections.Generic;
using KKdMainLib.IO;
using KKdMainLib.A3DA;
using KKdMainLib.MessagePack;
using MPIO = KKdMainLib.MessagePack.IO;
namespace KKdMainLib.DB
{
public struct Auth
public class Auth
{
public int Signature { get; private set; }
public string[] Category { get; private set; }
public UID[] _UID { get; private set; }
public Stream IO { get; private set; }
public int BINReader(string file)
public void BINReader(string file)
{
Dictionary<string, object> Dict = new Dictionary<string, object>();
string[] dataArray;
@@ -23,9 +22,9 @@ namespace KKdMainLib.DB
IO.Format = Main.Format.F;
Signature = IO.ReadInt32();
if (Signature != 0x44334123) return 0;
if (Signature != 0x44334123) return;
Signature = IO.ReadInt32();
if (Signature != 0x5F5F5F41) return 0;
if (Signature != 0x5F5F5F41) return;
IO.ReadInt64();
string[] STRData = IO.ReadString(IO.Length - IO.Position).Replace("\r", "").Split('\n');
@@ -50,13 +49,13 @@ namespace KKdMainLib.DB
for (int i0 = 0; i0 < _UID.Length; i0++)
{
Dict.FindValue(out _UID[i0].Category, "uid." + i0 + ".category");
Dict.FindValue(out _UID[i0].OrgUid , "uid." + i0 + ".org_uid" );
Dict.FindValue(out _UID[i0].Size , "uid." + i0 + ".size" );
Dict.FindValue(out _UID[i0].Value , "uid." + i0 + ".value" );
}
}
IO.Close();
return 1;
}
public void BINWriter(string file)
@@ -84,6 +83,8 @@ namespace KKdMainLib.DB
if (_UID[SO[i]].Category != null)
if (_UID[SO[i]].Category != "")
IO.Write("uid." + SO[i] + ".category=", _UID[SO[i]].Category);
if (_UID[SO[i]].OrgUid != null)
IO.Write("uid." + SO[i] + ".org_uid=" , _UID[SO[i]].OrgUid );
if (_UID[SO[i]].Size != null)
IO.Write("uid." + SO[i] + ".size=" , _UID[SO[i]].Size );
if (_UID[SO[i]].Value != null)
@@ -96,45 +97,37 @@ namespace KKdMainLib.DB
IO.Close();
}
public void MsgPackReader(string file)
public void MsgPackReader(string file, bool JSON)
{
MPIO IO = new MPIO(File.OpenReader(file + ".mp"));
MsgPack MsgPack = IO.Read();
IO.Close();
IO = null;
MsgPack MsgPack = file.ReadMP(JSON);
if (MsgPack.Element("AuthDB", out MsgPack AuthDB))
{
if (AuthDB.Element("Category", out MsgPack Temp, typeof(object[])))
if (AuthDB.Element("Category", out MsgPack Temp))
{
this.Category = new string[((object[])Temp.Object).Length];
MsgPack Category = new MsgPack();
this.Category = new string[Temp.Array.Length];
for (int i = 0; i < this.Category.Length; i++)
if (Temp[i].GetType() == typeof(MsgPack))
{
Category = (MsgPack)Temp[i];
this.Category[i] = Category.ReadString();
}
this.Category[i] = (Temp[i] as MsgPack).ReadString();
}
if (AuthDB.Element("UID", out Temp, typeof(object[])))
if (AuthDB.Element("UID", out Temp))
{
_UID = new UID[((object[])Temp.Object).Length];
MsgPack UID = new MsgPack();
_UID = new UID[Temp.Array.Length];
MsgPack UID;
for (int i = 0; i < _UID.Length; i++)
if (Temp[i].GetType() == typeof(MsgPack))
{
UID = (MsgPack)Temp[i];
_UID[i].Category = UID.ReadString("C");
_UID[i].Size = UID.ReadNInt32("S");
_UID[i].Value = UID.ReadString("V");
}
{
UID = 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");
}
}
}
MsgPack = null;
}
public void MsgPackWriter(string file)
public void MsgPackWriter(string file, bool JSON)
{
MsgPack AuthDB = new MsgPack("AuthDB");
if (Category != null)
@@ -151,22 +144,19 @@ namespace KKdMainLib.DB
for (int i = 0; i < _UID.Length; i++)
UID[i] = new MsgPack()
.Add("C", _UID[i].Category)
.Add("O", _UID[i].OrgUid )
.Add("S", _UID[i].Size )
.Add("V", _UID[i].Value );
AuthDB.Add(UID);
}
MsgPack MsgPack = new MsgPack(MsgPack.Types.FixMap).Add(AuthDB);
MPIO IO = new MPIO(File.OpenWriter(file + ".mp", true));
IO.Write(MsgPack, true);
IO = null;
MsgPack = null;
AuthDB.Write(true, file, JSON);
}
public struct UID
{
public int? Size;
public int? OrgUid;
public string Value;
public string Category;
}
+248
View File
@@ -0,0 +1,248 @@
// 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;
}
}
}
+332
View File
@@ -0,0 +1,332 @@
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
using System.Collections.Generic;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
namespace KKdMainLib.DB
{
public class Spr
{
public SpriteSet[] SpriteSets;
private Stream IO;
private int i, i0, i1, i2;
public void BINReader(string file)
{
/*Stream IO0 = File.OpenReader(file + "0.bin");
Stream IO1 = File.OpenReader(file + "1.bin");
List<int> _0 = new List<int>();
List<int> _1 = new List<int>();
IO0.Position = 0x20;
for (i = 0; i < 124; i++)
{ _0.Add(IO0.ReadInt32()); IO0.LongPosition += 8; }
IO1.Position = 0x20;
for (i = 0; i < 124; i++)
{ _1.Add(IO1.ReadInt32()); IO1.LongPosition += 8; }
IO0.Close();
IO1.Close();
IO = File.OpenWriter(@"F:\Source\MikuMikuModel\DatabaseConverter\msgpack-json-tools\aet_gam_pv643.bin");
IO.Position = 0x10;
for (i = 0; i < 108; i++)
{ IO.ReadInt32(); i1 = _1[_0.IndexOf(IO.ReadInt32())]; IO.Position -= 4; IO.Write(i1); }
IO.Close();*/
IO = File.OpenReader(file + ".bin");
int spriteSetsLength = IO.ReadInt32();
int spriteSetsOffset = IO.ReadInt32();
int spritesLength = IO.ReadInt32();
int spritesOffset = IO.ReadInt32();
IO.Position = spriteSetsOffset;
SpriteSets = new SpriteSet[spriteSetsLength];
for (i = 0; i < spriteSetsLength; i++)
{
SpriteSets[i].Id = IO.ReadInt32();
SpriteSets[i].Name = IO.ReadStringAtOffset();
SpriteSets[i].FileName = IO.ReadStringAtOffset();
IO.ReadInt32();
}
int setIndex;
bool IsTexture;
SpriteTexture st = new SpriteTexture();
int[] SprCount = new int[spriteSetsLength];
int[] TexCount = new int[spriteSetsLength];
IO.Position = spritesOffset;
for (i = 0; i < spritesLength; i++)
{
IO.LongPosition += 10;
setIndex = IO.ReadInt16();
IsTexture = (setIndex & 0x1000) == 0x1000;
setIndex &= 0xFFF;
if (IsTexture) TexCount[setIndex]++;
else SprCount[setIndex]++;
}
for (int i = 0; i < spriteSetsLength; i++)
{
SpriteSets[i].Sprites = new SpriteTexture[SprCount[i]];
SpriteSets[i].Textures = new SpriteTexture[TexCount[i]];
SprCount[i] = 0;
TexCount[i] = 0;
}
IO.Position = spritesOffset;
for (i = 0; i < spritesLength; i++)
{
st.Id = IO.ReadInt32();
st.Name = IO.ReadStringAtOffset();
IO.ReadInt16();
setIndex = IO.ReadInt16();
IsTexture = (setIndex & 0x1000) == 0x1000;
setIndex &= 0xFFF;
if (IsTexture) { SpriteSets[setIndex].Textures[TexCount[setIndex]] = st; TexCount[setIndex]++; }
else { SpriteSets[setIndex]. Sprites[SprCount[setIndex]] = st; SprCount[setIndex]++; }
}
IO.Close();
}
public void BINWriter(string file)
{
if (SpriteSets == null) return;
if (SpriteSets.Length == 0) return;
List<string> SetName = new List<string>();
List<string> SetFileName = new List<string>();
List<int> Ids = new List<int>();
List<int> SetIds = new List<int>();
List<int> NotAdd = new List<int>();
SpriteTexture temp;
SpriteSet set;
for (i = 0; i < SpriteSets.Length; i++)
{
set = SpriteSets[i];
if (set. Name != null)
if (SetName .Contains(set. Name)) { NotAdd.Add(i); continue; }
else SetName .Add (set. Name);
if (set.FileName != null)
if (SetFileName.Contains(set.FileName)) { NotAdd.Add(i); continue; }
else SetFileName.Add (set.FileName);
if (set.NewId)
{
SpriteSets[i].Id = null;
for (i0 = 0; i0 < set.Textures.Length; i0++) SpriteSets[i].Textures[i0].Id = null;
for (i0 = 0; i0 < set. Sprites.Length; i0++) SpriteSets[i]. Sprites[i0].Id = null;
continue;
}
if (set.Id != null)
if (SetIds.Contains((int)set.Id)) { NotAdd.Add(i); continue; }
else SetIds.Add ((int)set.Id);
for (i0 = 0; i0 < set. Sprites.Length; i0++)
{
temp = set. Sprites[i0];
if (temp.Id != null)
if ( Ids.Contains((int)temp.Id)) { NotAdd.Add(i); break; }
else Ids.Add ((int)temp.Id);
}
if (i0 + 1 != set.Sprites.Length) continue;
for (i0 = 0; i0 < set.Textures.Length; i0++)
{
temp = set.Textures[i0];
if (temp.Id != null)
if ( Ids.Contains((int)temp.Id)) { NotAdd.Add(i); break; }
else Ids.Add ((int)temp.Id);
}
}
SetName = null;
SetFileName = null;
for (i = 0; i < SpriteSets.Length; i++)
{
set = SpriteSets[i];
if (NotAdd.Contains(i)) continue;
if (!set.NewId) continue;
i1 = 0;
if (set.Id == null) while (true)
{ if (!SetIds.Contains(i1)) { SpriteSets[i].Id = i1; SetIds.Add(i1); break; } i1++; }
for (i0 = 0, i1 = 0; i0 < set. Sprites.Length; i0++)
if (set. Sprites[i0].Id == null) while (true) { if (!Ids.Contains(i1))
{ SpriteSets[i]. Sprites[i0].Id = i1; Ids.Add(i1); break; } i1++; }
for (i0 = 0, i1 = 0; i0 < set.Textures.Length; i0++)
if (set.Textures[i0].Id == null) while (true) { if (!Ids.Contains(i1))
{ SpriteSets[i].Textures[i0].Id = i1; Ids.Add(i1); break; } i1++; }
}
Ids = null;
SetIds = null;
for (i = 0, i0 = 0, i2 = 0; i < SpriteSets.Length; i++)
if (!NotAdd.Contains(i)) { i0 += SpriteSets[i].Sprites.Length + SpriteSets[i].Textures.Length; i2++; }
i1 = i0 * 12;
i1 = i1.Align(0x20) + 0x20;
IO = File.OpenWriter(file + ".bin", true);
IO.Write(i2);
IO.Write(i1);
IO.Write(i0);
IO.Write(0x20);
IO.Write(0x9066906690669066);
IO.Write(0x9066906690669066);
IO.Position = (i1 + i2 * 0x10).Align(0x20);
for (i = 0; i < SpriteSets.Length; i++)
{
if (NotAdd.Contains(i)) continue;
SpriteSets[i]. NameOffset = IO.Position; IO.Write(SpriteSets[i]. Name + "\0");
SpriteSets[i].FileNameOffset = IO.Position; IO.Write(SpriteSets[i].FileName + "\0");
}
for (i = 0; i < SpriteSets.Length; i++)
{
if (NotAdd.Contains(i)) continue;
for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++)
{ SpriteSets[i].Textures[i0].NameOffset = IO.Position; IO.Write(SpriteSets[i].Textures[i0].Name + "\0"); }
for (i0 = 0; i0 < SpriteSets[i]. Sprites.Length; i0++)
{ SpriteSets[i]. Sprites[i0].NameOffset = IO.Position; IO.Write(SpriteSets[i]. Sprites[i0].Name + "\0"); }
}
IO.Align(0x08, true);
IO.Position = 0x20;
for (i = 0, i2 = 0; i < SpriteSets.Length; i++)
{
if (NotAdd.Contains(i)) { i2++; continue; }
for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++)
{
IO.Write(SpriteSets[i].Textures[i0].Id );
IO.Write(SpriteSets[i].Textures[i0].NameOffset);
IO.Write((ushort) i0 );
IO.Write((ushort)(0x1000 | (i - i2)));
}
for (i0 = 0; i0 < SpriteSets[i]. Sprites.Length; i0++)
{
IO.Write(SpriteSets[i]. Sprites[i0].Id );
IO.Write(SpriteSets[i]. Sprites[i0].NameOffset);
IO.Write((ushort) i0 );
IO.Write((ushort)(i - i2));
}
}
IO.Align(0x20);
for (i = 0, i2 = 0; i < SpriteSets.Length; i++)
{
if (NotAdd.Contains(i)) { i2++; continue; }
IO.Write(SpriteSets[i].Id );
IO.Write(SpriteSets[i]. NameOffset);
IO.Write(SpriteSets[i].FileNameOffset);
IO.Write(i - i2);
}
IO.Close();
}
public void MsgPackReader(string file, bool JSON = false)
{
MsgPack MsgPack = file.ReadMP(JSON);
if (MsgPack.Element<MsgPack>("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);
}
MsgPack = null;
}
public void MsgPackWriter(string file, bool JSON)
{
if (SpriteSets == null) return;
if (SpriteSets.Length == 0) return;
MsgPack SprDB = new MsgPack("SprDB", SpriteSets.Length);
for (i = 0; i < SpriteSets.Length; i++) SprDB[i] = SpriteSets[i].WriteMsgPack();
SprDB.Write(true, file, JSON);
}
public struct SpriteTexture
{
public int NameOffset;
public int? Id;
public string Name;
public void ReadMsgPack(MsgPack msg)
{ Id = msg.ReadNInt32("Id"); Name = msg.ReadString("Name"); }
public MsgPack WriteMsgPack() =>
new MsgPack().Add("Id", Id).Add("Name", Name);
}
public struct SpriteSet
{
public int NameOffset;
public int FileNameOffset;
public int? Id;
public bool NewId;
public string Name;
public string FileName;
public SpriteTexture[] Sprites;
public SpriteTexture[] Textures;
public void ReadMsgPack(MsgPack msg)
{
FileName = msg.ReadString ("FileName");
Id = msg.ReadNInt32 ( "Id" );
Name = msg.ReadString ("Name" );
NewId = msg.ReadBoolean("NewId" );
if (msg.Element<MsgPack>( "Sprites", out MsgPack Sprites))
{
this .Sprites = new SpriteTexture[Sprites.Array.Length];
for (int i0 = 0; i0 < this.Sprites.Length; i0++)
this.Sprites[i0].ReadMsgPack(Sprites[i0] as MsgPack);
}
if (msg.Element<MsgPack>("Textures", out MsgPack Textures))
{
this .Textures = new SpriteTexture[Textures.Array.Length];
for (int i0 = 0; i0 < this.Textures.Length; i0++)
this.Textures[i0].ReadMsgPack(Textures[i0] as MsgPack);
}
}
public MsgPack WriteMsgPack()
{
MsgPack Sprites = new MsgPack( "Sprites", this.Sprites.Length);
for (int i0 = 0; i0 < this.Sprites.Length; i0++)
Sprites[i0] = this.Sprites[i0].WriteMsgPack();
MsgPack Textures = new MsgPack("Textures", this.Textures.Length);
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);
}
}
}
}
+55
View File
@@ -0,0 +1,55 @@
//Original research by Samyuu
using KKdMainLib.IO;
namespace KKdMainLib
{
public static class DCC //Databank_Checksum_Calculator
{
private static readonly ushort[] ChecksumLookupTable = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0,
};
public static ushort CalculateChecksum(string file) => CalculateChecksum(File.ReadAllBytes(file));
public static ushort CalculateChecksum(byte[] data)
{
ushort result = 0xFFFF;
for (int i = 0; i < data.Length; i++)
result = (ushort)(ChecksumLookupTable[(result >> 8) ^ data[i]] ^ (result << 8));
return result;
}
}
}
+27 -43
View File
@@ -12,8 +12,7 @@ namespace KKdMainLib
private int Offset = 0;
private PDHead Header;
private MsgPack MsgPack;
public Stream IO;
public EXP[] Dex;
@@ -158,7 +157,7 @@ namespace KKdMainLib
IO.Align(0x10, true);
if (Header.IsX) IO.Seek(Header.Lenght + 0x28, 0);
else IO.Seek(Header.Lenght + 0x20, 0);
else IO.Seek(Header.Lenght + 0x20, 0);
for (int i0 = 0; i0 < Dex.Length; i0++)
{
IO.Write(Dex[i0].MainOffset);
@@ -174,7 +173,7 @@ namespace KKdMainLib
}
if (Header.IsX) IO.Seek(Position0 - 8, 0);
else IO.Seek(Position0 - 4, 0);
else IO.Seek(Position0 - 4, 0);
IO.Write(Position1);
if (IO.Format > Main.Format.F)
@@ -190,48 +189,37 @@ namespace KKdMainLib
IO.Close();
}
public void MsgPackReader(string filepath)
public void MsgPackReader(string file, bool JSON)
{
int i0 = 0;
int i1 = 0;
this.Dex = new EXP[0];
Header = new PDHead();
MPIO IO = new MPIO(File.OpenReader(filepath + ".mp"));
MsgPack = IO.Read();
IO.Close();
IO = null;
if (MsgPack.Element("Dex", out MsgPack Dex, typeof(object[])))
{
MsgPack Temp = new MsgPack();
MsgPack MsgPack = file.ReadMP(JSON);
if (!MsgPack.Element<MsgPack>("Dex", out MsgPack Dex)) return;
this.Dex = new EXP[((object[])Dex.Object).Length];
MsgPack EXP = new MsgPack();
for (i0 = 0; i0 < this.Dex.Length; i0++)
if (Dex[i0].GetType() == typeof(MsgPack))
this.Dex = 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") };
if (EXP.Element<MsgPack>("Main", out MsgPack Main))
{
this.Dex[i0] = new EXP();
EXP = (MsgPack)Dex[i0];
this.Dex[i0].Name = EXP.ReadString("Name");
if (EXP.Element("Main", out Temp, typeof(object[])))
{
this.Dex[i0].Main = new List<EXPElement>
{ Capacity = ((object[])Temp.Object).Length };
for (i1 = 0; i1 < this.Dex[i0].Main.Capacity; i1++)
if (Temp[i1].GetType() == typeof(MsgPack))
this.Dex[i0].Main.Add(ReadEXP((MsgPack)Temp[i1]));
}
if (EXP.Element("Eyes", out Temp, typeof(object[])))
{
this.Dex[i0].Eyes = new List<EXPElement>
{ Capacity = ((object[])Temp.Object).Length };
for (i1 = 0; i1 < this.Dex[i0].Eyes.Capacity; i1++)
if (Temp[i1].GetType() == typeof(MsgPack))
this.Dex[i0].Eyes.Add(ReadEXP((MsgPack)Temp[i1]));
}
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));
}
}
MsgPack = null;
}
@@ -240,7 +228,7 @@ namespace KKdMainLib
ID = mp.ReadUInt16("I"), Value = mp.ReadSingle("V"),
Trans = mp.ReadSingle("T") };
public void MsgPackWriter(string filepath)
public void MsgPackWriter(string file, bool JSON)
{
int i0 = 0;
int i1 = 0;
@@ -260,11 +248,7 @@ namespace KKdMainLib
Dex[i0] = EXP;
}
MsgPack = new MsgPack(MsgPack.Types.FixMap).Add(Dex);
MPIO IO = new MPIO(File.OpenWriter(filepath + ".mp", true));
IO.Write(MsgPack, true);
IO = null;
Dex.Write(true, file, JSON);
}
private MsgPack WriteEXP(EXPElement element) =>
+2 -2
View File
@@ -11,7 +11,7 @@ namespace KKdMainLib
public static void Decrypt(this string file)
{
Console.Title = "DIVAFILE Decrypt - File: " + MSIO.Path.GetFileName(file);
Console.Title = "DIVAFILE Decrypt - File: " + Path.GetFileName(file);
Stream reader = File.OpenReader(file);
if (reader.ReadInt64() != 0x454C494641564944)
{ reader.Close(); return; }
@@ -35,7 +35,7 @@ namespace KKdMainLib
public static void Encrypt(this string file)
{
Console.Title = "DIVAFILE Encrypt - File: " + MSIO.Path.GetFileName(file);
Console.Title = "DIVAFILE Encrypt - File: " + Path.GetFileName(file);
Stream reader = File.OpenReader(file);
int FileLenghtOrigin = reader.Length;
int FileLenght = FileLenghtOrigin.Align(16);
+248
View File
@@ -0,0 +1,248 @@
using System;
using System.Net;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
namespace KKdMainLib
{
public class DataBank
{
public DataBank() { Success = false; IO = null; pvList = null; }
private Stream IO;
private int i;
private PvList[] pvList;
private const string d = ".";
private const string c = ",";
public bool Success { get; private set; }
public void DBReader(string file)
{
Success = false;
if (!File.Exists(file)) return;
string text = File.ReadAllText(file);
while (text.Contains("%")) text = WebUtility.UrlDecode(text);
string[] array = text.Split(',');
if (file.Contains("PvList") && array.Length % 7 < 2)
{
pvList = new PvList[array.Length / 7];
for (i = 0; i < pvList.Length; i++) pvList[i].SetValue(array, i);
Success = true;
}
}
public void DBWriter(string file)
{
if (!Success) return;
IO = File.OpenWriter();
if (file.Contains("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);
ushort num = DCC.CalculateChecksum(data);
uint num2 = (uint)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
File.WriteAllBytes(file + "_" + num + "_" + num2 + ".dat", data);
}
public void MsgPackReader(string file, bool JSON)
{
Success = false;
MsgPack msgPack = file.ReadMP(JSON);
bool compact = msgPack.ReadBoolean("Compact");
if (file.Contains("PvList") && msgPack.Element<MsgPack>("PvList", out MsgPack PvList))
{
pvList = new PvList[PvList.Array.Length];
for (i = 0; i < pvList.Length; i++)
pvList[i].SetValue((MsgPack)PvList[i], compact);
Success = true;
}
msgPack = null;
}
public void MsgPackWriter(string file, bool JSON, bool Compact = true)
{
if (!Success) return;
MsgPack msgPack = new MsgPack();
if (file.Contains("PvList"))
{
if (Compact) msgPack.Add("Compact", Compact);
MsgPack PvList = new MsgPack("PvList", pvList.Length);
for (i = 0; i < pvList.Length; i++) PvList[i] = pvList[i].WriteMP(Compact);
msgPack.Add(PvList);
}
msgPack.Write(file, JSON).Dispose();
}
public static string UrlEncode(string value) =>
WebUtility.UrlEncode(value).Replace("+", "%20");
public struct PvList
{
public int ID;
public bool Enable;
public bool Extra;
public Date AdvDemoStart;
public Date AdvDemoEnd;
public Date StartShow;
public Date EndShow;
public void SetValue(string[] data, int i = 0)
{
ID = int.Parse(data[i * 7]);
Enable = int.Parse(data[i * 7 + 1]) == 1;
Extra = int.Parse(data[i * 7 + 2]) == 1;
AdvDemoStart.SetValue(data[i * 7 + 3]);
AdvDemoEnd .SetValue(data[i * 7 + 4]);
StartShow .SetValue(data[i * 7 + 5]);
EndShow .SetValue(data[i * 7 + 6]);
}
public void SetValue(MsgPack msg, bool Compact)
{
MsgPack Temp = new MsgPack();
this.Enable = true;
this.Extra = false;
ID = msg.ReadInt32("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 (Compact)
{
AdvDemoStart.SetValue(msg.ReadNInt32("AdvDemoStart"), true);
AdvDemoEnd .SetValue(msg.ReadNInt32("AdvDemoEnd" ), false);
StartShow .SetValue(msg.ReadNInt32("StartShow" ), false);
EndShow .SetValue(msg.ReadNInt32( "EndShow" ), true);
return;
}
if (msg.Element("AdvDemoStart", out Temp)) AdvDemoStart.SetValue(Temp, true);
if (msg.Element("AdvDemoEnd" , out Temp)) AdvDemoEnd .SetValue(Temp, false);
if (msg.Element("StartShow" , out Temp)) StartShow .SetValue(Temp, false);
if (msg.Element( "EndShow" , out Temp)) EndShow .SetValue(Temp, true);
}
public MsgPack WriteMP(bool Compact)
{
MsgPack msgPack = new MsgPack();
msgPack.Add("ID", ID);
if (!Enable) msgPack.Add("Enable", Enable);
if ( Extra ) msgPack.Add("Extra" , Extra );
if (Compact)
{
if (AdvDemoStart.WriteLower) msgPack.Add("AdvDemoStart", AdvDemoStart.WriteInt());
if (AdvDemoEnd .WriteLower) msgPack.Add("AdvDemoEnd" , AdvDemoEnd .WriteInt());
if (StartShow .WriteLower) msgPack.Add("StartShow" , StartShow .WriteInt());
if ( EndShow .WriteUpper) msgPack.Add( "EndShow" , EndShow .WriteInt());
}
else
{
if (AdvDemoStart.WriteLower) msgPack.Add(AdvDemoStart.WriteMP("AdvDemoStart"));
if (AdvDemoEnd .WriteLower) msgPack.Add(AdvDemoEnd .WriteMP("AdvDemoEnd" ));
if (StartShow .WriteLower) msgPack.Add(StartShow .WriteMP("StartShow" ));
if ( EndShow .WriteUpper) msgPack.Add( EndShow .WriteMP( "EndShow" ));
}
return msgPack;
}
public override string ToString() =>
UrlEncode(ID + "," + (Enable ? 1 : 0) + "," + (Extra ? 1 : 0) + "," +
AdvDemoStart.ToString() + "," + AdvDemoEnd.ToString() + "," +
StartShow.ToString() + "," + EndShow.ToString());
}
public struct Date
{
private int year;
private int month;
private int day;
public int Year { get => year; set { year = value; CheckDate(); } }
public int Month { get => month; set { month = value; CheckDate(); } }
public int Day { get => day; set { day = value; CheckDate(); } }
public bool WriteUpper => Year != 2029 || Month != 1 || Day != 1;
public bool WriteLower => Year != 2000 || Month != 1 || Day != 1;
public void SetDefaultLower() => Year = 2000;
public void SetDefaultUpper() => Year = 2029;
public void SetValue(string data)
{
string[] array = data.Split('-');
if (array.Length == 3)
{
Year = int.Parse(array[0]);
Month = int.Parse(array[1]);
Day = int.Parse(array[2]);
}
}
public void SetValue(int? YMD, bool SetDefaultUpper)
{
if (!SetDefaultUpper) SetDefaultLower();
else this.SetDefaultUpper();
if (YMD != null)
{
year = YMD.Value / 10000;
month = YMD.Value / 100 % 100;
day = YMD.Value % 100;
CheckDate();
}
}
public void SetValue(MsgPack msg, bool SetDefaultUpper)
{
if (!SetDefaultUpper) SetDefaultLower();
else this.SetDefaultUpper();
int? Year = msg.ReadNInt32( "Year");
int? Month = msg.ReadNInt32("Month");
int? Day = msg.ReadNInt32( "Day");
if ( Year != null) year = Year.Value;
if (Month != null) month = Month.Value;
if ( Day != null) day = Day.Value;
CheckDate();
}
public int WriteInt() =>
(Year * 100 + Month) * 100 + Day;
public MsgPack WriteMP(string name) =>
new MsgPack(name).Add("Year", Year).Add("Month", Month).Add("Day", Day);
private void CheckDate()
{
if (year < 2000) { year = 2000; month = 1; day = 1; return; }
if (year >= 2029) { year = 2029; month = 1; day = 1; return; }
if (month < 1) month = 1;
else if (month > 12) month = 12;
if (day < 1) day = 1;
else if (day > 31 && (month == 1 || month == 3 || month == 5 ||
month == 7 || month == 8 || month == 10 || month == 12)) day = 31;
else if (day > 30 && (month == 4 || month == 6 ||
month == 9 || month == 11)) day = 30;
else if (day > 29 && month == 2 && year % 4 == 0) day = 29;
else if (day > 28 && month == 2 && year % 4 != 0) day = 28;
}
public override string ToString() =>
Year.ToString("d4") + "-" + Month.ToString("d2") + "-" + Day.ToString("d2");
}
}
}
+13 -14
View File
@@ -35,16 +35,16 @@ namespace KKdMainLib
Files = null;
Signature = Farc.FArC;
FT = false;
Console.Title = "FARC Extractor - Archive: " + MSIO.Path.GetFileName(file);
if (!MSIO.File.Exists(file))
Console.Title = "FARC Extractor - Archive: " + Path.GetFileName(file);
if (!File.Exists(file))
{
Console.WriteLine("File {0} doesn't exist.", MSIO.Path.GetFileName(file));
Console.WriteLine("File {0} doesn't exist.", Path.GetFileName(file));
Console.Clear();
return;
}
Stream reader = File.OpenReader(file);
string directory = MSIO.Path.GetFullPath(file).Replace(MSIO.Path.GetExtension(file), "");
string directory = Path.GetFullPath(file).Replace(Path.GetExtension(file), "");
Signature = (Farc)reader.ReadInt32Endian(true);
if (Signature != Farc.FArc && Signature != Farc.FArC && Signature != Farc.FARC)
{
@@ -76,7 +76,7 @@ namespace KKdMainLib
if (SaveToDisk)
{
File.WriteAllBytes(MSIO.Path.Combine(directory, Files[i].Name), Files[i].Data);
File.WriteAllBytes(Path.Combine(directory, Files[i].Name), Files[i].Data);
Files[i].Data = null;
}
}
@@ -157,8 +157,8 @@ namespace KKdMainLib
GZipStream gZipStream;
if (Encrypted)
{
gZipStream = new GZipStream(new MSIO.
MemoryStream(Files[i].Data), CompressionMode.Decompress);
gZipStream = new GZipStream(new MSIO.MemoryStream(
Files[i].Data), CompressionMode.Decompress);
stream.Close();
}
else gZipStream = new GZipStream(stream, CompressionMode.Decompress);
@@ -177,7 +177,7 @@ namespace KKdMainLib
if (SaveToDisk)
{
File.WriteAllBytes(MSIO.Path.Combine(directory, Files[i].Name), Files[i].Data);
File.WriteAllBytes(Path.Combine(directory, Files[i].Name), Files[i].Data);
Files[i].Data = null;
}
@@ -231,15 +231,14 @@ namespace KKdMainLib
{
Files = null;
FT = false;
string[] files = MSIO.Directory.GetFiles(file);
string[] files = Directory.GetFiles(file);
Files = new FARCFile[files.Length];
for (int i = 0; i < files.Length; i++)
{
Files[i] = new FARCFile { Name = files[i] };
string ext = MSIO.Path.GetExtension(files[i]).ToLower();
if (ext == ".a3da" || ext == ".mot" || ext == ".vag")
Signature = Farc.FArc;
string ext = Path.GetExtension(files[i]).ToLower();
if (ext == ".a3da" || ext == ".diva" || ext == ".vag") Signature = Farc.FArc;
}
files = null;
@@ -259,7 +258,7 @@ namespace KKdMainLib
}
int HeaderPartLength = Signature == Farc.FArc ? 0x09 : 0x0D;
for (int i = 0; i < Files.Length; i++)
HeaderWriter.Length += MSIO.Path.GetFileName(Files[i].Name).Length + HeaderPartLength;
HeaderWriter.Length += Path.GetFileName(Files[i].Name).Length + HeaderPartLength;
writer.WriteEndian(HeaderWriter.Length, true);
writer.Write(HeaderWriter.ToArray(true));
HeaderWriter = null;
@@ -276,7 +275,7 @@ namespace KKdMainLib
else writer.Seek(0x0C, 0);
for (int i = 0; i < Files.Length; i++)
{
writer.Write(MSIO.Path.GetFileName(Files[i].Name) + "\0");
writer.Write(Path.GetFileName(Files[i].Name) + "\0");
writer.WriteEndian(Files[i].Offset, true);
if (Signature != Farc.FArc)
writer.WriteEndian(Files[i].SizeComp, true);
+16
View File
@@ -0,0 +1,16 @@
using System;
using MSIO = System.IO;
namespace KKdMainLib.IO
{
public static class Directory
{
public static bool Exists(string path) => MSIO.Directory.Exists(path);
public static void Delete(string path) => MSIO.Directory.Delete(path);
public static string GetCurrentDirectory() => MSIO.Directory.GetCurrentDirectory();
public static string[] GetFiles(string path) => MSIO.Directory.GetFiles(path);
public static string[] GetDirectories(string path) => MSIO.Directory.GetDirectories(path);
public static MSIO.DirectoryInfo CreateDirectory(string path) => MSIO.Directory.CreateDirectory(path);
}
}
+6 -3
View File
@@ -38,13 +38,16 @@ namespace KKdMainLib.IO
return Data.Replace("\r", "").Split('\n'); }
public static void WriteAllBytes(string file, byte[] data)
{ Stream IO = OpenWriter(file); IO.Write(data); IO.Close(); }
{ Stream IO = OpenWriter(file, true); IO.Write(data); IO.Close(); }
public static void WriteAllText (string file, string data)
{ Stream IO = OpenWriter(file); IO.Write(data); IO.Close(); }
{ Stream IO = OpenWriter(file, true); IO.Write(data); IO.Close(); }
public static void WriteAllLines(string file, string[] data)
{ Stream IO = OpenWriter(file); for (int i = 0; i < data.Length; i++) IO.Write(data[i] + "\r\n"); IO.Close(); }
{ Stream IO = OpenWriter(file, true); for (int i = 0; i < data.Length; i++)
IO.Write(data[i] + "\r\n"); IO.Close(); }
public static bool Exists(string file) => MSIO.File.Exists(file);
public static void Delete(string file) => MSIO.File.Delete(file);
}
}
+49 -1
View File
@@ -11,7 +11,7 @@ namespace KKdMainLib.IO
public static byte[] NullTerminated (this Stream stream, byte End = 0)
{
List<byte> s = new List<byte>();
while (true && stream.LongPosition > 0 && stream.LongPosition < stream.LongLength)
while (stream.LongPosition < stream.LongLength)
{
byte a = stream.ReadByte();
if (a == End) break;
@@ -19,5 +19,53 @@ namespace KKdMainLib.IO
}
return s.ToArray();
}
public static char PeekCharUTF8(this Stream stream)
{ long LongPosition = stream.LongPosition; char val = stream.ReadCharUTF8();
stream.LongPosition = LongPosition; return val; }
public static Stream SkipWhitespace(this Stream stream)
{
long LongPosition = stream.LongPosition;
while (true)
if (char.IsWhiteSpace(stream.ReadCharUTF8())) LongPosition = stream.LongPosition;
else { stream.LongPosition = LongPosition; break; }
return stream;
}
public static bool Assert(this Stream stream, char next)
{ if (stream.PeekCharUTF8() == next) { stream.ReadCharUTF8(); return true; } else return false; }
public static bool Assert(this Stream stream, string next)
{
for (var i = 0; i < next.Length; i++)
if (!stream.Assert(next[i])) return false;
return true;
}
public static long ReadIntX(this Stream stream ) => stream.IsX ?
stream.ReadInt64() : stream.ReadUInt32Endian( );
public static long ReadIntX(this Stream stream, bool IsBE) => stream.IsX ?
stream.ReadInt64() : stream.ReadUInt32Endian(IsBE);
public static byte[] ReadAtOffset(this Stream stream, long Offset = 0, long Length = 0)
{
byte[] arr = null;
long Position = stream.LongPosition;
if (Offset == 0) { Position += stream.IsX ? 8 : 4; Offset = stream.ReadIntX(); }
stream.LongPosition = Offset;
if (Length == 0) arr = stream.NullTerminated();
else arr = stream.ReadBytes(Length);
stream.LongPosition = Position;
return arr;
}
public static string ReadStringAtOffset(this Stream stream, long Offset = 0, long Length = 0)
{
string s = null;
long Position = stream.LongPosition;
if (Offset == 0) { Position += stream.IsX ? 8 : 4; Offset = stream.ReadIntX(); }
stream.LongPosition = Offset;
if (Length == 0) s = stream.NullTerminatedUTF8();
else s = stream.ReadStringUTF8(Length);
stream.LongPosition = Position;
return s;
}
}
}
+25
View File
@@ -0,0 +1,25 @@
using System;
using MSIO = System.IO;
namespace KKdMainLib.IO
{
public static class Path
{
public static string GetFileName(string path) =>
MSIO.Path.GetFileName(path);
public static string GetFileNameWithoutExtension(string path) =>
MSIO.Path.GetFileNameWithoutExtension(path);
public static string GetExtension(string path) =>
MSIO.Path.GetExtension(path);
public static string GetFullPath(string path) =>
MSIO.Path.GetFullPath(path);
public static string Combine(string path1, string path2) =>
MSIO.Path.Combine(path1, path2);
public static string Combine(string path1, string path2, string path3) =>
MSIO.Path.Combine(path1, path2, path3);
public static string Combine(string path1, string path2, string path3, string path4) =>
MSIO.Path.Combine(path1, path2, path3, path4);
public static string Combine(params string[] paths) =>
MSIO.Path.Combine(paths);
}
}
+93 -51
View File
@@ -7,7 +7,7 @@ namespace KKdMainLib.IO
public unsafe class Stream : IDisposable
{
private MSIO.Stream stream;
private int i, i0, TempBitRead, TempBitWrite;
private int I, i, i0, TempBitRead, TempBitWrite;
private ushort ValRead;
private byte BitRead, BitWrite, ValWrite;
private byte[] buf;
@@ -28,12 +28,16 @@ namespace KKdMainLib.IO
public uint UIntOffset { get => (uint)LongOffset; set => LongOffset = value; }
public long LongOffset;
public int Length { get => ( int)stream. Length; set => stream.SetLength (value); }
public uint UIntLength { get => (uint)stream. Length; set => stream.SetLength (value); }
public long LongLength { get => stream. Length; set => stream.SetLength (value); }
public int Position { get => ( int)stream.Position; set => stream.Position = value ; }
public uint UIntPosition { get => (uint)stream.Position; set => stream.Position = value ; }
public long LongPosition { get => stream.Position; set => stream.Position = value ; }
public int Length { get => ( int)stream.Length; set => stream.SetLength(value); }
public uint UIntLength { get => (uint)stream.Length; set => stream.SetLength(value); }
public long LongLength { get => stream.Length; set => stream.SetLength(value); }
public int Position
{ get => ( int)stream.Position - Offset; set => stream.Position = value + Offset; }
public uint UIntPosition
{ get => (uint)stream.Position - UIntOffset; set => stream.Position = value + UIntOffset; }
public long LongPosition
{ get => stream.Position - LongOffset; set => stream.Position = value + LongOffset; }
public bool CanRead => stream.CanRead;
public bool CanSeek => stream.CanSeek;
@@ -45,11 +49,12 @@ namespace KKdMainLib.IO
public Stream(MSIO.Stream output = null, byte[] Data = null, bool isBE = false)
{
if (output == null) output = MSIO.Stream.Null;
LongOffset = 0;
BitRead = 8;
ValRead = ValRead = BitWrite = 0;
stream = output;
Format = Main.Format.NULL;
buf = new byte[16];
buf = new byte[128];
IsBE = isBE;
data = Data;
}
@@ -171,43 +176,51 @@ 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++) Write(val[i]); }
public void Write( sbyte* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
public void Write( byte* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
public void Write( short* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
public void Write(ushort* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
public void Write( int* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
public void Write( uint* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
public void Write( long* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
public void Write( ulong* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
public void Write( float* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
public void Write(double* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
public void WriteEndian( short* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(val[i]); }
public void WriteEndian(ushort* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(val[i]); }
public void WriteEndian( int* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(val[i]); }
public void WriteEndian( uint* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(val[i]); }
public void WriteEndian( long* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(val[i]); }
public void WriteEndian( ulong* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(val[i]); }
public void WriteEndian( float* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(val[i]); }
public void WriteEndian(double* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(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)); }
public void WriteEndian(ushort* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(2, Endian(val[i], 2, IsBE)); }
public void WriteEndian( int* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(4, Endian(val[i], 4, IsBE)); }
public void WriteEndian( uint* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(4, Endian(val[i], 4, IsBE)); }
public void WriteEndian( long* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(8, Endian(val[i], 8, IsBE)); }
public void WriteEndian( ulong* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(8, Endian(val[i], 8, IsBE)); }
public void WriteEndian( float* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(4, Endian(*( uint*)&val[i], 4, IsBE)); }
public void WriteEndian(double* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(8, Endian(*(ulong*)&val[i], 8, IsBE)); }
public void WriteEndian( short* val, int Length, bool IsBE)
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
{ for (i = 0; i < Length; i++) ToArray(2, Endian(val[i], 2, IsBE)); }
public void WriteEndian(ushort* val, int Length, bool IsBE)
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
{ for (i = 0; i < Length; i++) ToArray(2, Endian(val[i], 2, IsBE)); }
public void WriteEndian( int* val, int Length, bool IsBE)
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
{ for (i = 0; i < Length; i++) ToArray(4, Endian(val[i], 4, IsBE)); }
public void WriteEndian( uint* val, int Length, bool IsBE)
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
{ for (i = 0; i < Length; i++) ToArray(4, Endian(val[i], 4, IsBE)); }
public void WriteEndian( long* val, int Length, bool IsBE)
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
{ for (i = 0; i < Length; i++) ToArray(8, Endian(val[i], 8, IsBE)); }
public void WriteEndian( ulong* val, int Length, bool IsBE)
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
{ for (i = 0; i < Length; i++) ToArray(8, Endian(val[i], 8, IsBE)); }
public void WriteEndian( float* val, int Length, bool IsBE)
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
{ for (i = 0; i < Length; i++) ToArray(4, Endian(*( uint*)&val[i], 4, IsBE)); }
public void WriteEndian(double* val, int Length, bool IsBE)
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
{ for (i = 0; i < Length; i++) ToArray(8, Endian(*(ulong*)&val[i], 8, IsBE)); }
public void Write( char val, bool UTF8 = true)
{ if (UTF8) Write(val.ToString().ToUTF8()); else Write(val.ToString().ToASCII()); }
@@ -233,32 +246,61 @@ namespace KKdMainLib.IO
public void WriteEndian(double val, bool IsBE) => ToArray(8, Endian(*(ulong*)&val, 8, IsBE));
public long Endian( long BE, byte Length, bool IsBE)
{ if (IsBE) { for (byte i = 0; i < Length; i++) { buf[i] = (byte)BE; BE >>= 8; } BE = 0;
for (byte i = 0; i < Length; i++) { BE |= buf[i]; if (i < Length - 1) BE <<= 8; } } return BE; }
{ if (IsBE) { for (I = 0; I < Length; I++) { buf[I] = (byte)BE; BE >>= 8; } BE = 0;
for (I = 0; I < Length; I++) { BE |= buf[I]; if (I < Length - 1) BE <<= 8; } } return BE; }
public ulong Endian( ulong BE, byte Length, bool IsBE)
{ if (IsBE) { for (byte i = 0; i < Length; i++) { buf[i] = (byte)BE; BE >>= 8; } BE = 0;
for (byte i = 0; i < Length; i++) { BE |= buf[i]; if (i < Length - 1) BE <<= 8; } } return BE; }
{ if (IsBE) { for (I = 0; I < Length; I++) { buf[I] = (byte)BE; BE >>= 8; } BE = 0;
for (I = 0; I < Length; I++) { BE |= buf[I]; if (I < Length - 1) BE <<= 8; } } return BE; }
private void ToArray(byte L, long val)
{ CheckWrited(); for (i = 0; i < L; i++) { buf[i] = (byte)val; val >>= 8; } Write(buf, L); }
{ CheckWrited(); for (I = 0; I < L; I++) { buf[I] = (byte)val; val >>= 8; } stream.Write(buf, 0, L); }
private void ToArray(byte L, ulong val)
{ CheckWrited(); for (i = 0; i < L; i++) { buf[i] = (byte)val; val >>= 8; } Write(buf, L); }
{ CheckWrited(); for (I = 0; I < L; I++) { buf[I] = (byte)val; val >>= 8; } stream.Write(buf, 0, L); }
private long IntFromArray(byte L, bool IsBE = false) { Read(L); long val = 0; if (IsBE)
for (i = 0; i < L; i++) { val <<= 8; val |= buf[i ]; } else
for (i = L; i > 0; i--) { val <<= 8; val |= buf[i - 1]; } return val; }
private long IntFromArray(byte L) { stream.Read(buf, 0, L); long val = 0;
for (I = L; I > 0; I--) { val <<= 8; val |= buf[I - 1]; } return val; }
private ulong UIntFromArray(byte L, bool IsBE = false) { Read(L); ulong val = 0; if (IsBE)
for (i = 0; i < L; i++) { val <<= 8; val |= buf[i ]; } else
for (i = L; i > 0; i--) { val <<= 8; val |= buf[i - 1]; } return val; }
private ulong UIntFromArray(byte L) { stream.Read(buf, 0, L); ulong val = 0;
for (I = L; I > 0; I--) { val <<= 8; val |= buf[I - 1]; } return val; }
private void Read(byte Length) => stream.Read(buf, 0, Length);
private long IntFromArray(byte L, bool IsBE) { stream.Read(buf, 0, L); long val = 0; if (IsBE)
for (I = 0; I < L; I++) { val <<= 8; val |= buf[I ]; } else
for (I = L; I > 0; I--) { val <<= 8; val |= buf[I - 1]; } return val; }
private ulong UIntFromArray(byte L, bool IsBE) { stream.Read(buf, 0, L); ulong val = 0; if (IsBE)
for (I = 0; I < L; I++) { val <<= 8; val |= buf[I ]; } else
for (I = L; I > 0; I--) { val <<= 8; val |= buf[I - 1]; } return val; }
public char ReadChar(bool UTF8 = true)
{ if (UTF8) return ReadCharUTF8();
else return (char)stream.ReadByte(); }
public char ReadCharUTF8()
{
byte t;
int T;
int val = 0;
for (I = 0, i0 = 4; I < i0; I++)
{
T = stream.ReadByte();
if (T == -1) return '\uFFFF';
t = (byte)T;
if ((t & 0xC0) == 0x80 && I > 0) val = (val << 6) | (t & 0x3F);
else if ((t & 0x80) == 0x00 && I == 0) return (char)t;
else if ((t & 0xE0) == 0xC0 && I == 0) { val = t & 0x1F; i0 = 2; }
else if ((t & 0xF0) == 0xE0 && I == 0) { val = t & 0x0F; i0 = 3; }
else if ((t & 0xF8) == 0xF0 && I == 0) { val = t & 0x07; i0 = 4; }
else return '\uFFFF';
}
return (char)val;
}
public string ReadString(long Length, bool UTF8 = true)
{ if (UTF8) return ReadStringUTF8 (Length);
else return ReadStringASCII(Length); }
else return ReadStringASCII(Length); }
public string ReadStringUTF8 (long Length) => ReadBytes(Length).ToUTF8 ();
public string ReadStringASCII(long Length) => ReadBytes(Length).ToASCII();
@@ -266,7 +308,7 @@ namespace KKdMainLib.IO
public string ReadString(long? Length, bool UTF8 = true)
{ if (UTF8) return ReadStringUTF8 (Length);
else return ReadStringASCII(Length); }
else return ReadStringASCII(Length); }
public string ReadStringUTF8 (long? Length) => ReadBytes(Length).ToUTF8 ();
public string ReadStringASCII(long? Length) => ReadBytes(Length).ToASCII();
+17 -8
View File
@@ -36,24 +36,35 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="A3DA\A3DAExt.cs" />
<Compile Include="A3DA\A3DA.cs" />
<Compile Include="Aet\Aet.cs" />
<Compile Include="Aet\AetExt.cs" />
<Compile Include="DB\Aet.cs" />
<Compile Include="DB\Auth.cs" />
<Compile Include="DEX.cs" />
<Compile Include="DIVAFILE.cs" />
<Compile Include="DB\Spr.cs" />
<Compile Include="IO\Directory.cs" />
<Compile Include="IO\File.cs" />
<Compile Include="IO\IOExtensions.cs" />
<Compile Include="IO\Path.cs" />
<Compile Include="IO\Stream.cs" />
<Compile Include="MathExtensions.cs" />
<Compile Include="MessagePack\JSONIO.cs" />
<Compile Include="MessagePack\MPExt.cs" />
<Compile Include="MessagePack\MsgPack.cs" />
<Compile Include="MessagePack\IO.cs" />
<Compile Include="STR.cs" />
<Compile Include="Types\Half.cs" />
<Compile Include="A3DA\A3DA.cs" />
<Compile Include="Types\Vector2.cs" />
<Compile Include="Types\Vector3.cs" />
<Compile Include="DataBank.cs" />
<Compile Include="DCC.cs" />
<Compile Include="DEX.cs" />
<Compile Include="DIVAFILE.cs" />
<Compile Include="FARC.cs" />
<Compile Include="Main.cs" />
<Compile Include="MathExtensions.cs" />
<Compile Include="PDHeader.cs" />
<Compile Include="POF.cs" />
<Compile Include="STR.cs" />
<Compile Include="Text.cs" />
<Compile Include="Xml.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
@@ -61,8 +72,6 @@
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+43 -41
View File
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Windows.Forms;
using System.Globalization;
using System.Collections.Generic;
@@ -68,9 +69,10 @@ namespace KKdMainLib
public static string Choose(int code, string filetype, out string[] FileNames)
{
string MsgPack = GetArgs("MessagePack", true, "mp");
string JSON = GetArgs("JSON", true, "json");
string BIN = GetArgs("BIN", true, "bin");
string XML = GetArgs("XML", true, "xml");
string WAV = GetArgs("WAV", true, "wav");
FileNames = new string[0];
if (code == 1)
{
@@ -78,32 +80,32 @@ namespace KKdMainLib
OpenFileDialog ofd = new OpenFileDialog { InitialDirectory =
Application.StartupPath, Multiselect = true };
if (filetype == "a3da") ofd.Filter = GetArgs("A3DA", "a3da", "mp") +
GetArgs("A3DA", true, "a3da") + MsgPack;
else if (filetype == "bin" ) ofd.Filter = GetArgs("BIN" , "bin", "mp") +
BIN + MsgPack;
else if (filetype == "bon" ) ofd.Filter = GetArgs("BON" , "bon", "bin", "mp") +
GetArgs("BON", true, "bon") + BIN + MsgPack;
else if (filetype == "dex" ) ofd.Filter = GetArgs("DEX" , "dex", "bin", "mp") +
GetArgs("DEX", true, "dex") + BIN + MsgPack;
if (filetype == "a3da") ofd.Filter = GetArgs("A3DA", "a3da", "json", "mp") +
GetArgs("A3DA", true, "a3da") + JSON + MsgPack;
else if (filetype == "bin" ) ofd.Filter = GetArgs("BIN" , "bin", "json", "mp") +
BIN + JSON + MsgPack;
else if (filetype == "bon" ) ofd.Filter = GetArgs("BON" , "bon", "bin", "json", "mp") +
GetArgs("BON", true, "bon") + BIN + JSON + MsgPack;
else if (filetype == "databank") ofd.Filter = GetArgs("DAT", "dat", "json", "mp") +
GetArgs("DAT", true, "dat") + JSON + MsgPack;
else if (filetype == "dex" ) ofd.Filter = GetArgs("DEX" , "dex", "bin", "json", "mp") +
GetArgs("DEX", true, "dex") + BIN + JSON + MsgPack;
else if (filetype == "diva") ofd.Filter = GetArgs("DIVA", "diva", "wav") +
GetArgs("DIVA", true, "diva") + GetArgs("WAV", true, "wav");
else if (filetype == "dsc" ) ofd.Filter = GetArgs("DSC" , "dsc", "mp") +
GetArgs("DSC", true, "dsc") + MsgPack;
else if (filetype == "dsc" ) ofd.Filter = GetArgs("DSC" , "dsc", "json", "mp") +
GetArgs("DSC", true, "dsc") + JSON + MsgPack;
else if (filetype == "farc") ofd.Filter = "FARC Archives (*.farc)|*.farc";
else if (filetype == "image") ofd.Filter = GetArgs("Image", "dds", "png") +
GetArgs("DDS", true, "dds") + GetArgs("PNG", true, "png");
else if (filetype == "kki") ofd.Filter = GetArgs("KKI", "kki");
else if (filetype == "mot") ofd.Filter = GetArgs("MOT", "mot", "mp") +
GetArgs("MOT", true, "mot") + MsgPack;
else if (filetype == "ppd") ofd.Filter = GetArgs("PPD", "ppd", "pak", "mod") +
else if (filetype == "json") ofd.Filter = "JSON (*.json)|*.json";
else if (filetype == "kki" ) ofd.Filter = GetArgs("KKI", "kki");
else if (filetype == "ppd" ) ofd.Filter = GetArgs("PPD", "ppd", "pak", "mod") +
GetArgs("PPD", true, "ppd") + GetArgs("PAK", true, "pak") + GetArgs("MOD", true, "mod");
else if (filetype == "str") ofd.Filter = GetArgs("STR", "str", "bin", "mp") +
GetArgs("STR", true, "str") + BIN + MsgPack;
else if (filetype == "vag") ofd.Filter = GetArgs("VAG", "vag", "wav") +
else if (filetype == "str" ) ofd.Filter = GetArgs("STR", "str", "bin", "json", "mp") +
GetArgs("STR", true, "str") + BIN + JSON + MsgPack;
else if (filetype == "vag" ) ofd.Filter = GetArgs("VAG", "vag", "wav") +
GetArgs("VAG", true, "vag") + GetArgs("WAV", true, "wav");
else if (filetype == "xml") ofd.Filter = GetArgs("XML", "xml");
else ofd.Filter = GetArgs("All;", false, "*");
else ofd.Filter = GetArgs("All;", false, "*");
if (ofd.ShowDialog() == DialogResult.OK)
FileNames = ofd.FileNames;
@@ -277,7 +279,10 @@ namespace KKdMainLib
}
else if (!Dict.ContainsKey(args[0])) Dict.Add(args[0], value);
}
public static TKey GetKey<TKey, TVal>(this Dictionary<TKey, TVal> Dict, TVal val) =>
Dict.First((KeyValuePair<TKey, TVal> x) => x.Value.Equals(val)).Key;
public static string ToTitleCase(this string s)
{ return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s); }
@@ -296,42 +301,45 @@ namespace KKdMainLib
NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
public static string ToString(this bool? d) => d.GetValueOrDefault().ToString();
public static string ToString(this bool d) => d.ToString().ToLower();
public static string ToString(this sbyte? d) => d.GetValueOrDefault().ToString();
public static string ToString(this sbyte d) => d.ToString();
public static string ToString(this byte? d) => d.GetValueOrDefault().ToString();
public static string ToString(this byte d) => d.ToString();
public static string ToString(this short? d) => d.GetValueOrDefault().ToString();
public static string ToString(this short d) => d.ToString();
public static string ToString(this ushort? d) => d.GetValueOrDefault().ToString();
public static string ToString(this ushort d) => d.ToString();
public static string ToString(this int? d) => d.GetValueOrDefault().ToString();
public static string ToString(this int d) => d.ToString();
public static string ToString(this uint? d) => d.GetValueOrDefault().ToString();
public static string ToString(this uint d) => d.ToString();
public static string ToString(this long? d) => d.GetValueOrDefault().ToString();
public static string ToString(this long d) => d.ToString();
public static string ToString(this ulong? d) => d.GetValueOrDefault().ToString();
public static string ToString(this ulong d) => d.ToString();
public static string ToString(this float? d, byte round) => d.GetValueOrDefault().ToString(round);
public static string ToString(this float? d) => d.GetValueOrDefault().ToString();
public static string ToString(this float d, byte round) =>
Math.Round(d, round).ToString().ToLower().Replace(NumberDecimalSeparator, ".");
public static string ToString(this float d) =>
d .ToString().ToLower().Replace(NumberDecimalSeparator, ".");
public static string ToString(this double? d, byte round) => d.GetValueOrDefault().ToString(round);
public static string ToString(this double? d) => d.GetValueOrDefault().ToString();
public static string ToString(this double d, byte round) =>
Math.Round(d, round).ToString().ToLower().Replace(NumberDecimalSeparator, ".");
public static string ToString(this double d) =>
d .ToString().ToLower().Replace(NumberDecimalSeparator, ".");
public static float ToSingle(this string s) =>
float. Parse(s.Replace(".", NumberDecimalSeparator));
public static bool ToSingle(this string s, out float value) =>
float.TryParse(s.Replace(".", NumberDecimalSeparator), out value);
public static double ToDouble(this string s) =>
double. Parse(s.Replace(".", NumberDecimalSeparator));
public static bool ToDouble(this string s, out double value) =>
double.TryParse(s.Replace(".", NumberDecimalSeparator), out value);
public static bool ToSingle(this string s, out float? value)
{ bool Val = ToSingle(s, out float val); value = val; return Val; }
public static bool ToDouble(this string s, out double? value)
{ bool Val = ToDouble(s, out double val); value = val; return Val; }
@@ -350,11 +358,5 @@ namespace KKdMainLib
X = 10,
XHD = 11,
}
public struct ThreadArgs
{
public int Thread;
public int ID;
}
}
}
+38 -51
View File
@@ -55,20 +55,19 @@ namespace KKdMainLib.MessagePack
{ MsgPack.Object = ( long)(sbyte)Unk; MsgPack.Type = MsgPack.Types.NegInt; }
return MsgPack;
}
bool Boolean = false;
while (!Boolean)
while (true)
{
Boolean = ReadNil (ref MsgPack);
Boolean = ReadArr (ref MsgPack);
Boolean = ReadMap (ref MsgPack);
Boolean = ReadExt (ref MsgPack);
Boolean = ReadString (ref MsgPack);
Boolean = ReadBoolean(ref MsgPack);
Boolean = ReadBytes (ref MsgPack);
Boolean = ReadInt (ref MsgPack);
Boolean = ReadUInt (ref MsgPack);
Boolean = ReadFloat (ref MsgPack);
if (ReadNil (ref MsgPack)) 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;
break;
}
return MsgPack;
@@ -139,7 +138,7 @@ namespace KKdMainLib.MessagePack
int Length = 0;
if (Type == MsgPack.Types.Str8 ) Length = _IO.ReadByte();
else if (Type == MsgPack.Types.Str16) Length = _IO.ReadInt16Endian(true);
else Length = _IO.ReadInt32Endian(true);
else Length = _IO.ReadInt32Endian(true);
return _IO.ReadString(Length);
}
return null;
@@ -191,52 +190,40 @@ namespace KKdMainLib.MessagePack
return true;
}
public IO Write(MsgPack MsgPack, bool Close = false)
public IO Write(MsgPack MsgPack, bool Close)
{ Write(MsgPack); if (Close) this.Close(); return this; }
public IO Write(MsgPack MsgPack)
{
if (MsgPack.Name != null) Write(MsgPack.Name);
if (MsgPack.Object == null) { WriteNil(); return this; }
if (MsgPack.Object.GetType() == typeof(List<object>))
{
List<object> Obj = (List<object>)MsgPack.Object;
WriteMap(Obj.Count);
foreach (object obj in Obj) Write(obj);
}
else if (MsgPack.Object.GetType() == typeof(object[]))
{
object[] Obj = (object[])MsgPack.Object;
WriteArr(Obj.Length);
foreach (object obj in Obj) Write(obj);
}
else Write(MsgPack.Object);
Write(MsgPack.Object);
return this;
}
private void Write(object obj)
{
if (obj == null ) WriteNil ();
else if (obj.GetType() == typeof(MsgPack)) Write((MsgPack)obj);
else
if (obj == null) { WriteNil(); return; }
switch (obj)
{
Type type = obj.GetType();
if (type == typeof(byte[])) Write((byte[])obj);
else if (type == typeof( bool)) Write(( bool)obj);
else if (type == typeof( sbyte)) Write(( sbyte)obj);
else if (type == typeof( byte)) Write(( byte)obj);
else if (type == typeof( short)) Write(( short)obj);
else if (type == typeof(ushort)) Write((ushort)obj);
else if (type == typeof( int)) Write(( int)obj);
else if (type == typeof( uint)) Write(( uint)obj);
else if (type == typeof( long)) Write(( long)obj);
else if (type == typeof( ulong)) Write(( ulong)obj);
else if (type == typeof( float)) Write(( float)obj);
else if (type == typeof(double)) Write((double)obj);
else if (type == typeof(string)) Write((string)obj);
else if (type == typeof(MsgPack.Ext)) Write((MsgPack.Ext)obj);
case 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 MsgPack val: Write(val); break;
case byte[] val: Write(val); break;
case bool val: Write(val); break;
case sbyte val: Write(val); break;
case byte val: Write(val); break;
case short val: Write(val); break;
case ushort val: Write(val); break;
case int val: Write(val); break;
case uint val: Write(val); break;
case long val: Write(val); break;
case ulong val: Write(val); break;
case float val: Write(val); break;
case double val: Write(val); break;
case string val: Write(val); break;
case MsgPack.Ext val: Write(val); break;
}
}
@@ -313,7 +300,7 @@ namespace KKdMainLib.MessagePack
else { _IO.Write((byte) 0xDF); _IO.WriteEndian( val, true); }
}
private void WriteExt(MsgPack.Ext val)
private void Write(MsgPack.Ext val)
{
if (val.Data == null) { WriteNil(); return; }
+250
View File
@@ -0,0 +1,250 @@
//Original or reader part: https://github.com/MarcosLopezC/LightJson/
using System;
using System.Collections.Generic;
using KKdMainLib.IO;
namespace KKdMainLib.MessagePack
{
public class JSONIO
{
public Stream _IO;
public JSONIO( ) => _IO = File.OpenWriter();
public JSONIO(Stream IO) => _IO = IO;
public void Close() => _IO.Close();
public 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)
{
char c = _IO.SkipWhitespace().PeekCharUTF8();
object obj = null;
if (char.IsDigit(c))
obj = ReadNumber ();
else
switch (c)
{
case '"': obj = ReadString (); break;
case '{': obj = ReadObject (); break;
case '[': obj = ReadArray (); break;
case '-': obj = ReadNumber (); break;
case 't':
case 'f': obj = ReadBoolean(); break;
case 'n': obj = ReadNull (); break;
}
return new MsgPack(Key, true, obj);
}
private string ReadString()
{
if (!_IO.Assert('"')) return null;
char c;
string s = "";
while (true)
{
c = _IO.ReadCharUTF8();
if (c == '\\')
{
c = _IO.ReadCharUTF8();
switch (char.ToLower(c))
{
case '"' :
case '\\':
case '/' : s += c; break;
case 'b' : s += '\b'; break;
case 'f' : s += '\f'; break;
case 'n' : s += '\n'; break;
case 'r' : s += '\r'; break;
case 't' : s += '\t'; break;
case 'u' : s += ReadUnicodeLiteral(); break;
default: return null;
}
}
else if (c == '"') break;
else if (char.IsControl(c)) return null;
else s += c;
}
return s;
}
private char ReadUnicodeLiteral() =>
(char)((((((ReadHexDigit() << 4) | ReadHexDigit()) << 4) | ReadHexDigit()) << 4) | ReadHexDigit());
private int ReadHexDigit() => byte.Parse(_IO.ReadCharUTF8().ToString(),
System.Globalization.NumberStyles.HexNumber);
private List<object> ReadObject()
{
List<object> Obj = new List<object>();
if (!_IO.Assert('{')) return null;
if (_IO.SkipWhitespace().PeekCharUTF8() == '}') { _IO.ReadCharUTF8(); return null; }
string key;
while (true)
{
_IO.SkipWhitespace();
key = ReadString();
if (!_IO.SkipWhitespace().Assert(':')) return null;
Obj.Add(ReadValue(key));
_IO.SkipWhitespace();
var next = _IO.ReadCharUTF8();
if (next == '}') break;
else if (next == ',') continue;
else return null;
}
return Obj;
}
private object[] ReadArray()
{
List<object> Obj = new List<object>();
if (!_IO.Assert('[')) return null;
if (_IO.SkipWhitespace().PeekCharUTF8() == ']') { _IO.ReadCharUTF8(); return null; }
char c;
while (true)
{
Obj.Add(ReadValue(null));
c = _IO.SkipWhitespace().ReadCharUTF8();
if (c == ']') break;
else if (c == ',') continue;
else return null;
}
return Obj.ToArray();
}
private object ReadNumber()
{
string s = " ";
_IO.SkipWhitespace();
if (_IO.PeekCharUTF8() == '-') s += _IO.ReadCharUTF8();
if (_IO.PeekCharUTF8() == '0') s += _IO.ReadCharUTF8();
else s += ReadDigits ();
if (_IO.PeekCharUTF8() == '.') s += _IO.ReadCharUTF8() + ReadDigits();
else return long.Parse(s);
char c = _IO.PeekCharUTF8();
if (c == 'e' || c == 'E')
{
s += _IO.ReadCharUTF8();
c = _IO.PeekCharUTF8();
if (c == '+' || c == '-') s += _IO.ReadCharUTF8();
s += ReadDigits();
}
return s.ToDouble();
}
private bool ReadBoolean()
{
char c = _IO.PeekCharUTF8();
if (c == 't' && _IO.Assert( "true")) return true;
else if (c == 'f' && _IO.Assert("false")) return false;
return false;
}
private object ReadNull() { _IO.Assert("null"); return null; }
private string ReadDigits()
{ string s = ""; while (char.IsDigit(_IO.SkipWhitespace().
PeekCharUTF8())) s += _IO.ReadCharUTF8(); return s; }
public JSONIO Write(MsgPack MsgPack, bool Close, string End = "\n", string TabChar = " ")
{ Write(MsgPack, End, TabChar, "", true); if (Close) this.Close(); return this; }
public JSONIO Write(MsgPack MsgPack, bool Close, bool Style = false)
{ Write(MsgPack, "\n", " ", "", Style); if (Close) this.Close(); return this; }
private JSONIO Write(MsgPack MsgPack, string End, string TabChar, string Tab, bool Style)
{
string OldTab = Tab;
Tab += TabChar;
if (MsgPack.Name != null) _IO.Write("\"" + MsgPack.Name + "\":" + (Style ? " " : ""));
if (MsgPack.Object == null) { WriteNil(); return this; }
if (MsgPack.List != null)
{
WriteMap();
if (Style) _IO.Write(End);
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);
}
if (Style) _IO.Write(OldTab);
WriteMap(true);
}
else if (MsgPack.Array != null)
{
WriteArr();
if (Style) _IO.Write(End);
for (int i = 0; i < MsgPack.Array.Length; i++)
{
if (Style) _IO.Write(Tab);
Write(MsgPack.Array[i], End, TabChar, Tab, Style);
if (i + 1 < MsgPack.Array.Length) _IO.Write(',');
if (Style) _IO.Write(End);
}
if (Style) _IO.Write(OldTab);
WriteArr(true);
}
else if (MsgPack.Object is MsgPack msg)
Write(msg, End, TabChar, Tab, Style);
else Write(MsgPack.Object, End, TabChar, Tab, Style);
return this;
}
private void Write(object obj, string End, string TabChar, string Tab, bool Style)
{
if (obj == null) { WriteNil(); return; }
switch (obj)
{
case MsgPack val: Write(val, End, TabChar, Tab, Style); break;
case bool val: Write(val); break;
case string val: Write(val); break;
case sbyte val: _IO.Write(Main.ToString(val)); break;
case byte val: _IO.Write(Main.ToString(val)); break;
case short val: _IO.Write(Main.ToString(val)); break;
case ushort val: _IO.Write(Main.ToString(val)); break;
case int val: _IO.Write(Main.ToString(val)); break;
case uint val: _IO.Write(Main.ToString(val)); break;
case long val: _IO.Write(Main.ToString(val)); break;
case ulong val: _IO.Write(Main.ToString(val)); break;
case float val: _IO.Write(Main.ToString(val)); break;
case double val: _IO.Write(Main.ToString(val)); break;
}
}
private void Write( bool val) => _IO.Write(val ? "true" : "false");
private void Write(string val) => _IO.Write("\"" + val
.Replace("\\", "\\\\").Replace("/" , "\\/").Replace("\'", "\\\'").Replace("\"", "\\\"")
.Replace("\0", "\\0" ).Replace("\a", "\\a").Replace("\b", "\\b" ).Replace("\f", "\\f" )
.Replace("\n", "\\n" ).Replace("\r", "\\r").Replace("\t", "\\t" ) + "\"");
private void WriteNil() => _IO.Write("null");
private void WriteArr(bool End = false) => _IO.Write(End ? "]" : "[");
private void WriteMap(bool End = false) => _IO.Write(End ? "}" : "{");
}
}
+59
View File
@@ -0,0 +1,59 @@
using KKdMainLib.IO;
using MPIO = KKdMainLib.MessagePack.IO;
namespace KKdMainLib.MessagePack
{
public static class MPExt
{
public static MsgPack ReadMP(this string file, bool JSON = false)
{
MsgPack MsgPack;
if (JSON)
{ JSONIO IO = new JSONIO(File.OpenReader(file + ".json"));
MsgPack = IO.Read(); IO.Close(); IO = null; }
else
{ MPIO IO = new MPIO(File.OpenReader(file + ".mp" ));
MsgPack = IO.Read(); IO.Close(); IO = null; }
return MsgPack;
}
public static void WriteAfterAll(this MsgPack mp, bool Temp, string file, bool JSON = false)
{ if (Temp) new MsgPack().Add(mp).WriteAfterAll(file, JSON).Dispose();
else mp .WriteAfterAll(file, JSON); }
public static MsgPack WriteAfterAll(this MsgPack mp, string file, bool JSON = false)
{
byte[] data = null;
if (JSON)
{ JSONIO IO = new JSONIO(File.OpenWriter());
IO.Write(mp, false, true); data = IO._IO.ToArray(true); }
else
{ MPIO IO = new MPIO(File.OpenWriter());
IO.Write(mp, false ); data = IO._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();
public static void ToMsgPack(this string file) =>
file.ReadMP(true).Write(file ).Dispose();
}
}
+89 -74
View File
@@ -1,13 +1,17 @@
using System;
using System.Linq;
using System.Collections.Generic;
namespace KKdMainLib.MessagePack
{
public class MsgPack
public class MsgPack : IDisposable
{
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);
@@ -15,12 +19,40 @@ namespace KKdMainLib.MessagePack
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 static MsgPack Null => null;
public object this[int index]
{ get { return ((object[])Object)[index]; }
set { object[] Data = (object[])Object; Data[index] = value; Object = Data; } }
{ get { if (Array != null) return Array[index]; return null; }
set { if (Array != null) Array[index] = value; } }
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; }
@@ -29,12 +61,11 @@ namespace KKdMainLib.MessagePack
{ 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; }
{ if (Count > 0) { Object = new object[Count]; }
else Object = null; this.Name = Name; Type = Types.Arr32; }
public MsgPack Add(object obj)
{ if (obj != null) if (typeof(List<object>) == Object.GetType())
{ List<object> Obj = (List<object>)Object; Obj.Add(obj); Object = Obj; } return this; }
public void Dispose()
{ Type = 0; Name = null; Object = null; }
public MsgPack Add( sbyte? val) => Add(null, val);
public MsgPack Add( byte? val) => Add(null, val);
@@ -162,88 +193,72 @@ namespace KKdMainLib.MessagePack
public double ReadDouble() => ReadNDouble().GetValueOrDefault();
public bool? ReadNBoolean()
{ if (Object == null) return null;
if (Object.GetType() == typeof( bool)) return ( bool) Object; return null; ; }
{ if (Object is bool Boolean) return Boolean; return null; }
public sbyte? ReadNInt8()
{ if (Object == null) return null;
if (Object.GetType() == typeof( long)) return ( sbyte)( long)Object;
else if (Object.GetType() == typeof( ulong)) return ( sbyte)(ulong)Object; return null; }
{ if (Object is long Int64) return ( sbyte) Int64;
else if (Object is ulong UInt64) return ( sbyte) UInt64; return null; }
public byte? ReadNUInt8()
{ if (Object == null) return null;
if (Object.GetType() == typeof( long)) return ( byte)( long)Object;
else if (Object.GetType() == typeof( ulong)) return ( byte)(ulong)Object; return null; }
{ if (Object is long Int64) return ( byte) Int64;
else if (Object is ulong UInt64) return ( byte) UInt64; return null; }
public short? ReadNInt16()
{ if (Object == null) return null;
if (Object.GetType() == typeof( long)) return ( short)( long)Object;
else if (Object.GetType() == typeof( ulong)) return ( short)(ulong)Object; return null; }
{ if (Object is long Int64) return ( short) Int64;
else if (Object is ulong UInt64) return ( short) UInt64; return null; }
public ushort? ReadNUInt16()
{ if (Object == null) return null;
if (Object.GetType() == typeof( long)) return (ushort)( long)Object;
else if (Object.GetType() == typeof( ulong)) return (ushort)(ulong)Object; return null; }
{ if (Object is long Int64) return (ushort) Int64;
else if (Object is ulong UInt64) return (ushort) UInt64; return null; }
public int? ReadNInt32()
{ if (Object == null) return null;
if (Object.GetType() == typeof( long)) return ( int)( long)Object;
else if (Object.GetType() == typeof( ulong)) return ( int)(ulong)Object; return null; }
{ if (Object is long Int64) return ( int) Int64;
else if (Object is ulong UInt64) return ( int) UInt64; return null; }
public uint? ReadNUInt32()
{ if (Object == null) return null;
if (Object.GetType() == typeof( long)) return ( uint)( long)Object;
else if (Object.GetType() == typeof( ulong)) return ( uint)(ulong)Object; return null; }
{ if (Object is long Int64) return ( uint) Int64;
else if (Object is ulong UInt64) return ( uint) UInt64; return null; }
public long? ReadNInt64()
{ if (Object == null) return null;
if (Object.GetType() == typeof( long)) return ( long) Object;
else if (Object.GetType() == typeof( ulong)) return ( long)(ulong)Object; return null; }
{ if (Object is long Int64) return ( long) Int64;
else if (Object is ulong UInt64) return ( long) UInt64; return null; }
public ulong? ReadNUInt64()
{ if (Object == null) return null;
if (Object.GetType() == typeof( ulong)) return ( ulong) Object;
else if (Object.GetType() == typeof( long)) return ( ulong)( long)Object; return null; }
{ if (Object is long Int64) return ( ulong) Int64;
else if (Object is ulong UInt64) return ( ulong) UInt64; return null; }
public float? ReadNSingle()
{ if (Object == null) return null;
if (Object.GetType() == typeof(double)) return (float)(double)Object;
else if (Object.GetType() == typeof( float)) return (float) Object;
else if (Object.GetType() == typeof( long)) return (float)( long)Object;
else if (Object.GetType() == typeof( ulong)) return (float)( ulong)Object; return null; }
{ if (Object is long Int64) return ( float) Int64;
else if (Object is ulong UInt64) return ( float) UInt64;
else if (Object is float Float32) return ( float)Float32;
else if (Object is double Float64) return ( float)Float64; return null; }
public double? ReadNDouble()
{ if (Object == null) return null;
if (Object.GetType() == typeof(double)) return (double) Object;
else if (Object.GetType() == typeof( float)) return (double)(float)Object;
else if (Object.GetType() == typeof( long)) return (double)( long)Object;
else if (Object.GetType() == typeof( ulong)) return (double)(ulong)Object; return null; }
{ if (Object is 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; }
public string ReadString()
{ if (Object == null) return null;
if (Object.GetType() == typeof(string)) return (string) Object; return null; }
public bool Element(string Name, out MsgPack MsgPack, Type Type)
{ if (Element(out MsgPack, Name)) return MsgPack.Object.GetType() == Type; return false; }
{ if (Object is string String) return String; return null; }
public bool Element<T>(string Name, out MsgPack MsgPack)
{
if (Element(Name, out MsgPack))
{
if (MsgPack.Array == null) return false;
for (int i = 0; i < MsgPack.Array.Length; i++)
if (!(MsgPack[i] is T)) return false;
return true;
}
return false;
}
public bool Element(string Name, out MsgPack MsgPack)
{ if (Element(out MsgPack, Name)) return MsgPack != null; return false; }
public bool Element(out MsgPack MsgPack, string Name)
{
MsgPack = null;
if (Object == null) return false;
if (List != null)
foreach (object obj in List)
if (obj is MsgPack msg) if (msg.Name == Name) { MsgPack = msg; return true; }
return false;
}
Type type = Object.GetType();
if (type == typeof(List<object>))
{
List<object> Obj = (List<object>)Object;
foreach (object obj in Obj)
{
if (obj == null) continue; type = obj.GetType();
if (type == typeof(MsgPack)) if (((MsgPack)obj).Name == Name)
{ MsgPack = (MsgPack)obj; return true; }
}
}
else if (type == typeof(object[]))
{
object[] Obj = (object[])Object;
foreach (object obj in Obj)
{
if (obj == null) continue; type = obj.GetType();
if (type == typeof(MsgPack)) if (((MsgPack)obj).Name == Name)
{ MsgPack = (MsgPack)obj; return true; }
}
}
public bool ContainsKey(string Name)
{
if (List == null) return false;
foreach (object obj in List)
if (obj is MsgPack msg) if (msg.Name == Name) return true;
return false;
}
+20 -2
View File
@@ -28,7 +28,11 @@ namespace KKdMainLib
return POF;
}
public static Stream GetOffset(this Stream stream, ref POF POF)
{if (stream.Format > Main.Format.F) POF.POFOffsets.Add(stream.Position - (stream.IsX ? stream.Offset : 0x00)); return stream; }
{
if (POF != null) if (stream.Format > Main.Format.F)
POF.POFOffsets.Add(stream.Position - (stream.IsX ? stream.Offset : 0x00));
return stream;
}
public static void ReadPOF(this Stream stream, ref POF POF)
{
@@ -108,6 +112,20 @@ namespace KKdMainLib
stream.Align(16, true);
stream.WriteEOFC(ID);
}
public static long ReadUInt32Endian(this Stream IO, ref POF POF) =>
IO.GetOffset(ref POF).ReadUInt32Endian();
public static long ReadUInt32Endian(this Stream IO, ref POF POF, bool IsBE) =>
IO.GetOffset(ref POF).ReadUInt32Endian(IsBE);
public static long ReadInt64(this Stream IO, ref POF POF) =>
IO.GetOffset(ref POF).ReadInt64();
public static long ReadIntX(this Stream IO, ref POF POF ) =>
IO.IsX ? IO.ReadInt64() : IO.ReadUInt32Endian( );
public static long ReadIntX(this Stream IO, ref POF POF, bool IsBE) =>
IO.IsX ? IO.ReadInt64() : IO.ReadUInt32Endian(IsBE);
public static string ReadStringAtOffset(this Stream IO, ref POF POF, long Offset = 0, long Length = 0) =>
IO.GetOffset(ref POF).ReadStringAtOffset(Offset, Length);
}
}
+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.5.8")]
[assembly: AssemblyFileVersion("0.4.5.8")]
[assembly: AssemblyVersion("0.4.5.10")]
[assembly: AssemblyFileVersion("0.4.5.10")]
+25 -43
View File
@@ -1,5 +1,4 @@
using System;
using System.Xml.Linq;
using System.Collections.Generic;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
@@ -17,9 +16,8 @@ namespace KKdMainLib
}
public STR()
{ Count = 0; Offset = 0; OffsetX = 0; STRs = null; POF = null; Header = new PDHead(); }
public long Count;
{ Offset = 0; OffsetX = 0; STRs = null; POF = null; Header = new PDHead(); }
private long Offset;
private long OffsetX;
public String[] STRs;
@@ -39,7 +37,7 @@ namespace KKdMainLib
POF = Header.AddPOF();
reader.Position = Header.Lenght;
Count = reader.ReadInt32Endian();
long Count = reader.ReadInt32Endian();
Offset = reader.ReadInt32Endian();
if (Offset == 0)
@@ -72,7 +70,7 @@ namespace KKdMainLib
else
{
reader.Position -= 4;
Count = 0;
int Count = 0;
for (int a = 0, i = 0; reader.Position > 0 && reader.Position < reader.Length; i++, Count++)
{
a = reader.ReadInt32();
@@ -102,6 +100,7 @@ namespace KKdMainLib
POF = new POF();
writer.IsBE = writer.Format == Main.Format.F2BE;
long Count = STRs.LongLength;
if (writer.Format > Main.Format.FT)
{
writer.Position = 0x40;
@@ -172,56 +171,39 @@ namespace KKdMainLib
writer.Close();
}
public void MsgPackReader(string filepath)
public void MsgPackReader(string file, bool JSON)
{
//STRs = new List<String>();
MsgPack MsgPack = file.ReadMP(JSON);
Xml Xml = new Xml();
Xml.OpenXml(filepath + ".xml", true);
Xml.Compact = true;
int i = 0;
foreach (XElement STR_ in Xml.doc.Elements("STR"))
{
foreach (XAttribute Entry in STR_.Attributes())
if (Entry.Name == "Format")
Enum.TryParse(Entry.Value, out Header.Format);
foreach (XElement STREntry in STR_.Elements())
if (!MsgPack.Element("STR", out MsgPack STR)) return;
if (!STR.Element<MsgPack>("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)
{
if (STREntry.Name == "STREntry")
{
String Str = new String();
foreach (XAttribute Entry in STREntry.Attributes())
{
if (Entry.Name == "ID" ) Str.ID = int.Parse(Entry.Value);
if (Entry.Name == "String") Str.Str = Entry.Value ;
}
//STRs.Add(Str);
}
i++;
String = (MsgPack)Strings[i];
STRs[i].ID = String.ReadInt32("ID");
STRs[i].Str = String.ReadString("Str");
}
}
Count = i;
MsgPack = null;
}
public void MsgPackWriter(string filepath)
public void MsgPackWriter(string file, bool JSON)
{
MsgPack STR_ = new MsgPack("STR").Add("Format", Header.Format.ToString()).Add("Count", Count);
MsgPack Strings = new MsgPack("Strings", Count);
for (int i = 0; i < Count; i++)
MsgPack STR_ = new MsgPack("STR").Add("Format", Header.Format.ToString());
MsgPack Strings = new MsgPack("Strings", STRs.Length);
for (int i = 0; i < STRs.Length; i++)
{
Strings[i] = new MsgPack().Add("ID", STRs[i].ID);
if (STRs[i].Str != null)
if (STRs[i].Str != "")
if (STRs[i].Str != null) if (STRs[i].Str != "")
((MsgPack)Strings[i]).Add("S", STRs[i].Str); ;
}
STR_.Add(Strings);
MsgPack MsgPack = new MsgPack(MsgPack.Types.FixMap).Add(STR_);
MPIO IO = new MPIO(File.OpenWriter(filepath + ".mp", true));
IO.Write(MsgPack, true);
IO = null;
MsgPack = null;
STR_.Write(true, file, JSON);
}
}
}
+21
View File
@@ -0,0 +1,21 @@
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; }
}
}
+21
View File
@@ -0,0 +1,21 @@
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; }
}
}
-102
View File
@@ -1,102 +0,0 @@
using System;
using System.Xml;
using System.Text;
using System.Xml.Linq;
namespace KKdMainLib
{
public class Xml
{
public XDocument doc;
public bool Compact = false;
public Xml() { doc = new XDocument(); }
public void OpenXml(string file, bool compact)
{
doc = XDocument.Load(file);
Compact = compact;
}
public void SaveXml(string file)
{
XmlWriter writer = XmlWriter.Create(file, settings);
doc.Save(writer);
writer.Dispose();
Compact = false;
GC.Collect();
}
public readonly XmlWriterSettings settings = new XmlWriterSettings
{ Encoding = Encoding.UTF8, NewLineChars = "\n", Indent = true, IndentChars = "\t" };
public void Reader(XElement Child, ref bool value, string localName)
{ if (Child.Name == localName) value = bool.Parse(Child.Value); }
public void Reader(XAttribute Entry, ref bool value, string localName)
{ if (Entry.Name == localName) value = bool.Parse(Entry.Value); }
public void Reader(XElement Child, ref int value, string localName)
{ if (Child.Name == localName) value = int.Parse(Child.Value); }
public void Reader(XAttribute Entry, ref int value, string localName)
{ if (Entry.Name == localName) value = int.Parse(Entry.Value); }
public void Reader(XElement Child, ref uint value, string localName)
{ if (Child.Name == localName) value = uint.Parse(Child.Value); }
public void Reader(XAttribute Entry, ref uint value, string localName)
{ if (Entry.Name == localName) value = uint.Parse(Entry.Value); }
public void Reader(XElement Child, ref long value, string localName)
{ if (Child.Name == localName) value = long.Parse(Child.Value); }
public void Reader(XAttribute Entry, ref long value, string localName)
{ if (Entry.Name == localName) value = long.Parse(Entry.Value); }
public void Reader(XElement Child, ref ulong value, string localName)
{ if (Child.Name == localName) value = ulong.Parse(Child.Value); }
public void Reader(XAttribute Entry, ref ulong value, string localName)
{ if (Entry.Name == localName) value = ulong.Parse(Entry.Value); }
public void Reader(XElement Child, ref double value, string localName)
{ if (Child.Name == localName) value = Child.Value.ToDouble(); }
public void Reader(XAttribute Entry, ref double value, string localName)
{ if (Entry.Name == localName) value = Entry.Value.ToDouble(); }
public void Reader(XElement Child, ref string value, string localName)
{ if (Child.Name == localName) value = Child.Value; }
public void Reader(XAttribute Entry, ref string value, string localName)
{ if (Entry.Name == localName) value = Entry.Value; }
public void Reader(XElement Child, ref string[] value, string localName, params char[] Separate)
{ if (Child.Name == localName) value = Child.Value.Split(Separate); }
public void Reader(XAttribute Entry, ref string[] value, string localName, params char[] Separate)
{ if (Entry.Name == localName) value = Entry.Value.Split(Separate); }
public void Writer(XElement element, bool value, string localName) =>
Writer(element, value.ToString().ToLower(), localName);
public void Writer(XElement element, long value, string localName) =>
Writer(element, value.ToString().ToLower(), localName);
public void Writer(XElement element, ulong value, string localName) =>
Writer(element, value.ToString().ToLower(), localName);
public void Writer(XElement element, double value, string localName) =>
Writer(element, value.ToString(), localName);
public void Writer(XElement element, string value, string localName)
{
if (Compact && value != "" && value != null)
element.Add(new XAttribute(localName, value));
else if (!Compact)
element.Add(new XElement(localName, value));
}
}
}
+87 -103
View File
@@ -1,129 +1,113 @@
using KKdMainLib;
using KKdMainLib.IO;
using MSIO = System.IO;
namespace KKdSoundLib
{
public unsafe class DIVA
{
public DIVAFile Data = new DIVAFile();
public string file = "";
private int c, i;
public DIVA() { Data = new DIVAFile(); file = ""; }
public DIVA(string filepath) { Data = new DIVAFile(); file = filepath; }
public DIVA() { Data = new DIVAFile(); }
public void DIVAReader(bool ToArray = false)
public void DIVAReader(string file, bool ToArray = false)
{
if (MSIO.File.Exists(file + ".diva"))
{
Data = new DIVAFile();
Stream reader = File.OpenReader(file + ".diva");
if (!File.Exists(file + ".diva")) return;
if (reader.ReadString(0x04) == "DIVA")
{
reader.ReadInt32();
Data.Size = reader.ReadUInt32();
Data.SampleRate = reader.ReadUInt32();
Data.SamplesCount = reader.ReadUInt32();
reader.ReadInt64();
Data.Channels = reader.ReadUInt16();
reader.ReadUInt16();
Data.Name = reader.ReadString(0x20);
Data = new DIVAFile();
Stream reader = File.OpenReader(file + ".diva");
Stream writer = File.OpenWriter();
if (!ToArray) writer = File.OpenWriter(file + ".wav", true);
writer.LongPosition = 0x2C;
if (reader.ReadString(0x04) != "DIVA") { reader.Close(); return; }
byte value = 0;
int[] current = new int[Data.Channels];
int[] currentclamp = new int[Data.Channels];
sbyte[] stepindex = new sbyte[Data.Channels];
float f;
reader.ReadInt32();
Data.Size = reader.ReadUInt32();
Data.SampleRate = reader.ReadUInt32();
Data.SamplesCount = reader.ReadUInt32();
reader.ReadInt64();
Data.Channels = reader.ReadUInt16();
reader.ReadUInt16();
Data.Name = reader.ReadString(0x20);
int* currentPtr = current.GetPtr();
int* currentclampPtr = currentclamp.GetPtr();
sbyte* stepindexPtr = stepindex.GetPtr();
for (i = 0; i < Data.SamplesCount; i++)
for (c = 0; c < Data.Channels; c++)
{
value = reader.ReadHalfByte();
IMADecoder(value, ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
f = (float)(currentPtr[c] / 32768.0);
writer.Write(f);
}
WAV.Header Header = new WAV.Header
{ Bytes = 4, Channels = Data.Channels, Format = 3,
SampleRate = Data.SampleRate, Size = Data.SamplesCount * Data.Channels * 4};
writer.Write(Header, 0);
if (ToArray) Data.Data = writer.ToArray();
writer.Close();
}
reader.Close();
}
}
private byte[] BuildWavHeader(WAV.Header Header, short Bytes)
{
Stream writer = File.OpenWriter();
writer.Write(Header);
byte[] Data = writer.ToArray();
if (!ToArray) writer = File.OpenWriter(file + ".wav", true);
writer.LongPosition = 0x2C;
byte value = 0;
int[] current = new int[Data.Channels];
int[] currentclamp = new int[Data.Channels];
sbyte[] stepindex = new sbyte[Data.Channels];
float f;
int* currentPtr = current.GetPtr();
int* currentclampPtr = currentclamp.GetPtr();
sbyte* stepindexPtr = stepindex.GetPtr();
for (i = 0; i < Data.SamplesCount; i++)
for (c = 0; c < Data.Channels; c++)
{
value = reader.ReadHalfByte();
IMADecoder(value, ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
f = (float)(currentPtr[c] / 32768.0);
writer.Write(f);
}
WAV.Header Header = new WAV.Header { Bytes = 4, Channels = Data.Channels, Format = 3,
SampleRate = Data.SampleRate, Size = Data.SamplesCount * Data.Channels * 4 };
writer.Write(Header, 0);
if (ToArray) Data.Data = writer.ToArray();
writer.Close();
return Data;
reader.Close();
}
public void DIVAWriter()
public void DIVAWriter(string file)
{
if (MSIO.File.Exists(file + ".wav"))
{
Stream reader = File.OpenReader(file + ".wav");
Stream writer = File.OpenWriter(file + ".diva", true);
Data = new DIVAFile();
WAV.Header Header = reader.ReadWAVHeader();
if (Header.IsSupported)
if (!File.Exists(file + ".wav")) return;
Stream reader = File.OpenReader(file + ".wav");
Data = new DIVAFile();
WAV.Header Header = reader.ReadWAVHeader();
if (!Header.IsSupported) { reader.Close(); return; }
Stream writer = File.OpenWriter(file + ".diva", true);
Data.Channels = Header.Channels;
Data.SampleRate = Header.SampleRate;
writer.LongPosition = 0x40;
byte value = 0;
int[] sample = new int[Data.Channels];
int[] current = new int[Data.Channels];
int[] currentclamp = new int[Data.Channels];
sbyte[] stepindex = new sbyte[Data.Channels];
int* samplePtr = sample.GetPtr();
int* currentPtr = current.GetPtr();
int* currentclampPtr = currentclamp.GetPtr();
sbyte* stepindexPtr = stepindex.GetPtr();
Data.SamplesCount = Header.Size / Header.Channels / Header.Bytes;
for (i = 0; i < Data.SamplesCount; i++)
for (c = 0; c < Header.Channels; c++)
{
Data.Channels = Header.Channels;
Data.SampleRate = Header.SampleRate;
writer.LongPosition = 0x40;
byte value = 0;
int[] sample = new int[Data.Channels];
int[] current = new int[Data.Channels];
int[] currentclamp = new int[Data.Channels];
sbyte[] stepindex = new sbyte[Data.Channels];
int* samplePtr = sample.GetPtr();
int* currentPtr = current.GetPtr();
int* currentclampPtr = currentclamp.GetPtr();
sbyte* stepindexPtr = stepindex.GetPtr();
Data.SamplesCount = Header.Size / Header.Channels / Header.Bytes;
for (i = 0; i < Data.SamplesCount; i++)
for (c = 0; c < Header.Channels; c++)
{
samplePtr[c] = (reader.ReadWAVSample(Header.Bytes, Header.Format) * 0x8000).CFTI();
value = IMAEncoder(samplePtr[c], ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
writer.Write(value, 4);
}
writer.CheckWrited();
writer.LongPosition = 0x00;
writer.Write("DIVA");
writer.Write(0x00);
writer.Write((Data.SamplesCount * Data.Channels).Align(2, 2));
writer.Write(Data.SampleRate);
writer.Write(Data.SamplesCount);
writer.Write(0x00);
writer.Write(0x00);
writer.Write(Data.Channels);
samplePtr[c] = (reader.ReadWAVSample(Header.Bytes, Header.Format) * 0x8000).CFTI();
value = IMAEncoder(samplePtr[c], ref currentPtr[c],
ref currentclampPtr[c], ref stepindexPtr[c]);
writer.Write(value, 4);
}
reader.Close();
writer.Close();
}
writer.CheckWrited();
writer.LongPosition = 0x00;
writer.Write("DIVA");
writer.Write(0x00);
writer.Write((Data.SamplesCount * Data.Channels).Align(2, 2));
writer.Write(Data.SampleRate);
writer.Write(Data.SamplesCount);
writer.Write(0x00);
writer.Write(0x00);
writer.Write(Data.Channels);
writer.Close();
reader.Close();
}
private void IMADecoder(byte value, ref int current, ref int currentclamp, ref sbyte stepindex)
+11 -7
View File
@@ -1,4 +1,6 @@
using KKdMainLib.IO;
using System;
using KKdMainLib;
using KKdMainLib.IO;
namespace KKdSoundLib
{
@@ -15,10 +17,10 @@ namespace KKdSoundLib
public static void Write(this Stream IO, double Sample, ushort Bytes, ushort Format)
{
if (Bytes == 2) IO.Write ((ushort)(Sample * 0x00008000));
else if (Bytes == 4 && Format == 0x01) IO.Write (( int)(Sample * 0x80000000));
else if (Bytes == 4 && Format == 0x03) IO.Write ((float) Sample);
else if (Bytes == 8 && Format == 0x03) IO.Write ( Sample);
if (Bytes == 2) IO.Write((Sample * 0x00008000).CFTS());
else if (Bytes == 4 && Format == 0x01) IO.Write((Sample * 0x80000000).CFTI());
else if (Bytes == 4 && Format == 0x03) IO.Write((float)Sample);
else if (Bytes == 8 && Format == 0x03) IO.Write( Sample);
}
public static WAV.Header ReadWAVHeader(this Stream IO)
@@ -46,7 +48,7 @@ namespace KKdSoundLib
Header.Format = IO.ReadUInt16();
}
if (Header.Bytes < 1 || (Header.Bytes > 4 && Header.Bytes != 8)) return Header;
if (Header.Bytes > 0 && Header.Bytes < 4 && Header.Format == 3) return Header;
if (Header.Bytes > 0 && Header.Bytes < 4 && Header.Format == 3 ) return Header;
if (Header.Bytes == 8 && Header.Format == 1) return Header;
IO.Seek(Offset + 0x14, 0);
if (IO.ReadString(4) != "data") return Header;
@@ -70,7 +72,9 @@ namespace KKdSoundLib
else IO.Write(Header.Size + 0x3C);
IO.Write("WAVE");
IO.Write("fmt ");
IO.Write(0x10);
if (Header.Format != 0xFFFE) IO.Write(0x10);
else IO.Write(0x28);
IO.Write(Header.Format);
IO.Write((short)Header.Channels);
IO.Write(Header.SampleRate);
-2
View File
@@ -46,8 +46,6 @@
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KKdMainLib\KKdMainLib.csproj">
+2 -2
View File
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA")]
[assembly: AssemblyVersion("0.0.2.1")]
[assembly: AssemblyFileVersion("0.0.2.1")]
[assembly: AssemblyVersion("0.0.2.3")]
[assembly: AssemblyFileVersion("0.0.2.3")]
+76 -49
View File
@@ -1,6 +1,5 @@
using KKdMainLib;
using KKdMainLib.IO;
using MSIO = System.IO;
namespace KKdSoundLib
{
@@ -13,20 +12,18 @@ namespace KKdSoundLib
private const uint BS = 28; //VAGBlockSize
private int[] Samp1, Samp2, Samp3, Samp4;
private int* S1Ptr, S2Ptr, S3Ptr, S4Ptr;
private bool Success = false;
public VAGFile VAGData = new VAGFile();
public string file = "";
public VAG() { VAGData = new VAGFile(); file = "";
public VAG() { VAGData = new VAGFile();
HEVAG1Ptr = HEVAG1.GetPtr(); HEVAG2Ptr = HEVAG2.GetPtr();
HEVAG3Ptr = HEVAG3.GetPtr(); HEVAG4Ptr = HEVAG4.GetPtr();
}
public VAG(string filepath) { VAGData = new VAGFile(); file = filepath; }
HEVAG3Ptr = HEVAG3.GetPtr(); HEVAG4Ptr = HEVAG4.GetPtr(); }
public void VAGReader()
public void VAGReader(string file)
{
if (!MSIO.File.Exists(file + ".vag")) return;
Success = false;
if (!File.Exists(file + ".vag")) return;
VAGData = new VAGFile();
Stream reader = File.OpenReader(file + ".vag", true);
@@ -147,6 +144,7 @@ namespace KKdSoundLib
VAGData.DataPtr = VAGData.OriginDataPtr;
reader.Close();
Success = true;
}
private void DecodeHEVAG()
@@ -176,33 +174,44 @@ namespace KKdSoundLib
}
}
public void WAVWriterStraight()
public void WAVWriterStraight(string file, bool IgnoreEndFlags = false)
{
if (!Success) return;
byte Flag = VAGData.Flags[0];
if (Flag == 7) return;
WAV.Header Header = new WAV.Header();
Stream writer = File.OpenWriter(file + ".wav", true);
writer.LongPosition = 0x2C;
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
{
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
writer.Write(f);
}
for (i1 = 0, i2 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
{
Flag = VAGData.Flags[i1];
if (Flag == 5 || Flag > 6) break;
if (Flag < 8)
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
{
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
writer.Write(f);
}
else
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
writer.Write(0f);
if (Flag == 1) break;
for (i1 = 0, i2 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
{
Flag = VAGData.Flags[i1];
if (!IgnoreEndFlags && Flag == 5 || Flag == 7) break;
if (Flag < 8)
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
{
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
writer.Write(f);
}
else
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
writer.Write(0f);
if (!IgnoreEndFlags && Flag == 1) break;
}
VAGData.DataPtr = VAGData.OriginDataPtr;
@@ -212,29 +221,36 @@ namespace KKdSoundLib
writer.Close();
}
public void WAVWriter()
public void WAVWriter(string file, bool IgnoreEndFlags = false)
{
if (!Success) return;
byte Flag = VAGData.Flags[0];
if (Flag == 7) return;
WAV.Header Header = new WAV.Header();
Stream writer;
if (Flag == 6) writer = File.OpenWriter(file + ".loop.0.wav", true);
else writer = File.OpenWriter(file + ".0.wav", true);
if (!IgnoreEndFlags && Flag == 6) writer = File.OpenWriter(file + ".loop.0.wav", true);
else writer = File.OpenWriter(file + ".0.wav", true);
writer.LongPosition = 0x2C;
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
{
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
writer.Write(f);
}
if (Flag < 8)
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
{
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
writer.Write(f);
}
else
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
writer.Write(0f);
VAGData.DataPtr += VBS;
for (i1 = 1, i2 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
{
Flag = VAGData.Flags[i1];
if (Flag == 5 || Flag > 6) break;
else if (Flag == 6)
if (!IgnoreEndFlags && Flag == 5 || Flag == 7) break;
else if (!IgnoreEndFlags && Flag == 6)
{
Header = new WAV.Header { Bytes = 4, Channels = ch, Format = 3, SampleRate =
VAGData.SampleRate, Size = writer.UIntPosition - 0x2C };
@@ -246,15 +262,20 @@ namespace KKdSoundLib
writer.LongPosition = 0x2C;
}
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
{
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
writer.Write(f);
}
if (!IgnoreEndFlags && Flag < 8)
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
{
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
writer.Write(f);
}
else
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
writer.Write(0f);
if (Flag == 1) break;
else if (Flag == 3)
if (!IgnoreEndFlags && Flag == 1) break;
else if (!IgnoreEndFlags && Flag == 3)
{
Header = new WAV.Header { Bytes = 4, Channels = ch, Format = 3, SampleRate =
VAGData.SampleRate, Size = writer.UIntPosition - 0x2C };
@@ -277,8 +298,9 @@ namespace KKdSoundLib
writer.Close();
}
public int WAVReaderStraight(bool ExtendedFlagging = false)
public int WAVReaderStraight(string file, bool ExtendedFlagging = false)
{
Success = false;
VAGData = new VAGFile();
Stream reader = File.OpenReader(file + ".wav");
WAV.Header Header = reader.ReadWAVHeader();
@@ -319,16 +341,18 @@ namespace KKdSoundLib
VAGData.Flags[VAGData.Size - 1] = 0x1;
reader.Close();
Success = true;
return 0;
}
public int WAVReader(bool ExtendedFlagging = false)
public int WAVReader(string file, bool ExtendedFlagging = false)
{
Success = false;
string[] Files;
bool HasLoop = false;
bool[] Loop;
{
if (!file.EndsWith(".0")) return WAVReaderStraight();
if (!file.EndsWith(".0")) return WAVReaderStraight(file);
file = file.Remove(file.Length - 2);
i2 = 0;
System.Collections.Generic.List<string> files =
@@ -337,12 +361,12 @@ namespace KKdSoundLib
new System.Collections.Generic.List< bool>();
while (true)
{
if (MSIO.File.Exists(file + "." + i2 + ".wav"))
if (File.Exists(file + "." + i2 + ".wav"))
{
files.Add(file + "." + i2 + ".wav");
loop.Add(false);
}
else if (MSIO.File.Exists(file + "." + i2 + ".loop.wav"))
else if (File.Exists(file + "." + i2 + ".loop.wav"))
{
files.Add(file + "." + i2 + ".loop.wav");
loop.Add(true);
@@ -431,12 +455,14 @@ namespace KKdSoundLib
VAGData.Channels = ch;
VAGData.SampleRate = SampleRate;
Success = true;
return 0;
}
public void VAGWriter(bool HEVAG = true)
public void VAGWriter(string file, bool HEVAG = true)
{
VAGData.Name = MSIO.Path.GetFileName(file);
if (!Success) return;
VAGData.Name = Path.GetFileName(file);
Stream writer = File.OpenWriter(file + ".vag", true);
Samp1 = new int[ch]; S1Ptr = Samp1.GetPtr();
Samp2 = new int[ch]; S2Ptr = Samp2.GetPtr();
@@ -466,6 +492,7 @@ namespace KKdSoundLib
if (HEVAG) writer.Write(VAGData.Channels);
else writer.Write((ushort)0x1);
writer.Write(VAGData.Name);
writer.LongLength = 0x30;
writer.LongPosition = 0x30;
if (HEVAG)
+2 -2
View File
@@ -37,6 +37,8 @@
<ItemGroup>
<Compile Include="classes\DataBase.cs" />
<Compile Include="classes\Tools\A3D.cs" />
<Compile Include="classes\Tools\AET.cs" />
<Compile Include="classes\Tools\DB.cs" />
<Compile Include="classes\Tools\DEX.cs" />
<Compile Include="classes\Tools\DIV.cs" />
<Compile Include="classes\Tools\STR.cs" />
@@ -51,8 +53,6 @@
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KKdMainLib\KKdMainLib.csproj">
+38 -23
View File
@@ -1,7 +1,7 @@
using System;
using System;
using System.Collections.Generic;
using KKdMainLib.IO;
using MSIO = System.IO;
using KKdMainLib.Types;
using KKdMain = KKdMainLib.Main;
using KKdFARC = KKdMainLib.FARC;
@@ -16,33 +16,34 @@ namespace PD_Tool
public static void Main(string[] args)
{
Console.Title = "PD_Tool";
if (args.Length == 0)
{
while (function != "Q") MainMenu();
Exit();
}
string header;
long header;
Stream reader;
KKdFARC Farc;
foreach (string arg in args)
{
Farc = new KKdFARC();
if (MSIO.Directory.Exists(arg)) Farc.Pack(arg);
else if (MSIO.File.Exists(arg) && MSIO.Path.GetExtension(arg) == ".farc") Farc.UnPack(arg, true);
else if (MSIO.File.Exists(arg))
if (Directory.Exists(arg)) Farc.Pack(arg);
else if (File.Exists(arg) && Path.GetExtension(arg) == ".farc") Farc.UnPack(arg, true);
else if (File.Exists(arg))
{
reader = File.OpenReader(arg);
header = reader.ReadString(8);
header = reader.ReadInt64();
reader.Close();
if (header.ToUpper() == "DIVAFILE") DIVAFILE.Decrypt(arg);
if (header == 0x454C494641564944) KKdMainLib.DIVAFILE.Decrypt(arg);
}
}
Exit();
}
private static bool JSON = false;
private static void MainMenu()
{
Console.Title = "PD_Tool";
@@ -57,7 +58,9 @@ namespace PD_Tool
KKdMain.ConsoleDesign("4. Encrypt to DIVAFILE");
KKdMain.ConsoleDesign("5. DB_Tools");
KKdMain.ConsoleDesign("6. Converting Tools");
KKdMain.ConsoleDesign(JSON ? "7. MsgPack to JSON" : "7. JSON to MsgPack");
KKdMain.ConsoleDesign(false);
KKdMain.ConsoleDesign(JSON ? "M. MessagePack" : "J. JSON");
KKdMain.ConsoleDesign("Q. Quit");
KKdMain.ConsoleDesign(false);
KKdMain.ConsoleDesign(true);
@@ -66,19 +69,20 @@ namespace PD_Tool
function = Console.ReadLine().ToUpper();
bool isNumber = int.TryParse(function, out int result);
if (isNumber) Functions();
if (function == "M") JSON = false;
else if (function == "J") JSON = true ;
}
private static void Functions()
{
Console.Clear();
if (function == "1" || function == "2")
FARC.Processor(function == "1");
if (function == "1" || function == "2") FARC.Processor(function == "1");
else if (function == "3" || function == "4")
{
KKdMain.Choose(1, "", out string[] FileNames);
foreach (string FileName in FileNames) DIVAFILE.Decrypt(FileName);
}
else if (function == "5") DataBase.Processor();
else if (function == "5") DataBase.Processor(JSON);
else if (function == "6")
{
Console.Clear();
@@ -86,26 +90,37 @@ namespace PD_Tool
KKdMain.ConsoleDesign(true);
KKdMain.ConsoleDesign(" Choose tool:");
KKdMain.ConsoleDesign(false);
KKdMain.ConsoleDesign("1. A3DA Converter");
KKdMain.ConsoleDesign("2. DEX Converter");
KKdMain.ConsoleDesign("3. DIVA Converter");
KKdMain.ConsoleDesign("4. STR Converter");
KKdMain.ConsoleDesign("5. VAG Converter");
KKdMain.ConsoleDesign("1. A3DA Converter");
KKdMain.ConsoleDesign("2. AET Converter");
KKdMain.ConsoleDesign("3. DataBank Converter");
KKdMain.ConsoleDesign("4. DEX Converter");
KKdMain.ConsoleDesign("5. DIVA Converter");
KKdMain.ConsoleDesign("6. STR Converter");
KKdMain.ConsoleDesign("7. VAG Converter");
KKdMain.ConsoleDesign(false);
KKdMain.ConsoleDesign("R. Return to Main Menu");
KKdMain.ConsoleDesign("Q. Quit");
KKdMain.ConsoleDesign(false);
KKdMain.ConsoleDesign(true);
Console.WriteLine();
string Function = Console.ReadLine();
Console.Clear();
if (Function == "1") Tools.A3D.Processor();
else if (Function == "2") Tools.DEX.Processor();
else if (Function == "3") Tools.DIV.Processor();
else if (Function == "4") Tools.STR.Processor();
else if (Function == "5") Tools.VAG.Processor();
if (Function == "1") Tools.A3D.Processor(JSON);
else if (Function == "2") Tools.AET.Processor(JSON);
else if (Function == "3") Tools.DB .Processor(JSON);
else if (Function == "4") Tools.DEX.Processor(JSON);
else if (Function == "5") Tools.DIV.Processor();
else if (Function == "6") Tools.STR.Processor(JSON);
else if (Function == "7") Tools.VAG.Processor();
else function = Function;
}
else if (function == "7")
{
KKdMain.Choose(1, JSON ? "mp" : "json", out string[] FileNames);
if (JSON) foreach (string file in FileNames)
KKdMainLib.MessagePack.MPExt.ToJSON (file.Replace(Path.GetExtension(file), ""));
else foreach (string file in FileNames)
KKdMainLib.MessagePack.MPExt.ToMsgPack(file.Replace(Path.GetExtension(file), ""));
}
}
public static void Exit() => Environment.Exit(0);
+2 -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.5.7")]
[assembly: AssemblyFileVersion("0.4.5.7")]
[assembly: AssemblyVersion("0.4.5.10")]
[assembly: AssemblyFileVersion("0.4.5.10")]
+77 -10
View File
@@ -1,13 +1,13 @@
using System;
using System.IO;
using KKdMainLib;
using KKdMainLib.DB;
using DB = KKdMainLib.DB;
namespace PD_Tool
{
public class DataBase
{
public static void Processor()
public static void Processor(bool JSON)
{
Console.Title = "DB Converter";
Console.Clear();
@@ -15,17 +15,23 @@ namespace PD_Tool
Main.ConsoleDesign(" Choose type of DataBase file:");
Main.ConsoleDesign(false);
Main.ConsoleDesign("1. Auth DB Converter");
Main.ConsoleDesign("2. AET DB Converter");
Main.ConsoleDesign("3. SPR DB Converter");
Main.ConsoleDesign(false);
Main.ConsoleDesign("R. Return to Main Menu");
Main.ConsoleDesign(false);
Main.ConsoleDesign(true);
Console.WriteLine();
string format = Console.ReadLine();
if (format == "1") AuthDBProcessor();
if (format == "1") AuthDBProcessor(JSON);
if (format == "2") AETDBProcessor(JSON);
if (format == "3") SPRDBProcessor(JSON);
}
public static void AuthDBProcessor()
public static void AuthDBProcessor(bool JSON)
{
Console.Title = "Auth DB Converter";
Auth Auth = new Auth();
DB.Auth Auth;
Main.Choose(1, "bin", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
@@ -33,21 +39,82 @@ namespace PD_Tool
foreach (string file in FileNames)
{
Console.Title = "Auth: DB Converter: " + Path.GetFileNameWithoutExtension(file);
Auth = new Auth();
Console.Title = "Auth DB Converter: " + Path.GetFileNameWithoutExtension(file);
Auth = new DB.Auth();
ext = Path.GetExtension(file).ToLower();
filepath = file.Replace(Path.GetExtension(file), "");
if (ext == ".bin")
{
Auth.BINReader (filepath);
Auth.MsgPackWriter(filepath);
Auth.MsgPackWriter(filepath, JSON);
}
else if (ext == ".mp")
else if (ext == ".mp" || ext == ".json")
{
Auth.MsgPackReader(filepath);
Auth.MsgPackReader(filepath, ext == ".json");
Auth.BINWriter (filepath);
}
Auth = null;
}
}
public static void AETDBProcessor(bool JSON)
{
Console.Title = "AET DB Converter";
DB.Aet Aet;
Main.Choose(1, "bin", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
foreach (string file in FileNames)
{
Console.Title = "AET DB Converter: " + Path.GetFileNameWithoutExtension(file);
Aet = new DB.Aet();
ext = Path.GetExtension(file).ToLower();
filepath = file.Replace(Path.GetExtension(file), "");
if (ext == ".bin")
{
Aet.BINReader (filepath);
Aet.MsgPackWriter(filepath, JSON);
}
else if (ext == ".mp" || ext == ".json")
{
Aet.MsgPackReader(filepath, ext == ".json");
Aet.BINWriter (filepath);
}
Aet = null;
}
}
public static void SPRDBProcessor(bool JSON)
{
Console.Title = "SPR DB Converter";
DB.Spr Spr;
Main.Choose(1, "bin", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
foreach (string file in FileNames)
{
Console.Title = "SPR DB Converter: " + Path.GetFileNameWithoutExtension(file);
Spr = new DB.Spr();
ext = Path.GetExtension(file).ToLower();
filepath = file.Replace(Path.GetExtension(file), "");
if (ext == ".bin")
{
Spr.BINReader (filepath);
Spr.MsgPackWriter(filepath, JSON);
}
else if (ext == ".mp" || ext == ".json")
{
Spr.MsgPackReader(filepath, ext == ".json");
Spr.BINWriter (filepath);
}
Spr = null;
}
}
}
+26 -29
View File
@@ -1,14 +1,13 @@
using System;
using KKdMainLib;
using KKdMainLib.IO;
using MSIO = System.IO;
using KKdA3DA = KKdMainLib.A3DA.A3DA;
namespace PD_Tool.Tools
{
class A3D
{
public static void Processor()
public static void Processor(bool JSON)
{
Console.Title = "A3DA Converter";
Main.Choose(1, "a3da", out string[] FileNames);
@@ -48,35 +47,33 @@ namespace PD_Tool.Tools
KKdA3DA A;
foreach (string file in FileNames)
try
{
ext = MSIO.Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "A3DA Converter: " +
MSIO.Path.GetFileNameWithoutExtension(file);
A = new KKdA3DA();
if (ext == ".a3da")
{
A.A3DAReader (filepath);
A.MsgPackWriter(filepath);
}
else if (ext == ".mp" )
{
A.MsgPackReader(filepath);
A.IO = File.OpenWriter(filepath + ".a3da", true);
if (A.Data.Header.Format < Main.Format.F2LE)
A.Data._.CompressF16 = Format == Main.Format.MGF ? 2 : 1;
A.Data.Header.Format = Format;
{
A = new KKdA3DA();
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
if (A.Data.Header.Format > Main.Format.DT && A.Data.Header.Format != Main.Format.FT)
A.A3DCWriter(filepath);
else
A.A3DAWriter();
}
Console.Title = "A3DA Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".a3da")
{
A.A3DAReader (filepath);
A.MsgPackWriter(filepath, JSON);
}
catch (Exception e)
{ Console.WriteLine(e); }
else if (ext == ".mp" || ext == ".json")
{
A.MsgPackReader(filepath, ext == ".json");
A.IO = File.OpenWriter(filepath + ".a3da", true);
if (A.Data.Header.Format < Main.Format.F2LE)
A.Data._.CompressF16 = Format == Main.Format.MGF ? 2 : 1;
A.Data.Header.Format = Format;
if (A.Data.Header.Format > Main.Format.DT && A.Data.Header.Format != Main.Format.FT)
A.A3DCWriter(filepath);
else
A.A3DAWriter();
}
A = null;
}
}
}
}
+41
View File
@@ -0,0 +1,41 @@
using System;
using KKdMainLib;
using KKdMainLib.IO;
using KKdAet = KKdMainLib.Aet.Aet;
namespace PD_Tool.Tools
{
public class AET
{
public static void Processor(bool JSON)
{
Console.Title = "AET Converter";
KKdAet Aet;
Main.Choose(1, "bin", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
foreach (string file in FileNames)
{
Aet = new KKdAet();
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "AET Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".bin")
{
Aet. AETReader(filepath);
Aet.MsgPackWriter(filepath, JSON);
}
else if (ext == ".mp" || ext == ".json")
{
Aet.MsgPackReader(filepath, ext == ".json");
Aet. AETWriter(filepath);
}
Aet = null;
}
}
}
}
+64
View File
@@ -0,0 +1,64 @@
using System;
using KKdMainLib;
using KKdMainLib.IO;
namespace PD_Tool.Tools
{
public class DB
{
public static void Processor(bool JSON)
{
Console.Title = "DataBank Converter";
Main.Choose(1, "databank", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
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();
DataBank DB;
string[] file_split;
int File_Checksum = 0, Get_Checksum;
foreach (string file in FileNames)
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
string filename = Path.GetFileNameWithoutExtension(file);
file_split = filename.Split('_');
DB = new DataBank();
if (file_split.Length == 5 && ext == ".dat")
{
if (!int.TryParse(file_split[3], out File_Checksum)) continue;
Get_Checksum = DCC.CalculateChecksum(file);
if (File_Checksum != Get_Checksum) continue;
filepath = file.Replace(filename + ".dat", "");
Console.Title = "DataBank Converter: " + filename;
DB. DBReader(file);
DB.MsgPackWriter(filepath + file_split[0] + "_" +
file_split[1] + "_" + file_split[2], JSON, format != "2");
}
else if (ext == ".mp" || ext == ".json")
{
Console.Title = "DataBank Converter: " + filename;
DB.MsgPackReader(filepath, JSON);
DB. DBWriter(filepath);
}
DB = null;
}
}
}
}
+20 -13
View File
@@ -1,13 +1,13 @@
using System;
using KKdMainLib;
using MSIO = System.IO;
using KKdMainLib.IO;
using KKdDEX = KKdMainLib.DEX;
namespace PD_Tool.Tools
{
public class DEX
{
public static void Processor()
public static void Processor(bool JSON)
{
Console.Title = "DEX Converter";
KKdDEX DEX;
@@ -16,10 +16,13 @@ namespace PD_Tool.Tools
string filepath = "";
string ext = "";
bool MP = true;
bool MP = true;
bool _JSON = true;
foreach (string file in FileNames)
if (file.EndsWith(".mp" ))
{ MP = false; break; }
{ MP = false; break; }
else if (file.EndsWith(".json"))
{ _JSON = false; break; }
Console.Clear();
string format = "";
@@ -29,7 +32,8 @@ namespace PD_Tool.Tools
Main.ConsoleDesign("1. F/FT PS3/PS4/PSVita");
Main.ConsoleDesign("2. F2nd PS3/PSVita");
Main.ConsoleDesign("3. X PS4/PSVita");
if (MP) Main.ConsoleDesign("9. MessagePack");
if ( MP && !JSON) Main.ConsoleDesign("9. MessagePack");
if (_JSON && JSON) Main.ConsoleDesign("9. JSON");
Main.ConsoleDesign(false);
Main.ConsoleDesign(true);
Console.WriteLine();
@@ -39,22 +43,25 @@ namespace PD_Tool.Tools
if (format == "1") Format = Main.Format.F ;
else if (format == "2") Format = Main.Format.F2LE;
else if (format == "3") Format = Main.Format.X ;
else if (format == "9" && MP ) Format = Main.Format.NULL;
else if (format == "9" && (MP && _JSON)) Format = Main.Format.NULL;
else return;
foreach (string file in FileNames)
{
DEX = new KKdDEX();
ext = MSIO.Path.GetExtension(file).ToLower();
filepath = file.Replace(MSIO.Path.GetExtension(file), "");
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "DEX Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".bin" || ext == ".dex")
DEX.DEXReader(filepath, ext);
else DEX.MsgPackReader(filepath);
DEX. DEXReader(filepath, ext );
else DEX.MsgPackReader(filepath, JSON);
if (Format > Main.Format.NULL)
DEX.DEXWriter(filepath, Format);
else DEX.MsgPackWriter(filepath);
DEX. DEXWriter(filepath, Format);
else DEX.MsgPackWriter(filepath, JSON );
DEX = null;
}
}
}
+13 -18
View File
@@ -11,28 +11,23 @@ namespace PD_Tool.Tools
{
Console.Title = "DIVA Converter";
Main.Choose(1, "diva", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
DIVA DIVA;
foreach (string file in FileNames)
try
{
string filepath = file.Replace(Path.GetExtension(file), "");
string ext = Path.GetExtension(file);
Console.Title = "DIVA Converter: " + Path.GetFileNameWithoutExtension(file);
DIVA = new DIVA(filepath);
switch (ext.ToLower())
{
case ".diva":
DIVA.DIVAReader();
break;
case ".wav":
DIVA.DIVAWriter();
break;
}
GC.Collect();
}
catch (Exception e) { Console.WriteLine(e.Message); }
{
DIVA = new DIVA();
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "DIVA Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".diva") DIVA.DIVAReader(filepath);
else if (ext == ".wav" ) DIVA.DIVAWriter(filepath);
DIVA = null;
}
}
}
}
+9 -7
View File
@@ -1,13 +1,13 @@
using System;
using KKdMainLib;
using MSIO = System.IO;
using KKdMainLib.IO;
using KKdSTR = KKdMainLib.STR;
namespace PD_Tool.Tools
{
public class STR
{
public static void Processor()
public static void Processor(bool JSON)
{
Console.Title = "STR Converter";
Main.Choose(1, "str", out string[] FileNames);
@@ -17,22 +17,24 @@ namespace PD_Tool.Tools
string ext = "";
foreach (string file in FileNames)
{
filepath = file.Replace(MSIO.Path.GetExtension(file), "");
ext = MSIO.Path.GetExtension(file).ToLower();
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Data = new KKdSTR();
Console.Title = "PD_Tool: Converter Tools: STR Reader: " +
MSIO.Path.GetFileNameWithoutExtension(file);
Path.GetFileNameWithoutExtension(file);
if (ext == ".str" || ext == ".bin")
{
Data.STRReader (filepath, ext);
Data.MsgPackWriter(filepath);
Data.MsgPackWriter(filepath, JSON);
}
else if (ext == ".mp")
{
Data.MsgPackReader(filepath);
Data.MsgPackReader(filepath, JSON);
Data.STRWriter (filepath);
}
Data = null;
}
}
}
+15 -20
View File
@@ -11,6 +11,10 @@ namespace PD_Tool.Tools
{
Console.Title = "VAG Converter";
Main.Choose(1, "vag", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
bool InputWAV = false;
foreach (string file in FileNames)
if (Path.GetExtension(file) == ".wav")
@@ -34,26 +38,17 @@ namespace PD_Tool.Tools
KKdVAG VAG;
foreach (string file in FileNames)
try
{
string ext = Path.GetExtension(file);
string filepath = file.Remove(file.Length - ext.Length);
Console.Title = "VAG Converter: " +
Path.GetFileNameWithoutExtension(file);
VAG = new KKdVAG() { file = filepath };
switch (ext.ToLower())
{
case ".vag":
VAG.VAGReader();
VAG.WAVWriter();
break;
case ".wav":
VAG.WAVReader();
VAG.VAGWriter(HE_VAG);
break;
}
}
catch (Exception e) { Console.WriteLine(e.Message); }
{
VAG = new KKdVAG();
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "VAG Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".vag") { VAG.VAGReader(filepath); VAG.WAVWriter(filepath ); }
else if (ext == ".wav") { VAG.WAVReader(filepath); VAG.VAGWriter(filepath, HE_VAG); }
VAG = null;
}
}
}
}
+4 -1
View File
@@ -8,11 +8,14 @@ A simple tool for working with Project Diva DT/FT/F/F2/X files
- `FARC Extract/Create`
- `DIVAFILE Encrypt/Decrypt`
- `DB_Tools`
- `Aet DB Converter`
- `Auth DB Converter`
- `Spr DB Converter`
- `Converting Tools`
- `A3DA Converter`
- `DataBank Converter`
- `DEX Converter`
- `DIVA Converter`
- `STR Converter`
- `VAG Converter`