Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
@@ -1,5 +1,6 @@
|
||||
.vs
|
||||
build
|
||||
packages
|
||||
KKdBaseLib/bin
|
||||
KKdBaseLib/obj
|
||||
KKdMainLib/bin
|
||||
|
||||
+38
-15
@@ -1,28 +1,51 @@
|
||||
using KKdBaseLib.A3DA;
|
||||
using KKdBaseLib.Auth3D;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct A3DAKey
|
||||
{
|
||||
public KeyType Type;
|
||||
public int Unk04;
|
||||
public float Value;
|
||||
public float MaxFrames;
|
||||
public EPType EPTypePre;
|
||||
public EPType EPTypePost;
|
||||
public float FDBSaE; //Frame Difference Between Start and End
|
||||
public float VDBSaE; //Value Difference Between Start and End
|
||||
public int Unk1C;
|
||||
public int Unk20;
|
||||
public int Unk24;
|
||||
public int Unk28;
|
||||
public int Unk2C;
|
||||
public int Unk30;
|
||||
public int Unk34;
|
||||
public int Length;
|
||||
public int Unk3C;
|
||||
public int DataOffset; //Used only in-game and points to KFT3 Array
|
||||
public int Unk44;
|
||||
public 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,164 +0,0 @@
|
||||
namespace KKdBaseLib.Aet
|
||||
{
|
||||
public struct AetHeader
|
||||
{
|
||||
public Pointer<AetData>[] Data;
|
||||
}
|
||||
|
||||
public struct AetData
|
||||
{
|
||||
public Pointer<string> Name;
|
||||
public float StartFrame;
|
||||
public float EndFrame;
|
||||
public float FrameRate;
|
||||
public uint BackColor;
|
||||
public uint Width;
|
||||
public uint Height;
|
||||
public Pointer<Vector2<CountPointer<KFT2>>> Camera;
|
||||
public CountPointer<AetComposition > Compositions ;
|
||||
public CountPointer<AetSurface> Surfaces;
|
||||
public CountPointer<AetSoundEffect > SoundEffects ;
|
||||
}
|
||||
|
||||
public struct AetComposition
|
||||
{
|
||||
public int P;
|
||||
public int C { get => E != null ? E.Length : 0;
|
||||
set => E = value > -1 ? new AetLayer[value] : null; }
|
||||
|
||||
public int O;
|
||||
public AetLayer[] E;
|
||||
|
||||
public override string ToString() => "Count: " + C;
|
||||
}
|
||||
|
||||
|
||||
public struct AetLayer
|
||||
{
|
||||
public int ID;
|
||||
public int Offset;
|
||||
public Pointer<string> Name;
|
||||
public float StartFrame;
|
||||
public float EndFrame;
|
||||
public float StartOffset;
|
||||
public float PlaybackSpeed;
|
||||
public AetLayerFlags Flags;
|
||||
public byte Pad;
|
||||
public AetLayerType Type;
|
||||
public int DataID;
|
||||
public int ParentLayer;
|
||||
public CountPointer<AetMarker> Marker;
|
||||
public Pointer<AnimationData> Data;
|
||||
public Pointer<AudioData> ExtraData;
|
||||
|
||||
public enum AetLayerFlags : ushort
|
||||
{
|
||||
Visible = 0b0000000000000001,
|
||||
Audible = 0b0000000000000010,
|
||||
Unk2 = 0b0000000000000100,
|
||||
Unk3 = 0b0000000000001000,
|
||||
Unk4 = 0b0000000000010000,
|
||||
AudioRealted = 0b0000000000100000,
|
||||
Unk6 = 0b0000000001000000,
|
||||
SpriteFrames = 0b0000000010000000,
|
||||
Unk8 = 0b0000000100000000,
|
||||
Unk9 = 0b0000001000000000,
|
||||
Unk10 = 0b0000010000000000,
|
||||
Unk11 = 0b0000100000000000,
|
||||
Unk12 = 0b0001000000000000,
|
||||
Unk13 = 0b0010000000000000,
|
||||
Unk14 = 0b0100000000000000,
|
||||
Unk15 = 0b1000000000000000,
|
||||
}
|
||||
|
||||
public enum AetLayerType : byte
|
||||
{
|
||||
Nop = 0,
|
||||
Pic = 1,
|
||||
Aif = 2,
|
||||
Eff = 3,
|
||||
}
|
||||
|
||||
public override string ToString() => $"ID: {ID}; Name: {Name.V}; Type: {Type}" +
|
||||
( DataID > -1 ? $"; Data ID: " + $"{ DataID}" : "") +
|
||||
(ParentLayer > -1 ? $"; Parent Object ID: {ParentLayer}" : "");
|
||||
}
|
||||
|
||||
public struct AetMarker
|
||||
{
|
||||
public float Frame;
|
||||
public Pointer<string> Name;
|
||||
}
|
||||
|
||||
public struct AnimationData
|
||||
{
|
||||
public BlendMode Mode;
|
||||
public byte Padding0;
|
||||
public bool UseTextureMask;
|
||||
public byte Padding1;
|
||||
public CountPointer<KFT2> OriginX;
|
||||
public CountPointer<KFT2> OriginY;
|
||||
public CountPointer<KFT2> PositionX;
|
||||
public CountPointer<KFT2> PositionY;
|
||||
public CountPointer<KFT2> Rotation;
|
||||
public CountPointer<KFT2> ScaleX;
|
||||
public CountPointer<KFT2> ScaleY;
|
||||
public CountPointer<KFT2> Opacity;
|
||||
public Pointer<Perspective> Persp;
|
||||
|
||||
public enum BlendMode : byte
|
||||
{
|
||||
Alpha = 3,
|
||||
Additive = 5,
|
||||
DstColorZero = 6,
|
||||
SrcAlphaOneMinusSrcColor = 7,
|
||||
Transparent = 8,
|
||||
}
|
||||
|
||||
public struct Perspective
|
||||
{
|
||||
public CountPointer<KFT2> Unk1 ;
|
||||
public CountPointer<KFT2> Unk2 ;
|
||||
public CountPointer<KFT2> RotReturnX;
|
||||
public CountPointer<KFT2> RotReturnY;
|
||||
public CountPointer<KFT2> RotReturnZ;
|
||||
public CountPointer<KFT2> RotationX;
|
||||
public CountPointer<KFT2> RotationY;
|
||||
public CountPointer<KFT2> ScaleZ;
|
||||
}
|
||||
}
|
||||
|
||||
public struct AudioData
|
||||
{
|
||||
public CountPointer<KFT2> Data0;
|
||||
public CountPointer<KFT2> Data1;
|
||||
public CountPointer<KFT2> Data2;
|
||||
public CountPointer<KFT2> Data3;
|
||||
}
|
||||
|
||||
public struct AetSurface
|
||||
{
|
||||
public int O;
|
||||
public uint Color;
|
||||
public ushort Width;
|
||||
public ushort Height;
|
||||
public float Frames;
|
||||
public CountPointer<AetSpriteIdentifier> Sprites;
|
||||
|
||||
public override string ToString() => $"Width: {Width}; Height: {Height}; Color: {Color.ToString("X2")}";
|
||||
}
|
||||
|
||||
public struct AetSpriteIdentifier
|
||||
{
|
||||
public Pointer<string> Name;
|
||||
public uint ID;
|
||||
|
||||
public override string ToString() => $"ID: {ID}; Name: {Name}";
|
||||
}
|
||||
|
||||
public struct AetSoundEffect
|
||||
{
|
||||
public int O;
|
||||
public uint Unk;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace KKdBaseLib.A3DA
|
||||
namespace KKdBaseLib.Auth3D
|
||||
{
|
||||
public struct A3DAData
|
||||
public struct Data
|
||||
{
|
||||
public string[] Motion;
|
||||
public string[] ObjectList;
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
public struct _
|
||||
{
|
||||
public int? CompressF16;
|
||||
public CompressF16 CompressF16;
|
||||
public string FileName;
|
||||
public string PropertyVersion;
|
||||
public string ConverterVersion;
|
||||
@@ -35,18 +35,19 @@
|
||||
|
||||
public struct Ambient
|
||||
{
|
||||
public string Name;
|
||||
public Vector4<Key> LightDiffuse;
|
||||
public Vector4<Key> RimLightDiffuse;
|
||||
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 AutoExposure;
|
||||
public Key? Gamma;
|
||||
public Key? Exposure;
|
||||
public Key? Saturate;
|
||||
public Key? GammaRate;
|
||||
public Key? ExposureRate;
|
||||
public Key? AutoExposure;
|
||||
}
|
||||
|
||||
public struct CameraRoot
|
||||
@@ -57,7 +58,7 @@
|
||||
|
||||
public struct ViewPoint
|
||||
{
|
||||
public bool? FOVHorizontal;
|
||||
public bool FOVHorizontal;
|
||||
public float? Aspect;
|
||||
public float? CameraApertureH;
|
||||
public float? CameraApertureW;
|
||||
@@ -96,40 +97,70 @@
|
||||
public struct Fog
|
||||
{
|
||||
public int? Id;
|
||||
public Key End;
|
||||
public Key Start;
|
||||
public Key Density;
|
||||
public Vector4<Key> Diffuse;
|
||||
public Key? End;
|
||||
public Key? Start;
|
||||
public Key? Density;
|
||||
public Vec4<Key?>? Diffuse;
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
{
|
||||
Null = 0,
|
||||
Value = 1,
|
||||
Lerp = 2,
|
||||
None = 0,
|
||||
Static = 1,
|
||||
Linear = 2,
|
||||
Hermite = 3,
|
||||
Hold = 4,
|
||||
}
|
||||
|
||||
public enum EPType : int
|
||||
{
|
||||
EP_1 = 1,
|
||||
EP_2 = 2,
|
||||
EP_3 = 3,
|
||||
}
|
||||
|
||||
public struct Key
|
||||
{
|
||||
public KeyType? Type;
|
||||
public int Length;
|
||||
public KeyType Type;
|
||||
public int? BinOffset;
|
||||
public EPType EPTypePre;
|
||||
public EPType EPTypePost;
|
||||
public float? Max;
|
||||
public float? Value;
|
||||
public float Value;
|
||||
public RawD 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 RawD
|
||||
{
|
||||
public int KeyType;
|
||||
@@ -137,58 +168,6 @@
|
||||
public string ValueType;
|
||||
public string[] ValueList;
|
||||
}
|
||||
|
||||
public static Vector3<A3DAKey> ToA3DAKey(Vector3<Key> k) =>
|
||||
new Vector3<A3DAKey> { X = (A3DAKey)k.X, Y = (A3DAKey)k.Y, Z = (A3DAKey)k.Z };
|
||||
public static Vector3<Key> ToKey(Vector3<A3DAKey> k) =>
|
||||
new Vector3<Key> { X = (Key)k.X, Y = (Key)k.Y, Z = (Key)k.Z };
|
||||
|
||||
public static explicit operator Key(A3DAKey k)
|
||||
{
|
||||
Key key = default;
|
||||
key.EPTypePost = k.EPTypePost;
|
||||
key.EPTypePre = k.EPTypePre;
|
||||
key.Max = k.MaxFrames;
|
||||
if (k.Length > 1)
|
||||
{
|
||||
key.Type = k.Type;
|
||||
key.Length = k.Length;
|
||||
key.Keys = k.Keys;
|
||||
}
|
||||
else if (k.Length == 1)
|
||||
{
|
||||
key.Type = KeyType.Value;
|
||||
key.Value = k.Keys[0].V;
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
public static explicit operator A3DAKey(Key k)
|
||||
{
|
||||
A3DAKey key = default;
|
||||
key.EPTypePost = k.EPTypePost;
|
||||
key.EPTypePre = k.EPTypePre;
|
||||
key.MaxFrames = k.Max ?? 0;
|
||||
if (k.Type != null && k.Length > 1)
|
||||
{
|
||||
key.Type = k.Type.Value;
|
||||
key.Length = k.Length;
|
||||
key.Keys = k.Keys;
|
||||
key.FDBSaE = k.Keys[k.Length - 1].F - k.Keys[0].F;
|
||||
key.VDBSaE = k.Keys[k.Length - 1].V - k.Keys[0].V;
|
||||
}
|
||||
else
|
||||
{
|
||||
key.Length = 1;
|
||||
key.Keys = new KFT3[1];
|
||||
if (k.Length == 1)
|
||||
{
|
||||
key.Type = KeyType.Value;
|
||||
key.Keys[0].V = k.Value ?? 0;
|
||||
}
|
||||
}
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
public struct Light
|
||||
@@ -196,34 +175,41 @@
|
||||
public int? Id;
|
||||
public string Name;
|
||||
public string Type;
|
||||
public Vector4<Key> Ambient;
|
||||
public Vector4<Key> Diffuse;
|
||||
public Vector4<Key> Specular;
|
||||
public Vector4<Key> Incandescence;
|
||||
public 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?>? Incandescence;
|
||||
public ModelTransform Position;
|
||||
public ModelTransform SpotDirection;
|
||||
}
|
||||
|
||||
public struct MaterialList
|
||||
{
|
||||
public ulong HashName;
|
||||
public string Name;
|
||||
public string HashName;
|
||||
public Key GlowIntensity;
|
||||
public Vector4<Key> BlendColor;
|
||||
public Vector4<Key> Incandescence;
|
||||
public Vec4<Key?>? BlendColor;
|
||||
public Vec4<Key?>? Incandescence;
|
||||
}
|
||||
|
||||
public struct MObjectHRC
|
||||
{
|
||||
public string Name;
|
||||
public Node[] Node;
|
||||
public Vector3<float?> JointOrient;
|
||||
public Vec3<float?> JointOrient;
|
||||
public Instance[] Instances;
|
||||
public ModelTransform MT;
|
||||
|
||||
public struct Instance
|
||||
{
|
||||
public int? Shadow;
|
||||
public bool? Shadow;
|
||||
public string Name;
|
||||
public string UIDName;
|
||||
public ModelTransform MT;
|
||||
@@ -235,9 +221,9 @@
|
||||
public bool Writed;
|
||||
public int? BinOffset;
|
||||
public Key Visibility;
|
||||
public Vector3<Key> Rot;
|
||||
public Vector3<Key> Scale;
|
||||
public Vector3<Key> Trans;
|
||||
public Vec3<Key> Rot;
|
||||
public Vec3<Key> Scale;
|
||||
public Vec3<Key> Trans;
|
||||
}
|
||||
|
||||
public struct Node
|
||||
@@ -249,8 +235,10 @@
|
||||
|
||||
public struct Object
|
||||
{
|
||||
public int? MorphOffset;
|
||||
public float? PatOffset;
|
||||
public float? MorphOffset;
|
||||
public string Name;
|
||||
public string Pat;
|
||||
public string Morph;
|
||||
public string UIDName;
|
||||
public string ParentName;
|
||||
@@ -268,40 +256,44 @@
|
||||
public struct TextureTransform
|
||||
{
|
||||
public string Name;
|
||||
public Key Rotate;
|
||||
public Key RotateFrame;
|
||||
public Vector2<Key> Offset;
|
||||
public Vector2<Key> Repeat;
|
||||
public Vector2<Key> Coverage;
|
||||
public Vector2<Key> TranslateFrame;
|
||||
public 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 float? Shadow;
|
||||
public bool? Shadow;
|
||||
public string Name;
|
||||
public string UIDName;
|
||||
public Node[] Node;
|
||||
public Vector3<float?> JointOrient;
|
||||
public Vec3<float?> JointOrient;
|
||||
}
|
||||
|
||||
public struct PlayControl
|
||||
{
|
||||
public float? Begin;
|
||||
public float? Div;
|
||||
public float? FPS;
|
||||
public float? Offset;
|
||||
public float? Size;
|
||||
public int Begin;
|
||||
public int? Div;
|
||||
public int FPS;
|
||||
public int? Offset;
|
||||
public int Size;
|
||||
}
|
||||
|
||||
public struct PostProcess
|
||||
{
|
||||
public Key LensFlare;
|
||||
public Key LensGhost;
|
||||
public Key LensShaft;
|
||||
public Vector4<Key> Ambient;
|
||||
public Vector4<Key> Diffuse;
|
||||
public Vector4<Key> Specular;
|
||||
public Key? LensFlare;
|
||||
public Key? LensGhost;
|
||||
public Key? LensShaft;
|
||||
public Vec4<Key?>? Ambient;
|
||||
public Vec4<Key?>? Diffuse;
|
||||
public Vec4<Key?>? Specular;
|
||||
}
|
||||
}
|
||||
+43
-10
@@ -1,4 +1,4 @@
|
||||
//Original research by Samyuu
|
||||
//Original research by Samyuu
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
@@ -39,26 +39,59 @@ namespace KKdBaseLib
|
||||
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0,
|
||||
};
|
||||
|
||||
public static ushort CalculateChecksum(this byte[] data)
|
||||
public static ushort CalculateChecksum(byte[] data,
|
||||
int offset = 0, ushort seed = 0xFFFF)
|
||||
{
|
||||
ushort result = 0xFFFF;
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
int length = data.Length;
|
||||
ushort result = seed;
|
||||
for (int i = offset; i < length; i++)
|
||||
result = (ushort)(ChecksumLookupTable[(result >> 8) ^ data[i]] ^ (result << 8));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static uint CalculateChecksumUInt(this byte[] data)
|
||||
public static uint CalculateChecksumU32(byte[] data,
|
||||
int offset = 0, uint seed = 0xFFFFFFFF)
|
||||
{
|
||||
uint result = 0xFFFFFFFF;
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
int length = data.Length;
|
||||
uint result = seed;
|
||||
for (int i = offset; i < length; i++)
|
||||
result = ChecksumLookupTable[(byte)(result >> 8) ^ data[i]] ^ (result << 8);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ulong CalculateChecksumULong(this byte[] data)
|
||||
public static ulong CalculateChecksumU64(byte[] data,
|
||||
int offset = 0, ulong seed = 0xFFFFFFFFFFFFFFFF)
|
||||
{
|
||||
ulong result = 0xFFFFFFFFFFFFFFFF;
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
int length = data.Length;
|
||||
ulong result = seed;
|
||||
for (int i = offset; i < length; i++)
|
||||
result = ChecksumLookupTable[(byte)(result >> 8) ^ data[i]] ^ (result << 8);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static unsafe ushort CalculateChecksum(byte* data,
|
||||
int length, int offset = 0, ushort seed = 0xFFFF)
|
||||
{
|
||||
ushort result = seed;
|
||||
for (int i = offset; i < length; i++)
|
||||
result = (ushort)(ChecksumLookupTable[(result >> 8) ^ data[i]] ^ (result << 8));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static unsafe uint CalculateChecksumU32(byte* data,
|
||||
int length, int offset = 0, uint seed = 0xFFFFFFFF)
|
||||
{
|
||||
uint result = seed;
|
||||
for (int i = offset; i < length; i++)
|
||||
result = ChecksumLookupTable[(byte)(result >> 8) ^ data[i]] ^ (result << 8);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static unsafe ulong CalculateChecksumU64(byte* data,
|
||||
int length, int offset = 0, ulong seed = 0xFFFFFFFFFFFFFFFF)
|
||||
{
|
||||
ulong result = seed;
|
||||
for (int i = offset; i < length; i++)
|
||||
result = ChecksumLookupTable[(byte)(result >> 8) ^ data[i]] ^ (result << 8);
|
||||
return result;
|
||||
}
|
||||
|
||||
+154
-113
@@ -1,17 +1,13 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public static unsafe class Extensions
|
||||
{
|
||||
private const double RadPi = 180 / Math.PI;
|
||||
public static double ToDegrees(this double val) => val * RadPi;
|
||||
public static double ToRadians(this double val) => val / RadPi;
|
||||
|
||||
public static double Acos (this double d ) => Math.Acos (d );
|
||||
public static double Asin (this double d ) => Math.Asin (d );
|
||||
public static double Atan (this double d ) => Math.Atan (d );
|
||||
public static double Aсtg (this double d ) => 1 / Math.Atan (d );
|
||||
public static double 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 );
|
||||
@@ -30,7 +26,6 @@ namespace KKdBaseLib
|
||||
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 );
|
||||
@@ -38,13 +33,10 @@ namespace KKdBaseLib
|
||||
public static double Pow (this double x , double y ) => Math.Pow (x , y );
|
||||
public static double Round(this double val , int d ) => Math.Round(val , d );
|
||||
|
||||
public static float ToDegrees(this float val) => (float)(val * RadPi);
|
||||
public static float ToRadians(this float val) => (float)(val / RadPi);
|
||||
|
||||
public static float Acos (this float d ) => (float) Math.Acos (d ) ;
|
||||
public static float Asin (this float d ) => (float) Math.Asin (d ) ;
|
||||
public static float Atan (this float d ) => (float) Math.Atan (d ) ;
|
||||
public static float Aсtg (this float d ) => (float)(1 / Math.Atan (d ));
|
||||
public static float 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 ) ;
|
||||
@@ -62,7 +54,6 @@ namespace KKdBaseLib
|
||||
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 );
|
||||
@@ -70,7 +61,7 @@ namespace KKdBaseLib
|
||||
public static float Pow (this float x , float y ) => (float)Math.Pow (x , y );
|
||||
public static float Round(this float val , int d ) => (float)Math.Round(val , d );
|
||||
|
||||
public static void FC( ref double Value) =>
|
||||
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) =>
|
||||
@@ -89,17 +80,36 @@ namespace KKdBaseLib
|
||||
((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; }
|
||||
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; }
|
||||
@@ -116,39 +126,65 @@ namespace KKdBaseLib
|
||||
{ if (isBE) { for (byte i = 0; i < 8; i++) { buf[i] = (byte)le; le >>= 8; } le = 0;
|
||||
for (byte i = 0; i < 8; i++) { le |= buf[i]; if (i < 7) le <<= 8; } } return le; }
|
||||
|
||||
public static short TI16(this byte[] arr)
|
||||
{ short val; fixed (byte* ptr = arr) val = *( short*)ptr; return val; }
|
||||
public static ushort TU16(this byte[] arr)
|
||||
{ ushort val; fixed (byte* ptr = arr) val = *(ushort*)ptr; return val; }
|
||||
public static int TI32(this byte[] arr)
|
||||
{ int val; fixed (byte* ptr = arr) val = *( int*)ptr; return val; }
|
||||
public static uint TU32(this byte[] arr)
|
||||
{ uint val; fixed (byte* ptr = arr) val = *( uint*)ptr; return val; }
|
||||
public static long TI64(this byte[] arr)
|
||||
{ long val; fixed (byte* ptr = arr) val = *( long*)ptr; return val; }
|
||||
public static ulong TU64(this byte[] arr)
|
||||
{ ulong val; fixed (byte* ptr = arr) val = *( ulong*)ptr; return val; }
|
||||
public static float TF32(this byte[] arr)
|
||||
{ float val; fixed (byte* ptr = arr) val = *( float*)ptr; return val; }
|
||||
public static double TF64(this byte[] arr)
|
||||
{ double val; fixed (byte* ptr = arr) val = *(double*)ptr; return val; }
|
||||
public static 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, short val)
|
||||
{ fixed (byte* ptr = arr) *( short*)ptr = val; }
|
||||
public static void GBy(this byte[] arr, ushort val)
|
||||
{ fixed (byte* ptr = arr) *(ushort*)ptr = val; }
|
||||
public static void GBy(this byte[] arr, int val)
|
||||
{ fixed (byte* ptr = arr) *( int*)ptr = val; }
|
||||
public static void GBy(this byte[] arr, uint val)
|
||||
{ fixed (byte* ptr = arr) *( uint*)ptr = val; }
|
||||
public static void GBy(this byte[] arr, long val)
|
||||
{ fixed (byte* ptr = arr) *( long*)ptr = val; }
|
||||
public static void GBy(this byte[] arr, ulong val)
|
||||
{ fixed (byte* ptr = arr) *( ulong*)ptr = val; }
|
||||
public static void GBy(this byte[] arr, float val)
|
||||
{ fixed (byte* ptr = arr) *( float*)ptr = val; }
|
||||
public static void GBy(this byte[] arr, double val)
|
||||
{ fixed (byte* ptr = arr) *(double*)ptr = val; }
|
||||
public static 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 ?
|
||||
@@ -203,51 +239,12 @@ namespace KKdBaseLib
|
||||
public static double ToF64(this long i) => *(double*)&i;
|
||||
public static double ToF64(this ulong i) => *(double*)&i;
|
||||
|
||||
public static string ToString(this int d, bool BE) =>
|
||||
public static string ToS(this int d, bool BE) =>
|
||||
BitConverter.GetBytes(d.E(BE)).ToASCII();
|
||||
|
||||
public static sbyte* GetPtr(this sbyte[] array)
|
||||
{ fixed ( sbyte* tempPtr = array) return tempPtr; }
|
||||
public static byte* GetPtr(this byte[] array)
|
||||
{ fixed ( byte* tempPtr = array) return tempPtr; }
|
||||
public static short* GetPtr(this short[] array)
|
||||
{ fixed ( short* tempPtr = array) return tempPtr; }
|
||||
public static ushort* GetPtr(this ushort[] array)
|
||||
{ fixed (ushort* tempPtr = array) return tempPtr; }
|
||||
public static int* GetPtr(this int[] array)
|
||||
{ fixed ( int* tempPtr = array) return tempPtr; }
|
||||
public static uint* GetPtr(this uint[] array)
|
||||
{ fixed ( uint* tempPtr = array) return tempPtr; }
|
||||
public static long* GetPtr(this long[] array)
|
||||
{ fixed ( long* tempPtr = array) return tempPtr; }
|
||||
public static ulong* GetPtr(this ulong[] array)
|
||||
{ fixed ( ulong* tempPtr = array) return tempPtr; }
|
||||
public static float* GetPtr(this float[] array)
|
||||
{ fixed ( float* tempPtr = array) return tempPtr; }
|
||||
public static double* GetPtr(this double[] array)
|
||||
{ fixed (double* tempPtr = array) return tempPtr; }
|
||||
public static string ToS(this uint d, bool BE) =>
|
||||
BitConverter.GetBytes(d.E(BE)).ToASCII();
|
||||
|
||||
public static IntPtr GetIntPtr(this sbyte[] array)
|
||||
{ fixed ( sbyte* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this byte[] array)
|
||||
{ fixed ( byte* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this short[] array)
|
||||
{ fixed ( short* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this ushort[] array)
|
||||
{ fixed (ushort* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this int[] array)
|
||||
{ fixed ( int* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this uint[] array)
|
||||
{ fixed ( uint* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this long[] array)
|
||||
{ fixed ( long* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this ulong[] array)
|
||||
{ fixed ( ulong* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this float[] array)
|
||||
{ fixed ( float* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
public static IntPtr GetIntPtr(this double[] array)
|
||||
{ fixed (double* tempPtr = array) return (IntPtr)tempPtr; }
|
||||
|
||||
public static string ToS(this object d)
|
||||
{
|
||||
if (d == null ) return "Null";
|
||||
@@ -257,7 +254,7 @@ namespace KKdBaseLib
|
||||
return d.ToString();
|
||||
}
|
||||
|
||||
private static readonly string NumberDecimalSeparator =
|
||||
private static readonly string NDS =
|
||||
System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator;
|
||||
|
||||
public static string ToS(this bool? d) => (d ?? default).ToString();
|
||||
@@ -279,28 +276,72 @@ namespace KKdBaseLib
|
||||
public static string ToS(this ulong? d) => (d ?? default).ToString();
|
||||
public static string ToS(this ulong d) => d.ToString();
|
||||
public static string ToS(this float? d, int round) => (d ?? default).ToS(round);
|
||||
public static string ToS(this float? d) => (d ?? default).ToString();
|
||||
public static string ToS(this float d, int round) =>
|
||||
Math.Round(d, round).ToString().ToLower().Replace(NumberDecimalSeparator, ".");
|
||||
public static string ToS(this float d) =>
|
||||
Math.Round(d, 15).ToString().ToLower().Replace(NumberDecimalSeparator, ".");
|
||||
public static string ToS(this 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).ToString();
|
||||
public static string ToS(this double d, int round) =>
|
||||
Math.Round(d, round).ToString().ToLower().Replace(NumberDecimalSeparator, ".");
|
||||
public static string ToS(this double d) =>
|
||||
Math.Round(d, 15).ToString().ToLower().Replace(NumberDecimalSeparator, ".");
|
||||
public static float ToF32(this string s) =>
|
||||
float. Parse(s.Replace(".", NumberDecimalSeparator));
|
||||
public static bool ToF32(this string s, out float value) =>
|
||||
float.TryParse(s.Replace(".", NumberDecimalSeparator), out value);
|
||||
public static double ToF64(this string s) =>
|
||||
double. Parse(s.Replace(".", NumberDecimalSeparator));
|
||||
public static bool ToF64(this string s, out double value) =>
|
||||
double.TryParse(s.Replace(".", NumberDecimalSeparator), out value);
|
||||
public static bool ToF32(this string s, out float? value)
|
||||
{ bool Val = ToF32(s, out float val); value = val; return Val; }
|
||||
public static bool ToF64(this string s, out double? value)
|
||||
{ bool Val = ToF64(s, out double val); value = val; return Val; }
|
||||
public static 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+146
-129
@@ -1,120 +1,128 @@
|
||||
namespace KKdBaseLib.F2
|
||||
namespace KKdBaseLib.F2
|
||||
{
|
||||
public struct ENRSList : INull
|
||||
public struct ENRS : INull
|
||||
{
|
||||
public KKdList<ENRS> List;
|
||||
public ENRSEntry[] Array;
|
||||
|
||||
public int Length => length();
|
||||
|
||||
public bool IsNull => List. IsNull;
|
||||
public bool NotNull => List.NotNull;
|
||||
public bool IsNull => Array == null;
|
||||
public bool NotNull => Array != null;
|
||||
|
||||
public unsafe static ENRSList Read(byte[] data)
|
||||
public unsafe void Read(byte[] data)
|
||||
{
|
||||
if (data == null || data.Length < 0x10) return default;
|
||||
byte* ptr = data.GetPtr();
|
||||
int i, i0;
|
||||
int ENRSCount = ((int*)ptr)[1];
|
||||
KKdList<ENRS> list = KKdList<ENRS>.New;
|
||||
ptr += 0x10;
|
||||
ENRS enrs;
|
||||
ENRS.SubENRS sub;
|
||||
|
||||
for (i = 0; i < ENRSCount; i++)
|
||||
if (data == null || data.Length < 0x10) return;
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
enrs = default;
|
||||
enrs.Offset = ReadENRSValue(ref ptr);
|
||||
enrs.Count = ReadENRSValue(ref ptr);
|
||||
enrs.Size = ReadENRSValue(ref ptr);
|
||||
enrs.Repeat = ReadENRSValue(ref ptr);
|
||||
int i, i0;
|
||||
int ENRSCount = ((int*)ptr)[1];
|
||||
ENRSEntry enrsEntry;
|
||||
ENRSEntry.SubENRSEntry sub;
|
||||
Array = new ENRSEntry[ENRSCount];
|
||||
|
||||
if (i > 0) enrs.Offset += list[list.Count - 1].Offset;
|
||||
|
||||
if (enrs.Repeat < 1) { enrs.Sub = null; list.Add(enrs); continue; }
|
||||
|
||||
enrs.Sub = new KKdList<ENRS.SubENRS> { Capacity = enrs.Count };
|
||||
for (i0 = 0; i0 < enrs.Count; i0++)
|
||||
byte* localPtr = ptr + 0x10;
|
||||
for (i = 0; i < ENRSCount; i++)
|
||||
{
|
||||
sub = default;
|
||||
sub.Skip = ReadENRSValue(ref ptr, out sub.Type);
|
||||
sub.Reverse = ReadENRSValue(ref ptr);
|
||||
if (i0 > 0) sub.Skip += enrs.Sub[i0 - 1].SizeSkip;
|
||||
enrs.Sub.Add(sub);
|
||||
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 (enrs.Sub[i0].Type == ENRS.Type.Invalid) return default;
|
||||
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;
|
||||
}
|
||||
list.Add(enrs);
|
||||
}
|
||||
return new ENRSList { List = list };
|
||||
}
|
||||
|
||||
public unsafe static byte[] Write(ENRSList enrsList)
|
||||
public unsafe byte[] Write()
|
||||
{
|
||||
int i, i0;
|
||||
byte[] data;
|
||||
byte* ptr;
|
||||
|
||||
KKdList<ENRS> list = (System.Collections.Generic.List<ENRS>)enrsList.List;
|
||||
if (enrsList.IsNull || enrsList.List.Count < 1) return new byte[0x20];
|
||||
if (IsNull || Array.Length < 1) return new byte[0x20];
|
||||
|
||||
data = new byte[enrsList.Length];
|
||||
ptr = data.GetPtr();
|
||||
((int*)ptr)[1] = enrsList.List.Count;
|
||||
ptr += 0x10;
|
||||
|
||||
for (i = 0; i < enrsList.List.Count; i++)
|
||||
data = new byte[Length];
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
ENRS enrs = enrsList.List[i];
|
||||
WriteENRSValue(ref ptr, i > 0 ? enrs.Offset - enrsList.List[i - 1].Offset : enrs.Offset);
|
||||
WriteENRSValue(ref ptr, enrs.Count );
|
||||
WriteENRSValue(ref ptr, enrs.Size );
|
||||
WriteENRSValue(ref ptr, enrs.Repeat);
|
||||
((int*)ptr)[1] = Array.Length;
|
||||
|
||||
if (enrs.Repeat < 1) continue;
|
||||
|
||||
for (i0 = 0; i0 < enrs.Count; i0++)
|
||||
byte* localPtr = ptr + 0x10;
|
||||
for (i = 0; i < Array.Length; i++)
|
||||
{
|
||||
if (enrs.Sub[i0].Type < ENRS.Type. WORD ||
|
||||
enrs.Sub[i0].Type > ENRS.Type.QWORD)
|
||||
return data;
|
||||
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;
|
||||
|
||||
WriteENRSValue(ref ptr, i0 > 0 ? enrs.Sub[i0].Skip -
|
||||
enrs.Sub[i0 - 1].SizeSkip : enrs.Sub[i0].Skip, enrs.Sub[i0].Type);
|
||||
WriteENRSValue(ref ptr, enrs.Sub[i0].Reverse);
|
||||
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 < List.Count; i++)
|
||||
for (i = 0; i < Array.Length; i++)
|
||||
{
|
||||
ENRS enrs = List[i];
|
||||
length += GetSize(i > 0 ? enrs.Offset - List[i - 1].Offset : enrs.Offset);
|
||||
length += GetSize(enrs.Count );
|
||||
length += GetSize(enrs.Size );
|
||||
length += GetSize(enrs.Repeat);
|
||||
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 < ENRS.Type. WORD ||
|
||||
enrs.Sub[i0].Type > ENRS.Type.QWORD) return length.A(0x10);
|
||||
if (enrs.Sub[i0].Type < ENRSEntry.Type. WORD ||
|
||||
enrs.Sub[i0].Type > ENRSEntry.Type.QWORD) return length.A(0x10);
|
||||
|
||||
length += GetSizeType(i0 > 0 ? enrs.Sub[i0].Skip -
|
||||
enrs.Sub[i0 - 1].SizeSkip : enrs.Sub[i0].Skip);
|
||||
length += GetSize(enrs.Sub[i0].Reverse);
|
||||
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 int GetSizeType(int val) => val < 0x00000010 ? 1 : val < 0x00001000 ? 2 : 4;
|
||||
static int GetSize (int val) => val < 0x00000040 ? 1 : val < 0x00004000 ? 2 : 4;
|
||||
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)
|
||||
@@ -134,84 +142,90 @@
|
||||
return Sub;
|
||||
}*/
|
||||
|
||||
[System.ThreadStatic] private static ENRS.Value value;
|
||||
[System.ThreadStatic] private static ENRSEntry.Value value;
|
||||
|
||||
private unsafe static int ReadENRSValue(ref byte* ptr, out ENRS.Type type)
|
||||
private unsafe static bool ReadENRSValue(ref byte* ptr, out int v, out ENRSEntry.Type type)
|
||||
{
|
||||
int V = *ptr & 0xF;
|
||||
type = (ENRS. Type)((*ptr & 0x30) >> 4);
|
||||
value = (ENRS.Value)((*ptr & 0xC0) >> 6);
|
||||
v = *ptr & 0xF;
|
||||
type = (ENRSEntry. Type)((*ptr & 0x30) >> 4);
|
||||
value = (ENRSEntry.Value)((*ptr & 0xC0) >> 6);
|
||||
ptr++;
|
||||
if (value == ENRS.Value.Int32 )
|
||||
{ V = (V << 24) | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; ptr += 3; }
|
||||
else if (value == ENRS.Value.Int16 )
|
||||
{ V = (V << 8) | ptr[0]; ptr += 1; }
|
||||
else if (value == ENRS.Value.Invalid) V = 0;
|
||||
return V;
|
||||
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 int ReadENRSValue(ref byte* ptr)
|
||||
private unsafe static bool ReadENRSValue(ref byte* ptr, out int v)
|
||||
{
|
||||
int V = *ptr & 0x3F;
|
||||
value = (ENRS.Value)((*ptr & 0xC0) >> 6);
|
||||
v = *ptr & 0x3F;
|
||||
value = (ENRSEntry.Value)((*ptr & 0xC0) >> 6);
|
||||
ptr++;
|
||||
if (value == ENRS.Value.Int32 )
|
||||
{ V = (V << 24) | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; ptr += 3; }
|
||||
else if (value == ENRS.Value.Int16 )
|
||||
{ V = (V << 8) | ptr[0]; ptr += 1; }
|
||||
else if (value == ENRS.Value.Invalid) V = 0;
|
||||
return V;
|
||||
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 void WriteENRSValue(ref byte* ptr, int val, ENRS.Type type)
|
||||
private unsafe static bool WriteENRSValue(ref byte* ptr, int val, ENRSEntry.Type type)
|
||||
{
|
||||
value = ENRS.Value.Invalid;
|
||||
if (val < 0x00000040) value = ENRS.Value.Int8 ;
|
||||
else if (val < 0x00004000) value = ENRS.Value.Int16;
|
||||
else if (val < 0x40000000) value = ENRS.Value.Int32;
|
||||
*ptr = (byte)((((byte)value << 6) & 0xC0) | (((byte)type << 4) & 0x30));
|
||||
|
||||
if (val < 0x00000010)
|
||||
{ *ptr |= (byte)( val & 0x0F); }
|
||||
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)((val >> 8) & 0x0F); ptr++;
|
||||
*ptr = (byte)( val & 0xFF); }
|
||||
{
|
||||
*ptr++ = (byte)(((byte)ENRSEntry.Value.Int16 << 6) | t | ((val >> 8) & 0xF));
|
||||
*ptr++ = (byte)(val & 0xFF);
|
||||
}
|
||||
else if (val < 0x10000000)
|
||||
{ *ptr |= (byte)((val >> 24) & 0x0F); ptr++;
|
||||
*ptr = (byte)((val >> 16) & 0xFF); ptr++;
|
||||
*ptr = (byte)((val >> 8) & 0xFF); ptr++;
|
||||
*ptr = (byte)( val & 0xFF); }
|
||||
ptr++;
|
||||
{
|
||||
*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 void WriteENRSValue(ref byte* ptr, int val)
|
||||
private unsafe static bool WriteENRSValue(ref byte* ptr, int val)
|
||||
{
|
||||
value = ENRS.Value.Invalid;
|
||||
if (val < 0x00000040) value = ENRS.Value.Int8 ;
|
||||
else if (val < 0x00004000) value = ENRS.Value.Int16;
|
||||
else if (val < 0x40000000) value = ENRS.Value.Int32;
|
||||
*ptr = (byte)(((byte)value << 6) & 0xC0);
|
||||
|
||||
if (val < 0x00000040)
|
||||
{ *ptr |= (byte)( val & 0x3F); }
|
||||
if (val < 0x00000040)
|
||||
*ptr++ = (byte)(((byte)ENRSEntry.Value.Int8 << 6) | ( val & 0x3F));
|
||||
else if (val < 0x00004000)
|
||||
{ *ptr |= (byte)((val >> 8) & 0x3F); ptr++;
|
||||
*ptr = (byte)( val & 0xFF); }
|
||||
{
|
||||
*ptr++ = (byte)(((byte)ENRSEntry.Value.Int16 << 6) | ((val >> 8) & 0x3F));
|
||||
*ptr++ = (byte)(val & 0xFF);
|
||||
}
|
||||
else if (val < 0x40000000)
|
||||
{ *ptr |= (byte)((val >> 24) & 0x3F); ptr++;
|
||||
*ptr = (byte)((val >> 16) & 0xFF); ptr++;
|
||||
*ptr = (byte)((val >> 8) & 0xFF); ptr++;
|
||||
*ptr = (byte)( val & 0xFF); }
|
||||
ptr++;
|
||||
{
|
||||
*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 ENRS
|
||||
public struct ENRSEntry
|
||||
{
|
||||
public int Offset;
|
||||
public int Count;
|
||||
public int Size;
|
||||
public int Repeat;
|
||||
public KKdList<SubENRS> Sub;
|
||||
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
|
||||
{
|
||||
@@ -229,12 +243,15 @@
|
||||
Invalid = 0b11,
|
||||
}
|
||||
|
||||
public struct SubENRS
|
||||
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);
|
||||
|
||||
@@ -248,6 +265,6 @@
|
||||
}
|
||||
|
||||
public override string ToString() =>
|
||||
$"{(NotNull ? $"ENRS Count: {List.Count}" : "No ENRS")}";
|
||||
$"{(NotNull ? $"ENRS Count: {Array.Length}" : "No ENRS")}";
|
||||
}
|
||||
}
|
||||
|
||||
+12
-13
@@ -1,23 +1,22 @@
|
||||
namespace KKdBaseLib.F2
|
||||
namespace KKdBaseLib.F2
|
||||
{
|
||||
public struct Header
|
||||
{
|
||||
public int Signature;
|
||||
public int DataSize;
|
||||
public int Length;
|
||||
public int Flags;
|
||||
public int Depth;
|
||||
public int SectionSize;
|
||||
public int Mode;
|
||||
public int InnerSignature;
|
||||
public int SectionSignature;
|
||||
public 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 NotUseDataSizeAsSectionSize;
|
||||
public bool UseBigEndian;
|
||||
public bool UseSectionSize;
|
||||
|
||||
public bool IsBE => Format == Format.F2BE;
|
||||
public bool IsX => Format == Format.X || Format == Format.XHD;
|
||||
|
||||
public override string ToString() => Signature.ToString(false);
|
||||
public override string ToString() => Signature.ToS(false);
|
||||
}
|
||||
}
|
||||
|
||||
+96
-54
@@ -1,4 +1,4 @@
|
||||
namespace KKdBaseLib.F2
|
||||
namespace KKdBaseLib.F2
|
||||
{
|
||||
public struct POF : INull
|
||||
{
|
||||
@@ -10,70 +10,111 @@
|
||||
public int Length => length(false).A(0x10);
|
||||
public int LengthX => length( true).A(0x10);
|
||||
|
||||
public unsafe static POF Read(byte[] data, bool shiftX)
|
||||
public unsafe void Read(byte[] data, bool shiftX)
|
||||
{
|
||||
Value Val = 0;
|
||||
KKdList<long> offsets = KKdList<long>.New;
|
||||
byte* ptr = data.GetPtr();
|
||||
int i = 0, offset = 0, v = 0;
|
||||
byte bitShift = (byte)(shiftX ? 3 : 2);
|
||||
|
||||
int length = *(int*)ptr - 4; ptr += 4;
|
||||
while (length > i)
|
||||
Offsets = KKdList<long>.New;
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
v = *ptr & 0x3F;
|
||||
Val = (Value)(*ptr & 0xC0);
|
||||
ptr++; i++;
|
||||
if (Val == Value.Int32 )
|
||||
{ v = (v << 24) | (ptr[0] << 16) | (ptr[1] << 8) | ptr[2]; ptr += 3; i += 3; }
|
||||
else if (Val == Value.Int16 )
|
||||
{ v = (v << 8) | ptr[0]; ptr += 1; i += 3; }
|
||||
else if (Val == Value.Invalid) break;
|
||||
offset += v;
|
||||
offsets.Add(offset << bitShift);
|
||||
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;
|
||||
}
|
||||
return new POF { Offsets = offsets };
|
||||
}
|
||||
|
||||
public unsafe static byte[] Write(POF pof, bool shiftX)
|
||||
public unsafe byte[] Write(bool shiftX)
|
||||
{
|
||||
pof.Offsets.Sort();
|
||||
long offset = 0;
|
||||
byte bitShift = (byte)(shiftX ? 3 : 2);
|
||||
int max1 = 0x00100 >> bitShift;
|
||||
int max2 = 0x10000 >> bitShift;
|
||||
Offsets.Sort();
|
||||
long j, k, o;
|
||||
byte bitShift, v;
|
||||
bitShift = (byte)(shiftX ? 3 : 2);
|
||||
v = (byte)((1 << bitShift) - 1);
|
||||
|
||||
byte[] data = new byte[pof.Length];
|
||||
byte* ptr = data.GetPtr();
|
||||
|
||||
byte Val = 0;
|
||||
*(int*)ptr = pof.length(shiftX); ptr += 4;
|
||||
for (int i = 0; i < pof.Offsets.Count; i++)
|
||||
j = 0;
|
||||
byte[] data = new byte[length(shiftX)];
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
offset = pof.Offsets[i];
|
||||
if (i > 0) { offset -= pof.Offsets[i - 1]; if (offset == 0) continue; }
|
||||
*(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;
|
||||
}
|
||||
|
||||
offset >>= bitShift;
|
||||
Val = (byte)(offset > max2 ? Value.Int32 : offset > max1 ? Value.Int16 : Value.Int8);
|
||||
if (offset < max1) *ptr = (byte)(Val | offset );
|
||||
else if (offset < max2) { *ptr = (byte)(Val | (offset >> 8)); ptr++;
|
||||
*ptr = (byte) offset ; }
|
||||
else { *ptr = (byte)(Val | (offset >> 24)); ptr++;
|
||||
*ptr = (byte) (offset >> 16) ; ptr++;
|
||||
*ptr = (byte) (offset >> 8) ; ptr++;
|
||||
*ptr = (byte) offset ; }
|
||||
ptr++;
|
||||
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)
|
||||
{
|
||||
int length = 5;
|
||||
if (Offsets.IsNull)
|
||||
return 0;
|
||||
|
||||
int length = 4;
|
||||
long offset = 0;
|
||||
byte bitShift = (byte)(shiftX ? 3 : 2);
|
||||
int max1 = 0x00100 >> bitShift;
|
||||
int max2 = 0x10000 >> bitShift;
|
||||
int max1 = 0x00000040;
|
||||
int max2 = 0x00004000;
|
||||
int max3 = 0x40000000;
|
||||
for (int i = 0; i < Offsets.Count; i++)
|
||||
{
|
||||
offset = Offsets[i];
|
||||
@@ -82,17 +123,18 @@
|
||||
offset >>= bitShift;
|
||||
if (offset < max1) length += 1;
|
||||
else if (offset < max2) length += 2;
|
||||
else length += 4;
|
||||
else if (offset < max3) length += 4;
|
||||
else length += 1;
|
||||
}
|
||||
return length;
|
||||
return length;
|
||||
}
|
||||
|
||||
public enum Value : byte
|
||||
{
|
||||
Invalid = 0b00000000,
|
||||
Int8 = 0b01000000,
|
||||
Int16 = 0b10000000,
|
||||
Int32 = 0b11000000,
|
||||
Invalid = 0b00,
|
||||
Int8 = 0b01,
|
||||
Int16 = 0b10,
|
||||
Int32 = 0b11,
|
||||
}
|
||||
|
||||
public override string ToString() =>
|
||||
|
||||
+25
-28
@@ -1,4 +1,4 @@
|
||||
namespace KKdBaseLib.F2
|
||||
namespace KKdBaseLib.F2
|
||||
{
|
||||
public struct Struct
|
||||
{
|
||||
@@ -6,13 +6,11 @@
|
||||
public byte[] Data;
|
||||
public Struct[] SubStructs;
|
||||
|
||||
public ENRSList ENRS;
|
||||
public ENRS ENRS;
|
||||
public POF POF;
|
||||
|
||||
public int Length => length(false);
|
||||
public int LengthX => length( true);
|
||||
|
||||
public int Depth => Header.Depth;
|
||||
public uint Length => length(false);
|
||||
public uint LengthX => length( true);
|
||||
|
||||
public bool HasPOF => POF .NotNull;
|
||||
public bool HasENRS => ENRS.NotNull;
|
||||
@@ -20,29 +18,28 @@
|
||||
|
||||
public long DataOffset;
|
||||
|
||||
public override string ToString() => $"{Header.ToString()}" +
|
||||
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" : "")}";
|
||||
|
||||
private int length(bool shiftX = false)
|
||||
{
|
||||
int length = Data != null ? Data.Length : 0;
|
||||
if (HasPOF ) length += 0x20 + (shiftX ? POF.LengthX : POF.Length);
|
||||
if (HasENRS) length += 0x20 + ENRS.Length;
|
||||
|
||||
if (HasSubStructs)
|
||||
{
|
||||
for (int i = 0; i < SubStructs.Length; i++)
|
||||
length += (shiftX ? SubStructs[i].LengthX : SubStructs[i].Length) + SubStructs[i].Header.Length;
|
||||
length += 0x20;
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
public void Update(bool ShiftX = false)
|
||||
{
|
||||
Header.SectionSize = Data != null ? Data.Length : 0;
|
||||
Header.DataSize = length(ShiftX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace KKdBaseLib
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public enum Format : byte
|
||||
{
|
||||
@@ -9,11 +9,11 @@
|
||||
DTe = 4,
|
||||
F = 5,
|
||||
AFT = 6,
|
||||
F2LE = 7,
|
||||
F2BE = 8,
|
||||
MGF = 9,
|
||||
X = 10,
|
||||
XHD = 11,
|
||||
FT = 12,
|
||||
F2 = 7,
|
||||
MGF = 8,
|
||||
X = 9,
|
||||
XHD = 10,
|
||||
FT = 11,
|
||||
M39 = 12,
|
||||
}
|
||||
}
|
||||
|
||||
+61
-34
@@ -1,69 +1,96 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct Half : IFormattable
|
||||
{
|
||||
private ushort _value;
|
||||
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 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 Half(ushort bits) => new Half() { value = bits };
|
||||
|
||||
public static explicit operator ushort(Half bits) => bits._value;
|
||||
public static explicit operator ushort(Half bits) => bits.value;
|
||||
|
||||
public static unsafe implicit operator float(Half h)
|
||||
{
|
||||
int sign = (h._value >> 15) & 0x001;
|
||||
int exponent = ((h._value >> 10) & 0x01F) + 127 - 15;
|
||||
int mantissa = h._value & 0x3FF;
|
||||
int si32;
|
||||
int sign = (h.value >> 15) & 0x001;
|
||||
int exponent = (h.value >> 10) & 0x01F;
|
||||
int mantissa = h.value & 0x3FF;
|
||||
unchecked { si32 = sign != 0 ? (int)0x80000000 : 0x00000000; }
|
||||
|
||||
int si32 = (sign << 31) | (exponent << 23) | (mantissa << 13);
|
||||
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;
|
||||
ushort sign = (ushort)( (si32 >> 16) & 0x8000);
|
||||
short exponent = ( short)(((si32 >> 23) & 0x00FF) - 127 + 15);
|
||||
ushort mantissa = (ushort)( (si32 >> 13) & 0x03FF);
|
||||
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 < 0) { exponent = 0; mantissa = 0; }
|
||||
else if (exponent > 30) exponent = 31;
|
||||
|
||||
return new Half { _value = (ushort)(sign | (exponent << 10) | mantissa) };
|
||||
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)
|
||||
public static unsafe implicit operator double(Half h)
|
||||
{
|
||||
int sign = (h._value >> 15) & 0x001;
|
||||
int exponent = ((h._value >> 10) & 0x01F) + 1023 - 15;
|
||||
int mantissa = h._value & 0x3FF;
|
||||
long si64;
|
||||
long sign = (h.value >> 15) & 0x001;
|
||||
long exponent = (h.value >> 10) & 0x01F;
|
||||
long mantissa = h.value & 0x3FF;
|
||||
unchecked { si64 = sign != 0 ? (long)0x8000000000000000 : 0x0000000000000000; }
|
||||
|
||||
long si64 = ((long)sign << 63) | ((long)exponent << 52) | ((long)mantissa << 42);
|
||||
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;
|
||||
ushort sign = (ushort) ((si64 >> 48) & 0x8000);
|
||||
short exponent = ( short)(((si64 >> 52) & 0x07FF) - 1023 + 15);
|
||||
ushort mantissa = (ushort) ((si64 >> 42) & 0x03FF);
|
||||
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 < 0) { exponent = 0; mantissa = 0; }
|
||||
else if (exponent > 30) exponent = 31;
|
||||
|
||||
return new Half { _value = (ushort)(sign | (exponent << 10) | mantissa) };
|
||||
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);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace KKdBaseLib
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public interface IKF
|
||||
{
|
||||
|
||||
+120
-107
@@ -1,39 +1,53 @@
|
||||
using KKdBaseLib.A3DA;
|
||||
using KKdBaseLib.Auth3D;
|
||||
|
||||
namespace KKdBaseLib.Interpolation
|
||||
{
|
||||
public struct A3DAI //A3DA Interpolation
|
||||
public class A3DAI : IInterpolation<float>, System.IDisposable // A3DA Interpolation
|
||||
{
|
||||
private A3DAKey key;
|
||||
private A3DAKey a3daKey;
|
||||
|
||||
private float f;
|
||||
private float last;
|
||||
private float deltaFrame;
|
||||
private float t;
|
||||
private float v;
|
||||
private float df;
|
||||
private float @if;
|
||||
private float rf;
|
||||
private float lastTime;
|
||||
|
||||
private KFT3 firstKey;
|
||||
private KFT3 lastKey;
|
||||
|
||||
public float InterpolationFramerate
|
||||
{ get => @if; set { @if = value; deltaFrame = @if / rf; } }
|
||||
public float RequestedFramerate
|
||||
{ get => rf; set { rf = value; deltaFrame = @if / rf; } }
|
||||
public float RequestedFramerate { get => rf; set { rf = value; df = @if / rf; } }
|
||||
|
||||
public float Frame => f;
|
||||
public float Value => last;
|
||||
public bool IsNull => key.Keys == null ? true : key.Length < 1;
|
||||
public bool NotNull => key.Keys == null ? false : key.Length > 0;
|
||||
public 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(A3DAKey key, float a3daFramerate = 60, float requestedFramerate = 60)
|
||||
public A3DAI(Key key, float a3daFramerate = 60, float requestedFramerate = 60)
|
||||
{
|
||||
lastTime = 0;
|
||||
this.key = key; f = -1; deltaFrame = last = rf = @if = 0;
|
||||
a3daKey = new A3DAKey(key); f = -1; df = @if = rf = t = v = 0;
|
||||
@if = a3daFramerate;
|
||||
firstKey = lastKey = default;
|
||||
RequestedFramerate = requestedFramerate;
|
||||
f = -deltaFrame;
|
||||
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)
|
||||
@@ -45,138 +59,137 @@ namespace KKdBaseLib.Interpolation
|
||||
|
||||
public float SetTime(float time)
|
||||
{
|
||||
if ((int)key.Type < 1 || (int)key.Type > 4 || key.Length < 1) return 0;
|
||||
if ((int)key.Type == 1) return key.Keys[0].V;
|
||||
|
||||
lastTime = time;
|
||||
t = time;
|
||||
f = time * @if;
|
||||
last = Interpolate(f);
|
||||
return last;
|
||||
|
||||
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)
|
||||
{
|
||||
if ((int)key.Type < 1 || (int)key.Type > 4 || key.Length < 1) return 0;
|
||||
if ((int)key.Type == 1) return key.Keys[0].V;
|
||||
t = frame / rf;
|
||||
f = frame * df;
|
||||
|
||||
lastTime = frame / rf;
|
||||
f = frame * deltaFrame;
|
||||
last = Interpolate(f);
|
||||
return last;
|
||||
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)
|
||||
{
|
||||
if ((int)key.Type < 1 || (int)key.Type > 4 || key.Length < 1) return 0;
|
||||
if ((int)key.Type == 1) return key.Keys[0].V;
|
||||
t += time;
|
||||
f = t * @if;
|
||||
|
||||
lastTime += time;
|
||||
f = lastTime * @if;
|
||||
last = Interpolate(f);
|
||||
return last;
|
||||
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()
|
||||
{
|
||||
if ((int)key.Type < 1 || (int)key.Type > 4 || key.Length < 1) return 0;
|
||||
if ((int)key.Type == 1) return key.Keys[0].V;
|
||||
f += df;
|
||||
t = f / @if;
|
||||
|
||||
f += deltaFrame;
|
||||
lastTime = f / @if;
|
||||
last = Interpolate(f);
|
||||
return last;
|
||||
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 df = 0;
|
||||
float ep = 0;
|
||||
float f = (int)frame;
|
||||
|
||||
if (f < firstKey.F)
|
||||
if (frame < firstKey.F)
|
||||
{
|
||||
if (key.EPTypePost < EPType.EP_1 || key.EPTypePost > EPType.EP_3)
|
||||
if (a3daKey.EPTypePost < EPType.Linear || a3daKey.EPTypePost > EPType.CycleOffset)
|
||||
return firstKey.V;
|
||||
|
||||
df = firstKey.F - frame;
|
||||
if (key.EPTypePre == EPType.EP_1)
|
||||
float df = firstKey.F - frame;
|
||||
if (a3daKey.EPTypePre == EPType.Linear)
|
||||
return firstKey.V - df * firstKey.T1;
|
||||
else if (key.EPTypePre == EPType.EP_2 || key.EPTypePre == EPType.EP_3)
|
||||
{
|
||||
frame = lastKey.F - df % key.FDBSaE;
|
||||
f = (int)frame;
|
||||
}
|
||||
|
||||
frame = lastKey.F - df % a3daKey.FrameDelta;
|
||||
if (a3daKey.EPTypePre == EPType.CycleOffset)
|
||||
ep = -(float)((int)(df / a3daKey.FrameDelta) + 1) * a3daKey.ValueDelta;
|
||||
}
|
||||
else if (f >= lastKey.F)
|
||||
else if (frame >= lastKey.F)
|
||||
{
|
||||
if (key.EPTypePost < EPType.EP_1 || key.EPTypePost > EPType.EP_3)
|
||||
if (a3daKey.EPTypePost < EPType.Linear || a3daKey.EPTypePost > EPType.CycleOffset)
|
||||
return lastKey.V;
|
||||
|
||||
df = frame - lastKey.F;
|
||||
if (key.EPTypePost == EPType.EP_1)
|
||||
float df = frame - lastKey.F;
|
||||
if (a3daKey.EPTypePost == EPType.Linear)
|
||||
return lastKey.V + df * lastKey.T2;
|
||||
else if (key.EPTypePost == EPType.EP_2 || key.EPTypePost == EPType.EP_3)
|
||||
{
|
||||
frame = firstKey.F + df % key.FDBSaE;
|
||||
f = (int)frame;
|
||||
}
|
||||
|
||||
frame = firstKey.F + df % a3daKey.FrameDelta;
|
||||
if (a3daKey.EPTypePost == EPType.CycleOffset)
|
||||
ep = (float)((int)(df / a3daKey.FrameDelta) + 1) * a3daKey.ValueDelta;
|
||||
}
|
||||
|
||||
if ((f < firstKey.F && key.EPTypePre == EPType.EP_3) ||
|
||||
(f >= firstKey.F && key.EPTypePost == EPType.EP_3))
|
||||
KFT3 c, n;
|
||||
long key = 0;
|
||||
unsafe
|
||||
{
|
||||
ep = df / key.FDBSaE;
|
||||
ep = (ep >= 0 && ep != (int)ep) ? (ep - (int)ep > 0 ? 1 : 0) : ep;
|
||||
ep = (f < firstKey.F ? -1 : 1) * (ep + 1) * key.VDBSaE;
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
if (f <= firstKey.F)
|
||||
return firstKey.V + ep;
|
||||
else if (f >= lastKey.F)
|
||||
return lastKey.V + ep;
|
||||
|
||||
int data = 0;
|
||||
int length = key.Length;
|
||||
int tempLength;
|
||||
while (length > 0)
|
||||
float v;
|
||||
if (frame <= c.F || frame >= n.F)
|
||||
v = frame > c.F ? n.V : c.V;
|
||||
else if (a3daKey.Type == KeyType.Linear)
|
||||
{
|
||||
tempLength = length >> 1;
|
||||
if (f <= key.Keys[data + tempLength].F)
|
||||
length = tempLength;
|
||||
else
|
||||
{
|
||||
data += tempLength + 1;
|
||||
length -= tempLength + 1;
|
||||
}
|
||||
float t = (frame - c.F) / (n.F - c.F);
|
||||
v = (1.0f - t) * c.V + t * n.V;
|
||||
}
|
||||
|
||||
KFT3 c = key.Keys[data - 1];
|
||||
KFT3 n = key.Keys[data];
|
||||
float result;
|
||||
if (frame > c.F && frame < n.F)
|
||||
else if (a3daKey.Type == KeyType.Hermite)
|
||||
{
|
||||
if (key.Type == KeyType.Lerp)
|
||||
{
|
||||
float t = (frame - c.F) / (n.F - c.F);
|
||||
result = (1 - t) * c.V + t * n.V;
|
||||
}
|
||||
else if (key.Type == KeyType.Hermite)
|
||||
{
|
||||
float t = (frame - c.F) / (n.F - c.F);
|
||||
float t_2 = (1 - t) * (1 - t);
|
||||
result = t_2 * c.V * (1 + 2 * t) + (t * n.V * (3 - 2 * t) +
|
||||
(t_2 * c.T2 + t * (t - 1) * n.T1) * (n.F - c.F)) * t;
|
||||
}
|
||||
else
|
||||
result = c.V;
|
||||
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
|
||||
result = frame > c.F ? n.V : c.V;
|
||||
return result + ep;
|
||||
else v = c.V;
|
||||
return v + ep;
|
||||
}
|
||||
|
||||
public void ResetFrameCount() => f = -deltaFrame;
|
||||
public void ResetFrameCount() { f = -df; t = f / rf; }
|
||||
|
||||
public override string ToString() => $"Frame: {f}, Value: {last}";
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
namespace KKdBaseLib.Interpolation
|
||||
namespace KKdBaseLib.Interpolation
|
||||
{
|
||||
public interface IInterpolation : INull
|
||||
public interface IInterpolation<T> : INull
|
||||
{
|
||||
float RequestedFramerate { get; set; }
|
||||
float InterpolationFramerate { get; set; }
|
||||
float RequestedFramerate { get; set; }
|
||||
|
||||
float Frame { get; }
|
||||
float Value { get; }
|
||||
|
||||
float SetTime (float time);
|
||||
float SetFrame(float frame);
|
||||
float NextFrame(float time);
|
||||
float NextFrame();
|
||||
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}";
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
namespace KKdBaseLib.Interpolation
|
||||
{
|
||||
public struct PDI : IInterpolation //Project DIVA Interpolation
|
||||
{
|
||||
private KFT2[] array;
|
||||
|
||||
private float f;
|
||||
private float last;
|
||||
private float deltaFrame;
|
||||
private float @if;
|
||||
private float rf;
|
||||
private float lastTime;
|
||||
|
||||
private KFT2 firstKey;
|
||||
private KFT2 lastKey;
|
||||
|
||||
public float InterpolationFramerate
|
||||
{ get => @if; set { @if = value; deltaFrame = @if / rf; } }
|
||||
public float RequestedFramerate
|
||||
{ get => rf; set { rf = value; deltaFrame = @if / rf; } }
|
||||
|
||||
public float Frame => f;
|
||||
public float Value => last;
|
||||
public bool IsNull => array == null ? true : array.Length < 1;
|
||||
public bool NotNull => array == null ? false : array.Length > 0;
|
||||
|
||||
public PDI(KFT2[] Array, float InterpolationFramerate = 60, float RequestedFramerate = 60)
|
||||
{
|
||||
lastTime = 0;
|
||||
this.array = Array; f = -1; deltaFrame = last = rf = @if = 0;
|
||||
@if = InterpolationFramerate;
|
||||
firstKey = lastKey = default;
|
||||
this.RequestedFramerate = RequestedFramerate;
|
||||
f = -deltaFrame;
|
||||
ResetFrameCount();
|
||||
|
||||
if (Array != null && Array.Length > 0)
|
||||
{
|
||||
firstKey = Array[0];
|
||||
lastKey = Array[Array.Length - 1];
|
||||
}
|
||||
}
|
||||
|
||||
public float SetTime(float time)
|
||||
{
|
||||
if (array == null || array.Length < 1) return 0;
|
||||
|
||||
lastTime = time;
|
||||
f = time * @if;
|
||||
last = Interpolate(f);
|
||||
return last;
|
||||
}
|
||||
|
||||
public float SetFrame(float frame)
|
||||
{
|
||||
if (array == null || array.Length < 1) return 0;
|
||||
|
||||
lastTime = frame / rf;
|
||||
f = frame * deltaFrame;
|
||||
last = Interpolate(f);
|
||||
return last;
|
||||
}
|
||||
|
||||
public float NextFrame(float time)
|
||||
{
|
||||
if (array == null || array.Length < 1) return 0;
|
||||
|
||||
lastTime += time;
|
||||
f = lastTime * @if;
|
||||
last = Interpolate(f);
|
||||
return last;
|
||||
}
|
||||
|
||||
public float NextFrame()
|
||||
{
|
||||
if (array == null || array.Length < 1) return 0;
|
||||
|
||||
f += deltaFrame;
|
||||
lastTime = f / @if;
|
||||
last = Interpolate(f);
|
||||
return last;
|
||||
}
|
||||
|
||||
private float Interpolate(float frame)
|
||||
{
|
||||
float f = (int)frame;
|
||||
|
||||
int data = 0;
|
||||
int length = array.Length;
|
||||
while (length > 0)
|
||||
if (f <= array[data + (length >> 1)].F)
|
||||
length >>= 1;
|
||||
else
|
||||
{
|
||||
int delta = (length >> 1) + 1;
|
||||
data += delta;
|
||||
length -= delta;
|
||||
}
|
||||
|
||||
if (data == 0)
|
||||
return firstKey.V;
|
||||
else if (data >= array.Length)
|
||||
return lastKey.V;
|
||||
|
||||
KFT2 c = array[data - 1];
|
||||
KFT2 n = array[data];
|
||||
float result = c.F == n.F ? c.V : n.V;
|
||||
if (frame < n.F)
|
||||
{
|
||||
|
||||
float t = (this.f - c.F) / (n.F - c.F);
|
||||
float t_1 = t - 1;
|
||||
result = (t_1 * 2 - 1) * (c.V - n.V) * t * t +
|
||||
(t_1 * c.T + t * n.T) * t_1 * (this.f - c.F) + c.V;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void ResetFrameCount() => f = -deltaFrame;
|
||||
|
||||
public override string ToString() => $"Frame: {f}, Value: {last}";
|
||||
}
|
||||
}
|
||||
+36
-16
@@ -1,10 +1,10 @@
|
||||
namespace KKdBaseLib
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct KFT0 : IKF
|
||||
{
|
||||
public float F;
|
||||
|
||||
public KFT0(float F = 0)
|
||||
public KFT0(float F)
|
||||
{ this.F = F; }
|
||||
|
||||
public KFT0 ToT0() => this;
|
||||
@@ -33,7 +33,7 @@
|
||||
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;
|
||||
@@ -49,13 +49,16 @@
|
||||
public static bool operator ==(KFT0 a, KFT0 b) => a.F == b.F;
|
||||
public static bool operator !=(KFT0 a, KFT0 b) => a.F != b.F;
|
||||
}
|
||||
|
||||
|
||||
public struct KFT1 : IKF
|
||||
{
|
||||
public float F;
|
||||
public float V;
|
||||
|
||||
public KFT1(float F = 0, float V = 0)
|
||||
public KFT1(float F)
|
||||
{ this.F = F; V = 0; }
|
||||
|
||||
public KFT1(float F, float V)
|
||||
{ this.F = F; this.V = V; }
|
||||
|
||||
public KFT0 ToT0() =>
|
||||
@@ -67,7 +70,7 @@
|
||||
new KFT3(F, V);
|
||||
|
||||
public IKF Check() =>
|
||||
V == 0 ? (KFT0)this : (IKF)this;
|
||||
V.ToU32() == 0x00000000 ? (KFT0)this : (IKF)this;
|
||||
|
||||
public override string ToString() => ToString(true, 7);
|
||||
public string ToString(int round = 7, bool brackets = true) =>
|
||||
@@ -86,7 +89,7 @@
|
||||
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;
|
||||
@@ -102,14 +105,20 @@
|
||||
public static bool operator ==(KFT1 a, KFT1 b) => a.F == b.F && a.V == b.V;
|
||||
public static bool operator !=(KFT1 a, KFT1 b) => a.F != b.F || a.V != b.V;
|
||||
}
|
||||
|
||||
|
||||
public struct KFT2 : IKF
|
||||
{
|
||||
public float F;
|
||||
public float V;
|
||||
public float T;
|
||||
|
||||
public KFT2(float F = 0, float V = 0, float T = 0)
|
||||
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() =>
|
||||
@@ -118,15 +127,15 @@
|
||||
new KFT1(F, V);
|
||||
public KFT2 ToT2() => this;
|
||||
public KFT3 ToT3() =>
|
||||
new KFT3(F, V, T, T);
|
||||
new KFT3(F, V, T);
|
||||
|
||||
public KFT3 ToT3(IKF Previous) =>
|
||||
Previous is KFT2 PreviousT2 ?
|
||||
Previous is KFT2 PreviousT2 ?
|
||||
new KFT3(F, V, PreviousT2.T, T) :
|
||||
new KFT3(F, V, T, T);
|
||||
|
||||
public IKF Check() =>
|
||||
T == 0 ? (V == 0 ? (IKF)ToT0() : ToT1()) : this;
|
||||
T.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) =>
|
||||
@@ -145,7 +154,7 @@
|
||||
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;
|
||||
@@ -161,7 +170,7 @@
|
||||
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;
|
||||
@@ -169,7 +178,16 @@
|
||||
public float T1;
|
||||
public float T2;
|
||||
|
||||
public KFT3(float F = 0, float V = 0, float T1 = 0, float T2 = 0)
|
||||
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() =>
|
||||
@@ -181,7 +199,9 @@
|
||||
public KFT3 ToT3() => this;
|
||||
|
||||
public IKF Check() =>
|
||||
T1 == 0 && T2 == 0 ? (V == 0 ? (IKF)(KFT0)this : (KFT1)this) : T1 == T2 ? (KFT2)this : (IKF)this;
|
||||
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) =>
|
||||
|
||||
@@ -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>{437F63F1-8C23-429E-AB14-38B85C9EDB16}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>KKdBaseLib</RootNamespace>
|
||||
<AssemblyName>KKdBaseLib</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
<Authors>korenkonder</Authors>
|
||||
<Company></Company>
|
||||
<Configuration></Configuration>
|
||||
<Copyright>korenkonder (C) 2019-2021</Copyright>
|
||||
<Description>A base library</Description>
|
||||
<FileVersion>0.4.10.2</FileVersion>
|
||||
<PackageId>KKdBaseLib</PackageId>
|
||||
<Product>KKdBaseLib</Product>
|
||||
<TargetFramework>net461</TargetFramework>
|
||||
<Title>KKdBaseLib</Title>
|
||||
<Version>0.4.10.2</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -23,7 +24,7 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
|
||||
<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>
|
||||
@@ -36,39 +37,9 @@
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
|
||||
<NoWarn>IDE0004, IDE0018, IDE0032, IDE0044, IDE0045, IDE0046, IDE0051, IDE0055, IDE0059, IDE0063, IDE0066, IDE0069, IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="F2\ENRS.cs" />
|
||||
<Compile Include="F2\Header.cs" />
|
||||
<Compile Include="F2\POF.cs" />
|
||||
<Compile Include="F2\Struct.cs" />
|
||||
<Compile Include="Interpolation\A3DAI.cs" />
|
||||
<Compile Include="Interpolation\IInterpolation.cs" />
|
||||
<Compile Include="Interpolation\PDI.cs" />
|
||||
<Compile Include="A3DA.cs" />
|
||||
<Compile Include="A3DAKey.cs" />
|
||||
<Compile Include="Aet.cs" />
|
||||
<Compile Include="DCC.cs" />
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="Format.cs" />
|
||||
<Compile Include="Half.cs" />
|
||||
<Compile Include="Interfaces.cs" />
|
||||
<Compile Include="KF.cs" />
|
||||
<Compile Include="KKdList.cs" />
|
||||
<Compile Include="MsgPack.cs" />
|
||||
<Compile Include="Pointer.cs" />
|
||||
<Compile Include="Text.cs" />
|
||||
<Compile Include="Vector.cs" />
|
||||
<Compile Include="Vector3.cs" />
|
||||
<Compile Include="Vector4.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
</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})";
|
||||
}
|
||||
}
|
||||
+95
-43
@@ -1,33 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct KKdList<T> : System.IDisposable, IEnumerator, IEnumerable, INull
|
||||
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 };
|
||||
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;
|
||||
|
||||
public int Count { get; private set; }
|
||||
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; } }
|
||||
set { if (array != null) System.Array.Resize(ref array, value); else array = new T[value];
|
||||
if (Count >= value) count = value; } }
|
||||
|
||||
|
||||
public KKdList(T[] Array)
|
||||
{ index = 0; Count = Array.Length; array = Array; }
|
||||
public 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 < Count ? array[index] : default;
|
||||
public T Current => index > -1 && index < Count ? array[index] : default;
|
||||
|
||||
object IEnumerator.Current => Current;
|
||||
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;
|
||||
@@ -37,44 +57,45 @@ namespace KKdBaseLib
|
||||
{ get => array != null && index < array.Length ? array[index] : default;
|
||||
set { if (array != null && index < array.Length) array[index] = value; } }
|
||||
|
||||
public bool MoveNext()
|
||||
{ if (index == Count - 1) { index = 0; return false; }
|
||||
else { index++ ; return true; } }
|
||||
public 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() => this;
|
||||
public IEnumerator GetEnumerator() => enumerator = new Enumerator(array);
|
||||
|
||||
public void Dispose() { array = null; Count = 0; index = 0; }
|
||||
IEnumerator<T> IEnumerable<T>.GetEnumerator() => enumerator = new Enumerator(array);
|
||||
|
||||
public void Reset() => index = 0;
|
||||
IEnumerator IEnumerable.GetEnumerator() => enumerator = new Enumerator(array);
|
||||
|
||||
public void Dispose() { array = null; count = 0; index = -1; }
|
||||
|
||||
public void Add(T item)
|
||||
{
|
||||
if (IsNull) return;
|
||||
|
||||
Count++;
|
||||
if (array.Length < Count)
|
||||
System.Array.Resize(ref array, Count);
|
||||
array[Count - 1] = item;
|
||||
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) return;
|
||||
if (IsNull || index < 0 || index >= count) return;
|
||||
|
||||
for (int i = index + 1; i < Count; i++)
|
||||
array[i - 1] = array[i];
|
||||
Count--;
|
||||
if (index + 1 < count)
|
||||
System.Array.Copy(array, index + 1, array, index, count - index - 1);
|
||||
count--;
|
||||
}
|
||||
|
||||
public void RemoveRange(int IndexStart, int IndexEnd)
|
||||
public void RemoveRange(int indexStart, int indexEnd)
|
||||
{
|
||||
if (IsNull) return;
|
||||
if (IndexEnd - IndexStart < 1) return;
|
||||
int indexCount = indexEnd - indexStart;
|
||||
if (IsNull || indexCount < 1 || indexStart < 0 || indexEnd > count) return;
|
||||
|
||||
if (IndexEnd - IndexStart != Count)
|
||||
for (int i = IndexStart; i < Count; i++)
|
||||
array[i] = array[i + IndexEnd - IndexStart];
|
||||
Count -= IndexEnd - IndexStart;
|
||||
if ((indexEnd + indexCount) < count)
|
||||
System.Array.Copy(array, indexEnd, array, indexStart, indexCount);
|
||||
count -= indexCount;
|
||||
}
|
||||
|
||||
public T[] ToArray() => array;
|
||||
@@ -82,34 +103,65 @@ namespace KKdBaseLib
|
||||
public bool Contains(T val)
|
||||
{
|
||||
if (IsNull) return false;
|
||||
for (int i = 0; i < Count; i++)
|
||||
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;
|
||||
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++)
|
||||
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;
|
||||
else if (array[i].Equals(val)) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void Sort()
|
||||
{ List<T> List = this; List.Sort(); array = List.ToArray(); Count = List.Count; }
|
||||
{ Capacity = Count; List<T> List = (List<T>)this; List.Sort();
|
||||
array = List.ToArray(); count = List.Count; }
|
||||
|
||||
public static implicit operator KKdList<T>( List<T> List) =>
|
||||
new KKdList<T> { array = List.ToArray(), Count = List.Count };
|
||||
public static explicit operator KKdList<T>( List<T> list) =>
|
||||
new KKdList<T> { array = list.ToArray(), count = list.Count };
|
||||
|
||||
public static implicit operator List<T>(KKdList<T> List)
|
||||
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
|
||||
{
|
||||
List<T> list = new List<T>();
|
||||
for (int i = 0; i < List.Count; i++) list.Add(List[i]);
|
||||
return list;
|
||||
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,284 @@
|
||||
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;
|
||||
sort[i++] = ++j;
|
||||
if (j * 10 >= length)
|
||||
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)})";
|
||||
}
|
||||
}
|
||||
+134
-83
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
@@ -6,27 +6,25 @@ namespace KKdBaseLib
|
||||
{
|
||||
public string Name;
|
||||
public object Object;
|
||||
|
||||
|
||||
public MsgPack[] Array => Object is MsgPack[] Array ? Array : null;
|
||||
public KKdList<MsgPack> List => Object is KKdList<MsgPack> List ? List : default;
|
||||
|
||||
public static MsgPack New => new MsgPack { Object = KKdList<MsgPack>.New };
|
||||
public static MsgPack NewReserve(int Capacity) =>
|
||||
new MsgPack { Object = KKdList<MsgPack>.NewReserve(Capacity) };
|
||||
public static MsgPack NewReserve(int capacity) =>
|
||||
new MsgPack { Object = KKdList<MsgPack>.NewReserve(capacity) };
|
||||
|
||||
public bool IsNull => Array == null && List. IsNull;
|
||||
public bool NotNull => Array != null || List.NotNull;
|
||||
|
||||
public MsgPack( string Name = null)
|
||||
{ Object = KKdList<MsgPack>.New; this.Name = Name; }
|
||||
public MsgPack( string name = null)
|
||||
{ Object = KKdList<MsgPack>.New; Name = name; }
|
||||
|
||||
public MsgPack(long Count, string Name = null)
|
||||
{ Object = Count > 0 ? new MsgPack[Count] : null; this.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)
|
||||
{ this.Name = Name; this.Object = Object; }
|
||||
|
||||
public static MsgPack Null => new MsgPack();
|
||||
public MsgPack(string name, object @object)
|
||||
{ Name = name; Object = @object; }
|
||||
|
||||
public MsgPack this[ int index]
|
||||
{ get => Object is MsgPack[] Array ? Array[index] : default;
|
||||
@@ -36,14 +34,25 @@ namespace KKdBaseLib
|
||||
{ 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; }
|
||||
{ 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)];
|
||||
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; }
|
||||
|
||||
@@ -69,7 +78,7 @@ namespace KKdBaseLib
|
||||
public static implicit operator MsgPack( ulong val) => new MsgPack(null, val);
|
||||
public static implicit operator MsgPack( float val) => new MsgPack(null, val);
|
||||
public static implicit operator MsgPack(double val) => new MsgPack(null, val);
|
||||
|
||||
|
||||
public MsgPack Add( bool? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( sbyte? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
public MsgPack Add( byte? val) => val.HasValue ? Add(new MsgPack(null, val.Value)) : this;
|
||||
@@ -95,81 +104,106 @@ namespace KKdBaseLib
|
||||
public MsgPack Add( ulong val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add( float val) => Add(new MsgPack(null, val));
|
||||
public MsgPack Add(double val) => Add(new MsgPack(null, val));
|
||||
|
||||
public MsgPack Add(string Val, bool? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, sbyte? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, byte? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, short? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, ushort? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, int? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, uint? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, long? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, ulong? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, float? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
public MsgPack Add(string Val, double? val) => val.HasValue ? Add(Val, val.Value) : this;
|
||||
|
||||
public MsgPack Add(string Val, byte[] val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, string val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, bool val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, sbyte val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, byte val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, short val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, ushort val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, int val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, uint val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, long val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, ulong val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, float val) => Add(new MsgPack(Val, val));
|
||||
public MsgPack Add(string Val, double val) => Add(new MsgPack(Val, val));
|
||||
|
||||
public bool RB (string Name) => RnB (Name) ?? default;
|
||||
public sbyte RI8 (string Name) => RnI8 (Name) ?? default;
|
||||
public byte RU8 (string Name) => RnU8 (Name) ?? default;
|
||||
public short RI16(string Name) => RnI16(Name) ?? default;
|
||||
public ushort RU16(string Name) => RnU16(Name) ?? default;
|
||||
public int RI32(string Name) => RnI32(Name) ?? default;
|
||||
public uint RU32(string Name) => RnU32(Name) ?? default;
|
||||
public long RI64(string Name) => RnI64(Name) ?? default;
|
||||
public ulong RU64(string Name) => RnU64(Name) ?? default;
|
||||
public float RF32(string Name) => RnF32(Name) ?? default;
|
||||
public double RF64(string Name) => RnF64(Name) ?? default;
|
||||
public 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 bool? RnB (string Name)
|
||||
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];
|
||||
MsgPack MsgPack = this[name];
|
||||
if (MsgPack.Object is bool B ) return B ; return null;
|
||||
}
|
||||
public sbyte? RnI8 (string Name)
|
||||
public sbyte? RnI8 (string name)
|
||||
{
|
||||
MsgPack MsgPack = this[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)
|
||||
public byte? RnU8 (string name)
|
||||
{
|
||||
MsgPack MsgPack = this[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)
|
||||
public short? RnI16(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[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)
|
||||
public ushort? RnU16(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[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)
|
||||
public int? RnI32(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[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;
|
||||
@@ -177,9 +211,9 @@ namespace KKdBaseLib
|
||||
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)
|
||||
public uint? RnU32(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[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;
|
||||
@@ -187,9 +221,9 @@ namespace KKdBaseLib
|
||||
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)
|
||||
public long? RnI64(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[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;
|
||||
@@ -199,9 +233,9 @@ namespace KKdBaseLib
|
||||
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)
|
||||
public ulong? RnU64(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[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;
|
||||
@@ -210,9 +244,9 @@ namespace KKdBaseLib
|
||||
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)
|
||||
public float? RnF32(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[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;
|
||||
@@ -223,9 +257,9 @@ namespace KKdBaseLib
|
||||
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)
|
||||
public double? RnF64(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[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;
|
||||
@@ -236,9 +270,9 @@ namespace KKdBaseLib
|
||||
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)
|
||||
public string RS(string name)
|
||||
{
|
||||
MsgPack MsgPack = this[Name];
|
||||
MsgPack MsgPack = this[name];
|
||||
if (MsgPack.Object is string S ) return S ; return null;
|
||||
}
|
||||
|
||||
@@ -253,7 +287,7 @@ namespace KKdBaseLib
|
||||
public ulong RU64() => RnU64() ?? default;
|
||||
public float RF32() => RnF32() ?? default;
|
||||
public double RF64() => RnF64() ?? default;
|
||||
|
||||
|
||||
public bool? RnB ()
|
||||
{ if (Object is bool B ) return B ; return null; }
|
||||
public sbyte? RnI8 ()
|
||||
@@ -326,23 +360,34 @@ namespace KKdBaseLib
|
||||
public string RS ()
|
||||
{ if (Object is string S ) return S ; return null; }
|
||||
|
||||
public MsgPack Element(string Name)
|
||||
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];
|
||||
if (List[i].Name == name) return List[i];
|
||||
return default;
|
||||
}
|
||||
|
||||
public bool ContainsKey(string Name) => ElementIndex(Name) > -1;
|
||||
public bool ContainsKey(string name) => ElementIndex(name) > -1;
|
||||
|
||||
public int ElementIndex(string Name)
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -353,4 +398,10 @@ namespace KKdBaseLib
|
||||
public byte[] Data;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IMsgPack : INull
|
||||
{
|
||||
//public void ReadMsgPack();
|
||||
public MsgPack WriteMsgPack(string name);
|
||||
}
|
||||
}
|
||||
|
||||
+30
-2
@@ -1,4 +1,4 @@
|
||||
namespace KKdBaseLib
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct Pointer<T>
|
||||
{
|
||||
@@ -13,7 +13,35 @@
|
||||
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;
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
using System.Reflection;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("KKdBaseLib")]
|
||||
[assembly: AssemblyDescription("A base library")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("KKdBaseLib")]
|
||||
[assembly: AssemblyCopyright("korenkonder © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("437F63F1-8C23-429E-AB14-38B85C9EDB16")]
|
||||
[assembly: AssemblyVersion("0.4.8.0")]
|
||||
[assembly: AssemblyFileVersion("0.4.8.0")]
|
||||
|
||||
@@ -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}";
|
||||
}
|
||||
}
|
||||
+7
-4
@@ -1,16 +1,19 @@
|
||||
using System.Text;
|
||||
using System.Text;
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public static class Text
|
||||
{
|
||||
public readonly static Encoding ShiftJIS = Encoding.GetEncoding(932);
|
||||
|
||||
|
||||
public static string ToASCII(this byte[] Array) => Encoding.ASCII.GetString(Array ?? new byte[0]);
|
||||
public static string ToUTF8 (this byte[] Array) => Encoding.UTF8 .GetString(Array ?? new byte[0]);
|
||||
public static byte[] ToASCII(this string Data ) => Encoding.ASCII.GetBytes (Data ?? "" );
|
||||
public static byte[] ToUTF8 (this string Data ) => Encoding.UTF8 .GetBytes (Data ?? "" );
|
||||
public static byte[] ToASCII(this char[] Data ) => Encoding.ASCII.GetBytes (Data ?? new char[0]);
|
||||
public static 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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
namespace KKdBaseLib
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct Vector2<T> : INull
|
||||
public struct Vec2<T> : INull
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
|
||||
public Vector2(T X, T Y)
|
||||
{ this.X = X; this.Y = 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 Vector3<T> : INull
|
||||
|
||||
public struct Vec3<T> : INull
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
public T Z;
|
||||
|
||||
public Vector3(T X, T Y, T Z)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; }
|
||||
|
||||
public 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 Vector4<T> : INull
|
||||
public struct Vec4<T> : INull
|
||||
{
|
||||
public T X;
|
||||
public T Y;
|
||||
public T Z;
|
||||
public T W;
|
||||
|
||||
public Vector4(T X, T Y, T Z, T W)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; this.W = W; }
|
||||
|
||||
public 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;
|
||||
|
||||
@@ -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)})";
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct Vector3
|
||||
{
|
||||
public float X;
|
||||
public float Y;
|
||||
public float Z;
|
||||
|
||||
public Vector3(float X, float Y, float Z)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; }
|
||||
|
||||
public float Length => (X * X + Y * Y + Z * Z).Sqrt();
|
||||
public Vector3 Normalized => this = Length == 0 ? new Vector3() : this / Length;
|
||||
|
||||
public static Vector3 operator +(Vector3 left, Vector3 right)
|
||||
{ left.X += right.X; left.Y += right.Y; left.Z += right.Z; return left; }
|
||||
public static Vector3 operator -(Vector3 left, Vector3 right)
|
||||
{ left.X -= right.X; left.Y -= right.Y; left.Z -= right.Z; return left; }
|
||||
public static Vector3 operator -(Vector3 vec)
|
||||
{ vec.X = -vec.X; vec.Y = -vec.Y; vec.Z = -vec.Z; return vec; }
|
||||
public static Vector3 operator *(Vector3 vec, float scale)
|
||||
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; return vec; }
|
||||
public static Vector3 operator *( float scale, Vector3 vec)
|
||||
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; return vec; }
|
||||
public static Vector3 operator *(Vector3 vec, Vector3 scale)
|
||||
{ vec.X *= scale.X; vec.Y *= scale.Y; vec.Z *= scale.Z; return vec; }
|
||||
public static Vector3 operator /(Vector3 vec, float scale)
|
||||
{ vec.X /= scale ; vec.Y /= scale ; vec.Z /= scale ; return vec; }
|
||||
public static Vector3 operator /(Vector3 vec, Vector3 scale)
|
||||
{ vec.X /= scale.X; vec.Y /= scale.Y; vec.Z /= scale.Z; return vec; }
|
||||
public static bool operator ==(Vector3 A, Vector3 B) => A.Equals(B);
|
||||
public static bool operator !=(Vector3 A, Vector3 B) => !A.Equals(B);
|
||||
|
||||
public static double Distance (Vector3 left, Vector3 right) =>
|
||||
(right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) *
|
||||
(right.Y - left.Y) + (right.Z - left.Z) * (right.Z - left.Z).Sqrt();
|
||||
public static double DistanceSquared(Vector3 left, Vector3 right) =>
|
||||
(right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) *
|
||||
(right.Y - left.Y) + (right.Z - left.Z) * (right.Z - left.Z);
|
||||
public static double Dot(Vector3 left, Vector3 right) =>
|
||||
left.X * right.X + left.Y * right.Y + left.Z * right.Z;
|
||||
public static Vector3 Cross(Vector3 left, Vector3 right) =>
|
||||
new Vector3 { X = left.Y * right.Z - left.Z * right.Y,
|
||||
Y = left.Z * right.X - left.X * right.Z,
|
||||
Z = left.X * right.Y - left.Y * right.X, };
|
||||
public static Vector3 Lerp(Vector3 a, Vector3 b, float blend) =>
|
||||
new Vector3 { X = blend * (b.X - a.X) + a.X,
|
||||
Y = blend * (b.Y - a.Y) + a.Y,
|
||||
Z = blend * (b.Z - a.Z) + a.Z };
|
||||
public static Vector3 Lerp(Vector3 a, Vector3 b, Vector3 blend) =>
|
||||
new Vector3 { X = blend.X * (b.X - a.X) + a.X,
|
||||
Y = blend.Y * (b.Y - a.Y) + a.Y,
|
||||
Z = blend.Z * (b.Z - a.Z) + a.Z };
|
||||
public Vector3 Round( ) =>
|
||||
new Vector3 { X = X.Round( ), Y = Y.Round( ), Z = Z.Round( ) };
|
||||
public Vector3 Round(int d) =>
|
||||
new Vector3 { X = X.Round(d), Y = Y.Round(d), Z = Z.Round(d) };
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int hashCode = X.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ Y.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ Z.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
public override bool Equals(object obj) =>
|
||||
obj is Vector3 vec ? Equals(vec) : false;
|
||||
public bool Equals(Vector3 other) =>
|
||||
X == other.X && Y == other.Y && Z == other.Z;
|
||||
|
||||
public override string ToString() => $"({X}; {Y}, {Z})";
|
||||
public string ToString(int d) => $"({X.Round(d)}; {Y.Round(d)}, {Z.Round(d)})";
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public struct Vector4
|
||||
{
|
||||
public float X;
|
||||
public float Y;
|
||||
public float Z;
|
||||
public float W;
|
||||
|
||||
public Vector4(float X, float Y, float Z, float W)
|
||||
{ this.X = X; this.Y = Y; this.Z = Z; this.W = W; }
|
||||
|
||||
public float Length => (X * X + Y * Y + Z * Z + W * W).Sqrt();
|
||||
public Vector4 Normalized => this = Length == 0 ? new Vector4() : this / Length;
|
||||
|
||||
public static Vector4 operator +(Vector4 left, Vector4 right)
|
||||
{ left.X += right.X; left.Y += right.Y; left.Z += right.Z; left.W += right.W; return left; }
|
||||
public static Vector4 operator -(Vector4 left, Vector4 right)
|
||||
{ left.X -= right.X; left.Y -= right.Y; left.Z -= right.Z; left.W -= right.W; return left; }
|
||||
public static Vector4 operator -(Vector4 vec)
|
||||
{ vec.X = -vec.X; vec.Y = -vec.Y; vec.Z = -vec.Z; vec.W = -vec.W; return vec; }
|
||||
public static Vector4 operator *(Vector4 vec, float scale)
|
||||
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; vec.W *= scale ; return vec; }
|
||||
public static Vector4 operator *( float scale, Vector4 vec)
|
||||
{ vec.X *= scale ; vec.Y *= scale ; vec.Z *= scale ; vec.W *= scale ; return vec; }
|
||||
public static Vector4 operator *(Vector4 vec, Vector4 scale)
|
||||
{ vec.X *= scale.X; vec.Y *= scale.Y; vec.Z *= scale.Z; vec.W *= scale.W; return vec; }
|
||||
public static Vector4 operator /(Vector4 vec, float scale)
|
||||
{ vec.X /= scale ; vec.Y /= scale ; vec.Z /= scale ; vec.W /= scale ; return vec; }
|
||||
public static Vector4 operator /(Vector4 vec, Vector4 scale)
|
||||
{ vec.X /= scale.X; vec.Y /= scale.Y; vec.Z /= scale.Z; vec.W /= scale.W; return vec; }
|
||||
public static bool operator ==(Vector4 A, Vector4 B) => A.Equals(B);
|
||||
public static bool operator !=(Vector4 A, Vector4 B) => !A.Equals(B);
|
||||
|
||||
public static double Distance (Vector4 left, Vector4 right) =>
|
||||
((right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) * (right.Y - left.Y) +
|
||||
(right.Z - left.Z) * (right.Z - left.Z) + (right.W - left.W) * (right.W - left.W)).Sqrt();
|
||||
public static double DistanceSquared(Vector4 left, Vector4 right) =>
|
||||
(right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) * (right.Y - left.Y) +
|
||||
(right.Z - left.Z) * (right.Z - left.Z) + (right.W - left.W) * (right.W - left.W);
|
||||
public static double Dot(Vector4 left, Vector4 right) =>
|
||||
left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W;
|
||||
public static Vector4 Lerp(Vector4 a, Vector4 b, float blend) =>
|
||||
new Vector4 { X = blend * (b.X - a.X) + a.X,
|
||||
Y = blend * (b.Y - a.Y) + a.Y,
|
||||
Z = blend * (b.Z - a.Z) + a.Z,
|
||||
W = blend * (b.W - a.W) + a.W };
|
||||
public static Vector4 Lerp(Vector4 a, Vector4 b, Vector4 blend) =>
|
||||
new Vector4 { X = blend.X * (b.X - a.X) + a.X,
|
||||
Y = blend.Y * (b.Y - a.Y) + a.Y,
|
||||
Z = blend.Z * (b.Z - a.Z) + a.Z,
|
||||
W = blend.W * (b.W - a.W) + a.W };
|
||||
public Vector4 Round( ) =>
|
||||
new Vector4 { X = X.Round( ), Y = Y.Round( ), Z = Z.Round( ), W = W.Round( ) };
|
||||
public Vector4 Round(int d) =>
|
||||
new Vector4 { X = X.Round(d), Y = Y.Round(d), Z = Z.Round(d), W = W.Round(d) };
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int hashCode = X.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ Y.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ Z.GetHashCode();
|
||||
hashCode = (hashCode * 397) ^ W.GetHashCode();
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
public override bool Equals(object obj) =>
|
||||
obj is Vector4 vec ? Equals(vec) : false;
|
||||
public bool Equals(Vector4 other) =>
|
||||
X == other.X && Y == other.Y && Z == other.Z && W == other.W;
|
||||
|
||||
public override string ToString() => $"({X}; {Y}, {Z}, {W})";
|
||||
public string ToString(int d) => $"({X.Round(d)}; {Y.Round(d)}, {Z.Round(d)}, {W.Round(d)})";
|
||||
}
|
||||
}
|
||||
+1021
-843
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,146 @@
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public unsafe struct AddParam : System.IDisposable
|
||||
{
|
||||
private long i;
|
||||
private Stream s;
|
||||
|
||||
public HeaderData Header;
|
||||
|
||||
public void AddParamReader(string file)
|
||||
{
|
||||
Header = new HeaderData();
|
||||
|
||||
s = File.OpenReader(file + ".adp");
|
||||
Header.Count = s.RI64();
|
||||
Header.DataLength = s.RI64();
|
||||
Header.DataOffset = s.RI64();
|
||||
|
||||
if (Header.Count < 1 || Header.DataOffset > s.P || Header.DataLength > s.LI64
|
||||
- Header.DataOffset || Header.Count * 0x20 > s.LI64 - Header.DataOffset) { s.C(); return; }
|
||||
|
||||
Header.Data = new HeaderData.Sub[Header.Count];
|
||||
byte[] data = s.RBy(Header.DataLength, Header.DataOffset);
|
||||
s.C();
|
||||
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
HeaderData.Sub* hPtr = (HeaderData.Sub*)ptr;
|
||||
for (i = 0; i < Header.Count; i++)
|
||||
Header.Data[i] = hPtr[i];
|
||||
}
|
||||
|
||||
data = null;
|
||||
}
|
||||
|
||||
public void AddParamWriter(string file)
|
||||
{
|
||||
if (Header.Data == null || Header.Data.LongLength < 1) return;
|
||||
|
||||
Header.Count = Header.Data.LongLength;
|
||||
Header.DataLength = Header.Count * 0x20;
|
||||
Header.DataOffset = 0x18L;
|
||||
|
||||
byte[] data = new byte[Header.DataLength];
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
HeaderData.Sub* hPtr = (HeaderData.Sub*)ptr;
|
||||
for (i = 0; i < Header.Count; i++)
|
||||
hPtr[i] = Header.Data[i];
|
||||
}
|
||||
|
||||
s = File.OpenWriter(file + ".adp", true);
|
||||
s.W(Header.Count);
|
||||
s.W(Header.DataLength);
|
||||
s.W(Header.DataOffset);
|
||||
s.W(data);
|
||||
s.C();
|
||||
data = null;
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
{
|
||||
Header = new HeaderData();
|
||||
|
||||
MsgPack addParam;
|
||||
MsgPack msgPack = file.ReadMPAllAtOnce(json);
|
||||
if ((addParam = msgPack["AddParam", true]).IsNull) return;
|
||||
|
||||
Header.Count = addParam.Array.LongLength;
|
||||
Header.Data = new HeaderData.Sub[Header.Count];
|
||||
for (i = 0; i < Header.Count; i++)
|
||||
{
|
||||
ref HeaderData.Sub sub = ref Header.Data[i];
|
||||
sub.Time = addParam[i].RF32("Time");
|
||||
sub.Flags = addParam[i].RI32("Flags");
|
||||
sub.Frame = addParam[i].RI32("Frame");
|
||||
sub.ID = addParam[i].RI32("ID");
|
||||
sub.Value = addParam[i].RF32("Value");
|
||||
|
||||
sub.PVBranch = addParam[i].RnI32("PVBranch") ?? 0;
|
||||
float? f = addParam[i].RnF32("Value");
|
||||
if (f.HasValue)
|
||||
{
|
||||
if (sub.ID == 0) { float v = 0; *(uint*)&v = addParam[i].RU32("Value"); sub.Value = v; }
|
||||
else sub.Value = f.Value;
|
||||
}
|
||||
else { float v = 0; *(uint*)&v = 0xFFFFFFFF; sub.Value = v; }
|
||||
|
||||
}
|
||||
|
||||
msgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
if (Header.Data == null || Header.Data.LongLength < 1) return;
|
||||
|
||||
MsgPack addParam = new MsgPack(Header.Data.LongLength, "AddParam");
|
||||
fixed (HeaderData.Sub* ptr = Header.Data)
|
||||
for (i = 0; i < Header.Count; i++)
|
||||
{
|
||||
ref HeaderData.Sub sub = ref Header.Data[i];
|
||||
addParam[i] = MsgPack.New.Add("Time", sub.Time).Add("Flags", sub.Flags).Add("Frame", sub.Frame);
|
||||
|
||||
if (sub.PVBranch > 0)
|
||||
addParam[i] = addParam[i].Add("PVBranch", sub.PVBranch);
|
||||
|
||||
addParam[i] = addParam[i].Add("ID", sub.ID);
|
||||
|
||||
if (sub.ID == 0)
|
||||
addParam[i] = addParam[i].Add("Value", *(uint*)&ptr[i].Value);
|
||||
else if (*(uint*)&ptr[i].Value != 0xFFFFFFFF)
|
||||
addParam[i] = addParam[i].Add("Value", sub.Value);
|
||||
|
||||
}
|
||||
addParam.WriteAfterAll(false, true, file, json);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{ if (s != null) s.D(); s = null; Header = default; }
|
||||
|
||||
public struct HeaderData
|
||||
{
|
||||
public long Count;
|
||||
public long DataLength;
|
||||
public long DataOffset;
|
||||
|
||||
public Sub[] Data;
|
||||
|
||||
public struct Sub
|
||||
{
|
||||
public float Time;
|
||||
public int Flags;
|
||||
public int Frame;
|
||||
public int Pad0C;
|
||||
public int PVBranch;
|
||||
public int ID;
|
||||
public float Value;
|
||||
public int Pad1C;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+579
-571
File diff suppressed because it is too large
Load Diff
+84
-84
@@ -1,6 +1,5 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
@@ -9,39 +8,39 @@ namespace KKdMainLib.DB
|
||||
public class Aet : System.IDisposable
|
||||
{
|
||||
private int i, i0, i1, i2;
|
||||
private Stream _IO;
|
||||
private Stream s;
|
||||
|
||||
public AetSet[] AetSets;
|
||||
|
||||
public void BINReader(string file)
|
||||
{
|
||||
_IO = File.OpenReader(file + ".bin");
|
||||
s = File.OpenReader(file + ".bin");
|
||||
|
||||
int aetSetsLength = _IO.RI32();
|
||||
int aetSetsOffset = _IO.RI32();
|
||||
int aetsLength = _IO.RI32();
|
||||
int aetsOffset = _IO.RI32();
|
||||
int aetSetsLength = s.RI32();
|
||||
int aetSetsOffset = s.RI32();
|
||||
int aetsLength = s.RI32();
|
||||
int aetsOffset = s.RI32();
|
||||
|
||||
_IO.P = aetSetsOffset;
|
||||
s.P = aetSetsOffset;
|
||||
AetSets = new AetSet[aetSetsLength];
|
||||
for (i = 0; i < aetSetsLength; i++)
|
||||
{
|
||||
AetSets[i].Id = _IO.RI32();
|
||||
AetSets[i].Name = _IO.RSaO();
|
||||
AetSets[i].FileName = _IO.RSaO();
|
||||
_IO.RI32();
|
||||
AetSets[i].SpriteSetId = _IO.RI32();
|
||||
AetSets[i].Id = 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.P = aetsOffset;
|
||||
s.P = aetsOffset;
|
||||
for (i = 0; i < aetsLength; i++)
|
||||
{
|
||||
_IO.I64P += 10;
|
||||
setIndex = _IO.RI16();
|
||||
s.PI64 += 10;
|
||||
setIndex = s.RI16();
|
||||
AetCount[setIndex]++;
|
||||
}
|
||||
|
||||
@@ -51,18 +50,18 @@ namespace KKdMainLib.DB
|
||||
AetCount[i] = 0;
|
||||
}
|
||||
|
||||
_IO.P = aetsOffset;
|
||||
s.P = aetsOffset;
|
||||
for (i = 0; i < aetsLength; i++)
|
||||
{
|
||||
aet.Id = _IO.RI32();
|
||||
aet.Name = _IO.RSaO();
|
||||
_IO.RI16();
|
||||
setIndex = _IO.RI16();
|
||||
aet.Id = s.RI32();
|
||||
aet.Name = s.RSaO();
|
||||
s.RI16();
|
||||
setIndex = s.RI16();
|
||||
|
||||
AetSets[setIndex].Aets[AetCount[setIndex]] = aet; AetCount[setIndex]++;
|
||||
}
|
||||
|
||||
_IO.C();
|
||||
s.C();
|
||||
}
|
||||
|
||||
|
||||
@@ -71,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;
|
||||
|
||||
@@ -85,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)
|
||||
{
|
||||
@@ -99,93 +98,94 @@ 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.A(0x20) + 0x20;
|
||||
|
||||
_IO = File.OpenWriter(file + ".bin", true);
|
||||
_IO.W(i2);
|
||||
_IO.W(i1);
|
||||
_IO.W(i0);
|
||||
_IO.W(0x20);
|
||||
_IO.W(0x9066906690669066);
|
||||
_IO.W(0x9066906690669066);
|
||||
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.P = (i1 + i2 * 0x14).A(0x20);
|
||||
s.P = (i1 + i2 * 0x14).A(0x20);
|
||||
for (i = 0; i < AetSets.Length; i++)
|
||||
{
|
||||
if (NotAdd.Contains(i)) continue;
|
||||
AetSets[i]. NameOffset = _IO.P; _IO.W(AetSets[i]. Name + "\0");
|
||||
AetSets[i].FileNameOffset = _IO.P; _IO.W(AetSets[i].FileName + "\0");
|
||||
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.P; _IO.W(AetSets[i].Aets[i0].Name + "\0"); }
|
||||
{ AetSets[i].Aets[i0].NameOffset = s.P; s.W(AetSets[i].Aets[i0].Name + "\0"); }
|
||||
}
|
||||
_IO.A(0x08, true);
|
||||
|
||||
_IO.P = 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.W(AetSets[i].Aets[i0].Id );
|
||||
_IO.W(AetSets[i].Aets[i0].NameOffset);
|
||||
_IO.W((ushort) i0 );
|
||||
_IO.W((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.A(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.W(AetSets[i].Id );
|
||||
_IO.W(AetSets[i]. NameOffset);
|
||||
_IO.W(AetSets[i].FileNameOffset);
|
||||
_IO.W(i - i2);
|
||||
_IO.W(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.C();
|
||||
notAdd.Dispose();
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
@@ -213,12 +213,12 @@ namespace KKdMainLib.DB
|
||||
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 (_IO != null) _IO.D(); AetSets = null; disposed = true; } }
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; AetSets = null; disposed = true; } }
|
||||
|
||||
public struct AET
|
||||
{
|
||||
@@ -228,7 +228,7 @@ namespace KKdMainLib.DB
|
||||
|
||||
public void ReadMsgPack(MsgPack msg)
|
||||
{ Id = msg.RnU16("Id"); Name = msg.RS("Name"); }
|
||||
|
||||
|
||||
public MsgPack WriteMsgPack() =>
|
||||
MsgPack.New.Add("Id", Id).Add("Name", Name);
|
||||
}
|
||||
@@ -243,13 +243,13 @@ namespace KKdMainLib.DB
|
||||
public string Name;
|
||||
public string FileName;
|
||||
public AET[] Aets;
|
||||
|
||||
|
||||
public void ReadMsgPack(MsgPack msg)
|
||||
{
|
||||
FileName = msg.RS ("FileName" );
|
||||
FileName = msg.RS ("FileName" );
|
||||
Id = msg.RnU16( "Id");
|
||||
Name = msg.RS ( "Name" );
|
||||
NewId = msg.RB("NewId" );
|
||||
Name = msg.RS ( "Name" );
|
||||
NewId = msg.RB ("NewId" );
|
||||
SpriteSetId = msg.RnU16("SpriteSetId");
|
||||
|
||||
MsgPack Temp;
|
||||
|
||||
+38
-40
@@ -1,97 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using A3DADict = System.Collections.Generic.Dictionary<string, object>;
|
||||
|
||||
namespace KKdMainLib.DB
|
||||
{
|
||||
public class Auth : IDisposable
|
||||
{
|
||||
private int i;
|
||||
private Stream _IO;
|
||||
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 = Format.F;
|
||||
int signature = _IO.RI32();
|
||||
s.Format = Format.F;
|
||||
int signature = s.RI32();
|
||||
if (signature != 0x44334123) return;
|
||||
signature = _IO.RI32();
|
||||
signature = s.RI32();
|
||||
if (signature != 0x5F5F5F41) return;
|
||||
_IO.RI64();
|
||||
s.RI64();
|
||||
|
||||
string[] strData = _IO.RS(_IO.L - _IO.P).Replace("\r", "").Split('\n');
|
||||
string[] strData = s.RS(s.L - s.P).Replace("\r\n", "\n").Replace("\r", "\n").Split('\n');
|
||||
for (i = 0; i < strData.Length; i++)
|
||||
{
|
||||
dataArray = strData[i].Split('=');
|
||||
if (dataArray.Length == 2)
|
||||
dict.GetDictionary(dataArray[0], dataArray[1]);
|
||||
}
|
||||
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 (i = 0; i < Category.Length; i++)
|
||||
if (dict.FindValue(out value, "category." + i + ".value"))
|
||||
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"))
|
||||
{
|
||||
UIDs = new UID[int.Parse(value)];
|
||||
for (i = 0; i < UIDs.Length; i++)
|
||||
{
|
||||
dict.FindValue(out UIDs[i].Category, "uid." + i + ".category");
|
||||
dict.FindValue(out UIDs[i].OrgUid , "uid." + i + ".org_uid" );
|
||||
dict.FindValue(out UIDs[i].Size , "uid." + i + ".size" );
|
||||
dict.FindValue(out UIDs[i].Value , "uid." + i + ".value" );
|
||||
dict.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.C();
|
||||
s.C();
|
||||
dict.Clear();
|
||||
dict = null;
|
||||
}
|
||||
|
||||
public void BINWriter(string file)
|
||||
{
|
||||
_IO = File.OpenWriter(file + ".bin", true);
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
|
||||
_IO.W("#A3DA__________\n");
|
||||
_IO.W("#" + DateTime.UtcNow.ToString("ddd MMM dd HH:mm:ss yyyy",
|
||||
s.W("#A3DA__________\n");
|
||||
s.W("#" + DateTime.UtcNow.ToString("ddd MMM dd HH:mm:ss yyyy",
|
||||
System.Globalization.CultureInfo.InvariantCulture) + "\n");
|
||||
|
||||
if (Category != null)
|
||||
{
|
||||
int[] so = Category.Length.SortWriter();
|
||||
int[] so = Category.Length.SW();
|
||||
for (i = 0; i < Category.Length; i++)
|
||||
_IO.W($"category.{so[i]}.value={ Category[so[i]]}\n");
|
||||
_IO.W($"category.length={Category.Length}\n");
|
||||
s.W($"category.{so[i]}.value={ Category[so[i]]}\n");
|
||||
s.W($"category.length={Category.Length}\n");
|
||||
}
|
||||
|
||||
if (UIDs != null)
|
||||
{
|
||||
int[] so = UIDs.Length.SortWriter();
|
||||
int[] so = UIDs.Length.SW();
|
||||
for (i = 0; i < UIDs.Length; i++)
|
||||
{
|
||||
if (UIDs[so[i]].Category != null && UIDs[so[i]].Category != "")
|
||||
_IO.W($"uid.{so[i]}.category=" + UIDs[so[i]].Category + "\n");
|
||||
s.W($"uid.{so[i]}.category=" + UIDs[so[i]].Category + "\n");
|
||||
if (UIDs[so[i]].OrgUid != null)
|
||||
_IO.W($"uid.{so[i]}.org_uid=" + UIDs[so[i]].OrgUid + "\n");
|
||||
s.W($"uid.{so[i]}.org_uid=" + UIDs[so[i]].OrgUid + "\n");
|
||||
if (UIDs[so[i]].Size != null)
|
||||
_IO.W($"uid.{so[i]}.size=" + UIDs[so[i]].Size + "\n");
|
||||
s.W($"uid.{so[i]}.size=" + UIDs[so[i]].Size + "\n");
|
||||
if (UIDs[so[i]].Value != null && UIDs[so[i]].Value != "")
|
||||
_IO.W($"uid.{so[i]}.value=" + UIDs[so[i]].Value + "\n");
|
||||
s.W($"uid.{so[i]}.value=" + UIDs[so[i]].Value + "\n");
|
||||
}
|
||||
_IO.W($"uid.length={UIDs.Length}\n");
|
||||
s.W($"uid.length={UIDs.Length}\n");
|
||||
}
|
||||
|
||||
_IO.C();
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
@@ -128,7 +126,7 @@ namespace KKdMainLib.DB
|
||||
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
MsgPack authDB = new MsgPack("AuthDB");
|
||||
MsgPack authDB = new MsgPack("AuthDB");
|
||||
if (Category != null)
|
||||
{
|
||||
MsgPack category = new MsgPack(Category.Length, "Category");
|
||||
@@ -148,12 +146,12 @@ namespace KKdMainLib.DB
|
||||
authDB.Add(uid);
|
||||
}
|
||||
|
||||
authDB.Write(true, file, json);
|
||||
authDB.Write(false, true, file, json);
|
||||
}
|
||||
|
||||
private bool disposed = false;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (_IO != null) _IO.D(); Category = null; UIDs = null; disposed = true; } }
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; Category = null; UIDs = null; disposed = true; } }
|
||||
|
||||
public struct UID
|
||||
{
|
||||
|
||||
+70
-73
@@ -1,6 +1,5 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
@@ -9,27 +8,27 @@ namespace KKdMainLib.DB
|
||||
public class Spr : System.IDisposable
|
||||
{
|
||||
private int i, i0, i1, i2;
|
||||
private Stream _IO;
|
||||
private Stream s;
|
||||
|
||||
public SpriteSet[] SpriteSets;
|
||||
|
||||
public void BINReader(string file)
|
||||
{
|
||||
_IO = File.OpenReader(file + ".bin");
|
||||
s = File.OpenReader(file + ".bin");
|
||||
|
||||
int spriteSetsLength = _IO.RI32();
|
||||
int spriteSetsOffset = _IO.RI32();
|
||||
int spritesLength = _IO.RI32();
|
||||
int spritesOffset = _IO.RI32();
|
||||
int spriteSetsLength = s.RI32();
|
||||
int spriteSetsOffset = s.RI32();
|
||||
int spritesLength = s.RI32();
|
||||
int spritesOffset = s.RI32();
|
||||
|
||||
_IO.P = spriteSetsOffset;
|
||||
s.P = spriteSetsOffset;
|
||||
SpriteSets = new SpriteSet[spriteSetsLength];
|
||||
for (i = 0; i < spriteSetsLength; i++)
|
||||
{
|
||||
SpriteSets[i].Id = _IO.RI32();
|
||||
SpriteSets[i].Name = _IO.RSaO();
|
||||
SpriteSets[i].FileName = _IO.RSaO();
|
||||
_IO.RI32();
|
||||
SpriteSets[i].Id = s.RI32();
|
||||
SpriteSets[i].Name = s.RSaO();
|
||||
SpriteSets[i].FileName = s.RSaO();
|
||||
s.RI32();
|
||||
}
|
||||
|
||||
int setIndex;
|
||||
@@ -38,11 +37,11 @@ namespace KKdMainLib.DB
|
||||
int[] sprCount = new int[spriteSetsLength];
|
||||
int[] texCount = new int[spriteSetsLength];
|
||||
|
||||
_IO.P = spritesOffset;
|
||||
s.P = spritesOffset;
|
||||
for (i = 0; i < spritesLength; i++)
|
||||
{
|
||||
_IO.I64P += 10;
|
||||
setIndex = _IO.RI16();
|
||||
s.PI64 += 10;
|
||||
setIndex = s.RI16();
|
||||
isTexture = (setIndex & 0x1000) == 0x1000;
|
||||
setIndex &= 0xFFF;
|
||||
|
||||
@@ -59,21 +58,21 @@ namespace KKdMainLib.DB
|
||||
texCount[i] = 0;
|
||||
}
|
||||
|
||||
_IO.P = spritesOffset;
|
||||
s.P = spritesOffset;
|
||||
for (i = 0; i < spritesLength; i++)
|
||||
{
|
||||
st.Id = _IO.RI32();
|
||||
st.Name = _IO.RSaO();
|
||||
_IO.RI16();
|
||||
setIndex = _IO.RI16();
|
||||
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]++; }
|
||||
}
|
||||
|
||||
_IO.C();
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void BINWriter(string file)
|
||||
@@ -81,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;
|
||||
|
||||
@@ -130,8 +129,8 @@ namespace KKdMainLib.DB
|
||||
else ids.Add ((int)temp.Id);
|
||||
}
|
||||
}
|
||||
setName = null;
|
||||
setFileName = null;
|
||||
setName .Dispose();
|
||||
setFileName.Dispose();
|
||||
|
||||
for (i = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
@@ -151,80 +150,78 @@ namespace KKdMainLib.DB
|
||||
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++; }
|
||||
|
||||
|
||||
i1 = i0 * 12;
|
||||
i1 = i1.A(0x20) + 0x20;
|
||||
|
||||
_IO = File.OpenWriter(file + ".bin", true);
|
||||
_IO.W(i2);
|
||||
_IO.W(i1);
|
||||
_IO.W(i0);
|
||||
_IO.W(0x20);
|
||||
_IO.W(0x9066906690669066);
|
||||
_IO.W(0x9066906690669066);
|
||||
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.P = (i1 + i2 * 0x10).A(0x20);
|
||||
s.P = (i1 + i2 * 0x10).A(0x20);
|
||||
for (i = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
if (notAdd.Contains(i)) continue;
|
||||
for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++)
|
||||
{ SpriteSets[i].Textures[i0].NameOffset = _IO.P;
|
||||
_IO.W(SpriteSets[i].Textures[i0].Name + "\0"); }
|
||||
{ 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 = _IO.P;
|
||||
_IO.W(SpriteSets[i]. Sprites[i0].Name + "\0"); }
|
||||
{ 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;
|
||||
SpriteSets[i]. NameOffset = _IO.P; _IO.W(SpriteSets[i]. Name + "\0");
|
||||
SpriteSets[i].FileNameOffset = _IO.P; _IO.W(SpriteSets[i].FileName + "\0");
|
||||
SpriteSets[i]. NameOffset = s.P; s.W(SpriteSets[i]. Name + "\0");
|
||||
SpriteSets[i].FileNameOffset = s.P; s.W(SpriteSets[i].FileName + "\0");
|
||||
}
|
||||
|
||||
_IO.A(0x08, true);
|
||||
_IO.P = 0x20;
|
||||
s.A(0x08, true);
|
||||
|
||||
s.P = 0x20;
|
||||
for (i = 0, i2 = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
if (notAdd.Contains(i)) { i2++; continue; }
|
||||
|
||||
|
||||
for (i0 = 0; i0 < SpriteSets[i].Textures.Length; i0++)
|
||||
{
|
||||
_IO.W(SpriteSets[i].Textures[i0].Id );
|
||||
_IO.W(SpriteSets[i].Textures[i0].NameOffset);
|
||||
_IO.W((ushort) i0 );
|
||||
_IO.W((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.W(SpriteSets[i]. Sprites[i0].Id );
|
||||
_IO.W(SpriteSets[i]. Sprites[i0].NameOffset);
|
||||
_IO.W((ushort) i0 );
|
||||
_IO.W((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.A(0x20);
|
||||
s.A(0x20);
|
||||
|
||||
for (i = 0, i2 = 0; i < SpriteSets.Length; i++)
|
||||
{
|
||||
if (notAdd.Contains(i)) { i2++; continue; }
|
||||
|
||||
_IO.W(SpriteSets[i].Id );
|
||||
_IO.W(SpriteSets[i]. NameOffset);
|
||||
_IO.W(SpriteSets[i].FileNameOffset);
|
||||
_IO.W(i - i2);
|
||||
s.W(SpriteSets[i].Id );
|
||||
s.W(SpriteSets[i]. NameOffset);
|
||||
s.W(SpriteSets[i].FileNameOffset);
|
||||
s.W(i - i2);
|
||||
}
|
||||
|
||||
_IO.C();
|
||||
notAdd.Dispose();
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json = false)
|
||||
@@ -251,12 +248,12 @@ namespace KKdMainLib.DB
|
||||
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 (_IO != null) _IO.D(); SpriteSets = null; disposed = true; } }
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; SpriteSets = null; disposed = true; } }
|
||||
|
||||
public struct SpriteTexture
|
||||
{
|
||||
@@ -281,7 +278,7 @@ namespace KKdMainLib.DB
|
||||
public string FileName;
|
||||
public SpriteTexture[] Sprites;
|
||||
public SpriteTexture[] Textures;
|
||||
|
||||
|
||||
public void ReadMsgPack(MsgPack msg)
|
||||
{
|
||||
FileName = msg.RS ("FileName");
|
||||
|
||||
+96
-92
@@ -1,4 +1,4 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace KKdMainLib
|
||||
{
|
||||
private int i, i0, i1;
|
||||
private Header header;
|
||||
private Stream _IO;
|
||||
private Stream s;
|
||||
|
||||
public EXP[] Dex;
|
||||
|
||||
@@ -16,150 +16,154 @@ namespace KKdMainLib
|
||||
{
|
||||
Dex = null;
|
||||
header = new Header();
|
||||
_IO = File.OpenReader(filepath + ext);
|
||||
s = File.OpenReader(filepath + ext);
|
||||
|
||||
header.Format = Format.F;
|
||||
header.SectionSignature = _IO.RI32();
|
||||
if (header.SectionSignature == 0x43505845)
|
||||
header = _IO.ReadHeader(true, true);
|
||||
if (header.SectionSignature != 0x64) return;
|
||||
uint signature = s.RU32();
|
||||
if (signature == 0x43505845) { header = s.ReadHeader(true); signature = s.RU32(); }
|
||||
if (signature != 0x64) return;
|
||||
|
||||
_IO.O = _IO.P - 0x4;
|
||||
Dex = new EXP[_IO.RI32()];
|
||||
int DEXOffset = _IO.RI32();
|
||||
int DEXNameOffset = _IO.RI32();
|
||||
if (DEXNameOffset == 0x00) { _IO.Format = header.Format = Format.X; DEXNameOffset = (int)_IO.RIX(); }
|
||||
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.P = DEXOffset;
|
||||
s.P = DEXOffset;
|
||||
for (i = 0; i < Dex.Length; i++)
|
||||
{
|
||||
Dex[i].MainOffset = (int)_IO.RIX();
|
||||
Dex[i].EyesOffset = (int)_IO.RIX();
|
||||
Dex[i].MainOffset = (int)s.RIX();
|
||||
Dex[i].EyesOffset = (int)s.RIX();
|
||||
}
|
||||
_IO.P = DEXNameOffset;
|
||||
s.P = DEXNameOffset;
|
||||
for (i = 0; i < Dex.Length; i++)
|
||||
Dex[i].NameOffset = (int)_IO.RIX();
|
||||
Dex[i].NameOffset = (int)s.RIX();
|
||||
|
||||
for (i = 0; i < Dex.Length; i++)
|
||||
{
|
||||
EXPElement element = new EXPElement();
|
||||
Dex[i].Main = KKdList<EXPElement>.New;
|
||||
_IO.P = Dex[i].MainOffset;
|
||||
s.P = Dex[i].MainOffset;
|
||||
while (true)
|
||||
{
|
||||
element.Frame = _IO.RF32();
|
||||
element.Both = _IO.RU16();
|
||||
element.ID = _IO.RU16();
|
||||
element.Value = _IO.RF32();
|
||||
element.Trans = _IO.RF32();
|
||||
element.Frame = s.RF32();
|
||||
element.Both = s.RU16();
|
||||
element.ID = s.RU16();
|
||||
element.Value = s.RF32();
|
||||
element.Trans = s.RF32();
|
||||
if (element.Frame == 999999 || element.Both == 0xFFFF) break;
|
||||
Dex[i].Main.Add(element);
|
||||
}
|
||||
Dex[i].Main.Capacity = Dex[i].Main.Count;
|
||||
|
||||
Dex[i].Eyes = KKdList<EXPElement>.New;
|
||||
_IO.P = Dex[i].EyesOffset;
|
||||
s.P = Dex[i].EyesOffset;
|
||||
while(true)
|
||||
{
|
||||
element.Frame = _IO.RF32();
|
||||
element.Both = _IO.RU16();
|
||||
element.ID = _IO.RU16();
|
||||
element.Value = _IO.RF32();
|
||||
element.Trans = _IO.RF32();
|
||||
element.Frame = s.RF32();
|
||||
element.Both = s.RU16();
|
||||
element.ID = s.RU16();
|
||||
element.Value = s.RF32();
|
||||
element.Trans = s.RF32();
|
||||
if (element.Frame == 999999 || element.Both == 0xFFFF) break;
|
||||
Dex[i].Eyes.Add(element);
|
||||
}
|
||||
Dex[i].Eyes.Capacity = Dex[i].Eyes.Count;
|
||||
|
||||
Dex[i].Name = _IO.RSaO(Dex[i].NameOffset);
|
||||
Dex[i].Name = s.RSaO(Dex[i].NameOffset);
|
||||
}
|
||||
|
||||
_IO.C();
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void DEXWriter(string filepath, Format Format)
|
||||
public void DEXWriter(string filepath, Format format)
|
||||
{
|
||||
if (Dex == null || Dex.Length < 1) return;
|
||||
|
||||
header = new Header();
|
||||
_IO = File.OpenWriter(filepath + (Format > Format.F && Format < Format.FT ? ".dex" : ".bin"), true);
|
||||
header.Format = _IO.Format = Format;
|
||||
s = File.OpenWriter(filepath + (format > Format.F && format < Format.FT ? ".dex" : ".bin"), true);
|
||||
header.Format = s.Format = format;
|
||||
|
||||
_IO.O = Format > Format.F ? 0x20 : 0;
|
||||
_IO.W(0x64);
|
||||
_IO.W(Dex.Length);
|
||||
s.Format = format;
|
||||
s.O = format > Format.F ? 0x20 : 0;
|
||||
s.P = 0;
|
||||
s.W(0x64);
|
||||
s.W(Dex.Length);
|
||||
|
||||
_IO.WX(header.IsX ? 0x28 : 0x20);
|
||||
_IO.WX(0x00);
|
||||
s.WX(header.IsX ? 0x28 : 0x20);
|
||||
s.WX(0x00);
|
||||
|
||||
int Position0 = _IO.P;
|
||||
_IO.W(0x00L);
|
||||
_IO.W(0x00L);
|
||||
int Position0 = s.P;
|
||||
s.W(0x00L);
|
||||
s.W(0x00L);
|
||||
|
||||
for (i = 0; i < Dex.Length * 3; i++) _IO.WX(0x00);
|
||||
_IO.A(0x20);
|
||||
for (i = 0; i < Dex.Length * 3; i++) s.WX(0x00);
|
||||
s.A(0x20);
|
||||
|
||||
for (i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
Dex[i0].MainOffset = _IO.P;
|
||||
Dex[i0].MainOffset = s.P;
|
||||
for (i1 = 0; i1 < Dex[i0].Main.Count; i1++)
|
||||
{
|
||||
_IO.W(Dex[i0].Main[i1].Frame);
|
||||
_IO.W(Dex[i0].Main[i1].Both );
|
||||
_IO.W(Dex[i0].Main[i1].ID );
|
||||
_IO.W(Dex[i0].Main[i1].Value);
|
||||
_IO.W(Dex[i0].Main[i1].Trans);
|
||||
s.W(Dex[i0].Main[i1].Frame);
|
||||
s.W(Dex[i0].Main[i1].Both );
|
||||
s.W(Dex[i0].Main[i1].ID );
|
||||
s.W(Dex[i0].Main[i1].Value);
|
||||
s.W(Dex[i0].Main[i1].Trans);
|
||||
}
|
||||
_IO.W(999999f);
|
||||
_IO.W(0xFFFF);
|
||||
_IO.W(0x0L);
|
||||
_IO.A(0x20);
|
||||
s.W(999999f);
|
||||
s.W(0xFFFF);
|
||||
s.W(0x0L);
|
||||
s.A(0x20);
|
||||
|
||||
Dex[i0].EyesOffset = _IO.P;
|
||||
Dex[i0].EyesOffset = s.P;
|
||||
for (i1 = 0; i1 < Dex[i0].Eyes.Count; i1++)
|
||||
{
|
||||
_IO.W(Dex[i0].Eyes[i1].Frame);
|
||||
_IO.W(Dex[i0].Eyes[i1].Both );
|
||||
_IO.W(Dex[i0].Eyes[i1].ID );
|
||||
_IO.W(Dex[i0].Eyes[i1].Value);
|
||||
_IO.W(Dex[i0].Eyes[i1].Trans);
|
||||
s.W(Dex[i0].Eyes[i1].Frame);
|
||||
s.W(Dex[i0].Eyes[i1].Both );
|
||||
s.W(Dex[i0].Eyes[i1].ID );
|
||||
s.W(Dex[i0].Eyes[i1].Value);
|
||||
s.W(Dex[i0].Eyes[i1].Trans);
|
||||
}
|
||||
_IO.W(999999f);
|
||||
_IO.W(0xFFFF);
|
||||
_IO.W(0x0L);
|
||||
_IO.A(0x20);
|
||||
s.W(999999f);
|
||||
s.W(0xFFFF);
|
||||
s.W(0x0L);
|
||||
s.A(0x20);
|
||||
}
|
||||
for (i = 0; i < Dex.Length; i0++)
|
||||
{
|
||||
Dex[i].NameOffset = _IO.P;
|
||||
_IO.W(Dex[i].Name + "\0");
|
||||
}
|
||||
_IO.A(0x10, true);
|
||||
|
||||
_IO.P = header.IsX ? 0x28 : 0x20;
|
||||
for (i = 0; i < Dex.Length; i++)
|
||||
{
|
||||
_IO.WX(Dex[i].MainOffset);
|
||||
_IO.WX(Dex[i].EyesOffset);
|
||||
Dex[i].NameOffset = s.P;
|
||||
s.W(Dex[i].Name + "\0");
|
||||
}
|
||||
int namesPosition = _IO.P;
|
||||
s.A(0x10, true);
|
||||
|
||||
s.P = header.IsX ? 0x28 : 0x20;
|
||||
for (i = 0; i < Dex.Length; i++)
|
||||
_IO.WX(Dex[i].NameOffset);
|
||||
|
||||
_IO.P = Position0 - (header.IsX ? 8 : 4);
|
||||
_IO.W(namesPosition);
|
||||
|
||||
if (Format > Format.F)
|
||||
{
|
||||
int offset = _IO.L;
|
||||
_IO.O = 0;
|
||||
_IO.P = _IO.L;
|
||||
_IO.WEOFC(0);
|
||||
_IO.P = 0;
|
||||
s.WX(Dex[i].MainOffset);
|
||||
s.WX(Dex[i].EyesOffset);
|
||||
}
|
||||
int namesPosition = s.P;
|
||||
for (i = 0; i < Dex.Length; i++)
|
||||
s.WX(Dex[i].NameOffset);
|
||||
|
||||
s.P = Position0 - (header.IsX ? 8 : 4);
|
||||
s.W(namesPosition);
|
||||
|
||||
if (format > Format.F)
|
||||
{
|
||||
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;
|
||||
_IO.W(header, true);
|
||||
header.UseSectionSize = true;
|
||||
s.W(header);
|
||||
}
|
||||
_IO.C();
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
@@ -188,7 +192,7 @@ namespace KKdMainLib
|
||||
{
|
||||
Dex[i0].Eyes = KKdList<EXPElement>.New;
|
||||
Dex[i0].Eyes.Capacity = temp.Array.Length;
|
||||
for (i1 = 0; i1 < this.Dex[i0].Eyes.Capacity; i1++)
|
||||
for (i1 = 0; i1 < Dex[i0].Eyes.Capacity; i1++)
|
||||
Dex[i0].Eyes.Add(EXPElement.Read(temp[i1]));
|
||||
}
|
||||
temp.Dispose();
|
||||
@@ -205,7 +209,7 @@ namespace KKdMainLib
|
||||
MsgPack dex = new MsgPack(Dex.Length, "Dex");
|
||||
for (i0 = 0; i0 < Dex.Length; i0++)
|
||||
{
|
||||
MsgPack exp = MsgPack.New.Add("Name", this.Dex[i0].Name);
|
||||
MsgPack exp = MsgPack.New.Add("Name", Dex[i0].Name);
|
||||
MsgPack main = new MsgPack(Dex[i0].Main.Count, "Main");
|
||||
for (i1 = 0; i1 < Dex[i0].Main.Count; i1++)
|
||||
main[i1] = Dex[i0].Main[i1].Write();
|
||||
@@ -218,12 +222,12 @@ namespace KKdMainLib
|
||||
dex[i0] = exp;
|
||||
}
|
||||
|
||||
dex.Write(true, file, json);
|
||||
dex.Write(false, true, file, json);
|
||||
}
|
||||
|
||||
private bool disposed;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (_IO != null) _IO.Dispose(); Dex = null; header = default; disposed = true; } }
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; Dex = null; header = default; disposed = true; } }
|
||||
|
||||
public struct EXP
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
@@ -8,9 +8,7 @@ namespace KKdMainLib
|
||||
{
|
||||
public static class DIVAFILE
|
||||
{
|
||||
private static readonly byte[] Key = new byte[]
|
||||
{ 0x66, 0x69, 0x6C, 0x65, 0x20, 0x61, 0x63, 0x63,
|
||||
0x65, 0x73, 0x73, 0x20, 0x64, 0x65, 0x6E, 0x79 };
|
||||
private static readonly byte[] Key = "file access deny".ToASCII();
|
||||
|
||||
public static void Decrypt(this string file)
|
||||
{
|
||||
|
||||
+138
-111
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Net;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
@@ -7,9 +7,10 @@ namespace KKdMainLib
|
||||
{
|
||||
public struct DataBank : IDisposable
|
||||
{
|
||||
private Stream _IO;
|
||||
private int i;
|
||||
private Stream s;
|
||||
|
||||
public bool pvListPDA;
|
||||
public PvList[] pvList;
|
||||
public PsrData[] psrData;
|
||||
|
||||
@@ -20,6 +21,7 @@ namespace KKdMainLib
|
||||
|
||||
public void DBReader(string file)
|
||||
{
|
||||
pvListPDA = false;
|
||||
Success = false;
|
||||
if (!File.Exists(file)) return;
|
||||
string text = File.ReadAllText(file);
|
||||
@@ -28,49 +30,73 @@ namespace KKdMainLib
|
||||
|
||||
pvList = null;
|
||||
psrData = null;
|
||||
if (file.Contains("psrData") && array.Length % 13 < 2)
|
||||
if (file.Contains("psrData") && array.Length % 13 == 0)
|
||||
{
|
||||
psrData = new PsrData[array.Length / 13];
|
||||
for (i = 0; i < psrData.Length; i++) psrData[i].SetValue(array, i);
|
||||
Success = true;
|
||||
}
|
||||
else if (file.Contains("psrData")) Success = true;
|
||||
else if (file.Contains("PvList") && array.Length % 7 < 2)
|
||||
else if (file.Contains("PvList") && (array.Length % 7 == 0 || array.Length % 6 == 0))
|
||||
{
|
||||
pvList = new PvList[array.Length / 7];
|
||||
for (i = 0; i < pvList.Length; i++) pvList[i].SetValue(array, i);
|
||||
if (array[2] != "0" && array[2] != "1")
|
||||
{
|
||||
pvListPDA = true;
|
||||
pvList = new PvList[array.Length / 6];
|
||||
for (i = 0; i < pvList.Length; i++) pvList[i].SetValue(array, i, 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 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 num2)
|
||||
{
|
||||
if (!Success) return;
|
||||
|
||||
_IO = File.OpenWriter();
|
||||
if (file.Contains("psrData"))
|
||||
{
|
||||
if (psrData != null && psrData.Length > 0)
|
||||
for (i = 0; i < psrData.Length; i++)
|
||||
_IO.W(psrData[i].ToString() + c);
|
||||
}
|
||||
else if (file.Contains("PvList"))
|
||||
{
|
||||
if (pvList != null && pvList.Length > 0)
|
||||
for (i = 0; i < pvList.Length; i++)
|
||||
_IO.W(UrlEncode(pvList[i].ToString() +
|
||||
(i < pvList.Length ? c : "")));
|
||||
else _IO.W("%2A%2A%2A");
|
||||
}
|
||||
|
||||
byte[] data = _IO.ToArray(true);
|
||||
byte[] data = DBWriter(file);
|
||||
if (data == null) return;
|
||||
|
||||
ushort num = DCC.CalculateChecksum(data);
|
||||
File.WriteAllBytes(file + "_" + num + "_" + num2 + ".dat", data);
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
{
|
||||
pvListPDA = false;
|
||||
Success = false;
|
||||
MsgPack msgPack = file.ReadMPAllAtOnce(json);
|
||||
bool compact = msgPack.RB("Compact");
|
||||
@@ -98,14 +124,21 @@ namespace KKdMainLib
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
msgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool json, bool Compact = true)
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
if (!Success) return;
|
||||
MsgPack msgPack = MsgPack.New;
|
||||
@@ -123,24 +156,24 @@ namespace KKdMainLib
|
||||
else if (file.Contains("PvList"))
|
||||
{
|
||||
if (pvList != null)
|
||||
{
|
||||
if (Compact) msgPack.Add("Compact", Compact);
|
||||
{msgPack.Add("Compact", true);
|
||||
|
||||
MsgPack PvList = new MsgPack(pvList.Length, "PvList");
|
||||
for (i = 0; i < pvList.Length; i++) PvList[i] = pvList[i].WriteMP(Compact);
|
||||
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("PvList", null));
|
||||
else msgPack.Add(new MsgPack(pvListPDA ? "PvListPDA" : "PvList", null));
|
||||
}
|
||||
msgPack.Write(file, json).Dispose();
|
||||
msgPack.Write(file, false, json).Dispose();
|
||||
}
|
||||
|
||||
public static string UrlEncode(string value) =>
|
||||
WebUtility.UrlEncode(value).Replace("+", "%20");
|
||||
WebUtility.UrlEncode(value).Replace("+", "%20").Replace("!", "%21").Replace("*", "%2A");
|
||||
|
||||
private bool disposed;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (_IO != null) _IO.Dispose(); psrData = null; pvList = null; Success = false; disposed = true; } }
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; psrData = null;
|
||||
pvList = null; pvListPDA = false; Success = false; disposed = true; } }
|
||||
|
||||
public struct PsrData
|
||||
{
|
||||
@@ -164,9 +197,9 @@ namespace KKdMainLib
|
||||
else { id = msg.RnI32("ID"); if (id != null) PV_ID = (int)id; }
|
||||
|
||||
MsgPack temp;
|
||||
if ((temp = msg["P1", true]).NotNull) p1.SetValue(temp);
|
||||
if ((temp = msg["P2", true]).NotNull) p2.SetValue(temp);
|
||||
if ((temp = msg["P3", true]).NotNull) p3.SetValue(temp);
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -175,35 +208,35 @@ namespace KKdMainLib
|
||||
.Add(p2.WriteMP("P2")).Add(p3.WriteMP("P3"));
|
||||
|
||||
public override string ToString() =>
|
||||
UrlEncode(p1.ToString() + c + p2.ToString() + c + p3.ToString() + c + PV_ID);
|
||||
UrlEncode($"{p1},{p2},{p3},{PV_ID}");
|
||||
}
|
||||
|
||||
public struct Player
|
||||
{
|
||||
public int Score0;
|
||||
public int Score1;
|
||||
public string Name0;
|
||||
public string Name1;
|
||||
public string Name;
|
||||
public string NameExtra;
|
||||
public int Score;
|
||||
public int ScoreExtra;
|
||||
public Difficulty Diff;
|
||||
public bool Has2P => Name1 != null;
|
||||
public bool HasExtra => NameExtra != null;
|
||||
|
||||
public void SetValue(string[] data, int i = 0, int offset = 0)
|
||||
{
|
||||
string[] array = data[i * 13 + offset * 4].Split('.');
|
||||
Score0 = int.Parse(array[0]);
|
||||
if (array.Length > 1) Score1 = int.Parse(array[1]);
|
||||
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++)
|
||||
{
|
||||
text += data[i * 13 + 1 + offset * 4][j].ToString();
|
||||
if (text.EndsWith("xxx"))
|
||||
{
|
||||
Name0 = text.Remove(text.Length - 3);
|
||||
Name = text.Remove(text.Length - 3);
|
||||
text = "";
|
||||
}
|
||||
}
|
||||
if (array.Length == 1) Name0 = text;
|
||||
else Name1 = 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
|
||||
@@ -213,63 +246,75 @@ namespace KKdMainLib
|
||||
public void SetValue(MsgPack msg)
|
||||
{
|
||||
Diff = (Difficulty)msg.RI32("Diff");
|
||||
Score0 = msg.RI32 ("Score");
|
||||
Name0 = msg.RS( "Name");
|
||||
if (Name0 == null)
|
||||
Name = msg.RS ( "Name");
|
||||
NameExtra = msg.RS ( "NameExtra");
|
||||
Score = msg.RI32("Score");
|
||||
ScoreExtra = msg.RI32("ScoreExtra");
|
||||
|
||||
if (Name == null)
|
||||
{
|
||||
Score0 = msg.RI32("Score0");
|
||||
Score1 = msg.RI32("Score1");
|
||||
Name0 = msg.RS ( "Name0");
|
||||
Name1 = msg.RS ( "Name1");
|
||||
Name = msg.RS ( "Name0");
|
||||
NameExtra = msg.RS ( "Name1");
|
||||
Score = msg.RI32("Score0");
|
||||
ScoreExtra = msg.RI32("Score1");
|
||||
}
|
||||
else Name1 = null;
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(string name) =>
|
||||
Has2P ? new MsgPack(name).Add("Diff", (int)Diff).Add("Score0", Score0)
|
||||
.Add("Score1", Score1).Add("Name0", Name0).Add("Name1", Name1) :
|
||||
new MsgPack(name).Add("Diff", (int)Diff)
|
||||
.Add("Score" , Score0).Add("Name" , Name0);
|
||||
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() =>
|
||||
(Score0 + (Has2P ? (d + Score1) : "") + c + UrlEncode(Name0) +
|
||||
(Has2P ? ("xxx" + UrlEncode(Name1)) : "") + c +
|
||||
Diff + c + (Has2P ? "0.1" : "0")).Replace("*", "%2A");
|
||||
Score + (HasExtra ? (d + ScoreExtra) : "") + c + UrlEncode(Name) +
|
||||
(HasExtra ? ("xxx" + UrlEncode(NameExtra)) : "") + c +
|
||||
(int)Diff + c + (HasExtra ? "0.1" : "0");
|
||||
}
|
||||
|
||||
public struct PvList
|
||||
{
|
||||
public int PV_ID;
|
||||
public bool Enable;
|
||||
public bool Extra;
|
||||
public int Version;
|
||||
public int Edition;
|
||||
public Date AdvDemoStart;
|
||||
public Date AdvDemoEnd;
|
||||
public Date StartShow;
|
||||
public Date EndShow;
|
||||
|
||||
public void SetValue(string[] data, int i = 0)
|
||||
public void SetValue(string[] data, int i = 0, bool pda = false)
|
||||
{
|
||||
PV_ID = int.Parse(data[i * 7]);
|
||||
Enable = int.Parse(data[i * 7 + 1]) == 1;
|
||||
Extra = int.Parse(data[i * 7 + 2]) == 1;
|
||||
AdvDemoStart.SV(data[i * 7 + 3]);
|
||||
AdvDemoEnd .SV(data[i * 7 + 4]);
|
||||
StartShow .SV(data[i * 7 + 5]);
|
||||
EndShow .SV(data[i * 7 + 6]);
|
||||
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 void SetValue(MsgPack msg, bool Compact)
|
||||
{
|
||||
Enable = true;
|
||||
Extra = false;
|
||||
Version = 1;
|
||||
Edition = 0;
|
||||
|
||||
int? id = msg.RnI32("PV_ID");
|
||||
if (id != null) PV_ID = (int)id;
|
||||
else { id = msg.RnI32("ID"); if (id != null) PV_ID = (int)id; }
|
||||
bool? enable = msg.RnB("Enable");
|
||||
bool? extra = msg.RnB("Extra");
|
||||
if (enable != null) Enable = (bool)enable;
|
||||
if (extra != null) Extra = (bool)extra ;
|
||||
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);
|
||||
@@ -287,33 +332,21 @@ namespace KKdMainLib
|
||||
temp.Dispose();
|
||||
}
|
||||
|
||||
public MsgPack WriteMP(bool Compact)
|
||||
public MsgPack WriteMP()
|
||||
{
|
||||
MsgPack msgPack = MsgPack.New;
|
||||
msgPack.Add("ID", PV_ID);
|
||||
if (!Enable) msgPack.Add("Enable", Enable);
|
||||
if ( Extra ) msgPack.Add("Extra" , Extra );
|
||||
if (Compact)
|
||||
{
|
||||
if (AdvDemoStart.WU) msgPack.Add("AdvDemoStart", AdvDemoStart.WI());
|
||||
if (AdvDemoEnd .WL) msgPack.Add("AdvDemoEnd" , AdvDemoEnd .WI());
|
||||
if (StartShow .WL) msgPack.Add("StartShow" , StartShow .WI());
|
||||
if ( EndShow .WU) msgPack.Add( "EndShow" , EndShow .WI());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (AdvDemoStart.WU) msgPack.Add(AdvDemoStart.WriteMP("AdvDemoStart"));
|
||||
if (AdvDemoEnd .WL) msgPack.Add(AdvDemoEnd .WriteMP("AdvDemoEnd" ));
|
||||
if (StartShow .WL) msgPack.Add(StartShow .WriteMP("StartShow" ));
|
||||
if ( EndShow .WU) msgPack.Add( EndShow .WriteMP( "EndShow" ));
|
||||
}
|
||||
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 override string ToString() =>
|
||||
UrlEncode(PV_ID + c + (Enable ? 1 : 0) + c + (Extra ? 1 : 0) + c +
|
||||
AdvDemoStart.ToString() + c + AdvDemoEnd.ToString() + c +
|
||||
StartShow.ToString() + c + EndShow.ToString());
|
||||
public string ToString(bool pda) => !pda
|
||||
? UrlEncode($"{PV_ID},{Version},{Edition},{AdvDemoStart},{AdvDemoEnd},{StartShow},{EndShow}")
|
||||
: UrlEncode($"{PV_ID},{Version},{AdvDemoStart},{AdvDemoEnd},{StartShow},{EndShow}");
|
||||
}
|
||||
|
||||
public struct Date
|
||||
@@ -323,9 +356,7 @@ namespace KKdMainLib
|
||||
private int day;
|
||||
|
||||
public int Year { get => year; set { year = value; CheckDate(); } }
|
||||
|
||||
public int Month { get => month; set { month = value; CheckDate(); } }
|
||||
|
||||
public int Day { get => day; set { day = value; CheckDate(); } }
|
||||
|
||||
public bool WU => Year != 2029 || Month != 1 || Day != 1;
|
||||
@@ -371,11 +402,7 @@ namespace KKdMainLib
|
||||
CheckDate();
|
||||
}
|
||||
|
||||
public int WI() =>
|
||||
(Year * 100 + Month) * 100 + Day;
|
||||
|
||||
public MsgPack WriteMP(string name) =>
|
||||
new MsgPack(name).Add("Year", Year).Add("Month", Month).Add("Day", Day);
|
||||
public int Int => (Year * 100 + Month) * 100 + Day;
|
||||
|
||||
private void CheckDate()
|
||||
{
|
||||
@@ -393,7 +420,7 @@ namespace KKdMainLib
|
||||
}
|
||||
|
||||
public override string ToString() =>
|
||||
Year.ToString("d4") + "-" + Month.ToString("d2") + "-" + Day.ToString("d2");
|
||||
$"{Year:d4}-{Month:d2}-{Day:d2}";
|
||||
}
|
||||
|
||||
public enum Difficulty
|
||||
|
||||
+196
-71
@@ -1,4 +1,4 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
@@ -6,41 +6,44 @@ namespace KKdMainLib
|
||||
{
|
||||
public static class HeaderExtensions
|
||||
{
|
||||
public static Header ReadHeader(this Stream stream, bool seek, bool readSectionSignature = true)
|
||||
public static Header ReadHeader(this Stream stream, bool seek)
|
||||
{
|
||||
if (seek)
|
||||
if (stream.I64P > 4) stream.I64P -= 4;
|
||||
else stream.I64P = 0;
|
||||
return stream.ReadHeader(readSectionSignature);
|
||||
if (stream.PI64 > 4) stream.PI64 -= 4;
|
||||
else stream.PI64 = 0;
|
||||
return stream.ReadHeader();
|
||||
}
|
||||
|
||||
public static Header ReadHeader(this Stream stream, bool readSectionSignature = true)
|
||||
public static Header ReadHeader(this Stream stream)
|
||||
{
|
||||
Header header = new Header { Format = Format.F2LE, Signature = stream.RI32(),
|
||||
DataSize = stream.RI32(), Length = stream.RI32(), Flags = stream.RI32(),
|
||||
Depth = stream.RI32(), SectionSize = stream.RI32(),
|
||||
Mode = stream.RI32() };
|
||||
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();
|
||||
if ((header.Flags & 0x08000000) == 0x08000000) header.Format = Format.F2BE;
|
||||
header.NotUseDataSizeAsSectionSize = (header.Flags & 0x10000000) != 0x10000000;
|
||||
header.UseBigEndian = (header.Flags & 0x08000000) != 0;
|
||||
header.UseSectionSize = (header.Flags & 0x10000000) != 0;
|
||||
if (header.Length == 0x40)
|
||||
{
|
||||
stream.RI64();
|
||||
stream.RI64();
|
||||
header.InnerSignature = stream.RI32();
|
||||
header.InnerSignature = stream.RU32();
|
||||
stream.RI32();
|
||||
stream.RI64();
|
||||
}
|
||||
stream.Format = header.Format;
|
||||
if (readSectionSignature) header.SectionSignature = stream.RI32E();
|
||||
return header;
|
||||
}
|
||||
|
||||
public static void W(this Stream stream, Header header, bool extended = false)
|
||||
{
|
||||
header.Length = (header.Format < Format.X && extended) ? 0x40 : 0x20;
|
||||
header.Flags = (!header.NotUseDataSizeAsSectionSize ? 0x10000000 : 0) |
|
||||
(header.Format == Format.F2BE ? 0x08000000 : 0);
|
||||
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);
|
||||
@@ -48,13 +51,11 @@ namespace KKdMainLib
|
||||
stream.W(header.Flags);
|
||||
stream.W(header.Depth);
|
||||
stream.W(header.SectionSize);
|
||||
stream.W(header.Mode);
|
||||
stream.W(header.Version);
|
||||
stream.W(0x00);
|
||||
if (header.Length == 0x40)
|
||||
{
|
||||
stream.W(header.Format < Format.MGF ? (int)((header.SectionSignature ^
|
||||
(header.DataSize * (long)header.Signature)) - header.Depth + header.SectionSize) : 0);
|
||||
stream.W(0x00);
|
||||
stream.W(0x00L);
|
||||
stream.W(0x00L);
|
||||
stream.W(header.InnerSignature);
|
||||
stream.W(0x00);
|
||||
@@ -62,31 +63,33 @@ namespace KKdMainLib
|
||||
}
|
||||
}
|
||||
|
||||
public static void WEOFC(this Stream stream, int depth = 0) =>
|
||||
stream.W(new Header { Depth = depth, Length = 0x20, Signature = 0x43464F45 });
|
||||
public static void WEOFC(this Stream stream, 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, int depth = 0)
|
||||
public static void W(this Stream stream, POF pof, bool shiftX = false, uint depth = 0)
|
||||
{
|
||||
byte[] data = POF.Write(pof, shiftX);
|
||||
Header header = new Header { Depth = depth, Format = Format.F2LE,
|
||||
Length = 0x20, Signature = shiftX ? 0x31464F50 : 0x30464F50 };
|
||||
header.DataSize = header.SectionSize = data.Length;
|
||||
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, ENRSList enrs, int depth = 0)
|
||||
public static void W(this Stream stream, ENRS enrs, uint depth = 0)
|
||||
{
|
||||
byte[] data = ENRSList.Write(enrs);
|
||||
Header header = new Header { Depth = depth, Format = Format.F2LE,
|
||||
Length = 0x20, Signature = 0x53524E45 };
|
||||
header.DataSize = header.SectionSize = data.Length;
|
||||
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);
|
||||
}
|
||||
@@ -105,11 +108,12 @@ namespace KKdMainLib
|
||||
|
||||
public 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(header.SectionSize) };
|
||||
ref int depth = ref header.Depth;
|
||||
stream.P, Data = stream.RBy(l) };
|
||||
uint depth = header.Depth;
|
||||
|
||||
int lastSig = 0, sig;
|
||||
uint lastSig = 0, sig;
|
||||
long length = stream.L - stream.P;
|
||||
long position = 0;
|
||||
KKdList<Struct> subStructs = KKdList<Struct>.New;
|
||||
@@ -117,48 +121,53 @@ namespace KKdMainLib
|
||||
{
|
||||
header = stream.ReadHeader(false);
|
||||
sig = header.Signature;
|
||||
position += header.Length + header.SectionSize;
|
||||
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(header.SectionSize);
|
||||
if (sig == 0x53524E45) @struct.ENRS = ENRSList.Read(Data);
|
||||
else @struct.POF = POF .Read(Data, sig == 0x31464F50);
|
||||
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)
|
||||
{ }
|
||||
else if (header.Depth <= depth) { stream.I64P -= header.Length; break; }
|
||||
else subStructs.Add(stream.RSt(header));
|
||||
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)
|
||||
public static byte[] W(this Struct @struct, bool shiftX = false, bool useDepth = true)
|
||||
{
|
||||
byte[] Data;
|
||||
using (Stream stream = File.OpenWriter()) { Struct.Update(shiftX);
|
||||
stream.W(Struct, shiftX); stream.WEOFC(); Data = stream.ToArray(); }
|
||||
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, bool shiftX = false)
|
||||
public static void W(this Stream stream, Struct @struct, uint depth = 0,
|
||||
bool shiftX = false, bool useDepth = true)
|
||||
{
|
||||
stream.W(@struct.Header);
|
||||
stream.W(@struct.Data );
|
||||
if (@struct.HasPOF ) stream.W(@struct.POF , shiftX);
|
||||
if (@struct.HasENRS) stream.W(@struct.ENRS);
|
||||
@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], shiftX);
|
||||
stream.WEOFC(@struct.Depth + 1);
|
||||
}
|
||||
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)
|
||||
@@ -184,36 +193,44 @@ namespace KKdMainLib
|
||||
else using ( MP _IO = new MP(File.OpenReader(file + ".mp" ))) MsgPack = _IO.Read(true);
|
||||
return MsgPack;
|
||||
}
|
||||
|
||||
public static void Write(this MsgPack mp, bool temp, string file, bool json = false)
|
||||
{ if (temp) MsgPack.New.Add(mp).Write(file, json).Dispose();
|
||||
else mp .Write(file, json); }
|
||||
|
||||
public static MsgPack Write(this MsgPack mp, string file, bool json = false)
|
||||
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, "\n", " ");
|
||||
else using ( MP _IO = new MP(File.OpenWriter(file + ".json", true))) _IO.W(mp);
|
||||
if (json)
|
||||
using (JSON _IO = new JSON(File.OpenWriter(file + ".json", true)))
|
||||
_IO.W(mp, 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 temp, string file, bool json = false)
|
||||
{ if (temp) MsgPack.New.Add(mp).WriteAfterAll(file, json).Dispose();
|
||||
else mp .WriteAfterAll(file, json); }
|
||||
public static void WriteAfterAll(this MsgPack mp, bool 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 json = false)
|
||||
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, true); data = _IO.ToArray(); }
|
||||
else using ( MP _IO = new MP(File.OpenWriter())) { _IO.W(mp ); data = _IO.ToArray(); }
|
||||
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, true).Dispose();
|
||||
file.ReadMP( ).Write(file, false, true).Dispose();
|
||||
|
||||
public static void ToMsgPack(this string file) =>
|
||||
file.ReadMP(true).Write(file ).Dispose();
|
||||
file.ReadMP(true).Write(file, false ).Dispose();
|
||||
}
|
||||
|
||||
public static class IKFExt
|
||||
@@ -229,4 +246,112 @@ namespace KKdMainLib
|
||||
return kf;
|
||||
}
|
||||
}
|
||||
|
||||
public static class HashExt
|
||||
{
|
||||
public static ulong HashFNV1a64(this byte[] array, int length) // 0x1403B04D0 in SBZV_7.10; FNV 1a 64-bit
|
||||
{
|
||||
int i = 0;
|
||||
ulong hash = 0xCBF29CE484222325;
|
||||
while (i < length)
|
||||
{ hash = 0x100000001B3 * (hash ^ (ulong)array[i]); i++; }
|
||||
return (hash >> 32) ^ hash;
|
||||
}
|
||||
|
||||
public static uint HashMurmurHash(this byte[] array, int length, uint seed = 0,
|
||||
bool alreadyUpper = false, bool bigEndian = false) // 0x814D7A9C in PCSB00554; MurmurHash
|
||||
{
|
||||
uint a, b, hash;
|
||||
int i;
|
||||
|
||||
const uint m = 0x7FD652AD;
|
||||
const int r = 16;
|
||||
|
||||
hash = seed + 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+323
-38
@@ -1,4 +1,4 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
@@ -7,70 +7,355 @@ namespace KKdMainLib.F2
|
||||
public struct Bloom : System.IDisposable
|
||||
{
|
||||
private int i;
|
||||
private Stream _IO;
|
||||
private Header header;
|
||||
private Stream s;
|
||||
|
||||
public bool IsX;
|
||||
public CountPointer<BLT> BLTs;
|
||||
|
||||
public void BLTReader(string file)
|
||||
{
|
||||
IsX = false;
|
||||
BLTs = default;
|
||||
_IO = File.OpenReader(file + ".blt", true);
|
||||
header = _IO.ReadHeader();
|
||||
if (header.Signature != 0x544D4C42 || header.InnerSignature != 0x3) return;
|
||||
_IO.P -= 0x4;
|
||||
byte[] bltData = File.ReadAllBytes(file + ".blt");
|
||||
Struct _BLMT = bltData.RSt(); bltData = null;
|
||||
if (_BLMT.Header.Signature != 0x544D4C42) return;
|
||||
|
||||
BLTs = _IO.RCPE<BLT>();
|
||||
if (BLTs.C < 1) { _IO.C(); BLTs.C = -1; return; }
|
||||
s = File.OpenReader(_BLMT.Data);
|
||||
s.IsBE = _BLMT.Header.UseBigEndian;
|
||||
|
||||
if (BLTs.C > 0 && BLTs.O == 0) { _IO.C(); BLTs.C = -1; return; }
|
||||
/*{
|
||||
_IO.Format = Header.Format = Format.X;
|
||||
_IO.Offset = Header.Length;
|
||||
_IO.Position = BLTs.Offset;
|
||||
BLTs = _IO.ReadCountPointerX<BLT>();
|
||||
}*/
|
||||
BLTs = s.RCPE<BLT>();
|
||||
if (BLTs.C < 1) { s.C(); BLTs.C = -1; return; }
|
||||
|
||||
_IO.P = BLTs.O;
|
||||
for (i = 0; i < BLTs.C; i++)
|
||||
if (!(BLTs.C > 0 && BLTs.O == 0))
|
||||
{
|
||||
ref BLT blt = ref BLTs.E[i];
|
||||
_IO.RI32E();
|
||||
blt.Color .X = _IO.RF32E();
|
||||
blt.Color .Y = _IO.RF32E();
|
||||
blt.Color .Z = _IO.RF32E();
|
||||
blt.Brightpass.X = _IO.RF32E();
|
||||
blt.Brightpass.Y = _IO.RF32E();
|
||||
blt.Brightpass.Z = _IO.RF32E();
|
||||
blt.Range = _IO.RF32E();
|
||||
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();
|
||||
}
|
||||
}
|
||||
_IO.C();
|
||||
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;
|
||||
|
||||
_IO = File.OpenWriter();
|
||||
_IO.WPSSJIS("ID,ColorR,ColorG,ColorB,BrightpassR,BrightpassG,BrightpassB,Range\n");
|
||||
s = File.OpenWriter();
|
||||
s.WPSSJIS("ID,ColorR,ColorG,ColorB,BrightpassR,BrightpassG,BrightpassB,Range\n");
|
||||
for (i = 0; i < BLTs.C; i++)
|
||||
_IO.W(i + "," + BLTs[i] + "\n");
|
||||
File.WriteAllBytes(file + "_bloom.txt", _IO.ToArray(true));
|
||||
s.W($"{i},{ BLTs[i]}\n");
|
||||
File.WriteAllBytes($"{file}_bloom.txt", s.ToArray(true));
|
||||
}
|
||||
|
||||
private bool disposed;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (_IO != null) _IO.Dispose(); BLTs = default; header = default; disposed = true; } }
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; BLTs = default; IsX = false; disposed = true; } }
|
||||
|
||||
public struct BLT
|
||||
{
|
||||
public Vector3 Color;
|
||||
public Vector3 Brightpass;
|
||||
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() => Color .ToString(6) + "," +
|
||||
Brightpass.ToString(6) + "," +
|
||||
Range .ToS(6);
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
@@ -7,78 +7,373 @@ namespace KKdMainLib.F2
|
||||
public struct ColorCorrection : System.IDisposable
|
||||
{
|
||||
private int i;
|
||||
private Stream _IO;
|
||||
private Header header;
|
||||
private Stream s;
|
||||
|
||||
public bool IsX;
|
||||
public CountPointer<CCT> CCTs;
|
||||
|
||||
public void CCTReader(string file)
|
||||
{
|
||||
IsX = false;
|
||||
CCTs = default;
|
||||
_IO = File.OpenReader(file + ".cct", true);
|
||||
header = _IO.ReadHeader();
|
||||
if (header.Signature != 0x54524343 || header.InnerSignature != 0x3) return;
|
||||
_IO.P -= 0x4;
|
||||
byte[] ccData = File.ReadAllBytes(file + ".cct");
|
||||
Struct _CCRT = ccData.RSt(); ccData = null;
|
||||
if (_CCRT.Header.Signature != 0x54524343) return;
|
||||
|
||||
CCTs = _IO.RCPE<CCT>();
|
||||
if (CCTs.C < 1) { _IO.C(); CCTs.C = -1; return; }
|
||||
s = File.OpenReader(_CCRT.Data);
|
||||
s.IsBE = _CCRT.Header.UseBigEndian;
|
||||
|
||||
if (CCTs.C > 0 && CCTs.O == 0) { _IO.C(); CCTs.C = -1; return; }
|
||||
/*{
|
||||
_IO.Format = Header.Format = Format.X;
|
||||
_IO.Offset = Header.Length;
|
||||
_IO.Position = CCTs.Offset;
|
||||
CCTs = _IO.ReadCountPointerX<CCT>();
|
||||
}*/
|
||||
CCTs = s.RCPE<CCT>();
|
||||
if (CCTs.C < 1) { s.C(); CCTs.C = -1; return; }
|
||||
|
||||
_IO.P = CCTs.O;
|
||||
for (i = 0; i < CCTs.C; i++)
|
||||
if (!(CCTs.C > 0 && CCTs.O == 0))
|
||||
{
|
||||
ref CCT cct = ref CCTs.E[i];
|
||||
_IO.RI32E();
|
||||
cct.Hue = _IO.RF32E();
|
||||
cct.Saturation = _IO.RF32E();
|
||||
cct.Lightness = _IO.RF32E();
|
||||
cct.Exposure = _IO.RF32E();
|
||||
cct.Gamma.X = _IO.RF32E();
|
||||
cct.Gamma.Y = _IO.RF32E();
|
||||
cct.Gamma.Z = _IO.RF32E();
|
||||
cct.Contrast = _IO.RF32E();
|
||||
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);
|
||||
}
|
||||
|
||||
_IO.C();
|
||||
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;
|
||||
|
||||
_IO = File.OpenWriter();
|
||||
_IO.WPSSJIS("ID,Hue,Saturation,Lightness,Exposure,GammaR,GammaG,GammaB,Contrast\n");
|
||||
s = File.OpenWriter();
|
||||
s.WPSSJIS("ID,Hue,Saturation,Lightness,Exposure,GammaR,GammaG,GammaB,Contrast\n");
|
||||
for (i = 0; i < CCTs.C; i++)
|
||||
_IO.W(i + "," + CCTs[i] + "\n");
|
||||
File.WriteAllBytes(file + "_cc.txt", _IO.ToArray(true));
|
||||
s.W($"{i},{CCTs[i]}\n");
|
||||
File.WriteAllBytes($"{file}_cc.txt", s.ToArray(true));
|
||||
}
|
||||
|
||||
private bool disposed;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (_IO != null) _IO.Dispose(); CCTs = default; header = default; disposed = true; } }
|
||||
{ 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 Vector3 Gamma;
|
||||
public Vec3 Gamma;
|
||||
public float Contrast;
|
||||
|
||||
public override string ToString() => Hue .ToS(6) + "," +
|
||||
Saturation.ToS(6) + "," +
|
||||
Lightness .ToS(6) + "," +
|
||||
Exposure .ToS(6) + "," +
|
||||
Gamma .ToString(6) + "," +
|
||||
Contrast .ToS(6);
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+307
-37
@@ -1,4 +1,4 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
@@ -7,74 +7,344 @@ namespace KKdMainLib.F2
|
||||
public struct DOF : System.IDisposable
|
||||
{
|
||||
private int i;
|
||||
private Stream _IO;
|
||||
private Header header;
|
||||
private Stream s;
|
||||
|
||||
public bool IsX;
|
||||
public CountPointer<DFT> DFTs;
|
||||
|
||||
public void DFTReader(string file)
|
||||
{
|
||||
IsX = false;
|
||||
DFTs = default;
|
||||
_IO = File.OpenReader(file + ".dft", true);
|
||||
header = _IO.ReadHeader();
|
||||
if (header.Signature != 0x54464F44 || header.InnerSignature != 0x3) return;
|
||||
_IO.P -= 0x4;
|
||||
byte[] dftData = File.ReadAllBytes(file + ".dft");
|
||||
Struct _DOFT = dftData.RSt(); dftData = null;
|
||||
if (_DOFT.Header.Signature != 0x54464F44) return;
|
||||
|
||||
DFTs = _IO.RCPE<DFT>();
|
||||
if (DFTs.C < 1) { _IO.C(); DFTs.C = -1; return; }
|
||||
s = File.OpenReader(_DOFT.Data);
|
||||
s.IsBE = _DOFT.Header.UseBigEndian;
|
||||
|
||||
if (DFTs.C > 0 && DFTs.O == 0) { _IO.C(); DFTs.C = -1; return; }
|
||||
/*{
|
||||
_IO.Format = Header.Format = Format.X;
|
||||
_IO.Offset = Header.Length;
|
||||
_IO.Position = DFTs.Offset;
|
||||
DFTs = _IO.ReadCountPointerX<DFT>();
|
||||
}*/
|
||||
DFTs = s.RCPE<DFT>();
|
||||
if (DFTs.C < 1) { s.C(); DFTs.C = -1; return; }
|
||||
|
||||
_IO.P = DFTs.O;
|
||||
for (i = 0; i < DFTs.C; i++)
|
||||
if (!(DFTs.C > 0 && DFTs.O == 0))
|
||||
{
|
||||
ref DFT DFT = ref DFTs.E[i];
|
||||
_IO.RI32E();
|
||||
DFT. Focus = _IO.RF32E();
|
||||
DFT. FocusRange = _IO.RF32E();
|
||||
DFT.FuzzingRange = _IO.RF32E();
|
||||
DFT.Ratio = _IO.RF32E();
|
||||
DFT.Quality = _IO.RF32E();
|
||||
if (_IO.IsX) _IO.RI32();
|
||||
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);
|
||||
}
|
||||
|
||||
_IO.C();
|
||||
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;
|
||||
|
||||
_IO = File.OpenWriter();
|
||||
_IO.WPSSJIS("ID,Focus,FocusRange,FuzzingRange,Ratio,Quality\n");
|
||||
s = File.OpenWriter();
|
||||
s.WPSSJIS("ID,Focus,FocusRange,FuzzingRange,Ratio,Quality\n");
|
||||
for (i = 0; i < DFTs.C; i++)
|
||||
_IO.W(i + "," + DFTs[i] + "\n");
|
||||
File.WriteAllBytes(file + "_dof.txt", _IO.ToArray(true));
|
||||
s.W($"{i},{DFTs[i]}\n");
|
||||
File.WriteAllBytes($"{file}_dof.txt", s.ToArray(true));
|
||||
}
|
||||
|
||||
private bool disposed;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (_IO != null) _IO.Dispose(); DFTs = default; header = default; disposed = true; } }
|
||||
{ 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() => Focus .ToS(6) + "," +
|
||||
FocusRange.ToS(6) + "," +
|
||||
FuzzingRange.ToS(6) + "," +
|
||||
Ratio .ToS(6) + "," +
|
||||
Quality .ToS(6);
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+854
-91
@@ -1,4 +1,4 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
@@ -7,69 +7,784 @@ namespace KKdMainLib.F2
|
||||
public struct Light : System.IDisposable
|
||||
{
|
||||
private int i, i0;
|
||||
private Stream _IO;
|
||||
private Header header;
|
||||
private Stream s;
|
||||
|
||||
public CountPointer<CountPointer<LIT>> LITs;
|
||||
public bool IsX;
|
||||
public CountPointer<LightStruct> LITs;
|
||||
|
||||
public void LITReader(string file)
|
||||
{
|
||||
IsX = false;
|
||||
LITs = default;
|
||||
_IO = File.OpenReader(file + ".lit", true);
|
||||
header = _IO.ReadHeader();
|
||||
if (header.Signature != 0x4354494C || header.InnerSignature != 0x2 ||
|
||||
header.SectionSignature != 0x2) return;
|
||||
byte[] litData = File.ReadAllBytes(file + ".lit");
|
||||
Struct _LITC = litData.RSt(); litData = null;
|
||||
if (_LITC.Header.Signature != 0x4354494C) return;
|
||||
|
||||
LITs = _IO.RCPE<CountPointer<LIT>>();
|
||||
if (LITs.C < 1) { _IO.C(); LITs.C = -1; return; }
|
||||
s = File.OpenReader(_LITC.Data);
|
||||
s.IsBE = _LITC.Header.UseBigEndian;
|
||||
|
||||
_IO.P = LITs.O;
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
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)
|
||||
{
|
||||
LITs[i] = _IO.RCPX<LIT>();
|
||||
if ((LITs[i].C > 0 || LITs[i].O == 0) && !_IO.IsX) { _IO.C(); LITs.C = -1; return; }
|
||||
/*{
|
||||
_IO.Format = Header.Format = Format.X;
|
||||
_IO.Offset = Header.Length;
|
||||
_IO.Position = LITs.Offset;
|
||||
LITs[i] = _IO.ReadCountPointerX<LIT>();
|
||||
}
|
||||
if (_IO.IsX) IO.ReadInt64();*/
|
||||
}
|
||||
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++)
|
||||
{
|
||||
_IO.P = LITs[i].O;
|
||||
for (i0 = 0; i0 < LITs[i].C; i0++)
|
||||
for (i = 0; i < LITs.C; i++)
|
||||
{
|
||||
ref LIT lit = ref LITs.E[i].E[i0];
|
||||
lit.Id = (Id )_IO.RI32E();
|
||||
lit.Flags = (Flags)_IO.RI32E();
|
||||
lit.Type = (Type )_IO.RI32E();
|
||||
if (_IO.IsX) { _IO.RI64(); _IO.RI64(); _IO.RI64(); }
|
||||
lit.Ambient .X = _IO.RF32E();
|
||||
lit.Ambient .Y = _IO.RF32E();
|
||||
lit.Ambient .Z = _IO.RF32E();
|
||||
lit.Ambient .W = _IO.RF32E();
|
||||
lit.Diffuse .X = _IO.RF32E();
|
||||
lit.Diffuse .Y = _IO.RF32E();
|
||||
lit.Diffuse .Z = _IO.RF32E();
|
||||
lit.Diffuse .W = _IO.RF32E();
|
||||
lit.Specular .X = _IO.RF32E();
|
||||
lit.Specular .Y = _IO.RF32E();
|
||||
lit.Specular .Z = _IO.RF32E();
|
||||
lit.Specular .W = _IO.RF32E();
|
||||
lit.Position .X = _IO.RF32E();
|
||||
lit.Position .Y = _IO.RF32E();
|
||||
lit.Position .Z = _IO.RF32E();
|
||||
lit.ToneCurve.X = _IO.RF32E();
|
||||
lit.ToneCurve.Y = _IO.RF32E();
|
||||
lit.ToneCurve.Z = _IO.RF32E();
|
||||
if (_IO.IsX) { _IO.RI64(); _IO.RI64(); _IO.RI64();
|
||||
_IO.RI64(); _IO.RI64(); _IO.RI32(); }
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
_IO.C();
|
||||
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)
|
||||
@@ -77,48 +792,89 @@ namespace KKdMainLib.F2
|
||||
i = 0;
|
||||
if (LITs.C < 1) return;
|
||||
|
||||
_IO = File.OpenWriter();
|
||||
_IO.WPSSJIS("Type,AmbientR,AmbientG,AmbientB,DiffuseR,DiffuseG,DiffuseB,SpecularR,SpecularG," +
|
||||
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[i].C; i0++)
|
||||
_IO.W(LITs[i][i0] + "," + i + "\n");
|
||||
File.WriteAllBytes(file + "_light.txt", _IO.ToArray(true));
|
||||
}
|
||||
|
||||
public struct LIT
|
||||
{
|
||||
public Id Id;
|
||||
public Flags Flags;
|
||||
public Type Type;
|
||||
public Vector4 Ambient;
|
||||
public Vector4 Diffuse;
|
||||
public Vector4 Specular;
|
||||
public Vector3 Position;
|
||||
public Vector3 ToneCurve;
|
||||
|
||||
public override string ToString() => Flags == 0 ? ",,,,,,,,,,,,,,,," : Type + "," +
|
||||
((Flags & Flags.Ambient ) == 0 ? ",,," : Ambient .ToString(6) + ",") +
|
||||
((Flags & Flags.Diffuse ) == 0 ? ",,," : Diffuse .ToString(6) + ",") +
|
||||
((Flags & Flags.Specular ) == 0 ? ",,,," : Specular .ToString(6) + ",") +
|
||||
((Flags & Flags.Position ) == 0 ? ",,," : Position .ToString(6) + ",") +
|
||||
((Flags & Flags.ToneCurve) == 0 ? ",,," : ToneCurve.ToString(6));
|
||||
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 (_IO != null) _IO.Dispose(); LITs = default; header = default; disposed = true; } }
|
||||
{ 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 = 0,
|
||||
STAGE = 1,
|
||||
SUN = 2,
|
||||
REFLECT = 3,
|
||||
SHADOW = 4,
|
||||
CHARA_COLOR = 5,
|
||||
CHARA_F = 6,
|
||||
PROJECTION = 7,
|
||||
CHARA = 0x00,
|
||||
STAGE = 0x01,
|
||||
SUN = 0x02,
|
||||
REFLECT = 0x03,
|
||||
SHADOW = 0x04,
|
||||
CHARA_COLOR = 0x05,
|
||||
CHARA_F = 0x06,
|
||||
PROJECTION = 0x07,
|
||||
}
|
||||
|
||||
public enum Type : int
|
||||
@@ -131,12 +887,19 @@ namespace KKdMainLib.F2
|
||||
|
||||
public enum Flags : int
|
||||
{
|
||||
Type = 0b0000000001,
|
||||
Ambient = 0b0000000010,
|
||||
Diffuse = 0b0000000100,
|
||||
Specular = 0b0000001000,
|
||||
Position = 0b0000010000,
|
||||
ToneCurve = 0b1000000000,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
+122
-130
@@ -1,4 +1,4 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using System.IO.Compression;
|
||||
using System.Security.Cryptography;
|
||||
@@ -11,31 +11,31 @@ namespace KKdMainLib
|
||||
public class FARC : System.IDisposable
|
||||
{
|
||||
public FARC() => NewFARC();
|
||||
public FARC(string File, bool IsDirectory = false)
|
||||
{ if (IsDirectory) DirectoryPath = File; else FilePath = File; NewFARC(); }
|
||||
public FARC(string file, bool isDirectory = false)
|
||||
{ if (isDirectory) DirectoryPath = file; else FilePath = file; NewFARC(); }
|
||||
|
||||
private void NewFARC() { Files = null; Signature = Farc.FArC; cbc = ft = false; }
|
||||
private void NewFARC() { Files = KKdList<FARCFile>.New; Signature = Farc.FArC; Format = Format.DT; }
|
||||
|
||||
public FARCFile[] Files = null;
|
||||
public KKdList<FARCFile> Files = KKdList<FARCFile>.New;
|
||||
public Type FARCType;
|
||||
public Farc Signature = Farc.FArC;
|
||||
public Format Format = Format.DT;
|
||||
public string FilePath, DirectoryPath;
|
||||
public bool HasFiles => Files == null ? false : Files.Length > 0;
|
||||
public bool HasFiles => !Files.IsNull || Files.Count > 0;
|
||||
public int CompressionLevel = 12;
|
||||
|
||||
private bool cbc, ft;
|
||||
|
||||
private readonly byte[] key = Text.ToASCII("project_diva.bin");
|
||||
private readonly byte[] key = "project_diva.bin".ToASCII();
|
||||
|
||||
private readonly byte[] keyFT = { 0x13, 0x72, 0xD5, 0x7B, 0x6E, 0x9E,
|
||||
0x31, 0xEB, 0xA2, 0x39, 0xB8, 0x3C, 0x15, 0x57, 0xC6, 0xBB };
|
||||
|
||||
private AesManaged GetAes(bool isFT, byte[] iv) =>
|
||||
new AesManaged { KeySize = 128, Key = isFT ? keyFT : key,
|
||||
new AesManaged () { KeySize = 128, Key = isFT ? keyFT : key,
|
||||
BlockSize = 128, Mode = isFT ? CipherMode.CBC : CipherMode.ECB,
|
||||
Padding = PaddingMode.Zeros, IV = iv ?? new byte[16] };
|
||||
|
||||
public void UnPack(bool saveToDisk = true)
|
||||
{ if (HeaderReader()) { FileReader(); if (saveToDisk) this.SaveToDisk(); } }
|
||||
|
||||
public void Unpack(bool saveToDisk = true)
|
||||
{ if (HeaderReader()) { FileReader(); if (saveToDisk) SaveToDisk(); } }
|
||||
|
||||
public bool HeaderReader()
|
||||
{
|
||||
@@ -43,7 +43,7 @@ namespace KKdMainLib
|
||||
if (!File.Exists(FilePath)) return false;
|
||||
|
||||
Stream reader = File.OpenReader(FilePath);
|
||||
DirectoryPath = Path.GetFullPath(FilePath).Replace(Path.GetExtension(FilePath), "");
|
||||
DirectoryPath = Path.RemoveExtension(Path.GetFullPath(FilePath));
|
||||
Signature = (Farc)reader.RI32E(true);
|
||||
if (Signature != Farc.FArc && Signature != Farc.FArC && Signature != Farc.FARC)
|
||||
{ reader.Dispose(); return false; }
|
||||
@@ -53,12 +53,11 @@ namespace KKdMainLib
|
||||
{
|
||||
FARCType = (Type)reader.RI32E(true);
|
||||
reader.RI32();
|
||||
|
||||
int farcMode = reader.RI32E(true);
|
||||
ft = farcMode == 0x10;
|
||||
cbc = farcMode != 0x10 && farcMode != 0x40;
|
||||
|
||||
if (cbc && FARCType.HasFlag(Type.ECB))
|
||||
Format = (FARCType & Type.Enc) != 0 && (farcMode & (farcMode - 1)) != 0 ? Format.FT : Format.DT;
|
||||
|
||||
if (Format == Format.FT && (FARCType & Type.Enc) != 0)
|
||||
{
|
||||
reader.Dispose();
|
||||
byte[] header = new byte[headerLength - 0x08];
|
||||
@@ -73,40 +72,41 @@ namespace KKdMainLib
|
||||
reader = File.OpenReader(header);
|
||||
|
||||
farcMode = reader.RI32E(true);
|
||||
ft = farcMode == 0x10;
|
||||
}
|
||||
}
|
||||
|
||||
if (Signature == Farc.FARC)
|
||||
if (reader.RI32E(true) == 1)
|
||||
Files = new FARCFile[reader.RI32E(true)];
|
||||
Files.Capacity = reader.RI32E(true);
|
||||
reader.RI32();
|
||||
|
||||
if (Files == null)
|
||||
if (Files.Capacity == 0)
|
||||
{
|
||||
int Count = 0;
|
||||
long Position = reader.I64P;
|
||||
while (reader.I64P < headerLength)
|
||||
long Position = reader.PI64;
|
||||
while (reader.PI64 < headerLength)
|
||||
{
|
||||
reader.NT();
|
||||
reader.RI32();
|
||||
if (Signature != Farc.FArc ) reader.RI32();
|
||||
if (Signature != Farc.FArc) reader.RI32();
|
||||
reader.RI32();
|
||||
if (Signature == Farc.FARC && ft) reader.RI32();
|
||||
if (Signature == Farc.FARC && Format == Format.FT) reader.RI32();
|
||||
Count++;
|
||||
}
|
||||
reader.I64P = Position;
|
||||
Files = new FARCFile[Count];
|
||||
reader.PI64 = Position;
|
||||
Files.Capacity = Count;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
for (int i = 0; i < Files.Capacity; i++)
|
||||
{
|
||||
Files[i].Name = reader.NTUTF8();
|
||||
Files[i].Offset = reader.RI32E(true);
|
||||
if (Signature != Farc.FArc) Files[i].SizeComp = reader.RI32E(true);
|
||||
Files[i].SizeUnc = reader.RI32E(true);
|
||||
if (Signature == Farc.FARC && ft)
|
||||
Files[i].Type = (Type)reader.RI32E(true);
|
||||
FARCFile file = default;
|
||||
file.Name = reader.NTUTF8();
|
||||
file.Offset = reader.RI32E(true);
|
||||
if (Signature != Farc.FArc) file.SizeComp = reader.RI32E(true);
|
||||
file.SizeUnc = reader.RI32E(true);
|
||||
if (Signature == Farc.FARC && Format == Format.FT)
|
||||
file.Type = (Type)reader.RI32E(true);
|
||||
Files.Add(file);
|
||||
}
|
||||
|
||||
reader.Dispose();
|
||||
@@ -114,92 +114,81 @@ namespace KKdMainLib
|
||||
}
|
||||
|
||||
private void FileReader()
|
||||
{ for (int i = 0; i < Files.Length; i++) FileReader(i); }
|
||||
{ for (int i = 0; i < Files.Count; i++) FileReader(i); }
|
||||
|
||||
public byte[] FileReader(string file)
|
||||
{
|
||||
if (!HasFiles) return null;
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
if (Files[i].Name.ToLower() == file.ToLower()) return FileReader(i);
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool Exists(string file)
|
||||
{
|
||||
if (!HasFiles) return false;
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
if (Files[i].Name.ToLower() == file.ToLower()) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public byte[] FileReader(int i)
|
||||
{
|
||||
if (!HasFiles) return null;
|
||||
if (i >= Files.Length) return null;
|
||||
if (i >= Files.Count) return null;
|
||||
|
||||
FARCFile file = Files[i];
|
||||
if (Signature != Farc.FARC)
|
||||
{
|
||||
if (Signature == Farc.FArC)
|
||||
using (MSIO.MemoryStream memorystream = new MSIO.MemoryStream(
|
||||
File.ReadAllBytes(FilePath, Files[i].SizeComp, Files[i].Offset)))
|
||||
using (GZipStream gZipStream = new GZipStream(memorystream, CompressionMode.Decompress))
|
||||
{
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
}
|
||||
else Files[i].Data = File.ReadAllBytes(FilePath, Files[i].SizeUnc, Files[i].Offset);
|
||||
return Files[i].Data;
|
||||
file.Data = Signature == Farc.FArC && file.SizeUnc > 0
|
||||
? File.ReadAllBytes(FilePath, file.SizeComp, file.Offset).InflateGZip(file.SizeUnc)
|
||||
: File.ReadAllBytes(FilePath, file.SizeUnc, file.Offset);
|
||||
Files[i] = file;
|
||||
return file.Data;
|
||||
}
|
||||
|
||||
int FileSize = FARCType.HasFlag(Type.ECB) || Files[i].Type.HasFlag(Type.ECB) ?
|
||||
Files[i].SizeComp.A(0x10) : Files[i].SizeComp;
|
||||
MSIO.FileStream stream = new MSIO.FileStream(FilePath, MSIO.FileMode.Open,
|
||||
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite);
|
||||
stream.Seek(Files[i].Offset, 0);
|
||||
Files[i].Data = new byte[FileSize];
|
||||
|
||||
bool encrypted = false;
|
||||
if (FARCType.HasFlag(Type.ECB))
|
||||
int FileSize = ((FARCType | file.Type) & Type.Enc) != 0 ? file.SizeComp.A(0x10)
|
||||
: (((FARCType | file.Type) & Type.GZip) != 0 ? file.SizeComp : file.SizeUnc);
|
||||
using (Stream stream = File.OpenReader(FilePath))
|
||||
{
|
||||
if ((ft && Files[i].Type.HasFlag(Type.ECB)) || cbc)
|
||||
stream.S(file.Offset, 0);
|
||||
file.Data = stream.RBy(FileSize);
|
||||
}
|
||||
|
||||
if ((FARCType & Type.Enc) != 0)
|
||||
{
|
||||
if (Format == Format.FT && (file.Type & Type.Enc) != 0)
|
||||
{
|
||||
using (AesManaged aes = GetAes(true, null))
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
using (CryptoStream cryptoStream = new CryptoStream(new MSIO.MemoryStream(file.Data),
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Files[i].Data, 0, FileSize);
|
||||
Files[i].Data = SkipData(Files[i].Data, 0x10);
|
||||
cryptoStream.Read(file.Data, 0, FileSize);
|
||||
file.Data = SkipData(file.Data, 0x10);
|
||||
}
|
||||
else
|
||||
using (AesManaged aes = GetAes(false, null))
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
using (CryptoStream cryptoStream = new CryptoStream(new MSIO.MemoryStream(file.Data),
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(Files[i].Data, 0, FileSize);
|
||||
encrypted = true;
|
||||
cryptoStream.Read(file.Data, 0, FileSize);
|
||||
}
|
||||
|
||||
bool compressed = false;
|
||||
if (((ft && Files[i].Type.HasFlag(Type.GZip)) ||
|
||||
FARCType.HasFlag(Type.GZip)) && Files[i].SizeUnc > 0)
|
||||
{
|
||||
GZipStream gZipStream = new GZipStream(encrypted ? new MSIO.MemoryStream(Files[i].Data) :
|
||||
(MSIO.Stream)stream, CompressionMode.Decompress);
|
||||
byte[] Temp = new byte[Files[i].SizeUnc];
|
||||
gZipStream.Read(Temp, 0, Files[i].SizeUnc);
|
||||
Files[i].Data = Temp;
|
||||
gZipStream.Dispose();
|
||||
compressed = true;
|
||||
}
|
||||
if (((file.Type | FARCType) & Type.GZip) != 0 && file.SizeUnc > 0)
|
||||
file.Data = file.Data.InflateGZip(file.SizeUnc);
|
||||
|
||||
if (!encrypted && !compressed)
|
||||
{
|
||||
Files[i].Data = new byte[Files[i].SizeUnc];
|
||||
stream.Read(Files[i].Data, 0, Files[i].SizeUnc);
|
||||
}
|
||||
stream.Dispose();
|
||||
return Files[i].Data;
|
||||
Files[i] = file;
|
||||
return file.Data;
|
||||
}
|
||||
|
||||
private void SaveToDisk()
|
||||
{
|
||||
if (DirectoryPath == null || Files == null) return;
|
||||
if (DirectoryPath == "" || Files.Length < 1) return;
|
||||
if (DirectoryPath == null || Files.IsNull ) return;
|
||||
if (DirectoryPath == "" || Files.Count < 1) return;
|
||||
MSIO.Directory.CreateDirectory(DirectoryPath);
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
{
|
||||
if (Files[i].Data != null)
|
||||
File.WriteAllBytes(Path.Combine(DirectoryPath, Files[i].Name), Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
FARCFile file = Files[i];
|
||||
if (file.Data != null)
|
||||
File.WriteAllBytes(Path.Combine(DirectoryPath, file.Name), file.Data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,9 +203,9 @@ namespace KKdMainLib
|
||||
{
|
||||
NewFARC();
|
||||
string[] files = Directory.GetFiles(DirectoryPath);
|
||||
Files = new FARCFile[files.Length];
|
||||
Files.Capacity = files.Length;
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
Files[i] = new FARCFile { Name = Path.GetFileName(files[i]), Data = File.ReadAllBytes(files[i]) };
|
||||
Files.Add(new FARCFile { Name = Path.GetFileName(files[i]), Data = File.ReadAllBytes(files[i]) });
|
||||
files = null;
|
||||
Signature = signature;
|
||||
Save();
|
||||
@@ -224,10 +213,12 @@ namespace KKdMainLib
|
||||
|
||||
public void Save()
|
||||
{
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
if (!HasFiles || (Signature != Farc.FArc && Signature != Farc.FArC && Signature != Farc.FARC)) return;
|
||||
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
{
|
||||
string ext = Path.GetExtension(Files[i].Name).ToLower();
|
||||
if (ext == ".a3da" || ext == ".diva" || ext == ".vag")
|
||||
if (ext == ".a3da" || ext == ".diva" || ext == ".farc" || ext == ".vag")
|
||||
{ Signature = Farc.FArc; break; }
|
||||
}
|
||||
|
||||
@@ -236,77 +227,78 @@ namespace KKdMainLib
|
||||
|
||||
using (Stream headerWriter = File.OpenWriter())
|
||||
{
|
||||
if (Signature == Farc.FArc) headerWriter.WE(0x20, true);
|
||||
else if (Signature == Farc.FArC) headerWriter.WE(0x10, true);
|
||||
if (Signature == Farc.FArc) headerWriter.WE(0x01, true);
|
||||
else if (Signature == Farc.FArC) headerWriter.WE(0x01, true);
|
||||
else if (Signature == Farc.FARC)
|
||||
{
|
||||
headerWriter.WE((int)FARCType, true);
|
||||
headerWriter.W (0x00);
|
||||
headerWriter.W (0x00);
|
||||
headerWriter.WE(0x40, true);
|
||||
headerWriter.W (0x00);
|
||||
headerWriter.W (0x00);
|
||||
headerWriter.W (0x00);
|
||||
}
|
||||
int HeaderPartLength = Signature == Farc.FArc ? 0x09 : 0x0D;
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
headerWriter.L += Path.GetFileName(Files[i].Name).Length + HeaderPartLength;
|
||||
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.W (headerWriter.ToArray(true));
|
||||
}
|
||||
|
||||
int align = writer.P.A(0x10) - writer.P;
|
||||
for (int i1 = 0; i1 < align; i1++)
|
||||
writer.W((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
|
||||
|
||||
for (int i = 0; i < Files.Length; i++)
|
||||
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.Length; i++)
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
{
|
||||
writer.W(Path.GetFileName(Files[i].Name) + "\0");
|
||||
writer.WE(Files[i].Offset, true);
|
||||
if (Signature != Farc.FArc)
|
||||
writer.WE(Files[i].SizeComp, true);
|
||||
writer.WE(Files[i].SizeUnc, true);
|
||||
FARCFile file = Files[i];
|
||||
writer.W (file.Name + "\0");
|
||||
writer.WE(file.Offset, true);
|
||||
if (Signature != Farc.FArc) writer.WE(file.SizeComp, true);
|
||||
writer.WE(file.SizeUnc, true);
|
||||
}
|
||||
writer.Dispose();
|
||||
}
|
||||
|
||||
private void CompressStuff(int i, ref Stream writer)
|
||||
{
|
||||
Files[i].Offset = writer.P;
|
||||
Files[i].SizeUnc = Files[i].Data.Length;
|
||||
Files[i].Type = Type.None;
|
||||
FARCFile file = Files[i];
|
||||
file.Offset = writer.P;
|
||||
file.SizeUnc = file.Data.Length;
|
||||
file.Type = Type.None;
|
||||
|
||||
if (Signature == Farc.FArC || (Signature == Farc.FARC && FARCType.HasFlag(Type.GZip)))
|
||||
byte[] data = file.Data;
|
||||
if (Signature == Farc.FArC || (Signature == Farc.FARC && (FARCType & Type.GZip) != 0))
|
||||
{
|
||||
Files[i].Type |= Type.GZip;
|
||||
MSIO.MemoryStream stream = new MSIO.MemoryStream();
|
||||
using (GZipStream gZipStream = new GZipStream(stream, CompressionMode.Compress))
|
||||
gZipStream.Write(Files[i].Data, 0, Files[i].Data.Length);
|
||||
Files[i].Data = stream.ToArray();
|
||||
stream.Dispose();
|
||||
Files[i].SizeComp = Files[i].Data.Length;
|
||||
file.Type |= Type.GZip;
|
||||
data = file.Data.DeflateGZip(CompressionLevel);
|
||||
}
|
||||
file.SizeComp = data.Length;
|
||||
|
||||
if (Signature == Farc.FARC && FARCType.HasFlag(Type.ECB))
|
||||
if (Signature == Farc.FARC && (FARCType & Type.Enc) != 0)
|
||||
{
|
||||
int AlignData = Files[i].Data.Length.A(0x40);
|
||||
byte[] Data = new byte[AlignData];
|
||||
for (int i1 = 0; i1 < AlignData ; i1++) Data[i1] = 0x78;
|
||||
for (int i1 = 0; i1 < Files[i].Data.Length; i1++) Data[i1] = Files[i].Data[i1];
|
||||
|
||||
Files[i].Data = Encrypt(Data, false);
|
||||
int alignLength = data.Length.A(0x40);
|
||||
byte[] tempData = new byte[alignLength];
|
||||
System.Array.Copy(data, tempData, data.Length);
|
||||
for (int i1 = file.Data.Length; i1 < alignLength; i1++) tempData[i1] = 0x78;
|
||||
data = Encrypt(tempData, false);
|
||||
}
|
||||
|
||||
writer.W(Files[i].Data);
|
||||
Files[i].Data = null;
|
||||
writer.W(data);
|
||||
|
||||
if (Signature != Farc.FARC)
|
||||
{
|
||||
int Align = writer.P.A(0x20) - writer.P;
|
||||
int Align = writer.P.A(0x10) - writer.P;
|
||||
for (int i1 = 0; i1 < Align; i1++)
|
||||
writer.W((byte)(Signature == Farc.FArc ? 0x00 : 0x78));
|
||||
}
|
||||
Files[i] = file;
|
||||
}
|
||||
|
||||
private byte[] Encrypt(byte[] data, bool isFT)
|
||||
@@ -344,7 +336,7 @@ namespace KKdMainLib
|
||||
{
|
||||
None = 0b000,
|
||||
GZip = 0b010,
|
||||
ECB = 0b100,
|
||||
Enc = 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,15 +1,102 @@
|
||||
using MSIO = System.IO;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+80
-57
@@ -1,4 +1,4 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
@@ -12,22 +12,23 @@ namespace KKdMainLib.IO
|
||||
public static byte[] NT (this Stream stream, byte end = 0)
|
||||
{
|
||||
KKdList<byte> s = KKdList<byte>.New;
|
||||
while (stream.I64P < stream.I64L)
|
||||
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.I64P--; return val; }
|
||||
{ byte val = stream.RU8(); stream.PI64--; return val; }
|
||||
public static char PCASCII(this Stream stream)
|
||||
{ byte val = stream.RU8(); stream.I64P--; return (char)val; }
|
||||
{ byte val = stream.RU8(); stream.PI64--; return (char)val; }
|
||||
public static char PCUTF8 (this Stream stream)
|
||||
{ long LongPosition = stream.I64P; char val = stream.RCUTF8();
|
||||
stream.I64P = LongPosition; return val; }
|
||||
{ long LongPosition = stream.PI64; char val = stream.RCUTF8();
|
||||
stream.PI64 = LongPosition; return val; }
|
||||
|
||||
public static Stream SW(this Stream stream)
|
||||
{
|
||||
@@ -37,73 +38,95 @@ namespace KKdMainLib.IO
|
||||
return stream;
|
||||
}
|
||||
|
||||
public static bool As(this Stream stream, byte next)
|
||||
{ if (stream.PB() == next) { stream.PB(); return true; } else return false; }
|
||||
public static bool As(this Stream stream, byte[] next)
|
||||
{
|
||||
public static bool 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)
|
||||
{
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
public static bool As(this Stream stream, char next)
|
||||
{ if (stream.PCUTF8() == next) { stream.RCUTF8(); return true; } else return false; }
|
||||
public static bool As(this Stream stream, string next)
|
||||
{
|
||||
for (var i = 0; i < next.Length; i++)
|
||||
if (!As(stream, next[i])) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public static long RIX(this Stream stream ) => stream.IsX ?
|
||||
stream.RI64() : stream.RU32E( );
|
||||
public static long RIX(this Stream stream, bool isBE) => stream.IsX ?
|
||||
stream.RI64() : stream.RU32E(isBE);
|
||||
public static 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.W ( val);
|
||||
else stream.WE((int)val); POF.Offsets.Add(stream.P); }
|
||||
public static void WX(this Stream stream, long val, ref POF POF, bool IsBE)
|
||||
{ if (stream.IsX) stream.W ( val );
|
||||
else stream.WE((int)val, IsBE); POF.Offsets.Add(stream.P); }
|
||||
public static void WX(this Stream stream, long val, 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.W ( 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.W ( val );
|
||||
else stream.WE((int)val, IsBE); }
|
||||
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)
|
||||
public static byte[] RaO(this Stream stream, long offset = -1, long length = -1)
|
||||
{
|
||||
byte[] arr = null;
|
||||
long Position = stream.I64P;
|
||||
if (Offset == -1) { Position += stream.IsX ? 8 : 4; Offset = stream.RIX(); }
|
||||
stream.I64P = Offset;
|
||||
if (Length == -1) arr = stream.NT();
|
||||
else arr = stream.RBy(Length);
|
||||
stream.I64P = Position;
|
||||
long Position = stream.PI64;
|
||||
if (offset == -1) { Position += stream.IsX ? 8 : 4; offset = stream.RIX(); }
|
||||
stream.PI64 = offset;
|
||||
if (length == -1) arr = stream.NT();
|
||||
else arr = stream.RBy(length);
|
||||
stream.PI64 = Position;
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static string RSaO(this Stream stream, long Offset = -1, long Length = -1)
|
||||
public static string RSaO(this Stream stream)
|
||||
{
|
||||
string s = null;
|
||||
long Position = stream.I64P;
|
||||
if (Offset == -1) { Position += stream.IsX ? 8 : 4; Offset = stream.RIX(); }
|
||||
stream.I64P = Offset;
|
||||
if (Length == -1) s = stream.NTUTF8();
|
||||
else s = stream.RSUTF8(Length);
|
||||
stream.I64P = Position;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -114,11 +137,11 @@ namespace KKdMainLib.IO
|
||||
public static void WPSSJIS(this Stream stream, ref Pointer<string> val)
|
||||
{ val.O = stream.P; stream.WPSSJIS(val.V); }
|
||||
|
||||
public static string RPSSJIS(this Stream stream, long Offset = -1, long Length = -1) =>
|
||||
Text.ShiftJIS.GetString(stream.RaO(Offset, Length));
|
||||
public static string RPSSJIS(this Stream stream, long offset = -1, long length = -1) =>
|
||||
Text.ShiftJIS.GetString(stream.RaO(offset, length));
|
||||
|
||||
public static void WPSSJIS(this Stream stream, string String) =>
|
||||
stream.W(Text.ShiftJIS.GetBytes(String));
|
||||
public static 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>();
|
||||
@@ -133,7 +156,7 @@ namespace KKdMainLib.IO
|
||||
public static void W<T>(this Stream stream, Pointer<T> val) =>
|
||||
stream.W(val.O);
|
||||
|
||||
public static CountPointer<T> ReadCountPointer<T>(this Stream stream) =>
|
||||
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)
|
||||
|
||||
+94
-23
@@ -1,30 +1,41 @@
|
||||
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));
|
||||
public static Stream OpenWriter(byte[] Data) => new Stream(new MSIO.MemoryStream(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) { byte[] data =
|
||||
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); if (SetLength0) _IO.SL(0); return _IO; }
|
||||
public static Stream OpenWriter(string file, int SetLength)
|
||||
{ Stream _IO = OpenWriter(file); _IO.SL(SetLength); return _IO; }
|
||||
{ Stream _IO = 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)
|
||||
{ byte[] Data; using (Stream _IO = OpenReader(file)) Data = _IO.RBy(length, offset); return Data; }
|
||||
@@ -41,16 +52,76 @@ namespace KKdMainLib.IO
|
||||
return Data.Replace(((char)0xFEFF).ToString(), "").Replace("\r", "").Split('\n'); }
|
||||
|
||||
public static void WriteAllBytes(string file, byte[] data)
|
||||
{ using (Stream _IO = OpenWriter(file, true)) _IO.W(data); }
|
||||
{ using Stream _IO = OpenWriter(file, true); if (data != null) _IO.W(data); }
|
||||
|
||||
public static void WriteAllText (string file, string data)
|
||||
{ using (Stream _IO = OpenWriter(file, true)) _IO.W(data); }
|
||||
{ using Stream _IO = OpenWriter(file, true); if (data != null) _IO.W(data); }
|
||||
|
||||
public static void WriteAllLines(string file, string[] data)
|
||||
{ using (Stream _IO = OpenWriter(file, true)) for (int i = 0; i < data.Length; i++)
|
||||
_IO.W(data[i] + "\r\n"); }
|
||||
{ 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);
|
||||
}
|
||||
}
|
||||
|
||||
+78
-66
@@ -1,4 +1,4 @@
|
||||
//Original or reader part: https://github.com/MarcosLopezC/LightJson/
|
||||
//Original or reader part: https://github.com/MarcosLopezC/LightJson/
|
||||
|
||||
using KKdBaseLib;
|
||||
using BaseExtensions = KKdBaseLib.Extensions;
|
||||
@@ -37,54 +37,54 @@ namespace KKdMainLib.IO
|
||||
};
|
||||
return new MsgPack(Key, obj);
|
||||
}
|
||||
|
||||
private string RS()
|
||||
{
|
||||
if (!Extensions.As(_IO, '"')) return null;
|
||||
|
||||
private string RS()
|
||||
{
|
||||
if (!Extensions.As(_IO, '"')) return null;
|
||||
char c;
|
||||
string s = "";
|
||||
while (true)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
c = _IO.RCUTF8();
|
||||
|
||||
if (c == '\\')
|
||||
{
|
||||
c = _IO.RCUTF8();
|
||||
if (c == '\\')
|
||||
{
|
||||
c = _IO.RCUTF8();
|
||||
|
||||
switch (char.ToLower(c))
|
||||
{
|
||||
case '"' :
|
||||
case '\\':
|
||||
case '/' : s += c; break;
|
||||
case 'b' : s += '\b'; break;
|
||||
case 'f' : s += '\f'; break;
|
||||
switch (char.ToLower(c))
|
||||
{
|
||||
case '"' :
|
||||
case '\\':
|
||||
case '/' : s += c; break;
|
||||
case 'b' : s += '\b'; break;
|
||||
case 'f' : s += '\f'; break;
|
||||
case 'n' : s += '\n'; break;
|
||||
case 'r' : s += '\r'; break;
|
||||
case 't' : s += '\t'; break;
|
||||
case 'u' : s += RUL(); break;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
else if (c == '"') break;
|
||||
else if (char.IsControl(c))
|
||||
case 'r' : s += '\r'; break;
|
||||
case 't' : s += '\t'; break;
|
||||
case 'u' : s += RUL(); break;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
else if (c == '"') break;
|
||||
else if (char.IsControl(c))
|
||||
return null;
|
||||
else s += c;
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private char RUL() =>
|
||||
private char RUL() =>
|
||||
(char)((((((RHD() << 4) | RHD()) << 4) | RHD()) << 4) | RHD());
|
||||
|
||||
private int RHD() => byte.Parse(_IO.RCUTF8().ToString(),
|
||||
private int RHD() => byte.Parse(_IO.RCUTF8().ToString(),
|
||||
System.Globalization.NumberStyles.HexNumber);
|
||||
|
||||
private KKdList<MsgPack> RO()
|
||||
{
|
||||
KKdList<MsgPack> obj = KKdList<MsgPack>.New;
|
||||
if (!Extensions.As(_IO, '{')) return KKdList<MsgPack>.Null;
|
||||
if (_IO.SW().PCUTF8() == '}')
|
||||
if (_IO.SW().PCUTF8() == '}')
|
||||
{ _IO.RCUTF8(); return KKdList<MsgPack>.Null; }
|
||||
|
||||
string key;
|
||||
@@ -99,21 +99,21 @@ namespace KKdMainLib.IO
|
||||
|
||||
obj.Add(ReadValue(key));
|
||||
c = _IO.SW().PCUTF8();
|
||||
|
||||
|
||||
if (c == '}') { _IO.RCUTF8(); break; }
|
||||
else if (c == ',') { _IO.RCUTF8(); continue; }
|
||||
else return KKdList<MsgPack>.Null;
|
||||
}
|
||||
|
||||
obj.Capacity = obj.Count;
|
||||
return obj;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private MsgPack[] RA()
|
||||
{
|
||||
KKdList<MsgPack> obj = KKdList<MsgPack>.New;
|
||||
if (!Extensions.As(_IO, '[')) return null;
|
||||
if (_IO.SW().PCUTF8() == ']')
|
||||
{ _IO.RCUTF8(); return null; }
|
||||
{ _IO.RCUTF8(); return obj.ToArray(); }
|
||||
|
||||
char c;
|
||||
while (true)
|
||||
@@ -125,20 +125,28 @@ namespace KKdMainLib.IO
|
||||
else if (c == ',') { _IO.RCUTF8(); continue; }
|
||||
else return null;
|
||||
}
|
||||
obj.Capacity = obj.Count;
|
||||
return obj.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private object RF()
|
||||
{
|
||||
string s = " ";
|
||||
private object RF()
|
||||
{
|
||||
string s = "";
|
||||
_IO.SW();
|
||||
if (_IO.PCUTF8() == '-') s += _IO.RCUTF8();
|
||||
if (_IO.PCUTF8() == '0') s += _IO.RCUTF8();
|
||||
else s += ReadDigits ();
|
||||
if (_IO.PCUTF8() == '.') s += _IO.RCUTF8() + ReadDigits();
|
||||
else
|
||||
bool negative = false;
|
||||
if (_IO.PCUTF8() == '-') { _IO.RCUTF8(); negative = true; }
|
||||
if (_IO.PCUTF8() == '0') s += _IO.RCUTF8();
|
||||
else s += RD ();
|
||||
char c = _IO.PCUTF8();
|
||||
if (c == '.') s += _IO.RCUTF8() + RD();
|
||||
else if (negative && s == "0")
|
||||
return (float)-0.0f;
|
||||
else if (c != 'e' && c != 'E')
|
||||
{
|
||||
long val = long.Parse(s);
|
||||
if (negative) s = "-" + s;
|
||||
long val;
|
||||
try { val = long.Parse(s); }
|
||||
catch { return ulong.Parse(s); }
|
||||
if (val >= 0x00000000 && val < 0x000000100) return ( byte)val;
|
||||
else if (val >= -0x00000080 && val < 0x000000080) return ( sbyte)val;
|
||||
else if (val >= -0x00008000 && val < 0x000008000) return ( short)val;
|
||||
@@ -148,19 +156,22 @@ namespace KKdMainLib.IO
|
||||
else return val;
|
||||
}
|
||||
|
||||
char c = _IO.PCUTF8();
|
||||
c = _IO.PCUTF8();
|
||||
if (c == 'e' || c == 'E')
|
||||
{
|
||||
{
|
||||
s += _IO.RCUTF8();
|
||||
c = _IO.PCUTF8();
|
||||
if (c == '+' || c == '-') s += _IO.RCUTF8();
|
||||
s += ReadDigits();
|
||||
}
|
||||
s += RD();
|
||||
}
|
||||
double d = s.ToF64();
|
||||
return (float)d == d ? (float)d : d;
|
||||
if ((float)d == d)
|
||||
return negative ? (((float)d).ToU32() | 0x80000000).ToF32() : (float)d;
|
||||
else
|
||||
return negative ? (d.ToU64() | 0x8000000000000000).ToF64() : d;
|
||||
}
|
||||
|
||||
private bool RBo()
|
||||
private bool RBo()
|
||||
{
|
||||
char c = _IO.PCUTF8();
|
||||
if (c == 't' && _IO.As( "true")) return true;
|
||||
@@ -168,24 +179,25 @@ namespace KKdMainLib.IO
|
||||
return false;
|
||||
}
|
||||
|
||||
private object RN() { _IO.As("null"); return null; }
|
||||
private object RN() { _IO.As("null"); return null; }
|
||||
|
||||
private string ReadDigits()
|
||||
private string RD()
|
||||
{ string s = ""; while (char.IsDigit(_IO.SW().
|
||||
PCUTF8())) s += _IO.RCUTF8(); return s; }
|
||||
|
||||
public JSON W(MsgPack msgPack, string end = "\n", string tabChar = " ") =>
|
||||
W(msgPack, end, tabChar, "", true);
|
||||
public JSON W(MsgPack msgPack, bool ignoreNull, string end = "\n", string tabChar = " ") =>
|
||||
W(msgPack, ignoreNull, end, tabChar, "", true);
|
||||
|
||||
public JSON W(MsgPack msgPack, bool style = false) =>
|
||||
W(msgPack, "\n", " ", "", style);
|
||||
public JSON W(MsgPack msgPack, bool ignoreNull, bool style = false) =>
|
||||
W(msgPack, ignoreNull, "\n", " ", "", style);
|
||||
|
||||
private JSON W(MsgPack msgPack, string end, string tabChar, string tab, bool style, bool isArray = false)
|
||||
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) { WN(); return this; }
|
||||
if (msgPack.Name != null && !isArray ) _IO.W("\"" + msgPack.Name + "\":" + (style ? " " : ""));
|
||||
if (msgPack.Object == null) { if (!ignoreNull) WN(); return this; }
|
||||
|
||||
if (msgPack.List.NotNull)
|
||||
{
|
||||
@@ -195,14 +207,14 @@ namespace KKdMainLib.IO
|
||||
for (int i = 0; i < msgPack.List.Count; i++)
|
||||
{
|
||||
if (style) _IO.W(tab);
|
||||
W(msgPack.List[i], end, tabChar, tab, style);
|
||||
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], end, tabChar, tab, style);
|
||||
W(msgPack.List[0], ignoreNull, end, tabChar, tab, style);
|
||||
if (style) _IO.W(end);
|
||||
}
|
||||
if (style) _IO.W(oldTab);
|
||||
@@ -216,20 +228,20 @@ namespace KKdMainLib.IO
|
||||
for (int i = 0; i < msgPack.Array.Length; i++)
|
||||
{
|
||||
if (style) _IO.W(tab);
|
||||
W(msgPack.Array[i], end, tabChar, tab, style, true);
|
||||
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], end, tabChar, tab, style, true);
|
||||
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, end, tabChar, tab, style);
|
||||
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));
|
||||
|
||||
|
||||
+45
-43
@@ -1,4 +1,4 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
@@ -96,7 +96,7 @@ namespace KKdMainLib.IO
|
||||
msgPack.Object = _IO.RBy(Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private bool RS(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
string val = RS(type);
|
||||
@@ -153,7 +153,7 @@ namespace KKdMainLib.IO
|
||||
private bool RE(ref MsgPack MsgPack, ref Types type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (type == Types.FixExt1 ) Length = 1 ;
|
||||
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 ;
|
||||
@@ -165,24 +165,24 @@ namespace KKdMainLib.IO
|
||||
MsgPack.Object = new MsgPack.Ext { Type = _IO.RI8(), Data = _IO.RBy(Length) };
|
||||
return true;
|
||||
}
|
||||
|
||||
public MP W(MsgPack msgPack, bool IsArray = false)
|
||||
|
||||
public MP W(MsgPack msgPack, bool ignoreNull, bool IsArray = false)
|
||||
{
|
||||
if (msgPack.Name != null && !IsArray) W(msgPack.Name);
|
||||
Write(msgPack.Object);
|
||||
Write(msgPack.Object, ignoreNull);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void Write(object obj)
|
||||
private void Write(object obj, bool ignoreNull)
|
||||
{
|
||||
if (obj == null) { WN(); return; }
|
||||
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]); break;
|
||||
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]); break;
|
||||
case MsgPack val: W(val); break;
|
||||
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;
|
||||
@@ -196,32 +196,32 @@ namespace KKdMainLib.IO
|
||||
case float val: W(val); break;
|
||||
case double val: W(val); break;
|
||||
case string val: W(val); break;
|
||||
case MsgPack.Ext val: WE(val); break;
|
||||
case MsgPack.Ext val: W(val); break;
|
||||
}
|
||||
}
|
||||
|
||||
private void W( sbyte val) { if (val < -0x20) _IO.W(0xD0); _IO.W(val); }
|
||||
private void W( byte val) { if (val >= 0x80) _IO.W(0xCC); _IO.W(val); }
|
||||
private void W( 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(0xD1); _IO.WE(val, true); } }
|
||||
else { _IO.W((byte)0xD1); _IO.WE(val, true); } }
|
||||
private void W(ushort val) { if (( byte)val == val) W(( byte)val);
|
||||
else { _IO.W(0xCD); _IO.WE(val, true); } }
|
||||
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(0xD2); _IO.WE(val, true); } }
|
||||
else { _IO.W((byte)0xD2); _IO.WE(val, true); } }
|
||||
private void W( uint val) { if ((ushort)val == val) W((ushort)val);
|
||||
else { _IO.W(0xCE); _IO.WE(val, true); } }
|
||||
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(0xD3); _IO.WE(val, true); } }
|
||||
else { _IO.W((byte)0xD3); _IO.WE(val, true); } }
|
||||
private void W( ulong val) { if (( uint)val == val) W(( uint)val);
|
||||
else { _IO.W(0xCF); _IO.WE(val, true); } }
|
||||
else { _IO.W((byte)0xCF); _IO.WE(val, true); } }
|
||||
private void W( float val) { if (( long)val == val) W(( long)val);
|
||||
else { _IO.W(0xCA); _IO.WE(val, true); } }
|
||||
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(0xCB); _IO.WE(val, true); } }
|
||||
else { _IO.W((byte)0xCB); _IO.WE(val, true); } }
|
||||
|
||||
private void W( bool val) =>
|
||||
_IO.W((byte)(val ? 0xC3 : 0xC2));
|
||||
@@ -230,60 +230,62 @@ namespace KKdMainLib.IO
|
||||
{
|
||||
if (val == null) { WN(); return; }
|
||||
|
||||
if (val.Length < 0x100) { _IO.W(0xC4); _IO.W (( byte)val.Length ); }
|
||||
else if (val.Length < 0x10000) { _IO.W(0xC5); _IO.WE((ushort)val.Length, true); }
|
||||
else { _IO.W(0xC6); _IO.WE( val.Length, true); }
|
||||
if (val.Length < 0x100) { _IO.W((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(0xD9); _IO.W (( byte)array.Length); }
|
||||
else if (array.Length < 0x10000) { _IO.W(0xDA); _IO.WE((ushort)array.Length, true); }
|
||||
else { _IO.W(0xDB); _IO.WE( array.Length, true); }
|
||||
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(0xC0);
|
||||
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(0xDC); _IO.WE((ushort)val, true); }
|
||||
else { _IO.W(0xDD); _IO.WE( val, true); }
|
||||
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(0xDE); _IO.WE((ushort)val, true); }
|
||||
else { _IO.W(0xDF); _IO.WE( val, true); }
|
||||
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(0xD4);
|
||||
else if (val.Data.Length == 2 ) _IO.W(0xD5);
|
||||
else if (val.Data.Length == 4 ) _IO.W(0xD6);
|
||||
else if (val.Data.Length == 8 ) _IO.W(0xD7);
|
||||
else if (val.Data.Length == 16) _IO.W(0xD8);
|
||||
else if (val.Data.Length == 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(0xC7); _IO.W (( byte)val.Data.Length); }
|
||||
{ _IO.W((byte)0xC7); _IO.W (( byte)val.Data.Length); }
|
||||
else if (val.Data.Length < 0x10000)
|
||||
{ _IO.W(0xC8); _IO.WE((ushort)val.Data.Length, true); }
|
||||
{ _IO.W((byte)0xC8); _IO.WE((ushort)val.Data.Length, true); }
|
||||
else
|
||||
{ _IO.W(0xC9); _IO.WE( val.Data.Length, true); }
|
||||
{ _IO.W((byte)0xC9); _IO.WE( val.Data.Length, true); }
|
||||
}
|
||||
_IO.W(val.Type);
|
||||
_IO.W(val.Data);
|
||||
|
||||
+61
-15
@@ -1,26 +1,72 @@
|
||||
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) =>
|
||||
MSIO.Path.GetDirectoryName(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;
|
||||
}
|
||||
}
|
||||
|
||||
+295
-226
@@ -1,25 +1,26 @@
|
||||
using System;
|
||||
using System;
|
||||
using KKdBaseLib;
|
||||
using MSIO = System.IO;
|
||||
using ENRSDict = System.Collections.Generic.Dictionary<long, int>;
|
||||
using ENRSDict = System.Collections.Generic.Dictionary<long, byte>;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public unsafe class Stream : IDisposable
|
||||
{
|
||||
private int I, i, BitRead, BitWrite, TempBitRead, TempBitWrite, ValRead, ValWrite;
|
||||
private int i, j, bitRead, bitWrite, tempBitRead, tempBitWrite, valRead, valWrite;
|
||||
private byte[] b;
|
||||
private MSIO.Stream s;
|
||||
|
||||
private readonly bool canRead;
|
||||
private readonly bool canWrite;
|
||||
|
||||
private bool getENRS;
|
||||
|
||||
private Format format = Format.NULL;
|
||||
|
||||
public Format Format
|
||||
{ get => format;
|
||||
set { format = value;
|
||||
IsBE = format == Format.F2BE;
|
||||
IsX = format == Format.X || format == Format.XHD; } }
|
||||
{ get => format;
|
||||
set { format = value; IsX = format == Format.X || format == Format.XHD; } }
|
||||
|
||||
public ENRSDict ENRSDict;
|
||||
|
||||
@@ -30,38 +31,37 @@ namespace KKdMainLib.IO
|
||||
set { if (value && ENRSDict == null)
|
||||
ENRSDict = new ENRSDict(); getENRS = value; } }
|
||||
|
||||
public int O { get => ( int)I64O; set => I64O = value; }
|
||||
public uint U32O { get => (uint)I64O; set => I64O = value; }
|
||||
public long I64O;
|
||||
public int O { get => ( int)OI64; set => OI64 = value; }
|
||||
public uint OU32 { get => (uint)OI64; set => OI64 = value; }
|
||||
public long OI64;
|
||||
|
||||
public int L { get => ( int)s.Length - O; set => s.SetLength(value + O); }
|
||||
public uint U32L { get => (uint)s.Length - U32O; set => s.SetLength(value + U32O); }
|
||||
public long I64L { get => s.Length - I64O; set => s.SetLength(value + I64O); }
|
||||
public int L { get => ( int)s.Length - O; set => s.SetLength(value + O ); }
|
||||
public uint LU32 { get => (uint)s.Length - OU32; set => s.SetLength(value + OU32); }
|
||||
public long LI64 { get => s.Length - OI64; set => s.SetLength(value + OI64); }
|
||||
|
||||
public int P
|
||||
{ get => ( int)s.Position - O; set => s.Position = value + O; }
|
||||
public uint U32P
|
||||
{ get => (uint)s.Position - U32O; set => s.Position = value + U32O; }
|
||||
public long I64P
|
||||
{ get => s.Position - I64O; set => s.Position = value + I64O; }
|
||||
public int P { get => ( int)s.Position - O; set => s.Position = value + O ; }
|
||||
public uint PU32 { get => (uint)s.Position - OU32; set => s.Position = value + OU32; }
|
||||
public long PI64 { get => s.Position - OI64; set => s.Position = value + OI64; }
|
||||
|
||||
public bool CanRead => s.CanRead;
|
||||
public bool CanRead => canRead ;
|
||||
public bool CanSeek => s.CanSeek;
|
||||
public bool CanTimeout => s.CanTimeout;
|
||||
public bool CanWrite => s.CanWrite;
|
||||
public bool CanWrite => s.CanWrite && canWrite;
|
||||
|
||||
public string File = null;
|
||||
|
||||
public Stream(MSIO.Stream output = 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;
|
||||
I64O = 0;
|
||||
BitRead = 8;
|
||||
ValRead = ValRead = BitWrite = 0;
|
||||
OI64 = 0;
|
||||
bitRead = 8;
|
||||
valRead = valRead = bitWrite = 0;
|
||||
s = output;
|
||||
Format = Format.NULL;
|
||||
b = new byte[0x100];
|
||||
this.IsBE = isBE;
|
||||
IsBE = isBE;
|
||||
this.canRead = s.CanRead && canRead;
|
||||
this.canWrite = s.CanWrite && canWrite;
|
||||
}
|
||||
|
||||
public void C() => D(true);
|
||||
@@ -72,7 +72,7 @@ namespace KKdMainLib.IO
|
||||
|
||||
public long S(long offset, SeekOrigin origin = 0) =>
|
||||
s.Seek(offset + O, (MSIO.SeekOrigin)(int)origin);
|
||||
|
||||
|
||||
public long? S(long? offset, SeekOrigin origin)
|
||||
{ if (offset == null) return null;
|
||||
return s.Seek((long)offset + O, (MSIO.SeekOrigin)(int)origin); }
|
||||
@@ -95,12 +95,12 @@ namespace KKdMainLib.IO
|
||||
if (P % align != 0) s.Seek(P + O + Al, 0);
|
||||
}
|
||||
|
||||
public void A(long align, bool SetLength)
|
||||
public void A(long align, bool setLength)
|
||||
{
|
||||
if (SetLength) s.SetLength(P + O);
|
||||
if (setLength) s.SetLength(P + O);
|
||||
long Al = align - P % align;
|
||||
if (P % align != 0) s.Seek(P + O + Al, 0);
|
||||
if (SetLength) s.SetLength(P + O);
|
||||
if (setLength) s.SetLength(P + O);
|
||||
}
|
||||
|
||||
public void A(long align, bool setLength0, bool setLength1)
|
||||
@@ -111,56 +111,59 @@ namespace KKdMainLib.IO
|
||||
if (setLength1) s.SetLength(P + O);
|
||||
}
|
||||
|
||||
public bool RBo () => s.ReadByte() != 0;
|
||||
public sbyte RI8 () => (sbyte)s.ReadByte();
|
||||
public byte RU8 () => ( byte)s.ReadByte();
|
||||
public short RI16() { s.Read(b, 0, 2); return b.TI16(); }
|
||||
public ushort RU16() { s.Read(b, 0, 2); return b.TU16(); }
|
||||
public int RI32() { s.Read(b, 0, 4); return b.TI32(); }
|
||||
public uint RU32() { s.Read(b, 0, 4); return b.TU32(); }
|
||||
public long RI64() { s.Read(b, 0, 8); return b.TI64(); }
|
||||
public ulong RU64() { s.Read(b, 0, 8); return b.TU64(); }
|
||||
public float RF32() { s.Read(b, 0, 4); return b.TF32(); }
|
||||
public double RF64() { s.Read(b, 0, 8); return b.TF64(); }
|
||||
|
||||
public short RI16E() { s.Read(b, 0, 2); b.E(2, IsBE); return b.TI16(); }
|
||||
public ushort RU16E() { s.Read(b, 0, 2); b.E(2, IsBE); return b.TU16(); }
|
||||
public int RI32E() { s.Read(b, 0, 4); b.E(4, IsBE); return b.TI32(); }
|
||||
public uint RU32E() { s.Read(b, 0, 4); b.E(4, IsBE); return b.TU32(); }
|
||||
public long RI64E() { s.Read(b, 0, 8); b.E(8, IsBE); return b.TI64(); }
|
||||
public ulong RU64E() { s.Read(b, 0, 8); b.E(8, IsBE); return b.TU64(); }
|
||||
public float RF32E() { s.Read(b, 0, 4); b.E(4, IsBE); return b.TF32(); }
|
||||
public double RF64E() { s.Read(b, 0, 8); b.E(8, IsBE); return b.TF64(); }
|
||||
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 RI16E(bool isBE) { s.Read(b, 0, 2); b.E(2, isBE); return b.TI16(); }
|
||||
public ushort RU16E(bool isBE) { s.Read(b, 0, 2); b.E(2, isBE); return b.TU16(); }
|
||||
public int RI32E(bool isBE) { s.Read(b, 0, 4); b.E(4, isBE); return b.TI32(); }
|
||||
public uint RU32E(bool isBE) { s.Read(b, 0, 4); b.E(4, isBE); return b.TU32(); }
|
||||
public long RI64E(bool isBE) { s.Read(b, 0, 8); b.E(8, isBE); return b.TI64(); }
|
||||
public ulong RU64E(bool isBE) { s.Read(b, 0, 8); b.E(8, isBE); return b.TU64(); }
|
||||
public float RF32E(bool isBE) { s.Read(b, 0, 4); b.E(4, isBE); return b.TF32(); }
|
||||
public double RF64E(bool isBE) { s.Read(b, 0, 8); b.E(8, isBE); return b.TF64(); }
|
||||
public 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 W(byte[] Val ) =>
|
||||
s.Write(Val ?? new byte[0], 0, Val.Length);
|
||||
public void W(byte[] Val, int Length) =>
|
||||
s.Write(Val ?? new byte[0], 0, Length);
|
||||
public void W(byte[] Val, int Offset, int Length) =>
|
||||
s.Write(Val ?? new byte[0], Offset, Length);
|
||||
public void W(char[] val, bool UTF8 = true) =>
|
||||
W(UTF8 ? val.ToUTF8() : val.ToASCII());
|
||||
public 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 W( bool val) => s.WriteByte((byte)(val ? 1 : 0));
|
||||
public void W( sbyte val) => s.WriteByte((byte) val);
|
||||
public void W( byte val) => s.WriteByte( val);
|
||||
public void W( short val) { b.GBy(val); s.Write(b, 0, 2); }
|
||||
public void W(ushort val) { b.GBy(val); s.Write(b, 0, 2); }
|
||||
public void W( int val) { b.GBy(val); s.Write(b, 0, 4); }
|
||||
public void W( uint val) { b.GBy(val); s.Write(b, 0, 4); }
|
||||
public void W( long val) { b.GBy(val); s.Write(b, 0, 8); }
|
||||
public void W( ulong val) { b.GBy(val); s.Write(b, 0, 8); }
|
||||
public void W( float val) { b.GBy(val); s.Write(b, 0, 4); }
|
||||
public void W(double val) { b.GBy(val); s.Write(b, 0, 8); }
|
||||
public 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 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 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 W( sbyte? val) => W(val ?? default);
|
||||
public void W( byte? val) => W(val ?? default);
|
||||
@@ -173,198 +176,264 @@ namespace KKdMainLib.IO
|
||||
public void W( float? val) => W(val ?? default);
|
||||
public void W(double? val) => W(val ?? default);
|
||||
|
||||
public void W( char val, bool UTF8 = true) =>
|
||||
W(UTF8 ? val.ToString().ToUTF8() : val.ToString().ToASCII());
|
||||
public void W(string val, bool UTF8 = true) =>
|
||||
W(UTF8 ? val .ToUTF8() : val .ToASCII());
|
||||
|
||||
public void WE( short val) { b.GBy(val); b.E(2, IsBE); s.Write(b, 0, 2); }
|
||||
public void WE(ushort val) { b.GBy(val); b.E(2, IsBE); s.Write(b, 0, 2); }
|
||||
public void WE( int val) { b.GBy(val); b.E(4, IsBE); s.Write(b, 0, 4); }
|
||||
public void WE( uint val) { b.GBy(val); b.E(4, IsBE); s.Write(b, 0, 4); }
|
||||
public void WE( long val) { b.GBy(val); b.E(8, IsBE); s.Write(b, 0, 8); }
|
||||
public void WE( ulong val) { b.GBy(val); b.E(8, IsBE); s.Write(b, 0, 8); }
|
||||
public void WE( float val) { b.GBy(val); b.E(4, IsBE); s.Write(b, 0, 4); }
|
||||
public void WE(double val) { b.GBy(val); b.E(8, IsBE); s.Write(b, 0, 8); }
|
||||
public void W( char val, bool utf8 = true) =>
|
||||
W(utf8 ? val.ToString().ToUTF8() : val.ToString().ToASCII());
|
||||
public void W(string val, bool utf8 = true) =>
|
||||
W(utf8 ? val .ToUTF8() : val .ToASCII());
|
||||
|
||||
public void WE( short val, bool isBE) { b.GBy(val); b.E(2, isBE); s.Write(b, 0, 2); }
|
||||
public void WE(ushort val, bool isBE) { b.GBy(val); b.E(2, isBE); s.Write(b, 0, 2); }
|
||||
public void WE( int val, bool isBE) { b.GBy(val); b.E(4, isBE); s.Write(b, 0, 4); }
|
||||
public void WE( uint val, bool isBE) { b.GBy(val); b.E(4, isBE); s.Write(b, 0, 4); }
|
||||
public void WE( long val, bool isBE) { b.GBy(val); b.E(8, isBE); s.Write(b, 0, 8); }
|
||||
public void WE( ulong val, bool isBE) { b.GBy(val); b.E(8, isBE); s.Write(b, 0, 8); }
|
||||
public void WE( float val, bool isBE) { b.GBy(val); b.E(4, isBE); s.Write(b, 0, 4); }
|
||||
public void WE(double val, bool isBE) { b.GBy(val); b.E(8, isBE); s.Write(b, 0, 8); }
|
||||
public 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); }
|
||||
|
||||
private void RENRS(byte[] b, int c)
|
||||
{ if (getENRS) ENRSDict.Add(P, c); s.Read(b, 0, c); }
|
||||
|
||||
public short RI16ENRS() { RENRS(b, 2); return b.TI16(); }
|
||||
public ushort RU16ENRS() { RENRS(b, 2); return b.TU16(); }
|
||||
public int RI32ENRS() { RENRS(b, 4); return b.TI32(); }
|
||||
public uint RU32ENRS() { RENRS(b, 4); return b.TU32(); }
|
||||
public long RI64ENRS() { RENRS(b, 8); return b.TI64(); }
|
||||
public ulong RU64ENRS() { RENRS(b, 8); return b.TU64(); }
|
||||
public float RF32ENRS() { RENRS(b, 4); return b.TF32(); }
|
||||
public double RF64ENRS() { RENRS(b, 8); return b.TF64(); }
|
||||
|
||||
public short RI16ENRSE() { RENRS(b, 2); b.E(2, IsBE); return b.TI16(); }
|
||||
public ushort RU16ENRSE() { RENRS(b, 2); b.E(2, IsBE); return b.TU16(); }
|
||||
public int RI32ENRSE() { RENRS(b, 4); b.E(4, IsBE); return b.TI32(); }
|
||||
public uint RU32ENRSE() { RENRS(b, 4); b.E(4, IsBE); return b.TU32(); }
|
||||
public long RI64ENRSE() { RENRS(b, 8); b.E(8, IsBE); return b.TI64(); }
|
||||
public ulong RU64ENRSE() { RENRS(b, 8); b.E(8, IsBE); return b.TU64(); }
|
||||
public float RF32ENRSE() { RENRS(b, 4); b.E(4, IsBE); return b.TF32(); }
|
||||
public double RF64ENRSE() { RENRS(b, 8); b.E(8, IsBE); return b.TF64(); }
|
||||
|
||||
public short RI16ENRSE(bool isBE) { RENRS(b, 2); b.E(2, isBE); return b.TI16(); }
|
||||
public ushort RU16ENRSE(bool isBE) { RENRS(b, 2); b.E(2, isBE); return b.TU16(); }
|
||||
public int RI32ENRSE(bool isBE) { RENRS(b, 4); b.E(4, isBE); return b.TI32(); }
|
||||
public uint RU32ENRSE(bool isBE) { RENRS(b, 4); b.E(4, isBE); return b.TU32(); }
|
||||
public long RI64ENRSE(bool isBE) { RENRS(b, 8); b.E(8, isBE); return b.TI64(); }
|
||||
public ulong RU64ENRSE(bool isBE) { RENRS(b, 8); b.E(8, isBE); return b.TU64(); }
|
||||
public float RF32ENRSE(bool isBE) { RENRS(b, 4); b.E(4, isBE); return b.TF32(); }
|
||||
public double RF64ENRSE(bool isBE) { RENRS(b, 8); b.E(8, isBE); return b.TF64(); }
|
||||
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 WENRS(byte[] b, int c)
|
||||
{ if (getENRS) ENRSDict.Add(P, c); s.Write(b, 0, c); }
|
||||
private void RENRS(byte c)
|
||||
{ cR(); if (getENRS) ENRSDict.Add(P, c); s.Read(b, 0, c); }
|
||||
|
||||
public void WENRS( short val) { b.GBy(val); WENRS(b, 2); }
|
||||
public void WENRS(ushort val) { b.GBy(val); WENRS(b, 2); }
|
||||
public void WENRS( int val) { b.GBy(val); WENRS(b, 4); }
|
||||
public void WENRS( uint val) { b.GBy(val); WENRS(b, 4); }
|
||||
public void WENRS( long val) { b.GBy(val); WENRS(b, 8); }
|
||||
public void WENRS( ulong val) { b.GBy(val); WENRS(b, 8); }
|
||||
public void WENRS( float val) { b.GBy(val); WENRS(b, 4); }
|
||||
public void WENRS(double val) { b.GBy(val); WENRS(b, 8); }
|
||||
|
||||
public void WENRSE( short val) { b.GBy(val); b.E(2, IsBE); WENRS(b, 2); }
|
||||
public void WENRSE(ushort val) { b.GBy(val); b.E(2, IsBE); WENRS(b, 2); }
|
||||
public void WENRSE( int val) { b.GBy(val); b.E(4, IsBE); WENRS(b, 4); }
|
||||
public void WENRSE( uint val) { b.GBy(val); b.E(4, IsBE); WENRS(b, 4); }
|
||||
public void WENRSE( long val) { b.GBy(val); b.E(8, IsBE); WENRS(b, 8); }
|
||||
public void WENRSE( ulong val) { b.GBy(val); b.E(8, IsBE); WENRS(b, 8); }
|
||||
public void WENRSE( float val) { b.GBy(val); b.E(4, IsBE); WENRS(b, 4); }
|
||||
public void WENRSE(double val) { b.GBy(val); b.E(8, IsBE); WENRS(b, 8); }
|
||||
|
||||
public void WENRSE( short val, bool isBE) { b.GBy(val); b.E(2, isBE); WENRS(b, 2); }
|
||||
public void WENRSE(ushort val, bool isBE) { b.GBy(val); b.E(2, isBE); WENRS(b, 2); }
|
||||
public void WENRSE( int val, bool isBE) { b.GBy(val); b.E(4, isBE); WENRS(b, 4); }
|
||||
public void WENRSE( uint val, bool isBE) { b.GBy(val); b.E(4, isBE); WENRS(b, 4); }
|
||||
public void WENRSE( long val, bool isBE) { b.GBy(val); b.E(8, isBE); WENRS(b, 8); }
|
||||
public void WENRSE( ulong val, bool isBE) { b.GBy(val); b.E(8, isBE); WENRS(b, 8); }
|
||||
public void WENRSE( float val, bool isBE) { b.GBy(val); b.E(4, isBE); WENRS(b, 4); }
|
||||
public void WENRSE(double val, bool isBE) { b.GBy(val); b.E(8, isBE); WENRS(b, 8); }
|
||||
public 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(); }
|
||||
|
||||
public Half RF16 ( ) { ushort a = RU16 ( ); return (Half)a; }
|
||||
public Half RF16E ( ) { ushort a = RU16E ( ); return (Half)a; }
|
||||
public Half RF16E (bool isBE) { ushort a = RU16E (isBE); return (Half)a; }
|
||||
public Half RF16ENRS ( ) { ushort a = RU16E ( ); return (Half)a; }
|
||||
public Half RF16ENRSE( ) { ushort a = RU16ENRSE( ); return (Half)a; }
|
||||
public Half RF16ENRSE(bool isBE) { ushort a = RU16ENRSE(isBE); return (Half)a; }
|
||||
public 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(); }
|
||||
|
||||
public void W (Half val ) => W ((ushort)val );
|
||||
public void WE (Half val ) => WE ((ushort)val );
|
||||
public void WE (Half val, bool isBE) => WE ((ushort)val, isBE);
|
||||
public void WENRS (Half val ) => WENRS ((ushort)val );
|
||||
public void WENRSE(Half val ) => WENRSE((ushort)val );
|
||||
public void WENRSE(Half val, bool isBE) => WENRSE((ushort)val, isBE);
|
||||
|
||||
public char RC(bool UTF8 = true) => UTF8 ? RCUTF8() : (char)s.ReadByte();
|
||||
public 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 WENRS(byte c)
|
||||
{ if (getENRS) ENRSDict.Add(P, c); cW(); s.Write(b, 0, c); }
|
||||
|
||||
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, i = 4; I < i; I++)
|
||||
for (j = 0, i = 4; j < i; j++)
|
||||
{
|
||||
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; i = 2; }
|
||||
else if ((t & 0xF0) == 0xE0 && I == 0) { val = t & 0x0F; i = 3; }
|
||||
else if ((t & 0xF8) == 0xF0 && I == 0) { val = t & 0x07; i = 4; }
|
||||
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 RS(long Length, bool UTF8 = true) =>
|
||||
UTF8 ? RSUTF8(Length) : RSASCII(Length);
|
||||
public string RS(long Length, bool utf8 = true)
|
||||
{ cR(); return utf8 ? RSUTF8(Length) : RSASCII(Length);}
|
||||
|
||||
public string RSUTF8 (long Length) => RBy(Length).ToUTF8 ();
|
||||
public string RSASCII(long Length) => RBy(Length).ToASCII();
|
||||
|
||||
|
||||
public string RS(long? Length, bool UTF8 = true) =>
|
||||
UTF8 ? RSUTF8(Length) : RSASCII(Length);
|
||||
public string RSUTF8 (long length) { cR(); return RBy(length).ToUTF8 (); }
|
||||
public string RSASCII(long length) { cR(); return RBy(length).ToASCII(); }
|
||||
|
||||
public string RSUTF8 (long? Length) => RBy(Length).ToUTF8 ();
|
||||
public string RSASCII(long? Length) => RBy(Length).ToASCII();
|
||||
|
||||
public byte[] RBy(long Length, int Offset = -1)
|
||||
{ byte[] Buf = new byte[Length]; if (Offset > -1) s.Position = Offset;
|
||||
s.Read(Buf, 0, (int)Length); return Buf; }
|
||||
|
||||
public void RBy(long Length, byte[] Buf, long Offset = -1)
|
||||
{ if (Offset > -1) s.Position = Offset; s.Read(Buf, 0, (int)Length); }
|
||||
public string RS(long? length, bool utf8 = true)
|
||||
{ cR(); return utf8? RSUTF8(length) : RSASCII(length); }
|
||||
|
||||
public byte[] RBy(long? Length, int Offset = -1)
|
||||
{ if (Length == null) return new byte[0]; else return RBy((long)Length, Offset); }
|
||||
public string RSUTF8 (long? length) { cR(); return RBy(length).ToUTF8 (); }
|
||||
public string RSASCII(long? length) { cR(); return RBy(length).ToASCII(); }
|
||||
|
||||
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)
|
||||
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)s.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 RHB() => RBi(4);
|
||||
|
||||
public void W(int val, byte Bits)
|
||||
|
||||
public void W(int val, byte bits)
|
||||
{
|
||||
val &= (1 << Bits) - 1;
|
||||
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;
|
||||
s.WriteByte((byte)(ValWrite | (val >> BitWrite)));
|
||||
ValWrite = 0;
|
||||
bitWrite = (byte)-tempBitWrite;
|
||||
tempBitWrite = 8 + tempBitWrite;
|
||||
s.WriteByte((byte)(valWrite | (val >> bitWrite)));
|
||||
valWrite = 0;
|
||||
}
|
||||
ValWrite |= val << TempBitWrite;
|
||||
ValWrite &= 0xFF;
|
||||
valWrite |= val << tempBitWrite;
|
||||
valWrite &= 0xFF;
|
||||
}
|
||||
|
||||
public void CR() //CheckRead
|
||||
{ if (BitRead > 0) ValRead = 0; BitRead = 8; }
|
||||
{ if (bitRead > 0) valRead = 0; bitRead = 8; }
|
||||
public void CW() //CheckWrite
|
||||
{ if (BitWrite > 0) { s.WriteByte((byte)ValWrite); ValWrite = 0; BitWrite = 0; } }
|
||||
{ if (bitWrite > 0) { cW(); s.WriteByte((byte)valWrite); valWrite = 0; bitWrite = 0; } }
|
||||
|
||||
public byte[] ToArray(bool Close)
|
||||
{ byte[] Data = ToArray(); if (Close) Dispose(); return Data; }
|
||||
public byte[] ToArray(bool close)
|
||||
{ byte[] data = ToArray(); if (close) Dispose(); return data; }
|
||||
|
||||
public byte[] ToArray()
|
||||
{
|
||||
long Position = s.Position;
|
||||
byte[] Data = RBy(s.Length, 0);
|
||||
s.Position = Position;
|
||||
return Data;
|
||||
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-2021</Copyright>
|
||||
<Description>A simple library for working with Project Diva AC/DT/F/AFT/F2/X/FT/M39 files</Description>
|
||||
<FileVersion>0.4.10.2</FileVersion>
|
||||
<PackageId>KKdMainLib</PackageId>
|
||||
<Product>KKdMainLib</Product>
|
||||
<TargetFramework>net461</TargetFramework>
|
||||
<Title>KKdMainLib</Title>
|
||||
<Version>0.4.10.2</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -23,7 +24,7 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
|
||||
<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>
|
||||
@@ -36,46 +37,22 @@
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
|
||||
<NoWarn>IDE0004, IDE0018, IDE0032, IDE0044, IDE0045, IDE0046, IDE0051, IDE0055, IDE0059, IDE0063, IDE0066, IDE0069, IDE1006</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DB\Aet.cs" />
|
||||
<Compile Include="DB\Auth.cs" />
|
||||
<Compile Include="DB\Spr.cs" />
|
||||
<Compile Include="F2\Bloom.cs" />
|
||||
<Compile Include="F2\ColorCorrection.cs" />
|
||||
<Compile Include="F2\DOF.cs" />
|
||||
<Compile Include="F2\Light.cs" />
|
||||
<Compile Include="IO\Directory.cs" />
|
||||
<Compile Include="IO\Extensions.cs" />
|
||||
<Compile Include="IO\File.cs" />
|
||||
<Compile Include="IO\JSON.cs" />
|
||||
<Compile Include="IO\MP.cs" />
|
||||
<Compile Include="IO\Path.cs" />
|
||||
<Compile Include="IO\Stream.cs" />
|
||||
<Compile Include="A3DA.cs" />
|
||||
<Compile Include="Aet.cs" />
|
||||
<Compile Include="DataBank.cs" />
|
||||
<Compile Include="DEX.cs" />
|
||||
<Compile Include="DIVAFILE.cs" />
|
||||
<Compile Include="Extensions.cs" />
|
||||
<Compile Include="FARC.cs" />
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="Mot.cs" />
|
||||
<Compile Include="STR.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<ProjectReference Include="..\KKdBaseLib\KKdBaseLib.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KKdBaseLib\KKdBaseLib.csproj">
|
||||
<Project>{437f63f1-8c23-429e-ab14-38b85c9edb16}</Project>
|
||||
<Name>KKdBaseLib</Name>
|
||||
</ProjectReference>
|
||||
<EmbeddedResource Update="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -1,199 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Globalization;
|
||||
using System.Collections.Generic;
|
||||
using KKdBaseLib;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public static unsafe class Main
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Dictionary<string, object> bufDict = new Dictionary<string, object>();
|
||||
if (dict == null) return false;
|
||||
else if (args.Length < 1) return false;
|
||||
|
||||
args[0] = args[0].ToLower();
|
||||
if (args.Length > 1)
|
||||
{
|
||||
string[] newArgs = new string[args.Length - 1];
|
||||
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) =>
|
||||
dict.FindValue(out string val, args.Split(split)) ? bool.TryParse(val, out value) : false;
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> dict,
|
||||
ref int value, char split, string args) =>
|
||||
dict.FindValue(out string val, args.Split(split)) ? int.TryParse(val, out value) : false;
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> dict,
|
||||
ref float value, char split, string args) =>
|
||||
dict.FindValue(out string val, args.Split(split)) ? val.ToF32( out value) : false;
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> dict,
|
||||
ref double value, char split, string args) =>
|
||||
dict.FindValue(out string val, args.Split(split)) ? val.ToF64( out value) : false;
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> Dict,
|
||||
ref 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 float value, string args)
|
||||
{ if (dict.FindValue(out string val, args.Split('.' )))
|
||||
return val.ToF32(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.ToF64(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 float? value, string args)
|
||||
{ if (dict.FindValue(out string val, args.Split('.' )))
|
||||
return val.ToF32(out value); value = null; return false; }
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> dict,
|
||||
out double? value, string args)
|
||||
{ if (dict.FindValue(out string val, args.Split('.' )))
|
||||
return val.ToF64(out value); value = null; return false; }
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> dict,
|
||||
out string value, string args)
|
||||
{ if (dict.FindValue(out string val, args.Split('.' )))
|
||||
{ value = val; return true; } value = null; return false; }
|
||||
|
||||
public static bool FindValue(this Dictionary<string, object> dict,
|
||||
out string value, string[] args)
|
||||
{
|
||||
value = "";
|
||||
if (dict == null) return false;
|
||||
else if (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 ((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>();
|
||||
else if (args.Length < 1) return;
|
||||
|
||||
args[0] = args[0].ToLower();
|
||||
if (args.Length > 1)
|
||||
{
|
||||
string[] newArgs = new string[args.Length - 1];
|
||||
for (int i = 0; i < args.Length - 1; i++) newArgs[i] = args[i + 1];
|
||||
if (!dict.ContainsKey(args[0])) dict.Add(args[0], null);
|
||||
if (dict[args[0]] != null)
|
||||
{
|
||||
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 TKey GetKey<TKey, TVal>(this Dictionary<TKey, TVal> dict, TVal val) =>
|
||||
dict.First((KeyValuePair<TKey, TVal> x) => x.Value.Equals(val)).Key;
|
||||
|
||||
public static string ToTitleCase(this string s)
|
||||
{ return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s); }
|
||||
|
||||
public static int[] SortWriter(this int length)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+147
-117
@@ -1,36 +1,38 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public struct Mot
|
||||
public struct Mot : System.IDisposable
|
||||
{
|
||||
private int i, i0, i1;
|
||||
public MotHeader[] MOT;
|
||||
private Stream _IO;
|
||||
private Stream s;
|
||||
|
||||
[System.ThreadStatic] public bool Modern;
|
||||
|
||||
public void MOTReader(string file)
|
||||
{
|
||||
_IO = File.OpenReader(file + ".bin");
|
||||
s = File.OpenReader(file + ".bin");
|
||||
|
||||
i = 0;
|
||||
while (true)
|
||||
if (_IO.RI64() == 0) break;
|
||||
else { _IO.RI64(); i++; }
|
||||
if (s.RI64() == 0) break;
|
||||
else { s.RI64(); i++; }
|
||||
if (i == 0) return;
|
||||
|
||||
_IO.P = 0;
|
||||
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 = _IO.RI32();
|
||||
mot.KeySetTypesOffset = _IO.RI32();
|
||||
mot. KeySetOffset = _IO.RI32();
|
||||
mot.BoneInfo .O = _IO.RI32();
|
||||
mot.KeySet .O = s.RI32();
|
||||
mot.KeySetTypesOffset = s.RI32();
|
||||
mot. KeySetOffset = s.RI32();
|
||||
mot.BoneInfo .O = s.RI32();
|
||||
}
|
||||
|
||||
for (i = 0; i < motCount; i++)
|
||||
@@ -38,128 +40,158 @@ namespace KKdMainLib
|
||||
ref MotHeader mot = ref MOT[i];
|
||||
|
||||
i0 = 1;
|
||||
_IO.P = mot.BoneInfo.O;
|
||||
_IO.RU16();
|
||||
while (_IO.RU16() != 0) i0++;
|
||||
s.P = mot.BoneInfo.O;
|
||||
s.RU16();
|
||||
while (s.P < s.L && s.RU16() != 0) i0++;
|
||||
|
||||
mot.BoneInfo.V = new BoneInfo[i0];
|
||||
_IO.P = mot.BoneInfo.O;
|
||||
mot.BoneInfo.V = new int[i0];
|
||||
s.P = mot.BoneInfo.O;
|
||||
for (i0 = 0; i0 < mot.BoneInfo.V.Length; i0++)
|
||||
mot.BoneInfo.V[i0].Id = _IO.RU16();
|
||||
mot.BoneInfo.V[i0] = s.RU16();
|
||||
|
||||
_IO.P = mot.KeySet.O;
|
||||
int info = _IO.RU16();
|
||||
s.P = mot.KeySet.O;
|
||||
int info = s.RU16();
|
||||
mot.HighBits = info >> 14;
|
||||
mot.FrameCount = _IO.RU16();
|
||||
mot.FrameCount = s.RU16();
|
||||
|
||||
mot.KeySet.V = new KeySet[info & 0x3FFF];
|
||||
_IO.P = mot.KeySetTypesOffset;
|
||||
s.P = mot.KeySetTypesOffset;
|
||||
for (i0 = 0; i0 < mot.KeySet.V.Length; i0++)
|
||||
{
|
||||
if (i0 % 8 == 0) i1 = _IO.RU16();
|
||||
|
||||
if (i0 % 8 == 0) i1 = s.RU16();
|
||||
mot.KeySet.V[i0] = new KeySet { Type = (KeySetType)((i1 >> (i0 % 8 * 2)) & 0b11) };
|
||||
}
|
||||
|
||||
_IO.P = mot.KeySetOffset;
|
||||
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 = _IO.RF32(); }
|
||||
else if (key.Type == KeySetType.Linear)
|
||||
key.Keys[0].V = s.RF32(); }
|
||||
else if (key.Type == KeySetType.Linear && !Modern)
|
||||
{
|
||||
key.Keys = new KFT2[_IO.RU16()];
|
||||
key.Keys = new KFT2[s.RU16()];
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
key.Keys[i1].F = _IO.RU16();
|
||||
_IO.A(0x4);
|
||||
key.Keys[i1].F = s.RU16();
|
||||
s.A(0x4);
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
key.Keys[i1].V = _IO.RF32();
|
||||
key.Keys[i1].V = s.RF32();
|
||||
}
|
||||
else if (key.Type == KeySetType.Interpolated)
|
||||
else if (key.Type == KeySetType.Tangent && !Modern)
|
||||
{
|
||||
key.Keys = new KFT2[_IO.RU16()];
|
||||
key.Keys = new KFT2[s.RU16()];
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
key.Keys[i1].F = _IO.RU16();
|
||||
_IO.A(0x4);
|
||||
key.Keys[i1].F = s.RU16();
|
||||
s.A(0x4);
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
{ key.Keys[i1].V = _IO.RF32(); key.Keys[i1].T = _IO.RF32(); }
|
||||
{ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
_IO.C();
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MOTWriter(string file)
|
||||
{
|
||||
if (MOT == null) return;
|
||||
_IO = File.OpenWriter(file + ".bin");
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
|
||||
int MOTCount = MOT.Length;
|
||||
_IO.P = (MOTCount + 1) << 4;
|
||||
s.P = (MOTCount + 1) << 4;
|
||||
for (i = 0; i < MOTCount; i++)
|
||||
{
|
||||
ref MotHeader mot = ref MOT[i];
|
||||
mot.KeySet.O = _IO.P;
|
||||
_IO.W((ushort)((mot.HighBits << 14) | (mot.KeySet.V.Length & 0x3FFF)));
|
||||
_IO.W((ushort)mot.FrameCount);
|
||||
mot.KeySet.O = s.P;
|
||||
s.W((ushort)((mot.HighBits << 14) | (mot.KeySet.V.Length & 0x3FFF)));
|
||||
s.W((ushort)mot.FrameCount);
|
||||
|
||||
mot.KeySetTypesOffset = _IO.P;
|
||||
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) { _IO.W((ushort)i1); i1 = 0; }
|
||||
if (i0 % 8 == 7) { s.W((ushort)i1); i1 = 0; }
|
||||
}
|
||||
_IO.W((ushort)i1);
|
||||
s.W((ushort)i1);
|
||||
if (s.P % 4 != 0) s.W((ushort)0x00);
|
||||
|
||||
_IO.A(0x4);
|
||||
mot.KeySetOffset = _IO.P;
|
||||
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)
|
||||
_IO.W(key.Keys[0].V);
|
||||
else if (key.Type == KeySetType.Linear)
|
||||
s.W(key.Keys[0].V);
|
||||
else if ((key.Type == KeySetType.Linear
|
||||
|| key.Type == KeySetType.Tangent) && !Modern)
|
||||
{
|
||||
_IO.W((ushort)key.Keys.Length);
|
||||
s.W((ushort)key.Keys.Length);
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
_IO.W(key.Keys[i1].F);
|
||||
_IO.A(0x4);
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
_IO.W(key.Keys[i1].V);
|
||||
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.Interpolated)
|
||||
else if (key.Type != KeySetType.None)
|
||||
{
|
||||
_IO.W((ushort)key.Keys.Length);
|
||||
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++)
|
||||
_IO.W(key.Keys[i1].F);
|
||||
_IO.A(0x4);
|
||||
s.W(key.Keys[i1].V);
|
||||
for (i1 = 0; i1 < key.Keys.Length; i1++)
|
||||
{ _IO.W(key.Keys[i1].V); _IO.W(key.Keys[i1].T); }
|
||||
s.W((ushort)key.Keys[i1].F);
|
||||
s.A(0x4);
|
||||
}
|
||||
}
|
||||
_IO.A(0x4);
|
||||
if (s.P % 4 != 0) s.W((ushort)0x00);
|
||||
|
||||
mot.BoneInfo.O = _IO.P;
|
||||
mot.BoneInfo.O = s.P;
|
||||
for (i0 = 0; i0 < mot.BoneInfo.V.Length; i0++)
|
||||
_IO.W((ushort)mot.BoneInfo.V[i0].Id);
|
||||
_IO.W((ushort)0);
|
||||
s.W((ushort)mot.BoneInfo.V[i0]);
|
||||
s.W((ushort)0);
|
||||
}
|
||||
_IO.A(0x4, true);
|
||||
if (s.P % 4 != 0) s.W((ushort)0x00);
|
||||
s.A(0x4, true);
|
||||
|
||||
_IO.P = 0;
|
||||
s.P = 0;
|
||||
for (i = 0; i < MOTCount; i++)
|
||||
{
|
||||
ref MotHeader mot = ref MOT[i];
|
||||
_IO.W(mot.KeySet .O );
|
||||
_IO.W(mot.KeySetTypesOffset);
|
||||
_IO.W(mot. KeySetOffset);
|
||||
_IO.W(mot.BoneInfo .O );
|
||||
s.W(mot.KeySet .O );
|
||||
s.W(mot.KeySetTypesOffset);
|
||||
s.W(mot. KeySetOffset);
|
||||
s.W(mot.BoneInfo .O );
|
||||
}
|
||||
|
||||
_IO.C();
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
@@ -184,7 +216,7 @@ namespace KKdMainLib
|
||||
MsgPack mot = new MsgPack(motCount, "MOT");
|
||||
for (i = 0; i < motCount; i++)
|
||||
mot[i] = MsgPackWriter(ref MOT[i]);
|
||||
mot.Write(true, file, json);
|
||||
mot.Write(false, true, file, json);
|
||||
}
|
||||
|
||||
public void MsgPackReader(MsgPack msgPack, ref MotHeader mot)
|
||||
@@ -210,14 +242,9 @@ namespace KKdMainLib
|
||||
else if (keySet.Type == KeySetType.Static)
|
||||
{
|
||||
keySet.Keys = new KFT2[1];
|
||||
if (temp1.Array == null) continue;
|
||||
else if (temp1.Array.Length == 0) continue;
|
||||
else if (temp1.Array[0].Array == null) continue;
|
||||
else if (temp1.Array[0].Array.Length == 0) continue;
|
||||
else if (temp1.Array[0].Array.Length == 1)
|
||||
keySet.Keys[0] = new KFT2 (temp1.Array[0][0].RF32());
|
||||
else if (temp1.Array[0].Array.Length > 1)
|
||||
keySet.Keys[0] = new KFT2 (temp1.Array[0][0].RF32(), temp1.Array[1].RF32());
|
||||
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)
|
||||
{
|
||||
@@ -228,12 +255,12 @@ namespace KKdMainLib
|
||||
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());
|
||||
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());
|
||||
keySet.Keys[i1] = new KFT2(array[0].RF32(), array[1].RF32());
|
||||
}
|
||||
}
|
||||
else if (keySet.Type == KeySetType.Interpolated)
|
||||
else if (keySet.Type == KeySetType.Tangent)
|
||||
{
|
||||
keySet.Keys = new KFT2[temp1.Array.Length];
|
||||
for (i1 = 0; i1 < temp1.Array.Length; i1++)
|
||||
@@ -242,21 +269,21 @@ namespace KKdMainLib
|
||||
if (array.Array == null ||
|
||||
array.Array.Length == 0) continue;
|
||||
else if (array.Array.Length == 1)
|
||||
keySet.Keys[i1] = new KFT2 (array[0].RF32());
|
||||
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());
|
||||
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(),
|
||||
keySet.Keys[i1] = new KFT2(array[0].RF32(),
|
||||
array[1].RF32(), temp1.Array[i1][2].RF32());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ((temp = msgPack["BoneInfo", true]).NotNull)
|
||||
{
|
||||
mot.BoneInfo.V = new BoneInfo[temp.Array.Length];
|
||||
mot.BoneInfo.V = new int[temp.Array.Length];
|
||||
for (i = 0; i < mot.BoneInfo.V.Length; i++)
|
||||
mot.BoneInfo.V[i].Id = temp[i].RI32();
|
||||
mot.BoneInfo.V[i] = temp[i].RI32();
|
||||
}
|
||||
temp.Dispose();
|
||||
}
|
||||
@@ -273,52 +300,60 @@ namespace KKdMainLib
|
||||
|
||||
keySets[i0] = new MsgPack(2);
|
||||
keySets[i0].Array[0] = (byte)keySet.Type;
|
||||
keySets[i0].Array[1] = new MsgPack(keySet.Keys.Length);
|
||||
if (keySet.Type == KeySetType.Static)
|
||||
{
|
||||
IKF kf = keySet.Keys[0].Check();
|
||||
if (kf is KFT0 KFT0) keySets[i0].Array[1][0] =
|
||||
new MsgPack(null, new MsgPack[] { KFT0.F });
|
||||
else if (kf is KFT1 KFT1) keySets[i0].Array[1][0] =
|
||||
new MsgPack(null, new MsgPack[] { KFT1.F, KFT1.V });
|
||||
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) keySets[i0].Array[1][i1] =
|
||||
new MsgPack(null, new MsgPack[] { KFT0.F });
|
||||
else if (kf is KFT1 KFT1) keySets[i0].Array[1][i1] =
|
||||
new MsgPack(null, new MsgPack[] { KFT1.F, KFT1.V });
|
||||
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) keySets[i0].Array[1][i1] =
|
||||
new MsgPack(null, new MsgPack[] { KFT0.F });
|
||||
else if (kf is KFT1 KFT1) keySets[i0].Array[1][i1] =
|
||||
new MsgPack(null, new MsgPack[] { KFT1.F, KFT1.V });
|
||||
else if (kf is KFT2 KFT2) keySets[i0].Array[1][i1] =
|
||||
new MsgPack(null, new MsgPack[] { KFT2.F, KFT2.V, KFT2.T });
|
||||
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].Id;
|
||||
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<BoneInfo[]> BoneInfo;
|
||||
public Pointer<KeySet[]> KeySet ;
|
||||
public Pointer< int[]> BoneInfo;
|
||||
|
||||
public int HighBits;
|
||||
public int FrameCount;
|
||||
@@ -329,22 +364,17 @@ namespace KKdMainLib
|
||||
public KFT2[] Keys;
|
||||
public KeySetType Type;
|
||||
|
||||
public override string ToString() => $"Type: {Type}" + (Type == KeySetType.Static ?
|
||||
$"; Value: {Keys[0].Check()}" : Type > KeySetType.Static ? $"; Keys: {Keys.Length}" : "");
|
||||
public 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,
|
||||
Interpolated = 0b11,
|
||||
}
|
||||
|
||||
public struct BoneInfo
|
||||
{
|
||||
public string Name;
|
||||
public int Id;
|
||||
None = 0b00,
|
||||
Static = 0b01,
|
||||
Linear = 0b10,
|
||||
Tangent = 0b11,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,780 @@
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public struct MotHead : System.IDisposable
|
||||
{
|
||||
private int i, i0, i1;
|
||||
private Stream s;
|
||||
|
||||
public HeaderData Header;
|
||||
|
||||
public void MotHeadReader(string file)
|
||||
{
|
||||
s = File.OpenReader(file + ".bin");
|
||||
s.RI32();
|
||||
Header = new HeaderData();
|
||||
|
||||
int offset = s.RI32();
|
||||
if (offset < 0x10) goto RETURN;
|
||||
s.O = offset;
|
||||
s.P = 0;
|
||||
|
||||
Header. MotionSetID = s.RI32();
|
||||
Header.StartMotionID = s.RI32();
|
||||
Header. EndMotionID = s.RI32();
|
||||
Header.SubHeaderOffset = s.RI32();
|
||||
|
||||
if (Header.SubHeaderOffset < 0x10) goto RETURN;
|
||||
i0 = Header.EndMotionID - Header.StartMotionID;
|
||||
if (i0 < 0) goto RETURN;
|
||||
|
||||
s.P = Header.SubHeaderOffset;
|
||||
Header.Data = new HeaderData.Sub[++i0];
|
||||
for (i = 0; i < Header.Data.Length; i++) Header.Data[i].Offset = s.RI32();
|
||||
for (i = 0; i < Header.Data.Length; i++)
|
||||
{
|
||||
if (Header.Data[i].Offset < 0x10) continue;
|
||||
|
||||
s.P = Header.Data[i].Offset;
|
||||
|
||||
Header.Data[i].MotionID = Header.StartMotionID + i;
|
||||
Header.Data[i].SomeData = s.RI32();
|
||||
s.RI64();
|
||||
s.RI64();
|
||||
Header.Data[i].Offset2 = s.RI32();
|
||||
Header.Data[i].DataHeaderOffset = s.RI32();
|
||||
|
||||
if (Header.Data[i].DataHeaderOffset < 0x10) goto RETURN;
|
||||
s.P = Header.Data[i].DataHeaderOffset;
|
||||
i0 = 0;
|
||||
while (s.RI32() != -1) { s.RI32(); s.RI32(); i0++; }
|
||||
s.P = Header.Data[i].DataHeaderOffset;
|
||||
|
||||
Header.Data[i].Array = new HeaderData.Sub.Data[i0];
|
||||
for (i0 = 0; i0 < Header.Data[i].Array.Length; i0++)
|
||||
{
|
||||
Header.Data[i].Array[i0].Type = s.RI32();
|
||||
Header.Data[i].Array[i0].Frame = s.RI32();
|
||||
Header.Data[i].Array[i0].Offset = s.RI32();
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < Header.Data.Length; i++)
|
||||
{
|
||||
if (Header.Data[i].Offset2 > 0x10)
|
||||
{
|
||||
s.P = Header.Data[i].Offset2;
|
||||
i0 = 0;
|
||||
while (s.RI32() != -1) { s.RI32(); i0++; }
|
||||
s.P = Header.Data[i].Offset2;
|
||||
|
||||
Header.Data[i].Array2 = new HeaderData.Sub.Data2[i0];
|
||||
for (i0 = 0; i0 < Header.Data[i].Array2.Length; i0++)
|
||||
{
|
||||
Header.Data[i].Array2[i0].Frame = s.RI32();
|
||||
Header.Data[i].Array2[i0].Offset = s.RI32();
|
||||
}
|
||||
|
||||
for (i0 = 0; i0 < Header.Data[i].Array2.Length; i0++)
|
||||
{
|
||||
if (Header.Data[i].Array2[i0].Offset < 0x10) goto RETURN;
|
||||
s.P = Header.Data[i].Array2[i0].Offset;
|
||||
Header.Data[i].Array2[i0].Array = new int[7];
|
||||
for (i1 = 0; i1 < Header.Data[i].Array2[i0].Array.Length; i1++)
|
||||
Header.Data[i].Array2[i0].Array[i1] = s.RI32();
|
||||
}
|
||||
}
|
||||
|
||||
if (Header.Data[i].Array == null || Header.Data[i].Array.Length < 1) continue;
|
||||
|
||||
for (i0 = 0; i0 < Header.Data[i].Array.Length; i0++)
|
||||
{
|
||||
ref HeaderData.Sub.Data Data = ref Header.Data[i].Array[i0];
|
||||
if ((i1 = GetSize(Data.Type)) < 1) continue;
|
||||
|
||||
|
||||
if (Data.Offset > 0)
|
||||
{
|
||||
s.P = Data.Offset;
|
||||
if (i1 == 0x01) Data.Array = new int[] { s.RU8 () };
|
||||
else if (i1 == 0x02) Data.Array = new int[] { s.RU16() };
|
||||
else
|
||||
{
|
||||
Data.Array = new int[i1 / 4];
|
||||
for (i1 = 0; i1 < Data.Array.Length; i1++) Data.Array[i1] = s.RI32();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RETURN:
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MotHeadWriter(string file)
|
||||
{
|
||||
if (Header.Data == null || Header.Data.Length < 1) return;
|
||||
|
||||
Header.StartMotionID = 0x7FFFFFFF;
|
||||
Header.EndMotionID = 0x00000000;
|
||||
for (i = 0; i < Header.Data.Length; i++)
|
||||
{
|
||||
if (Header.Data[i].MotionID < Header.StartMotionID)
|
||||
Header.StartMotionID = Header.Data[i].MotionID;
|
||||
if (Header.Data[i].MotionID > Header. EndMotionID)
|
||||
Header. EndMotionID = Header.Data[i].MotionID;
|
||||
}
|
||||
|
||||
s = File.OpenWriter(file + ".bin", true);
|
||||
s.W(0x01);
|
||||
s.W(0x20);
|
||||
s.A(0x20, true);
|
||||
s.O = 0x20;
|
||||
s.P = 0;
|
||||
s.W(0);
|
||||
for (int I = Header.EndMotionID - Header.StartMotionID; I > -1; I--)
|
||||
for (i = 0; i < Header.Data.Length; i++)
|
||||
if (Header.StartMotionID + I == Header.Data[i].MotionID)
|
||||
{
|
||||
s.A(0x20, true);
|
||||
Header.Data[i].Offset = s.P;
|
||||
Header.Data[i].DataHeaderOffset = Header.Data[i].Offset + 0x20;
|
||||
s.W(0L);
|
||||
s.W(0L);
|
||||
s.W(0L);
|
||||
s.W(0L);
|
||||
|
||||
for (i0 = 0; i0 < Header.Data[i].Array.Length; i0++)
|
||||
{ s.W( 0); s.W( 0); s.W(0); }
|
||||
s.W(-1); s.W(-1); s.W(0);
|
||||
|
||||
for (i0 = Header.Data[i].Array.Length - 1; i0 > -1; i0--)
|
||||
{
|
||||
ref HeaderData.Sub.Data data = ref Header.Data[i].Array[i0];
|
||||
int Size = GetSize(data.Type);
|
||||
if (data.Array == null || data.Array.Length < 1 || Size < 1) continue;
|
||||
|
||||
if (data.Type == 0x3E || data.Type == 0x49) s.A(0x20, true);
|
||||
data.Offset = s.P;
|
||||
|
||||
if (Size == 0x01) s.W(( byte)data.Array[0]);
|
||||
else if (Size == 0x02) s.W((short)data.Array[0]);
|
||||
else
|
||||
{
|
||||
if (s.P % 0x4 != 0) s.A(0x04, true);
|
||||
Size /= 4;
|
||||
|
||||
data.Offset = s.P;
|
||||
for (i1 = 0; i1 < data.Array.Length && i1 < Size; i1++)
|
||||
s.W(data.Array[i1]);
|
||||
|
||||
for (; i1 < Size; i1++) s.W(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (Header.Data[i].Array2 != null)
|
||||
if (Header.Data[i].Array2.Length > 0)
|
||||
{
|
||||
Header.Data[i].Offset2 = s.P;
|
||||
|
||||
for (i0 = 0; i0 < Header.Data[i].Array2.Length; i0++)
|
||||
{ s.W( 0); s.W(0); }
|
||||
s.W(-1); s.W(0);
|
||||
|
||||
for (i0 = Header.Data[i].Array2.Length - 1; i0 > -1; i0--)
|
||||
{
|
||||
Header.Data[i].Array2[i0].Offset = s.P;
|
||||
for (i1 = 0; i1 < Header.Data[i].Array2[i0].Array.Length && i1 < 7; i1++)
|
||||
s.W(Header.Data[i].Array2[i0].Array[i1]);
|
||||
|
||||
for (; i1 < 7; i1++) s.W(0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
s.A(0x04, true);
|
||||
Header.SubHeaderOffset = s.P;
|
||||
i1 = Header.EndMotionID - Header.StartMotionID;
|
||||
|
||||
int offset = 0;
|
||||
for (i = 0, i1++; i < i1; i++)
|
||||
{
|
||||
offset = 0;
|
||||
for (i0 = 0; i0 < Header.Data.Length; i0++)
|
||||
if (Header.StartMotionID + i == Header.Data[i0].MotionID)
|
||||
{ offset = Header.Data[i0].Offset; break; }
|
||||
s.W(offset);
|
||||
}
|
||||
s.A(0x20, true);
|
||||
|
||||
for (i = 0; i < Header.Data.Length; i++)
|
||||
{
|
||||
s.P = Header.Data[i].Offset;
|
||||
s.W(Header.Data[i].SomeData);
|
||||
s.W(0);
|
||||
s.W(0L);
|
||||
s.W(0x040004);
|
||||
s.W(Header.Data[i].Offset2);
|
||||
s.W(Header.Data[i].DataHeaderOffset);
|
||||
s.W(0);
|
||||
|
||||
s.P = Header.Data[i].DataHeaderOffset;
|
||||
for (i0 = 0; i0 < Header.Data[i].Array.Length; i0++)
|
||||
{
|
||||
s.W(Header.Data[i].Array[i0].Type );
|
||||
s.W(Header.Data[i].Array[i0].Frame );
|
||||
s.W(Header.Data[i].Array[i0].Offset);
|
||||
}
|
||||
|
||||
s.P = Header.Data[i].Offset2;
|
||||
if (Header.Data[i].Array2 != null)
|
||||
for (i0 = 0; i0 < Header.Data[i].Array2.Length; i0++)
|
||||
{
|
||||
s.W(Header.Data[i].Array2[i0].Frame );
|
||||
s.W(Header.Data[i].Array2[i0].Offset);
|
||||
}
|
||||
}
|
||||
|
||||
s.P = 0;
|
||||
s.W(Header.MotionSetID );
|
||||
s.W(Header.StartMotionID );
|
||||
s.W(Header. EndMotionID );
|
||||
s.W(Header.SubHeaderOffset);
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
{
|
||||
Header = new HeaderData();
|
||||
|
||||
MsgPack motHead;
|
||||
MsgPack msgPack = file.ReadMPAllAtOnce(json);
|
||||
if ((motHead = msgPack["MotHead"]).IsNull) return;
|
||||
Header.MotionSetID = motHead.RI32("MotionSetID");
|
||||
|
||||
MsgPack temp = MsgPack.New;
|
||||
MsgPack motions, array;
|
||||
if ((motions = motHead["Motions", true]).IsNull) return;
|
||||
Header.Data = new HeaderData.Sub[motions.Array.Length];
|
||||
for (i = 0; i < Header.Data.Length; i++)
|
||||
{
|
||||
Header.Data[i].MotionID = motions[i].RI32("MotionID");
|
||||
Header.Data[i].SomeData = motions[i].RI32("SomeData");
|
||||
|
||||
MsgPack array2;
|
||||
if ((array2 = motions[i]["Array2", true]).NotNull)
|
||||
{
|
||||
Header.Data[i].Array2 = new HeaderData.Sub.Data2[array2.Array.Length];
|
||||
|
||||
for (i0 = 0; i0 < Header.Data[i].Array2.Length; i0++)
|
||||
{
|
||||
Header.Data[i].Array2[i0].Frame = array2[i0].RI32("Frame");
|
||||
|
||||
MsgPack arrayArray;
|
||||
if ((arrayArray = array2[i0]["Array", true]).IsNull) continue;
|
||||
|
||||
Header.Data[i].Array2[i0].Array = new int[arrayArray.Array.Length];
|
||||
for (i1 = 0; i1 < Header.Data[i].Array2[i0].Array.Length; i1++)
|
||||
Header.Data[i].Array2[i0].Array[i1] = arrayArray[i1].RI32();
|
||||
}
|
||||
}
|
||||
|
||||
if ((array = motions[i]["Array", true]).IsNull) { continue; }
|
||||
|
||||
Header.Data[i].Array = new HeaderData.Sub.Data[array.Array.Length];
|
||||
|
||||
for (i0 = 0; i0 < Header.Data[i].Array.Length; i0++)
|
||||
{
|
||||
ref HeaderData.Sub.Data data = ref Header.Data[i].Array[i0];
|
||||
data.Type = array[i0].RI32("Type");
|
||||
data.Frame = array[i0].RI32("Frame");
|
||||
|
||||
if ((temp = array[i0]["Type3"]).NotNull)
|
||||
{
|
||||
data.Type = 0x03;
|
||||
data.Array = new int[] { temp.RI32("i0") };
|
||||
}
|
||||
else if ((temp = array[i0]["Type53"]).NotNull)
|
||||
{
|
||||
data.Type = 0x35;
|
||||
data.Array = new int[] { temp.RI32("i0"),
|
||||
temp.RF32("f1").ToI32(),
|
||||
temp.RF32("f2").ToI32(),
|
||||
temp.RI32("i3") };
|
||||
}
|
||||
else if ((temp = array[i0]["Type54"]).NotNull)
|
||||
{
|
||||
data.Type = 0x36;
|
||||
data.Array = new int[] { temp.RI32("i0"),
|
||||
temp.RF32("f1").ToI32(),
|
||||
temp.RF32("f2").ToI32(),
|
||||
temp.RI32("i3") };
|
||||
}
|
||||
else if ((temp = array[i0]["Type55"]).NotNull)
|
||||
{
|
||||
data.Type = 0x37;
|
||||
data.Array = new int[] { temp.RI32("i0"),
|
||||
temp.RF32("f1").ToI32(),
|
||||
temp.RF32("f2").ToI32(),
|
||||
temp.RI32("i3") };
|
||||
}
|
||||
else if ((temp = array[i0]["Type56"]).NotNull)
|
||||
{
|
||||
data.Type = 0x38;
|
||||
data.Array = new int[] { temp.RI32("i0"),
|
||||
temp.RF32("f1").ToI32(),
|
||||
temp.RF32("f2").ToI32(),
|
||||
temp.RI32("i3") };
|
||||
}
|
||||
else if ((temp = array[i0]["Type57"]).NotNull)
|
||||
{
|
||||
data.Type = 0x39;
|
||||
data.Array = new int[] { temp.RI32("i0"),
|
||||
temp.RF32("f1").ToI32(),
|
||||
temp.RF32("f2").ToI32(),
|
||||
temp.RI32("i3") };
|
||||
}
|
||||
else if ((temp = array[i0]["Type60"]).NotNull)
|
||||
{
|
||||
data.Type = 0x3C;
|
||||
data.Array = new int[] { temp.RI32("i0"),
|
||||
temp.RF32("f1").ToI32(),
|
||||
temp.RF32("f2").ToI32(),
|
||||
temp.RF32("f3").ToI32() };
|
||||
}
|
||||
else if ((temp = array[i0]["Type61"]).NotNull)
|
||||
{
|
||||
data.Type = 0x3D;
|
||||
data.Array = new int[] { temp.RI32("i0"), temp.RF32("f1").ToI32() };
|
||||
}
|
||||
else if ((temp = array[i0]["Type62"]).NotNull)
|
||||
{
|
||||
data.Type = 0x3E;
|
||||
data.Array = new int[0x10];
|
||||
data.Array[ 0] = temp.RI32("i0");
|
||||
data.Array[ 1] =
|
||||
((byte)temp.RI32("i1_3") << 24) | ((byte)temp.RI32("i1_2") << 16) |
|
||||
((byte)temp.RI32("i1_1") << 8) | (byte)temp.RI32("i1_0");
|
||||
data.Array[ 2] = temp.RF32("f2" ).ToI32();
|
||||
data.Array[ 3] = temp.RF32("f3" ).ToI32();
|
||||
data.Array[ 4] = temp.RF32("f4" ).ToI32();
|
||||
data.Array[ 5] = temp.RF32("f5" ).ToI32();
|
||||
data.Array[ 6] = temp.RF32("f6" ).ToI32();
|
||||
data.Array[ 7] = temp.RF32("f7" ).ToI32();
|
||||
data.Array[ 8] = temp.RF32("f8" ).ToI32();
|
||||
data.Array[ 9] = temp.RF32("f9" ).ToI32();
|
||||
data.Array[10] = temp.RF32("f10").ToI32();
|
||||
data.Array[11] = temp.RF32("f11").ToI32();
|
||||
data.Array[12] = temp.RF32("f12").ToI32();
|
||||
data.Array[13] = temp.RF32("f13").ToI32();
|
||||
data.Array[14] = temp.RF32("f14").ToI32();
|
||||
data.Array[15] = temp.RI32("i15");
|
||||
}
|
||||
else if ((temp = array[i0]["Type65"]).NotNull)
|
||||
{
|
||||
data.Type = 0x41;
|
||||
data.Array = new int[] { temp.RI32("i0") };
|
||||
}
|
||||
else if ((temp = array[i0]["Type66"]).NotNull)
|
||||
{
|
||||
data.Type = 0x42;
|
||||
data.Array = new int[] { temp.RF32("f0").ToI32() };
|
||||
}
|
||||
else if ((temp = array[i0]["Type67"]).NotNull)
|
||||
{
|
||||
data.Type = 0x43;
|
||||
data.Array = new int[] { temp.RI32("i0"), temp.RF32("f1").ToI32() };
|
||||
}
|
||||
else if ((temp = array[i0]["Type68"]).NotNull)
|
||||
{
|
||||
data.Type = 0x44;
|
||||
data.Array = new int[] { temp.RI32("i0"), temp.RF32("f1").ToI32() };
|
||||
}
|
||||
else if ((temp = array[i0]["Type69"]).NotNull)
|
||||
{
|
||||
data.Type = 0x45;
|
||||
data.Array = new int[] { temp.RI32("i0"), temp.RI32("i1") };
|
||||
}
|
||||
else if ((temp = array[i0]["Type70"]).NotNull)
|
||||
{
|
||||
data.Type = 0x46;
|
||||
data.Array = new int[] { temp.RI32("i0") };
|
||||
}
|
||||
else if ((temp = array[i0]["Type71"]).NotNull)
|
||||
{
|
||||
data.Type = 0x47;
|
||||
data.Array = new int[] { temp.RI32("i0"), temp.RF32("f1").ToI32() };
|
||||
}
|
||||
else if ((temp = array[i0]["Type72"]).NotNull)
|
||||
{
|
||||
data.Type = 0x48;
|
||||
data.Array = new int[] { temp.RI32("i0"), temp.RF32("f1").ToI32() };
|
||||
}
|
||||
else if ((temp = array[i0]["Type73"]).NotNull)
|
||||
{
|
||||
data.Type = 0x49;
|
||||
data.Array = new int[] { temp.RI32("i0"),
|
||||
temp.RF32("f1").ToI32(),
|
||||
temp.RI32("i2"),
|
||||
temp.RF32("f3").ToI32(),
|
||||
temp.RI32("i4"),
|
||||
temp.RI32("i5"),
|
||||
temp.RI32("i6"),
|
||||
temp.RI32("i7"),
|
||||
temp.RI32("i8"),
|
||||
temp.RI32("i9"),
|
||||
temp.RI32("i10"),
|
||||
temp.RI32("i11") };
|
||||
}
|
||||
else if ((temp = array[i0]["Type74"]).NotNull)
|
||||
{
|
||||
data.Type = 0x4A;
|
||||
data.Array = new int[] { temp.RI32("i0") };
|
||||
}
|
||||
else if ((temp = array[i0]["Type62"]).NotNull)
|
||||
{
|
||||
data.Type = 0x4B;
|
||||
data.Array = new int[0x0D];
|
||||
data.Array[ 0] = temp.RI32("i0");
|
||||
data.Array[ 1] = ((byte)temp.RI32("i1_1") << 8) | (byte)temp.RI32("i1_0");
|
||||
data.Array[ 2] = temp.RF32("f2" ).ToI32();
|
||||
data.Array[ 3] = temp.RF32("f3" ).ToI32();
|
||||
data.Array[ 4] = temp.RF32("f4" ).ToI32();
|
||||
data.Array[ 5] = temp.RF32("f5" ).ToI32();
|
||||
data.Array[ 6] = temp.RF32("f6" ).ToI32();
|
||||
data.Array[ 7] = temp.RF32("f7" ).ToI32();
|
||||
data.Array[ 8] = temp.RF32("f8" ).ToI32();
|
||||
data.Array[ 9] = temp.RF32("f9" ).ToI32();
|
||||
data.Array[10] = temp.RF32("f10").ToI32();
|
||||
data.Array[11] = temp.RF32("f11").ToI32();
|
||||
data.Array[12] = temp.RF32("f12").ToI32();
|
||||
}
|
||||
else if ((temp = array[i0]["Type76"]).NotNull)
|
||||
{
|
||||
data.Type = 0x4C;
|
||||
data.Array = new int[] { temp.RI32("i0"),
|
||||
temp.RF32("f1").ToI32(),
|
||||
temp.RF32("f2").ToI32() };
|
||||
}
|
||||
else if ((temp = array[i0]["Type77"]).NotNull)
|
||||
{
|
||||
data.Type = 0x4D;
|
||||
data.Array = new int[] { temp.RI32("i0") };
|
||||
}
|
||||
else if ((temp = array[i0]["Type79"]).NotNull)
|
||||
{
|
||||
data.Type = 0x4F;
|
||||
data.Array = new int[] { temp.RI32("i0") };
|
||||
}
|
||||
else if ((temp = array[i0]["Type80"]).NotNull)
|
||||
{
|
||||
data.Type = 0x50;
|
||||
data.Array = new int[] { temp.RI32("i0") };
|
||||
}
|
||||
else if ((temp = array[i0]["Array", true]).NotNull)
|
||||
{
|
||||
data.Array = new int[temp.Array.Length];
|
||||
for (i1 = 0; i1 < data.Array.Length; i1++)
|
||||
data.Array[i1] = temp[i1].RI32();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msgPack.Dispose();
|
||||
}
|
||||
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
if (Header.Data == null || Header.Data.Length < 1) return;
|
||||
|
||||
for (i = 0, i1 = 0; i < Header.Data.Length; i++)
|
||||
if (Header.Data[i].Offset >= 0x10) i1++;
|
||||
MsgPack motHead = new MsgPack("MotHead").Add("MotionSetID", Header.MotionSetID);
|
||||
MsgPack motions = new MsgPack(i1, "Motions");
|
||||
for (int I = 0, i = 0; i < Header.Data.Length; i++)
|
||||
{
|
||||
if (Header.Data[i].Offset < 0x10) continue;
|
||||
MsgPack motion = MsgPack.New
|
||||
.Add("MotionID", Header.Data[i].MotionID)
|
||||
.Add("SomeData", Header.Data[i].SomeData);
|
||||
|
||||
if (Header.Data[i].Array == null || Header.Data[i].Array.Length < 1) { }
|
||||
else
|
||||
{
|
||||
MsgPack array = new MsgPack(Header.Data[i].Array.Length, "Array");
|
||||
for (i0 = 0; i0 < Header.Data[i].Array.Length; i0++)
|
||||
{
|
||||
ref HeaderData.Sub.Data data = ref Header.Data[i].Array[i0];
|
||||
MsgPack arrayEntry = MsgPack.New;
|
||||
arrayEntry.Add("Frame", data.Frame);
|
||||
if (data.Array == null || data.Array.Length < 1)
|
||||
arrayEntry.Add("Type", data.Type);
|
||||
else if (data.Type == 0x03)
|
||||
arrayEntry.Add(new MsgPack("Type3")
|
||||
.Add("i0", data.Array[0]));
|
||||
else if (data.Type == 0x35)
|
||||
arrayEntry.Add(new MsgPack("Type53")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("f1", data.Array[1].ToF32())
|
||||
.Add("f2", data.Array[2].ToF32())
|
||||
.Add("i3", data.Array[3]));
|
||||
else if (data.Type == 0x36)
|
||||
arrayEntry.Add(new MsgPack("Type54")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("f1", data.Array[1].ToF32())
|
||||
.Add("f2", data.Array[2].ToF32())
|
||||
.Add("i3", data.Array[3]));
|
||||
else if (data.Type == 0x37)
|
||||
arrayEntry.Add(new MsgPack("Type55")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("f1", data.Array[1].ToF32())
|
||||
.Add("f2", data.Array[2].ToF32())
|
||||
.Add("i3", data.Array[3]));
|
||||
else if (data.Type == 0x38)
|
||||
arrayEntry.Add(new MsgPack("Type56")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("f1", data.Array[1].ToF32())
|
||||
.Add("f2", data.Array[2].ToF32())
|
||||
.Add("i3", data.Array[3]));
|
||||
else if (data.Type == 0x39)
|
||||
arrayEntry.Add(new MsgPack("Type57")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("f1", data.Array[1].ToF32())
|
||||
.Add("f2", data.Array[2].ToF32())
|
||||
.Add("i3", data.Array[3]));
|
||||
else if (data.Type == 0x3C)
|
||||
arrayEntry.Add(new MsgPack("Type60")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("f1", data.Array[1].ToF32())
|
||||
.Add("f2", data.Array[2].ToF32())
|
||||
.Add("f3", data.Array[3].ToF32()));
|
||||
else if (data.Type == 0x3D)
|
||||
arrayEntry.Add(new MsgPack("Type61")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("f1", data.Array[1].ToF32()));
|
||||
else if (data.Type == 0x3E)
|
||||
arrayEntry.Add(new MsgPack("Type62")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("i1_0", (byte) data.Array[1])
|
||||
.Add("i1_1", (byte)(data.Array[1] >> 8))
|
||||
.Add("i1_2", (byte)(data.Array[1] >> 16))
|
||||
.Add("i1_3", (byte)(data.Array[1] >> 24))
|
||||
.Add("f2" , data.Array[ 2].ToF32())
|
||||
.Add("f3" , data.Array[ 3].ToF32())
|
||||
.Add("f4" , data.Array[ 4].ToF32())
|
||||
.Add("f5" , data.Array[ 5].ToF32())
|
||||
.Add("f6" , data.Array[ 6].ToF32())
|
||||
.Add("f7" , data.Array[ 7].ToF32())
|
||||
.Add("f8" , data.Array[ 8].ToF32())
|
||||
.Add("f9" , data.Array[ 9].ToF32())
|
||||
.Add("f10", data.Array[10].ToF32())
|
||||
.Add("f11", data.Array[11].ToF32())
|
||||
.Add("f12", data.Array[12].ToF32())
|
||||
.Add("f13", data.Array[13].ToF32())
|
||||
.Add("f14", data.Array[14].ToF32())
|
||||
.Add("i15", data.Array[15]));
|
||||
else if (data.Type == 0x41)
|
||||
arrayEntry.Add(new MsgPack("Type65")
|
||||
.Add("i0", data.Array[0]));
|
||||
else if (data.Type == 0x42)
|
||||
arrayEntry.Add(new MsgPack("Type66")
|
||||
.Add("f0", data.Array[0].ToF32()));
|
||||
else if (data.Type == 0x43)
|
||||
arrayEntry.Add(new MsgPack("Type67")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("f1", data.Array[1].ToF32()));
|
||||
else if (data.Type == 0x44)
|
||||
arrayEntry.Add(new MsgPack("Type68")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("f1", data.Array[1].ToF32()));
|
||||
else if (data.Type == 0x45)
|
||||
arrayEntry.Add(new MsgPack("Type69")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("i1", data.Array[1]));
|
||||
else if (data.Type == 0x46)
|
||||
arrayEntry.Add(new MsgPack("Type70")
|
||||
.Add("i0", data.Array[0]));
|
||||
else if (data.Type == 0x47)
|
||||
arrayEntry.Add(new MsgPack("Type71")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("f1", data.Array[1].ToF32()));
|
||||
else if (data.Type == 0x48)
|
||||
arrayEntry.Add(new MsgPack("Type72")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("f1", data.Array[1].ToF32()));
|
||||
else if (data.Type == 0x49)
|
||||
arrayEntry.Add(new MsgPack("Type73")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("f1", data.Array[1].ToF32())
|
||||
.Add("i2", data.Array[2])
|
||||
.Add("f3", data.Array[3].ToF32())
|
||||
.Add("i4", data.Array[4])
|
||||
.Add("i5", data.Array[5])
|
||||
.Add("i6", data.Array[6])
|
||||
.Add("i7", data.Array[7])
|
||||
.Add("i8", data.Array[8])
|
||||
.Add("i9", data.Array[9])
|
||||
.Add("i10", data.Array[10])
|
||||
.Add("i11", data.Array[11]));
|
||||
else if (data.Type == 0x4A)
|
||||
arrayEntry.Add(new MsgPack("Type74")
|
||||
.Add("i0", data.Array[0]));
|
||||
else if (data.Type == 0x4B)
|
||||
arrayEntry.Add(new MsgPack("Type75")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("i1_0", (byte) data.Array[1])
|
||||
.Add("i1_1", (byte)(data.Array[1] >> 8))
|
||||
.Add("f2" , data.Array[ 2].ToF32())
|
||||
.Add("f3" , data.Array[ 3].ToF32())
|
||||
.Add("f4" , data.Array[ 4].ToF32())
|
||||
.Add("f5" , data.Array[ 5].ToF32())
|
||||
.Add("f6" , data.Array[ 6].ToF32())
|
||||
.Add("f7" , data.Array[ 7].ToF32())
|
||||
.Add("f8" , data.Array[ 8].ToF32())
|
||||
.Add("f9" , data.Array[ 9].ToF32())
|
||||
.Add("f10", data.Array[10].ToF32())
|
||||
.Add("f11", data.Array[11].ToF32())
|
||||
.Add("f12", data.Array[12].ToF32()));
|
||||
else if (data.Type == 0x4C)
|
||||
arrayEntry.Add(new MsgPack("Type76")
|
||||
.Add("i0", data.Array[0])
|
||||
.Add("f1", data.Array[1].ToF32())
|
||||
.Add("f2", data.Array[2].ToF32()));
|
||||
else if (data.Type == 0x4D)
|
||||
arrayEntry.Add(new MsgPack("Type77")
|
||||
.Add("i0", data.Array[0]));
|
||||
else if (data.Type == 0x4F)
|
||||
arrayEntry.Add(new MsgPack("Type79")
|
||||
.Add("i0", data.Array[0]));
|
||||
else if (data.Type == 0x50)
|
||||
arrayEntry.Add(new MsgPack("Type80")
|
||||
.Add("i0", data.Array[0]));
|
||||
else
|
||||
{
|
||||
arrayEntry.Add("Type", data.Type);
|
||||
MsgPack arrayArray = new MsgPack(data.Array.Length, "Array");
|
||||
for (i1 = 0; i1 < data.Array.Length; i1++)
|
||||
arrayArray[i1] = data.Array[i1];
|
||||
arrayEntry.Add(arrayArray);
|
||||
}
|
||||
array[i0] = arrayEntry;
|
||||
}
|
||||
motion.Add(array);
|
||||
}
|
||||
|
||||
if (Header.Data[i].Array2 == null || Header.Data[i].Array2.Length < 1) { }
|
||||
else
|
||||
{
|
||||
MsgPack array2 = new MsgPack(Header.Data[i].Array2.Length, "Array2");
|
||||
for (i0 = 0; i0 < Header.Data[i].Array2.Length; i0++)
|
||||
{
|
||||
MsgPack arrayEntry = MsgPack.New.Add("Frame", Header.Data[i].Array2[i0].Frame);
|
||||
if (Header.Data[i].Array2[i0].Array == null || Header.Data[i].Array2[i0].Array.Length < 1) { }
|
||||
else
|
||||
{
|
||||
MsgPack arrayArray = new MsgPack(Header.Data[i].Array2[i0].Array.Length, "Array");
|
||||
for (i1 = 0; i1 < Header.Data[i].Array2[i0].Array.Length; i1++)
|
||||
arrayArray[i1] = Header.Data[i].Array2[i0].Array[i1];
|
||||
arrayEntry.Add(arrayArray);
|
||||
}
|
||||
array2[i0] = arrayEntry;
|
||||
}
|
||||
motion.Add(array2);
|
||||
}
|
||||
|
||||
motions[I] = motion;
|
||||
I++;
|
||||
}
|
||||
motHead.Add(motions);
|
||||
motHead.WriteAfterAll(false, true, file, json);
|
||||
}
|
||||
|
||||
private static int GetSize(int Type) =>
|
||||
Type switch
|
||||
{
|
||||
0x02 => 0x02,
|
||||
0x03 => 0x04,
|
||||
0x04 => 0x04,
|
||||
0x07 => 0x08,
|
||||
0x08 => 0x08,
|
||||
0x0D => 0x0C,
|
||||
0x11 => 0x1C,
|
||||
0x1D => 0x30,
|
||||
0x20 => 0x10,
|
||||
0x21 => 0x18,
|
||||
0x35 => 0x14,
|
||||
0x36 => 0x14,
|
||||
0x37 => 0x14,
|
||||
0x38 => 0x14,
|
||||
0x39 => 0x14,
|
||||
0x3A => 0x14,
|
||||
0x3B => 0x04,
|
||||
0x3C => 0x10,
|
||||
0x3D => 0x08,
|
||||
0x3E => 0x40,
|
||||
0x40 => 0x00,
|
||||
0x41 => 0x04,
|
||||
0x42 => 0x04,
|
||||
0x43 => 0x08,
|
||||
0x44 => 0x08,
|
||||
0x45 => 0x08,
|
||||
0x46 => 0x04,
|
||||
0x47 => 0x08,
|
||||
0x48 => 0x08,
|
||||
0x49 => 0x30,
|
||||
0x4A => 0x02,
|
||||
0x4B => 0x34,
|
||||
0x4C => 0x0C,
|
||||
0x4D => 0x04,
|
||||
0x4E => 0x1C,
|
||||
0x4F => 0x01,
|
||||
0x50 => 0x01,
|
||||
_ => 0x00,
|
||||
};
|
||||
|
||||
public void Dispose()
|
||||
{ if (s != null) s.D(); s = null; Header = default; }
|
||||
|
||||
public struct HeaderData
|
||||
{
|
||||
public int MotionSetID;
|
||||
public int StartMotionID;
|
||||
public int EndMotionID;
|
||||
public int SubHeaderOffset;
|
||||
|
||||
public Sub[] Data;
|
||||
|
||||
public struct Sub
|
||||
{
|
||||
public int Offset;
|
||||
public int MotionID;
|
||||
|
||||
public int SomeData;
|
||||
public int Offset2;
|
||||
public int DataHeaderOffset;
|
||||
|
||||
public Data[] Array;
|
||||
public Data2[] Array2;
|
||||
|
||||
public struct Data
|
||||
{
|
||||
public int Type;
|
||||
public int Frame;
|
||||
public int Offset;
|
||||
|
||||
public int[] Array;
|
||||
}
|
||||
|
||||
public struct Data2
|
||||
{
|
||||
public int Offset;
|
||||
|
||||
public int Frame;
|
||||
public int[] Array;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,7 @@
|
||||
using System.Reflection;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("KKdMainLib")]
|
||||
[assembly: AssemblyDescription("A simple library for working with Project Diva AC/DT/F/AFT/F2/X/FT files")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("KKdMainLib")]
|
||||
[assembly: AssemblyCopyright("korenkonder © 2018-2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("2BA7EFC6-91D1-8BBC-C487-06C7F36CC789")]
|
||||
[assembly: AssemblyVersion("0.4.8.0")]
|
||||
[assembly: AssemblyFileVersion("0.4.8.0")]
|
||||
|
||||
+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>
|
||||
+102
-116
@@ -1,185 +1,170 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
public struct STR : System.IDisposable
|
||||
{
|
||||
private long offset;
|
||||
private long offsetX;
|
||||
{
|
||||
private POF pof;
|
||||
private Header header;
|
||||
private Stream _IO;
|
||||
private Stream s;
|
||||
|
||||
public String[] STRs;
|
||||
public String[] Strings;
|
||||
|
||||
public int STRReader(string filepath, string ext)
|
||||
{
|
||||
_IO = File.OpenReader(filepath + ext);
|
||||
s = File.OpenReader(filepath + ext);
|
||||
|
||||
header = new Header();
|
||||
_IO.Format = Format.F;
|
||||
header.Signature = _IO.RI32();
|
||||
if (header.Signature == 0x41525453)
|
||||
s.Format = Format.F;
|
||||
uint signature = s.RU32();
|
||||
if (signature == 0x41525453)
|
||||
{
|
||||
header = _IO.ReadHeader(true, false);
|
||||
pof.Offsets = KKdList<long>.New;
|
||||
|
||||
long count = _IO.RI32E();
|
||||
offset = _IO.RI32E();
|
||||
|
||||
if (offset == 0)
|
||||
{
|
||||
offset = count;
|
||||
offsetX = _IO.RI64();
|
||||
count = _IO.RI64();
|
||||
_IO.O = header.Length;
|
||||
_IO.Format = Format.X;
|
||||
_IO.I64O += offset;
|
||||
_IO.P = 0;
|
||||
}
|
||||
else _IO.P = header.Length + 0x40;
|
||||
header = s.ReadHeader(true);
|
||||
s.IsBE = header.UseBigEndian;
|
||||
s.Format = header.Format;
|
||||
|
||||
STRs = new String[count];
|
||||
int count = s.RI32E();
|
||||
int offset = s.RI32E();
|
||||
|
||||
s.P = offset;
|
||||
Strings = new String[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
STRs[i].Str.O = _IO.RI32E();
|
||||
STRs[i].ID = _IO.RI32E();
|
||||
Strings[i].Str.O = s.RI32E();
|
||||
Strings[i].ID = s.RI32E();
|
||||
}
|
||||
|
||||
if (_IO.IsX)
|
||||
{
|
||||
_IO.I64O = header.Length + offsetX;
|
||||
for (int i = 0; i < count; i++)
|
||||
STRs[i].Str.V = _IO.RSaO(STRs[i].Str.O);
|
||||
}
|
||||
else
|
||||
{
|
||||
_IO.O = 0;
|
||||
for (int i = 0; i < count; i++)
|
||||
STRs[i].Str.V = STRs[i].Str.O > 0 ?
|
||||
_IO.RSaO(STRs[i].Str.O) : null;
|
||||
}
|
||||
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
|
||||
{
|
||||
_IO.P -= 4;
|
||||
if ((signature >> 24) > 0) { header.Format = Format.DT; s.IsBE = true; }
|
||||
else header.Format = Format.F;
|
||||
int count = 0;
|
||||
for (int a = 0, i = 0; _IO.P > 0 && _IO.P < _IO.L; i++, count++)
|
||||
{
|
||||
a = _IO.RI32();
|
||||
if (a == 0) break;
|
||||
}
|
||||
STRs = new String[count];
|
||||
for (uint i = signature; i != 0 && s.P >= 0 && s.P < s.L; count++)
|
||||
i = s.RU32();
|
||||
Strings = new String[count];
|
||||
|
||||
s.P = 0;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
_IO.I64P = STRs[i].Str.O;
|
||||
STRs[i].ID = i;
|
||||
STRs[i].Str.V = _IO.NTUTF8();
|
||||
Strings[i].ID = i;
|
||||
Strings[i].Str.V = s.RSaO();
|
||||
}
|
||||
}
|
||||
|
||||
_IO.C();
|
||||
s.C();
|
||||
return 1;
|
||||
}
|
||||
|
||||
public void STRWriter(string filepath)
|
||||
{
|
||||
if (STRs == null || STRs.Length == 0 || header.Format > Format.F2BE) return;
|
||||
if (Strings == null || Strings.Length == 0 || header.Format > Format.F2) return;
|
||||
uint offset = 0;
|
||||
uint currentOffset = 0;
|
||||
_IO = File.OpenWriter(filepath + (header.Format > Format.AFT &&
|
||||
Format format = header.Format;
|
||||
s = File.OpenWriter(filepath + (header.Format > Format.AFT &&
|
||||
header.Format < Format.FT ? ".str" : ".bin"), true);
|
||||
_IO.Format = header.Format;
|
||||
s.Format = header.Format;
|
||||
s.IsBE = header.UseBigEndian;
|
||||
pof.Offsets = KKdList<long>.New;
|
||||
|
||||
long count = STRs.LongLength;
|
||||
if (_IO.Format > Format.AFT && _IO.Format < Format.FT)
|
||||
long count = Strings.LongLength;
|
||||
if (s.Format > Format.AFT && s.Format < Format.FT)
|
||||
{
|
||||
_IO.P = 0x40;
|
||||
_IO.WX(count, ref pof);
|
||||
_IO.WX(0x80);
|
||||
_IO.P = 0x80;
|
||||
for (int i = 0; i < count; i++) _IO.W(0x00L);
|
||||
_IO.A(0x10);
|
||||
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++) _IO.W(0x00);
|
||||
_IO.A(0x20);
|
||||
}
|
||||
for (int i = 0; i < count; i++) s.W(0x00);
|
||||
s.A(0x10);
|
||||
|
||||
KKdList<string> usedSTR = KKdList<string>.New;
|
||||
KKdList<int> usedSTRPos = KKdList<int>.New;
|
||||
int[] STRPos = new int[count];
|
||||
|
||||
usedSTRPos.Add(_IO.P);
|
||||
usedSTR.Add("");
|
||||
_IO.W(0);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
if (!usedSTR.Contains(STRs[i].Str.V))
|
||||
if (usedSTR.Contains(Strings[i].Str.V))
|
||||
{
|
||||
STRPos[i] = _IO.P;
|
||||
usedSTRPos.Add(STRPos[i]);
|
||||
usedSTR.Add(STRs[i].Str.V);
|
||||
_IO.W(STRs[i].Str.V);
|
||||
_IO.W(0);
|
||||
for (int i2 = 0; i2 < count; i2++)
|
||||
if (usedSTR[i2] == Strings[i].Str.V)
|
||||
{ STRPos[i] = usedSTRPos[i2]; break; }
|
||||
}
|
||||
else
|
||||
for (int i2 = 0; i2 < count; i2++)
|
||||
if (usedSTR[i2] == STRs[i].Str.V) { STRPos[i] = usedSTRPos[i2]; break; }
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
s.A(0x4);
|
||||
s.L = s.P;
|
||||
|
||||
if (_IO.Format > Format.AFT)
|
||||
if (s.Format > Format.AFT)
|
||||
{
|
||||
_IO.A(0x10);
|
||||
offset = _IO.U32P;
|
||||
_IO.P = 0x80;
|
||||
s.A(0x10);
|
||||
offset = s.PU32;
|
||||
s.P = 0x80;
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
pof.Offsets.Add(_IO.P);
|
||||
_IO.WE(STRPos[i]);
|
||||
_IO.WE(STRs[i].ID);
|
||||
pof.Offsets.Add(s.P);
|
||||
s.WE(STRPos[i]);
|
||||
s.WE(Strings[i].ID);
|
||||
}
|
||||
|
||||
_IO.U32P = offset;
|
||||
_IO.W(pof, false, 1);
|
||||
currentOffset = _IO.U32P;
|
||||
_IO.WEOFC();
|
||||
header.DataSize = (int)(currentOffset - 0x40);
|
||||
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 = (int)(offset - 0x40);
|
||||
_IO.P = 0;
|
||||
_IO.W(header, true);
|
||||
header.SectionSize = offset - 0x40;
|
||||
header.UseSectionSize = true;
|
||||
s.P = 0;
|
||||
s.W(header, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_IO.P = 0;
|
||||
for (int i = 0; i < count; i++) _IO.W(STRPos[i]);
|
||||
s.P = 0;
|
||||
s.IsBE = header.Format < Format.F;
|
||||
for (int i = 0; i < count; i++) s.WE(STRPos[i]);
|
||||
}
|
||||
_IO.C();
|
||||
s.C();
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
{
|
||||
header = default;
|
||||
Strings = default;
|
||||
MsgPack temp;
|
||||
MsgPack msgPack = file.ReadMPAllAtOnce(json);
|
||||
if ((temp = msgPack["STR"]).NotNull) return;
|
||||
if ((temp = msgPack["STR"]).IsNull) return;
|
||||
|
||||
header = new Header();
|
||||
System.Enum.TryParse(temp.RS("Format"), out header.Format);
|
||||
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 = msgPack["Strings", true]).IsNull) return;
|
||||
if ((temp = temp["Strings", true]).IsNull) return;
|
||||
|
||||
STRs = new String[temp.Array.Length];
|
||||
for (int i = 0; i < STRs.Length; i++)
|
||||
Strings = new String[temp.Array.Length];
|
||||
for (int i = 0; i < Strings.Length; i++)
|
||||
{
|
||||
STRs[i].ID = temp[i].RI32("ID" );
|
||||
STRs[i].Str.V = temp[i].RS ("Str");
|
||||
if (STRs[i].Str.V == null) STRs[i].Str.V = "";
|
||||
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.Dispose();
|
||||
@@ -187,24 +172,25 @@ namespace KKdMainLib
|
||||
|
||||
public void MsgPackWriter(string file, bool json)
|
||||
{
|
||||
if (STRs == null || STRs.Length == 0) return;
|
||||
if (Strings == null || Strings.Length == 0) return;
|
||||
MsgPack str = new MsgPack("STR").Add("Format", header.Format.ToString());
|
||||
MsgPack strings = new MsgPack(STRs.Length, "Strings");
|
||||
for (int i = 0; i < STRs.Length; i++)
|
||||
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] = MsgPack.New.Add("ID", STRs[i].ID);
|
||||
if (STRs[i].Str.V != null)
|
||||
if (STRs[i].Str.V != "")
|
||||
strings[i] = strings[i].Add("Str", STRs[i].Str.V);
|
||||
strings[i] = MsgPack.New.Add("ID", Strings[i].ID);
|
||||
if (Strings[i].Str.V != null)
|
||||
if (Strings[i].Str.V != "")
|
||||
strings[i] = strings[i].Add("Str", Strings[i].Str.V);
|
||||
}
|
||||
str.Add(strings);
|
||||
|
||||
str.WriteAfterAll(true, file, json);
|
||||
str.WriteAfterAll(false, true, file, json);
|
||||
}
|
||||
|
||||
private bool disposed;
|
||||
public void Dispose()
|
||||
{ if (!disposed) { if (_IO != null) _IO.Dispose(); STRs = default;
|
||||
{ if (!disposed) { if (s != null) s.D(); s = null; Strings = default;
|
||||
pof = default; header = default; disposed = true; } }
|
||||
|
||||
public struct String
|
||||
@@ -212,7 +198,7 @@ namespace KKdMainLib
|
||||
public int ID;
|
||||
public Pointer<string> Str;
|
||||
|
||||
public override string ToString() => "ID: " + ID + (Str.V != null ||
|
||||
public override string ToString() => "ID: " + ID + (Str.V != null ||
|
||||
Str.V != "" ? ("; Str: " + Str.V) : "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
+57
-50
@@ -1,4 +1,4 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdSoundLib
|
||||
@@ -20,43 +20,47 @@ namespace KKdSoundLib
|
||||
if (reader.RS(0x04) != "DIVA") { reader.C(); return; }
|
||||
|
||||
reader.RI32();
|
||||
Data.Size = reader.RU32();
|
||||
Data.SampleRate = reader.RU32();
|
||||
Data.SamplesCount = reader.RU32();
|
||||
Data.Size = reader.RI32();
|
||||
Data.SampleRate = reader.RI32();
|
||||
Data.SamplesCount = reader.RI32();
|
||||
reader.RI64();
|
||||
Data.Channels = reader.RU16();
|
||||
reader.RU16();
|
||||
Data.Name = reader.RS(0x20);
|
||||
|
||||
Stream writer = File.OpenWriter();
|
||||
if (!ToArray) writer = File.OpenWriter(file + ".wav", true);
|
||||
writer.I64P = 0x2C;
|
||||
|
||||
byte value = 0;
|
||||
byte[] data = new byte[Data.SamplesCount * Data.Channels * 4];
|
||||
int[] current = new int[Data.Channels];
|
||||
int[] currentclamp = new int[Data.Channels];
|
||||
sbyte[] stepindex = new sbyte[Data.Channels];
|
||||
float f;
|
||||
|
||||
int* currentPtr = current.GetPtr();
|
||||
int* currentclampPtr = currentclamp.GetPtr();
|
||||
sbyte* stepindexPtr = stepindex.GetPtr();
|
||||
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Data.Channels; c++)
|
||||
{
|
||||
value = reader.RHB();
|
||||
IMADecoder(value, ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
|
||||
f = (float)(currentPtr[c] / 32768.0);
|
||||
writer.W(f);
|
||||
}
|
||||
fixed (int* currentPtr = current)
|
||||
fixed (int* currentclampPtr = currentclamp)
|
||||
fixed (sbyte* stepindexPtr = stepindex)
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
float* dataPtr = (float*)ptr;
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Data.Channels; c++, dataPtr++)
|
||||
{
|
||||
value = reader.RHB();
|
||||
IMADecoder(value, ref currentPtr[c], ref currentclampPtr[c], ref stepindexPtr[c]);
|
||||
*dataPtr = (float)(currentPtr[c] / 32768.0);
|
||||
}
|
||||
}
|
||||
reader.CR();
|
||||
|
||||
WAV.Header Header = new WAV.Header { Bytes = 4, Channels = Data.Channels, Format = 3,
|
||||
SampleRate = Data.SampleRate, Size = Data.SamplesCount * Data.Channels * 4 };
|
||||
writer.W(Header, 0);
|
||||
if (ToArray) Data.Data = writer.ToArray();
|
||||
writer.C();
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -74,7 +78,9 @@ namespace KKdSoundLib
|
||||
Stream writer = File.OpenWriter(file + ".diva", true);
|
||||
Data.Channels = Header.Channels;
|
||||
Data.SampleRate = Header.SampleRate;
|
||||
writer.I64P = 0x40;
|
||||
Data.SamplesCount = Header.Size / Header.Channels / Header.Bytes;
|
||||
writer.PI64 = 0x40;
|
||||
writer.LI64 = 0x40 + (Data.SamplesCount * Data.Channels).A(2, 2);
|
||||
|
||||
byte value = 0;
|
||||
int[] sample = new int[Data.Channels];
|
||||
@@ -82,23 +88,24 @@ namespace KKdSoundLib
|
||||
int[] currentclamp = new int[Data.Channels];
|
||||
sbyte[] stepindex = new sbyte[Data.Channels];
|
||||
|
||||
int* samplePtr = sample.GetPtr();
|
||||
int* currentPtr = current.GetPtr();
|
||||
int* currentclampPtr = currentclamp.GetPtr();
|
||||
sbyte* stepindexPtr = stepindex.GetPtr();
|
||||
Data.SamplesCount = Header.Size / Header.Channels / Header.Bytes;
|
||||
fixed (int* samplePtr = sample)
|
||||
fixed (int* currentPtr = current)
|
||||
fixed (int* currentclampPtr = currentclamp)
|
||||
fixed (sbyte* stepindexPtr = stepindex)
|
||||
{
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Header.Channels; c++)
|
||||
{
|
||||
samplePtr[c] = (reader.RS(Header.Bytes, Header.Format) * 0x8000).CFTI();
|
||||
value = IMAEncoder(samplePtr[c], ref currentPtr[c],
|
||||
ref currentclampPtr[c], ref stepindexPtr[c]);
|
||||
writer.W(value, 4);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Header.Channels; c++)
|
||||
{
|
||||
samplePtr[c] = (reader.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.I64P = 0x00;
|
||||
writer.PI64 = 0x00;
|
||||
writer.W("DIVA");
|
||||
writer.W(0x00);
|
||||
writer.W((Data.SamplesCount * Data.Channels).A(2, 2));
|
||||
@@ -119,14 +126,14 @@ namespace KKdSoundLib
|
||||
if ((value & 1) == 1) diff += step >> 2;
|
||||
if ((value & 2) == 2) diff += step >> 1;
|
||||
if ((value & 4) == 4) diff += step;
|
||||
|
||||
|
||||
if ((value & 8) == 8)
|
||||
{ currentclamp -= diff; current = currentclamp;
|
||||
if (currentclamp < -0x8000) currentclamp = -0x8000; }
|
||||
else
|
||||
{ currentclamp += diff; current = currentclamp;
|
||||
if (currentclamp > 0x7FFF) currentclamp = 0x7FFF; }
|
||||
|
||||
|
||||
stepindex += ima_index_table[value & 7];
|
||||
if (stepindex < 0) stepindex = 0;
|
||||
if (stepindex > 88) stepindex = 88;
|
||||
@@ -140,9 +147,9 @@ namespace KKdSoundLib
|
||||
{
|
||||
value = 0;
|
||||
step = ima_step_table[stepindex];
|
||||
|
||||
|
||||
delta = sample - current;
|
||||
|
||||
|
||||
if (delta < 0)
|
||||
{ value |= 8; delta = -delta; }
|
||||
diff = step >> 3;
|
||||
@@ -154,14 +161,14 @@ namespace KKdSoundLib
|
||||
step >>= 1;
|
||||
if (delta > step)
|
||||
{ value |= 1; diff += step; }
|
||||
|
||||
|
||||
if ((value & 8) == 8)
|
||||
{ currentclamp -= diff; current = currentclamp;
|
||||
if (currentclamp < -0x8000) currentclamp = -0x8000; }
|
||||
else
|
||||
{ currentclamp += diff; current = currentclamp;
|
||||
if (currentclamp > 0x7FFF) currentclamp = 0x7FFF; }
|
||||
|
||||
|
||||
stepindex += ima_index_table[value & 0x07];
|
||||
if (stepindex < 0) stepindex = 0;
|
||||
if (stepindex > 88) stepindex = 88;
|
||||
@@ -188,9 +195,9 @@ namespace KKdSoundLib
|
||||
|
||||
public struct DIVAFile
|
||||
{
|
||||
public uint Size;
|
||||
public uint SampleRate;
|
||||
public uint SamplesCount;
|
||||
public int Size;
|
||||
public int SampleRate;
|
||||
public int SamplesCount;
|
||||
public string Name;
|
||||
public ushort Channels;
|
||||
public byte[] Data;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace KKdSoundLib
|
||||
@@ -34,7 +34,7 @@ namespace KKdSoundLib
|
||||
if (Header.Format == 0x01 || Header.Format == 0x03 || Header.Format == 0xFFFE)
|
||||
{
|
||||
Header.Channels = _IO.RU16();
|
||||
Header.SampleRate = _IO.RU32();
|
||||
Header.SampleRate = _IO.RI32();
|
||||
_IO.RI32(); _IO.RI16();
|
||||
Header.Bytes = _IO.RU16();
|
||||
if (Header.Bytes % 8 != 0) return Header;
|
||||
@@ -51,8 +51,8 @@ namespace KKdSoundLib
|
||||
if (Header.Bytes == 8 && Header.Format == 1) return Header;
|
||||
_IO.S(Offset + 0x14, 0);
|
||||
if (_IO.RS(4) != "data") return Header;
|
||||
Header.Size = _IO.RU32();
|
||||
Header.HeaderSize = _IO.U32P;
|
||||
Header.Size = _IO.RI32();
|
||||
Header.HeaderSize = _IO.P;
|
||||
Header.IsSupported = true;
|
||||
return Header;
|
||||
}
|
||||
@@ -73,7 +73,7 @@ namespace KKdSoundLib
|
||||
_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);
|
||||
|
||||
@@ -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-2021</Copyright>
|
||||
<Description>A simple library for working with Project Diva F/AFT/F2/X/FT audio files</Description>
|
||||
<FileVersion>0.1.2.0</FileVersion>
|
||||
<PackageId>KKdSoundLib</PackageId>
|
||||
<Product>KKdSoundLib</Product>
|
||||
<TargetFramework>net461</TargetFramework>
|
||||
<Title>KKdSoundLib</Title>
|
||||
<Version>0.1.2.0</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
@@ -23,7 +24,7 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
|
||||
<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>
|
||||
@@ -36,30 +37,10 @@
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
|
||||
<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" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KKdBaseLib\KKdBaseLib.csproj">
|
||||
<Project>{da55bfd3-927e-473c-a779-f9e6365384ae}</Project>
|
||||
<Name>KKdBaseLib</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\KKdMainLib\KKdMainLib.csproj">
|
||||
<Project>{2BA7EFC6-91D1-8BBC-C487-06C7F36CC789}</Project>
|
||||
<Name>KKdMainLib</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
using System.Reflection;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: AssemblyTitle("KKdSoundLib")]
|
||||
[assembly: AssemblyDescription("A simple library for working with Project Diva F/AFT/F2/X/FT audio files")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("KKdSoundLib")]
|
||||
[assembly: AssemblyCopyright("korenkonder © 2019")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA")]
|
||||
[assembly: AssemblyVersion("0.1.1.0")]
|
||||
[assembly: AssemblyFileVersion("0.1.1.0")]
|
||||
|
||||
+545
-475
File diff suppressed because it is too large
Load Diff
+4
-4
@@ -1,12 +1,12 @@
|
||||
namespace KKdSoundLib
|
||||
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;
|
||||
|
||||
@@ -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>
|
||||
@@ -23,7 +23,7 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
|
||||
<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>
|
||||
@@ -36,10 +36,11 @@
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<LangVersion>8.0</LangVersion>
|
||||
<NoWarn>IDE0004, IDE0044, IDE0045, IDE0046, IDE0055, IDE0059, IDE0069, IDE1006</NoWarn>
|
||||
<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\ADP.cs" />
|
||||
<Compile Include="classes\AET.cs" />
|
||||
<Compile Include="classes\BLT.cs" />
|
||||
<Compile Include="classes\CCT.cs" />
|
||||
@@ -51,8 +52,10 @@
|
||||
<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" />
|
||||
@@ -69,12 +72,11 @@
|
||||
<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>
|
||||
|
||||
+201
-85
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Windows.Forms;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
@@ -18,6 +18,9 @@ namespace PD_Tool
|
||||
{
|
||||
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(); }
|
||||
|
||||
@@ -26,9 +29,10 @@ namespace PD_Tool
|
||||
foreach (string arg in args)
|
||||
{
|
||||
GC.Collect();
|
||||
if (Directory.Exists(arg)) using (KKdFARC FARC = new KKdFARC(arg, true)) FARC.Pack();
|
||||
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);
|
||||
using (KKdFARC farc = new KKdFARC(arg)) farc.Unpack(true);
|
||||
else if (File.Exists(arg))
|
||||
{
|
||||
using (reader = File.OpenReader(arg))
|
||||
@@ -43,22 +47,23 @@ namespace PD_Tool
|
||||
|
||||
private static void MainMenu()
|
||||
{
|
||||
Console. InputEncoding = System.Text.Encoding.Unicode;
|
||||
Console.OutputEncoding = System.Text.Encoding.Unicode;
|
||||
Console.Title = "PD_Tool";
|
||||
Version ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
|
||||
Console.Title = $"PD_Tool v{ver}";
|
||||
Console.Clear();
|
||||
|
||||
ConsoleDesign(true);
|
||||
ConsoleDesign(" Choose action:");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign("1. Extract FARC Archive");
|
||||
ConsoleDesign("2. Create FARC Archive");
|
||||
ConsoleDesign("2. Create FARC Archive");
|
||||
ConsoleDesign("3. Decrypt from DIVAFILE");
|
||||
ConsoleDesign("4. Encrypt to DIVAFILE");
|
||||
ConsoleDesign("4. Encrypt to DIVAFILE");
|
||||
ConsoleDesign("5. DB_Tools");
|
||||
ConsoleDesign("6. AC/DT/F/AFT/FT Converting Tools");
|
||||
ConsoleDesign("7. F/F2/X/FT Converting Tools");
|
||||
ConsoleDesign(json ? "8. MsgPack to JSON" : "9. JSON to MsgPack");
|
||||
ConsoleDesign("6. AC/DT/F/AFT Converting Tools");
|
||||
ConsoleDesign("7. F/F2/FT Converting Tools");
|
||||
ConsoleDesign("8. X/XHD 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");
|
||||
@@ -69,83 +74,178 @@ namespace PD_Tool
|
||||
choose = Console.ReadLine().ToUpper();
|
||||
bool isNumber = int.TryParse(choose, out int result);
|
||||
if (isNumber) Functions();
|
||||
if (choose == "M") json = false;
|
||||
else if (choose == "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 (choose == "1" || choose == "2") FARC.Processor(choose == "1");
|
||||
else if (choose == "3" || choose == "4")
|
||||
if (choose == null || choose == "") return;
|
||||
|
||||
if (choose[0] == '1' || choose[0] == '2') FARC.Processor(choose == "1");
|
||||
else if (choose[0] == '3')
|
||||
{
|
||||
Choose(1, "", out string[] FileNames);
|
||||
foreach (string FileName in FileNames) DIVAFILE.Decrypt(FileName);
|
||||
}
|
||||
else if (choose == "5") DataBase.Processor(json);
|
||||
else if (choose == "6")
|
||||
else if (choose[0] == '4')
|
||||
{
|
||||
Console.Clear();
|
||||
Console.Title = "AC/DT/F/AFT/FT Converting Tools";
|
||||
ConsoleDesign(true);
|
||||
ConsoleDesign(" Choose converter:");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign("1. A3DA" );
|
||||
ConsoleDesign("2. AET" );
|
||||
ConsoleDesign("3. DataBank");
|
||||
ConsoleDesign("4. DEX" );
|
||||
ConsoleDesign("5. DIVA" );
|
||||
ConsoleDesign("6. MotHead" );
|
||||
ConsoleDesign("7. MOT" );
|
||||
ConsoleDesign("8. STR" );
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign("R. Return to Main Menu");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
string localChoose = Console.ReadLine();
|
||||
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") MOT.Processor(json);
|
||||
else if (localChoose == "7") STR.Processor(json);
|
||||
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 == "7")
|
||||
else if (choose[0] == '7')
|
||||
{
|
||||
Console.Clear();
|
||||
Console.Title = "F/F2/X/FT Converting Tools";
|
||||
ConsoleDesign(true);
|
||||
ConsoleDesign(" Choose converter:");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign("1. A3DA" );
|
||||
ConsoleDesign("2. Bloom" );
|
||||
ConsoleDesign("3. Color Correction");
|
||||
ConsoleDesign("4. DEX" );
|
||||
ConsoleDesign("5. DOF" );
|
||||
ConsoleDesign("6. Light" );
|
||||
ConsoleDesign("7. Particles" );
|
||||
ConsoleDesign("8. STR" );
|
||||
ConsoleDesign("9. VAG" );
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign("R. Return to Main Menu");
|
||||
ConsoleDesign(false);
|
||||
ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
string localChoose = Console.ReadLine();
|
||||
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();
|
||||
else if (localChoose == "3") CCT.Processor();
|
||||
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();
|
||||
else if (localChoose == "6") LIT.Processor();
|
||||
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 == "8")
|
||||
else if (choose[0] == '8')
|
||||
{
|
||||
string localChoose = "";
|
||||
if (choose.Length == 1)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.Title = "X/XHD 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. AddParam");
|
||||
ConsoleDesign("3. AET" );
|
||||
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") ADP.Processor(json);
|
||||
else if (localChoose == "3") AET.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] == 'A')
|
||||
{
|
||||
Console.Title = json ? "MsgPack to JSON" : "JSON to MsgPack";
|
||||
Choose(1, json ? "mp" : "json", out string[] fileNames);
|
||||
@@ -153,30 +253,30 @@ namespace PD_Tool
|
||||
if (json)
|
||||
{
|
||||
Console.Title = "MsgPack to JSON: " + Path.GetFileNameWithoutExtension(file);
|
||||
file.Replace(Path.GetExtension(file), "").ToJSON ();
|
||||
Path.RemoveExtension(file).ToJSON ();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Title = "JSON to MsgPack: " + Path.GetFileNameWithoutExtension(file);
|
||||
file.Replace(Path.GetExtension(file), "").ToMsgPack();
|
||||
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 = "█ █";
|
||||
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("████████████████████████████████████████████████████");
|
||||
else Console.WriteLine("█ █");
|
||||
if (Fill) Console.WriteLine("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
|
||||
else Console.WriteLine("X X");
|
||||
}
|
||||
|
||||
private static string GetArgs(string name, bool And, params string[] ext)
|
||||
@@ -201,42 +301,58 @@ namespace PD_Tool
|
||||
|
||||
public static string Choose(int code, string filetype, out string[] FileNames)
|
||||
{
|
||||
string mp = GetArgs("MessagePack", true, "mp" );
|
||||
string json = GetArgs("JSON" , true, "json");
|
||||
string bin = GetArgs("BIN" , true, "bin" );
|
||||
string wav = GetArgs("WAV" , true, "wav" );
|
||||
|
||||
FileNames = new string[0];
|
||||
if (code == 1)
|
||||
{
|
||||
string Filter = GetArgs("All;", false, "*");
|
||||
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 == "adp" ) Filter = GetArgs("ADP" , "adp", "json", "mp") +
|
||||
GetArgs("ADP", true, "adp" ) + json + mp;
|
||||
else if (filetype == "bin" ) Filter = GetArgs("BIN" , "bin", "json", "mp") +
|
||||
bin + json + mp;
|
||||
else if (filetype == "blt" ) Filter = GetArgs("BLT" , "blt");
|
||||
else if (filetype == "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");
|
||||
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");
|
||||
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 == "farc") Filter = "FARC Archives (*.farc)|*.farc";
|
||||
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 == "mp" ) Filter = GetArgs("MessagePack", "mp");
|
||||
else if (filetype == "lit") Filter = GetArgs("LIT" , "lit");
|
||||
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 { InitialDirectory = Application.StartupPath,
|
||||
Filter = Filter, Multiselect = true, Title = "Choose file(s) to open:" })
|
||||
if (ofd.ShowDialog() == DialogResult.OK) FileNames = ofd.FileNames;
|
||||
|
||||
using OpenFileDialog ofd = new OpenFileDialog { InitialDirectory = Application.StartupPath,
|
||||
Filter = Filter, Multiselect = true, Title = "Choose file(s) to open:" };
|
||||
if (ofd.ShowDialog() == DialogResult.OK) FileNames = ofd.FileNames;
|
||||
}
|
||||
else if (code == 2)
|
||||
{
|
||||
|
||||
@@ -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 AC/DT/F/AFT/F2/X/FT files")]
|
||||
[assembly: AssemblyDescription("A simple tool for working with Project Diva AC/DT/F/AFT/F2/X/FT/M39 files")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("PD_Tool")]
|
||||
[assembly: AssemblyCopyright("korenkonder © 2017-2019")]
|
||||
[assembly: AssemblyCopyright("korenkonder (C) 2017-2021")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
|
||||
[assembly: AssemblyVersion("0.4.8.0")]
|
||||
[assembly: AssemblyFileVersion("0.4.8.0")]
|
||||
[assembly: AssemblyVersion("0.4.10.2")]
|
||||
[assembly: AssemblyFileVersion("0.4.10.2")]
|
||||
|
||||
+72
-63
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdA3DA = KKdMainLib.A3DA;
|
||||
@@ -20,96 +20,103 @@ namespace PD_Tool
|
||||
|
||||
Format format = Format.NULL;
|
||||
string choose = "";
|
||||
if (mp)
|
||||
{
|
||||
Console.Clear();
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of format to export:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. A3DA [DT/AC/F]");
|
||||
Program.ConsoleDesign("2. A3DC [DT/AC/F]");
|
||||
Program.ConsoleDesign("3. A3DA [AFT/FT] ");
|
||||
Program.ConsoleDesign("4. A3DC [AFT/FT] ");
|
||||
Program.ConsoleDesign("5. A3DC [F2] ");
|
||||
Program.ConsoleDesign("6. A3DC [MGF] ");
|
||||
Program.ConsoleDesign("7. A3DC [X] ");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
choose = Console.ReadLine();
|
||||
if (choose == "1") format = Format.DT ;
|
||||
else if (choose == "2") format = Format.F ;
|
||||
else if (choose == "3") format = Format.AFT ;
|
||||
else if (choose == "4") format = Format.AFT ;
|
||||
else if (choose == "5") format = Format.F2LE;
|
||||
else if (choose == "6") format = Format.MGF ;
|
||||
else if (choose == "7") format = Format.X ;
|
||||
else return;
|
||||
}
|
||||
Console.Clear();
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of format to export:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. A3DA [DT/AC/F]");
|
||||
Program.ConsoleDesign("2. A3DC [DT/AC/F]");
|
||||
Program.ConsoleDesign("3. A3DA [AFT/FT/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]");
|
||||
if (!mp) Program.ConsoleDesign($"9. {(json ? "JSON" : "MsgPack")}");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
choose = Console.ReadLine().ToUpper();
|
||||
if (choose == "1") format = Format.DT ;
|
||||
else if (choose == "2") format = Format.F ;
|
||||
else if (choose == "3") format = Format.AFT;
|
||||
else if (choose == "4") format = Format.AFT;
|
||||
else if (choose == "5") format = Format.F2;
|
||||
else if (choose == "6") format = Format.MGF;
|
||||
else if (choose == "7") format = Format.X ;
|
||||
else if (choose == "8") format = Format.XHD;
|
||||
else if (choose == "9") format = Format.NULL;
|
||||
else return;
|
||||
|
||||
int state;
|
||||
string filepath, ext;
|
||||
KKdA3DA a3da;
|
||||
KKdFARC farc;
|
||||
foreach (string file in fileNames)
|
||||
{
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "A3DA Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".farc")
|
||||
using (KKdFARC farc = new KKdFARC(file))
|
||||
using (farc = new KKdFARC(file))
|
||||
FARCProcessor(farc, choose, format);
|
||||
else if (ext == ".a3da")
|
||||
using (a3da = new KKdA3DA(true))
|
||||
using (a3da = new KKdA3DA())
|
||||
{
|
||||
state = a3da.A3DAReader(filepath);
|
||||
if (state == 1) a3da.MsgPackWriter(filepath, json);
|
||||
if (state == 1)
|
||||
if (choose == "9") a3da.MsgPackWriter(filepath, json);
|
||||
else
|
||||
{
|
||||
a3da.Head.Format = format;
|
||||
File.WriteAllBytes(filepath + ".a3da", (choose == "1" ||
|
||||
choose == "3") ? a3da.A3DAWriter() : a3da.A3DCWriter());
|
||||
}
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
using (a3da = new KKdA3DA(true))
|
||||
using (a3da = new KKdA3DA())
|
||||
{
|
||||
a3da.MsgPackReader(filepath, ext == ".json");
|
||||
a3da.Data._.CompressF16 = format > Format.AFT && format <
|
||||
Format.FT ? format == Format.MGF ? 2 : 1 : 0;
|
||||
a3da.Head.Format = format;
|
||||
|
||||
File.WriteAllBytes(filepath + ".a3da", (choose != "1" &&
|
||||
choose != "3") ? a3da.A3DCWriter() : a3da.A3DAWriter());
|
||||
File.WriteAllBytes(filepath + ".a3da", (choose == "1" ||
|
||||
choose == "3") ? a3da.A3DAWriter() : a3da.A3DCWriter());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void FARCProcessor(KKdFARC farc, string choose, Format format)
|
||||
{
|
||||
if (!farc.HeaderReader()) return;
|
||||
if (!farc.HasFiles) return;
|
||||
|
||||
if (!farc.HeaderReader() || !farc.HasFiles) return;
|
||||
|
||||
KKdList<string> list = KKdList<string>.New;
|
||||
for (int i = 0; i < farc.Files.Length; i++)
|
||||
if (!farc.Files[i].Name.Contains("div") && farc.Files[i].Name.EndsWith(".a3da"))
|
||||
list.Add(farc.Files[i].Name);
|
||||
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.Length; i++)
|
||||
if (farc.Files[i].Name.EndsWith(".a3da"))
|
||||
for (int i = 0; i < farc.Files.Count; i++)
|
||||
if (farc.Files[i].Name.ToLower().EndsWith(".a3da"))
|
||||
A3DAlist.Add(farc.Files[i].Name);
|
||||
|
||||
byte[] data = null;
|
||||
if (list.Count == A3DAlist.Count || (format > Format.AFT && format < Format.FT))
|
||||
if (list.Count == A3DAlist.Count)
|
||||
{
|
||||
KKdA3DA a3da;
|
||||
for (int i = 0; i < A3DAlist.Count; i++)
|
||||
using (a3da = new KKdA3DA(true))
|
||||
using (a3da = new KKdA3DA())
|
||||
{
|
||||
data = farc.FileReader(A3DAlist[i]);
|
||||
int state = a3da.A3DAReader(data);
|
||||
if (state == 1)
|
||||
{
|
||||
a3da.Data._.CompressF16 = format > Format.AFT && format <
|
||||
Format.FT ? format == Format.MGF ? 2 : 1 : 0;
|
||||
KKdFARC.FARCFile file = farc.Files[i];
|
||||
a3da.Head.Format = format;
|
||||
farc.Files[i].Data = (choose != "1" && choose != "3") ? a3da.A3DCWriter() : a3da.A3DAWriter();
|
||||
file.Data = (choose == "1"|| choose == "3") ? a3da.A3DAWriter() : a3da.A3DCWriter();
|
||||
farc.Files[i] = file;
|
||||
}
|
||||
}
|
||||
farc.Save();
|
||||
@@ -117,12 +124,12 @@ namespace PD_Tool
|
||||
}
|
||||
|
||||
KKdA3DA[] a3daArray;
|
||||
using (KKdList<KKdA3DA> a3daList = KKdList<KKdA3DA>.New)
|
||||
using (KKdList<KKdA3DA> a3daList = KKdList<KKdA3DA>.NewReserve(list.Count))
|
||||
{
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
KKdA3DA a3da;
|
||||
using (a3da = new KKdA3DA(true))
|
||||
using (a3da = new KKdA3DA())
|
||||
{
|
||||
data = farc.FileReader(list[i]);
|
||||
int state = a3da.A3DAReader(data);
|
||||
@@ -135,13 +142,14 @@ namespace PD_Tool
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
if (a3daArray[i].Data.PlayControl.Div == null) continue;
|
||||
float Div = a3daArray[i].Data.PlayControl.Div.Value;
|
||||
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(true))
|
||||
for (int i1 = 1; i1 < div; i1++)
|
||||
using (a3da = new KKdA3DA())
|
||||
{
|
||||
string file = Path.GetFileNameWithoutExtension(list[i]) +
|
||||
"_div_" + i1 + Path.GetExtension(list[i]);
|
||||
string file = filename + "_div_" + i1 + ext;
|
||||
data = farc.FileReader(file);
|
||||
int state = a3da.A3DAReader(data);
|
||||
if (state == 1) a3daArray[i].A3DAMerger(ref a3da.Data);
|
||||
@@ -149,14 +157,15 @@ namespace PD_Tool
|
||||
a3daArray[i].Data.PlayControl.Div = null;
|
||||
}
|
||||
|
||||
farc.Files = new KKdFARC.FARCFile[list.Count];
|
||||
farc.Files.Capacity = 0;
|
||||
farc.Files.Capacity = list.Count;
|
||||
for (int i = 0; i < list.Count; i++)
|
||||
{
|
||||
farc.Files[i].Name = list[i];
|
||||
a3daArray[i].Data._.CompressF16 = format > Format.AFT && format <
|
||||
Format.FT ? format == Format.MGF ? 2 : 1 : 0;
|
||||
KKdFARC.FARCFile file = default;
|
||||
file.Name = list[i];
|
||||
a3daArray[i].Head.Format = format;
|
||||
farc.Files[i].Data = (choose != "1" && choose != "3") ? a3daArray[i].A3DCWriter() : a3daArray[i].A3DAWriter();
|
||||
file.Data = (choose == "1" || choose == "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 ADP
|
||||
{
|
||||
public static void Processor(bool json)
|
||||
{
|
||||
Console.Title = "Add Param Converter";
|
||||
Program.Choose(1, "adp", out string[] fileNames);
|
||||
if (fileNames.Length < 1) return;
|
||||
|
||||
string filepath, ext;
|
||||
AddParam adp;
|
||||
foreach (string file in fileNames)
|
||||
using (adp = new AddParam())
|
||||
{
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "Add Param Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".adp")
|
||||
{
|
||||
adp.AddParamReader(filepath);
|
||||
adp. MsgPackWriter(filepath, json);
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
{
|
||||
adp. MsgPackReader(filepath, ext == ".json");
|
||||
adp.AddParamWriter(filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdAet = KKdMainLib.Aet.Aet;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
@@ -13,13 +13,12 @@ namespace PD_Tool
|
||||
if (fileNames.Length < 1) return;
|
||||
|
||||
string filepath, ext;
|
||||
KKdAet aet;
|
||||
Aet aet;
|
||||
foreach (string file in fileNames)
|
||||
using (aet = new KKdAet())
|
||||
using (aet = new Aet())
|
||||
{
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "AET Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".bin")
|
||||
|
||||
+37
-7
@@ -1,28 +1,58 @@
|
||||
using System;
|
||||
using KKdMainLib.IO;
|
||||
using System;
|
||||
using KKdMainLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
public class BLT
|
||||
{
|
||||
public static void Processor()
|
||||
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())
|
||||
{
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "Bloom Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".blt") { blt.BLTReader(filepath); blt.TXTWriter(filepath); }
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+37
-7
@@ -1,28 +1,58 @@
|
||||
using System;
|
||||
using KKdMainLib.IO;
|
||||
using System;
|
||||
using KKdMainLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
public class CCT
|
||||
{
|
||||
public static void Processor()
|
||||
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())
|
||||
{
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "Color Correction Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".cct") { cct.CCTReader(filepath); cct.TXTWriter(filepath); }
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-22
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace PD_Tool
|
||||
@@ -16,30 +16,14 @@ namespace PD_Tool
|
||||
if (file.EndsWith(".mp" )) { mp = false; break; }
|
||||
else if (file.EndsWith(".json")) { mp = false; break; }
|
||||
|
||||
string choose = "1";
|
||||
if (mp)
|
||||
{
|
||||
Console.Clear();
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of exporting file:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. Compact");
|
||||
Program.ConsoleDesign("2. Normal");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
choose = Console.ReadLine();
|
||||
}
|
||||
|
||||
uint num2 = (uint)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
|
||||
uint num2 = (uint)((DateTime.Now.Ticks - 621355968000000000) / 10000000);
|
||||
string[] file_split;
|
||||
string filepath, ext;
|
||||
KKdMainLib.DataBank db;
|
||||
foreach (string file in fileNames)
|
||||
{
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
string filename = Path.GetFileNameWithoutExtension(file);
|
||||
file_split = filename.Split('_');
|
||||
@@ -50,8 +34,15 @@ namespace PD_Tool
|
||||
filepath = file.Replace(filename + ".dat", "");
|
||||
Console.Title = "DataBank Converter: " + filename;
|
||||
db. DBReader(file);
|
||||
db.MsgPackWriter(filepath + file_split[0] + "_" +
|
||||
file_split[1] + "_" + file_split[2], json, choose != "2");
|
||||
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)
|
||||
{
|
||||
|
||||
+20
-21
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdDEX = KKdMainLib.DEX;
|
||||
@@ -12,7 +12,7 @@ namespace PD_Tool
|
||||
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)
|
||||
@@ -24,38 +24,37 @@ namespace PD_Tool
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of exporting file:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. F/FT PS3/PS4/PSVita");
|
||||
Program.ConsoleDesign("2. F2 PS3/PSVita");
|
||||
Program.ConsoleDesign("3. X PS4/PSVita");
|
||||
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();
|
||||
|
||||
choose = Console.ReadLine().ToUpper();
|
||||
|
||||
Format format = Format.NULL;
|
||||
if (choose == "1") format = Format.F ;
|
||||
else if (choose == "2") format = Format.F2LE;
|
||||
else if (choose == "3") format = Format.X ;
|
||||
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;
|
||||
KKdDEX dex;
|
||||
foreach (string file in fileNames)
|
||||
using (DEX = new KKdDEX())
|
||||
using (dex = new KKdDEX())
|
||||
{
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+37
-7
@@ -1,28 +1,58 @@
|
||||
using System;
|
||||
using KKdMainLib.IO;
|
||||
using System;
|
||||
using KKdMainLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
public class DFT
|
||||
{
|
||||
public static void Processor()
|
||||
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())
|
||||
{
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "DOF Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".dft") { dft.DFTReader(filepath); dft.TXTWriter(filepath); }
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System;
|
||||
using KKdMainLib.IO;
|
||||
using KKdSoundLib;
|
||||
|
||||
namespace PD_Tool
|
||||
@@ -17,9 +17,8 @@ namespace PD_Tool
|
||||
foreach (string file in fileNames)
|
||||
{
|
||||
diva = new DIVA();
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "DIVA Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".diva") diva.DIVAReader(filepath);
|
||||
@@ -28,4 +27,4 @@ namespace PD_Tool
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using KKdMainLib;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace PD_Tool
|
||||
@@ -8,9 +8,10 @@ namespace PD_Tool
|
||||
public static void Decrypt(string file)
|
||||
{
|
||||
Stream reader = File.OpenReader(file);
|
||||
if (reader.RI64() != 0x454C494641564944) { reader.C(); return; }
|
||||
ulong head = reader.RU64();
|
||||
reader.C();
|
||||
|
||||
if (head != 0x454C494641564944) return;
|
||||
System.Console.Title = "DIVAFILE Decrypt: " + Path.GetFileName(file);
|
||||
file.Decrypt();
|
||||
}
|
||||
@@ -18,9 +19,10 @@ namespace PD_Tool
|
||||
public static void Encrypt(string file)
|
||||
{
|
||||
Stream reader = File.OpenReader(file);
|
||||
if (reader.RI64() == 0x454C494641564944) { reader.C(); return; }
|
||||
ulong head = reader.RU64();
|
||||
reader.C();
|
||||
|
||||
if (head == 0x454C494641564944) return;
|
||||
System.Console.Title = "DIVAFILE Encrypt: " + Path.GetFileName(file);
|
||||
file.Encrypt();
|
||||
}
|
||||
|
||||
+29
-27
@@ -1,32 +1,34 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Aet = KKdMainLib.DB.Aet;
|
||||
using Auth = KKdMainLib.DB.Auth;
|
||||
using Spr = KKdMainLib.DB.Spr;
|
||||
using System;
|
||||
using KKdMainLib.DB;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
public class DataBase
|
||||
{
|
||||
public static void Processor(bool json)
|
||||
public static void Processor(bool json, char choose)
|
||||
{
|
||||
Console.Title = "DB Converter";
|
||||
Console.Clear();
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of DataBase file:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. Auth DB Converter");
|
||||
Program.ConsoleDesign("2. AET DB Converter");
|
||||
Program.ConsoleDesign("3. SPR DB Converter");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("R. Return to Main Menu");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
string format = Console.ReadLine();
|
||||
if (format == "1") AuthDBProcessor(json);
|
||||
if (format == "2") AETDBProcessor(json);
|
||||
if (format == "3") SPRDBProcessor(json);
|
||||
if (choose == '\0')
|
||||
{
|
||||
Console.Title = "DB Converter";
|
||||
Console.Clear();
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of DataBase file:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. Auth DB Converter");
|
||||
Program.ConsoleDesign("2. AET DB Converter");
|
||||
Program.ConsoleDesign("3. SPR DB Converter");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("R. Return to Main Menu");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
string format = Console.ReadLine().ToUpper();
|
||||
if (format.Length > 0) choose = format[0];
|
||||
}
|
||||
if (choose == '1') AuthDBProcessor(json);
|
||||
if (choose == '2') AETDBProcessor(json);
|
||||
if (choose == '3') SPRDBProcessor(json);
|
||||
}
|
||||
|
||||
public static void AuthDBProcessor(bool JSON)
|
||||
@@ -41,8 +43,8 @@ namespace PD_Tool
|
||||
using (auth = new Auth())
|
||||
{
|
||||
Console.Title = "Auth DB Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
filepath = file.Replace(Path.GetExtension(file), "");
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
if (ext == ".bin")
|
||||
{
|
||||
@@ -69,8 +71,8 @@ namespace PD_Tool
|
||||
using (aet = new Aet())
|
||||
{
|
||||
Console.Title = "AET DB Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
filepath = file.Replace(Path.GetExtension(file), "");
|
||||
|
||||
if (ext == ".bin")
|
||||
{
|
||||
@@ -97,8 +99,8 @@ namespace PD_Tool
|
||||
using (spr = new Spr())
|
||||
{
|
||||
Console.Title = "SPR DB Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
filepath = file.Replace(Path.GetExtension(file), "");
|
||||
|
||||
if (ext == ".bin")
|
||||
{
|
||||
|
||||
+12
-12
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System;
|
||||
using KKdMainLib.IO;
|
||||
using KKdFARC = KKdMainLib.FARC;
|
||||
|
||||
namespace PD_Tool
|
||||
@@ -18,25 +18,25 @@ namespace PD_Tool
|
||||
{
|
||||
Console.Title = "FARC Extractor: " + Path.GetFileNameWithoutExtension(fileExtract);
|
||||
using (KKdFARC farc = new KKdFARC(fileExtract))
|
||||
farc.UnPack();
|
||||
farc.Unpack();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
string file = Program.Choose(2, "", out string[] fileNames);
|
||||
Console.Clear();
|
||||
if (file == null || file == "") return;
|
||||
Console.Title = "FARC Creator";
|
||||
|
||||
|
||||
using (KKdFARC farc = new KKdFARC(file, true))
|
||||
{
|
||||
Console.Title = "FARC Creator: " + Path.GetDirectoryName(file);
|
||||
|
||||
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of created FARC:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. FArc [DT/DT2/DTex/F/F2/X]");
|
||||
Program.ConsoleDesign("2. FArC [DT/DT2/DTex/F/F2/X] (Compressed)");
|
||||
Program.ConsoleDesign("1. FArc (Uncompressed)");
|
||||
Program.ConsoleDesign("2. FArC (Compressed)");
|
||||
Program.ConsoleDesign("3. FARC [F/F2/X]");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("R. Return to Main Menu");
|
||||
@@ -50,8 +50,8 @@ namespace PD_Tool
|
||||
else if (choose == "3" || choose == "4")
|
||||
{
|
||||
farc.Signature = KKdFARC.Farc.FARC;
|
||||
|
||||
Console.WriteLine();
|
||||
|
||||
Console.Clear();
|
||||
Program.ConsoleDesign(true);
|
||||
Program.ConsoleDesign(" Choose type of FARC:");
|
||||
Program.ConsoleDesign(false);
|
||||
@@ -62,9 +62,9 @@ namespace PD_Tool
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
choose = Console.ReadLine();
|
||||
choose = Console.ReadLine().ToUpper();
|
||||
if (choose == "2" || choose == "4") farc.FARCType |= KKdFARC.Type.GZip;
|
||||
if (choose == "3" || choose == "4") farc.FARCType |= KKdFARC.Type.ECB ;
|
||||
if (choose == "3" || choose == "4") farc.FARCType |= KKdFARC.Type.Enc ;
|
||||
}
|
||||
else if (choose == "R") return;
|
||||
else farc.Signature = KKdFARC.Farc.FArC;
|
||||
|
||||
+36
-6
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using KKdMainLib.IO;
|
||||
using KKdMainLib.F2;
|
||||
|
||||
@@ -6,23 +6,53 @@ namespace PD_Tool
|
||||
{
|
||||
public class LIT
|
||||
{
|
||||
public static void Processor()
|
||||
public static void Processor(bool json)
|
||||
{
|
||||
Console.Title = "Light Converter";
|
||||
Program.Choose(1, "lit", out string[] fileNames);
|
||||
if (fileNames.Length < 1) return;
|
||||
|
||||
bool bloom = false;
|
||||
foreach (string file in fileNames)
|
||||
if (file.EndsWith(".lit")) { 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;
|
||||
Light lit;
|
||||
foreach (string file in fileNames)
|
||||
using (lit = new Light())
|
||||
{
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "Light Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".lit") { lit.LITReader(filepath); lit.TXTWriter(filepath); }
|
||||
if (ext == ".lit")
|
||||
{
|
||||
lit.LITReader(filepath);
|
||||
if (choose == "2" && !lit.IsX)
|
||||
lit.TXTWriter(filepath);
|
||||
else
|
||||
lit.MsgPackWriter(filepath, json);
|
||||
}
|
||||
else if (ext == ".json" || ext == ".mp")
|
||||
{
|
||||
lit.MsgPackReader(filepath, json);
|
||||
lit.LITWriter(filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
public class MHD
|
||||
{
|
||||
public static void Processor(bool json)
|
||||
{
|
||||
Console.Title = "MotHead Converter";
|
||||
Program.Choose(1, "bin", out string[] fileNames);
|
||||
if (fileNames.Length < 1) return;
|
||||
|
||||
string filepath, ext;
|
||||
MotHead mhd;
|
||||
foreach (string file in fileNames)
|
||||
using (mhd = new MotHead())
|
||||
{
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "MotHead Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".bin")
|
||||
{
|
||||
mhd.MotHeadReader(filepath);
|
||||
mhd.MsgPackWriter(filepath, json);
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
{
|
||||
mhd.MsgPackReader(filepath, ext == ".json");
|
||||
mhd.MotHeadWriter(filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+90
-19
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
|
||||
@@ -11,29 +11,100 @@ namespace PD_Tool
|
||||
Console.Title = "MOT Converter";
|
||||
Program.Choose(1, "bin", out string[] fileNames);
|
||||
if (fileNames.Length < 1) return;
|
||||
|
||||
|
||||
string filepath, ext;
|
||||
Mot mot;
|
||||
foreach (string file in fileNames)
|
||||
{
|
||||
mot = new Mot();
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
using (mot = new Mot())
|
||||
{
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
|
||||
Console.Title = "MOT Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".bin")
|
||||
{
|
||||
mot. MOTReader(filepath);
|
||||
mot.MsgPackWriter(filepath, json);
|
||||
Console.Title = "MOT Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".bin")
|
||||
{
|
||||
/*KKdBaseLib.KKdDict<int, int> a = KKdBaseLib.KKdDict<int, int>.New;
|
||||
while (true)
|
||||
{
|
||||
string b = Console.ReadLine();
|
||||
if (b == "") break;
|
||||
string[] c = b.Split(' ');
|
||||
if (c.Length == 2)
|
||||
a.Add(int.Parse(c[0]), int.Parse(c[1]));
|
||||
}
|
||||
a.Add(0, 1);
|
||||
a.Add(1648, 3);
|
||||
a.Add(2139, 2);
|
||||
a.Add(5416, 4);
|
||||
a.Add(6589, 5);
|
||||
a.Add(7783, 1);
|
||||
mot.MOTReader(filepath);
|
||||
|
||||
Mot.KeySet[] oks = mot.MOT[1].KeySet.V;
|
||||
Mot.MotHeader mh = mot.MOT[1];
|
||||
mh.KeySet.V = new Mot.KeySet[mh.KeySet.V.Length];
|
||||
Mot.KeySet[] ok = mh.KeySet.V;
|
||||
for (int i = 0; i < mh.KeySet.V.Length; i++)
|
||||
{
|
||||
KKdBaseLib.Interpolation.PDI[] pdi = new KKdBaseLib.Interpolation.PDI[mot.MOT.Length];
|
||||
for (int h = 0; h < mot.MOT.Length; h++)
|
||||
pdi[h] = new KKdBaseLib.Interpolation.PDI(mot.MOT[h].KeySet.V[i].Keys);
|
||||
|
||||
KKdBaseLib.KKdList<KKdBaseLib.KFT2> kf = KKdBaseLib.KKdList<KKdBaseLib.KFT2>.New;
|
||||
|
||||
bool old = false;
|
||||
KKdBaseLib.KFT2 v = default;
|
||||
KKdBaseLib.KFT2 ov = default;
|
||||
int k = -1;
|
||||
for (int h = 0; h < mh.FrameCount; h++)
|
||||
{
|
||||
if (a.ContainsKey(h))
|
||||
k = a[h];
|
||||
else if (k == -1) continue;
|
||||
|
||||
ref KKdBaseLib.Interpolation.PDI pdil = ref pdi[k];
|
||||
|
||||
v.F = h;
|
||||
v.V = pdil.SetFrame(h);
|
||||
if (h == 0 || ov.V != v.V)
|
||||
{
|
||||
if (old) { old = false; kf.Add(ov); }
|
||||
kf.Add(v);
|
||||
}
|
||||
else old = true;
|
||||
ov = v;
|
||||
}
|
||||
kf.Capacity = kf.Count;
|
||||
ok[i].Keys = kf.ToArray();
|
||||
ok[i].Type = Mot.KeySetType.Linear;
|
||||
|
||||
for (int h = 0; h < mot.MOT.Length; h++)
|
||||
pdi[h] = default;
|
||||
}
|
||||
for (int i = 0; i < mh.KeySet.V.Length; i++)
|
||||
{
|
||||
if (ok[i].Keys.Length != 1) continue;
|
||||
|
||||
if (ok[i].Keys[0].V == 0)
|
||||
{
|
||||
ok[i].Keys[0].F = 0;
|
||||
ok[i].Type = Mot.KeySetType.None;
|
||||
}
|
||||
else ok[i].Type = Mot.KeySetType.Static;
|
||||
}
|
||||
mot.MOT[1].KeySet.V = ok;
|
||||
Array.Resize(ref mot.MOT, 2);
|
||||
mot.MOTWriter(filepath + "_mod");*/
|
||||
mot. MOTReader(filepath);
|
||||
mot.MsgPackWriter(filepath, json);
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
{
|
||||
mot.MsgPackReader(filepath, ext == ".json");
|
||||
mot. MOTWriter(filepath);
|
||||
}
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
{
|
||||
mot.MsgPackReader(filepath, ext == ".json");
|
||||
mot. MOTWriter(filepath);
|
||||
}
|
||||
mot = new Mot();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using KKdMainLib.IO;
|
||||
using KKdSTR = KKdMainLib.STR;
|
||||
|
||||
@@ -16,15 +16,13 @@ namespace PD_Tool
|
||||
foreach (string file in fileNames)
|
||||
using (str = new KKdSTR())
|
||||
{
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "PD_Tool: Converter Tools: STR Reader: " +
|
||||
Path.GetFileNameWithoutExtension(file);
|
||||
Console.Title = "STR Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".str" || ext == ".bin")
|
||||
{
|
||||
str.STRReader (filepath, ext);
|
||||
str.STRReader (filepath, ext);
|
||||
str.MsgPackWriter(filepath, json);
|
||||
}
|
||||
else if (ext == ".json" || ext == ".mp")
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib;
|
||||
using KKdMainLib.IO;
|
||||
using KKdFARC = KKdMainLib.FARC;
|
||||
|
||||
namespace PD_Tool
|
||||
{
|
||||
public class TBL
|
||||
{
|
||||
public static void Processor(bool json)
|
||||
{
|
||||
Console.Title = "Table Converter";
|
||||
Program.Choose(1, "tbl", out string[] fileNames);
|
||||
if (fileNames.Length < 1) return;
|
||||
|
||||
string filepath, ext;
|
||||
Tables tbl;
|
||||
foreach (string file in fileNames)
|
||||
using (tbl = new Tables())
|
||||
{
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "Table Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".bin")
|
||||
{
|
||||
tbl.BINReader (filepath);
|
||||
tbl.MsgPackWriter(filepath, json);
|
||||
}
|
||||
else if (ext == ".farc")
|
||||
using (KKdFARC farc = new KKdFARC(file))
|
||||
FARCProcessor(ref tbl, farc, filepath, json);
|
||||
else if (ext == ".json" || ext == ".mp")
|
||||
{
|
||||
tbl.MsgPackReader(filepath, ext == ".json");
|
||||
tbl.BINWriter (filepath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void FARCProcessor(ref Tables tbl, KKdFARC farc, string filepath, bool json)
|
||||
{
|
||||
if (!farc.HeaderReader()) return;
|
||||
if (!farc.HasFiles) return;
|
||||
|
||||
int file = -1;
|
||||
KKdList<string> list = KKdList<string>.New;
|
||||
for (int i = 0; i < farc.Files.Count; i++)
|
||||
if (farc.Files[i].Name.ToLower().EndsWith(".bin")) { file = i; break; }
|
||||
if (file == -1) return;
|
||||
|
||||
farc.Unpack(false);
|
||||
tbl.BINReader (farc.Files[file].Data);
|
||||
tbl.MsgPackWriter(filepath.Replace(Path.GetFileName(filepath),
|
||||
Path.GetFileNameWithoutExtension(farc.Files[file].Name)), json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System;
|
||||
using KKdMainLib.IO;
|
||||
using KKdVAG = KKdSoundLib.VAG;
|
||||
|
||||
namespace PD_Tool
|
||||
@@ -25,15 +25,16 @@ namespace PD_Tool
|
||||
Program.ConsoleDesign(" Choose type of format to export:");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("1. VAG (Downmix to 1 ch)");
|
||||
Program.ConsoleDesign("2. HEVAG [Fastest]");
|
||||
Program.ConsoleDesign("2. HEVAG [Fastest] (Multichannel VAG)");
|
||||
Program.ConsoleDesign("3. HEVAG [Fast]");
|
||||
Program.ConsoleDesign("4. HEVAG [Medium]");
|
||||
Program.ConsoleDesign("5. HEVAG [Slow]");
|
||||
Program.ConsoleDesign("6. HEVAG [Slowest]");
|
||||
Program.ConsoleDesign("7. HEVAG [Slow as hell] (Full HEVAG)");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
choose = Console.ReadLine();
|
||||
choose = Console.ReadLine().ToUpper();
|
||||
}
|
||||
|
||||
string filepath, ext;
|
||||
@@ -41,9 +42,8 @@ namespace PD_Tool
|
||||
foreach (string file in fileNames)
|
||||
using (VAG = new KKdVAG())
|
||||
{
|
||||
ext = Path.GetExtension(file);
|
||||
filepath = file.Replace(ext, "");
|
||||
ext = ext.ToLower();
|
||||
filepath = Path.RemoveExtension(file);
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "VAG Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".vag") { VAG.VAGReader(filepath); VAG.WAVWriter(filepath ); }
|
||||
@@ -51,4 +51,4 @@ namespace PD_Tool
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,46 @@
|
||||
# PD_Tool
|
||||
A simple tool for working with Project Diva DT/FT/F/F2/X files
|
||||
A simple tool for working with Project Diva AC/DT/F/AFT/F2/X/FT/M39 files
|
||||
|
||||
# Dependencies:
|
||||
+ `.NET Framework 4.6.1`: Required to run/build PD_Tool C# project.
|
||||
+ `.NET Framework 4.6.1`: Required to build KKdBaseLib, KKdMainLib and KKdSoundLib C# projects and to run/build PD_Tool C# project.
|
||||
|
||||
# Tools:
|
||||
- `FARC Extract/Create`
|
||||
- `DIVAFILE Encrypt/Decrypt`
|
||||
- `DIVAFILE Decrypt/Encrypt`
|
||||
- `DB_Tools`
|
||||
- `Aet DB Converter`
|
||||
- `Auth DB Converter`
|
||||
- `Spr DB Converter`
|
||||
- `Converting Tools`
|
||||
- `AC/DT/F/AFT Converting Tools`
|
||||
- `A3DA Converter`
|
||||
- `AET Converter`
|
||||
- `DataBank Converter`
|
||||
- `DEX Converter`
|
||||
- `DIVA Converter`
|
||||
- `MotHead Converter`
|
||||
- `MOT Converter`
|
||||
- `STR Converter`
|
||||
- `Table Converter`
|
||||
- `F/F2/FT Converting Tools`
|
||||
- `A3DA Converter`
|
||||
- `Bloom Converter`
|
||||
- `Color Correction Converter`
|
||||
- `DEX Converter`
|
||||
- `DOF Converter`
|
||||
- `Light Converter`
|
||||
- `STR Converter`
|
||||
- `VAG Converter`
|
||||
|
||||
- `X/XHD Converting Tools`
|
||||
- `A3DA Converter`
|
||||
- `DEX Converter`
|
||||
- `VAG Converter`
|
||||
- `FT/M39 Converting Tools`
|
||||
- `A3DA Converter`
|
||||
- `AddParam Converter`
|
||||
- `AET Converter`
|
||||
- `DEX Converter`
|
||||
- `DIVA Converter`
|
||||
- `MotHead Converter`
|
||||
- `MOT Converter`
|
||||
- `STR Converter`
|
||||
- `Table Converter`
|
||||
|
||||
Reference in New Issue
Block a user