Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e35116b894 | ||
|
|
4698c75c7a | ||
|
|
792781a5f7 | ||
|
|
773e148783 | ||
|
|
87d4862af5 | ||
|
|
b26cdc8b5c | ||
|
|
6e2f5746b0 | ||
|
|
3f883c4c77 | ||
|
|
0863721dc4 | ||
|
|
e0d651bd55 | ||
|
|
3bbbea9536 | ||
|
|
4de7bd32f7 | ||
|
|
93f905d3e1 |
@@ -1,5 +1,7 @@
|
||||
.vs
|
||||
build
|
||||
KKdBaseLib/bin
|
||||
KKdBaseLib/obj
|
||||
KKdMainLib/bin
|
||||
KKdMainLib/obj
|
||||
KKdMathLib/bin
|
||||
|
||||
@@ -0,0 +1,305 @@
|
||||
namespace KKdBaseLib.A3DA
|
||||
{
|
||||
public struct A3DAData
|
||||
{
|
||||
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 int? 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 class 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 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 enum KeyType : int
|
||||
{
|
||||
Null = 0,
|
||||
Value = 1,
|
||||
Lerp = 2,
|
||||
Hermite = 3,
|
||||
Hold = 4,
|
||||
}
|
||||
|
||||
public enum EPType : int
|
||||
{
|
||||
EP_1 = 1,
|
||||
EP_2 = 2,
|
||||
EP_3 = 3,
|
||||
}
|
||||
|
||||
public static Vector3<A3DAKey> ToA3DAKey(Vector3<Key> k) => new Vector3<A3DAKey> { X = k.X, Y = k.Y, Z = k.Z };
|
||||
public static Vector3<Key> ToKey(Vector3<A3DAKey> k) => new Vector3<Key> { X = k.X, Y = k.Y, Z = k.Z };
|
||||
|
||||
public static implicit operator Key(A3DAKey k)
|
||||
{
|
||||
Key key = default;
|
||||
key.EPTypePost = (EPType)(int)k.EPTypePost;
|
||||
key.EPTypePre = (EPType)(int)k.EPTypePre;
|
||||
key.Max = k.MaxFrames;
|
||||
if (k.Length > 1)
|
||||
{
|
||||
key.Type = (KeyType)(int)k.Type;
|
||||
key.Length = 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 implicit operator A3DAKey(Key k)
|
||||
{
|
||||
A3DAKey key = default;
|
||||
key.EPTypePost = (A3DAKey.EPType)(int)k.EPTypePost;
|
||||
key.EPTypePre = (A3DAKey.EPType)(int)k.EPTypePre;
|
||||
key.MaxFrames = k.Max ?? 0;
|
||||
if (k.Length > 1)
|
||||
{
|
||||
key.Type = (A3DAKey.KeyType)(int)k.Type;
|
||||
key.Length = k.Length;
|
||||
key.Keys = k.Keys;
|
||||
key.FDBSaE = k.Keys[k.Length - 1].F - k.Keys[0].F;
|
||||
key.VDBSaE = k.Keys[k.Length - 1].V - k.Keys[0].V;
|
||||
}
|
||||
else
|
||||
{
|
||||
key.Length = 1;
|
||||
key.Keys = new KFT3[1];
|
||||
if (key.Length == 1)
|
||||
{
|
||||
key.Type = A3DAKey.KeyType.Value;
|
||||
key.Keys[0].V = k.Value ?? 0;
|
||||
}
|
||||
}
|
||||
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 float? Shadow;
|
||||
public string Name;
|
||||
public string UIDName;
|
||||
public Node[] Node;
|
||||
public Vector3<float?> JointOrient;
|
||||
}
|
||||
|
||||
public struct PlayControl
|
||||
{
|
||||
public float? Begin;
|
||||
public float? Div;
|
||||
public float? FPS;
|
||||
public float? Offset;
|
||||
public float? Size;
|
||||
}
|
||||
|
||||
public class PostProcess
|
||||
{
|
||||
public Key LensFlare;
|
||||
public Key LensGhost;
|
||||
public Key LensShaft;
|
||||
public Vector4<Key> Ambient;
|
||||
public Vector4<Key> Diffuse;
|
||||
public Vector4<Key> Specular;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct A3DAKey
|
||||
{
|
||||
public KeyType Type;
|
||||
public int Unk04;
|
||||
public float MaxFrames;
|
||||
public EPType EPTypePre;
|
||||
public EPType EPTypePost;
|
||||
public float FDBSaE; //Frame Difference Between Start and End
|
||||
public float VDBSaE; //Value Difference Between Start and End
|
||||
public int Unk1C;
|
||||
public int Unk20;
|
||||
public int Unk24;
|
||||
public int Unk28;
|
||||
public int Unk2C;
|
||||
public int Unk30;
|
||||
public int Unk34;
|
||||
public int Length;
|
||||
public int Unk3C;
|
||||
public int DataOffset; //Used only in-game and points to KFT3 Array
|
||||
public int Unk44;
|
||||
|
||||
public KFT3[] Keys;
|
||||
|
||||
public enum KeyType : int
|
||||
{
|
||||
Null = 0,
|
||||
Value = 1,
|
||||
Lerp = 2,
|
||||
Hermite = 3,
|
||||
Hold = 4,
|
||||
}
|
||||
|
||||
public enum EPType : int
|
||||
{
|
||||
EP_1 = 1,
|
||||
EP_2 = 2,
|
||||
EP_3 = 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
namespace KKdBaseLib.Aet
|
||||
{
|
||||
public struct AetHeader
|
||||
{
|
||||
public Pointer<AetData>[] Data;
|
||||
}
|
||||
|
||||
public struct AetData
|
||||
{
|
||||
public Pointer<string> Name;
|
||||
public float StartFrame;
|
||||
public float FrameDuration;
|
||||
public float FrameRate;
|
||||
public uint BackColor;
|
||||
public uint Width;
|
||||
public uint Height;
|
||||
public Pointer<Vector2<CountPointer<KFT2>>> Position;
|
||||
public CountPointer<AetLayer > Layers ;
|
||||
public CountPointer<AetRegion> Regions;
|
||||
public CountPointer<AetSound > Sounds ;
|
||||
}
|
||||
|
||||
public struct AetLayer
|
||||
{
|
||||
public int Pointer;
|
||||
public int C { get => E != null ? E.Length : 0;
|
||||
set => E = value > -1 ? new AetObject[value] : null; }
|
||||
|
||||
public int O;
|
||||
public AetObject[] E;
|
||||
|
||||
public override string ToString() => "Count: " + C;
|
||||
}
|
||||
|
||||
|
||||
public struct AetObject
|
||||
{
|
||||
public int ID;
|
||||
public int Offset;
|
||||
public Pointer<string> Name;
|
||||
public float LoopStart;
|
||||
public float LoopEnd;
|
||||
public float StartFrame;
|
||||
public float PlaybackSpeed;
|
||||
public AetObjFlags Flags;
|
||||
public byte Pad;
|
||||
public AetObjType Type;
|
||||
public int DataID;
|
||||
public int ParentObjectID;
|
||||
public CountPointer<Marker> Marker;
|
||||
public Pointer<AnimationData> Data;
|
||||
public Pointer<AetObjExtraData> ExtraData;
|
||||
|
||||
public enum AetObjFlags : ushort
|
||||
{
|
||||
Visible = 0b0000000000000001,
|
||||
Audible = 0b0000000000000010,
|
||||
Unk2 = 0b0000000000000100,
|
||||
Unk3 = 0b0000000000001000,
|
||||
Unk4 = 0b0000000000010000,
|
||||
AudioRealted = 0b0000000000100000,
|
||||
Unk6 = 0b0000000001000000,
|
||||
SpriteFrames = 0b0000000010000000,
|
||||
Unk8 = 0b0000000100000000,
|
||||
Unk9 = 0b0000001000000000,
|
||||
Unk10 = 0b0000010000000000,
|
||||
Unk11 = 0b0000100000000000,
|
||||
Unk12 = 0b0001000000000000,
|
||||
Unk13 = 0b0010000000000000,
|
||||
Unk14 = 0b0100000000000000,
|
||||
Unk15 = 0b1000000000000000,
|
||||
}
|
||||
|
||||
public enum AetObjType : byte
|
||||
{
|
||||
Nop = 0,
|
||||
Pic = 1,
|
||||
Aif = 2,
|
||||
Eff = 3,
|
||||
}
|
||||
|
||||
public struct AetObjExtraData
|
||||
{
|
||||
public CountPointer<KFT2> Unk0;
|
||||
public CountPointer<KFT2> Unk1;
|
||||
public CountPointer<KFT2> Unk2;
|
||||
public CountPointer<KFT2> Unk3;
|
||||
}
|
||||
|
||||
public override string ToString() => $"ID: {ID}; Name: {Name.V}; Type: {Type}" +
|
||||
( DataID > -1 ? $"; Data ID: " + $"{ DataID}" : "") +
|
||||
(ParentObjectID > -1 ? $"; Parent Object ID: {ParentObjectID}" : "");
|
||||
}
|
||||
|
||||
public struct Marker
|
||||
{
|
||||
public float Frame;
|
||||
public Pointer<string> Name;
|
||||
}
|
||||
|
||||
public struct AnimationData
|
||||
{
|
||||
public BlendMode Mode;
|
||||
public byte Padding0;
|
||||
public bool UseTextureMask;
|
||||
public byte Padding1;
|
||||
public CountPointer<KFT2> OriginX;
|
||||
public CountPointer<KFT2> OriginY;
|
||||
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<ThirdDimension> _3D;
|
||||
|
||||
public enum BlendMode : byte
|
||||
{
|
||||
Alpha = 3,
|
||||
Additive = 5,
|
||||
DstColorZero = 6,
|
||||
SrcAlphaOneMinusSrcColor = 7,
|
||||
Transparent = 8,
|
||||
}
|
||||
|
||||
public struct ThirdDimension
|
||||
{
|
||||
public CountPointer<KFT2> Unk1 ;
|
||||
public CountPointer<KFT2> Unk2 ;
|
||||
public CountPointer<KFT2> RotReturnX;
|
||||
public CountPointer<KFT2> RotReturnY;
|
||||
public CountPointer<KFT2> RotReturnZ;
|
||||
public CountPointer<KFT2> RotationX;
|
||||
public CountPointer<KFT2> RotationY;
|
||||
public CountPointer<KFT2> ScaleZ;
|
||||
}
|
||||
}
|
||||
|
||||
public struct AetRegion
|
||||
{
|
||||
public int Offset;
|
||||
public uint Color;
|
||||
public ushort Width;
|
||||
public ushort Height;
|
||||
public float Frames;
|
||||
public CountPointer<Sprite> Sprites;
|
||||
|
||||
public override string ToString() => $"Width: {Width}; Height: {Height}; Color: {Color.ToString("X2")}";
|
||||
}
|
||||
|
||||
public struct Sprite
|
||||
{
|
||||
public Pointer<string> Name;
|
||||
public uint ID;
|
||||
|
||||
public override string ToString() => $"ID: {ID}; Name: {Name}";
|
||||
}
|
||||
|
||||
public struct AetSound
|
||||
{
|
||||
public int Offset;
|
||||
public uint Unk0;
|
||||
public uint Unk1;
|
||||
public uint Unk2;
|
||||
public uint Unk3;
|
||||
}
|
||||
}
|
||||
@@ -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,27 @@ 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
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 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 byte* bufPtr = buf.GetPtr();
|
||||
|
||||
public static byte[] Endian(this byte[] LE, byte Len)
|
||||
{ CFUTRM(buf, ref bufPtr);
|
||||
for (byte i = 0; i < Len; i++) bufPtr[i] = LE[i];
|
||||
for (byte i = 0; i < Len; i++) LE[Len - i - 1] = bufPtr[i]; return LE; }
|
||||
|
||||
public static byte[] Endian(this byte[] LE, byte Len, bool IsBE)
|
||||
{ CFUTRM(buf, ref bufPtr);
|
||||
if (IsBE) { for (byte i = 0; i < Len; i++) bufPtr[i] = LE[i];
|
||||
for (byte i = 0; i < Len; i++) LE[Len - i - 1] = bufPtr[i]; } return LE; }
|
||||
|
||||
public static short Endian(this short LE, bool IsBE)
|
||||
{ CFUTRM(buf, ref bufPtr);
|
||||
if (IsBE) { int TLE = 0; for (byte i = 0; i < 2; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
|
||||
for (byte i = 0; i < 2; i++) { TLE |= bufPtr[i]; if (i < 1) TLE <<= 8; } LE = (short)TLE; } return LE; }
|
||||
|
||||
public static ushort Endian(this ushort LE, bool IsBE)
|
||||
{ CFUTRM(buf, ref bufPtr);
|
||||
if (IsBE) { for (byte i = 0; i < 2; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
|
||||
for (byte i = 0; i < 2; i++) { LE |= bufPtr[i]; if (i < 1) LE <<= 8; } } return LE; }
|
||||
|
||||
public static int Endian(this int LE, bool IsBE)
|
||||
{ CFUTRM(buf, ref bufPtr);
|
||||
if (IsBE) { for (byte i = 0; i < 4; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
|
||||
for (byte i = 0; i < 4; i++) { LE |= bufPtr[i]; if (i < 3) LE <<= 8; } } return LE; }
|
||||
|
||||
public static uint Endian(this uint LE, bool IsBE)
|
||||
{ CFUTRM(buf, ref bufPtr);
|
||||
if (IsBE) { for (byte i = 0; i < 4; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
|
||||
for (byte i = 0; i < 4; i++) { LE |= bufPtr[i]; if (i < 3) LE <<= 8; } } return LE; }
|
||||
|
||||
public static long Endian(this long LE, bool IsBE)
|
||||
{ CFUTRM(buf, ref bufPtr);
|
||||
if (IsBE) { for (byte i = 0; i < 8; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
|
||||
for (byte i = 0; i < 8; i++) { LE |= bufPtr[i]; if (i < 7) LE <<= 8; } } return LE; }
|
||||
|
||||
public static ulong Endian(this ulong LE, bool IsBE)
|
||||
{ CFUTRM(buf, ref bufPtr);
|
||||
if (IsBE) { for (byte i = 0; i < 8; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
|
||||
for (byte i = 0; i < 8; i++) { LE |= bufPtr[i]; if (i < 7) LE <<= 8; } } return LE; }
|
||||
|
||||
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 ToInt32(this float f) => *( int*)&f;
|
||||
public static uint ToUInt32(this float f) => *( uint*)&f;
|
||||
public static long ToInt64(this double f) => *( long*)&f;
|
||||
public static ulong ToUInt64(this double f) => *(ulong*)&f;
|
||||
|
||||
public static float ToSingle(this int i) => *( float*)&i;
|
||||
public static float ToSingle(this uint i) => *( float*)&i;
|
||||
public static double ToDouble(this long i) => *(double*)&i;
|
||||
public static double ToDouble(this ulong i) => *(double*)&i;
|
||||
|
||||
public static sbyte* GetPtr(this sbyte[] array) { fixed ( sbyte* tempPtr = array) return tempPtr; }
|
||||
public static byte* GetPtr(this byte[] array) { fixed ( byte* tempPtr = array) return tempPtr; }
|
||||
public static short* GetPtr(this short[] array) { fixed ( short* tempPtr = array) return tempPtr; }
|
||||
public static ushort* GetPtr(this ushort[] array) { fixed (ushort* tempPtr = array) return tempPtr; }
|
||||
public static int* GetPtr(this int[] array) { fixed ( int* tempPtr = array) return tempPtr; }
|
||||
public static uint* GetPtr(this uint[] array) { fixed ( uint* tempPtr = array) return tempPtr; }
|
||||
public static long* GetPtr(this long[] array) { fixed ( long* tempPtr = array) return tempPtr; }
|
||||
public static ulong* GetPtr(this ulong[] array) { fixed ( ulong* tempPtr = array) return tempPtr; }
|
||||
public static float* GetPtr(this float[] array) { fixed ( float* tempPtr = array) return tempPtr; }
|
||||
public static double* GetPtr(this double[] array) { fixed (double* tempPtr = array) return tempPtr; }
|
||||
|
||||
public static IntPtr GetIntPtr(this sbyte[] array) { fixed ( sbyte* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this byte[] array) { fixed ( byte* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this short[] array) { fixed ( short* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this ushort[] array) { fixed (ushort* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this int[] array) { fixed ( int* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this uint[] array) { fixed ( uint* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this long[] array) { fixed ( long* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this ulong[] array) { fixed ( ulong* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this float[] array) { fixed ( float* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this double[] array) { fixed (double* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
|
||||
public static string ToString(this int d, bool IsBE) =>
|
||||
BitConverter.GetBytes(d.Endian(IsBE)).ToASCII();
|
||||
|
||||
public static string ToString(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 ToString(F32);
|
||||
else if (d is double F64 ) return ToString(F64);
|
||||
return d.ToString();
|
||||
}
|
||||
|
||||
private static readonly string NumberDecimalSeparator =
|
||||
System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
|
||||
|
||||
public static string ToString(this bool? d) => (d ?? default).ToString();
|
||||
public static string ToString(this bool d) => d.ToString().ToLower();
|
||||
public static string ToString(this sbyte? d) => (d ?? default).ToString();
|
||||
public static string ToString(this sbyte d) => d.ToString();
|
||||
public static string ToString(this byte? d) => (d ?? default).ToString();
|
||||
public static string ToString(this byte d) => d.ToString();
|
||||
public static string ToString(this short? d) => (d ?? default).ToString();
|
||||
public static string ToString(this short d) => d.ToString();
|
||||
public static string ToString(this ushort? d) => (d ?? default).ToString();
|
||||
public static string ToString(this ushort d) => d.ToString();
|
||||
public static string ToString(this int? d) => (d ?? default).ToString();
|
||||
public static string ToString(this int d) => d.ToString();
|
||||
public static string ToString(this uint? d) => (d ?? default).ToString();
|
||||
public static string ToString(this uint d) => d.ToString();
|
||||
public static string ToString(this long? d) => (d ?? default).ToString();
|
||||
public static string ToString(this long d) => d.ToString();
|
||||
public static string ToString(this ulong? d) => (d ?? default).ToString();
|
||||
public static string ToString(this ulong d) => d.ToString();
|
||||
public static string ToString(this float? d, byte round) => (d ?? default).ToString(round);
|
||||
public static string ToString(this float? d) => (d ?? default).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 ?? default).ToString(round);
|
||||
public static string ToString(this double? d) => (d ?? default).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; }
|
||||
|
||||
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]
|
||||
[System.Security.SecuritySafeCritical]
|
||||
private static void CFUTRM(byte[] buf, ref byte* bufPtr) //CheckForUnableToReadMemory
|
||||
{ try { if (buf[0] != bufPtr[0] || bufPtr[1] != bufPtr[1] || bufPtr[2] != bufPtr[2] || buf[3] != bufPtr[3] ||
|
||||
buf[4] != bufPtr[4] || bufPtr[5] != bufPtr[5] || bufPtr[6] != bufPtr[6] || buf[7] != bufPtr[7])
|
||||
bufPtr = buf.GetPtr(); } catch (AccessViolationException) { bufPtr = buf.GetPtr(); } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,251 @@
|
||||
namespace KKdBaseLib.F2
|
||||
{
|
||||
public unsafe struct ENRSList : INull
|
||||
{
|
||||
public int Depth;
|
||||
public KKdList<ENRS> List;
|
||||
|
||||
public int Length => length();
|
||||
|
||||
public bool IsNull => List. IsNull;
|
||||
public bool NotNull => List.NotNull;
|
||||
|
||||
public static ENRSList Read(byte[] data, int Depth = 0)
|
||||
{
|
||||
if (data == null || data.Length < 0x10) return default;
|
||||
byte* ptr = data.GetPtr();
|
||||
int i, i0;
|
||||
int ENRSCount = ((int*)ptr)[1];
|
||||
KKdList<ENRS> List = KKdList<ENRS>.New;
|
||||
ptr += 0x10;
|
||||
ENRS ENR;
|
||||
ENRS.SubENRS Sub;
|
||||
|
||||
for (i = 0; i < ENRSCount; i++)
|
||||
{
|
||||
ENR = default;
|
||||
ENR.Offset = ReadENRSValue(ref ptr);
|
||||
ENR.Count = ReadENRSValue(ref ptr);
|
||||
ENR.Size = ReadENRSValue(ref ptr);
|
||||
ENR.Repeat = ReadENRSValue(ref ptr);
|
||||
|
||||
if (i > 0) ENR.Offset += List[List.Count - 1].Offset;
|
||||
|
||||
if (ENR.Repeat < 1) { ENR.Sub = null; List.Add(ENR); continue; }
|
||||
|
||||
ENR.Sub = new KKdList<ENRS.SubENRS> { Capacity = ENR.Count };
|
||||
for (i0 = 0; i0 < ENR.Count; i0++)
|
||||
{
|
||||
Sub = default;
|
||||
Sub.Skip = ReadENRSValue(ref ptr, out Sub.Type);
|
||||
Sub.Reverse = ReadENRSValue(ref ptr);
|
||||
if (i0 > 0) Sub.Skip += ENR.Sub[i0 - 1].SizeSkip;
|
||||
ENR.Sub.Add(Sub);
|
||||
|
||||
if (ENR.Sub[i0].Type == ENRS.Type.Invalid) return default;
|
||||
}
|
||||
List.Add(ENR);
|
||||
}
|
||||
return new ENRSList { Depth = Depth, List = List };
|
||||
}
|
||||
|
||||
public static byte[] Write(ENRSList ENRS)
|
||||
{
|
||||
int i, i0;
|
||||
byte[] data;
|
||||
byte* ptr;
|
||||
|
||||
KKdList<ENRS> List = (System.Collections.Generic.List<ENRS>)ENRS.List;
|
||||
if (ENRS.IsNull || ENRS.List.Count < 1) return new byte[0x20];
|
||||
|
||||
data = new byte[ENRS.Length];
|
||||
ptr = data.GetPtr();
|
||||
((int*)ptr)[1] = ENRS.List.Count;
|
||||
ptr += 0x10;
|
||||
|
||||
for (i = 0; i < ENRS.List.Count; i++)
|
||||
{
|
||||
ENRS ENR = ENRS.List[i];
|
||||
WriteENRSValue(ref ptr, i > 0 ? ENR.Offset - ENRS.List[i - 1].Offset : ENR.Offset);
|
||||
WriteENRSValue(ref ptr, ENR.Count );
|
||||
WriteENRSValue(ref ptr, ENR.Size );
|
||||
WriteENRSValue(ref ptr, ENR.Repeat);
|
||||
|
||||
if (ENR.Repeat < 1) continue;
|
||||
|
||||
for (i0 = 0; i0 < ENR.Count; i0++)
|
||||
{
|
||||
if (ENR.Sub[i0].Type < ENRSList.ENRS.Type. WORD ||
|
||||
ENR.Sub[i0].Type > ENRSList.ENRS.Type.QWORD)
|
||||
return data;
|
||||
|
||||
WriteENRSValue(ref ptr, i0 > 0 ? ENR.Sub[i0].Skip -
|
||||
ENR.Sub[i0 - 1].SizeSkip : ENR.Sub[i0].Skip, ENR.Sub[i0].Type);
|
||||
WriteENRSValue(ref ptr, ENR.Sub[i0].Reverse);
|
||||
}
|
||||
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private int length()
|
||||
{
|
||||
int i, i0;
|
||||
int length = 0x10;
|
||||
for (i = 0; i < List.Count; i++)
|
||||
{
|
||||
ENRS ENR = List[i];
|
||||
length += GetSize(i > 0 ? ENR.Offset - List[i - 1].Offset : ENR.Offset);
|
||||
length += GetSize(ENR.Count );
|
||||
length += GetSize(ENR.Size );
|
||||
length += GetSize(ENR.Repeat);
|
||||
|
||||
if (ENR.Repeat < 1) continue;
|
||||
|
||||
for (i0 = 0; i0 < ENR.Count; i0++)
|
||||
{
|
||||
if (ENR.Sub[i0].Type < ENRS.Type. WORD ||
|
||||
ENR.Sub[i0].Type > ENRS.Type.QWORD) return length.Align(0x10);
|
||||
|
||||
length += GetSizeType(i0 > 0 ? ENR.Sub[i0].Skip - ENR.Sub[i0 - 1].SizeSkip : ENR.Sub[i0].Skip);
|
||||
length += GetSize(ENR.Sub[i0].Reverse);
|
||||
}
|
||||
}
|
||||
return length.Align(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 ENRS.Value Value;
|
||||
|
||||
private static int ReadENRSValue(ref byte* ptr, out ENRS.Type Type)
|
||||
{
|
||||
int V = *ptr & 0xF;
|
||||
Type = (ENRS. Type)((*ptr & 0x30) >> 4);
|
||||
Value = (ENRS.Value)((*ptr & 0xC0) >> 6);
|
||||
ptr++;
|
||||
if (Value == ENRS.Value.Int32 )
|
||||
{ V = (V << 24) | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; ptr += 3; }
|
||||
else if (Value == ENRS.Value.Int16 )
|
||||
{ V = (V << 8) | ptr[0]; ptr += 1; }
|
||||
else if (Value == ENRS.Value.Invalid) V = 0;
|
||||
return V;
|
||||
}
|
||||
|
||||
private static int ReadENRSValue(ref byte* ptr)
|
||||
{
|
||||
int V = *ptr & 0x3F;
|
||||
Value = (ENRS.Value)((*ptr & 0xC0) >> 6);
|
||||
ptr++;
|
||||
if (Value == ENRS.Value.Int32 )
|
||||
{ V = (V << 24) | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; ptr += 3; }
|
||||
else if (Value == ENRS.Value.Int16 )
|
||||
{ V = (V << 8) | ptr[0]; ptr += 1; }
|
||||
else if (Value == ENRS.Value.Invalid) V = 0;
|
||||
return V;
|
||||
}
|
||||
|
||||
private static void WriteENRSValue(ref byte* ptr, int Val, ENRS.Type Type)
|
||||
{
|
||||
Value = ENRS.Value.Invalid;
|
||||
if (Val < 0x00000040) Value = ENRS.Value.Int8 ;
|
||||
else if (Val < 0x00004000) Value = ENRS.Value.Int16;
|
||||
else if (Val < 0x40000000) Value = ENRS.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 static void WriteENRSValue(ref byte* ptr, int Val)
|
||||
{
|
||||
Value = ENRS.Value.Invalid;
|
||||
if (Val < 0x00000040) Value = ENRS.Value.Int8 ;
|
||||
else if (Val < 0x00004000) Value = ENRS.Value.Int16;
|
||||
else if (Val < 0x40000000) Value = ENRS.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 ENRS
|
||||
{
|
||||
public int Offset;
|
||||
public int Count;
|
||||
public int Size;
|
||||
public int Repeat;
|
||||
public KKdList<SubENRS> 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 SubENRS
|
||||
{
|
||||
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() =>
|
||||
$"Depth: {Depth}{(NotNull ? $"; ENRS Count: {List.Count}" : "")}";
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
namespace KKdBaseLib.F2
|
||||
{
|
||||
public unsafe struct POF : INull
|
||||
{
|
||||
public int Depth;
|
||||
public KKdList<long> Offsets;
|
||||
|
||||
public bool IsNull => Offsets. IsNull;
|
||||
public bool NotNull => Offsets.NotNull;
|
||||
|
||||
public int Length => length(false).Align(0x10);
|
||||
public int LengthX => length( true).Align(0x10);
|
||||
|
||||
public static POF Read(byte[] data, bool ShiftX, int Depth = 0)
|
||||
{
|
||||
Value Val = 0;
|
||||
KKdList<long> Offsets = KKdList<long>.New;
|
||||
byte* ptr = data.GetPtr();
|
||||
int i = 0, Offset = 0, V = 0;
|
||||
byte BitShift = (byte)(ShiftX ? 3 : 2);
|
||||
|
||||
int Length = *(int*)ptr - 4; ptr += 4;
|
||||
while (Length > i)
|
||||
{
|
||||
V = *ptr & 0x3F;
|
||||
Val = (Value)(*ptr & 0xC0);
|
||||
ptr++; i++;
|
||||
if (Val == Value.Int32 )
|
||||
{ V = (V << 24) | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; ptr += 3; i += 3; }
|
||||
else if (Val == Value.Int16 )
|
||||
{ V = (V << 8) | ptr[0]; ptr += 1; i += 3; }
|
||||
else if (Val == Value.Invalid) break;
|
||||
Offset += V;
|
||||
Offsets.Add(Offset << BitShift);
|
||||
}
|
||||
return new POF { Depth = Depth, Offsets = Offsets };
|
||||
}
|
||||
|
||||
public static byte[] Write(POF POF, bool ShiftX)
|
||||
{
|
||||
POF.Offsets.Sort();
|
||||
long Offset = 0;
|
||||
byte BitShift = (byte)(ShiftX ? 3 : 2);
|
||||
int Max1 = 0x00100 >> BitShift;
|
||||
int Max2 = 0x10000 >> BitShift;
|
||||
|
||||
byte[] data = new byte[POF.Length];
|
||||
byte* ptr = data.GetPtr();
|
||||
|
||||
byte Val = 0;
|
||||
*(int*)ptr = POF.length(ShiftX); ptr += 4;
|
||||
for (int i = 0; i < POF.Offsets.Count; i++)
|
||||
{
|
||||
Offset = POF.Offsets[i];
|
||||
if (i > 0) { Offset -= POF.Offsets[i - 1]; if (Offset == 0) continue; }
|
||||
|
||||
Offset >>= BitShift;
|
||||
Val = (byte)(Offset > Max2 ? Value.Int32 : Offset > Max1 ? Value.Int16 : Value.Int8);
|
||||
if (Offset < Max1) *ptr = (byte)(Val | Offset );
|
||||
else if (Offset < Max2) { *ptr = (byte)(Val | (Offset >> 8)); ptr++;
|
||||
*ptr = (byte) Offset ; }
|
||||
else { *ptr = (byte)(Val | (Offset >> 24)); ptr++;
|
||||
*ptr = (byte) (Offset >> 16) ; ptr++;
|
||||
*ptr = (byte) (Offset >> 8) ; ptr++;
|
||||
*ptr = (byte) Offset ; }
|
||||
ptr++;
|
||||
}
|
||||
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() =>
|
||||
$"Depth: {Depth}{(NotNull ? $"; Offsets Count: {Offsets.Count}" : "")}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
namespace KKdBaseLib.F2
|
||||
{
|
||||
public struct Struct
|
||||
{
|
||||
public Header Header;
|
||||
public byte[] Data;
|
||||
public Struct[] SubStructs;
|
||||
|
||||
public ENRSList 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
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,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
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 implicit 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 implicit 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, Half b) => (float)a + (float)b;
|
||||
public static Half operator - (Half a, Half b) => (float)a - (float)b;
|
||||
public static Half operator * (Half a, Half b) => (float)a * (float)b;
|
||||
public static Half 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 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.ToString((double)this);
|
||||
public string ToString(string format, IFormatProvider formatProvider) =>
|
||||
((float)this).ToString(format, formatProvider);
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public interface IKF
|
||||
{
|
||||
KFT0 ToT0();
|
||||
KFT1 ToT1();
|
||||
KFT2 ToT2();
|
||||
KFT3 ToT3();
|
||||
|
||||
IKF Check();
|
||||
string ToString();
|
||||
string ToString(bool Brackets);
|
||||
}
|
||||
|
||||
public interface INull
|
||||
{
|
||||
bool IsNull { get; }
|
||||
bool NotNull { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
using Type = KKdBaseLib.A3DAKey.KeyType;
|
||||
using EPType = KKdBaseLib.A3DAKey.EPType;
|
||||
|
||||
namespace KKdBaseLib.Interpolation
|
||||
{
|
||||
public struct A3DAI //A3DA Interpolation
|
||||
{
|
||||
private A3DAKey key;
|
||||
|
||||
private float F;
|
||||
private float Last;
|
||||
private float DeltaFrame;
|
||||
private float IF;
|
||||
private float RF;
|
||||
private float LastTime;
|
||||
|
||||
private KFT3 firstKey;
|
||||
private KFT3 lastKey;
|
||||
|
||||
public float InterpolationFramerate
|
||||
{ get => IF; set { IF = value; DeltaFrame = IF / RF; } }
|
||||
public float RequestedFramerate
|
||||
{ get => RF; set { RF = value; DeltaFrame = IF / RF; } }
|
||||
|
||||
public float Frame => F;
|
||||
public float Value => Last;
|
||||
public bool IsNull => key.Keys == null ? true : key.Length < 1;
|
||||
public bool NotNull => key.Keys == null ? false : key.Length > 0;
|
||||
|
||||
public A3DAI(A3DAKey key, float A3DAFramerate = 60, float RequestedFramerate = 60)
|
||||
{
|
||||
LastTime = 0;
|
||||
this.key = key; F = -1; DeltaFrame = Last = RF = IF = 0;
|
||||
IF = A3DAFramerate;
|
||||
firstKey = lastKey = default;
|
||||
this.RequestedFramerate = RequestedFramerate;
|
||||
F = -DeltaFrame;
|
||||
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)key.Type < 1 || (int)key.Type > 4 || key.Length < 1) return 0;
|
||||
if ((int)key.Type == 1) return key.Keys[0].V;
|
||||
|
||||
LastTime = time;
|
||||
F = time * IF;
|
||||
Last = Interpolate(F);
|
||||
return Last;
|
||||
}
|
||||
|
||||
public float SetFrame(float frame)
|
||||
{
|
||||
if ((int)key.Type < 1 || (int)key.Type > 4 || key.Length < 1) return 0;
|
||||
if ((int)key.Type == 1) return key.Keys[0].V;
|
||||
|
||||
LastTime = frame / RF;
|
||||
F = frame * DeltaFrame;
|
||||
Last = Interpolate(F);
|
||||
return Last;
|
||||
}
|
||||
|
||||
public float NextFrame(float time)
|
||||
{
|
||||
if ((int)key.Type < 1 || (int)key.Type > 4 || key.Length < 1) return 0;
|
||||
if ((int)key.Type == 1) return key.Keys[0].V;
|
||||
|
||||
LastTime += time;
|
||||
F = LastTime * IF;
|
||||
Last = Interpolate(F);
|
||||
return Last;
|
||||
}
|
||||
|
||||
public float NextFrame()
|
||||
{
|
||||
if ((int)key.Type < 1 || (int)key.Type > 4 || key.Length < 1) return 0;
|
||||
if ((int)key.Type == 1) return key.Keys[0].V;
|
||||
|
||||
F += DeltaFrame;
|
||||
LastTime = F / IF;
|
||||
Last = Interpolate(F);
|
||||
return Last;
|
||||
}
|
||||
|
||||
private float Interpolate(float frame)
|
||||
{
|
||||
float DF = 0;
|
||||
float EP;
|
||||
float f = (int)frame;
|
||||
if (f < firstKey.F)
|
||||
{
|
||||
DF = firstKey.F - frame;
|
||||
if (key.EPTypePre == EPType.EP_2 || key.EPTypePre == EPType.EP_3)
|
||||
{
|
||||
frame = firstKey.F - DF % key.FDBSaE;
|
||||
f = (int)frame;
|
||||
}
|
||||
else if (key.EPTypePre == EPType.EP_1)
|
||||
return firstKey.V - DF * firstKey.T1;
|
||||
else
|
||||
return firstKey.V;
|
||||
}
|
||||
else if (f >= lastKey.F)
|
||||
{
|
||||
DF = frame - lastKey.F;
|
||||
if (key.EPTypePost == EPType.EP_2 || key.EPTypePost == EPType.EP_3)
|
||||
{
|
||||
frame = firstKey.F + DF % key.FDBSaE;
|
||||
f = (int)frame;
|
||||
}
|
||||
else if (key.EPTypePost == EPType.EP_1)
|
||||
return lastKey.V + DF * lastKey.T2;
|
||||
else
|
||||
return lastKey.V;
|
||||
}
|
||||
|
||||
if ((f < firstKey.F && key.EPTypePre == EPType.EP_3) ||
|
||||
(f >= firstKey.F && key.EPTypePost == EPType.EP_3))
|
||||
{
|
||||
EP = DF / key.FDBSaE;
|
||||
EP = (EP >= 0 && (int)EP != EP) ? ((int)EP - EP < 0 ? 1 : 0) : EP;
|
||||
|
||||
if (f < firstKey.F)
|
||||
EP = -(EP + 1) * key.VDBSaE;
|
||||
else
|
||||
EP = (EP + 1) * key.VDBSaE;
|
||||
}
|
||||
else
|
||||
EP = 0;
|
||||
|
||||
int data = 0;
|
||||
int length = key.Length;
|
||||
while (length > 0)
|
||||
if (f <= key.Keys[data + (length >> 1)].F)
|
||||
length >>= 1;
|
||||
else
|
||||
{
|
||||
int delta = (length >> 1) + 1;
|
||||
data += delta;
|
||||
length -= delta;
|
||||
}
|
||||
|
||||
if (data == 0)
|
||||
return firstKey.V + EP;
|
||||
else if (data >= key.Length)
|
||||
return lastKey.V + EP;
|
||||
|
||||
KFT3 c = key.Keys[data - 1];
|
||||
KFT3 n = key.Keys[data];
|
||||
float result = c.F == n.F ? c.V : n.V;
|
||||
if (key.Type == Type.Lerp)
|
||||
{
|
||||
if (frame < n.F)
|
||||
{
|
||||
float t = (frame - c.F) / (n.F - c.F);
|
||||
result = (1 - t) * c.V + t * n.V;
|
||||
}
|
||||
}
|
||||
else if (key.Type == Type.Hermite)
|
||||
{
|
||||
if (frame < n.F)
|
||||
{
|
||||
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 if (key.Type == Type.Hold)
|
||||
{
|
||||
if (frame < n.F)
|
||||
result = c.V;
|
||||
}
|
||||
else
|
||||
return EP;
|
||||
return result + EP;
|
||||
}
|
||||
|
||||
public void ResetFrameCount() => F = -DeltaFrame;
|
||||
|
||||
public override string ToString() => $"Frame: {F}, Value: {Value}";
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
namespace KKdBaseLib.Interpolation
|
||||
{
|
||||
public struct PDI : IInterpolation //Project DIVA Interpolation
|
||||
{
|
||||
private KFT2[] Array;
|
||||
|
||||
private float F;
|
||||
private float Last;
|
||||
private float DeltaFrame;
|
||||
private float IF;
|
||||
private float RF;
|
||||
private float LastTime;
|
||||
|
||||
private KFT2 firstKey;
|
||||
private KFT2 lastKey;
|
||||
|
||||
public float InterpolationFramerate
|
||||
{ get => IF; set { IF = value; DeltaFrame = IF / RF; } }
|
||||
public float RequestedFramerate
|
||||
{ get => RF; set { RF = value; DeltaFrame = 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, bool Loop, float InterpolationFramerate = 60, float RequestedFramerate = 60)
|
||||
{
|
||||
LastTime = 0;
|
||||
this.Array = Array; F = -1; DeltaFrame = Last = RF = IF = 0;
|
||||
IF = InterpolationFramerate;
|
||||
firstKey = lastKey = default;
|
||||
this.RequestedFramerate = RequestedFramerate;
|
||||
F = -DeltaFrame;
|
||||
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 * DeltaFrame;
|
||||
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 += DeltaFrame;
|
||||
LastTime = F / IF;
|
||||
Last = Interpolate(F);
|
||||
return Last;
|
||||
}
|
||||
|
||||
private float Interpolate(float frame)
|
||||
{
|
||||
float f = (int)frame;
|
||||
|
||||
int data = 0;
|
||||
int length = Array.Length;
|
||||
while (length > 0)
|
||||
if (f <= Array[data + (length >> 1)].F)
|
||||
length >>= 1;
|
||||
else
|
||||
{
|
||||
int delta = (length >> 1) + 1;
|
||||
data += delta;
|
||||
length -= delta;
|
||||
}
|
||||
|
||||
if (data == 0)
|
||||
return firstKey.V;
|
||||
else if (data >= Array.Length)
|
||||
return lastKey.V;
|
||||
|
||||
KFT2 c = Array[data - 1];
|
||||
KFT2 n = Array[data];
|
||||
float result = c.F == n.F ? c.V : n.V;
|
||||
if (frame < n.F)
|
||||
{
|
||||
|
||||
float t = (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 * (F - c.F) + c.V;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void ResetFrameCount() => F = -DeltaFrame;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct KFT0 : IKF
|
||||
{
|
||||
public float F;
|
||||
|
||||
public KFT0(float F = 0)
|
||||
{ this.F = F; }
|
||||
|
||||
public KFT0 ToT0() => this;
|
||||
public KFT1 ToT1() => this;
|
||||
public KFT2 ToT2() => this;
|
||||
public KFT3 ToT3() => this;
|
||||
|
||||
public IKF Check() => this;
|
||||
|
||||
public override string ToString() => ToString(true);
|
||||
public string ToString(bool Brackets = true) =>
|
||||
Extensions.ToString(F);
|
||||
|
||||
public static implicit operator KFT1(KFT0 KF) =>
|
||||
new KFT1(KF.F);
|
||||
public static implicit operator KFT2(KFT0 KF) =>
|
||||
new KFT2(KF.F);
|
||||
public static implicit operator KFT3(KFT0 KF) =>
|
||||
new KFT3(KF.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() => this;
|
||||
public KFT1 ToT1() => this;
|
||||
public KFT2 ToT2() => this;
|
||||
public KFT3 ToT3() => this;
|
||||
|
||||
public IKF Check() =>
|
||||
V == 0 ? (KFT0)this : (IKF)this;
|
||||
|
||||
public override string ToString() => ToString(true);
|
||||
public string ToString(bool Brackets = true) =>
|
||||
(Brackets ? "(" : "") + Extensions.ToString(F) + "," +
|
||||
Extensions.ToString(V) + (Brackets ? ")" : "");
|
||||
|
||||
public static implicit operator KFT0(KFT1 KF) =>
|
||||
new KFT0(KF.F);
|
||||
public static implicit operator KFT2(KFT1 KF) =>
|
||||
new KFT2(KF.F, KF.V);
|
||||
public static implicit operator KFT3(KFT1 KF) =>
|
||||
new KFT3(KF.F, KF.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() => this;
|
||||
public KFT1 ToT1() => this;
|
||||
public KFT2 ToT2() => this;
|
||||
public KFT3 ToT3() => this;
|
||||
|
||||
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)(KFT0)this : (KFT1)this) : this;
|
||||
|
||||
public override string ToString() => ToString(true);
|
||||
public string ToString(bool Brackets) =>
|
||||
(Brackets ? "(" : "") + Extensions.ToString(F) + "," + Extensions.
|
||||
ToString(V) + "," + Extensions.ToString(T) + (Brackets ? ")" : "");
|
||||
|
||||
public static implicit operator KFT0(KFT2 KF) =>
|
||||
new KFT0(KF.F);
|
||||
public static implicit operator KFT1(KFT2 KF) =>
|
||||
new KFT1(KF.F, KF.V);
|
||||
public static implicit operator KFT3(KFT2 KF) =>
|
||||
new KFT3(KF.F, KF.V, KF.T, KF.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() => this;
|
||||
public KFT1 ToT1() => this;
|
||||
public KFT2 ToT2() => this;
|
||||
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);
|
||||
public string ToString(bool Brackets) =>
|
||||
(Brackets ? "(" : "") + Extensions.ToString(F) + "," + Extensions.ToString(V) + "," +
|
||||
Extensions.ToString(T1) + "," + Extensions.ToString(T2) + (Brackets ? ")" : "");
|
||||
|
||||
public static implicit operator KFT0(KFT3 KF) =>
|
||||
new KFT0(KF.F);
|
||||
public static implicit operator KFT1(KFT3 KF) =>
|
||||
new KFT1(KF.F, KF.V);
|
||||
public static implicit operator KFT2(KFT3 KF) =>
|
||||
new KFT2(KF.F, KF.V, KF.T1);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?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>{437F63F1-8C23-429E-AB14-38B85C9EDB16}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>KKdBaseLib</RootNamespace>
|
||||
<AssemblyName>KKdBaseLib</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</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>
|
||||
<ItemGroup>
|
||||
<Compile Include="F2\ENRS.cs" />
|
||||
<Compile Include="F2\Header.cs" />
|
||||
<Compile Include="F2\POF.cs" />
|
||||
<Compile Include="F2\Struct.cs" />
|
||||
<Compile Include="Interpolation\A3DAI.cs" />
|
||||
<Compile Include="Interpolation\IInterpolation.cs" />
|
||||
<Compile Include="Interpolation\PDI.cs" />
|
||||
<Compile Include="A3DA.cs" />
|
||||
<Compile Include="A3DAKey.cs" />
|
||||
<Compile Include="Aet.cs" />
|
||||
<Compile Include="DCC.cs" />
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="Format.cs" />
|
||||
<Compile Include="Half.cs" />
|
||||
<Compile Include="Interfaces.cs" />
|
||||
<Compile Include="KF.cs" />
|
||||
<Compile Include="KKdList.cs" />
|
||||
<Compile Include="MsgPack.cs" />
|
||||
<Compile Include="Pointer.cs" />
|
||||
<Compile Include="Text.cs" />
|
||||
<Compile Include="Vector.cs" />
|
||||
<Compile Include="Vector3.cs" />
|
||||
<Compile Include="Vector4.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>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -0,0 +1,115 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct KKdList<T> : System.IDisposable, IEnumerator, IEnumerable, 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 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];
|
||||
if (Count >= value) Count = 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 && 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 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 + 1; i < Count; i++)
|
||||
array[i - 1] = array[i];
|
||||
Count--;
|
||||
}
|
||||
|
||||
public void RemoveRange(int IndexStart, int IndexEnd)
|
||||
{
|
||||
if (IsNull) return;
|
||||
if (IndexEnd - IndexStart < 1) return;
|
||||
|
||||
if (IndexEnd - IndexStart != Count)
|
||||
for (int i = IndexStart; i < Count; i++)
|
||||
array[i] = array[i + IndexEnd - IndexStart];
|
||||
Count -= 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 (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 = this; List.Sort(); array = List.ToArray(); Count = List.Count; }
|
||||
|
||||
public static implicit operator KKdList<T>( List<T> List) =>
|
||||
new KKdList<T> { array = List.ToArray(), Count = List.Count };
|
||||
|
||||
public static implicit operator List<T>(KKdList<T> List)
|
||||
{
|
||||
List<T> list = new List<T>();
|
||||
for (int i = 0; i < List.Count; i++) list.Add(List[i]);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,356 @@
|
||||
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; 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 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; }
|
||||
|
||||
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) { 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 Val, bool? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, sbyte? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, byte? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, short? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, ushort? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, int? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, uint? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, long? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, ulong? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, float? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, double? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
|
||||
public MsgPack Add(string Val, byte[] val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, string val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, bool val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, sbyte val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, byte val) => Add(new MsgPack(Val, val));
|
||||
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 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 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct Pointer<T>
|
||||
{
|
||||
public int O;
|
||||
public T V;
|
||||
|
||||
public override string ToString() => Extensions.ToString(V);
|
||||
|
||||
public Pointer(T value)
|
||||
{ O = 0; V = value; }
|
||||
|
||||
public Pointer(int 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("KKdBaseLib")]
|
||||
[assembly: AssemblyDescription("A base library")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("KKdBaseLib")]
|
||||
[assembly: AssemblyCopyright("korenkonder © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("437F63F1-8C23-429E-AB14-38B85C9EDB16")]
|
||||
[assembly: AssemblyVersion("0.4.7.6")]
|
||||
[assembly: AssemblyFileVersion("0.4.7.6")]
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Text;
|
||||
|
||||
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 ?? "" );
|
||||
public static byte[] ToUTF8 (this string Data ) => Encoding.UTF8 .GetBytes (Data ?? "" );
|
||||
public static byte[] ToASCII(this char[] Data ) => Encoding.ASCII.GetBytes (Data ?? new char[0]);
|
||||
public static byte[] ToUTF8 (this char[] Data ) => Encoding.UTF8 .GetBytes (Data ?? new char[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct Vector2<T> : INull
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
|
||||
public Vector2(T X, T Y)
|
||||
{ this.X = X; this.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)
|
||||
{ this.X = X; this.Y = Y; this.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)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; this.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})";
|
||||
}
|
||||
}
|
||||
@@ -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.Equals(B);
|
||||
public static bool operator !=(Vector3 A, Vector3 B) => !A.Equals(B);
|
||||
|
||||
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)})";
|
||||
}
|
||||
}
|
||||
@@ -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)})";
|
||||
}
|
||||
}
|
||||
+2419
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,419 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.A3DA
|
||||
{
|
||||
public static class A3DAExt
|
||||
{
|
||||
private const string d = ".";
|
||||
private const string BO = "bin_offset";
|
||||
private const string MTBO = "model_transform" + d + BO;
|
||||
|
||||
private static string value;
|
||||
private static string[] dataArray;
|
||||
private static int SOi;
|
||||
private static int[] SO;
|
||||
|
||||
public static ModelTransform ReadMT(this Dictionary<string, object> Dict, string Temp)
|
||||
{
|
||||
ModelTransform MT = new ModelTransform();
|
||||
Dict.FindValue(out MT.BinOffset, Temp + MTBO);
|
||||
|
||||
MT.Rot = Dict.ReadVec3(Temp + "rot" + d);
|
||||
MT.Scale = Dict.ReadVec3(Temp + "scale" + d);
|
||||
MT.Trans = Dict.ReadVec3(Temp + "trans" + d);
|
||||
MT.Visibility = Dict.ReadKey (Temp + "visibility" + d);
|
||||
return MT;
|
||||
}
|
||||
|
||||
public static RGBAKey ReadRGBAKey(this Dictionary<string, object> Dict, string Temp) =>
|
||||
new RGBAKey { A = Dict.ReadKey(Temp + "a" + d), B = Dict.ReadKey(Temp + "b" + d),
|
||||
G = Dict.ReadKey(Temp + "g" + d), R = Dict.ReadKey(Temp + "r" + d) };
|
||||
|
||||
public static Vector3<Key> ReadVec3(this Dictionary<string, object> Dict, string Temp) =>
|
||||
new Vector3<Key> { X = Dict.ReadKey(Temp + "x" + d), Y =
|
||||
Dict.ReadKey(Temp + "y" + d), Z = Dict.ReadKey(Temp + "z" + d) };
|
||||
|
||||
public static KeyUV ReadKeyUV(this Dictionary<string, object> Dict, string Temp) =>
|
||||
new KeyUV { U = Dict.ReadKey(Temp + "U" + d), V = Dict.ReadKey(Temp + "V" + d) };
|
||||
|
||||
public static Key ReadKey(this Dictionary<string, object> Dict, string Temp)
|
||||
{
|
||||
Key Key = new Key();
|
||||
Dict.FindValue(out Key.BinOffset, Temp + BO );
|
||||
Dict.FindValue(out Key.Type , Temp + "type");
|
||||
|
||||
if (Key.BinOffset == null && Key.Type == null) return null;
|
||||
if (Key.Type == null) return Key;
|
||||
if (Key.Type == 0x0000) return Key;
|
||||
|
||||
if (Key.Type == 0x0001) { Dict.FindValue(out Key.Value, Temp + "value"); return Key; }
|
||||
|
||||
int i = 0, i0 = 0;
|
||||
byte i1 = 0;
|
||||
Dict.FindValue(out Key.EPTypePost, Temp + "ep_type_post");
|
||||
Dict.FindValue(out Key.EPTypePre , Temp + "ep_type_pre" );
|
||||
Dict.FindValue(out Key.Length , Temp + "key.length" );
|
||||
Dict.FindValue(out Key.Max , Temp + "max" );
|
||||
if (Dict.StartsWith(Temp + "raw_data"))
|
||||
Dict.FindValue(out Key.RawData.KeyType, Temp + "raw_data_key_type");
|
||||
|
||||
if (Key.Length != null)
|
||||
{
|
||||
Key.Trans = new Key.Transform[(int)Key.Length];
|
||||
for (i0 = 0; i0 < Key.Length; i0++)
|
||||
if (Dict.FindValue(out value, Temp + "key" + d + i0 + d + "data"))
|
||||
{
|
||||
Key.Trans[i0] = new Key.Transform();
|
||||
dataArray = value.Replace("(", "").Replace(")", "").Split(',');
|
||||
Key.Trans[i0].Type = dataArray.Length - 1;
|
||||
Key.Trans[i0].Frame = dataArray[0].ToDouble();
|
||||
Key.Trans[i0].Value = new double[Key.Trans[i0].Type];
|
||||
for (i1 = 1; i1 < dataArray.Length; i1++)
|
||||
Key.Trans[i0].Value[i1 - 1] = dataArray[i1].ToDouble();
|
||||
}
|
||||
}
|
||||
else if (Key.RawData.KeyType != null)
|
||||
{
|
||||
Key.RawData = new Key.RawD();
|
||||
Dict.FindValue(out Key.RawData.ValueType, Temp + "raw_data.value_type");
|
||||
if (Dict.FindValue(out value, Temp + "raw_data.value_list"))
|
||||
Key.RawData.ValueList = value.Split(',');
|
||||
Dict.FindValue(out Key.RawData.ValueListSize, Temp + "raw_data.value_list_size");
|
||||
value = "";
|
||||
|
||||
int DataSize = (int)Key.RawData.KeyType + 1;
|
||||
Key.Length = Key.RawData.ValueListSize / DataSize;
|
||||
Key.Trans = new Key.Transform[(int)Key.Length];
|
||||
for (i = 0; i < Key.Length; i++)
|
||||
{
|
||||
Key.Trans[i].Type = (int)Key.RawData.KeyType;
|
||||
Key.Trans[i].Frame = Key.RawData.ValueList[i * DataSize + 0].ToDouble();
|
||||
Key.Trans[i].Value = new double[Key.Trans[i0].Type];
|
||||
for (i1 = 1; i1 < Key.Trans[i].Type; i1++)
|
||||
Key.Trans[i].Value[i1 - 1] = Key.RawData.ValueList[i * DataSize + i1].ToDouble();
|
||||
}
|
||||
Key.RawData.ValueList = null;
|
||||
}
|
||||
return Key;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ModelTransform MT,
|
||||
string Temp, bool A3DC, bool IsX = false, byte Flags = 0b11111)
|
||||
{
|
||||
if (A3DC && !MT.Writed && (Flags & 0b10000) == 0b10000)
|
||||
{ IO.Write(Temp + MTBO + "=", MT.BinOffset); MT.Writed = true; }
|
||||
|
||||
if (A3DC) return;
|
||||
|
||||
if ((Flags & 0b01000) == 0b01000) IO.Write(MT.Rot , Temp + "rot" + d, A3DC);
|
||||
if ((Flags & 0b00100) == 0b00100) IO.Write(MT.Scale , Temp + "scale" + d, A3DC);
|
||||
if ((Flags & 0b00010) == 0b00010) IO.Write(MT.Trans , Temp + "trans" + d, A3DC);
|
||||
if ((Flags & 0b00001) == 0b00001) IO.Write(MT.Visibility, Temp + "visibility" + d, A3DC);
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, RGBAKey RGBA, string Temp, string Data, bool A3DC = false)
|
||||
{
|
||||
if (RGBA.R == null && RGBA.B == null && RGBA.G == null && RGBA.A == null) return;
|
||||
IO.Write(Temp + Data + "=", "true");
|
||||
IO.Write(RGBA.A, Temp + Data + d + "a" + d, A3DC); IO.Write(RGBA.B, Temp + Data + d + "b" + d, A3DC);
|
||||
IO.Write(RGBA.G, Temp + Data + d + "g" + d, A3DC); IO.Write(RGBA.R, Temp + Data + d + "r" + d, A3DC);
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, Vector3<Key> Key, string Temp, bool A3DC = false)
|
||||
{ IO.Write(Key.X, Temp + "x" + d, A3DC); IO.Write(Key.Y,
|
||||
Temp + "y" + d, A3DC); IO.Write(Key.Z, Temp + "z" + d, A3DC); }
|
||||
|
||||
public static void Write(this Stream IO, KeyUV UV, string Temp, string Data, bool A3DC = false)
|
||||
{ IO.Write(UV.U, Temp, Data + "U", A3DC); IO.Write(UV.V, Temp, Data + "V", A3DC); }
|
||||
|
||||
public static void Write(this Stream IO, Key Key, string Temp, string Data, bool A3DC = false)
|
||||
{ if (Key != null) { IO.Write(Temp + Data + "=", "true"); IO.Write(Key, Temp + Data + d, A3DC); } }
|
||||
|
||||
public static void Write(this Stream IO, Key Key, string Temp, bool A3DC = false)
|
||||
{
|
||||
if (Key == null) return;
|
||||
|
||||
if (A3DC) { IO.Write(Temp + BO + "=", Key.BinOffset); return; }
|
||||
|
||||
int i = 0;
|
||||
if (Key.Trans != null)
|
||||
if (Key.Trans.Length == 0)
|
||||
{
|
||||
IO.Write(Temp + "type=", Key.Type);
|
||||
if (Key.Type > 0) IO.Write(Temp + "value=", Key.Value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Key.EPTypePost != null) IO.Write(Temp + "ep_type_post=", Key.EPTypePost);
|
||||
if (Key.EPTypePre != null) IO.Write(Temp + "ep_type_pre=" , Key.EPTypePre );
|
||||
if (Key.RawData == null && Key.Trans != null)
|
||||
{
|
||||
SO = Key.Trans.Length.SortWriter();
|
||||
for (i = 0; i < Key.Trans.Length; i++)
|
||||
{
|
||||
SOi = SO[i];
|
||||
IO.Write(Temp + "key" + d + SOi + d + "data=", Key.Trans[SOi].ToString());
|
||||
IO.Write(Temp + "key" + d + SOi + d + "type=", Key.Trans[SOi].Type );
|
||||
}
|
||||
IO.Write(Temp + "key.length=", Key.Length);
|
||||
if (Key.Max != null) IO.Write(Temp + "max=", Key.Max);
|
||||
}
|
||||
else if (Key.Trans != null)
|
||||
{
|
||||
if (Key.Max != null) IO.Write(Temp + "max=", Key.Max);
|
||||
for (i = 0; i < Key.Trans.Length; i++)
|
||||
{
|
||||
if (Key.RawData.KeyType < Key.Trans[i].Type || Key.RawData.KeyType == null)
|
||||
Key.RawData.KeyType = Key.Trans[i].Type;
|
||||
if (Key.RawData.KeyType == 3) break;
|
||||
}
|
||||
Key.RawData.ValueListSize = Key.Trans.Length * (Key.RawData.KeyType + 1);
|
||||
IO.Write(Temp + "raw_data.value_list=");
|
||||
for (i = 0; i < Key.Trans.Length; i++)
|
||||
IO.Write(Key.Trans[i].ToString(false));
|
||||
IO.Position = IO.Position - 1;
|
||||
IO.Write('\n');
|
||||
IO.Write(Temp + "raw_data.value_list_size=", Key.RawData.ValueListSize);
|
||||
IO.Write(Temp + "raw_data.value_type=" , Key.RawData.ValueType );
|
||||
IO.Write(Temp + "raw_data_key_type=" , Key.RawData. KeyType );
|
||||
}
|
||||
IO.Write(Temp + "type=", Key.Type & 0xFF);
|
||||
if (Key.RawData == null && Key.Trans == null && Key.Value != null)
|
||||
if (Key.Value != 0) IO.Write(Temp + "value=", Key.Value);
|
||||
}
|
||||
|
||||
public static void ReadMT(this Stream IO, ref ModelTransform MT, int C_F16)
|
||||
{
|
||||
if (MT.BinOffset == null) return;
|
||||
|
||||
IO.Position = (int)MT.BinOffset;
|
||||
|
||||
IO.ReadOffset(out MT.Scale);
|
||||
IO.ReadOffset(out MT.Rot );
|
||||
IO.ReadOffset(out MT.Trans);
|
||||
MT.Visibility = new Key { BinOffset = IO.ReadInt32() };
|
||||
|
||||
IO.ReadVec3(ref MT.Scale , C_F16);
|
||||
IO.ReadVec3(ref MT.Rot , C_F16, true);
|
||||
IO.ReadVec3(ref MT.Trans , C_F16);
|
||||
IO.ReadKey (ref MT.Visibility, C_F16);
|
||||
}
|
||||
|
||||
public static void ReadRGBAKey(this Stream IO, ref RGBAKey RGBA, int C_F16)
|
||||
{ IO.ReadKey(ref RGBA.R, C_F16); IO.ReadKey(ref RGBA.G, C_F16);
|
||||
IO.ReadKey(ref RGBA.B, C_F16); IO.ReadKey(ref RGBA.A, C_F16); }
|
||||
|
||||
public static void ReadVec3(this Stream IO, ref Vector3<Key> Key, int C_F16, bool F16 = false)
|
||||
{ IO.ReadKey(ref Key.X, C_F16, F16); IO.ReadKey(ref Key.Y,
|
||||
C_F16, F16); IO.ReadKey(ref Key.Z, C_F16, F16); }
|
||||
|
||||
public static void ReadKeyUV(this Stream IO, ref KeyUV UV, int C_F16)
|
||||
{ IO.ReadKey(ref UV.U, C_F16); IO.ReadKey(ref UV.V, C_F16); }
|
||||
|
||||
public static void ReadKey(this Stream IO, ref Key Key, int C_F16, bool F16 = false)
|
||||
{
|
||||
if (Key == null) return;
|
||||
if (Key.BinOffset == null || Key.BinOffset < 0) return;
|
||||
|
||||
IO.Position = (int)Key.BinOffset;
|
||||
Key.Type = IO.ReadInt32();
|
||||
|
||||
Key.Value = IO.ReadSingle();
|
||||
if (Key.Type == 0x0000 || Key.Type == 0x0001) return;
|
||||
|
||||
Key.Max = IO.ReadSingle();
|
||||
Key.Length = IO.ReadInt32 ();
|
||||
Key.Trans = new Key.Transform[(int)Key.Length];
|
||||
int Ke = (int)Key.Length;
|
||||
for (int i = 0; i < Key.Length; i++)
|
||||
{
|
||||
Key.Trans[i] = new Key.Transform { Type = 3, Value = new double[3] };
|
||||
if (F16 && C_F16 > 0)
|
||||
{ Key.Trans[i].Frame = IO.ReadUInt16(); Key.Trans[i].Value[0] = (double)IO.ReadHalf (); }
|
||||
else
|
||||
{ Key.Trans[i].Frame = IO.ReadSingle(); Key.Trans[i].Value[0] = IO.ReadSingle(); }
|
||||
|
||||
if (F16 && C_F16 == 2)
|
||||
{ Key.Trans[i].Value[1] = (double)IO.ReadHalf ();
|
||||
Key.Trans[i].Value[2] = (double)IO.ReadHalf (); }
|
||||
else
|
||||
{ Key.Trans[i].Value[1] = IO.ReadSingle();
|
||||
Key.Trans[i].Value[2] = IO.ReadSingle(); }
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReadOffset(this Stream IO, out Vector3<Key> Key)
|
||||
{ Key = new Vector3<Key> { X = new Key { BinOffset = IO.ReadInt32() },
|
||||
Y = new Key { BinOffset = IO.ReadInt32() },
|
||||
Z = new Key { BinOffset = IO.ReadInt32() }, }; }
|
||||
|
||||
public static void WriteOffset(this Stream IO, ref ModelTransform MT, bool ReturnToOffset)
|
||||
{
|
||||
if (ReturnToOffset)
|
||||
{
|
||||
IO.Position = (int)MT.BinOffset;
|
||||
IO.WriteOffset(MT.Scale);
|
||||
IO.WriteOffset(MT.Rot );
|
||||
IO.WriteOffset(MT.Trans);
|
||||
IO.Write(MT.Visibility.BinOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
MT.BinOffset = IO.Position;
|
||||
IO.Position += 0x30;
|
||||
IO.Length += 0x30;
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteOffset(this Stream IO, Vector3<Key> Key)
|
||||
{
|
||||
IO.Write(Key.X.BinOffset);
|
||||
IO.Write(Key.Y.BinOffset);
|
||||
IO.Write(Key.Z.BinOffset);
|
||||
}
|
||||
|
||||
public static ModelTransform ReadMT(this MsgPack k, string name)
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadMT(); return new ModelTransform(); }
|
||||
|
||||
public static ModelTransform ReadMT(this MsgPack k) =>
|
||||
new ModelTransform { Rot = k.ReadVec3("Rot" ), Scale = k.ReadVec3("Scale" ),
|
||||
Trans = k.ReadVec3("Trans"), Visibility = k.ReadKey ("Visibility") };
|
||||
|
||||
public static RGBAKey ReadRGBAKey(this MsgPack k, string name)
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadRGBAKey(); return new RGBAKey(); }
|
||||
|
||||
public static RGBAKey ReadRGBAKey(this MsgPack k) =>
|
||||
new RGBAKey { R = k.ReadKey("R"), G = k.ReadKey("G"), B = k.ReadKey("B"), A = k.ReadKey("A") };
|
||||
|
||||
public static Vector3<Key> ReadVec3(this MsgPack k, string name)
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadVec3(); return new Vector3<Key>(); }
|
||||
|
||||
public static Vector3<Key> ReadVec3(this MsgPack k) =>
|
||||
new Vector3<Key> { X = k.ReadKey("X"), Y = k.ReadKey("Y"), Z = k.ReadKey("Z") };
|
||||
|
||||
public static KeyUV ReadKeyUV(this MsgPack k, string name)
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadKeyUV(); return new KeyUV(); }
|
||||
|
||||
public static KeyUV ReadKeyUV(this MsgPack k) =>
|
||||
new KeyUV { U = k.ReadKey("U"), V = k.ReadKey("V") };
|
||||
|
||||
public static Key ReadKey(this MsgPack k, string name)
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadKey(); return null; }
|
||||
|
||||
public static Key ReadKey(this MsgPack k)
|
||||
{
|
||||
if (k == null) return null;
|
||||
|
||||
Key Key = new Key { EPTypePost = k.ReadNDouble("Post"),
|
||||
EPTypePre = k.ReadNDouble("Pre"), Max = k.ReadNDouble("M"),
|
||||
Type = k.ReadNInt32("T"), Value = k.ReadNDouble("V") };
|
||||
if (k.ReadBoolean("RD")) Key.RawData = new Key.RawD();
|
||||
if (Key.Type == 0) Key.Value = 0.0;
|
||||
|
||||
if (Key.Type < 2) return Key;
|
||||
|
||||
if (!k.Element<MsgPack>("Trans", out MsgPack Trans)) return Key;
|
||||
|
||||
Key.Length = Trans.Array.Length;
|
||||
Key.Trans = new Key.Transform[Key.Length.Value];
|
||||
byte i1 = 0;
|
||||
for (int i = 0; i < Key.Length; i++)
|
||||
{
|
||||
Key.Trans[i] = new Key.Transform();
|
||||
if (Trans[i] is MsgPack _Trans)
|
||||
{
|
||||
if (_Trans.Array == null) continue;
|
||||
Key.Trans[i].Type = _Trans.Array.Length - 1;
|
||||
Key.Trans[i].Value = new double[Key.Trans[i].Type];
|
||||
|
||||
Key.Trans[i].Frame = (_Trans[0] as MsgPack).ReadDouble();
|
||||
|
||||
for (i1 = 0; i1 < Key.Trans[i].Type; i1++)
|
||||
Key.Trans[i].Value[i1] = ((MsgPack)_Trans[i1 + 1]).ReadDouble();
|
||||
}
|
||||
}
|
||||
return Key;
|
||||
}
|
||||
|
||||
public static MsgPack WriteMP(this ModelTransform MT, string name) =>
|
||||
MT.WriteMP(new MsgPack(name));
|
||||
|
||||
public static MsgPack WriteMP(this ModelTransform MT) =>
|
||||
MT.WriteMP(new MsgPack( ));
|
||||
|
||||
public static MsgPack WriteMP(this ModelTransform MT, MsgPack MTs) =>
|
||||
MTs.Add(MT.Rot .WriteMP("Rot" ))
|
||||
.Add(MT.Scale .WriteMP("Scale" ))
|
||||
.Add(MT.Trans .WriteMP("Trans" ))
|
||||
.Add(MT.Visibility.WriteMP("Visibility"));
|
||||
|
||||
public static MsgPack WriteMP(this RGBAKey RGBA, string name)
|
||||
{
|
||||
if (RGBA.R == null && RGBA.G == null && RGBA.B == null && RGBA.A == null) return MsgPack.Null;
|
||||
return new MsgPack(name).Add(RGBA.R.WriteMP("R")).Add(RGBA.G.WriteMP("G"))
|
||||
.Add(RGBA.B.WriteMP("B")).Add(RGBA.A.WriteMP("A"));
|
||||
}
|
||||
|
||||
public static MsgPack WriteMP(this Vector3<Key> Key, string name) =>
|
||||
new MsgPack(name).Add(Key.X.WriteMP("X")).Add(Key.Y.WriteMP("Y")).Add(Key.Z.WriteMP("Z"));
|
||||
|
||||
public static MsgPack WriteMP(this KeyUV UV, string name)
|
||||
{
|
||||
if (UV.U == null && UV.V == null) return MsgPack.Null;
|
||||
return new MsgPack(name).Add(UV.U.WriteMP("U")).Add(UV.V.WriteMP("V"));
|
||||
}
|
||||
|
||||
public static MsgPack WriteMP(this Key Key, string name)
|
||||
{
|
||||
if (Key == null) return MsgPack.Null;
|
||||
if (Key.Type == null) return MsgPack.Null;
|
||||
|
||||
MsgPack Keys = new MsgPack(name).Add("T", Key.Type);
|
||||
if (Key.Trans != null)
|
||||
{
|
||||
Keys.Add("Post", Key.EPTypePost).Add("Pre", Key.EPTypePre).Add("M", Key.Max);
|
||||
|
||||
if (Key.RawData != null) Keys.Add("RD", true);
|
||||
|
||||
byte i0 = 0;
|
||||
MsgPack Trans = new MsgPack("Trans", Key.Trans.Length);
|
||||
for (int i = 0; i < Key.Trans.Length; i++)
|
||||
{
|
||||
MsgPack K = new MsgPack(Key.Trans[i].Type + 1);
|
||||
K[0] = Key.Trans[i].Frame;
|
||||
for (i0 = 1; i0 < Key.Trans[i].Type + 1; i0++)
|
||||
K[i0] = Key.Trans[i].Value[i0 - 1];
|
||||
Trans[i] = K;
|
||||
}
|
||||
Keys.Add(Trans);
|
||||
}
|
||||
else if (Key.Value != 0) Keys.Add("V", Key.Value);
|
||||
return Keys;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, string Data, ref bool? val)
|
||||
{ if (val != null) IO.Write(Data, ( bool)val ); }
|
||||
public static void Write(this Stream IO, string Data, long? val)
|
||||
{ if (val != null) IO.Write(Data, ( long)val ); }
|
||||
public static void Write(this Stream IO, string Data, ulong? val)
|
||||
{ if (val != null) IO.Write(Data, ( ulong)val ); }
|
||||
public static void Write(this Stream IO, string Data, double? val)
|
||||
{ if (val != null) IO.Write(Data, (double)val ); }
|
||||
public static void Write(this Stream IO, string Data, double? val, byte r)
|
||||
{ if (val != null) IO.Write(Data, (double)val, r); }
|
||||
public static void Write(this Stream IO, string Data, ref bool val) =>
|
||||
IO.Write(Data, Main.ToString(val));
|
||||
public static void Write(this Stream IO, string Data, long val) =>
|
||||
IO.Write(Data, val.ToString( ));
|
||||
public static void Write(this Stream IO, string Data, ulong val) =>
|
||||
IO.Write(Data, val.ToString( ));
|
||||
public static void Write(this Stream IO, string Data, double val) =>
|
||||
IO.Write(Data, val.ToString( ));
|
||||
public static void Write(this Stream IO, string Data, double val, byte r) =>
|
||||
IO.Write(Data, val.ToString(r ));
|
||||
public static void Write(this Stream IO, string Data, string val)
|
||||
{ if (val != null) IO.Write((Data + val + "\n").ToUTF8()); }
|
||||
}
|
||||
}
|
||||
+1019
File diff suppressed because it is too large
Load Diff
@@ -1,980 +0,0 @@
|
||||
//Original: AetSet.bt Version: 2.0 by samyuu
|
||||
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.Aet
|
||||
{
|
||||
public class Aet
|
||||
{
|
||||
public Aet()
|
||||
{ AET = new AetHeader(); i = i0 = 0; IO = null; }
|
||||
|
||||
public AetHeader AET;
|
||||
|
||||
private int i, i0;
|
||||
private Stream IO;
|
||||
|
||||
private const string x00 = "\0";
|
||||
|
||||
public void AETReader(string file)
|
||||
{
|
||||
IO = File.OpenReader(file + ".bin", true);
|
||||
|
||||
AET.MAIN = IO.ReadPointer<AetData>();
|
||||
AET.TOUCH = IO.ReadPointer<AetData>();
|
||||
if (AET.MAIN.Offset > 0)
|
||||
{
|
||||
AETReader(ref AET.MAIN);
|
||||
if (AET.TOUCH.Offset > 0)
|
||||
AETReader(ref AET.TOUCH);
|
||||
}
|
||||
|
||||
IO.Close();
|
||||
}
|
||||
|
||||
public void AETWriter(string file)
|
||||
{
|
||||
if (AET.MAIN.Offset < 0) return;
|
||||
IO = File.OpenWriter(file + ".bin", true);
|
||||
|
||||
IO.Position = 0x20;
|
||||
AETWriter(ref AET.MAIN );
|
||||
|
||||
if (AET.TOUCH.Offset >= 0)
|
||||
{
|
||||
IO.Position = IO.Length + 0x20;
|
||||
AETWriter(ref AET.TOUCH);
|
||||
}
|
||||
|
||||
IO.Position = 0;
|
||||
IO.Write(AET.MAIN.Offset);
|
||||
if (AET.TOUCH.Offset > 0) IO.Write(AET.TOUCH.Offset);
|
||||
|
||||
IO.Close();
|
||||
}
|
||||
|
||||
public void AETReader(ref Pointer<AetData> AET)
|
||||
{
|
||||
IO.Position = AET.Offset;
|
||||
ref AetData Aet = ref AET.Value;
|
||||
|
||||
Aet.Name = IO.ReadPointerString();
|
||||
Aet.Unk = IO.ReadSingle();
|
||||
Aet.Duration = IO.ReadSingle();
|
||||
Aet.FrameRate = IO.ReadSingle();
|
||||
IO.ReadInt32();
|
||||
Aet.Width = IO.ReadInt32();
|
||||
Aet.Height = IO.ReadInt32();
|
||||
Aet.DontChange = IO.ReadInt32();
|
||||
if (Aet.DontChange != 0) { IO.Close(); return; }
|
||||
Aet.LayObjPointers = IO.ReadCountPointer<CountPointer<int>>();
|
||||
CountPointer<SpriteEntry> Sprites = IO.ReadCountPointer<SpriteEntry>();
|
||||
Aet.Unknown = IO.ReadCountPointer<int>();
|
||||
|
||||
Aet.LayObjDict = new Dictionary<int, int>();
|
||||
Aet.ObjectsDict = new Dictionary<int, AetObject>();
|
||||
Aet.SprEntsDict = new Dictionary<int, SpriteEntry>();
|
||||
Aet.SpritesDict = new Dictionary<int, Sprite>();
|
||||
|
||||
IO.Position = Aet.LayObjPointers.Offset;
|
||||
for (i = 0; i < Aet.LayObjPointers.Count; i++)
|
||||
{
|
||||
Aet.LayObjDict.Add(i, IO.Position);
|
||||
Aet.LayObjPointers.Entries[i] = IO.ReadCountPointer<int>();
|
||||
}
|
||||
|
||||
for (i = 0; i < Aet.LayObjPointers.Count; i++)
|
||||
{
|
||||
IO.Position = Aet.LayObjPointers.Entries[i].Offset;
|
||||
for (i0 = 0; i0 < Aet.LayObjPointers.Entries[i].Count; i0++)
|
||||
Aet.LayObjPointers.Entries[i].Entries[i0] = IO.ReadAetObject(ref Aet.ObjectsDict);
|
||||
}
|
||||
|
||||
IO.Position = Sprites.Offset;
|
||||
for (i = 0; i < Sprites.Count; i++)
|
||||
{
|
||||
SpriteEntry SprEnt = new SpriteEntry();
|
||||
int Offset = IO.Position;
|
||||
|
||||
SprEnt.Unknown = IO.ReadInt32();
|
||||
SprEnt.Width = IO.ReadInt16();
|
||||
SprEnt.Height = IO.ReadInt16();
|
||||
SprEnt.Frames = IO.ReadSingle();
|
||||
SprEnt.Sprites = IO.ReadCountPointer<int>();
|
||||
long Position = IO.LongPosition;
|
||||
IO.Position = SprEnt.Sprites.Offset;
|
||||
for (i0 = 0; i0 < SprEnt.Sprites.Count; i0++)
|
||||
{
|
||||
Sprite Spr = new Sprite();
|
||||
int OffsetLocal = IO.Position;
|
||||
Spr.Name = IO.ReadPointerString();
|
||||
Spr.ID = IO.ReadInt32();
|
||||
Aet.SpritesDict.Add(OffsetLocal, Spr);
|
||||
SprEnt.Sprites.Entries[i0] = OffsetLocal;
|
||||
}
|
||||
IO.LongPosition = Position;
|
||||
Aet.SprEntsDict.Add(Offset, SprEnt);
|
||||
}
|
||||
}
|
||||
|
||||
public void AETWriter(ref Pointer<AetData> AET)
|
||||
{
|
||||
ref AetData Aet = ref AET.Value;
|
||||
|
||||
if (Aet.SpritesArr != null)
|
||||
{
|
||||
List<int> WrittenSprites = new List<int>();
|
||||
for (i = 0; i < Aet.SprEntsArr.Length; i++)
|
||||
{
|
||||
ref SpriteEntry SprEnt = ref Aet.SprEntsArr[i].Value;
|
||||
if (SprEnt.Sprites.Count < 1) continue;
|
||||
SprEnt.Sprites.Offset = IO.Position;
|
||||
for (i0 = 0; i0 < SprEnt.Sprites.Count; i0++)
|
||||
{
|
||||
ref int I = ref SprEnt.Sprites.Entries[i0];
|
||||
Aet.SpritesArr[Aet.SpritesIndDict[I]].Offset = IO.Position;
|
||||
IO.Write(0);
|
||||
IO.Write(Aet.SpritesArr[Aet.SpritesIndDict[I]].Value.ID);
|
||||
WrittenSprites.Add(Aet.SpritesIndDict[I]);
|
||||
}
|
||||
}
|
||||
for (i = 0; i < Aet.SpritesArr.Length; i++)
|
||||
if (!WrittenSprites.Contains(i))
|
||||
{
|
||||
Aet.SpritesArr[i].Offset = IO.Position;
|
||||
IO.Write(0);
|
||||
IO.Write(Aet.SpritesArr[i].Value.ID);
|
||||
WrittenSprites.Add(i);
|
||||
}
|
||||
}
|
||||
|
||||
IO.Align(0x20);
|
||||
for (i = 0; i < Aet.SprEntsArr.Length; i++)
|
||||
{
|
||||
Aet.SprEntsArr[i].Offset = IO.Position;
|
||||
ref SpriteEntry SprEnt = ref Aet.SprEntsArr[i].Value;
|
||||
IO.Write(SprEnt.Unknown);
|
||||
IO.Write(SprEnt.Width);
|
||||
IO.Write(SprEnt.Height);
|
||||
IO.Write(SprEnt.Frames);
|
||||
IO.Write(SprEnt.Sprites.Count);
|
||||
IO.Write(SprEnt.Sprites.Offset);
|
||||
}
|
||||
|
||||
IO.Align(0x20);
|
||||
Aet.LayObjPointers.Offset = IO.Position;
|
||||
for (i = 0; i < Aet.LayObjPointers.Count; i++)
|
||||
{
|
||||
Aet.LayObjPointers.Entries[i].Offset = IO.Position;
|
||||
IO.Write(0L);
|
||||
}
|
||||
|
||||
List<int> NullValPointers = new List<int>();
|
||||
for (i = 0; i < Aet.LayObjPointers.Count; i++)
|
||||
{
|
||||
for (i0 = 0; i0 < Aet.LayObjPointers.Entries[i].Count; i0++)
|
||||
{
|
||||
ref int I = ref Aet.LayObjPointers.Entries[i].Entries[i0];
|
||||
IO.Write(ref Aet.ObjectsArr[I].Value, ref NullValPointers);
|
||||
}
|
||||
|
||||
IO.Align(0x20);
|
||||
for (i0 = 0; i0 < Aet.LayObjPointers.Entries[i].Count; i0++)
|
||||
{
|
||||
ref int I = ref Aet.LayObjPointers.Entries[i].Entries[i0];
|
||||
IO.Write(ref Aet.ObjectsArr[I].Value, ref Aet.ObjectsArr[I].Offset);
|
||||
}
|
||||
}
|
||||
|
||||
IO.Align(0x20);
|
||||
AET.Offset = IO.Position;
|
||||
IO.Write(0L);
|
||||
IO.Write(Aet.Duration);
|
||||
IO.Write(Aet.FrameRate);
|
||||
IO.Write(0);
|
||||
IO.Write(Aet.Width);
|
||||
IO.Write(Aet.Height);
|
||||
IO.Write(0);
|
||||
IO.Write(0L);
|
||||
IO.Write(0L);
|
||||
IO.Write(0L);
|
||||
IO.Write(0L);
|
||||
|
||||
IO.Align(0x10);
|
||||
{
|
||||
Dictionary<string, int> UsedValues = new Dictionary<string, int>();
|
||||
|
||||
if (Aet.SpritesArr != null)
|
||||
for (i = 0; i < Aet.SpritesArr.Length; i++)
|
||||
IO.WritePointerString(ref UsedValues, ref Aet.SpritesArr[i].Value.Name);
|
||||
|
||||
//IO.Align(0x4);
|
||||
for (i = 0; i < Aet.ObjectsArr.Length; i++)
|
||||
{
|
||||
ref AetObject Obj = ref Aet.ObjectsArr[i].Value;
|
||||
if (Obj.Type == ObjType.Pic)
|
||||
for (i0 = 0; i0 < Obj.Pic.Value.Marker.Count; i0++)
|
||||
IO.WritePointerString(ref UsedValues, ref Obj.Pic.Value.Marker.Entries[i0].Name);
|
||||
else if (Obj.Type == ObjType.Eff)
|
||||
for (i0 = 0; i0 < Obj.Eff.Value.Marker.Count; i0++)
|
||||
IO.WritePointerString(ref UsedValues, ref Obj.Eff.Value.Marker.Entries[i0].Name);
|
||||
|
||||
IO.WritePointerString(ref UsedValues, ref Obj.Name);
|
||||
}
|
||||
|
||||
//IO.Align(0x4);
|
||||
|
||||
Aet.Name.Offset = IO.Position;
|
||||
IO.Write(Aet.Name.Value + x00);
|
||||
}
|
||||
|
||||
if (Aet.Unknown.Count > 0)
|
||||
{
|
||||
IO.Align(0x10);
|
||||
Aet.Unknown.Offset = IO.Position;
|
||||
for (i = 0; i < Aet.Unknown.Count * 10; i++)
|
||||
IO.Write(0L);
|
||||
}
|
||||
|
||||
IO.Align(0x10);
|
||||
int ReturnPosition = IO.Position;
|
||||
for (i = 0; i < NullValPointers.Count; i++)
|
||||
{
|
||||
IO.Position = NullValPointers[i];
|
||||
IO.Write(ReturnPosition + i * 4);
|
||||
}
|
||||
IO.Position = ReturnPosition;
|
||||
for (i = 0; i < NullValPointers.Count; i++) IO.Write(0);
|
||||
|
||||
IO.Align(1, true);
|
||||
|
||||
for (i = 0; i < Aet.ObjectsArr.Length; i++)
|
||||
{
|
||||
ref AetObject Obj = ref Aet.ObjectsArr[i].Value;
|
||||
if (Obj.Type == ObjType.Pic)
|
||||
{
|
||||
IO.Position = Obj.Pic.Offset;
|
||||
IO.Write(Aet.SprEntsArr[Aet.SprEntsIndDict[Obj.Pic.Value.SpriteEntryID]].Offset);
|
||||
IO.Write(Obj.Pic.Value.ParentObjectID > -1 ?
|
||||
Aet.ObjectsArr[Obj.Pic.Value.ParentObjectID].Offset : 0);
|
||||
IO.Write(Obj.Eff.Value.Marker.Count );
|
||||
IO.Write(Obj.Eff.Value.Marker.Offset);
|
||||
ref CountPointer<Marker> Marker = ref Obj.Pic.Value.Marker;
|
||||
IO.Position = Marker.Offset;
|
||||
for (i0 = 0; i0 < Marker.Count; i0++)
|
||||
{
|
||||
IO.Write(Marker.Entries[i0].Frame);
|
||||
IO.Write(Marker.Entries[i0]. Name.Offset);
|
||||
}
|
||||
}
|
||||
else if (Obj.Type == ObjType.Eff)
|
||||
{
|
||||
IO.Position = Obj.Eff.Offset;
|
||||
IO.Write(Aet.LayObjPointers.Entries[Obj.Eff.Value.LayerID].Offset);
|
||||
IO.Write(Obj.Eff.Value.ParentObjectID > -1 ?
|
||||
Aet.ObjectsArr[Obj.Eff.Value.ParentObjectID].Offset : 0);
|
||||
IO.Write(Obj.Eff.Value.Marker.Count );
|
||||
IO.Write(Obj.Eff.Value.Marker.Offset);
|
||||
ref CountPointer<Marker> Marker = ref Obj.Eff.Value.Marker;
|
||||
IO.Position = Marker.Offset;
|
||||
for (i0 = 0; i0 < Marker.Count; i0++)
|
||||
{
|
||||
IO.Write(Marker.Entries[i0].Frame);
|
||||
IO.Write(Marker.Entries[i0]. Name.Offset);
|
||||
}
|
||||
}
|
||||
|
||||
IO.Position = Aet.ObjectsArr[i].Offset;
|
||||
IO.Write(Obj.Name.Offset);
|
||||
}
|
||||
|
||||
if (Aet.SpritesArr != null)
|
||||
for (i = 0; i < Aet.SpritesArr.Length; i++)
|
||||
{
|
||||
IO.Position = Aet.SpritesArr[i].Offset;
|
||||
IO.Write(Aet.SpritesArr[i].Value.Name.Offset);
|
||||
}
|
||||
|
||||
for (i = 0; i < Aet.LayObjPointers.Count; i++)
|
||||
{
|
||||
IO.Position = Aet.LayObjPointers.Entries[i].Offset;
|
||||
IO.Write(Aet.LayObjPointers.Entries[i].Count);
|
||||
IO.Write(Aet.LayObjPointers.Entries[i].Count > 0 ?
|
||||
Aet.ObjectsArr[Aet.ObjectsIndDict[Aet.LayObjPointers.Entries[i].Entries[0]]].Offset : 0);
|
||||
}
|
||||
|
||||
IO.Position = AET.Offset;
|
||||
IO.Write(Aet.Name.Offset);
|
||||
IO.Position = AET.Offset + 0x20;
|
||||
IO.Write(Aet.LayObjPointers.Count );
|
||||
IO.Write(Aet.LayObjPointers.Offset);
|
||||
IO.Write(Aet.SprEntsArr.Length);
|
||||
IO.Write(Aet.SprEntsArr[0].Offset);
|
||||
if (Aet.Unknown.Count > 0)
|
||||
{ IO.Write(Aet.Unknown.Count); IO.Write(Aet.Unknown.Offset); }
|
||||
else IO.Write(0L);
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
{
|
||||
AET = new AetHeader();
|
||||
AET.MAIN .Offset = -1;
|
||||
AET.TOUCH.Offset = -1;
|
||||
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
if (!MsgPack.Element<MsgPack>("Aet", out MsgPack Aet)) { MsgPack = null; return; }
|
||||
|
||||
if (Aet.Array != null)
|
||||
if (Aet.Array.Length == 1)
|
||||
{
|
||||
if (Aet.Array[0] is MsgPack MAIN ) MsgPackReader(MAIN , ref AET.MAIN );
|
||||
}
|
||||
else if (Aet.Array.Length == 2)
|
||||
{
|
||||
if (Aet.Array[0] is MsgPack MAIN ) MsgPackReader(MAIN , ref AET.MAIN );
|
||||
if (Aet.Array[1] is MsgPack TOUCH) MsgPackReader(TOUCH, ref AET.TOUCH);
|
||||
}
|
||||
|
||||
MsgPack = null;
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
{
|
||||
if (this.AET.MAIN .Offset <= 0) return;
|
||||
MsgPack AET = new MsgPack("Aet", this.AET.TOUCH.Offset > 0 ? 2 : 1);
|
||||
|
||||
AET[0] = MsgPackWriter(ref this.AET.MAIN);
|
||||
if (this.AET.TOUCH.Offset > 0) AET[1] = MsgPackWriter(ref this.AET.TOUCH);
|
||||
|
||||
AET.WriteAfterAll(true, file, JSON);
|
||||
}
|
||||
|
||||
public void MsgPackReader(MsgPack AET, ref Pointer<AetData> AetData)
|
||||
{
|
||||
MsgPack Temp = new MsgPack();
|
||||
|
||||
AetData.Offset = -1;
|
||||
ref AetData Aet = ref AetData.Value;
|
||||
|
||||
Aet.Name.Value = AET.ReadString("Name" );
|
||||
Aet.Unk = AET.ReadSingle("Unk" );
|
||||
Aet.Duration = AET.ReadSingle("Duration" );
|
||||
Aet.FrameRate = AET.ReadSingle("FrameRate");
|
||||
Aet.Width = AET.ReadInt32("Width" );
|
||||
Aet.Height = AET.ReadInt32("Height");
|
||||
|
||||
if (AET.Element<MsgPack>("Layers", out MsgPack Layers))
|
||||
{
|
||||
Aet.LayObjPointers.Count = Layers.Array.Length;
|
||||
for (i = 0; i < Aet.LayObjPointers.Count; i++)
|
||||
if (Layers[i] is MsgPack ObjectID)
|
||||
{
|
||||
Aet.LayObjPointers.Entries[i].Count =
|
||||
ObjectID.Array == null ? 0 : ObjectID.Array.Length;
|
||||
for (i0 = 0; i0 < Aet.LayObjPointers.Entries[i].Count; i0++)
|
||||
if (ObjectID.Array[i0] is MsgPack msg)
|
||||
Aet.LayObjPointers.Entries[i].Entries[i0] = msg.ReadInt32();
|
||||
}
|
||||
}
|
||||
else return;
|
||||
|
||||
Aet.ObjectsIndDict = new Dictionary<int, int>();
|
||||
Aet.SprEntsIndDict = new Dictionary<int, int>();
|
||||
Aet.SpritesIndDict = new Dictionary<int, int>();
|
||||
|
||||
int? ID = null;
|
||||
if (AET.Element("SpriteEntry", out Temp))
|
||||
{
|
||||
Aet.SprEntsArr = new Pointer<SpriteEntry>[1];
|
||||
ID = Aet.SprEntsArr[0].Value.ReadMP(Temp);
|
||||
if (ID != null) Aet.SprEntsIndDict.Add(ID.Value, 0);
|
||||
}
|
||||
else if (AET.Element<MsgPack>("SpriteEntries", out Temp))
|
||||
{
|
||||
Aet.SprEntsArr = new Pointer<SpriteEntry>[Temp.Array.Length];
|
||||
for (i = 0; i < Aet.SprEntsArr.Length; i++)
|
||||
if (Temp[i] is MsgPack SpriteEntry)
|
||||
{
|
||||
ID = Aet.SprEntsArr[i].Value.ReadMP(SpriteEntry);
|
||||
if (ID != null) Aet.SprEntsIndDict.Add(ID.Value, i);
|
||||
}
|
||||
}
|
||||
else return;
|
||||
|
||||
if (AET.Element("Object", out Temp))
|
||||
{
|
||||
Aet.ObjectsArr = new Pointer<AetObject>[1];
|
||||
ID = Aet.ObjectsArr[0].Value.ReadMP(Temp, 0, ref Aet);
|
||||
if (ID != null) Aet.ObjectsIndDict.Add(ID.Value, 0);
|
||||
}
|
||||
else if (AET.Element<MsgPack>("Objects", out Temp))
|
||||
{
|
||||
Aet.ObjectsArr = new Pointer<AetObject>[Temp.Array.Length];
|
||||
for (i = 0; i < Aet.ObjectsArr.Length; i++)
|
||||
if (Temp[i] is MsgPack Object)
|
||||
{
|
||||
ID = Aet.ObjectsArr[i].Value.ReadMP(Object, i, ref Aet);
|
||||
if (ID != null) Aet.ObjectsIndDict.Add(ID.Value, i);
|
||||
}
|
||||
}
|
||||
else return;
|
||||
|
||||
if (AET.Element("Sprite", out Temp))
|
||||
{
|
||||
Aet.SpritesArr = new Pointer<Sprite>[1];
|
||||
ID = Aet.SpritesArr[0].Value.ReadMP(Temp);
|
||||
if (ID != null) Aet.SpritesIndDict.Add(ID.Value, 0);
|
||||
}
|
||||
else if (AET.Element<MsgPack>("Sprites", out Temp))
|
||||
{
|
||||
Aet.SpritesArr = new Pointer<Sprite>[Temp.Array.Length];
|
||||
for (i = 0; i < Aet.SpritesArr.Length; i++)
|
||||
if (Temp[i] is MsgPack Sprite)
|
||||
{
|
||||
ID = Aet.SpritesArr[i].Value.ReadMP(Sprite);
|
||||
if (ID != null) Aet.SpritesIndDict.Add(ID.Value, i);
|
||||
}
|
||||
}
|
||||
if (AET.Element("Unknown", out Temp))
|
||||
Aet.Unknown.Count = Temp.ReadInt32();
|
||||
|
||||
AetData.Offset = 0;
|
||||
}
|
||||
|
||||
|
||||
public MsgPack MsgPackWriter(ref Pointer<AetData> AetData)
|
||||
{
|
||||
if (AetData.Offset <= 0) return null;
|
||||
ref AetData Aet = ref AetData.Value;
|
||||
|
||||
Aet.ObjectsIndDict = Aet.ObjectsDict.GetIndDict();
|
||||
Aet.SpritesIndDict = Aet.SpritesDict.GetIndDict();
|
||||
Aet.SprEntsIndDict = Aet.SprEntsDict.GetIndDict();
|
||||
Aet.ObjectsArr = Aet.ObjectsDict.ToPointerArray();
|
||||
Aet.SpritesArr = Aet.SpritesDict.ToPointerArray();
|
||||
Aet.SprEntsArr = Aet.SprEntsDict.ToPointerArray();
|
||||
Aet.ObjectsDict = null;
|
||||
Aet.SpritesDict = null;
|
||||
Aet.SprEntsDict = null;
|
||||
|
||||
MsgPack AET = new MsgPack().Add("Name", Aet.Name.Value).Add("Duration",
|
||||
Aet.Duration).Add("FrameRate", Aet.FrameRate).Add("Width",
|
||||
Aet.Width).Add("Height", Aet.Height).Add("Unk", Aet.Unk);
|
||||
|
||||
if (Aet.LayObjPointers.Count > 0)
|
||||
{
|
||||
MsgPack Layers = new MsgPack("Layers", Aet.LayObjPointers.Count);
|
||||
for (i = 0; i < Aet.LayObjPointers.Count; i++)
|
||||
if (Aet.LayObjPointers.Entries[i].Count > 0)
|
||||
{
|
||||
MsgPack Objects = new MsgPack(Aet.LayObjPointers.Entries[i].Count);
|
||||
for (i0 = 0; i0 < Aet.LayObjPointers.Entries[i].Count; i0++)
|
||||
Objects[i0] = Aet.ObjectsIndDict[Aet.LayObjPointers.Entries[i].Entries[i0]];
|
||||
Layers[i] = Objects;
|
||||
}
|
||||
AET.Add(Layers);
|
||||
}
|
||||
|
||||
if (Aet.SprEntsArr.Length == 1)
|
||||
AET.Add(Aet.SprEntsArr[0].Value.WriteMP(0, ref Aet.SpritesIndDict, "SpriteEntry"));
|
||||
else if (Aet.SprEntsArr.Length > 0)
|
||||
{
|
||||
MsgPack SpriteEntries = new MsgPack("SpriteEntries", Aet.SprEntsArr.Length);
|
||||
for (i = 0; i < Aet.SprEntsArr.Length; i++)
|
||||
SpriteEntries[i] = Aet.SprEntsArr[i].Value.WriteMP(i, ref Aet.SpritesIndDict);
|
||||
AET.Add(SpriteEntries);
|
||||
}
|
||||
|
||||
if (Aet.ObjectsArr.Length == 1)
|
||||
AET.Add(Aet.ObjectsArr[0].Value.WriteMP(0, ref Aet, "Object"));
|
||||
else if (Aet.ObjectsArr.Length > 1)
|
||||
{
|
||||
MsgPack Objects = new MsgPack("Objects", Aet.ObjectsArr.Length);
|
||||
for (i = 0; i < Aet.ObjectsArr.Length; i++)
|
||||
Objects[i] = Aet.ObjectsArr[i].Value.WriteMP(i, ref Aet);
|
||||
AET.Add(Objects);
|
||||
}
|
||||
|
||||
if (Aet.SpritesArr.Length == 1)
|
||||
AET.Add(Aet.SpritesArr[0].Value.WriteMP(0, "Sprite"));
|
||||
else if (Aet.SpritesArr.Length > 1)
|
||||
{
|
||||
MsgPack Sprites = new MsgPack("Sprites", Aet.SpritesArr.Length);
|
||||
for (i = 0; i < Aet.SpritesArr.Length; i++)
|
||||
Sprites[i] = Aet.SpritesArr[i].Value.WriteMP(i);
|
||||
AET.Add(Sprites);
|
||||
}
|
||||
|
||||
if (Aet.Unknown.Count > 0)
|
||||
AET.Add("Unknown", Aet.Unknown.Count);
|
||||
|
||||
return AET;
|
||||
}
|
||||
}
|
||||
|
||||
public struct AetHeader
|
||||
{
|
||||
public Pointer<AetData> MAIN ;
|
||||
public Pointer<AetData> TOUCH;
|
||||
}
|
||||
|
||||
public struct AetData
|
||||
{
|
||||
public Pointer<string> Name;
|
||||
public float Unk;
|
||||
public float Duration;
|
||||
public float FrameRate;
|
||||
public int Width;
|
||||
public int Height;
|
||||
public int DontChange;
|
||||
public CountPointer<CountPointer<int>> LayObjPointers;
|
||||
public CountPointer<int> Unknown;
|
||||
|
||||
public Dictionary<int, int> LayObjDict;
|
||||
public Dictionary<int, int> ObjectsIndDict;
|
||||
public Dictionary<int, int> SpritesIndDict;
|
||||
public Dictionary<int, int> SprEntsIndDict;
|
||||
public Pointer< AetObject>[] ObjectsArr;
|
||||
public Pointer<SpriteEntry>[] SprEntsArr;
|
||||
public Pointer< Sprite>[] SpritesArr;
|
||||
public Dictionary<int, AetObject> ObjectsDict;
|
||||
public Dictionary<int, SpriteEntry> SprEntsDict;
|
||||
public Dictionary<int, Sprite> SpritesDict;
|
||||
}
|
||||
|
||||
public struct AetObject
|
||||
{
|
||||
public int Offset;
|
||||
public Pointer<string> Name;
|
||||
public float StartTime0;
|
||||
public float LoopDuration;
|
||||
public float StartTime1;
|
||||
public float PlaybackSpeed;
|
||||
public byte Unk0;
|
||||
public byte Unk1;
|
||||
public byte Unk2;
|
||||
public ObjType Type;
|
||||
public Pointer<Pic> Pic;
|
||||
public Pointer<Aif> Aif;
|
||||
public Pointer<Eff> Eff;
|
||||
|
||||
public int? ReadMP(MsgPack msg, int i, ref AetData Aet)
|
||||
{
|
||||
Name.Value = msg.ReadString("Name" );
|
||||
StartTime0 = msg.ReadSingle("StartTime0" );
|
||||
LoopDuration = msg.ReadSingle("LoopDuration" );
|
||||
StartTime1 = msg.ReadSingle("StartTime1" );
|
||||
PlaybackSpeed = msg.ReadSingle("PlaybackSpeed");
|
||||
Unk0 = msg.ReadUInt8("Unk0");
|
||||
Unk1 = msg.ReadUInt8("Unk1");
|
||||
Unk2 = msg.ReadUInt8("Unk2");
|
||||
if (msg.Element("Pic", out MsgPack Pic))
|
||||
{ Type = ObjType.Pic; this.Pic = new Pointer<Pic>() { Value = new Pic().ReadMP(Pic, i, ref Aet) }; }
|
||||
else if (msg.Element("Aif", out MsgPack Aif))
|
||||
{ Type = ObjType.Aif; this.Aif = new Pointer<Aif>() { Value = new Aif().ReadMP(Aif) }; }
|
||||
else if (msg.Element("Eff", out MsgPack Eff))
|
||||
{ Type = ObjType.Eff; this.Eff = new Pointer<Eff>() { Value = new Eff().ReadMP(Eff, i, ref Aet) }; }
|
||||
else Type = ObjType.Nop;
|
||||
|
||||
return msg.ReadNInt32("ID");
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(int Id, ref AetData Aet, string name = null)
|
||||
{
|
||||
MsgPack AetObject = new MsgPack(name).Add("ID", Id).Add("Name", Name.Value)
|
||||
.Add("StartTime0", StartTime0).Add("LoopDuration", LoopDuration)
|
||||
.Add("StartTime1", StartTime1).Add("PlaybackSpeed", PlaybackSpeed)
|
||||
.Add("Unk0", Unk0).Add("Unk1", Unk1).Add("Unk2", Unk2);
|
||||
|
||||
if (Type == ObjType.Pic) AetObject.Add(Pic.Value.WriteMP(ref Aet));
|
||||
else if (Type == ObjType.Aif) AetObject.Add(Aif.Value.WriteMP());
|
||||
else if (Type == ObjType.Eff) AetObject.Add(Eff.Value.WriteMP(ref Aet));
|
||||
return AetObject;
|
||||
}
|
||||
}
|
||||
|
||||
public struct Pic
|
||||
{
|
||||
public int SpriteEntryID;
|
||||
public int ParentObjectID;
|
||||
public CountPointer<Marker> Marker;
|
||||
public Pointer<AnimationData> Data;
|
||||
|
||||
public Pic ReadMP(MsgPack msg, int i, ref AetData Aet)
|
||||
{
|
||||
int SpriteEntryID = msg.ReadInt32("SpriteEntryID");
|
||||
if (Aet.SprEntsIndDict.ContainsValue(SpriteEntryID))
|
||||
this.SpriteEntryID = Aet.SprEntsIndDict.GetKey(SpriteEntryID);
|
||||
|
||||
this.ParentObjectID = -1;
|
||||
int? ParentObjectID = msg.ReadNInt32("ParentObjectID");
|
||||
if (ParentObjectID != null)
|
||||
this.ParentObjectID = ParentObjectID.Value;
|
||||
|
||||
if (msg.Element("Marker", out MsgPack Marker))
|
||||
{
|
||||
this.Marker.Count = 1;
|
||||
this.Marker.Entries[0].ReadMP(Marker);
|
||||
}
|
||||
else if (msg.Element<MsgPack>("Markers", out MsgPack Markers))
|
||||
{
|
||||
this.Marker.Count = Markers.Array.Length;
|
||||
for (i = 0; i < Markers.Array.Length; i++)
|
||||
if (Markers[i] is MsgPack Object)
|
||||
this.Marker.Entries[i].ReadMP(Object);
|
||||
}
|
||||
else this.Marker.Entries = null;
|
||||
|
||||
Data.Value.ReadMP(msg);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(ref AetData Aet)
|
||||
{
|
||||
MsgPack Pic = new MsgPack("Pic");
|
||||
if (Aet.SprEntsIndDict.ContainsKey(SpriteEntryID))
|
||||
Pic.Add("SpriteEntryID", Aet.SprEntsIndDict[SpriteEntryID]);
|
||||
if (ParentObjectID > 0)
|
||||
if (Aet.ObjectsIndDict.ContainsKey(ParentObjectID))
|
||||
Pic.Add("ParentObjectID", Aet.ObjectsIndDict[ParentObjectID]);
|
||||
|
||||
if (Marker.Count == 1)
|
||||
Pic.Add(Marker.Entries[0].WriteMP("Marker"));
|
||||
else if (Marker.Count > 1)
|
||||
{
|
||||
MsgPack Markers = new MsgPack("Markers", Marker.Count);
|
||||
for (int i = 0; i < Marker.Count; i++)
|
||||
Markers[i] = Marker.Entries[i].WriteMP();
|
||||
Pic.Add(Markers);
|
||||
}
|
||||
|
||||
Pic.Add(Data.Value.WriteMP());
|
||||
return Pic;
|
||||
}
|
||||
}
|
||||
|
||||
public struct Aif
|
||||
{
|
||||
public Pointer<int> Value;
|
||||
public int Zero0;
|
||||
public int Zero1;
|
||||
public int Zero2;
|
||||
public int Zero3;
|
||||
public int Pointer;
|
||||
public CountPointer<float> Unk0;
|
||||
public CountPointer<float> Unk1;
|
||||
public CountPointer<float> Unk2;
|
||||
public CountPointer<float> Unk3;
|
||||
|
||||
public Aif ReadMP(MsgPack msg)
|
||||
{
|
||||
Value.Value = msg.ReadInt32("Value");
|
||||
|
||||
msg.ReadMP(ref Unk0, "Unk0");
|
||||
msg.ReadMP(ref Unk1, "Unk1");
|
||||
msg.ReadMP(ref Unk2, "Unk2");
|
||||
msg.ReadMP(ref Unk3, "Unk3");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MsgPack WriteMP() =>
|
||||
new MsgPack("Aif").Add("Value", Value.Value).Add(Unk0.WriteMP("Unk0")).Add(Unk1
|
||||
.WriteMP("Unk1")).Add(Unk2.WriteMP("Unk2")).Add(Unk3.WriteMP("Unk3"));
|
||||
}
|
||||
|
||||
public struct Eff
|
||||
{
|
||||
public int LayerID;
|
||||
public int ParentObjectID;
|
||||
public CountPointer<Marker> Marker;
|
||||
public Pointer<AnimationData> Data;
|
||||
|
||||
public Eff ReadMP(MsgPack msg, int i, ref AetData Aet)
|
||||
{
|
||||
LayerID = msg.ReadInt32("LayerID");
|
||||
|
||||
this.ParentObjectID = -1;
|
||||
int? ParentObjectID = msg.ReadNInt32("ParentObjectID");
|
||||
if (ParentObjectID != null)
|
||||
this.ParentObjectID = ParentObjectID.Value;
|
||||
|
||||
if (msg.Element("Marker", out MsgPack Marker))
|
||||
{
|
||||
this.Marker.Count = 1;
|
||||
this.Marker.Entries[0].ReadMP(Marker);
|
||||
}
|
||||
else if (msg.Element<MsgPack>("Markers", out MsgPack Markers))
|
||||
{
|
||||
this.Marker.Count = Markers.Array.Length;
|
||||
for (i = 0; i < Markers.Array.Length; i++)
|
||||
if (Markers[i] is MsgPack Object)
|
||||
this.Marker.Entries[i].ReadMP(Object);
|
||||
}
|
||||
else this.Marker.Entries = null;
|
||||
|
||||
Data.Value.ReadMP(msg);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(ref AetData Aet)
|
||||
{
|
||||
MsgPack Eff = new MsgPack("Eff");
|
||||
if (Aet.LayObjDict.ContainsValue(LayerID))
|
||||
Eff.Add("LayerID", Aet.LayObjDict.GetKey(LayerID));
|
||||
if (ParentObjectID > 0)
|
||||
if (Aet.ObjectsIndDict.ContainsKey(ParentObjectID))
|
||||
Eff.Add("ParentObjectID", Aet.ObjectsIndDict[ParentObjectID]);
|
||||
|
||||
if (Marker.Count == 1)
|
||||
Eff.Add(Marker.Entries[0].WriteMP("Marker"));
|
||||
else if (Marker.Count > 1)
|
||||
{
|
||||
MsgPack Markers = new MsgPack("Markers", Marker.Count);
|
||||
for (int i = 0; i < Marker.Count; i++)
|
||||
Markers[i] = Marker.Entries[i].WriteMP();
|
||||
Eff.Add(Markers);
|
||||
}
|
||||
|
||||
Eff.Add(Data.Value.WriteMP());
|
||||
|
||||
return Eff;
|
||||
}
|
||||
}
|
||||
|
||||
public struct Marker
|
||||
{
|
||||
public float Frame;
|
||||
public Pointer<string> Name;
|
||||
|
||||
public void ReadMP(MsgPack mp)
|
||||
{ Frame = mp.ReadSingle("Frame"); Name.Value = mp.ReadString("Name"); }
|
||||
|
||||
public MsgPack WriteMP(string name = null) =>
|
||||
new MsgPack(name).Add("Frame", Frame).Add("Name", Name.Value);
|
||||
}
|
||||
|
||||
public struct SubAnimationData
|
||||
{
|
||||
public KeyFrameEntry OriginX;
|
||||
public KeyFrameEntry OriginY;
|
||||
public KeyFrameEntry PositionX;
|
||||
public KeyFrameEntry PositionY;
|
||||
public KeyFrameEntry Rotation;
|
||||
public KeyFrameEntry ScaleX;
|
||||
public KeyFrameEntry ScaleY;
|
||||
public KeyFrameEntry Opacity;
|
||||
|
||||
public void ReadMP(MsgPack msg)
|
||||
{
|
||||
OriginX.ReadMP(msg, "OriginX");
|
||||
OriginY.ReadMP(msg, "OriginY");
|
||||
PositionX.ReadMP(msg, "PositionX");
|
||||
PositionY.ReadMP(msg, "PositionY");
|
||||
Rotation .ReadMP(msg, "Rotation" );
|
||||
ScaleX.ReadMP(msg, "ScaleX");
|
||||
ScaleY.ReadMP(msg, "ScaleY");
|
||||
Opacity .ReadMP(msg, "Opacity" );
|
||||
}
|
||||
|
||||
public MsgPack WriteMP()
|
||||
{
|
||||
MsgPack AnimationData = new MsgPack("SubAnimationData");
|
||||
WriteMP(ref AnimationData);
|
||||
return AnimationData;
|
||||
}
|
||||
|
||||
public void WriteMP(ref MsgPack msg)
|
||||
{
|
||||
msg.Add( OriginX.WriteMP( "OriginX"));
|
||||
msg.Add( OriginY.WriteMP( "OriginY"));
|
||||
msg.Add(PositionX.WriteMP("PositionX"));
|
||||
msg.Add(PositionY.WriteMP("PositionY"));
|
||||
msg.Add(Rotation .WriteMP("Rotation" ));
|
||||
msg.Add( ScaleX.WriteMP( "ScaleX"));
|
||||
msg.Add( ScaleY.WriteMP( "ScaleY"));
|
||||
msg.Add(Opacity .WriteMP("Opacity" ));
|
||||
}
|
||||
}
|
||||
|
||||
public struct AnimationData
|
||||
{
|
||||
public BlendMode BlendMode;
|
||||
public byte Unk0;
|
||||
public bool UseTextureMask;
|
||||
public byte Unk1;
|
||||
public SubAnimationData Anim;
|
||||
public Pointer<SubAnimationData> SubAnim;
|
||||
|
||||
public void ReadMP(MsgPack msg)
|
||||
{
|
||||
if (!msg.Element("AnimationData", out MsgPack Data)) return;
|
||||
|
||||
System.Enum.TryParse(Data.ReadString("BlendMode"), out BlendMode);
|
||||
Unk0 = Data.ReadUInt8 ("Unk0");
|
||||
UseTextureMask = Data.ReadBoolean("UseTextureMask");
|
||||
Unk1 = Data.ReadUInt8 ("Unk1");
|
||||
|
||||
Anim.ReadMP(Data);
|
||||
|
||||
SubAnim.Offset = -1;
|
||||
if (Data.Element("SubAnimationData", out MsgPack SubAnimationData))
|
||||
{ SubAnim.Offset = 0; SubAnim.Value.ReadMP(SubAnimationData); }
|
||||
}
|
||||
|
||||
public MsgPack WriteMP()
|
||||
{
|
||||
MsgPack AnimationData = new MsgPack("AnimationData")
|
||||
.Add("BlendMode", BlendMode.ToString()).Add("Unk0", Unk0)
|
||||
.Add("UseTextureMask", UseTextureMask) .Add("Unk1", Unk1);
|
||||
|
||||
Anim.WriteMP(ref AnimationData);
|
||||
if (SubAnim.Offset > 0)
|
||||
AnimationData.Add(SubAnim.Value.WriteMP());
|
||||
return AnimationData;
|
||||
}
|
||||
}
|
||||
|
||||
public struct KeyFrameEntry
|
||||
{
|
||||
public int Count;
|
||||
public int Offset;
|
||||
public float Value;
|
||||
public float[] ArrValue;
|
||||
public float[] KeyFrame;
|
||||
public float[] Interpolation;
|
||||
|
||||
public void ReadMP(MsgPack msg, string name)
|
||||
{
|
||||
float? Value = msg.ReadNSingle(name);
|
||||
if (Value != null) { Count = 1; this.Value = Value.Value; return; }
|
||||
if (!msg.Element<MsgPack>(name, out MsgPack Temp)) return;
|
||||
|
||||
MsgPack temp;
|
||||
Count = Temp.Array.Length;
|
||||
if (Count == 0) return;
|
||||
ArrValue = new float[Count];
|
||||
KeyFrame = new float[Count];
|
||||
Interpolation = new float[Count];
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
temp = Temp[i] as MsgPack;
|
||||
KeyFrame [i] = temp.ReadSingle("KeyFrame" );
|
||||
ArrValue [i] = temp.ReadSingle("Value" );
|
||||
Interpolation[i] = temp.ReadSingle("Interpolation");
|
||||
}
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(string name)
|
||||
{
|
||||
if (Count < 1) return MsgPack.Null;
|
||||
if (Count == 1) return new MsgPack(name, MsgPack.Types.Float32, Value);
|
||||
MsgPack KFE = new MsgPack(name, Count);
|
||||
for (int i = 0; i < Count; i++) KFE[i] = new MsgPack().Add("KeyFrame", KeyFrame[i])
|
||||
.Add("Value", ArrValue[i]).Add("Interpolation", Interpolation[i]);
|
||||
return KFE;
|
||||
}
|
||||
}
|
||||
|
||||
public struct SpriteEntry
|
||||
{
|
||||
public int Unknown;
|
||||
public short Width;
|
||||
public short Height;
|
||||
public float Frames;
|
||||
public CountPointer<int> Sprites;
|
||||
|
||||
public int? ReadMP(MsgPack msg)
|
||||
{
|
||||
Unknown = msg.ReadInt32 ("Unknown");
|
||||
Width = msg.ReadInt16 ("Width" );
|
||||
Height = msg.ReadInt16 ("Height" );
|
||||
Frames = msg.ReadSingle("Frames" );
|
||||
|
||||
if (msg.Element("SpriteID", out MsgPack SpriteID))
|
||||
{
|
||||
Sprites = new CountPointer<int> { Count = 1 };
|
||||
Sprites.Entries[0] = SpriteID.ReadInt32();
|
||||
}
|
||||
else if (msg.Element<MsgPack>("SpriteIDs", out MsgPack SpriteIDs))
|
||||
{
|
||||
Sprites = new CountPointer<int> { Count = SpriteIDs.Array.Length };
|
||||
for (int i0 = 0; i0 < Sprites.Count; i0++)
|
||||
Sprites.Entries[i0] = (SpriteIDs[i0] as MsgPack).ReadInt32();
|
||||
}
|
||||
|
||||
return msg.ReadNInt32("ID");
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(int Id, ref Dictionary<int, int> SpritesIndDict, string Name = null)
|
||||
{
|
||||
MsgPack SpriteEntry = new MsgPack(Name).Add("ID", Id)
|
||||
.Add("Width", Width).Add("Height", Height).Add("Unknown", Unknown);
|
||||
|
||||
if (Sprites.Count > 0) SpriteEntry.Add("Frames", Frames);
|
||||
|
||||
if (Sprites.Count == 1)
|
||||
SpriteEntry.Add("SpriteID", SpritesIndDict[Sprites.Entries[0]]);
|
||||
else if (Sprites.Count > 1)
|
||||
{
|
||||
MsgPack SpriteIDs = new MsgPack("SpriteIDs", Sprites.Count);
|
||||
for (int i0 = 0; i0 < Sprites.Count; i0++)
|
||||
SpriteIDs[i0] = SpritesIndDict[Sprites.Entries[i0]];
|
||||
SpriteEntry.Add(SpriteIDs);
|
||||
}
|
||||
|
||||
return SpriteEntry;
|
||||
}
|
||||
}
|
||||
|
||||
public struct Sprite
|
||||
{
|
||||
public Pointer<string> Name;
|
||||
public int ID;
|
||||
|
||||
public MsgPack WriteMP(int Id, string name = null) =>
|
||||
new MsgPack(name).Add("ID", Id).Add("Name", Name.Value).Add("SprDB_ID", ID);
|
||||
|
||||
public int? ReadMP(MsgPack mp)
|
||||
{ ID = mp.ReadInt32("SprDB_ID"); Name.Value = mp.ReadString("Name"); return mp.ReadNInt32("ID"); }
|
||||
}
|
||||
|
||||
public struct CountPointer<T>
|
||||
{
|
||||
public int Count { get => Entries == null ? 0 : Entries.Length; set => Entries = new T[value]; }
|
||||
public int Offset;
|
||||
|
||||
public T[] Entries;
|
||||
|
||||
public override string ToString() => Entries.ToString();
|
||||
}
|
||||
|
||||
public struct Pointer<T>
|
||||
{
|
||||
public int Offset;
|
||||
public T Value;
|
||||
|
||||
public override string ToString() => Value.ToString();
|
||||
}
|
||||
|
||||
public enum ObjType : byte
|
||||
{
|
||||
Nop = 0,
|
||||
Pic = 1,
|
||||
Aif = 2,
|
||||
Eff = 3,
|
||||
}
|
||||
|
||||
public enum BlendMode : byte
|
||||
{
|
||||
Alpha = 3,
|
||||
Additive = 5,
|
||||
DstColorZero = 6,
|
||||
SrcAlphaOneMinusSrcColor = 7,
|
||||
Transparent = 8,
|
||||
}
|
||||
}
|
||||
@@ -1,465 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.Aet
|
||||
{
|
||||
public static class AetExt
|
||||
{
|
||||
private static System.Text.Encoding ShiftJIS = System.Text.Encoding.GetEncoding(932);
|
||||
|
||||
public static Dictionary<TKey, int> GetIndDict<TKey, TVal>(this Dictionary<TKey, TVal> Dict)
|
||||
{
|
||||
List<TKey> Keys = Dict.Keys.ToList();
|
||||
Dictionary<TKey, int> IndDict = new Dictionary<TKey, int>();
|
||||
for (int i = 0; i < Keys.Count; i++)
|
||||
IndDict.Add(Keys[i], i);
|
||||
return IndDict;
|
||||
}
|
||||
|
||||
public static Pointer<T>[] ToPointerArray<T>(this Dictionary<int, T> val)
|
||||
{
|
||||
Pointer<T>[] arr = new Pointer<T>[val.Count];
|
||||
for (int i = 0; i < val.Count; i++)
|
||||
arr[i] = val.ElementAt(i).ToPointer();
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static Pointer<T> ReadPointer<T>(this Stream IO) =>
|
||||
new Pointer<T> { Offset = IO.ReadInt32() };
|
||||
|
||||
public static Pointer<string> ReadPointerString(this Stream IO)
|
||||
{ Pointer<string> val = IO.ReadPointer<string>();
|
||||
val.Value = IO.ReadStringAtOffset(val.Offset); return val; }
|
||||
|
||||
public static Pointer<string> ReadPointerStringShiftJIS(this Stream IO)
|
||||
{ Pointer<string> val = IO.ReadPointer<string>();
|
||||
val.Value = ShiftJIS.GetString(IO.ReadAtOffset(val.Offset)); return val; }
|
||||
|
||||
public static void WriteShiftJIS(this Stream IO, string String) =>
|
||||
IO.Write(ShiftJIS.GetBytes(String));
|
||||
|
||||
public static CountPointer<T> ReadCountPointer<T>(this Stream IO)
|
||||
{ CountPointer<T> val = new CountPointer<T> { Count = IO.ReadInt32(),
|
||||
Offset = IO.ReadInt32() }; val.Entries = new T[val.Count]; return val; }
|
||||
|
||||
|
||||
public static Pointer<T> ToPointer<T>(this KeyValuePair<int, T> val) =>
|
||||
new Pointer<T> { Offset = val.Key, Value = val.Value };
|
||||
|
||||
public static void ReadMP(this MsgPack msg, ref CountPointer<float> val, string Name)
|
||||
{
|
||||
val.Offset = 0;
|
||||
val.Entries = null;
|
||||
if (msg.ContainsKey(Name))
|
||||
{
|
||||
val.Count = 1;
|
||||
val.Entries[0] = msg.ReadSingle(Name);
|
||||
}
|
||||
else if(msg.Element<MsgPack>(Name, out MsgPack Temp))
|
||||
{
|
||||
val.Count = Temp.Array.Length;
|
||||
for (int i = 0; i < val.Count; i++)
|
||||
if (Temp[i] is MsgPack temp)
|
||||
val.Entries[i] = temp.ReadSingle();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static MsgPack WriteMP(this CountPointer<float> val, string Name)
|
||||
{
|
||||
if (val.Count == 1) return new MsgPack(Name, MsgPack.Types.Float32, val.Entries[0]);
|
||||
else if (val.Count > 1)
|
||||
{
|
||||
MsgPack Val = new MsgPack(Name, val.Count);
|
||||
for (int i = 0; i < val.Count; i++) Val[i] = val.Entries[i];
|
||||
return Val;
|
||||
}
|
||||
return MsgPack.Null;
|
||||
}
|
||||
|
||||
public static int ReadAetObject(this Stream IO, ref Dictionary<int, AetObject> ObjectsDict)
|
||||
{
|
||||
AetObject Anim = new AetObject();
|
||||
int AnimOffset = IO.Position;
|
||||
if (ObjectsDict.ContainsKey(AnimOffset)) return AnimOffset;
|
||||
Anim.Name = IO.ReadPointerString();
|
||||
Anim.StartTime0 = IO.ReadSingle();
|
||||
Anim.LoopDuration = IO.ReadSingle();
|
||||
Anim.StartTime1 = IO.ReadSingle();
|
||||
Anim.PlaybackSpeed = IO.ReadSingle();
|
||||
Anim.Unk0 = IO.ReadByte();
|
||||
Anim.Unk1 = IO.ReadByte();
|
||||
Anim.Unk2 = IO.ReadByte();
|
||||
Anim.Type = (ObjType)IO.ReadByte();
|
||||
if (Anim.Type == ObjType.Pic) Anim.Pic = IO.ReadPic(ref ObjectsDict);
|
||||
else if (Anim.Type == ObjType.Aif) Anim.Aif = IO.ReadAif();
|
||||
else if (Anim.Type == ObjType.Eff) Anim.Eff = IO.ReadEff(ref ObjectsDict);
|
||||
IO.Position = AnimOffset + 0x30;
|
||||
if (!ObjectsDict.ContainsKey(AnimOffset))
|
||||
ObjectsDict.Add(AnimOffset, Anim);
|
||||
return AnimOffset;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ref AetObject Anim, ref List<int> NullValPointers)
|
||||
{
|
||||
if (Anim.Type == ObjType.Pic)
|
||||
{
|
||||
if (Anim.Pic.Value.Marker.Count > 0)
|
||||
{
|
||||
Anim.Pic.Value.Marker.Offset = IO.Position;
|
||||
for (int i = 0; i < Anim.Pic.Value.Marker.Count; i++) IO.Write(0L);
|
||||
}
|
||||
IO.Write(ref Anim.Pic.Value.Data, ref NullValPointers);
|
||||
}
|
||||
else if (Anim.Type == ObjType.Aif) IO.Write(ref Anim.Aif);
|
||||
else if (Anim.Type == ObjType.Eff)
|
||||
{
|
||||
if (Anim.Eff.Value.Marker.Count > 0)
|
||||
{
|
||||
Anim.Eff.Value.Marker.Offset = IO.Position;
|
||||
for (int i = 0; i < Anim.Eff.Value.Marker.Count; i++) IO.Write(0L);
|
||||
}
|
||||
IO.Write(ref Anim.Eff.Value.Data, ref NullValPointers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ref AetObject Anim, ref int Offset)
|
||||
{
|
||||
Offset = IO.Position;
|
||||
IO.Write(0);
|
||||
IO.Write(Anim.StartTime0 );
|
||||
IO.Write(Anim.LoopDuration );
|
||||
IO.Write(Anim.StartTime1 );
|
||||
IO.Write(Anim.PlaybackSpeed);
|
||||
IO.Write(Anim.Unk0);
|
||||
IO.Write(Anim.Unk1);
|
||||
IO.Write(Anim.Unk2);
|
||||
IO.Write((byte)Anim.Type);
|
||||
if (Anim.Type == ObjType.Pic) IO.Write(ref Anim.Pic);
|
||||
else if (Anim.Type == ObjType.Aif)
|
||||
{
|
||||
Anim.Aif.Offset = IO.Position;
|
||||
IO.Write(Anim.Aif.Value.Value.Offset);
|
||||
IO.Write(0L);
|
||||
IO.Write(0L);
|
||||
IO.Write(Anim.Aif.Value.Pointer);
|
||||
}
|
||||
else if (Anim.Type == ObjType.Eff) IO.Write(ref Anim.Eff);
|
||||
else { IO.Write(0L); IO.Write(0L); IO.Write(0L); }
|
||||
}
|
||||
|
||||
public static Pointer<Pic> ReadPic(this Stream IO, ref Dictionary<int, AetObject> ObjectsDict)
|
||||
{
|
||||
Pointer<Pic> Pic = new Pointer<Pic> { Offset = IO.Position,
|
||||
Value = new Pic
|
||||
{
|
||||
SpriteEntryID = IO.ReadInt32(),
|
||||
ParentObjectID = IO.ReadInt32(),
|
||||
Marker = IO.ReadCountPointer<Marker>()
|
||||
}
|
||||
};
|
||||
Pic.Value.Data.Offset = IO.ReadInt32();
|
||||
IO.ReadAnimData(ref Pic.Value.Data);
|
||||
|
||||
IO.Position = Pic.Value.Marker.Offset;
|
||||
for (int i = 0; i < Pic.Value.Marker.Count; i++)
|
||||
{
|
||||
Pic.Value.Marker.Entries[i].Frame = IO.ReadSingle();
|
||||
Pic.Value.Marker.Entries[i]. Name = IO.ReadPointerStringShiftJIS();
|
||||
}
|
||||
|
||||
return Pic;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ref Pointer<Pic> Pic)
|
||||
{
|
||||
Pic.Offset = IO.Position;
|
||||
IO.Write(0L);
|
||||
if (Pic.Value.Marker.Count > 0)
|
||||
{
|
||||
IO.Write(Pic.Value.Marker.Count );
|
||||
IO.Write(Pic.Value.Marker.Offset);
|
||||
}
|
||||
else IO.Write(0L);
|
||||
IO.Write(Pic.Value.Data .Offset);
|
||||
IO.Write(0);
|
||||
}
|
||||
|
||||
public static Pointer<Aif> ReadAif(this Stream IO)
|
||||
{
|
||||
Pointer<Aif> Aif = new Pointer<Aif> { Offset = IO.Position,
|
||||
Value = new Aif
|
||||
{
|
||||
Value = IO.ReadPointer<int>(),
|
||||
Zero0 = IO.ReadInt32(),
|
||||
Zero1 = IO.ReadInt32(),
|
||||
Zero2 = IO.ReadInt32(),
|
||||
Zero3 = IO.ReadInt32(),
|
||||
Pointer = IO.ReadInt32(),
|
||||
}
|
||||
};
|
||||
|
||||
IO.Position = Aif.Value.Value.Offset;
|
||||
Aif.Value.Value.Value = IO.ReadInt32();
|
||||
|
||||
IO.Position = Aif.Value.Pointer;
|
||||
Aif.Value.Unk0 = IO.ReadCountPointer<float>();
|
||||
Aif.Value.Unk1 = IO.ReadCountPointer<float>();
|
||||
Aif.Value.Unk2 = IO.ReadCountPointer<float>();
|
||||
Aif.Value.Unk3 = IO.ReadCountPointer<float>();
|
||||
|
||||
IO.Position = Aif.Value.Unk0.Offset;
|
||||
for (int i = 0; i < Aif.Value.Unk0.Count; i++) Aif.Value.Unk0.Entries[i] = IO.ReadSingle();
|
||||
IO.Position = Aif.Value.Unk1.Offset;
|
||||
for (int i = 0; i < Aif.Value.Unk1.Count; i++) Aif.Value.Unk1.Entries[i] = IO.ReadSingle();
|
||||
IO.Position = Aif.Value.Unk2.Offset;
|
||||
for (int i = 0; i < Aif.Value.Unk2.Count; i++) Aif.Value.Unk2.Entries[i] = IO.ReadSingle();
|
||||
IO.Position = Aif.Value.Unk3.Offset;
|
||||
for (int i = 0; i < Aif.Value.Unk3.Count; i++) Aif.Value.Unk3.Entries[i] = IO.ReadSingle();
|
||||
|
||||
return Aif;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ref Pointer<Aif> Aif)
|
||||
{
|
||||
if (Aif.Value.Unk0.Count > 0) { Aif.Value.Unk0.Offset = IO.Position;
|
||||
for (int i = 0; i < Aif.Value.Unk0.Count; i++) IO.Write(Aif.Value.Unk0.Entries[i]); }
|
||||
if (Aif.Value.Unk1.Count > 0) { Aif.Value.Unk1.Offset = IO.Position;
|
||||
for (int i = 0; i < Aif.Value.Unk1.Count; i++) IO.Write(Aif.Value.Unk1.Entries[i]); }
|
||||
if (Aif.Value.Unk2.Count > 0) { Aif.Value.Unk2.Offset = IO.Position;
|
||||
for (int i = 0; i < Aif.Value.Unk2.Count; i++) IO.Write(Aif.Value.Unk2.Entries[i]); }
|
||||
if (Aif.Value.Unk3.Count > 0) { Aif.Value.Unk3.Offset = IO.Position;
|
||||
for (int i = 0; i < Aif.Value.Unk3.Count; i++) IO.Write(Aif.Value.Unk3.Entries[i]); }
|
||||
|
||||
IO.Align(0x10);
|
||||
Aif.Value.Value.Offset = IO.Position;
|
||||
IO.Write(Aif.Value.Value.Value);
|
||||
|
||||
IO.Align(0x10);
|
||||
Aif.Value.Pointer = IO.Position;
|
||||
if (Aif.Value.Unk0.Count > 0) { IO.Write(Aif.Value.Unk0.Count); IO.Write(Aif.Value.Unk0.Offset); }
|
||||
else IO.Write(0L);
|
||||
if (Aif.Value.Unk1.Count > 0) { IO.Write(Aif.Value.Unk1.Count); IO.Write(Aif.Value.Unk1.Offset); }
|
||||
else IO.Write(0L);
|
||||
if (Aif.Value.Unk2.Count > 0) { IO.Write(Aif.Value.Unk2.Count); IO.Write(Aif.Value.Unk2.Offset); }
|
||||
else IO.Write(0L);
|
||||
if (Aif.Value.Unk3.Count > 0) { IO.Write(Aif.Value.Unk3.Count); IO.Write(Aif.Value.Unk3.Offset); }
|
||||
else IO.Write(0L);
|
||||
}
|
||||
|
||||
public static Pointer<Eff> ReadEff(this Stream IO, ref Dictionary<int, AetObject> ObjectsDict)
|
||||
{
|
||||
Pointer<Eff> Eff = new Pointer<Eff> { Offset = IO.Position,
|
||||
Value = new Eff
|
||||
{
|
||||
LayerID = IO.ReadInt32(),
|
||||
ParentObjectID = IO.ReadInt32(),
|
||||
Marker = IO.ReadCountPointer<Marker>()
|
||||
}
|
||||
};
|
||||
Eff.Value.Data.Offset = IO.ReadInt32();
|
||||
IO.Position = Eff.Value.LayerID;
|
||||
CountPointer<AetObject> AetObjEntry = IO.ReadCountPointer<AetObject>();
|
||||
IO.Position = AetObjEntry.Offset;
|
||||
for (int i = 0; i < AetObjEntry.Count; i++) IO.ReadAetObject(ref ObjectsDict);
|
||||
IO.Position = Eff.Value.Marker.Offset;
|
||||
for (int i = 0; i < Eff.Value.Marker.Count; i++)
|
||||
{
|
||||
Eff.Value.Marker.Entries[i].Frame = IO.ReadSingle();
|
||||
Eff.Value.Marker.Entries[i]. Name = IO.ReadPointerStringShiftJIS();
|
||||
}
|
||||
IO.ReadAnimData(ref Eff.Value.Data);
|
||||
|
||||
return Eff;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ref Pointer<Eff> Eff)
|
||||
{
|
||||
Eff.Offset = IO.Position;
|
||||
IO.Write(0L);
|
||||
if (Eff.Value.Marker.Count > 0)
|
||||
{
|
||||
IO.Write(Eff.Value.Marker.Count );
|
||||
IO.Write(Eff.Value.Marker.Offset);
|
||||
}
|
||||
else IO.Write(0L);
|
||||
IO.Write(Eff.Value.Data.Offset);
|
||||
IO.Write(0);
|
||||
}
|
||||
|
||||
public static void ReadAnimData(this Stream IO, ref Pointer<AnimationData> Anim)
|
||||
{
|
||||
ref AnimationData Data = ref Anim.Value;
|
||||
IO.Position = Anim.Offset;
|
||||
Data.BlendMode = (BlendMode)IO.ReadByte();
|
||||
Data.Unk0 = IO.ReadByte();
|
||||
Data.UseTextureMask = IO.ReadBoolean();
|
||||
Data.Unk1 = IO.ReadByte();
|
||||
Data.Anim = IO.ReadSubAnimData();
|
||||
Data.SubAnim = IO.ReadPointer<SubAnimationData>();
|
||||
|
||||
IO.ReadSubAnimData(ref Data.Anim);
|
||||
|
||||
if (Data.SubAnim.Offset > 0)
|
||||
{
|
||||
IO.Position = Data.SubAnim.Offset;
|
||||
Data.SubAnim.Value = IO.ReadSubAnimData();
|
||||
IO.ReadSubAnimData(ref Data.SubAnim.Value);
|
||||
}
|
||||
}
|
||||
|
||||
public static SubAnimationData ReadSubAnimData(this Stream IO)
|
||||
{
|
||||
SubAnimationData Data = new SubAnimationData() { };
|
||||
Data. OriginX = IO.ReadKeyFrameEntry();
|
||||
Data. OriginY = IO.ReadKeyFrameEntry();
|
||||
Data.PositionX = IO.ReadKeyFrameEntry();
|
||||
Data.PositionY = IO.ReadKeyFrameEntry();
|
||||
Data.Rotation = IO.ReadKeyFrameEntry();
|
||||
Data. ScaleX = IO.ReadKeyFrameEntry();
|
||||
Data. ScaleY = IO.ReadKeyFrameEntry();
|
||||
Data.Opacity = IO.ReadKeyFrameEntry();
|
||||
return Data;
|
||||
}
|
||||
|
||||
public static void ReadSubAnimData(this Stream IO, ref SubAnimationData Data)
|
||||
{
|
||||
IO.ReadKeyFrameEntry(ref Data. OriginX);
|
||||
IO.ReadKeyFrameEntry(ref Data. OriginY);
|
||||
IO.ReadKeyFrameEntry(ref Data.PositionX);
|
||||
IO.ReadKeyFrameEntry(ref Data.PositionY);
|
||||
IO.ReadKeyFrameEntry(ref Data.Rotation );
|
||||
IO.ReadKeyFrameEntry(ref Data. ScaleX);
|
||||
IO.ReadKeyFrameEntry(ref Data. ScaleY);
|
||||
IO.ReadKeyFrameEntry(ref Data.Opacity );
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ref Pointer<AnimationData> Anim, ref List<int> NullValPointers)
|
||||
{
|
||||
ref AnimationData Data = ref Anim.Value;
|
||||
|
||||
byte SubFlags = 0;
|
||||
if (Data.SubAnim.Offset > -1)
|
||||
SubFlags = IO.Write(ref Data.SubAnim.Value);
|
||||
|
||||
byte Flags = IO.Write(ref Data.Anim);
|
||||
|
||||
if (Data.SubAnim.Offset > -1)
|
||||
{
|
||||
IO.Align(0x20);
|
||||
Data.SubAnim.Offset = IO.Position;
|
||||
IO.Write(ref Data.SubAnim.Value, ref NullValPointers, Flags);
|
||||
}
|
||||
|
||||
IO.Align(0x20);
|
||||
Anim.Offset = IO.Position;
|
||||
IO.WriteByte((byte) Data.BlendMode);
|
||||
IO.WriteByte( Data.Unk0);
|
||||
IO.WriteByte((byte)(Data.UseTextureMask ? 1 : 0));
|
||||
IO.WriteByte( Data.Unk1);
|
||||
|
||||
IO.Write(ref Data.Anim, ref NullValPointers, Flags);
|
||||
IO.Write(Data.SubAnim.Offset > -1 ? Data.SubAnim.Offset : 0);
|
||||
}
|
||||
|
||||
public static byte Write(this Stream IO, ref SubAnimationData Data)
|
||||
{
|
||||
int Flags = 0;
|
||||
Flags |= IO.Write(ref Data. OriginX) ? 0b10000000 : 0;
|
||||
Flags |= IO.Write(ref Data. OriginY) ? 0b01000000 : 0;
|
||||
Flags |= IO.Write(ref Data.PositionX) ? 0b00100000 : 0;
|
||||
Flags |= IO.Write(ref Data.PositionY) ? 0b00010000 : 0;
|
||||
Flags |= IO.Write(ref Data.Rotation ) ? 0b00001000 : 0;
|
||||
Flags |= IO.Write(ref Data. ScaleX) ? 0b00000100 : 0;
|
||||
Flags |= IO.Write(ref Data. ScaleY) ? 0b00000010 : 0;
|
||||
Flags |= IO.Write(ref Data.Opacity ) ? 0b00000001 : 0;
|
||||
return (byte)Flags;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ref SubAnimationData Data, ref List<int> NullValPointers, byte Flags)
|
||||
{
|
||||
IO.Write(Data. OriginX.Count );
|
||||
if ((Flags & 0b10000000) == 0b10000000) NullValPointers.Add(IO.Position);
|
||||
IO.Write(Data. OriginX.Offset);
|
||||
IO.Write(Data. OriginY.Count );
|
||||
if ((Flags & 0b01000000) == 0b01000000) NullValPointers.Add(IO.Position);
|
||||
IO.Write(Data. OriginY.Offset);
|
||||
IO.Write(Data.PositionX.Count );
|
||||
if ((Flags & 0b00100000) == 0b00100000) NullValPointers.Add(IO.Position);
|
||||
IO.Write(Data.PositionX.Offset);
|
||||
IO.Write(Data.PositionY.Count );
|
||||
if ((Flags & 0b00010000) == 0b00010000) NullValPointers.Add(IO.Position);
|
||||
IO.Write(Data.PositionY.Offset);
|
||||
IO.Write(Data.Rotation .Count );
|
||||
if ((Flags & 0b00001000) == 0b00001000) NullValPointers.Add(IO.Position);
|
||||
IO.Write(Data.Rotation .Offset);
|
||||
IO.Write(Data. ScaleX.Count );
|
||||
if ((Flags & 0b00000100) == 0b00000100) NullValPointers.Add(IO.Position);
|
||||
IO.Write(Data. ScaleX.Offset);
|
||||
IO.Write(Data. ScaleY.Count );
|
||||
if ((Flags & 0b00000010) == 0b00000010) NullValPointers.Add(IO.Position);
|
||||
IO.Write(Data. ScaleY.Offset);
|
||||
IO.Write(Data.Opacity .Count );
|
||||
if ((Flags & 0b00000001) == 0b00000001) NullValPointers.Add(IO.Position);
|
||||
IO.Write(Data.Opacity .Offset);
|
||||
}
|
||||
|
||||
public static KeyFrameEntry ReadKeyFrameEntry(this Stream IO) =>
|
||||
new KeyFrameEntry { Count = IO.ReadInt32(), Offset = IO.ReadInt32() };
|
||||
|
||||
public static void ReadKeyFrameEntry(this Stream IO, ref KeyFrameEntry entry)
|
||||
{
|
||||
if (entry.Count < 1) return;
|
||||
IO.Position = entry.Offset;
|
||||
if (entry.Count == 1) { entry.Value = IO.ReadSingle(); return; }
|
||||
|
||||
entry.Interpolation = new float[entry.Count];
|
||||
entry.KeyFrame = new float[entry.Count];
|
||||
entry.ArrValue = new float[entry.Count];
|
||||
for (int i = 0; i < entry.Count; i++) entry.KeyFrame [i] = IO.ReadSingle();
|
||||
for (int i = 0; i < entry.Count; i++)
|
||||
{ entry.ArrValue[i] = IO.ReadSingle(); entry.Interpolation[i] = IO.ReadSingle(); }
|
||||
}
|
||||
|
||||
public static bool Write(this Stream IO, ref KeyFrameEntry entry)
|
||||
{
|
||||
if (entry.Count == 0) return false;
|
||||
|
||||
if (entry.Count > 2) IO.Align(0x20);
|
||||
entry.Offset = IO.Position;
|
||||
if (entry.Count == 1) if (entry.Value == 0) return true;
|
||||
else { IO.Write(entry.Value); return false; }
|
||||
|
||||
for (int i = 0; i < entry.Count; i++) IO.Write(entry.KeyFrame [i]);
|
||||
for (int i = 0; i < entry.Count; i++)
|
||||
{ IO.Write(entry.ArrValue[i]); IO.Write(entry.Interpolation[i]); }
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void ReadMP(this CountPointer<Marker> mark, MsgPack msg)
|
||||
{
|
||||
if (msg.Element("Marker", out MsgPack Marker))
|
||||
{
|
||||
mark.Count = 1;
|
||||
mark.Entries[0].ReadMP(Marker);
|
||||
}
|
||||
else if (msg.Element<MsgPack>("Markers", out MsgPack Markers))
|
||||
{
|
||||
mark.Count = Markers.Array.Length;
|
||||
for (int i = 0; i < mark.Count; i++)
|
||||
mark.Entries[i].ReadMP(Markers[i] as MsgPack);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WritePointerString(this Stream IO,
|
||||
ref Dictionary<string, int> Dict, ref Pointer<string> Str)
|
||||
{
|
||||
if (Dict.ContainsKey(Str.Value)) Str.Offset = Dict[Str.Value];
|
||||
else
|
||||
{ Str.Offset = IO.Position; Dict.Add(Str.Value, Str.Offset); IO.WriteShiftJIS(Str.Value + "\0"); }
|
||||
}
|
||||
}
|
||||
}
|
||||
+66
-62
@@ -1,8 +1,8 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.DB
|
||||
{
|
||||
@@ -17,31 +17,31 @@ namespace KKdMainLib.DB
|
||||
{
|
||||
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.I64P += 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();
|
||||
}
|
||||
|
||||
|
||||
@@ -138,67 +138,69 @@ namespace KKdMainLib.DB
|
||||
i1 = i1.Align(0x20) + 0x20;
|
||||
|
||||
IO = File.OpenWriter(file + ".bin", true);
|
||||
IO.Write(i2);
|
||||
IO.Write(i1);
|
||||
IO.Write(i0);
|
||||
IO.Write(0x20);
|
||||
IO.Write(0x9066906690669066);
|
||||
IO.Write(0x9066906690669066);
|
||||
IO.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).Align(0x20);
|
||||
for (i = 0; i < AetSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) continue;
|
||||
AetSets[i]. NameOffset = IO.Position; IO.Write(AetSets[i]. Name + "\0");
|
||||
AetSets[i].FileNameOffset = IO.Position; IO.Write(AetSets[i].FileName + "\0");
|
||||
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.A(0x08, true);
|
||||
|
||||
IO.Position = 0x20;
|
||||
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)
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
|
||||
if (MsgPack.Element<MsgPack>("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] as MsgPack);
|
||||
AetSets[i].ReadMsgPack(Temp[i]);
|
||||
}
|
||||
MsgPack = null;
|
||||
Temp.Dispose();
|
||||
MsgPack.Dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -207,7 +209,7 @@ namespace KKdMainLib.DB
|
||||
if (AetSets == null) return;
|
||||
if (AetSets.Length == 0) return;
|
||||
|
||||
MsgPack AetDB = new MsgPack("AetDB", AetSets.Length);
|
||||
MsgPack AetDB = new MsgPack(AetSets.Length, "AetDB");
|
||||
for (i = 0; i < AetSets.Length; i++)
|
||||
AetDB[i] = AetSets[i].WriteMsgPack();
|
||||
|
||||
@@ -221,10 +223,10 @@ 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() =>
|
||||
new MsgPack().Add("Id", Id).Add("Name", Name);
|
||||
MsgPack.New.Add("Id", Id).Add("Name", Name);
|
||||
}
|
||||
|
||||
public struct AetSet
|
||||
@@ -240,27 +242,29 @@ namespace KKdMainLib.DB
|
||||
|
||||
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.Element<MsgPack>("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] as MsgPack);
|
||||
Aets = new AET[Temp.Array.Length];
|
||||
for (int i0 = 0; i0 < Aets.Length; i0++)
|
||||
Aets[i0].ReadMsgPack(Temp[i0]);
|
||||
}
|
||||
Temp.Dispose();
|
||||
}
|
||||
|
||||
public MsgPack WriteMsgPack()
|
||||
{
|
||||
MsgPack Aets = new MsgPack("Aets", this.Aets.Length);
|
||||
MsgPack Aets = new MsgPack(this.Aets.Length, "Aets");
|
||||
for (int i0 = 0; i0 < this.Aets.Length; i0++)
|
||||
Aets[i0] = this.Aets[i0].WriteMsgPack();
|
||||
|
||||
return new MsgPack().Add("FileName", FileName).Add("Id", Id)
|
||||
return MsgPack.New.Add("FileName", FileName).Add("Id", Id)
|
||||
.Add("Name", Name).Add("SpriteSetId", SpriteSetId).Add(Aets);
|
||||
}
|
||||
}
|
||||
|
||||
+42
-47
@@ -1,8 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.A3DA;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.DB
|
||||
{
|
||||
@@ -20,14 +19,14 @@ namespace KKdMainLib.DB
|
||||
|
||||
IO = File.OpenReader(file + ".bin");
|
||||
|
||||
IO.Format = Main.Format.F;
|
||||
Signature = IO.ReadInt32();
|
||||
IO.Format = Format.F;
|
||||
Signature = IO.RI32();
|
||||
if (Signature != 0x44334123) return;
|
||||
Signature = IO.ReadInt32();
|
||||
Signature = IO.RI32();
|
||||
if (Signature != 0x5F5F5F41) return;
|
||||
IO.ReadInt64();
|
||||
IO.RI64();
|
||||
|
||||
string[] STRData = IO.ReadString(IO.Length - IO.Position).Replace("\r", "").Split('\n');
|
||||
string[] STRData = IO.RS(IO.L - IO.P).Replace("\r", "").Split('\n');
|
||||
for (int i = 0; i < STRData.Length; i++)
|
||||
{
|
||||
dataArray = STRData[i].Split('=');
|
||||
@@ -55,24 +54,23 @@ namespace KKdMainLib.DB
|
||||
}
|
||||
}
|
||||
|
||||
IO.Close();
|
||||
IO.C();
|
||||
}
|
||||
|
||||
public void BINWriter(string file)
|
||||
{
|
||||
IO = File.OpenWriter(file + ".bin", true);
|
||||
|
||||
IO.Write("#A3DA__________\n");
|
||||
IO.Write("#", DateTime.UtcNow.ToString("ddd MMM dd HH:mm:ss yyyy",
|
||||
IO.W("#A3DA__________\n");
|
||||
IO.W("#", DateTime.UtcNow.ToString("ddd MMM dd HH:mm:ss yyyy",
|
||||
System.Globalization.CultureInfo.InvariantCulture));
|
||||
|
||||
if (Category != null)
|
||||
{
|
||||
int[] SO = Category.Length.SortWriter();
|
||||
for (int i = 0; i < Category.Length; i++)
|
||||
if (Category[SO[i]] != null)
|
||||
IO.Write("category." + SO[i] + ".value=", Category[SO[i]]);
|
||||
IO.Write("category.length=", Category.Length);
|
||||
IO.W("category." + SO[i] + ".value=", Category[SO[i]]);
|
||||
IO.W("category.length=", Category.Length);
|
||||
}
|
||||
|
||||
if (_UID != null)
|
||||
@@ -80,51 +78,49 @@ namespace KKdMainLib.DB
|
||||
int[] SO = _UID.Length.SortWriter();
|
||||
for (int i = 0; i < _UID.Length; i++)
|
||||
{
|
||||
if (_UID[SO[i]].Category != null)
|
||||
if (_UID[SO[i]].Category != "")
|
||||
IO.Write("uid." + SO[i] + ".category=", _UID[SO[i]].Category);
|
||||
if (_UID[SO[i]].OrgUid != null)
|
||||
IO.Write("uid." + SO[i] + ".org_uid=" , _UID[SO[i]].OrgUid );
|
||||
if (_UID[SO[i]].Size != null)
|
||||
IO.Write("uid." + SO[i] + ".size=" , _UID[SO[i]].Size );
|
||||
if (_UID[SO[i]].Value != null)
|
||||
if (_UID[SO[i]].Value != "")
|
||||
IO.Write("uid." + SO[i] + ".value=" , _UID[SO[i]].Value );
|
||||
if (_UID[SO[i]].Category != "")
|
||||
IO.W("uid." + SO[i] + ".category=", _UID[SO[i]].Category);
|
||||
IO.W("uid." + SO[i] + ".org_uid=" , _UID[SO[i]].OrgUid );
|
||||
IO.W("uid." + SO[i] + ".size=" , _UID[SO[i]].Size );
|
||||
if (_UID[SO[i]].Value != "")
|
||||
IO.W("uid." + SO[i] + ".value=" , _UID[SO[i]].Value );
|
||||
}
|
||||
IO.Write("uid.length=", _UID.Length);
|
||||
IO.W("uid.length=", _UID.Length);
|
||||
}
|
||||
|
||||
IO.Close();
|
||||
IO.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
|
||||
if (MsgPack.Element("AuthDB", out MsgPack AuthDB))
|
||||
MsgPack AuthDB;
|
||||
if ((AuthDB = MsgPack["AuthDB"]).NotNull)
|
||||
{
|
||||
if (AuthDB.Element("Category", out MsgPack Temp))
|
||||
MsgPack Temp;
|
||||
if ((Temp = MsgPack["Category", true]).NotNull)
|
||||
{
|
||||
this.Category = new string[Temp.Array.Length];
|
||||
for (int i = 0; i < this.Category.Length; i++)
|
||||
this.Category[i] = (Temp[i] as MsgPack).ReadString();
|
||||
Category = new string[Temp.Array.Length];
|
||||
for (int i = 0; i < Category.Length; i++)
|
||||
Category[i] = Temp[i].RS();
|
||||
}
|
||||
|
||||
if (AuthDB.Element("UID", out Temp))
|
||||
if ((Temp = MsgPack["UID", true]).NotNull)
|
||||
{
|
||||
_UID = new UID[Temp.Array.Length];
|
||||
MsgPack UID;
|
||||
for (int i = 0; i < _UID.Length; i++)
|
||||
{
|
||||
UID = Temp[i] as MsgPack;
|
||||
_UID[i].Category = UID.ReadString("C");
|
||||
_UID[i].OrgUid = UID.ReadNInt32("O");
|
||||
_UID[i].Size = UID.ReadNInt32("S");
|
||||
_UID[i].Value = UID.ReadString("V");
|
||||
_UID[i].Category = Temp[i].RS("Category");
|
||||
_UID[i].OrgUid = Temp[i].RnI32("OrgUid" );
|
||||
_UID[i].Size = Temp[i].RnI32("Size" );
|
||||
_UID[i].Value = Temp[i].RS("Value" );
|
||||
}
|
||||
}
|
||||
Temp.Dispose();
|
||||
}
|
||||
MsgPack = null;
|
||||
AuthDB.Dispose();
|
||||
MsgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
@@ -132,21 +128,20 @@ namespace KKdMainLib.DB
|
||||
MsgPack AuthDB = new MsgPack("AuthDB");
|
||||
if (Category != null)
|
||||
{
|
||||
MsgPack Category = new MsgPack("Category", this.Category.Length);
|
||||
MsgPack Category = new MsgPack(this.Category.Length, "Category");
|
||||
for (int i = 0; i < this.Category.Length; i++)
|
||||
Category[i] = this.Category[i];
|
||||
Category[i] = (MsgPack)this.Category[i];
|
||||
AuthDB.Add(Category);
|
||||
}
|
||||
|
||||
if (_UID != null)
|
||||
{
|
||||
MsgPack UID = new MsgPack("UID", _UID.Length);
|
||||
MsgPack UID = new MsgPack(_UID.Length, "UID");
|
||||
for (int i = 0; i < _UID.Length; i++)
|
||||
UID[i] = new MsgPack()
|
||||
.Add("C", _UID[i].Category)
|
||||
.Add("O", _UID[i].OrgUid )
|
||||
.Add("S", _UID[i].Size )
|
||||
.Add("V", _UID[i].Value );
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
// Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary
|
||||
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.Types;
|
||||
using KKdMainLib.MessagePack;
|
||||
using MPIO = KKdMainLib.MessagePack.IO;
|
||||
|
||||
namespace KKdMainLib.DB
|
||||
{
|
||||
public class BoneData
|
||||
{
|
||||
public Stream IO;
|
||||
public BONE Data;
|
||||
|
||||
private int i, i0;
|
||||
|
||||
public BoneData()
|
||||
{ Data = new BONE(); }
|
||||
|
||||
public void BONReader(string file, string ext)
|
||||
{
|
||||
Data = new BONE { Header = new PDHead() };
|
||||
IO = File.OpenReader(file + ext);
|
||||
|
||||
IO.Format = Main.Format.F;
|
||||
Data.Header.Signature = IO.ReadInt32();
|
||||
if (Data.Header.Signature == 0x454E4F42)
|
||||
{
|
||||
Data.Header = IO.ReadHeader(true);
|
||||
Data.POF = Data.Header.AddPOF();
|
||||
}
|
||||
if (Data.Header.Signature != 0x09102720)
|
||||
return;
|
||||
|
||||
Data.Skeleton = new SkeletonEntry[IO.ReadInt32Endian()];
|
||||
Data.SkeletonsOffset = IO.ReadUInt32Endian(ref Data.POF);
|
||||
Data.SkeletonNamesOffset = IO.ReadUInt32Endian();
|
||||
if (Data.SkeletonNamesOffset == 0)
|
||||
{
|
||||
IO.IsX = true;
|
||||
IO.Format = Main.Format.X;
|
||||
Data.POF.POFOffsets = new List<long>();
|
||||
IO.Seek(Data.Header.Lenght, 0);
|
||||
IO.LongOffset = Data.Header.Lenght;
|
||||
Data.Header.Signature = IO.ReadInt32();
|
||||
Data.Skeleton = new SkeletonEntry[IO.ReadInt32Endian()];
|
||||
Data.SkeletonsOffset = IO.ReadInt64();
|
||||
Data.SkeletonNamesOffset = IO.ReadInt64(ref Data.POF);
|
||||
}
|
||||
else
|
||||
{
|
||||
IO.LongPosition -= 4;
|
||||
IO.GetOffset(ref Data.POF);
|
||||
IO.LongPosition += 4;
|
||||
}
|
||||
|
||||
Data.SkeletonEntryOffset = new long[Data.Skeleton.Length];
|
||||
IO.LongPosition = Data.SkeletonsOffset;
|
||||
for (i0 = 0; i0 < Data.Skeleton.Length; i0++)
|
||||
Data.SkeletonEntryOffset[i0] = IO.ReadIntX(ref Data.POF);
|
||||
|
||||
for (i0 = 0; i0 < Data.Skeleton.Length; i0++)
|
||||
{
|
||||
Data.Skeleton[i0] = new SkeletonEntry();
|
||||
IO.LongPosition = Data.SkeletonEntryOffset[i0];
|
||||
|
||||
Data.Skeleton[i0].BoneOffset = IO.ReadIntX(ref Data.POF);
|
||||
Data.Skeleton[i0].Position = new Vector3<float>[IO.ReadIntX()];
|
||||
Data.Skeleton[i0].PositionOffset = IO.ReadIntX(ref Data.POF);
|
||||
Data.Skeleton[i0].Field02Offset = IO.ReadIntX(ref Data.POF);
|
||||
Data.Skeleton[i0].BoneName1 = new string[IO.ReadIntX()];
|
||||
Data.Skeleton[i0].BoneName1Offset = IO.ReadIntX(ref Data.POF);
|
||||
Data.Skeleton[i0].BoneName2 = new string[IO.ReadIntX()];
|
||||
Data.Skeleton[i0].BoneName2Offset = IO.ReadIntX(ref Data.POF);
|
||||
Data.Skeleton[i0].ParentIndiceOffset = IO.ReadIntX(ref Data.POF);
|
||||
|
||||
IO.LongPosition = Data.SkeletonNamesOffset + i0 << (IO.IsX ? 3 : 2);
|
||||
|
||||
Data.Skeleton[i0].Name = IO.ReadStringAtOffset(ref Data.POF);
|
||||
IO.LongPosition = Data.Skeleton[i0].BoneOffset;
|
||||
|
||||
long Count = 0;
|
||||
string Name = "";
|
||||
while (true)
|
||||
{
|
||||
IO.ReadUInt64();
|
||||
Name = IO.ReadStringAtOffset(ref Data.POF);
|
||||
if (Name == "End") break;
|
||||
Count++;
|
||||
}
|
||||
|
||||
Data.Skeleton[i0].Bone = new BoneEntry[Count];
|
||||
for (i = 0; i < Count; i++)
|
||||
{
|
||||
Data.Skeleton[i0].Bone[i].Type = (BoneType)IO.ReadByte ();
|
||||
Data.Skeleton[i0].Bone[i].HasParent = IO.ReadBoolean();
|
||||
Data.Skeleton[i0].Bone[i].ParentNameIndex = IO.ReadByte ();
|
||||
Data.Skeleton[i0].Bone[i].Field01 = IO.ReadByte ();
|
||||
Data.Skeleton[i0].Bone[i].PairNameIndex = IO.ReadByte ();
|
||||
Data.Skeleton[i0].Bone[i].Field02 = IO.ReadByte ();
|
||||
IO.ReadInt16Endian();
|
||||
Data.Skeleton[i0].Bone[i].Name = IO.ReadStringAtOffset(ref Data.POF);
|
||||
}
|
||||
|
||||
IO.LongPosition = Data.Skeleton[i0].PositionOffset;
|
||||
for (i = 0; i < Data.Skeleton[i0].Position.Length; i++)
|
||||
Data.Skeleton[i0].Position[i] = new Vector3<float>(IO.ReadSingleEndian(),
|
||||
IO.ReadSingleEndian(), IO.ReadSingleEndian());
|
||||
|
||||
IO.LongPosition = Data.Skeleton[i0].Field02Offset;
|
||||
Data.Skeleton[i0].Field02 = IO.ReadIntX();
|
||||
|
||||
IO.LongPosition = Data.Skeleton[i0].BoneName1Offset;
|
||||
for (i = 0; i < Data.Skeleton[i0].BoneName1.Length; i++)
|
||||
Data.Skeleton[i0].BoneName1[i] = IO.ReadStringAtOffset(ref Data.POF);
|
||||
|
||||
IO.LongPosition = Data.Skeleton[i0].BoneName2Offset;
|
||||
for (i = 0; i < Data.Skeleton[i0].BoneName2.Length; i++)
|
||||
Data.Skeleton[i0].BoneName2[i] = IO.ReadStringAtOffset(ref Data.POF);
|
||||
|
||||
IO.LongPosition = Data.Skeleton[i0].ParentIndiceOffset;
|
||||
for (i = 0; i < Data.Skeleton[i0].BoneName2.Length; i++)
|
||||
Data.Skeleton[i0].ParentIndice[i] = IO.ReadInt16Endian();
|
||||
}
|
||||
if (IO.Format > Main.Format.F)
|
||||
{
|
||||
IO.LongPosition = Data.POF.Offset;
|
||||
IO.ReadPOF(ref Data.POF);
|
||||
}
|
||||
IO.Close();
|
||||
}
|
||||
|
||||
public void BONWriter(string file, Main.Format Format)
|
||||
{
|
||||
IO = File.OpenWriter(file + ".bon", true);
|
||||
IO.Close();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
|
||||
MsgPack = null;
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
{
|
||||
MsgPack BoneDB = new MsgPack("BoneDB", Data.Skeleton.Length);
|
||||
for (i0 = 0; i0 < Data.Skeleton.Length; i0++)
|
||||
{
|
||||
MsgPack Skeleton = new MsgPack().Add("Name" , Data.Skeleton[i0].Name )
|
||||
.Add("Field02", Data.Skeleton[i0].Field02);
|
||||
|
||||
MsgPack Bone = new MsgPack("Bone", Data.Skeleton[i0].Bone.Length);
|
||||
for (i = 0; i < Data.Skeleton[i0].Bone.Length; i++)
|
||||
Bone[i] = new MsgPack().Add("Type" , (byte) Data.Skeleton[i0].Bone[i].Type )
|
||||
.Add("HasParent" , Data.Skeleton[i0].Bone[i].HasParent )
|
||||
.Add("ParentNameIndex", Data.Skeleton[i0].Bone[i].ParentNameIndex)
|
||||
.Add("Field01" , Data.Skeleton[i0].Bone[i].Field01 )
|
||||
.Add("PairNameIndex" , Data.Skeleton[i0].Bone[i].PairNameIndex )
|
||||
.Add("Field02" , Data.Skeleton[i0].Bone[i].Field02 )
|
||||
.Add("Name" , Data.Skeleton[i0].Bone[i].Name );
|
||||
Skeleton.Add(Bone);
|
||||
|
||||
MsgPack Position = new MsgPack("Position", Data.Skeleton[i0].Position.Length);
|
||||
for (i = 0; i < Data.Skeleton[i0].Position.Length; i++)
|
||||
Position[i] = new MsgPack().Add("X", Data.Skeleton[i0].Position[i].X)
|
||||
.Add("Y", Data.Skeleton[i0].Position[i].Y)
|
||||
.Add("Z", Data.Skeleton[i0].Position[i].Z);
|
||||
Skeleton.Add(Position);
|
||||
|
||||
MsgPack BoneName1 = new MsgPack("BoneName1", Data.Skeleton[i0].BoneName1.Length);
|
||||
for (i = 0; i < Data.Skeleton[i0].BoneName1.Length; i++)
|
||||
BoneName1[i] = Data.Skeleton[i0].BoneName1[i];
|
||||
Skeleton.Add(BoneName1);
|
||||
|
||||
MsgPack BoneName2 = new MsgPack("BoneName2", Data.Skeleton[i0].BoneName2.Length);
|
||||
for (i = 0; i < Data.Skeleton[i0].BoneName2.Length; i++)
|
||||
BoneName2[i] = Data.Skeleton[i0].BoneName2[i];
|
||||
Skeleton.Add(BoneName2);
|
||||
|
||||
MsgPack ParentIndice = new MsgPack("ParentIndice", Data.Skeleton[i0].ParentIndice.Length);
|
||||
for (i = 0; i < Data.Skeleton[i0].ParentIndice.Length; i++)
|
||||
ParentIndice[i] = Data.Skeleton[i0].ParentIndice[i];
|
||||
BoneDB[i0] = Skeleton.Add(ParentIndice);
|
||||
}
|
||||
|
||||
BoneDB.Write(true, file, JSON);
|
||||
}
|
||||
|
||||
/*public struct Bone
|
||||
{
|
||||
public List<string> Names;
|
||||
public List<long> Offsets;
|
||||
}*/
|
||||
|
||||
public struct BONE
|
||||
{
|
||||
public long SkeletonsOffset;
|
||||
public long SkeletonNamesOffset;
|
||||
public POF POF;
|
||||
public PDHead Header;
|
||||
public long[] SkeletonEntryOffset;
|
||||
public SkeletonEntry[] Skeleton;
|
||||
}
|
||||
|
||||
public struct BoneEntry
|
||||
{
|
||||
public bool HasParent;
|
||||
public byte Field01;
|
||||
public byte Field02;
|
||||
public byte PairNameIndex;
|
||||
public byte ParentNameIndex;
|
||||
public string Name;
|
||||
public BoneType Type;
|
||||
}
|
||||
|
||||
public enum BoneType : byte
|
||||
{
|
||||
Rotation = 0,
|
||||
Type1 = 1,
|
||||
Position = 2,
|
||||
Type3 = 3,
|
||||
Type4 = 4,
|
||||
Type5 = 5,
|
||||
Type6 = 6,
|
||||
};
|
||||
|
||||
public struct SkeletonEntry
|
||||
{
|
||||
public long BoneOffset;
|
||||
public long Field02Offset;
|
||||
public long PositionOffset;
|
||||
public long BoneName1Offset;
|
||||
public long BoneName2Offset;
|
||||
public long ParentIndiceOffset;
|
||||
|
||||
public long Field02;
|
||||
public string Name;
|
||||
public short[] ParentIndice;
|
||||
public string[] BoneName1;
|
||||
public string[] BoneName2;
|
||||
public BoneEntry[] Bone;
|
||||
public Vector3<float>[] Position;
|
||||
}
|
||||
}
|
||||
}
|
||||
+86
-100
@@ -1,8 +1,8 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.DB
|
||||
{
|
||||
@@ -15,41 +15,21 @@ namespace KKdMainLib.DB
|
||||
|
||||
public void BINReader(string file)
|
||||
{
|
||||
/*Stream IO0 = File.OpenReader(file + "0.bin");
|
||||
Stream IO1 = File.OpenReader(file + "1.bin");
|
||||
|
||||
List<int> _0 = new List<int>();
|
||||
List<int> _1 = new List<int>();
|
||||
IO0.Position = 0x20;
|
||||
for (i = 0; i < 124; i++)
|
||||
{ _0.Add(IO0.ReadInt32()); IO0.LongPosition += 8; }
|
||||
IO1.Position = 0x20;
|
||||
for (i = 0; i < 124; i++)
|
||||
{ _1.Add(IO1.ReadInt32()); IO1.LongPosition += 8; }
|
||||
IO0.Close();
|
||||
IO1.Close();
|
||||
|
||||
IO = File.OpenWriter(@"F:\Source\MikuMikuModel\DatabaseConverter\msgpack-json-tools\aet_gam_pv643.bin");
|
||||
IO.Position = 0x10;
|
||||
for (i = 0; i < 108; i++)
|
||||
{ IO.ReadInt32(); i1 = _1[_0.IndexOf(IO.ReadInt32())]; IO.Position -= 4; IO.Write(i1); }
|
||||
IO.Close();*/
|
||||
|
||||
IO = File.OpenReader(file + ".bin");
|
||||
|
||||
int spriteSetsLength = IO.ReadInt32();
|
||||
int spriteSetsOffset = IO.ReadInt32();
|
||||
int spritesLength = IO.ReadInt32();
|
||||
int spritesOffset = IO.ReadInt32();
|
||||
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;
|
||||
@@ -58,11 +38,11 @@ namespace KKdMainLib.DB
|
||||
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();
|
||||
IO.I64P += 10;
|
||||
setIndex = IO.RI16();
|
||||
IsTexture = (setIndex & 0x1000) == 0x1000;
|
||||
setIndex &= 0xFFF;
|
||||
|
||||
@@ -79,13 +59,13 @@ namespace KKdMainLib.DB
|
||||
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();
|
||||
st.Id = IO.RI32();
|
||||
st.Name = IO.RSaO();
|
||||
IO.RI16();
|
||||
setIndex = IO.RI16();
|
||||
IsTexture = (setIndex & 0x1000) == 0x1000;
|
||||
setIndex &= 0xFFF;
|
||||
|
||||
@@ -93,7 +73,7 @@ namespace KKdMainLib.DB
|
||||
else { SpriteSets[setIndex]. Sprites[SprCount[setIndex]] = st; SprCount[setIndex]++; }
|
||||
}
|
||||
|
||||
IO.Close();
|
||||
IO.C();
|
||||
}
|
||||
|
||||
public void BINWriter(string file)
|
||||
@@ -104,8 +84,8 @@ namespace KKdMainLib.DB
|
||||
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>();
|
||||
SpriteTexture temp;
|
||||
@@ -140,7 +120,7 @@ namespace KKdMainLib.DB
|
||||
if ( Ids.Contains((int)temp.Id)) { NotAdd.Add(i); break; }
|
||||
else Ids.Add ((int)temp.Id);
|
||||
}
|
||||
if (i0 + 1 != set.Sprites.Length) continue;
|
||||
if (i0 < set.Sprites.Length) continue;
|
||||
|
||||
for (i0 = 0; i0 < set.Textures.Length; i0++)
|
||||
{
|
||||
@@ -163,13 +143,13 @@ namespace KKdMainLib.DB
|
||||
if (set.Id == null) while (true)
|
||||
{ if (!SetIds.Contains(i1)) { SpriteSets[i].Id = i1; SetIds.Add(i1); break; } i1++; }
|
||||
|
||||
for (i0 = 0, i1 = 0; i0 < set. Sprites.Length; i0++)
|
||||
if (set. Sprites[i0].Id == null) while (true) { if (!Ids.Contains(i1))
|
||||
{ SpriteSets[i]. Sprites[i0].Id = i1; Ids.Add(i1); break; } i1++; }
|
||||
|
||||
for (i0 = 0, i1 = 0; i0 < set.Textures.Length; i0++)
|
||||
if (set.Textures[i0].Id == null) while (true) { if (!Ids.Contains(i1))
|
||||
{ SpriteSets[i].Textures[i0].Id = i1; Ids.Add(i1); break; } i1++; }
|
||||
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;
|
||||
@@ -184,78 +164,82 @@ namespace KKdMainLib.DB
|
||||
i1 = i1.Align(0x20) + 0x20;
|
||||
|
||||
IO = File.OpenWriter(file + ".bin", true);
|
||||
IO.Write(i2);
|
||||
IO.Write(i1);
|
||||
IO.Write(i0);
|
||||
IO.Write(0x20);
|
||||
IO.Write(0x9066906690669066);
|
||||
IO.Write(0x9066906690669066);
|
||||
IO.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).Align(0x20);
|
||||
for (i = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) continue;
|
||||
SpriteSets[i]. NameOffset = IO.Position; IO.Write(SpriteSets[i]. Name + "\0");
|
||||
SpriteSets[i].FileNameOffset = IO.Position; IO.Write(SpriteSets[i].FileName + "\0");
|
||||
for (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"); }
|
||||
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; }
|
||||
|
||||
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; }
|
||||
|
||||
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)
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
|
||||
if (MsgPack.Element<MsgPack>("SprDB", out MsgPack SprDB))
|
||||
MsgPack SprDB;
|
||||
if ((SprDB = MsgPack["SprDB", true]).NotNull)
|
||||
{
|
||||
SpriteSets = new SpriteSet[SprDB.Array.Length];
|
||||
for (int i = 0; i < SpriteSets.Length; i++)
|
||||
SpriteSets[i].ReadMsgPack(SprDB[i] as MsgPack);
|
||||
SpriteSets[i].ReadMsgPack(SprDB[i]);
|
||||
}
|
||||
MsgPack = null;
|
||||
SprDB.Dispose();
|
||||
MsgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
@@ -263,7 +247,7 @@ namespace KKdMainLib.DB
|
||||
if (SpriteSets == null) return;
|
||||
if (SpriteSets.Length == 0) return;
|
||||
|
||||
MsgPack SprDB = new MsgPack("SprDB", SpriteSets.Length);
|
||||
MsgPack SprDB = new MsgPack(SpriteSets.Length, "SprDB");
|
||||
for (i = 0; i < SpriteSets.Length; i++) SprDB[i] = SpriteSets[i].WriteMsgPack();
|
||||
|
||||
SprDB.Write(true, file, JSON);
|
||||
@@ -276,10 +260,10 @@ 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() =>
|
||||
new MsgPack().Add("Id", Id).Add("Name", Name);
|
||||
MsgPack.New.Add("Id", Id).Add("Name", Name);
|
||||
}
|
||||
|
||||
public struct SpriteSet
|
||||
@@ -295,37 +279,39 @@ namespace KKdMainLib.DB
|
||||
|
||||
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.Element<MsgPack>( "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] as MsgPack);
|
||||
Sprites = new SpriteTexture[Temp.Array.Length];
|
||||
for (int i0 = 0; i0 < Sprites.Length; i0++)
|
||||
Sprites[i0].ReadMsgPack(Temp[i0]);
|
||||
}
|
||||
|
||||
if (msg.Element<MsgPack>("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] as MsgPack);
|
||||
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( "Sprites", this.Sprites.Length);
|
||||
MsgPack Sprites = new MsgPack(this. Sprites.Length, "Sprites");
|
||||
for (int i0 = 0; i0 < this.Sprites.Length; i0++)
|
||||
Sprites[i0] = this.Sprites[i0].WriteMsgPack();
|
||||
|
||||
MsgPack Textures = new MsgPack("Textures", this.Textures.Length);
|
||||
MsgPack Textures = new MsgPack(this.Textures.Length, "Textures");
|
||||
for (int i0 = 0; i0 < this.Textures.Length; i0++)
|
||||
Textures[i0] = this.Textures[i0].WriteMsgPack();
|
||||
|
||||
return new MsgPack().Add("FileName", FileName).Add("Id", Id).Add("Name", Name).Add(Sprites).Add(Textures);
|
||||
return MsgPack.New.Add("FileName", FileName).Add("Id", Id).Add("Name", Name).Add(Sprites).Add(Textures);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+131
-146
@@ -1,249 +1,226 @@
|
||||
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 DEX()
|
||||
{ Dex = null; Header = new PDHead(); }
|
||||
{ Dex = null; Header = new Header(); }
|
||||
|
||||
private int Offset = 0;
|
||||
private PDHead Header;
|
||||
|
||||
public Stream IO;
|
||||
private Header Header;
|
||||
private Stream IO;
|
||||
|
||||
public EXP[] Dex;
|
||||
|
||||
public int DEXReader(string filepath, string ext)
|
||||
{
|
||||
Header = new PDHead();
|
||||
Header = new Header();
|
||||
IO = File.OpenReader(filepath + ext);
|
||||
|
||||
Header.Format = Main.Format.F;
|
||||
Header.Signature = IO.ReadInt32();
|
||||
if (Header.Signature == 0x43505845)
|
||||
Header = IO.ReadHeader(true);
|
||||
if (Header.Signature != 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 0;
|
||||
|
||||
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) { Header.Format = Format.X; DEXNameOffset = (int)IO.RI64(); }
|
||||
|
||||
IO.Seek(DEXOffset + Offset, 0);
|
||||
IO.S(DEXOffset, 0);
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
Dex[i0] = new EXP { Main = new List<EXPElement>(), Eyes = new List<EXPElement>() };
|
||||
Dex[i0] = new EXP { Main = KKdList<EXPElement>.New, Eyes = KKdList<EXPElement>.New };
|
||||
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
Dex[i0].MainOffset = IO.ReadInt32();
|
||||
if (Header.IsX) IO.ReadInt32();
|
||||
Dex[i0].EyesOffset = IO.ReadInt32();
|
||||
if (Header.IsX) IO.ReadInt32();
|
||||
Dex[i0].MainOffset = IO.RI32();
|
||||
if (Header.IsX) IO.RI32();
|
||||
Dex[i0].EyesOffset = IO.RI32();
|
||||
if (Header.IsX) IO.RI32();
|
||||
}
|
||||
IO.Seek(DEXNameOffset + Offset, 0);
|
||||
IO.S(DEXNameOffset, 0);
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
Dex[i0].NameOffset = IO.ReadInt32();
|
||||
if (Header.IsX) IO.ReadInt32();
|
||||
Dex[i0].NameOffset = IO.RI32();
|
||||
if (Header.IsX) IO.RI32();
|
||||
}
|
||||
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
EXPElement element = new EXPElement();
|
||||
IO.Seek(Dex[i0].MainOffset + Offset, 0);
|
||||
IO.S(Dex[i0].MainOffset + Offset, 0);
|
||||
while (true)
|
||||
{
|
||||
element.Frame = IO.ReadSingle();
|
||||
element.Both = IO.ReadUInt16();
|
||||
element.ID = IO.ReadUInt16();
|
||||
element.Value = IO.ReadSingle();
|
||||
element.Trans = IO.ReadSingle();
|
||||
element.Frame = IO.RF32();
|
||||
element.Both = IO.RU16();
|
||||
element.ID = IO.RU16();
|
||||
element.Value = IO.RF32();
|
||||
element.Trans = IO.RF32();
|
||||
Dex[i0].Main.Add(element);
|
||||
|
||||
if (element.Frame == 999999 || element.Both == 0xFFFF)
|
||||
break;
|
||||
}
|
||||
|
||||
IO.Seek(Dex[i0].EyesOffset + Offset, 0);
|
||||
IO.S(Dex[i0].EyesOffset, 0);
|
||||
while(true)
|
||||
{
|
||||
element.Frame = IO.ReadSingle();
|
||||
element.Both = IO.ReadUInt16();
|
||||
element.ID = IO.ReadUInt16();
|
||||
element.Value = IO.ReadSingle();
|
||||
element.Trans = IO.ReadSingle();
|
||||
element.Frame = IO.RF32();
|
||||
element.Both = IO.RU16();
|
||||
element.ID = IO.RU16();
|
||||
element.Value = IO.RF32();
|
||||
element.Trans = IO.RF32();
|
||||
Dex[i0].Eyes.Add(element);
|
||||
|
||||
if (element.Frame == 999999 || element.Both == 0xFFFF)
|
||||
break;
|
||||
if (element.Frame == 999999 || element.Both == 0xFFFF) break;
|
||||
}
|
||||
|
||||
IO.Seek(Dex[i0].NameOffset + Offset, 0);
|
||||
Dex[i0].Name = IO.NullTerminatedUTF8();
|
||||
Dex[i0].Name = IO.RSaO(Dex[i0].NameOffset);
|
||||
}
|
||||
|
||||
IO.Close();
|
||||
IO.C();
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void DEXWriter(string filepath, Main.Format Format)
|
||||
public void DEXWriter(string filepath, Format Format)
|
||||
{
|
||||
Header = new PDHead() { Format = Format };
|
||||
IO = File.OpenWriter(filepath + (Header.Format > Main.Format.F ? ".Dex" : ".bin"), true);
|
||||
IO.Format = Header.Format;
|
||||
Header = new Header();
|
||||
IO = File.OpenWriter(filepath + (Format > Format.F ? ".dex" : ".bin"), true);
|
||||
Header.Format = IO.Format = Format;
|
||||
|
||||
if (IO.Format > Main.Format.F)
|
||||
{
|
||||
Header.Lenght = 0x20;
|
||||
Header.DataSize = 0x00;
|
||||
Header.Signature = 0x43505845;
|
||||
Header.SectionSize = 0x00;
|
||||
IO.Write(Header);
|
||||
}
|
||||
IO.O = Format > Format.F ? 0x20 : 0;
|
||||
IO.W(0x64);
|
||||
IO.W(Dex.Length);
|
||||
|
||||
IO.Write(0x64);
|
||||
IO.Write(Dex.Length);
|
||||
|
||||
if (Header.IsX) IO.Write((long)0x28);
|
||||
else IO.Write( 0x20);
|
||||
if (Header.IsX) IO.Write((long)0x00);
|
||||
else IO.Write( 0x00);
|
||||
IO.WX(Header.IsX ? 0x28 : 0x20);
|
||||
IO.WX(0x00);
|
||||
|
||||
int Position0 = IO.Position;
|
||||
IO.Write((long)0x00);
|
||||
IO.Write((long)0x00);
|
||||
int Position0 = IO.P;
|
||||
IO.W(0x00L);
|
||||
IO.W(0x00L);
|
||||
|
||||
for (int i = 0; i < Dex.Length * 3; i++)
|
||||
if (Header.IsX) IO.Write((long)0x00);
|
||||
else IO.Write( 0x00);
|
||||
for (int i = 0; i < Dex.Length * 3; i++) IO.WX(0x00);
|
||||
|
||||
IO.Align(0x20, true);
|
||||
IO.A(0x20, true);
|
||||
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
Dex[i0].MainOffset = IO.Position - Header.Lenght;
|
||||
Dex[i0].MainOffset = IO.P;
|
||||
for (int 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.A(0x20, true);
|
||||
|
||||
Dex[i0].EyesOffset = IO.Position - Header.Lenght;
|
||||
Dex[i0].EyesOffset = IO.P;
|
||||
for (int 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.A(0x20, true);
|
||||
}
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
Dex[i0].NameOffset = IO.Position - Header.Lenght;
|
||||
IO.Write(Dex[i0].Name + "\0");
|
||||
Dex[i0].NameOffset = IO.P;
|
||||
IO.W(Dex[i0].Name + "\0");
|
||||
}
|
||||
IO.Align(0x10, true);
|
||||
IO.A(0x10, true);
|
||||
|
||||
if (Header.IsX) IO.Seek(Header.Lenght + 0x28, 0);
|
||||
else IO.Seek(Header.Lenght + 0x20, 0);
|
||||
IO.P = Header.IsX ? 0x28 : 0x20;
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
IO.Write(Dex[i0].MainOffset);
|
||||
if (Header.IsX) IO.Write(0x00);
|
||||
IO.Write(Dex[i0].EyesOffset);
|
||||
if (Header.IsX) IO.Write(0x00);
|
||||
IO.WX(Dex[i0].MainOffset);
|
||||
IO.WX(Dex[i0].EyesOffset);
|
||||
}
|
||||
int Position1 = IO.Position - Header.Lenght;
|
||||
int Position1 = IO.P;
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
IO.Write(Dex[i0].NameOffset);
|
||||
if (Header.IsX) IO.Write(0x00);
|
||||
}
|
||||
IO.WX(Dex[i0].NameOffset);
|
||||
|
||||
if (Header.IsX) IO.Seek(Position0 - 8, 0);
|
||||
else IO.Seek(Position0 - 4, 0);
|
||||
IO.Write(Position1);
|
||||
IO.P = Position0 - (Header.IsX ? 8 : 4);
|
||||
IO.W(Position1);
|
||||
|
||||
if (IO.Format > Main.Format.F)
|
||||
if (Format > Format.F)
|
||||
{
|
||||
Offset = IO.Length - Header.Lenght;
|
||||
IO.Seek(IO.Length, 0);
|
||||
IO.WriteEOFC(0);
|
||||
IO.Seek(0, 0);
|
||||
Offset = IO.L;
|
||||
IO.O = 0;
|
||||
IO.P = IO.L;
|
||||
IO.WEOFC(0);
|
||||
IO.P = 0;
|
||||
Header.DataSize = Offset;
|
||||
Header.SectionSize = Offset;
|
||||
IO.Write(Header);
|
||||
Header.Signature = 0x43505845;
|
||||
IO.W(Header, true);
|
||||
}
|
||||
IO.Close();
|
||||
IO.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
public int MsgPackReader(string file, bool JSON)
|
||||
{
|
||||
int i0 = 0;
|
||||
int i1 = 0;
|
||||
this.Dex = new EXP[0];
|
||||
Header = new PDHead();
|
||||
Header = new Header();
|
||||
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
if (!MsgPack.Element<MsgPack>("Dex", out MsgPack Dex)) return;
|
||||
|
||||
this.Dex = new EXP[Dex.Array.Length];
|
||||
for (i0 = 0; i0 < this.Dex.Length; i0++)
|
||||
if (Dex[i0] is MsgPack EXP)
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
MsgPack Dex;
|
||||
if ((Dex = MsgPack["Dex", true]).NotNull)
|
||||
{
|
||||
this.Dex = new EXP[Dex.Array.Length];
|
||||
for (i0 = 0; i0 < this.Dex.Length; i0++)
|
||||
{
|
||||
this.Dex[i0] = new EXP { Name = EXP.ReadString("Name") };
|
||||
this.Dex[i0] = new EXP { Name = Dex[i0].RS("Name") };
|
||||
|
||||
if (EXP.Element<MsgPack>("Main", out MsgPack Main))
|
||||
MsgPack Temp;
|
||||
if ((Temp = MsgPack["Main", true]).NotNull)
|
||||
{
|
||||
this.Dex[i0].Main = new List<EXPElement>();
|
||||
for (i1 = 0; i1 < Main.Array.Length; i1++)
|
||||
if (Main[i1] is MsgPack Exp)
|
||||
this.Dex[i0].Main.Add(ReadEXP(Exp));
|
||||
this.Dex[i0].Main = KKdList<EXPElement>.New;
|
||||
for (i1 = 0; i1 < this.Dex[i0].Main.Count; i1++)
|
||||
this.Dex[i0].Main.Add(EXPElement.Read(Temp[i1]));
|
||||
}
|
||||
if (EXP.Element<MsgPack>("Eyes", out MsgPack Eyes))
|
||||
if ((Temp = MsgPack["Eyes", true]).NotNull)
|
||||
{
|
||||
this.Dex[i0].Eyes = new List<EXPElement>();
|
||||
for (i1 = 0; i1 < Eyes.Array.Length; i1++)
|
||||
if (Eyes[i1] is MsgPack Exp)
|
||||
this.Dex[i0].Eyes.Add(ReadEXP(Exp));
|
||||
this.Dex[i0].Eyes = KKdList<EXPElement>.New;
|
||||
for (i1 = 0; i1 < this.Dex[i0].Main.Count; i1++)
|
||||
this.Dex[i0].Eyes.Add(EXPElement.Read(Temp[i1]));
|
||||
}
|
||||
Temp.Dispose();
|
||||
}
|
||||
MsgPack = null;
|
||||
}
|
||||
Dex.Dispose();
|
||||
MsgPack.Dispose();
|
||||
return 1;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
int i0 = 0;
|
||||
int i1 = 0;
|
||||
MsgPack Dex = new MsgPack("Dex", this.Dex.Length);
|
||||
MsgPack Dex = new MsgPack(this.Dex.Length, "Dex");
|
||||
for (i0 = 0; i0 < this.Dex.Length; i0++)
|
||||
{
|
||||
MsgPack EXP = new MsgPack().Add("Name", this.Dex[i0].Name);
|
||||
MsgPack Main = new MsgPack("Main", this.Dex[i0].Main.Count);
|
||||
MsgPack EXP = MsgPack.New.Add("Name", this.Dex[i0].Name);
|
||||
MsgPack Main = new MsgPack(this.Dex[i0].Main.Count, "Main");
|
||||
for (i1 = 0; i1 < this.Dex[i0].Main.Count; i1++)
|
||||
Main[i1] = WriteEXP(this.Dex[i0].Main[i1]);
|
||||
Main[i1] = this.Dex[i0].Main[i1].Write();
|
||||
EXP.Add(Main);
|
||||
|
||||
MsgPack Eyes = new MsgPack("Eyes", this.Dex[i0].Eyes.Count);
|
||||
MsgPack Eyes = new MsgPack(this.Dex[i0].Eyes.Count, "Eyes");
|
||||
for (i1 = 0; i1 < this.Dex[i0].Eyes.Count; i1++)
|
||||
Eyes[i1] = WriteEXP(this.Dex[i0].Eyes[i1]);
|
||||
Eyes[i1] = this.Dex[i0].Eyes[i1].Write();
|
||||
EXP.Add(Eyes);
|
||||
Dex[i0] = EXP;
|
||||
}
|
||||
@@ -251,18 +228,16 @@ namespace KKdMainLib
|
||||
Dex.Write(true, file, JSON);
|
||||
}
|
||||
|
||||
private MsgPack WriteEXP(EXPElement element) =>
|
||||
new MsgPack().Add("F", element.Frame).Add("B", element.Both ).Add("I", element.ID )
|
||||
.Add("V", element.Value).Add("T", element.Trans);
|
||||
|
||||
public struct EXP
|
||||
{
|
||||
public int MainOffset;
|
||||
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
|
||||
@@ -272,6 +247,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+41
-33
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using MSIO = System.IO;
|
||||
|
||||
@@ -7,58 +8,65 @@ namespace KKdMainLib
|
||||
{
|
||||
public static class DIVAFILE
|
||||
{
|
||||
private static readonly byte[] Key = "file access deny".ToASCII();
|
||||
private static readonly byte[] Key = new byte[]
|
||||
{ 0x66, 0x69, 0x6C, 0x65, 0x20, 0x61, 0x63, 0x63,
|
||||
0x65, 0x73, 0x73, 0x20, 0x64, 0x65, 0x6E, 0x79 };
|
||||
|
||||
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];
|
||||
byte[] In;
|
||||
using (Stream IO = File.OpenReader(file))
|
||||
In = IO.ToArray();
|
||||
|
||||
int FileLengthOrigin = In.Length;
|
||||
int FileLength = FileLengthOrigin.Align(16);
|
||||
byte[] Inalign = new byte[FileLength];
|
||||
for (int i = 0; i < In.Length; i++) Inalign[i] = In[i];
|
||||
In = null;
|
||||
byte[] encrypted = new byte[FileLenght];
|
||||
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(Inalign),
|
||||
crypto.CreateEncryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read);
|
||||
cryptoData.Read(encrypted, 0, FileLength);
|
||||
}
|
||||
|
||||
using (Stream IO = File.OpenWriter(file, Inalign.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+218
-65
@@ -1,18 +1,19 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public class DataBank
|
||||
{
|
||||
public DataBank() { Success = false; IO = null; pvList = null; }
|
||||
public DataBank() { Success = false; IO = null; pvList = null; psrDat = null; }
|
||||
|
||||
private Stream IO;
|
||||
private int i;
|
||||
|
||||
private PvList[] pvList;
|
||||
private PvList[] pvList;
|
||||
private psrData[] psrDat;
|
||||
|
||||
private const string d = ".";
|
||||
private const string c = ",";
|
||||
@@ -27,72 +28,213 @@ namespace KKdMainLib
|
||||
while (text.Contains("%")) text = WebUtility.UrlDecode(text);
|
||||
string[] array = text.Split(',');
|
||||
|
||||
if (file.Contains("PvList") && array.Length % 7 < 2)
|
||||
if (file.Contains("psrData") && array.Length % 13 < 2)
|
||||
{
|
||||
psrDat = new psrData[array.Length / 13];
|
||||
for (i = 0; i < psrDat.Length; i++) psrDat[i].SetValue(array, i);
|
||||
Success = true;
|
||||
}
|
||||
else if (file.Contains("psrData")) { psrDat = null; Success = true; }
|
||||
else if (file.Contains("PvList") && array.Length % 7 < 2)
|
||||
{
|
||||
pvList = new PvList[array.Length / 7];
|
||||
for (i = 0; i < pvList.Length; i++) pvList[i].SetValue(array, i);
|
||||
Success = true;
|
||||
}
|
||||
else if (file.Contains("PvList")) { pvList = null; Success = true; }
|
||||
}
|
||||
|
||||
public void DBWriter(string file)
|
||||
public void DBWriter(string file, uint num2)
|
||||
{
|
||||
if (!Success) return;
|
||||
|
||||
IO = File.OpenWriter();
|
||||
if (file.Contains("PvList"))
|
||||
if (file.Contains("psrData"))
|
||||
{
|
||||
if (pvList.Length != 0)
|
||||
for (i = 0; i < pvList.Length; i++)
|
||||
IO.Write(UrlEncode(pvList[i].ToString() +
|
||||
((i + 1 != pvList.Length) ? "," : "")));
|
||||
else IO.Write("%2A%2A%2A");
|
||||
if (psrDat != null && psrDat.Length > 0)
|
||||
for (i = 0; i < psrDat.Length; i++)
|
||||
IO.W(psrDat[i].ToString() + c);
|
||||
}
|
||||
|
||||
byte[] data = IO.ToArray(Close: true);
|
||||
else if (file.Contains("PvList"))
|
||||
{
|
||||
if (pvList != null && pvList.Length > 0)
|
||||
for (i = 0; i < pvList.Length; i++)
|
||||
IO.W(UrlEncode(pvList[i].ToString() +
|
||||
(i < pvList.Length ? c : "")));
|
||||
else IO.W("%2A%2A%2A");
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Success = false;
|
||||
MsgPack msgPack = file.ReadMP(JSON);
|
||||
bool compact = msgPack.ReadBoolean("Compact");
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
|
||||
bool compact = MsgPack.RB("Compact");
|
||||
|
||||
if (file.Contains("PvList") && msgPack.Element<MsgPack>("PvList", out MsgPack PvList))
|
||||
if (file.Contains("psrData"))
|
||||
{
|
||||
pvList = new PvList[PvList.Array.Length];
|
||||
for (i = 0; i < pvList.Length; i++)
|
||||
pvList[i].SetValue((MsgPack)PvList[i], compact);
|
||||
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]);
|
||||
}
|
||||
else if (MsgPack["psrData"].NotNull) psrDat = null;
|
||||
Success = true;
|
||||
psrData.Dispose();
|
||||
}
|
||||
msgPack = null;
|
||||
else if (file.Contains("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);
|
||||
}
|
||||
else if (MsgPack["PvList"].NotNull) pvList = null;
|
||||
Success = true;
|
||||
PvList.Dispose();
|
||||
}
|
||||
|
||||
MsgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON, bool Compact = true)
|
||||
{
|
||||
if (!Success) return;
|
||||
MsgPack msgPack = new MsgPack();
|
||||
MsgPack MsgPack = MsgPack.New;
|
||||
|
||||
if (file.Contains("PvList"))
|
||||
if (file.Contains("psrData"))
|
||||
{
|
||||
if (Compact) msgPack.Add("Compact", Compact);
|
||||
|
||||
MsgPack PvList = new MsgPack("PvList", pvList.Length);
|
||||
for (i = 0; i < pvList.Length; i++) PvList[i] = pvList[i].WriteMP(Compact);
|
||||
msgPack.Add(PvList);
|
||||
if (psrDat != null)
|
||||
{
|
||||
MsgPack psrData = new MsgPack(psrDat.Length, "psrData");
|
||||
for (i = 0; i < psrDat.Length; i++) psrData[i] = psrDat[i].WriteMP();
|
||||
MsgPack.Add(psrData);
|
||||
}
|
||||
else MsgPack.Add(new MsgPack("psrData", null));
|
||||
}
|
||||
msgPack.Write(file, JSON).Dispose();
|
||||
else if (file.Contains("PvList"))
|
||||
{
|
||||
if (pvList != null)
|
||||
{
|
||||
if (Compact) MsgPack.Add("Compact", Compact);
|
||||
|
||||
MsgPack PvList = new MsgPack(pvList.Length, "PvList");
|
||||
for (i = 0; i < pvList.Length; i++) PvList[i] = pvList[i].WriteMP(Compact);
|
||||
MsgPack.Add(PvList);
|
||||
}
|
||||
else MsgPack.Add(new MsgPack("PvList", null));
|
||||
}
|
||||
MsgPack.Write(file, JSON).Dispose();
|
||||
}
|
||||
|
||||
public static string UrlEncode(string value) =>
|
||||
WebUtility.UrlEncode(value).Replace("+", "%20");
|
||||
|
||||
public struct psrData
|
||||
{
|
||||
public Player p1;
|
||||
public Player p2;
|
||||
public Player p3;
|
||||
public int PV_ID;
|
||||
|
||||
public void SetValue(string[] data, int i = 0)
|
||||
{
|
||||
p1.SetValue(data, i, 0);
|
||||
p2.SetValue(data, i, 1);
|
||||
p3.SetValue(data, i, 2);
|
||||
PV_ID = int.Parse(data[i * 13 + 12]);
|
||||
}
|
||||
|
||||
public void SetValue(MsgPack msg)
|
||||
{
|
||||
int? ID = msg.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() =>
|
||||
MsgPack.New.Add("PV_ID", PV_ID).Add(p1.WriteMP("P1"))
|
||||
.Add(p2.WriteMP("P2")).Add(p3.WriteMP("P3"));
|
||||
|
||||
public override string ToString() =>
|
||||
UrlEncode(p1.ToString() + c + p2.ToString() + c + p3.ToString() + c + PV_ID);
|
||||
}
|
||||
|
||||
public struct Player
|
||||
{
|
||||
public int Score0;
|
||||
public int Score1;
|
||||
public string Name0;
|
||||
public string Name1;
|
||||
public Difficulty Diff;
|
||||
public bool Has2P => Name1 != null;
|
||||
|
||||
public void SetValue(string[] data, int i = 0, int offset = 0)
|
||||
{
|
||||
string[] array = data[i * 13 + offset * 4].Split('.');
|
||||
Score0 = int.Parse(array[0]);
|
||||
if (array.Length > 1) Score1 = int.Parse(array[1]);
|
||||
string text = "";
|
||||
for (int j = 0; j < data[i * 13 + 1 + offset * 4].Length; j++)
|
||||
{
|
||||
text += data[i * 13 + 1 + offset * 4][j].ToString();
|
||||
if (text.EndsWith("xxx"))
|
||||
{
|
||||
Name0 = text.Remove(text.Length - 3);
|
||||
text = "";
|
||||
}
|
||||
}
|
||||
if (array.Length == 1) Name0 = text;
|
||||
else Name1 = text;
|
||||
if (int.TryParse(data[i * 13 + 2 + offset * 4], out int Diff))
|
||||
this.Diff = (Difficulty)Diff;
|
||||
else
|
||||
Enum.TryParse(data[i * 13 + 2 + offset * 4], out this.Diff);
|
||||
}
|
||||
|
||||
public void SetValue(MsgPack msg)
|
||||
{
|
||||
Diff = (Difficulty)msg.RI32("Diff");
|
||||
Score0 = msg.RI32 ("Score");
|
||||
Name0 = msg.RS( "Name");
|
||||
if (Name0 == null)
|
||||
{
|
||||
Score0 = msg.RI32("Score0");
|
||||
Score1 = msg.RI32("Score1");
|
||||
Name0 = msg.RS ( "Name0");
|
||||
Name1 = msg.RS ( "Name1");
|
||||
}
|
||||
else Name1 = null;
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(string name) =>
|
||||
Has2P ? new MsgPack(name).Add("Diff", (int)Diff).Add("Score0", Score0)
|
||||
.Add("Score1", Score1).Add("Name0", Name0).Add("Name1", Name1) :
|
||||
new MsgPack(name).Add("Diff", (int)Diff)
|
||||
.Add("Score" , Score0).Add("Name" , Name0);
|
||||
|
||||
public override string ToString() =>
|
||||
(Score0 + (Has2P ? (d + Score1) : "") + c + UrlEncode(Name0) +
|
||||
(Has2P ? ("xxx" + UrlEncode(Name1)) : "") + c +
|
||||
Diff + c + (Has2P ? "0.1" : "0")).Replace("*", "%2A");
|
||||
}
|
||||
|
||||
public struct PvList
|
||||
{
|
||||
public int ID;
|
||||
public int PV_ID;
|
||||
public bool Enable;
|
||||
public bool Extra;
|
||||
public Date AdvDemoStart;
|
||||
@@ -102,9 +244,9 @@ namespace KKdMainLib
|
||||
|
||||
public void SetValue(string[] data, int i = 0)
|
||||
{
|
||||
ID = int.Parse(data[i * 7]);
|
||||
PV_ID = int.Parse(data[i * 7]);
|
||||
Enable = int.Parse(data[i * 7 + 1]) == 1;
|
||||
Extra = int.Parse(data[i * 7 + 2]) == 1;
|
||||
Extra = int.Parse(data[i * 7 + 2]) == 1;
|
||||
AdvDemoStart.SetValue(data[i * 7 + 3]);
|
||||
AdvDemoEnd .SetValue(data[i * 7 + 4]);
|
||||
StartShow .SetValue(data[i * 7 + 5]);
|
||||
@@ -113,56 +255,59 @@ namespace KKdMainLib
|
||||
|
||||
public void SetValue(MsgPack msg, bool Compact)
|
||||
{
|
||||
MsgPack Temp = new MsgPack();
|
||||
this.Enable = true;
|
||||
this.Extra = false;
|
||||
|
||||
ID = msg.ReadInt32("ID");
|
||||
bool? Enable = msg.ReadNBoolean("Enable");
|
||||
bool? Extra = msg.ReadNBoolean("Extra");
|
||||
if (Enable.HasValue) this.Enable = (bool)Enable;
|
||||
if (Extra .HasValue) this.Extra = (bool)Extra ;
|
||||
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; }
|
||||
bool? Enable = msg.RnB("Enable");
|
||||
bool? Extra = msg.RnB("Extra");
|
||||
if (Enable != null) this.Enable = (bool)Enable;
|
||||
if (Extra != null) this.Extra = (bool)Extra ;
|
||||
if (Compact)
|
||||
{
|
||||
AdvDemoStart.SetValue(msg.ReadNInt32("AdvDemoStart"), true);
|
||||
AdvDemoEnd .SetValue(msg.ReadNInt32("AdvDemoEnd" ), false);
|
||||
StartShow .SetValue(msg.ReadNInt32("StartShow" ), false);
|
||||
EndShow .SetValue(msg.ReadNInt32( "EndShow" ), true);
|
||||
AdvDemoStart.SetValue(msg.RnI32("AdvDemoStart"), true);
|
||||
AdvDemoEnd .SetValue(msg.RnI32("AdvDemoEnd" ), false);
|
||||
StartShow .SetValue(msg.RnI32("StartShow" ), false);
|
||||
EndShow .SetValue(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.SetValue(Temp, true);
|
||||
if ((Temp = msg["AdvDemoEnd" , true]).NotNull) AdvDemoEnd .SetValue(Temp, false);
|
||||
if ((Temp = msg["StartShow" , true]).NotNull) StartShow .SetValue(Temp, false);
|
||||
if ((Temp = msg[ "EndShow" , true]).NotNull) EndShow .SetValue(Temp, true);
|
||||
Temp.Dispose();
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(bool Compact)
|
||||
{
|
||||
MsgPack msgPack = new MsgPack();
|
||||
msgPack.Add("ID", ID);
|
||||
if (!Enable) msgPack.Add("Enable", Enable);
|
||||
if ( Extra ) msgPack.Add("Extra" , Extra );
|
||||
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());
|
||||
if (AdvDemoStart.WriteUpper) 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" ));
|
||||
if (AdvDemoStart.WriteUpper) MsgPack.Add(AdvDemoStart.WriteMP("AdvDemoStart"));
|
||||
if (AdvDemoEnd .WriteLower) MsgPack.Add(AdvDemoEnd .WriteMP("AdvDemoEnd" ));
|
||||
if (StartShow .WriteLower) MsgPack.Add(StartShow .WriteMP("StartShow" ));
|
||||
if ( EndShow .WriteUpper) MsgPack.Add( EndShow .WriteMP( "EndShow" ));
|
||||
}
|
||||
return msgPack;
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
public override string ToString() =>
|
||||
UrlEncode(ID + "," + (Enable ? 1 : 0) + "," + (Extra ? 1 : 0) + "," +
|
||||
AdvDemoStart.ToString() + "," + AdvDemoEnd.ToString() + "," +
|
||||
StartShow.ToString() + "," + EndShow.ToString());
|
||||
UrlEncode(PV_ID + c + (Enable ? 1 : 0) + c + (Extra ? 1 : 0) + c +
|
||||
AdvDemoStart.ToString() + c + AdvDemoEnd.ToString() + c +
|
||||
StartShow.ToString() + c + EndShow.ToString());
|
||||
}
|
||||
|
||||
public struct Date
|
||||
@@ -211,9 +356,9 @@ namespace KKdMainLib
|
||||
{
|
||||
if (!SetDefaultUpper) SetDefaultLower();
|
||||
else this.SetDefaultUpper();
|
||||
int? Year = msg.ReadNInt32( "Year");
|
||||
int? Month = msg.ReadNInt32("Month");
|
||||
int? Day = msg.ReadNInt32( "Day");
|
||||
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;
|
||||
@@ -244,5 +389,13 @@ namespace KKdMainLib
|
||||
public override string ToString() =>
|
||||
Year.ToString("d4") + "-" + Month.ToString("d2") + "-" + Day.ToString("d2");
|
||||
}
|
||||
|
||||
public enum Difficulty
|
||||
{
|
||||
Easy = 0,
|
||||
Normal = 1,
|
||||
Hard = 2,
|
||||
Extreme = 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,231 @@
|
||||
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.I64P > 4) stream.I64P -= 4;
|
||||
else stream.I64P = 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 ID = 0) =>
|
||||
stream.W(new Header { Depth = ID, Length = 0x20, Signature = 0x43464F45 });
|
||||
}
|
||||
|
||||
public static class POFExtensions
|
||||
{
|
||||
public static void W(this Stream stream, POF POF, bool ShiftX = false)
|
||||
{
|
||||
byte[] data = POF.Write(POF, ShiftX);
|
||||
Header Header = new Header { Depth = POF.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, ENRSList ENRS)
|
||||
{
|
||||
byte[] data = ENRSList.Write(ENRS);
|
||||
Header Header = new Header { Depth = ENRS.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 (Header.Depth == 0 && (Sig == 0x53524E45 ||
|
||||
(Sig & 0xF0FFFFFF) == 0x30464F50 || Sig == 0x43505854))
|
||||
{
|
||||
byte[] Data = stream.RBy(Header.SectionSize);
|
||||
if (Sig == 0x53524E45) Struct.ENRS = ENRSList.Read(Data, Header.Depth);
|
||||
else Struct.POF = POF .Read(Data, Sig == 0x31464F50, Header.Depth);
|
||||
}
|
||||
else if (Header.Depth <= Depth) { stream.I64P -= 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)
|
||||
{
|
||||
byte[] Data;
|
||||
using (Stream stream = File.OpenWriter()) { Struct.Update(ShiftX);
|
||||
stream.W(Struct, ShiftX); stream.WEOFC(); Data = stream.ToArray(); }
|
||||
return Data;
|
||||
}
|
||||
|
||||
public static void W(this Stream stream, Struct Struct, bool ShiftX = false)
|
||||
{
|
||||
stream.W(Struct.Header);
|
||||
stream.W(Struct.Data );
|
||||
if (Struct.HasPOF ) stream.W(Struct.POF , ShiftX);
|
||||
if (Struct.HasENRS) stream.W(Struct.ENRS);
|
||||
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 + ".json", true))) IO.Write(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.Write(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib.F2
|
||||
{
|
||||
public struct Bloom
|
||||
{
|
||||
public CountPointer<BLT> BLTs;
|
||||
private Stream IO;
|
||||
private Header Header;
|
||||
private int i;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
public struct BLT
|
||||
{
|
||||
public Vector3 Color;
|
||||
public Vector3 Brightpass;
|
||||
public float Range;
|
||||
|
||||
public override string ToString() => Color .ToString(6) + "," +
|
||||
Brightpass.ToString(6) + "," +
|
||||
Range .ToString(6);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib.F2
|
||||
{
|
||||
public struct ColorCorrection
|
||||
{
|
||||
public CountPointer<CCT> CCTs;
|
||||
private Stream IO;
|
||||
private Header Header;
|
||||
private int i;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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 .ToString(6) + "," +
|
||||
Saturation.ToString(6) + "," +
|
||||
Lightness .ToString(6) + "," +
|
||||
Exposure .ToString(6) + "," +
|
||||
Gamma .ToString(6) + "," +
|
||||
Contrast .ToString(6);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib.F2
|
||||
{
|
||||
public struct DOF
|
||||
{
|
||||
public CountPointer<DFT> DFTs;
|
||||
private Stream IO;
|
||||
private Header Header;
|
||||
private int i;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
public struct DFT
|
||||
{
|
||||
public float Focus;
|
||||
public float FocusRange;
|
||||
public float FuzzingRange;
|
||||
public float Ratio;
|
||||
public float Quality;
|
||||
|
||||
public override string ToString() => Focus .ToString(6) + "," +
|
||||
FocusRange.ToString(6) + "," +
|
||||
FuzzingRange.ToString(6) + "," +
|
||||
Ratio .ToString(6) + "," +
|
||||
Quality .ToString(6);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib.F2
|
||||
{
|
||||
public struct Light
|
||||
{
|
||||
public CountPointer<CountPointer<LIT>> LITs;
|
||||
private Stream IO;
|
||||
private Header Header;
|
||||
private int i, i0;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
+246
-259
@@ -1,355 +1,342 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using System;
|
||||
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() { Files = new FARCFile[0]; Signature = Farc.FArC; FT = false; }
|
||||
public FARC() => NewFARC();
|
||||
public FARC(string File, bool IsDirectory = false)
|
||||
{ if (IsDirectory) DirectoryPath = File; else FilePath = File; NewFARC(); }
|
||||
|
||||
public FARCFile[] Files = new FARCFile[0];
|
||||
private void NewFARC() { Files = null; Signature = Farc.FArC; CBC = FT = false; }
|
||||
|
||||
public FARCFile[] Files = null;
|
||||
public Type FARCType;
|
||||
public Farc Signature = Farc.FArC;
|
||||
public string FilePath, DirectoryPath;
|
||||
public bool HasFiles => Files == null ? false : Files.Length > 0;
|
||||
|
||||
private bool FT = false;
|
||||
private bool CBC, FT;
|
||||
|
||||
private readonly byte[] Key = Text.ToASCII("project_diva.bin");
|
||||
|
||||
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,
|
||||
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(string file, bool SaveToDisk = true)
|
||||
public bool HeaderReader()
|
||||
{
|
||||
Files = null;
|
||||
Signature = Farc.FArC;
|
||||
FT = false;
|
||||
Console.Title = "FARC Extractor - Archive: " + Path.GetFileName(file);
|
||||
if (!File.Exists(file))
|
||||
{
|
||||
Console.WriteLine("File {0} doesn't exist.", Path.GetFileName(file));
|
||||
Console.Clear();
|
||||
return;
|
||||
}
|
||||
NewFARC();
|
||||
if (!File.Exists(FilePath)) return false;
|
||||
|
||||
Stream reader = File.OpenReader(file);
|
||||
string directory = Path.GetFullPath(file).Replace(Path.GetExtension(file), "");
|
||||
Signature = (Farc)reader.ReadInt32Endian(true);
|
||||
Stream reader = File.OpenReader(FilePath);
|
||||
DirectoryPath = Path.GetFullPath(FilePath).Replace(Path.GetExtension(FilePath), "");
|
||||
Signature = (Farc)reader.RI32E(true);
|
||||
if (Signature != Farc.FArc && Signature != Farc.FArC && Signature != Farc.FARC)
|
||||
{
|
||||
Console.WriteLine("Unknown signature"); reader.Close();
|
||||
Console.Clear();
|
||||
return;
|
||||
}
|
||||
{ reader.Dispose(); return false; }
|
||||
|
||||
MSIO.Directory.CreateDirectory(directory);
|
||||
int HeaderLength = reader.ReadInt32Endian(true);
|
||||
if (Signature != Farc.FARC)
|
||||
int HeaderLength = reader.RI32E(true);
|
||||
if (Signature == Farc.FARC)
|
||||
{
|
||||
reader.ReadUInt32();
|
||||
HeaderReader(HeaderLength, ref Files, ref reader);
|
||||
reader.Close();
|
||||
FARCType = (Type)reader.RI32E(true);
|
||||
reader.RI32();
|
||||
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
int FARCMode = reader.RI32E(true);
|
||||
FT = FARCMode == 0x10;
|
||||
CBC = FARCMode != 0x10 && FARCMode != 0x40;
|
||||
|
||||
if (CBC && FARCType.HasFlag(Type.ECB))
|
||||
{
|
||||
if (Signature == Farc.FArC)
|
||||
using (MSIO.MemoryStream memorystream = new MSIO.MemoryStream(
|
||||
File.ReadAllBytes(file, Files[i].SizeComp, Files[i].Offset)))
|
||||
{
|
||||
GZipStream gZipStream = new GZipStream(memorystream, CompressionMode.Decompress);
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
}
|
||||
else
|
||||
Files[i].Data = File.ReadAllBytes(file, Files[i].SizeUnc, Files[i].Offset);
|
||||
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 };
|
||||
|
||||
if (SaveToDisk)
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(directory, Files[i].Name), Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
}
|
||||
using (AesManaged aes = GetAes(true, null))
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Header, 0x00, HeaderLength - 0x08);
|
||||
Header = SkipData(Header, 0x10);
|
||||
reader = File.OpenReader(Header);
|
||||
|
||||
FARCMode = reader.RI32E(true);
|
||||
FT = FARCMode == 0x10;
|
||||
}
|
||||
Console.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
int Mode = reader.ReadInt32Endian(true);
|
||||
reader.ReadUInt32();
|
||||
bool GZip = (Mode & 2) == 2;
|
||||
bool ECB = (Mode & 4) == 4;
|
||||
if (Signature == Farc.FARC)
|
||||
if (reader.RI32E(true) == 1)
|
||||
Files = new FARCFile[reader.RI32E(true)];
|
||||
reader.RI32();
|
||||
|
||||
int FARCType = reader.ReadInt32Endian(true);
|
||||
FT = FARCType == 0x10;
|
||||
bool CBC = !FT && FARCType != 0x40;
|
||||
if (ECB && CBC)
|
||||
if (Files == null)
|
||||
{
|
||||
byte[] Header = new byte[HeaderLength - 0x08];
|
||||
FT = true;
|
||||
reader.Close();
|
||||
MSIO.FileStream stream = new MSIO.FileStream(file, MSIO.FileMode.Open,
|
||||
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite);
|
||||
stream.Seek(0x10, 0);
|
||||
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Header, 0x00, HeaderLength - 0x08);
|
||||
Header = SkipData(Header, 0x10);
|
||||
Stream CBCreader = new Stream(new MSIO.MemoryStream(Header));
|
||||
CBCreader.BaseStream.Seek(0, 0);
|
||||
|
||||
FARCType = CBCreader.ReadInt32Endian(true);
|
||||
FT = FARCType == 0x10;
|
||||
if (CBCreader.ReadInt32Endian(true) == 1)
|
||||
Files = new FARCFile[CBCreader.ReadInt32Endian(true)];
|
||||
CBCreader.ReadUInt32();
|
||||
HeaderReader(HeaderLength, ref Files, ref CBCreader);
|
||||
CBCreader.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (reader.ReadInt32Endian(true) == 1)
|
||||
Files = new FARCFile[reader.ReadInt32Endian(true)];
|
||||
reader.ReadUInt32();
|
||||
HeaderReader(HeaderLength, ref Files, ref reader);
|
||||
reader.Close();
|
||||
int Count = 0;
|
||||
long Position = reader.I64P;
|
||||
while (reader.I64P < HeaderLength)
|
||||
{
|
||||
reader.NT();
|
||||
reader.RI32();
|
||||
if (Signature != Farc.FArc ) reader.RI32();
|
||||
reader.RI32();
|
||||
if (Signature == Farc.FARC && FT) reader.RI32();
|
||||
Count++;
|
||||
}
|
||||
reader.I64P = Position;
|
||||
Files = new FARCFile[Count];
|
||||
}
|
||||
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
int FileSize = ECB || Files[i].ECB ? Files[i].SizeComp.Align(0x10) : Files[i].SizeComp;
|
||||
MSIO.FileStream stream = new MSIO.FileStream(file, MSIO.FileMode.Open,
|
||||
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite);
|
||||
stream.Seek(Files[i].Offset, 0);
|
||||
Files[i].Data = new byte[FileSize];
|
||||
|
||||
bool Encrypted = false;
|
||||
if (ECB)
|
||||
{
|
||||
if ((FT && Files[i].ECB) || CBC)
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Files[i].Data, 0, FileSize);
|
||||
Files[i].Data = SkipData(Files[i].Data, 0x10);
|
||||
}
|
||||
else
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(false, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Files[i].Data, 0, FileSize);
|
||||
Encrypted = true;
|
||||
}
|
||||
|
||||
bool Compressed = false;
|
||||
bool LocalGZip = (FT && Files[i].GZip) || GZip && Files[i].SizeUnc != 0;
|
||||
if (LocalGZip)
|
||||
{
|
||||
GZipStream gZipStream;
|
||||
if (Encrypted)
|
||||
{
|
||||
gZipStream = new GZipStream(new MSIO.MemoryStream(
|
||||
Files[i].Data), CompressionMode.Decompress);
|
||||
stream.Close();
|
||||
}
|
||||
else gZipStream = new GZipStream(stream, CompressionMode.Decompress);
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
|
||||
Compressed = true;
|
||||
}
|
||||
|
||||
if (!Encrypted && !Compressed)
|
||||
{
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
stream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
if (SaveToDisk)
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(directory, Files[i].Name), Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
}
|
||||
|
||||
Files[i].Name = reader.NTUTF8();
|
||||
Files[i].Offset = reader.RI32E(true);
|
||||
if (Signature != Farc.FArc) Files[i].SizeComp = reader.RI32E(true);
|
||||
Files[i].SizeUnc = reader.RI32E(true);
|
||||
if (Signature == Farc.FARC && FT)
|
||||
Files[i].Type = (Type)reader.RI32E(true);
|
||||
}
|
||||
Console.Clear();
|
||||
|
||||
reader.Dispose();
|
||||
return true;
|
||||
}
|
||||
|
||||
byte[] SkipData(byte[] Data, int Skip)
|
||||
private void FileReader()
|
||||
{ for (int i = 0; i < Files.Length; i++) FileReader(i); }
|
||||
|
||||
public byte[] FileReader(int i)
|
||||
{
|
||||
if (!HasFiles) return null;
|
||||
if (i >= Files.Length) return null;
|
||||
if (Signature != Farc.FARC)
|
||||
{
|
||||
if (Signature == Farc.FArC)
|
||||
using (MSIO.MemoryStream memorystream = new MSIO.MemoryStream(
|
||||
File.ReadAllBytes(FilePath, Files[i].SizeComp, Files[i].Offset)))
|
||||
using (GZipStream gZipStream = new GZipStream(memorystream, CompressionMode.Decompress))
|
||||
{
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
}
|
||||
else Files[i].Data = File.ReadAllBytes(FilePath, Files[i].SizeUnc, Files[i].Offset);
|
||||
return Files[i].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))
|
||||
{
|
||||
if ((FT && Files[i].Type.HasFlag(Type.ECB)) || CBC)
|
||||
{
|
||||
using (AesManaged aes = GetAes(true, null))
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Files[i].Data, 0, FileSize);
|
||||
Files[i].Data = SkipData(Files[i].Data, 0x10);
|
||||
}
|
||||
else
|
||||
using (AesManaged aes = GetAes(false, null))
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Files[i].Data, 0, FileSize);
|
||||
Encrypted = true;
|
||||
}
|
||||
|
||||
bool Compressed = false;
|
||||
if (((FT && Files[i].Type.HasFlag(Type.GZip)) ||
|
||||
FARCType.HasFlag(Type.GZip)) && Files[i].SizeUnc > 0)
|
||||
{
|
||||
GZipStream gZipStream = new GZipStream(Encrypted ? new MSIO.MemoryStream(Files[i].Data) :
|
||||
(MSIO.Stream)stream, CompressionMode.Decompress);
|
||||
byte[] Temp = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Temp, 0, Files[i].SizeUnc);
|
||||
Files[i].Data = Temp;
|
||||
gZipStream.Dispose();
|
||||
Compressed = true;
|
||||
}
|
||||
|
||||
if (!Encrypted && !Compressed)
|
||||
{
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
stream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
}
|
||||
stream.Dispose();
|
||||
return Files[i].Data;
|
||||
}
|
||||
|
||||
private void SaveToDisk()
|
||||
{
|
||||
if (DirectoryPath == null || Files == null) return;
|
||||
if (DirectoryPath == "" || Files.Length < 1) return;
|
||||
MSIO.Directory.CreateDirectory(DirectoryPath);
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
if (Files[i].Data != null)
|
||||
File.WriteAllBytes(Path.Combine(DirectoryPath, Files[i].Name), Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] SkipData(byte[] Data, int Skip)
|
||||
{
|
||||
byte[] SkipData = new byte[Data.Length - Skip];
|
||||
for (int i = 0; i < Data.Length - Skip; i++) SkipData[i] = Data[i + Skip];
|
||||
return SkipData;
|
||||
}
|
||||
|
||||
void HeaderReader(int HeaderLenght, ref FARCFile[] Files, ref Stream reader)
|
||||
public void Pack(Farc Signature = Farc.FArC)
|
||||
{
|
||||
if (Files == null)
|
||||
{
|
||||
int Count = 0;
|
||||
long Position = reader.BaseStream.Position;
|
||||
while (reader.BaseStream.Position < HeaderLenght)
|
||||
{
|
||||
reader.NullTerminated();
|
||||
reader.ReadInt32();
|
||||
if (Signature != Farc.FArc ) reader.ReadInt32();
|
||||
reader.ReadInt32();
|
||||
if (Signature == Farc.FARC && FT) reader.ReadInt32();
|
||||
Count++;
|
||||
}
|
||||
reader.Seek(Position, 0);
|
||||
Files = new FARCFile[Count];
|
||||
}
|
||||
|
||||
int LocalMode = 0;
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
Files[i].Name = reader.NullTerminatedUTF8();
|
||||
Files[i].Offset = reader.ReadInt32Endian(true);
|
||||
if (Signature != Farc.FArc) Files[i].SizeComp = reader.ReadInt32Endian(true);
|
||||
Files[i].SizeUnc = reader.ReadInt32Endian(true);
|
||||
if (Signature == Farc.FARC && FT)
|
||||
{
|
||||
LocalMode = reader.ReadInt32Endian(true);
|
||||
Files[i].GZip = (LocalMode & 2) == 2;
|
||||
Files[i].ECB = (LocalMode & 4) == 4;
|
||||
}
|
||||
}
|
||||
NewFARC();
|
||||
string[] files = Directory.GetFiles(DirectoryPath);
|
||||
Files = new FARCFile[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 = null;
|
||||
this.Signature = Signature;
|
||||
Save();
|
||||
}
|
||||
|
||||
public void Pack(string file)
|
||||
public void Save()
|
||||
{
|
||||
Files = null;
|
||||
FT = false;
|
||||
string[] files = Directory.GetFiles(file);
|
||||
Files = new FARCFile[files.Length];
|
||||
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
Files[i] = new FARCFile { Name = files[i] };
|
||||
string ext = Path.GetExtension(files[i]).ToLower();
|
||||
if (ext == ".a3da" || ext == ".diva" || ext == ".vag") Signature = Farc.FArc;
|
||||
}
|
||||
files = null;
|
||||
|
||||
Stream writer = File.OpenWriter(file + ".farc", true);
|
||||
writer.WriteEndian((int)Signature, true);
|
||||
|
||||
Stream HeaderWriter = File.OpenWriter();
|
||||
for (int i = 0; i < 3; i++) HeaderWriter.WriteByte(0x00);
|
||||
if (Signature == Farc.FArc) HeaderWriter.WriteByte(0x20);
|
||||
else if (Signature == Farc.FArC) HeaderWriter.WriteByte(0x10);
|
||||
else if (Signature == Farc.FARC)
|
||||
{
|
||||
HeaderWriter.WriteByte(0x06);
|
||||
for (int i = 0; i < 7; i++) HeaderWriter.WriteByte(0x00);
|
||||
HeaderWriter.WriteByte(0x40);
|
||||
for (int i = 0; i < 8; i++) HeaderWriter.WriteByte(0x00);
|
||||
}
|
||||
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;
|
||||
{
|
||||
string ext = Path.GetExtension(Files[i].Name).ToLower();
|
||||
if (ext == ".a3da" || ext == ".diva" || ext == ".vag")
|
||||
{ Signature = Farc.FArc; break; }
|
||||
}
|
||||
|
||||
int Align = writer.Position.Align(0x10) - writer.Position;
|
||||
Stream writer = File.OpenWriter(DirectoryPath + ".farc", true);
|
||||
writer.WE((int)Signature, true);
|
||||
|
||||
using (Stream HeaderWriter = File.OpenWriter())
|
||||
{
|
||||
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);
|
||||
}
|
||||
int HeaderPartLength = Signature == Farc.FArc ? 0x09 : 0x0D;
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
HeaderWriter.L += Path.GetFileName(Files[i].Name).Length + HeaderPartLength;
|
||||
writer.WE(HeaderWriter.L, true);
|
||||
writer.W(HeaderWriter.ToArray(true));
|
||||
}
|
||||
|
||||
int Align = writer.P.Align(0x10) - writer.P;
|
||||
for (int i1 = 0; i1 < Align; i1++)
|
||||
if (Signature == Farc.FArc) writer.WriteByte(0x00);
|
||||
else writer.WriteByte(0x78);
|
||||
writer.W((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
|
||||
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
CompressStuff(i, ref Files, ref writer);
|
||||
|
||||
if (Signature == Farc.FARC) writer.Seek(0x1C, 0);
|
||||
else writer.Seek(0x0C, 0);
|
||||
writer.P = 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);
|
||||
writer.W(Path.GetFileName(Files[i].Name) + "\0");
|
||||
writer.WE(Files[i].Offset, true);
|
||||
if (Signature != Farc.FArc)
|
||||
writer.WriteEndian(Files[i].SizeComp, true);
|
||||
writer.WriteEndian(Files[i].SizeUnc, true);
|
||||
writer.WE(Files[i].SizeComp, true);
|
||||
writer.WE(Files[i].SizeUnc, true);
|
||||
}
|
||||
writer.Close();
|
||||
writer.Dispose();
|
||||
}
|
||||
|
||||
void CompressStuff(int i, ref FARCFile[] Files, ref Stream writer)
|
||||
private void CompressStuff(int i, ref FARCFile[] Files, ref Stream writer)
|
||||
{
|
||||
Files[i].Offset = writer.Position;
|
||||
Files[i].Data = File.ReadAllBytes(Files[i].Name);
|
||||
Files[i].Offset = writer.P;
|
||||
Files[i].SizeUnc = Files[i].Data.Length;
|
||||
Files[i].Type = Type.None;
|
||||
|
||||
if (Signature != Farc.FArc)
|
||||
if (Signature == Farc.FArC || (Signature == Farc.FARC && FARCType.HasFlag(Type.GZip)))
|
||||
{
|
||||
if (Signature != Farc.FArc)
|
||||
{
|
||||
MSIO.MemoryStream stream = new MSIO.MemoryStream();
|
||||
using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Compress))
|
||||
gZipStream.Write(Files[i].Data, 0, Files[i].Data.Length);
|
||||
Files[i].Data = stream.ToArray();
|
||||
stream.Dispose();
|
||||
Files[i].SizeComp = Files[i].Data.Length;
|
||||
}
|
||||
else if (Signature == Farc.FARC)
|
||||
{
|
||||
int AlignData = Files[i].Data.Length.Align(0x40);
|
||||
byte[] Data = new byte[AlignData];
|
||||
for (int i1 = 0; i1 < Files[i].Data.Length; i1++)
|
||||
Data[i1] = Files[i].Data[i1];
|
||||
for (int i1 = Files[i].Data.Length; i1 < AlignData; i1++)
|
||||
Data[i1] = 0x78;
|
||||
|
||||
Files[i].Data = Encrypt(Data, false);
|
||||
}
|
||||
Files[i].Type |= Type.GZip;
|
||||
MSIO.MemoryStream stream = new MSIO.MemoryStream();
|
||||
using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Compress))
|
||||
gZipStream.Write(Files[i].Data, 0, Files[i].Data.Length);
|
||||
Files[i].Data = stream.ToArray();
|
||||
stream.Dispose();
|
||||
Files[i].SizeComp = Files[i].Data.Length;
|
||||
}
|
||||
writer.Write(Files[i].Data);
|
||||
|
||||
if (Signature == Farc.FARC && FARCType.HasFlag(Type.ECB))
|
||||
{
|
||||
int AlignData = Files[i].Data.Length.Align(0x40);
|
||||
byte[] Data = new byte[AlignData];
|
||||
for (int i1 = 0; i1 < AlignData ; i1++) Data[i1] = 0x78;
|
||||
for (int i1 = 0; i1 < Files[i].Data.Length; i1++) Data[i1] = Files[i].Data[i1];
|
||||
|
||||
Files[i].Data = Encrypt(Data, false);
|
||||
}
|
||||
|
||||
writer.W(Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
|
||||
if (Signature != Farc.FARC)
|
||||
{
|
||||
int Align = writer.Position.Align(0x20) - writer.Position;
|
||||
int Align = writer.P.Align(0x20) - writer.P;
|
||||
for (int i1 = 0; i1 < Align; i1++)
|
||||
if (Signature == Farc.FArc) writer.WriteByte(0x00);
|
||||
else writer.WriteByte(0x78);
|
||||
writer.W((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
aes.CreateEncryptor(), CryptoStreamMode.Write))
|
||||
cryptoStream.Write(Data, 0, Data.Length);
|
||||
return stream.ToArray();
|
||||
}
|
||||
|
||||
public enum Farc
|
||||
{
|
||||
FArc = 0x46417263,
|
||||
FArC = 0x46417243,
|
||||
FARC = 0x46415243,
|
||||
}
|
||||
public void Dispose() => NewFARC();
|
||||
|
||||
public struct FARCFile
|
||||
{
|
||||
public int Offset;
|
||||
public int SizeComp;
|
||||
public int SizeUnc;
|
||||
public bool GZip;
|
||||
public bool ECB;
|
||||
public Type Type;
|
||||
public byte[] Data;
|
||||
public string Name;
|
||||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
public enum Farc : int
|
||||
{
|
||||
FArc = 0x46417263,
|
||||
FArC = 0x46417243,
|
||||
FARC = 0x46415243,
|
||||
}
|
||||
|
||||
public enum Type : int
|
||||
{
|
||||
None = 0b000,
|
||||
GZip = 0b010,
|
||||
ECB = 0b100,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using MSIO = System.IO;
|
||||
using MSIO = System.IO;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
|
||||
@@ -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.I64P < stream.I64L)
|
||||
{
|
||||
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.I64P--; return val; }
|
||||
public static char PCASCII(this Stream stream)
|
||||
{ byte val = stream.RU8(); stream.I64P--; return (char)val; }
|
||||
public static char PCUTF8 (this Stream stream)
|
||||
{ long LongPosition = stream.I64P; char val = stream.RCUTF8();
|
||||
stream.I64P = 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 A(this Stream stream, byte next)
|
||||
{ if (stream.PB() == next) { stream.PB(); return true; } else return false; }
|
||||
public static bool A(this Stream stream, byte[] next)
|
||||
{
|
||||
for (var i = 0; i < next.Length; i++)
|
||||
if (!A(stream, next[i])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool AASCII(this Stream stream, char next)
|
||||
{ if (stream.PCUTF8() == next) { stream.RCUTF8(); return true; } else return false; }
|
||||
public static bool AASCII(this Stream stream, string next)
|
||||
{
|
||||
for (var i = 0; i < next.Length; i++)
|
||||
if (!stream.AASCII(next[i])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool A(this Stream stream, char next)
|
||||
{ if (stream.PCUTF8() == next) { stream.RCUTF8(); return true; } else return false; }
|
||||
public static bool a(this Stream stream, string next)
|
||||
{
|
||||
for (var i = 0; i < next.Length; i++)
|
||||
if (!A(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.I64P;
|
||||
if (Offset == -1) { Position += stream.IsX ? 8 : 4; Offset = stream.RIX(); }
|
||||
stream.I64P = Offset;
|
||||
if (Length == -1) arr = stream.NT();
|
||||
else arr = stream.RBy(Length);
|
||||
stream.I64P = Position;
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static string RSaO(this Stream stream, long Offset = -1, long Length = -1)
|
||||
{
|
||||
string s = null;
|
||||
long Position = stream.I64P;
|
||||
if (Offset == -1) { Position += stream.IsX ? 8 : 4; Offset = stream.RIX(); }
|
||||
stream.I64P = Offset;
|
||||
if (Length == -1) s = stream.NTUTF8();
|
||||
else s = stream.RSUTF8(Length);
|
||||
stream.I64P = 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 = 0, long Length = 0) =>
|
||||
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); }
|
||||
}
|
||||
}
|
||||
+15
-13
@@ -5,18 +5,19 @@ namespace KKdMainLib.IO
|
||||
{
|
||||
public static class File
|
||||
{
|
||||
public static Stream OpenReader(byte[] Data) => new Stream(new MSIO.MemoryStream(Data), Data);
|
||||
public static Stream OpenReader(byte[] Data) => new Stream(new MSIO.MemoryStream(Data));
|
||||
public static Stream OpenWriter( ) => new Stream(new MSIO.MemoryStream( ));
|
||||
|
||||
public static Stream OpenReader(string file, bool ReadAllAtOnce)
|
||||
{ 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; }
|
||||
public static Stream OpenWriter(string file, bool SetLength0)
|
||||
{ Stream IO = OpenWriter(file); 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,
|
||||
MSIO.FileMode.OpenOrCreate, MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite)) { File = file };
|
||||
@@ -25,27 +26,28 @@ namespace KKdMainLib.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)) 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)) 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)) for (int i = 0; i < data.Length; i++)
|
||||
IO.W(data[i] + "\r\n"); }
|
||||
|
||||
public static bool Exists(string file) => MSIO.File.Exists(file);
|
||||
public static void Delete(string file) => MSIO.File.Delete(file);
|
||||
|
||||
@@ -1,71 +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)
|
||||
{
|
||||
long LongPosition = stream.LongPosition;
|
||||
while (true)
|
||||
if (char.IsWhiteSpace(stream.ReadCharUTF8())) LongPosition = stream.LongPosition;
|
||||
else { stream.LongPosition = LongPosition; break; }
|
||||
return stream;
|
||||
}
|
||||
public static bool Assert(this Stream stream, char next)
|
||||
{ if (stream.PeekCharUTF8() == next) { stream.ReadCharUTF8(); return true; } else return false; }
|
||||
public static bool Assert(this Stream stream, string next)
|
||||
{
|
||||
for (var i = 0; i < next.Length; i++)
|
||||
if (!stream.Assert(next[i])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static long ReadIntX(this Stream stream ) => stream.IsX ?
|
||||
stream.ReadInt64() : stream.ReadUInt32Endian( );
|
||||
public static long ReadIntX(this Stream stream, bool IsBE) => stream.IsX ?
|
||||
stream.ReadInt64() : stream.ReadUInt32Endian(IsBE);
|
||||
|
||||
public static byte[] ReadAtOffset(this Stream stream, long Offset = 0, long Length = 0)
|
||||
{
|
||||
byte[] arr = null;
|
||||
long Position = stream.LongPosition;
|
||||
if (Offset == 0) { Position += stream.IsX ? 8 : 4; Offset = stream.ReadIntX(); }
|
||||
stream.LongPosition = Offset;
|
||||
if (Length == 0) arr = stream.NullTerminated();
|
||||
else arr = stream.ReadBytes(Length);
|
||||
stream.LongPosition = Position;
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static string ReadStringAtOffset(this Stream stream, long Offset = 0, long Length = 0)
|
||||
{
|
||||
string s = null;
|
||||
long Position = stream.LongPosition;
|
||||
if (Offset == 0) { Position += stream.IsX ? 8 : 4; Offset = stream.ReadIntX(); }
|
||||
stream.LongPosition = Offset;
|
||||
if (Length == 0) s = stream.NullTerminatedUTF8();
|
||||
else s = stream.ReadStringUTF8(Length);
|
||||
stream.LongPosition = Position;
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
//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) => _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
|
||||
switch (c)
|
||||
{
|
||||
case '"': obj = RS (); break;
|
||||
case '{': obj = RO (); break;
|
||||
case '[': obj = RA (); break;
|
||||
case '-': obj = RF (); break;
|
||||
case 't':
|
||||
case 'f': obj = RBo(); break;
|
||||
case 'n': obj = RN (); break;
|
||||
}
|
||||
return new MsgPack(Key, obj);
|
||||
}
|
||||
|
||||
private string RS()
|
||||
{
|
||||
if (!Extensions.A(_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.A(_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.A(_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.A(_IO, '[')) return null;
|
||||
if (_IO.SW().PCUTF8() == ']')
|
||||
{ _IO.RCUTF8(); return null; }
|
||||
|
||||
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 += ReadDigits ();
|
||||
if (_IO.PCUTF8() == '.') s += _IO.RCUTF8() + 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.PCUTF8();
|
||||
if (c == 'e' || c == 'E')
|
||||
{
|
||||
s += _IO.RCUTF8();
|
||||
c = _IO.PCUTF8();
|
||||
if (c == '+' || c == '-') s += _IO.RCUTF8();
|
||||
s += ReadDigits();
|
||||
}
|
||||
double d = s.ToDouble();
|
||||
return (float)d == d ? (float)d : d;
|
||||
}
|
||||
|
||||
private bool RBo()
|
||||
{
|
||||
char c = _IO.PCUTF8();
|
||||
if (c == 't' && _IO.a( "true")) return true;
|
||||
else if (c == 'f' && _IO.a("false")) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
private object RN() { _IO.a("null"); return null; }
|
||||
|
||||
private string ReadDigits()
|
||||
{ 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.ToString(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 ? "}" : "{");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,343 @@
|
||||
using KKdBaseLib;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public struct MP : System.IDisposable
|
||||
{
|
||||
public MP(Stream IO) => _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 Write(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++) Write(val[i]); break;
|
||||
case MsgPack[] val: WA(val.Length);
|
||||
for (int i = 0; i < val.Length; i++) Write(val[i]); break;
|
||||
case MsgPack val: Write(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: WE(val); break;
|
||||
}
|
||||
}
|
||||
|
||||
private void W( sbyte val) { if (val < -0x20) _IO.W(0xD0); _IO.W(val); }
|
||||
private void W( byte val) { if (val >= 0x80) _IO.W(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(0xD1); _IO.WE(val, true); } }
|
||||
private void W(ushort val) { if (( byte)val == val) W(( byte)val);
|
||||
else { _IO.W(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(0xD2); _IO.WE(val, true); } }
|
||||
private void W( uint val) { if ((ushort)val == val) W((ushort)val);
|
||||
else { _IO.W(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(0xD3); _IO.WE(val, true); } }
|
||||
private void W( ulong val) { if (( uint)val == val) W(( uint)val);
|
||||
else { _IO.W(0xCF); _IO.WE(val, true); } }
|
||||
private void W( float val) { if (( long)val == val) W(( long)val);
|
||||
else { _IO.W(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(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(0xC4); _IO.W (( byte)val.Length ); }
|
||||
else if (val.Length < 0x10000)
|
||||
{ _IO.W(0xC5); _IO.WE((ushort)val.Length, true); }
|
||||
else
|
||||
{ _IO.W(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(0xD9); _IO.W (( byte)array.Length); }
|
||||
else if (array.Length < 0x10000) { _IO.W(0xDA); _IO.WE((ushort)array.Length, true); }
|
||||
else { _IO.W(0xDB); _IO.WE( array.Length, true); }
|
||||
_IO.W(array);
|
||||
}
|
||||
|
||||
private void WN() => _IO.W(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(0xDC); _IO.WE((ushort)val, true); }
|
||||
else { _IO.W(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(0xDE); _IO.WE((ushort)val, true); }
|
||||
else { _IO.W(0xDF); _IO.WE( val, true); }
|
||||
}
|
||||
|
||||
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(0xD4);
|
||||
else if (val.Data.Length == 2 ) _IO.W(0xD5);
|
||||
else if (val.Data.Length == 4 ) _IO.W(0xD6);
|
||||
else if (val.Data.Length == 8 ) _IO.W(0xD7);
|
||||
else if (val.Data.Length == 16) _IO.W(0xD8);
|
||||
else
|
||||
{
|
||||
if (val.Data.Length < 0x100)
|
||||
{ _IO.W(0xC7); _IO.W (( byte)val.Data.Length); }
|
||||
else if (val.Data.Length < 0x10000)
|
||||
{ _IO.W(0xC8); _IO.WE((ushort)val.Data.Length, true); }
|
||||
else
|
||||
{ _IO.W(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,
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using MSIO = System.IO;
|
||||
using MSIO = System.IO;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
@@ -21,5 +20,7 @@ namespace KKdMainLib.IO
|
||||
MSIO.Path.Combine(path1, path2, path3, path4);
|
||||
public static string Combine(params string[] paths) =>
|
||||
MSIO.Path.Combine(paths);
|
||||
public static string GetDirectoryName(string path) =>
|
||||
MSIO.Path.GetDirectoryName(path);
|
||||
}
|
||||
}
|
||||
|
||||
+173
-250
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using KKdMainLib.Types;
|
||||
using KKdBaseLib;
|
||||
using MSIO = System.IO;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
@@ -7,37 +7,35 @@ 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 int I, i, BitRead, BitWrite, TempBitRead, TempBitWrite, ValRead, ValWrite;
|
||||
private byte[] buf;
|
||||
private byte[] data;
|
||||
private byte* ptr;
|
||||
|
||||
private Main.Format _format = Main.Format.NULL;
|
||||
private Format _format = Format.NULL;
|
||||
|
||||
public Main.Format Format
|
||||
public Format Format
|
||||
{ get => _format;
|
||||
set { _format = value;
|
||||
IsBE = _format == Main.Format.F2BE;
|
||||
IsX = _format == Main.Format.X || _format == Main.Format.XHD; } }
|
||||
IsBE = _format == Format.F2BE;
|
||||
IsX = _format == Format.X || _format == Format.XHD; } }
|
||||
|
||||
public bool IsBE = false;
|
||||
public bool IsX = false;
|
||||
|
||||
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)I64O; set => I64O = value; }
|
||||
public uint U32O { get => (uint)I64O; set => I64O = value; }
|
||||
public long I64O;
|
||||
|
||||
public int Length { get => ( int)stream.Length; set => stream.SetLength(value); }
|
||||
public uint UIntLength { get => (uint)stream.Length; set => stream.SetLength(value); }
|
||||
public long LongLength { get => stream.Length; set => stream.SetLength(value); }
|
||||
public int L { get => ( int)stream.Length - O; set => stream.SetLength(value + O); }
|
||||
public uint U32L { get => (uint)stream.Length - U32O; set => stream.SetLength(value + U32O); }
|
||||
public long I64L { get => stream.Length - I64O; set => stream.SetLength(value + I64O); }
|
||||
|
||||
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)stream.Position - O; set => stream.Position = value + O; }
|
||||
public uint U32P
|
||||
{ get => (uint)stream.Position - U32O; set => stream.Position = value + U32O; }
|
||||
public long I64P
|
||||
{ get => stream.Position - I64O; set => stream.Position = value + I64O; }
|
||||
|
||||
public bool CanRead => stream.CanRead;
|
||||
public bool CanSeek => stream.CanSeek;
|
||||
@@ -46,243 +44,160 @@ namespace KKdMainLib.IO
|
||||
|
||||
public string File = null;
|
||||
|
||||
public Stream(MSIO.Stream output = null, byte[] Data = null, bool isBE = false)
|
||||
public Stream(MSIO.Stream output = null, bool isBE = false)
|
||||
{
|
||||
if (output == null) output = MSIO.Stream.Null;
|
||||
LongOffset = 0;
|
||||
I64O = 0;
|
||||
BitRead = 8;
|
||||
ValRead = ValRead = BitWrite = 0;
|
||||
stream = output;
|
||||
Format = Main.Format.NULL;
|
||||
buf = new byte[128];
|
||||
Format = Format.NULL;
|
||||
buf = new byte[0x100];
|
||||
ptr = buf.GetPtr();
|
||||
IsBE = isBE;
|
||||
data = Data;
|
||||
}
|
||||
|
||||
public void Close() => Dispose();
|
||||
public void C() => D(true);
|
||||
|
||||
public void Flush() => stream.Flush();
|
||||
public void F() => stream.Flush();
|
||||
|
||||
public void SetLength(long length = 0) => stream.SetLength(length);
|
||||
public void SL(long length = 0) => stream.SetLength(length);
|
||||
|
||||
public long Seek(long offset, SeekOrigin origin = 0) =>
|
||||
public long S(long offset, SeekOrigin origin = 0) =>
|
||||
stream.Seek(offset, (MSIO.SeekOrigin)(int)origin);
|
||||
|
||||
public long? Seek(long? offset, SeekOrigin origin)
|
||||
public long? S(long? offset, SeekOrigin origin)
|
||||
{ if (offset == null) return null; return stream.Seek((long)offset, (MSIO.SeekOrigin)(int)origin); }
|
||||
|
||||
public void Dispose()
|
||||
{ CheckWrited(); Dispose(true); }
|
||||
private bool disposed = false;
|
||||
public void D() => D(true);
|
||||
public void Dispose() => D(true);
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{ if (disposing && stream != MSIO.Stream.Null) stream.Flush(); stream.Dispose(); data = null; }
|
||||
protected virtual void D(bool dispose)
|
||||
{ CW(); if (stream != MSIO.Stream.Null && !disposed) { disposed = true; stream.Flush();
|
||||
stream.Dispose(); } if (dispose) GC.SuppressFinalize(this); }
|
||||
|
||||
public MSIO.Stream BaseStream
|
||||
public MSIO.Stream BS
|
||||
{ get { stream.Flush(); return stream; } set { stream = value; } }
|
||||
|
||||
public void Align(long Align)
|
||||
public void A(long Align)
|
||||
{
|
||||
long Al = Align - Position % Align;
|
||||
if (Position % Align != 0)
|
||||
stream.Seek(Position + Al, 0);
|
||||
long Al = Align - P % Align;
|
||||
if (P % Align != 0) stream.Seek(P + O + Al, 0);
|
||||
}
|
||||
|
||||
public void Align(long Align, bool SetLength)
|
||||
public void A(long Align, bool SetLength)
|
||||
{
|
||||
if (SetLength) stream.SetLength(Position);
|
||||
long Al = Align - Position % Align;
|
||||
if (Position % Align != 0) stream.Seek(Position + Al, 0);
|
||||
if (SetLength) stream.SetLength(Position);
|
||||
if (SetLength) stream.SetLength(P + O);
|
||||
long Al = Align - P % Align;
|
||||
if (P % Align != 0) stream.Seek(P + O + Al, 0);
|
||||
if (SetLength) stream.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);
|
||||
long Al = Align - Position % Align;
|
||||
if (Position % Align != 0) stream.Seek(Position + Al, 0);
|
||||
if (SetLength1) stream.SetLength(Position);
|
||||
if (SetLength0) stream.SetLength(P + O);
|
||||
long Al = Align - P % Align;
|
||||
if (P % Align != 0) stream.Seek(P + Al, 0);
|
||||
if (SetLength1) stream.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 bool RBo () => stream.ReadByte() != 0;
|
||||
public sbyte RI8 () => (sbyte)stream.ReadByte();
|
||||
public byte RU8 () => ( byte)stream.ReadByte();
|
||||
public short RI16() { CR(); stream.Read(buf, 0, 2); return *( short*)ptr; }
|
||||
public ushort RU16() { CR(); stream.Read(buf, 0, 2); return *(ushort*)ptr; }
|
||||
public int RI32() { CR(); stream.Read(buf, 0, 4); return *( int*)ptr; }
|
||||
public uint RU32() { CR(); stream.Read(buf, 0, 4); return *( uint*)ptr; }
|
||||
public long RI64() { CR(); stream.Read(buf, 0, 8); return *( long*)ptr; }
|
||||
public ulong RU64() { CR(); stream.Read(buf, 0, 8); return *( ulong*)ptr; }
|
||||
public float RF32() { CR(); stream.Read(buf, 0, 4); return *( float*)ptr; }
|
||||
public double RF64() { CR(); stream.Read(buf, 0, 8); return *(double*)ptr; }
|
||||
|
||||
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 short RI16E() { CR(); stream.Read(buf, 0, 2); buf.Endian(2, IsBE); return *( short*)ptr; }
|
||||
public ushort RU16E() { CR(); stream.Read(buf, 0, 2); buf.Endian(2, IsBE); return *(ushort*)ptr; }
|
||||
public int RI32E() { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( int*)ptr; }
|
||||
public uint RU32E() { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( uint*)ptr; }
|
||||
public long RI64E() { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *( long*)ptr; }
|
||||
public ulong RU64E() { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *( ulong*)ptr; }
|
||||
public float RF32E() { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( float*)ptr; }
|
||||
public double RF64E() { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *(double*)ptr; }
|
||||
|
||||
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(bool IsBE) { CR(); stream.Read(buf, 0, 2); buf.Endian(2, IsBE); return *( short*)ptr; }
|
||||
public ushort RU16E(bool IsBE) { CR(); stream.Read(buf, 0, 2); buf.Endian(2, IsBE); return *(ushort*)ptr; }
|
||||
public int RI32E(bool IsBE) { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( int*)ptr; }
|
||||
public uint RU32E(bool IsBE) { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( uint*)ptr; }
|
||||
public long RI64E(bool IsBE) { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *( long*)ptr; }
|
||||
public ulong RU64E(bool IsBE) { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *( ulong*)ptr; }
|
||||
public float RF32E(bool IsBE) { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( float*)ptr; }
|
||||
public double RF64E(bool IsBE) { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *(double*)ptr; }
|
||||
|
||||
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 void W(byte[] Val ) => stream.Write(Val ?? new byte[0], 0, Val.Length);
|
||||
public void W(byte[] Val, int Length) => stream.Write(Val ?? new byte[0], 0, Length);
|
||||
public void W(byte[] Val, int Offset, int Length) => stream.Write(Val ?? new byte[0], Offset, Length);
|
||||
public void W(char[] val, bool UTF8 = true) => W(UTF8 ? val.ToUTF8() : val.ToASCII());
|
||||
|
||||
public void WriteByte(byte val) => stream.WriteByte(val);
|
||||
public void W( bool val) => stream.WriteByte((byte)(val ? 1 : 0));
|
||||
public void W( sbyte val) => stream.WriteByte((byte) val);
|
||||
public void W( byte val) => stream.WriteByte( val);
|
||||
public void W( short val) { CW(); *( short*)ptr = val; stream.Write(buf, 0, 2); }
|
||||
public void W(ushort val) { CW(); *(ushort*)ptr = val; stream.Write(buf, 0, 2); }
|
||||
public void W( int val) { CW(); *( int*)ptr = val; stream.Write(buf, 0, 4); }
|
||||
public void W( uint val) { CW(); *( uint*)ptr = val; stream.Write(buf, 0, 4); }
|
||||
public void W( long val) { CW(); *( long*)ptr = val; stream.Write(buf, 0, 8); }
|
||||
public void W( ulong val) { CW(); *( ulong*)ptr = val; stream.Write(buf, 0, 8); }
|
||||
public void W( float val) { CW(); *( float*)ptr = val; stream.Write(buf, 0, 4); }
|
||||
public void W(double val) { CW(); *(double*)ptr = val; stream.Write(buf, 0, 8); }
|
||||
|
||||
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( 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 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 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( 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 WE( short val) { CW(); *( short*)ptr = val; buf.Endian(2, IsBE); stream.Write(buf, 0, 2); }
|
||||
public void WE(ushort val) { CW(); *(ushort*)ptr = val; buf.Endian(2, IsBE); stream.Write(buf, 0, 2); }
|
||||
public void WE( int val) { CW(); *( int*)ptr = val; buf.Endian(4, IsBE); stream.Write(buf, 0, 4); }
|
||||
public void WE( uint val) { CW(); *( uint*)ptr = val; buf.Endian(4, IsBE); stream.Write(buf, 0, 4); }
|
||||
public void WE( long val) { CW(); *( long*)ptr = val; buf.Endian(8, IsBE); stream.Write(buf, 0, 8); }
|
||||
public void WE( ulong val) { CW(); *( ulong*)ptr = val; buf.Endian(8, IsBE); stream.Write(buf, 0, 8); }
|
||||
public void WE( float val) { CW(); *( float*)ptr = val; buf.Endian(4, IsBE); stream.Write(buf, 0, 4); }
|
||||
public void WE(double val) { CW(); *(double*)ptr = val; buf.Endian(8, IsBE); stream.Write(buf, 0, 8); }
|
||||
|
||||
public void WE( short val, bool IsBE) { CW(); *( short*)ptr = val; buf.Endian(2, IsBE); stream.Write(buf, 0, 2); }
|
||||
public void WE(ushort val, bool IsBE) { CW(); *(ushort*)ptr = val; buf.Endian(2, IsBE); stream.Write(buf, 0, 2); }
|
||||
public void WE( int val, bool IsBE) { CW(); *( int*)ptr = val; buf.Endian(4, IsBE); stream.Write(buf, 0, 4); }
|
||||
public void WE( uint val, bool IsBE) { CW(); *( uint*)ptr = val; buf.Endian(4, IsBE); stream.Write(buf, 0, 4); }
|
||||
public void WE( long val, bool IsBE) { CW(); *( long*)ptr = val; buf.Endian(8, IsBE); stream.Write(buf, 0, 8); }
|
||||
public void WE( ulong val, bool IsBE) { CW(); *( ulong*)ptr = val; buf.Endian(8, IsBE); stream.Write(buf, 0, 8); }
|
||||
public void WE( float val, bool IsBE) { CW(); *( float*)ptr = val; buf.Endian(4, IsBE); stream.Write(buf, 0, 4); }
|
||||
public void WE(double val, bool IsBE) { CW(); *(double*)ptr = val; buf.Endian(8, IsBE); stream.Write(buf, 0, 8); }
|
||||
|
||||
public void WriteEndian( short* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(2, Endian(val[i], 2, IsBE)); }
|
||||
public void WriteEndian(ushort* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(2, Endian(val[i], 2, IsBE)); }
|
||||
public void WriteEndian( int* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, Endian(val[i], 4, IsBE)); }
|
||||
public void WriteEndian( uint* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, Endian(val[i], 4, IsBE)); }
|
||||
public void WriteEndian( long* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(8, Endian(val[i], 8, IsBE)); }
|
||||
public void WriteEndian( ulong* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(8, Endian(val[i], 8, IsBE)); }
|
||||
public void WriteEndian( float* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(4, Endian(*( uint*)&val[i], 4, IsBE)); }
|
||||
public void WriteEndian(double* val, int Length)
|
||||
{ for (i = 0; i < Length; i++) ToArray(8, Endian(*(ulong*)&val[i], 8, IsBE)); }
|
||||
|
||||
public void WriteEndian( short* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) 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 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 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 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 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 char RC(bool UTF8 = true) => UTF8 ? RCUTF8() : (char)stream.ReadByte();
|
||||
|
||||
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 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; }
|
||||
|
||||
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; }
|
||||
|
||||
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); }
|
||||
|
||||
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); }
|
||||
|
||||
private long IntFromArray(byte L) { stream.Read(buf, 0, L); long val = 0;
|
||||
for (I = L; I > 0; I--) { val <<= 8; val |= buf[I - 1]; } return val; }
|
||||
|
||||
private ulong UIntFromArray(byte L) { stream.Read(buf, 0, L); ulong val = 0;
|
||||
for (I = L; I > 0; I--) { val <<= 8; val |= buf[I - 1]; } return val; }
|
||||
|
||||
private long IntFromArray(byte L, bool IsBE) { stream.Read(buf, 0, L); long val = 0; if (IsBE)
|
||||
for (I = 0; I < L; I++) { val <<= 8; val |= buf[I ]; } else
|
||||
for (I = L; I > 0; I--) { val <<= 8; val |= buf[I - 1]; } return val; }
|
||||
|
||||
private ulong UIntFromArray(byte L, bool IsBE) { stream.Read(buf, 0, L); ulong val = 0; if (IsBE)
|
||||
for (I = 0; I < L; I++) { val <<= 8; val |= buf[I ]; } else
|
||||
for (I = L; I > 0; I--) { val <<= 8; val |= buf[I - 1]; } return val; }
|
||||
|
||||
public char ReadChar(bool UTF8 = true)
|
||||
{ if (UTF8) return ReadCharUTF8();
|
||||
else return (char)stream.ReadByte(); }
|
||||
|
||||
public char ReadCharUTF8()
|
||||
public char RCUTF8()
|
||||
{
|
||||
byte t;
|
||||
int T;
|
||||
int val = 0;
|
||||
for (I = 0, i0 = 4; I < i0; I++)
|
||||
for (I = 0, i = 4; I < i; I++)
|
||||
{
|
||||
T = stream.ReadByte();
|
||||
if (T == -1) return '\uFFFF';
|
||||
@@ -290,44 +205,42 @@ namespace KKdMainLib.IO
|
||||
|
||||
if ((t & 0xC0) == 0x80 && I > 0) val = (val << 6) | (t & 0x3F);
|
||||
else if ((t & 0x80) == 0x00 && I == 0) return (char)t;
|
||||
else if ((t & 0xE0) == 0xC0 && I == 0) { val = t & 0x1F; i0 = 2; }
|
||||
else if ((t & 0xF0) == 0xE0 && I == 0) { val = t & 0x0F; i0 = 3; }
|
||||
else if ((t & 0xF8) == 0xF0 && I == 0) { val = t & 0x07; i0 = 4; }
|
||||
else if ((t & 0xE0) == 0xC0 && I == 0) { val = t & 0x1F; i = 2; }
|
||||
else if ((t & 0xF0) == 0xE0 && I == 0) { val = t & 0x0F; i = 3; }
|
||||
else if ((t & 0xF8) == 0xF0 && I == 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 string RSUTF8 (long Length) => RBy(Length).ToUTF8 ();
|
||||
public string RSASCII(long Length) => RBy(Length).ToASCII();
|
||||
|
||||
public byte[] ReadBytes(long Length, int Offset = 0)
|
||||
{ byte[] Buf = new byte[Length]; if (Offset > 0) stream.Position = Offset;
|
||||
|
||||
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) 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 void RBy(long Length, byte[] Buf, long Offset = -1)
|
||||
{ if (Offset > -1) stream.Position = Offset; stream.Read(Buf, 0, (int)Length); }
|
||||
|
||||
public byte[] ReadBytes(long? Length, int Offset = 0)
|
||||
{ if (Length == null) return new byte[0]; else return ReadBytes((long)Length, Offset); }
|
||||
public byte[] RBy(long? Length, int Offset = -1)
|
||||
{ if (Length == null) return new byte[0]; else return RBy((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 void RBy(long Length, byte Bits, byte[] Buf, long Offset = -1)
|
||||
{ if (Offset > -1) stream.Seek(Offset, 0);
|
||||
if (Bits > 0 && Bits < 8) for (i = 0; i < Length; i++) Buf[i] = RBi(Bits); }
|
||||
|
||||
public byte ReadBits(byte Bits)
|
||||
public byte RBi(byte Bits)
|
||||
{
|
||||
BitRead += Bits;
|
||||
TempBitRead = 8 - BitRead;
|
||||
@@ -340,10 +253,11 @@ namespace KKdMainLib.IO
|
||||
return (byte)((ValRead >> TempBitRead) & ((1 << Bits) - 1));
|
||||
}
|
||||
|
||||
public byte ReadHalfByte() => ReadBits(4);
|
||||
public byte RHB() => RBi(4);
|
||||
|
||||
public void Write(byte val, byte Bits)
|
||||
public void W(int val, byte Bits)
|
||||
{
|
||||
val &= (1 << Bits) - 1;
|
||||
BitWrite += Bits;
|
||||
TempBitWrite = 8 - BitWrite;
|
||||
if (TempBitWrite < 0)
|
||||
@@ -353,21 +267,30 @@ namespace KKdMainLib.IO
|
||||
stream.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
|
||||
{ CFUTRM(); if (BitRead > 0) ValRead = 0; BitRead = 8; }
|
||||
public void CW() //CheckWrite
|
||||
{ CFUTRM(); if (BitWrite > 0) { stream.WriteByte((byte)ValWrite); ValWrite = 0; BitWrite = 0; } }
|
||||
|
||||
public byte[] ToArray(bool Close)
|
||||
{ byte[] Data = ToArray(); if (Close) this.Close(); return Data; }
|
||||
{ byte[] Data = ToArray(); if (Close) Dispose(); return Data; }
|
||||
|
||||
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]
|
||||
[System.Security.SecuritySafeCritical]
|
||||
private void CFUTRM() //CheckForUnableToReadMemory
|
||||
{ try { if (buf[0] != ptr[0] || buf[1] != ptr[1] || buf[2] != ptr[2] || buf[3] != ptr[3] ||
|
||||
buf[4] != ptr[4] || buf[5] != ptr[5] || buf[6] != ptr[6] || buf[7] != ptr[7])
|
||||
ptr = buf.GetPtr(); } catch (AccessViolationException) { ptr = buf.GetPtr(); } }
|
||||
|
||||
public byte[] ToArray()
|
||||
{
|
||||
long Offset = stream.Position;
|
||||
LongPosition = 0;
|
||||
byte[] Data = ReadBytes(stream.Length);
|
||||
LongPosition = Offset;
|
||||
long Position = stream.Position;
|
||||
byte[] Data = RBy(stream.Length, 0);
|
||||
stream.Position = Position;
|
||||
return Data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
<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>
|
||||
@@ -33,38 +35,34 @@
|
||||
<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="A3DA\A3DAExt.cs" />
|
||||
<Compile Include="A3DA\A3DA.cs" />
|
||||
<Compile Include="Aet\Aet.cs" />
|
||||
<Compile Include="Aet\AetExt.cs" />
|
||||
<Compile Include="DB\Aet.cs" />
|
||||
<Compile Include="DB\Auth.cs" />
|
||||
<Compile Include="DB\Spr.cs" />
|
||||
<Compile Include="F2\Bloom.cs" />
|
||||
<Compile Include="F2\ColorCorrection.cs" />
|
||||
<Compile Include="F2\DOF.cs" />
|
||||
<Compile Include="F2\Light.cs" />
|
||||
<Compile Include="IO\Directory.cs" />
|
||||
<Compile Include="IO\Extensions.cs" />
|
||||
<Compile Include="IO\File.cs" />
|
||||
<Compile Include="IO\IOExtensions.cs" />
|
||||
<Compile Include="IO\JSON.cs" />
|
||||
<Compile Include="IO\MP.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\Vector2.cs" />
|
||||
<Compile Include="Types\Vector3.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="Extensions.cs" />
|
||||
<Compile Include="FARC.cs" />
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="MathExtensions.cs" />
|
||||
<Compile Include="PDHeader.cs" />
|
||||
<Compile Include="POF.cs" />
|
||||
<Compile Include="Mot.cs" />
|
||||
<Compile Include="STR.cs" />
|
||||
<Compile Include="Text.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -73,5 +71,11 @@
|
||||
<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>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
+35
-195
@@ -1,27 +1,13 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using KKdBaseLib;
|
||||
|
||||
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)
|
||||
@@ -39,107 +25,6 @@ namespace KKdMainLib
|
||||
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)
|
||||
{
|
||||
Console.WriteLine("Choose file(s) to open:");
|
||||
OpenFileDialog ofd = new OpenFileDialog { InitialDirectory =
|
||||
Application.StartupPath, Multiselect = true };
|
||||
|
||||
if (filetype == "a3da") ofd.Filter = GetArgs("A3DA", "a3da", "json", "mp") +
|
||||
GetArgs("A3DA", true, "a3da") + JSON + MsgPack;
|
||||
else if (filetype == "bin" ) ofd.Filter = GetArgs("BIN" , "bin", "json", "mp") +
|
||||
BIN + JSON + MsgPack;
|
||||
else if (filetype == "bon" ) ofd.Filter = GetArgs("BON" , "bon", "bin", "json", "mp") +
|
||||
GetArgs("BON", true, "bon") + BIN + JSON + MsgPack;
|
||||
else if (filetype == "databank") ofd.Filter = GetArgs("DAT", "dat", "json", "mp") +
|
||||
GetArgs("DAT", true, "dat") + JSON + MsgPack;
|
||||
else if (filetype == "dex" ) ofd.Filter = GetArgs("DEX" , "dex", "bin", "json", "mp") +
|
||||
GetArgs("DEX", true, "dex") + BIN + JSON + MsgPack;
|
||||
else if (filetype == "diva") ofd.Filter = GetArgs("DIVA", "diva", "wav") +
|
||||
GetArgs("DIVA", true, "diva") + GetArgs("WAV", true, "wav");
|
||||
else if (filetype == "dsc" ) ofd.Filter = GetArgs("DSC" , "dsc", "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 == "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");
|
||||
else ofd.Filter = GetArgs("All;", false, "*");
|
||||
|
||||
if (ofd.ShowDialog() == DialogResult.OK)
|
||||
FileNames = ofd.FileNames;
|
||||
}
|
||||
else if (code == 2)
|
||||
{
|
||||
FolderBrowserDialog fbd = new FolderBrowserDialog();
|
||||
Console.WriteLine("Choose folder:");
|
||||
fbd.SelectedPath = Application.StartupPath;
|
||||
if (fbd.ShowDialog() == DialogResult.OK)
|
||||
return fbd.SelectedPath.ToString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void ChooseSave(int code, 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)
|
||||
{
|
||||
@@ -162,8 +47,10 @@ namespace KKdMainLib
|
||||
public static bool StartsWith(this Dictionary<string, object> Dict, string[] args)
|
||||
{
|
||||
Dictionary<string, object> bufDict = new Dictionary<string, object>();
|
||||
if (Dict == null)
|
||||
Dict = new Dictionary<string, object>();
|
||||
if (Dict == null) return false;
|
||||
else if (args.Length < 1) return false;
|
||||
|
||||
args[0] = args[0].ToLower();
|
||||
if (args.Length > 1)
|
||||
{
|
||||
string[] NewArgs = new string[args.Length - 1];
|
||||
@@ -178,24 +65,25 @@ namespace KKdMainLib
|
||||
}
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> Dict,
|
||||
ref bool value, char Split, string args)
|
||||
{ if (Dict.FindValue(out string val, args.Split(Split)))
|
||||
return bool.TryParse(val, out value); return false; }
|
||||
ref bool value, char Split, string args) =>
|
||||
Dict.FindValue(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)
|
||||
{ if (Dict.FindValue(out string val, args.Split(Split)))
|
||||
return int.TryParse(val, out value); return false; }
|
||||
ref int value, char Split, string args) =>
|
||||
Dict.FindValue(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)
|
||||
{ if (Dict.FindValue(out string val, args.Split(Split)))
|
||||
return val.ToDouble(out value); return false; }
|
||||
ref float value, char Split, string args) =>
|
||||
Dict.FindValue(out string val, args.Split(Split)) ? val.ToSingle( 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 FindValue(this Dictionary<string, object> Dict,
|
||||
ref string value, char Split, string args)
|
||||
{ if (Dict.FindValue(out string val, args.Split(Split)))
|
||||
{ value = val; return true; } return false; }
|
||||
{ value = val; return true; } return false; }
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> Dict,
|
||||
out bool value, string args)
|
||||
@@ -207,6 +95,11 @@ namespace KKdMainLib
|
||||
{ if (Dict.FindValue(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 float value, string args)
|
||||
{ if (Dict.FindValue(out string val, args.Split('.' )))
|
||||
return val.ToSingle(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('.' )))
|
||||
@@ -216,12 +109,17 @@ namespace KKdMainLib
|
||||
out int? value, string args)
|
||||
{ if (Dict.FindValue(out string val, args.Split('.' )))
|
||||
{ bool Val = int.TryParse(val, out int _value);
|
||||
value = _value; return Val; } value = null; return false; }
|
||||
value = _value; return Val; } value = null; return false; }
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> Dict,
|
||||
out float? value, string args)
|
||||
{ if (Dict.FindValue(out string val, args.Split('.' )))
|
||||
return val.ToSingle(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; }
|
||||
return val.ToDouble(out value); value = null; return false; }
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> Dict,
|
||||
out string value, string args)
|
||||
@@ -232,10 +130,11 @@ namespace KKdMainLib
|
||||
out string value, string[] args)
|
||||
{
|
||||
value = "";
|
||||
if (Dict == null) return false;
|
||||
if (Dict == null) return false;
|
||||
else if (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];
|
||||
@@ -261,7 +160,10 @@ namespace KKdMainLib
|
||||
string[] args, string value)
|
||||
{
|
||||
Dictionary<string, object> bufDict = new Dictionary<string, object>();
|
||||
if (Dict == null) Dict = new Dictionary<string, object>();
|
||||
if (Dict == null) Dict = new Dictionary<string, object>();
|
||||
else if (args.Length < 1) return;
|
||||
|
||||
args[0] = args[0].ToLower();
|
||||
if (args.Length > 1)
|
||||
{
|
||||
string[] NewArgs = new string[args.Length - 1];
|
||||
@@ -296,67 +198,5 @@ namespace KKdMainLib
|
||||
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 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,196 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public static class MathExtensions
|
||||
{
|
||||
public static void FloorCeiling(ref double Value)
|
||||
{ if (Value % 1 >= 0.5) Value = (long)(Value + 0.5);
|
||||
else Value = (long) Value; }
|
||||
|
||||
public static long FloorCeiling(this double Value)
|
||||
{ if (Value % 1 >= 0.5) return (long)(Value + 0.5);
|
||||
else return (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 double Round(this double c) => Math.Round(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; }
|
||||
}
|
||||
}
|
||||
@@ -1,326 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
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 MsgPack Read(bool NotArray = true)
|
||||
{
|
||||
MsgPack MsgPack = new MsgPack();
|
||||
byte Unk = _IO.ReadByte();
|
||||
MsgPack.Type = (MsgPack.Types)Unk;
|
||||
if (NotArray)
|
||||
{
|
||||
MsgPack.Name = ReadString(MsgPack.Type);
|
||||
if (MsgPack.Name != null) { Unk = _IO.ReadByte(); MsgPack.Type = (MsgPack.Types)Unk; }
|
||||
}
|
||||
|
||||
bool FixArr = MsgPack.Type >= MsgPack.Types.FixArr && MsgPack.Type <= MsgPack.Types.FixArrMax;
|
||||
bool FixMap = MsgPack.Type >= MsgPack.Types.FixMap && MsgPack.Type <= MsgPack.Types.FixMapMax;
|
||||
bool FixStr = MsgPack.Type >= MsgPack.Types.FixStr && MsgPack.Type <= MsgPack.Types.FixStrMax;
|
||||
bool PosInt = MsgPack.Type >= MsgPack.Types.PosInt && MsgPack.Type <= MsgPack.Types.PosIntMax;
|
||||
bool NegInt = MsgPack.Type >= MsgPack.Types.NegInt && MsgPack.Type <= MsgPack.Types.NegIntMax;
|
||||
if (FixArr || FixMap || FixStr || PosInt || NegInt)
|
||||
{
|
||||
if (FixArr || FixMap)
|
||||
{
|
||||
MsgPack.Type = FixMap ? MsgPack.Types.FixMap : MsgPack.Types.FixArr;
|
||||
if (FixMap)
|
||||
{
|
||||
MsgPack.Object = new List<object>();
|
||||
for (int i = 0; i < Unk - (byte)MsgPack.Type; i++)
|
||||
MsgPack.Add(Read());
|
||||
}
|
||||
else
|
||||
{
|
||||
MsgPack.Object = new object[Unk - (byte)MsgPack.Type];
|
||||
for (int i = 0; i < Unk - (byte)MsgPack.Type; i++)
|
||||
MsgPack[i] = Read(false);
|
||||
}
|
||||
}
|
||||
else if (FixStr)
|
||||
{ MsgPack.Object = ReadString(MsgPack.Type); MsgPack.Type = MsgPack.Types.FixStr; }
|
||||
else if (PosInt)
|
||||
{ MsgPack.Object = (ulong) Unk; MsgPack.Type = MsgPack.Types.PosInt; }
|
||||
else if (NegInt)
|
||||
{ MsgPack.Object = ( long)(sbyte)Unk; MsgPack.Type = MsgPack.Types.NegInt; }
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (ReadNil (ref MsgPack)) break;
|
||||
if (ReadArr (ref MsgPack)) break;
|
||||
if (ReadMap (ref MsgPack)) break;
|
||||
if (ReadExt (ref MsgPack)) break;
|
||||
if (ReadString (ref MsgPack)) break;
|
||||
if (ReadBoolean(ref MsgPack)) break;
|
||||
if (ReadBytes (ref MsgPack)) break;
|
||||
if (ReadInt (ref MsgPack)) break;
|
||||
if (ReadUInt (ref MsgPack)) break;
|
||||
if (ReadFloat (ref MsgPack)) break;
|
||||
break;
|
||||
}
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
private bool ReadInt(ref MsgPack MsgPack)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.Int8 ) MsgPack.Object = (long)_IO.ReadSByte();
|
||||
else if (MsgPack.Type == MsgPack.Types.Int16) MsgPack.Object = (long)_IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Int32) MsgPack.Object = (long)_IO.ReadInt32Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Int64) MsgPack.Object = (long)_IO.ReadInt64Endian(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadUInt(ref MsgPack MsgPack)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.UInt8 ) MsgPack.Object = (ulong)_IO.ReadByte();
|
||||
else if (MsgPack.Type == MsgPack.Types.UInt16) MsgPack.Object = (ulong)_IO.ReadUInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.UInt32) MsgPack.Object = (ulong)_IO.ReadUInt32Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.UInt64) MsgPack.Object = (ulong)_IO.ReadUInt64Endian(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadFloat(ref MsgPack MsgPack)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.Float32) MsgPack.Object = _IO.ReadSingleEndian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Float64) MsgPack.Object = _IO.ReadDoubleEndian(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadBoolean(ref MsgPack MsgPack)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.False) MsgPack.Object = false;
|
||||
else if (MsgPack.Type == MsgPack.Types.True ) MsgPack.Object = true ;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadBytes(ref MsgPack MsgPack)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.Bin8 ) Length = _IO.ReadByte();
|
||||
else if (MsgPack.Type == MsgPack.Types.Bin16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Bin32) Length = _IO.ReadInt32Endian(true);
|
||||
else return false;
|
||||
MsgPack.Object = _IO.ReadBytes(Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadString(ref MsgPack MsgPack)
|
||||
{
|
||||
string val = ReadString(MsgPack.Type);
|
||||
if (val != null) MsgPack.Object = val;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private string ReadString(MsgPack.Types Val)
|
||||
{
|
||||
if (Val >= MsgPack.Types.FixStr && Val <= MsgPack.Types.FixStrMax)
|
||||
return _IO.ReadString(Val - MsgPack.Types.FixStr);
|
||||
else if (Val >= MsgPack.Types.Str8 && Val <= MsgPack.Types.Str32)
|
||||
{
|
||||
Enum.TryParse(Val.ToString(), out MsgPack.Types Type);
|
||||
int Length = 0;
|
||||
if (Type == MsgPack.Types.Str8 ) Length = _IO.ReadByte();
|
||||
else if (Type == MsgPack.Types.Str16) Length = _IO.ReadInt16Endian(true);
|
||||
else Length = _IO.ReadInt32Endian(true);
|
||||
return _IO.ReadString(Length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool ReadNil(ref MsgPack MsgPack)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.Nil)
|
||||
MsgPack.Object = null;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadArr(ref MsgPack MsgPack)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.Arr16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Arr32) Length = _IO.ReadInt32Endian(true);
|
||||
else return false;
|
||||
MsgPack.Object = new object[Length];
|
||||
for (int i = 0; i < Length; i++) MsgPack[i] = Read(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadMap(ref MsgPack MsgPack)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.Map16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Map32) Length = _IO.ReadInt32Endian(true);
|
||||
else return false;
|
||||
MsgPack.Object = new List<object>();
|
||||
for (int i = 0; i < Length; i++) MsgPack.Add(Read());
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadExt(ref MsgPack MsgPack)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.FixExt1 ) Length = 1 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt2 ) Length = 2 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt4 ) Length = 4 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt8 ) Length = 8 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt16) Length = 16;
|
||||
else if (MsgPack.Type == MsgPack.Types. Ext8 ) Length = _IO.ReadByte();
|
||||
else if (MsgPack.Type == MsgPack.Types. Ext16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types. Ext32) Length = _IO.ReadInt32Endian(true);
|
||||
else return false;
|
||||
MsgPack.Object = new MsgPack.Ext { Type = _IO.ReadSByte(), Data = _IO.ReadBytes(Length) };
|
||||
return true;
|
||||
}
|
||||
|
||||
public IO Write(MsgPack MsgPack, bool Close)
|
||||
{ Write(MsgPack); if (Close) this.Close(); return this; }
|
||||
|
||||
public IO Write(MsgPack MsgPack)
|
||||
{
|
||||
if (MsgPack.Name != null) Write(MsgPack.Name);
|
||||
Write(MsgPack.Object);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void Write(object obj)
|
||||
{
|
||||
if (obj == null) { WriteNil(); return; }
|
||||
switch (obj)
|
||||
{
|
||||
case List<object> val: WriteMap(val.Count );
|
||||
foreach (object Val in val) Write(Val); break;
|
||||
case object[] val: WriteArr(val.Length);
|
||||
foreach (object Val in val) Write(Val); break;
|
||||
case 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.Write((byte)0xD0); _IO.Write(val); }
|
||||
private void Write( byte val) { if (val >= 0x80) _IO.Write((byte)0xCC); _IO.Write(val); }
|
||||
private void Write( short val) { if (( sbyte)val == val) Write(( sbyte)val);
|
||||
else if (( byte)val == val) Write(( byte)val);
|
||||
else { _IO.Write((byte)0xD1); _IO.WriteEndian(val, true); } }
|
||||
private void Write(ushort val) { if (( byte)val == val) Write(( byte)val);
|
||||
else { _IO.Write((byte)0xCD); _IO.WriteEndian(val, true); } }
|
||||
private void Write( int val) { if (( short)val == val) Write(( short)val);
|
||||
else if ((ushort)val == val) Write((ushort)val);
|
||||
else { _IO.Write((byte)0xD2); _IO.WriteEndian(val, true); } }
|
||||
private void Write( uint val) { if ((ushort)val == val) Write((ushort)val);
|
||||
else { _IO.Write((byte)0xCE); _IO.WriteEndian(val, true); } }
|
||||
private void Write( long val) { if (( int)val == val) Write(( int)val);
|
||||
else if (( uint)val == val) Write(( uint)val);
|
||||
else { _IO.Write((byte)0xD3); _IO.WriteEndian(val, true); } }
|
||||
private void Write( ulong val) { if (( uint)val == val) Write(( uint)val);
|
||||
else { _IO.Write((byte)0xCF); _IO.WriteEndian(val, true); } }
|
||||
private void Write( float val) { if (( long)val == val) Write(( long)val);
|
||||
else { _IO.Write((byte)0xCA); _IO.WriteEndian(val, true); } }
|
||||
private void Write(double val) { if (( long)val == val) Write(( long)val);
|
||||
else if (( float)val == val) Write(( float)val);
|
||||
else { _IO.Write((byte)0xCB); _IO.WriteEndian(val, true); } }
|
||||
|
||||
private void Write( bool val)
|
||||
{ _IO.Write((byte)(val ? 0xC3 : 0xC2)); }
|
||||
|
||||
private void Write(byte[] val)
|
||||
{
|
||||
if (val == null) { WriteNil(); return; }
|
||||
|
||||
if (val.Length < 0x100)
|
||||
{ _IO.Write((byte)0xC4); _IO.Write (( byte)val.Length ); }
|
||||
else if (val.Length < 0x10000)
|
||||
{ _IO.Write((byte)0xC5); _IO.WriteEndian((ushort)val.Length, true); }
|
||||
else
|
||||
{ _IO.Write((byte)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.Write((byte)(0xA0 | (array.Length & 0x1F)));
|
||||
else if (array.Length < 0x100)
|
||||
{ _IO.Write((byte) 0xD9); _IO.Write (( byte)array.Length); }
|
||||
else if (array.Length < 0x10000)
|
||||
{ _IO.Write((byte )0xDA); _IO.WriteEndian((ushort)array.Length, true); }
|
||||
else
|
||||
{ _IO.Write((byte) 0xDB); _IO.WriteEndian( array.Length, true); }
|
||||
_IO.Write(array);
|
||||
}
|
||||
|
||||
private void WriteNil() => _IO.Write((byte)0xC0);
|
||||
|
||||
private void WriteArr(int val)
|
||||
{
|
||||
if (val == 0) { WriteNil(); return; }
|
||||
else if (val < 0x10) _IO.Write((byte)(0x90 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.Write((byte) 0xDC); _IO.WriteEndian((ushort)val, true); }
|
||||
else { _IO.Write((byte) 0xDD); _IO.WriteEndian( val, true); }
|
||||
}
|
||||
|
||||
private void WriteMap(int val)
|
||||
{
|
||||
if (val == 0) { WriteNil(); return; }
|
||||
else if (val < 0x10) _IO.Write((byte)(0x80 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.Write((byte) 0xDE); _IO.WriteEndian((ushort)val, true); }
|
||||
else { _IO.Write((byte) 0xDF); _IO.WriteEndian( val, true); }
|
||||
}
|
||||
|
||||
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.Write((byte)0xD4);
|
||||
else if (val.Data.Length == 2 ) _IO.Write((byte)0xD5);
|
||||
else if (val.Data.Length == 4 ) _IO.Write((byte)0xD6);
|
||||
else if (val.Data.Length == 8 ) _IO.Write((byte)0xD7);
|
||||
else if (val.Data.Length == 16) _IO.Write((byte)0xD8);
|
||||
else
|
||||
{
|
||||
if (val.Data.Length < 0x100)
|
||||
{ _IO.Write((byte)0xC7); _IO.Write (( byte)val.Data.Length); }
|
||||
else if (val.Data.Length < 0x10000)
|
||||
{ _IO.Write((byte)0xC8); _IO.WriteEndian((ushort)val.Data.Length, true); }
|
||||
else
|
||||
{ _IO.Write((byte)0xC9); _IO.WriteEndian( val.Data.Length, true); }
|
||||
}
|
||||
_IO.Write(val.Type);
|
||||
_IO.Write(val.Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,250 +0,0 @@
|
||||
//Original or reader part: https://github.com/MarcosLopezC/LightJson/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib.MessagePack
|
||||
{
|
||||
public class JSONIO
|
||||
{
|
||||
public Stream _IO;
|
||||
|
||||
public JSONIO( ) => _IO = File.OpenWriter();
|
||||
public JSONIO(Stream IO) => _IO = IO;
|
||||
|
||||
public void Close() => _IO.Close();
|
||||
|
||||
public MsgPack Read() => ReadValue();
|
||||
|
||||
private string ReadKey() => ReadString();
|
||||
|
||||
private MsgPack ReadValue()
|
||||
{
|
||||
char c = _IO.SkipWhitespace().PeekCharUTF8();
|
||||
object obj = null;
|
||||
if (c == '{') obj = ReadObject();
|
||||
return new MsgPack(null, true, obj);
|
||||
}
|
||||
|
||||
private MsgPack ReadValue(string Key)
|
||||
{
|
||||
char c = _IO.SkipWhitespace().PeekCharUTF8();
|
||||
object obj = null;
|
||||
if (char.IsDigit(c))
|
||||
obj = ReadNumber ();
|
||||
else
|
||||
switch (c)
|
||||
{
|
||||
case '"': obj = ReadString (); break;
|
||||
case '{': obj = ReadObject (); break;
|
||||
case '[': obj = ReadArray (); break;
|
||||
case '-': obj = ReadNumber (); break;
|
||||
case 't':
|
||||
case 'f': obj = ReadBoolean(); break;
|
||||
case 'n': obj = ReadNull (); break;
|
||||
}
|
||||
return new MsgPack(Key, true, obj);
|
||||
}
|
||||
|
||||
private string ReadString()
|
||||
{
|
||||
if (!_IO.Assert('"')) return null;
|
||||
char c;
|
||||
string s = "";
|
||||
while (true)
|
||||
{
|
||||
c = _IO.ReadCharUTF8();
|
||||
|
||||
if (c == '\\')
|
||||
{
|
||||
c = _IO.ReadCharUTF8();
|
||||
|
||||
switch (char.ToLower(c))
|
||||
{
|
||||
case '"' :
|
||||
case '\\':
|
||||
case '/' : s += c; break;
|
||||
case 'b' : s += '\b'; break;
|
||||
case 'f' : s += '\f'; break;
|
||||
case 'n' : s += '\n'; break;
|
||||
case 'r' : s += '\r'; break;
|
||||
case 't' : s += '\t'; break;
|
||||
case 'u' : s += ReadUnicodeLiteral(); break;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
else if (c == '"') break;
|
||||
else if (char.IsControl(c)) return null;
|
||||
else s += c;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private char ReadUnicodeLiteral() =>
|
||||
(char)((((((ReadHexDigit() << 4) | ReadHexDigit()) << 4) | ReadHexDigit()) << 4) | ReadHexDigit());
|
||||
|
||||
private int ReadHexDigit() => byte.Parse(_IO.ReadCharUTF8().ToString(),
|
||||
System.Globalization.NumberStyles.HexNumber);
|
||||
|
||||
private List<object> ReadObject()
|
||||
{
|
||||
List<object> Obj = new List<object>();
|
||||
if (!_IO.Assert('{')) return null;
|
||||
if (_IO.SkipWhitespace().PeekCharUTF8() == '}') { _IO.ReadCharUTF8(); return null; }
|
||||
|
||||
string key;
|
||||
while (true)
|
||||
{
|
||||
_IO.SkipWhitespace();
|
||||
|
||||
key = ReadString();
|
||||
if (!_IO.SkipWhitespace().Assert(':')) return null;
|
||||
Obj.Add(ReadValue(key));
|
||||
|
||||
_IO.SkipWhitespace();
|
||||
|
||||
var next = _IO.ReadCharUTF8();
|
||||
|
||||
if (next == '}') break;
|
||||
else if (next == ',') continue;
|
||||
else return null;
|
||||
}
|
||||
|
||||
return Obj;
|
||||
}
|
||||
|
||||
private object[] ReadArray()
|
||||
{
|
||||
List<object> Obj = new List<object>();
|
||||
if (!_IO.Assert('[')) return null;
|
||||
if (_IO.SkipWhitespace().PeekCharUTF8() == ']') { _IO.ReadCharUTF8(); return null; }
|
||||
|
||||
char c;
|
||||
while (true)
|
||||
{
|
||||
Obj.Add(ReadValue(null));
|
||||
c = _IO.SkipWhitespace().ReadCharUTF8();
|
||||
|
||||
if (c == ']') break;
|
||||
else if (c == ',') continue;
|
||||
else return null;
|
||||
}
|
||||
return Obj.ToArray();
|
||||
}
|
||||
|
||||
private object ReadNumber()
|
||||
{
|
||||
string s = " ";
|
||||
_IO.SkipWhitespace();
|
||||
if (_IO.PeekCharUTF8() == '-') s += _IO.ReadCharUTF8();
|
||||
if (_IO.PeekCharUTF8() == '0') s += _IO.ReadCharUTF8();
|
||||
else s += ReadDigits ();
|
||||
if (_IO.PeekCharUTF8() == '.') s += _IO.ReadCharUTF8() + ReadDigits();
|
||||
else return long.Parse(s);
|
||||
|
||||
char c = _IO.PeekCharUTF8();
|
||||
if (c == 'e' || c == 'E')
|
||||
{
|
||||
s += _IO.ReadCharUTF8();
|
||||
c = _IO.PeekCharUTF8();
|
||||
if (c == '+' || c == '-') s += _IO.ReadCharUTF8();
|
||||
s += ReadDigits();
|
||||
}
|
||||
return s.ToDouble();
|
||||
}
|
||||
|
||||
private bool ReadBoolean()
|
||||
{
|
||||
char c = _IO.PeekCharUTF8();
|
||||
if (c == 't' && _IO.Assert( "true")) return true;
|
||||
else if (c == 'f' && _IO.Assert("false")) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
private object ReadNull() { _IO.Assert("null"); return null; }
|
||||
|
||||
private string ReadDigits()
|
||||
{ string s = ""; while (char.IsDigit(_IO.SkipWhitespace().
|
||||
PeekCharUTF8())) s += _IO.ReadCharUTF8(); return s; }
|
||||
|
||||
public JSONIO Write(MsgPack MsgPack, bool Close, string End = "\n", string TabChar = " ")
|
||||
{ Write(MsgPack, End, TabChar, "", true); if (Close) this.Close(); return this; }
|
||||
|
||||
public JSONIO Write(MsgPack MsgPack, bool Close, bool Style = false)
|
||||
{ Write(MsgPack, "\n", " ", "", Style); if (Close) this.Close(); return this; }
|
||||
|
||||
private JSONIO Write(MsgPack MsgPack, string End, string TabChar, string Tab, bool Style)
|
||||
{
|
||||
string OldTab = Tab;
|
||||
Tab += TabChar;
|
||||
if (MsgPack.Name != null) _IO.Write("\"" + MsgPack.Name + "\":" + (Style ? " " : ""));
|
||||
if (MsgPack.Object == null) { WriteNil(); return this; }
|
||||
|
||||
if (MsgPack.List != null)
|
||||
{
|
||||
WriteMap();
|
||||
if (Style) _IO.Write(End);
|
||||
for (int i = 0; i < MsgPack.List.Count; i++)
|
||||
{
|
||||
if (Style) _IO.Write(Tab);
|
||||
Write(MsgPack.List[i], End, TabChar, Tab, Style);
|
||||
if (i + 1 < MsgPack.List. Count) _IO.Write(',');
|
||||
if (Style) _IO.Write(End);
|
||||
}
|
||||
if (Style) _IO.Write(OldTab);
|
||||
WriteMap(true);
|
||||
}
|
||||
else if (MsgPack.Array != null)
|
||||
{
|
||||
WriteArr();
|
||||
if (Style) _IO.Write(End);
|
||||
for (int i = 0; i < MsgPack.Array.Length; i++)
|
||||
{
|
||||
if (Style) _IO.Write(Tab);
|
||||
Write(MsgPack.Array[i], End, TabChar, Tab, Style);
|
||||
if (i + 1 < MsgPack.Array.Length) _IO.Write(',');
|
||||
if (Style) _IO.Write(End);
|
||||
}
|
||||
if (Style) _IO.Write(OldTab);
|
||||
WriteArr(true);
|
||||
}
|
||||
else if (MsgPack.Object is MsgPack msg)
|
||||
Write(msg, End, TabChar, Tab, Style);
|
||||
else Write(MsgPack.Object, End, TabChar, Tab, Style);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private void Write(object obj, string End, string TabChar, string Tab, bool Style)
|
||||
{
|
||||
if (obj == null) { WriteNil(); return; }
|
||||
switch (obj)
|
||||
{
|
||||
case MsgPack val: Write(val, End, TabChar, Tab, Style); break;
|
||||
case bool val: Write(val); break;
|
||||
case string val: Write(val); break;
|
||||
case sbyte val: _IO.Write(Main.ToString(val)); break;
|
||||
case byte val: _IO.Write(Main.ToString(val)); break;
|
||||
case short val: _IO.Write(Main.ToString(val)); break;
|
||||
case ushort val: _IO.Write(Main.ToString(val)); break;
|
||||
case int val: _IO.Write(Main.ToString(val)); break;
|
||||
case uint val: _IO.Write(Main.ToString(val)); break;
|
||||
case long val: _IO.Write(Main.ToString(val)); break;
|
||||
case ulong val: _IO.Write(Main.ToString(val)); break;
|
||||
case float val: _IO.Write(Main.ToString(val)); break;
|
||||
case double val: _IO.Write(Main.ToString(val)); break;
|
||||
}
|
||||
}
|
||||
private void Write( bool val) => _IO.Write(val ? "true" : "false");
|
||||
private void Write(string val) => _IO.Write("\"" + val
|
||||
.Replace("\\", "\\\\").Replace("/" , "\\/").Replace("\'", "\\\'").Replace("\"", "\\\"")
|
||||
.Replace("\0", "\\0" ).Replace("\a", "\\a").Replace("\b", "\\b" ).Replace("\f", "\\f" )
|
||||
.Replace("\n", "\\n" ).Replace("\r", "\\r").Replace("\t", "\\t" ) + "\"");
|
||||
|
||||
private void WriteNil() => _IO.Write("null");
|
||||
private void WriteArr(bool End = false) => _IO.Write(End ? "]" : "[");
|
||||
private void WriteMap(bool End = false) => _IO.Write(End ? "}" : "{");
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
using KKdMainLib.IO;
|
||||
using MPIO = KKdMainLib.MessagePack.IO;
|
||||
|
||||
namespace KKdMainLib.MessagePack
|
||||
{
|
||||
public static class MPExt
|
||||
{
|
||||
public static MsgPack ReadMP(this string file, bool JSON = false)
|
||||
{
|
||||
MsgPack MsgPack;
|
||||
if (JSON)
|
||||
{ JSONIO IO = new JSONIO(File.OpenReader(file + ".json"));
|
||||
MsgPack = IO.Read(); IO.Close(); IO = null; }
|
||||
else
|
||||
{ MPIO IO = new MPIO(File.OpenReader(file + ".mp" ));
|
||||
MsgPack = IO.Read(); IO.Close(); IO = null; }
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
public static void WriteAfterAll(this MsgPack mp, bool Temp, string file, bool JSON = false)
|
||||
{ if (Temp) new MsgPack().Add(mp).WriteAfterAll(file, JSON).Dispose();
|
||||
else mp .WriteAfterAll(file, JSON); }
|
||||
|
||||
public static MsgPack WriteAfterAll(this MsgPack mp, string file, bool JSON = false)
|
||||
{
|
||||
byte[] data = null;
|
||||
if (JSON)
|
||||
{ JSONIO IO = new JSONIO(File.OpenWriter());
|
||||
IO.Write(mp, false, true); data = IO._IO.ToArray(true); }
|
||||
else
|
||||
{ MPIO IO = new MPIO(File.OpenWriter());
|
||||
IO.Write(mp, false ); data = IO._IO.ToArray(true); }
|
||||
File.WriteAllBytes(file + (JSON ? ".json" : ".mp"), data);
|
||||
return mp;
|
||||
}
|
||||
|
||||
|
||||
public static void Write(this MsgPack mp, bool Temp, string file, bool JSON = false)
|
||||
{ if (Temp) new MsgPack().Add(mp).Write(file, JSON).Dispose();
|
||||
else mp .Write(file, JSON); }
|
||||
|
||||
public static MsgPack Write(this MsgPack mp, string file, bool JSON = false)
|
||||
{
|
||||
if (JSON)
|
||||
{ JSONIO IO = new JSONIO(File.OpenWriter(file + ".json", true));
|
||||
IO.Write(mp, true, true); IO = null; }
|
||||
else
|
||||
{ MPIO IO = new MPIO(File.OpenWriter(file + ".mp" , true));
|
||||
IO.Write(mp, true ); IO = null; }
|
||||
return mp;
|
||||
}
|
||||
|
||||
public static void ToJSON (this string file) =>
|
||||
file.ReadMP( ).Write(file, true).Dispose();
|
||||
|
||||
public static void ToMsgPack(this string file) =>
|
||||
file.ReadMP(true).Write(file ).Dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,317 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace KKdMainLib.MessagePack
|
||||
{
|
||||
public class MsgPack : IDisposable
|
||||
{
|
||||
public Types Type;
|
||||
public string Name;
|
||||
public object Object;
|
||||
|
||||
public object[] Array => Object is object[] List ? List : null;
|
||||
public List<object> List => Object is List<object> Array ? Array : null;
|
||||
|
||||
public MsgPack( Types Type = Types.Map32) => NewMsgPack(null, Type);
|
||||
public MsgPack(string Name, Types Type = Types.Map32) => NewMsgPack(Name, Type);
|
||||
public MsgPack( long Count) => NewMsgPack(null, Count);
|
||||
public MsgPack(string Name, long Count) => NewMsgPack(Name, Count);
|
||||
public MsgPack(string Name, Types Type, object Object)
|
||||
{ this.Name = Name; this.Type = Type; this.Object = Object; }
|
||||
public MsgPack(string Name, bool TypeIsntKnown, object Object)
|
||||
{
|
||||
switch (Object)
|
||||
{
|
||||
case List<object> val: Type = Types. Map32; break;
|
||||
case object[] val: Type = Types. Arr32; break;
|
||||
case MsgPack val: Type = Types. Map32; break;
|
||||
case byte[] val: Type = Types. Bin32; break;
|
||||
case bool val: Type = val ? Types.True : Types.False; break;
|
||||
case sbyte val: Type = Types. Int8 ; break;
|
||||
case byte val: Type = Types. UInt8 ; break;
|
||||
case short val: Type = Types. Int16; break;
|
||||
case ushort val: Type = Types. UInt16; break;
|
||||
case int val: Type = Types. Int32; break;
|
||||
case uint val: Type = Types. UInt32; break;
|
||||
case long val: Type = Types. Int64; break;
|
||||
case ulong val: Type = Types. UInt64; break;
|
||||
case float val: Type = Types.Float32; break;
|
||||
case double val: Type = Types.Float64; break;
|
||||
case string val: Type = Types. Str32; break;
|
||||
case Ext val: Type = Types. Ext32; break;
|
||||
case null: Type = Types. Nil; break;
|
||||
}
|
||||
this.Name = Name; this.Object = Object;
|
||||
}
|
||||
|
||||
public static MsgPack Null => null;
|
||||
|
||||
public object this[int index]
|
||||
{ get { if (Array != null) return Array[index]; return null; }
|
||||
set { if (Array != null) Array[index] = value; } }
|
||||
|
||||
public MsgPack Add(object obj)
|
||||
{ if (obj != null && List != null) List.Add(obj); return this; }
|
||||
|
||||
public MsgPack(List<object> Object, string Name, Types Type)
|
||||
{ this.Object = Object; this.Name = Name; this.Type = Type; }
|
||||
|
||||
private void NewMsgPack(string Name, Types Type)
|
||||
{ Object = new List<object>(); this.Name = Name; this.Type = Type; }
|
||||
|
||||
private void NewMsgPack(string Name, long Count)
|
||||
{ if (Count > 0) { Object = new object[Count]; }
|
||||
else Object = null; this.Name = Name; Type = Types.Arr32; }
|
||||
|
||||
public void Dispose()
|
||||
{ Type = 0; Name = null; Object = null; }
|
||||
|
||||
public MsgPack Add( sbyte? val) => Add(null, val);
|
||||
public MsgPack Add( byte? val) => Add(null, val);
|
||||
public MsgPack Add( short? val) => Add(null, val);
|
||||
public MsgPack Add(ushort? val) => Add(null, val);
|
||||
public MsgPack Add( int? val) => Add(null, val);
|
||||
public MsgPack Add( uint? val) => Add(null, val);
|
||||
public MsgPack Add( long? val) => Add(null, val);
|
||||
public MsgPack Add( ulong? val) => Add(null, val);
|
||||
public MsgPack Add( float? val) => Add(null, val);
|
||||
public MsgPack Add(double? val) => Add(null, val);
|
||||
|
||||
public MsgPack Add(byte[] val) => Add(null, val);
|
||||
public MsgPack Add(string val) => Add(null, val);
|
||||
public MsgPack Add( bool val) => Add(null, val);
|
||||
public MsgPack Add( sbyte val) => Add(null, val);
|
||||
public MsgPack Add( byte val) => Add(null, val);
|
||||
public MsgPack Add( short val) => Add(null, val);
|
||||
public MsgPack Add(ushort val) => Add(null, val);
|
||||
public MsgPack Add( int val) => Add(null, val);
|
||||
public MsgPack Add( uint val) => Add(null, val);
|
||||
public MsgPack Add( long val) => Add(null, val);
|
||||
public MsgPack Add( ulong val) => Add(null, val);
|
||||
public MsgPack Add( float val) => Add(null, val);
|
||||
public MsgPack Add(double val) => Add(null, val);
|
||||
|
||||
public MsgPack Add(string Val, sbyte? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( sbyte)val); return this; }
|
||||
public MsgPack Add(string Val, byte? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( byte)val); return this; }
|
||||
public MsgPack Add(string Val, short? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( short)val); return this; }
|
||||
public MsgPack Add(string Val, ushort? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, (ushort)val); return this; }
|
||||
public MsgPack Add(string Val, int? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( int)val); return this; }
|
||||
public MsgPack Add(string Val, uint? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( uint)val); return this; }
|
||||
public MsgPack Add(string Val, long? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( long)val); return this; }
|
||||
public MsgPack Add(string Val, ulong? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( ulong)val); return this; }
|
||||
public MsgPack Add(string Val, float? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( float)val); return this; }
|
||||
public MsgPack Add(string Val, double? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, (double)val); return this; }
|
||||
|
||||
public MsgPack Add(string Val, byte[] val)
|
||||
{ if (val == null) Add(Null); else
|
||||
Add(new MsgPack(Val, Types. Bin32, val)); return this; }
|
||||
public MsgPack Add(string Val, string val)
|
||||
{ if (val == null) Add(Null); else
|
||||
Add(new MsgPack(Val, Types. Str32, val)); return this; }
|
||||
public MsgPack Add(string Val, bool val)
|
||||
{ Add(new MsgPack(Val, val ?
|
||||
Types.True : Types. False, val)); return this; }
|
||||
public MsgPack Add(string Val, sbyte val)
|
||||
{ Add(new MsgPack(Val, Types. Int8, val)); return this; }
|
||||
public MsgPack Add(string Val, byte val)
|
||||
{ Add(new MsgPack(Val, Types. UInt8, val)); return this; }
|
||||
public MsgPack Add(string Val, short val)
|
||||
{ Add(new MsgPack(Val, Types. Int16, val)); return this; }
|
||||
public MsgPack Add(string Val, ushort val)
|
||||
{ Add(new MsgPack(Val, Types. UInt16, val)); return this; }
|
||||
public MsgPack Add(string Val, int val)
|
||||
{ Add(new MsgPack(Val, Types. Int32, val)); return this; }
|
||||
public MsgPack Add(string Val, uint val)
|
||||
{ Add(new MsgPack(Val, Types. UInt32, val)); return this; }
|
||||
public MsgPack Add(string Val, long val)
|
||||
{ Add(new MsgPack(Val, Types. Int64, val)); return this; }
|
||||
public MsgPack Add(string Val, ulong val)
|
||||
{ Add(new MsgPack(Val, Types. UInt64, val)); return this; }
|
||||
public MsgPack Add(string Val, float val)
|
||||
{ Add(new MsgPack(Val, Types.Float32, val)); return this; }
|
||||
public MsgPack Add(string Val, double val)
|
||||
{ Add(new MsgPack(Val, Types.Float64, val)); return this; }
|
||||
|
||||
public 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)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack.ReadNBoolean(); return null; }
|
||||
public sbyte? ReadNInt8(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt8(); return null; }
|
||||
public byte? ReadNUInt8(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt8(); return null; }
|
||||
public short? ReadNInt16(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt16(); return null; }
|
||||
public ushort? ReadNUInt16(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt16(); return null; }
|
||||
public int? ReadNInt32(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt32(); return null; }
|
||||
public uint? ReadNUInt32(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt32(); return null; }
|
||||
public long? ReadNInt64(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt64(); return null; }
|
||||
public ulong? ReadNUInt64(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt64(); return null; }
|
||||
public float? ReadNSingle(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNSingle(); return null; }
|
||||
public double? ReadNDouble(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNDouble(); return null; }
|
||||
public string ReadString(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadString(); return null; }
|
||||
|
||||
public bool 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 long Int64) return ( sbyte) Int64;
|
||||
else if (Object is ulong UInt64) return ( sbyte) UInt64; return null; }
|
||||
public byte? ReadNUInt8()
|
||||
{ if (Object is long Int64) return ( byte) Int64;
|
||||
else if (Object is ulong UInt64) return ( byte) UInt64; return null; }
|
||||
public short? ReadNInt16()
|
||||
{ if (Object is long Int64) return ( short) Int64;
|
||||
else if (Object is ulong UInt64) return ( short) UInt64; return null; }
|
||||
public ushort? ReadNUInt16()
|
||||
{ if (Object is long Int64) return (ushort) Int64;
|
||||
else if (Object is ulong UInt64) return (ushort) UInt64; return null; }
|
||||
public int? ReadNInt32()
|
||||
{ if (Object is long Int64) return ( int) Int64;
|
||||
else if (Object is ulong UInt64) return ( int) UInt64; return null; }
|
||||
public uint? ReadNUInt32()
|
||||
{ if (Object is long Int64) return ( uint) Int64;
|
||||
else if (Object is ulong UInt64) return ( uint) UInt64; return null; }
|
||||
public long? ReadNInt64()
|
||||
{ if (Object is long Int64) return ( long) Int64;
|
||||
else if (Object is ulong UInt64) return ( long) UInt64; return null; }
|
||||
public ulong? ReadNUInt64()
|
||||
{ if (Object is long Int64) return ( ulong) Int64;
|
||||
else if (Object is ulong UInt64) return ( ulong) UInt64; return null; }
|
||||
public float? ReadNSingle()
|
||||
{ if (Object is long Int64) return ( float) Int64;
|
||||
else if (Object is ulong UInt64) return ( float) UInt64;
|
||||
else if (Object is float Float32) return ( float)Float32;
|
||||
else if (Object is double Float64) return ( float)Float64; return null; }
|
||||
public double? ReadNDouble()
|
||||
{ if (Object is long Int64) return (double) Int64;
|
||||
else if (Object is ulong UInt64) return (double) UInt64;
|
||||
else if (Object is float Float32) return (double)Float32;
|
||||
else if (Object is double Float64) return (double)Float64; return null; }
|
||||
public string ReadString()
|
||||
{ if (Object is string String) return String; return null; }
|
||||
|
||||
public bool Element<T>(string Name, out MsgPack MsgPack)
|
||||
{
|
||||
if (Element(Name, out MsgPack))
|
||||
{
|
||||
if (MsgPack.Array == null) return false;
|
||||
|
||||
for (int i = 0; i < MsgPack.Array.Length; i++)
|
||||
if (!(MsgPack[i] is T)) return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Element(string Name, out MsgPack MsgPack)
|
||||
{
|
||||
MsgPack = null;
|
||||
if (List != null)
|
||||
foreach (object obj in List)
|
||||
if (obj is MsgPack msg) if (msg.Name == Name) { MsgPack = msg; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool ContainsKey(string Name)
|
||||
{
|
||||
if (List == null) return false;
|
||||
|
||||
foreach (object obj in List)
|
||||
if (obj is MsgPack msg) if (msg.Name == Name) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public enum Types : byte
|
||||
{
|
||||
PosInt = 0b00000000,
|
||||
FixMap = 0b10000000,
|
||||
FixArr = 0b10010000,
|
||||
FixStr = 0b10100000,
|
||||
Nil = 0b11000000,
|
||||
NeverUsed = 0b11000001,
|
||||
False = 0b11000010,
|
||||
True = 0b11000011,
|
||||
Bin8 = 0b11000100,
|
||||
Bin16 = 0b11000101,
|
||||
Bin32 = 0b11000110,
|
||||
Ext8 = 0b11000111,
|
||||
Ext16 = 0b11001000,
|
||||
Ext32 = 0b11001001,
|
||||
Float32 = 0b11001010,
|
||||
Float64 = 0b11001011,
|
||||
UInt8 = 0b11001100,
|
||||
UInt16 = 0b11001101,
|
||||
UInt32 = 0b11001110,
|
||||
UInt64 = 0b11001111,
|
||||
Int8 = 0b11010000,
|
||||
Int16 = 0b11010001,
|
||||
Int32 = 0b11010010,
|
||||
Int64 = 0b11010011,
|
||||
FixExt1 = 0b11010100,
|
||||
FixExt2 = 0b11010101,
|
||||
FixExt4 = 0b11010110,
|
||||
FixExt8 = 0b11010111,
|
||||
FixExt16 = 0b11011000,
|
||||
Str8 = 0b11011001,
|
||||
Str16 = 0b11011010,
|
||||
Str32 = 0b11011011,
|
||||
Arr16 = 0b11011100,
|
||||
Arr32 = 0b11011101,
|
||||
Map16 = 0b11011110,
|
||||
Map32 = 0b11011111,
|
||||
NegInt = 0b11100000,
|
||||
PosIntMax = 0b01111111,
|
||||
FixMapMax = 0b10001111,
|
||||
FixArrMax = 0b10011111,
|
||||
FixStrMax = 0b10111111,
|
||||
NegIntMax = 0b11111111,
|
||||
}
|
||||
|
||||
public struct Ext
|
||||
{
|
||||
public byte[] Data;
|
||||
public sbyte Type;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,350 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public struct Mot
|
||||
{
|
||||
private int i, i0, i1;
|
||||
private 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;
|
||||
|
||||
int MOTCount = i;
|
||||
MsgPack m = new MsgPack(MOTCount, "Mot");
|
||||
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");
|
||||
|
||||
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);
|
||||
|
||||
IO.A(0x4);
|
||||
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(Key.Keys[i1].F);
|
||||
IO.A(0x4);
|
||||
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(Key.Keys[i1].F);
|
||||
IO.A(0x4);
|
||||
for (i1 = 0; i1 < Key.Keys.Length; i1++)
|
||||
{ IO.W(Key.Keys[i1].V); IO.W(Key.Keys[i1].T); }
|
||||
}
|
||||
}
|
||||
IO.A(0x4);
|
||||
|
||||
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);
|
||||
}
|
||||
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 MOTS;
|
||||
if ((MOTS = MsgPack["MOT"]).NotNull)
|
||||
{
|
||||
MOT = new MotHeader[MOTS.Array.Length];
|
||||
for (int i = 0; i < MOT.Length; i++)
|
||||
MsgPackReader(MOTS.Array[i], ref MOT[i]);
|
||||
}
|
||||
MOTS.Dispose();
|
||||
MsgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
{
|
||||
int MOTCount = MOT.Length;
|
||||
MsgPack MOTS = new MsgPack(MOTCount, "MOT");
|
||||
for (i = 0; i < MOTCount; i++)
|
||||
MOTS[i] = MsgPackWriter(ref MOT[i]);
|
||||
MOTS.Write(true, file, JSON);
|
||||
}
|
||||
|
||||
public void MsgPackReader(MsgPack MOT, ref MotHeader Mot)
|
||||
{
|
||||
MsgPack Temp = MsgPack.New;
|
||||
Mot.HighBits = MOT.RI32("HighBits" );
|
||||
Mot.FrameCount = MOT.RI32("FrameCount");
|
||||
|
||||
if ((Temp = MOT["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 keySet = Temp.Array[i0].Array[1];
|
||||
|
||||
if (keySet.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 (keySet.Array == null) continue;
|
||||
else if (keySet.Array.Length == 0) continue;
|
||||
else if (keySet.Array[0].Array == null) continue;
|
||||
else if (keySet.Array[0].Array.Length == 0) continue;
|
||||
else if (keySet.Array[0].Array.Length == 1)
|
||||
KeySet.Keys[0] = new KFT2 (keySet.Array[0][0].RF32());
|
||||
else if (keySet.Array[0].Array.Length > 1)
|
||||
KeySet.Keys[0] = new KFT2 (keySet.Array[0][0].RF32(), keySet.Array[1].RF32());
|
||||
}
|
||||
else if (KeySet.Type == KeySetType.Linear)
|
||||
{
|
||||
KeySet.Keys = new KFT2[keySet.Array.Length];
|
||||
for (i1 = 0; i1 < keySet.Array.Length; i1++)
|
||||
{
|
||||
ref MsgPack Array = ref keySet.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[keySet.Array.Length];
|
||||
for (i1 = 0; i1 < keySet.Array.Length; i1++)
|
||||
{
|
||||
ref MsgPack Array = ref keySet.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(), keySet.Array[i1][2].RF32());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((Temp = MOT["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[i1].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 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].Check()}" : 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,63 +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 RealSignature;
|
||||
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.Seek(-4, SeekOrigin.Current);
|
||||
else stream.Seek( 0, 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();
|
||||
stream.IsBE = Header.Format == Main.Format.F2BE;
|
||||
stream.Format = Header.Format;
|
||||
stream.LongPosition = Position + Header.Lenght;
|
||||
Header.Signature = stream.ReadInt32Endian();
|
||||
return Header;
|
||||
}
|
||||
|
||||
public static void Write(this Stream stream, PDHead Header)
|
||||
{
|
||||
stream.Write(Header.Signature);
|
||||
stream.Write(Header.DataSize);
|
||||
stream.Write(Header.Lenght);
|
||||
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);
|
||||
}
|
||||
|
||||
public static void WriteEOFC(this Stream stream, int ID)
|
||||
{ PDHead Header = new PDHead { Format = Main.Format.F2LE, ID = ID,
|
||||
Lenght = 0x20, Signature = 0x43464F45, }; stream.Write(Header); }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
using System;
|
||||
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])
|
||||
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);
|
||||
|
||||
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 long ReadIntX(this Stream IO, ref POF POF ) =>
|
||||
IO.IsX ? IO.ReadInt64() : IO.ReadUInt32Endian( );
|
||||
public static long ReadIntX(this Stream IO, ref POF POF, bool IsBE) =>
|
||||
IO.IsX ? IO.ReadInt64() : IO.ReadUInt32Endian(IsBE);
|
||||
|
||||
public static string ReadStringAtOffset(this Stream IO, ref POF POF, long Offset = 0, long Length = 0) =>
|
||||
IO.GetOffset(ref POF).ReadStringAtOffset(Offset, Length);
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,14 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("KKdMainLib")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[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("Copyright korenkonder © 2018-2019")]
|
||||
[assembly: AssemblyCopyright("korenkonder © 2018-2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("2BA7EFC6-91D1-8BBC-C487-06C7F36CC789")]
|
||||
[assembly: AssemblyVersion("0.4.5.10")]
|
||||
[assembly: AssemblyFileVersion("0.4.5.10")]
|
||||
[assembly: AssemblyVersion("0.4.7.6")]
|
||||
[assembly: AssemblyFileVersion("0.4.7.6")]
|
||||
|
||||
+126
-117
@@ -1,209 +1,218 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
using MPIO = KKdMainLib.MessagePack.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public class STR
|
||||
{
|
||||
public struct String
|
||||
{
|
||||
public int ID;
|
||||
public int StrOffset;
|
||||
public string Str;
|
||||
}
|
||||
|
||||
public STR()
|
||||
{ Offset = 0; OffsetX = 0; STRs = null; POF = null; Header = new PDHead(); }
|
||||
{ Offset = 0; OffsetX = 0; STRs = null; Header = new Header(); }
|
||||
|
||||
private long Offset;
|
||||
private long OffsetX;
|
||||
public String[] STRs;
|
||||
private POF POF;
|
||||
private PDHead Header;
|
||||
private Header Header;
|
||||
private Stream IO;
|
||||
|
||||
public String[] STRs;
|
||||
|
||||
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();
|
||||
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;
|
||||
Header = IO.ReadHeader(true, false);
|
||||
POF.Offsets = KKdList<long>.New;
|
||||
|
||||
long Count = reader.ReadInt32Endian();
|
||||
Offset = reader.ReadInt32Endian();
|
||||
long Count = IO.RI32E();
|
||||
Offset = IO.RI32E();
|
||||
|
||||
if (Offset == 0)
|
||||
{
|
||||
Offset = Count;
|
||||
OffsetX = reader.ReadInt64();
|
||||
Count = reader.ReadInt64();
|
||||
reader.Offset = Header.Lenght;
|
||||
reader.Format = Main.Format.X;
|
||||
OffsetX = IO.RI64();
|
||||
Count = IO.RI64();
|
||||
IO.O = Header.Length;
|
||||
IO.Format = Format.X;
|
||||
IO.I64O += Offset;
|
||||
IO.P = 0;
|
||||
}
|
||||
reader.LongPosition = reader.IsX ? Offset + reader.Offset : Offset;
|
||||
else IO.P = Header.Length + 0x40;
|
||||
|
||||
STRs = 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;
|
||||
STRs[i].Str.O = IO.RI32E();
|
||||
STRs[i].ID = IO.RI32E();
|
||||
}
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
if (IO.IsX)
|
||||
{
|
||||
reader.LongPosition = STRs[i].StrOffset + (reader.IsX ? reader.Offset : 0);
|
||||
STRs[i].Str = reader.NullTerminatedUTF8();
|
||||
IO.I64O = Header.Length + OffsetX;
|
||||
for (int i = 0; i < Count; i++)
|
||||
STRs[i].Str.V = IO.RSaO(STRs[i].Str.O);
|
||||
}
|
||||
else
|
||||
{
|
||||
IO.O = 0;
|
||||
for (int i = 0; i < Count; i++)
|
||||
STRs[i].Str.V = STRs[i].Str.O > 0 ?
|
||||
IO.RSaO(STRs[i].Str.O) : null;
|
||||
}
|
||||
|
||||
reader.Position = POF.Offset;
|
||||
reader.ReadPOF(ref POF);
|
||||
}
|
||||
else
|
||||
{
|
||||
reader.Position -= 4;
|
||||
IO.P -= 4;
|
||||
int Count = 0;
|
||||
for (int a = 0, i = 0; reader.Position > 0 && reader.Position < reader.Length; i++, Count++)
|
||||
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];
|
||||
|
||||
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.I64P = STRs[i].Str.O;
|
||||
STRs[i].ID = i;
|
||||
STRs[i].Str.V = IO.NTUTF8();
|
||||
}
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
IO.C();
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void STRWriter(string filepath)
|
||||
{
|
||||
if (STRs == null || STRs.Length == 0 || Header.Format > Format.F2BE) return;
|
||||
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;
|
||||
IO = File.OpenWriter(filepath + (Header.Format > Format.FT ? ".str" : ".bin"), true);
|
||||
IO.Format = Header.Format;
|
||||
POF.Offsets = KKdList<long>.New;
|
||||
IO.IsBE = IO.Format == Format.F2BE;
|
||||
|
||||
long Count = STRs.LongLength;
|
||||
if (writer.Format > Main.Format.FT)
|
||||
if (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(16);
|
||||
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(32);
|
||||
for (int i = 0; i < Count; i++) IO.W(0x00);
|
||||
IO.A(0x20);
|
||||
}
|
||||
|
||||
List<string> UsedSTR = new List<string>();
|
||||
List<int> UsedSTRPos = new List<int>();
|
||||
KKdList<string> UsedSTR = KKdList<string>.New;
|
||||
KKdList<int> UsedSTRPos = KKdList<int>.New;
|
||||
int[] STRPos = new int[Count];
|
||||
for (int i1 = 0; i1 < Count; i1++)
|
||||
|
||||
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(STRs[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(STRs[i].Str.V);
|
||||
IO.W(STRs[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);
|
||||
}
|
||||
}
|
||||
if (writer.Format > Main.Format.FT)
|
||||
{
|
||||
writer.Align(16);
|
||||
Offset = writer.UIntPosition;
|
||||
writer.Position = 0x80;
|
||||
}
|
||||
else
|
||||
writer.Position = 0;
|
||||
for (int i1 = 0; i1 < Count; i1++)
|
||||
{
|
||||
writer.WriteEndian(STRPos[i1]);
|
||||
if (writer.Format > Main.Format.FT) writer.Position += 4;
|
||||
for (int i2 = 0; i2 < Count; i2++)
|
||||
if (UsedSTR[i2] == STRs[i].Str.V) { STRPos[i] = UsedSTRPos[i2]; break; }
|
||||
}
|
||||
|
||||
if (writer.Format > Main.Format.FT)
|
||||
if (IO.Format > 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);
|
||||
IO.A(0x10);
|
||||
Offset = IO.U32P;
|
||||
IO.P = 0x80;
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
POF.Offsets.Add(IO.P);
|
||||
IO.WE(STRPos[i]);
|
||||
IO.WE(STRs[i].ID);
|
||||
}
|
||||
|
||||
IO.U32P = Offset;
|
||||
POF.Depth = 1;
|
||||
IO.W(POF);
|
||||
CurrentOffset = IO.U32P;
|
||||
IO.WEOFC();
|
||||
Header.DataSize = (int)(CurrentOffset - 0x40);
|
||||
Header.Signature = 0x41525453;
|
||||
Header.SectionSize = (int)(Offset - Header.Lenght);
|
||||
writer.Position = 0;
|
||||
writer.Write(Header);
|
||||
Header.SectionSize = (int)(Offset - 0x40);
|
||||
IO.P = 0;
|
||||
IO.W(Header, true);
|
||||
}
|
||||
writer.Close();
|
||||
else
|
||||
{
|
||||
IO.P = 0;
|
||||
for (int i = 0; i < Count; i++) IO.W(STRPos[i]);
|
||||
}
|
||||
IO.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMP(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.Element<MsgPack>("Strings", out MsgPack Strings)) return;
|
||||
if ((Temp = MsgPack["Strings", true]).IsNull) return;
|
||||
|
||||
STRs = new String[Strings.Array.Length];
|
||||
STRs = new String[Temp.Array.Length];
|
||||
for (int i = 0; i < STRs.Length; i++)
|
||||
if (Strings[i] is MsgPack String)
|
||||
{
|
||||
String = (MsgPack)Strings[i];
|
||||
STRs[i].ID = String.ReadInt32("ID");
|
||||
STRs[i].Str = String.ReadString("Str");
|
||||
}
|
||||
{
|
||||
STRs[i].ID = Temp[i].RI32 ("ID" );
|
||||
STRs[i].Str.V = Temp[i].RS("Str");
|
||||
if (STRs[i].Str.V == null) STRs[i].Str.V = "";
|
||||
}
|
||||
|
||||
MsgPack = null;
|
||||
MsgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
{
|
||||
if (STRs == null || STRs.Length == 0) return;
|
||||
MsgPack STR_ = new MsgPack("STR").Add("Format", Header.Format.ToString());
|
||||
MsgPack Strings = new MsgPack("Strings", STRs.Length);
|
||||
MsgPack Strings = new MsgPack(STRs.Length, "Strings");
|
||||
for (int i = 0; i < STRs.Length; i++)
|
||||
{
|
||||
Strings[i] = new MsgPack().Add("ID", STRs[i].ID);
|
||||
if (STRs[i].Str != null) if (STRs[i].Str != "")
|
||||
((MsgPack)Strings[i]).Add("S", STRs[i].Str); ;
|
||||
Strings[i] = MsgPack.New.Add("ID", STRs[i].ID);
|
||||
if (STRs[i].Str.V != null)
|
||||
if (STRs[i].Str.V != "")
|
||||
Strings[i] = Strings[i].Add("Str", STRs[i].Str.V);
|
||||
}
|
||||
STR_.Add(Strings);
|
||||
|
||||
STR_.Write(true, file, JSON);
|
||||
STR_.WriteAfterAll(true, file, JSON);
|
||||
}
|
||||
|
||||
public struct String
|
||||
{
|
||||
public int ID;
|
||||
public Pointer<string> Str;
|
||||
|
||||
public override string ToString() => "ID: " + ID + (Str.V != null ||
|
||||
Str.V != "" ? ("; Str: " + Str.V) : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public static class Text
|
||||
{
|
||||
public static string ToASCII(this byte[] Array) => Encoding.ASCII.GetString(Array);
|
||||
public static string ToUTF8 (this byte[] Array) => Encoding.UTF8 .GetString(Array);
|
||||
public static byte[] ToASCII(this string Data ) => Encoding.ASCII.GetBytes (Data );
|
||||
public static byte[] ToUTF8 (this string Data ) => Encoding.UTF8 .GetBytes (Data );
|
||||
public static byte[] ToASCII(this char[] Data ) => Encoding.ASCII.GetBytes (Data );
|
||||
public static byte[] ToUTF8 (this char[] Data ) => Encoding.UTF8 .GetBytes (Data );
|
||||
public static string ToBase64(this byte[] Array) => Convert. ToBase64String(Array);
|
||||
public static byte[] FromBase64(this string Data ) => Convert.FromBase64String(Data );
|
||||
}
|
||||
}
|
||||
@@ -1,102 +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 == 0x1F)
|
||||
return double.NaN;
|
||||
else if (h._value >> 10 == 0x3F)
|
||||
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 = 0;
|
||||
if (Math.Abs(x - exponent_max / Pow2) > Math.Abs(x - exponent_min / Pow2))
|
||||
exponent = exponent_max;
|
||||
else exponent = 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++;
|
||||
}
|
||||
|
||||
if (i >= +0)
|
||||
return 0x7C00;
|
||||
else
|
||||
return 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();
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.Types
|
||||
{
|
||||
public class Vector2<T>
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
public T Z;
|
||||
|
||||
public Vector2()
|
||||
{ X = default(T); Y = default(T); Z = default(T); }
|
||||
|
||||
public Vector2(T X, T Y, T Z)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; }
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.Types
|
||||
{
|
||||
public class Vector3<T>
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
public T Z;
|
||||
|
||||
public Vector3()
|
||||
{ X = default(T); Y = default(T); Z = default(T); }
|
||||
|
||||
public Vector3(T X, T Y, T Z)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; }
|
||||
}
|
||||
}
|
||||
+32
-32
@@ -1,4 +1,4 @@
|
||||
using KKdMainLib;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdSoundLib
|
||||
@@ -17,20 +17,20 @@ 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);
|
||||
reader.RI32();
|
||||
Data.Size = reader.RU32();
|
||||
Data.SampleRate = reader.RU32();
|
||||
Data.SamplesCount = reader.RU32();
|
||||
reader.RI64();
|
||||
Data.Channels = reader.RU16();
|
||||
reader.RU16();
|
||||
Data.Name = reader.RS(0x20);
|
||||
|
||||
Stream writer = File.OpenWriter();
|
||||
if (!ToArray) writer = File.OpenWriter(file + ".wav", true);
|
||||
writer.LongPosition = 0x2C;
|
||||
writer.I64P = 0x2C;
|
||||
|
||||
byte value = 0;
|
||||
int[] current = new int[Data.Channels];
|
||||
@@ -45,19 +45,19 @@ namespace KKdSoundLib
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Data.Channels; c++)
|
||||
{
|
||||
value = reader.ReadHalfByte();
|
||||
value = reader.RHB();
|
||||
IMADecoder(value, ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
|
||||
f = (float)(currentPtr[c] / 32768.0);
|
||||
writer.Write(f);
|
||||
writer.W(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);
|
||||
writer.W(Header, 0);
|
||||
if (ToArray) Data.Data = writer.ToArray();
|
||||
writer.Close();
|
||||
writer.C();
|
||||
|
||||
reader.Close();
|
||||
reader.C();
|
||||
}
|
||||
|
||||
public void DIVAWriter(string file)
|
||||
@@ -68,12 +68,12 @@ 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;
|
||||
writer.I64P = 0x40;
|
||||
|
||||
byte value = 0;
|
||||
int[] sample = new int[Data.Channels];
|
||||
@@ -90,24 +90,24 @@ namespace KKdSoundLib
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Header.Channels; c++)
|
||||
{
|
||||
samplePtr[c] = (reader.ReadWAVSample(Header.Bytes, Header.Format) * 0x8000).CFTI();
|
||||
samplePtr[c] = (reader.RS(Header.Bytes, Header.Format) * 0x8000).CFTI();
|
||||
value = IMAEncoder(samplePtr[c], ref currentPtr[c],
|
||||
ref currentclampPtr[c], ref stepindexPtr[c]);
|
||||
writer.Write(value, 4);
|
||||
writer.W(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.I64P = 0x00;
|
||||
writer.W("DIVA");
|
||||
writer.W(0x00);
|
||||
writer.W((Data.SamplesCount * Data.Channels).Align(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)
|
||||
|
||||
+54
-55
@@ -1,98 +1,97 @@
|
||||
using System;
|
||||
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)
|
||||
{
|
||||
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.RU32();
|
||||
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.RU32();
|
||||
Header.HeaderSize = IO.U32P;
|
||||
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.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.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(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
<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>
|
||||
@@ -33,6 +35,8 @@
|
||||
<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="Extensions.cs" />
|
||||
@@ -48,6 +52,10 @@
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KKdBaseLib\KKdBaseLib.csproj">
|
||||
<Project>{da55bfd3-927e-473c-a779-f9e6365384ae}</Project>
|
||||
<Name>KKdBaseLib</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\KKdMainLib\KKdMainLib.csproj">
|
||||
<Project>{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}</Project>
|
||||
<Name>KKdMainLib</Name>
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("KKdSoundLib")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[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("Copyright korenkonder © 2019")]
|
||||
[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")]
|
||||
[assembly: AssemblyVersion("0.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.1.0.0")]
|
||||
|
||||
+186
-169
@@ -1,4 +1,4 @@
|
||||
using KKdMainLib;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdSoundLib
|
||||
@@ -28,18 +28,18 @@ namespace KKdSoundLib
|
||||
VAGData = new VAGFile();
|
||||
Stream reader = File.OpenReader(file + ".vag", true);
|
||||
|
||||
if (reader.ReadUInt32() != 0x70474156) return;
|
||||
if (reader.RU32() != 0x70474156) return;
|
||||
|
||||
VAGData.Version = reader.ReadUInt32Endian(true);
|
||||
reader.ReadUInt32();
|
||||
VAGData.Size = reader.ReadUInt32Endian(true);
|
||||
VAGData.SampleRate = reader.ReadUInt32Endian(true);
|
||||
reader.ReadUInt32();
|
||||
reader.ReadUInt32();
|
||||
reader.ReadUInt16();
|
||||
VAGData.Channels = reader.ReadUInt16();
|
||||
VAGData.Version = reader.RU32E(true);
|
||||
reader.RU32();
|
||||
VAGData.Size = reader.RU32E(true);
|
||||
VAGData.SampleRate = reader.RU32E(true);
|
||||
reader.RU32();
|
||||
reader.RU32();
|
||||
reader.RU16();
|
||||
VAGData.Channels = reader.RU16();
|
||||
if (VAGData.Channels < 2) VAGData.Channels = 1;
|
||||
VAGData.Name = reader.ReadString(0x10);
|
||||
VAGData.Name = reader.RS(0x10);
|
||||
|
||||
bool HEVAG = VAGData.Version == 0x00020001 || VAGData.Version == 0x00030000;
|
||||
if (!HEVAG) VAGData.Channels = 1;
|
||||
@@ -52,7 +52,7 @@ namespace KKdSoundLib
|
||||
Samp2 = new int[VAGData.Channels]; S2Ptr = Samp2.GetPtr();
|
||||
Samp3 = new int[VAGData.Channels]; S3Ptr = Samp3.GetPtr();
|
||||
Samp4 = new int[VAGData.Channels]; S4Ptr = Samp4.GetPtr();
|
||||
if (VAGData.Size + 0x30 > reader.LongLength) VAGData.Size = reader.UIntLength - 0x30;
|
||||
if (VAGData.Size + 0x30 > reader.I64L) VAGData.Size = reader.U32L - 0x30;
|
||||
VAGData.Size = (VAGData.Size / VAGData.Channels) >> 4;
|
||||
VAGData.Flags = new byte [VAGData.Size];
|
||||
VAGData.Data = new int[VAGData.Size * VBS];
|
||||
@@ -63,16 +63,16 @@ namespace KKdSoundLib
|
||||
for (i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
|
||||
for (c = 0; c < ch; c++)
|
||||
{
|
||||
s = reader.ReadByte();
|
||||
s = reader.RU8();
|
||||
PrNR = (s & 0xF0) >> 4;
|
||||
ShF = s & 0x0F;
|
||||
s = reader.ReadByte();
|
||||
s = reader.RU8();
|
||||
PrNR = (s & 0xF0) | PrNR;
|
||||
VAGData.Flags[i1] = (byte)(s & 0xF);
|
||||
|
||||
for (i = 0, i2 = 1; i < BS; i += 2, i2 += 2)
|
||||
{
|
||||
s = reader.ReadByte();
|
||||
s = reader.RU8();
|
||||
four_bitPtr[i ] = s & 0x0F;
|
||||
four_bitPtr[i2] = s & 0xF0;
|
||||
four_bitPtr[i2] >>= 4;
|
||||
@@ -89,20 +89,19 @@ namespace KKdSoundLib
|
||||
VAGData.DataPtr[i * ch + c] = temp_bufferPtr[i ];
|
||||
VAGData.DataPtr[i2 * ch + c] = temp_bufferPtr[i2];
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
for (i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
|
||||
{
|
||||
s = reader.ReadByte();
|
||||
s = reader.RU8();
|
||||
PrNR = (s & 0xF0) >> 4;
|
||||
ShF = s & 0x0F;
|
||||
s = reader.ReadByte();
|
||||
s = reader.RU8();
|
||||
VAGData.Flags[i1] = (byte)(s & 0xF);
|
||||
|
||||
for (i = 0, i2 = 1; i < BS; i += 2, i2 += 2)
|
||||
{
|
||||
s = reader.ReadByte();
|
||||
s = reader.RU8();
|
||||
four_bitPtr[i ] = s & 0x0F;
|
||||
four_bitPtr[i2] = s & 0xF0;
|
||||
four_bitPtr[i2] >>= 4;
|
||||
@@ -110,29 +109,7 @@ namespace KKdSoundLib
|
||||
|
||||
VAG_1 = HEVAG1Ptr[PrNR]; VAG_2 = HEVAG2Ptr[PrNR];
|
||||
tS1 = S1Ptr[c]; tS2 = S2Ptr[c];
|
||||
|
||||
i = 0; i2 = 1;
|
||||
while (i < BS)
|
||||
{
|
||||
d0 = four_bitPtr[i];
|
||||
d1 = four_bitPtr[i2];
|
||||
if (d0 > 7) d0 -= 16;
|
||||
if (d1 > 7) d1 -= 16;
|
||||
d0 = d0 << (20 - ShF);
|
||||
d1 = d1 << (20 - ShF);
|
||||
|
||||
g = ((tS1 >> 8) * VAG_1 + (tS2 >> 8) * VAG_2) >> 5;
|
||||
tS2 = tS1; tS1 = g + d0;
|
||||
|
||||
g = ((tS1 >> 8) * VAG_1 + (tS2 >> 8) * VAG_2) >> 5;
|
||||
tS2 = tS1; tS1 = g + d1;
|
||||
|
||||
temp_bufferPtr[i ] = tS2;
|
||||
temp_bufferPtr[i2] = tS1;
|
||||
i += 2;
|
||||
i2 += 2;
|
||||
}
|
||||
|
||||
DecodeVAG();
|
||||
S1Ptr[c] = tS1; S2Ptr[c] = tS2;
|
||||
|
||||
for (i = 0, i2 = 1; i < BS; i += 2, i2 += 2)
|
||||
@@ -143,10 +120,35 @@ namespace KKdSoundLib
|
||||
}
|
||||
|
||||
VAGData.DataPtr = VAGData.OriginDataPtr;
|
||||
reader.Close();
|
||||
reader.C();
|
||||
Success = true;
|
||||
}
|
||||
|
||||
private void DecodeVAG()
|
||||
{
|
||||
i = 0; i2 = 1;
|
||||
while (i < BS)
|
||||
{
|
||||
d0 = four_bitPtr[i];
|
||||
d1 = four_bitPtr[i2];
|
||||
if (d0 > 7) d0 -= 16;
|
||||
if (d1 > 7) d1 -= 16;
|
||||
d0 <<= 20 - ShF;
|
||||
d1 <<= 20 - ShF;
|
||||
|
||||
g = ((tS1 >> 8) * VAG_1 + (tS2 >> 8) * VAG_2) >> 5;
|
||||
tS2 = tS1; tS1 = g + d0;
|
||||
|
||||
g = ((tS1 >> 8) * VAG_1 + (tS2 >> 8) * VAG_2) >> 5;
|
||||
tS2 = tS1; tS1 = g + d1;
|
||||
|
||||
temp_bufferPtr[i ] = tS2;
|
||||
temp_bufferPtr[i2] = tS1;
|
||||
i += 2;
|
||||
i2 += 2;
|
||||
}
|
||||
}
|
||||
|
||||
private void DecodeHEVAG()
|
||||
{
|
||||
i = 0; i2 = 1;
|
||||
@@ -156,8 +158,8 @@ namespace KKdSoundLib
|
||||
d1 = four_bitPtr[i2];
|
||||
if (d0 > 7) d0 -= 16;
|
||||
if (d1 > 7) d1 -= 16;
|
||||
d0 = d0 << (20 - ShF);
|
||||
d1 = d1 << (20 - ShF);
|
||||
d0 <<= 20 - ShF;
|
||||
d1 <<= 20 - ShF;
|
||||
|
||||
g = ((tS1 >> 8) * HEVAG_1 + (tS2 >> 8) * HEVAG_2 +
|
||||
(tS3 >> 8) * HEVAG_3 + (tS4 >> 8) * HEVAG_4) >> 5;
|
||||
@@ -181,44 +183,44 @@ namespace KKdSoundLib
|
||||
if (Flag == 7) return;
|
||||
WAV.Header Header = new WAV.Header();
|
||||
Stream writer = File.OpenWriter(file + ".wav", true);
|
||||
writer.LongPosition = 0x2C;
|
||||
writer.I64P = 0x2C;
|
||||
|
||||
if (Flag < 8)
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
{
|
||||
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
|
||||
writer.Write(f);
|
||||
writer.W(f);
|
||||
}
|
||||
else
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
writer.Write(0f);
|
||||
writer.W(0f);
|
||||
|
||||
for (i1 = 0, i2 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
|
||||
{
|
||||
Flag = VAGData.Flags[i1];
|
||||
if (!IgnoreEndFlags && Flag == 5 || Flag == 7) break;
|
||||
if (!IgnoreEndFlags && (Flag == 5 || Flag == 7)) break;
|
||||
if (Flag < 8)
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
{
|
||||
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
|
||||
writer.Write(f);
|
||||
writer.W(f);
|
||||
}
|
||||
else
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
writer.Write(0f);
|
||||
writer.W(0f);
|
||||
|
||||
if (!IgnoreEndFlags && Flag == 1) break;
|
||||
}
|
||||
VAGData.DataPtr = VAGData.OriginDataPtr;
|
||||
|
||||
Header = new WAV.Header { Bytes = 4, Channels = ch, Format = 3, SampleRate =
|
||||
VAGData.SampleRate, Size = writer.UIntPosition - 0x2C };
|
||||
writer.Write(Header, 0);
|
||||
writer.Close();
|
||||
VAGData.SampleRate, Size = writer.U32P - 0x2C };
|
||||
writer.W(Header, 0);
|
||||
writer.C();
|
||||
}
|
||||
|
||||
public void WAVWriter(string file, bool IgnoreEndFlags = false)
|
||||
@@ -230,36 +232,36 @@ namespace KKdSoundLib
|
||||
Stream writer;
|
||||
if (!IgnoreEndFlags && Flag == 6) writer = File.OpenWriter(file + ".loop.0.wav", true);
|
||||
else writer = File.OpenWriter(file + ".0.wav", true);
|
||||
writer.LongPosition = 0x2C;
|
||||
writer.I64P = 0x2C;
|
||||
|
||||
if (Flag < 8)
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
{
|
||||
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
|
||||
writer.Write(f);
|
||||
writer.W(f);
|
||||
}
|
||||
else
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
writer.Write(0f);
|
||||
writer.W(0f);
|
||||
|
||||
VAGData.DataPtr += VBS;
|
||||
|
||||
for (i1 = 1, i2 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
|
||||
{
|
||||
Flag = VAGData.Flags[i1];
|
||||
if (!IgnoreEndFlags && Flag == 5 || Flag == 7) break;
|
||||
if (!IgnoreEndFlags && (Flag == 5 || Flag == 7)) break;
|
||||
else if (!IgnoreEndFlags && Flag == 6)
|
||||
{
|
||||
Header = new WAV.Header { Bytes = 4, Channels = ch, Format = 3, SampleRate =
|
||||
VAGData.SampleRate, Size = writer.UIntPosition - 0x2C };
|
||||
writer.Write(Header, 0);
|
||||
writer.Close();
|
||||
VAGData.SampleRate, Size = writer.U32P - 0x2C };
|
||||
writer.W(Header, 0);
|
||||
writer.C();
|
||||
i2++;
|
||||
|
||||
writer = File.OpenWriter(file + "." + i2 + ".loop.wav", true);
|
||||
writer.LongPosition = 0x2C;
|
||||
writer.I64P = 0x2C;
|
||||
}
|
||||
|
||||
if (!IgnoreEndFlags && Flag < 8)
|
||||
@@ -267,35 +269,35 @@ namespace KKdSoundLib
|
||||
for (c = 0; c < ch; c++)
|
||||
{
|
||||
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
|
||||
writer.Write(f);
|
||||
writer.W(f);
|
||||
}
|
||||
else
|
||||
for (i = 0; i < BS; i++)
|
||||
for (c = 0; c < ch; c++)
|
||||
writer.Write(0f);
|
||||
writer.W(0f);
|
||||
|
||||
if (!IgnoreEndFlags && Flag == 1) break;
|
||||
else if (!IgnoreEndFlags && Flag == 3)
|
||||
{
|
||||
Header = new WAV.Header { Bytes = 4, Channels = ch, Format = 3, SampleRate =
|
||||
VAGData.SampleRate, Size = writer.UIntPosition - 0x2C };
|
||||
writer.Write(Header, 0);
|
||||
writer.Close();
|
||||
VAGData.SampleRate, Size = writer.U32P - 0x2C };
|
||||
writer.W(Header, 0);
|
||||
writer.C();
|
||||
i2++;
|
||||
|
||||
if (VAGData.Size == i1 + 1)
|
||||
writer = File.OpenWriter();
|
||||
else
|
||||
writer = File.OpenWriter(file + "." + i2 + ".wav", true);
|
||||
writer.LongPosition = 0x2C;
|
||||
writer.I64P = 0x2C;
|
||||
}
|
||||
}
|
||||
VAGData.DataPtr = VAGData.OriginDataPtr;
|
||||
|
||||
Header = new WAV.Header { Bytes = 4, Channels = ch, Format = 3, SampleRate =
|
||||
VAGData.SampleRate, Size = writer.UIntPosition - 0x2C };
|
||||
writer.Write(Header, 0);
|
||||
writer.Close();
|
||||
VAGData.SampleRate, Size = writer.U32P - 0x2C };
|
||||
writer.W(Header, 0);
|
||||
writer.C();
|
||||
}
|
||||
|
||||
public int WAVReaderStraight(string file, bool ExtendedFlagging = false)
|
||||
@@ -304,7 +306,7 @@ namespace KKdSoundLib
|
||||
VAGData = new VAGFile();
|
||||
Stream reader = File.OpenReader(file + ".wav");
|
||||
WAV.Header Header = reader.ReadWAVHeader();
|
||||
if (!Header.IsSupported) { reader.Close(); return 1; }
|
||||
if (!Header.IsSupported) { reader.C(); return 1; }
|
||||
ch = Header.Channels;
|
||||
VBS = BS * ch;
|
||||
|
||||
@@ -315,22 +317,22 @@ namespace KKdSoundLib
|
||||
|
||||
if (Header.Bytes == 1 && Header.Format == 0x01)
|
||||
for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
|
||||
*VAGData.DataPtr = (reader.ReadByte () - 0x80) << 16;
|
||||
*VAGData.DataPtr = (reader.RU8 () - 0x80) << 16;
|
||||
else if (Header.Bytes == 2 && Header.Format == 0x01)
|
||||
for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
|
||||
*VAGData.DataPtr = reader.ReadInt16 () << 8;
|
||||
*VAGData.DataPtr = reader.RI16 () << 8;
|
||||
else if (Header.Bytes == 3 && Header.Format == 0x01)
|
||||
for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
|
||||
*VAGData.DataPtr = reader.ReadByte () | (reader.ReadInt16() << 8);
|
||||
*VAGData.DataPtr = reader.RU8 () | (reader.RI16() << 8);
|
||||
else if (Header.Bytes == 4 && Header.Format == 0x01)
|
||||
for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
|
||||
*VAGData.DataPtr = reader.ReadInt32 () >> 8;
|
||||
*VAGData.DataPtr = reader.RI32 () >> 8;
|
||||
else if (Header.Bytes == 4 && Header.Format == 0x03)
|
||||
for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
|
||||
*VAGData.DataPtr = (int)(reader.ReadSingle() * 8388608.0);
|
||||
*VAGData.DataPtr = (int)(reader.RF32() * 8388608.0);
|
||||
else if (Header.Bytes == 8 && Header.Format == 0x03)
|
||||
for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
|
||||
*VAGData.DataPtr = (int)(reader.ReadDouble() * 8388608.0);
|
||||
*VAGData.DataPtr = (int)(reader.RF64() * 8388608.0);
|
||||
|
||||
VAGData.Size = VAGData.Size.Align(VBS, VBS);
|
||||
VAGData.DataPtr = VAGData.OriginDataPtr;
|
||||
@@ -340,7 +342,7 @@ namespace KKdSoundLib
|
||||
if (ExtendedFlagging) VAGData.Flags[0] = 0x4;
|
||||
VAGData.Flags[VAGData.Size - 1] = 0x1;
|
||||
|
||||
reader.Close();
|
||||
reader.C();
|
||||
Success = true;
|
||||
return 0;
|
||||
}
|
||||
@@ -391,15 +393,15 @@ namespace KKdSoundLib
|
||||
reader = File.OpenReader(Files[i]);
|
||||
Header = reader.ReadWAVHeader();
|
||||
|
||||
if (!Header.IsSupported) { reader.Close(); return 2; }
|
||||
if (!Header.IsSupported) { reader.C(); return 2; }
|
||||
if (i == 0) { SampleRate = Header.SampleRate;
|
||||
ch = Channels = Header.Channels; VBS = BS * ch; }
|
||||
if (Header.Channels != Channels ) { reader.Close(); return 3; }
|
||||
if (Header.SampleRate != SampleRate) { reader.Close(); return 4; }
|
||||
if (Header.Channels != Channels ) { reader.C(); return 3; }
|
||||
if (Header.SampleRate != SampleRate) { reader.C(); return 4; }
|
||||
|
||||
Sizes[i] = Header.Size / Header.Bytes;
|
||||
Size += Sizes[i].Align(VBS);
|
||||
reader.Close();
|
||||
reader.C();
|
||||
}
|
||||
|
||||
VAGData.Data = new int[Size];
|
||||
@@ -420,23 +422,23 @@ namespace KKdSoundLib
|
||||
Header = reader.ReadWAVHeader();
|
||||
if (Header.Bytes == 1 && Header.Format == 0x01)
|
||||
for (int i1 = 0; i1 < Sizes[i]; i1++, VAGData.DataPtr++)
|
||||
*VAGData.DataPtr = (reader.ReadByte () - 0x80) << 16;
|
||||
*VAGData.DataPtr = (reader.RU8 () - 0x80) << 16;
|
||||
else if (Header.Bytes == 2 && Header.Format == 0x01)
|
||||
for (int i1 = 0; i1 < Sizes[i]; i1++, VAGData.DataPtr++)
|
||||
*VAGData.DataPtr = reader.ReadInt16 () << 8;
|
||||
*VAGData.DataPtr = reader.RI16 () << 8;
|
||||
else if (Header.Bytes == 3 && Header.Format == 0x01)
|
||||
for (int i1 = 0; i1 < Sizes[i]; i1++, VAGData.DataPtr++)
|
||||
*VAGData.DataPtr = reader.ReadByte () | (reader.ReadInt16() << 8);
|
||||
*VAGData.DataPtr = reader.RU8 () | (reader.RI16() << 8);
|
||||
else if (Header.Bytes == 4 && Header.Format == 0x01)
|
||||
for (int i1 = 0; i1 < Sizes[i]; i1++, VAGData.DataPtr++)
|
||||
*VAGData.DataPtr = reader.ReadInt32 () >> 8;
|
||||
*VAGData.DataPtr = reader.RI32 () >> 8;
|
||||
else if (Header.Bytes == 4 && Header.Format == 0x03)
|
||||
for (int i1 = 0; i1 < Sizes[i]; i1++, VAGData.DataPtr++)
|
||||
*VAGData.DataPtr = (int)(reader.ReadSingle() * 8388608.0);
|
||||
*VAGData.DataPtr = (int)(reader.RF32() * 8388608.0);
|
||||
else if (Header.Bytes == 8 && Header.Format == 0x03)
|
||||
for (int i1 = 0; i1 < Sizes[i]; i1++, VAGData.DataPtr++)
|
||||
*VAGData.DataPtr = (int)(reader.ReadDouble() * 8388608.0);
|
||||
reader.Close();
|
||||
*VAGData.DataPtr = (int)(reader.RF64() * 8388608.0);
|
||||
reader.C();
|
||||
|
||||
AlignVAG = Sizes[i].Align(VBS) - Sizes[i];
|
||||
VAGData.DataPtr += AlignVAG;
|
||||
@@ -477,23 +479,22 @@ namespace KKdSoundLib
|
||||
four_bit = new int[BS]; four_bitPtr = four_bit .GetPtr();
|
||||
data_buffer = new int[BS]; data_bufferPtr = data_buffer.GetPtr();
|
||||
temp_buffer = new int[BS]; temp_bufferPtr = temp_buffer.GetPtr();
|
||||
buffer = new int[PrNRCount, BS];
|
||||
|
||||
writer.Write(0x70474156);
|
||||
if (HEVAG) writer.WriteEndian(0x00020001, true);
|
||||
else writer.WriteEndian(0x00000020, true);
|
||||
writer.Write(0);
|
||||
if (HEVAG) writer.WriteEndian((VAGData.Size * ch + ch) << 4, true);
|
||||
else writer.WriteEndian((VAGData.Size + 1) << 4, true);
|
||||
writer.WriteEndian(VAGData.SampleRate, true);
|
||||
writer.Write(0);
|
||||
writer.Write(0);
|
||||
writer.Write((ushort)0);
|
||||
if (HEVAG) writer.Write(VAGData.Channels);
|
||||
else writer.Write((ushort)0x1);
|
||||
writer.Write(VAGData.Name);
|
||||
writer.LongLength = 0x30;
|
||||
writer.LongPosition = 0x30;
|
||||
writer.W(0x70474156);
|
||||
if (HEVAG) writer.WE(0x00020001, true);
|
||||
else writer.WE(0x00000020, true);
|
||||
writer.W(0);
|
||||
if (HEVAG) writer.WE((VAGData.Size * ch + ch) << 4, true);
|
||||
else writer.WE((VAGData.Size + 1) << 4, true);
|
||||
writer.WE(VAGData.SampleRate, true);
|
||||
writer.W(0);
|
||||
writer.W(0);
|
||||
writer.W((ushort)0);
|
||||
if (HEVAG) writer.W(VAGData.Channels);
|
||||
else writer.W((ushort)0x1);
|
||||
writer.W(VAGData.Name);
|
||||
writer.I64L = 0x30;
|
||||
writer.I64P = 0x30;
|
||||
|
||||
if (HEVAG)
|
||||
for (i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
|
||||
@@ -508,26 +509,26 @@ namespace KKdSoundLib
|
||||
if (s == 0)
|
||||
{
|
||||
S_1[c] = S_2[c] = S_3[c] = S_4[c] = 0;
|
||||
writer.WriteByte(0);
|
||||
writer.WriteByte(VAGData.Flags[i1]);
|
||||
writer.WriteByte(0);
|
||||
writer.WriteByte(0);
|
||||
writer.Write(0);
|
||||
writer.Write(0);
|
||||
writer.Write(0);
|
||||
writer.W(0);
|
||||
writer.W(VAGData.Flags[i1]);
|
||||
writer.W(0);
|
||||
writer.W(0);
|
||||
writer.W(0);
|
||||
writer.W(0);
|
||||
writer.W(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
Calc4BitsHEVAG();
|
||||
|
||||
s = ((PrNR & 0xF) << 4) | (ShF & 0xF);
|
||||
writer.WriteByte((byte)s);
|
||||
writer.W((byte)s);
|
||||
s = (PrNR & 0xF0) | (VAGData.Flags[i1] & 0xF);
|
||||
writer.WriteByte((byte)s);
|
||||
writer.W((byte)s);
|
||||
for (i = 0, i2 = 1; i < BS; i += 2, i2 += 2)
|
||||
{
|
||||
s = (four_bitPtr[i2] << 4) | four_bitPtr[i];
|
||||
writer.WriteByte((byte)s);
|
||||
writer.W((byte)s);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -545,102 +546,118 @@ namespace KKdSoundLib
|
||||
if (s == 0)
|
||||
{
|
||||
S_1[c] = S_2[c] = 0;
|
||||
writer.WriteByte(0);
|
||||
writer.WriteByte(VAGData.Flags[i1]);
|
||||
writer.WriteByte(0);
|
||||
writer.WriteByte(0);
|
||||
writer.Write(0);
|
||||
writer.Write(0);
|
||||
writer.Write(0);
|
||||
writer.W(0);
|
||||
writer.W(VAGData.Flags[i1]);
|
||||
writer.W(0);
|
||||
writer.W(0);
|
||||
writer.W(0);
|
||||
writer.W(0);
|
||||
writer.W(0);
|
||||
continue;
|
||||
}
|
||||
|
||||
Calc4BitsVAG();
|
||||
|
||||
s = ((PrNR & 0xF) << 4) | (ShF & 0xF);
|
||||
writer.WriteByte((byte)s);
|
||||
writer.WriteByte(VAGData.Flags[i1]);
|
||||
writer.W((byte)s);
|
||||
writer.W(VAGData.Flags[i1]);
|
||||
for (i = 0, i2 = 1; i < BS; i += 2, i2 += 2)
|
||||
{
|
||||
s = (four_bitPtr[i2] << 4) | four_bitPtr[i];
|
||||
writer.WriteByte((byte)s);
|
||||
writer.W((byte)s);
|
||||
}
|
||||
}
|
||||
|
||||
if (!HEVAG) ch = 1;
|
||||
for (c = 0; c < ch; c++)
|
||||
{
|
||||
writer.Write(0x77770700);
|
||||
writer.Write(0x77777777);
|
||||
writer.Write(0x77777777);
|
||||
writer.Write(0x77777777);
|
||||
writer.W(0x77770700);
|
||||
writer.W(0x77777777);
|
||||
writer.W(0x77777777);
|
||||
writer.W(0x77777777);
|
||||
}
|
||||
VAGData.DataPtr = VAGData.OriginDataPtr;
|
||||
writer.Close();
|
||||
writer.C();
|
||||
}
|
||||
|
||||
private int min, ShM, S1, S2, S3, S4, tS1, tS2, tS3, tS4, PrNRf;
|
||||
private int VAG_1, VAG_2, HEVAG_1, HEVAG_2, HEVAG_3, HEVAG_4;
|
||||
private int[] data_buffer, error, four_bit, max, S_1, S_2, S_3, S_4, temp_buffer;
|
||||
private int[,] buffer;
|
||||
private int* data_bufferPtr, errorPtr, four_bitPtr, maxPtr, temp_bufferPtr;
|
||||
|
||||
|
||||
private void Calc4BitsVAG()
|
||||
{
|
||||
ShF = min = 134217728;
|
||||
for (j = 0; j < 5; j++)
|
||||
PrNRf = 0;
|
||||
min = 134217728;
|
||||
for (j = 0; j < PrNRCount; j++)
|
||||
{
|
||||
maxPtr[j] = 0;
|
||||
S1 = S1Ptr[c]; S2 = S2Ptr[c];
|
||||
VAG_1 = HEVAG1Ptr[j]; VAG_2 = HEVAG2Ptr[j];
|
||||
for (i = 0; i < 28; i++)
|
||||
PrNR = j;
|
||||
|
||||
Calc4Bits_VAG();
|
||||
|
||||
tS1 = S1Ptr[c]; tS2 = S2Ptr[c];
|
||||
DecodeVAG();
|
||||
i = 0;
|
||||
errorPtr[j] = 0;
|
||||
while (i < BS)
|
||||
{
|
||||
g = data_bufferPtr[i];
|
||||
e = ((S1 >> 8) * VAG_1 + (S2 >> 8) * VAG_2) >> 5;
|
||||
e = g - e;
|
||||
if (e > 7864319) e = 7864319;
|
||||
if (e < -7864320) e = -7864320;
|
||||
buffer[j, i] = e;
|
||||
e = data_bufferPtr[i] - temp_bufferPtr[i];
|
||||
if (e < 0) e = -e;
|
||||
if (e > maxPtr[j]) maxPtr[j] = e;
|
||||
S2 = S1; S1 = g;
|
||||
errorPtr[j] += e;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (maxPtr[j] < min) { PrNR = j; min = maxPtr[j]; }
|
||||
if (errorPtr[j] < min) { PrNRf = j; min = errorPtr[j]; }
|
||||
}
|
||||
|
||||
S1Ptr[c] = S1; S2Ptr[c] = S2;
|
||||
PrNR = PrNRf;
|
||||
|
||||
ShF = 0;
|
||||
ShM = 0x4000;
|
||||
min = min >> 8;
|
||||
|
||||
while (ShF < 12)
|
||||
Calc4Bits_VAG();
|
||||
S1Ptr[c] = S1; S2Ptr[c] = S2;
|
||||
S_1 [c] = tS1; S_2 [c] = tS2;
|
||||
}
|
||||
|
||||
private void Calc4Bits_VAG()
|
||||
{
|
||||
S1 = S1Ptr[c]; S2 = S2Ptr[c];
|
||||
VAG_1 = HEVAG1Ptr[PrNR]; HEVAG_2 = HEVAG2Ptr[PrNR];
|
||||
|
||||
i = 0;
|
||||
maxPtr[PrNR] = 0;
|
||||
while (i < BS)
|
||||
{
|
||||
e = min + (ShM >> 3);
|
||||
if ((ShM & e) == ShM)
|
||||
break;
|
||||
ShF++;
|
||||
ShM >>= 1;
|
||||
g = data_bufferPtr[i];
|
||||
e = ((S1 >> 8) * VAG_1 + (S2 >> 8) * VAG_2) >> 5;
|
||||
e = g - e;
|
||||
if (e > 7864319) e = 7864319;
|
||||
if (e < -7864320) e = -7864320;
|
||||
temp_bufferPtr[i] = e;
|
||||
if (e < 0) e = -e;
|
||||
if (e > maxPtr[PrNR]) maxPtr[PrNR] = e;
|
||||
S2 = S1; S1 = g;
|
||||
i++;
|
||||
}
|
||||
|
||||
S1 = S_1[c]; S2 = S_2[c];
|
||||
for (i = 0; i < 28; i++)
|
||||
for (ShF = 0, ShM = 0x400000; ShF < 15; ShF++, ShM >>= 1)
|
||||
{ e = maxPtr[PrNR] + (ShM >> 3); if ((ShM & e) == ShM) break; }
|
||||
|
||||
tS1 = S_1[c]; tS2 = S_2[c];
|
||||
i = 0;
|
||||
while (i < BS)
|
||||
{
|
||||
g = buffer[PrNR, i];
|
||||
e = ((S1 >> 8) * HEVAG1Ptr[PrNR] + (S2 >> 8) * HEVAG2Ptr[PrNR]) >> 5;
|
||||
g = temp_bufferPtr[i];
|
||||
e = ((tS1 >> 8) * VAG_1 + (tS2 >> 8) * VAG_2) >> 5;
|
||||
e = g - e;
|
||||
|
||||
d1 = e << ShF;
|
||||
d0 = (int)((uint)d1 + 0x80000) >> 20;
|
||||
d0 = (d1 + 0x80000) >> 20;
|
||||
if (d0 > 7) d0 = 7;
|
||||
if (d0 < -8) d0 = -8;
|
||||
four_bitPtr[i] = d0 & 0xF;
|
||||
d0 = d0 << (20 - ShF);
|
||||
d0 <<= 20 - ShF;
|
||||
|
||||
S2 = S1; S1 = d0 - e;
|
||||
tS2 = tS1; tS1 = d0 - e;
|
||||
i++;
|
||||
}
|
||||
S_1[c] = S1; S_2[c] = S2;
|
||||
}
|
||||
|
||||
private void Calc4BitsHEVAG()
|
||||
@@ -714,7 +731,7 @@ namespace KKdSoundLib
|
||||
if (d0 > 7) d0 = 7;
|
||||
if (d0 < -8) d0 = -8;
|
||||
four_bitPtr[i] = d0 & 0xF;
|
||||
d0 = d0 << (20 - ShF);
|
||||
d0 <<= 20 - ShF;
|
||||
|
||||
tS4 = tS3; tS3 = tS2; tS2 = tS1; tS1 = d0 - e;
|
||||
i++;
|
||||
|
||||
+1
-7
@@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KKdSoundLib
|
||||
namespace KKdSoundLib
|
||||
{
|
||||
public static class WAV
|
||||
{
|
||||
|
||||
+13
-7
@@ -1,24 +1,26 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27130.2003
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29025.244
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PD_Tool", "PD_Tool\PD_Tool.csproj", "{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}"
|
||||
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
|
||||
|
||||
+14
-1
@@ -22,6 +22,8 @@
|
||||
<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>
|
||||
@@ -33,16 +35,23 @@
|
||||
<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\DataBase.cs" />
|
||||
<Compile Include="classes\Tools\A3D.cs" />
|
||||
<Compile Include="classes\Tools\AET.cs" />
|
||||
<Compile Include="classes\Tools\BLT.cs" />
|
||||
<Compile Include="classes\Tools\CCT.cs" />
|
||||
<Compile Include="classes\Tools\DB.cs" />
|
||||
<Compile Include="classes\Tools\DEX.cs" />
|
||||
<Compile Include="classes\Tools\DFT.cs" />
|
||||
<Compile Include="classes\Tools\DIV.cs" />
|
||||
<Compile Include="classes\Tools\LIT.cs" />
|
||||
<Compile Include="classes\Tools\MOT.cs" />
|
||||
<Compile Include="classes\Tools\STR.cs" />
|
||||
<Compile Include="classes\Tools\VAG.cs" />
|
||||
<Compile Include="classes\DataBase.cs" />
|
||||
<Compile Include="classes\DIVAFILE.cs" />
|
||||
<Compile Include="classes\FARC.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
@@ -55,6 +64,10 @@
|
||||
<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>
|
||||
|
||||
+184
-59
@@ -1,69 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.Types;
|
||||
using KKdMain = KKdMainLib.Main;
|
||||
using KKdFARC = KKdMainLib.FARC;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static string function = "";
|
||||
public static List<string> ProcessedFiles = new List<string>();
|
||||
[System.Runtime.InteropServices.DllImport("user32.dll")]
|
||||
private static extern bool SetProcessDPIAware();
|
||||
|
||||
[ThreadStatic] public static string function = "";
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
SetProcessDPIAware();
|
||||
|
||||
Console.Title = "PD_Tool";
|
||||
if (args.Length == 0)
|
||||
{
|
||||
while (function != "Q") MainMenu();
|
||||
Exit();
|
||||
}
|
||||
if (args.Length == 0) { while (function != "Q") MainMenu(); Exit(); }
|
||||
|
||||
long header;
|
||||
Stream reader;
|
||||
KKdFARC Farc;
|
||||
|
||||
foreach (string arg in args)
|
||||
{
|
||||
Farc = new KKdFARC();
|
||||
if (Directory.Exists(arg)) Farc.Pack(arg);
|
||||
else if (File.Exists(arg) && Path.GetExtension(arg) == ".farc") Farc.UnPack(arg, true);
|
||||
if (Directory.Exists(arg)) new KKdFARC(arg, true).Pack();
|
||||
else if (File.Exists(arg) && Path.GetExtension(arg) == ".farc") new KKdFARC(arg).UnPack(true);
|
||||
else if (File.Exists(arg))
|
||||
{
|
||||
reader = File.OpenReader(arg);
|
||||
header = reader.ReadInt64();
|
||||
reader.Close();
|
||||
using (reader = File.OpenReader(arg))
|
||||
header = reader.RI64();
|
||||
if (header == 0x454C494641564944) KKdMainLib.DIVAFILE.Decrypt(arg);
|
||||
}
|
||||
}
|
||||
Exit();
|
||||
}
|
||||
|
||||
private static bool JSON = false;
|
||||
[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/X/FT Converting Tools");
|
||||
ConsoleDesign(JSON ? "8. 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();
|
||||
@@ -76,31 +74,31 @@ namespace PD_Tool
|
||||
private static void Functions()
|
||||
{
|
||||
Console.Clear();
|
||||
if (function == "1" || function == "2") FARC.Processor(function == "1");
|
||||
if (function == "1" || function == "2") FARC.Processor(function == "1");
|
||||
else if (function == "3" || function == "4")
|
||||
{
|
||||
KKdMain.Choose(1, "", out string[] FileNames);
|
||||
Choose(1, "", out string[] FileNames);
|
||||
foreach (string FileName in FileNames) DIVAFILE.Decrypt(FileName);
|
||||
}
|
||||
else if (function == "5") DataBase.Processor(JSON);
|
||||
else if (function == "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. MOT" );
|
||||
ConsoleDesign("7. STR" );
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign("R. Return to Main Menu");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
string Function = Console.ReadLine();
|
||||
Console.Clear();
|
||||
@@ -109,20 +107,147 @@ namespace PD_Tool
|
||||
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 if (Function == "6") Tools.MOT.Processor(JSON);
|
||||
else if (Function == "7") Tools.STR.Processor(JSON);
|
||||
else function = Function;
|
||||
}
|
||||
else if (function == "7")
|
||||
{
|
||||
KKdMain.Choose(1, JSON ? "mp" : "json", out string[] FileNames);
|
||||
if (JSON) foreach (string file in FileNames)
|
||||
KKdMainLib.MessagePack.MPExt.ToJSON (file.Replace(Path.GetExtension(file), ""));
|
||||
else foreach (string file in FileNames)
|
||||
KKdMainLib.MessagePack.MPExt.ToMsgPack(file.Replace(Path.GetExtension(file), ""));
|
||||
Console.Clear();
|
||||
Console.Title = "F/F2/X/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 Function = Console.ReadLine();
|
||||
Console.Clear();
|
||||
if (Function == "1") Tools.A3D.Processor(JSON);
|
||||
else if (Function == "2") Tools.BLT.Processor();
|
||||
else if (Function == "3") Tools.CCT.Processor();
|
||||
else if (Function == "4") Tools.DEX.Processor(JSON);
|
||||
else if (Function == "5") Tools.DFT.Processor();
|
||||
else if (Function == "6") Tools.LIT.Processor();
|
||||
else if (Function == "7") Tools.STR.Processor(JSON);
|
||||
else if (Function == "8") Tools.VAG.Processor();
|
||||
else function = Function;
|
||||
}
|
||||
else if (function == "8")
|
||||
{
|
||||
Choose(1, JSON ? "mp" : "json", out string[] FileNames);
|
||||
foreach (string file in FileNames)
|
||||
if (JSON)
|
||||
{
|
||||
Console.Title = "MsgPack to JSON: " + Path.GetFileNameWithoutExtension(file);
|
||||
MPExt.ToJSON (file.Replace(Path.GetExtension(file), ""));
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Title = "JSON to MsgPack: " + Path.GetFileNameWithoutExtension(file);
|
||||
MPExt.ToMsgPack(file.Replace(Path.GetExtension(file), ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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 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)
|
||||
{
|
||||
string Filter = GetArgs("All;", false, "*");
|
||||
if (filetype == "a3da") Filter = GetArgs("A3DA", "a3da", "farc", "json", "mp") +
|
||||
GetArgs("A3DA", true, "a3da") + GetArgs("FARC", true, "farc") + JSON + MsgPack;
|
||||
else if (filetype == "bin" ) Filter = GetArgs("BIN" , "bin", "json", "mp") +
|
||||
BIN + JSON + MsgPack;
|
||||
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 + MsgPack;
|
||||
else if (filetype == "cct" ) Filter = GetArgs("CCT" , "cct");
|
||||
else if (filetype == "databank") Filter = GetArgs("DAT", "dat", "json", "mp") +
|
||||
GetArgs("DAT", true, "dat") + JSON + MsgPack;
|
||||
else if (filetype == "dex" ) Filter = GetArgs("DEX" , "dex", "bin", "json", "mp") +
|
||||
GetArgs("DEX", true, "dex") + BIN + JSON + MsgPack;
|
||||
else if (filetype == "dft" ) Filter = GetArgs("DFT" , "dft");
|
||||
else if (filetype == "diva") Filter = GetArgs("DIVA", "diva", "wav") +
|
||||
GetArgs("DIVA", true, "diva") + GetArgs("WAV", true, "wav");
|
||||
else if (filetype == "dsc" ) Filter = GetArgs("DSC" , "dsc", "json", "mp") +
|
||||
GetArgs("DSC", true, "dsc") + JSON + MsgPack;
|
||||
else if (filetype == "dve" ) Filter = GetArgs("Particles", "farc");
|
||||
else if (filetype == "farc") Filter = "FARC Archives (*.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 + MsgPack;
|
||||
else if (filetype == "vag" ) Filter = GetArgs("VAG" , "vag", "wav") +
|
||||
GetArgs("VAG", true, "vag") + GetArgs("WAV", true, "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 "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,14 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("PD_Tool")]
|
||||
[assembly: AssemblyDescription("A simple tool for working with Project Diva A/DT/F/AFT/F2/X/FT files")]
|
||||
[assembly: AssemblyDescription("A simple tool for working with Project Diva AC/DT/F/AFT/F2/X/FT files")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("PD_Tool")]
|
||||
[assembly: AssemblyCopyright("Copyright korenkonder © 2017-2019")]
|
||||
[assembly: AssemblyCopyright("korenkonder © 2017-2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
|
||||
[assembly: AssemblyVersion("0.4.5.10")]
|
||||
[assembly: AssemblyFileVersion("0.4.5.10")]
|
||||
[assembly: AssemblyVersion("0.4.7.6")]
|
||||
[assembly: AssemblyFileVersion("0.4.7.6")]
|
||||
|
||||
@@ -8,26 +8,20 @@ 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();
|
||||
if (reader.RI64() != 0x454C494641564944) { reader.C(); return; }
|
||||
reader.C();
|
||||
|
||||
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;
|
||||
}
|
||||
if (reader.RI64() == 0x454C494641564944) { reader.C(); return; }
|
||||
reader.C();
|
||||
|
||||
System.Console.Title = "DIVAFILE Encrypt: " + Path.GetFileName(file);
|
||||
file.Encrypt();
|
||||
}
|
||||
}
|
||||
|
||||
+13
-14
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using KKdMainLib;
|
||||
using DB = KKdMainLib.DB;
|
||||
|
||||
namespace PD_Tool
|
||||
@@ -11,16 +10,16 @@ namespace PD_Tool
|
||||
{
|
||||
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);
|
||||
@@ -32,7 +31,7 @@ namespace PD_Tool
|
||||
{
|
||||
Console.Title = "Auth DB Converter";
|
||||
DB.Auth Auth;
|
||||
Main.Choose(1, "bin", out string[] FileNames);
|
||||
Program.Choose(1, "bin", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
@@ -62,7 +61,7 @@ namespace PD_Tool
|
||||
{
|
||||
Console.Title = "AET DB Converter";
|
||||
DB.Aet Aet;
|
||||
Main.Choose(1, "bin", out string[] FileNames);
|
||||
Program.Choose(1, "bin", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
@@ -92,7 +91,7 @@ namespace PD_Tool
|
||||
{
|
||||
Console.Title = "SPR DB Converter";
|
||||
DB.Spr Spr;
|
||||
Main.Choose(1, "bin", out string[] FileNames);
|
||||
Program.Choose(1, "bin", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
+44
-23
@@ -14,39 +14,60 @@ namespace PD_Tool
|
||||
if (Extract)
|
||||
{
|
||||
Console.Title = "FARC Extractor";
|
||||
Main.Choose(1, "farc", out string[] FileNames);
|
||||
foreach (string FileName in FileNames)
|
||||
if (FileName != "" && File.Exists(FileName))
|
||||
FARC.UnPack(FileName);
|
||||
Program.Choose(1, "farc", out string[] FileNames);
|
||||
foreach (string file in FileNames)
|
||||
if (file != "" && File.Exists(file))
|
||||
{
|
||||
Console.Title = "FARC Extractor: " + Path.GetFileNameWithoutExtension(file);
|
||||
new KKdFARC(file).UnPack();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string file = Main.Choose(2, "", out string[] FileNames);
|
||||
string file = Program.Choose(2, "", out string[] FileNames);
|
||||
Console.Clear();
|
||||
Console.Title = "FARC Creator";
|
||||
if (file != "")
|
||||
{
|
||||
Main.ConsoleDesign(true);
|
||||
Main.ConsoleDesign(" Choose type of created FARC:");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("1. FArc [DT/DT2nd/DTex/F/F2nd/X]");
|
||||
Main.ConsoleDesign("2. FArC [DT/DT2nd/DTex/F/F2nd/X] (Compressed)");
|
||||
Main.ConsoleDesign("3. FARC [F/F2nd/X] (Compressed)");
|
||||
Main.ConsoleDesign("4. FARC [FT] (Compressed)");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("Note: Creating FT FARCs currently not supported.");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign(true);
|
||||
Console.Title = "FARC Creator: " + Path.GetDirectoryName(file);
|
||||
FARC = new KKdFARC();
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of created FARC:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. FArc [DT/DT2/DTex/F/F2/X]");
|
||||
Program.ConsoleDesign("2. FArC [DT/DT2/DTex/F/F2/X] (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();
|
||||
int.TryParse(Console.ReadLine(), out int type);
|
||||
if (type == 1) FARC.Signature = KKdFARC.Farc.FArc;
|
||||
else if (type == 3) FARC.Signature = KKdFARC.Farc.FARC;
|
||||
else FARC.Signature = KKdFARC.Farc.FArC;
|
||||
Console.Clear();
|
||||
Console.Title = "FARC Creator - Directory: " + Path.GetDirectoryName(file);
|
||||
FARC.Pack(file);
|
||||
string type = Console.ReadLine().ToUpper();
|
||||
if (type == "1") FARC.Signature = KKdFARC.Farc.FArc;
|
||||
else if (type == "3" || type == "4")
|
||||
{
|
||||
FARC.Signature = KKdFARC.Farc.FARC;
|
||||
|
||||
Console.WriteLine();
|
||||
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();
|
||||
type = Console.ReadLine();
|
||||
if (type == "2" || type == "4") FARC.FARCType |= KKdFARC.Type.GZip;
|
||||
if (type == "3" || type == "4") FARC.FARCType |= KKdFARC.Type.ECB ;
|
||||
}
|
||||
else if (type == "R") return;
|
||||
else FARC.Signature = KKdFARC.Farc.FArC;
|
||||
new KKdFARC(file, true).Pack(FARC.Signature);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdA3DA = KKdMainLib.A3DA.A3DA;
|
||||
using KKdA3DA = KKdMainLib.A3DA;
|
||||
using KKdFARC = KKdMainLib.FARC;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
{
|
||||
@@ -10,42 +11,46 @@ namespace PD_Tool.Tools
|
||||
public static void Processor(bool JSON)
|
||||
{
|
||||
Console.Title = "A3DA Converter";
|
||||
Main.Choose(1, "a3da", out string[] FileNames);
|
||||
Program.Choose(1, "a3da", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
bool MP = true;
|
||||
bool MP = false;
|
||||
foreach (string file in FileNames)
|
||||
if (file.EndsWith(".mp" )) { MP = false; break; }
|
||||
if (file.EndsWith(".mp") || file.EndsWith(".json") || file.EndsWith(".farc")) { MP = true; break; }
|
||||
|
||||
Main.Format Format = Main.Format.NULL;
|
||||
if (!MP)
|
||||
Format Format = 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. DT PS3");
|
||||
Main.ConsoleDesign("2. F PS3/PSV");
|
||||
Main.ConsoleDesign("3. FT PS4");
|
||||
Main.ConsoleDesign("4. F2nd PS3/PSV");
|
||||
Main.ConsoleDesign("5. MGF PSV");
|
||||
Main.ConsoleDesign("6. X PS4/PSV");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign(true);
|
||||
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();
|
||||
string 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.F2LE;
|
||||
else if (format == "5") Format = Main.Format.MGF ;
|
||||
else if (format == "6") Format = Main.Format.X ;
|
||||
format = Console.ReadLine();
|
||||
if (format == "1") Format = Format.DT ;
|
||||
else if (format == "2") Format = Format.F ;
|
||||
else if (format == "3") Format = Format.FT ;
|
||||
else if (format == "4") Format = Format.FT ;
|
||||
else if (format == "5") Format = Format.F2LE;
|
||||
else if (format == "6") Format = Format.MGF ;
|
||||
else if (format == "7") Format = Format.X ;
|
||||
else return;
|
||||
}
|
||||
|
||||
KKdA3DA A;
|
||||
int state;
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
A = new KKdA3DA();
|
||||
@@ -54,23 +59,43 @@ namespace PD_Tool.Tools
|
||||
ext = ext.ToLower();
|
||||
|
||||
Console.Title = "A3DA Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".a3da")
|
||||
if (ext == ".farc")
|
||||
using (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.Data._.CompressF16 = Format > Format.FT ? Format == Format.MGF ? 2 : 1 : 0;
|
||||
A.Head.Format = Format;
|
||||
FARC.Files[i].Data = (format != "1" && format != "3") ? A.A3DCWriter() : A.A3DAWriter();
|
||||
}
|
||||
}
|
||||
FARC.Save();
|
||||
}
|
||||
else if (ext == ".a3da")
|
||||
{
|
||||
A.A3DAReader (filepath);
|
||||
A.MsgPackWriter(filepath, JSON);
|
||||
state = A.A3DAReader(filepath);
|
||||
if (state == 1) A.MsgPackWriter(filepath, JSON);
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
{
|
||||
A.MsgPackReader(filepath, ext == ".json");
|
||||
A.IO = File.OpenWriter(filepath + ".a3da", true);
|
||||
if (A.Data.Header.Format < Main.Format.F2LE)
|
||||
A.Data._.CompressF16 = Format == Main.Format.MGF ? 2 : 1;
|
||||
A.Data.Header.Format = Format;
|
||||
A.Data._.CompressF16 = Format > Format.FT ? Format == Format.MGF ? 2 : 1 : 0;
|
||||
A.Head.Format = Format;
|
||||
|
||||
if (A.Data.Header.Format > Main.Format.DT && A.Data.Header.Format != Main.Format.FT)
|
||||
A.A3DCWriter(filepath);
|
||||
else
|
||||
A.A3DAWriter();
|
||||
File.WriteAllBytes(filepath + ".a3da", (format != "1" &&
|
||||
format != "3") ? A.A3DCWriter() : A.A3DAWriter());
|
||||
}
|
||||
A = null;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdAet = KKdMainLib.Aet.Aet;
|
||||
|
||||
@@ -11,7 +10,7 @@ namespace PD_Tool.Tools
|
||||
{
|
||||
Console.Title = "AET Converter";
|
||||
KKdAet Aet;
|
||||
Main.Choose(1, "bin", out string[] FileNames);
|
||||
Program.Choose(1, "bin", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.F2;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
{
|
||||
public class BLT
|
||||
{
|
||||
public static void Processor()
|
||||
{
|
||||
Console.Title = "Bloom Converter";
|
||||
Bloom Bloom;
|
||||
Program.Choose(1, "blt", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
Bloom = new Bloom();
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
|
||||
Console.Title = "Bloom Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".blt") { Bloom.BLTReader(filepath); Bloom.TXTWriter(filepath); }
|
||||
//else if (ext == ".txt") { Bloom.TXTReader(filepath); Bloom.BLTWriter(filepath); }
|
||||
Bloom = new Bloom();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.F2;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
{
|
||||
public class CCT
|
||||
{
|
||||
public static void Processor()
|
||||
{
|
||||
Console.Title = "Color Correction Converter";
|
||||
ColorCorrection ColorCorrection;
|
||||
Program.Choose(1, "cct", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
ColorCorrection = new ColorCorrection();
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
|
||||
Console.Title = "Color Correction Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".cct") { ColorCorrection.CCTReader(filepath); ColorCorrection.TXTWriter(filepath); }
|
||||
//else if (ext == ".txt") { ColorCorrection.TXTReader(filepath); ColorCorrection.BLTWriter(filepath); }
|
||||
ColorCorrection = new ColorCorrection();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
-24
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
@@ -9,26 +8,34 @@ namespace PD_Tool.Tools
|
||||
public static void Processor(bool JSON)
|
||||
{
|
||||
Console.Title = "DataBank Converter";
|
||||
Main.Choose(1, "databank", out string[] FileNames);
|
||||
Program.Choose(1, "databank", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
Console.Clear();
|
||||
string format = "";
|
||||
Main.ConsoleDesign(true);
|
||||
Main.ConsoleDesign(" Choose type of exporting file:");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("1. Compact");
|
||||
Main.ConsoleDesign("2. Normal");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
format = Console.ReadLine();
|
||||
bool MP = true;
|
||||
foreach (string file in FileNames)
|
||||
if (file.EndsWith(".mp" )) { MP = false; break; }
|
||||
else if (file.EndsWith(".json")) { MP = false; break; }
|
||||
|
||||
DataBank DB;
|
||||
string format = "1";
|
||||
if (MP)
|
||||
{
|
||||
Console.Clear();
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of exporting file:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. Compact");
|
||||
Program.ConsoleDesign("2. Normal");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
format = Console.ReadLine();
|
||||
}
|
||||
|
||||
uint num2 = (uint)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||||
KKdMainLib.DataBank DB;
|
||||
string[] file_split;
|
||||
int File_Checksum = 0, Get_Checksum;
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
ext = Path.GetExtension(file);
|
||||
@@ -37,25 +44,20 @@ namespace PD_Tool.Tools
|
||||
|
||||
string filename = Path.GetFileNameWithoutExtension(file);
|
||||
file_split = filename.Split('_');
|
||||
DB = new DataBank();
|
||||
if (file_split.Length == 5 && ext == ".dat")
|
||||
DB = new KKdMainLib.DataBank();
|
||||
if (file_split.Length == 5 && ext == ".dat" && MP)
|
||||
{
|
||||
if (!int.TryParse(file_split[3], out File_Checksum)) continue;
|
||||
|
||||
Get_Checksum = DCC.CalculateChecksum(file);
|
||||
if (File_Checksum != Get_Checksum) continue;
|
||||
|
||||
filepath = file.Replace(filename + ".dat", "");
|
||||
Console.Title = "DataBank Converter: " + filename;
|
||||
DB. DBReader(file);
|
||||
DB.MsgPackWriter(filepath + file_split[0] + "_" +
|
||||
file_split[1] + "_" + file_split[2], JSON, format != "2");
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
else if ((ext == ".mp" || ext == ".json") && !MP)
|
||||
{
|
||||
Console.Title = "DataBank Converter: " + filename;
|
||||
DB.MsgPackReader(filepath, JSON);
|
||||
DB. DBWriter(filepath);
|
||||
DB. DBWriter(filepath, num2);
|
||||
}
|
||||
DB = null;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdDEX = KKdMainLib.DEX;
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace PD_Tool.Tools
|
||||
{
|
||||
Console.Title = "DEX Converter";
|
||||
KKdDEX DEX;
|
||||
Main.Choose(1, "dex", out string[] FileNames);
|
||||
Program.Choose(1, "dex", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
@@ -26,26 +26,27 @@ namespace PD_Tool.Tools
|
||||
|
||||
Console.Clear();
|
||||
string format = "";
|
||||
Main.ConsoleDesign(true);
|
||||
Main.ConsoleDesign(" Choose type of exporting file:");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("1. F/FT PS3/PS4/PSVita");
|
||||
Main.ConsoleDesign("2. F2nd PS3/PSVita");
|
||||
Main.ConsoleDesign("3. X PS4/PSVita");
|
||||
if ( MP && !JSON) Main.ConsoleDesign("9. MessagePack");
|
||||
if (_JSON && JSON) Main.ConsoleDesign("9. JSON");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign(true);
|
||||
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();
|
||||
format = Console.ReadLine();
|
||||
|
||||
Main.Format Format = Main.Format.NULL;
|
||||
if (format == "1") Format = Main.Format.F ;
|
||||
else if (format == "2") Format = Main.Format.F2LE;
|
||||
else if (format == "3") Format = Main.Format.X ;
|
||||
else if (format == "9" && (MP && _JSON)) Format = Main.Format.NULL;
|
||||
Format Format = Format.NULL;
|
||||
if (format == "1") Format = Format.F ;
|
||||
else if (format == "2") Format = Format.F2LE;
|
||||
else if (format == "3") Format = Format.X ;
|
||||
else if (format == "9" && (MP && _JSON)) Format = Format.NULL;
|
||||
else return;
|
||||
|
||||
int state;
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
DEX = new KKdDEX();
|
||||
@@ -55,12 +56,15 @@ namespace PD_Tool.Tools
|
||||
|
||||
Console.Title = "DEX Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".bin" || ext == ".dex")
|
||||
DEX. DEXReader(filepath, ext );
|
||||
else DEX.MsgPackReader(filepath, JSON);
|
||||
state = DEX. DEXReader(filepath, ext );
|
||||
else state = DEX.MsgPackReader(filepath, JSON);
|
||||
|
||||
if (Format > Main.Format.NULL)
|
||||
DEX. DEXWriter(filepath, Format);
|
||||
else DEX.MsgPackWriter(filepath, JSON );
|
||||
if (state == 1)
|
||||
{
|
||||
if (Format > Format.NULL)
|
||||
DEX. DEXWriter(filepath, Format);
|
||||
else DEX.MsgPackWriter(filepath, JSON);
|
||||
}
|
||||
DEX = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.F2;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
{
|
||||
public class DFT
|
||||
{
|
||||
public static void Processor()
|
||||
{
|
||||
Console.Title = "DOF Converter";
|
||||
DOF DOF;
|
||||
Program.Choose(1, "dft", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
DOF = new DOF();
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
|
||||
Console.Title = "DOF Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".dft") { DOF.DFTReader(filepath); DOF.TXTWriter(filepath); }
|
||||
//else if (ext == ".txt") { DOF.TXTReader(filepath); DOF.DFTWriter(filepath); }
|
||||
DOF = new DOF();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using KKdMainLib;
|
||||
using KKdSoundLib;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
@@ -10,7 +9,7 @@ namespace PD_Tool.Tools
|
||||
public static void Processor()
|
||||
{
|
||||
Console.Title = "DIVA Converter";
|
||||
Main.Choose(1, "diva", out string[] FileNames);
|
||||
Program.Choose(1, "diva", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.F2;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
{
|
||||
public class LIT
|
||||
{
|
||||
public static void Processor()
|
||||
{
|
||||
Console.Title = "Light Converter";
|
||||
Light LIT;
|
||||
Program.Choose(1, "lit", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
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); }
|
||||
LIT = new Light();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
{
|
||||
public class MOT
|
||||
{
|
||||
public static void Processor(bool JSON)
|
||||
{
|
||||
Console.Title = "MOT Converter";
|
||||
Mot Mot;
|
||||
Program.Choose(1, "bin", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
|
||||
foreach (string file in FileNames)
|
||||
{
|
||||
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);
|
||||
}
|
||||
Mot = new Mot();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdSTR = KKdMainLib.STR;
|
||||
|
||||
@@ -10,7 +9,7 @@ namespace PD_Tool.Tools
|
||||
public static void Processor(bool JSON)
|
||||
{
|
||||
Console.Title = "STR Converter";
|
||||
Main.Choose(1, "str", out string[] FileNames);
|
||||
Program.Choose(1, "str", out string[] FileNames);
|
||||
|
||||
KKdSTR Data;
|
||||
string filepath = "";
|
||||
@@ -29,9 +28,9 @@ namespace PD_Tool.Tools
|
||||
Data.STRReader (filepath, ext);
|
||||
Data.MsgPackWriter(filepath, JSON);
|
||||
}
|
||||
else if (ext == ".mp")
|
||||
else if (ext == ".json" || ext == ".mp")
|
||||
{
|
||||
Data.MsgPackReader(filepath, JSON);
|
||||
Data.MsgPackReader(filepath, ext == ".json");
|
||||
Data.STRWriter (filepath);
|
||||
}
|
||||
Data = null;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using KKdMainLib;
|
||||
using KKdVAG = KKdSoundLib.VAG;
|
||||
|
||||
namespace PD_Tool.Tools
|
||||
@@ -10,7 +9,7 @@ namespace PD_Tool.Tools
|
||||
public static void Processor()
|
||||
{
|
||||
Console.Title = "VAG Converter";
|
||||
Main.Choose(1, "vag", out string[] FileNames);
|
||||
Program.Choose(1, "vag", out string[] FileNames);
|
||||
if (FileNames.Length < 1) return;
|
||||
string filepath = "";
|
||||
string ext = "";
|
||||
@@ -24,13 +23,13 @@ namespace PD_Tool.Tools
|
||||
if (InputWAV)
|
||||
{
|
||||
Console.Clear();
|
||||
Main.ConsoleDesign(true);
|
||||
Main.ConsoleDesign(" Choose type of format to export:");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign("1. VAG (Downmix to 1 ch)");
|
||||
Main.ConsoleDesign("2. HEVAG");
|
||||
Main.ConsoleDesign(false);
|
||||
Main.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of format to export:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. VAG (Downmix to 1 ch)");
|
||||
Program.ConsoleDesign("2. HEVAG");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
string format = Console.ReadLine();
|
||||
HE_VAG = format == "2";
|
||||
|
||||
Reference in New Issue
Block a user