2021-08-11 15:11:05 +00:00
using CXMLDecompiler ;
2021-08-13 04:44:47 +00:00
using General ;
using Ionic.Zlib ;
2019-05-06 12:53:11 +00:00
using System ;
2019-04-27 14:43:27 +00:00
using System.IO ;
2019-04-28 18:32:20 +00:00
using System.Reflection ;
2019-04-27 14:43:27 +00:00
2019-05-03 20:18:55 +00:00
namespace CXMLCli
2019-04-27 14:43:27 +00:00
{
class Program
{
2021-08-13 04:44:47 +00:00
static bool HasArg ( string argsfull , string argcheck )
{
string [ ] args = argsfull . Split ( ' ' ) ;
foreach ( string arg in args )
{
if ( arg = = argcheck )
{
return true ;
}
}
return false ;
}
2021-08-11 15:11:05 +00:00
static int Main ( string [ ] args )
2019-04-27 14:43:27 +00:00
{
2021-08-11 15:11:05 +00:00
// Do you have gimconv?
if ( ! File . Exists ( Path . Combine ( "GimConv" , "GimConv.exe" ) ) )
GimConv . DownloadGimConv ( ) ; // Politely ask sony to give it to us.
2019-05-07 14:06:18 +00:00
2019-05-03 20:18:55 +00:00
bool Check = true ;
2019-04-28 18:32:20 +00:00
if ( args . Length = = 0 )
{
Console . WriteLine ( "-- app.info/CXML Decompiler --" ) ;
Console . WriteLine ( "I like to see girls die :3" ) ;
Console . WriteLine ( "Required Arguments:" ) ;
2019-05-06 12:53:11 +00:00
Console . WriteLine ( "\t<input_filename>" ) ;
2019-04-28 18:32:20 +00:00
Console . WriteLine ( "Optional Arguments:" ) ;
2019-05-06 12:53:11 +00:00
Console . WriteLine ( "\t-iv --is-vag File is HE-VAG audio and NOT CXML" ) ;
2021-08-13 04:44:47 +00:00
Console . WriteLine ( "\t-dc --decompress Decompress .Z File" ) ;
Console . WriteLine ( "\t-cc --compress Compress back to .Z File" ) ;
2019-05-03 20:18:55 +00:00
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-ist --dump-string-id Dump string ID table." ) ;
Console . WriteLine ( "\t-iit --dump-int-id Dump int ID table." ) ;
Console . WriteLine ( "\t-st --dump-string Dump string table." ) ;
Console . WriteLine ( "\t-ct --dump-char Dump char table." ) ;
2020-09-04 04:18:56 +00:00
Console . WriteLine ( "\t-hit --dump-hash-id Dump hash ID table." ) ;
2019-05-03 20:18:55 +00:00
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." ) ;
2021-08-13 04:44:47 +00:00
Console . WriteLine ( "\t-p --process-files Process Extracted Files" ) ;
2021-08-17 12:08:11 +00:00
Console . WriteLine ( "\t-nr --no-recursive Do not recursively decompile .RCS to XML" ) ;
2021-08-11 09:30:50 +00:00
Console . WriteLine ( "\t-w --wait-exit Wait for keypress before exiting" ) ;
2021-08-13 04:44:47 +00:00
Console . WriteLine ( "\t-d --decompile Decompile CXML to XML." ) ;
Console . WriteLine ( "\t-c --compile Compile XML to CXML" ) ;
2021-08-13 18:18:59 +00:00
Console . WriteLine ( "\t-h --hash-string When Compiling, Generate new hashes" ) ;
2021-08-13 15:38:57 +00:00
Console . WriteLine ( "Example Decompile: " + Path . GetFileName ( Assembly . GetEntryAssembly ( ) . Location ) + " app.info -d -p" ) ;
2021-08-13 04:44:47 +00:00
Console . WriteLine ( "Example Compile: " + Path . GetFileName ( Assembly . GetEntryAssembly ( ) . Location ) + " app.xml app.info -c" ) ;
2021-08-11 13:03:30 +00:00
Console . WriteLine ( "Default functonality is to Decompile,\nThis is canceled if any other arguments passed." ) ;
2021-08-11 15:11:05 +00:00
return 0 ;
2019-04-28 18:32:20 +00:00
}
2019-04-27 14:43:27 +00:00
2019-04-28 18:32:20 +00:00
String ArgsFull = String . Join ( " " , args ) ;
String path = args [ 0 ] ;
2019-05-06 12:53:11 +00:00
2021-08-13 15:35:39 +00:00
if ( args . Length = = 1 )
{
ArgsFull + = " -d -p -w" ;
}
2019-05-06 12:53:11 +00:00
2021-08-13 04:44:47 +00:00
if ( HasArg ( ArgsFull , "-iv" ) | | HasArg ( ArgsFull , "--is-vag" ) )
2019-05-06 12:53:11 +00:00
{
byte [ ] WaveData = VAG . VAGAudio . Vag2Wav ( path ) ;
string FileName = Path . GetFileNameWithoutExtension ( path ) + "-" + VAG . VAGAudio . GetFilename ( path ) + ".wav" ;
Console . WriteLine ( "Writing " + FileName ) ;
File . WriteAllBytes ( FileName , WaveData ) ;
2021-08-11 15:11:05 +00:00
return 0 ;
2019-05-06 12:53:11 +00:00
}
2021-08-13 04:44:47 +00:00
if ( HasArg ( ArgsFull , "-dc" ) | | HasArg ( ArgsFull , "--decompress" ) )
{
Console . WriteLine ( "Decompressing " + path ) ;
Byte [ ] FileData = File . ReadAllBytes ( path ) ;
Byte [ ] DecompressedData = ZlibStream . UncompressBuffer ( FileData ) ;
string Extension = Tools . GetFileExtension ( DecompressedData ) ;
string OutPath = Path . ChangeExtension ( path , Extension ) ;
File . WriteAllBytes ( OutPath , DecompressedData ) ;
return 0 ;
}
if ( HasArg ( ArgsFull , "-cc" ) | | HasArg ( ArgsFull , "--compress" ) )
{
Console . WriteLine ( "Compressing " + path ) ;
Byte [ ] FileData = File . ReadAllBytes ( path ) ;
Byte [ ] CompressedData = ZlibStream . CompressBuffer ( FileData ) ;
string Extension = Tools . GetFileExtension ( CompressedData ) ;
string OutPath = Path . ChangeExtension ( path , Extension ) ;
File . WriteAllBytes ( OutPath , CompressedData ) ;
return 0 ;
}
2021-08-11 09:30:50 +00:00
CXML . CXMLParser cxmlParser = new CXML . CXMLParser ( ) ;
2021-08-13 04:44:47 +00:00
if ( ! HasArg ( ArgsFull , "-c" ) & & ! HasArg ( ArgsFull , "--compile" ) )
2021-08-11 09:30:50 +00:00
{
2021-08-13 15:35:39 +00:00
Console . WriteLine ( "Initalizing: " + path ) ;
cxmlParser . Init ( path , Check ) ;
2021-08-11 09:30:50 +00:00
}
2019-05-06 12:53:11 +00:00
2021-08-13 15:35:39 +00:00
2021-08-13 04:44:47 +00:00
if ( HasArg ( ArgsFull , "-f" ) | | HasArg ( ArgsFull , "--force" ) )
2019-04-27 14:43:27 +00:00
{
2019-04-28 18:32:20 +00:00
Check = false ;
2019-04-27 14:43:27 +00:00
}
2019-04-28 18:32:20 +00:00
2021-08-13 04:44:47 +00:00
if ( HasArg ( ArgsFull , "-dt" ) | | HasArg ( ArgsFull , "--dump-tables" ) )
2019-05-03 20:18:55 +00:00
{
2021-08-13 15:35:39 +00:00
ArgsFull + = " -tt -ist -iit -st -ct -sit -iat -fat -ft" ;
2019-05-03 20:18:55 +00:00
}
2021-08-13 04:44:47 +00:00
if ( HasArg ( ArgsFull , "-tt" ) | | HasArg ( ArgsFull , "--dump-tree" ) )
2019-05-03 20:18:55 +00:00
{
Console . WriteLine ( "Dumping tree table." ) ;
2021-08-11 09:30:50 +00:00
File . WriteAllBytes ( "tree-table.bin" , cxmlParser . GetTreeTable ( ) ) ;
2019-05-03 20:18:55 +00:00
}
2021-08-13 04:44:47 +00:00
if ( HasArg ( ArgsFull , "-ist" ) | | HasArg ( ArgsFull , "--dump-string-id" ) )
2019-05-03 20:18:55 +00:00
{
Console . WriteLine ( "Dumping string ID table." ) ;
2021-08-11 09:30:50 +00:00
File . WriteAllBytes ( "string-id-table.bin" , cxmlParser . GetStringIDTable ( ) ) ;
2019-05-03 20:18:55 +00:00
}
2021-08-13 04:44:47 +00:00
if ( HasArg ( ArgsFull , "-iit" ) | | HasArg ( ArgsFull , "--dump-int-id" ) )
2019-05-03 20:18:55 +00:00
{
Console . WriteLine ( "Dumping int ID table." ) ;
2021-08-11 09:30:50 +00:00
File . WriteAllBytes ( "int-id-table.bin" , cxmlParser . GetIntIDTable ( ) ) ;
2019-05-03 20:18:55 +00:00
}
2019-04-28 18:32:20 +00:00
2021-08-13 04:44:47 +00:00
if ( HasArg ( ArgsFull , "-st" ) | | HasArg ( ArgsFull , "--dump-string" ) )
2019-04-27 14:43:27 +00:00
{
2019-04-28 18:32:20 +00:00
Console . WriteLine ( "Dumping string table." ) ;
2021-08-11 09:30:50 +00:00
File . WriteAllBytes ( "string-table.bin" , cxmlParser . GetStringTable ( ) ) ;
2019-04-28 18:32:20 +00:00
2019-04-27 14:43:27 +00:00
}
2021-08-13 04:44:47 +00:00
if ( HasArg ( ArgsFull , "-ct" ) | | HasArg ( ArgsFull , "--dump-char" ) )
2019-05-03 20:18:55 +00:00
{
Console . WriteLine ( "Dumping char table." ) ;
2021-08-11 09:30:50 +00:00
File . WriteAllBytes ( "char-table.bin" , cxmlParser . GetCharTable ( ) ) ;
2019-05-03 20:18:55 +00:00
}
2019-04-27 14:43:27 +00:00
2021-08-13 04:44:47 +00:00
if ( ( HasArg ( ArgsFull , "-sit" ) | | HasArg ( ArgsFull , "--dump-style-id" ) ) /*kept for backwards comp*/ | | ( HasArg ( ArgsFull , "-hit" ) | | HasArg ( ArgsFull , "--dump-hash-id" ) ) )
2019-04-28 18:32:20 +00:00
{
2020-09-04 04:18:56 +00:00
Console . WriteLine ( "Dumping hash ID table." ) ;
2021-08-11 09:30:50 +00:00
File . WriteAllBytes ( "hash-id-table.bin" , cxmlParser . GetHashIDTable ( ) ) ;
2019-05-03 20:18:55 +00:00
}
2021-08-13 04:44:47 +00:00
if ( HasArg ( ArgsFull , "-iat" ) | | HasArg ( ArgsFull , "--dump-int-array" ) )
2019-05-03 20:18:55 +00:00
{
Console . WriteLine ( "Dumping int array table." ) ;
2021-08-11 09:30:50 +00:00
File . WriteAllBytes ( "int-array-table.bin" , cxmlParser . GetIntArrayTable ( ) ) ;
2019-04-28 18:32:20 +00:00
}
2021-08-13 04:44:47 +00:00
if ( HasArg ( ArgsFull , "-fat" ) | | HasArg ( ArgsFull , "--dump-float-array" ) )
2019-05-03 20:18:55 +00:00
{
Console . WriteLine ( "Dumping float array table." ) ;
2021-08-11 09:30:50 +00:00
File . WriteAllBytes ( "float-array-table.bin" , cxmlParser . GetFloatArrayTable ( ) ) ;
2019-05-03 20:18:55 +00:00
}
2021-08-13 04:44:47 +00:00
if ( HasArg ( ArgsFull , "-ft" ) | | HasArg ( ArgsFull , "--dump-tree" ) )
2019-04-28 18:32:20 +00:00
{
Console . WriteLine ( "Dumping file table." ) ;
2021-08-12 13:28:34 +00:00
File . WriteAllBytes ( "file-table.bin" , cxmlParser . GetFileTable ( ) ) ;
2021-08-11 09:30:50 +00:00
}
2021-08-13 04:44:47 +00:00
if ( HasArg ( ArgsFull , "-p" ) | | HasArg ( ArgsFull , "--process-files" ) )
2021-08-11 09:30:50 +00:00
{
cxmlParser . ProcessFiles = true ;
}
2021-08-13 04:44:47 +00:00
if ( HasArg ( ArgsFull , "-w" ) | | HasArg ( ArgsFull , "--wait-exit" ) )
2021-08-11 09:30:50 +00:00
{
cxmlParser . WaitExit = true ;
2019-04-28 18:32:20 +00:00
}
2021-08-17 12:08:11 +00:00
if ( HasArg ( ArgsFull , "-nr" ) | | HasArg ( ArgsFull , "--no-recursive" ) )
{
cxmlParser . NoRecursive = true ;
}
2019-04-27 14:43:27 +00:00
2021-08-13 04:44:47 +00:00
if ( HasArg ( ArgsFull , "-d" ) | | HasArg ( ArgsFull , "--decompile" ) & & ! HasArg ( ArgsFull , "-dt" ) )
2019-04-28 18:32:20 +00:00
{
Console . WriteLine ( "Decompiling." ) ;
2021-08-11 09:30:50 +00:00
cxmlParser . DecompileCXML ( path , Check ) ;
2019-05-03 20:18:55 +00:00
Console . WriteLine ( "\n\nDECOMPILATION COMPLETE!" ) ;
2021-08-11 09:30:50 +00:00
if ( cxmlParser . WaitExit )
Console . ReadKey ( ) ;
2019-04-28 18:32:20 +00:00
}
2021-08-13 04:44:47 +00:00
else if ( HasArg ( ArgsFull , "-c" ) | | HasArg ( ArgsFull , "--compile" ) )
2021-08-12 13:28:34 +00:00
{
2021-08-13 15:35:39 +00:00
Console . WriteLine ( "Compiling: " + path ) ;
2021-08-12 13:28:34 +00:00
CXMLBuilder builder = new CXMLBuilder ( ) ;
2021-08-13 18:18:59 +00:00
if ( HasArg ( ArgsFull , "-h" ) | | HasArg ( ArgsFull , "----hash-string" ) )
builder . HashStrings = true ;
2021-08-13 04:59:34 +00:00
builder . Init ( path , args [ 1 ] ) ;
2021-08-12 13:28:34 +00:00
builder . BuildCXML ( path , args [ 1 ] ) ;
Console . WriteLine ( "\n\nCOMPILATION COMPLETE!" ) ;
if ( cxmlParser . WaitExit )
Console . ReadKey ( ) ;
}
2021-08-11 13:03:30 +00:00
return 0 ;
2019-04-27 14:43:27 +00:00
}
}
}