Compare commits

...
11 Commits
Author SHA1 Message Date
korenkonder 38851135b6 Release v0.4.9.0
A3DA, Aet, DataBank, FARC, MOT, MotHead, Tables, VAG
2020-03-11 23:06:50 +03:00
korenkonder 9cbeaf59c2 Release v0.4.8.2
A3DA, AET, DataBank, FARC
2020-02-07 14:00:49 +03:00
korenkonder c70630e705 Release v0.4.8.1
A3DA, AET, DEX, DIVA, FARC, STR, VAG
2019-12-05 23:27:01 +03:00
korenkonder 6d80dfd0c9 Release v0.4.8.0
A3DA, Aet, DataBank, DEX, VAG
2019-11-05 10:28:28 +03:00
Kuji Kitamura 06b41269c0 Release v0.4.7.6
A3DA, AET, DCC, DIVAFILE, MOT
2019-10-27 17:49:16 +03:00
KujiKita 4698c75c7a Release v0.4.7.5
A3DA, Aet, AetDB, AuthDB, Databank, DEX, MOT, STR, VAG
2019-09-30 20:44:46 +03:00
KujiKita 792781a5f7 Release v0.4.7.4
Aet
2019-09-11 23:37:05 +03:00
KujiKita 773e148783 Release v0.4.7.3
A3DA
2019-09-04 01:16:03 +03:00
KujiKita 87d4862af5 Release v0.4.7.2
A3DA, BLT, CCT, DEX, DFT, LIT, Mot, SprDB
2019-08-21 03:04:19 +03:00
Kuji Kitamura b26cdc8b5c Release v0.4.7.1
A3DA
2019-08-07 21:24:59 +03:00
KujiKita 6e2f5746b0 Release v0.4.7.0
A3DA, Aet, AetDB, AuthDB, DataBank, DEX, DIVA, DIVAFILE, FARC, STR, VAG
2019-07-12 06:14:51 +03:00
107 changed files with 12985 additions and 7939 deletions
+3
View File
@@ -1,5 +1,8 @@
.vs
build
packages
KKdBaseLib/bin
KKdBaseLib/obj
KKdMainLib/bin
KKdMainLib/obj
KKdMathLib/bin
+26
View File
@@ -0,0 +1,26 @@
using KKdBaseLib.Auth3D;
namespace KKdBaseLib
{
public struct A3DAKey
{
public KeyType Type;
public float Value;
public float MaxFrames;
public EPType EPTypePre;
public EPType EPTypePost;
public float FrameDelta;
public float ValueDelta;
public int Unk1C;
public int Unk20;
public int Unk24;
public int Unk28;
public int Unk2C;
public int Unk30;
public int Unk34;
public long Length;
public long DataOffset; //Used only in-game and points to KFT3 Array
public KFT3[] Keys;
}
}
+194
View File
@@ -0,0 +1,194 @@
namespace KKdBaseLib.Auth2D
{
public struct Header
{
public Pointer<Scene>[] Scenes;
}
public struct Scene
{
public Pointer<string> Name;
public float StartFrame;
public float EndFrame;
public float FrameRate;
public uint BackColor;
public uint Width;
public uint Height;
public Pointer<Vector2<CountPointer<KFT2>>> Camera;
public CountPointer<Composition> Compositions;
public CountPointer<Video > Videos;
public CountPointer<Audio > Audios;
}
public struct Composition
{
public int P;
public int C { get => E != null ? E.Length : 0;
set => E = value > -1 ? new Layer[value] : null; }
public int O;
public Layer[] E;
public override string ToString() => "Count: " + C;
}
public struct Layer
{
public int ID;
public int Offset;
public Pointer<string> Name;
public float StartFrame;
public float EndFrame;
public float OffsetFrame;
public float TimeScale;
public AetLayerFlags Flags;
public AetLayerQuality Quality;
public AetLayerType Type;
public int VideoItemOffset;
public int ParentLayer;
public CountPointer<Marker> Markers;
public Pointer<VideoData> Video;
public Pointer<AudioData> Audio;
public int DataID;
public enum AetLayerFlags : ushort
{
VideoActive = 0b0000000000000001,
AudioActive = 0b0000000000000010,
EffectsActive = 0b0000000000000100,
MotionBlur = 0b0000000000001000,
FrameBlending = 0b0000000000010000,
Locked = 0b0000000000100000,
Shy = 0b0000000001000000,
Collapse = 0b0000000010000000,
AutoOrientRotation = 0b0000000100000000,
AdjustmentLayer = 0b0000001000000000,
TimeRemapping = 0b0000010000000000,
LayerIs3D = 0b0000100000000000,
LookAtCamera = 0b0001000000000000,
LookAtPOI = 0b0010000000000000, //POI - Point Of Interest
Solo = 0b0100000000000000,
MarkersLocked = 0b1000000000000000,
}
public enum AetLayerQuality : byte
{
None = 0,
Wireframe = 1,
Draft = 2,
Best = 3,
}
public enum AetLayerType : byte
{
None = 0,
Video = 1,
Audio = 2,
Composition = 3,
}
public override string ToString() => $"ID: {ID}; Name: {Name.V}; Type: {Type}" +
( DataID > -1 ? $"; " + $"Data ID: { DataID}" : "") +
(ParentLayer > -1 ? $"; Parent Object ID: {ParentLayer}" : "");
}
public struct Marker
{
public float Frame;
public Pointer<string> Name;
}
public struct VideoData
{
public VideoTransferMode TransferMode;
public byte Padding;
public CountPointer<KFT2> AnchorX;
public CountPointer<KFT2> AnchorY;
public CountPointer<KFT2> PositionX;
public CountPointer<KFT2> PositionY;
public CountPointer<KFT2> Rotation ;
public CountPointer<KFT2> ScaleX;
public CountPointer<KFT2> ScaleY;
public CountPointer<KFT2> Opacity ;
public Pointer<Video3DData> Video3D;
public struct VideoTransferMode
{
public TransferBlendMode BlendMode;
public TransferFlags Flags;
public TransferTrackMatte TrackMatte;
public enum TransferBlendMode : byte
{
Alpha = 3,
Additive = 5,
DstColorZero = 6,
SrcAlphaOneMinusSrcColor = 7,
Transparent = 8,
}
public enum TransferFlags : byte
{
PreserveAlpha = 0b01,
RandomizeDissolve = 0b10,
}
public enum TransferTrackMatte : byte
{
NoTrackMatte = 0,
Alpha = 1,
NotAlpha = 2,
Luma = 3,
NotLuma = 4,
}
}
public struct Video3DData
{
public CountPointer<KFT2> AnchorZ;
public CountPointer<KFT2> PositionZ;
public CountPointer<KFT2> DirectionX;
public CountPointer<KFT2> DirectionY;
public CountPointer<KFT2> DirectionZ;
public CountPointer<KFT2> RotationX;
public CountPointer<KFT2> RotationY;
public CountPointer<KFT2> ScaleZ;
}
}
public struct AudioData
{
public CountPointer<KFT2> VolumeL;
public CountPointer<KFT2> VolumeR;
public CountPointer<KFT2> PanL;
public CountPointer<KFT2> PanR;
}
public struct Video
{
public int O;
public uint Color;
public ushort Width;
public ushort Height;
public float Frames;
public CountPointer<Source> Sources;
public override string ToString() => $"Width: {Width}; Height: {Height}; Color: {Color.ToString("X2")}";
public struct Source
{
public Pointer<string> Name;
public uint ID;
public override string ToString() => $"ID: {ID}; Name: {Name}";
}
}
public struct Audio
{
public int O;
public uint SoundID;
}
}
+314
View File
@@ -0,0 +1,314 @@
namespace KKdBaseLib.Auth3D
{
public struct Data
{
public string[] Motion;
public string[] ObjectList;
public string[] ObjectHRCList;
public string[] MObjectHRCList;
public _ _;
public DOF? DOF;
public Fog[] Fog;
public Curve[] Curve;
public Event[] Event;
public Light[] Light;
public Object[] Object;
public Ambient[] Ambient;
public ObjectHRC[] ObjectHRC;
public CameraRoot[] CameraRoot;
public MObjectHRC[] MObjectHRC;
public PlayControl PlayControl;
public PostProcess? PostProcess;
public MaterialList[] MaterialList;
public ModelTransform[] Chara;
public ModelTransform[] Point;
public CameraAuxiliary? CameraAuxiliary;
}
public struct _
{
public CompressF16 CompressF16;
public string FileName;
public string PropertyVersion;
public string ConverterVersion;
}
public struct Ambient
{
public string Name;
public Vector4<Key> LightDiffuse;
public Vector4<Key> RimLightDiffuse;
}
public struct CameraAuxiliary
{
public Key Gamma;
public Key Exposure;
public Key Saturate;
public Key GammaRate;
public Key AutoExposure;
}
public struct CameraRoot
{
public ViewPoint VP;
public ModelTransform MT;
public ModelTransform Interest;
public struct ViewPoint
{
public bool FOVHorizontal;
public float? Aspect;
public float? CameraApertureH;
public float? CameraApertureW;
public Key FOV;
public Key Roll;
public Key FocalLength;
public ModelTransform MT;
}
}
public struct Curve
{
public string Name;
public Key CV;
}
public struct DOF
{
public string Name;
public ModelTransform MT;
}
public struct Event
{
public int? Type;
public float? End;
public float? Begin;
public float? ClipEnd;
public float? ClipBegin;
public float? TimeRefScale;
public string Name;
public string Param1;
public string Ref;
}
public struct Fog
{
public int? Id;
public Key End;
public Key Start;
public Key Density;
public Vector4<Key> Diffuse;
}
public enum CompressF16 : int
{
F32F32F32F32 = 0,
I16F16F32F32 = 1,
I16F16F16F16 = 2,
}
public enum EPType : int
{
EP_1 = 1,
EP_2 = 2,
EP_3 = 3,
}
public enum KeyType : int
{
Null = 0,
Value = 1,
Lerp = 2,
Hermite = 3,
Hold = 4,
}
public struct Key
{
public KeyType? Type;
public int Length;
public int? BinOffset;
public EPType EPTypePre;
public EPType EPTypePost;
public float? Max;
public float? Value;
public RawD RawData;
public KFT3[] Keys;
public struct RawD
{
public int KeyType;
public int ValueListSize;
public string ValueType;
public string[] ValueList;
}
public static Vector3<A3DAKey> ToA3DAKey(Vector3< Key> k) =>
new Vector3<A3DAKey> { X = (A3DAKey)k.X, Y = (A3DAKey)k.Y, Z = (A3DAKey)k.Z };
public static Vector3< Key> ToKey (Vector3<A3DAKey> k) =>
new Vector3< Key> { X = ( Key)k.X, Y = ( Key)k.Y, Z = ( Key)k.Z };
public static explicit operator Key(A3DAKey k)
{
Key key = default;
key.EPTypePost = k.EPTypePost;
key.EPTypePre = k.EPTypePre;
key.Max = k.MaxFrames;
if (k.Length > 1)
{
key.Type = k.Type;
key.Length = (int)k.Length;
key.Keys = k.Keys;
}
else if (k.Length == 1)
{
key.Type = KeyType.Value;
key.Value = k.Keys[0].V;
}
return key;
}
public static explicit operator A3DAKey(Key k)
{
A3DAKey key = default;
key.EPTypePost = k.EPTypePost;
key.EPTypePre = k.EPTypePre;
key.MaxFrames = k.Max ?? 0;
if (k.Type != null && k.Length > 1)
{
key.Type = k.Type.Value;
key.Length = k.Length;
key.Keys = k.Keys;
key.FrameDelta = k.Keys[k.Length - 1].F - k.Keys[0].F;
key.ValueDelta = k.Keys[k.Length - 1].V - k.Keys[0].V;
}
else
{
key.Type = 0;
key.Value = 0.0f;
if (k.Type.HasValue && k.Value.HasValue)
{
key.Type = k.Type.Value;
key.Value = k.Value.Value;
}
}
return key;
}
}
public struct Light
{
public int? Id;
public string Name;
public string Type;
public Vector4<Key> Ambient;
public Vector4<Key> Diffuse;
public Vector4<Key> Specular;
public Vector4<Key> Incandescence;
public ModelTransform Position;
public ModelTransform SpotDirection;
}
public struct MaterialList
{
public string Name;
public string HashName;
public Key GlowIntensity;
public Vector4<Key> BlendColor;
public Vector4<Key> Incandescence;
}
public struct MObjectHRC
{
public string Name;
public Node[] Node;
public Vector3<float?> JointOrient;
public Instance[] Instances;
public ModelTransform MT;
public struct Instance
{
public int? Shadow;
public string Name;
public string UIDName;
public ModelTransform MT;
}
}
public struct ModelTransform
{
public bool Writed;
public int? BinOffset;
public Key Visibility;
public Vector3<Key> Rot;
public Vector3<Key> Scale;
public Vector3<Key> Trans;
}
public struct Node
{
public int? Parent;
public string Name;
public ModelTransform MT;
}
public struct Object
{
public int? MorphOffset;
public string Name;
public string Morph;
public string UIDName;
public string ParentName;
public ModelTransform MT;
public TexturePattern[] TexPat;
public TextureTransform[] TexTrans;
public struct TexturePattern
{
public int? PatOffset;
public string Pat;
public string Name;
}
public struct TextureTransform
{
public string Name;
public Key Rotate;
public Key RotateFrame;
public Vector2<Key> Offset;
public Vector2<Key> Repeat;
public Vector2<Key> Coverage;
public Vector2<Key> TranslateFrame;
}
}
public struct ObjectHRC
{
public int? Shadow;
public string Name;
public string UIDName;
public Node[] Node;
public Vector3<float?> JointOrient;
}
public struct PlayControl
{
public int Begin;
public int? Div;
public int FPS;
public int? Offset;
public int Size;
}
public struct PostProcess
{
public Key LensFlare;
public Key LensGhost;
public Key LensShaft;
public Vector4<Key> Ambient;
public Vector4<Key> Diffuse;
public Vector4<Key> Specular;
}
}
+42 -7
View File
@@ -1,10 +1,8 @@
//Original research by Samyuu
using KKdMainLib.IO;
namespace KKdMainLib
namespace KKdBaseLib
{
public static class DCC //Databank_Checksum_Calculator
public static class DCC //Databank Checksum Calculator
{
private static readonly ushort[] ChecksumLookupTable = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
@@ -41,14 +39,51 @@ namespace KKdMainLib
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0,
};
public static ushort CalculateChecksum(string file) => CalculateChecksum(File.ReadAllBytes(file));
public static ushort CalculateChecksum(byte[] data)
public static ushort CalculateChecksum(this byte[] data)
{
ushort result = 0xFFFF;
for (int i = 0; i < data.Length; i++)
result = (ushort)(ChecksumLookupTable[(result >> 8) ^ data[i]] ^ (result << 8));
return result;
}
public static uint CalculateChecksumUInt(this byte[] data)
{
uint result = 0xFFFFFFFF;
for (int i = 0; i < data.Length; i++)
result = ChecksumLookupTable[(byte)(result >> 8) ^ data[i]] ^ (result << 8);
return result;
}
public static ulong CalculateChecksumULong(this byte[] data)
{
ulong result = 0xFFFFFFFFFFFFFFFF;
for (int i = 0; i < data.Length; i++)
result = ChecksumLookupTable[(byte)(result >> 8) ^ data[i]] ^ (result << 8);
return result;
}
public static unsafe ushort CalculateChecksum(byte* data, int length)
{
ushort result = 0xFFFF;
for (int i = 0; i < length; i++)
result = (ushort)(ChecksumLookupTable[(result >> 8) ^ data[i]] ^ (result << 8));
return result;
}
public static unsafe uint CalculateChecksumUInt(byte* data, int length)
{
uint result = 0xFFFFFFFF;
for (int i = 0; i < length; i++)
result = ChecksumLookupTable[(byte)(result >> 8) ^ data[i]] ^ (result << 8);
return result;
}
public static unsafe ulong CalculateChecksumULong(byte* data, int length)
{
ulong result = 0xFFFFFFFFFFFFFFFF;
for (int i = 0; i < length; i++)
result = ChecksumLookupTable[(byte)(result >> 8) ^ data[i]] ^ (result << 8);
return result;
}
}
+274
View File
@@ -0,0 +1,274 @@
using System;
namespace KKdBaseLib
{
public static unsafe class Extensions
{
private const double RadPi = 180 / Math.PI;
public static double ToDegrees(this double val) => val * RadPi;
public static double ToRadians(this double val) => val / RadPi;
public static double Acos (this double d ) => Math.Acos (d );
public static double Asin (this double d ) => Math.Asin (d );
public static double Atan (this double d ) => Math.Atan (d );
public static double Aсtg (this double d ) => 1 / Math.Atan (d );
public static double Cos (this double d ) => Math.Cos (d );
public static double Cosh (this double val) => Math.Cosh (val);
public static double Sin (this double a ) => Math.Sin (a );
public static double Sinh (this double val) => Math.Sinh (val);
public static double Tan (this double a ) => Math.Tan (a );
public static double Tanh (this double val) => Math.Tanh (val);
public static double Ctg (this double a ) => 1 / Math.Tan (a );
public static double Ctgh (this double val) => 1 / Math.Tanh (val);
public static double Abs (this double val) => Math.Abs (val);
public static double Ceiling(this double a ) => Math.Ceiling(a );
public static double Exp (this double d ) => Math.Exp (d );
public static double Log (this double d ) => Math.Log (d );
public static double Log10 (this double d ) => Math.Log10 (d );
public static double Round (this double d ) => Math.Round (d );
public static int Sign (this double val) => Math.Sign (val);
public static double Sqrt (this double d ) => Math.Sqrt (d );
public static double Atan2(this double y , double x ) => Math.Atan2(y , x );
public static double Log (this double val , double newBase) => Math.Log (val , newBase);
public static double Max (this double val1, double val2 ) => Math.Max (val1, val2 );
public static double Min (this double val1, double val2 ) => Math.Min (val1, val2 );
public static double Pow (this double x , double y ) => Math.Pow (x , y );
public static double Round(this double val , int d ) => Math.Round(val , d );
public static float ToDegrees(this float val) => (float)(val * RadPi);
public static float ToRadians(this float val) => (float)(val / RadPi);
public static float Acos (this float d ) => (float) Math.Acos (d ) ;
public static float Asin (this float d ) => (float) Math.Asin (d ) ;
public static float Atan (this float d ) => (float) Math.Atan (d ) ;
public static float Aсtg (this float d ) => (float)(1 / Math.Atan (d ));
public static float Cos (this float d ) => (float) Math.Cos (d ) ;
public static float Cosh (this float val) => (float) Math.Cosh (val) ;
public static float Sin (this float a ) => (float) Math.Sin (a ) ;
public static float Sinh (this float val) => (float) Math.Sinh (val) ;
public static float Tan (this float a ) => (float) Math.Tan (a ) ;
public static float Tanh (this float val) => (float) Math.Tanh (val) ;
public static float Ctg (this float a ) => (float)(1 / Math.Tan (a ));
public static float Ctgh (this float val) => (float)(1 / Math.Tanh (val));
public static float Abs (this float val) => Math.Abs (val) ;
public static float Ceiling(this float a ) => (float) Math.Ceiling(a ) ;
public static float Exp (this float d ) => (float) Math.Exp (d ) ;
public static float Log (this float d ) => (float) Math.Log (d ) ;
public static float Log10 (this float d ) => (float) Math.Log10 (d ) ;
public static float Round (this float d ) => (float) Math.Round (d ) ;
public static float Sqrt (this float d ) => (float) Math.Sqrt (d ) ;
public static float Atan2(this float y , float x ) => (float)Math.Atan2(y , x );
public static float Log (this float val , float newBase) => (float)Math.Log (val , newBase);
public static float Max (this float val1, float val2 ) => Math.Max (val1, val2 );
public static float Min (this float val1, float val2 ) => Math.Min (val1, val2 );
public static float Pow (this float x , float y ) => (float)Math.Pow (x , y );
public static float Round(this float val , int d ) => (float)Math.Round(val , d );
public static void FC( ref double Value) =>
Value = Value % 1 >= 0.5 ? (long)(Value + 0.5) : (long)Value;
public static long FC(this double Value) =>
Value % 1 >= 0.5 ? (long)(Value + 0.5) : (long)Value;
public static int A(this int value, int alignement, int divide = 1) =>
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
public static uint A(this uint value, uint alignement, uint divide = 1) =>
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
public static long A(this long value, long alignement, long divide = 1) =>
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
public static ulong A(this ulong value, ulong alignement, ulong divide = 1) =>
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
private static byte[] buf = new byte[8];
public static byte[] E(this byte[] le, byte len)
{ for (byte i = 0; i < len; i++) buf[i] = le[i];
for (byte i = 0; i < len; i++) le[len - i - 1] = buf[i]; return le; }
public static byte[] E(this byte[] le, byte len, bool isBE)
{ if (isBE) { for (byte i = 0; i < len; i++) buf[i] = le[i];
for (byte i = 0; i < len; i++) le[len - i - 1] = buf[i]; } return le; }
public static short E(this short le, bool isBE)
{ if (isBE) { for (byte i = 0; i < 2; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
for (byte i = 0; i < 2; i++) { le = (short)((int)le |
buf[i]); if (i < 1) le <<= 8; } } return le; }
public static ushort E(this ushort le, bool isBE)
{ if (isBE) { for (byte i = 0; i < 2; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
for (byte i = 0; i < 2; i++) { le |= buf[i]; if (i < 1) le <<= 8; } } return le; }
public static int E(this int le, bool isBE)
{ if (isBE) { for (byte i = 0; i < 4; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
for (byte i = 0; i < 4; i++) { le |= buf[i]; if (i < 3) le <<= 8; } } return le; }
public static uint E(this uint le, bool isBE)
{ if (isBE) { for (byte i = 0; i < 4; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
for (byte i = 0; i < 4; i++) { le |= buf[i]; if (i < 3) le <<= 8; } } return le; }
public static long E(this long le, bool isBE)
{ if (isBE) { for (byte i = 0; i < 8; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
for (byte i = 0; i < 8; i++) { le |= buf[i]; if (i < 7) le <<= 8; } } return le; }
public static ulong E(this ulong le, bool isBE)
{ if (isBE) { for (byte i = 0; i < 8; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
for (byte i = 0; i < 8; i++) { le |= buf[i]; if (i < 7) le <<= 8; } } return le; }
public static short TI16(this byte[] arr)
{ short val; fixed (byte* ptr = arr) val = *( short*)ptr; return val; }
public static ushort TU16(this byte[] arr)
{ ushort val; fixed (byte* ptr = arr) val = *(ushort*)ptr; return val; }
public static int TI32(this byte[] arr)
{ int val; fixed (byte* ptr = arr) val = *( int*)ptr; return val; }
public static uint TU32(this byte[] arr)
{ uint val; fixed (byte* ptr = arr) val = *( uint*)ptr; return val; }
public static long TI64(this byte[] arr)
{ long val; fixed (byte* ptr = arr) val = *( long*)ptr; return val; }
public static ulong TU64(this byte[] arr)
{ ulong val; fixed (byte* ptr = arr) val = *( ulong*)ptr; return val; }
public static float TF32(this byte[] arr)
{ float val; fixed (byte* ptr = arr) val = *( float*)ptr; return val; }
public static double TF64(this byte[] arr)
{ double val; fixed (byte* ptr = arr) val = *(double*)ptr; return val; }
public static void GBy(this byte[] arr, short val)
{ fixed (byte* ptr = arr) *( short*)ptr = val; }
public static void GBy(this byte[] arr, ushort val)
{ fixed (byte* ptr = arr) *(ushort*)ptr = val; }
public static void GBy(this byte[] arr, int val)
{ fixed (byte* ptr = arr) *( int*)ptr = val; }
public static void GBy(this byte[] arr, uint val)
{ fixed (byte* ptr = arr) *( uint*)ptr = val; }
public static void GBy(this byte[] arr, long val)
{ fixed (byte* ptr = arr) *( long*)ptr = val; }
public static void GBy(this byte[] arr, ulong val)
{ fixed (byte* ptr = arr) *( ulong*)ptr = val; }
public static void GBy(this byte[] arr, float val)
{ fixed (byte* ptr = arr) *( float*)ptr = val; }
public static void GBy(this byte[] arr, double val)
{ fixed (byte* ptr = arr) *(double*)ptr = val; }
public static sbyte CITSB(this int c)
{ return ( sbyte)(c > 0x0000007F ?
0x0000007F : c < -0x00000080 ? -0x00000080 : c); }
public static byte CITB (this int c)
{ return ( byte)(c > 0x000000FF ?
0x000000FF : c < 0x00000000 ? 0x00000000 : c); }
public static short CITS (this int c)
{ return ( short)(c > 0x00007FFF ?
0x00007FFF : c < -0x00008000 ? -0x00008000 : c); }
public static ushort CITUS(this int c)
{ return (ushort)(c > 0x0000FFFF ?
0x0000FFFF : c < 0x00000000 ? 0x00000000 : c); }
public static sbyte CFTSB(this float c)
{ c = c.Round(); return ( sbyte)(c > 0x0000007F ?
0x0000007F : c < -0x00000080 ? -0x00000080 : c); }
public static byte CFTB (this float c)
{ c = c.Round(); return ( byte)(c > 0x000000FF ?
0x000000FF : c < 0x00000000 ? 0x00000000 : c); }
public static short CFTS (this float c)
{ c = c.Round(); return ( short)(c > 0x00007FFF ?
0x00007FFF : c < -0x00008000 ? -0x00008000 : c); }
public static ushort CFTUS(this float c)
{ c = c.Round(); return (ushort)(c > 0x0000FFFF ?
0x0000FFFF : c < 0x00000000 ? 0x00000000 : c); }
public static sbyte CFTSB(this double c)
{ c = c.Round(); return ( sbyte)(c > 0x0000007F ?
0x0000007F : c < -0x00000080 ? -0x00000080 : c); }
public static byte CFTB (this double c)
{ c = c.Round(); return ( byte)(c > 0x000000FF ?
0x000000FF : c < 0x00000000 ? 0x00000000 : c); }
public static short CFTS (this double c)
{ c = c.Round(); return ( short)(c > 0x00007FFF ?
0x00007FFF : c < -0x00008000 ? -0x00008000 : c); }
public static ushort CFTUS(this double c)
{ c = c.Round(); return (ushort)(c > 0x0000FFFF ?
0x0000FFFF : c < 0x00000000 ? 0x00000000 : c); }
public static int CFTI (this double c)
{ c = c.Round(); return ( int)(c > 0x7FFFFFFF ?
0x7FFFFFFF : c < -0x80000000 ? -0x80000000 : c); }
public static uint CFTUI(this double c)
{ c = c.Round(); return ( uint)(c > 0xFFFFFFFF ?
0xFFFFFFFF : c < 0xFFFFFFFF ? 0x00000000 : c); }
public static int ToI32(this float f) => *( int*)&f;
public static uint ToU32(this float f) => *( uint*)&f;
public static long ToI64(this double f) => *( long*)&f;
public static ulong ToU64(this double f) => *(ulong*)&f;
public static float ToF32(this int i) => *( float*)&i;
public static float ToF32(this uint i) => *( float*)&i;
public static double ToF64(this long i) => *(double*)&i;
public static double ToF64(this ulong i) => *(double*)&i;
public static string ToString(this int d, bool BE) =>
BitConverter.GetBytes(d.E(BE)).ToASCII();
public static string ToS(this object d)
{
if (d == null ) return "Null";
else if (d is bool boolean) return boolean ? "true" : "false";
else if (d is float f32 ) return ToS(f32);
else if (d is double f64 ) return ToS(f64);
return d.ToString();
}
private static readonly string NDS =
System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
public static string ToS(this bool? d) => (d ?? default).ToString();
public static string ToS(this bool d) => d.ToString().ToLower();
public static string ToS(this sbyte? d) => (d ?? default).ToString();
public static string ToS(this sbyte d) => d.ToString();
public static string ToS(this byte? d) => (d ?? default).ToString();
public static string ToS(this byte d) => d.ToString();
public static string ToS(this short? d) => (d ?? default).ToString();
public static string ToS(this short d) => d.ToString();
public static string ToS(this ushort? d) => (d ?? default).ToString();
public static string ToS(this ushort d) => d.ToString();
public static string ToS(this int? d) => (d ?? default).ToString();
public static string ToS(this int d) => d.ToString();
public static string ToS(this uint? d) => (d ?? default).ToString();
public static string ToS(this uint d) => d.ToString();
public static string ToS(this long? d) => (d ?? default).ToString();
public static string ToS(this long d) => d.ToString();
public static string ToS(this ulong? d) => (d ?? default).ToString();
public static string ToS(this ulong d) => d.ToString();
public static string ToS(this float? d, int round) => (d ?? default).ToS(round);
public static string ToS(this float? d) => (d ?? default).ToS();
public static string ToS(this float d, int round)
{ string s = (d.ToU32() & 0x80000000) != 0 ? "-" : ""; d = (d.ToU32() & 0x7FFFFFFF).ToF32();
return s + Math.Round(d, round).ToString().ToLower().Replace(NDS, "."); }
public static string ToS(this float d)
{ string s = (d.ToU32() & 0x80000000) != 0 ? "-" : ""; d = (d.ToU32() & 0x7FFFFFFF).ToF32();
return s + Math.Round(d, 15).ToString().ToLower().Replace(NDS, "."); }
public static string ToS(this double? d, int round) => (d ?? default).ToS(round);
public static string ToS(this double? d) => (d ?? default).ToS();
public static string ToS(this double d, int round)
{ string s = (d.ToU64() & 0x8000000000000000) != 0 ? "-" : ""; d = (d.ToU64() & 0x7FFFFFFFFFFFFFFF).ToF64();
return s + Math.Round(d, round).ToString().ToLower().Replace(NDS, "."); }
public static string ToS(this double d)
{ string s = (d.ToU64() & 0x8000000000000000) != 0 ? "-" : ""; d = (d.ToU64() & 0x7FFFFFFFFFFFFFFF).ToF64();
return s + Math.Round(d, 15).ToString().ToLower().Replace(NDS, "."); }
public static float ToF32(this string s)
{ if (s.Length < 1) return 0; uint d = 0; if (s[0] == '-') d = 0x80000000;
d |= float.Parse(s.Replace(".", NDS)).ToU32(); return d.ToF32(); }
public static double ToF64(this string s)
{ if (s.Length < 1) return 0; ulong d = 0; if (s[0] == '-') d = 0x8000000000000000;
d |= double.Parse(s.Replace(".", NDS)).ToU64(); return d.ToF64(); }
public static bool ToF32(this string s, out float val)
{ val = 0; if (s.Length < 1) return false; uint d = 0; if (s[0] == '-') d = 0x80000000;
bool b = float.TryParse(s.Replace(".", NDS), out val); if (b) val = (d | val.ToU32()).ToF32(); return b; }
public static bool ToF64(this string s, out double val)
{ val = 0; if (s.Length < 1) return false; ulong d = 0; if (s[0] == '-') d = 0x8000000000000000;
bool b = double.TryParse(s.Replace(".", NDS), out val); if (b) val = (d | val.ToU64()).ToF64(); return b; }
public static bool ToF32(this string s, out float? val)
{ val = null; if (s.Length < 1) return false; uint d = 0; if (s[0] == '-') d = 0x80000000;
bool b = float.TryParse(s.Replace(".", NDS), out float t); if (b) val = (d | t.ToU32()).ToF32(); return b; }
public static bool ToF64(this string s, out double? val)
{ val = null; if (s.Length < 1) return false; ulong d = 0; if (s[0] == '-') d = 0x8000000000000000;
bool b = double.TryParse(s.Replace(".", NDS), out double t); if (b) val = (d | t.ToU64()).ToF64(); return b; }
}
}
+255
View File
@@ -0,0 +1,255 @@
namespace KKdBaseLib.F2
{
public struct ENRS : INull
{
public ENRSEntry[] Array;
public int Length => length();
public bool IsNull => Array == null;
public bool NotNull => Array != null;
public unsafe void Read(byte[] data)
{
if (data == null || data.Length < 0x10) return;
fixed (byte* ptr = data)
{
int i, i0;
int ENRSCount = ((int*)ptr)[1];
ENRSEntry enrsEntry;
ENRSEntry.SubENRSEntry sub;
Array = new ENRSEntry[ENRSCount];
byte* localPtr = ptr + 0x10;
for (i = 0; i < ENRSCount; i++)
{
enrsEntry = default;
enrsEntry.Offset = ReadENRSValue(ref localPtr);
enrsEntry.Count = ReadENRSValue(ref localPtr);
enrsEntry.Size = ReadENRSValue(ref localPtr);
enrsEntry.Repeat = ReadENRSValue(ref localPtr);
if (i > 0) enrsEntry.Offset += Array[i - 1].Offset;
if (enrsEntry.Repeat < 1) { enrsEntry.Sub = null; Array[i] = enrsEntry; continue; }
enrsEntry.Sub = new ENRSEntry.SubENRSEntry[enrsEntry.Count];
for (i0 = 0; i0 < enrsEntry.Count; i0++)
{
sub = default;
sub.Skip = ReadENRSValue(ref localPtr, out sub.Type);
sub.Reverse = ReadENRSValue(ref localPtr);
if (i0 > 0) sub.Skip += enrsEntry.Sub[i0 - 1].SizeSkip;
enrsEntry.Sub[i0] = sub;
if (enrsEntry.Sub[i0].Type == ENRSEntry.Type.Invalid) { Array = null; return; }
}
Array[i] = enrsEntry;
}
}
}
public unsafe byte[] Write()
{
int i, i0;
byte[] data;
if (IsNull || Array.Length < 1) return new byte[0x20];
data = new byte[Length];
fixed (byte* ptr = data)
{
((int*)ptr)[1] = Array.Length;
byte* localPtr = ptr + 0x10;
for (i = 0; i < Array.Length; i++)
{
ENRSEntry enrsEntry = Array[i];
WriteENRSValue(ref localPtr, i > 0 ? enrsEntry.Offset -
Array[i - 1].Offset : enrsEntry.Offset);
WriteENRSValue(ref localPtr, enrsEntry.Count > enrsEntry.Sub.Length ?
enrsEntry.Sub.Length : enrsEntry.Count);
WriteENRSValue(ref localPtr, enrsEntry.Size );
WriteENRSValue(ref localPtr, enrsEntry.Repeat);
if (enrsEntry.Repeat < 1) continue;
for (i0 = 0; i0 < enrsEntry.Count && i0 < enrsEntry.Sub.Length; i0++)
{
if (enrsEntry.Sub[i0].Type < ENRSEntry.Type. WORD ||
enrsEntry.Sub[i0].Type > ENRSEntry.Type.QWORD)
return data;
WriteENRSValue(ref localPtr, i0 > 0 ? enrsEntry.Sub[i0].Skip -
enrsEntry.Sub[i0 - 1].SizeSkip : enrsEntry.Sub[i0].Skip, enrsEntry.Sub[i0].Type);
WriteENRSValue(ref localPtr, enrsEntry.Sub[i0].Reverse);
}
}
}
return data;
}
private int length()
{
int i, i0;
int length = 0x10;
for (i = 0; i < Array.Length; i++)
{
ENRSEntry enrs = Array[i];
length += GetSize(i > 0 ? enrs.Offset - Array[i - 1].Offset : enrs.Offset);
length += GetSize(enrs.Count );
length += GetSize(enrs.Size );
length += GetSize(enrs.Repeat);
if (enrs.Repeat < 1) continue;
for (i0 = 0; i0 < enrs.Count; i0++)
{
if (enrs.Sub[i0].Type < ENRSEntry.Type. WORD ||
enrs.Sub[i0].Type > ENRSEntry.Type.QWORD) return length.A(0x10);
length += GetSizeType(i0 > 0 ? enrs.Sub[i0].Skip -
enrs.Sub[i0 - 1].SizeSkip : enrs.Sub[i0].Skip);
length += GetSize(enrs.Sub[i0].Reverse);
}
}
return length.A(0x10);
static int GetSizeType(int val) => val < 0x00000010 ? 1 : val < 0x00001000 ? 2 : 4;
static int GetSize (int val) => val < 0x00000040 ? 1 : val < 0x00004000 ? 2 : 4;
}
/*private static KKdList<ENRS.SubENRS> Optimize(KKdList<ENRS.SubENRS> Sub)
{
if (Sub.IsNull || Sub.Count < 2) return Sub;
for (int i = 1; i < Sub.Capacity; i++)
if (Sub[i - 1].Skip == Sub[i].Skip - Sub[i - 1].Size && Sub[i - 1].Type == Sub[i].Type)
{
ENRS.SubENRS SubENRS = Sub[i - 1];
SubENRS.Reverse++;
Sub[i - 1] = SubENRS;
Sub.RemoveAt(i);
Sub.Capacity--;
i--;
}
return Sub;
}*/
[System.ThreadStatic] private static ENRSEntry.Value value;
private unsafe static int ReadENRSValue(ref byte* ptr, out ENRSEntry.Type type)
{
int V = *ptr & 0xF;
type = (ENRSEntry. Type)((*ptr & 0x30) >> 4);
value = (ENRSEntry.Value)((*ptr & 0xC0) >> 6);
ptr++;
if (value == ENRSEntry.Value.Int32 )
{ V = (V << 24) | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; ptr += 3; }
else if (value == ENRSEntry.Value.Int16 )
{ V = (V << 8) | ptr[0]; ptr += 1; }
else if (value == ENRSEntry.Value.Invalid) V = 0;
return V;
}
private unsafe static int ReadENRSValue(ref byte* ptr)
{
int V = *ptr & 0x3F;
value = (ENRSEntry.Value)((*ptr & 0xC0) >> 6);
ptr++;
if (value == ENRSEntry.Value.Int32 )
{ V = (V << 24) | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; ptr += 3; }
else if (value == ENRSEntry.Value.Int16 )
{ V = (V << 8) | ptr[0]; ptr += 1; }
else if (value == ENRSEntry.Value.Invalid) V = 0;
return V;
}
private unsafe static void WriteENRSValue(ref byte* ptr, int val, ENRSEntry.Type type)
{
value = ENRSEntry.Value.Invalid;
if (val < 0x00000040) value = ENRSEntry.Value.Int8 ;
else if (val < 0x00004000) value = ENRSEntry.Value.Int16;
else if (val < 0x40000000) value = ENRSEntry.Value.Int32;
*ptr = (byte)((((byte)value << 6) & 0xC0) | (((byte)type << 4) & 0x30));
if (val < 0x00000010)
{ *ptr |= (byte)( val & 0x0F); }
else if (val < 0x00001000)
{ *ptr |= (byte)((val >> 8) & 0x0F); ptr++;
*ptr = (byte)( val & 0xFF); }
else if (val < 0x10000000)
{ *ptr |= (byte)((val >> 24) & 0x0F); ptr++;
*ptr = (byte)((val >> 16) & 0xFF); ptr++;
*ptr = (byte)((val >> 8) & 0xFF); ptr++;
*ptr = (byte)( val & 0xFF); }
ptr++;
}
private unsafe static void WriteENRSValue(ref byte* ptr, int val)
{
value = ENRSEntry.Value.Invalid;
if (val < 0x00000040) value = ENRSEntry.Value.Int8 ;
else if (val < 0x00004000) value = ENRSEntry.Value.Int16;
else if (val < 0x40000000) value = ENRSEntry.Value.Int32;
*ptr = (byte)(((byte)value << 6) & 0xC0);
if (val < 0x00000040)
{ *ptr |= (byte)( val & 0x3F); }
else if (val < 0x00004000)
{ *ptr |= (byte)((val >> 8) & 0x3F); ptr++;
*ptr = (byte)( val & 0xFF); }
else if (val < 0x40000000)
{ *ptr |= (byte)((val >> 24) & 0x3F); ptr++;
*ptr = (byte)((val >> 16) & 0xFF); ptr++;
*ptr = (byte)((val >> 8) & 0xFF); ptr++;
*ptr = (byte)( val & 0xFF); }
ptr++;
}
public struct ENRSEntry
{
public int Offset;
public int Count;
public int Size;
public int Repeat;
public SubENRSEntry[] Sub;
public enum Type : byte
{
WORD = 0b00,
DWORD = 0b01,
QWORD = 0b10,
Invalid = 0b11,
}
public enum Value : byte
{
Int8 = 0b00,
Int16 = 0b01,
Int32 = 0b10,
Invalid = 0b11,
}
public struct SubENRSEntry
{
public int Skip;
public int Reverse;
public Type Type;
public int SizeSkip => Skip + Reverse * (2 << (byte)Type);
public int Size => Reverse * (2 << (byte)Type);
public override string ToString() => "Skip: " + Skip +
"; Reverse: " + Reverse + "; Type: " + Type;
}
public override string ToString() =>
"Offset: " + Offset + "; Count: " + Count + "; " +
"Size: " + Size + "; Repeat: " + Repeat;
}
public override string ToString() =>
$"{(NotNull ? $"ENRS Count: {Array.Length}" : "No ENRS")}";
}
}
+23
View File
@@ -0,0 +1,23 @@
namespace KKdBaseLib.F2
{
public struct Header
{
public int Signature;
public int DataSize;
public int Length;
public int Flags;
public int Depth;
public int SectionSize;
public int Mode;
public int InnerSignature;
public int SectionSignature;
public Format Format;
public bool NotUseDataSizeAsSectionSize;
public bool IsBE => Format == Format.F2BE;
public bool IsX => Format == Format.X || Format == Format.XHD;
public override string ToString() => Signature.ToString(false);
}
}
+105
View File
@@ -0,0 +1,105 @@
namespace KKdBaseLib.F2
{
public struct POF : INull
{
public KKdList<long> Offsets;
public bool IsNull => Offsets. IsNull;
public bool NotNull => Offsets.NotNull;
public int Length => length(false).A(0x10);
public int LengthX => length( true).A(0x10);
public unsafe void Read(byte[] data, bool shiftX)
{
Value Val = 0;
Offsets = KKdList<long>.New;
fixed (byte* ptr = data)
{
int i = 0, offset = 0, v = 0;
byte bitShift = (byte)(shiftX ? 3 : 2);
int length = *(int*)ptr - 4;
byte* localPtr = ptr + 4;
while (length > i)
{
v = *ptr & 0x3F;
Val = (Value)(*ptr & 0xC0);
localPtr++; i++;
if (Val == Value.Int32 )
{ v = (v << 24) | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; localPtr += 3; i += 3; }
else if (Val == Value.Int16 )
{ v = (v << 8) | ptr[0]; localPtr += 1; i += 3; }
else if (Val == Value.Invalid) break;
offset += v;
Offsets.Add(offset << bitShift);
}
}
}
public unsafe byte[] Write(bool shiftX)
{
Offsets.Sort();
long offset = 0;
byte bitShift = (byte)(shiftX ? 3 : 2);
int max1 = 0x00100 >> bitShift;
int max2 = 0x10000 >> bitShift;
byte[] data = new byte[length(shiftX)];
fixed (byte* ptr = data)
{
byte Val = 0;
*(int*)ptr = length(shiftX);
byte* localPtr = ptr + 4;
for (int i = 0; i < Offsets.Count; i++)
{
offset = Offsets[i];
if (i > 0) { offset -= Offsets[i - 1]; if (offset == 0) continue; }
offset >>= bitShift;
Val = (byte)(offset > max2 ? Value.Int32 : offset > max1 ? Value.Int16 : Value.Int8);
if (offset < max1) *localPtr = (byte)(Val | offset );
else if (offset < max2) { *localPtr = (byte)(Val | (offset >> 8)); localPtr++;
*localPtr = (byte) offset ; }
else { *localPtr = (byte)(Val | (offset >> 24)); localPtr++;
*localPtr = (byte) (offset >> 16) ; localPtr++;
*localPtr = (byte) (offset >> 8) ; localPtr++;
*localPtr = (byte) offset ; }
localPtr++;
}
}
return data;
}
private int length(bool shiftX = false)
{
int length = 5;
long offset = 0;
byte bitShift = (byte)(shiftX ? 3 : 2);
int max1 = 0x00100 >> bitShift;
int max2 = 0x10000 >> bitShift;
for (int i = 0; i < Offsets.Count; i++)
{
offset = Offsets[i];
if (i > 0) { offset -= Offsets[i - 1]; if (offset == 0) continue; }
offset >>= bitShift;
if (offset < max1) length += 1;
else if (offset < max2) length += 2;
else length += 4;
}
return length;
}
public enum Value : byte
{
Invalid = 0b00000000,
Int8 = 0b01000000,
Int16 = 0b10000000,
Int32 = 0b11000000,
}
public override string ToString() =>
$"{(NotNull ? $"Offsets Count: {Offsets.Count}" : "No POF")}";
}
}
+48
View File
@@ -0,0 +1,48 @@
namespace KKdBaseLib.F2
{
public struct Struct
{
public Header Header;
public byte[] Data;
public Struct[] SubStructs;
public ENRS ENRS;
public POF POF;
public int Length => length(false);
public int LengthX => length( true);
public int Depth => Header.Depth;
public bool HasPOF => POF .NotNull;
public bool HasENRS => ENRS.NotNull;
public bool HasSubStructs => SubStructs != null;
public long DataOffset;
public override string ToString() => $"{Header.ToString()}" +
$"{(HasSubStructs ? $"; SubStructs: {SubStructs.Length}" : "")}" +
$"{(HasENRS ? "; Has ENRS" : "")}{(HasPOF ? "; Has POF" : "")}";
private int length(bool shiftX = false)
{
int length = Data != null ? Data.Length : 0;
if (HasPOF ) length += 0x20 + (shiftX ? POF.LengthX : POF.Length);
if (HasENRS) length += 0x20 + ENRS.Length;
if (HasSubStructs)
{
for (int i = 0; i < SubStructs.Length; i++)
length += (shiftX ? SubStructs[i].LengthX : SubStructs[i].Length) + SubStructs[i].Header.Length;
length += 0x20;
}
return length;
}
public void Update(bool ShiftX = false)
{
Header.SectionSize = Data != null ? Data.Length : 0;
Header.DataSize = length(ShiftX);
}
}
}
+19
View File
@@ -0,0 +1,19 @@
namespace KKdBaseLib
{
public enum Format : byte
{
NULL = 0,
DT = 1,
PDA = 2,
DT2 = 3,
DTe = 4,
F = 5,
AFT = 6,
F2LE = 7,
F2BE = 8,
MGF = 9,
X = 10,
XHD = 11,
FT = 12,
}
}
+88
View File
@@ -0,0 +1,88 @@
using System;
namespace KKdBaseLib
{
public struct Half : IFormattable
{
private ushort _value;
public static Half NaN => new Half { _value = 0x7FFF };
public static Half PositiveNaN => new Half { _value = 0x7FFF };
public static Half NegativeNaN => new Half { _value = 0xFFFF };
public static Half PositiveZero => new Half { _value = 0x0000 };
public static Half NegativeZero => new Half { _value = 0x8000 };
public static Half PositiveInfinity => new Half { _value = 0x7C00 };
public static Half NegativeInfinity => new Half { _value = 0xFC00 };
public static explicit operator Half(ushort bits) => new Half() { _value = bits };
public static explicit operator ushort(Half bits) => bits._value;
public static unsafe implicit operator float(Half h)
{
int sign = (h._value >> 15) & 0x001;
int exponent = ((h._value >> 10) & 0x01F) + 127 - 15;
int mantissa = h._value & 0x3FF;
int si32 = (sign << 31) | (exponent << 23) | (mantissa << 13);
return *(float*)&si32;
}
public static unsafe explicit operator Half(float val)
{
int si32 = *(int*)&val;
ushort sign = (ushort)( (si32 >> 16) & 0x8000);
short exponent = ( short)(((si32 >> 23) & 0x00FF) - 127 + 15);
ushort mantissa = (ushort)( (si32 >> 13) & 0x03FF);
if (exponent < 0) { exponent = 0; mantissa = 0; }
else if (exponent > 30) exponent = 31;
return new Half { _value = (ushort)(sign | (exponent << 10) | mantissa) };
}
public static unsafe implicit operator double(Half h)
{
int sign = (h._value >> 15) & 0x001;
int exponent = ((h._value >> 10) & 0x01F) + 1023 - 15;
int mantissa = h._value & 0x3FF;
long si64 = ((long)sign << 63) | ((long)exponent << 52) | ((long)mantissa << 42);
return *(double*)&si64;
}
public static unsafe explicit operator Half(double val)
{
long si64 = *(long*)&val;
ushort sign = (ushort) ((si64 >> 48) & 0x8000);
short exponent = ( short)(((si64 >> 52) & 0x07FF) - 1023 + 15);
ushort mantissa = (ushort) ((si64 >> 42) & 0x03FF);
if (exponent < 0) { exponent = 0; mantissa = 0; }
else if (exponent > 30) exponent = 31;
return new Half { _value = (ushort)(sign | (exponent << 10) | mantissa) };
}
public static Half operator - (Half a ) => new Half() { _value = (ushort)(a._value ^ 0x8000) };
public static Half operator + (Half a, Half b) => (Half)((float)a + (float)b);
public static Half operator - (Half a, Half b) => (Half)((float)a - (float)b);
public static Half operator * (Half a, Half b) => (Half)((float)a * (float)b);
public static Half operator / (Half a, Half b) => (Half)((float)a / (float)b);
public static bool operator > (Half a, Half b) => (float)a > (float)b;
public static bool operator < (Half a, Half b) => (float)a < (float)b;
public static bool operator >=(Half a, Half b) => (float)a >= (float)b;
public static bool operator <=(Half a, Half b) => (float)a <= (float)b;
public static bool operator ==(Half a, Half b) => (float)a == (float)b;
public static bool operator !=(Half a, Half b) => (float)a != (float)b;
public int CompareTo(object obj) => CompareTo((Half)obj);
public int CompareTo(Half h) => this == h ? 0 : (this > h ? 1 : -1);
public bool Equals(Half other) => this == other;
public override bool Equals(object obj) => base.Equals(obj);
public override string ToString() => Extensions.ToS((double)this);
public string ToString(string format, IFormatProvider formatProvider) =>
((float)this).ToString(format, formatProvider);
public override int GetHashCode() => base.GetHashCode();
}
}
+21
View File
@@ -0,0 +1,21 @@
namespace KKdBaseLib
{
public interface IKF
{
KFT0 ToT0();
KFT1 ToT1();
KFT2 ToT2();
KFT3 ToT3();
IKF Check();
string ToString();
string ToString(int round, bool brackets);
string ToString(bool brackets, int round);
}
public interface INull
{
bool IsNull { get; }
bool NotNull { get; }
}
}
+189
View File
@@ -0,0 +1,189 @@
using KKdBaseLib.Auth3D;
namespace KKdBaseLib.Interpolation
{
public struct A3DAI //A3DA Interpolation
{
private A3DAKey a3daKey;
private float f;
private float last;
private float df;
private float @if;
private float rf;
private float lastTime;
private KFT3 firstKey;
private KFT3 lastKey;
public float InterpolationFramerate { get => @if; set { @if = value; df = @if / rf; } }
public float RequestedFramerate { get => rf; set { rf = value; df = @if / rf; } }
public float Frame => f;
public float Value => last;
public bool IsNull => a3daKey.Keys == null ? true : a3daKey.Length < 1;
public bool NotNull => a3daKey.Keys == null ? false : a3daKey.Length > 0;
public A3DAI(Key key, float a3daFramerate = 60, float requestedFramerate = 60)
{
lastTime = 0;
a3daKey = (A3DAKey)key; f = -1; df = last = rf = @if = 0;
@if = a3daFramerate;
firstKey = lastKey = default;
RequestedFramerate = requestedFramerate;
f = -df;
ResetFrameCount();
if (key.Keys != null && key.Length > 0)
{
firstKey = key.Keys[0];
lastKey = key.Keys[key.Length - 1];
}
}
public A3DAI(A3DAKey key, float a3daFramerate = 60, float requestedFramerate = 60)
{
lastTime = 0;
a3daKey = key; f = -1; df = last = rf = @if = 0;
@if = a3daFramerate;
firstKey = lastKey = default;
RequestedFramerate = requestedFramerate;
f = -df;
ResetFrameCount();
if (key.Keys != null && key.Length > 0)
{
firstKey = key.Keys[0];
lastKey = key.Keys[key.Length - 1];
}
}
public float SetTime(float time)
{
if ((int)a3daKey.Type < 0 || (int)a3daKey.Type > 4) return 0.0f;
else if ((int)a3daKey.Type < 2) return a3daKey.Value;
else if (a3daKey.Length < 1) return 0.0f;
lastTime = time;
f = time * @if;
last = Interpolate(f);
return last;
}
public float SetFrame(float frame)
{
if ((int)a3daKey.Type < 0 || (int)a3daKey.Type > 4) return 0.0f;
else if ((int)a3daKey.Type < 2) return a3daKey.Value;
else if (a3daKey.Length < 1) return 0.0f;
lastTime = frame / rf;
f = frame * df;
last = Interpolate(f);
return last;
}
public float NextFrame(float time)
{
if ((int)a3daKey.Type < 0 || (int)a3daKey.Type > 4) return 0.0f;
else if ((int)a3daKey.Type < 2) return a3daKey.Value;
else if (a3daKey.Length < 1) return 0.0f;
lastTime += time;
f = lastTime * @if;
last = Interpolate(f);
return last;
}
public float NextFrame()
{
if ((int)a3daKey.Type < 0 || (int)a3daKey.Type > 4) return 0.0f;
else if ((int)a3daKey.Type < 2) return a3daKey.Value;
else if (a3daKey.Length < 1) return 0.0f;
f += df;
lastTime = f / @if;
last = Interpolate(f);
return last;
}
private float Interpolate(float frame)
{
float df = 0;
float ep = 0;
float f = (int)frame;
if (f < firstKey.F)
{
if (a3daKey.EPTypePost < EPType.EP_1 || a3daKey.EPTypePost > EPType.EP_3) return firstKey.V;
df = firstKey.F - frame;
if (a3daKey.EPTypePre == EPType.EP_1) return firstKey.V - df * firstKey.T1;
frame = lastKey.F - df % a3daKey.FrameDelta;
f = (int)frame;
if (a3daKey.EPTypePre == EPType.EP_3)
{
ep = df / a3daKey.FrameDelta;
ep = (ep > 0 && ep != (int)ep) ? (ep - (int)ep > 0 ? 1 : 0) : ep;
ep = -(ep + 1) * a3daKey.ValueDelta;
}
}
else if (f >= lastKey.F)
{
if (a3daKey.EPTypePost < EPType.EP_1 || a3daKey.EPTypePost > EPType.EP_3) return lastKey.V;
df = frame - lastKey.F;
if (a3daKey.EPTypePost == EPType.EP_1) return lastKey.V + df * lastKey.T2;
frame = firstKey.F + df % a3daKey.FrameDelta;
f = (int)frame;
if (a3daKey.EPTypePost == EPType.EP_3)
{
ep = df / a3daKey.FrameDelta;
ep = (ep > 0 && ep != (int)ep) ? (ep - (int)ep > 0 ? 1 : 0) : ep;
ep = (ep + 1) * a3daKey.ValueDelta;
}
}
if (f <= firstKey.F) return firstKey.V + ep;
else if (f >= lastKey.F) return lastKey.V + ep;
long key = 0;
long length = a3daKey.Length;
long temp;
while (length > 0)
if (f > a3daKey.Keys[key + (temp = length >> 1)].F)
{
key += temp + 1;
length -= temp + 1;
}
else length = temp;
ref KFT3 c = ref a3daKey.Keys[key - 1];
ref KFT3 n = ref a3daKey.Keys[key];
float result;
if (frame > c.F && frame < n.F)
{
if (a3daKey.Type == KeyType.Lerp)
{
float t = (frame - c.F) / (n.F - c.F);
result = (1 - t) * c.V + t * n.V;
}
else if (a3daKey.Type == KeyType.Hermite)
{
float t = (frame - c.F) / (n.F - c.F);
float t_2 = (1 - t) * (1 - t);
result = t_2 * c.V * (1 + 2 * t) + (t * n.V * (3 - 2 * t) +
(t_2 * c.T2 + t * (t - 1) * n.T1) * (n.F - c.F)) * t;
}
else result = c.V;
}
else result = frame > c.F ? n.V : c.V;
return result + ep;
}
public void ResetFrameCount() => f = -df;
public override string ToString() => $"Frame: {f}, Value: {last}";
}
}
@@ -0,0 +1,17 @@
namespace KKdBaseLib.Interpolation
{
public interface IInterpolation : INull
{
float RequestedFramerate { get; set; }
float InterpolationFramerate { get; set; }
float Frame { get; }
float Value { get; }
float SetTime (float time);
float SetFrame(float frame);
float NextFrame(float time);
float NextFrame();
void ResetFrameCount();
}
}
+118
View File
@@ -0,0 +1,118 @@
namespace KKdBaseLib.Interpolation
{
public struct PDI : IInterpolation //Project DIVA Interpolation
{
private KFT2[] array;
private float f;
private float last;
private float df;
private float @if;
private float rf;
private float lastTime;
private KFT2 firstKey;
private KFT2 lastKey;
public float InterpolationFramerate { get => @if; set { @if = value; df = @if / rf; } }
public float RequestedFramerate { get => rf; set { rf = value; df = @if / rf; } }
public float Frame => f;
public float Value => last;
public bool IsNull => array == null ? true : array.Length < 1;
public bool NotNull => array == null ? false : array.Length > 0;
public PDI(KFT2[] array, float interpolationFramerate = 60, float requestedFramerate = 60)
{
lastTime = 0;
this.array = array; f = -1; df = last = rf = @if = 0;
@if = interpolationFramerate;
firstKey = lastKey = default;
RequestedFramerate = requestedFramerate;
f = -df;
ResetFrameCount();
if (array != null && array.Length > 0)
{
firstKey = array[0];
lastKey = array[array.Length - 1];
}
}
public float SetTime(float time)
{
if (array == null || array.Length < 1) return 0;
lastTime = time;
f = time * @if;
last = Interpolate(f);
return last;
}
public float SetFrame(float frame)
{
if (array == null || array.Length < 1) return 0;
lastTime = frame / rf;
f = frame * df;
last = Interpolate(f);
return last;
}
public float NextFrame(float time)
{
if (array == null || array.Length < 1) return 0;
lastTime += time;
f = lastTime * @if;
last = Interpolate(f);
return last;
}
public float NextFrame()
{
if (array == null || array.Length < 1) return 0;
f += df;
lastTime = f / @if;
last = Interpolate(f);
return last;
}
private float Interpolate(float frame)
{
float f = (int)frame;
if (f <= firstKey.F) return firstKey.V;
else if (f >= lastKey.F) return lastKey.V;
int key = 0;
int length = array.Length;
int temp;
while (length > 0)
if (f > array[key + (temp = length >> 1)].F)
{
key += temp + 1;
length -= temp + 1;
}
else length = temp;
ref KFT2 c = ref array[key - 1];
ref KFT2 n = ref array[key];
float result;
if (frame > c.F && frame < n.F)
{
float t = (this.f - c.F) / (n.F - c.F);
float t_1 = t - 1;
result = (t_1 * 2 - 1) * (c.V - n.V) * t * t +
(t_1 * c.T + t * n.T) * t_1 * (this.f - c.F) + c.V;
}
else result = frame > c.F ? n.V : c.V;
return result;
}
public void ResetFrameCount() => f = -df;
public override string ToString() => $"Frame: {f}, Value: {last}";
}
}
+227
View File
@@ -0,0 +1,227 @@
namespace KKdBaseLib
{
public struct KFT0 : IKF
{
public float F;
public KFT0(float F = 0)
{ this.F = F; }
public KFT0 ToT0() => this;
public KFT1 ToT1() =>
new KFT1(F);
public KFT2 ToT2() =>
new KFT2(F);
public KFT3 ToT3() =>
new KFT3(F);
public IKF Check() => this;
public override string ToString() => ToString(true, 7);
public string ToString(int round = 7, bool brackets = true) =>
ToString(brackets, round);
public string ToString(bool brackets = true, int round = 7) =>
Extensions.ToS(F, round);
public static explicit operator KFT1(KFT0 KF) =>
new KFT1(KF.F);
public static explicit operator KFT2(KFT0 KF) =>
new KFT2(KF.F);
public static explicit operator KFT3(KFT0 KF) =>
new KFT3(KF.F);
public override int GetHashCode() => base.GetHashCode();
public override bool Equals(object obj)
{ if (obj is KFT0 b) return this == b; else return base.Equals(obj); }
public static bool operator > (float a, KFT0 b) => a > b.F;
public static bool operator < (float a, KFT0 b) => a < b.F;
public static bool operator >=(float a, KFT0 b) => a >= b.F;
public static bool operator <=(float a, KFT0 b) => a <= b.F;
public static bool operator > (KFT0 a, float b) => a.F > b;
public static bool operator < (KFT0 a, float b) => a.F < b;
public static bool operator >=(KFT0 a, float b) => a.F >= b;
public static bool operator <=(KFT0 a, float b) => a.F <= b;
public static bool operator > (KFT0 a, KFT0 b) => a.F > b.F;
public static bool operator < (KFT0 a, KFT0 b) => a.F < b.F;
public static bool operator >=(KFT0 a, KFT0 b) => a.F >= b.F;
public static bool operator <=(KFT0 a, KFT0 b) => a.F <= b.F;
public static bool operator ==(KFT0 a, KFT0 b) => a.F == b.F;
public static bool operator !=(KFT0 a, KFT0 b) => a.F != b.F;
}
public struct KFT1 : IKF
{
public float F;
public float V;
public KFT1(float F = 0, float V = 0)
{ this.F = F; this.V = V; }
public KFT0 ToT0() =>
new KFT0(F);
public KFT1 ToT1() => this;
public KFT2 ToT2() =>
new KFT2(F, V);
public KFT3 ToT3() =>
new KFT3(F, V);
public IKF Check() =>
V == 0 ? (KFT0)this : (IKF)this;
public override string ToString() => ToString(true, 7);
public string ToString(int round = 7, bool brackets = true) =>
ToString(brackets, round);
public string ToString(bool brackets = true, int round = 7) =>
(brackets ? "(" : "") + Extensions.ToS(F, round) + "," +
Extensions.ToS(V, round) + (brackets ? ")" : "");
public static explicit operator KFT0(KFT1 KF) =>
new KFT0(KF.F);
public static explicit operator KFT2(KFT1 KF) =>
new KFT2(KF.F, KF.V);
public static explicit operator KFT3(KFT1 KF) =>
new KFT3(KF.F, KF.V);
public override int GetHashCode() => base.GetHashCode();
public override bool Equals(object obj)
{ if (obj is KFT1 b) return this == b; else return base.Equals(obj); }
public static bool operator > (float a, KFT1 b) => a > b.F;
public static bool operator < (float a, KFT1 b) => a < b.F;
public static bool operator >=(float a, KFT1 b) => a >= b.F;
public static bool operator <=(float a, KFT1 b) => a <= b.F;
public static bool operator > (KFT1 a, float b) => a.F > b;
public static bool operator < (KFT1 a, float b) => a.F < b;
public static bool operator >=(KFT1 a, float b) => a.F >= b;
public static bool operator <=(KFT1 a, float b) => a.F <= b;
public static bool operator > (KFT1 a, KFT1 b) => a.F > b.F;
public static bool operator < (KFT1 a, KFT1 b) => a.F < b.F;
public static bool operator >=(KFT1 a, KFT1 b) => a.F >= b.F;
public static bool operator <=(KFT1 a, KFT1 b) => a.F <= b.F;
public static bool operator ==(KFT1 a, KFT1 b) => a.F == b.F && a.V == b.V;
public static bool operator !=(KFT1 a, KFT1 b) => a.F != b.F || a.V != b.V;
}
public struct KFT2 : IKF
{
public float F;
public float V;
public float T;
public KFT2(float F = 0, float V = 0, float T = 0)
{ this.F = F; this.V = V; this.T = T; }
public KFT0 ToT0() =>
new KFT0(F);
public KFT1 ToT1() =>
new KFT1(F, V);
public KFT2 ToT2() => this;
public KFT3 ToT3() =>
new KFT3(F, V, T, T);
public KFT3 ToT3(IKF Previous) =>
Previous is KFT2 PreviousT2 ?
new KFT3(F, V, PreviousT2.T, T) :
new KFT3(F, V, T, T);
public IKF Check() =>
T == 0 ? (V == 0 ? (IKF)ToT0() : ToT1()) : this;
public override string ToString() => ToString(true, 7);
public string ToString(int round = 7, bool brackets = true) =>
ToString(brackets, round);
public string ToString(bool brackets = true, int round = 7) =>
(brackets ? "(" : "") + Extensions.ToS(F, round) + "," + Extensions.
ToS(V, round) + "," + Extensions.ToS(T, round) + (brackets ? ")" : "");
public static explicit operator KFT0(KFT2 KF) =>
new KFT0(KF.F);
public static explicit operator KFT1(KFT2 KF) =>
new KFT1(KF.F, KF.V);
public static explicit operator KFT3(KFT2 KF) =>
new KFT3(KF.F, KF.V, KF.T, KF.T);
public override int GetHashCode() => base.GetHashCode();
public override bool Equals(object obj)
{ if (obj is KFT2 b) return this == b; else return base.Equals(obj); }
public static bool operator > (float a, KFT2 b) => a > b.F;
public static bool operator < (float a, KFT2 b) => a < b.F;
public static bool operator >=(float a, KFT2 b) => a >= b.F;
public static bool operator <=(float a, KFT2 b) => a <= b.F;
public static bool operator > (KFT2 a, float b) => a.F > b;
public static bool operator < (KFT2 a, float b) => a.F < b;
public static bool operator >=(KFT2 a, float b) => a.F >= b;
public static bool operator <=(KFT2 a, float b) => a.F <= b;
public static bool operator > (KFT2 a, KFT2 b) => a.F > b.F;
public static bool operator < (KFT2 a, KFT2 b) => a.F < b.F;
public static bool operator >=(KFT2 a, KFT2 b) => a.F >= b.F;
public static bool operator <=(KFT2 a, KFT2 b) => a.F <= b.F;
public static bool operator ==(KFT2 a, KFT2 b) => a.F == b.F && a.V == b.V && a.T == b.T;
public static bool operator !=(KFT2 a, KFT2 b) => a.F != b.F || a.V != b.V || a.T != b.T;
}
public struct KFT3 : IKF
{
public float F;
public float V;
public float T1;
public float T2;
public KFT3(float F = 0, float V = 0, float T1 = 0, float T2 = 0)
{ this.F = F; this.V = V; this.T1 = T1; this.T2 = T2; }
public KFT0 ToT0() =>
new KFT0(F);
public KFT1 ToT1() =>
new KFT1(F, V);
public KFT2 ToT2() =>
new KFT2(F, V, T1);
public KFT3 ToT3() => this;
public IKF Check() =>
T1 == 0 && T2 == 0 ? (V == 0 ? (IKF)(KFT0)this : (KFT1)this) : T1 == T2 ? (KFT2)this : (IKF)this;
public override string ToString() => ToString(true, 7);
public string ToString(int round = 7, bool brackets = true) =>
ToString(brackets, round);
public string ToString(bool brackets = true, int round = 7) =>
(brackets ? "(" : "") + Extensions.ToS(F, round) + "," + Extensions.ToS(V, round) + "," +
Extensions.ToS(T1, round) + "," + Extensions.ToS(T2, round) + (brackets ? ")" : "");
public static explicit operator KFT0(KFT3 KF) =>
new KFT0(KF.F);
public static explicit operator KFT1(KFT3 KF) =>
new KFT1(KF.F, KF.V);
public static explicit operator KFT2(KFT3 KF) =>
new KFT2(KF.F, KF.V, KF.T1);
public override int GetHashCode() => base.GetHashCode();
public override bool Equals(object obj)
{ if (obj is KFT3 b) return this == b; else return base.Equals(obj); }
public static bool operator > (float a, KFT3 b) => a > b.F;
public static bool operator < (float a, KFT3 b) => a < b.F;
public static bool operator >=(float a, KFT3 b) => a >= b.F;
public static bool operator <=(float a, KFT3 b) => a <= b.F;
public static bool operator > (KFT3 a, float b) => a.F > b;
public static bool operator < (KFT3 a, float b) => a.F < b;
public static bool operator >=(KFT3 a, float b) => a.F >= b;
public static bool operator <=(KFT3 a, float b) => a.F <= b;
public static bool operator > (KFT3 a, KFT3 b) => a.F > b.F;
public static bool operator < (KFT3 a, KFT3 b) => a.F < b.F;
public static bool operator >=(KFT3 a, KFT3 b) => a.F >= b.F;
public static bool operator <=(KFT3 a, KFT3 b) => a.F <= b.F;
public static bool operator ==(KFT3 a, KFT3 b) => a.F == b.F && a.V == b.V && a.T1 == b.T1 && a.T2 == b.T2;
public static bool operator !=(KFT3 a, KFT3 b) => a.F != b.F || a.V != b.V || a.T1 != b.T1 || a.T2 != b.T2;
public IKF ToT2(IKF Previous, out IKF Current)
{
Current = Previous is KFT2 PreviousT2
? new KFT2(PreviousT2.F, PreviousT2.V, T1)
: new KFT2(F, V, T1);
return new KFT2(F, V, T2);
}
}
}
+42
View File
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Authors>korenkonder</Authors>
<Company></Company>
<Configuration></Configuration>
<Copyright>korenkonder © 2019-2020</Copyright>
<Description>A base library</Description>
<FileVersion>0.4.9.0</FileVersion>
<PackageId>KKdBaseLib</PackageId>
<Product>KKdBaseLib</Product>
<TargetFramework>netstandard2.0</TargetFramework>
<Title>KKdBaseLib</Title>
<Version>0.4.9.0</Version>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>embedded</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
</Project>
+222
View File
@@ -0,0 +1,222 @@
namespace KKdBaseLib
{
public struct KKdDict<TKey, TValue> : System.IDisposable, System.Collections.IEnumerator, INull
{
public static KKdDict<TKey, TValue> Null => new KKdDict<TKey, TValue>();
public static KKdDict<TKey, TValue> New => new KKdDict<TKey, TValue>() { count = 0, Capacity = 0 };
public static KKdDict<TKey, TValue> NewReserve(int Capacity) =>
new KKdDict<TKey, TValue>() { count = 0, Capacity = Capacity };
private int count;
private int index;
private TKey [] keyArray;
private TValue[] valArray;
public int Count => count;
public bool IsNull => keyArray == null || valArray == null;
public bool NotNull => keyArray != null && valArray != null;
public int Capacity { get => keyArray != null && valArray != null ? valArray.Length : -1;
set { if (keyArray != null) System.Array.Resize(ref keyArray, value); else keyArray = new TKey [value];
if (valArray != null) System.Array.Resize(ref valArray, value); else valArray = new TValue[value];
if (count >= value) count = value; } }
public KKdDict(TKey[] keyArray, TValue[] valArray)
{
this.keyArray = null; this.valArray = null; count = 0; index = 0;
if (keyArray == null || valArray == null || keyArray.Length != valArray.Length) return;
count = valArray.Length; this.keyArray = keyArray; this.valArray = valArray; }
public KeyValuePair<TKey, TValue> Current => index < count ?
new KeyValuePair<TKey, TValue>(keyArray[index], valArray[index]) : default;
object System.Collections.IEnumerator.Current => Current;
public TKey [] Keys => keyArray;
public TValue[] Values => valArray;
public KeyValuePair<TKey, TValue> this[ int index, bool list]
{ get => keyArray != null && valArray != null && index > -1 && index < keyArray.Length &&
index < valArray.Length ? new KeyValuePair<TKey, TValue>(keyArray[index], valArray[index]) : default;
set { if (keyArray != null && valArray != null && index > -1 && index < keyArray.Length &&
index < valArray.Length) { keyArray[index] = value.Key; valArray[index] = value.Value; } } }
public KeyValuePair<TKey, TValue> this[uint index, bool list]
{ get => keyArray != null && valArray != null && index < keyArray.Length &&
index < valArray.Length ? new KeyValuePair<TKey, TValue>(keyArray[index], valArray[index]) : default;
set { if (keyArray != null && valArray != null && index < keyArray.Length &&
index < valArray.Length) { keyArray[index] = value.Key; valArray[index] = value.Value; } } }
public TValue this[TKey key]
{ get => valArray != null && valArray.Length > 0 && CK(key, out int index) ? valArray[index] : default;
set { if (valArray != null && valArray.Length > 0) if (CK(key, out int index)) valArray[index] = value; else Add(key, value); } }
public bool MoveNext()
{ if (index == count - 1) { index = 0; return false; }
else { index++ ; return true; } }
public System.Collections.IEnumerator GetEnumerator() => this;
public void Dispose() { keyArray = null; valArray = null; count = 0; index = 0; }
public void Reset() => index = 0;
public void Add(KeyValuePair<TKey, TValue> pair)
{
if (IsNull) return;
count++;
if (keyArray.Length < count) System.Array.Resize(ref keyArray, count);
if (valArray.Length < count) System.Array.Resize(ref valArray, count);
keyArray[count - 1] = pair.Key;
valArray[count - 1] = pair.Value;
}
public void Add(TKey key, TValue val)
{
if (IsNull) return;
count++;
if (keyArray.Length < count) System.Array.Resize(ref keyArray, count);
if (valArray.Length < count) System.Array.Resize(ref valArray, count);
keyArray[count - 1] = key;
valArray[count - 1] = val;
}
public bool RemoveKey(TKey key)
{
if (IsNull) return false;
int index = IndexOf(key);
if (index == -1) return false;
if (index + 1 < count)
{ System.Array.Copy(keyArray, index + 1, keyArray, index, count - index);
System.Array.Copy(valArray, index + 1, valArray, index, count - index); }
count--;
return true;
}
public bool RemoveValue(TValue val)
{
if (IsNull) return false;
int index = IndexOf(val);
if (index == -1) return false;
if (index + 1 < count)
{ System.Array.Copy(keyArray, index + 1, keyArray, index, count - index);
System.Array.Copy(valArray, index + 1, valArray, index, count - index); }
count--;
return true;
}
public void RemoveAt(int index)
{
if (IsNull || index < 0 || index >= count) return;
if (index + 1 < count)
{ System.Array.Copy(keyArray, index + 1, keyArray, index, count - index);
System.Array.Copy(valArray, index + 1, valArray, index, count - index); }
count--;
}
public void RemoveRange(int indexStart, int indexEnd)
{
int indexcount = indexEnd - indexStart;
if (IsNull || indexcount < 1 || indexStart < 0 || indexEnd > count) return;
if ((indexEnd + indexcount) < count)
{ System.Array.Copy(keyArray, indexEnd, keyArray, indexStart, indexcount);
System.Array.Copy(valArray, indexEnd, valArray, indexStart, indexcount); }
count -= indexcount;
}
public TValue[] ToArray() => valArray;
public bool ContainsKey (TKey key) => CK(key, out int index);
public bool ContainsValue(TValue val) => CV(val, out int index);
public bool Contains (KeyValuePair<TKey, TValue> pair) => C(pair, out int index);
public bool ContainsKey (TKey key, out int index) => CK(key, out index);
public bool ContainsValue(TValue val, out int index) => CV(val, out index);
public bool Contains (KeyValuePair<TKey, TValue> pair, out int index) => C(pair, out index);
private bool CK(TKey key, out int index)
{
index = -1;
if (IsNull) return false;
for (int i = 0; i < count; i++)
if (keyArray[i] == null && key == null) { index = i; return true; }
else if (keyArray[i] == null || key == null) continue;
else if (keyArray[i].Equals(key)) { index = i; return true; }
return false;
}
private bool CV(TValue val, out int index)
{
index = -1;
if (IsNull) return false;
for (int i = 0; i < count; i++)
if (valArray[i] == null && val == null) { index = i; return true; }
else if (valArray[i] == null || val == null) continue;
else if (valArray[i].Equals(val)) { index = i; return true; }
return false;
}
private bool C(KeyValuePair<TKey, TValue> pair, out int index)
{
index = -1;
if (IsNull) return false;
for (int i = 0; i < count; i++)
if (keyArray[i] == null && pair.Key == null &&
valArray[i] == null && pair.Value == null) { index = i; return true; }
else if ((keyArray[i] == null || pair.Key == null) &&
(valArray[i] == null || pair.Value == null)) continue;
else if (keyArray[i].Equals(pair.Key ) &&
valArray[i].Equals(pair.Value)) { index = i; return true; }
return false;
}
public TKey GetKey(TValue val)
{
if (IsNull) return default;
for (int i = 0; i < count; i++)
if (keyArray[i] == null && val == null) return keyArray[i];
else if (keyArray[i] == null || val == null) continue;
else if (keyArray[i].Equals(val)) return keyArray[i];
return default;
}
private int IndexOf(TKey key)
{
if (IsNull) return -1;
for (int i = 0; i < count; i++)
if (keyArray[i] == null && key == null) return i;
else if (keyArray[i] == null || key == null) continue;
else if (keyArray[i].Equals(key)) return i;
return -1;
}
private int IndexOf(TValue val)
{
if (IsNull) return -1;
for (int i = 0; i < count; i++)
if (valArray[i] == null && val == null) return i;
else if (valArray[i] == null || val == null) continue;
else if (valArray[i].Equals(val)) return i;
return -1;
}
}
public struct KeyValuePair<TKey, TValue>
{
public TKey Key;
public TValue Value;
public KeyValuePair(TKey key, TValue value)
{ Key = key; Value = value; }
}
}
+144
View File
@@ -0,0 +1,144 @@
using System.Collections;
using System.Collections.Generic;
namespace KKdBaseLib
{
public struct KKdList<T> : System.IDisposable, IEnumerable<T>, IEnumerable, IEnumerator, INull
{
public static KKdList<T> Null => new KKdList<T>();
public static KKdList<T> New => new KKdList<T>() { count = 0, Capacity = 0 };
public static KKdList<T> NewReserve(int Capacity) => new KKdList<T>() { count = 0, Capacity = Capacity };
private int count;
private int index;
private T[] array;
private Enumerator enumerator;
public int Count => count;
public bool IsNull => array == null;
public bool NotNull => array != null;
public int Capacity { get => array != null ? array.Length : -1;
set { if (array != null) System.Array.Resize(ref array, value); else array = new T[value];
if (Count >= value) count = value; } }
public KKdList(T[] array)
{ index = -1; count = array.Length; this.array = array; enumerator = new Enumerator(this.array); }
public T Current => index > -1 && index < Count ? array[index] : default;
object IEnumerator.Current => enumerator.Current;
public bool MoveNext() => enumerator.MoveNext();
public void Reset() => enumerator.Reset();
public T this[ int index]
{ get => array != null && index > -1 && index < array.Length ? array[index] : default;
set { if (array != null && index > -1 && index < array.Length) array[index] = value; } }
public T this[uint index]
{ get => array != null && index < array.Length ? array[index] : default;
set { if (array != null && index < array.Length) array[index] = value; } }
public IEnumerator GetEnumerator() => enumerator = new Enumerator(array);
IEnumerator<T> IEnumerable<T>.GetEnumerator() => enumerator = new Enumerator(array);
IEnumerator IEnumerable.GetEnumerator() => enumerator = new Enumerator(array);
public void Dispose() { array = null; count = 0; index = -1; }
public void Add(T item)
{
if (IsNull) return;
count++;
if (array.Length < count)
System.Array.Resize(ref array, count);
array[count - 1] = item;
}
public void RemoveAt(int index)
{
if (IsNull || index < 0 || index >= count) return;
if (index + 1 < count)
System.Array.Copy(array, index + 1, array, index, count - index);
count--;
}
public void RemoveRange(int indexStart, int indexEnd)
{
int indexCount = indexEnd - indexStart;
if (IsNull || indexCount < 1 || indexStart < 0 || indexEnd > count) return;
if ((indexEnd + indexCount) < count)
System.Array.Copy(array, indexEnd, array, indexStart, indexCount);
count -= indexCount;
}
public T[] ToArray() => array;
public bool Contains(T val)
{
if (IsNull) return false;
for (int i = 0; i < count; i++)
if (array[i] == null && val == null) return true;
else if (array[i] == null || val == null) continue;
else if (array[i].Equals(val)) return true;
return false;
}
public int IndexOf(T val)
{
if (IsNull) return -1;
for (int i = 0; i < count; i++)
if (array[i] == null && val == null) return i;
else if (array[i] == null || val == null) continue;
else if (array[i].Equals(val)) return i;
return -1;
}
public void Sort()
{ List<T> List = (List<T>)this; List.Sort(); array = List.ToArray(); count = List.Count; }
public static explicit operator KKdList<T>( List<T> list) =>
new KKdList<T> { array = list.ToArray(), count = list.Count };
public static explicit operator List<T>(KKdList<T> list)
{ List<T> outList = new List<T>(); for (int i = 0; i < list.Count; i++) outList.Add(list[i]); return outList; }
public struct Enumerator : IEnumerator<T>, IEnumerator
{
private T[] array;
private int index;
private int count;
private T current;
internal Enumerator(T[] array)
{ this.array = array; count = index = 0; current = default;
if (array != null && array.Length > 0) { current = array[0]; count = array.Length; } }
public void Dispose()
{ array = null; count = index = 0; current = default; }
public bool MoveNext()
{
if (index < count) { current = array[index]; index++; return true; }
else { current = default; index = count + 1; return false; }
}
public T Current => current;
object IEnumerator.Current =>
(index == 0 || index == array.Length + 1) ? default : current;
void IEnumerator.Reset() => Reset();
public void Reset() { index = 0; current = default; }
}
}
}
+383
View File
@@ -0,0 +1,383 @@
using System;
namespace KKdBaseLib
{
public struct MsgPack : IDisposable, IEquatable<MsgPack>, INull
{
public string Name;
public object Object;
public MsgPack[] Array => Object is MsgPack[] Array ? Array : null;
public KKdList<MsgPack> List => Object is KKdList<MsgPack> List ? List : default;
public static MsgPack New => new MsgPack { Object = KKdList<MsgPack>.New };
public static MsgPack NewReserve(int capacity) =>
new MsgPack { Object = KKdList<MsgPack>.NewReserve(capacity) };
public bool IsNull => Array == null && List. IsNull;
public bool NotNull => Array != null || List.NotNull;
public MsgPack( string name = null)
{ Object = KKdList<MsgPack>.New; Name = name; }
public MsgPack(long count, string name = null)
{ Object = count > -1 ? new MsgPack[count] : null; this.Name = name; }
public MsgPack(string name, object @object)
{ Name = name; Object = @object; }
public static MsgPack Null => new MsgPack();
public MsgPack this[ int index]
{ get => Object is MsgPack[] Array ? Array[index] : default;
set { if (Object is MsgPack[] Array) { Array[index] = value; Object = Array; } } }
public MsgPack this[uint index]
{ get => Object is MsgPack[] Array ? Array[index] : default;
set { if (Object is MsgPack[] Array) { Array[index] = value; Object = Array; } } }
public MsgPack this[string key]
{ get => Object is KKdList<MsgPack> List ? List[ElementIndex(key)] : default;
set { if (Object is KKdList<MsgPack> List && value.Object != null)
{ List.Add(value); Object = List; } } }
public MsgPack this[string key, bool array]
{ get { if (!array) return this[key];
if (Object is KKdList<MsgPack> List) { MsgPack MsgPack = List[ElementIndex(key)];
return MsgPack.Object is MsgPack[] ? MsgPack : default; } return default; } }
public MsgPack Add(MsgPack obj)
{ if (Object is KKdList<MsgPack> List && obj.Object != null) { List.Add(obj); Object = List; } return this; }
public void Dispose()
{ Name = null; Object = null; }
public bool Equals(MsgPack msg) =>
Name == msg.Name && Object == msg.Object;
public override string ToString() => Name ?? "" + (Object != null ?
(List. NotNull ? $"{(Name != null ? " " : "")}Elements Count: {List .Count }" :
(Array != null ? $"{(Name != null ? " " : "")}Elements Count: {Array.Length}" : Object)) : "");
public static implicit operator MsgPack(byte[] val) => new MsgPack(null, val);
public static implicit operator MsgPack(string val) => new MsgPack(null, val);
public static implicit operator MsgPack( sbyte val) => new MsgPack(null, val);
public static implicit operator MsgPack( byte val) => new MsgPack(null, val);
public static implicit operator MsgPack( short val) => new MsgPack(null, val);
public static implicit operator MsgPack(ushort val) => new MsgPack(null, val);
public static implicit operator MsgPack( int val) => new MsgPack(null, val);
public static implicit operator MsgPack( uint val) => new MsgPack(null, val);
public static implicit operator MsgPack( long val) => new MsgPack(null, val);
public static implicit operator MsgPack( ulong val) => new MsgPack(null, val);
public static implicit operator MsgPack( float val) => new MsgPack(null, val);
public static implicit operator MsgPack(double val) => new MsgPack(null, val);
public MsgPack Add( bool? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( sbyte? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( byte? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( short? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add(ushort? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( int? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( uint? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( long? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( ulong? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( float? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add(double? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add(byte[] val) => Add(new MsgPack(null, val));
public MsgPack Add(string val) => Add(new MsgPack(null, val));
public MsgPack Add( bool val) => Add(new MsgPack(null, val));
public MsgPack Add( sbyte val) => Add(new MsgPack(null, val));
public MsgPack Add( byte val) => Add(new MsgPack(null, val));
public MsgPack Add( short val) => Add(new MsgPack(null, val));
public MsgPack Add(ushort val) => Add(new MsgPack(null, val));
public MsgPack Add( int val) => Add(new MsgPack(null, val));
public MsgPack Add( uint val) => Add(new MsgPack(null, val));
public MsgPack Add( long val) => Add(new MsgPack(null, val));
public MsgPack Add( ulong val) => Add(new MsgPack(null, val));
public MsgPack Add( float val) => Add(new MsgPack(null, val));
public MsgPack Add(double val) => Add(new MsgPack(null, val));
public MsgPack Add(string Name, bool? val) => val.HasValue ? Add(Name, val.Value) : this;
public MsgPack Add(string Name, sbyte? val) => val.HasValue ? Add(Name, val.Value) : this;
public MsgPack Add(string Name, byte? val) => val.HasValue ? Add(Name, val.Value) : this;
public MsgPack Add(string Name, short? val) => val.HasValue ? Add(Name, val.Value) : this;
public MsgPack Add(string Name, ushort? val) => val.HasValue ? Add(Name, val.Value) : this;
public MsgPack Add(string Name, int? val) => val.HasValue ? Add(Name, val.Value) : this;
public MsgPack Add(string Name, uint? val) => val.HasValue ? Add(Name, val.Value) : this;
public MsgPack Add(string Name, long? val) => val.HasValue ? Add(Name, val.Value) : this;
public MsgPack Add(string Name, ulong? val) => val.HasValue ? Add(Name, val.Value) : this;
public MsgPack Add(string Name, float? val) => val.HasValue ? Add(Name, val.Value) : this;
public MsgPack Add(string Name, double? val) => val.HasValue ? Add(Name, val.Value) : this;
public MsgPack Add(string Name, byte[] val) => Add(new MsgPack(Name, val));
public MsgPack Add(string Name, string val) => Add(new MsgPack(Name, val));
public MsgPack Add(string Name, bool val) => Add(new MsgPack(Name, val));
public MsgPack Add(string Name, sbyte val) => Add(new MsgPack(Name, val));
public MsgPack Add(string Name, byte val) => Add(new MsgPack(Name, val));
public MsgPack Add(string Name, short val) => Add(new MsgPack(Name, val));
public MsgPack Add(string Name, ushort val) => Add(new MsgPack(Name, val));
public MsgPack Add(string Name, int val) => Add(new MsgPack(Name, val));
public MsgPack Add(string Name, uint val) => Add(new MsgPack(Name, val));
public MsgPack Add(string Name, long val) => Add(new MsgPack(Name, val));
public MsgPack Add(string Name, ulong val) => Add(new MsgPack(Name, val));
public MsgPack Add(string Name, float val) => Add(new MsgPack(Name, val));
public MsgPack Add(string Name, double val) => Add(new MsgPack(Name, val));
public bool RB (string name) => RnB (name) ?? default;
public sbyte RI8 (string name) => RnI8 (name) ?? default;
public byte RU8 (string name) => RnU8 (name) ?? default;
public short RI16(string name) => RnI16(name) ?? default;
public ushort RU16(string name) => RnU16(name) ?? default;
public int RI32(string name) => RnI32(name) ?? default;
public uint RU32(string name) => RnU32(name) ?? default;
public long RI64(string name) => RnI64(name) ?? default;
public ulong RU64(string name) => RnU64(name) ?? default;
public float RF32(string name) => RnF32(name) ?? default;
public double RF64(string name) => RnF64(name) ?? default;
public void R(string name, out bool? val) { val = RnB (name); }
public void R(string name, out sbyte? val) { val = RnI8 (name); }
public void R(string name, out byte? val) { val = RnU8 (name); }
public void R(string name, out short? val) { val = RnI16(name); }
public void R(string name, out ushort? val) { val = RnU16(name); }
public void R(string name, out int? val) { val = RnI32(name); }
public void R(string name, out uint? val) { val = RnU32(name); }
public void R(string name, out long? val) { val = RnI64(name); }
public void R(string name, out ulong? val) { val = RnU64(name); }
public void R(string name, out float? val) { val = RnF32(name); }
public void R(string name, out double? val) { val = RnF64(name); }
public void R(string name, out bool val) { val = RB (name); }
public void R(string name, out sbyte val) { val = RI8 (name); }
public void R(string name, out byte val) { val = RU8 (name); }
public void R(string name, out short val) { val = RI16(name); }
public void R(string name, out ushort val) { val = RU16(name); }
public void R(string name, out int val) { val = RI32(name); }
public void R(string name, out uint val) { val = RU32(name); }
public void R(string name, out long val) { val = RI64(name); }
public void R(string name, out ulong val) { val = RU64(name); }
public void R(string name, out float val) { val = RF32(name); }
public void R(string name, out double val) { val = RF64(name); }
public void R(string name, out string val) { val = RS (name); }
public bool? RnB (string name)
{
MsgPack MsgPack = this[name];
if (MsgPack.Object is bool B ) return B ; return null;
}
public sbyte? RnI8 (string name)
{
MsgPack MsgPack = this[name];
if (MsgPack.Object is sbyte I8 ) return I8 ;
else if (MsgPack.Object is byte U8 ) return ( sbyte)U8 ; return null;
}
public byte? RnU8 (string name)
{
MsgPack MsgPack = this[name];
if (MsgPack.Object is sbyte I8 ) return ( byte)I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ; return null;
}
public short? RnI16(string name)
{
MsgPack MsgPack = this[name];
if (MsgPack.Object is sbyte I8 ) return I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return I16;
else if (MsgPack.Object is ushort U16) return ( short)U16; return null;
}
public ushort? RnU16(string name)
{
MsgPack MsgPack = this[name];
if (MsgPack.Object is sbyte I8 ) return (ushort)I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return (ushort)I16;
else if (MsgPack.Object is ushort U16) return U16; return null;
}
public int? RnI32(string name)
{
MsgPack MsgPack = this[name];
if (MsgPack.Object is sbyte I8 ) return I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return I16;
else if (MsgPack.Object is ushort U16) return U16;
else if (MsgPack.Object is int I32) return I32;
else if (MsgPack.Object is uint U32) return ( int)U32; return null;
}
public uint? RnU32(string name)
{
MsgPack MsgPack = this[name];
if (MsgPack.Object is sbyte I8 ) return ( uint)I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return ( uint)I16;
else if (MsgPack.Object is ushort U16) return U16;
else if (MsgPack.Object is int I32) return ( uint)I32;
else if (MsgPack.Object is uint U32) return U32; return null;
}
public long? RnI64(string name)
{
MsgPack MsgPack = this[name];
if (MsgPack.Object is sbyte I8 ) return I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return I16;
else if (MsgPack.Object is ushort U16) return U16;
else if (MsgPack.Object is int I32) return I32;
else if (MsgPack.Object is uint U32) return U32;
else if (MsgPack.Object is long I64) return I64;
else if (MsgPack.Object is ulong U64) return ( long)U64; return null;
}
public ulong? RnU64(string name)
{
MsgPack MsgPack = this[name];
if (MsgPack.Object is sbyte I8 ) return ( ulong)I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return ( ulong)I16;
else if (MsgPack.Object is ushort U16) return U16;
else if (MsgPack.Object is int I32) return ( ulong)I32;
else if (MsgPack.Object is uint U32) return U32;
else if (MsgPack.Object is long I64) return ( ulong)I64; return null;
}
public float? RnF32(string name)
{
MsgPack MsgPack = this[name];
if (MsgPack.Object is sbyte I8 ) return I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return I16;
else if (MsgPack.Object is ushort U16) return U16;
else if (MsgPack.Object is int I32) return I32;
else if (MsgPack.Object is uint U32) return U32;
else if (MsgPack.Object is long I64) return I64;
else if (MsgPack.Object is float F32) return F32;
else if (MsgPack.Object is double F64) return ( float)F64; return null;
}
public double? RnF64(string name)
{
MsgPack MsgPack = this[name];
if (MsgPack.Object is sbyte I8 ) return I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return I16;
else if (MsgPack.Object is ushort U16) return U16;
else if (MsgPack.Object is int I32) return I32;
else if (MsgPack.Object is uint U32) return U32;
else if (MsgPack.Object is long I64) return I64;
else if (MsgPack.Object is float F32) return F32;
else if (MsgPack.Object is double F64) return F64; return null;
}
public string RS(string name)
{
MsgPack MsgPack = this[name];
if (MsgPack.Object is string S ) return S ; return null;
}
public bool RB () => RnB () ?? default;
public sbyte RI8 () => RnI8 () ?? default;
public byte RU8 () => RnU8 () ?? default;
public short RI16() => RnI16() ?? default;
public ushort RU16() => RnU16() ?? default;
public int RI32() => RnI32() ?? default;
public uint RU32() => RnU32() ?? default;
public long RI64() => RnI64() ?? default;
public ulong RU64() => RnU64() ?? default;
public float RF32() => RnF32() ?? default;
public double RF64() => RnF64() ?? default;
public bool? RnB ()
{ if (Object is bool B ) return B ; return null; }
public sbyte? RnI8 ()
{ if (Object is sbyte I8 ) return I8 ;
else if (Object is byte U8 ) return ( sbyte)U8 ; return null; }
public byte? RnU8 ()
{ if (Object is sbyte I8 ) return ( byte)I8 ;
else if (Object is byte U8 ) return U8 ; return null; }
public short? RnI16()
{ if (Object is sbyte I8 ) return I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return I16;
else if (Object is ushort U16) return ( short)U16; return null; }
public ushort? RnU16()
{ if (Object is sbyte I8 ) return (ushort)I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return (ushort)I16;
else if (Object is ushort U16) return U16; return null; }
public int? RnI32()
{ if (Object is sbyte I8 ) return I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return I16;
else if (Object is ushort U16) return U16;
else if (Object is int I32) return I32;
else if (Object is uint U32) return ( int)U32; return null; }
public uint? RnU32()
{ if (Object is sbyte I8 ) return ( uint)I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return ( uint)I16;
else if (Object is ushort U16) return U16;
else if (Object is int I32) return ( uint)I32;
else if (Object is uint U32) return U32; return null; }
public long? RnI64()
{ if (Object is sbyte I8 ) return I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return I16;
else if (Object is ushort U16) return U16;
else if (Object is int I32) return I32;
else if (Object is uint U32) return U32;
else if (Object is long I64) return I64;
else if (Object is ulong U64) return ( long)U64; return null; }
public ulong? RnU64()
{ if (Object is sbyte I8 ) return ( ulong)I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return ( ulong)I16;
else if (Object is ushort U16) return U16;
else if (Object is int I32) return ( ulong)I32;
else if (Object is uint U32) return U32;
else if (Object is long I64) return ( ulong)I64; return null; }
public float? RnF32()
{ if (Object is sbyte I8 ) return I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return I16;
else if (Object is ushort U16) return U16;
else if (Object is int I32) return I32;
else if (Object is uint U32) return U32;
else if (Object is long I64) return I64;
else if (Object is float F32) return F32;
else if (Object is double F64) return ( float)F64; return null; }
public double? RnF64()
{ if (Object is sbyte I8 ) return I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return I16;
else if (Object is ushort U16) return U16;
else if (Object is int I32) return I32;
else if (Object is uint U32) return U32;
else if (Object is long I64) return I64;
else if (Object is float F32) return F32;
else if (Object is double F64) return F64; return null; }
public string RS ()
{ if (Object is string S ) return S ; return null; }
public MsgPack Element(string name)
{
if (List.IsNull) return default;
for (int i = 0; i < List.Count; i++)
if (List[i].Name == name) return List[i];
return default;
}
public bool ContainsKey(string name) => ElementIndex(name) > -1;
public int ElementIndex(string name)
{
if (List.IsNull) return -1;
for (int i = 0; i < List.Count; i++)
if (List[i].Name == name) return i;
return -1;
}
public struct Ext
{
public sbyte Type;
public byte[] Data;
}
}
}
+59
View File
@@ -0,0 +1,59 @@
namespace KKdBaseLib
{
public struct Pointer<T>
{
public int O;
public T V;
public override string ToString() => Extensions.ToS(V);
public Pointer(T value)
{ O = 0; V = value; }
public Pointer(int offset, T value)
{ O = offset; V = value; }
}
public struct PointerI64<T>
{
public long O;
public T V;
public override string ToString() => Extensions.ToS(V);
public PointerI64(T value)
{ O = 0; V = value; }
public PointerI64(long offset, T value)
{ O = offset; V = value; }
}
public struct PointerU64<T>
{
public ulong O;
public T V;
public override string ToString() => Extensions.ToS(V);
public PointerU64(T value)
{ O = 0; V = value; }
public PointerU64(ulong offset, T value)
{ O = offset; V = value; }
}
public struct CountPointer<T>
{
public int C { get => E != null ? E.Length : 0;
set => E = value > -1 ? new T [value] : null; }
public int O;
public T[] E;
public T this[int index]
{ get => E != null && index > -1 && index < E.LongLength ? E[index] : default;
set { if (E != null && index > -1 && index < E.LongLength) E[index] = value; } }
public override string ToString() => C < 1 ? "No Entries" :
C == 1 ? E[0].ToString() : "Count: " + C;
}
}
+7
View File
@@ -0,0 +1,7 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("437F63F1-8C23-429E-AB14-38B85C9EDB16")]
+195
View File
@@ -0,0 +1,195 @@
namespace KKdBaseLib
{
public struct ButtonSE
{
public TableDate Start;
public TableDate End;
public int ID;
public int SortIndex;
public string Name;
public string SEName;
}
public struct ChainSlideSE
{
public TableDate Start;
public TableDate End;
public int ID;
public int SortIndex;
public string Name;
public string FirstSEName;
public string FailureSEName;
public string SubSEName;
public string SuccessSEName;
}
public struct CollectionCard
{
public TableDate Start;
public TableDate End;
public int DispNum;
public int ID;
public int NG;
public int SortIndex;
public int TypeParam;
public string Chara;
public string DivaProParam;
public string ModuleAuthor;
public string Name;
public string NameReading;
public string Type;
public string WallParam;
}
public struct CustomizeItem
{
public TableDate ShopStart;
public TableDate ShopEnd;
public int ID;
public int ObjID;
public int NG;
public int SellType;
public int ShopPrice;
public int SortIndex;
public string Chara;
public string Name;
public string Parts;
}
public struct Module
{
public TableDate ShopStart;
public TableDate ShopEnd;
public int Attribute;
public int ID;
public int NG;
public int ShopPrice;
public int SortIndex;
public string Chara;
public string Costume;
public string Name;
}
public struct Plate
{
public int Alpha;
public int BaseID;
public int Border;
public int ColorB;
public int ColorG;
public int ColorR;
public int ID;
public int Shadow;
public int ShadowAlpha;
public int ShadowColorB;
public int ShadowColorG;
public int ShadowColorR;
public string Font;
}
public struct PV
{
public TableDate AdvStart;
public TableDate AdvEnd;
public int ID;
public int Ignore;
public string Name;
public Difficulty[] Easy;
public Difficulty[] Encore;
public Difficulty[] Extreme;
public Difficulty[] Normal;
public Difficulty[] Hard;
public struct Difficulty
{
public TableDate Start;
public TableDate End;
public int Edition;
public int Version;
}
}
public struct SlideSE
{
public TableDate Start;
public TableDate End;
public int ID;
public int SortIndex;
public string Name;
public string SEName;
}
public struct SliderTouchSE
{
public TableDate Start;
public TableDate End;
public int ID;
public int SortIndex;
public string Name;
public string SEName;
}
public struct TableDate : INull
{
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 IsNull => Year == -1 || Month == -1 || Day != -1;
public bool NotNull => Year != -1 && Month != -1 && Day != -1;
public bool WU => Year != 2029 || Month != 1 || Day != 1;
public bool WL => Year != 2000 || Month != 1 || Day != 1;
public void SN () => Year = -1;
public void SDL() => Year = 2000;
public void SDU() => Year = 2029;
public void SV(int? ymd, bool setDefaultUpper)
{
if (!setDefaultUpper) SDL();
else SDU();
if (ymd != null)
{
year = ymd.Value / 10000;
month = ymd.Value / 100 % 100;
day = ymd.Value % 100;
CheckDate();
}
}
public int Int => NotNull ? (Year * 100 + Month) * 100 + Day : -1;
private void CheckDate()
{
if (year == -1 || month == -1 || day == -1) { year = -1; month = -1; day = -1; return; }
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")}";
}
}
+3 -1
View File
@@ -1,9 +1,11 @@
using System.Text;
namespace KKdMainLib
namespace KKdBaseLib
{
public static class Text
{
public readonly static Encoding ShiftJIS = Encoding.GetEncoding(932);
public static string ToASCII(this byte[] Array) => Encoding.ASCII.GetString(Array ?? new byte[0]);
public static string ToUTF8 (this byte[] Array) => Encoding.UTF8 .GetString(Array ?? new byte[0]);
public static byte[] ToASCII(this string Data ) => Encoding.ASCII.GetBytes (Data ?? "" );
+47
View File
@@ -0,0 +1,47 @@
namespace KKdBaseLib
{
public struct Vector2<T> : INull
{
public T X;
public T Y;
public Vector2(T x, T y)
{ X = x; Y = y; }
public bool IsNull => X == null && Y == null;
public bool NotNull => X != null || Y != null;
public override string ToString() => $"({X}; {Y})";
}
public struct Vector3<T> : INull
{
public T X;
public T Y;
public T Z;
public Vector3(T x, T y, T z)
{ X = x; Y = y; Z = z; }
public bool IsNull => X == null && Y == null && Z == null;
public bool NotNull => X != null || Y != null || Z != null;
public override string ToString() => $"({X}; {Y}; {Z})";
}
public struct Vector4<T> : INull
{
public T X;
public T Y;
public T Z;
public T W;
public Vector4(T x, T y, T z, T w)
{ X = x; Y = y; Z = z; W = w; }
public bool IsNull => X == null && Y == null && Z == null && W == null;
public bool NotNull => X != null || Y != null || Z != null || W != null;
public override string ToString() => $"({X}; {Y}; {Z}; {W})";
}
}
+77
View File
@@ -0,0 +1,77 @@
namespace KKdBaseLib
{
public struct Vector3
{
public float X;
public float Y;
public float Z;
public Vector3(float X, float Y, float Z)
{ this.X = X; this.Y = Y; this.Z = Z; }
public float Length => (X * X + Y * Y + Z * Z).Sqrt();
public Vector3 Normalized => this = Length == 0 ? new Vector3() : this / Length;
public static Vector3 operator +(Vector3 left, Vector3 right)
{ left.X += right.X; left.Y += right.Y; left.Z += right.Z; return left; }
public static Vector3 operator -(Vector3 left, Vector3 right)
{ left.X -= right.X; left.Y -= right.Y; left.Z -= right.Z; return left; }
public static Vector3 operator -(Vector3 vec)
{ vec.X = -vec.X; vec.Y = -vec.Y; vec.Z = -vec.Z; return vec; }
public static Vector3 operator *(Vector3 vec, float scale)
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; return vec; }
public static Vector3 operator *( float scale, Vector3 vec)
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; return vec; }
public static Vector3 operator *(Vector3 vec, Vector3 scale)
{ vec.X *= scale.X; vec.Y *= scale.Y; vec.Z *= scale.Z; return vec; }
public static Vector3 operator /(Vector3 vec, float scale)
{ vec.X /= scale ; vec.Y /= scale ; vec.Z /= scale ; return vec; }
public static Vector3 operator /(Vector3 vec, Vector3 scale)
{ vec.X /= scale.X; vec.Y /= scale.Y; vec.Z /= scale.Z; return vec; }
public static bool operator ==(Vector3 A, Vector3 B) => A.X == B.X && A.Y == B.Y && A.Z == B.Z;
public static bool operator !=(Vector3 A, Vector3 B) => A.X != B.X || A.Y != B.Y || A.Z != B.Z;
public static double Distance (Vector3 left, Vector3 right) =>
(right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) *
(right.Y - left.Y) + (right.Z - left.Z) * (right.Z - left.Z).Sqrt();
public static double DistanceSquared(Vector3 left, Vector3 right) =>
(right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) *
(right.Y - left.Y) + (right.Z - left.Z) * (right.Z - left.Z);
public static double Dot(Vector3 left, Vector3 right) =>
left.X * right.X + left.Y * right.Y + left.Z * right.Z;
public static Vector3 Cross(Vector3 left, Vector3 right) =>
new Vector3 { X = left.Y * right.Z - left.Z * right.Y,
Y = left.Z * right.X - left.X * right.Z,
Z = left.X * right.Y - left.Y * right.X, };
public static Vector3 Lerp(Vector3 a, Vector3 b, float blend) =>
new Vector3 { X = blend * (b.X - a.X) + a.X,
Y = blend * (b.Y - a.Y) + a.Y,
Z = blend * (b.Z - a.Z) + a.Z };
public static Vector3 Lerp(Vector3 a, Vector3 b, Vector3 blend) =>
new Vector3 { X = blend.X * (b.X - a.X) + a.X,
Y = blend.Y * (b.Y - a.Y) + a.Y,
Z = blend.Z * (b.Z - a.Z) + a.Z };
public Vector3 Round( ) =>
new Vector3 { X = X.Round( ), Y = Y.Round( ), Z = Z.Round( ) };
public Vector3 Round(int d) =>
new Vector3 { X = X.Round(d), Y = Y.Round(d), Z = Z.Round(d) };
public override int GetHashCode()
{
unchecked
{
int hashCode = X.GetHashCode();
hashCode = (hashCode * 397) ^ Y.GetHashCode();
hashCode = (hashCode * 397) ^ Z.GetHashCode();
return hashCode;
}
}
public override bool Equals(object obj) =>
obj is Vector3 vec ? Equals(vec) : false;
public bool Equals(Vector3 other) =>
X == other.X && Y == other.Y && Z == other.Z;
public override string ToString() => $"({X}; {Y}, {Z})";
public string ToString(int d) => $"({X.Round(d)}; {Y.Round(d)}, {Z.Round(d)})";
}
}
+77
View File
@@ -0,0 +1,77 @@
namespace KKdBaseLib
{
public struct Vector4
{
public float X;
public float Y;
public float Z;
public float W;
public Vector4(float X, float Y, float Z, float W)
{ this.X = X; this.Y = Y; this.Z = Z; this.W = W; }
public float Length => (X * X + Y * Y + Z * Z + W * W).Sqrt();
public Vector4 Normalized => this = Length == 0 ? new Vector4() : this / Length;
public static Vector4 operator +(Vector4 left, Vector4 right)
{ left.X += right.X; left.Y += right.Y; left.Z += right.Z; left.W += right.W; return left; }
public static Vector4 operator -(Vector4 left, Vector4 right)
{ left.X -= right.X; left.Y -= right.Y; left.Z -= right.Z; left.W -= right.W; return left; }
public static Vector4 operator -(Vector4 vec)
{ vec.X = -vec.X; vec.Y = -vec.Y; vec.Z = -vec.Z; vec.W = -vec.W; return vec; }
public static Vector4 operator *(Vector4 vec, float scale)
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; vec.W *= scale ; return vec; }
public static Vector4 operator *( float scale, Vector4 vec)
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; vec.W *= scale ; return vec; }
public static Vector4 operator *(Vector4 vec, Vector4 scale)
{ vec.X *= scale.X; vec.Y *= scale.Y; vec.Z *= scale.Z; vec.W *= scale.W; return vec; }
public static Vector4 operator /(Vector4 vec, float scale)
{ vec.X /= scale ; vec.Y /= scale ; vec.Z /= scale ; vec.W /= scale ; return vec; }
public static Vector4 operator /(Vector4 vec, Vector4 scale)
{ vec.X /= scale.X; vec.Y /= scale.Y; vec.Z /= scale.Z; vec.W /= scale.W; return vec; }
public static bool operator ==(Vector4 A, Vector4 B) => A.Equals(B);
public static bool operator !=(Vector4 A, Vector4 B) => !A.Equals(B);
public static double Distance (Vector4 left, Vector4 right) =>
((right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) * (right.Y - left.Y) +
(right.Z - left.Z) * (right.Z - left.Z) + (right.W - left.W) * (right.W - left.W)).Sqrt();
public static double DistanceSquared(Vector4 left, Vector4 right) =>
(right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) * (right.Y - left.Y) +
(right.Z - left.Z) * (right.Z - left.Z) + (right.W - left.W) * (right.W - left.W);
public static double Dot(Vector4 left, Vector4 right) =>
left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W;
public static Vector4 Lerp(Vector4 a, Vector4 b, float blend) =>
new Vector4 { X = blend * (b.X - a.X) + a.X,
Y = blend * (b.Y - a.Y) + a.Y,
Z = blend * (b.Z - a.Z) + a.Z,
W = blend * (b.W - a.W) + a.W };
public static Vector4 Lerp(Vector4 a, Vector4 b, Vector4 blend) =>
new Vector4 { X = blend.X * (b.X - a.X) + a.X,
Y = blend.Y * (b.Y - a.Y) + a.Y,
Z = blend.Z * (b.Z - a.Z) + a.Z,
W = blend.W * (b.W - a.W) + a.W };
public Vector4 Round( ) =>
new Vector4 { X = X.Round( ), Y = Y.Round( ), Z = Z.Round( ), W = W.Round( ) };
public Vector4 Round(int d) =>
new Vector4 { X = X.Round(d), Y = Y.Round(d), Z = Z.Round(d), W = W.Round(d) };
public override int GetHashCode()
{
unchecked
{
int hashCode = X.GetHashCode();
hashCode = (hashCode * 397) ^ Y.GetHashCode();
hashCode = (hashCode * 397) ^ Z.GetHashCode();
hashCode = (hashCode * 397) ^ W.GetHashCode();
return hashCode;
}
}
public override bool Equals(object obj) =>
obj is Vector4 vec ? Equals(vec) : false;
public bool Equals(Vector4 other) =>
X == other.X && Y == other.Y && Z == other.Z && W == other.W;
public override string ToString() => $"({X}; {Y}, {Z}, {W})";
public string ToString(int d) => $"({X.Round(d)}; {Y.Round(d)}, {Z.Round(d)}, {W.Round(d)})";
}
}
+1680 -1718
View File
File diff suppressed because it is too large Load Diff
+881 -1260
View File
File diff suppressed because it is too large Load Diff
+81 -73
View File
@@ -1,47 +1,47 @@
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
using System.Collections.Generic;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
namespace KKdMainLib.DB
{
public class Aet
public class Aet : System.IDisposable
{
public AetSet[] AetSets;
private Stream IO;
private int i, i0, i1, i2;
private Stream _IO;
public AetSet[] AetSets;
public void BINReader(string file)
{
IO = File.OpenReader(file + ".bin");
_IO = File.OpenReader(file + ".bin");
int aetSetsLength = IO.ReadInt32();
int aetSetsOffset = IO.ReadInt32();
int aetsLength = IO.ReadInt32();
int aetsOffset = IO.ReadInt32();
int aetSetsLength = _IO.RI32();
int aetSetsOffset = _IO.RI32();
int aetsLength = _IO.RI32();
int aetsOffset = _IO.RI32();
IO.Position = aetSetsOffset;
_IO.P = 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();
AetSets[i].Id = _IO.RI32();
AetSets[i].Name = _IO.RSaO();
AetSets[i].FileName = _IO.RSaO();
_IO.RI32();
AetSets[i].SpriteSetId = _IO.RI32();
}
int setIndex;
AET aet = new AET();
int[] AetCount = new int[aetSetsLength];
IO.Position = aetsOffset;
_IO.P = aetsOffset;
for (i = 0; i < aetsLength; i++)
{
IO.LongPosition += 10;
setIndex = IO.ReadInt16();
_IO.PI64 += 10;
setIndex = _IO.RI16();
AetCount[setIndex]++;
}
@@ -51,18 +51,18 @@ namespace KKdMainLib.DB
AetCount[i] = 0;
}
IO.Position = aetsOffset;
_IO.P = aetsOffset;
for (i = 0; i < aetsLength; i++)
{
aet.Id = IO.ReadInt32();
aet.Name = IO.ReadStringAtOffset();
IO.ReadInt16();
setIndex = IO.ReadInt16();
aet.Id = _IO.RI32();
aet.Name = _IO.RSaO();
_IO.RI16();
setIndex = _IO.RI16();
AetSets[setIndex].Aets[AetCount[setIndex]] = aet; AetCount[setIndex]++;
}
IO.Close();
_IO.C();
}
@@ -133,76 +133,78 @@ namespace KKdMainLib.DB
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;
i1 = i1.A(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 = File.OpenWriter(file + ".bin", true);
_IO.W(i2);
_IO.W(i1);
_IO.W(i0);
_IO.W(0x20);
_IO.W(0x9066906690669066);
_IO.W(0x9066906690669066);
IO.Position = (i1 + i2 * 0x14).Align(0x20);
_IO.P = (i1 + i2 * 0x14).A(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");
AetSets[i]. NameOffset = _IO.P; _IO.W(AetSets[i]. Name + "\0");
AetSets[i].FileNameOffset = _IO.P; _IO.W(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"); }
{ AetSets[i].Aets[i0].NameOffset = _IO.P; _IO.W(AetSets[i].Aets[i0].Name + "\0"); }
}
IO.Align(0x08, true);
IO.Position = 0x20;
_IO.A(0x08, true);
_IO.P = 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.W(AetSets[i].Aets[i0].Id );
_IO.W(AetSets[i].Aets[i0].NameOffset);
_IO.W((ushort) i0 );
_IO.W((ushort)(i - i2));
}
}
IO.Align(0x20);
_IO.A(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.W(AetSets[i].Id );
_IO.W(AetSets[i]. NameOffset);
_IO.W(AetSets[i].FileNameOffset);
_IO.W(i - i2);
_IO.W(AetSets[i].SpriteSetId );
}
IO.Close();
_IO.C();
}
public void MsgPackReader(string file, bool JSON)
public void MsgPackReader(string file, bool json)
{
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
MsgPack MsgPack = file.ReadMPAllAtOnce(json);
if (MsgPack.ElementArray("AetDB", out MsgPack AetDB))
MsgPack Temp = default;
if ((Temp = MsgPack["AetDB", true]).NotNull)
{
AetSets = new AetSet[AetDB.Array.Length];
AetSets = new AetSet[Temp.Array.Length];
for (int i = 0; i < AetSets.Length; i++)
AetSets[i].ReadMsgPack(AetDB[i]);
AetSets[i].ReadMsgPack(Temp[i]);
}
MsgPack = MsgPack.New;
Temp.Dispose();
MsgPack.Dispose();
}
public void MsgPackWriter(string file, bool JSON)
public void MsgPackWriter(string file, bool json)
{
if (AetSets == null) return;
if (AetSets.Length == 0) return;
@@ -211,9 +213,13 @@ namespace KKdMainLib.DB
for (i = 0; i < AetSets.Length; i++)
AetDB[i] = AetSets[i].WriteMsgPack();
AetDB.Write(true, file, JSON);
AetDB.Write(true, file, json);
}
private bool disposed = false;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.D(); AetSets = null; disposed = true; } }
public struct AET
{
public int NameOffset;
@@ -221,8 +227,8 @@ namespace KKdMainLib.DB
public string Name;
public void ReadMsgPack(MsgPack msg)
{ Id = msg.ReadNUInt16("Id"); Name = msg.ReadString("Name"); }
{ Id = msg.RnU16("Id"); Name = msg.RS("Name"); }
public MsgPack WriteMsgPack() =>
MsgPack.New.Add("Id", Id).Add("Name", Name);
}
@@ -237,21 +243,23 @@ namespace KKdMainLib.DB
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");
FileName = msg.RS ("FileName" );
Id = msg.RnU16( "Id");
Name = msg.RS ( "Name" );
NewId = msg.RB("NewId" );
SpriteSetId = msg.RnU16("SpriteSetId");
if (msg.ElementArray("Aets", out MsgPack Aets))
MsgPack Temp;
if ((Temp = msg["Aets", true]).NotNull)
{
this.Aets = new AET[Aets.Array.Length];
for (int i0 = 0; i0 < this.Aets.Length; i0++)
this.Aets[i0].ReadMsgPack(Aets[i0]);
Aets = new AET[Temp.Array.Length];
for (int i0 = 0; i0 < Aets.Length; i0++)
Aets[i0].ReadMsgPack(Temp[i0]);
}
Temp.Dispose();
}
public MsgPack WriteMsgPack()
+92 -84
View File
@@ -1,150 +1,158 @@
using System;
using System.Collections.Generic;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib.A3DA;
using KKdMainLib.MessagePack;
using A3DADict = System.Collections.Generic.Dictionary<string, object>;
namespace KKdMainLib.DB
{
public class Auth
public class Auth : IDisposable
{
public int Signature { get; private set; }
public string[] Category { get; private set; }
public UID[] _UID { get; private set; }
public Stream IO { get; private set; }
private int i;
private Stream _IO;
public string[] Category;
public UID[] UIDs;
public void BINReader(string file)
{
Dictionary<string, object> Dict = new Dictionary<string, object>();
string[] dataArray;
A3DADict dict = new A3DADict();
IO = File.OpenReader(file + ".bin");
_IO = File.OpenReader(file + ".bin");
IO.Format = Main.Format.F;
Signature = IO.ReadInt32();
if (Signature != 0x44334123) return;
Signature = IO.ReadInt32();
if (Signature != 0x5F5F5F41) return;
IO.ReadInt64();
_IO.Format = Format.F;
int signature = _IO.RI32();
if (signature != 0x44334123) return;
signature = _IO.RI32();
if (signature != 0x5F5F5F41) return;
_IO.RI64();
string[] STRData = IO.ReadString(IO.Length - IO.Position).Replace("\r", "").Split('\n');
for (int i = 0; i < STRData.Length; i++)
{
dataArray = STRData[i].Split('=');
if (dataArray.Length == 2)
Dict.GetDictionary(dataArray[0], dataArray[1]);
}
string[] strData = _IO.RS(_IO.L - _IO.P).Replace("\r\n", "\n").Replace("\r", "\n").Split('\n');
for (i = 0; i < strData.Length; i++)
dict.GD(strData[i]);
strData = null;
if (Dict.FindValue(out string value, "category.length"))
if (dict.FV(out string value, "category.length"))
{
Category = new string[int.Parse(value)];
for (int i0 = 0; i0 < Category.Length; i0++)
if (Dict.FindValue(out value, "category." + i0 + ".value"))
Category[i0] = value;
for (i = 0; i < Category.Length; i++)
if (dict.FV(out value, $"category.{i}.value"))
Category[i] = value;
}
if (Dict.FindValue(out value, "uid.length"))
if (dict.FV(out value, "uid.length"))
{
_UID = new UID[int.Parse(value)];
for (int i0 = 0; i0 < _UID.Length; i0++)
UIDs = new UID[int.Parse(value)];
for (i = 0; i < UIDs.Length; i++)
{
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" );
dict.FV(out UIDs[i].Category, $"uid.{i}.category");
dict.FV(out UIDs[i].OrgUid , $"uid.{i}.org_uid" );
dict.FV(out UIDs[i].Size , $"uid.{i}.size" );
dict.FV(out UIDs[i].Value , $"uid.{i}.value" );
}
}
IO.Close();
_IO.C();
dict.Clear();
dict = null;
}
public void BINWriter(string file)
{
IO = File.OpenWriter(file + ".bin", true);
_IO = File.OpenWriter(file + ".bin", true);
IO.Write("#A3DA__________\n");
IO.Write("#", DateTime.UtcNow.ToString("ddd MMM dd HH:mm:ss yyyy",
System.Globalization.CultureInfo.InvariantCulture));
_IO.W("#A3DA__________\n");
_IO.W("#" + DateTime.UtcNow.ToString("ddd MMM dd HH:mm:ss yyyy",
System.Globalization.CultureInfo.InvariantCulture) + "\n");
if (Category != null)
{
int[] SO = Category.Length.SortWriter();
for (int i = 0; i < Category.Length; i++)
IO.Write("category." + SO[i] + ".value=", Category[SO[i]]);
IO.Write("category.length=", Category.Length);
int[] so = Category.Length.SW();
for (i = 0; i < Category.Length; i++)
_IO.W($"category.{so[i]}.value={ Category[so[i]]}\n");
_IO.W($"category.length={Category.Length}\n");
}
if (_UID != null)
if (UIDs != null)
{
int[] SO = _UID.Length.SortWriter();
for (int i = 0; i < _UID.Length; i++)
int[] so = UIDs.Length.SW();
for (i = 0; i < UIDs.Length; i++)
{
if (_UID[SO[i]].Category != "")
IO.Write("uid." + SO[i] + ".category=", _UID[SO[i]].Category);
IO.Write("uid." + SO[i] + ".org_uid=" , _UID[SO[i]].OrgUid );
IO.Write("uid." + SO[i] + ".size=" , _UID[SO[i]].Size );
if (_UID[SO[i]].Value != "")
IO.Write("uid." + SO[i] + ".value=" , _UID[SO[i]].Value );
if (UIDs[so[i]].Category != null && UIDs[so[i]].Category != "")
_IO.W($"uid.{so[i]}.category=" + UIDs[so[i]].Category + "\n");
if (UIDs[so[i]].OrgUid != null)
_IO.W($"uid.{so[i]}.org_uid=" + UIDs[so[i]].OrgUid + "\n");
if (UIDs[so[i]].Size != null)
_IO.W($"uid.{so[i]}.size=" + UIDs[so[i]].Size + "\n");
if (UIDs[so[i]].Value != null && UIDs[so[i]].Value != "")
_IO.W($"uid.{so[i]}.value=" + UIDs[so[i]].Value + "\n");
}
IO.Write("uid.length=", _UID.Length);
_IO.W($"uid.length={UIDs.Length}\n");
}
IO.Close();
_IO.C();
}
public void MsgPackReader(string file, bool JSON)
public void MsgPackReader(string file, bool json)
{
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
MsgPack msgPack = file.ReadMPAllAtOnce(json);
if (MsgPack.Element("AuthDB", out MsgPack AuthDB))
MsgPack authDB;
if ((authDB = msgPack["AuthDB"]).NotNull)
{
if (AuthDB.ElementArray("Category", out MsgPack Temp))
MsgPack temp;
if ((temp = authDB["Category", true]).NotNull)
{
Category = new string[Temp.Array.Length];
Category = new string[temp.Array.Length];
for (int i = 0; i < Category.Length; i++)
Category[i] = Temp[i].ReadString();
Category[i] = temp[i].RS();
}
if (AuthDB.ElementArray("UID", out Temp))
if ((temp = authDB["UID", true]).NotNull)
{
_UID = new UID[Temp.Array.Length];
for (int i = 0; i < _UID.Length; i++)
UIDs = new UID[temp.Array.Length];
for (int i = 0; i < UIDs.Length; i++)
{
_UID[i].Category = Temp[i].ReadString("Category");
_UID[i].OrgUid = Temp[i].ReadNInt32("OrgUid" );
_UID[i].Size = Temp[i].ReadNInt32("Size" );
_UID[i].Value = Temp[i].ReadString("Value" );
UIDs[i].Category = temp[i].RS ("Category");
UIDs[i].OrgUid = temp[i].RnI32("OrgUid" );
UIDs[i].Size = temp[i].RnI32("Size" );
UIDs[i].Value = temp[i].RS ("Value" );
}
}
temp.Dispose();
}
MsgPack = MsgPack.New;
authDB.Dispose();
msgPack.Dispose();
}
public void MsgPackWriter(string file, bool JSON)
public void MsgPackWriter(string file, bool json)
{
MsgPack AuthDB = new MsgPack("AuthDB");
MsgPack authDB = new MsgPack("AuthDB");
if (Category != null)
{
MsgPack Category = new MsgPack(this.Category.Length, "Category");
for (int i = 0; i < this.Category.Length; i++)
Category[i] = (MsgPack)this.Category[i];
AuthDB.Add(Category);
MsgPack category = new MsgPack(Category.Length, "Category");
for (int i = 0; i < Category.Length; i++)
category[i] = (MsgPack)Category[i];
authDB.Add(category);
}
if (_UID != null)
if (UIDs != null)
{
MsgPack UID = new MsgPack(_UID.Length, "UID");
for (int i = 0; i < _UID.Length; i++)
UID[i] = MsgPack.New.Add("Category", _UID[i].Category)
.Add("OrgUid" , _UID[i].OrgUid )
.Add("Size" , _UID[i].Size )
.Add("Value" , _UID[i].Value );
AuthDB.Add(UID);
MsgPack uid = new MsgPack(UIDs.Length, "UID");
for (int i = 0; i < UIDs.Length; i++)
uid[i] = MsgPack.New.Add("Category", UIDs[i].Category)
.Add("OrgUid" , UIDs[i].OrgUid )
.Add("Size" , UIDs[i].Size )
.Add("Value" , UIDs[i].Value );
authDB.Add(uid);
}
AuthDB.Write(true, file, JSON);
authDB.Write(true, file, json);
}
private bool disposed = false;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.D(); Category = null; UIDs = null; disposed = true; } }
public struct UID
{
public int? Size;
+149 -137
View File
@@ -1,79 +1,79 @@
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
using System.Collections.Generic;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
namespace KKdMainLib.DB
{
public class Spr
public class Spr : System.IDisposable
{
public SpriteSet[] SpriteSets;
private Stream IO;
private int i, i0, i1, i2;
private Stream _IO;
public SpriteSet[] SpriteSets;
public void BINReader(string file)
{
IO = File.OpenReader(file + ".bin");
_IO = File.OpenReader(file + ".bin");
int spriteSetsLength = IO.ReadInt32();
int spriteSetsOffset = IO.ReadInt32();
int spritesLength = IO.ReadInt32();
int spritesOffset = IO.ReadInt32();
int spriteSetsLength = _IO.RI32();
int spriteSetsOffset = _IO.RI32();
int spritesLength = _IO.RI32();
int spritesOffset = _IO.RI32();
IO.Position = spriteSetsOffset;
_IO.P = 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();
SpriteSets[i].Id = _IO.RI32();
SpriteSets[i].Name = _IO.RSaO();
SpriteSets[i].FileName = _IO.RSaO();
_IO.RI32();
}
int setIndex;
bool IsTexture;
bool isTexture;
SpriteTexture st = new SpriteTexture();
int[] SprCount = new int[spriteSetsLength];
int[] TexCount = new int[spriteSetsLength];
int[] sprCount = new int[spriteSetsLength];
int[] texCount = new int[spriteSetsLength];
IO.Position = spritesOffset;
_IO.P = spritesOffset;
for (i = 0; i < spritesLength; i++)
{
IO.LongPosition += 10;
setIndex = IO.ReadInt16();
IsTexture = (setIndex & 0x1000) == 0x1000;
_IO.PI64 += 10;
setIndex = _IO.RI16();
isTexture = (setIndex & 0x1000) == 0x1000;
setIndex &= 0xFFF;
if (IsTexture) TexCount[setIndex]++;
else SprCount[setIndex]++;
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]];
SpriteSets[i].Sprites = new SpriteTexture[sprCount[i]];
SpriteSets[i].Textures = new SpriteTexture[texCount[i]];
SprCount[i] = 0;
TexCount[i] = 0;
sprCount[i] = 0;
texCount[i] = 0;
}
IO.Position = spritesOffset;
_IO.P = spritesOffset;
for (i = 0; i < spritesLength; i++)
{
st.Id = IO.ReadInt32();
st.Name = IO.ReadStringAtOffset();
IO.ReadInt16();
setIndex = IO.ReadInt16();
IsTexture = (setIndex & 0x1000) == 0x1000;
st.Id = _IO.RI32();
st.Name = _IO.RSaO();
_IO.RI16();
setIndex = _IO.RI16();
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]++; }
if (isTexture) { SpriteSets[setIndex].Textures[texCount[setIndex]] = st; texCount[setIndex]++; }
else { SpriteSets[setIndex]. Sprites[sprCount[setIndex]] = st; sprCount[setIndex]++; }
}
IO.Close();
_IO.C();
}
public void BINWriter(string file)
@@ -81,13 +81,13 @@ namespace KKdMainLib.DB
if (SpriteSets == null) return;
if (SpriteSets.Length == 0) return;
List<string> SetName = new List<string>();
List<string> SetFileName = new List<string>();
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> ids = new List<int>();
List<int> setIds = new List<int>();
List<int> NotAdd = new List<int>();
List<int> notAdd = new List<int>();
SpriteTexture temp;
SpriteSet set;
@@ -95,11 +95,11 @@ namespace KKdMainLib.DB
{
set = SpriteSets[i];
if (set. Name != null)
if (SetName .Contains(set. Name)) { NotAdd.Add(i); continue; }
else SetName .Add (set. Name);
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 (setFileName.Contains(set.FileName)) { notAdd.Add(i); continue; }
else setFileName.Add (set.FileName);
if (set.NewId)
{
@@ -110,15 +110,15 @@ namespace KKdMainLib.DB
}
if (set.Id != null)
if (SetIds.Contains((int)set.Id)) { NotAdd.Add(i); continue; }
else SetIds.Add ((int)set.Id);
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 ( ids.Contains((int)temp.Id)) { notAdd.Add(i); break; }
else ids.Add ((int)temp.Id);
}
if (i0 < set.Sprites.Length) continue;
@@ -126,129 +126,138 @@ namespace KKdMainLib.DB
{
temp = set.Textures[i0];
if (temp.Id != null)
if ( Ids.Contains((int)temp.Id)) { NotAdd.Add(i); break; }
else Ids.Add ((int)temp.Id);
if ( ids.Contains((int)temp.Id)) { notAdd.Add(i); break; }
else ids.Add ((int)temp.Id);
}
}
SetName = null;
SetFileName = null;
setName = null;
setFileName = null;
for (i = 0; i < SpriteSets.Length; i++)
{
set = SpriteSets[i];
if (NotAdd.Contains(i)) continue;
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++; }
{ if (!setIds.Contains(i1)) { SpriteSets[i].Id = i1; setIds.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++; }
while (set.Textures[i0].Id == null)
if (!ids.Contains(i1)) ids.Add((int)(SpriteSets[i].Textures[i0].Id = i1)); else i1++;
for (i0 = 0, i1 = 0; i0 < set. Sprites.Length; i0++)
while (set. Sprites[i0].Id == null)
if (!ids.Contains(i1)) ids.Add((int)(SpriteSets[i]. Sprites[i0].Id = i1)); else i1++;
}
Ids = null;
SetIds = null;
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++; }
if (!notAdd.Contains(i)) { i0 += SpriteSets[i].Sprites.Length + SpriteSets[i].Textures.Length; i2++; }
i1 = i0 * 12;
i1 = i1.Align(0x20) + 0x20;
i1 = i1.A(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 = File.OpenWriter(file + ".bin", true);
_IO.W(i2);
_IO.W(i1);
_IO.W(i0);
_IO.W(0x20);
_IO.W(0x9066906690669066);
_IO.W(0x9066906690669066);
IO.Position = (i1 + i2 * 0x10).Align(0x20);
_IO.P = (i1 + i2 * 0x10).A(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");
if (notAdd.Contains(i)) continue;
for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++)
{ SpriteSets[i].Textures[i0].NameOffset = _IO.P;
_IO.W(SpriteSets[i].Textures[i0].Name + "\0"); }
for (i0 = 0; i0 < SpriteSets[i]. Sprites.Length; i0++)
{ SpriteSets[i]. Sprites[i0].NameOffset = _IO.P;
_IO.W(SpriteSets[i]. Sprites[i0].Name + "\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"); }
if (notAdd.Contains(i)) continue;
SpriteSets[i]. NameOffset = _IO.P; _IO.W(SpriteSets[i]. Name + "\0");
SpriteSets[i].FileNameOffset = _IO.P; _IO.W(SpriteSets[i].FileName + "\0");
}
IO.Align(0x08, true);
IO.Position = 0x20;
_IO.A(0x08, true);
_IO.P = 0x20;
for (i = 0, i2 = 0; i < SpriteSets.Length; i++)
{
if (NotAdd.Contains(i)) { i2++; continue; }
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)));
_IO.W(SpriteSets[i].Textures[i0].Id );
_IO.W(SpriteSets[i].Textures[i0].NameOffset);
_IO.W((ushort) i0 );
_IO.W((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.W(SpriteSets[i]. Sprites[i0].Id );
_IO.W(SpriteSets[i]. Sprites[i0].NameOffset);
_IO.W((ushort) i0 );
_IO.W((ushort)(i - i2));
}
}
IO.Align(0x20);
_IO.A(0x20);
for (i = 0, i2 = 0; i < SpriteSets.Length; i++)
{
if (NotAdd.Contains(i)) { i2++; continue; }
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.W(SpriteSets[i].Id );
_IO.W(SpriteSets[i]. NameOffset);
_IO.W(SpriteSets[i].FileNameOffset);
_IO.W(i - i2);
}
IO.Close();
_IO.C();
}
public void MsgPackReader(string file, bool JSON = false)
public void MsgPackReader(string file, bool json = false)
{
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
MsgPack msgPack = file.ReadMPAllAtOnce(json);
if (MsgPack.ElementArray("SprDB", out MsgPack SprDB))
MsgPack sprDB;
if ((sprDB = msgPack["SprDB", true]).NotNull)
{
SpriteSets = new SpriteSet[SprDB.Array.Length];
SpriteSets = new SpriteSet[sprDB.Array.Length];
for (int i = 0; i < SpriteSets.Length; i++)
SpriteSets[i].ReadMsgPack(SprDB[i]);
SpriteSets[i].ReadMsgPack(sprDB[i]);
}
MsgPack = MsgPack.New;
sprDB.Dispose();
msgPack.Dispose();
}
public void MsgPackWriter(string file, bool JSON)
public void MsgPackWriter(string file, bool json)
{
if (SpriteSets == null) return;
if (SpriteSets.Length == 0) return;
MsgPack SprDB = new MsgPack(SpriteSets.Length, "SprDB");
for (i = 0; i < SpriteSets.Length; i++) SprDB[i] = SpriteSets[i].WriteMsgPack();
MsgPack sprDB = new MsgPack(SpriteSets.Length, "SprDB");
for (i = 0; i < SpriteSets.Length; i++)
sprDB[i] = SpriteSets[i].WriteMsgPack();
SprDB.Write(true, file, JSON);
sprDB.Write(true, file, json);
}
private bool disposed = false;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.D(); SpriteSets = null; disposed = true; } }
public struct SpriteTexture
{
public int NameOffset;
@@ -256,7 +265,7 @@ namespace KKdMainLib.DB
public string Name;
public void ReadMsgPack(MsgPack msg)
{ Id = msg.ReadNInt32("Id"); Name = msg.ReadString("Name"); }
{ Id = msg.RnI32("Id"); Name = msg.RS("Name"); }
public MsgPack WriteMsgPack() =>
MsgPack.New.Add("Id", Id).Add("Name", Name);
@@ -272,40 +281,43 @@ namespace KKdMainLib.DB
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" );
FileName = msg.RS ("FileName");
Id = msg.RnI32( "Id" );
Name = msg.RS ("Name" );
NewId = msg.RB ("NewId" );
if (msg.ElementArray( "Sprites", out MsgPack Sprites))
MsgPack temp;
if ((temp = msg["Sprites", true]).NotNull)
{
this.Sprites = new SpriteTexture[Sprites.Array.Length];
for (int i0 = 0; i0 < this.Sprites.Length; i0++)
this.Sprites[i0].ReadMsgPack(Sprites[i0]);
Sprites = new SpriteTexture[temp.Array.Length];
for (int i0 = 0; i0 < Sprites.Length; i0++)
Sprites[i0].ReadMsgPack(temp[i0]);
}
if (msg.ElementArray("Textures", out MsgPack Textures))
if ((temp = msg["Textures", true]).NotNull)
{
this.Textures = new SpriteTexture[Textures.Array.Length];
for (int i0 = 0; i0 < this.Textures.Length; i0++)
this.Textures[i0].ReadMsgPack(Textures[i0]);
Textures = new SpriteTexture[temp.Array.Length];
for (int i0 = 0; i0 < Textures.Length; i0++)
Textures[i0].ReadMsgPack(temp[i0]);
}
temp.Dispose();
}
public MsgPack WriteMsgPack()
{
MsgPack Sprites = new MsgPack(this. Sprites.Length, "Sprites");
for (int i0 = 0; i0 < this.Sprites.Length; i0++)
Sprites[i0] = this.Sprites[i0].WriteMsgPack();
MsgPack sprites = new MsgPack( Sprites.Length, "Sprites");
for (int i0 = 0; i0 < Sprites.Length; i0++)
sprites[i0] = Sprites[i0].WriteMsgPack();
MsgPack Textures = new MsgPack(this.Textures.Length, "Textures");
for (int i0 = 0; i0 < this.Textures.Length; i0++)
Textures[i0] = this.Textures[i0].WriteMsgPack();
MsgPack textures = new MsgPack(Textures.Length, "Textures");
for (int i0 = 0; i0 < Textures.Length; i0++)
textures[i0] = Textures[i0].WriteMsgPack();
return MsgPack.New.Add("FileName", FileName).Add("Id", Id).Add("Name", Name).Add(Sprites).Add(Textures);
return MsgPack.New.Add("FileName", FileName).Add("Id", Id)
.Add("Name", Name).Add(sprites).Add(textures);
}
}
}
+172 -170
View File
@@ -1,239 +1,229 @@
using System.Collections.Generic;
using KKdBaseLib;
using KKdBaseLib.F2;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
using MPIO = KKdMainLib.MessagePack.IO;
namespace KKdMainLib
{
public class DEX
public struct DEX : System.IDisposable
{
public DEX()
{ Dex = null; Header = new PDHead(); }
private int Offset = 0;
private PDHead Header;
private Stream IO;
private int i, i0, i1;
private Header header;
private Stream _IO;
public EXP[] Dex;
public int DEXReader(string filepath, string ext)
public void DEXReader(string filepath, string ext)
{
Header = new PDHead();
IO = File.OpenReader(filepath + ext);
Dex = null;
header = new Header();
_IO = File.OpenReader(filepath + ext);
Header.Format = Main.Format.F;
Header.SectionSignature = IO.ReadInt32();
if (Header.SectionSignature == 0x43505845)
Header = IO.ReadHeader(true);
if (Header.SectionSignature != 0x64)
return 0;
header.Format = Format.F;
header.SectionSignature = _IO.RI32();
if (header.SectionSignature == 0x43505845)
header = _IO.ReadHeader(true, true);
if (header.SectionSignature != 0x64) return;
Offset = IO.Position - 0x4;
Dex = new EXP[IO.ReadInt32()];
int DEXOffset = IO.ReadInt32();
if (IO.ReadInt32() == 0x00) Header.Format = Main.Format.X;
int DEXNameOffset = IO.ReadInt32();
if (Header.IsX) IO.ReadInt32();
_IO.O = _IO.P - 0x4;
Dex = new EXP[_IO.RI32()];
int DEXOffset = _IO.RI32();
int DEXNameOffset = _IO.RI32();
if (DEXNameOffset == 0x00) { _IO.Format = header.Format = Format.X; DEXNameOffset = (int)_IO.RIX(); }
IO.Seek(DEXOffset + Offset, 0);
for (int i0 = 0; i0 < Dex.Length; i0++)
Dex[i0] = new EXP { Main = new List<EXPElement>(), Eyes = new List<EXPElement>() };
for (int i0 = 0; i0 < Dex.Length; i0++)
_IO.P = DEXOffset;
for (i = 0; i < Dex.Length; i++)
{
Dex[i0].MainOffset = IO.ReadInt32();
if (Header.IsX) IO.ReadInt32();
Dex[i0].EyesOffset = IO.ReadInt32();
if (Header.IsX) IO.ReadInt32();
}
IO.Seek(DEXNameOffset + Offset, 0);
for (int i0 = 0; i0 < Dex.Length; i0++)
{
Dex[i0].NameOffset = IO.ReadInt32();
if (Header.IsX) IO.ReadInt32();
Dex[i].MainOffset = (int)_IO.RIX();
Dex[i].EyesOffset = (int)_IO.RIX();
}
_IO.P = DEXNameOffset;
for (i = 0; i < Dex.Length; i++)
Dex[i].NameOffset = (int)_IO.RIX();
for (int i0 = 0; i0 < Dex.Length; i0++)
for (i = 0; i < Dex.Length; i++)
{
EXPElement element = new EXPElement();
IO.Seek(Dex[i0].MainOffset + Offset, 0);
Dex[i].Main = KKdList<EXPElement>.New;
_IO.P = Dex[i].MainOffset;
while (true)
{
element.Frame = IO.ReadSingle();
element.Both = IO.ReadUInt16();
element.ID = IO.ReadUInt16();
element.Value = IO.ReadSingle();
element.Trans = IO.ReadSingle();
Dex[i0].Main.Add(element);
if (element.Frame == 999999 || element.Both == 0xFFFF)
break;
element.Frame = _IO.RF32();
element.Both = _IO.RU16();
element.ID = _IO.RU16();
element.Value = _IO.RF32();
element.Trans = _IO.RF32();
if (element.Frame == 999999 || element.Both == 0xFFFF) break;
Dex[i].Main.Add(element);
}
IO.Seek(Dex[i0].EyesOffset + Offset, 0);
Dex[i].Eyes = KKdList<EXPElement>.New;
_IO.P = Dex[i].EyesOffset;
while(true)
{
element.Frame = IO.ReadSingle();
element.Both = IO.ReadUInt16();
element.ID = IO.ReadUInt16();
element.Value = IO.ReadSingle();
element.Trans = IO.ReadSingle();
Dex[i0].Eyes.Add(element);
if (element.Frame == 999999 || element.Both == 0xFFFF)
break;
element.Frame = _IO.RF32();
element.Both = _IO.RU16();
element.ID = _IO.RU16();
element.Value = _IO.RF32();
element.Trans = _IO.RF32();
if (element.Frame == 999999 || element.Both == 0xFFFF) break;
Dex[i].Eyes.Add(element);
}
IO.Seek(Dex[i0].NameOffset + Offset, 0);
Dex[i0].Name = IO.NullTerminatedUTF8();
Dex[i].Name = _IO.RSaO(Dex[i].NameOffset);
}
IO.Close();
return 1;
_IO.C();
}
public void DEXWriter(string filepath, Main.Format Format)
public void DEXWriter(string filepath, Format Format)
{
Header = new PDHead() { Format = Format };
IO = File.OpenWriter(filepath + (Format > Main.Format.F ? ".dex" : ".bin"), true);
IO.Format = Format;
if (Dex == null || Dex.Length < 1) return;
IO.Offset = Format > Main.Format.F ? 0x20 : 0;
IO.Write(0x64);
IO.Write(Dex.Length);
header = new Header();
_IO = File.OpenWriter(filepath + (Format > Format.F && Format < Format.FT ? ".dex" : ".bin"), true);
header.Format = _IO.Format = Format;
IO.WriteX(Header.IsX ? 0x28 : 0x20);
IO.WriteX(0x00);
_IO.O = Format > Format.F ? 0x20 : 0;
_IO.W(0x64);
_IO.W(Dex.Length);
int Position0 = IO.Position;
IO.Write(0x00L);
IO.Write(0x00L);
_IO.WX(header.IsX ? 0x28 : 0x20);
_IO.WX(0x00);
for (int i = 0; i < Dex.Length * 3; i++) IO.WriteX(0x00);
int Position0 = _IO.P;
_IO.W(0x00L);
_IO.W(0x00L);
IO.Align(0x20, true);
for (i = 0; i < Dex.Length * 3; i++) _IO.WX(0x00);
_IO.A(0x20);
for (int i0 = 0; i0 < Dex.Length; i0++)
for (i0 = 0; i0 < Dex.Length; i0++)
{
Dex[i0].MainOffset = IO.Position;
for (int i1 = 0; i1 < Dex[i0].Main.Count; i1++)
Dex[i0].MainOffset = _IO.P;
for (i1 = 0; i1 < Dex[i0].Main.Count; i1++)
{
IO.Write(Dex[i0].Main[i1].Frame);
IO.Write(Dex[i0].Main[i1].Both );
IO.Write(Dex[i0].Main[i1].ID );
IO.Write(Dex[i0].Main[i1].Value);
IO.Write(Dex[i0].Main[i1].Trans);
_IO.W(Dex[i0].Main[i1].Frame);
_IO.W(Dex[i0].Main[i1].Both );
_IO.W(Dex[i0].Main[i1].ID );
_IO.W(Dex[i0].Main[i1].Value);
_IO.W(Dex[i0].Main[i1].Trans);
}
IO.Align(0x20, true);
_IO.W(999999f);
_IO.W(0xFFFF);
_IO.W(0x0L);
_IO.A(0x20);
Dex[i0].EyesOffset = IO.Position;
for (int i1 = 0; i1 < Dex[i0].Eyes.Count; i1++)
Dex[i0].EyesOffset = _IO.P;
for (i1 = 0; i1 < Dex[i0].Eyes.Count; i1++)
{
IO.Write(Dex[i0].Eyes[i1].Frame);
IO.Write(Dex[i0].Eyes[i1].Both );
IO.Write(Dex[i0].Eyes[i1].ID );
IO.Write(Dex[i0].Eyes[i1].Value);
IO.Write(Dex[i0].Eyes[i1].Trans);
_IO.W(Dex[i0].Eyes[i1].Frame);
_IO.W(Dex[i0].Eyes[i1].Both );
_IO.W(Dex[i0].Eyes[i1].ID );
_IO.W(Dex[i0].Eyes[i1].Value);
_IO.W(Dex[i0].Eyes[i1].Trans);
}
IO.Align(0x20, true);
_IO.W(999999f);
_IO.W(0xFFFF);
_IO.W(0x0L);
_IO.A(0x20);
}
for (int i0 = 0; i0 < Dex.Length; i0++)
for (i = 0; i < Dex.Length; i++)
{
Dex[i0].NameOffset = IO.Position;
IO.Write(Dex[i0].Name + "\0");
Dex[i].NameOffset = _IO.P;
_IO.W(Dex[i].Name + "\0");
}
IO.Align(0x10, true);
_IO.A(0x10, true);
IO.Position = Header.IsX ? 0x28 : 0x20;
for (int i0 = 0; i0 < Dex.Length; i0++)
_IO.P = header.IsX ? 0x28 : 0x20;
for (i = 0; i < Dex.Length; i++)
{
IO.WriteX(Dex[i0].MainOffset);
IO.WriteX(Dex[i0].EyesOffset);
_IO.WX(Dex[i].MainOffset);
_IO.WX(Dex[i].EyesOffset);
}
int Position1 = IO.Position;
for (int i0 = 0; i0 < Dex.Length; i0++)
IO.WriteX(Dex[i0].NameOffset);
int namesPosition = _IO.P;
for (i = 0; i < Dex.Length; i++)
_IO.WX(Dex[i].NameOffset);
IO.Position = Position0 - (Header.IsX ? 8 : 4);
IO.Write(Position1);
_IO.P = Position0 - (header.IsX ? 8 : 4);
_IO.W(namesPosition);
if (Format > Main.Format.F)
if (Format > Format.F)
{
Offset = IO.Length;
IO.Offset = 0;
IO.Position = IO.Length;
IO.WriteEOFC(0);
IO.Position = 0;
Header.DataSize = Offset;
Header.SectionSize = Offset;
Header.Signature = 0x43505845;
IO.Write(Header, true);
int offset = _IO.L;
_IO.O = 0;
_IO.P = _IO.L;
_IO.WEOFC(0);
_IO.P = 0;
header.DataSize = offset;
header.SectionSize = offset;
header.Signature = 0x43505845;
_IO.W(header, true);
}
IO.Close();
_IO.C();
}
public void MsgPackReader(string file, bool JSON)
public void MsgPackReader(string file, bool json)
{
int i0 = 0;
int i1 = 0;
this.Dex = new EXP[0];
Header = new PDHead();
Dex = null;
header = new Header();
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
if (!MsgPack.ElementArray("Dex", out MsgPack Dex)) return;
this.Dex = new EXP[Dex.Array.Length];
for (i0 = 0; i0 < this.Dex.Length; i0++)
MsgPack msgPack = file.ReadMPAllAtOnce(json);
MsgPack dex;
if ((dex = msgPack["Dex", true]).NotNull)
{
this.Dex[i0] = new EXP { Name = Dex[i0].ReadString("Name") };
Dex = new EXP[dex.Array.Length];
for (i0 = 0; i0 < Dex.Length; i0++)
{
Dex[i0] = new EXP { Name = dex[i0].RS("Name") };
if (Dex[i0].ElementArray("Main", out MsgPack Main))
{
this.Dex[i0].Main = new List<EXPElement>();
for (i1 = 0; i1 < Main.Array.Length; i1++)
this.Dex[i0].Main.Add(ReadEXP(Main[i1]));
}
if (Dex[i0].ElementArray("Eyes", out MsgPack Eyes))
{
this.Dex[i0].Eyes = new List<EXPElement>();
for (i1 = 0; i1 < Eyes.Array.Length; i1++)
this.Dex[i0].Eyes.Add(ReadEXP(Eyes[i1]));
MsgPack temp;
if ((temp = dex[i0]["Main", true]).NotNull)
{
Dex[i0].Main = KKdList<EXPElement>.New;
Dex[i0].Main.Capacity = temp.Array.Length;
for (i1 = 0; i1 < Dex[i0].Main.Capacity; i1++)
Dex[i0].Main.Add(EXPElement.Read(temp[i1]));
}
if ((temp = dex[i0]["Eyes", true]).NotNull)
{
Dex[i0].Eyes = KKdList<EXPElement>.New;
Dex[i0].Eyes.Capacity = temp.Array.Length;
for (i1 = 0; i1 < this.Dex[i0].Eyes.Capacity; i1++)
Dex[i0].Eyes.Add(EXPElement.Read(temp[i1]));
}
temp.Dispose();
}
}
MsgPack = MsgPack.New;
dex.Dispose();
msgPack.Dispose();
}
private EXPElement ReadEXP(MsgPack mp) =>
new EXPElement() { Frame = mp.ReadSingle("F"), Both = mp.ReadUInt16("B"),
ID = mp.ReadUInt16("I"), Value = mp.ReadSingle("V"),
Trans = mp.ReadSingle("T") };
public void MsgPackWriter(string file, bool JSON)
public void MsgPackWriter(string file, bool json)
{
int i0 = 0;
int i1 = 0;
MsgPack Dex = new MsgPack(this.Dex.Length, "Dex");
for (i0 = 0; i0 < this.Dex.Length; i0++)
{
MsgPack EXP = MsgPack.New.Add("Name", this.Dex[i0].Name);
MsgPack Main = new MsgPack(this.Dex[i0].Main.Count, "Main");
for (i1 = 0; i1 < this.Dex[i0].Main.Count; i1++)
Main[i1] = WriteEXP(this.Dex[i0].Main[i1]);
EXP.Add(Main);
if (Dex == null || Dex.Length < 1) return;
MsgPack Eyes = new MsgPack(this.Dex[i0].Eyes.Count, "Eyes");
for (i1 = 0; i1 < this.Dex[i0].Eyes.Count; i1++)
Eyes[i1] = WriteEXP(this.Dex[i0].Eyes[i1]);
EXP.Add(Eyes);
Dex[i0] = EXP;
MsgPack dex = new MsgPack(Dex.Length, "Dex");
for (i0 = 0; i0 < Dex.Length; i0++)
{
MsgPack exp = MsgPack.New.Add("Name", Dex[i0].Name);
MsgPack main = new MsgPack(Dex[i0].Main.Count, "Main");
for (i1 = 0; i1 < Dex[i0].Main.Count; i1++)
main[i1] = Dex[i0].Main[i1].Write();
exp.Add(main);
MsgPack eyes = new MsgPack(Dex[i0].Eyes.Count, "Eyes");
for (i1 = 0; i1 < Dex[i0].Eyes.Count; i1++)
eyes[i1] = Dex[i0].Eyes[i1].Write();
exp.Add(eyes);
dex[i0] = exp;
}
Dex.Write(true, file, JSON);
dex.Write(true, file, json);
}
private MsgPack WriteEXP(EXPElement element) =>
MsgPack.New.Add("F", element.Frame).Add("B", element.Both ).Add("I", element.ID )
.Add("V", element.Value).Add("T", element.Trans);
private bool disposed;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.Dispose(); Dex = null; header = default; disposed = true; } }
public struct EXP
{
@@ -241,8 +231,10 @@ namespace KKdMainLib
public int EyesOffset;
public int NameOffset;
public string Name;
public List<EXPElement> Main;
public List<EXPElement> Eyes;
public KKdList<EXPElement> Main;
public KKdList<EXPElement> Eyes;
public override string ToString() => Name;
}
public struct EXPElement
@@ -252,6 +244,16 @@ namespace KKdMainLib
public ushort ID;
public float Value;
public float Trans;
public static EXPElement Read(MsgPack msg) =>
new EXPElement() { Frame = msg.RF32("F"), Both = msg.RU16("B"),
ID = msg.RU16("I"), Value = msg.RF32("V"),
Trans = msg.RF32("T"), };
public MsgPack Write() =>
MsgPack.New.Add("F", Frame).Add("B", Both )
.Add("I", ID).Add("V", Value)
.Add("T", Trans);
}
}
}
+40 -34
View File
@@ -1,5 +1,6 @@
using System;
using System.Security.Cryptography;
using KKdBaseLib;
using KKdMainLib.IO;
using MSIO = System.IO;
@@ -13,54 +14,59 @@ namespace KKdMainLib
public static void Decrypt(this string file)
{
Console.Title = "DIVAFILE Decrypt - File: " + Path.GetFileName(file);
Stream reader = File.OpenReader(file);
if (reader.ReadInt64() != 0x454C494641564944)
{ reader.Close(); return; }
int StreamLenght = reader.ReadInt32();
int FileLenght = reader.ReadInt32();
byte[] decrypted = new byte[StreamLenght];
reader.Seek(0, 0);
int streamLength, fileLength;
byte[] encrypted, decrypted;
using (Stream _IO = File.OpenReader(file))
{
if (_IO.RI64() != 0x454C494641564944) return;
streamLength = _IO.RI32();
fileLength = _IO.RI32();
encrypted = _IO.RBy(streamLength);
decrypted = new byte[streamLength];
}
using (AesManaged crypto = new AesManaged())
{
crypto.Key = Key; crypto.IV = new byte[16];
crypto.Mode = CipherMode.ECB; crypto.Padding = PaddingMode.Zeros;
using (CryptoStream cryptoData = new CryptoStream(reader.BaseStream,
crypto.CreateDecryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read))
cryptoData.Read(decrypted, 0, StreamLenght);
using CryptoStream cryptoData = new CryptoStream(new MSIO.MemoryStream(encrypted),
crypto.CreateDecryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read);
cryptoData.Read(decrypted, 0, streamLength);
}
Stream writer = File.OpenWriter(file, FileLenght);
for (int i = 0x10; i < StreamLenght && i < FileLenght + 0x10; i++)
writer.Write(decrypted[i]);
writer.Close();
using (Stream _IO = File.OpenWriter(file, fileLength))
_IO.W(decrypted, fileLength < streamLength ? fileLength : streamLength);
}
public static void Encrypt(this string file)
{
Console.Title = "DIVAFILE Encrypt - File: " + Path.GetFileName(file);
Stream reader = File.OpenReader(file);
int FileLenghtOrigin = reader.Length;
int FileLenght = FileLenghtOrigin.Align(16);
reader.Close();
byte[] In = File.OpenReader(file).ToArray(true);
byte[] Inalign = new byte[FileLenght];
for (int i = 0; i < In.Length; i++) Inalign[i] = In[i];
In = null;
byte[] encrypted = new byte[FileLenght];
byte[] data;
using (Stream _IO = File.OpenReader(file))
data = _IO.ToArray();
int fileLengthOrigin = data.Length;
int fileLength = fileLengthOrigin.A(16);
byte[] dataAlign = new byte[fileLength];
Array.Copy(data, dataAlign, data.Length);
data = null;
byte[] encrypted = new byte[fileLength];
using (AesManaged crypto = new AesManaged())
{
crypto.Key = Key; crypto.IV = new byte[16];
crypto.Mode = CipherMode.ECB; crypto.Padding = PaddingMode.Zeros;
using (CryptoStream cryptoData = new CryptoStream(new MSIO.MemoryStream(Inalign),
crypto.CreateEncryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read))
cryptoData.Read(encrypted, 0, FileLenght);
using CryptoStream cryptoData = new CryptoStream(new MSIO.MemoryStream(dataAlign),
crypto.CreateEncryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read);
cryptoData.Read(encrypted, 0, fileLength);
}
using (Stream _IO = File.OpenWriter(file, dataAlign.Length))
{
_IO.W(0x454C494641564944);
_IO.W(fileLength);
_IO.W(fileLengthOrigin);
_IO.W(encrypted);
}
Stream writer = File.OpenWriter(file, Inalign.Length);
writer.Write(0x454C494641564944);
writer.Write(FileLenght);
writer.Write(FileLenghtOrigin);
writer.Write(encrypted);
writer.Close();
}
}
}
+131 -138
View File
@@ -1,19 +1,17 @@
using System;
using System.Net;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
namespace KKdMainLib
{
public class DataBank
public struct DataBank : IDisposable
{
public DataBank() { Success = false; IO = null; pvList = null; psrDat = null; }
private Stream IO;
private Stream _IO;
private int i;
private PvList[] pvList;
private psrData[] psrDat;
public PvList[] pvList;
public PsrData[] psrData;
private const string d = ".";
private const string c = ",";
@@ -28,115 +26,125 @@ namespace KKdMainLib
while (text.Contains("%")) text = WebUtility.UrlDecode(text);
string[] array = text.Split(',');
pvList = null;
psrData = null;
if (file.Contains("psrData") && array.Length % 13 < 2)
{
psrDat = new psrData[array.Length / 13];
for (i = 0; i < psrDat.Length; i++) psrDat[i].SetValue(array, i);
psrData = new PsrData[array.Length / 13];
for (i = 0; i < psrData.Length; i++) psrData[i].SetValue(array, i);
Success = true;
}
else if (file.Contains("psrData")) { psrDat = null; Success = true; }
else if (file.Contains("psrData")) Success = true;
else if (file.Contains("PvList") && array.Length % 7 < 2)
{
pvList = new PvList[array.Length / 7];
for (i = 0; i < pvList.Length; i++) pvList[i].SetValue(array, i);
Success = true;
}
else if (file.Contains("PvList")) { pvList = null; Success = true; }
else if (file.Contains("PvList")) Success = true;
}
public void DBWriter(string file)
public void DBWriter(string file, uint num2)
{
if (!Success) return;
IO = File.OpenWriter();
_IO = File.OpenWriter();
if (file.Contains("psrData"))
{
if (psrDat != null || psrDat.Length > 0)
for (i = 0; i < psrDat.Length; i++)
IO.Write(psrDat[i].ToString() + c);
if (psrData != null && psrData.Length > 0)
for (i = 0; i < psrData.Length; i++)
_IO.W(psrData[i].ToString() + c);
}
else if (file.Contains("PvList"))
{
if (pvList != null || pvList.Length > 0)
for (i = 0; i < pvList.Length; i++)
IO.Write(UrlEncode(pvList[i].ToString() +
(i < pvList.Length ? c : "")));
if (pvList != null && pvList.Length > 0)
{
for (i = 0; i < pvList.Length - 1; i++)
_IO.W(UrlEncode(pvList[i].ToString() + c));
_IO.W(UrlEncode(pvList[i].ToString()));
}
else _IO.W("%2A%2A%2A");
}
else IO.Write("%2A%2A%2A");
byte[] data = IO.ToArray(true);
byte[] data = _IO.ToArray(true);
ushort num = DCC.CalculateChecksum(data);
uint num2 = (uint)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
File.WriteAllBytes(file + "_" + num + "_" + num2 + ".dat", data);
}
public void MsgPackReader(string file, bool JSON)
public void MsgPackReader(string file, bool json)
{
Success = false;
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
bool compact = MsgPack.ReadBoolean("Compact");
MsgPack msgPack = file.ReadMPAllAtOnce(json);
bool compact = msgPack.RB("Compact");
psrData = null;
pvList = null;
if (file.Contains("psrData"))
{
if (MsgPack.ElementArray("psrData", out MsgPack psrData))
MsgPack psrData;
if ((psrData = msgPack["psrData", true]).NotNull)
{
psrDat = new psrData[psrData.Array.Length];
for (i = 0; i < psrDat.Length; i++)
psrDat[i].SetValue(psrData[i]);
this.psrData = new PsrData[psrData.Array.Length];
for (i = 0; i < this.psrData.Length; i++)
this.psrData[i].SetValue(psrData[i]);
}
else if (MsgPack.ContainsKey("psrData")) psrDat = null;
Success = true;
psrData.Dispose();
}
else if (file.Contains("PvList"))
{
if (MsgPack.ElementArray("PvList", out MsgPack PvList))
MsgPack pvList;
if ((pvList = msgPack["PvList", true]).NotNull)
{
pvList = new PvList[PvList.Array.Length];
for (i = 0; i < pvList.Length; i++)
pvList[i].SetValue(PvList[i], compact);
this.pvList = new PvList[pvList.Array.Length];
for (i = 0; i < this.pvList.Length; i++)
this.pvList[i].SetValue(pvList[i], compact);
}
else if (MsgPack.ContainsKey("PvList")) pvList = null;
Success = true;
pvList.Dispose();
}
MsgPack = MsgPack.New;
msgPack.Dispose();
}
public void MsgPackWriter(string file, bool JSON, bool Compact = true)
public void MsgPackWriter(string file, bool json)
{
if (!Success) return;
MsgPack msgPack = MsgPack.New;
if (file.Contains("psrData"))
{
if (psrDat != null)
if (psrData != null)
{
MsgPack psrData = new MsgPack(psrDat.Length, "psrData");
for (i = 0; i < psrDat.Length; i++) psrData[i] = psrDat[i].WriteMP();
MsgPack psrData = new MsgPack(this.psrData.Length, "psrData");
for (i = 0; i < this.psrData.Length; i++) psrData[i] = this.psrData[i].WriteMP();
msgPack.Add(psrData);
}
else msgPack.Add(new MsgPack("psrData", null));
}
else if (file.Contains("PvList"))
{
if (psrDat != null)
{
if (Compact) msgPack.Add("Compact", Compact);
if (pvList != null)
{msgPack.Add("Compact", true);
MsgPack PvList = new MsgPack(pvList.Length, "PvList");
for (i = 0; i < pvList.Length; i++) PvList[i] = pvList[i].WriteMP(Compact);
for (i = 0; i < pvList.Length; i++) PvList[i] = pvList[i].WriteMP();
msgPack.Add(PvList);
}
else msgPack.Add(new MsgPack("PvList", null));
}
msgPack.Write(file, JSON).Dispose();
msgPack.Write(file, json).Dispose();
}
public static string UrlEncode(string value) =>
WebUtility.UrlEncode(value).Replace("+", "%20");
public struct psrData
private bool disposed;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.Dispose(); psrData = null;
pvList = null; Success = false; disposed = true; } }
public struct PsrData
{
public Player p1;
public Player p2;
@@ -153,12 +161,15 @@ namespace KKdMainLib
public void SetValue(MsgPack msg)
{
int? ID = msg.ReadNInt32("PV_ID");
if (ID != null) PV_ID = (int)ID;
else { ID = msg.ReadNInt32("ID"); if (ID != null) PV_ID = (int)ID; }
if (msg.Element("P1", out MsgPack P1)) p1.SetValue(P1);
if (msg.Element("P2", out MsgPack P2)) p2.SetValue(P2);
if (msg.Element("P3", out MsgPack P3)) p3.SetValue(P3);
int? id = msg.RnI32("PV_ID");
if (id != null) PV_ID = (int)id;
else { id = msg.RnI32("ID"); if (id != null) PV_ID = (int)id; }
MsgPack temp;
if ((temp = msg["P1", true]).NotNull) p1.SetValue(temp);
if ((temp = msg["P2", true]).NotNull) p2.SetValue(temp);
if ((temp = msg["P3", true]).NotNull) p3.SetValue(temp);
temp.Dispose();
}
public MsgPack WriteMP() =>
@@ -166,7 +177,7 @@ namespace KKdMainLib
.Add(p2.WriteMP("P2")).Add(p3.WriteMP("P3"));
public override string ToString() =>
UrlEncode(p1.ToString() + c + p2.ToString() + c + p3.ToString() + c + PV_ID);
UrlEncode($"{p1.ToString()},{p2.ToString()},{p3.ToString()},{PV_ID}");
}
public struct Player
@@ -203,15 +214,15 @@ namespace KKdMainLib
public void SetValue(MsgPack msg)
{
Diff = (Difficulty)msg.ReadInt32("Diff");
Score0 = msg.ReadInt32 ("Score");
Name0 = msg.ReadString( "Name");
Diff = (Difficulty)msg.RI32("Diff");
Score0 = msg.RI32 ("Score");
Name0 = msg.RS( "Name");
if (Name0 == null)
{
Score0 = msg.ReadInt32 ("Score0");
Score1 = msg.ReadInt32 ("Score1");
Name0 = msg.ReadString( "Name0");
Name1 = msg.ReadString( "Name1");
Score0 = msg.RI32("Score0");
Score1 = msg.RI32("Score1");
Name0 = msg.RS ( "Name0");
Name1 = msg.RS ( "Name1");
}
else Name1 = null;
}
@@ -231,8 +242,8 @@ namespace KKdMainLib
public struct PvList
{
public int PV_ID;
public bool Enable;
public bool Extra;
public int Version;
public int Edition;
public Date AdvDemoStart;
public Date AdvDemoEnd;
public Date StartShow;
@@ -240,69 +251,57 @@ namespace KKdMainLib
public void SetValue(string[] data, int i = 0)
{
PV_ID = int.Parse(data[i * 7]);
Enable = int.Parse(data[i * 7 + 1]) == 1;
Extra = int.Parse(data[i * 7 + 2]) == 1;
AdvDemoStart.SetValue(data[i * 7 + 3]);
AdvDemoEnd .SetValue(data[i * 7 + 4]);
StartShow .SetValue(data[i * 7 + 5]);
EndShow .SetValue(data[i * 7 + 6]);
PV_ID = int.Parse(data[i * 7]);
Version = int.Parse(data[i * 7 + 1]);
Edition = int.Parse(data[i * 7 + 2]);
AdvDemoStart.SV(data[i * 7 + 3]);
AdvDemoEnd .SV(data[i * 7 + 4]);
StartShow .SV(data[i * 7 + 5]);
EndShow .SV(data[i * 7 + 6]);
}
public void SetValue(MsgPack msg, bool Compact)
{
MsgPack Temp = MsgPack.New;
this.Enable = true;
this.Extra = false;
Version = 1;
Edition = 0;
int? ID = msg.ReadNInt32("PV_ID");
if (ID != null) PV_ID = (int)ID;
else { ID = msg.ReadNInt32("ID"); if (ID != null) PV_ID = (int)ID; }
bool? Enable = msg.ReadNBoolean("Enable");
bool? Extra = msg.ReadNBoolean("Extra");
if (Enable != null) this.Enable = (bool)Enable;
if (Extra != null) this.Extra = (bool)Extra ;
int? id = msg.RnI32("PV_ID");
if (id != null) PV_ID = id.Value; else { id = msg.RnI32("ID"); if (id != null) PV_ID = id.Value; }
bool? enable = msg.RnB("Enable"); if (enable != null) Version = enable.Value ? 1 : 0;
bool? extra = msg.RnB("Extra" ); if (extra != null) Edition = extra .Value ? 1 : 0;
int? version = msg.RnI32("Version"); if (version != null) Version = version.Value;
int? edition = msg.RnI32("Edition"); if (edition != null) Edition = edition.Value;
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);
AdvDemoStart.SV(msg.RnI32("AdvDemoStart"), true);
AdvDemoEnd .SV(msg.RnI32("AdvDemoEnd" ), false);
StartShow .SV(msg.RnI32("StartShow" ), false);
EndShow .SV(msg.RnI32( "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);
MsgPack temp;
if ((temp = msg["AdvDemoStart", true]).NotNull) AdvDemoStart.SV(temp, true);
if ((temp = msg["AdvDemoEnd" , true]).NotNull) AdvDemoEnd .SV(temp, false);
if ((temp = msg["StartShow" , true]).NotNull) StartShow .SV(temp, false);
if ((temp = msg[ "EndShow" , true]).NotNull) EndShow .SV(temp, true);
temp.Dispose();
}
public MsgPack WriteMP(bool Compact)
public MsgPack WriteMP()
{
MsgPack msgPack = MsgPack.New;
msgPack.Add("ID", PV_ID);
if (!Enable) msgPack.Add("Enable", Enable);
if ( Extra ) msgPack.Add("Extra" , Extra );
if (Compact)
{
if (AdvDemoStart.WriteLower) msgPack.Add("AdvDemoStart", AdvDemoStart.WriteInt());
if (AdvDemoEnd .WriteLower) msgPack.Add("AdvDemoEnd" , AdvDemoEnd .WriteInt());
if (StartShow .WriteLower) msgPack.Add("StartShow" , StartShow .WriteInt());
if ( EndShow .WriteUpper) msgPack.Add( "EndShow" , EndShow .WriteInt());
}
else
{
if (AdvDemoStart.WriteLower) msgPack.Add(AdvDemoStart.WriteMP("AdvDemoStart"));
if (AdvDemoEnd .WriteLower) msgPack.Add(AdvDemoEnd .WriteMP("AdvDemoEnd" ));
if (StartShow .WriteLower) msgPack.Add(StartShow .WriteMP("StartShow" ));
if ( EndShow .WriteUpper) msgPack.Add( EndShow .WriteMP( "EndShow" ));
}
MsgPack msgPack = MsgPack.New.Add("ID" , PV_ID )
.Add("Version", Version)
.Add("Edition", Edition);
if (AdvDemoStart.WU) msgPack.Add("AdvDemoStart", AdvDemoStart.Int);
if (AdvDemoEnd .WL) msgPack.Add("AdvDemoEnd" , AdvDemoEnd .Int);
if (StartShow .WL) msgPack.Add("StartShow" , StartShow .Int);
if ( EndShow .WU) msgPack.Add( "EndShow" , EndShow .Int);
return msgPack;
}
public override string ToString() =>
UrlEncode(PV_ID + c + (Enable ? 1 : 0) + c + (Extra ? 1 : 0) + c +
AdvDemoStart.ToString() + c + AdvDemoEnd.ToString() + c +
StartShow.ToString() + c + EndShow.ToString());
UrlEncode($"{PV_ID},{Version},{Edition},{AdvDemoStart},{AdvDemoEnd},{StartShow},{EndShow}");
}
public struct Date
@@ -312,18 +311,16 @@ namespace KKdMainLib
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 bool WU => Year != 2029 || Month != 1 || Day != 1;
public bool WL => Year != 2000 || Month != 1 || Day != 1;
public void SetDefaultLower() => Year = 2000;
public void SetDefaultUpper() => Year = 2029;
public void SDL() => Year = 2000;
public void SDU() => Year = 2029;
public void SetValue(string data)
public void SV(string data)
{
string[] array = data.Split('-');
if (array.Length == 3)
@@ -334,37 +331,33 @@ namespace KKdMainLib
}
}
public void SetValue(int? YMD, bool SetDefaultUpper)
public void SV(int? ymd, bool setDefaultUpper)
{
if (!SetDefaultUpper) SetDefaultLower();
else this.SetDefaultUpper();
if (YMD != null)
if (!setDefaultUpper) SDL();
else SDU();
if (ymd != null)
{
year = YMD.Value / 10000;
month = YMD.Value / 100 % 100;
day = YMD.Value % 100;
year = ymd.Value / 10000;
month = ymd.Value / 100 % 100;
day = ymd.Value % 100;
CheckDate();
}
}
public void SetValue(MsgPack msg, bool SetDefaultUpper)
public void SV(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 (!setDefaultUpper) SDL();
else SDU();
int? Year = msg.RnI32( "Year");
int? Month = msg.RnI32("Month");
int? Day = msg.RnI32( "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);
public int Int => (Year * 100 + Month) * 100 + Day;
private void CheckDate()
{
@@ -382,7 +375,7 @@ namespace KKdMainLib
}
public override string ToString() =>
Year.ToString("d4") + "-" + Month.ToString("d2") + "-" + Day.ToString("d2");
$"{Year.ToString("d4")}-{Month.ToString("d2")}-{Day.ToString("d2")}";
}
public enum Difficulty
+242
View File
@@ -0,0 +1,242 @@
using KKdBaseLib;
using KKdBaseLib.F2;
using KKdMainLib.IO;
namespace KKdMainLib
{
public static class HeaderExtensions
{
public static Header ReadHeader(this Stream stream, bool seek, bool readSectionSignature = true)
{
if (seek)
if (stream.PI64 > 4) stream.PI64 -= 4;
else stream.PI64 = 0;
return stream.ReadHeader(readSectionSignature);
}
public static Header ReadHeader(this Stream stream, bool readSectionSignature = true)
{
Header header = new Header { Format = Format.F2LE, Signature = stream.RI32(),
DataSize = stream.RI32(), Length = stream.RI32(), Flags = stream.RI32(),
Depth = stream.RI32(), SectionSize = stream.RI32(),
Mode = stream.RI32() };
stream.RI32();
if ((header.Flags & 0x08000000) == 0x08000000) header.Format = Format.F2BE;
header.NotUseDataSizeAsSectionSize = (header.Flags & 0x10000000) != 0x10000000;
if (header.Length == 0x40)
{
stream.RI64();
stream.RI64();
header.InnerSignature = stream.RI32();
stream.RI32();
stream.RI64();
}
stream.Format = header.Format;
if (readSectionSignature) header.SectionSignature = stream.RI32E();
return header;
}
public static void W(this Stream stream, Header header, bool extended = false)
{
header.Length = (header.Format < Format.X && extended) ? 0x40 : 0x20;
header.Flags = (!header.NotUseDataSizeAsSectionSize ? 0x10000000 : 0) |
(header.Format == Format.F2BE ? 0x08000000 : 0);
stream.W(header.Signature);
stream.W(header.DataSize);
stream.W(header.Length);
stream.W(header.Flags);
stream.W(header.Depth);
stream.W(header.SectionSize);
stream.W(header.Mode);
stream.W(0x00);
if (header.Length == 0x40)
{
stream.W(header.Format < Format.MGF ? (int)((header.SectionSignature ^
(header.DataSize * (long)header.Signature)) - header.Depth + header.SectionSize) : 0);
stream.W(0x00);
stream.W(0x00L);
stream.W(header.InnerSignature);
stream.W(0x00);
stream.W(0x00L);
}
}
public static void WEOFC(this Stream stream, int depth = 0) =>
stream.W(new Header { Depth = depth, Length = 0x20, Signature = 0x43464F45 });
}
public static class POFExtensions
{
public static void W(this Stream stream, POF pof, bool shiftX = false, int depth = 0)
{
byte[] data = pof.Write(shiftX);
Header header = new Header { Depth = depth, Format = Format.F2LE,
Length = 0x20, Signature = shiftX ? 0x31464F50 : 0x30464F50 };
header.DataSize = header.SectionSize = data.Length;
stream.W(header);
stream.W(data);
}
}
public static class ENRSExtensions
{
public static void W(this Stream stream, ENRS enrs, int depth = 0)
{
byte[] data = enrs.Write();
Header header = new Header { Depth = depth, Format = Format.F2LE,
Length = 0x20, Signature = 0x53524E45 };
header.DataSize = header.SectionSize = data.Length;
stream.W(header);
stream.W(data);
}
}
public static class StructExtensions
{
public static Struct RSt(this byte[] data)
{
if (data == null || data.Length < 1) return default;
Struct @struct;
using (Stream stream = File.OpenReader(data))
@struct = stream.RSt(stream.ReadHeader(false));
return @struct;
}
public static Struct RSt(this Stream stream, Header header)
{
Struct @struct = new Struct { Header = header, DataOffset =
stream.P, Data = stream.RBy(header.SectionSize) };
int depth = header.Depth;
int lastSig = 0, sig;
long length = stream.L - stream.P;
long position = 0;
KKdList<Struct> subStructs = KKdList<Struct>.New;
while (length > position)
{
header = stream.ReadHeader(false);
sig = header.Signature;
position += header.Length + header.SectionSize;
if (sig == 0x43464F45 && header.Depth == depth + 1) break;
else if (sig == 0x53524E45 || (sig & 0xF0FFFFFF) == 0x30464F50)
{
byte[] Data = stream.RBy(header.SectionSize);
if (sig == 0x53524E45) @struct.ENRS.Read(Data);
else @struct.POF .Read(Data, sig == 0x31464F50);
}
else if (header.Depth == 0 && sig == 0x43505854)
{ subStructs.Add(new Struct { Header = header, DataOffset =
stream.P, Data = stream.RBy(header.SectionSize) }); }
else if (header.Depth <= depth) { stream.PI64 -= header.Length; break; }
else subStructs.Add(stream.RSt(header));
lastSig = sig;
}
if (subStructs.Capacity > 0) @struct.SubStructs = subStructs.ToArray();
return @struct;
}
public static byte[] W(this Struct Struct, bool shiftX = false, bool useDepth = true)
{
byte[] Data;
using (Stream stream = File.OpenWriter()) { Struct.Update(shiftX);
stream.W(Struct, shiftX, useDepth); stream.WEOFC(); Data = stream.ToArray(); }
return Data;
}
public static void W(this Stream stream, Struct @struct, bool shiftX = false, bool useDepth = true)
{
stream.W(@struct.Header);
stream.W(@struct.Data );
if (@struct.HasPOF ) stream.W(@struct.POF , shiftX, useDepth ? @struct.Depth + 1 : 0);
if (@struct.HasENRS) stream.W(@struct.ENRS, useDepth ? @struct.Depth + 1 : 0);
if (@struct.HasSubStructs)
{
for (int i = 0; i < @struct.SubStructs.Length; i++)
stream.W(@struct.SubStructs[i], shiftX);
stream.WEOFC(@struct.Depth + 1);
}
}
}
public static class MPExt
{
public static MsgPack ReadMP(this byte[] array, bool json = false)
{
MsgPack MsgPack;
if (json) using (JSON _IO = new JSON(File.OpenReader(array))) MsgPack = _IO.Read( );
else using ( MP _IO = new MP(File.OpenReader(array))) MsgPack = _IO.Read(true);
return MsgPack;
}
public static MsgPack ReadMPAllAtOnce(this string file, bool json = false)
{
MsgPack MsgPack;
if (json) using (JSON _IO = new JSON(File.OpenReader(file + ".json", true))) MsgPack = _IO.Read( );
else using ( MP _IO = new MP(File.OpenReader(file + ".mp" , true))) MsgPack = _IO.Read(true);
return MsgPack;
}
public static MsgPack ReadMP(this string file, bool json = false)
{
MsgPack MsgPack;
if (json) using (JSON _IO = new JSON(File.OpenReader(file + ".json"))) MsgPack = _IO.Read( );
else using ( MP _IO = new MP(File.OpenReader(file + ".mp" ))) MsgPack = _IO.Read(true);
return MsgPack;
}
public static void Write(this MsgPack mp, bool temp, string file, bool json = false)
{ if (temp) MsgPack.New.Add(mp).Write(file, json).Dispose();
else mp .Write(file, json); }
public static MsgPack Write(this MsgPack mp, string file, bool json = false)
{
if (json) using (JSON _IO = new JSON(File.OpenWriter(file + ".json", true))) _IO.W(mp, "\n", " ");
else using ( MP _IO = new MP(File.OpenWriter(file + ".mp" , true))) _IO.W(mp);
return mp;
}
public static void WriteAfterAll(this MsgPack mp, bool temp, string file, bool json = false)
{ if (temp) MsgPack.New.Add(mp).WriteAfterAll(file, json).Dispose();
else mp .WriteAfterAll(file, json); }
public static MsgPack WriteAfterAll(this MsgPack mp, string file, bool json = false)
{
byte[] data = null;
if (json) using (JSON _IO = new JSON(File.OpenWriter())) { _IO.W(mp, true); data = _IO.ToArray(); }
else using ( MP _IO = new MP(File.OpenWriter())) { _IO.W(mp ); data = _IO.ToArray(); }
File.WriteAllBytes(file + (json ? ".json" : ".mp"), data);
return mp;
}
public static void ToJSON (this string file) =>
file.ReadMP( ).Write(file, true).Dispose();
public static void ToMsgPack(this string file) =>
file.ReadMP(true).Write(file ).Dispose();
}
public static class IKFExt
{
public static IKF Round(this IKF kf, int d)
{
if (kf is KFT0 kft0) { kft0.F = kft0.F .Round(d); return kft0; }
else if (kf is KFT1 kft1) { kft1.F = kft1.F .Round(d); kft1.V = kft1.V .Round(d); return kft1; }
else if (kf is KFT2 kft2) { kft2.F = kft2.F .Round(d); kft2.V = kft2.V .Round(d);
kft2.T = kft2.T .Round(d); return kft2; }
else if (kf is KFT3 kft3) { kft3.F = kft3.F .Round(d); kft3.V = kft3.V .Round(d);
kft3.T1 = kft3.T1.Round(d); kft3.T2 = kft3.T2.Round(d); return kft3; }
return kf;
}
}
public static class LibDeflate
{
public static void Extract()
{
if (!File.Exists("libdeflate.dll"))
File.WriteAllBytes("libdeflate.dll", Properties.Resources.libdeflate);
}
}
}
+76
View File
@@ -0,0 +1,76 @@
using KKdBaseLib;
using KKdBaseLib.F2;
using KKdMainLib.IO;
namespace KKdMainLib.F2
{
public struct Bloom : System.IDisposable
{
private int i;
private Stream _IO;
private Header header;
public CountPointer<BLT> BLTs;
public void BLTReader(string file)
{
BLTs = default;
_IO = File.OpenReader(file + ".blt", true);
header = _IO.ReadHeader();
if (header.Signature != 0x544D4C42 || header.InnerSignature != 0x3) return;
_IO.P -= 0x4;
BLTs = _IO.RCPE<BLT>();
if (BLTs.C < 1) { _IO.C(); BLTs.C = -1; return; }
if (BLTs.C > 0 && BLTs.O == 0) { _IO.C(); BLTs.C = -1; return; }
/*{
_IO.Format = Header.Format = Format.X;
_IO.Offset = Header.Length;
_IO.Position = BLTs.Offset;
BLTs = _IO.ReadCountPointerX<BLT>();
}*/
_IO.P = BLTs.O;
for (i = 0; i < BLTs.C; i++)
{
ref BLT blt = ref BLTs.E[i];
_IO.RI32E();
blt.Color .X = _IO.RF32E();
blt.Color .Y = _IO.RF32E();
blt.Color .Z = _IO.RF32E();
blt.Brightpass.X = _IO.RF32E();
blt.Brightpass.Y = _IO.RF32E();
blt.Brightpass.Z = _IO.RF32E();
blt.Range = _IO.RF32E();
}
_IO.C();
}
public void TXTWriter(string file)
{
if (BLTs.C < 1) return;
_IO = File.OpenWriter();
_IO.WPSSJIS("ID,ColorR,ColorG,ColorB,BrightpassR,BrightpassG,BrightpassB,Range\n");
for (i = 0; i < BLTs.C; i++)
_IO.W(i + "," + BLTs[i] + "\n");
File.WriteAllBytes(file + "_bloom.txt", _IO.ToArray(true));
}
private bool disposed;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.Dispose(); BLTs = default; header = default; disposed = true; } }
public struct BLT
{
public Vector3 Color;
public Vector3 Brightpass;
public float Range;
public override string ToString() => Color .ToString(6) + "," +
Brightpass.ToString(6) + "," +
Range .ToS(6);
}
}
}
+84
View File
@@ -0,0 +1,84 @@
using KKdBaseLib;
using KKdBaseLib.F2;
using KKdMainLib.IO;
namespace KKdMainLib.F2
{
public struct ColorCorrection : System.IDisposable
{
private int i;
private Stream _IO;
private Header header;
public CountPointer<CCT> CCTs;
public void CCTReader(string file)
{
CCTs = default;
_IO = File.OpenReader(file + ".cct", true);
header = _IO.ReadHeader();
if (header.Signature != 0x54524343 || header.InnerSignature != 0x3) return;
_IO.P -= 0x4;
CCTs = _IO.RCPE<CCT>();
if (CCTs.C < 1) { _IO.C(); CCTs.C = -1; return; }
if (CCTs.C > 0 && CCTs.O == 0) { _IO.C(); CCTs.C = -1; return; }
/*{
_IO.Format = Header.Format = Format.X;
_IO.Offset = Header.Length;
_IO.Position = CCTs.Offset;
CCTs = _IO.ReadCountPointerX<CCT>();
}*/
_IO.P = CCTs.O;
for (i = 0; i < CCTs.C; i++)
{
ref CCT cct = ref CCTs.E[i];
_IO.RI32E();
cct.Hue = _IO.RF32E();
cct.Saturation = _IO.RF32E();
cct.Lightness = _IO.RF32E();
cct.Exposure = _IO.RF32E();
cct.Gamma.X = _IO.RF32E();
cct.Gamma.Y = _IO.RF32E();
cct.Gamma.Z = _IO.RF32E();
cct.Contrast = _IO.RF32E();
}
_IO.C();
}
public void TXTWriter(string file)
{
if (CCTs.C < 1) return;
_IO = File.OpenWriter();
_IO.WPSSJIS("ID,Hue,Saturation,Lightness,Exposure,GammaR,GammaG,GammaB,Contrast\n");
for (i = 0; i < CCTs.C; i++)
_IO.W(i + "," + CCTs[i] + "\n");
File.WriteAllBytes(file + "_cc.txt", _IO.ToArray(true));
}
private bool disposed;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.Dispose(); CCTs = default; header = default; disposed = true; } }
public struct CCT
{
public float Hue;
public float Saturation;
public float Lightness;
public float Exposure;
public Vector3 Gamma;
public float Contrast;
public override string ToString() => Hue .ToS(6) + "," +
Saturation.ToS(6) + "," +
Lightness .ToS(6) + "," +
Exposure .ToS(6) + "," +
Gamma .ToString(6) + "," +
Contrast .ToS(6);
}
}
}
+80
View File
@@ -0,0 +1,80 @@
using KKdBaseLib;
using KKdBaseLib.F2;
using KKdMainLib.IO;
namespace KKdMainLib.F2
{
public struct DOF : System.IDisposable
{
private int i;
private Stream _IO;
private Header header;
public CountPointer<DFT> DFTs;
public void DFTReader(string file)
{
DFTs = default;
_IO = File.OpenReader(file + ".dft", true);
header = _IO.ReadHeader();
if (header.Signature != 0x54464F44 || header.InnerSignature != 0x3) return;
_IO.P -= 0x4;
DFTs = _IO.RCPE<DFT>();
if (DFTs.C < 1) { _IO.C(); DFTs.C = -1; return; }
if (DFTs.C > 0 && DFTs.O == 0) { _IO.C(); DFTs.C = -1; return; }
/*{
_IO.Format = Header.Format = Format.X;
_IO.Offset = Header.Length;
_IO.Position = DFTs.Offset;
DFTs = _IO.ReadCountPointerX<DFT>();
}*/
_IO.P = DFTs.O;
for (i = 0; i < DFTs.C; i++)
{
ref DFT DFT = ref DFTs.E[i];
_IO.RI32E();
DFT. Focus = _IO.RF32E();
DFT. FocusRange = _IO.RF32E();
DFT.FuzzingRange = _IO.RF32E();
DFT.Ratio = _IO.RF32E();
DFT.Quality = _IO.RF32E();
if (_IO.IsX) _IO.RI32();
}
_IO.C();
}
public void TXTWriter(string file)
{
if (DFTs.C < 1) return;
_IO = File.OpenWriter();
_IO.WPSSJIS("ID,Focus,FocusRange,FuzzingRange,Ratio,Quality\n");
for (i = 0; i < DFTs.C; i++)
_IO.W(i + "," + DFTs[i] + "\n");
File.WriteAllBytes(file + "_dof.txt", _IO.ToArray(true));
}
private bool disposed;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.Dispose(); DFTs = default; header = default; disposed = true; } }
public struct DFT
{
public float Focus;
public float FocusRange;
public float FuzzingRange;
public float Ratio;
public float Quality;
public override string ToString() => Focus .ToS(6) + "," +
FocusRange.ToS(6) + "," +
FuzzingRange.ToS(6) + "," +
Ratio .ToS(6) + "," +
Quality .ToS(6);
}
}
}
+142
View File
@@ -0,0 +1,142 @@
using KKdBaseLib;
using KKdBaseLib.F2;
using KKdMainLib.IO;
namespace KKdMainLib.F2
{
public struct Light : System.IDisposable
{
private int i, i0;
private Stream _IO;
private Header header;
public CountPointer<CountPointer<LIT>> LITs;
public void LITReader(string file)
{
LITs = default;
_IO = File.OpenReader(file + ".lit", true);
header = _IO.ReadHeader();
if (header.Signature != 0x4354494C || header.InnerSignature != 0x2 ||
header.SectionSignature != 0x2) return;
LITs = _IO.RCPE<CountPointer<LIT>>();
if (LITs.C < 1) { _IO.C(); LITs.C = -1; return; }
_IO.P = LITs.O;
for (i = 0; i < LITs.C; i++)
{
LITs[i] = _IO.RCPX<LIT>();
if ((LITs[i].C > 0 || LITs[i].O == 0) && !_IO.IsX) { _IO.C(); LITs.C = -1; return; }
/*{
_IO.Format = Header.Format = Format.X;
_IO.Offset = Header.Length;
_IO.Position = LITs.Offset;
LITs[i] = _IO.ReadCountPointerX<LIT>();
}
if (_IO.IsX) IO.ReadInt64();*/
}
for (i = 0; i < LITs.C; i++)
{
_IO.P = LITs[i].O;
for (i0 = 0; i0 < LITs[i].C; i0++)
{
ref LIT lit = ref LITs.E[i].E[i0];
lit.Id = (Id )_IO.RI32E();
lit.Flags = (Flags)_IO.RI32E();
lit.Type = (Type )_IO.RI32E();
if (_IO.IsX) { _IO.RI64(); _IO.RI64(); _IO.RI64(); }
lit.Ambient .X = _IO.RF32E();
lit.Ambient .Y = _IO.RF32E();
lit.Ambient .Z = _IO.RF32E();
lit.Ambient .W = _IO.RF32E();
lit.Diffuse .X = _IO.RF32E();
lit.Diffuse .Y = _IO.RF32E();
lit.Diffuse .Z = _IO.RF32E();
lit.Diffuse .W = _IO.RF32E();
lit.Specular .X = _IO.RF32E();
lit.Specular .Y = _IO.RF32E();
lit.Specular .Z = _IO.RF32E();
lit.Specular .W = _IO.RF32E();
lit.Position .X = _IO.RF32E();
lit.Position .Y = _IO.RF32E();
lit.Position .Z = _IO.RF32E();
lit.ToneCurve.X = _IO.RF32E();
lit.ToneCurve.Y = _IO.RF32E();
lit.ToneCurve.Z = _IO.RF32E();
if (_IO.IsX) { _IO.RI64(); _IO.RI64(); _IO.RI64();
_IO.RI64(); _IO.RI64(); _IO.RI32(); }
}
}
_IO.C();
}
public void TXTWriter(string file)
{
i = 0;
if (LITs.C < 1) return;
_IO = File.OpenWriter();
_IO.WPSSJIS("Type,AmbientR,AmbientG,AmbientB,DiffuseR,DiffuseG,DiffuseB,SpecularR,SpecularG," +
"SpecularB,SpecularA,PosX,PosY,PosZ,ToneCurveBegin,ToneCurveEnd,ToneCurveBlendRate," +
(file.EndsWith("_chara") ? "コメント" : "ID") + "\n");
for (i0 = 0; i0 < LITs[i].C; i0++)
_IO.W(LITs[i][i0] + "," + i + "\n");
File.WriteAllBytes(file + "_light.txt", _IO.ToArray(true));
}
public struct LIT
{
public Id Id;
public Flags Flags;
public Type Type;
public Vector4 Ambient;
public Vector4 Diffuse;
public Vector4 Specular;
public Vector3 Position;
public Vector3 ToneCurve;
public override string ToString() => Flags == 0 ? ",,,,,,,,,,,,,,,," : Type + "," +
((Flags & Flags.Ambient ) == 0 ? ",,," : Ambient .ToString(6) + ",") +
((Flags & Flags.Diffuse ) == 0 ? ",,," : Diffuse .ToString(6) + ",") +
((Flags & Flags.Specular ) == 0 ? ",,,," : Specular .ToString(6) + ",") +
((Flags & Flags.Position ) == 0 ? ",,," : Position .ToString(6) + ",") +
((Flags & Flags.ToneCurve) == 0 ? ",,," : ToneCurve.ToString(6));
}
private bool disposed;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.Dispose(); LITs = default; header = default; disposed = true; } }
public enum Id : int
{
CHARA = 0,
STAGE = 1,
SUN = 2,
REFLECT = 3,
SHADOW = 4,
CHARA_COLOR = 5,
CHARA_F = 6,
PROJECTION = 7,
}
public enum Type : int
{
OFF = 0,
PARALLEL = 1,
POINT = 2,
SPOT = 3,
}
public enum Flags : int
{
Type = 0b0000000001,
Ambient = 0b0000000010,
Diffuse = 0b0000000100,
Specular = 0b0000001000,
Position = 0b0000010000,
ToneCurve = 0b1000000000,
}
}
}
+194 -178
View File
@@ -2,42 +2,42 @@
using System.IO.Compression;
using System.Security.Cryptography;
using KKdBaseLib;
using KKdMainLib.IO;
using MSIO = System.IO;
namespace KKdMainLib
{
public class FARC
public class FARC : System.IDisposable
{
public FARC() => NewFARC();
public FARC(string File, bool IsDirectory = false)
{ if (IsDirectory) DirectoryPath = File; else FilePath = File; NewFARC(); }
public FARC(string file, bool isDirectory = false)
{ if (isDirectory) DirectoryPath = file; else FilePath = file; NewFARC(); }
private void NewFARC() { Files = null; Signature = Farc.FArC; CBC = FT = false; }
private void NewFARC() { if (!MSIO.File.Exists("libdeflate.dll"))
File.WriteAllBytes("libdeflate.dll", Properties.Resources.libdeflate);
Files = KKdList<FARCFile>.New; Signature = Farc.FArC; Format = Format.DT; }
public FARCFile[] Files = null;
public KKdList<FARCFile> Files = KKdList<FARCFile>.New;
public Type FARCType;
public Farc Signature = Farc.FArC;
public Format Format = Format.DT;
public string FilePath, DirectoryPath;
public bool HasFiles => Files == null ? false : Files.Length > 0;
public bool HasFiles => Files.IsNull ? false : Files.Count > 0;
public int CompressionLevel = 12;
private bool CBC, FT;
private readonly byte[] key = Text.ToASCII("project_diva.bin");
private readonly byte[] Key = Text.ToASCII("project_diva.bin");
private readonly byte[] KeyFT = { 0x13, 0x72, 0xD5, 0x7B, 0x6E, 0x9E,
private readonly byte[] keyFT = { 0x13, 0x72, 0xD5, 0x7B, 0x6E, 0x9E,
0x31, 0xEB, 0xA2, 0x39, 0xB8, 0x3C, 0x15, 0x57, 0xC6, 0xBB };
AesManaged GetAes(bool isFT, byte[] iv)
{
AesManaged AesManaged = new AesManaged { KeySize = 128, Key = isFT ? KeyFT : Key,
private AesManaged GetAes(bool isFT, byte[] iv) =>
new AesManaged () { KeySize = 128, Key = isFT ? keyFT : key,
BlockSize = 128, Mode = isFT ? CipherMode.CBC : CipherMode.ECB,
Padding = PaddingMode.Zeros, IV = iv ?? new byte[16] };
return AesManaged;
}
public void UnPack(bool SaveToDisk = true)
{ if (HeaderReader()) { FileReader(); if (SaveToDisk) this.SaveToDisk(); } }
public void Unpack(bool saveToDisk = true)
{ if (HeaderReader()) { FileReader(); if (saveToDisk) SaveToDisk(); } }
public bool HeaderReader()
{
@@ -46,268 +46,284 @@ namespace KKdMainLib
Stream reader = File.OpenReader(FilePath);
DirectoryPath = Path.GetFullPath(FilePath).Replace(Path.GetExtension(FilePath), "");
Signature = (Farc)reader.ReadInt32Endian(true);
Signature = (Farc)reader.RI32E(true);
if (Signature != Farc.FArc && Signature != Farc.FArC && Signature != Farc.FARC)
{ reader.Close(); return false; }
{ reader.Dispose(); return false; }
int HeaderLength = reader.ReadInt32Endian(true);
int headerLength = reader.RI32E(true);
if (Signature == Farc.FARC)
{
FARCType = (Type)reader.ReadInt32Endian(true);
reader.ReadInt32();
FARCType = (Type)reader.RI32E(true);
reader.RI32();
int farcMode = reader.RI32E(true);
int FARCMode = reader.ReadInt32Endian(true);
FT = FARCMode == 0x10;
CBC = FARCMode != 0x10 && FARCMode != 0x40;
Format = (FARCType & Type.ECB) != 0 && (farcMode & (farcMode - 1)) != 0 ? Format.FT : Format.DT;
if (CBC && FARCType.HasFlag(Type.ECB))
if (Format == Format.FT && (FARCType & Type.ECB) != 0)
{
reader.Close();
byte[] Header = new byte[HeaderLength - 0x08];
reader.Dispose();
byte[] header = new byte[headerLength - 0x08];
MSIO.FileStream stream = new MSIO.FileStream(FilePath, MSIO.FileMode.Open,
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite) { Position = 0x10 };
using (AesManaged aes = GetAes(true, null))
using (CryptoStream cryptoStream = new CryptoStream(stream,
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
cryptoStream.Read(Header, 0x00, HeaderLength - 0x08);
Header = SkipData(Header, 0x10);
reader = File.OpenReader(Header);
aes.CreateDecryptor(), CryptoStreamMode.Read))
cryptoStream.Read(header, 0x00, headerLength - 0x08);
header = SkipData(header, 0x10);
reader = File.OpenReader(header);
FARCMode = reader.ReadInt32Endian(true);
FT = FARCMode == 0x10;
farcMode = reader.RI32E(true);
}
}
if (Signature == Farc.FARC)
if (reader.ReadInt32Endian(true) == 1)
Files = new FARCFile[reader.ReadInt32Endian(true)];
reader.ReadInt32();
if (reader.RI32E(true) == 1)
Files.Capacity = reader.RI32E(true);
reader.RI32();
if (Files == null)
if (Files.Capacity == 0)
{
int Count = 0;
long Position = reader.LongPosition;
while (reader.LongPosition < HeaderLength)
long Position = reader.PI64;
while (reader.PI64 < headerLength)
{
reader.NullTerminated();
reader.ReadInt32();
if (Signature != Farc.FArc ) reader.ReadInt32();
reader.ReadInt32();
if (Signature == Farc.FARC && FT) reader.ReadInt32();
reader.NT();
reader.RI32();
if (Signature != Farc.FArc) reader.RI32();
reader.RI32();
if (Signature == Farc.FARC && Format == Format.FT) reader.RI32();
Count++;
}
reader.LongPosition = Position;
Files = new FARCFile[Count];
reader.PI64 = Position;
Files.Capacity = Count;
}
for (int i = 0; i < Files.Length; i++)
for (int i = 0; i < Files.Capacity; i++)
{
Files[i].Name = reader.NullTerminatedUTF8();
Files[i].Offset = reader.ReadInt32Endian(true);
if (Signature != Farc.FArc) Files[i].SizeComp = reader.ReadInt32Endian(true);
Files[i].SizeUnc = reader.ReadInt32Endian(true);
if (Signature == Farc.FARC && FT)
Files[i].Type = (Type)reader.ReadInt32Endian(true);
FARCFile file = default;
file.Name = reader.NTUTF8();
file.Offset = reader.RI32E(true);
if (Signature != Farc.FArc) file.SizeComp = reader.RI32E(true);
file.SizeUnc = reader.RI32E(true);
if (Signature == Farc.FARC && Format == Format.FT)
file.Type = (Type)reader.RI32E(true);
Files.Add(file);
}
reader.Close();
reader.Dispose();
return true;
}
private void FileReader()
{ for (int i = 0; i < Files.Length; i++) FileReader(i); }
{ for (int i = 0; i < Files.Count; i++) FileReader(i); }
public byte[] FileReader(string file)
{
if (!HasFiles) return null;
for (int i = 0; i < Files.Count; i++)
if (Files[i].Name.ToLower() == file.ToLower()) return FileReader(i);
return null;
}
public bool Exists(string file)
{
if (!HasFiles) return false;
for (int i = 0; i < Files.Count; i++)
if (Files[i].Name.ToLower() == file.ToLower()) return true;
return false;
}
public byte[] FileReader(int i)
{
if (!HasFiles) return null;
if (i >= Files.Length) return null;
if (i >= Files.Count) return null;
FARCFile file = Files[i];
if (Signature != Farc.FARC)
{
if (Signature == Farc.FArC)
using (MSIO.MemoryStream memorystream = new MSIO.MemoryStream(
File.ReadAllBytes(FilePath, Files[i].SizeComp, Files[i].Offset)))
File.ReadAllBytes(FilePath, file.SizeComp, file.Offset)))
using (GZipStream gZipStream = new GZipStream(memorystream, CompressionMode.Decompress))
{
GZipStream gZipStream = new GZipStream(memorystream, CompressionMode.Decompress);
Files[i].Data = new byte[Files[i].SizeUnc];
gZipStream.Read(Files[i].Data, 0, Files[i].SizeUnc);
file.Data = new byte[file.SizeUnc];
gZipStream.Read(file.Data, 0, file.SizeUnc);
}
else Files[i].Data = File.ReadAllBytes(FilePath, Files[i].SizeUnc, Files[i].Offset);
return Files[i].Data;
else file.Data = File.ReadAllBytes(FilePath, file.SizeUnc, file.Offset);
Files[i] = file;
return file.Data;
}
int FileSize = FARCType.HasFlag(Type.ECB) || Files[i].Type.HasFlag(Type.ECB) ?
Files[i].SizeComp.Align(0x10) : Files[i].SizeComp;
MSIO.FileStream stream = new MSIO.FileStream(FilePath, MSIO.FileMode.Open,
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite);
stream.Seek(Files[i].Offset, 0);
Files[i].Data = new byte[FileSize];
bool Encrypted = false;
if (FARCType.HasFlag(Type.ECB))
int FileSize = (FARCType & Type.ECB) != 0 || (file.Type & Type.ECB) != 0 ?
file.SizeComp.A(0x10) : ((FARCType & Type.GZip) != 0 || (file.Type & Type.GZip) != 0 ? file.SizeComp : file.SizeUnc);
using (Stream stream = File.OpenReader(FilePath))
{
if ((FT && Files[i].Type.HasFlag(Type.ECB)) || CBC)
stream.S(file.Offset, 0);
file.Data = stream.RBy(FileSize);
}
if ((FARCType & Type.ECB) != 0)
{
if (Format == Format.FT && (file.Type & Type.ECB) != 0)
{
using (CryptoStream cryptoStream = new CryptoStream(stream,
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
cryptoStream.Read(Files[i].Data, 0, FileSize);
Files[i].Data = SkipData(Files[i].Data, 0x10);
using (AesManaged aes = GetAes(true, null))
using (CryptoStream cryptoStream = new CryptoStream(new MSIO.MemoryStream(file.Data),
aes.CreateDecryptor(), CryptoStreamMode.Read))
cryptoStream.Read(file.Data, 0, FileSize);
file.Data = SkipData(file.Data, 0x10);
}
else
using (CryptoStream cryptoStream = new CryptoStream(stream,
GetAes(false, null).CreateDecryptor(), CryptoStreamMode.Read))
cryptoStream.Read(Files[i].Data, 0, FileSize);
Encrypted = true;
using (AesManaged aes = GetAes(false, null))
using (CryptoStream cryptoStream = new CryptoStream(new MSIO.MemoryStream(file.Data),
aes.CreateDecryptor(), CryptoStreamMode.Read))
cryptoStream.Read(file.Data, 0, FileSize);
}
if (((Format == Format.FT && (file.Type & Type.GZip) != 0) ||
(FARCType & Type.GZip) != 0) && file.SizeUnc > 0)
file.Data = file.Data.InflateGZip(file.SizeUnc);
bool Compressed = false;
if (((FT && Files[i].Type.HasFlag(Type.GZip)) ||
FARCType.HasFlag(Type.GZip)) && Files[i].SizeUnc > 0)
{
GZipStream gZipStream;
if (Encrypted) { gZipStream = new GZipStream(new MSIO.MemoryStream(Files[i].Data),
CompressionMode.Decompress); stream.Close(); }
else gZipStream = new GZipStream(stream, CompressionMode.Decompress);
byte[] Temp = new byte[Files[i].SizeUnc];
gZipStream.Read(Temp, 0, Files[i].SizeUnc);
Files[i].Data = Temp;
Compressed = true;
}
if (!Encrypted && !Compressed)
{
Files[i].Data = new byte[Files[i].SizeUnc];
stream.Read(Files[i].Data, 0, Files[i].SizeUnc);
stream.Close();
}
return Files[i].Data;
Files[i] = file;
return file.Data;
}
private void SaveToDisk()
{
if (DirectoryPath == null || Files == null) return;
if (DirectoryPath == "" || Files.Length < 1) return;
if (DirectoryPath == null || Files.IsNull ) return;
if (DirectoryPath == "" || Files.Count < 1) return;
MSIO.Directory.CreateDirectory(DirectoryPath);
for (int i = 0; i < Files.Length; i++)
for (int i = 0; i < Files.Count; i++)
{
if (Files[i].Data != null)
File.WriteAllBytes(Path.Combine(DirectoryPath, Files[i].Name), Files[i].Data);
Files[i].Data = null;
FARCFile file = Files[i];
if (file.Data != null)
File.WriteAllBytes(Path.Combine(DirectoryPath, file.Name), file.Data);
}
}
private byte[] SkipData(byte[] Data, int Skip)
private byte[] SkipData(byte[] data, int skip)
{
byte[] SkipData = new byte[Data.Length - Skip];
for (int i = 0; i < Data.Length - Skip; i++) SkipData[i] = Data[i + Skip];
return SkipData;
byte[] skipData = new byte[data.Length - skip];
System.Array.Copy(data, skip, skipData, 0, data.Length - skip);
return skipData;
}
public void Pack()
public void Pack(Farc signature = Farc.FArC)
{
NewFARC();
string[] files = Directory.GetFiles(DirectoryPath);
Files = new FARCFile[files.Length];
Files.Capacity = files.Length;
for (int i = 0; i < files.Length; i++)
Files[i] = new FARCFile { Name = Path.GetFileName(files[i]), Data = File.ReadAllBytes(files[i]) };
Files.Add(new FARCFile { Name = Path.GetFileName(files[i]), Data = File.ReadAllBytes(files[i]) });
files = null;
Signature = signature;
Save();
}
public void Save()
{
for (int i = 0; i < Files.Length; i++)
if (!HasFiles) return;
for (int i = 0; i < Files.Count; i++)
{
string ext = Path.GetExtension(Files[i].Name).ToLower();
if (ext == ".a3da" || ext == ".diva" || ext == ".vag") Signature = Farc.FArc;
if (ext == ".a3da" || ext == ".diva" || ext == ".vag")
{ Signature = Farc.FArc; break; }
}
Stream writer = File.OpenWriter(DirectoryPath + ".farc", true);
writer.WriteEndian((int)Signature, true);
writer.WE((int)Signature, true);
Stream HeaderWriter = File.OpenWriter();
if (Signature == Farc.FArc) HeaderWriter.WriteEndian(0x20, true);
else if (Signature == Farc.FArC) HeaderWriter.WriteEndian(0x10, true);
else if (Signature == Farc.FARC)
using (Stream headerWriter = File.OpenWriter())
{
HeaderWriter.WriteEndian((int)FARCType, true);
HeaderWriter.Write (0x00);
HeaderWriter.WriteEndian(0x40, true);
HeaderWriter.Write (0x00);
}
int HeaderPartLength = Signature == Farc.FArc ? 0x09 : 0x0D;
for (int i = 0; i < Files.Length; i++)
HeaderWriter.Length += Path.GetFileName(Files[i].Name).Length + HeaderPartLength;
writer.WriteEndian(HeaderWriter.Length, true);
writer.Write(HeaderWriter.ToArray(true));
HeaderWriter = null;
int Align = writer.Position.Align(0x10) - writer.Position;
for (int i1 = 0; i1 < Align; i1++)
writer.WriteByte((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
for (int i = 0; i < Files.Length; i++)
CompressStuff(i, ref Files, ref writer);
writer.Position = Signature == Farc.FARC ? 0x1C : 0x0C;
for (int i = 0; i < Files.Length; i++)
{
writer.Write(Path.GetFileName(Files[i].Name) + "\0");
writer.WriteEndian(Files[i].Offset, true);
if (Signature == Farc.FArc) headerWriter.WE(0x20, true);
else if (Signature == Farc.FArC) headerWriter.WE(0x10, true);
else if (Signature == Farc.FARC)
{
headerWriter.WE((int)FARCType, true);
headerWriter.W (0x00);
headerWriter.WE(0x40, true);
headerWriter.W (0x00);
headerWriter.W (0x00);
}
if (Signature != Farc.FArc)
writer.WriteEndian(Files[i].SizeComp, true);
writer.WriteEndian(Files[i].SizeUnc, true);
for (int i = 0; i < Files.Count; i++)
{ headerWriter.W(Files[i].Name + "\0"); headerWriter.W(0x00L); headerWriter.W(0x00); }
else
for (int i = 0; i < Files.Count; i++)
{ headerWriter.W(Files[i].Name + "\0"); headerWriter.W(0x00L); }
writer.WE(headerWriter.L, true);
writer.W (headerWriter.ToArray(true));
}
writer.Close();
int align = writer.P.A(0x10) - writer.P;
for (int i1 = 0; i1 < align; i1++)
writer.W((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
writer.F();
for (int i = 0; i < Files.Count; i++)
CompressStuff(i, ref writer);
writer.P = Signature == Farc.FARC ? 0x1C : 0x0C;
for (int i = 0; i < Files.Count; i++)
{
FARCFile file = Files[i];
writer.W (file.Name + "\0");
writer.WE(file.Offset, true);
if (Signature != Farc.FArc) writer.WE(file.SizeComp, true);
writer.WE(file.SizeUnc, true);
}
writer.Dispose();
}
private void CompressStuff(int i, ref FARCFile[] Files, ref Stream writer)
private void CompressStuff(int i, ref Stream writer)
{
Files[i].Offset = writer.Position;
Files[i].SizeUnc = Files[i].Data.Length;
Files[i].Type = Type.None;
FARCFile file = Files[i];
file.Offset = writer.P;
file.SizeUnc = file.Data.Length;
file.Type = Type.None;
if (Signature == Farc.FArC || (Signature == Farc.FARC && FARCType.HasFlag(Type.GZip)))
byte[] data = file.Data;
if (Signature == Farc.FArC || (Signature == Farc.FARC && (FARCType & Type.GZip) != 0))
{
Files[i].Type |= Type.GZip;
MSIO.MemoryStream stream = new MSIO.MemoryStream();
using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Compress))
gZipStream.Write(Files[i].Data, 0, Files[i].Data.Length);
Files[i].Data = stream.ToArray();
stream.Dispose();
Files[i].SizeComp = Files[i].Data.Length;
file.Type |= Type.GZip;
data = file.Data.DeflateGZip(CompressionLevel);
file.SizeComp = data.Length;
}
if (Signature == Farc.FARC && FARCType.HasFlag(Type.ECB))
if (Signature == Farc.FARC && (FARCType & Type.ECB) != 0)
{
int AlignData = Files[i].Data.Length.Align(0x40);
byte[] Data = new byte[AlignData];
for (int i1 = 0; i1 < AlignData ; i1++) Data[i1] = 0x78;
for (int i1 = 0; i1 < Files[i].Data.Length; i1++) Data[i1] = Files[i].Data[i1];
Files[i].Data = Encrypt(Data, false);
int alignLength = data.Length.A(0x40);
byte[] tempData = new byte[alignLength];
System.Array.Copy(data, tempData, data.Length);
for (int i1 = file.Data.Length; i1 < alignLength; i1++) tempData[i1] = 0x78;
data = Encrypt(tempData, false);
file.SizeComp = data.Length;
}
writer.Write(Files[i].Data);
Files[i].Data = null;
writer.W(data);
if (Signature != Farc.FARC)
{
int Align = writer.Position.Align(0x20) - writer.Position;
int Align = writer.P.A(0x10) - writer.P;
for (int i1 = 0; i1 < Align; i1++)
writer.WriteByte((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
writer.W((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
}
Files[i] = file;
}
private byte[] Encrypt(byte[] Data, bool isFT)
private byte[] Encrypt(byte[] data, bool isFT)
{
MSIO.MemoryStream stream = new MSIO.MemoryStream();
using (AesManaged aes = GetAes(isFT, null))
using (CryptoStream cryptoStream = new CryptoStream(stream,
GetAes(isFT, null).CreateEncryptor(), CryptoStreamMode.Write))
cryptoStream.Write(Data, 0, Data.Length);
aes.CreateEncryptor(), CryptoStreamMode.Write))
cryptoStream.Write(data, 0, data.Length);
return stream.ToArray();
}
public void Dispose() => NewFARC();
public struct FARCFile
{
public int Offset;
+161
View File
@@ -0,0 +1,161 @@
using System.Runtime.InteropServices;
namespace KKdMainLib.IO
{
public static unsafe class DeflateInflate
{
private const string libDeflateString = "libdeflate.dll";
public static byte[] Deflate(this byte[] data, long compressionLevel)
{
void* c = libdeflate_alloc_compressor((int)compressionLevel);
int maxOutBytes = libdeflate_deflate_compress_bound(c, data.Length);
byte[] outData = new byte[maxOutBytes];
int actualOut = 0;
fixed (byte* inPtr = data)
fixed (byte* outPtr = outData)
actualOut = libdeflate_deflate_compress(c, inPtr, data.Length, outPtr, maxOutBytes);
libdeflate_free_compressor(c);
System.Array.Resize(ref outData, (int)actualOut);
return outData;
}
public static byte[] Inflate(this byte[] data, long length)
{
byte[] outData = new byte[length];
int actualOut = 0;
void* d = libdeflate_alloc_decompressor();
fixed (byte* inPtr = data)
fixed (byte* outPtr = outData)
libdeflate_deflate_decompress(d, inPtr, data.Length, outPtr, (int)length, (byte*)&actualOut);
libdeflate_free_decompressor(d);
if (actualOut == 0 || actualOut > length)
throw new System.Exception("DeflateInflate Error: specified input length" +
" is less than it should be for current Deflate data");
else if (actualOut < length)
System.Array.Resize(ref outData, (int)actualOut);
return outData;
}
public static byte[] DeflateGZip(this byte[] data, long compressionLevel)
{
void* c = libdeflate_alloc_compressor((int)compressionLevel);
int maxOutBytes = libdeflate_deflate_compress_bound(c, data.Length);
byte[] outData = new byte[maxOutBytes];
int actualOut = 0;
fixed (byte* inPtr = data)
fixed (byte* outPtr = outData)
actualOut = libdeflate_gzip_compress(c, inPtr, data.Length, outPtr, maxOutBytes);
libdeflate_free_compressor(c);
System.Array.Resize(ref outData, (int)actualOut);
return outData;
}
public static byte[] InflateGZip(this byte[] data, long length)
{
byte[] outData = new byte[length];
int actualOut = 0;
void* d = libdeflate_alloc_decompressor();
fixed (byte* inPtr = data)
fixed (byte* outPtr = outData)
libdeflate_gzip_decompress(d, inPtr, data.Length, outPtr, (int)length, (byte*)&actualOut);
libdeflate_free_decompressor(d);
if (actualOut == 0 || actualOut > length)
throw new System.Exception("DeflateInflate Error: specified input length" +
" is less than it should be for current Deflate data");
else if (actualOut < length)
System.Array.Resize(ref outData, (int)actualOut);
return outData;
}
public static byte[] DeflateZLib(this byte[] data, long compressionLevel)
{
void* c = libdeflate_alloc_compressor((int)compressionLevel);
int maxOutBytes = libdeflate_deflate_compress_bound(c, data.Length);
byte[] outData = new byte[maxOutBytes];
int actualOut = 0;
fixed (byte* inPtr = data)
fixed (byte* outPtr = outData)
actualOut = libdeflate_zlib_compress(c, inPtr, data.Length, outPtr, maxOutBytes);
libdeflate_free_compressor(c);
System.Array.Resize(ref outData, (int)actualOut);
return outData;
}
public static byte[] InflateZLib(this byte[] data, long length)
{
byte[] outData = new byte[length];
int actualOut = 0;
void* d = libdeflate_alloc_decompressor();
fixed (byte* inPtr = data)
fixed (byte* outPtr = outData)
libdeflate_zlib_decompress(d, inPtr, data.Length, outPtr, (int)length, (byte*)&actualOut);
libdeflate_free_decompressor(d);
if (actualOut == 0 || actualOut > length)
throw new System.Exception("DeflateInflate Error: specified input length" +
" is less than it should be for current Deflate data");
else if (actualOut < length)
System.Array.Resize(ref outData, (int)actualOut);
return outData;
}
[DllImport(libDeflateString)]
private static extern void* libdeflate_alloc_compressor(int compressionLevel);
[DllImport(libDeflateString)]
private static extern void* libdeflate_alloc_decompressor();
[DllImport(libDeflateString)]
private static extern int libdeflate_deflate_compress_bound(void* c, int length);
[DllImport(libDeflateString)]
private static extern int libdeflate_deflate_compress(void* c, byte* inData, int inBytes,
byte* outData, int maxOutBytes);
[DllImport(libDeflateString)]
private static extern void libdeflate_deflate_decompress(void* d, byte* inData, int inBytes,
byte* outData, int outBytesAvail, byte* actualOutBytes);
[DllImport(libDeflateString)]
private static extern void libdeflate_deflate_decompress_ex(void* d, byte* inData, int inBytes,
byte* outData, int outBytesAvail, byte* actualInBytes, byte* actualOutBytes);
[DllImport(libDeflateString)]
private static extern int libdeflate_gzip_compress_bound(void* c, int length);
[DllImport(libDeflateString)]
private static extern int libdeflate_gzip_compress(void* c, byte* inData, int inBytes,
byte* outData, int maxOutBytes);
[DllImport(libDeflateString)]
private static extern void libdeflate_gzip_decompress(void* d, byte* inData, int inBytes,
byte* outData, int outBytesAvail, byte* actualOutBytes);
[DllImport(libDeflateString)]
private static extern void libdeflate_gzip_decompress_ex(void* d, byte* inData, int inBytes,
byte* outData, int outBytesAvail, byte* actualInBytes, byte* actualOutBytes);
[DllImport(libDeflateString)]
private static extern int libdeflate_zlib_compress_bound(void* c, int length);
[DllImport(libDeflateString)]
private static extern int libdeflate_zlib_compress(void* c, byte* inData, int inBytes,
byte* outData, int maxOutBytes);
[DllImport(libDeflateString)]
private static extern void libdeflate_zlib_decompress(void* d, byte* inData, int inBytes,
byte* outData, int outBytesAvail, byte* actualOutBytes);
[DllImport(libDeflateString)]
private static extern void libdeflate_free_compressor(void* c);
[DllImport(libDeflateString)]
private static extern void libdeflate_free_decompressor(void* d);
}
}
+1 -2
View File
@@ -1,5 +1,4 @@
using System;
using MSIO = System.IO;
using MSIO = System.IO;
namespace KKdMainLib.IO
{
+180
View File
@@ -0,0 +1,180 @@
using KKdBaseLib;
using KKdBaseLib.F2;
namespace KKdMainLib.IO
{
public static class Extensions
{
public static string NTASCII(this Stream stream, byte end = 0) =>
stream.NT(end).ToASCII();
public static string NTUTF8 (this Stream stream, byte end = 0) =>
stream.NT(end).ToUTF8 ();
public static byte[] NT (this Stream stream, byte end = 0)
{
KKdList<byte> s = KKdList<byte>.New;
while (stream.PI64 < stream.LI64)
{
byte a = stream.RU8();
if (a == end) break;
else s.Add(a);
}
return s.ToArray();
}
public static byte PB (this Stream stream)
{ byte val = stream.RU8(); stream.PI64--; return val; }
public static char PCASCII(this Stream stream)
{ byte val = stream.RU8(); stream.PI64--; return (char)val; }
public static char PCUTF8 (this Stream stream)
{ long LongPosition = stream.PI64; char val = stream.RCUTF8();
stream.PI64 = LongPosition; return val; }
public static Stream SW(this Stream stream)
{
while (true)
if (char.IsWhiteSpace(stream.PCUTF8())) stream.RCUTF8();
else break;
return stream;
}
public static bool As(this Stream stream, byte next)
{ if (stream.PB() == next) { stream.PB(); return true; } else return false; }
public static bool As(this Stream stream, byte[] next)
{
for (var i = 0; i < next.Length; i++)
if (!As(stream, next[i])) return false;
return true;
}
public static bool AsASCII(this Stream stream, char next)
{ if (stream.PCUTF8() == next) { stream.RCUTF8(); return true; } else return false; }
public static bool AsASCII(this Stream stream, string next)
{
for (var i = 0; i < next.Length; i++)
if (!stream.AsASCII(next[i])) return false;
return true;
}
public static bool As(this Stream stream, char next)
{ if (stream.PCUTF8() == next) { stream.RCUTF8(); return true; } else return false; }
public static bool As(this Stream stream, string next)
{
for (var i = 0; i < next.Length; i++)
if (!As(stream, next[i])) return false;
return true;
}
public static long RIX(this Stream stream ) => stream.IsX ?
stream.RI64() : stream.RU32E( );
public static long RIX(this Stream stream, bool isBE) => stream.IsX ?
stream.RI64() : stream.RU32E(isBE);
public static void WX(this Stream stream, long val, ref POF POF)
{ if (stream.IsX) stream.W ( val);
else stream.WE((int)val); POF.Offsets.Add(stream.P); }
public static void WX(this Stream stream, long val, ref POF POF, bool IsBE)
{ if (stream.IsX) stream.W ( val );
else stream.WE((int)val, IsBE); POF.Offsets.Add(stream.P); }
public static void WX(this Stream stream, long val)
{ if (stream.IsX) stream.W ( val);
else stream.WE((int)val); }
public static void WX(this Stream stream, long val, bool IsBE)
{ if (stream.IsX) stream.W ( val );
else stream.WE((int)val, IsBE); }
public static byte[] RaO(this Stream stream, long Offset = -1, long Length = -1)
{
byte[] arr = null;
long Position = stream.PI64;
if (Offset == -1) { Position += stream.IsX ? 8 : 4; Offset = stream.RIX(); }
stream.PI64 = Offset;
if (Length == -1) arr = stream.NT();
else arr = stream.RBy(Length);
stream.PI64 = Position;
return arr;
}
public static string RSaO(this Stream stream, long Offset = -1, long Length = -1)
{
string s = null;
long Position = stream.PI64;
if (Offset == -1) { Position += stream.IsX ? 8 : 4; Offset = stream.RIX(); }
stream.PI64 = Offset;
if (Length == -1) s = stream.NTUTF8();
else s = stream.RSUTF8(Length);
stream.PI64 = Position;
return s;
}
public static Pointer<string> RPSSJIS(this Stream stream)
{ Pointer<string> val = stream.RP<string>();
val.V = stream.RPSSJIS(val.O); return val; }
public static void WPSSJIS(this Stream stream, ref Pointer<string> val)
{ val.O = stream.P; stream.WPSSJIS(val.V); }
public static string RPSSJIS(this Stream stream, long Offset = -1, long Length = -1) =>
Text.ShiftJIS.GetString(stream.RaO(Offset, Length));
public static void WPSSJIS(this Stream stream, string String) =>
stream.W(Text.ShiftJIS.GetBytes(String));
public static Pointer<string> RPS(this Stream stream)
{ Pointer<string> val = stream.RP<string>();
val.V = stream.RSaO(val.O); return val; }
public static void W(this Stream stream, ref Pointer<string> val)
{ val.O = stream.P; stream.W(val.V); }
public static Pointer<T> RP<T>(this Stream stream) =>
new Pointer<T> { O = stream.RI32() };
public static void W<T>(this Stream stream, Pointer<T> val) =>
stream.W(val.O);
public static CountPointer<T> ReadCountPointer<T>(this Stream stream) =>
new CountPointer<T> { C = stream.RI32(), O = stream.RI32() };
public static void W<T>(this Stream stream, CountPointer<T> val)
{ stream.W(val.C); stream.W(val.O); }
public static Pointer<T> RPE<T>(this Stream stream) =>
new Pointer<T> { O = stream.RI32E() };
public static void WE<T>(this Stream stream, Pointer<T> val) =>
stream.WE(val.O);
public static CountPointer<T> RCPE<T>(this Stream stream) =>
new CountPointer<T> { C = stream.RI32E(), O = stream.RI32E() };
public static void WE<T>(this Stream stream, CountPointer<T> val)
{ stream.WE(val.C); stream.WE(val.O); }
public static Pointer<string> RPSE(this Stream stream)
{ Pointer<string> val = stream.RPE<string>();
val.V = stream.RSaO(val.O); return val; }
public static void WE(this Stream stream, ref Pointer<string> val)
{ val.O = stream.P; stream.W(val.V); }
public static Pointer<T> RPX<T>(this Stream stream) =>
new Pointer<T> { O = (int)stream.RIX() };
public static void WE<T>(this Stream stream, ref Pointer<T> val) =>
stream.WX(val.O);
public static Pointer<string> RPSX(this Stream stream)
{ Pointer<string> val = stream.RPX<string>();
val.V = stream.RSaO(val.O); return val; }
public static void WX(this Stream stream, ref Pointer<string> val)
{ val.O = stream.P; stream.W(val.V); }
public static CountPointer<T> RCPX<T>(this Stream stream) =>
new CountPointer<T> { C = (int)stream.RIX(), O = (int)stream.RIX() };
public static void WX<T>(this Stream stream, CountPointer<T> val)
{ stream.WX(val.C); stream.WX(val.O); }
}
}
+31 -16
View File
@@ -6,46 +6,61 @@ namespace KKdMainLib.IO
public static class File
{
public static Stream OpenReader(byte[] Data) => new Stream(new MSIO.MemoryStream(Data));
public static Stream OpenWriter(byte[] Data) => new Stream(new MSIO.MemoryStream(Data));
public static Stream OpenWriter( ) => new Stream(new MSIO.MemoryStream( ));
public static Stream OpenReader(string file, bool ReadAllAtOnce)
{ Stream IO = OpenReader(file); if (ReadAllAtOnce) return OpenReader(IO.ToArray(true)); return IO; }
{ Stream _IO = OpenReader(file); if (ReadAllAtOnce) { byte[] data =
_IO.ToArray(); _IO.Dispose(); return OpenReader(data); } return _IO; }
public static Stream OpenReader(string file)
{ Stream IO = new Stream(new MSIO.FileStream(file, MSIO.FileMode.Open, MSIO.FileAccess.ReadWrite,
MSIO.FileShare.ReadWrite)) { File = file }; return IO; }
{ Stream _IO = new Stream(new MSIO.FileStream(file, MSIO.FileMode.Open, MSIO.FileAccess.ReadWrite,
MSIO.FileShare.ReadWrite)) { File = file }; return _IO; }
public static Stream OpenWriter(string file, bool SetLength0)
{ Stream IO = OpenWriter(file); if (SetLength0) IO.SetLength(0); return IO; }
{ Stream _IO = OpenWriter(file); if (SetLength0) _IO.SL(0); return _IO; }
public static Stream OpenWriter(string file, int SetLength)
{ Stream IO = OpenWriter(file); IO.SetLength(SetLength); return IO; }
{ Stream _IO = OpenWriter(file); _IO.SL(SetLength); return _IO; }
public static Stream OpenWriter(string file)
{ Stream IO = new Stream(new MSIO.FileStream(file,
{ Stream _IO = new Stream(new MSIO.FileStream(file,
MSIO.FileMode.OpenOrCreate, MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite)) { File = file };
MSIO.File. SetCreationTimeUtc(file, DateTime.UtcNow);
MSIO.File. SetLastWriteTimeUtc(file, DateTime.UtcNow);
MSIO.File.SetLastAccessTimeUtc(file, DateTime.UtcNow); return IO; }
MSIO.File.SetLastAccessTimeUtc(file, DateTime.UtcNow); return _IO; }
public static byte[] ReadAllBytes(string file, int length, int offset)
{ Stream IO = OpenReader(file); byte[] Data = IO.ReadBytes(length, offset); IO.Close(); return Data; }
{ byte[] Data; using (Stream _IO = OpenReader(file)) Data = _IO.RBy(length, offset); return Data; }
public static byte[] ReadAllBytes(string file)
{ Stream IO = OpenReader(file); byte[] Data = IO.ReadBytes(IO.Length); IO.Close(); return Data; }
{ byte[] Data; using (Stream _IO = OpenReader(file)) Data = _IO.RBy(_IO.L); return Data; }
public static string ReadAllText (string file)
{ Stream IO = OpenReader(file); string Data = IO.ReadStringUTF8(IO.Length); IO.Close(); return Data; }
{ string Data; using (Stream _IO = OpenReader(file)) Data = _IO.RSUTF8(_IO.L);
return Data.Replace(((char)0xFEFF).ToString(), ""); }
public static string[] ReadAllLines(string file)
{ Stream IO = OpenReader(file); string Data = IO.ReadStringUTF8(IO.Length); IO.Close();
return Data.Replace("\r", "").Split('\n'); }
{ string Data; using (Stream _IO = OpenReader(file)) Data = _IO.RSUTF8(_IO.L);
return Data.Replace(((char)0xFEFF).ToString(), "").Replace("\r", "").Split('\n'); }
public static void WriteAllBytes(string file, byte[] data)
{ Stream IO = OpenWriter(file, true); IO.Write(data); IO.Close(); }
{ using Stream _IO = OpenWriter(file, true); if (data != null) _IO.W(data); }
public static void WriteAllText (string file, string data)
{ Stream IO = OpenWriter(file, true); IO.Write(data); IO.Close(); }
{ using Stream _IO = OpenWriter(file, true); if (data != null) _IO.W(data); }
public static void WriteAllLines(string file, string[] data)
{ Stream IO = OpenWriter(file, true); for (int i = 0; i < data.Length; i++)
IO.Write(data[i] + "\r\n"); IO.Close(); }
{ using Stream _IO = OpenWriter(file, true);
if (data != null) for (int i = 0; i < data.Length; i++)
if (data[i] != null) _IO.W(data[i] + "\r\n"); }
public static void WriteAllBytes(string file, byte[] data, long length)
{ using Stream _IO = OpenWriter(file, true); if (data != null) { _IO.W(data); _IO.LI64 = length; } }
public static void WriteAllText (string file, string data, long length)
{ using Stream _IO = OpenWriter(file, true); if (data != null) { _IO.W(data); _IO.LI64 = length; } }
public static void WriteAllLines(string file, string[] data, long length)
{ using Stream _IO = OpenWriter(file, true);
if (data != null) { for (int i = 0; i < data.Length; i++)
if (data[i] != null) _IO.W(data[i] + "\r\n"); } _IO.LI64 = length; }
public static bool Exists(string file) => MSIO.File.Exists(file);
public static void Delete(string file) => MSIO.File.Delete(file);
-77
View File
@@ -1,77 +0,0 @@
using System.Collections.Generic;
namespace KKdMainLib.IO
{
public static class IOExtensions
{
public static string NullTerminatedASCII(this Stream stream, byte End = 0) =>
stream.NullTerminated(End).ToASCII();
public static string NullTerminatedUTF8 (this Stream stream, byte End = 0) =>
stream.NullTerminated(End).ToUTF8 ();
public static byte[] NullTerminated (this Stream stream, byte End = 0)
{
List<byte> s = new List<byte>();
while (stream.LongPosition < stream.LongLength)
{
byte a = stream.ReadByte();
if (a == End) break;
else s.Add(a);
}
return s.ToArray();
}
public static char PeekCharUTF8(this Stream stream)
{ long LongPosition = stream.LongPosition; char val = stream.ReadCharUTF8();
stream.LongPosition = LongPosition; return val; }
public static Stream SkipWhitespace(this Stream stream)
{
while (true)
if (char.IsWhiteSpace(stream.PeekCharUTF8())) stream.ReadCharUTF8();
else break;
return stream;
}
public static bool Assert(this Stream stream, char next)
{ if (stream.PeekCharUTF8() == next) { stream.ReadCharUTF8(); return true; } else return false; }
public static bool Assert(this Stream stream, string next)
{
for (var i = 0; i < next.Length; i++)
if (!stream.Assert(next[i])) return false;
return true;
}
public static long ReadIntX(this Stream stream ) => stream.IsX ?
stream.ReadInt64() : stream.ReadUInt32Endian( );
public static long ReadIntX(this Stream stream, bool IsBE) => stream.IsX ?
stream.ReadInt64() : stream.ReadUInt32Endian(IsBE);
public static void WriteX(this Stream stream, long val)
{ if (stream.IsX) stream.Write ( val);
else stream.WriteEndian((int)val); }
public static void WriteX(this Stream stream, long val, bool IsBE)
{ if (stream.IsX) stream.Write ( val );
else stream.WriteEndian((int)val, IsBE); }
public static byte[] ReadAtOffset(this Stream stream, long Offset = 0, long Length = 0)
{
byte[] arr = null;
long Position = stream.LongPosition;
if (Offset == 0) { Position += stream.IsX ? 8 : 4; Offset = stream.ReadIntX(); }
stream.LongPosition = Offset;
if (Length == 0) arr = stream.NullTerminated();
else arr = stream.ReadBytes(Length);
stream.LongPosition = Position;
return arr;
}
public static string ReadStringAtOffset(this Stream stream, long Offset = 0, long Length = 0)
{
string s = null;
long Position = stream.LongPosition;
if (Offset == 0) { Position += stream.IsX ? 8 : 4; Offset = stream.ReadIntX(); }
stream.LongPosition = Offset;
if (Length == 0) s = stream.NullTerminatedUTF8();
else s = stream.ReadStringUTF8(Length);
stream.LongPosition = Position;
return s;
}
}
}
+251
View File
@@ -0,0 +1,251 @@
//Original or reader part: https://github.com/MarcosLopezC/LightJson/
using KKdBaseLib;
using BaseExtensions = KKdBaseLib.Extensions;
namespace KKdMainLib.IO
{
public struct JSON : System.IDisposable
{
public JSON(Stream _IO) => this._IO = _IO;
private Stream _IO;
public void Close() => _IO.C();
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
public MsgPack Read() => ReadValue();
private MsgPack ReadValue(string Key = null)
{
char c = _IO.SW().PCUTF8();
object obj = null;
if (char.IsDigit(c))
obj = RF();
else
obj = c switch
{
'"' => RS (),
'{' => RO (),
'[' => RA (),
'-' => RF (),
't' => RBo(),
'f' => RBo(),
'n' => RN (),
_ => null ,
};
return new MsgPack(Key, obj);
}
private string RS()
{
if (!Extensions.As(_IO, '"')) return null;
char c;
string s = "";
while (true)
{
c = _IO.RCUTF8();
if (c == '\\')
{
c = _IO.RCUTF8();
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 += RUL(); break;
default: return null;
}
}
else if (c == '"') break;
else if (char.IsControl(c))
return null;
else s += c;
}
return s;
}
private char RUL() =>
(char)((((((RHD() << 4) | RHD()) << 4) | RHD()) << 4) | RHD());
private int RHD() => byte.Parse(_IO.RCUTF8().ToString(),
System.Globalization.NumberStyles.HexNumber);
private KKdList<MsgPack> RO()
{
KKdList<MsgPack> obj = KKdList<MsgPack>.New;
if (!Extensions.As(_IO, '{')) return KKdList<MsgPack>.Null;
if (_IO.SW().PCUTF8() == '}')
{ _IO.RCUTF8(); return KKdList<MsgPack>.Null; }
string key;
char c;
while (true)
{
_IO.SW();
key = RS();
if (!Extensions.As(_IO.SW(), ':'))
return KKdList<MsgPack>.Null;
obj.Add(ReadValue(key));
c = _IO.SW().PCUTF8();
if (c == '}') { _IO.RCUTF8(); break; }
else if (c == ',') { _IO.RCUTF8(); continue; }
else return KKdList<MsgPack>.Null;
}
return obj;
}
private MsgPack[] RA()
{
KKdList<MsgPack> obj = KKdList<MsgPack>.New;
if (!Extensions.As(_IO, '[')) return null;
if (_IO.SW().PCUTF8() == ']')
{ _IO.RCUTF8(); return obj.ToArray(); }
char c;
while (true)
{
obj.Add(ReadValue(null));
c = _IO.SW().PCUTF8();
if (c == ']') { _IO.RCUTF8(); break; }
else if (c == ',') { _IO.RCUTF8(); continue; }
else return null;
}
return obj.ToArray();
}
private object RF()
{
string s = " ";
_IO.SW();
if (_IO.PCUTF8() == '-') s += _IO.RCUTF8();
if (_IO.PCUTF8() == '0') s += _IO.RCUTF8();
else s += RD ();
char c = _IO.PCUTF8();
if (c == '.') s += _IO.RCUTF8() + RD();
else if (c != 'e' && c != 'E')
{
long val = long.Parse(s);
if (val >= 0x00000000 && val < 0x000000100) return ( byte)val;
else if (val >= -0x00000080 && val < 0x000000080) return ( sbyte)val;
else if (val >= -0x00008000 && val < 0x000008000) return ( short)val;
else if (val >= 0x00000000 && val < 0x000010000) return (ushort)val;
else if (val >= -0x80000000 && val < 0x000800000) return ( int)val;
else if (val >= 0x00000000 && val < 0x100000000) return ( uint)val;
else return val;
}
c = _IO.PCUTF8();
if (c == 'e' || c == 'E')
{
s += _IO.RCUTF8();
c = _IO.PCUTF8();
if (c == '+' || c == '-') s += _IO.RCUTF8();
s += RD();
}
double d = s.ToF64();
return (float)d == d ? (float)d : d;
}
private bool RBo()
{
char c = _IO.PCUTF8();
if (c == 't' && _IO.As( "true")) return true;
else if (c == 'f' && _IO.As("false")) return false;
return false;
}
private object RN() { _IO.As("null"); return null; }
private string RD()
{ string s = ""; while (char.IsDigit(_IO.SW().
PCUTF8())) s += _IO.RCUTF8(); return s; }
public JSON W(MsgPack msgPack, string end = "\n", string tabChar = " ") =>
W(msgPack, end, tabChar, "", true);
public JSON W(MsgPack msgPack, bool style = false) =>
W(msgPack, "\n", " ", "", style);
private JSON W(MsgPack msgPack, string end, string tabChar, string tab, bool style, bool isArray = false)
{
string oldTab = tab;
tab += tabChar;
if (msgPack.Name != null && !isArray) _IO.W("\"" + msgPack.Name + "\":" + (style ? " " : ""));
if (msgPack.Object == null) { WN(); return this; }
if (msgPack.List.NotNull)
{
WM();
if (style) _IO.W(end);
if (msgPack.List.Count > 1)
for (int i = 0; i < msgPack.List.Count; i++)
{
if (style) _IO.W(tab);
W(msgPack.List[i], end, tabChar, tab, style);
if (i + 1 < msgPack.List.Count) _IO.W(',');
if (style) _IO.W(end);
}
else if (msgPack.List.Count == 1)
{
if (style) _IO.W(tab);
W(msgPack.List[0], end, tabChar, tab, style);
if (style) _IO.W(end);
}
if (style) _IO.W(oldTab);
WM(true);
}
else if (msgPack.Array != null)
{
WA();
if (style) _IO.W(end);
if (msgPack.Array.Length > 1)
for (int i = 0; i < msgPack.Array.Length; i++)
{
if (style) _IO.W(tab);
W(msgPack.Array[i], end, tabChar, tab, style, true);
if (i + 1 < msgPack.Array.Length) _IO.W(',');
if (style) _IO.W(end);
}
else if (msgPack.Array.Length == 1)
{
if (style) _IO.W(tab);
W(msgPack.Array[0], end, tabChar, tab, style, true);
if (style) _IO.W(end);
}
if (style) _IO.W(oldTab);
WA(true);
}
else if (msgPack.Object is MsgPack msg) W(msg, end, tabChar, tab, style);
else if (msgPack.Object is string str) W(str);
else _IO.W(BaseExtensions.ToS(msgPack.Object));
return this;
}
public void Dispose() => _IO.C();
private void W(string val) => _IO.W("\"" + val
.Replace("\\", "\\\\").Replace("/" , "\\/").Replace("\"", "\\\"")
.Replace("\0", "\\0" ).Replace("\b", "\\b").Replace("\f", "\\f" )
.Replace("\n", "\\n" ).Replace("\r", "\\r").Replace("\t", "\\t" ) + "\"");
private void WN() => _IO.W("null");
private void WA(bool End = false) => _IO.W(End ? "]" : "[");
private void WM(bool End = false) => _IO.W(End ? "}" : "{");
}
}
+342
View File
@@ -0,0 +1,342 @@
using KKdBaseLib;
namespace KKdMainLib.IO
{
public struct MP : System.IDisposable
{
public MP(Stream _IO) => this._IO = _IO;
private Stream _IO;
public void Close() => _IO.C();
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
public MsgPack Read(bool array = false)
{
MsgPack msgPack = MsgPack.New;
byte unk = _IO.RU8();
if (!array) { msgPack.Name = RS((Types)unk); unk = _IO.RU8(); }
Types type = (Types)unk;
if (type >= Types.FixMap && type <= Types.FixMapMax)
{
msgPack.Object = KKdList<MsgPack>.New;
for (int i = 0; i < unk - (byte)Types.FixMap; i++) msgPack.Add( Read(false));
}
else if (type >= Types.FixArr && type <= Types.FixArrMax)
{
msgPack.Object = new MsgPack[unk - (byte)Types.FixArr];
for (int i = 0; i < unk - (byte)Types.FixArr; i++) msgPack[i] = Read( true);
}
else if (type >= Types.FixStr && type <= Types.FixStrMax) msgPack.Object = RS(type);
else if (type >= Types.PosInt && type <= Types.PosIntMax) msgPack.Object = unk;
else if (type >= Types.NegInt && type <= Types.NegIntMax) msgPack.Object = (sbyte)unk;
else
while (true)
{
if (RN (ref msgPack, ref type)) break;
if (RBy(ref msgPack, ref type)) break;
if (RM (ref msgPack, ref type)) break;
if (RE (ref msgPack, ref type)) break;
if (RS (ref msgPack, ref type)) break;
if (RBo(ref msgPack, ref type)) break;
if (RA (ref msgPack, ref type)) break;
if (RI (ref msgPack, ref type)) break;
if (RU (ref msgPack, ref type)) break;
if (RF (ref msgPack, ref type)) break;
break;
}
return msgPack;
}
private bool RI(ref MsgPack msgPack, ref Types type)
{
if (type == Types.Int8 ) msgPack.Object = _IO.RI8();
else if (type == Types.Int16) msgPack.Object = _IO.RI16E(true);
else if (type == Types.Int32) msgPack.Object = _IO.RI32E(true);
else if (type == Types.Int64) msgPack.Object = _IO.RI64E(true);
else return false;
return true;
}
private bool RU(ref MsgPack msgPack, ref Types type)
{
if (type == Types.UInt8 ) msgPack.Object = _IO.RU8();
else if (type == Types.UInt16) msgPack.Object = _IO.RU16E(true);
else if (type == Types.UInt32) msgPack.Object = _IO.RU32E(true);
else if (type == Types.UInt64) msgPack.Object = _IO.RU64E(true);
else return false;
return true;
}
private bool RF(ref MsgPack msgPack, ref Types type)
{
if (type == Types.Float32) msgPack.Object = _IO.RF32E(true);
else if (type == Types.Float64) msgPack.Object = _IO.RF64E(true);
else return false;
return true;
}
private bool RBo(ref MsgPack msgPack, ref Types type)
{
if (type == Types.False) msgPack.Object = false;
else if (type == Types.True ) msgPack.Object = true ;
else return false;
return true;
}
private bool RBy(ref MsgPack msgPack, ref Types type)
{
int Length = 0;
if (type == Types.Bin8 ) Length = _IO.RU8();
else if (type == Types.Bin16) Length = _IO.RI16E(true);
else if (type == Types.Bin32) Length = _IO.RI32E(true);
else return false;
msgPack.Object = _IO.RBy(Length);
return true;
}
private bool RS(ref MsgPack msgPack, ref Types type)
{
string val = RS(type);
if (val != null) msgPack.Object = val;
else return false;
return true;
}
private string RS(Types val)
{
if (val >= Types.FixStr && val <= Types.FixStrMax)
return _IO.RS(val - Types.FixStr);
else if (val >= Types. Str8 && val <= Types. Str32 )
{
System.Enum.TryParse(val.ToString(), out Types type);
int Length = 0;
if (type == Types.Str8 ) Length = _IO.RU8();
else if (type == Types.Str16) Length = _IO.RI16E(true);
else Length = _IO.RI32E(true);
return _IO.RS(Length);
}
return null;
}
private bool RN(ref MsgPack msgPack, ref Types type)
{
if (type == Types.Nil) msgPack.Object = null;
else return false;
return true;
}
private bool RA(ref MsgPack msgPack, ref Types type)
{
int Length = 0;
if (type == Types.Arr16) Length = _IO.RI16E(true);
else if (type == Types.Arr32) Length = _IO.RI32E(true);
else return false;
msgPack.Object = new MsgPack[Length];
for (int i = 0; i < Length; i++) msgPack[i] = Read(true);
return true;
}
private bool RM(ref MsgPack msgPack, ref Types type)
{
int Length = 0;
if (type == Types.Map16) Length = _IO.RI16E(true);
else if (type == Types.Map32) Length = _IO.RI32E(true);
else return false;
msgPack.Object = KKdList<MsgPack>.New;
for (int i = 0; i < Length; i++) msgPack.Add(Read());
return true;
}
private bool RE(ref MsgPack MsgPack, ref Types type)
{
int Length = 0;
if (type == Types.FixExt1 ) Length = 1 ;
else if (type == Types.FixExt2 ) Length = 2 ;
else if (type == Types.FixExt4 ) Length = 4 ;
else if (type == Types.FixExt8 ) Length = 8 ;
else if (type == Types.FixExt16) Length = 16;
else if (type == Types. Ext8 ) Length = _IO.RU8();
else if (type == Types. Ext16) Length = _IO.RI16E(true);
else if (type == Types. Ext32) Length = _IO.RI32E(true);
else return false;
MsgPack.Object = new MsgPack.Ext { Type = _IO.RI8(), Data = _IO.RBy(Length) };
return true;
}
public MP W(MsgPack msgPack, bool IsArray = false)
{
if (msgPack.Name != null && !IsArray) W(msgPack.Name);
Write(msgPack.Object);
return this;
}
private void Write(object obj)
{
if (obj == null) { WN(); return; }
switch (obj)
{
case KKdList<MsgPack> val: WM(val.Count );
for (int i = 0; i < val.Count ; i++) W(val[i]); break;
case MsgPack[] val: WA(val.Length);
for (int i = 0; i < val.Length; i++) W(val[i]); break;
case MsgPack val: W(val); break;
case byte[] val: W(val); break;
case bool val: W(val); break;
case sbyte val: W(val); break;
case byte val: W(val); break;
case short val: W(val); break;
case ushort val: W(val); break;
case int val: W(val); break;
case uint val: W(val); break;
case long val: W(val); break;
case ulong val: W(val); break;
case float val: W(val); break;
case double val: W(val); break;
case string val: W(val); break;
case MsgPack.Ext val: W(val); break;
}
}
private void W( sbyte val) { if (val < -0x20) _IO.W((byte)0xD0); _IO.W(val); }
private void W( byte val) { if (val >= 0x80) _IO.W((byte)0xCC); _IO.W(val); }
private void W( short val) { if (( sbyte)val == val) W(( sbyte)val);
else if (( byte)val == val) W(( byte)val);
else { _IO.W((byte)0xD1); _IO.WE(val, true); } }
private void W(ushort val) { if (( byte)val == val) W(( byte)val);
else { _IO.W((byte)0xCD); _IO.WE(val, true); } }
private void W( int val) { if (( short)val == val) W(( short)val);
else if ((ushort)val == val) W((ushort)val);
else { _IO.W((byte)0xD2); _IO.WE(val, true); } }
private void W( uint val) { if ((ushort)val == val) W((ushort)val);
else { _IO.W((byte)0xCE); _IO.WE(val, true); } }
private void W( long val) { if (( int)val == val) W(( int)val);
else if (( uint)val == val) W(( uint)val);
else { _IO.W((byte)0xD3); _IO.WE(val, true); } }
private void W( ulong val) { if (( uint)val == val) W(( uint)val);
else { _IO.W((byte)0xCF); _IO.WE(val, true); } }
private void W( float val) { if (( long)val == val) W(( long)val);
else { _IO.W((byte)0xCA); _IO.WE(val, true); } }
private void W(double val) { if (( long)val == val) W(( long)val);
else if (( float)val == val) W(( float)val);
else { _IO.W((byte)0xCB); _IO.WE(val, true); } }
private void W( bool val) =>
_IO.W((byte)(val ? 0xC3 : 0xC2));
private void W(byte[] val)
{
if (val == null) { WN(); return; }
if (val.Length < 0x100) { _IO.W((byte)0xC4); _IO.W (( byte)val.Length ); }
else if (val.Length < 0x10000) { _IO.W((byte)0xC5); _IO.WE((ushort)val.Length, true); }
else { _IO.W((byte)0xC6); _IO.WE( val.Length, true); }
_IO.W(val);
}
private void W(string val)
{
if (val == null) { WN(); return; }
byte[] array = Text.ToUTF8(val);
if (array.Length < 0x20) _IO.W((byte)(0xA0 | (array.Length & 0x1F)));
else if (array.Length < 0x100) { _IO.W((byte)0xD9); _IO.W (( byte)array.Length); }
else if (array.Length < 0x10000) { _IO.W((byte)0xDA); _IO.WE((ushort)array.Length, true); }
else { _IO.W((byte)0xDB); _IO.WE( array.Length, true); }
_IO.W(array);
}
private void WN() => _IO.W((byte)0xC0);
private void WA(int val)
{
if (val == 0) { WN(); return; }
else if (val < 0x10) _IO.W((byte)(0x90 | (val & 0x0F)));
else if (val < 0x10000) { _IO.W((byte)0xDC); _IO.WE((ushort)val, true); }
else { _IO.W((byte)0xDD); _IO.WE( val, true); }
}
private void WM(int val)
{
if (val == 0) { WN(); return; }
else if (val < 0x10) _IO.W((byte)(0x80 | (val & 0x0F)));
else if (val < 0x10000) { _IO.W((byte)0xDE); _IO.WE((ushort)val, true); }
else { _IO.W((byte)0xDF); _IO.WE( val, true); }
}
private void W(MsgPack.Ext val) => WE(val);
private void WE(MsgPack.Ext val)
{
if (val.Data == null) { WN(); return; }
if (val.Data.Length < 1 ) { WN(); return; }
else if (val.Data.Length == 1 ) _IO.W((byte)0xD4);
else if (val.Data.Length == 2 ) _IO.W((byte)0xD5);
else if (val.Data.Length == 4 ) _IO.W((byte)0xD6);
else if (val.Data.Length == 8 ) _IO.W((byte)0xD7);
else if (val.Data.Length == 16) _IO.W((byte)0xD8);
else
{
if (val.Data.Length < 0x100)
{ _IO.W((byte)0xC7); _IO.W (( byte)val.Data.Length); }
else if (val.Data.Length < 0x10000)
{ _IO.W((byte)0xC8); _IO.WE((ushort)val.Data.Length, true); }
else
{ _IO.W((byte)0xC9); _IO.WE( val.Data.Length, true); }
}
_IO.W(val.Type);
_IO.W(val.Data);
}
public void Dispose() => _IO.C();
}
public enum Types : byte
{
PosInt = 0b00000000,
FixMap = 0b10000000,
FixArr = 0b10010000,
FixStr = 0b10100000,
Nil = 0b11000000,
NeverUsed = 0b11000001,
False = 0b11000010,
True = 0b11000011,
Bin8 = 0b11000100,
Bin16 = 0b11000101,
Bin32 = 0b11000110,
Ext8 = 0b11000111,
Ext16 = 0b11001000,
Ext32 = 0b11001001,
Float32 = 0b11001010,
Float64 = 0b11001011,
UInt8 = 0b11001100,
UInt16 = 0b11001101,
UInt32 = 0b11001110,
UInt64 = 0b11001111,
Int8 = 0b11010000,
Int16 = 0b11010001,
Int32 = 0b11010010,
Int64 = 0b11010011,
FixExt1 = 0b11010100,
FixExt2 = 0b11010101,
FixExt4 = 0b11010110,
FixExt8 = 0b11010111,
FixExt16 = 0b11011000,
Str8 = 0b11011001,
Str16 = 0b11011010,
Str32 = 0b11011011,
Arr16 = 0b11011100,
Arr32 = 0b11011101,
Map16 = 0b11011110,
Map32 = 0b11011111,
NegInt = 0b11100000,
PosIntMax = 0b01111111,
FixMapMax = 0b10001111,
FixArrMax = 0b10011111,
FixStrMax = 0b10111111,
NegIntMax = 0b11111111,
}
}
+275 -291
View File
@@ -1,382 +1,366 @@
using System;
using KKdMainLib.Types;
using KKdBaseLib;
using MSIO = System.IO;
using ENRSDict = System.Collections.Generic.Dictionary<long, int>;
namespace KKdMainLib.IO
{
public unsafe class Stream : IDisposable
{
private MSIO.Stream stream;
private int I, i, i0, TempBitRead, TempBitWrite;
private ushort ValRead;
private byte BitRead, BitWrite, ValWrite;
private byte[] buf;
private int i, j, bitRead, bitWrite, tempBitRead, tempBitWrite, valRead, valWrite;
private byte[] b;
private MSIO.Stream s;
private Main.Format _format = Main.Format.NULL;
private bool getENRS;
public Main.Format Format
{ get => _format;
set { _format = value;
IsBE = _format == Main.Format.F2BE;
IsX = _format == Main.Format.X || _format == Main.Format.XHD; } }
private Format format = Format.NULL;
public Format Format
{ get => format;
set { format = value;
IsBE = format == Format.F2BE;
IsX = format == Format.X || format == Format.XHD; } }
public ENRSDict ENRSDict;
public bool IsBE = false;
public bool IsX = false;
public bool GetENRS
{ get => getENRS;
set { if (value && ENRSDict == null)
ENRSDict = new ENRSDict(); getENRS = value; } }
public int Offset { get => ( int)LongOffset; set => LongOffset = value; }
public uint UIntOffset { get => (uint)LongOffset; set => LongOffset = value; }
public long LongOffset;
public int O { get => ( int)OI64; set => OI64 = value; }
public uint OU32 { get => (uint)OI64; set => OI64 = value; }
public long OI64;
public int Length { get => ( int)stream.Length - Offset; set => stream.SetLength(value + Offset); }
public uint UIntLength { get => (uint)stream.Length - UIntOffset; set => stream.SetLength(value + UIntOffset); }
public long LongLength { get => stream.Length - LongOffset; set => stream.SetLength(value + LongOffset); }
public int L { get => ( int)s.Length - O; set => s.SetLength(value + O ); }
public uint LU32 { get => (uint)s.Length - OU32; set => s.SetLength(value + OU32); }
public long LI64 { get => s.Length - OI64; set => s.SetLength(value + OI64); }
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 int P { get => ( int)s.Position - O; set => s.Position = value + O ; }
public uint PU32 { get => (uint)s.Position - OU32; set => s.Position = value + OU32; }
public long PI64 { get => s.Position - OI64; set => s.Position = value + OI64; }
public bool CanRead => stream.CanRead;
public bool CanSeek => stream.CanSeek;
public bool CanTimeout => stream.CanTimeout;
public bool CanWrite => stream.CanWrite;
public bool CanRead => s.CanRead;
public bool CanSeek => s.CanSeek;
public bool CanTimeout => s.CanTimeout;
public bool CanWrite => s.CanWrite;
public string File = null;
public Stream(MSIO.Stream output = 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[128];
OI64 = 0;
bitRead = 8;
valRead = valRead = bitWrite = 0;
s = output;
Format = Format.NULL;
b = new byte[0x100];
IsBE = isBE;
}
public void Close() => Dispose();
public void C() => D(true);
public void Flush() => stream.Flush();
public void F() => s.Flush();
public void SetLength(long length = 0) => stream.SetLength(length);
public void SL(long length = 0) => s.SetLength(length);
public long Seek(long offset, SeekOrigin origin = 0) =>
stream.Seek(offset, (MSIO.SeekOrigin)(int)origin);
public long? Seek(long? offset, SeekOrigin origin)
{ if (offset == null) return null; return stream.Seek((long)offset, (MSIO.SeekOrigin)(int)origin); }
public long S(long offset, SeekOrigin origin = 0) =>
s.Seek(offset + O, (MSIO.SeekOrigin)(int)origin);
public void Dispose()
{ CheckWrited(); Dispose(true); }
public long? S(long? offset, SeekOrigin origin)
{ if (offset == null) return null;
return s.Seek((long)offset + O, (MSIO.SeekOrigin)(int)origin); }
private void Dispose(bool disposing)
{ if (disposing && stream != MSIO.Stream.Null) stream.Flush(); stream.Dispose(); }
private bool disposed = false;
public void D() => D(true);
public void Dispose() => D(true);
public MSIO.Stream BaseStream
{ get { stream.Flush(); return stream; } set { stream = value; } }
protected virtual void D(bool dispose)
{ CW(); if (ENRSDict != null) { ENRSDict.Clear(); ENRSDict = null; }
if (s != MSIO.Stream.Null && !disposed) { disposed = true; s.Flush();
s.Dispose(); } if (dispose) GC.SuppressFinalize(this); }
public void Align(long Align)
public MSIO.Stream BS
{ get { s.Flush(); return s; } set { s = value; } }
public void A(long align)
{
long Al = Align - Position % Align;
if (Position % Align != 0)
stream.Seek(Position + Offset + Al, 0);
long Al = align - P % align;
if (P % align != 0) s.Seek(P + O + Al, 0);
}
public void Align(long Align, bool SetLength)
public void A(long align, bool SetLength)
{
if (SetLength) stream.SetLength(Position + Offset);
long Al = Align - Position % Align;
if (Position % Align != 0) stream.Seek(Position + Offset + Al, 0);
if (SetLength) stream.SetLength(Position + Offset);
if (SetLength) s.SetLength(P + O);
long Al = align - P % align;
if (P % align != 0) s.Seek(P + O + Al, 0);
if (SetLength) s.SetLength(P + O);
}
public void Align(long Align, bool SetLength0, bool SetLength1)
public void A(long align, bool setLength0, bool setLength1)
{
if (SetLength0) stream.SetLength(Position + Offset);
long Al = Align - Position % Align;
if (Position % Align != 0) stream.Seek(Position + Al, 0);
if (SetLength1) stream.SetLength(Position + Offset);
if (setLength0) s.SetLength(P + O);
long Al = align - P % align;
if (P % align != 0) s.Seek(P + Al, 0);
if (setLength1) s.SetLength(P + O);
}
public bool ReadBoolean() => stream.ReadByte() == 1;
public sbyte ReadSByte() => ( sbyte)stream.ReadByte();
public byte ReadByte() => ( byte)stream.ReadByte();
public sbyte ReadInt8() => ( sbyte) IntFromArray(1);
public byte ReadUInt8() => ( byte)UIntFromArray(1);
public short ReadInt16() => ( short) IntFromArray(2);
public ushort ReadUInt16() => (ushort)UIntFromArray(2);
public int ReadInt24() => ( int) IntFromArray(3);
public int ReadInt32() => ( int) IntFromArray(4);
public uint ReadUInt32() => ( uint)UIntFromArray(4);
public long ReadInt64() => IntFromArray(8);
public ulong ReadUInt64() => UIntFromArray(8);
public Half ReadHalf() { ushort a = ReadUInt16(); return ( Half ) a; }
public float ReadSingle() { uint a = ReadUInt32(); return *( float*)&a; }
public double ReadDouble() { ulong a = ReadUInt64(); return *(double*)&a; }
public short ReadInt16Endian() => ( short) IntFromArray(2, IsBE);
public ushort ReadUInt16Endian() => (ushort)UIntFromArray(2, IsBE);
public int ReadInt24Endian() => ( int) IntFromArray(3, IsBE);
public int ReadInt32Endian() => ( int) IntFromArray(4, IsBE);
public uint ReadUInt32Endian() => ( uint)UIntFromArray(4, IsBE);
public long ReadInt64Endian() => IntFromArray(8, IsBE);
public ulong ReadUInt64Endian() => UIntFromArray(8, IsBE);
public Half ReadHalfEndian() { ushort a = ReadUInt16Endian(); return ( Half ) a; }
public float ReadSingleEndian() { uint a = ReadUInt32Endian(); return *( float*)&a; }
public double ReadDoubleEndian() { ulong a = ReadUInt64Endian(); return *(double*)&a; }
public bool RBo () => s.ReadByte() != 0;
public sbyte RI8 () => (sbyte)s.ReadByte();
public byte RU8 () => ( byte)s.ReadByte();
public short RI16() { s.Read(b, 0, 2); return b.TI16(); }
public ushort RU16() { s.Read(b, 0, 2); return b.TU16(); }
public int RI32() { s.Read(b, 0, 4); return b.TI32(); }
public uint RU32() { s.Read(b, 0, 4); return b.TU32(); }
public long RI64() { s.Read(b, 0, 8); return b.TI64(); }
public ulong RU64() { s.Read(b, 0, 8); return b.TU64(); }
public float RF32() { s.Read(b, 0, 4); return b.TF32(); }
public double RF64() { s.Read(b, 0, 8); return b.TF64(); }
public short ReadInt16Endian(bool IsBE) => ( short) IntFromArray(2, IsBE);
public ushort ReadUInt16Endian(bool IsBE) => (ushort)UIntFromArray(2, IsBE);
public int ReadInt24Endian(bool IsBE) => ( int) IntFromArray(3, IsBE);
public int ReadInt32Endian(bool IsBE) => ( int) IntFromArray(4, IsBE);
public uint ReadUInt32Endian(bool IsBE) => ( uint)UIntFromArray(4, IsBE);
public long ReadInt64Endian(bool IsBE) => IntFromArray(8, IsBE);
public ulong ReadUInt64Endian(bool IsBE) => UIntFromArray(8, IsBE);
public Half ReadHalfEndian(bool IsBE)
{ ushort a = ReadUInt16Endian(IsBE); return ( Half ) a; }
public float ReadSingleEndian(bool IsBE)
{ uint a = ReadUInt32Endian(IsBE); return *( float*)&a; }
public double ReadDoubleEndian(bool IsBE)
{ ulong a = ReadUInt64Endian(IsBE); return *(double*)&a; }
public short RI16E() { s.Read(b, 0, 2); b.E(2, IsBE); return b.TI16(); }
public ushort RU16E() { s.Read(b, 0, 2); b.E(2, IsBE); return b.TU16(); }
public int RI32E() { s.Read(b, 0, 4); b.E(4, IsBE); return b.TI32(); }
public uint RU32E() { s.Read(b, 0, 4); b.E(4, IsBE); return b.TU32(); }
public long RI64E() { s.Read(b, 0, 8); b.E(8, IsBE); return b.TI64(); }
public ulong RU64E() { s.Read(b, 0, 8); b.E(8, IsBE); return b.TU64(); }
public float RF32E() { s.Read(b, 0, 4); b.E(4, IsBE); return b.TF32(); }
public double RF64E() { s.Read(b, 0, 8); b.E(8, IsBE); return b.TF64(); }
public void Write(byte[] Val) => stream.Write(Val, 0, Val. Length);
public void Write(byte[] Val, int Length) => stream.Write(Val, 0 , Length);
public void Write(byte[] Val, int Offset, int Length) => stream.Write(Val, Offset, Length);
public void Write(char[] val, bool UTF8 = true)
{ if (UTF8) Write(val.ToUTF8()); else Write(val.ToASCII()); }
public short RI16E(bool isBE) { s.Read(b, 0, 2); b.E(2, isBE); return b.TI16(); }
public ushort RU16E(bool isBE) { s.Read(b, 0, 2); b.E(2, isBE); return b.TU16(); }
public int RI32E(bool isBE) { s.Read(b, 0, 4); b.E(4, isBE); return b.TI32(); }
public uint RU32E(bool isBE) { s.Read(b, 0, 4); b.E(4, isBE); return b.TU32(); }
public long RI64E(bool isBE) { s.Read(b, 0, 8); b.E(8, isBE); return b.TI64(); }
public ulong RU64E(bool isBE) { s.Read(b, 0, 8); b.E(8, isBE); return b.TU64(); }
public float RF32E(bool isBE) { s.Read(b, 0, 4); b.E(4, isBE); return b.TF32(); }
public double RF64E(bool isBE) { s.Read(b, 0, 8); b.E(8, isBE); return b.TF64(); }
public void WriteByte(byte val) => stream.WriteByte(val);
public void W(byte[] Val ) =>
s.Write(Val ?? new byte[0], 0, Val.Length);
public void W(byte[] Val, int Length) =>
s.Write(Val ?? new byte[0], 0, Length);
public void W(byte[] Val, int Offset, int Length) =>
s.Write(Val ?? new byte[0], Offset, Length);
public void W(char[] val, bool UTF8 = true) =>
W(UTF8 ? val.ToUTF8() : val.ToASCII());
public void Write( bool val) => stream.WriteByte((byte)(val ? 1 : 0));
public void Write( sbyte val) => stream.WriteByte((byte) val);
public void Write( byte val) => stream.WriteByte( val);
public void Write( short val) => ToArray(2, val);
public void Write(ushort val) => ToArray(2, val);
public void Write( int val) => ToArray(4, val);
public void Write( uint val) => ToArray(4, val);
public void Write( long val) => ToArray(8, val);
public void Write( ulong val) => ToArray(8, val);
public void Write( Half val) => ToArray(2, (ushort) val);
public void Write( float val) => ToArray(4, *( uint*)&val);
public void Write(double val) => ToArray(8, *(ulong*)&val);
public void W( bool val) => s.WriteByte((byte)(val ? 1 : 0));
public void W( sbyte val) => s.WriteByte((byte) val);
public void W( byte val) => s.WriteByte( val);
public void W( short val) { b.GBy(val); s.Write(b, 0, 2); }
public void W(ushort val) { b.GBy(val); s.Write(b, 0, 2); }
public void W( int val) { b.GBy(val); s.Write(b, 0, 4); }
public void W( uint val) { b.GBy(val); s.Write(b, 0, 4); }
public void W( long val) { b.GBy(val); s.Write(b, 0, 8); }
public void W( ulong val) { b.GBy(val); s.Write(b, 0, 8); }
public void W( float val) { b.GBy(val); s.Write(b, 0, 4); }
public void W(double val) { b.GBy(val); s.Write(b, 0, 8); }
public void Write( sbyte? val) => Write(val.GetValueOrDefault());
public void Write( byte? val) => Write(val.GetValueOrDefault());
public void Write( short? val) => Write(val.GetValueOrDefault());
public void Write(ushort? val) => Write(val.GetValueOrDefault());
public void Write( int? val) => Write(val.GetValueOrDefault());
public void Write( uint? val) => Write(val.GetValueOrDefault());
public void Write( long? val) => Write(val.GetValueOrDefault());
public void Write( ulong? val) => Write(val.GetValueOrDefault());
public void Write( float? val) => Write(val.GetValueOrDefault());
public void Write(double? val) => Write(val.GetValueOrDefault());
public void Write( bool* val, int Length)
{ for (i = 0; i < Length; i++) stream.WriteByte((byte)(val[i] ? 1 : 0)); }
public void Write( sbyte* val, int Length)
{ for (i = 0; i < Length; i++) stream.WriteByte((byte) val[i]); }
public void Write( byte* val, int Length)
{ for (i = 0; i < Length; i++) stream.WriteByte( val[i]); }
public void Write( short* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(2, val[i]); }
public void Write(ushort* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(2, val[i]); }
public void Write( int* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(4, val[i]); }
public void Write( uint* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(4, val[i]); }
public void Write( long* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(8, val[i]); }
public void Write( ulong* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(8, val[i]); }
public void Write( float* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(4, *( uint*)&val[i]); }
public void Write(double* val, int Length)
{ for (i = 0; i < Length; i++) ToArray(4, *(ulong*)&val[i]); }
public void 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 W( sbyte? val) => W(val ?? default);
public void W( byte? val) => W(val ?? default);
public void W( short? val) => W(val ?? default);
public void W(ushort? val) => W(val ?? default);
public void W( int? val) => W(val ?? default);
public void W( uint? val) => W(val ?? default);
public void W( long? val) => W(val ?? default);
public void W( ulong? val) => W(val ?? default);
public void W( float? val) => W(val ?? default);
public void W(double? val) => W(val ?? default);
public void WriteEndian( short* val, int Length, bool 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++) ToArray(2, Endian(val[i], 2, IsBE)); }
public void WriteEndian( int* val, int Length, bool 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++) ToArray(4, Endian(val[i], 4, IsBE)); }
public void WriteEndian( long* val, int Length, bool 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++) ToArray(8, Endian(val[i], 8, IsBE)); }
public void WriteEndian( float* val, int Length, bool 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++) ToArray(8, Endian(*(ulong*)&val[i], 8, IsBE)); }
public void W( char val, bool UTF8 = true) =>
W(UTF8 ? val.ToString().ToUTF8() : val.ToString().ToASCII());
public void W(string val, bool UTF8 = true) =>
W(UTF8 ? val .ToUTF8() : val .ToASCII());
public void Write( char val, bool UTF8 = true)
{ if (UTF8) Write(val.ToString().ToUTF8()); else Write(val.ToString().ToASCII()); }
public void Write(string val, bool UTF8 = true)
{ if (UTF8) Write(val .ToUTF8()); else Write(val .ToASCII()); }
public void WriteEndian( short val) => ToArray(2, Endian(val, 2, IsBE));
public void WriteEndian(ushort val) => ToArray(2, Endian(val, 2, IsBE));
public void WriteEndian( int val) => ToArray(4, Endian(val, 4, IsBE));
public void WriteEndian( uint val) => ToArray(4, Endian(val, 4, IsBE));
public void WriteEndian( long val) => ToArray(8, Endian(val, 8, IsBE));
public void WriteEndian( ulong val) => ToArray(8, Endian(val, 8, IsBE));
public void WriteEndian( float val) => ToArray(4, Endian(*( uint*)&val, 4, IsBE));
public void WriteEndian(double val) => ToArray(8, Endian(*(ulong*)&val, 8, IsBE));
public void WE( short val) { b.GBy(val); b.E(2, IsBE); s.Write(b, 0, 2); }
public void WE(ushort val) { b.GBy(val); b.E(2, IsBE); s.Write(b, 0, 2); }
public void WE( int val) { b.GBy(val); b.E(4, IsBE); s.Write(b, 0, 4); }
public void WE( uint val) { b.GBy(val); b.E(4, IsBE); s.Write(b, 0, 4); }
public void WE( long val) { b.GBy(val); b.E(8, IsBE); s.Write(b, 0, 8); }
public void WE( ulong val) { b.GBy(val); b.E(8, IsBE); s.Write(b, 0, 8); }
public void WE( float val) { b.GBy(val); b.E(4, IsBE); s.Write(b, 0, 4); }
public void WE(double val) { b.GBy(val); b.E(8, IsBE); s.Write(b, 0, 8); }
public void WriteEndian( short val, bool IsBE) => ToArray(2, Endian(val, 2, IsBE));
public void WriteEndian(ushort val, bool IsBE) => ToArray(2, Endian(val, 2, IsBE));
public void WriteEndian( int val, bool IsBE) => ToArray(4, Endian(val, 4, IsBE));
public void WriteEndian( uint val, bool IsBE) => ToArray(4, Endian(val, 4, IsBE));
public void WriteEndian( long val, bool IsBE) => ToArray(8, Endian(val, 8, IsBE));
public void WriteEndian( ulong val, bool IsBE) => ToArray(8, Endian(val, 8, IsBE));
public void WriteEndian( float val, bool IsBE) => ToArray(4, Endian(*( uint*)&val, 4, IsBE));
public void WriteEndian(double val, bool IsBE) => ToArray(8, Endian(*(ulong*)&val, 8, IsBE));
public void WE( short val, bool isBE) { b.GBy(val); b.E(2, isBE); s.Write(b, 0, 2); }
public void WE(ushort val, bool isBE) { b.GBy(val); b.E(2, isBE); s.Write(b, 0, 2); }
public void WE( int val, bool isBE) { b.GBy(val); b.E(4, isBE); s.Write(b, 0, 4); }
public void WE( uint val, bool isBE) { b.GBy(val); b.E(4, isBE); s.Write(b, 0, 4); }
public void WE( long val, bool isBE) { b.GBy(val); b.E(8, isBE); s.Write(b, 0, 8); }
public void WE( ulong val, bool isBE) { b.GBy(val); b.E(8, isBE); s.Write(b, 0, 8); }
public void WE( float val, bool isBE) { b.GBy(val); b.E(4, isBE); s.Write(b, 0, 4); }
public void WE(double val, bool isBE) { b.GBy(val); b.E(8, isBE); s.Write(b, 0, 8); }
public long Endian( long BE, byte Length, bool IsBE)
{ 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 RENRS(byte[] b, int c)
{ if (getENRS) ENRSDict.Add(P, c); s.Read(b, 0, c); }
public ulong Endian( ulong BE, byte Length, bool IsBE)
{ 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 short RI16ENRS() { RENRS(b, 2); return b.TI16(); }
public ushort RU16ENRS() { RENRS(b, 2); return b.TU16(); }
public int RI32ENRS() { RENRS(b, 4); return b.TI32(); }
public uint RU32ENRS() { RENRS(b, 4); return b.TU32(); }
public long RI64ENRS() { RENRS(b, 8); return b.TI64(); }
public ulong RU64ENRS() { RENRS(b, 8); return b.TU64(); }
public float RF32ENRS() { RENRS(b, 4); return b.TF32(); }
public double RF64ENRS() { RENRS(b, 8); return b.TF64(); }
private void ToArray(byte L, long val)
{ CheckWrited(); for (I = 0; I < L; I++) { buf[I] = (byte)val; val >>= 8; } stream.Write(buf, 0, L); }
public short RI16ENRSE() { RENRS(b, 2); b.E(2, IsBE); return b.TI16(); }
public ushort RU16ENRSE() { RENRS(b, 2); b.E(2, IsBE); return b.TU16(); }
public int RI32ENRSE() { RENRS(b, 4); b.E(4, IsBE); return b.TI32(); }
public uint RU32ENRSE() { RENRS(b, 4); b.E(4, IsBE); return b.TU32(); }
public long RI64ENRSE() { RENRS(b, 8); b.E(8, IsBE); return b.TI64(); }
public ulong RU64ENRSE() { RENRS(b, 8); b.E(8, IsBE); return b.TU64(); }
public float RF32ENRSE() { RENRS(b, 4); b.E(4, IsBE); return b.TF32(); }
public double RF64ENRSE() { RENRS(b, 8); b.E(8, IsBE); return b.TF64(); }
private void ToArray(byte L, ulong val)
{ CheckWrited(); for (I = 0; I < L; I++) { buf[I] = (byte)val; val >>= 8; } stream.Write(buf, 0, L); }
public short RI16ENRSE(bool isBE) { RENRS(b, 2); b.E(2, isBE); return b.TI16(); }
public ushort RU16ENRSE(bool isBE) { RENRS(b, 2); b.E(2, isBE); return b.TU16(); }
public int RI32ENRSE(bool isBE) { RENRS(b, 4); b.E(4, isBE); return b.TI32(); }
public uint RU32ENRSE(bool isBE) { RENRS(b, 4); b.E(4, isBE); return b.TU32(); }
public long RI64ENRSE(bool isBE) { RENRS(b, 8); b.E(8, isBE); return b.TI64(); }
public ulong RU64ENRSE(bool isBE) { RENRS(b, 8); b.E(8, isBE); return b.TU64(); }
public float RF32ENRSE(bool isBE) { RENRS(b, 4); b.E(4, isBE); return b.TF32(); }
public double RF64ENRSE(bool isBE) { RENRS(b, 8); b.E(8, isBE); return b.TF64(); }
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 void WENRS(byte[] b, int c)
{ if (getENRS) ENRSDict.Add(P, c); s.Write(b, 0, c); }
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; }
public void WENRS( short val) { b.GBy(val); WENRS(b, 2); }
public void WENRS(ushort val) { b.GBy(val); WENRS(b, 2); }
public void WENRS( int val) { b.GBy(val); WENRS(b, 4); }
public void WENRS( uint val) { b.GBy(val); WENRS(b, 4); }
public void WENRS( long val) { b.GBy(val); WENRS(b, 8); }
public void WENRS( ulong val) { b.GBy(val); WENRS(b, 8); }
public void WENRS( float val) { b.GBy(val); WENRS(b, 4); }
public void WENRS(double val) { b.GBy(val); WENRS(b, 8); }
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; }
public void WENRSE( short val) { b.GBy(val); b.E(2, IsBE); WENRS(b, 2); }
public void WENRSE(ushort val) { b.GBy(val); b.E(2, IsBE); WENRS(b, 2); }
public void WENRSE( int val) { b.GBy(val); b.E(4, IsBE); WENRS(b, 4); }
public void WENRSE( uint val) { b.GBy(val); b.E(4, IsBE); WENRS(b, 4); }
public void WENRSE( long val) { b.GBy(val); b.E(8, IsBE); WENRS(b, 8); }
public void WENRSE( ulong val) { b.GBy(val); b.E(8, IsBE); WENRS(b, 8); }
public void WENRSE( float val) { b.GBy(val); b.E(4, IsBE); WENRS(b, 4); }
public void WENRSE(double val) { b.GBy(val); b.E(8, IsBE); WENRS(b, 8); }
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 void WENRSE( short val, bool isBE) { b.GBy(val); b.E(2, isBE); WENRS(b, 2); }
public void WENRSE(ushort val, bool isBE) { b.GBy(val); b.E(2, isBE); WENRS(b, 2); }
public void WENRSE( int val, bool isBE) { b.GBy(val); b.E(4, isBE); WENRS(b, 4); }
public void WENRSE( uint val, bool isBE) { b.GBy(val); b.E(4, isBE); WENRS(b, 4); }
public void WENRSE( long val, bool isBE) { b.GBy(val); b.E(8, isBE); WENRS(b, 8); }
public void WENRSE( ulong val, bool isBE) { b.GBy(val); b.E(8, isBE); WENRS(b, 8); }
public void WENRSE( float val, bool isBE) { b.GBy(val); b.E(4, isBE); WENRS(b, 4); }
public void WENRSE(double val, bool isBE) { b.GBy(val); b.E(8, isBE); WENRS(b, 8); }
public char ReadCharUTF8()
public Half RF16 ( ) { ushort a = RU16 ( ); return (Half)a; }
public Half RF16E ( ) { ushort a = RU16E ( ); return (Half)a; }
public Half RF16E (bool isBE) { ushort a = RU16E (isBE); return (Half)a; }
public Half RF16ENRS ( ) { ushort a = RU16E ( ); return (Half)a; }
public Half RF16ENRSE( ) { ushort a = RU16ENRSE( ); return (Half)a; }
public Half RF16ENRSE(bool isBE) { ushort a = RU16ENRSE(isBE); return (Half)a; }
public void W (Half val ) => W ((ushort)val );
public void WE (Half val ) => WE ((ushort)val );
public void WE (Half val, bool isBE) => WE ((ushort)val, isBE);
public void WENRS (Half val ) => WENRS ((ushort)val );
public void WENRSE(Half val ) => WENRSE((ushort)val );
public void WENRSE(Half val, bool isBE) => WENRSE((ushort)val, isBE);
public char RC(bool utf8 = true) => utf8 ? RCUTF8() : (char)s.ReadByte();
public char RCUTF8()
{
byte t;
int T;
int val = 0;
for (I = 0, i0 = 4; I < i0; I++)
for (j = 0, i = 4; j < i; j++)
{
T = stream.ReadByte();
T = s.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; }
if ((t & 0xC0) == 0x80 && j > 0) val = (val << 6) | (t & 0x3F);
else if ((t & 0x80) == 0x00 && j == 0) return (char)t;
else if ((t & 0xE0) == 0xC0 && j == 0) { val = t & 0x1F; i = 2; }
else if ((t & 0xF0) == 0xE0 && j == 0) { val = t & 0x0F; i = 3; }
else if ((t & 0xF8) == 0xF0 && j == 0) { val = t & 0x07; i = 4; }
else return '\uFFFF';
}
return (char)val;
}
public string ReadString(long Length, bool UTF8 = true)
{ if (UTF8) return ReadStringUTF8 (Length);
else return ReadStringASCII(Length); }
public string ReadStringUTF8 (long Length) => ReadBytes(Length).ToUTF8 ();
public string ReadStringASCII(long Length) => ReadBytes(Length).ToASCII();
public string ReadString(long? Length, bool UTF8 = true)
{ if (UTF8) return ReadStringUTF8 (Length);
else return ReadStringASCII(Length); }
public string RS(long Length, bool UTF8 = true) =>
UTF8 ? RSUTF8(Length) : RSASCII(Length);
public string ReadStringUTF8 (long? Length) => ReadBytes(Length).ToUTF8 ();
public string ReadStringASCII(long? Length) => ReadBytes(Length).ToASCII();
public byte[] ReadBytes(long Length, int Offset = 0)
{ byte[] Buf = new byte[Length]; if (Offset > 0) stream.Position = Offset;
stream.Read(Buf, 0, (int)Length); return Buf; }
public void ReadBytes(long Length, byte[] Buf, long Offset = 0)
{ if (Offset > 0) stream.Position = Offset; stream.Read(Buf, 0, (int)Length); }
public string RSUTF8 (long length) => RBy(length).ToUTF8 ();
public string RSASCII(long length) => RBy(length).ToASCII();
public byte[] ReadBytes(long? Length, int Offset = 0)
{ if (Length == null) return new byte[0]; else return ReadBytes((long)Length, Offset); }
public void ReadBytes(long Length, byte Bits, byte[] Buf, long Offset = 0)
{ if (Offset > 0) stream.Seek(Offset, 0);
if (Bits > 0 && Bits < 8) for (i0 = 0; i0 < Length; i0++) Buf[i0] = ReadBits(Bits); }
public byte ReadBits(byte Bits)
public string RS(long? length, bool utf8 = true) =>
utf8 ? RSUTF8(length) : RSASCII(length);
public string RSUTF8 (long? length) => RBy(length).ToUTF8 ();
public string RSASCII(long? length) => RBy(length).ToASCII();
public byte[] RBy(long length, int offset = -1)
{ byte[] Buf = new byte[length]; if (offset > -1) s.Position = offset;
s.Read(Buf, 0, (int)length); return Buf; }
public int RBy(long length, byte[] buf, long offset = -1)
{ if (offset > -1) s.Position = offset; return s.Read(buf, 0, (int)length); }
public byte[] RBy(long? length, int offset = -1)
{ if (length == null) return new byte[0]; else return RBy((long)length, offset); }
public void RBy(long length, byte bits, byte[] buf, long offset = -1)
{ if (offset > -1) s.Seek(offset, 0);
if (bits > 0 && bits < 8) for (i = 0; i < length; i++) buf[i] = RBi(bits); CR(); }
public byte RBi(byte bits)
{
BitRead += Bits;
TempBitRead = 8 - BitRead;
if (TempBitRead < 0)
bitRead += bits;
tempBitRead = 8 - bitRead;
if (tempBitRead < 0)
{
BitRead = (byte)-TempBitRead;
TempBitRead = 8 + TempBitRead;
ValRead = (ushort)((ValRead << 8) | (byte)stream.ReadByte());
bitRead = (byte)-tempBitRead;
tempBitRead = 8 + tempBitRead;
valRead = (ushort)((valRead << 8) | (byte)s.ReadByte());
}
return (byte)((ValRead >> TempBitRead) & ((1 << Bits) - 1));
return (byte)((valRead >> tempBitRead) & ((1 << bits) - 1));
}
public byte ReadHalfByte() => ReadBits(4);
public void Write(byte val, byte Bits)
public byte RHB() => RBi(4);
public void W(int val, byte bits)
{
BitWrite += Bits;
TempBitWrite = 8 - BitWrite;
if (TempBitWrite < 0)
val &= (1 << bits) - 1;
bitWrite += bits;
tempBitWrite = 8 - bitWrite;
if (tempBitWrite < 0)
{
BitWrite = (byte)-TempBitWrite;
TempBitWrite = 8 + TempBitWrite;
stream.WriteByte((byte)(ValWrite | (val >> BitWrite)));
ValWrite = 0;
bitWrite = (byte)-tempBitWrite;
tempBitWrite = 8 + tempBitWrite;
s.WriteByte((byte)(valWrite | (val >> bitWrite)));
valWrite = 0;
}
ValWrite |= (byte)(val << TempBitWrite);
valWrite |= val << tempBitWrite;
valWrite &= 0xFF;
}
public void CheckRead () { if (BitRead > 0) ValRead = 0; BitRead = 8; }
public void CheckWrited() { if (BitWrite > 0) { Write(ValWrite); ValWrite = BitWrite = 0; } }
public void CR() //CheckRead
{ if (bitRead > 0) valRead = 0; bitRead = 8; }
public void CW() //CheckWrite
{ if (bitWrite > 0) { s.WriteByte((byte)valWrite); valWrite = 0; bitWrite = 0; } }
public byte[] ToArray(bool Close)
{ byte[] Data = ToArray(); if (Close) this.Close(); return Data; }
public byte[] ToArray(bool close)
{ byte[] Data = ToArray(); if (close) Dispose(); return Data; }
public byte[] ToArray()
{
long Position = stream.Position;
stream.Position = 0;
byte[] Data = ReadBytes(stream.Length);
stream.Position = Position;
long Position = s.Position;
byte[] Data = RBy(s.Length, 0);
s.Position = Position;
return Data;
}
}
+18 -54
View File
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>KKdMainLib</RootNamespace>
<AssemblyName>KKdMainLib</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Authors>korenkonder</Authors>
<Company></Company>
<Configuration></Configuration>
<Copyright>korenkonder © 2018-2020</Copyright>
<Description>A simple library for working with Project Diva AC/DT/F/AFT/F2/X/FT/M39 files</Description>
<FileVersion>0.4.9.0</FileVersion>
<PackageId>KKdMainLib</PackageId>
<Product>KKdMainLib</Product>
<TargetFramework>netstandard2.0</TargetFramework>
<Title>KKdMainLib</Title>
<Version>0.4.9.0</Version>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -22,8 +23,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -35,47 +36,10 @@
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="DB\Aet.cs" />
<Compile Include="DB\Auth.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="MessagePack\JSONIO.cs" />
<Compile Include="MessagePack\MPExt.cs" />
<Compile Include="MessagePack\MsgPack.cs" />
<Compile Include="MessagePack\IO.cs" />
<Compile Include="Types\Half.cs" />
<Compile Include="Types\IKeyFrame.cs" />
<Compile Include="Types\KKdList.cs" />
<Compile Include="Types\Pointer.cs" />
<Compile Include="Types\Vector.cs" />
<Compile Include="A3DA.cs" />
<Compile Include="Aet.cs" />
<Compile Include="DataBank.cs" />
<Compile Include="DCC.cs" />
<Compile Include="DEX.cs" />
<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="Properties\AssemblyInfo.cs" />
<ProjectReference Include="..\KKdBaseLib\KKdBaseLib.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
+105 -288
View File
@@ -1,367 +1,184 @@
using System;
using System.Linq;
using System.Windows.Forms;
using System.Globalization;
using System.Collections.Generic;
using KKdMainLib.IO;
using KKdBaseLib;
using A3DADict = System.Collections.Generic.Dictionary<string, object>;
namespace KKdMainLib
{
public static unsafe class Main
{
public static void ConsoleDesign(string text, params string[] args)
{
text = string.Format(text, args);
string Text = "█ █";
Text = Text.Remove(3) + text + Text.Remove(0, text.Length + 3);
Console.WriteLine(Text);
}
public static void ConsoleDesign(bool Fill)
{
if (Fill) Console.WriteLine("████████████████████████████████████████████████████");
else Console.WriteLine("█ █");
}
public const string TimeFormatHHmmssfff = "{0:d2}:{1:d2}:{2:d2}.{3:d3}";
public static void WriteTime(this TimeSpan time, bool WriteLine = false)
public static void WT(this TimeSpan time, bool writeLine = false)
{
if (WriteLine) Console.WriteLine(TimeFormatHHmmssfff,
if (writeLine) Console.WriteLine(TimeFormatHHmmssfff,
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
else Console.Write (TimeFormatHHmmssfff,
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
}
public static void WriteTime(this TimeSpan time, string Text, bool WriteLine = true)
public static void WT(this TimeSpan time, string text, bool writeLine = true)
{
if (WriteLine) Console.WriteLine(TimeFormatHHmmssfff + " - " + Text,
if (writeLine) Console.WriteLine(TimeFormatHHmmssfff + " - " + text,
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
else Console.Write (TimeFormatHHmmssfff + " - " + Text,
else Console.Write (TimeFormatHHmmssfff + " - " + text,
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
}
private static string GetArgs(string name, bool And, params string[] ext)
{
string Out = "";
if (And) Out = "|";
Out += name + " files (";
for (int i = 0; i < ext.Length; i++)
{ Out += "*." + ext[i]; if (i + 1 < ext.Length) Out += ", "; }
Out += ")|";
for (int i = 0; i < ext.Length; i++)
{ Out += "*." + ext[i]; if (i + 1 < ext.Length) Out += ";"; }
return Out;
}
private static string GetArgs(string name, params string[] ext)
{
string Out = name + " files (";
for (int i = 0; i < ext.Length; i++)
{ Out += "*." + ext[i]; if (i + 1 < ext.Length) Out += ", "; }
Out += ")|";
for (int i = 0; i < ext.Length; i++)
{ Out += "*." + ext[i]; if (i + 1 < ext.Length) Out += ";"; }
return Out;
}
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 WAV = GetArgs("WAV", true, "wav");
FileNames = new string[0];
if (code == 1)
{
OpenFileDialog ofd = new OpenFileDialog { InitialDirectory = Application.StartupPath,
Multiselect = true, Title = "Choose file(s) to open:" };
ofd.Filter = GetArgs("All;", false, "*");
if (filetype == "a3da") ofd.Filter = GetArgs("A3DA", "a3da", "farc", "json", "mp") +
GetArgs("A3DA", true, "a3da") + GetArgs("FARC", true, "farc") + JSON + MsgPack;
else if (filetype == "bin" ) ofd.Filter = GetArgs("BIN" , "bin", "json", "mp") +
BIN + JSON + MsgPack;
else if (filetype == "bon" ) ofd.Filter = GetArgs("BON" , "bon", "bin", "json", "mp") +
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", "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 == "json") ofd.Filter = "JSON (*.json)|*.json";
else if (filetype == "kki" ) ofd.Filter = GetArgs("KKI", "kki");
else if (filetype == "mp" ) ofd.Filter = GetArgs("MessagePack", "mp");
else if (filetype == "ppd" ) ofd.Filter = GetArgs("PPD", "ppd", "pak", "mod") +
GetArgs("PPD", true, "ppd") + GetArgs("PAK", true, "pak") + GetArgs("MOD", true, "mod");
else if (filetype == "str" ) ofd.Filter = GetArgs("STR", "str", "bin", "json", "mp") +
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");
if (ofd.ShowDialog() == DialogResult.OK)
FileNames = ofd.FileNames;
}
else if (code == 2)
{
OpenFileDialog ofd = new OpenFileDialog { InitialDirectory = Application.StartupPath,
ValidateNames = false, CheckFileExists = false, Filter = " | ", CheckPathExists = true,
Title = "Choose any file in folder:", FileName = "Folder Selection." };
if (ofd.ShowDialog() == DialogResult.OK)
return Path.GetDirectoryName(ofd.FileName);
}
return "";
}
public static void ChooseSave(string filetype,
out string InitialDirectory, out string[] FileNames)
{
InitialDirectory = "";
FileNames = new string[0];
Console.WriteLine("Choose file to save:");
SaveFileDialog sfd = new SaveFileDialog { InitialDirectory = Application.StartupPath };
switch (filetype)
{
case "kki":
sfd.Filter = "KKI file (*.kki)|*.kki";
break;
}
if (sfd.ShowDialog() == DialogResult.OK)
{
InitialDirectory = sfd.InitialDirectory.ToString();
FileNames = sfd.FileNames;
}
}
public static string NullTerminated(this string Source, ref int i, byte End)
public static string NT(this string source, ref int i, byte end)
{
string s = "";
while (true)
{
if (Source[i] == End) break;
else s += Source[i];
if (source[i] == end) break;
else s += source[i];
i++;
}
return s;
}
public static bool StartsWith(this Dictionary<string, object> Dict, string args, char Split) =>
Dict.StartsWith(args.Split(Split));
public static bool SW(this A3DADict dict, string args, char split = '.') =>
dict.SW(args.Split(split));
public static bool StartsWith(this Dictionary<string, object> Dict, string args) =>
Dict.StartsWith(args.Split('.'));
public static bool StartsWith(this Dictionary<string, object> Dict, string[] args)
public static bool SW(this A3DADict dict, string[] args)
{
Dictionary<string, object> bufDict = new Dictionary<string, object>();
if (Dict == null)
Dict = new Dictionary<string, object>();
if (dict == null || args.Length < 1) return false;
args[0] = args[0].ToLower();
if (args.Length > 1)
{
string[] NewArgs = new string[args.Length - 1];
string[] newArgs = new string[args.Length - 1];
for (int i = 0; i < args.Length - 1; i++)
NewArgs[i] = args[i + 1];
if (!Dict.ContainsKey(args[0]))
return false;
bufDict = (Dictionary<string, object>)Dict[args[0]];
return StartsWith(bufDict, NewArgs);
newArgs[i] = args[i + 1];
return dict.ContainsKey(args[0]) ? SW((A3DADict)dict[args[0]], newArgs) : false;
}
return Dict.ContainsKey(args[0]);
return dict.ContainsKey(args[0]);
}
public static bool FindValue(this Dictionary<string, object> Dict,
ref bool value, char Split, string args) =>
Dict.FindValue(out string val, args.Split(Split)) ? bool.TryParse(val, out value) : false;
public static bool FV(this A3DADict dict, ref bool value, char split, string args) =>
dict.FV(out string val, args.Split(split)) ? bool.TryParse(val, out value) : false;
public static bool FindValue(this Dictionary<string, object> Dict,
ref int value, char Split, string args) =>
Dict.FindValue(out string val, args.Split(Split)) ? int.TryParse(val, out value) : false;
public static bool FV(this A3DADict dict, ref int value, char split, string args) =>
dict.FV(out string val, args.Split(split)) ? int.TryParse(val, out value) : false;
public static bool FindValue(this Dictionary<string, object> Dict,
ref double value, char Split, string args) =>
Dict.FindValue(out string val, args.Split(Split)) ? val.ToDouble( out value) : false;
public static bool FV(this A3DADict dict, ref float value, char split, string args) =>
dict.FV(out string val, args.Split(split)) ? val.ToF32(out value) : false;
public static bool FindValue(this Dictionary<string, object> Dict,
ref string value, char Split, string args)
{ if (Dict.FindValue(out string val, args.Split(Split)))
public static bool FV(this A3DADict dict, ref double value, char split, string args) =>
dict.FV(out string val, args.Split(split)) ? val.ToF64(out value) : false;
public static bool FV(this A3DADict dict, ref string value, char split, string args)
{ if (dict.FV(out string val , args.Split(split)))
{ value = val; return true; } return false; }
public static bool FindValue(this Dictionary<string, object> Dict,
out bool value, string args)
{ if (Dict.FindValue(out string val, args.Split('.' )))
public static bool FV(this A3DADict dict, out bool value, string args)
{ if (dict.FV(out string val , args.Split('.' )))
return bool.TryParse(val, out value); value = false; return false; }
public static bool FindValue(this Dictionary<string, object> Dict,
out int value, string args)
{ if (Dict.FindValue(out string val, args.Split('.' )))
public static bool FV(this A3DADict dict, out int value, string args)
{ if (dict.FV(out string val , args.Split('.' )))
return int.TryParse(val, out value); value = 0; return false; }
public static bool FindValue(this Dictionary<string, object> Dict,
out double value, string args)
{ if (Dict.FindValue(out string val, args.Split('.' )))
return val.ToDouble(out value); value = 0; return false; }
public static bool FV(this A3DADict dict, out float value, string args)
{ if (dict.FV(out string val , args.Split('.' )))
return val.ToF32(out value); value = 0; return false; }
public static bool FindValue(this Dictionary<string, object> Dict,
out int? value, string args)
{ if (Dict.FindValue(out string val, args.Split('.' )))
public static bool FV(this A3DADict dict, out double value, string args)
{ if (dict.FV(out string val , args.Split('.' )))
return val.ToF64(out value); value = 0; return false; }
public static bool FV(this A3DADict dict, out int? value, string args)
{ if (dict.FV(out string val , args.Split('.' )))
{ bool Val = int.TryParse(val, out int _value);
value = _value; return Val; } value = null; return false; }
public static bool FV(this A3DADict dict, out float? value, string args)
{ if (dict.FV(out string val , args.Split('.' )))
return val.ToF32(out value); value = null; return false; }
public static bool FindValue(this Dictionary<string, object> Dict,
out double? value, string args)
{ if (Dict.FindValue(out string val, args.Split('.' )))
return ToDouble(val, out value); value = null; return false; }
public static bool FV(this A3DADict dict, out double? value, string args)
{ if (dict.FV(out string val , args.Split('.' )))
return val.ToF64(out value); value = null; return false; }
public static bool FindValue(this Dictionary<string, object> Dict,
out string value, string args)
{ if (Dict.FindValue(out string val, args.Split('.' )))
{ value = val; return true; } value = null; return false; }
public static bool FV(this A3DADict dict, out string value, string args) =>
dict.FV(out value, args.Split('.' ));
public static bool FindValue(this Dictionary<string, object> Dict,
out string value, string[] args)
public static bool FV(this A3DADict dict, out string value, string[] args)
{
value = "";
if (Dict == null) return false;
else if (args.Length < 1) return false;
value = null;
if (dict == null || args.Length < 1) return false;
if (!Dict.ContainsKey(args[0])) return false;
args[0] = args[0].ToLower();
if (!dict.ContainsKey(args[0])) return false;
else if (args.Length > 1)
{
string[] NewArgs = new string[args.Length - 1];
for (int i = 0; i < args.Length - 1; i++) NewArgs[i] = args[i + 1];
return ((Dictionary<string, object>)Dict[args[0]]).FindValue(out value, NewArgs);
string[] newArgs = new string[args.Length - 1];
for (int i = 0; i < args.Length - 1; i++) newArgs[i] = args[i + 1];
return ((A3DADict)dict[args[0]]).FV(out value, newArgs);
}
else if (args.Length == 1)
{
if (Dict[args[0]].GetType() == Dict.GetType())
return ((Dictionary<string, object>)Dict[args[0]]).FindValue(out value, args);
else if (Dict[args[0]].GetType() != typeof(string)) return false;
if (dict[args[0]].GetType() == dict.GetType())
return ((A3DADict)dict[args[0]]).FV(out value, args);
else if (dict[args[0]].GetType() != typeof(string)) return false;
}
value = (string)Dict[args[0]];
value = (string)dict[args[0]];
return true;
}
public static void GetDictionary(this Dictionary<string, object> Dict,
string args, string value, char Split = '.') =>
Dict.GetDictionary(args.Split(Split), value);
public static void GetDictionary(this Dictionary<string, object> Dict,
string[] args, string value)
public static void GD(this A3DADict dict, string args, char split = '.')
{
Dictionary<string, object> bufDict = new Dictionary<string, object>();
if (Dict == null) Dict = new Dictionary<string, object>();
if (args.Length > 1)
{
string[] NewArgs = new string[args.Length - 1];
for (int i = 0; i < args.Length - 1; i++) NewArgs[i] = args[i + 1];
if (!Dict.ContainsKey(args[0])) Dict.Add(args[0], null);
if (Dict[args[0]] != null)
{
if (Dict[args[0]].GetType() == typeof(string))
Dict[args[0]] = new Dictionary<string, object> { { "", Dict[args[0]] } };
}
else Dict[args[0]] = new Dictionary<string, object>();
bufDict = (Dictionary<string, object>)Dict[args[0]];
bufDict.GetDictionary(NewArgs, value);
Dict[args[0]] = bufDict;
}
else if (!Dict.ContainsKey(args[0])) Dict.Add(args[0], value);
string[] dataArray = args.Split('=');
if (dataArray.Length == 2)
dict.GD(dataArray[0].Split(split), dataArray[1]);
dataArray = null;
}
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 void GD(this A3DADict dict, string args, string value, char split = '.') =>
dict.GD(args.Split(split), value);
public static string ToTitleCase(this string s)
{ return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s); }
public static void GD(this A3DADict dict, string[] args, string value)
{
if (dict == null) dict = new A3DADict();
else if (args.Length < 1) return;
public static int[] SortWriter(this int Length)
args[0] = args[0].ToLower();
if (args.Length > 1)
{
string[] newArgs = new string[args.Length - 1];
for (int i = 0; i < args.Length - 1; i++) newArgs[i] = args[i + 1];
if (!dict.ContainsKey(args[0])) dict.Add(args[0], null);
if (dict[args[0]] != null)
{
if (dict[args[0]].GetType() == typeof(string))
dict[args[0]] = new A3DADict { { "", dict[args[0]] } };
}
else dict[args[0]] = new A3DADict();
A3DADict bufDict = (A3DADict)dict[args[0]];
bufDict.GD(newArgs, value);
dict[args[0]] = bufDict;
}
else if (!dict.ContainsKey(args[0])) dict.Add(args[0], value);
}
public static TKey GK<TKey, TVal>(this Dictionary<TKey, TVal> dict, TVal val) =>
dict.First((System.Collections.Generic.KeyValuePair<TKey, TVal> x) => x.Value.Equals(val)).Key;
public static string TTC(this string s) =>
CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s);
public static int[] SW(this int length)
{
int i = 0;
List<string> A = new List<string>();
for (i = 0; i < Length; i++) A.Add(i.ToString());
for (i = 0; i < length; i++) A.Add(i.ToString());
A.Sort();
int[] B = new int[Length];
for (i = 0; i < Length; i++) B[i] = int.Parse(A[i]);
int[] B = new int[length];
for (i = 0; i < length; i++) B[i] = int.Parse(A[i]);
return B;
}
private static readonly string NumberDecimalSeparator =
NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
public static string ToString(this object d)
{
if (d == null) return "Null";
else if (d is float F32) return ToString(F32);
else if (d is double F64) return ToString(F64);
return d.ToString();
}
public static string ToString(this bool? d) => d.GetValueOrDefault().ToString();
public static string ToString(this bool d) => d.ToString().ToLower();
public static string ToString(this sbyte? d) => d.GetValueOrDefault().ToString();
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; }
public enum Format : byte
{
NULL = 0,
DT = 1,
PDA = 2,
DT2 = 3,
DTe = 4,
F = 5,
FT = 6,
F2LE = 7,
F2BE = 8,
MGF = 9,
X = 10,
XHD = 11,
}
}
}
-226
View File
@@ -1,226 +0,0 @@
using System;
namespace KKdMainLib
{
public static class MathExtensions
{
private const double RadPi = 180 / Math.PI;
public static double ToDegrees(this double val) => val * RadPi;
public static double ToRadians(this double val) => val / RadPi;
public static double Acos (this double d ) => Math.Acos (d );
public static double Asin (this double d ) => Math.Asin (d );
public static double Atan (this double d ) => Math.Atan (d );
public static double Aсtg (this double d ) => 1 / Math.Atan (d );
public static double Cos (this double d ) => Math.Cos (d );
public static double Cosh (this double val) => Math.Cosh (val);
public static double Sin (this double a ) => Math.Sin (a );
public static double Sinh (this double val) => Math.Sinh (val);
public static double Tan (this double a ) => Math.Tan (a );
public static double Tanh (this double val) => Math.Tanh (val);
public static double Ctg (this double a ) => 1 / Math.Tan (a );
public static double Ctgh (this double val) => 1 / Math.Tanh (val);
public static double Abs (this double val) => Math.Abs (val);
public static double Ceiling(this double a ) => Math.Ceiling(a );
public static double Exp (this double d ) => Math.Exp (d );
public static double Log (this double d ) => Math.Log (d );
public static double Log10 (this double d ) => Math.Log10 (d );
public static double Round (this double d ) => Math.Round (d );
public static int Sign (this double val) => Math.Sign (val);
public static double Sqrt (this double d ) => Math.Sqrt (d );
public static double Atan2(this double y , double x ) => Math.Atan2(y , x );
public static double Log (this double val , double newBase) => Math.Log (val , newBase);
public static double Max (this double val1, double val2 ) => Math.Max (val1, val2 );
public static double Min (this double val1, double val2 ) => Math.Min (val1, val2 );
public static double Pow (this double x , double y ) => Math.Pow (x , y );
public static double Round(this double val , int d ) => Math.Round(val , d );
public static void FloorCeiling( ref double Value) =>
Value = Value % 1 >= 0.5 ? (long)(Value + 0.5) : (long) Value;
public static long FloorCeiling(this double Value) =>
Value % 1 >= 0.5 ? (long)(Value + 0.5) : (long) Value;
public static int Align(this int value, int alignement, int divide = 1) =>
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
public static uint Align(this uint value, uint alignement, uint divide = 1) =>
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
public static long Align(this long value, long alignement, long divide = 1) =>
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
public static ulong Align(this ulong value, ulong alignement, ulong divide = 1) =>
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
public static byte[] buf = new byte[8];
public static unsafe byte* bufPtr = buf.GetPtr();
public static unsafe long Endian(this long LE, byte Len, bool IsBE)
{ if (IsBE) { for (byte i = 0; i < Len; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
for (byte i = 0; i < Len; i++) { LE |= bufPtr[i]; if (i < Len - 1) LE <<= 8; } } return LE; }
public static unsafe ulong Endian(this ulong LE, byte Len, bool IsBE)
{ if (IsBE) { for (byte i = 0; i < Len; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
for (byte i = 0; i < Len; i++) { LE |= bufPtr[i]; if (i < Len - 1) LE <<= 8; } } return LE; }
public static sbyte CITSB(this int c)
{
if (c > 0x7F) c = 0x7F;
else if (c < -0x80) c = -0x80;
return (sbyte)c;
}
public static byte CITB(this int c)
{
if (c > 0xFF) c = 0xFF;
else if (c < 0x00) c = 0x00;
return (byte)c;
}
public static short CITS(this int c)
{
if (c > 0x7FFF) c = 0x7FFF;
else if (c < -0x8000) c = -0x8000;
return (short)c;
}
public static ushort CITUS(this int c)
{
if (c > 0xFFFF) c = 0xFFFF;
else if (c < 0x0000) c = 0x0000;
return (ushort)c;
}
public static sbyte CFTSB(this float c)
{
c = c.Round();
if (c > 0x7F) c = 0x7F;
else if (c < -0x80) c = -0x80;
return (sbyte)c;
}
public static byte CFTB(this float c)
{
c = c.Round();
if (c > 0xFF) c = 0xFF;
else if (c < 0x00) c = 0x00;
return (byte)c;
}
public static short CFTS(this float c)
{
c = c.Round();
if (c > 0x7FFF) c = 0x7FFF;
else if (c < -0x8000) c = -0x8000;
return (short)c;
}
public static ushort CFTUS(this float c)
{
c = c.Round();
if (c > 0xFFFF) c = 0xFFFF;
else if (c < 0x0000) c = 0x0000;
return (ushort)c;
}
public static int CFTI(this float c)
{
c = c.Round();
if (c > 0x7FFFFFFF) c = 0x7FFFFFFF;
else if (c < -0x80000000) c = -0x80000000;
return (int)c;
}
public static uint CFTUI(this float c)
{
c = c.Round();
if (c > 0xFFFFFFFF) c = 0xFFFFFFFF;
else if (c < 0x00000000) c = 0x00000000;
return (uint)c;
}
public static float Round(this float c) => (float)Math.Round(c);
public static sbyte CFTSB(this double c)
{
c = Math.Round(c);
if (c > 0x7F) c = 0x7F;
else if (c < -0x80) c = -0x80;
return (sbyte)c;
}
public static byte CFTB(this double c)
{
c = Math.Round(c);
if (c > 0xFF) c = 0xFF;
else if (c < 0x00) c = 0x00;
return (byte)c;
}
public static short CFTS(this double c)
{
c = Math.Round(c);
if (c > 0x7FFF) c = 0x7FFF;
else if (c < -0x8000) c = -0x8000;
return (short)c;
}
public static ushort CFTUS(this double c)
{
c = Math.Round(c);
if (c > 0xFFFF) c = 0xFFFF;
else if (c < 0x0000) c = 0x0000;
return (ushort)c;
}
public static int CFTI(this double c)
{
c = Math.Round(c);
if (c > 0x7FFFFFFF) c = 0x7FFFFFFF;
else if (c < -0x80000000) c = -0x80000000;
return (int)c;
}
public static uint CFTUI(this double c)
{
c = Math.Round(c);
if (c > 0xFFFFFFFF) c = 0xFFFFFFFF;
else if (c < 0x00000000) c = 0x00000000;
return (uint)c;
}
public static unsafe sbyte* GetPtr(this sbyte[] array)
{ sbyte* Ptr; fixed ( sbyte* tempPtr = array) Ptr = tempPtr; return Ptr; }
public static unsafe byte* GetPtr(this byte[] array)
{ byte* Ptr; fixed ( byte* tempPtr = array) Ptr = tempPtr; return Ptr; }
public static unsafe short* GetPtr(this short[] array)
{ short* Ptr; fixed ( short* tempPtr = array) Ptr = tempPtr; return Ptr; }
public static unsafe ushort* GetPtr(this ushort[] array)
{ ushort* Ptr; fixed (ushort* tempPtr = array) Ptr = tempPtr; return Ptr; }
public static unsafe int* GetPtr(this int[] array)
{ int* Ptr; fixed ( int* tempPtr = array) Ptr = tempPtr; return Ptr; }
public static unsafe uint* GetPtr(this uint[] array)
{ uint* Ptr; fixed ( uint* tempPtr = array) Ptr = tempPtr; return Ptr; }
public static unsafe long* GetPtr(this long[] array)
{ long* Ptr; fixed ( long* tempPtr = array) Ptr = tempPtr; return Ptr; }
public static unsafe ulong* GetPtr(this ulong[] array)
{ ulong* Ptr; fixed ( ulong* tempPtr = array) Ptr = tempPtr; return Ptr; }
public static unsafe float* GetPtr(this float[] array)
{ float* Ptr; fixed ( float* tempPtr = array) Ptr = tempPtr; return Ptr; }
public static unsafe double* GetPtr(this double[] array)
{ double* Ptr; fixed (double* tempPtr = array) Ptr = tempPtr; return Ptr; }
}
}
-361
View File
@@ -1,361 +0,0 @@
using System;
using KKdMainLib.IO;
using KKdMainLib.Types;
namespace KKdMainLib.MessagePack
{
public class IO
{
public Stream _IO;
public IO( ) => _IO = File.OpenWriter();
public IO(Stream IO) => _IO = IO;
public void Close() => _IO.Close();
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
public MsgPack Read(bool Array = false)
{
MsgPack MsgPack = MsgPack.New;
byte Unk = _IO.ReadByte();
Types Type = (Types)Unk;
if (!Array)
{
MsgPack.Name = ReadString(Type);
if (MsgPack.Name != null) { Unk = _IO.ReadByte(); Type = (Types)Unk; }
}
bool FixArr = Type >= Types.FixArr && Type <= Types.FixArrMax;
bool FixMap = Type >= Types.FixMap && Type <= Types.FixMapMax;
bool FixStr = Type >= Types.FixStr && Type <= Types.FixStrMax;
bool PosInt = Type >= Types.PosInt && Type <= Types.PosIntMax;
bool NegInt = Type >= Types.NegInt && Type <= Types.NegIntMax;
if (FixArr || FixMap || FixStr || PosInt || NegInt)
{
if (FixMap)
{
MsgPack.Object = KKdList<MsgPack>.New;
for (int i = 0; i < Unk - (byte)Types.FixMap; i++) MsgPack.Add( Read(false));
}
else if (FixArr)
{
MsgPack.Object = new MsgPack[Unk - (byte)Types.FixArr];
for (int i = 0; i < Unk - (byte)Types.FixArr; i++) MsgPack[i] = Read( true);
}
else if (FixStr) MsgPack.Object = ReadString( Type);
else if (PosInt) MsgPack.Object = Unk;
else if (NegInt) MsgPack.Object = (sbyte)Unk;
return MsgPack;
}
while (true)
{
if (ReadNil (ref MsgPack, ref Type)) break;
if (ReadArr (ref MsgPack, ref Type)) break;
if (ReadMap (ref MsgPack, ref Type)) break;
if (ReadExt (ref MsgPack, ref Type)) break;
if (ReadString (ref MsgPack, ref Type)) break;
if (ReadBoolean(ref MsgPack, ref Type)) break;
if (ReadBytes (ref MsgPack, ref Type)) break;
if (ReadInt (ref MsgPack, ref Type)) break;
if (ReadUInt (ref MsgPack, ref Type)) break;
if (ReadFloat (ref MsgPack, ref Type)) break;
break;
}
return MsgPack;
}
private bool ReadInt (ref MsgPack MsgPack, ref Types Type)
{
if (Type == Types.Int8 ) MsgPack.Object = _IO.ReadSByte();
else if (Type == Types.Int16) MsgPack.Object = _IO.ReadInt16Endian(true);
else if (Type == Types.Int32) MsgPack.Object = _IO.ReadInt32Endian(true);
else if (Type == Types.Int64) MsgPack.Object = _IO.ReadInt64Endian(true);
else return false;
return true;
}
private bool ReadUInt (ref MsgPack MsgPack, ref Types Type)
{
if (Type == Types.UInt8 ) MsgPack.Object = _IO.ReadByte();
else if (Type == Types.UInt16) MsgPack.Object = _IO.ReadUInt16Endian(true);
else if (Type == Types.UInt32) MsgPack.Object = _IO.ReadUInt32Endian(true);
else if (Type == Types.UInt64) MsgPack.Object = _IO.ReadUInt64Endian(true);
else return false;
return true;
}
private bool ReadFloat (ref MsgPack MsgPack, ref Types Type)
{
if (Type == Types.Float32) MsgPack.Object = _IO.ReadSingleEndian(true);
else if (Type == Types.Float64) MsgPack.Object = _IO.ReadDoubleEndian(true);
else return false;
return true;
}
private bool ReadBoolean(ref MsgPack MsgPack, ref Types Type)
{
if (Type == Types.False) MsgPack.Object = false;
else if (Type == Types.True ) MsgPack.Object = true ;
else return false;
return true;
}
private bool ReadBytes (ref MsgPack MsgPack, ref Types Type)
{
int Length = 0;
if (Type == Types.Bin8 ) Length = _IO.ReadByte();
else if (Type == Types.Bin16) Length = _IO.ReadInt16Endian(true);
else if (Type == Types.Bin32) Length = _IO.ReadInt32Endian(true);
else return false;
MsgPack.Object = _IO.ReadBytes(Length);
return true;
}
private bool ReadString (ref MsgPack MsgPack, ref Types Type)
{
string val = ReadString(Type);
if (val != null) MsgPack.Object = val;
else return false;
return true;
}
private string ReadString(Types Val)
{
if (Val >= Types.FixStr && Val <= Types.FixStrMax)
return _IO.ReadString(Val - Types.FixStr);
else if (Val >= Types. Str8 && Val <= Types. Str32 )
{
Enum.TryParse(Val.ToString(), out Types Type);
int Length = 0;
if (Type == Types.Str8 ) Length = _IO.ReadByte();
else if (Type == Types.Str16) Length = _IO.ReadInt16Endian(true);
else Length = _IO.ReadInt32Endian(true);
return _IO.ReadString(Length);
}
return null;
}
private bool ReadNil(ref MsgPack MsgPack, ref Types Type)
{
if (Type == Types.Nil) MsgPack.Object = null;
else return false;
return true;
}
private bool ReadArr(ref MsgPack MsgPack, ref Types Type)
{
int Length = 0;
if (Type == Types.Arr16) Length = _IO.ReadInt16Endian(true);
else if (Type == Types.Arr32) Length = _IO.ReadInt32Endian(true);
else return false;
MsgPack.Object = new MsgPack[Length];
for (int i = 0; i < Length; i++) MsgPack[i] = Read(true);
return true;
}
private bool ReadMap(ref MsgPack MsgPack, ref Types Type)
{
int Length = 0;
if (Type == Types.Map16) Length = _IO.ReadInt16Endian(true);
else if (Type == Types.Map32) Length = _IO.ReadInt32Endian(true);
else return false;
MsgPack.Object = KKdList<MsgPack>.New;
for (int i = 0; i < Length; i++) MsgPack.Add(Read());
return true;
}
private bool ReadExt(ref MsgPack MsgPack, ref Types Type)
{
int Length = 0;
if (Type == Types.FixExt1 ) Length = 1 ;
else if (Type == Types.FixExt2 ) Length = 2 ;
else if (Type == Types.FixExt4 ) Length = 4 ;
else if (Type == Types.FixExt8 ) Length = 8 ;
else if (Type == Types.FixExt16) Length = 16;
else if (Type == Types. Ext8 ) Length = _IO.ReadByte();
else if (Type == Types. Ext16) Length = _IO.ReadInt16Endian(true);
else if (Type == Types. Ext32) Length = _IO.ReadInt32Endian(true);
else return false;
MsgPack.Object = new MsgPack.Ext { Type = _IO.ReadSByte(), Data = _IO.ReadBytes(Length) };
return true;
}
public IO Write(MsgPack MsgPack, bool IsArray = false)
{
if (MsgPack.Name != null && !IsArray) Write(MsgPack.Name);
Write(MsgPack.Object);
return this;
}
private void Write(object obj)
{
if (obj == null) { WriteNil(); return; }
switch (obj)
{
case KKdList<MsgPack> val: WriteMap(val.Count );
for (int i = 0; i < val.Count ; i++) Write(val[i]); break;
case MsgPack[] val: WriteArr(val.Length);
for (int i = 0; i < val.Length; i++) Write(val[i]); break;
case MsgPack val: Write(val); break;
case byte[] val: Write(val); break;
case bool val: Write(val); break;
case sbyte val: Write(val); break;
case byte val: Write(val); break;
case short val: Write(val); break;
case ushort val: Write(val); break;
case int val: Write(val); break;
case uint val: Write(val); break;
case long val: Write(val); break;
case ulong val: Write(val); break;
case float val: Write(val); break;
case double val: Write(val); break;
case string val: Write(val); break;
case MsgPack.Ext val: Write(val); break;
}
}
private void Write( sbyte val) { if (val < -0x20) _IO.WriteByte(0xD0); _IO.Write(val); }
private void Write( byte val) { if (val >= 0x80) _IO.WriteByte(0xCC); _IO.Write(val); }
private void Write( short val) { if (( sbyte)val == val) Write(( sbyte)val);
else if (( byte)val == val) Write(( byte)val);
else { _IO.WriteByte(0xD1); _IO.WriteEndian(val, true); } }
private void Write(ushort val) { if (( byte)val == val) Write(( byte)val);
else { _IO.WriteByte(0xCD); _IO.WriteEndian(val, true); } }
private void Write( int val) { if (( short)val == val) Write(( short)val);
else if ((ushort)val == val) Write((ushort)val);
else { _IO.WriteByte(0xD2); _IO.WriteEndian(val, true); } }
private void Write( uint val) { if ((ushort)val == val) Write((ushort)val);
else { _IO.WriteByte(0xCE); _IO.WriteEndian(val, true); } }
private void Write( long val) { if (( int)val == val) Write(( int)val);
else if (( uint)val == val) Write(( uint)val);
else { _IO.WriteByte(0xD3); _IO.WriteEndian(val, true); } }
private void Write( ulong val) { if (( uint)val == val) Write(( uint)val);
else { _IO.WriteByte(0xCF); _IO.WriteEndian(val, true); } }
private void Write( float val) { if (( long)val == val) Write(( long)val);
else { _IO.WriteByte(0xCA); _IO.WriteEndian(val, true); } }
private void Write(double val) { if (( long)val == val) Write(( long)val);
else if (( float)val == val) Write(( float)val);
else { _IO.WriteByte(0xCB); _IO.WriteEndian(val, true); } }
private void Write( bool val) =>
_IO.WriteByte((byte)(val ? 0xC3 : 0xC2));
private void Write(byte[] val)
{
if (val == null) { WriteNil(); return; }
if (val.Length < 0x100)
{ _IO.WriteByte(0xC4); _IO.WriteByte (( byte)val.Length ); }
else if (val.Length < 0x10000)
{ _IO.WriteByte(0xC5); _IO.WriteEndian((ushort)val.Length, true); }
else
{ _IO.WriteByte(0xC6); _IO.WriteEndian( val.Length, true); }
_IO.Write(val);
}
private void Write(string val)
{
if (val == null) { WriteNil(); return; }
byte[] array = Text.ToUTF8(val);
if (array.Length < 0x20)
_IO.WriteByte((byte)(0xA0 | (array.Length & 0x1F)));
else if (array.Length < 0x100)
{ _IO.WriteByte(0xD9); _IO.WriteByte (( byte)array.Length); }
else if (array.Length < 0x10000)
{ _IO.WriteByte(0xDA); _IO.WriteEndian((ushort)array.Length, true); }
else
{ _IO.WriteByte(0xDB); _IO.WriteEndian( array.Length, true); }
_IO.Write(array);
}
private void WriteNil() => _IO.WriteByte(0xC0);
private void WriteArr(int val)
{
if (val == 0) { WriteNil(); return; }
else if (val < 0x10) _IO.WriteByte((byte)(0x90 | (val & 0x0F)));
else if (val < 0x10000) { _IO.WriteByte(0xDC); _IO.WriteEndian((ushort)val, true); }
else { _IO.WriteByte(0xDD); _IO.WriteEndian( val, true); }
}
private void WriteMap(int val)
{
if (val == 0) { WriteNil(); return; }
else if (val < 0x10) _IO.WriteByte((byte)(0x80 | (val & 0x0F)));
else if (val < 0x10000) { _IO.WriteByte(0xDE); _IO.WriteEndian((ushort)val, true); }
else { _IO.WriteByte(0xDF); _IO.WriteEndian( val, true); }
}
private void Write(MsgPack.Ext val)
{
if (val.Data == null) { WriteNil(); return; }
if (val.Data.Length < 1 ) { WriteNil(); return; }
else if (val.Data.Length == 1 ) _IO.WriteByte(0xD4);
else if (val.Data.Length == 2 ) _IO.WriteByte(0xD5);
else if (val.Data.Length == 4 ) _IO.WriteByte(0xD6);
else if (val.Data.Length == 8 ) _IO.WriteByte(0xD7);
else if (val.Data.Length == 16) _IO.WriteByte(0xD8);
else
{
if (val.Data.Length < 0x100)
{ _IO.WriteByte(0xC7); _IO.WriteByte (( byte)val.Data.Length); }
else if (val.Data.Length < 0x10000)
{ _IO.WriteByte(0xC8); _IO.WriteEndian((ushort)val.Data.Length, true); }
else
{ _IO.WriteByte(0xC9); _IO.WriteEndian( val.Data.Length, true); }
}
_IO.Write(val.Type);
_IO.Write(val.Data);
}
}
public enum Types : byte
{
PosInt = 0b00000000,
FixMap = 0b10000000,
FixArr = 0b10010000,
FixStr = 0b10100000,
Nil = 0b11000000,
NeverUsed = 0b11000001,
False = 0b11000010,
True = 0b11000011,
Bin8 = 0b11000100,
Bin16 = 0b11000101,
Bin32 = 0b11000110,
Ext8 = 0b11000111,
Ext16 = 0b11001000,
Ext32 = 0b11001001,
Float32 = 0b11001010,
Float64 = 0b11001011,
UInt8 = 0b11001100,
UInt16 = 0b11001101,
UInt32 = 0b11001110,
UInt64 = 0b11001111,
Int8 = 0b11010000,
Int16 = 0b11010001,
Int32 = 0b11010010,
Int64 = 0b11010011,
FixExt1 = 0b11010100,
FixExt2 = 0b11010101,
FixExt4 = 0b11010110,
FixExt8 = 0b11010111,
FixExt16 = 0b11011000,
Str8 = 0b11011001,
Str16 = 0b11011010,
Str32 = 0b11011011,
Arr16 = 0b11011100,
Arr32 = 0b11011101,
Map16 = 0b11011110,
Map32 = 0b11011111,
NegInt = 0b11100000,
PosIntMax = 0b01111111,
FixMapMax = 0b10001111,
FixArrMax = 0b10011111,
FixStrMax = 0b10111111,
NegIntMax = 0b11111111,
}
}
-266
View File
@@ -1,266 +0,0 @@
//Original or reader part: https://github.com/MarcosLopezC/LightJson/
using KKdMainLib.IO;
using KKdMainLib.Types;
namespace KKdMainLib.MessagePack
{
public class JSONIO
{
public Stream _IO;
public JSONIO( ) => _IO = File.OpenWriter();
public JSONIO(Stream IO) => _IO = IO;
public void Close() => _IO.Close();
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
public MsgPack Read() => ReadValue();
private MsgPack ReadValue(string Key = null)
{
char c = _IO.SkipWhitespace().PeekCharUTF8();
object obj = null;
if (char.IsDigit(c))
obj = ReadNumber ();
else
switch (c)
{
case '"': obj = ReadString (); break;
case '{': obj = ReadObject (); break;
case '[': obj = ReadArray (); break;
case '-': obj = ReadNumber (); break;
case 't':
case 'f': obj = ReadBoolean(); break;
case 'n': obj = ReadNull (); break;
}
return new MsgPack(Key, obj);
}
private string ReadString()
{
if (!_IO.Assert('"')) return null;
char c;
string s = "";
while (true)
{
c = _IO.ReadCharUTF8();
if (c == '\\')
{
c = _IO.ReadCharUTF8();
switch (char.ToLower(c))
{
case '"' :
case '\\':
case '/' : s += c; break;
case 'b' : s += '\b'; break;
case 'f' : s += '\f'; break;
case 'n' : s += '\n'; break;
case 'r' : s += '\r'; break;
case 't' : s += '\t'; break;
case 'u' : s += ReadUnicodeLiteral(); break;
default: return null;
}
}
else if (c == '"') break;
else if (char.IsControl(c)) return null;
else s += c;
}
return s;
}
private char ReadUnicodeLiteral() =>
(char)((((((ReadHexDigit() << 4) | ReadHexDigit()) << 4) | ReadHexDigit()) << 4) | ReadHexDigit());
private int ReadHexDigit() => byte.Parse(_IO.ReadCharUTF8().ToString(),
System.Globalization.NumberStyles.HexNumber);
private KKdList<MsgPack> ReadObject()
{
KKdList<MsgPack> Obj = KKdList<MsgPack>.New;
if (!_IO.Assert('{')) return KKdList<MsgPack>.Null;
if (_IO.SkipWhitespace().PeekCharUTF8() == '}') { _IO.ReadCharUTF8(); return KKdList<MsgPack>.Null; }
string key;
char c;
while (true)
{
_IO.SkipWhitespace();
key = ReadString();
if (!_IO.SkipWhitespace().Assert(':'))
return KKdList<MsgPack>.Null;
Obj.Add(ReadValue(key));
c = _IO.SkipWhitespace().PeekCharUTF8();
if (c == '}') { _IO.ReadCharUTF8(); break; }
else if (c == ',') { _IO.ReadCharUTF8(); continue; }
else return KKdList<MsgPack>.Null;
}
return Obj;
}
private MsgPack[] ReadArray()
{
KKdList<MsgPack> Obj = KKdList<MsgPack>.New;
if (!_IO.Assert('[')) return null;
if (_IO.SkipWhitespace().PeekCharUTF8() == ']') { _IO.ReadCharUTF8(); return null; }
char c;
while (true)
{
Obj.Add(ReadValue(null));
c = _IO.SkipWhitespace().PeekCharUTF8();
if (c == ']') { _IO.ReadCharUTF8(); break; }
else if (c == ',') { _IO.ReadCharUTF8(); continue; }
else return null;
}
return Obj.ToArray();
}
private object ReadNumber()
{
string s = " ";
_IO.SkipWhitespace();
if (_IO.PeekCharUTF8() == '-') s += _IO.ReadCharUTF8();
if (_IO.PeekCharUTF8() == '0') s += _IO.ReadCharUTF8();
else s += ReadDigits ();
if (_IO.PeekCharUTF8() == '.') s += _IO.ReadCharUTF8() + ReadDigits();
else
{
long val = long.Parse(s);
if (val >= 0x00000000 && val < 0x000000100) return ( byte)val;
else if (val >= -0x00000080 && val < 0x000000080) return ( sbyte)val;
else if (val >= -0x00008000 && val < 0x000008000) return ( short)val;
else if (val >= 0x00000000 && val < 0x000010000) return (ushort)val;
else if (val >= -0x80000000 && val < 0x000800000) return ( int)val;
else if (val >= 0x00000000 && val < 0x100000000) return ( uint)val;
else return val;
}
char c = _IO.PeekCharUTF8();
if (c == 'e' || c == 'E')
{
s += _IO.ReadCharUTF8();
c = _IO.PeekCharUTF8();
if (c == '+' || c == '-') s += _IO.ReadCharUTF8();
s += ReadDigits();
}
double d = s.ToDouble();
return (float)d == d ? (float)d : d;
}
private bool ReadBoolean()
{
char c = _IO.PeekCharUTF8();
if (c == 't' && _IO.Assert( "true")) return true;
else if (c == 'f' && _IO.Assert("false")) return false;
return false;
}
private object ReadNull() { _IO.Assert("null"); return null; }
private string ReadDigits()
{ string s = ""; while (char.IsDigit(_IO.SkipWhitespace().
PeekCharUTF8())) s += _IO.ReadCharUTF8(); return s; }
public JSONIO Write(MsgPack MsgPack, string End = "\n", string TabChar = " ")
{ Write(MsgPack, End, TabChar, "", true); return this; }
public JSONIO Write(MsgPack MsgPack, bool Style = false)
{ Write(MsgPack, "\n", " ", "", Style); return this; }
private JSONIO Write(MsgPack MsgPack, string End, string TabChar, string Tab, bool Style, bool IsArray = false)
{
string OldTab = Tab;
Tab += TabChar;
if (MsgPack.Name != null && !IsArray) _IO.Write("\"" + MsgPack.Name + "\":" + (Style ? " " : ""));
if (MsgPack.Object == null) { WriteNil(); return this; }
if (MsgPack.List.NotNull)
{
WriteMap();
if (Style) _IO.Write(End);
if (MsgPack.List.Count > 1)
for (int i = 0; i < MsgPack.List.Count; i++)
{
if (Style) _IO.Write(Tab);
Write(MsgPack.List[i], End, TabChar, Tab, Style);
if (i + 1 < MsgPack.List.Count) _IO.Write(',');
if (Style) _IO.Write(End);
}
else if (MsgPack.List.Count == 1)
{
if (Style) _IO.Write(Tab);
Write(MsgPack.List[0], End, TabChar, Tab, Style);
if (Style) _IO.Write(End);
}
if (Style) _IO.Write(OldTab);
WriteMap(true);
}
else if (MsgPack.Array != null)
{
WriteArr();
if (Style) _IO.Write(End);
if (MsgPack.Array.Length > 1)
for (int i = 0; i < MsgPack.Array.Length; i++)
{
if (Style) _IO.Write(Tab);
Write(MsgPack.Array[i], End, TabChar, Tab, Style, true);
if (i + 1 < MsgPack.Array.Length) _IO.Write(',');
if (Style) _IO.Write(End);
}
else if (MsgPack.Array.Length == 1)
{
if (Style) _IO.Write(Tab);
Write(MsgPack.Array[0], End, TabChar, Tab, Style, true);
if (Style) _IO.Write(End);
}
if (Style) _IO.Write(OldTab);
WriteArr(true);
}
else if (MsgPack.Object is MsgPack msg)
Write(msg, End, TabChar, Tab, Style);
else Write(MsgPack.Object, End, TabChar, Tab, Style);
return this;
}
private void Write(object obj, string End, string TabChar, string Tab, bool Style)
{
if (obj == null) { WriteNil(); return; }
switch (obj)
{
case MsgPack val: Write(val, End, TabChar, Tab, Style); break;
case bool val: Write(val); break;
case string val: Write(val); break;
case sbyte val: _IO.Write(Main.ToString(val)); break;
case byte val: _IO.Write(Main.ToString(val)); break;
case short val: _IO.Write(Main.ToString(val)); break;
case ushort val: _IO.Write(Main.ToString(val)); break;
case int val: _IO.Write(Main.ToString(val)); break;
case uint val: _IO.Write(Main.ToString(val)); break;
case long val: _IO.Write(Main.ToString(val)); break;
case ulong val: _IO.Write(Main.ToString(val)); break;
case float val: _IO.Write(Main.ToString(val)); break;
case double val: _IO.Write(Main.ToString(val)); break;
}
}
private void Write( bool val) => _IO.Write(val ? "true" : "false");
private void Write(string val) => _IO.Write("\"" + val
.Replace("\\", "\\\\").Replace("/" , "\\/").Replace("\"", "\\\"")
.Replace("\0", "\\0" ).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 ? "}" : "{");
}
}
-70
View File
@@ -1,70 +0,0 @@
using KKdMainLib.IO;
using MPIO = KKdMainLib.MessagePack.IO;
namespace KKdMainLib.MessagePack
{
public static class MPExt
{
public static MsgPack ReadMPAllAtOnce(this string file, bool JSON = false)
{
MsgPack MsgPack;
if (JSON)
{ JSONIO IO = new JSONIO(File.OpenReader(file + ".json", true));
MsgPack = IO.Read(); IO.Close(); IO = null; }
else
{ MPIO IO = new MPIO(File.OpenReader(file + ".mp" , true));
MsgPack = IO.Read(); IO.Close(); IO = null; }
return MsgPack;
}
public static MsgPack ReadMP(this string file, bool JSON = false)
{
MsgPack MsgPack;
if (JSON)
{ JSONIO IO = new JSONIO(File.OpenReader(file + ".json"));
MsgPack = IO.Read(); IO.Close(); IO = null; }
else
{ MPIO IO = new MPIO(File.OpenReader(file + ".mp" ));
MsgPack = IO.Read(); IO.Close(); IO = null; }
return MsgPack;
}
public static void Write(this MsgPack mp, bool Temp, string file, bool JSON = false)
{ if (Temp) MsgPack.New.Add(mp).Write(file, JSON).Dispose();
else mp .Write(file, JSON); }
public static MsgPack Write(this MsgPack mp, string file, bool JSON = false)
{
if (JSON)
{ JSONIO IO = new JSONIO(File.OpenWriter(file + ".json", true));
IO.Write(mp, "\n", " ").Close(); IO = null; }
else
{ MPIO IO = new MPIO(File.OpenWriter(file + ".mp" , true));
IO.Write(mp ).Close(); IO = null; }
return mp;
}
public static void WriteAfterAll(this MsgPack mp, bool Temp, string file, bool JSON = false)
{ if (Temp) MsgPack.New.Add(mp).WriteAfterAll(file, JSON).Dispose();
else mp .WriteAfterAll(file, JSON); }
public static MsgPack WriteAfterAll(this MsgPack mp, string file, bool JSON = false)
{
byte[] data = null;
if (JSON)
{ JSONIO IO = new JSONIO(File.OpenWriter());
IO.Write(mp, true); data = IO.ToArray(true); }
else
{ MPIO IO = new MPIO(File.OpenWriter());
IO.Write(mp ); data = IO.ToArray(true); }
File.WriteAllBytes(file + (JSON ? ".json" : ".mp"), data);
return mp;
}
public static void ToJSON (this string file) =>
file.ReadMP( ).Write(file, true).Dispose();
public static void ToMsgPack(this string file) =>
file.ReadMP(true).Write(file ).Dispose();
}
}
-261
View File
@@ -1,261 +0,0 @@
using System;
using KKdMainLib.Types;
namespace KKdMainLib.MessagePack
{
public struct MsgPack : IDisposable, IEquatable<MsgPack>
{
public string Name;
public object Object;
public MsgPack[] Array => Object is MsgPack[] List ? List : null;
public KKdList<MsgPack> List => Object is KKdList<MsgPack> List ? List : default;
public static MsgPack New => new MsgPack { Object = KKdList<MsgPack>.New };
public static MsgPack NewReserve(int Capacity) =>
new MsgPack { Object = KKdList<MsgPack>.NewReserve(Capacity) };
public MsgPack( string Name = null)
{ Object = KKdList<MsgPack>.New; this.Name = Name; }
public MsgPack(long Count, string Name = null)
{ Object = Count > 0 ? new MsgPack[Count] : null; this.Name = Name; }
public MsgPack(string Name, object Object)
{ this.Name = Name; this.Object = Object; }
public static MsgPack Null => new MsgPack();
public MsgPack this[int index]
{ get => Object is MsgPack[] Array ? Array[index] : default;
set { if (Object is MsgPack[] Array) { Array[index] = value; Object = Array; } } }
public MsgPack Add(MsgPack obj)
{ if (Object is KKdList<MsgPack> List) { List.Add(obj); Object = List; } return this; }
public void Dispose()
{ Name = null; Object = null; }
public bool Equals(MsgPack msg) =>
Name == msg.Name && Object == msg.Object;
public override string ToString() => Name ?? "" +
(List. NotNull ? ((Name != null ? " " : "") + "Elements Count: " + List .Count ) :
(Array != null ? ((Name != null ? " " : "") + "Elements Count: " + Array.Length) :
Object.ToString()));
public MsgPack Add(string Val, byte[] val) => val != null ? Add(new MsgPack(Val, val)) : this;
public MsgPack Add(string Val, string val) => val != null ? Add(new MsgPack(Val, val)) : this;
public static explicit operator MsgPack(byte[] val) => new MsgPack(null, val);
public static explicit operator MsgPack(string val) => new MsgPack(null, val);
public static explicit operator MsgPack( sbyte val) => new MsgPack(null, val);
public static explicit operator MsgPack( byte val) => new MsgPack(null, val);
public static explicit operator MsgPack( short val) => new MsgPack(null, val);
public static explicit operator MsgPack(ushort val) => new MsgPack(null, val);
public static explicit operator MsgPack( int val) => new MsgPack(null, val);
public static explicit operator MsgPack( uint val) => new MsgPack(null, val);
public static explicit operator MsgPack( long val) => new MsgPack(null, val);
public static explicit operator MsgPack( ulong val) => new MsgPack(null, val);
public static explicit operator MsgPack( float val) => new MsgPack(null, val);
public static explicit operator MsgPack(double val) => new MsgPack(null, val);
public MsgPack Add( sbyte? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( byte? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( short? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add(ushort? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( int? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( uint? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( long? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( ulong? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add( float? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add(double? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
public MsgPack Add(byte[] val) => Add(new MsgPack(null, val));
public MsgPack Add(string val) => Add(new MsgPack(null, val));
public MsgPack Add( bool val) => Add(new MsgPack(null, val));
public MsgPack Add( sbyte val) => Add(new MsgPack(null, val));
public MsgPack Add( byte val) => Add(new MsgPack(null, val));
public MsgPack Add( short val) => Add(new MsgPack(null, val));
public MsgPack Add(ushort val) => Add(new MsgPack(null, val));
public MsgPack Add( int val) => Add(new MsgPack(null, val));
public MsgPack Add( uint val) => Add(new MsgPack(null, val));
public MsgPack Add( long val) => Add(new MsgPack(null, val));
public MsgPack Add( ulong val) => Add(new MsgPack(null, val));
public MsgPack Add( float val) => Add(new MsgPack(null, val));
public MsgPack Add(double val) => Add(new MsgPack(null, val));
public MsgPack Add(string Val, sbyte? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, byte? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, short? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, ushort? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, int? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, uint? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, long? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, ulong? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, float? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, double? val) => val.HasValue ? Add(Val, val.Value) : this;
public MsgPack Add(string Val, bool val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, sbyte val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, byte val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, short val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, ushort val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, int val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, uint val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, long val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, ulong val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, float val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, double val) => Add(new MsgPack(Val, val));
public bool ReadBoolean(string Name) => ReadNBoolean(Name).GetValueOrDefault();
public sbyte ReadInt8(string Name) => ReadNInt8(Name).GetValueOrDefault();
public byte ReadUInt8(string Name) => ReadNUInt8(Name).GetValueOrDefault();
public short ReadInt16(string Name) => ReadNInt16(Name).GetValueOrDefault();
public ushort ReadUInt16(string Name) => ReadNUInt16(Name).GetValueOrDefault();
public int ReadInt32(string Name) => ReadNInt32(Name).GetValueOrDefault();
public uint ReadUInt32(string Name) => ReadNUInt32(Name).GetValueOrDefault();
public long ReadInt64(string Name) => ReadNInt64(Name).GetValueOrDefault();
public ulong ReadUInt64(string Name) => ReadNUInt64(Name).GetValueOrDefault();
public float ReadSingle(string Name) => ReadNSingle(Name).GetValueOrDefault();
public double ReadDouble(string Name) => ReadNDouble(Name).GetValueOrDefault();
public bool? ReadNBoolean(string Name) =>
Element(Name, out MsgPack MsgPack) ? MsgPack.ReadNBoolean() : null;
public sbyte? ReadNInt8(string Name) =>
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNInt8 () : null;
public byte? ReadNUInt8(string Name) =>
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNUInt8 () : null;
public short? ReadNInt16(string Name) =>
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNInt16() : null;
public ushort? ReadNUInt16(string Name) =>
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNUInt16() : null;
public int? ReadNInt32(string Name) =>
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNInt32() : null;
public uint? ReadNUInt32(string Name) =>
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNUInt32() : null;
public long? ReadNInt64(string Name) =>
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNInt64() : null;
public ulong? ReadNUInt64(string Name) =>
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNUInt64() : null;
public float? ReadNSingle(string Name) =>
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNSingle() : null;
public double? ReadNDouble(string Name) =>
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadNDouble() : null;
public string ReadString(string Name) =>
Element(Name, out MsgPack MsgPack) ? MsgPack. ReadString() : null;
public bool ReadBoolean() => ReadNBoolean().GetValueOrDefault();
public sbyte ReadInt8() => ReadNInt8().GetValueOrDefault();
public byte ReadUInt8() => ReadNUInt8().GetValueOrDefault();
public short ReadInt16() => ReadNInt16().GetValueOrDefault();
public ushort ReadUInt16() => ReadNUInt16().GetValueOrDefault();
public int ReadInt32() => ReadNInt32().GetValueOrDefault();
public uint ReadUInt32() => ReadNUInt32().GetValueOrDefault();
public long ReadInt64() => ReadNInt64().GetValueOrDefault();
public ulong ReadUInt64() => ReadNUInt64().GetValueOrDefault();
public float ReadSingle() => ReadNSingle().GetValueOrDefault();
public double ReadDouble() => ReadNDouble().GetValueOrDefault();
public bool? ReadNBoolean()
{ if (Object is bool Boolean) return Boolean; return null; }
public sbyte? ReadNInt8()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return ( sbyte) UInt8 ; return null; }
public byte? ReadNUInt8()
{ if (Object is sbyte Int8 ) return ( byte) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ; return null; }
public short? ReadNInt16()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return ( short) UInt16; return null; }
public ushort? ReadNUInt16()
{ if (Object is sbyte Int8 ) return (ushort) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return (ushort) Int16;
else if (Object is ushort UInt16) return UInt16; return null; }
public int? ReadNInt32()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return ( int) UInt32; return null; }
public uint? ReadNUInt32()
{ if (Object is sbyte Int8 ) return ( uint) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return ( uint) Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return ( uint) Int32;
else if (Object is uint UInt32) return UInt32; return null; }
public long? ReadNInt64()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return Int64;
else if (Object is ulong UInt64) return ( long) UInt64; return null; }
public ulong? ReadNUInt64()
{ if (Object is sbyte Int8 ) return ( ulong) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return ( ulong) Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return ( ulong) Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return ( ulong) Int64;
else if (Object is ulong UInt64) return UInt64; return null; }
public float? ReadNSingle()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return Int64;
else if (Object is float Float32) return Float32;
else if (Object is double Float64) return ( float)Float64; return null; }
public double? ReadNDouble()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return Int64;
else if (Object is float Float32) return Float32;
else if (Object is double Float64) return Float64; return null; }
public string ReadString()
{ if (Object is string String) return String; return null; }
public bool ElementArray(string Name, out MsgPack MsgPack) =>
Element(Name, out MsgPack) ? MsgPack.Array != null : false;
public bool Element(string Name, out MsgPack MsgPack)
{
MsgPack = New;
if (List.IsNull) return false;
for (int i = 0; i < List.Count; i++)
if (List[i].Name == Name) { MsgPack = List[i]; return true; }
return false;
}
public bool ContainsKey(string Name)
{
if (List.IsNull) return false;
for (int i = 0; i < List.Count ; i++)
if (List[i].Name == Name) return true;
return false;
}
public struct Ext
{
public sbyte Type;
public byte[] Data;
}
}
}
+356
View File
@@ -0,0 +1,356 @@
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
using KKdBaseLib;
using KKdMainLib.IO;
namespace KKdMainLib
{
public struct Mot : System.IDisposable
{
private int i, i0, i1;
public MotHeader[] MOT;
private Stream _IO;
public void MOTReader(string file)
{
_IO = File.OpenReader(file + ".bin");
i = 0;
while (true)
if (_IO.RI64() == 0) break;
else { _IO.RI64(); i++; }
if (i == 0) return;
_IO.P = 0;
int motCount = i;
MOT = new MotHeader[motCount];
for (i = 0; i < motCount; i++)
{
ref MotHeader mot = ref MOT[i];
mot.KeySet .O = _IO.RI32();
mot.KeySetTypesOffset = _IO.RI32();
mot. KeySetOffset = _IO.RI32();
mot.BoneInfo .O = _IO.RI32();
}
for (i = 0; i < motCount; i++)
{
ref MotHeader mot = ref MOT[i];
i0 = 1;
_IO.P = mot.BoneInfo.O;
_IO.RU16();
while (_IO.RU16() != 0) i0++;
mot.BoneInfo.V = new BoneInfo[i0];
_IO.P = mot.BoneInfo.O;
for (i0 = 0; i0 < mot.BoneInfo.V.Length; i0++)
mot.BoneInfo.V[i0].Id = _IO.RU16();
_IO.P = mot.KeySet.O;
int info = _IO.RU16();
mot.HighBits = info >> 14;
mot.FrameCount = _IO.RU16();
mot.KeySet.V = new KeySet[info & 0x3FFF];
_IO.P = mot.KeySetTypesOffset;
for (i0 = 0; i0 < mot.KeySet.V.Length; i0++)
{
if (i0 % 8 == 0) i1 = _IO.RU16();
mot.KeySet.V[i0] = new KeySet { Type = (KeySetType)((i1 >> (i0 % 8 * 2)) & 0b11) };
}
_IO.P = mot.KeySetOffset;
for (i0 = 0; i0 < mot.KeySet.V.Length; i0++)
{
ref KeySet key = ref mot.KeySet.V[i0];
if (key.Type == KeySetType.Static)
{ key.Keys = new KFT2[1];
key.Keys[0].V = _IO.RF32(); }
else if (key.Type == KeySetType.Linear)
{
key.Keys = new KFT2[_IO.RU16()];
for (i1 = 0; i1 < key.Keys.Length; i1++)
key.Keys[i1].F = _IO.RU16();
_IO.A(0x4);
for (i1 = 0; i1 < key.Keys.Length; i1++)
key.Keys[i1].V = _IO.RF32();
}
else if (key.Type == KeySetType.Interpolated)
{
key.Keys = new KFT2[_IO.RU16()];
for (i1 = 0; i1 < key.Keys.Length; i1++)
key.Keys[i1].F = _IO.RU16();
_IO.A(0x4);
for (i1 = 0; i1 < key.Keys.Length; i1++)
{ key.Keys[i1].V = _IO.RF32(); key.Keys[i1].T = _IO.RF32(); }
}
}
}
_IO.C();
}
public void MOTWriter(string file)
{
if (MOT == null) return;
_IO = File.OpenWriter(file + ".bin", true);
int MOTCount = MOT.Length;
_IO.P = (MOTCount + 1) << 4;
for (i = 0; i < MOTCount; i++)
{
ref MotHeader mot = ref MOT[i];
mot.KeySet.O = _IO.P;
_IO.W((ushort)((mot.HighBits << 14) | (mot.KeySet.V.Length & 0x3FFF)));
_IO.W((ushort)mot.FrameCount);
mot.KeySetTypesOffset = _IO.P;
for (i0 = 0, i1 = 0; i0 < mot.KeySet.V.Length; i0++)
{
i1 |= ((byte)mot.KeySet.V[i0].Type << (i0 % 8 * 2)) & (0b11 << (i0 % 8 * 2));
if (i0 % 8 == 7) { _IO.W((ushort)i1); i1 = 0; }
}
_IO.W((ushort)i1);
if (_IO.P % 4 != 0) _IO.W((ushort)0x00);
mot.KeySetOffset = _IO.P;
for (i0 = 0; i0 < mot.KeySet.V.Length; i0++)
{
ref KeySet key = ref mot.KeySet.V[i0];
if (key.Type == KeySetType.Static)
_IO.W(key.Keys[0].V);
else if (key.Type == KeySetType.Linear)
{
_IO.W((ushort)key.Keys.Length);
for (i1 = 0; i1 < key.Keys.Length; i1++)
_IO.W((ushort)key.Keys[i1].F);
if (_IO.P % 4 != 0) _IO.W((ushort)0x00);
for (i1 = 0; i1 < key.Keys.Length; i1++)
_IO.W(key.Keys[i1].V);
}
else if (key.Type == KeySetType.Interpolated)
{
_IO.W((ushort)key.Keys.Length);
for (i1 = 0; i1 < key.Keys.Length; i1++)
_IO.W((ushort)key.Keys[i1].F);
if (_IO.P % 4 != 0) _IO.W((ushort)0x00);
for (i1 = 0; i1 < key.Keys.Length; i1++)
{ _IO.W(key.Keys[i1].V); _IO.W(key.Keys[i1].T); }
}
}
if (_IO.P % 4 != 0) _IO.W((ushort)0x00);
mot.BoneInfo.O = _IO.P;
for (i0 = 0; i0 < mot.BoneInfo.V.Length; i0++)
_IO.W((ushort)mot.BoneInfo.V[i0].Id);
_IO.W((ushort)0);
}
if (_IO.P % 4 != 0) _IO.W((ushort)0x00);
_IO.A(0x4, true);
_IO.P = 0;
for (i = 0; i < MOTCount; i++)
{
ref MotHeader mot = ref MOT[i];
_IO.W(mot.KeySet .O );
_IO.W(mot.KeySetTypesOffset);
_IO.W(mot. KeySetOffset);
_IO.W(mot.BoneInfo .O );
}
_IO.C();
}
public void MsgPackReader(string file, bool json)
{
MOT = null;
MsgPack msgPack = file.ReadMP(json);
MsgPack mot;
if ((mot = msgPack["MOT"]).NotNull)
{
MOT = new MotHeader[mot.Array.Length];
for (int i = 0; i < MOT.Length; i++)
MsgPackReader(mot.Array[i], ref MOT[i]);
}
mot.Dispose();
msgPack.Dispose();
}
public void MsgPackWriter(string file, bool json)
{
int motCount = MOT.Length;
MsgPack mot = new MsgPack(motCount, "MOT");
for (i = 0; i < motCount; i++)
mot[i] = MsgPackWriter(ref MOT[i]);
mot.Write(true, file, json);
}
public void MsgPackReader(MsgPack msgPack, ref MotHeader mot)
{
MsgPack temp = MsgPack.New;
mot.HighBits = msgPack.RI32("HighBits" );
mot.FrameCount = msgPack.RI32("FrameCount");
if ((temp = msgPack["KeySets", true]).IsNull) { temp.Dispose(); return; }
mot.KeySet.V = new KeySet[temp.Array.Length];
for (i0 = 0; i0 < mot.KeySet.V.Length; i0++)
{
ref KeySet keySet = ref mot.KeySet.V[i0];
if (temp.Array[i0].Array == null || temp.Array[i0].Array.Length != 2) continue;
keySet.Type = (KeySetType)temp.Array[i0].Array[0].RI32();
MsgPack temp1 = temp.Array[i0].Array[1];
if (temp1.Array == null) { keySet.Type = 0; continue; }
else if (keySet.Type == KeySetType.None) continue;
else if (keySet.Type == KeySetType.Static)
{
keySet.Keys = new KFT2[1];
if (temp1.Array == null) continue;
else if (temp1.Array.Length == 0) continue;
else if (temp1.Array[0].Array == null) continue;
else if (temp1.Array[0].Array.Length == 0) continue;
else if (temp1.Array[0].Array.Length == 1)
keySet.Keys[0] = new KFT2(temp1.Array[0][0].RF32());
else if (temp1.Array[0].Array.Length > 1)
keySet.Keys[0] = new KFT2(temp1.Array[0][0].RF32(), temp1.Array[0][1].RF32());
}
else if (keySet.Type == KeySetType.Linear)
{
keySet.Keys = new KFT2[temp1.Array.Length];
for (i1 = 0; i1 < temp1.Array.Length; i1++)
{
ref MsgPack array = ref temp1.Array[i1];
if (array.Array == null) continue;
else if (array.Array.Length == 0) continue;
else if (array.Array.Length == 1)
keySet.Keys[i1] = new KFT2(array[0].RF32());
else if (array.Array.Length == 2)
keySet.Keys[i1] = new KFT2(array[0].RF32(), array[1].RF32());
}
}
else if (keySet.Type == KeySetType.Interpolated)
{
keySet.Keys = new KFT2[temp1.Array.Length];
for (i1 = 0; i1 < temp1.Array.Length; i1++)
{
ref MsgPack array = ref temp1.Array[i1];
if (array.Array == null ||
array.Array.Length == 0) continue;
else if (array.Array.Length == 1)
keySet.Keys[i1] = new KFT2(array[0].RF32());
else if (array.Array.Length == 2)
keySet.Keys[i1] = new KFT2(array[0].RF32(), array[1].RF32());
else if (array.Array.Length > 2)
keySet.Keys[i1] = new KFT2(array[0].RF32(),
array[1].RF32(), temp1.Array[i1][2].RF32());
}
}
}
if ((temp = msgPack["BoneInfo", true]).NotNull)
{
mot.BoneInfo.V = new BoneInfo[temp.Array.Length];
for (i = 0; i < mot.BoneInfo.V.Length; i++)
mot.BoneInfo.V[i].Id = temp[i].RI32();
}
temp.Dispose();
}
public MsgPack MsgPackWriter(ref MotHeader Mot)
{
MsgPack mot = MsgPack.NewReserve(4).Add("FrameCount", Mot.FrameCount).Add("HighBits", Mot.HighBits);
MsgPack keySets = new MsgPack(Mot.KeySet.V.Length, "KeySets");
for (i0 = 0; i0 < Mot.KeySet.V.Length; i0++)
{
ref KeySet keySet = ref Mot.KeySet.V[i0];
if (keySet.Type == KeySetType.None) continue;
keySets[i0] = new MsgPack(2);
keySets[i0].Array[0] = (byte)keySet.Type;
keySets[i0].Array[1] = new MsgPack(keySet.Keys.Length);
if (keySet.Type == KeySetType.Static)
{
IKF kf = keySet.Keys[0].Check();
if (kf is KFT0 KFT0) keySets[i0].Array[1][0] =
new MsgPack(null, new MsgPack[] { KFT0.F });
else if (kf is KFT1 KFT1) keySets[i0].Array[1][0] =
new MsgPack(null, new MsgPack[] { KFT1.F, KFT1.V });
}
else if (keySet.Type == KeySetType.Linear)
for (i1 = 0; i1 < keySet.Keys.Length; i1++)
{
IKF kf = keySet.Keys[i1].Check();
if (kf is KFT0 KFT0) keySets[i0].Array[1][i1] =
new MsgPack(null, new MsgPack[] { KFT0.F });
else if (kf is KFT1 KFT1) keySets[i0].Array[1][i1] =
new MsgPack(null, new MsgPack[] { KFT1.F, KFT1.V });
}
else
for (i1 = 0; i1 < keySet.Keys.Length; i1++)
{
IKF kf = keySet.Keys[i1].Check();
if (kf is KFT0 KFT0) keySets[i0].Array[1][i1] =
new MsgPack(null, new MsgPack[] { KFT0.F });
else if (kf is KFT1 KFT1) keySets[i0].Array[1][i1] =
new MsgPack(null, new MsgPack[] { KFT1.F, KFT1.V });
else if (kf is KFT2 KFT2) keySets[i0].Array[1][i1] =
new MsgPack(null, new MsgPack[] { KFT2.F, KFT2.V, KFT2.T });
}
}
mot.Add(keySets);
MsgPack boneInfo = new MsgPack(Mot.BoneInfo.V.Length, "BoneInfo");
for (i0 = 0; i0 < Mot.BoneInfo.V.Length; i0++)
boneInfo[i0] = Mot.BoneInfo.V[i0].Id;
mot.Add(boneInfo);
return mot;
}
public void Dispose()
{
_IO = null;
MOT = null;
}
public struct MotHeader
{
public int KeySetOffset;
public int KeySetTypesOffset;
public Pointer< KeySet []> KeySet ;
public Pointer<BoneInfo[]> BoneInfo;
public int HighBits;
public int FrameCount;
}
public struct KeySet
{
public KFT2[] Keys;
public KeySetType Type;
public override string ToString() => $"Type: {Type}" + (Type == KeySetType.Static ?
$"; Value: {Keys[0].V}" : Type > KeySetType.Static ? $"; Keys: {Keys.Length}" : "");
}
public enum KeySetType : byte
{
None = 0b00,
Static = 0b01,
Linear = 0b10,
Interpolated = 0b11,
}
public struct BoneInfo
{
public string Name;
public int Id;
}
}
}
+755
View File
@@ -0,0 +1,755 @@
using KKdBaseLib;
using KKdMainLib.IO;
namespace KKdMainLib
{
public struct MotHead
{
private int i, i0, i1;
private Stream _IO;
public HeaderData Header;
public void MotHeadReader(string file)
{
_IO = File.OpenReader(file + ".bin");
_IO.RI32();
Header = new HeaderData();
int offset = _IO.RI32();
if (offset < 0x10) goto RETURN;
_IO.O = offset;
_IO.P = 0;
Header. MotionSetID = _IO.RI32();
Header.StartMotionID = _IO.RI32();
Header. EndMotionID = _IO.RI32();
Header.SubHeaderOffset = _IO.RI32();
if (Header.SubHeaderOffset < 0x10) goto RETURN;
i0 = Header.EndMotionID - Header.StartMotionID;
if (i0 < 0) goto RETURN;
_IO.P = Header.SubHeaderOffset;
Header.Data = new HeaderData.Sub[++i0];
for (i = 0; i < Header.Data.Length; i++) Header.Data[i].Offset = _IO.RI32();
for (i = 0; i < Header.Data.Length; i++)
{
if (Header.Data[i].Offset < 0x10) continue;
_IO.P = Header.Data[i].Offset;
Header.Data[i].MotionID = Header.StartMotionID + i;
Header.Data[i].SomeData = _IO.RI32();
_IO.RI64();
_IO.RI64();
Header.Data[i].Offset2 = _IO.RI32();
Header.Data[i].DataHeaderOffset = _IO.RI32();
if (Header.Data[i].DataHeaderOffset < 0x10) goto RETURN;
_IO.P = Header.Data[i].DataHeaderOffset;
i0 = 0;
while (_IO.RI32() != -1) { _IO.RI32(); _IO.RI32(); i0++; }
_IO.P = Header.Data[i].DataHeaderOffset;
Header.Data[i].Array = new HeaderData.Sub.Data[i0];
for (i0 = 0; i0 < Header.Data[i].Array.Length; i0++)
{
Header.Data[i].Array[i0].Type = _IO.RI32();
Header.Data[i].Array[i0].Frame = _IO.RI32();
Header.Data[i].Array[i0].Offset = _IO.RI32();
}
}
for (i = 0; i < Header.Data.Length; i++)
{
if (Header.Data[i].Offset2 > 0x10)
{
_IO.P = Header.Data[i].Offset2;
i0 = 0;
while (_IO.RI32() != -1) { _IO.RI32(); i0++; }
_IO.P = Header.Data[i].Offset2;
Header.Data[i].Array2 = new HeaderData.Sub.Data2[i0];
for (i0 = 0; i0 < Header.Data[i].Array2.Length; i0++)
{
Header.Data[i].Array2[i0].Frame = _IO.RI32();
Header.Data[i].Array2[i0].Offset = _IO.RI32();
}
for (i0 = 0; i0 < Header.Data[i].Array2.Length; i0++)
{
if (Header.Data[i].Array2[i0].Offset < 0x10) goto RETURN;
_IO.P = Header.Data[i].Array2[i0].Offset;
Header.Data[i].Array2[i0].Array = new int[7];
for (i1 = 0; i1 < Header.Data[i].Array2[i0].Array.Length; i1++)
Header.Data[i].Array2[i0].Array[i1] = _IO.RI32();
}
}
if (Header.Data[i].Array == null || Header.Data[i].Array.Length < 1) continue;
for (i0 = 0; i0 < Header.Data[i].Array.Length; i0++)
{
ref HeaderData.Sub.Data Data = ref Header.Data[i].Array[i0];
if (!GetSize(Data.Type, out i1)) goto RETURN;
if (Data.Offset > 0)
{
_IO.P = Data.Offset;
if (i1 == 0x01) Data.Array = new int[] { _IO.RU8 () };
else if (i1 == 0x02) Data.Array = new int[] { _IO.RU16() };
else
{
Data.Array = new int[i1 / 4];
for (i1 = 0; i1 < Data.Array.Length; i1++) Data.Array[i1] = _IO.RI32();
}
}
}
}
RETURN:
_IO.C();
}
public void MotHeadWriter(string file)
{
if (Header.Data == null || Header.Data.Length < 1) return;
Header.StartMotionID = 0x7FFFFFFF;
Header.EndMotionID = 0x00000000;
for (i = 0; i < Header.Data.Length; i++)
{
if (Header.Data[i].MotionID < Header.StartMotionID)
Header.StartMotionID = Header.Data[i].MotionID;
if (Header.Data[i].MotionID > Header. EndMotionID)
Header. EndMotionID = Header.Data[i].MotionID;
}
_IO = File.OpenWriter(file + ".bin");
_IO.W(0x01);
_IO.W(0x20);
_IO.A(0x20, true);
_IO.O = 0x20;
_IO.P = 0;
_IO.W(0);
for (int I = Header.EndMotionID - Header.StartMotionID; I > -1; I--)
for (i = 0; i < Header.Data.Length; i++)
if (Header.StartMotionID + I == Header.Data[i].MotionID)
{
_IO.A(0x20, true);
Header.Data[i].Offset = _IO.P;
Header.Data[i].DataHeaderOffset = Header.Data[i].Offset + 0x20;
_IO.W(0L);
_IO.W(0L);
_IO.W(0L);
_IO.W(0L);
for (i0 = 0; i0 < Header.Data[i].Array.Length; i0++)
{ _IO.W( 0); _IO.W( 0); _IO.W(0); }
_IO.W(-1); _IO.W(-1); _IO.W(0);
for (i0 = Header.Data[i].Array.Length - 1; i0 > -1; i0--)
{
ref HeaderData.Sub.Data data = ref Header.Data[i].Array[i0];
if (data.Array != null)
if (data.Array.Length > 0 &&
GetSize(data.Type, out int Size))
{
if (data.Type == 0x3E) _IO.A(0x20, true);
data.Offset = _IO.P;
if (Size == 0x01) _IO.W(( byte)data.Array[0]);
else if (Size == 0x02) _IO.W((short)data.Array[0]);
else
{
if (_IO.P % 0x4 != 0) _IO.A(0x04, true);
Size /= 4;
data.Offset = _IO.P;
for (i1 = 0; i1 < data.Array.Length && i1 < Size; i1++)
_IO.W(data.Array[i1]);
for (; i1 < Size; i1++) _IO.W(0);
}
}
}
if (Header.Data[i].Array2 != null)
if (Header.Data[i].Array2.Length > 0)
{
Header.Data[i].Offset2 = _IO.P;
for (i0 = 0; i0 < Header.Data[i].Array2.Length; i0++)
{ _IO.W( 0); _IO.W(0); }
_IO.W(-1); _IO.W(0);
for (i0 = Header.Data[i].Array2.Length - 1; i0 > -1; i0--)
{
Header.Data[i].Array2[i0].Offset = _IO.P;
for (i1 = 0; i1 < Header.Data[i].Array2[i0].Array.Length && i1 < 7; i1++)
_IO.W(Header.Data[i].Array2[i0].Array[i1]);
for (; i1 < 7; i1++) _IO.W(0);
}
}
break;
}
_IO.A(0x20, true);
Header.SubHeaderOffset = _IO.P;
i1 = Header.EndMotionID - Header.StartMotionID;
int offset = 0;
for (i = 0, i1++; i < i1; i++)
{
offset = 0;
for (i0 = 0; i0 < Header.Data.Length; i0++)
if (Header.StartMotionID + i == Header.Data[i0].MotionID)
{ offset = Header.Data[i0].Offset; break; }
_IO.W(offset);
}
_IO.A(0x20, true);
for (i = 0; i < Header.Data.Length; i++)
{
_IO.P = Header.Data[i].Offset;
_IO.W(Header.Data[i].SomeData);
_IO.W(0);
_IO.W(0L);
_IO.W(0x040004);
_IO.W(Header.Data[i].Offset2);
_IO.W(Header.Data[i].DataHeaderOffset);
_IO.W(0);
_IO.P = Header.Data[i].DataHeaderOffset;
for (i0 = 0; i0 < Header.Data[i].Array.Length; i0++)
{
_IO.W(Header.Data[i].Array[i0].Type );
_IO.W(Header.Data[i].Array[i0].Frame );
_IO.W(Header.Data[i].Array[i0].Offset);
}
_IO.P = Header.Data[i].Offset2;
if (Header.Data[i].Array2 != null)
for (i0 = 0; i0 < Header.Data[i].Array2.Length; i0++)
{
_IO.W(Header.Data[i].Array2[i0].Frame );
_IO.W(Header.Data[i].Array2[i0].Offset);
}
}
_IO.P = 0;
_IO.W(Header.MotionSetID );
_IO.W(Header.StartMotionID );
_IO.W(Header. EndMotionID );
_IO.W(Header.SubHeaderOffset);
_IO.C();
}
public void MsgPackReader(string file, bool json)
{
Header = new HeaderData();
MsgPack motHead;
MsgPack msgPack = file.ReadMPAllAtOnce(json);
if ((motHead = msgPack["MotHead"]).IsNull) return;
Header.MotionSetID = motHead.RI32("MotionSetID");
MsgPack temp = MsgPack.New;
MsgPack motions, array;
if ((motions = motHead["Motions", true]).IsNull) return;
Header.Data = new HeaderData.Sub[motions.Array.Length];
for (i = 0; i < Header.Data.Length; i++)
{
Header.Data[i].MotionID = motions[i].RI32("MotionID");
Header.Data[i].SomeData = motions[i].RI32("SomeData");
MsgPack array2;
if ((array2 = motions[i]["Array2", true]).NotNull)
{
Header.Data[i].Array2 = new HeaderData.Sub.Data2[array2.Array.Length];
for (i0 = 0; i0 < Header.Data[i].Array2.Length; i0++)
{
Header.Data[i].Array2[i0].Frame = array2[i0].RI32("Frame");
MsgPack arrayArray;
if ((arrayArray = array2[i0]["Array", true]).IsNull) continue;
Header.Data[i].Array2[i0].Array = new int[arrayArray.Array.Length];
for (i1 = 0; i1 < Header.Data[i].Array2[i0].Array.Length; i1++)
Header.Data[i].Array2[i0].Array[i1] = arrayArray[i1].RI32();
}
}
if ((array = motions[i]["Array", true]).IsNull) { continue; }
Header.Data[i].Array = new HeaderData.Sub.Data[array.Array.Length];
for (i0 = 0; i0 < Header.Data[i].Array.Length; i0++)
{
ref HeaderData.Sub.Data data = ref Header.Data[i].Array[i0];
data.Type = array[i0].RI32("Type");
data.Frame = array[i0].RI32("Frame");
if ((temp = array[i0]["Type3"]).NotNull)
{
data.Type = 0x03;
data.Array = new int[] { temp.RI32("i0") };
}
else if ((temp = array[i0]["Type53"]).NotNull)
{
data.Type = 0x35;
data.Array = new int[] { temp.RI32("i0"),
temp.RF32("f1").ToI32(),
temp.RF32("f2").ToI32(),
temp.RI32("i3") };
}
else if ((temp = array[i0]["Type54"]).NotNull)
{
data.Type = 0x36;
data.Array = new int[] { temp.RI32("i0"),
temp.RF32("f1").ToI32(),
temp.RF32("f2").ToI32(),
temp.RI32("i3") };
}
else if ((temp = array[i0]["Type55"]).NotNull)
{
data.Type = 0x37;
data.Array = new int[] { temp.RI32("i0"),
temp.RF32("f1").ToI32(),
temp.RF32("f2").ToI32(),
temp.RI32("i3") };
}
else if ((temp = array[i0]["Type56"]).NotNull)
{
data.Type = 0x38;
data.Array = new int[] { temp.RI32("i0"),
temp.RF32("f1").ToI32(),
temp.RF32("f2").ToI32(),
temp.RI32("i3") };
}
else if ((temp = array[i0]["Type57"]).NotNull)
{
data.Type = 0x39;
data.Array = new int[] { temp.RI32("i0"),
temp.RF32("f1").ToI32(),
temp.RF32("f2").ToI32(),
temp.RI32("i3") };
}
else if ((temp = array[i0]["Type60"]).NotNull)
{
data.Type = 0x3C;
data.Array = new int[] { temp.RI32("i0"),
temp.RF32("f1").ToI32(),
temp.RF32("f2").ToI32(),
temp.RF32("f3").ToI32() };
}
else if ((temp = array[i0]["Type61"]).NotNull)
{
data.Type = 0x3D;
data.Array = new int[] { temp.RI32("i0"), temp.RF32("f1").ToI32() };
}
else if ((temp = array[i0]["Type62"]).NotNull)
{
data.Type = 0x3E;
data.Array = new int[0x10];
data.Array[ 0] = temp.RI32("i0");
data.Array[ 1] =
((byte)temp.RI32("i1_3") << 24) | ((byte)temp.RI32("i1_2") << 16) |
((byte)temp.RI32("i1_1") << 8) | (byte)temp.RI32("i1_0");
data.Array[ 2] = temp.RF32("f2" ).ToI32();
data.Array[ 3] = temp.RF32("f3" ).ToI32();
data.Array[ 4] = temp.RF32("f4" ).ToI32();
data.Array[ 5] = temp.RF32("f5" ).ToI32();
data.Array[ 6] = temp.RF32("f6" ).ToI32();
data.Array[ 7] = temp.RF32("f7" ).ToI32();
data.Array[ 8] = temp.RF32("f8" ).ToI32();
data.Array[ 9] = temp.RF32("f9" ).ToI32();
data.Array[10] = temp.RF32("f10").ToI32();
data.Array[11] = temp.RF32("f11").ToI32();
data.Array[12] = temp.RF32("f12").ToI32();
data.Array[13] = temp.RF32("f13").ToI32();
data.Array[14] = temp.RF32("f14").ToI32();
data.Array[15] = temp.RI32("i15");
}
else if ((temp = array[i0]["Type65"]).NotNull)
{
data.Type = 0x41;
data.Array = new int[] { temp.RI32("i0") };
}
else if ((temp = array[i0]["Type66"]).NotNull)
{
data.Type = 0x42;
data.Array = new int[] { temp.RF32("f0").ToI32() };
}
else if ((temp = array[i0]["Type67"]).NotNull)
{
data.Type = 0x43;
data.Array = new int[] { temp.RI32("i0"), temp.RF32("f1").ToI32() };
}
else if ((temp = array[i0]["Type68"]).NotNull)
{
data.Type = 0x44;
data.Array = new int[] { temp.RI32("i0"), temp.RF32("f1").ToI32() };
}
else if ((temp = array[i0]["Type69"]).NotNull)
{
data.Type = 0x45;
data.Array = new int[] { temp.RI32("i0"), temp.RI32("i1") };
}
else if ((temp = array[i0]["Type70"]).NotNull)
{
data.Type = 0x46;
data.Array = new int[] { temp.RI32("i0") };
}
else if ((temp = array[i0]["Type71"]).NotNull)
{
data.Type = 0x47;
data.Array = new int[] { temp.RI32("i0"), temp.RF32("f1").ToI32() };
}
else if ((temp = array[i0]["Type72"]).NotNull)
{
data.Type = 0x48;
data.Array = new int[] { temp.RI32("i0"), temp.RF32("f1").ToI32() };
}
else if ((temp = array[i0]["Type73"]).NotNull)
{
data.Type = 0x49;
data.Array = new int[] { temp.RI32("i0"),
temp.RF32("f1").ToI32(),
temp.RI32("i2"),
temp.RF32("f3").ToI32() };
}
else if ((temp = array[i0]["Type74"]).NotNull)
{
data.Type = 0x4A;
data.Array = new int[] { temp.RI32("i0") };
}
else if ((temp = array[i0]["Type62"]).NotNull)
{
data.Type = 0x4B;
data.Array = new int[0x0D];
data.Array[ 0] = temp.RI32("i0");
data.Array[ 1] = ((byte)temp.RI32("i1_1") << 8) | (byte)temp.RI32("i1_0");
data.Array[ 2] = temp.RF32("f2" ).ToI32();
data.Array[ 3] = temp.RF32("f3" ).ToI32();
data.Array[ 4] = temp.RF32("f4" ).ToI32();
data.Array[ 5] = temp.RF32("f5" ).ToI32();
data.Array[ 6] = temp.RF32("f6" ).ToI32();
data.Array[ 7] = temp.RF32("f7" ).ToI32();
data.Array[ 8] = temp.RF32("f8" ).ToI32();
data.Array[ 9] = temp.RF32("f9" ).ToI32();
data.Array[10] = temp.RF32("f10").ToI32();
data.Array[11] = temp.RF32("f11").ToI32();
data.Array[12] = temp.RF32("f12").ToI32();
}
else if ((temp = array[i0]["Type76"]).NotNull)
{
data.Type = 0x4C;
data.Array = new int[] { temp.RI32("i0"),
temp.RF32("f1").ToI32(),
temp.RF32("f2").ToI32(),
temp.RI32("i3") };
}
else if ((temp = array[i0]["Type77"]).NotNull)
{
data.Type = 0x4D;
data.Array = new int[] { temp.RI32("i0") };
}
else if ((temp = array[i0]["Type79"]).NotNull)
{
data.Type = 0x4F;
data.Array = new int[] { temp.RI32("i0") };
}
else if ((temp = array[i0]["Type80"]).NotNull)
{
data.Type = 0x50;
data.Array = new int[] { temp.RI32("i0") };
}
else if ((temp = array[i0]["Array", true]).NotNull)
{
data.Array = new int[temp.Array.Length];
for (i1 = 0; i1 < data.Array.Length; i1++)
data.Array[i1] = temp[i1].RI32();
}
}
}
msgPack.Dispose();
}
public void MsgPackWriter(string file, bool json)
{
if (Header.Data == null || Header.Data.Length < 1) return;
for (i = 0, i1 = 0; i < Header.Data.Length; i++)
if (Header.Data[i].Offset >= 0x10) i1++;
MsgPack motHead = new MsgPack("MotHead").Add("MotionSetID", Header.MotionSetID);
MsgPack motions = new MsgPack(i1, "Motions");
for (int I = 0, i = 0; i < Header.Data.Length; i++)
{
if (Header.Data[i].Offset < 0x10) continue;
MsgPack motion = MsgPack.New
.Add("MotionID", Header.Data[i].MotionID)
.Add("SomeData", Header.Data[i].SomeData);
if (Header.Data[i].Array == null || Header.Data[i].Array.Length < 1) { }
else
{
MsgPack array = new MsgPack(Header.Data[i].Array.Length, "Array");
for (i0 = 0; i0 < Header.Data[i].Array.Length; i0++)
{
ref HeaderData.Sub.Data data = ref Header.Data[i].Array[i0];
MsgPack arrayEntry = MsgPack.New;
arrayEntry.Add("Frame", data.Frame);
if (data.Array == null || data.Array.Length < 1)
arrayEntry.Add("Type", data.Type);
else if (data.Type == 0x03)
arrayEntry.Add(new MsgPack("Type3")
.Add("i0", data.Array[0]));
else if (data.Type == 0x35)
arrayEntry.Add(new MsgPack("Type53")
.Add("i0", data.Array[0])
.Add("f1", data.Array[1].ToF32())
.Add("f2", data.Array[2].ToF32())
.Add("i3", data.Array[3]));
else if (data.Type == 0x36)
arrayEntry.Add(new MsgPack("Type54")
.Add("i0", data.Array[0])
.Add("f1", data.Array[1].ToF32())
.Add("f2", data.Array[2].ToF32())
.Add("i3", data.Array[3]));
else if (data.Type == 0x37)
arrayEntry.Add(new MsgPack("Type55")
.Add("i0", data.Array[0])
.Add("f1", data.Array[1].ToF32())
.Add("f2", data.Array[2].ToF32())
.Add("i3", data.Array[3]));
else if (data.Type == 0x38)
arrayEntry.Add(new MsgPack("Type56")
.Add("i0", data.Array[0])
.Add("f1", data.Array[1].ToF32())
.Add("f2", data.Array[2].ToF32())
.Add("i3", data.Array[3]));
else if (data.Type == 0x39)
arrayEntry.Add(new MsgPack("Type57")
.Add("i0", data.Array[0])
.Add("f1", data.Array[1].ToF32())
.Add("f2", data.Array[2].ToF32())
.Add("i3", data.Array[3]));
else if (data.Type == 0x3C)
arrayEntry.Add(new MsgPack("Type60")
.Add("i0", data.Array[0])
.Add("f1", data.Array[1].ToF32())
.Add("f2", data.Array[2].ToF32())
.Add("f3", data.Array[3].ToF32()));
else if (data.Type == 0x3D)
arrayEntry.Add(new MsgPack("Type61")
.Add("i0", data.Array[0])
.Add("f1", data.Array[1].ToF32()));
else if (data.Type == 0x3E)
arrayEntry.Add(new MsgPack("Type62")
.Add("i0", data.Array[0])
.Add("i1_0", (byte) data.Array[1])
.Add("i1_1", (byte)(data.Array[1] >> 8))
.Add("i1_2", (byte)(data.Array[1] >> 16))
.Add("i1_3", (byte)(data.Array[1] >> 24))
.Add("f2" , data.Array[ 2].ToF32())
.Add("f3" , data.Array[ 3].ToF32())
.Add("f4" , data.Array[ 4].ToF32())
.Add("f5" , data.Array[ 5].ToF32())
.Add("f6" , data.Array[ 6].ToF32())
.Add("f7" , data.Array[ 7].ToF32())
.Add("f8" , data.Array[ 8].ToF32())
.Add("f9" , data.Array[ 9].ToF32())
.Add("f10", data.Array[10].ToF32())
.Add("f11", data.Array[11].ToF32())
.Add("f12", data.Array[12].ToF32())
.Add("f13", data.Array[13].ToF32())
.Add("f14", data.Array[14].ToF32())
.Add("i15", data.Array[15]));
else if (data.Type == 0x41)
arrayEntry.Add(new MsgPack("Type65")
.Add("i0", data.Array[0]));
else if (data.Type == 0x42)
arrayEntry.Add(new MsgPack("Type66")
.Add("f0", data.Array[0].ToF32()));
else if (data.Type == 0x43)
arrayEntry.Add(new MsgPack("Type67")
.Add("i0", data.Array[0])
.Add("f1", data.Array[1].ToF32()));
else if (data.Type == 0x44)
arrayEntry.Add(new MsgPack("Type68")
.Add("i0", data.Array[0])
.Add("f1", data.Array[1].ToF32()));
else if (data.Type == 0x45)
arrayEntry.Add(new MsgPack("Type69")
.Add("i0", data.Array[0])
.Add("i1", data.Array[1]));
else if (data.Type == 0x46)
arrayEntry.Add(new MsgPack("Type70")
.Add("i0", data.Array[0]));
else if (data.Type == 0x47)
arrayEntry.Add(new MsgPack("Type71")
.Add("i0", data.Array[0])
.Add("f1", data.Array[1].ToF32()));
else if (data.Type == 0x48)
arrayEntry.Add(new MsgPack("Type72")
.Add("i0", data.Array[0])
.Add("f1", data.Array[1].ToF32()));
else if (data.Type == 0x49)
arrayEntry.Add(new MsgPack("Type73")
.Add("i0", data.Array[0])
.Add("f1", data.Array[1].ToF32())
.Add("i2", (short)data.Array[2])
.Add("f3", data.Array[3].ToF32()));
else if (data.Type == 0x4A)
arrayEntry.Add(new MsgPack("Type74")
.Add("i0", data.Array[0]));
else if (data.Type == 0x4B)
arrayEntry.Add(new MsgPack("Type75")
.Add("i0", data.Array[0])
.Add("i1_0", (byte) data.Array[1])
.Add("i1_1", (byte)(data.Array[1] >> 8))
.Add("f2" , data.Array[ 2].ToF32())
.Add("f3" , data.Array[ 3].ToF32())
.Add("f4" , data.Array[ 4].ToF32())
.Add("f5" , data.Array[ 5].ToF32())
.Add("f6" , data.Array[ 6].ToF32())
.Add("f7" , data.Array[ 7].ToF32())
.Add("f8" , data.Array[ 8].ToF32())
.Add("f9" , data.Array[ 9].ToF32())
.Add("f10", data.Array[10].ToF32())
.Add("f11", data.Array[11].ToF32())
.Add("f12", data.Array[12].ToF32()));
else if (data.Type == 0x4C)
arrayEntry.Add(new MsgPack("Type76")
.Add("i0", data.Array[0])
.Add("f1", data.Array[1].ToF32())
.Add("f2", data.Array[2].ToF32())
.Add("i3", data.Array[3]));
else if (data.Type == 0x4D)
arrayEntry.Add(new MsgPack("Type77")
.Add("i0", data.Array[0]));
else if (data.Type == 0x4F)
arrayEntry.Add(new MsgPack("Type79")
.Add("i0", data.Array[0]));
else if (data.Type == 0x50)
arrayEntry.Add(new MsgPack("Type80")
.Add("i0", data.Array[0]));
else
{
arrayEntry.Add("Type", data.Type);
MsgPack arrayArray = new MsgPack(data.Array.Length, "Array");
for (i1 = 0; i1 < data.Array.Length; i1++)
arrayArray[i1] = data.Array[i1];
arrayEntry.Add(arrayArray);
}
array[i0] = arrayEntry;
}
motion.Add(array);
}
if (Header.Data[i].Array2 == null || Header.Data[i].Array2.Length < 1) { }
else
{
MsgPack array2 = new MsgPack(Header.Data[i].Array2.Length, "Array2");
for (i0 = 0; i0 < Header.Data[i].Array2.Length; i0++)
{
MsgPack arrayEntry = MsgPack.New.Add("Frame", Header.Data[i].Array2[i0].Frame);
if (Header.Data[i].Array2[i0].Array == null || Header.Data[i].Array2[i0].Array.Length < 1) { }
else
{
MsgPack arrayArray = new MsgPack(Header.Data[i].Array2[i0].Array.Length, "Array");
for (i1 = 0; i1 < Header.Data[i].Array2[i0].Array.Length; i1++)
arrayArray[i1] = Header.Data[i].Array2[i0].Array[i1];
arrayEntry.Add(arrayArray);
}
array2[i0] = arrayEntry;
}
motion.Add(array2);
}
motions[I] = motion;
I++;
}
motHead.Add(motions);
motHead.WriteAfterAll(true, file, json);
}
private static bool GetSize(int Type, out int Size)
{
Size = Type switch
{
0x03 => 0x04,
0x35 => 0x14,
0x36 => 0x14,
0x37 => 0x14,
0x38 => 0x14,
0x39 => 0x14,
0x3C => 0x10,
0x3D => 0x08,
0x3E => 0x40,
0x40 => 0x00,
0x41 => 0x04,
0x42 => 0x04,
0x43 => 0x08,
0x44 => 0x08,
0x45 => 0x08,
0x46 => 0x04,
0x47 => 0x08,
0x48 => 0x08,
0x49 => 0x10,
0x4A => 0x02,
0x4B => 0x34,
0x4C => 0x10,
0x4D => 0x04,
0x4F => 0x01,
0x50 => 0x04,
_ => 0x00,
};
return Size > 0;
}
public struct HeaderData
{
public int MotionSetID;
public int StartMotionID;
public int EndMotionID;
public int SubHeaderOffset;
public Sub[] Data;
public struct Sub
{
public int Offset;
public int MotionID;
public int SomeData;
public int Offset2;
public int DataHeaderOffset;
public Data[] Array;
public Data2[] Array2;
public struct Data
{
public int Type;
public int Frame;
public int Offset;
public int[] Array;
}
public struct Data2
{
public int Offset;
public int Frame;
public int[] Array;
}
}
}
}
}
-79
View File
@@ -1,79 +0,0 @@
using KKdMainLib.IO;
namespace KKdMainLib
{
public struct PDHead
{
public int ID;
public int Lenght;
public int DataSize;
public int Signature;
public int SectionSize;
public int InnerSignature;
public int SectionSignature;
public Main.Format Format;
public bool IsBE => Format == Main.Format.F2BE;
public bool IsX => Format == Main.Format.X || Format == Main.Format.XHD;
}
public static class PDHeadExtensions
{
public static PDHead ReadHeader(this Stream stream, bool Seek)
{
if (Seek)
if (stream.Position > 4) stream.LongPosition -= 4;
else stream.LongPosition = 0;
return stream.ReadHeader();
}
public static PDHead ReadHeader(this Stream stream)
{
long Position = stream.LongPosition;
PDHead Header = new PDHead
{ Format = Main.Format.F2LE, Signature = stream.ReadInt32(),
DataSize = stream.ReadInt32(), Lenght = stream.ReadInt32() };
if (stream.ReadUInt32() == 0x18000000)
{ Header.Format = Main.Format.F2BE; }
Header.ID = stream.ReadInt32();
Header.SectionSize = stream.ReadInt32();
if (Header.Lenght == 0x40)
{
stream.Position = 0x30;
Header.InnerSignature = stream.ReadInt32();
}
stream.IsBE = Header.Format == Main.Format.F2BE;
stream.Format = Header.Format;
stream.LongPosition = Position + Header.Lenght;
Header.SectionSignature = stream.ReadInt32Endian();
return Header;
}
public static void Write(this Stream stream, PDHead Header, bool X = false)
{
stream.Write(Header.Signature);
stream.Write(Header.DataSize);
stream.Write((Header.Format < Main.Format.X && !X) ? 0x40 : 0x20);
if (Header.Format == Main.Format.F2BE) stream.Write(0x18000000);
else stream.Write(0x10000000);
stream.Write(Header.ID);
stream.Write(Header.SectionSize);
stream.Write(0x00);
stream.Write(0x00);
if (Header.Format < Main.Format.X && !X)
{
stream.Write(Header.Format < Main.Format.MGF ? (int)((Header.SectionSignature ^
(Header.DataSize * (long)Header.Signature)) - Header.ID + Header.SectionSize) : 0);
stream.Write(0x00);
stream.Write(0x00L);
stream.Write(Header.InnerSignature);
stream.Write(0x00);
stream.Write(0x00L);
}
}
public static void WriteEOFC(this Stream stream, int ID = 0) =>
stream.Write(new PDHead { ID = ID,
Lenght = 0x20, Signature = 0x43464F45 }, true);
}
}
-125
View File
@@ -1,125 +0,0 @@
using System.Collections.Generic;
using KKdMainLib.IO;
namespace KKdMainLib
{
public class POF
{
public byte Type;
public int Lenght;
public int Offset;
public int LastOffset;
public List<long> Offsets;
public List<long> POFOffsets;
public PDHead Header;
public POF()
{ Type = 0; Lenght = 0; Offset = 0; LastOffset = 0; Offsets = new List<long>();
POFOffsets = new List<long>(); Header = new PDHead(); }
}
public static class POFExtensions
{
public static POF AddPOF(this PDHead Header)
{
POF POF = new POF { Offsets = new List<long>(), POFOffsets =
new List<long>(), Offset = Header.DataSize + Header.Lenght };
return POF;
}
public static Stream GetOffset(this Stream stream, ref POF POF)
{
if (POF != null) if (stream.Format > Main.Format.F)
POF.POFOffsets.Add(stream.Position + (stream.IsX ? stream.Offset : 0x00));
return stream;
}
public static void ReadPOF(this Stream stream, ref POF POF)
{
if (stream.ReadString(3) == "POF")
{
POF.POFOffsets.Sort();
POF.Type = byte.Parse(stream.ReadString(1));
int IsX = POF.Type + 2;
stream.Seek(-4, SeekOrigin.Current);
POF.Header = stream.ReadHeader();
stream.Seek(POF.Offset + POF.Header.Lenght, 0);
POF.Lenght = stream.ReadInt32();
while (POF.Lenght + POF.Offset + POF.Header.Lenght > stream.Position)
{
int a = stream.ReadByte();
if (a >> 6 == 0) break;
else if (a >> 6 == 1) a = a & 0x3F;
else if (a >> 6 == 2)
{
a = a & 0x3F;
a = (a << 8) | stream.ReadByte();
}
else if (a >> 6 == 3)
{
a = a & 0x3F;
a = (a << 8) | stream.ReadByte();
a = (a << 8) | stream.ReadByte();
a = (a << 8) | stream.ReadByte();
}
a <<= IsX;
POF.LastOffset += a;
POF.Offsets.Add(POF.LastOffset);
}
for (int i = 0; i < POF.Offsets.Count && i < POF.POFOffsets.Count; i++)
if (POF.Offsets[i] != POF.POFOffsets[i])
System.Console.WriteLine("Not right POF{0} offset table.\n" +
" Expected: {1}\n Got: {2}", POF.Type,
POF.Offsets[i].ToString("X8"), POF.POFOffsets[i].ToString("X8"));
}
}
public static void Write(this Stream stream, ref POF POF, int ID)
{
POF.POFOffsets.Sort();
long CurrentPOFOffset = 0;
long POFOffset = 0;
byte BitShift = (byte)(2 + POF.Type);
int Max1 = (0x00FF >> BitShift) << BitShift;
int Max2 = (0xFFFF >> BitShift) << BitShift;
POF.Lenght = 5 + ID;
for (int i = 0; i < POF.POFOffsets.Count; i++)
{
POFOffset = POF.POFOffsets[i] - CurrentPOFOffset;
CurrentPOFOffset = POF.POFOffsets[i];
if (POFOffset <= Max1) POF.Lenght += 1;
else if (POFOffset <= Max2) POF.Lenght += 2;
else POF.Lenght += 4;
POF.POFOffsets[i] = POFOffset;
}
long POFLenghtAling = POF.Lenght.Align(16);
POF.Header = new PDHead { DataSize = (int)POFLenghtAling, ID = ID, Format = Main.Format.F2LE,
Lenght = 0x20, SectionSize = (int)POFLenghtAling, Signature = 0x30464F50 };
POF.Header.Signature += POF.Type << 24;
stream.Write(POF.Header, true);
stream.Write(POF.Lenght);
for (int i = 0; i < POF.POFOffsets.Count; i++)
{
POFOffset = POF.POFOffsets[i];
if (POFOffset <= Max1) stream.Write (( byte)((1 << 6) | (POFOffset >> BitShift)));
else if (POFOffset <= Max2) stream.WriteEndian((ushort)((2 << 14) | (POFOffset >> BitShift)), true);
else stream.WriteEndian(( uint)((3 << 30) | (POFOffset >> BitShift)), true);
}
stream.Write(0x00);
stream.Align(16, true);
stream.WriteEOFC(ID);
}
public static long ReadUInt32Endian(this Stream IO, ref POF POF ) =>
IO.GetOffset(ref POF).ReadUInt32Endian( );
public static long ReadUInt32Endian(this Stream IO, ref POF POF, bool IsBE) =>
IO.GetOffset(ref POF).ReadUInt32Endian(IsBE);
public static long ReadInt64 (this Stream IO, ref POF POF) =>
IO.GetOffset(ref POF).ReadInt64();
public static string ReadStringAtOffset(this Stream IO, ref POF POF, long Offset = 0, long Length = 0) =>
IO.GetOffset(ref POF).ReadStringAtOffset(Offset, Length);
}
}
-8
View File
@@ -1,15 +1,7 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("KKdMainLib")]
[assembly: AssemblyDescription("A simple library for working with Project Diva AC/DT/F/AFT/F2/X/FT files")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KKdMainLib")]
[assembly: AssemblyCopyright("korenkonder © 2018-2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("2BA7EFC6-91D1-8BBC-C487-06C7F36CC789")]
[assembly: AssemblyVersion("0.4.6.4")]
[assembly: AssemblyFileVersion("0.4.6.4")]
+73
View File
@@ -0,0 +1,73 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace KKdMainLib.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("KKdMainLib.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static byte[] libdeflate {
get {
object obj = ResourceManager.GetObject("libdeflate", resourceCulture);
return ((byte[])(obj));
}
}
}
}
+65
View File
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="libdeflate" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\libdeflate.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>
+131 -139
View File
@@ -1,204 +1,196 @@
using KKdMainLib.IO;
using KKdMainLib.Types;
using KKdMainLib.MessagePack;
using KKdBaseLib;
using KKdBaseLib.F2;
using KKdMainLib.IO;
namespace KKdMainLib
{
public class STR
public struct STR : System.IDisposable
{
public struct String
{
public int ID;
public int StrOffset;
public string Str;
}
private POF pof;
private Header header;
private Stream _IO;
public STR()
{ Offset = 0; OffsetX = 0; STRs = null; POF = null; Header = new PDHead(); }
private long Offset;
private long OffsetX;
public String[] STRs;
private POF POF;
private PDHead Header;
public String[] Strings;
public int STRReader(string filepath, string ext)
{
Stream reader = File.OpenReader(filepath + ext);
_IO = File.OpenReader(filepath + ext);
Header = new PDHead();
reader.Format = Main.Format.F;
Header.Signature = reader.ReadInt32();
if (Header.Signature == 0x41525453)
header = new Header();
_IO.Format = Format.F;
header.Signature = _IO.RI32();
if (header.Signature == 0x41525453)
{
Header = reader.ReadHeader(true);
POF = Header.AddPOF();
reader.Position = Header.Lenght;
long Count = reader.ReadInt32Endian();
Offset = reader.ReadInt32Endian();
if (Offset == 0)
{
Offset = Count;
OffsetX = reader.ReadInt64();
Count = reader.ReadInt64();
reader.Offset = Header.Lenght;
reader.Format = Main.Format.X;
}
reader.LongPosition = reader.IsX ? Offset + reader.Offset : Offset;
header = _IO.ReadHeader(true, false);
STRs = new String[Count];
for (int i = 0; i < Count; i++)
int count = _IO.RI32E();
int offset = _IO.RI32E();
_IO.P = offset;
Strings = new String[count];
for (int i = 0; i < count; i++)
{
STRs[i].StrOffset = reader.GetOffset(ref POF).ReadInt32Endian();
STRs[i].ID = reader.ReadInt32Endian();
if (reader.IsX) STRs[i].StrOffset += (int)OffsetX;
Strings[i].Str.O = _IO.RI32E();
Strings[i].ID = _IO.RI32E();
}
for (int i = 0; i < Count; i++)
{
reader.LongPosition = STRs[i].StrOffset + (reader.IsX ? reader.Offset : 0);
STRs[i].Str = reader.NullTerminatedUTF8();
}
reader.Position = POF.Offset;
reader.ReadPOF(ref POF);
_IO.O = 0;
for (int i = 0; i < count; i++)
Strings[i].Str.V = Strings[i].Str.O > 0 ?
_IO.RSaO(Strings[i].Str.O) : null;
}
else
{
reader.Position -= 4;
int Count = 0;
for (int a = 0, i = 0; reader.Position > 0 && reader.Position < reader.Length; i++, Count++)
_IO.P -= 4;
int count = 0;
for (int a = 0, i = 0; _IO.P > 0 && _IO.P < _IO.L; i++, count++)
{
a = reader.ReadInt32();
a = _IO.RI32();
if (a == 0) break;
}
STRs = new String[Count];
Strings = new String[count];
for (int i = 0; i < Count; i++)
for (int i = 0; i < count; i++)
{
reader.LongPosition = STRs[i].StrOffset + (reader.IsX ? reader.Offset : 0);
STRs[i].ID = i;
STRs[i].Str = reader.NullTerminatedUTF8();
_IO.PI64 = Strings[i].Str.O;
Strings[i].ID = i;
Strings[i].Str.V = _IO.NTUTF8();
}
}
reader.Close();
_IO.C();
return 1;
}
public void STRWriter(string filepath)
{
uint Offset = 0;
uint CurrentOffset = 0;
Stream writer = File.OpenWriter(filepath + (Header.
Format > Main.Format.FT ? ".str" : ".bin"), true);
writer.Format = Header.Format;
POF = new POF();
writer.IsBE = writer.Format == Main.Format.F2BE;
if (Strings == null || Strings.Length == 0 || header.Format > Format.F2BE) return;
uint offset = 0;
uint currentOffset = 0;
_IO = File.OpenWriter(filepath + (header.Format > Format.AFT &&
header.Format < Format.FT ? ".str" : ".bin"), true);
_IO.Format = header.Format;
pof.Offsets = KKdList<long>.New;
long Count = STRs.LongLength;
if (writer.Format > Main.Format.FT)
long count = Strings.LongLength;
if (_IO.Format > Format.AFT && _IO.Format < Format.FT)
{
writer.Position = 0x40;
writer.WriteEndian(Count);
writer.GetOffset(ref POF).WriteEndian(0x80);
writer.Position = 0x80;
for (int i = 0; i < Count; i++)
{
writer.GetOffset(ref POF).Write(0x00);
writer.WriteEndian(STRs[i].ID);
}
writer.Align(0x10);
_IO.P = 0x40;
_IO.WX(count, ref pof);
_IO.WX(0x80);
_IO.P = 0x80;
for (int i = 0; i < count; i++) _IO.W(0x00L);
_IO.A(0x10);
}
else
{
for (int i = 0; i < Count; i++) writer.Write(0x00);
writer.Align(0x20);
for (int i = 0; i < count; i++) _IO.W(0x00);
_IO.A(0x20);
}
KKdList<string> UsedSTR = KKdList<string>.New;
KKdList<int> UsedSTRPos = KKdList<int>.New;
int[] STRPos = new int[Count];
for (int i1 = 0; i1 < Count; i1++)
KKdList<string> usedSTR = KKdList<string>.New;
KKdList<int> usedSTRPos = KKdList<int>.New;
int[] STRPos = new int[count];
usedSTRPos.Add(_IO.P);
usedSTR.Add("");
_IO.W(0);
for (int i = 0; i < count; i++)
{
if (UsedSTR.Contains(STRs[i1].Str))
if (!usedSTR.Contains(Strings[i].Str.V))
{
for (int i2 = 0; i2 < Count; i2++)
if (UsedSTR[i2] == STRs[i1].Str)
{ STRPos[i1] = UsedSTRPos[i2]; break; }
STRPos[i] = _IO.P;
usedSTRPos.Add(STRPos[i]);
usedSTR.Add(Strings[i].Str.V);
_IO.W(Strings[i].Str.V);
_IO.W(0);
}
else
{
STRPos[i1] = writer.Position;
UsedSTRPos.Add(STRPos[i1]);
UsedSTR.Add(STRs[i1].Str);
writer.Write(STRs[i1].Str);
writer.WriteByte(0);
}
for (int i2 = 0; i2 < count; i2++)
if (usedSTR[i2] == Strings[i].Str.V) { STRPos[i] = usedSTRPos[i2]; break; }
}
if (writer.Format > Main.Format.FT)
if (_IO.Format > Format.AFT)
{
writer.Align(0x10);
Offset = writer.UIntPosition;
writer.Position = 0x80;
_IO.A(0x10);
offset = _IO.PU32;
_IO.P = 0x80;
for (int i = 0; i < count; i++)
{
pof.Offsets.Add(_IO.P);
_IO.WE(STRPos[i]);
_IO.WE(Strings[i].ID);
}
_IO.PU32 = offset;
_IO.W(pof, false, 1);
currentOffset = _IO.PU32;
_IO.WEOFC();
header.DataSize = (int)(currentOffset - 0x40);
header.Signature = 0x41525453;
header.SectionSize = (int)(offset - 0x40);
_IO.P = 0;
_IO.W(header, true);
}
else
writer.Position = 0;
for (int i1 = 0; i1 < Count; i1++)
{
writer.WriteEndian(STRPos[i1]);
if (writer.Format > Main.Format.FT) writer.Position += 4;
_IO.P = 0;
for (int i = 0; i < count; i++) _IO.W(STRPos[i]);
}
if (writer.Format > Main.Format.FT)
{
writer.UIntPosition = Offset;
writer.Write(ref POF, 1);
CurrentOffset = writer.UIntPosition;
writer.WriteEOFC(0);
Header.Lenght = 0x40;
Header.DataSize = (int)(CurrentOffset - Header.Lenght);
Header.Signature = 0x41525453;
Header.SectionSize = (int)(Offset - Header.Lenght);
writer.Position = 0;
writer.Write(Header);
}
writer.Close();
_IO.C();
}
public void MsgPackReader(string file, bool JSON)
public void MsgPackReader(string file, bool json)
{
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
MsgPack temp;
MsgPack msgPack = file.ReadMPAllAtOnce(json);
if ((temp = msgPack["STR"]).NotNull) return;
if (!MsgPack.Element("STR", out MsgPack STR)) return;
header = new Header();
System.Enum.TryParse(temp.RS("Format"), out header.Format);
if (!STR.ElementArray("Strings", out MsgPack Strings)) return;
if ((temp = msgPack["Strings", true]).IsNull) return;
STRs = new String[Strings.Array.Length];
for (int i = 0; i < STRs.Length; i++)
Strings = new String[temp.Array.Length];
for (int i = 0; i < Strings.Length; i++)
{
STRs[i].ID = Strings[i].ReadInt32 ("ID" );
STRs[i].Str = Strings[i].ReadString("Str");
Strings[i].ID = temp[i].RI32("ID" );
Strings[i].Str.V = temp[i].RS ("Str");
if (Strings[i].Str.V == null) Strings[i].Str.V = "";
}
MsgPack = MsgPack.New;
msgPack.Dispose();
}
public void MsgPackWriter(string file, bool JSON)
public void MsgPackWriter(string file, bool json)
{
MsgPack STR_ = new MsgPack("STR").Add("Format", Header.Format.ToString());
MsgPack Strings = new MsgPack(STRs.Length, "Strings");
for (int i = 0; i < STRs.Length; i++)
if (Strings == null || Strings.Length == 0) return;
MsgPack str = new MsgPack("STR").Add("Format", header.Format.ToString());
MsgPack strings = new MsgPack(Strings.Length, "Strings");
for (int i = 0; i < Strings.Length; i++)
{
Strings[i] = MsgPack.New.Add("ID", STRs[i].ID);
if (STRs[i].Str != null) if (STRs[i].Str != "")
Strings[i].Add("S", STRs[i].Str); ;
strings[i] = MsgPack.New.Add("ID", Strings[i].ID);
if (Strings[i].Str.V != null)
if (Strings[i].Str.V != "")
strings[i] = strings[i].Add("Str", Strings[i].Str.V);
}
STR_.Add(Strings);
str.Add(strings);
STR_.Write(true, file, JSON);
str.WriteAfterAll(true, file, json);
}
private bool disposed;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.Dispose(); Strings = default;
pof = default; header = default; disposed = true; } }
public struct String
{
public int ID;
public Pointer<string> Str;
public override string ToString() => "ID: " + ID + (Str.V != null ||
Str.V != "" ? ("; Str: " + Str.V) : "");
}
}
}
+959
View File
@@ -0,0 +1,959 @@
using KKdBaseLib;
using KKdMainLib.IO;
using TableDict = System.Collections.Generic.Dictionary<string, object>;
namespace KKdMainLib
{
public struct Tables : System.IDisposable
{
private int i0;
private Stream _IO;
private TableDict dict;
public ButtonSE[] ButtonSETable;
public ChainSlideSE[] ChainSlideSETable;
public SlideSE[] SlideSETable;
public SliderTouchSE[] SliderTouchSETable;
public CollectionCard[] CollectionCardTable;
public CustomizeItem[] CustomizeItemTable;
public Module[] ModuleTable;
public Plate[] PlateTable;
public PV[] PVList;
private const string c = ".";
public Tables(bool def = true)
{
i0 = 0;
_IO = null;
dict = null;
disposed = false;
ButtonSETable = null; ChainSlideSETable = null; SlideSETable = null; SliderTouchSETable = null;
CollectionCardTable = null; CustomizeItemTable = null;
ModuleTable = null; PlateTable = null; PVList = null;
}
public void BINReader(string file) =>
BINReader(File.ReadAllBytes(file + ".bin"));
public void BINReader(byte[] data)
{
ButtonSETable = null; ChainSlideSETable = null; SlideSETable = null; SliderTouchSETable = null;
CollectionCardTable = null; CustomizeItemTable = null;
ModuleTable = null; PlateTable = null; PVList = null;
dict = new TableDict();
string[] strData = data.ToUTF8().Replace("\r\n", "\n").Replace("\r", "\n").Split('\n');
for (i0 = 0; i0 < strData.Length; i0++)
dict.GD(strData[i0]);
strData = null;
int length;
string name;
if (dict.FV(out length, "btn_se.data_list.length"))
{
ButtonSETable = new ButtonSE[length];
for (i0 = 0; i0 < length; i0++)
{
name = "btn_se" + c + i0 + c;
ref ButtonSE btn = ref ButtonSETable[i0];
dict.FV(out btn. ID , name + "id" );
dict.FV(out btn. Name , name + "name" );
dict.FV(out btn. SEName , name + "se_name" );
dict.FV(out btn.SortIndex, name + "sort_index");
btn.Start = GetStartTableDate(dict, name);
btn.End = GetEndTableDate(dict, name);
}
}
else if (dict.FV(out length, "chainslide_se.data_list.length"))
{
ChainSlideSETable = new ChainSlideSE[length];
for (i0 = 0; i0 < length; i0++)
{
name = "chainslide_se" + c + i0 + c;
ref ChainSlideSE csld = ref ChainSlideSETable[i0];
dict.FV(out csld. ID , name + "id" );
dict.FV(out csld. Name , name + "name" );
dict.FV(out csld. FirstSEName , name + "first_se_name" );
dict.FV(out csld.FailureSEName , name + "failure_se_name" );
dict.FV(out csld. SortIndex, name + "sort_index");
dict.FV(out csld. SubSEName , name + "sub_se_name" );
dict.FV(out csld.SuccessSEName , name + "success_se_name" );
csld.Start = GetStartTableDate(dict, name);
csld.End = GetEndTableDate(dict, name);
}
}
else if (dict.FV(out length, "collection_card.data_list.length"))
{
CollectionCardTable = new CollectionCard[length];
for (i0 = 0; i0 < length; i0++)
{
name = "collection_card" + c + i0 + c;
ref CollectionCard clcrd = ref CollectionCardTable[i0];
dict.FV(out clcrd.Chara , name + "chara" );
dict.FV(out clcrd.DispNum , name + "disp_num" );
dict.FV(out clcrd.DivaProParam, name + "divapro_param");
dict.FV(out clcrd.ID , name + "id" );
dict.FV(out clcrd.ModuleAuthor, name + "module_author");
dict.FV(out clcrd.Name , name + "name" );
dict.FV(out clcrd.NameReading , name + "name_reading" );
dict.FV(out clcrd.NG , name + "ng" );
dict.FV(out clcrd.SortIndex , name + "sort_idx" );
dict.FV(out clcrd.Type , name + "type" );
dict.FV(out clcrd.TypeParam , name + "type_param" );
dict.FV(out clcrd.WallParam , name + "wall_param" );
clcrd.Start = GetStartTableDate(dict, name);
clcrd.End = GetEndTableDate(dict, name);
}
}
else if (dict.FV(out length, "cstm_item.data_list.length"))
{
CustomizeItemTable = new CustomizeItem[length];
for (i0 = 0; i0 < length; i0++)
{
name = "cstm_item" + c + i0 + c;
ref CustomizeItem czitm = ref CustomizeItemTable[i0];
dict.FV(out czitm.Chara , name + "chara" );
dict.FV(out czitm.ID , name + "id" );
dict.FV(out czitm.Name , name + "name" );
dict.FV(out czitm.NG , name + "ng" );
dict.FV(out czitm.ObjID , name + "obj_id" );
dict.FV(out czitm.Parts , name + "parts" );
dict.FV(out czitm.SellType , name + "sell_type" );
dict.FV(out czitm.ShopPrice, name + "shop_price");
dict.FV(out czitm.SortIndex, name + "sort_index");
czitm.ShopStart = GetStartTableDate(dict, name + "shop_");
czitm.ShopEnd = GetEndTableDate(dict, name + "shop_");
}
}
else if (dict.FV(out length, "module.data_list.length"))
{
ModuleTable = new Module[length];
for (i0 = 0; i0 < length; i0++)
{
name = "module" + c + i0 + c;
ref Module mdl = ref ModuleTable[i0];
dict.FV(out mdl.Attribute, name + "attr" );
dict.FV(out mdl.Chara , name + "chara" );
dict.FV(out mdl.Costume , name + "cos" );
dict.FV(out mdl.ID , name + "id" );
dict.FV(out mdl.Name , name + "name" );
dict.FV(out mdl.NG , name + "ng" );
dict.FV(out mdl.ShopPrice, name + "shop_price");
dict.FV(out mdl.SortIndex, name + "sort_index");
mdl.ShopStart = GetStartTableDate(dict, name + "shop_");
mdl.ShopEnd = GetEndTableDate(dict, name + "shop_");
}
}
else if (dict.FV(out length, "plate.data_list.length"))
{
PlateTable = new Plate[length];
for (i0 = 0; i0 < length; i0++)
{
name = "plate" + c + i0 + c;
ref Plate plt = ref PlateTable[i0];
dict.FV(out plt.Alpha , name + "alpha" );
dict.FV(out plt.BaseID , name + "base_id" );
dict.FV(out plt.Border , name + "border" );
dict.FV(out plt.ColorB , name + "color_b" );
dict.FV(out plt.ColorG , name + "color_g" );
dict.FV(out plt.ColorR , name + "color_r" );
dict.FV(out plt.Font , name + "font" );
dict.FV(out plt.ID , name + "id" );
dict.FV(out plt.Shadow , name + "shadow" );
dict.FV(out plt.ShadowAlpha , name + "shadow_alpha" );
dict.FV(out plt.ShadowColorB, name + "shadow_color_b");
dict.FV(out plt.ShadowColorG, name + "shadow_color_g");
dict.FV(out plt.ShadowColorR, name + "shadow_color_r");
}
}
else if (dict.FV(out length, "pv_list.data_list.length"))
{
PVList = new PV[length];
for (i0 = 0; i0 < length; i0++)
{
name = "pv_list" + c + i0 + c;
ref PV pv = ref PVList[i0];
dict.FV(out pv.ID , name + "id" );
dict.FV(out pv.Ignore, name + "ignore");
dict.FV(out pv.Name , name + "name" );
pv.AdvStart = GetStartTableDate(dict, name + "adv_demo_");
pv.AdvEnd = GetEndTableDate(dict, name + "adv_demo_");
pv.Easy = GetDifficulty(dict, name + "easy" + c);
pv.Encore = GetDifficulty(dict, name + "encore" + c);
pv.Extreme = GetDifficulty(dict, name + "extreme" + c);
pv.Hard = GetDifficulty(dict, name + "hard" + c);
pv.Normal = GetDifficulty(dict, name + "normal" + c);
}
static PV.Difficulty[] GetDifficulty(TableDict dict, string name)
{
int len, val;
if (!dict.FV(out len, name + "length") || len < 0) return null;
PV.Difficulty[] arr = new PV.Difficulty[len];
for (int i = 0; i < len; i++)
{
if (dict.FV(out val, $"{name}{i}.edition")) arr[i].Edition = val;
if (dict.FV(out val, $"{name}{i}.ver" )) arr[i].Version = val;
arr[i].Start = GetStartTableDate(dict, $"{name}{i}.");
arr[i].End = GetEndTableDate(dict, $"{name}{i}.");
}
return arr;
}
}
else if (dict.FV(out length, "slide_se.data_list.length"))
{
SlideSETable = new SlideSE[length];
for (i0 = 0; i0 < length; i0++)
{
name = "slide_se" + c + i0 + c;
ref SlideSE sld = ref SlideSETable[i0];
dict.FV(out sld. ID , name + "id" );
dict.FV(out sld. Name , name + "name" );
dict.FV(out sld. SEName , name + "se_name" );
dict.FV(out sld.SortIndex, name + "sort_index");
sld.Start = GetStartTableDate(dict, name);
sld.End = GetEndTableDate(dict, name);
}
}
else if (dict.FV(out length, "slidertouch_se.data_list.length"))
{
SliderTouchSETable = new SliderTouchSE[length];
for (i0 = 0; i0 < length; i0++)
{
name = "slidertouch_se" + c + i0 + c;
ref SliderTouchSE stld = ref SliderTouchSETable[i0];
dict.FV(out stld. ID , name + "id" );
dict.FV(out stld. Name , name + "name" );
dict.FV(out stld. SEName , name + "se_name" );
dict.FV(out stld.SortIndex, name + "sort_index");
stld.Start = GetStartTableDate(dict, name);
stld.End = GetEndTableDate(dict, name);
}
}
static TableDate GetStartTableDate(TableDict dict, string name)
{
TableDate date = default; date.SDL(); int val;
if (dict.FV(out val, name + "st_day" )) date.Day = val;
if (dict.FV(out val, name + "st_month")) date.Month = val;
if (dict.FV(out val, name + "st_year" )) date.Year = val;
return date;
}
static TableDate GetEndTableDate(TableDict dict, string name)
{
TableDate date = default; date.SDU(); int val;
if (dict.FV(out val, name + "ed_day" )) date.Day = val;
if (dict.FV(out val, name + "ed_month")) date.Month = val;
if (dict.FV(out val, name + "ed_year" )) date.Year = val;
return date;
}
}
public void BINWriter(string file)
{
int[] so;
int length;
string name;
if (ButtonSETable != null)
{
_IO = File.OpenWriter(file + ".bin", true);
length = ButtonSETable.Length;
so = length.SW();
WriteEmptyLines(_IO, length);
for (i0 = 0; i0 < length; i0++)
{
name = "btn_se" + c + so[i0] + c;
ref ButtonSE btn = ref ButtonSETable[so[i0]];
WriteEndTableDate(_IO, name, btn.End);
W(name + "id" , btn. ID );
W(name + "name" , btn. Name );
W(name + "se_name" , btn. SEName );
W(name + "sort_index", btn.SortIndex);
WriteStartTableDate(_IO, name, btn.Start);
}
W("btn_se.data_list.length", length);
_IO.W("kind=0\n");
_IO.D();
}
else if (ChainSlideSETable != null)
{
_IO = File.OpenWriter(file + ".bin", true);
length = ChainSlideSETable.Length;
so = length.SW();
WriteEmptyLines(_IO, length);
for (i0 = 0; i0 < length; i0++)
{
name = "chainslide_se" + c + so[i0] + c;
ref ChainSlideSE csld = ref ChainSlideSETable[so[i0]];
WriteEndTableDate(_IO, name, csld.End);
W(name + "failure_se_name" , csld.FailureSEName );
W(name + "first_se_name" , csld. FirstSEName );
W(name + "id" , csld. ID );
W(name + "name" , csld. Name );
W(name + "sort_index", csld. SortIndex);
WriteStartTableDate(_IO, name, csld.Start);
W(name + "sub_se_name" , csld. SubSEName );
W(name + "success_se_name" , csld.SuccessSEName );
}
W("chainslide_se.data_list.length", length);
_IO.W("kind=2\n");
_IO.D();
}
else if (CollectionCardTable != null)
{
_IO = File.OpenWriter(file + ".bin", true);
length = CollectionCardTable.Length;
so = length.SW();
WriteEmptyLines(_IO, length);
for (i0 = 0; i0 < length; i0++)
{
name = "collection_card" + c + so[i0] + c;
ref CollectionCard clcrd = ref CollectionCardTable[so[i0]];
W(name + "chara" , clcrd.Chara );
W(name + "disp_num" , clcrd.DispNum );
W(name + "divapro_param", clcrd.DivaProParam);
WriteEndTableDate(_IO, name, clcrd.End);
W(name + "id" , clcrd.ID );
W(name + "module_author", clcrd.ModuleAuthor);
W(name + "name" , clcrd.Name );
W(name + "name_reading" , clcrd.NameReading );
W(name + "ng" , clcrd.NG );
W(name + "sort_idx" , clcrd.SortIndex );
WriteStartTableDate(_IO, name, clcrd.Start);
W(name + "type" , clcrd.Type );
W(name + "type_param" , clcrd.TypeParam );
W(name + "wall_param" , clcrd.WallParam );
}
W("collection_card.data_list.length", length);
_IO.W("patch=0\n");
_IO.W("version=0\n");
_IO.D();
}
else if (CustomizeItemTable != null)
{
_IO = File.OpenWriter(file + ".bin", true);
length = CustomizeItemTable.Length;
so = length.SW();
WriteEmptyLines(_IO, length);
for (i0 = 0; i0 < length; i0++)
{
name = "cstm_item" + c + so[i0] + c;
ref CustomizeItem czitm = ref CustomizeItemTable[so[i0]];
W(name + "chara" , czitm.Chara );
W(name + "id" , czitm.ID );
W(name + "name" , czitm.Name );
W(name + "ng" , czitm.NG );
W(name + "obj_id" , czitm.ObjID );
W(name + "parts" , czitm.Parts );
W(name + "sell_type" , czitm.SellType );
WriteEndTableDate(_IO, name + "shop_", czitm.ShopEnd);
W(name + "shop_price", czitm.ShopPrice);
WriteStartTableDate(_IO, name + "shop_", czitm.ShopStart);
W(name + "sort_index", czitm.SortIndex);
}
W("cstm_item.data_list.length", length);
_IO.W("patch=0\n");
_IO.W("version=0\n");
_IO.D();
}
else if (ModuleTable != null)
{
_IO = File.OpenWriter(file + ".bin", true);
length = ModuleTable.Length;
so = length.SW();
WriteEmptyLines(_IO, length);
for (i0 = 0; i0 < length; i0++)
{
name = "module" + c + so[i0] + c;
ref Module mdl = ref ModuleTable[so[i0]];
W(name + "attr" , mdl.Attribute);
W(name + "chara" , mdl.Chara );
W(name + "cos" , mdl.Costume );
W(name + "id" , mdl.ID );
W(name + "name" , mdl.Name );
W(name + "ng" , mdl.NG );
WriteEndTableDate(_IO, name + "shop_", mdl.ShopEnd);
W(name + "shop_price", mdl.ShopPrice);
WriteStartTableDate(_IO, name + "shop_", mdl.ShopStart);
W(name + "sort_index", mdl.SortIndex);
}
W("module.data_list.length", length);
_IO.D();
}
else if (PlateTable != null)
{
_IO = File.OpenWriter(file + ".bin", true);
length = PlateTable.Length;
so = length.SW();
WriteEmptyLines(_IO, length);
for (i0 = 0; i0 < length; i0++)
{
name = "plate" + c + so[i0] + c;
ref Plate plt = ref PlateTable[so[i0]];
W(name + "alpha" , plt.Alpha );
W(name + "base_id" , plt.BaseID );
W(name + "border" , plt.Border );
W(name + "color_b" , plt.ColorB );
W(name + "color_g" , plt.ColorG );
W(name + "color_r" , plt.ColorR );
W(name + "font" , plt.Font );
W(name + "id" , plt.ID );
W(name + "shadow" , plt.Shadow );
W(name + "shadow_alpha" , plt.ShadowAlpha );
W(name + "shadow_color_b", plt.ShadowColorB);
W(name + "shadow_color_g", plt.ShadowColorG);
W(name + "shadow_color_r", plt.ShadowColorR);
}
W("plate.data_list.length", length);
_IO.D();
}
else if (PVList != null)
{
_IO = File.OpenWriter(file + ".bin", true);
length = PVList.Length;
so = length.SW();
WriteEmptyLines(_IO, length);
for (i0 = 0; i0 < length; i0++)
{
name = "pv_list" + c + so[i0] + c;
ref PV pv = ref PVList[so[i0]];
WriteEndTableDate(_IO, name + "adv_demo_", pv.AdvEnd );
WriteStartTableDate(_IO, name + "adv_demo_", pv.AdvStart);
WriteDifficulty(_IO, name + "easy.", pv.Easy );
WriteDifficulty(_IO, name + "encore.", pv.Encore );
WriteDifficulty(_IO, name + "extreme.", pv.Extreme);
WriteDifficulty(_IO, name + "hard.", pv.Hard );
W(name + "id" , pv.ID );
W(name + "ignore", pv.Ignore);
W(name + "name" , pv.Name );
WriteDifficulty(_IO, name + "extreme.", pv.Normal );
}
W("pv_list.data_list.length", length);
_IO.D();
static void WriteDifficulty(Stream _IO, string name, PV.Difficulty[] arr)
{
if (arr == null) { _IO.W($"{name}.length=0\n"); return; }
int length = arr.Length;
int[] so = length.SW();
for (int i = 0; i < length; i++)
{
ref PV.Difficulty diff = ref arr[so[i]];
WriteStartTableDate(_IO, $"{name}{i}.", diff.Start);
_IO.W($"{name}{i}.edition" + $"={diff.Edition}\n");
WriteEndTableDate(_IO, $"{name}{i}.", diff.End );
_IO.W($"{name}{i}.ver" + $"={diff.Version}\n");
}
_IO.W($"{name}.length={length}\n");
}
}
else if (SlideSETable != null)
{
_IO = File.OpenWriter(file + ".bin", true);
length = SlideSETable.Length;
so = length.SW();
WriteEmptyLines(_IO, length);
_IO.W("kind=1\n");
for (i0 = 0; i0 < length; i0++)
{
name = "slide_se" + c + so[i0] + c;
ref SlideSE sld = ref SlideSETable[so[i0]];
WriteEndTableDate(_IO, name, sld.End);
W(name + "id" , sld. ID );
W(name + "name" , sld. Name );
W(name + "se_name" , sld. SEName );
W(name + "sort_index", sld.SortIndex);
WriteStartTableDate(_IO, name, sld.Start);
}
W("slide_se.data_list.length", length);
_IO.D();
}
else if (SliderTouchSETable != null)
{
_IO = File.OpenWriter(file + ".bin", true);
length = SliderTouchSETable.Length;
so = length.SW();
WriteEmptyLines(_IO, length);
_IO.W("kind=3\n");
for (i0 = 0; i0 < length; i0++)
{
name = "slidertouch_se" + c + so[i0] + c;
ref SliderTouchSE sldt = ref SliderTouchSETable[so[i0]];
WriteEndTableDate(_IO, name, sldt.End);
W(name + "id" , sldt. ID );
W(name + "name" , sldt. Name );
W(name + "se_name" , sldt. SEName );
W(name + "sort_index", sldt.SortIndex);
WriteStartTableDate(_IO, name, sldt.Start);
}
W("slidertouch_se.data_list.length", length);
_IO.D();
}
static void WriteEmptyLines(Stream _IO, int count)
{ for (int i = 0; i < count; i++) _IO.W("#---------------------------------------------\n"); }
static void WriteStartTableDate(Stream _IO, string name, TableDate date)
{
_IO.W(name + "st_day" + "=" + date.Day + "\n");
_IO.W(name + "st_month" + "=" + date.Month + "\n");
_IO.W(name + "st_year" + "=" + date.Year + "\n");
}
static void WriteEndTableDate(Stream _IO, string name, TableDate date)
{
_IO.W(name + "ed_day" + "=" + date.Day + "\n");
_IO.W(name + "ed_month" + "=" + date.Month + "\n");
_IO.W(name + "ed_year" + "=" + date.Year + "\n");
}
}
private void W(string Data, long val) =>
_IO.W(Data + "=" + val + "\n");
private void W(string Data, string val)
{ if (val != null) _IO.W(Data + "=" + val + "\n"); }
public void MsgPackReader(string file, bool json)
{
ButtonSETable = null; ChainSlideSETable = null; SlideSETable = null; SliderTouchSETable = null;
CollectionCardTable = null; CustomizeItemTable = null;
ModuleTable = null; PlateTable = null; PVList = null;
MsgPack msgPack = file.ReadMPAllAtOnce(json);
MsgPack temp;
if ((temp = msgPack["ButtonSETable", true]).NotNull)
{
ButtonSETable = new ButtonSE[temp.Array.Length];
for (i0 = 0; i0 < ButtonSETable.Length; i0++)
{
MsgPack btnMP = temp[i0];
ref ButtonSE btn = ref ButtonSETable[i0];
btn.End .SV(btnMP.RnI32("End" ), true);
btn.Start.SV(btnMP.RnI32("Start"), false);
btnMP.R( "ID" , out btn. ID );
btnMP.R( "Name" , out btn. Name );
btnMP.R( "SEName" , out btn. SEName );
btnMP.R("SortIndex", out btn.SortIndex);
}
}
else if ((temp = msgPack["ChainSlideSETable", true]).NotNull)
{
ChainSlideSETable = new ChainSlideSE[temp.Array.Length];
for (i0 = 0; i0 < ChainSlideSETable.Length; i0++)
{
MsgPack csldMP = temp[i0];
ref ChainSlideSE csld = ref ChainSlideSETable[i0];
csld.End .SV(csldMP.RnI32("End" ), true);
csld.Start.SV(csldMP.RnI32("Start"), false);
csldMP.R("FailureSEName" , out csld.FailureSEName );
csldMP.R( "FirstSEName" , out csld. FirstSEName );
csldMP.R( "ID" , out csld. ID );
csldMP.R( "Name" , out csld. Name );
csldMP.R( "SortIndex", out csld. SortIndex);
csldMP.R( "SubSEName" , out csld. SubSEName );
csldMP.R("SuccessSEName" , out csld.SuccessSEName );
}
}
else if ((temp = msgPack["CollectionCardTable", true]).NotNull)
{
CollectionCardTable = new CollectionCard[temp.Array.Length];
for (i0 = 0; i0 < CollectionCardTable.Length; i0++)
{
MsgPack clcrdMP = temp[i0];
ref CollectionCard clcrd = ref CollectionCardTable[i0];
clcrd.End .SV(clcrdMP.RnI32("End" ), true);
clcrd.Start.SV(clcrdMP.RnI32("Start"), false);
clcrdMP.R("Chara" , out clcrd.Chara );
clcrdMP.R("DispNum" , out clcrd.DispNum );
clcrdMP.R("DivaProParam", out clcrd.DivaProParam);
clcrdMP.R("ID" , out clcrd.ID );
clcrdMP.R("ModuleAuthor", out clcrd.ModuleAuthor);
clcrdMP.R("Name" , out clcrd.Name );
clcrdMP.R("NameReading" , out clcrd.NameReading );
clcrdMP.R("NG" , out clcrd.NG );
clcrdMP.R("SortIndex" , out clcrd.SortIndex );
clcrdMP.R("Type" , out clcrd.Type );
clcrdMP.R("TypeParam" , out clcrd.TypeParam );
clcrdMP.R("WallParam" , out clcrd.WallParam );
}
}
else if ((temp = msgPack["CustomizeItemTable", true]).NotNull)
{
CustomizeItemTable = new CustomizeItem[temp.Array.Length];
for (i0 = 0; i0 < CustomizeItemTable.Length; i0++)
{
MsgPack czitmMP = temp[i0];
ref CustomizeItem czitm = ref CustomizeItemTable[i0];
czitm.ShopEnd .SV(czitmMP.RnI32("ShopEnd" ), true);
czitm.ShopStart.SV(czitmMP.RnI32("ShopStart"), false);
czitmMP.R("Chara" , out czitm.Chara );
czitmMP.R("ID" , out czitm.ID );
czitmMP.R("Name" , out czitm.Name );
czitmMP.R("NG" , out czitm.NG );
czitmMP.R("ObjID" , out czitm.ObjID );
czitmMP.R("Parts" , out czitm.Parts );
czitmMP.R("SellType" , out czitm.SellType );
czitmMP.R("ShopPrice", out czitm.ShopPrice);
czitmMP.R("SortIndex", out czitm.SortIndex);
}
}
else if ((temp = msgPack["ModuleTable", true]).NotNull)
{
ModuleTable = new Module[temp.Array.Length];
for (i0 = 0; i0 < ModuleTable.Length; i0++)
{
MsgPack mdlMP = temp[i0];
ref Module mdl = ref ModuleTable[i0];
mdl.ShopEnd .SV(mdlMP.RnI32("ShopEnd" ), true);
mdl.ShopStart.SV(mdlMP.RnI32("ShopStart"), false);
mdlMP.R("Attribute", out mdl.Attribute);
mdlMP.R("Costume" , out mdl.Costume );
mdlMP.R("Chara" , out mdl.Chara );
mdlMP.R("ID" , out mdl.ID );
mdlMP.R("Name" , out mdl.Name );
mdlMP.R("NG" , out mdl.NG );
mdlMP.R("ShopPrice", out mdl.ShopPrice);
mdlMP.R("SortIndex", out mdl.SortIndex);
}
}
else if ((temp = msgPack["PlateTable", true]).NotNull)
{
PlateTable = new Plate[temp.Array.Length];
for (i0 = 0; i0 < PlateTable.Length; i0++)
{
MsgPack pltMP = temp[i0];
ref Plate plt = ref PlateTable[i0];
pltMP.R("Alpha" , out plt.Alpha );
pltMP.R("BaseID" , out plt.BaseID );
pltMP.R("Border" , out plt.Border );
pltMP.R("ColorB" , out plt.ColorB );
pltMP.R("ColorG" , out plt.ColorG );
pltMP.R("ColorR" , out plt.ColorR );
pltMP.R("Font" , out plt.Font );
pltMP.R("ID" , out plt.ID );
pltMP.R("Shadow" , out plt.Shadow );
pltMP.R("ShadowAlpha" , out plt.ShadowAlpha );
pltMP.R("ShadowColorB", out plt.ShadowColorB);
pltMP.R("ShadowColorG", out plt.ShadowColorG);
pltMP.R("ShadowColorR", out plt.ShadowColorR);
}
}
else if ((temp = msgPack["PV", true]).NotNull)
{
PVList = new PV[temp.Array.Length];
for (i0 = 0; i0 < PVList.Length; i0++)
{
MsgPack pvMP = temp[i0];
ref PV pv = ref PVList[i0];
pv.AdvEnd .SV(pvMP.RnI32("AdvEnd" ), true);
pv.AdvStart.SV(pvMP.RnI32("AdvStart"), false);
pvMP.R("ID" , out pv.ID );
pvMP.R("Ignore", out pv.Ignore);
pvMP.R("Name" , out pv.Name );
pv.Easy = GetDifficulty(pvMP, "Easy" );
pv.Normal = GetDifficulty(pvMP, "Normal" );
pv.Hard = GetDifficulty(pvMP, "Hard" );
pv.Extreme = GetDifficulty(pvMP, "Extreme");
pv.Encore = GetDifficulty(pvMP, "Encore" );
}
static PV.Difficulty[] GetDifficulty(MsgPack mp, string name)
{
MsgPack t;
if ((t = mp[name, true]).IsNull) return null;
PV.Difficulty[] arr = new PV.Difficulty[t.Array.Length];
for (int i = 0; i < arr.Length; i++)
{
MsgPack pvMP = t[i];
ref PV.Difficulty diff = ref arr[i];
diff.End .SV(pvMP.RnI32("End" ), true);
diff.Start.SV(pvMP.RnI32("Start"), false);
pvMP.R("Edition", out diff.Edition);
pvMP.R("Version", out diff.Version);
}
return arr;
}
}
else if ((temp = msgPack["SlideSETable", true]).NotNull)
{
SlideSETable = new SlideSE[temp.Array.Length];
for (i0 = 0; i0 < SlideSETable.Length; i0++)
{
MsgPack sldMP = temp[i0];
ref SlideSE sld = ref SlideSETable[i0];
sld.End .SV(sldMP.RnI32("End" ), true);
sld.Start.SV(sldMP.RnI32("Start"), false);
sldMP.R( "ID" , out sld. ID );
sldMP.R( "Name" , out sld. Name );
sldMP.R( "SEName" , out sld. SEName );
sldMP.R("SortIndex", out sld.SortIndex);
}
}
else if ((temp = msgPack["SliderTouchSETable", true]).NotNull)
{
SliderTouchSETable = new SliderTouchSE[temp.Array.Length];
for (i0 = 0; i0 < SliderTouchSETable.Length; i0++)
{
MsgPack TEMP = temp[i0];
ref SliderTouchSE sldt = ref SliderTouchSETable[i0];
sldt.End .SV(TEMP.RnI32("End" ), true);
sldt.Start.SV(TEMP.RnI32("Start"), false);
TEMP.R( "ID" , out sldt. ID );
TEMP.R( "Name" , out sldt. Name );
TEMP.R( "SEName" , out sldt. SEName );
TEMP.R("SortIndex", out sldt.SortIndex);
}
}
temp.Dispose();
msgPack.Dispose();
}
public void MsgPackWriter(string file, bool json)
{
MsgPack msgPack = MsgPack.New;
if (ButtonSETable != null)
{
MsgPack buttonSETable = new MsgPack(ButtonSETable.Length, "ButtonSETable");
for (i0 = 0; i0 < ButtonSETable.Length; i0++)
{
ref ButtonSE btn = ref ButtonSETable[i0];
buttonSETable[i0] = MsgPack.New.Add( "End" , btn.End.Int )
.Add( "ID" , btn. ID )
.Add( "Name" , btn. Name )
.Add( "SEName" , btn. SEName )
.Add("SortIndex", btn.SortIndex)
.Add( "Start", btn.Start.Int);
}
msgPack.Add(buttonSETable);
}
else if (ChainSlideSETable != null)
{
MsgPack chainSlideSETable = new MsgPack(ChainSlideSETable.Length, "ChainSlideSETable");
for (i0 = 0; i0 < ChainSlideSETable.Length; i0++)
{
ref ChainSlideSE csld = ref ChainSlideSETable[i0];
chainSlideSETable[i0] = MsgPack.New.Add( "End" , csld. End.Int )
.Add("FailureSEName" , csld.FailureSEName )
.Add( "FirstSEName" , csld. FirstSEName )
.Add( "ID" , csld. ID )
.Add( "Name" , csld. Name )
.Add( "SubSEName" , csld. SubSEName )
.Add("SuccessSEName" , csld.SuccessSEName )
.Add( "SortIndex", csld. SortIndex)
.Add( "Start", csld. Start.Int);
}
msgPack.Add(chainSlideSETable);
}
else if (CollectionCardTable != null)
{
MsgPack collectionCardTable = new MsgPack(CollectionCardTable.Length, "CollectionCardTable");
for (i0 = 0; i0 < CollectionCardTable.Length; i0++)
{
ref CollectionCard clcrd = ref CollectionCardTable[i0];
collectionCardTable[i0] = MsgPack.New.Add("Chara" , clcrd.Chara )
.Add("DispNum" , clcrd.DispNum )
.Add("DivaProParam", clcrd.DivaProParam)
.Add("End" , clcrd.End.Int )
.Add("ID" , clcrd.ID )
.Add("ModuleAuthor", clcrd.ModuleAuthor)
.Add("Name" , clcrd.Name )
.Add("NameReading" , clcrd.NameReading )
.Add("NG" , clcrd.NG )
.Add("SortIndex" , clcrd.SortIndex )
.Add("Start" , clcrd.Start.Int )
.Add("Type" , clcrd.Type )
.Add("TypeParam" , clcrd.TypeParam )
.Add("WallParam" , clcrd.WallParam );
}
msgPack.Add(collectionCardTable);
}
else if (CustomizeItemTable != null)
{
MsgPack customizeItemTable = new MsgPack(CustomizeItemTable.Length, "CustomizeItemTable");
for (i0 = 0; i0 < CustomizeItemTable.Length; i0++)
{
ref CustomizeItem czitm = ref CustomizeItemTable[i0];
customizeItemTable[i0] = MsgPack.New.Add("Chara" , czitm.Chara )
.Add("ID" , czitm.ID )
.Add("Name" , czitm.Name )
.Add("NG" , czitm.NG )
.Add("ObjID" , czitm.ObjID )
.Add("Parts" , czitm.Parts )
.Add("SellType" , czitm.SellType )
.Add("ShopEnd" , czitm.ShopEnd .Int)
.Add("ShopPrice", czitm.ShopPrice )
.Add("ShopStart", czitm.ShopStart.Int)
.Add("SortIndex", czitm.SortIndex );
}
msgPack.Add(customizeItemTable);
}
else if (ModuleTable != null)
{
MsgPack moduleTable = new MsgPack(ModuleTable.Length, "ModuleTable");
for (i0 = 0; i0 < ModuleTable.Length; i0++)
{
ref Module mdl = ref ModuleTable[i0];
moduleTable[i0] = MsgPack.New.Add("Attribute", mdl.Attribute )
.Add("Chara" , mdl.Chara )
.Add("Costume" , mdl.Costume )
.Add("ID" , mdl.ID )
.Add("Name" , mdl.Name )
.Add("NG" , mdl.NG )
.Add("ShopEnd" , mdl.ShopEnd .Int)
.Add("ShopPrice", mdl.ShopPrice )
.Add("ShopStart", mdl.ShopStart.Int)
.Add("SortIndex", mdl.SortIndex );
}
msgPack.Add(moduleTable);
}
else if (PlateTable != null)
{
MsgPack plateTable = new MsgPack(PlateTable.Length, "PlateTable");
for (i0 = 0; i0 < PlateTable.Length; i0++)
{
ref Plate plt = ref PlateTable[i0];
plateTable[i0] = MsgPack.New.Add("Alpha" , plt.Alpha )
.Add("BaseID" , plt.BaseID )
.Add("Border" , plt.Border )
.Add("ColorB" , plt.ColorB )
.Add("ColorG" , plt.ColorG )
.Add("ColorR" , plt.ColorR )
.Add("Font" , plt.Font )
.Add("ID" , plt.ID )
.Add("Shadow" , plt.Shadow )
.Add("ShadowAlpha" , plt.ShadowAlpha )
.Add("ShadowColorB", plt.ShadowColorB)
.Add("ShadowColorG", plt.ShadowColorG)
.Add("ShadowColorR", plt.ShadowColorR);
}
msgPack.Add(plateTable);
}
else if (PVList != null)
{
MsgPack pvList = new MsgPack(PVList.Length, "PVList");
for (i0 = 0; i0 < PVList.Length; i0++)
{
ref PV pv = ref PVList[i0];
MsgPack mp = MsgPack.New.Add("AdvEnd" , pv.AdvEnd .Int)
.Add("AdvStart", pv.AdvStart.Int);
mp = mp.Add("ID" , pv.ID )
.Add("Name" , pv.Name )
.Add("Ignore", pv.Ignore);
mp.Add(WriteDifficulty("Easy" , pv.Easy ));
mp.Add(WriteDifficulty("Normal" , pv.Normal ));
mp.Add(WriteDifficulty("Hard" , pv.Hard ));
mp.Add(WriteDifficulty("Extreme", pv.Extreme));
mp.Add(WriteDifficulty("Encore" , pv.Encore ));
pvList[i0] = mp;
}
msgPack.Add(pvList);
static MsgPack WriteDifficulty(string name, PV.Difficulty[] arr)
{
if (arr == null) return default;
MsgPack mp = new MsgPack(arr.Length, name);
for (int i = 0; i < arr.Length; i++)
{
ref PV.Difficulty diff = ref arr[i];
mp[i] = MsgPack.New.Add("Edition", diff.Edition )
.Add("End" , diff.End.Int )
.Add("Start" , diff.Start.Int)
.Add("Version", diff.Version );
}
return mp;
}
}
else if (SlideSETable != null)
{
MsgPack slideSETable = new MsgPack(SlideSETable.Length, "SlideSETable");
for (i0 = 0; i0 < SlideSETable.Length; i0++)
{
ref SlideSE sld = ref SlideSETable[i0];
slideSETable[i0] = MsgPack.New.Add( "End" , sld.End.Int )
.Add( "ID" , sld. ID )
.Add( "Name" , sld. Name )
.Add( "SEName" , sld. SEName )
.Add("SortIndex", sld.SortIndex)
.Add( "Start", sld.Start.Int);
}
msgPack.Add(slideSETable);
}
else if (SliderTouchSETable != null)
{
MsgPack sliderTouchSETable = new MsgPack(SliderTouchSETable.Length, "SliderTouchSETable");
for (i0 = 0; i0 < SliderTouchSETable.Length; i0++)
{
ref SliderTouchSE sldt = ref SliderTouchSETable[i0];
sliderTouchSETable[i0] = MsgPack.New.Add( "End" , sldt.End.Int )
.Add( "ID" , sldt. ID )
.Add( "Name" , sldt. Name )
.Add( "SEName" , sldt. SEName )
.Add("SortIndex", sldt.SortIndex)
.Add( "Start", sldt.Start.Int);
}
msgPack.Add(sliderTouchSETable);
}
if (msgPack.List.Count == 1) msgPack.Write(file, json);
}
private bool disposed;
public void Dispose()
{
if (disposed) return;
if (_IO != null) { _IO.D(); _IO = null; }
if (dict != null) { dict.Clear(); dict = null; }
ButtonSETable = null; ChainSlideSETable = null; SlideSETable = null; SliderTouchSETable = null;
CollectionCardTable = null; CustomizeItemTable = null;
ModuleTable = null; PlateTable = null; PVList = null;
}
}
}
-84
View File
@@ -1,84 +0,0 @@
using System;
namespace KKdMainLib.Types
{
public struct Half : IFormattable
{
private ushort _value;
public static explicit operator Half(ushort bits) => new Half() { _value = bits };
public static explicit operator ushort(Half bits) => bits._value;
public static explicit operator double(Half h)
{
if (h._value == 0x0000) return +0;
else if (h._value == 0x8000) return -0;
else if (h._value == 0x7C00) return double.PositiveInfinity;
else if (h._value == 0xFC00) return double.NegativeInfinity;
else if (h._value >> 10 == 0x001F) return double.NaN;
else if (h._value >> 10 == 0x003F) return -double.NaN;
long exponent = ((h._value >> 10) & 0x1F);
long mantissa = (h._value & 0x3FF);
sbyte n = (sbyte)(((h._value >> 15 & 0x01) == 0) ? 1 : -1);
double m = (((long)1 << 10) | mantissa) / Math.Pow(2, 10);
double x = Math.Pow(2, exponent - (0x1F >> 1));
double d = n * m * x;
return d;
}
public static explicit operator Half(double val)
{
Half h = new Half();
if (val == +0 ) h._value = 0x0000;
else if (val == -0 ) h._value = 0x8000;
else if (val == double.NaN ) h._value = 0x7FFF;
else if (val == -double.NaN ) h._value = 0xFFFF;
else if (val == double.PositiveInfinity) h._value = 0x7C00;
else if (val == double.NegativeInfinity) h._value = 0xFC00;
else h._value = ToDouble(val);
return h;
}
public static ushort ToDouble(double val)
{
ushort Sign = 0;
if (val < 0)
Sign = 0x8000;
val = Math.Abs(val);
double Pow1 = 1;
double Pow2 = 1 << 10;
double x = 0;
int MaxPow = (1 << 4);
int i = 0;
while (i < MaxPow && i > -MaxPow + 1)
{
Pow1 = Math.Pow(2, i);
x = val / Pow1;
if (x >= 1 && x < 2)
{
ushort exponent_max = (ushort)Math.Ceiling(x * Pow2);
ushort exponent_min = (ushort)Math.Floor (x * Pow2);
ushort exponent = Math.Abs(x - exponent_max / Pow2) >
Math.Abs(x - exponent_min / Pow2) ? exponent_max : exponent_min;
ushort mantissa = (ushort)(i + MaxPow - 1);
ushort d = (ushort)(Sign | ((mantissa & 0x001F) << 10) | (exponent & 0x03FF));
return d;
}
else if (val < 1) i--;
else i++;
}
return i >= +0 ? (ushort)0x7C00 : (ushort)0xFC00;
}
public override string ToString() => ((double)this).ToString();
public string ToString(string format, IFormatProvider formatProvider) =>
((double)this).ToString(format, formatProvider);
public override int GetHashCode() => base.GetHashCode();
}
}
-141
View File
@@ -1,141 +0,0 @@
namespace KKdMainLib.Types
{
public interface IKeyFrame<TKey, TVal>
{
IKeyFrame<TKey, TVal> Check();
IKeyFrame<TKey, TVal> ToKeyFrameT0();
IKeyFrame<TKey, TVal> ToKeyFrameT1();
IKeyFrame<TKey, TVal> ToKeyFrameT2();
IKeyFrame<TKey, TVal> ToKeyFrameT3();
string ToString();
string ToString(bool Brackets);
}
public struct KeyFrameT0<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
new KeyFrameT0<TKey, TVal> { Frame = Frame };
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
new KeyFrameT1<TKey, TVal> { Frame = Frame };
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
new KeyFrameT2<TKey, TVal> { Frame = Frame };
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
new KeyFrameT3<TKey, TVal> { Frame = Frame };
public IKeyFrame<TKey, TVal> Check() => this;
public override string ToString() =>
Main.ToString(Frame);
public string ToString(bool Brackets) =>
Main.ToString(Frame);
}
public struct KeyFrameT1<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public TVal Value;
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
new KeyFrameT0<TKey, TVal> { Frame = Frame };
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
new KeyFrameT1<TKey, TVal> { Frame = Frame, Value = Value };
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
new KeyFrameT2<TKey, TVal> { Frame = Frame, Value = Value };
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value };
public IKeyFrame<TKey, TVal> Check() =>
Value.Equals(default(TVal)) ? ToKeyFrameT0() : (this);
public override string ToString() => ToString(true);
public string ToString(bool Brackets) =>
(Brackets ? "(" : "") + Main.ToString(Frame) + "," +
Main.ToString(Value) + (Brackets ? ")" : "");
}
public struct KeyFrameT2<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public TVal Value;
public TVal Interpolation;
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
new KeyFrameT0<TKey, TVal> { Frame = Frame };
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
new KeyFrameT1<TKey, TVal> { Frame = Frame, Value = Value };
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
new KeyFrameT2<TKey, TVal> { Frame = Frame, Value = Value,
Interpolation = Interpolation};
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
Interpolation1 = Interpolation, Interpolation2 = Interpolation };
public IKeyFrame<TKey, TVal> ToKeyFrameT3(IKeyFrame<TKey, TVal> Previous) =>
Previous is KeyFrameT2<TKey, TVal> PreviousT2 ?
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
Interpolation1 = PreviousT2.Interpolation, Interpolation2 = Interpolation } :
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
Interpolation1 = Interpolation, Interpolation2 = Interpolation };
public IKeyFrame<TKey, TVal> Check()
{
if (Value.Equals(default(TVal)) && Interpolation.Equals(default(TVal)))
return ToKeyFrameT0();
else if (Value.Equals(default(TVal))) return ToKeyFrameT1();
return this;
}
public override string ToString() => ToString(true);
public string ToString(bool Brackets) =>
(Brackets ? "(" : "") + Main.ToString(Frame) + "," + Main.
ToString(Value) + "," + Main.ToString(Interpolation) + (Brackets ? ")" : "");
}
public struct KeyFrameT3<TKey, TVal> : IKeyFrame<TKey, TVal>
{
public TKey Frame;
public TVal Value;
public TVal Interpolation1;
public TVal Interpolation2;
public IKeyFrame<TKey, TVal> ToKeyFrameT0() =>
new KeyFrameT0<TKey, TVal> { Frame = Frame };
public IKeyFrame<TKey, TVal> ToKeyFrameT1() =>
new KeyFrameT1<TKey, TVal> { Frame = Frame, Value = Value };
public IKeyFrame<TKey, TVal> ToKeyFrameT2() =>
new KeyFrameT2<TKey, TVal> { Frame = Frame, Value = Value, Interpolation = Interpolation1 };
public IKeyFrame<TKey, TVal> ToKeyFrameT3() =>
new KeyFrameT3<TKey, TVal> { Frame = Frame, Value = Value,
Interpolation1 = Interpolation1, Interpolation2 = Interpolation2 };
public IKeyFrame<TKey, TVal> Check()
{
if (Value.Equals(default(TVal)) && Interpolation1.Equals(default(TVal)) &&
Interpolation2.Equals(default(TVal))) return ToKeyFrameT0();
else if (Interpolation1.Equals(default(TVal)) &&
Interpolation2.Equals(default(TVal))) return ToKeyFrameT1();
else if (Interpolation1.Equals(Interpolation2))
return ToKeyFrameT2();
return this;
}
public override string ToString() => ToString(true);
public string ToString(bool Brackets) =>
(Brackets ? "(" : "") + Main.ToString(Frame) + "," + Main.ToString(Value) + "," +
Main.ToString(Interpolation1) + "," + Main.ToString(Interpolation2) + (Brackets ? ")" : "");
public IKeyFrame<TKey, TVal> ToKeyFrameT2(IKeyFrame<TKey, TVal>
Previous, out IKeyFrame<TKey, TVal> Current)
{
Current = Previous is KeyFrameT2<TKey, TVal> PreviousT2
? new KeyFrameT2<TKey, TVal> { Frame = PreviousT2.Frame,
Value = PreviousT2.Value, Interpolation = Interpolation1 }
: new KeyFrameT2<TKey, TVal> { Frame = Frame,
Value = Value, Interpolation = Interpolation1 };
return new KeyFrameT2<TKey, TVal> { Frame = Frame,
Value = Value, Interpolation = Interpolation2 };
}
}
}
-102
View File
@@ -1,102 +0,0 @@
using System.Collections;
namespace KKdMainLib.Types
{
public struct KKdList<T> : IEnumerator, IEnumerable
{
public static KKdList<T> Null => new KKdList<T>();
public static KKdList<T> New => new KKdList<T>() { Capacity = 0 };
public static KKdList<T> NewReserve(int Capacity) => new KKdList<T>() { Capacity = Capacity };
private int index;
private T[] array;
public int Count { get; private set; }
public bool IsNull => array == null;
public bool NotNull => array != null;
public int Capacity { get => array != null ? array.Length : -1;
set
{
if (array != null) System.Array.Resize(ref array, value);
else array = new T[value];
}
}
public KKdList(T[] Array)
{
index = 0;
Count = Array.Length;
array = Array;
}
public T Current => index < Count ? array[index] : default;
object IEnumerator.Current => Current;
public T this[int index]
{ get => array != null ? array[index] : default;
set { if (array != null) array[index] = value; } }
public bool MoveNext()
{ if (index == (Count - 1)) { index = 0; return false; }
else { index++ ; return true; } }
public IEnumerator GetEnumerator() => this;
public void Dispose() { array = null; Count = 0; index = 0; }
public void Reset() => index = 0;
public void Add(T item)
{
if (IsNull) return;
Count++;
if (array.Length < Count)
System.Array.Resize(ref array, Count);
array[Count - 1] = item;
}
public void RemoveAt(int index)
{
if (IsNull) return;
for (int i = index; i < Count; i++)
array[i] = array[i + 1];
}
public void RemoveRange(int IndexStart, int IndexEnd)
{
if (IndexEnd - IndexStart < 1) return;
if (IsNull) return;
for (int i = IndexStart; i < Count; i++)
array[i] = array[i + IndexEnd - IndexStart];
}
public T[] ToArray() => array;
public bool Contains(T val)
{
if (IsNull) return false;
for (int i = 0; i < Count; i++)
if (array[i] == null && val == null) return true;
else if ( val == null) continue;
else if (array[i] .Equals(val) ) return true;
return false;
}
public int IndexOf(T val)
{
if (IsNull) return -1;
for (int i = 0; i < Count; i++)
if (array[i] == null && val == null) return i;
else if ( val == null) continue;
else if (array[i] .Equals(val) ) return i;
return -1;
}
}
}
-43
View File
@@ -1,43 +0,0 @@
using KKdMainLib.IO;
namespace KKdMainLib.Types
{
public struct Pointer<T>
{
public int Offset;
public T Value;
public override string ToString() => Main.ToString(Value);
}
public struct CountPointer<T>
{
public int Count { get => Entries != null ? Entries.Length : 0;
set => Entries = new T[value]; }
public int Offset;
public T[] Entries;
public T this[int index]
{ get => Count > 0 ? Entries[index] : default;
set { if (Count > 0) Entries[index] = value; } }
public override string ToString() => Count < 1 ? "No Entries" :
Count == 1 ? Entries[0].ToString() : "Count: " + Count;
}
public static class PointerExt
{
public static Pointer<T> ReadPointer<T>(this Stream IO) =>
new Pointer<T> { Offset = IO.ReadInt32() };
public static Pointer<string> ReadPointerString(this Stream IO)
{
Pointer<string> val = IO.ReadPointer<string>();
val.Value = IO.ReadStringAtOffset(val.Offset); return val;
}
public static CountPointer<T> ReadCountPointer<T>(this Stream IO) =>
new CountPointer<T> { Count = IO.ReadInt32(), Offset = IO.ReadInt32() };
}
}
-44
View File
@@ -1,44 +0,0 @@
namespace KKdMainLib.Types
{
public struct Vector2<T>
{
public T X;
public T Y;
public Vector2(T X, T Y)
{ this.X = X; this.Y = Y; }
public bool NotNull => X != null && Y != null;
public override string ToString() => "X: " + X + "; Y: " + Y;
}
public struct Vector3<T>
{
public T X;
public T Y;
public T Z;
public Vector3(T X, T Y, T Z)
{ this.X = X; this.Y = Y; this.Z = Z; }
public bool NotNull => X != null && Y != null && Z != null;
public override string ToString() => "X: " + X + "; Y: " + Y + "; Z: " + Z;
}
public struct Vector4<T>
{
public T X;
public T Y;
public T Z;
public T W;
public Vector4(T X, T Y, T Z, T W)
{ this.X = X; this.Y = Y; this.Z = Z; this.W = W; }
public bool NotNull => X != null && Y != null && Z != null && W != null;
public override string ToString() => "X: " + X + "; Y: " + Y + "; Z: " + Z + "; W: " + W;
}
}
Binary file not shown.
+76 -68
View File
@@ -1,4 +1,4 @@
using KKdMainLib;
using KKdBaseLib;
using KKdMainLib.IO;
namespace KKdSoundLib
@@ -17,47 +17,52 @@ namespace KKdSoundLib
Data = new DIVAFile();
Stream reader = File.OpenReader(file + ".diva");
if (reader.ReadString(0x04) != "DIVA") { reader.Close(); return; }
if (reader.RS(0x04) != "DIVA") { reader.C(); return; }
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);
Stream writer = File.OpenWriter();
if (!ToArray) writer = File.OpenWriter(file + ".wav", true);
writer.LongPosition = 0x2C;
reader.RI32();
Data.Size = reader.RI32();
Data.SampleRate = reader.RI32();
Data.SamplesCount = reader.RI32();
reader.RI64();
Data.Channels = reader.RU16();
reader.RU16();
Data.Name = reader.RS(0x20);
byte value = 0;
byte[] data = new byte[Data.SamplesCount * Data.Channels * 4];
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();
fixed (int* currentPtr = current)
fixed (int* currentclampPtr = currentclamp)
fixed (sbyte* stepindexPtr = stepindex)
fixed (byte* ptr = data)
{
float* dataPtr = (float*)ptr;
for (i = 0; i < Data.SamplesCount; i++)
for (c = 0; c < Data.Channels; c++, dataPtr++)
{
value = reader.RHB();
IMADecoder(value, ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
*dataPtr = (float)(currentPtr[c] / 32768.0);
}
}
reader.CR();
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();
if (ToArray) Data.Data = data;
else
{
Stream writer = File.OpenWriter(file + ".wav", true);
WAV.Header Header = new WAV.Header { Bytes = 4, Channels = Data.Channels, Format = 3,
SampleRate = Data.SampleRate, Size = Data.SamplesCount * Data.Channels * 4 };
writer.W(Header, 0);
writer.W(data);
writer.C();
}
reader.Close();
reader.C();
}
public void DIVAWriter(string file)
@@ -68,12 +73,14 @@ namespace KKdSoundLib
Data = new DIVAFile();
WAV.Header Header = reader.ReadWAVHeader();
if (!Header.IsSupported) { reader.Close(); return; }
if (!Header.IsSupported) { reader.C(); return; }
Stream writer = File.OpenWriter(file + ".diva", true);
Data.Channels = Header.Channels;
Data.SampleRate = Header.SampleRate;
writer.LongPosition = 0x40;
Data.SamplesCount = Header.Size / Header.Channels / Header.Bytes;
writer.PI64 = 0x40;
writer.LI64 = 0x40 + (Data.SamplesCount * Data.Channels).A(2, 2);
byte value = 0;
int[] sample = new int[Data.Channels];
@@ -81,33 +88,34 @@ namespace KKdSoundLib
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;
fixed (int* samplePtr = sample)
fixed (int* currentPtr = current)
fixed (int* currentclampPtr = currentclamp)
fixed (sbyte* stepindexPtr = stepindex)
{
for (i = 0; i < Data.SamplesCount; i++)
for (c = 0; c < Header.Channels; c++)
{
samplePtr[c] = (reader.RS(Header.Bytes, Header.Format) * 0x8000).CFTI();
value = IMAEncoder(samplePtr[c], ref currentPtr[c],
ref currentclampPtr[c], ref stepindexPtr[c]);
writer.W(value, 4);
}
}
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.CW();
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();
writer.PI64 = 0x00;
writer.W("DIVA");
writer.W(0x00);
writer.W((Data.SamplesCount * Data.Channels).A(2, 2));
writer.W(Data.SampleRate);
writer.W(Data.SamplesCount);
writer.W(0x00);
writer.W(0x00);
writer.W(Data.Channels);
writer.C();
reader.C();
}
private void IMADecoder(byte value, ref int current, ref int currentclamp, ref sbyte stepindex)
@@ -118,14 +126,14 @@ namespace KKdSoundLib
if ((value & 1) == 1) diff += step >> 2;
if ((value & 2) == 2) diff += step >> 1;
if ((value & 4) == 4) diff += step;
if ((value & 8) == 8)
{ currentclamp -= diff; current = currentclamp;
if (currentclamp < -0x8000) currentclamp = -0x8000; }
else
{ currentclamp += diff; current = currentclamp;
if (currentclamp > 0x7FFF) currentclamp = 0x7FFF; }
stepindex += ima_index_table[value & 7];
if (stepindex < 0) stepindex = 0;
if (stepindex > 88) stepindex = 88;
@@ -139,9 +147,9 @@ namespace KKdSoundLib
{
value = 0;
step = ima_step_table[stepindex];
delta = sample - current;
if (delta < 0)
{ value |= 8; delta = -delta; }
diff = step >> 3;
@@ -153,14 +161,14 @@ namespace KKdSoundLib
step >>= 1;
if (delta > step)
{ value |= 1; diff += step; }
if ((value & 8) == 8)
{ currentclamp -= diff; current = currentclamp;
if (currentclamp < -0x8000) currentclamp = -0x8000; }
else
{ currentclamp += diff; current = currentclamp;
if (currentclamp > 0x7FFF) currentclamp = 0x7FFF; }
stepindex += ima_index_table[value & 0x07];
if (stepindex < 0) stepindex = 0;
if (stepindex > 88) stepindex = 88;
@@ -187,9 +195,9 @@ namespace KKdSoundLib
public struct DIVAFile
{
public uint Size;
public uint SampleRate;
public uint SamplesCount;
public int Size;
public int SampleRate;
public int SamplesCount;
public string Name;
public ushort Channels;
public byte[] Data;
+56 -56
View File
@@ -1,97 +1,97 @@
using KKdMainLib;
using KKdBaseLib;
using KKdMainLib.IO;
namespace KKdSoundLib
{
public static class Extensions
{
public static double ReadWAVSample(this Stream IO, ushort Bytes, ushort Format)
public static double RS(this Stream _IO, ushort Bytes, ushort Format)
{
if (Bytes == 2) return IO. ReadInt16() / (double)0x00008000;
else if (Bytes == 4 && Format == 0x01) return IO. ReadInt32() / (double)0x80000000;
else if (Bytes == 4 && Format == 0x03) return IO.ReadSingle();
else if (Bytes == 8 && Format == 0x03) return IO.ReadDouble();
if (Bytes == 2) return _IO. RI16() / (double)0x00008000;
else if (Bytes == 4 && Format == 0x01) return _IO. RI32() / (double)0x80000000;
else if (Bytes == 4 && Format == 0x03) return _IO.RF32();
else if (Bytes == 8 && Format == 0x03) return _IO.RF64();
else return 0;
}
public static void Write(this Stream IO, double Sample, ushort Bytes, ushort Format)
public static void W(this Stream _IO, double Sample, ushort Bytes, ushort Format)
{
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);
if (Bytes == 2) _IO.W((Sample * 0x00008000).CFTS());
else if (Bytes == 4 && Format == 0x01) _IO.W((Sample * 0x80000000).CFTI());
else if (Bytes == 4 && Format == 0x03) _IO.W((float)Sample);
else if (Bytes == 8 && Format == 0x03) _IO.W( Sample);
}
public static WAV.Header ReadWAVHeader(this Stream IO)
public static WAV.Header ReadWAVHeader(this Stream _IO)
{
WAV.Header Header = new WAV.Header();
if (IO.ReadString(4) != "RIFF") return Header;
IO.ReadUInt32();
if (IO.ReadString(4) != "WAVE") return Header;
if (IO.ReadString(4) != "fmt ") return Header;
int Offset = IO.ReadInt32();
Header.Format = IO.ReadUInt16();
if (_IO.RS(4) != "RIFF") return Header;
_IO.RU32();
if (_IO.RS(4) != "WAVE") return Header;
if (_IO.RS(4) != "fmt ") return Header;
int Offset = _IO.RI32();
Header.Format = _IO.RU16();
if (Header.Format == 0x01 || Header.Format == 0x03 || Header.Format == 0xFFFE)
{
Header.Channels = IO.ReadUInt16();
Header.SampleRate = IO.ReadUInt32();
IO.ReadInt32(); IO.ReadInt16();
Header.Bytes = IO.ReadUInt16();
Header.Channels = _IO.RU16();
Header.SampleRate = _IO.RI32();
_IO.RI32(); _IO.RI16();
Header.Bytes = _IO.RU16();
if (Header.Bytes % 8 != 0) return Header;
Header.Bytes >>= 3;
if (Header.Bytes == 0) return Header;
if (Header.Format == 0xFFFE)
{
IO.ReadInt32();
Header.ChannelMask = IO.ReadUInt32();
Header.Format = IO.ReadUInt16();
_IO.RI32();
Header.ChannelMask = _IO.RU32();
Header.Format = _IO.RU16();
}
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 == 8 && Header.Format == 1) return Header;
IO.Seek(Offset + 0x14, 0);
if (IO.ReadString(4) != "data") return Header;
Header.Size = IO.ReadUInt32();
Header.HeaderSize = IO.UIntPosition;
_IO.S(Offset + 0x14, 0);
if (_IO.RS(4) != "data") return Header;
Header.Size = _IO.RI32();
Header.HeaderSize = _IO.P;
Header.IsSupported = true;
return Header;
}
return Header;
}
public static void Write(this Stream IO, WAV.Header Header, long Seek) => IO.Write(Header, Seek, 0);
public static void W(this Stream _IO, WAV.Header Header, long Seek) => _IO.W(Header, Seek, 0);
public static void Write(this Stream IO, WAV.Header Header, long Seek, SeekOrigin Origin)
{ IO.Seek(Seek, Origin); IO.Write(Header); }
public static void W(this Stream _IO, WAV.Header Header, long Seek, SeekOrigin Origin)
{ _IO.S(Seek, Origin); _IO.W(Header); }
public static void Write(this Stream IO, WAV.Header Header)
public static void W(this Stream _IO, WAV.Header Header)
{
IO.Write("RIFF");
if (Header.Format != 0xFFFE) IO.Write(Header.Size + 0x24);
else IO.Write(Header.Size + 0x3C);
IO.Write("WAVE");
IO.Write("fmt ");
if (Header.Format != 0xFFFE) IO.Write(0x10);
else IO.Write(0x28);
IO.Write(Header.Format);
IO.Write((short)Header.Channels);
IO.Write(Header.SampleRate);
IO.Write(Header.SampleRate * Header.Channels * Header.Bytes);
IO.Write((short)(Header.Channels * Header.Bytes));
IO.Write((short)(Header.Bytes << 3));
_IO.W("RIFF");
if (Header.Format != 0xFFFE) _IO.W(Header.Size + 0x24);
else _IO.W(Header.Size + 0x3C);
_IO.W("WAVE");
_IO.W("fmt ");
if (Header.Format != 0xFFFE) _IO.W(0x10);
else _IO.W(0x28);
_IO.W(Header.Format);
_IO.W((short)Header.Channels);
_IO.W(Header.SampleRate);
_IO.W(Header.SampleRate * Header.Channels * Header.Bytes);
_IO.W((short)(Header.Channels * Header.Bytes));
_IO.W((short)(Header.Bytes << 3));
if (Header.Format == 0xFFFE)
{
IO.Write((short)0x16);
IO.Write((short)(Header.Bytes << 3));
IO.Write(Header.ChannelMask);
IO.Write(Header.Bytes == 2 ? 0x01 : 0x03);
IO.Write(0x00100000);
IO.Write(0xAA000080);
IO.Write(0x719B3800);
_IO.W((short)0x16);
_IO.W((short)(Header.Bytes << 3));
_IO.W(Header.ChannelMask);
_IO.W(Header.Bytes == 2 ? 0x01 : 0x03);
_IO.W(0x00100000);
_IO.W(0xAA000080);
_IO.W(0x719B3800);
}
IO.Write("data");
IO.Write(Header.Size);
_IO.W("data");
_IO.W(Header.Size);
}
}
}
+19 -34
View File
@@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>KKdSoundLib</RootNamespace>
<AssemblyName>KKdSoundLib</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Authors>korenkonder</Authors>
<Company></Company>
<Configuration></Configuration>
<Copyright>korenkonder © 2019-2020</Copyright>
<Description>A simple library for working with Project Diva F/AFT/F2/X/FT audio files</Description>
<FileVersion>0.1.2.0</FileVersion>
<PackageId>KKdSoundLib</PackageId>
<Product>KKdSoundLib</Product>
<TargetFramework>netstandard2.0</TargetFramework>
<Title>KKdSoundLib</Title>
<Version>0.1.2.0</Version>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -22,8 +23,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -35,27 +36,11 @@
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="Extensions.cs" />
<Compile Include="DIVA.cs" />
<Compile Include="VAG.cs" />
<Compile Include="WAV.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<ProjectReference Include="..\KKdBaseLib\KKdBaseLib.csproj" />
<ProjectReference Include="..\KKdMainLib\KKdMainLib.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KKdMainLib\KKdMainLib.csproj">
<Project>{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}</Project>
<Name>KKdMainLib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
-8
View File
@@ -1,15 +1,7 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("KKdSoundLib")]
[assembly: AssemblyDescription("A simple library for working with Project Diva F/AFT/F2/X/FT audio files")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KKdSoundLib")]
[assembly: AssemblyCopyright("korenkonder © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA")]
[assembly: AssemblyVersion("0.0.2.3")]
[assembly: AssemblyFileVersion("0.0.2.3")]
+576 -567
View File
File diff suppressed because it is too large Load Diff
+3 -3
View File
@@ -4,9 +4,9 @@
{
public struct Header
{
public uint Size;
public uint SampleRate;
public uint HeaderSize;
public int Size;
public int SampleRate;
public int HeaderSize;
public uint ChannelMask;
public bool IsSupported;
public ushort Bytes;
+11 -5
View File
@@ -3,22 +3,24 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29025.244
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PD_Tool", "PD_Tool\PD_Tool.csproj", "{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KKdBaseLib", "KKdBaseLib\KKdBaseLib.csproj", "{437F63F1-8C23-429E-AB14-38B85C9EDB16}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KKdMainLib", "KKdMainLib\KKdMainLib.csproj", "{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KKdSoundLib", "KKdSoundLib\KKdSoundLib.csproj", "{D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PD_Tool", "PD_Tool\PD_Tool.csproj", "{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Release|Any CPU.Build.0 = Release|Any CPU
{437F63F1-8C23-429E-AB14-38B85C9EDB16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{437F63F1-8C23-429E-AB14-38B85C9EDB16}.Debug|Any CPU.Build.0 = Debug|Any CPU
{437F63F1-8C23-429E-AB14-38B85C9EDB16}.Release|Any CPU.ActiveCfg = Release|Any CPU
{437F63F1-8C23-429E-AB14-38B85C9EDB16}.Release|Any CPU.Build.0 = Release|Any CPU
{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -27,6 +29,10 @@ Global
{D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA}.Release|Any CPU.Build.0 = Release|Any CPU
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
+182 -72
View File
@@ -1,73 +1,183 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>PD_Tool</RootNamespace>
<AssemblyName>PD_Tool</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\build\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>embedded</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\build\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="classes\DataBase.cs" />
<Compile Include="classes\Tools\A3D.cs" />
<Compile Include="classes\Tools\AET.cs" />
<Compile Include="classes\Tools\DB.cs" />
<Compile Include="classes\Tools\DEX.cs" />
<Compile Include="classes\Tools\DIV.cs" />
<Compile Include="classes\Tools\STR.cs" />
<Compile Include="classes\Tools\VAG.cs" />
<Compile Include="classes\DIVAFILE.cs" />
<Compile Include="classes\FARC.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KKdMainLib\KKdMainLib.csproj">
<Project>{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}</Project>
<Name>KKdMainLib</Name>
<EmbedInteropTypes>False</EmbedInteropTypes>
</ProjectReference>
<ProjectReference Include="..\KKdSoundLib\KKdSoundLib.csproj">
<Project>{D8A3F2D7-10CC-5723-EC9A-45D3B9C2DF77}</Project>
<Name>KKdSoundLib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>PD_Tool</RootNamespace>
<AssemblyName>PD_Tool</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\build\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>embedded</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\build\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="classes\A3D.cs" />
<Compile Include="classes\AET.cs" />
<Compile Include="classes\BLT.cs" />
<Compile Include="classes\CCT.cs" />
<Compile Include="classes\DataBase.cs" />
<Compile Include="classes\DB.cs" />
<Compile Include="classes\DEX.cs" />
<Compile Include="classes\DFT.cs" />
<Compile Include="classes\DIV.cs" />
<Compile Include="classes\DIVAFILE.cs" />
<Compile Include="classes\FARC.cs" />
<Compile Include="classes\LIT.cs" />
<Compile Include="classes\MHD.cs" />
<Compile Include="classes\MOT.cs" />
<Compile Include="classes\STR.cs" />
<Compile Include="classes\TBL.cs" />
<Compile Include="classes\VAG.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KKdBaseLib\KKdBaseLib.csproj">
<Project>{437f63f1-8c23-429e-ab14-38b85c9edb16}</Project>
<Name>KKdBaseLib</Name>
</ProjectReference>
<ProjectReference Include="..\KKdMainLib\KKdMainLib.csproj">
<Project>{2ba7efc6-91d1-8bbc-c487-06c7f36cc789}</Project>
<Name>KKdMainLib</Name>
</ProjectReference>
<ProjectReference Include="..\KKdSoundLib\KKdSoundLib.csproj">
<Project>{d8a3f2d7-10cc-5723-ec9a-45d3b9c2df77}</Project>
<Name>KKdSoundLib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>del Microsoft.Win32.Primitives.dll
del netstandard.dll
del PD_Tool.exe.config
del System.AppContext.dll
del System.Collections.Concurrent.dll
del System.Collections.dll
del System.Collections.NonGeneric.dll
del System.Collections.Specialized.dll
del System.ComponentModel.dll
del System.ComponentModel.EventBasedAsync.dll
del System.ComponentModel.Primitives.dll
del System.ComponentModel.TypeConverter.dll
del System.Console.dll
del System.Data.Common.dll
del System.Diagnostics.Contracts.dll
del System.Diagnostics.Debug.dll
del System.Diagnostics.FileVersionInfo.dll
del System.Diagnostics.Process.dll
del System.Diagnostics.StackTrace.dll
del System.Diagnostics.TextWriterTraceListener.dll
del System.Diagnostics.Tools.dll
del System.Diagnostics.TraceSource.dll
del System.Diagnostics.Tracing.dll
del System.Drawing.Primitives.dll
del System.Dynamic.Runtime.dll
del System.Globalization.Calendars.dll
del System.Globalization.dll
del System.Globalization.Extensions.dll
del System.IO.Compression.dll
del System.IO.Compression.ZipFile.dll
del System.IO.dll
del System.IO.FileSystem.dll
del System.IO.FileSystem.DriveInfo.dll
del System.IO.FileSystem.Primitives.dll
del System.IO.FileSystem.Watcher.dll
del System.IO.IsolatedStorage.dll
del System.IO.MemoryMappedFiles.dll
del System.IO.Pipes.dll
del System.IO.UnmanagedMemoryStream.dll
del System.Linq.dll
del System.Linq.Expressions.dll
del System.Linq.Parallel.dll
del System.Linq.Queryable.dll
del System.Net.Http.dll
del System.Net.NameResolution.dll
del System.Net.NetworkInformation.dll
del System.Net.Ping.dll
del System.Net.Primitives.dll
del System.Net.Requests.dll
del System.Net.Security.dll
del System.Net.Sockets.dll
del System.Net.WebHeaderCollection.dll
del System.Net.WebSockets.Client.dll
del System.Net.WebSockets.dll
del System.ObjectModel.dll
del System.Reflection.dll
del System.Reflection.Extensions.dll
del System.Reflection.Primitives.dll
del System.Resources.Reader.dll
del System.Resources.ResourceManager.dll
del System.Resources.Writer.dll
del System.Runtime.CompilerServices.VisualC.dll
del System.Runtime.dll
del System.Runtime.Extensions.dll
del System.Runtime.Handles.dll
del System.Runtime.InteropServices.dll
del System.Runtime.InteropServices.RuntimeInformation.dll
del System.Runtime.Numerics.dll
del System.Runtime.Serialization.Formatters.dll
del System.Runtime.Serialization.Json.dll
del System.Runtime.Serialization.Primitives.dll
del System.Runtime.Serialization.Xml.dll
del System.Security.Claims.dll
del System.Security.Cryptography.Algorithms.dll
del System.Security.Cryptography.Csp.dll
del System.Security.Cryptography.Encoding.dll
del System.Security.Cryptography.Primitives.dll
del System.Security.Cryptography.X509Certificates.dll
del System.Security.Principal.dll
del System.Security.SecureString.dll
del System.Text.Encoding.dll
del System.Text.Encoding.Extensions.dll
del System.Text.RegularExpressions.dll
del System.Threading.dll
del System.Threading.Overlapped.dll
del System.Threading.Tasks.dll
del System.Threading.Tasks.Parallel.dll
del System.Threading.Thread.dll
del System.Threading.ThreadPool.dll
del System.Threading.Timer.dll
del System.ValueTuple.dll
del System.Xml.ReaderWriter.dll
del System.Xml.XDocument.dll
del System.Xml.XmlDocument.dll
del System.Xml.XmlSerializer.dll
del System.Xml.XPath.dll
del System.Xml.XPath.XDocument.dll</PostBuildEvent>
</PropertyGroup>
</Project>
+226 -70
View File
@@ -1,123 +1,279 @@
using System;
using System;
using System.Windows.Forms;
using KKdMainLib;
using KKdMainLib.IO;
using KKdMain = KKdMainLib.Main;
using KKdFARC = KKdMainLib.FARC;
namespace PD_Tool
{
public static class Program
{
[ThreadStatic] public static string function = "";
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
[ThreadStatic] public static string choose = "";
[STAThread]
public static void Main(string[] args)
{
SetProcessDPIAware();
Console.Title = "PD_Tool";
if (args.Length == 0)
{
GC.Collect();
while (function != "Q") MainMenu();
Exit();
}
if (args.Length == 0) { while (choose != "Q") MainMenu(); Exit(); }
long header;
Stream reader;
foreach (string arg in args)
{
if (Directory.Exists(arg)) new KKdFARC(arg, true).Pack();
else if (File.Exists(arg) && Path.GetExtension(arg) == ".farc") new KKdFARC(arg).UnPack(true);
GC.Collect();
if (Directory.Exists(arg)) using (KKdFARC FARC = new KKdFARC(arg, true)) FARC.Pack();
else if (File.Exists(arg) && Path.GetExtension(arg) == ".farc")
using (KKdFARC farc = new KKdFARC(arg)) farc.Unpack(true);
else if (File.Exists(arg))
{
reader = File.OpenReader(arg);
header = reader.ReadInt64();
reader.Close();
using (reader = File.OpenReader(arg))
header = reader.RI64();
if (header == 0x454C494641564944) KKdMainLib.DIVAFILE.Decrypt(arg);
}
}
Exit();
}
[ThreadStatic] private static bool JSON = true;
[ThreadStatic] private static bool json = true;
private static void MainMenu()
{
Console. InputEncoding = System.Text.Encoding.Unicode;
Console.OutputEncoding = System.Text.Encoding.Unicode;
Console.Title = "PD_Tool";
Console.Clear();
KKdMain.ConsoleDesign(true);
KKdMain.ConsoleDesign(" Choose action:");
KKdMain.ConsoleDesign(false);
KKdMain.ConsoleDesign("1. Extract FARC Archive");
KKdMain.ConsoleDesign("2. Create FARC Archive");
KKdMain.ConsoleDesign("3. Decrypt from DIVAFILE");
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);
ConsoleDesign(true);
ConsoleDesign(" Choose action:");
ConsoleDesign(false);
ConsoleDesign("1. Extract FARC Archive");
ConsoleDesign("2. Create FARC Archive");
ConsoleDesign("3. Decrypt from DIVAFILE");
ConsoleDesign("4. Encrypt to DIVAFILE");
ConsoleDesign("5. DB_Tools");
ConsoleDesign("6. AC/DT/F/AFT/FT Converting Tools");
ConsoleDesign("7. F/F2/FT Converting Tools");
ConsoleDesign("8. X/XHD Converting Tools");
ConsoleDesign(json ? "9. MsgPack to JSON" : "9. JSON to MsgPack");
ConsoleDesign(false);
ConsoleDesign(json ? "M. MessagePack" : "J. JSON");
ConsoleDesign("Q. Quit");
ConsoleDesign(false);
ConsoleDesign(true);
Console.WriteLine();
function = Console.ReadLine().ToUpper();
bool isNumber = int.TryParse(function, out int result);
choose = Console.ReadLine().ToUpper();
bool isNumber = int.TryParse(choose, out int result);
if (isNumber) Functions();
if (function == "M") JSON = false;
else if (function == "J") JSON = true ;
if (choose == "M") json = false;
else if (choose == "J") json = true ;
}
private static void Functions()
{
Console.Clear();
if (function == "1" || function == "2") FARC.Processor(function == "1");
else if (function == "3" || function == "4")
if (choose == "1" || choose == "2") FARC.Processor(choose == "1");
else if (choose == "3" || choose == "4")
{
KKdMain.Choose(1, "", out string[] FileNames);
Choose(1, "", out string[] FileNames);
foreach (string FileName in FileNames) DIVAFILE.Decrypt(FileName);
}
else if (function == "5") DataBase.Processor(JSON);
else if (function == "6")
else if (choose == "5") DataBase.Processor(json);
else if (choose == "6")
{
Console.Clear();
Console.Title = "Converter Tools";
KKdMain.ConsoleDesign(true);
KKdMain.ConsoleDesign(" Choose tool:");
KKdMain.ConsoleDesign(false);
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(false);
KKdMain.ConsoleDesign(true);
Console.Title = "AC/DT/F/AFT/FT Converting Tools";
ConsoleDesign(true);
ConsoleDesign(" Choose converter:");
ConsoleDesign(false);
ConsoleDesign("1. A3DA" );
ConsoleDesign("2. AET" );
ConsoleDesign("3. DataBank");
ConsoleDesign("4. DEX" );
ConsoleDesign("5. DIVA" );
ConsoleDesign("6. MotHead" );
ConsoleDesign("7. MOT" );
ConsoleDesign("8. Table" );
ConsoleDesign("9. STR" );
ConsoleDesign(false);
ConsoleDesign("R. Return to Main Menu");
ConsoleDesign(false);
ConsoleDesign(true);
Console.WriteLine();
string Function = Console.ReadLine();
Console.Clear();
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;
string localChoose = Console.ReadLine().ToUpper();
if (localChoose == "1") A3D.Processor(json);
else if (localChoose == "2") AET.Processor(json);
else if (localChoose == "3") DB .Processor(json);
else if (localChoose == "4") DEX.Processor(json);
else if (localChoose == "5") DIV.Processor();
else if (localChoose == "6") MHD.Processor(json);
else if (localChoose == "7") MOT.Processor(json);
else if (localChoose == "8") TBL.Processor(json);
else if (localChoose == "9") STR.Processor(json);
else choose = localChoose;
}
else if (function == "7")
else if (choose == "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), ""));
Console.Clear();
Console.Title = "F/F2/FT Converting Tools";
ConsoleDesign(true);
ConsoleDesign(" Choose converter:");
ConsoleDesign(false);
ConsoleDesign("1. A3DA" );
ConsoleDesign("2. Bloom" );
ConsoleDesign("3. Color Correction");
ConsoleDesign("4. DEX" );
ConsoleDesign("5. DOF" );
ConsoleDesign("6. Light" );
ConsoleDesign("7. STR" );
ConsoleDesign("8. VAG" );
ConsoleDesign(false);
ConsoleDesign("R. Return to Main Menu");
ConsoleDesign(false);
ConsoleDesign(true);
Console.WriteLine();
string localChoose = Console.ReadLine().ToUpper();
if (localChoose == "1") A3D.Processor(json);
else if (localChoose == "2") BLT.Processor();
else if (localChoose == "3") CCT.Processor();
else if (localChoose == "4") DEX.Processor(json);
else if (localChoose == "5") DFT.Processor();
else if (localChoose == "6") LIT.Processor();
else if (localChoose == "7") STR.Processor(json);
else if (localChoose == "8") VAG.Processor();
else choose = localChoose;
}
else if (choose == "8")
{
Console.Clear();
Console.Title = "X Converting Tools";
ConsoleDesign(true);
ConsoleDesign(" Choose converter:");
ConsoleDesign(false);
ConsoleDesign("1. A3DA" );
ConsoleDesign("2. DEX" );
ConsoleDesign("3. VAG" );
ConsoleDesign(false);
ConsoleDesign("R. Return to Main Menu");
ConsoleDesign(false);
ConsoleDesign(true);
Console.WriteLine();
string localChoose = Console.ReadLine().ToUpper();
if (localChoose == "1") A3D.Processor(json);
else if (localChoose == "2") DEX.Processor(json);
else if (localChoose == "3") VAG.Processor();
else choose = localChoose;
}
else if (choose == "9")
{
Console.Title = json ? "MsgPack to JSON" : "JSON to MsgPack";
Choose(1, json ? "mp" : "json", out string[] fileNames);
foreach (string file in fileNames)
if (json)
{
Console.Title = "MsgPack to JSON: " + Path.GetFileNameWithoutExtension(file);
file.Replace(Path.GetExtension(file), "").ToJSON ();
}
else
{
Console.Title = "JSON to MsgPack: " + Path.GetFileNameWithoutExtension(file);
file.Replace(Path.GetExtension(file), "").ToMsgPack();
}
}
}
public static void Exit() => Environment.Exit(0);
public static void ConsoleDesign(string text, params string[] args)
{
text = string.Format(text, args);
string Text = "█ █";
Text = Text.Remove(3) + text + Text.Remove(0, text.Length + 3);
Console.WriteLine(Text);
}
public static void ConsoleDesign(bool Fill)
{
if (Fill) Console.WriteLine("████████████████████████████████████████████████████");
else Console.WriteLine("█ █");
}
private static string GetArgs(string name, bool And, params string[] ext)
{
int L = ext.Length;
string Out = (And ? "|" : "") + name + " files (";
for (int i = 0; i < L; i++) { Out += "*." + ext[i]; if (i + 1 < L) Out += ", "; }
Out += ")|";
for (int i = 0; i < L; i++) { Out += "*." + ext[i]; if (i + 1 < L) Out += ";" ; }
return Out;
}
private static string GetArgs(string name, params string[] ext)
{
int L = ext.Length;
string Out = name + " files (";
for (int i = 0; i < L; i++) { Out += "*." + ext[i]; if (i + 1 < L) Out += ", "; }
Out += ")|";
for (int i = 0; i < L; i++) { Out += "*." + ext[i]; if (i + 1 < L) Out += ";" ; }
return Out;
}
public static string Choose(int code, string filetype, out string[] FileNames)
{
string mp = GetArgs("MessagePack", true, "mp" );
string json = GetArgs("JSON" , true, "json");
string bin = GetArgs("BIN" , true, "bin" );
string wav = GetArgs("WAV" , true, "wav" );
FileNames = new string[0];
if (code == 1)
{
string Filter = GetArgs("All;", false, "*");
if (filetype == "a3da") Filter = GetArgs("A3DA", "a3da", "farc", "json", "mp") +
GetArgs("A3DA", true, "a3da") + GetArgs("FARC", true, "farc") + json + mp;
else if (filetype == "bin" ) Filter = GetArgs("BIN" , "bin", "json", "mp") +
bin + json + mp;
else if (filetype == "blt" ) Filter = GetArgs("BLT" , "blt");
else if (filetype == "bon" ) Filter = GetArgs("BON" , "bon", "bin", "json", "mp") +
GetArgs("BON", true, "bon") + bin + json + mp;
else if (filetype == "cct" ) Filter = GetArgs("CCT" , "cct");
else if (filetype == "databank") Filter = GetArgs("DAT", "dat", "json", "mp") +
GetArgs("DAT", true, "dat") + json + mp;
else if (filetype == "dex" ) Filter = GetArgs("DEX" , "dex", "bin", "json", "mp") +
GetArgs("DEX", true, "dex") + bin + json + mp;
else if (filetype == "dft" ) Filter = GetArgs("DFT" , "dft");
else if (filetype == "diva") Filter = GetArgs("DIVA", "diva", "wav") +
GetArgs("DIVA", true, "diva") + wav;
else if (filetype == "farc") Filter = GetArgs("FARC", "farc");
else if (filetype == "json") Filter = GetArgs("JSON", "json");
else if (filetype == "mp" ) Filter = GetArgs("MessagePack", "mp");
else if (filetype == "lit") Filter = GetArgs("LIT" , "lit");
else if (filetype == "str" ) Filter = GetArgs("STR" , "str", "bin", "json", "mp") +
GetArgs("STR", true, "str") + bin + json + mp;
else if (filetype == "tbl" ) Filter = GetArgs("Table" , "bin", "farc", "json", "mp") +
bin + GetArgs("FARC Archives", true, "farc") + json + mp;
else if (filetype == "vag" ) Filter = GetArgs("VAG" , "vag", "wav") +
GetArgs("VAG", true, "vag") + wav;
using OpenFileDialog ofd = new OpenFileDialog { //InitialDirectory = Application.StartupPath,
Filter = Filter, Multiselect = true, Title = "Choose file(s) to open:" };
if (ofd.ShowDialog() == DialogResult.OK) FileNames = ofd.FileNames;
}
else if (code == 2)
{
string Return = "";
using (OpenFileDialog ofd = new OpenFileDialog { //InitialDirectory = Application.StartupPath,
ValidateNames = false, CheckFileExists = false, Filter = " | ", CheckPathExists = true,
Title = "Choose any file in folder:", FileName = "Folder Selection." })
if (ofd.ShowDialog() == DialogResult.OK) Return = Path.GetDirectoryName(ofd.FileName);
return Return;
}
return "";
}
}
}
+4 -4
View File
@@ -2,14 +2,14 @@
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("PD_Tool")]
[assembly: AssemblyDescription("A simple tool for working with Project Diva AC/DT/F/AFT/F2/X/FT files")]
[assembly: AssemblyDescription("A simple tool for working with Project Diva AC/DT/F/AFT/F2/X/FT/M39 files")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PD_Tool")]
[assembly: AssemblyCopyright("korenkonder © 2017-2019")]
[assembly: AssemblyCopyright("korenkonder © 2017-2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
[assembly: AssemblyVersion("0.4.6.4")]
[assembly: AssemblyFileVersion("0.4.6.4")]
[assembly: AssemblyVersion("0.4.9.0")]
[assembly: AssemblyFileVersion("0.4.9.0")]
+169
View File
@@ -0,0 +1,169 @@
using System;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdA3DA = KKdMainLib.A3DA;
using KKdFARC = KKdMainLib.FARC;
namespace PD_Tool
{
class A3D
{
public static void Processor(bool json)
{
Console.Title = "A3DA Converter";
Program.Choose(1, "a3da", out string[] fileNames);
if (fileNames.Length < 1) return;
bool mp = false;
foreach (string file in fileNames)
if (file.EndsWith(".mp") || file.EndsWith(".json") || file.EndsWith(".farc")) { mp = true; break; }
Format format = Format.NULL;
string choose = "";
if (mp)
{
Console.Clear();
Program.ConsoleDesign(true);
Program.ConsoleDesign(" Choose type of format to export:");
Program.ConsoleDesign(false);
Program.ConsoleDesign("1. A3DA [DT/AC/F]");
Program.ConsoleDesign("2. A3DC [DT/AC/F]");
Program.ConsoleDesign("3. A3DA [AFT/FT] ");
Program.ConsoleDesign("4. A3DC [AFT/FT] ");
Program.ConsoleDesign("5. A3DC [F2] ");
Program.ConsoleDesign("6. A3DC [MGF] ");
Program.ConsoleDesign("7. A3DC [X] ");
Program.ConsoleDesign(false);
Program.ConsoleDesign(true);
Console.WriteLine();
choose = Console.ReadLine().ToUpper();
if (choose == "1") format = Format.DT ;
else if (choose == "2") format = Format.F ;
else if (choose == "3") format = Format.AFT ;
else if (choose == "4") format = Format.AFT ;
else if (choose == "5") format = Format.F2LE;
else if (choose == "6") format = Format.MGF ;
else if (choose == "7") format = Format.X ;
else return;
}
int state;
string filepath, ext;
KKdA3DA a3da;
foreach (string file in fileNames)
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "A3DA Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".farc")
using (KKdFARC farc = new KKdFARC(file))
FARCProcessor(farc, choose, format);
else if (ext == ".a3da")
using (a3da = new KKdA3DA(true))
{
state = a3da.A3DAReader(filepath);
if (state == 1) a3da.MsgPackWriter(filepath, json);
}
else if (ext == ".mp" || ext == ".json")
using (a3da = new KKdA3DA(true))
{
a3da.MsgPackReader(filepath, ext == ".json");
a3da.Head.Format = format;
File.WriteAllBytes(filepath + ".a3da", (choose != "1" &&
choose != "3") ? a3da.A3DCWriter() : a3da.A3DAWriter());
}
}
}
private static void FARCProcessor(KKdFARC farc, string choose, Format format)
{
if (!farc.HeaderReader()) return;
if (!farc.HasFiles) return;
KKdList<string> list = KKdList<string>.New;
for (int i = 0; i < farc.Files.Count; i++)
{
string file = farc.Files[i].Name.ToLower();
bool div = false;
for (int i0 = 0; i0 < 159 && !div; i0++)
if (file.Contains("div_" + i0)) div = true;
if (!div && file.EndsWith(".a3da")) list.Add(file);
}
KKdList<string> A3DAlist = KKdList<string>.New;
for (int i = 0; i < farc.Files.Count; i++)
if (farc.Files[i].Name.ToLower().EndsWith(".a3da"))
A3DAlist.Add(farc.Files[i].Name);
byte[] data = null;
if (list.Count == A3DAlist.Count || (format > Format.AFT && format < Format.FT))
{
KKdA3DA a3da;
for (int i = 0; i < A3DAlist.Count; i++)
using (a3da = new KKdA3DA(true))
{
data = farc.FileReader(A3DAlist[i]);
int state = a3da.A3DAReader(data);
if (state == 1)
{
KKdFARC.FARCFile file = farc.Files[i];
a3da.Head.Format = format;
file.Data = (choose != "1" && choose != "3") ? a3da.A3DCWriter() : a3da.A3DAWriter();
farc.Files[i] = file;
}
}
farc.Save();
return;
}
KKdA3DA[] a3daArray;
using (KKdList<KKdA3DA> a3daList = KKdList<KKdA3DA>.New)
{
for (int i = 0; i < list.Count; i++)
{
KKdA3DA a3da;
using (a3da = new KKdA3DA(true))
{
data = farc.FileReader(list[i]);
int state = a3da.A3DAReader(data);
if (state == 1) a3daList.Add(a3da);
}
}
a3daArray = a3daList.ToArray();
}
for (int i = 0; i < list.Count; i++)
{
if (a3daArray[i].Data.PlayControl.Div == null) continue;
float Div = a3daArray[i].Data.PlayControl.Div.Value;
KKdA3DA a3da;
for (int i1 = 1; i1 < Div; i1++)
using (a3da = new KKdA3DA(true))
{
string file = Path.GetFileNameWithoutExtension(list[i]) +
"_div_" + i1 + Path.GetExtension(list[i]);
data = farc.FileReader(file);
int state = a3da.A3DAReader(data);
if (state == 1) a3daArray[i].A3DAMerger(ref a3da.Data);
}
a3daArray[i].Data.PlayControl.Div = null;
}
farc.Files.Capacity = list.Count;
for (int i = 0; i < list.Count; i++)
{
KKdFARC.FARCFile file = default;
file.Name = list[i];
a3daArray[i].Head.Format = format;
file.Data = (choose != "1" && choose != "3") ? a3daArray[i].A3DCWriter() : a3daArray[i].A3DAWriter();
farc.Files.Add(file);
}
farc.Save();
return;
}
}
}
+38
View File
@@ -0,0 +1,38 @@
using System;
using KKdMainLib;
using KKdMainLib.IO;
namespace PD_Tool
{
public class AET
{
public static void Processor(bool json)
{
Console.Title = "AET Converter";
Program.Choose(1, "bin", out string[] fileNames);
if (fileNames.Length < 1) return;
string filepath, ext;
Aet aet;
foreach (string file in fileNames)
using (aet = new Aet())
{
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);
}
}
}
}
}
+30
View File
@@ -0,0 +1,30 @@
using System;
using KKdMainLib.IO;
using KKdMainLib.F2;
namespace PD_Tool
{
public class BLT
{
public static void Processor()
{
Console.Title = "Bloom Converter";
Program.Choose(1, "blt", out string[] fileNames);
if (fileNames.Length < 1) return;
string filepath, ext;
Bloom blt;
foreach (string file in fileNames)
using (blt = new Bloom())
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "Bloom Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".blt") { blt.BLTReader(filepath); blt.TXTWriter(filepath); }
//else if (ext == ".txt") { blt.TXTReader(filepath); blt.BLTWriter(filepath); }
}
}
}
}
+30
View File
@@ -0,0 +1,30 @@
using System;
using KKdMainLib.IO;
using KKdMainLib.F2;
namespace PD_Tool
{
public class CCT
{
public static void Processor()
{
Console.Title = "Color Correction Converter";
Program.Choose(1, "cct", out string[] fileNames);
if (fileNames.Length < 1) return;
string filepath, ext;
ColorCorrection cct;
foreach (string file in fileNames)
using (cct = new ColorCorrection())
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "Color Correction Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".cct") { cct.CCTReader(filepath); cct.TXTWriter(filepath); }
//else if (ext == ".txt") { cct.TXTReader(filepath); cct.BLTWriter(filepath); }
}
}
}
}
+58
View File
@@ -0,0 +1,58 @@
using System;
using KKdMainLib.IO;
namespace PD_Tool
{
public class DB
{
public static void Processor(bool json)
{
Console.Title = "DataBank Converter";
Program.Choose(1, "databank", out string[] fileNames);
if (fileNames.Length < 1) return;
bool mp = true;
foreach (string file in fileNames)
if (file.EndsWith(".mp" )) { mp = false; break; }
else if (file.EndsWith(".json")) { mp = false; break; }
uint num2 = (uint)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
string[] file_split;
string filepath, ext;
KKdMainLib.DataBank db;
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('_');
using (db = new KKdMainLib.DataBank())
{
if (file_split.Length == 5 && ext == ".dat" && mp)
{
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);
}
else if (ext == ".bin" && mp)
{
filepath = file.Replace(".bin", "");
Console.Title = "DataBank Converter: " + filename;
db. DBReader(file);
db.MsgPackWriter(filepath, json);
}
else if ((ext == ".mp" || ext == ".json") && !mp)
{
Console.Title = "DataBank Converter: " + filename;
db.MsgPackReader(filepath, json);
db. DBWriter(filepath, num2);
}
}
}
}
}
}
+62
View File
@@ -0,0 +1,62 @@
using System;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdDEX = KKdMainLib.DEX;
namespace PD_Tool
{
public class DEX
{
public static void Processor(bool json)
{
Console.Title = "DEX Converter";
Program.Choose(1, "dex", out string[] fileNames);
if (fileNames.Length < 1) return;
bool mp = true;
bool _json = true;
foreach (string file in fileNames)
if (file.EndsWith(".mp" )) { mp = false; break; }
else if (file.EndsWith(".json")) { _json = false; break; }
Console.Clear();
string choose = "";
Program.ConsoleDesign(true);
Program.ConsoleDesign(" Choose type of exporting file:");
Program.ConsoleDesign(false);
Program.ConsoleDesign("1. F/FT PS3/PS4/PSVita");
Program.ConsoleDesign("2. F2 PS3/PSVita");
Program.ConsoleDesign("3. X PS4/PSVita");
if ( mp && !json) Program.ConsoleDesign("9. MessagePack");
if (_json && json) Program.ConsoleDesign("9. JSON");
Program.ConsoleDesign(false);
Program.ConsoleDesign(true);
Console.WriteLine();
choose = Console.ReadLine().ToUpper();
Format format = Format.NULL;
if (choose == "1") format = Format.F ;
else if (choose == "2") format = Format.F2LE;
else if (choose == "3") format = Format.X ;
else if (choose == "9" && mp && _json) format = Format.NULL;
else return;
string filepath, ext;
KKdDEX DEX;
foreach (string file in fileNames)
using (DEX = new KKdDEX())
{
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, json);
if (format > Format.NULL) DEX. DEXWriter(filepath, format);
else DEX.MsgPackWriter(filepath, json);
}
}
}
}
+30
View File
@@ -0,0 +1,30 @@
using System;
using KKdMainLib.IO;
using KKdMainLib.F2;
namespace PD_Tool
{
public class DFT
{
public static void Processor()
{
Console.Title = "DOF Converter";
Program.Choose(1, "dft", out string[] fileNames);
if (fileNames.Length < 1) return;
string filepath, ext;
DOF dft;
foreach (string file in fileNames)
using (dft = new DOF())
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "DOF Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".dft") { dft.DFTReader(filepath); dft.TXTWriter(filepath); }
//else if (ext == ".txt") { dft.TXTReader(filepath); dft.DFTWriter(filepath); }
}
}
}
}
+31
View File
@@ -0,0 +1,31 @@
using System;
using System.IO;
using KKdSoundLib;
namespace PD_Tool
{
public class DIV
{
public static void Processor()
{
Console.Title = "DIVA Converter";
Program.Choose(1, "diva", out string[] fileNames);
if (fileNames.Length < 1) return;
string filepath, ext;
DIVA diva;
foreach (string file in fileNames)
{
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 -13
View File
@@ -8,26 +8,22 @@ namespace PD_Tool
public static void Decrypt(string file)
{
Stream reader = File.OpenReader(file);
if (reader.ReadInt64() != 0x454C494641564944)
{
reader.Close();
Encrypt(file);
return;
}
reader.Close();
ulong head = reader.RU64();
reader.C();
if (head != 0x454C494641564944) return;
System.Console.Title = "DIVAFILE Decrypt: " + Path.GetFileName(file);
file.Decrypt();
}
public static void Encrypt(string file)
{
Stream reader = File.OpenReader(file);
if (reader.ReadInt64() == 0x454C494641564944)
{
reader.Close();
Decrypt(file);
return;
}
ulong head = reader.RU64();
reader.C();
if (head == 0x454C494641564944) return;
System.Console.Title = "DIVAFILE Encrypt: " + Path.GetFileName(file);
file.Encrypt();
}
}
+80 -85
View File
@@ -1,121 +1,116 @@
using System;
using System.IO;
using KKdMainLib;
using DB = KKdMainLib.DB;
using Aet = KKdMainLib.DB.Aet;
using Auth = KKdMainLib.DB.Auth;
using Spr = KKdMainLib.DB.Spr;
namespace PD_Tool
{
public class DataBase
{
public static void Processor(bool JSON)
public static void Processor(bool json)
{
Console.Title = "DB Converter";
Console.Clear();
Main.ConsoleDesign(true);
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);
Program.ConsoleDesign(true);
Program.ConsoleDesign(" Choose type of DataBase file:");
Program.ConsoleDesign(false);
Program.ConsoleDesign("1. Auth DB Converter");
Program.ConsoleDesign("2. AET DB Converter");
Program.ConsoleDesign("3. SPR DB Converter");
Program.ConsoleDesign(false);
Program.ConsoleDesign("R. Return to Main Menu");
Program.ConsoleDesign(false);
Program.ConsoleDesign(true);
Console.WriteLine();
string format = Console.ReadLine();
if (format == "1") AuthDBProcessor(JSON);
if (format == "2") AETDBProcessor(JSON);
if (format == "3") SPRDBProcessor(JSON);
string format = Console.ReadLine().ToUpper();
if (format == "1") AuthDBProcessor(json);
if (format == "2") AETDBProcessor(json);
if (format == "3") SPRDBProcessor(json);
}
public static void AuthDBProcessor(bool JSON)
{
Console.Title = "Auth DB Converter";
DB.Auth Auth;
Main.Choose(1, "bin", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
Program.Choose(1, "bin", out string[] fileNames);
if (fileNames.Length < 1) return;
foreach (string file in FileNames)
{
Console.Title = "Auth DB Converter: " + Path.GetFileNameWithoutExtension(file);
Auth = new DB.Auth();
ext = Path.GetExtension(file).ToLower();
filepath = file.Replace(Path.GetExtension(file), "");
string filepath, ext;
Auth auth;
foreach (string file in fileNames)
using (auth = new Auth())
{
Console.Title = "Auth DB Converter: " + Path.GetFileNameWithoutExtension(file);
ext = Path.GetExtension(file).ToLower();
filepath = file.Replace(Path.GetExtension(file), "");
if (ext == ".bin")
{
Auth.BINReader (filepath);
Auth.MsgPackWriter(filepath, JSON);
if (ext == ".bin")
{
auth.BINReader (filepath);
auth.MsgPackWriter(filepath, JSON);
}
else if (ext == ".mp" || ext == ".json")
{
auth.MsgPackReader(filepath, ext == ".json");
auth.BINWriter (filepath);
}
}
else if (ext == ".mp" || ext == ".json")
{
Auth.MsgPackReader(filepath, ext == ".json");
Auth.BINWriter (filepath);
}
Auth = null;
}
}
public static void AETDBProcessor(bool JSON)
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 = "";
Program.Choose(1, "bin", out string[] fileNames);
if (fileNames.Length < 1) return;
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), "");
string filepath, ext;
Aet aet;
foreach (string file in fileNames)
using (aet = new Aet())
{
Console.Title = "AET DB Converter: " + Path.GetFileNameWithoutExtension(file);
ext = Path.GetExtension(file).ToLower();
filepath = file.Replace(Path.GetExtension(file), "");
if (ext == ".bin")
{
Aet.BINReader (filepath);
Aet.MsgPackWriter(filepath, JSON);
if (ext == ".bin")
{
aet.BINReader (filepath);
aet.MsgPackWriter(filepath, json);
}
else if (ext == ".mp" || ext == ".json")
{
aet.MsgPackReader(filepath, ext == ".json");
aet.BINWriter (filepath);
}
}
else if (ext == ".mp" || ext == ".json")
{
Aet.MsgPackReader(filepath, ext == ".json");
Aet.BINWriter (filepath);
}
Aet = null;
}
}
public static void SPRDBProcessor(bool JSON)
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 = "";
Program.Choose(1, "bin", out string[] fileNames);
if (fileNames.Length < 1) return;
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), "");
string filepath, ext;
Spr spr;
foreach (string file in fileNames)
using (spr = new Spr())
{
Console.Title = "SPR DB Converter: " + Path.GetFileNameWithoutExtension(file);
ext = Path.GetExtension(file).ToLower();
filepath = file.Replace(Path.GetExtension(file), "");
if (ext == ".bin")
{
Spr.BINReader (filepath);
Spr.MsgPackWriter(filepath, JSON);
if (ext == ".bin")
{
spr.BINReader (filepath);
spr.MsgPackWriter(filepath, json);
}
else if (ext == ".mp" || ext == ".json")
{
spr.MsgPackReader(filepath, ext == ".json");
spr.BINWriter (filepath);
}
}
else if (ext == ".mp" || ext == ".json")
{
Spr.MsgPackReader(filepath, ext == ".json");
Spr.BINWriter (filepath);
}
Spr = null;
}
}
}
}
+56 -53
View File
@@ -1,71 +1,74 @@
using System;
using System.IO;
using KKdMainLib;
using KKdFARC = KKdMainLib.FARC;
namespace PD_Tool
{
public class FARC
{
public static void Processor(bool Extract)
public static void Processor(bool extract)
{
KKdFARC FARC = new KKdFARC();
Console.Clear();
if (Extract)
if (extract)
{
Console.Title = "FARC Extractor";
Main.Choose(1, "farc", out string[] FileNames);
foreach (string FileName in FileNames)
if (FileName != "" && File.Exists(FileName))
new KKdFARC(FileName).UnPack();
}
else
{
string file = Main.Choose(2, "", out string[] FileNames);
Console.Clear();
Console.Title = "FARC Creator";
if (file != "")
{
FARC = new KKdFARC();
Main.ConsoleDesign(true);
Main.ConsoleDesign(" Choose type of created FARC:");
Main.ConsoleDesign(false);
Main.ConsoleDesign("1. FArc [DT/DT2nd/DTex/F/F2nd/X]");
Main.ConsoleDesign("2. FArC [DT/DT2nd/DTex/F/F2nd/X] (Compressed)");
Main.ConsoleDesign("3. FARC [F/F2nd/X]");
Main.ConsoleDesign(false);
Main.ConsoleDesign("R. Return to Main Menu");
Main.ConsoleDesign(false);
Main.ConsoleDesign(true);
Console.WriteLine();
Console.WriteLine("Choosed folder: {0}", file);
Console.WriteLine();
string type = Console.ReadLine().ToUpper();
if (type == "1") FARC.Signature = KKdFARC.Farc.FArc;
else if (type == "3" || type == "4")
Program.Choose(1, "farc", out string[] fileNamesExtract);
foreach (string fileExtract in fileNamesExtract)
if (fileExtract != "" && File.Exists(fileExtract))
{
FARC.Signature = KKdFARC.Farc.FARC;
Console.WriteLine();
Main.ConsoleDesign(true);
Main.ConsoleDesign(" Choose type of FARC:");
Main.ConsoleDesign(false);
Main.ConsoleDesign("1. FARC");
Main.ConsoleDesign("2. FARC (Compressed)");
Main.ConsoleDesign("3. FARC (Encrypted)");
Main.ConsoleDesign("4. FARC (Compressed & Encrypted)");
Main.ConsoleDesign(false);
Main.ConsoleDesign(true);
Console.WriteLine();
type = Console.ReadLine();
if (type == "2" || type == "4") FARC.FARCType |= KKdFARC.Type.GZip;
if (type == "3" || type == "4") FARC.FARCType |= KKdFARC.Type.ECB ;
Console.Title = "FARC Extractor: " + Path.GetFileNameWithoutExtension(fileExtract);
using (KKdFARC farc = new KKdFARC(fileExtract))
farc.Unpack();
}
else if (type == "R") return;
else FARC.Signature = KKdFARC.Farc.FArC;
Console.Title = "FARC Creator - Directory: " + Path.GetDirectoryName(file);
new KKdFARC(file, true).Pack();
return;
}
string file = Program.Choose(2, "", out string[] fileNames);
Console.Clear();
if (file == null || file == "") return;
Console.Title = "FARC Creator";
using (KKdFARC farc = new KKdFARC(file, true))
{
Console.Title = "FARC Creator: " + Path.GetDirectoryName(file);
Program.ConsoleDesign(true);
Program.ConsoleDesign(" Choose type of created FARC:");
Program.ConsoleDesign(false);
Program.ConsoleDesign("1. FArc (Uncompressed)");
Program.ConsoleDesign("2. FArC (Compressed)");
Program.ConsoleDesign("3. FARC [F/F2/X]");
Program.ConsoleDesign(false);
Program.ConsoleDesign("R. Return to Main Menu");
Program.ConsoleDesign(false);
Program.ConsoleDesign(true);
Console.WriteLine();
Console.WriteLine("Choosed folder: {0}", file);
Console.WriteLine();
string choose = Console.ReadLine().ToUpper();
if (choose == "1") farc.Signature = KKdFARC.Farc.FArc;
else if (choose == "3" || choose == "4")
{
farc.Signature = KKdFARC.Farc.FARC;
Console.Clear();
Program.ConsoleDesign(true);
Program.ConsoleDesign(" Choose type of FARC:");
Program.ConsoleDesign(false);
Program.ConsoleDesign("1. FARC");
Program.ConsoleDesign("2. FARC (Compressed)");
Program.ConsoleDesign("3. FARC (Encrypted)");
Program.ConsoleDesign("4. FARC (Compressed & Encrypted)");
Program.ConsoleDesign(false);
Program.ConsoleDesign(true);
Console.WriteLine();
choose = Console.ReadLine().ToUpper();
if (choose == "2" || choose == "4") farc.FARCType |= KKdFARC.Type.GZip;
if (choose == "3" || choose == "4") farc.FARCType |= KKdFARC.Type.ECB ;
}
else if (choose == "R") return;
else farc.Signature = KKdFARC.Farc.FArC;
farc.Pack(farc.Signature);
}
}
}
+30
View File
@@ -0,0 +1,30 @@
using System;
using KKdMainLib.IO;
using KKdMainLib.F2;
namespace PD_Tool
{
public class LIT
{
public static void Processor()
{
Console.Title = "Light Converter";
Program.Choose(1, "lit", out string[] fileNames);
if (fileNames.Length < 1) return;
string filepath, ext;
Light lit;
foreach (string file in fileNames)
using (lit = new Light())
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "Light Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".lit") { lit.LITReader(filepath); lit.TXTWriter(filepath); }
//else if (ext == ".txt") { lit.TXTReader(filepath); lit.LITWriter(filepath); }
}
}
}
}
+39
View File
@@ -0,0 +1,39 @@
using System;
using KKdMainLib;
using KKdMainLib.IO;
namespace PD_Tool
{
public class MHD
{
public static void Processor(bool json)
{
Console.Title = "MotHead Converter";
Program.Choose(1, "bin", out string[] fileNames);
if (fileNames.Length < 1) return;
string filepath, ext;
MotHead mhd;
foreach (string file in fileNames)
{
mhd = new MotHead();
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "MotHead Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".bin")
{
mhd.MotHeadReader(filepath);
mhd.MsgPackWriter(filepath, json);
}
else if (ext == ".mp" || ext == ".json")
{
mhd.MsgPackReader(filepath, ext == ".json");
mhd.MotHeadWriter(filepath);
}
mhd = new MotHead();
}
}
}
}
+38
View File
@@ -0,0 +1,38 @@
using System;
using KKdMainLib;
using KKdMainLib.IO;
namespace PD_Tool
{
public class MOT
{
public static void Processor(bool json)
{
Console.Title = "MOT Converter";
Program.Choose(1, "bin", out string[] fileNames);
if (fileNames.Length < 1) return;
string filepath, ext;
Mot mot;
foreach (string file in fileNames)
using (mot = new Mot())
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "MOT Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".bin")
{
mot. MOTReader(filepath);
mot.MsgPackWriter(filepath, json);
}
else if (ext == ".mp" || ext == ".json")
{
mot.MsgPackReader(filepath, ext == ".json");
mot. MOTWriter(filepath);
}
}
}
}
}
+37
View File
@@ -0,0 +1,37 @@
using System;
using KKdMainLib.IO;
using KKdSTR = KKdMainLib.STR;
namespace PD_Tool
{
public class STR
{
public static void Processor(bool json)
{
Console.Title = "STR Converter";
Program.Choose(1, "str", out string[] fileNames);
string filepath, ext;
KKdSTR str;
foreach (string file in fileNames)
using (str = new KKdSTR())
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "STR Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".str" || ext == ".bin")
{
str.STRReader (filepath, ext);
str.MsgPackWriter(filepath, json);
}
else if (ext == ".json" || ext == ".mp")
{
str.MsgPackReader(filepath, ext == ".json");
str.STRWriter (filepath);
}
}
}
}
}
+60
View File
@@ -0,0 +1,60 @@
using System;
using System.IO;
using KKdBaseLib;
using KKdMainLib;
using KKdFARC = KKdMainLib.FARC;
namespace PD_Tool
{
public class TBL
{
public static void Processor(bool json)
{
Console.Title = "Table Converter";
Program.Choose(1, "tbl", out string[] fileNames);
if (fileNames.Length < 1) return;
string filepath, ext;
Tables tbl;
foreach (string file in fileNames)
using (tbl = new Tables())
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "Table Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".bin")
{
tbl.BINReader (filepath);
tbl.MsgPackWriter(filepath, json);
}
else if (ext == ".farc")
using (KKdFARC farc = new KKdFARC(file))
FARCProcessor(ref tbl, farc, filepath, json);
else if (ext == ".json" || ext == ".mp")
{
tbl.MsgPackReader(filepath, ext == ".json");
tbl.BINWriter (filepath);
}
}
}
private static void FARCProcessor(ref Tables tbl, KKdFARC farc, string filepath, bool json)
{
if (!farc.HeaderReader()) return;
if (!farc.HasFiles) return;
int file = -1;
KKdList<string> list = KKdList<string>.New;
for (int i = 0; i < farc.Files.Count; i++)
if (farc.Files[i].Name.ToLower().EndsWith(".bin")) { file = i; break; }
if (file == -1) return;
farc.Unpack(false);
tbl.BINReader (farc.Files[file].Data);
tbl.MsgPackWriter(filepath.Replace(Path.GetFileName(filepath),
Path.GetFileNameWithoutExtension(farc.Files[file].Name)), json);
}
}
}
-111
View File
@@ -1,111 +0,0 @@
using System;
using KKdMainLib;
using KKdMainLib.IO;
using KKdMainLib.MessagePack;
using KKdA3DA = KKdMainLib.A3DA.A3DA;
using KKdFARC = KKdMainLib.FARC;
namespace PD_Tool.Tools
{
class A3D
{
public static void Processor(bool JSON)
{
Console.Title = "A3DA Converter";
Main.Choose(1, "a3da", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
bool MP = false;
foreach (string file in FileNames)
if (file.EndsWith(".mp" )) { MP = true; break; }
else if (file.EndsWith(".json")) { MP = true; break; }
else if (file.EndsWith(".farc")) { MP = true; break; }
Main.Format Format = Main.Format.NULL;
string format = "";
if (MP)
{
Console.Clear();
Main.ConsoleDesign(true);
Main.ConsoleDesign(" Choose type of format to export:");
Main.ConsoleDesign(false);
Main.ConsoleDesign("1. A3DA [DT/AC/F]");
Main.ConsoleDesign("2. A3DC [DT/AC/F]");
Main.ConsoleDesign("3. A3DA [AFT/FT] ");
Main.ConsoleDesign("4. A3DC [AFT/FT] ");
Main.ConsoleDesign("5. A3DC [F2] ");
Main.ConsoleDesign("6. A3DC [MGF] ");
Main.ConsoleDesign("7. A3DC [X] ");
Main.ConsoleDesign(false);
Main.ConsoleDesign(true);
Console.WriteLine();
format = Console.ReadLine();
if (format == "1") Format = Main.Format.DT ;
else if (format == "2") Format = Main.Format.F ;
else if (format == "3") Format = Main.Format.FT ;
else if (format == "4") Format = Main.Format.FT ;
else if (format == "5") Format = Main.Format.F2LE;
else if (format == "6") Format = Main.Format.MGF ;
else if (format == "7") Format = Main.Format.X ;
else return;
}
KKdA3DA A;
int state;
foreach (string file in FileNames)
{
A = new KKdA3DA();
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "A3DA Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".farc")
{
KKdFARC FARC = new KKdFARC(file);
if (!FARC.HeaderReader()) continue;
if (!FARC.HasFiles) continue;
MsgPack A3DA = MsgPack.Null;
byte[] data = null;
for (int i = 0; i < FARC.Files.Length; i++)
{
data = FARC.FileReader(i);
state = A.A3DAReader(data);
if (state == 1)
{
A3DA = A.MsgPackWriter();
A = new KKdA3DA();
A.MsgPackReader(A3DA);
A.IO = File.OpenWriter();
A.Data._.CompressF16 = Format > Main.Format.FT ?
Format == Main.Format.MGF ? 2 : 1 : 0;
A.Data.Format = Format;
FARC.Files[i].Data = (format != "1" &&
format != "3") ? A.A3DCWriter() : A.A3DAWriter();
}
}
FARC.Save();
}
else if (ext == ".a3da")
{
state = A.A3DAReader(filepath);
if (state == 1) A.MsgPackWriter(filepath, JSON);
}
else if (ext == ".mp" || ext == ".json")
{
A.MsgPackReader(filepath, ext == ".json");
A.Data._.CompressF16 = Format > Main.Format.FT ?
Format == Main.Format.MGF ? 2 : 1 : 0;
A.Data.Format = Format;
File.WriteAllBytes(filepath + ".a3da", (format != "1" &&
format != "3") ? A.A3DCWriter() : A.A3DAWriter());
}
A = null;
}
}
}
}
-41
View File
@@ -1,41 +0,0 @@
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;
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More