Compare 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
52 changed files with 4161 additions and 3893 deletions
+305
View File
@@ -0,0 +1,305 @@
namespace KKdBaseLib.A3DA
{
public struct A3DAData
{
public string[] Motion;
public string[] ObjectList;
public string[] ObjectHRCList;
public string[] MObjectHRCList;
public _ _;
public DOF DOF;
public Fog[] Fog;
public Curve[] Curve;
public Event[] Event;
public Light[] Light;
public Object[] Object;
public Ambient[] Ambient;
public ObjectHRC[] ObjectHRC;
public CameraRoot[] CameraRoot;
public MObjectHRC[] MObjectHRC;
public PlayControl PlayControl;
public PostProcess PostProcess;
public MaterialList[] MaterialList;
public ModelTransform[] Chara;
public ModelTransform[] Point;
public CameraAuxiliary CameraAuxiliary;
}
public struct _
{
public int? CompressF16;
public string FileName;
public string PropertyVersion;
public string ConverterVersion;
}
public struct Ambient
{
public string Name;
public Vector4<Key> LightDiffuse;
public Vector4<Key> RimLightDiffuse;
}
public struct CameraAuxiliary
{
public Key Gamma;
public Key Exposure;
public Key Saturate;
public Key GammaRate;
public Key AutoExposure;
}
public struct CameraRoot
{
public ViewPoint VP;
public ModelTransform MT;
public ModelTransform Interest;
public struct ViewPoint
{
public bool? FOVHorizontal;
public float? Aspect;
public float? CameraApertureH;
public float? CameraApertureW;
public Key FOV;
public Key Roll;
public Key FocalLength;
public ModelTransform MT;
}
}
public struct Curve
{
public string Name;
public Key CV;
}
public class DOF
{
public string Name;
public ModelTransform MT;
}
public struct Event
{
public int? Type;
public float? End;
public float? Begin;
public float? ClipEnd;
public float? ClipBegin;
public float? TimeRefScale;
public string Name;
public string Param1;
public string Ref;
}
public struct Fog
{
public int? Id;
public Key End;
public Key Start;
public Key Density;
public Vector4<Key> Diffuse;
}
public struct Key
{
public KeyType? Type;
public int Length;
public int? BinOffset;
public EPType EPTypePre;
public EPType EPTypePost;
public float? Max;
public float? Value;
public RawD RawData;
public KFT3[] Keys;
public struct RawD
{
public int KeyType;
public int ValueListSize;
public string ValueType;
public string[] ValueList;
}
public enum KeyType : int
{
Null = 0,
Value = 1,
Lerp = 2,
Hermite = 3,
Hold = 4,
}
public enum EPType : int
{
EP_1 = 1,
EP_2 = 2,
EP_3 = 3,
}
public static Vector3<A3DAKey> ToA3DAKey(Vector3<Key> k) => new Vector3<A3DAKey> { X = k.X, Y = k.Y, Z = k.Z };
public static Vector3<Key> ToKey(Vector3<A3DAKey> k) => new Vector3<Key> { X = k.X, Y = k.Y, Z = k.Z };
public static implicit operator Key(A3DAKey k)
{
Key key = default;
key.EPTypePost = (EPType)(int)k.EPTypePost;
key.EPTypePre = (EPType)(int)k.EPTypePre;
key.Max = k.MaxFrames;
if (k.Length > 1)
{
key.Type = (KeyType)(int)k.Type;
key.Length = k.Length;
key.Keys = k.Keys;
}
else if (k.Length == 1)
{
key.Type = KeyType.Value;
key.Value = k.Keys[0].V;
}
return key;
}
public static implicit operator A3DAKey(Key k)
{
A3DAKey key = default;
key.EPTypePost = (A3DAKey.EPType)(int)k.EPTypePost;
key.EPTypePre = (A3DAKey.EPType)(int)k.EPTypePre;
key.MaxFrames = k.Max ?? 0;
if (k.Length > 1)
{
key.Type = (A3DAKey.KeyType)(int)k.Type;
key.Length = k.Length;
key.Keys = k.Keys;
key.FDBSaE = k.Keys[k.Length - 1].F - k.Keys[0].F;
key.VDBSaE = k.Keys[k.Length - 1].V - k.Keys[0].V;
}
else
{
key.Length = 1;
key.Keys = new KFT3[1];
if (key.Length == 1)
{
key.Type = A3DAKey.KeyType.Value;
key.Keys[0].V = k.Value ?? 0;
}
}
return key;
}
}
public struct Light
{
public int? Id;
public string Name;
public string Type;
public Vector4<Key> Ambient;
public Vector4<Key> Diffuse;
public Vector4<Key> Specular;
public Vector4<Key> Incandescence;
public ModelTransform Position;
public ModelTransform SpotDirection;
}
public struct MaterialList
{
public string Name;
public string HashName;
public Key GlowIntensity;
public Vector4<Key> BlendColor;
public Vector4<Key> Incandescence;
}
public struct MObjectHRC
{
public string Name;
public Node[] Node;
public Vector3<float?> JointOrient;
public Instance[] Instances;
public ModelTransform MT;
public struct Instance
{
public int? Shadow;
public string Name;
public string UIDName;
public ModelTransform MT;
}
}
public struct ModelTransform
{
public bool Writed;
public int? BinOffset;
public Key Visibility;
public Vector3<Key> Rot;
public Vector3<Key> Scale;
public Vector3<Key> Trans;
}
public struct Node
{
public int? Parent;
public string Name;
public ModelTransform MT;
}
public struct Object
{
public int? MorphOffset;
public string Name;
public string Morph;
public string UIDName;
public string ParentName;
public ModelTransform MT;
public TexturePattern[] TexPat;
public TextureTransform[] TexTrans;
public struct TexturePattern
{
public int? PatOffset;
public string Pat;
public string Name;
}
public struct TextureTransform
{
public string Name;
public Key Rotate;
public Key RotateFrame;
public Vector2<Key> Offset;
public Vector2<Key> Repeat;
public Vector2<Key> Coverage;
public Vector2<Key> TranslateFrame;
}
}
public struct ObjectHRC
{
public float? Shadow;
public string Name;
public string UIDName;
public Node[] Node;
public Vector3<float?> JointOrient;
}
public struct PlayControl
{
public float? Begin;
public float? Div;
public float? FPS;
public float? Offset;
public float? Size;
}
public class PostProcess
{
public Key LensFlare;
public Key LensGhost;
public Key LensShaft;
public Vector4<Key> Ambient;
public Vector4<Key> Diffuse;
public Vector4<Key> Specular;
}
}
+42
View File
@@ -0,0 +1,42 @@
namespace KKdBaseLib
{
public struct A3DAKey
{
public KeyType Type;
public int Unk04;
public float MaxFrames;
public EPType EPTypePre;
public EPType EPTypePost;
public float FDBSaE; //Frame Difference Between Start and End
public float VDBSaE; //Value Difference Between Start and End
public int Unk1C;
public int Unk20;
public int Unk24;
public int Unk28;
public int Unk2C;
public int Unk30;
public int Unk34;
public int Length;
public int Unk3C;
public int DataOffset; //Used only in-game and points to KFT3 Array
public int Unk44;
public KFT3[] Keys;
public enum KeyType : int
{
Null = 0,
Value = 1,
Lerp = 2,
Hermite = 3,
Hold = 4,
}
public enum EPType : int
{
EP_1 = 1,
EP_2 = 2,
EP_3 = 3,
}
}
}
+167
View File
@@ -0,0 +1,167 @@
namespace KKdBaseLib.Aet
{
public struct AetHeader
{
public Pointer<AetData>[] Data;
}
public struct AetData
{
public Pointer<string> Name;
public float StartFrame;
public float FrameDuration;
public float FrameRate;
public uint BackColor;
public uint Width;
public uint Height;
public Pointer<Vector2<CountPointer<KFT2>>> Position;
public CountPointer<AetLayer > Layers ;
public CountPointer<AetRegion> Regions;
public CountPointer<AetSound > Sounds ;
}
public struct AetLayer
{
public int Pointer;
public int C { get => E != null ? E.Length : 0;
set => E = value > -1 ? new AetObject[value] : null; }
public int O;
public AetObject[] E;
public override string ToString() => "Count: " + C;
}
public struct AetObject
{
public int ID;
public int Offset;
public Pointer<string> Name;
public float LoopStart;
public float LoopEnd;
public float StartFrame;
public float PlaybackSpeed;
public AetObjFlags Flags;
public byte Pad;
public AetObjType Type;
public int DataID;
public int ParentObjectID;
public CountPointer<Marker> Marker;
public Pointer<AnimationData> Data;
public Pointer<AetObjExtraData> ExtraData;
public enum AetObjFlags : ushort
{
Visible = 0b0000000000000001,
Audible = 0b0000000000000010,
Unk2 = 0b0000000000000100,
Unk3 = 0b0000000000001000,
Unk4 = 0b0000000000010000,
AudioRealted = 0b0000000000100000,
Unk6 = 0b0000000001000000,
SpriteFrames = 0b0000000010000000,
Unk8 = 0b0000000100000000,
Unk9 = 0b0000001000000000,
Unk10 = 0b0000010000000000,
Unk11 = 0b0000100000000000,
Unk12 = 0b0001000000000000,
Unk13 = 0b0010000000000000,
Unk14 = 0b0100000000000000,
Unk15 = 0b1000000000000000,
}
public enum AetObjType : byte
{
Nop = 0,
Pic = 1,
Aif = 2,
Eff = 3,
}
public struct AetObjExtraData
{
public CountPointer<KFT2> Unk0;
public CountPointer<KFT2> Unk1;
public CountPointer<KFT2> Unk2;
public CountPointer<KFT2> Unk3;
}
public override string ToString() => $"ID: {ID}; Name: {Name.V}; Type: {Type}" +
( DataID > -1 ? $"; Data ID: " + $"{ DataID}" : "") +
(ParentObjectID > -1 ? $"; Parent Object ID: {ParentObjectID}" : "");
}
public struct Marker
{
public float Frame;
public Pointer<string> Name;
}
public struct AnimationData
{
public BlendMode Mode;
public byte Padding0;
public bool UseTextureMask;
public byte Padding1;
public CountPointer<KFT2> OriginX;
public CountPointer<KFT2> OriginY;
public CountPointer<KFT2> PositionX;
public CountPointer<KFT2> PositionY;
public CountPointer<KFT2> Rotation;
public CountPointer<KFT2> ScaleX;
public CountPointer<KFT2> ScaleY;
public CountPointer<KFT2> Opacity;
public Pointer<ThirdDimension> _3D;
public enum BlendMode : byte
{
Alpha = 3,
Additive = 5,
DstColorZero = 6,
SrcAlphaOneMinusSrcColor = 7,
Transparent = 8,
}
public struct ThirdDimension
{
public CountPointer<KFT2> Unk1 ;
public CountPointer<KFT2> Unk2 ;
public CountPointer<KFT2> RotReturnX;
public CountPointer<KFT2> RotReturnY;
public CountPointer<KFT2> RotReturnZ;
public CountPointer<KFT2> RotationX;
public CountPointer<KFT2> RotationY;
public CountPointer<KFT2> ScaleZ;
}
}
public struct AetRegion
{
public int Offset;
public uint Color;
public ushort Width;
public ushort Height;
public float Frames;
public CountPointer<Sprite> Sprites;
public override string ToString() => $"Width: {Width}; Height: {Height}; Color: {Color.ToString("X2")}";
}
public struct Sprite
{
public Pointer<string> Name;
public uint ID;
public override string ToString() => $"ID: {ID}; Name: {Name}";
}
public struct AetSound
{
public int Offset;
public uint Unk0;
public uint Unk1;
public uint Unk2;
public uint Unk3;
}
}
+11 -3
View File
@@ -39,7 +39,7 @@ namespace KKdBaseLib
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0,
};
public static ushort CalculateChecksum(byte[] data)
public static ushort CalculateChecksum(this byte[] data)
{
ushort result = 0xFFFF;
for (int i = 0; i < data.Length; i++)
@@ -47,11 +47,19 @@ namespace KKdBaseLib
return result;
}
public static uint CalculateChecksumUInt(byte[] data)
public static uint CalculateChecksumUInt(this byte[] data)
{
uint result = 0xFFFFFFFF;
for (int i = 0; i < data.Length; i++)
result = ChecksumLookupTable[((ushort)result >> 8) ^ data[i]] ^ (result << 8);
result = ChecksumLookupTable[(byte)(result >> 8) ^ data[i]] ^ (result << 8);
return result;
}
public static ulong CalculateChecksumULong(this byte[] data)
{
ulong result = 0xFFFFFFFFFFFFFFFF;
for (int i = 0; i < data.Length; i++)
result = ChecksumLookupTable[(byte)(result >> 8) ^ data[i]] ^ (result << 8);
return result;
}
}
+13 -13
View File
@@ -220,32 +220,32 @@ namespace KKdBaseLib
private static readonly string NumberDecimalSeparator =
System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
public static string ToString(this bool? d) => d.GetValueOrDefault().ToString();
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.GetValueOrDefault().ToString();
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.GetValueOrDefault().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.GetValueOrDefault().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.GetValueOrDefault().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.GetValueOrDefault().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.GetValueOrDefault().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.GetValueOrDefault().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.GetValueOrDefault().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.GetValueOrDefault().ToString(round);
public static string ToString(this float? d) => d.GetValueOrDefault().ToString();
public static string ToString(this float? d, byte round) => (d ?? default).ToString(round);
public static string ToString(this float? d) => (d ?? default).ToString();
public static string ToString(this float d, byte round) =>
Math.Round(d, round).ToString().ToLower().Replace(NumberDecimalSeparator, ".");
public static string ToString(this float d) =>
d .ToString().ToLower().Replace(NumberDecimalSeparator, ".");
public static string ToString(this double? d, byte round) => d.GetValueOrDefault().ToString(round);
public static string ToString(this double? d) => d.GetValueOrDefault().ToString();
public static string ToString(this double? d, byte round) => (d ?? default).ToString(round);
public static string ToString(this double? d) => (d ?? default).ToString();
public static string ToString(this double d, byte round) =>
Math.Round(d, round).ToString().ToLower().Replace(NumberDecimalSeparator, ".");
public static string ToString(this double d) =>
+2 -2
View File
@@ -113,8 +113,8 @@
}
return length.Align(0x10);
int GetSizeType(int Val) => Val < 0x00000010 ? 1 : Val < 0x00001000 ? 2 : 4;
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)
+6 -8
View File
@@ -1,15 +1,13 @@
namespace KKdBaseLib
{
public interface IKF<TKey, TVal>
public interface IKF
{
TKey F { get; set; }
KFT0 ToT0();
KFT1 ToT1();
KFT2 ToT2();
KFT3 ToT3();
KFT0<TKey, TVal> ToT0();
KFT1<TKey, TVal> ToT1();
KFT2<TKey, TVal> ToT2();
KFT3<TKey, TVal> ToT3();
IKF<TKey, TVal> Check();
IKF Check();
string ToString();
string ToString(bool Brackets);
}
+189
View File
@@ -0,0 +1,189 @@
using Type = KKdBaseLib.A3DAKey.KeyType;
using EPType = KKdBaseLib.A3DAKey.EPType;
namespace KKdBaseLib.Interpolation
{
public struct A3DAI //A3DA Interpolation
{
private A3DAKey key;
private float F;
private float Last;
private float DeltaFrame;
private float IF;
private float RF;
private float LastTime;
private KFT3 firstKey;
private KFT3 lastKey;
public float InterpolationFramerate
{ get => IF; set { IF = value; DeltaFrame = IF / RF; } }
public float RequestedFramerate
{ get => RF; set { RF = value; DeltaFrame = IF / RF; } }
public float Frame => F;
public float Value => Last;
public bool IsNull => key.Keys == null ? true : key.Length < 1;
public bool NotNull => key.Keys == null ? false : key.Length > 0;
public A3DAI(A3DAKey key, float A3DAFramerate = 60, float RequestedFramerate = 60)
{
LastTime = 0;
this.key = key; F = -1; DeltaFrame = Last = RF = IF = 0;
IF = A3DAFramerate;
firstKey = lastKey = default;
this.RequestedFramerate = RequestedFramerate;
F = -DeltaFrame;
ResetFrameCount();
if (key.Keys != null && key.Length > 0)
{
firstKey = key.Keys[0];
lastKey = key.Keys[key.Length - 1];
}
}
public float SetTime(float time)
{
if ((int)key.Type < 1 || (int)key.Type > 4 || key.Length < 1) return 0;
if ((int)key.Type == 1) return key.Keys[0].V;
LastTime = time;
F = time * IF;
Last = Interpolate(F);
return Last;
}
public float SetFrame(float frame)
{
if ((int)key.Type < 1 || (int)key.Type > 4 || key.Length < 1) return 0;
if ((int)key.Type == 1) return key.Keys[0].V;
LastTime = frame / RF;
F = frame * DeltaFrame;
Last = Interpolate(F);
return Last;
}
public float NextFrame(float time)
{
if ((int)key.Type < 1 || (int)key.Type > 4 || key.Length < 1) return 0;
if ((int)key.Type == 1) return key.Keys[0].V;
LastTime += time;
F = LastTime * IF;
Last = Interpolate(F);
return Last;
}
public float NextFrame()
{
if ((int)key.Type < 1 || (int)key.Type > 4 || key.Length < 1) return 0;
if ((int)key.Type == 1) return key.Keys[0].V;
F += DeltaFrame;
LastTime = F / IF;
Last = Interpolate(F);
return Last;
}
private float Interpolate(float frame)
{
float DF = 0;
float EP;
float f = (int)frame;
if (f < firstKey.F)
{
DF = firstKey.F - frame;
if (key.EPTypePre == EPType.EP_2 || key.EPTypePre == EPType.EP_3)
{
frame = firstKey.F - DF % key.FDBSaE;
f = (int)frame;
}
else if (key.EPTypePre == EPType.EP_1)
return firstKey.V - DF * firstKey.T1;
else
return firstKey.V;
}
else if (f >= lastKey.F)
{
DF = frame - lastKey.F;
if (key.EPTypePost == EPType.EP_2 || key.EPTypePost == EPType.EP_3)
{
frame = firstKey.F + DF % key.FDBSaE;
f = (int)frame;
}
else if (key.EPTypePost == EPType.EP_1)
return lastKey.V + DF * lastKey.T2;
else
return lastKey.V;
}
if ((f < firstKey.F && key.EPTypePre == EPType.EP_3) ||
(f >= firstKey.F && key.EPTypePost == EPType.EP_3))
{
EP = DF / key.FDBSaE;
EP = (EP >= 0 && (int)EP != EP) ? ((int)EP - EP < 0 ? 1 : 0) : EP;
if (f < firstKey.F)
EP = -(EP + 1) * key.VDBSaE;
else
EP = (EP + 1) * key.VDBSaE;
}
else
EP = 0;
int data = 0;
int length = key.Length;
while (length > 0)
if (f <= key.Keys[data + (length >> 1)].F)
length >>= 1;
else
{
int delta = (length >> 1) + 1;
data += delta;
length -= delta;
}
if (data == 0)
return firstKey.V + EP;
else if (data >= key.Length)
return lastKey.V + EP;
KFT3 c = key.Keys[data - 1];
KFT3 n = key.Keys[data];
float result = c.F == n.F ? c.V : n.V;
if (key.Type == Type.Lerp)
{
if (frame < n.F)
{
float t = (frame - c.F) / (n.F - c.F);
result = (1 - t) * c.V + t * n.V;
}
}
else if (key.Type == Type.Hermite)
{
if (frame < n.F)
{
float t = (frame - c.F) / (n.F - c.F);
float t_2 = (1 - t) * (1 - t);
result = t_2 * c.V * (1 + 2 * t) + (t * n.V * (3 - 2 * t) +
(t_2 * c.T2 + t * (t - 1) * n.T1) * (n.F - c.F)) * t;
}
}
else if (key.Type == Type.Hold)
{
if (frame < n.F)
result = c.V;
}
else
return EP;
return result + EP;
}
public void ResetFrameCount() => F = -DeltaFrame;
public override string ToString() => $"Frame: {F}, Value: {Value}";
}
}
@@ -0,0 +1,17 @@
namespace KKdBaseLib.Interpolation
{
public interface IInterpolation : INull
{
float RequestedFramerate { get; set; }
float InterpolationFramerate { get; set; }
float Frame { get; }
float Value { get; }
float SetTime (float time);
float SetFrame(float frame);
float NextFrame(float time);
float NextFrame();
void ResetFrameCount();
}
}
+121
View File
@@ -0,0 +1,121 @@
namespace KKdBaseLib.Interpolation
{
public struct PDI : IInterpolation //Project DIVA Interpolation
{
private KFT2[] Array;
private float F;
private float Last;
private float DeltaFrame;
private float IF;
private float RF;
private float LastTime;
private KFT2 firstKey;
private KFT2 lastKey;
public float InterpolationFramerate
{ get => IF; set { IF = value; DeltaFrame = IF / RF; } }
public float RequestedFramerate
{ get => RF; set { RF = value; DeltaFrame = IF / RF; } }
public float Frame => F;
public float Value => Last;
public bool IsNull => Array == null ? true : Array.Length < 1;
public bool NotNull => Array == null ? false : Array.Length > 0;
public PDI(KFT2[] Array, bool Loop, float InterpolationFramerate = 60, float RequestedFramerate = 60)
{
LastTime = 0;
this.Array = Array; F = -1; DeltaFrame = Last = RF = IF = 0;
IF = InterpolationFramerate;
firstKey = lastKey = default;
this.RequestedFramerate = RequestedFramerate;
F = -DeltaFrame;
ResetFrameCount();
if (Array != null && Array.Length > 0)
{
firstKey = Array[0];
lastKey = Array[Array.Length - 1];
}
}
public float SetTime(float time)
{
if (Array == null || Array.Length < 1) return 0;
LastTime = time;
F = time * IF;
Last = Interpolate(F);
return Last;
}
public float SetFrame(float frame)
{
if (Array == null || Array.Length < 1) return 0;
LastTime = frame / RF;
F = frame * DeltaFrame;
Last = Interpolate(F);
return Last;
}
public float NextFrame(float time)
{
if (Array == null || Array.Length < 1) return 0;
LastTime += time;
F = LastTime * IF;
Last = Interpolate(F);
return Last;
}
public float NextFrame()
{
if (Array == null || Array.Length < 1) return 0;
F += DeltaFrame;
LastTime = F / IF;
Last = Interpolate(F);
return Last;
}
private float Interpolate(float frame)
{
float f = (int)frame;
int data = 0;
int length = Array.Length;
while (length > 0)
if (f <= Array[data + (length >> 1)].F)
length >>= 1;
else
{
int delta = (length >> 1) + 1;
data += delta;
length -= delta;
}
if (data == 0)
return firstKey.V;
else if (data >= Array.Length)
return lastKey.V;
KFT2 c = Array[data - 1];
KFT2 n = Array[data];
float result = c.F == n.F ? c.V : n.V;
if (frame < n.F)
{
float t = (F - c.F) / (n.F - c.F);
float t_1 = t - 1;
result = (t_1 * 2 - 1) * (c.V - n.V) * t * t +
(t_1 * c.T + t * n.T) * t_1 * (F - c.F) + c.V;
}
return result;
}
public void ResetFrameCount() => F = -DeltaFrame;
}
}
+74 -77
View File
@@ -1,134 +1,131 @@
namespace KKdBaseLib
{
public struct KFT0<TKey, TVal> : IKF<TKey, TVal>
public struct KFT0 : IKF
{
public TKey F { get; set; }
public float F;
public KFT0(TKey F = default)
public KFT0(float F = 0)
{ this.F = F; }
public KFT0<TKey, TVal> ToT0() => this;
public KFT1<TKey, TVal> ToT1() => this;
public KFT2<TKey, TVal> ToT2() => this;
public KFT3<TKey, TVal> ToT3() => this;
public KFT0 ToT0() => this;
public KFT1 ToT1() => this;
public KFT2 ToT2() => this;
public KFT3 ToT3() => this;
public IKF<TKey, TVal> Check() => this;
public IKF Check() => this;
public override string ToString() => ToString(true);
public string ToString(bool Brackets = true) =>
Extensions.ToString(F);
public static implicit operator KFT1<TKey, TVal>(KFT0<TKey, TVal> KF) =>
new KFT1<TKey, TVal>(KF.F);
public static implicit operator KFT2<TKey, TVal>(KFT0<TKey, TVal> KF) =>
new KFT2<TKey, TVal>(KF.F);
public static implicit operator KFT3<TKey, TVal>(KFT0<TKey, TVal> KF) =>
new KFT3<TKey, TVal>(KF.F);
public static implicit operator KFT1(KFT0 KF) =>
new KFT1(KF.F);
public static implicit operator KFT2(KFT0 KF) =>
new KFT2(KF.F);
public static implicit operator KFT3(KFT0 KF) =>
new KFT3(KF.F);
}
public struct KFT1<TKey, TVal> : IKF<TKey, TVal>
public struct KFT1 : IKF
{
public TKey F { get; set; }
public TVal V;
public float F;
public float V;
public KFT1(TKey F = default, TVal V = default)
public KFT1(float F = 0, float V = 0)
{ this.F = F; this.V = V; }
public KFT0<TKey, TVal> ToT0() => this;
public KFT1<TKey, TVal> ToT1() => this;
public KFT2<TKey, TVal> ToT2() => this;
public KFT3<TKey, TVal> ToT3() => this;
public KFT0 ToT0() => this;
public KFT1 ToT1() => this;
public KFT2 ToT2() => this;
public KFT3 ToT3() => this;
public IKF<TKey, TVal> Check() =>
V.Equals(default(TVal)) ? (KFT0<TKey, TVal>)this : (IKF<TKey, TVal>)this;
public IKF Check() =>
V == 0 ? (KFT0)this : (IKF)this;
public override string ToString() => ToString(true);
public string ToString(bool Brackets = true) =>
(Brackets ? "(" : "") + Extensions.ToString(F) + "," +
Extensions.ToString(V) + (Brackets ? ")" : "");
public static implicit operator KFT0<TKey, TVal>(KFT1<TKey, TVal> KF) =>
new KFT0<TKey, TVal>(KF.F);
public static implicit operator KFT2<TKey, TVal>(KFT1<TKey, TVal> KF) =>
new KFT2<TKey, TVal>(KF.F, KF.V);
public static implicit operator KFT3<TKey, TVal>(KFT1<TKey, TVal> KF) =>
new KFT3<TKey, TVal>(KF.F, KF.V);
public static implicit operator KFT0(KFT1 KF) =>
new KFT0(KF.F);
public static implicit operator KFT2(KFT1 KF) =>
new KFT2(KF.F, KF.V);
public static implicit operator KFT3(KFT1 KF) =>
new KFT3(KF.F, KF.V);
}
public struct KFT2<TKey, TVal> : IKF<TKey, TVal>
public struct KFT2 : IKF
{
public TKey F { get; set; }
public TVal V;
public TVal T;
public float F;
public float V;
public float T;
public KFT2(TKey F = default, TVal V = default, TVal T = default)
public KFT2(float F = 0, float V = 0, float T = 0)
{ this.F = F; this.V = V; this.T = T; }
public KFT0<TKey, TVal> ToT0() => this;
public KFT1<TKey, TVal> ToT1() => this;
public KFT2<TKey, TVal> ToT2() => this;
public KFT3<TKey, TVal> ToT3() => this;
public KFT0 ToT0() => this;
public KFT1 ToT1() => this;
public KFT2 ToT2() => this;
public KFT3 ToT3() => this;
public KFT3<TKey, TVal> ToT3(IKF<TKey, TVal> Previous) =>
Previous is KFT2<TKey, TVal> PreviousT2 ?
new KFT3<TKey, TVal>(F, V, PreviousT2.T, T) :
new KFT3<TKey, TVal>(F, V, T, T);
public KFT3 ToT3(IKF Previous) =>
Previous is KFT2 PreviousT2 ?
new KFT3(F, V, PreviousT2.T, T) :
new KFT3(F, V, T, T);
public IKF<TKey, TVal> Check() =>
T.Equals(default(TVal)) ? (V.Equals(default(TVal)) ?
(KFT0<TKey, TVal>)this : (IKF<TKey, TVal>)this) : this;
public IKF Check() =>
T == 0 ? (V == 0 ? (IKF)(KFT0)this : (KFT1)this) : this;
public override string ToString() => ToString(true);
public string ToString(bool Brackets) =>
(Brackets ? "(" : "") + Extensions.ToString(F) + "," + Extensions.
ToString(V) + "," + Extensions.ToString(T) + (Brackets ? ")" : "");
public static implicit operator KFT0<TKey, TVal>(KFT2<TKey, TVal> KF) =>
new KFT0<TKey, TVal>(KF.F);
public static implicit operator KFT1<TKey, TVal>(KFT2<TKey, TVal> KF) =>
new KFT1<TKey, TVal>(KF.F, KF.V);
public static implicit operator KFT3<TKey, TVal>(KFT2<TKey, TVal> KF) =>
new KFT3<TKey, TVal>(KF.F, KF.V, KF.T, KF.T);
public static implicit operator KFT0(KFT2 KF) =>
new KFT0(KF.F);
public static implicit operator KFT1(KFT2 KF) =>
new KFT1(KF.F, KF.V);
public static implicit operator KFT3(KFT2 KF) =>
new KFT3(KF.F, KF.V, KF.T, KF.T);
}
public struct KFT3<TKey, TVal> : IKF<TKey, TVal>
public struct KFT3 : IKF
{
public TKey F { get; set; }
public TVal V;
public TVal T1;
public TVal T2;
public float F;
public float V;
public float T1;
public float T2;
public KFT3(TKey F = default, TVal V = default, TVal T1 = default, TVal T2 = default)
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<TKey, TVal> ToT0() => this;
public KFT1<TKey, TVal> ToT1() => this;
public KFT2<TKey, TVal> ToT2() => this;
public KFT3<TKey, TVal> ToT3() => this;
public KFT0 ToT0() => this;
public KFT1 ToT1() => this;
public KFT2 ToT2() => this;
public KFT3 ToT3() => this;
public IKF<TKey, TVal> Check() =>
T1.Equals(default(TVal)) && T2.Equals(default(TVal)) ? (V.Equals(default(TVal)) ?
(IKF<TKey, TVal>)(KFT0<TKey, TVal>)this : (KFT1<TKey, TVal>)this) :
T1.Equals(T2) ? (KFT2<TKey, TVal>)this : (IKF <TKey, TVal>)this;
public IKF Check() =>
T1 == 0 && T2 == 0 ? (V == 0 ? (IKF)(KFT0)this : (KFT1)this) : T1 == T2 ? (KFT2)this : (IKF)this;
public override string ToString() => ToString(true);
public string ToString(bool Brackets) =>
(Brackets ? "(" : "") + Extensions.ToString(F) + "," + Extensions.ToString(V) + "," +
Extensions.ToString(T1) + "," + Extensions.ToString(T2) + (Brackets ? ")" : "");
public static implicit operator KFT0<TKey, TVal>(KFT3<TKey, TVal> KF) =>
new KFT0<TKey, TVal>(KF.F);
public static implicit operator KFT1<TKey, TVal>(KFT3<TKey, TVal> KF) =>
new KFT1<TKey, TVal>(KF.F, KF.V);
public static implicit operator KFT2<TKey, TVal>(KFT3<TKey, TVal> KF) =>
new KFT2<TKey, TVal>(KF.F, KF.V, KF.T1);
public static implicit operator KFT0(KFT3 KF) =>
new KFT0(KF.F);
public static implicit operator KFT1(KFT3 KF) =>
new KFT1(KF.F, KF.V);
public static implicit operator KFT2(KFT3 KF) =>
new KFT2(KF.F, KF.V, KF.T1);
public IKF<TKey, TVal> ToT2(IKF<TKey, TVal> Previous, out IKF<TKey, TVal> Current)
public IKF ToT2(IKF Previous, out IKF Current)
{
Current = Previous is KFT2<TKey, TVal> PreviousT2
? new KFT2<TKey, TVal>(PreviousT2.F, PreviousT2.V, T1)
: new KFT2<TKey, TVal>(F, V, T1);
return new KFT2<TKey, TVal>(F, V, T2);
Current = Previous is KFT2 PreviousT2
? new KFT2(PreviousT2.F, PreviousT2.V, T1)
: new KFT2(F, V, T1);
return new KFT2(F, V, T2);
}
}
}
+10 -4
View File
@@ -22,8 +22,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -35,14 +35,20 @@
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="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" />
+4 -4
View File
@@ -30,12 +30,12 @@ namespace KKdBaseLib
object IEnumerator.Current => Current;
public T this[ int index]
{ get => array != null && index > -1 ? array[index] : default;
set { if (array != null && index > -1) array[index] = value; } }
{ get => array != null && index > -1 && index < array.Length ? array[index] : default;
set { if (array != null && index > -1 && index < array.Length) array[index] = value; } }
public T this[uint index]
{ get => array != null ? array[index] : default;
set { if (array != null) array[index] = value; } }
{ get => array != null && index < array.Length ? array[index] : default;
set { if (array != null && index < array.Length) array[index] = value; } }
public bool MoveNext()
{ if (index == Count - 1) { index = 0; return false; }
+172 -196
View File
@@ -28,7 +28,11 @@ namespace KKdBaseLib
public static MsgPack Null => new MsgPack();
public MsgPack this[int index]
public MsgPack this[ int index]
{ get => Object is MsgPack[] Array ? Array[index] : default;
set { if (Object is MsgPack[] Array) { Array[index] = value; Object = Array; } } }
public MsgPack this[uint index]
{ get => Object is MsgPack[] Array ? Array[index] : default;
set { if (Object is MsgPack[] Array) { Array[index] = value; Object = Array; } } }
@@ -49,10 +53,9 @@ namespace KKdBaseLib
public bool Equals(MsgPack msg) =>
Name == msg.Name && Object == msg.Object;
public override string ToString() => Name ?? "" +
(List. NotNull ? ((Name != null ? " " : "") + "Elements Count: " + List .Count ) :
(Array != null ? ((Name != null ? " " : "") + "Elements Count: " + Array.Length) :
Object.ToString()));
public override string ToString() => Name ?? "" + (Object != null ?
(List. NotNull ? $"{(Name != null ? " " : "")}Elements Count: {List .Count }" :
(Array != null ? $"{(Name != null ? " " : "")}Elements Count: {Array.Length}" : Object)) : "");
public static implicit operator MsgPack(byte[] val) => new MsgPack(null, val);
public static implicit operator MsgPack(string val) => new MsgPack(null, val);
@@ -119,236 +122,209 @@ namespace KKdBaseLib
public MsgPack Add(string Val, float val) => Add(new MsgPack(Val, val));
public MsgPack Add(string Val, double val) => Add(new MsgPack(Val, val));
public bool ReadBoolean(string Name) => ReadNBoolean(Name).GetValueOrDefault();
public sbyte ReadInt8(string Name) => ReadNInt8(Name).GetValueOrDefault();
public byte ReadUInt8(string Name) => ReadNUInt8(Name).GetValueOrDefault();
public short ReadInt16(string Name) => ReadNInt16(Name).GetValueOrDefault();
public ushort ReadUInt16(string Name) => ReadNUInt16(Name).GetValueOrDefault();
public int ReadInt32(string Name) => ReadNInt32(Name).GetValueOrDefault();
public uint ReadUInt32(string Name) => ReadNUInt32(Name).GetValueOrDefault();
public long ReadInt64(string Name) => ReadNInt64(Name).GetValueOrDefault();
public ulong ReadUInt64(string Name) => ReadNUInt64(Name).GetValueOrDefault();
public float ReadSingle(string Name) => ReadNSingle(Name).GetValueOrDefault();
public double ReadDouble(string Name) => ReadNDouble(Name).GetValueOrDefault();
public bool RB (string Name) => RnB (Name) ?? default;
public sbyte RI8 (string Name) => RnI8 (Name) ?? default;
public byte RU8 (string Name) => RnU8 (Name) ?? default;
public short RI16(string Name) => RnI16(Name) ?? default;
public ushort RU16(string Name) => RnU16(Name) ?? default;
public int RI32(string Name) => RnI32(Name) ?? default;
public uint RU32(string Name) => RnU32(Name) ?? default;
public long RI64(string Name) => RnI64(Name) ?? default;
public ulong RU64(string Name) => RnU64(Name) ?? default;
public float RF32(string Name) => RnF32(Name) ?? default;
public double RF64(string Name) => RnF64(Name) ?? default;
public bool? ReadNBoolean(string Name)
public bool? RnB (string Name)
{
MsgPack MsgPack = this[Name];
if (MsgPack.Object is bool Boolean) return Boolean;
return null;
if (MsgPack.Object is bool B ) return B ; return null;
}
public sbyte? ReadNInt8(string Name)
public sbyte? RnI8 (string Name)
{
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return ( sbyte) UInt8 ;
return null;
if (MsgPack.Object is sbyte I8 ) return I8 ;
else if (MsgPack.Object is byte U8 ) return ( sbyte)U8 ; return null;
}
public byte? ReadNUInt8(string Name)
public byte? RnU8 (string Name)
{
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return ( byte) Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
return null;
if (MsgPack.Object is sbyte I8 ) return ( byte)I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ; return null;
}
public short? ReadNInt16(string Name)
public short? RnI16(string Name)
{
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return Int16;
else if (MsgPack.Object is ushort UInt16) return ( short) UInt16;
return null;
if (MsgPack.Object is sbyte I8 ) return I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return I16;
else if (MsgPack.Object is ushort U16) return ( short)U16; return null;
}
public ushort? ReadNUInt16(string Name)
public ushort? RnU16(string Name)
{
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return (ushort) Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return (ushort) Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
return null;
if (MsgPack.Object is sbyte I8 ) return (ushort)I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return (ushort)I16;
else if (MsgPack.Object is ushort U16) return U16; return null;
}
public int? ReadNInt32(string Name)
public int? RnI32(string Name)
{
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return Int32;
else if (MsgPack.Object is uint UInt32) return ( int) UInt32;
return null;
if (MsgPack.Object is sbyte I8 ) return I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return I16;
else if (MsgPack.Object is ushort U16) return U16;
else if (MsgPack.Object is int I32) return I32;
else if (MsgPack.Object is uint U32) return ( int)U32; return null;
}
public uint? ReadNUInt32(string Name)
public uint? RnU32(string Name)
{
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return ( uint) Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return ( uint) Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return ( uint) Int32;
else if (MsgPack.Object is uint UInt32) return UInt32;
return null;
if (MsgPack.Object is sbyte I8 ) return ( uint)I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return ( uint)I16;
else if (MsgPack.Object is ushort U16) return U16;
else if (MsgPack.Object is int I32) return ( uint)I32;
else if (MsgPack.Object is uint U32) return U32; return null;
}
public long? ReadNInt64(string Name)
public long? RnI64(string Name)
{
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return Int32;
else if (MsgPack.Object is uint UInt32) return UInt32;
else if (MsgPack.Object is long Int64) return Int64;
else if (MsgPack.Object is ulong UInt64) return ( long) UInt64;
return null;
if (MsgPack.Object is sbyte I8 ) return I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return I16;
else if (MsgPack.Object is ushort U16) return U16;
else if (MsgPack.Object is int I32) return I32;
else if (MsgPack.Object is uint U32) return U32;
else if (MsgPack.Object is long I64) return I64;
else if (MsgPack.Object is ulong U64) return ( long)U64; return null;
}
public ulong? ReadNUInt64(string Name)
public ulong? RnU64(string Name)
{
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return ( ulong) Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return ( ulong) Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return ( ulong) Int32;
else if (MsgPack.Object is uint UInt32) return UInt32;
else if (MsgPack.Object is long Int64) return ( ulong) Int64;
else if (MsgPack.Object is ulong UInt64) return UInt64;
return null;
if (MsgPack.Object is sbyte I8 ) return ( ulong)I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return ( ulong)I16;
else if (MsgPack.Object is ushort U16) return U16;
else if (MsgPack.Object is int I32) return ( ulong)I32;
else if (MsgPack.Object is uint U32) return U32;
else if (MsgPack.Object is long I64) return ( ulong)I64; return null;
}
public float? ReadNSingle(string Name)
public float? RnF32(string Name)
{
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return Int32;
else if (MsgPack.Object is uint UInt32) return UInt32;
else if (MsgPack.Object is long Int64) return Int64;
else if (MsgPack.Object is float Float32) return Float32;
else if (MsgPack.Object is double Float64) return ( float)Float64;
return null;
if (MsgPack.Object is sbyte I8 ) return I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return I16;
else if (MsgPack.Object is ushort U16) return U16;
else if (MsgPack.Object is int I32) return I32;
else if (MsgPack.Object is uint U32) return U32;
else if (MsgPack.Object is long I64) return I64;
else if (MsgPack.Object is float F32) return F32;
else if (MsgPack.Object is double F64) return ( float)F64; return null;
}
public double? ReadNDouble(string Name)
public double? RnF64(string Name)
{
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return Int32;
else if (MsgPack.Object is uint UInt32) return UInt32;
else if (MsgPack.Object is long Int64) return Int64;
else if (MsgPack.Object is float Float32) return Float32;
else if (MsgPack.Object is double Float64) return Float64;
return null;
if (MsgPack.Object is sbyte I8 ) return I8 ;
else if (MsgPack.Object is byte U8 ) return U8 ;
else if (MsgPack.Object is short I16) return I16;
else if (MsgPack.Object is ushort U16) return U16;
else if (MsgPack.Object is int I32) return I32;
else if (MsgPack.Object is uint U32) return U32;
else if (MsgPack.Object is long I64) return I64;
else if (MsgPack.Object is float F32) return F32;
else if (MsgPack.Object is double F64) return F64; return null;
}
public string ReadString(string Name)
public string RS(string Name)
{
MsgPack MsgPack = this[Name];
if (MsgPack.Object is string String) return String;
return null;
if (MsgPack.Object is string S ) return S ; return null;
}
public bool ReadBoolean() => ReadNBoolean().GetValueOrDefault();
public sbyte ReadInt8() => ReadNInt8().GetValueOrDefault();
public byte ReadUInt8() => ReadNUInt8().GetValueOrDefault();
public short ReadInt16() => ReadNInt16().GetValueOrDefault();
public ushort ReadUInt16() => ReadNUInt16().GetValueOrDefault();
public int ReadInt32() => ReadNInt32().GetValueOrDefault();
public uint ReadUInt32() => ReadNUInt32().GetValueOrDefault();
public long ReadInt64() => ReadNInt64().GetValueOrDefault();
public ulong ReadUInt64() => ReadNUInt64().GetValueOrDefault();
public float ReadSingle() => ReadNSingle().GetValueOrDefault();
public double ReadDouble() => ReadNDouble().GetValueOrDefault();
public bool RB () => RnB () ?? default;
public sbyte RI8 () => RnI8 () ?? default;
public byte RU8 () => RnU8 () ?? default;
public short RI16() => RnI16() ?? default;
public ushort RU16() => RnU16() ?? default;
public int RI32() => RnI32() ?? default;
public uint RU32() => RnU32() ?? default;
public long RI64() => RnI64() ?? default;
public ulong RU64() => RnU64() ?? default;
public float RF32() => RnF32() ?? default;
public double RF64() => RnF64() ?? default;
public bool? ReadNBoolean()
{ if (Object is bool Boolean) return Boolean; return null; }
public sbyte? ReadNInt8()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return ( sbyte) UInt8 ; return null; }
public byte? ReadNUInt8()
{ if (Object is sbyte Int8 ) return ( byte) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ; return null; }
public short? ReadNInt16()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return ( short) UInt16; return null; }
public ushort? ReadNUInt16()
{ if (Object is sbyte Int8 ) return (ushort) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return (ushort) Int16;
else if (Object is ushort UInt16) return UInt16; return null; }
public int? ReadNInt32()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return ( int) UInt32; return null; }
public uint? ReadNUInt32()
{ if (Object is sbyte Int8 ) return ( uint) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return ( uint) Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return ( uint) Int32;
else if (Object is uint UInt32) return UInt32; return null; }
public long? ReadNInt64()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return Int64;
else if (Object is ulong UInt64) return ( long) UInt64; return null; }
public ulong? ReadNUInt64()
{ if (Object is sbyte Int8 ) return ( ulong) Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return ( ulong) Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return ( ulong) Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return ( ulong) Int64;
else if (Object is ulong UInt64) return UInt64; return null; }
public float? ReadNSingle()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return Int64;
else if (Object is float Float32) return Float32;
else if (Object is double Float64) return ( float)Float64; return null; }
public double? ReadNDouble()
{ if (Object is sbyte Int8 ) return Int8 ;
else if (Object is byte UInt8 ) return UInt8 ;
else if (Object is short Int16) return Int16;
else if (Object is ushort UInt16) return UInt16;
else if (Object is int Int32) return Int32;
else if (Object is uint UInt32) return UInt32;
else if (Object is long Int64) return Int64;
else if (Object is float Float32) return Float32;
else if (Object is double Float64) return Float64; return null; }
public string ReadString()
{ if (Object is string String) return String; return null; }
public bool ElementArray1(string Name, out MsgPack MsgPack) =>
Element1(Name, out MsgPack) ? MsgPack.Array != null : false;
public bool Element1(string Name, out MsgPack MsgPack)
{
MsgPack = New;
if (List.IsNull) return false;
for (int i = 0; i < List.Count; i++)
if (List[i].Name == Name) { MsgPack = List[i]; return true; }
return false;
}
public bool? RnB ()
{ if (Object is bool B ) return B ; return null; }
public sbyte? RnI8 ()
{ if (Object is sbyte I8 ) return I8 ;
else if (Object is byte U8 ) return ( sbyte)U8 ; return null; }
public byte? RnU8 ()
{ if (Object is sbyte I8 ) return ( byte)I8 ;
else if (Object is byte U8 ) return U8 ; return null; }
public short? RnI16()
{ if (Object is sbyte I8 ) return I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return I16;
else if (Object is ushort U16) return ( short)U16; return null; }
public ushort? RnU16()
{ if (Object is sbyte I8 ) return (ushort)I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return (ushort)I16;
else if (Object is ushort U16) return U16; return null; }
public int? RnI32()
{ if (Object is sbyte I8 ) return I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return I16;
else if (Object is ushort U16) return U16;
else if (Object is int I32) return I32;
else if (Object is uint U32) return ( int)U32; return null; }
public uint? RnU32()
{ if (Object is sbyte I8 ) return ( uint)I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return ( uint)I16;
else if (Object is ushort U16) return U16;
else if (Object is int I32) return ( uint)I32;
else if (Object is uint U32) return U32; return null; }
public long? RnI64()
{ if (Object is sbyte I8 ) return I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return I16;
else if (Object is ushort U16) return U16;
else if (Object is int I32) return I32;
else if (Object is uint U32) return U32;
else if (Object is long I64) return I64;
else if (Object is ulong U64) return ( long)U64; return null; }
public ulong? RnU64()
{ if (Object is sbyte I8 ) return ( ulong)I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return ( ulong)I16;
else if (Object is ushort U16) return U16;
else if (Object is int I32) return ( ulong)I32;
else if (Object is uint U32) return U32;
else if (Object is long I64) return ( ulong)I64; return null; }
public float? RnF32()
{ if (Object is sbyte I8 ) return I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return I16;
else if (Object is ushort U16) return U16;
else if (Object is int I32) return I32;
else if (Object is uint U32) return U32;
else if (Object is long I64) return I64;
else if (Object is float F32) return F32;
else if (Object is double F64) return ( float)F64; return null; }
public double? RnF64()
{ if (Object is sbyte I8 ) return I8 ;
else if (Object is byte U8 ) return U8 ;
else if (Object is short I16) return I16;
else if (Object is ushort U16) return U16;
else if (Object is int I32) return I32;
else if (Object is uint U32) return U32;
else if (Object is long I64) return I64;
else if (Object is float F32) return F32;
else if (Object is double F64) return F64; return null; }
public string RS ()
{ if (Object is string S ) return S ; return null; }
public MsgPack Element(string Name)
{
+17 -12
View File
@@ -2,25 +2,30 @@
{
public struct Pointer<T>
{
public int Offset;
public T Value;
public int O;
public T V;
public override string ToString() => Extensions.ToString(Value);
public override string ToString() => Extensions.ToString(V);
public Pointer(T value)
{ O = 0; V = value; }
public Pointer(int offset, T value)
{ O = offset; V = value; }
}
public struct CountPointer<T>
{
public int Count { get => Entries != null ? Entries.Length : 0;
set => Entries = value < 0 ? null : new T[value]; }
public int Offset;
public T[] Entries;
public int C { get => E != null ? E.Length : 0;
set => E = value > -1 ? new T [value] : null; }
public int O;
public T[] E;
public T this[int index]
{ get => Count > 0 ? Entries[index] : default;
set { if (Count > 0) Entries[index] = value; } }
{ get => E != null && index > -1 && index < E.LongLength ? E[index] : default;
set { if (E != null && index > -1 && index < E.LongLength) E[index] = value; } }
public override string ToString() => Count < 1 ? "No Entries" :
Count == 1 ? Entries[0].ToString() : "Count: " + Count;
public override string ToString() => C < 1 ? "No Entries" :
C == 1 ? E[0].ToString() : "Count: " + C;
}
}
+2 -2
View File
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("437F63F1-8C23-429E-AB14-38B85C9EDB16")]
[assembly: AssemblyVersion("0.4.7.5")]
[assembly: AssemblyFileVersion("0.4.7.5")]
[assembly: AssemblyVersion("0.4.7.6")]
[assembly: AssemblyFileVersion("0.4.7.6")]
+3 -3
View File
@@ -11,7 +11,7 @@
public bool IsNull => X == null && Y == null;
public bool NotNull => X != null || Y != null;
public override string ToString() => "X: " + X + "; Y: " + Y;
public override string ToString() => $"({X}; {Y})";
}
public struct Vector3<T> : INull
@@ -26,7 +26,7 @@
public bool IsNull => X == null && Y == null && Z == null;
public bool NotNull => X != null || Y != null || Z != null;
public override string ToString() => "X: " + X + "; Y: " + Y + "; Z: " + Z;
public override string ToString() => $"({X}; {Y}; {Z})";
}
public struct Vector4<T> : INull
@@ -42,6 +42,6 @@
public bool IsNull => X == null && Y == null && Z == null && W == null;
public bool NotNull => X != null || Y != null || Z != null || W != null;
public override string ToString() => "X: " + X + "; Y: " + Y + "; Z: " + Z + "; W: " + W;
public override string ToString() => $"({X}; {Y}; {Z}; {W})";
}
}
+11 -11
View File
@@ -2,14 +2,14 @@
{
public struct Vector3
{
public double X;
public double Y;
public double Z;
public float X;
public float Y;
public float Z;
public Vector3(double X, double Y, double Z)
public Vector3(float X, float Y, float Z)
{ this.X = X; this.Y = Y; this.Z = Z; }
public double Length => (X * X + Y * Y + Z * Z).Sqrt();
public float Length => (X * X + Y * Y + Z * Z).Sqrt();
public Vector3 Normalized => this = Length == 0 ? new Vector3() : this / Length;
public static Vector3 operator +(Vector3 left, Vector3 right)
@@ -18,13 +18,13 @@
{ left.X -= right.X; left.Y -= right.Y; left.Z -= right.Z; return left; }
public static Vector3 operator -(Vector3 vec)
{ vec.X = -vec.X; vec.Y = -vec.Y; vec.Z = -vec.Z; return vec; }
public static Vector3 operator *(Vector3 vec, double scale)
public static Vector3 operator *(Vector3 vec, float scale)
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; return vec; }
public static Vector3 operator *( double scale, Vector3 vec)
public static Vector3 operator *( float scale, Vector3 vec)
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; return vec; }
public static Vector3 operator *(Vector3 vec, Vector3 scale)
{ vec.X *= scale.X; vec.Y *= scale.Y; vec.Z *= scale.Z; return vec; }
public static Vector3 operator /(Vector3 vec, double scale)
public static Vector3 operator /(Vector3 vec, float scale)
{ vec.X /= scale ; vec.Y /= scale ; vec.Z /= scale ; return vec; }
public static Vector3 operator /(Vector3 vec, Vector3 scale)
{ vec.X /= scale.X; vec.Y /= scale.Y; vec.Z /= scale.Z; return vec; }
@@ -43,7 +43,7 @@
new Vector3 { X = left.Y * right.Z - left.Z * right.Y,
Y = left.Z * right.X - left.X * right.Z,
Z = left.X * right.Y - left.Y * right.X, };
public static Vector3 Lerp(Vector3 a, Vector3 b, double blend) =>
public static Vector3 Lerp(Vector3 a, Vector3 b, float blend) =>
new Vector3 { X = blend * (b.X - a.X) + a.X,
Y = blend * (b.Y - a.Y) + a.Y,
Z = blend * (b.Z - a.Z) + a.Z };
@@ -71,7 +71,7 @@
public bool Equals(Vector3 other) =>
X == other.X && Y == other.Y && Z == other.Z;
public override string ToString() => $"{X},{Y},{Z}";
public string ToString(int d) => $"{X.Round(d)},{Y.Round(d)},{Z.Round(d)}";
public override string ToString() => $"({X}; {Y}, {Z})";
public string ToString(int d) => $"({X.Round(d)}; {Y.Round(d)}, {Z.Round(d)})";
}
}
+13 -13
View File
@@ -2,15 +2,15 @@
{
public struct Vector4
{
public double X;
public double Y;
public double Z;
public double W;
public float X;
public float Y;
public float Z;
public float W;
public Vector4(double X, double Y, double Z, double W)
public Vector4(float X, float Y, float Z, float W)
{ this.X = X; this.Y = Y; this.Z = Z; this.W = W; }
public double Length => (X * X + Y * Y + Z * Z + W * W).Sqrt();
public float Length => (X * X + Y * Y + Z * Z + W * W).Sqrt();
public Vector4 Normalized => this = Length == 0 ? new Vector4() : this / Length;
public static Vector4 operator +(Vector4 left, Vector4 right)
@@ -19,13 +19,13 @@
{ left.X -= right.X; left.Y -= right.Y; left.Z -= right.Z; left.W -= right.W; return left; }
public static Vector4 operator -(Vector4 vec)
{ vec.X = -vec.X; vec.Y = -vec.Y; vec.Z = -vec.Z; vec.W = -vec.W; return vec; }
public static Vector4 operator *(Vector4 vec, double scale)
public static Vector4 operator *(Vector4 vec, float scale)
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; vec.W *= scale ; return vec; }
public static Vector4 operator *( double scale, Vector4 vec)
public static Vector4 operator *( float scale, Vector4 vec)
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; vec.W *= scale ; return vec; }
public static Vector4 operator *(Vector4 vec, Vector4 scale)
{ vec.X *= scale.X; vec.Y *= scale.Y; vec.Z *= scale.Z; vec.W *= scale.W; return vec; }
public static Vector4 operator /(Vector4 vec, double scale)
public static Vector4 operator /(Vector4 vec, float scale)
{ vec.X /= scale ; vec.Y /= scale ; vec.Z /= scale ; vec.W /= scale ; return vec; }
public static Vector4 operator /(Vector4 vec, Vector4 scale)
{ vec.X /= scale.X; vec.Y /= scale.Y; vec.Z /= scale.Z; vec.W /= scale.W; return vec; }
@@ -40,8 +40,8 @@
(right.Z - left.Z) * (right.Z - left.Z) + (right.W - left.W) * (right.W - left.W);
public static double Dot(Vector4 left, Vector4 right) =>
left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W;
public static Vector4 Lerp(Vector4 a, Vector4 b, double blend) =>
new Vector4 { X = blend * (b.X - a.X) + a.X,
public static Vector4 Lerp(Vector4 a, Vector4 b, float blend) =>
new Vector4 { X = blend * (b.X - a.X) + a.X,
Y = blend * (b.Y - a.Y) + a.Y,
Z = blend * (b.Z - a.Z) + a.Z,
W = blend * (b.W - a.W) + a.W };
@@ -71,7 +71,7 @@
public bool Equals(Vector4 other) =>
X == other.X && Y == other.Y && Z == other.Z && W == other.W;
public override string ToString() => $"{X},{Y},{Z},{W}";
public string ToString(int d) => $"{X.Round(d)},{Y.Round(d)},{Z.Round(d)},{W.Round(d)}";
public override string ToString() => $"({X}; {Y}, {Z}, {W})";
public string ToString(int d) => $"({X.Round(d)}; {Y.Round(d)}, {Z.Round(d)}, {W.Round(d)})";
}
}
+778 -985
View File
File diff suppressed because it is too large Load Diff
+848 -1237
View File
File diff suppressed because it is too large Load Diff
+48 -48
View File
@@ -17,31 +17,31 @@ namespace KKdMainLib.DB
{
IO = File.OpenReader(file + ".bin");
int aetSetsLength = IO.ReadInt32();
int aetSetsOffset = IO.ReadInt32();
int aetsLength = IO.ReadInt32();
int aetsOffset = IO.ReadInt32();
int aetSetsLength = IO.RI32();
int aetSetsOffset = IO.RI32();
int aetsLength = IO.RI32();
int aetsOffset = IO.RI32();
IO.Position = aetSetsOffset;
IO.P = aetSetsOffset;
AetSets = new AetSet[aetSetsLength];
for (i = 0; i < aetSetsLength; i++)
{
AetSets[i].Id = IO.ReadInt32();
AetSets[i].Name = IO.ReadStringAtOffset();
AetSets[i].FileName = IO.ReadStringAtOffset();
IO.ReadInt32();
AetSets[i].SpriteSetId = IO.ReadInt32();
AetSets[i].Id = IO.RI32();
AetSets[i].Name = IO.RSaO();
AetSets[i].FileName = IO.RSaO();
IO.RI32();
AetSets[i].SpriteSetId = IO.RI32();
}
int setIndex;
AET aet = new AET();
int[] AetCount = new int[aetSetsLength];
IO.Position = aetsOffset;
IO.P = aetsOffset;
for (i = 0; i < aetsLength; i++)
{
IO.LongPosition += 10;
setIndex = IO.ReadInt16();
IO.I64P += 10;
setIndex = IO.RI16();
AetCount[setIndex]++;
}
@@ -51,18 +51,18 @@ namespace KKdMainLib.DB
AetCount[i] = 0;
}
IO.Position = aetsOffset;
IO.P = aetsOffset;
for (i = 0; i < aetsLength; i++)
{
aet.Id = IO.ReadInt32();
aet.Name = IO.ReadStringAtOffset();
IO.ReadInt16();
setIndex = IO.ReadInt16();
aet.Id = IO.RI32();
aet.Name = IO.RSaO();
IO.RI16();
setIndex = IO.RI16();
AetSets[setIndex].Aets[AetCount[setIndex]] = aet; AetCount[setIndex]++;
}
IO.Close();
IO.C();
}
@@ -138,54 +138,54 @@ namespace KKdMainLib.DB
i1 = i1.Align(0x20) + 0x20;
IO = File.OpenWriter(file + ".bin", true);
IO.Write(i2);
IO.Write(i1);
IO.Write(i0);
IO.Write(0x20);
IO.Write(0x9066906690669066);
IO.Write(0x9066906690669066);
IO.W(i2);
IO.W(i1);
IO.W(i0);
IO.W(0x20);
IO.W(0x9066906690669066);
IO.W(0x9066906690669066);
IO.Position = (i1 + i2 * 0x14).Align(0x20);
IO.P = (i1 + i2 * 0x14).Align(0x20);
for (i = 0; i < AetSets.Length; i++)
{
if (NotAdd.Contains(i)) continue;
AetSets[i]. NameOffset = IO.Position; IO.Write(AetSets[i]. Name + "\0");
AetSets[i].FileNameOffset = IO.Position; IO.Write(AetSets[i].FileName + "\0");
AetSets[i]. NameOffset = IO.P; IO.W(AetSets[i]. Name + "\0");
AetSets[i].FileNameOffset = IO.P; IO.W(AetSets[i].FileName + "\0");
}
for (i = 0; i < AetSets.Length; i++)
{
if (NotAdd.Contains(i)) continue;
for (i0 = 0; i0 < AetSets[i].Aets.Length; i0++)
{ AetSets[i].Aets[i0].NameOffset = IO.Position; IO.Write(AetSets[i].Aets[i0].Name + "\0"); }
{ AetSets[i].Aets[i0].NameOffset = IO.P; IO.W(AetSets[i].Aets[i0].Name + "\0"); }
}
IO.Align(0x08, true);
IO.A(0x08, true);
IO.Position = 0x20;
IO.P = 0x20;
for (i = 0, i2 = 0; i < AetSets.Length; i++)
{
if (NotAdd.Contains(i)) { i2++; continue; }
for (i0 = 0; i0 < AetSets[i].Aets.Length; i0++)
{
IO.Write(AetSets[i].Aets[i0].Id );
IO.Write(AetSets[i].Aets[i0].NameOffset);
IO.Write((ushort) i0 );
IO.Write((ushort)(i - i2));
IO.W(AetSets[i].Aets[i0].Id );
IO.W(AetSets[i].Aets[i0].NameOffset);
IO.W((ushort) i0 );
IO.W((ushort)(i - i2));
}
}
IO.Align(0x20);
IO.A(0x20);
for (i = 0, i2 = 0; i < AetSets.Length; i++)
{
if (NotAdd.Contains(i)) { i2++; continue; }
IO.Write(AetSets[i].Id );
IO.Write(AetSets[i]. NameOffset);
IO.Write(AetSets[i].FileNameOffset);
IO.Write(i - i2);
IO.Write(AetSets[i].SpriteSetId );
IO.W(AetSets[i].Id );
IO.W(AetSets[i]. NameOffset);
IO.W(AetSets[i].FileNameOffset);
IO.W(i - i2);
IO.W(AetSets[i].SpriteSetId );
}
IO.Close();
IO.C();
}
public void MsgPackReader(string file, bool JSON)
@@ -223,7 +223,7 @@ namespace KKdMainLib.DB
public string Name;
public void ReadMsgPack(MsgPack msg)
{ Id = msg.ReadNUInt16("Id"); Name = msg.ReadString("Name"); }
{ Id = msg.RnU16("Id"); Name = msg.RS("Name"); }
public MsgPack WriteMsgPack() =>
MsgPack.New.Add("Id", Id).Add("Name", Name);
@@ -242,11 +242,11 @@ namespace KKdMainLib.DB
public void ReadMsgPack(MsgPack msg)
{
FileName = msg.ReadString ("FileName" );
Id = msg.ReadNUInt16( "Id");
Name = msg.ReadString ( "Name" );
NewId = msg.ReadBoolean("NewId" );
SpriteSetId = msg.ReadNUInt16("SpriteSetId");
FileName = msg.RS ("FileName" );
Id = msg.RnU16( "Id");
Name = msg.RS ( "Name" );
NewId = msg.RB("NewId" );
SpriteSetId = msg.RnU16("SpriteSetId");
MsgPack Temp;
if ((Temp = msg["Aets", true]).NotNull)
+20 -21
View File
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdMainLib.A3DA;
namespace KKdMainLib.DB
{
@@ -21,13 +20,13 @@ namespace KKdMainLib.DB
IO = File.OpenReader(file + ".bin");
IO.Format = Format.F;
Signature = IO.ReadInt32();
Signature = IO.RI32();
if (Signature != 0x44334123) return;
Signature = IO.ReadInt32();
Signature = IO.RI32();
if (Signature != 0x5F5F5F41) return;
IO.ReadInt64();
IO.RI64();
string[] STRData = IO.ReadString(IO.Length - IO.Position).Replace("\r", "").Split('\n');
string[] STRData = IO.RS(IO.L - IO.P).Replace("\r", "").Split('\n');
for (int i = 0; i < STRData.Length; i++)
{
dataArray = STRData[i].Split('=');
@@ -55,23 +54,23 @@ namespace KKdMainLib.DB
}
}
IO.Close();
IO.C();
}
public void BINWriter(string file)
{
IO = File.OpenWriter(file + ".bin", true);
IO.Write("#A3DA__________\n");
IO.Write("#", DateTime.UtcNow.ToString("ddd MMM dd HH:mm:ss yyyy",
IO.W("#A3DA__________\n");
IO.W("#", DateTime.UtcNow.ToString("ddd MMM dd HH:mm:ss yyyy",
System.Globalization.CultureInfo.InvariantCulture));
if (Category != null)
{
int[] SO = Category.Length.SortWriter();
for (int i = 0; i < Category.Length; i++)
IO.Write("category." + SO[i] + ".value=", Category[SO[i]]);
IO.Write("category.length=", Category.Length);
IO.W("category." + SO[i] + ".value=", Category[SO[i]]);
IO.W("category.length=", Category.Length);
}
if (_UID != null)
@@ -80,16 +79,16 @@ namespace KKdMainLib.DB
for (int i = 0; i < _UID.Length; i++)
{
if (_UID[SO[i]].Category != "")
IO.Write("uid." + SO[i] + ".category=", _UID[SO[i]].Category);
IO.Write("uid." + SO[i] + ".org_uid=" , _UID[SO[i]].OrgUid );
IO.Write("uid." + SO[i] + ".size=" , _UID[SO[i]].Size );
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.Write("uid." + SO[i] + ".value=" , _UID[SO[i]].Value );
IO.W("uid." + SO[i] + ".value=" , _UID[SO[i]].Value );
}
IO.Write("uid.length=", _UID.Length);
IO.W("uid.length=", _UID.Length);
}
IO.Close();
IO.C();
}
public void MsgPackReader(string file, bool JSON)
@@ -104,7 +103,7 @@ namespace KKdMainLib.DB
{
Category = new string[Temp.Array.Length];
for (int i = 0; i < Category.Length; i++)
Category[i] = Temp[i].ReadString();
Category[i] = Temp[i].RS();
}
if ((Temp = MsgPack["UID", true]).NotNull)
@@ -112,10 +111,10 @@ namespace KKdMainLib.DB
_UID = new UID[Temp.Array.Length];
for (int i = 0; i < _UID.Length; i++)
{
_UID[i].Category = Temp[i].ReadString("Category");
_UID[i].OrgUid = Temp[i].ReadNInt32("OrgUid" );
_UID[i].Size = Temp[i].ReadNInt32("Size" );
_UID[i].Value = Temp[i].ReadString("Value" );
_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();
+52 -52
View File
@@ -17,19 +17,19 @@ namespace KKdMainLib.DB
{
IO = File.OpenReader(file + ".bin");
int spriteSetsLength = IO.ReadInt32();
int spriteSetsOffset = IO.ReadInt32();
int spritesLength = IO.ReadInt32();
int spritesOffset = IO.ReadInt32();
int spriteSetsLength = IO.RI32();
int spriteSetsOffset = IO.RI32();
int spritesLength = IO.RI32();
int spritesOffset = IO.RI32();
IO.Position = spriteSetsOffset;
IO.P = spriteSetsOffset;
SpriteSets = new SpriteSet[spriteSetsLength];
for (i = 0; i < spriteSetsLength; i++)
{
SpriteSets[i].Id = IO.ReadInt32();
SpriteSets[i].Name = IO.ReadStringAtOffset();
SpriteSets[i].FileName = IO.ReadStringAtOffset();
IO.ReadInt32();
SpriteSets[i].Id = IO.RI32();
SpriteSets[i].Name = IO.RSaO();
SpriteSets[i].FileName = IO.RSaO();
IO.RI32();
}
int setIndex;
@@ -38,11 +38,11 @@ namespace KKdMainLib.DB
int[] SprCount = new int[spriteSetsLength];
int[] TexCount = new int[spriteSetsLength];
IO.Position = spritesOffset;
IO.P = spritesOffset;
for (i = 0; i < spritesLength; i++)
{
IO.LongPosition += 10;
setIndex = IO.ReadInt16();
IO.I64P += 10;
setIndex = IO.RI16();
IsTexture = (setIndex & 0x1000) == 0x1000;
setIndex &= 0xFFF;
@@ -59,13 +59,13 @@ namespace KKdMainLib.DB
TexCount[i] = 0;
}
IO.Position = spritesOffset;
IO.P = spritesOffset;
for (i = 0; i < spritesLength; i++)
{
st.Id = IO.ReadInt32();
st.Name = IO.ReadStringAtOffset();
IO.ReadInt16();
setIndex = IO.ReadInt16();
st.Id = IO.RI32();
st.Name = IO.RSaO();
IO.RI16();
setIndex = IO.RI16();
IsTexture = (setIndex & 0x1000) == 0x1000;
setIndex &= 0xFFF;
@@ -73,7 +73,7 @@ namespace KKdMainLib.DB
else { SpriteSets[setIndex]. Sprites[SprCount[setIndex]] = st; SprCount[setIndex]++; }
}
IO.Close();
IO.C();
}
public void BINWriter(string file)
@@ -164,67 +164,67 @@ namespace KKdMainLib.DB
i1 = i1.Align(0x20) + 0x20;
IO = File.OpenWriter(file + ".bin", true);
IO.Write(i2);
IO.Write(i1);
IO.Write(i0);
IO.Write(0x20);
IO.Write(0x9066906690669066);
IO.Write(0x9066906690669066);
IO.W(i2);
IO.W(i1);
IO.W(i0);
IO.W(0x20);
IO.W(0x9066906690669066);
IO.W(0x9066906690669066);
IO.Position = (i1 + i2 * 0x10).Align(0x20);
IO.P = (i1 + i2 * 0x10).Align(0x20);
for (i = 0; i < SpriteSets.Length; i++)
{
if (NotAdd.Contains(i)) continue;
for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++)
{ SpriteSets[i].Textures[i0].NameOffset = IO.Position;
IO.Write(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.Position;
IO.Write(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.Position; IO.Write(SpriteSets[i]. Name + "\0");
SpriteSets[i].FileNameOffset = IO.Position; IO.Write(SpriteSets[i].FileName + "\0");
SpriteSets[i]. NameOffset = IO.P; IO.W(SpriteSets[i]. Name + "\0");
SpriteSets[i].FileNameOffset = IO.P; IO.W(SpriteSets[i].FileName + "\0");
}
IO.Align(0x08, true);
IO.Position = 0x20;
IO.A(0x08, true);
IO.P = 0x20;
for (i = 0, i2 = 0; i < SpriteSets.Length; i++)
{
if (NotAdd.Contains(i)) { i2++; continue; }
for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++)
{
IO.Write(SpriteSets[i].Textures[i0].Id );
IO.Write(SpriteSets[i].Textures[i0].NameOffset);
IO.Write((ushort) i0 );
IO.Write((ushort)(0x1000 | (i - i2)));
IO.W(SpriteSets[i].Textures[i0].Id );
IO.W(SpriteSets[i].Textures[i0].NameOffset);
IO.W((ushort) i0 );
IO.W((ushort)(0x1000 | (i - i2)));
}
for (i0 = 0; i0 < SpriteSets[i]. Sprites.Length; i0++)
{
IO.Write(SpriteSets[i]. Sprites[i0].Id );
IO.Write(SpriteSets[i]. Sprites[i0].NameOffset);
IO.Write((ushort) i0 );
IO.Write((ushort)(i - i2));
IO.W(SpriteSets[i]. Sprites[i0].Id );
IO.W(SpriteSets[i]. Sprites[i0].NameOffset);
IO.W((ushort) i0 );
IO.W((ushort)(i - i2));
}
}
IO.Align(0x20);
IO.A(0x20);
for (i = 0, i2 = 0; i < SpriteSets.Length; i++)
{
if (NotAdd.Contains(i)) { i2++; continue; }
IO.Write(SpriteSets[i].Id );
IO.Write(SpriteSets[i]. NameOffset);
IO.Write(SpriteSets[i].FileNameOffset);
IO.Write(i - i2);
IO.W(SpriteSets[i].Id );
IO.W(SpriteSets[i]. NameOffset);
IO.W(SpriteSets[i].FileNameOffset);
IO.W(i - i2);
}
IO.Close();
IO.C();
}
public void MsgPackReader(string file, bool JSON = false)
@@ -260,7 +260,7 @@ namespace KKdMainLib.DB
public string Name;
public void ReadMsgPack(MsgPack msg)
{ Id = msg.ReadNInt32("Id"); Name = msg.ReadString("Name"); }
{ Id = msg.RnI32("Id"); Name = msg.RS("Name"); }
public MsgPack WriteMsgPack() =>
MsgPack.New.Add("Id", Id).Add("Name", Name);
@@ -279,10 +279,10 @@ namespace KKdMainLib.DB
public void ReadMsgPack(MsgPack msg)
{
FileName = msg.ReadString ("FileName");
Id = msg.ReadNInt32 ( "Id" );
Name = msg.ReadString ("Name" );
NewId = msg.ReadBoolean("NewId" );
FileName = msg.RS ("FileName");
Id = msg.RnI32( "Id" );
Name = msg.RS ("Name" );
NewId = msg.RB ("NewId" );
MsgPack Temp;
if ((Temp = msg["Sprites", true]).NotNull)
+73 -73
View File
@@ -22,69 +22,69 @@ namespace KKdMainLib
IO = File.OpenReader(filepath + ext);
Header.Format = Format.F;
Header.SectionSignature = IO.ReadInt32();
Header.SectionSignature = IO.RI32();
if (Header.SectionSignature == 0x43505845)
Header = IO.ReadHeader(true, true);
if (Header.SectionSignature != 0x64) return 0;
IO.Offset = IO.Position - 0x4;
Dex = new EXP[IO.ReadInt32()];
int DEXOffset = IO.ReadInt32();
int DEXNameOffset = IO.ReadInt32();
if (DEXNameOffset == 0x00) { Header.Format = Format.X; DEXNameOffset = (int)IO.ReadInt64(); }
IO.O = IO.P - 0x4;
Dex = new EXP[IO.RI32()];
int DEXOffset = IO.RI32();
int DEXNameOffset = IO.RI32();
if (DEXNameOffset == 0x00) { Header.Format = Format.X; DEXNameOffset = (int)IO.RI64(); }
IO.Seek(DEXOffset, 0);
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[i0].MainOffset = IO.ReadInt32();
if (Header.IsX) IO.ReadInt32();
Dex[i0].EyesOffset = IO.ReadInt32();
if (Header.IsX) IO.ReadInt32();
Dex[i0].MainOffset = IO.RI32();
if (Header.IsX) IO.RI32();
Dex[i0].EyesOffset = IO.RI32();
if (Header.IsX) IO.RI32();
}
IO.Seek(DEXNameOffset, 0);
IO.S(DEXNameOffset, 0);
for (int i0 = 0; i0 < Dex.Length; i0++)
{
Dex[i0].NameOffset = IO.ReadInt32();
if (Header.IsX) IO.ReadInt32();
Dex[i0].NameOffset = IO.RI32();
if (Header.IsX) IO.RI32();
}
for (int i0 = 0; i0 < Dex.Length; i0++)
{
EXPElement element = new EXPElement();
IO.Seek(Dex[i0].MainOffset + Offset, 0);
IO.S(Dex[i0].MainOffset + Offset, 0);
while (true)
{
element.Frame = IO.ReadSingle();
element.Both = IO.ReadUInt16();
element.ID = IO.ReadUInt16();
element.Value = IO.ReadSingle();
element.Trans = IO.ReadSingle();
element.Frame = IO.RF32();
element.Both = IO.RU16();
element.ID = IO.RU16();
element.Value = IO.RF32();
element.Trans = IO.RF32();
Dex[i0].Main.Add(element);
if (element.Frame == 999999 || element.Both == 0xFFFF)
break;
}
IO.Seek(Dex[i0].EyesOffset, 0);
IO.S(Dex[i0].EyesOffset, 0);
while(true)
{
element.Frame = IO.ReadSingle();
element.Both = IO.ReadUInt16();
element.ID = IO.ReadUInt16();
element.Value = IO.ReadSingle();
element.Trans = IO.ReadSingle();
element.Frame = IO.RF32();
element.Both = IO.RU16();
element.ID = IO.RU16();
element.Value = IO.RF32();
element.Trans = IO.RF32();
Dex[i0].Eyes.Add(element);
if (element.Frame == 999999 || element.Both == 0xFFFF) break;
}
Dex[i0].Name = IO.ReadStringAtOffset(Dex[i0].NameOffset);
Dex[i0].Name = IO.RSaO(Dex[i0].NameOffset);
}
IO.Close();
IO.C();
return 1;
}
@@ -94,78 +94,78 @@ namespace KKdMainLib
IO = File.OpenWriter(filepath + (Format > Format.F ? ".dex" : ".bin"), true);
Header.Format = IO.Format = Format;
IO.Offset = Format > Format.F ? 0x20 : 0;
IO.Write(0x64);
IO.Write(Dex.Length);
IO.O = Format > Format.F ? 0x20 : 0;
IO.W(0x64);
IO.W(Dex.Length);
IO.WriteX(Header.IsX ? 0x28 : 0x20);
IO.WriteX(0x00);
IO.WX(Header.IsX ? 0x28 : 0x20);
IO.WX(0x00);
int Position0 = IO.Position;
IO.Write(0x00L);
IO.Write(0x00L);
int Position0 = IO.P;
IO.W(0x00L);
IO.W(0x00L);
for (int i = 0; i < Dex.Length * 3; i++) IO.WriteX(0x00);
for (int i = 0; i < Dex.Length * 3; i++) IO.WX(0x00);
IO.Align(0x20, true);
IO.A(0x20, true);
for (int i0 = 0; i0 < Dex.Length; i0++)
{
Dex[i0].MainOffset = IO.Position;
Dex[i0].MainOffset = IO.P;
for (int i1 = 0; i1 < Dex[i0].Main.Count; i1++)
{
IO.Write(Dex[i0].Main[i1].Frame);
IO.Write(Dex[i0].Main[i1].Both );
IO.Write(Dex[i0].Main[i1].ID );
IO.Write(Dex[i0].Main[i1].Value);
IO.Write(Dex[i0].Main[i1].Trans);
IO.W(Dex[i0].Main[i1].Frame);
IO.W(Dex[i0].Main[i1].Both );
IO.W(Dex[i0].Main[i1].ID );
IO.W(Dex[i0].Main[i1].Value);
IO.W(Dex[i0].Main[i1].Trans);
}
IO.Align(0x20, true);
IO.A(0x20, true);
Dex[i0].EyesOffset = IO.Position;
Dex[i0].EyesOffset = IO.P;
for (int i1 = 0; i1 < Dex[i0].Eyes.Count; i1++)
{
IO.Write(Dex[i0].Eyes[i1].Frame);
IO.Write(Dex[i0].Eyes[i1].Both );
IO.Write(Dex[i0].Eyes[i1].ID );
IO.Write(Dex[i0].Eyes[i1].Value);
IO.Write(Dex[i0].Eyes[i1].Trans);
IO.W(Dex[i0].Eyes[i1].Frame);
IO.W(Dex[i0].Eyes[i1].Both );
IO.W(Dex[i0].Eyes[i1].ID );
IO.W(Dex[i0].Eyes[i1].Value);
IO.W(Dex[i0].Eyes[i1].Trans);
}
IO.Align(0x20, true);
IO.A(0x20, true);
}
for (int i0 = 0; i0 < Dex.Length; i0++)
{
Dex[i0].NameOffset = IO.Position;
IO.Write(Dex[i0].Name + "\0");
Dex[i0].NameOffset = IO.P;
IO.W(Dex[i0].Name + "\0");
}
IO.Align(0x10, true);
IO.A(0x10, true);
IO.Position = Header.IsX ? 0x28 : 0x20;
IO.P = Header.IsX ? 0x28 : 0x20;
for (int i0 = 0; i0 < Dex.Length; i0++)
{
IO.WriteX(Dex[i0].MainOffset);
IO.WriteX(Dex[i0].EyesOffset);
IO.WX(Dex[i0].MainOffset);
IO.WX(Dex[i0].EyesOffset);
}
int Position1 = IO.Position;
int Position1 = IO.P;
for (int i0 = 0; i0 < Dex.Length; i0++)
IO.WriteX(Dex[i0].NameOffset);
IO.WX(Dex[i0].NameOffset);
IO.Position = Position0 - (Header.IsX ? 8 : 4);
IO.Write(Position1);
IO.P = Position0 - (Header.IsX ? 8 : 4);
IO.W(Position1);
if (Format > Format.F)
{
Offset = IO.Length;
IO.Offset = 0;
IO.Position = IO.Length;
IO.WriteEOFC(0);
IO.Position = 0;
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.Write(Header, true);
IO.W(Header, true);
}
IO.Close();
IO.C();
}
public int MsgPackReader(string file, bool JSON)
@@ -182,7 +182,7 @@ namespace KKdMainLib
this.Dex = new EXP[Dex.Array.Length];
for (i0 = 0; i0 < this.Dex.Length; i0++)
{
this.Dex[i0] = new EXP { Name = Dex[i0].ReadString("Name") };
this.Dex[i0] = new EXP { Name = Dex[i0].RS("Name") };
MsgPack Temp;
if ((Temp = MsgPack["Main", true]).NotNull)
@@ -249,9 +249,9 @@ namespace KKdMainLib
public float Trans;
public static EXPElement Read(MsgPack msg) =>
new EXPElement() { Frame = msg.ReadSingle("F"), Both = msg.ReadUInt16("B"),
ID = msg.ReadUInt16("I"), Value = msg.ReadSingle("V"),
Trans = msg.ReadSingle("T"), };
new EXPElement() { Frame = msg.RF32("F"), Both = msg.RU16("B"),
ID = msg.RU16("I"), Value = msg.RF32("V"),
Trans = msg.RF32("T"), };
public MsgPack Write() =>
MsgPack.New.Add("F", Frame).Add("B", Both )
+33 -27
View File
@@ -14,35 +14,39 @@ namespace KKdMainLib
public static void Decrypt(this string file)
{
Stream IO = File.OpenReader(file);
if (IO.ReadInt64() != 0x454C494641564944)
{ IO.Close(); return; }
int StreamLength = IO.ReadInt32();
int FileLength = IO.ReadInt32();
byte[] encrypted = IO.ReadBytes(StreamLength);
byte[] decrypted = new byte[StreamLength];
IO.Close();
int StreamLength, FileLength;
byte[] encrypted, decrypted;
using (Stream IO = File.OpenReader(file))
{
if (IO.RI64() != 0x454C494641564944) return;
StreamLength = IO.RI32();
FileLength = IO.RI32();
encrypted = IO.RBy(StreamLength);
decrypted = new byte[StreamLength];
}
using (AesManaged crypto = new AesManaged())
{
crypto.Key = Key; crypto.IV = new byte[16];
crypto.Mode = CipherMode.ECB; crypto.Padding = PaddingMode.Zeros;
using (CryptoStream cryptoData = new CryptoStream(new MSIO.MemoryStream(encrypted),
crypto.CreateDecryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read))
cryptoData.Read(decrypted, 0, StreamLength);
using CryptoStream cryptoData = new CryptoStream(new MSIO.MemoryStream(encrypted),
crypto.CreateDecryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read);
cryptoData.Read(decrypted, 0, StreamLength);
}
IO = File.OpenWriter(file, FileLength);
IO.Write(decrypted, FileLength < StreamLength ? FileLength : StreamLength);
IO.Close();
using (Stream IO = File.OpenWriter(file, FileLength))
IO.W(decrypted, FileLength < StreamLength ? FileLength : StreamLength);
}
public static void Encrypt(this string file)
{
Stream IO = File.OpenReader(file);
int FileLengthOrigin = IO.Length;
byte[] In;
using (Stream IO = File.OpenReader(file))
In = IO.ToArray();
int FileLengthOrigin = In.Length;
int FileLength = FileLengthOrigin.Align(16);
byte[] In = IO.ToArray();
IO.Close();
byte[] Inalign = new byte[FileLength];
for (int i = 0; i < In.Length; i++) Inalign[i] = In[i];
In = null;
@@ -51,16 +55,18 @@ namespace KKdMainLib
{
crypto.Key = Key; crypto.IV = new byte[16];
crypto.Mode = CipherMode.ECB; crypto.Padding = PaddingMode.Zeros;
using (CryptoStream cryptoData = new CryptoStream(new MSIO.MemoryStream(Inalign),
crypto.CreateEncryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read))
cryptoData.Read(encrypted, 0, FileLength);
using CryptoStream cryptoData = new CryptoStream(new MSIO.MemoryStream(Inalign),
crypto.CreateEncryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read);
cryptoData.Read(encrypted, 0, FileLength);
}
using (Stream IO = File.OpenWriter(file, Inalign.Length))
{
IO.W(0x454C494641564944);
IO.W(FileLength);
IO.W(FileLengthOrigin);
IO.W(encrypted);
}
IO = File.OpenWriter(file, Inalign.Length);
IO.Write(0x454C494641564944);
IO.Write(FileLength);
IO.Write(FileLengthOrigin);
IO.Write(encrypted);
IO.Close();
}
}
}
+24 -24
View File
@@ -53,15 +53,15 @@ namespace KKdMainLib
{
if (psrDat != null && psrDat.Length > 0)
for (i = 0; i < psrDat.Length; i++)
IO.Write(psrDat[i].ToString() + c);
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.Write(UrlEncode(pvList[i].ToString() +
IO.W(UrlEncode(pvList[i].ToString() +
(i < pvList.Length ? c : "")));
else IO.Write("%2A%2A%2A");
else IO.W("%2A%2A%2A");
}
byte[] data = IO.ToArray(true);
@@ -73,7 +73,7 @@ namespace KKdMainLib
{
Success = false;
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
bool compact = MsgPack.ReadBoolean("Compact");
bool compact = MsgPack.RB("Compact");
if (file.Contains("psrData"))
{
@@ -155,9 +155,9 @@ namespace KKdMainLib
public void SetValue(MsgPack msg)
{
int? ID = msg.ReadNInt32("PV_ID");
int? ID = msg.RnI32("PV_ID");
if (ID != null) PV_ID = (int)ID;
else { ID = msg.ReadNInt32("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);
@@ -207,15 +207,15 @@ namespace KKdMainLib
public void SetValue(MsgPack msg)
{
Diff = (Difficulty)msg.ReadInt32("Diff");
Score0 = msg.ReadInt32 ("Score");
Name0 = msg.ReadString( "Name");
Diff = (Difficulty)msg.RI32("Diff");
Score0 = msg.RI32 ("Score");
Name0 = msg.RS( "Name");
if (Name0 == null)
{
Score0 = msg.ReadInt32 ("Score0");
Score1 = msg.ReadInt32 ("Score1");
Name0 = msg.ReadString( "Name0");
Name1 = msg.ReadString( "Name1");
Score0 = msg.RI32("Score0");
Score1 = msg.RI32("Score1");
Name0 = msg.RS ( "Name0");
Name1 = msg.RS ( "Name1");
}
else Name1 = null;
}
@@ -258,19 +258,19 @@ namespace KKdMainLib
this.Enable = true;
this.Extra = false;
int? ID = msg.ReadNInt32("PV_ID");
int? ID = msg.RnI32("PV_ID");
if (ID != null) PV_ID = (int)ID;
else { ID = msg.ReadNInt32("ID"); if (ID != null) PV_ID = (int)ID; }
bool? Enable = msg.ReadNBoolean("Enable");
bool? Extra = msg.ReadNBoolean("Extra");
else { ID = msg.RnI32("ID"); if (ID != null) PV_ID = (int)ID; }
bool? Enable = msg.RnB("Enable");
bool? Extra = msg.RnB("Extra");
if (Enable != null) this.Enable = (bool)Enable;
if (Extra != null) this.Extra = (bool)Extra ;
if (Compact)
{
AdvDemoStart.SetValue(msg.ReadNInt32("AdvDemoStart"), true);
AdvDemoEnd .SetValue(msg.ReadNInt32("AdvDemoEnd" ), false);
StartShow .SetValue(msg.ReadNInt32("StartShow" ), false);
EndShow .SetValue(msg.ReadNInt32( "EndShow" ), true);
AdvDemoStart.SetValue(msg.RnI32("AdvDemoStart"), true);
AdvDemoEnd .SetValue(msg.RnI32("AdvDemoEnd" ), false);
StartShow .SetValue(msg.RnI32("StartShow" ), false);
EndShow .SetValue(msg.RnI32( "EndShow" ), true);
return;
}
MsgPack Temp;
@@ -356,9 +356,9 @@ namespace KKdMainLib
{
if (!SetDefaultUpper) SetDefaultLower();
else this.SetDefaultUpper();
int? Year = msg.ReadNInt32( "Year");
int? Month = msg.ReadNInt32("Month");
int? Day = msg.ReadNInt32( "Day");
int? Year = msg.RnI32( "Year");
int? Month = msg.RnI32("Month");
int? Day = msg.RnI32( "Day");
if ( Year != null) year = Year.Value;
if (Month != null) month = Month.Value;
if ( Day != null) day = Day.Value;
+62 -75
View File
@@ -9,108 +9,108 @@ namespace KKdMainLib
public static Header ReadHeader(this Stream stream, bool Seek, bool ReadSectionSignature = true)
{
if (Seek)
if (stream.LongPosition > 4) stream.LongPosition -= 4;
else stream.LongPosition = 0;
if (stream.I64P > 4) stream.I64P -= 4;
else stream.I64P = 0;
return stream.ReadHeader(ReadSectionSignature);
}
public static Header ReadHeader(this Stream stream, bool ReadSectionSignature = true)
{
Header Header = new Header { Format = Format.F2LE, Signature = stream.ReadInt32(),
DataSize = stream.ReadInt32(), Length = stream.ReadInt32(), Flags = stream.ReadInt32(),
Depth = stream.ReadInt32(), SectionSize = stream.ReadInt32(),
Mode = stream.ReadInt32() };
stream.ReadInt32();
Header Header = new Header { Format = Format.F2LE, Signature = stream.RI32(),
DataSize = stream.RI32(), Length = stream.RI32(), Flags = stream.RI32(),
Depth = stream.RI32(), SectionSize = stream.RI32(),
Mode = stream.RI32() };
stream.RI32();
if ((Header.Flags & 0x08000000) == 0x08000000) Header.Format = Format.F2BE;
Header.NotUseDataSizeAsSectionSize = (Header.Flags & 0x10000000) != 0x10000000;
if (Header.Length == 0x40)
{
stream.ReadInt64();
stream.ReadInt64();
Header.InnerSignature = stream.ReadInt32();
stream.ReadInt32();
stream.ReadInt64();
stream.RI64();
stream.RI64();
Header.InnerSignature = stream.RI32();
stream.RI32();
stream.RI64();
}
stream.Format = Header.Format;
if (ReadSectionSignature) Header.SectionSignature = stream.ReadInt32Endian();
if (ReadSectionSignature) Header.SectionSignature = stream.RI32E();
return Header;
}
public static void Write(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);
stream.Write(Header.Signature);
stream.Write(Header.DataSize);
stream.Write(Header.Length);
stream.Write(Header.Flags);
stream.Write(Header.Depth);
stream.Write(Header.SectionSize);
stream.Write(Header.Mode);
stream.Write(0x00);
stream.W(Header.Signature);
stream.W(Header.DataSize);
stream.W(Header.Length);
stream.W(Header.Flags);
stream.W(Header.Depth);
stream.W(Header.SectionSize);
stream.W(Header.Mode);
stream.W(0x00);
if (Header.Length == 0x40)
{
stream.Write(Header.Format < Format.MGF ? (int)((Header.SectionSignature ^
stream.W(Header.Format < Format.MGF ? (int)((Header.SectionSignature ^
(Header.DataSize * (long)Header.Signature)) - Header.Depth + Header.SectionSize) : 0);
stream.Write(0x00);
stream.Write(0x00L);
stream.Write(Header.InnerSignature);
stream.Write(0x00);
stream.Write(0x00L);
stream.W(0x00);
stream.W(0x00L);
stream.W(Header.InnerSignature);
stream.W(0x00);
stream.W(0x00L);
}
}
public static void WriteEOFC(this Stream stream, int ID = 0) =>
stream.Write(new Header { Depth = ID, 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 Write(this Stream stream, POF POF, bool ShiftX = false)
public static void W(this Stream stream, POF POF, bool ShiftX = false)
{
byte[] data = POF.Write(POF, ShiftX);
Header Header = new Header { Depth = POF.Depth, Format = Format.F2LE,
Length = 0x20, Signature = ShiftX ? 0x31464F50 : 0x30464F50 };
Header.DataSize = Header.SectionSize = data.Length;
stream.Write(Header);
stream.Write(data);
stream.W(Header);
stream.W(data);
}
}
public static class ENRSExtensions
{
public static void Write(this Stream stream, ENRSList ENRS)
public static void W(this Stream stream, ENRSList ENRS)
{
byte[] data = ENRSList.Write(ENRS);
Header Header = new Header { Depth = ENRS.Depth,
Format = Format.F2LE, Length = 0x20, Signature = 0x53524E45 };
Header.DataSize = Header.SectionSize = data.Length;
stream.Write(Header);
stream.Write(data);
stream.W(Header);
stream.W(data);
}
}
public static class StructExtensions
{
public static Struct ReadStruct(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.ReadStruct(stream.ReadHeader(false));
Struct = stream.RSt(stream.ReadHeader(false));
return Struct;
}
public static Struct ReadStruct(this Stream stream, Header Header)
public static Struct RSt(this Stream stream, Header Header)
{
Struct Struct = new Struct { Header = Header, DataOffset =
stream.Position, Data = stream.ReadBytes(Header.SectionSize) };
stream.P, Data = stream.RBy(Header.SectionSize) };
int Depth = Header.Depth;
int LastSig = 0, Sig;
long Length = stream.Length - stream.Position;
long Length = stream.L - stream.P;
long Position = 0;
KKdList<Struct> SubStructs = KKdList<Struct>.New;
while (Length > Position)
@@ -122,12 +122,12 @@ namespace KKdMainLib
else if (Header.Depth == 0 && (Sig == 0x53524E45 ||
(Sig & 0xF0FFFFFF) == 0x30464F50 || Sig == 0x43505854))
{
byte[] Data = stream.ReadBytes(Header.SectionSize);
byte[] Data = stream.RBy(Header.SectionSize);
if (Sig == 0x53524E45) Struct.ENRS = ENRSList.Read(Data, Header.Depth);
else Struct.POF = POF .Read(Data, Sig == 0x31464F50, Header.Depth);
}
else if (Header.Depth <= Depth) { stream.LongPosition -= Header.Length; break; }
else SubStructs.Add(stream.ReadStruct(Header));
else if (Header.Depth <= Depth) { stream.I64P -= Header.Length; break; }
else SubStructs.Add(stream.RSt(Header));
LastSig = Sig;
}
@@ -135,25 +135,25 @@ namespace KKdMainLib
return Struct;
}
public static byte[] Write(this Struct Struct, bool ShiftX = false)
public static byte[] W(this Struct Struct, bool ShiftX = false)
{
byte[] Data;
using (Stream stream = File.OpenWriter()) { Struct.Update(ShiftX);
stream.Write(Struct, ShiftX); stream.WriteEOFC(); Data = stream.ToArray(); }
stream.W(Struct, ShiftX); stream.WEOFC(); Data = stream.ToArray(); }
return Data;
}
public static void Write(this Stream stream, Struct Struct, bool ShiftX = false)
public static void W(this Stream stream, Struct Struct, bool ShiftX = false)
{
stream.Write(Struct.Header);
stream.Write(Struct.Data );
if (Struct.HasPOF ) stream.Write(Struct.POF , ShiftX);
if (Struct.HasENRS) stream.Write(Struct.ENRS);
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.Write(Struct.SubStructs[i], ShiftX);
stream.WriteEOFC(Struct.Depth + 1);
stream.W(Struct.SubStructs[i], ShiftX);
stream.WEOFC(Struct.Depth + 1);
}
}
}
@@ -190,7 +190,7 @@ namespace KKdMainLib
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.Write(mp, "\n", " ");
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;
}
@@ -202,7 +202,7 @@ namespace KKdMainLib
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.Write(mp, true); data = IO.ToArray(); }
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;
@@ -217,27 +217,14 @@ namespace KKdMainLib
public static class IKFExt
{
public static IKF<float, float> Round(this IKF<float, float> KF, int d)
public static IKF Round(this IKF KF, int d)
{
if (KF is KFT0<float, float> KFT0) { KFT0.F = KFT0.F.Round(d); return KFT0; }
else if (KF is KFT1<float, float> KFT1) { KFT1.F = KFT1.F.Round(d);
KFT1.V = KFT1.V.Round(d); return KFT1; }
else if (KF is KFT2<float, float> 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<float, float> KFT3) { KFT3.F = KFT3.F.Round(d);
KFT3.V = KFT3.V.Round(d); KFT3.T1 = KFT3.T1.Round(d); KFT3.T2 = KFT3.T2.Round(d); return KFT3; }
return KF;
}
public static IKF<double, double> Round(this IKF<double, double> KF, int d)
{
if (KF is KFT0<double, double> KFT0) { KFT0.F = KFT0.F.Round(d); return KFT0; }
else if (KF is KFT1<double, double> KFT1) { KFT1.F = KFT1.F.Round(d);
KFT1.V = KFT1.V.Round(d); return KFT1; }
else if (KF is KFT2<double, double> 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<double, double> 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; }
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;
}
}
+20 -20
View File
@@ -17,12 +17,12 @@ namespace KKdMainLib.F2
IO = File.OpenReader(file + ".blt", true);
Header = IO.ReadHeader();
if (Header.Signature != 0x544D4C42 || Header.InnerSignature != 0x3) return;
IO.Position -= 0x4;
IO.P -= 0x4;
BLTs = IO.ReadCountPointerEndian<BLT>();
if (BLTs.Count < 1) { IO.Close(); BLTs.Count = -1; return; }
BLTs = IO.RCPE<BLT>();
if (BLTs.C < 1) { IO.C(); BLTs.C = -1; return; }
if (BLTs.Count > 0 && BLTs.Offset == 0) { IO.Close(); BLTs.Count = -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;
@@ -30,30 +30,30 @@ namespace KKdMainLib.F2
BLTs = IO.ReadCountPointerX<BLT>();
}*/
IO.Position = BLTs.Offset;
for (i = 0; i < BLTs.Count; i++)
IO.P = BLTs.O;
for (i = 0; i < BLTs.C; i++)
{
ref BLT BLT = ref BLTs.Entries[i];
IO.ReadInt32Endian();
BLT.Color .X = IO.ReadSingleEndian();
BLT.Color .Y = IO.ReadSingleEndian();
BLT.Color .Z = IO.ReadSingleEndian();
BLT.Brightpass.X = IO.ReadSingleEndian();
BLT.Brightpass.Y = IO.ReadSingleEndian();
BLT.Brightpass.Z = IO.ReadSingleEndian();
BLT.Range = IO.ReadSingleEndian();
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.Close();
IO.C();
}
public void TXTWriter(string file)
{
if (BLTs.Count < 1) return;
if (BLTs.C < 1) return;
IO = File.OpenWriter();
IO.WriteShiftJIS("ID,ColorR,ColorG,ColorB,BrightpassR,BrightpassG,BrightpassB,Range\n");
for (i = 0; i < BLTs.Count; i++)
IO.Write(i + "," + BLTs[i] + "\n");
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));
}
+21 -21
View File
@@ -17,12 +17,12 @@ namespace KKdMainLib.F2
IO = File.OpenReader(file + ".cct", true);
Header = IO.ReadHeader();
if (Header.Signature != 0x54524343 || Header.InnerSignature != 0x3) return;
IO.Position -= 0x4;
IO.P -= 0x4;
CCTs = IO.ReadCountPointerEndian<CCT>();
if (CCTs.Count < 1) { IO.Close(); CCTs.Count = -1; return; }
CCTs = IO.RCPE<CCT>();
if (CCTs.C < 1) { IO.C(); CCTs.C = -1; return; }
if (CCTs.Count > 0 && CCTs.Offset == 0) { IO.Close(); CCTs.Count = -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;
@@ -30,32 +30,32 @@ namespace KKdMainLib.F2
CCTs = IO.ReadCountPointerX<CCT>();
}*/
IO.Position = CCTs.Offset;
for (i = 0; i < CCTs.Count; i++)
IO.P = CCTs.O;
for (i = 0; i < CCTs.C; i++)
{
ref CCT CCT = ref CCTs.Entries[i];
IO.ReadInt32Endian();
CCT.Hue = IO.ReadSingleEndian();
CCT.Saturation = IO.ReadSingleEndian();
CCT.Lightness = IO.ReadSingleEndian();
CCT.Exposure = IO.ReadSingleEndian();
CCT.Gamma.X = IO.ReadSingleEndian();
CCT.Gamma.Y = IO.ReadSingleEndian();
CCT.Gamma.Z = IO.ReadSingleEndian();
CCT.Contrast = IO.ReadSingleEndian();
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.Close();
IO.C();
}
public void TXTWriter(string file)
{
if (CCTs.Count < 1) return;
if (CCTs.C < 1) return;
IO = File.OpenWriter();
IO.WriteShiftJIS("ID,Hue,Saturation,Lightness,Exposure,GammaR,GammaG,GammaB,Contrast\n");
for (i = 0; i < CCTs.Count; i++)
IO.Write(i + "," + CCTs[i] + "\n");
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));
}
+19 -19
View File
@@ -17,12 +17,12 @@ namespace KKdMainLib.F2
IO = File.OpenReader(file + ".dft", true);
Header = IO.ReadHeader();
if (Header.Signature != 0x54464F44 || Header.InnerSignature != 0x3) return;
IO.Position -= 0x4;
IO.P -= 0x4;
DFTs = IO.ReadCountPointerEndian<DFT>();
if (DFTs.Count < 1) { IO.Close(); DFTs.Count = -1; return; }
DFTs = IO.RCPE<DFT>();
if (DFTs.C < 1) { IO.C(); DFTs.C = -1; return; }
if (DFTs.Count > 0 && DFTs.Offset == 0) { IO.Close(); DFTs.Count = -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;
@@ -30,30 +30,30 @@ namespace KKdMainLib.F2
DFTs = IO.ReadCountPointerX<DFT>();
}*/
IO.Position = DFTs.Offset;
for (i = 0; i < DFTs.Count; i++)
IO.P = DFTs.O;
for (i = 0; i < DFTs.C; i++)
{
ref DFT DFT = ref DFTs.Entries[i];
IO.ReadInt32Endian();
DFT. Focus = IO.ReadSingleEndian();
DFT. FocusRange = IO.ReadSingleEndian();
DFT.FuzzingRange = IO.ReadSingleEndian();
DFT.Ratio = IO.ReadSingleEndian();
DFT.Quality = IO.ReadSingleEndian();
if (IO.IsX) IO.ReadInt32();
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.Close();
IO.C();
}
public void TXTWriter(string file)
{
if (DFTs.Count < 1) return;
if (DFTs.C < 1) return;
IO = File.OpenWriter();
IO.WriteShiftJIS("ID,Focus,FocusRange,FuzzingRange,Ratio,Quality\n");
for (i = 0; i < DFTs.Count; i++)
IO.Write(i + "," + DFTs[i] + "\n");
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));
}
+39 -39
View File
@@ -19,14 +19,14 @@ namespace KKdMainLib.F2
if (Header.Signature != 0x4354494C || Header.InnerSignature != 0x2 ||
Header.SectionSignature != 0x2) return;
LITs = IO.ReadCountPointerEndian<CountPointer<LIT>>();
if (LITs.Count < 1) { IO.Close(); LITs.Count = -1; return; }
LITs = IO.RCPE<CountPointer<LIT>>();
if (LITs.C < 1) { IO.C(); LITs.C = -1; return; }
IO.Position = LITs.Offset;
for (i = 0; i < LITs.Count; i++)
IO.P = LITs.O;
for (i = 0; i < LITs.C; i++)
{
LITs[i] = IO.ReadCountPointerX<LIT>();
if ((LITs[i].Count > 0 || LITs[i].Offset == 0) && !IO.IsX) { IO.Close(); LITs.Count = -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;
@@ -36,52 +36,52 @@ namespace KKdMainLib.F2
if (IO.IsX) IO.ReadInt64();*/
}
for (i = 0; i < LITs.Count; i++)
for (i = 0; i < LITs.C; i++)
{
IO.Position = LITs[i].Offset;
for (i0 = 0; i0 < LITs[i].Count; i0++)
IO.P = LITs[i].O;
for (i0 = 0; i0 < LITs[i].C; i0++)
{
ref LIT LIT = ref LITs.Entries[i].Entries[i0];
LIT.Id = (Id )IO.ReadInt32Endian();
LIT.Flags = (Flags)IO.ReadInt32Endian();
LIT.Type = (Type )IO.ReadInt32Endian();
if (IO.IsX) { IO.ReadInt64(); IO.ReadInt64(); IO.ReadInt64(); }
LIT.Ambient .X = IO.ReadSingleEndian();
LIT.Ambient .Y = IO.ReadSingleEndian();
LIT.Ambient .Z = IO.ReadSingleEndian();
LIT.Ambient .W = IO.ReadSingleEndian();
LIT.Diffuse .X = IO.ReadSingleEndian();
LIT.Diffuse .Y = IO.ReadSingleEndian();
LIT.Diffuse .Z = IO.ReadSingleEndian();
LIT.Diffuse .W = IO.ReadSingleEndian();
LIT.Specular .X = IO.ReadSingleEndian();
LIT.Specular .Y = IO.ReadSingleEndian();
LIT.Specular .Z = IO.ReadSingleEndian();
LIT.Specular .W = IO.ReadSingleEndian();
LIT.Position .X = IO.ReadSingleEndian();
LIT.Position .Y = IO.ReadSingleEndian();
LIT.Position .Z = IO.ReadSingleEndian();
LIT.ToneCurve.X = IO.ReadSingleEndian();
LIT.ToneCurve.Y = IO.ReadSingleEndian();
LIT.ToneCurve.Z = IO.ReadSingleEndian();
if (IO.IsX) { IO.ReadInt64(); IO.ReadInt64(); IO.ReadInt64();
IO.ReadInt64(); IO.ReadInt64(); IO.ReadInt32(); }
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.Close();
IO.C();
}
public void TXTWriter(string file)
{
i = 0;
if (LITs.Count < 1) return;
if (LITs.C < 1) return;
IO = File.OpenWriter();
IO.WriteShiftJIS("Type,AmbientR,AmbientG,AmbientB,DiffuseR,DiffuseG,DiffuseB,SpecularR,SpecularG," +
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].Count; i0++)
IO.Write(LITs[i][i0] + "," + i + "\n");
for (i0 = 0; i0 < LITs[i].C; i0++)
IO.W(LITs[i][i0] + "," + i + "\n");
File.WriteAllBytes(file + "_light.txt", IO.ToArray(true));
}
+47 -47
View File
@@ -44,23 +44,23 @@ namespace KKdMainLib
Stream reader = File.OpenReader(FilePath);
DirectoryPath = Path.GetFullPath(FilePath).Replace(Path.GetExtension(FilePath), "");
Signature = (Farc)reader.ReadInt32Endian(true);
Signature = (Farc)reader.RI32E(true);
if (Signature != Farc.FArc && Signature != Farc.FArC && Signature != Farc.FARC)
{ reader.Close(); return false; }
{ reader.Dispose(); return false; }
int HeaderLength = reader.ReadInt32Endian(true);
int HeaderLength = reader.RI32E(true);
if (Signature == Farc.FARC)
{
FARCType = (Type)reader.ReadInt32Endian(true);
reader.ReadInt32();
FARCType = (Type)reader.RI32E(true);
reader.RI32();
int FARCMode = reader.ReadInt32Endian(true);
int FARCMode = reader.RI32E(true);
FT = FARCMode == 0x10;
CBC = FARCMode != 0x10 && FARCMode != 0x40;
if (CBC && FARCType.HasFlag(Type.ECB))
{
reader.Close();
reader.Dispose();
byte[] Header = new byte[HeaderLength - 0x08];
MSIO.FileStream stream = new MSIO.FileStream(FilePath, MSIO.FileMode.Open,
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite) { Position = 0x10 };
@@ -72,44 +72,44 @@ namespace KKdMainLib
Header = SkipData(Header, 0x10);
reader = File.OpenReader(Header);
FARCMode = reader.ReadInt32Endian(true);
FARCMode = reader.RI32E(true);
FT = FARCMode == 0x10;
}
}
if (Signature == Farc.FARC)
if (reader.ReadInt32Endian(true) == 1)
Files = new FARCFile[reader.ReadInt32Endian(true)];
reader.ReadInt32();
if (reader.RI32E(true) == 1)
Files = new FARCFile[reader.RI32E(true)];
reader.RI32();
if (Files == null)
{
int Count = 0;
long Position = reader.LongPosition;
while (reader.LongPosition < HeaderLength)
long Position = reader.I64P;
while (reader.I64P < HeaderLength)
{
reader.NullTerminated();
reader.ReadInt32();
if (Signature != Farc.FArc ) reader.ReadInt32();
reader.ReadInt32();
if (Signature == Farc.FARC && FT) reader.ReadInt32();
reader.NT();
reader.RI32();
if (Signature != Farc.FArc ) reader.RI32();
reader.RI32();
if (Signature == Farc.FARC && FT) reader.RI32();
Count++;
}
reader.LongPosition = Position;
reader.I64P = Position;
Files = new FARCFile[Count];
}
for (int i = 0; i < Files.Length; i++)
{
Files[i].Name = reader.NullTerminatedUTF8();
Files[i].Offset = reader.ReadInt32Endian(true);
if (Signature != Farc.FArc) Files[i].SizeComp = reader.ReadInt32Endian(true);
Files[i].SizeUnc = reader.ReadInt32Endian(true);
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.ReadInt32Endian(true);
Files[i].Type = (Type)reader.RI32E(true);
}
reader.Close();
reader.Dispose();
return true;
}
@@ -224,48 +224,48 @@ namespace KKdMainLib
}
Stream writer = File.OpenWriter(DirectoryPath + ".farc", true);
writer.WriteEndian((int)Signature, true);
writer.WE((int)Signature, true);
using (Stream HeaderWriter = File.OpenWriter())
{
if (Signature == Farc.FArc) HeaderWriter.WriteEndian(0x20, true);
else if (Signature == Farc.FArC) HeaderWriter.WriteEndian(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.WriteEndian((int)FARCType, true);
HeaderWriter.Write (0x00);
HeaderWriter.WriteEndian(0x40, true);
HeaderWriter.Write (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.Length; i++)
HeaderWriter.Length += Path.GetFileName(Files[i].Name).Length + HeaderPartLength;
writer.WriteEndian(HeaderWriter.Length, true);
writer.Write(HeaderWriter.ToArray(true));
HeaderWriter.L += Path.GetFileName(Files[i].Name).Length + HeaderPartLength;
writer.WE(HeaderWriter.L, true);
writer.W(HeaderWriter.ToArray(true));
}
int Align = writer.Position.Align(0x10) - writer.Position;
int Align = writer.P.Align(0x10) - writer.P;
for (int i1 = 0; i1 < Align; i1++)
writer.WriteByte((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
writer.W((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
for (int i = 0; i < Files.Length; i++)
CompressStuff(i, ref Files, ref writer);
writer.Position = Signature == Farc.FARC ? 0x1C : 0x0C;
writer.P = Signature == Farc.FARC ? 0x1C : 0x0C;
for (int i = 0; i < Files.Length; i++)
{
writer.Write(Path.GetFileName(Files[i].Name) + "\0");
writer.WriteEndian(Files[i].Offset, true);
writer.W(Path.GetFileName(Files[i].Name) + "\0");
writer.WE(Files[i].Offset, true);
if (Signature != Farc.FArc)
writer.WriteEndian(Files[i].SizeComp, true);
writer.WriteEndian(Files[i].SizeUnc, true);
writer.WE(Files[i].SizeComp, true);
writer.WE(Files[i].SizeUnc, true);
}
writer.Close();
writer.Dispose();
}
private void CompressStuff(int i, ref FARCFile[] Files, ref Stream writer)
{
Files[i].Offset = writer.Position;
Files[i].Offset = writer.P;
Files[i].SizeUnc = Files[i].Data.Length;
Files[i].Type = Type.None;
@@ -290,14 +290,14 @@ namespace KKdMainLib
Files[i].Data = Encrypt(Data, false);
}
writer.Write(Files[i].Data);
writer.W(Files[i].Data);
Files[i].Data = null;
if (Signature != Farc.FARC)
{
int Align = writer.Position.Align(0x20) - writer.Position;
int Align = writer.P.Align(0x20) - writer.P;
for (int i1 = 0; i1 < Align; i1++)
writer.WriteByte((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
writer.W((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
}
}
+116 -86
View File
@@ -5,146 +5,176 @@ namespace KKdMainLib.IO
{
public static class Extensions
{
public static string NullTerminatedASCII(this Stream stream, byte End = 0) =>
stream.NullTerminated(End).ToASCII();
public static string NullTerminatedUTF8 (this Stream stream, byte End = 0) =>
stream.NullTerminated(End).ToUTF8 ();
public static byte[] NullTerminated (this Stream stream, byte End = 0)
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.LongPosition < stream.LongLength)
while (stream.I64P < stream.I64L)
{
byte a = stream.ReadByte();
byte a = stream.RU8();
if (a == End) break;
else s.Add(a);
}
return s.ToArray();
}
public static byte PeekByte (this Stream stream)
{ byte val = stream.ReadByte(); stream.LongPosition--; return val; }
public static char PeekCharASCII(this Stream stream)
{ byte val = stream.ReadByte(); stream.LongPosition--; return (char)val; }
public static char PeekCharUTF8 (this Stream stream)
{ long LongPosition = stream.LongPosition; char val = stream.ReadCharUTF8();
stream.LongPosition = LongPosition; return val; }
public static byte PB (this Stream stream)
{ byte val = stream.RU8(); stream.I64P--; return val; }
public static char PCASCII(this Stream stream)
{ byte val = stream.RU8(); stream.I64P--; return (char)val; }
public static char PCUTF8 (this Stream stream)
{ long LongPosition = stream.I64P; char val = stream.RCUTF8();
stream.I64P = LongPosition; return val; }
public static Stream SkipWhitespace(this Stream stream)
public static Stream SW(this Stream stream)
{
while (true)
if (char.IsWhiteSpace(stream.PeekCharUTF8())) stream.ReadCharUTF8();
if (char.IsWhiteSpace(stream.PCUTF8())) stream.RCUTF8();
else break;
return stream;
}
public static bool Assert(this Stream stream, byte next)
{ if (stream.PeekByte() == next) { stream.PeekByte(); return true; } else return false; }
public static bool Assert(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 (!stream.Assert(next[i])) return false;
if (!A(stream, next[i])) return false;
return true;
}
public static bool AssertASCII(this Stream stream, char next)
{ if (stream.PeekCharUTF8() == next) { stream.ReadCharUTF8(); return true; } else return false; }
public static bool AssertASCII(this Stream stream, string next)
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.AssertASCII(next[i])) return false;
if (!stream.AASCII(next[i])) return false;
return true;
}
public static bool Assert(this Stream stream, char next)
{ if (stream.PeekCharUTF8() == next) { stream.ReadCharUTF8(); return true; } else return false; }
public static bool Assert(this Stream stream, string next)
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.Assert(next[i])) return false;
if (!A(stream, next[i])) return false;
return true;
}
public static long ReadIntX(this Stream stream ) => stream.IsX ?
stream.ReadInt64() : stream.ReadUInt32Endian( );
public static long ReadIntX(this Stream stream, bool IsBE) => stream.IsX ?
stream.ReadInt64() : stream.ReadUInt32Endian(IsBE);
public static long RIX(this Stream stream ) => stream.IsX ?
stream.RI64() : stream.RU32E( );
public static long RIX(this Stream stream, bool IsBE) => stream.IsX ?
stream.RI64() : stream.RU32E(IsBE);
public static void WriteX(this Stream stream, long val, ref POF POF)
{ if (stream.IsX) stream.Write ( val);
else stream.WriteEndian((int)val); POF.Offsets.Add(stream.Position); }
public static void WriteX(this Stream stream, long val, ref POF POF, bool IsBE)
{ if (stream.IsX) stream.Write ( val );
else stream.WriteEndian((int)val, IsBE); POF.Offsets.Add(stream.Position); }
public static void WX(this Stream stream, long val, ref POF POF)
{ if (stream.IsX) stream.W ( val);
else stream.WE((int)val); POF.Offsets.Add(stream.P); }
public static void WX(this Stream stream, long val, ref POF POF, bool IsBE)
{ if (stream.IsX) stream.W ( val );
else stream.WE((int)val, IsBE); POF.Offsets.Add(stream.P); }
public static void WriteX(this Stream stream, long val)
{ if (stream.IsX) stream.Write ( val);
else stream.WriteEndian((int)val); }
public static void WriteX(this Stream stream, long val, bool IsBE)
{ if (stream.IsX) stream.Write ( val );
else stream.WriteEndian((int)val, IsBE); }
public static void WX(this Stream stream, long val)
{ if (stream.IsX) stream.W ( val);
else stream.WE((int)val); }
public static void WX(this Stream stream, long val, bool IsBE)
{ if (stream.IsX) stream.W ( val );
else stream.WE((int)val, IsBE); }
public static byte[] ReadAtOffset(this Stream stream, long Offset = -1, long Length = -1)
public static byte[] RaO(this Stream stream, long Offset = -1, long Length = -1)
{
byte[] arr = null;
long Position = stream.LongPosition;
if (Offset == -1) { Position += stream.IsX ? 8 : 4; Offset = stream.ReadIntX(); }
stream.LongPosition = Offset;
if (Length == -1) arr = stream.NullTerminated();
else arr = stream.ReadBytes(Length);
stream.LongPosition = Position;
long Position = stream.I64P;
if (Offset == -1) { Position += stream.IsX ? 8 : 4; Offset = stream.RIX(); }
stream.I64P = Offset;
if (Length == -1) arr = stream.NT();
else arr = stream.RBy(Length);
stream.I64P = Position;
return arr;
}
public static string ReadStringAtOffset(this Stream stream, long Offset = -1, long Length = -1)
public static string RSaO(this Stream stream, long Offset = -1, long Length = -1)
{
string s = null;
long Position = stream.LongPosition;
if (Offset == -1) { Position += stream.IsX ? 8 : 4; Offset = stream.ReadIntX(); }
stream.LongPosition = Offset;
if (Length == -1) s = stream.NullTerminatedUTF8();
else s = stream.ReadStringUTF8(Length);
stream.LongPosition = Position;
long Position = stream.I64P;
if (Offset == -1) { Position += stream.IsX ? 8 : 4; Offset = stream.RIX(); }
stream.I64P = Offset;
if (Length == -1) s = stream.NTUTF8();
else s = stream.RSUTF8(Length);
stream.I64P = Position;
return s;
}
public static Pointer<string> ReadPointerStringShiftJIS(this Stream stream)
{ Pointer<string> val = stream.ReadPointer<string>();
val.Value = stream.ReadStringShiftJISAtOffset(val.Offset); return val; }
public static Pointer<string> RPSSJIS(this Stream stream)
{ Pointer<string> val = stream.RP<string>();
val.V = stream.RPSSJIS(val.O); return val; }
public static string ReadStringShiftJISAtOffset(this Stream stream, long Offset = 0, long Length = 0) =>
Text.ShiftJIS.GetString(stream.ReadAtOffset(Offset, Length));
public static void WPSSJIS(this Stream stream, ref Pointer<string> val)
{ val.O = stream.P; stream.WPSSJIS(val.V); }
public static void WriteShiftJIS(this Stream stream, string String) =>
stream.Write(Text.ShiftJIS.GetBytes(String));
public static Pointer<T> ReadPointer<T>(this Stream stream) =>
new Pointer<T> { Offset = stream.ReadInt32() };
public static string RPSSJIS(this Stream stream, long Offset = 0, long Length = 0) =>
Text.ShiftJIS.GetString(stream.RaO(Offset, Length));
public static Pointer<string> ReadPointerString(this Stream stream)
{ Pointer<string> val = stream.ReadPointer<string>();
val.Value = stream.ReadStringAtOffset(val.Offset); return val; }
public static void WPSSJIS(this Stream stream, string String) =>
stream.W(Text.ShiftJIS.GetBytes(String));
public static Pointer<string> RPS(this Stream stream)
{ Pointer<string> val = stream.RP<string>();
val.V = stream.RSaO(val.O); return val; }
public static void W(this Stream stream, ref Pointer<string> val)
{ val.O = stream.P; stream.W(val.V); }
public static Pointer<T> RP<T>(this Stream stream) =>
new Pointer<T> { O = stream.RI32() };
public static void W<T>(this Stream stream, Pointer<T> val) =>
stream.W(val.O);
public static CountPointer<T> ReadCountPointer<T>(this Stream stream) =>
new CountPointer<T> { Count = stream.ReadInt32(), Offset = stream.ReadInt32() };
new CountPointer<T> { C = stream.RI32(), O = stream.RI32() };
public static Pointer<T> ReadPointerEndian<T>(this Stream stream) =>
new Pointer<T> { Offset = stream.ReadInt32Endian() };
public static void W<T>(this Stream stream, CountPointer<T> val)
{ stream.W(val.C); stream.W(val.O); }
public static Pointer<string> ReadPointerStringEndian(this Stream stream)
{ Pointer<string> val = stream.ReadPointerEndian<string>();
val.Value = stream.ReadStringAtOffset(val.Offset); return val; }
public static Pointer<T> RPE<T>(this Stream stream) =>
new Pointer<T> { O = stream.RI32E() };
public static CountPointer<T> ReadCountPointerEndian<T>(this Stream stream) =>
new CountPointer<T> { Count = stream.ReadInt32Endian(), Offset = stream.ReadInt32Endian() };
public static void WE<T>(this Stream stream, Pointer<T> val) =>
stream.WE(val.O);
public static Pointer<T> ReadPointerX<T>(this Stream stream) =>
new Pointer<T> { Offset = (int)stream.ReadIntX() };
public static CountPointer<T> RCPE<T>(this Stream stream) =>
new CountPointer<T> { C = stream.RI32E(), O = stream.RI32E() };
public static Pointer<string> ReadPointerStringX(this Stream stream)
{ Pointer<string> val = stream.ReadPointerX<string>();
val.Value = stream.ReadStringAtOffset(val.Offset); return val; }
public static void WE<T>(this Stream stream, CountPointer<T> val)
{ stream.WE(val.C); stream.WE(val.O); }
public static CountPointer<T> ReadCountPointerX<T>(this Stream stream) =>
new CountPointer<T> { Count = (int)stream.ReadIntX(), Offset = (int)stream.ReadIntX() };
public static Pointer<string> RPSE(this Stream stream)
{ Pointer<string> val = stream.RPE<string>();
val.V = stream.RSaO(val.O); return val; }
public static void WE(this Stream stream, ref Pointer<string> val)
{ val.O = stream.P; stream.W(val.V); }
public static Pointer<T> RPX<T>(this Stream stream) =>
new Pointer<T> { O = (int)stream.RIX() };
public static void WE<T>(this Stream stream, ref Pointer<T> val) =>
stream.WX(val.O);
public static Pointer<string> RPSX(this Stream stream)
{ Pointer<string> val = stream.RPX<string>();
val.V = stream.RSaO(val.O); return val; }
public static void WX(this Stream stream, ref Pointer<string> val)
{ val.O = stream.P; stream.W(val.V); }
public static CountPointer<T> RCPX<T>(this Stream stream) =>
new CountPointer<T> { C = (int)stream.RIX(), O = (int)stream.RIX() };
public static void WX<T>(this Stream stream, CountPointer<T> val)
{ stream.WX(val.C); stream.WX(val.O); }
}
}
+13 -12
View File
@@ -10,14 +10,14 @@ namespace KKdMainLib.IO
public static Stream OpenReader(string file, bool ReadAllAtOnce)
{ Stream IO = OpenReader(file); if (ReadAllAtOnce) { byte[] data =
IO.ToArray(); IO.Close(); return OpenReader(data); } return IO; }
IO.ToArray(); IO.Dispose(); return OpenReader(data); } return IO; }
public static Stream OpenReader(string file)
{ Stream IO = new Stream(new MSIO.FileStream(file, MSIO.FileMode.Open, MSIO.FileAccess.ReadWrite,
MSIO.FileShare.ReadWrite)) { File = file }; return IO; }
public static Stream OpenWriter(string file, bool SetLength0)
{ Stream IO = OpenWriter(file); if (SetLength0) IO.SetLength(0); return IO; }
{ Stream IO = OpenWriter(file); if (SetLength0) IO.SL(0); return IO; }
public static Stream OpenWriter(string file, int SetLength)
{ Stream IO = OpenWriter(file); IO.SetLength(SetLength); return IO; }
{ Stream IO = OpenWriter(file); IO.SL(SetLength); return IO; }
public static Stream OpenWriter(string file)
{ Stream IO = new Stream(new MSIO.FileStream(file,
MSIO.FileMode.OpenOrCreate, MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite)) { File = file };
@@ -26,27 +26,28 @@ namespace KKdMainLib.IO
MSIO.File.SetLastAccessTimeUtc(file, DateTime.UtcNow); return IO; }
public static byte[] ReadAllBytes(string file, int length, int offset)
{ Stream IO = OpenReader(file); byte[] Data = IO.ReadBytes(length, offset); IO.Close(); return Data; }
{ byte[] Data; using (Stream IO = OpenReader(file)) Data = IO.RBy(length, offset); return Data; }
public static byte[] ReadAllBytes(string file)
{ Stream IO = OpenReader(file); byte[] Data = IO.ReadBytes(IO.Length); IO.Close(); return Data; }
{ byte[] Data; using (Stream IO = OpenReader(file)) Data = IO.RBy(IO.L); return Data; }
public static string ReadAllText (string file)
{ Stream IO = OpenReader(file); string Data = IO.ReadStringUTF8(IO.Length); IO.Close(); return Data; }
{ string Data; using (Stream IO = OpenReader(file)) Data = IO.RSUTF8(IO.L);
return Data.Replace(((char)0xFEFF).ToString(), ""); }
public static string[] ReadAllLines(string file)
{ Stream IO = OpenReader(file); string Data = IO.ReadStringUTF8(IO.Length); IO.Close();
return Data.Replace("\r", "").Split('\n'); }
{ string Data; using (Stream IO = OpenReader(file)) Data = IO.RSUTF8(IO.L);
return Data.Replace(((char)0xFEFF).ToString(), "").Replace("\r", "").Split('\n'); }
public static void WriteAllBytes(string file, byte[] data)
{ Stream IO = OpenWriter(file, true); IO.Write(data); IO.Close(); }
{ using (Stream IO = OpenWriter(file, true)) IO.W(data); }
public static void WriteAllText (string file, string data)
{ Stream IO = OpenWriter(file, true); IO.Write(data); IO.Close(); }
{ using (Stream IO = OpenWriter(file, true)) IO.W(data); }
public static void WriteAllLines(string file, string[] data)
{ Stream IO = OpenWriter(file, true); for (int i = 0; i < data.Length; i++)
IO.Write(data[i] + "\r\n"); IO.Close(); }
{ using (Stream IO = OpenWriter(file, true)) for (int i = 0; i < data.Length; i++)
IO.W(data[i] + "\r\n"); }
public static bool Exists(string file) => MSIO.File.Exists(file);
public static void Delete(string file) => MSIO.File.Delete(file);
+87 -87
View File
@@ -11,7 +11,7 @@ namespace KKdMainLib.IO
private Stream _IO;
public void Close() => _IO.Close();
public void Close() => _IO.C();
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
@@ -19,36 +19,36 @@ namespace KKdMainLib.IO
private MsgPack ReadValue(string Key = null)
{
char c = _IO.SkipWhitespace().PeekCharUTF8();
char c = _IO.SW().PCUTF8();
object obj = null;
if (char.IsDigit(c))
obj = ReadNumber ();
obj = RF ();
else
switch (c)
{
case '"': obj = ReadString (); break;
case '{': obj = ReadObject (); break;
case '[': obj = ReadArray (); break;
case '-': obj = ReadNumber (); break;
case '"': obj = RS (); break;
case '{': obj = RO (); break;
case '[': obj = RA (); break;
case '-': obj = RF (); break;
case 't':
case 'f': obj = ReadBoolean(); break;
case 'n': obj = ReadNull (); break;
case 'f': obj = RBo(); break;
case 'n': obj = RN (); break;
}
return new MsgPack(Key, obj);
}
private string ReadString()
private string RS()
{
if (!_IO.Assert('"')) return null;
if (!Extensions.A(_IO, '"')) return null;
char c;
string s = "";
while (true)
{
c = _IO.ReadCharUTF8();
c = _IO.RCUTF8();
if (c == '\\')
{
c = _IO.ReadCharUTF8();
c = _IO.RCUTF8();
switch (char.ToLower(c))
{
@@ -60,7 +60,7 @@ namespace KKdMainLib.IO
case 'n' : s += '\n'; break;
case 'r' : s += '\r'; break;
case 't' : s += '\t'; break;
case 'u' : s += ReadUnicodeLiteral(); break;
case 'u' : s += RUL(); break;
default: return null;
}
}
@@ -73,68 +73,68 @@ namespace KKdMainLib.IO
return s;
}
private char ReadUnicodeLiteral() =>
(char)((((((ReadHexDigit() << 4) | ReadHexDigit()) << 4) | ReadHexDigit()) << 4) | ReadHexDigit());
private char RUL() =>
(char)((((((RHD() << 4) | RHD()) << 4) | RHD()) << 4) | RHD());
private int ReadHexDigit() => byte.Parse(_IO.ReadCharUTF8().ToString(),
private int RHD() => byte.Parse(_IO.RCUTF8().ToString(),
System.Globalization.NumberStyles.HexNumber);
private KKdList<MsgPack> ReadObject()
private KKdList<MsgPack> RO()
{
KKdList<MsgPack> Obj = KKdList<MsgPack>.New;
if (!_IO.Assert('{')) return KKdList<MsgPack>.Null;
if (_IO.SkipWhitespace().PeekCharUTF8() == '}')
{ _IO.ReadCharUTF8(); return KKdList<MsgPack>.Null; }
if (!Extensions.A(_IO, '{')) return KKdList<MsgPack>.Null;
if (_IO.SW().PCUTF8() == '}')
{ _IO.RCUTF8(); return KKdList<MsgPack>.Null; }
string key;
char c;
while (true)
{
_IO.SkipWhitespace();
_IO.SW();
key = ReadString();
if (!_IO.SkipWhitespace().Assert(':'))
key = RS();
if (!Extensions.A(_IO.SW(), ':'))
return KKdList<MsgPack>.Null;
Obj.Add(ReadValue(key));
c = _IO.SkipWhitespace().PeekCharUTF8();
c = _IO.SW().PCUTF8();
if (c == '}') { _IO.ReadCharUTF8(); break; }
else if (c == ',') { _IO.ReadCharUTF8(); continue; }
if (c == '}') { _IO.RCUTF8(); break; }
else if (c == ',') { _IO.RCUTF8(); continue; }
else return KKdList<MsgPack>.Null;
}
return Obj;
}
private MsgPack[] ReadArray()
private MsgPack[] RA()
{
KKdList<MsgPack> Obj = KKdList<MsgPack>.New;
if (!_IO.Assert('[')) return null;
if (_IO.SkipWhitespace().PeekCharUTF8() == ']')
{ _IO.ReadCharUTF8(); return null; }
if (!Extensions.A(_IO, '[')) return null;
if (_IO.SW().PCUTF8() == ']')
{ _IO.RCUTF8(); return null; }
char c;
while (true)
{
Obj.Add(ReadValue(null));
c = _IO.SkipWhitespace().PeekCharUTF8();
c = _IO.SW().PCUTF8();
if (c == ']') { _IO.ReadCharUTF8(); break; }
else if (c == ',') { _IO.ReadCharUTF8(); continue; }
if (c == ']') { _IO.RCUTF8(); break; }
else if (c == ',') { _IO.RCUTF8(); continue; }
else return null;
}
return Obj.ToArray();
}
private object ReadNumber()
private object RF()
{
string s = " ";
_IO.SkipWhitespace();
if (_IO.PeekCharUTF8() == '-') s += _IO.ReadCharUTF8();
if (_IO.PeekCharUTF8() == '0') s += _IO.ReadCharUTF8();
_IO.SW();
if (_IO.PCUTF8() == '-') s += _IO.RCUTF8();
if (_IO.PCUTF8() == '0') s += _IO.RCUTF8();
else s += ReadDigits ();
if (_IO.PeekCharUTF8() == '.') s += _IO.ReadCharUTF8() + ReadDigits();
if (_IO.PCUTF8() == '.') s += _IO.RCUTF8() + ReadDigits();
else
{
long val = long.Parse(s);
@@ -147,103 +147,103 @@ namespace KKdMainLib.IO
else return val;
}
char c = _IO.PeekCharUTF8();
char c = _IO.PCUTF8();
if (c == 'e' || c == 'E')
{
s += _IO.ReadCharUTF8();
c = _IO.PeekCharUTF8();
if (c == '+' || c == '-') s += _IO.ReadCharUTF8();
s += _IO.RCUTF8();
c = _IO.PCUTF8();
if (c == '+' || c == '-') s += _IO.RCUTF8();
s += ReadDigits();
}
double d = s.ToDouble();
return (float)d == d ? (float)d : d;
}
private bool ReadBoolean()
private bool RBo()
{
char c = _IO.PeekCharUTF8();
if (c == 't' && _IO.Assert( "true")) return true;
else if (c == 'f' && _IO.Assert("false")) return false;
char c = _IO.PCUTF8();
if (c == 't' && _IO.a( "true")) return true;
else if (c == 'f' && _IO.a("false")) return false;
return false;
}
private object ReadNull() { _IO.Assert("null"); return null; }
private object RN() { _IO.a("null"); return null; }
private string ReadDigits()
{ string s = ""; while (char.IsDigit(_IO.SkipWhitespace().
PeekCharUTF8())) s += _IO.ReadCharUTF8(); return s; }
{ string s = ""; while (char.IsDigit(_IO.SW().
PCUTF8())) s += _IO.RCUTF8(); return s; }
public JSON Write(MsgPack MsgPack, string End = "\n", string TabChar = " ") =>
Write(MsgPack, End, TabChar, "", true);
public JSON W(MsgPack MsgPack, string End = "\n", string TabChar = " ") =>
W(MsgPack, End, TabChar, "", true);
public JSON Write(MsgPack MsgPack, bool Style = false) =>
Write(MsgPack, "\n", " ", "", Style);
public JSON W(MsgPack MsgPack, bool Style = false) =>
W(MsgPack, "\n", " ", "", Style);
private JSON Write(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.Write("\"" + MsgPack.Name + "\":" + (Style ? " " : ""));
if (MsgPack.Object == null) { WriteNil(); return this; }
if (MsgPack.Name != null && !IsArray) _IO.W("\"" + MsgPack.Name + "\":" + (Style ? " " : ""));
if (MsgPack.Object == null) { WN(); return this; }
if (MsgPack.List.NotNull)
{
WriteMap();
if (Style) _IO.Write(End);
WM();
if (Style) _IO.W(End);
if (MsgPack.List.Count > 1)
for (int i = 0; i < MsgPack.List.Count; i++)
{
if (Style) _IO.Write(Tab);
Write(MsgPack.List[i], End, TabChar, Tab, Style);
if (i + 1 < MsgPack.List.Count) _IO.Write(',');
if (Style) _IO.Write(End);
if (Style) _IO.W(Tab);
W(MsgPack.List[i], End, TabChar, Tab, Style);
if (i + 1 < MsgPack.List.Count) _IO.W(',');
if (Style) _IO.W(End);
}
else if (MsgPack.List.Count == 1)
{
if (Style) _IO.Write(Tab);
Write(MsgPack.List[0], End, TabChar, Tab, Style);
if (Style) _IO.Write(End);
if (Style) _IO.W(Tab);
W(MsgPack.List[0], End, TabChar, Tab, Style);
if (Style) _IO.W(End);
}
if (Style) _IO.Write(OldTab);
WriteMap(true);
if (Style) _IO.W(OldTab);
WM(true);
}
else if (MsgPack.Array != null)
{
WriteArr();
if (Style) _IO.Write(End);
WA();
if (Style) _IO.W(End);
if (MsgPack.Array.Length > 1)
for (int i = 0; i < MsgPack.Array.Length; i++)
{
if (Style) _IO.Write(Tab);
Write(MsgPack.Array[i], End, TabChar, Tab, Style, true);
if (i + 1 < MsgPack.Array.Length) _IO.Write(',');
if (Style) _IO.Write(End);
if (Style) _IO.W(Tab);
W(MsgPack.Array[i], End, TabChar, Tab, Style, true);
if (i + 1 < MsgPack.Array.Length) _IO.W(',');
if (Style) _IO.W(End);
}
else if (MsgPack.Array.Length == 1)
{
if (Style) _IO.Write(Tab);
Write(MsgPack.Array[0], End, TabChar, Tab, Style, true);
if (Style) _IO.Write(End);
if (Style) _IO.W(Tab);
W(MsgPack.Array[0], End, TabChar, Tab, Style, true);
if (Style) _IO.W(End);
}
if (Style) _IO.Write(OldTab);
WriteArr(true);
if (Style) _IO.W(OldTab);
WA(true);
}
else if (MsgPack.Object is MsgPack msg) Write(msg, End, TabChar, Tab, Style);
else if (MsgPack.Object is string str) Write(str);
else _IO.Write(BaseExtensions.ToString(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;
}
public void Dispose() => _IO.Close();
public void Dispose() => _IO.C();
private void Write(string val) => _IO.Write("\"" + val
private void W(string val) => _IO.W("\"" + val
.Replace("\\", "\\\\").Replace("/" , "\\/").Replace("\"", "\\\"")
.Replace("\0", "\\0" ).Replace("\b", "\\b").Replace("\f", "\\f" )
.Replace("\n", "\\n" ).Replace("\r", "\\r").Replace("\t", "\\t" ) + "\"");
private void WriteNil() => _IO.Write("null");
private void WriteArr(bool End = false) => _IO.Write(End ? "]" : "[");
private void WriteMap(bool End = false) => _IO.Write(End ? "}" : "{");
private void WN() => _IO.W("null");
private void WA(bool End = false) => _IO.W(End ? "]" : "[");
private void WM(bool End = false) => _IO.W(End ? "}" : "{");
}
}
+133 -137
View File
@@ -8,15 +8,15 @@ namespace KKdMainLib.IO
private Stream _IO;
public void Close() => _IO.Close();
public void Close() => _IO.C();
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
public MsgPack Read(bool Array = false)
{
MsgPack MsgPack = MsgPack.New;
byte Unk = _IO.ReadByte();
if (!Array) { MsgPack.Name = ReadString((Types)Unk); Unk = _IO.ReadByte(); }
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)
@@ -29,56 +29,56 @@ namespace KKdMainLib.IO
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 = ReadString(Type);
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 (ReadNil (ref MsgPack, ref Type)) break;
if (ReadArr (ref MsgPack, ref Type)) break;
if (ReadMap (ref MsgPack, ref Type)) break;
if (ReadExt (ref MsgPack, ref Type)) break;
if (ReadString (ref MsgPack, ref Type)) break;
if (ReadBoolean(ref MsgPack, ref Type)) break;
if (ReadBytes (ref MsgPack, ref Type)) break;
if (ReadInt (ref MsgPack, ref Type)) break;
if (ReadUInt (ref MsgPack, ref Type)) break;
if (ReadFloat (ref MsgPack, ref Type)) break;
if (RN (ref MsgPack, ref Type)) break;
if (RBy(ref MsgPack, ref Type)) break;
if (RM (ref MsgPack, ref Type)) break;
if (RE (ref MsgPack, ref Type)) break;
if (RS (ref MsgPack, ref Type)) break;
if (RBo(ref MsgPack, ref Type)) break;
if (RA (ref MsgPack, ref Type)) break;
if (RI (ref MsgPack, ref Type)) break;
if (RU (ref MsgPack, ref Type)) break;
if (RF (ref MsgPack, ref Type)) break;
break;
}
return MsgPack;
}
private bool ReadInt (ref MsgPack MsgPack, ref Types Type)
private bool RI(ref MsgPack MsgPack, ref Types Type)
{
if (Type == Types.Int8 ) MsgPack.Object = _IO.ReadSByte();
else if (Type == Types.Int16) MsgPack.Object = _IO.ReadInt16Endian(true);
else if (Type == Types.Int32) MsgPack.Object = _IO.ReadInt32Endian(true);
else if (Type == Types.Int64) MsgPack.Object = _IO.ReadInt64Endian(true);
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 ReadUInt (ref MsgPack MsgPack, ref Types Type)
private bool RU(ref MsgPack MsgPack, ref Types Type)
{
if (Type == Types.UInt8 ) MsgPack.Object = _IO.ReadByte();
else if (Type == Types.UInt16) MsgPack.Object = _IO.ReadUInt16Endian(true);
else if (Type == Types.UInt32) MsgPack.Object = _IO.ReadUInt32Endian(true);
else if (Type == Types.UInt64) MsgPack.Object = _IO.ReadUInt64Endian(true);
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 ReadFloat (ref MsgPack MsgPack, ref Types Type)
private bool RF(ref MsgPack MsgPack, ref Types Type)
{
if (Type == Types.Float32) MsgPack.Object = _IO.ReadSingleEndian(true);
else if (Type == Types.Float64) MsgPack.Object = _IO.ReadDoubleEndian(true);
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 ReadBoolean(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 ;
@@ -86,71 +86,71 @@ namespace KKdMainLib.IO
return true;
}
private bool ReadBytes (ref MsgPack MsgPack, ref Types Type)
private bool RBy(ref MsgPack MsgPack, ref Types Type)
{
int Length = 0;
if (Type == Types.Bin8 ) Length = _IO.ReadByte();
else if (Type == Types.Bin16) Length = _IO.ReadInt16Endian(true);
else if (Type == Types.Bin32) Length = _IO.ReadInt32Endian(true);
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.ReadBytes(Length);
MsgPack.Object = _IO.RBy(Length);
return true;
}
private bool ReadString (ref MsgPack MsgPack, ref Types Type)
private bool RS(ref MsgPack MsgPack, ref Types Type)
{
string val = ReadString(Type);
string val = RS(Type);
if (val != null) MsgPack.Object = val;
else return false;
return true;
}
private string ReadString(Types Val)
private string RS(Types Val)
{
if (Val >= Types.FixStr && Val <= Types.FixStrMax)
return _IO.ReadString(Val - Types.FixStr);
return _IO.RS(Val - Types.FixStr);
else if (Val >= Types. Str8 && Val <= Types. Str32 )
{
System.Enum.TryParse(Val.ToString(), out Types Type);
int Length = 0;
if (Type == Types.Str8 ) Length = _IO.ReadByte();
else if (Type == Types.Str16) Length = _IO.ReadInt16Endian(true);
else Length = _IO.ReadInt32Endian(true);
return _IO.ReadString(Length);
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 ReadNil(ref MsgPack MsgPack, ref Types Type)
private bool RN(ref MsgPack MsgPack, ref Types Type)
{
if (Type == Types.Nil) MsgPack.Object = null;
else return false;
return true;
}
private bool ReadArr(ref MsgPack MsgPack, ref Types Type)
private bool RA(ref MsgPack MsgPack, ref Types Type)
{
int Length = 0;
if (Type == Types.Arr16) Length = _IO.ReadInt16Endian(true);
else if (Type == Types.Arr32) Length = _IO.ReadInt32Endian(true);
if (Type == Types.Arr16) Length = _IO.RI16E(true);
else if (Type == Types.Arr32) Length = _IO.RI32E(true);
else return false;
MsgPack.Object = new MsgPack[Length];
for (int i = 0; i < Length; i++) MsgPack[i] = Read(true);
return true;
}
private bool ReadMap(ref MsgPack MsgPack, ref Types Type)
private bool RM(ref MsgPack MsgPack, ref Types Type)
{
int Length = 0;
if (Type == Types.Map16) Length = _IO.ReadInt16Endian(true);
else if (Type == Types.Map32) Length = _IO.ReadInt32Endian(true);
if (Type == Types.Map16) Length = _IO.RI16E(true);
else if (Type == Types.Map32) Length = _IO.RI32E(true);
else return false;
MsgPack.Object = KKdList<MsgPack>.New;
for (int i = 0; i < Length; i++) MsgPack.Add(Read());
return true;
}
private bool ReadExt(ref MsgPack MsgPack, ref Types Type)
private bool RE(ref MsgPack MsgPack, ref Types Type)
{
int Length = 0;
if (Type == Types.FixExt1 ) Length = 1 ;
@@ -158,145 +158,141 @@ namespace KKdMainLib.IO
else if (Type == Types.FixExt4 ) Length = 4 ;
else if (Type == Types.FixExt8 ) Length = 8 ;
else if (Type == Types.FixExt16) Length = 16;
else if (Type == Types. Ext8 ) Length = _IO.ReadByte();
else if (Type == Types. Ext16) Length = _IO.ReadInt16Endian(true);
else if (Type == Types. Ext32) Length = _IO.ReadInt32Endian(true);
else 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.ReadSByte(), Data = _IO.ReadBytes(Length) };
MsgPack.Object = new MsgPack.Ext { Type = _IO.RI8(), Data = _IO.RBy(Length) };
return true;
}
public MP Write(MsgPack MsgPack, bool IsArray = false)
{
if (MsgPack.Name != null && !IsArray) Write(MsgPack.Name);
if (MsgPack.Name != null && !IsArray) W(MsgPack.Name);
Write(MsgPack.Object);
return this;
}
private void Write(object obj)
{
if (obj == null) { WriteNil(); return; }
if (obj == null) { WN(); return; }
switch (obj)
{
case KKdList<MsgPack> val: WriteMap(val.Count );
case KKdList<MsgPack> val: WM(val.Count );
for (int i = 0; i < val.Count ; i++) Write(val[i]); break;
case MsgPack[] val: WriteArr(val.Length);
case MsgPack[] val: WA(val.Length);
for (int i = 0; i < val.Length; i++) Write(val[i]); break;
case MsgPack val: Write(val); break;
case byte[] val: Write(val); break;
case bool val: Write(val); break;
case sbyte val: Write(val); break;
case byte val: Write(val); break;
case short val: Write(val); break;
case ushort val: Write(val); break;
case int val: Write(val); break;
case uint val: Write(val); break;
case long val: Write(val); break;
case ulong val: Write(val); break;
case float val: Write(val); break;
case double val: Write(val); break;
case string val: Write(val); break;
case MsgPack.Ext val: Write(val); break;
case byte[] val: W(val); break;
case bool val: W(val); break;
case sbyte val: W(val); break;
case byte val: W(val); break;
case short val: W(val); break;
case ushort val: W(val); break;
case int val: W(val); break;
case uint val: W(val); break;
case long val: W(val); break;
case ulong val: W(val); break;
case float val: W(val); break;
case double val: W(val); break;
case string val: W(val); break;
case MsgPack.Ext val: WE(val); break;
}
}
private void Write( sbyte val) { if (val < -0x20) _IO.WriteByte(0xD0); _IO.Write(val); }
private void Write( byte val) { if (val >= 0x80) _IO.WriteByte(0xCC); _IO.Write(val); }
private void Write( short val) { if (( sbyte)val == val) Write(( sbyte)val);
else if (( byte)val == val) Write(( byte)val);
else { _IO.WriteByte(0xD1); _IO.WriteEndian(val, true); } }
private void Write(ushort val) { if (( byte)val == val) Write(( byte)val);
else { _IO.WriteByte(0xCD); _IO.WriteEndian(val, true); } }
private void Write( int val) { if (( short)val == val) Write(( short)val);
else if ((ushort)val == val) Write((ushort)val);
else { _IO.WriteByte(0xD2); _IO.WriteEndian(val, true); } }
private void Write( uint val) { if ((ushort)val == val) Write((ushort)val);
else { _IO.WriteByte(0xCE); _IO.WriteEndian(val, true); } }
private void Write( long val) { if (( int)val == val) Write(( int)val);
else if (( uint)val == val) Write(( uint)val);
else { _IO.WriteByte(0xD3); _IO.WriteEndian(val, true); } }
private void Write( ulong val) { if (( uint)val == val) Write(( uint)val);
else { _IO.WriteByte(0xCF); _IO.WriteEndian(val, true); } }
private void Write( float val) { if (( long)val == val) Write(( long)val);
else { _IO.WriteByte(0xCA); _IO.WriteEndian(val, true); } }
private void Write(double val) { if (( long)val == val) Write(( long)val);
else if (( float)val == val) Write(( float)val);
else { _IO.WriteByte(0xCB); _IO.WriteEndian(val, true); } }
private void W( sbyte val) { if (val < -0x20) _IO.W(0xD0); _IO.W(val); }
private void W( byte val) { if (val >= 0x80) _IO.W(0xCC); _IO.W(val); }
private void W( short val) { if (( sbyte)val == val) W(( sbyte)val);
else if (( byte)val == val) W(( byte)val);
else { _IO.W(0xD1); _IO.WE(val, true); } }
private void W(ushort val) { if (( byte)val == val) W(( byte)val);
else { _IO.W(0xCD); _IO.WE(val, true); } }
private void W( int val) { if (( short)val == val) W(( short)val);
else if ((ushort)val == val) W((ushort)val);
else { _IO.W(0xD2); _IO.WE(val, true); } }
private void W( uint val) { if ((ushort)val == val) W((ushort)val);
else { _IO.W(0xCE); _IO.WE(val, true); } }
private void W( long val) { if (( int)val == val) W(( int)val);
else if (( uint)val == val) W(( uint)val);
else { _IO.W(0xD3); _IO.WE(val, true); } }
private void W( ulong val) { if (( uint)val == val) W(( uint)val);
else { _IO.W(0xCF); _IO.WE(val, true); } }
private void W( float val) { if (( long)val == val) W(( long)val);
else { _IO.W(0xCA); _IO.WE(val, true); } }
private void W(double val) { if (( long)val == val) W(( long)val);
else if (( float)val == val) W(( float)val);
else { _IO.W(0xCB); _IO.WE(val, true); } }
private void Write( bool val) =>
_IO.WriteByte((byte)(val ? 0xC3 : 0xC2));
private void W( bool val) =>
_IO.W((byte)(val ? 0xC3 : 0xC2));
private void Write(byte[] val)
private void W(byte[] val)
{
if (val == null) { WriteNil(); return; }
if (val == null) { WN(); return; }
if (val.Length < 0x100)
{ _IO.WriteByte(0xC4); _IO.WriteByte (( byte)val.Length ); }
{ _IO.W(0xC4); _IO.W (( byte)val.Length ); }
else if (val.Length < 0x10000)
{ _IO.WriteByte(0xC5); _IO.WriteEndian((ushort)val.Length, true); }
{ _IO.W(0xC5); _IO.WE((ushort)val.Length, true); }
else
{ _IO.WriteByte(0xC6); _IO.WriteEndian( val.Length, true); }
_IO.Write(val);
{ _IO.W(0xC6); _IO.WE( val.Length, true); }
_IO.W(val);
}
private void Write(string val)
private void W(string val)
{
if (val == null) { WriteNil(); return; }
if (val == null) { WN(); return; }
byte[] array = Text.ToUTF8(val);
if (array.Length < 0x20)
_IO.WriteByte((byte)(0xA0 | (array.Length & 0x1F)));
else if (array.Length < 0x100)
{ _IO.WriteByte(0xD9); _IO.WriteByte (( byte)array.Length); }
else if (array.Length < 0x10000)
{ _IO.WriteByte(0xDA); _IO.WriteEndian((ushort)array.Length, true); }
else
{ _IO.WriteByte(0xDB); _IO.WriteEndian( array.Length, true); }
_IO.Write(array);
if (array.Length < 0x20) _IO.W((byte)(0xA0 | (array.Length & 0x1F)));
else if (array.Length < 0x100) { _IO.W(0xD9); _IO.W (( byte)array.Length); }
else if (array.Length < 0x10000) { _IO.W(0xDA); _IO.WE((ushort)array.Length, true); }
else { _IO.W(0xDB); _IO.WE( array.Length, true); }
_IO.W(array);
}
private void WriteNil() => _IO.WriteByte(0xC0);
private void WN() => _IO.W(0xC0);
private void WriteArr(int val)
private void WA(int val)
{
if (val == 0) { WriteNil(); return; }
else if (val < 0x10) _IO.WriteByte((byte)(0x90 | (val & 0x0F)));
else if (val < 0x10000) { _IO.WriteByte(0xDC); _IO.WriteEndian((ushort)val, true); }
else { _IO.WriteByte(0xDD); _IO.WriteEndian( val, true); }
if (val == 0) { WN(); return; }
else if (val < 0x10) _IO.W((byte)(0x90 | (val & 0x0F)));
else if (val < 0x10000) { _IO.W(0xDC); _IO.WE((ushort)val, true); }
else { _IO.W(0xDD); _IO.WE( val, true); }
}
private void WriteMap(int val)
private void WM(int val)
{
if (val == 0) { WriteNil(); return; }
else if (val < 0x10) _IO.WriteByte((byte)(0x80 | (val & 0x0F)));
else if (val < 0x10000) { _IO.WriteByte(0xDE); _IO.WriteEndian((ushort)val, true); }
else { _IO.WriteByte(0xDF); _IO.WriteEndian( val, true); }
if (val == 0) { WN(); return; }
else if (val < 0x10) _IO.W((byte)(0x80 | (val & 0x0F)));
else if (val < 0x10000) { _IO.W(0xDE); _IO.WE((ushort)val, true); }
else { _IO.W(0xDF); _IO.WE( val, true); }
}
private void Write(MsgPack.Ext val)
private void WE(MsgPack.Ext val)
{
if (val.Data == null) { WriteNil(); return; }
if (val.Data == null) { WN(); return; }
if (val.Data.Length < 1 ) { WriteNil(); return; }
else if (val.Data.Length == 1 ) _IO.WriteByte(0xD4);
else if (val.Data.Length == 2 ) _IO.WriteByte(0xD5);
else if (val.Data.Length == 4 ) _IO.WriteByte(0xD6);
else if (val.Data.Length == 8 ) _IO.WriteByte(0xD7);
else if (val.Data.Length == 16) _IO.WriteByte(0xD8);
if (val.Data.Length < 1 ) { WN(); return; }
else if (val.Data.Length == 1 ) _IO.W(0xD4);
else if (val.Data.Length == 2 ) _IO.W(0xD5);
else if (val.Data.Length == 4 ) _IO.W(0xD6);
else if (val.Data.Length == 8 ) _IO.W(0xD7);
else if (val.Data.Length == 16) _IO.W(0xD8);
else
{
if (val.Data.Length < 0x100)
{ _IO.WriteByte(0xC7); _IO.WriteByte (( byte)val.Data.Length); }
{ _IO.W(0xC7); _IO.W (( byte)val.Data.Length); }
else if (val.Data.Length < 0x10000)
{ _IO.WriteByte(0xC8); _IO.WriteEndian((ushort)val.Data.Length, true); }
{ _IO.W(0xC8); _IO.WE((ushort)val.Data.Length, true); }
else
{ _IO.WriteByte(0xC9); _IO.WriteEndian( val.Data.Length, true); }
{ _IO.W(0xC9); _IO.WE( val.Data.Length, true); }
}
_IO.Write(val.Type);
_IO.Write(val.Data);
_IO.W(val.Type);
_IO.W(val.Data);
}
public void Dispose() => _IO.Close();
public void Dispose() => _IO.C();
}
public enum Types : byte
+134 -158
View File
@@ -1,5 +1,4 @@
using System;
using System.Runtime.InteropServices;
using KKdBaseLib;
using MSIO = System.IO;
@@ -23,23 +22,20 @@ namespace KKdMainLib.IO
public bool IsBE = false;
public bool IsX = false;
public int Offset { get => ( int)LongOffset; set => LongOffset = value; }
public uint UIntOffset { get => (uint)LongOffset; set => LongOffset = value; }
public long LongOffset;
public int O { get => ( int)I64O; set => I64O = value; }
public uint U32O { get => (uint)I64O; set => I64O = value; }
public long I64O;
public int Length { get => ( int)stream.Length - Offset;
set => stream.SetLength(value + Offset); }
public uint UIntLength { get => (uint)stream.Length - UIntOffset;
set => stream.SetLength(value + UIntOffset); }
public long LongLength { get => stream.Length - LongOffset;
set => stream.SetLength(value + LongOffset); }
public int L { get => ( int)stream.Length - O; set => stream.SetLength(value + O); }
public uint U32L { get => (uint)stream.Length - U32O; set => stream.SetLength(value + U32O); }
public long I64L { get => stream.Length - I64O; set => stream.SetLength(value + I64O); }
public int Position
{ get => ( int)stream.Position - Offset; set => stream.Position = value + Offset; }
public uint UIntPosition
{ get => (uint)stream.Position - UIntOffset; set => stream.Position = value + UIntOffset; }
public long LongPosition
{ get => stream.Position - LongOffset; set => stream.Position = value + LongOffset; }
public int P
{ get => ( int)stream.Position - O; set => stream.Position = value + O; }
public uint U32P
{ get => (uint)stream.Position - U32O; set => stream.Position = value + U32O; }
public long I64P
{ get => stream.Position - I64O; set => stream.Position = value + I64O; }
public bool CanRead => stream.CanRead;
public bool CanSeek => stream.CanSeek;
@@ -51,7 +47,7 @@ namespace KKdMainLib.IO
public Stream(MSIO.Stream output = null, bool isBE = false)
{
if (output == null) output = MSIO.Stream.Null;
LongOffset = 0;
I64O = 0;
BitRead = 8;
ValRead = ValRead = BitWrite = 0;
stream = output;
@@ -61,162 +57,142 @@ namespace KKdMainLib.IO
IsBE = isBE;
}
public void Close() => Dispose();
public void C() => D(true);
public void Flush() => stream.Flush();
public void F() => stream.Flush();
public void SetLength(long length = 0) => stream.SetLength(length);
public void SL(long length = 0) => stream.SetLength(length);
public long Seek(long offset, SeekOrigin origin = 0) =>
public long S(long offset, SeekOrigin origin = 0) =>
stream.Seek(offset, (MSIO.SeekOrigin)(int)origin);
public long? Seek(long? offset, SeekOrigin origin)
public long? S(long? offset, SeekOrigin origin)
{ if (offset == null) return null; return stream.Seek((long)offset, (MSIO.SeekOrigin)(int)origin); }
public void Dispose() => Dispose(true);
private bool disposed = false;
public void D() => D(true);
public void Dispose() => D(true);
protected virtual void Dispose(bool dispose)
{ CW(); if (stream != MSIO.Stream.Null) { stream.Flush(); stream.Dispose(); } if (dispose) GC.SuppressFinalize(this); }
protected virtual void D(bool dispose)
{ CW(); if (stream != MSIO.Stream.Null && !disposed) { disposed = true; stream.Flush();
stream.Dispose(); } if (dispose) GC.SuppressFinalize(this); }
public MSIO.Stream BaseStream
public MSIO.Stream BS
{ get { stream.Flush(); return stream; } set { stream = value; } }
public void Align(long Align)
public void A(long Align)
{
long Al = Align - Position % Align;
if (Position % Align != 0)
stream.Seek(Position + Offset + Al, 0);
long Al = Align - P % Align;
if (P % Align != 0) stream.Seek(P + O + Al, 0);
}
public void Align(long Align, bool SetLength)
public void A(long Align, bool SetLength)
{
if (SetLength) stream.SetLength(Position + Offset);
long Al = Align - Position % Align;
if (Position % Align != 0) stream.Seek(Position + Offset + Al, 0);
if (SetLength) stream.SetLength(Position + Offset);
if (SetLength) stream.SetLength(P + O);
long Al = Align - P % Align;
if (P % Align != 0) stream.Seek(P + O + Al, 0);
if (SetLength) stream.SetLength(P + O);
}
public void Align(long Align, bool SetLength0, bool SetLength1)
public void A(long Align, bool SetLength0, bool SetLength1)
{
if (SetLength0) stream.SetLength(Position + Offset);
long Al = Align - Position % Align;
if (Position % Align != 0) stream.Seek(Position + Al, 0);
if (SetLength1) stream.SetLength(Position + Offset);
if (SetLength0) stream.SetLength(P + O);
long Al = Align - P % Align;
if (P % Align != 0) stream.Seek(P + Al, 0);
if (SetLength1) stream.SetLength(P + O);
}
public bool ReadBoolean() => stream.ReadByte() != 0;
public sbyte ReadSByte() => ( sbyte)stream.ReadByte();
public byte ReadByte() => ( byte)stream.ReadByte();
public sbyte ReadInt8() => ( sbyte)stream.ReadByte();
public byte ReadUInt8() => ( byte)stream.ReadByte();
public short ReadInt16() { CR(); stream.Read(buf, 0, 2); return *( short*)ptr; }
public ushort ReadUInt16() { CR(); stream.Read(buf, 0, 2); return *(ushort*)ptr; }
public int ReadInt32() { CR(); stream.Read(buf, 0, 4); return *( int*)ptr; }
public uint ReadUInt32() { CR(); stream.Read(buf, 0, 4); return *( uint*)ptr; }
public long ReadInt64() { CR(); stream.Read(buf, 0, 8); return *( long*)ptr; }
public ulong ReadUInt64() { CR(); stream.Read(buf, 0, 8); return *( ulong*)ptr; }
public float ReadSingle() { CR(); stream.Read(buf, 0, 4); return *( float*)ptr; }
public double ReadDouble() { CR(); stream.Read(buf, 0, 8); return *(double*)ptr; }
public bool RBo () => stream.ReadByte() != 0;
public sbyte RI8 () => (sbyte)stream.ReadByte();
public byte RU8 () => ( byte)stream.ReadByte();
public short RI16() { CR(); stream.Read(buf, 0, 2); return *( short*)ptr; }
public ushort RU16() { CR(); stream.Read(buf, 0, 2); return *(ushort*)ptr; }
public int RI32() { CR(); stream.Read(buf, 0, 4); return *( int*)ptr; }
public uint RU32() { CR(); stream.Read(buf, 0, 4); return *( uint*)ptr; }
public long RI64() { CR(); stream.Read(buf, 0, 8); return *( long*)ptr; }
public ulong RU64() { CR(); stream.Read(buf, 0, 8); return *( ulong*)ptr; }
public float RF32() { CR(); stream.Read(buf, 0, 4); return *( float*)ptr; }
public double RF64() { CR(); stream.Read(buf, 0, 8); return *(double*)ptr; }
public short ReadInt16Endian() { CR(); stream.Read(buf, 0, 2); buf.Endian(2, IsBE); return *( short*)ptr; }
public ushort ReadUInt16Endian() { CR(); stream.Read(buf, 0, 2); buf.Endian(2, IsBE); return *(ushort*)ptr; }
public int ReadInt32Endian() { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( int*)ptr; }
public uint ReadUInt32Endian() { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( uint*)ptr; }
public long ReadInt64Endian() { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *( long*)ptr; }
public ulong ReadUInt64Endian() { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *( ulong*)ptr; }
public float ReadSingleEndian() { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( float*)ptr; }
public double ReadDoubleEndian() { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); 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 ReadInt16Endian(bool IsBE)
{ CR(); stream.Read(buf, 0, 2); buf.Endian(2, IsBE); return *( short*)ptr; }
public ushort ReadUInt16Endian(bool IsBE)
{ CR(); stream.Read(buf, 0, 2); buf.Endian(2, IsBE); return *(ushort*)ptr; }
public int ReadInt32Endian(bool IsBE)
{ CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( int*)ptr; }
public uint ReadUInt32Endian(bool IsBE)
{ CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( uint*)ptr; }
public long ReadInt64Endian(bool IsBE)
{ CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *( long*)ptr; }
public ulong ReadUInt64Endian(bool IsBE)
{ CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *( ulong*)ptr; }
public float ReadSingleEndian(bool IsBE)
{ CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( float*)ptr; }
public double ReadDoubleEndian(bool IsBE)
{ CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *(double*)ptr; }
public short RI16E(bool IsBE) { CR(); stream.Read(buf, 0, 2); buf.Endian(2, IsBE); return *( short*)ptr; }
public ushort RU16E(bool IsBE) { CR(); stream.Read(buf, 0, 2); buf.Endian(2, IsBE); return *(ushort*)ptr; }
public int RI32E(bool IsBE) { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( int*)ptr; }
public uint RU32E(bool IsBE) { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( uint*)ptr; }
public long RI64E(bool IsBE) { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *( long*)ptr; }
public ulong RU64E(bool IsBE) { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *( ulong*)ptr; }
public float RF32E(bool IsBE) { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( float*)ptr; }
public double RF64E(bool IsBE) { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *(double*)ptr; }
public void Write(byte[] Val ) => stream.Write(Val ?? new byte[0], 0, Val.Length);
public void Write(byte[] Val, int Length) => stream.Write(Val ?? new byte[0], 0, Length);
public void Write(byte[] Val, int Offset, int Length) => stream.Write(Val ?? new byte[0], Offset, Length);
public void Write(char[] val, bool UTF8 = true) => Write(UTF8 ? val.ToUTF8() : val.ToASCII());
public void W(byte[] Val ) => stream.Write(Val ?? new byte[0], 0, Val.Length);
public void W(byte[] Val, int Length) => stream.Write(Val ?? new byte[0], 0, Length);
public void W(byte[] Val, int Offset, int Length) => stream.Write(Val ?? new byte[0], Offset, Length);
public void W(char[] val, bool UTF8 = true) => W(UTF8 ? val.ToUTF8() : val.ToASCII());
public void WriteByte(byte val) => stream.WriteByte(val);
public void W( bool val) => stream.WriteByte((byte)(val ? 1 : 0));
public void W( sbyte val) => stream.WriteByte((byte) val);
public void W( byte val) => stream.WriteByte( val);
public void W( short val) { CW(); *( short*)ptr = val; stream.Write(buf, 0, 2); }
public void W(ushort val) { CW(); *(ushort*)ptr = val; stream.Write(buf, 0, 2); }
public void W( int val) { CW(); *( int*)ptr = val; stream.Write(buf, 0, 4); }
public void W( uint val) { CW(); *( uint*)ptr = val; stream.Write(buf, 0, 4); }
public void W( long val) { CW(); *( long*)ptr = val; stream.Write(buf, 0, 8); }
public void W( ulong val) { CW(); *( ulong*)ptr = val; stream.Write(buf, 0, 8); }
public void W( float val) { CW(); *( float*)ptr = val; stream.Write(buf, 0, 4); }
public void W(double val) { CW(); *(double*)ptr = val; stream.Write(buf, 0, 8); }
public void Write( bool val) => stream.WriteByte((byte)(val ? 1 : 0));
public void Write( sbyte val) => stream.WriteByte((byte) val);
public void Write( byte val) => stream.WriteByte( val);
public void Write( short val) { CW(); *( short*)ptr = val; stream.Write(buf, 0, 2); }
public void Write(ushort val) { CW(); *(ushort*)ptr = val; stream.Write(buf, 0, 2); }
public void Write( int val) { CW(); *( int*)ptr = val; stream.Write(buf, 0, 4); }
public void Write( uint val) { CW(); *( uint*)ptr = val; stream.Write(buf, 0, 4); }
public void Write( long val) { CW(); *( long*)ptr = val; stream.Write(buf, 0, 8); }
public void Write( ulong val) { CW(); *( ulong*)ptr = val; stream.Write(buf, 0, 8); }
public void Write( float val) { CW(); *( float*)ptr = val; stream.Write(buf, 0, 4); }
public void Write(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);
public void W( short? val) => W(val ?? default);
public void W(ushort? val) => W(val ?? default);
public void W( int? val) => W(val ?? default);
public void W( uint? val) => W(val ?? default);
public void W( long? val) => W(val ?? default);
public void W( ulong? val) => W(val ?? default);
public void W( float? val) => W(val ?? default);
public void W(double? val) => W(val ?? default);
public void Write( sbyte? val) => Write(val.GetValueOrDefault());
public void Write( byte? val) => Write(val.GetValueOrDefault());
public void Write( short? val) => Write(val.GetValueOrDefault());
public void Write(ushort? val) => Write(val.GetValueOrDefault());
public void Write( int? val) => Write(val.GetValueOrDefault());
public void Write( uint? val) => Write(val.GetValueOrDefault());
public void Write( long? val) => Write(val.GetValueOrDefault());
public void Write( ulong? val) => Write(val.GetValueOrDefault());
public void Write( float? val) => Write(val.GetValueOrDefault());
public void Write(double? val) => Write(val.GetValueOrDefault());
public void Write( char val, bool UTF8 = true) =>
Write(UTF8 ? val.ToString().ToUTF8() : val.ToString().ToASCII());
public void Write(string val, bool UTF8 = true) =>
Write(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 WriteEndian( short val) { CW(); *( short*)ptr = val; buf.Endian(2, IsBE); stream.Write(buf, 0, 2); }
public void WriteEndian(ushort val) { CW(); *(ushort*)ptr = val; buf.Endian(2, IsBE); stream.Write(buf, 0, 2); }
public void WriteEndian( int val) { CW(); *( int*)ptr = val; buf.Endian(4, IsBE); stream.Write(buf, 0, 4); }
public void WriteEndian( uint val) { CW(); *( uint*)ptr = val; buf.Endian(4, IsBE); stream.Write(buf, 0, 4); }
public void WriteEndian( long val) { CW(); *( long*)ptr = val; buf.Endian(8, IsBE); stream.Write(buf, 0, 8); }
public void WriteEndian( ulong val) { CW(); *( ulong*)ptr = val; buf.Endian(8, IsBE); stream.Write(buf, 0, 8); }
public void WriteEndian( float val) { CW(); *( float*)ptr = val; buf.Endian(4, IsBE); stream.Write(buf, 0, 4); }
public void WriteEndian(double val) { CW(); *(double*)ptr = val; buf.Endian(8, IsBE); stream.Write(buf, 0, 8); }
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 WriteEndian( short val, bool IsBE)
{ CW(); *( short*)ptr = val; buf.Endian(2, IsBE); stream.Write(buf, 0, 2); }
public void WriteEndian(ushort val, bool IsBE)
{ CW(); *(ushort*)ptr = val; buf.Endian(2, IsBE); stream.Write(buf, 0, 2); }
public void WriteEndian( int val, bool IsBE)
{ CW(); *( int*)ptr = val; buf.Endian(4, IsBE); stream.Write(buf, 0, 4); }
public void WriteEndian( uint val, bool IsBE)
{ CW(); *( uint*)ptr = val; buf.Endian(4, IsBE); stream.Write(buf, 0, 4); }
public void WriteEndian( long val, bool IsBE)
{ CW(); *( long*)ptr = val; buf.Endian(8, IsBE); stream.Write(buf, 0, 8); }
public void WriteEndian( ulong val, bool IsBE)
{ CW(); *( ulong*)ptr = val; buf.Endian(8, IsBE); stream.Write(buf, 0, 8); }
public void WriteEndian( float val, bool IsBE)
{ CW(); *( float*)ptr = val; buf.Endian(4, IsBE); stream.Write(buf, 0, 4); }
public void WriteEndian(double val, bool IsBE)
{ CW(); *(double*)ptr = val; buf.Endian(8, IsBE); stream.Write(buf, 0, 8); }
public void WE( short val, bool IsBE) { CW(); *( short*)ptr = val; buf.Endian(2, IsBE); stream.Write(buf, 0, 2); }
public void WE(ushort val, bool IsBE) { CW(); *(ushort*)ptr = val; buf.Endian(2, IsBE); stream.Write(buf, 0, 2); }
public void WE( int val, bool IsBE) { CW(); *( int*)ptr = val; buf.Endian(4, IsBE); stream.Write(buf, 0, 4); }
public void WE( uint val, bool IsBE) { CW(); *( uint*)ptr = val; buf.Endian(4, IsBE); stream.Write(buf, 0, 4); }
public void WE( long val, bool IsBE) { CW(); *( long*)ptr = val; buf.Endian(8, IsBE); stream.Write(buf, 0, 8); }
public void WE( ulong val, bool IsBE) { CW(); *( ulong*)ptr = val; buf.Endian(8, IsBE); stream.Write(buf, 0, 8); }
public void WE( float val, bool IsBE) { CW(); *( float*)ptr = val; buf.Endian(4, IsBE); stream.Write(buf, 0, 4); }
public void WE(double val, bool IsBE) { CW(); *(double*)ptr = val; buf.Endian(8, IsBE); stream.Write(buf, 0, 8); }
public Half ReadHalf ( ) { ushort a = ReadUInt16 ( ); return (Half)a; }
public Half ReadHalfEndian( ) { ushort a = ReadUInt16Endian( ); return (Half)a; }
public Half ReadHalfEndian(bool IsBE) { ushort a = ReadUInt16Endian(IsBE); return (Half)a; }
public Half RF16 ( ) { ushort a = RU16 ( ); return (Half)a; }
public Half RF16E( ) { ushort a = RU16E( ); return (Half)a; }
public Half RF16E(bool IsBE) { ushort a = RU16E(IsBE); return (Half)a; }
public void Write ( Half val ) => Write ( (ushort ) val );
public void WriteEndian( Half val ) => WriteEndian( (ushort ) val );
public void WriteEndian( Half val, bool IsBE) => WriteEndian( (ushort ) val, IsBE);
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 ReadChar(bool UTF8 = true) => UTF8 ? ReadCharUTF8() : (char)stream.ReadByte();
public char RC(bool UTF8 = true) => UTF8 ? RCUTF8() : (char)stream.ReadByte();
public char ReadCharUTF8()
public char RCUTF8()
{
byte t;
int T;
@@ -237,34 +213,34 @@ namespace KKdMainLib.IO
return (char)val;
}
public string ReadString(long Length, bool UTF8 = true) =>
UTF8 ? ReadStringUTF8(Length) : ReadStringASCII(Length);
public string RS(long Length, bool UTF8 = true) =>
UTF8 ? RSUTF8(Length) : RSASCII(Length);
public string ReadStringUTF8 (long Length) => ReadBytes(Length).ToUTF8 ();
public string ReadStringASCII(long Length) => ReadBytes(Length).ToASCII();
public string RSUTF8 (long Length) => RBy(Length).ToUTF8 ();
public string RSASCII(long Length) => RBy(Length).ToASCII();
public string ReadString(long? Length, bool UTF8 = true) =>
UTF8 ? ReadStringUTF8(Length) : ReadStringASCII(Length);
public string RS(long? Length, bool UTF8 = true) =>
UTF8 ? RSUTF8(Length) : RSASCII(Length);
public string ReadStringUTF8 (long? Length) => ReadBytes(Length).ToUTF8 ();
public string ReadStringASCII(long? Length) => ReadBytes(Length).ToASCII();
public string RSUTF8 (long? Length) => RBy(Length).ToUTF8 ();
public string RSASCII(long? Length) => RBy(Length).ToASCII();
public byte[] ReadBytes(long Length, int Offset = -1)
public byte[] RBy(long Length, int Offset = -1)
{ byte[] Buf = new byte[Length]; if (Offset > -1) stream.Position = Offset;
stream.Read(Buf, 0, (int)Length); return Buf; }
public void ReadBytes(long Length, byte[] Buf, long Offset = -1)
public void RBy(long Length, byte[] Buf, long Offset = -1)
{ if (Offset > -1) stream.Position = Offset; stream.Read(Buf, 0, (int)Length); }
public byte[] ReadBytes(long? Length, int Offset = -1)
{ if (Length == null) return new byte[0]; else return ReadBytes((long)Length, Offset); }
public byte[] RBy(long? Length, int Offset = -1)
{ if (Length == null) return new byte[0]; else return RBy((long)Length, Offset); }
public void ReadBytes(long Length, byte Bits, byte[] Buf, long Offset = -1)
public void RBy(long Length, byte Bits, byte[] Buf, long Offset = -1)
{ if (Offset > -1) stream.Seek(Offset, 0);
if (Bits > 0 && Bits < 8) for (i = 0; i < Length; i++) Buf[i] = ReadBits(Bits); }
if (Bits > 0 && Bits < 8) for (i = 0; i < Length; i++) Buf[i] = RBi(Bits); }
public byte ReadBits(byte Bits)
public byte RBi(byte Bits)
{
BitRead += Bits;
TempBitRead = 8 - BitRead;
@@ -277,9 +253,9 @@ namespace KKdMainLib.IO
return (byte)((ValRead >> TempBitRead) & ((1 << Bits) - 1));
}
public byte ReadHalfByte() => ReadBits(4);
public byte RHB() => RBi(4);
public void Write(int val, byte Bits)
public void W(int val, byte Bits)
{
val &= (1 << Bits) - 1;
BitWrite += Bits;
@@ -313,7 +289,7 @@ namespace KKdMainLib.IO
public byte[] ToArray()
{
long Position = stream.Position;
byte[] Data = ReadBytes(stream.Length, 0);
byte[] Data = RBy(stream.Length, 0);
stream.Position = Position;
return Data;
}
+4 -4
View File
@@ -22,8 +22,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -35,8 +35,8 @@
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="DB\Aet.cs" />
+14
View File
@@ -72,6 +72,10 @@ namespace KKdMainLib
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;
@@ -91,6 +95,11 @@ namespace KKdMainLib
{ if (Dict.FindValue(out string val, args.Split('.' )))
return int.TryParse(val, out value); value = 0; return false; }
public static bool FindValue(this Dictionary<string, object> Dict,
out float value, string args)
{ if (Dict.FindValue(out string val, args.Split('.' )))
return val.ToSingle(out value); value = 0; return false; }
public static bool FindValue(this Dictionary<string, object> Dict,
out double value, string args)
{ if (Dict.FindValue(out string val, args.Split('.' )))
@@ -102,6 +111,11 @@ namespace KKdMainLib
{ 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,
out float? value, string args)
{ if (Dict.FindValue(out string val, args.Split('.' )))
return val.ToSingle(out value); value = null; return false; }
public static bool FindValue(this Dictionary<string, object> Dict,
out double? value, string args)
{ if (Dict.FindValue(out string val, args.Split('.' )))
+130 -105
View File
@@ -17,8 +17,8 @@ namespace KKdMainLib
i = 0;
while (true)
if (IO.ReadInt64() == 0) break;
else { IO.ReadInt64(); i++; }
if (IO.RI64() == 0) break;
else { IO.RI64(); i++; }
if (i == 0) return;
int MOTCount = i;
@@ -27,10 +27,10 @@ namespace KKdMainLib
for (i = 0; i < MOTCount; i++)
{
ref MotHeader Mot = ref MOT[i];
Mot.KeySet .Offset = IO.ReadInt32();
Mot.KeySetTypesOffset = IO.ReadInt32();
Mot. KeySetOffset = IO.ReadInt32();
Mot.BoneInfo .Offset = IO.ReadInt32();
Mot.KeySet .O = IO.RI32();
Mot.KeySetTypesOffset = IO.RI32();
Mot. KeySetOffset = IO.RI32();
Mot.BoneInfo .O = IO.RI32();
}
for (i = 0; i < MOTCount; i++)
@@ -38,57 +38,57 @@ namespace KKdMainLib
ref MotHeader Mot = ref MOT[i];
i0 = 1;
IO.Position = Mot.BoneInfo.Offset;
IO.ReadUInt16();
while (IO.ReadUInt16() != 0) i0++;
IO.P = Mot.BoneInfo.O;
IO.RU16();
while (IO.RU16() != 0) i0++;
Mot.BoneInfo.Value = new BoneInfo[i0];
IO.Position = Mot.BoneInfo.Offset;
for (i0 = 0; i0 < Mot.BoneInfo.Value.Length; i0++)
Mot.BoneInfo.Value[i0].Id = IO.ReadUInt16();
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.Position = Mot.KeySet.Offset;
int info = IO.ReadUInt16();
IO.P = Mot.KeySet.O;
int info = IO.RU16();
Mot.HighBits = info >> 14;
Mot.FrameCount = IO.ReadUInt16();
Mot.FrameCount = IO.RU16();
Mot.KeySet.Value = new KeySet[info & 0x3FFF];
IO.Position = Mot.KeySetTypesOffset;
for (i0 = 0; i0 < Mot.KeySet.Value.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.ReadUInt16();
if (i0 % 8 == 0) i1 = IO.RU16();
Mot.KeySet.Value[i0] = new KeySet { Type = (KeySetType)((i1 >> (i0 % 8 * 2)) & 0b11) };
Mot.KeySet.V[i0] = new KeySet { Type = (KeySetType)((i1 >> (i0 % 8 * 2)) & 0b11) };
}
IO.Position = Mot.KeySetOffset;
for (i0 = 0; i0 < Mot.KeySet.Value.Length; i0++)
IO.P = Mot.KeySetOffset;
for (i0 = 0; i0 < Mot.KeySet.V.Length; i0++)
{
ref KeySet Key = ref Mot.KeySet.Value[i0];
ref KeySet Key = ref Mot.KeySet.V[i0];
if (Key.Type == KeySetType.Static)
{ Key.Keys = new KFT2<ushort, float>[1];
Key.Keys[0].V = IO.ReadSingle(); }
{ Key.Keys = new KFT2[1];
Key.Keys[0].V = IO.RF32(); }
else if (Key.Type == KeySetType.Linear)
{
Key.Keys = new KFT2<ushort, float>[IO.ReadUInt16()];
Key.Keys = new KFT2[IO.RU16()];
for (i1 = 0; i1 < Key.Keys.Length; i1++)
Key.Keys[i1].F = IO.ReadUInt16();
IO.Align(0x4);
Key.Keys[i1].F = IO.RU16();
IO.A(0x4);
for (i1 = 0; i1 < Key.Keys.Length; i1++)
Key.Keys[i1].V = IO.ReadSingle();
Key.Keys[i1].V = IO.RF32();
}
else if (Key.Type == KeySetType.Interpolated)
{
Key.Keys = new KFT2<ushort, float>[IO.ReadUInt16()];
Key.Keys = new KFT2[IO.RU16()];
for (i1 = 0; i1 < Key.Keys.Length; i1++)
Key.Keys[i].F = IO.ReadUInt16();
IO.Align(0x4);
Key.Keys[i1].F = IO.RU16();
IO.A(0x4);
for (i1 = 0; i1 < Key.Keys.Length; i1++)
{ Key.Keys[i1].V = IO.ReadSingle(); Key.Keys[i1].T = IO.ReadSingle(); }
{ Key.Keys[i1].V = IO.RF32(); Key.Keys[i1].T = IO.RF32(); }
}
}
}
IO.Close();
IO.C();
}
public void MOTWriter(string file)
@@ -97,69 +97,69 @@ namespace KKdMainLib
IO = File.OpenWriter(file + ".bin");
int MOTCount = MOT.Length;
IO.Position = (MOTCount + 1) << 4;
IO.P = (MOTCount + 1) << 4;
for (i = 0; i < MOTCount; i++)
{
ref MotHeader Mot = ref MOT[i];
Mot.KeySet.Offset = IO.Position;
IO.Write((ushort)((Mot.HighBits << 14) | (Mot.KeySet.Value.Length & 0x3FFF)));
IO.Write((ushort)Mot.FrameCount);
Mot.KeySet.O = IO.P;
IO.W((ushort)((Mot.HighBits << 14) | (Mot.KeySet.V.Length & 0x3FFF)));
IO.W((ushort)Mot.FrameCount);
Mot.KeySetTypesOffset = IO.Position;
for (i0 = 0, i1 = 0; i0 < Mot.KeySet.Value.Length; i0++)
Mot.KeySetTypesOffset = IO.P;
for (i0 = 0, i1 = 0; i0 < Mot.KeySet.V.Length; i0++)
{
i1 |= ((byte)Mot.KeySet.Value[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.Write((ushort)i1); i1 = 0; }
if (i0 % 8 == 7) { IO.W((ushort)i1); i1 = 0; }
}
IO.Write((ushort)i1);
IO.W((ushort)i1);
IO.Align(0x4);
Mot.KeySetOffset = IO.Position;
for (i0 = 0; i0 < Mot.KeySet.Value.Length; i0++)
IO.A(0x4);
Mot.KeySetOffset = IO.P;
for (i0 = 0; i0 < Mot.KeySet.V.Length; i0++)
{
ref KeySet Key = ref Mot.KeySet.Value[i0];
ref KeySet Key = ref Mot.KeySet.V[i0];
if (Key.Type == KeySetType.Static)
IO.Write(Key.Keys[0].V);
IO.W(Key.Keys[0].V);
else if (Key.Type == KeySetType.Linear)
{
IO.Write((ushort)Key.Keys.Length);
IO.W((ushort)Key.Keys.Length);
for (i1 = 0; i1 < Key.Keys.Length; i1++)
IO.Write(Key.Keys[i1].F);
IO.Align(0x4);
IO.W(Key.Keys[i1].F);
IO.A(0x4);
for (i1 = 0; i1 < Key.Keys.Length; i1++)
IO.Write(Key.Keys[i1].V);
IO.W(Key.Keys[i1].V);
}
else if (Key.Type == KeySetType.Interpolated)
{
IO.Write((ushort)Key.Keys.Length);
IO.W((ushort)Key.Keys.Length);
for (i1 = 0; i1 < Key.Keys.Length; i1++)
IO.Write(Key.Keys[i1].F);
IO.Align(0x4);
IO.W(Key.Keys[i1].F);
IO.A(0x4);
for (i1 = 0; i1 < Key.Keys.Length; i1++)
{ IO.Write(Key.Keys[i1].V); IO.Write(Key.Keys[i1].T); }
{ IO.W(Key.Keys[i1].V); IO.W(Key.Keys[i1].T); }
}
}
IO.Align(0x4);
IO.A(0x4);
Mot.BoneInfo.Offset = IO.Position;
for (i0 = 0; i0 < Mot.BoneInfo.Value.Length; i0++)
IO.Write((ushort)Mot.BoneInfo.Value[i0].Id);
IO.Write((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.Align(0x4, true);
IO.A(0x4, true);
IO.Position = 0;
IO.P = 0;
for (i = 0; i < MOTCount; i++)
{
ref MotHeader Mot = ref MOT[i];
IO.Write(Mot.KeySet .Offset);
IO.Write(Mot.KeySetTypesOffset);
IO.Write(Mot. KeySetOffset);
IO.Write(Mot.BoneInfo .Offset);
IO.W(Mot.KeySet .O);
IO.W(Mot.KeySetTypesOffset);
IO.W(Mot. KeySetOffset);
IO.W(Mot.BoneInfo .O);
}
IO.Close();
IO.C();
}
public void MsgPackReader(string file, bool JSON)
@@ -190,18 +190,18 @@ namespace KKdMainLib
public void MsgPackReader(MsgPack MOT, ref MotHeader Mot)
{
MsgPack Temp = MsgPack.New;
Mot.HighBits = MOT.ReadInt32("HighBits" );
Mot.FrameCount = MOT.ReadInt32("FrameCount");
Mot.HighBits = MOT.RI32("HighBits" );
Mot.FrameCount = MOT.RI32("FrameCount");
if ((Temp = MOT["KeySets", true]).IsNull) { Temp.Dispose(); return; }
Mot.KeySet.Value = new KeySet[Temp.Array.Length];
for (i0 = 0; i0 < Mot.KeySet.Value.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.Value[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].ReadInt32();
KeySet.Type = (KeySetType)Temp.Array[i0].Array[0].RI32();
MsgPack keySet = Temp.Array[i0].Array[1];
@@ -209,36 +209,54 @@ namespace KKdMainLib
else if (KeySet.Type == KeySetType.None) continue;
else if (KeySet.Type == KeySetType.Static)
{
KeySet.Keys = new KFT2<ushort, float>[1];
KeySet.Keys[0].F = keySet.Array[0][0].ReadUInt16();
KeySet.Keys[0].V = keySet.Array[0][1].ReadSingle();
KeySet.Keys = new KFT2[1];
if (keySet.Array == null) continue;
else if (keySet.Array.Length == 0) continue;
else if (keySet.Array[0].Array == null) continue;
else if (keySet.Array[0].Array.Length == 0) continue;
else if (keySet.Array[0].Array.Length == 1)
KeySet.Keys[0] = new KFT2 (keySet.Array[0][0].RF32());
else if (keySet.Array[0].Array.Length > 1)
KeySet.Keys[0] = new KFT2 (keySet.Array[0][0].RF32(), keySet.Array[1].RF32());
}
else if (KeySet.Type == KeySetType.Linear)
{
KeySet.Keys = new KFT2<ushort, float>[keySet.Array.Length];
KeySet.Keys = new KFT2[keySet.Array.Length];
for (i1 = 0; i1 < keySet.Array.Length; i1++)
{
KeySet.Keys[i1].F = keySet.Array[i1][0].ReadUInt16();
KeySet.Keys[i1].V = keySet.Array[i1][1].ReadSingle();
ref MsgPack Array = ref keySet.Array[i1];
if (Array.Array == null) continue;
else if (Array.Array.Length == 0) continue;
else if (Array.Array.Length == 1)
KeySet.Keys[i1] = new KFT2 (Array[0].RF32());
else if (Array.Array.Length == 2)
KeySet.Keys[i1] = new KFT2 (Array[0].RF32(), Array[1].RF32());
}
}
else if (KeySet.Type == KeySetType.Interpolated)
{
KeySet.Keys = new KFT2<ushort, float>[keySet.Array.Length];
KeySet.Keys = new KFT2[keySet.Array.Length];
for (i1 = 0; i1 < keySet.Array.Length; i1++)
{
KeySet.Keys[i1].F = keySet.Array[i1][0].ReadUInt16();
KeySet.Keys[i1].V = keySet.Array[i1][1].ReadSingle();
KeySet.Keys[i1].T = keySet.Array[i1][2].ReadSingle();
ref MsgPack Array = ref keySet.Array[i1];
if (Array.Array == null ||
Array.Array.Length == 0) continue;
else if (Array.Array.Length == 1)
KeySet.Keys[i1] = new KFT2 (Array[0].RF32());
else if (Array.Array.Length == 2)
KeySet.Keys[i1] = new KFT2 (Array[0].RF32(), Array[1].RF32());
else if (Array.Array.Length > 2)
KeySet.Keys[i1] = new KFT2 (Array[0].RF32(),
Array[1].RF32(), keySet.Array[i1][2].RF32());
}
}
}
if ((Temp = MOT["BoneInfo", true]).NotNull)
{
Mot.BoneInfo.Value = new BoneInfo[Temp.Array.Length];
for (i = 0; i < Mot.BoneInfo.Value.Length; i++)
Mot.BoneInfo.Value[i].Id = Temp[i].ReadInt32();
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();
}
@@ -247,10 +265,10 @@ namespace KKdMainLib
{
MsgPack MOT = MsgPack.NewReserve(4).Add("FrameCount", Mot.FrameCount).Add("HighBits", Mot.HighBits);
MsgPack KeySets = new MsgPack(Mot.KeySet.Value.Length, "KeySets");
for (i0 = 0; i0 < Mot.KeySet.Value.Length; i0++)
MsgPack KeySets = new MsgPack(Mot.KeySet.V.Length, "KeySets");
for (i0 = 0; i0 < Mot.KeySet.V.Length; i0++)
{
ref KeySet KeySet = ref Mot.KeySet.Value[i0];
ref KeySet KeySet = ref Mot.KeySet.V[i0];
if (KeySet.Type == KeySetType.None) continue;
KeySets[i0] = new MsgPack(2);
@@ -258,31 +276,38 @@ namespace KKdMainLib
KeySets[i0].Array[1] = new MsgPack(KeySet.Keys.Length);
if (KeySet.Type == KeySetType.Static)
{
KeySets[i0].Array[1][0] = new MsgPack(2);
KeySets[i0].Array[1][0].Array[0] = KeySet.Keys[0].F;
KeySets[i0].Array[1][0].Array[1] = KeySet.Keys[0].V;
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++)
{
KeySets[i0].Array[1][i1] = new MsgPack(2);
KeySets[i0].Array[1][i1].Array[0] = KeySet.Keys[i1].F;
KeySets[i0].Array[1][i1].Array[1] = KeySet.Keys[i1].V;
IKF KF = KeySet.Keys[i1].Check();
if (KF is KFT0 KFT0) KeySets[i0].Array[1][i1] =
new MsgPack(null, new MsgPack[] { KFT0.F });
else if (KF is KFT1 KFT1) KeySets[i0].Array[1][i1] =
new MsgPack(null, new MsgPack[] { KFT1.F, KFT1.V });
}
else
for (i1 = 0; i1 < KeySet.Keys.Length; i1++)
{
KeySets[i0].Array[1][i1] = new MsgPack(3);
KeySets[i0].Array[1][i1].Array[0] = KeySet.Keys[i1].F;
KeySets[i0].Array[1][i1].Array[1] = KeySet.Keys[i1].V;
KeySets[i0].Array[1][i1].Array[2] = KeySet.Keys[i1].T;
IKF KF = KeySet.Keys[i1].Check();
if (KF is KFT0 KFT0) KeySets[i0].Array[1][i1] =
new MsgPack(null, new MsgPack[] { KFT0.F });
else if (KF is KFT1 KFT1) KeySets[i0].Array[1][i1] =
new MsgPack(null, new MsgPack[] { KFT1.F, KFT1.V });
else if (KF is KFT2 KFT2) KeySets[i0].Array[1][i1] =
new MsgPack(null, new MsgPack[] { KFT2.F, KFT2.V, KFT2.T });
}
}
MOT.Add(KeySets);
MsgPack BoneInfo = new MsgPack(Mot.BoneInfo.Value.Length, "BoneInfo");
for (i0 = 0; i0 < Mot.BoneInfo.Value.Length; i0++)
BoneInfo[i0] = Mot.BoneInfo.Value[i0].Id;
MsgPack BoneInfo = new MsgPack(Mot.BoneInfo.V.Length, "BoneInfo");
for (i0 = 0; i0 < Mot.BoneInfo.V.Length; i0++)
BoneInfo[i0] = Mot.BoneInfo.V[i0].Id;
MOT.Add(BoneInfo);
return MOT;
@@ -301,7 +326,7 @@ namespace KKdMainLib
public struct KeySet
{
public KFT2<ushort, float>[] Keys;
public KFT2[] Keys;
public KeySetType Type;
public override string ToString() => $"Type: {Type}" + (Type == KeySetType.Static ?
+2 -2
View File
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("2BA7EFC6-91D1-8BBC-C487-06C7F36CC789")]
[assembly: AssemblyVersion("0.4.7.5")]
[assembly: AssemblyFileVersion("0.4.7.5")]
[assembly: AssemblyVersion("0.4.7.6")]
[assembly: AssemblyFileVersion("0.4.7.6")]
+62 -62
View File
@@ -23,68 +23,68 @@ namespace KKdMainLib
Header = new Header();
IO.Format = Format.F;
Header.Signature = IO.ReadInt32();
Header.Signature = IO.RI32();
if (Header.Signature == 0x41525453)
{
Header = IO.ReadHeader(true, false);
POF.Offsets = KKdList<long>.New;
long Count = IO.ReadInt32Endian();
Offset = IO.ReadInt32Endian();
long Count = IO.RI32E();
Offset = IO.RI32E();
if (Offset == 0)
{
Offset = Count;
OffsetX = IO.ReadInt64();
Count = IO.ReadInt64();
IO.Offset = Header.Length;
OffsetX = IO.RI64();
Count = IO.RI64();
IO.O = Header.Length;
IO.Format = Format.X;
IO.LongOffset += Offset;
IO.Position = 0;
IO.I64O += Offset;
IO.P = 0;
}
else IO.Position = Header.Length + 0x40;
else IO.P = Header.Length + 0x40;
STRs = new String[Count];
for (int i = 0; i < Count; i++)
{
STRs[i].Str.Offset = IO.ReadInt32Endian();
STRs[i].ID = IO.ReadInt32Endian();
STRs[i].Str.O = IO.RI32E();
STRs[i].ID = IO.RI32E();
}
if (IO.IsX)
{
IO.LongOffset = Header.Length + OffsetX;
IO.I64O = Header.Length + OffsetX;
for (int i = 0; i < Count; i++)
STRs[i].Str.Value = IO.ReadStringAtOffset(STRs[i].Str.Offset);
STRs[i].Str.V = IO.RSaO(STRs[i].Str.O);
}
else
{
IO.Offset = 0;
IO.O = 0;
for (int i = 0; i < Count; i++)
STRs[i].Str.Value = STRs[i].Str.Offset > 0 ?
IO.ReadStringAtOffset(STRs[i].Str.Offset) : null;
STRs[i].Str.V = STRs[i].Str.O > 0 ?
IO.RSaO(STRs[i].Str.O) : null;
}
}
else
{
IO.Position -= 4;
IO.P -= 4;
int Count = 0;
for (int a = 0, i = 0; IO.Position > 0 && IO.Position < IO.Length; i++, Count++)
for (int a = 0, i = 0; IO.P > 0 && IO.P < IO.L; i++, Count++)
{
a = IO.ReadInt32();
a = IO.RI32();
if (a == 0) break;
}
STRs = new String[Count];
for (int i = 0; i < Count; i++)
{
IO.LongPosition = STRs[i].Str.Offset;
IO.I64P = STRs[i].Str.O;
STRs[i].ID = i;
STRs[i].Str.Value = IO.NullTerminatedUTF8();
STRs[i].Str.V = IO.NTUTF8();
}
}
IO.Close();
IO.C();
return 1;
}
@@ -101,70 +101,70 @@ namespace KKdMainLib
long Count = STRs.LongLength;
if (IO.Format > Format.FT)
{
IO.Position = 0x40;
IO.WriteX(Count, ref POF);
IO.WriteX(0x80);
IO.Position = 0x80;
for (int i = 0; i < Count; i++) IO.Write(0x00L);
IO.Align(0x10);
IO.P = 0x40;
IO.WX(Count, ref POF);
IO.WX(0x80);
IO.P = 0x80;
for (int i = 0; i < Count; i++) IO.W(0x00L);
IO.A(0x10);
}
else
{
for (int i = 0; i < Count; i++) IO.Write(0x00);
IO.Align(0x20);
for (int i = 0; i < Count; i++) IO.W(0x00);
IO.A(0x20);
}
KKdList<string> UsedSTR = KKdList<string>.New;
KKdList<int> UsedSTRPos = KKdList<int>.New;
int[] STRPos = new int[Count];
UsedSTRPos.Add(IO.Position);
UsedSTRPos.Add(IO.P);
UsedSTR.Add("");
IO.WriteByte(0);
IO.W(0);
for (int i = 0; i < Count; i++)
{
if (!UsedSTR.Contains(STRs[i].Str.Value))
if (!UsedSTR.Contains(STRs[i].Str.V))
{
STRPos[i] = IO.Position;
STRPos[i] = IO.P;
UsedSTRPos.Add(STRPos[i]);
UsedSTR.Add(STRs[i].Str.Value);
IO.Write(STRs[i].Str.Value);
IO.WriteByte(0);
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] == STRs[i].Str.Value) { STRPos[i] = UsedSTRPos[i2]; break; }
if (UsedSTR[i2] == STRs[i].Str.V) { STRPos[i] = UsedSTRPos[i2]; break; }
}
if (IO.Format > Format.FT)
{
IO.Align(0x10);
Offset = IO.UIntPosition;
IO.Position = 0x80;
IO.A(0x10);
Offset = IO.U32P;
IO.P = 0x80;
for (int i = 0; i < Count; i++)
{
POF.Offsets.Add(IO.Position);
IO.WriteEndian(STRPos[i]);
IO.WriteEndian(STRs[i].ID);
POF.Offsets.Add(IO.P);
IO.WE(STRPos[i]);
IO.WE(STRs[i].ID);
}
IO.UIntPosition = Offset;
IO.U32P = Offset;
POF.Depth = 1;
IO.Write(POF);
CurrentOffset = IO.UIntPosition;
IO.WriteEOFC();
IO.W(POF);
CurrentOffset = IO.U32P;
IO.WEOFC();
Header.DataSize = (int)(CurrentOffset - 0x40);
Header.Signature = 0x41525453;
Header.SectionSize = (int)(Offset - 0x40);
IO.Position = 0;
IO.Write(Header, true);
IO.P = 0;
IO.W(Header, true);
}
else
{
IO.Position = 0;
for (int i = 0; i < Count; i++) IO.Write(STRPos[i]);
IO.P = 0;
for (int i = 0; i < Count; i++) IO.W(STRPos[i]);
}
IO.Close();
IO.C();
}
public void MsgPackReader(string file, bool JSON)
@@ -174,16 +174,16 @@ namespace KKdMainLib
if ((Temp = MsgPack["STR"]).NotNull) return;
Header = new Header();
System.Enum.TryParse(Temp.ReadString("Format"), out Header.Format);
System.Enum.TryParse(Temp.RS("Format"), out Header.Format);
if ((Temp = MsgPack["Strings", true]).IsNull) return;
STRs = new String[Temp.Array.Length];
for (int i = 0; i < STRs.Length; i++)
{
STRs[i].ID = Temp[i].ReadInt32 ("ID" );
STRs[i].Str.Value = Temp[i].ReadString("Str");
if (STRs[i].Str.Value == null) STRs[i].Str.Value = "";
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();
@@ -197,9 +197,9 @@ namespace KKdMainLib
for (int i = 0; i < STRs.Length; i++)
{
Strings[i] = MsgPack.New.Add("ID", STRs[i].ID);
if (STRs[i].Str.Value != null)
if (STRs[i].Str.Value != "")
Strings[i] = Strings[i].Add("Str", STRs[i].Str.Value);
if (STRs[i].Str.V != null)
if (STRs[i].Str.V != "")
Strings[i] = Strings[i].Add("Str", STRs[i].Str.V);
}
STR_.Add(Strings);
@@ -211,8 +211,8 @@ namespace KKdMainLib
public int ID;
public Pointer<string> Str;
public override string ToString() => "ID: " + ID + (Str.Value != null ||
Str.Value != "" ? ("; Str: " + Str.Value) : "");
public override string ToString() => "ID: " + ID + (Str.V != null ||
Str.V != "" ? ("; Str: " + Str.V) : "");
}
}
}
+30 -30
View File
@@ -17,20 +17,20 @@ namespace KKdSoundLib
Data = new DIVAFile();
Stream reader = File.OpenReader(file + ".diva");
if (reader.ReadString(0x04) != "DIVA") { reader.Close(); return; }
if (reader.RS(0x04) != "DIVA") { reader.C(); return; }
reader.ReadInt32();
Data.Size = reader.ReadUInt32();
Data.SampleRate = reader.ReadUInt32();
Data.SamplesCount = reader.ReadUInt32();
reader.ReadInt64();
Data.Channels = reader.ReadUInt16();
reader.ReadUInt16();
Data.Name = reader.ReadString(0x20);
reader.RI32();
Data.Size = reader.RU32();
Data.SampleRate = reader.RU32();
Data.SamplesCount = reader.RU32();
reader.RI64();
Data.Channels = reader.RU16();
reader.RU16();
Data.Name = reader.RS(0x20);
Stream writer = File.OpenWriter();
if (!ToArray) writer = File.OpenWriter(file + ".wav", true);
writer.LongPosition = 0x2C;
writer.I64P = 0x2C;
byte value = 0;
int[] current = new int[Data.Channels];
@@ -45,19 +45,19 @@ namespace KKdSoundLib
for (i = 0; i < Data.SamplesCount; i++)
for (c = 0; c < Data.Channels; c++)
{
value = reader.ReadHalfByte();
value = reader.RHB();
IMADecoder(value, ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
f = (float)(currentPtr[c] / 32768.0);
writer.Write(f);
writer.W(f);
}
WAV.Header Header = new WAV.Header { Bytes = 4, Channels = Data.Channels, Format = 3,
SampleRate = Data.SampleRate, Size = Data.SamplesCount * Data.Channels * 4 };
writer.Write(Header, 0);
writer.W(Header, 0);
if (ToArray) Data.Data = writer.ToArray();
writer.Close();
writer.C();
reader.Close();
reader.C();
}
public void DIVAWriter(string file)
@@ -68,12 +68,12 @@ namespace KKdSoundLib
Data = new DIVAFile();
WAV.Header Header = reader.ReadWAVHeader();
if (!Header.IsSupported) { reader.Close(); return; }
if (!Header.IsSupported) { reader.C(); return; }
Stream writer = File.OpenWriter(file + ".diva", true);
Data.Channels = Header.Channels;
Data.SampleRate = Header.SampleRate;
writer.LongPosition = 0x40;
writer.I64P = 0x40;
byte value = 0;
int[] sample = new int[Data.Channels];
@@ -90,24 +90,24 @@ namespace KKdSoundLib
for (i = 0; i < Data.SamplesCount; i++)
for (c = 0; c < Header.Channels; c++)
{
samplePtr[c] = (reader.ReadWAVSample(Header.Bytes, Header.Format) * 0x8000).CFTI();
samplePtr[c] = (reader.RS(Header.Bytes, Header.Format) * 0x8000).CFTI();
value = IMAEncoder(samplePtr[c], ref currentPtr[c],
ref currentclampPtr[c], ref stepindexPtr[c]);
writer.Write(value, 4);
writer.W(value, 4);
}
writer.CW();
writer.LongPosition = 0x00;
writer.Write("DIVA");
writer.Write(0x00);
writer.Write((Data.SamplesCount * Data.Channels).Align(2, 2));
writer.Write(Data.SampleRate);
writer.Write(Data.SamplesCount);
writer.Write(0x00);
writer.Write(0x00);
writer.Write(Data.Channels);
writer.Close();
reader.Close();
writer.I64P = 0x00;
writer.W("DIVA");
writer.W(0x00);
writer.W((Data.SamplesCount * Data.Channels).Align(2, 2));
writer.W(Data.SampleRate);
writer.W(Data.SamplesCount);
writer.W(0x00);
writer.W(0x00);
writer.W(Data.Channels);
writer.C();
reader.C();
}
private void IMADecoder(byte value, ref int current, ref int currentclamp, ref sbyte stepindex)
+53 -53
View File
@@ -5,93 +5,93 @@ namespace KKdSoundLib
{
public static class Extensions
{
public static double ReadWAVSample(this Stream IO, ushort Bytes, ushort Format)
public static double RS(this Stream IO, ushort Bytes, ushort Format)
{
if (Bytes == 2) return IO. ReadInt16() / (double)0x00008000;
else if (Bytes == 4 && Format == 0x01) return IO. ReadInt32() / (double)0x80000000;
else if (Bytes == 4 && Format == 0x03) return IO.ReadSingle();
else if (Bytes == 8 && Format == 0x03) return IO.ReadDouble();
if (Bytes == 2) return IO. RI16() / (double)0x00008000;
else if (Bytes == 4 && Format == 0x01) return IO. RI32() / (double)0x80000000;
else if (Bytes == 4 && Format == 0x03) return IO.RF32();
else if (Bytes == 8 && Format == 0x03) return IO.RF64();
else return 0;
}
public static void Write(this Stream IO, double Sample, ushort Bytes, ushort Format)
public static void W(this Stream IO, double Sample, ushort Bytes, ushort Format)
{
if (Bytes == 2) IO.Write((Sample * 0x00008000).CFTS());
else if (Bytes == 4 && Format == 0x01) IO.Write((Sample * 0x80000000).CFTI());
else if (Bytes == 4 && Format == 0x03) IO.Write((float)Sample);
else if (Bytes == 8 && Format == 0x03) IO.Write( Sample);
if (Bytes == 2) IO.W((Sample * 0x00008000).CFTS());
else if (Bytes == 4 && Format == 0x01) IO.W((Sample * 0x80000000).CFTI());
else if (Bytes == 4 && Format == 0x03) IO.W((float)Sample);
else if (Bytes == 8 && Format == 0x03) IO.W( Sample);
}
public static WAV.Header ReadWAVHeader(this Stream IO)
{
WAV.Header Header = new WAV.Header();
if (IO.ReadString(4) != "RIFF") return Header;
IO.ReadUInt32();
if (IO.ReadString(4) != "WAVE") return Header;
if (IO.ReadString(4) != "fmt ") return Header;
int Offset = IO.ReadInt32();
Header.Format = IO.ReadUInt16();
if (IO.RS(4) != "RIFF") return Header;
IO.RU32();
if (IO.RS(4) != "WAVE") return Header;
if (IO.RS(4) != "fmt ") return Header;
int Offset = IO.RI32();
Header.Format = IO.RU16();
if (Header.Format == 0x01 || Header.Format == 0x03 || Header.Format == 0xFFFE)
{
Header.Channels = IO.ReadUInt16();
Header.SampleRate = IO.ReadUInt32();
IO.ReadInt32(); IO.ReadInt16();
Header.Bytes = IO.ReadUInt16();
Header.Channels = IO.RU16();
Header.SampleRate = IO.RU32();
IO.RI32(); IO.RI16();
Header.Bytes = IO.RU16();
if (Header.Bytes % 8 != 0) return Header;
Header.Bytes >>= 3;
if (Header.Bytes == 0) return Header;
if (Header.Format == 0xFFFE)
{
IO.ReadInt32();
Header.ChannelMask = IO.ReadUInt32();
Header.Format = IO.ReadUInt16();
IO.RI32();
Header.ChannelMask = IO.RU32();
Header.Format = IO.RU16();
}
if (Header.Bytes < 1 || (Header.Bytes > 4 && Header.Bytes != 8)) return Header;
if (Header.Bytes > 0 && Header.Bytes < 4 && Header.Format == 3 ) return Header;
if (Header.Bytes == 8 && Header.Format == 1) return Header;
IO.Seek(Offset + 0x14, 0);
if (IO.ReadString(4) != "data") return Header;
Header.Size = IO.ReadUInt32();
Header.HeaderSize = IO.UIntPosition;
IO.S(Offset + 0x14, 0);
if (IO.RS(4) != "data") return Header;
Header.Size = IO.RU32();
Header.HeaderSize = IO.U32P;
Header.IsSupported = true;
return Header;
}
return Header;
}
public static void Write(this Stream IO, WAV.Header Header, long Seek) => IO.Write(Header, Seek, 0);
public static void W(this Stream IO, WAV.Header Header, long Seek) => IO.W(Header, Seek, 0);
public static void Write(this Stream IO, WAV.Header Header, long Seek, SeekOrigin Origin)
{ IO.Seek(Seek, Origin); IO.Write(Header); }
public static void W(this Stream IO, WAV.Header Header, long Seek, SeekOrigin Origin)
{ IO.S(Seek, Origin); IO.W(Header); }
public static void Write(this Stream IO, WAV.Header Header)
public static void W(this Stream IO, WAV.Header Header)
{
IO.Write("RIFF");
if (Header.Format != 0xFFFE) IO.Write(Header.Size + 0x24);
else IO.Write(Header.Size + 0x3C);
IO.Write("WAVE");
IO.Write("fmt ");
if (Header.Format != 0xFFFE) IO.Write(0x10);
else IO.Write(0x28);
IO.W("RIFF");
if (Header.Format != 0xFFFE) IO.W(Header.Size + 0x24);
else IO.W(Header.Size + 0x3C);
IO.W("WAVE");
IO.W("fmt ");
if (Header.Format != 0xFFFE) IO.W(0x10);
else IO.W(0x28);
IO.Write(Header.Format);
IO.Write((short)Header.Channels);
IO.Write(Header.SampleRate);
IO.Write(Header.SampleRate * Header.Channels * Header.Bytes);
IO.Write((short)(Header.Channels * Header.Bytes));
IO.Write((short)(Header.Bytes << 3));
IO.W(Header.Format);
IO.W((short)Header.Channels);
IO.W(Header.SampleRate);
IO.W(Header.SampleRate * Header.Channels * Header.Bytes);
IO.W((short)(Header.Channels * Header.Bytes));
IO.W((short)(Header.Bytes << 3));
if (Header.Format == 0xFFFE)
{
IO.Write((short)0x16);
IO.Write((short)(Header.Bytes << 3));
IO.Write(Header.ChannelMask);
IO.Write(Header.Bytes == 2 ? 0x01 : 0x03);
IO.Write(0x00100000);
IO.Write(0xAA000080);
IO.Write(0x719B3800);
IO.W((short)0x16);
IO.W((short)(Header.Bytes << 3));
IO.W(Header.ChannelMask);
IO.W(Header.Bytes == 2 ? 0x01 : 0x03);
IO.W(0x00100000);
IO.W(0xAA000080);
IO.W(0x719B3800);
}
IO.Write("data");
IO.Write(Header.Size);
IO.W("data");
IO.W(Header.Size);
}
}
}
+4 -4
View File
@@ -22,8 +22,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -35,8 +35,8 @@
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="Extensions.cs" />
+101 -101
View File
@@ -28,18 +28,18 @@ namespace KKdSoundLib
VAGData = new VAGFile();
Stream reader = File.OpenReader(file + ".vag", true);
if (reader.ReadUInt32() != 0x70474156) return;
if (reader.RU32() != 0x70474156) return;
VAGData.Version = reader.ReadUInt32Endian(true);
reader.ReadUInt32();
VAGData.Size = reader.ReadUInt32Endian(true);
VAGData.SampleRate = reader.ReadUInt32Endian(true);
reader.ReadUInt32();
reader.ReadUInt32();
reader.ReadUInt16();
VAGData.Channels = reader.ReadUInt16();
VAGData.Version = reader.RU32E(true);
reader.RU32();
VAGData.Size = reader.RU32E(true);
VAGData.SampleRate = reader.RU32E(true);
reader.RU32();
reader.RU32();
reader.RU16();
VAGData.Channels = reader.RU16();
if (VAGData.Channels < 2) VAGData.Channels = 1;
VAGData.Name = reader.ReadString(0x10);
VAGData.Name = reader.RS(0x10);
bool HEVAG = VAGData.Version == 0x00020001 || VAGData.Version == 0x00030000;
if (!HEVAG) VAGData.Channels = 1;
@@ -52,7 +52,7 @@ namespace KKdSoundLib
Samp2 = new int[VAGData.Channels]; S2Ptr = Samp2.GetPtr();
Samp3 = new int[VAGData.Channels]; S3Ptr = Samp3.GetPtr();
Samp4 = new int[VAGData.Channels]; S4Ptr = Samp4.GetPtr();
if (VAGData.Size + 0x30 > reader.LongLength) VAGData.Size = reader.UIntLength - 0x30;
if (VAGData.Size + 0x30 > reader.I64L) VAGData.Size = reader.U32L - 0x30;
VAGData.Size = (VAGData.Size / VAGData.Channels) >> 4;
VAGData.Flags = new byte [VAGData.Size];
VAGData.Data = new int[VAGData.Size * VBS];
@@ -63,16 +63,16 @@ namespace KKdSoundLib
for (i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
for (c = 0; c < ch; c++)
{
s = reader.ReadByte();
s = reader.RU8();
PrNR = (s & 0xF0) >> 4;
ShF = s & 0x0F;
s = reader.ReadByte();
s = reader.RU8();
PrNR = (s & 0xF0) | PrNR;
VAGData.Flags[i1] = (byte)(s & 0xF);
for (i = 0, i2 = 1; i < BS; i += 2, i2 += 2)
{
s = reader.ReadByte();
s = reader.RU8();
four_bitPtr[i ] = s & 0x0F;
four_bitPtr[i2] = s & 0xF0;
four_bitPtr[i2] >>= 4;
@@ -93,15 +93,15 @@ namespace KKdSoundLib
else
for (i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
{
s = reader.ReadByte();
s = reader.RU8();
PrNR = (s & 0xF0) >> 4;
ShF = s & 0x0F;
s = reader.ReadByte();
s = reader.RU8();
VAGData.Flags[i1] = (byte)(s & 0xF);
for (i = 0, i2 = 1; i < BS; i += 2, i2 += 2)
{
s = reader.ReadByte();
s = reader.RU8();
four_bitPtr[i ] = s & 0x0F;
four_bitPtr[i2] = s & 0xF0;
four_bitPtr[i2] >>= 4;
@@ -120,7 +120,7 @@ namespace KKdSoundLib
}
VAGData.DataPtr = VAGData.OriginDataPtr;
reader.Close();
reader.C();
Success = true;
}
@@ -183,19 +183,19 @@ namespace KKdSoundLib
if (Flag == 7) return;
WAV.Header Header = new WAV.Header();
Stream writer = File.OpenWriter(file + ".wav", true);
writer.LongPosition = 0x2C;
writer.I64P = 0x2C;
if (Flag < 8)
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
{
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
writer.Write(f);
writer.W(f);
}
else
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
writer.Write(0f);
writer.W(0f);
for (i1 = 0, i2 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
{
@@ -206,21 +206,21 @@ namespace KKdSoundLib
for (c = 0; c < ch; c++)
{
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
writer.Write(f);
writer.W(f);
}
else
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
writer.Write(0f);
writer.W(0f);
if (!IgnoreEndFlags && Flag == 1) break;
}
VAGData.DataPtr = VAGData.OriginDataPtr;
Header = new WAV.Header { Bytes = 4, Channels = ch, Format = 3, SampleRate =
VAGData.SampleRate, Size = writer.UIntPosition - 0x2C };
writer.Write(Header, 0);
writer.Close();
VAGData.SampleRate, Size = writer.U32P - 0x2C };
writer.W(Header, 0);
writer.C();
}
public void WAVWriter(string file, bool IgnoreEndFlags = false)
@@ -232,19 +232,19 @@ namespace KKdSoundLib
Stream writer;
if (!IgnoreEndFlags && Flag == 6) writer = File.OpenWriter(file + ".loop.0.wav", true);
else writer = File.OpenWriter(file + ".0.wav", true);
writer.LongPosition = 0x2C;
writer.I64P = 0x2C;
if (Flag < 8)
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
{
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
writer.Write(f);
writer.W(f);
}
else
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
writer.Write(0f);
writer.W(0f);
VAGData.DataPtr += VBS;
@@ -255,13 +255,13 @@ namespace KKdSoundLib
else if (!IgnoreEndFlags && Flag == 6)
{
Header = new WAV.Header { Bytes = 4, Channels = ch, Format = 3, SampleRate =
VAGData.SampleRate, Size = writer.UIntPosition - 0x2C };
writer.Write(Header, 0);
writer.Close();
VAGData.SampleRate, Size = writer.U32P - 0x2C };
writer.W(Header, 0);
writer.C();
i2++;
writer = File.OpenWriter(file + "." + i2 + ".loop.wav", true);
writer.LongPosition = 0x2C;
writer.I64P = 0x2C;
}
if (!IgnoreEndFlags && Flag < 8)
@@ -269,35 +269,35 @@ namespace KKdSoundLib
for (c = 0; c < ch; c++)
{
f = (float)(VAGData.DataPtr[i * ch + c] / 8388608.0);
writer.Write(f);
writer.W(f);
}
else
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
writer.Write(0f);
writer.W(0f);
if (!IgnoreEndFlags && Flag == 1) break;
else if (!IgnoreEndFlags && Flag == 3)
{
Header = new WAV.Header { Bytes = 4, Channels = ch, Format = 3, SampleRate =
VAGData.SampleRate, Size = writer.UIntPosition - 0x2C };
writer.Write(Header, 0);
writer.Close();
VAGData.SampleRate, Size = writer.U32P - 0x2C };
writer.W(Header, 0);
writer.C();
i2++;
if (VAGData.Size == i1 + 1)
writer = File.OpenWriter();
else
writer = File.OpenWriter(file + "." + i2 + ".wav", true);
writer.LongPosition = 0x2C;
writer.I64P = 0x2C;
}
}
VAGData.DataPtr = VAGData.OriginDataPtr;
Header = new WAV.Header { Bytes = 4, Channels = ch, Format = 3, SampleRate =
VAGData.SampleRate, Size = writer.UIntPosition - 0x2C };
writer.Write(Header, 0);
writer.Close();
VAGData.SampleRate, Size = writer.U32P - 0x2C };
writer.W(Header, 0);
writer.C();
}
public int WAVReaderStraight(string file, bool ExtendedFlagging = false)
@@ -306,7 +306,7 @@ namespace KKdSoundLib
VAGData = new VAGFile();
Stream reader = File.OpenReader(file + ".wav");
WAV.Header Header = reader.ReadWAVHeader();
if (!Header.IsSupported) { reader.Close(); return 1; }
if (!Header.IsSupported) { reader.C(); return 1; }
ch = Header.Channels;
VBS = BS * ch;
@@ -317,22 +317,22 @@ namespace KKdSoundLib
if (Header.Bytes == 1 && Header.Format == 0x01)
for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
*VAGData.DataPtr = (reader.ReadByte () - 0x80) << 16;
*VAGData.DataPtr = (reader.RU8 () - 0x80) << 16;
else if (Header.Bytes == 2 && Header.Format == 0x01)
for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
*VAGData.DataPtr = reader.ReadInt16 () << 8;
*VAGData.DataPtr = reader.RI16 () << 8;
else if (Header.Bytes == 3 && Header.Format == 0x01)
for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
*VAGData.DataPtr = reader.ReadByte () | (reader.ReadInt16() << 8);
*VAGData.DataPtr = reader.RU8 () | (reader.RI16() << 8);
else if (Header.Bytes == 4 && Header.Format == 0x01)
for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
*VAGData.DataPtr = reader.ReadInt32 () >> 8;
*VAGData.DataPtr = reader.RI32 () >> 8;
else if (Header.Bytes == 4 && Header.Format == 0x03)
for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
*VAGData.DataPtr = (int)(reader.ReadSingle() * 8388608.0);
*VAGData.DataPtr = (int)(reader.RF32() * 8388608.0);
else if (Header.Bytes == 8 && Header.Format == 0x03)
for (int i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr++)
*VAGData.DataPtr = (int)(reader.ReadDouble() * 8388608.0);
*VAGData.DataPtr = (int)(reader.RF64() * 8388608.0);
VAGData.Size = VAGData.Size.Align(VBS, VBS);
VAGData.DataPtr = VAGData.OriginDataPtr;
@@ -342,7 +342,7 @@ namespace KKdSoundLib
if (ExtendedFlagging) VAGData.Flags[0] = 0x4;
VAGData.Flags[VAGData.Size - 1] = 0x1;
reader.Close();
reader.C();
Success = true;
return 0;
}
@@ -393,15 +393,15 @@ namespace KKdSoundLib
reader = File.OpenReader(Files[i]);
Header = reader.ReadWAVHeader();
if (!Header.IsSupported) { reader.Close(); return 2; }
if (!Header.IsSupported) { reader.C(); return 2; }
if (i == 0) { SampleRate = Header.SampleRate;
ch = Channels = Header.Channels; VBS = BS * ch; }
if (Header.Channels != Channels ) { reader.Close(); return 3; }
if (Header.SampleRate != SampleRate) { reader.Close(); return 4; }
if (Header.Channels != Channels ) { reader.C(); return 3; }
if (Header.SampleRate != SampleRate) { reader.C(); return 4; }
Sizes[i] = Header.Size / Header.Bytes;
Size += Sizes[i].Align(VBS);
reader.Close();
reader.C();
}
VAGData.Data = new int[Size];
@@ -422,23 +422,23 @@ namespace KKdSoundLib
Header = reader.ReadWAVHeader();
if (Header.Bytes == 1 && Header.Format == 0x01)
for (int i1 = 0; i1 < Sizes[i]; i1++, VAGData.DataPtr++)
*VAGData.DataPtr = (reader.ReadByte () - 0x80) << 16;
*VAGData.DataPtr = (reader.RU8 () - 0x80) << 16;
else if (Header.Bytes == 2 && Header.Format == 0x01)
for (int i1 = 0; i1 < Sizes[i]; i1++, VAGData.DataPtr++)
*VAGData.DataPtr = reader.ReadInt16 () << 8;
*VAGData.DataPtr = reader.RI16 () << 8;
else if (Header.Bytes == 3 && Header.Format == 0x01)
for (int i1 = 0; i1 < Sizes[i]; i1++, VAGData.DataPtr++)
*VAGData.DataPtr = reader.ReadByte () | (reader.ReadInt16() << 8);
*VAGData.DataPtr = reader.RU8 () | (reader.RI16() << 8);
else if (Header.Bytes == 4 && Header.Format == 0x01)
for (int i1 = 0; i1 < Sizes[i]; i1++, VAGData.DataPtr++)
*VAGData.DataPtr = reader.ReadInt32 () >> 8;
*VAGData.DataPtr = reader.RI32 () >> 8;
else if (Header.Bytes == 4 && Header.Format == 0x03)
for (int i1 = 0; i1 < Sizes[i]; i1++, VAGData.DataPtr++)
*VAGData.DataPtr = (int)(reader.ReadSingle() * 8388608.0);
*VAGData.DataPtr = (int)(reader.RF32() * 8388608.0);
else if (Header.Bytes == 8 && Header.Format == 0x03)
for (int i1 = 0; i1 < Sizes[i]; i1++, VAGData.DataPtr++)
*VAGData.DataPtr = (int)(reader.ReadDouble() * 8388608.0);
reader.Close();
*VAGData.DataPtr = (int)(reader.RF64() * 8388608.0);
reader.C();
AlignVAG = Sizes[i].Align(VBS) - Sizes[i];
VAGData.DataPtr += AlignVAG;
@@ -480,21 +480,21 @@ namespace KKdSoundLib
data_buffer = new int[BS]; data_bufferPtr = data_buffer.GetPtr();
temp_buffer = new int[BS]; temp_bufferPtr = temp_buffer.GetPtr();
writer.Write(0x70474156);
if (HEVAG) writer.WriteEndian(0x00020001, true);
else writer.WriteEndian(0x00000020, true);
writer.Write(0);
if (HEVAG) writer.WriteEndian((VAGData.Size * ch + ch) << 4, true);
else writer.WriteEndian((VAGData.Size + 1) << 4, true);
writer.WriteEndian(VAGData.SampleRate, true);
writer.Write(0);
writer.Write(0);
writer.Write((ushort)0);
if (HEVAG) writer.Write(VAGData.Channels);
else writer.Write((ushort)0x1);
writer.Write(VAGData.Name);
writer.LongLength = 0x30;
writer.LongPosition = 0x30;
writer.W(0x70474156);
if (HEVAG) writer.WE(0x00020001, true);
else writer.WE(0x00000020, true);
writer.W(0);
if (HEVAG) writer.WE((VAGData.Size * ch + ch) << 4, true);
else writer.WE((VAGData.Size + 1) << 4, true);
writer.WE(VAGData.SampleRate, true);
writer.W(0);
writer.W(0);
writer.W((ushort)0);
if (HEVAG) writer.W(VAGData.Channels);
else writer.W((ushort)0x1);
writer.W(VAGData.Name);
writer.I64L = 0x30;
writer.I64P = 0x30;
if (HEVAG)
for (i1 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
@@ -509,26 +509,26 @@ namespace KKdSoundLib
if (s == 0)
{
S_1[c] = S_2[c] = S_3[c] = S_4[c] = 0;
writer.WriteByte(0);
writer.WriteByte(VAGData.Flags[i1]);
writer.WriteByte(0);
writer.WriteByte(0);
writer.Write(0);
writer.Write(0);
writer.Write(0);
writer.W(0);
writer.W(VAGData.Flags[i1]);
writer.W(0);
writer.W(0);
writer.W(0);
writer.W(0);
writer.W(0);
continue;
}
Calc4BitsHEVAG();
s = ((PrNR & 0xF) << 4) | (ShF & 0xF);
writer.WriteByte((byte)s);
writer.W((byte)s);
s = (PrNR & 0xF0) | (VAGData.Flags[i1] & 0xF);
writer.WriteByte((byte)s);
writer.W((byte)s);
for (i = 0, i2 = 1; i < BS; i += 2, i2 += 2)
{
s = (four_bitPtr[i2] << 4) | four_bitPtr[i];
writer.WriteByte((byte)s);
writer.W((byte)s);
}
}
else
@@ -546,38 +546,38 @@ namespace KKdSoundLib
if (s == 0)
{
S_1[c] = S_2[c] = 0;
writer.WriteByte(0);
writer.WriteByte(VAGData.Flags[i1]);
writer.WriteByte(0);
writer.WriteByte(0);
writer.Write(0);
writer.Write(0);
writer.Write(0);
writer.W(0);
writer.W(VAGData.Flags[i1]);
writer.W(0);
writer.W(0);
writer.W(0);
writer.W(0);
writer.W(0);
continue;
}
Calc4BitsVAG();
s = ((PrNR & 0xF) << 4) | (ShF & 0xF);
writer.WriteByte((byte)s);
writer.WriteByte(VAGData.Flags[i1]);
writer.W((byte)s);
writer.W(VAGData.Flags[i1]);
for (i = 0, i2 = 1; i < BS; i += 2, i2 += 2)
{
s = (four_bitPtr[i2] << 4) | four_bitPtr[i];
writer.WriteByte((byte)s);
writer.W((byte)s);
}
}
if (!HEVAG) ch = 1;
for (c = 0; c < ch; c++)
{
writer.Write(0x77770700);
writer.Write(0x77777777);
writer.Write(0x77777777);
writer.Write(0x77777777);
writer.W(0x77770700);
writer.W(0x77777777);
writer.W(0x77777777);
writer.W(0x77777777);
}
VAGData.DataPtr = VAGData.OriginDataPtr;
writer.Close();
writer.C();
}
private int min, ShM, S1, S2, S3, S4, tS1, tS2, tS3, tS4, PrNRf;
+4 -4
View File
@@ -22,8 +22,8 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -35,8 +35,8 @@
<WarningLevel>4</WarningLevel>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>7.3</LangVersion>
<NoWarn>IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE1006</NoWarn>
<LangVersion>8.0</LangVersion>
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
</PropertyGroup>
<ItemGroup>
<Compile Include="classes\Tools\A3D.cs" />
+2 -3
View File
@@ -29,9 +29,8 @@ namespace PD_Tool
else if (File.Exists(arg) && Path.GetExtension(arg) == ".farc") new KKdFARC(arg).UnPack(true);
else if (File.Exists(arg))
{
reader = File.OpenReader(arg);
header = reader.ReadInt64();
reader.Close();
using (reader = File.OpenReader(arg))
header = reader.RI64();
if (header == 0x454C494641564944) KKdMainLib.DIVAFILE.Decrypt(arg);
}
}
+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.7.5")]
[assembly: AssemblyFileVersion("0.4.7.5")]
[assembly: AssemblyVersion("0.4.7.6")]
[assembly: AssemblyFileVersion("0.4.7.6")]
+4 -4
View File
@@ -8,8 +8,8 @@ namespace PD_Tool
public static void Decrypt(string file)
{
Stream reader = File.OpenReader(file);
if (reader.ReadInt64() != 0x454C494641564944) { reader.Close(); return; }
reader.Close();
if (reader.RI64() != 0x454C494641564944) { reader.C(); return; }
reader.C();
System.Console.Title = "DIVAFILE Decrypt: " + Path.GetFileName(file);
file.Decrypt();
@@ -18,8 +18,8 @@ namespace PD_Tool
public static void Encrypt(string file)
{
Stream reader = File.OpenReader(file);
if (reader.ReadInt64() == 0x454C494641564944) { reader.Close(); return; }
reader.Close();
if (reader.RI64() == 0x454C494641564944) { reader.C(); return; }
reader.C();
System.Console.Title = "DIVAFILE Encrypt: " + Path.GetFileName(file);
file.Encrypt();
+3 -3
View File
@@ -1,7 +1,7 @@
using System;
using KKdBaseLib;
using KKdMainLib.IO;
using KKdA3DA = KKdMainLib.A3DA.A3DA;
using KKdA3DA = KKdMainLib.A3DA;
using KKdFARC = KKdMainLib.FARC;
namespace PD_Tool.Tools
@@ -77,7 +77,7 @@ namespace PD_Tool.Tools
A = new KKdA3DA();
A.MsgPackReader(A3DA);
A.Data._.CompressF16 = Format > Format.FT ? Format == Format.MGF ? 2 : 1 : 0;
A.Data.Format = Format;
A.Head.Format = Format;
FARC.Files[i].Data = (format != "1" && format != "3") ? A.A3DCWriter() : A.A3DAWriter();
}
}
@@ -92,7 +92,7 @@ namespace PD_Tool.Tools
{
A.MsgPackReader(filepath, ext == ".json");
A.Data._.CompressF16 = Format > Format.FT ? Format == Format.MGF ? 2 : 1 : 0;
A.Data.Format = Format;
A.Head.Format = Format;
File.WriteAllBytes(filepath + ".a3da", (format != "1" &&
format != "3") ? A.A3DCWriter() : A.A3DAWriter());