Example #1
0
        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;
                }
            }
        }
        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);
            }
        }
Example #3
0
        /// <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 + ", ");
            }
        }
Example #4
0
        public CharacterValues(UnitObject unitObject, FileManager fileManager)
            : base(unitObject, fileManager)
        {
            try
            {
                //could also use "stat" column and "gold" entry
                DataRow[] goldRow = statsTable.Select("code = " + (int)ItemValueNames.gold);
                int maxPalladium = (int)goldRow[0]["maxSet"];

                _maxPalladium = maxPalladium;

                DataTable playersTable = fileManager.GetDataTable("PLAYERS");
                DataRow[] playerRows = playersTable.Select("code = " + UnitObject.UnitCode);
                int maxLevel = (int)playerRows[0]["maxLevel"];

                _maxLevel = maxLevel;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "CharacterValues");
            }
        }
Example #5
0
        public CharacterSkills(UnitObject unitObject, FileManager fileManager, IEnumerable<int> skillTabs)
            : base(unitObject, fileManager)
        {
            _skillTabs = new List<SkillTab>();

            //to make things easier, let's add all available character skills to the list
            List<UnitObjectStats.Stat.StatValue> availableSkills = new List<UnitObjectStats.Stat.StatValue>();
            ////get the skills the character already knows
            UnitObjectStats.Stat skills = UnitHelpFunctions.GetComplexValue(unitObject, ItemValueNames.skill_level);
            ////add them to the complete skill list
            availableSkills.AddRange(skills.Values);

            DataTable skillTable = fileManager.GetDataTable("SKILLS");

            //let's add all the skills the character doesn't know yet
            foreach (int skillTab in skillTabs)
            {
                DataRow[] skillRows = skillTable.Select("skillTab = " + skillTab);

                SkillTab skillsInSkillTab = CreateSkillsFromRow(availableSkills, skillTable, skillRows);

                if (skillsInSkillTab.Skills.Count > 0)
                {
                    _skillTabs.Add(skillsInSkillTab);
                }
            }

            // select the general skill tab
            DataRow[] generalSkillRows = skillTable.Select("skillTab = " + 0);
            _generalSkills = CreateSkillsFromRow(availableSkills, skillTable, generalSkillRows);

            //add all skills back to the savegame
            availableSkills.Clear();

            foreach (Skill skill in _generalSkills.Skills)
            {
                availableSkills.Add(skill.SkillBlock);
            }

            foreach (SkillTab skillTab in _skillTabs)
            {
                foreach (Skill skill in skillTab.Skills)
                {
                    availableSkills.Add(skill.SkillBlock);
                }
            }

            //skills.repeatCount = availableSkills.Count;

            //skills.Values = availableSkills;
            skills.Values.Clear();
            skills.Values.AddRange(availableSkills);
        }
Example #6
0
        public CharacterProperty(UnitObject unitObject, FileManager fileManager)
        {
            this.unitObject = unitObject;
            this.fileManager = fileManager;

            statsTable = fileManager.GetDataTable("STATS");
        }
Example #7
0
        public CharacterItems(UnitObject unitObject, FileManager fileManager)
            : base(unitObject, fileManager)
        {
            _itemTable = fileManager.GetDataTable("ITEMS");
            DataRow[] itemRow = _itemTable.Select("code = " + unitObject.UnitCode);

            //DataTable colorTable = _dataSet.GetExcelTableFromStringId("ITEMQUALITY");
            //DataRow[] colorRow = colorTable.Select("code = " + _hero.unitCode);

            if (itemRow.Length > 0)
            {
                _isItem = true;

                uint bitMask = (uint)itemRow[0]["bitmask02"];
                _isQuestItem = (bitMask >> 13 & 1) == 1;

                string maxStackSize = (string)itemRow[0]["stackSize"];
                string[] splitResult = maxStackSize.Split(new char[] { ',' });
                if (splitResult.Length == 3)
                {
                    _maxStackSize = int.Parse(splitResult[1]);
                }
                if (_maxStackSize <= 0)
                {
                    _maxStackSize = 1;
                }

                _stackSize = UnitHelpFunctions.GetSimpleValue(unitObject, ItemValueNames.item_quantity.ToString());
                if (_stackSize <= 0)
                {
                    _stackSize = 1;
                }

                _itemImagePath = CreateImagePath();

                _numberOfAugmentations = UnitHelpFunctions.GetSimpleValue(unitObject, ItemValueNames.item_augmented_count.ToString());
                _numberOfUpgrades = UnitHelpFunctions.GetSimpleValue(unitObject, ItemValueNames.item_upgraded_count.ToString());

                DataTable gameGlobals = fileManager.GetDataTable("GAME_GLOBALS");
                //DataRow[] globalsRow = gameGlobals.Select("name = " + "max_item_upgrades");
                DataRow[] globalsRow = gameGlobals.Select("Index = " + 16);
                _maxNumberOfUpgrades = (int)globalsRow[0]["intValue"];

                //globalsRow = gameGlobals.Select("name = " + "max_item_augmentations");
                globalsRow = gameGlobals.Select("Index = " + 17);
                _maxNumberOfAffixes = (int)globalsRow[0]["intValue"];
                UnitObjectStats.Stat affixes = UnitHelpFunctions.GetComplexValue(unitObject, ItemValueNames.applied_affix.ToString());
                if (affixes != null)
                {
                    _numberOfAffixes = affixes.Values.Count;
                }

                int numberOfInherentAffixes = _numberOfAffixes - _numberOfAugmentations;
                _numberOfAugmentationsLeft = _maxNumberOfAffixes - numberOfInherentAffixes;

                if (_numberOfAugmentationsLeft < 0)
                {
                    _numberOfAugmentationsLeft = 0;
                }

                _maxNumberOfAugmentations = _numberOfAugmentations + _numberOfAugmentationsLeft;
                if (_maxNumberOfAugmentations > _maxNumberOfAffixes)
                {
                    _maxNumberOfAugmentations = _maxNumberOfAffixes;
                }
            }

            _items = new List<CharacterItems>();

            foreach (UnitObject item in unitObject.Items)
            {
                CharacterItems wrapper = new CharacterItems(item, fileManager);
                _items.Add(wrapper);
            }
        }
Example #8
0
        public CharacterWrapper(UnitObject character, FileManager fileManager)
            : base(character, fileManager)
        {
            itemsTable = fileManager.GetDataTable("ITEMS");

            DataTable players = fileManager.GetDataTable("PLAYERS");
            DataRow[] playerRow = players.Select("code = " + character.UnitCode);

            if (playerRow.Length > 0)
            {
                int playerType = (int)playerRow[0]["unitType"];

                List<int> skillTabs = new List<int>();

                for (int counter = 1; counter < 8; counter++)
                {
                    int skillTab = (int)playerRow[0]["SkillTab" + counter];
                    if (skillTab >= 0)
                    {
                        skillTabs.Add(skillTab);
                    }
                }

                unitType = playerType - 3;

                characterSkills = new CharacterSkills(character, fileManager, skillTabs.ToArray());
            }

            characterClass = GetCharacterClass(character);
            characterGameMode = new CharacterGameMode(character, fileManager);
            characterValues = new CharacterValues(character, fileManager);
            gender = characterClass.ToString().EndsWith("_Male") ? Gender.Male : Gender.Female;
            weaponSlots = new WeaponSlots(character, fileManager);
            characterInventory = new CharacterInventory(character, fileManager);

            if (characterClass == CharacterClass.Engineer_Male || characterClass == CharacterClass.Engineer_Female)
            {
                //drone = new EngineerDrone(character, fileManager);
            }
        }
Example #9
0
 public UnitHelpFunctions(FileManager fileManager)
 {
     _fileManager = fileManager;
        _statsTable = fileManager.GetDataTable("STATS");
 }