Exemplo n.º 1
0
        private static BdatStringItem ReadItem(BdatTable table, int itemIndex)
        {
            int itemOffset = table.ItemTableOffset + itemIndex * table.ItemSize;

            var item = new BdatStringItem();

            foreach (BdatMember member in table.Members)
            {
                switch (member.Type)
                {
                case BdatMemberType.Scalar:
                    string v = ReadValue(table.Data, itemOffset + member.MemberPos, member.ValType);
                    item.AddMember(member.Name, new BdatStringValue(v, item, member));
                    break;

                case BdatMemberType.Array:
                    string[] a = ReadArray(table.Data, itemOffset + member.MemberPos, member);
                    item.AddMember(member.Name, new BdatStringValue(a, item, member));
                    break;

                case BdatMemberType.Flag:
                    BdatMember flagsMember = table.Members[member.FlagVarIndex];
                    string     f           = ReadFlag(table.Data, itemOffset, member, flagsMember);
                    item.AddMember(member.Name, new BdatStringValue(f, item, member));
                    break;
                }
            }

            return(item);
        }
        private static BdatStringTable ReadTable(byte[] file, int offset)
        {
            if (BitConverter.ToUInt32(file, offset) != 0x54414442)
            {
                return(null);
            }

            int namesOffset = BitConverter.ToUInt16(file, offset + 6);
            var tableName   = Stuff.GetUTF8Z(file, offset + namesOffset);
            var members     = BdatTable.ReadTableMembers(file, offset);

            var table = new BdatStringTable
            {
                Name    = tableName,
                BaseId  = BitConverter.ToUInt16(file, offset + 18),
                Members = members,
                Items   = ReadItems(file, offset, members)
            };

            int id = table.BaseId;

            foreach (BdatStringItem item in table.Items)
            {
                item.Table = tableName;
                item.Id    = id++;
            }

            return(table);
        }
Exemplo n.º 3
0
        public static string Print(BdatCollection tables)
        {
            var sb = new Indenter();
            BdatTable <FLD_SalvagePointList> pointList = tables.FLD_SalvagePointList;

            sb.AppendLine("<!DOCTYPE html>");
            sb.AppendLineAndIncrease("<html>");
            sb.AppendLineAndIncrease("<head>");
            sb.AppendLine("<meta charset=\"utf-8\" />");
            sb.AppendLine("<title>Xenoblade 2 Salvaging Points</title>");
            sb.AppendLine("<style>.tbox td{vertical-align: top;} table.BtnChallenge td,th{border: 1px solid;}table{margin:0;padding:0;border-collapse: collapse;}</style>");
            sb.DecreaseAndAppendLine("</head>");

            sb.AppendLineAndIncrease("<body>");

            foreach (FLD_SalvagePointList point in pointList.Where(x => x.SalvagePointName > 0))
            {
                PrintPoint(point, sb);
            }

            sb.DecreaseAndAppendLine("</body>");
            sb.DecreaseAndAppendLine("</html>");

            return(sb.ToString());
        }
Exemplo n.º 4
0
        public void ViewTable()
        {
            if (!IsFileOpened)
            {
                return;
            }

            BdatTable table = BdatTables.Tables[SelectedTable];

            CurrentTable = table;
            RefreshTable();
        }
Exemplo n.º 5
0
        public static List <QuestParent> ReadQuests(BdatTable <FLD_QuestList> table)
        {
            var parents = table.Where(x => x.FlagPRT != 0).ToArray();
            var quests  = new List <QuestParent>();

            foreach (var parent in parents)
            {
                var quest = ReadParentQuest(parent);
                quests.Add(quest);
            }

            return(quests);
        }
Exemplo n.º 6
0
        private static void ReadTable(BdatTable file, BdatCollection tables)
        {
            Type itemType  = TypeMap.GetTableType(file.Name);
            Type tableType = typeof(BdatTable <>).MakeGenericType(itemType);
            var  table     = (IBdatTable)Activator.CreateInstance(tableType);

            table.Name    = file.Name;
            table.BaseId  = file.BaseId;
            table.Members = file.Members;
            table.Items   = ReadItems(file, itemType);

            Fields[file.Name].SetValue(tables, table);
        }
Exemplo n.º 7
0
        private static Array ReadItems(BdatTable table, Type itemType)
        {
            Array items = Array.CreateInstance(itemType, table.ItemCount);
            var   func  = TypeMap.GetTableReadFunction(itemType);

            for (int i = 0; i < table.ItemCount; i++)
            {
                int    itemOffset = table.Data.Start + table.ItemTableOffset + i * table.ItemSize;
                object item       = func(table.Data.File, table.BaseId + i, itemOffset, table.Data.Start);
                items.SetValue(item, i);
            }

            return(items);
        }
Exemplo n.º 8
0
        private static BdatTable[] GetBdatMembers(string bdatDir, string pattern)
        {
            string[] filenames = Directory.GetFiles(bdatDir, pattern, SearchOption.AllDirectories);
            byte[][] files     = new byte[filenames.Length][];
            var      tables    = new BdatTable[filenames.Length][];

            for (int i = 0; i < filenames.Length; i++)
            {
                files[i]  = File.ReadAllBytes(filenames[i]);
                tables[i] = new BdatFile(files[i], filenames[i]).Tables;
            }

            BdatTable[] flat = tables.SelectMany(x => x).ToArray();

            return(flat);
        }
Exemplo n.º 9
0
        private static IEnumerable <Achievement> GetBladeAchievements(BdatTable <CHR_Bl> tables)
        {
            var achievements = new List <Achievement>();

            foreach (CHR_Bl blade in tables.Items.Where(x => x._ArtsAchievement1 != null))
            {
                achievements.AddRange(GetAchievementSet(blade, blade._KeyAchievement, string.Empty, "Key", 1));

                for (int i = 0; i < 3; i++)
                {
                    achievements.AddRange(GetAchievementSet(blade, blade._ArtsAchievement[i], blade._BArts[i]?._Name.name, "Special", 2 + i));
                    achievements.AddRange(GetAchievementSet(blade, blade._SkillAchievement[i], blade._BSkill[i]?._Name.name, "Battle Skill", 5 + i));
                    achievements.AddRange(GetAchievementSet(blade, blade._FskillAchivement[i], blade._FSkill[i]?._Name.name, "Field Skill", 8 + i));
                }
            }

            return(achievements.OrderBy(x => x.BladeId).ThenBy(x => x.Col).ThenBy(x => x.Row));
        }
Exemplo n.º 10
0
        public void ViewTable()
        {
            if (!IsFileOpened)
            {
                return;
            }

            BdatTable table     = BdatTables.Tables[SelectedTable];
            var       editTable = new EditTable(table);

            EditingTable = new DataTable();
            CurrentTable = table;

            EditingTable.Columns.Add(new DataColumn("ID")
            {
                ReadOnly = true
            });
            foreach (BdatMember col in editTable.Columns)
            {
                var column = new DataColumn();
                if (col.Type != BdatMemberType.Scalar)
                {
                    column.ReadOnly = true;
                }

                column.ColumnName = $"{col.Name}\n({col.ValType})";
                EditingTable.Columns.Add(column);
            }

            foreach (object[] item in editTable.Items)
            {
                DataRow row = EditingTable.NewRow();
                row.ItemArray = item;
                EditingTable.Rows.Add(item);
            }

            EditingTable.AcceptChanges();
            IsTableOpened = true;

            DataTable temp = EditingTable;

            EditingTable = null;
            EditingTable = temp;
        }
Exemplo n.º 11
0
        public EditTable(BdatTable bdat)
        {
            Name = bdat.Name;
            foreach (BdatMember member in bdat.Members)
            {
                Columns.Add(member);
            }

            for (int i = bdat.BaseId; i < bdat.BaseId + bdat.ItemCount; i++)
            {
                var item = new object[Columns.Count + 1];
                item[0] = i;
                for (int c = 0; c < Columns.Count; c++)
                {
                    item[c + 1] = bdat.ReadValue(i, Columns[c].Name);
                }

                Items.Add(item);
            }
        }
Exemplo n.º 12
0
        private static void ReadTable(byte[] file, int offset, BdatCollection tables)
        {
            if (BitConverter.ToUInt32(file, offset) != 0x54414442)
            {
                return;
            }

            int namesOffset = BitConverter.ToUInt16(file, offset + 6);
            var tableName   = Stuff.GetUTF8Z(file, offset + namesOffset);

            var itemType  = TypeMap.GetTableType(tableName);
            var tableType = typeof(BdatTable <>).MakeGenericType(itemType);
            var table     = (IBdatTable)Activator.CreateInstance(tableType);

            table.Name    = tableName;
            table.BaseId  = BitConverter.ToUInt16(file, offset + 18);
            table.Members = BdatTable.ReadTableMembers(file, offset);
            table.Items   = ReadItems(file, offset, itemType);

            Fields[tableName].SetValue(tables, table);
        }
Exemplo n.º 13
0
        public static MapInfo[] ReadAll(IFileSystem fs, BdatCollection tables, IProgressReport progress = null)
        {
            progress?.LogMessage("Reading map info and gimmick sets");
            Dictionary <string, MapInfo> maps = MapInfo.ReadAll(fs);

            BdatTable <FLD_maplist> mapList  = tables.FLD_maplist;
            BdatTable <MNU_MapInfo> areaList = tables.MNU_MapInfo;

            foreach (MapInfo mapInfo in maps.Values)
            {
                FLD_maplist map = mapList.FirstOrDefault(x => x.resource == mapInfo.Name && x._nameID != null);
                if (map == null)
                {
                    continue;
                }
                if (map._nameID != null)
                {
                    mapInfo.DisplayName = map._nameID.name;
                }

                foreach (MapAreaInfo areaInfo in mapInfo.Areas)
                {
                    MNU_MapInfo area = areaList.FirstOrDefault(x =>
                                                               x.level_name == areaInfo.Name || x.level_name2 == areaInfo.Name);
                    if (area == null)
                    {
                        progress?.LogMessage($"Found area {areaInfo.Name} that is not in the BDAT tables");
                        continue;
                    }

                    // Some areas use one of 2 maps depending on the game state.
                    // These 2 maps are always the same except one has a small addition or removal.
                    // We want the map with the most objects on it, so we use the second map for
                    // Gormott (ma05a), and the first map for everywhere else.
                    if (!string.IsNullOrWhiteSpace(area.level_name2) &&
                        area.level_name == areaInfo.Name &&
                        mapInfo.Name == "ma05a")
                    {
                        areaInfo.Priority = int.MaxValue;
                    }
                    else if (!string.IsNullOrWhiteSpace(area.level_name2) &&
                             area.level_name2 == areaInfo.Name &&
                             mapInfo.Name != "ma05a")
                    {
                        areaInfo.Priority = int.MaxValue;
                    }
                    else
                    {
                        areaInfo.Priority = area.level_priority;
                    }

                    if (area._disp_name?.name != null)
                    {
                        areaInfo.DisplayName = area._disp_name.name;
                    }
                }

                Dictionary <string, Lvb> gimmickSet = ReadGimmickSet(fs, tables, map.Id);
                AssignGimmickAreas(gimmickSet, mapInfo);
            }

            return(maps.Values.ToArray());
        }