Add buggy compiler
This commit is contained in:
parent
9905b383ec
commit
03a84358f0
Binary file not shown.
|
@ -1,4 +1,5 @@
|
|||
using General;
|
||||
using CXML;
|
||||
using General;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
@ -38,12 +39,12 @@ namespace CXMLDecompiler
|
|||
BinaryWriter bHashIDTable;
|
||||
BinaryWriter bStringIDTable;
|
||||
|
||||
XmlReader XMLFile;
|
||||
|
||||
String SilicaTypingInformation = "";
|
||||
public void Init(string XMLFile, string CxmlFile, string Magic)
|
||||
{
|
||||
MagicNumber = Magic;
|
||||
InfoFile = File.Open(CxmlFile, FileMode.CreateNew, FileAccess.ReadWrite);
|
||||
InfoFile = File.Open(CxmlFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
|
||||
InfoFile.SetLength(0);
|
||||
|
||||
TreeTable = new MemoryStream();
|
||||
StringIDTable = new MemoryStream();
|
||||
|
@ -71,30 +72,481 @@ namespace CXMLDecompiler
|
|||
|
||||
return;
|
||||
}
|
||||
public string DetectMagic(string XmlFileName)
|
||||
public void GetSilicaTypingInformation(string XmlFileName)
|
||||
{
|
||||
string SearchFor = "<!--Decompiled with CXML Decompiler v6 By SilicaAndPina (Magic: \"";
|
||||
string SearchFor2 = "\")--> ";
|
||||
string SearchFor = "<!--SilicaTypingInformation{{[[";
|
||||
string SearchFor2 = "]]}}SilicaTypingInformation-->";
|
||||
string xmlData = File.ReadAllText(XmlFileName);
|
||||
int ind1 = xmlData.IndexOf(SearchFor);
|
||||
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<TreeTableEntry> TreeTableEntries = new List<TreeTableEntry>();
|
||||
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<StringTableEntry> FileTableEntries = new List<StringTableEntry>();
|
||||
List<StringIDTableEntry> StringIDTableEntries = new List<StringIDTableEntry>();
|
||||
List<IntIDTableEntry> IntIDTableEntries = new List<IntIDTableEntry>();
|
||||
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();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
|||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,6 +58,7 @@ namespace CXMLCli
|
|||
return 0;
|
||||
}
|
||||
CXML.CXMLParser cxmlParser = new CXML.CXMLParser();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue