Release v0.4.7.5

A3DA, Aet, AetDB, AuthDB, Databank, DEX, MOT, STR, VAG
This commit is contained in:
KujiKita
2019-09-30 20:44:46 +03:00
parent 792781a5f7
commit 4698c75c7a
34 changed files with 801 additions and 634 deletions
+8
View File
@@ -46,5 +46,13 @@ namespace KKdBaseLib
result = (ushort)(ChecksumLookupTable[(result >> 8) ^ data[i]] ^ (result << 8));
return result;
}
public static uint CalculateChecksumUInt(byte[] data)
{
uint result = 0xFFFFFFFF;
for (int i = 0; i < data.Length; i++)
result = ChecksumLookupTable[((ushort)result >> 8) ^ data[i]] ^ (result << 8);
return result;
}
}
}
+48 -42
View File
@@ -92,98 +92,86 @@ namespace KKdBaseLib
public static byte* bufPtr = buf.GetPtr();
public static byte[] Endian(this byte[] LE, byte Len)
{ for (byte i = 0; i < Len; i++) bufPtr[i] = LE[i];
{ CFUTRM(buf, ref bufPtr);
for (byte i = 0; i < Len; i++) bufPtr[i] = LE[i];
for (byte i = 0; i < Len; i++) LE[Len - i - 1] = bufPtr[i]; return LE; }
public static byte[] Endian(this byte[] LE, byte Len, bool IsBE)
{ if (IsBE) { for (byte i = 0; i < Len; i++) bufPtr[i] = LE[i];
{ CFUTRM(buf, ref bufPtr);
if (IsBE) { for (byte i = 0; i < Len; i++) bufPtr[i] = LE[i];
for (byte i = 0; i < Len; i++) LE[Len - i - 1] = bufPtr[i]; } return LE; }
public static short Endian(this short LE, bool IsBE)
{ if (IsBE) { int TLE = 0; for (byte i = 0; i < 2; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
{ CFUTRM(buf, ref bufPtr);
if (IsBE) { int TLE = 0; for (byte i = 0; i < 2; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
for (byte i = 0; i < 2; i++) { TLE |= bufPtr[i]; if (i < 1) TLE <<= 8; } LE = (short)TLE; } return LE; }
public static ushort Endian(this ushort LE, bool IsBE)
{ if (IsBE) { for (byte i = 0; i < 2; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
{ CFUTRM(buf, ref bufPtr);
if (IsBE) { for (byte i = 0; i < 2; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
for (byte i = 0; i < 2; i++) { LE |= bufPtr[i]; if (i < 1) LE <<= 8; } } return LE; }
public static int Endian(this int LE, bool IsBE)
{ if (IsBE) { for (byte i = 0; i < 4; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
{ CFUTRM(buf, ref bufPtr);
if (IsBE) { for (byte i = 0; i < 4; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
for (byte i = 0; i < 4; i++) { LE |= bufPtr[i]; if (i < 3) LE <<= 8; } } return LE; }
public static uint Endian(this uint LE, bool IsBE)
{ if (IsBE) { for (byte i = 0; i < 4; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
{ CFUTRM(buf, ref bufPtr);
if (IsBE) { for (byte i = 0; i < 4; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
for (byte i = 0; i < 4; i++) { LE |= bufPtr[i]; if (i < 3) LE <<= 8; } } return LE; }
public static long Endian(this long LE, bool IsBE)
{ if (IsBE) { for (byte i = 0; i < 8; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
{ CFUTRM(buf, ref bufPtr);
if (IsBE) { for (byte i = 0; i < 8; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
for (byte i = 0; i < 8; i++) { LE |= bufPtr[i]; if (i < 7) LE <<= 8; } } return LE; }
public static ulong Endian(this ulong LE, bool IsBE)
{ if (IsBE) { for (byte i = 0; i < 8; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
{ CFUTRM(buf, ref bufPtr);
if (IsBE) { for (byte i = 0; i < 8; i++) { bufPtr[i] = (byte)LE; LE >>= 8; } LE = 0;
for (byte i = 0; i < 8; i++) { LE |= bufPtr[i]; if (i < 7) LE <<= 8; } } return LE; }
public static sbyte CITSB(this int c)
{ if (c > 0x0000007F) c = 0x0000007F;
else if (c < -0x00000080) c = -0x00000080; return ( sbyte)c; }
{ return ( sbyte)(c > 0x0000007F ? 0x0000007F : c < -0x00000080 ? -0x00000080 : c); }
public static byte CITB (this int c)
{ if (c > 0x000000FF) c = 0x000000FF;
else if (c < 0x00000000) c = 0x00000000; return ( byte)c; }
{ return ( byte)(c > 0x000000FF ? 0x000000FF : c < 0x00000000 ? 0x00000000 : c); }
public static short CITS (this int c)
{ if (c > 0x00007FFF) c = 0x00007FFF;
else if (c < -0x00008000) c = -0x00008000; return ( short)c; }
{ return ( short)(c > 0x00007FFF ? 0x00007FFF : c < -0x00008000 ? -0x00008000 : c); }
public static ushort CITUS(this int c)
{ if (c > 0x0000FFFF) c = 0x0000FFFF;
else if (c < 0x00000000) c = 0x00000000; return (ushort)c; }
{ return (ushort)(c > 0x0000FFFF ? 0x0000FFFF : c < 0x00000000 ? 0x00000000 : c); }
public static sbyte CFTSB(this float c)
{ c = c.Round(); if (c > 0x0000007F) c = 0x0000007F;
else if (c < -0x00000080) c = -0x00000080; return ( sbyte)c; }
{ c = c.Round(); return ( sbyte)(c > 0x0000007F ? 0x0000007F : c < -0x00000080 ? -0x00000080 : c); }
public static byte CFTB (this float c)
{ c = c.Round(); if (c > 0x000000FF) c = 0x000000FF;
else if (c < 0x00000000) c = 0x00000000; return ( byte)c; }
{ c = c.Round(); return ( byte)(c > 0x000000FF ? 0x000000FF : c < 0x00000000 ? 0x00000000 : c); }
public static short CFTS (this float c)
{ c = c.Round(); if (c > 0x00007FFF) c = 0x00007FFF;
else if (c < -0x00008000) c = -0x00008000; return ( short)c; }
{ c = c.Round(); return ( short)(c > 0x00007FFF ? 0x00007FFF : c < -0x00008000 ? -0x00008000 : c); }
public static ushort CFTUS(this float c)
{ c = c.Round(); if (c > 0x0000FFFF) c = 0x0000FFFF;
else if (c < 0x00000000) c = 0x00000000; return (ushort)c; }
public static int CFTI (this float c)
{ c = c.Round(); return ( int)c; }
public static uint CFTUI(this float c)
{ c = c.Round(); return ( uint)c; }
{ c = c.Round(); return (ushort)(c > 0x0000FFFF ? 0x0000FFFF : c < 0x00000000 ? 0x00000000 : c); }
public static sbyte CFTSB(this double c)
{ c = c.Round(); if (c > 0x0000007F) c = 0x0000007F;
else if (c < -0x00000080) c = -0x00000080; return ( sbyte)c; }
{ c = c.Round(); return ( sbyte)(c > 0x0000007F ? 0x0000007F : c < -0x00000080 ? -0x00000080 : c); }
public static byte CFTB (this double c)
{ c = c.Round(); if (c > 0x000000FF) c = 0x000000FF;
else if (c < 0x00000000) c = 0x00000000; return ( byte)c; }
{ c = c.Round(); return ( byte)(c > 0x000000FF ? 0x000000FF : c < 0x00000000 ? 0x00000000 : c); }
public static short CFTS (this double c)
{ c = c.Round(); if (c > 0x00007FFF) c = 0x00007FFF;
else if (c < -0x00008000) c = -0x00008000; return ( short)c; }
{ c = c.Round(); return ( short)(c > 0x00007FFF ? 0x00007FFF : c < -0x00008000 ? -0x00008000 : c); }
public static ushort CFTUS(this double c)
{ c = c.Round(); if (c > 0x0000FFFF) c = 0x0000FFFF;
else if (c < 0x00000000) c = 0x00000000; return (ushort)c; }
{ c = c.Round(); return (ushort)(c > 0x0000FFFF ? 0x0000FFFF : c < 0x00000000 ? 0x00000000 : c); }
public static int CFTI (this double c)
{ c = c.Round(); if (c > 0x7FFFFFFF) c = 0x7FFFFFFF;
else if (c < -0x80000000) c = -0x80000000; return ( int)c; }
{ c = c.Round(); return ( int)(c > 0x7FFFFFFF ? 0x7FFFFFFF : c < -0x80000000 ? -0x80000000 : c); }
public static uint CFTUI(this double c)
{ c = c.Round(); if (c > 0xFFFFFFFF) c = 0xFFFFFFFF;
else if (c < 0x00000000) c = 0x00000000; return ( uint)c; }
{ c = c.Round(); return ( uint)(c > 0xFFFFFFFF ? 0xFFFFFFFF : c < 0xFFFFFFFF ? 0x00000000 : c); }
public static int ToInt32(this float f) => *( int*)&f;
public static uint ToUInt32(this float f) => *( uint*)&f;
@@ -206,6 +194,17 @@ namespace KKdBaseLib
public static float* GetPtr(this float[] array) { fixed ( float* tempPtr = array) return tempPtr; }
public static double* GetPtr(this double[] array) { fixed (double* tempPtr = array) return tempPtr; }
public static IntPtr GetIntPtr(this sbyte[] array) { fixed ( sbyte* tempPtr = array) return (IntPtr)tempPtr; }
public static IntPtr GetIntPtr(this byte[] array) { fixed ( byte* tempPtr = array) return (IntPtr)tempPtr; }
public static IntPtr GetIntPtr(this short[] array) { fixed ( short* tempPtr = array) return (IntPtr)tempPtr; }
public static IntPtr GetIntPtr(this ushort[] array) { fixed (ushort* tempPtr = array) return (IntPtr)tempPtr; }
public static IntPtr GetIntPtr(this int[] array) { fixed ( int* tempPtr = array) return (IntPtr)tempPtr; }
public static IntPtr GetIntPtr(this uint[] array) { fixed ( uint* tempPtr = array) return (IntPtr)tempPtr; }
public static IntPtr GetIntPtr(this long[] array) { fixed ( long* tempPtr = array) return (IntPtr)tempPtr; }
public static IntPtr GetIntPtr(this ulong[] array) { fixed ( ulong* tempPtr = array) return (IntPtr)tempPtr; }
public static IntPtr GetIntPtr(this float[] array) { fixed ( float* tempPtr = array) return (IntPtr)tempPtr; }
public static IntPtr GetIntPtr(this double[] array) { fixed (double* tempPtr = array) return (IntPtr)tempPtr; }
public static string ToString(this int d, bool IsBE) =>
BitConverter.GetBytes(d.Endian(IsBE)).ToASCII();
@@ -263,5 +262,12 @@ namespace KKdBaseLib
{ bool Val = ToSingle(s, out float val); value = val; return Val; }
public static bool ToDouble(this string s, out double? value)
{ bool Val = ToDouble(s, out double val); value = val; return Val; }
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]
[System.Security.SecuritySafeCritical]
private static void CFUTRM(byte[] buf, ref byte* bufPtr) //CheckForUnableToReadMemory
{ try { if (buf[0] != bufPtr[0] || bufPtr[1] != bufPtr[1] || bufPtr[2] != bufPtr[2] || buf[3] != bufPtr[3] ||
buf[4] != bufPtr[4] || bufPtr[5] != bufPtr[5] || bufPtr[6] != bufPtr[6] || buf[7] != bufPtr[7])
bufPtr = buf.GetPtr(); } catch (AccessViolationException) { bufPtr = buf.GetPtr(); } }
}
}
+65 -36
View File
@@ -1,25 +1,29 @@
namespace KKdBaseLib.F2
{
public unsafe struct ENRSList
public unsafe struct ENRSList : INull
{
public int ID;
public bool EOFC;
public int Depth;
public KKdList<ENRS> List;
public int Length => length();
public bool IsNull => List. IsNull;
public bool NotNull => List.NotNull;
public static ENRSList Read(byte[] data, int ID = 0, bool EOFC = false)
public static ENRSList Read(byte[] data, int Depth = 0)
{
if (data == null || data.Length < 0x10) return default;
byte* ptr = data.GetPtr();
int i, i0;
int ENRSCount = ((int*)ptr)[1];
KKdList<ENRS> List = KKdList<ENRS>.New;
ptr += 0x10;
ENRS ENR;
ENRS.SubENRS Sub;
for (i = 0; i < ENRSCount; i++)
{
ENRS ENR;
ENR = default;
ENR.Offset = ReadENRSValue(ref ptr);
ENR.Count = ReadENRSValue(ref ptr);
ENR.Size = ReadENRSValue(ref ptr);
@@ -32,16 +36,17 @@
ENR.Sub = new KKdList<ENRS.SubENRS> { Capacity = ENR.Count };
for (i0 = 0; i0 < ENR.Count; i0++)
{
ENRS.SubENRS Sub = ENR.Sub[0];
Sub.Skip = ReadENRSValue(ref ptr, out Sub.Type) + i0 > 0 ? ENR.Sub[i0 - 1].SizeSkip : 0;
Sub = default;
Sub.Skip = ReadENRSValue(ref ptr, out Sub.Type);
Sub.Reverse = ReadENRSValue(ref ptr);
if (i0 > 0) Sub.Skip += ENR.Sub[i0 - 1].SizeSkip;
ENR.Sub.Add(Sub);
if (ENR.Sub[i0].Type == ENRS.Type.Invalid) return default;
}
List.Add(ENR);
}
return new ENRSList { EOFC = EOFC, ID = ID, List = List };
return new ENRSList { Depth = Depth, List = List };
}
public static byte[] Write(ENRSList ENRS)
@@ -53,20 +58,7 @@
KKdList<ENRS> List = (System.Collections.Generic.List<ENRS>)ENRS.List;
if (ENRS.IsNull || ENRS.List.Count < 1) return new byte[0x20];
int length = 0x10;
for (i = 0; i < ENRS.List.Count; i++)
{
length += 0x10;
ENRS ENR = ENRS.List[i];
if (ENR.Repeat > 0 && ENR.Sub.NotNull)
{
ENR.Count = ENR.Sub.Count;
length += 0x8 * ENR.Count;
}
else ENR.Repeat = 0;
ENRS.List[i] = ENR;
}
data = new byte[length];
data = new byte[ENRS.Length];
ptr = data.GetPtr();
((int*)ptr)[1] = ENRS.List.Count;
ptr += 0x10;
@@ -85,28 +77,65 @@
{
if (ENR.Sub[i0].Type < ENRSList.ENRS.Type. WORD ||
ENR.Sub[i0].Type > ENRSList.ENRS.Type.QWORD)
return GetFinalArray(data, ptr);
return data;
WriteENRSValue(ref ptr, i0 > 0 ? ENR.Sub[i0].Skip - ENR.Sub[i0 - 1].SizeSkip : ENR.Sub[i0].Skip, ENR.Sub[i0].Type);
WriteENRSValue(ref ptr, i0 > 0 ? ENR.Sub[i0].Skip -
ENR.Sub[i0 - 1].SizeSkip : ENR.Sub[i0].Skip, ENR.Sub[i0].Type);
WriteENRSValue(ref ptr, ENR.Sub[i0].Reverse);
}
}
return GetFinalArray(data, ptr);
return data;
}
private int length()
{
int i, i0;
int length = 0x10;
for (i = 0; i < List.Count; i++)
{
ENRS ENR = List[i];
length += GetSize(i > 0 ? ENR.Offset - List[i - 1].Offset : ENR.Offset);
length += GetSize(ENR.Count );
length += GetSize(ENR.Size );
length += GetSize(ENR.Repeat);
if (ENR.Repeat < 1) continue;
for (i0 = 0; i0 < ENR.Count; i0++)
{
if (ENR.Sub[i0].Type < ENRS.Type. WORD ||
ENR.Sub[i0].Type > ENRS.Type.QWORD) return length.Align(0x10);
length += GetSizeType(i0 > 0 ? ENR.Sub[i0].Skip - ENR.Sub[i0 - 1].SizeSkip : ENR.Sub[i0].Skip);
length += GetSize(ENR.Sub[i0].Reverse);
}
}
return length.Align(0x10);
int GetSizeType(int Val) => Val < 0x00000010 ? 1 : Val < 0x00001000 ? 2 : 4;
int GetSize (int Val) => Val < 0x00000040 ? 1 : Val < 0x00004000 ? 2 : 4;
}
/*private static KKdList<ENRS.SubENRS> Optimize(KKdList<ENRS.SubENRS> Sub)
{
if (Sub.IsNull || Sub.Count < 2) return Sub;
for (int i = 1; i < Sub.Capacity; i++)
if (Sub[i - 1].Skip == Sub[i].Skip - Sub[i - 1].Size && Sub[i - 1].Type == Sub[i].Type)
{
ENRS.SubENRS SubENRS = Sub[i - 1];
SubENRS.Reverse++;
Sub[i - 1] = SubENRS;
Sub.RemoveAt(i);
Sub.Capacity--;
i--;
}
return Sub;
}*/
[System.ThreadStatic] private static ENRS.Value Value;
private static byte[] GetFinalArray(byte[] data, byte* ptr)
{
byte* Ptr = data.GetPtr();
long length = (long)ptr - (long)Ptr;
byte[] tempdata = new byte[length.Align(0x10)];
for (int i = 0; i < length; i++) tempdata[i] = data[i];
data = null;
return tempdata;
}
private static int ReadENRSValue(ref byte* ptr, out ENRS.Type Type)
{
int V = *ptr & 0xF;
@@ -217,6 +246,6 @@
}
public override string ToString() =>
$"ID: {ID}{(NotNull ? $"; ENRS Count: {List.Count}" : "")}{(EOFC ? "; Has EOFC" : "")}";
$"Depth: {Depth}{(NotNull ? $"; ENRS Count: {List.Count}" : "")}";
}
}
+1 -1
View File
@@ -6,7 +6,7 @@
public int DataSize;
public int Length;
public int Flags;
public int ID;
public int Depth;
public int SectionSize;
public int Mode;
public int InnerSignature;
+39 -28
View File
@@ -1,15 +1,17 @@
namespace KKdBaseLib.F2
{
public unsafe struct POF
public unsafe struct POF : INull
{
public int ID;
public bool EOFC;
public int Depth;
public KKdList<long> Offsets;
public bool IsNull => Offsets. IsNull;
public bool NotNull => Offsets.NotNull;
public static POF Read(byte[] data, bool ShiftX, int ID = 0, bool EOFC = false)
public int Length => length(false).Align(0x10);
public int LengthX => length( true).Align(0x10);
public static POF Read(byte[] data, bool ShiftX, int Depth = 0)
{
Value Val = 0;
KKdList<long> Offsets = KKdList<long>.New;
@@ -31,33 +33,22 @@
Offset += V;
Offsets.Add(Offset << BitShift);
}
return new POF { EOFC = EOFC, ID = ID, Offsets = Offsets };
return new POF { Depth = Depth, Offsets = Offsets };
}
public static byte[] Write(POF POF, bool ShiftX)
{
POF.Offsets.Sort();
int Length = 5;
long Offset = 0;
byte BitShift = (byte)(ShiftX ? 3 : 2);
int Max1 = 0x00FF >> BitShift;
int Max2 = 0xFFFF >> BitShift;
for (int i = 0; i < POF.Offsets.Count; i++)
{
Offset = POF.Offsets[i];
if (i > 0) { Offset -= POF.Offsets[i - 1]; if (Offset == 0) continue; }
int Max1 = 0x00100 >> BitShift;
int Max2 = 0x10000 >> BitShift;
Offset >>= BitShift;
if (Offset <= Max1) Length += 1;
else if (Offset <= Max2) Length += 2;
else Length += 4;
}
byte[] data = new byte[Length.Align(0x10)];
byte[] data = new byte[POF.Length];
byte* ptr = data.GetPtr();
byte Val = 0;
*(int*)ptr = Length; ptr += 4;
*(int*)ptr = POF.length(ShiftX); ptr += 4;
for (int i = 0; i < POF.Offsets.Count; i++)
{
Offset = POF.Offsets[i];
@@ -65,18 +56,38 @@
Offset >>= BitShift;
Val = (byte)(Offset > Max2 ? Value.Int32 : Offset > Max1 ? Value.Int16 : Value.Int8);
if (Offset <= Max1) *ptr = (byte)(Val | Offset );
else if (Offset <= Max2) { *ptr = (byte)(Val | (Offset >> 8)); ptr++;
*ptr = (byte) Offset ; }
else { *ptr = (byte)(Val | (Offset >> 24)); ptr++;
*ptr = (byte) (Offset >> 16) ; ptr++;
*ptr = (byte) (Offset >> 8) ; ptr++;
*ptr = (byte) Offset ; }
if (Offset < Max1) *ptr = (byte)(Val | Offset );
else if (Offset < Max2) { *ptr = (byte)(Val | (Offset >> 8)); ptr++;
*ptr = (byte) Offset ; }
else { *ptr = (byte)(Val | (Offset >> 24)); ptr++;
*ptr = (byte) (Offset >> 16) ; ptr++;
*ptr = (byte) (Offset >> 8) ; ptr++;
*ptr = (byte) Offset ; }
ptr++;
}
return data;
}
private int length(bool ShiftX = false)
{
int length = 5;
long Offset = 0;
byte BitShift = (byte)(ShiftX ? 3 : 2);
int Max1 = 0x00100 >> BitShift;
int Max2 = 0x10000 >> BitShift;
for (int i = 0; i < Offsets.Count; i++)
{
Offset = Offsets[i];
if (i > 0) { Offset -= Offsets[i - 1]; if (Offset == 0) continue; }
Offset >>= BitShift;
if (Offset < Max1) length += 1;
else if (Offset < Max2) length += 2;
else length += 4;
}
return length;
}
public enum Value : byte
{
Invalid = 0b00000000,
@@ -86,6 +97,6 @@
}
public override string ToString() =>
$"ID: {ID}{(NotNull ? $"; Offsets Count: {Offsets.Count}" : "")}{(EOFC ? "; Has EOFC" : "")}";
$"Depth: {Depth}{(NotNull ? $"; Offsets Count: {Offsets.Count}" : "")}";
}
}
+26 -3
View File
@@ -6,11 +6,13 @@
public byte[] Data;
public Struct[] SubStructs;
public bool EOFC;
public ENRSList ENRS;
public POF POF;
public int Length => length(false);
public int LengthX => length( true);
public int ID => Header.ID;
public int Depth => Header.Depth;
public bool HasPOF => POF .NotNull;
public bool HasENRS => ENRS.NotNull;
@@ -20,6 +22,27 @@
public override string ToString() => $"{Header.ToString()}" +
$"{(HasSubStructs ? $"; SubStructs: {SubStructs.Length}" : "")}" +
$"{(HasENRS ? "; Has ENRS" : "")}{(HasPOF ? "; Has POF" : "")}{(EOFC ? "; Has EOFC" : "")}";
$"{(HasENRS ? "; Has ENRS" : "")}{(HasPOF ? "; Has POF" : "")}";
private int length(bool ShiftX = false)
{
int length = Data != null ? Data.Length : 0;
if (HasPOF ) length += 0x20 + (ShiftX ? POF.LengthX : POF.Length);
if (HasENRS) length += 0x20 + ENRS.Length;
if (HasSubStructs)
{
for (int i = 0; i < SubStructs.Length; i++)
length += (ShiftX ? SubStructs[i].LengthX : SubStructs[i].Length) + SubStructs[i].Header.Length;
length += 0x20;
}
return length;
}
public void Update(bool ShiftX = false)
{
Header.SectionSize = Data != null ? Data.Length : 0;
Header.DataSize = length(ShiftX);
}
}
}
+22
View File
@@ -0,0 +1,22 @@
namespace KKdBaseLib
{
public interface IKF<TKey, TVal>
{
TKey F { get; set; }
KFT0<TKey, TVal> ToT0();
KFT1<TKey, TVal> ToT1();
KFT2<TKey, TVal> ToT2();
KFT3<TKey, TVal> ToT3();
IKF<TKey, TVal> Check();
string ToString();
string ToString(bool Brackets);
}
public interface INull
{
bool IsNull { get; }
bool NotNull { get; }
}
}
+3 -17
View File
@@ -1,19 +1,5 @@
namespace KKdBaseLib
{
public interface IKF<TKey, TVal>
{
TKey F { get; set; }
KFT0<TKey, TVal> ToT0();
KFT1<TKey, TVal> ToT1();
KFT2<TKey, TVal> ToT2();
KFT3<TKey, TVal> ToT3();
IKF<TKey, TVal> Check();
string ToString();
string ToString(bool Brackets);
}
public struct KFT0<TKey, TVal> : IKF<TKey, TVal>
{
public TKey F { get; set; }
@@ -121,9 +107,9 @@
public KFT3<TKey, TVal> ToT3() => this;
public IKF<TKey, TVal> Check() =>
T1.Equals(default(TVal)) && T2.Equals(default(TVal)) ?
(V.Equals(default(TVal)) ? (KFT0<TKey, TVal>)this : (IKF<TKey, TVal>)this) :
T1.Equals(T2) ? (KFT2<TKey, TVal>)this : (IKF<TKey, TVal>)this;
T1.Equals(default(TVal)) && T2.Equals(default(TVal)) ? (V.Equals(default(TVal)) ?
(IKF<TKey, TVal>)(KFT0<TKey, TVal>)this : (KFT1<TKey, TVal>)this) :
T1.Equals(T2) ? (KFT2<TKey, TVal>)this : (IKF <TKey, TVal>)this;
public override string ToString() => ToString(true);
public string ToString(bool Brackets) =>
+2 -1
View File
@@ -47,7 +47,8 @@
<Compile Include="Extensions.cs" />
<Compile Include="Format.cs" />
<Compile Include="Half.cs" />
<Compile Include="IKF.cs" />
<Compile Include="Interfaces.cs" />
<Compile Include="KF.cs" />
<Compile Include="KKdList.cs" />
<Compile Include="MsgPack.cs" />
<Compile Include="Pointer.cs" />
+10 -9
View File
@@ -3,11 +3,11 @@ using System.Collections.Generic;
namespace KKdBaseLib
{
public struct KKdList<T> : System.IDisposable, IEnumerator, IEnumerable
public struct KKdList<T> : System.IDisposable, IEnumerator, IEnumerable, INull
{
public static KKdList<T> Null => new KKdList<T>();
public static KKdList<T> New => new KKdList<T>() { Capacity = 0 };
public static KKdList<T> NewReserve(int Capacity) => new KKdList<T>() { Capacity = Capacity };
public static KKdList<T> New => new KKdList<T>() { Count = 0, Capacity = 0 };
public static KKdList<T> NewReserve(int Capacity) => new KKdList<T>() { Count = 0, Capacity = Capacity };
private int index;
private T[] array;
@@ -30,16 +30,16 @@ namespace KKdBaseLib
object IEnumerator.Current => Current;
public T this[ int index]
{ get => array != null ? array[index] : default;
set { if (array != null) array[index] = value; } }
{ get => array != null && index > -1 ? array[index] : default;
set { if (array != null && index > -1) array[index] = value; } }
public T this[uint index]
{ get => array != null ? array[index] : default;
set { if (array != null) array[index] = value; } }
public bool MoveNext()
{ if (index == (Count - 1)) { index = 0; return false; }
else { index++ ; return true; } }
{ if (index == Count - 1) { index = 0; return false; }
else { index++ ; return true; } }
public IEnumerator GetEnumerator() => this;
@@ -71,8 +71,9 @@ namespace KKdBaseLib
if (IsNull) return;
if (IndexEnd - IndexStart < 1) return;
for (int i = IndexStart; i < Count; i++)
array[i] = array[i + IndexEnd - IndexStart];
if (IndexEnd - IndexStart != Count)
for (int i = IndexStart; i < Count; i++)
array[i] = array[i + IndexEnd - IndexStart];
Count -= IndexEnd - IndexStart;
}
+108 -85
View File
@@ -2,18 +2,21 @@
namespace KKdBaseLib
{
public struct MsgPack : IDisposable, IEquatable<MsgPack>
public struct MsgPack : IDisposable, IEquatable<MsgPack>, INull
{
public string Name;
public object Object;
public MsgPack[] Array => Object is MsgPack[] List ? List : null;
public KKdList<MsgPack> List => Object is KKdList<MsgPack> List ? List : default;
public MsgPack[] Array => Object is MsgPack[] Array ? Array : null;
public KKdList<MsgPack> List => Object is KKdList<MsgPack> List ? List : default;
public static MsgPack New => new MsgPack { Object = KKdList<MsgPack>.New };
public static MsgPack NewReserve(int Capacity) =>
new MsgPack { Object = KKdList<MsgPack>.NewReserve(Capacity) };
public bool IsNull => Array == null && List. IsNull;
public bool NotNull => Array != null || List.NotNull;
public MsgPack( string Name = null)
{ Object = KKdList<MsgPack>.New; this.Name = Name; }
@@ -28,6 +31,14 @@ namespace KKdBaseLib
public MsgPack this[int index]
{ get => Object is MsgPack[] Array ? Array[index] : default;
set { if (Object is MsgPack[] Array) { Array[index] = value; Object = Array; } } }
public MsgPack this[string key]
{ get => Object is KKdList<MsgPack> List ? List[ElementIndex(key)] : default; }
public MsgPack this[string key, bool array]
{ get { if (!array) return this[key];
if (Object is KKdList<MsgPack> List) { MsgPack MsgPack = List[ElementIndex(key)];
return MsgPack.Object is MsgPack[] ? MsgPack : default; } return default; } }
public MsgPack Add(MsgPack obj)
{ if (Object is KKdList<MsgPack> List) { List.Add(obj); Object = List; } return this; }
@@ -122,122 +133,122 @@ namespace KKdBaseLib
public bool? ReadNBoolean(string Name)
{
if (Element(Name, out MsgPack MsgPack))
if (MsgPack.Object is bool Boolean) return Boolean;
MsgPack MsgPack = this[Name];
if (MsgPack.Object is bool Boolean) return Boolean;
return null;
}
public sbyte? ReadNInt8(string Name)
{
if (Element(Name, out MsgPack MsgPack))
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return ( sbyte) UInt8 ;
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return ( sbyte) UInt8 ;
return null;
}
public byte? ReadNUInt8(string Name)
{
if (Element(Name, out MsgPack MsgPack))
if (MsgPack.Object is sbyte Int8 ) return ( byte) Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return ( byte) Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
return null;
}
public short? ReadNInt16(string Name)
{
if (Element(Name, out MsgPack MsgPack))
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return Int16;
else if (MsgPack.Object is ushort UInt16) return ( short) UInt16;
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return Int16;
else if (MsgPack.Object is ushort UInt16) return ( short) UInt16;
return null;
}
public ushort? ReadNUInt16(string Name)
{
if (Element(Name, out MsgPack MsgPack))
if (MsgPack.Object is sbyte Int8 ) return (ushort) Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return (ushort) Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return (ushort) Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return (ushort) Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
return null;
}
public int? ReadNInt32(string Name)
{
if (Element(Name, out MsgPack MsgPack))
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return Int32;
else if (MsgPack.Object is uint UInt32) return ( int) UInt32;
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return Int32;
else if (MsgPack.Object is uint UInt32) return ( int) UInt32;
return null;
}
public uint? ReadNUInt32(string Name)
{
if (Element(Name, out MsgPack MsgPack))
if (MsgPack.Object is sbyte Int8 ) return ( uint) Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return ( uint) Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return ( uint) Int32;
else if (MsgPack.Object is uint UInt32) return UInt32;
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return ( uint) Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return ( uint) Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return ( uint) Int32;
else if (MsgPack.Object is uint UInt32) return UInt32;
return null;
}
public long? ReadNInt64(string Name)
{
if (Element(Name, out MsgPack MsgPack))
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return Int32;
else if (MsgPack.Object is uint UInt32) return UInt32;
else if (MsgPack.Object is long Int64) return Int64;
else if (MsgPack.Object is ulong UInt64) return ( long) UInt64;
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return Int32;
else if (MsgPack.Object is uint UInt32) return UInt32;
else if (MsgPack.Object is long Int64) return Int64;
else if (MsgPack.Object is ulong UInt64) return ( long) UInt64;
return null;
}
public ulong? ReadNUInt64(string Name)
{
if (Element(Name, out MsgPack MsgPack))
if (MsgPack.Object is sbyte Int8 ) return ( ulong) Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return ( ulong) Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return ( ulong) Int32;
else if (MsgPack.Object is uint UInt32) return UInt32;
else if (MsgPack.Object is long Int64) return ( ulong) Int64;
else if (MsgPack.Object is ulong UInt64) return UInt64;
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return ( ulong) Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return ( ulong) Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return ( ulong) Int32;
else if (MsgPack.Object is uint UInt32) return UInt32;
else if (MsgPack.Object is long Int64) return ( ulong) Int64;
else if (MsgPack.Object is ulong UInt64) return UInt64;
return null;
}
public float? ReadNSingle(string Name)
{
if (Element(Name, out MsgPack MsgPack))
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return Int32;
else if (MsgPack.Object is uint UInt32) return UInt32;
else if (MsgPack.Object is long Int64) return Int64;
else if (MsgPack.Object is float Float32) return Float32;
else if (MsgPack.Object is double Float64) return ( float)Float64;
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return Int32;
else if (MsgPack.Object is uint UInt32) return UInt32;
else if (MsgPack.Object is long Int64) return Int64;
else if (MsgPack.Object is float Float32) return Float32;
else if (MsgPack.Object is double Float64) return ( float)Float64;
return null;
}
public double? ReadNDouble(string Name)
{
if (Element(Name, out MsgPack MsgPack))
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return Int32;
else if (MsgPack.Object is uint UInt32) return UInt32;
else if (MsgPack.Object is long Int64) return Int64;
else if (MsgPack.Object is float Float32) return Float32;
else if (MsgPack.Object is double Float64) return Float64;
MsgPack MsgPack = this[Name];
if (MsgPack.Object is sbyte Int8 ) return Int8 ;
else if (MsgPack.Object is byte UInt8 ) return UInt8 ;
else if (MsgPack.Object is short Int16) return Int16;
else if (MsgPack.Object is ushort UInt16) return UInt16;
else if (MsgPack.Object is int Int32) return Int32;
else if (MsgPack.Object is uint UInt32) return UInt32;
else if (MsgPack.Object is long Int64) return Int64;
else if (MsgPack.Object is float Float32) return Float32;
else if (MsgPack.Object is double Float64) return Float64;
return null;
}
public string ReadString(string Name)
{
if (Element(Name, out MsgPack MsgPack))
if (MsgPack.Object is string String) return String;
MsgPack MsgPack = this[Name];
if (MsgPack.Object is string String) return String;
return null;
}
@@ -326,10 +337,10 @@ namespace KKdBaseLib
public string ReadString()
{ if (Object is string String) return String; return null; }
public bool ElementArray(string Name, out MsgPack MsgPack) =>
Element(Name, out MsgPack) ? MsgPack.Array != null : false;
public bool ElementArray1(string Name, out MsgPack MsgPack) =>
Element1(Name, out MsgPack) ? MsgPack.Array != null : false;
public bool Element(string Name, out MsgPack MsgPack)
public bool Element1(string Name, out MsgPack MsgPack)
{
MsgPack = New;
if (List.IsNull) return false;
@@ -339,15 +350,27 @@ namespace KKdBaseLib
return false;
}
public bool ContainsKey(string Name)
public MsgPack Element(string Name)
{
if (List.IsNull) return false;
for (int i = 0; i < List.Count ; i++)
if (List[i].Name == Name) return true;
return false;
if (List.IsNull) return default;
for (int i = 0; i < List.Count; i++)
if (List[i].Name == Name) return List[i];
return default;
}
public bool ContainsKey(string Name) => ElementIndex(Name) > -1;
public int ElementIndex(string Name)
{
if (List.IsNull) return -1;
for (int i = 0; i < List.Count; i++)
if (List[i].Name == Name) return i;
return -1;
}
public struct Ext
{
public sbyte Type;
+2 -2
View File
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("437F63F1-8C23-429E-AB14-38B85C9EDB16")]
[assembly: AssemblyVersion("0.4.7.4")]
[assembly: AssemblyFileVersion("0.4.7.4")]
[assembly: AssemblyVersion("0.4.7.5")]
[assembly: AssemblyFileVersion("0.4.7.5")]
+11 -8
View File
@@ -1,6 +1,6 @@
namespace KKdBaseLib
{
public struct Vector2<T>
public struct Vector2<T> : INull
{
public T X;
public T Y;
@@ -8,12 +8,13 @@
public Vector2(T X, T Y)
{ this.X = X; this.Y = Y; }
public bool NotNull => X != null && Y != null;
public bool IsNull => X == null && Y == null;
public bool NotNull => X != null || Y != null;
public override string ToString() => "X: " + X + "; Y: " + Y;
}
public struct Vector3<T>
public struct Vector3<T> : INull
{
public T X;
public T Y;
@@ -21,13 +22,14 @@
public Vector3(T X, T Y, T Z)
{ this.X = X; this.Y = Y; this.Z = Z; }
public bool NotNull => X != null && Y != null && Z != null;
public bool IsNull => X == null && Y == null && Z == null;
public bool NotNull => X != null || Y != null || Z != null;
public override string ToString() => "X: " + X + "; Y: " + Y + "; Z: " + Z;
}
public struct Vector4<T>
public struct Vector4<T> : INull
{
public T X;
public T Y;
@@ -36,8 +38,9 @@
public Vector4(T X, T Y, T Z, T W)
{ this.X = X; this.Y = Y; this.Z = Z; this.W = W; }
public bool NotNull => X != null && Y != null && Z != null && W != null;
public bool IsNull => X == null && Y == null && Z == null && W == null;
public bool NotNull => X != null || Y != null || Z != null || W != null;
public override string ToString() => "X: " + X + "; Y: " + Y + "; Z: " + Z + "; W: " + W;
}
+7 -7
View File
@@ -37,17 +37,17 @@
public static double DistanceSquared(Vector3 left, Vector3 right) =>
(right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) *
(right.Y - left.Y) + (right.Z - left.Z) * (right.Z - left.Z);
public static double Dot (Vector3 left, Vector3 right) =>
(left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z);
public static double Dot(Vector3 left, Vector3 right) =>
left.X * right.X + left.Y * right.Y + left.Z * right.Z;
public static Vector3 Cross(Vector3 left, Vector3 right) =>
new Vector3 { X = (left.Y * right.Z) - (left.Z * right.Y),
Y = (left.Z * right.X) - (left.X * right.Z),
Z = (left.X * right.Y) - (left.Y * right.X), };
public static Vector3 Lerp (Vector3 a, Vector3 b, double blend) =>
new Vector3 { X = left.Y * right.Z - left.Z * right.Y,
Y = left.Z * right.X - left.X * right.Z,
Z = left.X * right.Y - left.Y * right.X, };
public static Vector3 Lerp(Vector3 a, Vector3 b, double blend) =>
new Vector3 { X = blend * (b.X - a.X) + a.X,
Y = blend * (b.Y - a.Y) + a.Y,
Z = blend * (b.Z - a.Z) + a.Z };
public static Vector3 Lerp (Vector3 a, Vector3 b, Vector3 blend) =>
public static Vector3 Lerp(Vector3 a, Vector3 b, Vector3 blend) =>
new Vector3 { X = blend.X * (b.X - a.X) + a.X,
Y = blend.Y * (b.Y - a.Y) + a.Y,
Z = blend.Z * (b.Z - a.Z) + a.Z };
+5 -5
View File
@@ -38,14 +38,14 @@
public static double DistanceSquared(Vector4 left, Vector4 right) =>
(right.X - left.X) * (right.X - left.X) + (right.Y - left.Y) * (right.Y - left.Y) +
(right.Z - left.Z) * (right.Z - left.Z) + (right.W - left.W) * (right.W - left.W);
public static double Dot (Vector4 left, Vector4 right) =>
(left.X * right.X) + (left.Y * right.Y) + (left.Z * right.Z) + (left.W * right.W);
public static Vector4 Lerp (Vector4 a, Vector4 b, double blend) =>
new Vector4 { X = blend * (b.X - a.X) + a.X,
public static double Dot(Vector4 left, Vector4 right) =>
left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W;
public static Vector4 Lerp(Vector4 a, Vector4 b, double blend) =>
new Vector4 { X = blend * (b.X - a.X) + a.X,
Y = blend * (b.Y - a.Y) + a.Y,
Z = blend * (b.Z - a.Z) + a.Z,
W = blend * (b.W - a.W) + a.W };
public static Vector4 Lerp (Vector4 a, Vector4 b, Vector4 blend) =>
public static Vector4 Lerp(Vector4 a, Vector4 b, Vector4 blend) =>
new Vector4 { X = blend.X * (b.X - a.X) + a.X,
Y = blend.Y * (b.Y - a.Y) + a.Y,
Z = blend.Z * (b.Z - a.Z) + a.Z,
+80 -74
View File
@@ -833,7 +833,7 @@ namespace KKdMainLib.A3DA
IO.Write(nameView + "parent=", Node.Parent);
IO.Write(Node.MT, nameView, A3DC, IsX, 0b01111);
}
IO.Write(nameView + "length=", ObjectHRC.Node.Length);
IO.Write(name + "node.length=", ObjectHRC.Node.Length);
}
if (ObjectHRC.Shadow != null)
@@ -1289,14 +1289,15 @@ namespace KKdMainLib.A3DA
public void MsgPackReader(string file, bool JSON)
{
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
if (!MsgPack.Element("A3D", out MsgPack A3D)) { MsgPack.Dispose(); return; }
MsgPackReader(A3D);
MsgPack A3D = MsgPack["A3D"];
if (A3D.NotNull) MsgPackReader(A3D);
MsgPack.Dispose();
}
public void MsgPackReader(MsgPack A3D)
{
MsgPack Temp = MsgPack.New;
if (A3D.Element("_", out Temp))
MsgPack temp = MsgPack.New, Temp = MsgPack.New;
if ((Temp = A3D["_"]).NotNull)
{
Data._ = new _
{
@@ -1307,7 +1308,7 @@ namespace KKdMainLib.A3DA
};
}
if (A3D.ElementArray("Ambient", out Temp))
if ((Temp = A3D["Ambient", true]).NotNull)
{
Data.Ambient = new Ambient[Temp.Array.Length];
@@ -1320,7 +1321,7 @@ namespace KKdMainLib.A3DA
};
}
if (A3D.Element("CameraAuxiliary", out Temp))
if ((Temp = A3D["CameraAuxiliary"]).NotNull)
Data.CameraAuxiliary = new CameraAuxiliary
{
AutoExposure = Temp.ReadKey("AutoExposure"),
@@ -1330,8 +1331,9 @@ namespace KKdMainLib.A3DA
Saturate = Temp.ReadKey("Saturate" ),
};
if (A3D.ElementArray("CameraRoot", out Temp))
if ((Temp = A3D["CameraRoot", true]).NotNull)
{
MsgPack ViewPoint;
Data.CameraRoot = new CameraRoot[Temp.Array.Length];
for (i = 0; i < Data.CameraRoot.Length; i++)
{
@@ -1340,8 +1342,8 @@ namespace KKdMainLib.A3DA
MT = Temp[i].ReadMT(),
Interest = Temp[i].ReadMT("Interest"),
};
if (!Temp[i].Element("ViewPoint", out MsgPack ViewPoint)) continue;
if ((ViewPoint = A3D["ViewPoint"]).IsNull) continue;
Data.CameraRoot[i].VP = new CameraRoot.ViewPoint
{
MT = ViewPoint.ReadMT(),
@@ -1356,14 +1358,14 @@ namespace KKdMainLib.A3DA
}
}
if (A3D.ElementArray("Chara", out Temp))
if ((Temp = A3D["Chara", true]).NotNull)
{
Data.Chara = new ModelTransform[Temp.Array.Length];
for (i = 0; i < Data.Chara.Length; i++)
Data.Chara[i] = Temp[i].ReadMT();
}
if (A3D.ElementArray("Curve", out Temp))
if ((Temp = A3D["Curve", true]).NotNull)
{
Data.Curve = new Curve[Temp.Array.Length];
for (i = 0; i < Data.Curve.Length; i++)
@@ -1374,14 +1376,14 @@ namespace KKdMainLib.A3DA
};
}
if (A3D.Element("DOF", out Temp))
if ((Temp = A3D["DOF"]).NotNull)
Data.DOF = new DOF
{
MT = Temp.ReadMT(),
Name = Temp.ReadString("Name"),
};
if (A3D.ElementArray("Event", out Temp))
if ((Temp = A3D["Event", true]).NotNull)
{
Data.Event = new Event[Temp.Array.Length];
for (i = 0; i < Data.Event.Length; i++)
@@ -1399,7 +1401,7 @@ namespace KKdMainLib.A3DA
};
}
if (A3D.ElementArray("Fog", out Temp))
if ((Temp = A3D["Fog", true]).NotNull)
{
Data.Fog = new Fog[Temp.Array.Length];
for (i = 0; i < Data.Fog.Length; i++)
@@ -1413,7 +1415,7 @@ namespace KKdMainLib.A3DA
};
}
if (A3D.ElementArray("Light", out Temp))
if ((Temp = A3D["Light", true]).NotNull)
{
Data.Light = new Light[Temp.Array.Length];
for (i = 0; i < Data.Light.Length; i++)
@@ -1431,7 +1433,7 @@ namespace KKdMainLib.A3DA
};
}
if (A3D.ElementArray("MaterialList", out Temp))
if ((Temp = A3D["MaterialList", true]).NotNull)
{
Data.MaterialList = new MaterialList[Temp.Array.Length];
for (i = 0; i < Data.MaterialList.Length; i++)
@@ -1445,7 +1447,7 @@ namespace KKdMainLib.A3DA
};
}
if (A3D.ElementArray("MObjectHRC", out Temp))
if ((Temp = A3D["MObjectHRC", true]).NotNull)
{
Data.MObjectHRC = new MObjectHRC[Temp.Array.Length];
for (i0 = 0; i0 < Data.MObjectHRC.Length; i0++)
@@ -1456,56 +1458,56 @@ namespace KKdMainLib.A3DA
Name = Temp[i0].ReadString("Name"),
};
if (Temp[i0].Element("JointOrient", out MsgPack JointOrient))
if ((temp = Temp[i0]["JointOrient"]).NotNull)
Data.MObjectHRC[i0].JointOrient = new Vector3<double?>
{
X = JointOrient.ReadDouble("X"),
Y = JointOrient.ReadDouble("Y"),
Z = JointOrient.ReadDouble("Z"),
X = temp.ReadDouble("X"),
Y = temp.ReadDouble("Y"),
Z = temp.ReadDouble("Z"),
};
if (Temp[i0].ElementArray("Instance", out MsgPack Instance))
if ((temp = Temp[i0]["Instance", true]).NotNull)
{
Data.MObjectHRC[i0].Instances = new MObjectHRC.Instance[Instance.Array.Length];
Data.MObjectHRC[i0].Instances = new MObjectHRC.Instance[temp.Array.Length];
for (i1 = 0; i1 < Data.MObjectHRC[i0].Instances.Length; i1++)
Data.MObjectHRC[i0].Instances[i1] = new MObjectHRC.Instance
{
MT = Instance[i1].ReadMT(),
Name = Instance[i1].ReadString( "Name"),
Shadow = Instance[i1].ReadNInt32( "Shadow"),
UIDName = Instance[i1].ReadString("UIDName"),
MT = temp[i1].ReadMT(),
Name = temp[i1].ReadString( "Name"),
Shadow = temp[i1].ReadNInt32( "Shadow"),
UIDName = temp[i1].ReadString("UIDName"),
};
}
if (Temp[i0].ElementArray("Node", out MsgPack Node))
if ((temp = Temp[i0]["Node", true]).NotNull)
{
Data.MObjectHRC[i0].Node = new Node[Temp.Array.Length];
Data.MObjectHRC[i0].Node = new Node[temp.Array.Length];
for (i1 = 0; i1 < Data.MObjectHRC[i0].Node.Length; i1++)
Data.MObjectHRC[i0].Node[i1] = new Node
{
MT = Node[i1].ReadMT(),
Name = Node[i1].ReadString( "Name"),
Parent = Node[i1].ReadNInt32("Parent"),
MT = temp[i1].ReadMT(),
Name = temp[i1].ReadString( "Name"),
Parent = temp[i1].ReadNInt32("Parent"),
};
}
}
}
if (A3D.ElementArray("MObjectHRCList", out Temp))
if ((Temp = A3D["MObjectHRCList", true]).NotNull)
{
Data.MObjectHRCList = new string[Temp.Array.Length];
for (i = 0; i < Data.MObjectHRCList.Length; i++)
Data.MObjectHRCList[i] = Temp[i].ReadString();
}
if (A3D.ElementArray("Motion", out Temp))
if ((Temp = A3D["Motion", true]).NotNull)
{
Data.Motion = new string[Temp.Array.Length];
for (i = 0; i < Data.Motion.Length; i++)
Data.Motion[i] = Temp[i].ReadString();
}
if (A3D.ElementArray("Object", out Temp))
if ((Temp = A3D["Object", true]).NotNull)
{
Data.Object = new Object[Temp.Array.Length];
for (i0 = 0; i0 < Data.Object.Length; i0++)
@@ -1520,37 +1522,37 @@ namespace KKdMainLib.A3DA
UIDName = Temp[i0].ReadString( "UIDName"),
};
if (Temp[i0].ElementArray("TexturePattern", out MsgPack TexPat))
if ((temp = Temp[i0]["TexturePattern", true]).NotNull)
{
Data.Object[i0].TexPat = new Object.TexturePattern[TexPat.Array.Length];
Data.Object[i0].TexPat = new Object.TexturePattern[temp.Array.Length];
for (i1 = 0; i1 < Data.Object[i0].TexPat.Length; i1++)
Data.Object[i0].TexPat[i1] = new Object.TexturePattern
{
Name = TexPat[i1].ReadString("Name" ),
Pat = TexPat[i1].ReadString("Pat" ),
PatOffset = TexPat[i1].ReadNInt32("PatOffset"),
Name = temp[i1].ReadString("Name" ),
Pat = temp[i1].ReadString("Pat" ),
PatOffset = temp[i1].ReadNInt32("PatOffset"),
};
}
if (Temp[i0].ElementArray("TextureTransform", out MsgPack TexTrans))
if ((temp = Temp[i0]["TextureTransform", true]).NotNull)
{
Data.Object[i0].TexTrans = new Object.TextureTransform[TexTrans.Array.Length];
Data.Object[i0].TexTrans = new Object.TextureTransform[temp.Array.Length];
for (i1 = 0; i1 < Data.Object[i0].TexTrans.Length; i1++)
Data.Object[i0].TexTrans[i1] = new Object.TextureTransform
{
Name = TexTrans[i1].ReadString("Name"),
Coverage = TexTrans[i1].ReadKeyUV("Coverage" ),
Offset = TexTrans[i1].ReadKeyUV("Offset" ),
Repeat = TexTrans[i1].ReadKeyUV("Repeat" ),
Rotate = TexTrans[i1].ReadKey ( "Rotate" ),
RotateFrame = TexTrans[i1].ReadKey ( "RotateFrame"),
TranslateFrame = TexTrans[i1].ReadKeyUV("TranslateFrame"),
Name = temp[i1].ReadString("Name"),
Coverage = temp[i1].ReadKeyUV("Coverage" ),
Offset = temp[i1].ReadKeyUV("Offset" ),
Repeat = temp[i1].ReadKeyUV("Repeat" ),
Rotate = temp[i1].ReadKey ( "Rotate" ),
RotateFrame = temp[i1].ReadKey ( "RotateFrame"),
TranslateFrame = temp[i1].ReadKeyUV("TranslateFrame"),
};
}
}
}
if (A3D.ElementArray("ObjectHRC", out Temp))
if ((Temp = A3D["ObjectHRC", true]).NotNull)
{
Data.ObjectHRC = new ObjectHRC[Temp.Array.Length];
for (i0 = 0; i0 < Data.ObjectHRC.Length; i0++)
@@ -1562,43 +1564,43 @@ namespace KKdMainLib.A3DA
UIDName = Temp[i0].ReadString ("UIDName"),
};
if (Temp[i0].Element("JointOrient", out MsgPack JointOrient))
if ((temp = Temp[i0]["JointOrient"]).NotNull)
Data.ObjectHRC[i0].JointOrient = new Vector3<double?>
{
X = JointOrient.ReadDouble("X"),
Y = JointOrient.ReadDouble("Y"),
Z = JointOrient.ReadDouble("Z"),
X = temp.ReadDouble("X"),
Y = temp.ReadDouble("Y"),
Z = temp.ReadDouble("Z"),
};
if (Temp[i0].ElementArray("Node", out MsgPack Node))
if ((temp = Temp[i0]["Node", true]).NotNull)
{
Data.ObjectHRC[i0].Node = new Node[Node.Array.Length];
Data.ObjectHRC[i0].Node = new Node[temp.Array.Length];
for (i1 = 0; i1 < Data.ObjectHRC[i0].Node.Length; i1++)
Data.ObjectHRC[i0].Node[i1] = new Node
{
MT = Node[i1].ReadMT(),
Name = Node[i1].ReadString( "Name"),
Parent = Node[i1].ReadInt32 ("Parent"),
MT = temp[i1].ReadMT(),
Name = temp[i1].ReadString( "Name"),
Parent = temp[i1].ReadInt32 ("Parent"),
};
}
}
}
if (A3D.ElementArray("ObjectHRCList", out Temp))
if ((Temp = A3D["ObjectHRCList", true]).NotNull)
{
Data.ObjectHRCList = new string[Temp.Array.Length];
for (i = 0; i < Data.ObjectHRCList.Length; i++)
Data.ObjectHRCList[i] = Temp[i].ReadString();
}
if (A3D.ElementArray("ObjectList", out Temp))
if ((Temp = A3D["ObjectList", true]).NotNull)
{
Data.ObjectList = new string[Temp.Array.Length];
for (i = 0; i < Data.ObjectList.Length; i++)
Data.ObjectList[i] = Temp[i].ReadString();
}
if (A3D.Element("PlayControl", out Temp))
if ((Temp = A3D["PlayControl"]).NotNull)
Data.PlayControl = new PlayControl
{
Begin = Temp.ReadNDouble("Begin" ),
@@ -1608,14 +1610,14 @@ namespace KKdMainLib.A3DA
Size = Temp.ReadNDouble("Size" ),
};
if (A3D.ElementArray("Point", out Temp))
if ((Temp = A3D["Point", true]).NotNull)
{
Data.Point = new ModelTransform[Temp.Array.Length];
for (i = 0; i < Data.Point.Length; i++)
Data.Point[i] = Temp[i].ReadMT();
}
if (A3D.Element("PostProcess", out Temp))
if ((Temp = A3D["PostProcess"]).NotNull)
Data.PostProcess = new PostProcess
{
Ambient = Temp.ReadRGBAKey("Ambient" ),
@@ -1625,6 +1627,9 @@ namespace KKdMainLib.A3DA
LensShaft = Temp.ReadKey ("LensShaft"),
Specular = Temp.ReadRGBAKey("Specular" ),
};
temp.Dispose();
Temp.Dispose();
}
public void MsgPackWriter(string file, bool JSON) =>
@@ -2081,7 +2086,7 @@ namespace KKdMainLib.A3DA
{
SOi = SO[i];
KF = Key.Keys[SOi].Check();
IO.Write(Temp + "key" + d + SOi + d + "data=", KF.Round(7).ToString());
IO.Write(Temp + "key" + d + SOi + d + "data=", KF.ToString());
int Type = 0;
if (KF is KFT0<float, float>) Type = 0;
else if (KF is KFT1<float, float>) Type = 1;
@@ -2220,32 +2225,32 @@ namespace KKdMainLib.A3DA
}
public static ModelTransform ReadMT(this MsgPack k, string name) =>
k.Element(name, out MsgPack Name) ? Name.ReadMT() : default;
k[name].ReadMT();
public static ModelTransform ReadMT(this MsgPack k) =>
new ModelTransform { Rot = k.ReadVec3("Rot" ), Scale = k.ReadVec3("Scale" ),
Trans = k.ReadVec3("Trans"), Visibility = k.ReadKey ("Visibility") };
public static Vector4<Key> ReadRGBAKey(this MsgPack k, string name) =>
k.Element(name, out MsgPack Name) ? Name.ReadRGBAKey() : default;
k[name].ReadRGBAKey();
public static Vector4<Key> ReadRGBAKey(this MsgPack k) =>
new Vector4<Key> { X = k.ReadKey("R"), Y = k.ReadKey("G"), Z = k.ReadKey("B"), W = k.ReadKey("A") };
public static Vector3<Key> ReadVec3(this MsgPack k, string name) =>
k.Element(name, out MsgPack Name) ? Name.ReadVec3() : default;
k[name].ReadVec3();
public static Vector3<Key> ReadVec3(this MsgPack k) =>
new Vector3<Key> { X = k.ReadKey("X"), Y = k.ReadKey("Y"), Z = k.ReadKey("Z") };
public static Vector2<Key> ReadKeyUV(this MsgPack k, string name) =>
k.Element(name, out MsgPack Name) ? Name.ReadKeyUV() : default;
k[name].ReadKeyUV();
public static Vector2<Key> ReadKeyUV(this MsgPack k) =>
new Vector2<Key> { X = k.ReadKey("U"), Y = k.ReadKey("V") };
public static Key ReadKey(this MsgPack k, string name) =>
k.Element(name, out MsgPack Name) ? Name.ReadKey() : default;
k[name].ReadKey();
public static Key ReadKey(this MsgPack k)
{
@@ -2259,7 +2264,8 @@ namespace KKdMainLib.A3DA
else if (Key.Type < Key.Interpolation.Lerp) return Key;
if (k.ReadBoolean("RawData")) Key.RawData = new Key.RawD() { KeyType = -1, ValueType = "float" };
if (!k.ElementArray("Trans", out MsgPack Trans)) return Key;
MsgPack Trans;
if ((Trans = k["Trans", true]).IsNull) return Key;
Key.Length = Trans.Array.Length;
Key.Keys = new KFT3<float, float>[Key.Length];
+110 -93
View File
@@ -349,23 +349,21 @@ namespace KKdMainLib.Aet
AET = new AetHeader();
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
if (!MsgPack.ElementArray("Aet", out MsgPack Aet)) { MsgPack.Dispose(); return; }
if (Aet.Array != null)
if (Aet.Array.Length > 0)
MsgPack Aet;
if ((Aet = MsgPack["Aet", true]).NotNull)
if (Aet.Array != null && Aet.Array.Length > 0)
{
AET.Data = new Pointer<AetData>[Aet.Array.Length];
for (int i = 0; i < AET.Data.Length; i++)
MsgPackReader(Aet.Array[i], ref AET.Data[i]);
}
Aet.Dispose();
MsgPack.Dispose();
}
public void MsgPackWriter(string file, bool JSON)
{
if (this.AET.Data == null) return;
if (this.AET.Data.Length == 0) return;
if (this.AET.Data == null || this.AET.Data.Length == 0) return;
MsgPack AET = new MsgPack(this.AET.Data.Length, "Aet");
for (int i = 0; i < this.AET.Data.Length; i++) AET[i] = MsgPackWriter(ref this.AET.Data[i]);
@@ -387,26 +385,25 @@ namespace KKdMainLib.Aet
Aet.Width = AET.ReadInt32("Width" );
Aet.Height = AET.ReadInt32("Height" );
if (AET.Element("Unknown", out Temp))
if ((Temp = AET["Unknown"]).NotNull)
Aet.Unknown.Count = Temp.ReadInt32();
if (AET.Element("Position", out Temp))
if ((Temp = AET["Position"]).NotNull)
{
Aet.Position.Offset = 1;
Aet.Position.Value.X.ReadMP(Temp, "X");
Aet.Position.Value.Y.ReadMP(Temp, "Y");
}
if (AET.ElementArray("SpriteEntries", out Temp))
if ((Temp = AET["SpriteEntries", true]).NotNull)
{
Aet.SpriteEntries.Count = Temp.Array.Length;
for (i = 0; i < Aet.SpriteEntries.Count; i++)
Aet.SpriteEntries.Entries[i].ReadMP(Temp[i]);
}
else return;
if (AET.ElementArray("Layers", out Temp))
if ((Temp = AET["Layers", true]).NotNull)
{
Aet.Layers.Count = Temp.Array.Length + 1;
for (i = 0; i < Aet.Layers.Count - 1; i++)
@@ -415,13 +412,13 @@ namespace KKdMainLib.Aet
else Aet.Layers.Count = 1;
i = Aet.Layers.Count - 1;
if (AET.ElementArray("RootLayer", out Temp))
if ((Temp = AET["RootLayer", true]).NotNull)
{
Aet.Layers.Entries[i].Count = Temp.Array.Length;
for (i0 = 0; i0 < Aet.Layers[i].Count; i0++)
Aet.Layers.Entries[i].Objects[i0].ReadMP(Temp[i0]);
}
else if (AET.Element("RootLayer", out Temp))
else if ((Temp = AET["RootLayer"]).NotNull)
{
Aet.Layers.Entries[i].Count = 1;
Aet.Layers.Entries[i].Objects[0].ReadMP(Temp);
@@ -429,6 +426,7 @@ namespace KKdMainLib.Aet
else return;
AetData.Offset = 0;
Temp.Dispose();
}
public MsgPack MsgPackWriter(ref Pointer<AetData> AetData)
@@ -475,19 +473,21 @@ namespace KKdMainLib.Aet
{
public static MsgPack ReadMP(this MsgPack msg, ref CountPointer<float> val, string Name)
{
MsgPack Temp;
val.Offset = 0;
val.Entries = null;
if (msg.ContainsKey(Name))
if ((Temp = msg[Name, true]).NotNull)
{
val.Count = 1;
val[0] = msg.ReadSingle(Name);
val[0] = Temp.ReadSingle();
}
else if(msg.ElementArray(Name, out MsgPack Temp))
else if ((Temp = msg[Name]).NotNull)
{
val.Count = Temp.Array.Length;
for (int i = 0; i < val.Count; i++)
val[i] = Temp[i].ReadSingle();
}
Temp.Dispose();
return msg;
}
@@ -873,17 +873,19 @@ namespace KKdMainLib.Aet
public static void ReadMP(this CountPointer<Marker> mark, MsgPack msg)
{
if (msg.Element("Marker", out MsgPack Marker))
MsgPack Temp;
if ((Temp = msg["Marker"]).NotNull)
{
mark.Count = 1;
mark.Entries[0].ReadMP(Marker);
mark.Entries[0].ReadMP(Temp);
}
else if (msg.ElementArray("Markers", out MsgPack Markers))
else if ((Temp = msg["Markers", true]).NotNull)
{
mark.Count = Markers.Array.Length;
mark.Count = Temp.Array.Length;
for (int i = 0; i < mark.Count; i++)
mark.Entries[i].ReadMP(Markers[i]);
mark.Entries[i].ReadMP(Temp[i]);
}
Temp.Dispose();
}
public static void WritePointerString(this Stream IO,
@@ -928,17 +930,19 @@ namespace KKdMainLib.Aet
public void ReadMP(MsgPack msg)
{
if (msg.Element("Object", out MsgPack Object))
MsgPack Temp;
if ((Temp = msg["Object"]).NotNull)
{
Count = 1;
Objects[0].ReadMP(Object);
Objects[0].ReadMP(Temp);
}
else if (msg.ElementArray("Objects", out MsgPack Objects))
else if ((Temp = msg["Objects", true]).NotNull)
{
Count = Objects.Array.Length;
Count = Temp.Array.Length;
for (int i0 = 0; i0 < Count; i0++)
this.Objects[i0].ReadMP(Objects[i0]);
Objects[i0].ReadMP(Temp[i0]);
}
Temp.Dispose();
}
public MsgPack WriteMP(int Id, ref AetData Aet)
@@ -990,10 +994,13 @@ namespace KKdMainLib.Aet
Unk0 = msg.ReadUInt8("Unk0");
Unk1 = msg.ReadUInt8("Unk1");
Unk2 = msg.ReadUInt8("Unk2");
if (msg.Element("Pic", out MsgPack Pic)) { Type = ObjType.Pic; this.Pic.Value.ReadMP(Pic); }
else if (msg.Element("Aif", out MsgPack Aif)) { Type = ObjType.Aif; this.Aif.Value.ReadMP(Aif); }
else if (msg.Element("Eff", out MsgPack Eff)) { Type = ObjType.Eff; this.Eff.Value.ReadMP(Eff); }
MsgPack Temp;
if ((Temp = msg["Pic"]).NotNull) { Type = ObjType.Pic; Pic.Value.ReadMP(Temp); }
else if ((Temp = msg["Aif"]).NotNull) { Type = ObjType.Aif; Aif.Value.ReadMP(Temp); }
else if ((Temp = msg["Eff"]).NotNull) { Type = ObjType.Eff; Eff.Value.ReadMP(Temp); }
else Type = ObjType.Nop;
Temp.Dispose();
}
public MsgPack WriteMP(ref AetData Aet, string name = null)
@@ -1033,18 +1040,20 @@ namespace KKdMainLib.Aet
if (ParentObjectID != null)
this.ParentObjectID = ParentObjectID.Value;
if (msg.Element("Marker", out MsgPack Marker))
MsgPack Temp;
if ((Temp = msg["Marker"]).NotNull)
{
this.Marker.Count = 1;
this.Marker.Entries[0].ReadMP(Marker);
Marker.Count = 1;
Marker.Entries[0].ReadMP(Temp);
}
else if (msg.ElementArray("Markers", out MsgPack Markers))
if ((Temp = msg["Markers", true]).NotNull)
{
this.Marker.Count = Markers.Array.Length;
for (int i = 0; i < Markers.Array.Length; i++)
this.Marker.Entries[i].ReadMP(Markers[i]);
Marker.Count = Temp.Array.Length;
for (int i = 0; i < Marker.Count; i++)
Marker.Entries[i].ReadMP(Temp[i]);
}
else this.Marker.Entries = null;
else Marker.Entries = null;
Temp.Dispose();
Data.Value.ReadMP(msg);
@@ -1117,18 +1126,20 @@ namespace KKdMainLib.Aet
if (ParentObjectID != null)
this.ParentObjectID = ParentObjectID.Value;
if (msg.Element("Marker", out MsgPack Marker))
MsgPack Temp;
if ((Temp = msg["Marker"]).NotNull)
{
this.Marker.Count = 1;
this.Marker.Entries[0].ReadMP(Marker);
Marker.Count = 1;
Marker.Entries[0].ReadMP(Temp);
}
else if (msg.ElementArray("Markers", out MsgPack Markers))
else if ((Temp = msg["Markers", true]).NotNull)
{
this.Marker.Count = Markers.Array.Length;
for (int i = 0; i < Markers.Array.Length; i++)
this.Marker.Entries[i].ReadMP(Markers[i]);
Marker.Count = Temp.Array.Length;
for (int i = 0; i < Marker.Count; i++)
Marker.Entries[i].ReadMP(Temp[i]);
}
else this.Marker.Entries = null;
else Marker.Entries = null;
Temp.Dispose();
Data.Value.ReadMP(msg);
}
@@ -1139,11 +1150,10 @@ namespace KKdMainLib.Aet
for (int i = 0; i < Aet.Layers.Count; i++)
if (Aet.Layers[i].Pointer == LayerID)
{ Eff.Add("LayerID", i); break; }
if (ParentObjectID > 0)
for (int i = 0; i < Aet.Layers.Count; i++)
for (int i1 = 0; i1 < Aet.Layers[i].Count; i1++)
if (Aet.Layers[i][i1].Offset == ParentObjectID)
{ Eff.Add("ParentObjectID", Aet.Layers[i][i1].ID); break; }
for (int i = 0; ParentObjectID > 0 && i < Aet.Layers.Count; i++)
for (int i1 = 0; i1 < Aet.Layers[i].Count; i1++)
if (Aet.Layers[i][i1].Offset == ParentObjectID)
{ Eff.Add("ParentObjectID", Aet.Layers[i][i1].ID); break; }
if (Marker.Count == 1)
Eff.Add(Marker[0].WriteMP("Marker"));
@@ -1232,25 +1242,29 @@ namespace KKdMainLib.Aet
public void ReadMP(MsgPack msg)
{
if (!msg.Element("AnimationData", out MsgPack Data)) return;
MsgPack Data;
if ((Data = msg["AnimationData"]).NotNull)
{
System.Enum.TryParse(Data.ReadString("BlendMode"), out Mode);
Unk0 = Data.ReadUInt8 ("Unk0");
UseTextureMask = Data.ReadBoolean("UseTextureMask");
Unk1 = Data.ReadUInt8 ("Unk1");
OriginX.ReadMP(Data, "OriginX");
OriginY.ReadMP(Data, "OriginY");
PositionX.ReadMP(Data, "PositionX");
PositionY.ReadMP(Data, "PositionY");
Rotation .ReadMP(Data, "Rotation" );
ScaleX.ReadMP(Data, "ScaleX");
ScaleY.ReadMP(Data, "ScaleY");
Opacity .ReadMP(Data, "Opacity" );
System.Enum.TryParse(Data.ReadString("BlendMode"), out Mode);
Unk0 = Data.ReadUInt8 ("Unk0");
UseTextureMask = Data.ReadBoolean("UseTextureMask");
Unk1 = Data.ReadUInt8 ("Unk1");
OriginX.ReadMP(Data, "OriginX");
OriginY.ReadMP(Data, "OriginY");
PositionX.ReadMP(Data, "PositionX");
PositionY.ReadMP(Data, "PositionY");
Rotation .ReadMP(Data, "Rotation" );
ScaleX.ReadMP(Data, "ScaleX");
ScaleY.ReadMP(Data, "ScaleY");
Opacity .ReadMP(Data, "Opacity" );
this._3D.Offset = -1;
if (Data.Element("3D", out MsgPack _3D))
{ this._3D.Offset = 0; this._3D.Value.ReadMP(_3D); }
MsgPack Temp;
_3D.Offset = -1;
if ((Temp = Data["3D"]).NotNull) { _3D.Offset = 0; _3D.Value.ReadMP(Temp); }
Temp.Dispose();
}
Data.Dispose();
}
public MsgPack WriteMP()
@@ -1267,8 +1281,7 @@ namespace KKdMainLib.Aet
AnimationData.Add( ScaleX.WriteMP( "ScaleX"));
AnimationData.Add( ScaleY.WriteMP( "ScaleY"));
AnimationData.Add(Opacity .WriteMP("Opacity" ));
if (_3D.Offset > 0)
AnimationData.Add(_3D.Value.WriteMP());
if (_3D.Offset > 0) AnimationData.Add(_3D.Value.WriteMP());
return AnimationData;
}
@@ -1293,21 +1306,23 @@ namespace KKdMainLib.Aet
public void ReadMP(MsgPack msg, string name)
{
MsgPack Temp;
float? Value = msg.ReadNSingle(name);
if (Value != null) { Count = 1; this.Value = Value.Value; return; }
if (!msg.ElementArray(name, out MsgPack Temp)) return;
Count = Temp.Array.Length;
if (Count == 0) return;
ArrValue = new float[Count];
KeyFrame = new float[Count];
Interpolation = new float[Count];
for (int i = 0; i < Count; i++)
if (Value != null) { Count = 1; this.Value = Value.Value; }
if ((Temp = msg[name, true]).NotNull && Temp.Array.Length > 1)
{
KeyFrame [i] = Temp[i].ReadSingle("KeyFrame" );
ArrValue [i] = Temp[i].ReadSingle("Value" );
Interpolation[i] = Temp[i].ReadSingle("Interpolation");
Count = Temp.Array.Length;
ArrValue = new float[Count];
KeyFrame = new float[Count];
Interpolation = new float[Count];
for (int i = 0; i < Count; i++)
{
KeyFrame [i] = Temp[i].ReadSingle("KeyFrame" );
ArrValue [i] = Temp[i].ReadSingle("Value" );
Interpolation[i] = Temp[i].ReadSingle("Interpolation");
}
}
Temp.Dispose();
}
public MsgPack WriteMP(string name)
@@ -1337,19 +1352,21 @@ namespace KKdMainLib.Aet
Height = msg.ReadInt16 ("Height" );
Frames = msg.ReadSingle("Frames" );
if (msg.Element("Sprite", out MsgPack Sprite))
MsgPack Temp;
if ((Temp = msg["Sprite"]).NotNull)
{
Sprites.Count = 1;
Sprites[0] = new Sprite() { Name = new Pointer<string>()
{ Value = Sprite.ReadString("Name") }, ID = Sprite.ReadInt32("ID") };
{ Value = Temp.ReadString("Name") }, ID = Temp.ReadInt32("ID") };
}
else if (msg.ElementArray("Sprites", out MsgPack Sprites))
else if ((Temp = msg["Sprites", true]).NotNull)
{
this.Sprites.Count = Sprites.Array.Length;
for (int i0 = 0; i0 < this.Sprites.Count; i0++)
this.Sprites[i0] = new Sprite() { Name = new Pointer<string>()
{ Value = Sprites[i0].ReadString("Name") }, ID = Sprites[i0].ReadInt32("ID") };
Sprites.Count = Temp.Array.Length;
for (int i0 = 0; i0 < Sprites.Count; i0++)
Sprites[i0] = new Sprite() { Name = new Pointer<string>()
{ Value = Temp[i0].ReadString("Name") }, ID = Temp[i0].ReadInt32("ID") };
}
Temp.Dispose();
}
public MsgPack WriteMP(int Id)
+11 -7
View File
@@ -192,12 +192,14 @@ namespace KKdMainLib.DB
{
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
if (MsgPack.ElementArray("AetDB", out MsgPack AetDB))
MsgPack Temp = default;
if ((Temp = MsgPack["AetDB", true]).NotNull)
{
AetSets = new AetSet[AetDB.Array.Length];
AetSets = new AetSet[Temp.Array.Length];
for (int i = 0; i < AetSets.Length; i++)
AetSets[i].ReadMsgPack(AetDB[i]);
AetSets[i].ReadMsgPack(Temp[i]);
}
Temp.Dispose();
MsgPack.Dispose();
}
@@ -246,12 +248,14 @@ namespace KKdMainLib.DB
NewId = msg.ReadBoolean("NewId" );
SpriteSetId = msg.ReadNUInt16("SpriteSetId");
if (msg.ElementArray("Aets", out MsgPack Aets))
MsgPack Temp;
if ((Temp = msg["Aets", true]).NotNull)
{
this.Aets = new AET[Aets.Array.Length];
for (int i0 = 0; i0 < this.Aets.Length; i0++)
this.Aets[i0].ReadMsgPack(Aets[i0]);
Aets = new AET[Temp.Array.Length];
for (int i0 = 0; i0 < Aets.Length; i0++)
Aets[i0].ReadMsgPack(Temp[i0]);
}
Temp.Dispose();
}
public MsgPack WriteMsgPack()
+7 -3
View File
@@ -96,16 +96,18 @@ namespace KKdMainLib.DB
{
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
if (MsgPack.Element("AuthDB", out MsgPack AuthDB))
MsgPack AuthDB;
if ((AuthDB = MsgPack["AuthDB"]).NotNull)
{
if (AuthDB.ElementArray("Category", out MsgPack Temp))
MsgPack Temp;
if ((Temp = MsgPack["Category", true]).NotNull)
{
Category = new string[Temp.Array.Length];
for (int i = 0; i < Category.Length; i++)
Category[i] = Temp[i].ReadString();
}
if (AuthDB.ElementArray("UID", out Temp))
if ((Temp = MsgPack["UID", true]).NotNull)
{
_UID = new UID[Temp.Array.Length];
for (int i = 0; i < _UID.Length; i++)
@@ -116,7 +118,9 @@ namespace KKdMainLib.DB
_UID[i].Value = Temp[i].ReadString("Value" );
}
}
Temp.Dispose();
}
AuthDB.Dispose();
MsgPack.Dispose();
}
+13 -9
View File
@@ -231,12 +231,14 @@ namespace KKdMainLib.DB
{
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
if (MsgPack.ElementArray("SprDB", out MsgPack SprDB))
MsgPack SprDB;
if ((SprDB = MsgPack["SprDB", true]).NotNull)
{
SpriteSets = new SpriteSet[SprDB.Array.Length];
for (int i = 0; i < SpriteSets.Length; i++)
SpriteSets[i].ReadMsgPack(SprDB[i]);
}
SprDB.Dispose();
MsgPack.Dispose();
}
@@ -282,19 +284,21 @@ namespace KKdMainLib.DB
Name = msg.ReadString ("Name" );
NewId = msg.ReadBoolean("NewId" );
if (msg.ElementArray( "Sprites", out MsgPack Sprites))
MsgPack Temp;
if ((Temp = msg["Sprites", true]).NotNull)
{
this.Sprites = new SpriteTexture[Sprites.Array.Length];
for (int i0 = 0; i0 < this.Sprites.Length; i0++)
this.Sprites[i0].ReadMsgPack(Sprites[i0]);
Sprites = new SpriteTexture[Temp.Array.Length];
for (int i0 = 0; i0 < Sprites.Length; i0++)
Sprites[i0].ReadMsgPack(Temp[i0]);
}
if (msg.ElementArray("Textures", out MsgPack Textures))
if ((Temp = msg["Textures", true]).NotNull)
{
this.Textures = new SpriteTexture[Textures.Array.Length];
for (int i0 = 0; i0 < this.Textures.Length; i0++)
this.Textures[i0].ReadMsgPack(Textures[i0]);
Textures = new SpriteTexture[Temp.Array.Length];
for (int i0 = 0; i0 < Textures.Length; i0++)
Textures[i0].ReadMsgPack(Temp[i0]);
}
Temp.Dispose();
}
public MsgPack WriteMsgPack()
+24 -19
View File
@@ -35,7 +35,7 @@ namespace KKdMainLib
IO.Seek(DEXOffset, 0);
for (int i0 = 0; i0 < Dex.Length; i0++)
Dex[i0] = new EXP { Main = new List<EXPElement>(), Eyes = new List<EXPElement>() };
Dex[i0] = new EXP { Main = KKdList<EXPElement>.New, Eyes = KKdList<EXPElement>.New };
for (int i0 = 0; i0 < Dex.Length; i0++)
{
@@ -176,26 +176,31 @@ namespace KKdMainLib
Header = new Header();
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
if (!MsgPack.ElementArray("Dex", out MsgPack Dex)) return 0;
this.Dex = new EXP[Dex.Array.Length];
for (i0 = 0; i0 < this.Dex.Length; i0++)
MsgPack Dex;
if ((Dex = MsgPack["Dex", true]).NotNull)
{
this.Dex[i0] = new EXP { Name = Dex[i0].ReadString("Name") };
this.Dex = new EXP[Dex.Array.Length];
for (i0 = 0; i0 < this.Dex.Length; i0++)
{
this.Dex[i0] = new EXP { Name = Dex[i0].ReadString("Name") };
if (Dex[i0].ElementArray("Main", out MsgPack Main))
{
this.Dex[i0].Main = new List<EXPElement>();
for (i1 = 0; i1 < Main.Array.Length; i1++)
this.Dex[i0].Main.Add(EXPElement.Read(Main[i1]));
}
if (Dex[i0].ElementArray("Eyes", out MsgPack Eyes))
{
this.Dex[i0].Eyes = new List<EXPElement>();
for (i1 = 0; i1 < Eyes.Array.Length; i1++)
this.Dex[i0].Eyes.Add(EXPElement.Read(Eyes[i1]));
MsgPack Temp;
if ((Temp = MsgPack["Main", true]).NotNull)
{
this.Dex[i0].Main = KKdList<EXPElement>.New;
for (i1 = 0; i1 < this.Dex[i0].Main.Count; i1++)
this.Dex[i0].Main.Add(EXPElement.Read(Temp[i1]));
}
if ((Temp = MsgPack["Eyes", true]).NotNull)
{
this.Dex[i0].Eyes = KKdList<EXPElement>.New;
for (i1 = 0; i1 < this.Dex[i0].Main.Count; i1++)
this.Dex[i0].Eyes.Add(EXPElement.Read(Temp[i1]));
}
Temp.Dispose();
}
}
Dex.Dispose();
MsgPack.Dispose();
return 1;
}
@@ -229,8 +234,8 @@ namespace KKdMainLib
public int EyesOffset;
public int NameOffset;
public string Name;
public List<EXPElement> Main;
public List<EXPElement> Eyes;
public KKdList<EXPElement> Main;
public KKdList<EXPElement> Eyes;
public override string ToString() => Name;
}
+1 -1
View File
@@ -41,8 +41,8 @@ namespace KKdMainLib
Stream IO = File.OpenReader(file);
int FileLengthOrigin = IO.Length;
int FileLength = FileLengthOrigin.Align(16);
byte[] In = IO.ToArray();
IO.Close();
byte[] In = File.OpenReader(file).ToArray(true);
byte[] Inalign = new byte[FileLength];
for (int i = 0; i < In.Length; i++) Inalign[i] = In[i];
In = null;
+25 -20
View File
@@ -44,30 +44,28 @@ namespace KKdMainLib
else if (file.Contains("PvList")) { pvList = null; Success = true; }
}
public void DBWriter(string file)
public void DBWriter(string file, uint num2)
{
if (!Success) return;
IO = File.OpenWriter();
if (file.Contains("psrData"))
{
if (psrDat != null || psrDat.Length > 0)
if (psrDat != null && psrDat.Length > 0)
for (i = 0; i < psrDat.Length; i++)
IO.Write(psrDat[i].ToString() + c);
}
else if (file.Contains("PvList"))
{
if (pvList != null || pvList.Length > 0)
if (pvList != null && pvList.Length > 0)
for (i = 0; i < pvList.Length; i++)
IO.Write(UrlEncode(pvList[i].ToString() +
(i < pvList.Length ? c : "")));
else IO.Write("%2A%2A%2A");
}
else IO.Write("%2A%2A%2A");
byte[] data = IO.ToArray(true);
ushort num = DCC.CalculateChecksum(data);
uint num2 = (uint)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
File.WriteAllBytes(file + "_" + num + "_" + num2 + ".dat", data);
}
@@ -79,25 +77,29 @@ namespace KKdMainLib
if (file.Contains("psrData"))
{
if (MsgPack.ElementArray("psrData", out MsgPack psrData))
MsgPack psrData;
if ((psrData = MsgPack["psrData", true]).NotNull)
{
psrDat = new psrData[psrData.Array.Length];
for (i = 0; i < psrDat.Length; i++)
psrDat[i].SetValue(psrData[i]);
}
else if (MsgPack.ContainsKey("psrData")) psrDat = null;
else if (MsgPack["psrData"].NotNull) psrDat = null;
Success = true;
psrData.Dispose();
}
else if (file.Contains("PvList"))
{
if (MsgPack.ElementArray("PvList", out MsgPack PvList))
MsgPack PvList;
if ((PvList = MsgPack["PvList", true]).NotNull)
{
pvList = new PvList[PvList.Array.Length];
for (i = 0; i < pvList.Length; i++)
pvList[i].SetValue(PvList[i], compact);
}
else if (MsgPack.ContainsKey("PvList")) pvList = null;
else if (MsgPack["PvList"].NotNull) pvList = null;
Success = true;
PvList.Dispose();
}
MsgPack.Dispose();
@@ -156,9 +158,11 @@ namespace KKdMainLib
int? ID = msg.ReadNInt32("PV_ID");
if (ID != null) PV_ID = (int)ID;
else { ID = msg.ReadNInt32("ID"); if (ID != null) PV_ID = (int)ID; }
if (msg.Element("P1", out MsgPack P1)) p1.SetValue(P1);
if (msg.Element("P2", out MsgPack P2)) p2.SetValue(P2);
if (msg.Element("P3", out MsgPack P3)) p3.SetValue(P3);
MsgPack Temp;
if ((Temp = msg["P1", true]).NotNull) p1.SetValue(Temp);
if ((Temp = msg["P2", true]).NotNull) p2.SetValue(Temp);
if ((Temp = msg["P3", true]).NotNull) p3.SetValue(Temp);
Temp.Dispose();
}
public MsgPack WriteMP() =>
@@ -251,7 +255,6 @@ namespace KKdMainLib
public void SetValue(MsgPack msg, bool Compact)
{
MsgPack Temp = MsgPack.New;
this.Enable = true;
this.Extra = false;
@@ -270,10 +273,12 @@ namespace KKdMainLib
EndShow .SetValue(msg.ReadNInt32( "EndShow" ), true);
return;
}
if (msg.Element("AdvDemoStart", out Temp)) AdvDemoStart.SetValue(Temp, true);
if (msg.Element("AdvDemoEnd" , out Temp)) AdvDemoEnd .SetValue(Temp, false);
if (msg.Element("StartShow" , out Temp)) StartShow .SetValue(Temp, false);
if (msg.Element( "EndShow" , out Temp)) EndShow .SetValue(Temp, true);
MsgPack Temp;
if ((Temp = msg["AdvDemoStart", true]).NotNull) AdvDemoStart.SetValue(Temp, true);
if ((Temp = msg["AdvDemoEnd" , true]).NotNull) AdvDemoEnd .SetValue(Temp, false);
if ((Temp = msg["StartShow" , true]).NotNull) StartShow .SetValue(Temp, false);
if ((Temp = msg[ "EndShow" , true]).NotNull) EndShow .SetValue(Temp, true);
Temp.Dispose();
}
public MsgPack WriteMP(bool Compact)
@@ -284,14 +289,14 @@ namespace KKdMainLib
if ( Extra ) MsgPack.Add("Extra" , Extra );
if (Compact)
{
if (AdvDemoStart.WriteLower) MsgPack.Add("AdvDemoStart", AdvDemoStart.WriteInt());
if (AdvDemoStart.WriteUpper) MsgPack.Add("AdvDemoStart", AdvDemoStart.WriteInt());
if (AdvDemoEnd .WriteLower) MsgPack.Add("AdvDemoEnd" , AdvDemoEnd .WriteInt());
if (StartShow .WriteLower) MsgPack.Add("StartShow" , StartShow .WriteInt());
if ( EndShow .WriteUpper) MsgPack.Add( "EndShow" , EndShow .WriteInt());
}
else
{
if (AdvDemoStart.WriteLower) MsgPack.Add(AdvDemoStart.WriteMP("AdvDemoStart"));
if (AdvDemoStart.WriteUpper) MsgPack.Add(AdvDemoStart.WriteMP("AdvDemoStart"));
if (AdvDemoEnd .WriteLower) MsgPack.Add(AdvDemoEnd .WriteMP("AdvDemoEnd" ));
if (StartShow .WriteLower) MsgPack.Add(StartShow .WriteMP("StartShow" ));
if ( EndShow .WriteUpper) MsgPack.Add( EndShow .WriteMP( "EndShow" ));
+28 -37
View File
@@ -18,7 +18,7 @@ namespace KKdMainLib
{
Header Header = new Header { Format = Format.F2LE, Signature = stream.ReadInt32(),
DataSize = stream.ReadInt32(), Length = stream.ReadInt32(), Flags = stream.ReadInt32(),
ID = stream.ReadInt32(), SectionSize = stream.ReadInt32(),
Depth = stream.ReadInt32(), SectionSize = stream.ReadInt32(),
Mode = stream.ReadInt32() };
stream.ReadInt32();
if ((Header.Flags & 0x08000000) == 0x08000000) Header.Format = Format.F2BE;
@@ -39,21 +39,21 @@ namespace KKdMainLib
public static void Write(this Stream stream, Header Header, bool Extended = false)
{
Header.Length = (Header.Format < Format.X && Extended) ? 0x40 : 0x20;
Header.Flags = (Header.NotUseDataSizeAsSectionSize ? 0x10000000 : 0) |
(Header.Format == Format.F2BE ? 0x08000000 : 0);
Header.Flags = (!Header.NotUseDataSizeAsSectionSize ? 0x10000000 : 0) |
(Header.Format == Format.F2BE ? 0x08000000 : 0);
stream.Write(Header.Signature);
stream.Write(Header.DataSize);
stream.Write(Header.Length);
stream.Write(Header.Flags);
stream.Write(Header.ID);
stream.Write(Header.Depth);
stream.Write(Header.SectionSize);
stream.Write(Header.Mode);
stream.Write(0x00);
if (Header.Length == 0x40)
{
stream.Write(Header.Format < Format.MGF ? (int)((Header.SectionSignature ^
(Header.DataSize * (long)Header.Signature)) - Header.ID + Header.SectionSize) : 0);
(Header.DataSize * (long)Header.Signature)) - Header.Depth + Header.SectionSize) : 0);
stream.Write(0x00);
stream.Write(0x00L);
stream.Write(Header.InnerSignature);
@@ -63,7 +63,7 @@ namespace KKdMainLib
}
public static void WriteEOFC(this Stream stream, int ID = 0) =>
stream.Write(new Header { ID = ID, Length = 0x20, Signature = 0x43464F45 });
stream.Write(new Header { Depth = ID, Length = 0x20, Signature = 0x43464F45 });
}
public static class POFExtensions
@@ -71,12 +71,11 @@ namespace KKdMainLib
public static void Write(this Stream stream, POF POF, bool ShiftX = false)
{
byte[] data = POF.Write(POF, ShiftX);
Header Header = new Header { ID = POF.ID, Format = Format.F2LE,
Header Header = new Header { Depth = POF.Depth, Format = Format.F2LE,
Length = 0x20, Signature = ShiftX ? 0x31464F50 : 0x30464F50 };
Header.DataSize = Header.SectionSize = data.Length;
stream.Write(Header);
stream.Write(data);
if (POF.EOFC) stream.WriteEOFC(POF.ID);
}
}
@@ -85,12 +84,11 @@ namespace KKdMainLib
public static void Write(this Stream stream, ENRSList ENRS)
{
byte[] data = ENRSList.Write(ENRS);
Header Header = new Header { ID = ENRS.ID,
Header Header = new Header { Depth = ENRS.Depth,
Format = Format.F2LE, Length = 0x20, Signature = 0x53524E45 };
Header.DataSize = Header.SectionSize = data.Length;
stream.Write(Header);
stream.Write(data);
if (ENRS.EOFC) stream.WriteEOFC(ENRS.ID);
}
}
@@ -109,39 +107,30 @@ namespace KKdMainLib
{
Struct Struct = new Struct { Header = Header, DataOffset =
stream.Position, Data = stream.ReadBytes(Header.SectionSize) };
int ID = Header.ID;
int Depth = Header.Depth;
int LastSig = 0, Sig;
long Length = stream.Length - stream.Position;
long Position = 0;
KKdList<Struct> SubStructs = KKdList<Struct>.New;
while (Length > Position)
{
Header = stream.ReadHeader(false);
Position += Header.Length + Header.DataSize;
if (Header.ID == ID && Header.Signature == 0x43464F45)
{ Struct.EOFC = true; break; }
else if (Header.ID == 0 && ((Header.Signature & 0xF0FFFFFF) == 0x30464F50 ||
Header.Signature == 0x53524E45 || Header.Signature == 0x43505854))
SubStructs.Add(new Struct { Header = Header, DataOffset =
stream.Position, Data = stream.ReadBytes(Header.SectionSize) });
else if (Header.ID <= ID)
{ stream.LongPosition -= Header.Length; break; }
Sig = Header.Signature;
Position += Header.Length + Header.SectionSize;
if (Sig == 0x43464F45 && Header.Depth == Depth + 1) break;
else if (Header.Depth == 0 && (Sig == 0x53524E45 ||
(Sig & 0xF0FFFFFF) == 0x30464F50 || Sig == 0x43505854))
{
byte[] Data = stream.ReadBytes(Header.SectionSize);
if (Sig == 0x53524E45) Struct.ENRS = ENRSList.Read(Data, Header.Depth);
else Struct.POF = POF .Read(Data, Sig == 0x31464F50, Header.Depth);
}
else if (Header.Depth <= Depth) { stream.LongPosition -= Header.Length; break; }
else SubStructs.Add(stream.ReadStruct(Header));
LastSig = Sig;
}
for (int i = 0; i < SubStructs.Capacity; i++)
{
string Sig = SubStructs[i].Header.ToString();
if (Sig == "ENRS" || Sig == "EOFC" || Sig == "POF0" || Sig == "POF1")
{
if (Sig == "EOFC") Struct.EOFC = true;
else if (Sig == "ENRS") Struct.ENRS = ENRSList.Read(SubStructs[i].Data,
SubStructs[i].ID, SubStructs[i].EOFC);
else Struct.POF = POF .Read(SubStructs[i].Data, Sig == "POF1",
SubStructs[i].ID, SubStructs[i].EOFC);
SubStructs.RemoveAt(i); SubStructs.Capacity--; i--;
}
}
if (SubStructs.Capacity > 0) Struct.SubStructs = SubStructs.ToArray();
return Struct;
}
@@ -149,21 +138,23 @@ namespace KKdMainLib
public static byte[] Write(this Struct Struct, bool ShiftX = false)
{
byte[] Data;
using (Stream stream = File.OpenWriter()) { stream.Write(Struct, ShiftX); Data = stream.ToArray(); }
using (Stream stream = File.OpenWriter()) { Struct.Update(ShiftX);
stream.Write(Struct, ShiftX); stream.WriteEOFC(); Data = stream.ToArray(); }
return Data;
}
public static void Write(this Stream stream, Struct Struct, bool ShiftX = false)
{
int HeaderPosition = stream.Position;
stream.Write(Struct.Header);
stream.Write(Struct.Data);
stream.Write(Struct.Data );
if (Struct.HasPOF ) stream.Write(Struct.POF , ShiftX);
if (Struct.HasENRS) stream.Write(Struct.ENRS);
if (Struct.HasSubStructs)
{
for (int i = 0; i < Struct.SubStructs.Length; i++)
stream.Write(Struct.SubStructs[i], ShiftX);
if (Struct.EOFC) stream.WriteEOFC(Struct.ID);
stream.WriteEOFC(Struct.Depth + 1);
}
}
}
+2 -1
View File
@@ -9,7 +9,8 @@ namespace KKdMainLib.IO
public static Stream OpenWriter( ) => new Stream(new MSIO.MemoryStream( ));
public static Stream OpenReader(string file, bool ReadAllAtOnce)
{ Stream IO = OpenReader(file); if (ReadAllAtOnce) return OpenReader(IO.ToArray(true)); return IO; }
{ Stream IO = OpenReader(file); if (ReadAllAtOnce) { byte[] data =
IO.ToArray(); IO.Close(); return OpenReader(data); } return IO; }
public static Stream OpenReader(string file)
{ Stream IO = new Stream(new MSIO.FileStream(file, MSIO.FileMode.Open, MSIO.FileAccess.ReadWrite,
MSIO.FileShare.ReadWrite)) { File = file }; return IO; }
+29 -17
View File
@@ -56,7 +56,7 @@ namespace KKdMainLib.IO
ValRead = ValRead = BitWrite = 0;
stream = output;
Format = Format.NULL;
buf = new byte[128];
buf = new byte[0x100];
ptr = buf.GetPtr();
IsBE = isBE;
}
@@ -73,8 +73,10 @@ namespace KKdMainLib.IO
public long? Seek(long? offset, SeekOrigin origin)
{ if (offset == null) return null; return stream.Seek((long)offset, (MSIO.SeekOrigin)(int)origin); }
public void Dispose()
{ CW(); if (stream != MSIO.Stream.Null) { stream.Flush(); stream.Dispose(); } }
public void Dispose() => Dispose(true);
protected virtual void Dispose(bool dispose)
{ CW(); if (stream != MSIO.Stream.Null) { stream.Flush(); stream.Dispose(); } if (dispose) GC.SuppressFinalize(this); }
public MSIO.Stream BaseStream
{ get { stream.Flush(); return stream; } set { stream = value; } }
@@ -125,18 +127,26 @@ namespace KKdMainLib.IO
public float ReadSingleEndian() { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( float*)ptr; }
public double ReadDoubleEndian() { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *(double*)ptr; }
public short ReadInt16Endian(bool IsBE) { CR(); stream.Read(buf, 0, 2); buf.Endian(2, IsBE); return *( short*)ptr; }
public ushort ReadUInt16Endian(bool IsBE) { CR(); stream.Read(buf, 0, 2); buf.Endian(2, IsBE); return *(ushort*)ptr; }
public int ReadInt32Endian(bool IsBE) { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( int*)ptr; }
public uint ReadUInt32Endian(bool IsBE) { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( uint*)ptr; }
public long ReadInt64Endian(bool IsBE) { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *( long*)ptr; }
public ulong ReadUInt64Endian(bool IsBE) { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *( ulong*)ptr; }
public float ReadSingleEndian(bool IsBE) { CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( float*)ptr; }
public double ReadDoubleEndian(bool IsBE) { CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *(double*)ptr; }
public short ReadInt16Endian(bool IsBE)
{ CR(); stream.Read(buf, 0, 2); buf.Endian(2, IsBE); return *( short*)ptr; }
public ushort ReadUInt16Endian(bool IsBE)
{ CR(); stream.Read(buf, 0, 2); buf.Endian(2, IsBE); return *(ushort*)ptr; }
public int ReadInt32Endian(bool IsBE)
{ CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( int*)ptr; }
public uint ReadUInt32Endian(bool IsBE)
{ CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( uint*)ptr; }
public long ReadInt64Endian(bool IsBE)
{ CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *( long*)ptr; }
public ulong ReadUInt64Endian(bool IsBE)
{ CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *( ulong*)ptr; }
public float ReadSingleEndian(bool IsBE)
{ CR(); stream.Read(buf, 0, 4); buf.Endian(4, IsBE); return *( float*)ptr; }
public double ReadDoubleEndian(bool IsBE)
{ CR(); stream.Read(buf, 0, 8); buf.Endian(8, IsBE); return *(double*)ptr; }
public void Write(byte[] Val ) => stream.Write(Val, 0, Val.Length);
public void Write(byte[] Val, int Length) => stream.Write(Val, 0, Length);
public void Write(byte[] Val, int Offset, int Length) => stream.Write(Val, Offset, Length);
public void Write(byte[] Val ) => stream.Write(Val ?? new byte[0], 0, Val.Length);
public void Write(byte[] Val, int Length) => stream.Write(Val ?? new byte[0], 0, Length);
public void Write(byte[] Val, int Offset, int Length) => stream.Write(Val ?? new byte[0], Offset, Length);
public void Write(char[] val, bool UTF8 = true) => Write(UTF8 ? val.ToUTF8() : val.ToASCII());
public void WriteByte(byte val) => stream.WriteByte(val);
@@ -291,12 +301,14 @@ namespace KKdMainLib.IO
{ CFUTRM(); if (BitWrite > 0) { stream.WriteByte((byte)ValWrite); ValWrite = 0; BitWrite = 0; } }
public byte[] ToArray(bool Close)
{ byte[] Data = ToArray(); if (Close) this.Close(); return Data; }
{ byte[] Data = ToArray(); if (Close) Dispose(); return Data; }
[System.Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions]
[System.Security.SecurityCritical]
[System.Security.SecuritySafeCritical]
private void CFUTRM() //CheckForUnableToReadMemory
{ ptr = buf.GetPtr(); }
{ try { if (buf[0] != ptr[0] || buf[1] != ptr[1] || buf[2] != ptr[2] || buf[3] != ptr[3] ||
buf[4] != ptr[4] || buf[5] != ptr[5] || buf[6] != ptr[6] || buf[7] != ptr[7])
ptr = buf.GetPtr(); } catch (AccessViolationException) { ptr = buf.GetPtr(); } }
public byte[] ToArray()
{
-14
View File
@@ -8,20 +8,6 @@ namespace KKdMainLib
{
public static unsafe class Main
{
public static void ConsoleDesign(string text, params string[] args)
{
text = string.Format(text, args);
string Text = "█ █";
Text = Text.Remove(3) + text + Text.Remove(0, text.Length + 3);
Console.WriteLine(Text);
}
public static void ConsoleDesign(bool Fill)
{
if (Fill) Console.WriteLine("████████████████████████████████████████████████████");
else Console.WriteLine("█ █");
}
public const string TimeFormatHHmmssfff = "{0:d2}:{1:d2}:{2:d2}.{3:d3}";
public static void WriteTime(this TimeSpan time, bool WriteLine = false)
+12 -14
View File
@@ -167,16 +167,14 @@ namespace KKdMainLib
MOT = null;
MsgPack MsgPack = file.ReadMP(JSON);
if (!MsgPack.ElementArray("MOT", out MsgPack MOTS)) { MsgPack.Dispose(); return; }
if (MOTS.Array != null)
if (MOTS.Array.Length > 0)
{
MOT = new MotHeader[MOTS.Array.Length];
for (int i = 0; i < MOT.Length; i++)
MsgPackReader(MOTS.Array[i], ref MOT[i]);
}
MsgPack MOTS;
if ((MOTS = MsgPack["MOT"]).NotNull)
{
MOT = new MotHeader[MOTS.Array.Length];
for (int i = 0; i < MOT.Length; i++)
MsgPackReader(MOTS.Array[i], ref MOT[i]);
}
MOTS.Dispose();
MsgPack.Dispose();
}
@@ -195,7 +193,7 @@ namespace KKdMainLib
Mot.HighBits = MOT.ReadInt32("HighBits" );
Mot.FrameCount = MOT.ReadInt32("FrameCount");
if (!MOT.ElementArray("KeySets", out Temp)) return;
if ((Temp = MOT["KeySets", true]).IsNull) { Temp.Dispose(); return; }
Mot.KeySet.Value = new KeySet[Temp.Array.Length];
for (i0 = 0; i0 < Mot.KeySet.Value.Length; i0++)
@@ -235,14 +233,14 @@ namespace KKdMainLib
}
}
}
if (MOT.ElementArray("BoneInfo", out Temp))
if ((Temp = MOT["BoneInfo", true]).NotNull)
{
Mot.BoneInfo.Value = new BoneInfo[Temp.Array.Length];
for (i = 0; i < Mot.BoneInfo.Value.Length; i++)
Mot.BoneInfo.Value[i].Id = Temp[i].ReadInt32();
}
else return;
Temp.Dispose();
}
public MsgPack MsgPackWriter(ref MotHeader Mot)
+2 -2
View File
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("2BA7EFC6-91D1-8BBC-C487-06C7F36CC789")]
[assembly: AssemblyVersion("0.4.7.4")]
[assembly: AssemblyFileVersion("0.4.7.4")]
[assembly: AssemblyVersion("0.4.7.5")]
[assembly: AssemblyFileVersion("0.4.7.5")]
+9 -7
View File
@@ -149,7 +149,7 @@ namespace KKdMainLib
}
IO.UIntPosition = Offset;
POF.ID = 1;
POF.Depth = 1;
IO.Write(POF);
CurrentOffset = IO.UIntPosition;
IO.WriteEOFC();
@@ -169,18 +169,20 @@ namespace KKdMainLib
public void MsgPackReader(string file, bool JSON)
{
MsgPack Temp;
MsgPack MsgPack = file.ReadMPAllAtOnce(JSON);
if (!MsgPack.Element("STR", out MsgPack STR)) return;
if ((Temp = MsgPack["STR"]).NotNull) return;
Header = new Header();
System.Enum.TryParse(STR.ReadString("Format"), out Header.Format);
System.Enum.TryParse(Temp.ReadString("Format"), out Header.Format);
if (!STR.ElementArray("Strings", out MsgPack Strings)) return;
if ((Temp = MsgPack["Strings", true]).IsNull) return;
STRs = new String[Strings.Array.Length];
STRs = new String[Temp.Array.Length];
for (int i = 0; i < STRs.Length; i++)
{
STRs[i].ID = Strings[i].ReadInt32 ("ID" );
STRs[i].Str.Value = Strings[i].ReadString("Str");
STRs[i].ID = Temp[i].ReadInt32 ("ID" );
STRs[i].Str.Value = Temp[i].ReadString("Str");
if (STRs[i].Str.Value == null) STRs[i].Str.Value = "";
}
+2 -2
View File
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("D8A3F2D7-10CC-5723-EC9A-45D3B9C2DFEA")]
[assembly: AssemblyVersion("0.0.3.0")]
[assembly: AssemblyFileVersion("0.0.3.0")]
[assembly: AssemblyVersion("0.1.0.0")]
[assembly: AssemblyFileVersion("0.1.0.0")]
+84 -66
View File
@@ -109,29 +109,7 @@ namespace KKdSoundLib
VAG_1 = HEVAG1Ptr[PrNR]; VAG_2 = HEVAG2Ptr[PrNR];
tS1 = S1Ptr[c]; tS2 = S2Ptr[c];
i = 0; i2 = 1;
while (i < BS)
{
d0 = four_bitPtr[i];
d1 = four_bitPtr[i2];
if (d0 > 7) d0 -= 16;
if (d1 > 7) d1 -= 16;
d0 <<= (20 - ShF);
d1 <<= (20 - ShF);
g = ((tS1 >> 8) * VAG_1 + (tS2 >> 8) * VAG_2) >> 5;
tS2 = tS1; tS1 = g + d0;
g = ((tS1 >> 8) * VAG_1 + (tS2 >> 8) * VAG_2) >> 5;
tS2 = tS1; tS1 = g + d1;
temp_bufferPtr[i ] = tS2;
temp_bufferPtr[i2] = tS1;
i += 2;
i2 += 2;
}
DecodeVAG();
S1Ptr[c] = tS1; S2Ptr[c] = tS2;
for (i = 0, i2 = 1; i < BS; i += 2, i2 += 2)
@@ -146,6 +124,31 @@ namespace KKdSoundLib
Success = true;
}
private void DecodeVAG()
{
i = 0; i2 = 1;
while (i < BS)
{
d0 = four_bitPtr[i];
d1 = four_bitPtr[i2];
if (d0 > 7) d0 -= 16;
if (d1 > 7) d1 -= 16;
d0 <<= 20 - ShF;
d1 <<= 20 - ShF;
g = ((tS1 >> 8) * VAG_1 + (tS2 >> 8) * VAG_2) >> 5;
tS2 = tS1; tS1 = g + d0;
g = ((tS1 >> 8) * VAG_1 + (tS2 >> 8) * VAG_2) >> 5;
tS2 = tS1; tS1 = g + d1;
temp_bufferPtr[i ] = tS2;
temp_bufferPtr[i2] = tS1;
i += 2;
i2 += 2;
}
}
private void DecodeHEVAG()
{
i = 0; i2 = 1;
@@ -155,8 +158,8 @@ namespace KKdSoundLib
d1 = four_bitPtr[i2];
if (d0 > 7) d0 -= 16;
if (d1 > 7) d1 -= 16;
d0 <<= (20 - ShF);
d1 <<= (20 - ShF);
d0 <<= 20 - ShF;
d1 <<= 20 - ShF;
g = ((tS1 >> 8) * HEVAG_1 + (tS2 >> 8) * HEVAG_2 +
(tS3 >> 8) * HEVAG_3 + (tS4 >> 8) * HEVAG_4) >> 5;
@@ -197,7 +200,7 @@ namespace KKdSoundLib
for (i1 = 0, i2 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
{
Flag = VAGData.Flags[i1];
if (!IgnoreEndFlags && Flag == 5 || Flag == 7) break;
if (!IgnoreEndFlags && (Flag == 5 || Flag == 7)) break;
if (Flag < 8)
for (i = 0; i < BS; i++)
for (c = 0; c < ch; c++)
@@ -248,7 +251,7 @@ namespace KKdSoundLib
for (i1 = 1, i2 = 0; i1 < VAGData.Size; i1++, VAGData.DataPtr += VBS)
{
Flag = VAGData.Flags[i1];
if (!IgnoreEndFlags && Flag == 5 || Flag == 7) break;
if (!IgnoreEndFlags && (Flag == 5 || Flag == 7)) break;
else if (!IgnoreEndFlags && Flag == 6)
{
Header = new WAV.Header { Bytes = 4, Channels = ch, Format = 3, SampleRate =
@@ -476,7 +479,6 @@ namespace KKdSoundLib
four_bit = new int[BS]; four_bitPtr = four_bit .GetPtr();
data_buffer = new int[BS]; data_bufferPtr = data_buffer.GetPtr();
temp_buffer = new int[BS]; temp_bufferPtr = temp_buffer.GetPtr();
buffer = new int[PrNRCount, BS];
writer.Write(0x70474156);
if (HEVAG) writer.WriteEndian(0x00020001, true);
@@ -581,65 +583,81 @@ namespace KKdSoundLib
private int min, ShM, S1, S2, S3, S4, tS1, tS2, tS3, tS4, PrNRf;
private int VAG_1, VAG_2, HEVAG_1, HEVAG_2, HEVAG_3, HEVAG_4;
private int[] data_buffer, error, four_bit, max, S_1, S_2, S_3, S_4, temp_buffer;
private int[,] buffer;
private int* data_bufferPtr, errorPtr, four_bitPtr, maxPtr, temp_bufferPtr;
private void Calc4BitsVAG()
{
ShF = min = 134217728;
for (j = 0; j < 5; j++)
PrNRf = 0;
min = 134217728;
for (j = 0; j < PrNRCount; j++)
{
maxPtr[j] = 0;
S1 = S1Ptr[c]; S2 = S2Ptr[c];
VAG_1 = HEVAG1Ptr[j]; VAG_2 = HEVAG2Ptr[j];
for (i = 0; i < 28; i++)
PrNR = j;
Calc4Bits_VAG();
tS1 = S1Ptr[c]; tS2 = S2Ptr[c];
DecodeVAG();
i = 0;
errorPtr[j] = 0;
while (i < BS)
{
g = data_bufferPtr[i];
e = ((S1 >> 8) * VAG_1 + (S2 >> 8) * VAG_2) >> 5;
e = g - e;
if (e > 7864319) e = 7864319;
if (e < -7864320) e = -7864320;
buffer[j, i] = e;
e = data_bufferPtr[i] - temp_bufferPtr[i];
if (e < 0) e = -e;
if (e > maxPtr[j]) maxPtr[j] = e;
S2 = S1; S1 = g;
errorPtr[j] += e;
i++;
}
if (maxPtr[j] < min) { PrNR = j; min = maxPtr[j]; }
if (errorPtr[j] < min) { PrNRf = j; min = errorPtr[j]; }
}
S1Ptr[c] = S1; S2Ptr[c] = S2;
PrNR = PrNRf;
ShF = 0;
ShM = 0x4000;
min >>= 8;
while (ShF < 12)
Calc4Bits_VAG();
S1Ptr[c] = S1; S2Ptr[c] = S2;
S_1 [c] = tS1; S_2 [c] = tS2;
}
private void Calc4Bits_VAG()
{
S1 = S1Ptr[c]; S2 = S2Ptr[c];
VAG_1 = HEVAG1Ptr[PrNR]; HEVAG_2 = HEVAG2Ptr[PrNR];
i = 0;
maxPtr[PrNR] = 0;
while (i < BS)
{
e = min + (ShM >> 3);
if ((ShM & e) == ShM)
break;
ShF++;
ShM >>= 1;
g = data_bufferPtr[i];
e = ((S1 >> 8) * VAG_1 + (S2 >> 8) * VAG_2) >> 5;
e = g - e;
if (e > 7864319) e = 7864319;
if (e < -7864320) e = -7864320;
temp_bufferPtr[i] = e;
if (e < 0) e = -e;
if (e > maxPtr[PrNR]) maxPtr[PrNR] = e;
S2 = S1; S1 = g;
i++;
}
S1 = S_1[c]; S2 = S_2[c];
for (i = 0; i < 28; i++)
for (ShF = 0, ShM = 0x400000; ShF < 15; ShF++, ShM >>= 1)
{ e = maxPtr[PrNR] + (ShM >> 3); if ((ShM & e) == ShM) break; }
tS1 = S_1[c]; tS2 = S_2[c];
i = 0;
while (i < BS)
{
g = buffer[PrNR, i];
e = ((S1 >> 8) * HEVAG1Ptr[PrNR] + (S2 >> 8) * HEVAG2Ptr[PrNR]) >> 5;
g = temp_bufferPtr[i];
e = ((tS1 >> 8) * VAG_1 + (tS2 >> 8) * VAG_2) >> 5;
e = g - e;
d1 = e << ShF;
d0 = (int)((uint)d1 + 0x80000) >> 20;
d0 = (d1 + 0x80000) >> 20;
if (d0 > 7) d0 = 7;
if (d0 < -8) d0 = -8;
four_bitPtr[i] = d0 & 0xF;
d0 <<= (20 - ShF);
d0 <<= 20 - ShF;
S2 = S1; S1 = d0 - e;
tS2 = tS1; tS1 = d0 - e;
i++;
}
S_1[c] = S1; S_2[c] = S2;
}
private void Calc4BitsHEVAG()
@@ -713,7 +731,7 @@ namespace KKdSoundLib
if (d0 > 7) d0 = 7;
if (d0 < -8) d0 = -8;
four_bitPtr[i] = d0 & 0xF;
d0 <<= (20 - ShF);
d0 <<= 20 - ShF;
tS4 = tS3; tS3 = tS2; tS2 = tS1; tS1 = d0 - e;
i++;
+2 -2
View File
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
[assembly: AssemblyVersion("0.4.7.4")]
[assembly: AssemblyFileVersion("0.4.7.4")]
[assembly: AssemblyVersion("0.4.7.5")]
[assembly: AssemblyFileVersion("0.4.7.5")]
+3 -2
View File
@@ -33,6 +33,7 @@ namespace PD_Tool.Tools
format = Console.ReadLine();
}
uint num2 = (uint)DateTime.Now.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
KKdMainLib.DataBank DB;
string[] file_split;
foreach (string file in FileNames)
@@ -52,11 +53,11 @@ namespace PD_Tool.Tools
DB.MsgPackWriter(filepath + file_split[0] + "_" +
file_split[1] + "_" + file_split[2], JSON, format != "2");
}
else if (ext == ".mp" || ext == ".json" && !MP)
else if ((ext == ".mp" || ext == ".json") && !MP)
{
Console.Title = "DataBank Converter: " + filename;
DB.MsgPackReader(filepath, JSON);
DB. DBWriter(filepath);
DB. DBWriter(filepath, num2);
}
DB = null;
}