Exemple #1
0
        public (BdatTables BDAT, List <string> Names) LoadBdat(string filename)
        {
            BdatTables    Tables;
            List <string> Names;

            try
            {
                Tables = new BdatTables(filename, Game.XB2, false);
                Names  = Tables.Tables.Select(x => x.Name).ToList();
            }
            catch
            {
                try
                {
                    Tables = new BdatTables(filename, Game.XBX, false);
                    Names  = Tables.Tables.Select(x => x.Name).ToList();
                }
                catch
                {
                    try
                    {
                        Tables = new BdatTables(filename, Game.XB1DE, false);
                        Names  = Tables.Tables.Select(x => x.Name).ToList();
                    }
                    catch
                    {
                        return(null, null);
                    }
                }
            }

            return(Tables, Names);
        }
Exemple #2
0
        private static string GenerateReadFunctionsFile(BdatTables info)
        {
            var sb = new Indenter();

            sb.AppendLine("// ReSharper disable InconsistentNaming");
            sb.AppendLine("// ReSharper disable UnusedMember.Global");
            sb.AppendLine("// ReSharper disable UseObjectOrCollectionInitializer");
            sb.AppendLine("// ReSharper disable UnusedParameter.Global").AppendLine();
            sb.AppendLine("using System;");
            sb.AppendLine("using XbTool.Types").AppendLine();
            sb.AppendLine("namespace XbTool.Serialization");
            sb.AppendLineAndIncrease("{");
            sb.AppendLine("public static class ReadFunctions");
            sb.AppendLineAndIncrease("{");
            bool firstFunction = true;

            foreach (var type in info.Types)
            {
                if (!firstFunction)
                {
                    sb.AppendLine();
                }
                firstFunction = false;
                GenerateReadFunction(type, sb);
            }

            sb.AppendLine();
            GenerateSetReferencesFunction(sb, info);

            sb.DecreaseAndAppendLine("}");
            sb.DecreaseAndAppendLine("}");
            return(sb.ToString());
        }
Exemple #3
0
        private static string GenerateBdatCollectionFile(BdatTables info)
        {
            var sb = new Indenter();

            sb.AppendLine("// ReSharper disable InconsistentNaming");
            sb.AppendLine("// ReSharper disable UnassignedField.Global");
            sb.AppendLine("// ReSharper disable UnusedMember.Global").AppendLine();
            sb.AppendLine("using System;");
            sb.AppendLine("using XbTool.Bdat;").AppendLine();
            sb.AppendLine("using XbTool.Types");
            sb.AppendLineAndIncrease("{");
            sb.AppendLine("[Serializable]");
            sb.AppendLine("public class BdatCollection");
            sb.AppendLineAndIncrease("{");

            foreach (var type in info.Types)
            {
                foreach (string table in type.TableNames.OrderBy(x => x))
                {
                    sb.AppendLine($"public BdatTable<{type.Name}> {table};");
                }
            }

            sb.DecreaseAndAppendLine("}");
            sb.DecreaseAndAppendLine("}");
            return(sb.ToString());
        }
Exemple #4
0
        public static BdatCollection GetBdatCollection(Options options)
        {
            BdatTables     bdats  = ReadBdatTables(options, false);
            BdatCollection tables = Deserialize.DeserializeTables(bdats);

            return(tables);
        }
Exemple #5
0
        private static string GenerateTypesFile(BdatTables info)
        {
            var sb = new Indenter();

            sb.AppendLine("// ReSharper disable InconsistentNaming");
            sb.AppendLine("// ReSharper disable NotAccessedField.Global");
            sb.AppendLine();
            sb.AppendLine("using System;");
            sb.AppendLine("using XbTool.Bdat;");
            sb.AppendLine();
            sb.AppendLine("namespace XbTool.Types");
            sb.AppendLineAndIncrease("{");

            for (int i = 0; i < info.Types.Length; i++)
            {
                if (i != 0)
                {
                    sb.AppendLine();
                }
                GenerateType(info.Types[i], sb);
            }

            sb.DecreaseAndAppendLine("}");
            return(sb.ToString());
        }
Exemple #6
0
 public void OpenBdat(string filename)
 {
     try
     {
         BdatTables   = new BdatTables(filename, Game.XB2, false);
         TableNames   = BdatTables.Tables.Select(x => x.Name).ToList();
         IsFileOpened = true;
     }
     catch
     {
         try
         {
             BdatTables   = new BdatTables(filename, Game.XBX, false);
             TableNames   = BdatTables.Tables.Select(x => x.Name).ToList();
             IsFileOpened = true;
         }
         catch
         {
             try
             {
                 BdatTables   = new BdatTables(filename, Game.XB1DE, false);
                 TableNames   = BdatTables.Tables.Select(x => x.Name).ToList();
                 IsFileOpened = true;
             }
             catch
             {
                 MessageBox.Show("Failed to open file. Is it a valid bdat?");
             }
         }
     }
 }
Exemple #7
0
        public static BdatCollection GetBdatCollection(IFileSystem fs, bool readMetadata)
        {
            var            bdats  = new BdatTables(fs, readMetadata);
            BdatCollection tables = Deserialize.DeserializeTables(bdats);

            return(tables);
        }
Exemple #8
0
        private static BdatStringCollection GetBdatStringCollection(Options options)
        {
            BdatTables           bdats  = ReadBdatTables(options, true);
            BdatStringCollection tables = DeserializeStrings.DeserializeTables(bdats);

            Metadata.ApplyMetadata(tables);
            return(tables);
        }
Exemple #9
0
        private static void BdatCodeGen(Options options)
        {
            if (options.Output == null)
            {
                throw new NullReferenceException("Output file was not specified.");
            }

            BdatTables bdats = ReadBdatTables(options, true);

            SerializationCode.CreateFiles(bdats, options.Output);
        }
Exemple #10
0
        public static BdatCollection DeserializeTables(BdatTables files)
        {
            var tables = new BdatCollection();

            foreach (BdatTable table in files.Tables)
            {
                ReadTable(table, tables);
            }

            ReadFunctions.SetReferences(tables);

            return(tables);
        }
Exemple #11
0
        public static void CreateFiles(BdatTables tables, string csDir)
        {
            Directory.CreateDirectory(csDir);

            string bdatTypes      = GenerateTypesFile(tables);
            string readFunctions  = GenerateReadFunctionsFile(tables);
            string bdatCollection = GenerateBdatCollectionFile(tables);
            string typeMap        = GenerateTypeMapFile(tables);

            File.WriteAllText(Path.Combine(csDir, "BdatTypes.cs"), bdatTypes);
            File.WriteAllText(Path.Combine(csDir, "ReadFunctions.cs"), readFunctions);
            File.WriteAllText(Path.Combine(csDir, "BdatCollection.cs"), bdatCollection);
            File.WriteAllText(Path.Combine(csDir, "TypeMap.txt"), typeMap);
        }
Exemple #12
0
        public MainViewModel()
        {
            ReadSaveCommand  = new RelayCommand(ReadSaveDialog);
            WriteSaveCommand = new RelayCommand(WriteSave);
            LoadBdatsCommand = new RelayCommand(LoadBdats);

            if (IsInDesignModeStatic)
            {
                using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SaveEditor.bf2savefile.sav.gz"))
                {
                    if (stream == null)
                    {
                        return;
                    }
                    using (var decompressionStream = new GZipStream(stream, CompressionMode.Decompress))
                    {
                        var file = new byte[0x1176A0];
                        decompressionStream.Read(file, 0, file.Length);
                        SaveFile = new SDataSave(new DataBuffer(file, Game.XB2, 0));
                    }
                }
            }

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SaveEditor.bdats.gz"))
            {
                if (stream == null)
                {
                    return;
                }
                using (var decompressionStream = new GZipStream(stream, CompressionMode.Decompress))
                {
                    var file = new byte[7394040];
                    decompressionStream.Read(file, 0, file.Length);
                    var bdats = new BdatTables(file, Game.XB2, false);
                    Tables = Deserialize.DeserializeTables(bdats);
                }
            }

            var s = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            s.AddRange(Tables.ITM_PcEquip.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            Acc = s.ToArray();
        }
Exemple #13
0
        private static string GenerateTypeMapFile(BdatTables info)
        {
            var sb = new StringBuilder();

            foreach (var type in info.Types)
            {
                sb.Append(type.Name);
                foreach (var table in type.TableNames.OrderBy(x => x))
                {
                    sb.Append($",{table}");
                }
                sb.AppendLine();
            }
            return(sb.ToString());
        }
        public static BdatStringCollection DeserializeTables(BdatTables tables, IProgressReport progress = null)
        {
            var collection = new BdatStringCollection {
                Bdats = tables
            };

            progress?.LogMessage("Parsing BDAT tables");
            progress?.SetTotal(tables.Tables.Length);

            foreach (BdatTable table in tables.Tables)
            {
                var items = new BdatStringItem[table.ItemCount];

                var stringTable = new BdatStringTable
                {
                    Collection = collection,
                    Name       = table.Name,
                    BaseId     = table.BaseId,
                    Members    = table.Members,
                    Items      = items,
                    Filename   = table.Filename
                };

                if (tables.DisplayFields.TryGetValue(table.Name, out string displayMember))
                {
                    stringTable.DisplayMember = displayMember;
                }

                for (int i = 0; i < table.ItemCount; i++)
                {
                    BdatStringItem item = ReadItem(table, i);
                    item.Table = stringTable;
                    item.Id    = table.BaseId + i;

                    if (displayMember != null)
                    {
                        item.Display = item[displayMember];
                    }

                    items[i] = item;
                }

                collection.Add(stringTable);
                progress?.ReportAdd(1);
            }

            return(collection);
        }
Exemple #15
0
        public static BdatCollection DeserializeTables(BdatTables files, IProgressReport progress = null)
        {
            progress?.LogMessage("Deserializing BDAT tables");
            progress?.SetTotal(files.Tables.Length);
            var tables = new BdatCollection();

            foreach (BdatTable table in files.Tables)
            {
                ReadTable(table, tables);
                progress?.ReportAdd(1);
            }

            ReadFunctions.SetReferences(tables);

            return(tables);
        }
Exemple #16
0
        private static void GenerateSetReferencesFunction(Indenter sb, BdatTables info)
        {
            sb.AppendLine("public static void SetReferences(BdatCollection tables)");
            sb.AppendLineAndIncrease("{");
            bool firstTable = true;

            foreach (var table in info.TableDesc)
            {
                if (!firstTable)
                {
                    sb.AppendLine();
                }
                firstTable = false;

                GenerateSetReferencesTable(sb, table);
            }

            sb.DecreaseAndAppendLine("}");
        }
Exemple #17
0
        public static void GenerateBdatHtml(IFileSystem fs, string outDir, IProgressReport progress)
        {
            var bdats = new BdatTables(fs, true, progress);
            BdatStringCollection tablesStr = DeserializeStrings.DeserializeTables(bdats, progress);

            Metadata.ApplyMetadata(tablesStr);
            HtmlGen.PrintSeparateTables(tablesStr, Path.Combine(outDir, BdatDir), progress);
            JsonGen.PrintAllTables(tablesStr, Path.Combine(outDir, JsonDir), progress);

            BdatCollection tables = Deserialize.DeserializeTables(bdats, progress);

            string dataDir = Path.Combine(outDir, DataDir);

            progress.SetTotal(0);
            progress.LogMessage("Creating salvaging tables");
            Directory.CreateDirectory(dataDir);
            string salvaging = SalvagingTable.Print(tables);

            File.WriteAllText(Path.Combine(dataDir, "salvaging.html"), salvaging);

            progress.LogMessage("Creating enemy tables");
            using (var writer = new StreamWriter(Path.Combine(dataDir, "enemies.csv")))
            {
                Enemies.PrintEnemies(tables, writer);
            }

            progress.LogMessage("Creating achievement tables");
            using (var writer = new StreamWriter(Path.Combine(dataDir, "achievements.csv")))
            {
                Achievements.PrintAchievements(tables, writer);
            }

            string gmkDir = Path.Combine(outDir, GmkDir);

            MapInfo[] gimmicks = ReadGmk.ReadAll(fs, tables, progress);
            progress.LogMessage("Writing map info and gimmick data");
            ExportMap.ExportCsv(gimmicks, gmkDir);
        }
Exemple #18
0
        public MainViewModel()
        {
            ReadSaveCommand  = new RelayCommand(ReadSaveDialog);
            WriteSaveCommand = new RelayCommand(WriteSave);
            LoadBdatsCommand = new RelayCommand(LoadBdats);

            if (IsInDesignModeStatic)
            {
                using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SaveEditor.bf2savefile.sav.gz"))
                {
                    if (stream == null)
                    {
                        return;
                    }
                    using (var decompressionStream = new GZipStream(stream, CompressionMode.Decompress))
                    {
                        var file = new byte[0x1176A0];
                        decompressionStream.Read(file, 0, file.Length);
                        SaveFile = new SDataSave(new DataBuffer(file, Game.XB2, 0));
                    }
                }
            }

            using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SaveEditor.bdats.gz"))
            {
                if (stream == null)
                {
                    return;
                }
                using (var decompressionStream = new GZipStream(stream, CompressionMode.Decompress))
                {
                    var file = new byte[7394040];
                    decompressionStream.Read(file, 0, file.Length);
                    var bdats = new BdatTables(file, Game.XB2, false);
                    Tables = Deserialize.DeserializeTables(bdats);
                }
            }

            var s = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            s.AddRange(Tables.ITM_PcEquip.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            Acc = s.ToArray();

            var t = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            t.AddRange(Tables.ITM_CrystalList.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            CorCrt = t.ToArray();

            var u = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            u.AddRange(Tables.ITM_SalvageList.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            Cyl = u.ToArray();

            var v = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            v.AddRange(Tables.ITM_PreciousList.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            Key = v.ToArray();

            var w = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            w.AddRange(Tables.ITM_InfoList.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            Info = w.ToArray();

            var xa = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            xa.AddRange(Tables.ITM_HanaAssist.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            SkRam = xa.ToArray();

            var xb = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            xb.AddRange(Tables.ITM_HanaNArtsSet.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            Art = xb.ToArray();

            var xc = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            xc.AddRange(Tables.ITM_HanaArtsEnh.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            EnRam = xc.ToArray();

            var xd = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            xd.AddRange(Tables.ITM_HanaAtr.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            ElCore = xd.ToArray();

            var xe = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            xe.AddRange(Tables.ITM_HanaRole.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            RCPU = xe.ToArray();

            var xf = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            xf.AddRange(Tables.ITM_BoosterList.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            Boost = xf.ToArray();

            var xg = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            xg.AddRange(Tables.ITM_Orb.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            ACore = xg.ToArray();

            var xh = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            xh.AddRange(Tables.ITM_FavoriteList.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            PItem = xh.ToArray();

            var xi = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            xi.AddRange(Tables.ITM_TresureList.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            Trs = xi.ToArray();

            var xj = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            xj.AddRange(Tables.ITM_CollectionList.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            Col = xj.ToArray();

            var xl = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            xl.AddRange(Tables.ITM_PreciousList.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            KItem = xl.ToArray();

            var xm = new List <ItemDesc> {
                new ItemDesc {
                    Id = 0, Name = ""
                }
            };

            xm.AddRange(Tables.ITM_PcWpnChip.Select(x => new ItemDesc {
                Id = x.Id, Name = x._Name?.name
            }));
            PcWpn = xm.ToArray();
        }
Exemple #19
0
 public void OpenBdat(string filename)
 {
     BdatTables   = new BdatTables(filename, Game.XB2, false);
     TableNames   = BdatTables.Tables.Select(x => x.Name).ToList();
     IsFileOpened = true;
 }