Compare commits
12
Commits
v0.4.10.10
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
797d0f9467 | ||
|
|
8b46fbbe03 | ||
|
|
b66b3b01d0 | ||
|
|
3c13856667 | ||
|
|
00d25ff67b | ||
|
|
a1c18941a1 | ||
|
|
c95a116297 | ||
|
|
139fbf307f | ||
|
|
1d5c88f39f | ||
|
|
786dca23fd | ||
|
|
7046e3cfc2 | ||
|
|
ec5f8c803e |
+18
-1
@@ -16,12 +16,29 @@ namespace KKdBaseLib.Auth2D
|
||||
public uint BackColor;
|
||||
public uint Width;
|
||||
public uint Height;
|
||||
public Pointer<Vec2<CountPointer<KFT2>>> Camera;
|
||||
public Pointer<Camera> Camera;
|
||||
public CountPointer<Composition> Composition;
|
||||
public CountPointer<Video > Video;
|
||||
public CountPointer<Audio > Audio;
|
||||
}
|
||||
|
||||
public struct Camera
|
||||
{
|
||||
public CountPointer<KFT2> EyeX;
|
||||
public CountPointer<KFT2> EyeY;
|
||||
public CountPointer<KFT2> EyeZ;
|
||||
public CountPointer<KFT2> PositionX;
|
||||
public CountPointer<KFT2> PositionY;
|
||||
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> RotationZ;
|
||||
public CountPointer<KFT2> Zoom ;
|
||||
}
|
||||
|
||||
public struct Composition
|
||||
{
|
||||
public int P;
|
||||
|
||||
@@ -142,6 +142,9 @@ namespace KKdBaseLib.Auth3D
|
||||
public float? Max;
|
||||
public float Value;
|
||||
public bool RawData;
|
||||
public bool RawDataBinary;
|
||||
public int? RawDataValueListSize;
|
||||
public int? RawDataValueListOffset;
|
||||
public KFT3[] Keys;
|
||||
|
||||
public Key(A3DAKey k)
|
||||
@@ -150,6 +153,9 @@ namespace KKdBaseLib.Auth3D
|
||||
Value = 0;
|
||||
BinOffset = null;
|
||||
RawData = default;
|
||||
RawDataBinary = default;
|
||||
RawDataValueListSize = null;
|
||||
RawDataValueListOffset = null;
|
||||
Keys = null;
|
||||
|
||||
EPTypePost = k.EPTypePost;
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
//Original research by Samyuu
|
||||
|
||||
namespace KKdBaseLib
|
||||
{
|
||||
public static class DCC //Databank Checksum Calculator
|
||||
{
|
||||
private static readonly ushort[] ChecksumLookupTable = {
|
||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
|
||||
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
|
||||
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
|
||||
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
|
||||
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
|
||||
0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
|
||||
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
|
||||
0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
|
||||
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
|
||||
0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
|
||||
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
|
||||
0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
|
||||
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
|
||||
0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
|
||||
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
|
||||
0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
|
||||
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
|
||||
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
|
||||
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
|
||||
0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
|
||||
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
|
||||
0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
||||
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
|
||||
0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
|
||||
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
|
||||
0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
|
||||
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
|
||||
0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
|
||||
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
|
||||
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
|
||||
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
|
||||
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0,
|
||||
};
|
||||
|
||||
public static ushort CalculateChecksum(byte[] data,
|
||||
int offset = 0, ushort seed = 0xFFFF)
|
||||
{
|
||||
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 CalculateChecksumU32(byte[] data,
|
||||
int offset = 0, uint seed = 0xFFFFFFFF)
|
||||
{
|
||||
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 CalculateChecksumU64(byte[] data,
|
||||
int offset = 0, ulong seed = 0xFFFFFFFFFFFFFFFF)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,6 +126,10 @@ 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 sbyte TI8(this byte[] arr, int offset = 0)
|
||||
{ sbyte val; fixed (byte* ptr = arr) val = *( sbyte*)(ptr + offset); return val; }
|
||||
public static byte TU8(this byte[] arr, int offset = 0)
|
||||
{ byte val; fixed (byte* ptr = arr) val = *( byte*)(ptr + offset); return val; }
|
||||
public static short TI16(this byte[] arr, int offset = 0)
|
||||
{ short val; fixed (byte* ptr = arr) val = *( short*)(ptr + offset); return val; }
|
||||
public static ushort TU16(this byte[] arr, int offset = 0)
|
||||
@@ -159,6 +163,10 @@ namespace KKdBaseLib
|
||||
public static Quat TQ (this byte[] arr, int offset = 0)
|
||||
{ Quat val; fixed (byte* ptr = arr) val = *( Quat*)(ptr + offset); return val; }
|
||||
|
||||
public static void GBy(this byte[] arr, sbyte val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( sbyte*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, byte val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( byte*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, short val, int offset = 0)
|
||||
{ fixed (byte* ptr = arr) *( short*)(ptr + offset) = val; }
|
||||
public static void GBy(this byte[] arr, ushort val, int offset = 0)
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
<Authors>korenkonder</Authors>
|
||||
<Company></Company>
|
||||
<Configuration></Configuration>
|
||||
<Copyright>korenkonder (C) 2019-2021</Copyright>
|
||||
<Copyright>korenkonder (C) 2019-2025</Copyright>
|
||||
<Description>A base library</Description>
|
||||
<FileVersion>0.4.10.8</FileVersion>
|
||||
<FileVersion>0.5.0.0</FileVersion>
|
||||
<PackageId>KKdBaseLib</PackageId>
|
||||
<Product>KKdBaseLib</Product>
|
||||
<TargetFramework>net461</TargetFramework>
|
||||
<Title>KKdBaseLib</Title>
|
||||
<Version>0.4.10.8</Version>
|
||||
<Version>0.5.0.0</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
||||
+39
-5
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace KKdBaseLib
|
||||
@@ -79,7 +80,7 @@ namespace KKdBaseLib
|
||||
|
||||
if (trace > 0)
|
||||
{
|
||||
double sq = System.Math.Sqrt(trace);
|
||||
double sq = Math.Sqrt(trace);
|
||||
|
||||
q.W = (float)sq;
|
||||
sq = 1.0 / (4.0 * sq);
|
||||
@@ -89,7 +90,7 @@ namespace KKdBaseLib
|
||||
}
|
||||
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);
|
||||
double sq = 2.0 * Math.Sqrt(1.0 + row0.X - row1.Y - row2.Z);
|
||||
|
||||
q.X = (float)(0.25 * sq);
|
||||
sq = 1.0 / sq;
|
||||
@@ -99,7 +100,7 @@ namespace KKdBaseLib
|
||||
}
|
||||
else if (row1.Y > row2.Z)
|
||||
{
|
||||
double sq = 2.0 * System.Math.Sqrt(1.0 + row1.Y - row0.X - row2.Z);
|
||||
double sq = 2.0 * Math.Sqrt(1.0 + row1.Y - row0.X - row2.Z);
|
||||
|
||||
q.Y = (float)(0.25 * sq);
|
||||
sq = 1.0 / sq;
|
||||
@@ -109,7 +110,7 @@ namespace KKdBaseLib
|
||||
}
|
||||
else
|
||||
{
|
||||
double sq = 2.0 * System.Math.Sqrt(1.0 + row2.Z - row0.X - row1.Y);
|
||||
double sq = 2.0 * Math.Sqrt(1.0 + row2.Z - row0.X - row1.Y);
|
||||
|
||||
q.Z = (float)(0.25 * sq);
|
||||
sq = 1.0 / sq;
|
||||
@@ -121,6 +122,33 @@ namespace KKdBaseLib
|
||||
return q.Normalized;
|
||||
}
|
||||
|
||||
public Vec3 GetRotation()
|
||||
{
|
||||
Vec3 rotation;
|
||||
if (-Row0.Z >= 1.0f)
|
||||
rotation.Y = (float)(Math.PI / 2.0);
|
||||
else if (-Row0.Z <= -1.0f)
|
||||
rotation.Y = (float)(-Math.PI / 2.0);
|
||||
else
|
||||
rotation.Y = (float)Math.Asin(-Row0.Z);
|
||||
|
||||
if (Math.Abs(Row0.Z) < 0.99999899f) {
|
||||
rotation.X = (float)Math.Atan2(Row1.Z, Row2.Z);
|
||||
rotation.Z = (float)Math.Atan2(Row0.Y, Row0.X);
|
||||
}
|
||||
else {
|
||||
rotation.X = 0.0f;
|
||||
rotation.Z = (float)Math.Atan2(Row2.Y, Row1.Y);
|
||||
if (Row0.Z > 0.0f)
|
||||
rotation.Z = -rotation.Z;
|
||||
}
|
||||
return rotation;
|
||||
}
|
||||
|
||||
public Vec3 GetScale() => new Vec3(Row0.Length, Row1.Length, Row2.Length);
|
||||
|
||||
public Vec3 GetTranslation() => Row3.XYZ;
|
||||
|
||||
public Mat4 Invert() => -this;
|
||||
|
||||
public Mat4 Translate(Vec3 vec)
|
||||
@@ -129,7 +157,13 @@ namespace KKdBaseLib
|
||||
public Mat4 Translate(Vec4 vec)
|
||||
{ Row3 = vec * this; return this; }
|
||||
|
||||
public static Mat4 operator +(Mat4 left, Mat4 right)
|
||||
public void TransformVector(in Vec3 normal, out Vec3 normalOut) {
|
||||
normalOut = (Row0 * new Vec4(normal.X) +
|
||||
Row1 * new Vec4(normal.Y) +
|
||||
Row2 * new Vec4(normal.Z)).XYZ;
|
||||
}
|
||||
|
||||
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; }
|
||||
|
||||
|
||||
+35
-67
@@ -45,52 +45,9 @@ namespace KKdBaseLib
|
||||
|
||||
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 readonly float Length => (X * X + Y * Y + Z * Z + W * W).Sqrt();
|
||||
public readonly float LengthSquared => X * X + Y * Y + Z * Z + W * W;
|
||||
public readonly Quat Normalized => this * (Length == 0.0f ? 1.0f : (1.0f / Length));
|
||||
|
||||
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; }
|
||||
@@ -125,34 +82,45 @@ namespace KKdBaseLib
|
||||
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;
|
||||
public static Quat Lerp(Quat left, Quat right, float blend) {
|
||||
Quat x_t;
|
||||
Quat y_t;
|
||||
x_t = left;
|
||||
y_t = right;
|
||||
|
||||
float dot = Dot(q1, q2);
|
||||
if (Dot(x_t, y_t) < 0.0f)
|
||||
x_t = -x_t;
|
||||
|
||||
return (x_t * (1.0f - blend) + y_t * blend).Normalized;
|
||||
}
|
||||
|
||||
public static Quat Slerp(Quat left, Quat right, float blend)
|
||||
{
|
||||
Quat x_t;
|
||||
Quat y_t;
|
||||
x_t = left;
|
||||
y_t = right;
|
||||
|
||||
float dot = Dot(x_t, y_t);
|
||||
if (dot < 0.0f)
|
||||
{
|
||||
q2 = -q2;
|
||||
dot = -dot;
|
||||
y_t = -y_t;
|
||||
}
|
||||
|
||||
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);
|
||||
if (1.0 - dot <= 0.08f)
|
||||
return Lerp(x_t, y_t, blend);
|
||||
|
||||
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;
|
||||
dot = System.Math.Min(dot, 1.0f);
|
||||
|
||||
float theta = (float)System.Math.Acos(dot);
|
||||
if (theta == 0.0f)
|
||||
return x_t;
|
||||
|
||||
float st = 1.0f / (float)System.Math.Sin(theta);
|
||||
float s0 = (float)System.Math.Sin((1.0f - blend) * theta) * st;
|
||||
float s1 = (float)System.Math.Sin(theta * blend) * st;
|
||||
return (x_t * s0 + y_t * s1).Normalized;
|
||||
}
|
||||
|
||||
public static explicit operator Vec4(Quat quat) =>
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ namespace KKdBaseLib
|
||||
[FieldOffset(0x0C)] public float W;
|
||||
|
||||
public Vec4(float val)
|
||||
{ X = val; Y = val; Z = val; W = 0.0f; }
|
||||
{ X = val; Y = val; Z = val; W = val; }
|
||||
|
||||
public Vec4(float X, float Y)
|
||||
{ this.X = X; this.Y = Y; Z = 0.0f; W = 0.0f; }
|
||||
|
||||
+118
-74
@@ -5,7 +5,6 @@ using KKdBaseLib.Auth3D;
|
||||
using KKdMainLib.IO;
|
||||
using Object = KKdBaseLib.Auth3D.Object;
|
||||
using A3DADict = System.Collections.Generic.Dictionary<string, object>;
|
||||
using UsedDict = System.Collections.Generic.Dictionary< int, KKdBaseLib.KeyValuePair<int, float>>;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
@@ -14,6 +13,8 @@ namespace KKdMainLib
|
||||
public Data Data;
|
||||
public A3DAHeader Head;
|
||||
|
||||
public static int Rounding = 9;
|
||||
|
||||
private Stream s;
|
||||
private bool a3dc;
|
||||
private int i, i0, i1;
|
||||
@@ -369,6 +370,8 @@ namespace KKdMainLib
|
||||
dict.FV(out jointOrient.Z, nameView + ".joint_orient.z");
|
||||
Data.MObjectHRC[i0].Node[i1].JointOrient = jointOrient;
|
||||
}
|
||||
else
|
||||
Data.MObjectHRC[i0].Node[i1].JointOrient = null;
|
||||
|
||||
dict.FV(out Data.MObjectHRC[i0].Node[i1].Name , nameView + ".name" );
|
||||
dict.FV(out Data.MObjectHRC[i0].Node[i1].Parent, nameView + ".parent");
|
||||
@@ -495,6 +498,8 @@ namespace KKdMainLib
|
||||
dict.FV(out jointOrient.Z, nameView + ".joint_orient.z");
|
||||
Data.ObjectHRC[i0].Node[i1].JointOrient = jointOrient;
|
||||
}
|
||||
else
|
||||
Data.ObjectHRC[i0].Node[i1].JointOrient = null;
|
||||
|
||||
dict.FV(out Data.ObjectHRC[i0].Node[i1].Name , nameView + ".name" );
|
||||
dict.FV(out Data.ObjectHRC[i0].Node[i1].Parent, nameView + ".parent");
|
||||
@@ -809,8 +814,6 @@ namespace KKdMainLib
|
||||
nameView = name + ".node." + soi1;
|
||||
ref ObjectNode node = ref mObjectHRC.Node[soi1];
|
||||
|
||||
W(ref node.MT, nameView, 0b10000);
|
||||
|
||||
if (node.JointOrient.HasValue)
|
||||
{
|
||||
Vec3 jointOrient = node.JointOrient.Value;
|
||||
@@ -819,6 +822,8 @@ namespace KKdMainLib
|
||||
W(nameView + ".joint_orient.z", jointOrient.Z);
|
||||
}
|
||||
|
||||
W(ref node.MT, nameView, 0b10000);
|
||||
|
||||
W(nameView + ".name", node.Name );
|
||||
W(nameView + ".parent", node.Parent);
|
||||
W(ref node.MT, nameView, 0b01111);
|
||||
@@ -965,8 +970,6 @@ namespace KKdMainLib
|
||||
nameView = name + ".node." + soi1;
|
||||
ref ObjectNode node = ref objectHRC.Node[soi1];
|
||||
|
||||
W(ref node.MT, nameView, 0b10000);
|
||||
|
||||
if (node.JointOrient.HasValue)
|
||||
{
|
||||
Vec3 jointOrient = node.JointOrient.Value;
|
||||
@@ -975,6 +978,8 @@ namespace KKdMainLib
|
||||
W(nameView + ".joint_orient.z", jointOrient.Z);
|
||||
}
|
||||
|
||||
W(ref node.MT, nameView, 0b10000);
|
||||
|
||||
W(nameView + ".name" , node.Name );
|
||||
W(nameView + ".parent", node.Parent);
|
||||
W(ref node.MT, nameView, 0b01111);
|
||||
@@ -1069,7 +1074,7 @@ namespace KKdMainLib
|
||||
private Key RK(string str)
|
||||
{
|
||||
Key key = new Key();
|
||||
if ( dict.FV(out key.BinOffset, str + BO )) return key;
|
||||
if ( dict.FV(out key.BinOffset, str + BO )) return key;
|
||||
if (!dict.FV(out int type , str + ".type")) return default;
|
||||
|
||||
key.Type = (KeyType)type;
|
||||
@@ -1089,11 +1094,24 @@ namespace KKdMainLib
|
||||
|
||||
if (keyType != 0)
|
||||
{
|
||||
dict.FV(out string valueType, str + ".raw_data.value_type");
|
||||
dict.FV(out int valueListSize, str + ".raw_data.value_list_size");
|
||||
|
||||
if (dict.FV(out int valueListOffset, str + ".raw_data.value_list_offset"))
|
||||
{
|
||||
if (keyType != 3)
|
||||
return default;
|
||||
|
||||
key.RawData = true;
|
||||
key.RawDataBinary = true;
|
||||
key.RawDataValueListSize = valueListSize;
|
||||
key.RawDataValueListOffset = valueListOffset;
|
||||
return key;
|
||||
}
|
||||
|
||||
string[] VL = null;
|
||||
dict.FV(out string value_type, str + ".raw_data.value_type");
|
||||
if (dict.FV(out value, str + ".raw_data.value_list"))
|
||||
VL = value.Split(',');
|
||||
dict.FV(out int valueListSize, str + ".raw_data.value_list_size");
|
||||
value = "";
|
||||
|
||||
int ds = keyType + 1;
|
||||
@@ -1174,7 +1192,7 @@ namespace KKdMainLib
|
||||
|
||||
private void W(ref Key key, string str, bool a3dc)
|
||||
{
|
||||
if (a3dc) { W(str + BO, key.BinOffset); return; }
|
||||
if (a3dc && !(key.RawData && key.RawDataBinary)) { W(str + BO, key.BinOffset); return; }
|
||||
|
||||
int i = 0;
|
||||
if (key.Type < KeyType.Linear || key.Keys == null || (key.Keys != null && key.Keys.Length == 0))
|
||||
@@ -1210,30 +1228,37 @@ namespace KKdMainLib
|
||||
else if (key.Keys != null)
|
||||
{
|
||||
int length = key.Keys.Length;
|
||||
int keyType = 0;
|
||||
IKF kf;
|
||||
W(str + ".max", (float)(key.Max ?? Data.PlayControl.Size));
|
||||
for (i = 0; i < length && keyType < 3; i++)
|
||||
int keyType = 0;
|
||||
if (key.RawDataBinary)
|
||||
{
|
||||
kf = key.Keys[i].Check();
|
||||
if (kf is KFT0 && keyType < 0) keyType = 0;
|
||||
else if (kf is KFT1 && keyType < 1) keyType = 1;
|
||||
else if (kf is KFT2 && keyType < 2) keyType = 2;
|
||||
else if (kf is KFT3 && keyType < 3) keyType = 3;
|
||||
W(str + ".raw_data.value_list_offset", key.RawDataValueListOffset);
|
||||
keyType = 3;
|
||||
}
|
||||
int valueListSize = length * keyType + length;
|
||||
s.W(str + ".raw_data.value_list=");
|
||||
if (keyType == 0) for (i = 0; i < length; i++)
|
||||
s.W(key.Keys[i].ToT0().ToString(false) + (i + 1 < length ? "," : ""));
|
||||
else if (keyType == 1) for (i = 0; i < length; i++)
|
||||
s.W(key.Keys[i].ToT1().ToString(false) + (i + 1 < length ? "," : ""));
|
||||
else if (keyType == 2) for (i = 0; i < length; i++)
|
||||
s.W(key.Keys[i].ToT2().ToString(false) + (i + 1 < length ? "," : ""));
|
||||
else if (keyType == 3) for (i = 0; i < length; i++)
|
||||
s.W(key.Keys[i] .ToString(false) + (i + 1 < length ? "," : ""));
|
||||
s.P--;
|
||||
s.W('\n');
|
||||
W(str + ".raw_data.value_list_size", valueListSize);
|
||||
else
|
||||
{
|
||||
for (i = 0; i < length && keyType < 3; i++)
|
||||
{
|
||||
IKF kf = key.Keys[i].Check();
|
||||
if (kf is KFT0 && keyType < 0) keyType = 0;
|
||||
else if (kf is KFT1 && keyType < 1) keyType = 1;
|
||||
else if (kf is KFT2 && keyType < 2) keyType = 2;
|
||||
else if (kf is KFT3 && keyType < 3) keyType = 3;
|
||||
}
|
||||
|
||||
s.W(str + ".raw_data.value_list=");
|
||||
if (keyType == 0) for (i = 0; i < length; i++)
|
||||
s.W(key.Keys[i].ToT0().ToString(false) + (i + 1 < length ? "," : ""));
|
||||
else if (keyType == 1) for (i = 0; i < length; i++)
|
||||
s.W(key.Keys[i].ToT1().ToString(false) + (i + 1 < length ? "," : ""));
|
||||
else if (keyType == 2) for (i = 0; i < length; i++)
|
||||
s.W(key.Keys[i].ToT2().ToString(false) + (i + 1 < length ? "," : ""));
|
||||
else if (keyType == 3) for (i = 0; i < length; i++)
|
||||
s.W(key.Keys[i] .ToString(false) + (i + 1 < length ? "," : ""));
|
||||
s.P--;
|
||||
s.W('\n');
|
||||
}
|
||||
W(str + ".raw_data.value_list_size", length * keyType + length);
|
||||
W(str + ".raw_data.value_type" , "float" );
|
||||
W(str + ".raw_data_key_type" , keyType );
|
||||
W(str + ".type", (int)key.Type);
|
||||
@@ -1253,9 +1278,9 @@ namespace KKdMainLib
|
||||
private void W(string Data, ulong val) =>
|
||||
W(Data, val.ToS());
|
||||
private void W(string Data, float val) =>
|
||||
W(Data, val.ToS(9));
|
||||
W(Data, val.ToS(Rounding));
|
||||
private void W(string Data, double val) =>
|
||||
W(Data, val.ToS(9));
|
||||
W(Data, val.ToS(Rounding));
|
||||
private void W(string Data, string val)
|
||||
{ if (val != null) s.W(Data + "=" + val + "\n"); }
|
||||
|
||||
@@ -1432,13 +1457,6 @@ namespace KKdMainLib
|
||||
for (i0 = 0; i0 < Data.Chara.Length; i0++)
|
||||
WO(ref Data.Chara[i0].MT, ReturnToOffset);
|
||||
|
||||
if (Data.DOF != null)
|
||||
{
|
||||
DOF dof = Data.DOF.Value;
|
||||
WO(ref dof.MT, ReturnToOffset);
|
||||
Data.DOF = dof;
|
||||
}
|
||||
|
||||
if (Data.Light != null)
|
||||
for (i0 = 0; i0 < Data.Light.Length; i0++)
|
||||
{
|
||||
@@ -1515,12 +1533,6 @@ namespace KKdMainLib
|
||||
for (i0 = 0; i0 < Data.Curve.Length; i0++)
|
||||
W(ref Data.Curve[i0].CV);
|
||||
|
||||
if (Data.DOF != null && (Head.Format == Format.AFT || Head.Format == Format.FT))
|
||||
{
|
||||
DOF dof = Data.DOF.Value;
|
||||
W(ref dof.MT);
|
||||
Data.DOF = dof;
|
||||
}
|
||||
|
||||
if (Data.Light != null)
|
||||
for (i0 = 0; i0 < Data.Light.Length; i0++)
|
||||
@@ -1680,14 +1692,15 @@ namespace KKdMainLib
|
||||
|
||||
private void RMT(ref ModelTransform mt)
|
||||
{
|
||||
if (mt.BinOffset == null) return;
|
||||
if (mt.BinOffset.HasValue)
|
||||
{
|
||||
s.P = (int)mt.BinOffset;
|
||||
|
||||
s.P = (int)mt.BinOffset;
|
||||
|
||||
ReadOffset(out mt.Scale);
|
||||
ReadOffset(out mt.Rot );
|
||||
ReadOffset(out mt.Trans);
|
||||
mt.Visibility = new Key { BinOffset = s.RI32() };
|
||||
ReadOffset(out mt.Scale);
|
||||
ReadOffset(out mt.Rot);
|
||||
ReadOffset(out mt.Trans);
|
||||
mt.Visibility = new Key { BinOffset = s.RI32() };
|
||||
}
|
||||
|
||||
RV3(ref mt.Scale );
|
||||
RV3(ref mt.Rot , true);
|
||||
@@ -1712,15 +1725,32 @@ namespace KKdMainLib
|
||||
|
||||
private void RK(ref Key key, bool f16 = false)
|
||||
{
|
||||
int length;
|
||||
if (key.RawData)
|
||||
{
|
||||
if (!key.RawDataBinary)
|
||||
return;
|
||||
|
||||
s.P = (int)key.RawDataValueListOffset;
|
||||
key.RawDataValueListOffset = 0;
|
||||
|
||||
length = (int)key.RawDataValueListSize / 4;
|
||||
key.Keys = new KFT3[length];
|
||||
for (int i = 0; i < key.Keys.Length; i++)
|
||||
{ ref KFT3 kf = ref key.Keys[i]; Vec4 v = s.RV4(); kf.F = v.X; kf.V = v.Y;
|
||||
kf.T1 = v.Z; kf.T2 = v.W; }
|
||||
return;
|
||||
}
|
||||
|
||||
if (key.BinOffset == null || key.BinOffset < 0) return;
|
||||
|
||||
s.P = (int)key.BinOffset;
|
||||
int Type = s.RI32();
|
||||
int Type = s.RI32();
|
||||
key.Value = s.RF32();
|
||||
key.Type = (KeyType)(Type & 0xFF);
|
||||
if (key.Type < KeyType.Linear) return;
|
||||
key.Max = s.RF32();
|
||||
int length = s.RI32();
|
||||
key.Max = s.RF32();
|
||||
length = s.RI32();
|
||||
key.EPTypePost = (EPType)((Type >> 12) & 0xF);
|
||||
key.EPTypePre = (EPType)((Type >> 8) & 0xF);
|
||||
key.Keys = new KFT3[length];
|
||||
@@ -1781,6 +1811,17 @@ namespace KKdMainLib
|
||||
|
||||
private void W(ref Key key, bool f16 = false)
|
||||
{
|
||||
if (key.RawData) {
|
||||
if (!key.RawDataBinary)
|
||||
return;
|
||||
|
||||
key.RawDataValueListOffset = s.P;
|
||||
key.RawDataValueListSize = key.Keys.Length * 4;
|
||||
for (i = 0; i < key.Keys.Length; i++)
|
||||
{ ref KFT3 kf = ref key.Keys[i]; s.W(new Vec4(kf.F, kf.V, kf.T1, kf.T2)); }
|
||||
return;
|
||||
}
|
||||
|
||||
key.BinOffset = s.P;
|
||||
if (key.Type > KeyType.Static && key.Keys != null)
|
||||
{
|
||||
@@ -2301,7 +2342,7 @@ namespace KKdMainLib
|
||||
Parent = temp1[i1].RI32("Parent"),
|
||||
};
|
||||
|
||||
if ((temp2 = temp1["JointOrient"]).NotNull)
|
||||
if ((temp2 = temp1[i1]["JointOrient"]).NotNull)
|
||||
Data.MObjectHRC[i0].Node[i1].JointOrient = new Vec3
|
||||
{
|
||||
X = temp1.RF32("X"),
|
||||
@@ -2425,7 +2466,7 @@ namespace KKdMainLib
|
||||
Parent = temp1[i1].RI32("Parent"),
|
||||
};
|
||||
|
||||
if ((temp2 = temp1["JointOrient"]).NotNull)
|
||||
if ((temp2 = temp1[i1]["JointOrient"]).NotNull)
|
||||
Data.ObjectHRC[i0].Node[i1].JointOrient = new Vec3
|
||||
{
|
||||
X = temp1.RF32("X"),
|
||||
@@ -2650,11 +2691,11 @@ namespace KKdMainLib
|
||||
MsgPack instance = new MsgPack(Data.MObjectHRC[i0].Instances.Length, "Instance");
|
||||
for (i1 = 0; i1 < Data.MObjectHRC[i0].Instances.Length; i1++)
|
||||
{
|
||||
instance[i1] = MsgPack.New.Add(ref Data.MObjectHRC[i0].Instances[i1].MT)
|
||||
.Add("Name", Data.MObjectHRC[i0].Instances[i1].Name);
|
||||
MsgPack _instance = MsgPack.New.Add("Name", Data.MObjectHRC[i0].Instances[i1].Name);
|
||||
if (Data.MObjectHRC[i0].Instances[i1].Shadow)
|
||||
instance[i1].Add("Shadow", true);
|
||||
instance[i1].Add("UIDName", Data.MObjectHRC[i0].Instances[i1].UIDName);
|
||||
_instance.Add("Shadow", true);
|
||||
_instance.Add("UIDName", Data.MObjectHRC[i0].Instances[i1].UIDName);
|
||||
instance[i1] = _instance.Add(ref Data.MObjectHRC[i0].Instances[i1].MT);
|
||||
}
|
||||
|
||||
_mObjectHRC.Add(instance);
|
||||
@@ -2665,19 +2706,19 @@ namespace KKdMainLib
|
||||
MsgPack node = new MsgPack(Data.MObjectHRC[i0].Node.Length, "Node");
|
||||
for (i1 = 0; i1 < Data.MObjectHRC[i0].Node.Length; i1++)
|
||||
{
|
||||
node[i1] = MsgPack.New
|
||||
MsgPack _node = MsgPack.New
|
||||
.Add("Name" , Data.MObjectHRC[i0].Node[i1].Name )
|
||||
.Add("Parent", Data.MObjectHRC[i0].Node[i1].Parent)
|
||||
.Add(ref Data.MObjectHRC[i0].Node[i1].MT);
|
||||
.Add("Parent", Data.MObjectHRC[i0].Node[i1].Parent);
|
||||
|
||||
if (Data.MObjectHRC[i0].Node[i1].JointOrient.HasValue)
|
||||
{
|
||||
Vec3 jointOrient = Data.MObjectHRC[i0].Node[i1].JointOrient.Value;
|
||||
node[i1] = node[i1].Add(new MsgPack("JointOrient")
|
||||
_node.Add(new MsgPack("JointOrient")
|
||||
.Add("X", jointOrient.X)
|
||||
.Add("Y", jointOrient.Y)
|
||||
.Add("Z", jointOrient.Z));
|
||||
}
|
||||
node[i1] = _node.Add(ref Data.MObjectHRC[i0].Node[i1].MT);
|
||||
}
|
||||
_mObjectHRC.Add(node);
|
||||
}
|
||||
@@ -2735,10 +2776,11 @@ namespace KKdMainLib
|
||||
MsgPack texPat = new MsgPack(Data.Object[i0].TexPat.Length, "TexturePattern");
|
||||
for (i1 = 0; i1 < Data.Object[i0].TexPat.Length; i1++)
|
||||
{
|
||||
texPat[i1] = MsgPack.New.Add("Name", Data.Object[i0].TexPat[i1].Name);
|
||||
MsgPack _texPat = MsgPack.New.Add("Name", Data.Object[i0].TexPat[i1].Name);
|
||||
if (Data.Object[i0].TexPat[i1].Pat != null)
|
||||
texPat[i1] = texPat[i1].Add("Pat" , Data.Object[i0].TexPat[i1].Pat )
|
||||
.Add("PatOffset", Data.Object[i0].TexPat[i1].PatOffset);
|
||||
_texPat.Add("Pat" , Data.Object[i0].TexPat[i1].Pat )
|
||||
.Add("PatOffset", Data.Object[i0].TexPat[i1].PatOffset);
|
||||
texPat[i1] = _texPat;
|
||||
}
|
||||
_object.Add(texPat);
|
||||
}
|
||||
@@ -2784,19 +2826,19 @@ namespace KKdMainLib
|
||||
MsgPack node = new MsgPack(Data.ObjectHRC[i0].Node.Length, "Node");
|
||||
for (i1 = 0; i1 < Data.ObjectHRC[i0].Node.Length; i1++)
|
||||
{
|
||||
node[i1] = MsgPack.New
|
||||
MsgPack _node = MsgPack.New
|
||||
.Add("Name" , Data.ObjectHRC[i0].Node[i1].Name )
|
||||
.Add("Parent", Data.ObjectHRC[i0].Node[i1].Parent)
|
||||
.Add(ref Data.ObjectHRC[i0].Node[i1].MT);
|
||||
.Add("Parent", Data.ObjectHRC[i0].Node[i1].Parent);
|
||||
|
||||
if (Data.ObjectHRC[i0].Node[i1].JointOrient.HasValue)
|
||||
{
|
||||
Vec3 jointOrient = Data.ObjectHRC[i0].Node[i1].JointOrient.Value;
|
||||
node[i1] = node[i1].Add(new MsgPack("JointOrient")
|
||||
_node.Add(new MsgPack("JointOrient")
|
||||
.Add("X", jointOrient.X)
|
||||
.Add("Y", jointOrient.Y)
|
||||
.Add("Z", jointOrient.Z));
|
||||
}
|
||||
node[i1] = _node.Add(ref Data.ObjectHRC[i0].Node[i1].MT);
|
||||
}
|
||||
_objectHRC.Add(node);
|
||||
}
|
||||
@@ -2912,7 +2954,8 @@ namespace KKdMainLib
|
||||
if (key.Type == 0) { key.Value = 0; return key; }
|
||||
else if (key.Type < KeyType.Linear) return key;
|
||||
|
||||
key.RawData = msgPack.RB("RawData");
|
||||
key.RawData = msgPack.RB("RawData");
|
||||
key.RawDataBinary = msgPack.RB("RawDataBinary");
|
||||
MsgPack trans;
|
||||
if ((trans = msgPack["Keys", true]).IsNull && (trans = msgPack["Trans", true]).IsNull) return key;
|
||||
|
||||
@@ -2988,7 +3031,8 @@ namespace KKdMainLib
|
||||
if (key.EPTypePre != EPType.None)
|
||||
keys.Add("EPTypePre", key.EPTypePre.ToString());
|
||||
|
||||
if (key.RawData) keys.Add("RawData", true);
|
||||
if (key.RawData ) keys.Add("RawData" , true);
|
||||
if (key.RawDataBinary) keys.Add("RawDataBinary", true);
|
||||
|
||||
int length = key.Keys.Length;
|
||||
MsgPack Keys = new MsgPack(length, "Keys");
|
||||
|
||||
+575
-488
File diff suppressed because it is too large
Load Diff
+60
-4
@@ -10,13 +10,13 @@ namespace KKdMainLib
|
||||
{
|
||||
private static readonly byte[] Key = "file access deny".ToASCII();
|
||||
|
||||
public static void Decrypt(this string file)
|
||||
public static void Decrypt(string file)
|
||||
{
|
||||
int streamLength, fileLength;
|
||||
byte[] encrypted, decrypted;
|
||||
using (Stream _IO = File.OpenReader(file))
|
||||
{
|
||||
if (_IO.RI64() != 0x454C494641564944) return;
|
||||
if (_IO.RU64() != 0x454C494641564944u) return;
|
||||
|
||||
streamLength = _IO.RI32();
|
||||
fileLength = _IO.RI32();
|
||||
@@ -37,7 +37,7 @@ namespace KKdMainLib
|
||||
_IO.W(decrypted, fileLength < streamLength ? fileLength : streamLength);
|
||||
}
|
||||
|
||||
public static void Encrypt(this string file)
|
||||
public static void Encrypt(string file)
|
||||
{
|
||||
byte[] data;
|
||||
using (Stream _IO = File.OpenReader(file))
|
||||
@@ -60,11 +60,67 @@ namespace KKdMainLib
|
||||
|
||||
using (Stream _IO = File.OpenWriter(file, dataAlign.Length))
|
||||
{
|
||||
_IO.W(0x454C494641564944);
|
||||
_IO.W(0x454C494641564944u);
|
||||
_IO.W(fileLength);
|
||||
_IO.W(fileLengthOrigin);
|
||||
_IO.W(encrypted);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] Decrypt(byte[] data)
|
||||
{
|
||||
int streamLength, fileLength;
|
||||
byte[] encrypted, decrypted;
|
||||
using (Stream _IO = File.OpenReader(data))
|
||||
{
|
||||
if (_IO.RU64() != 0x454C494641564944u) return data;
|
||||
|
||||
streamLength = _IO.RI32();
|
||||
fileLength = _IO.RI32();
|
||||
encrypted = _IO.RBy(streamLength);
|
||||
decrypted = new byte[streamLength];
|
||||
}
|
||||
|
||||
using (AesManaged crypto = new AesManaged())
|
||||
{
|
||||
crypto.Key = Key; crypto.IV = new byte[16];
|
||||
crypto.Mode = CipherMode.ECB; crypto.Padding = PaddingMode.Zeros;
|
||||
using CryptoStream cryptoData = new CryptoStream(new MSIO.MemoryStream(encrypted),
|
||||
crypto.CreateDecryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read);
|
||||
cryptoData.Read(decrypted, 0, streamLength);
|
||||
}
|
||||
|
||||
data = new byte[fileLength];
|
||||
Array.Copy(decrypted, data, fileLength < streamLength ? fileLength : streamLength);
|
||||
return data;
|
||||
}
|
||||
|
||||
public static byte[] Encrypt(byte[] data)
|
||||
{
|
||||
int fileLengthOrigin = data.Length;
|
||||
int fileLength = fileLengthOrigin.A(16);
|
||||
byte[] dataAlign = new byte[fileLength];
|
||||
Array.Copy(data, dataAlign, data.Length);
|
||||
data = null;
|
||||
byte[] encrypted = new byte[fileLength];
|
||||
using (AesManaged crypto = new AesManaged())
|
||||
{
|
||||
crypto.Key = Key; crypto.IV = new byte[16];
|
||||
crypto.Mode = CipherMode.ECB; crypto.Padding = PaddingMode.Zeros;
|
||||
using CryptoStream cryptoData = new CryptoStream(new MSIO.MemoryStream(dataAlign),
|
||||
crypto.CreateEncryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read);
|
||||
cryptoData.Read(encrypted, 0, fileLength);
|
||||
}
|
||||
|
||||
using (Stream _IO = File.OpenWriter())
|
||||
{
|
||||
_IO.W(0x454C494641564944u);
|
||||
_IO.W(fileLength);
|
||||
_IO.W(fileLengthOrigin);
|
||||
_IO.W(encrypted);
|
||||
data = _IO.ToArray();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,15 +83,15 @@ namespace KKdMainLib
|
||||
return s.ToArray(true);
|
||||
}
|
||||
|
||||
public void DBWriter(string file, uint num2)
|
||||
public void DBWriter(string file, uint timestamp)
|
||||
{
|
||||
if (!Success) return;
|
||||
|
||||
byte[] data = DBWriter(file);
|
||||
if (data == null) return;
|
||||
|
||||
ushort num = DCC.CalculateChecksum(data);
|
||||
File.WriteAllBytes(file + "_" + num + "_" + num2 + ".dat", data);
|
||||
ushort hash = data.HashCRC16_CCITT();
|
||||
File.WriteAllBytes(file + "_" + hash + "_" + timestamp + ".dat", data);
|
||||
}
|
||||
|
||||
public void MsgPackReader(string file, bool json)
|
||||
|
||||
@@ -100,13 +100,14 @@ namespace KKdMainLib
|
||||
public static Struct RSt(this byte[] data)
|
||||
{
|
||||
if (data == null || data.Length < 1) return default;
|
||||
data = DIVAFILE.Decrypt(data);
|
||||
Struct @struct;
|
||||
using (Stream stream = File.OpenReader(data))
|
||||
@struct = stream.RSt(stream.ReadHeader(false));
|
||||
return @struct;
|
||||
}
|
||||
|
||||
public static Struct RSt(this Stream stream, Header header)
|
||||
private static Struct RSt(this Stream stream, Header header)
|
||||
{
|
||||
uint l = header.UseSectionSize ? header.SectionSize : header.DataSize;
|
||||
Struct @struct = new Struct { Header = header, DataOffset =
|
||||
@@ -248,25 +249,31 @@ namespace KKdMainLib
|
||||
}
|
||||
|
||||
public static class HashExt
|
||||
{
|
||||
{
|
||||
public static uint HashFNV1a64(this byte[] array) =>
|
||||
array.HashMurmurHash(array.Length);
|
||||
|
||||
public static ulong HashFNV1a64(this byte[] array, int length) // 0x1403B04D0 in SBZV_7.10; FNV 1a 64-bit
|
||||
// FNV 1a 64-bit Modified
|
||||
// 0x1403B04D0 in SBZV_7.10
|
||||
public static ulong HashFNV1a64m(this byte[] array, int length)
|
||||
{
|
||||
int i = 0;
|
||||
ulong hash = 0xCBF29CE484222325;
|
||||
while (i < length)
|
||||
{ hash = 0x100000001B3 * (hash ^ (ulong)array[i]); i++; }
|
||||
return (hash >> 32) ^ hash;
|
||||
}
|
||||
|
||||
return (hash >> 32) ^ hash; // Actual Modification
|
||||
}
|
||||
|
||||
public static uint HashMurmurHash(this byte[] array, uint salt = 0,
|
||||
bool alreadyUpper = false, bool bigEndian = false) =>
|
||||
array.HashMurmurHash(array.Length, salt, alreadyUpper, bigEndian);
|
||||
|
||||
// MurmurHash
|
||||
// 0x814D7A9C in PCSB00554
|
||||
// 0x8134C304 in PCSB01007
|
||||
// 0x0069CEA4 in NPEB02013
|
||||
public static uint HashMurmurHash(this byte[] array, int length, uint salt = 0,
|
||||
bool alreadyUpper = false, bool bigEndian = false) // 0x814D7A9C in PCSB00554; MurmurHash
|
||||
bool alreadyUpper = false, bool bigEndian = false)
|
||||
{
|
||||
uint a, b, hash;
|
||||
int i;
|
||||
@@ -360,5 +367,51 @@ namespace KKdMainLib
|
||||
hash ^= hash >> 17;
|
||||
return hash;
|
||||
}
|
||||
|
||||
private static readonly ushort[] CRC16_CCITT_Table = {
|
||||
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
|
||||
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
|
||||
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
|
||||
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
|
||||
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
|
||||
0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
|
||||
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
|
||||
0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
|
||||
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
|
||||
0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
|
||||
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
|
||||
0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
|
||||
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
|
||||
0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
|
||||
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
|
||||
0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
|
||||
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
|
||||
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
|
||||
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
|
||||
0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
|
||||
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
|
||||
0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
||||
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
|
||||
0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
|
||||
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
|
||||
0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
|
||||
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
|
||||
0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
|
||||
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
|
||||
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
|
||||
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
|
||||
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0,
|
||||
};
|
||||
|
||||
// CRC16-CCITT
|
||||
// 0x140011A90 in SBZV_7.10
|
||||
public static ushort HashCRC16_CCITT(this byte[] data, int offset = 0, ushort seed = 0xFFFF)
|
||||
{
|
||||
int length = data.Length;
|
||||
ushort hash = seed;
|
||||
for (int i = offset; i < length; i++)
|
||||
hash = (ushort)(CRC16_CCITT_Table[(hash >> 8) ^ data[i]] ^ (hash << 8));
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+336
-150
@@ -1,6 +1,5 @@
|
||||
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/
|
||||
|
||||
using System.IO.Compression;
|
||||
using System.Security.Cryptography;
|
||||
using KKdBaseLib;
|
||||
using KKdMainLib.IO;
|
||||
@@ -14,12 +13,12 @@ namespace KKdMainLib
|
||||
public FARC(string file, bool isDirectory = false)
|
||||
{ if (isDirectory) DirectoryPath = file; else FilePath = file; NewFARC(); }
|
||||
|
||||
private void NewFARC() { Files = KKdList<FARCFile>.New; Signature = Farc.FArC; Format = Format.DT; }
|
||||
private void NewFARC() { Files = KKdList<FARCFile>.New; FT = false; }
|
||||
|
||||
public KKdList<FARCFile> Files = KKdList<FARCFile>.New;
|
||||
public Type FARCType;
|
||||
public Flags FARCFlags;
|
||||
public Farc Signature = Farc.FArC;
|
||||
public Format Format = Format.DT;
|
||||
public bool FT = false;
|
||||
public string FilePath, DirectoryPath;
|
||||
public bool HasFiles => !Files.IsNull || Files.Count > 0;
|
||||
public int CompressionLevel = 12;
|
||||
@@ -29,13 +28,13 @@ namespace KKdMainLib
|
||||
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,
|
||||
BlockSize = 128, Mode = isFT ? CipherMode.CBC : CipherMode.ECB,
|
||||
Padding = PaddingMode.Zeros, IV = iv ?? new byte[16] };
|
||||
private AesManaged GetAes(byte[] iv = null) =>
|
||||
new AesManaged () { KeySize = 128, Key = iv != null ? keyFT : key,
|
||||
BlockSize = 128, Mode = iv != null ? CipherMode.CBC : CipherMode.ECB,
|
||||
Padding = iv != null ? PaddingMode.PKCS7 : PaddingMode.Zeros, IV = iv ?? new byte[16] };
|
||||
|
||||
public void Unpack(bool saveToDisk = true)
|
||||
{ if (HeaderReader()) { FileReader(); if (saveToDisk) SaveToDisk(); } }
|
||||
{ if (HeaderReader()) FileReader(saveToDisk); }
|
||||
|
||||
public bool HeaderReader()
|
||||
{
|
||||
@@ -48,82 +47,152 @@ namespace KKdMainLib
|
||||
if (Signature != Farc.FArc && Signature != Farc.FArC && Signature != Farc.FARC)
|
||||
{ reader.Dispose(); return false; }
|
||||
|
||||
FT = false;
|
||||
|
||||
int headerLength = reader.RI32E(true);
|
||||
if (Signature == Farc.FARC)
|
||||
{
|
||||
FARCType = (Type)reader.RI32E(true);
|
||||
FARCFlags = (Flags)reader.RI32E(true);
|
||||
reader.RI32();
|
||||
int farcMode = reader.RI32E(true);
|
||||
int alignment = reader.RI32E(true);
|
||||
|
||||
Format = (FARCType & Type.Enc) != 0 && (farcMode & (farcMode - 1)) != 0 ? Format.FT : Format.DT;
|
||||
FT = (FARCFlags & Flags.AES) != 0 && (alignment & (alignment - 1)) != 0;
|
||||
|
||||
if (Format == Format.FT && (FARCType & Type.Enc) != 0)
|
||||
if (FT)
|
||||
{
|
||||
reader.Dispose();
|
||||
byte[] header = new byte[headerLength - 0x08];
|
||||
MSIO.FileStream stream = new MSIO.FileStream(FilePath, MSIO.FileMode.Open,
|
||||
MSIO.FileAccess.ReadWrite, MSIO.FileShare.ReadWrite) { Position = 0x10 };
|
||||
|
||||
using (AesManaged aes = GetAes(true, null))
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(header, 0x00, headerLength - 0x08);
|
||||
header = SkipData(header, 0x10);
|
||||
reader = File.OpenReader(header);
|
||||
|
||||
farcMode = reader.RI32E(true);
|
||||
headerLength -= 0x08;
|
||||
reader.S(-0x04, SeekOrigin.Current);
|
||||
}
|
||||
else
|
||||
headerLength -= 0x0C;
|
||||
}
|
||||
|
||||
if (Signature == Farc.FARC)
|
||||
if (reader.RI32E(true) == 1)
|
||||
Files.Capacity = 0;
|
||||
|
||||
if (FT)
|
||||
{
|
||||
headerLength -= 0x10;
|
||||
|
||||
byte[] iv = reader.RBy(0x10);
|
||||
byte[] header = reader.RBy(headerLength);
|
||||
reader.Dispose();
|
||||
|
||||
using (MSIO.MemoryStream ms = new MSIO.MemoryStream())
|
||||
{
|
||||
using (AesManaged aes = GetAes(iv))
|
||||
using (CryptoStream cryptoStream = new CryptoStream(ms,
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Write))
|
||||
cryptoStream.Write(header, 0x00, headerLength);
|
||||
header = ms.ToArray();
|
||||
headerLength = header.Length;
|
||||
}
|
||||
|
||||
reader = File.OpenReader(header);
|
||||
int alignment = reader.RI32E(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] header = reader.RBy(headerLength);
|
||||
reader.Dispose();
|
||||
reader = File.OpenReader(header);
|
||||
}
|
||||
|
||||
bool hasPerFileFlags = false;
|
||||
if (Signature == Farc.FARC) {
|
||||
if (reader.RI32E(true) == 1) {
|
||||
Files.Capacity = reader.RI32E(true);
|
||||
reader.RI32();
|
||||
hasPerFileFlags = true;
|
||||
}
|
||||
}
|
||||
reader.RI32E(true);
|
||||
|
||||
if (Files.Capacity == 0)
|
||||
{
|
||||
int Count = 0;
|
||||
long Position = reader.PI64;
|
||||
int Size = 0;
|
||||
if (hasPerFileFlags)
|
||||
Size = sizeof(int) * 4;
|
||||
else if (Signature != Farc.FArc)
|
||||
Size = sizeof(int) * 3;
|
||||
else
|
||||
Size = sizeof(int) * 2;
|
||||
|
||||
while (reader.PI64 < headerLength)
|
||||
{
|
||||
reader.NT();
|
||||
reader.RI32();
|
||||
if (Signature != Farc.FArc) reader.RI32();
|
||||
reader.RI32();
|
||||
if (Signature == Farc.FARC && Format == Format.FT) reader.RI32();
|
||||
reader.RBy(Size);
|
||||
Count++;
|
||||
}
|
||||
reader.PI64 = Position;
|
||||
Files.Capacity = Count;
|
||||
}
|
||||
|
||||
for (int i = 0; i < Files.Capacity; i++)
|
||||
{
|
||||
FARCFile file = default;
|
||||
file.Name = reader.NTUTF8();
|
||||
file.Offset = reader.RI32E(true);
|
||||
if (Signature != Farc.FArc) file.SizeComp = reader.RI32E(true);
|
||||
file.SizeUnc = reader.RI32E(true);
|
||||
if (Signature == Farc.FARC && Format == Format.FT)
|
||||
file.Type = (Type)reader.RI32E(true);
|
||||
Files.Add(file);
|
||||
}
|
||||
if (hasPerFileFlags)
|
||||
for (int i = 0; i < Files.Capacity; i++)
|
||||
{
|
||||
FARCFile file = default;
|
||||
file.Name = reader.NTUTF8();
|
||||
file.Offset = reader.RI32E(true);
|
||||
file.SizeComp = reader.RI32E(true);
|
||||
file.Size = reader.RI32E(true);
|
||||
Flags Flags = (Flags)reader.RI32E(true);
|
||||
|
||||
if (file.Size != 0)
|
||||
{
|
||||
file.Compressed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
file.Size = file.SizeComp;
|
||||
file.SizeComp = 0;
|
||||
file.Compressed = false;
|
||||
}
|
||||
|
||||
file.Encrypted = ((FARCFlags | Flags) & Flags.AES) != 0;
|
||||
Files.Add(file);
|
||||
}
|
||||
else if (Signature != Farc.FArc)
|
||||
for (int i = 0; i < Files.Capacity; i++)
|
||||
{
|
||||
FARCFile file = default;
|
||||
file.Name = reader.NTUTF8();
|
||||
file.Offset = reader.RI32E(true);
|
||||
file.SizeComp = reader.RI32E(true);
|
||||
file.Size = reader.RI32E(true);
|
||||
|
||||
if (file.Size != 0)
|
||||
{
|
||||
file.Compressed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
file.Size = file.SizeComp;
|
||||
file.SizeComp = 0;
|
||||
file.Compressed = false;
|
||||
}
|
||||
|
||||
file.Encrypted = (FARCFlags & Flags.AES) != 0;
|
||||
Files.Add(file);
|
||||
}
|
||||
else
|
||||
for (int i = 0; i < Files.Capacity; i++)
|
||||
{
|
||||
FARCFile file = default;
|
||||
file.Name = reader.NTUTF8();
|
||||
file.Offset = reader.RI32E(true);
|
||||
file.Size = reader.RI32E(true);
|
||||
|
||||
file.SizeComp = 0;
|
||||
file.Compressed = false;
|
||||
file.Encrypted = false;
|
||||
Files.Add(file);
|
||||
}
|
||||
|
||||
reader.Dispose();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void FileReader()
|
||||
{ for (int i = 0; i < Files.Count; i++) FileReader(i); }
|
||||
|
||||
public byte[] FileReader(string file)
|
||||
{
|
||||
if (!HasFiles) return null;
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
if (Files[i].Name.ToLower() == file.ToLower()) return FileReader(i);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public bool Exists(string file)
|
||||
{
|
||||
if (!HasFiles) return false;
|
||||
@@ -132,82 +201,153 @@ namespace KKdMainLib
|
||||
return false;
|
||||
}
|
||||
|
||||
private void FileReader(bool saveToDisk)
|
||||
{
|
||||
if (saveToDisk)
|
||||
MSIO.Directory.CreateDirectory(DirectoryPath);
|
||||
|
||||
Stream reader = File.OpenReader(FilePath);
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
FileReader(i, saveToDisk, ref reader);
|
||||
reader.Dispose();
|
||||
}
|
||||
|
||||
public byte[] FileReader(string file)
|
||||
{
|
||||
if (!HasFiles) return null;
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
if (Files[i].Name.ToLower() == file.ToLower())
|
||||
return FileReader(i);
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] FileReader(int i)
|
||||
{
|
||||
Stream reader = File.OpenReader(FilePath);
|
||||
byte[] data = FileReader(i, false, ref reader);
|
||||
reader.Dispose();
|
||||
return data;
|
||||
}
|
||||
|
||||
public byte[] FileReader(int i, bool saveToDisk, ref Stream reader)
|
||||
{
|
||||
if (!HasFiles) return null;
|
||||
if (i >= Files.Count) return null;
|
||||
|
||||
FARCFile file = Files[i];
|
||||
if (Signature != Farc.FARC)
|
||||
{
|
||||
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;
|
||||
}
|
||||
file.Data = null;
|
||||
|
||||
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))
|
||||
{
|
||||
stream.S(file.Offset, 0);
|
||||
file.Data = stream.RBy(FileSize);
|
||||
}
|
||||
reader.S(file.Offset, SeekOrigin.Begin);
|
||||
|
||||
if ((FARCType & Type.Enc) != 0)
|
||||
if (Signature == Farc.FArc)
|
||||
{
|
||||
if (Format == Format.FT && (file.Type & Type.Enc) != 0)
|
||||
file.DataComp = null;
|
||||
file.Data = reader.RBy(file.Size);
|
||||
}
|
||||
else if (Signature == Farc.FArC)
|
||||
{
|
||||
if (file.Compressed)
|
||||
{
|
||||
using (AesManaged aes = GetAes(true, null))
|
||||
using (CryptoStream cryptoStream = new CryptoStream(new MSIO.MemoryStream(file.Data),
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(file.Data, 0, FileSize);
|
||||
file.Data = SkipData(file.Data, 0x10);
|
||||
file.DataComp = reader.RBy(file.SizeComp);
|
||||
file.Data = file.DataComp.InflateGZip(file.Size);
|
||||
}
|
||||
else
|
||||
using (AesManaged aes = GetAes(false, null))
|
||||
using (CryptoStream cryptoStream = new CryptoStream(new MSIO.MemoryStream(file.Data),
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Read))
|
||||
cryptoStream.Read(file.Data, 0, FileSize);
|
||||
{
|
||||
file.DataComp = null;
|
||||
file.Data = reader.RBy(file.Size);
|
||||
}
|
||||
}
|
||||
else if (file.Compressed || file.Encrypted)
|
||||
{
|
||||
int tempSize = file.Encrypted ? file.SizeComp.A(0x10) : file.SizeComp;
|
||||
|
||||
byte[] temp;
|
||||
if (file.Encrypted)
|
||||
if (FT)
|
||||
{
|
||||
file.SizeComp -= 0x10;
|
||||
tempSize -= 0x10;
|
||||
|
||||
byte[] iv = reader.RBy(0x10);
|
||||
using (MSIO.MemoryStream ms = new MSIO.MemoryStream())
|
||||
{
|
||||
using (AesManaged aes = GetAes(iv))
|
||||
using (CryptoStream cryptoStream = new CryptoStream(ms,
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Write))
|
||||
cryptoStream.Write(reader.RBy(tempSize), 0x00, tempSize);
|
||||
temp = ms.ToArray();
|
||||
file.SizeComp = temp.Length;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (MSIO.MemoryStream ms = new MSIO.MemoryStream())
|
||||
{
|
||||
using (AesManaged aes = GetAes())
|
||||
using (CryptoStream cryptoStream = new CryptoStream(ms,
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Write))
|
||||
cryptoStream.Write(reader.RBy(tempSize), 0x00, tempSize);
|
||||
temp = ms.ToArray();
|
||||
}
|
||||
}
|
||||
else
|
||||
temp = reader.RBy(tempSize);
|
||||
|
||||
if (file.Compressed)
|
||||
{
|
||||
file.DataComp = temp;
|
||||
file.Data = file.DataComp.InflateGZip(file.Size);
|
||||
}
|
||||
else
|
||||
{
|
||||
file.DataComp = null;
|
||||
file.Data = temp;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
file.DataComp = null;
|
||||
file.Data = reader.RBy(file.Size);
|
||||
}
|
||||
|
||||
if (((file.Type | FARCType) & Type.GZip) != 0 && file.SizeUnc > 0)
|
||||
file.Data = file.Data.InflateGZip(file.SizeUnc);
|
||||
if (saveToDisk)
|
||||
{
|
||||
File.WriteAllBytes(Path.Combine(DirectoryPath, file.Name), file.Data);
|
||||
file.DataComp = null;
|
||||
file.Data = null;
|
||||
}
|
||||
|
||||
Files[i] = file;
|
||||
return file.Data;
|
||||
return Files[i].Data;
|
||||
}
|
||||
|
||||
private void SaveToDisk()
|
||||
{
|
||||
if (DirectoryPath == null || Files.IsNull ) return;
|
||||
if (DirectoryPath == "" || Files.Count < 1) return;
|
||||
MSIO.Directory.CreateDirectory(DirectoryPath);
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
{
|
||||
FARCFile file = Files[i];
|
||||
if (file.Data != null)
|
||||
File.WriteAllBytes(Path.Combine(DirectoryPath, file.Name), file.Data);
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] SkipData(byte[] data, int skip)
|
||||
{
|
||||
byte[] skipData = new byte[data.Length - skip];
|
||||
System.Array.Copy(data, skip, skipData, 0, data.Length - skip);
|
||||
return skipData;
|
||||
}
|
||||
|
||||
public void Pack(Farc signature = Farc.FArC)
|
||||
public void Pack()
|
||||
{
|
||||
NewFARC();
|
||||
string[] files = Directory.GetFiles(DirectoryPath);
|
||||
Files.Capacity = files.Length;
|
||||
|
||||
bool compressed = false;
|
||||
bool encrypted = false;
|
||||
switch (Signature)
|
||||
{
|
||||
case Farc.FARC:
|
||||
compressed = (FARCFlags & Flags.GZip) != 0;
|
||||
encrypted = (FARCFlags & Flags.AES) != 0;
|
||||
break;
|
||||
case Farc.FArC:
|
||||
FARCFlags = Flags.None;
|
||||
compressed = true;
|
||||
break;
|
||||
default:
|
||||
FARCFlags = Flags.None;
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < files.Length; i++)
|
||||
Files.Add(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]), Compressed = compressed, Encrypted = encrypted });
|
||||
files = null;
|
||||
Signature = signature;
|
||||
Save();
|
||||
}
|
||||
|
||||
@@ -227,22 +367,28 @@ namespace KKdMainLib
|
||||
|
||||
using (Stream headerWriter = File.OpenWriter())
|
||||
{
|
||||
if (Signature == Farc.FArc) headerWriter.WE(0x01, true);
|
||||
else if (Signature == Farc.FArC) headerWriter.WE(0x01, true);
|
||||
else if (Signature == Farc.FARC)
|
||||
switch (Signature)
|
||||
{
|
||||
headerWriter.WE((int)FARCType, true);
|
||||
headerWriter.W (0x00);
|
||||
headerWriter.WE(0x40, true);
|
||||
headerWriter.W (0x00);
|
||||
headerWriter.W (0x00);
|
||||
case Farc.FArc:
|
||||
headerWriter.WE(0x01, true);
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
{ headerWriter.W(Files[i].Name + "\0"); headerWriter.W(0x00L); }
|
||||
break;
|
||||
case Farc.FArC:
|
||||
headerWriter.WE(0x01, true);
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
{ headerWriter.W(Files[i].Name + "\0"); headerWriter.W(0x00L); headerWriter.W(0x00); }
|
||||
break;
|
||||
case Farc.FARC:
|
||||
headerWriter.WE((int)FARCFlags, true);
|
||||
headerWriter.W (0x00);
|
||||
headerWriter.WE(0x40, true);
|
||||
headerWriter.W (0x00);
|
||||
headerWriter.W (0x00);
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
{ headerWriter.W(Files[i].Name + "\0"); headerWriter.W(0x00L); headerWriter.W(0x00L); }
|
||||
break;
|
||||
}
|
||||
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));
|
||||
}
|
||||
@@ -256,13 +402,55 @@ namespace KKdMainLib
|
||||
CompressStuff(i, ref writer);
|
||||
|
||||
writer.P = Signature == Farc.FARC ? 0x1C : 0x0C;
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
switch (Signature)
|
||||
{
|
||||
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);
|
||||
case Farc.FArc:
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
{
|
||||
FARCFile file = Files[i];
|
||||
writer.W (file.Name + "\0");
|
||||
writer.WE(file.Offset, true);
|
||||
writer.WE(file.Size , true);
|
||||
}
|
||||
break;
|
||||
case Farc.FArC:
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
{
|
||||
FARCFile file = Files[i];
|
||||
writer.W (file.Name + "\0");
|
||||
writer.WE(file.Offset , true);
|
||||
if (file.Compressed)
|
||||
{
|
||||
writer.WE(file.SizeComp, true);
|
||||
writer.WE(file.Size , true);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WE(file.Size , true);
|
||||
writer.WE(0x00 , true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Farc.FARC:
|
||||
for (int i = 0; i < Files.Count; i++)
|
||||
{
|
||||
FARCFile file = Files[i];
|
||||
writer.W (file.Name + "\0");
|
||||
writer.WE(file.Offset , true);
|
||||
if (file.Compressed)
|
||||
{
|
||||
writer.WE(file.SizeComp, true);
|
||||
writer.WE(file.Size , true);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WE(file.Size , true);
|
||||
writer.WE(0x00 , true);
|
||||
}
|
||||
writer.WE((uint)((file.Compressed ? Flags.GZip : 0x00)
|
||||
| (file.Encrypted ? Flags.AES : 0x00)), true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
writer.Dispose();
|
||||
}
|
||||
@@ -271,24 +459,20 @@ namespace KKdMainLib
|
||||
{
|
||||
FARCFile file = Files[i];
|
||||
file.Offset = writer.P;
|
||||
file.SizeUnc = file.Data.Length;
|
||||
file.Type = Type.None;
|
||||
file.Size = file.Data.Length;
|
||||
|
||||
byte[] data = file.Data;
|
||||
if (Signature == Farc.FArC || (Signature == Farc.FARC && (FARCType & Type.GZip) != 0))
|
||||
{
|
||||
file.Type |= Type.GZip;
|
||||
if (file.Compressed)
|
||||
data = file.Data.DeflateGZip(CompressionLevel);
|
||||
}
|
||||
file.SizeComp = data.Length;
|
||||
|
||||
if (Signature == Farc.FARC && (FARCType & Type.Enc) != 0)
|
||||
if (file.Encrypted)
|
||||
{
|
||||
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);
|
||||
data = Encrypt(tempData);
|
||||
}
|
||||
writer.W(data);
|
||||
|
||||
@@ -301,26 +485,28 @@ namespace KKdMainLib
|
||||
Files[i] = file;
|
||||
}
|
||||
|
||||
private byte[] Encrypt(byte[] data, bool isFT)
|
||||
private byte[] Encrypt(byte[] data)
|
||||
{
|
||||
MSIO.MemoryStream stream = new MSIO.MemoryStream();
|
||||
using (AesManaged aes = GetAes(isFT, null))
|
||||
using (CryptoStream cryptoStream = new CryptoStream(stream,
|
||||
aes.CreateEncryptor(), CryptoStreamMode.Write))
|
||||
cryptoStream.Write(data, 0, data.Length);
|
||||
return stream.ToArray();
|
||||
MSIO.MemoryStream ms = new MSIO.MemoryStream();
|
||||
using (AesManaged aes = GetAes())
|
||||
using (CryptoStream cryptoStream = new CryptoStream(ms,
|
||||
aes.CreateDecryptor(), CryptoStreamMode.Write))
|
||||
cryptoStream.Write(data, 0x00, data.Length);
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
public void Dispose() => NewFARC();
|
||||
|
||||
public struct FARCFile
|
||||
{
|
||||
public int Offset;
|
||||
public int SizeComp;
|
||||
public int SizeUnc;
|
||||
public Type Type;
|
||||
public byte[] Data;
|
||||
public string Name;
|
||||
public int Offset;
|
||||
public int Size;
|
||||
public int SizeComp;
|
||||
public byte[] Data;
|
||||
public byte[] DataComp;
|
||||
public bool Compressed;
|
||||
public bool Encrypted;
|
||||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
@@ -332,11 +518,11 @@ namespace KKdMainLib
|
||||
FARC = 0x46415243,
|
||||
}
|
||||
|
||||
public enum Type : int
|
||||
public enum Flags : int
|
||||
{
|
||||
None = 0b000,
|
||||
GZip = 0b010,
|
||||
Enc = 0b100,
|
||||
AES = 0b100,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+488
-151
@@ -1,12 +1,26 @@
|
||||
//Original or reader part: https://github.com/MarcosLopezC/LightJson/
|
||||
|
||||
using KKdBaseLib;
|
||||
using System;
|
||||
using System.IO;
|
||||
using BaseExtensions = KKdBaseLib.Extensions;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public struct JSON : System.IDisposable
|
||||
{
|
||||
struct ReadBuffer
|
||||
{
|
||||
public char[] data;
|
||||
public int first;
|
||||
public int length;
|
||||
|
||||
public ReadBuffer(int size)
|
||||
{
|
||||
data = new char[size];
|
||||
first = 0;
|
||||
length = 0;
|
||||
}
|
||||
};
|
||||
|
||||
public JSON(Stream _IO) => this._IO = _IO;
|
||||
|
||||
private Stream _IO;
|
||||
@@ -15,176 +29,499 @@ namespace KKdMainLib.IO
|
||||
|
||||
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
|
||||
|
||||
public MsgPack Read() => ReadValue();
|
||||
|
||||
private MsgPack ReadValue(string Key = null)
|
||||
public MsgPack Read()
|
||||
{
|
||||
char c = _IO.SW().PCUTF8();
|
||||
object obj = null;
|
||||
if (char.IsDigit(c))
|
||||
obj = RF();
|
||||
else
|
||||
obj = c switch
|
||||
{
|
||||
'"' => RS (),
|
||||
'{' => RO (),
|
||||
'[' => RA (),
|
||||
'-' => RF (),
|
||||
't' => RBo(),
|
||||
'f' => RBo(),
|
||||
'n' => RN (),
|
||||
_ => null ,
|
||||
};
|
||||
return new MsgPack(Key, obj);
|
||||
ReadBuffer buf = new ReadBuffer(0x400);
|
||||
buf.first = 0;
|
||||
buf.length = 0;
|
||||
buf.data[0] = '\0';
|
||||
buf.data[buf.data.Length - 1] = '\0';
|
||||
int c = ReadChar(ref buf);
|
||||
return new MsgPack(null, ReadInner(ref buf, ref c));
|
||||
}
|
||||
|
||||
private string RS()
|
||||
int ReadChar(ref ReadBuffer buf)
|
||||
{
|
||||
if (!Extensions.As(_IO, '"')) return null;
|
||||
char c;
|
||||
string s = "";
|
||||
while (true)
|
||||
if (buf.length == 0)
|
||||
{
|
||||
c = _IO.RCUTF8();
|
||||
buf.first = 1;
|
||||
buf.data[0] = buf.data[buf.data.Length - 1];
|
||||
byte[] temp = new byte[buf.data.Length];
|
||||
buf.length = _IO.RBy(buf.data.Length - 1, temp);
|
||||
Array.Copy(temp, 0, buf.data, 1, buf.length);
|
||||
}
|
||||
|
||||
if (buf.length < 1)
|
||||
return -1;
|
||||
|
||||
int c = buf.data[buf.first];
|
||||
buf.first++;
|
||||
buf.length--;
|
||||
return c;
|
||||
}
|
||||
|
||||
void Seek(ref ReadBuffer buf, long offset)
|
||||
{
|
||||
if (buf.first < offset || offset >= buf.length - 1L) {
|
||||
long pos = _IO.PI64 - buf.length - offset;
|
||||
long off = pos % buf.data.Length;
|
||||
pos -= off;
|
||||
if (pos > 1)
|
||||
{
|
||||
_IO.S(pos, SeekOrigin.Begin);
|
||||
buf.first = (int)off;
|
||||
byte[] temp = _IO.RBy(buf.data.Length);
|
||||
buf.length = temp.Length;
|
||||
Array.Copy(temp, 0, buf.data, 0, temp.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
_IO.S(pos, SeekOrigin.Begin);
|
||||
buf.first = (int)(off + 1);
|
||||
buf.data[0] = '\0';
|
||||
byte[] temp = _IO.RBy(buf.data.Length - 1);
|
||||
buf.length = temp.Length;
|
||||
Array.Copy(temp, 0, buf.data, 1, temp.Length);
|
||||
}
|
||||
buf.length -= (int)off;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf.first -= (int)offset;
|
||||
buf.length += (int)offset;
|
||||
}
|
||||
}
|
||||
|
||||
void SeekOne(ref ReadBuffer buf)
|
||||
{
|
||||
buf.first--;
|
||||
buf.length++;
|
||||
}
|
||||
|
||||
object ReadInner(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
if (c == -1)
|
||||
return null;
|
||||
|
||||
if (c == ' ' || c == '\n' || c == '\r' || c == '\t')
|
||||
c = ReadChar(ref buf);
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
case '3':
|
||||
case '4':
|
||||
case '5':
|
||||
case '6':
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
case '-':
|
||||
return ReadFloat(ref buf, ref c);
|
||||
case '"':
|
||||
return ReadString(ref buf, ref c);
|
||||
case '{':
|
||||
return ReadMap(ref buf, ref c);
|
||||
case '[':
|
||||
return ReadArray(ref buf, ref c);
|
||||
case 't':
|
||||
return ReadBool(ref buf, ref c);
|
||||
case 'f':
|
||||
return ReadBool(ref buf, ref c);
|
||||
case 'n':
|
||||
return ReadNull(ref buf, ref c);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void ReadDigit(ref ReadBuffer buf, ref int c, byte[] dig_buf, ref int dig_buf_pos, int dig_buf_end) {
|
||||
int b = dig_buf_pos;
|
||||
while (c >= '0' && c <= '9' && b < dig_buf_end) {
|
||||
dig_buf[b++] = (byte)c;
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
break;
|
||||
}
|
||||
dig_buf_pos = b;
|
||||
}
|
||||
|
||||
object ReadFloat(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
byte[] dig_buf = new byte[0x100];
|
||||
int buf_pos = 0;
|
||||
int buf_end = dig_buf.Length;
|
||||
bool negate = false;
|
||||
bool zero = false;
|
||||
bool fraction = false;
|
||||
|
||||
if (c == '-')
|
||||
{
|
||||
dig_buf[buf_pos++] = (byte)c;
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
return null;
|
||||
negate = true;
|
||||
}
|
||||
|
||||
if (c == '0')
|
||||
{
|
||||
dig_buf[buf_pos++] = (byte)c;
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
return null;
|
||||
zero = true;
|
||||
}
|
||||
else
|
||||
ReadDigit(ref buf, ref c, dig_buf, ref buf_pos, buf_end);
|
||||
|
||||
if (c == '.')
|
||||
{
|
||||
dig_buf[buf_pos++] = (byte)c;
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
return null;
|
||||
ReadDigit(ref buf, ref c, dig_buf, ref buf_pos, buf_end);
|
||||
fraction = true;
|
||||
}
|
||||
|
||||
if (zero && !fraction)
|
||||
{
|
||||
object obj;
|
||||
if (negate)
|
||||
obj = -0.0f;
|
||||
else
|
||||
obj = 0;
|
||||
SeekOne(ref buf);
|
||||
return obj;
|
||||
}
|
||||
else if (c != 'e' && c != 'E' && !fraction)
|
||||
{
|
||||
string temp = dig_buf.ToUTF8();
|
||||
int null_term = temp.IndexOf('\0');
|
||||
if (null_term >= 0)
|
||||
temp = temp.Substring(0, null_term);
|
||||
if (!long.TryParse(temp, out long val))
|
||||
return null;
|
||||
|
||||
object obj;
|
||||
unchecked
|
||||
{
|
||||
if (val >= 0x00 && val <= 0xFF)
|
||||
obj = (byte)val;
|
||||
else if (val >= (sbyte)0x80 && val <= (sbyte)0x7F)
|
||||
obj = (sbyte)val;
|
||||
else if (val >= 0x0000 && val <= 0xFFFF)
|
||||
obj = (ushort)val;
|
||||
else if (val >= (short)0x8000 && val <= (short)0x7FFF)
|
||||
obj = (short)val;
|
||||
else if (val >= 0x00000000 && val <= 0xFFFFFFFF)
|
||||
obj = (uint)val;
|
||||
else if (val >= (int)0x80000000 && val <= (int)0x7FFFFFFF)
|
||||
obj = (int)val;
|
||||
else
|
||||
obj = val;
|
||||
}
|
||||
SeekOne(ref buf);
|
||||
return obj;
|
||||
}
|
||||
else if (c == 'e' || c == 'E')
|
||||
{
|
||||
dig_buf[buf_pos++] = (byte)c;
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
return null;
|
||||
|
||||
if (c == '+' || c == '-')
|
||||
{
|
||||
dig_buf[buf_pos++] = (byte)c;
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
return null;
|
||||
}
|
||||
ReadDigit(ref buf, ref c, dig_buf, ref buf_pos, buf_end);
|
||||
}
|
||||
|
||||
string ftemp = dig_buf.ToUTF8();
|
||||
int fnull_term = ftemp.IndexOf('\0');
|
||||
if (fnull_term >= 0)
|
||||
ftemp = ftemp.Substring(0, fnull_term);
|
||||
if (!ftemp.ToF64(out double fval))
|
||||
return null;
|
||||
|
||||
object fobj;
|
||||
if (fval == (float)fval)
|
||||
fobj = (float)fval;
|
||||
else
|
||||
fobj = fval;
|
||||
SeekOne(ref buf);
|
||||
return fobj;
|
||||
}
|
||||
|
||||
byte ReadStringHex(int c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return (byte)(c - '0');
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
return (byte)(c - 'A' + 0xA);
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
return (byte)(c - 'a' + 0xA);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
string ReadStringInner(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
if (c != '"')
|
||||
return null;
|
||||
|
||||
long pos = _IO.PI64 - buf.length;
|
||||
ulong len = 0;
|
||||
while (c != -1)
|
||||
{
|
||||
c = ReadChar(ref buf);
|
||||
if (c == '\\')
|
||||
{
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
break;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '"':
|
||||
case '\\':
|
||||
case '/':
|
||||
case 'b':
|
||||
case 'f':
|
||||
case 'n':
|
||||
case 'r':
|
||||
case 't':
|
||||
len++;
|
||||
break;
|
||||
case 'u':
|
||||
{
|
||||
uint uc = 0;
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
break;
|
||||
uc |= (uint)ReadStringHex(c) << 24;
|
||||
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
break;
|
||||
uc |= (uint)ReadStringHex(c) << 16;
|
||||
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
break;
|
||||
uc |= (uint)ReadStringHex(c) << 8;
|
||||
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
break;
|
||||
uc |= (uint)ReadStringHex(c);
|
||||
|
||||
if (uc <= 0x7F)
|
||||
len++;
|
||||
else if (c <= 0x7FF)
|
||||
len += 2;
|
||||
else
|
||||
len += 3;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (c == '"')
|
||||
break;
|
||||
else
|
||||
len++;
|
||||
}
|
||||
if (c == -1)
|
||||
return null;
|
||||
long pos_end = _IO.PI64 - buf.length;
|
||||
|
||||
Seek(ref buf, pos_end - pos);
|
||||
byte[] temp = new byte[len + 1];
|
||||
for (ulong i = 0; i < len;)
|
||||
{
|
||||
c = ReadChar(ref buf);
|
||||
|
||||
if (c == '\\')
|
||||
{
|
||||
c = _IO.RCUTF8();
|
||||
c = ReadChar(ref buf);
|
||||
|
||||
switch (char.ToLower(c))
|
||||
switch (c)
|
||||
{
|
||||
case '"' :
|
||||
case '"':
|
||||
temp[i++] = (byte)'"';
|
||||
break;
|
||||
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;
|
||||
temp[i++] = (byte)'\\';
|
||||
break;
|
||||
case '/':
|
||||
temp[i++] = (byte)'/';
|
||||
break;
|
||||
case 'b':
|
||||
temp[i++] = (byte)'\b';
|
||||
break;
|
||||
case 'f':
|
||||
temp[i++] = (byte)'\f';
|
||||
break;
|
||||
case 'n':
|
||||
temp[i++] = (byte)'\n';
|
||||
break;
|
||||
case 'r':
|
||||
temp[i++] = (byte)'\r';
|
||||
break;
|
||||
case 't':
|
||||
temp[i++] = (byte)'\t';
|
||||
break;
|
||||
case 'u':
|
||||
{
|
||||
uint uc = 0;
|
||||
uc |= (uint)ReadStringHex(ReadChar(ref buf)) << 24;
|
||||
uc |= (uint)ReadStringHex(ReadChar(ref buf)) << 16;
|
||||
uc |= (uint)ReadStringHex(ReadChar(ref buf)) << 8;
|
||||
uc |= (uint)ReadStringHex(ReadChar(ref buf));
|
||||
if (uc <= 0x7F)
|
||||
temp[i] = (byte)uc;
|
||||
else if (uc <= 0x7FF)
|
||||
{
|
||||
temp[i++] = (byte)(0xC0 | ((uc >> 6) & 0x1F));
|
||||
temp[i] = (byte)(0x80 | (uc & 0x3F));
|
||||
}
|
||||
else
|
||||
{
|
||||
temp[i++] = (byte)(0xE0 | ((uc >> 12) & 0xF));
|
||||
temp[i++] = (byte)(0x80 | ((uc >> 6) & 0x3F));
|
||||
temp[i++] = (byte)(0x80 | (uc & 0x3F));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (c == '"') break;
|
||||
else if (char.IsControl(c))
|
||||
else if (c == '"')
|
||||
break;
|
||||
else
|
||||
temp[i++] = (byte)c;
|
||||
}
|
||||
|
||||
if ((c = ReadChar(ref buf)) == -1)
|
||||
return null;
|
||||
|
||||
string str = temp.ToUTF8();
|
||||
int null_term = str.IndexOf('\0');
|
||||
if (null_term >= 0)
|
||||
str = str.Substring(0, null_term);
|
||||
return str;
|
||||
}
|
||||
|
||||
object ReadString(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
return ReadStringInner(ref buf, ref c);
|
||||
}
|
||||
|
||||
void ReadSkipWhitespace(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
while ((c = ReadChar(ref buf)) != -1)
|
||||
{
|
||||
if (c == ' ' || c == '\n' || c == '\r' || c == '\t')
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
object ReadMap(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
KKdList<MsgPack> map = KKdList<MsgPack>.New;
|
||||
if (c != '}')
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
ReadSkipWhitespace(ref buf, ref c);
|
||||
|
||||
if (c == '}')
|
||||
break;
|
||||
|
||||
string key = ReadStringInner(ref buf, ref c);
|
||||
if (key == null)
|
||||
return null;
|
||||
|
||||
ReadSkipWhitespace(ref buf, ref c);
|
||||
if (c != ':')
|
||||
return null;
|
||||
ReadSkipWhitespace(ref buf, ref c);
|
||||
|
||||
map.Add(new MsgPack(key, ReadInner(ref buf, ref c)));
|
||||
|
||||
ReadSkipWhitespace(ref buf, ref c);
|
||||
|
||||
if (c == '}')
|
||||
break;
|
||||
else if (c != ',')
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
map.Capacity = map.Count;
|
||||
return map;
|
||||
}
|
||||
|
||||
object ReadArray(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
KKdList<MsgPack> array = KKdList<MsgPack>.New;
|
||||
if (c != ']')
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
ReadSkipWhitespace(ref buf, ref c);
|
||||
|
||||
if (c == ']')
|
||||
break;
|
||||
|
||||
array.Add(new MsgPack(null, ReadInner(ref buf, ref c)));
|
||||
|
||||
ReadSkipWhitespace(ref buf, ref c);
|
||||
|
||||
if (c == ']')
|
||||
break;
|
||||
else if (c != ',')
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
array.Capacity = array.Count;
|
||||
return array.ToArray();
|
||||
}
|
||||
|
||||
object ReadBool(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
if (c != 't')
|
||||
{
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'a')
|
||||
return null;
|
||||
else s += c;
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'l')
|
||||
return null;
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 's')
|
||||
return null;
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'e')
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private char RUL() =>
|
||||
(char)((((((RHD() << 4) | RHD()) << 4) | RHD()) << 4) | RHD());
|
||||
|
||||
private int RHD() => byte.Parse(_IO.RCUTF8().ToString(),
|
||||
System.Globalization.NumberStyles.HexNumber);
|
||||
|
||||
private KKdList<MsgPack> RO()
|
||||
{
|
||||
KKdList<MsgPack> obj = KKdList<MsgPack>.New;
|
||||
if (!Extensions.As(_IO, '{')) return KKdList<MsgPack>.Null;
|
||||
if (_IO.SW().PCUTF8() == '}')
|
||||
{ _IO.RCUTF8(); return KKdList<MsgPack>.Null; }
|
||||
|
||||
string key;
|
||||
char c;
|
||||
while (true)
|
||||
{
|
||||
_IO.SW();
|
||||
|
||||
key = RS();
|
||||
if (!Extensions.As(_IO.SW(), ':'))
|
||||
return KKdList<MsgPack>.Null;
|
||||
|
||||
obj.Add(ReadValue(key));
|
||||
c = _IO.SW().PCUTF8();
|
||||
|
||||
if (c == '}') { _IO.RCUTF8(); break; }
|
||||
else if (c == ',') { _IO.RCUTF8(); continue; }
|
||||
else return KKdList<MsgPack>.Null;
|
||||
}
|
||||
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 obj.ToArray(); }
|
||||
|
||||
char c;
|
||||
while (true)
|
||||
{
|
||||
obj.Add(ReadValue(null));
|
||||
c = _IO.SW().PCUTF8();
|
||||
|
||||
if (c == ']') { _IO.RCUTF8(); break; }
|
||||
else if (c == ',') { _IO.RCUTF8(); continue; }
|
||||
else return null;
|
||||
}
|
||||
obj.Capacity = obj.Count;
|
||||
return obj.ToArray();
|
||||
}
|
||||
|
||||
private object RF()
|
||||
{
|
||||
string s = "";
|
||||
_IO.SW();
|
||||
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')
|
||||
{
|
||||
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;
|
||||
else if (val >= 0x00000000 && val < 0x000010000) return (ushort)val;
|
||||
else if (val >= -0x80000000 && val < 0x000800000) return ( int)val;
|
||||
else if (val >= 0x00000000 && val < 0x100000000) return ( uint)val;
|
||||
else return val;
|
||||
}
|
||||
|
||||
c = _IO.PCUTF8();
|
||||
if (c == 'e' || c == 'E')
|
||||
{
|
||||
s += _IO.RCUTF8();
|
||||
c = _IO.PCUTF8();
|
||||
if (c == '+' || c == '-') s += _IO.RCUTF8();
|
||||
s += RD();
|
||||
}
|
||||
double d = s.ToF64();
|
||||
if ((float)d == d)
|
||||
return negative ? (((float)d).ToU32() | 0x80000000).ToF32() : (float)d;
|
||||
else
|
||||
return negative ? (d.ToU64() | 0x8000000000000000).ToF64() : d;
|
||||
{
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'r')
|
||||
return null;
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'u')
|
||||
return null;
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'e')
|
||||
return null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool RBo()
|
||||
object ReadNull(ref ReadBuffer buf, ref int c)
|
||||
{
|
||||
char c = _IO.PCUTF8();
|
||||
if (c == 't' && _IO.As( "true")) return true;
|
||||
else if (c == 'f' && _IO.As("false")) return false;
|
||||
return false;
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'u')
|
||||
return null;
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'l')
|
||||
return null;
|
||||
if ((c = ReadChar(ref buf)) == -1 || c != 'l')
|
||||
return null;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private object RN() { _IO.As("null"); return null; }
|
||||
|
||||
private string RD()
|
||||
{ string s = ""; while (char.IsDigit(_IO.SW().
|
||||
PCUTF8())) s += _IO.RCUTF8(); return s; }
|
||||
|
||||
public JSON W(MsgPack msgPack, bool ignoreNull, string end = "\n", string tabChar = " ") =>
|
||||
W(msgPack, ignoreNull, end, tabChar, "", true);
|
||||
|
||||
|
||||
+342
-342
@@ -1,342 +1,342 @@
|
||||
using KKdBaseLib;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public struct MP : System.IDisposable
|
||||
{
|
||||
public MP(Stream _IO) => this._IO = _IO;
|
||||
|
||||
private Stream _IO;
|
||||
|
||||
public void Close() => _IO.C();
|
||||
|
||||
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
|
||||
|
||||
public MsgPack Read(bool array = false)
|
||||
{
|
||||
MsgPack msgPack = MsgPack.New;
|
||||
byte unk = _IO.RU8();
|
||||
if (!array) { msgPack.Name = RS((Types)unk); unk = _IO.RU8(); }
|
||||
Types type = (Types)unk;
|
||||
|
||||
if (type >= Types.FixMap && type <= Types.FixMapMax)
|
||||
{
|
||||
msgPack.Object = KKdList<MsgPack>.New;
|
||||
for (int i = 0; i < unk - (byte)Types.FixMap; i++) msgPack.Add( Read(false));
|
||||
}
|
||||
else if (type >= Types.FixArr && type <= Types.FixArrMax)
|
||||
{
|
||||
msgPack.Object = new MsgPack[unk - (byte)Types.FixArr];
|
||||
for (int i = 0; i < unk - (byte)Types.FixArr; i++) msgPack[i] = Read( true);
|
||||
}
|
||||
else if (type >= Types.FixStr && type <= Types.FixStrMax) msgPack.Object = RS(type);
|
||||
else if (type >= Types.PosInt && type <= Types.PosIntMax) msgPack.Object = unk;
|
||||
else if (type >= Types.NegInt && type <= Types.NegIntMax) msgPack.Object = (sbyte)unk;
|
||||
else
|
||||
while (true)
|
||||
{
|
||||
if (RN (ref msgPack, ref type)) break;
|
||||
if (RBy(ref msgPack, ref type)) break;
|
||||
if (RM (ref msgPack, ref type)) break;
|
||||
if (RE (ref msgPack, ref type)) break;
|
||||
if (RS (ref msgPack, ref type)) break;
|
||||
if (RBo(ref msgPack, ref type)) break;
|
||||
if (RA (ref msgPack, ref type)) break;
|
||||
if (RI (ref msgPack, ref type)) break;
|
||||
if (RU (ref msgPack, ref type)) break;
|
||||
if (RF (ref msgPack, ref type)) break;
|
||||
break;
|
||||
}
|
||||
return msgPack;
|
||||
}
|
||||
|
||||
private bool RI(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
if (type == Types.Int8 ) msgPack.Object = _IO.RI8();
|
||||
else if (type == Types.Int16) msgPack.Object = _IO.RI16E(true);
|
||||
else if (type == Types.Int32) msgPack.Object = _IO.RI32E(true);
|
||||
else if (type == Types.Int64) msgPack.Object = _IO.RI64E(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RU(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
if (type == Types.UInt8 ) msgPack.Object = _IO.RU8();
|
||||
else if (type == Types.UInt16) msgPack.Object = _IO.RU16E(true);
|
||||
else if (type == Types.UInt32) msgPack.Object = _IO.RU32E(true);
|
||||
else if (type == Types.UInt64) msgPack.Object = _IO.RU64E(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RF(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
if (type == Types.Float32) msgPack.Object = _IO.RF32E(true);
|
||||
else if (type == Types.Float64) msgPack.Object = _IO.RF64E(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RBo(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
if (type == Types.False) msgPack.Object = false;
|
||||
else if (type == Types.True ) msgPack.Object = true ;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RBy(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (type == Types.Bin8 ) Length = _IO.RU8();
|
||||
else if (type == Types.Bin16) Length = _IO.RI16E(true);
|
||||
else if (type == Types.Bin32) Length = _IO.RI32E(true);
|
||||
else return false;
|
||||
msgPack.Object = _IO.RBy(Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RS(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
string val = RS(type);
|
||||
if (val != null) msgPack.Object = val;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private string RS(Types val)
|
||||
{
|
||||
if (val >= Types.FixStr && val <= Types.FixStrMax)
|
||||
return _IO.RS(val - Types.FixStr);
|
||||
else if (val >= Types. Str8 && val <= Types. Str32 )
|
||||
{
|
||||
System.Enum.TryParse(val.ToString(), out Types type);
|
||||
int Length = 0;
|
||||
if (type == Types.Str8 ) Length = _IO.RU8();
|
||||
else if (type == Types.Str16) Length = _IO.RI16E(true);
|
||||
else Length = _IO.RI32E(true);
|
||||
return _IO.RS(Length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool RN(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
if (type == Types.Nil) msgPack.Object = null;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RA(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (type == Types.Arr16) Length = _IO.RI16E(true);
|
||||
else if (type == Types.Arr32) Length = _IO.RI32E(true);
|
||||
else return false;
|
||||
msgPack.Object = new MsgPack[Length];
|
||||
for (int i = 0; i < Length; i++) msgPack[i] = Read(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RM(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (type == Types.Map16) Length = _IO.RI16E(true);
|
||||
else if (type == Types.Map32) Length = _IO.RI32E(true);
|
||||
else return false;
|
||||
msgPack.Object = KKdList<MsgPack>.New;
|
||||
for (int i = 0; i < Length; i++) msgPack.Add(Read());
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RE(ref MsgPack MsgPack, ref Types type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (type == Types.FixExt1 ) Length = 1 ;
|
||||
else if (type == Types.FixExt2 ) Length = 2 ;
|
||||
else if (type == Types.FixExt4 ) Length = 4 ;
|
||||
else if (type == Types.FixExt8 ) Length = 8 ;
|
||||
else if (type == Types.FixExt16) Length = 16;
|
||||
else if (type == Types. Ext8 ) Length = _IO.RU8();
|
||||
else if (type == Types. Ext16) Length = _IO.RI16E(true);
|
||||
else if (type == Types. Ext32) Length = _IO.RI32E(true);
|
||||
else return false;
|
||||
MsgPack.Object = new MsgPack.Ext { Type = _IO.RI8(), Data = _IO.RBy(Length) };
|
||||
return true;
|
||||
}
|
||||
|
||||
public MP W(MsgPack msgPack, bool ignoreNull, bool IsArray = false)
|
||||
{
|
||||
if (msgPack.Name != null && !IsArray) W(msgPack.Name);
|
||||
Write(msgPack.Object, ignoreNull);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void Write(object obj, bool ignoreNull)
|
||||
{
|
||||
if (obj == null) { if (!ignoreNull) WN(); return; }
|
||||
switch (obj)
|
||||
{
|
||||
case KKdList<MsgPack> val: WM(val.Count );
|
||||
for (int i = 0; i < val.Count ; i++) W(val[i], ignoreNull); break;
|
||||
case MsgPack[] val: WA(val.Length);
|
||||
for (int i = 0; i < val.Length; i++) W(val[i], ignoreNull); break;
|
||||
case MsgPack val: W(val, ignoreNull); break;
|
||||
case byte[] val: W(val); break;
|
||||
case bool val: W(val); break;
|
||||
case sbyte val: W(val); break;
|
||||
case byte val: W(val); break;
|
||||
case short val: W(val); break;
|
||||
case ushort val: W(val); break;
|
||||
case int val: W(val); break;
|
||||
case uint val: W(val); break;
|
||||
case long val: W(val); break;
|
||||
case ulong val: W(val); break;
|
||||
case float val: W(val); break;
|
||||
case double val: W(val); break;
|
||||
case string val: W(val); break;
|
||||
case MsgPack.Ext val: W(val); break;
|
||||
}
|
||||
}
|
||||
|
||||
private void W( sbyte val) { if (val < -0x20) _IO.W((byte)0xD0); _IO.W(val); }
|
||||
private void W( byte val) { if (val >= 0x80) _IO.W((byte)0xCC); _IO.W(val); }
|
||||
private void W( short val) { if (( sbyte)val == val) W(( sbyte)val);
|
||||
else if (( byte)val == val) W(( byte)val);
|
||||
else { _IO.W((byte)0xD1); _IO.WE(val, true); } }
|
||||
private void W(ushort val) { if (( byte)val == val) W(( byte)val);
|
||||
else { _IO.W((byte)0xCD); _IO.WE(val, true); } }
|
||||
private void W( int val) { if (( short)val == val) W(( short)val);
|
||||
else if ((ushort)val == val) W((ushort)val);
|
||||
else { _IO.W((byte)0xD2); _IO.WE(val, true); } }
|
||||
private void W( uint val) { if ((ushort)val == val) W((ushort)val);
|
||||
else { _IO.W((byte)0xCE); _IO.WE(val, true); } }
|
||||
private void W( long val) { if (( int)val == val) W(( int)val);
|
||||
else if (( uint)val == val) W(( uint)val);
|
||||
else { _IO.W((byte)0xD3); _IO.WE(val, true); } }
|
||||
private void W( ulong val) { if (( uint)val == val) W(( uint)val);
|
||||
else { _IO.W((byte)0xCF); _IO.WE(val, true); } }
|
||||
private void W( float val) { if (( long)val == val) W(( long)val);
|
||||
else { _IO.W((byte)0xCA); _IO.WE(val, true); } }
|
||||
private void W(double val) { if (( long)val == val) W(( long)val);
|
||||
else if (( float)val == val) W(( float)val);
|
||||
else { _IO.W((byte)0xCB); _IO.WE(val, true); } }
|
||||
|
||||
private void W( bool val) =>
|
||||
_IO.W((byte)(val ? 0xC3 : 0xC2));
|
||||
|
||||
private void W(byte[] val)
|
||||
{
|
||||
if (val == null) { WN(); return; }
|
||||
|
||||
if (val.Length < 0x100) { _IO.W((byte)0xC4); _IO.W (( byte)val.Length ); }
|
||||
else if (val.Length < 0x10000) { _IO.W((byte)0xC5); _IO.WE((ushort)val.Length, true); }
|
||||
else { _IO.W((byte)0xC6); _IO.WE( val.Length, true); }
|
||||
_IO.W(val);
|
||||
}
|
||||
|
||||
private void W(string val)
|
||||
{
|
||||
if (val == null) { WN(); return; }
|
||||
|
||||
byte[] array = Text.ToUTF8(val);
|
||||
if (array.Length < 0x20) _IO.W((byte)(0xA0 | (array.Length & 0x1F)));
|
||||
else if (array.Length < 0x100) { _IO.W((byte)0xD9); _IO.W (( byte)array.Length); }
|
||||
else if (array.Length < 0x10000) { _IO.W((byte)0xDA); _IO.WE((ushort)array.Length, true); }
|
||||
else { _IO.W((byte)0xDB); _IO.WE( array.Length, true); }
|
||||
_IO.W(array);
|
||||
}
|
||||
|
||||
private void WN() => _IO.W((byte)0xC0);
|
||||
|
||||
private void WA(int val)
|
||||
{
|
||||
if (val == 0) { WN(); return; }
|
||||
else if (val < 0x10) _IO.W((byte)(0x90 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.W((byte)0xDC); _IO.WE((ushort)val, true); }
|
||||
else { _IO.W((byte)0xDD); _IO.WE( val, true); }
|
||||
}
|
||||
|
||||
private void WM(int val)
|
||||
{
|
||||
if (val == 0) { WN(); return; }
|
||||
else if (val < 0x10) _IO.W((byte)(0x80 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.W((byte)0xDE); _IO.WE((ushort)val, true); }
|
||||
else { _IO.W((byte)0xDF); _IO.WE( val, true); }
|
||||
}
|
||||
|
||||
private void W(MsgPack.Ext val) => WE(val);
|
||||
|
||||
private void WE(MsgPack.Ext val)
|
||||
{
|
||||
if (val.Data == null) { WN(); return; }
|
||||
|
||||
if (val.Data.Length < 1 ) { WN(); return; }
|
||||
else if (val.Data.Length == 1 ) _IO.W((byte)0xD4);
|
||||
else if (val.Data.Length == 2 ) _IO.W((byte)0xD5);
|
||||
else if (val.Data.Length == 4 ) _IO.W((byte)0xD6);
|
||||
else if (val.Data.Length == 8 ) _IO.W((byte)0xD7);
|
||||
else if (val.Data.Length == 16) _IO.W((byte)0xD8);
|
||||
else
|
||||
{
|
||||
if (val.Data.Length < 0x100)
|
||||
{ _IO.W((byte)0xC7); _IO.W (( byte)val.Data.Length); }
|
||||
else if (val.Data.Length < 0x10000)
|
||||
{ _IO.W((byte)0xC8); _IO.WE((ushort)val.Data.Length, true); }
|
||||
else
|
||||
{ _IO.W((byte)0xC9); _IO.WE( val.Data.Length, true); }
|
||||
}
|
||||
_IO.W(val.Type);
|
||||
_IO.W(val.Data);
|
||||
}
|
||||
|
||||
public void Dispose() => _IO.C();
|
||||
}
|
||||
|
||||
public enum Types : byte
|
||||
{
|
||||
PosInt = 0b00000000,
|
||||
FixMap = 0b10000000,
|
||||
FixArr = 0b10010000,
|
||||
FixStr = 0b10100000,
|
||||
Nil = 0b11000000,
|
||||
NeverUsed = 0b11000001,
|
||||
False = 0b11000010,
|
||||
True = 0b11000011,
|
||||
Bin8 = 0b11000100,
|
||||
Bin16 = 0b11000101,
|
||||
Bin32 = 0b11000110,
|
||||
Ext8 = 0b11000111,
|
||||
Ext16 = 0b11001000,
|
||||
Ext32 = 0b11001001,
|
||||
Float32 = 0b11001010,
|
||||
Float64 = 0b11001011,
|
||||
UInt8 = 0b11001100,
|
||||
UInt16 = 0b11001101,
|
||||
UInt32 = 0b11001110,
|
||||
UInt64 = 0b11001111,
|
||||
Int8 = 0b11010000,
|
||||
Int16 = 0b11010001,
|
||||
Int32 = 0b11010010,
|
||||
Int64 = 0b11010011,
|
||||
FixExt1 = 0b11010100,
|
||||
FixExt2 = 0b11010101,
|
||||
FixExt4 = 0b11010110,
|
||||
FixExt8 = 0b11010111,
|
||||
FixExt16 = 0b11011000,
|
||||
Str8 = 0b11011001,
|
||||
Str16 = 0b11011010,
|
||||
Str32 = 0b11011011,
|
||||
Arr16 = 0b11011100,
|
||||
Arr32 = 0b11011101,
|
||||
Map16 = 0b11011110,
|
||||
Map32 = 0b11011111,
|
||||
NegInt = 0b11100000,
|
||||
PosIntMax = 0b01111111,
|
||||
FixMapMax = 0b10001111,
|
||||
FixArrMax = 0b10011111,
|
||||
FixStrMax = 0b10111111,
|
||||
NegIntMax = 0b11111111,
|
||||
}
|
||||
}
|
||||
using KKdBaseLib;
|
||||
|
||||
namespace KKdMainLib.IO
|
||||
{
|
||||
public struct MP : System.IDisposable
|
||||
{
|
||||
public MP(Stream _IO) => this._IO = _IO;
|
||||
|
||||
private Stream _IO;
|
||||
|
||||
public void Close() => _IO.C();
|
||||
|
||||
public byte[] ToArray(bool Close = false) => _IO.ToArray(Close);
|
||||
|
||||
public MsgPack Read(bool array = false)
|
||||
{
|
||||
MsgPack msgPack = MsgPack.New;
|
||||
byte unk = _IO.RU8();
|
||||
if (!array) { msgPack.Name = RS((Types)unk); unk = _IO.RU8(); }
|
||||
Types type = (Types)unk;
|
||||
|
||||
if (type >= Types.FixMap && type <= Types.FixMapMax)
|
||||
{
|
||||
msgPack.Object = KKdList<MsgPack>.New;
|
||||
for (int i = 0; i < unk - (byte)Types.FixMap; i++) msgPack.Add( Read(false));
|
||||
}
|
||||
else if (type >= Types.FixArr && type <= Types.FixArrMax)
|
||||
{
|
||||
msgPack.Object = new MsgPack[unk - (byte)Types.FixArr];
|
||||
for (int i = 0; i < unk - (byte)Types.FixArr; i++) msgPack[i] = Read( true);
|
||||
}
|
||||
else if (type >= Types.FixStr && type <= Types.FixStrMax) msgPack.Object = RS(type);
|
||||
else if (type >= Types.PosInt && type <= Types.PosIntMax) msgPack.Object = unk;
|
||||
else if (type >= Types.NegInt && type <= Types.NegIntMax) msgPack.Object = (sbyte)unk;
|
||||
else
|
||||
while (true)
|
||||
{
|
||||
if (RN (ref msgPack, ref type)) break;
|
||||
if (RBy(ref msgPack, ref type)) break;
|
||||
if (RM (ref msgPack, ref type)) break;
|
||||
if (RE (ref msgPack, ref type)) break;
|
||||
if (RS (ref msgPack, ref type)) break;
|
||||
if (RBo(ref msgPack, ref type)) break;
|
||||
if (RA (ref msgPack, ref type)) break;
|
||||
if (RI (ref msgPack, ref type)) break;
|
||||
if (RU (ref msgPack, ref type)) break;
|
||||
if (RF (ref msgPack, ref type)) break;
|
||||
break;
|
||||
}
|
||||
return msgPack;
|
||||
}
|
||||
|
||||
private bool RI(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
if (type == Types.Int8 ) msgPack.Object = _IO.RI8();
|
||||
else if (type == Types.Int16) msgPack.Object = _IO.RI16E(true);
|
||||
else if (type == Types.Int32) msgPack.Object = _IO.RI32E(true);
|
||||
else if (type == Types.Int64) msgPack.Object = _IO.RI64E(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RU(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
if (type == Types.UInt8 ) msgPack.Object = _IO.RU8();
|
||||
else if (type == Types.UInt16) msgPack.Object = _IO.RU16E(true);
|
||||
else if (type == Types.UInt32) msgPack.Object = _IO.RU32E(true);
|
||||
else if (type == Types.UInt64) msgPack.Object = _IO.RU64E(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RF(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
if (type == Types.Float32) msgPack.Object = _IO.RF32E(true);
|
||||
else if (type == Types.Float64) msgPack.Object = _IO.RF64E(true);
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RBo(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
if (type == Types.False) msgPack.Object = false;
|
||||
else if (type == Types.True ) msgPack.Object = true ;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RBy(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (type == Types.Bin8 ) Length = _IO.RU8();
|
||||
else if (type == Types.Bin16) Length = _IO.RI16E(true);
|
||||
else if (type == Types.Bin32) Length = _IO.RI32E(true);
|
||||
else return false;
|
||||
msgPack.Object = _IO.RBy(Length);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RS(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
string val = RS(type);
|
||||
if (val != null) msgPack.Object = val;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private string RS(Types val)
|
||||
{
|
||||
if (val >= Types.FixStr && val <= Types.FixStrMax)
|
||||
return _IO.RS(val - Types.FixStr);
|
||||
else if (val >= Types. Str8 && val <= Types. Str32 )
|
||||
{
|
||||
System.Enum.TryParse(val.ToString(), out Types type);
|
||||
int Length = 0;
|
||||
if (type == Types.Str8 ) Length = _IO.RU8();
|
||||
else if (type == Types.Str16) Length = _IO.RI16E(true);
|
||||
else Length = _IO.RI32E(true);
|
||||
return _IO.RS(Length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private bool RN(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
if (type == Types.Nil) msgPack.Object = null;
|
||||
else return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RA(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (type == Types.Arr16) Length = _IO.RI16E(true);
|
||||
else if (type == Types.Arr32) Length = _IO.RI32E(true);
|
||||
else return false;
|
||||
msgPack.Object = new MsgPack[Length];
|
||||
for (int i = 0; i < Length; i++) msgPack[i] = Read(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RM(ref MsgPack msgPack, ref Types type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (type == Types.Map16) Length = _IO.RI16E(true);
|
||||
else if (type == Types.Map32) Length = _IO.RI32E(true);
|
||||
else return false;
|
||||
msgPack.Object = KKdList<MsgPack>.New;
|
||||
for (int i = 0; i < Length; i++) msgPack.Add(Read());
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool RE(ref MsgPack MsgPack, ref Types type)
|
||||
{
|
||||
int Length = 0;
|
||||
if (type == Types.FixExt1 ) Length = 1 ;
|
||||
else if (type == Types.FixExt2 ) Length = 2 ;
|
||||
else if (type == Types.FixExt4 ) Length = 4 ;
|
||||
else if (type == Types.FixExt8 ) Length = 8 ;
|
||||
else if (type == Types.FixExt16) Length = 16;
|
||||
else if (type == Types. Ext8 ) Length = _IO.RU8();
|
||||
else if (type == Types. Ext16) Length = _IO.RI16E(true);
|
||||
else if (type == Types. Ext32) Length = _IO.RI32E(true);
|
||||
else return false;
|
||||
MsgPack.Object = new MsgPack.Ext { Type = _IO.RI8(), Data = _IO.RBy(Length) };
|
||||
return true;
|
||||
}
|
||||
|
||||
public MP W(MsgPack msgPack, bool ignoreNull, bool IsArray = false)
|
||||
{
|
||||
if (msgPack.Name != null && !IsArray) W(msgPack.Name);
|
||||
Write(msgPack.Object, ignoreNull);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void Write(object obj, bool ignoreNull)
|
||||
{
|
||||
if (obj == null) { if (!ignoreNull) WN(); return; }
|
||||
switch (obj)
|
||||
{
|
||||
case KKdList<MsgPack> val: WM(val.Count );
|
||||
for (int i = 0; i < val.Count ; i++) W(val[i], ignoreNull); break;
|
||||
case MsgPack[] val: WA(val.Length);
|
||||
for (int i = 0; i < val.Length; i++) W(val[i], ignoreNull); break;
|
||||
case MsgPack val: W(val, ignoreNull); break;
|
||||
case byte[] val: W(val); break;
|
||||
case bool val: W(val); break;
|
||||
case sbyte val: W(val); break;
|
||||
case byte val: W(val); break;
|
||||
case short val: W(val); break;
|
||||
case ushort val: W(val); break;
|
||||
case int val: W(val); break;
|
||||
case uint val: W(val); break;
|
||||
case long val: W(val); break;
|
||||
case ulong val: W(val); break;
|
||||
case float val: W(val); break;
|
||||
case double val: W(val); break;
|
||||
case string val: W(val); break;
|
||||
case MsgPack.Ext val: W(val); break;
|
||||
}
|
||||
}
|
||||
|
||||
private void W( sbyte val) { if (val < -0x20) _IO.W((byte)0xD0); _IO.W(val); }
|
||||
private void W( byte val) { if (val >= 0x80) _IO.W((byte)0xCC); _IO.W(val); }
|
||||
private void W( short val) { if (( sbyte)val == val) W(( sbyte)val);
|
||||
else if (( byte)val == val) W(( byte)val);
|
||||
else { _IO.W((byte)0xD1); _IO.WE(val, true); } }
|
||||
private void W(ushort val) { if (( byte)val == val) W(( byte)val);
|
||||
else { _IO.W((byte)0xCD); _IO.WE(val, true); } }
|
||||
private void W( int val) { if (( short)val == val) W(( short)val);
|
||||
else if ((ushort)val == val) W((ushort)val);
|
||||
else { _IO.W((byte)0xD2); _IO.WE(val, true); } }
|
||||
private void W( uint val) { if ((ushort)val == val) W((ushort)val);
|
||||
else { _IO.W((byte)0xCE); _IO.WE(val, true); } }
|
||||
private void W( long val) { if (( int)val == val) W(( int)val);
|
||||
else if (( uint)val == val) W(( uint)val);
|
||||
else { _IO.W((byte)0xD3); _IO.WE(val, true); } }
|
||||
private void W( ulong val) { if (( uint)val == val) W(( uint)val);
|
||||
else { _IO.W((byte)0xCF); _IO.WE(val, true); } }
|
||||
private void W( float val) { if (( long)val == val) W(( long)val);
|
||||
else { _IO.W((byte)0xCA); _IO.WE(val, true); } }
|
||||
private void W(double val) { if (( long)val == val) W(( long)val);
|
||||
else if (( float)val == val) W(( float)val);
|
||||
else { _IO.W((byte)0xCB); _IO.WE(val, true); } }
|
||||
|
||||
private void W( bool val) =>
|
||||
_IO.W((byte)(val ? 0xC3 : 0xC2));
|
||||
|
||||
private void W(byte[] val)
|
||||
{
|
||||
if (val == null) { WN(); return; }
|
||||
|
||||
if (val.Length < 0x100) { _IO.W((byte)0xC4); _IO.W (( byte)val.Length ); }
|
||||
else if (val.Length < 0x10000) { _IO.W((byte)0xC5); _IO.WE((ushort)val.Length, true); }
|
||||
else { _IO.W((byte)0xC6); _IO.WE( val.Length, true); }
|
||||
_IO.W(val);
|
||||
}
|
||||
|
||||
private void W(string val)
|
||||
{
|
||||
if (val == null) { WN(); return; }
|
||||
|
||||
byte[] array = Text.ToUTF8(val);
|
||||
if (array.Length < 0x20) _IO.W((byte)(0xA0 | (array.Length & 0x1F)));
|
||||
else if (array.Length < 0x100) { _IO.W((byte)0xD9); _IO.W (( byte)array.Length); }
|
||||
else if (array.Length < 0x10000) { _IO.W((byte)0xDA); _IO.WE((ushort)array.Length, true); }
|
||||
else { _IO.W((byte)0xDB); _IO.WE( array.Length, true); }
|
||||
_IO.W(array);
|
||||
}
|
||||
|
||||
private void WN() => _IO.W((byte)0xC0);
|
||||
|
||||
private void WA(int val)
|
||||
{
|
||||
if (val == 0) { WN(); return; }
|
||||
else if (val < 0x10) _IO.W((byte)(0x90 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.W((byte)0xDC); _IO.WE((ushort)val, true); }
|
||||
else { _IO.W((byte)0xDD); _IO.WE( val, true); }
|
||||
}
|
||||
|
||||
private void WM(int val)
|
||||
{
|
||||
if (val == 0) { WN(); return; }
|
||||
else if (val < 0x10) _IO.W((byte)(0x80 | (val & 0x0F)));
|
||||
else if (val < 0x10000) { _IO.W((byte)0xDE); _IO.WE((ushort)val, true); }
|
||||
else { _IO.W((byte)0xDF); _IO.WE( val, true); }
|
||||
}
|
||||
|
||||
private void W(MsgPack.Ext val) => WE(val);
|
||||
|
||||
private void WE(MsgPack.Ext val)
|
||||
{
|
||||
if (val.Data == null) { WN(); return; }
|
||||
|
||||
if (val.Data.Length < 1 ) { WN(); return; }
|
||||
else if (val.Data.Length == 1 ) _IO.W((byte)0xD4);
|
||||
else if (val.Data.Length == 2 ) _IO.W((byte)0xD5);
|
||||
else if (val.Data.Length == 4 ) _IO.W((byte)0xD6);
|
||||
else if (val.Data.Length == 8 ) _IO.W((byte)0xD7);
|
||||
else if (val.Data.Length == 16) _IO.W((byte)0xD8);
|
||||
else
|
||||
{
|
||||
if (val.Data.Length < 0x100)
|
||||
{ _IO.W((byte)0xC7); _IO.W (( byte)val.Data.Length); }
|
||||
else if (val.Data.Length < 0x10000)
|
||||
{ _IO.W((byte)0xC8); _IO.WE((ushort)val.Data.Length, true); }
|
||||
else
|
||||
{ _IO.W((byte)0xC9); _IO.WE( val.Data.Length, true); }
|
||||
}
|
||||
_IO.W(val.Type);
|
||||
_IO.W(val.Data);
|
||||
}
|
||||
|
||||
public void Dispose() => _IO.C();
|
||||
}
|
||||
|
||||
public enum Types : byte
|
||||
{
|
||||
PosInt = 0b00000000,
|
||||
FixMap = 0b10000000,
|
||||
FixArr = 0b10010000,
|
||||
FixStr = 0b10100000,
|
||||
Nil = 0b11000000,
|
||||
NeverUsed = 0b11000001,
|
||||
False = 0b11000010,
|
||||
True = 0b11000011,
|
||||
Bin8 = 0b11000100,
|
||||
Bin16 = 0b11000101,
|
||||
Bin32 = 0b11000110,
|
||||
Ext8 = 0b11000111,
|
||||
Ext16 = 0b11001000,
|
||||
Ext32 = 0b11001001,
|
||||
Float32 = 0b11001010,
|
||||
Float64 = 0b11001011,
|
||||
UInt8 = 0b11001100,
|
||||
UInt16 = 0b11001101,
|
||||
UInt32 = 0b11001110,
|
||||
UInt64 = 0b11001111,
|
||||
Int8 = 0b11010000,
|
||||
Int16 = 0b11010001,
|
||||
Int32 = 0b11010010,
|
||||
Int64 = 0b11010011,
|
||||
FixExt1 = 0b11010100,
|
||||
FixExt2 = 0b11010101,
|
||||
FixExt4 = 0b11010110,
|
||||
FixExt8 = 0b11010111,
|
||||
FixExt16 = 0b11011000,
|
||||
Str8 = 0b11011001,
|
||||
Str16 = 0b11011010,
|
||||
Str32 = 0b11011011,
|
||||
Arr16 = 0b11011100,
|
||||
Arr32 = 0b11011101,
|
||||
Map16 = 0b11011110,
|
||||
Map32 = 0b11011111,
|
||||
NegInt = 0b11100000,
|
||||
PosIntMax = 0b01111111,
|
||||
FixMapMax = 0b10001111,
|
||||
FixArrMax = 0b10011111,
|
||||
FixStrMax = 0b10111111,
|
||||
NegIntMax = 0b11111111,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
<Authors>korenkonder</Authors>
|
||||
<Company></Company>
|
||||
<Configuration></Configuration>
|
||||
<Copyright>korenkonder (C) 2018-2022</Copyright>
|
||||
<Copyright>korenkonder (C) 2018-2024</Copyright>
|
||||
<Description>A simple library for working with Project Diva AC/DT/F/AFT/F2/X/XHD/FT/VRFL/M39 files</Description>
|
||||
<FileVersion>0.4.10.10</FileVersion>
|
||||
<FileVersion>0.5.0.0</FileVersion>
|
||||
<PackageId>KKdMainLib</PackageId>
|
||||
<Product>KKdMainLib</Product>
|
||||
<TargetFramework>net461</TargetFramework>
|
||||
<Title>KKdMainLib</Title>
|
||||
<Version>0.4.10.10</Version>
|
||||
<Version>0.5.0.0</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
||||
+400
-299
@@ -1,5 +1,7 @@
|
||||
using KKdBaseLib;
|
||||
using KKdBaseLib.F2;
|
||||
using KKdMainLib.IO;
|
||||
using static KKdMainLib.FARC;
|
||||
|
||||
namespace KKdMainLib
|
||||
{
|
||||
@@ -10,49 +12,91 @@ namespace KKdMainLib
|
||||
|
||||
public HeaderData Header;
|
||||
|
||||
public void MotHeadReader(string file)
|
||||
public void MotHeadReader(string file, string ext)
|
||||
{
|
||||
s = File.OpenReader(file + ".bin");
|
||||
s.RI32();
|
||||
bool x = false;
|
||||
int x_offset = 0;
|
||||
s = File.OpenReader(file + ext);
|
||||
Header = new HeaderData();
|
||||
int signature = s.RI32();
|
||||
if (signature == 0x484D4D4D)
|
||||
{
|
||||
x_offset = (int)s.ReadHeader(true).Length;
|
||||
Header.MotionSetID = s.RU32();
|
||||
int mot_count = s.RI32();
|
||||
int mot_hashes_offset = s.RI32();
|
||||
Header.SubHeaderOffset = s.RI32();
|
||||
if (Header.SubHeaderOffset == 0)
|
||||
{
|
||||
if (mot_hashes_offset != 0) mot_hashes_offset += x_offset;
|
||||
s.IsX = true;
|
||||
x = true;
|
||||
Header.SubHeaderOffset = (int)s.RIX();
|
||||
if (Header.SubHeaderOffset != 0) Header.SubHeaderOffset += x_offset;
|
||||
}
|
||||
|
||||
int offset = s.RI32();
|
||||
if (offset < 0x10) goto RETURN;
|
||||
s.O = offset;
|
||||
s.P = 0;
|
||||
if (Header.SubHeaderOffset < 0x20) goto RETURN;
|
||||
|
||||
Header. MotionSetID = s.RI32();
|
||||
Header.FirstMotionID = s.RI32();
|
||||
Header. LastMotionID = s.RI32();
|
||||
Header.SubHeaderOffset = s.RI32();
|
||||
s.P = mot_hashes_offset;
|
||||
Header.Data = new HeaderData.Sub[mot_count];
|
||||
for (i = 0; i < Header.Data.Length; i++) Header.Data[i].MotionID = s.RU32();
|
||||
}
|
||||
else
|
||||
{
|
||||
int offset = s.RI32();
|
||||
if (offset < 0x10) goto RETURN;
|
||||
s.O = offset;
|
||||
s.P = 0;
|
||||
|
||||
if (Header.SubHeaderOffset < 0x10) goto RETURN;
|
||||
i0 = Header.LastMotionID - Header.FirstMotionID;
|
||||
if (i0 < 0) goto RETURN;
|
||||
Header.MotionSetID = s.RU32();
|
||||
Header.FirstMotionID = s.RU32();
|
||||
Header.LastMotionID = s.RU32();
|
||||
Header.SubHeaderOffset = (int)s.RIX();
|
||||
|
||||
if (Header.SubHeaderOffset < 0x10) goto RETURN;
|
||||
i0 = (int)(Header.LastMotionID - Header.FirstMotionID);
|
||||
if (i0 < 0) goto RETURN;
|
||||
|
||||
Header.Data = new HeaderData.Sub[++i0];
|
||||
for (i = 0; i < Header.Data.Length; i++)
|
||||
Header.Data[i].MotionID = Header.FirstMotionID + (uint)i;
|
||||
}
|
||||
|
||||
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 (x) s.A(0x08);
|
||||
Header.Data[i].Offset = (int)s.RIX();
|
||||
if (x && Header.Data[i].Offset != 0) Header.Data[i].Offset += x_offset;
|
||||
}
|
||||
|
||||
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.FirstMotionID + i;
|
||||
Header.Data[i].Field00 = s.RI32();
|
||||
Header.Data[i].Field04 = s.RI32();
|
||||
Header.Data[i].Field08 = s.RI32();
|
||||
Header.Data[i].Field0C = s.RI32();
|
||||
if (!x)
|
||||
{
|
||||
Header.Data[i].Field04 = s.RI32();
|
||||
Header.Data[i].Field08 = s.RI32();
|
||||
Header.Data[i].Field0C = s.RI32();
|
||||
}
|
||||
Header.Data[i].Field10 = s.RU16();
|
||||
Header.Data[i].Field12 = s.RU16();
|
||||
Header.Data[i].Offset2 = s.RI32();
|
||||
Header.Data[i].DataHeaderOffset = s.RI32();
|
||||
if (x) s.A(0x08);
|
||||
Header.Data[i].Offset2 = (int)s.RIX();
|
||||
if (x && Header.Data[i].Offset2 != 0) Header.Data[i].Offset2 += x_offset;
|
||||
if (x) s.A(0x08);
|
||||
Header.Data[i].DataHeaderOffset = (int)s.RIX();
|
||||
if (x && Header.Data[i].DataHeaderOffset != 0)
|
||||
Header.Data[i].DataHeaderOffset += x_offset;
|
||||
|
||||
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++; }
|
||||
while (s.RI32() != -1) { s.RI32(); if (x) s.A(0x08); s.RIX(); i0++; }
|
||||
s.P = Header.Data[i].DataHeaderOffset;
|
||||
|
||||
Header.Data[i].Array = new HeaderData.Sub.Data[i0];
|
||||
@@ -60,7 +104,10 @@ namespace KKdMainLib
|
||||
{
|
||||
Header.Data[i].Array[i0].Type = (Type)s.RI32();
|
||||
Header.Data[i].Array[i0].Frame = s.RI32();
|
||||
Header.Data[i].Array[i0].Offset = s.RI32();
|
||||
if (x) s.A(0x08);
|
||||
Header.Data[i].Array[i0].Offset = (int)s.RIX();
|
||||
if (x && Header.Data[i].Array[i0].Offset != 0)
|
||||
Header.Data[i].Array[i0].Offset += x_offset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +124,10 @@ namespace KKdMainLib
|
||||
for (i0 = 0; i0 < Header.Data[i].Array2.Length; i0++)
|
||||
{
|
||||
Header.Data[i].Array2[i0].Type = s.RI32();
|
||||
Header.Data[i].Array2[i0].Offset = s.RI32();
|
||||
if (x) s.A(0x08);
|
||||
Header.Data[i].Array2[i0].Offset = (int)s.RIX();
|
||||
if (x && Header.Data[i].Array2[i0].Offset != 0)
|
||||
Header.Data[i].Array2[i0].Offset += x_offset;
|
||||
}
|
||||
|
||||
for (i0 = 0; i0 < Header.Data[i].Array2.Length; i0++)
|
||||
@@ -131,7 +181,7 @@ RETURN:
|
||||
s.O = 0x20;
|
||||
s.P = 0;
|
||||
s.W(0);
|
||||
for (int I = Header.LastMotionID - Header.FirstMotionID; I > -1; I--)
|
||||
for (int I = (int)(Header.LastMotionID - Header.FirstMotionID); I > -1; I--)
|
||||
for (i = 0; i < Header.Data.Length; i++)
|
||||
if (Header.FirstMotionID + I == Header.Data[i].MotionID)
|
||||
{
|
||||
@@ -153,8 +203,14 @@ RETURN:
|
||||
int Size = GetSize(data.Type);
|
||||
if (data.Array == null || data.Array.Length < 1 || Size < 1) continue;
|
||||
|
||||
if ((int)data.Type == 0x3E || (int)data.Type == 0x49)
|
||||
s.A(0x20, true);
|
||||
switch ((int)data.Type)
|
||||
{
|
||||
case 0x3E:
|
||||
case 0x49:
|
||||
case 0x4B:
|
||||
s.A(0x20, true);
|
||||
break;
|
||||
}
|
||||
|
||||
if (data.Array.Length >= 4 && s.P % 0x4 != 0)
|
||||
s.A(0x04, true);
|
||||
@@ -168,15 +224,15 @@ RETURN:
|
||||
s.A(0x20, true);
|
||||
}
|
||||
|
||||
if (Header.Data[i].Array2 != null && 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--)
|
||||
if (Header.Data[i].Array2 != null && 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--)
|
||||
{
|
||||
ref HeaderData.Sub.Data2 data = ref Header.Data[i].Array2[i0];
|
||||
int Size = GetSize2(data.Type);
|
||||
@@ -188,15 +244,15 @@ RETURN:
|
||||
s.A(0x02, true);
|
||||
|
||||
data.Offset = s.P;
|
||||
s.W(data.Array);
|
||||
}
|
||||
break;
|
||||
}
|
||||
s.W(data.Array);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
s.A(0x10, true);
|
||||
|
||||
Header.SubHeaderOffset = s.P;
|
||||
i1 = Header.LastMotionID - Header.FirstMotionID;
|
||||
i1 = (int)(Header.LastMotionID - Header.FirstMotionID);
|
||||
|
||||
int offset = 0;
|
||||
for (i = 0, i1++; i < i1; i++)
|
||||
@@ -254,14 +310,14 @@ RETURN:
|
||||
MsgPack motHead;
|
||||
MsgPack msgPack = file.ReadMPAllAtOnce(json);
|
||||
if ((motHead = msgPack["MotHead"]).IsNull) return;
|
||||
Header.MotionSetID = motHead.RI32("MotionSetID");
|
||||
Header.MotionSetID = motHead.RU32("MotionSetID");
|
||||
|
||||
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].MotionID = motions[i].RU32("MotionID");
|
||||
Header.Data[i].Field00 = motions[i].RI32("Field00");
|
||||
Header.Data[i].Field04 = motions[i].RI32("Field04");
|
||||
Header.Data[i].Field08 = motions[i].RI32("Field08");
|
||||
@@ -371,7 +427,7 @@ RETURN:
|
||||
case 0x20:
|
||||
data.Array.GBy(temp.RI16("i00_16"), 0x00);
|
||||
data.Array.GBy(temp.RI32("i04"), 0x04);
|
||||
data.Array.GBy(temp.RI32("i08"), 0x08);
|
||||
data.Array.GBy(temp.RF32("Duration"), 0x08);
|
||||
data.Array.GBy(temp.RI32("i0C"), 0x0C);
|
||||
break;
|
||||
case 0x21:
|
||||
@@ -383,89 +439,95 @@ RETURN:
|
||||
data.Array.GBy(temp.RI32("i10"), 0x10);
|
||||
data.Array.GBy(temp.RI32("i14"), 0x14);
|
||||
break;
|
||||
case 0x32:
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
data.Array.GBy(temp.RF32("f04"), 0x04);
|
||||
case 0x32: // SetFaceMotionId
|
||||
data.Array.GBy(temp.RI32("MotionID"), 0x00);
|
||||
data.Array.GBy(temp.RF32("Frame"), 0x04);
|
||||
break;
|
||||
case 0x35:
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
data.Array.GBy(temp.RF32("f04"), 0x04);
|
||||
data.Array.GBy(temp.RF32("f08"), 0x08);
|
||||
case 0x35: // SetFaceMottblMotion
|
||||
data.Array.GBy(temp.RI32("Index"), 0x00);
|
||||
data.Array.GBy(temp.RF32("Value"), 0x04);
|
||||
data.Array.GBy(temp.RF32("Duration"), 0x08);
|
||||
data.Array.GBy(temp.RI32("i0C"), 0x0C);
|
||||
data.Array.GBy(temp.RF32("f10"), 0x10);
|
||||
break;
|
||||
case 0x36:
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
data.Array.GBy(temp.RF32("f04"), 0x04);
|
||||
data.Array.GBy(temp.RF32("f08"), 0x08);
|
||||
case 0x36: // SetHandRMottblMotion
|
||||
data.Array.GBy(temp.RI32("Index"), 0x00);
|
||||
data.Array.GBy(temp.RF32("Value"), 0x04);
|
||||
data.Array.GBy(temp.RF32("Duration"), 0x08);
|
||||
data.Array.GBy(temp.RI32("i0C"), 0x0C);
|
||||
data.Array.GBy(temp.RF32("f10"), 0x10);
|
||||
break;
|
||||
case 0x37:
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
data.Array.GBy(temp.RF32("f04"), 0x04);
|
||||
data.Array.GBy(temp.RF32("f08"), 0x08);
|
||||
case 0x37: // SetHandLMottblMotion
|
||||
data.Array.GBy(temp.RI32("Index"), 0x00);
|
||||
data.Array.GBy(temp.RF32("Value"), 0x04);
|
||||
data.Array.GBy(temp.RF32("Duration"), 0x08);
|
||||
data.Array.GBy(temp.RI32("i0C"), 0x0C);
|
||||
data.Array.GBy(temp.RF32("f10"), 0x10);
|
||||
break;
|
||||
case 0x38:
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
data.Array.GBy(temp.RF32("f04"), 0x04);
|
||||
data.Array.GBy(temp.RF32("f08"), 0x08);
|
||||
case 0x38: // SetMouthMottblMotion
|
||||
data.Array.GBy(temp.RI32("Index"), 0x00);
|
||||
data.Array.GBy(temp.RF32("Value"), 0x04);
|
||||
data.Array.GBy(temp.RF32("Duration"), 0x08);
|
||||
data.Array.GBy(temp.RI32("i0C"), 0x0C);
|
||||
data.Array.GBy(temp.RF32("f10"), 0x10);
|
||||
break;
|
||||
case 0x39:
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
data.Array.GBy(temp.RF32("f04"), 0x04);
|
||||
data.Array.GBy(temp.RF32("f08"), 0x08);
|
||||
case 0x39: // SetEyesMottblMotion
|
||||
data.Array.GBy(temp.RI32("Index"), 0x00);
|
||||
data.Array.GBy(temp.RF32("Value"), 0x04);
|
||||
data.Array.GBy(temp.RF32("Duration"), 0x08);
|
||||
data.Array.GBy(temp.RI32("i0C"), 0x0C);
|
||||
data.Array.GBy(temp.RF32("f10"), 0x10);
|
||||
break;
|
||||
case 0x3A:
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
data.Array.GBy(temp.RF32("f04"), 0x04);
|
||||
data.Array.GBy(temp.RF32("f08"), 0x08);
|
||||
case 0x3A: // SetEyelidMottblMotion
|
||||
data.Array.GBy(temp.RI32("Index"), 0x00);
|
||||
data.Array.GBy(temp.RF32("Value"), 0x04);
|
||||
data.Array.GBy(temp.RF32("Duration"), 0x08);
|
||||
data.Array.GBy(temp.RI32("i0C"), 0x0C);
|
||||
data.Array.GBy(temp.RF32("f10"), 0x10);
|
||||
break;
|
||||
case 0x3B:
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
case 0x3B: // SetRobCharaHeadObject
|
||||
data.Array.GBy(temp.RI32("Index"), 0x00);
|
||||
break;
|
||||
case 0x3C:
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
data.Array.GBy(temp.RF32("f04"), 0x04);
|
||||
data.Array.GBy(temp.RF32("f08"), 0x08);
|
||||
data.Array.GBy(temp.RF32("f0C"), 0x0C);
|
||||
case 0x3C: // SetLookCamera
|
||||
data.Array.GBy(temp.RI32("Enable"), 0x00);
|
||||
data.Array.GBy(temp.RF32("HeadRotStrength"), 0x04);
|
||||
data.Array.GBy(temp.RF32("EyesRotStrength"), 0x08);
|
||||
data.Array.GBy(temp.RF32("BlendDuration"), 0x0C);
|
||||
break;
|
||||
case 0x3D:
|
||||
case 0x3D: // SetEyelidMotionFromFace
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
data.Array.GBy(temp.RF32("f04"), 0x04);
|
||||
data.Array.GBy(temp.RF32("Duration"), 0x04);
|
||||
break;
|
||||
case 0x3E:
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
data.Array.GBy(temp.RU8("i04_8"), 0x04);
|
||||
data.Array.GBy(temp.RU8("i05_8"), 0x05);
|
||||
data.Array.GBy(temp.RU8("i06_8"), 0x06);
|
||||
data.Array.GBy(temp.RU8("i07_8"), 0x07);
|
||||
data.Array.GBy(temp.RF32("f08"), 0x08);
|
||||
data.Array.GBy(temp.RF32("f0C"), 0x0C);
|
||||
data.Array.GBy(temp.RF32("f10"), 0x10);
|
||||
data.Array.GBy(temp.RF32("f14"), 0x14);
|
||||
data.Array.GBy(temp.RF32("f18"), 0x18);
|
||||
data.Array.GBy(temp.RF32("f1C"), 0x1C);
|
||||
data.Array.GBy(temp.RF32("f20"), 0x20);
|
||||
data.Array.GBy(temp.RF32("f24"), 0x24);
|
||||
data.Array.GBy(temp.RF32("f28"), 0x28);
|
||||
data.Array.GBy(temp.RF32("f2C"), 0x2C);
|
||||
data.Array.GBy(temp.RF32("f30"), 0x30);
|
||||
data.Array.GBy(temp.RF32("f34"), 0x34);
|
||||
data.Array.GBy(temp.RF32("f38"), 0x38);
|
||||
case 0x3E: // RobPartsAdjust
|
||||
data.Array.GBy(temp.RI32("TransitionDuration"), 0x00);
|
||||
data.Array.GBy(temp.RU8("Parts"), 0x04);
|
||||
data.Array.GBy(temp.RU8("Type"), 0x05);
|
||||
data.Array.GBy((byte)(temp.RB("IgnoreGravity") ? 1 : 0), 0x06);
|
||||
data.Array.GBy(temp.RU8("CycleType"), 0x07);
|
||||
data.Array.GBy(temp.RF32("ExternalForceX"), 0x08);
|
||||
data.Array.GBy(temp.RF32("ExternalForceY"), 0x0C);
|
||||
data.Array.GBy(temp.RF32("ExternalForceZ"), 0x10);
|
||||
data.Array.GBy(temp.RF32("ExternalForceCycleStrengthX"), 0x14);
|
||||
data.Array.GBy(temp.RF32("ExternalForceCycleStrengthY"), 0x18);
|
||||
data.Array.GBy(temp.RF32("ExternalForceCycleStrengthZ"), 0x1C);
|
||||
data.Array.GBy(temp.RF32("ExternalForceCycleX"), 0x20);
|
||||
data.Array.GBy(temp.RF32("ExternalForceCycleY"), 0x24);
|
||||
data.Array.GBy(temp.RF32("ExternalForceCycleZ"), 0x28);
|
||||
data.Array.GBy(temp.RF32("Cycle"), 0x2C);
|
||||
data.Array.GBy(temp.RF32("Phase"), 0x30);
|
||||
data.Array.GBy(temp.RF32("Force"), 0x34);
|
||||
data.Array.GBy(temp.RF32("Strength"), 0x38);
|
||||
data.Array.GBy(temp.RI32("StrengthTransition"), 0x3C);
|
||||
break;
|
||||
case 0x42:
|
||||
case 0x40: // OsageReset
|
||||
break;
|
||||
case 0x41: // MotionSkinParam
|
||||
data.Array.GBy(temp.RI32("Iterations"), 0x00);
|
||||
break;
|
||||
case 0x42: // OsageStep
|
||||
data.Array.GBy(temp.RF32("Value"), 0x00);
|
||||
break;
|
||||
case 0x43:
|
||||
case 0x43: // SleeveAdjust
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
data.Array.GBy(temp.RF32("f04"), 0x04);
|
||||
break;
|
||||
@@ -473,15 +535,15 @@ RETURN:
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
data.Array.GBy(temp.RF32("f04"), 0x04);
|
||||
break;
|
||||
case 0x45:
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
case 0x45: // MotionMaxFrame
|
||||
data.Array.GBy(temp.RI32("MaxFrame"), 0x00);
|
||||
break;
|
||||
case 0x46:
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
case 0x46: // CameraMaxFrame
|
||||
data.Array.GBy(temp.RI32("MaxFrame"), 0x00);
|
||||
break;
|
||||
case 0x47:
|
||||
data.Array.GBy(temp.RU8("i00_8"), 0x00);
|
||||
data.Array.GBy(temp.RF32("f04"), 0x04);
|
||||
case 0x47: // OsageMoveCancel
|
||||
data.Array.GBy(temp.RU8("ID"), 0x00); // 0 - All, 1 - Kami, 2 - Outer
|
||||
data.Array.GBy(temp.RF32("Value"), 0x04);
|
||||
break;
|
||||
case 0x48:
|
||||
data.Array.GBy(temp.RF32("f00"), 0x00);
|
||||
@@ -494,51 +556,51 @@ RETURN:
|
||||
data.Array.GBy(temp.RU8("i19_8"), 0x19);
|
||||
data.Array.GBy(temp.RU8("i1A_8"), 0x1A);
|
||||
break;
|
||||
case 0x49:
|
||||
data.Array.GBy(temp.RI16("i00_16"), 0x00);
|
||||
data.Array.GBy(temp.RI16("i02_16"), 0x02);
|
||||
data.Array.GBy(temp.RF32("f04"), 0x04);
|
||||
data.Array.GBy(temp.RI16("i08_16"), 0x08);
|
||||
data.Array.GBy(temp.RF32("f0C"), 0x0C);
|
||||
data.Array.GBy(temp.RI32("i10"), 0x10);
|
||||
data.Array.GBy(temp.RI32("i14"), 0x14);
|
||||
data.Array.GBy(temp.RI32("i18"), 0x18);
|
||||
data.Array.GBy(temp.RI32("i1C"), 0x1C);
|
||||
data.Array.GBy(temp.RU8("i20"), 0x20);
|
||||
data.Array.GBy(temp.RU8("i21"), 0x21);
|
||||
data.Array.GBy(temp.RU8("i22"), 0x22);
|
||||
data.Array.GBy(temp.RU8("i23"), 0x23);
|
||||
data.Array.GBy(temp.RF32("f24"), 0x24);
|
||||
data.Array.GBy(temp.RI32("i28"), 0x28);
|
||||
case 0x49: // RobHandAdjust
|
||||
data.Array.GBy(temp.RI16("Hand"), 0x00);
|
||||
data.Array.GBy(temp.RI16("ScaleSelect"), 0x02);
|
||||
data.Array.GBy(temp.RF32("Duration"), 0x04);
|
||||
data.Array.GBy(temp.RI16("Type"), 0x08);
|
||||
data.Array.GBy(temp.RF32("Scale"), 0x0C);
|
||||
data.Array.GBy(temp.RF32("RotBlend"), 0x10);
|
||||
data.Array.GBy(temp.RF32("OffsetX"), 0x14);
|
||||
data.Array.GBy(temp.RF32("OffsetY"), 0x18);
|
||||
data.Array.GBy(temp.RF32("OffsetZ"), 0x1C);
|
||||
data.Array.GBy((byte)(temp.RB("EnableScale") ? 1 : 0), 0x20);
|
||||
data.Array.GBy((byte)(temp.RB("DisableX") ? 1 : 0), 0x21);
|
||||
data.Array.GBy((byte)(temp.RB("DisableY") ? 1 : 0), 0x22);
|
||||
data.Array.GBy((byte)(temp.RB("DisableZ") ? 1 : 0), 0x23);
|
||||
data.Array.GBy(temp.RF32("OffsetBlend"), 0x24);
|
||||
data.Array.GBy(temp.RF32("ArmLength"), 0x28);
|
||||
data.Array.GBy(temp.RI32("i2C"), 0x2C);
|
||||
break;
|
||||
case 0x4A:
|
||||
data.Array.GBy(temp.RU8("i00_8"), 0x00);
|
||||
data.Array.GBy(temp.RU8("i01_8"), 0x01);
|
||||
case 0x4A: // DisableCollision
|
||||
data.Array.GBy(temp.RU8("Parts"), 0x00);
|
||||
data.Array.GBy(temp.RU8("Disable"), 0x01);
|
||||
break;
|
||||
case 0x4B:
|
||||
data.Array.GBy(temp.RI32("i00"), 0x00);
|
||||
data.Array.GBy(temp.RU8("i04_8"), 0x04);
|
||||
data.Array.GBy(temp.RU8("i05_8"), 0x05);
|
||||
data.Array.GBy(temp.RF32("f08"), 0x08);
|
||||
data.Array.GBy(temp.RF32("f0C"), 0x0C);
|
||||
data.Array.GBy(temp.RF32("f10"), 0x10);
|
||||
data.Array.GBy(temp.RF32("f14"), 0x14);
|
||||
data.Array.GBy(temp.RF32("f18"), 0x18);
|
||||
data.Array.GBy(temp.RF32("f1C"), 0x1C);
|
||||
data.Array.GBy(temp.RF32("f20"), 0x20);
|
||||
data.Array.GBy(temp.RF32("f24"), 0x24);
|
||||
data.Array.GBy(temp.RF32("f28"), 0x28);
|
||||
data.Array.GBy(temp.RF32("f2C"), 0x2C);
|
||||
data.Array.GBy(temp.RF32("f30"), 0x30);
|
||||
case 0x4B: // RobAdjustGlobal
|
||||
data.Array.GBy(temp.RI32("TransitionDuration"), 0x00);
|
||||
data.Array.GBy(temp.RU8("Type"), 0x04);
|
||||
data.Array.GBy(temp.RU8("CycleType"), 0x05);
|
||||
data.Array.GBy(temp.RF32("ExternalForceX"), 0x08);
|
||||
data.Array.GBy(temp.RF32("ExternalForceY"), 0x0C);
|
||||
data.Array.GBy(temp.RF32("ExternalForceZ"), 0x10);
|
||||
data.Array.GBy(temp.RF32("ExternalForceCycleStrengthX"), 0x14);
|
||||
data.Array.GBy(temp.RF32("ExternalForceCycleStrengthY"), 0x18);
|
||||
data.Array.GBy(temp.RF32("ExternalForceCycleStrengthZ"), 0x1C);
|
||||
data.Array.GBy(temp.RF32("ExternalForceCycleX"), 0x20);
|
||||
data.Array.GBy(temp.RF32("ExternalForceCycleY"), 0x24);
|
||||
data.Array.GBy(temp.RF32("ExternalForceCycleZ"), 0x28);
|
||||
data.Array.GBy(temp.RF32("Cycle"), 0x2C);
|
||||
data.Array.GBy(temp.RF32("Phase"), 0x30);
|
||||
break;
|
||||
case 0x4C:
|
||||
data.Array.GBy(temp.RI16("i00_16"), 0x00);
|
||||
data.Array.GBy(temp.RF32("f04"), 0x04);
|
||||
data.Array.GBy(temp.RF32("f08"), 0x08);
|
||||
case 0x4C: // RobArmAdjust
|
||||
data.Array.GBy(temp.RI16("Index"), 0x00);
|
||||
data.Array.GBy(temp.RF32("Duration"), 0x04);
|
||||
data.Array.GBy(temp.RF32("Value"), 0x08);
|
||||
break;
|
||||
case 0x4D:
|
||||
data.Array.GBy(temp.RU8("i00_8"), 0x00);
|
||||
case 0x4D: // DisableEyeMotion
|
||||
data.Array.GBy((byte)(temp.RB("Value") ? 1 : 0), 0x00);
|
||||
break;
|
||||
case 0x4E:
|
||||
data.Array.GBy(temp.RI16("i00_16"), 0x00);
|
||||
@@ -551,11 +613,13 @@ RETURN:
|
||||
data.Array.GBy(temp.RI32("i14"), 0x14);
|
||||
data.Array.GBy(temp.RI32("i18"), 0x18);
|
||||
break;
|
||||
case 0x4F:
|
||||
data.Array.GBy(temp.RU8("i00_8"), 0x00);
|
||||
case 0x4F: // RobCharaColiRing
|
||||
data.Array.GBy(temp.RU8("Index"), 0x00);
|
||||
break;
|
||||
case 0x50:
|
||||
data.Array.GBy(temp.RU8("i00_8"), 0x00);
|
||||
case 0x50: // AdjustGetGlobalTrans
|
||||
data.Array.GBy((byte)(temp.RB("Value") ? 1 : 0), 0x00);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -658,114 +722,121 @@ RETURN:
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00_16", data.Array.TI16(0x00))
|
||||
.Add("i04", data.Array.TI32(0x04))
|
||||
.Add("i08", data.Array.TI32(0x08))
|
||||
.Add("Duration", data.Array.TF32(0x08))
|
||||
.Add("i0C", data.Array.TI32(0x0C)));
|
||||
break;
|
||||
case 0x21:
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00_16", data.Array.TI16(0x00))
|
||||
.Add("i02_8", data.Array[0x02])
|
||||
.Add("i02_8", data.Array.TU8(0x02))
|
||||
.Add("i04", data.Array.TI32(0x04))
|
||||
.Add("f08", data.Array.TF32(0x08))
|
||||
.Add("f0C", data.Array.TF32(0x0C))
|
||||
.Add("i10", data.Array.TI32(0x10))
|
||||
.Add("i14", data.Array.TI32(0x14)));
|
||||
break;
|
||||
case 0x32:
|
||||
case 0x32: // SetFaceMotionId
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00", data.Array.TI32(0x00))
|
||||
.Add("f04", data.Array.TF32(0x04)));
|
||||
.Add("MotionID", data.Array.TI32(0x00))
|
||||
.Add("Frame", data.Array.TF32(0x04)));
|
||||
break;
|
||||
case 0x35:
|
||||
case 0x35: // SetFaceMottblMotion
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00", data.Array.TI32(0x00))
|
||||
.Add("f04", data.Array.TF32(0x04))
|
||||
.Add("f08", data.Array.TF32(0x08))
|
||||
.Add("Index", data.Array.TI32(0x00))
|
||||
.Add("Value", data.Array.TF32(0x04))
|
||||
.Add("Duration", data.Array.TF32(0x08))
|
||||
.Add("i0C", data.Array.TI32(0x0C))
|
||||
.Add("f10", data.Array.TF32(0x10)));
|
||||
break;
|
||||
case 0x36:
|
||||
case 0x36: // SetHandRMottblMotion
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00", data.Array.TI32(0x00))
|
||||
.Add("f04", data.Array.TF32(0x04))
|
||||
.Add("f08", data.Array.TF32(0x08))
|
||||
.Add("Index", data.Array.TI32(0x00))
|
||||
.Add("Value", data.Array.TF32(0x04))
|
||||
.Add("Duration", data.Array.TF32(0x08))
|
||||
.Add("i0C", data.Array.TI32(0x0C))
|
||||
.Add("f10", data.Array.TF32(0x10)));
|
||||
break;
|
||||
case 0x37:
|
||||
case 0x37: // SetHandLMottblMotion
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00", data.Array.TI32(0x00))
|
||||
.Add("f04", data.Array.TF32(0x04))
|
||||
.Add("f08", data.Array.TF32(0x08))
|
||||
.Add("Index", data.Array.TI32(0x00))
|
||||
.Add("Value", data.Array.TF32(0x04))
|
||||
.Add("Duration", data.Array.TF32(0x08))
|
||||
.Add("i0C", data.Array.TI32(0x0C))
|
||||
.Add("f10", data.Array.TF32(0x10)));
|
||||
break;
|
||||
case 0x38:
|
||||
case 0x38: // SetMouthMottblMotion
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00", data.Array.TI32(0x00))
|
||||
.Add("f04", data.Array.TF32(0x04))
|
||||
.Add("f08", data.Array.TF32(0x08))
|
||||
.Add("Index", data.Array.TI32(0x00))
|
||||
.Add("Value", data.Array.TF32(0x04))
|
||||
.Add("Duration", data.Array.TF32(0x08))
|
||||
.Add("i0C", data.Array.TI32(0x0C))
|
||||
.Add("f10", data.Array.TF32(0x10)));
|
||||
break;
|
||||
case 0x39:
|
||||
case 0x39: // SetEyesMottblMotion
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00", data.Array.TI32(0x00))
|
||||
.Add("f04", data.Array.TF32(0x04))
|
||||
.Add("f08", data.Array.TF32(0x08))
|
||||
.Add("Index", data.Array.TI32(0x00))
|
||||
.Add("Value", data.Array.TF32(0x04))
|
||||
.Add("Duration", data.Array.TF32(0x08))
|
||||
.Add("i0C", data.Array.TI32(0x0C))
|
||||
.Add("f10", data.Array.TF32(0x10)));
|
||||
break;
|
||||
case 0x3A:
|
||||
case 0x3A: // SetEyelidMottblMotion
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00", data.Array.TI32(0x00))
|
||||
.Add("f04", data.Array.TF32(0x04))
|
||||
.Add("f08", data.Array.TF32(0x08))
|
||||
.Add("Index", data.Array.TI32(0x00))
|
||||
.Add("Value", data.Array.TF32(0x04))
|
||||
.Add("Duration", data.Array.TF32(0x08))
|
||||
.Add("i0C", data.Array.TI32(0x0C))
|
||||
.Add("f10", data.Array.TF32(0x10)));
|
||||
break;
|
||||
case 0x3B:
|
||||
case 0x3B: // SetRobCharaHeadObject
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00", data.Array.TI32(0x00)));
|
||||
.Add("Index", data.Array.TI32(0x00)));
|
||||
break;
|
||||
case 0x3C:
|
||||
case 0x3C: // SetLookCamera
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("Enable", data.Array.TI32(0x00))
|
||||
.Add("HeadRotStrength", data.Array.TF32(0x04))
|
||||
.Add("EyesRotStrength", data.Array.TF32(0x08))
|
||||
.Add("BlendDuration", data.Array.TF32(0x0C)));
|
||||
break;
|
||||
case 0x3D: // SetEyelidMotionFromFace
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00", data.Array.TI32(0x00))
|
||||
.Add("f04", data.Array.TF32(0x04))
|
||||
.Add("f08", data.Array.TF32(0x08))
|
||||
.Add("f0C", data.Array.TF32(0x0C)));
|
||||
.Add("Duration", data.Array.TF32(0x04)));
|
||||
break;
|
||||
case 0x3D:
|
||||
case 0x3E: // RobPartsAdjust
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00", data.Array.TI32(0x00))
|
||||
.Add("f04", data.Array.TF32(0x04)));
|
||||
.Add("TransitionDuration", data.Array.TI32(0x00))
|
||||
.Add("Parts", data.Array.TU8(0x04))
|
||||
.Add("Type", data.Array.TU8(0x05))
|
||||
.Add("IgnoreGravity", data.Array.TU8(0x06) != 0)
|
||||
.Add("CycleType", data.Array.TU8(0x07))
|
||||
.Add("ExternalForceX", data.Array.TF32(0x08))
|
||||
.Add("ExternalForceY", data.Array.TF32(0x0C))
|
||||
.Add("ExternalForceZ", data.Array.TF32(0x10))
|
||||
.Add("ExternalForceCycleStrengthX", data.Array.TF32(0x14))
|
||||
.Add("ExternalForceCycleStrengthY", data.Array.TF32(0x18))
|
||||
.Add("ExternalForceCycleStrengthZ", data.Array.TF32(0x1C))
|
||||
.Add("ExternalForceCycleX", data.Array.TF32(0x20))
|
||||
.Add("ExternalForceCycleY", data.Array.TF32(0x24))
|
||||
.Add("ExternalForceCycleZ", data.Array.TF32(0x28))
|
||||
.Add("Cycle", data.Array.TF32(0x2C))
|
||||
.Add("Phase", data.Array.TF32(0x30))
|
||||
.Add("Force", data.Array.TF32(0x34))
|
||||
.Add("Strength", data.Array.TF32(0x38))
|
||||
.Add("StrengthTransition", data.Array.TI32(0x3C)));
|
||||
break;
|
||||
case 0x3E:
|
||||
case 0x40: // OsageReset
|
||||
break;
|
||||
case 0x41: // MotionSkinParam
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00", data.Array.TI32(0x00))
|
||||
.Add("i04_8", data.Array[0x04])
|
||||
.Add("i05_8", data.Array[0x05])
|
||||
.Add("i06_8", data.Array[0x06])
|
||||
.Add("i07_8", data.Array[0x07])
|
||||
.Add("f08", data.Array.TF32(0x08))
|
||||
.Add("f0C", data.Array.TF32(0x0C))
|
||||
.Add("f10", data.Array.TF32(0x10))
|
||||
.Add("f14", data.Array.TF32(0x14))
|
||||
.Add("f18", data.Array.TF32(0x18))
|
||||
.Add("f1C", data.Array.TF32(0x1C))
|
||||
.Add("f20", data.Array.TF32(0x20))
|
||||
.Add("f24", data.Array.TF32(0x24))
|
||||
.Add("f28", data.Array.TF32(0x28))
|
||||
.Add("f2C", data.Array.TF32(0x2C))
|
||||
.Add("f30", data.Array.TF32(0x30))
|
||||
.Add("f34", data.Array.TF32(0x34))
|
||||
.Add("f38", data.Array.TF32(0x38)));
|
||||
.Add("Iterations", data.Array.TI32(0x00)));
|
||||
break;
|
||||
case 0x42:
|
||||
case 0x42: // OsageStep
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("Value", data.Array.TF32(0x00)));
|
||||
break;
|
||||
case 0x43:
|
||||
case 0x43: // SleeveAdjust
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00", data.Array.TI32(0x00))
|
||||
.Add("f04", data.Array.TF32(0x04)));
|
||||
@@ -775,18 +846,18 @@ RETURN:
|
||||
.Add("i00", data.Array.TI32(0x00))
|
||||
.Add("f04", data.Array.TF32(0x04)));
|
||||
break;
|
||||
case 0x45:
|
||||
case 0x45: // MotionMaxFrame
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00", data.Array.TI32(0x00)));
|
||||
.Add("MaxFrame", data.Array.TI32(0x00)));
|
||||
break;
|
||||
case 0x46:
|
||||
case 0x46: // CameraMaxFrame
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00", data.Array.TI32(0x00)));
|
||||
.Add("MaxFrame", data.Array.TI32(0x00)));
|
||||
break;
|
||||
case 0x47:
|
||||
case 0x47: // OsageMoveCancel
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00_8", data.Array[0x00])
|
||||
.Add("f04", data.Array.TF32(0x04)));
|
||||
.Add("ID", data.Array.TU8(0x00)) // 0 - All, 1 - Kami, 2 - Outer
|
||||
.Add("Value", data.Array.TF32(0x04)));
|
||||
break;
|
||||
case 0x48:
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
@@ -796,66 +867,66 @@ RETURN:
|
||||
.Add("i0C", data.Array.TI32(0x0C))
|
||||
.Add("i10", data.Array.TI32(0x10))
|
||||
.Add("i14", data.Array.TI32(0x14))
|
||||
.Add("i18_8", data.Array[0x18])
|
||||
.Add("i19_8", data.Array[0x19])
|
||||
.Add("i1A_8", data.Array[0x1A]));
|
||||
.Add("i18_8", data.Array.TU8(0x18))
|
||||
.Add("i19_8", data.Array.TU8(0x19))
|
||||
.Add("i1A_8", data.Array.TU8(0x1A)));
|
||||
break;
|
||||
case 0x49:
|
||||
case 0x49: // RobHandAdjust
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00_16", data.Array.TI16(0x00))
|
||||
.Add("i02_16", data.Array.TI16(0x02))
|
||||
.Add("f04", data.Array.TF32(0x04))
|
||||
.Add("i08_16", data.Array.TI16(0x08))
|
||||
.Add("f0C", data.Array.TF32(0x0C))
|
||||
.Add("i10", data.Array.TI32(0x10))
|
||||
.Add("i14", data.Array.TI32(0x14))
|
||||
.Add("i18", data.Array.TI32(0x18))
|
||||
.Add("i1C", data.Array.TI32(0x1C))
|
||||
.Add("i20_8", data.Array[0x20])
|
||||
.Add("i21_8", data.Array[0x21])
|
||||
.Add("i22_8", data.Array[0x22])
|
||||
.Add("i23_8", data.Array[0x23])
|
||||
.Add("f24", data.Array.TI32(0x24))
|
||||
.Add("i28", data.Array.TI32(0x28))
|
||||
.Add("Hand", data.Array.TI16(0x00))
|
||||
.Add("ScaleSelect", data.Array.TI16(0x02))
|
||||
.Add("Duration", data.Array.TF32(0x04))
|
||||
.Add("Type", data.Array.TI16(0x08))
|
||||
.Add("Scale", data.Array.TF32(0x0C))
|
||||
.Add("RotBlend", data.Array.TF32(0x10))
|
||||
.Add("OffsetX", data.Array.TF32(0x14))
|
||||
.Add("OffsetY", data.Array.TF32(0x18))
|
||||
.Add("OffsetZ", data.Array.TF32(0x1C))
|
||||
.Add("EnableScale", data.Array.TU8(0x20) != 0)
|
||||
.Add("DisableX", data.Array.TU8(0x21) != 0)
|
||||
.Add("DisableY", data.Array.TU8(0x22) != 0)
|
||||
.Add("DisableZ", data.Array.TU8(0x23) != 0)
|
||||
.Add("OffsetBlend", data.Array.TF32(0x24))
|
||||
.Add("ArmLength", data.Array.TF32(0x28))
|
||||
.Add("i2C", data.Array.TI32(0x2C)));
|
||||
break;
|
||||
case 0x4A:
|
||||
case 0x4A: // DisableCollision
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00_8", data.Array[0x00])
|
||||
.Add("i01_8", data.Array[0x01]));
|
||||
.Add("Parts", data.Array.TU8(0x00))
|
||||
.Add("Disable", data.Array.TU8(0x01)));
|
||||
break;
|
||||
case 0x4B:
|
||||
case 0x4B: // RobAdjustGlobal
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00", data.Array.TI32(0x00))
|
||||
.Add("i04_8", data.Array[0x04])
|
||||
.Add("i05_8", data.Array[0x05])
|
||||
.Add("f08", data.Array.TF32(0x08))
|
||||
.Add("f0C", data.Array.TF32(0x0C))
|
||||
.Add("f10", data.Array.TF32(0x10))
|
||||
.Add("f14", data.Array.TF32(0x14))
|
||||
.Add("f18", data.Array.TF32(0x18))
|
||||
.Add("f1C", data.Array.TF32(0x1C))
|
||||
.Add("f20", data.Array.TF32(0x20))
|
||||
.Add("f24", data.Array.TF32(0x24))
|
||||
.Add("f28", data.Array.TF32(0x28))
|
||||
.Add("f2C", data.Array.TF32(0x2C))
|
||||
.Add("f30", data.Array.TF32(0x30)));
|
||||
.Add("TransitionDuration", data.Array.TI32(0x00))
|
||||
.Add("Type", data.Array.TU8(0x04))
|
||||
.Add("CycleType", data.Array.TU8(0x05))
|
||||
.Add("ExternalForceX", data.Array.TF32(0x08))
|
||||
.Add("ExternalForceY", data.Array.TF32(0x0C))
|
||||
.Add("ExternalForceZ", data.Array.TF32(0x10))
|
||||
.Add("ExternalForceCycleStrengthX", data.Array.TF32(0x14))
|
||||
.Add("ExternalForceCycleStrengthY", data.Array.TF32(0x18))
|
||||
.Add("ExternalForceCycleStrengthZ", data.Array.TF32(0x1C))
|
||||
.Add("ExternalForceCycleX", data.Array.TF32(0x20))
|
||||
.Add("ExternalForceCycleY", data.Array.TF32(0x24))
|
||||
.Add("ExternalForceCycleZ", data.Array.TF32(0x28))
|
||||
.Add("Cycle", data.Array.TF32(0x2C))
|
||||
.Add("Phase", data.Array.TF32(0x30)));
|
||||
break;
|
||||
case 0x4C:
|
||||
case 0x4C: // RobArmAdjust
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00_16", data.Array.TI16(0x00))
|
||||
.Add("f04", data.Array.TF32(0x04))
|
||||
.Add("f08", data.Array.TF32(0x08)));
|
||||
.Add("Index", data.Array.TI16(0x00))
|
||||
.Add("Duration", data.Array.TF32(0x04))
|
||||
.Add("Value", data.Array.TF32(0x08)));
|
||||
break;
|
||||
case 0x4D:
|
||||
case 0x4D: // DisableEyeMotion
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00_8", data.Array[0x00]));
|
||||
.Add("Value", data.Array.TU8(0x00) != 0));
|
||||
break;
|
||||
case 0x4E:
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00_16", data.Array.TI16(0x00))
|
||||
.Add("i02_8", data.Array[0x02])
|
||||
.Add("i03_8", data.Array[0x03])
|
||||
.Add("i02_8", data.Array.TU8(0x02))
|
||||
.Add("i03_8", data.Array.TU8(0x03))
|
||||
.Add("i04", data.Array.TI32(0x04))
|
||||
.Add("i08", data.Array.TI32(0x08))
|
||||
.Add("i0C", data.Array.TI32(0x0C))
|
||||
@@ -863,13 +934,13 @@ RETURN:
|
||||
.Add("i14", data.Array.TI32(0x14))
|
||||
.Add("i18", data.Array.TI32(0x18)));
|
||||
break;
|
||||
case 0x4F:
|
||||
case 0x4F: // RobCharaColiRing
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00_8", data.Array[0]));
|
||||
.Add("Index", data.Array.TU8(0)));
|
||||
break;
|
||||
case 0x50:
|
||||
case 0x50: // AdjustGetGlobalTrans
|
||||
arrayEntry.Add(new MsgPack("Data")
|
||||
.Add("i00_8", data.Array[0]));
|
||||
.Add("Value", data.Array.TU8(0) != 0));
|
||||
break;
|
||||
default:
|
||||
if (data.Array != null && data.Array.Length > 0)
|
||||
@@ -925,32 +996,34 @@ RETURN:
|
||||
0x1D => 0x3C,
|
||||
0x20 => 0x10,
|
||||
0x21 => 0x18,
|
||||
0x32 => 0x04,
|
||||
0x35 => 0x14,
|
||||
0x36 => 0x14,
|
||||
0x37 => 0x14,
|
||||
0x38 => 0x14,
|
||||
0x39 => 0x14,
|
||||
0x3A => 0x14,
|
||||
0x3B => 0x04,
|
||||
0x3C => 0x10,
|
||||
0x3D => 0x08,
|
||||
0x3E => 0x40,
|
||||
0x42 => 0x04,
|
||||
0x43 => 0x08,
|
||||
0x32 => 0x08, // SetFaceMotionId
|
||||
0x35 => 0x14, // SetFaceMottblMotion
|
||||
0x36 => 0x14, // SetHandRMottblMotion
|
||||
0x37 => 0x14, // SetHandLMottblMotion
|
||||
0x38 => 0x14, // SetMouthMottblMotion
|
||||
0x39 => 0x14, // SetEyesMottblMotion
|
||||
0x3A => 0x14, // SetEyelidMottblMotion
|
||||
0x3B => 0x04, // SetRobCharaHeadObject
|
||||
0x3C => 0x10, // SetLookCamera
|
||||
0x3D => 0x08, // SetEyelidMotionFromFace
|
||||
0x3E => 0x40, // RobPartsAdjust
|
||||
0x40 => 0x00, // OsageReset
|
||||
0x41 => 0x04, // MotionSkinParam
|
||||
0x42 => 0x04, // OsageStep
|
||||
0x43 => 0x08, // SleeveAdjust
|
||||
0x44 => 0x08,
|
||||
0x45 => 0x04,
|
||||
0x46 => 0x04,
|
||||
0x47 => 0x08,
|
||||
0x45 => 0x04, // MotionMaxFrame
|
||||
0x46 => 0x04, // CameraMaxFrame
|
||||
0x47 => 0x08, // OsageMoveCancel
|
||||
0x48 => 0x1C,
|
||||
0x49 => 0x30,
|
||||
0x4A => 0x02,
|
||||
0x4B => 0x34,
|
||||
0x4C => 0x0C,
|
||||
0x4D => 0x01,
|
||||
0x49 => 0x30, // RobHandAdjust
|
||||
0x4A => 0x02, // DisableCollision
|
||||
0x4B => 0x34, // RobAdjustGlobal
|
||||
0x4C => 0x0C, // RobArmAdjust
|
||||
0x4D => 0x01, // DisableEyeMotion
|
||||
0x4E => 0x1C,
|
||||
0x4F => 0x01,
|
||||
0x50 => 0x01,
|
||||
0x4F => 0x01, // RobCharaColiRing
|
||||
0x50 => 0x01, // AdjustGetGlobalTrans
|
||||
_ => 0x00,
|
||||
};
|
||||
|
||||
@@ -959,18 +1032,24 @@ RETURN:
|
||||
0x00 => 0x1C,
|
||||
0x01 => 0x08,
|
||||
0x02 => 0x14,
|
||||
0x28 => 0x10,
|
||||
0x2E => 0x02,
|
||||
0x33 => 0x02,
|
||||
0x37 => 0x0C,
|
||||
0x40 => 0x0C,
|
||||
0x42 => 0x04,
|
||||
0x44 => 0x04,
|
||||
_ => 0x00,
|
||||
};
|
||||
|
||||
public void Dispose()
|
||||
public void Dispose()
|
||||
{ if (s != null) s.D(); s = null; Header = default; }
|
||||
|
||||
public struct HeaderData
|
||||
{
|
||||
public int MotionSetID;
|
||||
public int FirstMotionID;
|
||||
public int LastMotionID;
|
||||
public uint MotionSetID;
|
||||
public uint FirstMotionID;
|
||||
public uint LastMotionID;
|
||||
public int SubHeaderOffset;
|
||||
|
||||
public Sub[] Data;
|
||||
@@ -978,7 +1057,7 @@ RETURN:
|
||||
public struct Sub
|
||||
{
|
||||
public int Offset;
|
||||
public int MotionID;
|
||||
public uint MotionID;
|
||||
|
||||
public int Field00;
|
||||
public int Field04;
|
||||
@@ -1013,9 +1092,31 @@ RETURN:
|
||||
|
||||
public enum Type
|
||||
{
|
||||
WindReset = 0x40,
|
||||
OsageReset = 0x41,
|
||||
OsageStep = 0x42,
|
||||
SetFaceMotionId = 0x32,
|
||||
SetFaceMottblMotion = 0x35,
|
||||
SetHandRMottblMotion = 0x36,
|
||||
SetHandLMottblMotion = 0x37,
|
||||
SetMouthMottblMotion = 0x38,
|
||||
SetEyesMottblMotion = 0x39,
|
||||
SetEyelidMottblMotion = 0x3A,
|
||||
SetRobCharaHeadObject = 0x3B,
|
||||
SetLookCamera = 0x3C,
|
||||
SetEyelidMotionFromFace = 0x3D,
|
||||
RobPartsAdjust = 0x3E,
|
||||
OsageReset = 0x40,
|
||||
MotionSkinParam = 0x41,
|
||||
OsageStep = 0x42,
|
||||
SleeveAdjust = 0x43,
|
||||
MotionMaxFrame = 0x45,
|
||||
CameraMaxFrame = 0x46,
|
||||
OsageMoveCancel = 0x47,
|
||||
RobHandAdjust = 0x49,
|
||||
DisableCollision = 0x4A,
|
||||
RobAdjustGlobal = 0x4B,
|
||||
RobArmAdjust = 0x4C,
|
||||
DisableEyeMotion = 0x4D,
|
||||
RobCharaColiRing = 0x4F,
|
||||
AdjustGetGlobalTrans = 0x50,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -178,10 +178,11 @@ namespace KKdMainLib
|
||||
MsgPack strings = new MsgPack(Strings.Length, "Strings");
|
||||
for (int i = 0; i < Strings.Length; i++)
|
||||
{
|
||||
strings[i] = MsgPack.New.Add("ID", Strings[i].ID);
|
||||
MsgPack @string = 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);
|
||||
@string.Add("Str", Strings[i].Str.V);
|
||||
strings[i] = @string;
|
||||
}
|
||||
str.Add(strings);
|
||||
|
||||
|
||||
Binary file not shown.
+6
-5
@@ -24,9 +24,10 @@ namespace KKdSoundLib
|
||||
Data.SampleRate = reader.RI32();
|
||||
Data.SamplesCount = reader.RI32();
|
||||
reader.RI64();
|
||||
Data.Channels = reader.RU16();
|
||||
Data.Channels = reader.RU8();
|
||||
reader.RU8();
|
||||
reader.RU16();
|
||||
Data.Name = reader.RS(0x20);
|
||||
reader.RBy(0x20);
|
||||
|
||||
byte value = 0;
|
||||
byte[] data = new byte[Data.SamplesCount * Data.Channels * 4];
|
||||
@@ -39,6 +40,7 @@ namespace KKdSoundLib
|
||||
fixed (sbyte* stepindexPtr = stepindex)
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
reader.S(0, SeekOrigin.Begin);
|
||||
float* dataPtr = (float*)ptr;
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Data.Channels; c++, dataPtr++)
|
||||
@@ -76,7 +78,7 @@ namespace KKdSoundLib
|
||||
if (!Header.IsSupported) { reader.C(); return; }
|
||||
|
||||
Stream writer = File.OpenWriter(file + ".diva", true);
|
||||
Data.Channels = Header.Channels;
|
||||
Data.Channels = (byte)Header.Channels;
|
||||
Data.SampleRate = Header.SampleRate;
|
||||
Data.SamplesCount = Header.Size / Header.Channels / Header.Bytes;
|
||||
writer.PI64 = 0x40;
|
||||
@@ -198,8 +200,7 @@ namespace KKdSoundLib
|
||||
public int Size;
|
||||
public int SampleRate;
|
||||
public int SamplesCount;
|
||||
public string Name;
|
||||
public ushort Channels;
|
||||
public byte Channels;
|
||||
public byte[] Data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
<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>
|
||||
<Copyright>korenkonder (C) 2019-2022</Copyright>
|
||||
<Description>A simple library for working with Project Diva F/AFT/F2/X/XHD/FT/VRFL/M39 audio files</Description>
|
||||
<FileVersion>0.1.2.1</FileVersion>
|
||||
<PackageId>KKdSoundLib</PackageId>
|
||||
<Product>KKdSoundLib</Product>
|
||||
<TargetFramework>net461</TargetFramework>
|
||||
<Title>KKdSoundLib</Title>
|
||||
<Version>0.1.2.0</Version>
|
||||
<Version>0.1.2.1</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
||||
+828
-828
File diff suppressed because it is too large
Load Diff
@@ -334,6 +334,8 @@ namespace PD_Tool
|
||||
else if (filetype == "json") Filter = GetArgs("JSON", "json");
|
||||
else if (filetype == "igb" ) Filter = GetArgs("IGB", "igb");
|
||||
else if (filetype == "mgftxt") Filter = GetArgs("MGF2AFT txt", "txt");
|
||||
else if (filetype == "mhd" ) Filter = GetArgs("MotHead", "mhd", "bin", "json", "mp") +
|
||||
GetArgs("MotHead", true, "mhd") + bin + json + mp;
|
||||
else if (filetype == "mp" ) Filter = GetArgs("MessagePack", "mp");
|
||||
else if (filetype == "lit") Filter = GetArgs("LIT" , "lit", "json", "mp") +
|
||||
GetArgs("LIT", true, "lit") + json + mp;
|
||||
|
||||
@@ -6,10 +6,10 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("PD_Tool")]
|
||||
[assembly: AssemblyCopyright("korenkonder (C) 2017-2022")]
|
||||
[assembly: AssemblyCopyright("korenkonder (C) 2017-2025")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
|
||||
[assembly: AssemblyVersion("0.4.10.10")]
|
||||
[assembly: AssemblyFileVersion("0.4.10.10")]
|
||||
[assembly: AssemblyVersion("0.5.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.5.0.0")]
|
||||
|
||||
+25
-16
@@ -37,20 +37,29 @@ namespace PD_Tool
|
||||
Program.ConsoleDesign("8. A3DC [XHD/VRFL]");
|
||||
if (!mp) Program.ConsoleDesign($"9. {(json ? "JSON" : "MsgPack")}");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign("X[Y] - X: option; Y: rounding in text (def. 9)");
|
||||
Program.ConsoleDesign(false);
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
choose = Console.ReadLine().ToUpper();
|
||||
if (choose == "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;
|
||||
if (choose == null || choose.Length < 1)
|
||||
return;
|
||||
else if (choose[0] == '1') format = Format.DT ;
|
||||
else if (choose[0] == '2') format = Format.F ;
|
||||
else if (choose[0] == '3') format = Format.AFT;
|
||||
else if (choose[0] == '4') format = Format.AFT;
|
||||
else if (choose[0] == '5') format = Format.F2 ;
|
||||
else if (choose[0] == '6') format = Format.MGF;
|
||||
else if (choose[0] == '7') format = Format.X ;
|
||||
else if (choose[0] == '8') format = Format.XHD;
|
||||
else if (choose[0] == '9') format = Format.NULL;
|
||||
else return;
|
||||
|
||||
if (int.TryParse(choose.Substring(1), out int rounding))
|
||||
KKdA3DA.Rounding = rounding;
|
||||
else
|
||||
KKdA3DA.Rounding = 9;
|
||||
|
||||
int state;
|
||||
string filepath, ext;
|
||||
KKdA3DA a3da;
|
||||
@@ -69,12 +78,12 @@ namespace PD_Tool
|
||||
{
|
||||
state = a3da.A3DAReader(filepath);
|
||||
if (state == 1)
|
||||
if (choose == "9") a3da.MsgPackWriter(filepath, json);
|
||||
if (choose[0] == '9') a3da.MsgPackWriter(filepath, json);
|
||||
else
|
||||
{
|
||||
a3da.Head.Format = format;
|
||||
File.WriteAllBytes(filepath + ".a3da", (choose == "1" ||
|
||||
choose == "4") ? a3da.A3DAWriter() : a3da.A3DCWriter());
|
||||
File.WriteAllBytes(filepath + ".a3da", choose[0] == '1' || choose[0] == '3'
|
||||
? a3da.A3DAWriter() : a3da.A3DCWriter());
|
||||
}
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
@@ -83,8 +92,8 @@ namespace PD_Tool
|
||||
a3da.MsgPackReader(filepath, ext == ".json");
|
||||
a3da.Head.Format = format;
|
||||
|
||||
File.WriteAllBytes(filepath + ".a3da", (choose == "1" ||
|
||||
choose == "4") ? a3da.A3DAWriter() : a3da.A3DCWriter());
|
||||
File.WriteAllBytes(filepath + ".a3da", choose[0] == '1' || choose[0] == '3'
|
||||
? a3da.A3DAWriter() : a3da.A3DCWriter());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,7 +127,7 @@ namespace PD_Tool
|
||||
{
|
||||
KKdFARC.FARCFile file = farc.Files[i];
|
||||
a3da.Head.Format = format;
|
||||
file.Data = (choose == "1"|| choose == "4")
|
||||
file.Data = choose[0] == '1' || choose[0] == '3'
|
||||
? a3da.A3DAWriter() : a3da.A3DCWriter();
|
||||
farc.Files[i] = file;
|
||||
}
|
||||
@@ -168,7 +177,7 @@ namespace PD_Tool
|
||||
KKdFARC.FARCFile file = default;
|
||||
file.Name = list[i];
|
||||
a3daArray[i].Head.Format = format;
|
||||
file.Data = (choose == "1" || choose == "4")
|
||||
file.Data = choose[0] == '1'|| choose[0] == '3'
|
||||
? a3daArray[i].A3DAWriter() : a3daArray[i].A3DCWriter();
|
||||
farc.Files.Add(file);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace PD_Tool
|
||||
if (file.EndsWith(".mp" )) { mp = false; break; }
|
||||
else if (file.EndsWith(".json")) { mp = false; break; }
|
||||
|
||||
uint num2 = (uint)((DateTime.Now.Ticks - 621355968000000000) / 10000000);
|
||||
uint timestamp = (uint)((DateTime.Now.Ticks - 621355968000000000) / 10000000);
|
||||
string[] file_split;
|
||||
string filepath, ext;
|
||||
KKdMainLib.DataBank db;
|
||||
@@ -48,7 +48,7 @@ namespace PD_Tool
|
||||
{
|
||||
Console.Title = "DataBank Converter: " + filename;
|
||||
db.MsgPackReader(filepath, json);
|
||||
db. DBWriter(filepath, num2);
|
||||
db. DBWriter(filepath, timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace PD_Tool
|
||||
|
||||
if (head != 0x454C494641564944) return;
|
||||
System.Console.Title = "DIVAFILE Decrypt: " + Path.GetFileName(file);
|
||||
file.Decrypt();
|
||||
KKdMainLib.DIVAFILE.Decrypt(file);
|
||||
}
|
||||
|
||||
public static void Encrypt(string file)
|
||||
@@ -24,7 +24,7 @@ namespace PD_Tool
|
||||
|
||||
if (head == 0x454C494641564944) return;
|
||||
System.Console.Title = "DIVAFILE Encrypt: " + Path.GetFileName(file);
|
||||
file.Encrypt();
|
||||
KKdMainLib.DIVAFILE.Encrypt(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,12 +63,12 @@ namespace PD_Tool
|
||||
Program.ConsoleDesign(true);
|
||||
Console.WriteLine();
|
||||
choose = Console.ReadLine().ToUpper();
|
||||
if (choose == "2" || choose == "4") farc.FARCType |= KKdFARC.Type.GZip;
|
||||
if (choose == "3" || choose == "4") farc.FARCType |= KKdFARC.Type.Enc ;
|
||||
if (choose == "2" || choose == "4") farc.FARCFlags |= KKdFARC.Flags.GZip;
|
||||
if (choose == "3" || choose == "4") farc.FARCFlags |= KKdFARC.Flags.AES ;
|
||||
}
|
||||
else if (choose == "R") return;
|
||||
else farc.Signature = KKdFARC.Farc.FArC;
|
||||
farc.Pack(farc.Signature);
|
||||
farc.Pack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace PD_Tool
|
||||
public static void Processor(bool json)
|
||||
{
|
||||
Console.Title = "MotHead Converter";
|
||||
Program.Choose(1, "bin", out string[] fileNames);
|
||||
Program.Choose(1, "mhd", out string[] fileNames);
|
||||
if (fileNames.Length < 1) return;
|
||||
|
||||
string filepath, ext;
|
||||
@@ -21,9 +21,9 @@ namespace PD_Tool
|
||||
ext = Path.GetExtension(file).ToLower();
|
||||
|
||||
Console.Title = "MotHead Converter: " + Path.GetFileNameWithoutExtension(file);
|
||||
if (ext == ".bin")
|
||||
if (ext == ".bin" || ext == ".mhd")
|
||||
{
|
||||
mhd.MotHeadReader(filepath);
|
||||
mhd.MotHeadReader(filepath, ext);
|
||||
mhd.MsgPackWriter(filepath, json);
|
||||
}
|
||||
else if (ext == ".mp" || ext == ".json")
|
||||
|
||||
Reference in New Issue
Block a user