Compare commits
2
Commits
v0.4.10.12
...
v0.4.10.14
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d5c88f39f | ||
|
|
786dca23fd |
+26
-34
@@ -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"),
|
||||
@@ -2652,11 +2643,11 @@ namespace KKdMainLib
|
||||
MsgPack instance = new MsgPack(Data.MObjectHRC[i0].Instances.Length, "Instance");
|
||||
for (i1 = 0; i1 < Data.MObjectHRC[i0].Instances.Length; i1++)
|
||||
{
|
||||
instance[i1] = MsgPack.New.Add(ref Data.MObjectHRC[i0].Instances[i1].MT)
|
||||
.Add("Name", Data.MObjectHRC[i0].Instances[i1].Name);
|
||||
MsgPack _instance = MsgPack.New.Add("Name", Data.MObjectHRC[i0].Instances[i1].Name);
|
||||
if (Data.MObjectHRC[i0].Instances[i1].Shadow)
|
||||
instance[i1].Add("Shadow", true);
|
||||
instance[i1].Add("UIDName", Data.MObjectHRC[i0].Instances[i1].UIDName);
|
||||
_instance.Add("Shadow", true);
|
||||
_instance.Add("UIDName", Data.MObjectHRC[i0].Instances[i1].UIDName);
|
||||
instance[i1] = _instance.Add(ref Data.MObjectHRC[i0].Instances[i1].MT);
|
||||
}
|
||||
|
||||
_mObjectHRC.Add(instance);
|
||||
@@ -2667,19 +2658,19 @@ namespace KKdMainLib
|
||||
MsgPack node = new MsgPack(Data.MObjectHRC[i0].Node.Length, "Node");
|
||||
for (i1 = 0; i1 < Data.MObjectHRC[i0].Node.Length; i1++)
|
||||
{
|
||||
node[i1] = MsgPack.New
|
||||
MsgPack _node = MsgPack.New
|
||||
.Add("Name" , Data.MObjectHRC[i0].Node[i1].Name )
|
||||
.Add("Parent", Data.MObjectHRC[i0].Node[i1].Parent)
|
||||
.Add(ref Data.MObjectHRC[i0].Node[i1].MT);
|
||||
.Add("Parent", Data.MObjectHRC[i0].Node[i1].Parent);
|
||||
|
||||
if (Data.MObjectHRC[i0].Node[i1].JointOrient.HasValue)
|
||||
{
|
||||
Vec3 jointOrient = Data.MObjectHRC[i0].Node[i1].JointOrient.Value;
|
||||
node[i1] = node[i1].Add(new MsgPack("JointOrient")
|
||||
_node.Add(new MsgPack("JointOrient")
|
||||
.Add("X", jointOrient.X)
|
||||
.Add("Y", jointOrient.Y)
|
||||
.Add("Z", jointOrient.Z));
|
||||
}
|
||||
node[i1] = _node.Add(ref Data.MObjectHRC[i0].Node[i1].MT);
|
||||
}
|
||||
_mObjectHRC.Add(node);
|
||||
}
|
||||
@@ -2737,10 +2728,11 @@ namespace KKdMainLib
|
||||
MsgPack texPat = new MsgPack(Data.Object[i0].TexPat.Length, "TexturePattern");
|
||||
for (i1 = 0; i1 < Data.Object[i0].TexPat.Length; i1++)
|
||||
{
|
||||
texPat[i1] = MsgPack.New.Add("Name", Data.Object[i0].TexPat[i1].Name);
|
||||
MsgPack _texPat = MsgPack.New.Add("Name", Data.Object[i0].TexPat[i1].Name);
|
||||
if (Data.Object[i0].TexPat[i1].Pat != null)
|
||||
texPat[i1] = texPat[i1].Add("Pat" , Data.Object[i0].TexPat[i1].Pat )
|
||||
.Add("PatOffset", Data.Object[i0].TexPat[i1].PatOffset);
|
||||
_texPat.Add("Pat" , Data.Object[i0].TexPat[i1].Pat )
|
||||
.Add("PatOffset", Data.Object[i0].TexPat[i1].PatOffset);
|
||||
texPat[i1] = _texPat;
|
||||
}
|
||||
_object.Add(texPat);
|
||||
}
|
||||
@@ -2786,19 +2778,19 @@ namespace KKdMainLib
|
||||
MsgPack node = new MsgPack(Data.ObjectHRC[i0].Node.Length, "Node");
|
||||
for (i1 = 0; i1 < Data.ObjectHRC[i0].Node.Length; i1++)
|
||||
{
|
||||
node[i1] = MsgPack.New
|
||||
MsgPack _node = MsgPack.New
|
||||
.Add("Name" , Data.ObjectHRC[i0].Node[i1].Name )
|
||||
.Add("Parent", Data.ObjectHRC[i0].Node[i1].Parent)
|
||||
.Add(ref Data.ObjectHRC[i0].Node[i1].MT);
|
||||
.Add("Parent", Data.ObjectHRC[i0].Node[i1].Parent);
|
||||
|
||||
if (Data.ObjectHRC[i0].Node[i1].JointOrient.HasValue)
|
||||
{
|
||||
Vec3 jointOrient = Data.ObjectHRC[i0].Node[i1].JointOrient.Value;
|
||||
node[i1] = node[i1].Add(new MsgPack("JointOrient")
|
||||
_node.Add(new MsgPack("JointOrient")
|
||||
.Add("X", jointOrient.X)
|
||||
.Add("Y", jointOrient.Y)
|
||||
.Add("Z", jointOrient.Z));
|
||||
}
|
||||
node[i1] = _node.Add(ref Data.ObjectHRC[i0].Node[i1].MT);
|
||||
}
|
||||
_objectHRC.Add(node);
|
||||
}
|
||||
|
||||
+221
-128
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
<Configuration></Configuration>
|
||||
<Copyright>korenkonder (C) 2018-2022</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.12</FileVersion>
|
||||
<FileVersion>0.4.10.14</FileVersion>
|
||||
<PackageId>KKdMainLib</PackageId>
|
||||
<Product>KKdMainLib</Product>
|
||||
<TargetFramework>net461</TargetFramework>
|
||||
<Title>KKdMainLib</Title>
|
||||
<Version>0.4.10.12</Version>
|
||||
<Version>0.4.10.14</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
||||
+3
-2
@@ -178,10 +178,11 @@ namespace KKdMainLib
|
||||
MsgPack strings = new MsgPack(Strings.Length, "Strings");
|
||||
for (int i = 0; i < Strings.Length; i++)
|
||||
{
|
||||
strings[i] = MsgPack.New.Add("ID", Strings[i].ID);
|
||||
MsgPack @string = MsgPack.New.Add("ID", Strings[i].ID);
|
||||
if (Strings[i].Str.V != null)
|
||||
if (Strings[i].Str.V != "")
|
||||
strings[i] = strings[i].Add("Str", Strings[i].Str.V);
|
||||
@string.Add("Str", Strings[i].Str.V);
|
||||
strings[i] = @string;
|
||||
}
|
||||
str.Add(strings);
|
||||
|
||||
|
||||
Binary file not shown.
+6
-5
@@ -24,9 +24,10 @@ namespace KKdSoundLib
|
||||
Data.SampleRate = reader.RI32();
|
||||
Data.SamplesCount = reader.RI32();
|
||||
reader.RI64();
|
||||
Data.Channels = reader.RU16();
|
||||
Data.Channels = reader.RU8();
|
||||
reader.RU8();
|
||||
reader.RU16();
|
||||
Data.Name = reader.RS(0x20);
|
||||
reader.RBy(0x20);
|
||||
|
||||
byte value = 0;
|
||||
byte[] data = new byte[Data.SamplesCount * Data.Channels * 4];
|
||||
@@ -39,6 +40,7 @@ namespace KKdSoundLib
|
||||
fixed (sbyte* stepindexPtr = stepindex)
|
||||
fixed (byte* ptr = data)
|
||||
{
|
||||
reader.S(0, SeekOrigin.Begin);
|
||||
float* dataPtr = (float*)ptr;
|
||||
for (i = 0; i < Data.SamplesCount; i++)
|
||||
for (c = 0; c < Data.Channels; c++, dataPtr++)
|
||||
@@ -76,7 +78,7 @@ namespace KKdSoundLib
|
||||
if (!Header.IsSupported) { reader.C(); return; }
|
||||
|
||||
Stream writer = File.OpenWriter(file + ".diva", true);
|
||||
Data.Channels = Header.Channels;
|
||||
Data.Channels = (byte)Header.Channels;
|
||||
Data.SampleRate = Header.SampleRate;
|
||||
Data.SamplesCount = Header.Size / Header.Channels / Header.Bytes;
|
||||
writer.PI64 = 0x40;
|
||||
@@ -198,8 +200,7 @@ namespace KKdSoundLib
|
||||
public int Size;
|
||||
public int SampleRate;
|
||||
public int SamplesCount;
|
||||
public string Name;
|
||||
public ushort Channels;
|
||||
public byte Channels;
|
||||
public byte[] Data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
<Authors>korenkonder</Authors>
|
||||
<Company></Company>
|
||||
<Configuration></Configuration>
|
||||
<Copyright>korenkonder (C) 2019-2021</Copyright>
|
||||
<Description>A simple library for working with Project Diva F/AFT/F2/X/FT audio files</Description>
|
||||
<FileVersion>0.1.2.0</FileVersion>
|
||||
<Copyright>korenkonder (C) 2019-2022</Copyright>
|
||||
<Description>A simple library for working with Project Diva F/AFT/F2/X/XHD/FT/VRFL/M39 audio files</Description>
|
||||
<FileVersion>0.1.2.1</FileVersion>
|
||||
<PackageId>KKdSoundLib</PackageId>
|
||||
<Product>KKdSoundLib</Product>
|
||||
<TargetFramework>net461</TargetFramework>
|
||||
<Title>KKdSoundLib</Title>
|
||||
<Version>0.1.2.0</Version>
|
||||
<Version>0.1.2.1</Version>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
||||
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
|
||||
[assembly: AssemblyVersion("0.4.10.12")]
|
||||
[assembly: AssemblyFileVersion("0.4.10.12")]
|
||||
[assembly: AssemblyVersion("0.4.10.13")]
|
||||
[assembly: AssemblyFileVersion("0.4.10.13")]
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user