diff --git a/.vs/AppInfoParser/v16/.suo b/.vs/AppInfoParser/v16/.suo index 67d8fff..096991b 100644 Binary files a/.vs/AppInfoParser/v16/.suo and b/.vs/AppInfoParser/v16/.suo differ diff --git a/AppInfoCli/CXMLBuilder.cs b/AppInfoCli/CXMLBuilder.cs index 5443e53..94f6eb3 100644 --- a/AppInfoCli/CXMLBuilder.cs +++ b/AppInfoCli/CXMLBuilder.cs @@ -224,15 +224,14 @@ namespace CXMLDecompiler 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) - if (entry.name == v) + if (entry.name == filename) return entry.offset; StringTableEntry ent = new StringTableEntry(); - ent.name = v; + ent.name = filename; ent.offset = Convert.ToInt32(FileTable.Position); FileTableEntries.Add(ent); @@ -365,7 +364,7 @@ namespace CXMLDecompiler break; case AttributeType.TYPE_STRING: int StringOffset = AddGetStringTable(attribute.Value); - int StringLen = attribute.Value.Length; + int StringLen = Encoding.UTF8.GetBytes(attribute.Value).Length; bWorkRam.Write(StringOffset); bWorkRam.Write(StringLen); Console.WriteLine("String: " + attribute.Value); @@ -413,7 +412,7 @@ namespace CXMLDecompiler case AttributeType.TYPE_FILE: string fPath = Path.Combine(MainDir, attribute.Value); byte[] data = File.ReadAllBytes(fPath); - int FilePtr = AddGetFileTable(data); + int FilePtr = AddGetFileTable(data, Path.Combine(Environment.CurrentDirectory, fPath)); int FileSz = data.Length; bWorkRam.Write(FilePtr); bWorkRam.Write(FileSz); diff --git a/AppInfoCli/CXMLReader.cs b/AppInfoCli/CXMLReader.cs index a0c7964..66a7fa6 100644 --- a/AppInfoCli/CXMLReader.cs +++ b/AppInfoCli/CXMLReader.cs @@ -355,7 +355,7 @@ namespace CXML if(tInfo.key == key) { if (tInfo.value.ToString() != value.ToString()) - throw new Exception("Fuck."); + throw new Exception("Very Weird CXML"); return; } } @@ -415,19 +415,23 @@ namespace CXML string extension = Path.GetExtension(oldName); string folderPath = Path.GetDirectoryName(oldName); 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 xmlRelNewPath = newPath.Substring(Tools.GetRootFolder(newPath).Length + 1); - Console.WriteLine("Moved " + xmlRelOldPath + " => " + xmlRelNewPath); - XmlData = XmlData.Replace(xmlRelOldPath, xmlRelNewPath); + string xmlRelOldPath = oldName.Substring(Tools.GetRootFolder(oldName).Length + 1); + string xmlRelNewPath = newPath.Substring(Tools.GetRootFolder(newPath).Length + 1); + Console.WriteLine("Moved " + xmlRelOldPath + " => " + xmlRelNewPath); + XmlData = XmlData.Replace(xmlRelOldPath, xmlRelNewPath); + } if (ProcessFiles) ProcessFile(newPath); } else { - Console.WriteLine("Generated Filename used for " + lpHandler.OldFileName); + Console.WriteLine("NOT MOVING: " + lpHandler.OldFileName); if (ProcessFiles) 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 + ")"); for(int i = 0; i < FileList.Count; i++) @@ -529,6 +533,7 @@ namespace CXML if (FileList[i].OldFileName != null) break; FileList[i].OldFileName = NewName; + FileList[i].FileName = IdealName; return; } else @@ -543,6 +548,7 @@ namespace CXML if (FileEntry) { lpHandler.OldFileName = NewName; + lpHandler.FileName = IdealName; } else { @@ -574,7 +580,7 @@ namespace CXML break; case AttributeType.TYPE_FLOAT: float FloatValue = bTreeTable.ReadSingle(); - AttributeValue = FloatValue.ToString()+"f"; + AttributeValue = ((double)FloatValue).ToString() + "f"; Console.WriteLine("Float - Value: " + AttributeValue.ToString() + " sz:" + bTreeTable.ReadInt32()); break; case AttributeType.TYPE_STRING: @@ -636,7 +642,7 @@ namespace CXML for(int i = 0; i < FloatArraySize; i++) { FloatValue = bFloatArrayTable.ReadSingle(); - StrList.Add(FloatValue.ToString()+"f"); + StrList.Add(((double)FloatValue).ToString() +"f"); } string[] StrArray = StrList.ToArray(); AttributeValue = "[" + String.Join(", ", StrArray) + "]"; @@ -650,9 +656,10 @@ namespace CXML FileTable.Seek(FilePtr, SeekOrigin.Begin); FileTable.Read(FileData, 0, FileSz); string FileHash = Tools.GenerateHash(FileData); - + string FileSmallHash = Tools.GenerateShortHash(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)) { Console.WriteLine("Writing: " + FileName); @@ -661,7 +668,7 @@ namespace CXML Directory.CreateDirectory(Path.GetDirectoryName(FileName)); File.WriteAllBytes(FileName, FileData); - ChangeFilename(ElementPtr, FileName, true); + RegisterFile(ElementPtr, FileName, true, IdealName); } else { @@ -682,7 +689,7 @@ namespace CXML Console.WriteLine("Loopback: " + LoopbackAttribute +" "+ LoopbackPtr.ToString("X")+" ("+ElementPtr.ToString("X")+")"); AttributeValue = Tools.ReadString(StringIDTable); - ChangeFilename(LoopbackPtr, AttributeValue.ToString(), false); + RegisterFile(LoopbackPtr, AttributeValue.ToString(), false); Console.WriteLine("Loopback ID String: " + StringIdTableOffset + " sz: " + bTreeTable.ReadInt32()); break; @@ -707,7 +714,7 @@ namespace CXML Console.WriteLine("Int Loopback: " + LoopbackAttribute + " " + LoopbackPtr.ToString("X") + " (" + ElementPtr.ToString("X") + ")"); AttributeValue = IDValue.ToString("X8"); - ChangeFilename(LoopbackPtr, AttributeValue.ToString(), false); + RegisterFile(LoopbackPtr, AttributeValue.ToString(), false); Console.WriteLine("Loopback Int: " + IntIdTableOffset + " sz: " + bTreeTable.ReadInt32()); break; diff --git a/AppInfoCli/Program.cs b/AppInfoCli/Program.cs index e4c3753..458710e 100644 --- a/AppInfoCli/Program.cs +++ b/AppInfoCli/Program.cs @@ -65,6 +65,10 @@ namespace CXMLCli String ArgsFull = String.Join(" ", args); String path = args[0]; + if (args.Length == 1) + { + ArgsFull += " -d -p -w"; + } if (HasArg(ArgsFull, "-iv") || HasArg(ArgsFull, "--is-vag")) { @@ -99,16 +103,12 @@ namespace CXMLCli CXML.CXMLParser cxmlParser = new CXML.CXMLParser(); if(!HasArg(ArgsFull, "-c") && !HasArg(ArgsFull, "--compile")) - cxmlParser.Init(path, Check); - - if (args.Length == 1) { - if (Path.GetExtension(args[0]) == ".xml") - ArgsFull += Path.ChangeExtension(args[0], ".cxml") + " -c -w"; - else - ArgsFull += "-d -p -w"; + Console.WriteLine("Initalizing: " + path); + cxmlParser.Init(path, Check); } + if (HasArg(ArgsFull, "-f") || HasArg(ArgsFull, "--force")) { Check = false; @@ -116,7 +116,7 @@ namespace CXMLCli 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")) @@ -198,7 +198,7 @@ namespace CXMLCli } else if (HasArg(ArgsFull, "-c") || HasArg(ArgsFull, "--compile")) { - Console.WriteLine("Compiling."); + Console.WriteLine("Compiling: " + path); CXMLBuilder builder = new CXMLBuilder(); builder.Init(path, args[1]); builder.BuildCXML(path, args[1]);