From 03a84358f0ea4ceb7b7be1bbdc4b8fd53b8d1e44 Mon Sep 17 00:00:00 2001 From: Bluzume <39113159+KuromeSan@users.noreply.github.com> Date: Fri, 13 Aug 2021 01:28:34 +1200 Subject: [PATCH] Add buggy compiler --- .vs/AppInfoParser/v16/.suo | Bin 79872 -> 90112 bytes AppInfoCli/CXMLBuilder.cs | 484 +++++++++++++++++++++++++++++++++++-- AppInfoCli/CXMLReader.cs | 34 +-- AppInfoCli/GimConv.cs | 2 + AppInfoCli/Program.cs | 18 +- AppInfoCli/Tools.cs | 10 + 6 files changed, 515 insertions(+), 33 deletions(-) diff --git a/.vs/AppInfoParser/v16/.suo b/.vs/AppInfoParser/v16/.suo index f4f1e0e48d46fe8ce1afdbd846786152f7dc1623..616eac256bdd9cbf35d8ac040cfeab66b9f80b0d 100644 GIT binary patch delta 7234 zcmeHL32>A}7XIHHVMzXj+;_+|2{~qx$y}L)2t#IofYBTf)H1TOMILg8ww?B?vPR6H+ba^cmk2hxH0X z48k9wLPQ~`U6?nI!2BUZAR-76i4YMXi0O!UL?|Kv5iSVn!b~KR5h;jZ#2Q2rLXFTN zXaEm0P(<~&1v9rX918m@!eC*4g(0m3s}~_kz0Ig;xera{W&IUVX;&fh8gE6lPlM}_ zUXJ(~q8TOXRwL1ZXhqzJAPMc5cOW_uT?m@(O_;Amu*1r5#Rek2fX*QI%0u=`HUfQ; zlCLr7lcapfAWEbqBlschYXs_hNk*W>@IPmScrpS_of4@@f&$k!3-+(?y9^0pCSjh8 zNI|3`)QB`hI${kxU~vH^1=!sIRIV{Y-%g_zGq6it<7lXF}* z`UilsNL2jj#uQzmqGd$7Bd5SRqYnfEm2m7n+?b`RIX;Yh@&&78_=l+(_ehRVhyQwbYB)#-!_U!DJt|_|d9ihJ>0=DpZ8c1eV`_=q6MhH*d zaQ~*14eOrTv1rb-Rb@Y){X$vP(x;w&cS+IhfB&%h#ILF!#ZDFclm?1%b&}f=*oyoJ ze!m`4f*;D41&^-!sCvd1!-4PH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08a(GDevOJ# z&MKf1Ier>hDND>;P@tNLqtKDl_)Cr?=Wzaf5z{K~vw2kse`CJAB?l z`U8r|r%GvuoLLMfYB5ndc@sU-m#$yGc4JxF#?hkeG|@uK*I29KeSdU->n?g|^j*KI zq6~S(PO~JW#g?Q|vRx&N7`gWtcY0BtDWXdGS`KB>{L#Mas>zTdx8&c^)HwjS<(tJc zS$;ANbH7qTMmfKjo*pe?Iu6-XM8{=EDSaT1PN(d{gSaNi*>30HNadimK5 z*36QTS}GPrsyx#7pQxo0b^nfsXn^F&dK!>7DyRXwq>~TV(+;tIuE}_)T4g-` "; + string SearchFor = ""; string xmlData = File.ReadAllText(XmlFileName); int ind1 = xmlData.IndexOf(SearchFor); - xmlData = xmlData.Substring(ind1+ SearchFor.Length); + xmlData = xmlData.Substring(ind1 + SearchFor.Length); int ind2 = xmlData.IndexOf(SearchFor2); xmlData = xmlData.Substring(0, ind2); - return xmlData; + SilicaTypingInformation = xmlData; } + public string GetTypingInformation(string Key) + { + string[] typeinf = SilicaTypingInformation.Split(','); + foreach(string type in typeinf) + { + string[] keyValuePair = type.Split('='); + if (keyValuePair[0] == Key) + return keyValuePair[1]; + } + return "0"; + } + public class StringTableEntry + { + public int offset; + public string name; + } + public class IntTableEntry + { + 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; + public string value; + public int loopbackOffset; + } + public class IntIDTableEntry + { + public int offset; + public int value; + public int loopbackOffset; + } + + public class TreeTableEntry + { + public int offset; + public XmlNode node; + } + List TreeTableEntries = new List(); + List StringTableEntries = new List(); + List CharTableEntries = new List(); + List HashIdTableEntries = new List(); + List IntArrayTableEntries = new List(); + List FloatArrayTableEntries = new List(); + List FileTableEntries = new List(); + List StringIDTableEntries = new List(); + List IntIDTableEntries = new List(); + public int AddGetTreeTable(XmlNode node) + { + if (!(node.NodeType == XmlNodeType.Element || node.NodeType == XmlNodeType.EndElement || node.NodeType == XmlNodeType.Attribute)) + return -1; + foreach (TreeTableEntry entry in TreeTableEntries) + if (entry.node == node) + return entry.offset; + + TreeTableEntry ent = new TreeTableEntry(); + ent.node = node; + ent.offset = Convert.ToInt32(TreeTable.Position); + TreeTableEntries.Add(ent); + WriteElement(node); + + return ent.offset; + } + + public int AddGetIntIdTable(int value, int loopbackPtr) + { + foreach (IntIDTableEntry entry in IntIDTableEntries) + if (entry.value == value && entry.loopbackOffset == loopbackPtr) + return entry.offset; + + IntIDTableEntry ent = new IntIDTableEntry(); + ent.value = value; + ent.loopbackOffset = loopbackPtr; + ent.offset = Convert.ToInt32(IntIDTable.Position); + IntIDTableEntries.Add(ent); + + bIntIDTable.Write((int)loopbackPtr); + bIntIDTable.Write((int)value); + + return ent.offset; + } + public int AddGetStringIdTable(string value, int loopbackPtr) + { + foreach (StringIDTableEntry entry in StringIDTableEntries) + if (entry.value == value && entry.loopbackOffset == loopbackPtr) + 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); + Tools.WriteStringToStream(StringIDTable, value); + StringIDTable.WriteByte(0x00); + StringIDTable.WriteByte(0x00); + + return ent.offset; + } + public int AddGetFileTable(byte[] value) + { + string v = Tools.GenerateHash(value); + foreach (StringTableEntry entry in FileTableEntries) + if (entry.name == v) + return entry.offset; + + StringTableEntry ent = new StringTableEntry(); + ent.name = v; + ent.offset = Convert.ToInt32(FileTable.Position); + 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); + + 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); + + foreach (float i in value) + bFloatArrayTable.Write((float)i); + + return ent.offset / 4; + } + 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); + + foreach (int i in value) + bIntArrayTable.Write((int)i); + + return ent.offset/4; + } + public int AddGetHashIdTable(int value) + { + foreach (IntTableEntry entry in HashIdTableEntries) + if (entry.value == value) + return entry.offset; + + IntTableEntry ent = new IntTableEntry(); + ent.value = value; + ent.offset = Convert.ToInt32(HashIDTable.Position); + HashIdTableEntries.Add(ent); + + bHashIDTable.Write((int)value); + + return ent.offset/4; + } + public int AddGetStringTable(string elementName) + { + foreach(StringTableEntry entry in StringTableEntries) + if (entry.name == elementName) + return entry.offset; + + StringTableEntry ent = new StringTableEntry(); + ent.name = elementName; + ent.offset = Convert.ToInt32(StringTable.Position); + StringTableEntries.Add(ent); + + Tools.WriteStringToStream(StringTable, elementName); + StringTable.WriteByte(0x00); + + return ent.offset; + } + public int AddGetCharTable(string elementName) + { + foreach (StringTableEntry entry in CharTableEntries) + if (entry.name == elementName) + return entry.offset; + + StringTableEntry ent = new StringTableEntry(); + ent.name = elementName; + ent.offset = Convert.ToInt32(CharTable.Position); + CharTableEntries.Add(ent); + + Tools.WriteStringToStream(CharTable, elementName); + CharTable.WriteByte(0x00); + CharTable.WriteByte(0x00); + + return ent.offset/2; + } + + 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)))); + } + public void WriteAttribute(XmlAttribute attribute, MemoryStream WorkRam, BinaryWriter bWorkRam, string ElementName) + { + int AttributePtr = AddGetStringTable(attribute.Name); + AttributeType Type = DetermineType(ElementName, attribute.Name); + bWorkRam.Write(AttributePtr); + bWorkRam.Write((int)Type); + Console.WriteLine("AttributeType: " + Type.ToString()); + switch (Type) + { + case AttributeType.TYPE_NONE: + Console.WriteLine("UNSUPPORTED TYPE @ " + TreeTable.Position); + Console.ReadKey(); + break; + case AttributeType.TYPE_INT: + int intWrite = Int32.Parse(attribute.Value); + bWorkRam.Write((int)intWrite); + bWorkRam.Write((int)0x00); + Console.WriteLine("Int - Value: " + intWrite.ToString()); + break; + case AttributeType.TYPE_FLOAT: + float FloatValue = Single.Parse(attribute.Value.Substring(0, attribute.Value.Length - 1)); + bWorkRam.Write((float)FloatValue); + bWorkRam.Write((int)0x00); + Console.WriteLine("Float - Value: " + FloatValue.ToString()); + break; + case AttributeType.TYPE_STRING: + int StringOffset = AddGetStringTable(attribute.Value); + int StringLen = attribute.Value.Length; + bWorkRam.Write(StringOffset); + bWorkRam.Write(StringLen); + break; + case AttributeType.TYPE_CHAR: + int CharOffset = AddGetCharTable(attribute.Value); + int CharLen = attribute.Value.Length; + bWorkRam.Write(CharOffset); + bWorkRam.Write(CharLen); + 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); + break; + case AttributeType.TYPE_INTEGER_ARRAY: + string[] arr = attribute.Value.Replace("[", "").Replace("]", "").Replace(" ", "").Split(','); + int[] intArr = new int[arr.Length]; + for (int i = 0; i < intArr.Length; i++) + intArr[i] = int.Parse(arr[i]); + + int IntArrayOffset = AddGetIntArrayTable(intArr); + int IntArraySize = intArr.Length; + bWorkRam.Write(IntArrayOffset); + bWorkRam.Write(IntArraySize); + + break; + case AttributeType.TYPE_FLOAT_ARRAY: + arr = attribute.Value.Replace("[", "").Replace("]", "").Replace(" ", "").Replace("f", "").Split(','); + float[] floatArr = new float[arr.Length]; + for (int i = 0; i < floatArr.Length; i++) + floatArr[i] = float.Parse(arr[i]); + + int FloatArrayOffset = AddGetFloatArrayTable(floatArr); + int FloatArraySize = floatArr.Length; + bWorkRam.Write(FloatArrayOffset); + bWorkRam.Write(FloatArraySize); + break; + case AttributeType.TYPE_FILE: + byte[] data = File.ReadAllBytes(Path.Combine(MainDir, attribute.Value)); + int FilePtr = AddGetFileTable(data); + int FileSz = data.Length; + bWorkRam.Write(FilePtr); + bWorkRam.Write(FileSz); + break; + case AttributeType.TYPE_ID_STRING_LOOPBACK: + int StringIdTableOffset = AddGetStringIdTable(attribute.Value, Convert.ToInt32(TreeTable.Position)); + bWorkRam.Write(StringIdTableOffset); + bWorkRam.Write((int)0x00); + break; + case AttributeType.TYPE_ID_STRING: + StringIdTableOffset = AddGetStringIdTable(attribute.Value, -1); + bWorkRam.Write(StringIdTableOffset); + bWorkRam.Write((int)0x00); + 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); + break; + case AttributeType.TYPE_ID_INT: + IntIdTableOffset = AddGetIntIdTable(int.Parse(attribute.Value, System.Globalization.NumberStyles.HexNumber), -1); + bWorkRam.Write(IntIdTableOffset); + bWorkRam.Write((int)0x00); + break; + default: + Console.WriteLine("UNKNOWN TYPE @ " + TreeTable.Position); + Console.ReadKey(); + break; + } + } + public void WriteElement(XmlNode node) + { + MemoryStream WorkRam = new MemoryStream(); + BinaryWriter bWorkRam = new BinaryWriter(WorkRam); + int ElementPtr = AddGetStringTable(node.Name); + int NumAttributes = 0; + int ParentPtr = -1; + int PrevSibling = -1; + int NextSibling = -1; + + int FirstChild = -1; + int LastChild = -1; + long Position = TreeTable.Position; + bWorkRam.Write(ElementPtr); + bWorkRam.Write(NumAttributes); + bWorkRam.Write(ParentPtr); + bWorkRam.Write(PrevSibling); + bWorkRam.Write(NextSibling); + bWorkRam.Write(FirstChild); + bWorkRam.Write(LastChild); + + foreach (XmlAttribute attribute in node.Attributes) + { + WriteAttribute(attribute, WorkRam, bWorkRam, node.Name); + } + + + WorkRam.Seek(0x00, SeekOrigin.Begin); + WorkRam.CopyTo(TreeTable); + + foreach (XmlNode childNode in node.ChildNodes) + { + if(childNode != null) + AddGetTreeTable(childNode); + } + // Rewrite header now + + if (node.Attributes != null) + NumAttributes = node.Attributes.Count; + if (node.ParentNode != null) + ParentPtr = AddGetTreeTable(node.ParentNode); + if (node.PreviousSibling != null) + PrevSibling = AddGetTreeTable(node.PreviousSibling); + if (node.NextSibling != null) + NextSibling = AddGetTreeTable(node.NextSibling); + if (node.FirstChild != null) + FirstChild = AddGetTreeTable(node.FirstChild); + if (node.LastChild != null) + LastChild = AddGetTreeTable(node.LastChild); + + long Position2 = TreeTable.Position; + TreeTable.Seek(Position, SeekOrigin.Begin); + bTreeTable.Write(ElementPtr); + bTreeTable.Write(NumAttributes); + bTreeTable.Write(ParentPtr); + bTreeTable.Write(PrevSibling); + bTreeTable.Write(NextSibling); + bTreeTable.Write(FirstChild); + bTreeTable.Write(LastChild); + TreeTable.Seek(Position2, SeekOrigin.Begin); + } + public void BuildCXML(string XmlFile, string CxmlFile) { - string Magic = DetectMagic(XmlFile); + GetSilicaTypingInformation(XmlFile); + string Magic = GetTypingInformation("MAGIC"); + int Version = int.Parse(GetTypingInformation("VERSION")); Console.WriteLine("Magic Number: " + Magic); + Console.WriteLine("Version: " + Version.ToString("X")); if (!IsInitalized) - Init(XmlFile, XmlFile, "RCOF"); - - XmlReaderSettings XMLSettings = new XmlReaderSettings(); - string XMLPath = Path.Combine(MainDir, XMLFilename); - XMLFile = XmlReader.Create(XMLPath, XMLSettings); + Init(XmlFile, CxmlFile, Magic); + XmlDocument XMLFile = new XmlDocument(); + XMLFile.Load(XmlFile); Tools.WriteStringToStream(InfoFile, Magic); - bInfoFile.Write((UInt32)0x0110); + bInfoFile.Write((Int32)Version); + byte[] headerPlaceholder = new byte[0x48]; + InfoFile.Write(headerPlaceholder, 0x00, headerPlaceholder.Length); + + foreach(XmlNode childNode in XMLFile.ChildNodes) + { + AddGetTreeTable(childNode); + } + + int TreeTableOffset = Convert.ToInt32(InfoFile.Position); + int TreeTableSize = Convert.ToInt32(TreeTable.Length); + TreeTable.Seek(0x00, SeekOrigin.Begin); + TreeTable.CopyTo(InfoFile); + + int StringIdOffset = Convert.ToInt32(InfoFile.Position); + int StringIdSize = Convert.ToInt32(StringIDTable.Length); + StringIDTable.Seek(0x00, SeekOrigin.Begin); + StringIDTable.CopyTo(InfoFile); + + int IntIdOffset = Convert.ToInt32(InfoFile.Position); + int IntIdSize = Convert.ToInt32(IntIDTable.Length); + IntIDTable.Seek(0x00, SeekOrigin.Begin); + IntIDTable.CopyTo(InfoFile); + + int StringTableOffset = Convert.ToInt32(InfoFile.Position); + int StringTableSize = Convert.ToInt32(StringTable.Length); + StringTable.Seek(0x00, SeekOrigin.Begin); + StringTable.CopyTo(InfoFile); + + int CharTableOffset = Convert.ToInt32(InfoFile.Position); + int CharTableSize = Convert.ToInt32(CharTable.Length); + CharTable.Seek(0x00, SeekOrigin.Begin); + CharTable.CopyTo(InfoFile); + + int HashIdTableOffset = Convert.ToInt32(InfoFile.Position); + int HashIdTableSize = Convert.ToInt32(HashIDTable.Length); + HashIDTable.Seek(0x00, SeekOrigin.Begin); + HashIDTable.CopyTo(InfoFile); + + int IntArrayTableOffset = Convert.ToInt32(InfoFile.Position); + int IntArrayTableSize = Convert.ToInt32(IntArrayTable.Length); + IntArrayTable.Seek(0x00, SeekOrigin.Begin); + IntArrayTable.CopyTo(InfoFile); + + int FloatArrayTableOffset = Convert.ToInt32(InfoFile.Position); + int FloatArrayTableSize = Convert.ToInt32(FloatArrayTable.Length); + FloatArrayTable.Seek(0x00, SeekOrigin.Begin); + FloatArrayTable.CopyTo(InfoFile); + + int FileTableOffset = Convert.ToInt32(InfoFile.Position); + int FileTableSize = Convert.ToInt32(FileTable.Length); + FileTable.Seek(0x00, SeekOrigin.Begin); + FileTable.CopyTo(InfoFile); + + InfoFile.Seek(0x8, SeekOrigin.Begin); + bInfoFile.Write(TreeTableOffset); + bInfoFile.Write(TreeTableSize); + bInfoFile.Write(StringIdOffset); + bInfoFile.Write(StringIdSize); + bInfoFile.Write(IntIdOffset); + bInfoFile.Write(IntIdSize); + bInfoFile.Write(StringTableOffset); + bInfoFile.Write(StringTableSize); + bInfoFile.Write(CharTableOffset); + bInfoFile.Write(CharTableSize); + bInfoFile.Write(HashIdTableOffset); + bInfoFile.Write(HashIdTableSize); + bInfoFile.Write(IntArrayTableOffset); + bInfoFile.Write(IntArrayTableSize); + bInfoFile.Write(FloatArrayTableOffset); + bInfoFile.Write(FloatArrayTableSize); + bInfoFile.Write(FileTableOffset); + bInfoFile.Write(FileTableSize); + + InfoFile.Close(); } } diff --git a/AppInfoCli/CXMLReader.cs b/AppInfoCli/CXMLReader.cs index 21a6d14..a6a5624 100644 --- a/AppInfoCli/CXMLReader.cs +++ b/AppInfoCli/CXMLReader.cs @@ -60,7 +60,7 @@ namespace CXML String FileDir = ""; String XMLFilename = ""; String MagicNumber = ""; - + String SilicaTypingInformation = "SilicaTypingInformation{{[["; FileStream InfoFile; MemoryStream TreeTable; @@ -359,16 +359,17 @@ namespace CXML string XMLPath = Path.Combine(MainDir, XMLFilename); XMLFile = XmlWriter.Create(XMLPath, XMLSettings); XMLFile.WriteStartDocument(); - XMLFile.WriteComment("Decompiled with CXML Decompiler v6 By SilicaAndPina (Magic: \"" + MagicNumber + "\", Version: \""+ ReadVersion()+"\")"); - + XMLFile.WriteComment("REPLACE_WITH_SILICATOKEN"); + SilicaTypingInformation += "MAGIC=" + MagicNumber+",VERSION="+ReadVersion(); ReadElements(); - XMLFile.WriteEndDocument(); XMLFile.Flush(); XMLFile.Close(); + SilicaTypingInformation += "]]}}SilicaTypingInformation"; // Make corrections string XmlData = File.ReadAllText(XMLPath, Encoding.UTF8); + XmlData = XmlData.Replace("REPLACE_WITH_SILICATOKEN", SilicaTypingInformation); foreach(LoopbackHandler lpHandler in FileList) { if(lpHandler.OldFileName != null) @@ -569,7 +570,7 @@ namespace CXML int HashId = bHashIDTable.ReadInt32(); - AttributeValue = "@"+HashId.ToString("X8"); + AttributeValue = HashId.ToString("X8"); break; case AttributeType.TYPE_INTEGER_ARRAY: @@ -644,11 +645,15 @@ namespace CXML AttributeValue = Tools.ReadString(StringIDTable); ChangeFilename(LoopbackPtr, AttributeValue.ToString(), false); - Console.WriteLine("Loopback String: " + StringIdTableOffset + " sz: " + bTreeTable.ReadInt32()); + Console.WriteLine("Loopback ID String: " + StringIdTableOffset + " sz: " + bTreeTable.ReadInt32()); break; - case AttributeType.TYPE_ID_STRING: - Console.WriteLine("UNSUPPORTED TYPE @ " + TreeTable.Position); - Console.ReadKey(); + case AttributeType.TYPE_ID_STRING: // This is probably right, tbh + StringIdTableOffset = bTreeTable.ReadInt32(); + StringIDTable.Seek(StringIdTableOffset + 4, SeekOrigin.Begin); + + AttributeValue = Tools.ReadString(StringIDTable); + + Console.WriteLine("ID String: " + StringIdTableOffset + " sz: " + bTreeTable.ReadInt32()); break; case AttributeType.TYPE_ID_INT_LOOPBACK: int IntIdTableOffset = bTreeTable.ReadInt32(); @@ -662,8 +667,8 @@ namespace CXML LoopbackAttribute = Tools.ReadStringAt(StringTable, StringPtr); Console.WriteLine("Loopback: " + LoopbackAttribute + " " + LoopbackPtr.ToString("X") + " (" + ElementPtr.ToString("X") + ")"); - AttributeValue = "$"+IDValue.ToString("X8"); - ChangeFilename(LoopbackPtr, IDValue.ToString("X8"), false); + AttributeValue = IDValue.ToString("X8"); + ChangeFilename(LoopbackPtr, AttributeValue.ToString(), false); Console.WriteLine("Loopback Int: " + IntIdTableOffset + " sz: " + bTreeTable.ReadInt32()); break; @@ -672,15 +677,16 @@ namespace CXML IntIDTable.Seek(IntIdTableOffset + 4, SeekOrigin.Begin); IDValue = bIntIDTable.ReadInt32(); - AttributeValue = "#"+IDValue.ToString("X8"); + AttributeValue = IDValue.ToString("X8"); Console.WriteLine("Int Id: " + IntIdTableOffset + " sz: " + bTreeTable.ReadInt32()); break; default: Console.WriteLine("UNKNOWN TYPE @ " + TreeTable.Position); + Console.ReadKey(); break; }; - + SilicaTypingInformation += "," + Tools.GenerateShortHash(Encoding.UTF8.GetBytes(ElementName + AttributeName)) + "=" + ((int)Type).ToString(); Console.WriteLine(AttributeName + "=" + AttributeValue.ToString()); XMLFile.WriteAttributeString(AttributeName, AttributeValue.ToString()); XMLFile.Flush(); @@ -739,4 +745,4 @@ namespace CXML } } -} +}; diff --git a/AppInfoCli/GimConv.cs b/AppInfoCli/GimConv.cs index 2bb85d2..8d3ce37 100644 --- a/AppInfoCli/GimConv.cs +++ b/AppInfoCli/GimConv.cs @@ -24,6 +24,8 @@ namespace CXMLDecompiler private static void Wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { + if (e.Error != null) + return; Console.Write("\r\n"); MemoryStream zipStream = new MemoryStream(e.Result); ZipFile zip = ZipFile.Read(zipStream); diff --git a/AppInfoCli/Program.cs b/AppInfoCli/Program.cs index 578b671..f0e1d88 100644 --- a/AppInfoCli/Program.cs +++ b/AppInfoCli/Program.cs @@ -1,5 +1,4 @@ using CXMLDecompiler; -using General; using System; using System.IO; using System.Reflection; @@ -11,6 +10,8 @@ namespace CXMLCli 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. @@ -57,7 +58,8 @@ namespace CXMLCli return 0; } CXML.CXMLParser cxmlParser = new CXML.CXMLParser(); - cxmlParser.Init(path, Check); + if(!ArgsFull.Contains("-c") && !ArgsFull.Contains("--compile")) + cxmlParser.Init(path, Check); if (args.Length == 1) { @@ -130,7 +132,7 @@ namespace CXMLCli if (ArgsFull.Contains("-ft") || ArgsFull.Contains("--dump-tree")) { Console.WriteLine("Dumping file table."); - File.WriteAllBytes("file-table.bin", cxmlParser.GetTreeTable()); + File.WriteAllBytes("file-table.bin", cxmlParser.GetFileTable()); } if (ArgsFull.Contains("-p") || ArgsFull.Contains("--process-files")) @@ -152,6 +154,16 @@ namespace CXMLCli Console.ReadKey(); } + if (ArgsFull.Contains("-c") || ArgsFull.Contains("--compile")) + { + Console.WriteLine("Compiling."); + CXMLBuilder builder = new CXMLBuilder(); + builder.BuildCXML(path, args[1]); + Console.WriteLine("\n\nCOMPILATION COMPLETE!"); + if (cxmlParser.WaitExit) + Console.ReadKey(); + } + return 0; } } diff --git a/AppInfoCli/Tools.cs b/AppInfoCli/Tools.cs index 727bc02..78f618f 100644 --- a/AppInfoCli/Tools.cs +++ b/AppInfoCli/Tools.cs @@ -18,6 +18,11 @@ namespace General Byte[] bytes = Encoding.UTF8.GetBytes(str); s.Write(bytes, 0x00, bytes.Length); } + public static void WriteUtf16StringToStream(Stream s, String str) + { + Byte[] bytes = Encoding.Unicode.GetBytes(str); + s.Write(bytes, 0x00, bytes.Length); + } public static MemoryStream ByteToStream(byte[] Array) { MemoryStream ms = new MemoryStream(); @@ -252,6 +257,11 @@ namespace General return BitConverter.ToString(ShaBytes).Replace("-", "").ToUpper(); } + public static string GenerateShortHash(byte[] Data) + { + return GenerateHash(Data).Substring(0, 8); + } + public static String ReadString(Stream ms, int limit = -1) { int i = 0xFF;