Skip to content

Commit

Permalink
Release v0.4.10.19
Browse files Browse the repository at this point in the history
  • Loading branch information
korenkonder committed Nov 21, 2023
1 parent 3c13856 commit b66b3b0
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 42 deletions.
167 changes: 130 additions & 37 deletions KKdMainLib/FARC.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//Original: https://github.com/blueskythlikesclouds/MikuMikuLibrary/

using System.IO.Compression;
using System.Security.Cryptography;
using KKdBaseLib;
using KKdMainLib.IO;
Expand Down Expand Up @@ -139,7 +138,17 @@ public bool HeaderReader()
file.Size = reader.RI32E(true);
Flags Flags = (Flags)reader.RI32E(true);

file.Compressed = file.Size != 0 || (FARCFlags & Flags.GZip) != 0;
if (file.Size != 0)
{
file.Compressed = (FARCFlags & Flags.GZip) != 0;
}
else
{
file.Size = file.SizeComp;
file.SizeComp = 0;
file.Compressed = false;
}

file.Encrypted = ((FARCFlags | Flags) & Flags.AES) != 0;
Files.Add(file);
}
Expand All @@ -152,8 +161,18 @@ public bool HeaderReader()
file.SizeComp = reader.RI32E(true);
file.Size = reader.RI32E(true);

file.Compressed = file.Size != 0;
file.Encrypted = (FARCFlags & Flags.AES) != 0;
if (file.Size != 0)
{
file.Compressed = true;
}
else
{
file.Size = file.SizeComp;
file.SizeComp = 0;
file.Compressed = false;
}

file.Encrypted = false;
Files.Add(file);
}
else
Expand Down Expand Up @@ -227,10 +246,18 @@ public byte[] FileReader(int i, bool saveToDisk, ref Stream reader)
}
else if (Signature == Farc.FArC)
{
file.DataComp = reader.RBy(file.SizeComp);
file.Data = file.DataComp.InflateGZip(file.Size);
if (file.Compressed)
{
file.DataComp = reader.RBy(file.SizeComp);
file.Data = file.DataComp.InflateGZip(file.Size);
}
else
{
file.DataComp = null;
file.Data = reader.RBy(file.Size);
}
}
else if (file.Encrypted || file.Compressed)
else if (file.Compressed || file.Encrypted)
{
int tempSize = file.Encrypted ? file.SizeComp.A(0x10) : file.SizeComp;

Expand Down Expand Up @@ -266,15 +293,15 @@ public byte[] FileReader(int i, bool saveToDisk, ref Stream reader)
else
temp = reader.RBy(tempSize);

if (!file.Compressed)
if (file.Compressed)
{
file.DataComp = null;
file.Data = temp;
file.DataComp = temp;
file.Data = file.DataComp.InflateGZip(file.Size);
}
else
{
file.DataComp = temp;
file.Data = file.DataComp.InflateGZip(file.Size);
file.DataComp = null;
file.Data = temp;
}
}
else
Expand All @@ -294,15 +321,33 @@ public byte[] FileReader(int i, bool saveToDisk, ref Stream reader)
return Files[i].Data;
}

public void Pack(Farc signature = Farc.FArC)
public void Pack()
{
NewFARC();
string[] files = Directory.GetFiles(DirectoryPath);
Files.Capacity = files.Length;

bool compressed = false;
bool encrypted = false;
switch (Signature)
{
case Farc.FARC:
compressed = (FARCFlags & Flags.GZip) != 0;
encrypted = (FARCFlags & Flags.AES) != 0;
break;
case Farc.FArC:
FARCFlags = Flags.None;
compressed = true;
break;
default:
FARCFlags = Flags.None;
break;
}

for (int i = 0; i < files.Length; i++)
Files.Add(new FARCFile { Name = Path.GetFileName(files[i]), Data = File.ReadAllBytes(files[i]) });
Files.Add(new FARCFile { Name = Path.GetFileName(files[i]),
Data = File.ReadAllBytes(files[i]), Compressed = compressed, Encrypted = encrypted });
files = null;
Signature = signature;
Save();
}

Expand All @@ -322,22 +367,28 @@ public void Save()

using (Stream headerWriter = File.OpenWriter())
{
if (Signature == Farc.FArc) headerWriter.WE(0x01, true);
else if (Signature == Farc.FArC) headerWriter.WE(0x01, true);
else if (Signature == Farc.FARC)
switch (Signature)
{
headerWriter.WE((int)FARCFlags, true);
headerWriter.W (0x00);
headerWriter.WE(0x40, true);
headerWriter.W (0x00);
headerWriter.W (0x00);
case Farc.FArc:
headerWriter.WE(0x01, true);
for (int i = 0; i < Files.Count; i++)
{ headerWriter.W(Files[i].Name + "\0"); headerWriter.W(0x00L); }
break;
case Farc.FArC:
headerWriter.WE(0x01, true);
for (int i = 0; i < Files.Count; i++)
{ headerWriter.W(Files[i].Name + "\0"); headerWriter.W(0x00L); headerWriter.W(0x00); }
break;
case Farc.FARC:
headerWriter.WE((int)FARCFlags, true);
headerWriter.W (0x00);
headerWriter.WE(0x40, true);
headerWriter.W (0x00);
headerWriter.W (0x00);
for (int i = 0; i < Files.Count; i++)
{ headerWriter.W(Files[i].Name + "\0"); headerWriter.W(0x00L); headerWriter.W(0x00L); }
break;
}
if (Signature != Farc.FArc)
for (int i = 0; i < Files.Count; i++)
{ headerWriter.W(Files[i].Name + "\0"); headerWriter.W(0x00L); headerWriter.W(0x00); }
else
for (int i = 0; i < Files.Count; i++)
{ headerWriter.W(Files[i].Name + "\0"); headerWriter.W(0x00L); }
writer.WE(headerWriter.L, true);
writer.W (headerWriter.ToArray(true));
}
Expand All @@ -351,13 +402,55 @@ public void Save()
CompressStuff(i, ref writer);

writer.P = Signature == Farc.FARC ? 0x1C : 0x0C;
for (int i = 0; i < Files.Count; i++)
switch (Signature)
{
FARCFile file = Files[i];
writer.W (file.Name + "\0");
writer.WE(file.Offset, true);
if (Signature != Farc.FArc) writer.WE(file.SizeComp, true);
writer.WE(file.Size, true);
case Farc.FArc:
for (int i = 0; i < Files.Count; i++)
{
FARCFile file = Files[i];
writer.W (file.Name + "\0");
writer.WE(file.Offset, true);
writer.WE(file.Size , true);
}
break;
case Farc.FArC:
for (int i = 0; i < Files.Count; i++)
{
FARCFile file = Files[i];
writer.W (file.Name + "\0");
writer.WE(file.Offset , true);
if (file.Compressed)
{
writer.WE(file.SizeComp, true);
writer.WE(file.Size , true);
}
else
{
writer.WE(file.Size , true);
writer.WE(0x00 , true);
}
}
break;
case Farc.FARC:
for (int i = 0; i < Files.Count; i++)
{
FARCFile file = Files[i];
writer.W (file.Name + "\0");
writer.WE(file.Offset , true);
if (file.Compressed)
{
writer.WE(file.SizeComp, true);
writer.WE(file.Size , true);
}
else
{
writer.WE(file.Size , true);
writer.WE(0x00 , true);
}
writer.WE((uint)((file.Compressed ? Flags.GZip : 0x00)
| (file.Encrypted ? Flags.AES : 0x00)), true);
}
break;
}
writer.Dispose();
}
Expand All @@ -369,11 +462,11 @@ private void CompressStuff(int i, ref Stream writer)
file.Size = file.Data.Length;

byte[] data = file.Data;
if (Signature == Farc.FArC || (Signature == Farc.FARC && (FARCFlags & Flags.GZip) != 0))
if (file.Compressed)
data = file.Data.DeflateGZip(CompressionLevel);
file.SizeComp = data.Length;

if (Signature == Farc.FARC && (FARCFlags & Flags.AES) != 0)
if (file.Encrypted)
{
int alignLength = data.Length.A(0x40);
byte[] tempData = new byte[alignLength];
Expand Down
4 changes: 2 additions & 2 deletions KKdMainLib/KKdMainLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
<Configuration></Configuration>
<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.18</FileVersion>
<FileVersion>0.4.10.19</FileVersion>
<PackageId>KKdMainLib</PackageId>
<Product>KKdMainLib</Product>
<TargetFramework>net461</TargetFramework>
<Title>KKdMainLib</Title>
<Version>0.4.10.18</Version>
<Version>0.4.10.19</Version>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
4 changes: 2 additions & 2 deletions PD_Tool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("7B5D5A3A-A6F8-4813-C97D-ACFC98F7397E")]
[assembly: AssemblyVersion("0.4.10.18")]
[assembly: AssemblyFileVersion("0.4.10.18")]
[assembly: AssemblyVersion("0.4.10.19")]
[assembly: AssemblyFileVersion("0.4.10.19")]
2 changes: 1 addition & 1 deletion PD_Tool/classes/FARC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void Processor(bool extract)
}
else if (choose == "R") return;
else farc.Signature = KKdFARC.Farc.FArC;
farc.Pack(farc.Signature);
farc.Pack();
}
}
}
Expand Down

0 comments on commit b66b3b0

Please sign in to comment.