Make compiler 1:1
This commit is contained in:
parent
03a84358f0
commit
0bbc504570
Binary file not shown.
|
@ -5,7 +5,6 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace CXMLDecompiler
|
||||
|
@ -74,6 +73,11 @@ namespace CXMLDecompiler
|
|||
}
|
||||
public void GetSilicaTypingInformation(string XmlFileName)
|
||||
{
|
||||
if (XmlFileName.Contains("<!--SilicaTypingInformation{{[[")){
|
||||
Console.WriteLine("XML Does not contain SilicaTypingInformation\nABORTING!");
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
string SearchFor = "<!--SilicaTypingInformation{{[[";
|
||||
string SearchFor2 = "]]}}SilicaTypingInformation-->";
|
||||
string xmlData = File.ReadAllText(XmlFileName);
|
||||
|
@ -104,16 +108,6 @@ namespace CXMLDecompiler
|
|||
public int offset;
|
||||
public int value;
|
||||
}
|
||||
public class IntArrayTableEntry
|
||||
{
|
||||
public int offset;
|
||||
public int[] value;
|
||||
}
|
||||
public class FloatArrayTableEntry
|
||||
{
|
||||
public int offset;
|
||||
public float[] value;
|
||||
}
|
||||
public class StringIDTableEntry
|
||||
{
|
||||
public int offset;
|
||||
|
@ -136,8 +130,8 @@ namespace CXMLDecompiler
|
|||
List<StringTableEntry> StringTableEntries = new List<StringTableEntry>();
|
||||
List<StringTableEntry> CharTableEntries = new List<StringTableEntry>();
|
||||
List<IntTableEntry> HashIdTableEntries = new List<IntTableEntry>();
|
||||
List<IntArrayTableEntry> IntArrayTableEntries = new List<IntArrayTableEntry>();
|
||||
List<FloatArrayTableEntry> FloatArrayTableEntries = new List<FloatArrayTableEntry>();
|
||||
List<Int32> IntArrayTableEntries = new List<Int32>();
|
||||
List<Single> FloatArrayTableEntries = new List<Single>();
|
||||
List<StringTableEntry> FileTableEntries = new List<StringTableEntry>();
|
||||
List<StringIDTableEntry> StringIDTableEntries = new List<StringIDTableEntry>();
|
||||
List<IntIDTableEntry> IntIDTableEntries = new List<IntIDTableEntry>();
|
||||
|
@ -161,9 +155,24 @@ namespace CXMLDecompiler
|
|||
public int AddGetIntIdTable(int value, int loopbackPtr)
|
||||
{
|
||||
foreach (IntIDTableEntry entry in IntIDTableEntries)
|
||||
if (entry.value == value && entry.loopbackOffset == loopbackPtr)
|
||||
return entry.offset;
|
||||
{
|
||||
|
||||
if (entry.loopbackOffset == loopbackPtr && loopbackPtr != -1)
|
||||
{
|
||||
return entry.offset;
|
||||
}
|
||||
else if (entry.value == value)
|
||||
{
|
||||
if (loopbackPtr == -1)
|
||||
return entry.offset;
|
||||
entry.loopbackOffset = loopbackPtr;
|
||||
long position1 = IntIDTable.Position;
|
||||
IntIDTable.Seek(entry.offset, SeekOrigin.Begin);
|
||||
bIntIDTable.Write(loopbackPtr);
|
||||
IntIDTable.Seek(position1, SeekOrigin.Begin);
|
||||
return entry.offset;
|
||||
}
|
||||
}
|
||||
IntIDTableEntry ent = new IntIDTableEntry();
|
||||
ent.value = value;
|
||||
ent.loopbackOffset = loopbackPtr;
|
||||
|
@ -178,19 +187,38 @@ namespace CXMLDecompiler
|
|||
public int AddGetStringIdTable(string value, int loopbackPtr)
|
||||
{
|
||||
foreach (StringIDTableEntry entry in StringIDTableEntries)
|
||||
if (entry.value == value && entry.loopbackOffset == loopbackPtr)
|
||||
{
|
||||
if (entry.loopbackOffset == loopbackPtr && loopbackPtr != -1)
|
||||
{
|
||||
return entry.offset;
|
||||
|
||||
}
|
||||
else if (entry.value == value)
|
||||
{
|
||||
if (loopbackPtr == -1)
|
||||
return entry.offset;
|
||||
entry.loopbackOffset = loopbackPtr;
|
||||
long position1 = StringIDTable.Position;
|
||||
StringIDTable.Seek(entry.offset, SeekOrigin.Begin);
|
||||
bStringIDTable.Write(loopbackPtr);
|
||||
StringIDTable.Seek(position1, SeekOrigin.Begin);
|
||||
return entry.offset;
|
||||
}
|
||||
}
|
||||
StringIDTableEntry ent = new StringIDTableEntry();
|
||||
ent.value = value;
|
||||
ent.loopbackOffset = loopbackPtr;
|
||||
ent.offset = Convert.ToInt32(StringIDTable.Position);
|
||||
StringIDTableEntries.Add(ent);
|
||||
|
||||
bStringIDTable.Write((Int32)loopbackPtr);
|
||||
|
||||
bStringIDTable.Write(loopbackPtr);
|
||||
Tools.WriteStringToStream(StringIDTable, value);
|
||||
StringIDTable.WriteByte(0x00);
|
||||
StringIDTable.WriteByte(0x00);
|
||||
|
||||
|
||||
if (loopbackPtr != -1)
|
||||
{
|
||||
Align(StringIDTable, 4);
|
||||
}
|
||||
|
||||
return ent.offset;
|
||||
}
|
||||
|
@ -207,49 +235,59 @@ namespace CXMLDecompiler
|
|||
FileTableEntries.Add(ent);
|
||||
|
||||
FileTable.Write(value, 0x00, value.Length);
|
||||
int paddingLen = 0x10 - (value.Length % 0x10);
|
||||
byte[] padding = new byte[paddingLen];
|
||||
FileTable.Write(value, 0x00, value.Length);
|
||||
Align(FileTable, 0x10);
|
||||
|
||||
return ent.offset;
|
||||
}
|
||||
public int AddGetFloatArrayTable(float[] value)
|
||||
{
|
||||
foreach (FloatArrayTableEntry entry in FloatArrayTableEntries)
|
||||
if (entry.value.SequenceEqual(value))
|
||||
return entry.offset;
|
||||
|
||||
FloatArrayTableEntry ent = new FloatArrayTableEntry();
|
||||
ent.value = value;
|
||||
ent.offset = Convert.ToInt32(FloatArrayTable.Position);
|
||||
FloatArrayTableEntries.Add(ent);
|
||||
float[] Test = new float[value.Length];
|
||||
float[] TestAgainst = FloatArrayTableEntries.ToArray();
|
||||
for (int i = 0; i < TestAgainst.Length; i += 1)
|
||||
{
|
||||
if (i + value.Length > TestAgainst.Length)
|
||||
break;
|
||||
Array.ConstrainedCopy(TestAgainst, i, Test, 0, value.Length);
|
||||
if(value.SequenceEqual(Test))
|
||||
return i;
|
||||
}
|
||||
int offset = Convert.ToInt32(FloatArrayTable.Position) / 4;
|
||||
|
||||
foreach (float i in value)
|
||||
{
|
||||
bFloatArrayTable.Write((float)i);
|
||||
FloatArrayTableEntries.Add(i);
|
||||
}
|
||||
|
||||
return ent.offset / 4;
|
||||
return offset;
|
||||
}
|
||||
public int AddGetIntArrayTable(int[] value)
|
||||
{
|
||||
foreach (IntArrayTableEntry entry in IntArrayTableEntries)
|
||||
if (entry.value.SequenceEqual(value))
|
||||
return entry.offset;
|
||||
|
||||
IntArrayTableEntry ent = new IntArrayTableEntry();
|
||||
ent.value = value;
|
||||
ent.offset = Convert.ToInt32(IntArrayTable.Position);
|
||||
IntArrayTableEntries.Add(ent);
|
||||
int[] Test = new int[value.Length];
|
||||
int[] TestAgainst = IntArrayTableEntries.ToArray();
|
||||
for (int i = 0; i < TestAgainst.Length; i += 1)
|
||||
{
|
||||
if (i + value.Length > TestAgainst.Length)
|
||||
break;
|
||||
Array.ConstrainedCopy(TestAgainst, i, Test, 0, value.Length);
|
||||
if (value.SequenceEqual(Test))
|
||||
return i;
|
||||
}
|
||||
int offset = Convert.ToInt32(IntArrayTable.Position) / 4;
|
||||
|
||||
foreach (int i in value)
|
||||
{
|
||||
bIntArrayTable.Write((int)i);
|
||||
IntArrayTableEntries.Add(i);
|
||||
}
|
||||
|
||||
return ent.offset/4;
|
||||
return offset;
|
||||
}
|
||||
public int AddGetHashIdTable(int value)
|
||||
{
|
||||
foreach (IntTableEntry entry in HashIdTableEntries)
|
||||
if (entry.value == value)
|
||||
return entry.offset;
|
||||
return entry.offset/4;
|
||||
|
||||
IntTableEntry ent = new IntTableEntry();
|
||||
ent.value = value;
|
||||
|
@ -284,19 +322,19 @@ namespace CXMLDecompiler
|
|||
|
||||
StringTableEntry ent = new StringTableEntry();
|
||||
ent.name = elementName;
|
||||
ent.offset = Convert.ToInt32(CharTable.Position);
|
||||
ent.offset = Convert.ToInt32(CharTable.Position)/2;
|
||||
CharTableEntries.Add(ent);
|
||||
|
||||
Tools.WriteStringToStream(CharTable, elementName);
|
||||
Tools.WriteUtf16StringToStream(CharTable, elementName);
|
||||
CharTable.WriteByte(0x00);
|
||||
CharTable.WriteByte(0x00);
|
||||
|
||||
return ent.offset/2;
|
||||
return ent.offset;
|
||||
}
|
||||
|
||||
public AttributeType DetermineType(string ElementName, string AttributeName) // This is what i was worried about...
|
||||
{
|
||||
return (AttributeType)int.Parse(GetTypingInformation(Tools.GenerateShortHash(Encoding.UTF8.GetBytes(ElementName + AttributeName))));
|
||||
return (AttributeType)int.Parse(GetTypingInformation(ElementName + ":" + AttributeName));
|
||||
}
|
||||
public void WriteAttribute(XmlAttribute attribute, MemoryStream WorkRam, BinaryWriter bWorkRam, string ElementName)
|
||||
{
|
||||
|
@ -328,18 +366,21 @@ namespace CXMLDecompiler
|
|||
int StringLen = attribute.Value.Length;
|
||||
bWorkRam.Write(StringOffset);
|
||||
bWorkRam.Write(StringLen);
|
||||
Console.WriteLine("String: " + attribute.Value);
|
||||
break;
|
||||
case AttributeType.TYPE_CHAR:
|
||||
int CharOffset = AddGetCharTable(attribute.Value);
|
||||
int CharLen = attribute.Value.Length;
|
||||
int CharLen = Encoding.Unicode.GetBytes(attribute.Value).Length;
|
||||
bWorkRam.Write(CharOffset);
|
||||
bWorkRam.Write(CharLen);
|
||||
Console.WriteLine("Char: " + attribute.Value);
|
||||
break;
|
||||
case AttributeType.TYPE_HASH_ID:
|
||||
int HashTableOffset = AddGetHashIdTable(Int32.Parse(attribute.Value, System.Globalization.NumberStyles.HexNumber));
|
||||
int HashTableSize = 4;
|
||||
bWorkRam.Write(HashTableOffset);
|
||||
bWorkRam.Write(HashTableSize);
|
||||
Console.WriteLine("Hash ID Offset:" + HashTableOffset.ToString() + " size: " + HashTableSize);
|
||||
break;
|
||||
case AttributeType.TYPE_INTEGER_ARRAY:
|
||||
string[] arr = attribute.Value.Replace("[", "").Replace("]", "").Replace(" ", "").Split(',');
|
||||
|
@ -352,6 +393,7 @@ namespace CXMLDecompiler
|
|||
bWorkRam.Write(IntArrayOffset);
|
||||
bWorkRam.Write(IntArraySize);
|
||||
|
||||
Console.WriteLine("Int Array: " + attribute.Value);
|
||||
break;
|
||||
case AttributeType.TYPE_FLOAT_ARRAY:
|
||||
arr = attribute.Value.Replace("[", "").Replace("]", "").Replace(" ", "").Replace("f", "").Split(',');
|
||||
|
@ -363,28 +405,37 @@ namespace CXMLDecompiler
|
|||
int FloatArraySize = floatArr.Length;
|
||||
bWorkRam.Write(FloatArrayOffset);
|
||||
bWorkRam.Write(FloatArraySize);
|
||||
|
||||
Console.WriteLine("Float Array: " + attribute.Value);
|
||||
break;
|
||||
case AttributeType.TYPE_FILE:
|
||||
byte[] data = File.ReadAllBytes(Path.Combine(MainDir, attribute.Value));
|
||||
string fPath = Path.Combine(MainDir, attribute.Value);
|
||||
byte[] data = File.ReadAllBytes(fPath);
|
||||
int FilePtr = AddGetFileTable(data);
|
||||
int FileSz = data.Length;
|
||||
bWorkRam.Write(FilePtr);
|
||||
bWorkRam.Write(FileSz);
|
||||
Console.WriteLine("Reading File: " + fPath);
|
||||
break;
|
||||
case AttributeType.TYPE_ID_STRING_LOOPBACK:
|
||||
int StringIdTableOffset = AddGetStringIdTable(attribute.Value, Convert.ToInt32(TreeTable.Position));
|
||||
bWorkRam.Write(StringIdTableOffset);
|
||||
bWorkRam.Write((int)0x00);
|
||||
Console.WriteLine("String Loopback: " + ElementName + " " + TreeTable.Position.ToString("X") + " (" + TreeTable.Position.ToString("X") + ")");
|
||||
Console.WriteLine("Loopback ID String: " + StringIdTableOffset + " sz: 0");
|
||||
break;
|
||||
case AttributeType.TYPE_ID_STRING:
|
||||
StringIdTableOffset = AddGetStringIdTable(attribute.Value, -1);
|
||||
bWorkRam.Write(StringIdTableOffset);
|
||||
bWorkRam.Write((int)0x00);
|
||||
Console.WriteLine("ID String: " + StringIdTableOffset + " sz: 0");
|
||||
break;
|
||||
case AttributeType.TYPE_ID_INT_LOOPBACK:
|
||||
int IntIdTableOffset = AddGetIntIdTable(int.Parse(attribute.Value, System.Globalization.NumberStyles.HexNumber), Convert.ToInt32(TreeTable.Position));
|
||||
bWorkRam.Write(IntIdTableOffset);
|
||||
bWorkRam.Write((int)0x00);
|
||||
Console.WriteLine("Int Loopback: " + ElementName + " " + TreeTable.Position.ToString("X") + " (" + TreeTable.Position.ToString("X") + ")");
|
||||
Console.WriteLine("Loopback ID Int: " + IntIdTableOffset + " sz: 0");
|
||||
break;
|
||||
case AttributeType.TYPE_ID_INT:
|
||||
IntIdTableOffset = AddGetIntIdTable(int.Parse(attribute.Value, System.Globalization.NumberStyles.HexNumber), -1);
|
||||
|
@ -459,6 +510,20 @@ namespace CXMLDecompiler
|
|||
TreeTable.Seek(Position2, SeekOrigin.Begin);
|
||||
}
|
||||
|
||||
public void Align(Stream s, int align)
|
||||
{
|
||||
|
||||
int size = Convert.ToInt32(s.Length);
|
||||
|
||||
if (size % align != 0)
|
||||
{
|
||||
int totalAlign = (align - (size % align));
|
||||
for (int i = 0; i < totalAlign; i++)
|
||||
{
|
||||
s.WriteByte(0x00);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void BuildCXML(string XmlFile, string CxmlFile)
|
||||
{
|
||||
GetSilicaTypingInformation(XmlFile);
|
||||
|
@ -483,46 +548,56 @@ namespace CXMLDecompiler
|
|||
|
||||
int TreeTableOffset = Convert.ToInt32(InfoFile.Position);
|
||||
int TreeTableSize = Convert.ToInt32(TreeTable.Length);
|
||||
Align(TreeTable, 0x10);
|
||||
TreeTable.Seek(0x00, SeekOrigin.Begin);
|
||||
TreeTable.CopyTo(InfoFile);
|
||||
|
||||
|
||||
int StringIdOffset = Convert.ToInt32(InfoFile.Position);
|
||||
int StringIdSize = Convert.ToInt32(StringIDTable.Length);
|
||||
Align(StringIDTable, 0x10);
|
||||
StringIDTable.Seek(0x00, SeekOrigin.Begin);
|
||||
StringIDTable.CopyTo(InfoFile);
|
||||
|
||||
int IntIdOffset = Convert.ToInt32(InfoFile.Position);
|
||||
int IntIdSize = Convert.ToInt32(IntIDTable.Length);
|
||||
Align(IntIDTable, 0x10);
|
||||
IntIDTable.Seek(0x00, SeekOrigin.Begin);
|
||||
IntIDTable.CopyTo(InfoFile);
|
||||
|
||||
int StringTableOffset = Convert.ToInt32(InfoFile.Position);
|
||||
int StringTableSize = Convert.ToInt32(StringTable.Length);
|
||||
Align(StringTable, 0x10);
|
||||
StringTable.Seek(0x00, SeekOrigin.Begin);
|
||||
StringTable.CopyTo(InfoFile);
|
||||
|
||||
int CharTableOffset = Convert.ToInt32(InfoFile.Position);
|
||||
int CharTableSize = Convert.ToInt32(CharTable.Length);
|
||||
Align(CharTable, 0x10);
|
||||
CharTable.Seek(0x00, SeekOrigin.Begin);
|
||||
CharTable.CopyTo(InfoFile);
|
||||
|
||||
int HashIdTableOffset = Convert.ToInt32(InfoFile.Position);
|
||||
int HashIdTableSize = Convert.ToInt32(HashIDTable.Length);
|
||||
Align(HashIDTable, 0x10);
|
||||
HashIDTable.Seek(0x00, SeekOrigin.Begin);
|
||||
HashIDTable.CopyTo(InfoFile);
|
||||
|
||||
int IntArrayTableOffset = Convert.ToInt32(InfoFile.Position);
|
||||
int IntArrayTableSize = Convert.ToInt32(IntArrayTable.Length);
|
||||
Align(IntArrayTable, 0x10);
|
||||
IntArrayTable.Seek(0x00, SeekOrigin.Begin);
|
||||
IntArrayTable.CopyTo(InfoFile);
|
||||
|
||||
int FloatArrayTableOffset = Convert.ToInt32(InfoFile.Position);
|
||||
int FloatArrayTableSize = Convert.ToInt32(FloatArrayTable.Length);
|
||||
Align(FloatArrayTable, 0x10);
|
||||
FloatArrayTable.Seek(0x00, SeekOrigin.Begin);
|
||||
FloatArrayTable.CopyTo(InfoFile);
|
||||
|
||||
int FileTableOffset = Convert.ToInt32(InfoFile.Position);
|
||||
int FileTableSize = Convert.ToInt32(FileTable.Length);
|
||||
Align(FileTable, 0x10);
|
||||
FileTable.Seek(0x00, SeekOrigin.Begin);
|
||||
FileTable.CopyTo(InfoFile);
|
||||
|
||||
|
|
|
@ -55,11 +55,18 @@ namespace CXML
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public class TypingInformation
|
||||
{
|
||||
public string key;
|
||||
public string value;
|
||||
}
|
||||
String MainDir = "";
|
||||
String FileDir = "";
|
||||
String XMLFilename = "";
|
||||
String MagicNumber = "";
|
||||
|
||||
List<TypingInformation> SilicaTypingInformationList = new List<TypingInformation>();
|
||||
|
||||
String SilicaTypingInformation = "SilicaTypingInformation{{[[";
|
||||
FileStream InfoFile;
|
||||
|
||||
|
@ -341,6 +348,22 @@ namespace CXML
|
|||
{
|
||||
return Tools.ReadIntAt(InfoFile, 0x4);
|
||||
}
|
||||
public void AddTypingInfo(string key, object value)
|
||||
{
|
||||
foreach(TypingInformation tInfo in SilicaTypingInformationList)
|
||||
{
|
||||
if(tInfo.key == key)
|
||||
{
|
||||
if (tInfo.value.ToString() != value.ToString())
|
||||
throw new Exception("Fuck.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
TypingInformation typingInfo = new TypingInformation();
|
||||
typingInfo.key = key;
|
||||
typingInfo.value = value.ToString();
|
||||
SilicaTypingInformationList.Add(typingInfo);
|
||||
}
|
||||
public void DecompileCXML(String CXMLFile, bool force = false)
|
||||
{
|
||||
|
||||
|
@ -360,11 +383,23 @@ namespace CXML
|
|||
XMLFile = XmlWriter.Create(XMLPath, XMLSettings);
|
||||
XMLFile.WriteStartDocument();
|
||||
XMLFile.WriteComment("REPLACE_WITH_SILICATOKEN");
|
||||
SilicaTypingInformation += "MAGIC=" + MagicNumber+",VERSION="+ReadVersion();
|
||||
AddTypingInfo("MAGIC", MagicNumber);
|
||||
AddTypingInfo("VERSION", ReadVersion());
|
||||
ReadElements();
|
||||
XMLFile.WriteEndDocument();
|
||||
XMLFile.Flush();
|
||||
XMLFile.Close();
|
||||
|
||||
for(int i = 0; i < SilicaTypingInformationList.Count; i++)
|
||||
{
|
||||
TypingInformation tinfo = SilicaTypingInformationList[i];
|
||||
SilicaTypingInformation += tinfo.key + "=" + tinfo.value;
|
||||
if(i+1 != SilicaTypingInformationList.Count)
|
||||
{
|
||||
SilicaTypingInformation += ",";
|
||||
}
|
||||
}
|
||||
|
||||
SilicaTypingInformation += "]]}}SilicaTypingInformation";
|
||||
|
||||
// Make corrections
|
||||
|
@ -551,6 +586,7 @@ namespace CXML
|
|||
StringTable.Read(StringBytes, 0x00, StringLen);
|
||||
|
||||
AttributeValue = Encoding.UTF8.GetString(StringBytes);
|
||||
Console.WriteLine("String: " + AttributeValue);
|
||||
break;
|
||||
case AttributeType.TYPE_CHAR:
|
||||
int CharOffset = bTreeTable.ReadInt32() * 2;
|
||||
|
@ -561,6 +597,7 @@ namespace CXML
|
|||
CharTable.Read(CharBytes, 0x00, CharLen);
|
||||
|
||||
AttributeValue = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(Encoding.Unicode.GetString(CharBytes)));
|
||||
Console.WriteLine("Char: " + AttributeValue);
|
||||
break;
|
||||
case AttributeType.TYPE_HASH_ID:
|
||||
int HashTableOffset = bTreeTable.ReadInt32();
|
||||
|
@ -587,6 +624,7 @@ namespace CXML
|
|||
}
|
||||
int[] IntArray = IntList.ToArray();
|
||||
AttributeValue = "[" + String.Join(", ", IntArray) + "]";
|
||||
Console.WriteLine("Int Array: " + AttributeValue.ToString());
|
||||
break;
|
||||
case AttributeType.TYPE_FLOAT_ARRAY:
|
||||
int FloatArrayOffset = bTreeTable.ReadInt32();
|
||||
|
@ -602,6 +640,7 @@ namespace CXML
|
|||
}
|
||||
string[] StrArray = StrList.ToArray();
|
||||
AttributeValue = "[" + String.Join(", ", StrArray) + "]";
|
||||
Console.WriteLine("Float Array: " + AttributeValue.ToString());
|
||||
break;
|
||||
case AttributeType.TYPE_FILE:
|
||||
int FilePtr = bTreeTable.ReadInt32();
|
||||
|
@ -626,7 +665,7 @@ namespace CXML
|
|||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("File allready extracted \n(theres a VERY low chance that it acturally is a different file that has the same hash.)");
|
||||
Console.WriteLine("File allready extracted.");
|
||||
}
|
||||
|
||||
string xmlRelPath = FileName.Substring(Tools.GetRootFolder(FileName).Length + 1);
|
||||
|
@ -665,7 +704,7 @@ namespace CXML
|
|||
int IDValue = bIntIDTable.ReadInt32();
|
||||
|
||||
LoopbackAttribute = Tools.ReadStringAt(StringTable, StringPtr);
|
||||
Console.WriteLine("Loopback: " + LoopbackAttribute + " " + LoopbackPtr.ToString("X") + " (" + ElementPtr.ToString("X") + ")");
|
||||
Console.WriteLine("Int Loopback: " + LoopbackAttribute + " " + LoopbackPtr.ToString("X") + " (" + ElementPtr.ToString("X") + ")");
|
||||
|
||||
AttributeValue = IDValue.ToString("X8");
|
||||
ChangeFilename(LoopbackPtr, AttributeValue.ToString(), false);
|
||||
|
@ -686,7 +725,7 @@ namespace CXML
|
|||
break;
|
||||
};
|
||||
|
||||
SilicaTypingInformation += "," + Tools.GenerateShortHash(Encoding.UTF8.GetBytes(ElementName + AttributeName)) + "=" + ((int)Type).ToString();
|
||||
AddTypingInfo(ElementName + ":" + AttributeName, ((int)Type).ToString());
|
||||
Console.WriteLine(AttributeName + "=" + AttributeValue.ToString());
|
||||
XMLFile.WriteAttributeString(AttributeName, AttributeValue.ToString());
|
||||
XMLFile.Flush();
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using CXMLDecompiler;
|
||||
using General;
|
||||
using Ionic.Zlib;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
@ -7,11 +9,22 @@ 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)
|
||||
{
|
||||
|
||||
args = "common_resource\\common_resource.xml common_res.rco -c".Split(' ');
|
||||
// args = "common_resource.rco -d -p".Split(' ');
|
||||
// Do you have gimconv?
|
||||
if (!File.Exists(Path.Combine("GimConv", "GimConv.exe")))
|
||||
GimConv.DownloadGimConv(); // Politely ask sony to give it to us.
|
||||
|
@ -26,6 +39,8 @@ namespace CXMLCli
|
|||
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.");
|
||||
|
@ -37,10 +52,12 @@ namespace CXMLCli
|
|||
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-p --process-files Process Extracted Files");
|
||||
Console.WriteLine("\t-p --process-files Process Extracted Files");
|
||||
Console.WriteLine("\t-w --wait-exit Wait for keypress before exiting");
|
||||
Console.WriteLine("\t-d --decompile Decompile CXML.");
|
||||
Console.WriteLine("Example: " + Path.GetFileName(Assembly.GetEntryAssembly().Location) + " app.info -f -s -t -f -d");
|
||||
Console.WriteLine("\t-d --decompile Decompile CXML to XML.");
|
||||
Console.WriteLine("\t-c --compile Compile XML to CXML");
|
||||
Console.WriteLine("Example Decompile: " + Path.GetFileName(Assembly.GetEntryAssembly().Location) + " app.info -d -dt");
|
||||
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;
|
||||
}
|
||||
|
@ -49,7 +66,7 @@ namespace CXMLCli
|
|||
String path = args[0];
|
||||
|
||||
|
||||
if (ArgsFull.Contains("-iv") || ArgsFull.Contains("--is-vag"))
|
||||
if (HasArg(ArgsFull, "-iv") || HasArg(ArgsFull, "--is-vag"))
|
||||
{
|
||||
byte[] WaveData = VAG.VAGAudio.Vag2Wav(path);
|
||||
string FileName = Path.GetFileNameWithoutExtension(path) + "-" + VAG.VAGAudio.GetFilename(path) + ".wav";
|
||||
|
@ -57,95 +74,121 @@ namespace CXMLCli
|
|||
File.WriteAllBytes(FileName, WaveData);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
CXML.CXMLParser cxmlParser = new CXML.CXMLParser();
|
||||
if(!ArgsFull.Contains("-c") && !ArgsFull.Contains("--compile"))
|
||||
if(!HasArg(ArgsFull, "-c") && !HasArg(ArgsFull, "--compile"))
|
||||
cxmlParser.Init(path, Check);
|
||||
|
||||
if (args.Length == 1)
|
||||
{
|
||||
ArgsFull += "-d -p -w";
|
||||
if (Path.GetExtension(args[0]) == ".xml")
|
||||
ArgsFull += Path.ChangeExtension(args[0], ".cxml") + " -c -w";
|
||||
else
|
||||
ArgsFull += "-d -p -w";
|
||||
}
|
||||
|
||||
if (ArgsFull.Contains("-f") || ArgsFull.Contains("--force"))
|
||||
if (HasArg(ArgsFull, "-f") || HasArg(ArgsFull, "--force"))
|
||||
{
|
||||
Check = false;
|
||||
}
|
||||
|
||||
if (ArgsFull.Contains("-dt") || ArgsFull.Contains("--dump-tables"))
|
||||
if (HasArg(ArgsFull, "-dt") || HasArg(ArgsFull, "--dump-tables"))
|
||||
{
|
||||
ArgsFull += "-tt -ist -iit -st -ct -sit -iat -fat -ft";
|
||||
}
|
||||
|
||||
if (ArgsFull.Contains("-tt") || ArgsFull.Contains("--dump-tree"))
|
||||
if (HasArg(ArgsFull, "-tt") || HasArg(ArgsFull, "--dump-tree"))
|
||||
{
|
||||
Console.WriteLine("Dumping tree table.");
|
||||
File.WriteAllBytes("tree-table.bin", cxmlParser.GetTreeTable());
|
||||
|
||||
}
|
||||
|
||||
if (ArgsFull.Contains("-ist") || ArgsFull.Contains("--dump-string-id"))
|
||||
if (HasArg(ArgsFull, "-ist") || HasArg(ArgsFull, "--dump-string-id"))
|
||||
{
|
||||
Console.WriteLine("Dumping string ID table.");
|
||||
File.WriteAllBytes("string-id-table.bin", cxmlParser.GetStringIDTable());
|
||||
|
||||
}
|
||||
|
||||
if (ArgsFull.Contains("-iit") || ArgsFull.Contains("--dump-int-id"))
|
||||
if (HasArg(ArgsFull, "-iit") || HasArg(ArgsFull, "--dump-int-id"))
|
||||
{
|
||||
Console.WriteLine("Dumping int ID table.");
|
||||
File.WriteAllBytes("int-id-table.bin", cxmlParser.GetIntIDTable());
|
||||
}
|
||||
|
||||
if (ArgsFull.Contains("-st") || ArgsFull.Contains("--dump-string"))
|
||||
if (HasArg(ArgsFull, "-st") || HasArg(ArgsFull, "--dump-string"))
|
||||
{
|
||||
Console.WriteLine("Dumping string table.");
|
||||
File.WriteAllBytes("string-table.bin",cxmlParser.GetStringTable());
|
||||
|
||||
}
|
||||
|
||||
if (ArgsFull.Contains("-ct") || ArgsFull.Contains("--dump-char"))
|
||||
if (HasArg(ArgsFull, "-ct") || HasArg(ArgsFull, "--dump-char"))
|
||||
{
|
||||
Console.WriteLine("Dumping char table.");
|
||||
File.WriteAllBytes("char-table.bin", cxmlParser.GetCharTable());
|
||||
}
|
||||
|
||||
if ((ArgsFull.Contains("-sit") || ArgsFull.Contains("--dump-style-id")) /*kept for backwards comp*/ || (ArgsFull.Contains("-hit") || ArgsFull.Contains("--dump-hash-id")))
|
||||
if ((HasArg(ArgsFull, "-sit") || HasArg(ArgsFull, "--dump-style-id")) /*kept for backwards comp*/ || (HasArg(ArgsFull, "-hit") || HasArg(ArgsFull, "--dump-hash-id")))
|
||||
{
|
||||
Console.WriteLine("Dumping hash ID table.");
|
||||
File.WriteAllBytes("hash-id-table.bin", cxmlParser.GetHashIDTable());
|
||||
}
|
||||
|
||||
|
||||
if (ArgsFull.Contains("-iat") || ArgsFull.Contains("--dump-int-array"))
|
||||
if (HasArg(ArgsFull, "-iat") || HasArg(ArgsFull, "--dump-int-array"))
|
||||
{
|
||||
Console.WriteLine("Dumping int array table.");
|
||||
File.WriteAllBytes("int-array-table.bin", cxmlParser.GetIntArrayTable());
|
||||
}
|
||||
|
||||
if (ArgsFull.Contains("-fat") || ArgsFull.Contains("--dump-float-array"))
|
||||
if (HasArg(ArgsFull, "-fat") || HasArg(ArgsFull, "--dump-float-array"))
|
||||
{
|
||||
Console.WriteLine("Dumping float array table.");
|
||||
File.WriteAllBytes("float-array-table.bin", cxmlParser.GetFloatArrayTable());
|
||||
}
|
||||
|
||||
|
||||
if (ArgsFull.Contains("-ft") || ArgsFull.Contains("--dump-tree"))
|
||||
if (HasArg(ArgsFull, "-ft") || HasArg(ArgsFull, "--dump-tree"))
|
||||
{
|
||||
Console.WriteLine("Dumping file table.");
|
||||
File.WriteAllBytes("file-table.bin", cxmlParser.GetFileTable());
|
||||
}
|
||||
|
||||
if (ArgsFull.Contains("-p") || ArgsFull.Contains("--process-files"))
|
||||
if (HasArg(ArgsFull, "-p") || HasArg(ArgsFull, "--process-files"))
|
||||
{
|
||||
cxmlParser.ProcessFiles = true;
|
||||
}
|
||||
|
||||
if (ArgsFull.Contains("-w") || ArgsFull.Contains("--wait-exit"))
|
||||
if (HasArg(ArgsFull, "-w") || HasArg(ArgsFull, "--wait-exit"))
|
||||
{
|
||||
cxmlParser.WaitExit = true;
|
||||
}
|
||||
|
||||
if (ArgsFull.Contains("-d") || ArgsFull.Contains("--decompile") && !ArgsFull.Contains("-dt"))
|
||||
if (HasArg(ArgsFull, "-d") || HasArg(ArgsFull, "--decompile") && !HasArg(ArgsFull, "-dt"))
|
||||
{
|
||||
Console.WriteLine("Decompiling.");
|
||||
cxmlParser.DecompileCXML(path, Check);
|
||||
|
@ -153,8 +196,7 @@ namespace CXMLCli
|
|||
if(cxmlParser.WaitExit)
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
if (ArgsFull.Contains("-c") || ArgsFull.Contains("--compile"))
|
||||
else if (HasArg(ArgsFull, "-c") || HasArg(ArgsFull, "--compile"))
|
||||
{
|
||||
Console.WriteLine("Compiling.");
|
||||
CXMLBuilder builder = new CXMLBuilder();
|
||||
|
|
|
@ -6,7 +6,6 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace General
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue