Compare commits

..
1 Commits
Author SHA1 Message Date
Kuji Kitamura e35116b894 Release v0.4.7.6
A3DA, AET, DCC, DIVAFILE, MOT
2019-10-27 16:41:04 +03:00
80 changed files with 5799 additions and 6463 deletions
-1
View File
@@ -1,6 +1,5 @@
.vs
build
packages
KKdBaseLib/bin
KKdBaseLib/obj
KKdMainLib/bin
+36 -43
View File
@@ -7,7 +7,7 @@
public string[] ObjectHRCList;
public string[] MObjectHRCList;
public _ _;
public DOF? DOF;
public DOF DOF;
public Fog[] Fog;
public Curve[] Curve;
public Event[] Event;
@@ -18,11 +18,11 @@
public CameraRoot[] CameraRoot;
public MObjectHRC[] MObjectHRC;
public PlayControl PlayControl;
public PostProcess? PostProcess;
public PostProcess PostProcess;
public MaterialList[] MaterialList;
public ModelTransform[] Chara;
public ModelTransform[] Point;
public CameraAuxiliary? CameraAuxiliary;
public CameraAuxiliary CameraAuxiliary;
}
public struct _
@@ -74,7 +74,7 @@
public Key CV;
}
public struct DOF
public class DOF
{
public string Name;
public ModelTransform MT;
@@ -102,22 +102,6 @@
public Vector4<Key> Diffuse;
}
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 struct Key
{
public KeyType? Type;
@@ -138,20 +122,34 @@
public string[] ValueList;
}
public static Vector3<A3DAKey> ToA3DAKey(Vector3<Key> k) =>
new Vector3<A3DAKey> { X = (A3DAKey)k.X, Y = (A3DAKey)k.Y, Z = (A3DAKey)k.Z };
public static Vector3<Key> ToKey(Vector3<A3DAKey> k) =>
new Vector3<Key> { X = (Key)k.X, Y = (Key)k.Y, Z = (Key)k.Z };
public enum KeyType : int
{
Null = 0,
Value = 1,
Lerp = 2,
Hermite = 3,
Hold = 4,
}
public static explicit operator Key(A3DAKey k)
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 = k.EPTypePost;
key.EPTypePre = k.EPTypePre;
key.EPTypePost = (EPType)(int)k.EPTypePost;
key.EPTypePre = (EPType)(int)k.EPTypePre;
key.Max = k.MaxFrames;
if (k.Length > 1)
{
key.Type = k.Type;
key.Type = (KeyType)(int)k.Type;
key.Length = k.Length;
key.Keys = k.Keys;
}
@@ -163,34 +161,29 @@
return key;
}
public static explicit operator A3DAKey(Key k)
public static implicit operator A3DAKey(Key k)
{
A3DAKey key = default;
key.EPTypePost = k.EPTypePost;
key.EPTypePre = k.EPTypePre;
key.EPTypePost = (A3DAKey.EPType)(int)k.EPTypePost;
key.EPTypePre = (A3DAKey.EPType)(int)k.EPTypePre;
key.MaxFrames = k.Max ?? 0;
if (k.Type != null && k.Length > 1)
if (k.Length > 1)
{
key.Type = k.Type.Value;
key.Type = (A3DAKey.KeyType)(int)k.Type;
key.Length = k.Length;
key.Keys = k.Keys;
key.FrameDelta = k.Keys[k.Length - 1].F - k.Keys[0].F;
key.ValueDelta = k.Keys[k.Length - 1].V - k.Keys[0].V;
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 (k.Length == 1)
if (key.Length == 1)
{
key.Type = KeyType.Value;
key.Type = A3DAKey.KeyType.Value;
key.Keys[0].V = k.Value ?? 0;
}
else if (k.Type.HasValue && k.Value.HasValue)
{
key.Type = k.Type.Value;
key.Keys[0].V = k.Value.Value;
}
}
return key;
}
@@ -300,7 +293,7 @@
public float? Size;
}
public struct PostProcess
public class PostProcess
{
public Key LensFlare;
public Key LensGhost;
+19 -5
View File
@@ -1,6 +1,4 @@
using KKdBaseLib.A3DA;
namespace KKdBaseLib
namespace KKdBaseLib
{
public struct A3DAKey
{
@@ -9,8 +7,8 @@ namespace KKdBaseLib
public float MaxFrames;
public EPType EPTypePre;
public EPType EPTypePost;
public float FrameDelta;
public float ValueDelta;
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;
@@ -24,5 +22,21 @@ namespace KKdBaseLib
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,
}
}
}
+47 -46
View File
@@ -9,51 +9,49 @@
{
public Pointer<string> Name;
public float StartFrame;
public float EndFrame;
public float FrameDuration;
public float FrameRate;
public uint BackColor;
public uint Width;
public uint Height;
public Pointer<Vector2<CountPointer<KFT2>>> Camera;
public CountPointer<AetComposition > Compositions ;
public CountPointer<AetSurface> Surfaces;
public CountPointer<AetSoundEffect > SoundEffects ;
public Pointer<Vector2<CountPointer<KFT2>>> Position;
public CountPointer<AetLayer > Layers ;
public CountPointer<AetRegion> Regions;
public CountPointer<AetSound > Sounds ;
}
public struct AetComposition
public struct AetLayer
{
public int P;
public int Pointer;
public int C { get => E != null ? E.Length : 0;
set => E = value > -1 ? new AetLayer[value] : null; }
set => E = value > -1 ? new AetObject[value] : null; }
public int O;
public AetLayer[] E;
public AetObject[] E;
public override string ToString() => "Count: " + C;
}
public struct AetLayer
public struct AetObject
{
public int ID;
public int Offset;
public Pointer<string> Name;
public float LoopStart;
public float LoopEnd;
public float StartFrame;
public float EndFrame;
public float StartOffset;
public float PlaybackSpeed;
public AetLayerFlags Flags;
public AetObjFlags Flags;
public byte Pad;
public AetLayerType Type;
public int DataOffset;
public int ParentLayer;
public CountPointer<AetMarker> Marker;
public Pointer<AnimationData> Data;
public Pointer<AudioData> ExtraData;
public AetObjType Type;
public int DataID;
public int ParentObjectID;
public CountPointer<Marker> Marker;
public Pointer<AnimationData> Data;
public Pointer<AetObjExtraData> ExtraData;
public enum AetLayerFlags : ushort
public enum AetObjFlags : ushort
{
Visible = 0b0000000000000001,
Audible = 0b0000000000000010,
@@ -73,7 +71,7 @@
Unk15 = 0b1000000000000000,
}
public enum AetLayerType : byte
public enum AetObjType : byte
{
Nop = 0,
Pic = 1,
@@ -81,12 +79,20 @@
Eff = 3,
}
public override string ToString() => $"ID: {ID}; Name: {Name.V}; Type: {Type}" +
( DataID > -1 ? $"; " + $"Data ID: { DataID}" : "") +
(ParentLayer > -1 ? $"; Parent Object ID: {ParentLayer}" : "");
}
public struct AetObjExtraData
{
public CountPointer<KFT2> Unk0;
public CountPointer<KFT2> Unk1;
public CountPointer<KFT2> Unk2;
public CountPointer<KFT2> Unk3;
}
public struct AetMarker
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;
@@ -106,7 +112,7 @@
public CountPointer<KFT2> ScaleX;
public CountPointer<KFT2> ScaleY;
public CountPointer<KFT2> Opacity;
public Pointer<Perspective> Persp;
public Pointer<ThirdDimension> _3D;
public enum BlendMode : byte
{
@@ -116,8 +122,8 @@
SrcAlphaOneMinusSrcColor = 7,
Transparent = 8,
}
public struct Perspective
public struct ThirdDimension
{
public CountPointer<KFT2> Unk1 ;
public CountPointer<KFT2> Unk2 ;
@@ -130,27 +136,19 @@
}
}
public struct AudioData
public struct AetRegion
{
public CountPointer<KFT2> Data0;
public CountPointer<KFT2> Data1;
public CountPointer<KFT2> Data2;
public CountPointer<KFT2> Data3;
}
public struct AetSurface
{
public int O;
public int Offset;
public uint Color;
public ushort Width;
public ushort Height;
public float Frames;
public CountPointer<AetSpriteIdentifier> Sprites;
public CountPointer<Sprite> Sprites;
public override string ToString() => $"Width: {Width}; Height: {Height}; Color: {Color.ToString("X2")}";
}
public struct AetSpriteIdentifier
public struct Sprite
{
public Pointer<string> Name;
public uint ID;
@@ -158,9 +156,12 @@
public override string ToString() => $"ID: {ID}; Name: {Name}";
}
public struct AetSoundEffect
public struct AetSound
{
public int O;
public uint Unk;
public int Offset;
public uint Unk0;
public uint Unk1;
public uint Unk2;
public uint Unk3;
}
}
+154 -145
View File
@@ -70,195 +70,204 @@ namespace KKdBaseLib
public static float Pow (this float x , float y ) => (float)Math.Pow (x , y );
public static float Round(this float val , int d ) => (float)Math.Round(val , d );
public static void FC( ref double Value) =>
Value = Value % 1 >= 0.5 ? (long)(Value + 0.5) : (long)Value;
public static void FloorCeiling( ref double Value) =>
Value = Value % 1 >= 0.5 ? (long)(Value + 0.5) : (long) Value;
public static long FC(this double Value) =>
Value % 1 >= 0.5 ? (long)(Value + 0.5) : (long)Value;
public static long FloorCeiling(this double Value) =>
Value % 1 >= 0.5 ? (long)(Value + 0.5) : (long) Value;
public static int A(this int value, int alignement, int divide = 1) =>
public static int Align(this int value, int alignement, int divide = 1) =>
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
public static uint A(this uint value, uint alignement, uint divide = 1) =>
public static uint Align(this uint value, uint alignement, uint divide = 1) =>
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
public static long A(this long value, long alignement, long divide = 1) =>
public static long Align(this long value, long alignement, long divide = 1) =>
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
public static ulong A(this ulong value, ulong alignement, ulong divide = 1) =>
public static ulong Align(this ulong value, ulong alignement, ulong divide = 1) =>
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
private static byte[] buf = new byte[8];
public static byte[] 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 byte[] E(this byte[] le, byte len)
{ for (byte i = 0; i < len; i++) buf[i] = le[i];
for (byte i = 0; i < len; i++) le[len - i - 1] = buf[i]; return le; }
public static byte[] E(this byte[] le, byte len, bool isBE)
{ if (isBE) { for (byte i = 0; i < len; i++) buf[i] = le[i];
for (byte i = 0; i < len; i++) le[len - i - 1] = buf[i]; } return le; }
public static short E(this short le, bool isBE)
{ if (isBE) { for (byte i = 0; i < 2; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
for (byte i = 0; i < 2; i++) { le = (short)((int)le |
buf[i]); if (i < 1) le <<= 8; } } return le; }
public static ushort E(this ushort le, bool isBE)
{ if (isBE) { for (byte i = 0; i < 2; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
for (byte i = 0; i < 2; i++) { le |= buf[i]; if (i < 1) le <<= 8; } } return le; }
public static int E(this int le, bool isBE)
{ if (isBE) { for (byte i = 0; i < 4; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
for (byte i = 0; i < 4; i++) { le |= buf[i]; if (i < 3) le <<= 8; } } return le; }
public static uint E(this uint le, bool isBE)
{ if (isBE) { for (byte i = 0; i < 4; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
for (byte i = 0; i < 4; i++) { le |= buf[i]; if (i < 3) le <<= 8; } } return le; }
public static long E(this long le, bool isBE)
{ if (isBE) { for (byte i = 0; i < 8; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
for (byte i = 0; i < 8; i++) { le |= buf[i]; if (i < 7) le <<= 8; } } return le; }
public static ulong E(this ulong le, bool isBE)
{ if (isBE) { for (byte i = 0; i < 8; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
for (byte i = 0; i < 8; i++) { le |= buf[i]; if (i < 7) le <<= 8; } } return le; }
public static short 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 short TI16(this byte[] arr)
{ short val; fixed (byte* ptr = arr) val = *( short*)ptr; return val; }
public static ushort TU16(this byte[] arr)
{ ushort val; fixed (byte* ptr = arr) val = *(ushort*)ptr; return val; }
public static int TI32(this byte[] arr)
{ int val; fixed (byte* ptr = arr) val = *( int*)ptr; return val; }
public static uint TU32(this byte[] arr)
{ uint val; fixed (byte* ptr = arr) val = *( uint*)ptr; return val; }
public static long TI64(this byte[] arr)
{ long val; fixed (byte* ptr = arr) val = *( long*)ptr; return val; }
public static ulong TU64(this byte[] arr)
{ ulong val; fixed (byte* ptr = arr) val = *( ulong*)ptr; return val; }
public static float TF32(this byte[] arr)
{ float val; fixed (byte* ptr = arr) val = *( float*)ptr; return val; }
public static double TF64(this byte[] arr)
{ double val; fixed (byte* ptr = arr) val = *(double*)ptr; return val; }
public static 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 void GBy(this byte[] arr, short val)
{ fixed (byte* ptr = arr) *( short*)ptr = val; }
public static void GBy(this byte[] arr, ushort val)
{ fixed (byte* ptr = arr) *(ushort*)ptr = val; }
public static void GBy(this byte[] arr, int val)
{ fixed (byte* ptr = arr) *( int*)ptr = val; }
public static void GBy(this byte[] arr, uint val)
{ fixed (byte* ptr = arr) *( uint*)ptr = val; }
public static void GBy(this byte[] arr, long val)
{ fixed (byte* ptr = arr) *( long*)ptr = val; }
public static void GBy(this byte[] arr, ulong val)
{ fixed (byte* ptr = arr) *( ulong*)ptr = val; }
public static void GBy(this byte[] arr, float val)
{ fixed (byte* ptr = arr) *( float*)ptr = val; }
public static void GBy(this byte[] arr, double val)
{ fixed (byte* ptr = arr) *(double*)ptr = val; }
public static 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); }
{ 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); }
{ 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); }
{ 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); }
{ 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); }
{ 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); }
{ 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); }
{ 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); }
{ 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); }
{ 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); }
{ 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); }
{ 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); }
{ 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); }
{ 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); }
{ c = c.Round(); return ( uint)(c > 0xFFFFFFFF ? 0xFFFFFFFF : c < 0xFFFFFFFF ? 0x00000000 : c); }
public static int ToI32(this float f) => *( int*)&f;
public static uint ToU32(this float f) => *( uint*)&f;
public static long ToI64(this double f) => *( long*)&f;
public static ulong ToU64(this double f) => *(ulong*)&f;
public static 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 ToF32(this int i) => *( float*)&i;
public static float ToF32(this uint i) => *( float*)&i;
public static double ToF64(this long i) => *(double*)&i;
public static double ToF64(this ulong i) => *(double*)&i;
public static 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 string ToString(this int d, bool BE) =>
BitConverter.GetBytes(d.E(BE)).ToASCII();
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 string ToS(this object d)
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 ToS(f32);
else if (d is double f64 ) return ToS(f64);
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 ToS(this bool? d) => (d ?? default).ToString();
public static string ToS(this bool d) => d.ToString().ToLower();
public static string ToS(this sbyte? d) => (d ?? default).ToString();
public static string ToS(this sbyte d) => d.ToString();
public static string ToS(this byte? d) => (d ?? default).ToString();
public static string ToS(this byte d) => d.ToString();
public static string ToS(this short? d) => (d ?? default).ToString();
public static string ToS(this short d) => d.ToString();
public static string ToS(this ushort? d) => (d ?? default).ToString();
public static string ToS(this ushort d) => d.ToString();
public static string ToS(this int? d) => (d ?? default).ToString();
public static string ToS(this int d) => d.ToString();
public static string ToS(this uint? d) => (d ?? default).ToString();
public static string ToS(this uint d) => d.ToString();
public static string ToS(this long? d) => (d ?? default).ToString();
public static string ToS(this long d) => d.ToString();
public static string ToS(this ulong? d) => (d ?? default).ToString();
public static string ToS(this ulong d) => d.ToString();
public static string ToS(this float? d, int round) => (d ?? default).ToS(round);
public static string ToS(this float? d) => (d ?? default).ToString();
public static string ToS(this float d, int round) =>
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 ToS(this float d) =>
Math.Round(d, 15).ToString().ToLower().Replace(NumberDecimalSeparator, ".");
public static string ToS(this double? d, int round) => (d ?? default).ToS(round);
public static string ToS(this double? d) => (d ?? default).ToString();
public static string ToS(this double d, int round) =>
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 ToS(this double d) =>
Math.Round(d, 15).ToString().ToLower().Replace(NumberDecimalSeparator, ".");
public static float ToF32(this string s) =>
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 ToF32(this string s, out float value) =>
public static bool ToSingle(this string s, out float value) =>
float.TryParse(s.Replace(".", NumberDecimalSeparator), out value);
public static double ToF64(this string s) =>
public static double ToDouble(this string s) =>
double. Parse(s.Replace(".", NumberDecimalSeparator));
public static bool ToF64(this string s, out double value) =>
public static bool ToDouble(this string s, out double value) =>
double.TryParse(s.Replace(".", NumberDecimalSeparator), out value);
public static bool ToF32(this string s, out float? value)
{ bool Val = ToF32(s, out float val); value = val; return Val; }
public static bool ToF64(this string s, out double? value)
{ bool Val = ToF64(s, out double val); value = val; return Val; }
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(); } }
}
}
+125 -129
View File
@@ -1,90 +1,89 @@
namespace KKdBaseLib.F2
{
public struct ENRS : INull
public unsafe struct ENRSList : INull
{
public ENRSEntry[] Array;
public int Depth;
public KKdList<ENRS> List;
public int Length => length();
public bool IsNull => Array == null;
public bool NotNull => Array != null;
public bool IsNull => List. IsNull;
public bool NotNull => List.NotNull;
public unsafe void Read(byte[] data)
public static ENRSList Read(byte[] data, int Depth = 0)
{
if (data == null || data.Length < 0x10) return;
fixed (byte* ptr = data)
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++)
{
int i, i0;
int ENRSCount = ((int*)ptr)[1];
ENRSEntry enrsEntry;
ENRSEntry.SubENRSEntry sub;
Array = new ENRSEntry[ENRSCount];
ENR = default;
ENR.Offset = ReadENRSValue(ref ptr);
ENR.Count = ReadENRSValue(ref ptr);
ENR.Size = ReadENRSValue(ref ptr);
ENR.Repeat = ReadENRSValue(ref ptr);
byte* localPtr = ptr + 0x10;
for (i = 0; i < ENRSCount; i++)
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++)
{
enrsEntry = default;
enrsEntry.Offset = ReadENRSValue(ref localPtr);
enrsEntry.Count = ReadENRSValue(ref localPtr);
enrsEntry.Size = ReadENRSValue(ref localPtr);
enrsEntry.Repeat = ReadENRSValue(ref localPtr);
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 (i > 0) enrsEntry.Offset += Array[i - 1].Offset;
if (enrsEntry.Repeat < 1) { enrsEntry.Sub = null; Array[i] = enrsEntry; continue; }
enrsEntry.Sub = new ENRSEntry.SubENRSEntry[enrsEntry.Count];
for (i0 = 0; i0 < enrsEntry.Count; i0++)
{
sub = default;
sub.Skip = ReadENRSValue(ref localPtr, out sub.Type);
sub.Reverse = ReadENRSValue(ref localPtr);
if (i0 > 0) sub.Skip += enrsEntry.Sub[i0 - 1].SizeSkip;
enrsEntry.Sub[i0] = sub;
if (enrsEntry.Sub[i0].Type == ENRSEntry.Type.Invalid) { Array = null; return; }
}
Array[i] = enrsEntry;
if (ENR.Sub[i0].Type == ENRS.Type.Invalid) return default;
}
List.Add(ENR);
}
return new ENRSList { Depth = Depth, List = List };
}
public unsafe byte[] Write()
public static byte[] Write(ENRSList ENRS)
{
int i, i0;
byte[] data;
byte* ptr;
if (IsNull || Array.Length < 1) return new byte[0x20];
KKdList<ENRS> List = (System.Collections.Generic.List<ENRS>)ENRS.List;
if (ENRS.IsNull || ENRS.List.Count < 1) return new byte[0x20];
data = new byte[Length];
fixed (byte* ptr = data)
data = new byte[ENRS.Length];
ptr = data.GetPtr();
((int*)ptr)[1] = ENRS.List.Count;
ptr += 0x10;
for (i = 0; i < ENRS.List.Count; i++)
{
((int*)ptr)[1] = Array.Length;
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);
byte* localPtr = ptr + 0x10;
for (i = 0; i < Array.Length; i++)
if (ENR.Repeat < 1) continue;
for (i0 = 0; i0 < ENR.Count; i0++)
{
ENRSEntry enrsEntry = Array[i];
WriteENRSValue(ref localPtr, i > 0 ? enrsEntry.Offset -
Array[i - 1].Offset : enrsEntry.Offset);
WriteENRSValue(ref localPtr, enrsEntry.Count > enrsEntry.Sub.Length ?
enrsEntry.Sub.Length : enrsEntry.Count);
WriteENRSValue(ref localPtr, enrsEntry.Size );
WriteENRSValue(ref localPtr, enrsEntry.Repeat);
if (ENR.Sub[i0].Type < ENRSList.ENRS.Type. WORD ||
ENR.Sub[i0].Type > ENRSList.ENRS.Type.QWORD)
return data;
if (enrsEntry.Repeat < 1) continue;
for (i0 = 0; i0 < enrsEntry.Count && i0 < enrsEntry.Sub.Length; i0++)
{
if (enrsEntry.Sub[i0].Type < ENRSEntry.Type. WORD ||
enrsEntry.Sub[i0].Type > ENRSEntry.Type.QWORD)
return data;
WriteENRSValue(ref localPtr, i0 > 0 ? enrsEntry.Sub[i0].Skip -
enrsEntry.Sub[i0 - 1].SizeSkip : enrsEntry.Sub[i0].Skip, enrsEntry.Sub[i0].Type);
WriteENRSValue(ref localPtr, enrsEntry.Sub[i0].Reverse);
}
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;
}
@@ -93,30 +92,29 @@
{
int i, i0;
int length = 0x10;
for (i = 0; i < Array.Length; i++)
for (i = 0; i < List.Count; i++)
{
ENRSEntry enrs = Array[i];
length += GetSize(i > 0 ? enrs.Offset - Array[i - 1].Offset : enrs.Offset);
length += GetSize(enrs.Count );
length += GetSize(enrs.Size );
length += GetSize(enrs.Repeat);
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 (enrs.Repeat < 1) continue;
if (ENR.Repeat < 1) continue;
for (i0 = 0; i0 < enrs.Count; i0++)
for (i0 = 0; i0 < ENR.Count; i0++)
{
if (enrs.Sub[i0].Type < ENRSEntry.Type. WORD ||
enrs.Sub[i0].Type > ENRSEntry.Type.QWORD) return length.A(0x10);
if (ENR.Sub[i0].Type < ENRS.Type. WORD ||
ENR.Sub[i0].Type > ENRS.Type.QWORD) return length.Align(0x10);
length += GetSizeType(i0 > 0 ? enrs.Sub[i0].Skip -
enrs.Sub[i0 - 1].SizeSkip : enrs.Sub[i0].Skip);
length += GetSize(enrs.Sub[i0].Reverse);
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.A(0x10);
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;
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)
@@ -136,84 +134,84 @@
return Sub;
}*/
[System.ThreadStatic] private static ENRSEntry.Value value;
[System.ThreadStatic] private static ENRS.Value Value;
private unsafe static int ReadENRSValue(ref byte* ptr, out ENRSEntry.Type type)
private static int ReadENRSValue(ref byte* ptr, out ENRS.Type Type)
{
int V = *ptr & 0xF;
type = (ENRSEntry. Type)((*ptr & 0x30) >> 4);
value = (ENRSEntry.Value)((*ptr & 0xC0) >> 6);
Type = (ENRS. Type)((*ptr & 0x30) >> 4);
Value = (ENRS.Value)((*ptr & 0xC0) >> 6);
ptr++;
if (value == ENRSEntry.Value.Int32 )
if (Value == ENRS.Value.Int32 )
{ V = (V << 24) | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; ptr += 3; }
else if (value == ENRSEntry.Value.Int16 )
else if (Value == ENRS.Value.Int16 )
{ V = (V << 8) | ptr[0]; ptr += 1; }
else if (value == ENRSEntry.Value.Invalid) V = 0;
else if (Value == ENRS.Value.Invalid) V = 0;
return V;
}
private unsafe static int ReadENRSValue(ref byte* ptr)
private static int ReadENRSValue(ref byte* ptr)
{
int V = *ptr & 0x3F;
value = (ENRSEntry.Value)((*ptr & 0xC0) >> 6);
Value = (ENRS.Value)((*ptr & 0xC0) >> 6);
ptr++;
if (value == ENRSEntry.Value.Int32 )
if (Value == ENRS.Value.Int32 )
{ V = (V << 24) | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; ptr += 3; }
else if (value == ENRSEntry.Value.Int16 )
else if (Value == ENRS.Value.Int16 )
{ V = (V << 8) | ptr[0]; ptr += 1; }
else if (value == ENRSEntry.Value.Invalid) V = 0;
else if (Value == ENRS.Value.Invalid) V = 0;
return V;
}
private unsafe static void WriteENRSValue(ref byte* ptr, int val, ENRSEntry.Type type)
private static void WriteENRSValue(ref byte* ptr, int Val, ENRS.Type Type)
{
value = ENRSEntry.Value.Invalid;
if (val < 0x00000040) value = ENRSEntry.Value.Int8 ;
else if (val < 0x00004000) value = ENRSEntry.Value.Int16;
else if (val < 0x40000000) value = ENRSEntry.Value.Int32;
*ptr = (byte)((((byte)value << 6) & 0xC0) | (((byte)type << 4) & 0x30));
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); }
if (Val < 0x00000010)
{ *ptr |= (byte)( Val & 0x0F); }
else if (Val < 0x00001000)
{ *ptr |= (byte)((Val >> 8) & 0x0F); ptr++;
*ptr = (byte)( Val & 0xFF); }
else if (Val < 0x10000000)
{ *ptr |= (byte)((Val >> 24) & 0x0F); ptr++;
*ptr = (byte)((Val >> 16) & 0xFF); ptr++;
*ptr = (byte)((Val >> 8) & 0xFF); ptr++;
*ptr = (byte)( Val & 0xFF); }
ptr++;
}
private unsafe static void WriteENRSValue(ref byte* ptr, int val)
private static void WriteENRSValue(ref byte* ptr, int Val)
{
value = ENRSEntry.Value.Invalid;
if (val < 0x00000040) value = ENRSEntry.Value.Int8 ;
else if (val < 0x00004000) value = ENRSEntry.Value.Int16;
else if (val < 0x40000000) value = ENRSEntry.Value.Int32;
*ptr = (byte)(((byte)value << 6) & 0xC0);
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); }
if (Val < 0x00000040)
{ *ptr |= (byte)( Val & 0x3F); }
else if (Val < 0x00004000)
{ *ptr |= (byte)((Val >> 8) & 0x3F); ptr++;
*ptr = (byte)( Val & 0xFF); }
else if (Val < 0x40000000)
{ *ptr |= (byte)((Val >> 24) & 0x3F); ptr++;
*ptr = (byte)((Val >> 16) & 0xFF); ptr++;
*ptr = (byte)((Val >> 8) & 0xFF); ptr++;
*ptr = (byte)( Val & 0xFF); }
ptr++;
}
public struct ENRSEntry
public struct ENRS
{
public int Offset;
public int Count;
public int Size;
public int Repeat;
public SubENRSEntry[] Sub;
public KKdList<SubENRS> Sub;
public enum Type : byte
{
@@ -231,7 +229,7 @@
Invalid = 0b11,
}
public struct SubENRSEntry
public struct SubENRS
{
public int Skip;
public int Reverse;
@@ -240,16 +238,14 @@
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() => "Skip: " + Skip + "; Reverse: " + Reverse + "; Type: " + Type;
}
public override string ToString() =>
"Offset: " + Offset + "; Count: " + Count + "; " +
"Size: " + Size + "; Repeat: " + Repeat;
"Offset: " + Offset + "; Count: " + Count + "; " + "Size: " + Size + "; Repeat: " + Repeat;
}
public override string ToString() =>
$"{(NotNull ? $"ENRS Count: {Array.Length}" : "No ENRS")}";
$"Depth: {Depth}{(NotNull ? $"; ENRS Count: {List.Count}" : "")}";
}
}
+59 -62
View File
@@ -1,94 +1,91 @@
namespace KKdBaseLib.F2
{
public struct POF : INull
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).A(0x10);
public int LengthX => length( true).A(0x10);
public int Length => length(false).Align(0x10);
public int LengthX => length( true).Align(0x10);
public unsafe void Read(byte[] data, bool shiftX)
public static POF Read(byte[] data, bool ShiftX, int Depth = 0)
{
Value Val = 0;
Offsets = KKdList<long>.New;
fixed (byte* ptr = data)
{
int i = 0, offset = 0, v = 0;
byte bitShift = (byte)(shiftX ? 3 : 2);
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;
byte* localPtr = ptr + 4;
while (length > i)
{
v = *ptr & 0x3F;
Val = (Value)(*ptr & 0xC0);
localPtr++; i++;
if (Val == Value.Int32 )
{ v = (v << 24) | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; localPtr += 3; i += 3; }
else if (Val == Value.Int16 )
{ v = (v << 8) | ptr[0]; localPtr += 1; i += 3; }
else if (Val == Value.Invalid) break;
offset += v;
Offsets.Add(offset << bitShift);
}
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 unsafe byte[] Write(bool shiftX)
public static byte[] Write(POF POF, bool ShiftX)
{
Offsets.Sort();
long offset = 0;
byte bitShift = (byte)(shiftX ? 3 : 2);
int max1 = 0x00100 >> bitShift;
int max2 = 0x10000 >> bitShift;
POF.Offsets.Sort();
long Offset = 0;
byte BitShift = (byte)(ShiftX ? 3 : 2);
int Max1 = 0x00100 >> BitShift;
int Max2 = 0x10000 >> BitShift;
byte[] data = new byte[length(shiftX)];
fixed (byte* ptr = data)
byte[] 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++)
{
byte Val = 0;
*(int*)ptr = length(shiftX);
byte* localPtr = ptr + 4;
for (int i = 0; i < Offsets.Count; i++)
{
offset = Offsets[i];
if (i > 0) { offset -= Offsets[i - 1]; if (offset == 0) continue; }
Offset = 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) *localPtr = (byte)(Val | offset );
else if (offset < max2) { *localPtr = (byte)(Val | (offset >> 8)); localPtr++;
*localPtr = (byte) offset ; }
else { *localPtr = (byte)(Val | (offset >> 24)); localPtr++;
*localPtr = (byte) (offset >> 16) ; localPtr++;
*localPtr = (byte) (offset >> 8) ; localPtr++;
*localPtr = (byte) offset ; }
localPtr++;
}
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)
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;
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 = 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;
Offset >>= BitShift;
if (Offset < Max1) length += 1;
else if (Offset < Max2) length += 2;
else length += 4;
}
return length;
return length;
}
public enum Value : byte
@@ -100,6 +97,6 @@
}
public override string ToString() =>
$"{(NotNull ? $"Offsets Count: {Offsets.Count}" : "No POF")}";
$"Depth: {Depth}{(NotNull ? $"; Offsets Count: {Offsets.Count}" : "")}";
}
}
+6 -6
View File
@@ -6,9 +6,9 @@
public byte[] Data;
public Struct[] SubStructs;
public ENRS ENRS;
public ENRSList ENRS;
public POF POF;
public int Length => length(false);
public int LengthX => length( true);
@@ -24,19 +24,19 @@
$"{(HasSubStructs ? $"; SubStructs: {SubStructs.Length}" : "")}" +
$"{(HasENRS ? "; Has ENRS" : "")}{(HasPOF ? "; Has POF" : "")}";
private int length(bool shiftX = false)
private int length(bool ShiftX = false)
{
int length = Data != null ? Data.Length : 0;
if (HasPOF ) length += 0x20 + (shiftX ? POF.LengthX : POF.Length);
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 += (ShiftX ? SubStructs[i].LengthX : SubStructs[i].Length) + SubStructs[i].Header.Length;
length += 0x20;
}
return length;
return length;
}
public void Update(bool ShiftX = false)
+1 -2
View File
@@ -8,12 +8,11 @@
DT2 = 3,
DTe = 4,
F = 5,
AFT = 6,
FT = 6,
F2LE = 7,
F2BE = 8,
MGF = 9,
X = 10,
XHD = 11,
FT = 12,
}
}
+8 -9
View File
@@ -28,7 +28,7 @@ namespace KKdBaseLib
return *(float*)&si32;
}
public static unsafe explicit operator Half(float val)
public static unsafe implicit operator Half(float val)
{
int si32 = *(int*)&val;
ushort sign = (ushort)( (si32 >> 16) & 0x8000);
@@ -41,7 +41,7 @@ namespace KKdBaseLib
return new Half { _value = (ushort)(sign | (exponent << 10) | mantissa) };
}
public static unsafe implicit operator double(Half h)
public static unsafe implicit operator double(Half h)
{
int sign = (h._value >> 15) & 0x001;
int exponent = ((h._value >> 10) & 0x01F) + 1023 - 15;
@@ -51,7 +51,7 @@ namespace KKdBaseLib
return *(double*)&si64;
}
public static unsafe explicit operator Half(double val)
public static unsafe implicit operator Half(double val)
{
long si64 = *(long*)&val;
ushort sign = (ushort) ((si64 >> 48) & 0x8000);
@@ -64,11 +64,10 @@ namespace KKdBaseLib
return new Half { _value = (ushort)(sign | (exponent << 10) | mantissa) };
}
public static Half operator - (Half a ) => new Half() { _value = (ushort)(a._value ^ 0x8000) };
public static Half operator + (Half a, Half b) => (Half)((float)a + (float)b);
public static Half operator - (Half a, Half b) => (Half)((float)a - (float)b);
public static Half operator * (Half a, Half b) => (Half)((float)a * (float)b);
public static Half operator / (Half a, Half b) => (Half)((float)a / (float)b);
public static 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;
@@ -80,7 +79,7 @@ namespace KKdBaseLib
public int CompareTo(Half h) => this == h ? 0 : (this > h ? 1 : -1);
public bool Equals(Half other) => this == other;
public override bool Equals(object obj) => base.Equals(obj);
public override string ToString() => Extensions.ToS((double)this);
public 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();
+1 -2
View File
@@ -9,8 +9,7 @@
IKF Check();
string ToString();
string ToString(int round, bool brackets);
string ToString(bool brackets, int round);
string ToString(bool Brackets);
}
public interface INull
+86 -79
View File
@@ -1,4 +1,5 @@
using KKdBaseLib.A3DA;
using Type = KKdBaseLib.A3DAKey.KeyType;
using EPType = KKdBaseLib.A3DAKey.EPType;
namespace KKdBaseLib.Interpolation
{
@@ -6,34 +7,34 @@ namespace KKdBaseLib.Interpolation
{
private A3DAKey key;
private float f;
private float last;
private float df;
private float @if;
private float rf;
private float lastTime;
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; df = @if / rf; } }
{ get => IF; set { IF = value; DeltaFrame = IF / RF; } }
public float RequestedFramerate
{ get => rf; set { rf = value; df = @if / rf; } }
{ get => RF; set { RF = value; DeltaFrame = IF / RF; } }
public float Frame => f;
public float Value => last;
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)
public A3DAI(A3DAKey key, float A3DAFramerate = 60, float RequestedFramerate = 60)
{
lastTime = 0;
this.key = key; last = rf = @if = 0;
f = -1; df = 1;
@if = a3daFramerate;
LastTime = 0;
this.key = key; F = -1; DeltaFrame = Last = RF = IF = 0;
IF = A3DAFramerate;
firstKey = lastKey = default;
RequestedFramerate = requestedFramerate;
this.RequestedFramerate = RequestedFramerate;
F = -DeltaFrame;
ResetFrameCount();
if (key.Keys != null && key.Length > 0)
@@ -48,10 +49,10 @@ namespace KKdBaseLib.Interpolation
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;
LastTime = time;
F = time * IF;
Last = Interpolate(F);
return Last;
}
public float SetFrame(float frame)
@@ -59,10 +60,10 @@ namespace KKdBaseLib.Interpolation
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 * df;
last = Interpolate(f);
return last;
LastTime = frame / RF;
F = frame * DeltaFrame;
Last = Interpolate(F);
return Last;
}
public float NextFrame(float time)
@@ -70,10 +71,10 @@ namespace KKdBaseLib.Interpolation
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;
LastTime += time;
F = LastTime * IF;
Last = Interpolate(F);
return Last;
}
public float NextFrame()
@@ -81,102 +82,108 @@ namespace KKdBaseLib.Interpolation
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 += df;
lastTime = f / @if;
last = Interpolate(f);
return last;
F += DeltaFrame;
LastTime = F / IF;
Last = Interpolate(F);
return Last;
}
private float Interpolate(float frame)
{
float df = 0;
float ep = 0;
float DF = 0;
float EP;
float f = (int)frame;
if (f < firstKey.F)
{
if (key.EPTypePost < EPType.EP_1 || key.EPTypePost > EPType.EP_3)
return firstKey.V;
df = firstKey.F - frame;
if (key.EPTypePre == EPType.EP_1)
return firstKey.V - df * firstKey.T1;
else if (key.EPTypePre == EPType.EP_2 || key.EPTypePre == EPType.EP_3)
DF = firstKey.F - frame;
if (key.EPTypePre == EPType.EP_2 || key.EPTypePre == EPType.EP_3)
{
frame = lastKey.F - df % key.FrameDelta;
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)
{
if (key.EPTypePost < EPType.EP_1 || key.EPTypePost > EPType.EP_3)
return lastKey.V;
df = frame - lastKey.F;
if (key.EPTypePost == EPType.EP_1)
return lastKey.V + df * lastKey.T2;
else if (key.EPTypePost == EPType.EP_2 || key.EPTypePost == EPType.EP_3)
DF = frame - lastKey.F;
if (key.EPTypePost == EPType.EP_2 || key.EPTypePost == EPType.EP_3)
{
frame = firstKey.F + df % key.FrameDelta;
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.FrameDelta;
ep = (ep >= 0 && ep != (int)ep) ? (ep - (int)ep > 0 ? 1 : 0) : ep;
ep = (f < firstKey.F ? -1 : 1) * (ep + 1) * key.ValueDelta;
}
EP = DF / key.FDBSaE;
EP = (EP >= 0 && (int)EP != EP) ? ((int)EP - EP < 0 ? 1 : 0) : EP;
if (f <= firstKey.F)
return firstKey.V + ep;
else if (f >= lastKey.F)
return lastKey.V + 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;
int tempLength;
while (length > 0)
{
tempLength = length >> 1;
if (f <= key.Keys[data + tempLength].F)
length = tempLength;
if (f <= key.Keys[data + (length >> 1)].F)
length >>= 1;
else
{
data += tempLength + 1;
length -= tempLength + 1;
int delta = (length >> 1) + 1;
data += delta;
length -= delta;
}
}
ref KFT3 c = ref key.Keys[data - 1];
ref KFT3 n = ref key.Keys[data];
float result;
if (frame > c.F && frame < n.F)
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 (key.Type == KeyType.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 == KeyType.Hermite)
}
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
}
else if (key.Type == Type.Hold)
{
if (frame < n.F)
result = c.V;
}
else
result = frame > c.F ? n.V : c.V;
return result + ep;
return EP;
return result + EP;
}
public void ResetFrameCount() => f = -df;
public void ResetFrameCount() => F = -DeltaFrame;
public override string ToString() => $"Frame: {f}, Value: {last}";
public override string ToString() => $"Frame: {F}, Value: {Value}";
}
}
+1 -1
View File
@@ -7,7 +7,7 @@
float Frame { get; }
float Value { get; }
float SetTime (float time);
float SetFrame(float frame);
float NextFrame(float time);
+47 -49
View File
@@ -2,36 +2,36 @@
{
public struct PDI : IInterpolation //Project DIVA Interpolation
{
private KFT2[] array;
private KFT2[] Array;
private float f;
private float last;
private float deltaFrame;
private float @if;
private float rf;
private float lastTime;
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; } }
{ get => IF; set { IF = value; DeltaFrame = IF / RF; } }
public float RequestedFramerate
{ get => rf; set { rf = value; deltaFrame = @if / rf; } }
{ 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, float InterpolationFramerate = 60, float RequestedFramerate = 60)
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;
LastTime = 0;
this.Array = Array; F = -1; DeltaFrame = Last = RF = IF = 0;
IF = InterpolationFramerate;
firstKey = lastKey = default;
this.RequestedFramerate = RequestedFramerate;
f = -deltaFrame;
F = -DeltaFrame;
ResetFrameCount();
if (Array != null && Array.Length > 0)
@@ -43,42 +43,42 @@
public float SetTime(float time)
{
if (array == null || array.Length < 1) return 0;
if (Array == null || Array.Length < 1) return 0;
lastTime = time;
f = time * @if;
last = Interpolate(f);
return last;
LastTime = time;
F = time * IF;
Last = Interpolate(F);
return Last;
}
public float SetFrame(float frame)
{
if (array == null || array.Length < 1) return 0;
if (Array == null || Array.Length < 1) return 0;
lastTime = frame / rf;
f = frame * deltaFrame;
last = Interpolate(f);
return last;
LastTime = frame / RF;
F = frame * DeltaFrame;
Last = Interpolate(F);
return Last;
}
public float NextFrame(float time)
{
if (array == null || array.Length < 1) return 0;
if (Array == null || Array.Length < 1) return 0;
lastTime += time;
f = lastTime * @if;
last = Interpolate(f);
return last;
LastTime += time;
F = LastTime * IF;
Last = Interpolate(F);
return Last;
}
public float NextFrame()
{
if (array == null || array.Length < 1) return 0;
if (Array == null || Array.Length < 1) return 0;
f += deltaFrame;
lastTime = f / @if;
last = Interpolate(f);
return last;
F += DeltaFrame;
LastTime = F / IF;
Last = Interpolate(F);
return Last;
}
private float Interpolate(float frame)
@@ -86,9 +86,9 @@
float f = (int)frame;
int data = 0;
int length = array.Length;
int length = Array.Length;
while (length > 0)
if (f <= array[data + (length >> 1)].F)
if (f <= Array[data + (length >> 1)].F)
length >>= 1;
else
{
@@ -99,25 +99,23 @@
if (data == 0)
return firstKey.V;
else if (data >= array.Length)
else if (data >= Array.Length)
return lastKey.V;
KFT2 c = array[data - 1];
KFT2 n = array[data];
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 = (this.f - c.F) / (n.F - c.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 * (this.f - c.F) + c.V;
(t_1 * c.T + t * n.T) * t_1 * (F - c.F) + c.V;
}
return result;
}
public void ResetFrameCount() => f = -deltaFrame;
public override string ToString() => $"Frame: {f}, Value: {last}";
public void ResetFrameCount() => F = -DeltaFrame;
}
}
+44 -140
View File
@@ -8,48 +8,24 @@
{ this.F = F; }
public KFT0 ToT0() => this;
public KFT1 ToT1() =>
new KFT1(F);
public KFT2 ToT2() =>
new KFT2(F);
public KFT3 ToT3() =>
new KFT3(F);
public KFT1 ToT1() => this;
public KFT2 ToT2() => this;
public KFT3 ToT3() => this;
public IKF Check() => this;
public override string ToString() => ToString(true, 7);
public string ToString(int round = 7, bool brackets = true) =>
ToString(brackets, round);
public string ToString(bool brackets = true, int round = 7) =>
Extensions.ToS(F, round);
public override string ToString() => ToString(true);
public string ToString(bool Brackets = true) =>
Extensions.ToString(F);
public static explicit operator KFT1(KFT0 KF) =>
public static implicit operator KFT1(KFT0 KF) =>
new KFT1(KF.F);
public static explicit operator KFT2(KFT0 KF) =>
public static implicit operator KFT2(KFT0 KF) =>
new KFT2(KF.F);
public static explicit operator KFT3(KFT0 KF) =>
public static implicit operator KFT3(KFT0 KF) =>
new KFT3(KF.F);
public override int GetHashCode() => base.GetHashCode();
public override bool Equals(object obj)
{ if (obj is KFT0 b) return this == b; else return base.Equals(obj); }
public static bool operator > (float a, KFT0 b) => a > b.F;
public static bool operator < (float a, KFT0 b) => a < b.F;
public static bool operator >=(float a, KFT0 b) => a >= b.F;
public static bool operator <=(float a, KFT0 b) => a <= b.F;
public static bool operator > (KFT0 a, float b) => a.F > b;
public static bool operator < (KFT0 a, float b) => a.F < b;
public static bool operator >=(KFT0 a, float b) => a.F >= b;
public static bool operator <=(KFT0 a, float b) => a.F <= b;
public static bool operator > (KFT0 a, KFT0 b) => a.F > b.F;
public static bool operator < (KFT0 a, KFT0 b) => a.F < b.F;
public static bool operator >=(KFT0 a, KFT0 b) => a.F >= b.F;
public static bool operator <=(KFT0 a, KFT0 b) => a.F <= b.F;
public static bool operator ==(KFT0 a, KFT0 b) => a.F == b.F;
public static bool operator !=(KFT0 a, KFT0 b) => a.F != b.F;
}
public struct KFT1 : IKF
{
public float F;
@@ -58,51 +34,27 @@
public KFT1(float F = 0, float V = 0)
{ this.F = F; this.V = V; }
public KFT0 ToT0() =>
new KFT0(F);
public KFT0 ToT0() => this;
public KFT1 ToT1() => this;
public KFT2 ToT2() =>
new KFT2(F, V);
public KFT3 ToT3() =>
new KFT3(F, V);
public KFT2 ToT2() => this;
public KFT3 ToT3() => this;
public IKF Check() =>
V == 0 ? (KFT0)this : (IKF)this;
public override string ToString() => ToString(true, 7);
public string ToString(int round = 7, bool brackets = true) =>
ToString(brackets, round);
public string ToString(bool brackets = true, int round = 7) =>
(brackets ? "(" : "") + Extensions.ToS(F, round) + "," +
Extensions.ToS(V, round) + (brackets ? ")" : "");
public override string ToString() => ToString(true);
public string ToString(bool Brackets = true) =>
(Brackets ? "(" : "") + Extensions.ToString(F) + "," +
Extensions.ToString(V) + (Brackets ? ")" : "");
public static explicit operator KFT0(KFT1 KF) =>
public static implicit operator KFT0(KFT1 KF) =>
new KFT0(KF.F);
public static explicit operator KFT2(KFT1 KF) =>
public static implicit operator KFT2(KFT1 KF) =>
new KFT2(KF.F, KF.V);
public static explicit operator KFT3(KFT1 KF) =>
public static implicit operator KFT3(KFT1 KF) =>
new KFT3(KF.F, KF.V);
public override int GetHashCode() => base.GetHashCode();
public override bool Equals(object obj)
{ if (obj is KFT1 b) return this == b; else return base.Equals(obj); }
public static bool operator > (float a, KFT1 b) => a > b.F;
public static bool operator < (float a, KFT1 b) => a < b.F;
public static bool operator >=(float a, KFT1 b) => a >= b.F;
public static bool operator <=(float a, KFT1 b) => a <= b.F;
public static bool operator > (KFT1 a, float b) => a.F > b;
public static bool operator < (KFT1 a, float b) => a.F < b;
public static bool operator >=(KFT1 a, float b) => a.F >= b;
public static bool operator <=(KFT1 a, float b) => a.F <= b;
public static bool operator > (KFT1 a, KFT1 b) => a.F > b.F;
public static bool operator < (KFT1 a, KFT1 b) => a.F < b.F;
public static bool operator >=(KFT1 a, KFT1 b) => a.F >= b.F;
public static bool operator <=(KFT1 a, KFT1 b) => a.F <= b.F;
public static bool operator ==(KFT1 a, KFT1 b) => a.F == b.F && a.V == b.V;
public static bool operator !=(KFT1 a, KFT1 b) => a.F != b.F || a.V != b.V;
}
public struct KFT2 : IKF
{
public float F;
@@ -112,56 +64,32 @@
public KFT2(float F = 0, float V = 0, float T = 0)
{ this.F = F; this.V = V; this.T = T; }
public KFT0 ToT0() =>
new KFT0(F);
public KFT1 ToT1() =>
new KFT1(F, V);
public KFT0 ToT0() => this;
public KFT1 ToT1() => this;
public KFT2 ToT2() => this;
public KFT3 ToT3() =>
new KFT3(F, V, T, T);
public KFT3 ToT3() => this;
public KFT3 ToT3(IKF Previous) =>
Previous is KFT2 PreviousT2 ?
Previous is KFT2 PreviousT2 ?
new KFT3(F, V, PreviousT2.T, T) :
new KFT3(F, V, T, T);
public IKF Check() =>
T == 0 ? (V == 0 ? (IKF)ToT0() : ToT1()) : this;
T == 0 ? (V == 0 ? (IKF)(KFT0)this : (KFT1)this) : this;
public override string ToString() => ToString(true, 7);
public string ToString(int round = 7, bool brackets = true) =>
ToString(brackets, round);
public string ToString(bool brackets = true, int round = 7) =>
(brackets ? "(" : "") + Extensions.ToS(F, round) + "," + Extensions.
ToS(V, round) + "," + Extensions.ToS(T, round) + (brackets ? ")" : "");
public override string ToString() => ToString(true);
public string ToString(bool Brackets) =>
(Brackets ? "(" : "") + Extensions.ToString(F) + "," + Extensions.
ToString(V) + "," + Extensions.ToString(T) + (Brackets ? ")" : "");
public static explicit operator KFT0(KFT2 KF) =>
public static implicit operator KFT0(KFT2 KF) =>
new KFT0(KF.F);
public static explicit operator KFT1(KFT2 KF) =>
public static implicit operator KFT1(KFT2 KF) =>
new KFT1(KF.F, KF.V);
public static explicit operator KFT3(KFT2 KF) =>
public static implicit operator KFT3(KFT2 KF) =>
new KFT3(KF.F, KF.V, KF.T, KF.T);
public override int GetHashCode() => base.GetHashCode();
public override bool Equals(object obj)
{ if (obj is KFT2 b) return this == b; else return base.Equals(obj); }
public static bool operator > (float a, KFT2 b) => a > b.F;
public static bool operator < (float a, KFT2 b) => a < b.F;
public static bool operator >=(float a, KFT2 b) => a >= b.F;
public static bool operator <=(float a, KFT2 b) => a <= b.F;
public static bool operator > (KFT2 a, float b) => a.F > b;
public static bool operator < (KFT2 a, float b) => a.F < b;
public static bool operator >=(KFT2 a, float b) => a.F >= b;
public static bool operator <=(KFT2 a, float b) => a.F <= b;
public static bool operator > (KFT2 a, KFT2 b) => a.F > b.F;
public static bool operator < (KFT2 a, KFT2 b) => a.F < b.F;
public static bool operator >=(KFT2 a, KFT2 b) => a.F >= b.F;
public static bool operator <=(KFT2 a, KFT2 b) => a.F <= b.F;
public static bool operator ==(KFT2 a, KFT2 b) => a.F == b.F && a.V == b.V && a.T == b.T;
public static bool operator !=(KFT2 a, KFT2 b) => a.F != b.F || a.V != b.V || a.T != b.T;
}
public struct KFT3 : IKF
{
public float F;
@@ -172,50 +100,26 @@
public KFT3(float F = 0, float V = 0, float T1 = 0, float T2 = 0)
{ this.F = F; this.V = V; this.T1 = T1; this.T2 = T2; }
public KFT0 ToT0() =>
new KFT0(F);
public KFT1 ToT1() =>
new KFT1(F, V);
public KFT2 ToT2() =>
new KFT2(F, V, T1);
public 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, 7);
public string ToString(int round = 7, bool brackets = true) =>
ToString(brackets, round);
public string ToString(bool brackets = true, int round = 7) =>
(brackets ? "(" : "") + Extensions.ToS(F, round) + "," + Extensions.ToS(V, round) + "," +
Extensions.ToS(T1, round) + "," + Extensions.ToS(T2, round) + (brackets ? ")" : "");
public 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 explicit operator KFT0(KFT3 KF) =>
public static implicit operator KFT0(KFT3 KF) =>
new KFT0(KF.F);
public static explicit operator KFT1(KFT3 KF) =>
public static implicit operator KFT1(KFT3 KF) =>
new KFT1(KF.F, KF.V);
public static explicit operator KFT2(KFT3 KF) =>
public static implicit operator KFT2(KFT3 KF) =>
new KFT2(KF.F, KF.V, KF.T1);
public override int GetHashCode() => base.GetHashCode();
public override bool Equals(object obj)
{ if (obj is KFT3 b) return this == b; else return base.Equals(obj); }
public static bool operator > (float a, KFT3 b) => a > b.F;
public static bool operator < (float a, KFT3 b) => a < b.F;
public static bool operator >=(float a, KFT3 b) => a >= b.F;
public static bool operator <=(float a, KFT3 b) => a <= b.F;
public static bool operator > (KFT3 a, float b) => a.F > b;
public static bool operator < (KFT3 a, float b) => a.F < b;
public static bool operator >=(KFT3 a, float b) => a.F >= b;
public static bool operator <=(KFT3 a, float b) => a.F <= b;
public static bool operator > (KFT3 a, KFT3 b) => a.F > b.F;
public static bool operator < (KFT3 a, KFT3 b) => a.F < b.F;
public static bool operator >=(KFT3 a, KFT3 b) => a.F >= b.F;
public static bool operator <=(KFT3 a, KFT3 b) => a.F <= b.F;
public static bool operator ==(KFT3 a, KFT3 b) => a.F == b.F && a.V == b.V && a.T1 == b.T1 && a.T2 == b.T2;
public static bool operator !=(KFT3 a, KFT3 b) => a.F != b.F || a.V != b.V || a.T1 != b.T1 || a.T2 != b.T2;
public IKF ToT2(IKF Previous, out IKF Current)
{
Current = Previous is KFT2 PreviousT2
+45 -13
View File
@@ -1,17 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<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>
<Authors>korenkonder</Authors>
<Company></Company>
<Configuration></Configuration>
<Copyright>korenkonder © 2019</Copyright>
<Description>A base library</Description>
<FileVersion>0.4.8.1</FileVersion>
<PackageId>KKdBaseLib</PackageId>
<Product>KKdBaseLib</Product>
<TargetFramework>netstandard2.0</TargetFramework>
<Title>KKdBaseLib</Title>
<Version>0.4.8.1</Version>
<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>
@@ -39,4 +38,37 @@
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
</Project>
<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>
-211
View File
@@ -1,211 +0,0 @@
namespace KKdBaseLib
{
public struct KKdDict<TKey, TValue> : System.IDisposable, System.Collections.IEnumerator, INull
{
public static KKdDict<TKey, TValue> Null => new KKdDict<TKey, TValue>();
public static KKdDict<TKey, TValue> New => new KKdDict<TKey, TValue>() { Count = 0, Capacity = 0 };
public static KKdDict<TKey, TValue> NewReserve(int Capacity) =>
new KKdDict<TKey, TValue>() { Count = 0, Capacity = Capacity };
private int index;
private TKey [] keyArray;
private TValue[] valArray;
public int Count { get; private set; }
public bool IsNull => keyArray == null || valArray == null;
public bool NotNull => keyArray != null && valArray != null;
public int Capacity { get => keyArray != null && valArray != null ? valArray.Length : -1;
set { if (keyArray != null) System.Array.Resize(ref keyArray, value); else keyArray = new TKey [value];
if (valArray != null) System.Array.Resize(ref valArray, value); else valArray = new TValue[value];
if (Count >= value) Count = value; } }
public KKdDict(TKey[] keyArray, TValue[] valArray)
{
this.keyArray = null; this.valArray = null; Count = 0; index = 0;
if (keyArray == null || valArray == null || keyArray.Length != valArray.Length) return;
Count = valArray.Length; this.keyArray = keyArray; this.valArray = valArray; }
public KeyValuePair<TKey, TValue> Current => index < Count ?
new KeyValuePair<TKey, TValue>(keyArray[index], valArray[index]) : default;
object System.Collections.IEnumerator.Current => Current;
public TKey [] Keys => keyArray;
public TValue[] Values => valArray;
public KeyValuePair<TKey, TValue> this[ int index, bool list]
{ get => keyArray != null && valArray != null && index > -1 && index < keyArray.Length &&
index < valArray.Length ? new KeyValuePair<TKey, TValue>(keyArray[index], valArray[index]) : default;
set { if (keyArray != null && valArray != null && index > -1 && index < keyArray.Length &&
index < valArray.Length) { keyArray[index] = value.Key; valArray[index] = value.Value; } } }
public KeyValuePair<TKey, TValue> this[uint index, bool list]
{ get => keyArray != null && valArray != null && index < keyArray.Length &&
index < valArray.Length ? new KeyValuePair<TKey, TValue>(keyArray[index], valArray[index]) : default;
set { if (keyArray != null && valArray != null && index < keyArray.Length &&
index < valArray.Length) { keyArray[index] = value.Key; valArray[index] = value.Value; } } }
public TValue this[TKey key]
{ get => valArray != null && valArray.Length > 0 && ContainsKey(key) ? valArray[IndexOf(key)] : default;
set { if (valArray != null && valArray.Length > 0 && ContainsKey(key)) valArray[IndexOf(key)] = value; } }
public bool MoveNext()
{ if (index == Count - 1) { index = 0; return false; }
else { index++ ; return true; } }
public System.Collections.IEnumerator GetEnumerator() => this;
public void Dispose() { valArray = null; Count = 0; index = 0; }
public void Reset() => index = 0;
public void Add(KeyValuePair<TKey, TValue> pair)
{
if (IsNull) return;
Count++;
if (keyArray.Length < Count) System.Array.Resize(ref keyArray, Count);
if (valArray.Length < Count) System.Array.Resize(ref valArray, Count);
keyArray[Count - 1] = pair.Key;
valArray[Count - 1] = pair.Value;
}
public void Add(TKey key, TValue val)
{
if (IsNull) return;
Count++;
if (keyArray.Length < Count) System.Array.Resize(ref keyArray, Count);
if (valArray.Length < Count) System.Array.Resize(ref valArray, Count);
keyArray[Count - 1] = key;
valArray[Count - 1] = val;
}
public bool RemoveKey(TKey key)
{
if (IsNull) return false;
int index = IndexOf(key);
if (index == -1) return false;
for (int i = index + 1; i < Count; i++)
{
keyArray[i - 1] = keyArray[i];
valArray[i - 1] = valArray[i];
}
Count--;
return true;
}
public bool RemoveValue(TValue val)
{
if (IsNull) return false;
int index = IndexOf(val);
if (index == -1) return false;
for (int i = index + 1; i < Count; i++)
{
keyArray[i - 1] = keyArray[i];
valArray[i - 1] = valArray[i];
}
Count--;
return true;
}
public void RemoveAt(int index)
{
if (IsNull) return;
for (int i = index + 1; i < Count; i++)
{
keyArray[i - 1] = keyArray[i];
valArray[i - 1] = valArray[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++)
{
keyArray[i] = keyArray[i + IndexEnd - IndexStart];
valArray[i] = valArray[i + IndexEnd - IndexStart];
}
Count -= IndexEnd - IndexStart;
}
public TValue[] ToArray() => valArray;
public bool ContainsKey(TKey key)
{
if (IsNull) return false;
for (int i = 0; i < Count; i++)
if (keyArray[i] == null && key == null) return true;
else if (keyArray[i] == null || key == null) continue;
else if (keyArray[i] .Equals(key) ) return true;
return false;
}
public bool ContainsValue(TValue val)
{
if (IsNull) return false;
for (int i = 0; i < Count; i++)
if (valArray[i] == null && val == null) return true;
else if (valArray[i] == null || val == null) continue;
else if (valArray[i] .Equals(val) ) return true;
return false;
}
public bool Contains(KeyValuePair<TKey, TValue> pair)
{
if (IsNull) return false;
for (int i = 0; i < Count; i++)
if ( keyArray[i] == null && pair.Key == null &&
valArray[i] == null && pair.Value == null ) return true;
else if ((keyArray[i] == null || pair.Key == null) &&
(valArray[i] == null || pair.Value == null)) continue;
else if ( keyArray[i] .Equals(pair.Key) &&
valArray[i] .Equals(pair.Value) ) return true;
return false;
}
private int IndexOf(TKey key)
{
if (IsNull) return -1;
for (int i = 0; i < Count; i++)
if (keyArray[i] == null && key == null) return i;
else if (keyArray[i] == null || key == null) continue;
else if (keyArray[i] .Equals(key) ) return i;
return -1;
}
private int IndexOf(TValue val)
{
if (IsNull) return -1;
for (int i = 0; i < Count; i++)
if (keyArray[i] == null && val == null) return i;
else if (keyArray[i] == null || val == null) continue;
else if (keyArray[i] .Equals(val) ) return i;
return -1;
}
}
public struct KeyValuePair<TKey, TValue>
{
public TKey Key;
public TValue Value;
public KeyValuePair(TKey key, TValue value)
{ Key = key; Value = value; }
}
}
+3 -3
View File
@@ -100,12 +100,12 @@ namespace KKdBaseLib
}
public void Sort()
{ List<T> List = (List<T>)this; List.Sort(); array = List.ToArray(); Count = List.Count; }
{ List<T> List = this; List.Sort(); array = List.ToArray(); Count = List.Count; }
public static explicit operator KKdList<T>( List<T> List) =>
public static implicit operator KKdList<T>( List<T> List) =>
new KKdList<T> { array = List.ToArray(), Count = List.Count };
public static explicit operator List<T>(KKdList<T> List)
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]);
+7 -7
View File
@@ -6,7 +6,7 @@ namespace KKdBaseLib
{
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;
@@ -43,9 +43,9 @@ namespace KKdBaseLib
{ get { if (!array) return this[key];
if (Object is KKdList<MsgPack> List) { MsgPack MsgPack = List[ElementIndex(key)];
return MsgPack.Object is MsgPack[] ? MsgPack : default; } return default; } }
public MsgPack Add(MsgPack obj)
{ if (Object is KKdList<MsgPack> List && obj.Object != null) { List.Add(obj); Object = List; } return this; }
{ if (Object is KKdList<MsgPack> List) { List.Add(obj); Object = List; } return this; }
public void Dispose()
{ Name = null; Object = null; }
@@ -69,7 +69,7 @@ namespace KKdBaseLib
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;
@@ -95,7 +95,7 @@ namespace KKdBaseLib
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;
@@ -107,7 +107,7 @@ namespace KKdBaseLib
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));
@@ -253,7 +253,7 @@ namespace KKdBaseLib
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 ()
+2 -30
View File
@@ -5,7 +5,7 @@
public int O;
public T V;
public override string ToString() => Extensions.ToS(V);
public override string ToString() => Extensions.ToString(V);
public Pointer(T value)
{ O = 0; V = value; }
@@ -13,35 +13,7 @@
public Pointer(int offset, T value)
{ O = offset; V = value; }
}
public struct PointerI64<T>
{
public long O;
public T V;
public override string ToString() => Extensions.ToS(V);
public PointerI64(T value)
{ O = 0; V = value; }
public PointerI64(long offset, T value)
{ O = offset; V = value; }
}
public struct PointerU64<T>
{
public ulong O;
public T V;
public override string ToString() => Extensions.ToS(V);
public PointerU64(T value)
{ O = 0; V = value; }
public PointerU64(ulong offset, T value)
{ O = offset; V = value; }
}
public struct CountPointer<T>
{
public int C { get => E != null ? E.Length : 0;
+8
View File
@@ -1,7 +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")]
+1 -1
View File
@@ -5,7 +5,7 @@ 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 ?? "" );
+3 -3
View File
@@ -13,7 +13,7 @@
public override string ToString() => $"({X}; {Y})";
}
public struct Vector3<T> : INull
{
public T X;
@@ -22,7 +22,7 @@
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;
@@ -38,7 +38,7 @@
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;
+1354 -1595
View File
File diff suppressed because it is too large Load Diff
+591 -563
View File
File diff suppressed because it is too large Load Diff
+58 -62
View File
@@ -6,42 +6,42 @@ using KKdMainLib.IO;
namespace KKdMainLib.DB
{
public class Aet : System.IDisposable
public class Aet
{
private int i, i0, i1, i2;
private Stream _IO;
public AetSet[] AetSets;
private Stream IO;
private int i, i0, i1, i2;
public void BINReader(string file)
{
_IO = File.OpenReader(file + ".bin");
IO = File.OpenReader(file + ".bin");
int aetSetsLength = _IO.RI32();
int aetSetsOffset = _IO.RI32();
int aetsLength = _IO.RI32();
int aetsOffset = _IO.RI32();
int aetSetsLength = IO.RI32();
int aetSetsOffset = IO.RI32();
int aetsLength = IO.RI32();
int aetsOffset = IO.RI32();
_IO.P = aetSetsOffset;
IO.P = aetSetsOffset;
AetSets = new AetSet[aetSetsLength];
for (i = 0; i < aetSetsLength; i++)
{
AetSets[i].Id = _IO.RI32();
AetSets[i].Name = _IO.RSaO();
AetSets[i].FileName = _IO.RSaO();
_IO.RI32();
AetSets[i].SpriteSetId = _IO.RI32();
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.P = aetsOffset;
IO.P = aetsOffset;
for (i = 0; i < aetsLength; i++)
{
_IO.PI64 += 10;
setIndex = _IO.RI16();
IO.I64P += 10;
setIndex = IO.RI16();
AetCount[setIndex]++;
}
@@ -51,18 +51,18 @@ namespace KKdMainLib.DB
AetCount[i] = 0;
}
_IO.P = aetsOffset;
IO.P = aetsOffset;
for (i = 0; i < aetsLength; i++)
{
aet.Id = _IO.RI32();
aet.Name = _IO.RSaO();
_IO.RI16();
setIndex = _IO.RI16();
aet.Id = IO.RI32();
aet.Name = IO.RSaO();
IO.RI16();
setIndex = IO.RI16();
AetSets[setIndex].Aets[AetCount[setIndex]] = aet; AetCount[setIndex]++;
}
_IO.C();
IO.C();
}
@@ -133,64 +133,64 @@ namespace KKdMainLib.DB
for (i = 0, i0 = 0, i2 = 0; i < AetSets.Length; i++)
if (!NotAdd.Contains(i)) { i0 += AetSets[i].Aets.Length; i2++; }
i1 = i0 * 12;
i1 = i1.A(0x20) + 0x20;
i1 = i1.Align(0x20) + 0x20;
_IO = File.OpenWriter(file + ".bin", true);
_IO.W(i2);
_IO.W(i1);
_IO.W(i0);
_IO.W(0x20);
_IO.W(0x9066906690669066);
_IO.W(0x9066906690669066);
IO = File.OpenWriter(file + ".bin", true);
IO.W(i2);
IO.W(i1);
IO.W(i0);
IO.W(0x20);
IO.W(0x9066906690669066);
IO.W(0x9066906690669066);
_IO.P = (i1 + i2 * 0x14).A(0x20);
IO.P = (i1 + i2 * 0x14).Align(0x20);
for (i = 0; i < AetSets.Length; i++)
{
if (NotAdd.Contains(i)) continue;
AetSets[i]. NameOffset = _IO.P; _IO.W(AetSets[i]. Name + "\0");
AetSets[i].FileNameOffset = _IO.P; _IO.W(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.P; _IO.W(AetSets[i].Aets[i0].Name + "\0"); }
{ AetSets[i].Aets[i0].NameOffset = IO.P; IO.W(AetSets[i].Aets[i0].Name + "\0"); }
}
_IO.A(0x08, true);
_IO.P = 0x20;
IO.A(0x08, true);
IO.P = 0x20;
for (i = 0, i2 = 0; i < AetSets.Length; i++)
{
if (NotAdd.Contains(i)) { i2++; continue; }
for (i0 = 0; i0 < AetSets[i].Aets.Length; i0++)
{
_IO.W(AetSets[i].Aets[i0].Id );
_IO.W(AetSets[i].Aets[i0].NameOffset);
_IO.W((ushort) i0 );
_IO.W((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.A(0x20);
IO.A(0x20);
for (i = 0, i2 = 0; i < AetSets.Length; i++)
{
if (NotAdd.Contains(i)) { i2++; continue; }
_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.W(AetSets[i].Id );
IO.W(AetSets[i]. NameOffset);
IO.W(AetSets[i].FileNameOffset);
IO.W(i - i2);
IO.W(AetSets[i].SpriteSetId );
}
_IO.C();
IO.C();
}
public void MsgPackReader(string file, bool json)
public void MsgPackReader(string file, bool JSON)
{
MsgPack MsgPack = file.ReadMPAllAtOnce(json);
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
MsgPack Temp = default;
if ((Temp = MsgPack["AetDB", true]).NotNull)
@@ -204,7 +204,7 @@ namespace KKdMainLib.DB
}
public void MsgPackWriter(string file, bool json)
public void MsgPackWriter(string file, bool JSON)
{
if (AetSets == null) return;
if (AetSets.Length == 0) return;
@@ -213,13 +213,9 @@ namespace KKdMainLib.DB
for (i = 0; i < AetSets.Length; i++)
AetDB[i] = AetSets[i].WriteMsgPack();
AetDB.Write(true, file, json);
AetDB.Write(true, file, JSON);
}
private bool disposed = false;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.D(); AetSets = null; disposed = true; } }
public struct AET
{
public int NameOffset;
@@ -228,7 +224,7 @@ namespace KKdMainLib.DB
public void ReadMsgPack(MsgPack msg)
{ Id = msg.RnU16("Id"); Name = msg.RS("Name"); }
public MsgPack WriteMsgPack() =>
MsgPack.New.Add("Id", Id).Add("Name", Name);
}
@@ -243,7 +239,7 @@ namespace KKdMainLib.DB
public string Name;
public string FileName;
public AET[] Aets;
public void ReadMsgPack(MsgPack msg)
{
FileName = msg.RS ("FileName" );
+81 -88
View File
@@ -5,156 +5,149 @@ using KKdMainLib.IO;
namespace KKdMainLib.DB
{
public class Auth : IDisposable
public class Auth
{
private int i;
private Stream _IO;
public string[] Category;
public UID[] UIDs;
public int Signature { get; private set; }
public string[] Category { get; private set; }
public UID[] _UID { get; private set; }
public Stream IO { get; private set; }
public void BINReader(string file)
{
Dictionary<string, object> dict = new Dictionary<string, object>();
Dictionary<string, object> Dict = new Dictionary<string, object>();
string[] dataArray;
_IO = File.OpenReader(file + ".bin");
IO = File.OpenReader(file + ".bin");
_IO.Format = Format.F;
int signature = _IO.RI32();
if (signature != 0x44334123) return;
signature = _IO.RI32();
if (signature != 0x5F5F5F41) return;
_IO.RI64();
IO.Format = Format.F;
Signature = IO.RI32();
if (Signature != 0x44334123) return;
Signature = IO.RI32();
if (Signature != 0x5F5F5F41) return;
IO.RI64();
string[] strData = _IO.RS(_IO.L - _IO.P).Replace("\r", "").Split('\n');
for (i = 0; i < strData.Length; i++)
string[] STRData = IO.RS(IO.L - IO.P).Replace("\r", "").Split('\n');
for (int i = 0; i < STRData.Length; i++)
{
dataArray = strData[i].Split('=');
dataArray = STRData[i].Split('=');
if (dataArray.Length == 2)
dict.GetDictionary(dataArray[0], dataArray[1]);
Dict.GetDictionary(dataArray[0], dataArray[1]);
}
if (dict.FindValue(out string value, "category.length"))
if (Dict.FindValue(out string value, "category.length"))
{
Category = new string[int.Parse(value)];
for (i = 0; i < Category.Length; i++)
if (dict.FindValue(out value, "category." + i + ".value"))
Category[i] = value;
for (int i0 = 0; i0 < Category.Length; i0++)
if (Dict.FindValue(out value, "category." + i0 + ".value"))
Category[i0] = value;
}
if (dict.FindValue(out value, "uid.length"))
if (Dict.FindValue(out value, "uid.length"))
{
UIDs = new UID[int.Parse(value)];
for (i = 0; i < UIDs.Length; i++)
_UID = new UID[int.Parse(value)];
for (int i0 = 0; i0 < _UID.Length; i0++)
{
dict.FindValue(out UIDs[i].Category, "uid." + i + ".category");
dict.FindValue(out UIDs[i].OrgUid , "uid." + i + ".org_uid" );
dict.FindValue(out UIDs[i].Size , "uid." + i + ".size" );
dict.FindValue(out UIDs[i].Value , "uid." + i + ".value" );
Dict.FindValue(out _UID[i0].Category, "uid." + i0 + ".category");
Dict.FindValue(out _UID[i0].OrgUid , "uid." + i0 + ".org_uid" );
Dict.FindValue(out _UID[i0].Size , "uid." + i0 + ".size" );
Dict.FindValue(out _UID[i0].Value , "uid." + i0 + ".value" );
}
}
_IO.C();
IO.C();
}
public void BINWriter(string file)
{
_IO = File.OpenWriter(file + ".bin", true);
IO = File.OpenWriter(file + ".bin", true);
_IO.W("#A3DA__________\n");
_IO.W("#" + DateTime.UtcNow.ToString("ddd MMM dd HH:mm:ss yyyy",
System.Globalization.CultureInfo.InvariantCulture) + "\n");
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 (i = 0; i < Category.Length; i++)
_IO.W($"category.{so[i]}.value={ Category[so[i]]}\n");
_IO.W($"category.length={Category.Length}\n");
int[] SO = Category.Length.SortWriter();
for (int i = 0; i < Category.Length; i++)
IO.W("category." + SO[i] + ".value=", Category[SO[i]]);
IO.W("category.length=", Category.Length);
}
if (UIDs != null)
if (_UID != null)
{
int[] so = UIDs.Length.SortWriter();
for (i = 0; i < UIDs.Length; i++)
int[] SO = _UID.Length.SortWriter();
for (int i = 0; i < _UID.Length; i++)
{
if (UIDs[so[i]].Category != null && UIDs[so[i]].Category != "")
_IO.W($"uid.{so[i]}.category=" + UIDs[so[i]].Category + "\n");
if (UIDs[so[i]].OrgUid != null)
_IO.W($"uid.{so[i]}.org_uid=" + UIDs[so[i]].OrgUid + "\n");
if (UIDs[so[i]].Size != null)
_IO.W($"uid.{so[i]}.size=" + UIDs[so[i]].Size + "\n");
if (UIDs[so[i]].Value != null && UIDs[so[i]].Value != "")
_IO.W($"uid.{so[i]}.value=" + UIDs[so[i]].Value + "\n");
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.W($"uid.length={UIDs.Length}\n");
IO.W("uid.length=", _UID.Length);
}
_IO.C();
IO.C();
}
public void MsgPackReader(string file, bool json)
public void MsgPackReader(string file, bool JSON)
{
MsgPack msgPack = file.ReadMPAllAtOnce(json);
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
MsgPack authDB;
if ((authDB = msgPack["AuthDB"]).NotNull)
MsgPack AuthDB;
if ((AuthDB = MsgPack["AuthDB"]).NotNull)
{
MsgPack temp;
if ((temp = authDB["Category", true]).NotNull)
MsgPack Temp;
if ((Temp = MsgPack["Category", true]).NotNull)
{
Category = new string[temp.Array.Length];
Category = new string[Temp.Array.Length];
for (int i = 0; i < Category.Length; i++)
Category[i] = temp[i].RS();
Category[i] = Temp[i].RS();
}
if ((temp = authDB["UID", true]).NotNull)
if ((Temp = MsgPack["UID", true]).NotNull)
{
UIDs = new UID[temp.Array.Length];
for (int i = 0; i < UIDs.Length; i++)
_UID = new UID[Temp.Array.Length];
for (int i = 0; i < _UID.Length; i++)
{
UIDs[i].Category = temp[i].RS ("Category");
UIDs[i].OrgUid = temp[i].RnI32("OrgUid" );
UIDs[i].Size = temp[i].RnI32("Size" );
UIDs[i].Value = temp[i].RS ("Value" );
_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();
Temp.Dispose();
}
authDB.Dispose();
msgPack.Dispose();
AuthDB.Dispose();
MsgPack.Dispose();
}
public void MsgPackWriter(string file, bool json)
public void MsgPackWriter(string file, bool JSON)
{
MsgPack authDB = new MsgPack("AuthDB");
MsgPack AuthDB = new MsgPack("AuthDB");
if (Category != null)
{
MsgPack category = new MsgPack(Category.Length, "Category");
for (int i = 0; i < Category.Length; i++)
category[i] = (MsgPack)Category[i];
authDB.Add(category);
MsgPack Category = new MsgPack(this.Category.Length, "Category");
for (int i = 0; i < this.Category.Length; i++)
Category[i] = (MsgPack)this.Category[i];
AuthDB.Add(Category);
}
if (UIDs != null)
if (_UID != null)
{
MsgPack uid = new MsgPack(UIDs.Length, "UID");
for (int i = 0; i < UIDs.Length; i++)
uid[i] = MsgPack.New.Add("Category", UIDs[i].Category)
.Add("OrgUid" , UIDs[i].OrgUid )
.Add("Size" , UIDs[i].Size )
.Add("Value" , UIDs[i].Value );
authDB.Add(uid);
MsgPack UID = new MsgPack(_UID.Length, "UID");
for (int i = 0; i < _UID.Length; i++)
UID[i] = MsgPack.New.Add("Category", _UID[i].Category)
.Add("OrgUid" , _UID[i].OrgUid )
.Add("Size" , _UID[i].Size )
.Add("Value" , _UID[i].Value );
AuthDB.Add(UID);
}
authDB.Write(true, file, json);
AuthDB.Write(true, file, JSON);
}
private bool disposed = false;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.D(); Category = null; UIDs = null; disposed = true; } }
public struct UID
{
public int? Size;
+132 -138
View File
@@ -6,74 +6,74 @@ using KKdMainLib.IO;
namespace KKdMainLib.DB
{
public class Spr : System.IDisposable
public class Spr
{
private int i, i0, i1, i2;
private Stream _IO;
public SpriteSet[] SpriteSets;
private Stream IO;
private int i, i0, i1, i2;
public void BINReader(string file)
{
_IO = File.OpenReader(file + ".bin");
IO = File.OpenReader(file + ".bin");
int spriteSetsLength = _IO.RI32();
int spriteSetsOffset = _IO.RI32();
int spritesLength = _IO.RI32();
int spritesOffset = _IO.RI32();
int spriteSetsLength = IO.RI32();
int spriteSetsOffset = IO.RI32();
int spritesLength = IO.RI32();
int spritesOffset = IO.RI32();
_IO.P = spriteSetsOffset;
IO.P = spriteSetsOffset;
SpriteSets = new SpriteSet[spriteSetsLength];
for (i = 0; i < spriteSetsLength; i++)
{
SpriteSets[i].Id = _IO.RI32();
SpriteSets[i].Name = _IO.RSaO();
SpriteSets[i].FileName = _IO.RSaO();
_IO.RI32();
SpriteSets[i].Id = IO.RI32();
SpriteSets[i].Name = IO.RSaO();
SpriteSets[i].FileName = IO.RSaO();
IO.RI32();
}
int setIndex;
bool isTexture;
bool IsTexture;
SpriteTexture st = new SpriteTexture();
int[] sprCount = new int[spriteSetsLength];
int[] texCount = new int[spriteSetsLength];
int[] SprCount = new int[spriteSetsLength];
int[] TexCount = new int[spriteSetsLength];
_IO.P = spritesOffset;
IO.P = spritesOffset;
for (i = 0; i < spritesLength; i++)
{
_IO.PI64 += 10;
setIndex = _IO.RI16();
isTexture = (setIndex & 0x1000) == 0x1000;
IO.I64P += 10;
setIndex = IO.RI16();
IsTexture = (setIndex & 0x1000) == 0x1000;
setIndex &= 0xFFF;
if (isTexture) texCount[setIndex]++;
else sprCount[setIndex]++;
if (IsTexture) TexCount[setIndex]++;
else SprCount[setIndex]++;
}
for (int i = 0; i < spriteSetsLength; i++)
{
SpriteSets[i].Sprites = new SpriteTexture[sprCount[i]];
SpriteSets[i].Textures = new SpriteTexture[texCount[i]];
SpriteSets[i].Sprites = new SpriteTexture[SprCount[i]];
SpriteSets[i].Textures = new SpriteTexture[TexCount[i]];
sprCount[i] = 0;
texCount[i] = 0;
SprCount[i] = 0;
TexCount[i] = 0;
}
_IO.P = spritesOffset;
IO.P = spritesOffset;
for (i = 0; i < spritesLength; i++)
{
st.Id = _IO.RI32();
st.Name = _IO.RSaO();
_IO.RI16();
setIndex = _IO.RI16();
isTexture = (setIndex & 0x1000) == 0x1000;
st.Id = IO.RI32();
st.Name = IO.RSaO();
IO.RI16();
setIndex = IO.RI16();
IsTexture = (setIndex & 0x1000) == 0x1000;
setIndex &= 0xFFF;
if (isTexture) { SpriteSets[setIndex].Textures[texCount[setIndex]] = st; texCount[setIndex]++; }
else { SpriteSets[setIndex]. Sprites[sprCount[setIndex]] = st; sprCount[setIndex]++; }
if (IsTexture) { SpriteSets[setIndex].Textures[TexCount[setIndex]] = st; TexCount[setIndex]++; }
else { SpriteSets[setIndex]. Sprites[SprCount[setIndex]] = st; SprCount[setIndex]++; }
}
_IO.C();
IO.C();
}
public void BINWriter(string file)
@@ -81,13 +81,13 @@ namespace KKdMainLib.DB
if (SpriteSets == null) return;
if (SpriteSets.Length == 0) return;
List<string> setName = new List<string>();
List<string> setFileName = new List<string>();
List<string> SetName = new List<string>();
List<string> SetFileName = new List<string>();
List<int> ids = new List<int>();
List<int> setIds = new List<int>();
List<int> Ids = new List<int>();
List<int> SetIds = new List<int>();
List<int> notAdd = new List<int>();
List<int> NotAdd = new List<int>();
SpriteTexture temp;
SpriteSet set;
@@ -95,11 +95,11 @@ namespace KKdMainLib.DB
{
set = SpriteSets[i];
if (set. Name != null)
if (setName .Contains(set. Name)) { notAdd.Add(i); continue; }
else setName .Add (set. Name);
if (SetName .Contains(set. Name)) { NotAdd.Add(i); continue; }
else SetName .Add (set. Name);
if (set.FileName != null)
if (setFileName.Contains(set.FileName)) { notAdd.Add(i); continue; }
else setFileName.Add (set.FileName);
if (SetFileName.Contains(set.FileName)) { NotAdd.Add(i); continue; }
else SetFileName.Add (set.FileName);
if (set.NewId)
{
@@ -110,15 +110,15 @@ namespace KKdMainLib.DB
}
if (set.Id != null)
if (setIds.Contains((int)set.Id)) { notAdd.Add(i); continue; }
else setIds.Add ((int)set.Id);
if (SetIds.Contains((int)set.Id)) { NotAdd.Add(i); continue; }
else SetIds.Add ((int)set.Id);
for (i0 = 0; i0 < set. Sprites.Length; i0++)
{
temp = set. Sprites[i0];
if (temp.Id != null)
if ( ids.Contains((int)temp.Id)) { notAdd.Add(i); break; }
else ids.Add ((int)temp.Id);
if ( Ids.Contains((int)temp.Id)) { NotAdd.Add(i); break; }
else Ids.Add ((int)temp.Id);
}
if (i0 < set.Sprites.Length) continue;
@@ -126,138 +126,133 @@ namespace KKdMainLib.DB
{
temp = set.Textures[i0];
if (temp.Id != null)
if ( ids.Contains((int)temp.Id)) { notAdd.Add(i); break; }
else ids.Add ((int)temp.Id);
if ( Ids.Contains((int)temp.Id)) { NotAdd.Add(i); break; }
else Ids.Add ((int)temp.Id);
}
}
setName = null;
setFileName = null;
SetName = null;
SetFileName = null;
for (i = 0; i < SpriteSets.Length; i++)
{
set = SpriteSets[i];
if (notAdd.Contains(i)) continue;
if (NotAdd.Contains(i)) continue;
if (!set.NewId) continue;
i1 = 0;
if (set.Id == null) while (true)
{ if (!setIds.Contains(i1)) { SpriteSets[i].Id = i1; setIds.Add(i1); break; } i1++; }
{ if (!SetIds.Contains(i1)) { SpriteSets[i].Id = i1; SetIds.Add(i1); break; } i1++; }
for (i0 = 0, i1 = 0; i0 < set.Textures.Length; i0++)
while (set.Textures[i0].Id == null)
if (!ids.Contains(i1)) ids.Add((int)(SpriteSets[i].Textures[i0].Id = i1)); else i1++;
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++;
if (!Ids.Contains(i1)) Ids.Add((int)(SpriteSets[i]. Sprites[i0].Id = i1)); else i1++;
}
ids = null;
setIds = null;
Ids = null;
SetIds = null;
for (i = 0, i0 = 0, i2 = 0; i < SpriteSets.Length; i++)
if (!notAdd.Contains(i)) { i0 += SpriteSets[i].Sprites.Length + SpriteSets[i].Textures.Length; i2++; }
if (!NotAdd.Contains(i)) { i0 += SpriteSets[i].Sprites.Length + SpriteSets[i].Textures.Length; i2++; }
i1 = i0 * 12;
i1 = i1.A(0x20) + 0x20;
i1 = i1.Align(0x20) + 0x20;
_IO = File.OpenWriter(file + ".bin", true);
_IO.W(i2);
_IO.W(i1);
_IO.W(i0);
_IO.W(0x20);
_IO.W(0x9066906690669066);
_IO.W(0x9066906690669066);
IO = File.OpenWriter(file + ".bin", true);
IO.W(i2);
IO.W(i1);
IO.W(i0);
IO.W(0x20);
IO.W(0x9066906690669066);
IO.W(0x9066906690669066);
_IO.P = (i1 + i2 * 0x10).A(0x20);
IO.P = (i1 + i2 * 0x10).Align(0x20);
for (i = 0; i < SpriteSets.Length; i++)
{
if (notAdd.Contains(i)) continue;
if (NotAdd.Contains(i)) continue;
for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++)
{ SpriteSets[i].Textures[i0].NameOffset = _IO.P;
_IO.W(SpriteSets[i].Textures[i0].Name + "\0"); }
{ 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"); }
{ 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;
SpriteSets[i]. NameOffset = _IO.P; _IO.W(SpriteSets[i]. Name + "\0");
SpriteSets[i].FileNameOffset = _IO.P; _IO.W(SpriteSets[i].FileName + "\0");
if (NotAdd.Contains(i)) continue;
SpriteSets[i]. NameOffset = IO.P; IO.W(SpriteSets[i]. Name + "\0");
SpriteSets[i].FileNameOffset = IO.P; IO.W(SpriteSets[i].FileName + "\0");
}
_IO.A(0x08, true);
_IO.P = 0x20;
IO.A(0x08, true);
IO.P = 0x20;
for (i = 0, i2 = 0; i < SpriteSets.Length; i++)
{
if (notAdd.Contains(i)) { i2++; continue; }
if (NotAdd.Contains(i)) { i2++; continue; }
for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++)
{
_IO.W(SpriteSets[i].Textures[i0].Id );
_IO.W(SpriteSets[i].Textures[i0].NameOffset);
_IO.W((ushort) i0 );
_IO.W((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.W(SpriteSets[i]. Sprites[i0].Id );
_IO.W(SpriteSets[i]. Sprites[i0].NameOffset);
_IO.W((ushort) i0 );
_IO.W((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.A(0x20);
IO.A(0x20);
for (i = 0, i2 = 0; i < SpriteSets.Length; i++)
{
if (notAdd.Contains(i)) { i2++; continue; }
if (NotAdd.Contains(i)) { i2++; continue; }
_IO.W(SpriteSets[i].Id );
_IO.W(SpriteSets[i]. NameOffset);
_IO.W(SpriteSets[i].FileNameOffset);
_IO.W(i - i2);
IO.W(SpriteSets[i].Id );
IO.W(SpriteSets[i]. NameOffset);
IO.W(SpriteSets[i].FileNameOffset);
IO.W(i - i2);
}
_IO.C();
IO.C();
}
public void MsgPackReader(string file, bool json = false)
public void MsgPackReader(string file, bool JSON = false)
{
MsgPack msgPack = file.ReadMPAllAtOnce(json);
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
MsgPack sprDB;
if ((sprDB = msgPack["SprDB", true]).NotNull)
MsgPack SprDB;
if ((SprDB = MsgPack["SprDB", true]).NotNull)
{
SpriteSets = new SpriteSet[sprDB.Array.Length];
SpriteSets = new SpriteSet[SprDB.Array.Length];
for (int i = 0; i < SpriteSets.Length; i++)
SpriteSets[i].ReadMsgPack(sprDB[i]);
SpriteSets[i].ReadMsgPack(SprDB[i]);
}
sprDB.Dispose();
msgPack.Dispose();
SprDB.Dispose();
MsgPack.Dispose();
}
public void MsgPackWriter(string file, bool json)
public void MsgPackWriter(string file, bool JSON)
{
if (SpriteSets == null) return;
if (SpriteSets.Length == 0) return;
MsgPack sprDB = new MsgPack(SpriteSets.Length, "SprDB");
for (i = 0; i < SpriteSets.Length; i++)
sprDB[i] = SpriteSets[i].WriteMsgPack();
MsgPack SprDB = new MsgPack(SpriteSets.Length, "SprDB");
for (i = 0; i < SpriteSets.Length; i++) SprDB[i] = SpriteSets[i].WriteMsgPack();
sprDB.Write(true, file, json);
SprDB.Write(true, file, JSON);
}
private bool disposed = false;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.D(); SpriteSets = null; disposed = true; } }
public struct SpriteTexture
{
public int NameOffset;
@@ -281,43 +276,42 @@ namespace KKdMainLib.DB
public string FileName;
public SpriteTexture[] Sprites;
public SpriteTexture[] Textures;
public void ReadMsgPack(MsgPack msg)
{
FileName = msg.RS ("FileName");
Id = msg.RnI32( "Id" );
Name = msg.RS ("Name" );
NewId = msg.RB ("NewId" );
FileName = msg.RS ("FileName");
Id = msg.RnI32( "Id" );
Name = msg.RS ("Name" );
NewId = msg.RB ("NewId" );
MsgPack temp;
if ((temp = msg["Sprites", true]).NotNull)
MsgPack Temp;
if ((Temp = msg["Sprites", true]).NotNull)
{
Sprites = new SpriteTexture[temp.Array.Length];
Sprites = new SpriteTexture[Temp.Array.Length];
for (int i0 = 0; i0 < Sprites.Length; i0++)
Sprites[i0].ReadMsgPack(temp[i0]);
Sprites[i0].ReadMsgPack(Temp[i0]);
}
if ((temp = msg["Textures", true]).NotNull)
if ((Temp = msg["Textures", true]).NotNull)
{
Textures = new SpriteTexture[temp.Array.Length];
Textures = new SpriteTexture[Temp.Array.Length];
for (int i0 = 0; i0 < Textures.Length; i0++)
Textures[i0].ReadMsgPack(temp[i0]);
Textures[i0].ReadMsgPack(Temp[i0]);
}
temp.Dispose();
Temp.Dispose();
}
public MsgPack WriteMsgPack()
{
MsgPack sprites = new MsgPack( Sprites.Length, "Sprites");
for (int i0 = 0; i0 < Sprites.Length; i0++)
sprites[i0] = Sprites[i0].WriteMsgPack();
MsgPack Sprites = new MsgPack(this. Sprites.Length, "Sprites");
for (int i0 = 0; i0 < this.Sprites.Length; i0++)
Sprites[i0] = this.Sprites[i0].WriteMsgPack();
MsgPack textures = new MsgPack(Textures.Length, "Textures");
for (int i0 = 0; i0 < Textures.Length; i0++)
textures[i0] = Textures[i0].WriteMsgPack();
MsgPack Textures = new MsgPack(this.Textures.Length, "Textures");
for (int i0 = 0; i0 < this.Textures.Length; i0++)
Textures[i0] = this.Textures[i0].WriteMsgPack();
return MsgPack.New.Add("FileName", FileName).Add("Id", Id)
.Add("Name", Name).Add(sprites).Add(textures);
return MsgPack.New.Add("FileName", FileName).Add("Id", Id).Add("Name", Name).Add(Sprites).Add(Textures);
}
}
}
+152 -149
View File
@@ -1,230 +1,233 @@
using KKdBaseLib;
using System.Collections.Generic;
using KKdBaseLib;
using KKdBaseLib.F2;
using KKdMainLib.IO;
namespace KKdMainLib
{
public struct DEX : System.IDisposable
public class DEX
{
private int i, i0, i1;
private Header header;
private Stream _IO;
public DEX()
{ Dex = null; Header = new Header(); }
private int Offset = 0;
private Header Header;
private Stream IO;
public EXP[] Dex;
public void DEXReader(string filepath, string ext)
public int DEXReader(string filepath, string ext)
{
Dex = null;
header = new Header();
_IO = File.OpenReader(filepath + ext);
Header = new Header();
IO = File.OpenReader(filepath + ext);
header.Format = Format.F;
header.SectionSignature = _IO.RI32();
if (header.SectionSignature == 0x43505845)
header = _IO.ReadHeader(true, true);
if (header.SectionSignature != 0x64) return;
Header.Format = Format.F;
Header.SectionSignature = IO.RI32();
if (Header.SectionSignature == 0x43505845)
Header = IO.ReadHeader(true, true);
if (Header.SectionSignature != 0x64) return 0;
_IO.O = _IO.P - 0x4;
Dex = new EXP[_IO.RI32()];
int DEXOffset = _IO.RI32();
int DEXNameOffset = _IO.RI32();
if (DEXNameOffset == 0x00) { _IO.Format = header.Format = Format.X; DEXNameOffset = (int)_IO.RIX(); }
IO.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.P = DEXOffset;
for (i = 0; i < Dex.Length; i++)
IO.S(DEXOffset, 0);
for (int i0 = 0; i0 < Dex.Length; i0++)
Dex[i0] = new EXP { Main = KKdList<EXPElement>.New, Eyes = KKdList<EXPElement>.New };
for (int i0 = 0; i0 < Dex.Length; i0++)
{
Dex[i].MainOffset = (int)_IO.RIX();
Dex[i].EyesOffset = (int)_IO.RIX();
Dex[i0].MainOffset = IO.RI32();
if (Header.IsX) IO.RI32();
Dex[i0].EyesOffset = IO.RI32();
if (Header.IsX) IO.RI32();
}
IO.S(DEXNameOffset, 0);
for (int i0 = 0; i0 < Dex.Length; i0++)
{
Dex[i0].NameOffset = IO.RI32();
if (Header.IsX) IO.RI32();
}
_IO.P = DEXNameOffset;
for (i = 0; i < Dex.Length; i++)
Dex[i].NameOffset = (int)_IO.RIX();
for (i = 0; i < Dex.Length; i++)
for (int i0 = 0; i0 < Dex.Length; i0++)
{
EXPElement element = new EXPElement();
Dex[i].Main = KKdList<EXPElement>.New;
_IO.P = Dex[i].MainOffset;
IO.S(Dex[i0].MainOffset + Offset, 0);
while (true)
{
element.Frame = _IO.RF32();
element.Both = _IO.RU16();
element.ID = _IO.RU16();
element.Value = _IO.RF32();
element.Trans = _IO.RF32();
if (element.Frame == 999999 || element.Both == 0xFFFF) break;
Dex[i].Main.Add(element);
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;
}
Dex[i].Eyes = KKdList<EXPElement>.New;
_IO.P = Dex[i].EyesOffset;
IO.S(Dex[i0].EyesOffset, 0);
while(true)
{
element.Frame = _IO.RF32();
element.Both = _IO.RU16();
element.ID = _IO.RU16();
element.Value = _IO.RF32();
element.Trans = _IO.RF32();
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;
Dex[i].Eyes.Add(element);
}
Dex[i].Name = _IO.RSaO(Dex[i].NameOffset);
Dex[i0].Name = IO.RSaO(Dex[i0].NameOffset);
}
_IO.C();
IO.C();
return 1;
}
public void DEXWriter(string filepath, Format Format)
{
if (Dex == null || Dex.Length < 1) return;
Header = new Header();
IO = File.OpenWriter(filepath + (Format > Format.F ? ".dex" : ".bin"), true);
Header.Format = IO.Format = Format;
header = new Header();
_IO = File.OpenWriter(filepath + (Format > Format.F && Format < Format.FT ? ".dex" : ".bin"), true);
header.Format = _IO.Format = Format;
IO.O = Format > Format.F ? 0x20 : 0;
IO.W(0x64);
IO.W(Dex.Length);
_IO.O = Format > Format.F ? 0x20 : 0;
_IO.W(0x64);
_IO.W(Dex.Length);
IO.WX(Header.IsX ? 0x28 : 0x20);
IO.WX(0x00);
_IO.WX(header.IsX ? 0x28 : 0x20);
_IO.WX(0x00);
int Position0 = IO.P;
IO.W(0x00L);
IO.W(0x00L);
int Position0 = _IO.P;
_IO.W(0x00L);
_IO.W(0x00L);
for (int i = 0; i < Dex.Length * 3; i++) IO.WX(0x00);
for (i = 0; i < Dex.Length * 3; i++) _IO.WX(0x00);
_IO.A(0x20);
IO.A(0x20, true);
for (i0 = 0; i0 < Dex.Length; i0++)
for (int i0 = 0; i0 < Dex.Length; i0++)
{
Dex[i0].MainOffset = _IO.P;
for (i1 = 0; i1 < Dex[i0].Main.Count; i1++)
Dex[i0].MainOffset = IO.P;
for (int i1 = 0; i1 < Dex[i0].Main.Count; i1++)
{
_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.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.W(999999f);
_IO.W(0xFFFF);
_IO.W(0x0L);
_IO.A(0x20);
IO.A(0x20, true);
Dex[i0].EyesOffset = _IO.P;
for (i1 = 0; i1 < Dex[i0].Eyes.Count; i1++)
Dex[i0].EyesOffset = IO.P;
for (int i1 = 0; i1 < Dex[i0].Eyes.Count; i1++)
{
_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.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.W(999999f);
_IO.W(0xFFFF);
_IO.W(0x0L);
_IO.A(0x20);
IO.A(0x20, true);
}
for (i = 0; i < Dex.Length; i++)
for (int i0 = 0; i0 < Dex.Length; i0++)
{
Dex[i].NameOffset = _IO.P;
_IO.W(Dex[i].Name + "\0");
Dex[i0].NameOffset = IO.P;
IO.W(Dex[i0].Name + "\0");
}
_IO.A(0x10, true);
IO.A(0x10, true);
_IO.P = header.IsX ? 0x28 : 0x20;
for (i = 0; i < Dex.Length; i++)
IO.P = Header.IsX ? 0x28 : 0x20;
for (int i0 = 0; i0 < Dex.Length; i0++)
{
_IO.WX(Dex[i].MainOffset);
_IO.WX(Dex[i].EyesOffset);
IO.WX(Dex[i0].MainOffset);
IO.WX(Dex[i0].EyesOffset);
}
int namesPosition = _IO.P;
for (i = 0; i < Dex.Length; i++)
_IO.WX(Dex[i].NameOffset);
int Position1 = IO.P;
for (int i0 = 0; i0 < Dex.Length; i0++)
IO.WX(Dex[i0].NameOffset);
_IO.P = Position0 - (header.IsX ? 8 : 4);
_IO.W(namesPosition);
IO.P = Position0 - (Header.IsX ? 8 : 4);
IO.W(Position1);
if (Format > Format.F)
{
int offset = _IO.L;
_IO.O = 0;
_IO.P = _IO.L;
_IO.WEOFC(0);
_IO.P = 0;
header.DataSize = offset;
header.SectionSize = offset;
header.Signature = 0x43505845;
_IO.W(header, true);
Offset = IO.L;
IO.O = 0;
IO.P = IO.L;
IO.WEOFC(0);
IO.P = 0;
Header.DataSize = Offset;
Header.SectionSize = Offset;
Header.Signature = 0x43505845;
IO.W(Header, true);
}
_IO.C();
IO.C();
}
public void MsgPackReader(string file, bool json)
public int MsgPackReader(string file, bool JSON)
{
Dex = null;
header = new Header();
int i0 = 0;
int i1 = 0;
this.Dex = new EXP[0];
Header = new Header();
MsgPack msgPack = file.ReadMPAllAtOnce(json);
MsgPack dex;
if ((dex = msgPack["Dex", true]).NotNull)
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
MsgPack Dex;
if ((Dex = MsgPack["Dex", true]).NotNull)
{
Dex = new EXP[dex.Array.Length];
for (i0 = 0; i0 < Dex.Length; i0++)
this.Dex = new EXP[Dex.Array.Length];
for (i0 = 0; i0 < this.Dex.Length; i0++)
{
Dex[i0] = new EXP { Name = dex[i0].RS("Name") };
this.Dex[i0] = new EXP { Name = Dex[i0].RS("Name") };
MsgPack temp;
if ((temp = dex[i0]["Main", true]).NotNull)
MsgPack Temp;
if ((Temp = MsgPack["Main", true]).NotNull)
{
Dex[i0].Main = KKdList<EXPElement>.New;
Dex[i0].Main.Capacity = temp.Array.Length;
for (i1 = 0; i1 < Dex[i0].Main.Capacity; i1++)
Dex[i0].Main.Add(EXPElement.Read(temp[i1]));
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 ((temp = dex[i0]["Eyes", true]).NotNull)
if ((Temp = MsgPack["Eyes", true]).NotNull)
{
Dex[i0].Eyes = KKdList<EXPElement>.New;
Dex[i0].Eyes.Capacity = temp.Array.Length;
for (i1 = 0; i1 < this.Dex[i0].Eyes.Capacity; i1++)
Dex[i0].Eyes.Add(EXPElement.Read(temp[i1]));
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();
Temp.Dispose();
}
}
dex.Dispose();
msgPack.Dispose();
Dex.Dispose();
MsgPack.Dispose();
return 1;
}
public void MsgPackWriter(string file, bool json)
public void MsgPackWriter(string file, bool JSON)
{
if (Dex == null || Dex.Length < 1) return;
MsgPack dex = new MsgPack(Dex.Length, "Dex");
for (i0 = 0; i0 < Dex.Length; i0++)
int i0 = 0;
int i1 = 0;
MsgPack Dex = new MsgPack(this.Dex.Length, "Dex");
for (i0 = 0; i0 < this.Dex.Length; i0++)
{
MsgPack exp = MsgPack.New.Add("Name", this.Dex[i0].Name);
MsgPack main = new MsgPack(Dex[i0].Main.Count, "Main");
for (i1 = 0; i1 < Dex[i0].Main.Count; i1++)
main[i1] = Dex[i0].Main[i1].Write();
exp.Add(main);
MsgPack 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] = this.Dex[i0].Main[i1].Write();
EXP.Add(Main);
MsgPack eyes = new MsgPack(Dex[i0].Eyes.Count, "Eyes");
for (i1 = 0; i1 < Dex[i0].Eyes.Count; i1++)
eyes[i1] = Dex[i0].Eyes[i1].Write();
exp.Add(eyes);
dex[i0] = exp;
MsgPack Eyes = new MsgPack(this.Dex[i0].Eyes.Count, "Eyes");
for (i1 = 0; i1 < this.Dex[i0].Eyes.Count; i1++)
Eyes[i1] = this.Dex[i0].Eyes[i1].Write();
EXP.Add(Eyes);
Dex[i0] = EXP;
}
dex.Write(true, file, json);
Dex.Write(true, file, JSON);
}
private bool disposed;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.Dispose(); Dex = null; header = default; disposed = true; } }
public struct EXP
{
public int MainOffset;
+26 -26
View File
@@ -14,16 +14,16 @@ namespace KKdMainLib
public static void Decrypt(this string file)
{
int streamLength, fileLength;
int StreamLength, FileLength;
byte[] encrypted, decrypted;
using (Stream _IO = File.OpenReader(file))
using (Stream IO = File.OpenReader(file))
{
if (_IO.RI64() != 0x454C494641564944) return;
if (IO.RI64() != 0x454C494641564944) return;
streamLength = _IO.RI32();
fileLength = _IO.RI32();
encrypted = _IO.RBy(streamLength);
decrypted = new byte[streamLength];
StreamLength = IO.RI32();
FileLength = IO.RI32();
encrypted = IO.RBy(StreamLength);
decrypted = new byte[StreamLength];
}
using (AesManaged crypto = new AesManaged())
@@ -32,40 +32,40 @@ namespace KKdMainLib
crypto.Mode = CipherMode.ECB; crypto.Padding = PaddingMode.Zeros;
using CryptoStream cryptoData = new CryptoStream(new MSIO.MemoryStream(encrypted),
crypto.CreateDecryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read);
cryptoData.Read(decrypted, 0, streamLength);
cryptoData.Read(decrypted, 0, StreamLength);
}
using (Stream _IO = File.OpenWriter(file, fileLength))
_IO.W(decrypted, fileLength < streamLength ? fileLength : streamLength);
using (Stream IO = File.OpenWriter(file, FileLength))
IO.W(decrypted, FileLength < StreamLength ? FileLength : StreamLength);
}
public static void Encrypt(this string file)
{
byte[] data;
using (Stream _IO = File.OpenReader(file))
data = _IO.ToArray();
byte[] In;
using (Stream IO = File.OpenReader(file))
In = IO.ToArray();
int fileLengthOrigin = data.Length;
int fileLength = fileLengthOrigin.A(16);
byte[] dataAlign = new byte[fileLength];
Array.Copy(data, dataAlign, data.Length);
data = null;
byte[] encrypted = new byte[fileLength];
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[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(dataAlign),
using CryptoStream cryptoData = new CryptoStream(new MSIO.MemoryStream(Inalign),
crypto.CreateEncryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read);
cryptoData.Read(encrypted, 0, fileLength);
cryptoData.Read(encrypted, 0, FileLength);
}
using (Stream _IO = File.OpenWriter(file, dataAlign.Length))
using (Stream IO = File.OpenWriter(file, Inalign.Length))
{
_IO.W(0x454C494641564944);
_IO.W(fileLength);
_IO.W(fileLengthOrigin);
_IO.W(encrypted);
IO.W(0x454C494641564944);
IO.W(FileLength);
IO.W(FileLengthOrigin);
IO.W(encrypted);
}
}
}
+107 -113
View File
@@ -5,13 +5,15 @@ using KKdMainLib.IO;
namespace KKdMainLib
{
public struct DataBank : IDisposable
public class DataBank
{
private Stream _IO;
public DataBank() { Success = false; IO = null; pvList = null; psrDat = null; }
private Stream IO;
private int i;
public PvList[] pvList;
public PsrData[] psrData;
private PvList[] pvList;
private psrData[] psrDat;
private const string d = ".";
private const string c = ",";
@@ -26,123 +28,117 @@ namespace KKdMainLib
while (text.Contains("%")) text = WebUtility.UrlDecode(text);
string[] array = text.Split(',');
pvList = null;
psrData = null;
if (file.Contains("psrData") && array.Length % 13 < 2)
{
psrData = new PsrData[array.Length / 13];
for (i = 0; i < psrData.Length; i++) psrData[i].SetValue(array, i);
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")) 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")) Success = true;
else if (file.Contains("PvList")) { pvList = null; Success = true; }
}
public void DBWriter(string file, uint num2)
{
if (!Success) return;
_IO = File.OpenWriter();
IO = File.OpenWriter();
if (file.Contains("psrData"))
{
if (psrData != null && psrData.Length > 0)
for (i = 0; i < psrData.Length; i++)
_IO.W(psrData[i].ToString() + c);
if (psrDat != null && psrDat.Length > 0)
for (i = 0; i < psrDat.Length; i++)
IO.W(psrDat[i].ToString() + c);
}
else if (file.Contains("PvList"))
{
if (pvList != null && pvList.Length > 0)
for (i = 0; i < pvList.Length; i++)
_IO.W(UrlEncode(pvList[i].ToString() +
IO.W(UrlEncode(pvList[i].ToString() +
(i < pvList.Length ? c : "")));
else _IO.W("%2A%2A%2A");
else IO.W("%2A%2A%2A");
}
byte[] data = _IO.ToArray(true);
byte[] data = IO.ToArray(true);
ushort num = DCC.CalculateChecksum(data);
File.WriteAllBytes(file + "_" + num + "_" + num2 + ".dat", data);
}
public void MsgPackReader(string file, bool json)
public void MsgPackReader(string file, bool JSON)
{
Success = false;
MsgPack msgPack = file.ReadMPAllAtOnce(json);
bool compact = msgPack.RB("Compact");
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
bool compact = MsgPack.RB("Compact");
psrData = null;
pvList = null;
if (file.Contains("psrData"))
{
MsgPack psrData;
if ((psrData = msgPack["psrData", true]).NotNull)
if ((psrData = MsgPack["psrData", true]).NotNull)
{
this.psrData = new PsrData[psrData.Array.Length];
for (i = 0; i < this.psrData.Length; i++)
this.psrData[i].SetValue(psrData[i]);
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();
}
else if (file.Contains("PvList"))
{
MsgPack pvList;
if ((pvList = msgPack["PvList", true]).NotNull)
MsgPack PvList;
if ((PvList = MsgPack["PvList", true]).NotNull)
{
this.pvList = new PvList[pvList.Array.Length];
for (i = 0; i < this.pvList.Length; i++)
this.pvList[i].SetValue(pvList[i], compact);
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();
PvList.Dispose();
}
msgPack.Dispose();
MsgPack.Dispose();
}
public void MsgPackWriter(string file, bool json, bool Compact = true)
public void MsgPackWriter(string file, bool JSON, bool Compact = true)
{
if (!Success) return;
MsgPack msgPack = MsgPack.New;
MsgPack MsgPack = MsgPack.New;
if (file.Contains("psrData"))
{
if (psrData != null)
if (psrDat != null)
{
MsgPack psrData = new MsgPack(this.psrData.Length, "psrData");
for (i = 0; i < this.psrData.Length; i++) psrData[i] = this.psrData[i].WriteMP();
msgPack.Add(psrData);
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));
else MsgPack.Add(new MsgPack("psrData", null));
}
else if (file.Contains("PvList"))
{
if (pvList != null)
{
if (Compact) msgPack.Add("Compact", Compact);
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);
MsgPack.Add(PvList);
}
else msgPack.Add(new MsgPack("PvList", null));
else MsgPack.Add(new MsgPack("PvList", null));
}
msgPack.Write(file, json).Dispose();
MsgPack.Write(file, JSON).Dispose();
}
public static string UrlEncode(string value) =>
WebUtility.UrlEncode(value).Replace("+", "%20");
private bool disposed;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.Dispose(); psrData = null; pvList = null; Success = false; disposed = true; } }
public struct PsrData
public struct psrData
{
public Player p1;
public Player p2;
@@ -159,15 +155,14 @@ namespace KKdMainLib
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();
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() =>
@@ -252,62 +247,61 @@ namespace KKdMainLib
PV_ID = int.Parse(data[i * 7]);
Enable = int.Parse(data[i * 7 + 1]) == 1;
Extra = int.Parse(data[i * 7 + 2]) == 1;
AdvDemoStart.SV(data[i * 7 + 3]);
AdvDemoEnd .SV(data[i * 7 + 4]);
StartShow .SV(data[i * 7 + 5]);
EndShow .SV(data[i * 7 + 6]);
AdvDemoStart.SetValue(data[i * 7 + 3]);
AdvDemoEnd .SetValue(data[i * 7 + 4]);
StartShow .SetValue(data[i * 7 + 5]);
EndShow .SetValue(data[i * 7 + 6]);
}
public void SetValue(MsgPack msg, bool Compact)
{
Enable = true;
Extra = false;
this.Enable = true;
this.Extra = false;
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) Enable = (bool)enable;
if (extra != null) 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.SV(msg.RnI32("AdvDemoStart"), true);
AdvDemoEnd .SV(msg.RnI32("AdvDemoEnd" ), false);
StartShow .SV(msg.RnI32("StartShow" ), false);
EndShow .SV(msg.RnI32( "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;
}
MsgPack temp;
if ((temp = msg["AdvDemoStart", true]).NotNull) AdvDemoStart.SV(temp, true);
if ((temp = msg["AdvDemoEnd" , true]).NotNull) AdvDemoEnd .SV(temp, false);
if ((temp = msg["StartShow" , true]).NotNull) StartShow .SV(temp, false);
if ((temp = msg[ "EndShow" , true]).NotNull) EndShow .SV(temp, true);
temp.Dispose();
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 = MsgPack.New;
msgPack.Add("ID", PV_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.WU) msgPack.Add("AdvDemoStart", AdvDemoStart.WI());
if (AdvDemoEnd .WL) msgPack.Add("AdvDemoEnd" , AdvDemoEnd .WI());
if (StartShow .WL) msgPack.Add("StartShow" , StartShow .WI());
if ( EndShow .WU) msgPack.Add( "EndShow" , EndShow .WI());
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.WU) msgPack.Add(AdvDemoStart.WriteMP("AdvDemoStart"));
if (AdvDemoEnd .WL) msgPack.Add(AdvDemoEnd .WriteMP("AdvDemoEnd" ));
if (StartShow .WL) msgPack.Add(StartShow .WriteMP("StartShow" ));
if ( EndShow .WU) 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() =>
@@ -328,13 +322,13 @@ namespace KKdMainLib
public int Day { get => day; set { day = value; CheckDate(); } }
public bool WU => Year != 2029 || Month != 1 || Day != 1;
public bool WL => Year != 2000 || Month != 1 || Day != 1;
public bool WriteUpper => Year != 2029 || Month != 1 || Day != 1;
public bool WriteLower => Year != 2000 || Month != 1 || Day != 1;
public void SDL() => Year = 2000;
public void SDU() => Year = 2029;
public void SetDefaultLower() => Year = 2000;
public void SetDefaultUpper() => Year = 2029;
public void SV(string data)
public void SetValue(string data)
{
string[] array = data.Split('-');
if (array.Length == 3)
@@ -345,23 +339,23 @@ namespace KKdMainLib
}
}
public void SV(int? ymd, bool setDefaultUpper)
public void SetValue(int? YMD, bool SetDefaultUpper)
{
if (!setDefaultUpper) SDL();
else SDU();
if (ymd != null)
if (!SetDefaultUpper) SetDefaultLower();
else this.SetDefaultUpper();
if (YMD != null)
{
year = ymd.Value / 10000;
month = ymd.Value / 100 % 100;
day = ymd.Value % 100;
year = YMD.Value / 10000;
month = YMD.Value / 100 % 100;
day = YMD.Value % 100;
CheckDate();
}
}
public void SV(MsgPack msg, bool setDefaultUpper)
public void SetValue(MsgPack msg, bool SetDefaultUpper)
{
if (!setDefaultUpper) SDL();
else SDU();
if (!SetDefaultUpper) SetDefaultLower();
else this.SetDefaultUpper();
int? Year = msg.RnI32( "Year");
int? Month = msg.RnI32("Month");
int? Day = msg.RnI32( "Day");
@@ -371,7 +365,7 @@ namespace KKdMainLib
CheckDate();
}
public int WI() =>
public int WriteInt() =>
(Year * 100 + Month) * 100 + Day;
public MsgPack WriteMP(string name) =>
+116 -118
View File
@@ -6,207 +6,205 @@ namespace KKdMainLib
{
public static class HeaderExtensions
{
public static Header ReadHeader(this Stream stream, bool seek, bool readSectionSignature = true)
public static Header ReadHeader(this Stream stream, bool Seek, bool ReadSectionSignature = true)
{
if (seek)
if (stream.PI64 > 4) stream.PI64 -= 4;
else stream.PI64 = 0;
return stream.ReadHeader(readSectionSignature);
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)
public static Header ReadHeader(this Stream stream, bool ReadSectionSignature = true)
{
Header header = new Header { Format = Format.F2LE, Signature = stream.RI32(),
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)
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();
Header.InnerSignature = stream.RI32();
stream.RI32();
stream.RI64();
}
stream.Format = header.Format;
if (readSectionSignature) header.SectionSignature = stream.RI32E();
return header;
stream.Format = Header.Format;
if (ReadSectionSignature) Header.SectionSignature = stream.RI32E();
return Header;
}
public static void W(this Stream stream, Header header, bool extended = false)
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);
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(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)
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(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(Header.InnerSignature);
stream.W(0x00);
stream.W(0x00L);
}
}
public static void WEOFC(this Stream stream, int depth = 0) =>
stream.W(new Header { Depth = depth, Length = 0x20, Signature = 0x43464F45 });
public static 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, int depth = 0)
public static void W(this Stream stream, POF POF, bool ShiftX = false)
{
byte[] data = pof.Write(shiftX);
Header header = new Header { Depth = depth, Format = Format.F2LE,
Length = 0x20, Signature = shiftX ? 0x31464F50 : 0x30464F50 };
header.DataSize = header.SectionSize = data.Length;
stream.W(header);
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, ENRS enrs, int depth = 0)
public static void W(this Stream stream, ENRSList ENRS)
{
byte[] data = enrs.Write();
Header header = new Header { Depth = depth, Format = Format.F2LE,
Length = 0x20, Signature = 0x53524E45 };
header.DataSize = header.SectionSize = data.Length;
stream.W(header);
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)
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;
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)
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;
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)
int LastSig = 0, Sig;
long Length = stream.L - stream.P;
long Position = 0;
KKdList<Struct> SubStructs = KKdList<Struct>.New;
while (Length > Position)
{
header = stream.ReadHeader(false);
sig = header.Signature;
position += header.Length + header.SectionSize;
if (sig == 0x43464F45 && header.Depth == depth + 1) break;
else if (sig == 0x53524E45 || (sig & 0xF0FFFFFF) == 0x30464F50)
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.Read(Data);
else @struct.POF .Read(Data, sig == 0x31464F50);
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 == 0 && sig == 0x43505854)
{ subStructs.Add(new Struct { Header = header, DataOffset =
stream.P, Data = stream.RBy(header.SectionSize) }); }
else if (header.Depth <= depth) { stream.PI64 -= header.Length; break; }
else subStructs.Add(stream.RSt(header));
lastSig = sig;
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;
if (SubStructs.Capacity > 0) Struct.SubStructs = SubStructs.ToArray();
return Struct;
}
public static byte[] W(this Struct Struct, bool shiftX = false, bool useDepth = true)
public static byte[] W(this Struct Struct, bool ShiftX = false)
{
byte[] Data;
using (Stream stream = File.OpenWriter()) { Struct.Update(shiftX);
stream.W(Struct, shiftX, useDepth); stream.WEOFC(); Data = stream.ToArray(); }
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, bool useDepth = true)
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, useDepth ? @struct.Depth + 1 : 0);
if (@struct.HasENRS) stream.W(@struct.ENRS, useDepth ? @struct.Depth + 1 : 0);
if (@struct.HasSubStructs)
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);
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)
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);
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)
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);
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)
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);
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 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)
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.W(mp);
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 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)
public static MsgPack WriteAfterAll(this MsgPack mp, string file, bool JSON = false)
{
byte[] data = null;
if (json) using (JSON _IO = new JSON(File.OpenWriter())) { _IO.W(mp, true); data = _IO.ToArray(); }
else using ( MP _IO = new MP(File.OpenWriter())) { _IO.W(mp ); data = _IO.ToArray(); }
File.WriteAllBytes(file + (json ? ".json" : ".mp"), data);
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;
}
@@ -219,15 +217,15 @@ namespace KKdMainLib
public static class IKFExt
{
public static IKF Round(this IKF kf, int d)
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;
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;
}
}
}
+31 -36
View File
@@ -4,64 +4,59 @@ using KKdMainLib.IO;
namespace KKdMainLib.F2
{
public struct Bloom : System.IDisposable
public struct Bloom
{
private int i;
private Stream _IO;
private Header header;
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;
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; }
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; }
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.Format = Header.Format = Format.X;
IO.Offset = Header.Length;
IO.Position = BLTs.Offset;
BLTs = IO.ReadCountPointerX<BLT>();
}*/
_IO.P = BLTs.O;
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();
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();
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");
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));
IO.W(i + "," + BLTs[i] + "\n");
File.WriteAllBytes(file + "_bloom.txt", IO.ToArray(true));
}
private bool disposed;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.Dispose(); BLTs = default; header = default; disposed = true; } }
public struct BLT
{
public Vector3 Color;
@@ -70,7 +65,7 @@ namespace KKdMainLib.F2
public override string ToString() => Color .ToString(6) + "," +
Brightpass.ToString(6) + "," +
Range .ToS(6);
Range .ToString(6);
}
}
}
+36 -41
View File
@@ -4,66 +4,61 @@ using KKdMainLib.IO;
namespace KKdMainLib.F2
{
public struct ColorCorrection : System.IDisposable
public struct ColorCorrection
{
private int i;
private Stream _IO;
private Header header;
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;
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; }
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; }
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.Format = Header.Format = Format.X;
IO.Offset = Header.Length;
IO.Position = CCTs.Offset;
CCTs = IO.ReadCountPointerX<CCT>();
}*/
_IO.P = CCTs.O;
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();
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();
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");
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));
IO.W(i + "," + CCTs[i] + "\n");
File.WriteAllBytes(file + "_cc.txt", IO.ToArray(true));
}
private bool disposed;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.Dispose(); CCTs = default; header = default; disposed = true; } }
public struct CCT
{
public float Hue;
@@ -73,12 +68,12 @@ namespace KKdMainLib.F2
public Vector3 Gamma;
public float Contrast;
public override string ToString() => Hue .ToS(6) + "," +
Saturation.ToS(6) + "," +
Lightness .ToS(6) + "," +
Exposure .ToS(6) + "," +
public override string ToString() => Hue .ToString(6) + "," +
Saturation.ToString(6) + "," +
Lightness .ToString(6) + "," +
Exposure .ToString(6) + "," +
Gamma .ToString(6) + "," +
Contrast .ToS(6);
Contrast .ToString(6);
}
}
}
+33 -38
View File
@@ -4,64 +4,59 @@ using KKdMainLib.IO;
namespace KKdMainLib.F2
{
public struct DOF : System.IDisposable
public struct DOF
{
private int i;
private Stream _IO;
private Header header;
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;
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; }
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; }
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.Format = Header.Format = Format.X;
IO.Offset = Header.Length;
IO.Position = DFTs.Offset;
DFTs = IO.ReadCountPointerX<DFT>();
}*/
_IO.P = DFTs.O;
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.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();
IO.C();
}
public void TXTWriter(string file)
{
if (DFTs.C < 1) return;
_IO = File.OpenWriter();
_IO.WPSSJIS("ID,Focus,FocusRange,FuzzingRange,Ratio,Quality\n");
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));
IO.W(i + "," + DFTs[i] + "\n");
File.WriteAllBytes(file + "_dof.txt", IO.ToArray(true));
}
private bool disposed;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.Dispose(); DFTs = default; header = default; disposed = true; } }
public struct DFT
{
public float Focus;
@@ -70,11 +65,11 @@ namespace KKdMainLib.F2
public float Ratio;
public float Quality;
public override string ToString() => Focus .ToS(6) + "," +
FocusRange.ToS(6) + "," +
FuzzingRange.ToS(6) + "," +
Ratio .ToS(6) + "," +
Quality .ToS(6);
public override string ToString() => Focus .ToString(6) + "," +
FocusRange.ToString(6) + "," +
FuzzingRange.ToString(6) + "," +
Ratio .ToString(6) + "," +
Quality .ToString(6);
}
}
}
+50 -55
View File
@@ -4,72 +4,71 @@ using KKdMainLib.IO;
namespace KKdMainLib.F2
{
public struct Light : System.IDisposable
public struct Light
{
private int i, i0;
private Stream _IO;
private Header header;
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;
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; }
LITs = IO.RCPE<CountPointer<LIT>>();
if (LITs.C < 1) { IO.C(); LITs.C = -1; return; }
_IO.P = LITs.O;
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; }
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>();
IO.Format = Header.Format = Format.X;
IO.Offset = Header.Length;
IO.Position = LITs.Offset;
LITs[i] = IO.ReadCountPointerX<LIT>();
}
if (_IO.IsX) IO.ReadInt64();*/
if (IO.IsX) IO.ReadInt64();*/
}
for (i = 0; i < LITs.C; i++)
{
_IO.P = LITs[i].O;
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(); }
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();
IO.C();
}
public void TXTWriter(string file)
@@ -77,13 +76,13 @@ namespace KKdMainLib.F2
i = 0;
if (LITs.C < 1) return;
_IO = File.OpenWriter();
_IO.WPSSJIS("Type,AmbientR,AmbientG,AmbientB,DiffuseR,DiffuseG,DiffuseB,SpecularR,SpecularG," +
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));
IO.W(LITs[i][i0] + "," + i + "\n");
File.WriteAllBytes(file + "_light.txt", IO.ToArray(true));
}
public struct LIT
@@ -97,7 +96,7 @@ namespace KKdMainLib.F2
public Vector3 Position;
public Vector3 ToneCurve;
public override string ToString() => Flags == 0 ? ",,,,,,,,,,,,,,,," : Type + "," +
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) + ",") +
@@ -105,10 +104,6 @@ namespace KKdMainLib.F2
((Flags & Flags.ToneCurve) == 0 ? ",,," : ToneCurve.ToString(6));
}
private bool disposed;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.Dispose(); LITs = default; header = default; disposed = true; } }
public enum Id : int
{
CHARA = 0,
+142 -169
View File
@@ -14,28 +14,28 @@ namespace KKdMainLib
public FARC(string File, bool IsDirectory = false)
{ if (IsDirectory) DirectoryPath = File; else FilePath = File; NewFARC(); }
private void NewFARC() { Files = KKdList<FARCFile>.New; Signature = Farc.FArC; cbc = ft = false; }
private void NewFARC() { Files = null; Signature = Farc.FArC; CBC = FT = false; }
public KKdList<FARCFile> Files = KKdList<FARCFile>.New;
public FARCFile[] Files = null;
public Type FARCType;
public Farc Signature = Farc.FArC;
public string FilePath, DirectoryPath;
public bool HasFiles => Files.IsNull ? false : Files.Count > 0;
public bool HasFiles => Files == null ? false : Files.Length > 0;
private bool cbc, ft;
private bool CBC, FT;
private readonly byte[] key = Text.ToASCII("project_diva.bin");
private readonly byte[] Key = Text.ToASCII("project_diva.bin");
private readonly byte[] keyFT = { 0x13, 0x72, 0xD5, 0x7B, 0x6E, 0x9E,
private readonly byte[] KeyFT = { 0x13, 0x72, 0xD5, 0x7B, 0x6E, 0x9E,
0x31, 0xEB, 0xA2, 0x39, 0xB8, 0x3C, 0x15, 0x57, 0xC6, 0xBB };
private AesManaged GetAes(bool isFT, byte[] iv) =>
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] };
public void UnPack(bool saveToDisk = true)
{ if (HeaderReader()) { FileReader(); if (saveToDisk) SaveToDisk(); } }
public void UnPack(bool SaveToDisk = true)
{ if (HeaderReader()) { FileReader(); if (SaveToDisk) this.SaveToDisk(); } }
public bool HeaderReader()
{
@@ -48,67 +48,65 @@ namespace KKdMainLib
if (Signature != Farc.FArc && Signature != Farc.FArC && Signature != Farc.FARC)
{ reader.Dispose(); return false; }
int headerLength = reader.RI32E(true);
int HeaderLength = reader.RI32E(true);
if (Signature == Farc.FARC)
{
FARCType = (Type)reader.RI32E(true);
reader.RI32();
int farcMode = reader.RI32E(true);
ft = farcMode == 0x10;
cbc = farcMode != 0x10 && farcMode != 0x40;
int FARCMode = reader.RI32E(true);
FT = FARCMode == 0x10;
CBC = FARCMode != 0x10 && FARCMode != 0x40;
if (cbc && (FARCType & Type.ECB) != 0)
if (CBC && FARCType.HasFlag(Type.ECB))
{
reader.Dispose();
byte[] header = new byte[headerLength - 0x08];
byte[] Header = new byte[HeaderLength - 0x08];
MSIO.FileStream stream = new MSIO.FileStream(FilePath, MSIO.FileMode.Open,
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite) { Position = 0x10 };
using (AesManaged aes = GetAes(true, null))
using (CryptoStream cryptoStream = new CryptoStream(stream,
aes.CreateDecryptor(), CryptoStreamMode.Read))
cryptoStream.Read(header, 0x00, headerLength - 0x08);
header = SkipData(header, 0x10);
reader = File.OpenReader(header);
cryptoStream.Read(Header, 0x00, HeaderLength - 0x08);
Header = SkipData(Header, 0x10);
reader = File.OpenReader(Header);
farcMode = reader.RI32E(true);
ft = farcMode == 0x10;
FARCMode = reader.RI32E(true);
FT = FARCMode == 0x10;
}
}
if (Signature == Farc.FARC)
if (reader.RI32E(true) == 1)
Files.Capacity = reader.RI32E(true);
Files = new FARCFile[reader.RI32E(true)];
reader.RI32();
if (Files.Capacity == 0)
if (Files == null)
{
int Count = 0;
long Position = reader.PI64;
while (reader.PI64 < headerLength)
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();
if (Signature == Farc.FARC && FT) reader.RI32();
Count++;
}
reader.PI64 = Position;
Files.Capacity = Count;
reader.I64P = Position;
Files = new FARCFile[Count];
}
for (int i = 0; i < Files.Capacity; i++)
for (int i = 0; i < Files.Length; i++)
{
FARCFile file = default;
file.Name = reader.NTUTF8();
file.Offset = reader.RI32E(true);
if (Signature != Farc.FArc) file.SizeComp = reader.RI32E(true);
file.SizeUnc = reader.RI32E(true);
if (Signature == Farc.FARC && ft)
file.Type = (Type)reader.RI32E(true);
Files.Add(file);
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);
}
reader.Dispose();
@@ -116,132 +114,109 @@ namespace KKdMainLib
}
private void FileReader()
{ for (int i = 0; i < Files.Count; i++) FileReader(i); }
public byte[] FileReader(string file)
{
if (!HasFiles) return null;
for (int i = 0; i < Files.Count; i++)
if (Files[i].Name.ToLower() == file.ToLower()) return FileReader(i);
return null;
}
public bool Exists(string file)
{
if (!HasFiles) return false;
for (int i = 0; i < Files.Count; i++)
if (Files[i].Name.ToLower() == file.ToLower()) return true;
return false;
}
{ for (int i = 0; i < Files.Length; i++) FileReader(i); }
public byte[] FileReader(int i)
{
if (!HasFiles) return null;
if (i >= Files.Count) return null;
FARCFile file = Files[i];
if (i >= Files.Length) return null;
if (Signature != Farc.FARC)
{
if (Signature == Farc.FArC)
using (MSIO.MemoryStream memorystream = new MSIO.MemoryStream(
File.ReadAllBytes(FilePath, file.SizeComp, file.Offset)))
File.ReadAllBytes(FilePath, Files[i].SizeComp, Files[i].Offset)))
using (GZipStream gZipStream = new GZipStream(memorystream, CompressionMode.Decompress))
{
file.Data = new byte[file.SizeUnc];
gZipStream.Read(file.Data, 0, file.SizeUnc);
Files[i].Data = new byte[Files[i].SizeUnc];
gZipStream.Read(Files[i].Data, 0, Files[i].SizeUnc);
}
else file.Data = File.ReadAllBytes(FilePath, file.SizeUnc, file.Offset);
Files[i] = file;
return file.Data;
else Files[i].Data = File.ReadAllBytes(FilePath, Files[i].SizeUnc, Files[i].Offset);
return Files[i].Data;
}
int FileSize = (FARCType & Type.ECB) != 0 || (file.Type & Type.ECB) != 0 ?
file.SizeComp.A(0x10) : file.SizeComp;
using (MSIO.FileStream stream = new MSIO.FileStream(FilePath, MSIO.FileMode.Open,
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite))
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))
{
stream.Seek(file.Offset, 0);
file.Data = new byte[FileSize];
bool encrypted = false;
if ((FARCType & Type.ECB) != 0)
if ((FT && Files[i].Type.HasFlag(Type.ECB)) || CBC)
{
if ((ft && (file.Type & Type.ECB) != 0) || cbc)
{
using (AesManaged aes = GetAes(true, null))
using (CryptoStream cryptoStream = new CryptoStream(stream,
aes.CreateDecryptor(), CryptoStreamMode.Read))
cryptoStream.Read(file.Data, 0, FileSize);
file.Data = SkipData(file.Data, 0x10);
}
else
using (AesManaged aes = GetAes(false, null))
using (CryptoStream cryptoStream = new CryptoStream(stream,
aes.CreateDecryptor(), CryptoStreamMode.Read))
cryptoStream.Read(file.Data, 0, FileSize);
encrypted = true;
}
bool compressed = false;
if (((ft && (file.Type & Type.GZip) != 0) ||
(FARCType & Type.GZip) != 0) && file.SizeUnc > 0)
{
GZipStream gZipStream = new GZipStream(encrypted ? new MSIO.MemoryStream(file.Data) :
(MSIO.Stream)stream, CompressionMode.Decompress);
byte[] Temp = new byte[file.SizeUnc];
gZipStream.Read(Temp, 0, file.SizeUnc);
file.Data = Temp;
gZipStream.Dispose();
compressed = true;
}
if (!encrypted && !compressed)
{
file.Data = new byte[file.SizeUnc];
stream.Read(file.Data, 0, file.SizeUnc);
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;
}
Files[i] = file;
return file.Data;
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.IsNull ) return;
if (DirectoryPath == "" || Files.Count < 1) return;
if (DirectoryPath == null || Files == null) return;
if (DirectoryPath == "" || Files.Length < 1) return;
MSIO.Directory.CreateDirectory(DirectoryPath);
for (int i = 0; i < Files.Count; i++)
for (int i = 0; i < Files.Length; i++)
{
FARCFile file = Files[i];
if (file.Data != null)
File.WriteAllBytes(Path.Combine(DirectoryPath, file.Name), file.Data);
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)
private byte[] SkipData(byte[] Data, int Skip)
{
byte[] skipData = new byte[data.Length - skip];
System.Array.Copy(data, skip, skipData, 0, data.Length - skip);
return skipData;
byte[] SkipData = new byte[Data.Length - Skip];
for (int i = 0; i < Data.Length - Skip; i++) SkipData[i] = Data[i + Skip];
return SkipData;
}
public void Pack(Farc signature = Farc.FArC)
public void Pack(Farc Signature = Farc.FArC)
{
NewFARC();
string[] files = Directory.GetFiles(DirectoryPath);
Files.Capacity = files.Length;
Files = new FARCFile[files.Length];
for (int i = 0; i < files.Length; i++)
Files.Add(new FARCFile { Name = Path.GetFileName(files[i]), Data = File.ReadAllBytes(files[i]) });
Files[i] = new FARCFile { Name = Path.GetFileName(files[i]), Data = File.ReadAllBytes(files[i]) };
files = null;
Signature = signature;
this.Signature = Signature;
Save();
}
public void Save()
{
if (!HasFiles) return;
for (int i = 0; i < Files.Count; i++)
for (int i = 0; i < Files.Length; i++)
{
string ext = Path.GetExtension(Files[i].Name).ToLower();
if (ext == ".a3da" || ext == ".diva" || ext == ".vag")
@@ -251,90 +226,88 @@ namespace KKdMainLib
Stream writer = File.OpenWriter(DirectoryPath + ".farc", true);
writer.WE((int)Signature, true);
using (Stream headerWriter = File.OpenWriter())
using (Stream HeaderWriter = File.OpenWriter())
{
if (Signature == Farc.FArc) headerWriter.WE(0x20, true);
else if (Signature == Farc.FArC) headerWriter.WE(0x10, true);
if (Signature == Farc.FArc) HeaderWriter.WE(0x20, true);
else if (Signature == Farc.FArC) HeaderWriter.WE(0x10, true);
else if (Signature == Farc.FARC)
{
headerWriter.WE((int)FARCType, true);
headerWriter.W (0x00);
headerWriter.WE(0x40, true);
headerWriter.W (0x00);
HeaderWriter.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.Count; i++)
headerWriter.L += Path.GetFileName(Files[i].Name).Length + HeaderPartLength + 1;
writer.WE(headerWriter.L, true);
writer.W(headerWriter.ToArray(true));
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.A(0x10) - writer.P;
for (int i1 = 0; i1 < align; i1++)
int Align = writer.P.Align(0x10) - writer.P;
for (int i1 = 0; i1 < Align; i1++)
writer.W((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
for (int i = 0; i < Files.Count; i++)
CompressStuff(i, ref writer);
for (int i = 0; i < Files.Length; i++)
CompressStuff(i, ref Files, ref writer);
writer.P = Signature == Farc.FARC ? 0x1C : 0x0C;
for (int i = 0; i < Files.Count; i++)
for (int i = 0; i < Files.Length; i++)
{
FARCFile file = Files[i];
writer.W(Path.GetFileName(file.Name) + "\0");
writer.WE(file.Offset, true);
writer.W(Path.GetFileName(Files[i].Name) + "\0");
writer.WE(Files[i].Offset, true);
if (Signature != Farc.FArc)
writer.WE(file.SizeComp, true);
writer.WE(file.SizeUnc, true);
writer.WE(Files[i].SizeComp, true);
writer.WE(Files[i].SizeUnc, true);
}
writer.Dispose();
}
private void CompressStuff(int i, ref Stream writer)
private void CompressStuff(int i, ref FARCFile[] Files, ref Stream writer)
{
FARCFile file = Files[i];
file.Offset = writer.P;
file.SizeUnc = file.Data.Length;
file.Type = Type.None;
Files[i].Offset = writer.P;
Files[i].SizeUnc = Files[i].Data.Length;
Files[i].Type = Type.None;
byte[] data = file.Data;
if (Signature == Farc.FArC || (Signature == Farc.FARC && (FARCType & Type.GZip) != 0))
if (Signature == Farc.FArC || (Signature == Farc.FARC && FARCType.HasFlag(Type.GZip)))
{
file.Type |= Type.GZip;
Files[i].Type |= Type.GZip;
MSIO.MemoryStream stream = new MSIO.MemoryStream();
using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Compress))
gZipStream.Write(file.Data, 0, file.Data.Length);
data = stream.ToArray();
gZipStream.Write(Files[i].Data, 0, Files[i].Data.Length);
Files[i].Data = stream.ToArray();
stream.Dispose();
file.SizeComp = data.Length;
Files[i].SizeComp = Files[i].Data.Length;
}
if (Signature == Farc.FARC && (FARCType & Type.ECB) != 0)
if (Signature == Farc.FARC && FARCType.HasFlag(Type.ECB))
{
int alignLength = data.Length.A(0x40);
byte[] tempData = new byte[alignLength];
System.Array.Copy(data, tempData, data.Length);
for (int i1 = file.Data.Length; i1 < alignLength; i1++) tempData[i1] = 0x78;
data = Encrypt(tempData, false);
file.SizeComp = data.Length;
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(data);
writer.W(Files[i].Data);
Files[i].Data = null;
if (Signature != Farc.FARC)
{
int Align = writer.P.A(0x10) - writer.P;
int Align = writer.P.Align(0x20) - writer.P;
for (int i1 = 0; i1 < Align; i1++)
writer.W((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
}
Files[i] = file;
}
private byte[] Encrypt(byte[] data, bool isFT)
private byte[] Encrypt(byte[] Data, bool isFT)
{
MSIO.MemoryStream stream = new MSIO.MemoryStream();
using (AesManaged aes = GetAes(isFT, null))
using (CryptoStream cryptoStream = new CryptoStream(stream,
aes.CreateEncryptor(), CryptoStreamMode.Write))
cryptoStream.Write(data, 0, data.Length);
cryptoStream.Write(Data, 0, Data.Length);
return stream.ToArray();
}
+43 -43
View File
@@ -5,29 +5,29 @@ 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)
public static string NTASCII(this Stream stream, byte End = 0) =>
stream.NT(End).ToASCII();
public static string NTUTF8 (this Stream stream, byte End = 0) =>
stream.NT(End).ToUTF8 ();
public static byte[] NT (this Stream stream, byte End = 0)
{
KKdList<byte> s = KKdList<byte>.New;
while (stream.PI64 < stream.LI64)
while (stream.I64P < stream.I64L)
{
byte a = stream.RU8();
if (a == end) break;
if (a == End) break;
else s.Add(a);
}
return s.ToArray();
}
public static byte PB (this Stream stream)
{ byte val = stream.RU8(); stream.PI64--; return val; }
{ byte val = stream.RU8(); stream.I64P--; return val; }
public static char PCASCII(this Stream stream)
{ byte val = stream.RU8(); stream.PI64--; return (char)val; }
{ byte val = stream.RU8(); stream.I64P--; return (char)val; }
public static char PCUTF8 (this Stream stream)
{ long LongPosition = stream.PI64; char val = stream.RCUTF8();
stream.PI64 = LongPosition; return val; }
{ long LongPosition = stream.I64P; char val = stream.RCUTF8();
stream.I64P = LongPosition; return val; }
public static Stream SW(this Stream stream)
{
@@ -37,37 +37,37 @@ namespace KKdMainLib.IO
return stream;
}
public static bool As(this Stream stream, byte next)
{ if (stream.PB() == next) { stream.PB(); return true; } else return false; }
public static bool As(this Stream stream, byte[] next)
{
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 (!As(stream, next[i])) return false;
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 AsASCII(this Stream stream, char next)
{ if (stream.PCUTF8() == next) { stream.RCUTF8(); return true; } else return false; }
public static bool AsASCII(this Stream stream, string next)
{
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 (!stream.AsASCII(next[i])) return false;
if (!A(stream, next[i])) return false;
return true;
}
public static bool As(this Stream stream, char next)
{ if (stream.PCUTF8() == next) { stream.RCUTF8(); return true; } else return false; }
public static bool As(this Stream stream, string next)
{
for (var i = 0; i < next.Length; i++)
if (!As(stream, next[i])) return false;
return true;
}
}
public static long RIX(this Stream stream ) => stream.IsX ?
stream.RI64() : stream.RU32E( );
public static long RIX(this Stream stream, bool isBE) => stream.IsX ?
stream.RI64() : stream.RU32E(isBE);
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);
@@ -86,24 +86,24 @@ namespace KKdMainLib.IO
public static byte[] RaO(this Stream stream, long Offset = -1, long Length = -1)
{
byte[] arr = null;
long Position = stream.PI64;
long Position = stream.I64P;
if (Offset == -1) { Position += stream.IsX ? 8 : 4; Offset = stream.RIX(); }
stream.PI64 = Offset;
stream.I64P = Offset;
if (Length == -1) arr = stream.NT();
else arr = stream.RBy(Length);
stream.PI64 = Position;
stream.I64P = Position;
return arr;
}
public static string RSaO(this Stream stream, long Offset = -1, long Length = -1)
{
string s = null;
long Position = stream.PI64;
long Position = stream.I64P;
if (Offset == -1) { Position += stream.IsX ? 8 : 4; Offset = stream.RIX(); }
stream.PI64 = Offset;
stream.I64P = Offset;
if (Length == -1) s = stream.NTUTF8();
else s = stream.RSUTF8(Length);
stream.PI64 = Position;
stream.I64P = Position;
return s;
}
@@ -114,7 +114,7 @@ namespace KKdMainLib.IO
public static void WPSSJIS(this Stream stream, ref Pointer<string> val)
{ val.O = stream.P; stream.WPSSJIS(val.V); }
public static string RPSSJIS(this Stream stream, long Offset = -1, long Length = -1) =>
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) =>
+16 -29
View File
@@ -6,61 +6,48 @@ namespace KKdMainLib.IO
public static class File
{
public static Stream OpenReader(byte[] Data) => new Stream(new MSIO.MemoryStream(Data));
public static Stream OpenWriter(byte[] Data) => new Stream(new MSIO.MemoryStream(Data));
public static Stream OpenWriter( ) => new Stream(new MSIO.MemoryStream( ));
public static Stream OpenReader(string file, bool ReadAllAtOnce)
{ Stream _IO = OpenReader(file); if (ReadAllAtOnce) { byte[] data =
_IO.ToArray(); _IO.Dispose(); return OpenReader(data); } return _IO; }
{ Stream IO = OpenReader(file); if (ReadAllAtOnce) { byte[] data =
IO.ToArray(); IO.Dispose(); return OpenReader(data); } return IO; }
public static Stream OpenReader(string file)
{ Stream _IO = new Stream(new MSIO.FileStream(file, MSIO.FileMode.Open, MSIO.FileAccess.ReadWrite,
MSIO.FileShare.ReadWrite)) { File = file }; return _IO; }
{ Stream IO = new Stream(new MSIO.FileStream(file, MSIO.FileMode.Open, MSIO.FileAccess.ReadWrite,
MSIO.FileShare.ReadWrite)) { File = file }; return IO; }
public static Stream OpenWriter(string file, bool SetLength0)
{ Stream _IO = OpenWriter(file); if (SetLength0) _IO.SL(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.SL(SetLength); return _IO; }
{ Stream IO = OpenWriter(file); IO.SL(SetLength); return IO; }
public static Stream OpenWriter(string file)
{ Stream _IO = new Stream(new MSIO.FileStream(file,
{ Stream IO = new Stream(new MSIO.FileStream(file,
MSIO.FileMode.OpenOrCreate, MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite)) { File = file };
MSIO.File. SetCreationTimeUtc(file, DateTime.UtcNow);
MSIO.File. SetLastWriteTimeUtc(file, DateTime.UtcNow);
MSIO.File.SetLastAccessTimeUtc(file, DateTime.UtcNow); return _IO; }
MSIO.File.SetLastAccessTimeUtc(file, DateTime.UtcNow); return IO; }
public static byte[] ReadAllBytes(string file, int length, int offset)
{ byte[] Data; using (Stream _IO = OpenReader(file)) Data = _IO.RBy(length, offset); return Data; }
{ byte[] Data; using (Stream IO = OpenReader(file)) Data = IO.RBy(length, offset); return Data; }
public static byte[] ReadAllBytes(string file)
{ byte[] Data; using (Stream _IO = OpenReader(file)) Data = _IO.RBy(_IO.L); return Data; }
{ byte[] Data; using (Stream IO = OpenReader(file)) Data = IO.RBy(IO.L); return Data; }
public static string ReadAllText (string file)
{ string Data; using (Stream _IO = OpenReader(file)) Data = _IO.RSUTF8(_IO.L);
{ string Data; using (Stream IO = OpenReader(file)) Data = IO.RSUTF8(IO.L);
return Data.Replace(((char)0xFEFF).ToString(), ""); }
public static string[] ReadAllLines(string file)
{ string Data; using (Stream _IO = OpenReader(file)) Data = _IO.RSUTF8(_IO.L);
{ 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)
{ using Stream _IO = OpenWriter(file, true); if (data != null) _IO.W(data); }
{ using (Stream IO = OpenWriter(file, true)) IO.W(data); }
public static void WriteAllText (string file, string data)
{ using Stream _IO = OpenWriter(file, true); if (data != null) _IO.W(data); }
{ using (Stream IO = OpenWriter(file, true)) IO.W(data); }
public static void WriteAllLines(string file, string[] data)
{ using Stream _IO = OpenWriter(file, true);
if (data != null) for (int i = 0; i < data.Length; i++)
if (data[i] != null) _IO.W(data[i] + "\r\n"); }
public static void WriteAllBytes(string file, byte[] data, long length)
{ using Stream _IO = OpenWriter(file, true); if (data != null) { _IO.W(data); _IO.LI64 = length; } }
public static void WriteAllText (string file, string data, long length)
{ using Stream _IO = OpenWriter(file, true); if (data != null) { _IO.W(data); _IO.LI64 = length; } }
public static void WriteAllLines(string file, string[] data, long length)
{ using Stream _IO = OpenWriter(file, true);
if (data != null) { for (int i = 0; i < data.Length; i++)
if (data[i] != null) _IO.W(data[i] + "\r\n"); } _IO.LI64 = length; }
{ 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);
+109 -111
View File
@@ -7,7 +7,7 @@ namespace KKdMainLib.IO
{
public struct JSON : System.IDisposable
{
public JSON(Stream _IO) => this._IO = _IO;
public JSON(Stream IO) => _IO = IO;
private Stream _IO;
@@ -22,69 +22,68 @@ namespace KKdMainLib.IO
char c = _IO.SW().PCUTF8();
object obj = null;
if (char.IsDigit(c))
obj = RF();
obj = RF ();
else
obj = c switch
switch (c)
{
'"' => RS (),
'{' => RO (),
'[' => RA (),
'-' => RF (),
't' => RBo(),
'f' => RBo(),
'n' => RN (),
_ => null ,
};
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.As(_IO, '"')) return null;
private string RS()
{
if (!Extensions.A(_IO, '"')) return null;
char c;
string s = "";
while (true)
{
while (true)
{
c = _IO.RCUTF8();
if (c == '\\')
{
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;
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))
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;
}
return s;
}
private char RUL() =>
private char RUL() =>
(char)((((((RHD() << 4) | RHD()) << 4) | RHD()) << 4) | RHD());
private int RHD() => byte.Parse(_IO.RCUTF8().ToString(),
private int RHD() => byte.Parse(_IO.RCUTF8().ToString(),
System.Globalization.NumberStyles.HexNumber);
private KKdList<MsgPack> RO()
{
KKdList<MsgPack> obj = KKdList<MsgPack>.New;
if (!Extensions.As(_IO, '{')) return KKdList<MsgPack>.Null;
if (_IO.SW().PCUTF8() == '}')
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;
@@ -94,50 +93,49 @@ namespace KKdMainLib.IO
_IO.SW();
key = RS();
if (!Extensions.As(_IO.SW(), ':'))
if (!Extensions.A(_IO.SW(), ':'))
return KKdList<MsgPack>.Null;
obj.Add(ReadValue(key));
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;
}
return Obj;
}
private MsgPack[] RA()
{
KKdList<MsgPack> obj = KKdList<MsgPack>.New;
if (!Extensions.As(_IO, '[')) return null;
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));
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();
}
return Obj.ToArray();
}
private object RF()
{
string s = " ";
private object RF()
{
string s = " ";
_IO.SW();
if (_IO.PCUTF8() == '-') s += _IO.RCUTF8();
if (_IO.PCUTF8() == '0') s += _IO.RCUTF8();
else s += RD ();
char c = _IO.PCUTF8();
if (c == '.') s += _IO.RCUTF8() + RD();
else if (c != 'e' && c != 'E')
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;
@@ -149,90 +147,90 @@ namespace KKdMainLib.IO
else return val;
}
c = _IO.PCUTF8();
char c = _IO.PCUTF8();
if (c == 'e' || c == 'E')
{
{
s += _IO.RCUTF8();
c = _IO.PCUTF8();
if (c == '+' || c == '-') s += _IO.RCUTF8();
s += RD();
}
double d = s.ToF64();
s += ReadDigits();
}
double d = s.ToDouble();
return (float)d == d ? (float)d : d;
}
private bool RBo()
private bool RBo()
{
char c = _IO.PCUTF8();
if (c == 't' && _IO.As( "true")) return true;
else if (c == 'f' && _IO.As("false")) return false;
if (c == 't' && _IO.a( "true")) return true;
else if (c == 'f' && _IO.a("false")) return false;
return false;
}
private object RN() { _IO.As("null"); return null; }
private object RN() { _IO.a("null"); return null; }
private string RD()
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, string End = "\n", string TabChar = " ") =>
W(MsgPack, End, TabChar, "", true);
public JSON W(MsgPack msgPack, bool style = false) =>
W(msgPack, "\n", " ", "", style);
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)
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; }
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)
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(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);
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)
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(Tab);
W(MsgPack.List[0], End, TabChar, Tab, Style);
if (Style) _IO.W(End);
}
if (style) _IO.W(oldTab);
if (Style) _IO.W(OldTab);
WM(true);
}
else if (msgPack.Array != null)
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(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);
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)
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(Tab);
W(MsgPack.Array[0], End, TabChar, Tab, Style, true);
if (Style) _IO.W(End);
}
if (style) _IO.W(oldTab);
if (Style) _IO.W(OldTab);
WA(true);
}
else if (msgPack.Object is MsgPack msg) W(msg, end, tabChar, tab, style);
else if (msgPack.Object is string str) W(str);
else _IO.W(BaseExtensions.ToS(msgPack.Object));
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;
}
+94 -91
View File
@@ -4,7 +4,7 @@ namespace KKdMainLib.IO
{
public struct MP : System.IDisposable
{
public MP(Stream _IO) => this._IO = _IO;
public MP(Stream IO) => _IO = IO;
private Stream _IO;
@@ -12,164 +12,164 @@ namespace KKdMainLib.IO
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
public MsgPack Read(bool array = false)
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;
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)
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));
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)
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);
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 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;
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;
return MsgPack;
}
private bool RI(ref MsgPack msgPack, ref Types type)
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);
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)
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);
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)
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);
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)
private bool RBo(ref MsgPack MsgPack, ref Types Type)
{
if (type == Types.False) msgPack.Object = false;
else if (type == Types.True ) msgPack.Object = true ;
if (Type == Types.False) MsgPack.Object = false;
else if (Type == Types.True ) MsgPack.Object = true ;
else return false;
return true;
}
private bool RBy(ref MsgPack msgPack, ref Types type)
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);
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);
MsgPack.Object = _IO.RBy(Length);
return true;
}
private bool RS(ref MsgPack msgPack, ref Types type)
private bool RS(ref MsgPack MsgPack, ref Types Type)
{
string val = RS(type);
if (val != null) msgPack.Object = val;
string val = RS(Type);
if (val != null) MsgPack.Object = val;
else return false;
return true;
}
private string RS(Types val)
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 )
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);
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);
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)
private bool RN(ref MsgPack MsgPack, ref Types Type)
{
if (type == Types.Nil) msgPack.Object = null;
if (Type == Types.Nil) MsgPack.Object = null;
else return false;
return true;
}
private bool RA(ref MsgPack msgPack, ref Types type)
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);
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);
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)
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);
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());
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)
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);
if (Type == Types.FixExt1 ) Length = 1 ;
else if (Type == Types.FixExt2 ) Length = 2 ;
else if (Type == Types.FixExt4 ) Length = 4 ;
else if (Type == Types.FixExt8 ) Length = 8 ;
else if (Type == Types.FixExt16) Length = 16;
else if (Type == Types. Ext8 ) Length = _IO.RU8();
else if (Type == Types. Ext16) Length = _IO.RI16E(true);
else if (Type == Types. Ext32) Length = _IO.RI32E(true);
else return false;
MsgPack.Object = new MsgPack.Ext { Type = _IO.RI8(), Data = _IO.RBy(Length) };
return true;
}
public MP W(MsgPack msgPack, bool IsArray = false)
public MP Write(MsgPack MsgPack, bool IsArray = false)
{
if (msgPack.Name != null && !IsArray) W(msgPack.Name);
Write(msgPack.Object);
if (MsgPack.Name != null && !IsArray) W(MsgPack.Name);
Write(MsgPack.Object);
return this;
}
@@ -179,10 +179,10 @@ namespace KKdMainLib.IO
switch (obj)
{
case KKdList<MsgPack> val: WM(val.Count );
for (int i = 0; i < val.Count ; i++) W(val[i]); break;
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++) W(val[i]); break;
case MsgPack val: W(val); break;
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;
@@ -230,12 +230,15 @@ namespace KKdMainLib.IO
{
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); }
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; }
@@ -257,7 +260,7 @@ namespace KKdMainLib.IO
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; }
+147 -220
View File
@@ -1,166 +1,153 @@
using System;
using KKdBaseLib;
using MSIO = System.IO;
using ENRSDict = System.Collections.Generic.Dictionary<long, int>;
namespace KKdMainLib.IO
{
public unsafe class Stream : IDisposable
{
private MSIO.Stream stream;
private int I, i, BitRead, BitWrite, TempBitRead, TempBitWrite, ValRead, ValWrite;
private byte[] b;
private MSIO.Stream s;
private byte[] buf;
private byte* ptr;
private bool getENRS;
private Format format = Format.NULL;
private Format _format = Format.NULL;
public Format Format
{ get => format;
set { format = value;
IsBE = format == Format.F2BE;
IsX = format == Format.X || format == Format.XHD; } }
public ENRSDict ENRSDict;
{ get => _format;
set { _format = value;
IsBE = _format == Format.F2BE;
IsX = _format == Format.X || _format == Format.XHD; } }
public bool IsBE = false;
public bool IsX = false;
public bool GetENRS
{ get => getENRS;
set { if (value && ENRSDict == null)
ENRSDict = new ENRSDict(); getENRS = value; } }
public int O { get => ( int)OI64; set => OI64 = value; }
public uint OU32 { get => (uint)OI64; set => OI64 = value; }
public long OI64;
public int O { get => ( int)I64O; set => I64O = value; }
public uint U32O { get => (uint)I64O; set => I64O = value; }
public long I64O;
public int L { get => ( int)s.Length - O; set => s.SetLength(value + O); }
public uint LU32 { get => (uint)s.Length - OU32; set => s.SetLength(value + OU32); }
public long LI64 { get => s.Length - OI64; set => s.SetLength(value + OI64); }
public int 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 P
{ get => ( int)s.Position - O; set => s.Position = value + O; }
public uint PU32
{ get => (uint)s.Position - OU32; set => s.Position = value + OU32; }
public long PI64
{ get => s.Position - OI64; set => s.Position = value + OI64; }
public 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 => s.CanRead;
public bool CanSeek => s.CanSeek;
public bool CanTimeout => s.CanTimeout;
public bool CanWrite => s.CanWrite;
public bool CanRead => stream.CanRead;
public bool CanSeek => stream.CanSeek;
public bool CanTimeout => stream.CanTimeout;
public bool CanWrite => stream.CanWrite;
public string File = null;
public Stream(MSIO.Stream output = null, bool isBE = false)
{
if (output == null) output = MSIO.Stream.Null;
OI64 = 0;
I64O = 0;
BitRead = 8;
ValRead = ValRead = BitWrite = 0;
s = output;
stream = output;
Format = Format.NULL;
b = new byte[0x100];
this.IsBE = isBE;
buf = new byte[0x100];
ptr = buf.GetPtr();
IsBE = isBE;
}
public void C() => D(true);
public void F() => s.Flush();
public void F() => stream.Flush();
public void SL(long length = 0) => s.SetLength(length);
public void SL(long length = 0) => stream.SetLength(length);
public long S(long offset, SeekOrigin origin = 0) =>
s.Seek(offset + O, (MSIO.SeekOrigin)(int)origin);
stream.Seek(offset, (MSIO.SeekOrigin)(int)origin);
public long? S(long? offset, SeekOrigin origin)
{ if (offset == null) return null;
return s.Seek((long)offset + O, (MSIO.SeekOrigin)(int)origin); }
{ if (offset == null) return null; return stream.Seek((long)offset, (MSIO.SeekOrigin)(int)origin); }
private bool disposed = false;
public void D() => D(true);
public void Dispose() => D(true);
protected virtual void D(bool dispose)
{ CW(); if (ENRSDict != null) { ENRSDict.Clear(); ENRSDict = null; }
if (s != MSIO.Stream.Null && !disposed) { disposed = true; s.Flush();
s.Dispose(); } if (dispose) GC.SuppressFinalize(this); }
{ CW(); if (stream != MSIO.Stream.Null && !disposed) { disposed = true; stream.Flush();
stream.Dispose(); } if (dispose) GC.SuppressFinalize(this); }
public MSIO.Stream BS
{ get { s.Flush(); return s; } set { s = value; } }
{ get { stream.Flush(); return stream; } set { stream = value; } }
public void A(long align)
public void A(long Align)
{
long Al = align - P % align;
if (P % align != 0) s.Seek(P + O + Al, 0);
long Al = Align - P % Align;
if (P % Align != 0) stream.Seek(P + O + Al, 0);
}
public void A(long align, bool SetLength)
public void A(long Align, bool SetLength)
{
if (SetLength) s.SetLength(P + O);
long Al = align - P % align;
if (P % align != 0) s.Seek(P + O + Al, 0);
if (SetLength) s.SetLength(P + O);
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 A(long align, bool setLength0, bool setLength1)
public void A(long Align, bool SetLength0, bool SetLength1)
{
if (setLength0) s.SetLength(P + O);
long Al = align - P % align;
if (P % align != 0) s.Seek(P + Al, 0);
if (setLength1) s.SetLength(P + O);
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 RBo () => s.ReadByte() != 0;
public sbyte RI8 () => (sbyte)s.ReadByte();
public byte RU8 () => ( byte)s.ReadByte();
public short RI16() { s.Read(b, 0, 2); return b.TI16(); }
public ushort RU16() { s.Read(b, 0, 2); return b.TU16(); }
public int RI32() { s.Read(b, 0, 4); return b.TI32(); }
public uint RU32() { s.Read(b, 0, 4); return b.TU32(); }
public long RI64() { s.Read(b, 0, 8); return b.TI64(); }
public ulong RU64() { s.Read(b, 0, 8); return b.TU64(); }
public float RF32() { s.Read(b, 0, 4); return b.TF32(); }
public double RF64() { s.Read(b, 0, 8); return b.TF64(); }
public 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 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 RI16E() { s.Read(b, 0, 2); b.E(2, IsBE); return b.TI16(); }
public ushort RU16E() { s.Read(b, 0, 2); b.E(2, IsBE); return b.TU16(); }
public int RI32E() { s.Read(b, 0, 4); b.E(4, IsBE); return b.TI32(); }
public uint RU32E() { s.Read(b, 0, 4); b.E(4, IsBE); return b.TU32(); }
public long RI64E() { s.Read(b, 0, 8); b.E(8, IsBE); return b.TI64(); }
public ulong RU64E() { s.Read(b, 0, 8); b.E(8, IsBE); return b.TU64(); }
public float RF32E() { s.Read(b, 0, 4); b.E(4, IsBE); return b.TF32(); }
public double RF64E() { s.Read(b, 0, 8); b.E(8, IsBE); return b.TF64(); }
public 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 short RI16E(bool isBE) { s.Read(b, 0, 2); b.E(2, isBE); return b.TI16(); }
public ushort RU16E(bool isBE) { s.Read(b, 0, 2); b.E(2, isBE); return b.TU16(); }
public int RI32E(bool isBE) { s.Read(b, 0, 4); b.E(4, isBE); return b.TI32(); }
public uint RU32E(bool isBE) { s.Read(b, 0, 4); b.E(4, isBE); return b.TU32(); }
public long RI64E(bool isBE) { s.Read(b, 0, 8); b.E(8, isBE); return b.TI64(); }
public ulong RU64E(bool isBE) { s.Read(b, 0, 8); b.E(8, isBE); return b.TU64(); }
public float RF32E(bool isBE) { s.Read(b, 0, 4); b.E(4, isBE); return b.TF32(); }
public double RF64E(bool isBE) { s.Read(b, 0, 8); b.E(8, isBE); return b.TF64(); }
public void 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 W(byte[] Val ) =>
s.Write(Val ?? new byte[0], 0, Val.Length);
public void W(byte[] Val, int Length) =>
s.Write(Val ?? new byte[0], 0, Length);
public void W(byte[] Val, int Offset, int Length) =>
s.Write(Val ?? new byte[0], Offset, Length);
public void W(char[] val, bool UTF8 = true) =>
W(UTF8 ? val.ToUTF8() : val.ToASCII());
public void W( bool val) => s.WriteByte((byte)(val ? 1 : 0));
public void W( sbyte val) => s.WriteByte((byte) val);
public void W( byte val) => s.WriteByte( val);
public void W( short val) { b.GBy(val); s.Write(b, 0, 2); }
public void W(ushort val) { b.GBy(val); s.Write(b, 0, 2); }
public void W( int val) { b.GBy(val); s.Write(b, 0, 4); }
public void W( uint val) { b.GBy(val); s.Write(b, 0, 4); }
public void W( long val) { b.GBy(val); s.Write(b, 0, 8); }
public void W( ulong val) { b.GBy(val); s.Write(b, 0, 8); }
public void W( float val) { b.GBy(val); s.Write(b, 0, 4); }
public void W(double val) { b.GBy(val); s.Write(b, 0, 8); }
public void 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 W( sbyte? val) => W(val ?? default);
public void W( byte? val) => W(val ?? default);
@@ -173,104 +160,37 @@ namespace KKdMainLib.IO
public void W( float? val) => W(val ?? default);
public void W(double? val) => W(val ?? default);
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 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 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) { b.GBy(val); b.E(2, IsBE); s.Write(b, 0, 2); }
public void WE(ushort val) { b.GBy(val); b.E(2, IsBE); s.Write(b, 0, 2); }
public void WE( int val) { b.GBy(val); b.E(4, IsBE); s.Write(b, 0, 4); }
public void WE( uint val) { b.GBy(val); b.E(4, IsBE); s.Write(b, 0, 4); }
public void WE( long val) { b.GBy(val); b.E(8, IsBE); s.Write(b, 0, 8); }
public void WE( ulong val) { b.GBy(val); b.E(8, IsBE); s.Write(b, 0, 8); }
public void WE( float val) { b.GBy(val); b.E(4, IsBE); s.Write(b, 0, 4); }
public void WE(double val) { b.GBy(val); b.E(8, IsBE); s.Write(b, 0, 8); }
public void 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 WE( short val, bool isBE) { b.GBy(val); b.E(2, isBE); s.Write(b, 0, 2); }
public void WE(ushort val, bool isBE) { b.GBy(val); b.E(2, isBE); s.Write(b, 0, 2); }
public void WE( int val, bool isBE) { b.GBy(val); b.E(4, isBE); s.Write(b, 0, 4); }
public void WE( uint val, bool isBE) { b.GBy(val); b.E(4, isBE); s.Write(b, 0, 4); }
public void WE( long val, bool isBE) { b.GBy(val); b.E(8, isBE); s.Write(b, 0, 8); }
public void WE( ulong val, bool isBE) { b.GBy(val); b.E(8, isBE); s.Write(b, 0, 8); }
public void WE( float val, bool isBE) { b.GBy(val); b.E(4, isBE); s.Write(b, 0, 4); }
public void WE(double val, bool isBE) { b.GBy(val); b.E(8, isBE); s.Write(b, 0, 8); }
public 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; }
private void RENRS(byte[] b, int c)
{ if (getENRS) ENRSDict.Add(P, c); s.Read(b, 0, c); }
public short RI16ENRS() { RENRS(b, 2); return b.TI16(); }
public ushort RU16ENRS() { RENRS(b, 2); return b.TU16(); }
public int RI32ENRS() { RENRS(b, 4); return b.TI32(); }
public uint RU32ENRS() { RENRS(b, 4); return b.TU32(); }
public long RI64ENRS() { RENRS(b, 8); return b.TI64(); }
public ulong RU64ENRS() { RENRS(b, 8); return b.TU64(); }
public float RF32ENRS() { RENRS(b, 4); return b.TF32(); }
public double RF64ENRS() { RENRS(b, 8); return b.TF64(); }
public short RI16ENRSE() { RENRS(b, 2); b.E(2, IsBE); return b.TI16(); }
public ushort RU16ENRSE() { RENRS(b, 2); b.E(2, IsBE); return b.TU16(); }
public int RI32ENRSE() { RENRS(b, 4); b.E(4, IsBE); return b.TI32(); }
public uint RU32ENRSE() { RENRS(b, 4); b.E(4, IsBE); return b.TU32(); }
public long RI64ENRSE() { RENRS(b, 8); b.E(8, IsBE); return b.TI64(); }
public ulong RU64ENRSE() { RENRS(b, 8); b.E(8, IsBE); return b.TU64(); }
public float RF32ENRSE() { RENRS(b, 4); b.E(4, IsBE); return b.TF32(); }
public double RF64ENRSE() { RENRS(b, 8); b.E(8, IsBE); return b.TF64(); }
public short RI16ENRSE(bool isBE) { RENRS(b, 2); b.E(2, isBE); return b.TI16(); }
public ushort RU16ENRSE(bool isBE) { RENRS(b, 2); b.E(2, isBE); return b.TU16(); }
public int RI32ENRSE(bool isBE) { RENRS(b, 4); b.E(4, isBE); return b.TI32(); }
public uint RU32ENRSE(bool isBE) { RENRS(b, 4); b.E(4, isBE); return b.TU32(); }
public long RI64ENRSE(bool isBE) { RENRS(b, 8); b.E(8, isBE); return b.TI64(); }
public ulong RU64ENRSE(bool isBE) { RENRS(b, 8); b.E(8, isBE); return b.TU64(); }
public float RF32ENRSE(bool isBE) { RENRS(b, 4); b.E(4, isBE); return b.TF32(); }
public double RF64ENRSE(bool isBE) { RENRS(b, 8); b.E(8, isBE); return b.TF64(); }
private void WENRS(byte[] b, int c)
{ if (getENRS) ENRSDict.Add(P, c); s.Write(b, 0, c); }
public void WENRS( short val) { b.GBy(val); WENRS(b, 2); }
public void WENRS(ushort val) { b.GBy(val); WENRS(b, 2); }
public void WENRS( int val) { b.GBy(val); WENRS(b, 4); }
public void WENRS( uint val) { b.GBy(val); WENRS(b, 4); }
public void WENRS( long val) { b.GBy(val); WENRS(b, 8); }
public void WENRS( ulong val) { b.GBy(val); WENRS(b, 8); }
public void WENRS( float val) { b.GBy(val); WENRS(b, 4); }
public void WENRS(double val) { b.GBy(val); WENRS(b, 8); }
public void WENRSE( short val) { b.GBy(val); b.E(2, IsBE); WENRS(b, 2); }
public void WENRSE(ushort val) { b.GBy(val); b.E(2, IsBE); WENRS(b, 2); }
public void WENRSE( int val) { b.GBy(val); b.E(4, IsBE); WENRS(b, 4); }
public void WENRSE( uint val) { b.GBy(val); b.E(4, IsBE); WENRS(b, 4); }
public void WENRSE( long val) { b.GBy(val); b.E(8, IsBE); WENRS(b, 8); }
public void WENRSE( ulong val) { b.GBy(val); b.E(8, IsBE); WENRS(b, 8); }
public void WENRSE( float val) { b.GBy(val); b.E(4, IsBE); WENRS(b, 4); }
public void WENRSE(double val) { b.GBy(val); b.E(8, IsBE); WENRS(b, 8); }
public void WENRSE( short val, bool isBE) { b.GBy(val); b.E(2, isBE); WENRS(b, 2); }
public void WENRSE(ushort val, bool isBE) { b.GBy(val); b.E(2, isBE); WENRS(b, 2); }
public void WENRSE( int val, bool isBE) { b.GBy(val); b.E(4, isBE); WENRS(b, 4); }
public void WENRSE( uint val, bool isBE) { b.GBy(val); b.E(4, isBE); WENRS(b, 4); }
public void WENRSE( long val, bool isBE) { b.GBy(val); b.E(8, isBE); WENRS(b, 8); }
public void WENRSE( ulong val, bool isBE) { b.GBy(val); b.E(8, isBE); WENRS(b, 8); }
public void WENRSE( float val, bool isBE) { b.GBy(val); b.E(4, isBE); WENRS(b, 4); }
public void WENRSE(double val, bool isBE) { b.GBy(val); b.E(8, isBE); WENRS(b, 8); }
public Half RF16 ( ) { ushort a = RU16 ( ); return (Half)a; }
public Half RF16E ( ) { ushort a = RU16E ( ); return (Half)a; }
public Half RF16E (bool isBE) { ushort a = RU16E (isBE); return (Half)a; }
public Half RF16ENRS ( ) { ushort a = RU16E ( ); return (Half)a; }
public Half RF16ENRSE( ) { ushort a = RU16ENRSE( ); return (Half)a; }
public Half RF16ENRSE(bool isBE) { ushort a = RU16ENRSE(isBE); return (Half)a; }
public void W (Half val ) => W ((ushort)val );
public void WE (Half val ) => WE ((ushort)val );
public void WE (Half val, bool isBE) => WE ((ushort)val, isBE);
public void WENRS (Half val ) => WENRS ((ushort)val );
public void WENRSE(Half val ) => WENRSE((ushort)val );
public void WENRSE(Half val, bool isBE) => WENRSE((ushort)val, isBE);
public char RC(bool UTF8 = true) => UTF8 ? RCUTF8() : (char)s.ReadByte();
public 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 char RC(bool UTF8 = true) => UTF8 ? RCUTF8() : (char)stream.ReadByte();
public char RCUTF8()
{
@@ -279,7 +199,7 @@ namespace KKdMainLib.IO
int val = 0;
for (I = 0, i = 4; I < i; I++)
{
T = s.ReadByte();
T = stream.ReadByte();
if (T == -1) return '\uFFFF';
t = (byte)T;
@@ -298,28 +218,28 @@ namespace KKdMainLib.IO
public string RSUTF8 (long Length) => RBy(Length).ToUTF8 ();
public string RSASCII(long Length) => RBy(Length).ToASCII();
public string RS(long? Length, bool UTF8 = true) =>
UTF8 ? RSUTF8(Length) : RSASCII(Length);
public string RSUTF8 (long? Length) => RBy(Length).ToUTF8 ();
public string RSASCII(long? Length) => RBy(Length).ToASCII();
public byte[] RBy(long Length, int Offset = -1)
{ byte[] Buf = new byte[Length]; if (Offset > -1) s.Position = Offset;
s.Read(Buf, 0, (int)Length); return Buf; }
{ byte[] Buf = new byte[Length]; if (Offset > -1) stream.Position = Offset;
stream.Read(Buf, 0, (int)Length); return Buf; }
public void RBy(long Length, byte[] Buf, long Offset = -1)
{ if (Offset > -1) s.Position = Offset; s.Read(Buf, 0, (int)Length); }
{ if (Offset > -1) stream.Position = Offset; stream.Read(Buf, 0, (int)Length); }
public byte[] RBy(long? Length, int Offset = -1)
{ if (Length == null) return new byte[0]; else return RBy((long)Length, Offset); }
public void RBy(long Length, byte Bits, byte[] Buf, long Offset = -1)
{ if (Offset > -1) s.Seek(Offset, 0);
if (Bits > 0 && Bits < 8) for (i = 0; i < Length; i++) Buf[i] = RBi(Bits); CR(); }
{ if (Offset > -1) stream.Seek(Offset, 0);
if (Bits > 0 && Bits < 8) for (i = 0; i < Length; i++) Buf[i] = RBi(Bits); }
public byte RBi(byte Bits)
{
BitRead += Bits;
@@ -328,13 +248,13 @@ namespace KKdMainLib.IO
{
BitRead = (byte)-TempBitRead;
TempBitRead = 8 + TempBitRead;
ValRead = (ushort)((ValRead << 8) | (byte)s.ReadByte());
ValRead = (ushort)((ValRead << 8) | (byte)stream.ReadByte());
}
return (byte)((ValRead >> TempBitRead) & ((1 << Bits) - 1));
}
public byte RHB() => RBi(4);
public void W(int val, byte Bits)
{
val &= (1 << Bits) - 1;
@@ -344,7 +264,7 @@ namespace KKdMainLib.IO
{
BitWrite = (byte)-TempBitWrite;
TempBitWrite = 8 + TempBitWrite;
s.WriteByte((byte)(ValWrite | (val >> BitWrite)));
stream.WriteByte((byte)(ValWrite | (val >> BitWrite)));
ValWrite = 0;
}
ValWrite |= val << TempBitWrite;
@@ -352,18 +272,25 @@ namespace KKdMainLib.IO
}
public void CR() //CheckRead
{ if (BitRead > 0) ValRead = 0; BitRead = 8; }
{ CFUTRM(); if (BitRead > 0) ValRead = 0; BitRead = 8; }
public void CW() //CheckWrite
{ if (BitWrite > 0) { s.WriteByte((byte)ValWrite); ValWrite = 0; BitWrite = 0; } }
{ CFUTRM(); if (BitWrite > 0) { stream.WriteByte((byte)ValWrite); ValWrite = 0; BitWrite = 0; } }
public byte[] ToArray(bool Close)
{ 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 Position = s.Position;
byte[] Data = RBy(s.Length, 0);
s.Position = Position;
long Position = stream.Position;
byte[] Data = RBy(stream.Length, 0);
stream.Position = Position;
return Data;
}
}
+50 -14
View File
@@ -1,17 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<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>
<Authors>korenkonder</Authors>
<Company></Company>
<Configuration></Configuration>
<Copyright>korenkonder © 2018-2019</Copyright>
<Description>A simple library for working with Project Diva AC/DT/F/AFT/F2/X/FT files</Description>
<FileVersion>0.4.8.1</FileVersion>
<PackageId>KKdMainLib</PackageId>
<Product>KKdMainLib</Product>
<TargetFramework>netstandard2.0</TargetFramework>
<Title>KKdMainLib</Title>
<Version>0.4.8.1</Version>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>KKdMainLib</RootNamespace>
<AssemblyName>KKdMainLib</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -40,6 +39,43 @@
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\KKdBaseLib\KKdBaseLib.csproj" />
<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\JSON.cs" />
<Compile Include="IO\MP.cs" />
<Compile Include="IO\Path.cs" />
<Compile Include="IO\Stream.cs" />
<Compile Include="A3DA.cs" />
<Compile Include="Aet.cs" />
<Compile Include="DataBank.cs" />
<Compile Include="DEX.cs" />
<Compile Include="DIVAFILE.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="FARC.cs" />
<Compile Include="Main.cs" />
<Compile Include="Mot.cs" />
<Compile Include="STR.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
</Project>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KKdBaseLib\KKdBaseLib.csproj">
<Project>{437f63f1-8c23-429e-ab14-38b85c9edb16}</Project>
<Name>KKdBaseLib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+89 -86
View File
@@ -10,81 +10,84 @@ namespace KKdMainLib
{
public const string TimeFormatHHmmssfff = "{0:d2}:{1:d2}:{2:d2}.{3:d3}";
public static void WriteTime(this TimeSpan time, bool writeLine = false)
public static void WriteTime(this TimeSpan time, bool WriteLine = false)
{
if (writeLine) Console.WriteLine(TimeFormatHHmmssfff,
if (WriteLine) Console.WriteLine(TimeFormatHHmmssfff,
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
else Console.Write (TimeFormatHHmmssfff,
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
}
public static void WriteTime(this TimeSpan time, string Text, bool writeLine = true)
public static void WriteTime(this TimeSpan time, string Text, bool WriteLine = true)
{
if (writeLine) Console.WriteLine(TimeFormatHHmmssfff + " - " + Text,
if (WriteLine) Console.WriteLine(TimeFormatHHmmssfff + " - " + Text,
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
else Console.Write (TimeFormatHHmmssfff + " - " + Text,
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
}
public static string NullTerminated(this string source, ref int i, byte end)
public static string NullTerminated(this string Source, ref int i, byte End)
{
string s = "";
while (true)
{
if (source[i] == end) break;
else s += source[i];
if (Source[i] == End) break;
else s += Source[i];
i++;
}
return s;
}
public static bool StartsWith(this Dictionary<string, object> dict, string args, char split = '.') =>
dict.StartsWith(args.Split(split));
public static bool StartsWith(this Dictionary<string, object> Dict, string args, char Split) =>
Dict.StartsWith(args.Split(Split));
public static bool StartsWith(this Dictionary<string, object> dict, string[] args)
public static bool StartsWith(this Dictionary<string, object> Dict, string args) =>
Dict.StartsWith(args.Split('.'));
public static bool StartsWith(this Dictionary<string, object> Dict, string[] args)
{
Dictionary<string, object> bufDict = new Dictionary<string, object>();
if (dict == null) return false;
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];
string[] NewArgs = new string[args.Length - 1];
for (int i = 0; i < args.Length - 1; i++)
newArgs[i] = args[i + 1];
if (!dict.ContainsKey(args[0]))
NewArgs[i] = args[i + 1];
if (!Dict.ContainsKey(args[0]))
return false;
bufDict = (Dictionary<string, object>)dict[args[0]];
return StartsWith(bufDict, newArgs);
bufDict = (Dictionary<string, object>)Dict[args[0]];
return StartsWith(bufDict, NewArgs);
}
return dict.ContainsKey(args[0]);
return Dict.ContainsKey(args[0]);
}
public static bool FindValue(this Dictionary<string, object> dict,
ref bool value, char split, string args) =>
dict.FindValue(out string val, args.Split(split)) ? bool.TryParse(val, out value) : false;
public static bool FindValue(this Dictionary<string, object> dict,
ref int value, char split, string args) =>
dict.FindValue(out string val, args.Split(split)) ? int.TryParse(val, out value) : false;
public static bool FindValue(this Dictionary<string, object> dict,
ref float value, char split, string args) =>
dict.FindValue(out string val, args.Split(split)) ? val.ToF32( 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.ToF64( out value) : false;
public static bool FindValue(this Dictionary<string, object> Dict,
ref bool value, char Split, string args) =>
Dict.FindValue(out string val, args.Split(Split)) ? bool.TryParse(val, out value) : false;
public static bool FindValue(this Dictionary<string, object> Dict,
ref string value, char split, string args)
{ if (Dict.FindValue(out string val, args.Split(split)))
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 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; }
public static bool FindValue(this Dictionary<string, object> dict,
public static bool FindValue(this Dictionary<string, object> Dict,
out bool value, string args)
{ if (dict.FindValue(out string val, args.Split('.' )))
{ if (Dict.FindValue(out string val, args.Split('.' )))
return bool.TryParse(val, out value); value = false; return false; }
public static bool FindValue(this Dictionary<string, object> Dict,
@@ -92,107 +95,107 @@ 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,
public static bool FindValue(this Dictionary<string, object> Dict,
out float value, string args)
{ if (dict.FindValue(out string val, args.Split('.' )))
return val.ToF32(out value); value = 0; return false; }
{ 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,
public static bool FindValue(this Dictionary<string, object> Dict,
out double value, string args)
{ if (dict.FindValue(out string val, args.Split('.' )))
return val.ToF64(out value); value = 0; return false; }
{ if (Dict.FindValue(out string val, args.Split('.' )))
return val.ToDouble(out value); value = 0; return false; }
public static bool FindValue(this Dictionary<string, object> dict,
public static bool FindValue(this Dictionary<string, object> Dict,
out int? value, string args)
{ if (dict.FindValue(out string val, args.Split('.' )))
{ if (Dict.FindValue(out string val, args.Split('.' )))
{ bool Val = int.TryParse(val, out int _value);
value = _value; return Val; } value = null; return false; }
public static bool FindValue(this Dictionary<string, object> dict,
public static bool FindValue(this Dictionary<string, object> Dict,
out float? value, string args)
{ if (dict.FindValue(out string val, args.Split('.' )))
return val.ToF32(out value); value = null; return false; }
{ 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,
public static bool FindValue(this Dictionary<string, object> Dict,
out double? value, string args)
{ if (dict.FindValue(out string val, args.Split('.' )))
return val.ToF64(out value); value = null; return false; }
{ if (Dict.FindValue(out string val, args.Split('.' )))
return val.ToDouble(out value); value = null; return false; }
public static bool FindValue(this Dictionary<string, object> dict,
public static bool FindValue(this Dictionary<string, object> Dict,
out string value, string args)
{ if (dict.FindValue(out string val, args.Split('.' )))
{ if (Dict.FindValue(out string val, args.Split('.' )))
{ value = val; return true; } value = null; return false; }
public static bool FindValue(this Dictionary<string, object> dict,
public static bool FindValue(this Dictionary<string, object> Dict,
out string value, string[] args)
{
value = "";
if (dict == null) return false;
if (Dict == null) return false;
else if (args.Length < 1) return false;
args[0] = args[0].ToLower();
if (!dict.ContainsKey(args[0])) return false;
if (!Dict.ContainsKey(args[0])) return false;
else if (args.Length > 1)
{
string[] newArgs = new string[args.Length - 1];
for (int i = 0; i < args.Length - 1; i++) newArgs[i] = args[i + 1];
return ((Dictionary<string, object>)dict[args[0]]).FindValue(out value, newArgs);
string[] NewArgs = new string[args.Length - 1];
for (int i = 0; i < args.Length - 1; i++) NewArgs[i] = args[i + 1];
return ((Dictionary<string, object>)Dict[args[0]]).FindValue(out value, NewArgs);
}
else if (args.Length == 1)
{
if (dict[args[0]].GetType() == dict.GetType())
return ((Dictionary<string, object>)dict[args[0]]).FindValue(out value, args);
else if (dict[args[0]].GetType() != typeof(string)) return false;
if (Dict[args[0]].GetType() == Dict.GetType())
return ((Dictionary<string, object>)Dict[args[0]]).FindValue(out value, args);
else if (Dict[args[0]].GetType() != typeof(string)) return false;
}
value = (string)dict[args[0]];
value = (string)Dict[args[0]];
return true;
}
public static void GetDictionary(this Dictionary<string, object> Dict,
string args, string value, char Split = '.') =>
Dict.GetDictionary(args.Split(Split), value);
public static void GetDictionary(this Dictionary<string, object> dict,
string args, string value, char split = '.') =>
dict.GetDictionary(args.Split(split), value);
public static void GetDictionary(this Dictionary<string, object> dict,
public static void GetDictionary(this Dictionary<string, object> Dict,
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];
for (int i = 0; i < args.Length - 1; i++) newArgs[i] = args[i + 1];
if (!dict.ContainsKey(args[0])) dict.Add(args[0], null);
if (dict[args[0]] != null)
string[] NewArgs = new string[args.Length - 1];
for (int i = 0; i < args.Length - 1; i++) NewArgs[i] = args[i + 1];
if (!Dict.ContainsKey(args[0])) Dict.Add(args[0], null);
if (Dict[args[0]] != null)
{
if (dict[args[0]].GetType() == typeof(string))
dict[args[0]] = new Dictionary<string, object> { { "", dict[args[0]] } };
if (Dict[args[0]].GetType() == typeof(string))
Dict[args[0]] = new Dictionary<string, object> { { "", Dict[args[0]] } };
}
else dict[args[0]] = new Dictionary<string, object>();
bufDict = (Dictionary<string, object>)dict[args[0]];
bufDict.GetDictionary(newArgs, value);
dict[args[0]] = bufDict;
else Dict[args[0]] = new Dictionary<string, object>();
bufDict = (Dictionary<string, object>)Dict[args[0]];
bufDict.GetDictionary(NewArgs, value);
Dict[args[0]] = bufDict;
}
else if (!dict.ContainsKey(args[0])) dict.Add(args[0], value);
else if (!Dict.ContainsKey(args[0])) Dict.Add(args[0], value);
}
public static TKey GetKey<TKey, TVal>(this Dictionary<TKey, TVal> dict, TVal val) =>
dict.First((System.Collections.Generic.KeyValuePair<TKey, TVal> x) => x.Value.Equals(val)).Key;
public static TKey GetKey<TKey, TVal>(this Dictionary<TKey, TVal> Dict, TVal val) =>
Dict.First((KeyValuePair<TKey, TVal> x) => x.Value.Equals(val)).Key;
public static string ToTitleCase(this string s)
{ return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s); }
public static int[] SortWriter(this int length)
public static int[] SortWriter(this int Length)
{
int i = 0;
List<string> A = new List<string>();
for (i = 0; i < length; i++) A.Add(i.ToString());
for (i = 0; i < Length; i++) A.Add(i.ToString());
A.Sort();
int[] B = new int[length];
for (i = 0; i < length; i++) B[i] = int.Parse(A[i]);
int[] B = new int[Length];
for (i = 0; i < Length; i++) B[i] = int.Parse(A[i]);
return B;
}
}
+190 -190
View File
@@ -8,309 +8,309 @@ namespace KKdMainLib
public struct Mot
{
private int i, i0, i1;
public MotHeader[] MOT;
private Stream _IO;
private MotHeader[] MOT;
private Stream IO;
public void MOTReader(string file)
{
_IO = File.OpenReader(file + ".bin");
IO = File.OpenReader(file + ".bin");
i = 0;
while (true)
if (_IO.RI64() == 0) break;
else { _IO.RI64(); i++; }
if (IO.RI64() == 0) break;
else { IO.RI64(); i++; }
if (i == 0) return;
_IO.P = 0;
int motCount = i;
MOT = new MotHeader[motCount];
for (i = 0; i < motCount; i++)
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();
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++)
for (i = 0; i < MOTCount; i++)
{
ref MotHeader mot = ref MOT[i];
ref MotHeader Mot = ref MOT[i];
i0 = 1;
_IO.P = mot.BoneInfo.O;
_IO.RU16();
while (_IO.RU16() != 0) i0++;
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();
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();
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++)
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();
if (i0 % 8 == 0) i1 = IO.RU16();
mot.KeySet.V[i0] = new KeySet { Type = (KeySetType)((i1 >> (i0 % 8 * 2)) & 0b11) };
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++)
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)
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();
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)
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(); }
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();
IO.C();
}
public void MOTWriter(string file)
{
if (MOT == null) return;
_IO = File.OpenWriter(file + ".bin");
IO = File.OpenWriter(file + ".bin");
int MOTCount = MOT.Length;
_IO.P = (MOTCount + 1) << 4;
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);
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++)
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));
i1 |= ((byte)Mot.KeySet.V[i0].Type << (i0 % 8 * 2)) & (0b11 << (i0 % 8 * 2));
if (i0 % 8 == 7) { _IO.W((ushort)i1); i1 = 0; }
if (i0 % 8 == 7) { IO.W((ushort)i1); i1 = 0; }
}
_IO.W((ushort)i1);
IO.W((ushort)i1);
_IO.A(0x4);
mot.KeySetOffset = _IO.P;
for (i0 = 0; i0 < mot.KeySet.V.Length; i0++)
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)
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);
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)
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.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);
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);
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.A(0x4, true);
_IO.P = 0;
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 );
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();
IO.C();
}
public void MsgPackReader(string file, bool json)
public void MsgPackReader(string file, bool JSON)
{
MOT = null;
MsgPack msgPack = file.ReadMP(json);
MsgPack mot;
if ((mot = msgPack["MOT"]).NotNull)
MsgPack MsgPack = file.ReadMP(JSON);
MsgPack MOTS;
if ((MOTS = MsgPack["MOT"]).NotNull)
{
MOT = new MotHeader[mot.Array.Length];
MOT = new MotHeader[MOTS.Array.Length];
for (int i = 0; i < MOT.Length; i++)
MsgPackReader(mot.Array[i], ref MOT[i]);
MsgPackReader(MOTS.Array[i], ref MOT[i]);
}
mot.Dispose();
msgPack.Dispose();
MOTS.Dispose();
MsgPack.Dispose();
}
public void MsgPackWriter(string file, bool json)
public void MsgPackWriter(string file, bool JSON)
{
int motCount = MOT.Length;
MsgPack mot = new MsgPack(motCount, "MOT");
for (i = 0; i < motCount; i++)
mot[i] = MsgPackWriter(ref MOT[i]);
mot.Write(true, file, json);
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 msgPack, ref MotHeader mot)
public void MsgPackReader(MsgPack MOT, ref MotHeader Mot)
{
MsgPack temp = MsgPack.New;
mot.HighBits = msgPack.RI32("HighBits" );
mot.FrameCount = msgPack.RI32("FrameCount");
MsgPack Temp = MsgPack.New;
Mot.HighBits = MOT.RI32("HighBits" );
Mot.FrameCount = MOT.RI32("FrameCount");
if ((temp = msgPack["KeySets", true]).IsNull) { temp.Dispose(); return; }
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++)
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];
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();
if (Temp.Array[i0].Array == null || Temp.Array[i0].Array.Length != 2) continue;
KeySet.Type = (KeySetType)Temp.Array[i0].Array[0].RI32();
MsgPack temp1 = temp.Array[i0].Array[1];
MsgPack keySet = Temp.Array[i0].Array[1];
if (temp1.Array == null) { keySet.Type = 0; continue; }
else if (keySet.Type == KeySetType.None) continue;
else if (keySet.Type == KeySetType.Static)
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 (temp1.Array == null) continue;
else if (temp1.Array.Length == 0) continue;
else if (temp1.Array[0].Array == null) continue;
else if (temp1.Array[0].Array.Length == 0) continue;
else if (temp1.Array[0].Array.Length == 1)
keySet.Keys[0] = new KFT2 (temp1.Array[0][0].RF32());
else if (temp1.Array[0].Array.Length > 1)
keySet.Keys[0] = new KFT2 (temp1.Array[0][0].RF32(), temp1.Array[1].RF32());
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)
else if (KeySet.Type == KeySetType.Linear)
{
keySet.Keys = new KFT2[temp1.Array.Length];
for (i1 = 0; i1 < temp1.Array.Length; i1++)
KeySet.Keys = new KFT2[keySet.Array.Length];
for (i1 = 0; i1 < keySet.Array.Length; i1++)
{
ref MsgPack array = ref temp1.Array[i1];
if (array.Array == null) continue;
else if (array.Array.Length == 0) continue;
else if (array.Array.Length == 1)
keySet.Keys[i1] = new KFT2 (array[0].RF32());
else if (array.Array.Length == 2)
keySet.Keys[i1] = new KFT2 (array[0].RF32(), array[1].RF32());
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)
else if (KeySet.Type == KeySetType.Interpolated)
{
keySet.Keys = new KFT2[temp1.Array.Length];
for (i1 = 0; i1 < temp1.Array.Length; i1++)
KeySet.Keys = new KFT2[keySet.Array.Length];
for (i1 = 0; i1 < keySet.Array.Length; i1++)
{
ref MsgPack array = ref temp1.Array[i1];
if (array.Array == null ||
array.Array.Length == 0) continue;
else if (array.Array.Length == 1)
keySet.Keys[i1] = new KFT2 (array[0].RF32());
else if (array.Array.Length == 2)
keySet.Keys[i1] = new KFT2 (array[0].RF32(), array[1].RF32());
else if (array.Array.Length > 2)
keySet.Keys[i1] = new KFT2 (array[0].RF32(),
array[1].RF32(), temp1.Array[i1][2].RF32());
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 = msgPack["BoneInfo", true]).NotNull)
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();
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();
Temp.Dispose();
}
public MsgPack MsgPackWriter(ref MotHeader Mot)
{
MsgPack mot = MsgPack.NewReserve(4).Add("FrameCount", Mot.FrameCount).Add("HighBits", Mot.HighBits);
MsgPack MOT = MsgPack.NewReserve(4).Add("FrameCount", Mot.FrameCount).Add("HighBits", Mot.HighBits);
MsgPack keySets = new MsgPack(Mot.KeySet.V.Length, "KeySets");
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;
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)
KeySets[i0] = new MsgPack(2);
KeySets[i0].Array[0] = (byte)KeySet.Type;
KeySets[i0].Array[1] = new MsgPack(KeySet.Keys.Length);
if (KeySet.Type == KeySetType.Static)
{
IKF kf = keySet.Keys[0].Check();
if (kf is KFT0 KFT0) keySets[i0].Array[1][0] =
new MsgPack(null, new MsgPack[] { KFT0.F });
else if (kf is KFT1 KFT1) keySets[i0].Array[1][0] =
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++)
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] =
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] =
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++)
for (i1 = 0; i1 < KeySet.Keys.Length; i1++)
{
IKF kf = keySet.Keys[i1].Check();
if (kf is KFT0 KFT0) keySets[i0].Array[1][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] =
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] =
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);
MOT.Add(KeySets);
MsgPack boneInfo = new MsgPack(Mot.BoneInfo.V.Length, "BoneInfo");
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);
BoneInfo[i0] = Mot.BoneInfo.V[i0].Id;
MOT.Add(BoneInfo);
return mot;
return MOT;
}
public struct MotHeader
+8
View File
@@ -1,7 +1,15 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("KKdMainLib")]
[assembly: AssemblyDescription("A simple library for working with Project Diva AC/DT/F/AFT/F2/X/FT files")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KKdMainLib")]
[assembly: AssemblyCopyright("korenkonder © 2018-2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("2BA7EFC6-91D1-8BBC-C487-06C7F36CC789")]
[assembly: AssemblyVersion("0.4.7.6")]
[assembly: AssemblyFileVersion("0.4.7.6")]
+138 -116
View File
@@ -4,192 +4,214 @@ using KKdMainLib.IO;
namespace KKdMainLib
{
public struct STR : System.IDisposable
public class STR
{
private POF pof;
private Header header;
private Stream _IO;
public STR()
{ Offset = 0; OffsetX = 0; STRs = null; Header = new Header(); }
private long Offset;
private long OffsetX;
private POF POF;
private Header Header;
private Stream IO;
public String[] Strings;
public String[] STRs;
public int STRReader(string filepath, string ext)
{
_IO = File.OpenReader(filepath + ext);
IO = File.OpenReader(filepath + ext);
header = new Header();
_IO.Format = Format.F;
header.Signature = _IO.RI32();
if (header.Signature == 0x41525453)
Header = new Header();
IO.Format = Format.F;
Header.Signature = IO.RI32();
if (Header.Signature == 0x41525453)
{
header = _IO.ReadHeader(true, false);
int count = _IO.RI32E();
int offset = _IO.RI32E();
_IO.P = offset;
Strings = new String[count];
for (int i = 0; i < count; i++)
Header = IO.ReadHeader(true, false);
POF.Offsets = KKdList<long>.New;
long Count = IO.RI32E();
Offset = IO.RI32E();
if (Offset == 0)
{
Strings[i].Str.O = _IO.RI32E();
Strings[i].ID = _IO.RI32E();
Offset = Count;
OffsetX = IO.RI64();
Count = IO.RI64();
IO.O = Header.Length;
IO.Format = Format.X;
IO.I64O += Offset;
IO.P = 0;
}
else IO.P = Header.Length + 0x40;
STRs = new String[Count];
for (int i = 0; i < Count; i++)
{
STRs[i].Str.O = IO.RI32E();
STRs[i].ID = IO.RI32E();
}
_IO.O = 0;
for (int i = 0; i < count; i++)
Strings[i].Str.V = Strings[i].Str.O > 0 ?
_IO.RSaO(Strings[i].Str.O) : null;
if (IO.IsX)
{
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;
}
}
else
{
_IO.P -= 4;
int count = 0;
for (int a = 0, i = 0; _IO.P > 0 && _IO.P < _IO.L; i++, count++)
IO.P -= 4;
int Count = 0;
for (int a = 0, i = 0; IO.P > 0 && IO.P < IO.L; i++, Count++)
{
a = _IO.RI32();
a = IO.RI32();
if (a == 0) break;
}
Strings = new String[count];
STRs = new String[Count];
for (int i = 0; i < count; i++)
for (int i = 0; i < Count; i++)
{
_IO.PI64 = Strings[i].Str.O;
Strings[i].ID = i;
Strings[i].Str.V = _IO.NTUTF8();
IO.I64P = STRs[i].Str.O;
STRs[i].ID = i;
STRs[i].Str.V = IO.NTUTF8();
}
}
_IO.C();
IO.C();
return 1;
}
public void STRWriter(string filepath)
{
if (Strings == null || Strings.Length == 0 || header.Format > Format.F2BE) return;
uint offset = 0;
uint currentOffset = 0;
_IO = File.OpenWriter(filepath + (header.Format > Format.AFT &&
header.Format < Format.FT ? ".str" : ".bin"), true);
_IO.Format = header.Format;
pof.Offsets = KKdList<long>.New;
if (STRs == null || STRs.Length == 0 || Header.Format > Format.F2BE) return;
uint Offset = 0;
uint CurrentOffset = 0;
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 = Strings.LongLength;
if (_IO.Format > Format.AFT && _IO.Format < Format.FT)
long Count = STRs.LongLength;
if (IO.Format > Format.FT)
{
_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);
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++) _IO.W(0x00);
_IO.A(0x20);
for (int i = 0; i < Count; i++) IO.W(0x00);
IO.A(0x20);
}
KKdList<string> usedSTR = KKdList<string>.New;
KKdList<int> usedSTRPos = KKdList<int>.New;
int[] STRPos = new int[count];
KKdList<string> UsedSTR = KKdList<string>.New;
KKdList<int> UsedSTRPos = KKdList<int>.New;
int[] STRPos = new int[Count];
usedSTRPos.Add(_IO.P);
usedSTR.Add("");
_IO.W(0);
for (int i = 0; i < count; i++)
UsedSTRPos.Add(IO.P);
UsedSTR.Add("");
IO.W(0);
for (int i = 0; i < Count; i++)
{
if (!usedSTR.Contains(Strings[i].Str.V))
if (!UsedSTR.Contains(STRs[i].Str.V))
{
STRPos[i] = _IO.P;
usedSTRPos.Add(STRPos[i]);
usedSTR.Add(Strings[i].Str.V);
_IO.W(Strings[i].Str.V);
_IO.W(0);
STRPos[i] = IO.P;
UsedSTRPos.Add(STRPos[i]);
UsedSTR.Add(STRs[i].Str.V);
IO.W(STRs[i].Str.V);
IO.W(0);
}
else
for (int i2 = 0; i2 < count; i2++)
if (usedSTR[i2] == Strings[i].Str.V) { STRPos[i] = usedSTRPos[i2]; break; }
for (int i2 = 0; i2 < Count; i2++)
if (UsedSTR[i2] == STRs[i].Str.V) { STRPos[i] = UsedSTRPos[i2]; break; }
}
if (_IO.Format > Format.AFT)
if (IO.Format > Format.FT)
{
_IO.A(0x10);
offset = _IO.PU32;
_IO.P = 0x80;
for (int i = 0; i < count; i++)
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(Strings[i].ID);
POF.Offsets.Add(IO.P);
IO.WE(STRPos[i]);
IO.WE(STRs[i].ID);
}
_IO.PU32 = offset;
_IO.W(pof, false, 1);
currentOffset = _IO.PU32;
_IO.WEOFC();
header.DataSize = (int)(currentOffset - 0x40);
header.Signature = 0x41525453;
header.SectionSize = (int)(offset - 0x40);
_IO.P = 0;
_IO.W(header, true);
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 - 0x40);
IO.P = 0;
IO.W(Header, true);
}
else
{
_IO.P = 0;
for (int i = 0; i < count; i++) _IO.W(STRPos[i]);
IO.P = 0;
for (int i = 0; i < Count; i++) IO.W(STRPos[i]);
}
_IO.C();
IO.C();
}
public void MsgPackReader(string file, bool json)
public void MsgPackReader(string file, bool JSON)
{
MsgPack temp;
MsgPack msgPack = file.ReadMPAllAtOnce(json);
if ((temp = msgPack["STR"]).NotNull) return;
MsgPack Temp;
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
if ((Temp = MsgPack["STR"]).NotNull) return;
header = new Header();
System.Enum.TryParse(temp.RS("Format"), out header.Format);
Header = new Header();
System.Enum.TryParse(Temp.RS("Format"), out Header.Format);
if ((temp = msgPack["Strings", true]).IsNull) return;
if ((Temp = MsgPack["Strings", true]).IsNull) return;
Strings = new String[temp.Array.Length];
for (int i = 0; i < Strings.Length; i++)
STRs = new String[Temp.Array.Length];
for (int i = 0; i < STRs.Length; i++)
{
Strings[i].ID = temp[i].RI32("ID" );
Strings[i].Str.V = temp[i].RS ("Str");
if (Strings[i].Str.V == null) Strings[i].Str.V = "";
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.Dispose();
MsgPack.Dispose();
}
public void MsgPackWriter(string file, bool json)
public void MsgPackWriter(string file, bool JSON)
{
if (Strings == null || Strings.Length == 0) return;
MsgPack str = new MsgPack("STR").Add("Format", header.Format.ToString());
MsgPack strings = new MsgPack(Strings.Length, "Strings");
for (int i = 0; i < Strings.Length; i++)
if (STRs == null || STRs.Length == 0) return;
MsgPack STR_ = new MsgPack("STR").Add("Format", Header.Format.ToString());
MsgPack Strings = new MsgPack(STRs.Length, "Strings");
for (int i = 0; i < STRs.Length; i++)
{
strings[i] = MsgPack.New.Add("ID", Strings[i].ID);
if (Strings[i].Str.V != null)
if (Strings[i].Str.V != "")
strings[i] = strings[i].Add("Str", Strings[i].Str.V);
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_.Add(Strings);
str.WriteAfterAll(true, file, json);
STR_.WriteAfterAll(true, file, JSON);
}
private bool disposed;
public void Dispose()
{ if (!disposed) { if (_IO != null) _IO.Dispose(); Strings = default;
pof = default; header = default; disposed = true; } }
public struct String
{
public int ID;
public Pointer<string> Str;
public override string ToString() => "ID: " + ID + (Str.V != null ||
public override string ToString() => "ID: " + ID + (Str.V != null ||
Str.V != "" ? ("; Str: " + Str.V) : "");
}
}
+43 -51
View File
@@ -28,39 +28,34 @@ namespace KKdSoundLib
reader.RU16();
Data.Name = reader.RS(0x20);
Stream writer = File.OpenWriter();
if (!ToArray) writer = File.OpenWriter(file + ".wav", true);
writer.I64P = 0x2C;
byte value = 0;
byte[] data = new byte[Data.SamplesCount * Data.Channels * 4];
int[] current = new int[Data.Channels];
int[] currentclamp = new int[Data.Channels];
sbyte[] stepindex = new sbyte[Data.Channels];
float f;
fixed (int* currentPtr = current)
fixed (int* currentclampPtr = currentclamp)
fixed (sbyte* stepindexPtr = stepindex)
fixed (byte* ptr = data)
{
float* dataPtr = (float*)ptr;
for (i = 0; i < Data.SamplesCount; i++)
for (c = 0; c < Data.Channels; c++, dataPtr++)
{
value = reader.RHB();
IMADecoder(value, ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
*dataPtr = (float)(currentPtr[c] / 32768.0);
}
}
reader.CR();
int* currentPtr = current.GetPtr();
int* currentclampPtr = currentclamp.GetPtr();
sbyte* stepindexPtr = stepindex.GetPtr();
for (i = 0; i < Data.SamplesCount; i++)
for (c = 0; c < Data.Channels; c++)
{
value = reader.RHB();
IMADecoder(value, ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
f = (float)(currentPtr[c] / 32768.0);
writer.W(f);
}
if (ToArray) Data.Data = data;
else
{
Stream writer = File.OpenWriter(file + ".wav", true);
WAV.Header Header = new WAV.Header { Bytes = 4, Channels = Data.Channels, Format = 3,
SampleRate = Data.SampleRate, Size = Data.SamplesCount * Data.Channels * 4 };
writer.W(Header, 0);
writer.W(data);
writer.C();
}
WAV.Header Header = new WAV.Header { Bytes = 4, Channels = Data.Channels, Format = 3,
SampleRate = Data.SampleRate, Size = Data.SamplesCount * Data.Channels * 4 };
writer.W(Header, 0);
if (ToArray) Data.Data = writer.ToArray();
writer.C();
reader.C();
}
@@ -78,9 +73,7 @@ namespace KKdSoundLib
Stream writer = File.OpenWriter(file + ".diva", true);
Data.Channels = Header.Channels;
Data.SampleRate = Header.SampleRate;
Data.SamplesCount = Header.Size / Header.Channels / Header.Bytes;
writer.PI64 = 0x40;
writer.LI64 = 0x40 + (Data.SamplesCount * Data.Channels).A(2, 2);
writer.I64P = 0x40;
byte value = 0;
int[] sample = new int[Data.Channels];
@@ -88,27 +81,26 @@ namespace KKdSoundLib
int[] currentclamp = new int[Data.Channels];
sbyte[] stepindex = new sbyte[Data.Channels];
fixed (int* samplePtr = sample)
fixed (int* currentPtr = current)
fixed (int* currentclampPtr = currentclamp)
fixed (sbyte* stepindexPtr = stepindex)
{
for (i = 0; i < Data.SamplesCount; i++)
for (c = 0; c < Header.Channels; c++)
{
samplePtr[c] = (reader.RS(Header.Bytes, Header.Format) * 0x8000).CFTI();
value = IMAEncoder(samplePtr[c], ref currentPtr[c],
ref currentclampPtr[c], ref stepindexPtr[c]);
writer.W(value, 4);
}
}
int* samplePtr = sample.GetPtr();
int* currentPtr = current.GetPtr();
int* currentclampPtr = currentclamp.GetPtr();
sbyte* stepindexPtr = stepindex.GetPtr();
Data.SamplesCount = Header.Size / Header.Channels / Header.Bytes;
for (i = 0; i < Data.SamplesCount; i++)
for (c = 0; c < Header.Channels; c++)
{
samplePtr[c] = (reader.RS(Header.Bytes, Header.Format) * 0x8000).CFTI();
value = IMAEncoder(samplePtr[c], ref currentPtr[c],
ref currentclampPtr[c], ref stepindexPtr[c]);
writer.W(value, 4);
}
writer.CW();
writer.PI64 = 0x00;
writer.I64P = 0x00;
writer.W("DIVA");
writer.W(0x00);
writer.W((Data.SamplesCount * Data.Channels).A(2, 2));
writer.W((Data.SamplesCount * Data.Channels).Align(2, 2));
writer.W(Data.SampleRate);
writer.W(Data.SamplesCount);
writer.W(0x00);
@@ -126,14 +118,14 @@ namespace KKdSoundLib
if ((value & 1) == 1) diff += step >> 2;
if ((value & 2) == 2) diff += step >> 1;
if ((value & 4) == 4) diff += step;
if ((value & 8) == 8)
{ currentclamp -= diff; current = currentclamp;
if (currentclamp < -0x8000) currentclamp = -0x8000; }
else
{ currentclamp += diff; current = currentclamp;
if (currentclamp > 0x7FFF) currentclamp = 0x7FFF; }
stepindex += ima_index_table[value & 7];
if (stepindex < 0) stepindex = 0;
if (stepindex > 88) stepindex = 88;
@@ -147,9 +139,9 @@ namespace KKdSoundLib
{
value = 0;
step = ima_step_table[stepindex];
delta = sample - current;
if (delta < 0)
{ value |= 8; delta = -delta; }
diff = step >> 3;
@@ -161,14 +153,14 @@ namespace KKdSoundLib
step >>= 1;
if (delta > step)
{ value |= 1; diff += step; }
if ((value & 8) == 8)
{ currentclamp -= diff; current = currentclamp;
if (currentclamp < -0x8000) currentclamp = -0x8000; }
else
{ currentclamp += diff; current = currentclamp;
if (currentclamp > 0x7FFF) currentclamp = 0x7FFF; }
stepindex += ima_index_table[value & 0x07];
if (stepindex < 0) stepindex = 0;
if (stepindex > 88) stepindex = 88;
+55 -55
View File
@@ -5,93 +5,93 @@ namespace KKdSoundLib
{
public static class Extensions
{
public static double RS(this Stream _IO, ushort Bytes, ushort Format)
public static double RS(this Stream IO, ushort Bytes, ushort Format)
{
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();
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 W(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.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);
if (Bytes == 2) IO.W((Sample * 0x00008000).CFTS());
else if (Bytes == 4 && Format == 0x01) IO.W((Sample * 0x80000000).CFTI());
else if (Bytes == 4 && Format == 0x03) IO.W((float)Sample);
else if (Bytes == 8 && Format == 0x03) IO.W( Sample);
}
public static WAV.Header ReadWAVHeader(this Stream _IO)
public static WAV.Header ReadWAVHeader(this Stream IO)
{
WAV.Header Header = new WAV.Header();
if (_IO.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 (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.RU16();
Header.SampleRate = _IO.RU32();
_IO.RI32(); _IO.RI16();
Header.Bytes = _IO.RU16();
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.RI32();
Header.ChannelMask = _IO.RU32();
Header.Format = _IO.RU16();
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.S(Offset + 0x14, 0);
if (_IO.RS(4) != "data") return Header;
Header.Size = _IO.RU32();
Header.HeaderSize = _IO.PU32;
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 W(this Stream _IO, WAV.Header Header, long Seek) => _IO.W(Header, Seek, 0);
public static void W(this Stream IO, WAV.Header Header, long Seek) => IO.W(Header, Seek, 0);
public static void W(this Stream _IO, WAV.Header Header, long Seek, SeekOrigin Origin)
{ _IO.S(Seek, Origin); _IO.W(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 W(this Stream _IO, WAV.Header Header)
public static void W(this Stream IO, WAV.Header Header)
{
_IO.W("RIFF");
if (Header.Format != 0xFFFE) _IO.W(Header.Size + 0x24);
else _IO.W(Header.Size + 0x3C);
_IO.W("WAVE");
_IO.W("fmt ");
if (Header.Format != 0xFFFE) _IO.W(0x10);
else _IO.W(0x28);
_IO.W(Header.Format);
_IO.W((short)Header.Channels);
_IO.W(Header.SampleRate);
_IO.W(Header.SampleRate * Header.Channels * Header.Bytes);
_IO.W((short)(Header.Channels * Header.Bytes));
_IO.W((short)(Header.Bytes << 3));
IO.W("RIFF");
if (Header.Format != 0xFFFE) IO.W(Header.Size + 0x24);
else IO.W(Header.Size + 0x3C);
IO.W("WAVE");
IO.W("fmt ");
if (Header.Format != 0xFFFE) IO.W(0x10);
else IO.W(0x28);
IO.W(Header.Format);
IO.W((short)Header.Channels);
IO.W(Header.SampleRate);
IO.W(Header.SampleRate * Header.Channels * Header.Bytes);
IO.W((short)(Header.Channels * Header.Bytes));
IO.W((short)(Header.Bytes << 3));
if (Header.Format == 0xFFFE)
{
_IO.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.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.W("data");
_IO.W(Header.Size);
IO.W("data");
IO.W(Header.Size);
}
}
}
+34 -15
View File
@@ -1,17 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<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>
<Authors>korenkonder</Authors>
<Company></Company>
<Configuration></Configuration>
<Copyright>korenkonder © 2019</Copyright>
<Description>A simple library for working with Project Diva F/AFT/F2/X/FT audio files</Description>
<FileVersion>0.1.1.1</FileVersion>
<PackageId>KKdSoundLib</PackageId>
<Product>KKdSoundLib</Product>
<TargetFramework>netstandard2.0</TargetFramework>
<Title>KKdSoundLib</Title>
<Version>0.1.1.1</Version>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>KKdSoundLib</RootNamespace>
<AssemblyName>KKdSoundLib</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -40,7 +39,27 @@
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\KKdBaseLib\KKdBaseLib.csproj" />
<ProjectReference Include="..\KKdMainLib\KKdMainLib.csproj" />
<Compile Include="Extensions.cs" />
<Compile Include="DIVA.cs" />
<Compile Include="VAG.cs" />
<Compile Include="WAV.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
</Project>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KKdBaseLib\KKdBaseLib.csproj">
<Project>{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>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
+8
View File
@@ -1,7 +1,15 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("KKdSoundLib")]
[assembly: AssemblyDescription("A simple library for working with Project Diva F/AFT/F2/X/FT audio files")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KKdSoundLib")]
[assembly: AssemblyCopyright("korenkonder © 2019")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA")]
[assembly: AssemblyVersion("0.1.0.0")]
[assembly: AssemblyFileVersion("0.1.0.0")]
+403 -365
View File
File diff suppressed because it is too large Load Diff
+15 -114
View File
@@ -11,7 +11,6 @@
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -40,21 +39,21 @@
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="classes\A3D.cs" />
<Compile Include="classes\AET.cs" />
<Compile Include="classes\BLT.cs" />
<Compile Include="classes\CCT.cs" />
<Compile Include="classes\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\DB.cs" />
<Compile Include="classes\DEX.cs" />
<Compile Include="classes\DFT.cs" />
<Compile Include="classes\DIV.cs" />
<Compile Include="classes\DIVAFILE.cs" />
<Compile Include="classes\FARC.cs" />
<Compile Include="classes\LIT.cs" />
<Compile Include="classes\MOT.cs" />
<Compile Include="classes\STR.cs" />
<Compile Include="classes\VAG.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
@@ -70,112 +69,14 @@
<Name>KKdBaseLib</Name>
</ProjectReference>
<ProjectReference Include="..\KKdMainLib\KKdMainLib.csproj">
<Project>{2ba7efc6-91d1-8bbc-c487-06c7f36cc789}</Project>
<Project>{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}</Project>
<Name>KKdMainLib</Name>
<EmbedInteropTypes>False</EmbedInteropTypes>
</ProjectReference>
<ProjectReference Include="..\KKdSoundLib\KKdSoundLib.csproj">
<Project>{d8a3f2d7-10cc-5723-ec9a-45d3b9c2df77}</Project>
<Project>{D8A3F2D7-10CC-5723-EC9A-45D3B9C2DF77}</Project>
<Name>KKdSoundLib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>del Microsoft.Win32.Primitives.dll
del netstandard.dll
del PD_Tool.exe.config
del System.AppContext.dll
del System.Collections.Concurrent.dll
del System.Collections.dll
del System.Collections.NonGeneric.dll
del System.Collections.Specialized.dll
del System.ComponentModel.dll
del System.ComponentModel.EventBasedAsync.dll
del System.ComponentModel.Primitives.dll
del System.ComponentModel.TypeConverter.dll
del System.Console.dll
del System.Data.Common.dll
del System.Diagnostics.Contracts.dll
del System.Diagnostics.Debug.dll
del System.Diagnostics.FileVersionInfo.dll
del System.Diagnostics.Process.dll
del System.Diagnostics.StackTrace.dll
del System.Diagnostics.TextWriterTraceListener.dll
del System.Diagnostics.Tools.dll
del System.Diagnostics.TraceSource.dll
del System.Diagnostics.Tracing.dll
del System.Drawing.Primitives.dll
del System.Dynamic.Runtime.dll
del System.Globalization.Calendars.dll
del System.Globalization.dll
del System.Globalization.Extensions.dll
del System.IO.Compression.dll
del System.IO.Compression.ZipFile.dll
del System.IO.dll
del System.IO.FileSystem.dll
del System.IO.FileSystem.DriveInfo.dll
del System.IO.FileSystem.Primitives.dll
del System.IO.FileSystem.Watcher.dll
del System.IO.IsolatedStorage.dll
del System.IO.MemoryMappedFiles.dll
del System.IO.Pipes.dll
del System.IO.UnmanagedMemoryStream.dll
del System.Linq.dll
del System.Linq.Expressions.dll
del System.Linq.Parallel.dll
del System.Linq.Queryable.dll
del System.Net.Http.dll
del System.Net.NameResolution.dll
del System.Net.NetworkInformation.dll
del System.Net.Ping.dll
del System.Net.Primitives.dll
del System.Net.Requests.dll
del System.Net.Security.dll
del System.Net.Sockets.dll
del System.Net.WebHeaderCollection.dll
del System.Net.WebSockets.Client.dll
del System.Net.WebSockets.dll
del System.ObjectModel.dll
del System.Reflection.dll
del System.Reflection.Extensions.dll
del System.Reflection.Primitives.dll
del System.Resources.Reader.dll
del System.Resources.ResourceManager.dll
del System.Resources.Writer.dll
del System.Runtime.CompilerServices.VisualC.dll
del System.Runtime.dll
del System.Runtime.Extensions.dll
del System.Runtime.Handles.dll
del System.Runtime.InteropServices.dll
del System.Runtime.InteropServices.RuntimeInformation.dll
del System.Runtime.Numerics.dll
del System.Runtime.Serialization.Formatters.dll
del System.Runtime.Serialization.Json.dll
del System.Runtime.Serialization.Primitives.dll
del System.Runtime.Serialization.Xml.dll
del System.Security.Claims.dll
del System.Security.Cryptography.Algorithms.dll
del System.Security.Cryptography.Csp.dll
del System.Security.Cryptography.Encoding.dll
del System.Security.Cryptography.Primitives.dll
del System.Security.Cryptography.X509Certificates.dll
del System.Security.Principal.dll
del System.Security.SecureString.dll
del System.Text.Encoding.dll
del System.Text.Encoding.Extensions.dll
del System.Text.RegularExpressions.dll
del System.Threading.dll
del System.Threading.Overlapped.dll
del System.Threading.Tasks.dll
del System.Threading.Tasks.Parallel.dll
del System.Threading.Thread.dll
del System.Threading.ThreadPool.dll
del System.Threading.Timer.dll
del System.ValueTuple.dll
del System.Xml.ReaderWriter.dll
del System.Xml.XDocument.dll
del System.Xml.XmlDocument.dll
del System.Xml.XmlSerializer.dll
del System.Xml.XPath.dll
del System.Xml.XPath.XDocument.dll</PostBuildEvent>
</PropertyGroup>
</Project>
+68 -68
View File
@@ -11,24 +11,22 @@ namespace PD_Tool
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetProcessDPIAware();
[ThreadStatic] public static string choose = "";
[ThreadStatic] public static string function = "";
[STAThread]
public static void Main(string[] args)
{
SetProcessDPIAware();
Console.Title = "PD_Tool";
if (args.Length == 0) { while (choose != "Q") MainMenu(); Exit(); }
if (args.Length == 0) { while (function != "Q") MainMenu(); Exit(); }
long header;
Stream reader;
foreach (string arg in args)
{
GC.Collect();
if (Directory.Exists(arg)) using (KKdFARC FARC = new KKdFARC(arg, true)) FARC.Pack();
else if (File.Exists(arg) && Path.GetExtension(arg) == ".farc")
using (KKdFARC farc = new KKdFARC(arg)) farc.UnPack(true);
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))
{
using (reader = File.OpenReader(arg))
@@ -39,7 +37,7 @@ namespace PD_Tool
Exit();
}
[ThreadStatic] private static bool json = true;
[ThreadStatic] private static bool JSON = true;
private static void MainMenu()
{
@@ -58,32 +56,32 @@ namespace PD_Tool
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(JSON ? "8. MsgPack to JSON" : "9. JSON to MsgPack");
ConsoleDesign(false);
ConsoleDesign(json ? "M. MessagePack" : "J. JSON");
ConsoleDesign(JSON ? "M. MessagePack" : "J. JSON");
ConsoleDesign("Q. Quit");
ConsoleDesign(false);
ConsoleDesign(true);
Console.WriteLine();
choose = Console.ReadLine().ToUpper();
bool isNumber = int.TryParse(choose, out int result);
function = Console.ReadLine().ToUpper();
bool isNumber = int.TryParse(function, out int result);
if (isNumber) Functions();
if (choose == "M") json = false;
else if (choose == "J") json = true ;
if (function == "M") JSON = false;
else if (function == "J") JSON = true ;
}
private static void Functions()
{
Console.Clear();
if (choose == "1" || choose == "2") FARC.Processor(choose == "1");
else if (choose == "3" || choose == "4")
if (function == "1" || function == "2") FARC.Processor(function == "1");
else if (function == "3" || function == "4")
{
Choose(1, "", out string[] FileNames);
foreach (string FileName in FileNames) DIVAFILE.Decrypt(FileName);
}
else if (choose == "5") DataBase.Processor(json);
else if (choose == "6")
else if (function == "5") DataBase.Processor(JSON);
else if (function == "6")
{
Console.Clear();
Console.Title = "AC/DT/F/AFT/FT Converting Tools";
@@ -95,25 +93,25 @@ namespace PD_Tool
ConsoleDesign("3. DataBank");
ConsoleDesign("4. DEX" );
ConsoleDesign("5. DIVA" );
ConsoleDesign("6. MotHead" );
ConsoleDesign("7. MOT" );
ConsoleDesign("8. STR" );
ConsoleDesign("6. MOT" );
ConsoleDesign("7. STR" );
ConsoleDesign(false);
ConsoleDesign("R. Return to Main Menu");
ConsoleDesign(false);
ConsoleDesign(true);
Console.WriteLine();
string localChoose = Console.ReadLine();
if (localChoose == "1") A3D.Processor(json);
else if (localChoose == "2") AET.Processor(json);
else if (localChoose == "3") DB .Processor(json);
else if (localChoose == "4") DEX.Processor(json);
else if (localChoose == "5") DIV.Processor();
else if (localChoose == "6") MOT.Processor(json);
else if (localChoose == "7") STR.Processor(json);
else choose = localChoose;
string Function = Console.ReadLine();
Console.Clear();
if (Function == "1") Tools.A3D.Processor(JSON);
else if (Function == "2") Tools.AET.Processor(JSON);
else if (Function == "3") Tools.DB .Processor(JSON);
else if (Function == "4") Tools.DEX.Processor(JSON);
else if (Function == "5") Tools.DIV.Processor();
else if (Function == "6") Tools.MOT.Processor(JSON);
else if (Function == "7") Tools.STR.Processor(JSON);
else function = Function;
}
else if (choose == "7")
else if (function == "7")
{
Console.Clear();
Console.Title = "F/F2/X/FT Converting Tools";
@@ -126,39 +124,38 @@ namespace PD_Tool
ConsoleDesign("4. DEX" );
ConsoleDesign("5. DOF" );
ConsoleDesign("6. Light" );
ConsoleDesign("7. Particles" );
ConsoleDesign("8. STR" );
ConsoleDesign("9. VAG" );
ConsoleDesign("7. STR" );
ConsoleDesign("8. VAG" );
ConsoleDesign(false);
ConsoleDesign("R. Return to Main Menu");
ConsoleDesign(false);
ConsoleDesign(true);
Console.WriteLine();
string localChoose = Console.ReadLine();
if (localChoose == "1") A3D.Processor(json);
else if (localChoose == "2") BLT.Processor();
else if (localChoose == "3") CCT.Processor();
else if (localChoose == "4") DEX.Processor(json);
else if (localChoose == "5") DFT.Processor();
else if (localChoose == "6") LIT.Processor();
else if (localChoose == "7") STR.Processor(json);
else if (localChoose == "8") VAG.Processor();
else choose = localChoose;
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 (choose == "8")
else if (function == "8")
{
Console.Title = json ? "MsgPack to JSON" : "JSON to MsgPack";
Choose(1, json ? "mp" : "json", out string[] fileNames);
foreach (string file in fileNames)
if (json)
Choose(1, JSON ? "mp" : "json", out string[] FileNames);
foreach (string file in FileNames)
if (JSON)
{
Console.Title = "MsgPack to JSON: " + Path.GetFileNameWithoutExtension(file);
file.Replace(Path.GetExtension(file), "").ToJSON ();
MPExt.ToJSON (file.Replace(Path.GetExtension(file), ""));
}
else
{
Console.Title = "JSON to MsgPack: " + Path.GetFileNameWithoutExtension(file);
file.Replace(Path.GetExtension(file), "").ToMsgPack();
MPExt.ToMsgPack(file.Replace(Path.GetExtension(file), ""));
}
}
}
@@ -201,47 +198,50 @@ namespace PD_Tool
public static string Choose(int code, string filetype, out string[] FileNames)
{
string mp = GetArgs("MessagePack", true, "mp" );
string json = GetArgs("JSON" , true, "json");
string bin = GetArgs("BIN" , true, "bin" );
string wav = GetArgs("WAV" , true, "wav" );
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 + mp;
GetArgs("A3DA", true, "a3da") + GetArgs("FARC", true, "farc") + JSON + MsgPack;
else if (filetype == "bin" ) Filter = GetArgs("BIN" , "bin", "json", "mp") +
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 + 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 + mp;
GetArgs("DAT", true, "dat") + JSON + MsgPack;
else if (filetype == "dex" ) Filter = GetArgs("DEX" , "dex", "bin", "json", "mp") +
GetArgs("DEX", true, "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") + 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 + mp;
GetArgs("STR", true, "str") + BIN + JSON + MsgPack;
else if (filetype == "vag" ) Filter = GetArgs("VAG" , "vag", "wav") +
GetArgs("VAG", true, "vag") + wav;
using OpenFileDialog ofd = new OpenFileDialog { //InitialDirectory = Application.StartupPath,
Filter = Filter, Multiselect = true, Title = "Choose file(s) to open:" };
if (ofd.ShowDialog() == DialogResult.OK) FileNames = ofd.FileNames;
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,
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);
+2 -2
View File
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
[assembly: AssemblyVersion("0.4.8.1")]
[assembly: AssemblyFileVersion("0.4.8.1")]
[assembly: AssemblyVersion("0.4.7.6")]
[assembly: AssemblyFileVersion("0.4.7.6")]
-175
View File
@@ -1,175 +0,0 @@
using System;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdA3DA = KKdMainLib.A3DA;
using KKdFARC = KKdMainLib.FARC;
namespace PD_Tool
{
class A3D
{
public static void Processor(bool json)
{
Console.Title = "A3DA Converter";
Program.Choose(1, "a3da", out string[] fileNames);
if (fileNames.Length < 1) return;
bool mp = false;
foreach (string file in fileNames)
if (file.EndsWith(".mp") || file.EndsWith(".json") || file.EndsWith(".farc")) { mp = true; break; }
Format format = Format.NULL;
string choose = "";
if (mp)
{
Console.Clear();
Program.ConsoleDesign(true);
Program.ConsoleDesign(" Choose type of format to export:");
Program.ConsoleDesign(false);
Program.ConsoleDesign("1. A3DA [DT/AC/F]");
Program.ConsoleDesign("2. A3DC [DT/AC/F]");
Program.ConsoleDesign("3. A3DA [AFT/FT] ");
Program.ConsoleDesign("4. A3DC [AFT/FT] ");
Program.ConsoleDesign("5. A3DC [F2] ");
Program.ConsoleDesign("6. A3DC [MGF] ");
Program.ConsoleDesign("7. A3DC [X] ");
Program.ConsoleDesign(false);
Program.ConsoleDesign(true);
Console.WriteLine();
choose = Console.ReadLine();
if (choose == "1") format = Format.DT ;
else if (choose == "2") format = Format.F ;
else if (choose == "3") format = Format.AFT ;
else if (choose == "4") format = Format.AFT ;
else if (choose == "5") format = Format.F2LE;
else if (choose == "6") format = Format.MGF ;
else if (choose == "7") format = Format.X ;
else return;
}
int state;
string filepath, ext;
KKdA3DA a3da;
foreach (string file in fileNames)
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "A3DA Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".farc")
using (KKdFARC farc = new KKdFARC(file))
FARCProcessor(farc, choose, format);
else if (ext == ".a3da")
using (a3da = new KKdA3DA(true))
{
state = a3da.A3DAReader(filepath);
if (state == 1) a3da.MsgPackWriter(filepath, json);
}
else if (ext == ".mp" || ext == ".json")
using (a3da = new KKdA3DA(true))
{
a3da.MsgPackReader(filepath, ext == ".json");
a3da.Data._.CompressF16 = format > Format.AFT && format <
Format.FT ? format == Format.MGF ? 2 : 1 : 0;
a3da.Head.Format = format;
File.WriteAllBytes(filepath + ".a3da", (choose != "1" &&
choose != "3") ? a3da.A3DCWriter() : a3da.A3DAWriter());
}
}
}
private static void FARCProcessor(KKdFARC farc, string choose, Format format)
{
if (!farc.HeaderReader()) return;
if (!farc.HasFiles) return;
KKdList<string> list = KKdList<string>.New;
for (int i = 0; i < farc.Files.Count; i++)
{
string file = farc.Files[i].Name.ToLower();
bool div = false;
for (int i0 = 0; i0 < 159 && !div; i0++)
if (file.Contains("div_" + i0)) div = true;
if (!div && file.EndsWith(".a3da")) list.Add(file);
}
KKdList<string> A3DAlist = KKdList<string>.New;
for (int i = 0; i < farc.Files.Count; i++)
if (farc.Files[i].Name.ToLower().EndsWith(".a3da"))
A3DAlist.Add(farc.Files[i].Name);
byte[] data = null;
if (list.Count == A3DAlist.Count || (format > Format.AFT && format < Format.FT))
{
KKdA3DA a3da;
for (int i = 0; i < A3DAlist.Count; i++)
using (a3da = new KKdA3DA(true))
{
data = farc.FileReader(A3DAlist[i]);
int state = a3da.A3DAReader(data);
if (state == 1)
{
KKdFARC.FARCFile file = farc.Files[i];
a3da.Data._.CompressF16 = format > Format.AFT && format <
Format.FT ? format == Format.MGF ? 2 : 1 : 0;
a3da.Head.Format = format;
file.Data = (choose != "1" && choose != "3") ? a3da.A3DCWriter() : a3da.A3DAWriter();
farc.Files[i] = file;
}
}
farc.Save();
return;
}
KKdA3DA[] a3daArray;
using (KKdList<KKdA3DA> a3daList = KKdList<KKdA3DA>.New)
{
for (int i = 0; i < list.Count; i++)
{
KKdA3DA a3da;
using (a3da = new KKdA3DA(true))
{
data = farc.FileReader(list[i]);
int state = a3da.A3DAReader(data);
if (state == 1) a3daList.Add(a3da);
}
}
a3daArray = a3daList.ToArray();
}
for (int i = 0; i < list.Count; i++)
{
if (a3daArray[i].Data.PlayControl.Div == null) continue;
float Div = a3daArray[i].Data.PlayControl.Div.Value;
KKdA3DA a3da;
for (int i1 = 1; i1 < Div; i1++)
using (a3da = new KKdA3DA(true))
{
string file = Path.GetFileNameWithoutExtension(list[i]) +
"_div_" + i1 + Path.GetExtension(list[i]);
data = farc.FileReader(file);
int state = a3da.A3DAReader(data);
if (state == 1) a3daArray[i].A3DAMerger(ref a3da.Data);
}
a3daArray[i].Data.PlayControl.Div = null;
}
farc.Files.Capacity = list.Count;
for (int i = 0; i < list.Count; i++)
{
KKdFARC.FARCFile file = default;
file.Name = list[i];
a3daArray[i].Data._.CompressF16 = format > Format.AFT && format <
Format.FT ? format == Format.MGF ? 2 : 1 : 0;
a3daArray[i].Head.Format = format;
file.Data = (choose != "1" && choose != "3") ? a3daArray[i].A3DCWriter() : a3daArray[i].A3DAWriter();
farc.Files.Add(file);
}
farc.Save();
return;
}
}
}
-38
View File
@@ -1,38 +0,0 @@
using System;
using KKdMainLib.IO;
using KKdAet = KKdMainLib.Aet.Aet;
namespace PD_Tool
{
public class AET
{
public static void Processor(bool json)
{
Console.Title = "AET Converter";
Program.Choose(1, "bin", out string[] fileNames);
if (fileNames.Length < 1) return;
string filepath, ext;
KKdAet aet;
foreach (string file in fileNames)
using (aet = new KKdAet())
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "AET Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".bin")
{
aet. AETReader(filepath);
aet.MsgPackWriter(filepath, json);
}
else if (ext == ".mp" || ext == ".json")
{
aet.MsgPackReader(filepath, ext == ".json");
aet. AETWriter(filepath);
}
}
}
}
}
-29
View File
@@ -1,29 +0,0 @@
using System;
using KKdMainLib.IO;
using KKdMainLib.F2;
namespace PD_Tool
{
public class BLT
{
public static void Processor()
{
Console.Title = "Bloom Converter";
Program.Choose(1, "blt", out string[] fileNames);
if (fileNames.Length < 1) return;
string filepath, ext;
Bloom blt;
foreach (string file in fileNames)
using (blt = new Bloom())
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "Bloom Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".blt") { blt.BLTReader(filepath); blt.TXTWriter(filepath); }
}
}
}
}
-29
View File
@@ -1,29 +0,0 @@
using System;
using KKdMainLib.IO;
using KKdMainLib.F2;
namespace PD_Tool
{
public class CCT
{
public static void Processor()
{
Console.Title = "Color Correction Converter";
Program.Choose(1, "cct", out string[] fileNames);
if (fileNames.Length < 1) return;
string filepath, ext;
ColorCorrection cct;
foreach (string file in fileNames)
using (cct = new ColorCorrection())
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "Color Correction Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".cct") { cct.CCTReader(filepath); cct.TXTWriter(filepath); }
}
}
}
}
-66
View File
@@ -1,66 +0,0 @@
using System;
using KKdMainLib.IO;
namespace PD_Tool
{
public class DB
{
public static void Processor(bool json)
{
Console.Title = "DataBank Converter";
Program.Choose(1, "databank", out string[] fileNames);
if (fileNames.Length < 1) return;
bool mp = true;
foreach (string file in fileNames)
if (file.EndsWith(".mp" )) { mp = false; break; }
else if (file.EndsWith(".json")) { mp = false; break; }
string choose = "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();
choose = Console.ReadLine();
}
uint num2 = (uint)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
string[] file_split;
string filepath, ext;
KKdMainLib.DataBank db;
foreach (string file in fileNames)
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
string filename = Path.GetFileNameWithoutExtension(file);
file_split = filename.Split('_');
using (db = new KKdMainLib.DataBank())
{
if (file_split.Length == 5 && ext == ".dat" && mp)
{
filepath = file.Replace(filename + ".dat", "");
Console.Title = "DataBank Converter: " + filename;
db. DBReader(file);
db.MsgPackWriter(filepath + file_split[0] + "_" +
file_split[1] + "_" + file_split[2], json, choose != "2");
}
else if ((ext == ".mp" || ext == ".json") && !mp)
{
Console.Title = "DataBank Converter: " + filename;
db.MsgPackReader(filepath, json);
db. DBWriter(filepath, num2);
}
}
}
}
}
}
-62
View File
@@ -1,62 +0,0 @@
using System;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdDEX = KKdMainLib.DEX;
namespace PD_Tool
{
public class DEX
{
public static void Processor(bool json)
{
Console.Title = "DEX Converter";
Program.Choose(1, "dex", out string[] fileNames);
if (fileNames.Length < 1) return;
bool mp = true;
bool _json = true;
foreach (string file in fileNames)
if (file.EndsWith(".mp" )) { mp = false; break; }
else if (file.EndsWith(".json")) { _json = false; break; }
Console.Clear();
string choose = "";
Program.ConsoleDesign(true);
Program.ConsoleDesign(" Choose type of exporting file:");
Program.ConsoleDesign(false);
Program.ConsoleDesign("1. F/FT PS3/PS4/PSVita");
Program.ConsoleDesign("2. F2 PS3/PSVita");
Program.ConsoleDesign("3. X PS4/PSVita");
if ( mp && !json) Program.ConsoleDesign("9. MessagePack");
if (_json && json) Program.ConsoleDesign("9. JSON");
Program.ConsoleDesign(false);
Program.ConsoleDesign(true);
Console.WriteLine();
choose = Console.ReadLine();
Format format = Format.NULL;
if (choose == "1") format = Format.F ;
else if (choose == "2") format = Format.F2LE;
else if (choose == "3") format = Format.X ;
else if (choose == "9" && mp && _json) format = Format.NULL;
else return;
string filepath, ext;
KKdDEX DEX;
foreach (string file in fileNames)
using (DEX = new KKdDEX())
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "DEX Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".bin" || ext == ".dex") DEX. DEXReader(filepath, ext );
else DEX.MsgPackReader(filepath, json);
if (format > Format.NULL) DEX. DEXWriter(filepath, format);
else DEX.MsgPackWriter(filepath, json);
}
}
}
}
-29
View File
@@ -1,29 +0,0 @@
using System;
using KKdMainLib.IO;
using KKdMainLib.F2;
namespace PD_Tool
{
public class DFT
{
public static void Processor()
{
Console.Title = "DOF Converter";
Program.Choose(1, "dft", out string[] fileNames);
if (fileNames.Length < 1) return;
string filepath, ext;
DOF dft;
foreach (string file in fileNames)
using (dft = new DOF())
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "DOF Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".dft") { dft.DFTReader(filepath); dft.TXTWriter(filepath); }
}
}
}
}
+73 -69
View File
@@ -1,14 +1,12 @@
using System;
using System.IO;
using Aet = KKdMainLib.DB.Aet;
using Auth = KKdMainLib.DB.Auth;
using Spr = KKdMainLib.DB.Spr;
using DB = KKdMainLib.DB;
namespace PD_Tool
{
public class DataBase
{
public static void Processor(bool json)
public static void Processor(bool JSON)
{
Console.Title = "DB Converter";
Console.Clear();
@@ -24,93 +22,99 @@ namespace PD_Tool
Program.ConsoleDesign(true);
Console.WriteLine();
string format = Console.ReadLine();
if (format == "1") AuthDBProcessor(json);
if (format == "2") AETDBProcessor(json);
if (format == "3") SPRDBProcessor(json);
if (format == "1") AuthDBProcessor(JSON);
if (format == "2") AETDBProcessor(JSON);
if (format == "3") SPRDBProcessor(JSON);
}
public static void AuthDBProcessor(bool JSON)
{
Console.Title = "Auth DB Converter";
Program.Choose(1, "bin", out string[] fileNames);
if (fileNames.Length < 1) return;
DB.Auth Auth;
Program.Choose(1, "bin", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
string filepath, ext;
Auth auth;
foreach (string file in fileNames)
using (auth = new Auth())
foreach (string file in FileNames)
{
Console.Title = "Auth DB Converter: " + Path.GetFileNameWithoutExtension(file);
Auth = new DB.Auth();
ext = Path.GetExtension(file).ToLower();
filepath = file.Replace(Path.GetExtension(file), "");
if (ext == ".bin")
{
Console.Title = "Auth DB Converter: " + Path.GetFileNameWithoutExtension(file);
ext = Path.GetExtension(file).ToLower();
filepath = file.Replace(Path.GetExtension(file), "");
if (ext == ".bin")
{
auth.BINReader (filepath);
auth.MsgPackWriter(filepath, JSON);
}
else if (ext == ".mp" || ext == ".json")
{
auth.MsgPackReader(filepath, ext == ".json");
auth.BINWriter (filepath);
}
Auth.BINReader (filepath);
Auth.MsgPackWriter(filepath, JSON);
}
else if (ext == ".mp" || ext == ".json")
{
Auth.MsgPackReader(filepath, ext == ".json");
Auth.BINWriter (filepath);
}
Auth = null;
}
}
public static void AETDBProcessor(bool json)
public static void AETDBProcessor(bool JSON)
{
Console.Title = "AET DB Converter";
Program.Choose(1, "bin", out string[] fileNames);
if (fileNames.Length < 1) return;
DB.Aet Aet;
Program.Choose(1, "bin", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
string filepath, ext;
Aet aet;
foreach (string file in fileNames)
using (aet = new Aet())
foreach (string file in FileNames)
{
Console.Title = "AET DB Converter: " + Path.GetFileNameWithoutExtension(file);
Aet = new DB.Aet();
ext = Path.GetExtension(file).ToLower();
filepath = file.Replace(Path.GetExtension(file), "");
if (ext == ".bin")
{
Console.Title = "AET DB Converter: " + Path.GetFileNameWithoutExtension(file);
ext = Path.GetExtension(file).ToLower();
filepath = file.Replace(Path.GetExtension(file), "");
if (ext == ".bin")
{
aet.BINReader (filepath);
aet.MsgPackWriter(filepath, json);
}
else if (ext == ".mp" || ext == ".json")
{
aet.MsgPackReader(filepath, ext == ".json");
aet.BINWriter (filepath);
}
Aet.BINReader (filepath);
Aet.MsgPackWriter(filepath, JSON);
}
else if (ext == ".mp" || ext == ".json")
{
Aet.MsgPackReader(filepath, ext == ".json");
Aet.BINWriter (filepath);
}
Aet = null;
}
}
public static void SPRDBProcessor(bool json)
public static void SPRDBProcessor(bool JSON)
{
Console.Title = "SPR DB Converter";
Program.Choose(1, "bin", out string[] fileNames);
if (fileNames.Length < 1) return;
DB.Spr Spr;
Program.Choose(1, "bin", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
string filepath, ext;
Spr spr;
foreach (string file in fileNames)
using (spr = new Spr())
foreach (string file in FileNames)
{
Console.Title = "SPR DB Converter: " + Path.GetFileNameWithoutExtension(file);
Spr = new DB.Spr();
ext = Path.GetExtension(file).ToLower();
filepath = file.Replace(Path.GetExtension(file), "");
if (ext == ".bin")
{
Console.Title = "SPR DB Converter: " + Path.GetFileNameWithoutExtension(file);
ext = Path.GetExtension(file).ToLower();
filepath = file.Replace(Path.GetExtension(file), "");
if (ext == ".bin")
{
spr.BINReader (filepath);
spr.MsgPackWriter(filepath, json);
}
else if (ext == ".mp" || ext == ".json")
{
spr.MsgPackReader(filepath, ext == ".json");
spr.BINWriter (filepath);
}
Spr.BINReader (filepath);
Spr.MsgPackWriter(filepath, JSON);
}
else if (ext == ".mp" || ext == ".json")
{
Spr.MsgPackReader(filepath, ext == ".json");
Spr.BINWriter (filepath);
}
Spr = null;
}
}
}
}
+48 -48
View File
@@ -1,74 +1,74 @@
using System;
using System.IO;
using KKdMainLib;
using KKdFARC = KKdMainLib.FARC;
namespace PD_Tool
{
public class FARC
{
public static void Processor(bool extract)
public static void Processor(bool Extract)
{
KKdFARC FARC = new KKdFARC();
Console.Clear();
if (extract)
if (Extract)
{
Console.Title = "FARC Extractor";
Program.Choose(1, "farc", out string[] fileNamesExtract);
foreach (string fileExtract in fileNamesExtract)
if (fileExtract != "" && File.Exists(fileExtract))
Program.Choose(1, "farc", out string[] FileNames);
foreach (string file in FileNames)
if (file != "" && File.Exists(file))
{
Console.Title = "FARC Extractor: " + Path.GetFileNameWithoutExtension(fileExtract);
using (KKdFARC farc = new KKdFARC(fileExtract))
farc.UnPack();
Console.Title = "FARC Extractor: " + Path.GetFileNameWithoutExtension(file);
new KKdFARC(file).UnPack();
}
return;
}
string file = Program.Choose(2, "", out string[] fileNames);
Console.Clear();
if (file == null || file == "") return;
Console.Title = "FARC Creator";
using (KKdFARC farc = new KKdFARC(file, true))
else
{
Console.Title = "FARC Creator: " + Path.GetDirectoryName(file);
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();
string choose = Console.ReadLine().ToUpper();
if (choose == "1") farc.Signature = KKdFARC.Farc.FArc;
else if (choose == "3" || choose == "4")
string file = Program.Choose(2, "", out string[] FileNames);
Console.Clear();
Console.Title = "FARC Creator";
if (file != "")
{
farc.Signature = KKdFARC.Farc.FARC;
Console.Clear();
Console.Title = "FARC Creator: " + Path.GetDirectoryName(file);
FARC = new KKdFARC();
Program.ConsoleDesign(true);
Program.ConsoleDesign(" Choose type of FARC:");
Program.ConsoleDesign(" Choose type of created 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("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();
choose = Console.ReadLine();
if (choose == "2" || choose == "4") farc.FARCType |= KKdFARC.Type.GZip;
if (choose == "3" || choose == "4") farc.FARCType |= KKdFARC.Type.ECB ;
Console.WriteLine("Choosed folder: {0}", file);
Console.WriteLine();
string type = Console.ReadLine().ToUpper();
if (type == "1") FARC.Signature = KKdFARC.Farc.FArc;
else if (type == "3" || type == "4")
{
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);
}
else if (choose == "R") return;
else farc.Signature = KKdFARC.Farc.FArC;
farc.Pack(farc.Signature);
}
}
}
-29
View File
@@ -1,29 +0,0 @@
using System;
using KKdMainLib.IO;
using KKdMainLib.F2;
namespace PD_Tool
{
public class LIT
{
public static void Processor()
{
Console.Title = "Light Converter";
Program.Choose(1, "lit", out string[] fileNames);
if (fileNames.Length < 1) return;
string filepath, ext;
Light lit;
foreach (string file in fileNames)
using (lit = new Light())
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "Light Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".lit") { lit.LITReader(filepath); lit.TXTWriter(filepath); }
}
}
}
}
-39
View File
@@ -1,39 +0,0 @@
using System;
using KKdMainLib;
using KKdMainLib.IO;
namespace PD_Tool
{
public class MOT
{
public static void Processor(bool json)
{
Console.Title = "MOT Converter";
Program.Choose(1, "bin", out string[] fileNames);
if (fileNames.Length < 1) return;
string filepath, ext;
Mot mot;
foreach (string file in fileNames)
{
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();
}
}
}
}
-38
View File
@@ -1,38 +0,0 @@
using System;
using KKdMainLib.IO;
using KKdSTR = KKdMainLib.STR;
namespace PD_Tool
{
public class STR
{
public static void Processor(bool json)
{
Console.Title = "STR Converter";
Program.Choose(1, "str", out string[] fileNames);
string filepath, ext;
KKdSTR str;
foreach (string file in fileNames)
using (str = new KKdSTR())
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "PD_Tool: Converter Tools: STR Reader: " +
Path.GetFileNameWithoutExtension(file);
if (ext == ".str" || ext == ".bin")
{
str.STRReader (filepath, ext);
str.MsgPackWriter(filepath, json);
}
else if (ext == ".json" || ext == ".mp")
{
str.MsgPackReader(filepath, ext == ".json");
str.STRWriter (filepath);
}
}
}
}
}
+104
View File
@@ -0,0 +1,104 @@
using System;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdA3DA = KKdMainLib.A3DA;
using KKdFARC = KKdMainLib.FARC;
namespace PD_Tool.Tools
{
class A3D
{
public static void Processor(bool JSON)
{
Console.Title = "A3DA Converter";
Program.Choose(1, "a3da", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
bool MP = false;
foreach (string file in FileNames)
if (file.EndsWith(".mp") || file.EndsWith(".json") || file.EndsWith(".farc")) { MP = true; break; }
Format Format = Format.NULL;
string format = "";
if (MP)
{
Console.Clear();
Program.ConsoleDesign(true);
Program.ConsoleDesign(" Choose type of format to export:");
Program.ConsoleDesign(false);
Program.ConsoleDesign("1. A3DA [DT/AC/F]");
Program.ConsoleDesign("2. A3DC [DT/AC/F]");
Program.ConsoleDesign("3. A3DA [AFT/FT] ");
Program.ConsoleDesign("4. A3DC [AFT/FT] ");
Program.ConsoleDesign("5. A3DC [F2] ");
Program.ConsoleDesign("6. A3DC [MGF] ");
Program.ConsoleDesign("7. A3DC [X] ");
Program.ConsoleDesign(false);
Program.ConsoleDesign(true);
Console.WriteLine();
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();
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "A3DA Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".farc")
using (KKdFARC FARC = new KKdFARC(file))
{
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")
{
state = A.A3DAReader(filepath);
if (state == 1) A.MsgPackWriter(filepath, JSON);
}
else if (ext == ".mp" || ext == ".json")
{
A.MsgPackReader(filepath, ext == ".json");
A.Data._.CompressF16 = Format > Format.FT ? Format == Format.MGF ? 2 : 1 : 0;
A.Head.Format = Format;
File.WriteAllBytes(filepath + ".a3da", (format != "1" &&
format != "3") ? A.A3DCWriter() : A.A3DAWriter());
}
A = null;
}
}
}
}
+40
View File
@@ -0,0 +1,40 @@
using System;
using KKdMainLib.IO;
using KKdAet = KKdMainLib.Aet.Aet;
namespace PD_Tool.Tools
{
public class AET
{
public static void Processor(bool JSON)
{
Console.Title = "AET Converter";
KKdAet Aet;
Program.Choose(1, "bin", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
foreach (string file in FileNames)
{
Aet = new KKdAet();
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "AET Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".bin")
{
Aet. AETReader(filepath);
Aet.MsgPackWriter(filepath, JSON);
}
else if (ext == ".mp" || ext == ".json")
{
Aet.MsgPackReader(filepath, ext == ".json");
Aet. AETWriter(filepath);
}
Aet = null;
}
}
}
}
+32
View File
@@ -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();
}
}
}
}
+32
View File
@@ -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();
}
}
}
}
+66
View File
@@ -0,0 +1,66 @@
using System;
using KKdMainLib.IO;
namespace PD_Tool.Tools
{
public class DB
{
public static void Processor(bool JSON)
{
Console.Title = "DataBank Converter";
Program.Choose(1, "databank", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
bool MP = true;
foreach (string file in FileNames)
if (file.EndsWith(".mp" )) { MP = false; break; }
else if (file.EndsWith(".json")) { MP = false; break; }
string format = "1";
if (MP)
{
Console.Clear();
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;
foreach (string file in FileNames)
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
string filename = Path.GetFileNameWithoutExtension(file);
file_split = filename.Split('_');
DB = new KKdMainLib.DataBank();
if (file_split.Length == 5 && ext == ".dat" && MP)
{
filepath = file.Replace(filename + ".dat", "");
Console.Title = "DataBank Converter: " + filename;
DB. DBReader(file);
DB.MsgPackWriter(filepath + file_split[0] + "_" +
file_split[1] + "_" + file_split[2], JSON, format != "2");
}
else if ((ext == ".mp" || ext == ".json") && !MP)
{
Console.Title = "DataBank Converter: " + filename;
DB.MsgPackReader(filepath, JSON);
DB. DBWriter(filepath, num2);
}
DB = null;
}
}
}
}
+72
View File
@@ -0,0 +1,72 @@
using System;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdDEX = KKdMainLib.DEX;
namespace PD_Tool.Tools
{
public class DEX
{
public static void Processor(bool JSON)
{
Console.Title = "DEX Converter";
KKdDEX DEX;
Program.Choose(1, "dex", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
bool MP = true;
bool _JSON = true;
foreach (string file in FileNames)
if (file.EndsWith(".mp" ))
{ MP = false; break; }
else if (file.EndsWith(".json"))
{ _JSON = false; break; }
Console.Clear();
string format = "";
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();
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();
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "DEX Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".bin" || ext == ".dex")
state = DEX. DEXReader(filepath, ext );
else state = DEX.MsgPackReader(filepath, JSON);
if (state == 1)
{
if (Format > Format.NULL)
DEX. DEXWriter(filepath, Format);
else DEX.MsgPackWriter(filepath, JSON);
}
DEX = null;
}
}
}
}
+32
View File
@@ -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();
}
}
}
}
@@ -2,29 +2,30 @@
using System.IO;
using KKdSoundLib;
namespace PD_Tool
namespace PD_Tool.Tools
{
public class DIV
{
public static void Processor()
{
Console.Title = "DIVA Converter";
Program.Choose(1, "diva", out string[] fileNames);
if (fileNames.Length < 1) return;
Program.Choose(1, "diva", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
string filepath, ext;
DIVA diva;
foreach (string file in fileNames)
DIVA DIVA;
foreach (string file in FileNames)
{
diva = new DIVA();
DIVA = new DIVA();
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "DIVA Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".diva") diva.DIVAReader(filepath);
else if (ext == ".wav" ) diva.DIVAWriter(filepath);
diva = null;
if (ext == ".diva") DIVA.DIVAReader(filepath);
else if (ext == ".wav" ) DIVA.DIVAWriter(filepath);
DIVA = null;
}
}
}
+32
View File
@@ -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();
}
}
}
}
+40
View File
@@ -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();
}
}
}
}
+40
View File
@@ -0,0 +1,40 @@
using System;
using KKdMainLib.IO;
using KKdSTR = KKdMainLib.STR;
namespace PD_Tool.Tools
{
public class STR
{
public static void Processor(bool JSON)
{
Console.Title = "STR Converter";
Program.Choose(1, "str", out string[] FileNames);
KKdSTR Data;
string filepath = "";
string ext = "";
foreach (string file in FileNames)
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Data = new KKdSTR();
Console.Title = "PD_Tool: Converter Tools: STR Reader: " +
Path.GetFileNameWithoutExtension(file);
if (ext == ".str" || ext == ".bin")
{
Data.STRReader (filepath, ext);
Data.MsgPackWriter(filepath, JSON);
}
else if (ext == ".json" || ext == ".mp")
{
Data.MsgPackReader(filepath, ext == ".json");
Data.STRWriter (filepath);
}
Data = null;
}
}
}
}
+53
View File
@@ -0,0 +1,53 @@
using System;
using System.IO;
using KKdVAG = KKdSoundLib.VAG;
namespace PD_Tool.Tools
{
public class VAG
{
public static void Processor()
{
Console.Title = "VAG Converter";
Program.Choose(1, "vag", out string[] FileNames);
if (FileNames.Length < 1) return;
string filepath = "";
string ext = "";
bool InputWAV = false;
foreach (string file in FileNames)
if (Path.GetExtension(file) == ".wav")
InputWAV = true;
bool HE_VAG = true;
if (InputWAV)
{
Console.Clear();
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";
}
KKdVAG VAG;
foreach (string file in FileNames)
{
VAG = new KKdVAG();
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "VAG Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".vag") { VAG.VAGReader(filepath); VAG.WAVWriter(filepath ); }
else if (ext == ".wav") { VAG.WAVReader(filepath); VAG.VAGWriter(filepath, HE_VAG); }
VAG = null;
}
}
}
}
-54
View File
@@ -1,54 +0,0 @@
using System;
using System.IO;
using KKdVAG = KKdSoundLib.VAG;
namespace PD_Tool
{
public class VAG
{
public static void Processor()
{
Console.Title = "VAG Converter";
Program.Choose(1, "vag", out string[] fileNames);
if (fileNames.Length < 1) return;
bool wav = false;
foreach (string file in fileNames)
if (Path.GetExtension(file) == ".wav")
wav = true;
string choose = "";
if (wav)
{
Console.Clear();
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 [Fastest]");
Program.ConsoleDesign("3. HEVAG [Fast]");
Program.ConsoleDesign("4. HEVAG [Medium]");
Program.ConsoleDesign("5. HEVAG [Slow]");
Program.ConsoleDesign("6. HEVAG [Slowest]");
Program.ConsoleDesign(false);
Program.ConsoleDesign(true);
Console.WriteLine();
choose = Console.ReadLine();
}
string filepath, ext;
KKdVAG VAG;
foreach (string file in fileNames)
using (VAG = new KKdVAG())
{
ext = Path.GetExtension(file);
filepath = file.Replace(ext, "");
ext = ext.ToLower();
Console.Title = "VAG Converter: " + Path.GetFileNameWithoutExtension(file);
if (ext == ".vag") { VAG.VAGReader(filepath); VAG.WAVWriter(filepath ); }
else if (ext == ".wav") { VAG.WAVReader(filepath); VAG.VAGWriter(filepath, choose); }
}
}
}
}