Compare commits
57
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1c18941a1 | ||
|
|
c95a116297 | ||
|
|
139fbf307f | ||
|
|
1d5c88f39f | ||
|
|
786dca23fd | ||
|
|
7046e3cfc2 | ||
|
|
ec5f8c803e | ||
|
|
310d637072 | ||
|
|
4d05f6a878 | ||
|
|
35d7712d8f | ||
|
|
df92e13d2c | ||
|
|
803f64e333 | ||
|
|
a7e14e22ad | ||
|
|
d94f45870d | ||
|
|
2b46e0f4bd | ||
|
|
f1547f78b2 | ||
|
|
6c35326dda | ||
|
|
30a51f6bc4 | ||
|
|
54af060c13 | ||
|
|
84fd22b548 | ||
|
|
798b055756 | ||
|
|
30de413922 | ||
|
|
85a22ea0f7 | ||
|
|
99bb4e3571 | ||
|
|
036863a5a6 | ||
|
|
b6017d1d70 | ||
|
|
5de5d23e94 | ||
|
|
df0cb255fc | ||
|
|
89c9afd0c5 | ||
|
|
cd2eab5b8e | ||
|
|
8dd10b2fa4 | ||
|
|
35dee99307 | ||
|
|
b49b86887e | ||
|
|
a0a3737b47 | ||
|
|
9c86616dcd | ||
|
|
e2990dccaf | ||
|
|
e75c7e6742 | ||
|
|
5ace6bc0e0 | ||
|
|
38851135b6 | ||
|
|
9cbeaf59c2 | ||
|
|
c70630e705 | ||
|
|
6d80dfd0c9 | ||
|
|
06b41269c0 | ||
|
|
4698c75c7a | ||
|
|
792781a5f7 | ||
|
|
773e148783 | ||
|
|
87d4862af5 | ||
|
|
b26cdc8b5c | ||
|
|
6e2f5746b0 | ||
|
|
3f883c4c77 | ||
|
|
0863721dc4 | ||
|
|
e0d651bd55 | ||
|
|
3bbbea9536 | ||
|
|
4de7bd32f7 | ||
|
|
93f905d3e1 | ||
|
|
4c8b293beb | ||
|
|
72141ef603 |
@@ -1,5 +1,8 @@
|
||||
.vs
|
||||
build
|
||||
packages
|
||||
KKdBaseLib/bin
|
||||
KKdBaseLib/obj
|
||||
KKdMainLib/bin
|
||||
KKdMainLib/obj
|
||||
KKdMathLib/bin
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using KKdBaseLib.Auth3D;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct A3DAKey
|
||||
{
|
||||
public KeyType Type;
|
||||
public float Value;
|
||||
public float MaxFrames;
|
||||
public EPType EPTypePre;
|
||||
public EPType EPTypePost;
|
||||
public float FrameDelta;
|
||||
public float ValueDelta;
|
||||
public int Padding;
|
||||
public long FirstKey;
|
||||
public long SecondKey;
|
||||
public long AfterLastKey;
|
||||
public long Length;
|
||||
public long DataOffset; //Used only in-game and points to KFT3 Array
|
||||
|
||||
public KFT3[] Keys;
|
||||
|
||||
public A3DAKey(Key k)
|
||||
{
|
||||
Type = 0; Value = MaxFrames = FrameDelta = ValueDelta = 0; EPTypePre = EPTypePost = 0;
|
||||
FirstKey = SecondKey = AfterLastKey = Padding = 0;
|
||||
Length = DataOffset = 0; Keys = null;
|
||||
|
||||
MaxFrames = k.Max ?? 0;
|
||||
if (k.Type > KeyType.Static && k.Keys != null && k.Keys.Length > 1)
|
||||
{
|
||||
Type = k.Type;
|
||||
Length = k.Keys.Length;
|
||||
Keys = k.Keys;
|
||||
EPTypePost = k.EPTypePost;
|
||||
EPTypePre = k.EPTypePre;
|
||||
FrameDelta = k.Keys[Length - 1].F - k.Keys[0].F;
|
||||
ValueDelta = k.Keys[Length - 1].V - k.Keys[0].V;
|
||||
}
|
||||
else
|
||||
{
|
||||
Type = k.Type;
|
||||
Value = k.Type > 0 ? k.Value : 0.0f;
|
||||
EPTypePost = 0;
|
||||
EPTypePre = 0;
|
||||
FrameDelta = 0;
|
||||
ValueDelta = Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public class HeadData : System.Attribute { }
|
||||
public class Padding : System.Attribute { }
|
||||
public class Binary : System.Attribute { }
|
||||
public class Offset : System.Attribute { }
|
||||
public class Count : System.Attribute { }
|
||||
public class Flags : System.Attribute { }
|
||||
}
|
||||
@@ -0,0 +1,231 @@
|
||||
//Original: AetSet.bt Version: 5.0 by samyuu
|
||||
|
||||
namespace KKdBaseLib.Auth2D
|
||||
{
|
||||
public struct Header
|
||||
{
|
||||
public Pointer<Scene>[] Scenes;
|
||||
}
|
||||
|
||||
public struct Scene
|
||||
{
|
||||
public Pointer<string> Name;
|
||||
public float StartFrame;
|
||||
public float EndFrame;
|
||||
public float FrameRate;
|
||||
public uint BackColor;
|
||||
public uint Width;
|
||||
public uint Height;
|
||||
public Pointer<Vec2<CountPointer<KFT2>>> Camera;
|
||||
public CountPointer<Composition> Composition;
|
||||
public CountPointer<Video > Video;
|
||||
public CountPointer<Audio > Audio;
|
||||
}
|
||||
|
||||
public struct Composition
|
||||
{
|
||||
public int P;
|
||||
public int C { get => E != null ? E.Length : 0;
|
||||
set => E = value > -1 ? new Layer[value] : null; }
|
||||
|
||||
public int O;
|
||||
public Layer[] E;
|
||||
|
||||
public override string ToString() => "Count: " + C;
|
||||
}
|
||||
|
||||
|
||||
public struct Layer
|
||||
{
|
||||
public int ID;
|
||||
public int Offset;
|
||||
public Pointer<string> Name;
|
||||
public float StartFrame;
|
||||
public float EndFrame;
|
||||
public float OffsetFrame;
|
||||
public float TimeScale;
|
||||
public AetLayerFlags Flags;
|
||||
public AetLayerQuality Quality;
|
||||
public AetLayerType Type;
|
||||
public int VidItmOff; //VideoItemOffset
|
||||
public int ParentLayer;
|
||||
public CountPointer<Marker> Marker;
|
||||
public Pointer<VideoData> Video;
|
||||
public Pointer<AudioData> Audio;
|
||||
|
||||
public int DataID;
|
||||
|
||||
public enum AetLayerFlags : ushort
|
||||
{
|
||||
VideoActive = 0b0000000000000001,
|
||||
AudioActive = 0b0000000000000010,
|
||||
EffectsActive = 0b0000000000000100,
|
||||
MotionBlur = 0b0000000000001000,
|
||||
FrameBlending = 0b0000000000010000,
|
||||
Locked = 0b0000000000100000,
|
||||
Shy = 0b0000000001000000,
|
||||
Collapse = 0b0000000010000000,
|
||||
AutoOrientRotation = 0b0000000100000000,
|
||||
AdjustmentLayer = 0b0000001000000000,
|
||||
TimeRemapping = 0b0000010000000000,
|
||||
LayerIs3D = 0b0000100000000000,
|
||||
LookAtCamera = 0b0001000000000000,
|
||||
LookAtPOI = 0b0010000000000000, //POI - Point Of Interest
|
||||
Solo = 0b0100000000000000,
|
||||
MarkersLocked = 0b1000000000000000,
|
||||
}
|
||||
|
||||
public enum AetLayerQuality : byte
|
||||
{
|
||||
None = 0,
|
||||
Wireframe = 1,
|
||||
Draft = 2,
|
||||
Best = 3,
|
||||
}
|
||||
|
||||
public enum AetLayerType : byte
|
||||
{
|
||||
None = 0,
|
||||
Video = 1,
|
||||
Audio = 2,
|
||||
Composition = 3,
|
||||
}
|
||||
|
||||
public override string ToString() => $"ID: {ID}; Name: {Name.V}; Type: {Type}" +
|
||||
( DataID > -1 ? $"; " + $"Data ID: { DataID}" : "") +
|
||||
(ParentLayer > -1 ? $"; Parent Object ID: {ParentLayer}" : "");
|
||||
}
|
||||
|
||||
public struct Marker
|
||||
{
|
||||
public float Frame;
|
||||
public Pointer<string> Name;
|
||||
}
|
||||
|
||||
public struct VideoData
|
||||
{
|
||||
public VideoTransferMode TransferMode;
|
||||
public byte Padding;
|
||||
public CountPointer<KFT2> AnchorX;
|
||||
public CountPointer<KFT2> AnchorY;
|
||||
public CountPointer<KFT2> PositionX;
|
||||
public CountPointer<KFT2> PositionY;
|
||||
public CountPointer<KFT2> Rotation ;
|
||||
public CountPointer<KFT2> ScaleX;
|
||||
public CountPointer<KFT2> ScaleY;
|
||||
public CountPointer<KFT2> Opacity ;
|
||||
public Pointer<Video3DData> Video3D;
|
||||
|
||||
public struct VideoTransferMode
|
||||
{
|
||||
public TransferBlendMode BlendMode;
|
||||
public TransferFlags Flags;
|
||||
public TransferTrackMatte TrackMatte;
|
||||
|
||||
public enum TransferBlendMode : byte
|
||||
{
|
||||
None = 0,
|
||||
Copy = 1,
|
||||
Behind = 2,
|
||||
Normal = 3,
|
||||
Dissolve = 4,
|
||||
Add = 5,
|
||||
Multiply = 6,
|
||||
Screen = 7,
|
||||
Overlay = 8,
|
||||
SoftLight = 9,
|
||||
HardLight = 10,
|
||||
Darken = 11,
|
||||
Lighten = 12,
|
||||
ClassicDifference = 13,
|
||||
Hue = 14,
|
||||
Saturation = 15,
|
||||
Color = 16,
|
||||
Luminosity = 17,
|
||||
StenciilAlpha = 18,
|
||||
StencilLuma = 19,
|
||||
SilhouetteAlpha = 20,
|
||||
SilhouetteLuma = 21,
|
||||
LuminescentPremul = 22,
|
||||
AlphaAdd = 23,
|
||||
ClassicColorDodge = 24,
|
||||
ClassicColorBurn = 25,
|
||||
Exclusion = 26,
|
||||
Difference = 27,
|
||||
ColorDodge = 28,
|
||||
ColorBurn = 29,
|
||||
LinearDodge = 30,
|
||||
LinearBurn = 31,
|
||||
LinearLight = 32,
|
||||
VividLight = 33,
|
||||
PinLight = 34,
|
||||
HardMix = 35,
|
||||
LighterColor = 36,
|
||||
DarkerColor = 37,
|
||||
Subtract = 38,
|
||||
Divide = 39,
|
||||
}
|
||||
|
||||
public enum TransferFlags : byte
|
||||
{
|
||||
PreserveAlpha = 0b01,
|
||||
RandomizeDissolve = 0b10,
|
||||
}
|
||||
|
||||
public enum TransferTrackMatte : byte
|
||||
{
|
||||
NoTrackMatte = 0,
|
||||
Alpha = 1,
|
||||
NotAlpha = 2,
|
||||
Luma = 3,
|
||||
NotLuma = 4,
|
||||
}
|
||||
}
|
||||
|
||||
public struct Video3DData
|
||||
{
|
||||
public CountPointer<KFT2> AnchorZ;
|
||||
public CountPointer<KFT2> PositionZ;
|
||||
public CountPointer<KFT2> DirectionX;
|
||||
public CountPointer<KFT2> DirectionY;
|
||||
public CountPointer<KFT2> DirectionZ;
|
||||
public CountPointer<KFT2> RotationX;
|
||||
public CountPointer<KFT2> RotationY;
|
||||
public CountPointer<KFT2> ScaleZ;
|
||||
}
|
||||
}
|
||||
|
||||
public struct AudioData
|
||||
{
|
||||
public CountPointer<KFT2> VolumeL;
|
||||
public CountPointer<KFT2> VolumeR;
|
||||
public CountPointer<KFT2> PanL;
|
||||
public CountPointer<KFT2> PanR;
|
||||
}
|
||||
|
||||
public struct Video
|
||||
{
|
||||
public int O;
|
||||
public uint Color;
|
||||
public ushort Width;
|
||||
public ushort Height;
|
||||
public float Frames;
|
||||
public CountPointer<Identifier> Identifiers;
|
||||
|
||||
public override string ToString() => $"Width: {Width}; Height: {Height}; Color: {Color:X2)}";
|
||||
|
||||
public struct Identifier
|
||||
{
|
||||
public Pointer<string> Name;
|
||||
public uint ID;
|
||||
|
||||
public override string ToString() => $"ID: {ID}; Name: {Name}";
|
||||
}
|
||||
}
|
||||
|
||||
public struct Audio
|
||||
{
|
||||
public int O;
|
||||
public uint SoundID;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,302 @@
|
||||
namespace KKdBaseLib.Auth3D
|
||||
{
|
||||
public struct Data
|
||||
{
|
||||
public string[] Auth2D;
|
||||
public string[] Motion;
|
||||
public string[] ObjectList;
|
||||
public string[] ObjectHRCList;
|
||||
public string[] MObjectHRCList;
|
||||
public _ _;
|
||||
public DOF? DOF;
|
||||
public Fog[] Fog;
|
||||
public Chara[] Chara;
|
||||
public Curve[] Curve;
|
||||
public Event[] Event;
|
||||
public Light[] Light;
|
||||
public Point[] Point;
|
||||
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 CameraAuxiliary? CameraAuxiliary;
|
||||
}
|
||||
|
||||
public struct _
|
||||
{
|
||||
public CompressF16 CompressF16;
|
||||
public string FileName;
|
||||
public string PropertyVersion;
|
||||
public string ConverterVersion;
|
||||
}
|
||||
|
||||
public struct Ambient
|
||||
{
|
||||
public string Name;
|
||||
public Vec4<Key?>? LightDiffuse;
|
||||
public Vec4<Key?>? RimLightDiffuse;
|
||||
}
|
||||
|
||||
public struct CameraAuxiliary
|
||||
{
|
||||
public Key? Gamma;
|
||||
public Key? Exposure;
|
||||
public Key? Saturate;
|
||||
public Key? GammaRate;
|
||||
public Key? ExposureRate;
|
||||
public Key? AutoExposure;
|
||||
}
|
||||
|
||||
public struct CameraRoot
|
||||
{
|
||||
public ViewPoint VP;
|
||||
public ModelTransform MT;
|
||||
public ModelTransform Interest;
|
||||
|
||||
public struct ViewPoint
|
||||
{
|
||||
public bool FOVIsHorizontal;
|
||||
public float Aspect;
|
||||
public float CameraApertureH;
|
||||
public float CameraApertureW;
|
||||
public Key? FocalLength;
|
||||
public Key? FOV;
|
||||
public Key? Roll;
|
||||
public ModelTransform MT;
|
||||
}
|
||||
}
|
||||
|
||||
public struct Chara
|
||||
{
|
||||
public ModelTransform MT;
|
||||
public string Name;
|
||||
}
|
||||
|
||||
public struct Curve
|
||||
{
|
||||
public string Name;
|
||||
public Key CV;
|
||||
}
|
||||
|
||||
public struct DOF
|
||||
{
|
||||
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 Vec4<Key?>? Color;
|
||||
}
|
||||
|
||||
public enum CompressF16 : int
|
||||
{
|
||||
Type0 = 0,
|
||||
Type1 = 1,
|
||||
Type2 = 2,
|
||||
}
|
||||
|
||||
public enum EPType : int // Pre/Post Infinity
|
||||
{
|
||||
None = 0,
|
||||
Linear = 1,
|
||||
Cycle = 2,
|
||||
CycleOffset = 3,
|
||||
}
|
||||
|
||||
public enum KeyType : int
|
||||
{
|
||||
None = 0,
|
||||
Static = 1,
|
||||
Linear = 2,
|
||||
Hermite = 3,
|
||||
Hold = 4,
|
||||
}
|
||||
|
||||
public struct Key
|
||||
{
|
||||
public KeyType Type;
|
||||
public int? BinOffset;
|
||||
public EPType EPTypePre;
|
||||
public EPType EPTypePost;
|
||||
public float? Max;
|
||||
public float Value;
|
||||
public bool RawData;
|
||||
public KFT3[] Keys;
|
||||
|
||||
public Key(A3DAKey k)
|
||||
{
|
||||
Type = 0;
|
||||
Value = 0;
|
||||
BinOffset = null;
|
||||
RawData = default;
|
||||
Keys = null;
|
||||
|
||||
EPTypePost = k.EPTypePost;
|
||||
EPTypePre = k.EPTypePre;
|
||||
Max = k.MaxFrames;
|
||||
if (k.Length > 1)
|
||||
{
|
||||
Type = k.Type;
|
||||
Keys = k.Keys;
|
||||
}
|
||||
else if (k.Length == 1)
|
||||
{
|
||||
Type = KeyType.Static;
|
||||
Value = k.Keys[0].V;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct Light
|
||||
{
|
||||
public int Id;
|
||||
public string Type;
|
||||
public Key? ConeAngle;
|
||||
public Key? Constant;
|
||||
public Key? DropOff;
|
||||
public Key? Far;
|
||||
public Key? Intensity;
|
||||
public Key? Linear;
|
||||
public Key? Quadratic;
|
||||
public Vec4<Key?>? Ambient;
|
||||
public Vec4<Key?>? Diffuse;
|
||||
public Vec4<Key?>? Specular;
|
||||
public Vec4<Key?>? ToneCurve;
|
||||
public ModelTransform Position;
|
||||
public ModelTransform SpotDirection;
|
||||
}
|
||||
|
||||
public struct MaterialList
|
||||
{
|
||||
public string Name;
|
||||
public Key? GlowIntensity;
|
||||
public Vec4<Key?>? BlendColor;
|
||||
public Vec4<Key?>? Incandescence;
|
||||
}
|
||||
|
||||
public struct MObjectHRC
|
||||
{
|
||||
public string Name;
|
||||
public ObjectNode[] Node;
|
||||
public Instance[] Instances;
|
||||
public ModelTransform MT;
|
||||
|
||||
public struct Instance
|
||||
{
|
||||
public bool Shadow;
|
||||
public string Name;
|
||||
public string UIDName;
|
||||
public ModelTransform MT;
|
||||
}
|
||||
}
|
||||
|
||||
public struct ModelTransform
|
||||
{
|
||||
public int? BinOffset;
|
||||
public Key Visibility;
|
||||
public Vec3<Key> Rot;
|
||||
public Vec3<Key> Scale;
|
||||
public Vec3<Key> Trans;
|
||||
}
|
||||
|
||||
public struct Object
|
||||
{
|
||||
public float PatOffset;
|
||||
public float MorphOffset;
|
||||
public string Name;
|
||||
public string Pat;
|
||||
public string Morph;
|
||||
public string UIDName;
|
||||
public string ParentName;
|
||||
public string ParentNode;
|
||||
public ModelTransform MT;
|
||||
public TexturePattern[] TexPat;
|
||||
public TextureTransform[] TexTrans;
|
||||
|
||||
public struct TexturePattern
|
||||
{
|
||||
public float PatOffset;
|
||||
public string Pat;
|
||||
public string Name;
|
||||
}
|
||||
|
||||
public struct TextureTransform
|
||||
{
|
||||
public string Name;
|
||||
public Key? Rotate;
|
||||
public Key? RotateFrame;
|
||||
public Key? OffsetU;
|
||||
public Key? OffsetV;
|
||||
public Key? RepeatU;
|
||||
public Key? RepeatV;
|
||||
public Key? CoverageU;
|
||||
public Key? CoverageV;
|
||||
public Key? TranslateFrameU;
|
||||
public Key? TranslateFrameV;
|
||||
}
|
||||
}
|
||||
|
||||
public struct ObjectHRC
|
||||
{
|
||||
public bool Shadow;
|
||||
public string Name;
|
||||
public string UIDName;
|
||||
public string ParentName;
|
||||
public string ParentNode;
|
||||
public ObjectNode[] Node;
|
||||
}
|
||||
|
||||
public struct ObjectNode
|
||||
{
|
||||
public Vec3? JointOrient;
|
||||
public int Parent;
|
||||
public string Name;
|
||||
public ModelTransform MT;
|
||||
}
|
||||
|
||||
public struct PlayControl
|
||||
{
|
||||
public float Begin;
|
||||
public int? Div;
|
||||
public float FPS;
|
||||
public float? Offset;
|
||||
public float Size;
|
||||
}
|
||||
|
||||
public struct Point
|
||||
{
|
||||
public ModelTransform MT;
|
||||
public string Name;
|
||||
}
|
||||
|
||||
public struct PostProcess
|
||||
{
|
||||
public Key? LensFlare;
|
||||
public Key? LensGhost;
|
||||
public Key? LensShaft;
|
||||
public Vec4<Key?>? Intensity;
|
||||
public Vec4<Key?>? Radius;
|
||||
public Vec4<Key?>? SceneFade;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
using System;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public static unsafe class Extensions
|
||||
{
|
||||
public static double Acos (this double d ) => Math.Acos (d );
|
||||
public static double Asin (this double d ) => Math.Asin (d );
|
||||
public static double Atan (this double d ) => Math.Atan (d );
|
||||
public static double Actg (this double d ) => 1 / Math.Atan (d );
|
||||
public static double Cos (this double d ) => Math.Cos (d );
|
||||
public static double Cosh (this double val) => Math.Cosh (val);
|
||||
public static double Sin (this double a ) => Math.Sin (a );
|
||||
public static double Sinh (this double val) => Math.Sinh (val);
|
||||
public static double Tan (this double a ) => Math.Tan (a );
|
||||
public static double Tanh (this double val) => Math.Tanh (val);
|
||||
public static double Ctg (this double a ) => 1 / Math.Tan (a );
|
||||
public static double Ctgh (this double val) => 1 / Math.Tanh (val);
|
||||
|
||||
public static double Abs (this double val) => Math.Abs (val);
|
||||
public static double Ceiling(this double a ) => Math.Ceiling(a );
|
||||
public static double Exp (this double d ) => Math.Exp (d );
|
||||
public static double Log (this double d ) => Math.Log (d );
|
||||
public static double Log10 (this double d ) => Math.Log10 (d );
|
||||
public static double Round (this double d ) => Math.Round (d );
|
||||
public static int Sign (this double val) => Math.Sign (val);
|
||||
public static double Sqrt (this double d ) => Math.Sqrt (d );
|
||||
|
||||
public static double Atan2(this double y , double x ) => Math.Atan2(y , x );
|
||||
public static double Log (this double val , double newBase) => Math.Log (val , newBase);
|
||||
public static double Max (this double val1, double val2 ) => Math.Max (val1, val2 );
|
||||
public static double Min (this double val1, double val2 ) => Math.Min (val1, val2 );
|
||||
public static double Pow (this double x , double y ) => Math.Pow (x , y );
|
||||
public static double Round(this double val , int d ) => Math.Round(val , d );
|
||||
|
||||
public static float Acos (this float d ) => (float) Math.Acos (d ) ;
|
||||
public static float Asin (this float d ) => (float) Math.Asin (d ) ;
|
||||
public static float Atan (this float d ) => (float) Math.Atan (d ) ;
|
||||
public static float Actg (this float d ) => (float)(1 / Math.Atan (d ));
|
||||
public static float Cos (this float d ) => (float) Math.Cos (d ) ;
|
||||
public static float Cosh (this float val) => (float) Math.Cosh (val) ;
|
||||
public static float Sin (this float a ) => (float) Math.Sin (a ) ;
|
||||
public static float Sinh (this float val) => (float) Math.Sinh (val) ;
|
||||
public static float Tan (this float a ) => (float) Math.Tan (a ) ;
|
||||
public static float Tanh (this float val) => (float) Math.Tanh (val) ;
|
||||
public static float Ctg (this float a ) => (float)(1 / Math.Tan (a ));
|
||||
public static float Ctgh (this float val) => (float)(1 / Math.Tanh (val));
|
||||
|
||||
public static float Abs (this float val) => Math.Abs (val) ;
|
||||
public static float Ceiling(this float a ) => (float) Math.Ceiling(a ) ;
|
||||
public static float Exp (this float d ) => (float) Math.Exp (d ) ;
|
||||
public static float Log (this float d ) => (float) Math.Log (d ) ;
|
||||
public static float Log10 (this float d ) => (float) Math.Log10 (d ) ;
|
||||
public static float Round (this float d ) => (float) Math.Round (d ) ;
|
||||
public static float Sqrt (this float d ) => (float) Math.Sqrt (d ) ;
|
||||
|
||||
public static float Atan2(this float y , float x ) => (float)Math.Atan2(y , x );
|
||||
public static float Log (this float val , float newBase) => (float)Math.Log (val , newBase);
|
||||
public static float Max (this float val1, float val2 ) => Math.Max (val1, val2 );
|
||||
public static float Min (this float val1, float val2 ) => Math.Min (val1, val2 );
|
||||
public static float Pow (this float x , float y ) => (float)Math.Pow (x , y );
|
||||
public static float Round(this float val , int d ) => (float)Math.Round(val , d );
|
||||
|
||||
public static void FC( ref double Value) =>
|
||||
Value = Value % 1 >= 0.5 ? (long)(Value + 0.5) : (long)Value;
|
||||
|
||||
public static long FC(this double Value) =>
|
||||
Value % 1 >= 0.5 ? (long)(Value + 0.5) : (long)Value;
|
||||
|
||||
public static int A(this int value, int alignement, int divide = 1) =>
|
||||
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
|
||||
|
||||
public static uint A(this uint value, uint alignement, uint divide = 1) =>
|
||||
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
|
||||
|
||||
public static long A(this long value, long alignement, long divide = 1) =>
|
||||
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
|
||||
|
||||
public static ulong A(this ulong value, ulong alignement, ulong divide = 1) =>
|
||||
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
|
||||
|
||||
private static byte[] buf = new byte[8];
|
||||
|
||||
public static byte[] E(this byte[] le, byte len)
|
||||
{ for (byte i = 0; i < len; i++) buf[i] = le[i];
|
||||
for (byte i = 0; i < len; i++) le[len - i - 1] = buf[i]; return le; }
|
||||
public static byte[] E(this byte[] le, byte len, bool isBE)
|
||||
{ if (isBE) { for (byte i = 0; i < len; i++) buf[i] = le[i];
|
||||
for (byte i = 0; i < len; i++) le[len - i - 1] = buf[i]; } return le; }
|
||||
|
||||
public static short E(this short le)
|
||||
{ for (byte i = 0; i < 2; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
|
||||
for (byte i = 0; i < 2; i++) { le = (short)((int)le | buf[i]); if (i < 1) le <<= 8; } return le; }
|
||||
public static ushort E(this ushort le)
|
||||
{ for (byte i = 0; i < 2; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
|
||||
for (byte i = 0; i < 2; i++) { le |= buf[i]; if (i < 1) le <<= 8; } return le; }
|
||||
public static int E(this int le)
|
||||
{ for (byte i = 0; i < 4; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
|
||||
for (byte i = 0; i < 4; i++) { le |= buf[i]; if (i < 3) le <<= 8; } return le; }
|
||||
public static uint E(this uint le)
|
||||
{ for (byte i = 0; i < 4; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
|
||||
for (byte i = 0; i < 4; i++) { le |= buf[i]; if (i < 3) le <<= 8; } return le; }
|
||||
public static long E(this long le)
|
||||
{ for (byte i = 0; i < 8; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
|
||||
for (byte i = 0; i < 8; i++) { le |= buf[i]; if (i < 7) le <<= 8; } return le; }
|
||||
public static ulong E(this ulong le)
|
||||
{ for (byte i = 0; i < 8; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
|
||||
for (byte i = 0; i < 8; i++) { le |= buf[i]; if (i < 7) le <<= 8; } return le; }
|
||||
|
||||
public static short E(this short le, bool isBE)
|
||||
{ if (isBE) { for (byte i = 0; i < 2; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
|
||||
for (byte i = 0; i < 2; i++) { le = (short)((int)le | buf[i]); if (i < 1) le <<= 8; } } return le; }
|
||||
public static ushort E(this ushort le, bool isBE)
|
||||
{ if (isBE) { for (byte i = 0; i < 2; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
|
||||
for (byte i = 0; i < 2; i++) { le |= buf[i]; if (i < 1) le <<= 8; } } return le; }
|
||||
public static int E(this int le, bool isBE)
|
||||
{ if (isBE) { for (byte i = 0; i < 4; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
|
||||
for (byte i = 0; i < 4; i++) { le |= buf[i]; if (i < 3) le <<= 8; } } return le; }
|
||||
public static uint E(this uint le, bool isBE)
|
||||
{ if (isBE) { for (byte i = 0; i < 4; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
|
||||
for (byte i = 0; i < 4; i++) { le |= buf[i]; if (i < 3) le <<= 8; } } return le; }
|
||||
public static long E(this long le, bool isBE)
|
||||
{ if (isBE) { for (byte i = 0; i < 8; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
|
||||
for (byte i = 0; i < 8; i++) { le |= buf[i]; if (i < 7) le <<= 8; } } return le; }
|
||||
public static ulong E(this ulong le, bool isBE)
|
||||
{ if (isBE) { for (byte i = 0; i < 8; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
|
||||
for (byte i = 0; i < 8; i++) { le |= buf[i]; if (i < 7) le <<= 8; } } return le; }
|
||||
|
||||
public static sbyte TI8(this byte[] arr, int offset = 0)
|
||||
{ sbyte val; fixed (byte* ptr = arr) val = *( sbyte*)(ptr + offset); return val; }
|
||||
public static byte TU8(this byte[] arr, int offset = 0)
|
||||
{ byte val; fixed (byte* ptr = arr) val = *( byte*)(ptr + offset); return val; }
|
||||
public static short TI16(this byte[] arr, int offset = 0)
|
||||
{ short val; fixed (byte* ptr = arr) val = *( short*)(ptr + offset); return val; }
|
||||
public static ushort TU16(this byte[] arr, int offset = 0)
|
||||
{ ushort val; fixed (byte* ptr = arr) val = *(ushort*)(ptr + offset); return val; }
|
||||
public static int TI24(this byte[] arr, int offset = 0)
|
||||
{ int val; fixed (byte* ptr = arr) val = (*(ushort*)(ptr + offset))
|
||||
| ((( short)*(sbyte*)(ptr + offset + 2)) << 16); return val; }
|
||||
public static uint TU24(this byte[] arr, int offset = 0)
|
||||
{ uint val; fixed (byte* ptr = arr) val = (*(ushort*)(ptr + offset))
|
||||
| ((( uint)*( byte*)(ptr + offset + 2)) << 16); return val; }
|
||||
public static int TI32(this byte[] arr, int offset = 0)
|
||||
{ int val; fixed (byte* ptr = arr) val = *( int*)(ptr + offset); return val; }
|
||||
public static uint TU32(this byte[] arr, int offset = 0)
|
||||
{ uint val; fixed (byte* ptr = arr) val = *( uint*)(ptr + offset); return val; }
|
||||
public static long TI64(this byte[] arr, int offset = 0)
|
||||
{ long val; fixed (byte* ptr = arr) val = *( long*)(ptr + offset); return val; }
|
||||
public static ulong TU64(this byte[] arr, int offset = 0)
|
||||
{ ulong val; fixed (byte* ptr = arr) val = *( ulong*)(ptr + offset); return val; }
|
||||
public static Half TF16(this byte[] arr, int offset = 0)
|
||||
{ Half val; fixed (byte* ptr = arr) val = *( Half*)(ptr + offset); return val; }
|
||||
public static float TF32(this byte[] arr, int offset = 0)
|
||||
{ float val; fixed (byte* ptr = arr) val = *( float*)(ptr + offset); return val; }
|
||||
public static double TF64(this byte[] arr, int offset = 0)
|
||||
{ double val; fixed (byte* ptr = arr) val = *(double*)(ptr + offset); return val; }
|
||||
public static Vec2 TV2 (this byte[] arr, int offset = 0)
|
||||
{ Vec2 val; fixed (byte* ptr = arr) val = *( Vec2*)(ptr + offset); return val; }
|
||||
public static Vec3 TV3 (this byte[] arr, int offset = 0)
|
||||
{ Vec3 val; fixed (byte* ptr = arr) val = *( Vec3*)(ptr + offset); return val; }
|
||||
public static Vec4 TV4 (this byte[] arr, int offset = 0)
|
||||
{ Vec4 val; fixed (byte* ptr = arr) val = *( Vec4*)(ptr + offset); return val; }
|
||||
public static Quat TQ (this byte[] arr, int offset = 0)
|
||||
{ Quat val; fixed (byte* ptr = arr) val = *( Quat*)(ptr + offset); return val; }
|
||||
|
||||
public static void GBy(this byte[] arr, sbyte val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( sbyte*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, byte val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( byte*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, short val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( short*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, ushort val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *(ushort*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, int val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( int*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, uint val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( uint*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, long val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( long*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, ulong val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( ulong*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, Half val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( Half*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, float val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( float*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, double val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *(double*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, Vec2 val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( Vec2*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, Vec3 val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( Vec3*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, Vec4 val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( Vec4*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, Quat val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( Quat*)(ptr + offset) = val; }
|
||||
|
||||
public static sbyte CITSB(this int c)
|
||||
{ return ( sbyte)(c > 0x0000007F ?
|
||||
0x0000007F : c < -0x00000080 ? -0x00000080 : c); }
|
||||
public static byte CITB (this int c)
|
||||
{ return ( byte)(c > 0x000000FF ?
|
||||
0x000000FF : c < 0x00000000 ? 0x00000000 : c); }
|
||||
public static short CITS (this int c)
|
||||
{ return ( short)(c > 0x00007FFF ?
|
||||
0x00007FFF : c < -0x00008000 ? -0x00008000 : c); }
|
||||
public static ushort CITUS(this int c)
|
||||
{ return (ushort)(c > 0x0000FFFF ?
|
||||
0x0000FFFF : c < 0x00000000 ? 0x00000000 : c); }
|
||||
public static sbyte CFTSB(this float c)
|
||||
{ c = c.Round(); return ( sbyte)(c > 0x0000007F ?
|
||||
0x0000007F : c < -0x00000080 ? -0x00000080 : c); }
|
||||
public static byte CFTB (this float c)
|
||||
{ c = c.Round(); return ( byte)(c > 0x000000FF ?
|
||||
0x000000FF : c < 0x00000000 ? 0x00000000 : c); }
|
||||
public static short CFTS (this float c)
|
||||
{ c = c.Round(); return ( short)(c > 0x00007FFF ?
|
||||
0x00007FFF : c < -0x00008000 ? -0x00008000 : c); }
|
||||
public static ushort CFTUS(this float c)
|
||||
{ c = c.Round(); return (ushort)(c > 0x0000FFFF ?
|
||||
0x0000FFFF : c < 0x00000000 ? 0x00000000 : c); }
|
||||
public static sbyte CFTSB(this double c)
|
||||
{ c = c.Round(); return ( sbyte)(c > 0x0000007F ?
|
||||
0x0000007F : c < -0x00000080 ? -0x00000080 : c); }
|
||||
public static byte CFTB (this double c)
|
||||
{ c = c.Round(); return ( byte)(c > 0x000000FF ?
|
||||
0x000000FF : c < 0x00000000 ? 0x00000000 : c); }
|
||||
public static short CFTS (this double c)
|
||||
{ c = c.Round(); return ( short)(c > 0x00007FFF ?
|
||||
0x00007FFF : c < -0x00008000 ? -0x00008000 : c); }
|
||||
public static ushort CFTUS(this double c)
|
||||
{ c = c.Round(); return (ushort)(c > 0x0000FFFF ?
|
||||
0x0000FFFF : c < 0x00000000 ? 0x00000000 : c); }
|
||||
public static int CFTI (this double c)
|
||||
{ c = c.Round(); return ( int)(c > 0x7FFFFFFF ?
|
||||
0x7FFFFFFF : c < -0x80000000 ? -0x80000000 : c); }
|
||||
public static uint CFTUI(this double c)
|
||||
{ c = c.Round(); return ( uint)(c > 0xFFFFFFFF ?
|
||||
0xFFFFFFFF : c < 0xFFFFFFFF ? 0x00000000 : c); }
|
||||
|
||||
public static int ToI32(this float f) => *( int*)&f;
|
||||
public static uint ToU32(this float f) => *( uint*)&f;
|
||||
public static long ToI64(this double f) => *( long*)&f;
|
||||
public static ulong ToU64(this double f) => *(ulong*)&f;
|
||||
|
||||
public static float ToF32(this int i) => *( float*)&i;
|
||||
public static float ToF32(this uint i) => *( float*)&i;
|
||||
public static double ToF64(this long i) => *(double*)&i;
|
||||
public static double ToF64(this ulong i) => *(double*)&i;
|
||||
|
||||
public static string ToS(this int d, bool BE) =>
|
||||
BitConverter.GetBytes(d.E(BE)).ToASCII();
|
||||
|
||||
public static string ToS(this uint d, bool BE) =>
|
||||
BitConverter.GetBytes(d.E(BE)).ToASCII();
|
||||
|
||||
public static string ToS(this object d)
|
||||
{
|
||||
if (d == null ) return "Null";
|
||||
else if (d is bool boolean) return boolean ? "true" : "false";
|
||||
else if (d is float f32 ) return ToS(f32);
|
||||
else if (d is double f64 ) return ToS(f64);
|
||||
return d.ToString();
|
||||
}
|
||||
|
||||
private static readonly string NDS =
|
||||
System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
|
||||
|
||||
public static string ToS(this bool? d) => (d ?? default).ToString();
|
||||
public static string ToS(this bool d) => d.ToString().ToLower();
|
||||
public static string ToS(this sbyte? d) => (d ?? default).ToString();
|
||||
public static string ToS(this sbyte d) => d.ToString();
|
||||
public static string ToS(this byte? d) => (d ?? default).ToString();
|
||||
public static string ToS(this byte d) => d.ToString();
|
||||
public static string ToS(this short? d) => (d ?? default).ToString();
|
||||
public static string ToS(this short d) => d.ToString();
|
||||
public static string ToS(this ushort? d) => (d ?? default).ToString();
|
||||
public static string ToS(this ushort d) => d.ToString();
|
||||
public static string ToS(this int? d) => (d ?? default).ToString();
|
||||
public static string ToS(this int d) => d.ToString();
|
||||
public static string ToS(this uint? d) => (d ?? default).ToString();
|
||||
public static string ToS(this uint d) => d.ToString();
|
||||
public static string ToS(this long? d) => (d ?? default).ToString();
|
||||
public static string ToS(this long d) => d.ToString();
|
||||
public static string ToS(this ulong? d) => (d ?? default).ToString();
|
||||
public static string ToS(this ulong d) => d.ToString();
|
||||
public static string ToS(this float? d, int round) => (d ?? default).ToS(round);
|
||||
public static string ToS(this float? d) => (d ?? default).ToS(15);
|
||||
public static string ToS(this float d, int round)
|
||||
{ string s = (d.ToU32() & 0x80000000) != 0 ? "-" : ""; d = (d.ToU32() & 0x7FFFFFFF).ToF32();
|
||||
return s + Math.Round(d, round).ToString().ToLower().Replace(NDS, "."); }
|
||||
public static string ToS(this float d)
|
||||
{ string s = (d.ToU32() & 0x80000000) != 0 ? "-" : ""; d = (d.ToU32() & 0x7FFFFFFF).ToF32();
|
||||
return s + Math.Round(d, 15).ToString().ToLower().Replace(NDS, "."); }
|
||||
public static string ToS(this double? d, int round) => (d ?? default).ToS(round);
|
||||
public static string ToS(this double? d) => (d ?? default).ToS();
|
||||
public static string ToS(this double d, int round)
|
||||
{ string s = (d.ToU64() & 0x8000000000000000) != 0 ? "-" : ""; d = (d.ToU64() & 0x7FFFFFFFFFFFFFFF).ToF64();
|
||||
return s + Math.Round(d, round).ToString().ToLower().Replace(NDS, "."); }
|
||||
public static string ToS(this double d)
|
||||
{ string s = (d.ToU64() & 0x8000000000000000) != 0 ? "-" : ""; d = (d.ToU64() & 0x7FFFFFFFFFFFFFFF).ToF64();
|
||||
return s + Math.Round(d, 15).ToString().ToLower().Replace(NDS, "."); }
|
||||
public static float ToF32(this string s)
|
||||
{ if (s.Length < 1) return 0; uint d = 0; if (s[0] == '-') d = 0x80000000;
|
||||
d |= float.Parse(s.Replace(".", NDS)).ToU32(); return d.ToF32(); }
|
||||
public static double ToF64(this string s)
|
||||
{ if (s.Length < 1) return 0; ulong d = 0; if (s[0] == '-') d = 0x8000000000000000;
|
||||
d |= double.Parse(s.Replace(".", NDS)).ToU64(); return d.ToF64(); }
|
||||
public static bool ToF32(this string s, out float val)
|
||||
{ val = 0; if (s.Length < 1) return false; uint d = 0; if (s[0] == '-') d = 0x80000000;
|
||||
bool b = float.TryParse(s.Replace(".", NDS), out val); if (b) val = (d | val.ToU32()).ToF32(); return b; }
|
||||
public static bool ToF64(this string s, out double val)
|
||||
{ val = 0; if (s.Length < 1) return false; ulong d = 0; if (s[0] == '-') d = 0x8000000000000000;
|
||||
bool b = double.TryParse(s.Replace(".", NDS), out val); if (b) val = (d | val.ToU64()).ToF64(); return b; }
|
||||
public static bool ToF32(this string s, out float? val)
|
||||
{ val = null; if (s.Length < 1) return false; uint d = 0; if (s[0] == '-') d = 0x80000000;
|
||||
bool b = float.TryParse(s.Replace(".", NDS), out float t); if (b) val = (d | t.ToU32()).ToF32(); return b; }
|
||||
public static bool ToF64(this string s, out double? val)
|
||||
{ val = null; if (s.Length < 1) return false; ulong d = 0; if (s[0] == '-') d = 0x8000000000000000;
|
||||
bool b = double.TryParse(s.Replace(".", NDS), out double t); if (b) val = (d | t.ToU64()).ToF64(); return b; }
|
||||
|
||||
public static T[] ReverseEndian<T>(this T[] a)
|
||||
{
|
||||
if (a == null || a.Length < 1) return a;
|
||||
|
||||
int length = a.Length;
|
||||
T[] b = new T[length];
|
||||
for (int i = 0; i < length; i++)
|
||||
b[i] = (T)ReverseEndian(a[i]);
|
||||
return b;
|
||||
}
|
||||
|
||||
public static object ReverseEndian(this object a)
|
||||
{
|
||||
object c = default;
|
||||
System.Reflection.FieldInfo[] d = a.GetType().GetFields();
|
||||
foreach (System.Reflection.FieldInfo field in d)
|
||||
{
|
||||
object e = field.GetValue(a);
|
||||
Type t = field.FieldType;
|
||||
if (t == typeof( short)) e = (( short)e).E();
|
||||
else if (t == typeof(ushort)) e = ((ushort)e).E();
|
||||
else if (t == typeof( int)) e = (( int)e).E();
|
||||
else if (t == typeof( uint)) e = (( uint)e).E();
|
||||
else if (t == typeof( long)) e = (( long)e).E();
|
||||
else if (t == typeof( ulong)) e = (( ulong)e).E();
|
||||
else if (t == typeof( float)) e = (( float)e).ToI32().E().ToF32();
|
||||
else if (t == typeof(double)) e = ((double)e).ToI64().E().ToF64();
|
||||
else if (t == typeof( Half)) e = (Half)((ushort)(Half)e).E();
|
||||
else e = ReverseEndian(e);
|
||||
field.SetValue(a, e);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
namespace KKdBaseLib.F2
|
||||
{
|
||||
public struct ENRS : INull
|
||||
{
|
||||
public ENRSEntry[] Array;
|
||||
|
||||
public int Length => length();
|
||||
|
||||
public bool IsNull => Array == null;
|
||||
public bool NotNull => Array != null;
|
||||
|
||||
public unsafe void Read(byte[] data)
|
||||
{
|
||||
if (data == null || data.Length < 0x10) return;
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
int i, i0;
|
||||
int ENRSCount = ((int*)ptr)[1];
|
||||
ENRSEntry enrsEntry;
|
||||
ENRSEntry.SubENRSEntry sub;
|
||||
Array = new ENRSEntry[ENRSCount];
|
||||
|
||||
byte* localPtr = ptr + 0x10;
|
||||
for (i = 0; i < ENRSCount; i++)
|
||||
{
|
||||
enrsEntry = default;
|
||||
if (ReadENRSValue(ref localPtr, out enrsEntry.Offset)) return;
|
||||
if (ReadENRSValue(ref localPtr, out enrsEntry.Count )) return;
|
||||
if (ReadENRSValue(ref localPtr, out enrsEntry.Size )) return;
|
||||
if (ReadENRSValue(ref localPtr, out enrsEntry.Repeat)) return;
|
||||
|
||||
if (enrsEntry.Repeat < 1) { enrsEntry.Sub = null; Array[i] = enrsEntry; continue; }
|
||||
|
||||
enrsEntry.Sub = new ENRSEntry.SubENRSEntry[enrsEntry.Count];
|
||||
for (i0 = 0; i0 < enrsEntry.Count; i0++)
|
||||
{
|
||||
sub = default;
|
||||
if (ReadENRSValue(ref localPtr, out sub.Skip, out sub.Type)) return;
|
||||
if (ReadENRSValue(ref localPtr, out sub.Reverse )) return;
|
||||
enrsEntry.Sub[i0] = sub;
|
||||
|
||||
if (enrsEntry.Sub[i0].Type == ENRSEntry.Type.Invalid) { Array = null; return; }
|
||||
}
|
||||
Array[i] = enrsEntry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe byte[] Write()
|
||||
{
|
||||
int i, i0;
|
||||
byte[] data;
|
||||
|
||||
if (IsNull || Array.Length < 1) return new byte[0x20];
|
||||
|
||||
data = new byte[Length];
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
((int*)ptr)[1] = Array.Length;
|
||||
|
||||
byte* localPtr = ptr + 0x10;
|
||||
for (i = 0; i < Array.Length; i++)
|
||||
{
|
||||
ENRSEntry enrsEntry = Array[i];
|
||||
if (WriteENRSValue(ref localPtr, enrsEntry.Offset)) goto End;
|
||||
if (WriteENRSValue(ref localPtr, enrsEntry.Count )) goto End;
|
||||
if (WriteENRSValue(ref localPtr, enrsEntry.Size )) goto End;
|
||||
if (WriteENRSValue(ref localPtr, enrsEntry.Repeat)) goto End;
|
||||
|
||||
if (enrsEntry.Repeat < 1) continue;
|
||||
|
||||
for (i0 = 0; i0 < enrsEntry.Count && i0 < enrsEntry.Sub.Length; i0++)
|
||||
{
|
||||
if (enrsEntry.Sub[i0].Type > ENRSEntry.Type.QWORD)
|
||||
return data;
|
||||
|
||||
if (WriteENRSValue(ref localPtr, enrsEntry.Sub[i0].Skip, enrsEntry.Sub[i0].Type)) goto End;
|
||||
if (WriteENRSValue(ref localPtr, enrsEntry.Sub[i0].Reverse )) goto End;
|
||||
}
|
||||
}
|
||||
}
|
||||
End:
|
||||
return data;
|
||||
}
|
||||
|
||||
private int length()
|
||||
{
|
||||
if (Array == null)
|
||||
return 0;
|
||||
|
||||
int i, i0;
|
||||
int length = 0x10;
|
||||
for (i = 0; i < Array.Length; i++)
|
||||
{
|
||||
ENRSEntry enrs = Array[i];
|
||||
if (GetSize(enrs.Offset, ref length)) goto End;
|
||||
if (GetSize(enrs.Count , ref length)) goto End;
|
||||
if (GetSize(enrs.Size , ref length)) goto End;
|
||||
if (GetSize(enrs.Repeat, ref length)) goto End;
|
||||
|
||||
if (enrs.Repeat < 1) continue;
|
||||
|
||||
for (i0 = 0; i0 < enrs.Count; i0++)
|
||||
{
|
||||
if (enrs.Sub[i0].Type < ENRSEntry.Type. WORD ||
|
||||
enrs.Sub[i0].Type > ENRSEntry.Type.QWORD) return length.A(0x10);
|
||||
|
||||
if (GetSizeType(enrs.Sub[i0].Skip , ref length)) goto End;
|
||||
if (GetSize (enrs.Sub[i0].Reverse, ref length)) goto End;
|
||||
}
|
||||
}
|
||||
End:
|
||||
return length.A(0x10);
|
||||
|
||||
static bool GetSizeType(int val, ref int length)
|
||||
{
|
||||
length += val < 0x00000010 ? 1 : val < 0x00001000 ? 2 : val < 0x10000000 ? 4 : 1;
|
||||
return val >= 0x10000000;
|
||||
}
|
||||
|
||||
static bool GetSize (int val, ref int length)
|
||||
{
|
||||
length += val < 0x00000040 ? 1 : val < 0x00004000 ? 2 : val < 0x40000000 ? 4 : 1;
|
||||
return val >= 0x40000000;
|
||||
}
|
||||
}
|
||||
|
||||
/*private static KKdList<ENRS.SubENRS> Optimize(KKdList<ENRS.SubENRS> Sub)
|
||||
{
|
||||
if (Sub.IsNull || Sub.Count < 2) return Sub;
|
||||
|
||||
for (int i = 1; i < Sub.Capacity; i++)
|
||||
if (Sub[i - 1].Skip == Sub[i].Skip - Sub[i - 1].Size && Sub[i - 1].Type == Sub[i].Type)
|
||||
{
|
||||
ENRS.SubENRS SubENRS = Sub[i - 1];
|
||||
SubENRS.Reverse++;
|
||||
Sub[i - 1] = SubENRS;
|
||||
Sub.RemoveAt(i);
|
||||
Sub.Capacity--;
|
||||
i--;
|
||||
}
|
||||
return Sub;
|
||||
}*/
|
||||
|
||||
[System.ThreadStatic] private static ENRSEntry.Value value;
|
||||
|
||||
private unsafe static bool ReadENRSValue(ref byte* ptr, out int v, out ENRSEntry.Type type)
|
||||
{
|
||||
v = *ptr & 0xF;
|
||||
type = (ENRSEntry. Type)((*ptr & 0x30) >> 4);
|
||||
value = (ENRSEntry.Value)((*ptr & 0xC0) >> 6);
|
||||
ptr++;
|
||||
if (value == ENRSEntry.Value.Int32 ) v = (((((v << 8) | *ptr++) << 8) | *ptr++) << 8) | *ptr++;
|
||||
else if (value == ENRSEntry.Value.Int16 ) v = (v << 8) | *ptr++;
|
||||
else if (value == ENRSEntry.Value.Invalid) { v = 0; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
private unsafe static bool ReadENRSValue(ref byte* ptr, out int v)
|
||||
{
|
||||
v = *ptr & 0x3F;
|
||||
value = (ENRSEntry.Value)((*ptr & 0xC0) >> 6);
|
||||
ptr++;
|
||||
if (value == ENRSEntry.Value.Int32 ) v = (((((v << 8) | *ptr++) << 8) | *ptr++) << 8) | *ptr++;
|
||||
else if (value == ENRSEntry.Value.Int16 ) v = (v << 8) | *ptr++;
|
||||
else if (value == ENRSEntry.Value.Invalid) { v = 0; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
private unsafe static bool WriteENRSValue(ref byte* ptr, int val, ENRSEntry.Type type)
|
||||
{
|
||||
byte t = (byte)(((byte)type & 0x3) << 4);
|
||||
if (val < 0x00000010)
|
||||
*ptr++ = (byte)(((byte)ENRSEntry.Value.Int8 << 6) | t | ( val & 0xF));
|
||||
else if (val < 0x00001000)
|
||||
{
|
||||
*ptr++ = (byte)(((byte)ENRSEntry.Value.Int16 << 6) | t | ((val >> 8) & 0xF));
|
||||
*ptr++ = (byte)(val & 0xFF);
|
||||
}
|
||||
else if (val < 0x10000000)
|
||||
{
|
||||
*ptr++ = (byte)(((byte)ENRSEntry.Value.Int32 << 6) | t | ((val >> 24) & 0xF));
|
||||
*ptr++ = (byte)((val >> 16) & 0xFF);
|
||||
*ptr++ = (byte)((val >> 8) & 0xFF);
|
||||
*ptr++ = (byte)( val & 0xFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr++ = (byte)ENRSEntry.Value.Invalid << 6;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private unsafe static bool WriteENRSValue(ref byte* ptr, int val)
|
||||
{
|
||||
if (val < 0x00000040)
|
||||
*ptr++ = (byte)(((byte)ENRSEntry.Value.Int8 << 6) | ( val & 0x3F));
|
||||
else if (val < 0x00004000)
|
||||
{
|
||||
*ptr++ = (byte)(((byte)ENRSEntry.Value.Int16 << 6) | ((val >> 8) & 0x3F));
|
||||
*ptr++ = (byte)(val & 0xFF);
|
||||
}
|
||||
else if (val < 0x40000000)
|
||||
{
|
||||
*ptr++ = (byte)(((byte)ENRSEntry.Value.Int32 << 6) | ((val >> 24) & 0x3F));
|
||||
*ptr++ = (byte)((val >> 16) & 0xFF);
|
||||
*ptr++ = (byte)((val >> 8) & 0xFF);
|
||||
*ptr++ = (byte)( val & 0xFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr++ = (byte)ENRSEntry.Value.Invalid << 6;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public struct ENRSEntry
|
||||
{
|
||||
public int Offset;
|
||||
public int Count;
|
||||
public int Size;
|
||||
public int Repeat;
|
||||
public SubENRSEntry[] Sub;
|
||||
|
||||
public ENRSEntry(int offset, int count, int size, int repeat)
|
||||
{ Offset = offset; Count = count; Size = size; Repeat = repeat; Sub = new SubENRSEntry[count]; }
|
||||
|
||||
public enum Type : byte
|
||||
{
|
||||
WORD = 0b00,
|
||||
DWORD = 0b01,
|
||||
QWORD = 0b10,
|
||||
Invalid = 0b11,
|
||||
}
|
||||
|
||||
public enum Value : byte
|
||||
{
|
||||
Int8 = 0b00,
|
||||
Int16 = 0b01,
|
||||
Int32 = 0b10,
|
||||
Invalid = 0b11,
|
||||
}
|
||||
|
||||
public struct SubENRSEntry
|
||||
{
|
||||
public int Skip;
|
||||
public int Reverse;
|
||||
public Type Type;
|
||||
|
||||
public SubENRSEntry(int skip, int reverse, Type type)
|
||||
{ Skip = skip; Reverse = reverse; Type = type; }
|
||||
|
||||
public int SizeSkip => Skip + Reverse * (2 << (byte)Type);
|
||||
public int Size => Reverse * (2 << (byte)Type);
|
||||
|
||||
public override string ToString() =>
|
||||
$"Skip: {Skip}; Reverse: {Reverse}; Type: {Type}";
|
||||
}
|
||||
|
||||
public override string ToString() =>
|
||||
$"Offset: {Offset}; Count: {Count}; Size: {Size}; Repeat: {Repeat}";
|
||||
}
|
||||
|
||||
public override string ToString() =>
|
||||
$"{(NotNull ? $"ENRS Count: {Array.Length}" : "No ENRS")}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace KKdBaseLib.F2
|
||||
{
|
||||
public struct Header
|
||||
{
|
||||
public uint Signature; // 0x00
|
||||
public uint DataSize; // 0x04
|
||||
public uint Length; // 0x08
|
||||
public uint Flags; // 0x0C
|
||||
public uint Depth; // 0x10
|
||||
public uint SectionSize; // 0x14
|
||||
public uint Version; // 0x18
|
||||
public uint InnerSignature; // 0x30
|
||||
|
||||
public Format Format;
|
||||
public bool UseBigEndian;
|
||||
public bool UseSectionSize;
|
||||
|
||||
public bool IsX => Format == Format.X || Format == Format.XHD;
|
||||
|
||||
public override string ToString() => Signature.ToS(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
namespace KKdBaseLib.F2
|
||||
{
|
||||
public struct POF : INull
|
||||
{
|
||||
public KKdList<long> Offsets;
|
||||
|
||||
public bool IsNull => Offsets. IsNull;
|
||||
public bool NotNull => Offsets.NotNull;
|
||||
|
||||
public int Length => length(false).A(0x10);
|
||||
public int LengthX => length( true).A(0x10);
|
||||
|
||||
public unsafe void Read(byte[] data, bool shiftX)
|
||||
{
|
||||
Offsets = KKdList<long>.New;
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
long offset = 0;
|
||||
int i = 0, j = 0, v = 0;
|
||||
byte bitShift = (byte)(shiftX ? 3 : 2);
|
||||
|
||||
int length = *(int*)ptr - 4;
|
||||
byte* l = ptr + 4;
|
||||
Offsets.Capacity = length;
|
||||
while (length > i)
|
||||
{
|
||||
if (ReadPOFValue(ref l, out v)) break;
|
||||
j++;
|
||||
offset += v;
|
||||
Offsets.Add(offset << bitShift);
|
||||
}
|
||||
Offsets.Capacity = j;
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe byte[] Write(bool shiftX)
|
||||
{
|
||||
Offsets.Sort();
|
||||
long j, k, o;
|
||||
byte bitShift, v;
|
||||
bitShift = (byte)(shiftX ? 3 : 2);
|
||||
v = (byte)((1 << bitShift) - 1);
|
||||
|
||||
j = 0;
|
||||
byte[] data = new byte[length(shiftX)];
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
*(int*)ptr = length(shiftX);
|
||||
byte* l = ptr + 4;
|
||||
for (int i = 0; i < Offsets.Count; i++)
|
||||
{
|
||||
o = Offsets[i];
|
||||
if ((o & v) != 0)
|
||||
{
|
||||
WritePOFValue(ref l, 0x7FFFFFFF);
|
||||
break;
|
||||
}
|
||||
|
||||
k = o - j;
|
||||
if (i > 0 & k == 0)
|
||||
continue;
|
||||
j = o;
|
||||
o = k;
|
||||
WritePOFValue(ref l, o >> bitShift);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
[System.ThreadStatic] private static Value value;
|
||||
|
||||
private unsafe static bool ReadPOFValue(ref byte* ptr, out int v)
|
||||
{
|
||||
v = *ptr & 0x3F;
|
||||
value = (Value)((*ptr & 0xC0) >> 6);
|
||||
ptr++;
|
||||
if (value == Value.Int32 ) v = (((((v << 8) | *ptr++) << 8) | *ptr++) << 8) | *ptr++;
|
||||
else if (value == Value.Int16 ) v = (v << 8) | *ptr++;
|
||||
else if (value == Value.Invalid) { v = 0; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
private unsafe static bool WritePOFValue(ref byte* ptr, long val)
|
||||
{
|
||||
if (val < 0x00000040)
|
||||
*ptr++ = (byte)(((byte)Value.Int8 << 6) | ( val & 0x3F));
|
||||
else if (val < 0x00004000)
|
||||
{
|
||||
*ptr++ = (byte)(((byte)Value.Int16 << 6) | ((val >> 8) & 0x3F));
|
||||
*ptr++ = (byte)(val & 0xFF);
|
||||
}
|
||||
else if (val < 0x40000000)
|
||||
{
|
||||
*ptr++ = (byte)(((byte)Value.Int32 << 6) | ((val >> 24) & 0x3F));
|
||||
*ptr++ = (byte)((val >> 16) & 0xFF);
|
||||
*ptr++ = (byte)((val >> 8) & 0xFF);
|
||||
*ptr++ = (byte)( val & 0xFF);
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr++ = (byte)Value.Invalid << 6;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int length(bool shiftX = false)
|
||||
{
|
||||
if (Offsets.IsNull)
|
||||
return 0;
|
||||
|
||||
int length = 4;
|
||||
long offset = 0;
|
||||
byte bitShift = (byte)(shiftX ? 3 : 2);
|
||||
int max1 = 0x00000040;
|
||||
int max2 = 0x00004000;
|
||||
int max3 = 0x40000000;
|
||||
for (int i = 0; i < Offsets.Count; i++)
|
||||
{
|
||||
offset = Offsets[i];
|
||||
if (i > 0) { offset -= Offsets[i - 1]; if (offset == 0) continue; }
|
||||
|
||||
offset >>= bitShift;
|
||||
if (offset < max1) length += 1;
|
||||
else if (offset < max2) length += 2;
|
||||
else if (offset < max3) length += 4;
|
||||
else length += 1;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
public enum Value : byte
|
||||
{
|
||||
Invalid = 0b00,
|
||||
Int8 = 0b01,
|
||||
Int16 = 0b10,
|
||||
Int32 = 0b11,
|
||||
}
|
||||
|
||||
public override string ToString() =>
|
||||
$"{(NotNull ? $"Offsets Count: {Offsets.Count}" : "No POF")}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
namespace KKdBaseLib.F2
|
||||
{
|
||||
public struct Struct
|
||||
{
|
||||
public Header Header;
|
||||
public byte[] Data;
|
||||
public Struct[] SubStructs;
|
||||
|
||||
public ENRS ENRS;
|
||||
public POF POF;
|
||||
|
||||
public uint Length => length(false);
|
||||
public uint LengthX => length( true);
|
||||
|
||||
public bool HasPOF => POF .NotNull;
|
||||
public bool HasENRS => ENRS.NotNull;
|
||||
public bool HasSubStructs => SubStructs != null;
|
||||
|
||||
public long DataOffset;
|
||||
|
||||
public void Update(bool shiftX = false)
|
||||
{
|
||||
Header.SectionSize = Data != null ? (uint)Data.Length : 0;
|
||||
Header.DataSize = length(shiftX);
|
||||
}
|
||||
|
||||
private uint length(bool shiftX = false)
|
||||
{
|
||||
uint length = Data != null ? (uint)Data.Length : 0;
|
||||
if (HasPOF ) length += 0x20 + (uint)(shiftX ? POF.LengthX : POF.Length);
|
||||
if (HasENRS) length += 0x20 + (uint)ENRS.Length;
|
||||
if (HasSubStructs)
|
||||
for (int i = 0; i < SubStructs.Length; i++)
|
||||
length += (uint)(shiftX ? SubStructs[i].LengthX : SubStructs[i].Length)
|
||||
+ SubStructs[i].Header.Length;
|
||||
if (HasPOF || HasENRS || HasSubStructs)
|
||||
length += 0x20;
|
||||
return length;
|
||||
}
|
||||
|
||||
public override string ToString() => $"{Header}" +
|
||||
$"{(HasSubStructs ? $"; SubStructs: {SubStructs.Length}" : "")}" +
|
||||
$"{(HasENRS ? "; Has ENRS" : "")}{(HasPOF ? "; Has POF" : "")}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public enum Format : byte
|
||||
{
|
||||
NULL = 0,
|
||||
DT = 1,
|
||||
PDA = 2,
|
||||
DT2 = 3,
|
||||
DTe = 4,
|
||||
F = 5,
|
||||
AFT = 6,
|
||||
F2 = 7,
|
||||
MGF = 8,
|
||||
X = 9,
|
||||
XHD = 10,
|
||||
FT = 11,
|
||||
M39 = 12,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct Half : IFormattable
|
||||
{
|
||||
private ushort value;
|
||||
|
||||
public static Half NaN => new Half { value = 0x7FFF };
|
||||
public static Half PositiveNaN => new Half { value = 0x7FFF };
|
||||
public static Half NegativeNaN => new Half { value = 0xFFFF };
|
||||
public static Half PositiveZero => new Half { value = 0x0000 };
|
||||
public static Half NegativeZero => new Half { value = 0x8000 };
|
||||
public static Half PositiveInfinity => new Half { value = 0x7C00 };
|
||||
public static Half NegativeInfinity => new Half { value = 0xFC00 };
|
||||
|
||||
public static explicit operator Half(ushort bits) => new Half() { value = bits };
|
||||
|
||||
public static explicit operator ushort(Half bits) => bits.value;
|
||||
|
||||
public static unsafe implicit operator float(Half h)
|
||||
{
|
||||
int si32;
|
||||
int sign = (h.value >> 15) & 0x001;
|
||||
int exponent = (h.value >> 10) & 0x01F;
|
||||
int mantissa = h.value & 0x3FF;
|
||||
unchecked { si32 = sign != 0 ? (int)0x80000000 : 0x00000000; }
|
||||
|
||||
if (exponent == 0x1F) si32 |= 0x7F800000;
|
||||
else if (exponent != 0x00) si32 |= (exponent - 15 + 127) << 23;
|
||||
si32 |= mantissa << 13;
|
||||
return *(float*)&si32;
|
||||
}
|
||||
|
||||
public static unsafe explicit operator Half(float val)
|
||||
{
|
||||
int si32 = *(int*)&val;
|
||||
if ( si32 == 0x00000000) return new Half { value = 0x0000 };
|
||||
else if ((uint)si32 == 0x80000000) return new Half { value = 0x8000 };
|
||||
else
|
||||
{
|
||||
ushort sign = (ushort)((si32 >> 31) & 0x001);
|
||||
ushort exponent = (ushort)((si32 >> 23) & 0x0FF);
|
||||
ushort mantissa = (ushort)((si32 >> 13) & 0x3FF);
|
||||
|
||||
if (exponent == 0xFF) exponent = 31;
|
||||
else if (exponent != 0x00)
|
||||
{
|
||||
exponent -= 127 - 15;
|
||||
if (exponent < 0) exponent = mantissa = 0;
|
||||
else if (exponent > 30) exponent = 31;
|
||||
}
|
||||
return new Half { value = (ushort)((sign << 15) | (exponent << 10) | mantissa) };
|
||||
}
|
||||
}
|
||||
|
||||
public static unsafe implicit operator double(Half h)
|
||||
{
|
||||
long si64;
|
||||
long sign = (h.value >> 15) & 0x001;
|
||||
long exponent = (h.value >> 10) & 0x01F;
|
||||
long mantissa = h.value & 0x3FF;
|
||||
unchecked { si64 = sign != 0 ? (long)0x8000000000000000 : 0x0000000000000000; }
|
||||
|
||||
if (exponent == 0x1F) si64 |= 0x7FF0000000000000;
|
||||
else if (exponent != 0x00) si64 |= (exponent - 15 + 1023) << 52;
|
||||
si64 |= mantissa << 42;
|
||||
return *(double*)&si64;
|
||||
}
|
||||
|
||||
public static unsafe explicit operator Half(double val)
|
||||
{
|
||||
long si64 = *(long*)&val;
|
||||
if ( si64 == 0x0000000000000000) return new Half { value = 0x0000 };
|
||||
else if ((ulong)si64 == 0x8000000000000000) return new Half { value = 0x8000 };
|
||||
else
|
||||
{
|
||||
ushort sign = (ushort)((si64 >> 63) & 0x001);
|
||||
ushort exponent = (ushort)((si64 >> 52) & 0x7FF);
|
||||
ushort mantissa = (ushort)((si64 >> 42) & 0x3FF);
|
||||
|
||||
if (exponent == 0x7FF) exponent = 31;
|
||||
else if (exponent != 0x00)
|
||||
{
|
||||
exponent -= 1023 - 15;
|
||||
if (exponent < 0) exponent = mantissa = 0;
|
||||
else if (exponent > 30) exponent = 31;
|
||||
}
|
||||
return new Half { value = (ushort)((sign << 15) | (exponent << 10) | mantissa) };
|
||||
}
|
||||
}
|
||||
|
||||
public static Half operator - (Half a ) => new Half() { value = (ushort)(a.value ^ 0x8000) };
|
||||
public static Half operator + (Half a, Half b) => (Half)((float)a + (float)b);
|
||||
public static Half operator - (Half a, Half b) => (Half)((float)a - (float)b);
|
||||
public static Half operator * (Half a, Half b) => (Half)((float)a * (float)b);
|
||||
public static Half operator / (Half a, Half b) => (Half)((float)a / (float)b);
|
||||
public static bool operator > (Half a, Half b) => (float)a > (float)b;
|
||||
public static bool operator < (Half a, Half b) => (float)a < (float)b;
|
||||
public static bool operator >=(Half a, Half b) => (float)a >= (float)b;
|
||||
public static bool operator <=(Half a, Half b) => (float)a <= (float)b;
|
||||
public static bool operator ==(Half a, Half b) => (float)a == (float)b;
|
||||
public static bool operator !=(Half a, Half b) => (float)a != (float)b;
|
||||
|
||||
public int CompareTo(object obj) => CompareTo((Half)obj);
|
||||
public int CompareTo(Half h) => this == h ? 0 : (this > h ? 1 : -1);
|
||||
public bool Equals(Half other) => this == other;
|
||||
public override bool Equals(object obj) => base.Equals(obj);
|
||||
public override string ToString() => Extensions.ToS((double)this);
|
||||
public string ToString(string format, IFormatProvider formatProvider) =>
|
||||
((float)this).ToString(format, formatProvider);
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public interface IKF
|
||||
{
|
||||
KFT0 ToT0();
|
||||
KFT1 ToT1();
|
||||
KFT2 ToT2();
|
||||
KFT3 ToT3();
|
||||
|
||||
IKF Check();
|
||||
string ToString();
|
||||
string ToString(int round, bool brackets);
|
||||
string ToString(bool brackets, int round);
|
||||
}
|
||||
|
||||
public interface INull
|
||||
{
|
||||
bool IsNull { get; }
|
||||
bool NotNull { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
using KKdBaseLib.Auth3D;
|
||||
|
||||
namespace KKdBaseLib.Interpolation
|
||||
{
|
||||
public class A3DAI : IInterpolation<float>, System.IDisposable // A3DA Interpolation
|
||||
{
|
||||
private A3DAKey a3daKey;
|
||||
|
||||
private float f;
|
||||
private float t;
|
||||
private float v;
|
||||
private float df;
|
||||
private float @if;
|
||||
private float rf;
|
||||
|
||||
private KFT3 firstKey;
|
||||
private KFT3 lastKey;
|
||||
|
||||
public float RequestedFramerate { get => rf; set { rf = value; df = @if / rf; } }
|
||||
|
||||
public float Frame => f;
|
||||
public float Time => t;
|
||||
public float Value => v;
|
||||
public bool IsNull => a3daKey.Keys == null || a3daKey.Length < 1;
|
||||
public bool NotNull => a3daKey.Keys != null && a3daKey.Length > 0;
|
||||
|
||||
public A3DAI(Key key, float a3daFramerate = 60, float requestedFramerate = 60)
|
||||
{
|
||||
a3daKey = new A3DAKey(key); f = -1; df = @if = rf = t = v = 0;
|
||||
@if = a3daFramerate;
|
||||
firstKey = lastKey = default;
|
||||
RequestedFramerate = requestedFramerate;
|
||||
f = -df;
|
||||
ResetFrameCount();
|
||||
|
||||
if (key.Keys != null && key.Keys.Length > 0)
|
||||
{
|
||||
firstKey = key.Keys[0];
|
||||
lastKey = key.Keys[key.Keys.Length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
public A3DAI(A3DAKey key, float a3daFramerate = 60, float requestedFramerate = 60)
|
||||
{
|
||||
t = 0;
|
||||
a3daKey = key; f = -1; df = v = rf = @if = 0;
|
||||
@if = a3daFramerate;
|
||||
firstKey = lastKey = default;
|
||||
RequestedFramerate = requestedFramerate;
|
||||
f = -df;
|
||||
ResetFrameCount();
|
||||
|
||||
if (key.Keys != null && key.Length > 0)
|
||||
{
|
||||
firstKey = key.Keys[0];
|
||||
lastKey = key.Keys[key.Length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
public float SetTime(float time)
|
||||
{
|
||||
t = time;
|
||||
f = time * @if;
|
||||
|
||||
int type = (int)a3daKey.Type;
|
||||
if (type < 0 || type > 4) v = 0.0f;
|
||||
else if (type < 2) v = a3daKey.Value;
|
||||
else if (a3daKey.Length < 1) v = 0.0f;
|
||||
else v = Interpolate(f);
|
||||
return v;
|
||||
}
|
||||
|
||||
public float SetFrame(float frame)
|
||||
{
|
||||
t = frame / rf;
|
||||
f = frame * df;
|
||||
|
||||
int type = (int)a3daKey.Type;
|
||||
if (type < 0 || type > 4) v = 0.0f;
|
||||
else if (type < 2) v = a3daKey.Value;
|
||||
else if (a3daKey.Length < 1) v = 0.0f;
|
||||
else v = Interpolate(f);
|
||||
return v;
|
||||
}
|
||||
|
||||
public float NextFrame(float time)
|
||||
{
|
||||
t += time;
|
||||
f = t * @if;
|
||||
|
||||
int type = (int)a3daKey.Type;
|
||||
if (type < 0 || type > 4) v = 0.0f;
|
||||
else if (type < 2) v = a3daKey.Value;
|
||||
else if (a3daKey.Length < 1) v = 0.0f;
|
||||
else v = Interpolate(f);
|
||||
return v;
|
||||
}
|
||||
|
||||
public float NextFrame()
|
||||
{
|
||||
f += df;
|
||||
t = f / @if;
|
||||
|
||||
int type = (int)a3daKey.Type;
|
||||
if (type < 0 || type > 4) v = 0.0f;
|
||||
else if (type < 2) v = a3daKey.Value;
|
||||
else if (a3daKey.Length < 1) v = 0.0f;
|
||||
else v = Interpolate(f);
|
||||
return v;
|
||||
}
|
||||
|
||||
private float Interpolate(float frame)
|
||||
{
|
||||
float ep = 0;
|
||||
|
||||
if (frame < firstKey.F)
|
||||
{
|
||||
if (a3daKey.EPTypePost < EPType.Linear || a3daKey.EPTypePost > EPType.CycleOffset)
|
||||
return firstKey.V;
|
||||
|
||||
float df = firstKey.F - frame;
|
||||
if (a3daKey.EPTypePre == EPType.Linear)
|
||||
return firstKey.V - df * firstKey.T1;
|
||||
|
||||
frame = lastKey.F - df % a3daKey.FrameDelta;
|
||||
if (a3daKey.EPTypePre == EPType.CycleOffset)
|
||||
ep = -(float)((int)(df / a3daKey.FrameDelta) + 1) * a3daKey.ValueDelta;
|
||||
}
|
||||
else if (frame >= lastKey.F)
|
||||
{
|
||||
if (a3daKey.EPTypePost < EPType.Linear || a3daKey.EPTypePost > EPType.CycleOffset)
|
||||
return lastKey.V;
|
||||
|
||||
float df = frame - lastKey.F;
|
||||
if (a3daKey.EPTypePost == EPType.Linear)
|
||||
return lastKey.V + df * lastKey.T2;
|
||||
|
||||
frame = firstKey.F + df % a3daKey.FrameDelta;
|
||||
if (a3daKey.EPTypePost == EPType.CycleOffset)
|
||||
ep = (float)((int)(df / a3daKey.FrameDelta) + 1) * a3daKey.ValueDelta;
|
||||
}
|
||||
|
||||
KFT3 c, n;
|
||||
long key = 0;
|
||||
unsafe
|
||||
{
|
||||
fixed (KFT3* ptr = a3daKey.Keys)
|
||||
{
|
||||
long length = a3daKey.Length;
|
||||
long temp;
|
||||
while (length > 0)
|
||||
if (frame >= ptr[key + (temp = length >> 1)].F)
|
||||
{
|
||||
key += temp + 1;
|
||||
length -= temp + 1;
|
||||
}
|
||||
else length = temp;
|
||||
|
||||
c = ptr[key - 1];
|
||||
n = ptr[key];
|
||||
}
|
||||
}
|
||||
|
||||
float v;
|
||||
if (frame <= c.F || frame >= n.F)
|
||||
v = frame > c.F ? n.V : c.V;
|
||||
else if (a3daKey.Type == KeyType.Linear)
|
||||
{
|
||||
float t = (frame - c.F) / (n.F - c.F);
|
||||
v = (1.0f - t) * c.V + t * n.V;
|
||||
}
|
||||
else if (a3daKey.Type == KeyType.Hermite)
|
||||
{
|
||||
float df = f - c.F;
|
||||
float t = df / (n.F - c.F);
|
||||
float t_1 = t - 1.0f;
|
||||
return c.V + t * t * (3.0f - 2.0f * t) * (n.V - c.V) + (t_1 * c.T2 + t * n.T1) * df * t_1;
|
||||
}
|
||||
else v = c.V;
|
||||
return v + ep;
|
||||
}
|
||||
|
||||
public void ResetFrameCount() { f = -df; t = f / rf; }
|
||||
|
||||
public override string ToString() => $"F: {f}; T: {t}; V: {v}";
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
a3daKey.Keys = null;
|
||||
a3daKey = default;
|
||||
f = t = v = df = @if = rf = default;
|
||||
firstKey = lastKey = default;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace KKdBaseLib.Interpolation
|
||||
{
|
||||
public interface IInterpolation<T> : INull
|
||||
{
|
||||
float RequestedFramerate { get; set; }
|
||||
|
||||
float Frame { get; }
|
||||
float Time { get; }
|
||||
T Value { get; }
|
||||
|
||||
T SetTime (float time);
|
||||
T SetFrame(float frame);
|
||||
T NextFrame(float time);
|
||||
T NextFrame();
|
||||
void ResetFrameCount();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
namespace KKdBaseLib.Interpolation
|
||||
{
|
||||
public class MOTI : IInterpolation<float> // MOT Interpolation
|
||||
{
|
||||
private KFT2[] array;
|
||||
private int length;
|
||||
|
||||
private float f;
|
||||
private float t;
|
||||
private float v;
|
||||
private float df;
|
||||
private float @if;
|
||||
private float rf;
|
||||
|
||||
private KFT2 firstKey;
|
||||
private KFT2 lastKey;
|
||||
|
||||
public float RequestedFramerate { get => rf; set { rf = value; df = @if / rf; } }
|
||||
|
||||
public float Frame => f;
|
||||
public float Time => t;
|
||||
public float Value => v;
|
||||
public bool IsNull => array == null || array.Length < 1;
|
||||
public bool NotNull => array != null && array.Length > 0;
|
||||
|
||||
public MOTI(KFT2[] array, float interpolationFramerate = 60, float requestedFramerate = 60)
|
||||
{
|
||||
length = 0;
|
||||
this.array = array; f = -1; df = @if = rf = t = v = 0;
|
||||
@if = interpolationFramerate;
|
||||
firstKey = lastKey = default;
|
||||
RequestedFramerate = requestedFramerate;
|
||||
f = -df;
|
||||
ResetFrameCount();
|
||||
|
||||
if (array != null && array.Length > 0)
|
||||
{
|
||||
firstKey = array[0];
|
||||
lastKey = array[array.Length - 1];
|
||||
length = array.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public float SetTime(float time)
|
||||
{
|
||||
t = time;
|
||||
f = time * @if;
|
||||
|
||||
if (array == null || length < 1) v = 0.0f;
|
||||
else v = Interpolate(f);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public float SetFrame(float frame)
|
||||
{
|
||||
t = frame / rf;
|
||||
f = frame * df;
|
||||
|
||||
if (array == null || length < 1) v = 0.0f;
|
||||
else v = Interpolate(f);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public float NextFrame(float time)
|
||||
{
|
||||
t += time;
|
||||
f = t * @if;
|
||||
|
||||
if (array == null || length < 1) v = 0.0f;
|
||||
else v = Interpolate(f);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public float NextFrame()
|
||||
{
|
||||
f += df;
|
||||
t = f / @if;
|
||||
|
||||
if (array == null || length < 1) v = 0.0f;
|
||||
else v = Interpolate(f);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
private float Interpolate(float frame)
|
||||
{
|
||||
if (frame <= firstKey.F) return firstKey.V;
|
||||
else if (frame >= lastKey.F) return lastKey.V;
|
||||
|
||||
KFT2 c, n;
|
||||
unsafe
|
||||
{
|
||||
fixed (KFT2* ptr = array)
|
||||
{
|
||||
long key = 0;
|
||||
long length = this.length;
|
||||
long temp;
|
||||
while (length > 0)
|
||||
if (frame >= ptr[key + (temp = length >> 1)].F)
|
||||
{
|
||||
key += temp + 1;
|
||||
length -= temp + 1;
|
||||
}
|
||||
else length = temp;
|
||||
|
||||
c = ptr[key - 1];
|
||||
n = ptr[key];
|
||||
}
|
||||
}
|
||||
|
||||
float v;
|
||||
if (frame <= c.F || frame >= n.F)
|
||||
v = frame > c.F ? n.V : c.V;
|
||||
else
|
||||
{
|
||||
float df = f - c.F;
|
||||
float t = df / (n.F - c.F);
|
||||
float t_1 = t - 1.0f;
|
||||
return c.V + t * t * (3.0f - 2.0f * t) * (n.V - c.V) + (t_1 * c.T + t * n.T) * df * t_1;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
public void ResetFrameCount() { f = -df; t = f / rf; }
|
||||
|
||||
public override string ToString() => $"F: {f}; T: {t}; V: {v}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct KFT0 : IKF
|
||||
{
|
||||
public float F;
|
||||
|
||||
public KFT0(float F)
|
||||
{ this.F = F; }
|
||||
|
||||
public KFT0 ToT0() => this;
|
||||
public KFT1 ToT1() =>
|
||||
new KFT1(F);
|
||||
public KFT2 ToT2() =>
|
||||
new KFT2(F);
|
||||
public KFT3 ToT3() =>
|
||||
new KFT3(F);
|
||||
|
||||
public IKF Check() => this;
|
||||
|
||||
public override string ToString() => ToString(true, 7);
|
||||
public string ToString(int round = 7, bool brackets = true) =>
|
||||
ToString(brackets, round);
|
||||
public string ToString(bool brackets = true, int round = 7) =>
|
||||
Extensions.ToS(F, round);
|
||||
|
||||
public static explicit operator KFT1(KFT0 KF) =>
|
||||
new KFT1(KF.F);
|
||||
public static explicit operator KFT2(KFT0 KF) =>
|
||||
new KFT2(KF.F);
|
||||
public static explicit operator KFT3(KFT0 KF) =>
|
||||
new KFT3(KF.F);
|
||||
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
public override bool Equals(object obj)
|
||||
{ if (obj is KFT0 b) return this == b; else return base.Equals(obj); }
|
||||
|
||||
public static bool operator > (float a, KFT0 b) => a > b.F;
|
||||
public static bool operator < (float a, KFT0 b) => a < b.F;
|
||||
public static bool operator >=(float a, KFT0 b) => a >= b.F;
|
||||
public static bool operator <=(float a, KFT0 b) => a <= b.F;
|
||||
public static bool operator > (KFT0 a, float b) => a.F > b;
|
||||
public static bool operator < (KFT0 a, float b) => a.F < b;
|
||||
public static bool operator >=(KFT0 a, float b) => a.F >= b;
|
||||
public static bool operator <=(KFT0 a, float b) => a.F <= b;
|
||||
public static bool operator > (KFT0 a, KFT0 b) => a.F > b.F;
|
||||
public static bool operator < (KFT0 a, KFT0 b) => a.F < b.F;
|
||||
public static bool operator >=(KFT0 a, KFT0 b) => a.F >= b.F;
|
||||
public static bool operator <=(KFT0 a, KFT0 b) => a.F <= b.F;
|
||||
public static bool operator ==(KFT0 a, KFT0 b) => a.F == b.F;
|
||||
public static bool operator !=(KFT0 a, KFT0 b) => a.F != b.F;
|
||||
}
|
||||
|
||||
public struct KFT1 : IKF
|
||||
{
|
||||
public float F;
|
||||
public float V;
|
||||
|
||||
public KFT1(float F)
|
||||
{ this.F = F; V = 0; }
|
||||
|
||||
public KFT1(float F, float V)
|
||||
{ this.F = F; this.V = V; }
|
||||
|
||||
public KFT0 ToT0() =>
|
||||
new KFT0(F);
|
||||
public KFT1 ToT1() => this;
|
||||
public KFT2 ToT2() =>
|
||||
new KFT2(F, V);
|
||||
public KFT3 ToT3() =>
|
||||
new KFT3(F, V);
|
||||
|
||||
public IKF Check() =>
|
||||
V.ToU32() == 0x00000000 ? (KFT0)this : (IKF)this;
|
||||
|
||||
public override string ToString() => ToString(true, 7);
|
||||
public string ToString(int round = 7, bool brackets = true) =>
|
||||
ToString(brackets, round);
|
||||
public string ToString(bool brackets = true, int round = 7) =>
|
||||
(brackets ? "(" : "") + Extensions.ToS(F, round) + "," +
|
||||
Extensions.ToS(V, round) + (brackets ? ")" : "");
|
||||
|
||||
public static explicit operator KFT0(KFT1 KF) =>
|
||||
new KFT0(KF.F);
|
||||
public static explicit operator KFT2(KFT1 KF) =>
|
||||
new KFT2(KF.F, KF.V);
|
||||
public static explicit operator KFT3(KFT1 KF) =>
|
||||
new KFT3(KF.F, KF.V);
|
||||
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
public override bool Equals(object obj)
|
||||
{ if (obj is KFT1 b) return this == b; else return base.Equals(obj); }
|
||||
|
||||
public static bool operator > (float a, KFT1 b) => a > b.F;
|
||||
public static bool operator < (float a, KFT1 b) => a < b.F;
|
||||
public static bool operator >=(float a, KFT1 b) => a >= b.F;
|
||||
public static bool operator <=(float a, KFT1 b) => a <= b.F;
|
||||
public static bool operator > (KFT1 a, float b) => a.F > b;
|
||||
public static bool operator < (KFT1 a, float b) => a.F < b;
|
||||
public static bool operator >=(KFT1 a, float b) => a.F >= b;
|
||||
public static bool operator <=(KFT1 a, float b) => a.F <= b;
|
||||
public static bool operator > (KFT1 a, KFT1 b) => a.F > b.F;
|
||||
public static bool operator < (KFT1 a, KFT1 b) => a.F < b.F;
|
||||
public static bool operator >=(KFT1 a, KFT1 b) => a.F >= b.F;
|
||||
public static bool operator <=(KFT1 a, KFT1 b) => a.F <= b.F;
|
||||
public static bool operator ==(KFT1 a, KFT1 b) => a.F == b.F && a.V == b.V;
|
||||
public static bool operator !=(KFT1 a, KFT1 b) => a.F != b.F || a.V != b.V;
|
||||
}
|
||||
|
||||
public struct KFT2 : IKF
|
||||
{
|
||||
public float F;
|
||||
public float V;
|
||||
public float T;
|
||||
|
||||
public KFT2(float F)
|
||||
{ this.F = F; V = T = 0; }
|
||||
|
||||
public KFT2(float F, float V)
|
||||
{ this.F = F; this.V = V; T = 0; }
|
||||
|
||||
public KFT2(float F, float V, float T)
|
||||
{ this.F = F; this.V = V; this.T = T; }
|
||||
|
||||
public KFT0 ToT0() =>
|
||||
new KFT0(F);
|
||||
public KFT1 ToT1() =>
|
||||
new KFT1(F, V);
|
||||
public KFT2 ToT2() => this;
|
||||
public KFT3 ToT3() =>
|
||||
new KFT3(F, V, T);
|
||||
|
||||
public KFT3 ToT3(IKF Previous) =>
|
||||
Previous is KFT2 PreviousT2 ?
|
||||
new KFT3(F, V, PreviousT2.T, T) :
|
||||
new KFT3(F, V, T, T);
|
||||
|
||||
public IKF Check() =>
|
||||
T.ToU32() == 0x00000000 ? (V.ToU32() == 0x00000000 ? (IKF)ToT0() : ToT1()) : this;
|
||||
|
||||
public override string ToString() => ToString(true, 7);
|
||||
public string ToString(int round = 7, bool brackets = true) =>
|
||||
ToString(brackets, round);
|
||||
public string ToString(bool brackets = true, int round = 7) =>
|
||||
(brackets ? "(" : "") + Extensions.ToS(F, round) + "," + Extensions.
|
||||
ToS(V, round) + "," + Extensions.ToS(T, round) + (brackets ? ")" : "");
|
||||
|
||||
public static explicit operator KFT0(KFT2 KF) =>
|
||||
new KFT0(KF.F);
|
||||
public static explicit operator KFT1(KFT2 KF) =>
|
||||
new KFT1(KF.F, KF.V);
|
||||
public static explicit operator KFT3(KFT2 KF) =>
|
||||
new KFT3(KF.F, KF.V, KF.T, KF.T);
|
||||
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
public override bool Equals(object obj)
|
||||
{ if (obj is KFT2 b) return this == b; else return base.Equals(obj); }
|
||||
|
||||
public static bool operator > (float a, KFT2 b) => a > b.F;
|
||||
public static bool operator < (float a, KFT2 b) => a < b.F;
|
||||
public static bool operator >=(float a, KFT2 b) => a >= b.F;
|
||||
public static bool operator <=(float a, KFT2 b) => a <= b.F;
|
||||
public static bool operator > (KFT2 a, float b) => a.F > b;
|
||||
public static bool operator < (KFT2 a, float b) => a.F < b;
|
||||
public static bool operator >=(KFT2 a, float b) => a.F >= b;
|
||||
public static bool operator <=(KFT2 a, float b) => a.F <= b;
|
||||
public static bool operator > (KFT2 a, KFT2 b) => a.F > b.F;
|
||||
public static bool operator < (KFT2 a, KFT2 b) => a.F < b.F;
|
||||
public static bool operator >=(KFT2 a, KFT2 b) => a.F >= b.F;
|
||||
public static bool operator <=(KFT2 a, KFT2 b) => a.F <= b.F;
|
||||
public static bool operator ==(KFT2 a, KFT2 b) => a.F == b.F && a.V == b.V && a.T == b.T;
|
||||
public static bool operator !=(KFT2 a, KFT2 b) => a.F != b.F || a.V != b.V || a.T != b.T;
|
||||
}
|
||||
|
||||
public struct KFT3 : IKF
|
||||
{
|
||||
public float F;
|
||||
public float V;
|
||||
public float T1;
|
||||
public float T2;
|
||||
|
||||
public KFT3(float F)
|
||||
{ this.F = F; V = T1 = T2 = 0; }
|
||||
|
||||
public KFT3(float F, float V)
|
||||
{ this.F = F; this.V = V; T1 = T2 = 0; }
|
||||
|
||||
public KFT3(float F, float V, float T)
|
||||
{ this.F = F; this.V = V; T1 = T2 = T; }
|
||||
|
||||
public KFT3(float F, float V, float T1, float T2)
|
||||
{ this.F = F; this.V = V; this.T1 = T1; this.T2 = T2; }
|
||||
|
||||
public KFT0 ToT0() =>
|
||||
new KFT0(F);
|
||||
public KFT1 ToT1() =>
|
||||
new KFT1(F, V);
|
||||
public KFT2 ToT2() =>
|
||||
new KFT2(F, V, T1);
|
||||
public KFT3 ToT3() => this;
|
||||
|
||||
public IKF Check() =>
|
||||
T1.ToU32() == 0x00000000 && T2.ToU32() == 0x00000000
|
||||
? (V.ToU32() == 0x00000000 ? (IKF)(KFT0)this : (KFT1)this)
|
||||
: T1.ToU32() == T2.ToU32() ? (KFT2)this : (IKF)this;
|
||||
|
||||
public override string ToString() => ToString(true, 7);
|
||||
public string ToString(int round = 7, bool brackets = true) =>
|
||||
ToString(brackets, round);
|
||||
public string ToString(bool brackets = true, int round = 7) =>
|
||||
(brackets ? "(" : "") + Extensions.ToS(F, round) + "," + Extensions.ToS(V, round) + "," +
|
||||
Extensions.ToS(T1, round) + "," + Extensions.ToS(T2, round) + (brackets ? ")" : "");
|
||||
|
||||
public static explicit operator KFT0(KFT3 KF) =>
|
||||
new KFT0(KF.F);
|
||||
public static explicit operator KFT1(KFT3 KF) =>
|
||||
new KFT1(KF.F, KF.V);
|
||||
public static explicit operator KFT2(KFT3 KF) =>
|
||||
new KFT2(KF.F, KF.V, KF.T1);
|
||||
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
public override bool Equals(object obj)
|
||||
{ if (obj is KFT3 b) return this == b; else return base.Equals(obj); }
|
||||
|
||||
public static bool operator > (float a, KFT3 b) => a > b.F;
|
||||
public static bool operator < (float a, KFT3 b) => a < b.F;
|
||||
public static bool operator >=(float a, KFT3 b) => a >= b.F;
|
||||
public static bool operator <=(float a, KFT3 b) => a <= b.F;
|
||||
public static bool operator > (KFT3 a, float b) => a.F > b;
|
||||
public static bool operator < (KFT3 a, float b) => a.F < b;
|
||||
public static bool operator >=(KFT3 a, float b) => a.F >= b;
|
||||
public static bool operator <=(KFT3 a, float b) => a.F <= b;
|
||||
public static bool operator > (KFT3 a, KFT3 b) => a.F > b.F;
|
||||
public static bool operator < (KFT3 a, KFT3 b) => a.F < b.F;
|
||||
public static bool operator >=(KFT3 a, KFT3 b) => a.F >= b.F;
|
||||
public static bool operator <=(KFT3 a, KFT3 b) => a.F <= b.F;
|
||||
public static bool operator ==(KFT3 a, KFT3 b) => a.F == b.F && a.V == b.V && a.T1 == b.T1 && a.T2 == b.T2;
|
||||
public static bool operator !=(KFT3 a, KFT3 b) => a.F != b.F || a.V != b.V || a.T1 != b.T1 || a.T2 != b.T2;
|
||||
|
||||
public IKF ToT2(IKF Previous, out IKF Current)
|
||||
{
|
||||
Current = Previous is KFT2 PreviousT2
|
||||
? new KFT2(PreviousT2.F, PreviousT2.V, T1)
|
||||
: new KFT2(F, V, T1);
|
||||
return new KFT2(F, V, T2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Authors>korenkonder</Authors>
|
||||
<Company></Company>
|
||||
<Configuration></Configuration>
|
||||
<Copyright>korenkonder (C) 2019-2022</Copyright>
|
||||
<Description>A base library</Description>
|
||||
<FileVersion>0.4.10.12</FileVersion>
|
||||
<PackageId>KKdBaseLib</PackageId>
|
||||
<Product>KKdBaseLib</Product>
|
||||
<TargetFramework>net461</TargetFramework>
|
||||
<Title>KKdBaseLib</Title>
|
||||
<Version>0.4.10.12</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0018, IDE0032, IDE0044, IDE0045, IDE0046, IDE0051, IDE0055, IDE0059, IDE0063, IDE0066, IDE0069, IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>embedded</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0018, IDE0032, IDE0044, IDE0045, IDE0046, IDE0051, IDE0055, IDE0059, IDE0063, IDE0066, IDE0069, IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,242 @@
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct KKdDict<TKey, TValue> : System.IDisposable, System.Collections.IEnumerator, INull
|
||||
{
|
||||
public static KKdDict<TKey, TValue> Null => new KKdDict<TKey, TValue>();
|
||||
public static KKdDict<TKey, TValue> New => new KKdDict<TKey, TValue>() { count = 0, Capacity = 0 };
|
||||
public static KKdDict<TKey, TValue> NewReserve(int capacity) =>
|
||||
new KKdDict<TKey, TValue>() { count = 0, Capacity = capacity };
|
||||
|
||||
private int count;
|
||||
private int index;
|
||||
private TKey [] keyArray;
|
||||
private TValue[] valArray;
|
||||
|
||||
public int Count => count;
|
||||
|
||||
public bool IsNull => keyArray == null || valArray == null;
|
||||
public bool NotNull => keyArray != null && valArray != null;
|
||||
|
||||
public int Capacity { get => keyArray != null && valArray != null ? valArray.Length : -1;
|
||||
set { if (keyArray != null) System.Array.Resize(ref keyArray, value); else keyArray = new TKey [value];
|
||||
if (valArray != null) System.Array.Resize(ref valArray, value); else valArray = new TValue[value];
|
||||
if (count >= value) count = value; } }
|
||||
|
||||
|
||||
public KKdDict(TKey[] keyArray, TValue[] valArray)
|
||||
{
|
||||
this.keyArray = null; this.valArray = null; count = 0; index = 0;
|
||||
if (keyArray == null || valArray == null || keyArray.Length != valArray.Length) return;
|
||||
|
||||
count = this.keyArray.Length;
|
||||
this.keyArray = new TKey [count];
|
||||
this.valArray = new TValue[count];
|
||||
System.Array.Copy(keyArray, this.keyArray, count);
|
||||
System.Array.Copy(valArray, this.valArray, count);
|
||||
}
|
||||
|
||||
public KeyValuePair<TKey, TValue> Current => index < count ?
|
||||
new KeyValuePair<TKey, TValue>(keyArray[index], valArray[index]) : default;
|
||||
|
||||
object System.Collections.IEnumerator.Current => Current;
|
||||
|
||||
public TKey [] Keys => keyArray;
|
||||
public TValue[] Values => valArray;
|
||||
|
||||
public KeyValuePair<TKey, TValue> this[ int index, bool list]
|
||||
{ get => keyArray != null && valArray != null && index > -1 && index < keyArray.Length &&
|
||||
index < valArray.Length ? new KeyValuePair<TKey, TValue>(keyArray[index], valArray[index]) : default;
|
||||
set { if (keyArray != null && valArray != null && index > -1 && index < keyArray.Length &&
|
||||
index < valArray.Length) { keyArray[index] = value.Key; valArray[index] = value.Value; } } }
|
||||
|
||||
public KeyValuePair<TKey, TValue> this[uint index, bool list]
|
||||
{ get => keyArray != null && valArray != null && index < keyArray.Length &&
|
||||
index < valArray.Length ? new KeyValuePair<TKey, TValue>(keyArray[index], valArray[index]) : default;
|
||||
set { if (keyArray != null && valArray != null && index < keyArray.Length &&
|
||||
index < valArray.Length) { keyArray[index] = value.Key; valArray[index] = value.Value; } } }
|
||||
|
||||
public KeyValuePair<TKey, TValue> this[long index, bool list]
|
||||
{ get => keyArray != null && valArray != null && index > -1 && index < keyArray.Length &&
|
||||
index < valArray.Length ? new KeyValuePair<TKey, TValue>(keyArray[index], valArray[index]) : default;
|
||||
set { if (keyArray != null && valArray != null && index > -1 && index < keyArray.Length &&
|
||||
index < valArray.Length) { keyArray[index] = value.Key; valArray[index] = value.Value; } } }
|
||||
|
||||
public TValue this[TKey key]
|
||||
{ get => valArray != null && valArray.Length > 0
|
||||
&& CK(key, out int index) ? valArray[index] : default;
|
||||
set { if (valArray != null && valArray.Length > 0)
|
||||
if (CK(key, out int index)) valArray[index] = value; else Add(key, value); } }
|
||||
|
||||
public bool MoveNext()
|
||||
{ if (index == count - 1) { index = 0; return false; }
|
||||
else { index++ ; return true; } }
|
||||
|
||||
public System.Collections.IEnumerator GetEnumerator() => this;
|
||||
|
||||
public void Dispose() { keyArray = null; valArray = null; count = 0; index = 0; }
|
||||
|
||||
public void Reset() => index = 0;
|
||||
|
||||
public void Add(KeyValuePair<TKey, TValue> pair)
|
||||
{
|
||||
if (IsNull || ContainsKey(pair.Key)) return;
|
||||
|
||||
count++;
|
||||
if (keyArray.Length < count) System.Array.Resize(ref keyArray, keyArray.Length * 2 + 1);
|
||||
if (valArray.Length < count) System.Array.Resize(ref valArray, valArray.Length * 2 + 1);
|
||||
keyArray[count - 1] = pair.Key;
|
||||
valArray[count - 1] = pair.Value;
|
||||
}
|
||||
|
||||
public void Add(TKey key, TValue val)
|
||||
{
|
||||
if (IsNull || ContainsKey(key)) return;
|
||||
|
||||
count++;
|
||||
if (keyArray.Length < count) System.Array.Resize(ref keyArray, keyArray.Length * 2 + 1);
|
||||
if (valArray.Length < count) System.Array.Resize(ref valArray, valArray.Length * 2 + 1);
|
||||
keyArray[count - 1] = key;
|
||||
valArray[count - 1] = val;
|
||||
}
|
||||
|
||||
public bool RemoveKey(TKey key)
|
||||
{
|
||||
if (IsNull) return false;
|
||||
|
||||
int index = IndexOf(key);
|
||||
if (index == -1) return false;
|
||||
|
||||
if (index + 1 < count)
|
||||
{ System.Array.Copy(keyArray, index + 1, keyArray, index, count - index - 1);
|
||||
System.Array.Copy(valArray, index + 1, valArray, index, count - index - 1); }
|
||||
count--;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool RemoveValue(TValue val)
|
||||
{
|
||||
if (IsNull) return false;
|
||||
|
||||
int index = IndexOf(val);
|
||||
if (index == -1) return false;
|
||||
|
||||
if (index + 1 < count)
|
||||
{ System.Array.Copy(keyArray, index + 1, keyArray, index, count - index - 1);
|
||||
System.Array.Copy(valArray, index + 1, valArray, index, count - index - 1); }
|
||||
count--;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if (IsNull || index < 0 || index >= count) return;
|
||||
|
||||
if (index + 1 < count)
|
||||
{ System.Array.Copy(keyArray, index + 1, keyArray, index, count - index - 1);
|
||||
System.Array.Copy(valArray, index + 1, valArray, index, count - index - 1); }
|
||||
count--;
|
||||
}
|
||||
|
||||
public void RemoveRange(int indexStart, int indexEnd)
|
||||
{
|
||||
int indexcount = indexEnd - indexStart;
|
||||
if (IsNull || indexcount < 1 || indexStart < 0 || indexEnd > count) return;
|
||||
|
||||
if ((indexEnd + indexcount) < count)
|
||||
{ System.Array.Copy(keyArray, indexEnd, keyArray, indexStart, indexcount);
|
||||
System.Array.Copy(valArray, indexEnd, valArray, indexStart, indexcount); }
|
||||
count -= indexcount;
|
||||
}
|
||||
|
||||
public TValue[] ToArray() => valArray;
|
||||
|
||||
public bool ContainsKey (TKey key) => CK(key, out int index);
|
||||
public bool ContainsValue(TValue val) => CV(val, out int index);
|
||||
public bool Contains (KeyValuePair<TKey, TValue> pair) => C(pair, out int index);
|
||||
|
||||
public bool ContainsKey (TKey key, out int index) => CK(key, out index);
|
||||
public bool ContainsValue(TValue val, out int index) => CV(val, out index);
|
||||
public bool Contains (KeyValuePair<TKey, TValue> pair, out int index) => C(pair, out index);
|
||||
|
||||
private bool CK(TKey key, out int index)
|
||||
{
|
||||
index = -1;
|
||||
if (IsNull) return false;
|
||||
for (int i = 0; i < count; i++)
|
||||
if (keyArray[i] == null && key == null) { index = i; return true; }
|
||||
else if (keyArray[i] == null || key == null) continue;
|
||||
else if (keyArray[i].Equals(key)) { index = i; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool CV(TValue val, out int index)
|
||||
{
|
||||
index = -1;
|
||||
if (IsNull) return false;
|
||||
for (int i = 0; i < count; i++)
|
||||
if (valArray[i] == null && val == null) { index = i; return true; }
|
||||
else if (valArray[i] == null || val == null) continue;
|
||||
else if (valArray[i].Equals(val)) { index = i; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool C(KeyValuePair<TKey, TValue> pair, out int index)
|
||||
{
|
||||
index = -1;
|
||||
if (IsNull) return false;
|
||||
for (int i = 0; i < count; i++)
|
||||
if (keyArray[i] == null && pair.Key == null &&
|
||||
valArray[i] == null && pair.Value == null) { index = i; return true; }
|
||||
else if ((keyArray[i] == null || pair.Key == null) &&
|
||||
(valArray[i] == null || pair.Value == null)) continue;
|
||||
else if (keyArray[i].Equals(pair.Key ) &&
|
||||
valArray[i].Equals(pair.Value)) { index = i; return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
public TKey GetKey(TValue val)
|
||||
{
|
||||
if (IsNull) return default;
|
||||
for (int i = 0; i < count; i++)
|
||||
if (valArray[i] == null && val == null) return keyArray[i];
|
||||
else if (valArray[i] == null || val == null) continue;
|
||||
else if (valArray[i].Equals(val)) return keyArray[i];
|
||||
return default;
|
||||
}
|
||||
|
||||
private int IndexOf(TKey key)
|
||||
{
|
||||
if (IsNull) return -1;
|
||||
for (int i = 0; i < count; i++)
|
||||
if (keyArray[i] == null && key == null) return i;
|
||||
else if (keyArray[i] == null || key == null) continue;
|
||||
else if (keyArray[i].Equals(key)) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
private int IndexOf(TValue val)
|
||||
{
|
||||
if (IsNull) return -1;
|
||||
for (int i = 0; i < count; i++)
|
||||
if (valArray[i] == null && val == null) return i;
|
||||
else if (valArray[i] == null || val == null) continue;
|
||||
else if (valArray[i].Equals(val)) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public override string ToString() =>
|
||||
$"(Count: {Count}; Capacity: {Capacity}; Current: {Current})";
|
||||
}
|
||||
|
||||
public struct KeyValuePair<TKey, TValue>
|
||||
{
|
||||
public TKey Key;
|
||||
public TValue Value;
|
||||
|
||||
public KeyValuePair(TKey key, TValue value)
|
||||
{ Key = key; Value = value; }
|
||||
|
||||
public override string ToString() =>
|
||||
$"(Key: {Key}; Value: {Value})";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct KKdList<T> : System.IDisposable, IEnumerable<T>, IEnumerable, IEnumerator, INull
|
||||
{
|
||||
public static KKdList<T> Null => new KKdList<T>();
|
||||
public static KKdList<T> New => new KKdList<T>() { count = 0, Capacity = 0 };
|
||||
public static KKdList<T> NewReserve(int capacity) => new KKdList<T>() { count = 0, Capacity = capacity };
|
||||
|
||||
private int count;
|
||||
private int index;
|
||||
private T[] array;
|
||||
|
||||
private Enumerator enumerator;
|
||||
|
||||
public int Count => count;
|
||||
|
||||
public bool IsNull => array == null;
|
||||
public bool NotNull => array != null;
|
||||
|
||||
public int Capacity { get => array != null ? array.Length : -1;
|
||||
set { if (array != null) System.Array.Resize(ref array, value); else array = new T[value];
|
||||
if (Count >= value) count = value; } }
|
||||
|
||||
|
||||
public KKdList(T[] array)
|
||||
{
|
||||
index = -1;
|
||||
if (array != null)
|
||||
{
|
||||
count = array.Length;
|
||||
this.array = new T[count];
|
||||
System.Array.Copy(array, this.array, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 0;
|
||||
this.array = null;
|
||||
}
|
||||
enumerator = new Enumerator(this.array);
|
||||
}
|
||||
|
||||
public T Current => index > -1 && index < Count ? array[index] : default;
|
||||
|
||||
object IEnumerator.Current => enumerator.Current;
|
||||
|
||||
public bool MoveNext() => enumerator.MoveNext();
|
||||
public void Reset() => enumerator.Reset();
|
||||
|
||||
public T this[ int index]
|
||||
{ get => array != null && index > -1 && index < array.Length ? array[index] : default;
|
||||
set { if (array != null && index > -1 && index < array.Length) array[index] = value; } }
|
||||
|
||||
public T this[uint index]
|
||||
{ get => array != null && index < array.Length ? array[index] : default;
|
||||
set { if (array != null && index < array.Length) array[index] = value; } }
|
||||
|
||||
public T this[long index]
|
||||
{ get => array != null && index < array.Length ? array[index] : default;
|
||||
set { if (array != null && index < array.Length) array[index] = value; } }
|
||||
|
||||
public IEnumerator GetEnumerator() => enumerator = new Enumerator(array);
|
||||
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator() => enumerator = new Enumerator(array);
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => enumerator = new Enumerator(array);
|
||||
|
||||
public void Dispose() { array = null; count = 0; index = -1; }
|
||||
|
||||
public void Add(T item)
|
||||
{
|
||||
if (IsNull) return;
|
||||
|
||||
count++;
|
||||
if (array.Length < count)
|
||||
System.Array.Resize(ref array, array.Length * 2 + 1);
|
||||
array[count - 1] = item;
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if (IsNull || index < 0 || index >= count) return;
|
||||
|
||||
if (index + 1 < count)
|
||||
System.Array.Copy(array, index + 1, array, index, count - index - 1);
|
||||
count--;
|
||||
}
|
||||
|
||||
public void RemoveRange(int indexStart, int indexEnd)
|
||||
{
|
||||
int indexCount = indexEnd - indexStart;
|
||||
if (IsNull || indexCount < 1 || indexStart < 0 || indexEnd > count) return;
|
||||
|
||||
if ((indexEnd + indexCount) < count)
|
||||
System.Array.Copy(array, indexEnd, array, indexStart, indexCount);
|
||||
count -= indexCount;
|
||||
}
|
||||
|
||||
public T[] ToArray() => array;
|
||||
|
||||
public bool Contains(T val)
|
||||
{
|
||||
if (IsNull) return false;
|
||||
for (int i = 0; i < count; i++)
|
||||
if (array[i] == null && val == null) return true;
|
||||
else if (array[i] == null || val == null) continue;
|
||||
else if (array[i].Equals(val)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public int IndexOf(T val)
|
||||
{
|
||||
if (IsNull) return -1;
|
||||
for (int i = 0; i < count; i++)
|
||||
if (array[i] == null && val == null) return i;
|
||||
else if (array[i] == null || val == null) continue;
|
||||
else if (array[i].Equals(val)) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void Sort()
|
||||
{ Capacity = Count; List<T> List = (List<T>)this; List.Sort();
|
||||
array = List.ToArray(); count = List.Count; }
|
||||
|
||||
public static explicit operator KKdList<T>( List<T> list) =>
|
||||
new KKdList<T> { array = list.ToArray(), count = list.Count };
|
||||
|
||||
public static explicit operator List<T>(KKdList<T> list)
|
||||
{ list.Capacity = list.Count; List<T> outList = new List<T>();
|
||||
for (int i = 0; i < list.Count; i++) outList.Add(list[i]); return outList; }
|
||||
|
||||
public override string ToString() =>
|
||||
$"(Count: {Count}; Capacity: {Capacity}; Current: {Current})";
|
||||
|
||||
public struct Enumerator : IEnumerator<T>, IEnumerator
|
||||
{
|
||||
private T[] array;
|
||||
private int index;
|
||||
private int count;
|
||||
private T current;
|
||||
|
||||
internal Enumerator(T[] array)
|
||||
{ this.array = array; count = index = 0; current = default;
|
||||
if (array != null && array.Length > 0) { current = array[0]; count = array.Length; } }
|
||||
|
||||
public void Dispose()
|
||||
{ array = null; count = index = 0; current = default; }
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
if (index < count) { current = array[index]; index++; return true; }
|
||||
else { current = default; index = count + 1; return false; }
|
||||
}
|
||||
|
||||
public T Current => current;
|
||||
|
||||
object IEnumerator.Current =>
|
||||
(index == 0 || index == array.Length + 1) ? default : current;
|
||||
|
||||
void IEnumerator.Reset() => Reset();
|
||||
|
||||
public void Reset() { index = 0; current = default; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using A3DADict = System.Collections.Generic.Dictionary<string, object>;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public static unsafe class Main
|
||||
{
|
||||
public const string TimeFormatHHmmssfff = "{0:d2}:{1:d2}:{2:d2}.{3:d3}";
|
||||
|
||||
public static void WT(this TimeSpan time, bool writeLine = false)
|
||||
{
|
||||
if (writeLine) Console.WriteLine(TimeFormatHHmmssfff,
|
||||
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
|
||||
else Console.Write (TimeFormatHHmmssfff,
|
||||
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
|
||||
}
|
||||
|
||||
public static void WT(this TimeSpan time, string text, bool writeLine = true)
|
||||
{
|
||||
if (writeLine) Console.WriteLine(TimeFormatHHmmssfff + " - " + text,
|
||||
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
|
||||
else Console.Write (TimeFormatHHmmssfff + " - " + text,
|
||||
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
|
||||
}
|
||||
|
||||
public static string NT(this string source, ref int i, byte end)
|
||||
{
|
||||
string s = "";
|
||||
while (true)
|
||||
{
|
||||
if (source[i] == end) break;
|
||||
else s += source[i];
|
||||
i++;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static bool SW(this A3DADict dict, string args, char split = '.') =>
|
||||
dict.SW(args.Split(split));
|
||||
|
||||
public static bool SW(this A3DADict dict, string[] args)
|
||||
{
|
||||
if (dict == null || args.Length < 1) return false;
|
||||
|
||||
if (args.Length > 1)
|
||||
{
|
||||
string[] newArgs = new string[args.Length - 1];
|
||||
for (int i = 0; i < args.Length - 1; i++)
|
||||
newArgs[i] = args[i + 1];
|
||||
return dict.ContainsKey(args[0]) && SW((A3DADict)dict[args[0]], newArgs);
|
||||
}
|
||||
return dict.ContainsKey(args[0]);
|
||||
}
|
||||
|
||||
public static bool FV (this A3DADict dict, ref bool value, char split, string args) =>
|
||||
dict.FV(out string val, args.Split(split)) && bool.TryParse(val, out value);
|
||||
|
||||
public static bool FV (this A3DADict dict, ref int value, char split, string args) =>
|
||||
dict.FV(out string val, args.Split(split)) && int.TryParse(val, out value);
|
||||
|
||||
public static bool FV (this A3DADict dict, ref uint value, char split, string args) =>
|
||||
dict.FV(out string val, args.Split(split)) && uint.TryParse(val, out value);
|
||||
|
||||
public static bool FV (this A3DADict dict, ref long value, char split, string args) =>
|
||||
dict.FV(out string val, args.Split(split)) && long.TryParse(val, out value);
|
||||
|
||||
public static bool FV (this A3DADict dict, ref ulong value, char split, string args) =>
|
||||
dict.FV(out string val, args.Split(split)) && ulong.TryParse(val, out value);
|
||||
|
||||
public static bool FV (this A3DADict dict, ref float value, char split, string args) =>
|
||||
dict.FV(out string val, args.Split(split)) && val.ToF32(out value);
|
||||
|
||||
public static bool FV (this A3DADict dict, ref double value, char split, string args) =>
|
||||
dict.FV(out string val, args.Split(split)) && val.ToF64(out value);
|
||||
|
||||
public static bool FV (this A3DADict dict, ref string value, char split, string args)
|
||||
{ if (dict.FV(out string val , args.Split(split)))
|
||||
{ value = val; return true; } return false; }
|
||||
|
||||
public static bool FV (this A3DADict dict, out bool value, string args)
|
||||
{ if (dict.FV(out string val , args.Split('.' )))
|
||||
return bool.TryParse(val, out value); value = false; return false; }
|
||||
|
||||
public static bool FV (this A3DADict dict, out int value, string args)
|
||||
{ if (dict.FV(out string val , args.Split('.' )))
|
||||
return int.TryParse(val, out value); value = 0; return false; }
|
||||
|
||||
public static bool FV (this A3DADict dict, out uint value, string args)
|
||||
{ if (dict.FV(out string val , args.Split('.' )))
|
||||
return uint.TryParse(val, out value); value = 0; return false; }
|
||||
|
||||
public static bool FV (this A3DADict dict, out long value, string args)
|
||||
{ if (dict.FV(out string val , args.Split('.' )))
|
||||
return long.TryParse(val, out value); value = 0; return false; }
|
||||
|
||||
public static bool FV (this A3DADict dict, out ulong value, string args)
|
||||
{ if (dict.FV(out string val , args.Split('.' )))
|
||||
return ulong.TryParse(val, out value); value = 0; return false; }
|
||||
|
||||
public static bool FV (this A3DADict dict, out float value, string args)
|
||||
{ if (dict.FV(out string val , args.Split('.' )))
|
||||
return val.ToF32(out value); value = 0; return false; }
|
||||
|
||||
public static bool FV (this A3DADict dict, out double value, string args)
|
||||
{ if (dict.FV(out string val , args.Split('.' )))
|
||||
return val.ToF64(out value); value = 0; return false; }
|
||||
|
||||
public static bool FV<T>(this A3DADict dict, out T value, string args) where T : struct, Enum
|
||||
{ if (dict.FV(out string val , args.Split('.' )))
|
||||
{ bool Val = Enum.TryParse(val, out T _value); value = _value; return Val; }
|
||||
value = default; return false; }
|
||||
|
||||
public static bool FV (this A3DADict dict, out int? value, string args)
|
||||
{ if (dict.FV(out string val , args.Split('.' )))
|
||||
{ bool Val = int.TryParse(val, out int _value); value = _value; return Val; }
|
||||
value = null; return false; }
|
||||
|
||||
public static bool FV (this A3DADict dict, out uint? value, string args)
|
||||
{ if (dict.FV(out string val , args.Split('.' )))
|
||||
{ bool Val = uint.TryParse(val, out uint _value); value = _value; return Val; }
|
||||
value = null; return false; }
|
||||
|
||||
public static bool FV (this A3DADict dict, out long? value, string args)
|
||||
{ if (dict.FV(out string val , args.Split('.' )))
|
||||
{ bool Val = long.TryParse(val, out long _value); value = _value; return Val; }
|
||||
value = null; return false; }
|
||||
|
||||
public static bool FV (this A3DADict dict, out ulong? value, string args)
|
||||
{ if (dict.FV(out string val , args.Split('.' )))
|
||||
{ bool Val = ulong.TryParse(val, out ulong _value); value = _value; return Val; }
|
||||
value = null; return false; }
|
||||
|
||||
public static bool FV (this A3DADict dict, out float? value, string args)
|
||||
{ if (dict.FV(out string val , args.Split('.' )))
|
||||
return val.ToF32(out value); value = null; return false; }
|
||||
|
||||
public static bool FV (this A3DADict dict, out double? value, string args)
|
||||
{ if (dict.FV(out string val , args.Split('.' )))
|
||||
return val.ToF64(out value); value = null; return false; }
|
||||
|
||||
public static bool FV<T>(this A3DADict dict, out T? value, string args) where T : struct
|
||||
{ if (dict.FV(out string val , args.Split('.' )))
|
||||
{ bool Val = Enum.TryParse(val, out T _value); value = _value; return Val; }
|
||||
value = null; return false; }
|
||||
|
||||
public static bool FV (this A3DADict dict, out string value, string args) =>
|
||||
dict.FV(out value, args.Split('.' ));
|
||||
|
||||
public static bool FV(this A3DADict dict, out string value, string[] args)
|
||||
{
|
||||
value = null;
|
||||
if (dict == null || args.Length < 1) return false;
|
||||
|
||||
if (!dict.ContainsKey(args[0])) return false;
|
||||
else if (args.Length > 1)
|
||||
{
|
||||
string[] newArgs = new string[args.Length - 1];
|
||||
for (int i = 0; i < args.Length - 1; i++) newArgs[i] = args[i + 1];
|
||||
return ((A3DADict)dict[args[0]]).FV(out value, newArgs);
|
||||
}
|
||||
else if (args.Length == 1)
|
||||
{
|
||||
if (dict[args[0]].GetType() == dict.GetType())
|
||||
return ((A3DADict)dict[args[0]]).FV(out value, args);
|
||||
else if (dict[args[0]].GetType() != typeof(string)) return false;
|
||||
}
|
||||
|
||||
value = (string)dict[args[0]];
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool FK(this A3DADict dict, string args) =>
|
||||
dict.FK(args.Split('.' ));
|
||||
|
||||
public static bool FK(this A3DADict dict, string[] args)
|
||||
{
|
||||
if (dict == null || args.Length < 1) return false;
|
||||
|
||||
args[0] = args[0].ToLower();
|
||||
if (!dict.ContainsKey(args[0])) return false;
|
||||
else if (args.Length > 1)
|
||||
{
|
||||
string[] newArgs = new string[args.Length - 1];
|
||||
for (int i = 0; i < args.Length - 1; i++) newArgs[i] = args[i + 1];
|
||||
return ((A3DADict)dict[args[0]]).FK(newArgs);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void GD(this A3DADict dict, string args, char split = '.')
|
||||
{
|
||||
string[] dataArray = args.Split('=');
|
||||
if (dataArray.Length == 2)
|
||||
dict.GD(dataArray[0].Split(split), dataArray[1]);
|
||||
dataArray = null;
|
||||
}
|
||||
|
||||
public static void GD(this A3DADict dict, string args, string value, char split = '.') =>
|
||||
dict.GD(args.Split(split), value);
|
||||
|
||||
public static void GD(this A3DADict dict, string[] args, string value)
|
||||
{
|
||||
if (dict == null) dict = new A3DADict();
|
||||
else if (args.Length < 1) return;
|
||||
|
||||
if (args.Length > 1)
|
||||
{
|
||||
string[] newArgs = new string[args.Length - 1];
|
||||
for (int i = 0; i < args.Length - 1; i++) newArgs[i] = args[i + 1];
|
||||
if (!dict.ContainsKey(args[0])) dict.Add(args[0], null);
|
||||
if (dict[args[0]] != null)
|
||||
{
|
||||
if (dict[args[0]].GetType() == typeof(string))
|
||||
dict[args[0]] = new A3DADict { { "", dict[args[0]] } };
|
||||
}
|
||||
else dict[args[0]] = new A3DADict();
|
||||
A3DADict bufDict = (A3DADict)dict[args[0]];
|
||||
bufDict.GD(newArgs, value);
|
||||
dict[args[0]] = bufDict;
|
||||
}
|
||||
else if (!dict.ContainsKey(args[0])) dict.Add(args[0], value);
|
||||
}
|
||||
|
||||
public static TKey GK<TKey, TVal>(this Dictionary<TKey, TVal> dict, TVal val) =>
|
||||
dict.First((System.Collections.Generic.KeyValuePair<TKey, TVal> x) => x.Value.Equals(val)).Key;
|
||||
|
||||
public static string TTC(this string s) =>
|
||||
CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s);
|
||||
|
||||
public static int[] SW(this int length)
|
||||
{
|
||||
int i, j, m;
|
||||
|
||||
if (length <= 0) return new int[0];
|
||||
if (length == 1) return new int[1] { 0 };
|
||||
|
||||
int[] sort = new int[length];
|
||||
sort[0] = 0;
|
||||
i = 1;
|
||||
j = 1;
|
||||
|
||||
m = 1;
|
||||
while (m < length)
|
||||
m *= 10;
|
||||
while (i < length)
|
||||
{
|
||||
if (j * 10 < m)
|
||||
{
|
||||
sort[i++] = j;
|
||||
j *= 10;
|
||||
}
|
||||
else if (j >= length)
|
||||
{
|
||||
m /= 10;
|
||||
j /= 10;
|
||||
while (j % 10 == 9) j /= 10;
|
||||
j++;
|
||||
}
|
||||
else if (j % 10 != 9)
|
||||
sort[i++] = j++;
|
||||
|
||||
if (i < length)
|
||||
if (j == length && j % 10 != 9)
|
||||
{
|
||||
m /= 10;
|
||||
j /= 10;
|
||||
while (j % 10 == 9) j /= 10;
|
||||
j++;
|
||||
}
|
||||
else if (j < length && j % 10 == 9)
|
||||
{
|
||||
sort[i++] = j;
|
||||
while (j % 10 == 9) j /= 10;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return sort;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct Mat2
|
||||
{
|
||||
[FieldOffset(0x00)] public Vec2 Row0;
|
||||
[FieldOffset(0x08)] public Vec2 Row1;
|
||||
|
||||
public Vec2 Column0 { get => new Vec2(Row0.X, Row1.X);
|
||||
set { Row0.X = value.X; Row1.X = value.Y; } }
|
||||
public Vec2 Column1 { get => new Vec2(Row0.Y, Row1.Y);
|
||||
set { Row0.Y = value.X; Row1.Y = value.Y; } }
|
||||
|
||||
public static Mat2 Identity => new Mat2(new Vec2(1.0f, 0.0f),
|
||||
new Vec2(0.0f, 1.0f));
|
||||
|
||||
public Mat2(Vec2 row0, Vec2 row1)
|
||||
{ Row0 = row0; Row1 = row1; }
|
||||
|
||||
public Mat2 Invert() => -this;
|
||||
|
||||
public static Mat2 operator +(Mat2 left, Mat2 right)
|
||||
{ left.Row0 += right.Row0; left.Row1 += right.Row1; return left; }
|
||||
|
||||
public static Mat2 operator -(Mat2 left, Mat2 right)
|
||||
{ left.Row0 -= right.Row0; left.Row1 -= right.Row1; return left; }
|
||||
|
||||
public static Mat2 operator -(Mat2 mat)
|
||||
{
|
||||
int[] colIdx = { 0, 0 };
|
||||
int[] rowIdx = { 0, 0 };
|
||||
int[] pivotIdx = { -1, -1 };
|
||||
|
||||
Mat2 result = mat;
|
||||
float[,] inverse =
|
||||
{
|
||||
{ mat.Row0.X, mat.Row0.Y },
|
||||
{ mat.Row1.X, mat.Row1.Y }
|
||||
};
|
||||
int icol = 0;
|
||||
int irow = 0;
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
float maxPivot = 0.0f;
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
if (pivotIdx[j] == 0) continue;
|
||||
|
||||
for (int k = 0; k < 2; k++)
|
||||
{
|
||||
if (pivotIdx[k] == -1)
|
||||
{
|
||||
float absVal = System.Math.Abs(inverse[j, k]);
|
||||
if (absVal > maxPivot)
|
||||
{
|
||||
maxPivot = absVal;
|
||||
irow = j;
|
||||
icol = k;
|
||||
}
|
||||
}
|
||||
else if (pivotIdx[k] > 0)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
pivotIdx[icol]++;
|
||||
|
||||
if (irow != icol)
|
||||
for (int k = 0; k < 2; k++)
|
||||
{ float t = inverse[irow, k]; inverse[irow, k] = inverse[icol, k]; inverse[icol, k] = t; }
|
||||
|
||||
rowIdx[i] = irow;
|
||||
colIdx[i] = icol;
|
||||
|
||||
float pivot = inverse[icol, icol];
|
||||
|
||||
float oneOverPivot = 1.0f / pivot;
|
||||
inverse[icol, icol] = 1.0f;
|
||||
for (int k = 0; k < 2; k++)
|
||||
inverse[icol, k] *= oneOverPivot;
|
||||
|
||||
for (int j = 0; j < 2; j++)
|
||||
{
|
||||
if (icol == j) continue;
|
||||
|
||||
float f = inverse[j, icol];
|
||||
inverse[j, icol] = 0.0f;
|
||||
for (int k = 0; k < 3; k++)
|
||||
inverse[j, k] -= inverse[icol, k] * f;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 1; j >= 0; j--)
|
||||
{
|
||||
int ir = rowIdx[j];
|
||||
int ic = colIdx[j];
|
||||
for (int k = 0; k < 2; k++)
|
||||
{ float t = inverse[k, ic]; inverse[k, ic] = inverse[k, ir]; inverse[k, ir] = t; }
|
||||
}
|
||||
|
||||
result.Row0.X = inverse[0, 0]; result.Row0.Y = inverse[0, 1];
|
||||
result.Row1.X = inverse[1, 0]; result.Row1.Y = inverse[1, 1];
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Mat2 operator *(Mat2 left, Mat2 right)
|
||||
{
|
||||
Mat2 result = default;
|
||||
result.Row0 = left.Row0.X * right.Row0 + left.Row0.Y * right.Row1;
|
||||
result.Row1 = left.Row1.X * right.Row0 + left.Row1.Y * right.Row1;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Mat2 operator *(Mat2 mat, float scale) =>
|
||||
new Mat2(mat.Row0 * scale, mat.Row1 * scale);
|
||||
|
||||
public static bool operator ==(Mat2 A, Mat2 B) => A.Equals(B);
|
||||
public static bool operator !=(Mat2 A, Mat2 B) => !A.Equals(B);
|
||||
|
||||
public bool Equals(Mat2 other) =>
|
||||
Row0 == other.Row0 && Row1 == other.Row1;
|
||||
|
||||
public override bool Equals(object obj) => base.Equals(obj);
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
public override string ToString() => $"({Row0}; {Row1})";
|
||||
public string ToString(int d) => $"({Row0.ToString(d)}; {Row1.ToString(d)})";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct Mat3
|
||||
{
|
||||
[FieldOffset(0x00)] public Vec3 Row0;
|
||||
[FieldOffset(0x0C)] public Vec3 Row1;
|
||||
[FieldOffset(0x18)] public Vec3 Row2;
|
||||
|
||||
public Vec3 Column0 { get => new Vec3(Row0.X, Row1.X, Row2.X);
|
||||
set { Row0.X = value.X; Row1.X = value.Y; Row2.X = value.Z; } }
|
||||
public Vec3 Column1 { get => new Vec3(Row0.Y, Row1.Y, Row2.Y);
|
||||
set { Row0.Y = value.X; Row1.Y = value.Y; Row2.Y = value.Z; } }
|
||||
public Vec3 Column2 { get => new Vec3(Row0.Z, Row1.Z, Row2.Z);
|
||||
set { Row0.Z = value.X; Row1.Z = value.Y; Row2.Z = value.Z;} }
|
||||
|
||||
public static Mat3 Identity => new Mat3(new Vec3(1.0f, 0.0f, 0.0f),
|
||||
new Vec3(0.0f, 1.0f, 0.0f),
|
||||
new Vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
public Mat3(float m00, float m01, float m02, float m10, float m11, float m12, float m20, float m21, float m22)
|
||||
{ Row0 = new Vec3(m00, m01, m02); Row1 = new Vec3(m10, m11, m12); Row2 = new Vec3(m20, m21, m22);}
|
||||
|
||||
public Mat3(Vec3 row0, Vec3 row1, Vec3 row2)
|
||||
{ Row0 = row0; Row1 = row1; Row2 = row2; }
|
||||
|
||||
public Mat3(Mat4 mat)
|
||||
{ Row0 = new Vec3(mat.Row0); Row1 = new Vec3(mat.Row1); Row2 = new Vec3(mat.Row2); }
|
||||
|
||||
public Mat3(Quat q)
|
||||
{
|
||||
float qx = q.X;
|
||||
float qy = q.Y;
|
||||
float qz = q.Z;
|
||||
float qw = q.W;
|
||||
float g = qx + qx;
|
||||
float h = qy + qy;
|
||||
float k = qz + qz;
|
||||
float a = qx * g;
|
||||
float l = qx * h;
|
||||
float m = qy * h;
|
||||
qx *= k;
|
||||
qy *= k;
|
||||
qz *= k;
|
||||
|
||||
Row0 = new Vec3(1.0f - qz - m, l - qw * k, qx + qw * h);
|
||||
Row1 = new Vec3( l + qw * k, 1.0f - qz - a, qy - qw * g);
|
||||
Row2 = new Vec3( qx - qw * h, qy + qw * g, 1.0f - m - a);
|
||||
}
|
||||
|
||||
public Quat ToQuat()
|
||||
{
|
||||
Vec3 row0 = Row0;
|
||||
Vec3 row1 = Row1;
|
||||
Vec3 row2 = Row2;
|
||||
|
||||
Quat q = default;
|
||||
var trace = 0.25 * (row0.X + row1.Y + row2.Z+ 1.0);
|
||||
|
||||
if (trace > 0)
|
||||
{
|
||||
double sq = System.Math.Sqrt(trace);
|
||||
|
||||
q.W = (float)sq;
|
||||
sq = 1.0 / (4.0 * sq);
|
||||
q.X = (float)((row1.Z - row2.Y) * sq);
|
||||
q.Y = (float)((row2.X - row0.Z) * sq);
|
||||
q.Z = (float)((row0.Y - row1.X) * sq);
|
||||
}
|
||||
else if (row0.X > row1.Y && row0.X > row2.Z)
|
||||
{
|
||||
double sq = 2.0 * System.Math.Sqrt(1.0 + row0.X - row1.Y - row2.Z);
|
||||
|
||||
q.X = (float)(0.25 * sq);
|
||||
sq = 1.0 / sq;
|
||||
q.W = (float)((row2.Y - row1.Z) * sq);
|
||||
q.Y = (float)((row1.X + row0.Y) * sq);
|
||||
q.Z = (float)((row2.X + row0.Z) * sq);
|
||||
}
|
||||
else if (row1.Y > row2.Z)
|
||||
{
|
||||
double sq = 2.0 * System.Math.Sqrt(1.0 + row1.Y - row0.X - row2.Z);
|
||||
|
||||
q.Y = (float)(0.25 * sq);
|
||||
sq = 1.0 / sq;
|
||||
q.W = (float)((row2.X - row0.Z) * sq);
|
||||
q.X = (float)((row1.X + row0.Y) * sq);
|
||||
q.Z = (float)((row2.Y + row1.Z) * sq);
|
||||
}
|
||||
else
|
||||
{
|
||||
double sq = 2.0 * System.Math.Sqrt(1.0 + row2.Z - row0.X - row1.Y);
|
||||
|
||||
q.Z = (float)(0.25 * sq);
|
||||
sq = 1.0 / sq;
|
||||
q.W = (float)((row1.X - row0.Y) * sq);
|
||||
q.X = (float)((row2.X + row0.Z) * sq);
|
||||
q.Y = (float)((row2.Y + row1.Z) * sq);
|
||||
}
|
||||
|
||||
return q.Normalized;
|
||||
}
|
||||
|
||||
public Mat3 Invert() => -this;
|
||||
|
||||
public static Mat3 operator +(Mat3 left, Mat3 right)
|
||||
{ left.Row0 += right.Row0; left.Row1 += right.Row1; left.Row2 += right.Row2; return left; }
|
||||
|
||||
public static Mat3 operator -(Mat3 left, Mat3 right)
|
||||
{ left.Row0 -= right.Row0; left.Row1 -= right.Row1; left.Row2 -= right.Row2; return left; }
|
||||
|
||||
public static Mat3 operator -(Mat3 mat)
|
||||
{
|
||||
int[] colIdx = { 0, 0, 0 };
|
||||
int[] rowIdx = { 0, 0, 0 };
|
||||
int[] pivotIdx = { -1, -1, -1 };
|
||||
|
||||
Mat3 result = mat;
|
||||
float[,] inverse =
|
||||
{
|
||||
{ mat.Row0.X, mat.Row0.Y, mat.Row0.Z },
|
||||
{ mat.Row1.X, mat.Row1.Y, mat.Row1.Z },
|
||||
{ mat.Row2.X, mat.Row2.Y, mat.Row2.Z }
|
||||
};
|
||||
int icol = 0;
|
||||
int irow = 0;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
float maxPivot = 0.0f;
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
if (pivotIdx[j] == 0) continue;
|
||||
|
||||
for (int k = 0; k < 3; k++)
|
||||
{
|
||||
if (pivotIdx[k] == -1)
|
||||
{
|
||||
float absVal = System.Math.Abs(inverse[j, k]);
|
||||
if (absVal > maxPivot)
|
||||
{
|
||||
maxPivot = absVal;
|
||||
irow = j;
|
||||
icol = k;
|
||||
}
|
||||
}
|
||||
else if (pivotIdx[k] > 0)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
pivotIdx[icol]++;
|
||||
|
||||
if (irow != icol)
|
||||
for (int k = 0; k < 3; k++)
|
||||
{ float t = inverse[irow, k]; inverse[irow, k] = inverse[icol, k]; inverse[icol, k] = t; }
|
||||
|
||||
rowIdx[i] = irow;
|
||||
colIdx[i] = icol;
|
||||
|
||||
float pivot = inverse[icol, icol];
|
||||
|
||||
float oneOverPivot = 1.0f / pivot;
|
||||
inverse[icol, icol] = 1.0f;
|
||||
for (int k = 0; k < 3; k++)
|
||||
inverse[icol, k] *= oneOverPivot;
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
if (icol == j) continue;
|
||||
|
||||
float f = inverse[j, icol];
|
||||
inverse[j, icol] = 0.0f;
|
||||
for (int k = 0; k < 3; k++)
|
||||
inverse[j, k] -= inverse[icol, k] * f;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 2; j >= 0; j--)
|
||||
{
|
||||
int ir = rowIdx[j];
|
||||
int ic = colIdx[j];
|
||||
for (int k = 0; k < 3; k++)
|
||||
{ float t = inverse[k, ic]; inverse[k, ic] = inverse[k, ir]; inverse[k, ir] = t; }
|
||||
}
|
||||
|
||||
result.Row0.X = inverse[0, 0]; result.Row0.Y = inverse[0, 1]; result.Row0.Z = inverse[0, 2];
|
||||
result.Row1.X = inverse[1, 0]; result.Row1.Y = inverse[1, 1]; result.Row1.Z = inverse[1, 2];
|
||||
result.Row2.X = inverse[2, 0]; result.Row2.Y = inverse[2, 1]; result.Row2.Z = inverse[2, 2];
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Mat3 operator *(Mat3 left, Mat3 right)
|
||||
{
|
||||
Mat3 result = default;
|
||||
result.Row0 = left.Row0.X * right.Row0 + left.Row0.Y * right.Row1 + left.Row0.Z * right.Row2;
|
||||
result.Row1 = left.Row1.X * right.Row0 + left.Row1.Y * right.Row1 + left.Row1.Z * right.Row2;
|
||||
result.Row2 = left.Row2.X * right.Row0 + left.Row2.Y * right.Row1 + left.Row2.Z * right.Row2;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Mat3 operator *(Mat3 mat, float scale) =>
|
||||
new Mat3(mat.Row0 * scale, mat.Row1 * scale, mat.Row2 * scale);
|
||||
|
||||
public static bool operator ==(Mat3 A, Mat3 B) => A.Equals(B);
|
||||
public static bool operator !=(Mat3 A, Mat3 B) => !A.Equals(B);
|
||||
|
||||
public bool Equals(Mat3 other) =>
|
||||
Row0 == other.Row0 && Row1 == other.Row1 && Row2 == other.Row2;
|
||||
|
||||
public override bool Equals(object obj) => base.Equals(obj);
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
public override string ToString() => $"({Row0}; {Row1}; {Row2})";
|
||||
public string ToString(int d) => $"({Row0.ToString(d)}; {Row1.ToString(d)}; {Row2.ToString(d)})";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct Mat4
|
||||
{
|
||||
[FieldOffset(0x00)] public Vec4 Row0;
|
||||
[FieldOffset(0x10)] public Vec4 Row1;
|
||||
[FieldOffset(0x20)] public Vec4 Row2;
|
||||
[FieldOffset(0x30)] public Vec4 Row3;
|
||||
|
||||
public Vec4 Column0 { get => new Vec4(Row0.X, Row1.X, Row2.X, Row3.X);
|
||||
set { Row0.X = value.X; Row1.X = value.Y; Row2.X = value.Z; Row3.X = value.W; } }
|
||||
public Vec4 Column1 { get => new Vec4(Row0.Y, Row1.Y, Row2.Y, Row3.Y);
|
||||
set { Row0.Y = value.X; Row1.Y = value.Y; Row2.Y = value.Z; Row3.Y = value.W; } }
|
||||
public Vec4 Column2 { get => new Vec4(Row0.Z, Row1.Z, Row2.Z, Row3.Z);
|
||||
set { Row0.Z = value.X; Row1.Z = value.Y; Row2.Z = value.Z; Row3.Z = value.W; } }
|
||||
public Vec4 Column3 { get => new Vec4(Row0.W, Row1.W, Row2.W, Row3.W);
|
||||
set { Row0.W = value.X; Row1.W = value.Y; Row2.W = value.Z; Row3.W = value.W; } }
|
||||
|
||||
public static Mat4 Identity => new Mat4(new Vec4(1.0f, 0.0f, 0.0f, 0.0f),
|
||||
new Vec4(0.0f, 1.0f, 0.0f, 0.0f),
|
||||
new Vec4(0.0f, 0.0f, 1.0f, 0.0f),
|
||||
new Vec4(0.0f, 0.0f, 0.0f, 1.0f));
|
||||
|
||||
public Mat4(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13,
|
||||
float m20, float m21, float m22, float m23, float m30, float m31, float m32, float m33)
|
||||
{ Row0 = new Vec4(m00, m01, m02, m03); Row1 = new Vec4(m10, m11, m12, m13);
|
||||
Row2 = new Vec4(m20, m21, m22, m23); Row3 = new Vec4(m30, m31, m32, m33); }
|
||||
|
||||
public Mat4(Vec4 row0, Vec4 row1, Vec4 row2, Vec4 row3)
|
||||
{ Row0 = row0; Row1 = row1; Row2 = row2; Row3 = row3; }
|
||||
|
||||
public Mat4(Mat3 mat)
|
||||
{ Row0 = new Vec4(mat.Row0); Row1 = new Vec4(mat.Row1);
|
||||
Row2 = new Vec4(mat.Row2); Row3 = new Vec4(0.0f, 0.0f, 0.0f, 1.0f); }
|
||||
|
||||
public Mat4(Quat q)
|
||||
{ Row0 = Row1 = Row2 = Row3 = default; FromQuat(q); }
|
||||
|
||||
public Mat4(Quat q, Vec3 t)
|
||||
{ Row0 = Row1 = Row2 = Row3 = default; FromQuat(q); Row3 = new Vec4(t, 1.0f); }
|
||||
|
||||
public Mat4(Quat q, Vec4 t)
|
||||
{ Row0 = Row1 = Row2 = Row3 = default; FromQuat(q); Row3 = t; }
|
||||
|
||||
private void FromQuat(Quat q)
|
||||
{
|
||||
float qx = q.X;
|
||||
float qy = q.Y;
|
||||
float qz = q.Z;
|
||||
float qw = q.W;
|
||||
|
||||
float g = qx + qx;
|
||||
float h = qy + qy;
|
||||
float k = qz + qz;
|
||||
float a = qx * g;
|
||||
float l = qx * h;
|
||||
float m = qy * h;
|
||||
qx *= k;
|
||||
qy *= k;
|
||||
qz *= k;
|
||||
|
||||
Row0 = new Vec4(1.0f - (qz + m), l - qw * k , qx + qw * h , 0.0f);
|
||||
Row1 = new Vec4( l + qw * k , 1.0f - (qz + a), qy - qw * g , 0.0f);
|
||||
Row2 = new Vec4( qx - qw * h , qy + qw * g , 1.0f - (a + m), 0.0f);
|
||||
Row3 = new Vec4(0.0f , 0.0f , 0.0f , 1.0f);
|
||||
}
|
||||
|
||||
public Quat ToQuat()
|
||||
{
|
||||
Vec4 row0 = Row0;
|
||||
Vec4 row1 = Row1;
|
||||
Vec4 row2 = Row2;
|
||||
|
||||
Quat q = default;
|
||||
var trace = 0.25 * (row0.X + row1.Y + row2.Z+ 1.0);
|
||||
|
||||
if (trace > 0)
|
||||
{
|
||||
double sq = System.Math.Sqrt(trace);
|
||||
|
||||
q.W = (float)sq;
|
||||
sq = 1.0 / (4.0 * sq);
|
||||
q.X = (float)((row1.Z - row2.Y) * sq);
|
||||
q.Y = (float)((row2.X - row0.Z) * sq);
|
||||
q.Z = (float)((row0.Y - row1.X) * sq);
|
||||
}
|
||||
else if (row0.X > row1.Y && row0.X > row2.Z)
|
||||
{
|
||||
double sq = 2.0 * System.Math.Sqrt(1.0 + row0.X - row1.Y - row2.Z);
|
||||
|
||||
q.X = (float)(0.25 * sq);
|
||||
sq = 1.0 / sq;
|
||||
q.W = (float)((row2.Y - row1.Z) * sq);
|
||||
q.Y = (float)((row1.X + row0.Y) * sq);
|
||||
q.Z = (float)((row2.X + row0.Z) * sq);
|
||||
}
|
||||
else if (row1.Y > row2.Z)
|
||||
{
|
||||
double sq = 2.0 * System.Math.Sqrt(1.0 + row1.Y - row0.X - row2.Z);
|
||||
|
||||
q.Y = (float)(0.25 * sq);
|
||||
sq = 1.0 / sq;
|
||||
q.W = (float)((row2.X - row0.Z) * sq);
|
||||
q.X = (float)((row1.X + row0.Y) * sq);
|
||||
q.Z = (float)((row2.Y + row1.Z) * sq);
|
||||
}
|
||||
else
|
||||
{
|
||||
double sq = 2.0 * System.Math.Sqrt(1.0 + row2.Z - row0.X - row1.Y);
|
||||
|
||||
q.Z = (float)(0.25 * sq);
|
||||
sq = 1.0 / sq;
|
||||
q.W = (float)((row1.X - row0.Y) * sq);
|
||||
q.X = (float)((row2.X + row0.Z) * sq);
|
||||
q.Y = (float)((row2.Y + row1.Z) * sq);
|
||||
}
|
||||
|
||||
return q.Normalized;
|
||||
}
|
||||
|
||||
public Mat4 Invert() => -this;
|
||||
|
||||
public Mat4 Translate(Vec3 vec)
|
||||
{ Row3 = new Vec4(vec, 1.0f) * this; return this; }
|
||||
|
||||
public Mat4 Translate(Vec4 vec)
|
||||
{ Row3 = vec * this; return this; }
|
||||
|
||||
public static Mat4 operator +(Mat4 left, Mat4 right)
|
||||
{ left.Row0 += right.Row0; left.Row1 += right.Row1;
|
||||
left.Row2 += right.Row2; left.Row3 += right.Row3; return left; }
|
||||
|
||||
public static Mat4 operator -(Mat4 left, Mat4 right)
|
||||
{ left.Row0 -= right.Row0; left.Row1 -= right.Row1;
|
||||
left.Row2 -= right.Row2; left.Row3 -= right.Row3; return left; }
|
||||
|
||||
public static Mat4 operator -(Mat4 mat)
|
||||
{
|
||||
int[] colIdx = { 0, 0, 0, 0 };
|
||||
int[] rowIdx = { 0, 0, 0, 0 };
|
||||
int[] pivotIdx = { -1, -1, -1, -1 };
|
||||
|
||||
Mat4 result = mat;
|
||||
float[,] inverse =
|
||||
{
|
||||
{ mat.Row0.X, mat.Row0.Y, mat.Row0.Z, mat.Row0.W },
|
||||
{ mat.Row1.X, mat.Row1.Y, mat.Row1.Z, mat.Row1.W },
|
||||
{ mat.Row2.X, mat.Row2.Y, mat.Row2.Z, mat.Row2.W },
|
||||
{ mat.Row3.X, mat.Row3.Y, mat.Row3.Z, mat.Row3.W }
|
||||
};
|
||||
int icol = 0;
|
||||
int irow = 0;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
float maxPivot = 0.0f;
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
if (pivotIdx[j] == 0) continue;
|
||||
|
||||
for (int k = 0; k < 4; k++)
|
||||
{
|
||||
if (pivotIdx[k] == -1)
|
||||
{
|
||||
float absVal = System.Math.Abs(inverse[j, k]);
|
||||
if (absVal > maxPivot)
|
||||
{
|
||||
maxPivot = absVal;
|
||||
irow = j;
|
||||
icol = k;
|
||||
}
|
||||
}
|
||||
else if (pivotIdx[k] > 0)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
pivotIdx[icol]++;
|
||||
|
||||
if (irow != icol)
|
||||
for (int k = 0; k < 4; k++)
|
||||
{ float t = inverse[irow, k]; inverse[irow, k] = inverse[icol, k]; inverse[icol, k] = t; }
|
||||
|
||||
rowIdx[i] = irow;
|
||||
colIdx[i] = icol;
|
||||
|
||||
float pivot = inverse[icol, icol];
|
||||
|
||||
float oneOverPivot = 1.0f / pivot;
|
||||
inverse[icol, icol] = 1.0f;
|
||||
for (int k = 0; k < 4; k++)
|
||||
inverse[icol, k] *= oneOverPivot;
|
||||
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
if (icol == j) continue;
|
||||
|
||||
float f = inverse[j, icol];
|
||||
inverse[j, icol] = 0.0f;
|
||||
for (int k = 0; k < 4; k++)
|
||||
inverse[j, k] -= inverse[icol, k] * f;
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 3; j >= 0; j--)
|
||||
{
|
||||
int ir = rowIdx[j];
|
||||
int ic = colIdx[j];
|
||||
for (int k = 0; k < 4; k++)
|
||||
{ float t = inverse[k, ic]; inverse[k, ic] = inverse[k, ir]; inverse[k, ir] = t; }
|
||||
}
|
||||
|
||||
result.Row0.X = inverse[0, 0]; result.Row0.Y = inverse[0, 1];
|
||||
result.Row0.Z = inverse[0, 2]; result.Row0.W = inverse[0, 3];
|
||||
result.Row1.X = inverse[1, 0]; result.Row1.Y = inverse[1, 1];
|
||||
result.Row1.Z = inverse[1, 2]; result.Row1.W = inverse[1, 3];
|
||||
result.Row2.X = inverse[2, 0]; result.Row2.Y = inverse[2, 1];
|
||||
result.Row2.Z = inverse[2, 2]; result.Row2.W = inverse[2, 3];
|
||||
result.Row3.X = inverse[3, 0]; result.Row3.Y = inverse[3, 1];
|
||||
result.Row3.Z = inverse[3, 2]; result.Row3.W = inverse[3, 3];
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Mat4 operator *(Mat4 left, Mat4 right)
|
||||
{
|
||||
Mat4 result = default;
|
||||
result.Row0 = left.Row0.X * right.Row0 + left.Row0.Y * right.Row1
|
||||
+ left.Row0.Z * right.Row2 + left.Row0.W * right.Row3;
|
||||
result.Row1 = left.Row1.X * right.Row0 + left.Row1.Y * right.Row1
|
||||
+ left.Row1.Z * right.Row2 + left.Row1.W * right.Row3;
|
||||
result.Row2 = left.Row2.X * right.Row0 + left.Row2.Y * right.Row1
|
||||
+ left.Row2.Z * right.Row2 + left.Row2.W * right.Row3;
|
||||
result.Row3 = left.Row3.X * right.Row0 + left.Row3.Y * right.Row1
|
||||
+ left.Row3.Z * right.Row2 + left.Row3.W * right.Row3;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Mat4 operator *(Mat4 mat, float scale) =>
|
||||
new Mat4(mat.Row0 * scale, mat.Row1 * scale, mat.Row2 * scale, mat.Row3 * scale);
|
||||
|
||||
public static bool operator ==(Mat4 A, Mat4 B) => A.Equals(B);
|
||||
public static bool operator !=(Mat4 A, Mat4 B) => !A.Equals(B);
|
||||
|
||||
public bool Equals(Mat4 other) =>
|
||||
Row0 == other.Row0 && Row1 == other.Row1 && Row2 == other.Row2 && Row3 == other.Row3;
|
||||
|
||||
public override bool Equals(object obj) => base.Equals(obj);
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
public override string ToString() => $"({Row0}; {Row1}; {Row2}; {Row3})";
|
||||
public string ToString(int d) => $"({Row0.ToString(d)}; {Row1.ToString(d)}; {Row2.ToString(d)}; {Row3.ToString(d)})";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,407 @@
|
||||
using System;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct MsgPack : IDisposable, IEquatable<MsgPack>, INull
|
||||
{
|
||||
public string Name;
|
||||
public object Object;
|
||||
|
||||
public MsgPack[] Array => Object is MsgPack[] Array ? Array : null;
|
||||
public KKdList<MsgPack> List => Object is KKdList<MsgPack> List ? List : default;
|
||||
|
||||
public static MsgPack New => new MsgPack { Object = KKdList<MsgPack>.New };
|
||||
public static MsgPack NewReserve(int capacity) =>
|
||||
new MsgPack { Object = KKdList<MsgPack>.NewReserve(capacity) };
|
||||
|
||||
public bool IsNull => Array == null && List. IsNull;
|
||||
public bool NotNull => Array != null || List.NotNull;
|
||||
|
||||
public MsgPack( string name = null)
|
||||
{ Object = KKdList<MsgPack>.New; Name = name; }
|
||||
|
||||
public MsgPack(long count, string name = null)
|
||||
{ Object = count > -1 ? new MsgPack[count] : null; this.Name = name; }
|
||||
|
||||
public MsgPack(string name, object @object)
|
||||
{ Name = name; Object = @object; }
|
||||
|
||||
public MsgPack this[ int index]
|
||||
{ get => Object is MsgPack[] Array ? Array[index] : default;
|
||||
set { if (Object is MsgPack[] Array) { Array[index] = value; Object = Array; } } }
|
||||
|
||||
public MsgPack this[uint index]
|
||||
{ get => Object is MsgPack[] Array ? Array[index] : default;
|
||||
set { if (Object is MsgPack[] Array) { Array[index] = value; Object = Array; } } }
|
||||
|
||||
public MsgPack this[long index]
|
||||
{ get => Object is MsgPack[] Array ? Array[index] : default;
|
||||
set { if (Object is MsgPack[] Array) { Array[index] = value; Object = Array; } } }
|
||||
|
||||
public MsgPack this[string key]
|
||||
{ get => Object is KKdList<MsgPack> List ? List[ElementIndex(key)] : default;
|
||||
set { if (Object is KKdList<MsgPack> List && value.Object != null)
|
||||
{ List.Add(value); Object = List; } } }
|
||||
|
||||
public MsgPack this[string key, bool array]
|
||||
{ get { if (!array) return this[key];
|
||||
if (Object is KKdList<MsgPack> List) { MsgPack MsgPack = List[ElementIndex(key)];
|
||||
return MsgPack.Object is MsgPack[] ? MsgPack : default; } return default; } }
|
||||
|
||||
public MsgPack this[bool startsWith, string key]
|
||||
{ get { if (Object is KKdList<MsgPack> List) { MsgPack MsgPack =
|
||||
List[startsWith ? ElementIndexStartsWith(key) : ElementIndex(key)];
|
||||
return MsgPack.Object is MsgPack[] ? MsgPack : default; } return default; } }
|
||||
|
||||
public MsgPack Add(MsgPack obj)
|
||||
{ if (Object is KKdList<MsgPack> List && obj.Object != null) { List.Add(obj); Object = List; } return this; }
|
||||
|
||||
public void Dispose()
|
||||
{ Name = null; Object = null; }
|
||||
|
||||
public bool Equals(MsgPack msg) =>
|
||||
Name == msg.Name && Object == msg.Object;
|
||||
|
||||
public override string ToString() => Name ?? "" + (Object != null ?
|
||||
(List. NotNull ? $"{(Name != null ? " " : "")}Elements Count: {List .Count }" :
|
||||
(Array != null ? $"{(Name != null ? " " : "")}Elements Count: {Array.Length}" : Object)) : "");
|
||||
|
||||
public static implicit operator MsgPack(byte[] val) => new MsgPack(null, val);
|
||||
public static implicit operator MsgPack(string val) => new MsgPack(null, val);
|
||||
public static implicit operator MsgPack( sbyte val) => new MsgPack(null, val);
|
||||
public static implicit operator MsgPack( byte val) => new MsgPack(null, val);
|
||||
public static implicit operator MsgPack( short val) => new MsgPack(null, val);
|
||||
public static implicit operator MsgPack(ushort val) => new MsgPack(null, val);
|
||||
public static implicit operator MsgPack( int val) => new MsgPack(null, val);
|
||||
public static implicit operator MsgPack( uint val) => new MsgPack(null, val);
|
||||
public static implicit operator MsgPack( long val) => new MsgPack(null, val);
|
||||
public static implicit operator MsgPack( ulong val) => new MsgPack(null, val);
|
||||
public static implicit operator MsgPack( float val) => new MsgPack(null, val);
|
||||
public static implicit operator MsgPack(double val) => new MsgPack(null, val);
|
||||
|
||||
public MsgPack Add( bool? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( sbyte? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( byte? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( short? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add(ushort? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( int? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( uint? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( long? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( ulong? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( float? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add(double? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
|
||||
public MsgPack Add(byte[] val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add(string val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( bool val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( sbyte val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( byte val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( short val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add(ushort val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( int val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( uint val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( long val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( ulong val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( float val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add(double val) => Add(new MsgPack(null, val));
|
||||
|
||||
public MsgPack Add(string Name, bool? val) => val.HasValue ? Add(Name, val.Value) : this;
|
||||
public MsgPack Add(string Name, sbyte? val) => val.HasValue ? Add(Name, val.Value) : this;
|
||||
public MsgPack Add(string Name, byte? val) => val.HasValue ? Add(Name, val.Value) : this;
|
||||
public MsgPack Add(string Name, short? val) => val.HasValue ? Add(Name, val.Value) : this;
|
||||
public MsgPack Add(string Name, ushort? val) => val.HasValue ? Add(Name, val.Value) : this;
|
||||
public MsgPack Add(string Name, int? val) => val.HasValue ? Add(Name, val.Value) : this;
|
||||
public MsgPack Add(string Name, uint? val) => val.HasValue ? Add(Name, val.Value) : this;
|
||||
public MsgPack Add(string Name, long? val) => val.HasValue ? Add(Name, val.Value) : this;
|
||||
public MsgPack Add(string Name, ulong? val) => val.HasValue ? Add(Name, val.Value) : this;
|
||||
public MsgPack Add(string Name, float? val) => val.HasValue ? Add(Name, val.Value) : this;
|
||||
public MsgPack Add(string Name, double? val) => val.HasValue ? Add(Name, val.Value) : this;
|
||||
|
||||
public MsgPack Add(string Name, byte[] val) => Add(new MsgPack(Name, val));
|
||||
public MsgPack Add(string Name, string val) => Add(new MsgPack(Name, val));
|
||||
public MsgPack Add(string Name, bool val) => Add(new MsgPack(Name, val));
|
||||
public MsgPack Add(string Name, sbyte val) => Add(new MsgPack(Name, val));
|
||||
public MsgPack Add(string Name, byte val) => Add(new MsgPack(Name, val));
|
||||
public MsgPack Add(string Name, short val) => Add(new MsgPack(Name, val));
|
||||
public MsgPack Add(string Name, ushort val) => Add(new MsgPack(Name, val));
|
||||
public MsgPack Add(string Name, int val) => Add(new MsgPack(Name, val));
|
||||
public MsgPack Add(string Name, uint val) => Add(new MsgPack(Name, val));
|
||||
public MsgPack Add(string Name, long val) => Add(new MsgPack(Name, val));
|
||||
public MsgPack Add(string Name, ulong val) => Add(new MsgPack(Name, val));
|
||||
public MsgPack Add(string Name, float val) => Add(new MsgPack(Name, val));
|
||||
public MsgPack Add(string Name, double val) => Add(new MsgPack(Name, val));
|
||||
|
||||
public bool RB (string name) => RnB (name) ?? default;
|
||||
public sbyte RI8 (string name) => RnI8 (name) ?? default;
|
||||
public byte RU8 (string name) => RnU8 (name) ?? default;
|
||||
public short RI16(string name) => RnI16(name) ?? default;
|
||||
public ushort RU16(string name) => RnU16(name) ?? default;
|
||||
public int RI32(string name) => RnI32(name) ?? default;
|
||||
public uint RU32(string name) => RnU32(name) ?? default;
|
||||
public long RI64(string name) => RnI64(name) ?? default;
|
||||
public ulong RU64(string name) => RnU64(name) ?? default;
|
||||
public float RF32(string name) => RnF32(name) ?? default;
|
||||
public double RF64(string name) => RnF64(name) ?? default;
|
||||
|
||||
public void R(string name, out bool? val) { val = RnB (name); }
|
||||
public void R(string name, out sbyte? val) { val = RnI8 (name); }
|
||||
public void R(string name, out byte? val) { val = RnU8 (name); }
|
||||
public void R(string name, out short? val) { val = RnI16(name); }
|
||||
public void R(string name, out ushort? val) { val = RnU16(name); }
|
||||
public void R(string name, out int? val) { val = RnI32(name); }
|
||||
public void R(string name, out uint? val) { val = RnU32(name); }
|
||||
public void R(string name, out long? val) { val = RnI64(name); }
|
||||
public void R(string name, out ulong? val) { val = RnU64(name); }
|
||||
public void R(string name, out float? val) { val = RnF32(name); }
|
||||
public void R(string name, out double? val) { val = RnF64(name); }
|
||||
|
||||
public void R(string name, out bool val) { val = RB (name); }
|
||||
public void R(string name, out sbyte val) { val = RI8 (name); }
|
||||
public void R(string name, out byte val) { val = RU8 (name); }
|
||||
public void R(string name, out short val) { val = RI16(name); }
|
||||
public void R(string name, out ushort val) { val = RU16(name); }
|
||||
public void R(string name, out int val) { val = RI32(name); }
|
||||
public void R(string name, out uint val) { val = RU32(name); }
|
||||
public void R(string name, out long val) { val = RI64(name); }
|
||||
public void R(string name, out ulong val) { val = RU64(name); }
|
||||
public void R(string name, out float val) { val = RF32(name); }
|
||||
public void R(string name, out double val) { val = RF64(name); }
|
||||
public void R(string name, out string val) { val = RS (name); }
|
||||
|
||||
public bool? RnB (string name)
|
||||
{
|
||||
MsgPack MsgPack = this[name];
|
||||
if (MsgPack.Object is bool B ) return B ; return null;
|
||||
}
|
||||
public sbyte? RnI8 (string name)
|
||||
{
|
||||
MsgPack MsgPack = this[name];
|
||||
if (MsgPack.Object is sbyte I8 ) return I8 ;
|
||||
else if (MsgPack.Object is byte U8 ) return ( sbyte)U8 ; return null;
|
||||
}
|
||||
public byte? RnU8 (string name)
|
||||
{
|
||||
MsgPack MsgPack = this[name];
|
||||
if (MsgPack.Object is sbyte I8 ) return ( byte)I8 ;
|
||||
else if (MsgPack.Object is byte U8 ) return U8 ; return null;
|
||||
}
|
||||
public short? RnI16(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[name];
|
||||
if (MsgPack.Object is sbyte I8 ) return I8 ;
|
||||
else if (MsgPack.Object is byte U8 ) return U8 ;
|
||||
else if (MsgPack.Object is short I16) return I16;
|
||||
else if (MsgPack.Object is ushort U16) return ( short)U16; return null;
|
||||
}
|
||||
public ushort? RnU16(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[name];
|
||||
if (MsgPack.Object is sbyte I8 ) return (ushort)I8 ;
|
||||
else if (MsgPack.Object is byte U8 ) return U8 ;
|
||||
else if (MsgPack.Object is short I16) return (ushort)I16;
|
||||
else if (MsgPack.Object is ushort U16) return U16; return null;
|
||||
}
|
||||
public int? RnI32(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[name];
|
||||
if (MsgPack.Object is sbyte I8 ) return I8 ;
|
||||
else if (MsgPack.Object is byte U8 ) return U8 ;
|
||||
else if (MsgPack.Object is short I16) return I16;
|
||||
else if (MsgPack.Object is ushort U16) return U16;
|
||||
else if (MsgPack.Object is int I32) return I32;
|
||||
else if (MsgPack.Object is uint U32) return ( int)U32; return null;
|
||||
}
|
||||
public uint? RnU32(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[name];
|
||||
if (MsgPack.Object is sbyte I8 ) return ( uint)I8 ;
|
||||
else if (MsgPack.Object is byte U8 ) return U8 ;
|
||||
else if (MsgPack.Object is short I16) return ( uint)I16;
|
||||
else if (MsgPack.Object is ushort U16) return U16;
|
||||
else if (MsgPack.Object is int I32) return ( uint)I32;
|
||||
else if (MsgPack.Object is uint U32) return U32; return null;
|
||||
}
|
||||
public long? RnI64(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[name];
|
||||
if (MsgPack.Object is sbyte I8 ) return I8 ;
|
||||
else if (MsgPack.Object is byte U8 ) return U8 ;
|
||||
else if (MsgPack.Object is short I16) return I16;
|
||||
else if (MsgPack.Object is ushort U16) return U16;
|
||||
else if (MsgPack.Object is int I32) return I32;
|
||||
else if (MsgPack.Object is uint U32) return U32;
|
||||
else if (MsgPack.Object is long I64) return I64;
|
||||
else if (MsgPack.Object is ulong U64) return ( long)U64; return null;
|
||||
}
|
||||
public ulong? RnU64(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[name];
|
||||
if (MsgPack.Object is sbyte I8 ) return ( ulong)I8 ;
|
||||
else if (MsgPack.Object is byte U8 ) return U8 ;
|
||||
else if (MsgPack.Object is short I16) return ( ulong)I16;
|
||||
else if (MsgPack.Object is ushort U16) return U16;
|
||||
else if (MsgPack.Object is int I32) return ( ulong)I32;
|
||||
else if (MsgPack.Object is uint U32) return U32;
|
||||
else if (MsgPack.Object is long I64) return ( ulong)I64; return null;
|
||||
}
|
||||
public float? RnF32(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[name];
|
||||
if (MsgPack.Object is sbyte I8 ) return I8 ;
|
||||
else if (MsgPack.Object is byte U8 ) return U8 ;
|
||||
else if (MsgPack.Object is short I16) return I16;
|
||||
else if (MsgPack.Object is ushort U16) return U16;
|
||||
else if (MsgPack.Object is int I32) return I32;
|
||||
else if (MsgPack.Object is uint U32) return U32;
|
||||
else if (MsgPack.Object is long I64) return I64;
|
||||
else if (MsgPack.Object is float F32) return F32;
|
||||
else if (MsgPack.Object is double F64) return ( float)F64; return null;
|
||||
}
|
||||
public double? RnF64(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[name];
|
||||
if (MsgPack.Object is sbyte I8 ) return I8 ;
|
||||
else if (MsgPack.Object is byte U8 ) return U8 ;
|
||||
else if (MsgPack.Object is short I16) return I16;
|
||||
else if (MsgPack.Object is ushort U16) return U16;
|
||||
else if (MsgPack.Object is int I32) return I32;
|
||||
else if (MsgPack.Object is uint U32) return U32;
|
||||
else if (MsgPack.Object is long I64) return I64;
|
||||
else if (MsgPack.Object is float F32) return F32;
|
||||
else if (MsgPack.Object is double F64) return F64; return null;
|
||||
}
|
||||
public string RS(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[name];
|
||||
if (MsgPack.Object is string S ) return S ; return null;
|
||||
}
|
||||
|
||||
public bool RB () => RnB () ?? default;
|
||||
public sbyte RI8 () => RnI8 () ?? default;
|
||||
public byte RU8 () => RnU8 () ?? default;
|
||||
public short RI16() => RnI16() ?? default;
|
||||
public ushort RU16() => RnU16() ?? default;
|
||||
public int RI32() => RnI32() ?? default;
|
||||
public uint RU32() => RnU32() ?? default;
|
||||
public long RI64() => RnI64() ?? default;
|
||||
public ulong RU64() => RnU64() ?? default;
|
||||
public float RF32() => RnF32() ?? default;
|
||||
public double RF64() => RnF64() ?? default;
|
||||
|
||||
public bool? RnB ()
|
||||
{ if (Object is bool B ) return B ; return null; }
|
||||
public sbyte? RnI8 ()
|
||||
{ if (Object is sbyte I8 ) return I8 ;
|
||||
else if (Object is byte U8 ) return ( sbyte)U8 ; return null; }
|
||||
public byte? RnU8 ()
|
||||
{ if (Object is sbyte I8 ) return ( byte)I8 ;
|
||||
else if (Object is byte U8 ) return U8 ; return null; }
|
||||
public short? RnI16()
|
||||
{ if (Object is sbyte I8 ) return I8 ;
|
||||
else if (Object is byte U8 ) return U8 ;
|
||||
else if (Object is short I16) return I16;
|
||||
else if (Object is ushort U16) return ( short)U16; return null; }
|
||||
public ushort? RnU16()
|
||||
{ if (Object is sbyte I8 ) return (ushort)I8 ;
|
||||
else if (Object is byte U8 ) return U8 ;
|
||||
else if (Object is short I16) return (ushort)I16;
|
||||
else if (Object is ushort U16) return U16; return null; }
|
||||
public int? RnI32()
|
||||
{ if (Object is sbyte I8 ) return I8 ;
|
||||
else if (Object is byte U8 ) return U8 ;
|
||||
else if (Object is short I16) return I16;
|
||||
else if (Object is ushort U16) return U16;
|
||||
else if (Object is int I32) return I32;
|
||||
else if (Object is uint U32) return ( int)U32; return null; }
|
||||
public uint? RnU32()
|
||||
{ if (Object is sbyte I8 ) return ( uint)I8 ;
|
||||
else if (Object is byte U8 ) return U8 ;
|
||||
else if (Object is short I16) return ( uint)I16;
|
||||
else if (Object is ushort U16) return U16;
|
||||
else if (Object is int I32) return ( uint)I32;
|
||||
else if (Object is uint U32) return U32; return null; }
|
||||
public long? RnI64()
|
||||
{ if (Object is sbyte I8 ) return I8 ;
|
||||
else if (Object is byte U8 ) return U8 ;
|
||||
else if (Object is short I16) return I16;
|
||||
else if (Object is ushort U16) return U16;
|
||||
else if (Object is int I32) return I32;
|
||||
else if (Object is uint U32) return U32;
|
||||
else if (Object is long I64) return I64;
|
||||
else if (Object is ulong U64) return ( long)U64; return null; }
|
||||
public ulong? RnU64()
|
||||
{ if (Object is sbyte I8 ) return ( ulong)I8 ;
|
||||
else if (Object is byte U8 ) return U8 ;
|
||||
else if (Object is short I16) return ( ulong)I16;
|
||||
else if (Object is ushort U16) return U16;
|
||||
else if (Object is int I32) return ( ulong)I32;
|
||||
else if (Object is uint U32) return U32;
|
||||
else if (Object is long I64) return ( ulong)I64; return null; }
|
||||
public float? RnF32()
|
||||
{ if (Object is sbyte I8 ) return I8 ;
|
||||
else if (Object is byte U8 ) return U8 ;
|
||||
else if (Object is short I16) return I16;
|
||||
else if (Object is ushort U16) return U16;
|
||||
else if (Object is int I32) return I32;
|
||||
else if (Object is uint U32) return U32;
|
||||
else if (Object is long I64) return I64;
|
||||
else if (Object is float F32) return F32;
|
||||
else if (Object is double F64) return ( float)F64; return null; }
|
||||
public double? RnF64()
|
||||
{ if (Object is sbyte I8 ) return I8 ;
|
||||
else if (Object is byte U8 ) return U8 ;
|
||||
else if (Object is short I16) return I16;
|
||||
else if (Object is ushort U16) return U16;
|
||||
else if (Object is int I32) return I32;
|
||||
else if (Object is uint U32) return U32;
|
||||
else if (Object is long I64) return I64;
|
||||
else if (Object is float F32) return F32;
|
||||
else if (Object is double F64) return F64; return null; }
|
||||
public string RS ()
|
||||
{ if (Object is string S ) return S ; return null; }
|
||||
|
||||
public MsgPack Element(string name)
|
||||
{
|
||||
if (List.IsNull) return default;
|
||||
|
||||
for (int i = 0; i < List.Count; i++)
|
||||
if (List[i].Name == name) return List[i];
|
||||
return default;
|
||||
}
|
||||
|
||||
public bool ContainsKey(string name) => ElementIndex(name) > -1;
|
||||
|
||||
public int ElementIndex(string name)
|
||||
{
|
||||
if (List.IsNull) return -1;
|
||||
|
||||
for (int i = 0; i < List.Count; i++)
|
||||
if (List[i].Name == name) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool ContainsKeyStartsWith(string name) => ElementIndexStartsWith(name) > -1;
|
||||
|
||||
public int ElementIndexStartsWith(string name)
|
||||
{
|
||||
if (List.IsNull) return -1;
|
||||
|
||||
for (int i = 0; i < List.Count; i++)
|
||||
if (List[i].Name.StartsWith(name)) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public struct Ext
|
||||
{
|
||||
public sbyte Type;
|
||||
public byte[] Data;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IMsgPack : INull
|
||||
{
|
||||
//public void ReadMsgPack();
|
||||
public MsgPack WriteMsgPack(string name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct Pointer<T>
|
||||
{
|
||||
public int O;
|
||||
public T V;
|
||||
|
||||
public override string ToString() => Extensions.ToS(V);
|
||||
|
||||
public Pointer(T value)
|
||||
{ O = 0; V = value; }
|
||||
|
||||
public Pointer(int offset, T value)
|
||||
{ O = offset; V = value; }
|
||||
}
|
||||
|
||||
public struct PointerI64<T>
|
||||
{
|
||||
public long O;
|
||||
public T V;
|
||||
|
||||
public override string ToString() => Extensions.ToS(V);
|
||||
|
||||
public PointerI64(T value)
|
||||
{ O = 0; V = value; }
|
||||
|
||||
public PointerI64(long offset, T value)
|
||||
{ O = offset; V = value; }
|
||||
}
|
||||
|
||||
public struct PointerU64<T>
|
||||
{
|
||||
public ulong O;
|
||||
public T V;
|
||||
|
||||
public override string ToString() => Extensions.ToS(V);
|
||||
|
||||
public PointerU64(T value)
|
||||
{ O = 0; V = value; }
|
||||
|
||||
public PointerU64(ulong offset, T value)
|
||||
{ O = offset; V = value; }
|
||||
}
|
||||
|
||||
public struct CountPointer<T>
|
||||
{
|
||||
public int C { get => E != null ? E.Length : 0;
|
||||
set => E = value > -1 ? new T [value] : null; }
|
||||
public int O;
|
||||
public T[] E;
|
||||
|
||||
public T this[int index]
|
||||
{ get => E != null && index > -1 && index < E.LongLength ? E[index] : default;
|
||||
set { if (E != null && index > -1 && index < E.LongLength) E[index] = value; } }
|
||||
|
||||
public override string ToString() => C < 1 ? "No Entries" :
|
||||
C == 1 ? E[0].ToString() : "Count: " + C;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("437F63F1-8C23-429E-AB14-38B85C9EDB16")]
|
||||
@@ -0,0 +1,171 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct Quat
|
||||
{
|
||||
[FieldOffset(0x00)] public float X;
|
||||
[FieldOffset(0x04)] public float Y;
|
||||
[FieldOffset(0x08)] public float Z;
|
||||
[FieldOffset(0x0C)] public float W;
|
||||
|
||||
public static Quat Identity => new Quat(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
public Quat(float x, float y, float z)
|
||||
{
|
||||
x *= 0.5f;
|
||||
y *= 0.5f;
|
||||
z *= 0.5f;
|
||||
|
||||
var c1 = (float)System.Math.Cos(x);
|
||||
var c2 = (float)System.Math.Cos(y);
|
||||
var c3 = (float)System.Math.Cos(z);
|
||||
var s1 = (float)System.Math.Sin(x);
|
||||
var s2 = (float)System.Math.Sin(y);
|
||||
var s3 = (float)System.Math.Sin(z);
|
||||
|
||||
X = s1 * c2 * c3 + c1 * s2 * s3;
|
||||
Y = c1 * s2 * c3 - s1 * c2 * s3;
|
||||
Z = c1 * c2 * s3 + s1 * s2 * c3;
|
||||
W = c1 * c2 * c3 - s1 * s2 * s3;
|
||||
}
|
||||
|
||||
public Quat(Vec3 vec) : this(vec.X, vec.Y, vec.Z)
|
||||
{ }
|
||||
|
||||
public Quat(float x, float y, float z, float w)
|
||||
{ X = x; Y = y; Z = z; W = w; }
|
||||
|
||||
public Quat(Vec3 vec, float w)
|
||||
{ X = vec.X; Y = vec.Y; Z = vec.Z; W = w; }
|
||||
|
||||
public Quat(Vec4 vec)
|
||||
{ X = vec.X; Y = vec.Y; Z = vec.Z; W = vec.W; }
|
||||
|
||||
public Vec3 XYZ { get => new Vec3(X, Y, Z); set { X = value.X; Y = value.Y; Z = value.Z; } }
|
||||
|
||||
public float Length => (X * X + Y * Y + Z * Z + W * W).Sqrt();
|
||||
public float LengthSquared => X * X + Y * Y + Z * Z + W * W;
|
||||
public Quat Normalized => new Quat(X, Y, Z, W) * (Length == 0.0f ? 1.0f : (1.0f / Length));
|
||||
public Vec3 Euler { get
|
||||
{
|
||||
if (LengthSquared == 0) return default;
|
||||
|
||||
const float SINGULARITY_THRESHOLD = 0.4999995f;
|
||||
const float HalfPI = (float)(System.Math.PI * 0.5);
|
||||
|
||||
float sqx = X * X, sqy = Y * Y, sqz = Z * Z, sqw = W * W;
|
||||
float unit = sqx + sqy + sqz + sqw;
|
||||
float singularityTest = X * Z + Y * W;
|
||||
|
||||
if (singularityTest > SINGULARITY_THRESHOLD * unit)
|
||||
return new Vec3(0.0f, HalfPI, (float)(System.Math.Atan2(X, W) * 2.0));
|
||||
else if (singularityTest < -SINGULARITY_THRESHOLD * unit)
|
||||
return new Vec3(0.0f, -HalfPI, -(float)(System.Math.Atan2(X, W) * 2.0));
|
||||
else
|
||||
return new Vec3((float)System.Math.Atan2(2 * (X * W - Y * Z), sqw - sqx - sqy + sqz),
|
||||
(float)System.Math.Asin (2 * singularityTest / unit),
|
||||
(float)System.Math.Atan2(2 * (Z * W - X * Y), sqw + sqx - sqy - sqz));
|
||||
}
|
||||
}
|
||||
public Vec3 EulerDeg { get
|
||||
{
|
||||
if (LengthSquared == 0) return default;
|
||||
|
||||
const float SINGULARITY_THRESHOLD = 0.4999995f;
|
||||
const float HalfPI = (float)(System.Math.PI * 0.5);
|
||||
|
||||
float sqx = X * X, sqy = Y * Y, sqz = Z * Z, sqw = W * W;
|
||||
float unit = sqx + sqy + sqz + sqw;
|
||||
float singularityTest = X * Z + Y * W;
|
||||
|
||||
if (singularityTest > SINGULARITY_THRESHOLD * unit)
|
||||
return new Vec3(0.0f, HalfPI, (float)(System.Math.Atan2(X, W) * 2.0));
|
||||
else if (singularityTest < -SINGULARITY_THRESHOLD * unit)
|
||||
return new Vec3(0.0f, -HalfPI, -(float)(System.Math.Atan2(X, W) * 2.0));
|
||||
else
|
||||
return new Vec3((float)System.Math.Atan2(2 * (X * W - Y * Z), sqw - sqx - sqy + sqz),
|
||||
(float)System.Math.Asin (2 * singularityTest / unit),
|
||||
(float)System.Math.Atan2(2 * (Z * W - X * Y), sqw + sqx - sqy - sqz))
|
||||
* (float)(180.0 / System.Math.PI);
|
||||
}
|
||||
}
|
||||
|
||||
public static Quat operator +(Quat left, Quat right)
|
||||
{ left.X += right.X; left.Y += right.Y; left.Z += right.Z; left.W += right.W; return left; }
|
||||
public static Quat operator -(Quat left, Quat right)
|
||||
{ left.X -= right.X; left.Y -= right.Y; left.Z -= right.Z; left.W -= right.W; return left; }
|
||||
public static Quat operator -(Quat quat) =>
|
||||
new Quat(-quat.X, -quat.Y, -quat.Z, -quat.W);
|
||||
public static Quat operator *( Quat quat, float scale)
|
||||
{ quat.X *= scale ; quat.Y *= scale ; quat.Z *= scale ; quat.W *= scale ; return quat; }
|
||||
public static Quat operator *(float scale, Quat quat)
|
||||
{ quat.X *= scale ; quat.Y *= scale ; quat.Z *= scale ; quat.W *= scale ; return quat; }
|
||||
public static Quat operator *( Quat quat, Vec4 scale)
|
||||
{ quat.X *= scale.X; quat.Y *= scale.Y; quat.Z *= scale.Z; quat.W *= scale.W; return quat; }
|
||||
public static Quat operator *( Quat left, Quat right) =>
|
||||
new Quat(right.W * left.XYZ + left.W * right.XYZ + Vec3.Cross(left.XYZ, right.XYZ),
|
||||
left.W * right.W - Vec3.Dot(left.XYZ, right.XYZ)).Normalized;
|
||||
public static Quat operator /( Quat left, Quat right) =>
|
||||
left * -right;
|
||||
public static bool operator ==(Quat A, Quat B) => A.Equals(B);
|
||||
public static bool operator !=(Quat A, Quat B) => !A.Equals(B);
|
||||
|
||||
public static float Distance (Quat left, Quat right) =>
|
||||
((right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) * (right.Y - left.Y) +
|
||||
(right.Z - left.Z) * (right.Z - left.Z) + (right.W - left.W) * (right.W - left.W)).Sqrt();
|
||||
public static float DistanceSquared(Quat left, Quat right) =>
|
||||
(right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) * (right.Y - left.Y) +
|
||||
(right.Z - left.Z) * (right.Z - left.Z) + (right.W - left.W) * (right.W - left.W);
|
||||
public static float Dot(Quat left, Quat right) =>
|
||||
left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W;
|
||||
public Quat Round( ) =>
|
||||
new Quat { X = X.Round( ), Y = Y.Round( ), Z = Z.Round( ), W = W.Round( ) };
|
||||
public Quat Round(int d) =>
|
||||
new Quat { X = X.Round(d), Y = Y.Round(d), Z = Z.Round(d), W = W.Round(d) };
|
||||
|
||||
public static Quat Slerp(Quat q1, Quat q2, float blend)
|
||||
{
|
||||
q1 = q1.Normalized;
|
||||
q2 = q2.Normalized;
|
||||
|
||||
float dot = Dot(q1, q2);
|
||||
if (dot < 0.0f)
|
||||
{
|
||||
q2 = -q2;
|
||||
dot = -dot;
|
||||
}
|
||||
|
||||
Quat result;
|
||||
const float DOT_THRESHOLD = 0.9995f;
|
||||
if (dot <= DOT_THRESHOLD)
|
||||
{
|
||||
float theta_0 = (float)System.Math.Acos(dot);
|
||||
float theta = theta_0 * blend;
|
||||
float sin_theta = (float)System.Math.Sin(theta);
|
||||
float sin_theta_0 = (float)System.Math.Sin(theta_0);
|
||||
|
||||
float s0 = (float)System.Math.Cos(theta) - dot * sin_theta / sin_theta_0;
|
||||
float s1 = sin_theta / sin_theta_0;
|
||||
result = s0 * q1 + s1 * q2;
|
||||
}
|
||||
else
|
||||
result = (1.0f - blend) * q1 + blend * q2;
|
||||
return result.Normalized;
|
||||
}
|
||||
|
||||
public static explicit operator Vec4(Quat quat) =>
|
||||
new Vec4(quat.XYZ, quat.W);
|
||||
public static explicit operator Quat(Vec4 vec) =>
|
||||
new Quat( vec.XYZ, vec.W);
|
||||
|
||||
public bool Equals(Quat other) =>
|
||||
X == other.X && Y == other.Y && Z == other.Z && W == other.W;
|
||||
|
||||
public override bool Equals(object obj) => base.Equals(obj);
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
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)})";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
namespace KKdBaseLib.Tables
|
||||
{
|
||||
public struct ButtonSE
|
||||
{
|
||||
public TableDate Start;
|
||||
public TableDate End;
|
||||
|
||||
public int ID;
|
||||
public int SortIndex;
|
||||
public string Name;
|
||||
public string SEName;
|
||||
}
|
||||
|
||||
public struct ChainSlideSE
|
||||
{
|
||||
public TableDate Start;
|
||||
public TableDate End;
|
||||
|
||||
public int ID;
|
||||
public int SortIndex;
|
||||
public string Name;
|
||||
public string FirstSEName;
|
||||
public string FailureSEName;
|
||||
public string SubSEName;
|
||||
public string SuccessSEName;
|
||||
}
|
||||
|
||||
public struct CollectionCard
|
||||
{
|
||||
public TableDate Start;
|
||||
public TableDate End;
|
||||
|
||||
public int DispNum;
|
||||
public int ID;
|
||||
public int NG;
|
||||
public int SortIndex;
|
||||
public int TypeParam;
|
||||
public string Chara;
|
||||
public string DivaProParam;
|
||||
public string ModuleAuthor;
|
||||
public string Name;
|
||||
public string NameReading;
|
||||
public string Type;
|
||||
public string WallParam;
|
||||
}
|
||||
|
||||
public struct CustomizeItem
|
||||
{
|
||||
public TableDate ShopStart;
|
||||
public TableDate ShopEnd;
|
||||
|
||||
public int ID;
|
||||
public int ObjID;
|
||||
public int NG;
|
||||
public int SellType;
|
||||
public int ShopPrice;
|
||||
public int SortIndex;
|
||||
public string Chara;
|
||||
public string Name;
|
||||
public string Parts;
|
||||
}
|
||||
|
||||
public struct Module
|
||||
{
|
||||
public TableDate ShopStart;
|
||||
public TableDate ShopEnd;
|
||||
|
||||
public int Attribute;
|
||||
public int ID;
|
||||
public int NG;
|
||||
public int ShopPrice;
|
||||
public int SortIndex;
|
||||
public string Chara;
|
||||
public string Costume;
|
||||
public string Name;
|
||||
}
|
||||
|
||||
public struct Plate
|
||||
{
|
||||
public int Alpha;
|
||||
public int BaseID;
|
||||
public int Border;
|
||||
public int ColorB;
|
||||
public int ColorG;
|
||||
public int ColorR;
|
||||
public int ID;
|
||||
public int Shadow;
|
||||
public int ShadowAlpha;
|
||||
public int ShadowColorB;
|
||||
public int ShadowColorG;
|
||||
public int ShadowColorR;
|
||||
public string Font;
|
||||
}
|
||||
|
||||
public struct PV
|
||||
{
|
||||
public TableDate AdvStart;
|
||||
public TableDate AdvEnd;
|
||||
|
||||
public int ID;
|
||||
public int Ignore;
|
||||
public string Name;
|
||||
public Difficulty[] Easy;
|
||||
public Difficulty[] Encore;
|
||||
public Difficulty[] Extreme;
|
||||
public Difficulty[] Normal;
|
||||
public Difficulty[] Hard;
|
||||
|
||||
public struct Difficulty
|
||||
{
|
||||
public TableDate Start;
|
||||
public TableDate End;
|
||||
|
||||
public int Edition;
|
||||
public int Version;
|
||||
}
|
||||
}
|
||||
|
||||
public struct SlideSE
|
||||
{
|
||||
public TableDate Start;
|
||||
public TableDate End;
|
||||
|
||||
public int ID;
|
||||
public int SortIndex;
|
||||
public string Name;
|
||||
public string SEName;
|
||||
}
|
||||
|
||||
public struct SliderTouchSE
|
||||
{
|
||||
public TableDate Start;
|
||||
public TableDate End;
|
||||
|
||||
public int ID;
|
||||
public int SortIndex;
|
||||
public string Name;
|
||||
public string SEName;
|
||||
}
|
||||
|
||||
public struct TableDate : INull
|
||||
{
|
||||
private int year;
|
||||
private int month;
|
||||
private int day;
|
||||
|
||||
public int Year { get => year; set { year = value; CheckDate(); } }
|
||||
public int Month { get => month; set { month = value; CheckDate(); } }
|
||||
public int Day { get => day; set { day = value; CheckDate(); } }
|
||||
|
||||
public bool IsNull => Year == -1 || Month == -1 || Day != -1;
|
||||
public bool NotNull => Year != -1 && Month != -1 && Day != -1;
|
||||
|
||||
public bool WU => Year != 2029 || Month != 1 || Day != 1;
|
||||
public bool WL => Year != 2000 || Month != 1 || Day != 1;
|
||||
|
||||
public void SN () => Year = -1;
|
||||
public void SDL() => Year = 2000;
|
||||
public void SDU() => Year = 2029;
|
||||
|
||||
public void SV(int? ymd, bool setDefaultUpper)
|
||||
{
|
||||
if (!setDefaultUpper) SDL();
|
||||
else SDU();
|
||||
if (ymd != null)
|
||||
{
|
||||
year = ymd.Value / 10000;
|
||||
month = ymd.Value / 100 % 100;
|
||||
day = ymd.Value % 100;
|
||||
CheckDate();
|
||||
}
|
||||
}
|
||||
|
||||
public int Int => NotNull ? (Year * 100 + Month) * 100 + Day : -1;
|
||||
|
||||
private void CheckDate()
|
||||
{
|
||||
if (year == -1 || month == -1 || day == -1) { year = -1; month = -1; day = -1; return; }
|
||||
if (year < 2000) { year = 2000; month = 1; day = 1; return; }
|
||||
if (year >= 2029) { year = 2029; month = 1; day = 1; return; }
|
||||
if (month < 1) month = 1;
|
||||
else if (month > 12) month = 12;
|
||||
if (day < 1) day = 1;
|
||||
else if (day > 31 && (month == 1 || month == 3 || month == 5 ||
|
||||
month == 7 || month == 8 || month == 10 || month == 12)) day = 31;
|
||||
else if (day > 30 && (month == 4 || month == 6 ||
|
||||
month == 9 || month == 11)) day = 30;
|
||||
else if (day > 29 && month == 2 && year % 4 == 0) day = 29;
|
||||
else if (day > 28 && month == 2 && year % 4 != 0) day = 28;
|
||||
}
|
||||
|
||||
public override string ToString() =>
|
||||
$"{Year:d4}-{Month:d2}-{Day:d2}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Text;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public static class Text
|
||||
{
|
||||
public readonly static Encoding ShiftJIS = Encoding.GetEncoding(932);
|
||||
|
||||
public static string ToASCII(this byte[] Array) => Encoding.ASCII.GetString(Array ?? new byte[0]);
|
||||
public static byte[] ToASCII(this string Data ) => Encoding.ASCII.GetBytes (Data ?? "" );
|
||||
public static byte[] ToASCII(this char[] Data ) => Encoding.ASCII.GetBytes (Data ?? new char[0]);
|
||||
public static string ToSJIS (this byte[] Array) => ShiftJIS.GetString(Array ?? new byte[0]);
|
||||
public static byte[] ToSJIS (this string Data ) => ShiftJIS.GetBytes (Data ?? "" );
|
||||
public static byte[] ToSJIS (this char[] Data ) => ShiftJIS.GetBytes (Data ?? new char[0]);
|
||||
public static string ToUTF8 (this byte[] Array) => Encoding.UTF8 .GetString(Array ?? new byte[0]);
|
||||
public static byte[] ToUTF8 (this string Data ) => Encoding.UTF8 .GetBytes (Data ?? "" );
|
||||
public static byte[] ToUTF8 (this char[] Data ) => Encoding.UTF8 .GetBytes (Data ?? new char[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct Vec2<T> : INull
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
|
||||
public Vec2(T x, T y)
|
||||
{ X = x; Y = y; }
|
||||
|
||||
public bool IsNull => X == null && Y == null;
|
||||
public bool NotNull => X != null || Y != null;
|
||||
|
||||
public override string ToString() => $"({X}; {Y})";
|
||||
}
|
||||
|
||||
public struct Vec3<T> : INull
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
public T Z;
|
||||
|
||||
public Vec3(T x, T y, T z)
|
||||
{ X = x; Y = y; Z = z; }
|
||||
|
||||
public bool IsNull => X == null && Y == null && Z == null;
|
||||
public bool NotNull => X != null || Y != null || Z != null;
|
||||
|
||||
public override string ToString() => $"({X}; {Y}; {Z})";
|
||||
}
|
||||
|
||||
public struct Vec4<T> : INull
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
public T Z;
|
||||
public T W;
|
||||
|
||||
public Vec4(T x, T y, T z, T w)
|
||||
{ X = x; Y = y; Z = z; W = w; }
|
||||
|
||||
public bool IsNull => X == null && Y == null && Z == null && W == null;
|
||||
public bool NotNull => X != null || Y != null || Z != null || W != null;
|
||||
|
||||
public override string ToString() => $"({X}; {Y}; {Z}; {W})";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct Vec2
|
||||
{
|
||||
[FieldOffset(0x00)] public float X;
|
||||
[FieldOffset(0x04)] public float Y;
|
||||
|
||||
public Vec2(float val)
|
||||
{ X = val; Y = val; }
|
||||
|
||||
public Vec2(float X, float Y)
|
||||
{ this.X = X; this.Y = Y; }
|
||||
|
||||
public Vec2(Vec4 vec)
|
||||
{ X = vec.X; Y = vec.Y; }
|
||||
|
||||
public float Length => (X * X + Y * Y).Sqrt();
|
||||
public float LengthSquared => X * X + Y * Y;
|
||||
public Vec2 Normalized => this = Length == 0.0f ? new Vec2() : this * (1.0f / Length);
|
||||
|
||||
public static Vec2 operator +(Vec2 left, Vec2 right)
|
||||
{ left.X += right.X; left.Y += right.Y; return left; }
|
||||
public static Vec2 operator -(Vec2 left, Vec2 right)
|
||||
{ left.X -= right.X; left.Y -= right.Y; return left; }
|
||||
public static Vec2 operator -(Vec2 vec)
|
||||
{ vec.X = -vec.X; vec.Y = -vec.Y; return vec; }
|
||||
public static Vec2 operator *(Vec2 vec, float scale)
|
||||
{ vec.X *= scale ; vec.Y *= scale ; return vec; }
|
||||
public static Vec2 operator *( float scale, Vec2 vec)
|
||||
{ vec.X *= scale ; vec.Y *= scale ; return vec; }
|
||||
public static Vec2 operator *(Vec2 vec, Vec2 scale)
|
||||
{ vec.X *= scale.X; vec.Y *= scale.Y; return vec; }
|
||||
public static Vec2 operator /(Vec2 vec, float scale)
|
||||
{ vec.X /= scale ; vec.Y /= scale ; return vec; }
|
||||
public static Vec2 operator /(Vec2 vec, Vec2 scale)
|
||||
{ vec.X /= scale.X; vec.Y /= scale.Y; return vec; }
|
||||
public static bool operator ==(Vec2 A, Vec2 B) => A.X == B.X && A.Y == B.Y;
|
||||
public static bool operator !=(Vec2 A, Vec2 B) => A.X != B.X || A.Y != B.Y;
|
||||
|
||||
public static Vec2 operator *(Vec2 vec, Mat2 mat) =>
|
||||
new Vec2(vec.X * mat.Row0.X + vec.Y * mat.Row1.X,
|
||||
vec.X * mat.Row0.Y + vec.Y * mat.Row1.Y);
|
||||
|
||||
public static float Distance (Vec2 left, Vec2 right) =>
|
||||
(right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) * (right.Y - left.Y).Sqrt();
|
||||
public static float DistanceSquared(Vec2 left, Vec2 right) =>
|
||||
(right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) * (right.Y - left.Y);
|
||||
public static float Dot(Vec2 left, Vec2 right) =>
|
||||
left.X * right.X + left.Y * right.Y;
|
||||
public static Vec2 Lerp(Vec2 a, Vec2 b, float blend) =>
|
||||
new Vec2 { X = blend * (b.X - a.X) + a.X, Y = blend * (b.Y - a.Y) + a.Y };
|
||||
public static Vec2 Lerp(Vec2 a, Vec2 b, Vec2 blend) =>
|
||||
new Vec2 { X = blend.X * (b.X - a.X) + a.X, Y = blend.Y * (b.Y - a.Y) + a.Y };
|
||||
public Vec2 Round( ) =>
|
||||
new Vec2 { X = X.Round( ), Y = Y.Round( ) };
|
||||
public Vec2 Round(int d) =>
|
||||
new Vec2 { X = X.Round(d), Y = Y.Round(d) };
|
||||
|
||||
public bool Equals(Vec2 other) =>
|
||||
X == other.X && Y == other.Y;
|
||||
|
||||
public override bool Equals(object obj) => base.Equals(obj);
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
public override string ToString() => $"({X}; {Y})";
|
||||
public string ToString(int d) => $"({X.Round(d)}; {Y.Round(d)})";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct Vec3
|
||||
{
|
||||
[FieldOffset(0x00)] public float X;
|
||||
[FieldOffset(0x04)] public float Y;
|
||||
[FieldOffset(0x08)] public float Z;
|
||||
|
||||
public Vec3(float val)
|
||||
{ X = val; Y = val; Z = val; }
|
||||
|
||||
public Vec3(float X, float Y)
|
||||
{ this.X = X; this.Y = Y; Z = 0.0f; }
|
||||
|
||||
public Vec3(float X, float Y, float Z)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; }
|
||||
|
||||
public Vec3(Vec2 vec)
|
||||
{ X = vec.X; Y = vec.Y; Z = 0.0f; }
|
||||
|
||||
public Vec3(Vec2 vec, float Z)
|
||||
{ X = vec.X; Y = vec.Y; this.Z = Z; }
|
||||
|
||||
public Vec3(Vec4 vec)
|
||||
{ X = vec.X; Y = vec.Y; Z = vec.Z; }
|
||||
|
||||
public Vec2 XY => new Vec2(X, Y);
|
||||
|
||||
public float Length => (X * X + Y * Y + Z * Z).Sqrt();
|
||||
public float LengthSquared => X * X + Y * Y + Z * Z;
|
||||
public Vec3 Normalized => this = Length == 0.0f ? new Vec3() : this * (1.0f / Length);
|
||||
|
||||
public static Vec3 operator +(Vec3 left, Vec3 right)
|
||||
{ left.X += right.X; left.Y += right.Y; left.Z += right.Z; return left; }
|
||||
public static Vec3 operator -(Vec3 left, Vec3 right)
|
||||
{ left.X -= right.X; left.Y -= right.Y; left.Z -= right.Z; return left; }
|
||||
public static Vec3 operator -(Vec3 vec)
|
||||
{ vec.X = -vec.X; vec.Y = -vec.Y; vec.Z = -vec.Z; return vec; }
|
||||
public static Vec3 operator *( Vec3 vec, float scale)
|
||||
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; return vec; }
|
||||
public static Vec3 operator *(float scale, Vec3 vec)
|
||||
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; return vec; }
|
||||
public static Vec3 operator *( Vec3 vec, Vec3 scale)
|
||||
{ vec.X *= scale.X; vec.Y *= scale.Y; vec.Z *= scale.Z; return vec; }
|
||||
public static Vec3 operator /( Vec3 vec, float scale)
|
||||
{ vec.X /= scale ; vec.Y /= scale ; vec.Z /= scale ; return vec; }
|
||||
public static Vec3 operator /( Vec3 vec, Vec3 scale)
|
||||
{ vec.X /= scale.X; vec.Y /= scale.Y; vec.Z /= scale.Z; return vec; }
|
||||
public static bool operator ==(Vec3 A, Vec3 B) => A.X == B.X && A.Y == B.Y && A.Z == B.Z;
|
||||
public static bool operator !=(Vec3 A, Vec3 B) => A.X != B.X || A.Y != B.Y || A.Z != B.Z;
|
||||
|
||||
public static Vec3 operator *(Vec3 vec, Mat3 mat) =>
|
||||
new Vec3(vec.X * mat.Row0.X + vec.Y * mat.Row1.X + vec.Z * mat.Row2.X,
|
||||
vec.X * mat.Row0.Y + vec.Y * mat.Row1.Y + vec.Z * mat.Row2.Y,
|
||||
vec.X * mat.Row0.Z + vec.Y * mat.Row1.Z + vec.Z * mat.Row2.Z);
|
||||
|
||||
public static float Distance (Vec3 left, Vec3 right) =>
|
||||
((right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) *
|
||||
(right.Y - left.Y) + (right.Z - left.Z) * (right.Z - left.Z)).Sqrt();
|
||||
public static float DistanceSquared(Vec3 left, Vec3 right) =>
|
||||
(right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) *
|
||||
(right.Y - left.Y) + (right.Z - left.Z) * (right.Z - left.Z);
|
||||
public static float Dot(Vec3 left, Vec3 right) =>
|
||||
left.X * right.X + left.Y * right.Y + left.Z * right.Z;
|
||||
public static Vec3 Cross(Vec3 left, Vec3 right) =>
|
||||
new Vec3 { 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 Vec3 Lerp(Vec3 a, Vec3 b, float blend) =>
|
||||
new Vec3 { X = blend * (b.X - a.X) + a.X,
|
||||
Y = blend * (b.Y - a.Y) + a.Y,
|
||||
Z = blend * (b.Z - a.Z) + a.Z };
|
||||
public static Vec3 Lerp(Vec3 a, Vec3 b, Vec3 blend) =>
|
||||
new Vec3 { X = blend.X * (b.X - a.X) + a.X,
|
||||
Y = blend.Y * (b.Y - a.Y) + a.Y,
|
||||
Z = blend.Z * (b.Z - a.Z) + a.Z };
|
||||
public Vec3 Round( ) =>
|
||||
new Vec3 { X = X.Round( ), Y = Y.Round( ), Z = Z.Round( ) };
|
||||
public Vec3 Round(int d) =>
|
||||
new Vec3 { X = X.Round(d), Y = Y.Round(d), Z = Z.Round(d) };
|
||||
|
||||
public bool Equals(Vec3 other) =>
|
||||
X == other.X && Y == other.Y && Z == other.Z;
|
||||
|
||||
public override bool Equals(object obj) => base.Equals(obj);
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
public override string ToString() => $"({X}; {Y}; {Z})";
|
||||
public string ToString(int d) => $"({X.Round(d)}; {Y.Round(d)}; {Z.Round(d)})";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
[StructLayout(LayoutKind.Explicit)]
|
||||
public struct Vec4
|
||||
{
|
||||
[FieldOffset(0x00)] public float X;
|
||||
[FieldOffset(0x04)] public float Y;
|
||||
[FieldOffset(0x08)] public float Z;
|
||||
[FieldOffset(0x0C)] public float W;
|
||||
|
||||
public Vec4(float val)
|
||||
{ X = val; Y = val; Z = val; W = 0.0f; }
|
||||
|
||||
public Vec4(float X, float Y)
|
||||
{ this.X = X; this.Y = Y; Z = 0.0f; W = 0.0f; }
|
||||
|
||||
public Vec4(float X, float Y, float Z)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; W = 0.0f; }
|
||||
|
||||
public Vec4(float X, float Y, float Z, float W)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; this.W = W; }
|
||||
|
||||
public Vec4(Vec2 vec)
|
||||
{ X = vec.X; Y = vec.Y; Z = 0.0f; W = 0.0f; }
|
||||
|
||||
public Vec4(Vec2 vec, float Z)
|
||||
{ X = vec.X; Y = vec.Y; this.Z = Z; W = 0.0f; }
|
||||
|
||||
public Vec4(Vec2 vec, float Z, float W)
|
||||
{ X = vec.X; Y = vec.Y; this.Z = Z; this.W = W; }
|
||||
|
||||
public Vec4(Vec3 vec)
|
||||
{ X = vec.X; Y = vec.Y; Z = vec.Z; W = 0.0f; }
|
||||
|
||||
public Vec4(Vec3 vec, float W)
|
||||
{ X = vec.X; Y = vec.Y; Z = vec.Z; this.W = W; }
|
||||
|
||||
public Vec2 XY { get => new Vec2(X, Y ); set { X = value.X; Y = value.Y; } }
|
||||
public Vec3 XYZ { get => new Vec3(X, Y, Z); set { X = value.X; Y = value.Y; Z = value.Z; } }
|
||||
|
||||
public float Length => (X * X + Y * Y + Z * Z + W * W).Sqrt();
|
||||
public float LengthSquared => X * X + Y * Y + Z * Z + W * W;
|
||||
public Vec4 Normalized => new Vec4(X, Y, Z, W) * (Length == 0.0f ? 1.0f : (1.0f / Length));
|
||||
|
||||
public static Vec4 operator +(Vec4 left, Vec4 right)
|
||||
{ left.X += right.X; left.Y += right.Y; left.Z += right.Z; left.W += right.W; return left; }
|
||||
public static Vec4 operator -(Vec4 left, Vec4 right)
|
||||
{ left.X -= right.X; left.Y -= right.Y; left.Z -= right.Z; left.W -= right.W; return left; }
|
||||
public static Vec4 operator -(Vec4 vec)
|
||||
{ vec.X = -vec.X; vec.Y = -vec.Y; vec.Z = -vec.Z; vec.W = -vec.W; return vec; }
|
||||
public static Vec4 operator *( Vec4 vec, float scale)
|
||||
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; vec.W *= scale ; return vec; }
|
||||
public static Vec4 operator *(float scale, Vec4 vec)
|
||||
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; vec.W *= scale ; return vec; }
|
||||
public static Vec4 operator *( Vec4 vec, Vec4 scale)
|
||||
{ vec.X *= scale.X; vec.Y *= scale.Y; vec.Z *= scale.Z; vec.W *= scale.W; return vec; }
|
||||
public static Vec4 operator /( Vec4 vec, float scale)
|
||||
{ vec.X /= scale ; vec.Y /= scale ; vec.Z /= scale ; vec.W /= scale ; return vec; }
|
||||
public static Vec4 operator /( Vec4 vec, Vec4 scale)
|
||||
{ vec.X /= scale.X; vec.Y /= scale.Y; vec.Z /= scale.Z; vec.W /= scale.W; return vec; }
|
||||
public static bool operator ==(Vec4 A, Vec4 B) => A.Equals(B);
|
||||
public static bool operator !=(Vec4 A, Vec4 B) => !A.Equals(B);
|
||||
|
||||
public static Vec4 operator +(Vec4 left, Vec3 right)
|
||||
{ left.X += right.X; left.Y += right.Y; left.Z += right.Z; return left; }
|
||||
public static Vec4 operator -(Vec4 left, Vec3 right)
|
||||
{ left.X -= right.X; left.Y -= right.Y; left.Z -= right.Z; return left; }
|
||||
public static Vec4 operator *( Vec4 vec, Vec3 scale)
|
||||
{ vec.X *= scale.X; vec.Y *= scale.Y; vec.Z *= scale.Z; return vec; }
|
||||
public static Vec4 operator /( Vec4 vec, Vec3 scale)
|
||||
{ vec.X /= scale.X; vec.Y /= scale.Y; vec.Z /= scale.Z; return vec; }
|
||||
|
||||
public static Vec4 operator *(Vec4 vec, Mat4 mat) =>
|
||||
new Vec4(vec.X * mat.Row0.X + vec.Y * mat.Row1.X + vec.Z * mat.Row2.X + vec.W * mat.Row3.X,
|
||||
vec.X * mat.Row0.Y + vec.Y * mat.Row1.Y + vec.Z * mat.Row2.Y + vec.W * mat.Row3.Y,
|
||||
vec.X * mat.Row0.Z + vec.Y * mat.Row1.Z + vec.Z * mat.Row2.Z + vec.W * mat.Row3.Z,
|
||||
vec.X * mat.Row0.W + vec.Y * mat.Row1.W + vec.Z * mat.Row2.W + vec.W * mat.Row3.W);
|
||||
|
||||
public static float Distance (Vec4 left, Vec4 right) =>
|
||||
((right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) * (right.Y - left.Y) +
|
||||
(right.Z - left.Z) * (right.Z - left.Z) + (right.W - left.W) * (right.W - left.W)).Sqrt();
|
||||
public static float DistanceSquared(Vec4 left, Vec4 right) =>
|
||||
(right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) * (right.Y - left.Y) +
|
||||
(right.Z - left.Z) * (right.Z - left.Z) + (right.W - left.W) * (right.W - left.W);
|
||||
public static float Dot(Vec4 left, Vec4 right) =>
|
||||
left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W;
|
||||
public static Vec4 Lerp(Vec4 a, Vec4 b, float blend) =>
|
||||
new Vec4 { X = blend * (b.X - a.X) + a.X, Y = blend * (b.Y - a.Y) + a.Y,
|
||||
Z = blend * (b.Z - a.Z) + a.Z, W = blend * (b.W - a.W) + a.W };
|
||||
public static Vec4 Lerp(Vec4 a, Vec4 b, Vec4 blend) =>
|
||||
new Vec4 { X = blend.X * (b.X - a.X) + a.X, Y = blend.Y * (b.Y - a.Y) + a.Y,
|
||||
Z = blend.Z * (b.Z - a.Z) + a.Z, W = blend.W * (b.W - a.W) + a.W };
|
||||
public Vec4 Round( ) =>
|
||||
new Vec4 { X = X.Round( ), Y = Y.Round( ), Z = Z.Round( ), W = W.Round( ) };
|
||||
public Vec4 Round(int d) =>
|
||||
new Vec4 { X = X.Round(d), Y = Y.Round(d), Z = Z.Round(d), W = W.Round(d) };
|
||||
|
||||
public bool Equals(Vec4 other) =>
|
||||
X == other.X && Y == other.Y && Z == other.Z && W == other.W;
|
||||
|
||||
public override bool Equals(object obj) => base.Equals(obj);
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
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)})";
|
||||
}
|
||||
}
|
||||
+3022
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,421 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.A3DA
|
||||
{
|
||||
public static class A3DAExt
|
||||
{
|
||||
private const string d = ".";
|
||||
private const string BO = "bin_offset";
|
||||
private const string MTBO = "model_transform" + d + BO;
|
||||
|
||||
private static string value;
|
||||
private static string[] dataArray;
|
||||
private static int SOi;
|
||||
private static int[] SO;
|
||||
|
||||
public static ModelTransform ReadMT(this Dictionary<string, object> Dict, string Temp)
|
||||
{
|
||||
ModelTransform MT = new ModelTransform();
|
||||
Dict.FindValue(out MT.BinOffset, Temp + MTBO);
|
||||
|
||||
MT.Rot = Dict.ReadVec3(Temp + "rot" + d);
|
||||
MT.Scale = Dict.ReadVec3(Temp + "scale" + d);
|
||||
MT.Trans = Dict.ReadVec3(Temp + "trans" + d);
|
||||
MT.Visibility = Dict.ReadKey (Temp + "visibility" + d);
|
||||
return MT;
|
||||
}
|
||||
|
||||
public static RGBAKey ReadRGBAKey(this Dictionary<string, object> Dict, string Temp) =>
|
||||
new RGBAKey { A = Dict.ReadKey(Temp + "a" + d), B = Dict.ReadKey(Temp + "b" + d),
|
||||
G = Dict.ReadKey(Temp + "g" + d), R = Dict.ReadKey(Temp + "r" + d) };
|
||||
|
||||
public static Vector3<Key> ReadVec3(this Dictionary<string, object> Dict, string Temp) =>
|
||||
new Vector3<Key> { X = Dict.ReadKey(Temp + "x" + d), Y =
|
||||
Dict.ReadKey(Temp + "y" + d), Z = Dict.ReadKey(Temp + "z" + d) };
|
||||
|
||||
public static KeyUV ReadKeyUV(this Dictionary<string, object> Dict, string Temp) =>
|
||||
new KeyUV { U = Dict.ReadKey(Temp + "U" + d), V = Dict.ReadKey(Temp + "V" + d) };
|
||||
|
||||
public static Key ReadKey(this Dictionary<string, object> Dict, string Temp)
|
||||
{
|
||||
Key Key = new Key();
|
||||
Dict.FindValue(out Key.BinOffset, Temp + BO );
|
||||
Dict.FindValue(out Key.Type , Temp + "type");
|
||||
|
||||
if (Key.BinOffset == null && Key.Type == null) return null;
|
||||
if (Key.Type == null) return Key;
|
||||
if (Key.Type == 0x0000) return Key;
|
||||
|
||||
if (Key.Type == 0x0001) { Dict.FindValue(out Key.Value, Temp + "value"); return Key; }
|
||||
|
||||
int i = 0, i0 = 0;
|
||||
byte i1 = 0;
|
||||
Dict.FindValue(out Key.EPTypePost, Temp + "ep_type_post");
|
||||
Dict.FindValue(out Key.EPTypePre , Temp + "ep_type_pre" );
|
||||
Dict.FindValue(out Key.Length , Temp + "key.length" );
|
||||
Dict.FindValue(out Key.Max , Temp + "max" );
|
||||
if (Dict.StartsWith(Temp + "raw_data"))
|
||||
Dict.FindValue(out Key.RawData.KeyType, Temp + "raw_data_key_type");
|
||||
|
||||
if (Key.Length != null)
|
||||
{
|
||||
Key.Trans = new Key.Transform[(int)Key.Length];
|
||||
for (i0 = 0; i0 < Key.Length; i0++)
|
||||
if (Dict.FindValue(out value, Temp + "key" + d + i0 + d + "data"))
|
||||
{
|
||||
Key.Trans[i0] = new Key.Transform();
|
||||
dataArray = value.Replace("(", "").Replace(")", "").Split(',');
|
||||
Key.Trans[i0].Type = dataArray.Length - 1;
|
||||
Key.Trans[i0].Frame = dataArray[0].ToDouble();
|
||||
Key.Trans[i0].Value = new double[Key.Trans[i0].Type];
|
||||
for (i1 = 1; i1 < dataArray.Length; i1++)
|
||||
Key.Trans[i0].Value[i1 - 1] = dataArray[i1].ToDouble();
|
||||
}
|
||||
}
|
||||
else if (Key.RawData.KeyType != null)
|
||||
{
|
||||
Key.RawData = new Key.RawD();
|
||||
Dict.FindValue(out Key.RawData.ValueType, Temp + "raw_data.value_type");
|
||||
if (Dict.FindValue(out value, Temp + "raw_data.value_list"))
|
||||
Key.RawData.ValueList = value.Split(',');
|
||||
Dict.FindValue(out Key.RawData.ValueListSize, Temp + "raw_data.value_list_size");
|
||||
value = "";
|
||||
|
||||
int DataSize = (int)Key.RawData.KeyType + 1;
|
||||
Key.Length = Key.RawData.ValueListSize / DataSize;
|
||||
Key.Trans = new Key.Transform[(int)Key.Length];
|
||||
for (i = 0; i < Key.Length; i++)
|
||||
{
|
||||
Key.Trans[i].Type = (int)Key.RawData.KeyType;
|
||||
Key.Trans[i].Frame = Key.RawData.ValueList[i * DataSize + 0].ToDouble();
|
||||
Key.Trans[i].Value = new double[Key.Trans[i0].Type];
|
||||
for (i1 = 1; i1 < Key.Trans[i].Type; i1++)
|
||||
Key.Trans[i].Value[i1 - 1] = Key.RawData.ValueList[i * DataSize + i1].ToDouble();
|
||||
}
|
||||
Key.RawData.ValueList = null;
|
||||
}
|
||||
return Key;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, ModelTransform MT,
|
||||
string Temp, bool A3DC, bool IsX = false, byte Flags = 0b11111)
|
||||
{
|
||||
if (A3DC && !MT.Writed && (Flags & 0b10000) == 0b10000)
|
||||
{ IO.Write(Temp + MTBO + "=", MT.BinOffset); MT.Writed = true; }
|
||||
|
||||
if (A3DC) return;
|
||||
|
||||
if ((Flags & 0b01000) == 0b01000) IO.Write(MT.Rot , Temp + "rot" + d, A3DC);
|
||||
if ((Flags & 0b00100) == 0b00100) IO.Write(MT.Scale , Temp + "scale" + d, A3DC);
|
||||
if ((Flags & 0b00010) == 0b00010) IO.Write(MT.Trans , Temp + "trans" + d, A3DC);
|
||||
if ((Flags & 0b00001) == 0b00001) IO.Write(MT.Visibility, Temp + "visibility" + d, A3DC);
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, RGBAKey RGBA, string Temp, string Data, bool A3DC = false)
|
||||
{
|
||||
if (RGBA.R == null && RGBA.B == null && RGBA.G == null && RGBA.A == null) return;
|
||||
IO.Write(Temp + Data + "=", "true");
|
||||
IO.Write(RGBA.A, Temp + Data + d + "a" + d, A3DC); IO.Write(RGBA.B, Temp + Data + d + "b" + d, A3DC);
|
||||
IO.Write(RGBA.G, Temp + Data + d + "g" + d, A3DC); IO.Write(RGBA.R, Temp + Data + d + "r" + d, A3DC);
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, Vector3<Key> Key, string Temp, bool A3DC = false)
|
||||
{ IO.Write(Key.X, Temp + "x" + d, A3DC); IO.Write(Key.Y,
|
||||
Temp + "y" + d, A3DC); IO.Write(Key.Z, Temp + "z" + d, A3DC); }
|
||||
|
||||
public static void Write(this Stream IO, KeyUV UV, string Temp, string Data, bool A3DC = false)
|
||||
{ IO.Write(UV.U, Temp, Data + "U", A3DC); IO.Write(UV.V, Temp, Data + "V", A3DC); }
|
||||
|
||||
public static void Write(this Stream IO, Key Key, string Temp, string Data, bool A3DC = false)
|
||||
{ if (Key != null) { IO.Write(Temp + Data + "=", "true"); IO.Write(Key, Temp + Data + d, A3DC); } }
|
||||
|
||||
public static void Write(this Stream IO, Key Key, string Temp, bool A3DC = false)
|
||||
{
|
||||
if (Key == null) return;
|
||||
|
||||
if (A3DC) { IO.Write(Temp + BO + "=", Key.BinOffset); return; }
|
||||
|
||||
int i = 0;
|
||||
if (Key.Trans != null)
|
||||
if (Key.Trans.Length == 0)
|
||||
{
|
||||
IO.Write(Temp + "type=", Key.Type);
|
||||
if (Key.Type > 0) IO.Write(Temp + "value=", Key.Value);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Key.EPTypePost != null) IO.Write(Temp + "ep_type_post=", Key.EPTypePost);
|
||||
if (Key.EPTypePre != null) IO.Write(Temp + "ep_type_pre=" , Key.EPTypePre );
|
||||
if (Key.RawData == null && Key.Trans != null)
|
||||
{
|
||||
SO = Key.Trans.Length.SortWriter();
|
||||
for (i = 0; i < Key.Trans.Length; i++)
|
||||
{
|
||||
SOi = SO[i];
|
||||
IO.Write(Temp + "key" + d + SOi + d + "data=", Key.Trans[SOi].ToString());
|
||||
IO.Write(Temp + "key" + d + SOi + d + "type=", Key.Trans[SOi].Type );
|
||||
}
|
||||
IO.Write(Temp + "key.length=", Key.Length);
|
||||
if (Key.Max != null) IO.Write(Temp + "max=", Key.Max);
|
||||
}
|
||||
else if (Key.Trans != null)
|
||||
{
|
||||
if (Key.Max != null) IO.Write(Temp + "max=", Key.Max);
|
||||
for (i = 0; i < Key.Trans.Length; i++)
|
||||
{
|
||||
if (Key.RawData.KeyType < Key.Trans[i].Type || Key.RawData.KeyType == null)
|
||||
Key.RawData.KeyType = Key.Trans[i].Type;
|
||||
if (Key.RawData.KeyType == 3) break;
|
||||
}
|
||||
Key.RawData.ValueListSize = Key.Trans.Length * (Key.RawData.KeyType + 1);
|
||||
IO.Write(Temp + "raw_data.value_list=");
|
||||
for (i = 0; i < Key.Trans.Length; i++)
|
||||
IO.Write(Key.Trans[i].ToString(false));
|
||||
IO.Position = IO.Position - 1;
|
||||
IO.Write('\n');
|
||||
IO.Write(Temp + "raw_data.value_list_size=", Key.RawData.ValueListSize);
|
||||
IO.Write(Temp + "raw_data.value_type=" , Key.RawData.ValueType );
|
||||
IO.Write(Temp + "raw_data_key_type=" , Key.RawData. KeyType );
|
||||
}
|
||||
IO.Write(Temp + "type=", Key.Type & 0xFF);
|
||||
if (Key.RawData == null && Key.Trans == null && Key.Value != null)
|
||||
if (Key.Value != 0) IO.Write(Temp + "value=", Key.Value);
|
||||
}
|
||||
|
||||
public static void ReadMT(this Stream IO, ref ModelTransform MT, int C_F16)
|
||||
{
|
||||
if (MT.BinOffset == null) return;
|
||||
|
||||
IO.Position = IO.Offset + (int)MT.BinOffset;
|
||||
|
||||
IO.ReadOffset(out MT.Scale);
|
||||
IO.ReadOffset(out MT.Rot );
|
||||
IO.ReadOffset(out MT.Trans);
|
||||
MT.Visibility = new Key { BinOffset = IO.ReadInt32() };
|
||||
|
||||
IO.ReadVec3(ref MT.Scale , C_F16);
|
||||
IO.ReadVec3(ref MT.Rot , C_F16, true);
|
||||
IO.ReadVec3(ref MT.Trans , C_F16);
|
||||
IO.ReadKey (ref MT.Visibility, C_F16);
|
||||
}
|
||||
|
||||
public static void ReadRGBAKey(this Stream IO, ref RGBAKey RGBA, int C_F16)
|
||||
{ IO.ReadKey(ref RGBA.R, C_F16); IO.ReadKey(ref RGBA.G, C_F16);
|
||||
IO.ReadKey(ref RGBA.B, C_F16); IO.ReadKey(ref RGBA.A, C_F16); }
|
||||
|
||||
public static void ReadVec3(this Stream IO, ref Vector3<Key> Key, int C_F16, bool F16 = false)
|
||||
{ IO.ReadKey(ref Key.X, C_F16, F16); IO.ReadKey(ref Key.Y,
|
||||
C_F16, F16); IO.ReadKey(ref Key.Z, C_F16, F16); }
|
||||
|
||||
public static void ReadKeyUV(this Stream IO, ref KeyUV UV, int C_F16)
|
||||
{ IO.ReadKey(ref UV.U, C_F16); IO.ReadKey(ref UV.V, C_F16); }
|
||||
|
||||
public static void ReadKey(this Stream IO, ref Key Key, int C_F16, bool F16 = false)
|
||||
{
|
||||
if (Key == null) return;
|
||||
if (Key.BinOffset == null || Key.BinOffset < 0) return;
|
||||
|
||||
IO.Position = IO.Offset + (int)Key.BinOffset;
|
||||
Key.Type = IO.ReadInt32();
|
||||
|
||||
Key.Value = IO.ReadSingle();
|
||||
if (Key.Type == 0x0000 || Key.Type == 0x0001) return;
|
||||
|
||||
Key.Max = IO.ReadSingle();
|
||||
Key.Length = IO.ReadInt32 ();
|
||||
Key.Trans = new Key.Transform[(int)Key.Length];
|
||||
int Ke = (int)Key.Length;
|
||||
for (int i = 0; i < Key.Length; i++)
|
||||
{
|
||||
Key.Trans[i] = new Key.Transform { Type = 3, Value = new double[3] };
|
||||
if (F16 && C_F16 > 0)
|
||||
{ Key.Trans[i].Frame = IO.ReadUInt16(); Key.Trans[i].Value[0] = (double)IO.ReadHalf (); }
|
||||
else
|
||||
{ Key.Trans[i].Frame = IO.ReadSingle(); Key.Trans[i].Value[0] = IO.ReadSingle(); }
|
||||
|
||||
if (F16 && C_F16 == 2)
|
||||
{ Key.Trans[i].Value[1] = (double)IO.ReadHalf ();
|
||||
Key.Trans[i].Value[2] = (double)IO.ReadHalf (); }
|
||||
else
|
||||
{ Key.Trans[i].Value[1] = IO.ReadSingle();
|
||||
Key.Trans[i].Value[2] = IO.ReadSingle(); }
|
||||
}
|
||||
}
|
||||
|
||||
public static void ReadOffset(this Stream IO, out Vector3<Key> Key)
|
||||
{ Key = new Vector3<Key> { X = new Key { BinOffset = IO.ReadInt32() },
|
||||
Y = new Key { BinOffset = IO.ReadInt32() },
|
||||
Z = new Key { BinOffset = IO.ReadInt32() }, }; }
|
||||
|
||||
public static void WriteOffset(this Stream IO, ref ModelTransform MT, bool ReturnToOffset)
|
||||
{
|
||||
if (ReturnToOffset)
|
||||
{
|
||||
IO.Position = (int)MT.BinOffset;
|
||||
IO.WriteOffset(MT.Scale);
|
||||
IO.WriteOffset(MT.Rot );
|
||||
IO.WriteOffset(MT.Trans);
|
||||
IO.Write(MT.Visibility.BinOffset);
|
||||
}
|
||||
else
|
||||
{
|
||||
MT.BinOffset = IO.Position;
|
||||
IO.Position += 0x30;
|
||||
IO.Length += 0x30;
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteOffset(this Stream IO, Vector3<Key> Key)
|
||||
{
|
||||
IO.Write(Key.X.BinOffset);
|
||||
IO.Write(Key.Y.BinOffset);
|
||||
IO.Write(Key.Z.BinOffset);
|
||||
}
|
||||
|
||||
public static ModelTransform ReadMT(this MsgPack k, string name)
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadMT(); return new ModelTransform(); }
|
||||
|
||||
public static ModelTransform ReadMT(this MsgPack k) =>
|
||||
new ModelTransform { Rot = k.ReadVec3("Rot" ), Scale = k.ReadVec3("Scale" ),
|
||||
Trans = k.ReadVec3("Trans"), Visibility = k.ReadKey ("Visibility") };
|
||||
|
||||
public static RGBAKey ReadRGBAKey(this MsgPack k, string name)
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadRGBAKey(); return new RGBAKey(); }
|
||||
|
||||
public static RGBAKey ReadRGBAKey(this MsgPack k) =>
|
||||
new RGBAKey { R = k.ReadKey("R"), G = k.ReadKey("G"), B = k.ReadKey("B"), A = k.ReadKey("A") };
|
||||
|
||||
public static Vector3<Key> ReadVec3(this MsgPack k, string name)
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadVec3(); return new Vector3<Key>(); }
|
||||
|
||||
public static Vector3<Key> ReadVec3(this MsgPack k) =>
|
||||
new Vector3<Key> { X = k.ReadKey("X"), Y = k.ReadKey("Y"), Z = k.ReadKey("Z") };
|
||||
|
||||
public static KeyUV ReadKeyUV(this MsgPack k, string name)
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadKeyUV(); return new KeyUV(); }
|
||||
|
||||
public static KeyUV ReadKeyUV(this MsgPack k) =>
|
||||
new KeyUV { U = k.ReadKey("U"), V = k.ReadKey("V") };
|
||||
|
||||
public static Key ReadKey(this MsgPack k, string name)
|
||||
{ if (k.Element(name, out MsgPack Name)) return Name.ReadKey(); return null; }
|
||||
|
||||
public static Key ReadKey(this MsgPack k)
|
||||
{
|
||||
if (k == null) return null;
|
||||
|
||||
Key Key = new Key { EPTypePost = k.ReadNDouble("Post"),
|
||||
EPTypePre = k.ReadNDouble("Pre"), Max = k.ReadNDouble("M"),
|
||||
Type = k.ReadNInt32("T"), Value = k.ReadNDouble("V") };
|
||||
if (k.ReadBoolean("RD")) Key.RawData = new Key.RawD();
|
||||
if (Key.Type == 0) Key.Value = 0.0;
|
||||
|
||||
if (Key.Type < 2) return Key;
|
||||
|
||||
if (!k.Element("Trans", out MsgPack Trans, typeof(object[]))) return Key;
|
||||
|
||||
Key.Length = ((object[])Trans.Object).Length;
|
||||
Key.Trans = new Key.Transform[Key.Length.Value];
|
||||
MsgPack _Trans = new MsgPack();
|
||||
byte i1 = 0;
|
||||
for (int i = 0; i < Key.Length; i++)
|
||||
{
|
||||
Key.Trans[i] = new Key.Transform();
|
||||
if (Trans[i].GetType() != typeof(MsgPack)) continue;
|
||||
|
||||
_Trans = (MsgPack)Trans[i];
|
||||
if (_Trans.Object.GetType() != typeof(object[])) continue;
|
||||
Key.Trans[i].Type = ((object[])_Trans.Object).Length - 1;
|
||||
Key.Trans[i].Value = new double[Key.Trans[i].Type];
|
||||
|
||||
if (_Trans[0].GetType() != typeof(MsgPack)) continue;
|
||||
Key.Trans[i].Frame = ((MsgPack)_Trans[0]).ReadDouble();
|
||||
|
||||
for (i1 = 0; i1 < Key.Trans[i].Type; i1++)
|
||||
Key.Trans[i].Value[i1] = ((MsgPack)_Trans[i1 + 1]).ReadDouble();
|
||||
}
|
||||
return Key;
|
||||
}
|
||||
|
||||
public static MsgPack WriteMP(this ModelTransform MT, string name) =>
|
||||
MT.WriteMP(new MsgPack(name));
|
||||
|
||||
public static MsgPack WriteMP(this ModelTransform MT) =>
|
||||
MT.WriteMP(new MsgPack( ));
|
||||
|
||||
public static MsgPack WriteMP(this ModelTransform MT, MsgPack MTs) =>
|
||||
MTs.Add(MT.Rot .WriteMP("Rot" ))
|
||||
.Add(MT.Scale .WriteMP("Scale" ))
|
||||
.Add(MT.Trans .WriteMP("Trans" ))
|
||||
.Add(MT.Visibility.WriteMP("Visibility"));
|
||||
|
||||
public static MsgPack WriteMP(this RGBAKey RGBA, string name)
|
||||
{
|
||||
if (RGBA.R == null && RGBA.G == null && RGBA.B == null && RGBA.A == null) return MsgPack.Null;
|
||||
return new MsgPack(name).Add(RGBA.R.WriteMP("R")).Add(RGBA.G.WriteMP("G"))
|
||||
.Add(RGBA.B.WriteMP("B")).Add(RGBA.A.WriteMP("A"));
|
||||
}
|
||||
|
||||
public static MsgPack WriteMP(this Vector3<Key> Key, string name) =>
|
||||
new MsgPack(name).Add(Key.X.WriteMP("X")).Add(Key.Y.WriteMP("Y")).Add(Key.Z.WriteMP("Z"));
|
||||
|
||||
public static MsgPack WriteMP(this KeyUV UV, string name)
|
||||
{
|
||||
if (UV.U == null && UV.V == null) return MsgPack.Null;
|
||||
return new MsgPack(name).Add(UV.U.WriteMP("U")).Add(UV.V.WriteMP("V"));
|
||||
}
|
||||
|
||||
public static MsgPack WriteMP(this Key Key, string name)
|
||||
{
|
||||
if (Key == null) return MsgPack.Null;
|
||||
if (Key.Type == null) return MsgPack.Null;
|
||||
|
||||
MsgPack Keys = new MsgPack(name).Add("T", Key.Type);
|
||||
if (Key.Trans != null)
|
||||
{
|
||||
Keys.Add("Post", Key.EPTypePost).Add("Pre", Key.EPTypePre).Add("M", Key.Max);
|
||||
|
||||
if (Key.RawData != null) Keys.Add("RD", true);
|
||||
|
||||
byte i0 = 0;
|
||||
MsgPack Trans = new MsgPack("Trans", Key.Trans.Length);
|
||||
for (int i = 0; i < Key.Trans.Length; i++)
|
||||
{
|
||||
MsgPack K = new MsgPack(Key.Trans[i].Type + 1);
|
||||
K[0] = Key.Trans[i].Frame;
|
||||
for (i0 = 1; i0 < Key.Trans[i].Type + 1; i0++)
|
||||
K[i0] = Key.Trans[i].Value[i0 - 1];
|
||||
Trans[i] = K;
|
||||
}
|
||||
Keys.Add(Trans);
|
||||
}
|
||||
else if (Key.Value != 0) Keys.Add("V", Key.Value);
|
||||
return Keys;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, string Data, ref bool? val)
|
||||
{ if (val != null) IO.Write(Data, ( bool)val ); }
|
||||
public static void Write(this Stream IO, string Data, long? val)
|
||||
{ if (val != null) IO.Write(Data, ( long)val ); }
|
||||
public static void Write(this Stream IO, string Data, ulong? val)
|
||||
{ if (val != null) IO.Write(Data, ( ulong)val ); }
|
||||
public static void Write(this Stream IO, string Data, double? val)
|
||||
{ if (val != null) IO.Write(Data, (double)val ); }
|
||||
public static void Write(this Stream IO, string Data, double? val, byte r)
|
||||
{ if (val != null) IO.Write(Data, (double)val, r); }
|
||||
public static void Write(this Stream IO, string Data, ref bool val) =>
|
||||
IO.Write(Data, Main.ToString(val));
|
||||
public static void Write(this Stream IO, string Data, long val) =>
|
||||
IO.Write(Data, val.ToString( ));
|
||||
public static void Write(this Stream IO, string Data, ulong val) =>
|
||||
IO.Write(Data, val.ToString( ));
|
||||
public static void Write(this Stream IO, string Data, double val) =>
|
||||
IO.Write(Data, val.ToString( ));
|
||||
public static void Write(this Stream IO, string Data, double val, byte r) =>
|
||||
IO.Write(Data, val.ToString(r ));
|
||||
public static void Write(this Stream IO, string Data, string val)
|
||||
{ if (val != null) IO.Write((Data + val + "\n").ToUTF8()); }
|
||||
}
|
||||
}
|
||||
+974
-25
File diff suppressed because it is too large
Load Diff
+114
-110
@@ -1,48 +1,46 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
using MPIO = KKdMainLib.MessagePack.IO;
|
||||
|
||||
namespace KKdMainLib.DB
|
||||
{
|
||||
public class Aet
|
||||
public class Aet : System.IDisposable
|
||||
{
|
||||
public AetSet[] AetSets;
|
||||
|
||||
private Stream IO;
|
||||
private int i, i0, i1, i2;
|
||||
private Stream s;
|
||||
|
||||
public AetSet[] AetSets;
|
||||
|
||||
public void BINReader(string file)
|
||||
{
|
||||
IO = File.OpenReader(file + ".bin");
|
||||
s = File.OpenReader(file + ".bin");
|
||||
|
||||
int aetSetsLength = IO.ReadInt32();
|
||||
int aetSetsOffset = IO.ReadInt32();
|
||||
int aetsLength = IO.ReadInt32();
|
||||
int aetsOffset = IO.ReadInt32();
|
||||
int aetSetsLength = s.RI32();
|
||||
int aetSetsOffset = s.RI32();
|
||||
int aetsLength = s.RI32();
|
||||
int aetsOffset = s.RI32();
|
||||
|
||||
IO.Position = aetSetsOffset;
|
||||
s.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 = s.RI32();
|
||||
AetSets[i].Name = s.RSaO();
|
||||
AetSets[i].FileName = s.RSaO();
|
||||
s.RI32();
|
||||
AetSets[i].SpriteSetId = s.RI32();
|
||||
}
|
||||
|
||||
int setIndex;
|
||||
AET aet = new AET();
|
||||
int[] AetCount = new int[aetSetsLength];
|
||||
|
||||
IO.Position = aetsOffset;
|
||||
s.P = aetsOffset;
|
||||
for (i = 0; i < aetsLength; i++)
|
||||
{
|
||||
IO.LongPosition += 10;
|
||||
setIndex = IO.ReadInt16();
|
||||
s.PI64 += 10;
|
||||
setIndex = s.RI16();
|
||||
AetCount[setIndex]++;
|
||||
}
|
||||
|
||||
@@ -52,18 +50,18 @@ namespace KKdMainLib.DB
|
||||
AetCount[i] = 0;
|
||||
}
|
||||
|
||||
IO.Position = aetsOffset;
|
||||
s.P = aetsOffset;
|
||||
for (i = 0; i < aetsLength; i++)
|
||||
{
|
||||
aet.Id = IO.ReadInt32();
|
||||
aet.Name = IO.ReadStringAtOffset();
|
||||
IO.ReadInt16();
|
||||
setIndex = IO.ReadInt16();
|
||||
aet.Id = s.RI32();
|
||||
aet.Name = s.RSaO();
|
||||
s.RI16();
|
||||
setIndex = s.RI16();
|
||||
|
||||
AetSets[setIndex].Aets[AetCount[setIndex]] = aet; AetCount[setIndex]++;
|
||||
}
|
||||
|
||||
IO.Close();
|
||||
s.C();
|
||||
}
|
||||
|
||||
|
||||
@@ -72,13 +70,13 @@ namespace KKdMainLib.DB
|
||||
if (AetSets == null) return;
|
||||
if (AetSets.Length == 0) return;
|
||||
|
||||
List<string> SetName = new List<string>();
|
||||
List<string> SetFileName = new List<string>();
|
||||
KKdList<string> setName = KKdList<string>.New;
|
||||
KKdList<string> setFileName = KKdList<string>.New;
|
||||
|
||||
List<int> Ids = new List<int>();
|
||||
List<int> SetIds = new List<int>();
|
||||
KKdList<int> ids = KKdList<int>.New;
|
||||
KKdList<int> setIds = KKdList<int>.New;
|
||||
|
||||
List<int> NotAdd = new List<int>();
|
||||
KKdList<int> notAdd = KKdList<int>.New;
|
||||
AET temp;
|
||||
AetSet set;
|
||||
|
||||
@@ -86,11 +84,11 @@ namespace KKdMainLib.DB
|
||||
{
|
||||
set = AetSets[i];
|
||||
if (set. Name != null)
|
||||
if (SetName .Contains(set. Name)) { NotAdd.Add(i); continue; }
|
||||
else SetName .Add (set. Name);
|
||||
if (setName .Contains(set. Name)) { notAdd.Add(i); continue; }
|
||||
else setName .Add (set. Name);
|
||||
if (set.FileName != null)
|
||||
if (SetFileName.Contains(set.FileName)) { NotAdd.Add(i); continue; }
|
||||
else SetFileName.Add (set.FileName);
|
||||
if (setFileName.Contains(set.FileName)) { notAdd.Add(i); continue; }
|
||||
else setFileName.Add (set.FileName);
|
||||
|
||||
if (set.NewId)
|
||||
{
|
||||
@@ -100,122 +98,128 @@ namespace KKdMainLib.DB
|
||||
}
|
||||
|
||||
if (set.Id != null)
|
||||
if (SetIds.Contains((int)set.Id)) { NotAdd.Add(i); continue; }
|
||||
else SetIds.Add ((int)set.Id);
|
||||
if (setIds.Contains((int)set.Id)) { notAdd.Add(i); continue; }
|
||||
else setIds.Add ((int)set.Id);
|
||||
|
||||
for (i0 = 0; i0 < set.Aets.Length; i0++)
|
||||
{
|
||||
temp = set.Aets[i0];
|
||||
if (temp.Id != null)
|
||||
if ( Ids.Contains((int)temp.Id)) { NotAdd.Add(i); break; }
|
||||
else Ids.Add ((int)temp.Id);
|
||||
if ( ids.Contains((int)temp.Id)) { notAdd.Add(i); break; }
|
||||
else ids.Add ((int)temp.Id);
|
||||
}
|
||||
}
|
||||
SetName = null;
|
||||
SetFileName = null;
|
||||
setName .Dispose();
|
||||
setFileName.Dispose();
|
||||
|
||||
for (i = 0; i < AetSets.Length; i++)
|
||||
{
|
||||
set = AetSets[i];
|
||||
if (NotAdd.Contains(i)) continue;
|
||||
if (notAdd.Contains(i)) continue;
|
||||
if (!set.NewId) continue;
|
||||
|
||||
i1 = 0;
|
||||
if (set.Id == null) while (true)
|
||||
{ if (!SetIds.Contains(i1)) { AetSets[i].Id = i1; SetIds.Add(i1); break; } i1++; }
|
||||
{ if (!setIds.Contains(i1)) { AetSets[i].Id = i1; setIds.Add(i1); break; } i1++; }
|
||||
|
||||
for (i0 = 0, i1 = 0; i0 < set.Aets.Length; i0++)
|
||||
if (set.Aets[i0].Id == null) while (true) { if (!Ids.Contains(i1))
|
||||
{ AetSets[i].Aets[i0].Id = i1; Ids.Add(i1); break; } i1++; }
|
||||
if (set.Aets[i0].Id == null) while (true) { if (!ids.Contains(i1))
|
||||
{ AetSets[i].Aets[i0].Id = i1; ids.Add(i1); break; } i1++; }
|
||||
}
|
||||
|
||||
Ids = null;
|
||||
SetIds = null;
|
||||
ids.Dispose();
|
||||
setIds.Dispose();
|
||||
|
||||
for (i = 0, i0 = 0, i2 = 0; i < AetSets.Length; i++)
|
||||
if (!NotAdd.Contains(i)) { i0 += AetSets[i].Aets.Length; i2++; }
|
||||
|
||||
if (!notAdd.Contains(i)) { i0 += AetSets[i].Aets.Length; i2++; }
|
||||
|
||||
i1 = i0 * 12;
|
||||
i1 = i1.Align(0x20) + 0x20;
|
||||
i1 = i1.A(0x20) + 0x20;
|
||||
|
||||
IO = File.OpenWriter(file + ".bin", true);
|
||||
IO.Write(i2);
|
||||
IO.Write(i1);
|
||||
IO.Write(i0);
|
||||
IO.Write(0x20);
|
||||
IO.Write(0x9066906690669066);
|
||||
IO.Write(0x9066906690669066);
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
s.W(i2);
|
||||
s.W(i1);
|
||||
s.W(i0);
|
||||
s.W(0x20);
|
||||
s.W(0x9066906690669066);
|
||||
s.W(0x9066906690669066);
|
||||
|
||||
IO.Position = (i1 + i2 * 0x14).Align(0x20);
|
||||
s.P = (i1 + i2 * 0x14).A(0x20);
|
||||
for (i = 0; i < AetSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) continue;
|
||||
AetSets[i]. NameOffset = IO.Position; IO.Write(AetSets[i]. Name + "\0");
|
||||
AetSets[i].FileNameOffset = IO.Position; IO.Write(AetSets[i].FileName + "\0");
|
||||
if (notAdd.Contains(i)) continue;
|
||||
AetSets[i]. NameOffset = s.P; s.W(AetSets[i]. Name + "\0");
|
||||
AetSets[i].FileNameOffset = s.P; s.W(AetSets[i].FileName + "\0");
|
||||
}
|
||||
|
||||
for (i = 0; i < AetSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) continue;
|
||||
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 = s.P; s.W(AetSets[i].Aets[i0].Name + "\0"); }
|
||||
}
|
||||
IO.Align(0x08, true);
|
||||
|
||||
IO.Position = 0x20;
|
||||
s.A(0x08, true);
|
||||
|
||||
s.P = 0x20;
|
||||
for (i = 0, i2 = 0; i < AetSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) { i2++; continue; }
|
||||
|
||||
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));
|
||||
s.W(AetSets[i].Aets[i0].Id );
|
||||
s.W(AetSets[i].Aets[i0].NameOffset);
|
||||
s.W((ushort) i0 );
|
||||
s.W((ushort)(i - i2));
|
||||
}
|
||||
}
|
||||
IO.Align(0x20);
|
||||
s.A(0x20);
|
||||
|
||||
for (i = 0, i2 = 0; i < AetSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) { i2++; continue; }
|
||||
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 );
|
||||
s.W(AetSets[i].Id );
|
||||
s.W(AetSets[i]. NameOffset);
|
||||
s.W(AetSets[i].FileNameOffset);
|
||||
s.W(i - i2);
|
||||
s.W(AetSets[i].SpriteSetId );
|
||||
}
|
||||
IO.Close();
|
||||
notAdd.Dispose();
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
public void MsgPackReader(string file, bool json)
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
MsgPack MsgPack = file.ReadMPAllAtOnce(json);
|
||||
|
||||
if (MsgPack.Element("AetDB", out MsgPack AetDB, typeof(object[])))
|
||||
MsgPack Temp = default;
|
||||
if ((Temp = MsgPack["AetDB", true]).NotNull)
|
||||
{
|
||||
AetSets = new AetSet[((object[])AetDB.Object).Length];
|
||||
AetSets = new AetSet[Temp.Array.Length];
|
||||
for (int i = 0; i < AetSets.Length; i++)
|
||||
if (AetDB[i].GetType() == typeof(MsgPack))
|
||||
AetSets[i].ReadMsgPack((MsgPack)AetDB[i]);
|
||||
AetSets[i].ReadMsgPack(Temp[i]);
|
||||
}
|
||||
MsgPack = null;
|
||||
Temp.Dispose();
|
||||
MsgPack.Dispose();
|
||||
}
|
||||
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
if (AetSets == null) return;
|
||||
if (AetSets.Length == 0) return;
|
||||
|
||||
MsgPack AetDB = new MsgPack("AetDB", AetSets.Length);
|
||||
MsgPack AetDB = new MsgPack(AetSets.Length, "AetDB");
|
||||
for (i = 0; i < AetSets.Length; i++)
|
||||
AetDB[i] = AetSets[i].WriteMsgPack();
|
||||
|
||||
AetDB.Write(true, file, JSON);
|
||||
AetDB.Write(false, true, file, json);
|
||||
}
|
||||
|
||||
private bool disposed = false;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; AetSets = null; disposed = true; } }
|
||||
|
||||
public struct AET
|
||||
{
|
||||
public int NameOffset;
|
||||
@@ -223,10 +227,10 @@ namespace KKdMainLib.DB
|
||||
public string Name;
|
||||
|
||||
public void ReadMsgPack(MsgPack msg)
|
||||
{ Id = msg.ReadNUInt16("Id"); Name = msg.ReadString("Name"); }
|
||||
|
||||
{ Id = msg.RnU16("Id"); Name = msg.RS("Name"); }
|
||||
|
||||
public MsgPack WriteMsgPack() =>
|
||||
new MsgPack().Add("Id", Id).Add("Name", Name);
|
||||
MsgPack.New.Add("Id", Id).Add("Name", Name);
|
||||
}
|
||||
|
||||
public struct AetSet
|
||||
@@ -239,32 +243,32 @@ namespace KKdMainLib.DB
|
||||
public string Name;
|
||||
public string FileName;
|
||||
public AET[] Aets;
|
||||
|
||||
|
||||
public void ReadMsgPack(MsgPack msg)
|
||||
{
|
||||
FileName = msg.ReadString ("FileName" );
|
||||
Id = msg.ReadNUInt16( "Id");
|
||||
Name = msg.ReadString ( "Name" );
|
||||
NewId = msg.ReadBoolean("NewId" );
|
||||
SpriteSetId = msg.ReadNUInt16("SpriteSetId");
|
||||
FileName = msg.RS ("FileName" );
|
||||
Id = msg.RnU16( "Id");
|
||||
Name = msg.RS ( "Name" );
|
||||
NewId = msg.RB ("NewId" );
|
||||
SpriteSetId = msg.RnU16("SpriteSetId");
|
||||
|
||||
if (msg.Element("Aets", out MsgPack Aets, typeof(object[])))
|
||||
MsgPack Temp;
|
||||
if ((Temp = msg["Aets", true]).NotNull)
|
||||
{
|
||||
object Aet;
|
||||
this .Aets = new AET[((object[])Aets.Object).Length];
|
||||
for (int i0 = 0; i0 < this.Aets.Length; i0++)
|
||||
{ Aet = Aets[i0]; if (Aet.GetType() == typeof(MsgPack))
|
||||
this.Aets[i0].ReadMsgPack((MsgPack)Aet); }
|
||||
Aets = new AET[Temp.Array.Length];
|
||||
for (int i0 = 0; i0 < Aets.Length; i0++)
|
||||
Aets[i0].ReadMsgPack(Temp[i0]);
|
||||
}
|
||||
Temp.Dispose();
|
||||
}
|
||||
|
||||
public MsgPack WriteMsgPack()
|
||||
{
|
||||
MsgPack Aets = new MsgPack("Aets", this.Aets.Length);
|
||||
MsgPack Aets = new MsgPack(this.Aets.Length, "Aets");
|
||||
for (int i0 = 0; i0 < this.Aets.Length; i0++)
|
||||
Aets[i0] = this.Aets[i0].WriteMsgPack();
|
||||
|
||||
return new MsgPack().Add("FileName", FileName).Add("Id", Id)
|
||||
return MsgPack.New.Add("FileName", FileName).Add("Id", Id)
|
||||
.Add("Name", Name).Add("SpriteSetId", SpriteSetId).Add(Aets);
|
||||
}
|
||||
}
|
||||
|
||||
+124
-121
@@ -1,161 +1,164 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.A3DA;
|
||||
using KKdMainLib.MessagePack;
|
||||
using MPIO = KKdMainLib.MessagePack.IO;
|
||||
using A3DADict = System.Collections.Generic.Dictionary<string, object>;
|
||||
|
||||
namespace KKdMainLib.DB
|
||||
{
|
||||
public struct Auth
|
||||
public class Auth : IDisposable
|
||||
{
|
||||
public int Signature { get; private set; }
|
||||
public string[] Category { get; private set; }
|
||||
public UID[] _UID { get; private set; }
|
||||
public Stream IO { get; private set; }
|
||||
private int i;
|
||||
private Stream s;
|
||||
|
||||
public string[] Category;
|
||||
public UID[] UIDs;
|
||||
|
||||
public void BINReader(string file)
|
||||
{
|
||||
Dictionary<string, object> Dict = new Dictionary<string, object>();
|
||||
string[] dataArray;
|
||||
A3DADict dict = new A3DADict();
|
||||
|
||||
IO = File.OpenReader(file + ".bin");
|
||||
s = File.OpenReader(file + ".bin");
|
||||
|
||||
IO.Format = Main.Format.F;
|
||||
Signature = IO.ReadInt32();
|
||||
if (Signature != 0x44334123) return;
|
||||
Signature = IO.ReadInt32();
|
||||
if (Signature != 0x5F5F5F41) return;
|
||||
IO.ReadInt64();
|
||||
s.Format = Format.F;
|
||||
int signature = s.RI32();
|
||||
if (signature != 0x44334123) return;
|
||||
signature = s.RI32();
|
||||
if (signature != 0x5F5F5F41) return;
|
||||
s.RI64();
|
||||
|
||||
string[] STRData = IO.ReadString(IO.Length - IO.Position).Replace("\r", "").Split('\n');
|
||||
for (int i = 0; i < STRData.Length; i++)
|
||||
{
|
||||
dataArray = STRData[i].Split('=');
|
||||
if (dataArray.Length == 2)
|
||||
Dict.GetDictionary(dataArray[0], dataArray[1]);
|
||||
}
|
||||
string[] strData = s.RS(s.L - s.P).Replace("\r\n", "\n").Replace("\r", "\n").Split('\n');
|
||||
for (i = 0; i < strData.Length; i++)
|
||||
dict.GD(strData[i]);
|
||||
strData = null;
|
||||
|
||||
if (Dict.FindValue(out string value, "category.length"))
|
||||
if (dict.FV(out string value, "category.length"))
|
||||
{
|
||||
Category = new string[int.Parse(value)];
|
||||
for (int i0 = 0; i0 < Category.Length; i0++)
|
||||
if (Dict.FindValue(out value, "category." + i0 + ".value"))
|
||||
Category[i0] = value;
|
||||
for (i = 0; i < Category.Length; i++)
|
||||
if (dict.FV(out value, $"category.{i}.value"))
|
||||
Category[i] = value;
|
||||
}
|
||||
|
||||
if (Dict.FindValue(out value, "uid.length"))
|
||||
if (dict.FV(out value, "uid.length"))
|
||||
{
|
||||
_UID = new UID[int.Parse(value)];
|
||||
for (int i0 = 0; i0 < _UID.Length; i0++)
|
||||
UIDs = new UID[int.Parse(value)];
|
||||
for (i = 0; i < UIDs.Length; i++)
|
||||
{
|
||||
Dict.FindValue(out _UID[i0].Category, "uid." + i0 + ".category");
|
||||
Dict.FindValue(out _UID[i0].OrgUid , "uid." + i0 + ".org_uid" );
|
||||
Dict.FindValue(out _UID[i0].Size , "uid." + i0 + ".size" );
|
||||
Dict.FindValue(out _UID[i0].Value , "uid." + i0 + ".value" );
|
||||
dict.FV(out UIDs[i].Category, $"uid.{i}.category");
|
||||
dict.FV(out UIDs[i].OrgUid , $"uid.{i}.org_uid" );
|
||||
dict.FV(out UIDs[i].Size , $"uid.{i}.size" );
|
||||
dict.FV(out UIDs[i].Value , $"uid.{i}.value" );
|
||||
}
|
||||
}
|
||||
|
||||
IO.Close();
|
||||
s.C();
|
||||
dict.Clear();
|
||||
dict = null;
|
||||
}
|
||||
|
||||
public void BINWriter(string file)
|
||||
{
|
||||
IO = File.OpenWriter(file + ".bin", true);
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
|
||||
IO.Write("#A3DA__________\n");
|
||||
IO.Write("#", DateTime.UtcNow.ToString("ddd MMM dd HH:mm:ss yyyy",
|
||||
System.Globalization.CultureInfo.InvariantCulture));
|
||||
s.W("#A3DA__________\n");
|
||||
s.W("# date time was eliminated.\n");
|
||||
|
||||
if (Category != null)
|
||||
{
|
||||
int[] SO = Category.Length.SortWriter();
|
||||
int[] so = Category.Length.SW();
|
||||
for (i = 0; i < Category.Length; i++)
|
||||
s.W($"category.{so[i]}.value={ Category[so[i]]}\n");
|
||||
s.W($"category.length={Category.Length}\n");
|
||||
}
|
||||
|
||||
if (UIDs != null)
|
||||
{
|
||||
int[] so = UIDs.Length.SW();
|
||||
int max = -1;
|
||||
for (i = 0; i < UIDs.Length; i++)
|
||||
{
|
||||
if (UIDs[so[i]].Category != null && UIDs[so[i]].Category != "")
|
||||
s.W($"uid.{so[i]}.category=" + UIDs[so[i]].Category + "\n");
|
||||
if (UIDs[so[i]].OrgUid != null)
|
||||
{
|
||||
int orgUid = UIDs[so[i]].OrgUid.Value;
|
||||
s.W($"uid.{so[i]}.org_uid=" + orgUid + "\n");
|
||||
if (max < orgUid)
|
||||
max = orgUid;
|
||||
}
|
||||
if (UIDs[so[i]].Size != null)
|
||||
s.W($"uid.{so[i]}.size=" + UIDs[so[i]].Size + "\n");
|
||||
if (UIDs[so[i]].Value != null && UIDs[so[i]].Value != "")
|
||||
s.W($"uid.{so[i]}.value=" + UIDs[so[i]].Value + "\n");
|
||||
}
|
||||
s.W($"uid.length={UIDs.Length}\n");
|
||||
if (max != -1)
|
||||
s.W($"uid.max={max}\n");
|
||||
}
|
||||
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
{
|
||||
MsgPack msgPack = file.ReadMPAllAtOnce(json);
|
||||
|
||||
MsgPack authDB;
|
||||
if ((authDB = msgPack["AuthDB"]).NotNull)
|
||||
{
|
||||
MsgPack temp;
|
||||
if ((temp = authDB["Category", true]).NotNull)
|
||||
{
|
||||
Category = new string[temp.Array.Length];
|
||||
for (int i = 0; i < Category.Length; i++)
|
||||
Category[i] = temp[i].RS();
|
||||
}
|
||||
|
||||
if ((temp = authDB["UID", true]).NotNull)
|
||||
{
|
||||
UIDs = new UID[temp.Array.Length];
|
||||
for (int i = 0; i < UIDs.Length; i++)
|
||||
{
|
||||
UIDs[i].Category = temp[i].RS ("Category");
|
||||
UIDs[i].OrgUid = temp[i].RnI32("OrgUid" );
|
||||
UIDs[i].Size = temp[i].RnI32("Size" );
|
||||
UIDs[i].Value = temp[i].RS ("Value" );
|
||||
}
|
||||
}
|
||||
temp.Dispose();
|
||||
}
|
||||
authDB.Dispose();
|
||||
msgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
MsgPack authDB = new MsgPack("AuthDB");
|
||||
if (Category != null)
|
||||
{
|
||||
MsgPack category = new MsgPack(Category.Length, "Category");
|
||||
for (int i = 0; i < Category.Length; i++)
|
||||
if (Category[SO[i]] != null)
|
||||
IO.Write("category." + SO[i] + ".value=", Category[SO[i]]);
|
||||
IO.Write("category.length=", Category.Length);
|
||||
category[i] = (MsgPack)Category[i];
|
||||
authDB.Add(category);
|
||||
}
|
||||
|
||||
if (_UID != null)
|
||||
if (UIDs != null)
|
||||
{
|
||||
int[] SO = _UID.Length.SortWriter();
|
||||
for (int i = 0; i < _UID.Length; i++)
|
||||
{
|
||||
if (_UID[SO[i]].Category != null)
|
||||
if (_UID[SO[i]].Category != "")
|
||||
IO.Write("uid." + SO[i] + ".category=", _UID[SO[i]].Category);
|
||||
if (_UID[SO[i]].OrgUid != null)
|
||||
IO.Write("uid." + SO[i] + ".org_uid=" , _UID[SO[i]].OrgUid );
|
||||
if (_UID[SO[i]].Size != null)
|
||||
IO.Write("uid." + SO[i] + ".size=" , _UID[SO[i]].Size );
|
||||
if (_UID[SO[i]].Value != null)
|
||||
if (_UID[SO[i]].Value != "")
|
||||
IO.Write("uid." + SO[i] + ".value=" , _UID[SO[i]].Value );
|
||||
}
|
||||
IO.Write("uid.length=", _UID.Length);
|
||||
MsgPack uid = new MsgPack(UIDs.Length, "UID");
|
||||
for (int i = 0; i < UIDs.Length; i++)
|
||||
uid[i] = MsgPack.New.Add("Category", UIDs[i].Category)
|
||||
.Add("OrgUid" , UIDs[i].OrgUid )
|
||||
.Add("Size" , UIDs[i].Size )
|
||||
.Add("Value" , UIDs[i].Value );
|
||||
authDB.Add(uid);
|
||||
}
|
||||
|
||||
IO.Close();
|
||||
authDB.Write(false, true, file, json);
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
|
||||
if (MsgPack.Element("AuthDB", out MsgPack AuthDB))
|
||||
{
|
||||
if (AuthDB.Element("Category", out MsgPack Temp, typeof(object[])))
|
||||
{
|
||||
this.Category = new string[((object[])Temp.Object).Length];
|
||||
MsgPack Category;
|
||||
for (int i = 0; i < this.Category.Length; i++)
|
||||
if (Temp[i].GetType() == typeof(MsgPack))
|
||||
{ Category = (MsgPack)Temp[i]; this.Category[i] = Category.ReadString(); }
|
||||
}
|
||||
|
||||
if (AuthDB.Element("UID", out Temp, typeof(object[])))
|
||||
{
|
||||
_UID = new UID[((object[])Temp.Object).Length];
|
||||
MsgPack UID;
|
||||
for (int i = 0; i < _UID.Length; i++)
|
||||
if (Temp[i].GetType() == typeof(MsgPack))
|
||||
{
|
||||
UID = (MsgPack)Temp[i];
|
||||
_UID[i].Category = UID.ReadString("C");
|
||||
_UID[i].OrgUid = UID.ReadNInt32("O");
|
||||
_UID[i].Size = UID.ReadNInt32("S");
|
||||
_UID[i].Value = UID.ReadString("V");
|
||||
}
|
||||
}
|
||||
}
|
||||
MsgPack = null;
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
{
|
||||
MsgPack AuthDB = new MsgPack("AuthDB");
|
||||
if (Category != null)
|
||||
{
|
||||
MsgPack Category = new MsgPack("Category", this.Category.Length);
|
||||
for (int i = 0; i < this.Category.Length; i++)
|
||||
Category[i] = this.Category[i];
|
||||
AuthDB.Add(Category);
|
||||
}
|
||||
|
||||
if (_UID != null)
|
||||
{
|
||||
MsgPack UID = new MsgPack("UID", _UID.Length);
|
||||
for (int i = 0; i < _UID.Length; i++)
|
||||
UID[i] = new MsgPack()
|
||||
.Add("C", _UID[i].Category)
|
||||
.Add("O", _UID[i].OrgUid )
|
||||
.Add("S", _UID[i].Size )
|
||||
.Add("V", _UID[i].Value );
|
||||
AuthDB.Add(UID);
|
||||
}
|
||||
|
||||
AuthDB.Write(true, file, JSON);
|
||||
}
|
||||
private bool disposed = false;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; Category = null; UIDs = null; disposed = true; } }
|
||||
|
||||
public struct UID
|
||||
{
|
||||
|
||||
@@ -1,248 +0,0 @@
|
||||
// Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary
|
||||
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.Types;
|
||||
using KKdMainLib.MessagePack;
|
||||
using MPIO = KKdMainLib.MessagePack.IO;
|
||||
|
||||
namespace KKdMainLib.DB
|
||||
{
|
||||
public class BoneData
|
||||
{
|
||||
public Stream IO;
|
||||
public BONE Data;
|
||||
|
||||
private int i, i0;
|
||||
|
||||
public BoneData()
|
||||
{ Data = new BONE(); }
|
||||
|
||||
public void BONReader(string file, string ext)
|
||||
{
|
||||
Data = new BONE { Header = new PDHead() };
|
||||
IO = File.OpenReader(file + ext);
|
||||
|
||||
IO.Format = Main.Format.F;
|
||||
Data.Header.Signature = IO.ReadInt32();
|
||||
if (Data.Header.Signature == 0x454E4F42)
|
||||
{
|
||||
Data.Header = IO.ReadHeader(true);
|
||||
Data.POF = Data.Header.AddPOF();
|
||||
}
|
||||
if (Data.Header.Signature != 0x09102720)
|
||||
return;
|
||||
|
||||
Data.Skeleton = new SkeletonEntry[IO.ReadInt32Endian()];
|
||||
Data.SkeletonsOffset = IO.ReadUInt32Endian(ref Data.POF);
|
||||
Data.SkeletonNamesOffset = IO.ReadUInt32Endian();
|
||||
if (Data.SkeletonNamesOffset == 0)
|
||||
{
|
||||
IO.IsX = true;
|
||||
IO.Format = Main.Format.X;
|
||||
Data.POF.POFOffsets = new List<long>();
|
||||
IO.Seek(Data.Header.Lenght, 0);
|
||||
IO.LongOffset = Data.Header.Lenght;
|
||||
Data.Header.Signature = IO.ReadInt32();
|
||||
Data.Skeleton = new SkeletonEntry[IO.ReadInt32Endian()];
|
||||
Data.SkeletonsOffset = IO.ReadInt64();
|
||||
Data.SkeletonNamesOffset = IO.ReadInt64(ref Data.POF);
|
||||
}
|
||||
else
|
||||
{
|
||||
IO.LongPosition -= 4;
|
||||
IO.GetOffset(ref Data.POF);
|
||||
IO.LongPosition += 4;
|
||||
}
|
||||
|
||||
Data.SkeletonEntryOffset = new long[Data.Skeleton.Length];
|
||||
IO.LongPosition = Data.SkeletonsOffset;
|
||||
for (i0 = 0; i0 < Data.Skeleton.Length; i0++)
|
||||
Data.SkeletonEntryOffset[i0] = IO.ReadIntX(ref Data.POF);
|
||||
|
||||
for (i0 = 0; i0 < Data.Skeleton.Length; i0++)
|
||||
{
|
||||
Data.Skeleton[i0] = new SkeletonEntry();
|
||||
IO.LongPosition = Data.SkeletonEntryOffset[i0];
|
||||
|
||||
Data.Skeleton[i0].BoneOffset = IO.ReadIntX(ref Data.POF);
|
||||
Data.Skeleton[i0].Position = new Vector3<float>[IO.ReadIntX()];
|
||||
Data.Skeleton[i0].PositionOffset = IO.ReadIntX(ref Data.POF);
|
||||
Data.Skeleton[i0].Field02Offset = IO.ReadIntX(ref Data.POF);
|
||||
Data.Skeleton[i0].BoneName1 = new string[IO.ReadIntX()];
|
||||
Data.Skeleton[i0].BoneName1Offset = IO.ReadIntX(ref Data.POF);
|
||||
Data.Skeleton[i0].BoneName2 = new string[IO.ReadIntX()];
|
||||
Data.Skeleton[i0].BoneName2Offset = IO.ReadIntX(ref Data.POF);
|
||||
Data.Skeleton[i0].ParentIndiceOffset = IO.ReadIntX(ref Data.POF);
|
||||
|
||||
IO.LongPosition = Data.SkeletonNamesOffset + i0 << (IO.IsX ? 3 : 2);
|
||||
|
||||
Data.Skeleton[i0].Name = IO.ReadStringAtOffset(ref Data.POF);
|
||||
IO.LongPosition = Data.Skeleton[i0].BoneOffset;
|
||||
|
||||
long Count = 0;
|
||||
string Name = "";
|
||||
while (true)
|
||||
{
|
||||
IO.ReadUInt64();
|
||||
Name = IO.ReadStringAtOffset(ref Data.POF);
|
||||
if (Name == "End") break;
|
||||
Count++;
|
||||
}
|
||||
|
||||
Data.Skeleton[i0].Bone = new BoneEntry[Count];
|
||||
for (i = 0; i < Count; i++)
|
||||
{
|
||||
Data.Skeleton[i0].Bone[i].Type = (BoneType)IO.ReadByte ();
|
||||
Data.Skeleton[i0].Bone[i].HasParent = IO.ReadBoolean();
|
||||
Data.Skeleton[i0].Bone[i].ParentNameIndex = IO.ReadByte ();
|
||||
Data.Skeleton[i0].Bone[i].Field01 = IO.ReadByte ();
|
||||
Data.Skeleton[i0].Bone[i].PairNameIndex = IO.ReadByte ();
|
||||
Data.Skeleton[i0].Bone[i].Field02 = IO.ReadByte ();
|
||||
IO.ReadInt16Endian();
|
||||
Data.Skeleton[i0].Bone[i].Name = IO.ReadStringAtOffset(ref Data.POF);
|
||||
}
|
||||
|
||||
IO.LongPosition = Data.Skeleton[i0].PositionOffset;
|
||||
for (i = 0; i < Data.Skeleton[i0].Position.Length; i++)
|
||||
Data.Skeleton[i0].Position[i] = new Vector3<float>(IO.ReadSingleEndian(),
|
||||
IO.ReadSingleEndian(), IO.ReadSingleEndian());
|
||||
|
||||
IO.LongPosition = Data.Skeleton[i0].Field02Offset;
|
||||
Data.Skeleton[i0].Field02 = IO.ReadIntX();
|
||||
|
||||
IO.LongPosition = Data.Skeleton[i0].BoneName1Offset;
|
||||
for (i = 0; i < Data.Skeleton[i0].BoneName1.Length; i++)
|
||||
Data.Skeleton[i0].BoneName1[i] = IO.ReadStringAtOffset(ref Data.POF);
|
||||
|
||||
IO.LongPosition = Data.Skeleton[i0].BoneName2Offset;
|
||||
for (i = 0; i < Data.Skeleton[i0].BoneName2.Length; i++)
|
||||
Data.Skeleton[i0].BoneName2[i] = IO.ReadStringAtOffset(ref Data.POF);
|
||||
|
||||
IO.LongPosition = Data.Skeleton[i0].ParentIndiceOffset;
|
||||
for (i = 0; i < Data.Skeleton[i0].BoneName2.Length; i++)
|
||||
Data.Skeleton[i0].ParentIndice[i] = IO.ReadInt16Endian();
|
||||
}
|
||||
if (IO.Format > Main.Format.F)
|
||||
{
|
||||
IO.LongPosition = Data.POF.Offset;
|
||||
IO.ReadPOF(ref Data.POF);
|
||||
}
|
||||
IO.Close();
|
||||
}
|
||||
|
||||
public void BONWriter(string file, Main.Format Format)
|
||||
{
|
||||
IO = File.OpenWriter(file + ".bon", true);
|
||||
IO.Close();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
|
||||
MsgPack = null;
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
{
|
||||
MsgPack BoneDB = new MsgPack("BoneDB", Data.Skeleton.Length);
|
||||
for (i0 = 0; i0 < Data.Skeleton.Length; i0++)
|
||||
{
|
||||
MsgPack Skeleton = new MsgPack().Add("Name" , Data.Skeleton[i0].Name )
|
||||
.Add("Field02", Data.Skeleton[i0].Field02);
|
||||
|
||||
MsgPack Bone = new MsgPack("Bone", Data.Skeleton[i0].Bone.Length);
|
||||
for (i = 0; i < Data.Skeleton[i0].Bone.Length; i++)
|
||||
Bone[i] = new MsgPack().Add("Type" , (byte) Data.Skeleton[i0].Bone[i].Type )
|
||||
.Add("HasParent" , Data.Skeleton[i0].Bone[i].HasParent )
|
||||
.Add("ParentNameIndex", Data.Skeleton[i0].Bone[i].ParentNameIndex)
|
||||
.Add("Field01" , Data.Skeleton[i0].Bone[i].Field01 )
|
||||
.Add("PairNameIndex" , Data.Skeleton[i0].Bone[i].PairNameIndex )
|
||||
.Add("Field02" , Data.Skeleton[i0].Bone[i].Field02 )
|
||||
.Add("Name" , Data.Skeleton[i0].Bone[i].Name );
|
||||
Skeleton.Add(Bone);
|
||||
|
||||
MsgPack Position = new MsgPack("Position", Data.Skeleton[i0].Position.Length);
|
||||
for (i = 0; i < Data.Skeleton[i0].Position.Length; i++)
|
||||
Position[i] = new MsgPack().Add("X", Data.Skeleton[i0].Position[i].X)
|
||||
.Add("Y", Data.Skeleton[i0].Position[i].Y)
|
||||
.Add("Z", Data.Skeleton[i0].Position[i].Z);
|
||||
Skeleton.Add(Position);
|
||||
|
||||
MsgPack BoneName1 = new MsgPack("BoneName1", Data.Skeleton[i0].BoneName1.Length);
|
||||
for (i = 0; i < Data.Skeleton[i0].BoneName1.Length; i++)
|
||||
BoneName1[i] = Data.Skeleton[i0].BoneName1[i];
|
||||
Skeleton.Add(BoneName1);
|
||||
|
||||
MsgPack BoneName2 = new MsgPack("BoneName2", Data.Skeleton[i0].BoneName2.Length);
|
||||
for (i = 0; i < Data.Skeleton[i0].BoneName2.Length; i++)
|
||||
BoneName2[i] = Data.Skeleton[i0].BoneName2[i];
|
||||
Skeleton.Add(BoneName2);
|
||||
|
||||
MsgPack ParentIndice = new MsgPack("ParentIndice", Data.Skeleton[i0].ParentIndice.Length);
|
||||
for (i = 0; i < Data.Skeleton[i0].ParentIndice.Length; i++)
|
||||
ParentIndice[i] = Data.Skeleton[i0].ParentIndice[i];
|
||||
BoneDB[i0] = Skeleton.Add(ParentIndice);
|
||||
}
|
||||
|
||||
BoneDB.Write(true, file, JSON);
|
||||
}
|
||||
|
||||
/*public struct Bone
|
||||
{
|
||||
public List<string> Names;
|
||||
public List<long> Offsets;
|
||||
}*/
|
||||
|
||||
public struct BONE
|
||||
{
|
||||
public long SkeletonsOffset;
|
||||
public long SkeletonNamesOffset;
|
||||
public POF POF;
|
||||
public PDHead Header;
|
||||
public long[] SkeletonEntryOffset;
|
||||
public SkeletonEntry[] Skeleton;
|
||||
}
|
||||
|
||||
public struct BoneEntry
|
||||
{
|
||||
public bool HasParent;
|
||||
public byte Field01;
|
||||
public byte Field02;
|
||||
public byte PairNameIndex;
|
||||
public byte ParentNameIndex;
|
||||
public string Name;
|
||||
public BoneType Type;
|
||||
}
|
||||
|
||||
public enum BoneType : byte
|
||||
{
|
||||
Rotation = 0,
|
||||
Type1 = 1,
|
||||
Position = 2,
|
||||
Type3 = 3,
|
||||
Type4 = 4,
|
||||
Type5 = 5,
|
||||
Type6 = 6,
|
||||
};
|
||||
|
||||
public struct SkeletonEntry
|
||||
{
|
||||
public long BoneOffset;
|
||||
public long Field02Offset;
|
||||
public long PositionOffset;
|
||||
public long BoneName1Offset;
|
||||
public long BoneName2Offset;
|
||||
public long ParentIndiceOffset;
|
||||
|
||||
public long Field02;
|
||||
public string Name;
|
||||
public short[] ParentIndice;
|
||||
public string[] BoneName1;
|
||||
public string[] BoneName2;
|
||||
public BoneEntry[] Bone;
|
||||
public Vector3<float>[] Position;
|
||||
}
|
||||
}
|
||||
}
|
||||
+154
-171
@@ -1,100 +1,78 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
using MPIO = KKdMainLib.MessagePack.IO;
|
||||
|
||||
namespace KKdMainLib.DB
|
||||
{
|
||||
public class Spr
|
||||
public class Spr : System.IDisposable
|
||||
{
|
||||
public SpriteSet[] SpriteSets;
|
||||
|
||||
private Stream IO;
|
||||
private int i, i0, i1, i2;
|
||||
private Stream s;
|
||||
|
||||
public SpriteSet[] SpriteSets;
|
||||
|
||||
public void BINReader(string file)
|
||||
{
|
||||
/*Stream IO0 = File.OpenReader(file + "0.bin");
|
||||
Stream IO1 = File.OpenReader(file + "1.bin");
|
||||
s = File.OpenReader(file + ".bin");
|
||||
|
||||
List<int> _0 = new List<int>();
|
||||
List<int> _1 = new List<int>();
|
||||
IO0.Position = 0x20;
|
||||
for (i = 0; i < 124; i++)
|
||||
{ _0.Add(IO0.ReadInt32()); IO0.LongPosition += 8; }
|
||||
IO1.Position = 0x20;
|
||||
for (i = 0; i < 124; i++)
|
||||
{ _1.Add(IO1.ReadInt32()); IO1.LongPosition += 8; }
|
||||
IO0.Close();
|
||||
IO1.Close();
|
||||
int spriteSetsLength = s.RI32();
|
||||
int spriteSetsOffset = s.RI32();
|
||||
int spritesLength = s.RI32();
|
||||
int spritesOffset = s.RI32();
|
||||
|
||||
IO = File.OpenWriter(@"F:\Source\MikuMikuModel\DatabaseConverter\msgpack-json-tools\aet_gam_pv643.bin");
|
||||
IO.Position = 0x10;
|
||||
for (i = 0; i < 108; i++)
|
||||
{ IO.ReadInt32(); i1 = _1[_0.IndexOf(IO.ReadInt32())]; IO.Position -= 4; IO.Write(i1); }
|
||||
IO.Close();*/
|
||||
|
||||
IO = File.OpenReader(file + ".bin");
|
||||
|
||||
int spriteSetsLength = IO.ReadInt32();
|
||||
int spriteSetsOffset = IO.ReadInt32();
|
||||
int spritesLength = IO.ReadInt32();
|
||||
int spritesOffset = IO.ReadInt32();
|
||||
|
||||
IO.Position = spriteSetsOffset;
|
||||
s.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 = s.RI32();
|
||||
SpriteSets[i].Name = s.RSaO();
|
||||
SpriteSets[i].FileName = s.RSaO();
|
||||
s.RI32();
|
||||
}
|
||||
|
||||
int setIndex;
|
||||
bool IsTexture;
|
||||
bool isTexture;
|
||||
SpriteTexture st = new SpriteTexture();
|
||||
int[] SprCount = new int[spriteSetsLength];
|
||||
int[] TexCount = new int[spriteSetsLength];
|
||||
int[] sprCount = new int[spriteSetsLength];
|
||||
int[] texCount = new int[spriteSetsLength];
|
||||
|
||||
IO.Position = spritesOffset;
|
||||
s.P = spritesOffset;
|
||||
for (i = 0; i < spritesLength; i++)
|
||||
{
|
||||
IO.LongPosition += 10;
|
||||
setIndex = IO.ReadInt16();
|
||||
IsTexture = (setIndex & 0x1000) == 0x1000;
|
||||
s.PI64 += 10;
|
||||
setIndex = s.RI16();
|
||||
isTexture = (setIndex & 0x1000) == 0x1000;
|
||||
setIndex &= 0xFFF;
|
||||
|
||||
if (IsTexture) TexCount[setIndex]++;
|
||||
else SprCount[setIndex]++;
|
||||
if (isTexture) texCount[setIndex]++;
|
||||
else sprCount[setIndex]++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < spriteSetsLength; i++)
|
||||
{
|
||||
SpriteSets[i].Sprites = new SpriteTexture[SprCount[i]];
|
||||
SpriteSets[i].Textures = new SpriteTexture[TexCount[i]];
|
||||
SpriteSets[i].Sprites = new SpriteTexture[sprCount[i]];
|
||||
SpriteSets[i].Textures = new SpriteTexture[texCount[i]];
|
||||
|
||||
SprCount[i] = 0;
|
||||
TexCount[i] = 0;
|
||||
sprCount[i] = 0;
|
||||
texCount[i] = 0;
|
||||
}
|
||||
|
||||
IO.Position = spritesOffset;
|
||||
s.P = spritesOffset;
|
||||
for (i = 0; i < spritesLength; i++)
|
||||
{
|
||||
st.Id = IO.ReadInt32();
|
||||
st.Name = IO.ReadStringAtOffset();
|
||||
IO.ReadInt16();
|
||||
setIndex = IO.ReadInt16();
|
||||
IsTexture = (setIndex & 0x1000) == 0x1000;
|
||||
st.Id = s.RI32();
|
||||
st.Name = s.RSaO();
|
||||
s.RI16();
|
||||
setIndex = s.RI16();
|
||||
isTexture = (setIndex & 0x1000) == 0x1000;
|
||||
setIndex &= 0xFFF;
|
||||
|
||||
if (IsTexture) { SpriteSets[setIndex].Textures[TexCount[setIndex]] = st; TexCount[setIndex]++; }
|
||||
else { SpriteSets[setIndex]. Sprites[SprCount[setIndex]] = st; SprCount[setIndex]++; }
|
||||
|
||||
if (isTexture) { SpriteSets[setIndex].Textures[texCount[setIndex]] = st; texCount[setIndex]++; }
|
||||
else { SpriteSets[setIndex]. Sprites[sprCount[setIndex]] = st; sprCount[setIndex]++; }
|
||||
}
|
||||
|
||||
IO.Close();
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void BINWriter(string file)
|
||||
@@ -102,13 +80,13 @@ namespace KKdMainLib.DB
|
||||
if (SpriteSets == null) return;
|
||||
if (SpriteSets.Length == 0) return;
|
||||
|
||||
List<string> SetName = new List<string>();
|
||||
List<string> SetFileName = new List<string>();
|
||||
KKdList<string> setName = KKdList<string>.New;
|
||||
KKdList<string> setFileName = KKdList<string>.New;
|
||||
|
||||
List<int> Ids = new List<int>();
|
||||
List<int> SetIds = new List<int>();
|
||||
KKdList<int> ids = KKdList<int>.New;
|
||||
KKdList<int> setIds = KKdList<int>.New;
|
||||
|
||||
List<int> NotAdd = new List<int>();
|
||||
KKdList<int> notAdd = KKdList<int>.New;
|
||||
SpriteTexture temp;
|
||||
SpriteSet set;
|
||||
|
||||
@@ -116,11 +94,11 @@ namespace KKdMainLib.DB
|
||||
{
|
||||
set = SpriteSets[i];
|
||||
if (set. Name != null)
|
||||
if (SetName .Contains(set. Name)) { NotAdd.Add(i); continue; }
|
||||
else SetName .Add (set. Name);
|
||||
if (setName .Contains(set. Name)) { notAdd.Add(i); continue; }
|
||||
else setName .Add (set. Name);
|
||||
if (set.FileName != null)
|
||||
if (SetFileName.Contains(set.FileName)) { NotAdd.Add(i); continue; }
|
||||
else SetFileName.Add (set.FileName);
|
||||
if (setFileName.Contains(set.FileName)) { notAdd.Add(i); continue; }
|
||||
else setFileName.Add (set.FileName);
|
||||
|
||||
if (set.NewId)
|
||||
{
|
||||
@@ -131,146 +109,152 @@ namespace KKdMainLib.DB
|
||||
}
|
||||
|
||||
if (set.Id != null)
|
||||
if (SetIds.Contains((int)set.Id)) { NotAdd.Add(i); continue; }
|
||||
else SetIds.Add ((int)set.Id);
|
||||
if (setIds.Contains((int)set.Id)) { notAdd.Add(i); continue; }
|
||||
else setIds.Add ((int)set.Id);
|
||||
|
||||
for (i0 = 0; i0 < set. Sprites.Length; i0++)
|
||||
{
|
||||
temp = set. Sprites[i0];
|
||||
if (temp.Id != null)
|
||||
if ( Ids.Contains((int)temp.Id)) { NotAdd.Add(i); break; }
|
||||
else Ids.Add ((int)temp.Id);
|
||||
if ( ids.Contains((int)temp.Id)) { notAdd.Add(i); break; }
|
||||
else ids.Add ((int)temp.Id);
|
||||
}
|
||||
if (i0 + 1 != set.Sprites.Length) continue;
|
||||
if (i0 < set.Sprites.Length) continue;
|
||||
|
||||
for (i0 = 0; i0 < set.Textures.Length; i0++)
|
||||
{
|
||||
temp = set.Textures[i0];
|
||||
if (temp.Id != null)
|
||||
if ( Ids.Contains((int)temp.Id)) { NotAdd.Add(i); break; }
|
||||
else Ids.Add ((int)temp.Id);
|
||||
if ( ids.Contains((int)temp.Id)) { notAdd.Add(i); break; }
|
||||
else ids.Add ((int)temp.Id);
|
||||
}
|
||||
}
|
||||
SetName = null;
|
||||
SetFileName = null;
|
||||
setName .Dispose();
|
||||
setFileName.Dispose();
|
||||
|
||||
for (i = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
set = SpriteSets[i];
|
||||
if (NotAdd.Contains(i)) continue;
|
||||
if (notAdd.Contains(i)) continue;
|
||||
if (!set.NewId) continue;
|
||||
|
||||
i1 = 0;
|
||||
if (set.Id == null) while (true)
|
||||
{ if (!SetIds.Contains(i1)) { SpriteSets[i].Id = i1; SetIds.Add(i1); break; } i1++; }
|
||||
|
||||
for (i0 = 0, i1 = 0; i0 < set. Sprites.Length; i0++)
|
||||
if (set. Sprites[i0].Id == null) while (true) { if (!Ids.Contains(i1))
|
||||
{ SpriteSets[i]. Sprites[i0].Id = i1; Ids.Add(i1); break; } i1++; }
|
||||
{ if (!setIds.Contains(i1)) { SpriteSets[i].Id = i1; setIds.Add(i1); break; } i1++; }
|
||||
|
||||
for (i0 = 0, i1 = 0; i0 < set.Textures.Length; i0++)
|
||||
if (set.Textures[i0].Id == null) while (true) { if (!Ids.Contains(i1))
|
||||
{ SpriteSets[i].Textures[i0].Id = i1; Ids.Add(i1); break; } i1++; }
|
||||
while (set.Textures[i0].Id == null)
|
||||
if (!ids.Contains(i1)) ids.Add((int)(SpriteSets[i].Textures[i0].Id = i1)); else i1++;
|
||||
|
||||
for (i0 = 0, i1 = 0; i0 < set. Sprites.Length; i0++)
|
||||
while (set. Sprites[i0].Id == null)
|
||||
if (!ids.Contains(i1)) ids.Add((int)(SpriteSets[i]. Sprites[i0].Id = i1)); else i1++;
|
||||
}
|
||||
|
||||
Ids = null;
|
||||
SetIds = null;
|
||||
|
||||
|
||||
ids.Dispose();
|
||||
setIds.Dispose();
|
||||
|
||||
for (i = 0, i0 = 0, i2 = 0; i < SpriteSets.Length; i++)
|
||||
if (!NotAdd.Contains(i)) { i0 += SpriteSets[i].Sprites.Length + SpriteSets[i].Textures.Length; i2++; }
|
||||
|
||||
if (!notAdd.Contains(i)) { i0 += SpriteSets[i].Sprites.Length + SpriteSets[i].Textures.Length; i2++; }
|
||||
|
||||
i1 = i0 * 12;
|
||||
i1 = i1.Align(0x20) + 0x20;
|
||||
i1 = i1.A(0x20) + 0x20;
|
||||
|
||||
IO = File.OpenWriter(file + ".bin", true);
|
||||
IO.Write(i2);
|
||||
IO.Write(i1);
|
||||
IO.Write(i0);
|
||||
IO.Write(0x20);
|
||||
IO.Write(0x9066906690669066);
|
||||
IO.Write(0x9066906690669066);
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
s.W(i2);
|
||||
s.W(i1);
|
||||
s.W(i0);
|
||||
s.W(0x20);
|
||||
s.W(0x9066906690669066);
|
||||
s.W(0x9066906690669066);
|
||||
|
||||
IO.Position = (i1 + i2 * 0x10).Align(0x20);
|
||||
s.P = (i1 + i2 * 0x10).A(0x20);
|
||||
for (i = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) continue;
|
||||
SpriteSets[i]. NameOffset = IO.Position; IO.Write(SpriteSets[i]. Name + "\0");
|
||||
SpriteSets[i].FileNameOffset = IO.Position; IO.Write(SpriteSets[i].FileName + "\0");
|
||||
if (notAdd.Contains(i)) continue;
|
||||
for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++)
|
||||
{ SpriteSets[i].Textures[i0].NameOffset = s.P;
|
||||
s.W(SpriteSets[i].Textures[i0].Name + "\0"); }
|
||||
|
||||
for (i0 = 0; i0 < SpriteSets[i]. Sprites.Length; i0++)
|
||||
{ SpriteSets[i]. Sprites[i0].NameOffset = s.P;
|
||||
s.W(SpriteSets[i]. Sprites[i0].Name + "\0"); }
|
||||
}
|
||||
|
||||
for (i = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) continue;
|
||||
for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++)
|
||||
{ SpriteSets[i].Textures[i0].NameOffset = IO.Position; IO.Write(SpriteSets[i].Textures[i0].Name + "\0"); }
|
||||
|
||||
for (i0 = 0; i0 < SpriteSets[i]. Sprites.Length; i0++)
|
||||
{ SpriteSets[i]. Sprites[i0].NameOffset = IO.Position; IO.Write(SpriteSets[i]. Sprites[i0].Name + "\0"); }
|
||||
if (notAdd.Contains(i)) continue;
|
||||
SpriteSets[i]. NameOffset = s.P; s.W(SpriteSets[i]. Name + "\0");
|
||||
SpriteSets[i].FileNameOffset = s.P; s.W(SpriteSets[i].FileName + "\0");
|
||||
}
|
||||
|
||||
IO.Align(0x08, true);
|
||||
IO.Position = 0x20;
|
||||
s.A(0x08, true);
|
||||
|
||||
s.P = 0x20;
|
||||
for (i = 0, i2 = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) { i2++; continue; }
|
||||
|
||||
if (notAdd.Contains(i)) { i2++; continue; }
|
||||
|
||||
for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++)
|
||||
{
|
||||
IO.Write(SpriteSets[i].Textures[i0].Id );
|
||||
IO.Write(SpriteSets[i].Textures[i0].NameOffset);
|
||||
IO.Write((ushort) i0 );
|
||||
IO.Write((ushort)(0x1000 | (i - i2)));
|
||||
s.W(SpriteSets[i].Textures[i0].Id );
|
||||
s.W(SpriteSets[i].Textures[i0].NameOffset);
|
||||
s.W((ushort) i0 );
|
||||
s.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));
|
||||
s.W(SpriteSets[i]. Sprites[i0].Id );
|
||||
s.W(SpriteSets[i]. Sprites[i0].NameOffset);
|
||||
s.W((ushort) i0 );
|
||||
s.W((ushort)(i - i2));
|
||||
}
|
||||
}
|
||||
IO.Align(0x20);
|
||||
s.A(0x20);
|
||||
|
||||
for (i = 0, i2 = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) { i2++; continue; }
|
||||
if (notAdd.Contains(i)) { i2++; continue; }
|
||||
|
||||
IO.Write(SpriteSets[i].Id );
|
||||
IO.Write(SpriteSets[i]. NameOffset);
|
||||
IO.Write(SpriteSets[i].FileNameOffset);
|
||||
IO.Write(i - i2);
|
||||
s.W(SpriteSets[i].Id );
|
||||
s.W(SpriteSets[i]. NameOffset);
|
||||
s.W(SpriteSets[i].FileNameOffset);
|
||||
s.W(i - i2);
|
||||
}
|
||||
|
||||
IO.Close();
|
||||
notAdd.Dispose();
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool JSON = false)
|
||||
public void MsgPackReader(string file, bool json = false)
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
MsgPack msgPack = file.ReadMPAllAtOnce(json);
|
||||
|
||||
if (MsgPack.Element("SprDB", out MsgPack SprDB, typeof(object[])))
|
||||
MsgPack sprDB;
|
||||
if ((sprDB = msgPack["SprDB", true]).NotNull)
|
||||
{
|
||||
SpriteSets = new SpriteSet[((object[])SprDB.Object).Length];
|
||||
SpriteSets = new SpriteSet[sprDB.Array.Length];
|
||||
for (int i = 0; i < SpriteSets.Length; i++)
|
||||
if (SprDB[i].GetType() == typeof(MsgPack))
|
||||
SpriteSets[i].ReadMsgPack((MsgPack)SprDB[i]);
|
||||
SpriteSets[i].ReadMsgPack(sprDB[i]);
|
||||
}
|
||||
MsgPack = null;
|
||||
sprDB.Dispose();
|
||||
msgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
if (SpriteSets == null) return;
|
||||
if (SpriteSets.Length == 0) return;
|
||||
|
||||
MsgPack SprDB = new MsgPack("SprDB", SpriteSets.Length);
|
||||
for (i = 0; i < SpriteSets.Length; i++) SprDB[i] = SpriteSets[i].WriteMsgPack();
|
||||
MsgPack sprDB = new MsgPack(SpriteSets.Length, "SprDB");
|
||||
for (i = 0; i < SpriteSets.Length; i++)
|
||||
sprDB[i] = SpriteSets[i].WriteMsgPack();
|
||||
|
||||
SprDB.Write(true, file, JSON);
|
||||
sprDB.Write(false, true, file, json);
|
||||
}
|
||||
|
||||
private bool disposed = false;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; SpriteSets = null; disposed = true; } }
|
||||
|
||||
public struct SpriteTexture
|
||||
{
|
||||
public int NameOffset;
|
||||
@@ -278,10 +262,10 @@ namespace KKdMainLib.DB
|
||||
public string Name;
|
||||
|
||||
public void ReadMsgPack(MsgPack msg)
|
||||
{ Id = msg.ReadNInt32("Id"); Name = msg.ReadString("Name"); }
|
||||
{ Id = msg.RnI32("Id"); Name = msg.RS("Name"); }
|
||||
|
||||
public MsgPack WriteMsgPack() =>
|
||||
new MsgPack().Add("Id", Id).Add("Name", Name);
|
||||
MsgPack.New.Add("Id", Id).Add("Name", Name);
|
||||
}
|
||||
|
||||
public struct SpriteSet
|
||||
@@ -294,44 +278,43 @@ namespace KKdMainLib.DB
|
||||
public string FileName;
|
||||
public SpriteTexture[] Sprites;
|
||||
public SpriteTexture[] Textures;
|
||||
|
||||
|
||||
public void ReadMsgPack(MsgPack msg)
|
||||
{
|
||||
FileName = msg.ReadString ("FileName");
|
||||
Id = msg.ReadNInt32 ( "Id" );
|
||||
Name = msg.ReadString ("Name" );
|
||||
NewId = msg.ReadBoolean("NewId" );
|
||||
FileName = msg.RS ("FileName");
|
||||
Id = msg.RnI32( "Id" );
|
||||
Name = msg.RS ("Name" );
|
||||
NewId = msg.RB ("NewId" );
|
||||
|
||||
if (msg.Element( "Sprites", out MsgPack Sprites, typeof(object[])))
|
||||
MsgPack temp;
|
||||
if ((temp = msg["Sprites", true]).NotNull)
|
||||
{
|
||||
object Sprite;
|
||||
this .Sprites = new SpriteTexture[((object[])Sprites.Object).Length];
|
||||
for (int i0 = 0; i0 < this.Sprites.Length; i0++)
|
||||
{ Sprite = Sprites[i0]; if (Sprites.GetType() == typeof(MsgPack))
|
||||
this.Sprites[i0].ReadMsgPack((MsgPack)Sprite); }
|
||||
Sprites = new SpriteTexture[temp.Array.Length];
|
||||
for (int i0 = 0; i0 < Sprites.Length; i0++)
|
||||
Sprites[i0].ReadMsgPack(temp[i0]);
|
||||
}
|
||||
|
||||
if (msg.Element("Textures", out MsgPack Textures, typeof(object[])))
|
||||
if ((temp = msg["Textures", true]).NotNull)
|
||||
{
|
||||
object Texture;
|
||||
this .Textures = new SpriteTexture[((object[])Textures.Object).Length];
|
||||
for (int i0 = 0; i0 < this.Textures.Length; i0++)
|
||||
{ Texture = Textures[i0]; if (Texture.GetType() == typeof(MsgPack))
|
||||
this.Textures[i0].ReadMsgPack((MsgPack)Texture); }
|
||||
Textures = new SpriteTexture[temp.Array.Length];
|
||||
for (int i0 = 0; i0 < Textures.Length; i0++)
|
||||
Textures[i0].ReadMsgPack(temp[i0]);
|
||||
}
|
||||
temp.Dispose();
|
||||
}
|
||||
|
||||
public MsgPack WriteMsgPack()
|
||||
{
|
||||
MsgPack Sprites = new MsgPack( "Sprites", this.Sprites.Length);
|
||||
for (int i0 = 0; i0 < this.Sprites.Length; i0++)
|
||||
Sprites[i0] = this.Sprites[i0].WriteMsgPack();
|
||||
MsgPack sprites = new MsgPack( Sprites.Length, "Sprites");
|
||||
for (int i0 = 0; i0 < Sprites.Length; i0++)
|
||||
sprites[i0] = Sprites[i0].WriteMsgPack();
|
||||
|
||||
MsgPack Textures = new MsgPack("Textures", this.Textures.Length);
|
||||
for (int i0 = 0; i0 < this.Textures.Length; i0++)
|
||||
Textures[i0] = this.Textures[i0].WriteMsgPack();
|
||||
MsgPack textures = new MsgPack(Textures.Length, "Textures");
|
||||
for (int i0 = 0; i0 < Textures.Length; i0++)
|
||||
textures[i0] = Textures[i0].WriteMsgPack();
|
||||
|
||||
return new MsgPack().Add("FileName", FileName).Add("Id", Id).Add("Name", Name).Add(Sprites).Add(Textures);
|
||||
return MsgPack.New.Add("FileName", FileName).Add("Id", Id)
|
||||
.Add("Name", Name).Add(sprites).Add(textures);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
//Original research by Samyuu
|
||||
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public static class DCC //Databank_Checksum_Calculator
|
||||
{
|
||||
private static readonly ushort[] ChecksumLookupTable = {
|
||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
|
||||
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
|
||||
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
|
||||
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
|
||||
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
|
||||
0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
|
||||
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
|
||||
0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
|
||||
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
|
||||
0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
|
||||
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
|
||||
0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
|
||||
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
|
||||
0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
|
||||
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
|
||||
0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
|
||||
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
|
||||
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
|
||||
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
|
||||
0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
|
||||
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
|
||||
0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
||||
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
|
||||
0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
|
||||
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
|
||||
0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
|
||||
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
|
||||
0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
|
||||
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
|
||||
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
|
||||
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
|
||||
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0,
|
||||
};
|
||||
|
||||
public static ushort CalculateChecksum(string file) => CalculateChecksum(File.ReadAllBytes(file));
|
||||
|
||||
public static ushort CalculateChecksum(byte[] data)
|
||||
{
|
||||
ushort result = 0xFFFF;
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
result = (ushort)(ChecksumLookupTable[(result >> 8) ^ data[i]] ^ (result << 8));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
+186
-208
@@ -1,285 +1,263 @@
|
||||
using System.Collections.Generic;
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
using MPIO = KKdMainLib.MessagePack.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public class DEX
|
||||
public struct DEX : System.IDisposable
|
||||
{
|
||||
public DEX()
|
||||
{ Dex = null; Header = new PDHead(); }
|
||||
private int i, i0, i1;
|
||||
private Header header;
|
||||
private Stream s;
|
||||
|
||||
private int Offset = 0;
|
||||
private PDHead Header;
|
||||
|
||||
public Stream IO;
|
||||
public EXP[] Dex;
|
||||
|
||||
public int DEXReader(string filepath, string ext)
|
||||
public void DEXReader(string filepath, string ext)
|
||||
{
|
||||
Header = new PDHead();
|
||||
IO = File.OpenReader(filepath + ext);
|
||||
Dex = null;
|
||||
header = new Header();
|
||||
s = File.OpenReader(filepath + ext);
|
||||
|
||||
Header.Format = Main.Format.F;
|
||||
Header.Signature = IO.ReadInt32();
|
||||
if (Header.Signature == 0x43505845)
|
||||
Header = IO.ReadHeader(true);
|
||||
if (Header.Signature != 0x64)
|
||||
return 0;
|
||||
header.Format = Format.F;
|
||||
uint signature = s.RU32();
|
||||
if (signature == 0x43505845) { header = s.ReadHeader(true); signature = s.RU32(); }
|
||||
if (signature != 0x64) return;
|
||||
|
||||
Offset = IO.Position - 0x4;
|
||||
Dex = new EXP[IO.ReadInt32()];
|
||||
int DEXOffset = IO.ReadInt32();
|
||||
if (IO.ReadInt32() == 0x00) Header.Format = Main.Format.X;
|
||||
int DEXNameOffset = IO.ReadInt32();
|
||||
if (Header.IsX) IO.ReadInt32();
|
||||
s.O = s.P - 0x4;
|
||||
Dex = new EXP[s.RI32()];
|
||||
int DEXOffset = s.RI32();
|
||||
int DEXNameOffset = s.RI32();
|
||||
if (DEXNameOffset == 0x00) { s.Format = header.Format = Format.X; DEXNameOffset = (int)s.RIX(); }
|
||||
|
||||
IO.Seek(DEXOffset + Offset, 0);
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
Dex[i0] = new EXP { Main = new List<EXPElement>(), Eyes = new List<EXPElement>() };
|
||||
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
s.P = DEXOffset;
|
||||
for (i = 0; i < Dex.Length; i++)
|
||||
{
|
||||
Dex[i0].MainOffset = IO.ReadInt32();
|
||||
if (Header.IsX) IO.ReadInt32();
|
||||
Dex[i0].EyesOffset = IO.ReadInt32();
|
||||
if (Header.IsX) IO.ReadInt32();
|
||||
}
|
||||
IO.Seek(DEXNameOffset + Offset, 0);
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
Dex[i0].NameOffset = IO.ReadInt32();
|
||||
if (Header.IsX) IO.ReadInt32();
|
||||
Dex[i].FaceOffset = s.RIX();
|
||||
Dex[i].FaceCLOffset = s.RIX();
|
||||
}
|
||||
s.P = DEXNameOffset;
|
||||
for (i = 0; i < Dex.Length; i++)
|
||||
Dex[i].NameOffset = s.RIX();
|
||||
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
for (i = 0; i < Dex.Length; i++)
|
||||
{
|
||||
EXPElement element = new EXPElement();
|
||||
IO.Seek(Dex[i0].MainOffset + Offset, 0);
|
||||
EXPData element = new EXPData();
|
||||
Dex[i].Face = KKdList<EXPData>.New;
|
||||
s.PI64 = Dex[i].FaceOffset;
|
||||
while (true)
|
||||
{
|
||||
element.Frame = IO.ReadSingle();
|
||||
element.Both = IO.ReadUInt16();
|
||||
element.ID = IO.ReadUInt16();
|
||||
element.Value = IO.ReadSingle();
|
||||
element.Trans = IO.ReadSingle();
|
||||
Dex[i0].Main.Add(element);
|
||||
|
||||
if (element.Frame == 999999 || element.Both == 0xFFFF)
|
||||
break;
|
||||
element.Frame = s.RF32();
|
||||
element.Type = s.RU16();
|
||||
element.ID = s.RU16();
|
||||
element.Value = s.RF32();
|
||||
element.Trans = s.RF32();
|
||||
if (element.Type == 0xFFFF) break;
|
||||
Dex[i].Face.Add(element);
|
||||
}
|
||||
Dex[i].Face.Capacity = Dex[i].Face.Count;
|
||||
|
||||
IO.Seek(Dex[i0].EyesOffset + Offset, 0);
|
||||
Dex[i].FaceCL = KKdList<EXPData>.New;
|
||||
s.PI64 = Dex[i].FaceCLOffset;
|
||||
while(true)
|
||||
{
|
||||
element.Frame = IO.ReadSingle();
|
||||
element.Both = IO.ReadUInt16();
|
||||
element.ID = IO.ReadUInt16();
|
||||
element.Value = IO.ReadSingle();
|
||||
element.Trans = IO.ReadSingle();
|
||||
Dex[i0].Eyes.Add(element);
|
||||
|
||||
if (element.Frame == 999999 || element.Both == 0xFFFF)
|
||||
break;
|
||||
element.Frame = s.RF32();
|
||||
element.Type = s.RU16();
|
||||
element.ID = s.RU16();
|
||||
element.Value = s.RF32();
|
||||
element.Trans = s.RF32();
|
||||
if (element.Type == 0xFFFF) break;
|
||||
Dex[i].FaceCL.Add(element);
|
||||
}
|
||||
Dex[i].FaceCL.Capacity = Dex[i].FaceCL.Count;
|
||||
|
||||
IO.Seek(Dex[i0].NameOffset + Offset, 0);
|
||||
Dex[i0].Name = IO.NullTerminatedUTF8();
|
||||
Dex[i].Name = s.RSaO(Dex[i].NameOffset);
|
||||
}
|
||||
|
||||
IO.Close();
|
||||
return 1;
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void DEXWriter(string filepath, Main.Format Format)
|
||||
public void DEXWriter(string filepath, Format format)
|
||||
{
|
||||
Header = new PDHead() { Format = Format };
|
||||
IO = File.OpenWriter(filepath + (Header.Format > Main.Format.F ? ".Dex" : ".bin"), true);
|
||||
IO.Format = Header.Format;
|
||||
if (Dex == null || Dex.Length < 1) return;
|
||||
|
||||
if (IO.Format > Main.Format.F)
|
||||
header = new Header();
|
||||
s = File.OpenWriter(filepath + (format > Format.F && format < Format.FT ? ".dex" : ".bin"), true);
|
||||
header.Format = s.Format = format;
|
||||
|
||||
s.Format = format;
|
||||
s.O = format > Format.F ? 0x20 : 0;
|
||||
s.P = 0;
|
||||
s.W(0x64);
|
||||
s.W(Dex.Length);
|
||||
|
||||
s.WX(header.IsX ? 0x28 : 0x20);
|
||||
s.WX(0x00);
|
||||
|
||||
int Position0 = s.P;
|
||||
s.W(0x00L);
|
||||
s.W(0x00L);
|
||||
|
||||
for (i = 0; i < Dex.Length * 3; i++) s.WX(0x00);
|
||||
s.A(0x20);
|
||||
|
||||
for (i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
Header.Lenght = 0x20;
|
||||
Header.DataSize = 0x00;
|
||||
Header.Signature = 0x43505845;
|
||||
Header.SectionSize = 0x00;
|
||||
IO.Write(Header);
|
||||
}
|
||||
|
||||
IO.Write(0x64);
|
||||
IO.Write(Dex.Length);
|
||||
|
||||
if (Header.IsX) IO.Write((long)0x28);
|
||||
else IO.Write( 0x20);
|
||||
if (Header.IsX) IO.Write((long)0x00);
|
||||
else IO.Write( 0x00);
|
||||
|
||||
int Position0 = IO.Position;
|
||||
IO.Write((long)0x00);
|
||||
IO.Write((long)0x00);
|
||||
|
||||
for (int i = 0; i < Dex.Length * 3; i++)
|
||||
if (Header.IsX) IO.Write((long)0x00);
|
||||
else IO.Write( 0x00);
|
||||
|
||||
IO.Align(0x20, true);
|
||||
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
Dex[i0].MainOffset = IO.Position - Header.Lenght;
|
||||
for (int i1 = 0; i1 < Dex[i0].Main.Count; i1++)
|
||||
Dex[i0].FaceOffset = s.P;
|
||||
for (i1 = 0; i1 < Dex[i0].Face.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);
|
||||
s.W(Dex[i0].Face[i1].Frame);
|
||||
s.W(Dex[i0].Face[i1].Type );
|
||||
s.W(Dex[i0].Face[i1].ID );
|
||||
s.W(Dex[i0].Face[i1].Value);
|
||||
s.W(Dex[i0].Face[i1].Trans);
|
||||
}
|
||||
IO.Align(0x20, true);
|
||||
s.W(999999.0f);
|
||||
s.W(0xFFFF);
|
||||
s.W(0x0L);
|
||||
s.A(0x20);
|
||||
|
||||
Dex[i0].EyesOffset = IO.Position - Header.Lenght;
|
||||
for (int i1 = 0; i1 < Dex[i0].Eyes.Count; i1++)
|
||||
Dex[i0].FaceCLOffset = s.P;
|
||||
for (i1 = 0; i1 < Dex[i0].FaceCL.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);
|
||||
s.W(Dex[i0].FaceCL[i1].Frame);
|
||||
s.W(Dex[i0].FaceCL[i1].Type );
|
||||
s.W(Dex[i0].FaceCL[i1].ID );
|
||||
s.W(Dex[i0].FaceCL[i1].Value);
|
||||
s.W(Dex[i0].FaceCL[i1].Trans);
|
||||
}
|
||||
IO.Align(0x20, true);
|
||||
s.W(999999.0f);
|
||||
s.W(0xFFFF);
|
||||
s.W(0x0L);
|
||||
s.A(0x20);
|
||||
}
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
for (i = 0; i < Dex.Length; i++)
|
||||
{
|
||||
Dex[i0].NameOffset = IO.Position - Header.Lenght;
|
||||
IO.Write(Dex[i0].Name + "\0");
|
||||
Dex[i].NameOffset = s.P;
|
||||
s.W(Dex[i].Name + "\0");
|
||||
}
|
||||
IO.Align(0x10, true);
|
||||
s.A(0x10, true);
|
||||
|
||||
if (Header.IsX) IO.Seek(Header.Lenght + 0x28, 0);
|
||||
else IO.Seek(Header.Lenght + 0x20, 0);
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
s.P = header.IsX ? 0x28 : 0x20;
|
||||
for (i = 0; i < Dex.Length; i++)
|
||||
{
|
||||
IO.Write(Dex[i0].MainOffset);
|
||||
if (Header.IsX) IO.Write(0x00);
|
||||
IO.Write(Dex[i0].EyesOffset);
|
||||
if (Header.IsX) IO.Write(0x00);
|
||||
}
|
||||
int Position1 = IO.Position - Header.Lenght;
|
||||
for (int i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
IO.Write(Dex[i0].NameOffset);
|
||||
if (Header.IsX) IO.Write(0x00);
|
||||
s.WX(Dex[i].FaceOffset);
|
||||
s.WX(Dex[i].FaceCLOffset);
|
||||
}
|
||||
int namesPosition = s.P;
|
||||
for (i = 0; i < Dex.Length; i++)
|
||||
s.WX(Dex[i].NameOffset);
|
||||
|
||||
if (Header.IsX) IO.Seek(Position0 - 8, 0);
|
||||
else IO.Seek(Position0 - 4, 0);
|
||||
IO.Write(Position1);
|
||||
s.P = Position0 - (header.IsX ? 8 : 4);
|
||||
s.W(namesPosition);
|
||||
|
||||
if (IO.Format > Main.Format.F)
|
||||
if (format > Format.F)
|
||||
{
|
||||
Offset = IO.Length - Header.Lenght;
|
||||
IO.Seek(IO.Length, 0);
|
||||
IO.WriteEOFC(0);
|
||||
IO.Seek(0, 0);
|
||||
Header.DataSize = Offset;
|
||||
Header.SectionSize = Offset;
|
||||
IO.Write(Header);
|
||||
uint offset = s.LU32;
|
||||
s.O = 0;
|
||||
s.P = s.L;
|
||||
s.WEOFC(0);
|
||||
s.P = 0;
|
||||
header.DataSize = offset;
|
||||
header.SectionSize = offset;
|
||||
header.Signature = 0x43505845;
|
||||
header.UseSectionSize = true;
|
||||
s.W(header);
|
||||
}
|
||||
IO.Close();
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
public void MsgPackReader(string file, bool json)
|
||||
{
|
||||
int i0 = 0;
|
||||
int i1 = 0;
|
||||
this.Dex = new EXP[0];
|
||||
Header = new PDHead();
|
||||
Dex = null;
|
||||
header = new Header();
|
||||
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
|
||||
if (MsgPack.Element("Dex", out MsgPack Dex, typeof(object[])))
|
||||
MsgPack msgPack = file.ReadMPAllAtOnce(json);
|
||||
MsgPack dex;
|
||||
if ((dex = msgPack["Dex", true]).NotNull)
|
||||
{
|
||||
MsgPack Temp = new MsgPack();
|
||||
Dex = new EXP[dex.Array.Length];
|
||||
for (i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
Dex[i0] = new EXP { Name = dex[i0].RS("Name") };
|
||||
|
||||
this.Dex = new EXP[((object[])Dex.Object).Length];
|
||||
MsgPack EXP = new MsgPack();
|
||||
for (i0 = 0; i0 < this.Dex.Length; i0++)
|
||||
if (Dex[i0].GetType() == typeof(MsgPack))
|
||||
MsgPack temp;
|
||||
if ((temp = dex[i0]["Face", true]).NotNull)
|
||||
{
|
||||
this.Dex[i0] = new EXP();
|
||||
EXP = (MsgPack)Dex[i0];
|
||||
this.Dex[i0].Name = EXP.ReadString("Name");
|
||||
if (EXP.Element("Main", out Temp, typeof(object[])))
|
||||
{
|
||||
this.Dex[i0].Main = new List<EXPElement>
|
||||
{ Capacity = ((object[])Temp.Object).Length };
|
||||
for (i1 = 0; i1 < this.Dex[i0].Main.Capacity; i1++)
|
||||
if (Temp[i1].GetType() == typeof(MsgPack))
|
||||
this.Dex[i0].Main.Add(ReadEXP((MsgPack)Temp[i1]));
|
||||
}
|
||||
if (EXP.Element("Eyes", out Temp, typeof(object[])))
|
||||
{
|
||||
this.Dex[i0].Eyes = new List<EXPElement>
|
||||
{ Capacity = ((object[])Temp.Object).Length };
|
||||
for (i1 = 0; i1 < this.Dex[i0].Eyes.Capacity; i1++)
|
||||
if (Temp[i1].GetType() == typeof(MsgPack))
|
||||
this.Dex[i0].Eyes.Add(ReadEXP((MsgPack)Temp[i1]));
|
||||
}
|
||||
Dex[i0].Face = KKdList<EXPData>.New;
|
||||
Dex[i0].Face.Capacity = temp.Array.Length;
|
||||
for (i1 = 0; i1 < Dex[i0].Face.Capacity; i1++)
|
||||
Dex[i0].Face.Add(EXPData.Read(temp[i1]));
|
||||
}
|
||||
if ((temp = dex[i0]["FaceCL", true]).NotNull)
|
||||
{
|
||||
Dex[i0].FaceCL = KKdList<EXPData>.New;
|
||||
Dex[i0].FaceCL.Capacity = temp.Array.Length;
|
||||
for (i1 = 0; i1 < Dex[i0].FaceCL.Capacity; i1++)
|
||||
Dex[i0].FaceCL.Add(EXPData.Read(temp[i1]));
|
||||
}
|
||||
temp.Dispose();
|
||||
}
|
||||
}
|
||||
MsgPack = null;
|
||||
dex.Dispose();
|
||||
msgPack.Dispose();
|
||||
}
|
||||
|
||||
private EXPElement ReadEXP(MsgPack mp) =>
|
||||
new EXPElement() { Frame = mp.ReadSingle("F"), Both = mp.ReadUInt16("B"),
|
||||
ID = mp.ReadUInt16("I"), Value = mp.ReadSingle("V"),
|
||||
Trans = mp.ReadSingle("T") };
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
int i0 = 0;
|
||||
int i1 = 0;
|
||||
MsgPack Dex = new MsgPack("Dex", this.Dex.Length);
|
||||
for (i0 = 0; i0 < this.Dex.Length; i0++)
|
||||
{
|
||||
MsgPack EXP = new MsgPack().Add("Name", this.Dex[i0].Name);
|
||||
MsgPack Main = new MsgPack("Main", this.Dex[i0].Main.Count);
|
||||
for (i1 = 0; i1 < this.Dex[i0].Main.Count; i1++)
|
||||
Main[i1] = WriteEXP(this.Dex[i0].Main[i1]);
|
||||
EXP.Add(Main);
|
||||
if (Dex == null || Dex.Length < 1) return;
|
||||
|
||||
MsgPack Eyes = new MsgPack("Eyes", this.Dex[i0].Eyes.Count);
|
||||
for (i1 = 0; i1 < this.Dex[i0].Eyes.Count; i1++)
|
||||
Eyes[i1] = WriteEXP(this.Dex[i0].Eyes[i1]);
|
||||
EXP.Add(Eyes);
|
||||
Dex[i0] = EXP;
|
||||
MsgPack dex = new MsgPack(Dex.Length, "Dex");
|
||||
for (i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
MsgPack exp = MsgPack.New.Add("Name", Dex[i0].Name);
|
||||
MsgPack main = new MsgPack(Dex[i0].Face.Count, "Face");
|
||||
for (i1 = 0; i1 < Dex[i0].Face.Count; i1++)
|
||||
main[i1] = Dex[i0].Face[i1].Write();
|
||||
exp.Add(main);
|
||||
|
||||
MsgPack eyes = new MsgPack(Dex[i0].FaceCL.Count, "FaceCL");
|
||||
for (i1 = 0; i1 < Dex[i0].FaceCL.Count; i1++)
|
||||
eyes[i1] = Dex[i0].FaceCL[i1].Write();
|
||||
exp.Add(eyes);
|
||||
dex[i0] = exp;
|
||||
}
|
||||
|
||||
Dex.Write(true, file, JSON);
|
||||
dex.Write(false, true, file, json);
|
||||
}
|
||||
|
||||
private MsgPack WriteEXP(EXPElement element) =>
|
||||
new MsgPack().Add("F", element.Frame).Add("B", element.Both ).Add("I", element.ID )
|
||||
.Add("V", element.Value).Add("T", element.Trans);
|
||||
private bool disposed;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; Dex = null; header = default; disposed = true; } }
|
||||
|
||||
public struct EXP
|
||||
{
|
||||
public int MainOffset;
|
||||
public int EyesOffset;
|
||||
public int NameOffset;
|
||||
public long FaceOffset;
|
||||
public long FaceCLOffset;
|
||||
public long NameOffset;
|
||||
public string Name;
|
||||
public List<EXPElement> Main;
|
||||
public List<EXPElement> Eyes;
|
||||
public KKdList<EXPData> Face;
|
||||
public KKdList<EXPData> FaceCL;
|
||||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
public struct EXPElement
|
||||
public struct EXPData
|
||||
{
|
||||
public float Frame;
|
||||
public ushort Both;
|
||||
public ushort Type;
|
||||
public ushort ID;
|
||||
public float Value;
|
||||
public float Trans;
|
||||
|
||||
public static EXPData Read(MsgPack msg) =>
|
||||
new EXPData() { Frame = msg.RF32("Frame"), Type = msg.RU16("Type" ),
|
||||
ID = msg.RU16("ID" ), Value = msg.RF32("Value"),
|
||||
Trans = msg.RF32("Trans"), };
|
||||
|
||||
public MsgPack Write() =>
|
||||
MsgPack.New.Add("Frame", Frame).Add("Type" , Type )
|
||||
.Add("ID" , ID ).Add("Value", Value)
|
||||
.Add("Trans", Trans);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+99
-37
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using MSIO = System.IO;
|
||||
|
||||
@@ -9,56 +10,117 @@ namespace KKdMainLib
|
||||
{
|
||||
private static readonly byte[] Key = "file access deny".ToASCII();
|
||||
|
||||
public static void Decrypt(this string file)
|
||||
public static void Decrypt(string file)
|
||||
{
|
||||
Console.Title = "DIVAFILE Decrypt - File: " + Path.GetFileName(file);
|
||||
Stream reader = File.OpenReader(file);
|
||||
if (reader.ReadInt64() != 0x454C494641564944)
|
||||
{ reader.Close(); return; }
|
||||
int StreamLenght = reader.ReadInt32();
|
||||
int FileLenght = reader.ReadInt32();
|
||||
byte[] decrypted = new byte[StreamLenght];
|
||||
reader.Seek(0, 0);
|
||||
int streamLength, fileLength;
|
||||
byte[] encrypted, decrypted;
|
||||
using (Stream _IO = File.OpenReader(file))
|
||||
{
|
||||
if (_IO.RU64() != 0x454C494641564944u) return;
|
||||
|
||||
streamLength = _IO.RI32();
|
||||
fileLength = _IO.RI32();
|
||||
encrypted = _IO.RBy(streamLength);
|
||||
decrypted = new byte[streamLength];
|
||||
}
|
||||
|
||||
using (AesManaged crypto = new AesManaged())
|
||||
{
|
||||
crypto.Key = Key; crypto.IV = new byte[16];
|
||||
crypto.Mode = CipherMode.ECB; crypto.Padding = PaddingMode.Zeros;
|
||||
using (CryptoStream cryptoData = new CryptoStream(reader.BaseStream,
|
||||
crypto.CreateDecryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read))
|
||||
cryptoData.Read(decrypted, 0, StreamLenght);
|
||||
using CryptoStream cryptoData = new CryptoStream(new MSIO.MemoryStream(encrypted),
|
||||
crypto.CreateDecryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read);
|
||||
cryptoData.Read(decrypted, 0, streamLength);
|
||||
}
|
||||
Stream writer = File.OpenWriter(file, FileLenght);
|
||||
for (int i = 0x10; i < StreamLenght && i < FileLenght + 0x10; i++)
|
||||
writer.Write(decrypted[i]);
|
||||
writer.Close();
|
||||
|
||||
using (Stream _IO = File.OpenWriter(file, fileLength))
|
||||
_IO.W(decrypted, fileLength < streamLength ? fileLength : streamLength);
|
||||
}
|
||||
|
||||
public static void Encrypt(this string file)
|
||||
public static void Encrypt(string file)
|
||||
{
|
||||
Console.Title = "DIVAFILE Encrypt - File: " + Path.GetFileName(file);
|
||||
Stream reader = File.OpenReader(file);
|
||||
int FileLenghtOrigin = reader.Length;
|
||||
int FileLenght = FileLenghtOrigin.Align(16);
|
||||
reader.Close();
|
||||
byte[] In = File.OpenReader(file).ToArray(true);
|
||||
byte[] Inalign = new byte[FileLenght];
|
||||
for (int i = 0; i < In.Length; i++) Inalign[i] = In[i];
|
||||
In = null;
|
||||
byte[] encrypted = new byte[FileLenght];
|
||||
byte[] data;
|
||||
using (Stream _IO = File.OpenReader(file))
|
||||
data = _IO.ToArray();
|
||||
|
||||
int fileLengthOrigin = data.Length;
|
||||
int fileLength = fileLengthOrigin.A(16);
|
||||
byte[] dataAlign = new byte[fileLength];
|
||||
Array.Copy(data, dataAlign, data.Length);
|
||||
data = null;
|
||||
byte[] encrypted = new byte[fileLength];
|
||||
using (AesManaged crypto = new AesManaged())
|
||||
{
|
||||
crypto.Key = Key; crypto.IV = new byte[16];
|
||||
crypto.Mode = CipherMode.ECB; crypto.Padding = PaddingMode.Zeros;
|
||||
using (CryptoStream cryptoData = new CryptoStream(new MSIO.MemoryStream(Inalign),
|
||||
crypto.CreateEncryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read))
|
||||
cryptoData.Read(encrypted, 0, FileLenght);
|
||||
using CryptoStream cryptoData = new CryptoStream(new MSIO.MemoryStream(dataAlign),
|
||||
crypto.CreateEncryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read);
|
||||
cryptoData.Read(encrypted, 0, fileLength);
|
||||
}
|
||||
Stream writer = File.OpenWriter(file, Inalign.Length);
|
||||
writer.Write(0x454C494641564944);
|
||||
writer.Write(FileLenght);
|
||||
writer.Write(FileLenghtOrigin);
|
||||
writer.Write(encrypted);
|
||||
writer.Close();
|
||||
|
||||
using (Stream _IO = File.OpenWriter(file, dataAlign.Length))
|
||||
{
|
||||
_IO.W(0x454C494641564944u);
|
||||
_IO.W(fileLength);
|
||||
_IO.W(fileLengthOrigin);
|
||||
_IO.W(encrypted);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] Decrypt(byte[] data)
|
||||
{
|
||||
int streamLength, fileLength;
|
||||
byte[] encrypted, decrypted;
|
||||
using (Stream _IO = File.OpenReader(data))
|
||||
{
|
||||
if (_IO.RU64() != 0x454C494641564944u) return data;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
data = new byte[fileLength];
|
||||
Array.Copy(decrypted, data, fileLength < streamLength ? fileLength : streamLength);
|
||||
return data;
|
||||
}
|
||||
|
||||
public static byte[] Encrypt(byte[] data)
|
||||
{
|
||||
int fileLengthOrigin = data.Length;
|
||||
int fileLength = fileLengthOrigin.A(16);
|
||||
byte[] dataAlign = new byte[fileLength];
|
||||
Array.Copy(data, dataAlign, data.Length);
|
||||
data = null;
|
||||
byte[] encrypted = new byte[fileLength];
|
||||
using (AesManaged crypto = new AesManaged())
|
||||
{
|
||||
crypto.Key = Key; crypto.IV = new byte[16];
|
||||
crypto.Mode = CipherMode.ECB; crypto.Padding = PaddingMode.Zeros;
|
||||
using CryptoStream cryptoData = new CryptoStream(new MSIO.MemoryStream(dataAlign),
|
||||
crypto.CreateEncryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read);
|
||||
cryptoData.Read(encrypted, 0, fileLength);
|
||||
}
|
||||
|
||||
using (Stream _IO = File.OpenWriter())
|
||||
{
|
||||
_IO.W(0x454C494641564944u);
|
||||
_IO.W(fileLength);
|
||||
_IO.W(fileLengthOrigin);
|
||||
_IO.W(encrypted);
|
||||
data = _IO.ToArray();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+353
-220
@@ -1,301 +1,434 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Xml.Linq;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public class DataBank
|
||||
public struct DataBank : IDisposable
|
||||
{
|
||||
public DataBank()
|
||||
{ Success = false; Xml = null; IO = null; pvList = null; }
|
||||
private int i;
|
||||
private Stream s;
|
||||
|
||||
public bool pvListPDA;
|
||||
public PvList[] pvList;
|
||||
public PsrData[] psrData;
|
||||
|
||||
private const string d = ".";
|
||||
private const string c = ",";
|
||||
|
||||
public bool Success { get; private set; }
|
||||
|
||||
private Xml Xml;
|
||||
private Stream IO;
|
||||
|
||||
private PvList[] pvList;
|
||||
|
||||
public void DBReader(string file)
|
||||
{
|
||||
pvListPDA = false;
|
||||
Success = false;
|
||||
if (!File.Exists(file)) return;
|
||||
string text = File.ReadAllText(file);
|
||||
while (text.Contains("%")) text = WebUtility.UrlDecode(text);
|
||||
string[] array = text.Split(',');
|
||||
|
||||
string out_data = File.ReadAllText(file);
|
||||
while (out_data.Contains("%")) out_data = WebUtility.UrlDecode(out_data);
|
||||
|
||||
string[] data_split = out_data.Split(',');
|
||||
|
||||
if (file.Contains("PvList"))
|
||||
pvList = null;
|
||||
psrData = null;
|
||||
if (file.Contains("psrData") && array.Length % 13 == 0)
|
||||
{
|
||||
if (data_split.Length % 7 < 2)
|
||||
{
|
||||
int Count = data_split.Length / 7;
|
||||
pvList = new PvList[Count];
|
||||
for (int i = 0; i < Count; i++)
|
||||
pvList[i].SetValue(data_split, i);
|
||||
Success = true;
|
||||
return;
|
||||
}
|
||||
psrData = new PsrData[array.Length / 13];
|
||||
for (i = 0; i < psrData.Length; i++) psrData[i].SetValue(array, i);
|
||||
Success = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void DBWriter(string file)
|
||||
{
|
||||
if (!Success) return;
|
||||
|
||||
IO = File.OpenWriter();
|
||||
if (file.Contains("PvList"))
|
||||
if (pvList.Length > 0)
|
||||
for (int i = 0; i < pvList.Length; i++)
|
||||
IO.Write(UrlEncode(pvList[i].ToString() +
|
||||
(i + 1 != pvList.Length ? c : "")));
|
||||
else IO.Write("%2A%2A%2A");
|
||||
|
||||
byte[] data = IO.ToArray(true);
|
||||
|
||||
ushort checksum = DCC.CalculateChecksum(data);
|
||||
uint time = (uint)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||||
|
||||
File.WriteAllBytes(file + "_" + checksum + "_" + time + ".dat", data);
|
||||
}
|
||||
|
||||
public void XMLReader(string file)
|
||||
{
|
||||
Success = false;
|
||||
|
||||
if (!File.Exists(file)) return;
|
||||
|
||||
Xml = new Xml();
|
||||
Xml.OpenXml(file, true);
|
||||
|
||||
if (file.Contains("PvList"))
|
||||
foreach (XElement PvList in Xml.doc.Elements("PvList"))
|
||||
else if (file.Contains("psrData")) Success = true;
|
||||
else if (file.Contains("PvList") && (array.Length % 7 == 0 || array.Length % 6 == 0))
|
||||
{
|
||||
if (array[2] != "0" && array[2] != "1")
|
||||
{
|
||||
int Count = 0;
|
||||
foreach (XElement PV in PvList.Elements()) if (PV.Name == "PV") Count++;
|
||||
|
||||
pvList = new PvList[Count];
|
||||
int i = 0;
|
||||
foreach (XElement PV in PvList.Elements())
|
||||
{
|
||||
pvList[i].SetValue(PV);
|
||||
i++;
|
||||
}
|
||||
pvListPDA = true;
|
||||
pvList = new PvList[array.Length / 6];
|
||||
for (i = 0; i < pvList.Length; i++) pvList[i].SetValue(array, i, true);
|
||||
}
|
||||
|
||||
Success = true;
|
||||
else
|
||||
{
|
||||
pvList = new PvList[array.Length / 7];
|
||||
for (i = 0; i < pvList.Length; i++) pvList[i].SetValue(array, i, false);
|
||||
}
|
||||
Success = true;
|
||||
}
|
||||
else if (file.Contains("PvList")) Success = true;
|
||||
}
|
||||
|
||||
public void XMLWriter(string file)
|
||||
public byte[] DBWriter(string file)
|
||||
{
|
||||
if (!Success) return null;
|
||||
|
||||
s = File.OpenWriter();
|
||||
if (file.Contains("psrData"))
|
||||
{
|
||||
if (psrData != null && psrData.Length > 0)
|
||||
for (i = 0; i < psrData.Length; i++)
|
||||
if (psrData[i].PV_ID == 92)
|
||||
s.W(psrData[i].ToString() + c);
|
||||
else
|
||||
s.W(psrData[i].ToString() + c);
|
||||
}
|
||||
else if (file.Contains("PvList"))
|
||||
{
|
||||
if (pvList != null && pvList.Length > 0)
|
||||
{
|
||||
for (i = 0; i < pvList.Length - 1; i++)
|
||||
s.W(UrlEncode(pvList[i].ToString(pvListPDA) + c));
|
||||
s.W(UrlEncode(pvList[i].ToString(pvListPDA)));
|
||||
}
|
||||
else s.W("%2A%2A%2A");
|
||||
}
|
||||
|
||||
return s.ToArray(true);
|
||||
}
|
||||
|
||||
public void DBWriter(string file, uint timestamp)
|
||||
{
|
||||
if (!Success) return;
|
||||
|
||||
Xml = new Xml { Compact = true };
|
||||
byte[] data = DBWriter(file);
|
||||
if (data == null) return;
|
||||
|
||||
if (file.Contains("PvList"))
|
||||
ushort hash = data.HashCRC16_CCITT();
|
||||
File.WriteAllBytes(file + "_" + hash + "_" + timestamp + ".dat", data);
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
{
|
||||
pvListPDA = false;
|
||||
Success = false;
|
||||
MsgPack msgPack = file.ReadMPAllAtOnce(json);
|
||||
bool compact = msgPack.RB("Compact");
|
||||
|
||||
psrData = null;
|
||||
pvList = null;
|
||||
if (file.Contains("psrData"))
|
||||
{
|
||||
XElement PvList = new XElement("PvList");
|
||||
foreach (PvList pv in pvList)
|
||||
PvList.Add(pv.WriteXml(Xml, "PV"));
|
||||
Xml.doc.Add(PvList);
|
||||
MsgPack psrData;
|
||||
if ((psrData = msgPack["psrData", true]).NotNull)
|
||||
{
|
||||
this.psrData = new PsrData[psrData.Array.Length];
|
||||
for (i = 0; i < this.psrData.Length; i++)
|
||||
this.psrData[i].SetValue(psrData[i]);
|
||||
}
|
||||
Success = true;
|
||||
psrData.Dispose();
|
||||
}
|
||||
else if (file.Contains("PvList"))
|
||||
{
|
||||
MsgPack pvList;
|
||||
if ((pvList = msgPack["PvList", true]).NotNull)
|
||||
{
|
||||
this.pvList = new PvList[pvList.Array.Length];
|
||||
for (i = 0; i < this.pvList.Length; i++)
|
||||
this.pvList[i].SetValue(pvList[i], compact);
|
||||
}
|
||||
else if ((pvList = msgPack["PvListPDA", true]).NotNull)
|
||||
{
|
||||
pvListPDA = true;
|
||||
this.pvList = new PvList[pvList.Array.Length];
|
||||
for (i = 0; i < this.pvList.Length; i++)
|
||||
this.pvList[i].SetValue(pvList[i], compact);
|
||||
}
|
||||
Success = true;
|
||||
pvList.Dispose();
|
||||
}
|
||||
|
||||
if (File.Exists(file)) File.Delete(file);
|
||||
Xml.SaveXml(file);
|
||||
msgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
if (!Success) return;
|
||||
MsgPack msgPack = MsgPack.New;
|
||||
|
||||
if (file.Contains("psrData"))
|
||||
{
|
||||
if (psrData != null)
|
||||
{
|
||||
MsgPack psrData = new MsgPack(this.psrData.Length, "psrData");
|
||||
for (i = 0; i < this.psrData.Length; i++) psrData[i] = this.psrData[i].WriteMP();
|
||||
msgPack.Add(psrData);
|
||||
}
|
||||
else msgPack.Add(new MsgPack("psrData", null));
|
||||
}
|
||||
else if (file.Contains("PvList"))
|
||||
{
|
||||
if (pvList != null)
|
||||
{msgPack.Add("Compact", true);
|
||||
|
||||
MsgPack PvList = new MsgPack(pvList.Length, pvListPDA ? "PvListPDA" : "PvList");
|
||||
for (i = 0; i < pvList.Length; i++) PvList[i] = pvList[i].WriteMP();
|
||||
msgPack.Add(PvList);
|
||||
}
|
||||
else msgPack.Add(new MsgPack(pvListPDA ? "PvListPDA" : "PvList", null));
|
||||
}
|
||||
msgPack.Write(file, false, json).Dispose();
|
||||
}
|
||||
|
||||
public static string UrlEncode(string value) =>
|
||||
WebUtility.UrlEncode(value).Replace("+", "%20").Replace("!", "%21").Replace("*", "%2A");
|
||||
|
||||
private bool disposed;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; psrData = null;
|
||||
pvList = null; pvListPDA = false; Success = false; disposed = true; } }
|
||||
|
||||
public struct PsrData
|
||||
{
|
||||
public Player p1;
|
||||
public Player p2;
|
||||
public Player p3;
|
||||
public int PV_ID;
|
||||
|
||||
public void SetValue(string[] data, int i = 0)
|
||||
{
|
||||
p1.SetValue(data, i, 0);
|
||||
p2.SetValue(data, i, 1);
|
||||
p3.SetValue(data, i, 2);
|
||||
PV_ID = int.Parse(data[i * 13 + 12]);
|
||||
}
|
||||
|
||||
public void SetValue(MsgPack msg)
|
||||
{
|
||||
int? id = msg.RnI32("PV_ID");
|
||||
if (id != null) PV_ID = (int)id;
|
||||
else { id = msg.RnI32("ID"); if (id != null) PV_ID = (int)id; }
|
||||
|
||||
MsgPack temp;
|
||||
if ((temp = msg["P1"]).NotNull) p1.SetValue(temp);
|
||||
if ((temp = msg["P2"]).NotNull) p2.SetValue(temp);
|
||||
if ((temp = msg["P3"]).NotNull) p3.SetValue(temp);
|
||||
temp.Dispose();
|
||||
}
|
||||
|
||||
public MsgPack WriteMP() =>
|
||||
MsgPack.New.Add("PV_ID", PV_ID).Add(p1.WriteMP("P1"))
|
||||
.Add(p2.WriteMP("P2")).Add(p3.WriteMP("P3"));
|
||||
|
||||
public override string ToString() =>
|
||||
UrlEncode($"{p1},{p2},{p3},{PV_ID}");
|
||||
}
|
||||
|
||||
public struct Player
|
||||
{
|
||||
public int Score0;
|
||||
public int Score1;
|
||||
public string Name0;
|
||||
public string Name1;
|
||||
public int Diff;
|
||||
public bool Has2P => Name1 != null;
|
||||
public string Name;
|
||||
public string NameExtra;
|
||||
public int Score;
|
||||
public int ScoreExtra;
|
||||
public Difficulty Diff;
|
||||
public bool HasExtra => NameExtra != null;
|
||||
|
||||
public void SetValue(string[] data, int i = 0, int offset = 0)
|
||||
{
|
||||
string[] arr = data[i * 13 + 0 + offset * 4].Split('.');
|
||||
Score0 = int.Parse(arr[0]);
|
||||
if (arr.Length > 1) Score1 = int.Parse(arr[1]);
|
||||
|
||||
string temp = "";
|
||||
for (int i1 = 0; i1 < data[i * 13 + 1 + offset * 4].Length; i1++)
|
||||
string[] array = data[i * 13 + offset * 4].Split('.');
|
||||
Score = int.Parse(array[0]);
|
||||
if (array.Length > 1) ScoreExtra = int.Parse(array[1]);
|
||||
string text = "";
|
||||
for (int j = 0; j < data[i * 13 + 1 + offset * 4].Length; j++)
|
||||
{
|
||||
temp += data[i * 13 + 1 + offset * 4][i1];
|
||||
if (temp.EndsWith("xxx")) { Name0 = temp.Remove(temp.Length - 3); temp = ""; }
|
||||
}
|
||||
if (arr.Length == 1) Name0 = temp;
|
||||
else Name1 = temp;
|
||||
Diff = int.Parse(data[i * 13 + 2 + offset * 4]);
|
||||
}
|
||||
|
||||
public void SetValue(XElement value)
|
||||
{
|
||||
Name1 = null;
|
||||
foreach (XAttribute Entry in value.Attributes())
|
||||
if (Entry.Name == "Score" ) Score0 = int.Parse(Entry.Value);
|
||||
else if (Entry.Name == "Name" ) Name0 = Entry.Value;
|
||||
else if (Entry.Name == "Diff" ) Diff = int.Parse(Entry.Value);
|
||||
else if (Entry.Name == "Score0") Score0 = int.Parse(Entry.Value);
|
||||
else if (Entry.Name == "Score1") Score1 = int.Parse(Entry.Value);
|
||||
else if (Entry.Name == "Name0" ) Name0 = Entry.Value;
|
||||
else if (Entry.Name == "Name1" ) Name1 = Entry.Value;
|
||||
}
|
||||
|
||||
public XElement WriteXml(Xml Xml, string name)
|
||||
{
|
||||
XElement element = new XElement(name);
|
||||
if (!Has2P)
|
||||
{
|
||||
Xml.Writer(element, Score0, "Score");
|
||||
Xml.Writer(element, Name0 , "Name" );
|
||||
text += data[i * 13 + 1 + offset * 4][j].ToString();
|
||||
if (text.EndsWith("xxx"))
|
||||
{
|
||||
Name = text.Remove(text.Length - 3);
|
||||
text = "";
|
||||
}
|
||||
}
|
||||
if (array.Length == 1) Name = text;
|
||||
else NameExtra = text;
|
||||
if (int.TryParse(data[i * 13 + 2 + offset * 4], out int Diff))
|
||||
this.Diff = (Difficulty)Diff;
|
||||
else
|
||||
{
|
||||
Xml.Writer(element, Score0, "Score0");
|
||||
Xml.Writer(element, Score1, "Score1");
|
||||
Xml.Writer(element, Name0 , "Name0" );
|
||||
Xml.Writer(element, Name1 , "Name1" );
|
||||
}
|
||||
Xml.Writer(element, Diff, "Diff");
|
||||
return element;
|
||||
Enum.TryParse(data[i * 13 + 2 + offset * 4], out this.Diff);
|
||||
}
|
||||
|
||||
public override string ToString() => (Score0 + (Has2P ? d + Score1 : "") + c + UrlEncode(Name0) +
|
||||
(Has2P ? "xxx" + UrlEncode(Name1) : "") + c + Diff + c + (Has2P ? "0.1" : "0")).Replace("*", "%2A");
|
||||
}
|
||||
public void SetValue(MsgPack msg)
|
||||
{
|
||||
Diff = (Difficulty)msg.RI32("Diff");
|
||||
Name = msg.RS ( "Name");
|
||||
NameExtra = msg.RS ( "NameExtra");
|
||||
Score = msg.RI32("Score");
|
||||
ScoreExtra = msg.RI32("ScoreExtra");
|
||||
|
||||
public static string UrlEncode(string value) => WebUtility.UrlEncode(value).Replace("+", "%20");
|
||||
if (Name == null)
|
||||
{
|
||||
Name = msg.RS ( "Name0");
|
||||
NameExtra = msg.RS ( "Name1");
|
||||
Score = msg.RI32("Score0");
|
||||
ScoreExtra = msg.RI32("Score1");
|
||||
}
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(string name) =>
|
||||
HasExtra ? new MsgPack(name).Add("Diff", (int)Diff).Add("Name", Name)
|
||||
.Add("NameExtra", NameExtra).Add("Score", Score).Add("ScoreExtra", ScoreExtra) :
|
||||
new MsgPack(name).Add("Diff", (int)Diff).Add("Name" , Name) .Add("Score" , Score);
|
||||
|
||||
public override string ToString() =>
|
||||
Score + (HasExtra ? (d + ScoreExtra) : "") + c + UrlEncode(Name) +
|
||||
(HasExtra ? ("xxx" + UrlEncode(NameExtra)) : "") + c +
|
||||
(int)Diff + c + (HasExtra ? "0.1" : "0");
|
||||
}
|
||||
|
||||
public struct PvList
|
||||
{
|
||||
public int ID;
|
||||
public bool Enable;
|
||||
public bool Extra;
|
||||
public int PV_ID;
|
||||
public int Version;
|
||||
public int Edition;
|
||||
public Date AdvDemoStart;
|
||||
public Date AdvDemoEnd;
|
||||
public Date StartShow;
|
||||
public Date EndShow;
|
||||
|
||||
public void SetValue(string[] data, int i = 0)
|
||||
public void SetValue(string[] data, int i = 0, bool pda = false)
|
||||
{
|
||||
ID = int.Parse(data[i * 7 + 0]);
|
||||
Enable = int.Parse(data[i * 7 + 1]) == 1;
|
||||
Extra = int.Parse(data[i * 7 + 2]) == 1;
|
||||
AdvDemoStart.SetValue(data[i * 7 + 3]);
|
||||
AdvDemoEnd .SetValue(data[i * 7 + 4]);
|
||||
StartShow .SetValue(data[i * 7 + 5]);
|
||||
EndShow .SetValue(data[i * 7 + 6]);
|
||||
if (pda)
|
||||
{
|
||||
PV_ID = int.Parse(data[i * 6]);
|
||||
Version = int.Parse(data[i * 6 + 1]);
|
||||
AdvDemoStart.SV(data[i * 6 + 2]);
|
||||
AdvDemoEnd.SV(data[i * 6 + 3]);
|
||||
StartShow.SV(data[i * 6 + 4]);
|
||||
EndShow.SV(data[i * 6 + 5]);
|
||||
}
|
||||
else
|
||||
{
|
||||
PV_ID = int.Parse(data[i * 7]);
|
||||
Version = int.Parse(data[i * 7 + 1]);
|
||||
Edition = int.Parse(data[i * 7 + 2]);
|
||||
AdvDemoStart.SV(data[i * 7 + 3]);
|
||||
AdvDemoEnd .SV(data[i * 7 + 4]);
|
||||
StartShow .SV(data[i * 7 + 5]);
|
||||
EndShow .SV(data[i * 7 + 6]);
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() => UrlEncode(ID +
|
||||
c + (Enable ? 1 : 0) + c + (Extra ? 1 : 0) +
|
||||
c + AdvDemoStart.ToString() + c + AdvDemoEnd.ToString() +
|
||||
c + StartShow .ToString() + c + EndShow .ToString());
|
||||
|
||||
public void SetValue(XElement Value)
|
||||
public void SetValue(MsgPack msg, bool Compact)
|
||||
{
|
||||
Enable = true;
|
||||
foreach (XAttribute Entry in Value.Attributes())
|
||||
if (Entry.Name == "ID" ) ID = int.Parse(Entry.Value);
|
||||
else if (Entry.Name == "Enable" ) Enable = bool.Parse(Entry.Value);
|
||||
else if (Entry.Name == "Extra" ) Extra = bool.Parse(Entry.Value);
|
||||
Version = 1;
|
||||
Edition = 0;
|
||||
|
||||
AdvDemoStart.SetDefaultUpper();
|
||||
AdvDemoEnd .SetDefaultLower();
|
||||
StartShow .SetDefaultLower();
|
||||
EndShow .SetDefaultUpper();
|
||||
int? id = msg.RnI32("PV_ID");
|
||||
if (id != null) PV_ID = id.Value; else { id = msg.RnI32("ID"); if (id != null) PV_ID = id.Value; }
|
||||
bool? enable = msg.RnB("Enable"); if (enable != null) Version = enable.Value ? 1 : 0;
|
||||
bool? extra = msg.RnB("Extra" ); if (extra != null) Edition = extra .Value ? 1 : 0;
|
||||
int? version = msg.RnI32("Version"); if (version != null) Version = version.Value;
|
||||
int? edition = msg.RnI32("Edition"); if (edition != null) Edition = edition.Value;
|
||||
if (Compact)
|
||||
{
|
||||
AdvDemoStart.SV(msg.RnI32("AdvDemoStart"), true);
|
||||
AdvDemoEnd .SV(msg.RnI32("AdvDemoEnd" ), false);
|
||||
StartShow .SV(msg.RnI32("StartShow" ), false);
|
||||
EndShow .SV(msg.RnI32( "EndShow" ), true);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (XElement value in Value.Elements())
|
||||
if (value.Name == "AdvDemoStart") AdvDemoStart.SetValue(value);
|
||||
else if (value.Name == "AdvDemoEnd" ) AdvDemoEnd .SetValue(value);
|
||||
else if (value.Name == "StartShow" ) StartShow .SetValue(value);
|
||||
else if (value.Name == "EndShow" ) EndShow .SetValue(value);
|
||||
MsgPack temp;
|
||||
if ((temp = msg["AdvDemoStart", true]).NotNull) AdvDemoStart.SV(temp, true);
|
||||
if ((temp = msg["AdvDemoEnd" , true]).NotNull) AdvDemoEnd .SV(temp, false);
|
||||
if ((temp = msg["StartShow" , true]).NotNull) StartShow .SV(temp, false);
|
||||
if ((temp = msg[ "EndShow" , true]).NotNull) EndShow .SV(temp, true);
|
||||
temp.Dispose();
|
||||
}
|
||||
|
||||
public XElement WriteXml(Xml Xml, string name)
|
||||
public MsgPack WriteMP()
|
||||
{
|
||||
XElement element = new XElement(name);
|
||||
Xml.Writer(element, ID , "ID" );
|
||||
if (!Enable) Xml.Writer(element, Enable, "Enable");
|
||||
if ( Extra ) Xml.Writer(element, Extra , "Extra" );
|
||||
if (AdvDemoEnd.WriteLower)
|
||||
element.Add(AdvDemoStart.WriteXml(Xml, "AdvDemoStart"));
|
||||
if (AdvDemoEnd.WriteLower)
|
||||
element.Add(AdvDemoEnd .WriteXml(Xml, "AdvDemoEnd" ));
|
||||
if (StartShow .WriteLower)
|
||||
element.Add(StartShow .WriteXml(Xml, "StartShow" ));
|
||||
if ( EndShow .WriteUpper)
|
||||
element.Add(EndShow .WriteXml(Xml, "EndShow" ));
|
||||
return element;
|
||||
MsgPack msgPack = MsgPack.New.Add("ID" , PV_ID );
|
||||
if (Version != 1) msgPack.Add("Version", Version);
|
||||
if (Edition != 0) msgPack.Add("Edition", Edition);
|
||||
if (AdvDemoStart.WU) msgPack.Add("AdvDemoStart", AdvDemoStart.Int);
|
||||
if (AdvDemoEnd .WL) msgPack.Add("AdvDemoEnd" , AdvDemoEnd .Int);
|
||||
if (StartShow .WL) msgPack.Add("StartShow" , StartShow .Int);
|
||||
if ( EndShow .WU) msgPack.Add( "EndShow" , EndShow .Int);
|
||||
return msgPack;
|
||||
}
|
||||
|
||||
public string ToString(bool pda) => !pda
|
||||
? UrlEncode($"{PV_ID},{Version},{Edition},{AdvDemoStart},{AdvDemoEnd},{StartShow},{EndShow}")
|
||||
: UrlEncode($"{PV_ID},{Version},{AdvDemoStart},{AdvDemoEnd},{StartShow},{EndShow}");
|
||||
}
|
||||
|
||||
private const string d = ".";
|
||||
private const string c = ",";
|
||||
|
||||
public struct Date
|
||||
{
|
||||
private int year ;
|
||||
private int year;
|
||||
private int month;
|
||||
private int day ;
|
||||
private int day;
|
||||
|
||||
public int Year { get => year ; set { year = value; CheckDate(); } }
|
||||
public int Year { get => year; set { year = value; CheckDate(); } }
|
||||
public int Month { get => month; set { month = value; CheckDate(); } }
|
||||
public int Day { get => day ; set { day = value; CheckDate(); } }
|
||||
public int Day { get => day; set { day = value; CheckDate(); } }
|
||||
|
||||
public bool WriteUpper => (Year == 2029 && Month == 1 && Day == 1) ^ true;
|
||||
public bool WriteLower => (Year == 2000 && Month == 1 && Day == 1) ^ true;
|
||||
public bool WU => Year != 2029 || Month != 1 || Day != 1;
|
||||
public bool WL => Year != 2000 || Month != 1 || Day != 1;
|
||||
|
||||
public void SetDefaultLower() => Year = 1999;
|
||||
public void SetDefaultUpper() => Year = 2029;
|
||||
public void SDL() => Year = 2000;
|
||||
public void SDU() => Year = 2029;
|
||||
|
||||
public void SetValue(string data)
|
||||
public void SV(string data)
|
||||
{
|
||||
string[] arr = data.Split('-');
|
||||
if (arr.Length != 3) return;
|
||||
Year = int.Parse(arr[0]);
|
||||
Month = int.Parse(arr[1]);
|
||||
Day = int.Parse(arr[2]);
|
||||
string[] array = data.Split('-');
|
||||
if (array.Length == 3)
|
||||
{
|
||||
Year = int.Parse(array[0]);
|
||||
Month = int.Parse(array[1]);
|
||||
Day = int.Parse(array[2]);
|
||||
}
|
||||
}
|
||||
|
||||
public void SV(int? ymd, bool setDefaultUpper)
|
||||
{
|
||||
if (!setDefaultUpper) SDL();
|
||||
else SDU();
|
||||
if (ymd != null)
|
||||
{
|
||||
year = ymd.Value / 10000;
|
||||
month = ymd.Value / 100 % 100;
|
||||
day = ymd.Value % 100;
|
||||
CheckDate();
|
||||
}
|
||||
}
|
||||
|
||||
public void SV(MsgPack msg, bool setDefaultUpper)
|
||||
{
|
||||
if (!setDefaultUpper) SDL();
|
||||
else SDU();
|
||||
int? Year = msg.RnI32( "Year");
|
||||
int? Month = msg.RnI32("Month");
|
||||
int? Day = msg.RnI32( "Day");
|
||||
if ( Year != null) year = Year.Value;
|
||||
if (Month != null) month = Month.Value;
|
||||
if ( Day != null) day = Day.Value;
|
||||
CheckDate();
|
||||
}
|
||||
|
||||
public int Int => (Year * 100 + Month) * 100 + Day;
|
||||
|
||||
private void CheckDate()
|
||||
{
|
||||
if (year < 2000) { year = 2000; month = 1; day = 1; return; }
|
||||
else if (year >= 2029) { year = 2029; month = 1; day = 1; return; }
|
||||
|
||||
if (month < 1) month = 1;
|
||||
if (year < 2000) { year = 2000; month = 1; day = 1; return; }
|
||||
if (year >= 2029) { year = 2029; month = 1; day = 1; return; }
|
||||
if (month < 1) month = 1;
|
||||
else if (month > 12) month = 12;
|
||||
if (day < 1) day = 1;
|
||||
else if (day > 31 && (month == 1 || month == 3 || month == 5 ||
|
||||
month == 7 || month == 8 || month == 10 || month == 12)) day = 31;
|
||||
else if (day > 30 && (month == 4 || month == 6 || month == 9 || month == 11)) day = 30;
|
||||
else if (day > 29 && month == 2 && year % 4 == 0) day = 29;
|
||||
else if (day > 28 && month == 2 && year % 4 != 0) day = 29;
|
||||
if (day < 1) day = 1;
|
||||
else if (day > 31 && (month == 1 || month == 3 || month == 5 ||
|
||||
month == 7 || month == 8 || month == 10 || month == 12)) day = 31;
|
||||
else if (day > 30 && (month == 4 || month == 6 ||
|
||||
month == 9 || month == 11)) day = 30;
|
||||
else if (day > 29 && month == 2 && year % 4 == 0) day = 29;
|
||||
else if (day > 28 && month == 2 && year % 4 != 0) day = 28;
|
||||
}
|
||||
|
||||
public override string ToString() =>
|
||||
Year.ToString("d4") + "-" + Month.ToString("d2") + "-" + Day.ToString("d2");
|
||||
$"{Year:d4}-{Month:d2}-{Day:d2}";
|
||||
}
|
||||
|
||||
public void SetValue(XElement value)
|
||||
{
|
||||
foreach (XAttribute Entry in value.Attributes())
|
||||
if (Entry.Name == "Year" ) Year = int.Parse(Entry.Value);
|
||||
else if (Entry.Name == "Month") Month = int.Parse(Entry.Value);
|
||||
else if (Entry.Name == "Day" ) Day = int.Parse(Entry.Value);
|
||||
}
|
||||
|
||||
public XElement WriteXml(Xml Xml, string name)
|
||||
{
|
||||
XElement element = new XElement(name);
|
||||
Xml.Writer(element, Year , "Year" );
|
||||
Xml.Writer(element, Month, "Month");
|
||||
Xml.Writer(element, Day , "Day" );
|
||||
return element;
|
||||
}
|
||||
public enum Difficulty
|
||||
{
|
||||
Easy = 0,
|
||||
Normal = 1,
|
||||
Hard = 2,
|
||||
Extreme = 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,417 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public static class HeaderExtensions
|
||||
{
|
||||
public static Header ReadHeader(this Stream stream, bool seek)
|
||||
{
|
||||
if (seek)
|
||||
if (stream.PI64 > 4) stream.PI64 -= 4;
|
||||
else stream.PI64 = 0;
|
||||
return stream.ReadHeader();
|
||||
}
|
||||
|
||||
public static Header ReadHeader(this Stream stream)
|
||||
{
|
||||
Header header = new Header { Format = Format.F2 };
|
||||
header.Signature = stream.RU32();
|
||||
header.DataSize = stream.RU32();
|
||||
header.Length = stream.RU32();
|
||||
header.Flags = stream.RU32();
|
||||
header.Depth = stream.RU32();
|
||||
header.SectionSize = stream.RU32();
|
||||
header.Version = stream.RU32();
|
||||
stream.RI32();
|
||||
header.UseBigEndian = (header.Flags & 0x08000000) != 0;
|
||||
header.UseSectionSize = (header.Flags & 0x10000000) != 0;
|
||||
if (header.Length == 0x40)
|
||||
{
|
||||
stream.RI64();
|
||||
stream.RI64();
|
||||
header.InnerSignature = stream.RU32();
|
||||
stream.RI32();
|
||||
stream.RI64();
|
||||
}
|
||||
stream.Format = header.Format;
|
||||
return header;
|
||||
}
|
||||
|
||||
public static void W(this Stream stream, Header header, bool extended = false)
|
||||
{
|
||||
header.Length = (header.Format < Format.X && extended) ? 0x40u : 0x20u;
|
||||
header.Flags = (header.UseSectionSize ? 0x10000000 : 0u) |
|
||||
(header.UseBigEndian ? 0x08000000 : 0u);
|
||||
|
||||
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.Version);
|
||||
stream.W(0x00);
|
||||
if (header.Length == 0x40)
|
||||
{
|
||||
stream.W(0x00L);
|
||||
stream.W(0x00L);
|
||||
stream.W(header.InnerSignature);
|
||||
stream.W(0x00);
|
||||
stream.W(0x00L);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WEOFC(this Stream stream, uint depth = 0) =>
|
||||
stream.W(new Header { Depth = depth, Length = 0x20, Signature = 0x43464F45, UseSectionSize = true });
|
||||
}
|
||||
|
||||
public static class POFExtensions
|
||||
{
|
||||
public static void W(this Stream stream, POF pof, bool shiftX = false, uint depth = 0)
|
||||
{
|
||||
byte[] data = pof.Write(shiftX);
|
||||
Header header = new Header { Depth = depth, Format = Format.F2, Length = 0x20,
|
||||
Signature = shiftX ? 0x31464F50u : 0x30464F50u, UseSectionSize = true };
|
||||
header.DataSize = header.SectionSize = (uint)data.Length.A(0x10);
|
||||
stream.W(header);
|
||||
stream.W(data);
|
||||
for (int c = data.Length.A(0x10) - data.Length; c > 0; c--)
|
||||
stream.W((byte)0);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ENRSExtensions
|
||||
{
|
||||
public static void W(this Stream stream, ENRS enrs, uint depth = 0)
|
||||
{
|
||||
byte[] data = enrs.Write();
|
||||
Header header = new Header { Depth = depth, Format = Format.F2,
|
||||
Length = 0x20, Signature = 0x53524E45, UseSectionSize = true };
|
||||
header.DataSize = header.SectionSize = (uint)data.Length;
|
||||
stream.W(header);
|
||||
stream.W(data);
|
||||
}
|
||||
}
|
||||
|
||||
public static class StructExtensions
|
||||
{
|
||||
public static Struct RSt(this byte[] data)
|
||||
{
|
||||
if (data == null || data.Length < 1) return default;
|
||||
data = DIVAFILE.Decrypt(data);
|
||||
Struct @struct;
|
||||
using (Stream stream = File.OpenReader(data))
|
||||
@struct = stream.RSt(stream.ReadHeader(false));
|
||||
return @struct;
|
||||
}
|
||||
|
||||
private static Struct RSt(this Stream stream, Header header)
|
||||
{
|
||||
uint l = header.UseSectionSize ? header.SectionSize : header.DataSize;
|
||||
Struct @struct = new Struct { Header = header, DataOffset =
|
||||
stream.P, Data = stream.RBy(l) };
|
||||
uint depth = header.Depth;
|
||||
|
||||
uint lastSig = 0, sig;
|
||||
long length = stream.L - stream.P;
|
||||
long position = 0;
|
||||
KKdList<Struct> subStructs = KKdList<Struct>.New;
|
||||
while (length > position)
|
||||
{
|
||||
header = stream.ReadHeader(false);
|
||||
sig = header.Signature;
|
||||
l = header.UseSectionSize ? header.SectionSize : header.DataSize;
|
||||
position += header.Length + l;
|
||||
if (sig == 0x43464F45 && header.Depth == depth + 1) break;
|
||||
else if (sig == 0x53524E45 || (sig & 0xF0FFFFFF) == 0x30464F50)
|
||||
{
|
||||
byte[] Data = stream.RBy(l);
|
||||
if (sig == 0x53524E45) @struct.ENRS.Read(Data);
|
||||
else @struct.POF .Read(Data, sig == 0x31464F50);
|
||||
}
|
||||
else if (header.Depth == 0 && sig == 0x43505854)
|
||||
subStructs.Add(stream.RSt(header));
|
||||
else if (header.Depth > depth) subStructs.Add(stream.RSt(header));
|
||||
else { stream.PI64 -= header.Length; break; }
|
||||
lastSig = sig;
|
||||
}
|
||||
subStructs.Capacity = subStructs.Count;
|
||||
|
||||
if (subStructs.Capacity > 0) @struct.SubStructs = subStructs.ToArray();
|
||||
return @struct;
|
||||
}
|
||||
|
||||
public static byte[] W(this Struct @struct, bool shiftX = false, bool useDepth = true)
|
||||
{
|
||||
byte[] Data;
|
||||
using (Stream stream = File.OpenWriter())
|
||||
{ stream.W(@struct, 0, shiftX, useDepth); stream.WEOFC(); Data = stream.ToArray(); }
|
||||
return Data;
|
||||
}
|
||||
|
||||
public static void W(this Stream stream, Struct @struct, uint depth = 0,
|
||||
bool shiftX = false, bool useDepth = true)
|
||||
{
|
||||
@struct.Update(shiftX);
|
||||
|
||||
@struct.Header.Depth = depth;
|
||||
stream.W(@struct.Header, @struct.Header.Length == 0x40);
|
||||
if (@struct.Data != null) stream.W(@struct.Data);
|
||||
if (@struct.HasPOF ) stream.W(@struct.POF , shiftX, useDepth ? depth + 1 : 0u);
|
||||
if (@struct.HasENRS) stream.W(@struct.ENRS, useDepth ? depth + 1 : 0u);
|
||||
if (@struct.HasSubStructs)
|
||||
for (int i = 0; i < @struct.SubStructs.Length; i++)
|
||||
stream.W(@struct.SubStructs[i], depth + 1, shiftX, useDepth);
|
||||
if (@struct.HasPOF || @struct.HasENRS || @struct.HasSubStructs)
|
||||
stream.WEOFC(depth + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static class MPExt
|
||||
{
|
||||
public static MsgPack ReadMP(this byte[] array, bool json = false)
|
||||
{
|
||||
MsgPack MsgPack;
|
||||
if (json) using (JSON _IO = new JSON(File.OpenReader(array))) MsgPack = _IO.Read( );
|
||||
else using ( MP _IO = new MP(File.OpenReader(array))) MsgPack = _IO.Read(true);
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
public static MsgPack ReadMPAllAtOnce(this string file, bool json = false)
|
||||
{
|
||||
MsgPack MsgPack;
|
||||
if (json) using (JSON _IO = new JSON(File.OpenReader(file + ".json", true))) MsgPack = _IO.Read( );
|
||||
else using ( MP _IO = new MP(File.OpenReader(file + ".mp" , true))) MsgPack = _IO.Read(true);
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
public static MsgPack ReadMP(this string file, bool json = false)
|
||||
{
|
||||
MsgPack MsgPack;
|
||||
if (json) using (JSON _IO = new JSON(File.OpenReader(file + ".json"))) MsgPack = _IO.Read( );
|
||||
else using ( MP _IO = new MP(File.OpenReader(file + ".mp" ))) MsgPack = _IO.Read(true);
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
public static void Write(this MsgPack mp, bool ignoreNull, bool temp, string file, bool json = false)
|
||||
{ if (temp) MsgPack.New.Add(mp).Write(file, ignoreNull, json).Dispose();
|
||||
else mp .Write(file, ignoreNull, json); }
|
||||
|
||||
public static MsgPack Write(this MsgPack mp, string file, bool ignoreNull, bool json = false)
|
||||
{
|
||||
if (json)
|
||||
using (JSON _IO = new JSON(File.OpenWriter(file + ".json", true)))
|
||||
_IO.W(mp, ignoreNull, "\n", " ");
|
||||
else
|
||||
using ( MP _IO = new MP(File.OpenWriter(file + ".mp" , true)))
|
||||
_IO.W(mp, ignoreNull);
|
||||
return mp;
|
||||
}
|
||||
|
||||
public static void WriteAfterAll(this MsgPack mp, bool ignoreNull, bool temp, string file, bool json = false)
|
||||
{ if (temp) MsgPack.New.Add(mp).WriteAfterAll(file, ignoreNull, json).Dispose();
|
||||
else mp .WriteAfterAll(file, ignoreNull, json); }
|
||||
|
||||
public static MsgPack WriteAfterAll(this MsgPack mp, string file, bool ignoreNull, bool json = false)
|
||||
{
|
||||
byte[] data = null;
|
||||
if (json)
|
||||
using (JSON _IO = new JSON(File.OpenWriter()))
|
||||
{ _IO.W(mp, ignoreNull, true); data = _IO.ToArray(); }
|
||||
else
|
||||
using ( MP _IO = new MP(File.OpenWriter()))
|
||||
{ _IO.W(mp, ignoreNull ); data = _IO.ToArray(); }
|
||||
File.WriteAllBytes(file + (json ? ".json" : ".mp"), data);
|
||||
return mp;
|
||||
}
|
||||
|
||||
public static void ToJSON (this string file) =>
|
||||
file.ReadMP( ).Write(file, false, true).Dispose();
|
||||
|
||||
public static void ToMsgPack(this string file) =>
|
||||
file.ReadMP(true).Write(file, false ).Dispose();
|
||||
}
|
||||
|
||||
public static class IKFExt
|
||||
{
|
||||
public static IKF Round(this IKF kf, int d)
|
||||
{
|
||||
if (kf is KFT0 kft0) { kft0.F = kft0.F .Round(d); return kft0; }
|
||||
else if (kf is KFT1 kft1) { kft1.F = kft1.F .Round(d); kft1.V = kft1.V .Round(d); return kft1; }
|
||||
else if (kf is KFT2 kft2) { kft2.F = kft2.F .Round(d); kft2.V = kft2.V .Round(d);
|
||||
kft2.T = kft2.T .Round(d); return kft2; }
|
||||
else if (kf is KFT3 kft3) { kft3.F = kft3.F .Round(d); kft3.V = kft3.V .Round(d);
|
||||
kft3.T1 = kft3.T1.Round(d); kft3.T2 = kft3.T2.Round(d); return kft3; }
|
||||
return kf;
|
||||
}
|
||||
}
|
||||
|
||||
public static class HashExt
|
||||
{
|
||||
public static uint HashFNV1a64(this byte[] array) =>
|
||||
array.HashMurmurHash(array.Length);
|
||||
|
||||
// FNV 1a 64-bit Modified
|
||||
// 0x1403B04D0 in SBZV_7.10
|
||||
public static ulong HashFNV1a64m(this byte[] array, int length)
|
||||
{
|
||||
int i = 0;
|
||||
ulong hash = 0xCBF29CE484222325;
|
||||
while (i < length)
|
||||
{ hash = 0x100000001B3 * (hash ^ (ulong)array[i]); i++; }
|
||||
return (hash >> 32) ^ hash; // Actual Modification
|
||||
}
|
||||
|
||||
public static uint HashMurmurHash(this byte[] array, uint salt = 0,
|
||||
bool alreadyUpper = false, bool bigEndian = false) =>
|
||||
array.HashMurmurHash(array.Length, salt, alreadyUpper, bigEndian);
|
||||
|
||||
// MurmurHash
|
||||
// 0x814D7A9C in PCSB00554
|
||||
// 0x8134C304 in PCSB01007
|
||||
// 0x0069CEA4 in NPEB02013
|
||||
public static uint HashMurmurHash(this byte[] array, int length, uint salt = 0,
|
||||
bool alreadyUpper = false, bool bigEndian = false)
|
||||
{
|
||||
uint a, b, hash;
|
||||
int i;
|
||||
|
||||
const uint m = 0x7FD652AD;
|
||||
const int r = 16;
|
||||
|
||||
hash = salt + 0xDEADBEEF;
|
||||
if (alreadyUpper)
|
||||
{
|
||||
if (bigEndian)
|
||||
for (i = 0; length > 3; length -= 4, i += 4)
|
||||
{
|
||||
b = (uint)array[i + 3] | ((uint)array[i + 2] << 8)
|
||||
| ((uint)array[i + 1] << 16) | ((uint)array[i + 0] << 24);
|
||||
hash += b;
|
||||
hash *= m;
|
||||
hash ^= hash >> r;
|
||||
}
|
||||
else
|
||||
for (i = 0; length > 3; length -= 4, i += 4)
|
||||
{
|
||||
b = (uint)array[i + 0] | ((uint)array[i + 1] << 8)
|
||||
| ((uint)array[i + 2] << 16) | ((uint)array[i + 3] << 24);
|
||||
hash += b;
|
||||
hash *= m;
|
||||
hash ^= hash >> r;
|
||||
}
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
if (length > 1)
|
||||
{
|
||||
if (length > 2)
|
||||
hash += (uint)array[i + 2] << 16;
|
||||
hash += (uint)array[i + 1] << 8;
|
||||
}
|
||||
hash += array[i];
|
||||
hash *= m;
|
||||
hash ^= hash >> r;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bigEndian)
|
||||
for (i = 0; length > 3; length -= 4, i += 4)
|
||||
{
|
||||
b = (uint)array[i + 3] | ((uint)array[i + 2] << 8)
|
||||
| ((uint)array[i + 1] << 16) | ((uint)array[i + 0] << 24);
|
||||
a = b & 0xFF; if (a > 0x60 && a < 0x7B) a -= 0x20; b = (b & 0xFFFFFF00) | a ;
|
||||
a = (b >> 8) & 0xFF; if (a > 0x60 && a < 0x7B) a -= 0x20; b = (b & 0xFFFF00FF) | (a << 8);
|
||||
a = (b >> 16) & 0xFF; if (a > 0x60 && a < 0x7B) a -= 0x20; b = (b & 0xFF00FFFF) | (a << 16);
|
||||
a = (b >> 24) & 0xFF; if (a > 0x60 && a < 0x7B) a -= 0x20; b = (b & 0x00FFFFFF) | (a << 24);
|
||||
hash += b;
|
||||
hash *= m;
|
||||
hash ^= hash >> r;
|
||||
}
|
||||
else
|
||||
for (i = 0; length > 3; length -= 4, i += 4)
|
||||
{
|
||||
b = (uint)array[i + 0] | ((uint)array[i + 1] << 8)
|
||||
| ((uint)array[i + 2] << 16) | ((uint)array[i + 3] << 24);
|
||||
a = b & 0xFF; if (a > 0x60 && a < 0x7B) a -= 0x20; b = (b & 0xFFFFFF00) | a ;
|
||||
a = (b >> 8) & 0xFF; if (a > 0x60 && a < 0x7B) a -= 0x20; b = (b & 0xFFFF00FF) | (a << 8);
|
||||
a = (b >> 16) & 0xFF; if (a > 0x60 && a < 0x7B) a -= 0x20; b = (b & 0xFF00FFFF) | (a << 16);
|
||||
a = (b >> 24) & 0xFF; if (a > 0x60 && a < 0x7B) a -= 0x20; b = (b & 0x00FFFFFF) | (a << 24);
|
||||
hash += b;
|
||||
hash *= m;
|
||||
hash ^= hash >> r;
|
||||
}
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
if (length > 1)
|
||||
{
|
||||
if (length > 2)
|
||||
{
|
||||
b = array[i + 2]; if (b > 0x60 && b < 0x7B) b -= 0x20; hash += b << 16;
|
||||
}
|
||||
b = array[i + 1]; if (b > 0x60 && b < 0x7B) b -= 0x20; hash += b << 8;
|
||||
}
|
||||
b = array[i]; if (b > 0x60 && b < 0x7B) b -= 0x20; hash += b;
|
||||
hash *= m;
|
||||
hash ^= hash >> r;
|
||||
}
|
||||
}
|
||||
|
||||
hash *= m;
|
||||
hash ^= hash >> 10;
|
||||
hash *= m;
|
||||
hash ^= hash >> 17;
|
||||
return hash;
|
||||
}
|
||||
|
||||
private static readonly ushort[] CRC16_CCITT_Table = {
|
||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
|
||||
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
|
||||
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
|
||||
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
|
||||
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
|
||||
0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
|
||||
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
|
||||
0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
|
||||
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
|
||||
0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
|
||||
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
|
||||
0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
|
||||
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
|
||||
0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
|
||||
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
|
||||
0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
|
||||
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
|
||||
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
|
||||
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
|
||||
0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
|
||||
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
|
||||
0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
||||
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
|
||||
0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
|
||||
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
|
||||
0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
|
||||
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
|
||||
0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
|
||||
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
|
||||
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
|
||||
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
|
||||
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0,
|
||||
};
|
||||
|
||||
// CRC16-CCITT
|
||||
// 0x140011A90 in SBZV_7.10
|
||||
public static ushort HashCRC16_CCITT(this byte[] data, int offset = 0, ushort seed = 0xFFFF)
|
||||
{
|
||||
int length = data.Length;
|
||||
ushort hash = seed;
|
||||
for (int i = offset; i < length; i++)
|
||||
hash = (ushort)(CRC16_CCITT_Table[(hash >> 8) ^ data[i]] ^ (hash << 8));
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,361 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib.F2
|
||||
{
|
||||
public struct Bloom : System.IDisposable
|
||||
{
|
||||
private int i;
|
||||
private Stream s;
|
||||
|
||||
public bool IsX;
|
||||
public CountPointer<BLT> BLTs;
|
||||
|
||||
public void BLTReader(string file)
|
||||
{
|
||||
IsX = false;
|
||||
BLTs = default;
|
||||
byte[] bltData = File.ReadAllBytes(file + ".blt");
|
||||
Struct _BLMT = bltData.RSt(); bltData = null;
|
||||
if (_BLMT.Header.Signature != 0x544D4C42) return;
|
||||
|
||||
s = File.OpenReader(_BLMT.Data);
|
||||
s.IsBE = _BLMT.Header.UseBigEndian;
|
||||
|
||||
BLTs = s.RCPE<BLT>();
|
||||
if (BLTs.C < 1) { s.C(); BLTs.C = -1; return; }
|
||||
|
||||
if (!(BLTs.C > 0 && BLTs.O == 0))
|
||||
{
|
||||
s.PI64 = BLTs.O - _BLMT.Header.Length;
|
||||
for (i = 0; i < BLTs.C; i++)
|
||||
{
|
||||
ref BLT blt = ref BLTs.E[i];
|
||||
blt.Flags = (Flags)s.RI32E();
|
||||
blt.Color .X = s.RF32E();
|
||||
blt.Color .Y = s.RF32E();
|
||||
blt.Color .Z = s.RF32E();
|
||||
blt.Brightpass.X = s.RF32E();
|
||||
blt.Brightpass.Y = s.RF32E();
|
||||
blt.Brightpass.Z = s.RF32E();
|
||||
blt.Range = s.RF32E();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IsX = true;
|
||||
BLTs.O = (int)s.RI64E();
|
||||
s.PI64 = BLTs.O;
|
||||
for (i = 0; i < BLTs.C; i++)
|
||||
{
|
||||
ref BLT blt = ref BLTs.E[i];
|
||||
blt.Flags = (Flags)s.RI32E();
|
||||
blt.Color .X = s.RF32E();
|
||||
blt.Color .Y = s.RF32E();
|
||||
blt.Color .Z = s.RF32E();
|
||||
blt.Brightpass.X = s.RF32E();
|
||||
blt.Brightpass.Y = s.RF32E();
|
||||
blt.Brightpass.Z = s.RF32E();
|
||||
blt.Range = s.RF32E();
|
||||
blt.Unk1 = s.RF32 ();
|
||||
blt.Unk2 = s.RI32 ();
|
||||
blt.Unk3 = s.RF32 ();
|
||||
}
|
||||
}
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void BLTWriter(string file)
|
||||
{
|
||||
if (BLTs.E == null || BLTs.C < 1) return;
|
||||
|
||||
if (file.EndsWith("_bloom"))
|
||||
file = file.Substring(0, file.Length - 6);
|
||||
|
||||
s = File.OpenWriter();
|
||||
s.IsBE = false;
|
||||
s.Format = Format.F2;
|
||||
|
||||
ENRS e = default;
|
||||
POF p = default;
|
||||
p.Offsets = KKdList<long>.New;
|
||||
if (!IsX)
|
||||
{
|
||||
s.W(BLTs.C);
|
||||
s.W(0x50);
|
||||
s.A(0x10);
|
||||
|
||||
for (i = 0; i < BLTs.C; i++)
|
||||
{
|
||||
ref BLT blt = ref BLTs.E[i];
|
||||
s.W((int)blt.Flags);
|
||||
s.W(blt.Color .X);
|
||||
s.W(blt.Color .Y);
|
||||
s.W(blt.Color .Z);
|
||||
s.W(blt.Brightpass.X);
|
||||
s.W(blt.Brightpass.Y);
|
||||
s.W(blt.Brightpass.Z);
|
||||
s.W(blt.Range );
|
||||
}
|
||||
|
||||
e.Array = new ENRS.ENRSEntry[2];
|
||||
e.Array[0] = new ENRS.ENRSEntry(0x00, 0x01, 0x10, 0x01);
|
||||
e.Array[0].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x02, ENRS.ENRSEntry.Type.DWORD);
|
||||
e.Array[1] = new ENRS.ENRSEntry(0x10, 0x01, 0x20, BLTs.C);
|
||||
e.Array[1].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x08, ENRS.ENRSEntry.Type.DWORD);
|
||||
|
||||
p.Offsets.Add(0x44);
|
||||
}
|
||||
else
|
||||
{
|
||||
s.W(BLTs.C);
|
||||
s.A(0x08);
|
||||
s.W(0x10L);
|
||||
s.A(0x10);
|
||||
|
||||
for (i = 0; i < BLTs.C; i++)
|
||||
{
|
||||
ref BLT blt = ref BLTs.E[i];
|
||||
s.W((int)blt.Flags);
|
||||
s.W(blt.Color .X);
|
||||
s.W(blt.Color .Y);
|
||||
s.W(blt.Color .Z);
|
||||
s.W(blt.Brightpass.X);
|
||||
s.W(blt.Brightpass.Y);
|
||||
s.W(blt.Brightpass.Z);
|
||||
s.W(blt.Range );
|
||||
s.W(blt.Unk1 );
|
||||
s.W(blt.Unk2 );
|
||||
s.W(blt.Unk3 );
|
||||
}
|
||||
|
||||
e.Array = new ENRS.ENRSEntry[2];
|
||||
e.Array[0] = new ENRS.ENRSEntry(0x00, 0x02, 0x10, 0x01);
|
||||
e.Array[0].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x01, ENRS.ENRSEntry.Type.DWORD);
|
||||
e.Array[0].Sub[1] = new ENRS.ENRSEntry.SubENRSEntry(0x04, 0x01, ENRS.ENRSEntry.Type.QWORD);
|
||||
e.Array[1] = new ENRS.ENRSEntry(0x10, 0x01, 0x2C, BLTs.C);
|
||||
e.Array[1].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x08, ENRS.ENRSEntry.Type.DWORD);
|
||||
|
||||
p.Offsets.Add(0x08);
|
||||
}
|
||||
|
||||
s.A(0x10, true);
|
||||
byte[] data = s.ToArray(true);
|
||||
|
||||
Struct _BLMT = default;
|
||||
_BLMT.Header.Signature = 0x544D4C42;
|
||||
_BLMT.Header.DataSize = (uint)data.Length;
|
||||
_BLMT.Header.Length = 0x40;
|
||||
_BLMT.Header.Depth = 0;
|
||||
_BLMT.Header.SectionSize = (uint)data.Length;
|
||||
_BLMT.Header.Version = 0;
|
||||
_BLMT.Header.InnerSignature = 0x03;
|
||||
|
||||
_BLMT.Header.UseBigEndian = false;
|
||||
_BLMT.Header.UseSectionSize = true;
|
||||
_BLMT.Header.Format = Format.F2;
|
||||
_BLMT.Data = data;
|
||||
_BLMT.ENRS = e;
|
||||
_BLMT.POF = p;
|
||||
File.WriteAllBytes(file + ".blt", _BLMT.W(IsX, true));
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
{
|
||||
IsX = false;
|
||||
BLTs = default;
|
||||
|
||||
MsgPack msgPack = file.ReadMPAllAtOnce(json);
|
||||
MsgPack bloom;
|
||||
if ((bloom = msgPack["Bloom", true]).NotNull)
|
||||
{
|
||||
BLTs.E = new BLT[bloom.Array.Length];
|
||||
for (i = 0; i < BLTs.C; i++)
|
||||
{
|
||||
ref BLT blt = ref BLTs.E[i];
|
||||
blt = default;
|
||||
MsgPack b = bloom[i];
|
||||
MsgPack temp;
|
||||
if ((temp = b["Color"]).NotNull)
|
||||
{
|
||||
blt.Flags |= Flags.Color;
|
||||
blt.Color.X = temp.RF32("X");
|
||||
blt.Color.Y = temp.RF32("Y");
|
||||
blt.Color.Z = temp.RF32("Z");
|
||||
}
|
||||
|
||||
if ((temp = b["Brightpass"]).NotNull)
|
||||
{
|
||||
blt.Flags |= Flags.Brightpass;
|
||||
blt.Brightpass.X = temp.RF32("X");
|
||||
blt.Brightpass.Y = temp.RF32("Y");
|
||||
blt.Brightpass.Z = temp.RF32("Z");
|
||||
}
|
||||
|
||||
if ((temp = b["Range"]).Object != null)
|
||||
{
|
||||
blt.Flags |= Flags.Range;
|
||||
blt.Range = temp.RF32();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((bloom = msgPack["BloomX", true]).NotNull)
|
||||
{
|
||||
IsX = true;
|
||||
s.IsX = true;
|
||||
BLTs.E = new BLT[bloom.Array.Length];
|
||||
for (i = 0; i < BLTs.C; i++)
|
||||
{
|
||||
ref BLT blt = ref BLTs.E[i];
|
||||
blt = default;
|
||||
MsgPack b = bloom[i];
|
||||
MsgPack temp;
|
||||
if ((temp = b["Color"]).NotNull)
|
||||
{
|
||||
blt.Flags |= Flags.Color;
|
||||
blt.Color.X = temp.RF32("X");
|
||||
blt.Color.Y = temp.RF32("Y");
|
||||
blt.Color.Z = temp.RF32("Z");
|
||||
}
|
||||
|
||||
if ((temp = b["Brightpass"]).NotNull)
|
||||
{
|
||||
blt.Flags |= Flags.Brightpass;
|
||||
blt.Brightpass.X = temp.RF32("X");
|
||||
blt.Brightpass.Y = temp.RF32("Y");
|
||||
blt.Brightpass.Z = temp.RF32("Z");
|
||||
}
|
||||
|
||||
if ((temp = b["Range"]).Object != null)
|
||||
{
|
||||
blt.Flags |= Flags.Range;
|
||||
blt.Range = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = b["Unk1"]).Object != null)
|
||||
{
|
||||
blt.Flags |= Flags.Unk1;
|
||||
blt.Unk1 = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = b["Unk2"]).Object != null)
|
||||
{
|
||||
blt.Flags |= Flags.Unk2;
|
||||
blt.Unk2 = temp.RI32();
|
||||
}
|
||||
|
||||
if ((temp = b["Unk3"]).Object != null)
|
||||
{
|
||||
blt.Flags |= Flags.Unk3;
|
||||
blt.Unk3 = temp.RF32();
|
||||
}
|
||||
}
|
||||
}
|
||||
bloom.Dispose();
|
||||
msgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
if (BLTs.E == null || BLTs.C < 1) return;
|
||||
|
||||
MsgPack bloom;
|
||||
if (!IsX)
|
||||
{
|
||||
bloom = new MsgPack(BLTs.C, "Bloom");
|
||||
for (i = 0; i < BLTs.C; i++)
|
||||
{
|
||||
ref BLT blt = ref BLTs.E[i];
|
||||
MsgPack b = MsgPack.New;
|
||||
if ((blt.Flags & Flags.Color) != 0)
|
||||
b.Add(new MsgPack("Color")
|
||||
.Add("X", blt.Color.X)
|
||||
.Add("Y", blt.Color.Y)
|
||||
.Add("Z", blt.Color.Z));
|
||||
if ((blt.Flags & Flags.Brightpass) != 0)
|
||||
b.Add(new MsgPack("Brightpass")
|
||||
.Add("X", blt.Brightpass.X)
|
||||
.Add("Y", blt.Brightpass.Y)
|
||||
.Add("Z", blt.Brightpass.Z));
|
||||
if ((blt.Flags & Flags.Range) != 0)
|
||||
b.Add("Range", blt.Range);
|
||||
bloom[i] = b;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bloom = new MsgPack(BLTs.C, "BloomX");
|
||||
for (i = 0; i < BLTs.C; i++)
|
||||
{
|
||||
ref BLT blt = ref BLTs.E[i];
|
||||
MsgPack b = MsgPack.New;
|
||||
if ((blt.Flags & Flags.Color) != 0)
|
||||
b.Add(new MsgPack("Color")
|
||||
.Add("X", blt.Color.X)
|
||||
.Add("Y", blt.Color.Y)
|
||||
.Add("Z", blt.Color.Z));
|
||||
if ((blt.Flags & Flags.Brightpass) != 0)
|
||||
b.Add(new MsgPack("Brightpass")
|
||||
.Add("X", blt.Brightpass.X)
|
||||
.Add("Y", blt.Brightpass.Y)
|
||||
.Add("Z", blt.Brightpass.Z));
|
||||
if ((blt.Flags & Flags.Range) != 0)
|
||||
b.Add("Range", blt.Range);
|
||||
if ((blt.Flags & Flags.Unk1) != 0)
|
||||
b.Add("Unk1", blt.Unk1);
|
||||
if ((blt.Flags & Flags.Unk2) != 0)
|
||||
b.Add("Unk2", blt.Unk2);
|
||||
if ((blt.Flags & Flags.Unk3) != 0)
|
||||
b.Add("Unk3", blt.Unk3);
|
||||
bloom[i] = b;
|
||||
}
|
||||
}
|
||||
bloom.Write(false, true, file + "_bloom", json);
|
||||
}
|
||||
|
||||
public void TXTWriter(string file)
|
||||
{
|
||||
if (BLTs.C < 1) return;
|
||||
|
||||
s = File.OpenWriter();
|
||||
s.WPSSJIS("ID,ColorR,ColorG,ColorB,BrightpassR,BrightpassG,BrightpassB,Range\n");
|
||||
for (i = 0; i < BLTs.C; i++)
|
||||
s.W($"{i},{ BLTs[i]}\n");
|
||||
File.WriteAllBytes($"{file}_bloom.txt", s.ToArray(true));
|
||||
}
|
||||
|
||||
private bool disposed;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; BLTs = default; IsX = false; disposed = true; } }
|
||||
|
||||
public struct BLT
|
||||
{
|
||||
public Flags Flags;
|
||||
public Vec3 Color;
|
||||
public Vec3 Brightpass;
|
||||
public float Range;
|
||||
public float Unk1;
|
||||
public int Unk2;
|
||||
public float Unk3;
|
||||
|
||||
public override string ToString() =>
|
||||
((Flags & Flags.Color) != 0
|
||||
? $"{Color.X.ToS(6)},{Color.Y.ToS(6)},{Color.Z.ToS(6)}," : ",,,") +
|
||||
((Flags & Flags.Brightpass) != 0
|
||||
? $"{Brightpass.X.ToS(6)},{Brightpass.Y.ToS(6)},{Brightpass.Z.ToS(6)}," : ",,,") +
|
||||
((Flags & Flags.Range) != 0
|
||||
? $"{Range.ToS(6)}" : "");
|
||||
}
|
||||
|
||||
public enum Flags : int
|
||||
{
|
||||
Color = 0b000001,
|
||||
Brightpass = 0b000010,
|
||||
Range = 0b000100,
|
||||
Unk1 = 0b001000,
|
||||
Unk2 = 0b010000,
|
||||
Unk3 = 0b100000,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,379 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib.F2
|
||||
{
|
||||
public struct ColorCorrection : System.IDisposable
|
||||
{
|
||||
private int i;
|
||||
private Stream s;
|
||||
|
||||
public bool IsX;
|
||||
public CountPointer<CCT> CCTs;
|
||||
|
||||
public void CCTReader(string file)
|
||||
{
|
||||
IsX = false;
|
||||
CCTs = default;
|
||||
byte[] ccData = File.ReadAllBytes(file + ".cct");
|
||||
Struct _CCRT = ccData.RSt(); ccData = null;
|
||||
if (_CCRT.Header.Signature != 0x54524343) return;
|
||||
|
||||
s = File.OpenReader(_CCRT.Data);
|
||||
s.IsBE = _CCRT.Header.UseBigEndian;
|
||||
|
||||
CCTs = s.RCPE<CCT>();
|
||||
if (CCTs.C < 1) { s.C(); CCTs.C = -1; return; }
|
||||
|
||||
if (!(CCTs.C > 0 && CCTs.O == 0))
|
||||
{
|
||||
s.PI64 = CCTs.O - _CCRT.Header.Length;
|
||||
for (i = 0; i < CCTs.C; i++)
|
||||
{
|
||||
ref CCT cct = ref CCTs.E[i];
|
||||
cct.Flags = (Flags)s.RI32E();
|
||||
cct.Hue = s.RF32E();
|
||||
cct.Saturation = s.RF32E();
|
||||
cct.Lightness = s.RF32E();
|
||||
cct.Exposure = s.RF32E();
|
||||
cct.Gamma.X = s.RF32E();
|
||||
cct.Gamma.Y = s.RF32E();
|
||||
cct.Gamma.Z = s.RF32E();
|
||||
cct.Contrast = s.RF32E();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IsX = true;
|
||||
s.IsX = true;
|
||||
CCTs.O = (int)s.RI64E();
|
||||
s.PI64 = CCTs.O;
|
||||
for (i = 0; i < CCTs.C; i++)
|
||||
{
|
||||
ref CCT cct = ref CCTs.E[i];
|
||||
cct.Flags = (Flags)s.RI32E();
|
||||
cct.Hue = s.RF32E();
|
||||
cct.Saturation = s.RF32E();
|
||||
cct.Lightness = s.RF32E();
|
||||
cct.Exposure = s.RF32E();
|
||||
cct.Gamma.X = s.RF32E();
|
||||
cct.Gamma.Y = s.RF32E();
|
||||
cct.Gamma.Z = s.RF32E();
|
||||
cct.Contrast = s.RF32E();
|
||||
}
|
||||
}
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void CCTWriter(string file)
|
||||
{
|
||||
if (CCTs.E == null || CCTs.C < 1) return;
|
||||
|
||||
if (file.EndsWith("_cc"))
|
||||
file = file.Substring(0, file.Length - 3);
|
||||
|
||||
s = File.OpenWriter();
|
||||
s.IsBE = false;
|
||||
s.Format = Format.F2;
|
||||
|
||||
ENRS e = default;
|
||||
POF p = default;
|
||||
p.Offsets = KKdList<long>.New;
|
||||
if (!IsX)
|
||||
{
|
||||
s.W(CCTs.C);
|
||||
s.W(0x50);
|
||||
s.A(0x10);
|
||||
|
||||
for (i = 0; i < CCTs.C; i++)
|
||||
{
|
||||
ref CCT cct = ref CCTs.E[i];
|
||||
s.W((int)cct.Flags);
|
||||
s.W(cct.Hue );
|
||||
s.W(cct.Saturation);
|
||||
s.W(cct.Lightness );
|
||||
s.W(cct.Exposure );
|
||||
s.W(cct.Gamma.X );
|
||||
s.W(cct.Gamma.Y );
|
||||
s.W(cct.Gamma.Z );
|
||||
s.W(cct.Contrast );
|
||||
}
|
||||
|
||||
e.Array = new ENRS.ENRSEntry[2];
|
||||
e.Array[0] = new ENRS.ENRSEntry(0x00, 0x01, 0x10, 0x01);
|
||||
e.Array[0].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x02, ENRS.ENRSEntry.Type.DWORD);
|
||||
e.Array[1] = new ENRS.ENRSEntry(0x10, 0x01, 0x24, CCTs.C);
|
||||
e.Array[1].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x08, ENRS.ENRSEntry.Type.DWORD);
|
||||
|
||||
p.Offsets.Add(0x44);
|
||||
}
|
||||
else
|
||||
{
|
||||
s.W(CCTs.C);
|
||||
s.A(0x08);
|
||||
s.W(0x10L);
|
||||
s.A(0x10);
|
||||
|
||||
for (i = 0; i < CCTs.C; i++)
|
||||
{
|
||||
ref CCT cct = ref CCTs.E[i];
|
||||
s.W((int)cct.Flags);
|
||||
s.W(cct.Hue );
|
||||
s.W(cct.Saturation);
|
||||
s.W(cct.Lightness );
|
||||
s.W(cct.Exposure );
|
||||
s.W(cct.Gamma.X );
|
||||
s.W(cct.Gamma.Y );
|
||||
s.W(cct.Gamma.Z );
|
||||
s.W(cct.Contrast );
|
||||
}
|
||||
|
||||
e.Array = new ENRS.ENRSEntry[2];
|
||||
e.Array[0] = new ENRS.ENRSEntry(0x00, 0x02, 0x10, 0x01);
|
||||
e.Array[0].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x01, ENRS.ENRSEntry.Type.DWORD);
|
||||
e.Array[0].Sub[1] = new ENRS.ENRSEntry.SubENRSEntry(0x04, 0x01, ENRS.ENRSEntry.Type.QWORD);
|
||||
e.Array[1] = new ENRS.ENRSEntry(0x10, 0x01, 0x24, CCTs.C);
|
||||
e.Array[1].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x08, ENRS.ENRSEntry.Type.DWORD);
|
||||
|
||||
p.Offsets.Add(0x08);
|
||||
}
|
||||
|
||||
s.A(0x10, true);
|
||||
byte[] data = s.ToArray(true);
|
||||
|
||||
Struct _CCRT = default;
|
||||
_CCRT.Header.Signature = 0x54524343;
|
||||
_CCRT.Header.DataSize = (uint)data.Length;
|
||||
_CCRT.Header.Length = 0x40;
|
||||
_CCRT.Header.Depth = 0;
|
||||
_CCRT.Header.SectionSize = (uint)data.Length;
|
||||
_CCRT.Header.Version = 0;
|
||||
_CCRT.Header.InnerSignature = 0x03;
|
||||
|
||||
_CCRT.Header.UseBigEndian = false;
|
||||
_CCRT.Header.UseSectionSize = true;
|
||||
_CCRT.Header.Format = Format.F2;
|
||||
_CCRT.Data = data;
|
||||
_CCRT.ENRS = e;
|
||||
_CCRT.POF = p;
|
||||
File.WriteAllBytes(file + ".cct", _CCRT.W(IsX, true));
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
{
|
||||
IsX = false;
|
||||
CCTs = default;
|
||||
|
||||
MsgPack msgPack = file.ReadMPAllAtOnce(json);
|
||||
MsgPack cc;
|
||||
if ((cc = msgPack["ColorCorrection", true]).NotNull)
|
||||
{
|
||||
CCTs.E = new CCT[cc.Array.Length];
|
||||
for (i = 0; i < CCTs.C; i++)
|
||||
{
|
||||
ref CCT cct = ref CCTs.E[i];
|
||||
cct = default;
|
||||
MsgPack c = cc[i];
|
||||
MsgPack temp;
|
||||
if ((temp = c["Hue"]).Object != null)
|
||||
{
|
||||
cct.Flags |= Flags.Hue;
|
||||
cct.Hue = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = c["Saturation"]).Object != null)
|
||||
{
|
||||
cct.Flags |= Flags.Saturation;
|
||||
cct.Saturation = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = c["Lightness"]).Object != null)
|
||||
{
|
||||
cct.Flags |= Flags.Lightness;
|
||||
cct.Lightness = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = c["Exposure"]).Object != null)
|
||||
{
|
||||
cct.Flags |= Flags.Exposure;
|
||||
cct.Exposure = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = c["Gamma"]).NotNull)
|
||||
{
|
||||
cct.Flags |= Flags.Gamma;
|
||||
cct.Gamma.X = temp.RF32("X");
|
||||
cct.Gamma.Y = temp.RF32("Y");
|
||||
cct.Gamma.Z = temp.RF32("Z");
|
||||
}
|
||||
|
||||
if ((temp = c["Contrast"]).Object != null)
|
||||
{
|
||||
cct.Flags |= Flags.Contrast;
|
||||
cct.Contrast = temp.RF32();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((cc = msgPack["ColorCorrectionX", true]).NotNull)
|
||||
{
|
||||
IsX = true;
|
||||
CCTs.E = new CCT[cc.Array.Length];
|
||||
for (i = 0; i < CCTs.C; i++)
|
||||
{
|
||||
ref CCT cct = ref CCTs.E[i];
|
||||
cct = default;
|
||||
MsgPack c = cc[i];
|
||||
MsgPack temp;
|
||||
if ((temp = c["Hue"]).Object != null)
|
||||
{
|
||||
cct.Flags |= Flags.Hue;
|
||||
cct.Hue = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = c["Saturation"]).Object != null)
|
||||
{
|
||||
cct.Flags |= Flags.Saturation;
|
||||
cct.Saturation = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = c["Lightness"]).Object != null)
|
||||
{
|
||||
cct.Flags |= Flags.Lightness;
|
||||
cct.Lightness = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = c["Exposure"]).Object != null)
|
||||
{
|
||||
cct.Flags |= Flags.Exposure;
|
||||
cct.Exposure = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = c["Gamma"]).NotNull)
|
||||
{
|
||||
cct.Flags |= Flags.Gamma;
|
||||
cct.Gamma.X = temp.RF32("X");
|
||||
cct.Gamma.Y = temp.RF32("Y");
|
||||
cct.Gamma.Z = temp.RF32("Z");
|
||||
}
|
||||
|
||||
if ((temp = c["Contrast"]).Object != null)
|
||||
{
|
||||
cct.Flags |= Flags.Contrast;
|
||||
cct.Contrast = temp.RF32();
|
||||
}
|
||||
}
|
||||
}
|
||||
cc.Dispose();
|
||||
msgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
if (CCTs.E == null || CCTs.C < 1) return;
|
||||
|
||||
MsgPack cc;
|
||||
if (!IsX)
|
||||
{
|
||||
cc = new MsgPack(CCTs.C, "ColorCorrection");
|
||||
for (i = 0; i < CCTs.C; i++)
|
||||
{
|
||||
ref CCT cct = ref CCTs.E[i];
|
||||
MsgPack c = MsgPack.New;
|
||||
if ((cct.Flags & Flags.Hue) != 0)
|
||||
c.Add("Hue", cct.Hue);
|
||||
if ((cct.Flags & Flags.Saturation) != 0)
|
||||
c.Add("Saturation", cct.Saturation);
|
||||
if ((cct.Flags & Flags.Lightness) != 0)
|
||||
c.Add("Lightness", cct.Lightness);
|
||||
if ((cct.Flags & Flags.Exposure) != 0)
|
||||
c.Add("Exposure", cct.Exposure);
|
||||
if ((cct.Flags & Flags.Gamma) != 0)
|
||||
c.Add(new MsgPack("Gamma")
|
||||
.Add("X", cct.Gamma.X)
|
||||
.Add("Y", cct.Gamma.Y)
|
||||
.Add("Z", cct.Gamma.Z));
|
||||
if ((cct.Flags & Flags.Contrast) != 0)
|
||||
c.Add("Contrast", cct.Contrast);
|
||||
cc[i] = c;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cc = new MsgPack(CCTs.C, "ColorCorrectionX");
|
||||
for (i = 0; i < CCTs.C; i++)
|
||||
{
|
||||
ref CCT cct = ref CCTs.E[i];
|
||||
MsgPack c = MsgPack.New;
|
||||
if ((cct.Flags & Flags.Hue) != 0)
|
||||
c.Add("Hue", cct.Hue);
|
||||
if ((cct.Flags & Flags.Saturation) != 0)
|
||||
c.Add("Saturation", cct.Saturation);
|
||||
if ((cct.Flags & Flags.Lightness) != 0)
|
||||
c.Add("Lightness", cct.Lightness);
|
||||
if ((cct.Flags & Flags.Exposure) != 0)
|
||||
c.Add("Exposure", cct.Exposure);
|
||||
if ((cct.Flags & Flags.Gamma) != 0)
|
||||
c.Add(new MsgPack("Gamma")
|
||||
.Add("X", cct.Gamma.X)
|
||||
.Add("Y", cct.Gamma.Y)
|
||||
.Add("Z", cct.Gamma.Z));
|
||||
if ((cct.Flags & Flags.Contrast) != 0)
|
||||
c.Add("Contrast", cct.Contrast);
|
||||
cc[i] = c;
|
||||
}
|
||||
}
|
||||
cc.Write(false, true, file + "_cc", json);
|
||||
}
|
||||
|
||||
public void TXTWriter(string file)
|
||||
{
|
||||
if (CCTs.C < 1) return;
|
||||
|
||||
s = File.OpenWriter();
|
||||
s.WPSSJIS("ID,Hue,Saturation,Lightness,Exposure,GammaR,GammaG,GammaB,Contrast\n");
|
||||
for (i = 0; i < CCTs.C; i++)
|
||||
s.W($"{i},{CCTs[i]}\n");
|
||||
File.WriteAllBytes($"{file}_cc.txt", s.ToArray(true));
|
||||
}
|
||||
|
||||
private bool disposed;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; CCTs = default; IsX = false; disposed = true; } }
|
||||
|
||||
public struct CCT
|
||||
{
|
||||
public Flags Flags;
|
||||
public float Hue;
|
||||
public float Saturation;
|
||||
public float Lightness;
|
||||
public float Exposure;
|
||||
public Vec3 Gamma;
|
||||
public float Contrast;
|
||||
|
||||
public override string ToString() =>
|
||||
((Flags & Flags.Hue) != 0
|
||||
? $"{Hue.ToS(6)}," : ",") +
|
||||
((Flags & Flags.Saturation) != 0
|
||||
? $"{Saturation.ToS(6)}," : ",") +
|
||||
((Flags & Flags.Lightness) != 0
|
||||
? $"{Lightness.ToS(6)}," : ",") +
|
||||
((Flags & Flags.Exposure) != 0
|
||||
? $"{Exposure.ToS(6)}," : ",") +
|
||||
((Flags & Flags.Gamma) != 0
|
||||
? $"{Gamma.X.ToS(6)},{Gamma.Y.ToS(6)},{Gamma.Z.ToS(6)}," : ",,,") +
|
||||
((Flags & Flags.Contrast) != 0
|
||||
? $"{Contrast.ToS(6)}" : "");
|
||||
}
|
||||
|
||||
public enum Flags : int
|
||||
{
|
||||
Hue = 0b000001,
|
||||
Saturation = 0b000010,
|
||||
Lightness = 0b000100,
|
||||
Exposure = 0b001000,
|
||||
Gamma = 0b010000,
|
||||
Contrast = 0b100000,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,350 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib.F2
|
||||
{
|
||||
public struct DOF : System.IDisposable
|
||||
{
|
||||
private int i;
|
||||
private Stream s;
|
||||
|
||||
public bool IsX;
|
||||
public CountPointer<DFT> DFTs;
|
||||
|
||||
public void DFTReader(string file)
|
||||
{
|
||||
IsX = false;
|
||||
DFTs = default;
|
||||
byte[] dftData = File.ReadAllBytes(file + ".dft");
|
||||
Struct _DOFT = dftData.RSt(); dftData = null;
|
||||
if (_DOFT.Header.Signature != 0x54464F44) return;
|
||||
|
||||
s = File.OpenReader(_DOFT.Data);
|
||||
s.IsBE = _DOFT.Header.UseBigEndian;
|
||||
|
||||
DFTs = s.RCPE<DFT>();
|
||||
if (DFTs.C < 1) { s.C(); DFTs.C = -1; return; }
|
||||
|
||||
if (!(DFTs.C > 0 && DFTs.O == 0))
|
||||
{
|
||||
s.PI64 = DFTs.O - _DOFT.Header.Length;
|
||||
for (i = 0; i < DFTs.C; i++)
|
||||
{
|
||||
ref DFT dft = ref DFTs.E[i];
|
||||
dft.Flags = (Flags)s.RI32E();
|
||||
dft.Focus = s.RF32E();
|
||||
dft.FocusRange = s.RF32E();
|
||||
dft.FuzzingRange = s.RF32E();
|
||||
dft.Ratio = s.RF32E();
|
||||
dft.Quality = s.RF32E();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IsX = true;
|
||||
s.IsX = true;
|
||||
DFTs.O = (int)s.RI64E();
|
||||
s.PI64 = DFTs.O;
|
||||
for (i = 0; i < DFTs.C; i++)
|
||||
{
|
||||
ref DFT dft = ref DFTs.E[i];
|
||||
dft.Flags = (Flags)s.RI32E();
|
||||
dft.Focus = s.RF32E();
|
||||
dft.FocusRange = s.RF32E();
|
||||
dft.FuzzingRange = s.RF32E();
|
||||
dft.Ratio = s.RF32E();
|
||||
dft.Quality = s.RF32E();
|
||||
dft.Unk = s.RI32 ();
|
||||
}
|
||||
}
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void DFTWriter(string file)
|
||||
{
|
||||
if (DFTs.E == null || DFTs.C < 1) return;
|
||||
|
||||
if (file.EndsWith("_dof"))
|
||||
file = file.Substring(0, file.Length - 4);
|
||||
|
||||
s = File.OpenWriter();
|
||||
s.IsBE = false;
|
||||
s.Format = Format.F2;
|
||||
|
||||
ENRS e = default;
|
||||
POF p = default;
|
||||
p.Offsets = KKdList<long>.New;
|
||||
if (!IsX)
|
||||
{
|
||||
s.W(DFTs.C);
|
||||
s.W(0x50);
|
||||
s.A(0x10);
|
||||
|
||||
for (i = 0; i < DFTs.C; i++)
|
||||
{
|
||||
ref DFT dft = ref DFTs.E[i];
|
||||
s.W((int)dft.Flags);
|
||||
s.W(dft.Focus );
|
||||
s.W(dft.FocusRange );
|
||||
s.W(dft.FuzzingRange);
|
||||
s.W(dft.Ratio );
|
||||
s.W(dft.Quality );
|
||||
}
|
||||
|
||||
e.Array = new ENRS.ENRSEntry[2];
|
||||
e.Array[0] = new ENRS.ENRSEntry(0x00, 0x01, 0x10, 0x01);
|
||||
e.Array[0].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x02, ENRS.ENRSEntry.Type.DWORD);
|
||||
e.Array[1] = new ENRS.ENRSEntry(0x10, 0x01, 0x18, DFTs.C);
|
||||
e.Array[1].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x06, ENRS.ENRSEntry.Type.DWORD);
|
||||
|
||||
p.Offsets.Add(0x44);
|
||||
}
|
||||
else
|
||||
{
|
||||
s.W(DFTs.C);
|
||||
s.A(0x08);
|
||||
s.W(0x10L);
|
||||
s.A(0x10);
|
||||
|
||||
for (i = 0; i < DFTs.C; i++)
|
||||
{
|
||||
ref DFT dft = ref DFTs.E[i];
|
||||
s.W((int)dft.Flags);
|
||||
s.W(dft.Focus );
|
||||
s.W(dft.FocusRange );
|
||||
s.W(dft.FuzzingRange);
|
||||
s.W(dft.Ratio );
|
||||
s.W(dft.Quality );
|
||||
s.W(dft.Unk );
|
||||
}
|
||||
|
||||
e.Array = new ENRS.ENRSEntry[2];
|
||||
e.Array[0] = new ENRS.ENRSEntry(0x00, 0x02, 0x10, 0x01);
|
||||
e.Array[0].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x01, ENRS.ENRSEntry.Type.DWORD);
|
||||
e.Array[0].Sub[1] = new ENRS.ENRSEntry.SubENRSEntry(0x04, 0x01, ENRS.ENRSEntry.Type.QWORD);
|
||||
e.Array[1] = new ENRS.ENRSEntry(0x10, 0x01, 0x1C, DFTs.C);
|
||||
e.Array[1].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x06, ENRS.ENRSEntry.Type.DWORD);
|
||||
|
||||
p.Offsets.Add(0x08);
|
||||
}
|
||||
|
||||
s.A(0x10, true);
|
||||
byte[] data = s.ToArray(true);
|
||||
|
||||
Struct _DOFT = default;
|
||||
_DOFT.Header.Signature = 0x54464F44;
|
||||
_DOFT.Header.DataSize = (uint)data.Length;
|
||||
_DOFT.Header.Length = 0x40;
|
||||
_DOFT.Header.Depth = 0;
|
||||
_DOFT.Header.SectionSize = (uint)data.Length;
|
||||
_DOFT.Header.Version = 0;
|
||||
_DOFT.Header.InnerSignature = 0x03;
|
||||
|
||||
_DOFT.Header.UseBigEndian = false;
|
||||
_DOFT.Header.UseSectionSize = true;
|
||||
_DOFT.Header.Format = Format.F2;
|
||||
_DOFT.Data = data;
|
||||
_DOFT.ENRS = e;
|
||||
_DOFT.POF = p;
|
||||
File.WriteAllBytes(file + ".dft", _DOFT.W(IsX, true));
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
{
|
||||
IsX = false;
|
||||
DFTs = default;
|
||||
|
||||
MsgPack msgPack = file.ReadMPAllAtOnce(json);
|
||||
MsgPack dof;
|
||||
if ((dof = msgPack["DOF", true]).NotNull)
|
||||
{
|
||||
DFTs.E = new DFT[dof.Array.Length];
|
||||
for (i = 0; i < DFTs.C; i++)
|
||||
{
|
||||
ref DFT dft = ref DFTs.E[i];
|
||||
dft = default;
|
||||
MsgPack d = dof[i];
|
||||
MsgPack temp;
|
||||
if ((temp = d["Focus"]).Object != null)
|
||||
{
|
||||
dft.Flags |= Flags.Focus;
|
||||
dft.Focus = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = d["FocusRange"]).Object != null)
|
||||
{
|
||||
dft.Flags |= Flags.FocusRange;
|
||||
dft.FocusRange = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = d["FuzzingRange"]).Object != null)
|
||||
{
|
||||
dft.Flags |= Flags.FuzzingRange;
|
||||
dft.FuzzingRange = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = d["Ratio"]).Object != null)
|
||||
{
|
||||
dft.Flags |= Flags.Ratio;
|
||||
dft.Ratio = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = d["Quality"]).Object != null)
|
||||
{
|
||||
dft.Flags |= Flags.Quality;
|
||||
dft.Quality = temp.RF32();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((dof = msgPack["DOFX", true]).NotNull)
|
||||
{
|
||||
IsX = true;
|
||||
DFTs.E = new DFT[dof.Array.Length];
|
||||
for (i = 0; i < DFTs.C; i++)
|
||||
{
|
||||
ref DFT dft = ref DFTs.E[i];
|
||||
dft = default;
|
||||
MsgPack d = dof[i];
|
||||
MsgPack temp;
|
||||
if ((temp = d["Focus"]).Object != null)
|
||||
{
|
||||
dft.Flags |= Flags.Focus;
|
||||
dft.Focus = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = d["FocusRange"]).Object != null)
|
||||
{
|
||||
dft.Flags |= Flags.FocusRange;
|
||||
dft.FocusRange = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = d["FuzzingRange"]).Object != null)
|
||||
{
|
||||
dft.Flags |= Flags.FuzzingRange;
|
||||
dft.FuzzingRange = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = d["Ratio"]).Object != null)
|
||||
{
|
||||
dft.Flags |= Flags.Ratio;
|
||||
dft.Ratio = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = d["Quality"]).Object != null)
|
||||
{
|
||||
dft.Flags |= Flags.Quality;
|
||||
dft.Quality = temp.RF32();
|
||||
}
|
||||
|
||||
if ((temp = d["Unk"]).Object != null)
|
||||
{
|
||||
dft.Flags |= Flags.Unk;
|
||||
dft.Unk = temp.RI32();
|
||||
}
|
||||
}
|
||||
}
|
||||
dof.Dispose();
|
||||
msgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
if (DFTs.E == null || DFTs.C < 1) return;
|
||||
|
||||
MsgPack dof;
|
||||
if (!IsX)
|
||||
{
|
||||
dof = new MsgPack(DFTs.C, "DOF");
|
||||
for (i = 0; i < DFTs.C; i++)
|
||||
{
|
||||
ref DFT dft = ref DFTs.E[i];
|
||||
MsgPack d = MsgPack.New;
|
||||
if ((dft.Flags & Flags.Focus) != 0)
|
||||
d.Add("Focus", dft.Focus);
|
||||
if ((dft.Flags & Flags.FocusRange) != 0)
|
||||
d.Add("FocusRange", dft.FocusRange);
|
||||
if ((dft.Flags & Flags.FuzzingRange) != 0)
|
||||
d.Add("FuzzingRange", dft.FuzzingRange);
|
||||
if ((dft.Flags & Flags.Ratio) != 0)
|
||||
d.Add("Ratio", dft.Ratio);
|
||||
if ((dft.Flags & Flags.Quality) != 0)
|
||||
d.Add("Quality", dft.Quality);
|
||||
dof[i] = d;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dof = new MsgPack(DFTs.C, "DOFX");
|
||||
for (i = 0; i < DFTs.C; i++)
|
||||
{
|
||||
ref DFT dft = ref DFTs.E[i];
|
||||
MsgPack d = MsgPack.New;
|
||||
if ((dft.Flags & Flags.Focus) != 0)
|
||||
d.Add("Focus", dft.Focus);
|
||||
if ((dft.Flags & Flags.FocusRange) != 0)
|
||||
d.Add("FocusRange", dft.FocusRange);
|
||||
if ((dft.Flags & Flags.FuzzingRange) != 0)
|
||||
d.Add("FuzzingRange", dft.FuzzingRange);
|
||||
if ((dft.Flags & Flags.Ratio) != 0)
|
||||
d.Add("Ratio", dft.Ratio);
|
||||
if ((dft.Flags & Flags.Quality) != 0)
|
||||
d.Add("Quality", dft.Quality);
|
||||
if ((dft.Flags & Flags.Unk) != 0)
|
||||
d.Add("Unk", dft.Unk);
|
||||
dof[i] = d;
|
||||
}
|
||||
}
|
||||
dof.Write(false, true, file + "_dof", json);
|
||||
}
|
||||
|
||||
|
||||
public void TXTWriter(string file)
|
||||
{
|
||||
if (DFTs.C < 1) return;
|
||||
|
||||
s = File.OpenWriter();
|
||||
s.WPSSJIS("ID,Focus,FocusRange,FuzzingRange,Ratio,Quality\n");
|
||||
for (i = 0; i < DFTs.C; i++)
|
||||
s.W($"{i},{DFTs[i]}\n");
|
||||
File.WriteAllBytes($"{file}_dof.txt", s.ToArray(true));
|
||||
}
|
||||
|
||||
private bool disposed;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; DFTs = default; IsX = false; disposed = true; } }
|
||||
|
||||
public struct DFT
|
||||
{
|
||||
public Flags Flags;
|
||||
public float Focus;
|
||||
public float FocusRange;
|
||||
public float FuzzingRange;
|
||||
public float Ratio;
|
||||
public float Quality;
|
||||
public int Unk;
|
||||
|
||||
public override string ToString() =>
|
||||
((Flags & Flags.Focus) != 0
|
||||
? $"{Focus.ToS(6)}," : ",") +
|
||||
((Flags & Flags.FocusRange) != 0
|
||||
? $"{FocusRange.ToS(6)}," : ",") +
|
||||
((Flags & Flags.FuzzingRange) != 0
|
||||
? $"{FuzzingRange.ToS(6)}," : ",") +
|
||||
((Flags & Flags.Ratio) != 0
|
||||
? $"{Ratio.ToS(6)}," : ",") +
|
||||
((Flags & Flags.Quality) != 0
|
||||
? $"{Quality.ToS(6)}" : "");
|
||||
}
|
||||
|
||||
public enum Flags : int
|
||||
{
|
||||
Focus = 0b000001,
|
||||
FocusRange = 0b000010,
|
||||
FuzzingRange = 0b000100,
|
||||
Ratio = 0b001000,
|
||||
Quality = 0b010000,
|
||||
Unk = 0b100000,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,905 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib.F2
|
||||
{
|
||||
public struct Light : System.IDisposable
|
||||
{
|
||||
private int i, i0;
|
||||
private Stream s;
|
||||
|
||||
public bool IsX;
|
||||
public CountPointer<LightStruct> LITs;
|
||||
|
||||
public void LITReader(string file)
|
||||
{
|
||||
IsX = false;
|
||||
LITs = default;
|
||||
byte[] litData = File.ReadAllBytes(file + ".lit");
|
||||
Struct _LITC = litData.RSt(); litData = null;
|
||||
if (_LITC.Header.Signature != 0x4354494C) return;
|
||||
|
||||
s = File.OpenReader(_LITC.Data);
|
||||
s.IsBE = _LITC.Header.UseBigEndian;
|
||||
|
||||
s.RI32();
|
||||
LITs = s.RCPE<LightStruct>();
|
||||
if (LITs.C < 1) { s.C(); LITs.C = -1; return; }
|
||||
|
||||
s.PI64 = LITs.O - _LITC.Header.Length;
|
||||
if (s.RI32() != 0)
|
||||
{
|
||||
s.PI64 = LITs.O - _LITC.Header.Length;
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
LITs.E[i] = new LightStruct
|
||||
{ C0 = s.RI32E(), O0 = s.RI32E() };
|
||||
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
{
|
||||
s.PI64 = LITs.E[i].O0 - _LITC.Header.Length;
|
||||
for (i0 = 0; i0 < LITs.E[i].C0; i0++)
|
||||
{
|
||||
ref LIT lit = ref LITs.E[i].E0[i0];
|
||||
lit.Id = s.RI32E();
|
||||
lit.Flags = (Flags)s.RI32E();
|
||||
lit.Type = (Type )s.RI32E();
|
||||
lit.Ambient .X = s.RF32E();
|
||||
lit.Ambient .Y = s.RF32E();
|
||||
lit.Ambient .Z = s.RF32E();
|
||||
lit.Ambient .W = s.RF32E();
|
||||
lit.Diffuse .X = s.RF32E();
|
||||
lit.Diffuse .Y = s.RF32E();
|
||||
lit.Diffuse .Z = s.RF32E();
|
||||
lit.Diffuse .W = s.RF32E();
|
||||
lit.Specular .X = s.RF32E();
|
||||
lit.Specular .Y = s.RF32E();
|
||||
lit.Specular .Z = s.RF32E();
|
||||
lit.Specular .W = s.RF32E();
|
||||
lit.Position .X = s.RF32E();
|
||||
lit.Position .Y = s.RF32E();
|
||||
lit.Position .Z = s.RF32E();
|
||||
lit.ToneCurve.X = s.RF32E();
|
||||
lit.ToneCurve.Y = s.RF32E();
|
||||
lit.ToneCurve.Z = s.RF32E();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
IsX = true;
|
||||
s.PI64 = LITs.O;
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
LITs.E[i] = new LightStruct
|
||||
{ C0 = s.RI32E(), C1 = s.RI32E(), O0 = (int)s.RI64E(), O1 = (int)s.RI64E() };
|
||||
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
{
|
||||
s.P = LITs.E[i].O0;
|
||||
for (i0 = 0; i0 < LITs.E[i].C0; i0++)
|
||||
{
|
||||
ref LIT lit = ref LITs.E[i].E0[i0];
|
||||
lit.Id = s.RI32E();
|
||||
lit.Flags = (Flags)s.RI32E();
|
||||
lit.Type = (Type )s.RI32E();
|
||||
s.RI32();
|
||||
long off = s.RI64();
|
||||
lit.HasStr = s.RI64() != 0;
|
||||
lit.Unk10 = s.RI32();
|
||||
lit.Ambient .X = s.RF32E();
|
||||
lit.Ambient .Y = s.RF32E();
|
||||
lit.Ambient .Z = s.RF32E();
|
||||
lit.Ambient .W = s.RF32E();
|
||||
lit.Diffuse .X = s.RF32E();
|
||||
lit.Diffuse .Y = s.RF32E();
|
||||
lit.Diffuse .Z = s.RF32E();
|
||||
lit.Diffuse .W = s.RF32E();
|
||||
lit.Specular .X = s.RF32E();
|
||||
lit.Specular .Y = s.RF32E();
|
||||
lit.Specular .Z = s.RF32E();
|
||||
lit.Specular .W = s.RF32E();
|
||||
lit.Position .X = s.RF32E();
|
||||
lit.Position .Y = s.RF32E();
|
||||
lit.Position .Z = s.RF32E();
|
||||
lit.Unk01 = s.RF32();
|
||||
lit.Unk02 = s.RF32();
|
||||
lit.Unk03 = s.RF32();
|
||||
lit.Unk04 = s.RF32();
|
||||
lit.Unk05.X = s.RF32();
|
||||
lit.Unk05.Y = s.RF32();
|
||||
lit.Unk05.Z = s.RF32();
|
||||
lit.ToneCurve.X = s.RF32E();
|
||||
lit.ToneCurve.Y = s.RF32E();
|
||||
lit.ToneCurve.Z = s.RF32E();
|
||||
lit.Unk = s.RF32();
|
||||
lit.Unk06 = s.RF32();
|
||||
lit.Unk07 = s.RF32();
|
||||
lit.Unk08 = s.RF32();
|
||||
|
||||
lit.Str = off > 0 ? s.RaO(off).ToSJIS() : "";
|
||||
}
|
||||
|
||||
s.P = LITs.E[i].O1;
|
||||
for (i0 = 0; i0 < LITs.E[i].C1; i0++)
|
||||
{
|
||||
ref LITX lit = ref LITs.E[i].E1[i0];
|
||||
lit.C = s.RI32E();
|
||||
s.RI32E();
|
||||
lit.O = (int)s.RI64E();
|
||||
}
|
||||
|
||||
for (i0 = 0; i0 < LITs.E[i].C1; i0++)
|
||||
{
|
||||
ref LITX lit = ref LITs.E[i].E1[i0];
|
||||
ref KeyValuePair<int, int>[] data = ref lit.E;
|
||||
data = new KeyValuePair<int, int>[lit.C];
|
||||
|
||||
s.P = lit.O;
|
||||
for (int i1 = 0; i1 < lit.C; i1++)
|
||||
data[i1] = new KeyValuePair<int, int>(s.RI32E(), s.RI32E());
|
||||
}
|
||||
}
|
||||
}
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void LITWriter(string file)
|
||||
{
|
||||
if (LITs.E == null || LITs.C < 1) return;
|
||||
|
||||
if (file.EndsWith("_light"))
|
||||
file = file.Substring(0, file.Length - 6);
|
||||
|
||||
s = File.OpenWriter();
|
||||
s.IsBE = false;
|
||||
s.Format = Format.F2;
|
||||
|
||||
ENRS e = default;
|
||||
POF p = default;
|
||||
p.Offsets = KKdList<long>.New;
|
||||
if (!IsX)
|
||||
{
|
||||
s.W(0x02);
|
||||
s.W(LITs.C);
|
||||
s.W(0x50);
|
||||
s.A(0x10);
|
||||
|
||||
int offset0 = 0x50 + (LITs.C * 0x08).A(0x10);
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
{
|
||||
s.W(LITs.E[i].C0 > 0 ? LITs.E[i].C0 : 0);
|
||||
s.W(LITs.E[i].C0 > 0 ? offset0 : 0);
|
||||
offset0 += (0x54 * (LITs.E[i].C0 > 0 ? LITs.E[i].C0 : 0)).A(0x10);
|
||||
}
|
||||
s.A(0x10);
|
||||
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
{
|
||||
for (i0 = 0; i0 < LITs.E[i].C0; i0++)
|
||||
{
|
||||
ref LIT lit = ref LITs.E[i].E0[i0];
|
||||
s.W( lit.Id );
|
||||
s.W((int)lit.Flags);
|
||||
s.W((int)lit.Type );
|
||||
s.W(lit.Ambient .X);
|
||||
s.W(lit.Ambient .Y);
|
||||
s.W(lit.Ambient .Z);
|
||||
s.W(lit.Ambient .W);
|
||||
s.W(lit.Diffuse .X);
|
||||
s.W(lit.Diffuse .Y);
|
||||
s.W(lit.Diffuse .Z);
|
||||
s.W(lit.Diffuse .W);
|
||||
s.W(lit.Specular .X);
|
||||
s.W(lit.Specular .Y);
|
||||
s.W(lit.Specular .Z);
|
||||
s.W(lit.Specular .W);
|
||||
s.W(lit.Position .X);
|
||||
s.W(lit.Position .Y);
|
||||
s.W(lit.Position .Z);
|
||||
s.W(lit.ToneCurve.X);
|
||||
s.W(lit.ToneCurve.Y);
|
||||
s.W(lit.ToneCurve.Z);
|
||||
}
|
||||
s.A(0x10);
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
if (LITs.E[i].C0 > 0)
|
||||
count += LITs.E[i].C0;
|
||||
|
||||
e.Array = new ENRS.ENRSEntry[3];
|
||||
e.Array[0] = new ENRS.ENRSEntry(0x00, 0x01, 0x10, 0x01);
|
||||
e.Array[0].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x03, ENRS.ENRSEntry.Type.DWORD);
|
||||
e.Array[1] = new ENRS.ENRSEntry(0x10, 0x01, 0x08, LITs.C);
|
||||
e.Array[1].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x02, ENRS.ENRSEntry.Type.DWORD);
|
||||
e.Array[2] = new ENRS.ENRSEntry((LITs.C * 0x08).A(0x10), 0x01, 0x54, count);
|
||||
e.Array[2].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x15, ENRS.ENRSEntry.Type.DWORD);
|
||||
|
||||
p.Offsets.Add(0x48);
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
p.Offsets.Add(0x54 + 0x08 * i);
|
||||
}
|
||||
else
|
||||
{
|
||||
long offset0 = 0x50 + (LITs.C * 0x18).A(0x10);
|
||||
long offset1 = offset0;
|
||||
long offset2 = offset0 + 0x10;
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
offset1 += LITs.E[i].C0 * 0x98;
|
||||
offset1 = offset1.A(0x10);
|
||||
|
||||
long offset3 = offset1;
|
||||
long offset4 = offset1 + 0x08;
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
offset3 += LITs.E[i].C1 * 0x10;
|
||||
offset3 = offset3.A(0x10);
|
||||
long offset5 = offset3;
|
||||
long offset6 = offset3;
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
for (i0 = 0; i0 < LITs.E[i].C1; i0++)
|
||||
offset6 += LITs.E[i].E1[i0].C * 0x08;
|
||||
|
||||
byte[][][] strdata = new byte[LITs.C][][];
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
{
|
||||
strdata[i] = new byte[LITs.E[i].C0][];
|
||||
for (i0 = 0; i0 < LITs.E[i].C0; i0++)
|
||||
{
|
||||
ref LIT lit = ref LITs.E[i].E0[i0];
|
||||
strdata[i][i0] = lit.HasStr && lit.Str != null && lit.Str != "" ? lit.Str.ToSJIS() : null;
|
||||
}
|
||||
}
|
||||
|
||||
s.W(0x02);
|
||||
s.W(LITs.C);
|
||||
s.W(0x50L);
|
||||
s.A(0x10);
|
||||
s.P = 0x50;
|
||||
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
{
|
||||
s.W(LITs.E[i].C0 > 0 ? LITs.E[i].C0 : 0);
|
||||
s.W(LITs.E[i].C1 > 0 ? LITs.E[i].C1 : 0);
|
||||
s.W(LITs.E[i].C0 > 0 ? offset0 : 0);
|
||||
s.W(LITs.E[i].C1 > 0 ? offset1 : 0);
|
||||
offset0 += 0x98 * (LITs.E[i].C0 > 0 ? LITs.E[i].C0 : 0);
|
||||
offset1 += 0x10 * (LITs.E[i].C1 > 0 ? LITs.E[i].C1 : 0);
|
||||
}
|
||||
s.A(0x10);
|
||||
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
for (i0 = 0; i0 < LITs.E[i].C0; i0++)
|
||||
{
|
||||
ref LIT lit = ref LITs.E[i].E0[i0];
|
||||
s.W( lit.Id );
|
||||
s.W((int)lit.Flags);
|
||||
s.W((int)lit.Type );
|
||||
s.W((int)0);
|
||||
if (lit.HasStr && strdata[i][i0] != null && strdata[i][i0].Length > 0)
|
||||
{ s.W(offset6); s.W((long)strdata[i][i0].HashMurmurHash(strdata[i][i0].Length));
|
||||
offset6 += strdata[i][i0].Length + 1; }
|
||||
else
|
||||
{ s.W(0x00L); s.W((long)(lit.HasStr ? 0x0CAD3078 : 0)); }
|
||||
s.W(lit.Unk10 );
|
||||
s.W(lit.Ambient .X);
|
||||
s.W(lit.Ambient .Y);
|
||||
s.W(lit.Ambient .Z);
|
||||
s.W(lit.Ambient .W);
|
||||
s.W(lit.Diffuse .X);
|
||||
s.W(lit.Diffuse .Y);
|
||||
s.W(lit.Diffuse .Z);
|
||||
s.W(lit.Diffuse .W);
|
||||
s.W(lit.Specular .X);
|
||||
s.W(lit.Specular .Y);
|
||||
s.W(lit.Specular .Z);
|
||||
s.W(lit.Specular .W);
|
||||
s.W(lit.Position .X);
|
||||
s.W(lit.Position .Y);
|
||||
s.W(lit.Position .Z);
|
||||
s.W(lit.Unk01 );
|
||||
s.W(lit.Unk02 );
|
||||
s.W(lit.Unk03 );
|
||||
s.W(lit.Unk04 );
|
||||
s.W(lit.Unk05.X );
|
||||
s.W(lit.Unk05.Y );
|
||||
s.W(lit.Unk05.Z );
|
||||
s.W(lit.ToneCurve.X);
|
||||
s.W(lit.ToneCurve.Y);
|
||||
s.W(lit.ToneCurve.Z);
|
||||
s.W(lit.Unk );
|
||||
s.W(lit.Unk06 );
|
||||
s.W(lit.Unk07 );
|
||||
s.W(lit.Unk08 );
|
||||
}
|
||||
s.A(0x10);
|
||||
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
for (i0 = 0; i0 < LITs.E[i].C1; i0++)
|
||||
{
|
||||
ref LITX lit = ref LITs.E[i].E1[i0];
|
||||
s.W(lit.C);
|
||||
s.W((int)0);
|
||||
s.W(offset5);
|
||||
offset5 += lit.C * 0x08;
|
||||
}
|
||||
s.A(0x10);
|
||||
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
for (i0 = 0; i0 < LITs.E[i].C1; i0++)
|
||||
{
|
||||
ref LITX lit = ref LITs.E[i].E1[i0];
|
||||
for (int i1 = 0; i1 < lit.C; i1++)
|
||||
{
|
||||
s.W(lit.E[i1].Key);
|
||||
s.W(lit.E[i1].Value);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
for (i0 = 0; i0 < LITs.E[i].C0; i0++)
|
||||
{
|
||||
ref LIT lit = ref LITs.E[i].E0[i0];
|
||||
if (lit.HasStr && strdata[i][i0] != null && strdata[i][i0].Length > 0)
|
||||
{
|
||||
s.W(strdata[i][i0]);
|
||||
s.W((byte)0);
|
||||
}
|
||||
}
|
||||
s.A(0x10);
|
||||
|
||||
bool sub = false;
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
if (LITs.E[i].C1 > 0) { sub = true; break; }
|
||||
|
||||
int count = 0;
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
if (LITs.E[i].C0 > 0)
|
||||
count += LITs.E[i].C0;
|
||||
|
||||
e.Array = new ENRS.ENRSEntry[sub ? 5 : 3];
|
||||
e.Array[0] = new ENRS.ENRSEntry(0x00, 0x02, 0x50, 0x01);
|
||||
e.Array[0].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x02, ENRS.ENRSEntry.Type.DWORD);
|
||||
e.Array[0].Sub[1] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x01, ENRS.ENRSEntry.Type.QWORD);
|
||||
e.Array[1] = new ENRS.ENRSEntry(0x50, 0x02, 0x18, LITs.C);
|
||||
e.Array[1].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x02, ENRS.ENRSEntry.Type.DWORD);
|
||||
e.Array[1].Sub[1] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x02, ENRS.ENRSEntry.Type.QWORD);
|
||||
e.Array[2] = new ENRS.ENRSEntry((LITs.C * 0x18).A(0x10), 0x03, 0x98, count);
|
||||
e.Array[2].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x03, ENRS.ENRSEntry.Type.DWORD);
|
||||
e.Array[2].Sub[1] = new ENRS.ENRSEntry.SubENRSEntry(0x18, 0x0F, ENRS.ENRSEntry.Type.DWORD);
|
||||
e.Array[2].Sub[2] = new ENRS.ENRSEntry.SubENRSEntry(0x20, 0x03, ENRS.ENRSEntry.Type.DWORD);
|
||||
if (sub)
|
||||
{
|
||||
int sub_count = 0;
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
if (LITs.E[i].C1 > 0)
|
||||
sub_count += LITs.E[i].C1;
|
||||
|
||||
e.Array[3] = new ENRS.ENRSEntry((count * 0x98).A(0x10), 0x02, 0x10, sub_count);
|
||||
e.Array[3].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x01, ENRS.ENRSEntry.Type.DWORD);
|
||||
e.Array[3].Sub[1] = new ENRS.ENRSEntry.SubENRSEntry(0x04, 0x01, ENRS.ENRSEntry.Type.QWORD);
|
||||
e.Array[4] = new ENRS.ENRSEntry(sub_count * 0x10, 0x01, 0x08, LITs.E[0].E1[0].C);
|
||||
e.Array[4].Sub[0] = new ENRS.ENRSEntry.SubENRSEntry(0x00, 0x02, ENRS.ENRSEntry.Type.DWORD);
|
||||
}
|
||||
|
||||
p.Offsets.Add(0x08);
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
{
|
||||
if (LITs.E[i].C0 > 0)
|
||||
p.Offsets.Add(0x58 + 0x18 * i);
|
||||
if (LITs.E[i].C1 > 0)
|
||||
p.Offsets.Add(0x60 + 0x18 * i);
|
||||
}
|
||||
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
for (i0 = 0; i0 < LITs.E[i].C0; i0++)
|
||||
{
|
||||
ref LIT lit = ref LITs.E[i].E0[i0];
|
||||
if (lit.HasStr && strdata[i][i0] != null && strdata[i][i0].Length > 0)
|
||||
p.Offsets.Add(offset2);
|
||||
offset2 += 0x98;
|
||||
}
|
||||
|
||||
if (sub)
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
for (i0 = 0; i0 < LITs.E[i].C1; i0++)
|
||||
{
|
||||
p.Offsets.Add(offset4);
|
||||
offset4 += 0x10;
|
||||
}
|
||||
}
|
||||
|
||||
s.A(0x10, true);
|
||||
byte[] data = s.ToArray(true);
|
||||
|
||||
Struct _LITC = default;
|
||||
_LITC.Header.Signature = 0x4354494C;
|
||||
_LITC.Header.DataSize = (uint)data.Length;
|
||||
_LITC.Header.Length = 0x40;
|
||||
_LITC.Header.Depth = 0;
|
||||
_LITC.Header.SectionSize = (uint)data.Length;
|
||||
_LITC.Header.Version = 0;
|
||||
_LITC.Header.InnerSignature = 0x02;
|
||||
|
||||
_LITC.Header.UseBigEndian = false;
|
||||
_LITC.Header.UseSectionSize = true;
|
||||
_LITC.Header.Format = Format.F2;
|
||||
_LITC.Data = data;
|
||||
_LITC.ENRS = e;
|
||||
_LITC.POF = p;
|
||||
File.WriteAllBytes(file + ".lit", _LITC.W(IsX, true));
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
{
|
||||
IsX = false;
|
||||
LITs = default;
|
||||
|
||||
MsgPack msgPack = file.ReadMPAllAtOnce(json);
|
||||
MsgPack light;
|
||||
if ((light = msgPack["Light", true]).NotNull)
|
||||
{
|
||||
LITs.E = new LightStruct[light.Array.Length];
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
{
|
||||
ref LightStruct lit = ref LITs.E[i];
|
||||
lit = default;
|
||||
MsgPack l = light[i];
|
||||
MsgPack l0;
|
||||
if ((l0 = l["MainData", true]).IsNull)
|
||||
continue;
|
||||
|
||||
lit.C0 = l0.Array.Length;
|
||||
for (i0 = 0; i0 < lit.C0; i0++)
|
||||
{
|
||||
ref LIT lit0 = ref lit.E0[i0];
|
||||
MsgPack l1 = l0[i0];
|
||||
MsgPack temp;
|
||||
if ((temp = l1["Id"]).Object != null)
|
||||
lit0.Id = temp.RI32();
|
||||
|
||||
if ((temp = l1["Type"]).Object != null)
|
||||
{
|
||||
lit0.Flags |= Flags.Type;
|
||||
lit0.Type = (Type)temp.RI32();
|
||||
}
|
||||
|
||||
if ((temp = l1["Str"]).Object != null)
|
||||
{
|
||||
lit0.HasStr = true;
|
||||
lit0.Str = temp.RS();
|
||||
}
|
||||
|
||||
if ((temp = l1["Ambient"]).Object != null)
|
||||
{
|
||||
lit0.Flags |= Flags.Ambient;
|
||||
lit0.Ambient.X = temp.RF32("R");
|
||||
lit0.Ambient.Y = temp.RF32("G");
|
||||
lit0.Ambient.Z = temp.RF32("B");
|
||||
lit0.Ambient.W = temp.RF32("A");
|
||||
}
|
||||
|
||||
if ((temp = l1["Diffuse"]).Object != null)
|
||||
{
|
||||
lit0.Flags |= Flags.Diffuse;
|
||||
lit0.Diffuse.X = temp.RF32("R");
|
||||
lit0.Diffuse.Y = temp.RF32("G");
|
||||
lit0.Diffuse.Z = temp.RF32("B");
|
||||
lit0.Diffuse.W = temp.RF32("A");
|
||||
}
|
||||
|
||||
if ((temp = l1["Specular"]).Object != null)
|
||||
{
|
||||
lit0.Flags |= Flags.Specular;
|
||||
lit0.Specular.X = temp.RF32("R");
|
||||
lit0.Specular.Y = temp.RF32("G");
|
||||
lit0.Specular.Z = temp.RF32("B");
|
||||
lit0.Specular.W = temp.RF32("A");
|
||||
}
|
||||
|
||||
if ((temp = l1["Position"]).Object != null)
|
||||
{
|
||||
lit0.Flags |= Flags.Position;
|
||||
lit0.Position.X = temp.RF32("X");
|
||||
lit0.Position.Y = temp.RF32("Y");
|
||||
lit0.Position.Z = temp.RF32("Z");
|
||||
}
|
||||
|
||||
if ((temp = l1["ToneCurve"]).Object != null)
|
||||
{
|
||||
lit0.Flags |= Flags.ToneCurve;
|
||||
lit0.ToneCurve.X = temp.RF32("Begin" );
|
||||
lit0.ToneCurve.Y = temp.RF32("End" );
|
||||
lit0.ToneCurve.Z = temp.RF32("BlendRate");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((light = msgPack["LightX", true]).NotNull)
|
||||
{
|
||||
IsX = true;
|
||||
LITs.E = new LightStruct[light.Array.Length];
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
{
|
||||
ref LightStruct lit = ref LITs.E[i];
|
||||
lit = default;
|
||||
MsgPack l = light[i];
|
||||
MsgPack l0;
|
||||
if ((l0 = l["MainData", true]).IsNull)
|
||||
continue;
|
||||
|
||||
lit.C0 = l0.Array.Length;
|
||||
for (i0 = 0; i0 < lit.C0; i0++)
|
||||
{
|
||||
ref LIT lit0 = ref lit.E0[i0];
|
||||
lit0 = default;
|
||||
MsgPack l1;
|
||||
if ((l1 = l0[i0]).IsNull)
|
||||
continue;
|
||||
|
||||
MsgPack temp;
|
||||
if ((temp = l1["Id"]).Object != null)
|
||||
lit0.Id = temp.RI32();
|
||||
|
||||
if ((temp = l1["Flags"]).Object != null)
|
||||
lit0.Flags = (Flags)temp.RI32();
|
||||
|
||||
if ((temp = l1["Type"]).Object != null)
|
||||
lit0.Type = (Type)temp.RI32();
|
||||
|
||||
if ((temp = l1["Ambient"]).Object != null)
|
||||
{
|
||||
lit0.Ambient.X = temp.RF32("R");
|
||||
lit0.Ambient.Y = temp.RF32("G");
|
||||
lit0.Ambient.Z = temp.RF32("B");
|
||||
lit0.Ambient.W = temp.RF32("A");
|
||||
}
|
||||
|
||||
if ((temp = l1["Diffuse"]).Object != null)
|
||||
{
|
||||
lit0.Diffuse.X = temp.RF32("R");
|
||||
lit0.Diffuse.Y = temp.RF32("G");
|
||||
lit0.Diffuse.Z = temp.RF32("B");
|
||||
lit0.Diffuse.W = temp.RF32("A");
|
||||
}
|
||||
|
||||
if ((temp = l1["Specular"]).Object != null)
|
||||
{
|
||||
lit0.Specular.X = temp.RF32("R");
|
||||
lit0.Specular.Y = temp.RF32("G");
|
||||
lit0.Specular.Z = temp.RF32("B");
|
||||
lit0.Specular.W = temp.RF32("A");
|
||||
}
|
||||
|
||||
if ((temp = l1["Position"]).Object != null)
|
||||
{
|
||||
lit0.Position.X = temp.RF32("X");
|
||||
lit0.Position.Y = temp.RF32("Y");
|
||||
lit0.Position.Z = temp.RF32("Z");
|
||||
}
|
||||
|
||||
if ((temp = l1["ToneCurve"]).Object != null)
|
||||
lit0.ToneCurve.X = temp.RF32("Begin" );
|
||||
lit0.ToneCurve.Y = temp.RF32("End" );
|
||||
lit0.ToneCurve.Z = temp.RF32("BlendRate");
|
||||
|
||||
if ((temp = l1["Str"]).Object != null)
|
||||
{
|
||||
lit0.HasStr = true;
|
||||
lit0.Str = temp.RS();
|
||||
}
|
||||
|
||||
if ((temp = l1["Unk01"]).Object != null)
|
||||
lit0.Unk01 = temp.RF32();
|
||||
|
||||
if ((temp = l1["Unk02"]).Object != null)
|
||||
lit0.Unk02 = temp.RF32();
|
||||
|
||||
if ((temp = l1["Unk03"]).Object != null)
|
||||
lit0.Unk03 = temp.RF32();
|
||||
|
||||
if ((temp = l1["Unk04"]).Object != null)
|
||||
lit0.Unk04 = temp.RF32();
|
||||
|
||||
if ((temp = l1["Unk05"]).Object != null)
|
||||
lit0.Unk05.X = temp.RF32("X");
|
||||
lit0.Unk05.Y = temp.RF32("Y");
|
||||
lit0.Unk05.Z = temp.RF32("Z");
|
||||
|
||||
if ((temp = l1["Unk06"]).Object != null)
|
||||
lit0.Unk06 = temp.RF32();
|
||||
|
||||
if ((temp = l1["Unk07"]).Object != null)
|
||||
lit0.Unk07 = temp.RF32();
|
||||
|
||||
if ((temp = l1["Unk08"]).Object != null)
|
||||
lit0.Unk08 = temp.RF32();
|
||||
|
||||
if ((temp = l1["Unk10"]).Object != null)
|
||||
lit0.Unk10 = temp.RI32();
|
||||
|
||||
if ((temp = l1["Unk"]).Object != null)
|
||||
lit0.Unk = temp.RF32();
|
||||
}
|
||||
|
||||
if ((l0 = l["SubData", true]).IsNull)
|
||||
continue;
|
||||
|
||||
lit.C1 = l0.Array.Length;
|
||||
for (i0 = 0; i0 < lit.C1; i0++)
|
||||
{
|
||||
ref LITX lit1 = ref lit.E1[i0];
|
||||
lit1 = default;
|
||||
MsgPack l1;
|
||||
if ((l1 = l0[i0]).IsNull && l1.Array != null)
|
||||
continue;
|
||||
|
||||
lit1.C = l1.Array.Length;
|
||||
lit1.E = new KeyValuePair<int, int>[lit1.C];
|
||||
for (int i1 = 0; i1 < lit1.C; i1++)
|
||||
{
|
||||
lit1.E[i1] = default;
|
||||
MsgPack l2 = l1[i1];
|
||||
MsgPack temp;
|
||||
if ((temp = l2["Key"]).Object != null)
|
||||
lit1.E[i1].Key = temp.RI32();
|
||||
|
||||
if ((temp = l2["Value"]).Object != null)
|
||||
lit1.E[i1].Value = temp.RI32();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
light.Dispose();
|
||||
msgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
if (LITs.E == null || LITs.C < 1) return;
|
||||
|
||||
MsgPack light;
|
||||
if (!IsX)
|
||||
{
|
||||
light = new MsgPack(LITs.C, "Light");
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
{
|
||||
ref LightStruct lit = ref LITs.E[i];
|
||||
MsgPack l = MsgPack.New;
|
||||
MsgPack l0 = new MsgPack(lit.C0, "MainData");
|
||||
for (i0 = 0; i0 < lit.C0; i0++)
|
||||
{
|
||||
ref LIT lit0 = ref lit.E0[i0];
|
||||
MsgPack l1 = MsgPack.New;
|
||||
l1.Add("Id", lit0.Id);
|
||||
if ((lit0.Flags & Flags.Type) != 0)
|
||||
l1.Add("Type", (int)lit0.Type);
|
||||
if ((lit0.Flags & Flags.Ambient) != 0)
|
||||
l1.Add(new MsgPack("Ambient")
|
||||
.Add("R", lit0.Ambient.X)
|
||||
.Add("G", lit0.Ambient.Y)
|
||||
.Add("B", lit0.Ambient.Z)
|
||||
.Add("A", lit0.Ambient.W));
|
||||
if ((lit0.Flags & Flags.Diffuse) != 0)
|
||||
l1.Add(new MsgPack("Diffuse")
|
||||
.Add("R", lit0.Diffuse.X)
|
||||
.Add("G", lit0.Diffuse.Y)
|
||||
.Add("B", lit0.Diffuse.Z)
|
||||
.Add("A", lit0.Diffuse.W));
|
||||
if ((lit0.Flags & Flags.Specular) != 0)
|
||||
l1.Add(new MsgPack("Specular")
|
||||
.Add("R", lit0.Specular.X)
|
||||
.Add("G", lit0.Specular.Y)
|
||||
.Add("B", lit0.Specular.Z)
|
||||
.Add("A", lit0.Specular.W));
|
||||
if ((lit0.Flags & Flags.Position) != 0)
|
||||
l1.Add(new MsgPack("Position")
|
||||
.Add("X", lit0.Position.X)
|
||||
.Add("Y", lit0.Position.Y)
|
||||
.Add("Z", lit0.Position.Z));
|
||||
if ((lit0.Flags & Flags.ToneCurve) != 0)
|
||||
l1.Add(new MsgPack("ToneCurve")
|
||||
.Add("Begin" , lit0.ToneCurve.X)
|
||||
.Add("End" , lit0.ToneCurve.Y)
|
||||
.Add("BlendRate", lit0.ToneCurve.Z));
|
||||
l0[i0] = l1;
|
||||
}
|
||||
l.Add(l0);
|
||||
light[i] = l;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
light = new MsgPack(LITs.C, "LightX");
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
{
|
||||
ref LightStruct lit = ref LITs.E[i];
|
||||
MsgPack l = MsgPack.New;
|
||||
MsgPack l0 = new MsgPack(lit.C0, "MainData");
|
||||
for (i0 = 0; i0 < lit.C0; i0++)
|
||||
{
|
||||
ref LIT lit0 = ref lit.E0[i0];
|
||||
MsgPack l1 = MsgPack.New;
|
||||
l1.Add("Id", lit0.Id);
|
||||
l1.Add("Flags", (int)lit0.Flags);
|
||||
l1.Add("Type", (int)lit0.Type);
|
||||
l1.Add(new MsgPack("Ambient")
|
||||
.Add("R", lit0.Ambient.X)
|
||||
.Add("G", lit0.Ambient.Y)
|
||||
.Add("B", lit0.Ambient.Z)
|
||||
.Add("A", lit0.Ambient.W));
|
||||
l1.Add(new MsgPack("Diffuse")
|
||||
.Add("R", lit0.Diffuse.X)
|
||||
.Add("G", lit0.Diffuse.Y)
|
||||
.Add("B", lit0.Diffuse.Z)
|
||||
.Add("A", lit0.Diffuse.W));
|
||||
l1.Add(new MsgPack("Specular")
|
||||
.Add("R", lit0.Specular.X)
|
||||
.Add("G", lit0.Specular.Y)
|
||||
.Add("B", lit0.Specular.Z)
|
||||
.Add("A", lit0.Specular.W));
|
||||
l1.Add(new MsgPack("Position")
|
||||
.Add("X", lit0.Position.X)
|
||||
.Add("Y", lit0.Position.Y)
|
||||
.Add("Z", lit0.Position.Z));
|
||||
l1.Add(new MsgPack("ToneCurve")
|
||||
.Add("Begin" , lit0.ToneCurve.X)
|
||||
.Add("End" , lit0.ToneCurve.Y)
|
||||
.Add("BlendRate", lit0.ToneCurve.Z));
|
||||
|
||||
if (lit0.HasStr)
|
||||
l1.Add("Str", lit0.Str ?? "");
|
||||
l1.Add("Unk01", lit0.Unk01);
|
||||
l1.Add("Unk02", lit0.Unk02);
|
||||
l1.Add("Unk03", lit0.Unk03);
|
||||
l1.Add("Unk04", lit0.Unk04);
|
||||
l1.Add(new MsgPack("Unk05")
|
||||
.Add("X", lit0.Unk05.X)
|
||||
.Add("Y", lit0.Unk05.Y)
|
||||
.Add("Z", lit0.Unk05.Z));
|
||||
l1.Add("Unk06", lit0.Unk06);
|
||||
l1.Add("Unk07", lit0.Unk07);
|
||||
l1.Add("Unk08", lit0.Unk08);
|
||||
l1.Add("Unk10", lit0.Unk10);
|
||||
l1.Add("Unk", lit0.Unk);
|
||||
l0[i0] = l1;
|
||||
}
|
||||
l.Add(l0);
|
||||
|
||||
if (lit.C1 > 0)
|
||||
{
|
||||
l0 = new MsgPack(lit.C1, "SubData");
|
||||
for (i0 = 0; i0 < lit.C1; i0++)
|
||||
{
|
||||
ref LITX lit1 = ref lit.E1[i0];
|
||||
MsgPack l1 = new MsgPack(lit1.C);
|
||||
for (int i1 = 0; i1 < lit1.C; i1++)
|
||||
l1[i1] = MsgPack.New
|
||||
.Add("Key" , lit1.E[i1].Key )
|
||||
.Add("Value", lit1.E[i1].Value);
|
||||
l0[i0] = l1;
|
||||
}
|
||||
l.Add(l0);
|
||||
}
|
||||
light[i] = l;
|
||||
}
|
||||
}
|
||||
light.Write(false, true, file + "_light", json);
|
||||
}
|
||||
|
||||
public void TXTWriter(string file)
|
||||
{
|
||||
i = 0;
|
||||
if (LITs.C < 1) return;
|
||||
|
||||
s = File.OpenWriter();
|
||||
s.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.E[i].C0; i0++)
|
||||
s.W($"{LITs.E[i].E0[i0]},{i}\n");
|
||||
File.WriteAllBytes($"{file}_light.txt", s.ToArray(true));
|
||||
}
|
||||
|
||||
private bool disposed;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; LITs = default; IsX = false; disposed = true; } }
|
||||
|
||||
public struct LightStruct
|
||||
{
|
||||
public int C0 { get => E0 != null ? E0.Length : 0;
|
||||
set => E0 = value > -1 ? new LIT[value] : null; }
|
||||
public int O0;
|
||||
public LIT[] E0;
|
||||
|
||||
public int C1 { get => E1 != null ? E1.Length : 0;
|
||||
set => E1 = value > -1 ? new LITX[value] : default; }
|
||||
public int O1;
|
||||
public LITX[] E1;
|
||||
|
||||
public LIT this[int index]
|
||||
{ get => E0 != null && index > -1 && index < E0.LongLength ? E0[index] : default;
|
||||
set { if (E0 != null && index > -1 && index < E0.LongLength) E0[index] = value; } }
|
||||
|
||||
public LITX this[int index, bool x]
|
||||
{ get => E1 != null && index > -1 && index < E1.LongLength ? E1[index] : default;
|
||||
set { if (E1 != null && index > -1 && index < E1.LongLength) E1[index] = value; } }
|
||||
|
||||
public override string ToString() => C0 < 1 ? "No Entries" :
|
||||
C0 == 1 ? E0[0].ToString() : "Count: " + C0;
|
||||
}
|
||||
|
||||
public struct LIT
|
||||
{
|
||||
public int Id;
|
||||
public Flags Flags;
|
||||
public Type Type;
|
||||
public string Str;
|
||||
public bool HasStr;
|
||||
public Vec4 Ambient;
|
||||
public Vec4 Diffuse;
|
||||
public Vec4 Specular;
|
||||
public Vec3 Position;
|
||||
public float Unk01;
|
||||
public float Unk02;
|
||||
public float Unk03;
|
||||
public float Unk04;
|
||||
public Vec3 Unk05;
|
||||
public Vec3 ToneCurve;
|
||||
public float Unk;
|
||||
public float Unk06;
|
||||
public float Unk07;
|
||||
public float Unk08;
|
||||
public int Unk10;
|
||||
|
||||
public override string ToString() => Flags == 0 ? ",,,,,,,,,,,,,,,," : $"{(Type)Type}," +
|
||||
((Flags & Flags.Ambient ) != 0
|
||||
? $"{Ambient .X.ToS(6)},{Ambient .Y.ToS(6)},{Ambient .Z.ToS(6)}," : ",,,") +
|
||||
((Flags & Flags.Diffuse ) != 0
|
||||
? $"{Diffuse .X.ToS(6)},{Diffuse .Y.ToS(6)},{Diffuse .Z.ToS(6)}," : ",,,") +
|
||||
((Flags & Flags.Specular ) != 0
|
||||
? $"{Specular .X.ToS(6)},{Specular .Y.ToS(6)},{Specular .Z.ToS(6)},{Specular .W.ToS(6)}," : ",,,,") +
|
||||
((Flags & Flags.Position ) != 0
|
||||
? $"{Position .X.ToS(6)},{Position .Y.ToS(6)},{Position .Z.ToS(6)}," : ",,,") +
|
||||
((Flags & Flags.ToneCurve) != 0
|
||||
? $"{ToneCurve.X.ToS(6)},{ToneCurve.Y.ToS(6)},{ToneCurve.Z.ToS(6)}" : ",,");
|
||||
}
|
||||
|
||||
public enum Id : int
|
||||
{
|
||||
CHARA = 0x00,
|
||||
STAGE = 0x01,
|
||||
SUN = 0x02,
|
||||
REFLECT = 0x03,
|
||||
SHADOW = 0x04,
|
||||
CHARA_COLOR = 0x05,
|
||||
CHARA_F = 0x06,
|
||||
PROJECTION = 0x07,
|
||||
}
|
||||
|
||||
public enum Type : int
|
||||
{
|
||||
OFF = 0,
|
||||
PARALLEL = 1,
|
||||
POINT = 2,
|
||||
SPOT = 3,
|
||||
}
|
||||
|
||||
public enum Flags : int
|
||||
{
|
||||
Type = 0b00000000000000001,
|
||||
Ambient = 0b00000000000000010,
|
||||
Diffuse = 0b00000000000000100,
|
||||
Specular = 0b00000000000001000,
|
||||
Position = 0b00000000000010000,
|
||||
ToneCurve = 0b00000001000000000,
|
||||
}
|
||||
}
|
||||
|
||||
public struct LITX
|
||||
{
|
||||
public int C;
|
||||
public int O;
|
||||
public KeyValuePair<int, int>[] E;
|
||||
}
|
||||
}
|
||||
+355
-276
@@ -1,356 +1,435 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using System;
|
||||
using System.IO.Compression;
|
||||
using System.Security.Cryptography;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using MSIO = System.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public class FARC
|
||||
public class FARC : System.IDisposable
|
||||
{
|
||||
public FARC() { Files = new FARCFile[0]; Signature = Farc.FArC; FT = false; }
|
||||
public FARC() => NewFARC();
|
||||
public FARC(string file, bool isDirectory = false)
|
||||
{ if (isDirectory) DirectoryPath = file; else FilePath = file; NewFARC(); }
|
||||
|
||||
public FARCFile[] Files = new FARCFile[0];
|
||||
private void NewFARC() { Files = KKdList<FARCFile>.New; Signature = Farc.FArC; FT = false; }
|
||||
|
||||
public KKdList<FARCFile> Files = KKdList<FARCFile>.New;
|
||||
public Flags FARCFlags;
|
||||
public Farc Signature = Farc.FArC;
|
||||
public bool FT = false;
|
||||
public string FilePath, DirectoryPath;
|
||||
public bool HasFiles => !Files.IsNull || Files.Count > 0;
|
||||
public int CompressionLevel = 12;
|
||||
|
||||
private bool FT = false;
|
||||
private readonly byte[] key = "project_diva.bin".ToASCII();
|
||||
|
||||
private readonly byte[] Key = Text.ToASCII("project_diva.bin");
|
||||
|
||||
private readonly byte[] KeyFT = { 0x13, 0x72, 0xD5, 0x7B, 0x6E, 0x9E,
|
||||
private readonly byte[] keyFT = { 0x13, 0x72, 0xD5, 0x7B, 0x6E, 0x9E,
|
||||
0x31, 0xEB, 0xA2, 0x39, 0xB8, 0x3C, 0x15, 0x57, 0xC6, 0xBB };
|
||||
|
||||
AesManaged GetAes(bool isFT, byte[] iv)
|
||||
{
|
||||
AesManaged AesManaged = new AesManaged { KeySize = 128, Key = isFT ? KeyFT : Key,
|
||||
BlockSize = 128, Mode = isFT ? CipherMode.CBC : CipherMode.ECB,
|
||||
Padding = PaddingMode.Zeros, IV = iv ?? new byte[16] };
|
||||
return AesManaged;
|
||||
}
|
||||
private AesManaged GetAes(byte[] iv = null) =>
|
||||
new AesManaged () { KeySize = 128, Key = iv != null ? keyFT : key,
|
||||
BlockSize = 128, Mode = iv != null ? CipherMode.CBC : CipherMode.ECB,
|
||||
Padding = iv != null ? PaddingMode.PKCS7 : PaddingMode.Zeros, IV = iv ?? new byte[16] };
|
||||
|
||||
public void UnPack(string file, bool SaveToDisk = true)
|
||||
{
|
||||
Files = null;
|
||||
Signature = Farc.FArC;
|
||||
FT = false;
|
||||
Console.Title = "FARC Extractor - Archive: " + Path.GetFileName(file);
|
||||
if (!File.Exists(file))
|
||||
{
|
||||
Console.WriteLine("File {0} doesn't exist.", Path.GetFileName(file));
|
||||
Console.Clear();
|
||||
return;
|
||||
}
|
||||
public void Unpack(bool saveToDisk = true)
|
||||
{ if (HeaderReader()) FileReader(saveToDisk); }
|
||||
|
||||
Stream reader = File.OpenReader(file);
|
||||
string directory = Path.GetFullPath(file).Replace(Path.GetExtension(file), "");
|
||||
Signature = (Farc)reader.ReadInt32Endian(true);
|
||||
public bool HeaderReader()
|
||||
{
|
||||
NewFARC();
|
||||
if (!File.Exists(FilePath)) return false;
|
||||
|
||||
Stream reader = File.OpenReader(FilePath);
|
||||
DirectoryPath = Path.RemoveExtension(Path.GetFullPath(FilePath));
|
||||
Signature = (Farc)reader.RI32E(true);
|
||||
if (Signature != Farc.FArc && Signature != Farc.FArC && Signature != Farc.FARC)
|
||||
{
|
||||
Console.WriteLine("Unknown signature"); reader.Close();
|
||||
Console.Clear();
|
||||
return;
|
||||
}
|
||||
{ reader.Dispose(); return false; }
|
||||
|
||||
MSIO.Directory.CreateDirectory(directory);
|
||||
int HeaderLength = reader.ReadInt32Endian(true);
|
||||
if (Signature != Farc.FARC)
|
||||
{
|
||||
reader.ReadUInt32();
|
||||
HeaderReader(HeaderLength, ref Files, ref reader);
|
||||
reader.Close();
|
||||
FT = false;
|
||||
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
int headerLength = reader.RI32E(true);
|
||||
if (Signature == Farc.FARC)
|
||||
{
|
||||
FARCFlags = (Flags)reader.RI32E(true);
|
||||
reader.RI32();
|
||||
int alignment = reader.RI32E(true);
|
||||
|
||||
FT = (FARCFlags & Flags.AES) != 0 && (alignment & (alignment - 1)) != 0;
|
||||
|
||||
if (FT)
|
||||
{
|
||||
if (Signature == Farc.FArC)
|
||||
using (MSIO.MemoryStream memorystream = new MSIO.MemoryStream(
|
||||
File.ReadAllBytes(file, Files[i].SizeComp, Files[i].Offset)))
|
||||
{
|
||||
GZipStream gZipStream = new GZipStream(memorystream, CompressionMode.Decompress);
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
}
|
||||
else
|
||||
Files[i].Data = File.ReadAllBytes(file, Files[i].SizeUnc, Files[i].Offset);
|
||||
|
||||
if (SaveToDisk)
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(directory, Files[i].Name), Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
}
|
||||
headerLength -= 0x08;
|
||||
reader.S(-0x04, SeekOrigin.Current);
|
||||
}
|
||||
Console.Clear();
|
||||
return;
|
||||
else
|
||||
headerLength -= 0x0C;
|
||||
}
|
||||
|
||||
int Mode = reader.ReadInt32Endian(true);
|
||||
reader.ReadUInt32();
|
||||
bool GZip = (Mode & 2) == 2;
|
||||
bool ECB = (Mode & 4) == 4;
|
||||
Files.Capacity = 0;
|
||||
|
||||
int FARCType = reader.ReadInt32Endian(true);
|
||||
FT = FARCType == 0x10;
|
||||
bool CBC = !FT && FARCType != 0x40;
|
||||
if (ECB && CBC)
|
||||
if (FT)
|
||||
{
|
||||
byte[] Header = new byte[HeaderLength - 0x08];
|
||||
FT = true;
|
||||
reader.Close();
|
||||
MSIO.FileStream stream = new MSIO.FileStream(file, MSIO.FileMode.Open,
|
||||
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite);
|
||||
stream.Seek(0x10, 0);
|
||||
headerLength -= 0x10;
|
||||
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Header, 0x00, HeaderLength - 0x08);
|
||||
Header = SkipData(Header, 0x10);
|
||||
Stream CBCreader = new Stream(new MSIO.MemoryStream(Header));
|
||||
CBCreader.BaseStream.Seek(0, 0);
|
||||
byte[] iv = reader.RBy(0x10);
|
||||
byte[] header = reader.RBy(headerLength);
|
||||
reader.Dispose();
|
||||
|
||||
FARCType = CBCreader.ReadInt32Endian(true);
|
||||
FT = FARCType == 0x10;
|
||||
if (CBCreader.ReadInt32Endian(true) == 1)
|
||||
Files = new FARCFile[CBCreader.ReadInt32Endian(true)];
|
||||
CBCreader.ReadUInt32();
|
||||
HeaderReader(HeaderLength, ref Files, ref CBCreader);
|
||||
CBCreader.Close();
|
||||
using (MSIO.MemoryStream ms = new MSIO.MemoryStream())
|
||||
{
|
||||
using (AesManaged aes = GetAes(iv))
|
||||
using (CryptoStream cryptoStream = new CryptoStream(ms,
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Write))
|
||||
cryptoStream.Write(header, 0x00, headerLength);
|
||||
header = ms.ToArray();
|
||||
headerLength = header.Length;
|
||||
}
|
||||
|
||||
reader = File.OpenReader(header);
|
||||
int alignment = reader.RI32E(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (reader.ReadInt32Endian(true) == 1)
|
||||
Files = new FARCFile[reader.ReadInt32Endian(true)];
|
||||
reader.ReadUInt32();
|
||||
HeaderReader(HeaderLength, ref Files, ref reader);
|
||||
reader.Close();
|
||||
byte[] header = reader.RBy(headerLength);
|
||||
reader.Dispose();
|
||||
reader = File.OpenReader(header);
|
||||
}
|
||||
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
int FileSize = ECB || Files[i].ECB ? Files[i].SizeComp.Align(0x10) : Files[i].SizeComp;
|
||||
MSIO.FileStream stream = new MSIO.FileStream(file, MSIO.FileMode.Open,
|
||||
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite);
|
||||
stream.Seek(Files[i].Offset, 0);
|
||||
Files[i].Data = new byte[FileSize];
|
||||
|
||||
bool Encrypted = false;
|
||||
if (ECB)
|
||||
{
|
||||
if ((FT && Files[i].ECB) || CBC)
|
||||
{
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(true, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Files[i].Data, 0, FileSize);
|
||||
Files[i].Data = SkipData(Files[i].Data, 0x10);
|
||||
}
|
||||
else
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(false, null).CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Files[i].Data, 0, FileSize);
|
||||
Encrypted = true;
|
||||
bool hasPerFileFlags = false;
|
||||
if (Signature == Farc.FARC) {
|
||||
if (reader.RI32E(true) == 1) {
|
||||
Files.Capacity = reader.RI32E(true);
|
||||
hasPerFileFlags = true;
|
||||
}
|
||||
|
||||
bool Compressed = false;
|
||||
bool LocalGZip = (FT && Files[i].GZip) || GZip && Files[i].SizeUnc != 0;
|
||||
if (LocalGZip)
|
||||
{
|
||||
GZipStream gZipStream;
|
||||
if (Encrypted)
|
||||
{
|
||||
gZipStream = new GZipStream(new MSIO.MemoryStream(
|
||||
Files[i].Data), CompressionMode.Decompress);
|
||||
stream.Close();
|
||||
}
|
||||
else gZipStream = new GZipStream(stream, CompressionMode.Decompress);
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
|
||||
Compressed = true;
|
||||
}
|
||||
|
||||
if (!Encrypted && !Compressed)
|
||||
{
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
stream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
if (SaveToDisk)
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(directory, Files[i].Name), Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
}
|
||||
|
||||
}
|
||||
Console.Clear();
|
||||
}
|
||||
reader.RI32E(true);
|
||||
|
||||
byte[] SkipData(byte[] Data, int Skip)
|
||||
{
|
||||
byte[] SkipData = new byte[Data.Length - Skip];
|
||||
for (int i = 0; i < Data.Length - Skip; i++) SkipData[i] = Data[i + Skip];
|
||||
return SkipData;
|
||||
}
|
||||
|
||||
void HeaderReader(int HeaderLenght, ref FARCFile[] Files, ref Stream reader)
|
||||
{
|
||||
if (Files == null)
|
||||
if (Files.Capacity == 0)
|
||||
{
|
||||
int Count = 0;
|
||||
long Position = reader.BaseStream.Position;
|
||||
while (reader.BaseStream.Position < HeaderLenght)
|
||||
long Position = reader.PI64;
|
||||
int Size = 0;
|
||||
if (hasPerFileFlags)
|
||||
Size = sizeof(int) * 4;
|
||||
else if (Signature != Farc.FArc)
|
||||
Size = sizeof(int) * 3;
|
||||
else
|
||||
Size = sizeof(int) * 2;
|
||||
|
||||
while (reader.PI64 < headerLength)
|
||||
{
|
||||
reader.NullTerminated();
|
||||
reader.ReadInt32();
|
||||
if (Signature != Farc.FArc ) reader.ReadInt32();
|
||||
reader.ReadInt32();
|
||||
if (Signature == Farc.FARC && FT) reader.ReadInt32();
|
||||
reader.NT();
|
||||
reader.RBy(Size);
|
||||
Count++;
|
||||
}
|
||||
reader.Seek(Position, 0);
|
||||
Files = new FARCFile[Count];
|
||||
reader.PI64 = Position;
|
||||
Files.Capacity = Count;
|
||||
}
|
||||
|
||||
int LocalMode = 0;
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
Files[i].Name = reader.NullTerminatedUTF8();
|
||||
Files[i].Offset = reader.ReadInt32Endian(true);
|
||||
if (Signature != Farc.FArc) Files[i].SizeComp = reader.ReadInt32Endian(true);
|
||||
Files[i].SizeUnc = reader.ReadInt32Endian(true);
|
||||
if (Signature == Farc.FARC && FT)
|
||||
if (hasPerFileFlags)
|
||||
for (int i = 0; i < Files.Capacity; i++)
|
||||
{
|
||||
LocalMode = reader.ReadInt32Endian(true);
|
||||
Files[i].GZip = (LocalMode & 2) == 2;
|
||||
Files[i].ECB = (LocalMode & 4) == 4;
|
||||
FARCFile file = default;
|
||||
file.Name = reader.NTUTF8();
|
||||
file.Offset = reader.RI32E(true);
|
||||
file.SizeComp = reader.RI32E(true);
|
||||
file.Size = reader.RI32E(true);
|
||||
Flags Flags = (Flags)reader.RI32E(true);
|
||||
|
||||
file.Compressed = file.Size != 0 || (FARCFlags & Flags.GZip) != 0;
|
||||
file.Encrypted = ((FARCFlags | Flags) & Flags.AES) != 0;
|
||||
Files.Add(file);
|
||||
}
|
||||
}
|
||||
else if (Signature != Farc.FArc)
|
||||
for (int i = 0; i < Files.Capacity; i++)
|
||||
{
|
||||
FARCFile file = default;
|
||||
file.Name = reader.NTUTF8();
|
||||
file.Offset = reader.RI32E(true);
|
||||
file.SizeComp = reader.RI32E(true);
|
||||
file.Size = reader.RI32E(true);
|
||||
|
||||
file.Compressed = file.Size != 0;
|
||||
file.Encrypted = (FARCFlags & Flags.AES) != 0;
|
||||
Files.Add(file);
|
||||
}
|
||||
else
|
||||
for (int i = 0; i < Files.Capacity; i++)
|
||||
{
|
||||
FARCFile file = default;
|
||||
file.Name = reader.NTUTF8();
|
||||
file.Offset = reader.RI32E(true);
|
||||
file.Size = reader.RI32E(true);
|
||||
|
||||
file.SizeComp = 0;
|
||||
file.Compressed = false;
|
||||
file.Encrypted = false;
|
||||
Files.Add(file);
|
||||
}
|
||||
|
||||
reader.Dispose();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Exists(string file)
|
||||
{
|
||||
if (!HasFiles) return false;
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
if (Files[i].Name.ToLower() == file.ToLower()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Pack(string file)
|
||||
private void FileReader(bool saveToDisk)
|
||||
{
|
||||
Files = null;
|
||||
FT = false;
|
||||
string[] files = Directory.GetFiles(file);
|
||||
Files = new FARCFile[files.Length];
|
||||
if (saveToDisk)
|
||||
MSIO.Directory.CreateDirectory(DirectoryPath);
|
||||
|
||||
Stream reader = File.OpenReader(FilePath);
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
FileReader(i, saveToDisk, ref reader);
|
||||
reader.Dispose();
|
||||
}
|
||||
|
||||
public byte[] FileReader(string file)
|
||||
{
|
||||
if (!HasFiles) return null;
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
if (Files[i].Name.ToLower() == file.ToLower())
|
||||
return FileReader(i);
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] FileReader(int i)
|
||||
{
|
||||
Stream reader = File.OpenReader(FilePath);
|
||||
byte[] data = FileReader(i, false, ref reader);
|
||||
reader.Dispose();
|
||||
return data;
|
||||
}
|
||||
|
||||
public byte[] FileReader(int i, bool saveToDisk, ref Stream reader)
|
||||
{
|
||||
if (!HasFiles) return null;
|
||||
if (i >= Files.Count) return null;
|
||||
|
||||
FARCFile file = Files[i];
|
||||
file.Data = null;
|
||||
|
||||
reader.S(file.Offset, SeekOrigin.Begin);
|
||||
|
||||
if (Signature == Farc.FArc)
|
||||
{
|
||||
file.DataComp = null;
|
||||
file.Data = reader.RBy(file.Size);
|
||||
}
|
||||
else if (Signature == Farc.FArC)
|
||||
{
|
||||
file.DataComp = reader.RBy(file.SizeComp);
|
||||
file.Data = file.DataComp.InflateGZip(file.Size);
|
||||
}
|
||||
else if (file.Encrypted || file.Compressed)
|
||||
{
|
||||
int tempSize = file.Encrypted ? file.SizeComp.A(0x10) : file.SizeComp;
|
||||
|
||||
byte[] temp;
|
||||
if (file.Encrypted)
|
||||
if (FT)
|
||||
{
|
||||
file.SizeComp -= 0x10;
|
||||
tempSize -= 0x10;
|
||||
|
||||
byte[] iv = reader.RBy(0x10);
|
||||
using (MSIO.MemoryStream ms = new MSIO.MemoryStream())
|
||||
{
|
||||
using (AesManaged aes = GetAes(iv))
|
||||
using (CryptoStream cryptoStream = new CryptoStream(ms,
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Write))
|
||||
cryptoStream.Write(reader.RBy(tempSize), 0x00, tempSize);
|
||||
temp = ms.ToArray();
|
||||
file.SizeComp = temp.Length;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (MSIO.MemoryStream ms = new MSIO.MemoryStream())
|
||||
{
|
||||
using (AesManaged aes = GetAes())
|
||||
using (CryptoStream cryptoStream = new CryptoStream(ms,
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Write))
|
||||
cryptoStream.Write(reader.RBy(tempSize), 0x00, tempSize);
|
||||
temp = ms.ToArray();
|
||||
}
|
||||
}
|
||||
else
|
||||
temp = reader.RBy(tempSize);
|
||||
|
||||
if (!file.Compressed)
|
||||
{
|
||||
file.DataComp = null;
|
||||
file.Data = temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
file.DataComp = temp;
|
||||
file.Data = file.DataComp.InflateGZip(file.Size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
file.DataComp = null;
|
||||
file.Data = reader.RBy(file.Size);
|
||||
}
|
||||
|
||||
if (saveToDisk)
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(DirectoryPath, file.Name), file.Data);
|
||||
file.DataComp = null;
|
||||
file.Data = null;
|
||||
}
|
||||
|
||||
Files[i] = file;
|
||||
return Files[i].Data;
|
||||
}
|
||||
|
||||
public void Pack(Farc signature = Farc.FArC)
|
||||
{
|
||||
NewFARC();
|
||||
string[] files = Directory.GetFiles(DirectoryPath);
|
||||
Files.Capacity = files.Length;
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
{
|
||||
Files[i] = new FARCFile { Name = files[i] };
|
||||
string ext = Path.GetExtension(files[i]).ToLower();
|
||||
if (ext == ".a3da" || ext == ".diva" || ext == ".vag")
|
||||
Signature = Farc.FArc;
|
||||
}
|
||||
Files.Add(new FARCFile { Name = Path.GetFileName(files[i]), Data = File.ReadAllBytes(files[i]) });
|
||||
files = null;
|
||||
|
||||
Stream writer = File.OpenWriter(file + ".farc", true);
|
||||
writer.WriteEndian((int)Signature, true);
|
||||
|
||||
Stream HeaderWriter = File.OpenWriter();
|
||||
for (int i = 0; i < 3; i++) HeaderWriter.WriteByte(0x00);
|
||||
if (Signature == Farc.FArc) HeaderWriter.WriteByte(0x20);
|
||||
else if (Signature == Farc.FArC) HeaderWriter.WriteByte(0x10);
|
||||
else if (Signature == Farc.FARC)
|
||||
{
|
||||
HeaderWriter.WriteByte(0x06);
|
||||
for (int i = 0; i < 7; i++) HeaderWriter.WriteByte(0x00);
|
||||
HeaderWriter.WriteByte(0x40);
|
||||
for (int i = 0; i < 8; i++) HeaderWriter.WriteByte(0x00);
|
||||
}
|
||||
int HeaderPartLength = Signature == Farc.FArc ? 0x09 : 0x0D;
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
HeaderWriter.Length += Path.GetFileName(Files[i].Name).Length + HeaderPartLength;
|
||||
writer.WriteEndian(HeaderWriter.Length, true);
|
||||
writer.Write(HeaderWriter.ToArray(true));
|
||||
HeaderWriter = null;
|
||||
|
||||
int Align = writer.Position.Align(0x10) - writer.Position;
|
||||
for (int i1 = 0; i1 < Align; i1++)
|
||||
if (Signature == Farc.FArc) writer.WriteByte(0x00);
|
||||
else writer.WriteByte(0x78);
|
||||
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
CompressStuff(i, ref Files, ref writer);
|
||||
|
||||
if (Signature == Farc.FARC) writer.Seek(0x1C, 0);
|
||||
else writer.Seek(0x0C, 0);
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
{
|
||||
writer.Write(Path.GetFileName(Files[i].Name) + "\0");
|
||||
writer.WriteEndian(Files[i].Offset, true);
|
||||
if (Signature != Farc.FArc)
|
||||
writer.WriteEndian(Files[i].SizeComp, true);
|
||||
writer.WriteEndian(Files[i].SizeUnc, true);
|
||||
}
|
||||
writer.Close();
|
||||
Signature = signature;
|
||||
Save();
|
||||
}
|
||||
|
||||
void CompressStuff(int i, ref FARCFile[] Files, ref Stream writer)
|
||||
public void Save()
|
||||
{
|
||||
Files[i].Offset = writer.Position;
|
||||
Files[i].Data = File.ReadAllBytes(Files[i].Name);
|
||||
Files[i].SizeUnc = Files[i].Data.Length;
|
||||
if (!HasFiles || (Signature != Farc.FArc && Signature != Farc.FArC && Signature != Farc.FARC)) return;
|
||||
|
||||
if (Signature != Farc.FArc)
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
{
|
||||
if (Signature != Farc.FArc)
|
||||
{
|
||||
MSIO.MemoryStream stream = new MSIO.MemoryStream();
|
||||
using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Compress))
|
||||
gZipStream.Write(Files[i].Data, 0, Files[i].Data.Length);
|
||||
Files[i].Data = stream.ToArray();
|
||||
stream.Dispose();
|
||||
Files[i].SizeComp = Files[i].Data.Length;
|
||||
}
|
||||
string ext = Path.GetExtension(Files[i].Name).ToLower();
|
||||
if (ext == ".a3da" || ext == ".diva" || ext == ".farc" || ext == ".vag")
|
||||
{ Signature = Farc.FArc; break; }
|
||||
}
|
||||
|
||||
Stream writer = File.OpenWriter(DirectoryPath + ".farc", true);
|
||||
writer.WE((int)Signature, true);
|
||||
|
||||
using (Stream headerWriter = File.OpenWriter())
|
||||
{
|
||||
if (Signature == Farc.FArc) headerWriter.WE(0x01, true);
|
||||
else if (Signature == Farc.FArC) headerWriter.WE(0x01, true);
|
||||
else if (Signature == Farc.FARC)
|
||||
{
|
||||
int AlignData = Files[i].Data.Length.Align(0x40);
|
||||
byte[] Data = new byte[AlignData];
|
||||
for (int i1 = 0; i1 < Files[i].Data.Length; i1++)
|
||||
Data[i1] = Files[i].Data[i1];
|
||||
for (int i1 = Files[i].Data.Length; i1 < AlignData; i1++)
|
||||
Data[i1] = 0x78;
|
||||
|
||||
Files[i].Data = Encrypt(Data, false);
|
||||
headerWriter.WE((int)FARCFlags, true);
|
||||
headerWriter.W (0x00);
|
||||
headerWriter.WE(0x40, true);
|
||||
headerWriter.W (0x00);
|
||||
headerWriter.W (0x00);
|
||||
}
|
||||
if (Signature != Farc.FArc)
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
{ headerWriter.W(Files[i].Name + "\0"); headerWriter.W(0x00L); headerWriter.W(0x00); }
|
||||
else
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
{ headerWriter.W(Files[i].Name + "\0"); headerWriter.W(0x00L); }
|
||||
writer.WE(headerWriter.L, true);
|
||||
writer.W (headerWriter.ToArray(true));
|
||||
}
|
||||
writer.Write(Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
|
||||
int align = writer.P.A(0x10) - writer.P;
|
||||
for (int i1 = 0; i1 < align; i1++)
|
||||
writer.W((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
|
||||
|
||||
writer.F();
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
CompressStuff(i, ref writer);
|
||||
|
||||
writer.P = Signature == Farc.FARC ? 0x1C : 0x0C;
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
{
|
||||
FARCFile file = Files[i];
|
||||
writer.W (file.Name + "\0");
|
||||
writer.WE(file.Offset, true);
|
||||
if (Signature != Farc.FArc) writer.WE(file.SizeComp, true);
|
||||
writer.WE(file.Size, true);
|
||||
}
|
||||
writer.Dispose();
|
||||
}
|
||||
|
||||
private void CompressStuff(int i, ref Stream writer)
|
||||
{
|
||||
FARCFile file = Files[i];
|
||||
file.Offset = writer.P;
|
||||
file.Size = file.Data.Length;
|
||||
|
||||
byte[] data = file.Data;
|
||||
if (Signature == Farc.FArC || (Signature == Farc.FARC && (FARCFlags & Flags.GZip) != 0))
|
||||
data = file.Data.DeflateGZip(CompressionLevel);
|
||||
file.SizeComp = data.Length;
|
||||
|
||||
if (Signature == Farc.FARC && (FARCFlags & Flags.AES) != 0)
|
||||
{
|
||||
int alignLength = data.Length.A(0x40);
|
||||
byte[] tempData = new byte[alignLength];
|
||||
System.Array.Copy(data, tempData, data.Length);
|
||||
for (int i1 = file.Data.Length; i1 < alignLength; i1++) tempData[i1] = 0x78;
|
||||
data = Encrypt(tempData);
|
||||
}
|
||||
writer.W(data);
|
||||
|
||||
if (Signature != Farc.FARC)
|
||||
{
|
||||
int Align = writer.Position.Align(0x20) - writer.Position;
|
||||
int Align = writer.P.A(0x10) - writer.P;
|
||||
for (int i1 = 0; i1 < Align; i1++)
|
||||
if (Signature == Farc.FArc) writer.WriteByte(0x00);
|
||||
else writer.WriteByte(0x78);
|
||||
writer.W((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
|
||||
}
|
||||
Files[i] = file;
|
||||
}
|
||||
|
||||
byte[] Encrypt(byte[] Data, bool isFT)
|
||||
private byte[] Encrypt(byte[] data)
|
||||
{
|
||||
MSIO.MemoryStream stream = new MSIO.MemoryStream();
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
GetAes(isFT, null).CreateEncryptor(),CryptoStreamMode.Write))
|
||||
cryptoStream.Write(Data, 0, Data.Length);
|
||||
return stream.ToArray();
|
||||
MSIO.MemoryStream ms = new MSIO.MemoryStream();
|
||||
using (AesManaged aes = GetAes())
|
||||
using (CryptoStream cryptoStream = new CryptoStream(ms,
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Write))
|
||||
cryptoStream.Write(data, 0x00, data.Length);
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
public enum Farc
|
||||
public void Dispose() => NewFARC();
|
||||
|
||||
public struct FARCFile
|
||||
{
|
||||
public string Name;
|
||||
public int Offset;
|
||||
public int Size;
|
||||
public int SizeComp;
|
||||
public byte[] Data;
|
||||
public byte[] DataComp;
|
||||
public bool Compressed;
|
||||
public bool Encrypted;
|
||||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
public enum Farc : int
|
||||
{
|
||||
FArc = 0x46417263,
|
||||
FArC = 0x46417243,
|
||||
FARC = 0x46415243,
|
||||
}
|
||||
|
||||
public struct FARCFile
|
||||
public enum Flags : int
|
||||
{
|
||||
public int Offset;
|
||||
public int SizeComp;
|
||||
public int SizeUnc;
|
||||
public bool GZip;
|
||||
public bool ECB;
|
||||
public byte[] Data;
|
||||
public string Name;
|
||||
None = 0b000,
|
||||
GZip = 0b010,
|
||||
AES = 0b100,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public static unsafe class DeflateInflate
|
||||
{
|
||||
public static bool HasFile = false;
|
||||
|
||||
private const string libDeflateString = "libdeflate.dll";
|
||||
|
||||
public static void CheckLib()
|
||||
{
|
||||
if (!File.Exists(libDeflateString))
|
||||
File.WriteAllBytes(libDeflateString, Properties.Resources.libdeflate);
|
||||
HasFile = true;
|
||||
}
|
||||
|
||||
public static byte[] Deflate(this byte[] data, long compressionLevel)
|
||||
{
|
||||
CheckLib();
|
||||
|
||||
void* c = libdeflate_alloc_compressor((int)compressionLevel);
|
||||
int maxOutBytes = libdeflate_deflate_compress_bound(c, data.Length);
|
||||
byte[] outData = new byte[maxOutBytes];
|
||||
int actualOut = 0;
|
||||
fixed (byte* inPtr = data)
|
||||
fixed (byte* outPtr = outData)
|
||||
actualOut = libdeflate_deflate_compress(c, inPtr, data.Length, outPtr, maxOutBytes);
|
||||
libdeflate_free_compressor(c);
|
||||
System.Array.Resize(ref outData, (int)actualOut);
|
||||
return outData;
|
||||
}
|
||||
|
||||
public static byte[] Inflate(this byte[] data, long length)
|
||||
{
|
||||
CheckLib();
|
||||
|
||||
byte[] outData = new byte[length];
|
||||
|
||||
int actualOut = 0;
|
||||
void* d = libdeflate_alloc_decompressor();
|
||||
fixed (byte* inPtr = data)
|
||||
fixed (byte* outPtr = outData)
|
||||
libdeflate_deflate_decompress(d, inPtr, data.Length, outPtr, (int)length, &actualOut);
|
||||
libdeflate_free_decompressor(d);
|
||||
|
||||
if (actualOut == 0 || actualOut > length)
|
||||
return data.Inflate(length * 2);
|
||||
else if (actualOut < length)
|
||||
System.Array.Resize(ref outData, (int)actualOut);
|
||||
return outData;
|
||||
}
|
||||
|
||||
public static byte[] DeflateGZip(this byte[] data, long compressionLevel)
|
||||
{
|
||||
CheckLib();
|
||||
|
||||
void* c = libdeflate_alloc_compressor((int)compressionLevel);
|
||||
int maxOutBytes = libdeflate_gzip_compress_bound(c, data.Length);
|
||||
byte[] outData = new byte[maxOutBytes];
|
||||
int actualOut = 0;
|
||||
fixed (byte* inPtr = data)
|
||||
fixed (byte* outPtr = outData)
|
||||
actualOut = libdeflate_gzip_compress(c, inPtr, data.Length, outPtr, maxOutBytes);
|
||||
libdeflate_free_compressor(c);
|
||||
System.Array.Resize(ref outData, (int)actualOut);
|
||||
return outData;
|
||||
}
|
||||
|
||||
public static byte[] InflateGZip(this byte[] data, long length)
|
||||
{
|
||||
CheckLib();
|
||||
|
||||
byte[] outData = new byte[length];
|
||||
|
||||
int result;
|
||||
int actualOut = 0;
|
||||
void* d = libdeflate_alloc_decompressor();
|
||||
fixed (byte* inPtr = data)
|
||||
fixed (byte* outPtr = outData)
|
||||
result = libdeflate_gzip_decompress(d, inPtr, data.Length, outPtr, (int)length, &actualOut);
|
||||
libdeflate_free_decompressor(d);
|
||||
|
||||
if (actualOut == 0 || actualOut > length)
|
||||
return data.InflateGZip(length * 2 + 1);
|
||||
else if (actualOut < length)
|
||||
System.Array.Resize(ref outData, (int)actualOut);
|
||||
return outData;
|
||||
}
|
||||
|
||||
public static byte[] DeflateZLib(this byte[] data, long compressionLevel)
|
||||
{
|
||||
CheckLib();
|
||||
|
||||
void* c = libdeflate_alloc_compressor((int)compressionLevel);
|
||||
int maxOutBytes = libdeflate_zlib_compress_bound(c, data.Length);
|
||||
byte[] outData = new byte[maxOutBytes];
|
||||
int actualOut = 0;
|
||||
fixed (byte* inPtr = data)
|
||||
fixed (byte* outPtr = outData)
|
||||
actualOut = libdeflate_zlib_compress(c, inPtr, data.Length, outPtr, maxOutBytes);
|
||||
libdeflate_free_compressor(c);
|
||||
System.Array.Resize(ref outData, (int)actualOut);
|
||||
return outData;
|
||||
}
|
||||
|
||||
public static byte[] InflateZLib(this byte[] data, long length)
|
||||
{
|
||||
CheckLib();
|
||||
|
||||
byte[] outData = new byte[length];
|
||||
|
||||
int actualOut = 0;
|
||||
void* d = libdeflate_alloc_decompressor();
|
||||
fixed (byte* inPtr = data)
|
||||
fixed (byte* outPtr = outData)
|
||||
libdeflate_zlib_decompress(d, inPtr, data.Length, outPtr, (int)length, &actualOut);
|
||||
libdeflate_free_decompressor(d);
|
||||
|
||||
if (actualOut == 0 || actualOut > length)
|
||||
return data.InflateZLib(length * 2);
|
||||
else if (actualOut < length)
|
||||
System.Array.Resize(ref outData, (int)actualOut);
|
||||
return outData;
|
||||
}
|
||||
|
||||
[DllImport(libDeflateString)]
|
||||
private static extern void* libdeflate_alloc_compressor(int compressionLevel);
|
||||
|
||||
[DllImport(libDeflateString)]
|
||||
private static extern void* libdeflate_alloc_decompressor();
|
||||
|
||||
[DllImport(libDeflateString)]
|
||||
private static extern int libdeflate_deflate_compress_bound(void* c, int length);
|
||||
|
||||
[DllImport(libDeflateString)]
|
||||
private static extern int libdeflate_deflate_compress(void* c, byte* inData, int inBytes,
|
||||
byte* outData, int maxOutBytes);
|
||||
|
||||
[DllImport(libDeflateString)]
|
||||
private static extern int libdeflate_deflate_decompress(void* d, byte* inData, int inBytes,
|
||||
byte* outData, int outBytesAvail, int* actualOutBytes);
|
||||
|
||||
[DllImport(libDeflateString)]
|
||||
private static extern int libdeflate_deflate_decompress_ex(void* d, byte* inData, int inBytes,
|
||||
byte* outData, int outBytesAvail, int* actualInBytes, int* actualOutBytes);
|
||||
|
||||
[DllImport(libDeflateString)]
|
||||
private static extern int libdeflate_gzip_compress_bound(void* c, int length);
|
||||
|
||||
[DllImport(libDeflateString)]
|
||||
private static extern int libdeflate_gzip_compress(void* c, byte* inData, int inBytes,
|
||||
byte* outData, int maxOutBytes);
|
||||
|
||||
[DllImport(libDeflateString)]
|
||||
private static extern int libdeflate_gzip_decompress(void* d, byte* inData, int inBytes,
|
||||
byte* outData, int outBytesAvail, int* actualOutBytes);
|
||||
|
||||
[DllImport(libDeflateString)]
|
||||
private static extern int libdeflate_gzip_decompress_ex(void* d, byte* inData, int inBytes,
|
||||
byte* outData, int outBytesAvail, int* actualInBytes, int* actualOutBytes);
|
||||
|
||||
[DllImport(libDeflateString)]
|
||||
private static extern int libdeflate_zlib_compress_bound(void* c, int length);
|
||||
|
||||
[DllImport(libDeflateString)]
|
||||
private static extern int libdeflate_zlib_compress(void* c, byte* inData, int inBytes,
|
||||
byte* outData, int maxOutBytes);
|
||||
|
||||
[DllImport(libDeflateString)]
|
||||
private static extern int libdeflate_zlib_decompress(void* d, byte* inData, int inBytes,
|
||||
byte* outData, int outBytesAvail, int* actualOutBytes);
|
||||
|
||||
[DllImport(libDeflateString)]
|
||||
private static extern void libdeflate_free_compressor(void* c);
|
||||
|
||||
[DllImport(libDeflateString)]
|
||||
private static extern void libdeflate_free_decompressor(void* d);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,102 @@
|
||||
using System;
|
||||
using MSIO = System.IO;
|
||||
using MSIOD = System.IO.Directory;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public static class Directory
|
||||
{
|
||||
public static bool Exists(string path) => MSIO.Directory.Exists(path);
|
||||
public static void Delete(string path) => MSIO.Directory.Delete(path);
|
||||
public static string GetCurrentDirectory() => MSIO.Directory.GetCurrentDirectory();
|
||||
public static string[] GetFiles(string path) => MSIO.Directory.GetFiles(path);
|
||||
public static string[] GetDirectories(string path) => MSIO.Directory.GetDirectories(path);
|
||||
public static MSIO.DirectoryInfo CreateDirectory(string path) => MSIO.Directory.CreateDirectory(path);
|
||||
public static MSIO.DirectoryInfo CreateDirectory(string path) =>
|
||||
MSIOD.CreateDirectory(path);
|
||||
|
||||
public static void Delete(string path, bool recursive) =>
|
||||
MSIOD.Delete(path, recursive);
|
||||
|
||||
public static void Delete(string path) =>
|
||||
MSIOD.Delete(path);
|
||||
|
||||
public static bool Exists(string path) =>
|
||||
MSIOD.Exists(path);
|
||||
|
||||
public static System.DateTime GetCreationTime(string path) =>
|
||||
MSIOD.GetCreationTime(path);
|
||||
|
||||
public static System.DateTime GetCreationTimeUtc(string path) =>
|
||||
MSIOD.GetCreationTimeUtc(path);
|
||||
|
||||
public static string GetCurrentDirectory() =>
|
||||
MSIOD.GetCurrentDirectory();
|
||||
|
||||
public static string[] GetDirectories(string path, string searchPattern, MSIO.SearchOption searchOption) =>
|
||||
MSIOD.GetDirectories(path, searchPattern, searchOption);
|
||||
|
||||
public static string[] GetDirectories(string path, string searchPattern) =>
|
||||
MSIOD.GetDirectories(path, searchPattern);
|
||||
|
||||
public static string[] GetDirectories(string path) =>
|
||||
MSIOD.GetDirectories(path);
|
||||
|
||||
public static string GetDirectoryRoot(string path) =>
|
||||
MSIOD.GetDirectoryRoot(path);
|
||||
|
||||
public static string[] GetFiles(string path, string searchPattern, MSIO.SearchOption searchOption) =>
|
||||
MSIOD.GetFiles(path, searchPattern, searchOption);
|
||||
|
||||
public static string[] GetFiles(string path) =>
|
||||
MSIOD.GetFiles(path);
|
||||
|
||||
public static string[] GetFiles(string path, string searchPattern) =>
|
||||
MSIOD.GetFiles(path, searchPattern);
|
||||
|
||||
public static string[] GetFileSystemEntries(string path) =>
|
||||
MSIOD.GetFileSystemEntries(path);
|
||||
|
||||
public static string[] GetFileSystemEntries(string path, string searchPattern) =>
|
||||
MSIOD.GetFileSystemEntries(path, searchPattern);
|
||||
|
||||
public static string[] GetFileSystemEntries(string path, string searchPattern, MSIO.SearchOption searchOption) =>
|
||||
MSIOD.GetFileSystemEntries(path, searchPattern, searchOption);
|
||||
|
||||
public static System.DateTime GetLastAccessTime(string path) =>
|
||||
MSIOD.GetLastAccessTime(path);
|
||||
|
||||
public static System.DateTime GetLastAccessTimeUtc(string path) =>
|
||||
MSIOD.GetLastAccessTimeUtc(path);
|
||||
|
||||
public static System.DateTime GetLastWriteTime(string path) =>
|
||||
MSIOD.GetLastWriteTime(path);
|
||||
|
||||
public static System.DateTime GetLastWriteTimeUtc(string path) =>
|
||||
MSIOD.GetLastWriteTimeUtc(path);
|
||||
|
||||
public static string[] GetLogicalDrives() =>
|
||||
MSIOD.GetLogicalDrives();
|
||||
|
||||
public static MSIO.DirectoryInfo GetParent(string path) =>
|
||||
MSIOD.GetParent(path);
|
||||
|
||||
public static void Move(string sourceDirName, string destDirName) =>
|
||||
MSIOD.Move(sourceDirName, destDirName);
|
||||
|
||||
public static void SetCreationTime(string path, System.DateTime creationTime) =>
|
||||
MSIOD.SetCreationTime(path, creationTime);
|
||||
|
||||
public static void SetCreationTimeUtc(string path, System.DateTime creationTimeUtc) =>
|
||||
MSIOD.SetCreationTimeUtc(path, creationTimeUtc);
|
||||
|
||||
public static void SetCurrentDirectory(string path) =>
|
||||
MSIOD.SetCurrentDirectory(path);
|
||||
|
||||
public static void SetLastAccessTime(string path, System.DateTime lastAccessTime) =>
|
||||
MSIOD.SetLastAccessTime(path, lastAccessTime);
|
||||
|
||||
public static void SetLastAccessTimeUtc(string path, System.DateTime lastAccessTimeUtc) =>
|
||||
MSIOD.SetLastAccessTimeUtc(path, lastAccessTimeUtc);
|
||||
|
||||
public static void SetLastWriteTime(string path, System.DateTime lastWriteTime) =>
|
||||
MSIOD.SetLastWriteTime(path, lastWriteTime);
|
||||
|
||||
public static void SetLastWriteTimeUtc(string path, System.DateTime lastWriteTimeUtc) =>
|
||||
MSIOD.SetLastWriteTimeUtc(path, lastWriteTimeUtc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
public static string NTASCII(this Stream stream, byte end = 0) =>
|
||||
stream.NT(end).ToASCII();
|
||||
public static string NTUTF8 (this Stream stream, byte end = 0) =>
|
||||
stream.NT(end).ToUTF8 ();
|
||||
public static byte[] NT (this Stream stream, byte end = 0)
|
||||
{
|
||||
KKdList<byte> s = KKdList<byte>.New;
|
||||
while (stream.PI64 < stream.LI64)
|
||||
{
|
||||
byte a = stream.RU8();
|
||||
if (a == end) break;
|
||||
else s.Add(a);
|
||||
}
|
||||
s.Capacity = s.Count;
|
||||
return s.ToArray();
|
||||
}
|
||||
|
||||
public static byte PB (this Stream stream)
|
||||
{ byte val = stream.RU8(); stream.PI64--; return val; }
|
||||
public static char PCASCII(this Stream stream)
|
||||
{ byte val = stream.RU8(); stream.PI64--; return (char)val; }
|
||||
public static char PCUTF8 (this Stream stream)
|
||||
{ long LongPosition = stream.PI64; char val = stream.RCUTF8();
|
||||
stream.PI64 = LongPosition; return val; }
|
||||
|
||||
public static Stream SW(this Stream stream)
|
||||
{
|
||||
while (true)
|
||||
if (char.IsWhiteSpace(stream.PCUTF8())) stream.RCUTF8();
|
||||
else break;
|
||||
return stream;
|
||||
}
|
||||
|
||||
public static bool As(this Stream stream, byte next)
|
||||
{ if (stream.PB() == next) { stream.PB(); return true; } else return false; }
|
||||
public static bool As(this Stream stream, byte[] next)
|
||||
{
|
||||
for (var i = 0; i < next.Length; i++)
|
||||
if (!As(stream, next[i])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool AsASCII(this Stream stream, char next)
|
||||
{ if (stream.PCUTF8() == next) { stream.RCUTF8(); return true; } else return false; }
|
||||
public static bool AsASCII(this Stream stream, string next)
|
||||
{
|
||||
for (var i = 0; i < next.Length; i++)
|
||||
if (!stream.AsASCII(next[i])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool As(this Stream stream, char next)
|
||||
{ if (stream.PCUTF8() == next) { stream.RCUTF8(); return true; } else return false; }
|
||||
public static bool As(this Stream stream, string next)
|
||||
{
|
||||
for (var i = 0; i < next.Length; i++)
|
||||
if (!As(stream, next[i])) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static long RIX(this Stream stream ) =>
|
||||
stream.IsX ? stream.RI64E( ) : stream.RI32E( );
|
||||
public static long RIX(this Stream stream, bool isBE) =>
|
||||
stream.IsX ? stream.RI64E(isBE) : stream.RI32E(isBE);
|
||||
|
||||
public static void WX(this Stream stream, long val, ref POF pof)
|
||||
{ if (stream.IsX) stream.WE( 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.WE( val, isBE);
|
||||
else stream.WE((int)val, isBE); pof.Offsets.Add(stream.P); }
|
||||
|
||||
public static void WX(this Stream stream, long val)
|
||||
{ if (stream.IsX) stream.WE( val);
|
||||
else stream.WE((int)val); }
|
||||
public static void WX(this Stream stream, long val, bool isBE)
|
||||
{ if (stream.IsX) stream.WE( val, isBE);
|
||||
else stream.WE((int)val, isBE); }
|
||||
|
||||
public static byte[] RaO(this Stream stream, long offset = -1, long length = -1)
|
||||
{
|
||||
byte[] arr = null;
|
||||
long Position = stream.PI64;
|
||||
if (offset == -1) { Position += stream.IsX ? 8 : 4; offset = stream.RIX(); }
|
||||
stream.PI64 = offset;
|
||||
if (length == -1) arr = stream.NT();
|
||||
else arr = stream.RBy(length);
|
||||
stream.PI64 = Position;
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static string RSaO(this Stream stream)
|
||||
{
|
||||
long offset = stream.RIX();
|
||||
if (offset < 1)
|
||||
return "";
|
||||
|
||||
long position = stream.PI64;
|
||||
stream.PI64 = offset;
|
||||
string s = stream.NTUTF8();
|
||||
stream.PI64 = position;
|
||||
return s;
|
||||
}
|
||||
|
||||
public static string RSaO(this Stream stream, long offset)
|
||||
{
|
||||
long position = stream.PI64;
|
||||
stream.PI64 = offset;
|
||||
string s = stream.NTUTF8();
|
||||
stream.PI64 = position;
|
||||
return s;
|
||||
}
|
||||
|
||||
public static string RSaO(this Stream stream, long offset, long length)
|
||||
{
|
||||
if (length < 1)
|
||||
return "";
|
||||
|
||||
long position = stream.PI64;
|
||||
stream.PI64 = offset;
|
||||
string s = stream.RSUTF8(length);
|
||||
stream.PI64 = position;
|
||||
return s;
|
||||
}
|
||||
|
||||
public static Pointer<string> RPSSJIS(this Stream stream)
|
||||
{ Pointer<string> val = stream.RP<string>();
|
||||
val.V = stream.RPSSJIS(val.O); return val; }
|
||||
|
||||
public static void WPSSJIS(this Stream stream, ref Pointer<string> val)
|
||||
{ val.O = stream.P; stream.WPSSJIS(val.V); }
|
||||
|
||||
public static string RPSSJIS(this Stream stream, long offset = -1, long length = -1) =>
|
||||
Text.ShiftJIS.GetString(stream.RaO(offset, length));
|
||||
|
||||
public static void WPSSJIS(this Stream stream, string val) =>
|
||||
stream.W(val.ToSJIS());
|
||||
|
||||
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> RCP<T>(this Stream stream) =>
|
||||
new CountPointer<T> { C = stream.RI32(), O = stream.RI32() };
|
||||
|
||||
public static void W<T>(this Stream stream, CountPointer<T> val)
|
||||
{ stream.W(val.C); stream.W(val.O); }
|
||||
|
||||
public static Pointer<T> RPE<T>(this Stream stream) =>
|
||||
new Pointer<T> { O = stream.RI32E() };
|
||||
|
||||
public static void WE<T>(this Stream stream, Pointer<T> val) =>
|
||||
stream.WE(val.O);
|
||||
|
||||
public static CountPointer<T> RCPE<T>(this Stream stream) =>
|
||||
new CountPointer<T> { C = stream.RI32E(), O = stream.RI32E() };
|
||||
|
||||
public static void WE<T>(this Stream stream, CountPointer<T> val)
|
||||
{ stream.WE(val.C); stream.WE(val.O); }
|
||||
|
||||
public static Pointer<string> RPSE(this Stream stream)
|
||||
{ Pointer<string> val = stream.RPE<string>();
|
||||
val.V = stream.RSaO(val.O); return val; }
|
||||
|
||||
public static void WE(this Stream stream, ref Pointer<string> val)
|
||||
{ val.O = stream.P; stream.W(val.V); }
|
||||
|
||||
public static Pointer<T> RPX<T>(this Stream stream) =>
|
||||
new Pointer<T> { O = (int)stream.RIX() };
|
||||
|
||||
public static void WE<T>(this Stream stream, ref Pointer<T> val) =>
|
||||
stream.WX(val.O);
|
||||
|
||||
public static Pointer<string> RPSX(this Stream stream)
|
||||
{ Pointer<string> val = stream.RPX<string>();
|
||||
val.V = stream.RSaO(val.O); return val; }
|
||||
|
||||
public static void WX(this Stream stream, ref Pointer<string> val)
|
||||
{ val.O = stream.P; stream.W(val.V); }
|
||||
|
||||
public static CountPointer<T> RCPX<T>(this Stream stream) =>
|
||||
new CountPointer<T> { C = (int)stream.RIX(), O = (int)stream.RIX() };
|
||||
|
||||
public static void WX<T>(this Stream stream, CountPointer<T> val)
|
||||
{ stream.WX(val.C); stream.WX(val.O); }
|
||||
}
|
||||
}
|
||||
+101
-27
@@ -1,53 +1,127 @@
|
||||
using System;
|
||||
using MSIO = System.IO;
|
||||
using MSIOF = System.IO.File;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public static class File
|
||||
{
|
||||
public static Stream OpenReader(byte[] Data) => new Stream(new MSIO.MemoryStream(Data), Data);
|
||||
public static Stream OpenWriter( ) => new Stream(new MSIO.MemoryStream( ));
|
||||
public static Stream OpenReadWriter(byte[] data) => new Stream(new MSIO.MemoryStream(data));
|
||||
public static Stream OpenReader (byte[] data) => new Stream(new MSIO.MemoryStream(data), canWrite: false);
|
||||
public static Stream OpenWriter (byte[] data) => new Stream(new MSIO.MemoryStream(data), canRead : false);
|
||||
public static Stream OpenWriter ( ) => new Stream(new MSIO.MemoryStream( ), canRead : false);
|
||||
|
||||
public static Stream OpenReader(string file, bool ReadAllAtOnce)
|
||||
{ Stream IO = OpenReader(file); if (ReadAllAtOnce) return OpenReader(IO.ToArray(true)); return IO; }
|
||||
public static Stream OpenReadWriter(string file)
|
||||
{ bool exist = Exists(file);
|
||||
Stream _IO = new Stream(new MSIO.FileStream(file, MSIO.FileMode.OpenOrCreate,
|
||||
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite)) { File = file };
|
||||
System.DateTime t = System.DateTime.UtcNow;
|
||||
if (exist) MSIOF.SetCreationTimeUtc(file, t);
|
||||
MSIOF. SetLastWriteTimeUtc(file, t);
|
||||
MSIOF.SetLastAccessTimeUtc(file, t); return _IO; }
|
||||
public static Stream OpenReader(string file, bool readAllAtOnce)
|
||||
{ Stream _IO = OpenReader(file); if (readAllAtOnce) { byte[] data =
|
||||
_IO.ToArray(); _IO.Dispose(); return OpenReader(data); } return _IO; }
|
||||
public static Stream OpenReader(string file)
|
||||
{ Stream IO = new Stream(new MSIO.FileStream(file, MSIO.FileMode.Open, MSIO.FileAccess.ReadWrite,
|
||||
MSIO.FileShare.ReadWrite)) { File = file }; return IO; }
|
||||
public static Stream OpenWriter(string file, bool SetLength0)
|
||||
{ Stream IO = OpenWriter(file); IO.SetLength(0 ); return IO; }
|
||||
public static Stream OpenWriter(string file, int SetLength)
|
||||
{ Stream IO = OpenWriter(file); IO.SetLength(SetLength); return IO; }
|
||||
{ Stream _IO = new Stream(new MSIO.FileStream(file, MSIO.FileMode.Open, MSIO.FileAccess.Read,
|
||||
MSIO.FileShare.ReadWrite), canWrite: false) { File = file }; return _IO; }
|
||||
public static Stream OpenWriter(string file, bool setLength0)
|
||||
{ Stream _IO = OpenWriter(file); if (setLength0) _IO.SL(0); return _IO; }
|
||||
public static Stream OpenWriter(string file, int setLength)
|
||||
{ Stream _IO = OpenWriter(file); _IO.SL(setLength); return _IO; }
|
||||
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 };
|
||||
MSIO.File. SetCreationTimeUtc(file, DateTime.UtcNow);
|
||||
MSIO.File. SetLastWriteTimeUtc(file, DateTime.UtcNow);
|
||||
MSIO.File.SetLastAccessTimeUtc(file, DateTime.UtcNow); return IO; }
|
||||
{ bool exist = Exists(file);
|
||||
Stream _IO = new Stream(new MSIO.FileStream(file, MSIO.FileMode.OpenOrCreate,
|
||||
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite), canRead: false) { File = file };
|
||||
System.DateTime t = System.DateTime.UtcNow;
|
||||
if (!exist) MSIOF.SetCreationTimeUtc(file, t);
|
||||
MSIOF. SetLastWriteTimeUtc(file, t);
|
||||
MSIOF.SetLastAccessTimeUtc(file, t); 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); IO.Write(data); IO.Close(); }
|
||||
{ using Stream _IO = OpenWriter(file, true); if (data != null) _IO.W(data); }
|
||||
|
||||
public static void WriteAllText (string file, string data)
|
||||
{ Stream IO = OpenWriter(file); IO.Write(data); IO.Close(); }
|
||||
{ using Stream _IO = OpenWriter(file, true); if (data != null) _IO.W(data); }
|
||||
|
||||
public static void WriteAllLines(string file, string[] data)
|
||||
{ Stream IO = OpenWriter(file); for (int i = 0; i < data.Length; i++)
|
||||
IO.Write(data[i] + "\r\n"); IO.Close(); }
|
||||
{ using Stream _IO = OpenWriter(file, true);
|
||||
if (data != null) { int c = data.Length; for (int i = 0; i < c; i++)
|
||||
{ if (data[i] != null) _IO.W(data[i]); if (i + 1 < c) _IO.W("\n"); } } }
|
||||
|
||||
public static bool Exists(string file) => MSIO.File.Exists(file);
|
||||
public static void Delete(string file) => MSIO.File.Delete(file);
|
||||
public static void WriteAllBytes(string file, byte[] data, long length)
|
||||
{ using Stream _IO = OpenWriter(file, true); if (data != null) { _IO.W(data); _IO.LI64 = length; } }
|
||||
|
||||
public static void WriteAllText (string file, string data, long length)
|
||||
{ using Stream _IO = OpenWriter(file, true); if (data != null) { _IO.W(data); _IO.LI64 = length; } }
|
||||
|
||||
public static void WriteAllLines(string file, string[] data, long length)
|
||||
{ using Stream _IO = OpenWriter(file, true);
|
||||
if (data != null) { int c = data.Length; for (int i = 0; i < c; i++)
|
||||
{ if (data[i] != null) _IO.W(data[i]); if (i + 1 < c) _IO.W("\n"); } _IO.LI64 = length; } }
|
||||
|
||||
public static bool Exists(string file) =>
|
||||
MSIOF.Exists(file);
|
||||
|
||||
public static void Delete(string file) =>
|
||||
MSIOF.Delete(file);
|
||||
|
||||
public static MSIO.FileAttributes GetAttributes(string path) =>
|
||||
MSIOF.GetAttributes(path);
|
||||
|
||||
public static System.DateTime GetCreationTime(string path) =>
|
||||
MSIOF.GetCreationTime(path);
|
||||
|
||||
public static System.DateTime GetCreationTimeUtc(string path) =>
|
||||
MSIOF.GetCreationTimeUtc(path);
|
||||
|
||||
public static System.DateTime GetLastAccessTime(string path) =>
|
||||
MSIOF.GetLastAccessTime(path);
|
||||
|
||||
public static System.DateTime GetLastAccessTimeUtc(string path) =>
|
||||
MSIOF.GetLastAccessTimeUtc(path);
|
||||
|
||||
public static System.DateTime GetLastWriteTime(string path) =>
|
||||
MSIOF.GetLastWriteTime(path);
|
||||
|
||||
public static System.DateTime GetLastWriteTimeUtc(string path) =>
|
||||
MSIOF.GetLastWriteTimeUtc(path);
|
||||
|
||||
public static void Move(string sourceFileName, string destFileName) =>
|
||||
MSIOF.Move(sourceFileName, destFileName);
|
||||
|
||||
public static void SetAttributes(string path, MSIO.FileAttributes fileAttributes) =>
|
||||
MSIOF.SetAttributes(path, fileAttributes);
|
||||
|
||||
public static void SetCreationTime(string path, System.DateTime creationTime) =>
|
||||
MSIOF.SetCreationTime(path, creationTime);
|
||||
|
||||
public static void SetCreationTimeUtc(string path, System.DateTime creationTimeUtc) =>
|
||||
MSIOF.SetCreationTimeUtc(path, creationTimeUtc);
|
||||
|
||||
public static void SetLastAccessTime(string path, System.DateTime lastAccessTime) =>
|
||||
MSIOF.SetLastAccessTime(path, lastAccessTime);
|
||||
|
||||
public static void SetLastAccessTimeUtc(string path, System.DateTime lastAccessTimeUtc) =>
|
||||
MSIOF.SetLastAccessTimeUtc(path, lastAccessTimeUtc);
|
||||
|
||||
public static void SetLastWriteTime(string path, System.DateTime lastWriteTime) =>
|
||||
MSIOF.SetLastWriteTime(path, lastWriteTime);
|
||||
|
||||
public static void SetLastWriteTimeUtc(string path, System.DateTime lastWriteTimeUtc) =>
|
||||
MSIOF.SetLastWriteTimeUtc(path, lastWriteTimeUtc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public static class IOExtensions
|
||||
{
|
||||
public static string NullTerminatedASCII(this Stream stream, byte End = 0) =>
|
||||
stream.NullTerminated(End).ToASCII();
|
||||
public static string NullTerminatedUTF8 (this Stream stream, byte End = 0) =>
|
||||
stream.NullTerminated(End).ToUTF8 ();
|
||||
public static byte[] NullTerminated (this Stream stream, byte End = 0)
|
||||
{
|
||||
List<byte> s = new List<byte>();
|
||||
while (true && stream.LongPosition >= 0 && stream.LongPosition < stream.LongLength)
|
||||
{
|
||||
byte a = stream.ReadByte();
|
||||
if (a == End) break;
|
||||
else s.Add(a);
|
||||
}
|
||||
return s.ToArray();
|
||||
}
|
||||
public static char PeekCharUTF8(this Stream stream)
|
||||
{ long LongPosition = stream.LongPosition; char val = stream.ReadCharUTF8();
|
||||
stream.LongPosition = LongPosition; return val; }
|
||||
public static Stream SkipWhitespace(this Stream stream)
|
||||
{
|
||||
long LongPosition = stream.LongPosition;
|
||||
while (true)
|
||||
if (char.IsWhiteSpace(stream.ReadCharUTF8())) LongPosition = stream.LongPosition;
|
||||
else { stream.LongPosition = LongPosition; break; }
|
||||
return stream;
|
||||
}
|
||||
public static bool Assert(this Stream stream, char next)
|
||||
{ if (stream.PeekCharUTF8() == next) { stream.ReadCharUTF8(); return true; } else return false; }
|
||||
public static bool Assert(this Stream stream, string next)
|
||||
{
|
||||
for (var i = 0; i < next.Length; i++)
|
||||
if (!stream.Assert(next[i])) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,599 @@
|
||||
using KKdBaseLib;
|
||||
using System;
|
||||
using System.IO;
|
||||
using BaseExtensions = KKdBaseLib.Extensions;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public struct JSON : System.IDisposable
|
||||
{
|
||||
struct ReadBuffer
|
||||
{
|
||||
public char[] data;
|
||||
public int first;
|
||||
public int length;
|
||||
|
||||
public ReadBuffer(int size)
|
||||
{
|
||||
data = new char[size];
|
||||
first = 0;
|
||||
length = 0;
|
||||
}
|
||||
};
|
||||
|
||||
public JSON(Stream _IO) => this._IO = _IO;
|
||||
|
||||
private Stream _IO;
|
||||
|
||||
public void Close() => _IO.C();
|
||||
|
||||
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
|
||||
|
||||
public MsgPack Read()
|
||||
{
|
||||
ReadBuffer buf = new ReadBuffer(0x400);
|
||||
buf.first = 0;
|
||||
buf.length = 0;
|
||||
buf.data[0] = '\0';
|
||||
buf.data[buf.data.Length - 1] = '\0';
|
||||
int c = ReadChar(ref buf);
|
||||
return new MsgPack(null, ReadInner(ref buf, ref c));
|
||||
}
|
||||
|
||||
int ReadChar(ref ReadBuffer buf)
|
||||
{
|
||||
if (buf.length == 0)
|
||||
{
|
||||
buf.first = 1;
|
||||
buf.data[0] = buf.data[buf.data.Length - 1];
|
||||
byte[] temp = _IO.RBy(buf.data.Length - 1);
|
||||
buf.length = temp.Length;
|
||||
Array.Copy(temp, 0, buf.data, 1, temp.Length);
|
||||
}
|
||||
|
||||
if (buf.length < 1)
|
||||
return -1;
|
||||
|
||||
int c = buf.data[buf.first];
|
||||
buf.first++;
|
||||
buf.length--;
|
||||
return c;
|
||||
}
|
||||
|
||||
void Seek(ref ReadBuffer buf, long offset)
|
||||
{
|
||||
if (buf.first < offset || offset >= buf.length - 1L) {
|
||||
long pos = _IO.PI64 - buf.length - offset;
|
||||
long off = pos % buf.data.Length;
|
||||
pos -= off;
|
||||
if (pos > 1)
|
||||
{
|
||||
_IO.S(pos, SeekOrigin.Begin);
|
||||
buf.first = (int)off;
|
||||
byte[] temp = _IO.RBy(buf.data.Length);
|
||||
buf.length = temp.Length;
|
||||
Array.Copy(temp, 0, buf.data, 0, temp.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
_IO.S(pos, SeekOrigin.Begin);
|
||||
buf.first = (int)(off + 1);
|
||||
buf.data[0] = '\0';
|
||||
byte[] temp = _IO.RBy(buf.data.Length - 1);
|
||||
buf.length = temp.Length;
|
||||
Array.Copy(temp, 0, buf.data, 1, temp.Length);
|
||||
}
|
||||
buf.length -= (int)off;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf.first -= (int)offset;
|
||||
buf.length += (int)offset;
|
||||
}
|
||||
}
|
||||
|
||||
void SeekOne(ref ReadBuffer buf)
|
||||
{
|
||||
buf.first--;
|
||||
buf.length++;
|
||||
}
|
||||
|
||||
object ReadInner(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
if (c == -1)
|
||||
return null;
|
||||
|
||||
if (c == ' ' || c == '\n' || c == '\r' || c == '\t')
|
||||
c = ReadChar(ref buf);
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
case '-':
|
||||
return ReadFloat(ref buf, ref c);
|
||||
case '"':
|
||||
return ReadString(ref buf, ref c);
|
||||
case '{':
|
||||
return ReadMap(ref buf, ref c);
|
||||
case '[':
|
||||
return ReadArray(ref buf, ref c);
|
||||
case 't':
|
||||
return ReadBool(ref buf, ref c);
|
||||
case 'f':
|
||||
return ReadBool(ref buf, ref c);
|
||||
case 'n':
|
||||
return ReadNull(ref buf, ref c);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void ReadDigit(ref ReadBuffer buf, ref int c, byte[] dig_buf, ref int dig_buf_pos, int dig_buf_end) {
|
||||
int b = dig_buf_pos;
|
||||
while (c >= '0' && c <= '9' && b < dig_buf_end) {
|
||||
dig_buf[b++] = (byte)c;
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
break;
|
||||
}
|
||||
dig_buf_pos = b;
|
||||
}
|
||||
|
||||
object ReadFloat(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
byte[] dig_buf = new byte[0x100];
|
||||
int buf_pos = 0;
|
||||
int buf_end = dig_buf.Length;
|
||||
bool negate = false;
|
||||
bool zero = false;
|
||||
bool fraction = false;
|
||||
|
||||
if (c == '-')
|
||||
{
|
||||
dig_buf[buf_pos++] = (byte)c;
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
return null;
|
||||
negate = true;
|
||||
}
|
||||
|
||||
if (c == '0')
|
||||
{
|
||||
dig_buf[buf_pos++] = (byte)c;
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
return null;
|
||||
zero = true;
|
||||
}
|
||||
else
|
||||
ReadDigit(ref buf, ref c, dig_buf, ref buf_pos, buf_end);
|
||||
|
||||
if (c == '.')
|
||||
{
|
||||
dig_buf[buf_pos++] = (byte)c;
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
return null;
|
||||
ReadDigit(ref buf, ref c, dig_buf, ref buf_pos, buf_end);
|
||||
fraction = true;
|
||||
}
|
||||
|
||||
if (zero && !fraction)
|
||||
{
|
||||
object obj;
|
||||
if (negate)
|
||||
obj = -0.0f;
|
||||
else
|
||||
obj = 0;
|
||||
SeekOne(ref buf);
|
||||
return obj;
|
||||
}
|
||||
else if (c != 'e' && c != 'E' && !fraction)
|
||||
{
|
||||
string temp = dig_buf.ToUTF8();
|
||||
int null_term = temp.IndexOf('\0');
|
||||
if (null_term >= 0)
|
||||
temp = temp.Substring(0, null_term);
|
||||
if (!long.TryParse(temp, out long val))
|
||||
return null;
|
||||
|
||||
object obj;
|
||||
unchecked
|
||||
{
|
||||
if (val >= 0x00 && val < 0xFF)
|
||||
obj = (byte)val;
|
||||
else if (val >= (sbyte)0x80 && val <= (sbyte)0x7F)
|
||||
obj = (sbyte)val;
|
||||
else if (val >= 0x0000 && val < 0xFFFF)
|
||||
obj = (ushort)val;
|
||||
else if (val >= (short)0x8000 && val <= (short)0x7FFF)
|
||||
obj = (short)val;
|
||||
else if (val >= 0x00000000 && val <= 0xFFFFFFFF)
|
||||
obj = (uint)val;
|
||||
else if (val >= (int)0x80000000 && val <= (int)0x7FFFFFFF)
|
||||
obj = (int)val;
|
||||
else
|
||||
obj = val;
|
||||
}
|
||||
SeekOne(ref buf);
|
||||
return obj;
|
||||
}
|
||||
else if (c == 'e' || c == 'E')
|
||||
{
|
||||
dig_buf[buf_pos++] = (byte)c;
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
return null;
|
||||
|
||||
if (c == '+' || c == '-')
|
||||
{
|
||||
dig_buf[buf_pos++] = (byte)c;
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
return null;
|
||||
}
|
||||
ReadDigit(ref buf, ref c, dig_buf, ref buf_pos, buf_end);
|
||||
}
|
||||
|
||||
string ftemp = dig_buf.ToUTF8();
|
||||
int fnull_term = ftemp.IndexOf('\0');
|
||||
if (fnull_term >= 0)
|
||||
ftemp = ftemp.Substring(0, fnull_term);
|
||||
if (!ftemp.ToF64(out double fval))
|
||||
return null;
|
||||
|
||||
object fobj;
|
||||
if (fval == (float)fval)
|
||||
fobj = (float)fval;
|
||||
else
|
||||
fobj = fval;
|
||||
SeekOne(ref buf);
|
||||
return fobj;
|
||||
}
|
||||
|
||||
byte ReadStringHex(int c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return (byte)(c - '0');
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
return (byte)(c - 'A' + 0xA);
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
return (byte)(c - 'a' + 0xA);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
string ReadStringInner(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
if (c != '"')
|
||||
return null;
|
||||
|
||||
long pos = _IO.PI64 - buf.length;
|
||||
ulong len = 0;
|
||||
while (c != -1)
|
||||
{
|
||||
c = ReadChar(ref buf);
|
||||
if (c == '\\')
|
||||
{
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '"':
|
||||
case '\\':
|
||||
case '/':
|
||||
case 'b':
|
||||
case 'f':
|
||||
case 'n':
|
||||
case 'r':
|
||||
case 't':
|
||||
len++;
|
||||
break;
|
||||
case 'u':
|
||||
{
|
||||
uint uc = 0;
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
break;
|
||||
uc |= (uint)ReadStringHex(c) << 24;
|
||||
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
break;
|
||||
uc |= (uint)ReadStringHex(c) << 16;
|
||||
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
break;
|
||||
uc |= (uint)ReadStringHex(c) << 8;
|
||||
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
break;
|
||||
uc |= (uint)ReadStringHex(c);
|
||||
|
||||
if (uc <= 0x7F)
|
||||
len++;
|
||||
else if (c <= 0x7FF)
|
||||
len += 2;
|
||||
else
|
||||
len += 3;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (c == '"')
|
||||
break;
|
||||
else
|
||||
len++;
|
||||
}
|
||||
if (c == -1)
|
||||
return null;
|
||||
long pos_end = _IO.PI64 - buf.length;
|
||||
|
||||
Seek(ref buf, pos_end - pos);
|
||||
byte[] temp = new byte[len + 1];
|
||||
for (ulong i = 0; i < len;)
|
||||
{
|
||||
c = ReadChar(ref buf);
|
||||
|
||||
if (c == '\\')
|
||||
{
|
||||
c = ReadChar(ref buf);
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '"':
|
||||
temp[i++] = (byte)'"';
|
||||
break;
|
||||
case '\\':
|
||||
temp[i++] = (byte)'\\';
|
||||
break;
|
||||
case '/':
|
||||
temp[i++] = (byte)'/';
|
||||
break;
|
||||
case 'b':
|
||||
temp[i++] = (byte)'\b';
|
||||
break;
|
||||
case 'f':
|
||||
temp[i++] = (byte)'\f';
|
||||
break;
|
||||
case 'n':
|
||||
temp[i++] = (byte)'\n';
|
||||
break;
|
||||
case 'r':
|
||||
temp[i++] = (byte)'\r';
|
||||
break;
|
||||
case 't':
|
||||
temp[i++] = (byte)'\t';
|
||||
break;
|
||||
case 'u':
|
||||
{
|
||||
uint uc = 0;
|
||||
uc |= (uint)ReadStringHex(ReadChar(ref buf)) << 24;
|
||||
uc |= (uint)ReadStringHex(ReadChar(ref buf)) << 16;
|
||||
uc |= (uint)ReadStringHex(ReadChar(ref buf)) << 8;
|
||||
uc |= (uint)ReadStringHex(ReadChar(ref buf));
|
||||
if (uc <= 0x7F)
|
||||
temp[i] = (byte)uc;
|
||||
else if (uc <= 0x7FF)
|
||||
{
|
||||
temp[i++] = (byte)(0xC0 | ((uc >> 6) & 0x1F));
|
||||
temp[i] = (byte)(0x80 | (uc & 0x3F));
|
||||
}
|
||||
else
|
||||
{
|
||||
temp[i++] = (byte)(0xE0 | ((uc >> 12) & 0xF));
|
||||
temp[i++] = (byte)(0x80 | ((uc >> 6) & 0x3F));
|
||||
temp[i++] = (byte)(0x80 | (uc & 0x3F));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (c == '"')
|
||||
break;
|
||||
else
|
||||
temp[i++] = (byte)c;
|
||||
}
|
||||
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
return null;
|
||||
|
||||
string str = temp.ToUTF8();
|
||||
int null_term = str.IndexOf('\0');
|
||||
if (null_term >= 0)
|
||||
str = str.Substring(0, null_term);
|
||||
return str;
|
||||
}
|
||||
|
||||
object ReadString(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
return ReadStringInner(ref buf, ref c);
|
||||
}
|
||||
|
||||
void ReadSkipWhitespace(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
while ((c = ReadChar(ref buf)) != -1)
|
||||
{
|
||||
if (c == ' ' || c == '\n' || c == '\r' || c == '\t')
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
object ReadMap(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
KKdList<MsgPack> map = KKdList<MsgPack>.New;
|
||||
if (c != '}')
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
ReadSkipWhitespace(ref buf, ref c);
|
||||
|
||||
if (c == '}')
|
||||
break;
|
||||
|
||||
string key = ReadStringInner(ref buf, ref c);
|
||||
if (key == null)
|
||||
return null;
|
||||
|
||||
ReadSkipWhitespace(ref buf, ref c);
|
||||
if (c != ':')
|
||||
return null;
|
||||
ReadSkipWhitespace(ref buf, ref c);
|
||||
|
||||
map.Add(new MsgPack(key, ReadInner(ref buf, ref c)));
|
||||
|
||||
ReadSkipWhitespace(ref buf, ref c);
|
||||
|
||||
if (c == '}')
|
||||
break;
|
||||
else if (c != ',')
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
map.Capacity = map.Count;
|
||||
return map;
|
||||
}
|
||||
|
||||
object ReadArray(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
KKdList<MsgPack> array = KKdList<MsgPack>.New;
|
||||
if (c != ']')
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
ReadSkipWhitespace(ref buf, ref c);
|
||||
|
||||
if (c == ']')
|
||||
break;
|
||||
|
||||
array.Add(new MsgPack(null, ReadInner(ref buf, ref c)));
|
||||
|
||||
ReadSkipWhitespace(ref buf, ref c);
|
||||
|
||||
if (c == ']')
|
||||
break;
|
||||
else if (c != ',')
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
array.Capacity = array.Count;
|
||||
return array.ToArray();
|
||||
}
|
||||
|
||||
object ReadBool(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
if (c != 't')
|
||||
{
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'a')
|
||||
return null;
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'l')
|
||||
return null;
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 's')
|
||||
return null;
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'e')
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'r')
|
||||
return null;
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'u')
|
||||
return null;
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'e')
|
||||
return null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
object ReadNull(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'u')
|
||||
return null;
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'l')
|
||||
return null;
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'l')
|
||||
return null;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public JSON W(MsgPack msgPack, bool ignoreNull, string end = "\n", string tabChar = " ") =>
|
||||
W(msgPack, ignoreNull, end, tabChar, "", true);
|
||||
|
||||
public JSON W(MsgPack msgPack, bool ignoreNull, bool style = false) =>
|
||||
W(msgPack, ignoreNull, "\n", " ", "", style);
|
||||
|
||||
private JSON W(MsgPack msgPack, bool ignoreNull, string end,
|
||||
string tabChar, string tab, bool style, bool isArray = false)
|
||||
{
|
||||
string oldTab = tab;
|
||||
tab += tabChar;
|
||||
if (msgPack.Name != null && !isArray ) _IO.W("\"" + msgPack.Name + "\":" + (style ? " " : ""));
|
||||
if (msgPack.Object == null) { if (!ignoreNull) WN(); return this; }
|
||||
|
||||
if (msgPack.List.NotNull)
|
||||
{
|
||||
WM();
|
||||
if (style) _IO.W(end);
|
||||
if (msgPack.List.Count > 1)
|
||||
for (int i = 0; i < msgPack.List.Count; i++)
|
||||
{
|
||||
if (style) _IO.W(tab);
|
||||
W(msgPack.List[i], ignoreNull, end, tabChar, tab, style);
|
||||
if (i + 1 < msgPack.List.Count) _IO.W(',');
|
||||
if (style) _IO.W(end);
|
||||
}
|
||||
else if (msgPack.List.Count == 1)
|
||||
{
|
||||
if (style) _IO.W(tab);
|
||||
W(msgPack.List[0], ignoreNull, end, tabChar, tab, style);
|
||||
if (style) _IO.W(end);
|
||||
}
|
||||
if (style) _IO.W(oldTab);
|
||||
WM(true);
|
||||
}
|
||||
else if (msgPack.Array != null)
|
||||
{
|
||||
WA();
|
||||
if (style) _IO.W(end);
|
||||
if (msgPack.Array.Length > 1)
|
||||
for (int i = 0; i < msgPack.Array.Length; i++)
|
||||
{
|
||||
if (style) _IO.W(tab);
|
||||
W(msgPack.Array[i], ignoreNull, end, tabChar, tab, style, true);
|
||||
if (i + 1 < msgPack.Array.Length) _IO.W(',');
|
||||
if (style) _IO.W(end);
|
||||
}
|
||||
else if (msgPack.Array.Length == 1)
|
||||
{
|
||||
if (style) _IO.W(tab);
|
||||
W(msgPack.Array[0], ignoreNull, end, tabChar, tab, style, true);
|
||||
if (style) _IO.W(end);
|
||||
}
|
||||
if (style) _IO.W(oldTab);
|
||||
WA(true);
|
||||
}
|
||||
else if (msgPack.Object is MsgPack msg) W(msg, ignoreNull, end, tabChar, tab, style);
|
||||
else if (msgPack.Object is string str) W(str);
|
||||
else _IO.W(BaseExtensions.ToS(msgPack.Object));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void Dispose() => _IO.C();
|
||||
|
||||
private void W(string val) => _IO.W("\"" + val
|
||||
.Replace("\\", "\\\\").Replace("/" , "\\/").Replace("\"", "\\\"")
|
||||
.Replace("\0", "\\0" ).Replace("\b", "\\b").Replace("\f", "\\f" )
|
||||
.Replace("\n", "\\n" ).Replace("\r", "\\r").Replace("\t", "\\t" ) + "\"");
|
||||
|
||||
private void WN() => _IO.W("null");
|
||||
private void WA(bool End = false) => _IO.W(End ? "]" : "[");
|
||||
private void WM(bool End = false) => _IO.W(End ? "}" : "{");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,342 @@
|
||||
using KKdBaseLib;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public struct MP : System.IDisposable
|
||||
{
|
||||
public MP(Stream _IO) => this._IO = _IO;
|
||||
|
||||
private Stream _IO;
|
||||
|
||||
public void Close() => _IO.C();
|
||||
|
||||
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
|
||||
|
||||
public MsgPack Read(bool array = false)
|
||||
{
|
||||
MsgPack msgPack = MsgPack.New;
|
||||
byte unk = _IO.RU8();
|
||||
if (!array) { msgPack.Name = RS((Types)unk); unk = _IO.RU8(); }
|
||||
Types type = (Types)unk;
|
||||
|
||||
if (type >= Types.FixMap && type <= Types.FixMapMax)
|
||||
{
|
||||
msgPack.Object = KKdList<MsgPack>.New;
|
||||
for (int i = 0; i < unk - (byte)Types.FixMap; i++) msgPack.Add( Read(false));
|
||||
}
|
||||
else if (type >= Types.FixArr && type <= Types.FixArrMax)
|
||||
{
|
||||
msgPack.Object = new MsgPack[unk - (byte)Types.FixArr];
|
||||
for (int i = 0; i < unk - (byte)Types.FixArr; i++) msgPack[i] = Read( true);
|
||||
}
|
||||
else if (type >= Types.FixStr && type <= Types.FixStrMax) msgPack.Object = RS(type);
|
||||
else if (type >= Types.PosInt && type <= Types.PosIntMax) msgPack.Object = unk;
|
||||
else if (type >= Types.NegInt && type <= Types.NegIntMax) msgPack.Object = (sbyte)unk;
|
||||
else
|
||||
while (true)
|
||||
{
|
||||
if (RN (ref msgPack, ref type)) break;
|
||||
if (RBy(ref msgPack, ref type)) break;
|
||||
if (RM (ref msgPack, ref type)) break;
|
||||
if (RE (ref msgPack, ref type)) break;
|
||||
if (RS (ref msgPack, ref type)) break;
|
||||
if (RBo(ref msgPack, ref type)) break;
|
||||
if (RA (ref msgPack, ref type)) break;
|
||||
if (RI (ref msgPack, ref type)) break;
|
||||
if (RU (ref msgPack, ref type)) break;
|
||||
if (RF (ref msgPack, ref type)) break;
|
||||
break;
|
||||
}
|
||||
return msgPack;
|
||||
}
|
||||
|
||||
private bool RI(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
if (type == Types.Int8 ) msgPack.Object = _IO.RI8();
|
||||
else if (type == Types.Int16) msgPack.Object = _IO.RI16E(true);
|
||||
else if (type == Types.Int32) msgPack.Object = _IO.RI32E(true);
|
||||
else if (type == Types.Int64) msgPack.Object = _IO.RI64E(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RU(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
if (type == Types.UInt8 ) msgPack.Object = _IO.RU8();
|
||||
else if (type == Types.UInt16) msgPack.Object = _IO.RU16E(true);
|
||||
else if (type == Types.UInt32) msgPack.Object = _IO.RU32E(true);
|
||||
else if (type == Types.UInt64) msgPack.Object = _IO.RU64E(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RF(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
if (type == Types.Float32) msgPack.Object = _IO.RF32E(true);
|
||||
else if (type == Types.Float64) msgPack.Object = _IO.RF64E(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RBo(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
if (type == Types.False) msgPack.Object = false;
|
||||
else if (type == Types.True ) msgPack.Object = true ;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RBy(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (type == Types.Bin8 ) Length = _IO.RU8();
|
||||
else if (type == Types.Bin16) Length = _IO.RI16E(true);
|
||||
else if (type == Types.Bin32) Length = _IO.RI32E(true);
|
||||
else return false;
|
||||
msgPack.Object = _IO.RBy(Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RS(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
string val = RS(type);
|
||||
if (val != null) msgPack.Object = val;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private string RS(Types val)
|
||||
{
|
||||
if (val >= Types.FixStr && val <= Types.FixStrMax)
|
||||
return _IO.RS(val - Types.FixStr);
|
||||
else if (val >= Types. Str8 && val <= Types. Str32 )
|
||||
{
|
||||
System.Enum.TryParse(val.ToString(), out Types type);
|
||||
int Length = 0;
|
||||
if (type == Types.Str8 ) Length = _IO.RU8();
|
||||
else if (type == Types.Str16) Length = _IO.RI16E(true);
|
||||
else Length = _IO.RI32E(true);
|
||||
return _IO.RS(Length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool RN(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
if (type == Types.Nil) msgPack.Object = null;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RA(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (type == Types.Arr16) Length = _IO.RI16E(true);
|
||||
else if (type == Types.Arr32) Length = _IO.RI32E(true);
|
||||
else return false;
|
||||
msgPack.Object = new MsgPack[Length];
|
||||
for (int i = 0; i < Length; i++) msgPack[i] = Read(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RM(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (type == Types.Map16) Length = _IO.RI16E(true);
|
||||
else if (type == Types.Map32) Length = _IO.RI32E(true);
|
||||
else return false;
|
||||
msgPack.Object = KKdList<MsgPack>.New;
|
||||
for (int i = 0; i < Length; i++) msgPack.Add(Read());
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RE(ref MsgPack MsgPack, ref Types type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (type == Types.FixExt1 ) Length = 1 ;
|
||||
else if (type == Types.FixExt2 ) Length = 2 ;
|
||||
else if (type == Types.FixExt4 ) Length = 4 ;
|
||||
else if (type == Types.FixExt8 ) Length = 8 ;
|
||||
else if (type == Types.FixExt16) Length = 16;
|
||||
else if (type == Types. Ext8 ) Length = _IO.RU8();
|
||||
else if (type == Types. Ext16) Length = _IO.RI16E(true);
|
||||
else if (type == Types. Ext32) Length = _IO.RI32E(true);
|
||||
else return false;
|
||||
MsgPack.Object = new MsgPack.Ext { Type = _IO.RI8(), Data = _IO.RBy(Length) };
|
||||
return true;
|
||||
}
|
||||
|
||||
public MP W(MsgPack msgPack, bool ignoreNull, bool IsArray = false)
|
||||
{
|
||||
if (msgPack.Name != null && !IsArray) W(msgPack.Name);
|
||||
Write(msgPack.Object, ignoreNull);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void Write(object obj, bool ignoreNull)
|
||||
{
|
||||
if (obj == null) { if (!ignoreNull) WN(); return; }
|
||||
switch (obj)
|
||||
{
|
||||
case KKdList<MsgPack> val: WM(val.Count );
|
||||
for (int i = 0; i < val.Count ; i++) W(val[i], ignoreNull); break;
|
||||
case MsgPack[] val: WA(val.Length);
|
||||
for (int i = 0; i < val.Length; i++) W(val[i], ignoreNull); break;
|
||||
case MsgPack val: W(val, ignoreNull); break;
|
||||
case byte[] val: W(val); break;
|
||||
case bool val: W(val); break;
|
||||
case sbyte val: W(val); break;
|
||||
case byte val: W(val); break;
|
||||
case short val: W(val); break;
|
||||
case ushort val: W(val); break;
|
||||
case int val: W(val); break;
|
||||
case uint val: W(val); break;
|
||||
case long val: W(val); break;
|
||||
case ulong val: W(val); break;
|
||||
case float val: W(val); break;
|
||||
case double val: W(val); break;
|
||||
case string val: W(val); break;
|
||||
case MsgPack.Ext val: W(val); break;
|
||||
}
|
||||
}
|
||||
|
||||
private void W( sbyte val) { if (val < -0x20) _IO.W((byte)0xD0); _IO.W(val); }
|
||||
private void W( byte val) { if (val >= 0x80) _IO.W((byte)0xCC); _IO.W(val); }
|
||||
private void W( short val) { if (( sbyte)val == val) W(( sbyte)val);
|
||||
else if (( byte)val == val) W(( byte)val);
|
||||
else { _IO.W((byte)0xD1); _IO.WE(val, true); } }
|
||||
private void W(ushort val) { if (( byte)val == val) W(( byte)val);
|
||||
else { _IO.W((byte)0xCD); _IO.WE(val, true); } }
|
||||
private void W( int val) { if (( short)val == val) W(( short)val);
|
||||
else if ((ushort)val == val) W((ushort)val);
|
||||
else { _IO.W((byte)0xD2); _IO.WE(val, true); } }
|
||||
private void W( uint val) { if ((ushort)val == val) W((ushort)val);
|
||||
else { _IO.W((byte)0xCE); _IO.WE(val, true); } }
|
||||
private void W( long val) { if (( int)val == val) W(( int)val);
|
||||
else if (( uint)val == val) W(( uint)val);
|
||||
else { _IO.W((byte)0xD3); _IO.WE(val, true); } }
|
||||
private void W( ulong val) { if (( uint)val == val) W(( uint)val);
|
||||
else { _IO.W((byte)0xCF); _IO.WE(val, true); } }
|
||||
private void W( float val) { if (( long)val == val) W(( long)val);
|
||||
else { _IO.W((byte)0xCA); _IO.WE(val, true); } }
|
||||
private void W(double val) { if (( long)val == val) W(( long)val);
|
||||
else if (( float)val == val) W(( float)val);
|
||||
else { _IO.W((byte)0xCB); _IO.WE(val, true); } }
|
||||
|
||||
private void W( bool val) =>
|
||||
_IO.W((byte)(val ? 0xC3 : 0xC2));
|
||||
|
||||
private void W(byte[] val)
|
||||
{
|
||||
if (val == null) { WN(); return; }
|
||||
|
||||
if (val.Length < 0x100) { _IO.W((byte)0xC4); _IO.W (( byte)val.Length ); }
|
||||
else if (val.Length < 0x10000) { _IO.W((byte)0xC5); _IO.WE((ushort)val.Length, true); }
|
||||
else { _IO.W((byte)0xC6); _IO.WE( val.Length, true); }
|
||||
_IO.W(val);
|
||||
}
|
||||
|
||||
private void W(string val)
|
||||
{
|
||||
if (val == null) { WN(); return; }
|
||||
|
||||
byte[] array = Text.ToUTF8(val);
|
||||
if (array.Length < 0x20) _IO.W((byte)(0xA0 | (array.Length & 0x1F)));
|
||||
else if (array.Length < 0x100) { _IO.W((byte)0xD9); _IO.W (( byte)array.Length); }
|
||||
else if (array.Length < 0x10000) { _IO.W((byte)0xDA); _IO.WE((ushort)array.Length, true); }
|
||||
else { _IO.W((byte)0xDB); _IO.WE( array.Length, true); }
|
||||
_IO.W(array);
|
||||
}
|
||||
|
||||
private void WN() => _IO.W((byte)0xC0);
|
||||
|
||||
private void WA(int val)
|
||||
{
|
||||
if (val == 0) { WN(); return; }
|
||||
else if (val < 0x10) _IO.W((byte)(0x90 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.W((byte)0xDC); _IO.WE((ushort)val, true); }
|
||||
else { _IO.W((byte)0xDD); _IO.WE( val, true); }
|
||||
}
|
||||
|
||||
private void WM(int val)
|
||||
{
|
||||
if (val == 0) { WN(); return; }
|
||||
else if (val < 0x10) _IO.W((byte)(0x80 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.W((byte)0xDE); _IO.WE((ushort)val, true); }
|
||||
else { _IO.W((byte)0xDF); _IO.WE( val, true); }
|
||||
}
|
||||
|
||||
private void W(MsgPack.Ext val) => WE(val);
|
||||
|
||||
private void WE(MsgPack.Ext val)
|
||||
{
|
||||
if (val.Data == null) { WN(); return; }
|
||||
|
||||
if (val.Data.Length < 1 ) { WN(); return; }
|
||||
else if (val.Data.Length == 1 ) _IO.W((byte)0xD4);
|
||||
else if (val.Data.Length == 2 ) _IO.W((byte)0xD5);
|
||||
else if (val.Data.Length == 4 ) _IO.W((byte)0xD6);
|
||||
else if (val.Data.Length == 8 ) _IO.W((byte)0xD7);
|
||||
else if (val.Data.Length == 16) _IO.W((byte)0xD8);
|
||||
else
|
||||
{
|
||||
if (val.Data.Length < 0x100)
|
||||
{ _IO.W((byte)0xC7); _IO.W (( byte)val.Data.Length); }
|
||||
else if (val.Data.Length < 0x10000)
|
||||
{ _IO.W((byte)0xC8); _IO.WE((ushort)val.Data.Length, true); }
|
||||
else
|
||||
{ _IO.W((byte)0xC9); _IO.WE( val.Data.Length, true); }
|
||||
}
|
||||
_IO.W(val.Type);
|
||||
_IO.W(val.Data);
|
||||
}
|
||||
|
||||
public void Dispose() => _IO.C();
|
||||
}
|
||||
|
||||
public enum Types : byte
|
||||
{
|
||||
PosInt = 0b00000000,
|
||||
FixMap = 0b10000000,
|
||||
FixArr = 0b10010000,
|
||||
FixStr = 0b10100000,
|
||||
Nil = 0b11000000,
|
||||
NeverUsed = 0b11000001,
|
||||
False = 0b11000010,
|
||||
True = 0b11000011,
|
||||
Bin8 = 0b11000100,
|
||||
Bin16 = 0b11000101,
|
||||
Bin32 = 0b11000110,
|
||||
Ext8 = 0b11000111,
|
||||
Ext16 = 0b11001000,
|
||||
Ext32 = 0b11001001,
|
||||
Float32 = 0b11001010,
|
||||
Float64 = 0b11001011,
|
||||
UInt8 = 0b11001100,
|
||||
UInt16 = 0b11001101,
|
||||
UInt32 = 0b11001110,
|
||||
UInt64 = 0b11001111,
|
||||
Int8 = 0b11010000,
|
||||
Int16 = 0b11010001,
|
||||
Int32 = 0b11010010,
|
||||
Int64 = 0b11010011,
|
||||
FixExt1 = 0b11010100,
|
||||
FixExt2 = 0b11010101,
|
||||
FixExt4 = 0b11010110,
|
||||
FixExt8 = 0b11010111,
|
||||
FixExt16 = 0b11011000,
|
||||
Str8 = 0b11011001,
|
||||
Str16 = 0b11011010,
|
||||
Str32 = 0b11011011,
|
||||
Arr16 = 0b11011100,
|
||||
Arr32 = 0b11011101,
|
||||
Map16 = 0b11011110,
|
||||
Map32 = 0b11011111,
|
||||
NegInt = 0b11100000,
|
||||
PosIntMax = 0b01111111,
|
||||
FixMapMax = 0b10001111,
|
||||
FixArrMax = 0b10011111,
|
||||
FixStrMax = 0b10111111,
|
||||
NegIntMax = 0b11111111,
|
||||
}
|
||||
}
|
||||
+62
-15
@@ -1,25 +1,72 @@
|
||||
using System;
|
||||
using MSIO = System.IO;
|
||||
using MSIOP = System.IO.Path;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public static class Path
|
||||
{
|
||||
public static string GetFileName(string path) =>
|
||||
MSIO.Path.GetFileName(path);
|
||||
public static string GetFileNameWithoutExtension(string path) =>
|
||||
MSIO.Path.GetFileNameWithoutExtension(path);
|
||||
public static string GetExtension(string path) =>
|
||||
MSIO.Path.GetExtension(path);
|
||||
public static string GetFullPath(string path) =>
|
||||
MSIO.Path.GetFullPath(path);
|
||||
public static string Combine(string path1, string path2) =>
|
||||
MSIO.Path.Combine(path1, path2);
|
||||
public static char DirectorySeparatorChar => MSIOP.DirectorySeparatorChar;
|
||||
public static char AltDirectorySeparatorChar => MSIOP.AltDirectorySeparatorChar;
|
||||
public static char VolumeSeparatorChar => MSIOP.VolumeSeparatorChar;
|
||||
public static char PathSeparator => MSIOP.PathSeparator;
|
||||
|
||||
public static string ChangeExtension(string path, string extension) =>
|
||||
MSIOP.ChangeExtension(path, extension);
|
||||
|
||||
public static string Combine(string path1, string path2, string path3) =>
|
||||
MSIO.Path.Combine(path1, path2, path3);
|
||||
MSIOP.Combine(path1, path2, path3);
|
||||
|
||||
public static string Combine(string path1, string path2) =>
|
||||
MSIOP.Combine(path1, path2);
|
||||
|
||||
public static string Combine(string path1, string path2, string path3, string path4) =>
|
||||
MSIO.Path.Combine(path1, path2, path3, path4);
|
||||
MSIOP.Combine(path1, path2, path3, path4);
|
||||
|
||||
public static string Combine(params string[] paths) =>
|
||||
MSIO.Path.Combine(paths);
|
||||
MSIOP.Combine(paths);
|
||||
|
||||
public static string GetDirectoryName(string path) =>
|
||||
MSIOP.GetDirectoryName(path);
|
||||
|
||||
public static string GetExtension(string path) =>
|
||||
MSIOP.GetExtension(path);
|
||||
|
||||
public static string GetFileName(string path) =>
|
||||
MSIOP.GetFileName(path);
|
||||
|
||||
public static string GetFileNameWithoutExtension(string path) =>
|
||||
MSIOP.GetFileNameWithoutExtension(path);
|
||||
|
||||
public static string GetFullPath(string path) =>
|
||||
MSIOP.GetFullPath(path);
|
||||
|
||||
public static char[] GetInvalidFileNameChars() =>
|
||||
MSIOP.GetInvalidFileNameChars();
|
||||
|
||||
public static char[] GetInvalidPathChars() =>
|
||||
MSIOP.GetInvalidPathChars();
|
||||
|
||||
public static string GetPathRoot(string path) =>
|
||||
MSIOP.GetPathRoot(path);
|
||||
|
||||
public static string GetRandomFileName() =>
|
||||
MSIOP.GetRandomFileName();
|
||||
|
||||
public static string GetTempFileName() =>
|
||||
MSIOP.GetTempFileName();
|
||||
|
||||
public static string GetTempPath() =>
|
||||
MSIOP.GetTempPath();
|
||||
|
||||
public static bool HasExtension(string path) =>
|
||||
MSIOP.HasExtension(path);
|
||||
|
||||
public static bool IsPathRooted(string path) =>
|
||||
MSIOP.IsPathRooted(path);
|
||||
|
||||
public static string RemoveExtension(string path) =>
|
||||
path.Substring(0, path.Length - GetExtension(path).Length);
|
||||
|
||||
public static string ReplaceExtension(string path, string ext) =>
|
||||
path.Substring(0, path.Length - GetExtension(path).Length) + ext;
|
||||
}
|
||||
}
|
||||
|
||||
+352
-289
@@ -1,376 +1,439 @@
|
||||
using System;
|
||||
using KKdMainLib.Types;
|
||||
using System;
|
||||
using KKdBaseLib;
|
||||
using MSIO = System.IO;
|
||||
using ENRSDict = System.Collections.Generic.Dictionary<long, byte>;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public unsafe class Stream : IDisposable
|
||||
{
|
||||
private MSIO.Stream stream;
|
||||
private int i, i0, TempBitRead, TempBitWrite;
|
||||
private ushort ValRead;
|
||||
private byte BitRead, BitWrite, ValWrite;
|
||||
private byte[] buf;
|
||||
private byte[] data;
|
||||
private int i, j, bitRead, bitWrite, tempBitRead, tempBitWrite, valRead, valWrite;
|
||||
private byte[] b;
|
||||
private MSIO.Stream s;
|
||||
|
||||
private Main.Format _format = Main.Format.NULL;
|
||||
private readonly bool canRead;
|
||||
private readonly bool canWrite;
|
||||
|
||||
public Main.Format Format
|
||||
{ get => _format;
|
||||
set { _format = value;
|
||||
IsBE = _format == Main.Format.F2BE;
|
||||
IsX = _format == Main.Format.X || _format == Main.Format.XHD; } }
|
||||
private bool getENRS;
|
||||
|
||||
private Format format = Format.NULL;
|
||||
|
||||
public Format Format
|
||||
{ get => format;
|
||||
set { format = value; IsX = format == Format.X || format == Format.XHD; } }
|
||||
|
||||
public ENRSDict ENRSDict;
|
||||
|
||||
public bool IsBE = false;
|
||||
public bool IsX = false;
|
||||
public bool GetENRS
|
||||
{ get => getENRS;
|
||||
set { if (value && ENRSDict == null)
|
||||
ENRSDict = new ENRSDict(); getENRS = value; } }
|
||||
|
||||
public int Offset { get => ( int)LongOffset; set => LongOffset = value; }
|
||||
public uint UIntOffset { get => (uint)LongOffset; set => LongOffset = value; }
|
||||
public long LongOffset;
|
||||
public int O { get => ( int)OI64; set => OI64 = value; }
|
||||
public uint OU32 { get => (uint)OI64; set => OI64 = value; }
|
||||
public long OI64;
|
||||
|
||||
public int Length { get => ( int)stream.Length; set => stream.SetLength(value); }
|
||||
public uint UIntLength { get => (uint)stream.Length; set => stream.SetLength(value); }
|
||||
public long LongLength { get => stream.Length; set => stream.SetLength(value); }
|
||||
public int L { get => ( int)s.Length - O; set => s.SetLength(value + O ); }
|
||||
public uint LU32 { get => (uint)s.Length - OU32; set => s.SetLength(value + OU32); }
|
||||
public long LI64 { get => s.Length - OI64; set => s.SetLength(value + OI64); }
|
||||
|
||||
public int Position
|
||||
{ get => ( int)stream.Position - Offset; set => stream.Position = value + Offset; }
|
||||
public uint UIntPosition
|
||||
{ get => (uint)stream.Position - UIntOffset; set => stream.Position = value + UIntOffset; }
|
||||
public long LongPosition
|
||||
{ get => stream.Position - LongOffset; set => stream.Position = value + LongOffset; }
|
||||
public int P { get => ( int)s.Position - O; set => s.Position = value + O ; }
|
||||
public uint PU32 { get => (uint)s.Position - OU32; set => s.Position = value + OU32; }
|
||||
public long PI64 { get => s.Position - OI64; set => s.Position = value + OI64; }
|
||||
|
||||
public bool CanRead => stream.CanRead;
|
||||
public bool CanSeek => stream.CanSeek;
|
||||
public bool CanTimeout => stream.CanTimeout;
|
||||
public bool CanWrite => stream.CanWrite;
|
||||
public bool CanRead => canRead ;
|
||||
public bool CanSeek => s.CanSeek;
|
||||
public bool CanTimeout => s.CanTimeout;
|
||||
public bool CanWrite => s.CanWrite && canWrite;
|
||||
|
||||
public string File = null;
|
||||
|
||||
public Stream(MSIO.Stream output = null, byte[] Data = null, bool isBE = false)
|
||||
public Stream(MSIO.Stream output = null, bool isBE = false, bool canRead = true, bool canWrite = true)
|
||||
{
|
||||
if (output == null) output = MSIO.Stream.Null;
|
||||
LongOffset = 0;
|
||||
BitRead = 8;
|
||||
ValRead = ValRead = BitWrite = 0;
|
||||
stream = output;
|
||||
Format = Main.Format.NULL;
|
||||
buf = new byte[16];
|
||||
OI64 = 0;
|
||||
bitRead = 8;
|
||||
valRead = valRead = bitWrite = 0;
|
||||
s = output;
|
||||
Format = Format.NULL;
|
||||
b = new byte[0x100];
|
||||
IsBE = isBE;
|
||||
data = Data;
|
||||
this.canRead = s.CanRead && canRead;
|
||||
this.canWrite = s.CanWrite && canWrite;
|
||||
}
|
||||
|
||||
public void Close() => Dispose();
|
||||
public void C() => D(true);
|
||||
|
||||
public void Flush() => stream.Flush();
|
||||
public void F() => s.Flush();
|
||||
|
||||
public void SetLength(long length = 0) => stream.SetLength(length);
|
||||
public void SL(long length = 0) => s.SetLength(length);
|
||||
|
||||
public long Seek(long offset, SeekOrigin origin = 0) =>
|
||||
stream.Seek(offset, (MSIO.SeekOrigin)(int)origin);
|
||||
|
||||
public long? Seek(long? offset, SeekOrigin origin)
|
||||
{ if (offset == null) return null; return stream.Seek((long)offset, (MSIO.SeekOrigin)(int)origin); }
|
||||
public long S(long offset, SeekOrigin origin = 0) =>
|
||||
s.Seek(offset + O, (MSIO.SeekOrigin)(int)origin);
|
||||
|
||||
public void Dispose()
|
||||
{ CheckWrited(); Dispose(true); }
|
||||
public long? S(long? offset, SeekOrigin origin)
|
||||
{ if (offset == null) return null;
|
||||
return s.Seek((long)offset + O, (MSIO.SeekOrigin)(int)origin); }
|
||||
|
||||
private void Dispose(bool disposing)
|
||||
{ if (disposing && stream != MSIO.Stream.Null) stream.Flush(); stream.Dispose(); data = null; }
|
||||
private bool disposed = false;
|
||||
public void D() => D(true);
|
||||
public void Dispose() => D(true);
|
||||
|
||||
public MSIO.Stream BaseStream
|
||||
{ get { stream.Flush(); return stream; } set { stream = value; } }
|
||||
protected virtual void D(bool dispose)
|
||||
{ CW(); if (ENRSDict != null) { ENRSDict.Clear(); ENRSDict = null; }
|
||||
if (s != MSIO.Stream.Null && !disposed) { disposed = true; s.Flush();
|
||||
s.Dispose(); } if (dispose) GC.SuppressFinalize(this); }
|
||||
|
||||
public void Align(long Align)
|
||||
public MSIO.Stream BS
|
||||
{ get { s.Flush(); return s; } set { s = value; } }
|
||||
|
||||
public void A(long align)
|
||||
{
|
||||
long Al = Align - Position % Align;
|
||||
if (Position % Align != 0)
|
||||
stream.Seek(Position + Al, 0);
|
||||
long Al = align - P % align;
|
||||
if (P % align != 0) s.Seek(P + O + Al, 0);
|
||||
}
|
||||
|
||||
public void Align(long Align, bool SetLength)
|
||||
public void A(long align, bool setLength)
|
||||
{
|
||||
if (SetLength) stream.SetLength(Position);
|
||||
long Al = Align - Position % Align;
|
||||
if (Position % Align != 0) stream.Seek(Position + Al, 0);
|
||||
if (SetLength) stream.SetLength(Position);
|
||||
if (setLength) s.SetLength(P + O);
|
||||
long Al = align - P % align;
|
||||
if (P % align != 0) s.Seek(P + O + Al, 0);
|
||||
if (setLength) s.SetLength(P + O);
|
||||
}
|
||||
|
||||
public void Align(long Align, bool SetLength0, bool SetLength1)
|
||||
public void A(long align, bool setLength0, bool setLength1)
|
||||
{
|
||||
if (SetLength0) stream.SetLength(Position);
|
||||
long Al = Align - Position % Align;
|
||||
if (Position % Align != 0) stream.Seek(Position + Al, 0);
|
||||
if (SetLength1) stream.SetLength(Position);
|
||||
if (setLength0) s.SetLength(P + O);
|
||||
long Al = align - P % align;
|
||||
if (P % align != 0) s.Seek(P + Al, 0);
|
||||
if (setLength1) s.SetLength(P + O);
|
||||
}
|
||||
|
||||
public bool ReadBoolean() => stream.ReadByte() == 1;
|
||||
public sbyte ReadSByte() => ( sbyte)stream.ReadByte();
|
||||
public byte ReadByte() => ( byte)stream.ReadByte();
|
||||
public sbyte ReadInt8() => ( sbyte) IntFromArray(1);
|
||||
public byte ReadUInt8() => ( byte)UIntFromArray(1);
|
||||
public short ReadInt16() => ( short) IntFromArray(2);
|
||||
public ushort ReadUInt16() => (ushort)UIntFromArray(2);
|
||||
public int ReadInt24() => ( int) IntFromArray(3);
|
||||
public int ReadInt32() => ( int) IntFromArray(4);
|
||||
public uint ReadUInt32() => ( uint)UIntFromArray(4);
|
||||
public long ReadInt64() => IntFromArray(8);
|
||||
public ulong ReadUInt64() => UIntFromArray(8);
|
||||
public Half ReadHalf() { ushort a = ReadUInt16(); return ( Half ) a; }
|
||||
public float ReadSingle() { uint a = ReadUInt32(); return *( float*)&a; }
|
||||
public double ReadDouble() { ulong a = ReadUInt64(); return *(double*)&a; }
|
||||
|
||||
public short ReadInt16Endian() => ( short) IntFromArray(2, IsBE);
|
||||
public ushort ReadUInt16Endian() => (ushort)UIntFromArray(2, IsBE);
|
||||
public int ReadInt24Endian() => ( int) IntFromArray(3, IsBE);
|
||||
public int ReadInt32Endian() => ( int) IntFromArray(4, IsBE);
|
||||
public uint ReadUInt32Endian() => ( uint)UIntFromArray(4, IsBE);
|
||||
public long ReadInt64Endian() => IntFromArray(8, IsBE);
|
||||
public ulong ReadUInt64Endian() => UIntFromArray(8, IsBE);
|
||||
public Half ReadHalfEndian() { ushort a = ReadUInt16Endian(); return ( Half ) a; }
|
||||
public float ReadSingleEndian() { uint a = ReadUInt32Endian(); return *( float*)&a; }
|
||||
public double ReadDoubleEndian() { ulong a = ReadUInt64Endian(); return *(double*)&a; }
|
||||
private void cR() { if (!canRead ) throw new Exception("Stream cannot be read!"); }
|
||||
private void cW() { if (!canWrite) throw new Exception("Stream cannot be read!"); }
|
||||
|
||||
public short ReadInt16Endian(bool IsBE) => ( short) IntFromArray(2, IsBE);
|
||||
public ushort ReadUInt16Endian(bool IsBE) => (ushort)UIntFromArray(2, IsBE);
|
||||
public int ReadInt24Endian(bool IsBE) => ( int) IntFromArray(3, IsBE);
|
||||
public int ReadInt32Endian(bool IsBE) => ( int) IntFromArray(4, IsBE);
|
||||
public uint ReadUInt32Endian(bool IsBE) => ( uint)UIntFromArray(4, IsBE);
|
||||
public long ReadInt64Endian(bool IsBE) => IntFromArray(8, IsBE);
|
||||
public ulong ReadUInt64Endian(bool IsBE) => UIntFromArray(8, IsBE);
|
||||
public Half ReadHalfEndian(bool IsBE)
|
||||
{ ushort a = ReadUInt16Endian(IsBE); return ( Half ) a; }
|
||||
public float ReadSingleEndian(bool IsBE)
|
||||
{ uint a = ReadUInt32Endian(IsBE); return *( float*)&a; }
|
||||
public double ReadDoubleEndian(bool IsBE)
|
||||
{ ulong a = ReadUInt64Endian(IsBE); return *(double*)&a; }
|
||||
public bool RBo () { cR(); return s.ReadByte() != 0; }
|
||||
public sbyte RI8 () { cR(); return (sbyte)s.ReadByte(); }
|
||||
public byte RU8 () { cR(); return ( byte)s.ReadByte(); }
|
||||
public short RI16() { cR(); s.Read(b, 0, 2); return b.TI16(); }
|
||||
public ushort RU16() { cR(); s.Read(b, 0, 2); return b.TU16(); }
|
||||
public int RI32() { cR(); s.Read(b, 0, 4); return b.TI32(); }
|
||||
public uint RU32() { cR(); s.Read(b, 0, 4); return b.TU32(); }
|
||||
public long RI64() { cR(); s.Read(b, 0, 8); return b.TI64(); }
|
||||
public ulong RU64() { cR(); s.Read(b, 0, 8); return b.TU64(); }
|
||||
public float RF32() { cR(); s.Read(b, 0, 4); return b.TF32(); }
|
||||
public double RF64() { cR(); s.Read(b, 0, 8); return b.TF64(); }
|
||||
|
||||
public void Write(byte[] Val) => stream.Write(Val, 0, Val. Length);
|
||||
public void Write(byte[] Val, int Length) => stream.Write(Val, 0 , Length);
|
||||
public void Write(byte[] Val, int Offset, int Length) => stream.Write(Val, Offset, Length);
|
||||
public void Write(char[] val, bool UTF8 = true)
|
||||
{ if (UTF8) Write(val.ToUTF8()); else Write(val.ToASCII()); }
|
||||
public short RI16E() { cR(); s.Read(b, 0, 2); b.E(2, IsBE); return b.TI16(); }
|
||||
public ushort RU16E() { cR(); s.Read(b, 0, 2); b.E(2, IsBE); return b.TU16(); }
|
||||
public int RI32E() { cR(); s.Read(b, 0, 4); b.E(4, IsBE); return b.TI32(); }
|
||||
public uint RU32E() { cR(); s.Read(b, 0, 4); b.E(4, IsBE); return b.TU32(); }
|
||||
public long RI64E() { cR(); s.Read(b, 0, 8); b.E(8, IsBE); return b.TI64(); }
|
||||
public ulong RU64E() { cR(); s.Read(b, 0, 8); b.E(8, IsBE); return b.TU64(); }
|
||||
public float RF32E() { cR(); s.Read(b, 0, 4); b.E(4, IsBE); return b.TF32(); }
|
||||
public double RF64E() { cR(); s.Read(b, 0, 8); b.E(8, IsBE); return b.TF64(); }
|
||||
|
||||
public void WriteByte(byte val) => stream.WriteByte(val);
|
||||
public short RI16E(bool isBE) { cR(); s.Read(b, 0, 2); b.E(2, isBE); return b.TI16(); }
|
||||
public ushort RU16E(bool isBE) { cR(); s.Read(b, 0, 2); b.E(2, isBE); return b.TU16(); }
|
||||
public int RI32E(bool isBE) { cR(); s.Read(b, 0, 4); b.E(4, isBE); return b.TI32(); }
|
||||
public uint RU32E(bool isBE) { cR(); s.Read(b, 0, 4); b.E(4, isBE); return b.TU32(); }
|
||||
public long RI64E(bool isBE) { cR(); s.Read(b, 0, 8); b.E(8, isBE); return b.TI64(); }
|
||||
public ulong RU64E(bool isBE) { cR(); s.Read(b, 0, 8); b.E(8, isBE); return b.TU64(); }
|
||||
public float RF32E(bool isBE) { cR(); s.Read(b, 0, 4); b.E(4, isBE); return b.TF32(); }
|
||||
public double RF64E(bool isBE) { cR(); s.Read(b, 0, 8); b.E(8, isBE); return b.TF64(); }
|
||||
|
||||
public void Write( bool val) => stream.WriteByte((byte)(val ? 1 : 0));
|
||||
public void Write( sbyte val) => stream.WriteByte((byte) val);
|
||||
public void Write( byte val) => stream.WriteByte( val);
|
||||
public void Write( short val) => ToArray(2, val);
|
||||
public void Write(ushort val) => ToArray(2, val);
|
||||
public void Write( int val) => ToArray(4, val);
|
||||
public void Write( uint val) => ToArray(4, val);
|
||||
public void Write( long val) => ToArray(8, val);
|
||||
public void Write( ulong val) => ToArray(8, val);
|
||||
public void Write( Half val) => ToArray(2, (ushort) val);
|
||||
public void Write( float val) => ToArray(4, *( uint*)&val);
|
||||
public void Write(double val) => ToArray(8, *(ulong*)&val);
|
||||
public void W(byte[] val )
|
||||
{ cW(); s.Write(val ?? new byte[0], 0, val.Length); }
|
||||
public void W(byte[] val, int Length)
|
||||
{ cW(); s.Write(val ?? new byte[0], 0, Length); }
|
||||
public void W(byte[] val, int offset, int length)
|
||||
{ cW(); s.Write(val ?? new byte[0], offset, length); }
|
||||
public void W(char[] val, bool utf8 = true) =>
|
||||
W(utf8 ? val.ToUTF8() : val.ToASCII());
|
||||
|
||||
public void Write( sbyte? val) => Write(val.GetValueOrDefault());
|
||||
public void Write( byte? val) => Write(val.GetValueOrDefault());
|
||||
public void Write( short? val) => Write(val.GetValueOrDefault());
|
||||
public void Write(ushort? val) => Write(val.GetValueOrDefault());
|
||||
public void Write( int? val) => Write(val.GetValueOrDefault());
|
||||
public void Write( uint? val) => Write(val.GetValueOrDefault());
|
||||
public void Write( long? val) => Write(val.GetValueOrDefault());
|
||||
public void Write( ulong? val) => Write(val.GetValueOrDefault());
|
||||
public void Write( float? val) => Write(val.GetValueOrDefault());
|
||||
public void Write(double? val) => Write(val.GetValueOrDefault());
|
||||
|
||||
public void Write( bool* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
public void Write( sbyte* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
public void Write( byte* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
public void Write( short* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
public void Write(ushort* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
public void Write( int* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
public void Write( uint* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
public void Write( long* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
public void Write( ulong* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
public void Write( float* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
public void Write(double* val, int Length) { for (i = 0; i < Length; i++) Write(val[i]); }
|
||||
|
||||
public void WriteEndian( short* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
public void WriteEndian(ushort* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
public void WriteEndian( int* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
public void WriteEndian( uint* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
public void WriteEndian( long* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
public void WriteEndian( ulong* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
public void WriteEndian( float* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
public void WriteEndian(double* val, int Length) { for (i = 0; i < Length; i++) WriteEndian(val[i]); }
|
||||
|
||||
public void WriteEndian( short* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
public void WriteEndian(ushort* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
public void WriteEndian( int* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
public void WriteEndian( uint* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
public void WriteEndian( long* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
public void WriteEndian( ulong* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
public void WriteEndian( float* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
public void WriteEndian(double* val, int Length, bool IsBE)
|
||||
{ for (i = 0; i < Length; i++) WriteEndian(val[i], IsBE); }
|
||||
public void W( bool val) { cW(); s.WriteByte((byte)(val ? 1 : 0)); }
|
||||
public void W( sbyte val) { cW(); s.WriteByte((byte) val); }
|
||||
public void W( byte val) { cW(); s.WriteByte( val); }
|
||||
public void W( short val) { cW(); b.GBy(val); s.Write(b, 0, 2); }
|
||||
public void W(ushort val) { cW(); b.GBy(val); s.Write(b, 0, 2); }
|
||||
public void W( int val) { cW(); b.GBy(val); s.Write(b, 0, 4); }
|
||||
public void W( uint val) { cW(); b.GBy(val); s.Write(b, 0, 4); }
|
||||
public void W( long val) { cW(); b.GBy(val); s.Write(b, 0, 8); }
|
||||
public void W( ulong val) { cW(); b.GBy(val); s.Write(b, 0, 8); }
|
||||
public void W( float val) { cW(); b.GBy(val); s.Write(b, 0, 4); }
|
||||
public void W(double val) { cW(); b.GBy(val); s.Write(b, 0, 8); }
|
||||
|
||||
public void Write( char val, bool UTF8 = true)
|
||||
{ if (UTF8) Write(val.ToString().ToUTF8()); else Write(val.ToString().ToASCII()); }
|
||||
public void Write(string val, bool UTF8 = true)
|
||||
{ if (UTF8) Write(val .ToUTF8()); else Write(val .ToASCII()); }
|
||||
|
||||
public void WriteEndian( short val) => ToArray(2, Endian(val, 2, IsBE));
|
||||
public void WriteEndian(ushort val) => ToArray(2, Endian(val, 2, IsBE));
|
||||
public void WriteEndian( int val) => ToArray(4, Endian(val, 4, IsBE));
|
||||
public void WriteEndian( uint val) => ToArray(4, Endian(val, 4, IsBE));
|
||||
public void WriteEndian( long val) => ToArray(8, Endian(val, 8, IsBE));
|
||||
public void WriteEndian( ulong val) => ToArray(8, Endian(val, 8, IsBE));
|
||||
public void WriteEndian( float val) => ToArray(4, Endian(*( uint*)&val, 4, IsBE));
|
||||
public void WriteEndian(double val) => ToArray(8, Endian(*(ulong*)&val, 8, IsBE));
|
||||
public void W( sbyte? val) => W(val ?? default);
|
||||
public void W( byte? val) => W(val ?? default);
|
||||
public void W( short? val) => W(val ?? default);
|
||||
public void W(ushort? val) => W(val ?? default);
|
||||
public void W( int? val) => W(val ?? default);
|
||||
public void W( uint? val) => W(val ?? default);
|
||||
public void W( long? val) => W(val ?? default);
|
||||
public void W( ulong? val) => W(val ?? default);
|
||||
public void W( float? val) => W(val ?? default);
|
||||
public void W(double? val) => W(val ?? default);
|
||||
|
||||
public void WriteEndian( short val, bool IsBE) => ToArray(2, Endian(val, 2, IsBE));
|
||||
public void WriteEndian(ushort val, bool IsBE) => ToArray(2, Endian(val, 2, IsBE));
|
||||
public void WriteEndian( int val, bool IsBE) => ToArray(4, Endian(val, 4, IsBE));
|
||||
public void WriteEndian( uint val, bool IsBE) => ToArray(4, Endian(val, 4, IsBE));
|
||||
public void WriteEndian( long val, bool IsBE) => ToArray(8, Endian(val, 8, IsBE));
|
||||
public void WriteEndian( ulong val, bool IsBE) => ToArray(8, Endian(val, 8, IsBE));
|
||||
public void WriteEndian( float val, bool IsBE) => ToArray(4, Endian(*( uint*)&val, 4, IsBE));
|
||||
public void WriteEndian(double val, bool IsBE) => ToArray(8, Endian(*(ulong*)&val, 8, IsBE));
|
||||
public void 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 long Endian( long BE, byte Length, bool IsBE)
|
||||
{ if (IsBE) { for (byte i = 0; i < Length; i++) { buf[i] = (byte)BE; BE >>= 8; } BE = 0;
|
||||
for (byte i = 0; i < Length; i++) { BE |= buf[i]; if (i < Length - 1) BE <<= 8; } } return BE; }
|
||||
public void WE( short val) { cW(); b.GBy(val); b.E(2, IsBE); s.Write(b, 0, 2); }
|
||||
public void WE(ushort val) { cW(); b.GBy(val); b.E(2, IsBE); s.Write(b, 0, 2); }
|
||||
public void WE( int val) { cW(); b.GBy(val); b.E(4, IsBE); s.Write(b, 0, 4); }
|
||||
public void WE( uint val) { cW(); b.GBy(val); b.E(4, IsBE); s.Write(b, 0, 4); }
|
||||
public void WE( long val) { cW(); b.GBy(val); b.E(8, IsBE); s.Write(b, 0, 8); }
|
||||
public void WE( ulong val) { cW(); b.GBy(val); b.E(8, IsBE); s.Write(b, 0, 8); }
|
||||
public void WE( float val) { cW(); b.GBy(val); b.E(4, IsBE); s.Write(b, 0, 4); }
|
||||
public void WE(double val) { cW(); b.GBy(val); b.E(8, IsBE); s.Write(b, 0, 8); }
|
||||
|
||||
public ulong Endian( ulong BE, byte Length, bool IsBE)
|
||||
{ if (IsBE) { for (byte i = 0; i < Length; i++) { buf[i] = (byte)BE; BE >>= 8; } BE = 0;
|
||||
for (byte i = 0; i < Length; i++) { BE |= buf[i]; if (i < Length - 1) BE <<= 8; } } return BE; }
|
||||
public void WE( short val, bool isBE) { cW(); b.GBy(val); b.E(2, isBE); s.Write(b, 0, 2); }
|
||||
public void WE(ushort val, bool isBE) { cW(); b.GBy(val); b.E(2, isBE); s.Write(b, 0, 2); }
|
||||
public void WE( int val, bool isBE) { cW(); b.GBy(val); b.E(4, isBE); s.Write(b, 0, 4); }
|
||||
public void WE( uint val, bool isBE) { cW(); b.GBy(val); b.E(4, isBE); s.Write(b, 0, 4); }
|
||||
public void WE( long val, bool isBE) { cW(); b.GBy(val); b.E(8, isBE); s.Write(b, 0, 8); }
|
||||
public void WE( ulong val, bool isBE) { cW(); b.GBy(val); b.E(8, isBE); s.Write(b, 0, 8); }
|
||||
public void WE( float val, bool isBE) { cW(); b.GBy(val); b.E(4, isBE); s.Write(b, 0, 4); }
|
||||
public void WE(double val, bool isBE) { cW(); b.GBy(val); b.E(8, isBE); s.Write(b, 0, 8); }
|
||||
|
||||
private void ToArray(byte L, long val)
|
||||
{ CheckWrited(); for (i = 0; i < L; i++) { buf[i] = (byte)val; val >>= 8; } Write(buf, L); }
|
||||
private void RENRS(byte c)
|
||||
{ cR(); if (getENRS) ENRSDict.Add(P, c); s.Read(b, 0, c); }
|
||||
|
||||
private void ToArray(byte L, ulong val)
|
||||
{ CheckWrited(); for (i = 0; i < L; i++) { buf[i] = (byte)val; val >>= 8; } Write(buf, L); }
|
||||
public short RI16ENRS() { RENRS((byte)2); return b.TI16(); }
|
||||
public ushort RU16ENRS() { RENRS((byte)2); return b.TU16(); }
|
||||
public int RI32ENRS() { RENRS((byte)4); return b.TI32(); }
|
||||
public uint RU32ENRS() { RENRS((byte)4); return b.TU32(); }
|
||||
public long RI64ENRS() { RENRS((byte)8); return b.TI64(); }
|
||||
public ulong RU64ENRS() { RENRS((byte)8); return b.TU64(); }
|
||||
public float RF32ENRS() { RENRS((byte)4); return b.TF32(); }
|
||||
public double RF64ENRS() { RENRS((byte)8); return b.TF64(); }
|
||||
|
||||
private long IntFromArray(byte L, bool IsBE = false) { Read(L); long val = 0; if (IsBE)
|
||||
for (i = 0; i < L; i++) { val <<= 8; val |= buf[i ]; } else
|
||||
for (i = L; i > 0; i--) { val <<= 8; val |= buf[i - 1]; } return val; }
|
||||
public short RI16ENRSE() { RENRS((byte)2); b.E(2, IsBE); return b.TI16(); }
|
||||
public ushort RU16ENRSE() { RENRS((byte)2); b.E(2, IsBE); return b.TU16(); }
|
||||
public int RI32ENRSE() { RENRS((byte)4); b.E(4, IsBE); return b.TI32(); }
|
||||
public uint RU32ENRSE() { RENRS((byte)4); b.E(4, IsBE); return b.TU32(); }
|
||||
public long RI64ENRSE() { RENRS((byte)8); b.E(8, IsBE); return b.TI64(); }
|
||||
public ulong RU64ENRSE() { RENRS((byte)8); b.E(8, IsBE); return b.TU64(); }
|
||||
public float RF32ENRSE() { RENRS((byte)4); b.E(4, IsBE); return b.TF32(); }
|
||||
public double RF64ENRSE() { RENRS((byte)8); b.E(8, IsBE); return b.TF64(); }
|
||||
|
||||
private ulong UIntFromArray(byte L, bool IsBE = false) { Read(L); ulong val = 0; if (IsBE)
|
||||
for (i = 0; i < L; i++) { val <<= 8; val |= buf[i ]; } else
|
||||
for (i = L; i > 0; i--) { val <<= 8; val |= buf[i - 1]; } return val; }
|
||||
public short RI16ENRSE(bool isBE) { RENRS((byte)2); b.E(2, isBE); return b.TI16(); }
|
||||
public ushort RU16ENRSE(bool isBE) { RENRS((byte)2); b.E(2, isBE); return b.TU16(); }
|
||||
public int RI32ENRSE(bool isBE) { RENRS((byte)4); b.E(4, isBE); return b.TI32(); }
|
||||
public uint RU32ENRSE(bool isBE) { RENRS((byte)4); b.E(4, isBE); return b.TU32(); }
|
||||
public long RI64ENRSE(bool isBE) { RENRS((byte)8); b.E(8, isBE); return b.TI64(); }
|
||||
public ulong RU64ENRSE(bool isBE) { RENRS((byte)8); b.E(8, isBE); return b.TU64(); }
|
||||
public float RF32ENRSE(bool isBE) { RENRS((byte)4); b.E(4, isBE); return b.TF32(); }
|
||||
public double RF64ENRSE(bool isBE) { RENRS((byte)8); b.E(8, isBE); return b.TF64(); }
|
||||
|
||||
private void Read(byte Length) => stream.Read(buf, 0, Length);
|
||||
public char ReadChar(bool UTF8 = true)
|
||||
{ if (UTF8) return ReadCharUTF8();
|
||||
else return (char)stream.ReadByte(); }
|
||||
private void WENRS(byte c)
|
||||
{ if (getENRS) ENRSDict.Add(P, c); cW(); s.Write(b, 0, c); }
|
||||
|
||||
public char ReadCharUTF8()
|
||||
public void WENRS( short val) { b.GBy(val); WENRS((byte)2); }
|
||||
public void WENRS(ushort val) { b.GBy(val); WENRS((byte)2); }
|
||||
public void WENRS( int val) { b.GBy(val); WENRS((byte)4); }
|
||||
public void WENRS( uint val) { b.GBy(val); WENRS((byte)4); }
|
||||
public void WENRS( long val) { b.GBy(val); WENRS((byte)8); }
|
||||
public void WENRS( ulong val) { b.GBy(val); WENRS((byte)8); }
|
||||
public void WENRS( float val) { b.GBy(val); WENRS((byte)4); }
|
||||
public void WENRS(double val) { b.GBy(val); WENRS((byte)8); }
|
||||
|
||||
public void WENRSE( short val) { b.GBy(val); b.E(2, IsBE); WENRS((byte)2); }
|
||||
public void WENRSE(ushort val) { b.GBy(val); b.E(2, IsBE); WENRS((byte)2); }
|
||||
public void WENRSE( int val) { b.GBy(val); b.E(4, IsBE); WENRS((byte)4); }
|
||||
public void WENRSE( uint val) { b.GBy(val); b.E(4, IsBE); WENRS((byte)4); }
|
||||
public void WENRSE( long val) { b.GBy(val); b.E(8, IsBE); WENRS((byte)8); }
|
||||
public void WENRSE( ulong val) { b.GBy(val); b.E(8, IsBE); WENRS((byte)8); }
|
||||
public void WENRSE( float val) { b.GBy(val); b.E(4, IsBE); WENRS((byte)4); }
|
||||
public void WENRSE(double val) { b.GBy(val); b.E(8, IsBE); WENRS((byte)8); }
|
||||
|
||||
public void WENRSE( short val, bool isBE) { b.GBy(val); b.E(2, isBE); WENRS((byte)2); }
|
||||
public void WENRSE(ushort val, bool isBE) { b.GBy(val); b.E(2, isBE); WENRS((byte)2); }
|
||||
public void WENRSE( int val, bool isBE) { b.GBy(val); b.E(4, isBE); WENRS((byte)4); }
|
||||
public void WENRSE( uint val, bool isBE) { b.GBy(val); b.E(4, isBE); WENRS((byte)4); }
|
||||
public void WENRSE( long val, bool isBE) { b.GBy(val); b.E(8, isBE); WENRS((byte)8); }
|
||||
public void WENRSE( ulong val, bool isBE) { b.GBy(val); b.E(8, isBE); WENRS((byte)8); }
|
||||
public void WENRSE( float val, bool isBE) { b.GBy(val); b.E(4, isBE); WENRS((byte)4); }
|
||||
public void WENRSE(double val, bool isBE) { b.GBy(val); b.E(8, isBE); WENRS((byte)8); }
|
||||
|
||||
public int RI24 ( ) { cR(); s.Read(b, 0, 3); return b.TI24(); }
|
||||
public uint RU24 ( ) { cR(); s.Read(b, 0, 3); return b.TU24(); }
|
||||
public int RI24E( ) { cR(); s.Read(b, 0, 3); b.E(3, IsBE); return b.TI24(); }
|
||||
public uint RU24E( ) { cR(); s.Read(b, 0, 3); b.E(3, IsBE); return b.TU24(); }
|
||||
public int RI24E(bool isBE) { cR(); s.Read(b, 0, 3); b.E(3, isBE); return b.TI24(); }
|
||||
public uint RU24E(bool isBE) { cR(); s.Read(b, 0, 3); b.E(3, isBE); return b.TU24(); }
|
||||
|
||||
public Half RF16 ( ) { cR(); s.Read(b, 0, 2); return b.TF16(); }
|
||||
public Half RF16E( ) { cR(); s.Read(b, 0, 2); b.E(2, IsBE); return b.TF16(); }
|
||||
public Half RF16E(bool isBE) { cR(); s.Read(b, 0, 2); b.E(2, isBE); return b.TF16(); }
|
||||
|
||||
public void W (Half val ) { cW(); b.GBy(val); s.Write(b, 0, 2); }
|
||||
public void WE (Half val ) { cW(); b.GBy(val); b.E(2, IsBE); s.Write(b, 0, 2); }
|
||||
public void WE (Half val, bool isBE) { cW(); b.GBy(val); b.E(2, isBE); s.Write(b, 0, 2); }
|
||||
|
||||
public Vec2 RV2 ( ) { cR(); s.Read(b, 0, 8); return b.TV2(); }
|
||||
public Vec3 RV3 ( ) { cR(); s.Read(b, 0, 12); return b.TV3(); }
|
||||
public Vec4 RV4 ( ) { cR(); s.Read(b, 0, 16); return b.TV4(); }
|
||||
public Vec2 RV2E ( ) { cR(); s.Read(b, 0, 8); b.E( 8, IsBE); return b.TV2(); }
|
||||
public Vec3 RV3E ( ) { cR(); s.Read(b, 0, 12); b.E(12, IsBE); return b.TV3(); }
|
||||
public Vec4 RV4E ( ) { cR(); s.Read(b, 0, 16); b.E(16, IsBE); return b.TV4(); }
|
||||
public Vec2 RV2E (bool isBE) { cR(); s.Read(b, 0, 8); b.E( 8, isBE); return b.TV2(); }
|
||||
public Vec3 RV3E (bool isBE) { cR(); s.Read(b, 0, 12); b.E(12, isBE); return b.TV3(); }
|
||||
public Vec4 RV4E (bool isBE) { cR(); s.Read(b, 0, 16); b.E(16, isBE); return b.TV4(); }
|
||||
|
||||
public void W (Vec2 val ) { cW(); b.GBy(val); s.Write(b, 0, 8); }
|
||||
public void W (Vec3 val ) { cW(); b.GBy(val); s.Write(b, 0, 12); }
|
||||
public void W (Vec4 val ) { cW(); b.GBy(val); s.Write(b, 0, 16); }
|
||||
public void WE(Vec2 val ) { cW(); b.GBy(val); b.E( 8, IsBE); s.Write(b, 0, 8); }
|
||||
public void WE(Vec3 val ) { cW(); b.GBy(val); b.E(12, IsBE); s.Write(b, 0, 12); }
|
||||
public void WE(Vec4 val ) { cW(); b.GBy(val); b.E(16, IsBE); s.Write(b, 0, 16); }
|
||||
public void WE(Vec2 val, bool isBE) { cW(); b.GBy(val); b.E( 8, isBE); s.Write(b, 0, 8); }
|
||||
public void WE(Vec3 val, bool isBE) { cW(); b.GBy(val); b.E(12, isBE); s.Write(b, 0, 12); }
|
||||
public void WE(Vec4 val, bool isBE) { cW(); b.GBy(val); b.E(16, isBE); s.Write(b, 0, 16); }
|
||||
|
||||
public Quat RQ ( ) { cR(); s.Read(b, 0, 16); return b.TQ(); }
|
||||
public Quat RQE ( ) { cR(); s.Read(b, 0, 16); b.E(16, IsBE); return b.TQ(); }
|
||||
public Quat RQE (bool isBE) { cR(); s.Read(b, 0, 16); b.E(16, isBE); return b.TQ(); }
|
||||
public void W (Quat val ) { cW(); b.GBy(val); s.Write(b, 0, 16); }
|
||||
public void WE(Quat val ) { cW(); b.GBy(val); b.E(16, IsBE); s.Write(b, 0, 16); }
|
||||
public void WE(Quat val, bool isBE) { cW(); b.GBy(val); b.E(16, isBE); s.Write(b, 0, 16); }
|
||||
|
||||
public T[] RA<T>(long length, long offset = -1) where T : unmanaged
|
||||
{
|
||||
cR();
|
||||
int sizeOfT = sizeof(T);
|
||||
if (offset > -1) s.Position = offset;
|
||||
T[] array = new T[length];
|
||||
byte[] buf = new byte[sizeOfT];
|
||||
fixed (byte* ptr = buf)
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
cR(); s.Read(buf, 0, sizeOfT);
|
||||
array[i] = *(T*)ptr;
|
||||
}
|
||||
|
||||
if (IsBE) array = array.ReverseEndian();
|
||||
return array;
|
||||
}
|
||||
|
||||
public void WA<T>(T[] array, long length, long offset = -1) where T : unmanaged
|
||||
{
|
||||
if (IsBE) array = array.ReverseEndian();
|
||||
|
||||
cW();
|
||||
int sizeOfT = sizeof(T);
|
||||
if (offset > -1) s.Position = offset;
|
||||
byte[] buf = new byte[sizeOfT];
|
||||
fixed (byte* ptr = buf)
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
*(T*)ptr = array[i];
|
||||
s.Write(buf, 0, sizeOfT);
|
||||
}
|
||||
}
|
||||
|
||||
public char RC(bool utf8 = true)
|
||||
{ cR(); return utf8 ? RCUTF8() : (char)s.ReadByte();}
|
||||
|
||||
public char RCUTF8()
|
||||
{
|
||||
cR();
|
||||
byte t;
|
||||
int T;
|
||||
int val = 0;
|
||||
for (i = 0, i0 = 4; i < i0; i++)
|
||||
for (j = 0, i = 4; j < i; j++)
|
||||
{
|
||||
T = stream.ReadByte();
|
||||
T = s.ReadByte();
|
||||
if (T == -1) return '\uFFFF';
|
||||
t = (byte)T;
|
||||
|
||||
if ((t & 0xC0) == 0x80 && i > 0) val = (val << 6) | (t & 0x3F);
|
||||
else if ((t & 0x80) == 0x00 && i == 0) return (char)t;
|
||||
else if ((t & 0xE0) == 0xC0 && i == 0) { val = t & 0x1F; i0 = 2; }
|
||||
else if ((t & 0xF0) == 0xE0 && i == 0) { val = t & 0x0F; i0 = 3; }
|
||||
else if ((t & 0xF8) == 0xF0 && i == 0) { val = t & 0x07; i0 = 4; }
|
||||
if ((t & 0xC0) == 0x80 && j > 0) val = (val << 6) | (t & 0x3F);
|
||||
else if ((t & 0x80) == 0x00 && j == 0) return (char)t;
|
||||
else if ((t & 0xE0) == 0xC0 && j == 0) { val = t & 0x1F; i = 2; }
|
||||
else if ((t & 0xF0) == 0xE0 && j == 0) { val = t & 0x0F; i = 3; }
|
||||
else if ((t & 0xF8) == 0xF0 && j == 0) { val = t & 0x07; i = 4; }
|
||||
else return '\uFFFF';
|
||||
}
|
||||
return (char)val;
|
||||
}
|
||||
|
||||
public string ReadString(long Length, bool UTF8 = true)
|
||||
{ if (UTF8) return ReadStringUTF8 (Length);
|
||||
else return ReadStringASCII(Length); }
|
||||
|
||||
public string ReadStringUTF8 (long Length) => ReadBytes(Length).ToUTF8 ();
|
||||
public string ReadStringASCII(long Length) => ReadBytes(Length).ToASCII();
|
||||
|
||||
|
||||
public string ReadString(long? Length, bool UTF8 = true)
|
||||
{ if (UTF8) return ReadStringUTF8 (Length);
|
||||
else return ReadStringASCII(Length); }
|
||||
public string RS(long Length, bool utf8 = true)
|
||||
{ cR(); return utf8 ? RSUTF8(Length) : RSASCII(Length);}
|
||||
|
||||
public string ReadStringUTF8 (long? Length) => ReadBytes(Length).ToUTF8 ();
|
||||
public string ReadStringASCII(long? Length) => ReadBytes(Length).ToASCII();
|
||||
|
||||
public byte[] ReadBytes(long Length, int Offset = 0)
|
||||
{ byte[] Buf = new byte[Length]; if (Offset > 0) stream.Position = Offset;
|
||||
stream.Read(Buf, 0, (int)Length); return Buf; }
|
||||
|
||||
public void ReadBytes(long Length, byte[] Buf, long Offset = 0)
|
||||
{ if (Offset > 0) stream.Position = Offset; stream.Read(Buf, 0, (int)Length); }
|
||||
public string RSUTF8 (long length) { cR(); return RBy(length).ToUTF8 (); }
|
||||
public string RSASCII(long length) { cR(); return RBy(length).ToASCII(); }
|
||||
|
||||
public byte[] ReadBytes(long? Length, int Offset = 0)
|
||||
{ if (Length == null) return new byte[0]; else return ReadBytes((long)Length, Offset); }
|
||||
public string RS(long? length, bool utf8 = true)
|
||||
{ cR(); return utf8? RSUTF8(length) : RSASCII(length); }
|
||||
|
||||
public void ReadBytes(long Length, byte Bits, byte[] Buf, long Offset = 0)
|
||||
{ if (Offset > 0) stream.Seek(Offset, 0);
|
||||
if (Bits > 0 && Bits < 8) for (i0 = 0; i0 < Length; i0++) Buf[i0] = ReadBits(Bits); }
|
||||
|
||||
public byte ReadBits(byte Bits)
|
||||
public string RSUTF8 (long? length) { cR(); return RBy(length).ToUTF8 (); }
|
||||
public string RSASCII(long? length) { cR(); return RBy(length).ToASCII(); }
|
||||
|
||||
public byte[] RBy(long length, long offset = -1)
|
||||
{ cR(); byte[] buf = new byte[length]; if (offset > -1) s.Position = offset;
|
||||
s.Read(buf, 0, (int)length); return buf; }
|
||||
|
||||
public int RBy(long length, byte[] buf, long offset = -1)
|
||||
{ cR(); if (offset > -1) s.Position = offset; return s.Read(buf, 0, (int)length); }
|
||||
|
||||
public byte[] RBy(long? length, long offset = -1)
|
||||
{ if (length == null) return new byte[0]; else return RBy((long)length, offset); }
|
||||
|
||||
public void RBy(long length, byte bits, byte[] buf, long offset = -1)
|
||||
{ if (offset > -1) s.Seek(offset, 0);
|
||||
if (bits > 0 && bits < 8) for (i = 0; i < length; i++) buf[i] = RBi(bits); CR(); }
|
||||
|
||||
public byte RBi(byte bits)
|
||||
{
|
||||
BitRead += Bits;
|
||||
TempBitRead = 8 - BitRead;
|
||||
if (TempBitRead < 0)
|
||||
cR();
|
||||
bitRead += bits;
|
||||
tempBitRead = 8 - bitRead;
|
||||
if (tempBitRead < 0)
|
||||
{
|
||||
BitRead = (byte)-TempBitRead;
|
||||
TempBitRead = 8 + TempBitRead;
|
||||
ValRead = (ushort)((ValRead << 8) | (byte)stream.ReadByte());
|
||||
bitRead = (byte)-tempBitRead;
|
||||
tempBitRead = 8 + tempBitRead;
|
||||
valRead = (ushort)((valRead << 8) | (byte)s.ReadByte());
|
||||
}
|
||||
return (byte)((ValRead >> TempBitRead) & ((1 << Bits) - 1));
|
||||
return (byte)((valRead >> tempBitRead) & ((1 << bits) - 1));
|
||||
}
|
||||
|
||||
public byte ReadHalfByte() => ReadBits(4);
|
||||
|
||||
public void Write(byte val, byte Bits)
|
||||
public byte RHB() => RBi(4);
|
||||
|
||||
public void W(int val, byte bits)
|
||||
{
|
||||
BitWrite += Bits;
|
||||
TempBitWrite = 8 - BitWrite;
|
||||
if (TempBitWrite < 0)
|
||||
cW();
|
||||
val &= (1 << bits) - 1;
|
||||
bitWrite += bits;
|
||||
tempBitWrite = 8 - bitWrite;
|
||||
if (tempBitWrite < 0)
|
||||
{
|
||||
BitWrite = (byte)-TempBitWrite;
|
||||
TempBitWrite = 8 + TempBitWrite;
|
||||
stream.WriteByte((byte)(ValWrite | (val >> BitWrite)));
|
||||
ValWrite = 0;
|
||||
bitWrite = (byte)-tempBitWrite;
|
||||
tempBitWrite = 8 + tempBitWrite;
|
||||
s.WriteByte((byte)(valWrite | (val >> bitWrite)));
|
||||
valWrite = 0;
|
||||
}
|
||||
ValWrite |= (byte)(val << TempBitWrite);
|
||||
valWrite |= val << tempBitWrite;
|
||||
valWrite &= 0xFF;
|
||||
}
|
||||
|
||||
public void CheckRead () { if (BitRead > 0) ValRead = 0; BitRead = 8; }
|
||||
public void CheckWrited() { if (BitWrite > 0) { Write(ValWrite); ValWrite = BitWrite = 0; } }
|
||||
public void CR() //CheckRead
|
||||
{ if (bitRead > 0) valRead = 0; bitRead = 8; }
|
||||
public void CW() //CheckWrite
|
||||
{ if (bitWrite > 0) { cW(); s.WriteByte((byte)valWrite); valWrite = 0; bitWrite = 0; } }
|
||||
|
||||
public byte[] ToArray(bool Close)
|
||||
{ byte[] Data = ToArray(); if (Close) this.Close(); return Data; }
|
||||
public byte[] ToArray(bool close)
|
||||
{ byte[] data = ToArray(); if (close) Dispose(); return data; }
|
||||
|
||||
public byte[] ToArray()
|
||||
{
|
||||
long Offset = stream.Position;
|
||||
LongPosition = 0;
|
||||
byte[] Data = ReadBytes(stream.Length);
|
||||
LongPosition = Offset;
|
||||
return Data;
|
||||
}
|
||||
|
||||
public long ReadIntX( ) => IsX ? ReadInt64() : ReadUInt32Endian( );
|
||||
public long ReadIntX(bool IsBE) => IsX ? ReadInt64() : ReadUInt32Endian(IsBE);
|
||||
|
||||
public string ReadStringAtOffset(long Offset = 0, long Length = 0)
|
||||
{
|
||||
string s = null;
|
||||
long Position = LongPosition;
|
||||
if (Offset == 0) { Position += IsX ? 8 : 4; Offset = ReadIntX(); }
|
||||
LongPosition = Offset;
|
||||
if (Length == 0) s = this.NullTerminatedUTF8();
|
||||
else s = ReadStringUTF8(Length);
|
||||
LongPosition = Position;
|
||||
return s;
|
||||
long position = s.Position; s.Position = 0;
|
||||
byte[] data = new byte[s.Length];
|
||||
s.Read(data, 0, data.Length);
|
||||
s.Position = position;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>KKdMainLib</RootNamespace>
|
||||
<AssemblyName>KKdMainLib</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Authors>korenkonder</Authors>
|
||||
<Company></Company>
|
||||
<Configuration></Configuration>
|
||||
<Copyright>korenkonder (C) 2018-2023</Copyright>
|
||||
<Description>A simple library for working with Project Diva AC/DT/F/AFT/F2/X/XHD/FT/VRFL/M39 files</Description>
|
||||
<FileVersion>0.4.10.16</FileVersion>
|
||||
<PackageId>KKdMainLib</PackageId>
|
||||
<Product>KKdMainLib</Product>
|
||||
<TargetFramework>net461</TargetFramework>
|
||||
<Title>KKdMainLib</Title>
|
||||
<Version>0.4.10.16</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -22,6 +23,8 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0018, IDE0032, IDE0044, IDE0045, IDE0046, IDE0051, IDE0055, IDE0059, IDE0063, IDE0066, IDE0069, IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -33,47 +36,23 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0018, IDE0032, IDE0044, IDE0045, IDE0046, IDE0051, IDE0055, IDE0059, IDE0063, IDE0066, IDE0069, IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="A3DA\A3DAExt.cs" />
|
||||
<Compile Include="A3DA\A3DA.cs" />
|
||||
<Compile Include="DB\Aet.cs" />
|
||||
<Compile Include="DB\Auth.cs" />
|
||||
<Compile Include="DB\Spr.cs" />
|
||||
<Compile Include="IO\Directory.cs" />
|
||||
<Compile Include="IO\File.cs" />
|
||||
<Compile Include="IO\IOExtensions.cs" />
|
||||
<Compile Include="IO\Path.cs" />
|
||||
<Compile Include="IO\Stream.cs" />
|
||||
<Compile Include="MessagePack\JSONIO.cs" />
|
||||
<Compile Include="MessagePack\MPExt.cs" />
|
||||
<Compile Include="MessagePack\MsgPack.cs" />
|
||||
<Compile Include="MessagePack\IO.cs" />
|
||||
<Compile Include="Types\Half.cs" />
|
||||
<Compile Include="Types\Vector2.cs" />
|
||||
<Compile Include="Types\Vector3.cs" />
|
||||
<Compile Include="Aet.cs" />
|
||||
<Compile Include="DataBank.cs" />
|
||||
<Compile Include="DCC.cs" />
|
||||
<Compile Include="DEX.cs" />
|
||||
<Compile Include="DIVAFILE.cs" />
|
||||
<Compile Include="FARC.cs" />
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="MathExtensions.cs" />
|
||||
<Compile Include="PDHeader.cs" />
|
||||
<Compile Include="POF.cs" />
|
||||
<Compile Include="STR.cs" />
|
||||
<Compile Include="Text.cs" />
|
||||
<Compile Include="Xml.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<ProjectReference Include="..\KKdBaseLib\KKdBaseLib.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,360 +0,0 @@
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public static unsafe class Main
|
||||
{
|
||||
public static void ConsoleDesign(string text, params string[] args)
|
||||
{
|
||||
text = string.Format(text, args);
|
||||
string Text = "█ █";
|
||||
Text = Text.Remove(3) + text + Text.Remove(0, text.Length + 3);
|
||||
Console.WriteLine(Text);
|
||||
}
|
||||
|
||||
public static void ConsoleDesign(bool Fill)
|
||||
{
|
||||
if (Fill) Console.WriteLine("████████████████████████████████████████████████████");
|
||||
else Console.WriteLine("█ █");
|
||||
}
|
||||
|
||||
public const string TimeFormatHHmmssfff = "{0:d2}:{1:d2}:{2:d2}.{3:d3}";
|
||||
|
||||
public static void WriteTime(this TimeSpan time, bool WriteLine = false)
|
||||
{
|
||||
if (WriteLine) Console.WriteLine(TimeFormatHHmmssfff,
|
||||
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
|
||||
else Console.Write (TimeFormatHHmmssfff,
|
||||
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
|
||||
}
|
||||
|
||||
public static void WriteTime(this TimeSpan time, string Text, bool WriteLine = true)
|
||||
{
|
||||
if (WriteLine) Console.WriteLine(TimeFormatHHmmssfff + " - " + Text,
|
||||
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
|
||||
else Console.Write (TimeFormatHHmmssfff + " - " + Text,
|
||||
time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
|
||||
}
|
||||
|
||||
private static string GetArgs(string name, bool And, params string[] ext)
|
||||
{
|
||||
string Out = "";
|
||||
if (And) Out = "|";
|
||||
Out += name + " files (";
|
||||
for (int i = 0; i < ext.Length; i++)
|
||||
{ Out += "*." + ext[i]; if (i + 1 < ext.Length) Out += ", "; }
|
||||
Out += ")|";
|
||||
for (int i = 0; i < ext.Length; i++)
|
||||
{ Out += "*." + ext[i]; if (i + 1 < ext.Length) Out += ";"; }
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
private static string GetArgs(string name, params string[] ext)
|
||||
{
|
||||
string Out = name + " files (";
|
||||
for (int i = 0; i < ext.Length; i++)
|
||||
{ Out += "*." + ext[i]; if (i + 1 < ext.Length) Out += ", "; }
|
||||
Out += ")|";
|
||||
for (int i = 0; i < ext.Length; i++)
|
||||
{ Out += "*." + ext[i]; if (i + 1 < ext.Length) Out += ";"; }
|
||||
|
||||
return Out;
|
||||
}
|
||||
|
||||
public static string Choose(int code, string filetype, out string[] FileNames)
|
||||
{
|
||||
string MsgPack = GetArgs("MessagePack", true, "mp");
|
||||
string JSON = GetArgs("JSON", true, "json");
|
||||
string BIN = GetArgs("BIN", true, "bin");
|
||||
string XML = GetArgs("XML", true, "xml");
|
||||
|
||||
FileNames = new string[0];
|
||||
if (code == 1)
|
||||
{
|
||||
Console.WriteLine("Choose file(s) to open:");
|
||||
OpenFileDialog ofd = new OpenFileDialog { InitialDirectory =
|
||||
Application.StartupPath, Multiselect = true };
|
||||
|
||||
if (filetype == "a3da") ofd.Filter = GetArgs("A3DA", "a3da", "json", "mp") +
|
||||
GetArgs("A3DA", true, "a3da") + JSON + MsgPack;
|
||||
else if (filetype == "bin" ) ofd.Filter = GetArgs("BIN" , "bin", "json", "mp") +
|
||||
BIN + JSON + MsgPack;
|
||||
else if (filetype == "bon" ) ofd.Filter = GetArgs("BON" , "bon", "bin", "json", "mp") +
|
||||
GetArgs("BON", true, "bon") + BIN + JSON + MsgPack;
|
||||
else if (filetype == "databank") ofd.Filter = GetArgs("DAT" , "dat", "xml") +
|
||||
GetArgs("DAT", true, "dat") + XML;
|
||||
else if (filetype == "dex" ) ofd.Filter = GetArgs("DEX" , "dex", "bin", "json", "mp") +
|
||||
GetArgs("DEX", true, "dex") + BIN + JSON + MsgPack;
|
||||
else if (filetype == "diva") ofd.Filter = GetArgs("DIVA", "diva", "wav") +
|
||||
GetArgs("DIVA", true, "diva") + GetArgs("WAV", true, "wav");
|
||||
else if (filetype == "dsc" ) ofd.Filter = GetArgs("DSC" , "dsc", "json", "mp") +
|
||||
GetArgs("DSC", true, "dsc") + JSON + MsgPack;
|
||||
else if (filetype == "farc") ofd.Filter = "FARC Archives (*.farc)|*.farc";
|
||||
else if (filetype == "image") ofd.Filter = GetArgs("Image", "dds", "png") +
|
||||
GetArgs("DDS", true, "dds") + GetArgs("PNG", true, "png");
|
||||
else if (filetype == "kki") ofd.Filter = GetArgs("KKI", "kki");
|
||||
else if (filetype == "mot") ofd.Filter = GetArgs("MOT", "mot", "json", "mp") +
|
||||
GetArgs("MOT", true, "mot") + JSON + MsgPack;
|
||||
else if (filetype == "ppd") ofd.Filter = GetArgs("PPD", "ppd", "pak", "mod") +
|
||||
GetArgs("PPD", true, "ppd") + GetArgs("PAK", true, "pak") + GetArgs("MOD", true, "mod");
|
||||
else if (filetype == "str") ofd.Filter = GetArgs("STR", "str", "bin", "json", "mp") +
|
||||
GetArgs("STR", true, "str") + BIN + JSON + MsgPack;
|
||||
else if (filetype == "vag") ofd.Filter = GetArgs("VAG", "vag", "wav") +
|
||||
GetArgs("VAG", true, "vag") + GetArgs("WAV", true, "wav");
|
||||
else if (filetype == "xml") ofd.Filter = GetArgs("XML", "xml");
|
||||
else ofd.Filter = GetArgs("All;", false, "*");
|
||||
|
||||
if (ofd.ShowDialog() == DialogResult.OK)
|
||||
FileNames = ofd.FileNames;
|
||||
}
|
||||
else if (code == 2)
|
||||
{
|
||||
FolderBrowserDialog fbd = new FolderBrowserDialog();
|
||||
Console.WriteLine("Choose folder:");
|
||||
fbd.SelectedPath = Application.StartupPath;
|
||||
if (fbd.ShowDialog() == DialogResult.OK)
|
||||
return fbd.SelectedPath.ToString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void ChooseSave(int code, string filetype,
|
||||
out string InitialDirectory, out string[] FileNames)
|
||||
{
|
||||
InitialDirectory = "";
|
||||
FileNames = new string[0];
|
||||
Console.WriteLine("Choose file to save:");
|
||||
SaveFileDialog sfd = new SaveFileDialog { InitialDirectory = Application.StartupPath };
|
||||
switch (filetype)
|
||||
{
|
||||
case "kki":
|
||||
sfd.Filter = "KKI file (*.kki)|*.kki";
|
||||
break;
|
||||
}
|
||||
if (sfd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
InitialDirectory = sfd.InitialDirectory.ToString();
|
||||
FileNames = sfd.FileNames;
|
||||
}
|
||||
}
|
||||
|
||||
public static string NullTerminated(this string Source, ref int i, byte End)
|
||||
{
|
||||
string s = "";
|
||||
while (true)
|
||||
{
|
||||
if (Source[i] == End) break;
|
||||
else s += Source[i];
|
||||
i++;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public static bool StartsWith(this Dictionary<string, object> Dict, string args, char Split) =>
|
||||
Dict.StartsWith(args.Split(Split));
|
||||
|
||||
public static bool StartsWith(this Dictionary<string, object> Dict, string args) =>
|
||||
Dict.StartsWith(args.Split('.'));
|
||||
|
||||
public static bool StartsWith(this Dictionary<string, object> Dict, string[] args)
|
||||
{
|
||||
Dictionary<string, object> bufDict = new Dictionary<string, object>();
|
||||
if (Dict == null)
|
||||
Dict = new Dictionary<string, object>();
|
||||
if (args.Length > 1)
|
||||
{
|
||||
string[] NewArgs = new string[args.Length - 1];
|
||||
for (int i = 0; i < args.Length - 1; i++)
|
||||
NewArgs[i] = args[i + 1];
|
||||
if (!Dict.ContainsKey(args[0]))
|
||||
return false;
|
||||
bufDict = (Dictionary<string, object>)Dict[args[0]];
|
||||
return StartsWith(bufDict, NewArgs);
|
||||
}
|
||||
return Dict.ContainsKey(args[0]);
|
||||
}
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> Dict,
|
||||
ref bool value, char Split, string args)
|
||||
{ if (Dict.FindValue(out string val, args.Split(Split)))
|
||||
return bool.TryParse(val, out value); return false; }
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> Dict,
|
||||
ref int value, char Split, string args)
|
||||
{ if (Dict.FindValue(out string val, args.Split(Split)))
|
||||
return int.TryParse(val, out value); return false; }
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> Dict,
|
||||
ref double value, char Split, string args)
|
||||
{ if (Dict.FindValue(out string val, args.Split(Split)))
|
||||
return val.ToDouble(out value); return false; }
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> Dict,
|
||||
ref string value, char Split, string args)
|
||||
{ if (Dict.FindValue(out string val, args.Split(Split)))
|
||||
{ value = val; return true; } return false; }
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> Dict,
|
||||
out bool value, string args)
|
||||
{ if (Dict.FindValue(out string val, args.Split('.' )))
|
||||
return bool.TryParse(val, out value); value = false; return false; }
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> Dict,
|
||||
out int value, string args)
|
||||
{ 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 double value, string args)
|
||||
{ if (Dict.FindValue(out string val, args.Split('.' )))
|
||||
return val.ToDouble(out value); value = 0; return false; }
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> Dict,
|
||||
out int? value, string args)
|
||||
{ if (Dict.FindValue(out string val, args.Split('.' )))
|
||||
{ bool Val = int.TryParse(val, out int _value);
|
||||
value = _value; return Val; } value = null; return false; }
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> Dict,
|
||||
out double? value, string args)
|
||||
{ if (Dict.FindValue(out string val, args.Split('.' )))
|
||||
return ToDouble(val, out value); value = null; return false; }
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> Dict,
|
||||
out string value, string args)
|
||||
{ if (Dict.FindValue(out string val, args.Split('.' )))
|
||||
{ value = val; return true; } value = null; return false; }
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> Dict,
|
||||
out string value, string[] args)
|
||||
{
|
||||
value = "";
|
||||
if (Dict == null) return false;
|
||||
else if (args.Length < 1) return false;
|
||||
|
||||
if (!Dict.ContainsKey(args[0])) return false;
|
||||
else if (args.Length > 1)
|
||||
{
|
||||
string[] NewArgs = new string[args.Length - 1];
|
||||
for (int i = 0; i < args.Length - 1; i++) NewArgs[i] = args[i + 1];
|
||||
return ((Dictionary<string, object>)Dict[args[0]]).FindValue(out value, NewArgs);
|
||||
}
|
||||
else if (args.Length == 1)
|
||||
{
|
||||
if (Dict[args[0]].GetType() == Dict.GetType())
|
||||
return ((Dictionary<string, object>)Dict[args[0]]).FindValue(out value, args);
|
||||
else if (Dict[args[0]].GetType() != typeof(string)) return false;
|
||||
}
|
||||
|
||||
value = (string)Dict[args[0]];
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void GetDictionary(this Dictionary<string, object> Dict,
|
||||
string args, string value, char Split = '.') =>
|
||||
Dict.GetDictionary(args.Split(Split), value);
|
||||
|
||||
public static void GetDictionary(this Dictionary<string, object> Dict,
|
||||
string[] args, string value)
|
||||
{
|
||||
Dictionary<string, object> bufDict = new Dictionary<string, object>();
|
||||
if (Dict == null) Dict = new Dictionary<string, object>();
|
||||
if (args.Length > 1)
|
||||
{
|
||||
string[] NewArgs = new string[args.Length - 1];
|
||||
for (int i = 0; i < args.Length - 1; i++) NewArgs[i] = args[i + 1];
|
||||
if (!Dict.ContainsKey(args[0])) Dict.Add(args[0], null);
|
||||
if (Dict[args[0]] != null)
|
||||
{
|
||||
if (Dict[args[0]].GetType() == typeof(string))
|
||||
Dict[args[0]] = new Dictionary<string, object> { { "", Dict[args[0]] } };
|
||||
}
|
||||
else Dict[args[0]] = new Dictionary<string, object>();
|
||||
bufDict = (Dictionary<string, object>)Dict[args[0]];
|
||||
bufDict.GetDictionary(NewArgs, value);
|
||||
Dict[args[0]] = bufDict;
|
||||
}
|
||||
else if (!Dict.ContainsKey(args[0])) Dict.Add(args[0], value);
|
||||
}
|
||||
|
||||
public static string ToTitleCase(this string s)
|
||||
{ return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s); }
|
||||
|
||||
public static int[] SortWriter(this int Length)
|
||||
{
|
||||
int i = 0;
|
||||
List<string> A = new List<string>();
|
||||
for (i = 0; i < Length; i++) A.Add(i.ToString());
|
||||
A.Sort();
|
||||
int[] B = new int[Length];
|
||||
for (i = 0; i < Length; i++) B[i] = int.Parse(A[i]);
|
||||
return B;
|
||||
}
|
||||
|
||||
private static readonly string NumberDecimalSeparator =
|
||||
NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
|
||||
|
||||
public static string ToString(this bool? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this bool d) => d.ToString().ToLower();
|
||||
public static string ToString(this sbyte? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this sbyte d) => d.ToString();
|
||||
public static string ToString(this byte? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this byte d) => d.ToString();
|
||||
public static string ToString(this short? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this short d) => d.ToString();
|
||||
public static string ToString(this ushort? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this ushort d) => d.ToString();
|
||||
public static string ToString(this int? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this int d) => d.ToString();
|
||||
public static string ToString(this uint? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this uint d) => d.ToString();
|
||||
public static string ToString(this long? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this long d) => d.ToString();
|
||||
public static string ToString(this ulong? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this ulong d) => d.ToString();
|
||||
public static string ToString(this float? d, byte round) => d.GetValueOrDefault().ToString(round);
|
||||
public static string ToString(this float? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this float d, byte round) =>
|
||||
Math.Round(d, round).ToString().ToLower().Replace(NumberDecimalSeparator, ".");
|
||||
public static string ToString(this float d) =>
|
||||
d .ToString().ToLower().Replace(NumberDecimalSeparator, ".");
|
||||
public static string ToString(this double? d, byte round) => d.GetValueOrDefault().ToString(round);
|
||||
public static string ToString(this double? d) => d.GetValueOrDefault().ToString();
|
||||
public static string ToString(this double d, byte round) =>
|
||||
Math.Round(d, round).ToString().ToLower().Replace(NumberDecimalSeparator, ".");
|
||||
public static string ToString(this double d) =>
|
||||
d .ToString().ToLower().Replace(NumberDecimalSeparator, ".");
|
||||
public static float ToSingle(this string s) =>
|
||||
float. Parse(s.Replace(".", NumberDecimalSeparator));
|
||||
public static bool ToSingle(this string s, out float value) =>
|
||||
float.TryParse(s.Replace(".", NumberDecimalSeparator), out value);
|
||||
public static double ToDouble(this string s) =>
|
||||
double. Parse(s.Replace(".", NumberDecimalSeparator));
|
||||
public static bool ToDouble(this string s, out double value) =>
|
||||
double.TryParse(s.Replace(".", NumberDecimalSeparator), out value);
|
||||
public static bool ToSingle(this string s, out float? value)
|
||||
{ bool Val = ToSingle(s, out float val); value = val; return Val; }
|
||||
public static bool ToDouble(this string s, out double? value)
|
||||
{ bool Val = ToDouble(s, out double val); value = val; return Val; }
|
||||
|
||||
public enum Format : byte
|
||||
{
|
||||
NULL = 0,
|
||||
DT = 1,
|
||||
PDA = 2,
|
||||
DT2 = 3,
|
||||
DTe = 4,
|
||||
F = 5,
|
||||
FT = 6,
|
||||
F2LE = 7,
|
||||
F2BE = 8,
|
||||
MGF = 9,
|
||||
X = 10,
|
||||
XHD = 11,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public static class MathExtensions
|
||||
{
|
||||
public static void FloorCeiling(ref double Value)
|
||||
{ if (Value % 1 >= 0.5) Value = (long)(Value + 0.5);
|
||||
else Value = (long) Value; }
|
||||
|
||||
public static long FloorCeiling(this double Value)
|
||||
{ if (Value % 1 >= 0.5) return (long)(Value + 0.5);
|
||||
else return (long) Value; }
|
||||
|
||||
public static int Align(this int value, int alignement, int divide = 1) =>
|
||||
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
|
||||
|
||||
public static uint Align(this uint value, uint alignement, uint divide = 1) =>
|
||||
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
|
||||
|
||||
public static long Align(this long value, long alignement, long divide = 1) =>
|
||||
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
|
||||
|
||||
public static ulong Align(this ulong value, ulong alignement, ulong divide = 1) =>
|
||||
((value % alignement == 0) ? value : (value + alignement - value % alignement)) / divide;
|
||||
|
||||
public static byte[] buf = new byte[8];
|
||||
public static unsafe byte* bufPtr = buf.GetPtr();
|
||||
|
||||
public static unsafe long Endian(this long LE, byte Len, bool IsBE)
|
||||
{ if (IsBE) { for (byte i = 0; i < Len; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
|
||||
for (byte i = 0; i < Len; i++) { LE |= bufPtr[i]; if (i < Len - 1) LE <<= 8; } } return LE; }
|
||||
|
||||
public static unsafe ulong Endian(this ulong LE, byte Len, bool IsBE)
|
||||
{ if (IsBE) { for (byte i = 0; i < Len; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
|
||||
for (byte i = 0; i < Len; i++) { LE |= bufPtr[i]; if (i < Len - 1) LE <<= 8; } } return LE; }
|
||||
|
||||
public static sbyte CITSB(this int c)
|
||||
{
|
||||
if (c > 0x7F) c = 0x7F;
|
||||
else if (c < -0x80) c = -0x80;
|
||||
return (sbyte)c;
|
||||
}
|
||||
|
||||
public static byte CITB(this int c)
|
||||
{
|
||||
if (c > 0xFF) c = 0xFF;
|
||||
else if (c < 0x00) c = 0x00;
|
||||
return (byte)c;
|
||||
}
|
||||
|
||||
public static short CITS(this int c)
|
||||
{
|
||||
if (c > 0x7FFF) c = 0x7FFF;
|
||||
else if (c < -0x8000) c = -0x8000;
|
||||
return (short)c;
|
||||
}
|
||||
|
||||
public static ushort CITUS(this int c)
|
||||
{
|
||||
if (c > 0xFFFF) c = 0xFFFF;
|
||||
else if (c < 0x0000) c = 0x0000;
|
||||
return (ushort)c;
|
||||
}
|
||||
|
||||
public static sbyte CFTSB(this float c)
|
||||
{
|
||||
c = c.Round();
|
||||
if (c > 0x7F) c = 0x7F;
|
||||
else if (c < -0x80) c = -0x80;
|
||||
return (sbyte)c;
|
||||
}
|
||||
|
||||
public static byte CFTB(this float c)
|
||||
{
|
||||
c = c.Round();
|
||||
if (c > 0xFF) c = 0xFF;
|
||||
else if (c < 0x00) c = 0x00;
|
||||
return (byte)c;
|
||||
}
|
||||
|
||||
public static short CFTS(this float c)
|
||||
{
|
||||
c = c.Round();
|
||||
if (c > 0x7FFF) c = 0x7FFF;
|
||||
else if (c < -0x8000) c = -0x8000;
|
||||
return (short)c;
|
||||
}
|
||||
|
||||
public static ushort CFTUS(this float c)
|
||||
{
|
||||
c = c.Round();
|
||||
if (c > 0xFFFF) c = 0xFFFF;
|
||||
else if (c < 0x0000) c = 0x0000;
|
||||
return (ushort)c;
|
||||
}
|
||||
|
||||
public static int CFTI(this float c)
|
||||
{
|
||||
c = c.Round();
|
||||
if (c > 0x7FFFFFFF) c = 0x7FFFFFFF;
|
||||
else if (c < -0x80000000) c = -0x80000000;
|
||||
return (int)c;
|
||||
}
|
||||
|
||||
public static uint CFTUI(this float c)
|
||||
{
|
||||
c = c.Round();
|
||||
if (c > 0xFFFFFFFF) c = 0xFFFFFFFF;
|
||||
else if (c < 0x00000000) c = 0x00000000;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static float Round(this float c) => (float)Math.Round(c);
|
||||
|
||||
public static sbyte CFTSB(this double c)
|
||||
{
|
||||
c = Math.Round(c);
|
||||
if (c > 0x7F) c = 0x7F;
|
||||
else if (c < -0x80) c = -0x80;
|
||||
return (sbyte)c;
|
||||
}
|
||||
|
||||
public static byte CFTB(this double c)
|
||||
{
|
||||
c = Math.Round(c);
|
||||
if (c > 0xFF) c = 0xFF;
|
||||
else if (c < 0x00) c = 0x00;
|
||||
return (byte)c;
|
||||
}
|
||||
|
||||
public static short CFTS(this double c)
|
||||
{
|
||||
c = Math.Round(c);
|
||||
if (c > 0x7FFF) c = 0x7FFF;
|
||||
else if (c < -0x8000) c = -0x8000;
|
||||
return (short)c;
|
||||
}
|
||||
|
||||
public static ushort CFTUS(this double c)
|
||||
{
|
||||
c = Math.Round(c);
|
||||
if (c > 0xFFFF) c = 0xFFFF;
|
||||
else if (c < 0x0000) c = 0x0000;
|
||||
return (ushort)c;
|
||||
}
|
||||
|
||||
public static int CFTI(this double c)
|
||||
{
|
||||
c = Math.Round(c);
|
||||
if (c > 0x7FFFFFFF) c = 0x7FFFFFFF;
|
||||
else if (c < -0x80000000) c = -0x80000000;
|
||||
return (int)c;
|
||||
}
|
||||
|
||||
public static uint CFTUI(this double c)
|
||||
{
|
||||
c = Math.Round(c);
|
||||
if (c > 0xFFFFFFFF) c = 0xFFFFFFFF;
|
||||
else if (c < 0x00000000) c = 0x00000000;
|
||||
return (uint)c;
|
||||
}
|
||||
|
||||
public static double Round(this double c) => Math.Round(c);
|
||||
|
||||
public static unsafe sbyte* GetPtr(this sbyte[] array)
|
||||
{ sbyte* Ptr; fixed ( sbyte* tempPtr = array) Ptr = tempPtr; return Ptr; }
|
||||
|
||||
public static unsafe byte* GetPtr(this byte[] array)
|
||||
{ byte* Ptr; fixed ( byte* tempPtr = array) Ptr = tempPtr; return Ptr; }
|
||||
|
||||
public static unsafe short* GetPtr(this short[] array)
|
||||
{ short* Ptr; fixed ( short* tempPtr = array) Ptr = tempPtr; return Ptr; }
|
||||
|
||||
public static unsafe ushort* GetPtr(this ushort[] array)
|
||||
{ ushort* Ptr; fixed (ushort* tempPtr = array) Ptr = tempPtr; return Ptr; }
|
||||
|
||||
public static unsafe int* GetPtr(this int[] array)
|
||||
{ int* Ptr; fixed ( int* tempPtr = array) Ptr = tempPtr; return Ptr; }
|
||||
|
||||
public static unsafe uint* GetPtr(this uint[] array)
|
||||
{ uint* Ptr; fixed ( uint* tempPtr = array) Ptr = tempPtr; return Ptr; }
|
||||
|
||||
public static unsafe long* GetPtr(this long[] array)
|
||||
{ long* Ptr; fixed ( long* tempPtr = array) Ptr = tempPtr; return Ptr; }
|
||||
|
||||
public static unsafe ulong* GetPtr(this ulong[] array)
|
||||
{ ulong* Ptr; fixed ( ulong* tempPtr = array) Ptr = tempPtr; return Ptr; }
|
||||
|
||||
public static unsafe float* GetPtr(this float[] array)
|
||||
{ float* Ptr; fixed ( float* tempPtr = array) Ptr = tempPtr; return Ptr; }
|
||||
|
||||
public static unsafe double* GetPtr(this double[] array)
|
||||
{ double* Ptr; fixed (double* tempPtr = array) Ptr = tempPtr; return Ptr; }
|
||||
}
|
||||
}
|
||||
@@ -1,326 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib.MessagePack
|
||||
{
|
||||
public class IO
|
||||
{
|
||||
public Stream _IO;
|
||||
|
||||
public IO( ) => _IO = File.OpenWriter();
|
||||
public IO(Stream IO) => _IO = IO;
|
||||
|
||||
public void Close() => _IO.Close();
|
||||
|
||||
public MsgPack Read(bool NotArray = true)
|
||||
{
|
||||
MsgPack MsgPack = new MsgPack();
|
||||
byte Unk = _IO.ReadByte();
|
||||
MsgPack.Type = (MsgPack.Types)Unk;
|
||||
if (NotArray)
|
||||
{
|
||||
MsgPack.Name = ReadString(MsgPack.Type);
|
||||
if (MsgPack.Name != null) { Unk = _IO.ReadByte(); MsgPack.Type = (MsgPack.Types)Unk; }
|
||||
}
|
||||
|
||||
bool FixArr = MsgPack.Type >= MsgPack.Types.FixArr && MsgPack.Type <= MsgPack.Types.FixArrMax;
|
||||
bool FixMap = MsgPack.Type >= MsgPack.Types.FixMap && MsgPack.Type <= MsgPack.Types.FixMapMax;
|
||||
bool FixStr = MsgPack.Type >= MsgPack.Types.FixStr && MsgPack.Type <= MsgPack.Types.FixStrMax;
|
||||
bool PosInt = MsgPack.Type >= MsgPack.Types.PosInt && MsgPack.Type <= MsgPack.Types.PosIntMax;
|
||||
bool NegInt = MsgPack.Type >= MsgPack.Types.NegInt && MsgPack.Type <= MsgPack.Types.NegIntMax;
|
||||
if (FixArr || FixMap || FixStr || PosInt || NegInt)
|
||||
{
|
||||
if (FixArr || FixMap)
|
||||
{
|
||||
MsgPack.Type = FixMap ? MsgPack.Types.FixMap : MsgPack.Types.FixArr;
|
||||
if (FixMap)
|
||||
{
|
||||
MsgPack.Object = new List<object>();
|
||||
for (int i = 0; i < Unk - (byte)MsgPack.Type; i++)
|
||||
MsgPack.Add(Read());
|
||||
}
|
||||
else
|
||||
{
|
||||
MsgPack.Object = new object[Unk - (byte)MsgPack.Type];
|
||||
for (int i = 0; i < Unk - (byte)MsgPack.Type; i++)
|
||||
MsgPack[i] = Read(false);
|
||||
}
|
||||
}
|
||||
else if (FixStr)
|
||||
{ MsgPack.Object = ReadString(MsgPack.Type); MsgPack.Type = MsgPack.Types.FixStr; }
|
||||
else if (PosInt)
|
||||
{ MsgPack.Object = (ulong) Unk; MsgPack.Type = MsgPack.Types.PosInt; }
|
||||
else if (NegInt)
|
||||
{ MsgPack.Object = ( long)(sbyte)Unk; MsgPack.Type = MsgPack.Types.NegInt; }
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (ReadNil (ref MsgPack)) break;
|
||||
if (ReadArr (ref MsgPack)) break;
|
||||
if (ReadMap (ref MsgPack)) break;
|
||||
if (ReadExt (ref MsgPack)) break;
|
||||
if (ReadString (ref MsgPack)) break;
|
||||
if (ReadBoolean(ref MsgPack)) break;
|
||||
if (ReadBytes (ref MsgPack)) break;
|
||||
if (ReadInt (ref MsgPack)) break;
|
||||
if (ReadUInt (ref MsgPack)) break;
|
||||
if (ReadFloat (ref MsgPack)) break;
|
||||
break;
|
||||
}
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
private bool ReadInt(ref MsgPack MsgPack)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.Int8 ) MsgPack.Object = (long)_IO.ReadSByte();
|
||||
else if (MsgPack.Type == MsgPack.Types.Int16) MsgPack.Object = (long)_IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Int32) MsgPack.Object = (long)_IO.ReadInt32Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Int64) MsgPack.Object = (long)_IO.ReadInt64Endian(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadUInt(ref MsgPack MsgPack)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.UInt8 ) MsgPack.Object = (ulong)_IO.ReadByte();
|
||||
else if (MsgPack.Type == MsgPack.Types.UInt16) MsgPack.Object = (ulong)_IO.ReadUInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.UInt32) MsgPack.Object = (ulong)_IO.ReadUInt32Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.UInt64) MsgPack.Object = (ulong)_IO.ReadUInt64Endian(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadFloat(ref MsgPack MsgPack)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.Float32) MsgPack.Object = _IO.ReadSingleEndian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Float64) MsgPack.Object = _IO.ReadDoubleEndian(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadBoolean(ref MsgPack MsgPack)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.False) MsgPack.Object = false;
|
||||
else if (MsgPack.Type == MsgPack.Types.True ) MsgPack.Object = true ;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadBytes(ref MsgPack MsgPack)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.Bin8 ) Length = _IO.ReadByte();
|
||||
else if (MsgPack.Type == MsgPack.Types.Bin16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Bin32) Length = _IO.ReadInt32Endian(true);
|
||||
else return false;
|
||||
MsgPack.Object = _IO.ReadBytes(Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadString(ref MsgPack MsgPack)
|
||||
{
|
||||
string val = ReadString(MsgPack.Type);
|
||||
if (val != null) MsgPack.Object = val;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private string ReadString(MsgPack.Types Val)
|
||||
{
|
||||
if (Val >= MsgPack.Types.FixStr && Val <= MsgPack.Types.FixStrMax)
|
||||
return _IO.ReadString(Val - MsgPack.Types.FixStr);
|
||||
else if (Val >= MsgPack.Types.Str8 && Val <= MsgPack.Types.Str32)
|
||||
{
|
||||
Enum.TryParse(Val.ToString(), out MsgPack.Types Type);
|
||||
int Length = 0;
|
||||
if (Type == MsgPack.Types.Str8 ) Length = _IO.ReadByte();
|
||||
else if (Type == MsgPack.Types.Str16) Length = _IO.ReadInt16Endian(true);
|
||||
else Length = _IO.ReadInt32Endian(true);
|
||||
return _IO.ReadString(Length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool ReadNil(ref MsgPack MsgPack)
|
||||
{
|
||||
if (MsgPack.Type == MsgPack.Types.Nil)
|
||||
MsgPack.Object = null;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadArr(ref MsgPack MsgPack)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.Arr16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Arr32) Length = _IO.ReadInt32Endian(true);
|
||||
else return false;
|
||||
MsgPack.Object = new object[Length];
|
||||
for (int i = 0; i < Length; i++) MsgPack[i] = Read(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadMap(ref MsgPack MsgPack)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.Map16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types.Map32) Length = _IO.ReadInt32Endian(true);
|
||||
else return false;
|
||||
MsgPack.Object = new List<object>();
|
||||
for (int i = 0; i < Length; i++) MsgPack.Add(Read());
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool ReadExt(ref MsgPack MsgPack)
|
||||
{
|
||||
int Length = 0;
|
||||
if (MsgPack.Type == MsgPack.Types.FixExt1 ) Length = 1 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt2 ) Length = 2 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt4 ) Length = 4 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt8 ) Length = 8 ;
|
||||
else if (MsgPack.Type == MsgPack.Types.FixExt16) Length = 16;
|
||||
else if (MsgPack.Type == MsgPack.Types. Ext8 ) Length = _IO.ReadByte();
|
||||
else if (MsgPack.Type == MsgPack.Types. Ext16) Length = _IO.ReadInt16Endian(true);
|
||||
else if (MsgPack.Type == MsgPack.Types. Ext32) Length = _IO.ReadInt32Endian(true);
|
||||
else return false;
|
||||
MsgPack.Object = new MsgPack.Ext { Type = _IO.ReadSByte(), Data = _IO.ReadBytes(Length) };
|
||||
return true;
|
||||
}
|
||||
|
||||
public IO Write(MsgPack MsgPack, bool Close)
|
||||
{ Write(MsgPack); if (Close) this.Close(); return this; }
|
||||
|
||||
public IO Write(MsgPack MsgPack)
|
||||
{
|
||||
if (MsgPack.Name != null) Write(MsgPack.Name);
|
||||
Write(MsgPack.Object);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void Write(object obj)
|
||||
{
|
||||
if (obj == null) { WriteNil(); return; }
|
||||
switch (obj)
|
||||
{
|
||||
case List<object> val: WriteMap(val.Count );
|
||||
foreach (object Val in val) Write(Val); break;
|
||||
case object[] val: WriteArr(val.Length);
|
||||
foreach (object Val in val) Write(Val); break;
|
||||
case MsgPack val: Write(val); break;
|
||||
case byte[] val: Write(val); break;
|
||||
case bool val: Write(val); break;
|
||||
case sbyte val: Write(val); break;
|
||||
case byte val: Write(val); break;
|
||||
case short val: Write(val); break;
|
||||
case ushort val: Write(val); break;
|
||||
case int val: Write(val); break;
|
||||
case uint val: Write(val); break;
|
||||
case long val: Write(val); break;
|
||||
case ulong val: Write(val); break;
|
||||
case float val: Write(val); break;
|
||||
case double val: Write(val); break;
|
||||
case string val: Write(val); break;
|
||||
case MsgPack.Ext val: Write(val); break;
|
||||
}
|
||||
}
|
||||
|
||||
private void Write( sbyte val) { if (val < -0x20) _IO.Write((byte)0xD0); _IO.Write(val); }
|
||||
private void Write( byte val) { if (val >= 0x80) _IO.Write((byte)0xCC); _IO.Write(val); }
|
||||
private void Write( short val) { if (( sbyte)val == val) Write(( sbyte)val);
|
||||
else if (( byte)val == val) Write(( byte)val);
|
||||
else { _IO.Write((byte)0xD1); _IO.WriteEndian(val, true); } }
|
||||
private void Write(ushort val) { if (( byte)val == val) Write(( byte)val);
|
||||
else { _IO.Write((byte)0xCD); _IO.WriteEndian(val, true); } }
|
||||
private void Write( int val) { if (( short)val == val) Write(( short)val);
|
||||
else if ((ushort)val == val) Write((ushort)val);
|
||||
else { _IO.Write((byte)0xD2); _IO.WriteEndian(val, true); } }
|
||||
private void Write( uint val) { if ((ushort)val == val) Write((ushort)val);
|
||||
else { _IO.Write((byte)0xCE); _IO.WriteEndian(val, true); } }
|
||||
private void Write( long val) { if (( int)val == val) Write(( int)val);
|
||||
else if (( uint)val == val) Write(( uint)val);
|
||||
else { _IO.Write((byte)0xD3); _IO.WriteEndian(val, true); } }
|
||||
private void Write( ulong val) { if (( uint)val == val) Write(( uint)val);
|
||||
else { _IO.Write((byte)0xCF); _IO.WriteEndian(val, true); } }
|
||||
private void Write( float val) { if (( long)val == val) Write(( long)val);
|
||||
else { _IO.Write((byte)0xCA); _IO.WriteEndian(val, true); } }
|
||||
private void Write(double val) { if (( long)val == val) Write(( long)val);
|
||||
else if (( float)val == val) Write(( float)val);
|
||||
else { _IO.Write((byte)0xCB); _IO.WriteEndian(val, true); } }
|
||||
|
||||
private void Write( bool val)
|
||||
{ _IO.Write((byte)(val ? 0xC3 : 0xC2)); }
|
||||
|
||||
private void Write(byte[] val)
|
||||
{
|
||||
if (val == null) { WriteNil(); return; }
|
||||
|
||||
if (val.Length < 0x100)
|
||||
{ _IO.Write((byte)0xC4); _IO.Write (( byte)val.Length ); }
|
||||
else if (val.Length < 0x10000)
|
||||
{ _IO.Write((byte)0xC5); _IO.WriteEndian((ushort)val.Length, true); }
|
||||
else
|
||||
{ _IO.Write((byte)0xC6); _IO.WriteEndian( val.Length, true); }
|
||||
_IO.Write(val);
|
||||
}
|
||||
|
||||
private void Write(string val)
|
||||
{
|
||||
if (val == null) { WriteNil(); return; }
|
||||
|
||||
byte[] array = Text.ToUTF8(val);
|
||||
if (array.Length < 0x20)
|
||||
_IO.Write((byte)(0xA0 | (array.Length & 0x1F)));
|
||||
else if (array.Length < 0x100)
|
||||
{ _IO.Write((byte) 0xD9); _IO.Write (( byte)array.Length); }
|
||||
else if (array.Length < 0x10000)
|
||||
{ _IO.Write((byte )0xDA); _IO.WriteEndian((ushort)array.Length, true); }
|
||||
else
|
||||
{ _IO.Write((byte) 0xDB); _IO.WriteEndian( array.Length, true); }
|
||||
_IO.Write(array);
|
||||
}
|
||||
|
||||
private void WriteNil() => _IO.Write((byte)0xC0);
|
||||
|
||||
private void WriteArr(int val)
|
||||
{
|
||||
if (val == 0) { WriteNil(); return; }
|
||||
else if (val < 0x10) _IO.Write((byte)(0x90 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.Write((byte) 0xDC); _IO.WriteEndian((ushort)val, true); }
|
||||
else { _IO.Write((byte) 0xDD); _IO.WriteEndian( val, true); }
|
||||
}
|
||||
|
||||
private void WriteMap(int val)
|
||||
{
|
||||
if (val == 0) { WriteNil(); return; }
|
||||
else if (val < 0x10) _IO.Write((byte)(0x80 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.Write((byte) 0xDE); _IO.WriteEndian((ushort)val, true); }
|
||||
else { _IO.Write((byte) 0xDF); _IO.WriteEndian( val, true); }
|
||||
}
|
||||
|
||||
private void Write(MsgPack.Ext val)
|
||||
{
|
||||
if (val.Data == null) { WriteNil(); return; }
|
||||
|
||||
if (val.Data.Length < 1 ) { WriteNil(); return; }
|
||||
else if (val.Data.Length == 1 ) _IO.Write((byte)0xD4);
|
||||
else if (val.Data.Length == 2 ) _IO.Write((byte)0xD5);
|
||||
else if (val.Data.Length == 4 ) _IO.Write((byte)0xD6);
|
||||
else if (val.Data.Length == 8 ) _IO.Write((byte)0xD7);
|
||||
else if (val.Data.Length == 16) _IO.Write((byte)0xD8);
|
||||
else
|
||||
{
|
||||
if (val.Data.Length < 0x100)
|
||||
{ _IO.Write((byte)0xC7); _IO.Write (( byte)val.Data.Length); }
|
||||
else if (val.Data.Length < 0x10000)
|
||||
{ _IO.Write((byte)0xC8); _IO.WriteEndian((ushort)val.Data.Length, true); }
|
||||
else
|
||||
{ _IO.Write((byte)0xC9); _IO.WriteEndian( val.Data.Length, true); }
|
||||
}
|
||||
_IO.Write(val.Type);
|
||||
_IO.Write(val.Data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,244 +0,0 @@
|
||||
//Original or reader part: https://github.com/MarcosLopezC/LightJson/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib.MessagePack
|
||||
{
|
||||
public class JSONIO
|
||||
{
|
||||
public Stream _IO;
|
||||
|
||||
public JSONIO( ) => _IO = File.OpenWriter();
|
||||
public JSONIO(Stream IO) => _IO = IO;
|
||||
|
||||
public void Close() => _IO.Close();
|
||||
|
||||
public MsgPack Read() => ReadValue(null);
|
||||
|
||||
private string ReadKey() => ReadString();
|
||||
|
||||
private MsgPack ReadValue(string Key)
|
||||
{
|
||||
char c = _IO.SkipWhitespace().PeekCharUTF8();
|
||||
object obj = null;
|
||||
if (char.IsDigit(c))
|
||||
obj = ReadNumber ();
|
||||
switch (c)
|
||||
{
|
||||
case '"': obj = ReadString (); break;
|
||||
case '{': obj = ReadObject (); break;
|
||||
case '[': obj = ReadArray (); break;
|
||||
case '-': obj = ReadNumber (); break;
|
||||
case 't':
|
||||
case 'f': obj = ReadBoolean(); break;
|
||||
case 'n': obj = ReadNull (); break;
|
||||
}
|
||||
return new MsgPack(Key, obj);
|
||||
}
|
||||
|
||||
private string ReadString()
|
||||
{
|
||||
if (!_IO.Assert('"')) return null;
|
||||
char c;
|
||||
string s = "";
|
||||
while (true)
|
||||
{
|
||||
c = _IO.ReadCharUTF8();
|
||||
|
||||
if (c == '\\')
|
||||
{
|
||||
c = _IO.ReadCharUTF8();
|
||||
|
||||
switch (char.ToLower(c))
|
||||
{
|
||||
case '"' :
|
||||
case '\\':
|
||||
case '/' : s += c; break;
|
||||
case 'b' : s += '\b'; break;
|
||||
case 'f' : s += '\f'; break;
|
||||
case 'n' : s += '\n'; break;
|
||||
case 'r' : s += '\r'; break;
|
||||
case 't' : s += '\t'; break;
|
||||
case 'u' : s += ReadUnicodeLiteral(); break;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
else if (c == '"') break;
|
||||
else if (char.IsControl(c)) return null;
|
||||
else s += c;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private char ReadUnicodeLiteral() =>
|
||||
(char)((((((ReadHexDigit() << 4) | ReadHexDigit()) << 4) | ReadHexDigit()) << 4) | ReadHexDigit());
|
||||
|
||||
private int ReadHexDigit() => byte.Parse(_IO.ReadCharUTF8().ToString(),
|
||||
System.Globalization.NumberStyles.HexNumber);
|
||||
|
||||
private List<object> ReadObject()
|
||||
{
|
||||
List<object> Obj = new List<object>();
|
||||
if (!_IO.Assert('{')) return null;
|
||||
if (_IO.SkipWhitespace().PeekCharUTF8() == '}') { _IO.ReadCharUTF8(); return null; }
|
||||
|
||||
string key;
|
||||
while (true)
|
||||
{
|
||||
_IO.SkipWhitespace();
|
||||
|
||||
key = ReadString();
|
||||
if (!_IO.SkipWhitespace().Assert(':')) return null;
|
||||
Obj.Add(ReadValue(key));
|
||||
|
||||
_IO.SkipWhitespace();
|
||||
|
||||
var next = _IO.ReadCharUTF8();
|
||||
|
||||
if (next == '}') break;
|
||||
else if (next == ',') continue;
|
||||
else return null;
|
||||
}
|
||||
|
||||
return Obj;
|
||||
}
|
||||
|
||||
private object[] ReadArray()
|
||||
{
|
||||
List<object> Obj = new List<object>();
|
||||
if (!_IO.Assert('[')) return null;
|
||||
if (_IO.SkipWhitespace().PeekCharUTF8() == ']') { _IO.ReadCharUTF8(); return null; }
|
||||
|
||||
char c;
|
||||
while (true)
|
||||
{
|
||||
Obj.Add(ReadValue(null));
|
||||
c = _IO.SkipWhitespace().ReadCharUTF8();
|
||||
|
||||
if (c == ']') break;
|
||||
else if (c == ',') continue;
|
||||
else return null;
|
||||
}
|
||||
return Obj.ToArray();
|
||||
}
|
||||
|
||||
private object ReadNumber()
|
||||
{
|
||||
string s = " ";
|
||||
_IO.SkipWhitespace();
|
||||
if (_IO.PeekCharUTF8() == '-') s += _IO.ReadCharUTF8();
|
||||
if (_IO.PeekCharUTF8() == '0') s += _IO.ReadCharUTF8();
|
||||
else s += ReadDigits ();
|
||||
if (_IO.PeekCharUTF8() == '.') s += _IO.ReadCharUTF8() + ReadDigits();
|
||||
else return long.Parse(s);
|
||||
|
||||
char c = _IO.PeekCharUTF8();
|
||||
if (c == 'e' || c == 'E')
|
||||
{
|
||||
s += _IO.ReadCharUTF8();
|
||||
c = _IO.PeekCharUTF8();
|
||||
if (c == '+' || c == '-') s += _IO.ReadCharUTF8();
|
||||
s += ReadDigits();
|
||||
}
|
||||
return s.ToDouble();
|
||||
}
|
||||
|
||||
private bool ReadBoolean()
|
||||
{
|
||||
char c = _IO.PeekCharUTF8();
|
||||
if (c == 't' && _IO.Assert( "true")) return true;
|
||||
else if (c == 'f' && _IO.Assert("false")) return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool ReadNull() => _IO.Assert("null");
|
||||
|
||||
private string ReadDigits()
|
||||
{ string s = ""; while (char.IsDigit(_IO.SkipWhitespace().
|
||||
PeekCharUTF8())) s += _IO.ReadCharUTF8(); return s; }
|
||||
|
||||
public JSONIO Write(MsgPack MsgPack, bool Close, string End = "\n", string TabChar = "\t")
|
||||
{ Write(MsgPack, End, TabChar, "", true); if (Close) this.Close(); return this; }
|
||||
|
||||
public JSONIO Write(MsgPack MsgPack, bool Close, bool Style = false)
|
||||
{ Write(MsgPack, "\n", "\t", "", Style); if (Close) this.Close(); return this; }
|
||||
|
||||
private JSONIO Write(MsgPack MsgPack, string End, string TabChar, string Tab, bool Style)
|
||||
{
|
||||
string OldTab = Tab;
|
||||
Tab += TabChar;
|
||||
if (MsgPack.Name != null) _IO.Write("\"" + MsgPack.Name + "\":" + (Style ? " " : ""));
|
||||
if (MsgPack.Object == null) { WriteNil(); return this; }
|
||||
|
||||
Type type = MsgPack.Object.GetType();
|
||||
if (type == typeof(List<object>))
|
||||
{
|
||||
List<object> Obj = (List<object>)MsgPack.Object;
|
||||
WriteMap();
|
||||
if (Style) _IO.Write(End);
|
||||
for (int i = 0; i < Obj. Count; i++)
|
||||
{
|
||||
if (Style) _IO.Write(Tab);
|
||||
Write(Obj[i], Obj[i].GetType(), End, TabChar, Tab, Style);
|
||||
if (i + 1 < Obj. Count) _IO.Write(',');
|
||||
if (Style) _IO.Write(End);
|
||||
}
|
||||
if (Style) _IO.Write(OldTab);
|
||||
WriteMap(true);
|
||||
}
|
||||
else if (type == typeof(object[]))
|
||||
{
|
||||
object[] Obj = (object[])MsgPack.Object;
|
||||
WriteArr();
|
||||
if (Style) _IO.Write(End);
|
||||
for (int i = 0; i < Obj.Length; i++)
|
||||
{
|
||||
if (Style) _IO.Write(Tab);
|
||||
Write(Obj[i], Obj[i].GetType(), End, TabChar, Tab, Style);
|
||||
if (i + 1 < Obj.Length) _IO.Write(',');
|
||||
if (Style) _IO.Write(End);
|
||||
}
|
||||
if (Style) _IO.Write(OldTab);
|
||||
WriteArr(true);
|
||||
}
|
||||
else if (type == typeof(MsgPack))
|
||||
Write((MsgPack)MsgPack.Object, End, TabChar, Tab, Style);
|
||||
else Write(MsgPack.Object, type, End, TabChar, Tab, Style);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private void Write(object obj, Type type, string End, string TabChar, string Tab, bool Style)
|
||||
{
|
||||
if (obj == null) { WriteNil(); return; }
|
||||
switch (obj)
|
||||
{
|
||||
case MsgPack val: Write(val, End, TabChar, Tab, Style); break;
|
||||
case bool val: Write(val); break;
|
||||
case string val: Write(val); break;
|
||||
case sbyte val: _IO.Write(Main.ToString(val)); break;
|
||||
case byte val: _IO.Write(Main.ToString(val)); break;
|
||||
case short val: _IO.Write(Main.ToString(val)); break;
|
||||
case ushort val: _IO.Write(Main.ToString(val)); break;
|
||||
case int val: _IO.Write(Main.ToString(val)); break;
|
||||
case uint val: _IO.Write(Main.ToString(val)); break;
|
||||
case long val: _IO.Write(Main.ToString(val)); break;
|
||||
case ulong val: _IO.Write(Main.ToString(val)); break;
|
||||
case float val: _IO.Write(Main.ToString(val)); break;
|
||||
case double val: _IO.Write(Main.ToString(val)); break;
|
||||
}
|
||||
}
|
||||
private void Write( bool val) => _IO.Write(val ? "true" : "false");
|
||||
private void Write(string val) => _IO.Write("\"" + val
|
||||
.Replace("\\", "\\\\").Replace("/" , "\\/").Replace("\'", "\\\'").Replace("\"", "\\\"")
|
||||
.Replace("\0", "\\0" ).Replace("\a", "\\a").Replace("\b", "\\b" ).Replace("\f", "\\f" )
|
||||
.Replace("\n", "\\n" ).Replace("\r", "\\r").Replace("\t", "\\t" ) + "\"");
|
||||
|
||||
private void WriteNil() => _IO.Write("null");
|
||||
private void WriteArr(bool End = false) => _IO.Write(End ? "]" : "[");
|
||||
private void WriteMap(bool End = false) => _IO.Write(End ? "}" : "{");
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
using KKdMainLib.IO;
|
||||
using MPIO = KKdMainLib.MessagePack.IO;
|
||||
|
||||
namespace KKdMainLib.MessagePack
|
||||
{
|
||||
public static class MPExt
|
||||
{
|
||||
public static MsgPack ReadMP(this string file, bool JSON = false)
|
||||
{
|
||||
MsgPack MsgPack;
|
||||
if (JSON)
|
||||
{ JSONIO IO = new JSONIO(File.OpenReader(file + ".json"));
|
||||
MsgPack = IO.Read(); IO.Close(); IO = null; }
|
||||
else
|
||||
{ MPIO IO = new MPIO(File.OpenReader(file + ".mp" ));
|
||||
MsgPack = IO.Read(); IO.Close(); IO = null; }
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
public static void Write(this MsgPack mp, bool Temp, string file, bool JSON = false)
|
||||
{ if (Temp) new MsgPack().Add(mp).Write(file, JSON).Dispose();
|
||||
else mp .Write(file, JSON); }
|
||||
|
||||
public static MsgPack Write(this MsgPack mp, string file, bool JSON = false)
|
||||
{
|
||||
if (JSON)
|
||||
{ JSONIO IO = new JSONIO(File.OpenWriter(file + ".json", true));
|
||||
IO.Write(mp, true, true); IO = null; }
|
||||
else
|
||||
{ MPIO IO = new MPIO(File.OpenWriter(file + ".mp" , true));
|
||||
IO.Write(mp, true ); IO = null; }
|
||||
return mp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,354 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace KKdMainLib.MessagePack
|
||||
{
|
||||
public class MsgPack : IDisposable
|
||||
{
|
||||
public Types Type;
|
||||
public string Name;
|
||||
public object Object;
|
||||
|
||||
public MsgPack( Types Type = Types.Map32) => NewMsgPack(null, Type);
|
||||
public MsgPack(string Name, Types Type = Types.Map32) => NewMsgPack(Name, Type);
|
||||
public MsgPack( long Count) => NewMsgPack(null, Count);
|
||||
public MsgPack(string Name, long Count) => NewMsgPack(Name, Count);
|
||||
public MsgPack(string Name, Types Type, object Object)
|
||||
{ this.Name = Name; this.Type = Type; this.Object = Object; }
|
||||
public MsgPack(string Name, object Object)
|
||||
{
|
||||
switch (Object)
|
||||
{
|
||||
case List<object> val: Type = Types. Map32; break;
|
||||
case object[] val: Type = Types. Arr32; break;
|
||||
case MsgPack val: Type = Types. Map32; break;
|
||||
case byte[] val: Type = Types. Bin32; break;
|
||||
case bool val: Type = val ? Types.True : Types.False; break;
|
||||
case sbyte val: Type = Types. Int8 ; break;
|
||||
case byte val: Type = Types. UInt8 ; break;
|
||||
case short val: Type = Types. Int16; break;
|
||||
case ushort val: Type = Types. UInt16; break;
|
||||
case int val: Type = Types. Int32; break;
|
||||
case uint val: Type = Types. UInt32; break;
|
||||
case long val: Type = Types. Int64; break;
|
||||
case ulong val: Type = Types. UInt64; break;
|
||||
case float val: Type = Types.Float32; break;
|
||||
case double val: Type = Types.Float64; break;
|
||||
case string val: Type = Types. Str32; break;
|
||||
case Ext val: Type = Types. Ext32; break;
|
||||
}
|
||||
this.Name = Name; this.Object = Object;
|
||||
}
|
||||
|
||||
public static MsgPack Null => null;
|
||||
|
||||
public object this[int index]
|
||||
{ get { return ((object[])Object)[index]; }
|
||||
set { object[] Data = (object[])Object; Data[index] = value; Object = Data; } }
|
||||
|
||||
public MsgPack(List<object> Object, string Name, Types Type)
|
||||
{ this.Object = Object; this.Name = Name; this.Type = Type; }
|
||||
|
||||
private void NewMsgPack(string Name, Types Type)
|
||||
{ Object = new List<object>(); this.Name = Name; this.Type = Type; }
|
||||
|
||||
private void NewMsgPack(string Name, long Count)
|
||||
{ if (Count > 0) Object = new object[Count]; else Object = null; this.Name = Name; Type = Types.Arr32; }
|
||||
|
||||
public MsgPack Add(object obj)
|
||||
{ if (obj != null) if (typeof(List<object>) == Object.GetType())
|
||||
{ List<object> Obj = (List<object>)Object; Obj.Add(obj); Object = Obj; } return this; }
|
||||
|
||||
public MsgPack ToArray()
|
||||
{ if (typeof(List<object> ) == Object.GetType())
|
||||
{ Object = ((List<object> ) Object) .ToArray(); Type = Types.Arr32; } return this; }
|
||||
|
||||
public MsgPack ToList()
|
||||
{ if (typeof( object[]) == Object.GetType())
|
||||
{ Object = (( object[]) Object).OfType<object>().ToList (); Type = Types.Map32; } return this; }
|
||||
|
||||
public void Dispose()
|
||||
{ Type = 0; Name = null; Object = null; }
|
||||
|
||||
public MsgPack Add( sbyte? val) => Add(null, val);
|
||||
public MsgPack Add( byte? val) => Add(null, val);
|
||||
public MsgPack Add( short? val) => Add(null, val);
|
||||
public MsgPack Add(ushort? val) => Add(null, val);
|
||||
public MsgPack Add( int? val) => Add(null, val);
|
||||
public MsgPack Add( uint? val) => Add(null, val);
|
||||
public MsgPack Add( long? val) => Add(null, val);
|
||||
public MsgPack Add( ulong? val) => Add(null, val);
|
||||
public MsgPack Add( float? val) => Add(null, val);
|
||||
public MsgPack Add(double? val) => Add(null, val);
|
||||
|
||||
public MsgPack Add(byte[] val) => Add(null, val);
|
||||
public MsgPack Add(string val) => Add(null, val);
|
||||
public MsgPack Add( bool val) => Add(null, val);
|
||||
public MsgPack Add( sbyte val) => Add(null, val);
|
||||
public MsgPack Add( byte val) => Add(null, val);
|
||||
public MsgPack Add( short val) => Add(null, val);
|
||||
public MsgPack Add(ushort val) => Add(null, val);
|
||||
public MsgPack Add( int val) => Add(null, val);
|
||||
public MsgPack Add( uint val) => Add(null, val);
|
||||
public MsgPack Add( long val) => Add(null, val);
|
||||
public MsgPack Add( ulong val) => Add(null, val);
|
||||
public MsgPack Add( float val) => Add(null, val);
|
||||
public MsgPack Add(double val) => Add(null, val);
|
||||
|
||||
public MsgPack Add(string Val, sbyte? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( sbyte)val); return this; }
|
||||
public MsgPack Add(string Val, byte? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( byte)val); return this; }
|
||||
public MsgPack Add(string Val, short? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( short)val); return this; }
|
||||
public MsgPack Add(string Val, ushort? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, (ushort)val); return this; }
|
||||
public MsgPack Add(string Val, int? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( int)val); return this; }
|
||||
public MsgPack Add(string Val, uint? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( uint)val); return this; }
|
||||
public MsgPack Add(string Val, long? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( long)val); return this; }
|
||||
public MsgPack Add(string Val, ulong? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( ulong)val); return this; }
|
||||
public MsgPack Add(string Val, float? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, ( float)val); return this; }
|
||||
public MsgPack Add(string Val, double? val)
|
||||
{ if (val == null) Add(Null); else Add(Val, (double)val); return this; }
|
||||
|
||||
public MsgPack Add(string Val, byte[] val)
|
||||
{ if (val == null) Add(Null); else
|
||||
Add(new MsgPack(Val, Types. Bin32, val)); return this; }
|
||||
public MsgPack Add(string Val, string val)
|
||||
{ if (val == null) Add(Null); else
|
||||
Add(new MsgPack(Val, Types. Str32, val)); return this; }
|
||||
public MsgPack Add(string Val, bool val)
|
||||
{ Add(new MsgPack(Val, val ?
|
||||
Types.True : Types. False, val)); return this; }
|
||||
public MsgPack Add(string Val, sbyte val)
|
||||
{ Add(new MsgPack(Val, Types. Int8, val)); return this; }
|
||||
public MsgPack Add(string Val, byte val)
|
||||
{ Add(new MsgPack(Val, Types. UInt8, val)); return this; }
|
||||
public MsgPack Add(string Val, short val)
|
||||
{ Add(new MsgPack(Val, Types. Int16, val)); return this; }
|
||||
public MsgPack Add(string Val, ushort val)
|
||||
{ Add(new MsgPack(Val, Types. UInt16, val)); return this; }
|
||||
public MsgPack Add(string Val, int val)
|
||||
{ Add(new MsgPack(Val, Types. Int32, val)); return this; }
|
||||
public MsgPack Add(string Val, uint val)
|
||||
{ Add(new MsgPack(Val, Types. UInt32, val)); return this; }
|
||||
public MsgPack Add(string Val, long val)
|
||||
{ Add(new MsgPack(Val, Types. Int64, val)); return this; }
|
||||
public MsgPack Add(string Val, ulong val)
|
||||
{ Add(new MsgPack(Val, Types. UInt64, val)); return this; }
|
||||
public MsgPack Add(string Val, float val)
|
||||
{ Add(new MsgPack(Val, Types.Float32, val)); return this; }
|
||||
public MsgPack Add(string Val, double val)
|
||||
{ Add(new MsgPack(Val, Types.Float64, val)); return this; }
|
||||
|
||||
public bool ReadBoolean(string Name) => ReadNBoolean(Name).GetValueOrDefault();
|
||||
public sbyte ReadInt8(string Name) => ReadNInt8(Name).GetValueOrDefault();
|
||||
public byte ReadUInt8(string Name) => ReadNUInt8(Name).GetValueOrDefault();
|
||||
public short ReadInt16(string Name) => ReadNInt16(Name).GetValueOrDefault();
|
||||
public ushort ReadUInt16(string Name) => ReadNUInt16(Name).GetValueOrDefault();
|
||||
public int ReadInt32(string Name) => ReadNInt32(Name).GetValueOrDefault();
|
||||
public uint ReadUInt32(string Name) => ReadNUInt32(Name).GetValueOrDefault();
|
||||
public long ReadInt64(string Name) => ReadNInt64(Name).GetValueOrDefault();
|
||||
public ulong ReadUInt64(string Name) => ReadNUInt64(Name).GetValueOrDefault();
|
||||
public float ReadSingle(string Name) => ReadNSingle(Name).GetValueOrDefault();
|
||||
public double ReadDouble(string Name) => ReadNDouble(Name).GetValueOrDefault();
|
||||
|
||||
public bool? ReadNBoolean(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack.ReadNBoolean(); return null; }
|
||||
public sbyte? ReadNInt8(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt8(); return null; }
|
||||
public byte? ReadNUInt8(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt8(); return null; }
|
||||
public short? ReadNInt16(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt16(); return null; }
|
||||
public ushort? ReadNUInt16(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt16(); return null; }
|
||||
public int? ReadNInt32(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt32(); return null; }
|
||||
public uint? ReadNUInt32(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt32(); return null; }
|
||||
public long? ReadNInt64(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNInt64(); return null; }
|
||||
public ulong? ReadNUInt64(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNUInt64(); return null; }
|
||||
public float? ReadNSingle(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNSingle(); return null; }
|
||||
public double? ReadNDouble(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadNDouble(); return null; }
|
||||
public string ReadString(string Name)
|
||||
{ if (Element(Name, out MsgPack MsgPack)) return MsgPack. ReadString(); return null; }
|
||||
|
||||
public bool ReadBoolean() => ReadNBoolean().GetValueOrDefault();
|
||||
public sbyte ReadInt8() => ReadNInt8().GetValueOrDefault();
|
||||
public byte ReadUInt8() => ReadNUInt8().GetValueOrDefault();
|
||||
public short ReadInt16() => ReadNInt16().GetValueOrDefault();
|
||||
public ushort ReadUInt16() => ReadNUInt16().GetValueOrDefault();
|
||||
public int ReadInt32() => ReadNInt32().GetValueOrDefault();
|
||||
public uint ReadUInt32() => ReadNUInt32().GetValueOrDefault();
|
||||
public long ReadInt64() => ReadNInt64().GetValueOrDefault();
|
||||
public ulong ReadUInt64() => ReadNUInt64().GetValueOrDefault();
|
||||
public float ReadSingle() => ReadNSingle().GetValueOrDefault();
|
||||
public double ReadDouble() => ReadNDouble().GetValueOrDefault();
|
||||
|
||||
public bool? ReadNBoolean()
|
||||
{ if (Object == null) return null;
|
||||
if (Object.GetType() == typeof( bool)) return ( bool) Object; return null; ; }
|
||||
public sbyte? ReadNInt8()
|
||||
{ if (Object == null) return null;
|
||||
if (Object.GetType() == typeof( long)) return ( sbyte)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return ( sbyte)(ulong)Object; return null; }
|
||||
public byte? ReadNUInt8()
|
||||
{ if (Object == null) return null;
|
||||
if (Object.GetType() == typeof( long)) return ( byte)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return ( byte)(ulong)Object; return null; }
|
||||
public short? ReadNInt16()
|
||||
{ if (Object == null) return null;
|
||||
if (Object.GetType() == typeof( long)) return ( short)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return ( short)(ulong)Object; return null; }
|
||||
public ushort? ReadNUInt16()
|
||||
{ if (Object == null) return null;
|
||||
if (Object.GetType() == typeof( long)) return (ushort)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return (ushort)(ulong)Object; return null; }
|
||||
public int? ReadNInt32()
|
||||
{ if (Object == null) return null;
|
||||
if (Object.GetType() == typeof( long)) return ( int)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return ( int)(ulong)Object; return null; }
|
||||
public uint? ReadNUInt32()
|
||||
{ if (Object == null) return null;
|
||||
if (Object.GetType() == typeof( long)) return ( uint)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return ( uint)(ulong)Object; return null; }
|
||||
public long? ReadNInt64()
|
||||
{ if (Object == null) return null;
|
||||
if (Object.GetType() == typeof( long)) return ( long) Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return ( long)(ulong)Object; return null; }
|
||||
public ulong? ReadNUInt64()
|
||||
{ if (Object == null) return null;
|
||||
if (Object.GetType() == typeof( ulong)) return ( ulong) Object;
|
||||
else if (Object.GetType() == typeof( long)) return ( ulong)( long)Object; return null; }
|
||||
public float? ReadNSingle()
|
||||
{ if (Object == null) return null;
|
||||
if (Object.GetType() == typeof(double)) return (float)(double)Object;
|
||||
else if (Object.GetType() == typeof( float)) return (float) Object;
|
||||
else if (Object.GetType() == typeof( long)) return (float)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return (float)( ulong)Object; return null; }
|
||||
public double? ReadNDouble()
|
||||
{ if (Object == null) return null;
|
||||
if (Object.GetType() == typeof(double)) return (double) Object;
|
||||
else if (Object.GetType() == typeof( float)) return (double)(float)Object;
|
||||
else if (Object.GetType() == typeof( long)) return (double)( long)Object;
|
||||
else if (Object.GetType() == typeof( ulong)) return (double)(ulong)Object; return null; }
|
||||
public string ReadString()
|
||||
{ if (Object == null) return null;
|
||||
if (Object.GetType() == typeof(string)) return (string) Object; return null; }
|
||||
|
||||
public bool Element(string Name, out MsgPack MsgPack, Type Type)
|
||||
{ if (Element(out MsgPack, Name)) return MsgPack.Object.GetType() == Type; return false; }
|
||||
|
||||
public bool Element(string Name, out MsgPack MsgPack)
|
||||
{ if (Element(out MsgPack, Name)) return MsgPack != null; return false; }
|
||||
|
||||
public bool Element(out MsgPack MsgPack, string Name)
|
||||
{
|
||||
MsgPack = null;
|
||||
if (Object == null) return false;
|
||||
|
||||
Type type = Object.GetType();
|
||||
if (type == typeof(List<object>))
|
||||
{
|
||||
List<object> Obj = (List<object>)Object;
|
||||
foreach (object obj in Obj)
|
||||
{
|
||||
if (obj == null) continue; type = obj.GetType();
|
||||
if (type == typeof(MsgPack)) if (((MsgPack)obj).Name == Name)
|
||||
{ MsgPack = (MsgPack)obj; return true; }
|
||||
}
|
||||
}
|
||||
else if (type == typeof(object[]))
|
||||
{
|
||||
object[] Obj = (object[])Object;
|
||||
foreach (object obj in Obj)
|
||||
{
|
||||
if (obj == null) continue; type = obj.GetType();
|
||||
if (type == typeof(MsgPack)) if (((MsgPack)obj).Name == Name)
|
||||
{ MsgPack = (MsgPack)obj; return true; }
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool ContainsKey(string Name)
|
||||
{
|
||||
if (Object == null) return false;
|
||||
|
||||
Type type = Object.GetType();
|
||||
if (type == typeof(List<object>))
|
||||
{
|
||||
List<object> Obj = (List<object>)Object;
|
||||
foreach (object obj in Obj)
|
||||
{
|
||||
if (obj == null) continue; type = obj.GetType();
|
||||
if (type == typeof(MsgPack)) if (((MsgPack)obj).Name == Name) return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public enum Types : byte
|
||||
{
|
||||
PosInt = 0b00000000,
|
||||
FixMap = 0b10000000,
|
||||
FixArr = 0b10010000,
|
||||
FixStr = 0b10100000,
|
||||
Nil = 0b11000000,
|
||||
NeverUsed = 0b11000001,
|
||||
False = 0b11000010,
|
||||
True = 0b11000011,
|
||||
Bin8 = 0b11000100,
|
||||
Bin16 = 0b11000101,
|
||||
Bin32 = 0b11000110,
|
||||
Ext8 = 0b11000111,
|
||||
Ext16 = 0b11001000,
|
||||
Ext32 = 0b11001001,
|
||||
Float32 = 0b11001010,
|
||||
Float64 = 0b11001011,
|
||||
UInt8 = 0b11001100,
|
||||
UInt16 = 0b11001101,
|
||||
UInt32 = 0b11001110,
|
||||
UInt64 = 0b11001111,
|
||||
Int8 = 0b11010000,
|
||||
Int16 = 0b11010001,
|
||||
Int32 = 0b11010010,
|
||||
Int64 = 0b11010011,
|
||||
FixExt1 = 0b11010100,
|
||||
FixExt2 = 0b11010101,
|
||||
FixExt4 = 0b11010110,
|
||||
FixExt8 = 0b11010111,
|
||||
FixExt16 = 0b11011000,
|
||||
Str8 = 0b11011001,
|
||||
Str16 = 0b11011010,
|
||||
Str32 = 0b11011011,
|
||||
Arr16 = 0b11011100,
|
||||
Arr32 = 0b11011101,
|
||||
Map16 = 0b11011110,
|
||||
Map32 = 0b11011111,
|
||||
NegInt = 0b11100000,
|
||||
PosIntMax = 0b01111111,
|
||||
FixMapMax = 0b10001111,
|
||||
FixArrMax = 0b10011111,
|
||||
FixStrMax = 0b10111111,
|
||||
NegIntMax = 0b11111111,
|
||||
}
|
||||
|
||||
public struct Ext
|
||||
{
|
||||
public byte[] Data;
|
||||
public sbyte Type;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,380 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public struct Mot : System.IDisposable
|
||||
{
|
||||
private int i, i0, i1;
|
||||
public MotHeader[] MOT;
|
||||
private Stream s;
|
||||
|
||||
[System.ThreadStatic] public bool Modern;
|
||||
|
||||
public void MOTReader(string file)
|
||||
{
|
||||
s = File.OpenReader(file + ".bin");
|
||||
|
||||
i = 0;
|
||||
while (true)
|
||||
if (s.RI64() == 0) break;
|
||||
else { s.RI64(); i++; }
|
||||
if (i == 0) return;
|
||||
|
||||
s.P = 0;
|
||||
int motCount = i;
|
||||
MOT = new MotHeader[motCount];
|
||||
for (i = 0; i < motCount; i++)
|
||||
{
|
||||
ref MotHeader mot = ref MOT[i];
|
||||
mot.KeySet .O = s.RI32();
|
||||
mot.KeySetTypesOffset = s.RI32();
|
||||
mot. KeySetOffset = s.RI32();
|
||||
mot.BoneInfo .O = s.RI32();
|
||||
}
|
||||
|
||||
for (i = 0; i < motCount; i++)
|
||||
{
|
||||
ref MotHeader mot = ref MOT[i];
|
||||
|
||||
i0 = 1;
|
||||
s.P = mot.BoneInfo.O;
|
||||
s.RU16();
|
||||
while (s.P < s.L && s.RU16() != 0) i0++;
|
||||
|
||||
mot.BoneInfo.V = new int[i0];
|
||||
s.P = mot.BoneInfo.O;
|
||||
for (i0 = 0; i0 < mot.BoneInfo.V.Length; i0++)
|
||||
mot.BoneInfo.V[i0] = s.RU16();
|
||||
|
||||
s.P = mot.KeySet.O;
|
||||
int info = s.RU16();
|
||||
mot.HighBits = info >> 14;
|
||||
mot.FrameCount = s.RU16();
|
||||
|
||||
mot.KeySet.V = new KeySet[info & 0x3FFF];
|
||||
s.P = mot.KeySetTypesOffset;
|
||||
for (i0 = 0; i0 < mot.KeySet.V.Length; i0++)
|
||||
{
|
||||
if (i0 % 8 == 0) i1 = s.RU16();
|
||||
mot.KeySet.V[i0] = new KeySet { Type = (KeySetType)((i1 >> (i0 % 8 * 2)) & 0b11) };
|
||||
}
|
||||
|
||||
s.P = mot.KeySetOffset;
|
||||
for (i0 = 0; i0 < mot.KeySet.V.Length; i0++)
|
||||
{
|
||||
ref KeySet key = ref mot.KeySet.V[i0];
|
||||
if (key.Type == KeySetType.Static)
|
||||
{ key.Keys = new KFT2[1];
|
||||
key.Keys[0].V = s.RF32(); }
|
||||
else if (key.Type == KeySetType.Linear && !Modern)
|
||||
{
|
||||
key.Keys = new KFT2[s.RU16()];
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
key.Keys[i1].F = s.RU16();
|
||||
s.A(0x4);
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
key.Keys[i1].V = s.RF32();
|
||||
}
|
||||
else if (key.Type == KeySetType.Tangent && !Modern)
|
||||
{
|
||||
key.Keys = new KFT2[s.RU16()];
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
key.Keys[i1].F = s.RU16();
|
||||
s.A(0x4);
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
{ key.Keys[i1].V = s.RF32(); key.Keys[i1].T = s.RF32(); }
|
||||
}
|
||||
else if (key.Type != KeySetType.None)
|
||||
{
|
||||
key.Keys = new KFT2[s.RU16()];
|
||||
ushort type = s.RU16();
|
||||
if (key.Type == KeySetType.Tangent)
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
key.Keys[i1].T = s.RF32();
|
||||
|
||||
if (type == 1)
|
||||
{
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
key.Keys[i1].V = s.RF16();
|
||||
s.A(0x4);
|
||||
}
|
||||
else
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
key.Keys[i1].V = s.RF32();
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
key.Keys[i1].F = s.RU16();
|
||||
s.A(0x4);
|
||||
}
|
||||
}
|
||||
}
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MOTWriter(string file)
|
||||
{
|
||||
if (MOT == null) return;
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
|
||||
int MOTCount = MOT.Length;
|
||||
s.P = (MOTCount + 1) << 4;
|
||||
for (i = 0; i < MOTCount; i++)
|
||||
{
|
||||
ref MotHeader mot = ref MOT[i];
|
||||
mot.KeySet.O = s.P;
|
||||
s.W((ushort)((mot.HighBits << 14) | (mot.KeySet.V.Length & 0x3FFF)));
|
||||
s.W((ushort)mot.FrameCount);
|
||||
|
||||
mot.KeySetTypesOffset = s.P;
|
||||
for (i0 = 0, i1 = 0; i0 < mot.KeySet.V.Length; i0++)
|
||||
{
|
||||
i1 |= ((byte)mot.KeySet.V[i0].Type << (i0 % 8 * 2)) & (0b11 << (i0 % 8 * 2));
|
||||
|
||||
if (i0 % 8 == 7) { s.W((ushort)i1); i1 = 0; }
|
||||
}
|
||||
s.W((ushort)i1);
|
||||
if (s.P % 4 != 0) s.W((ushort)0x00);
|
||||
|
||||
mot.KeySetOffset = s.P;
|
||||
for (i0 = 0; i0 < mot.KeySet.V.Length; i0++)
|
||||
{
|
||||
ref KeySet key = ref mot.KeySet.V[i0];
|
||||
if (key.Type == KeySetType.Static)
|
||||
s.W(key.Keys[0].V);
|
||||
else if ((key.Type == KeySetType.Linear
|
||||
|| key.Type == KeySetType.Tangent) && !Modern)
|
||||
{
|
||||
s.W((ushort)key.Keys.Length);
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
s.W((ushort)key.Keys[i1].F);
|
||||
if (s.P % 4 != 0) s.W((ushort)0x00);
|
||||
if (key.Type == KeySetType.Tangent)
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
{ s.W(key.Keys[i1].V); s.W(key.Keys[i1].T); }
|
||||
else
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
s.W(key.Keys[i1].V);
|
||||
}
|
||||
else if (key.Type != KeySetType.None)
|
||||
{
|
||||
s.W((ushort)key.Keys.Length);
|
||||
s.W((ushort)0);
|
||||
if (key.Type == KeySetType.Tangent)
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
s.W(key.Keys[i1].T);
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
s.W(key.Keys[i1].V);
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
s.W((ushort)key.Keys[i1].F);
|
||||
s.A(0x4);
|
||||
}
|
||||
}
|
||||
if (s.P % 4 != 0) s.W((ushort)0x00);
|
||||
|
||||
mot.BoneInfo.O = s.P;
|
||||
for (i0 = 0; i0 < mot.BoneInfo.V.Length; i0++)
|
||||
s.W((ushort)mot.BoneInfo.V[i0]);
|
||||
s.W((ushort)0);
|
||||
}
|
||||
if (s.P % 4 != 0) s.W((ushort)0x00);
|
||||
s.A(0x4, true);
|
||||
|
||||
s.P = 0;
|
||||
for (i = 0; i < MOTCount; i++)
|
||||
{
|
||||
ref MotHeader mot = ref MOT[i];
|
||||
s.W(mot.KeySet .O );
|
||||
s.W(mot.KeySetTypesOffset);
|
||||
s.W(mot. KeySetOffset);
|
||||
s.W(mot.BoneInfo .O );
|
||||
}
|
||||
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
{
|
||||
MOT = null;
|
||||
|
||||
MsgPack msgPack = file.ReadMP(json);
|
||||
MsgPack mot;
|
||||
if ((mot = msgPack["MOT"]).NotNull)
|
||||
{
|
||||
MOT = new MotHeader[mot.Array.Length];
|
||||
for (int i = 0; i < MOT.Length; i++)
|
||||
MsgPackReader(mot.Array[i], ref MOT[i]);
|
||||
}
|
||||
mot.Dispose();
|
||||
msgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
int motCount = MOT.Length;
|
||||
MsgPack mot = new MsgPack(motCount, "MOT");
|
||||
for (i = 0; i < motCount; i++)
|
||||
mot[i] = MsgPackWriter(ref MOT[i]);
|
||||
mot.Write(false, true, file, json);
|
||||
}
|
||||
|
||||
public void MsgPackReader(MsgPack msgPack, ref MotHeader mot)
|
||||
{
|
||||
MsgPack temp = MsgPack.New;
|
||||
mot.HighBits = msgPack.RI32("HighBits" );
|
||||
mot.FrameCount = msgPack.RI32("FrameCount");
|
||||
|
||||
if ((temp = msgPack["KeySets", true]).IsNull) { temp.Dispose(); return; }
|
||||
|
||||
mot.KeySet.V = new KeySet[temp.Array.Length];
|
||||
for (i0 = 0; i0 < mot.KeySet.V.Length; i0++)
|
||||
{
|
||||
ref KeySet keySet = ref mot.KeySet.V[i0];
|
||||
|
||||
if (temp.Array[i0].Array == null || temp.Array[i0].Array.Length != 2) continue;
|
||||
keySet.Type = (KeySetType)temp.Array[i0].Array[0].RI32();
|
||||
|
||||
MsgPack temp1 = temp.Array[i0].Array[1];
|
||||
|
||||
if (temp1.Array == null) { keySet.Type = 0; continue; }
|
||||
else if (keySet.Type == KeySetType.None) continue;
|
||||
else if (keySet.Type == KeySetType.Static)
|
||||
{
|
||||
keySet.Keys = new KFT2[1];
|
||||
if (temp1.Array == null) continue;
|
||||
else if (temp1.Array.Length == 0) continue;
|
||||
else keySet.Keys[0] = new KFT2(0.0f, temp1.Array[0].RF32());
|
||||
}
|
||||
else if (keySet.Type == KeySetType.Linear)
|
||||
{
|
||||
keySet.Keys = new KFT2[temp1.Array.Length];
|
||||
for (i1 = 0; i1 < temp1.Array.Length; i1++)
|
||||
{
|
||||
ref MsgPack array = ref temp1.Array[i1];
|
||||
if (array.Array == null) continue;
|
||||
else if (array.Array.Length == 0) continue;
|
||||
else if (array.Array.Length == 1)
|
||||
keySet.Keys[i1] = new KFT2(array[0].RF32());
|
||||
else if (array.Array.Length == 2)
|
||||
keySet.Keys[i1] = new KFT2(array[0].RF32(), array[1].RF32());
|
||||
}
|
||||
}
|
||||
else if (keySet.Type == KeySetType.Tangent)
|
||||
{
|
||||
keySet.Keys = new KFT2[temp1.Array.Length];
|
||||
for (i1 = 0; i1 < temp1.Array.Length; i1++)
|
||||
{
|
||||
ref MsgPack array = ref temp1.Array[i1];
|
||||
if (array.Array == null ||
|
||||
array.Array.Length == 0) continue;
|
||||
else if (array.Array.Length == 1)
|
||||
keySet.Keys[i1] = new KFT2(array[0].RF32());
|
||||
else if (array.Array.Length == 2)
|
||||
keySet.Keys[i1] = new KFT2(array[0].RF32(), array[1].RF32());
|
||||
else if (array.Array.Length > 2)
|
||||
keySet.Keys[i1] = new KFT2(array[0].RF32(),
|
||||
array[1].RF32(), temp1.Array[i1][2].RF32());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((temp = msgPack["BoneInfo", true]).NotNull)
|
||||
{
|
||||
mot.BoneInfo.V = new int[temp.Array.Length];
|
||||
for (i = 0; i < mot.BoneInfo.V.Length; i++)
|
||||
mot.BoneInfo.V[i] = temp[i].RI32();
|
||||
}
|
||||
temp.Dispose();
|
||||
}
|
||||
|
||||
public MsgPack MsgPackWriter(ref MotHeader Mot)
|
||||
{
|
||||
MsgPack mot = MsgPack.NewReserve(4).Add("FrameCount", Mot.FrameCount).Add("HighBits", Mot.HighBits);
|
||||
|
||||
MsgPack keySets = new MsgPack(Mot.KeySet.V.Length, "KeySets");
|
||||
for (i0 = 0; i0 < Mot.KeySet.V.Length; i0++)
|
||||
{
|
||||
ref KeySet keySet = ref Mot.KeySet.V[i0];
|
||||
if (keySet.Type == KeySetType.None) continue;
|
||||
|
||||
keySets[i0] = new MsgPack(2);
|
||||
keySets[i0].Array[0] = (byte)keySet.Type;
|
||||
if (keySet.Type == KeySetType.Static)
|
||||
{
|
||||
IKF kf = keySet.Keys[0].Check();
|
||||
MsgPack k = default;
|
||||
if (kf is KFT0 KFT0) k = new MsgPack(null, new MsgPack[] { 0.0f });
|
||||
else if (kf is KFT1 KFT1) k = new MsgPack(null, new MsgPack[] { KFT1.V });
|
||||
keySets[i0].Array[1] = k;
|
||||
}
|
||||
else if (keySet.Type == KeySetType.Linear)
|
||||
{
|
||||
MsgPack k = new MsgPack(keySet.Keys.Length);
|
||||
for (i1 = 0; i1 < keySet.Keys.Length; i1++)
|
||||
{
|
||||
IKF kf = keySet.Keys[i1].Check();
|
||||
if (kf is KFT0 KFT0) k[i1] = new MsgPack(null, new MsgPack[] { KFT0.F });
|
||||
else if (kf is KFT1 KFT1) k[i1] = new MsgPack(null, new MsgPack[] { KFT1.F, KFT1.V });
|
||||
}
|
||||
keySets[i0].Array[1] = k;
|
||||
}
|
||||
else
|
||||
{
|
||||
MsgPack k = new MsgPack(keySet.Keys.Length);
|
||||
for (i1 = 0; i1 < keySet.Keys.Length; i1++)
|
||||
{
|
||||
IKF kf = keySet.Keys[i1].Check();
|
||||
if (kf is KFT0 KFT0) k[i1] = new MsgPack(null, new MsgPack[] { KFT0.F });
|
||||
else if (kf is KFT1 KFT1) k[i1] = new MsgPack(null, new MsgPack[] { KFT1.F, KFT1.V });
|
||||
else if (kf is KFT2 KFT2) k[i1] = new MsgPack(null, new MsgPack[] { KFT2.F, KFT2.V, KFT2.T });
|
||||
}
|
||||
keySets[i0].Array[1] = k;
|
||||
}
|
||||
}
|
||||
mot.Add(keySets);
|
||||
|
||||
MsgPack boneInfo = new MsgPack(Mot.BoneInfo.V.Length, "BoneInfo");
|
||||
for (i0 = 0; i0 < Mot.BoneInfo.V.Length; i0++)
|
||||
boneInfo[i0] = Mot.BoneInfo.V[i0];
|
||||
mot.Add(boneInfo);
|
||||
|
||||
return mot;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
s = null;
|
||||
MOT = null;
|
||||
}
|
||||
|
||||
public struct MotHeader
|
||||
{
|
||||
public int KeySetOffset;
|
||||
public int KeySetTypesOffset;
|
||||
public Pointer<KeySet[]> KeySet ;
|
||||
public Pointer< int[]> BoneInfo;
|
||||
|
||||
public int HighBits;
|
||||
public int FrameCount;
|
||||
}
|
||||
|
||||
public struct KeySet
|
||||
{
|
||||
public KFT2[] Keys;
|
||||
public KeySetType Type;
|
||||
|
||||
public override string ToString() =>
|
||||
$"Type: {Type}" + (Type == KeySetType.Static ? $"; Value: {Keys[0].V}"
|
||||
: Type > KeySetType.Static ? $"; Keys: {Keys.Length}; First Key: {Keys[0]}" : "");
|
||||
}
|
||||
|
||||
public enum KeySetType : byte
|
||||
{
|
||||
None = 0b00,
|
||||
Static = 0b01,
|
||||
Linear = 0b10,
|
||||
Tangent = 0b11,
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,63 +0,0 @@
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public struct PDHead
|
||||
{
|
||||
public int ID;
|
||||
public int Lenght;
|
||||
public int DataSize;
|
||||
public int Signature;
|
||||
public int SectionSize;
|
||||
public int RealSignature;
|
||||
public Main.Format Format;
|
||||
public bool IsBE => Format == Main.Format.F2BE;
|
||||
public bool IsX => Format == Main.Format.X || Format == Main.Format.XHD;
|
||||
}
|
||||
|
||||
public static class PDHeadExtensions
|
||||
{
|
||||
public static PDHead ReadHeader(this Stream stream, bool Seek)
|
||||
{
|
||||
if (Seek)
|
||||
if (stream.Position >= 4) stream.Seek(-4, SeekOrigin.Current);
|
||||
else stream.Seek( 0, 0);
|
||||
return stream.ReadHeader();
|
||||
}
|
||||
|
||||
public static PDHead ReadHeader(this Stream stream)
|
||||
{
|
||||
long Position = stream.LongPosition;
|
||||
PDHead Header = new PDHead
|
||||
{ Format = Main.Format.F2LE, Signature = stream.ReadInt32(),
|
||||
DataSize = stream.ReadInt32(), Lenght = stream.ReadInt32() };
|
||||
if (stream.ReadUInt32() == 0x18000000)
|
||||
{ Header.Format = Main.Format.F2BE; }
|
||||
Header.ID = stream.ReadInt32();
|
||||
Header.SectionSize = stream.ReadInt32();
|
||||
stream.IsBE = Header.Format == Main.Format.F2BE;
|
||||
stream.Format = Header.Format;
|
||||
stream.LongPosition = Position + Header.Lenght;
|
||||
Header.Signature = stream.ReadInt32Endian();
|
||||
return Header;
|
||||
}
|
||||
|
||||
public static void Write(this Stream stream, PDHead Header)
|
||||
{
|
||||
stream.Write(Header.Signature);
|
||||
stream.Write(Header.DataSize);
|
||||
stream.Write(Header.Lenght);
|
||||
if (Header.Format == Main.Format.F2BE) stream.Write(0x18000000);
|
||||
else stream.Write(0x10000000);
|
||||
stream.Write(Header.ID);
|
||||
stream.Write(Header.SectionSize);
|
||||
stream.Write(0x00);
|
||||
stream.Write(0x00);
|
||||
}
|
||||
|
||||
public static void WriteEOFC(this Stream stream, int ID)
|
||||
{ PDHead Header = new PDHead { Format = Main.Format.F2LE, ID = ID,
|
||||
Lenght = 0x20, Signature = 0x43464F45, }; stream.Write(Header); }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public class POF
|
||||
{
|
||||
public byte Type;
|
||||
public int Lenght;
|
||||
public int Offset;
|
||||
public int LastOffset;
|
||||
public List<long> Offsets;
|
||||
public List<long> POFOffsets;
|
||||
public PDHead Header;
|
||||
|
||||
public POF()
|
||||
{ Type = 0; Lenght = 0; Offset = 0; LastOffset = 0; Offsets = new List<long>();
|
||||
POFOffsets = new List<long>(); Header = new PDHead(); }
|
||||
}
|
||||
|
||||
public static class POFExtensions
|
||||
{
|
||||
public static POF AddPOF(this PDHead Header)
|
||||
{
|
||||
POF POF = new POF { Offsets = new List<long>(), POFOffsets =
|
||||
new List<long>(), Offset = Header.DataSize + Header.Lenght };
|
||||
return POF;
|
||||
}
|
||||
public static Stream GetOffset(this Stream stream, ref POF POF)
|
||||
{
|
||||
if (POF != null) if (stream.Format > Main.Format.F)
|
||||
POF.POFOffsets.Add(stream.Position - (stream.IsX ? stream.Offset : 0x00));
|
||||
return stream;
|
||||
}
|
||||
|
||||
public static void ReadPOF(this Stream stream, ref POF POF)
|
||||
{
|
||||
if (stream.ReadString(3) == "POF")
|
||||
{
|
||||
POF.POFOffsets.Sort();
|
||||
POF.Type = byte.Parse(stream.ReadString(1));
|
||||
int IsX = POF.Type + 2;
|
||||
stream.Seek(-4, SeekOrigin.Current);
|
||||
POF.Header = stream.ReadHeader();
|
||||
stream.Seek(POF.Offset + POF.Header.Lenght, 0);
|
||||
POF.Lenght = stream.ReadInt32();
|
||||
while (POF.Lenght + POF.Offset + POF.Header.Lenght > stream.Position)
|
||||
{
|
||||
int a = stream.ReadByte();
|
||||
if (a >> 6 == 0) break;
|
||||
else if (a >> 6 == 1) a = a & 0x3F;
|
||||
else if (a >> 6 == 2)
|
||||
{
|
||||
a = a & 0x3F;
|
||||
a = (a << 8) | stream.ReadByte();
|
||||
}
|
||||
else if (a >> 6 == 3)
|
||||
{
|
||||
a = a & 0x3F;
|
||||
a = (a << 8) | stream.ReadByte();
|
||||
a = (a << 8) | stream.ReadByte();
|
||||
a = (a << 8) | stream.ReadByte();
|
||||
}
|
||||
a <<= IsX;
|
||||
POF.LastOffset += a;
|
||||
POF.Offsets.Add(POF.LastOffset);
|
||||
}
|
||||
|
||||
for (int i = 0; i < POF.Offsets.Count && i < POF.POFOffsets.Count; i++)
|
||||
if (POF.Offsets[i] != POF.POFOffsets[i])
|
||||
Console.WriteLine("Not right POF{0} offset table.\n" +
|
||||
" Expected: {1}\n Got: {2}", POF.Type,
|
||||
POF.Offsets[i].ToString("X8"), POF.POFOffsets[i].ToString("X8"));
|
||||
}
|
||||
}
|
||||
|
||||
public static void Write(this Stream stream, ref POF POF, int ID)
|
||||
{
|
||||
POF.POFOffsets.Sort();
|
||||
long CurrentPOFOffset = 0;
|
||||
long POFOffset = 0;
|
||||
byte BitShift = (byte)(2 + POF.Type);
|
||||
int Max1 = (0x00FF >> BitShift) << BitShift;
|
||||
int Max2 = (0xFFFF >> BitShift) << BitShift;
|
||||
POF.Lenght = 5 + ID;
|
||||
for (int i = 0; i < POF.POFOffsets.Count; i++)
|
||||
{
|
||||
POFOffset = POF.POFOffsets[i] - CurrentPOFOffset;
|
||||
CurrentPOFOffset = POF.POFOffsets[i];
|
||||
if (POFOffset <= Max1) POF.Lenght += 1;
|
||||
else if (POFOffset <= Max2) POF.Lenght += 2;
|
||||
else POF.Lenght += 4;
|
||||
POF.POFOffsets[i] = POFOffset;
|
||||
}
|
||||
|
||||
long POFLenghtAling = POF.Lenght.Align(16);
|
||||
POF.Header = new PDHead { DataSize = (int)POFLenghtAling, ID = ID, Format = Main.Format.F2LE,
|
||||
Lenght = 0x20, SectionSize = (int)POFLenghtAling, Signature = 0x30464F50 };
|
||||
POF.Header.Signature += POF.Type << 24;
|
||||
stream.Write(POF.Header);
|
||||
|
||||
stream.Write(POF.Lenght);
|
||||
for (int i = 0; i < POF.POFOffsets.Count; i++)
|
||||
{
|
||||
POFOffset = POF.POFOffsets[i];
|
||||
if (POFOffset <= Max1) stream.Write (( byte)((1 << 6) | (POFOffset >> BitShift)));
|
||||
else if (POFOffset <= Max2) stream.WriteEndian((ushort)((2 << 14) | (POFOffset >> BitShift)), true);
|
||||
else stream.WriteEndian(( uint)((3 << 30) | (POFOffset >> BitShift)), true);
|
||||
}
|
||||
stream.Write(0x00);
|
||||
stream.Align(16, true);
|
||||
stream.WriteEOFC(ID);
|
||||
}
|
||||
|
||||
public static long ReadUInt32Endian(this Stream IO, ref POF POF) =>
|
||||
IO.GetOffset(ref POF).ReadUInt32Endian();
|
||||
public static long ReadUInt32Endian(this Stream IO, ref POF POF, bool IsBE) =>
|
||||
IO.GetOffset(ref POF).ReadUInt32Endian(IsBE);
|
||||
public static long ReadInt64(this Stream IO, ref POF POF) =>
|
||||
IO.GetOffset(ref POF).ReadInt64();
|
||||
|
||||
public static long ReadIntX(this Stream IO, ref POF POF ) =>
|
||||
IO.IsX ? IO.ReadInt64() : IO.ReadUInt32Endian( );
|
||||
public static long ReadIntX(this Stream IO, ref POF POF, bool IsBE) =>
|
||||
IO.IsX ? IO.ReadInt64() : IO.ReadUInt32Endian(IsBE);
|
||||
|
||||
public static string ReadStringAtOffset(this Stream IO, ref POF POF, long Offset = 0, long Length = 0) =>
|
||||
IO.GetOffset(ref POF).ReadStringAtOffset(Offset, Length);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,7 @@
|
||||
using System.Reflection;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("KKdMainLib")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("KKdMainLib")]
|
||||
[assembly: AssemblyCopyright("Copyright korenkonder © 2018-2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("2BA7EFC6-91D1-8BBC-C487-06C7F36CC789")]
|
||||
[assembly: AssemblyVersion("0.4.5.9")]
|
||||
[assembly: AssemblyFileVersion("0.4.5.9")]
|
||||
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.42000
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace KKdMainLib.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("KKdMainLib.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
internal static byte[] libdeflate {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("libdeflate", resourceCulture);
|
||||
return ((byte[])(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="libdeflate" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\libdeflate.dll;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
</root>
|
||||
+146
-152
@@ -1,212 +1,206 @@
|
||||
using System;
|
||||
using System.Xml.Linq;
|
||||
using System.Collections.Generic;
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.MessagePack;
|
||||
using MPIO = KKdMainLib.MessagePack.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public class STR
|
||||
public struct STR : System.IDisposable
|
||||
{
|
||||
public struct String
|
||||
{
|
||||
public int ID;
|
||||
public int StrOffset;
|
||||
public string Str;
|
||||
}
|
||||
private POF pof;
|
||||
private Header header;
|
||||
private Stream s;
|
||||
|
||||
public STR()
|
||||
{ Offset = 0; OffsetX = 0; STRs = null; POF = null; Header = new PDHead(); }
|
||||
|
||||
private long Offset;
|
||||
private long OffsetX;
|
||||
public String[] STRs;
|
||||
private POF POF;
|
||||
private PDHead Header;
|
||||
public String[] Strings;
|
||||
|
||||
public int STRReader(string filepath, string ext)
|
||||
{
|
||||
Stream reader = File.OpenReader(filepath + ext);
|
||||
s = File.OpenReader(filepath + ext);
|
||||
|
||||
Header = new PDHead();
|
||||
reader.Format = Main.Format.F;
|
||||
Header.Signature = reader.ReadInt32();
|
||||
if (Header.Signature == 0x41525453)
|
||||
header = new Header();
|
||||
s.Format = Format.F;
|
||||
uint signature = s.RU32();
|
||||
if (signature == 0x41525453)
|
||||
{
|
||||
Header = reader.ReadHeader(true);
|
||||
POF = Header.AddPOF();
|
||||
reader.Position = Header.Lenght;
|
||||
|
||||
long Count = reader.ReadInt32Endian();
|
||||
Offset = reader.ReadInt32Endian();
|
||||
|
||||
if (Offset == 0)
|
||||
{
|
||||
Offset = Count;
|
||||
OffsetX = reader.ReadInt64();
|
||||
Count = reader.ReadInt64();
|
||||
reader.Offset = Header.Lenght;
|
||||
reader.Format = Main.Format.X;
|
||||
}
|
||||
reader.LongPosition = reader.IsX ? Offset + reader.Offset : Offset;
|
||||
header = s.ReadHeader(true);
|
||||
s.IsBE = header.UseBigEndian;
|
||||
s.Format = header.Format;
|
||||
|
||||
STRs = new String[Count];
|
||||
for (int i = 0; i < Count; i++)
|
||||
int count = s.RI32E();
|
||||
int offset = s.RI32E();
|
||||
|
||||
s.P = offset;
|
||||
Strings = new String[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
STRs[i].StrOffset = reader.GetOffset(ref POF).ReadInt32Endian();
|
||||
STRs[i].ID = reader.ReadInt32Endian();
|
||||
if (reader.IsX) STRs[i].StrOffset += (int)OffsetX;
|
||||
Strings[i].Str.O = s.RI32E();
|
||||
Strings[i].ID = s.RI32E();
|
||||
}
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
reader.LongPosition = STRs[i].StrOffset + (reader.IsX ? reader.Offset : 0);
|
||||
STRs[i].Str = reader.NullTerminatedUTF8();
|
||||
}
|
||||
|
||||
reader.Position = POF.Offset;
|
||||
reader.ReadPOF(ref POF);
|
||||
s.O = 0;
|
||||
for (int i = 0; i < count; i++)
|
||||
Strings[i].Str.V = Strings[i].Str.O > 0 ?
|
||||
s.RSaO(Strings[i].Str.O) : null;
|
||||
}
|
||||
else
|
||||
{
|
||||
reader.Position -= 4;
|
||||
int Count = 0;
|
||||
for (int a = 0, i = 0; reader.Position > 0 && reader.Position < reader.Length; i++, Count++)
|
||||
{
|
||||
a = reader.ReadInt32();
|
||||
if (a == 0) break;
|
||||
}
|
||||
STRs = new String[Count];
|
||||
if ((signature >> 24) > 0) { header.Format = Format.DT; s.IsBE = true; }
|
||||
else header.Format = Format.F;
|
||||
int count = 0;
|
||||
for (uint i = signature; i != 0 && s.P >= 0 && s.P < s.L; count++)
|
||||
i = s.RU32();
|
||||
Strings = new String[count];
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
s.P = 0;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
reader.LongPosition = STRs[i].StrOffset + (reader.IsX ? reader.Offset : 0);
|
||||
STRs[i].ID = i;
|
||||
STRs[i].Str = reader.NullTerminatedUTF8();
|
||||
Strings[i].ID = i;
|
||||
Strings[i].Str.V = s.RSaO();
|
||||
}
|
||||
}
|
||||
|
||||
reader.Close();
|
||||
s.C();
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void STRWriter(string filepath)
|
||||
{
|
||||
uint Offset = 0;
|
||||
uint CurrentOffset = 0;
|
||||
Stream writer = File.OpenWriter(filepath + (Header.
|
||||
Format > Main.Format.FT ? ".str" : ".bin"), true);
|
||||
writer.Format = Header.Format;
|
||||
POF = new POF();
|
||||
writer.IsBE = writer.Format == Main.Format.F2BE;
|
||||
if (Strings == null || Strings.Length == 0 || header.Format > Format.F2) return;
|
||||
uint offset = 0;
|
||||
uint currentOffset = 0;
|
||||
Format format = header.Format;
|
||||
s = File.OpenWriter(filepath + (header.Format > Format.AFT &&
|
||||
header.Format < Format.FT ? ".str" : ".bin"), true);
|
||||
s.Format = header.Format;
|
||||
s.IsBE = header.UseBigEndian;
|
||||
pof.Offsets = KKdList<long>.New;
|
||||
|
||||
long Count = STRs.LongLength;
|
||||
if (writer.Format > Main.Format.FT)
|
||||
long count = Strings.LongLength;
|
||||
if (s.Format > Format.AFT && s.Format < Format.FT)
|
||||
{
|
||||
writer.Position = 0x40;
|
||||
writer.WriteEndian(Count);
|
||||
writer.GetOffset(ref POF).WriteEndian(0x80);
|
||||
writer.Position = 0x80;
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
writer.GetOffset(ref POF).Write(0x00);
|
||||
writer.WriteEndian(STRs[i].ID);
|
||||
}
|
||||
writer.Align(16);
|
||||
s.P = 0x40;
|
||||
s.WX(count, ref pof);
|
||||
s.WX(0x80);
|
||||
s.P = 0x80;
|
||||
for (int i = 0; i < count; i++) s.W(0x00L);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < Count; i++)
|
||||
writer.Write(0x00);
|
||||
writer.Align(32);
|
||||
}
|
||||
for (int i = 0; i < count; i++) s.W(0x00);
|
||||
s.A(0x10);
|
||||
|
||||
List<string> UsedSTR = new List<string>();
|
||||
List<int> UsedSTRPos = new List<int>();
|
||||
int[] STRPos = new int[Count];
|
||||
for (int i1 = 0; i1 < Count; i1++)
|
||||
KKdList<string> usedSTR = KKdList<string>.New;
|
||||
KKdList<int> usedSTRPos = KKdList<int>.New;
|
||||
int[] STRPos = new int[count];
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (UsedSTR.Contains(STRs[i1].Str))
|
||||
if (usedSTR.Contains(Strings[i].Str.V))
|
||||
{
|
||||
for (int i2 = 0; i2 < Count; i2++)
|
||||
if (UsedSTR[i2] == STRs[i1].Str)
|
||||
{ STRPos[i1] = UsedSTRPos[i2]; break; }
|
||||
for (int i2 = 0; i2 < count; i2++)
|
||||
if (usedSTR[i2] == Strings[i].Str.V)
|
||||
{ STRPos[i] = usedSTRPos[i2]; break; }
|
||||
}
|
||||
else
|
||||
{
|
||||
STRPos[i1] = writer.Position;
|
||||
UsedSTRPos.Add(STRPos[i1]);
|
||||
UsedSTR.Add(STRs[i1].Str);
|
||||
writer.Write(STRs[i1].Str);
|
||||
writer.WriteByte(0);
|
||||
usedSTRPos.Add(STRPos[i] = s.P);
|
||||
usedSTR.Add(Strings[i].Str.V);
|
||||
s.W(Strings[i].Str.V);
|
||||
s.W((byte)0);
|
||||
if (format < Format.F) s.A(0x8);
|
||||
}
|
||||
}
|
||||
if (writer.Format > Main.Format.FT)
|
||||
s.A(0x4);
|
||||
s.L = s.P;
|
||||
|
||||
if (s.Format > Format.AFT)
|
||||
{
|
||||
writer.Align(16);
|
||||
Offset = writer.UIntPosition;
|
||||
writer.Position = 0x80;
|
||||
s.A(0x10);
|
||||
offset = s.PU32;
|
||||
s.P = 0x80;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
pof.Offsets.Add(s.P);
|
||||
s.WE(STRPos[i]);
|
||||
s.WE(Strings[i].ID);
|
||||
}
|
||||
|
||||
s.PU32 = offset;
|
||||
s.W(pof, false, 1);
|
||||
s.WEOFC(1);
|
||||
currentOffset = s.PU32;
|
||||
s.WEOFC();
|
||||
header.DataSize = currentOffset - 0x40;
|
||||
header.Signature = 0x41525453;
|
||||
header.SectionSize = offset - 0x40;
|
||||
header.UseSectionSize = true;
|
||||
s.P = 0;
|
||||
s.W(header, true);
|
||||
}
|
||||
else
|
||||
writer.Position = 0;
|
||||
for (int i1 = 0; i1 < Count; i1++)
|
||||
{
|
||||
writer.WriteEndian(STRPos[i1]);
|
||||
if (writer.Format > Main.Format.FT) writer.Position += 4;
|
||||
s.P = 0;
|
||||
s.IsBE = header.Format < Format.F;
|
||||
for (int i = 0; i < count; i++) s.WE(STRPos[i]);
|
||||
}
|
||||
|
||||
if (writer.Format > Main.Format.FT)
|
||||
{
|
||||
writer.UIntPosition = Offset;
|
||||
writer.Write(ref POF, 1);
|
||||
CurrentOffset = writer.UIntPosition;
|
||||
writer.WriteEOFC(0);
|
||||
Header.Lenght = 0x40;
|
||||
Header.DataSize = (int)(CurrentOffset - Header.Lenght);
|
||||
Header.Signature = 0x41525453;
|
||||
Header.SectionSize = (int)(Offset - Header.Lenght);
|
||||
writer.Position = 0;
|
||||
writer.Write(Header);
|
||||
}
|
||||
writer.Close();
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool JSON)
|
||||
public void MsgPackReader(string file, bool json)
|
||||
{
|
||||
MsgPack MsgPack = file.ReadMP(JSON);
|
||||
header = default;
|
||||
Strings = default;
|
||||
MsgPack temp;
|
||||
MsgPack msgPack = file.ReadMPAllAtOnce(json);
|
||||
if ((temp = msgPack["STR"]).IsNull) return;
|
||||
|
||||
if (MsgPack.Element("STR", out MsgPack STR))
|
||||
header = new Header();
|
||||
if (!System.Enum.TryParse(temp.RS("Format"), out header.Format)) return;
|
||||
bool? isBE = temp.RnB("UseBigEndian");
|
||||
if (isBE.HasValue) header.UseBigEndian = isBE.Value;
|
||||
|
||||
if ((temp = temp["Strings", true]).IsNull) return;
|
||||
|
||||
Strings = new String[temp.Array.Length];
|
||||
for (int i = 0; i < Strings.Length; i++)
|
||||
{
|
||||
if (STR.Element("Strings", out MsgPack Strings, typeof(object[])))
|
||||
{
|
||||
STRs = new String[((object[])Strings.Object).Length];
|
||||
MsgPack String;
|
||||
for (int i = 0; i < STRs.Length; i++)
|
||||
if (Strings[i].GetType() == typeof(MsgPack))
|
||||
{
|
||||
String = (MsgPack)Strings[i];
|
||||
STRs[i].ID = String.ReadInt32 ("ID" );
|
||||
STRs[i].Str = String.ReadString("Str");
|
||||
}
|
||||
}
|
||||
Strings[i].ID = temp[i].RI32("ID" );
|
||||
Strings[i].Str.V = temp[i].RS ("Str");
|
||||
if (Strings[i].Str.V == null) Strings[i].Str.V = "";
|
||||
}
|
||||
MsgPack = null;
|
||||
|
||||
msgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool JSON)
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
MsgPack STR_ = new MsgPack("STR").Add("Format", Header.Format.ToString());
|
||||
MsgPack Strings = new MsgPack("Strings", STRs.Length);
|
||||
for (int i = 0; i < STRs.Length; i++)
|
||||
if (Strings == null || Strings.Length == 0) return;
|
||||
MsgPack str = new MsgPack("STR").Add("Format", header.Format.ToString());
|
||||
if (header.UseBigEndian) str.Add("UseBigEndian", header.UseBigEndian);
|
||||
MsgPack strings = new MsgPack(Strings.Length, "Strings");
|
||||
for (int i = 0; i < Strings.Length; i++)
|
||||
{
|
||||
Strings[i] = new MsgPack().Add("ID", STRs[i].ID);
|
||||
if (STRs[i].Str != null) if (STRs[i].Str != "")
|
||||
((MsgPack)Strings[i]).Add("S", STRs[i].Str); ;
|
||||
MsgPack @string = MsgPack.New.Add("ID", Strings[i].ID);
|
||||
if (Strings[i].Str.V != null)
|
||||
if (Strings[i].Str.V != "")
|
||||
@string.Add("Str", Strings[i].Str.V);
|
||||
strings[i] = @string;
|
||||
}
|
||||
STR_.Add(Strings);
|
||||
str.Add(strings);
|
||||
|
||||
STR_.Write(true, file, JSON);
|
||||
str.WriteAfterAll(false, true, file, json);
|
||||
}
|
||||
|
||||
private bool disposed;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; Strings = default;
|
||||
pof = default; header = default; disposed = true; } }
|
||||
|
||||
public struct String
|
||||
{
|
||||
public int ID;
|
||||
public Pointer<string> Str;
|
||||
|
||||
public override string ToString() => "ID: " + ID + (Str.V != null ||
|
||||
Str.V != "" ? ("; Str: " + Str.V) : "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,949 @@
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdBaseLib.Tables;
|
||||
using TableDict = System.Collections.Generic.Dictionary<string, object>;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public struct Tables : System.IDisposable
|
||||
{
|
||||
private int i0;
|
||||
private TableDict dict;
|
||||
private Stream s;
|
||||
|
||||
public ButtonSE[] ButtonSETable;
|
||||
public ChainSlideSE[] ChainSlideSETable;
|
||||
public SlideSE[] SlideSETable;
|
||||
public SliderTouchSE[] SliderTouchSETable;
|
||||
|
||||
public CollectionCard[] CollectionCardTable;
|
||||
public CustomizeItem[] CustomizeItemTable;
|
||||
public Module[] ModuleTable;
|
||||
public Plate[] PlateTable;
|
||||
public PV[] PVListTable;
|
||||
|
||||
private const string c = ".";
|
||||
|
||||
public void BINReader(string file) =>
|
||||
BINReader(File.ReadAllBytes(file + ".bin"));
|
||||
|
||||
public void BINReader(byte[] data)
|
||||
{
|
||||
ButtonSETable = null; ChainSlideSETable = null; SlideSETable = null; SliderTouchSETable = null;
|
||||
CollectionCardTable = null; CustomizeItemTable = null;
|
||||
ModuleTable = null; PlateTable = null; PVListTable = null;
|
||||
|
||||
dict = new TableDict();
|
||||
string[] strData = data.ToUTF8().Replace("\r\n", "\n").Replace("\r", "\n").Split('\n');
|
||||
for (i0 = 0; i0 < strData.Length; i0++)
|
||||
dict.GD(strData[i0]);
|
||||
strData = null;
|
||||
|
||||
int length;
|
||||
string name;
|
||||
if (dict.FV(out length, "btn_se.data_list.length"))
|
||||
{
|
||||
ButtonSETable = new ButtonSE[length];
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "btn_se" + c + i0 + c;
|
||||
|
||||
ref ButtonSE btn = ref ButtonSETable[i0];
|
||||
dict.FV(out btn. ID , name + "id" );
|
||||
dict.FV(out btn. Name , name + "name" );
|
||||
dict.FV(out btn. SEName , name + "se_name" );
|
||||
dict.FV(out btn.SortIndex, name + "sort_index");
|
||||
|
||||
btn.Start = GetStartTableDate(dict, name);
|
||||
btn.End = GetEndTableDate(dict, name);
|
||||
}
|
||||
}
|
||||
else if (dict.FV(out length, "chainslide_se.data_list.length"))
|
||||
{
|
||||
ChainSlideSETable = new ChainSlideSE[length];
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "chainslide_se" + c + i0 + c;
|
||||
|
||||
ref ChainSlideSE csld = ref ChainSlideSETable[i0];
|
||||
dict.FV(out csld. ID , name + "id" );
|
||||
dict.FV(out csld. Name , name + "name" );
|
||||
dict.FV(out csld. FirstSEName , name + "first_se_name" );
|
||||
dict.FV(out csld.FailureSEName , name + "failure_se_name" );
|
||||
dict.FV(out csld. SortIndex, name + "sort_index");
|
||||
dict.FV(out csld. SubSEName , name + "sub_se_name" );
|
||||
dict.FV(out csld.SuccessSEName , name + "success_se_name" );
|
||||
|
||||
csld.Start = GetStartTableDate(dict, name);
|
||||
csld.End = GetEndTableDate(dict, name);
|
||||
}
|
||||
}
|
||||
else if (dict.FV(out length, "collection_card.data_list.length"))
|
||||
{
|
||||
CollectionCardTable = new CollectionCard[length];
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "collection_card" + c + i0 + c;
|
||||
|
||||
ref CollectionCard clcrd = ref CollectionCardTable[i0];
|
||||
dict.FV(out clcrd.Chara , name + "chara" );
|
||||
dict.FV(out clcrd.DispNum , name + "disp_num" );
|
||||
dict.FV(out clcrd.DivaProParam, name + "divapro_param");
|
||||
dict.FV(out clcrd.ID , name + "id" );
|
||||
dict.FV(out clcrd.ModuleAuthor, name + "module_author");
|
||||
dict.FV(out clcrd.Name , name + "name" );
|
||||
dict.FV(out clcrd.NameReading , name + "name_reading" );
|
||||
dict.FV(out clcrd.NG , name + "ng" );
|
||||
dict.FV(out clcrd.SortIndex , name + "sort_idx" );
|
||||
dict.FV(out clcrd.Type , name + "type" );
|
||||
dict.FV(out clcrd.TypeParam , name + "type_param" );
|
||||
dict.FV(out clcrd.WallParam , name + "wall_param" );
|
||||
|
||||
clcrd.Start = GetStartTableDate(dict, name);
|
||||
clcrd.End = GetEndTableDate(dict, name);
|
||||
}
|
||||
}
|
||||
else if (dict.FV(out length, "cstm_item.data_list.length"))
|
||||
{
|
||||
CustomizeItemTable = new CustomizeItem[length];
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "cstm_item" + c + i0 + c;
|
||||
|
||||
ref CustomizeItem czitm = ref CustomizeItemTable[i0];
|
||||
dict.FV(out czitm.Chara , name + "chara" );
|
||||
dict.FV(out czitm.ID , name + "id" );
|
||||
dict.FV(out czitm.Name , name + "name" );
|
||||
dict.FV(out czitm.NG , name + "ng" );
|
||||
dict.FV(out czitm.ObjID , name + "obj_id" );
|
||||
dict.FV(out czitm.Parts , name + "parts" );
|
||||
dict.FV(out czitm.SellType , name + "sell_type" );
|
||||
dict.FV(out czitm.ShopPrice, name + "shop_price");
|
||||
dict.FV(out czitm.SortIndex, name + "sort_index");
|
||||
|
||||
czitm.ShopStart = GetStartTableDate(dict, name + "shop_");
|
||||
czitm.ShopEnd = GetEndTableDate(dict, name + "shop_");
|
||||
}
|
||||
}
|
||||
else if (dict.FV(out length, "module.data_list.length"))
|
||||
{
|
||||
ModuleTable = new Module[length];
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "module" + c + i0 + c;
|
||||
|
||||
ref Module mdl = ref ModuleTable[i0];
|
||||
dict.FV(out mdl.Attribute, name + "attr" );
|
||||
dict.FV(out mdl.Chara , name + "chara" );
|
||||
dict.FV(out mdl.Costume , name + "cos" );
|
||||
dict.FV(out mdl.ID , name + "id" );
|
||||
dict.FV(out mdl.Name , name + "name" );
|
||||
dict.FV(out mdl.NG , name + "ng" );
|
||||
dict.FV(out mdl.ShopPrice, name + "shop_price");
|
||||
dict.FV(out mdl.SortIndex, name + "sort_index");
|
||||
|
||||
mdl.ShopStart = GetStartTableDate(dict, name + "shop_");
|
||||
mdl.ShopEnd = GetEndTableDate(dict, name + "shop_");
|
||||
}
|
||||
}
|
||||
else if (dict.FV(out length, "plate.data_list.length"))
|
||||
{
|
||||
PlateTable = new Plate[length];
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "plate" + c + i0 + c;
|
||||
|
||||
ref Plate plt = ref PlateTable[i0];
|
||||
dict.FV(out plt.Alpha , name + "alpha" );
|
||||
dict.FV(out plt.BaseID , name + "base_id" );
|
||||
dict.FV(out plt.Border , name + "border" );
|
||||
dict.FV(out plt.ColorB , name + "color_b" );
|
||||
dict.FV(out plt.ColorG , name + "color_g" );
|
||||
dict.FV(out plt.ColorR , name + "color_r" );
|
||||
dict.FV(out plt.Font , name + "font" );
|
||||
dict.FV(out plt.ID , name + "id" );
|
||||
dict.FV(out plt.Shadow , name + "shadow" );
|
||||
dict.FV(out plt.ShadowAlpha , name + "shadow_alpha" );
|
||||
dict.FV(out plt.ShadowColorB, name + "shadow_color_b");
|
||||
dict.FV(out plt.ShadowColorG, name + "shadow_color_g");
|
||||
dict.FV(out plt.ShadowColorR, name + "shadow_color_r");
|
||||
}
|
||||
}
|
||||
else if (dict.FV(out length, "pv_list.data_list.length"))
|
||||
{
|
||||
PVListTable = new PV[length];
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "pv_list" + c + i0 + c;
|
||||
|
||||
ref PV pv = ref PVListTable[i0];
|
||||
dict.FV(out pv.ID , name + "id" );
|
||||
dict.FV(out pv.Ignore, name + "ignore");
|
||||
dict.FV(out pv.Name , name + "name" );
|
||||
|
||||
pv.AdvStart = GetStartTableDate(dict, name + "adv_demo_");
|
||||
pv.AdvEnd = GetEndTableDate(dict, name + "adv_demo_");
|
||||
|
||||
pv.Easy = GetDifficulty(dict, name + "easy" + c);
|
||||
pv.Encore = GetDifficulty(dict, name + "encore" + c);
|
||||
pv.Extreme = GetDifficulty(dict, name + "extreme" + c);
|
||||
pv.Hard = GetDifficulty(dict, name + "hard" + c);
|
||||
pv.Normal = GetDifficulty(dict, name + "normal" + c);
|
||||
}
|
||||
|
||||
static PV.Difficulty[] GetDifficulty(TableDict dict, string name)
|
||||
{
|
||||
int len, val;
|
||||
if (!dict.FV(out len, name + "length") || len < 0) return null;
|
||||
|
||||
PV.Difficulty[] arr = new PV.Difficulty[len];
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (dict.FV(out val, $"{name}{i}.edition")) arr[i].Edition = val;
|
||||
if (dict.FV(out val, $"{name}{i}.ver" )) arr[i].Version = val;
|
||||
|
||||
arr[i].Start = GetStartTableDate(dict, $"{name}{i}.");
|
||||
arr[i].End = GetEndTableDate(dict, $"{name}{i}.");
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
else if (dict.FV(out length, "slide_se.data_list.length"))
|
||||
{
|
||||
SlideSETable = new SlideSE[length];
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "slide_se" + c + i0 + c;
|
||||
|
||||
ref SlideSE sld = ref SlideSETable[i0];
|
||||
dict.FV(out sld. ID , name + "id" );
|
||||
dict.FV(out sld. Name , name + "name" );
|
||||
dict.FV(out sld. SEName , name + "se_name" );
|
||||
dict.FV(out sld.SortIndex, name + "sort_index");
|
||||
|
||||
sld.Start = GetStartTableDate(dict, name);
|
||||
sld.End = GetEndTableDate(dict, name);
|
||||
}
|
||||
}
|
||||
else if (dict.FV(out length, "slidertouch_se.data_list.length"))
|
||||
{
|
||||
SliderTouchSETable = new SliderTouchSE[length];
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "slidertouch_se" + c + i0 + c;
|
||||
|
||||
ref SliderTouchSE stld = ref SliderTouchSETable[i0];
|
||||
dict.FV(out stld. ID , name + "id" );
|
||||
dict.FV(out stld. Name , name + "name" );
|
||||
dict.FV(out stld. SEName , name + "se_name" );
|
||||
dict.FV(out stld.SortIndex, name + "sort_index");
|
||||
|
||||
stld.Start = GetStartTableDate(dict, name);
|
||||
stld.End = GetEndTableDate(dict, name);
|
||||
}
|
||||
}
|
||||
|
||||
static TableDate GetStartTableDate(TableDict dict, string name)
|
||||
{
|
||||
TableDate date = default; date.SDL(); int val;
|
||||
if (dict.FV(out val, name + "st_year" )) date.Year = val;
|
||||
if (dict.FV(out val, name + "st_month")) date.Month = val;
|
||||
if (dict.FV(out val, name + "st_day" )) date.Day = val;
|
||||
return date;
|
||||
}
|
||||
|
||||
static TableDate GetEndTableDate(TableDict dict, string name)
|
||||
{
|
||||
TableDate date = default; date.SDU(); int val;
|
||||
if (dict.FV(out val, name + "ed_year" )) date.Year = val;
|
||||
if (dict.FV(out val, name + "ed_month")) date.Month = val;
|
||||
if (dict.FV(out val, name + "ed_day" )) date.Day = val;
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
||||
public void BINWriter(string file)
|
||||
{
|
||||
int[] so;
|
||||
int length;
|
||||
string name;
|
||||
|
||||
if (ButtonSETable != null)
|
||||
{
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
length = ButtonSETable.Length;
|
||||
so = length.SW();
|
||||
WriteEmptyLines(s, length);
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "btn_se" + c + so[i0] + c;
|
||||
|
||||
ref ButtonSE btn = ref ButtonSETable[so[i0]];
|
||||
WriteEndTableDate(s, name, btn.End);
|
||||
W(name + "id" , btn. ID );
|
||||
W(name + "name" , btn. Name );
|
||||
W(name + "se_name" , btn. SEName );
|
||||
W(name + "sort_index", btn.SortIndex);
|
||||
WriteStartTableDate(s, name, btn.Start);
|
||||
}
|
||||
W("btn_se.data_list.length", length);
|
||||
s.W("kind=0\n");
|
||||
s.D();
|
||||
}
|
||||
else if (ChainSlideSETable != null)
|
||||
{
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
length = ChainSlideSETable.Length;
|
||||
so = length.SW();
|
||||
WriteEmptyLines(s, length);
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "chainslide_se" + c + so[i0] + c;
|
||||
|
||||
ref ChainSlideSE csld = ref ChainSlideSETable[so[i0]];
|
||||
WriteEndTableDate(s, name, csld.End);
|
||||
W(name + "failure_se_name" , csld.FailureSEName );
|
||||
W(name + "first_se_name" , csld. FirstSEName );
|
||||
W(name + "id" , csld. ID );
|
||||
W(name + "name" , csld. Name );
|
||||
W(name + "sort_index", csld. SortIndex);
|
||||
WriteStartTableDate(s, name, csld.Start);
|
||||
W(name + "sub_se_name" , csld. SubSEName );
|
||||
W(name + "success_se_name" , csld.SuccessSEName );
|
||||
}
|
||||
W("chainslide_se.data_list.length", length);
|
||||
s.W("kind=2\n");
|
||||
s.D();
|
||||
}
|
||||
else if (CollectionCardTable != null)
|
||||
{
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
length = CollectionCardTable.Length;
|
||||
so = length.SW();
|
||||
WriteEmptyLines(s, length);
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "collection_card" + c + so[i0] + c;
|
||||
|
||||
ref CollectionCard clcrd = ref CollectionCardTable[so[i0]];
|
||||
W(name + "chara" , clcrd.Chara );
|
||||
W(name + "disp_num" , clcrd.DispNum );
|
||||
W(name + "divapro_param", clcrd.DivaProParam);
|
||||
WriteEndTableDate(s, name, clcrd.End);
|
||||
W(name + "id" , clcrd.ID );
|
||||
W(name + "module_author", clcrd.ModuleAuthor);
|
||||
W(name + "name" , clcrd.Name );
|
||||
W(name + "name_reading" , clcrd.NameReading );
|
||||
W(name + "ng" , clcrd.NG );
|
||||
W(name + "sort_idx" , clcrd.SortIndex );
|
||||
WriteStartTableDate(s, name, clcrd.Start);
|
||||
W(name + "type" , clcrd.Type );
|
||||
W(name + "type_param" , clcrd.TypeParam );
|
||||
W(name + "wall_param" , clcrd.WallParam );
|
||||
}
|
||||
W("collection_card.data_list.length", length);
|
||||
s.W("patch=0\n");
|
||||
s.W("version=0\n");
|
||||
s.D();
|
||||
}
|
||||
else if (CustomizeItemTable != null)
|
||||
{
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
length = CustomizeItemTable.Length;
|
||||
so = length.SW();
|
||||
WriteEmptyLines(s, length);
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "cstm_item" + c + so[i0] + c;
|
||||
|
||||
ref CustomizeItem czitm = ref CustomizeItemTable[so[i0]];
|
||||
W(name + "chara" , czitm.Chara );
|
||||
W(name + "id" , czitm.ID );
|
||||
W(name + "name" , czitm.Name );
|
||||
W(name + "ng" , czitm.NG );
|
||||
W(name + "obj_id" , czitm.ObjID );
|
||||
W(name + "parts" , czitm.Parts );
|
||||
W(name + "sell_type" , czitm.SellType );
|
||||
WriteEndTableDate(s, name + "shop_", czitm.ShopEnd);
|
||||
W(name + "shop_price", czitm.ShopPrice);
|
||||
WriteStartTableDate(s, name + "shop_", czitm.ShopStart);
|
||||
W(name + "sort_index", czitm.SortIndex);
|
||||
}
|
||||
W("cstm_item.data_list.length", length);
|
||||
s.W("patch=0\n");
|
||||
s.W("version=0\n");
|
||||
s.D();
|
||||
}
|
||||
else if (ModuleTable != null)
|
||||
{
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
length = ModuleTable.Length;
|
||||
so = length.SW();
|
||||
WriteEmptyLines(s, length);
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "module" + c + so[i0] + c;
|
||||
|
||||
ref Module mdl = ref ModuleTable[so[i0]];
|
||||
W(name + "attr" , mdl.Attribute);
|
||||
W(name + "chara" , mdl.Chara );
|
||||
W(name + "cos" , mdl.Costume );
|
||||
W(name + "id" , mdl.ID );
|
||||
W(name + "name" , mdl.Name );
|
||||
W(name + "ng" , mdl.NG );
|
||||
WriteEndTableDate(s, name + "shop_", mdl.ShopEnd);
|
||||
W(name + "shop_price", mdl.ShopPrice);
|
||||
WriteStartTableDate(s, name + "shop_", mdl.ShopStart);
|
||||
W(name + "sort_index", mdl.SortIndex);
|
||||
}
|
||||
W("module.data_list.length", length);
|
||||
s.D();
|
||||
}
|
||||
else if (PlateTable != null)
|
||||
{
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
length = PlateTable.Length;
|
||||
so = length.SW();
|
||||
WriteEmptyLines(s, length);
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "plate" + c + so[i0] + c;
|
||||
|
||||
ref Plate plt = ref PlateTable[so[i0]];
|
||||
W(name + "alpha" , plt.Alpha );
|
||||
W(name + "base_id" , plt.BaseID );
|
||||
W(name + "border" , plt.Border );
|
||||
W(name + "color_b" , plt.ColorB );
|
||||
W(name + "color_g" , plt.ColorG );
|
||||
W(name + "color_r" , plt.ColorR );
|
||||
W(name + "font" , plt.Font );
|
||||
W(name + "id" , plt.ID );
|
||||
W(name + "shadow" , plt.Shadow );
|
||||
W(name + "shadow_alpha" , plt.ShadowAlpha );
|
||||
W(name + "shadow_color_b", plt.ShadowColorB);
|
||||
W(name + "shadow_color_g", plt.ShadowColorG);
|
||||
W(name + "shadow_color_r", plt.ShadowColorR);
|
||||
}
|
||||
W("plate.data_list.length", length);
|
||||
s.D();
|
||||
}
|
||||
else if (PVListTable != null)
|
||||
{
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
length = PVListTable.Length;
|
||||
so = length.SW();
|
||||
WriteEmptyLines(s, length);
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "pv_list" + c + so[i0] + c;
|
||||
|
||||
ref PV pv = ref PVListTable[so[i0]];
|
||||
WriteEndTableDate(s, name + "adv_demo_", pv.AdvEnd );
|
||||
WriteStartTableDate(s, name + "adv_demo_", pv.AdvStart);
|
||||
|
||||
WriteDifficulty(s, name + "easy.", pv.Easy );
|
||||
WriteDifficulty(s, name + "encore.", pv.Encore );
|
||||
WriteDifficulty(s, name + "extreme.", pv.Extreme);
|
||||
WriteDifficulty(s, name + "hard.", pv.Hard );
|
||||
W(name + "id" , pv.ID );
|
||||
W(name + "ignore", pv.Ignore);
|
||||
W(name + "name" , pv.Name );
|
||||
WriteDifficulty(s, name + "normal.", pv.Normal );
|
||||
}
|
||||
W("pv_list.data_list.length", length);
|
||||
s.D();
|
||||
|
||||
static void WriteDifficulty(Stream _IO, string name, PV.Difficulty[] arr)
|
||||
{
|
||||
if (arr == null) { _IO.W($"{name}length=0\n"); return; }
|
||||
|
||||
int length = arr.Length;
|
||||
int[] so = length.SW();
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
ref PV.Difficulty diff = ref arr[so[i]];
|
||||
|
||||
WriteEndTableDate(_IO, $"{name}{i}.", diff.End );
|
||||
_IO.W($"{name}{i}.edition" + $"={diff.Edition}\n");
|
||||
WriteStartTableDate(_IO, $"{name}{i}.", diff.Start);
|
||||
_IO.W($"{name}{i}.ver" + $"={diff.Version}\n");
|
||||
}
|
||||
_IO.W($"{name}length={length}\n");
|
||||
}
|
||||
}
|
||||
else if (SlideSETable != null)
|
||||
{
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
length = SlideSETable.Length;
|
||||
so = length.SW();
|
||||
WriteEmptyLines(s, length);
|
||||
s.W("kind=1\n");
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "slide_se" + c + so[i0] + c;
|
||||
|
||||
ref SlideSE sld = ref SlideSETable[so[i0]];
|
||||
WriteEndTableDate(s, name, sld.End);
|
||||
W(name + "id" , sld. ID );
|
||||
W(name + "name" , sld. Name );
|
||||
W(name + "se_name" , sld. SEName );
|
||||
W(name + "sort_index", sld.SortIndex);
|
||||
WriteStartTableDate(s, name, sld.Start);
|
||||
}
|
||||
W("slide_se.data_list.length", length);
|
||||
s.D();
|
||||
}
|
||||
else if (SliderTouchSETable != null)
|
||||
{
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
length = SliderTouchSETable.Length;
|
||||
so = length.SW();
|
||||
WriteEmptyLines(s, length);
|
||||
s.W("kind=3\n");
|
||||
for (i0 = 0; i0 < length; i0++)
|
||||
{
|
||||
name = "slidertouch_se" + c + so[i0] + c;
|
||||
|
||||
ref SliderTouchSE sldt = ref SliderTouchSETable[so[i0]];
|
||||
WriteEndTableDate(s, name, sldt.End);
|
||||
W(name + "id" , sldt. ID );
|
||||
W(name + "name" , sldt. Name );
|
||||
W(name + "se_name" , sldt. SEName );
|
||||
W(name + "sort_index", sldt.SortIndex);
|
||||
WriteStartTableDate(s, name, sldt.Start);
|
||||
}
|
||||
W("slidertouch_se.data_list.length", length);
|
||||
s.D();
|
||||
}
|
||||
|
||||
static void WriteEmptyLines(Stream _IO, int count)
|
||||
{ for (int i = 0; i < count; i++) _IO.W("#---------------------------------------------\n"); }
|
||||
|
||||
static void WriteStartTableDate(Stream _IO, string name, TableDate date)
|
||||
{
|
||||
_IO.W(name + "st_day" + "=" + date.Day + "\n");
|
||||
_IO.W(name + "st_month" + "=" + date.Month + "\n");
|
||||
_IO.W(name + "st_year" + "=" + date.Year + "\n");
|
||||
}
|
||||
|
||||
static void WriteEndTableDate(Stream _IO, string name, TableDate date)
|
||||
{
|
||||
_IO.W(name + "ed_day" + "=" + date.Day + "\n");
|
||||
_IO.W(name + "ed_month" + "=" + date.Month + "\n");
|
||||
_IO.W(name + "ed_year" + "=" + date.Year + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
private void W(string Data, long val) =>
|
||||
s.W(Data + "=" + val + "\n");
|
||||
private void W(string Data, string val)
|
||||
{ if (val != null) s.W(Data + "=" + val + "\n"); }
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
{
|
||||
ButtonSETable = null; ChainSlideSETable = null; SlideSETable = null; SliderTouchSETable = null;
|
||||
CollectionCardTable = null; CustomizeItemTable = null;
|
||||
ModuleTable = null; PlateTable = null; PVListTable = null;
|
||||
|
||||
MsgPack msgPack = file.ReadMPAllAtOnce(json);
|
||||
MsgPack temp;
|
||||
if ((temp = msgPack["ButtonSETable", true]).NotNull)
|
||||
{
|
||||
ButtonSETable = new ButtonSE[temp.Array.Length];
|
||||
for (i0 = 0; i0 < ButtonSETable.Length; i0++)
|
||||
{
|
||||
MsgPack btnMP = temp[i0];
|
||||
ref ButtonSE btn = ref ButtonSETable[i0];
|
||||
btn.End .SV(btnMP.RnI32("End" ), true);
|
||||
btn.Start.SV(btnMP.RnI32("Start"), false);
|
||||
|
||||
btnMP.R( "ID" , out btn. ID );
|
||||
btnMP.R( "Name" , out btn. Name );
|
||||
btnMP.R( "SEName" , out btn. SEName );
|
||||
btnMP.R("SortIndex", out btn.SortIndex);
|
||||
}
|
||||
}
|
||||
else if ((temp = msgPack["ChainSlideSETable", true]).NotNull)
|
||||
{
|
||||
ChainSlideSETable = new ChainSlideSE[temp.Array.Length];
|
||||
for (i0 = 0; i0 < ChainSlideSETable.Length; i0++)
|
||||
{
|
||||
MsgPack csldMP = temp[i0];
|
||||
ref ChainSlideSE csld = ref ChainSlideSETable[i0];
|
||||
csld.End .SV(csldMP.RnI32("End" ), true);
|
||||
csld.Start.SV(csldMP.RnI32("Start"), false);
|
||||
|
||||
csldMP.R("FailureSEName" , out csld.FailureSEName );
|
||||
csldMP.R( "FirstSEName" , out csld. FirstSEName );
|
||||
csldMP.R( "ID" , out csld. ID );
|
||||
csldMP.R( "Name" , out csld. Name );
|
||||
csldMP.R( "SortIndex", out csld. SortIndex);
|
||||
csldMP.R( "SubSEName" , out csld. SubSEName );
|
||||
csldMP.R("SuccessSEName" , out csld.SuccessSEName );
|
||||
}
|
||||
}
|
||||
else if ((temp = msgPack["CollectionCardTable", true]).NotNull)
|
||||
{
|
||||
CollectionCardTable = new CollectionCard[temp.Array.Length];
|
||||
for (i0 = 0; i0 < CollectionCardTable.Length; i0++)
|
||||
{
|
||||
MsgPack clcrdMP = temp[i0];
|
||||
ref CollectionCard clcrd = ref CollectionCardTable[i0];
|
||||
clcrd.End .SV(clcrdMP.RnI32("End" ), true);
|
||||
clcrd.Start.SV(clcrdMP.RnI32("Start"), false);
|
||||
|
||||
clcrdMP.R("Chara" , out clcrd.Chara );
|
||||
clcrdMP.R("DispNum" , out clcrd.DispNum );
|
||||
clcrdMP.R("DivaProParam", out clcrd.DivaProParam);
|
||||
clcrdMP.R("ID" , out clcrd.ID );
|
||||
clcrdMP.R("ModuleAuthor", out clcrd.ModuleAuthor);
|
||||
clcrdMP.R("Name" , out clcrd.Name );
|
||||
clcrdMP.R("NameReading" , out clcrd.NameReading );
|
||||
clcrdMP.R("NG" , out clcrd.NG );
|
||||
clcrdMP.R("SortIndex" , out clcrd.SortIndex );
|
||||
clcrdMP.R("Type" , out clcrd.Type );
|
||||
clcrdMP.R("TypeParam" , out clcrd.TypeParam );
|
||||
clcrdMP.R("WallParam" , out clcrd.WallParam );
|
||||
}
|
||||
}
|
||||
else if ((temp = msgPack["CustomizeItemTable", true]).NotNull)
|
||||
{
|
||||
CustomizeItemTable = new CustomizeItem[temp.Array.Length];
|
||||
for (i0 = 0; i0 < CustomizeItemTable.Length; i0++)
|
||||
{
|
||||
MsgPack czitmMP = temp[i0];
|
||||
ref CustomizeItem czitm = ref CustomizeItemTable[i0];
|
||||
czitm.ShopEnd .SV(czitmMP.RnI32("ShopEnd" ), true);
|
||||
czitm.ShopStart.SV(czitmMP.RnI32("ShopStart"), false);
|
||||
|
||||
czitmMP.R("Chara" , out czitm.Chara );
|
||||
czitmMP.R("ID" , out czitm.ID );
|
||||
czitmMP.R("Name" , out czitm.Name );
|
||||
czitmMP.R("NG" , out czitm.NG );
|
||||
czitmMP.R("ObjID" , out czitm.ObjID );
|
||||
czitmMP.R("Parts" , out czitm.Parts );
|
||||
czitmMP.R("SellType" , out czitm.SellType );
|
||||
czitmMP.R("ShopPrice", out czitm.ShopPrice);
|
||||
czitmMP.R("SortIndex", out czitm.SortIndex);
|
||||
}
|
||||
}
|
||||
else if ((temp = msgPack["ModuleTable", true]).NotNull)
|
||||
{
|
||||
ModuleTable = new Module[temp.Array.Length];
|
||||
for (i0 = 0; i0 < ModuleTable.Length; i0++)
|
||||
{
|
||||
MsgPack mdlMP = temp[i0];
|
||||
ref Module mdl = ref ModuleTable[i0];
|
||||
mdl.ShopEnd .SV(mdlMP.RnI32("ShopEnd" ), true);
|
||||
mdl.ShopStart.SV(mdlMP.RnI32("ShopStart"), false);
|
||||
|
||||
mdlMP.R("Attribute", out mdl.Attribute);
|
||||
mdlMP.R("Costume" , out mdl.Costume );
|
||||
mdlMP.R("Chara" , out mdl.Chara );
|
||||
mdlMP.R("ID" , out mdl.ID );
|
||||
mdlMP.R("Name" , out mdl.Name );
|
||||
mdlMP.R("NG" , out mdl.NG );
|
||||
mdlMP.R("ShopPrice", out mdl.ShopPrice);
|
||||
mdlMP.R("SortIndex", out mdl.SortIndex);
|
||||
}
|
||||
}
|
||||
else if ((temp = msgPack["PlateTable", true]).NotNull)
|
||||
{
|
||||
PlateTable = new Plate[temp.Array.Length];
|
||||
for (i0 = 0; i0 < PlateTable.Length; i0++)
|
||||
{
|
||||
MsgPack pltMP = temp[i0];
|
||||
ref Plate plt = ref PlateTable[i0];
|
||||
pltMP.R("Alpha" , out plt.Alpha );
|
||||
pltMP.R("BaseID" , out plt.BaseID );
|
||||
pltMP.R("Border" , out plt.Border );
|
||||
pltMP.R("ColorB" , out plt.ColorB );
|
||||
pltMP.R("ColorG" , out plt.ColorG );
|
||||
pltMP.R("ColorR" , out plt.ColorR );
|
||||
pltMP.R("Font" , out plt.Font );
|
||||
pltMP.R("ID" , out plt.ID );
|
||||
pltMP.R("Shadow" , out plt.Shadow );
|
||||
pltMP.R("ShadowAlpha" , out plt.ShadowAlpha );
|
||||
pltMP.R("ShadowColorB", out plt.ShadowColorB);
|
||||
pltMP.R("ShadowColorG", out plt.ShadowColorG);
|
||||
pltMP.R("ShadowColorR", out plt.ShadowColorR);
|
||||
}
|
||||
}
|
||||
else if ((temp = msgPack["PVList", true]).NotNull)
|
||||
{
|
||||
PVListTable = new PV[temp.Array.Length];
|
||||
for (i0 = 0; i0 < PVListTable.Length; i0++)
|
||||
{
|
||||
MsgPack pvMP = temp[i0];
|
||||
ref PV pv = ref PVListTable[i0];
|
||||
pv.AdvEnd .SV(pvMP.RnI32("AdvEnd" ), true);
|
||||
pv.AdvStart.SV(pvMP.RnI32("AdvStart"), false);
|
||||
|
||||
pvMP.R("ID" , out pv.ID );
|
||||
pvMP.R("Ignore", out pv.Ignore);
|
||||
pvMP.R("Name" , out pv.Name );
|
||||
|
||||
pv.Easy = GetDifficulty(pvMP, "Easy" );
|
||||
pv.Normal = GetDifficulty(pvMP, "Normal" );
|
||||
pv.Hard = GetDifficulty(pvMP, "Hard" );
|
||||
pv.Extreme = GetDifficulty(pvMP, "Extreme");
|
||||
pv.Encore = GetDifficulty(pvMP, "Encore" );
|
||||
}
|
||||
|
||||
static PV.Difficulty[] GetDifficulty(MsgPack mp, string name)
|
||||
{
|
||||
MsgPack t;
|
||||
if ((t = mp[name, true]).IsNull) return null;
|
||||
|
||||
PV.Difficulty[] arr = new PV.Difficulty[t.Array.Length];
|
||||
for (int i = 0; i < arr.Length; i++)
|
||||
{
|
||||
MsgPack pvMP = t[i];
|
||||
ref PV.Difficulty diff = ref arr[i];
|
||||
diff.End .SV(pvMP.RnI32("End" ), true);
|
||||
diff.Start.SV(pvMP.RnI32("Start"), false);
|
||||
|
||||
pvMP.R("Edition", out diff.Edition);
|
||||
pvMP.R("Version", out diff.Version);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
else if ((temp = msgPack["SlideSETable", true]).NotNull)
|
||||
{
|
||||
SlideSETable = new SlideSE[temp.Array.Length];
|
||||
for (i0 = 0; i0 < SlideSETable.Length; i0++)
|
||||
{
|
||||
MsgPack sldMP = temp[i0];
|
||||
ref SlideSE sld = ref SlideSETable[i0];
|
||||
sld.End .SV(sldMP.RnI32("End" ), true);
|
||||
sld.Start.SV(sldMP.RnI32("Start"), false);
|
||||
|
||||
sldMP.R( "ID" , out sld. ID );
|
||||
sldMP.R( "Name" , out sld. Name );
|
||||
sldMP.R( "SEName" , out sld. SEName );
|
||||
sldMP.R("SortIndex", out sld.SortIndex);
|
||||
}
|
||||
}
|
||||
else if ((temp = msgPack["SliderTouchSETable", true]).NotNull)
|
||||
{
|
||||
SliderTouchSETable = new SliderTouchSE[temp.Array.Length];
|
||||
for (i0 = 0; i0 < SliderTouchSETable.Length; i0++)
|
||||
{
|
||||
MsgPack TEMP = temp[i0];
|
||||
ref SliderTouchSE sldt = ref SliderTouchSETable[i0];
|
||||
sldt.End .SV(TEMP.RnI32("End" ), true);
|
||||
sldt.Start.SV(TEMP.RnI32("Start"), false);
|
||||
|
||||
TEMP.R( "ID" , out sldt. ID );
|
||||
TEMP.R( "Name" , out sldt. Name );
|
||||
TEMP.R( "SEName" , out sldt. SEName );
|
||||
TEMP.R("SortIndex", out sldt.SortIndex);
|
||||
}
|
||||
}
|
||||
temp.Dispose();
|
||||
msgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
MsgPack msgPack = MsgPack.New;
|
||||
if (ButtonSETable != null)
|
||||
{
|
||||
MsgPack buttonSETable = new MsgPack(ButtonSETable.Length, "ButtonSETable");
|
||||
for (i0 = 0; i0 < ButtonSETable.Length; i0++)
|
||||
{
|
||||
ref ButtonSE btn = ref ButtonSETable[i0];
|
||||
buttonSETable[i0] = MsgPack.New.Add( "End" , btn.End.Int )
|
||||
.Add( "ID" , btn. ID )
|
||||
.Add( "Name" , btn. Name )
|
||||
.Add( "SEName" , btn. SEName )
|
||||
.Add("SortIndex", btn.SortIndex)
|
||||
.Add( "Start", btn.Start.Int);
|
||||
}
|
||||
msgPack.Add(buttonSETable);
|
||||
}
|
||||
else if (ChainSlideSETable != null)
|
||||
{
|
||||
MsgPack chainSlideSETable = new MsgPack(ChainSlideSETable.Length, "ChainSlideSETable");
|
||||
for (i0 = 0; i0 < ChainSlideSETable.Length; i0++)
|
||||
{
|
||||
ref ChainSlideSE csld = ref ChainSlideSETable[i0];
|
||||
chainSlideSETable[i0] = MsgPack.New.Add( "End" , csld. End.Int )
|
||||
.Add("FailureSEName" , csld.FailureSEName )
|
||||
.Add( "FirstSEName" , csld. FirstSEName )
|
||||
.Add( "ID" , csld. ID )
|
||||
.Add( "Name" , csld. Name )
|
||||
.Add( "SubSEName" , csld. SubSEName )
|
||||
.Add("SuccessSEName" , csld.SuccessSEName )
|
||||
.Add( "SortIndex", csld. SortIndex)
|
||||
.Add( "Start", csld. Start.Int);
|
||||
}
|
||||
msgPack.Add(chainSlideSETable);
|
||||
}
|
||||
else if (CollectionCardTable != null)
|
||||
{
|
||||
MsgPack collectionCardTable = new MsgPack(CollectionCardTable.Length, "CollectionCardTable");
|
||||
for (i0 = 0; i0 < CollectionCardTable.Length; i0++)
|
||||
{
|
||||
ref CollectionCard clcrd = ref CollectionCardTable[i0];
|
||||
collectionCardTable[i0] = MsgPack.New.Add("Chara" , clcrd.Chara )
|
||||
.Add("DispNum" , clcrd.DispNum )
|
||||
.Add("DivaProParam", clcrd.DivaProParam)
|
||||
.Add("End" , clcrd.End.Int )
|
||||
.Add("ID" , clcrd.ID )
|
||||
.Add("ModuleAuthor", clcrd.ModuleAuthor)
|
||||
.Add("Name" , clcrd.Name )
|
||||
.Add("NameReading" , clcrd.NameReading )
|
||||
.Add("NG" , clcrd.NG )
|
||||
.Add("SortIndex" , clcrd.SortIndex )
|
||||
.Add("Start" , clcrd.Start.Int )
|
||||
.Add("Type" , clcrd.Type )
|
||||
.Add("TypeParam" , clcrd.TypeParam )
|
||||
.Add("WallParam" , clcrd.WallParam );
|
||||
}
|
||||
msgPack.Add(collectionCardTable);
|
||||
}
|
||||
else if (CustomizeItemTable != null)
|
||||
{
|
||||
MsgPack customizeItemTable = new MsgPack(CustomizeItemTable.Length, "CustomizeItemTable");
|
||||
for (i0 = 0; i0 < CustomizeItemTable.Length; i0++)
|
||||
{
|
||||
ref CustomizeItem czitm = ref CustomizeItemTable[i0];
|
||||
customizeItemTable[i0] = MsgPack.New.Add("Chara" , czitm.Chara )
|
||||
.Add("ID" , czitm.ID )
|
||||
.Add("Name" , czitm.Name )
|
||||
.Add("NG" , czitm.NG )
|
||||
.Add("ObjID" , czitm.ObjID )
|
||||
.Add("Parts" , czitm.Parts )
|
||||
.Add("SellType" , czitm.SellType )
|
||||
.Add("ShopEnd" , czitm.ShopEnd .Int)
|
||||
.Add("ShopPrice", czitm.ShopPrice )
|
||||
.Add("ShopStart", czitm.ShopStart.Int)
|
||||
.Add("SortIndex", czitm.SortIndex );
|
||||
}
|
||||
msgPack.Add(customizeItemTable);
|
||||
}
|
||||
else if (ModuleTable != null)
|
||||
{
|
||||
MsgPack moduleTable = new MsgPack(ModuleTable.Length, "ModuleTable");
|
||||
for (i0 = 0; i0 < ModuleTable.Length; i0++)
|
||||
{
|
||||
ref Module mdl = ref ModuleTable[i0];
|
||||
moduleTable[i0] = MsgPack.New.Add("Attribute", mdl.Attribute )
|
||||
.Add("Chara" , mdl.Chara )
|
||||
.Add("Costume" , mdl.Costume )
|
||||
.Add("ID" , mdl.ID )
|
||||
.Add("Name" , mdl.Name )
|
||||
.Add("NG" , mdl.NG )
|
||||
.Add("ShopEnd" , mdl.ShopEnd .Int)
|
||||
.Add("ShopPrice", mdl.ShopPrice )
|
||||
.Add("ShopStart", mdl.ShopStart.Int)
|
||||
.Add("SortIndex", mdl.SortIndex );
|
||||
}
|
||||
msgPack.Add(moduleTable);
|
||||
}
|
||||
else if (PlateTable != null)
|
||||
{
|
||||
MsgPack plateTable = new MsgPack(PlateTable.Length, "PlateTable");
|
||||
for (i0 = 0; i0 < PlateTable.Length; i0++)
|
||||
{
|
||||
ref Plate plt = ref PlateTable[i0];
|
||||
plateTable[i0] = MsgPack.New.Add("Alpha" , plt.Alpha )
|
||||
.Add("BaseID" , plt.BaseID )
|
||||
.Add("Border" , plt.Border )
|
||||
.Add("ColorB" , plt.ColorB )
|
||||
.Add("ColorG" , plt.ColorG )
|
||||
.Add("ColorR" , plt.ColorR )
|
||||
.Add("Font" , plt.Font )
|
||||
.Add("ID" , plt.ID )
|
||||
.Add("Shadow" , plt.Shadow )
|
||||
.Add("ShadowAlpha" , plt.ShadowAlpha )
|
||||
.Add("ShadowColorB", plt.ShadowColorB)
|
||||
.Add("ShadowColorG", plt.ShadowColorG)
|
||||
.Add("ShadowColorR", plt.ShadowColorR);
|
||||
}
|
||||
msgPack.Add(plateTable);
|
||||
}
|
||||
else if (PVListTable != null)
|
||||
{
|
||||
MsgPack pvList = new MsgPack(PVListTable.Length, "PVList");
|
||||
for (i0 = 0; i0 < PVListTable.Length; i0++)
|
||||
{
|
||||
ref PV pv = ref PVListTable[i0];
|
||||
MsgPack mp = MsgPack.New.Add("AdvEnd" , pv.AdvEnd .Int)
|
||||
.Add("AdvStart", pv.AdvStart.Int);
|
||||
|
||||
mp = mp.Add("ID" , pv.ID )
|
||||
.Add("Name" , pv.Name )
|
||||
.Add("Ignore", pv.Ignore);
|
||||
|
||||
mp.Add(WriteDifficulty("Easy" , pv.Easy ));
|
||||
mp.Add(WriteDifficulty("Normal" , pv.Normal ));
|
||||
mp.Add(WriteDifficulty("Hard" , pv.Hard ));
|
||||
mp.Add(WriteDifficulty("Extreme", pv.Extreme));
|
||||
mp.Add(WriteDifficulty("Encore" , pv.Encore ));
|
||||
pvList[i0] = mp;
|
||||
}
|
||||
msgPack.Add(pvList);
|
||||
|
||||
static MsgPack WriteDifficulty(string name, PV.Difficulty[] arr)
|
||||
{
|
||||
if (arr == null) return default;
|
||||
MsgPack mp = new MsgPack(arr.Length, name);
|
||||
for (int i = 0; i < arr.Length; i++)
|
||||
{
|
||||
ref PV.Difficulty diff = ref arr[i];
|
||||
mp[i] = MsgPack.New.Add("Edition", diff.Edition )
|
||||
.Add("End" , diff.End.Int )
|
||||
.Add("Start" , diff.Start.Int)
|
||||
.Add("Version", diff.Version );
|
||||
}
|
||||
return mp;
|
||||
}
|
||||
}
|
||||
else if (SlideSETable != null)
|
||||
{
|
||||
MsgPack slideSETable = new MsgPack(SlideSETable.Length, "SlideSETable");
|
||||
for (i0 = 0; i0 < SlideSETable.Length; i0++)
|
||||
{
|
||||
ref SlideSE sld = ref SlideSETable[i0];
|
||||
slideSETable[i0] = MsgPack.New.Add( "End" , sld.End.Int )
|
||||
.Add( "ID" , sld. ID )
|
||||
.Add( "Name" , sld. Name )
|
||||
.Add( "SEName" , sld. SEName )
|
||||
.Add("SortIndex", sld.SortIndex)
|
||||
.Add( "Start", sld.Start.Int);
|
||||
}
|
||||
msgPack.Add(slideSETable);
|
||||
}
|
||||
else if (SliderTouchSETable != null)
|
||||
{
|
||||
MsgPack sliderTouchSETable = new MsgPack(SliderTouchSETable.Length, "SliderTouchSETable");
|
||||
for (i0 = 0; i0 < SliderTouchSETable.Length; i0++)
|
||||
{
|
||||
ref SliderTouchSE sldt = ref SliderTouchSETable[i0];
|
||||
sliderTouchSETable[i0] = MsgPack.New.Add( "End" , sldt.End.Int )
|
||||
.Add( "ID" , sldt. ID )
|
||||
.Add( "Name" , sldt. Name )
|
||||
.Add( "SEName" , sldt. SEName )
|
||||
.Add("SortIndex", sldt.SortIndex)
|
||||
.Add( "Start", sldt.Start.Int);
|
||||
}
|
||||
msgPack.Add(sliderTouchSETable);
|
||||
}
|
||||
if (msgPack.List.Count == 1) msgPack.Write(file, false, json);
|
||||
}
|
||||
|
||||
private bool disposed;
|
||||
public void Dispose()
|
||||
{
|
||||
if (disposed) return;
|
||||
if (s != null) s.D(); s = null;
|
||||
if (dict != null) { dict.Clear(); dict = null; }
|
||||
ButtonSETable = null; ChainSlideSETable = null; SlideSETable = null; SliderTouchSETable = null;
|
||||
CollectionCardTable = null; CustomizeItemTable = null;
|
||||
ModuleTable = null; PlateTable = null; PVListTable = null; disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public static class Text
|
||||
{
|
||||
public static string ToASCII(this byte[] Array) => Encoding.ASCII.GetString(Array);
|
||||
public static string ToUTF8 (this byte[] Array) => Encoding.UTF8 .GetString(Array);
|
||||
public static byte[] ToASCII(this string Data ) => Encoding.ASCII.GetBytes (Data );
|
||||
public static byte[] ToUTF8 (this string Data ) => Encoding.UTF8 .GetBytes (Data );
|
||||
public static byte[] ToASCII(this char[] Data ) => Encoding.ASCII.GetBytes (Data );
|
||||
public static byte[] ToUTF8 (this char[] Data ) => Encoding.UTF8 .GetBytes (Data );
|
||||
public static string ToBase64(this byte[] Array) => Convert. ToBase64String(Array);
|
||||
public static byte[] FromBase64(this string Data ) => Convert.FromBase64String(Data );
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace KKdMainLib.Types
|
||||
{
|
||||
public struct Half : IFormattable
|
||||
{
|
||||
private ushort _value;
|
||||
|
||||
public static explicit operator Half(ushort bits) => new Half() { _value = bits };
|
||||
|
||||
public static explicit operator ushort(Half bits) => bits._value;
|
||||
|
||||
public static explicit operator double(Half h)
|
||||
{
|
||||
if (h._value == 0x0000)
|
||||
return +0;
|
||||
else if (h._value == 0x8000)
|
||||
return (-0);
|
||||
else if (h._value == 0x7C00)
|
||||
return double.PositiveInfinity;
|
||||
else if (h._value == 0xFC00)
|
||||
return double.NegativeInfinity;
|
||||
else if (h._value >> 10 == 0x1F)
|
||||
return double.NaN;
|
||||
else if (h._value >> 10 == 0x3F)
|
||||
return -double.NaN;
|
||||
|
||||
long exponent = ((h._value >> 10) & 0x1F);
|
||||
long mantissa = (h._value & 0x3FF);
|
||||
sbyte n = (sbyte)(((h._value >> 15 & 0x01) == 0) ? 1 : -1);
|
||||
|
||||
double m = (((long)1 << 10) | mantissa) / Math.Pow(2, 10);
|
||||
double x = Math.Pow(2, exponent - (0x1F >> 1));
|
||||
double d = n * m * x;
|
||||
return d;
|
||||
}
|
||||
|
||||
public static explicit operator Half(double val)
|
||||
{
|
||||
Half h = new Half();
|
||||
if (val == +0)
|
||||
h._value = 0x0000;
|
||||
else if (val == -0)
|
||||
h._value = 0x8000;
|
||||
else if (val == double.NaN)
|
||||
h._value = 0x7FFF;
|
||||
else if (val == -double.NaN)
|
||||
h._value = 0xFFFF;
|
||||
else if (val == double.PositiveInfinity)
|
||||
h._value = 0x7C00;
|
||||
else if (val == double.NegativeInfinity)
|
||||
h._value = 0xFC00;
|
||||
else
|
||||
h._value = ToDouble(val);
|
||||
return h;
|
||||
}
|
||||
|
||||
public static ushort ToDouble(double val)
|
||||
{
|
||||
ushort Sign = 0;
|
||||
if (val < 0)
|
||||
Sign = 0x8000;
|
||||
val = Math.Abs(val);
|
||||
double Pow1 = 1;
|
||||
double Pow2 = 1 << 10;
|
||||
double x = 0;
|
||||
|
||||
int MaxPow = (1 << 4);
|
||||
|
||||
int i = 0;
|
||||
while (i < MaxPow && i > -MaxPow + 1)
|
||||
{
|
||||
Pow1 = Math.Pow(2, i);
|
||||
x = val / Pow1;
|
||||
if (x >= 1 && x < 2)
|
||||
{
|
||||
ushort exponent_max = (ushort)Math.Ceiling(x * Pow2);
|
||||
ushort exponent_min = (ushort)Math.Floor (x * Pow2);
|
||||
ushort exponent = 0;
|
||||
if (Math.Abs(x - exponent_max / Pow2) > Math.Abs(x - exponent_min / Pow2))
|
||||
exponent = exponent_max;
|
||||
else exponent = exponent_min;
|
||||
ushort mantissa = (ushort)(i + MaxPow - 1);
|
||||
ushort d = (ushort)(Sign | ((mantissa & 0x001F) << 10) | (exponent & 0x03FF));
|
||||
return d;
|
||||
}
|
||||
else if (val < 1) i--;
|
||||
else i++;
|
||||
}
|
||||
|
||||
if (i >= +0)
|
||||
return 0x7C00;
|
||||
else
|
||||
return 0xFC00;
|
||||
}
|
||||
|
||||
public override string ToString() => ((double)this).ToString();
|
||||
public string ToString(string format, IFormatProvider formatProvider) =>
|
||||
((double)this).ToString(format, formatProvider);
|
||||
public override int GetHashCode() => base.GetHashCode();
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.Types
|
||||
{
|
||||
public class Vector2<T>
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
public T Z;
|
||||
|
||||
public Vector2()
|
||||
{ X = default(T); Y = default(T); Z = default(T); }
|
||||
|
||||
public Vector2(T X, T Y, T Z)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; }
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using KKdMainLib.MessagePack;
|
||||
|
||||
namespace KKdMainLib.Types
|
||||
{
|
||||
public class Vector3<T>
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
public T Z;
|
||||
|
||||
public Vector3()
|
||||
{ X = default(T); Y = default(T); Z = default(T); }
|
||||
|
||||
public Vector3(T X, T Y, T Z)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; }
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public class Xml
|
||||
{
|
||||
public XDocument doc;
|
||||
|
||||
public bool Compact = false;
|
||||
|
||||
public Xml() { doc = new XDocument(); }
|
||||
|
||||
public void OpenXml(string file, bool compact)
|
||||
{
|
||||
doc = XDocument.Load(file);
|
||||
Compact = compact;
|
||||
}
|
||||
|
||||
public void SaveXml(string file)
|
||||
{
|
||||
XmlWriter writer = XmlWriter.Create(file, settings);
|
||||
doc.Save(writer);
|
||||
writer.Dispose();
|
||||
Compact = false;
|
||||
GC.Collect();
|
||||
}
|
||||
|
||||
public readonly XmlWriterSettings settings = new XmlWriterSettings
|
||||
{ Encoding = Encoding.UTF8, NewLineChars = "\n", Indent = true, IndentChars = "\t" };
|
||||
|
||||
public void Reader(XElement Child, ref bool value, string localName)
|
||||
{ if (Child.Name == localName) value = bool.Parse(Child.Value); }
|
||||
|
||||
public void Reader(XAttribute Entry, ref bool value, string localName)
|
||||
{ if (Entry.Name == localName) value = bool.Parse(Entry.Value); }
|
||||
|
||||
public void Reader(XElement Child, ref int value, string localName)
|
||||
{ if (Child.Name == localName) value = int.Parse(Child.Value); }
|
||||
|
||||
public void Reader(XAttribute Entry, ref int value, string localName)
|
||||
{ if (Entry.Name == localName) value = int.Parse(Entry.Value); }
|
||||
|
||||
public void Reader(XElement Child, ref uint value, string localName)
|
||||
{ if (Child.Name == localName) value = uint.Parse(Child.Value); }
|
||||
|
||||
public void Reader(XAttribute Entry, ref uint value, string localName)
|
||||
{ if (Entry.Name == localName) value = uint.Parse(Entry.Value); }
|
||||
|
||||
public void Reader(XElement Child, ref long value, string localName)
|
||||
{ if (Child.Name == localName) value = long.Parse(Child.Value); }
|
||||
|
||||
public void Reader(XAttribute Entry, ref long value, string localName)
|
||||
{ if (Entry.Name == localName) value = long.Parse(Entry.Value); }
|
||||
|
||||
public void Reader(XElement Child, ref ulong value, string localName)
|
||||
{ if (Child.Name == localName) value = ulong.Parse(Child.Value); }
|
||||
|
||||
public void Reader(XAttribute Entry, ref ulong value, string localName)
|
||||
{ if (Entry.Name == localName) value = ulong.Parse(Entry.Value); }
|
||||
|
||||
public void Reader(XElement Child, ref double value, string localName)
|
||||
{ if (Child.Name == localName) value = Child.Value.ToDouble(); }
|
||||
|
||||
public void Reader(XAttribute Entry, ref double value, string localName)
|
||||
{ if (Entry.Name == localName) value = Entry.Value.ToDouble(); }
|
||||
|
||||
public void Reader(XElement Child, ref string value, string localName)
|
||||
{ if (Child.Name == localName) value = Child.Value; }
|
||||
|
||||
public void Reader(XAttribute Entry, ref string value, string localName)
|
||||
{ if (Entry.Name == localName) value = Entry.Value; }
|
||||
|
||||
public void Reader(XElement Child, ref string[] value, string localName, params char[] Separate)
|
||||
{ if (Child.Name == localName) value = Child.Value.Split(Separate); }
|
||||
|
||||
public void Reader(XAttribute Entry, ref string[] value, string localName, params char[] Separate)
|
||||
{ if (Entry.Name == localName) value = Entry.Value.Split(Separate); }
|
||||
|
||||
public void Writer(XElement element, bool value, string localName) =>
|
||||
Writer(element, value.ToString().ToLower(), localName);
|
||||
|
||||
public void Writer(XElement element, long value, string localName) =>
|
||||
Writer(element, value.ToString().ToLower(), localName);
|
||||
|
||||
public void Writer(XElement element, ulong value, string localName) =>
|
||||
Writer(element, value.ToString().ToLower(), localName);
|
||||
|
||||
public void Writer(XElement element, double value, string localName) =>
|
||||
Writer(element, value.ToString(), localName);
|
||||
|
||||
public void Writer(XElement element, string value, string localName)
|
||||
{
|
||||
if (Compact && value != "" && value != null)
|
||||
element.Add(new XAttribute(localName, value));
|
||||
else if (!Compact)
|
||||
element.Add(new XElement(localName, value));
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
+111
-118
@@ -1,4 +1,4 @@
|
||||
using KKdMainLib;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdSoundLib
|
||||
@@ -6,124 +6,118 @@ namespace KKdSoundLib
|
||||
public unsafe class DIVA
|
||||
{
|
||||
public DIVAFile Data = new DIVAFile();
|
||||
|
||||
public string file = "";
|
||||
private int c, i;
|
||||
|
||||
public DIVA() { Data = new DIVAFile(); file = ""; }
|
||||
public DIVA(string filepath) { Data = new DIVAFile(); file = filepath; }
|
||||
public DIVA() { Data = new DIVAFile(); }
|
||||
|
||||
public void DIVAReader(bool ToArray = false)
|
||||
public void DIVAReader(string file, bool ToArray = false)
|
||||
{
|
||||
if (File.Exists(file + ".diva"))
|
||||
if (!File.Exists(file + ".diva")) return;
|
||||
|
||||
Data = new DIVAFile();
|
||||
Stream reader = File.OpenReader(file + ".diva");
|
||||
|
||||
if (reader.RS(0x04) != "DIVA") { reader.C(); return; }
|
||||
|
||||
reader.RI32();
|
||||
Data.Size = reader.RI32();
|
||||
Data.SampleRate = reader.RI32();
|
||||
Data.SamplesCount = reader.RI32();
|
||||
reader.RI64();
|
||||
Data.Channels = reader.RU8();
|
||||
reader.RU8();
|
||||
reader.RU16();
|
||||
reader.RBy(0x20);
|
||||
|
||||
byte value = 0;
|
||||
byte[] data = new byte[Data.SamplesCount * Data.Channels * 4];
|
||||
int[] current = new int[Data.Channels];
|
||||
int[] currentclamp = new int[Data.Channels];
|
||||
sbyte[] stepindex = new sbyte[Data.Channels];
|
||||
|
||||
fixed (int* currentPtr = current)
|
||||
fixed (int* currentclampPtr = currentclamp)
|
||||
fixed (sbyte* stepindexPtr = stepindex)
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
Data = new DIVAFile();
|
||||
Stream reader = File.OpenReader(file + ".diva");
|
||||
|
||||
if (reader.ReadString(0x04) == "DIVA")
|
||||
{
|
||||
reader.ReadInt32();
|
||||
Data.Size = reader.ReadUInt32();
|
||||
Data.SampleRate = reader.ReadUInt32();
|
||||
Data.SamplesCount = reader.ReadUInt32();
|
||||
reader.ReadInt64();
|
||||
Data.Channels = reader.ReadUInt16();
|
||||
reader.ReadUInt16();
|
||||
Data.Name = reader.ReadString(0x20);
|
||||
|
||||
Stream writer = File.OpenWriter();
|
||||
if (!ToArray) writer = File.OpenWriter(file + ".wav", true);
|
||||
writer.LongPosition = 0x2C;
|
||||
|
||||
byte value = 0;
|
||||
int[] current = new int[Data.Channels];
|
||||
int[] currentclamp = new int[Data.Channels];
|
||||
sbyte[] stepindex = new sbyte[Data.Channels];
|
||||
float f;
|
||||
|
||||
int* currentPtr = current.GetPtr();
|
||||
int* currentclampPtr = currentclamp.GetPtr();
|
||||
sbyte* stepindexPtr = stepindex.GetPtr();
|
||||
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Data.Channels; c++)
|
||||
{
|
||||
value = reader.ReadHalfByte();
|
||||
IMADecoder(value, ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
|
||||
f = (float)(currentPtr[c] / 32768.0);
|
||||
writer.Write(f);
|
||||
}
|
||||
|
||||
WAV.Header Header = new WAV.Header
|
||||
{ Bytes = 4, Channels = Data.Channels, Format = 3,
|
||||
SampleRate = Data.SampleRate, Size = Data.SamplesCount * Data.Channels * 4};
|
||||
writer.Write(Header, 0);
|
||||
if (ToArray) Data.Data = writer.ToArray();
|
||||
writer.Close();
|
||||
}
|
||||
reader.Close();
|
||||
reader.S(0, SeekOrigin.Begin);
|
||||
float* dataPtr = (float*)ptr;
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Data.Channels; c++, dataPtr++)
|
||||
{
|
||||
value = reader.RHB();
|
||||
IMADecoder(value, ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
|
||||
*dataPtr = (float)(currentPtr[c] / 32768.0);
|
||||
}
|
||||
}
|
||||
reader.CR();
|
||||
|
||||
|
||||
if (ToArray) Data.Data = data;
|
||||
else
|
||||
{
|
||||
Stream writer = File.OpenWriter(file + ".wav", true);
|
||||
WAV.Header Header = new WAV.Header { Bytes = 4, Channels = Data.Channels, Format = 3,
|
||||
SampleRate = Data.SampleRate, Size = Data.SamplesCount * Data.Channels * 4 };
|
||||
writer.W(Header, 0);
|
||||
writer.W(data);
|
||||
writer.C();
|
||||
}
|
||||
|
||||
reader.C();
|
||||
}
|
||||
|
||||
private byte[] BuildWavHeader(WAV.Header Header, short Bytes)
|
||||
public void DIVAWriter(string file)
|
||||
{
|
||||
Stream writer = File.OpenWriter();
|
||||
writer.Write(Header);
|
||||
byte[] Data = writer.ToArray();
|
||||
writer.Close();
|
||||
return Data;
|
||||
}
|
||||
if (!File.Exists(file + ".wav")) return;
|
||||
|
||||
public void DIVAWriter()
|
||||
{
|
||||
if (File.Exists(file + ".wav"))
|
||||
Stream reader = File.OpenReader(file + ".wav");
|
||||
|
||||
Data = new DIVAFile();
|
||||
WAV.Header Header = reader.ReadWAVHeader();
|
||||
if (!Header.IsSupported) { reader.C(); return; }
|
||||
|
||||
Stream writer = File.OpenWriter(file + ".diva", true);
|
||||
Data.Channels = (byte)Header.Channels;
|
||||
Data.SampleRate = Header.SampleRate;
|
||||
Data.SamplesCount = Header.Size / Header.Channels / Header.Bytes;
|
||||
writer.PI64 = 0x40;
|
||||
writer.LI64 = 0x40 + (Data.SamplesCount * Data.Channels).A(2, 2);
|
||||
|
||||
byte value = 0;
|
||||
int[] sample = new int[Data.Channels];
|
||||
int[] current = new int[Data.Channels];
|
||||
int[] currentclamp = new int[Data.Channels];
|
||||
sbyte[] stepindex = new sbyte[Data.Channels];
|
||||
|
||||
fixed (int* samplePtr = sample)
|
||||
fixed (int* currentPtr = current)
|
||||
fixed (int* currentclampPtr = currentclamp)
|
||||
fixed (sbyte* stepindexPtr = stepindex)
|
||||
{
|
||||
Stream reader = File.OpenReader(file + ".wav");
|
||||
Stream writer = File.OpenWriter(file + ".diva", true);
|
||||
|
||||
Data = new DIVAFile();
|
||||
WAV.Header Header = reader.ReadWAVHeader();
|
||||
if (Header.IsSupported)
|
||||
{
|
||||
Data.Channels = Header.Channels;
|
||||
Data.SampleRate = Header.SampleRate;
|
||||
writer.LongPosition = 0x40;
|
||||
|
||||
byte value = 0;
|
||||
int[] sample = new int[Data.Channels];
|
||||
int[] current = new int[Data.Channels];
|
||||
int[] currentclamp = new int[Data.Channels];
|
||||
sbyte[] stepindex = new sbyte[Data.Channels];
|
||||
|
||||
int* samplePtr = sample.GetPtr();
|
||||
int* currentPtr = current.GetPtr();
|
||||
int* currentclampPtr = currentclamp.GetPtr();
|
||||
sbyte* stepindexPtr = stepindex.GetPtr();
|
||||
Data.SamplesCount = Header.Size / Header.Channels / Header.Bytes;
|
||||
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Header.Channels; c++)
|
||||
{
|
||||
samplePtr[c] = (reader.ReadWAVSample(Header.Bytes, Header.Format) * 0x8000).CFTI();
|
||||
value = IMAEncoder(samplePtr[c], ref currentPtr[c],
|
||||
ref currentclampPtr[c], ref stepindexPtr[c]);
|
||||
writer.Write(value, 4);
|
||||
}
|
||||
writer.CheckWrited();
|
||||
|
||||
writer.LongPosition = 0x00;
|
||||
writer.Write("DIVA");
|
||||
writer.Write(0x00);
|
||||
writer.Write((Data.SamplesCount * Data.Channels).Align(2, 2));
|
||||
writer.Write(Data.SampleRate);
|
||||
writer.Write(Data.SamplesCount);
|
||||
writer.Write(0x00);
|
||||
writer.Write(0x00);
|
||||
writer.Write(Data.Channels);
|
||||
}
|
||||
reader.Close();
|
||||
writer.Close();
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Header.Channels; c++)
|
||||
{
|
||||
samplePtr[c] = (reader.RS(Header.Bytes, Header.Format) * 0x8000).CFTI();
|
||||
value = IMAEncoder(samplePtr[c], ref currentPtr[c],
|
||||
ref currentclampPtr[c], ref stepindexPtr[c]);
|
||||
writer.W(value, 4);
|
||||
}
|
||||
}
|
||||
|
||||
writer.CW();
|
||||
|
||||
writer.PI64 = 0x00;
|
||||
writer.W("DIVA");
|
||||
writer.W(0x00);
|
||||
writer.W((Data.SamplesCount * Data.Channels).A(2, 2));
|
||||
writer.W(Data.SampleRate);
|
||||
writer.W(Data.SamplesCount);
|
||||
writer.W(0x00);
|
||||
writer.W(0x00);
|
||||
writer.W(Data.Channels);
|
||||
writer.C();
|
||||
reader.C();
|
||||
}
|
||||
|
||||
private void IMADecoder(byte value, ref int current, ref int currentclamp, ref sbyte stepindex)
|
||||
@@ -134,14 +128,14 @@ namespace KKdSoundLib
|
||||
if ((value & 1) == 1) diff += step >> 2;
|
||||
if ((value & 2) == 2) diff += step >> 1;
|
||||
if ((value & 4) == 4) diff += step;
|
||||
|
||||
|
||||
if ((value & 8) == 8)
|
||||
{ currentclamp -= diff; current = currentclamp;
|
||||
if (currentclamp < -0x8000) currentclamp = -0x8000; }
|
||||
else
|
||||
{ currentclamp += diff; current = currentclamp;
|
||||
if (currentclamp > 0x7FFF) currentclamp = 0x7FFF; }
|
||||
|
||||
|
||||
stepindex += ima_index_table[value & 7];
|
||||
if (stepindex < 0) stepindex = 0;
|
||||
if (stepindex > 88) stepindex = 88;
|
||||
@@ -155,9 +149,9 @@ namespace KKdSoundLib
|
||||
{
|
||||
value = 0;
|
||||
step = ima_step_table[stepindex];
|
||||
|
||||
|
||||
delta = sample - current;
|
||||
|
||||
|
||||
if (delta < 0)
|
||||
{ value |= 8; delta = -delta; }
|
||||
diff = step >> 3;
|
||||
@@ -169,14 +163,14 @@ namespace KKdSoundLib
|
||||
step >>= 1;
|
||||
if (delta > step)
|
||||
{ value |= 1; diff += step; }
|
||||
|
||||
|
||||
if ((value & 8) == 8)
|
||||
{ currentclamp -= diff; current = currentclamp;
|
||||
if (currentclamp < -0x8000) currentclamp = -0x8000; }
|
||||
else
|
||||
{ currentclamp += diff; current = currentclamp;
|
||||
if (currentclamp > 0x7FFF) currentclamp = 0x7FFF; }
|
||||
|
||||
|
||||
stepindex += ima_index_table[value & 0x07];
|
||||
if (stepindex < 0) stepindex = 0;
|
||||
if (stepindex > 88) stepindex = 88;
|
||||
@@ -203,11 +197,10 @@ namespace KKdSoundLib
|
||||
|
||||
public struct DIVAFile
|
||||
{
|
||||
public uint Size;
|
||||
public uint SampleRate;
|
||||
public uint SamplesCount;
|
||||
public string Name;
|
||||
public ushort Channels;
|
||||
public int Size;
|
||||
public int SampleRate;
|
||||
public int SamplesCount;
|
||||
public byte Channels;
|
||||
public byte[] Data;
|
||||
}
|
||||
}
|
||||
|
||||
+58
-57
@@ -1,96 +1,97 @@
|
||||
using KKdMainLib.IO;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdSoundLib
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
public static double ReadWAVSample(this Stream IO, ushort Bytes, ushort Format)
|
||||
public static double RS(this Stream _IO, ushort Bytes, ushort Format)
|
||||
{
|
||||
if (Bytes == 2) return IO. ReadInt16() / (double)0x00008000;
|
||||
else if (Bytes == 4 && Format == 0x01) return IO. ReadInt32() / (double)0x80000000;
|
||||
else if (Bytes == 4 && Format == 0x03) return IO.ReadSingle();
|
||||
else if (Bytes == 8 && Format == 0x03) return IO.ReadDouble();
|
||||
if (Bytes == 2) return _IO. RI16() / (double)0x00008000;
|
||||
else if (Bytes == 4 && Format == 0x01) return _IO. RI32() / (double)0x80000000;
|
||||
else if (Bytes == 4 && Format == 0x03) return _IO.RF32();
|
||||
else if (Bytes == 8 && Format == 0x03) return _IO.RF64();
|
||||
else return 0;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, double Sample, ushort Bytes, ushort Format)
|
||||
public static void W(this Stream _IO, double Sample, ushort Bytes, ushort Format)
|
||||
{
|
||||
if (Bytes == 2) IO.Write ((ushort)(Sample * 0x00008000));
|
||||
else if (Bytes == 4 && Format == 0x01) IO.Write (( int)(Sample * 0x80000000));
|
||||
else if (Bytes == 4 && Format == 0x03) IO.Write ((float) Sample);
|
||||
else if (Bytes == 8 && Format == 0x03) IO.Write ( Sample);
|
||||
if (Bytes == 2) _IO.W((Sample * 0x00008000).CFTS());
|
||||
else if (Bytes == 4 && Format == 0x01) _IO.W((Sample * 0x80000000).CFTI());
|
||||
else if (Bytes == 4 && Format == 0x03) _IO.W((float)Sample);
|
||||
else if (Bytes == 8 && Format == 0x03) _IO.W( Sample);
|
||||
}
|
||||
|
||||
public static WAV.Header ReadWAVHeader(this Stream IO)
|
||||
public static WAV.Header ReadWAVHeader(this Stream _IO)
|
||||
{
|
||||
WAV.Header Header = new WAV.Header();
|
||||
if (IO.ReadString(4) != "RIFF") return Header;
|
||||
IO.ReadUInt32();
|
||||
if (IO.ReadString(4) != "WAVE") return Header;
|
||||
if (IO.ReadString(4) != "fmt ") return Header;
|
||||
int Offset = IO.ReadInt32();
|
||||
Header.Format = IO.ReadUInt16();
|
||||
if (_IO.RS(4) != "RIFF") return Header;
|
||||
_IO.RU32();
|
||||
if (_IO.RS(4) != "WAVE") return Header;
|
||||
if (_IO.RS(4) != "fmt ") return Header;
|
||||
int Offset = _IO.RI32();
|
||||
Header.Format = _IO.RU16();
|
||||
if (Header.Format == 0x01 || Header.Format == 0x03 || Header.Format == 0xFFFE)
|
||||
{
|
||||
Header.Channels = IO.ReadUInt16();
|
||||
Header.SampleRate = IO.ReadUInt32();
|
||||
IO.ReadInt32(); IO.ReadInt16();
|
||||
Header.Bytes = IO.ReadUInt16();
|
||||
Header.Channels = _IO.RU16();
|
||||
Header.SampleRate = _IO.RI32();
|
||||
_IO.RI32(); _IO.RI16();
|
||||
Header.Bytes = _IO.RU16();
|
||||
if (Header.Bytes % 8 != 0) return Header;
|
||||
Header.Bytes >>= 3;
|
||||
if (Header.Bytes == 0) return Header;
|
||||
if (Header.Format == 0xFFFE)
|
||||
{
|
||||
IO.ReadInt32();
|
||||
Header.ChannelMask = IO.ReadUInt32();
|
||||
Header.Format = IO.ReadUInt16();
|
||||
_IO.RI32();
|
||||
Header.ChannelMask = _IO.RU32();
|
||||
Header.Format = _IO.RU16();
|
||||
}
|
||||
if (Header.Bytes < 1 || (Header.Bytes > 4 && Header.Bytes != 8)) return Header;
|
||||
if (Header.Bytes > 0 && Header.Bytes < 4 && Header.Format == 3) return Header;
|
||||
if (Header.Bytes > 0 && Header.Bytes < 4 && Header.Format == 3 ) return Header;
|
||||
if (Header.Bytes == 8 && Header.Format == 1) return Header;
|
||||
IO.Seek(Offset + 0x14, 0);
|
||||
if (IO.ReadString(4) != "data") return Header;
|
||||
Header.Size = IO.ReadUInt32();
|
||||
Header.HeaderSize = IO.UIntPosition;
|
||||
_IO.S(Offset + 0x14, 0);
|
||||
if (_IO.RS(4) != "data") return Header;
|
||||
Header.Size = _IO.RI32();
|
||||
Header.HeaderSize = _IO.P;
|
||||
Header.IsSupported = true;
|
||||
return Header;
|
||||
}
|
||||
return Header;
|
||||
}
|
||||
|
||||
public static void Write(this Stream IO, WAV.Header Header, long Seek) => IO.Write(Header, Seek, 0);
|
||||
public static void W(this Stream _IO, WAV.Header Header, long Seek) => _IO.W(Header, Seek, 0);
|
||||
|
||||
public static void Write(this Stream IO, WAV.Header Header, long Seek, SeekOrigin Origin)
|
||||
{ IO.Seek(Seek, Origin); IO.Write(Header); }
|
||||
public static void W(this Stream _IO, WAV.Header Header, long Seek, SeekOrigin Origin)
|
||||
{ _IO.S(Seek, Origin); _IO.W(Header); }
|
||||
|
||||
public static void Write(this Stream IO, WAV.Header Header)
|
||||
public static void W(this Stream _IO, WAV.Header Header)
|
||||
{
|
||||
IO.Write("RIFF");
|
||||
if (Header.Format != 0xFFFE) IO.Write(Header.Size + 0x24);
|
||||
else IO.Write(Header.Size + 0x3C);
|
||||
IO.Write("WAVE");
|
||||
IO.Write("fmt ");
|
||||
if (Header.Format != 0xFFFE) IO.Write(0x10);
|
||||
else IO.Write(0x28);
|
||||
|
||||
IO.Write(Header.Format);
|
||||
IO.Write((short)Header.Channels);
|
||||
IO.Write(Header.SampleRate);
|
||||
IO.Write(Header.SampleRate * Header.Channels * Header.Bytes);
|
||||
IO.Write((short)(Header.Channels * Header.Bytes));
|
||||
IO.Write((short)(Header.Bytes << 3));
|
||||
_IO.W("RIFF");
|
||||
if (Header.Format != 0xFFFE) _IO.W(Header.Size + 0x24);
|
||||
else _IO.W(Header.Size + 0x3C);
|
||||
_IO.W("WAVE");
|
||||
_IO.W("fmt ");
|
||||
if (Header.Format != 0xFFFE) _IO.W(0x10);
|
||||
else _IO.W(0x28);
|
||||
|
||||
_IO.W(Header.Format);
|
||||
_IO.W((short)Header.Channels);
|
||||
_IO.W(Header.SampleRate);
|
||||
_IO.W(Header.SampleRate * Header.Channels * Header.Bytes);
|
||||
_IO.W((short)(Header.Channels * Header.Bytes));
|
||||
_IO.W((short)(Header.Bytes << 3));
|
||||
if (Header.Format == 0xFFFE)
|
||||
{
|
||||
IO.Write((short)0x16);
|
||||
IO.Write((short)(Header.Bytes << 3));
|
||||
IO.Write(Header.ChannelMask);
|
||||
IO.Write(Header.Bytes == 2 ? 0x01 : 0x03);
|
||||
IO.Write(0x00100000);
|
||||
IO.Write(0xAA000080);
|
||||
IO.Write(0x719B3800);
|
||||
_IO.W((short)0x16);
|
||||
_IO.W((short)(Header.Bytes << 3));
|
||||
_IO.W(Header.ChannelMask);
|
||||
_IO.W(Header.Bytes == 2 ? 0x01 : 0x03);
|
||||
_IO.W(0x00100000);
|
||||
_IO.W(0xAA000080);
|
||||
_IO.W(0x719B3800);
|
||||
}
|
||||
IO.Write("data");
|
||||
IO.Write(Header.Size);
|
||||
_IO.W("data");
|
||||
_IO.W(Header.Size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>KKdSoundLib</RootNamespace>
|
||||
<AssemblyName>KKdSoundLib</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<Authors>korenkonder</Authors>
|
||||
<Company></Company>
|
||||
<Configuration></Configuration>
|
||||
<Copyright>korenkonder (C) 2019-2022</Copyright>
|
||||
<Description>A simple library for working with Project Diva F/AFT/F2/X/XHD/FT/VRFL/M39 audio files</Description>
|
||||
<FileVersion>0.1.2.1</FileVersion>
|
||||
<PackageId>KKdSoundLib</PackageId>
|
||||
<Product>KKdSoundLib</Product>
|
||||
<TargetFramework>net461</TargetFramework>
|
||||
<Title>KKdSoundLib</Title>
|
||||
<Version>0.1.2.1</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -22,6 +23,8 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0018, IDE0032, IDE0044, IDE0045, IDE0046, IDE0051, IDE0055, IDE0059, IDE0063, IDE0066, IDE0069, IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -33,27 +36,11 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0018, IDE0032, IDE0044, IDE0045, IDE0046, IDE0051, IDE0055, IDE0059, IDE0063, IDE0066, IDE0069, IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="DIVA.cs" />
|
||||
<Compile Include="VAG.cs" />
|
||||
<Compile Include="WAV.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<ProjectReference Include="..\KKdBaseLib\KKdBaseLib.csproj" />
|
||||
<ProjectReference Include="..\KKdMainLib\KKdMainLib.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KKdMainLib\KKdMainLib.csproj">
|
||||
<Project>{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}</Project>
|
||||
<Name>KKdMainLib</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
using System.Reflection;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("KKdSoundLib")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("KKdSoundLib")]
|
||||
[assembly: AssemblyCopyright("Copyright korenkonder © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA")]
|
||||
[assembly: AssemblyVersion("0.0.2.2")]
|
||||
[assembly: AssemblyFileVersion("0.0.2.2")]
|
||||
|
||||
+593
-556
File diff suppressed because it is too large
Load Diff
+3
-9
@@ -1,18 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace KKdSoundLib
|
||||
{
|
||||
public static class WAV
|
||||
{
|
||||
public struct Header
|
||||
{
|
||||
public uint Size;
|
||||
public uint SampleRate;
|
||||
public uint HeaderSize;
|
||||
public int Size;
|
||||
public int SampleRate;
|
||||
public int HeaderSize;
|
||||
public uint ChannelMask;
|
||||
public bool IsSupported;
|
||||
public ushort Bytes;
|
||||
|
||||
+13
-7
@@ -1,24 +1,26 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27130.2003
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29025.244
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PD_Tool", "PD_Tool\PD_Tool.csproj", "{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KKdBaseLib", "KKdBaseLib\KKdBaseLib.csproj", "{437F63F1-8C23-429E-AB14-38B85C9EDB16}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KKdMainLib", "KKdMainLib\KKdMainLib.csproj", "{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KKdSoundLib", "KKdSoundLib\KKdSoundLib.csproj", "{D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PD_Tool", "PD_Tool\PD_Tool.csproj", "{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{437F63F1-8C23-429E-AB14-38B85C9EDB16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{437F63F1-8C23-429E-AB14-38B85C9EDB16}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{437F63F1-8C23-429E-AB14-38B85C9EDB16}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{437F63F1-8C23-429E-AB14-38B85C9EDB16}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
@@ -27,6 +29,10 @@ Global
|
||||
{D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
+26
-13
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
@@ -11,6 +10,7 @@
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<RunPostBuildEvent>Always</RunPostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -22,6 +22,8 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0018, IDE0032, IDE0044, IDE0045, IDE0046, IDE0051, IDE0055, IDE0059, IDE0063, IDE0066, IDE0069, IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -33,17 +35,27 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0018, IDE0032, IDE0044, IDE0045, IDE0046, IDE0051, IDE0055, IDE0059, IDE0063, IDE0066, IDE0069, IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="classes\A3D.cs" />
|
||||
<Compile Include="classes\AET.cs" />
|
||||
<Compile Include="classes\BLT.cs" />
|
||||
<Compile Include="classes\CCT.cs" />
|
||||
<Compile Include="classes\DataBase.cs" />
|
||||
<Compile Include="classes\Tools\A3D.cs" />
|
||||
<Compile Include="classes\Tools\DB.cs" />
|
||||
<Compile Include="classes\Tools\DEX.cs" />
|
||||
<Compile Include="classes\Tools\DIV.cs" />
|
||||
<Compile Include="classes\Tools\STR.cs" />
|
||||
<Compile Include="classes\Tools\VAG.cs" />
|
||||
<Compile Include="classes\DB.cs" />
|
||||
<Compile Include="classes\DEX.cs" />
|
||||
<Compile Include="classes\DFT.cs" />
|
||||
<Compile Include="classes\DIV.cs" />
|
||||
<Compile Include="classes\DIVAFILE.cs" />
|
||||
<Compile Include="classes\FARC.cs" />
|
||||
<Compile Include="classes\LIT.cs" />
|
||||
<Compile Include="classes\MHD.cs" />
|
||||
<Compile Include="classes\MOT.cs" />
|
||||
<Compile Include="classes\STR.cs" />
|
||||
<Compile Include="classes\TBL.cs" />
|
||||
<Compile Include="classes\VAG.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
@@ -52,17 +64,18 @@
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KKdBaseLib\KKdBaseLib.csproj">
|
||||
<Project>{437f63f1-8c23-429e-ab14-38b85c9edb16}</Project>
|
||||
<Name>KKdBaseLib</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\KKdMainLib\KKdMainLib.csproj">
|
||||
<Project>{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}</Project>
|
||||
<Project>{2ba7efc6-91d1-8bbc-c487-06c7f36cc789}</Project>
|
||||
<Name>KKdMainLib</Name>
|
||||
<EmbedInteropTypes>False</EmbedInteropTypes>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\KKdSoundLib\KKdSoundLib.csproj">
|
||||
<Project>{D8A3F2D7-10CC-5723-EC9A-45D3B9C2DF77}</Project>
|
||||
<Project>{d8a3f2d7-10cc-5723-ec9a-45d3b9c2df77}</Project>
|
||||
<Name>KKdSoundLib</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
|
||||
+321
-71
@@ -1,117 +1,367 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMain = KKdMainLib.Main;
|
||||
using KKdFARC = KKdMainLib.FARC;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
public static class Program
|
||||
{
|
||||
public static string function = "";
|
||||
public static List<string> ProcessedFiles = new List<string>();
|
||||
[System.Runtime.InteropServices.DllImport("user32.dll")]
|
||||
private static extern bool SetProcessDPIAware();
|
||||
|
||||
[ThreadStatic] public static string choose = "";
|
||||
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
SetProcessDPIAware();
|
||||
|
||||
Console. InputEncoding = System.Text.Encoding.Unicode;
|
||||
Console.OutputEncoding = System.Text.Encoding.Unicode;
|
||||
|
||||
Console.Title = "PD_Tool";
|
||||
if (args.Length == 0) { while (choose != "Q") MainMenu(); Exit(); }
|
||||
|
||||
if (args.Length == 0)
|
||||
{
|
||||
while (function != "Q") MainMenu();
|
||||
Exit();
|
||||
}
|
||||
|
||||
string header;
|
||||
long header;
|
||||
Stream reader;
|
||||
KKdFARC Farc;
|
||||
|
||||
foreach (string arg in args)
|
||||
{
|
||||
Farc = new KKdFARC();
|
||||
if (Directory.Exists(arg)) Farc.Pack(arg);
|
||||
else if (File.Exists(arg) && Path.GetExtension(arg) == ".farc") Farc.UnPack(arg, true);
|
||||
GC.Collect();
|
||||
if (Directory.Exists(arg))
|
||||
using (KKdFARC FARC = new KKdFARC(arg, true) { CompressionLevel = 9 }) FARC.Pack();
|
||||
else if (File.Exists(arg) && Path.GetExtension(arg) == ".farc")
|
||||
using (KKdFARC farc = new KKdFARC(arg)) farc.Unpack(true);
|
||||
else if (File.Exists(arg))
|
||||
{
|
||||
reader = File.OpenReader(arg);
|
||||
header = reader.ReadString(8);
|
||||
reader.Close();
|
||||
if (header.ToUpper() == "DIVAFILE") DIVAFILE.Decrypt(arg);
|
||||
using (reader = File.OpenReader(arg))
|
||||
header = reader.RI64();
|
||||
if (header == 0x454C494641564944) KKdMainLib.DIVAFILE.Decrypt(arg);
|
||||
}
|
||||
}
|
||||
Exit();
|
||||
}
|
||||
|
||||
private static bool JSON = false;
|
||||
|
||||
[ThreadStatic] private static bool json = true;
|
||||
|
||||
private static void MainMenu()
|
||||
{
|
||||
Console.Title = "PD_Tool";
|
||||
Version ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
||||
Console.Title = $"PD_Tool v{ver}";
|
||||
Console.Clear();
|
||||
|
||||
KKdMain.ConsoleDesign(true);
|
||||
KKdMain.ConsoleDesign(" Choose action:");
|
||||
KKdMain.ConsoleDesign(false);
|
||||
KKdMain.ConsoleDesign("1. Extract FARC Archive");
|
||||
KKdMain.ConsoleDesign("2. Create FARC Archive");
|
||||
KKdMain.ConsoleDesign("3. Decrypt from DIVAFILE");
|
||||
KKdMain.ConsoleDesign("4. Encrypt to DIVAFILE");
|
||||
KKdMain.ConsoleDesign("5. DB_Tools");
|
||||
KKdMain.ConsoleDesign("6. Converting Tools");
|
||||
KKdMain.ConsoleDesign(false);
|
||||
KKdMain.ConsoleDesign(JSON ? "M. MessagePack" : "J. JSON");
|
||||
KKdMain.ConsoleDesign("Q. Quit");
|
||||
KKdMain.ConsoleDesign(false);
|
||||
KKdMain.ConsoleDesign(true);
|
||||
ConsoleDesign(true);
|
||||
ConsoleDesign(" Choose action:");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign("1. Extract FARC Archive");
|
||||
ConsoleDesign("2. Create FARC Archive");
|
||||
ConsoleDesign("3. Decrypt from DIVAFILE");
|
||||
ConsoleDesign("4. Encrypt to DIVAFILE");
|
||||
ConsoleDesign("5. DB_Tools");
|
||||
ConsoleDesign("6. AC/DT/F/AFT Converting Tools");
|
||||
ConsoleDesign("7. F/F2/FT Converting Tools");
|
||||
ConsoleDesign("8. X/XHD/VRFL Converting Tools");
|
||||
ConsoleDesign("9. FT/M39 Converting Tools");
|
||||
ConsoleDesign(json ? "A. MsgPack to JSON" : "A. JSON to MsgPack");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign(json ? "M. MessagePack" : "J. JSON");
|
||||
ConsoleDesign("Q. Quit");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
|
||||
function = Console.ReadLine().ToUpper();
|
||||
bool isNumber = int.TryParse(function, out int result);
|
||||
choose = Console.ReadLine().ToUpper();
|
||||
bool isNumber = int.TryParse(choose, out int result);
|
||||
if (isNumber) Functions();
|
||||
if (function == "M") JSON = false;
|
||||
else if (function == "J") JSON = true ;
|
||||
|
||||
if (choose == null || choose == "") return;
|
||||
if (choose[0] == 'M') json = false;
|
||||
else if (choose[0] == 'J') json = true ;
|
||||
else if (choose[0] >= 'A' && choose[0] <= 'A') Functions();
|
||||
}
|
||||
|
||||
private static void Functions()
|
||||
{
|
||||
Console.Clear();
|
||||
if (function == "1" || function == "2") FARC.Processor(function == "1");
|
||||
else if (function == "3" || function == "4")
|
||||
if (choose == null || choose == "") return;
|
||||
|
||||
if (choose[0] == '1' || choose[0] == '2') FARC.Processor(choose == "1");
|
||||
else if (choose[0] == '3')
|
||||
{
|
||||
KKdMain.Choose(1, "", out string[] FileNames);
|
||||
Choose(1, "", out string[] FileNames);
|
||||
foreach (string FileName in FileNames) DIVAFILE.Decrypt(FileName);
|
||||
}
|
||||
else if (function == "5") DataBase.Processor(JSON);
|
||||
else if (function == "6")
|
||||
else if (choose[0] == '4')
|
||||
{
|
||||
Console.Clear();
|
||||
Console.Title = "Converter Tools";
|
||||
KKdMain.ConsoleDesign(true);
|
||||
KKdMain.ConsoleDesign(" Choose tool:");
|
||||
KKdMain.ConsoleDesign(false);
|
||||
KKdMain.ConsoleDesign("1. A3DA Converter");
|
||||
KKdMain.ConsoleDesign("2. DEX Converter");
|
||||
KKdMain.ConsoleDesign("3. DIVA Converter");
|
||||
KKdMain.ConsoleDesign("4. STR Converter");
|
||||
KKdMain.ConsoleDesign("5. VAG Converter");
|
||||
KKdMain.ConsoleDesign("6. DataBank Converter");
|
||||
KKdMain.ConsoleDesign(false);
|
||||
KKdMain.ConsoleDesign("R. Return to Main Menu");
|
||||
KKdMain.ConsoleDesign(false);
|
||||
KKdMain.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
string Function = Console.ReadLine();
|
||||
Console.Clear();
|
||||
if (Function == "1") Tools.A3D.Processor(JSON);
|
||||
else if (Function == "2") Tools.DEX.Processor(JSON);
|
||||
else if (Function == "3") Tools.DIV.Processor();
|
||||
else if (Function == "4") Tools.STR.Processor(JSON);
|
||||
else if (Function == "5") Tools.VAG.Processor();
|
||||
else if (Function == "6") Tools.DB .Processor();
|
||||
else function = Function;
|
||||
Choose(1, "", out string[] FileNames);
|
||||
foreach (string FileName in FileNames) DIVAFILE.Encrypt(FileName);
|
||||
}
|
||||
else if (choose[0] == '5')
|
||||
DataBase.Processor(json, choose.Length > 1 ? choose[1] : '\0');
|
||||
else if (choose[0] == '6')
|
||||
{
|
||||
string localChoose = "";
|
||||
if (choose.Length == 1)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.Title = "AC/DT/F/AFT Converting Tools";
|
||||
ConsoleDesign(true);
|
||||
ConsoleDesign(" Choose converter:");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign("1. A3DA" );
|
||||
ConsoleDesign("2. AET" );
|
||||
ConsoleDesign("3. DataBank");
|
||||
ConsoleDesign("4. DEX" );
|
||||
ConsoleDesign("5. DIVA" );
|
||||
ConsoleDesign("6. MotHead" );
|
||||
ConsoleDesign("7. MOT" );
|
||||
ConsoleDesign("8. STR" );
|
||||
ConsoleDesign("9. Table" );
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign("R. Return to Main Menu");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
localChoose = Console.ReadLine().ToUpper();
|
||||
}
|
||||
else localChoose = choose[1].ToString();
|
||||
if (localChoose == "1") A3D.Processor(json);
|
||||
else if (localChoose == "2") AET.Processor(json);
|
||||
else if (localChoose == "3") DB .Processor(json);
|
||||
else if (localChoose == "4") DEX.Processor(json);
|
||||
else if (localChoose == "5") DIV.Processor();
|
||||
else if (localChoose == "6") MHD.Processor(json);
|
||||
else if (localChoose == "7") MOT.Processor(json);
|
||||
else if (localChoose == "8") STR.Processor(json);
|
||||
else if (localChoose == "9") TBL.Processor(json);
|
||||
else choose = localChoose;
|
||||
}
|
||||
else if (choose[0] == '7')
|
||||
{
|
||||
string localChoose = "";
|
||||
if (choose.Length == 1)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.Title = "F/F2/FT Converting Tools";
|
||||
ConsoleDesign(true);
|
||||
ConsoleDesign(" Choose converter:");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign("1. A3DA" );
|
||||
ConsoleDesign("2. Bloom" );
|
||||
ConsoleDesign("3. Color Correction");
|
||||
ConsoleDesign("4. DEX" );
|
||||
ConsoleDesign("5. DOF" );
|
||||
ConsoleDesign("6. Light" );
|
||||
ConsoleDesign("7. STR" );
|
||||
ConsoleDesign("8. VAG" );
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign("R. Return to Main Menu");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
localChoose = Console.ReadLine().ToUpper();
|
||||
}
|
||||
else localChoose = choose[1].ToString();
|
||||
if (localChoose == "1") A3D.Processor(json);
|
||||
else if (localChoose == "2") BLT.Processor(json);
|
||||
else if (localChoose == "3") CCT.Processor(json);
|
||||
else if (localChoose == "4") DEX.Processor(json);
|
||||
else if (localChoose == "5") DFT.Processor(json);
|
||||
else if (localChoose == "6") LIT.Processor(json);
|
||||
else if (localChoose == "7") STR.Processor(json);
|
||||
else if (localChoose == "8") VAG.Processor();
|
||||
else choose = localChoose;
|
||||
}
|
||||
else if (choose[0] == '8')
|
||||
{
|
||||
string localChoose = "";
|
||||
if (choose.Length == 1)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.Title = "X/XHD/VRFL Converting Tools";
|
||||
ConsoleDesign(true);
|
||||
ConsoleDesign(" Choose converter:");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign("1. A3DA");
|
||||
ConsoleDesign("2. Bloom" );
|
||||
ConsoleDesign("3. Color Correction");
|
||||
ConsoleDesign("4. DEX" );
|
||||
ConsoleDesign("5. DOF" );
|
||||
ConsoleDesign("6. Light" );
|
||||
ConsoleDesign("7. VAG" );
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign("R. Return to Main Menu");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
localChoose = Console.ReadLine().ToUpper();
|
||||
}
|
||||
else localChoose = choose[1].ToString();
|
||||
if (localChoose == "1") A3D.Processor(json);
|
||||
else if (localChoose == "2") BLT.Processor(json);
|
||||
else if (localChoose == "3") CCT.Processor(json);
|
||||
else if (localChoose == "4") DEX.Processor(json);
|
||||
else if (localChoose == "5") DFT.Processor(json);
|
||||
else if (localChoose == "6") LIT.Processor(json);
|
||||
else if (localChoose == "7") VAG.Processor();
|
||||
else choose = localChoose;
|
||||
}
|
||||
else if (choose[0] == '9')
|
||||
{
|
||||
string localChoose = "";
|
||||
if (choose.Length == 1)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.Title = "FT/M39 Converting Tools";
|
||||
ConsoleDesign(true);
|
||||
ConsoleDesign(" Choose converter:");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign("1. A3DA" );
|
||||
ConsoleDesign("2. AET" );
|
||||
ConsoleDesign("3. DEX" );
|
||||
ConsoleDesign("4. DIVA" );
|
||||
ConsoleDesign("5. MotHead" );
|
||||
ConsoleDesign("6. MOT" );
|
||||
ConsoleDesign("7. STR" );
|
||||
ConsoleDesign("8. Table" );
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign("R. Return to Main Menu");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
localChoose = Console.ReadLine().ToUpper();
|
||||
}
|
||||
else localChoose = choose[1].ToString();
|
||||
if (localChoose == "1") A3D.Processor(json);
|
||||
else if (localChoose == "2") AET.Processor(json);
|
||||
else if (localChoose == "3") DEX.Processor(json);
|
||||
else if (localChoose == "4") DIV.Processor();
|
||||
else if (localChoose == "5") MHD.Processor(json);
|
||||
else if (localChoose == "6") MOT.Processor(json);
|
||||
else if (localChoose == "7") STR.Processor(json);
|
||||
else if (localChoose == "8") TBL.Processor(json);
|
||||
else choose = localChoose;
|
||||
}
|
||||
else if (choose[0] == 'A')
|
||||
{
|
||||
Console.Title = json ? "MsgPack to JSON" : "JSON to MsgPack";
|
||||
Choose(1, json ? "mp" : "json", out string[] fileNames);
|
||||
foreach (string file in fileNames)
|
||||
if (json)
|
||||
{
|
||||
Console.Title = "MsgPack to JSON: " + Path.GetFileNameWithoutExtension(file);
|
||||
Path.RemoveExtension(file).ToJSON ();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Title = "JSON to MsgPack: " + Path.GetFileNameWithoutExtension(file);
|
||||
Path.RemoveExtension(file).ToMsgPack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Exit() => Environment.Exit(0);
|
||||
|
||||
public static void ConsoleDesign(string text, params string[] args)
|
||||
{
|
||||
text = string.Format(text, args);
|
||||
string Text = "X X";
|
||||
Text = Text.Remove(3) + text + Text.Remove(0, text.Length + 3);
|
||||
Console.WriteLine(Text);
|
||||
}
|
||||
|
||||
public static void ConsoleDesign(bool Fill)
|
||||
{
|
||||
if (Fill) Console.WriteLine("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
|
||||
else Console.WriteLine("X X");
|
||||
}
|
||||
|
||||
private static string GetArgs(string name, bool And, params string[] ext)
|
||||
{
|
||||
int L = ext.Length;
|
||||
string Out = (And ? "|" : "") + name + " files (";
|
||||
for (int i = 0; i < L; i++) { Out += "*." + ext[i]; if (i + 1 < L) Out += ", "; }
|
||||
Out += ")|";
|
||||
for (int i = 0; i < L; i++) { Out += "*." + ext[i]; if (i + 1 < L) Out += ";" ; }
|
||||
return Out;
|
||||
}
|
||||
|
||||
private static string GetArgs(string name, params string[] ext)
|
||||
{
|
||||
int L = ext.Length;
|
||||
string Out = name + " files (";
|
||||
for (int i = 0; i < L; i++) { Out += "*." + ext[i]; if (i + 1 < L) Out += ", "; }
|
||||
Out += ")|";
|
||||
for (int i = 0; i < L; i++) { Out += "*." + ext[i]; if (i + 1 < L) Out += ";" ; }
|
||||
return Out;
|
||||
}
|
||||
|
||||
public static string Choose(int code, string filetype, out string[] FileNames)
|
||||
{
|
||||
FileNames = new string[0];
|
||||
if (code == 1)
|
||||
{
|
||||
string mp = GetArgs("MessagePack", true, "mp" );
|
||||
string json = GetArgs("JSON" , true, "json");
|
||||
string bin = GetArgs("BIN" , true, "bin" );
|
||||
string wav = GetArgs("WAV" , true, "wav" );
|
||||
|
||||
string Filter = GetArgs("All", false, "*");
|
||||
if (filetype == "a3da") Filter = GetArgs("A3DA", "a3da", "farc", "json", "mp") +
|
||||
GetArgs("A3DA", true, "a3da") + GetArgs("FARC", true, "farc") + json + mp;
|
||||
else if (filetype == "bin" ) Filter = GetArgs("BIN" , "bin", "json", "mp") +
|
||||
bin + json + mp;
|
||||
else if (filetype == "blt" ) Filter = GetArgs("BLT" , "blt", "json", "mp") +
|
||||
GetArgs("BLT", true, "blt") + json + mp;
|
||||
else if (filetype == "bon" ) Filter = GetArgs("BON" , "bon", "bin", "json", "mp") +
|
||||
GetArgs("BON", true, "bon") + bin + json + mp;
|
||||
else if (filetype == "cct" ) Filter = GetArgs("CCT" , "cct", "json", "mp") +
|
||||
GetArgs("CCT", true, "cct") + json + mp;
|
||||
else if (filetype == "databank") Filter = GetArgs("DAT", "dat", "json", "mp") +
|
||||
GetArgs("DAT", true, "dat") + json + mp;
|
||||
else if (filetype == "dex" ) Filter = GetArgs("DEX" , "dex", "bin", "json", "mp") +
|
||||
GetArgs("DEX", true, "dex") + bin + json + mp;
|
||||
else if (filetype == "dft" ) Filter = GetArgs("DFT" , "dft", "json", "mp") +
|
||||
GetArgs("DFT", true, "dft") + json + mp;
|
||||
else if (filetype == "diva") Filter = GetArgs("DIVA", "diva", "wav") +
|
||||
GetArgs("DIVA", true, "diva") + wav;
|
||||
else if (filetype == "dsc" ) Filter = GetArgs("DSC" , "dsc", "json", "mp") +
|
||||
GetArgs("DSC", true, "dsc") + json + mp;
|
||||
else if (filetype == "dve" ) Filter = GetArgs("Particle", "dve", "farc", "json", "mp") +
|
||||
GetArgs("Particle", true, "dve") + GetArgs("Particle", true, "farc") + json + mp;
|
||||
else if (filetype == "farc") Filter = GetArgs("FARC", "farc");
|
||||
else if (filetype == "json") Filter = GetArgs("JSON", "json");
|
||||
else if (filetype == "igb" ) Filter = GetArgs("IGB", "igb");
|
||||
else if (filetype == "mgftxt") Filter = GetArgs("MGF2AFT txt", "txt");
|
||||
else if (filetype == "mhd" ) Filter = GetArgs("MotHead", "mhd", "bin", "json", "mp") +
|
||||
GetArgs("MotHead", true, "mhd") + bin + json + mp;
|
||||
else if (filetype == "mp" ) Filter = GetArgs("MessagePack", "mp");
|
||||
else if (filetype == "lit") Filter = GetArgs("LIT" , "lit", "json", "mp") +
|
||||
GetArgs("LIT", true, "lit") + json + mp;
|
||||
else if (filetype == "pvdb") Filter = GetArgs("PV DB / PV Field", "txt", "json", "mp") +
|
||||
GetArgs("PV DB / PV Field", true, "txt") + json + mp;
|
||||
else if (filetype == "str" ) Filter = GetArgs("STR" , "str", "bin", "json", "mp") +
|
||||
GetArgs("STR", true, "str") + bin + json + mp;
|
||||
else if (filetype == "tbl" ) Filter = GetArgs("Table" , "bin", "farc", "json", "mp") +
|
||||
bin + GetArgs("FARC Archives", true, "farc") + json + mp;
|
||||
else if (filetype == "vag" ) Filter = GetArgs("VAG" , "vag", "wav") +
|
||||
GetArgs("VAG", true, "vag") + wav;
|
||||
|
||||
using OpenFileDialog ofd = new OpenFileDialog { Filter = Filter,
|
||||
Multiselect = true, Title = "Choose file(s) to open:" };
|
||||
if (ofd.ShowDialog() == DialogResult.OK) FileNames = ofd.FileNames;
|
||||
}
|
||||
else if (code == 2)
|
||||
{
|
||||
string Return = "";
|
||||
using (OpenFileDialog ofd = new OpenFileDialog { ValidateNames = false,
|
||||
CheckFileExists = false, Filter = " | ", CheckPathExists = true,
|
||||
Title = "Choose any file in folder:", FileName = "Folder Selection." })
|
||||
if (ofd.ShowDialog() == DialogResult.OK) Return = Path.GetDirectoryName(ofd.FileName);
|
||||
return Return;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
using System.Reflection;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("PD_Tool")]
|
||||
[assembly: AssemblyDescription("A simple tool for working with Project Diva A/DT/F/AFT/F2/X/FT files")]
|
||||
[assembly: AssemblyDescription("A simple tool for working with Project Diva AC/DT/F/AFT/F2/X/XHD/FT/VRFL/M39 files")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("PD_Tool")]
|
||||
[assembly: AssemblyCopyright("Copyright korenkonder © 2017-2019")]
|
||||
[assembly: AssemblyCopyright("korenkonder (C) 2017-2023")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
|
||||
[assembly: AssemblyVersion("0.4.5.9")]
|
||||
[assembly: AssemblyFileVersion("0.4.5.9")]
|
||||
[assembly: AssemblyVersion("0.4.10.16")]
|
||||
[assembly: AssemblyFileVersion("0.4.10.16")]
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
using System;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdA3DA = KKdMainLib.A3DA;
|
||||
using KKdFARC = KKdMainLib.FARC;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
class A3D
|
||||
{
|
||||
public static void Processor(bool json)
|
||||
{
|
||||
Console.Title = "A3DA Converter";
|
||||
Program.Choose(1, "a3da", out string[] fileNames);
|
||||
if (fileNames.Length < 1) return;
|
||||
|
||||
bool mp = false;
|
||||
foreach (string file in fileNames)
|
||||
if (file.EndsWith(".mp") || file.EndsWith(".json") || file.EndsWith(".farc")) { mp = true; break; }
|
||||
|
||||
Format format = Format.NULL;
|
||||
string choose = "";
|
||||
Console.Clear();
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of format to export:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(" Tip: A3DC Opt - A3DC Optimization");
|
||||
Program.ConsoleDesign(" WARNING! CHECK RESULTS AFTER CONVERTING ");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. A3DA [DT/AC/F]");
|
||||
Program.ConsoleDesign("2. A3DC [DT/AC/F]");
|
||||
Program.ConsoleDesign("3. A3DA [AFT/FT/M39]");
|
||||
Program.ConsoleDesign("4. A3DC [AFT/FT/M39]");
|
||||
Program.ConsoleDesign("5. A3DC [F2]");
|
||||
Program.ConsoleDesign("6. A3DC [MGF]");
|
||||
Program.ConsoleDesign("7. A3DC [X]");
|
||||
Program.ConsoleDesign("8. A3DC [XHD/VRFL]");
|
||||
if (!mp) Program.ConsoleDesign($"9. {(json ? "JSON" : "MsgPack")}");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("X[Y] - X: option; Y: rounding in text (def. 9)");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
choose = Console.ReadLine().ToUpper();
|
||||
if (choose == null || choose.Length < 1)
|
||||
return;
|
||||
else if (choose[0] == '1') format = Format.DT ;
|
||||
else if (choose[0] == '2') format = Format.F ;
|
||||
else if (choose[0] == '3') format = Format.AFT;
|
||||
else if (choose[0] == '4') format = Format.AFT;
|
||||
else if (choose[0] == '5') format = Format.F2 ;
|
||||
else if (choose[0] == '6') format = Format.MGF;
|
||||
else if (choose[0] == '7') format = Format.X ;
|
||||
else if (choose[0] == '8') format = Format.XHD;
|
||||
else if (choose[0] == '9') format = Format.NULL;
|
||||
else return;
|
||||
|
||||
if (int.TryParse(choose.Substring(1), out int rounding))
|
||||
KKdA3DA.Rounding = rounding;
|
||||
else
|
||||
KKdA3DA.Rounding = 9;
|
||||
|
||||
int state;
|
||||
string filepath, ext;
|
||||
KKdA3DA a3da;
|
||||
KKdFARC farc;
|
||||
foreach (string file in fileNames)
|
||||
{
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "A3DA Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".farc")
|
||||
using (farc = new KKdFARC(file))
|
||||
FARCProcessor(farc, choose, format);
|
||||
else if (ext == ".a3da")
|
||||
using (a3da = new KKdA3DA())
|
||||
{
|
||||
state = a3da.A3DAReader(filepath);
|
||||
if (state == 1)
|
||||
if (choose[0] == '9') a3da.MsgPackWriter(filepath, json);
|
||||
else
|
||||
{
|
||||
a3da.Head.Format = format;
|
||||
File.WriteAllBytes(filepath + ".a3da", choose[0] == '1' || choose[0] == '3'
|
||||
? a3da.A3DAWriter() : a3da.A3DCWriter());
|
||||
}
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
using (a3da = new KKdA3DA())
|
||||
{
|
||||
a3da.MsgPackReader(filepath, ext == ".json");
|
||||
a3da.Head.Format = format;
|
||||
|
||||
File.WriteAllBytes(filepath + ".a3da", choose[0] == '1' || choose[0] == '3'
|
||||
? a3da.A3DAWriter() : a3da.A3DCWriter());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void FARCProcessor(KKdFARC farc, string choose, Format format)
|
||||
{
|
||||
if (!farc.HeaderReader() || !farc.HasFiles) return;
|
||||
|
||||
KKdList<string> list = KKdList<string>.New;
|
||||
for (int i = 0; i < farc.Files.Count; i++)
|
||||
{
|
||||
string file = farc.Files[i].Name.ToLower();
|
||||
if (!file.Contains("_div_") && file.EndsWith(".a3da")) list.Add(file);
|
||||
}
|
||||
|
||||
KKdList<string> A3DAlist = KKdList<string>.New;
|
||||
for (int i = 0; i < farc.Files.Count; i++)
|
||||
if (farc.Files[i].Name.ToLower().EndsWith(".a3da"))
|
||||
A3DAlist.Add(farc.Files[i].Name);
|
||||
|
||||
byte[] data = null;
|
||||
if (list.Count == A3DAlist.Count)
|
||||
{
|
||||
KKdA3DA a3da;
|
||||
for (int i = 0; i < A3DAlist.Count; i++)
|
||||
using (a3da = new KKdA3DA())
|
||||
{
|
||||
data = farc.FileReader(A3DAlist[i]);
|
||||
int state = a3da.A3DAReader(data);
|
||||
if (state == 1)
|
||||
{
|
||||
KKdFARC.FARCFile file = farc.Files[i];
|
||||
a3da.Head.Format = format;
|
||||
file.Data = choose[0] == '1' || choose[0] == '3'
|
||||
? a3da.A3DAWriter() : a3da.A3DCWriter();
|
||||
farc.Files[i] = file;
|
||||
}
|
||||
}
|
||||
farc.Save();
|
||||
return;
|
||||
}
|
||||
|
||||
KKdA3DA[] a3daArray;
|
||||
using (KKdList<KKdA3DA> a3daList = KKdList<KKdA3DA>.NewReserve(list.Count))
|
||||
{
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
KKdA3DA a3da;
|
||||
using (a3da = new KKdA3DA())
|
||||
{
|
||||
data = farc.FileReader(list[i]);
|
||||
int state = a3da.A3DAReader(data);
|
||||
if (state == 1) a3daList.Add(a3da);
|
||||
}
|
||||
}
|
||||
a3daArray = a3daList.ToArray();
|
||||
}
|
||||
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
if (a3daArray[i].Data.PlayControl.Div == null) continue;
|
||||
int div = a3daArray[i].Data.PlayControl.Div.Value;
|
||||
string filename = Path.RemoveExtension(list[i]);
|
||||
string ext = Path.GetExtension(list[i]).ToLower();
|
||||
KKdA3DA a3da;
|
||||
for (int i1 = 1; i1 < div; i1++)
|
||||
using (a3da = new KKdA3DA())
|
||||
{
|
||||
string file = filename + "_div_" + i1 + ext;
|
||||
data = farc.FileReader(file);
|
||||
int state = a3da.A3DAReader(data);
|
||||
if (state == 1) a3daArray[i].A3DAMerger(ref a3da.Data);
|
||||
}
|
||||
a3daArray[i].Data.PlayControl.Div = null;
|
||||
}
|
||||
|
||||
farc.Files.Capacity = 0;
|
||||
farc.Files.Capacity = list.Count;
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
KKdFARC.FARCFile file = default;
|
||||
file.Name = list[i];
|
||||
a3daArray[i].Head.Format = format;
|
||||
file.Data = choose[0] == '1'|| choose[0] == '3'
|
||||
? a3daArray[i].A3DAWriter() : a3daArray[i].A3DCWriter();
|
||||
farc.Files.Add(file);
|
||||
}
|
||||
farc.Save();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
public class AET
|
||||
{
|
||||
public static void Processor(bool json)
|
||||
{
|
||||
Console.Title = "AET Converter";
|
||||
Program.Choose(1, "bin", out string[] fileNames);
|
||||
if (fileNames.Length < 1) return;
|
||||
|
||||
string filepath, ext;
|
||||
Aet aet;
|
||||
foreach (string file in fileNames)
|
||||
using (aet = new Aet())
|
||||
{
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "AET Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".bin")
|
||||
{
|
||||
aet. AETReader(filepath);
|
||||
aet.MsgPackWriter(filepath, json);
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
{
|
||||
aet.MsgPackReader(filepath, ext == ".json");
|
||||
aet. AETWriter(filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using KKdMainLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
public class BLT
|
||||
{
|
||||
public static void Processor(bool json)
|
||||
{
|
||||
Console.Title = "Bloom Converter";
|
||||
Program.Choose(1, "blt", out string[] fileNames);
|
||||
if (fileNames.Length < 1) return;
|
||||
|
||||
bool bloom = false;
|
||||
foreach (string file in fileNames)
|
||||
if (file.EndsWith(".blt")) { bloom = true; break; }
|
||||
|
||||
string choose = "";
|
||||
if (bloom)
|
||||
{
|
||||
Console.Clear();
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of format to export:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. JSON");
|
||||
Program.ConsoleDesign("2. TXT");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
choose = Console.ReadLine().ToUpper();
|
||||
}
|
||||
|
||||
string filepath, ext;
|
||||
Bloom blt;
|
||||
foreach (string file in fileNames)
|
||||
using (blt = new Bloom())
|
||||
{
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "Bloom Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".blt")
|
||||
{
|
||||
blt.BLTReader(filepath);
|
||||
if (choose == "2" && !blt.IsX)
|
||||
blt.TXTWriter(filepath);
|
||||
else
|
||||
blt.MsgPackWriter(filepath, json);
|
||||
}
|
||||
else if (ext == ".json" || ext == ".mp")
|
||||
{
|
||||
blt.MsgPackReader(filepath, json);
|
||||
blt.BLTWriter(filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using KKdMainLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
public class CCT
|
||||
{
|
||||
public static void Processor(bool json)
|
||||
{
|
||||
Console.Title = "Color Correction Converter";
|
||||
Program.Choose(1, "cct", out string[] fileNames);
|
||||
if (fileNames.Length < 1) return;
|
||||
|
||||
bool cc = false;
|
||||
foreach (string file in fileNames)
|
||||
if (file.EndsWith(".cct")) { cc = true; break; }
|
||||
|
||||
string choose = "";
|
||||
if (cc)
|
||||
{
|
||||
Console.Clear();
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of format to export:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. JSON");
|
||||
Program.ConsoleDesign("2. TXT");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
choose = Console.ReadLine().ToUpper();
|
||||
}
|
||||
|
||||
string filepath, ext;
|
||||
ColorCorrection cct;
|
||||
foreach (string file in fileNames)
|
||||
using (cct = new ColorCorrection())
|
||||
{
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "Color Correction Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".cct")
|
||||
{
|
||||
cct.CCTReader(filepath);
|
||||
if (choose == "2" && !cct.IsX)
|
||||
cct.TXTWriter(filepath);
|
||||
else
|
||||
cct.MsgPackWriter(filepath, json);
|
||||
}
|
||||
else if (ext == ".json" || ext == ".mp")
|
||||
{
|
||||
cct.MsgPackReader(filepath, json);
|
||||
cct.CCTWriter(filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
public class DB
|
||||
{
|
||||
public static void Processor(bool json)
|
||||
{
|
||||
Console.Title = "DataBank Converter";
|
||||
Program.Choose(1, "databank", out string[] fileNames);
|
||||
if (fileNames.Length < 1) return;
|
||||
|
||||
bool mp = true;
|
||||
foreach (string file in fileNames)
|
||||
if (file.EndsWith(".mp" )) { mp = false; break; }
|
||||
else if (file.EndsWith(".json")) { mp = false; break; }
|
||||
|
||||
uint timestamp = (uint)((DateTime.Now.Ticks - 621355968000000000) / 10000000);
|
||||
string[] file_split;
|
||||
string filepath, ext;
|
||||
KKdMainLib.DataBank db;
|
||||
foreach (string file in fileNames)
|
||||
{
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
string filename = Path.GetFileNameWithoutExtension(file);
|
||||
file_split = filename.Split('_');
|
||||
using (db = new KKdMainLib.DataBank())
|
||||
{
|
||||
if (file_split.Length == 5 && ext == ".dat" && mp)
|
||||
{
|
||||
filepath = file.Replace(filename + ".dat", "");
|
||||
Console.Title = "DataBank Converter: " + filename;
|
||||
db. DBReader(file);
|
||||
db.MsgPackWriter(filepath + file_split[0] + "_" +
|
||||
file_split[1] + "_" + file_split[2], json);
|
||||
}
|
||||
else if (ext == ".bin" && mp)
|
||||
{
|
||||
filepath = file.Replace(".bin", "");
|
||||
Console.Title = "DataBank Converter: " + filename;
|
||||
db. DBReader(file);
|
||||
db.MsgPackWriter(filepath, json);
|
||||
}
|
||||
else if ((ext == ".mp" || ext == ".json") && !mp)
|
||||
{
|
||||
Console.Title = "DataBank Converter: " + filename;
|
||||
db.MsgPackReader(filepath, json);
|
||||
db. DBWriter(filepath, timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdDEX = KKdMainLib.DEX;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
public class DEX
|
||||
{
|
||||
public static void Processor(bool json)
|
||||
{
|
||||
Console.Title = "DEX Converter";
|
||||
Program.Choose(1, "dex", out string[] fileNames);
|
||||
if (fileNames.Length < 1) return;
|
||||
|
||||
bool mp = true;
|
||||
bool _json = true;
|
||||
foreach (string file in fileNames)
|
||||
if (file.EndsWith(".mp" )) { mp = false; break; }
|
||||
else if (file.EndsWith(".json")) { _json = false; break; }
|
||||
|
||||
Console.Clear();
|
||||
string choose = "";
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of exporting file:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. F/AFT/FT/M39 PS3/PS4/PSV/AC/NSW");
|
||||
Program.ConsoleDesign("2. F2 PS3/PSV");
|
||||
Program.ConsoleDesign("3. X PS4/PSV");
|
||||
if ( mp && !json) Program.ConsoleDesign("9. MessagePack");
|
||||
if (_json && json) Program.ConsoleDesign("9. JSON");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
choose = Console.ReadLine().ToUpper();
|
||||
|
||||
Format format = Format.NULL;
|
||||
if (choose == "1") format = Format.F ;
|
||||
else if (choose == "2") format = Format.F2;
|
||||
else if (choose == "3") format = Format.X ;
|
||||
else if (choose == "9" && mp && _json) format = Format.NULL;
|
||||
else return;
|
||||
|
||||
string filepath, ext;
|
||||
KKdDEX dex;
|
||||
foreach (string file in fileNames)
|
||||
using (dex = new KKdDEX())
|
||||
{
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "DEX Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".bin" || ext == ".dex") dex. DEXReader(filepath, ext );
|
||||
else dex.MsgPackReader(filepath, json);
|
||||
|
||||
if (format > Format.NULL) dex. DEXWriter(filepath, format);
|
||||
else dex.MsgPackWriter(filepath, json);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using KKdMainLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
public class DFT
|
||||
{
|
||||
public static void Processor(bool json)
|
||||
{
|
||||
Console.Title = "DOF Converter";
|
||||
Program.Choose(1, "dft", out string[] fileNames);
|
||||
if (fileNames.Length < 1) return;
|
||||
|
||||
bool cc = false;
|
||||
foreach (string file in fileNames)
|
||||
if (file.EndsWith(".dft")) { cc = true; break; }
|
||||
|
||||
string choose = "";
|
||||
if (cc)
|
||||
{
|
||||
Console.Clear();
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of format to export:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. JSON");
|
||||
Program.ConsoleDesign("2. TXT");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
choose = Console.ReadLine().ToUpper();
|
||||
}
|
||||
|
||||
string filepath, ext;
|
||||
DOF dft;
|
||||
foreach (string file in fileNames)
|
||||
using (dft = new DOF())
|
||||
{
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "DOF Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".dft")
|
||||
{
|
||||
dft.DFTReader(filepath);
|
||||
if (choose == "2" && !dft.IsX)
|
||||
dft.TXTWriter(filepath);
|
||||
else
|
||||
dft.MsgPackWriter(filepath, json);
|
||||
}
|
||||
else if (ext == ".json" || ext == ".mp")
|
||||
{
|
||||
dft.MsgPackReader(filepath, json);
|
||||
dft.DFTWriter(filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user