Fix bugs
This commit is contained in:
parent
6ac1d92efc
commit
9e0ca58fbe
Binary file not shown.
|
@ -224,15 +224,14 @@ namespace CXMLDecompiler
|
||||||
|
|
||||||
return ent.offset;
|
return ent.offset;
|
||||||
}
|
}
|
||||||
public int AddGetFileTable(byte[] value)
|
public int AddGetFileTable(byte[] value, string filename)
|
||||||
{
|
{
|
||||||
string v = Tools.GenerateHash(value);
|
|
||||||
foreach (StringTableEntry entry in FileTableEntries)
|
foreach (StringTableEntry entry in FileTableEntries)
|
||||||
if (entry.name == v)
|
if (entry.name == filename)
|
||||||
return entry.offset;
|
return entry.offset;
|
||||||
|
|
||||||
StringTableEntry ent = new StringTableEntry();
|
StringTableEntry ent = new StringTableEntry();
|
||||||
ent.name = v;
|
ent.name = filename;
|
||||||
ent.offset = Convert.ToInt32(FileTable.Position);
|
ent.offset = Convert.ToInt32(FileTable.Position);
|
||||||
FileTableEntries.Add(ent);
|
FileTableEntries.Add(ent);
|
||||||
|
|
||||||
|
@ -365,7 +364,7 @@ namespace CXMLDecompiler
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_STRING:
|
case AttributeType.TYPE_STRING:
|
||||||
int StringOffset = AddGetStringTable(attribute.Value);
|
int StringOffset = AddGetStringTable(attribute.Value);
|
||||||
int StringLen = attribute.Value.Length;
|
int StringLen = Encoding.UTF8.GetBytes(attribute.Value).Length;
|
||||||
bWorkRam.Write(StringOffset);
|
bWorkRam.Write(StringOffset);
|
||||||
bWorkRam.Write(StringLen);
|
bWorkRam.Write(StringLen);
|
||||||
Console.WriteLine("String: " + attribute.Value);
|
Console.WriteLine("String: " + attribute.Value);
|
||||||
|
@ -413,7 +412,7 @@ namespace CXMLDecompiler
|
||||||
case AttributeType.TYPE_FILE:
|
case AttributeType.TYPE_FILE:
|
||||||
string fPath = Path.Combine(MainDir, attribute.Value);
|
string fPath = Path.Combine(MainDir, attribute.Value);
|
||||||
byte[] data = File.ReadAllBytes(fPath);
|
byte[] data = File.ReadAllBytes(fPath);
|
||||||
int FilePtr = AddGetFileTable(data);
|
int FilePtr = AddGetFileTable(data, Path.Combine(Environment.CurrentDirectory, fPath));
|
||||||
int FileSz = data.Length;
|
int FileSz = data.Length;
|
||||||
bWorkRam.Write(FilePtr);
|
bWorkRam.Write(FilePtr);
|
||||||
bWorkRam.Write(FileSz);
|
bWorkRam.Write(FileSz);
|
||||||
|
|
|
@ -355,7 +355,7 @@ namespace CXML
|
||||||
if(tInfo.key == key)
|
if(tInfo.key == key)
|
||||||
{
|
{
|
||||||
if (tInfo.value.ToString() != value.ToString())
|
if (tInfo.value.ToString() != value.ToString())
|
||||||
throw new Exception("Fuck.");
|
throw new Exception("Very Weird CXML");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -415,19 +415,23 @@ namespace CXML
|
||||||
string extension = Path.GetExtension(oldName);
|
string extension = Path.GetExtension(oldName);
|
||||||
string folderPath = Path.GetDirectoryName(oldName);
|
string folderPath = Path.GetDirectoryName(oldName);
|
||||||
string newPath = Path.ChangeExtension(Path.Combine(folderPath, lpHandler.FileName), extension);
|
string newPath = Path.ChangeExtension(Path.Combine(folderPath, lpHandler.FileName), extension);
|
||||||
File.Move(oldName, newPath);
|
|
||||||
|
if(!File.Exists(newPath))
|
||||||
|
{
|
||||||
|
File.Move(oldName, newPath);
|
||||||
|
|
||||||
string xmlRelOldPath = oldName.Substring(Tools.GetRootFolder(oldName).Length + 1);
|
string xmlRelOldPath = oldName.Substring(Tools.GetRootFolder(oldName).Length + 1);
|
||||||
string xmlRelNewPath = newPath.Substring(Tools.GetRootFolder(newPath).Length + 1);
|
string xmlRelNewPath = newPath.Substring(Tools.GetRootFolder(newPath).Length + 1);
|
||||||
Console.WriteLine("Moved " + xmlRelOldPath + " => " + xmlRelNewPath);
|
Console.WriteLine("Moved " + xmlRelOldPath + " => " + xmlRelNewPath);
|
||||||
XmlData = XmlData.Replace(xmlRelOldPath, xmlRelNewPath);
|
XmlData = XmlData.Replace(xmlRelOldPath, xmlRelNewPath);
|
||||||
|
}
|
||||||
|
|
||||||
if (ProcessFiles)
|
if (ProcessFiles)
|
||||||
ProcessFile(newPath);
|
ProcessFile(newPath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("Generated Filename used for " + lpHandler.OldFileName);
|
Console.WriteLine("NOT MOVING: " + lpHandler.OldFileName);
|
||||||
if (ProcessFiles)
|
if (ProcessFiles)
|
||||||
ProcessFile(lpHandler.OldFileName);
|
ProcessFile(lpHandler.OldFileName);
|
||||||
}
|
}
|
||||||
|
@ -517,7 +521,7 @@ namespace CXML
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChangeFilename(Int64 ElementPtr, String NewName, Boolean FileEntry)
|
public void RegisterFile(Int64 ElementPtr, String NewName, Boolean FileEntry, String IdealName=null)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Adding Entry for Loopback: 0x" + ElementPtr.ToString("X8") + " (" + NewName + ")");
|
Console.WriteLine("Adding Entry for Loopback: 0x" + ElementPtr.ToString("X8") + " (" + NewName + ")");
|
||||||
for(int i = 0; i < FileList.Count; i++)
|
for(int i = 0; i < FileList.Count; i++)
|
||||||
|
@ -529,6 +533,7 @@ namespace CXML
|
||||||
if (FileList[i].OldFileName != null)
|
if (FileList[i].OldFileName != null)
|
||||||
break;
|
break;
|
||||||
FileList[i].OldFileName = NewName;
|
FileList[i].OldFileName = NewName;
|
||||||
|
FileList[i].FileName = IdealName;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -543,6 +548,7 @@ namespace CXML
|
||||||
if (FileEntry)
|
if (FileEntry)
|
||||||
{
|
{
|
||||||
lpHandler.OldFileName = NewName;
|
lpHandler.OldFileName = NewName;
|
||||||
|
lpHandler.FileName = IdealName;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -574,7 +580,7 @@ namespace CXML
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_FLOAT:
|
case AttributeType.TYPE_FLOAT:
|
||||||
float FloatValue = bTreeTable.ReadSingle();
|
float FloatValue = bTreeTable.ReadSingle();
|
||||||
AttributeValue = FloatValue.ToString()+"f";
|
AttributeValue = ((double)FloatValue).ToString() + "f";
|
||||||
Console.WriteLine("Float - Value: " + AttributeValue.ToString() + " sz:" + bTreeTable.ReadInt32());
|
Console.WriteLine("Float - Value: " + AttributeValue.ToString() + " sz:" + bTreeTable.ReadInt32());
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_STRING:
|
case AttributeType.TYPE_STRING:
|
||||||
|
@ -636,7 +642,7 @@ namespace CXML
|
||||||
for(int i = 0; i < FloatArraySize; i++)
|
for(int i = 0; i < FloatArraySize; i++)
|
||||||
{
|
{
|
||||||
FloatValue = bFloatArrayTable.ReadSingle();
|
FloatValue = bFloatArrayTable.ReadSingle();
|
||||||
StrList.Add(FloatValue.ToString()+"f");
|
StrList.Add(((double)FloatValue).ToString() +"f");
|
||||||
}
|
}
|
||||||
string[] StrArray = StrList.ToArray();
|
string[] StrArray = StrList.ToArray();
|
||||||
AttributeValue = "[" + String.Join(", ", StrArray) + "]";
|
AttributeValue = "[" + String.Join(", ", StrArray) + "]";
|
||||||
|
@ -650,9 +656,10 @@ namespace CXML
|
||||||
FileTable.Seek(FilePtr, SeekOrigin.Begin);
|
FileTable.Seek(FilePtr, SeekOrigin.Begin);
|
||||||
FileTable.Read(FileData, 0, FileSz);
|
FileTable.Read(FileData, 0, FileSz);
|
||||||
string FileHash = Tools.GenerateHash(FileData);
|
string FileHash = Tools.GenerateHash(FileData);
|
||||||
|
string FileSmallHash = Tools.GenerateShortHash(FileData);
|
||||||
String Extension = Tools.GetFileExtension(FileData);
|
String Extension = Tools.GetFileExtension(FileData);
|
||||||
String FileName = Path.Combine(FileDir, ElementName, FileHash + Extension);
|
String FileName = Path.Combine(FileDir, "original", FilePtr.ToString("X")+"-"+FileHash + Extension);
|
||||||
|
String IdealName = ElementName + "-" + AttributeName + "-" + FileSmallHash + Extension;
|
||||||
if (!File.Exists(FileName))
|
if (!File.Exists(FileName))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Writing: " + FileName);
|
Console.WriteLine("Writing: " + FileName);
|
||||||
|
@ -661,7 +668,7 @@ namespace CXML
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(FileName));
|
Directory.CreateDirectory(Path.GetDirectoryName(FileName));
|
||||||
|
|
||||||
File.WriteAllBytes(FileName, FileData);
|
File.WriteAllBytes(FileName, FileData);
|
||||||
ChangeFilename(ElementPtr, FileName, true);
|
RegisterFile(ElementPtr, FileName, true, IdealName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -682,7 +689,7 @@ namespace CXML
|
||||||
Console.WriteLine("Loopback: " + LoopbackAttribute +" "+ LoopbackPtr.ToString("X")+" ("+ElementPtr.ToString("X")+")");
|
Console.WriteLine("Loopback: " + LoopbackAttribute +" "+ LoopbackPtr.ToString("X")+" ("+ElementPtr.ToString("X")+")");
|
||||||
|
|
||||||
AttributeValue = Tools.ReadString(StringIDTable);
|
AttributeValue = Tools.ReadString(StringIDTable);
|
||||||
ChangeFilename(LoopbackPtr, AttributeValue.ToString(), false);
|
RegisterFile(LoopbackPtr, AttributeValue.ToString(), false);
|
||||||
|
|
||||||
Console.WriteLine("Loopback ID String: " + StringIdTableOffset + " sz: " + bTreeTable.ReadInt32());
|
Console.WriteLine("Loopback ID String: " + StringIdTableOffset + " sz: " + bTreeTable.ReadInt32());
|
||||||
break;
|
break;
|
||||||
|
@ -707,7 +714,7 @@ namespace CXML
|
||||||
Console.WriteLine("Int Loopback: " + LoopbackAttribute + " " + LoopbackPtr.ToString("X") + " (" + ElementPtr.ToString("X") + ")");
|
Console.WriteLine("Int Loopback: " + LoopbackAttribute + " " + LoopbackPtr.ToString("X") + " (" + ElementPtr.ToString("X") + ")");
|
||||||
|
|
||||||
AttributeValue = IDValue.ToString("X8");
|
AttributeValue = IDValue.ToString("X8");
|
||||||
ChangeFilename(LoopbackPtr, AttributeValue.ToString(), false);
|
RegisterFile(LoopbackPtr, AttributeValue.ToString(), false);
|
||||||
|
|
||||||
Console.WriteLine("Loopback Int: " + IntIdTableOffset + " sz: " + bTreeTable.ReadInt32());
|
Console.WriteLine("Loopback Int: " + IntIdTableOffset + " sz: " + bTreeTable.ReadInt32());
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -65,6 +65,10 @@ namespace CXMLCli
|
||||||
String ArgsFull = String.Join(" ", args);
|
String ArgsFull = String.Join(" ", args);
|
||||||
String path = args[0];
|
String path = args[0];
|
||||||
|
|
||||||
|
if (args.Length == 1)
|
||||||
|
{
|
||||||
|
ArgsFull += " -d -p -w";
|
||||||
|
}
|
||||||
|
|
||||||
if (HasArg(ArgsFull, "-iv") || HasArg(ArgsFull, "--is-vag"))
|
if (HasArg(ArgsFull, "-iv") || HasArg(ArgsFull, "--is-vag"))
|
||||||
{
|
{
|
||||||
|
@ -99,16 +103,12 @@ namespace CXMLCli
|
||||||
|
|
||||||
CXML.CXMLParser cxmlParser = new CXML.CXMLParser();
|
CXML.CXMLParser cxmlParser = new CXML.CXMLParser();
|
||||||
if(!HasArg(ArgsFull, "-c") && !HasArg(ArgsFull, "--compile"))
|
if(!HasArg(ArgsFull, "-c") && !HasArg(ArgsFull, "--compile"))
|
||||||
cxmlParser.Init(path, Check);
|
|
||||||
|
|
||||||
if (args.Length == 1)
|
|
||||||
{
|
{
|
||||||
if (Path.GetExtension(args[0]) == ".xml")
|
Console.WriteLine("Initalizing: " + path);
|
||||||
ArgsFull += Path.ChangeExtension(args[0], ".cxml") + " -c -w";
|
cxmlParser.Init(path, Check);
|
||||||
else
|
|
||||||
ArgsFull += "-d -p -w";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (HasArg(ArgsFull, "-f") || HasArg(ArgsFull, "--force"))
|
if (HasArg(ArgsFull, "-f") || HasArg(ArgsFull, "--force"))
|
||||||
{
|
{
|
||||||
Check = false;
|
Check = false;
|
||||||
|
@ -116,7 +116,7 @@ namespace CXMLCli
|
||||||
|
|
||||||
if (HasArg(ArgsFull, "-dt") || HasArg(ArgsFull, "--dump-tables"))
|
if (HasArg(ArgsFull, "-dt") || HasArg(ArgsFull, "--dump-tables"))
|
||||||
{
|
{
|
||||||
ArgsFull += "-tt -ist -iit -st -ct -sit -iat -fat -ft";
|
ArgsFull += " -tt -ist -iit -st -ct -sit -iat -fat -ft";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HasArg(ArgsFull, "-tt") || HasArg(ArgsFull, "--dump-tree"))
|
if (HasArg(ArgsFull, "-tt") || HasArg(ArgsFull, "--dump-tree"))
|
||||||
|
@ -198,7 +198,7 @@ namespace CXMLCli
|
||||||
}
|
}
|
||||||
else if (HasArg(ArgsFull, "-c") || HasArg(ArgsFull, "--compile"))
|
else if (HasArg(ArgsFull, "-c") || HasArg(ArgsFull, "--compile"))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Compiling.");
|
Console.WriteLine("Compiling: " + path);
|
||||||
CXMLBuilder builder = new CXMLBuilder();
|
CXMLBuilder builder = new CXMLBuilder();
|
||||||
builder.Init(path, args[1]);
|
builder.Init(path, args[1]);
|
||||||
builder.BuildCXML(path, args[1]);
|
builder.BuildCXML(path, args[1]);
|
||||||
|
|
Loading…
Reference in New Issue