public LevelRulesEditor(FileManager fileManager, PackFileEntry fileEntry) { InitializeComponent(); DoubleBuffered = true; _fileManager = fileManager; byte[] fileBytes = fileManager.GetFileBytes(fileEntry); _levelRules = new LevelRulesFile(fileEntry.Path, null); _levelRules.ParseFileBytes(fileBytes); foreach (LevelRulesFile.LevelRule levelRule in _levelRules.LevelRules) { if (levelRule.StaticRooms != null) { _LoadRooms(levelRule.StaticRooms, fileEntry.Path); } else { foreach (LevelRulesFile.Room[] levelRules in levelRule.Rules) { _LoadRooms(levelRules, fileEntry.Path); } } } }
public void SetBitmaps(FileManager fileManager, HGLWindowStyle windowStyle) { AtlasImageLoader loader; loader = new AtlasImageLoader(); loader.LoadAtlas(@"data\uix\xml\main_atlas.xml", fileManager); List<Bitmap> imageList = new List<Bitmap>(); imageList.Clear(); imageList.Add(loader.GetImage(windowStyle + "_1_TL")); imageList.Add(loader.GetImage(windowStyle + "_2_TM")); imageList.Add(loader.GetImage(windowStyle + "_3_TR")); imageList.Add(loader.GetImage(windowStyle + "_4_ML")); imageList.Add(loader.GetImage(windowStyle + "_5_MM")); imageList.Add(loader.GetImage(windowStyle + "_6_MR")); imageList.Add(loader.GetImage(windowStyle + "_7_BL")); imageList.Add(loader.GetImage(windowStyle + "_8_BM")); imageList.Add(loader.GetImage(windowStyle + "_9_BR")); SetBitmaps(imageList); loader.ClearImageList(); imageList.Clear(); }
private void _DoLoadingThread(ProgressForm progressForm, Object var) { //// Single Player/Standard data files //// progressForm.SetCurrentItemText("Loading File Manager..."); _fileManager = new FileManager(Config.HglDir); //_fileManager = new FileManager(Config.HglDir, FileManager.ClientVersions.Mod); foreach (PackFile file in _fileManager.IndexFiles) file.BeginDatReading(); progressForm.SetCurrentItemText("Loading Excel and Strings Tables..."); if (!_fileManager.LoadTableFiles()) { MessageBox.Show("Failed to load excel and strings files!", "Data Table Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } foreach (PackFile file in _fileManager.IndexFiles) file.EndDatAccess(); if (_fileManager.IsVersionMod) _fileManager.ProcessTables(); if (!Config.LoadTCv4DataFiles) return; //// TCv4 data files //// progressForm.SetCurrentItemText("Loading TCv4 File Manager..."); _fileManagerTCv4 = new FileManager(Config.HglDir, FileManager.ClientVersions.TestCenter); foreach (PackFile file in _fileManagerTCv4.IndexFiles) file.BeginDatReading(); progressForm.SetCurrentItemText("Loading TCv4 Excel and Strings Tables..."); if (!_fileManagerTCv4.LoadTableFiles()) { MessageBox.Show("Failed to load TCv4 excel and strings files!", "Data Table Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } foreach (PackFile file in _fileManagerTCv4.IndexFiles) file.EndDatAccess(); }
public ExcelFile(String filePath, FileManager.ClientVersions clientVersion = FileManager.ClientVersions.SinglePlayer) { Thread.CurrentThread.CurrentCulture = Common.EnglishUSCulture; IsExcelFile = true; FilePath = filePath; StringId = _GetStringId(filePath); if (StringId == null) throw new Exceptions.DataFileStringIdNotFound(filePath); // get the excel type attributes DataFileAttributes dataFileAttributes = null; if (clientVersion == FileManager.ClientVersions.Mod) { DataFileMapMod.TryGetValue(StringId, out dataFileAttributes); } if (dataFileAttributes == null && (clientVersion == FileManager.ClientVersions.Resurrection || clientVersion == FileManager.ClientVersions.Mod)) { DataFileMapResurrection.TryGetValue(StringId, out dataFileAttributes); } if (dataFileAttributes == null && clientVersion == FileManager.ClientVersions.TestCenter) { DataFileMapTestCenter.TryGetValue(StringId, out dataFileAttributes); } if (dataFileAttributes == null) { DataFileMap.TryGetValue(StringId, out dataFileAttributes); } Attributes = dataFileAttributes; if (Attributes == null) return; // create field delegators if (Attributes.RowType != null) { FieldInfo[] dataFileFields = Attributes.RowType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); dataFileFields = dataFileFields.OrderBy(f => f.MetadataToken).ToArray(); // order by defined order - GetFields does not guarantee ordering Delegator = new ObjectDelegator(dataFileFields); } else { Debug.WriteLine("Warning: Excel Definition has no RowType defined: " + StringId); } // if we're empty, then just return if (Attributes.IsEmpty) { HasIntegrity = true; Rows = new List<Object>(); return; } // we're using hard-coded mysh script table for SKILLS if (StringId == "SKILLS") _myshBuffer = Skills.Mysh.Data; // we aren't parsing file data, so need to manually assign a structure id _excelFileHeader.StructureID = Attributes.StructureId; }
/// <summary> /// Creates a DatafileEditor component, designed for editing DataFiles. /// </summary> /// <param name="dataFile">The dataFile in context.</param> /// <param name="fileManager">FileManager dependency.</param> public DatafileEditor(DataFile dataFile, FileManager fileManager) { _dataFile = dataFile; _fileManager = fileManager; _selectedIndexChange = false; _specialControls = new Hashtable(); InitializeComponent(); }
public UnitObjectStats(FileManager fileManager, int version = CurrentVersion) { _fileManager = fileManager; _version = version; StatSelectors = new List<StatSelector>(); Stats = new ConcurrentDictionary<Int32, Stat>(2, 50); //Stats = new Dictionary<Xls.StatCodes, Stat>(); Names = new List<StatName>(); }
public HGLForm(FileManager fileManager) { InitializeComponent(); this.fileManager = fileManager; background = new HGLWindowBackground(); comboBoxWindowStyle.DataSource = Enum.GetNames(typeof(HGLWindowStyle)); comboBoxWindowStyle.SelectedIndex = 0; }
private int _version; // 16 #endregion Fields #region Constructors public UnitObjectStats(FileManager fileManager, bool debugOutputLoadingProgress, int version = CurrentVersion) { _fileManager = fileManager; _debugOutputLoadingProgress = debugOutputLoadingProgress; _version = version; StatSelectors = new List<StatSelector>(); Stats = new ConcurrentDictionary<Int32, Stat>(2, 50); //Stats = new Dictionary<Xls.StatCodes, Stat>(); Names = new List<StatName>(); }
/// <summary> /// Constructs a list of tables that can be clicked to view. /// </summary> /// <param name="fileManager">FileManager dependency.</param> /// <param name="excelTableForm">Parents control of tables..</param> public TablesLoaded(FileManager fileManager, TableEditorForm excelTableForm) { _InitializeComponent(); _fileManager = fileManager; _excelTableForm = excelTableForm; if (_fileManager == null || _fileManager.DataFiles.Count == 0) return; _loadedTables_ListBox.DataSource = new BindingSource { DataSource = _fileManager.DataFiles }; // new BindingSource(_fileManager.DataFiles, null); // fix for .net know issue _loadedTables_ListBox.DoubleClick += _loadedTables_ListBox_MouseDoubleClick; _loadedTables_ListBox.Format += _loadedTables_ListBox_Format; }
public ScriptEditor(FileManager fileManager, DataGridViewCell dataGridViewCell, String rowName, String colName) { InitializeComponent(); _fileManager = fileManager; _dataGridViewCell = dataGridViewCell; Text = String.Format("Script Editor: Row({0}) '{1}', Col({2}) '{3}'", dataGridViewCell.RowIndex, rowName, dataGridViewCell.ColumnIndex, colName); FontFamily fontFamily = new FontFamily("Courier New"); Font font = new Font(fontFamily, 10, FontStyle.Regular, GraphicsUnit.Point); _scriptEditor_RichTextBox.Font = font; _scriptEditor_RichTextBox.Text = (String)dataGridViewCell.Value; }
public HeroEditor(CharacterFile characterFile, FileManager fileManager) { _characterFile = characterFile; _heroUnit = characterFile.Character; _fileManager = fileManager; //_panel = new CompletePanelControl(); //_statsTable = _excelTables.GetTable("stats") as Stats; //_itemFunctions = new UnitHelpFunctions(_dataSet); _itemFunctions.LoadCharacterValues(_heroUnit); //_itemFunctions.GenerateUnitNameStrings(); //_itemFunctions.PopulateItems(ref _heroUnit); //_wrapper = new UnitWrapper(_dataSet, heroFile); InitializeComponent(); }
public AnimationTestForm(FileManager fileManager) { InitializeComponent(); animations = new List<string>(); animations.Add("health anim "); animations.Add("power anim "); loader = new AtlasImageLoader(); loader.LoadAtlas(@"data\uix\xml\main_new_atlas.xml", fileManager); handler = new AnimationHandler(); handler.Speed = (int)numericUpDown1.Value; handler.NewFrameEvent += new NewFrame(handler_NewFrameEvent); handler.AddOverlay(loader.GetImage("meter mask")); handler.AddOverlay(loader.GetImage("health meter")); comboBox1.DataSource = animations; }
public ItemQualityCalculator(FileManager fileManager) { InitializeComponent(); _fileManager = fileManager; _itemQuality = _fileManager.GetDataTable("ITEM_QUALITY"); _qualities = new List<string>(); foreach(DataRow row in _itemQuality.Rows) { string quality = (string)row[2]; clb_qualities.Items.Add(quality); _qualities.Add(quality); } }
/// <summary> /// Initialise private variables and generate excel script functions if required. /// </summary> public ExcelScript(FileManager fileManager) { if (fileManager == null) throw new ArgumentNullException("fileManager", "File Manager cannot be null."); if (!fileManager.DataFiles.ContainsKey("STATS")) throw new Exceptions.ScriptNotInitialisedException("The supplied file manager did not have a valid Stats table."); // these initial counts are required for script compiling when determing if a function is from the .exe or from an Excel table if (!_haveExcelFunctions) { _initCallFunctionsCountSinglePlayer = CallFunctionsSinglePlayer.Count; _initCallFunctionsTestCenterCount = CallFunctionsTestCenter.Count; _initCallFunctionsResurrectionCount = CallFunctionsResurrection.Count; } _fileManager = fileManager; if (_fileManager.IsVersionResurrection || _fileManager.IsVersionMod) { CallFunctions = CallFunctionsResurrection; _initCallFunctionsCount = _initCallFunctionsResurrectionCount; _debugRoot = DebugRootResurrection; } else if (_fileManager.IsVersionTestCenter) { CallFunctions = CallFunctionsTestCenter; _initCallFunctionsCount = _initCallFunctionsTestCenterCount; _debugRoot = DebugRootTestCenter; } else { CallFunctions = CallFunctionsSinglePlayer; _initCallFunctionsCount = _initCallFunctionsCountSinglePlayer; _debugRoot = DebugRoot; } _statsTable = (ExcelFile)_fileManager.DataFiles["STATS"]; _statsDelegator = _fileManager.DataFileDelegators["STATS"]; if (_globalDebug) EnableDebug(true); if (CallFunctions.Count == _initCallFunctionsCount) _GenerateExcelScriptFunctions(); }
public DropOverview(FileManager fileManager) { InitializeComponent(); _fileManager = fileManager; _treasureTable = _fileManager.GetDataTable("TREASURE"); _itemsTable = _fileManager.GetDataTable("ITEMS"); _unitTypesTable = _fileManager.GetDataTable("UNITTYPES"); _itemQualityTable = _fileManager.GetDataTable("ITEM_QUALITY"); for (int counter = 0; counter < _treasureTable.Rows.Count; counter++) { DataRow row = _treasureTable.Rows[counter]; string name = (string)row[NAMECOLUMNINDEX]; if(name != "") { cb_dropTables.Items.Add(name); cb_dropTables.SelectedIndex = 0; } } }
/// <summary> /// Main constructor. Initialises the file tree system from a valid FileManager. /// </summary> /// <param name="fileManager">The FileManager to base the explorer tree on.</param> /// <param name="fileManagerTCv4">The FileManager to use for TCv4 specific extractions.</param> public FileExplorer(FileManager fileManager, FileManager fileManagerTCv4) { // init stuffs InitializeComponent(); _files_fileTreeView.DoubleBuffered(true); _fileManager = fileManager; _fileManagerTCv4 = fileManagerTCv4; backupKey_label.ForeColor = BackupColor; noEditorKey_label.ForeColor = NoEditColor; // load icons ImageList imageList = new ImageList { ColorDepth = ColorDepth.Depth32Bit }; foreach (Icon icon in Icons) { imageList.Images.Add(icon); } _files_fileTreeView.ImageList = imageList; // generate tree data _files_fileTreeView.BeginUpdate(); _GenerateFileTree(); _files_fileTreeView.TreeViewNodeSorter = new NodeSorter(); _files_fileTreeView.EndUpdate(); // general setups _quickExcelTCv4_checkBox.Checked = (fileManagerTCv4 != null); _quickExcelTCv4_checkBox.Enabled = Config.LoadTCv4DataFiles; _fileActionsExtract_checkBox.Enabled = true; _fileActionsPath_textBox.Text = Config.HglDir; // populate index files used // todo _indexFiles_listBox.Items.AddRange(fileManager.IndexFiles.ToArray()); //for (int i = 0; i < fileManager.IndexFiles.Count; i++) _indexFiles_listBox.SetSelected(i, true); //if (fileManagerTCv4 != null) _indexFiles_listBox.Items.AddRange(fileManagerTCv4.IndexFiles.ToArray()); }
public Items(FileManager manager) : base(manager, "items") { }
public BaseDefenseWaves(FileManager manager) : base(manager, "basedefense_waves") { }
public Affixes(FileManager manager) : base(manager,"affixes") { }
public static void ExtractAllCSV() { const String root = @"C:\test_mod\"; FileManager fileManager = new FileManager(Config.HglDir); fileManager.LoadTableFiles(); foreach (DataFile dataFile in fileManager.DataFiles.Values) { if (!dataFile.IsExcelFile) continue; ExcelFile excelFile = (ExcelFile)dataFile; byte[] csvBytes = excelFile.ExportCSV(fileManager); String savePath = Path.Combine(root, excelFile.FilePath).Replace(ExcelFile.Extension, ExcelFile.ExtensionDeserialised); Directory.CreateDirectory(Directory.GetDirectoryRoot(savePath)); File.WriteAllBytes(savePath, csvBytes); } }
public static void TestAllCodeValues() { FileManager fileManager = new FileManager(Config.HglDir); fileManager.LoadTableFiles(); int fileCountWithCode = 0; foreach (DataFile dataFile in fileManager.DataFiles.Values) { if (!dataFile.IsExcelFile) continue; ExcelFile excelFile = (ExcelFile)dataFile; Debug.Write(String.Format("Checking code fields within file {0}... ", excelFile.StringId)); FieldInfo[] fieldInfos = excelFile.Attributes.RowType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo[] codeFields = (from fi in fieldInfos where fi.Name == "code" select fi).ToArray(); if (codeFields.Length == 0) { Debug.WriteLine("None found."); continue; } //if (excelFile.StringId == "ACT") //{ // int bp = 0; // ExcelFile.Code codeObj = new ExcelFile.Code(); // codeObj = "AAB"; // int codeInt = codeObj; //} Debug.Assert(codeFields.Length == 1); Debug.WriteLine(String.Format("{0} fields found.", codeFields.Length)); fileCountWithCode++; ObjectDelegator objectDelegator = new ObjectDelegator(codeFields); Debug.WriteLine("Codes found: "); foreach (FieldInfo fieldInfo in codeFields) { foreach (Object row in excelFile.Rows) { int code = 0; if (fieldInfo.FieldType == typeof(short)) { code = (int)(short)objectDelegator["code"](row); } //else if (fieldInfo.FieldType == typeof(ExcelFile.Code)) //{ // code = (ExcelFile.Code)objectDelegator["code"](row); //} //else if (fieldInfo.FieldType == typeof(ExcelFile.ShortCode)) //{ // code = (ExcelFile.ShortCode)objectDelegator["code"](row); //} else { code = (int)objectDelegator["code"](row); } if (code == 0) continue; char char1 = (char)(code & 0xFF); char char2 = (char)((code & 0xFF00) >> 8); char char3 = (char)((code & 0xFF0000) >> 16); char char4 = (char)((code & 0xFF000000) >> 24); Debug.Assert(_CharCodeCharValue(char1)); Debug.Assert(_CharCodeCharValue(char2)); Debug.Assert(_CharCodeCharValue(char3)); Debug.Assert(_CharCodeCharValue(char4)); Debug.Write(String.Format(" {0}{1}{2}{3}", char1, char2, char3, char4)); } } Debug.WriteLine(""); } Debug.WriteLine(String.Format("{0} files with code fields checked.", fileCountWithCode)); }
/// <summary> /// This function checks every row/col of every excel file, determining if it needs to be visible/public or not. /// Any element non-zero for all rows, needs to be public (or add new OutputAttribute for "const" values?) /// </summary> public static void ExcelValuesDeepScan() { FileManager fileManager = new FileManager(Config.HglDir); fileManager.ExtractAllExcel(); Dictionary<uint, uint> rowTypeCounts = new Dictionary<uint, uint>(); Dictionary<String, uint[]> outputMessages = new Dictionary<String, uint[]>(); Dictionary<String, ObjectDelegator> objectDelegators = new Dictionary<String, ObjectDelegator>(); foreach (PackFileEntry fileEntry in fileManager.FileEntries.Values) { if (!fileEntry.Name.EndsWith(ExcelFile.Extension)) continue; byte[] fileBytes = fileManager.GetFileBytes(fileEntry, true); Debug.Assert(fileBytes != null); ExcelFile excelFile = new ExcelFile(fileBytes, fileEntry.Path); if (excelFile.Attributes.IsEmpty) continue; Debug.WriteLine("Checking file: " + fileEntry.Path); uint structureId = excelFile.Attributes.StructureId; uint structureUseCount = 0; if (rowTypeCounts.TryGetValue(structureId, out structureUseCount)) { rowTypeCounts[structureId] = ++structureUseCount; } else { rowTypeCounts.Add(structureId, 1); } ObjectDelegator excelDelegator; Type rowType = excelFile.Attributes.RowType; FieldInfo[] fieldInfos = rowType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); int rowCount = excelFile.Rows.Count; // create delegates if (!objectDelegators.TryGetValue(excelFile.StringId, out excelDelegator)) { excelDelegator = new ObjectDelegator(fieldInfos); objectDelegators.Add(excelFile.StringId, excelDelegator); } // check by column, by row int col = -1; foreach (FieldInfo fieldInfo in fieldInfos) { if (++col == 0) continue; // row header ObjectDelegator.FieldGetValueDelegate getValue = excelDelegator.GetFieldGetDelegate(fieldInfo.Name); ExcelFile.OutputAttribute outputAttribute = ExcelFile.GetExcelAttribute(fieldInfo); bool isArray = false; bool allEqual = true; Object firstValue = null; Array firstValueArray = null; int arrayIndexFirstDifferent = -1; int row = -1; String message = null; foreach (Object value in excelFile.Rows.Select(rowObject => getValue(rowObject))) { arrayIndexFirstDifferent = -1; if (++row == 0) { if (fieldInfo.FieldType.BaseType == typeof(Array)) { firstValueArray = (Array)value; isArray = true; IEnumerator enumerator = firstValueArray.GetEnumerator(); enumerator.MoveNext(); firstValue = enumerator.Current; } else { firstValue = value; } continue; } if (isArray) { Array objArray = (Array)value; Debug.Assert(firstValueArray != null); bool arrayEqual = true; IEnumerator enumeratorFirst = firstValueArray.GetEnumerator(); IEnumerator enumeratorCurrent = objArray.GetEnumerator(); while (enumeratorFirst.MoveNext()) { enumeratorCurrent.MoveNext(); arrayIndexFirstDifferent++; Object objFirst = enumeratorFirst.Current; Object objCurrent = enumeratorCurrent.Current; if (firstValue == null) firstValue = objFirst; if (objFirst.Equals(objCurrent)) continue; arrayEqual = false; break; } if (arrayEqual) continue; allEqual = false; break; } Debug.Assert(firstValue != null); if (firstValue.Equals(value)) continue; allEqual = false; break; } Debug.Assert(firstValue != null); Object constValue = null; bool ignoreConstCheck = false; if (outputAttribute != null) { constValue = outputAttribute.ConstantValue; ignoreConstCheck = outputAttribute.DebugIgnoreConstantCheck; } if (fieldInfo.IsPrivate) { if (!allEqual) { message = String.Format("Warning: Private column (Type = {1}, StructureId = 0x{2}) \"{0}\" has per-row differing values", fieldInfo.Name, fieldInfo.FieldType, structureId.ToString("X8")); // need to add structureId to ensure message is unique per structure type if (isArray) { message += ", first index differing: " + arrayIndexFirstDifferent; } } else // allEqual && IsPrivate { if (isArray) { if (fieldInfo.FieldType == typeof(Int32[])) { if (firstValue.Equals((Int32)0)) continue; } else if (fieldInfo.FieldType == typeof(byte[])) { if (firstValue.Equals((byte)0x00)) continue; } else { Debug.Assert(false, "Unexpected Array Type: " + fieldInfo.FieldType); } if (outputAttribute != null && firstValue.Equals(outputAttribute.ConstantValue)) continue; message = String.Format("Warning: Private column (Type = {2}, StructureId = 0x{3}) \"{0}\" has constant value not zero \"{1}\"", fieldInfo.Name, firstValue, fieldInfo.FieldType, structureId.ToString("X8")); } else // not array { if (firstValue.Equals(constValue)) continue; if (fieldInfo.FieldType == typeof(Int32) && ((Int32)firstValue == 0 && (firstValue.Equals(constValue) || constValue == null))) continue; if (fieldInfo.FieldType == typeof(Int16) && ((Int16)firstValue == 0 && (firstValue.Equals(constValue) || constValue == null))) continue; message = String.Format("Warning: Private column (Type = {2}, StructureId = 0x{3}) \"{0}\" has constant value not zero \"{1}\"", fieldInfo.Name, firstValue, fieldInfo.FieldType, structureId.ToString("X8")); if (outputAttribute != null && outputAttribute.ConstantValue != null) message += " (outputAttribute.ConstantValue is set)"; } } } else // IsPublic { if (ignoreConstCheck) continue; if (allEqual && fieldInfo.IsPublic && rowCount != 1 && (outputAttribute == null || outputAttribute.ConstantValue == null)) { message = String.Format("Notice: Public column (Type = {2}, StructureId = 0x{3}) \"{0}\" has constant value \"{1}\"", fieldInfo.Name, firstValue, fieldInfo.FieldType, structureId.ToString("X8")); } } if (message == null) continue; uint[] messageCounts; if (outputMessages.TryGetValue(message, out messageCounts)) { outputMessages[message] = new[] { messageCounts[0] + 1, structureId }; } else { outputMessages.Add(message, new uint[] { 1, structureId }); } } //int bp3 = 0; } String previousStringId = null; StringWriter stringWriter = new StringWriter(); foreach (KeyValuePair<String, uint[]> message in outputMessages) { String msg = message.Key; uint msgCount = message.Value[0]; uint forStructureId = message.Value[1]; uint structureCount = rowTypeCounts[forStructureId]; if (structureCount != msgCount) continue; // if not equal, then we have a message in one table, but in another table it's not applicable String[] stringIds1 = (from dataTableAttribute in DataFile.DataFileMap where dataTableAttribute.Value.StructureId == forStructureId select dataTableAttribute.Key).ToArray(); String[] stringIds2 = (from dataTableAttribute in DataFile.DataFileMapTestCenter where dataTableAttribute.Value.StructureId == forStructureId select dataTableAttribute.Key).ToArray(); String[] stringIds3 = (from dataTableAttribute in DataFile.DataFileMapResurrection where dataTableAttribute.Value.StructureId == forStructureId select dataTableAttribute.Key).ToArray(); String[] stringIds4 = (from dataTableAttribute in DataFile.DataFileMapMod where dataTableAttribute.Value.StructureId == forStructureId select dataTableAttribute.Key).ToArray(); String stringIdPrepend = String.Join(",", stringIds1) + String.Join(",", stringIds2) + String.Join(",", stringIds3) + String.Join(",", stringIds4); if (previousStringId != stringIdPrepend) { //Console.WriteLine(stringIdPrepend); stringWriter.WriteLine(stringIdPrepend); previousStringId = stringIdPrepend; } //Console.WriteLine(msg); stringWriter.WriteLine(msg); } File.WriteAllText(@"C:\asdf.txt", stringWriter.ToString()); }
/// <summary> /// This function is to test excel CSV cooking. /// </summary> public static void DoCookTest() { FileManager fileManager = new FileManager(Config.HglDir); fileManager.LoadTableFiles(); fileManager.ExtractAllExcel(); ExcelScript.GlobalDebug(true); foreach (PackFileEntry fileEntry in fileManager.FileEntries.Values) { if (!fileEntry.Name.EndsWith(ExcelFile.Extension)) continue; byte[] fileBytes = fileManager.GetFileBytes(fileEntry, true); Debug.Assert(fileBytes != null); String filePath = Path.Combine(Config.HglDir, fileEntry.Path); ExcelFile excelFile = new ExcelFile(fileBytes, fileEntry.Path); if (excelFile.Attributes.IsEmpty) continue; Console.WriteLine("Cooking file: " + fileEntry.Path); //if (!fileEntry.RelativeFullPathWithoutPatch.Contains("display_item")) continue; byte[] csvBytes = excelFile.ExportCSV(fileManager); File.WriteAllBytes(filePath.Replace(ExcelFile.Extension, ExcelFile.ExtensionDeserialised), csvBytes); ExcelFile excelFileCSV = new ExcelFile(fileEntry.Path); excelFileCSV.ParseCSV(csvBytes, fileManager); //byte[] recookedBytes = excelFileCSV.ToByteArray(); byte[] csvBytes2 = excelFileCSV.ExportCSV(fileManager); //if (!csvBytes.SequenceEqual(csvBytes2)) //{ // int b5p = 0; //} //if (excelFile.StringId == "GLOBAL_STRING") //{ // ExcelFile temp = new ExcelFile(recookedBytes, fileEntry.RelativeFullPathWithoutPatch); // int bp1 = 0; //} //File.WriteAllBytes(filePath, recookedBytes); } //int bp = 0; }
public static void CheckIdenticalFieldsToTCv4() { FileManager fileManager = new FileManager(Config.HglDir); fileManager.ExtractAllExcel(); FileManager fileManagerTCv4 = new FileManager(Config.HglDir, FileManager.ClientVersions.TestCenter); fileManager.LoadTableFiles(); fileManagerTCv4.LoadTableFiles(true); foreach (ExcelFile excelFile in fileManager.DataFiles.Values.Where(dataFile => dataFile.IsExcelFile)) { Debug.WriteLine("Checking: " + excelFile.StringId); if (excelFile.StringId == "LANGUAGE" || excelFile.StringId == "REGION") continue; ; ObjectDelegator objectDelegator = fileManager.DataFileDelegators[excelFile.StringId]; ObjectDelegator objectDelegatorTCv4 = fileManagerTCv4.DataFileDelegators["_TCv4_" + excelFile.StringId]; foreach (ObjectDelegator.FieldDelegate fieldDelegate in objectDelegator) { ObjectDelegator.FieldDelegate fieldDelegateTCv4 = objectDelegatorTCv4.GetFieldDelegate(fieldDelegate.Name); if (fieldDelegateTCv4 == null) { if (fieldDelegate.Name == "blendOpAdventurer") continue; // field removed in TCv4 from WARDROBE_LAYER if (fieldDelegate.Name == "unitVersionToGetSkillRespec") continue; // field removed in TCv4 from CHAR_DISPLAY if (fieldDelegate.Name == "String") continue; // field removed in TCv4 from RECIPIES if (fieldDelegate.Name == "unknown5") continue; // field removed in TCv4 from LEVEL if (fieldDelegate.Name == "undefined11a") continue; // field removed in TCv4 from STATS Debug.WriteLine(String.Format("Field '{0}' not found in TCv4 table.", fieldDelegate.Name)); continue; } // check excel attributes ExcelFile.OutputAttribute outputAttribute = ExcelFile.GetExcelAttribute(fieldDelegate.Info); ExcelFile.OutputAttribute outputAttributeTCv4 = ExcelFile.GetExcelAttribute(fieldDelegateTCv4.Info); if (!Equals(outputAttribute, outputAttributeTCv4)) { Debug.WriteLine(String.Format("Field '{0}' doesn't have matching excel attributes.", fieldDelegate.Name)); } // check field types if (fieldDelegate.FieldType.BaseType == typeof(Array)) { if (fieldDelegateTCv4.FieldType.BaseType != typeof(Array)) { Debug.WriteLine(String.Format("Field '{0}' is of type array, but TCv4 field is not.", fieldDelegate.Name)); continue; } MarshalAsAttribute arrayMarshal = (MarshalAsAttribute)fieldDelegate.Info.GetCustomAttributes(typeof(MarshalAsAttribute), false).First(); MarshalAsAttribute arrayMarshalTCv4 = (MarshalAsAttribute)fieldDelegateTCv4.Info.GetCustomAttributes(typeof(MarshalAsAttribute), false).First(); if (arrayMarshal.SizeConst == arrayMarshalTCv4.SizeConst) continue; Debug.WriteLine(String.Format("Array fields '{0}' have lengths '{1}' != '{2}'", fieldDelegate.Name, arrayMarshal.SizeConst, arrayMarshalTCv4.SizeConst)); } // check field accessor if (fieldDelegate.IsPublic && !fieldDelegateTCv4.IsPublic) { Debug.WriteLine(String.Format("Field '{0}' is public, but not so in TCv4 class.", fieldDelegate.Name)); } else if (fieldDelegate.IsPrivate && !fieldDelegateTCv4.IsPrivate) { Debug.WriteLine(String.Format("Field '{0}' is private, but not so in TCv4 class.", fieldDelegate.Name)); } if (fieldDelegate.FieldType == fieldDelegateTCv4.FieldType || fieldDelegate.FieldType.BaseType == typeof(Enum)) continue; Debug.WriteLine(String.Format("Field '{0}' of type '{1}' does not match TCv4 of type '{2}'", fieldDelegate.Name, fieldDelegate.FieldType, fieldDelegateTCv4.FieldType)); } } }
private void bw_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; FileManager HellgateFileManager; string cookingMessage = "Cooking {0}..."; string path = RevivalMod.DataPath; string[] excelToCook = null; string[] stringsToCook = null; string[] xmlToCook = null; string[] filesToPack = null; // Step One: Initialize the FileManager toolStripStatusLabel.Text = "Initializing the Hellgate File Manager..."; HellgateFileManager = new FileManager(Config.HglDir); if (HellgateFileManager.HasIntegrity == false) { Console.WriteLine("Could not initialize the File Manager, Integrity check failed."); e.Cancel = true; string caption = "Integrity Error"; string message = "Could not initialize the File Manager. Check Hellgate London is not running and that the installation is not corrupt."; MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Check if the user wants to cancel. if (backgroundWorker.CancellationPending) { e.Cancel = true; return; } // Step Two: Revert modifications automatically if flagged in the mod install xml. if (RevivalMod.Data.Modifications.DoRevert == true) { DialogResult dialogResult = DialogResult.Retry; while (dialogResult == DialogResult.Retry) { toolStripStatusLabel.Text = "Reverting previous Hellgate London modifications..."; bool error = Modification.RemoveModifications(HellgateFileManager); if (error == true) { string caption = "Reversion Error"; string message = "One or more errors occurred while reverting Hellgate London modifications. Check Hellgate London is not running and the files are not in use. It is highly recommended you ammend this before continuing, even if it means reinstalling the game."; dialogResult = MessageBox.Show(message, caption, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error); if (dialogResult == DialogResult.Abort) { e.Cancel = true; return; } } else { break; } } toolStripStatusLabel.Text = "Reloading the Hellgate File Manager..."; HellgateFileManager.Reload(); } // Check if the user wants to cancel. if (backgroundWorker.CancellationPending) { e.Cancel = true; return; } // Load the Excel tables toolStripStatusLabel.Text = "Caching the Hellgate London excel tables..."; HellgateFileManager.LoadTableFiles(); // Step Three: Cook Excel, String and XML files. // Search for files to cook excelToCook = Hellpack.SearchForExcelFiles(path); stringsToCook = Hellpack.SearchForStringFiles(path); xmlToCook = Hellpack.SearchForXmlFiles(path); if (excelToCook != null) { for (int i = 0; i < excelToCook.Length; i++) { // Check if the user wants to cancel. if (backgroundWorker.CancellationPending) { e.Cancel = true; return; } string epath = excelToCook[i]; string hglPath = epath.Substring(epath.IndexOf("data"), epath.Length - epath.IndexOf("data")); string report = String.Format(cookingMessage, hglPath); toolStripStatusLabel.Text = report; Hellpack.CookExcelFile(epath); } } if (stringsToCook != null) { for (int i = 0; i < stringsToCook.Length; i++) { // Check if the user wants to cancel. if (backgroundWorker.CancellationPending) { e.Cancel = true; return; } string epath = stringsToCook[i]; string hglPath = epath.Substring(epath.IndexOf("data"), epath.Length - epath.IndexOf("data")); string report = String.Format(cookingMessage, hglPath); toolStripStatusLabel.Text = report; Hellpack.CookStringFile(epath); } } if (xmlToCook != null) { for (int i = 0; i < xmlToCook.Length; i++) { // Check if the user wants to cancel. if (backgroundWorker.CancellationPending) { e.Cancel = true; return; } string epath = xmlToCook[i]; string hglPath = epath.Substring(epath.IndexOf("data"), epath.Length - epath.IndexOf("data")); string report = String.Format(cookingMessage, hglPath); toolStripStatusLabel.Text = report; Hellpack.CookXmlFile(epath, HellgateFileManager); } } // Step Four: Pack the base idx/dat. filesToPack = Hellpack.SearchForFilesToPack(path, true); toolStripStatusLabel.Text = String.Format("Packing {0}...", RevivalMod.Data.Modifications.ID + ".idx"); string hglDataPath = Path.Combine(Config.HglDir, "data"); string modDatPath = Path.Combine(hglDataPath, RevivalMod.Data.Modifications.ID) + ".idx"; bool packResult = Hellpack.PackDatFile(filesToPack, modDatPath, true); if (packResult == false) { HellgateFileManager.Dispose(); string caption = "Fatal Error"; string message = "An error occurred while packing the modification."; MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Step Five: Apply scripts. Scripts are only applied if they are checked or are hidden. if (optionalCheckedListBox.CheckedItems.Count != 0 || RevivalMod.Data.Modifications.Scripts.Where(s => s.Type == "hidden").Any() == true) { List<Script> scriptList = new List<Script>(); // Append optional list foreach (Script script in optionalCheckedListBox.CheckedItems) { scriptList.Add(script); } // Append hidden list foreach (Script script in RevivalMod.Data.Modifications.Scripts.Where(s => s.Type == "hidden")) { scriptList.Add(script); } // Reinitalize the File Manager HellgateFileManager.Reload(); HellgateFileManager.LoadTableFiles(); string indexPath = Path.Combine(Config.HglDir, "data", RevivalMod.Data.Modifications.ID + "_125.idx"); IndexFile indexFile = new IndexFile(indexPath); // Apply the scripts List<string> modifiedTables = new List<string>(); foreach (Script script in scriptList) { // Interface stuff toolStripStatusLabel.Text = String.Format("Applying {0} script...", script.Title); if (script.Extraction != null) { toolStripStatusLabel.Text = "MP conversion in progress, this may between 5 and 10 minutes."; } // The script Modification.ApplyScript(script, ref HellgateFileManager); if (script.Tables != null) { foreach (Script.Table table in script.Tables) { string tableID = table.ID.ToUpper(); if (modifiedTables.Contains(tableID) == false) modifiedTables.Add(tableID); } } // Copy files if any if (String.IsNullOrEmpty(script.ID) == false) { string optionalPath = Path.Combine(path, "optional", script.ID); if (Directory.Exists(optionalPath) == false) continue; string[] fileList = Directory.GetFiles(optionalPath, "*", SearchOption.AllDirectories); if (fileList == null) continue; if (fileList.Length == 0) continue; foreach (string filePath in fileList) { string relativePath = filePath.Replace(optionalPath + "\\", ""); string directory = Path.GetDirectoryName(relativePath) + "\\"; string fileName = Path.GetFileName(relativePath); byte[] fbuffer = null; try { fbuffer = File.ReadAllBytes(filePath); } catch (Exception ex) { ExceptionLogger.LogException(ex); continue; } indexFile.AddFile(directory, fileName, fbuffer, DateTime.Now); } } } // Repack the modified Tables. // These go in their own idx/dat under the same name as the base modification with the string _125 appended. foreach (string tableID in modifiedTables) { DataFile dataTable = HellgateFileManager.DataFiles[tableID]; byte[] ebuffer = dataTable.ToByteArray(); string fileName = Path.GetFileName(dataTable.FilePath); string fileDir = Path.GetDirectoryName(dataTable.FilePath) + "\\"; indexFile.AddFile(fileDir, fileName, ebuffer, DateTime.Now); } if (indexFile.Count > 0) { // Write the index byte[] ibuffer = indexFile.ToByteArray(); Crypt.Encrypt(ibuffer); try { File.WriteAllBytes(indexPath, ibuffer); HellgateFileManager.Dispose(); indexFile.EndDatAccess(); indexFile.Dispose(); } catch(Exception ex) { ExceptionLogger.LogException(ex); HellgateFileManager.Dispose(); indexFile.EndDatAccess(); indexFile.Dispose(); string caption = "Fatal Error"; string message = "An error occurred while packing the optional modification."; MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } string msgCaption = "Success"; string msgDescription = "Modification successfully installed!"; MessageBox.Show(msgDescription, msgCaption, MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void bw_DoWorkRevert(object sender, DoWorkEventArgs e) { HellgateFileManager = new FileManager(Config.HglDir); if (HellgateFileManager.HasIntegrity == false) { string errCaption = "Error"; string errMessage = "Could not initialize the File Manager. The Hellgate London directory is not set correctly or the installation is damaged beyond repair."; MessageBox.Show(errMessage, errCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } bool errorOccurred = false; // Remove the backup prefix, used in pre 1.5 patches or Reanimator/Hellzap foreach (IndexFile indexFile in HellgateFileManager.IndexFiles) { bool isModified = false; foreach (PackFileEntry fileEntry in indexFile.Files) { if (!fileEntry.IsPatchedOut) continue; fileEntry.IsPatchedOut = false; isModified = true; } if (!isModified) continue; byte[] ibuffer = indexFile.ToByteArray(); Crypt.Encrypt(ibuffer); try { File.WriteAllBytes(indexFile.FilePath, ibuffer); } catch { errorOccurred = true; } } // Delete all dats the arn't original string hellgateDatPath = Path.Combine(Config.HglDir, "data"); List<string> hellgateDats = new List<string>(); hellgateDats.AddRange(Directory.GetFiles(hellgateDatPath, "*.idx")); hellgateDats.AddRange(Directory.GetFiles(hellgateDatPath, "*.dat")); foreach (string datPath in hellgateDats) { string fileName = Path.GetFileName(datPath); if (Common.OriginalDats.Where(dat => String.Format("{0}.idx", dat) == fileName || String.Format("{0}.dat", dat) == fileName).Any() == false) { try { File.Delete(datPath); } catch { errorOccurred = true; } } } string captionMsg = "Revert Complete"; string revertMsg = errorOccurred ? "Revert complete but with errors." : "Revert successfully complete"; MessageBox.Show(revertMsg, captionMsg, MessageBoxButtons.OK, MessageBoxIcon.Information); }
public MonsterAffixes(FileManager manager) : base(manager, "monster_affixes") { }
/// <summary> /// Function to test saving/importing/exported/etc relating to DataTables (i.e. actions from WITHIN Reanimator etc.) /// </summary> public static void TestDataTableExportAndImport(bool doTCv4 = false) { /* bytesXls Bytes->Xls bytesXlsBytes Bytes->Xls->Bytes bytesXlsCsv Bytes->Xls->CSV bytesXlsCsvXls Bytes->Xls->CSV->Xls bytesXlsCsvXlsBytes Bytes->Xls->CSV->Xls->Bytes == bytesXlsTableXlsBytes as single byte is stripped ->CSV bytesXlsTable Bytes->Xls->Table bytesXlsTableXls Bytes->Xls->Table->Xls bytesXlsTableXlsBytes Bytes->Xls->Table->Xls->Bytes != bytesXlsBytes because of single script byte thingy lost to table bytesXlsTableXlsCsv Bytes->Xls->Table->Xls->CSV bytesXlsTableXlsCsvXls Bytes->Xls->Table->Xls->CSV->Xls bytesXlsTableXlsCsvXlsBytes Bytes->Xls->Table->Xls->CSV->Xls->Bytes byte[] bytesXlsBytes = bytesXls.ToByteArray(); byte[] bytesXlsTableXlsCsvXlsBytes = bytesXlsTableXlsCsvXls.ToByteArray(); */ String root = @"C:\excel_datatable_debug"; FileManager.ClientVersions clientVersion = FileManager.ClientVersions.SinglePlayer; if (doTCv4) { root = Path.Combine(root, "tcv4"); clientVersion = FileManager.ClientVersions.TestCenter; } root += @"\"; // lazy Directory.CreateDirectory(root); FileManager fileManager = new FileManager(Config.HglDir, clientVersion); fileManager.BeginAllDatReadAccess(); fileManager.LoadTableFiles(); List<String> sequenceFailed = new List<String>(); List<String> sequenceChecked = new List<String>(); foreach (KeyValuePair<String, DataFile> keyValuePair in fileManager.DataFiles) { String stringId = keyValuePair.Key; DataFile dataFile = keyValuePair.Value; if (dataFile.IsStringsFile) continue; //if (stringId != "WARDROBE_LAYER") continue; //if (stringId == "WARDROBE_LAYER") //{ // int bp = 0; //} Debug.Write("Checking " + stringId + "... "); ExcelFile bytesXls = (ExcelFile)dataFile; byte[] bytes = fileManager.GetFileBytes(bytesXls.FilePath, true); sequenceChecked.Add(stringId); sequenceFailed.Add(stringId); if (stringId == "PROPERTIES") continue; // can't do this atm - need to export Properties script table to DataTable etc. Debug.Write("DataTable... "); DataTable bytesXlsTable = fileManager.GetDataTable(stringId); if (bytesXlsTable == null) { Debug.WriteLine("FAILED!"); continue; } // parse as DataTable Debug.Write("new Excel... "); DataFile bytesXlsTableXls = new ExcelFile(bytesXls.FilePath, fileManager.ClientVersion); if (!bytesXlsTableXls.ParseDataTable(bytesXlsTable, fileManager)) { Debug.WriteLine("FAILED!"); continue; } // check just data table import/export byte[] bytesXlsBytes = bytesXls.ToByteArray(); byte[] bytesXlsTableXlsBytes = bytesXlsTableXls.ToByteArray(); if (bytesXls.ScriptBuffer == null && // can't check this as ScriptBuffer[0] is NOT always 0x00 (even though it's unused and means no script normally when pointed to) !bytesXls.HasStringBuffer) // as above - gets re-arranged etc (only consistant comparint CSV->XLS->DATA { Debug.Write("bytesXlsBytes==bytesXlsTableXlsBytes... "); if (!bytesXlsBytes.SequenceEqual(bytesXlsTableXlsBytes)) { Debug.WriteLine("FALSE!"); File.WriteAllBytes(root + bytesXls.StringId + "0.bytes", bytes); File.WriteAllBytes(root + bytesXls.StringId + "1.bytesXlsBytes", bytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "2.bytesXlsTableXlsBytes", bytesXlsTableXlsBytes); continue; } } // export CSV Debug.Write("ExportCSV... "); byte[] bytesXlsTableXlsCsv = bytesXlsTableXls.ExportCSV(fileManager); if (bytesXlsTableXlsCsv == null) { Debug.WriteLine("FAILED!"); continue; } Debug.Write("bytesXlsCsv==bytesXlsTableXlsCsv... "); byte[] bytesXlsCsv = bytesXls.ExportCSV(fileManager); if (!bytesXlsCsv.SequenceEqual(bytesXlsTableXlsCsv)) { Debug.WriteLine("FALSE!"); File.WriteAllBytes(root + bytesXls.StringId + "0.bytes", bytes); File.WriteAllBytes(root + bytesXls.StringId + "1.bytesXlsBytes", bytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1a.bytesXlsCsv.csv", bytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "2.bytesXlsTableXlsBytes", bytesXlsTableXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "3.bytesXlsTableXlsCsv.csv", bytesXlsTableXlsCsv); continue; } Debug.Write("bytesXlsCsvXlsBytes==bytesXlsTableXlsBytes... "); DataFile bytesXlsCsvXls = new ExcelFile(bytesXls.FilePath, fileManager.ClientVersion); bytesXlsCsvXls.ParseCSV(bytesXlsCsv, fileManager); byte[] bytesXlsCsvXlsBytes = bytesXlsCsvXls.ToByteArray(); if (!bytesXlsCsvXlsBytes.SequenceEqual(bytesXlsTableXlsBytes) && stringId != "ITEMDISPLAY" && stringId != "LEVEL") // ITEMDISPLAY has weird single non-standard ASCII char that is lost (from using MS Work on their part lol) { // and LEVEL references blank TREASURE rows and hence rowId references differ on recooks Debug.WriteLine("FALSE!"); File.WriteAllBytes(root + bytesXls.StringId + "0.bytes", bytes); File.WriteAllBytes(root + bytesXls.StringId + "1.bytesXlsBytes", bytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1a.bytesXlsCsv.csv", bytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "1b.bytesXlsCsvXlsBytes", bytesXlsCsvXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "2.bytesXlsTableXlsBytes", bytesXlsTableXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "3.bytesXlsTableXlsCsv.csv", bytesXlsTableXlsCsv); continue; } // import CSV Debug.Write("ParseCSV... "); DataFile bytesXlsTableXlsCsvXls = new ExcelFile(bytesXls.FilePath, fileManager.ClientVersion); if (!bytesXlsTableXlsCsvXls.ParseCSV(bytesXlsTableXlsCsv, fileManager)) { Debug.WriteLine("FAILED!"); continue; } // export imported as cooked and do byte compare Debug.Write("ToByteArray... "); byte[] bytesXlsTableXlsCsvXlsBytes = bytesXlsTableXlsCsvXls.ToByteArray(); Debug.Write("bytesXlsCsvXlsBytes==bytesXlsTableXlsCsvXlsBytes... "); if (!bytesXlsCsvXlsBytes.SequenceEqual(bytesXlsTableXlsCsvXlsBytes)) { Debug.WriteLine("FALSE!"); File.WriteAllBytes(root + bytesXls.StringId + "0.bytes", bytes); File.WriteAllBytes(root + bytesXls.StringId + "1.bytesXlsBytes", bytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "2.bytesXlsTableXlsBytes", bytesXlsTableXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "3.bytesXlsTableXlsCsv", bytesXlsTableXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "4.bytesXlsTableXlsCsvXlsBytes", bytesXlsTableXlsCsvXlsBytes); continue; } // yay Debug.WriteLine("OK!"); sequenceFailed.RemoveAt(sequenceFailed.Count - 1); } Debug.WriteLine("Totals: {0} sequence checks, {1} fails. ({2}% failed!)", sequenceChecked.Count, sequenceFailed.Count, (float)sequenceFailed.Count * 100f / sequenceChecked.Count); Debug.Write("Failed Tables: "); foreach (String stringIdFailed in sequenceFailed) { Debug.Write(stringIdFailed + ", "); } }
public NewNewTreasure(FileManager manager) : base(manager, "treasure") { }
/// <summary> /// Function to test all excel files cooking/recooking/etc to/from byte arrays and csv types. /// </summary> public static void TestExcelCooking(bool doTCv4 = false) { /* 0 0 byte[] fileBytes = fileManager.GetFileBytes(excelFile.FilePath, true); Bytes 0-gen bytes 0 1 2 3 4 foreach (DataFile dataFile in fileManager.DataFiles.Values) Bytes->Xls 1-gen Xls file 1 byte[] dataFileBytes = dataFile.ToByteArray(); Bytes->Xls->Bytes 1-gen bytes fromBytesExcel.ParseData(dataFileBytes); Bytes->Xls->Bytes->Xls 2-gen Xls file 1a byte[] bytesXlsBytesXlsBytes = fromBytesExcel.ToByteArray(); Bytes->Xls->Bytes->Xls->Bytes 2-gen bytes 1ba byte[] bytesXlsCsv = dataFile.ExportCSV(fileManager); Bytes->Xls->CSV 1-gen CSV-bytes bytesXlsCsvXls.ParseCSV(bytesXlsCsv, fileManager); Bytes->Xls->CSV ->Xls 2-gen Xls file 1bb byte[] bytesXlsCsvXlsBytes = bytesXlsCsvXls.ToByteArray(); Bytes->Xls->CSV ->Xls->Bytes 2-gen CSV-bytes 1b byte[] csvBytes = fromBytesExcel.ExportCSV(fileManager); Bytes->Xls->Bytes->Xls->CSV 2-gen CSV file csvExcel.ParseCSV(csvBytes, fileManager); Bytes->Xls->Bytes->Xls->CSV->Xls 3-gen Xls file 1c byte[] bytesXlsBytesXlsCsvXlsBytes = csvExcel.ToByteArray(); Bytes->Xls->Bytes->Xls->CSV->Xls->Bytes 3-gen bytes finalExcel.ParseData(recookedExcelBytes); Bytes->Xls->Bytes->Xls->CSV->Xls->Bytes->Xls 4-gen Xls file 1d byte[] csvCheck = finalExcel.ExportCSV(fileManager); Bytes->Xls->Bytes->Xls->CSV->Xls->Bytes->Xls->CSV 4-gen CSV file 1e byte[] finalCheck = finalExcel.ToByteArray(); Bytes->Xls->Bytes->Xls->CSV->Xls->Bytes->Xls->Bytes 4-gen bytes */ String root = @"C:\excel_debug"; FileManager.ClientVersions clientVersion = FileManager.ClientVersions.SinglePlayer; if (doTCv4) { root = Path.Combine(root, "tcv4"); clientVersion = FileManager.ClientVersions.TestCenter; } root += @"\"; // lazy Directory.CreateDirectory(root); FileManager fileManager = new FileManager(Config.HglDir, clientVersion); fileManager.BeginAllDatReadAccess(); fileManager.LoadTableFiles(); ExcelFile.EnableDebug = true; int checkedCount = 0; List<String> excelFailed = new List<String>(); foreach (DataFile bytesXls in fileManager.DataFiles.Values) { ExcelFile excelFile = bytesXls as ExcelFile; if (excelFile == null) continue; const String debugStr = "SKILLS"; //if (excelFile.StringId != debugStr) continue; //if (excelFile.StringId == debugStr) //{ // int bp = 0; //} checkedCount++; Debug.Write(String.Format("Checking {0}... ", bytesXls.StringId)); byte[] bytes = fileManager.GetFileBytes(excelFile.FilePath, true); try { byte[] bytesXlsBytes = bytesXls.ToByteArray(); if (bytesXls.StringId == "SOUNDS" && false) { byte[] csvBytesSounds = excelFile.ExportCSV(fileManager); ExcelFile soundsCSV = new ExcelFile(excelFile.FilePath); soundsCSV.ParseCSV(csvBytesSounds, fileManager); byte[] soundsBytes = soundsCSV.ToByteArray(); //byte[] soundsBytesFromCSV = soundsCSV.ExportCSV(); //ExcelFile soundsCSVFromBytesFromCSV = new ExcelFile(soundsBytesFromCSV, fileEntry.RelativeFullPathWithoutPatch); // some brute force ftw byte[][] bytesArrays = new[] { bytes, soundsBytes }; for (int z = 0; z < bytesArrays.Length; z++) { byte[] bytesBrute = bytesArrays[z]; int offset = 0x20; int stringsBytesCount = FileTools.ByteArrayToInt32(bytesBrute, ref offset); StringWriter stringWriterByteStrings = new StringWriter(); stringWriterByteStrings.WriteLine(stringsBytesCount + " bytes"); List<String> strings = new List<String>(); List<int> offsets = new List<int>(); while (offset < stringsBytesCount + 0x20) { String str = FileTools.ByteArrayToStringASCII(bytesBrute, offset); strings.Add(str); offsets.Add(offset); offset += str.Length + 1; } String[] sortedStrings = strings.ToArray(); int[] sortedOffsets = offsets.ToArray(); Array.Sort(sortedStrings, sortedOffsets); stringWriterByteStrings.WriteLine(strings.Count + " strings"); for (int i = 0; i < strings.Count; i++) { stringWriterByteStrings.WriteLine(sortedStrings[i] + "\t\t\t" + sortedOffsets[i]); } File.WriteAllText(@"C:\excel_debug\strings" + z + ".txt", stringWriterByteStrings.ToString()); } } Debug.Write("ToByteArray... "); if (bytes.Length != bytesXlsBytes.Length && !doTCv4) // some TCv4 tables don't have their sort columns yet { Debug.WriteLine("ToByteArray() dataFileBytes has differing length: " + bytesXls.StringId); File.WriteAllBytes(root + bytesXls.StringId + "0.bytes", bytes); File.WriteAllBytes(root + bytesXls.StringId + "1.bytesXlsBytes", bytesXlsBytes); excelFailed.Add(bytesXls.StringId); continue; } ExcelFile bytesXlsBytesXls = new ExcelFile(excelFile.FilePath, fileManager.ClientVersion); bytesXlsBytesXls.ParseData(bytesXlsBytes); Debug.Write("new ExcelFile... "); if (!bytesXlsBytesXls.HasIntegrity) { Debug.WriteLine("fromBytesExcel = new Excel from ToByteArray() failed!"); File.WriteAllBytes(root + bytesXls.StringId + "0.bytes", bytes); File.WriteAllBytes(root + bytesXls.StringId + "1.bytesXlsBytes", bytesXlsBytes); excelFailed.Add(bytesXls.StringId); continue; } // more checks Debug.Write("ToByteArray->ToByteArray... "); byte[] bytesXlsBytesXlsBytes = bytesXlsBytesXls.ToByteArray(); // bytesXlsBytesXlsBytes if (bytes.Length != bytesXlsBytesXlsBytes.Length && !doTCv4) // some TCv4 tables don't have their sort columns yet { Debug.WriteLine("ToByteArray() dataFileBytesFromToByteArray has differing length!"); File.WriteAllBytes(root + bytesXls.StringId + "0.bytes", bytes); File.WriteAllBytes(root + bytesXls.StringId + "1.bytesXlsBytes", bytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1a.toByteArrayFromByteArray", bytesXlsBytesXlsBytes); excelFailed.Add(bytesXls.StringId); continue; } // check generated sort index arrays); Debug.Write("IndexSortArrays... "); if (excelFile.IndexSortArray != null) { if (bytesXlsBytesXls.IndexSortArray == null || excelFile.IndexSortArray.Count != bytesXlsBytesXls.IndexSortArray.Count) { Debug.WriteLine("fromBytesExcel has not-matching IndexSortArray count!"); excelFailed.Add(bytesXls.StringId); continue; } bool hasError = false; for (int i = 0; i < excelFile.IndexSortArray.Count; i++) { if (excelFile.IndexSortArray[i].SequenceEqual(bytesXlsBytesXls.IndexSortArray[i])) continue; Debug.WriteLine(String.Format("IndexSortArray[{0}] NOT EQUAL to original!", i)); hasError = true; } if (hasError) { File.WriteAllBytes(root + bytesXls.StringId + "0.bytes", bytes); File.WriteAllBytes(root + bytesXls.StringId + "1.bytesXlsBytes", bytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1a.bytesXlsBytesXlsBytes", bytesXlsBytesXlsBytes); excelFailed.Add(bytesXls.StringId); continue; } } // some csv stuff Debug.Write("BaseXls->BaseCSV=="); byte[] bytesXlsCsv = bytesXls.ExportCSV(fileManager); // Bytes->Xls->CSV Debug.Write("ExportCSV... "); byte[] bytesXlsBytesXlsCsv = bytesXlsBytesXls.ExportCSV(fileManager); if (!bytesXlsCsv.SequenceEqual(bytesXlsBytesXlsCsv)) { Debug.WriteLine("FALSE!"); File.WriteAllBytes(root + bytesXls.StringId + "0.bytes", bytes); File.WriteAllBytes(root + bytesXls.StringId + "1.bytesXlsBytes", bytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1a.bytesXlsBytesXlsBytes", bytesXlsBytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1b.bytesXlsBytesXlsCsv.csv", bytesXlsBytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "1ba.bytesXlsCsv.csv", bytesXlsCsv); excelFailed.Add(bytesXls.StringId); continue; } ExcelFile bytesXlsCsvXls = new ExcelFile(excelFile.FilePath, fileManager.ClientVersion); bytesXlsCsvXls.ParseCSV(bytesXlsCsv, fileManager); byte[] bytesXlsCsvXlsBytes = bytesXlsCsvXls.ToByteArray(); // used later as well if (excelFile.ScriptBuffer == null && // can only compare here for no-script tables - can't compare to pure-base xls-bytes as xls->csv->xls rearranges script code !excelFile.HasStringBuffer) // xls->csv->xls also rearranges the strings buffer { Debug.Write("BytesXlsBytesXlsBytes==BytesXlsCsvXlsBytes... "); if (!bytesXlsBytesXlsBytes.SequenceEqual(bytesXlsCsvXlsBytes)) { Debug.WriteLine("FALSE!"); File.WriteAllBytes(root + bytesXls.StringId + "0.bytes", bytes); File.WriteAllBytes(root + bytesXls.StringId + "1.bytesXlsBytes", bytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1a.bytesXlsBytesXlsBytes", bytesXlsBytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1b.bytesXlsBytesXlsCsv.csv", bytesXlsBytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "1ba.bytesXlsCsv.csv", bytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "1bb.bytesXlsCsvXlsBytes", bytesXlsCsvXlsBytes); excelFailed.Add(bytesXls.StringId); continue; } Debug.Write("BytesXlsBytes==BytesXlsCsvXlsBytes... "); if (!bytesXlsBytes.SequenceEqual(bytesXlsCsvXlsBytes)) { Debug.WriteLine("FALSE!"); File.WriteAllBytes(root + bytesXls.StringId + "0.bytes", bytes); File.WriteAllBytes(root + bytesXls.StringId + "1.bytesXlsBytes", bytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1a.bytesXlsBytesXlsBytes", bytesXlsBytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1b.bytesXlsBytesXlsCsv.csv", bytesXlsBytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "1ba.bytesXlsCsv.csv", bytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "1bb.bytesXlsCsvXlsBytes", bytesXlsCsvXlsBytes); excelFailed.Add(bytesXls.StringId); continue; } } Debug.Write("BytesXlsBytesXlsCsv -> new ExcelFile"); ExcelFile bytesXlsBytesXlsCsvXls = new ExcelFile(excelFile.FilePath, fileManager.ClientVersion); bytesXlsBytesXlsCsvXls.ParseCSV(bytesXlsBytesXlsCsv, fileManager); Debug.Write("... "); if (!bytesXlsBytesXlsCsvXls.HasIntegrity) { Debug.WriteLine("Failed!"); File.WriteAllBytes(root + bytesXls.StringId + "0.bytes", bytes); File.WriteAllBytes(root + bytesXls.StringId + "1.bytesXlsBytes", bytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1a.bytesXlsBytesXlsBytes", bytesXlsBytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1b.bytesXlsBytesXlsCsv.csv", bytesXlsBytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "1ba.bytesXlsCsv.csv", bytesXlsCsv); excelFailed.Add(bytesXls.StringId); continue; } byte[] bytesXlsBytesXlsCsvXlsBytes = bytesXlsBytesXlsCsvXls.ToByteArray(); Debug.Write("BytesXlsCsvXlsBytes==BytesXlsBytesXlsCsvXlsBytes... "); if (!bytesXlsCsvXlsBytes.SequenceEqual(bytesXlsBytesXlsCsvXlsBytes)) { Debug.WriteLine("FALSE!"); File.WriteAllBytes(root + bytesXls.StringId + "0.bytes", bytes); File.WriteAllBytes(root + bytesXls.StringId + "1.bytesXlsBytes", bytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1a.bytesXlsBytesXlsBytes", bytesXlsBytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1b.bytesXlsBytesXlsCsv.csv", bytesXlsBytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "1ba.bytesXlsCsv.csv", bytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "1bb.bytesXlsCsvXlsBytes", bytesXlsCsvXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1c.bytesXlsBytesXlsCsvXlsBytes", bytesXlsBytesXlsCsvXlsBytes); excelFailed.Add(bytesXls.StringId); continue; } if (!fileManager.IsVersionTestCenter) { Debug.Write("StructureId... "); UInt32 structureId = BitConverter.ToUInt32(bytes, 4); UInt32 fromCSVStructureId = BitConverter.ToUInt32(bytesXlsBytesXlsCsvXlsBytes, 4); if (structureId != fromCSVStructureId) { Debug.WriteLine("Structure Id value do not match: " + structureId + " != " + fromCSVStructureId); excelFailed.Add(bytesXls.StringId); continue; } } Debug.Write("Almost Done... "); ExcelFile bytesXlsBytesXlsCsvXlsBytesXls = new ExcelFile(excelFile.FilePath, fileManager.ClientVersion); bytesXlsBytesXlsCsvXlsBytesXls.ParseData(bytesXlsBytesXlsCsvXlsBytes); byte[] bytesXlsBytesXlsCsvXlsBytesXlsCsv = bytesXlsBytesXlsCsvXlsBytesXls.ExportCSV(fileManager); int recookedLength = bytesXlsBytesXlsCsvXlsBytes.Length; if (excelFile.StringId == "SKILLS") recookedLength += 12; // 12 bytes in int ptr data not used/referenced at all and are removed/lost in bytes -> csv -> bytes if (bytes.Length != recookedLength && !doTCv4) // some TCv4 tables don't have their sort columns yet { Debug.WriteLine("Recooked Excel file has differing length!"); File.WriteAllBytes(root + bytesXls.StringId + "0.bytes", bytes); File.WriteAllBytes(root + bytesXls.StringId + "1.bytesXlsBytes", bytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1a.bytesXlsBytesXlsBytes", bytesXlsBytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1b.bytesXlsBytesXlsCsv.csv", bytesXlsBytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "1ba.bytesXlsCsv.csv", bytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "1c.bytesXlsBytesXlsCsvXlsBytes", bytesXlsBytesXlsCsvXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1d.bytesXlsBytesXlsCsvXlsBytesXlsCsv.csv", bytesXlsBytesXlsCsvXlsBytesXlsCsv); excelFailed.Add(bytesXls.StringId); continue; } Debug.Assert(bytesXlsBytesXlsCsvXlsBytesXls.HasIntegrity); byte[] bytesXlsBytesXlsCsvXlsBytesXlsBytes = bytesXlsBytesXlsCsvXlsBytesXls.ToByteArray(); if (excelFile.StringId == "SKILLS") Debug.Assert(bytesXlsBytesXlsCsvXlsBytesXlsBytes.Length + 12 == bytesXlsBytes.Length); else Debug.Assert(bytesXlsBytesXlsCsvXlsBytesXlsBytes.Length == bytesXlsBytes.Length || doTCv4); if (!bytesXlsBytesXlsCsv.SequenceEqual(bytesXlsBytesXlsCsvXlsBytesXlsCsv)) { Debug.WriteLine("csvBytes.SequenceEqual failed!"); File.WriteAllBytes(root + bytesXls.StringId + "0.bytes", bytes); File.WriteAllBytes(root + bytesXls.StringId + "1.bytesXlsBytes", bytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1a.bytesXlsBytesXlsBytes", bytesXlsBytesXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1b.bytesXlsBytesXlsCsv.csv", bytesXlsBytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "1ba.bytesXlsCsv.csv", bytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "1c.bytesXlsBytesXlsCsvXlsBytes", bytesXlsBytesXlsCsvXlsBytes); File.WriteAllBytes(root + bytesXls.StringId + "1d.bytesXlsBytesXlsCsvXlsBytesXlsCsv.csv", bytesXlsBytesXlsCsvXlsBytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + "1e.bytesXlsBytesXlsCsvXlsBytesXlsBytes", bytesXlsBytesXlsCsvXlsBytesXlsBytes); excelFailed.Add(bytesXls.StringId); continue; } Debug.Write("\nPerforming deep scan: "); ObjectDelegator objectDelegator = fileManager.DataFileDelegators[excelFile.StringId]; int lastPercent = 0; int col = 0; bool failed = false; foreach (FieldDelegate fieldDelegate in objectDelegator) { int percent = col * 100 / objectDelegator.FieldCount - 1; int dotCount = percent - lastPercent; for (int i = 0; i < dotCount; i++) Debug.Write("."); lastPercent = percent; ExcelFile.OutputAttribute excelAttribute = ExcelFile.GetExcelAttribute(fieldDelegate.Info); bool isArray = (fieldDelegate.FieldType.BaseType == typeof(Array)); for (int row = 0; row < excelFile.Rows.Count; row++) { Object obj1 = fieldDelegate.GetValue(excelFile.Rows[row]); Object obj2 = fieldDelegate.GetValue(bytesXlsBytesXlsCsvXlsBytesXls.Rows[row]); if (isArray) { //if (excelFile.StringId == "TREASURE") //{ // int bp = 0; //} IEnumerator arrayEnumator1 = ((Array)obj1).GetEnumerator(); IEnumerator arrayEnumator2 = ((Array)obj2).GetEnumerator(); int index = -1; while (arrayEnumator1.MoveNext() && arrayEnumator2.MoveNext()) { index++; Object elementVal1 = arrayEnumator1.Current; Object elementVal2 = arrayEnumator2.Current; if (elementVal1.Equals(elementVal2)) continue; Debug.WriteLine(String.Format("Array Element '{0}' != '{1}' on col({2}) = '{3}', row({4}), index({5})", elementVal1, elementVal2, col, fieldDelegate.Name, row, index)); failed = true; break; } if (failed) break; continue; } if (obj1.Equals(obj2)) continue; if (excelAttribute != null) { if (excelAttribute.IsStringOffset) { int offset1 = (int)obj1; int offset2 = (int)obj2; String str1 = excelFile.ReadStringTable(offset1); String str2 = bytesXlsBytesXlsCsvXlsBytesXls.ReadStringTable(offset2); if (str1 == str2) continue; obj1 = str1; obj2 = str2; } if (excelAttribute.IsScript) { int offset1 = (int)obj1; int offset2 = (int)obj2; Int32[] script1 = excelFile.ReadScriptTable(offset1); Int32[] script2 = bytesXlsBytesXlsCsvXlsBytesXls.ReadScriptTable(offset2); if (script1.SequenceEqual(script2)) continue; obj1 = script1.ToString(","); obj2 = script2.ToString(","); } } String str = obj1 as String; if ((str != null && str.StartsWith("+N%-N% base damage as [elem]")) || // "+N%-N% base damage as [elem]…" != "+N%-N% base damage as [elem]?" on col(2) = 'exampleDescription', row(132) // the '?' at end fieldDelegate.Name == "bonusStartingTreasure") // refernces multiple different blank rows continue; Debug.WriteLine(String.Format("'{0}' != '{1}' on col({2}) = '{3}', row({4})", obj1, obj2, col, fieldDelegate.Name, row)); failed = true; break; } if (failed) break; col++; } if (failed) { File.WriteAllBytes(root + bytesXls.StringId + ".bytesXlsBytesXlsCsv.csv", bytesXlsBytesXlsCsv); File.WriteAllBytes(root + bytesXls.StringId + ".bytesXlsBytesXlsCsvXlsBytesXlsCsv.csv", bytesXlsBytesXlsCsvXlsBytesXlsCsv); excelFailed.Add(bytesXls.StringId); continue; } Debug.WriteLine("OK\n"); } catch (Exception e) { Debug.WriteLine("Excel file Exception: " + bytesXls.StringId + "\n" + e); } } Debug.WriteLine(checkedCount + " excel files checked."); if (excelFailed.Count <= 0) return; Debug.WriteLine(excelFailed.Count + " failed excel checks! (" + ((float)excelFailed.Count / checkedCount * 100) + "%)"); foreach (String str in excelFailed) Debug.Write(str + ", "); }