Compare commits

...
Author SHA1 Message Date
korenkonder a1c18941a1 Patch for release v0.4.10.16 2023-05-29 22:53:10 +03:00
korenkonder c95a116297 Release v0.4.10.16
JSON
2023-05-29 12:49:13 +03:00
korenkonder 139fbf307f Release v0.4.10.15
MotHead
2023-05-18 18:06:08 +03:00
korenkonder 1d5c88f39f Release v0.4.10.14
A3DA
2022-08-11 00:07:13 +03:00
11 changed files with 759 additions and 331 deletions
+10 -19
View File
@@ -371,6 +371,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");
@@ -497,6 +499,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");
@@ -811,8 +815,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;
@@ -821,6 +823,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);
@@ -967,8 +971,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;
@@ -977,6 +979,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);
@@ -1434,13 +1438,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++)
{
@@ -1517,12 +1514,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++)
@@ -2303,7 +2294,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"),
@@ -2427,7 +2418,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"),
+221 -128
View File
@@ -14,12 +14,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; Signature = Farc.FArC; 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 +29,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 +48,132 @@ 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);
file.Compressed = file.Size != 0 || (FARCFlags & Flags.GZip) != 0;
file.Encrypted = ((FARCFlags | Flags) & Flags.AES) != 0;
Files.Add(file);
}
else if (Signature != Farc.FArc)
for (int i = 0; i < Files.Capacity; i++)
{
FARCFile file = default;
file.Name = reader.NTUTF8();
file.Offset = reader.RI32E(true);
file.SizeComp = reader.RI32E(true);
file.Size = reader.RI32E(true);
file.Compressed = file.Size != 0;
file.Encrypted = (FARCFlags & Flags.AES) != 0;
Files.Add(file);
}
else
for (int i = 0; i < Files.Capacity; i++)
{
FARCFile file = default;
file.Name = reader.NTUTF8();
file.Offset = reader.RI32E(true);
file.Size = reader.RI32E(true);
file.SizeComp = 0;
file.Compressed = false;
file.Encrypted = false;
Files.Add(file);
}
reader.Dispose();
return true;
}
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,71 +182,116 @@ 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)
{
file.DataComp = reader.RBy(file.SizeComp);
file.Data = file.DataComp.InflateGZip(file.Size);
}
else if (file.Encrypted || file.Compressed)
{
int tempSize = file.Encrypted ? file.SizeComp.A(0x10) : file.SizeComp;
byte[] temp;
if (file.Encrypted)
if (FT)
{
file.SizeComp -= 0x10;
tempSize -= 0x10;
byte[] iv = reader.RBy(0x10);
using (MSIO.MemoryStream ms = new MSIO.MemoryStream())
{
using (AesManaged aes = GetAes(iv))
using (CryptoStream cryptoStream = new CryptoStream(ms,
aes.CreateDecryptor(), CryptoStreamMode.Write))
cryptoStream.Write(reader.RBy(tempSize), 0x00, tempSize);
temp = ms.ToArray();
file.SizeComp = temp.Length;
}
}
else
{
using (MSIO.MemoryStream ms = new MSIO.MemoryStream())
{
using (AesManaged aes = GetAes())
using (CryptoStream cryptoStream = new CryptoStream(ms,
aes.CreateDecryptor(), CryptoStreamMode.Write))
cryptoStream.Write(reader.RBy(tempSize), 0x00, tempSize);
temp = ms.ToArray();
}
}
else
temp = reader.RBy(tempSize);
if (!file.Compressed)
{
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 = null;
file.Data = temp;
}
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 = temp;
file.Data = file.DataComp.InflateGZip(file.Size);
}
}
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;
}
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;
return Files[i].Data;
}
public void Pack(Farc signature = Farc.FArC)
@@ -231,7 +326,7 @@ namespace KKdMainLib
else if (Signature == Farc.FArC) headerWriter.WE(0x01, true);
else if (Signature == Farc.FARC)
{
headerWriter.WE((int)FARCType, true);
headerWriter.WE((int)FARCFlags, true);
headerWriter.W (0x00);
headerWriter.WE(0x40, true);
headerWriter.W (0x00);
@@ -262,7 +357,7 @@ namespace KKdMainLib
writer.W (file.Name + "\0");
writer.WE(file.Offset, true);
if (Signature != Farc.FArc) writer.WE(file.SizeComp, true);
writer.WE(file.SizeUnc, true);
writer.WE(file.Size, true);
}
writer.Dispose();
}
@@ -271,24 +366,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 (Signature == Farc.FArC || (Signature == Farc.FARC && (FARCFlags & Flags.GZip) != 0))
data = file.Data.DeflateGZip(CompressionLevel);
}
file.SizeComp = data.Length;
if (Signature == Farc.FARC && (FARCType & Type.Enc) != 0)
if (Signature == Farc.FARC && (FARCFlags & Flags.AES) != 0)
{
int alignLength = data.Length.A(0x40);
byte[] tempData = new byte[alignLength];
System.Array.Copy(data, tempData, data.Length);
for (int i1 = file.Data.Length; i1 < alignLength; i1++) tempData[i1] = 0x78;
data = Encrypt(tempData, false);
data = Encrypt(tempData);
}
writer.W(data);
@@ -301,26 +392,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 +425,11 @@ namespace KKdMainLib
FARC = 0x46415243,
}
public enum Type : int
public enum Flags : int
{
None = 0b000,
GZip = 0b010,
Enc = 0b100,
AES = 0b100,
}
}
}
+488 -151
View File
@@ -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 = _IO.RBy(buf.data.Length - 1);
buf.length = temp.Length;
Array.Copy(temp, 0, buf.data, 1, temp.Length);
}
if (buf.length < 1)
return -1;
int c = buf.data[buf.first];
buf.first++;
buf.length--;
return c;
}
void Seek(ref ReadBuffer buf, long offset)
{
if (buf.first < offset || offset >= buf.length - 1L) {
long pos = _IO.PI64 - buf.length - offset;
long off = pos % buf.data.Length;
pos -= off;
if (pos > 1)
{
_IO.S(pos, SeekOrigin.Begin);
buf.first = (int)off;
byte[] temp = _IO.RBy(buf.data.Length);
buf.length = temp.Length;
Array.Copy(temp, 0, buf.data, 0, temp.Length);
}
else
{
_IO.S(pos, SeekOrigin.Begin);
buf.first = (int)(off + 1);
buf.data[0] = '\0';
byte[] temp = _IO.RBy(buf.data.Length - 1);
buf.length = temp.Length;
Array.Copy(temp, 0, buf.data, 1, temp.Length);
}
buf.length -= (int)off;
}
else
{
buf.first -= (int)offset;
buf.length += (int)offset;
}
}
void SeekOne(ref ReadBuffer buf)
{
buf.first--;
buf.length++;
}
object ReadInner(ref ReadBuffer buf, ref int c)
{
if (c == -1)
return null;
if (c == ' ' || c == '\n' || c == '\r' || c == '\t')
c = ReadChar(ref buf);
switch (c)
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '-':
return ReadFloat(ref buf, ref c);
case '"':
return ReadString(ref buf, ref c);
case '{':
return ReadMap(ref buf, ref c);
case '[':
return ReadArray(ref buf, ref c);
case 't':
return ReadBool(ref buf, ref c);
case 'f':
return ReadBool(ref buf, ref c);
case 'n':
return ReadNull(ref buf, ref c);
}
return null;
}
void ReadDigit(ref ReadBuffer buf, ref int c, byte[] dig_buf, ref int dig_buf_pos, int dig_buf_end) {
int b = dig_buf_pos;
while (c >= '0' && c <= '9' && b < dig_buf_end) {
dig_buf[b++] = (byte)c;
if ((c = ReadChar(ref buf)) == -1)
break;
}
dig_buf_pos = b;
}
object ReadFloat(ref ReadBuffer buf, ref int c)
{
byte[] dig_buf = new byte[0x100];
int buf_pos = 0;
int buf_end = dig_buf.Length;
bool negate = false;
bool zero = false;
bool fraction = false;
if (c == '-')
{
dig_buf[buf_pos++] = (byte)c;
if ((c = ReadChar(ref buf)) == -1)
return null;
negate = true;
}
if (c == '0')
{
dig_buf[buf_pos++] = (byte)c;
if ((c = ReadChar(ref buf)) == -1)
return null;
zero = true;
}
else
ReadDigit(ref buf, ref c, dig_buf, ref buf_pos, buf_end);
if (c == '.')
{
dig_buf[buf_pos++] = (byte)c;
if ((c = ReadChar(ref buf)) == -1)
return null;
ReadDigit(ref buf, ref c, dig_buf, ref buf_pos, buf_end);
fraction = true;
}
if (zero && !fraction)
{
object obj;
if (negate)
obj = -0.0f;
else
obj = 0;
SeekOne(ref buf);
return obj;
}
else if (c != 'e' && c != 'E' && !fraction)
{
string temp = dig_buf.ToUTF8();
int null_term = temp.IndexOf('\0');
if (null_term >= 0)
temp = temp.Substring(0, null_term);
if (!long.TryParse(temp, out long val))
return null;
object obj;
unchecked
{
if (val >= 0x00 && val < 0xFF)
obj = (byte)val;
else if (val >= (sbyte)0x80 && val <= (sbyte)0x7F)
obj = (sbyte)val;
else if (val >= 0x0000 && val < 0xFFFF)
obj = (ushort)val;
else if (val >= (short)0x8000 && val <= (short)0x7FFF)
obj = (short)val;
else if (val >= 0x00000000 && val <= 0xFFFFFFFF)
obj = (uint)val;
else if (val >= (int)0x80000000 && val <= (int)0x7FFFFFFF)
obj = (int)val;
else
obj = val;
}
SeekOne(ref buf);
return obj;
}
else if (c == 'e' || c == 'E')
{
dig_buf[buf_pos++] = (byte)c;
if ((c = ReadChar(ref buf)) == -1)
return null;
if (c == '+' || c == '-')
{
dig_buf[buf_pos++] = (byte)c;
if ((c = ReadChar(ref buf)) == -1)
return null;
}
ReadDigit(ref buf, ref c, dig_buf, ref buf_pos, buf_end);
}
string ftemp = dig_buf.ToUTF8();
int fnull_term = ftemp.IndexOf('\0');
if (fnull_term >= 0)
ftemp = ftemp.Substring(0, fnull_term);
if (!ftemp.ToF64(out double fval))
return null;
object fobj;
if (fval == (float)fval)
fobj = (float)fval;
else
fobj = fval;
SeekOne(ref buf);
return fobj;
}
byte ReadStringHex(int c)
{
if (c >= '0' && c <= '9')
return (byte)(c - '0');
else if (c >= 'A' && c <= 'F')
return (byte)(c - 'A' + 0xA);
else if (c >= 'a' && c <= 'f')
return (byte)(c - 'a' + 0xA);
else
return 0;
}
string ReadStringInner(ref ReadBuffer buf, ref int c)
{
if (c != '"')
return null;
long pos = _IO.PI64 - buf.length;
ulong len = 0;
while (c != -1)
{
c = ReadChar(ref buf);
if (c == '\\')
{
if ((c = ReadChar(ref buf)) == -1)
break;
switch (c)
{
case '"':
case '\\':
case '/':
case 'b':
case 'f':
case 'n':
case 'r':
case 't':
len++;
break;
case 'u':
{
uint uc = 0;
if ((c = ReadChar(ref buf)) == -1)
break;
uc |= (uint)ReadStringHex(c) << 24;
if ((c = ReadChar(ref buf)) == -1)
break;
uc |= (uint)ReadStringHex(c) << 16;
if ((c = ReadChar(ref buf)) == -1)
break;
uc |= (uint)ReadStringHex(c) << 8;
if ((c = ReadChar(ref buf)) == -1)
break;
uc |= (uint)ReadStringHex(c);
if (uc <= 0x7F)
len++;
else if (c <= 0x7FF)
len += 2;
else
len += 3;
}
break;
}
}
else if (c == '"')
break;
else
len++;
}
if (c == -1)
return null;
long pos_end = _IO.PI64 - buf.length;
Seek(ref buf, pos_end - pos);
byte[] temp = new byte[len + 1];
for (ulong i = 0; i < len;)
{
c = ReadChar(ref buf);
if (c == '\\')
{
c = _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);
+3 -3
View File
@@ -4,14 +4,14 @@
<Authors>korenkonder</Authors>
<Company></Company>
<Configuration></Configuration>
<Copyright>korenkonder (C) 2018-2022</Copyright>
<Copyright>korenkonder (C) 2018-2023</Copyright>
<Description>A simple library for working with Project Diva AC/DT/F/AFT/F2/X/XHD/FT/VRFL/M39 files</Description>
<FileVersion>0.4.10.13</FileVersion>
<FileVersion>0.4.10.16</FileVersion>
<PackageId>KKdMainLib</PackageId>
<Product>KKdMainLib</Product>
<TargetFramework>net461</TargetFramework>
<Title>KKdMainLib</Title>
<Version>0.4.10.13</Version>
<Version>0.4.10.16</Version>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
+16 -10
View File
@@ -200,10 +200,16 @@ RETURN:
{
ref HeaderData.Sub.Data data = ref Header.Data[i].Array[i0];
int Size = GetSize(data.Type);
if (data.Array == null || data.Array.Length < 1 || Size < 1) continue;
if ((int)data.Type == 0x3E || (int)data.Type == 0x49)
s.A(0x20, true);
if (data.Array == null || data.Array.Length < 1 || Size < 1) continue;
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);
@@ -492,7 +498,7 @@ RETURN:
data.Array.GBy(temp.RF32("Duration"), 0x04);
break;
case 0x3E: // RobPartsAdjust
data.Array.GBy(temp.RF32("ForceDuration"), 0x00);
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);
@@ -510,7 +516,7 @@ RETURN:
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.RF32("StrengthTransition"), 0x3C);
data.Array.GBy(temp.RI32("StrengthTransition"), 0x3C);
break;
case 0x41: // OsageReset
data.Array.GBy(temp.RI32("Iterations"), 0x00);
@@ -570,7 +576,7 @@ RETURN:
data.Array.GBy(temp.RU8("i01_8"), 0x01);
break;
case 0x4B: // RobAdjustGlobal
data.Array.GBy(temp.RI32("ForceDuration"), 0x00);
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);
@@ -798,7 +804,7 @@ RETURN:
break;
case 0x3E: // RobPartsAdjust
arrayEntry.Add(new MsgPack("Data")
.Add("ForceDuration", data.Array.TF32(0x00))
.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)
@@ -816,7 +822,7 @@ RETURN:
.Add("Phase", data.Array.TF32(0x30))
.Add("Force", data.Array.TF32(0x34))
.Add("Strength", data.Array.TF32(0x38))
.Add("StrengthTransition", data.Array.TF32(0x3C)));
.Add("StrengthTransition", data.Array.TI32(0x3C)));
break;
case 0x41: // OsageReset
arrayEntry.Add(new MsgPack("Data")
@@ -887,7 +893,7 @@ RETURN:
break;
case 0x4B: // RobAdjustGlobal
arrayEntry.Add(new MsgPack("Data")
.Add("ForceDuration", data.Array.TF32(0x00))
.Add("TransitionDuration", data.Array.TI32(0x00))
.Add("Type", data.Array.TU8(0x04))
.Add("CycleType", data.Array.TU8(0x05))
.Add("ExternalForceX", data.Array.TF32(0x08))
Binary file not shown.
+6 -5
View File
@@ -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 -4
View File
@@ -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>
+3 -3
View File
@@ -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-2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
[assembly: AssemblyVersion("0.4.10.13")]
[assembly: AssemblyFileVersion("0.4.10.13")]
[assembly: AssemblyVersion("0.4.10.16")]
[assembly: AssemblyFileVersion("0.4.10.16")]
+6 -6
View File
@@ -82,8 +82,8 @@ namespace PD_Tool
else
{
a3da.Head.Format = format;
File.WriteAllBytes(filepath + ".a3da", (choose[0] == '1' ||
choose[0] == '3') ? a3da.A3DAWriter() : a3da.A3DCWriter());
File.WriteAllBytes(filepath + ".a3da", choose[0] == '1' || choose[0] == '3'
? a3da.A3DAWriter() : a3da.A3DCWriter());
}
}
else if (ext == ".mp" || ext == ".json")
@@ -92,8 +92,8 @@ namespace PD_Tool
a3da.MsgPackReader(filepath, ext == ".json");
a3da.Head.Format = format;
File.WriteAllBytes(filepath + ".a3da", (choose[0] == '1' ||
choose[0] == '3') ? a3da.A3DAWriter() : a3da.A3DCWriter());
File.WriteAllBytes(filepath + ".a3da", choose[0] == '1' || choose[0] == '3'
? a3da.A3DAWriter() : a3da.A3DCWriter());
}
}
}
@@ -127,7 +127,7 @@ namespace PD_Tool
{
KKdFARC.FARCFile file = farc.Files[i];
a3da.Head.Format = format;
file.Data = (choose[0] == '1'|| choose[0] == '4')
file.Data = choose[0] == '1' || choose[0] == '3'
? a3da.A3DAWriter() : a3da.A3DCWriter();
farc.Files[i] = file;
}
@@ -177,7 +177,7 @@ namespace PD_Tool
KKdFARC.FARCFile file = default;
file.Name = list[i];
a3daArray[i].Head.Format = format;
file.Data = (choose[0] == '1'|| choose[0] == '4')
file.Data = choose[0] == '1'|| choose[0] == '3'
? a3daArray[i].A3DAWriter() : a3daArray[i].A3DCWriter();
farc.Files.Add(file);
}
+2 -2
View File
@@ -63,8 +63,8 @@ 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;