static void Main(string[] args) { string hellgatePath = Config.HglDir; string currentDir = Directory.GetCurrentDirectory(); string dataDir = Path.Combine(currentDir, Hellgate.Common.DataPath); string dataCommonDir = Path.Combine(currentDir, Hellgate.Common.DataCommonPath); bool doCookTxt = false; bool doCookXml = false; bool doPackDat = false; // do pack any referenced files into a hellgate london dat/idx bool doSearchCd = false; // search the current directory for files to cook and pack bool doExcludeRaw = false; // do not pack source files, only cooked versions. bool doLevelRules = false; bool doRoomDefinitions = false; List<string> filesToPack = new List<string>(); List<string> excelFilesToCook = new List<string>(); List<string> stringFilesToCook = new List<string>(); List<string> xmlFilesToCook = new List<string>(); List<string> levelRulesFilesToSerialize = new List<string>(); List<string> roomDefinitionFilesSerialize = new List<string>(); #region alexs_stuff if (false) { //_fileManager = new FileManager(@"D:\Games\Hellgate London"); //_fileManager.LoadTableFiles(); ////byte[] buffer = fileManager.DataFiles["SOUNDS"].ExportCSV(); ////return; ////File.WriteAllBytes(@"D:\levels_rules.txt", buffer); //foreach (DataFile dataFile in _fileManager.DataFiles.Values) //{ // if (dataFile.IsStringsFile) continue; // ExcelFile excelFile = (ExcelFile) dataFile; // Console.WriteLine(dataFile.FileName); // String dir = Path.GetDirectoryName(dataFile.FilePath); // if (Directory.Exists(dir) == false) Directory.CreateDirectory(dir); // byte[] ebuffer = excelFile.ExportCSV(_fileManager); // //for (int i = 0; i < 10; i++) // //{ // // Stopwatch stopwatch = new Stopwatch(); // // stopwatch.Start(); // // ebuffer = dataFile.ExportCSV(); // // stopwatch.Stop(); // // Console.WriteLine("Elapsed: {0}", stopwatch.Elapsed); // //} // File.WriteAllBytes(dataFile.FilePath.Replace(".cooked", ""), ebuffer); //} //Stopwatch stopwatch = new Stopwatch(); //stopwatch.Start(); //const String pathExcel = @"data\excel\items.txt"; //byte[] excelBytes = File.ReadAllBytes(pathExcel); //ExcelFile excelFile = new ExcelFile(excelBytes, pathExcel); //byte[] excelCsvBytes = excelFile.ToByteArray(); //stopwatch.Stop(); //Console.WriteLine("Elapsed: {0}", stopwatch.Elapsed); //const String path = @"data\excel\strings\english\strings_revival.xls.uni2"; //byte[] cookedBytes = File.ReadAllBytes(path); //StringsFile stringsFile = new StringsFile(cookedBytes, path); //byte[] csvBytes = stringsFile.ExportCSV(); //if (!cookedBytes.SequenceEqual(csvBytes)) //{ // File.WriteAllBytes(path + "2", csvBytes); // int bp = 0; //} //doSearchCd = true; //doCookTxt = true; //if (doSearchCd && doCookTxt) //{ // excelFilesToCook.AddRange(SearchForExcelFiles(currentDir)); // stringFilesToCook.AddRange(SearchForStringFiles(currentDir)); //} //if (doCookTxt) //{ // CookExcelFiles(excelFilesToCook.ToArray()); // CookStringFiles(stringFilesToCook.ToArray()); //} //return; } #endregion #region Model conversion testing if (false) { //_fileManager = new FileManager(@"D:\Games\Hellgate London"); //string filePath = @"data\background\tubestations\charingcross\cc_southbound.m"; //byte[] buffer = _fileManager.GetFileBytes(filePath); //if (buffer == null) //{ // Console.WriteLine("Could not read specified file."); // return; //} //string modelId = Path.GetFileNameWithoutExtension(filePath); //Model model = new Model(buffer, modelId); //buffer = model.ExportCollada(); //File.WriteAllBytes(modelId + ".xml", buffer); //return; } #endregion #region SQL test if (false) { //_fileManager = new FileManager(@"D:\Games\Hellgate London", true); //_fileManager.LoadTableFiles(); //byte[] sqlBuffer = new byte[1024]; //int sqlOffset = 0; ////string createDB = "CREATE DATABASE hellgate_london;\nUSE hellgate_london;\n"; ////byte[] createDBArray = FileTools.StringToASCIIByteArray(createDB); ////FileTools.WriteToBuffer(ref sqlBuffer, ref sqlOffset, createDBArray); //foreach (DataFile dataFile in _fileManager.DataFiles.Values) //{ // if (dataFile.IsStringsFile) continue; // ExcelFile excelFile = dataFile as ExcelFile; // byte[] buffer = excelFile.ExportSQL(_fileManager, "hgl"); // //if (dataFile.IsExcelFile) continue; // //byte[] buffer = dataFile.ExportSQL("hgl_tcv4_"); // Console.WriteLine(dataFile.FileName); // FileTools.WriteToBuffer(ref sqlBuffer, ref sqlOffset, buffer); // if (true) // { // String dir = Path.GetDirectoryName(dataFile.FilePath); // if (Directory.Exists(dir) == false) Directory.CreateDirectory(dir); // string fileName = dataFile.FilePath; // fileName = fileName.Replace(".txt.cooked", ".sql"); // fileName = fileName.Replace(".xls.uni.cooked", ".sql"); // File.WriteAllBytes(fileName, buffer); // } //} //Array.Resize(ref sqlBuffer, sqlOffset); //File.WriteAllBytes("hellgate_london_db.sql", sqlBuffer); //return; } #endregion Console.WriteLine("Hellpack - the Hellgate London compiler.\nWritten by the Revival Team, 2012\nhttp://www.hellgateaus.net"); Console.WriteLine(String.Empty); #region Command Line Arugements if (args.Length == 0) { // No arguments defined - this is the default program doCookTxt = true; doCookXml = true; doPackDat = true; doSearchCd = true; doExcludeRaw = true; doLevelRules = true; doRoomDefinitions = true; } else { foreach (string arg in args) { switch (arg) { case "/t": doCookTxt = true; break; case "/x": doCookXml = true; break; case "/p": doPackDat = true; break; case "/s": doSearchCd = true; break; case "/e": doExcludeRaw = true; break; case "/lr": doLevelRules = true; break; case "/rd": doRoomDefinitions = true; break; case "/?": case "/help": Console.WriteLine(UsageMsg); return; default: if (arg.StartsWith("/p:")) { _defaultDat = arg.Replace("/p:", ""); // Trim in case someone has appended the extention if (_defaultDat.EndsWith(".idx")) _defaultDat = _defaultDat.Replace(".idx", ""); if (_defaultDat.EndsWith(".dat")) _defaultDat = _defaultDat.Replace(".dat", ""); break; } if (arg.StartsWith("/h:")) { hellgatePath = arg.Replace("/h:", ""); break; } if (arg.EndsWith(ExcelFile.ExtensionDeserialised)) { excelFilesToCook.Add(arg); doCookTxt = true; break; } if (arg.EndsWith(StringsFile.ExtensionDeserialised)) { stringFilesToCook.Add(arg); doCookTxt = true; break; } if (arg.EndsWith(LevelRulesFile.ExtensionDeserialised)) { levelRulesFilesToSerialize.Add(arg); doLevelRules = true; break; } if (arg.EndsWith(RoomDefinitionFile.ExtensionDeserialised)) { roomDefinitionFilesSerialize.Add(arg); doRoomDefinitions = true; break; } if (arg.EndsWith(XmlCookedFile.ExtensionDeserialised)) { xmlFilesToCook.Add(arg); doCookXml = true; break; } else { Console.WriteLine(String.Format("Incorrect argument given: {0}", arg)); Console.WriteLine(UsageMsg); return; } } } } #endregion #region Program Functions // Search for Txt files to cook if (doSearchCd && doCookTxt) { string[] result = SearchForExcelFiles(currentDir); if (result != null) excelFilesToCook.AddRange(result); result = SearchForStringFiles(currentDir); if (result != null) stringFilesToCook.AddRange(result); } // Search for Xml files to cook if (doSearchCd && doCookXml) { String[] xmlToCook = SearchForXmlFiles(currentDir); if (xmlToCook != null) xmlFilesToCook.AddRange(xmlToCook); } // Search for .drl Level Rules files to cook if (doSearchCd && doLevelRules) { IEnumerable<String> drlXmlToCompile = _SearchForDrlXmlFiles(currentDir); if (drlXmlToCompile != null) levelRulesFilesToSerialize.AddRange(drlXmlToCompile); } // Search for .rom Level Rules files to cook if (doSearchCd && doRoomDefinitions) { // todo } // need for code/name -> row index lookups Console.WriteLine("Loading FileManager..."); _fileManager = new FileManager(hellgatePath); _fileManager.BeginAllDatReadAccess(); Console.WriteLine("Loading strings and tables..."); _fileManager.LoadTableFiles(); _fileManager.EndAllDatAccess(); // Cook Txt files) if (doCookTxt) { _CookExcelFiles(excelFilesToCook.ToArray()); CookStringFiles(stringFilesToCook.ToArray()); } // Cook Xml files if (doCookXml) { // ensure we have the correct hellgate installation path if (Directory.Exists(hellgatePath)) { if (_fileManager.HasIntegrity == false) { Console.WriteLine("Warning: XML could not be cooked - fileManager.Integrity = false"); } else { _CookXmlFiles(xmlFilesToCook.ToArray(), _fileManager); } } else { Console.WriteLine("Warning: Can not cook XML, Hellgate London directory missing."); } } // cook .drl Level Rules files if (doLevelRules) { CookLevelRulesFiles(levelRulesFilesToSerialize); } // cook .rom Room Definition files if (doRoomDefinitions) { CookRoomDefinitionFiles(roomDefinitionFilesSerialize); } // Files to pack if (doPackDat) { filesToPack.AddRange(SearchForFilesToPack(currentDir, doExcludeRaw)); PackDatFile(filesToPack.ToArray(), Path.Combine(dataDir, _defaultDat + ".idx"), false); } #endregion return; }
public static void TestAllExcelScripts() { ExcelScript.GlobalDebug(true); FileManager fileManager = new FileManager(Config.HglDir); fileManager.BeginAllDatReadAccess(); fileManager.LoadTableFiles(); fileManager.EndAllDatAccess(); StringWriter results = new StringWriter(); Dictionary<String, int> excelScriptDecompileFails = new Dictionary<String, int>(); Dictionary<String, int> excelScriptRecompileFails = new Dictionary<String, int>(); Dictionary<String, int> excelScriptComparisonFails = new Dictionary<String, int>(); int grandTotalScripts = 0; int grandTotalScriptsDecompiled = 0; int grandTotalScriptsFailedDecompilation = 0; int grandTotalScriptsRecompiled = 0; int grandTotalScriptsFailedRecompilation = 0; int grandTotalScriptsCompared = 0; int grandTotalScriptsFailedComparison = 0; foreach (ExcelFile excelFile in fileManager.DataFiles.Values.Where(dataFile => dataFile.IsExcelFile)) { String excelStringId = String.Format("{0}...", excelFile.StringId); Debug.Write(excelStringId); results.Write(excelStringId); //if (excelFile.StringId != "SKILLS") continue; if (excelFile.Delegator == null || excelFile.ScriptCode == null || excelFile.ScriptCode.Length == 0) { Debug.WriteLine(" No script data"); results.WriteLine(" No script data"); continue; } String scriptIntValues = String.Format(" {0} script int values...", excelFile.ScriptCode.Length); Debug.WriteLine(scriptIntValues); results.WriteLine(scriptIntValues); StringWriter excelFileResults = new StringWriter(); int colIndex = -1; int totalScriptsFound = 0; int totalScriptsDecompiled = 0; int totalScriptsFailedDecompilation = 0; int totalScriptsRecompiled = 0; int totalScriptsFailedRecompilation = 0; int totalScriptsCompared = 0; int totalScriptsFailedComparison = 0; foreach (FieldDelegate fieldDelegate in excelFile.Delegator) { colIndex++; ExcelAttributes excelAtributes = (ExcelAttributes)fieldDelegate.Info.GetCustomAttributes(typeof(ExcelAttributes), true).FirstOrDefault(); if (excelAtributes == null || !excelAtributes.IsScript) continue; String currentColumn = String.Format("\tColumn[{0}] = {1}", colIndex, fieldDelegate.Name); Debug.WriteLine(currentColumn); results.WriteLine(currentColumn); excelFileResults.WriteLine(currentColumn); int rowIndex = -1; int prevOffset = 0; int scriptCount = 0; int scriptsDecompiled = 0; int scriptsFailedDecompilation = 0; int scriptsRecompiled = 0; int scriptsFailedRecompilation = 0; int scriptsCompared = 0; int scriptsFailedComparison = 0; foreach (Object row in excelFile.Rows) { rowIndex++; int byteOffset = (int)fieldDelegate.GetValue(row); if (byteOffset == 0) continue; Debug.Assert(byteOffset > prevOffset); prevOffset = byteOffset; if (byteOffset == 9649 && excelFile.StringId == "SKILLS") // todo: not sure what's with this script... { continue; } excelFileResults.WriteLine(String.Format("\t\tColumn({0}) = {3}, Row({1}), ByteOffset({2}):", colIndex, rowIndex, byteOffset, fieldDelegate.Name)); ExcelScript excelScript = new ExcelScript(fileManager); scriptCount++; String script; int[] scriptCodes = excelFile.ReadScriptTable(byteOffset); String scriptCodesStr = scriptCodes.ToString(","); String semiDecompiledScript = _ReadScriptTable(excelScript, scriptCodes); //if (scriptCodesStr == "707,0,714,666,0,3,201,673,603979779,26,5,2,284,0,0") //{ // int bp = 0; //} // test decompiling try { script = excelScript.Decompile(excelFile.ScriptBuffer, byteOffset, scriptCodesStr, excelFile.StringId, rowIndex, colIndex, fieldDelegate.Name); scriptsDecompiled++; } catch (Exception e) { if (!excelScriptDecompileFails.ContainsKey(excelFile.StringId)) { excelScriptDecompileFails.Add(excelFile.StringId, 1); } else { excelScriptDecompileFails[excelFile.StringId]++; } scriptsFailedDecompilation++; excelFileResults.WriteLine("Script Decompile Failed:\n" + semiDecompiledScript + "\n" + e + "\n"); continue; } // test compiling of decompiled script int[] recompiledScriptCode; try { ExcelScript excelScriptCompile = new ExcelScript(fileManager); recompiledScriptCode = excelScriptCompile.Compile(script, scriptCodesStr, excelFile.StringId, rowIndex, colIndex, fieldDelegate.Name); scriptsRecompiled++; } catch (Exception e) { if (!excelScriptRecompileFails.ContainsKey(excelFile.StringId)) { excelScriptRecompileFails.Add(excelFile.StringId, 1); } else { excelScriptRecompileFails[excelFile.StringId]++; } scriptsFailedRecompilation++; excelFileResults.WriteLine("Script Recompile Failed:\n" + semiDecompiledScript + "\n" + e + "\n"); continue; } // check recompiled fidelity scriptsCompared++; if (!scriptCodes.SequenceEqual(recompiledScriptCode)) { if (!excelScriptComparisonFails.ContainsKey(excelFile.StringId)) { excelScriptComparisonFails.Add(excelFile.StringId, 1); } else { excelScriptComparisonFails[excelFile.StringId]++; } scriptsFailedComparison++; String compareFailed = String.Format("Script Comparison Failed:\nOriginal Script: {0} = {1}\nRecompiled Script: {2}\nSemi-Decompiled:\n{3}", scriptCodesStr, script, recompiledScriptCode.ToString(","), semiDecompiledScript); excelFileResults.WriteLine(compareFailed); continue; } excelFileResults.WriteLine(script + "\n"); } totalScriptsFound += scriptCount; totalScriptsDecompiled += scriptsDecompiled; totalScriptsFailedDecompilation += scriptsFailedDecompilation; totalScriptsRecompiled += scriptsRecompiled; totalScriptsFailedRecompilation += scriptsFailedRecompilation; totalScriptsCompared += scriptsCompared; totalScriptsFailedComparison += scriptsFailedComparison; String columnStats = String.Format("\t\t{0} scripts found, {1} scripts decompiled, {2} scripts failed to decompile.\n", scriptCount, scriptsDecompiled, scriptsFailedDecompilation); columnStats += String.Format("\t\t\t{0} scripts recompiled, {1} scripts failed to recompile, {2} scripts compared, {3} scripts failed comparison", scriptsRecompiled, scriptsFailedRecompilation, scriptsCompared, scriptsFailedComparison); Debug.WriteLine(columnStats); excelFileResults.WriteLine(columnStats); } grandTotalScripts += totalScriptsFound; grandTotalScriptsDecompiled += totalScriptsDecompiled; grandTotalScriptsFailedDecompilation += totalScriptsFailedDecompilation; grandTotalScriptsRecompiled += totalScriptsRecompiled; grandTotalScriptsFailedRecompilation += totalScriptsFailedRecompilation; grandTotalScriptsCompared += totalScriptsCompared; grandTotalScriptsFailedComparison += totalScriptsFailedComparison; String totalStats = String.Format("Totals: {0} scripts found, {1} scripts decompiled, {2} scripts failed to decompile.\n", totalScriptsFound, totalScriptsDecompiled, totalScriptsFailedDecompilation); totalStats += String.Format("\t{0} scripts recompiled, {1} scripts failed to recompile, {2} scripts compared, {3} scripts failed comparison", totalScriptsRecompiled, totalScriptsFailedRecompilation, totalScriptsCompared, totalScriptsFailedComparison); Debug.WriteLine(totalStats); results.WriteLine(totalStats); excelFileResults.WriteLine(totalStats); File.WriteAllText(@"C:\TestScripts\excelScripts_" + excelFile.StringId + ".txt", excelFileResults.ToString()); excelFileResults.Close(); } foreach (KeyValuePair<String, int> keyValuePair in excelScriptDecompileFails) { String excelFileFails = String.Format("{0} had {1} failed decompilation.", keyValuePair.Key, keyValuePair.Value); Debug.WriteLine(excelFileFails); results.WriteLine(excelFileFails); } String grandTotalStats = String.Format("Grand Totals: {0} scripts found, {1} scripts decompiled, {2} scripts failed to decompile.\n", grandTotalScripts, grandTotalScriptsDecompiled, grandTotalScriptsFailedDecompilation); grandTotalStats += String.Format("\t{0} scripts recompiled, {1} scripts failed to recompile, {2} scripts compared, {3} scripts failed comparison", grandTotalScriptsRecompiled, grandTotalScriptsFailedRecompilation, grandTotalScriptsCompared, grandTotalScriptsFailedComparison); Debug.WriteLine(grandTotalStats); results.WriteLine(grandTotalStats); File.WriteAllText(@"C:\TestScripts\excelScripts_Results.txt", results.ToString()); }
static void Main(string[] args) { var manager = new FileManager(@"C:\Hellgate"); manager.BeginAllDatReadAccess(); manager.LoadTableFiles(); manager.EndAllDatAccess(); //TODO: hp/power regen is messed up when displaying the full formula because I guess the itemdisplay formula isn't used //note: "display dmg" is ilvl multi*item dmg*dmg% (before "increments" are applied), where dmg% is the first or second argument in dmg_elec(100,100) //TODO: weapon ranges //TODO: add affix names to properties //TODO: sword attack rates //TODO: wtf is up with ilvls that don't match any of the listed numbers (maxlevel, fixedlevel, level)? //long term TODO: assign unit types so "isa" functions (among other things) work args = new[] { "ITEMS" }; //new Items(manager).WriteAllUniqueLegendaryItemPages(); //return; string sqlStatement; WikiScript script; foreach (string arg in args) { switch (arg) { case "ACHIEVEMENTS": script = new Achievements(manager); break; case "AFFIXES": script = new Affixes(manager); break; case "BASEWAVES": script = new BaseDefenseWaves(manager); break; case "MONSTERAFFIXES": script = new MonsterAffixes(manager); break; case "ARMORAFFIXES": script = new ArmorAffixes(manager); break; case "ITEMLEVELS": script = new ItemLevels(manager); break; case "LEVELS": script = new Levels(manager); break; case "MONSTERS": script = new Monsters(manager); break; case "PVPRANKS": script = new PVPRanks(manager); break; case "LEVELSCALING": script = new LevelScaling(manager); break; case "ITEMS": script = new Items(manager); break; case "ITEM_QUALITY": script = new ItemQuality(manager); break; case "TREASURE": script = new NewTreasure(manager); break; case "MONSTER_QUALITY": script = new MonsterQuality(manager); break; case "RECIPES": script = new Recipes(manager); break; case "ITEM_SETS": script = new Sets(manager); break; default: throw new Exception("Unknown WikiScript: " + arg); } sqlStatement = script.ExportTableInsertScript(); File.WriteAllText(arg.ToLower() + ".sql", sqlStatement); } return; }