260 lines
11 KiB
C#
260 lines
11 KiB
C#
using CXMLDecompiler;
|
|
using General;
|
|
using Ionic.Zlib;
|
|
using System;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
|
|
namespace CXMLCli
|
|
{
|
|
class Program
|
|
{
|
|
static bool HasArg(string argsfull, string argcheck)
|
|
{
|
|
string[] args = argsfull.Split(' ');
|
|
foreach(string arg in args)
|
|
{
|
|
if(arg == argcheck)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
static int Main(string[] args)
|
|
{
|
|
|
|
// Do you have gimconv?
|
|
|
|
bool windowsNT = Environment.OSVersion.Platform.Equals(PlatformID.Win32NT);
|
|
bool windows32 = Environment.OSVersion.Platform.Equals(PlatformID.Win32Windows);
|
|
bool windows32S = Environment.OSVersion.Platform.Equals(PlatformID.Win32S);
|
|
bool windowsCE = Environment.OSVersion.Platform.Equals(PlatformID.WinCE);
|
|
|
|
if (windowsNT || windows32 || windows32S || windowsCE)
|
|
{
|
|
if (!File.Exists(Path.Combine("GimConv", "GimConv.exe")))
|
|
{
|
|
GimConv.DownloadGimConv(); // Politely ask sony to give it to us.
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("NOTE: GimConv is windows binary, so you cant use it on this OS!\n.GIM Decoding will be disabled!");
|
|
}
|
|
|
|
bool Check = true;
|
|
|
|
if (args.Length == 0)
|
|
{
|
|
Console.WriteLine("-- CXML Decompiler --");
|
|
Console.WriteLine("Required Arguments:");
|
|
Console.WriteLine("\t<input_filename>");
|
|
Console.WriteLine("Optional Arguments:");
|
|
Console.WriteLine("\t-iv --is-vag File is HE-VAG audio and NOT CXML");
|
|
Console.WriteLine("\t-dc --decompress Decompress .Z File");
|
|
Console.WriteLine("\t-cc --compress Compress back to .Z File");
|
|
Console.WriteLine("\t-f --force Dont check magic number.");
|
|
Console.WriteLine("\t-dt --dump-tables Dump ALL tables.");
|
|
Console.WriteLine("\t-tt --dump-tree Dump tree table.");
|
|
Console.WriteLine("\t-idt --dump-id Dump id ID table.");
|
|
Console.WriteLine("\t-iht --dump-hash-id Dump hash ID table.");
|
|
Console.WriteLine("\t-st --dump-string Dump string table.");
|
|
Console.WriteLine("\t-wt --dump-wstring Dump wstring table.");
|
|
Console.WriteLine("\t-ht --dump-hash Dump hash table.");
|
|
Console.WriteLine("\t-iat --dump-int-array Dump int array table.");
|
|
Console.WriteLine("\t-fat --dump-float-array Dump float array table.");
|
|
Console.WriteLine("\t-ft --dump-file Dump file table.");
|
|
Console.WriteLine("\t-le --little-endian Decode ints as Little Endian");
|
|
Console.WriteLine("\t-be --big-endian Decode ints as Big Endian");
|
|
Console.WriteLine("\t-ps3 --playstation-3 Use the old CXML Format used back on PS3.");
|
|
Console.WriteLine("\t-p --process-files Process Extracted Files");
|
|
Console.WriteLine("\t-nr --no-recursive Do not recursively decompile .RCS to XML");
|
|
Console.WriteLine("\t-w --wait-exit Wait for keypress before exiting");
|
|
Console.WriteLine("\t-d --decompile Decompile CXML to XML.");
|
|
Console.WriteLine("\t-c --compile Compile XML to CXML");
|
|
Console.WriteLine("\t-h --hash-string When Compiling, Generate new hashes");
|
|
Console.WriteLine("Example Decompile: " + Path.GetFileName(Assembly.GetEntryAssembly().Location) + " app.info -d -p");
|
|
Console.WriteLine("Example Compile: " + Path.GetFileName(Assembly.GetEntryAssembly().Location) + " app.xml app.info -c");
|
|
Console.WriteLine("Default functonality is to Decompile,\nThis is canceled if any other arguments passed.");
|
|
return 0;
|
|
}
|
|
|
|
String ArgsFull = String.Join(" ", args);
|
|
String ProcessFilePath = args[0];
|
|
|
|
bool ForcePs3 = false;
|
|
Endianness FileEndianness = Endianness.UNCHANGED;
|
|
|
|
if (args.Length == 1)
|
|
{
|
|
ArgsFull += " -d -p -w";
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-le") || HasArg(ArgsFull, "--little-endian"))
|
|
{
|
|
FileEndianness = Endianness.LITTLE_ENDIAN;
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-be") || HasArg(ArgsFull, "--big-endian"))
|
|
{
|
|
FileEndianness = Endianness.LITTLE_ENDIAN;
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-ps3") || HasArg(ArgsFull, "--playstation-3"))
|
|
{
|
|
ForcePs3 = true;
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-iv") || HasArg(ArgsFull, "--is-vag"))
|
|
{
|
|
byte[] WaveData = VAG.VAGAudio.Vag2Wav(ProcessFilePath);
|
|
string FileName = Path.GetFileNameWithoutExtension(ProcessFilePath) + "-" + VAG.VAGAudio.GetFilename(ProcessFilePath) + ".wav";
|
|
Console.WriteLine("Writing "+FileName);
|
|
File.WriteAllBytes(FileName, WaveData);
|
|
return 0;
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-f") || HasArg(ArgsFull, "--force"))
|
|
{
|
|
Check = false;
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-dc") || HasArg(ArgsFull, "--decompress"))
|
|
{
|
|
Console.WriteLine("Decompressing " + ProcessFilePath);
|
|
Byte[] FileData = File.ReadAllBytes(ProcessFilePath);
|
|
Byte[] DecompressedData = ZlibStream.UncompressBuffer(FileData);
|
|
string Extension = Tools.GetFileExtension(DecompressedData);
|
|
string OutPath = Path.ChangeExtension(ProcessFilePath, Extension);
|
|
File.WriteAllBytes(OutPath, DecompressedData);
|
|
return 0;
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-cc") || HasArg(ArgsFull, "--compress"))
|
|
{
|
|
Console.WriteLine("Compressing " + ProcessFilePath);
|
|
Byte[] FileData = File.ReadAllBytes(ProcessFilePath);
|
|
Byte[] CompressedData = ZlibStream.CompressBuffer(FileData);
|
|
string Extension = Tools.GetFileExtension(CompressedData);
|
|
string OutPath = Path.ChangeExtension(ProcessFilePath, Extension);
|
|
File.WriteAllBytes(OutPath, CompressedData);
|
|
return 0;
|
|
}
|
|
|
|
CXMLReader cxmlParser = new CXMLReader();
|
|
if(!HasArg(ArgsFull, "-c") && !HasArg(ArgsFull, "--compile"))
|
|
{
|
|
Console.WriteLine("Initalizing: " + ProcessFilePath);
|
|
cxmlParser.Init(ProcessFilePath, Check, ForcePs3, FileEndianness);
|
|
}
|
|
|
|
|
|
|
|
if (HasArg(ArgsFull, "-dt") || HasArg(ArgsFull, "--dump-tables"))
|
|
{
|
|
ArgsFull += " --dump-tree --dump-id --dump-hash-id --dump-string --dump-wstring --dump-hash --dump-int-array --dump-float-array --dump-file ";
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-tt") || HasArg(ArgsFull, "--dump-tree"))
|
|
{
|
|
Console.WriteLine("Dumping tree table.");
|
|
File.WriteAllBytes("tree-table.bin", cxmlParser.GetTreeTable());
|
|
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-idt") || HasArg(ArgsFull, "--dump-id"))
|
|
{
|
|
Console.WriteLine("Dumping ID table.");
|
|
File.WriteAllBytes("id-table.bin", cxmlParser.GetIDTable());
|
|
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-iht") || HasArg(ArgsFull, "--dump-hash-id"))
|
|
{
|
|
Console.WriteLine("Dumping hash ID table.");
|
|
File.WriteAllBytes("hash-id-table.bin", cxmlParser.GetHashIDTable());
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-st") || HasArg(ArgsFull, "--dump-string"))
|
|
{
|
|
Console.WriteLine("Dumping string table.");
|
|
File.WriteAllBytes("string-table.bin",cxmlParser.GetStringTable());
|
|
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-wt") || HasArg(ArgsFull, "--dump-wstring"))
|
|
{
|
|
Console.WriteLine("Dumping wstring table.");
|
|
File.WriteAllBytes("wstring-table.bin", cxmlParser.GetWStringTable());
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-ht") || HasArg(ArgsFull, "--dump-hash"))
|
|
{
|
|
Console.WriteLine("Dumping hash table.");
|
|
File.WriteAllBytes("hash-table.bin", cxmlParser.GetHashTable());
|
|
}
|
|
|
|
|
|
if (HasArg(ArgsFull, "-iat") || HasArg(ArgsFull, "--dump-int-array"))
|
|
{
|
|
Console.WriteLine("Dumping int array table.");
|
|
File.WriteAllBytes("int-array-table.bin", cxmlParser.GetIntArrayTable());
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-fat") || HasArg(ArgsFull, "--dump-float-array"))
|
|
{
|
|
Console.WriteLine("Dumping float array table.");
|
|
File.WriteAllBytes("float-array-table.bin", cxmlParser.GetFloatArrayTable());
|
|
}
|
|
|
|
|
|
if (HasArg(ArgsFull, "-ft") || HasArg(ArgsFull, "--dump-tree"))
|
|
{
|
|
Console.WriteLine("Dumping file table.");
|
|
File.WriteAllBytes("file-table.bin", cxmlParser.GetFileTable());
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-p") || HasArg(ArgsFull, "--process-files"))
|
|
{
|
|
cxmlParser.ProcessFiles = true;
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-w") || HasArg(ArgsFull, "--wait-exit"))
|
|
{
|
|
cxmlParser.WaitExit = true;
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-nr") || HasArg(ArgsFull, "--no-recursive"))
|
|
{
|
|
cxmlParser.NoRecursive = true;
|
|
}
|
|
|
|
if (HasArg(ArgsFull, "-d") || HasArg(ArgsFull, "--decompile") && !HasArg(ArgsFull, "-dt"))
|
|
{
|
|
Console.WriteLine("Decompiling.");
|
|
cxmlParser.DecompileCXML(ProcessFilePath);
|
|
Console.WriteLine("\n\nDECOMPILATION COMPLETE!");
|
|
if(cxmlParser.WaitExit)
|
|
Console.ReadKey();
|
|
}
|
|
else if (HasArg(ArgsFull, "-c") || HasArg(ArgsFull, "--compile"))
|
|
{
|
|
Console.WriteLine("Compiling: " + ProcessFilePath);
|
|
CXMLBuilder builder = new CXMLBuilder();
|
|
if (HasArg(ArgsFull, "-h") || HasArg(ArgsFull, "----hash-string"))
|
|
builder.HashStrings = true;
|
|
|
|
builder.Init(ProcessFilePath, args[1]);
|
|
builder.BuildCXML(ProcessFilePath, args[1]);
|
|
Console.WriteLine("\n\nCOMPILATION COMPLETE!");
|
|
if (cxmlParser.WaitExit)
|
|
Console.ReadKey();
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
}
|