Ejemplo n.º 1
0
        public static void ReloadFMGs()
        {
            if (AssetLocator.Type == GameType.Undefined)
            {
                return;
            }

            if (AssetLocator.Type == GameType.DarkSoulsIISOTFS)
            {
                ReloadFMGsDS2();
                IsLoaded = true;
                return;
            }

            IBinder fmgBinder;
            var     desc = AssetLocator.GetEnglishItemMsgbnd();

            if (AssetLocator.Type == GameType.DemonsSouls || AssetLocator.Type == GameType.DarkSoulsPTDE || AssetLocator.Type == GameType.DarkSoulsRemastered)
            {
                fmgBinder = BND3.Read(desc.AssetPath);
            }
            else
            {
                fmgBinder = BND4.Read(desc.AssetPath);
            }

            _fmgs = new Dictionary <ItemFMGTypes, FMG>();
            foreach (var file in fmgBinder.Files)
            {
                _fmgs.Add((ItemFMGTypes)file.ID, FMG.Read(file.Bytes));
            }
            IsLoaded = true;
        }
Ejemplo n.º 2
0
            public FMGHandler(TextHandler th, BND3 bnd, string name)
            {
                IEnumerable <BinderFile> list = bnd.Files.Where(f => Path.GetFileNameWithoutExtension(f.Name) == name);

                FileProper = list.ElementAt(0);
                Proper     = FMG.Read(FileProper.Bytes);
                if (list.Count() > 1)
                {
                    FilePatch = list.ElementAtOrDefault(1);
                    Patch     = FMG.Read(FilePatch.Bytes);
                }
            }
Ejemplo n.º 3
0
        public bool ScrapeMsgs(Universe u)
        {
            if (spec.MsgDir == null)
            {
                return(false);
            }
            foreach (KeyValuePair <string, FMG> entry in editor.LoadBnds(spec.MsgDir, (data, name) => FMG.Read(data)).SelectMany(e => e.Value)
                     .Concat(editor.Load(spec.MsgDir, name => FMG.Read(name), "*.fmg")).OrderBy(e => e.Key))
            {
                if (MsgTypes.ContainsKey(entry.Key))
                {
                    Namespace type = MsgTypes[entry.Key];
                    foreach (FMG.Entry name in entry.Value.Entries)
                    {
                        u.Names[Obj.Of(type, name.ID)] = name.Text;
                    }
                }
            }
            if (Directory.Exists($@"{spec.GameDir}\{spec.MsgDir}\talk"))
            {
                foreach (KeyValuePair <string, FMG> entry in editor.Load(spec.MsgDir + @"\talk", name => FMG.Read(name), "*.fmg"))
                {
                    foreach (FMG.Entry name in entry.Value.Entries)
                    {
                        u.Names[Obj.Talk(name.ID)] = name.Text;
                    }
                }
            }
            if (spec.ParamFile == null || !talkParamMsgId.ContainsKey(spec.Game))
            {
                return(false);
            }
            LoadParams();
            if (!Params.ContainsKey("TalkParam"))
            {
                return(false);
            }
            string msgId = talkParamMsgId[spec.Game];

            foreach (PARAM.Row row in Params["TalkParam"].Rows)
            {
                int dialogue = (int)row[msgId].Value;
                if (dialogue > 0)
                {
                    Obj dialogueObj = Obj.Of(Namespace.DIALOGUE, dialogue);
                    if (u.Names.ContainsKey(dialogueObj))
                    {
                        u.Names[Obj.Talk((int)row.ID)] = u.Names[dialogueObj];
                    }
                }
            }
            return(true);
        }
        private static Dictionary <int, string> MakeRef(IBinder refBND, int iRef)
        {
            FMG refFMG = null;
            Dictionary <int, string> refDict = null;

            if (refBND != null)
            {
                refFMG  = FMG.Read((refBND.Files[iRef]).Bytes);
                refDict = refFMG.Entries.ToDictionary(t => t.ID, t => t.Text);
            }

            return(refDict);
        }
Ejemplo n.º 5
0
 public static void ReloadFmgs()
 {
     try
     {
         BND4 fmgBnd = BND4.Read(FMGBndPath);
         ItemFMG = FMG.Read(fmgBnd.Files.Find(x => Path.GetFileName(x.Name) == "アイテム名.fmg").Bytes);
     }
     catch (Exception e)
     {
         if (!Failwarn)
         {
             Debug.Log("Failed to load item fmg file. Item names will not be shown.");
             Failwarn = true;
         }
     }
 }
Ejemplo n.º 6
0
        public static void LoadMessages(SQLiteConnection con, string messageDir)
        {
            List <string> messageFilepaths = new List <string>();

            messageFilepaths.AddRange(Directory.GetFiles(messageDir, "*.msgbnd.dcx"));

            foreach (string messageFilepath in messageFilepaths)
            {
                var msgbnd = BND3.Read(messageFilepath);
                foreach (BinderFile file in msgbnd.Files)
                {
                    string name = Path.GetFileNameWithoutExtension(file.Name);

                    // Yes, .msgbnd file is FMG
                    FMG msg = FMG.Read(file.Bytes);
                    ReadMessagesIntoDatabase(con, name, msg);
                }
            }
        }
Ejemplo n.º 7
0
        public static void ReloadFMGsDS2()
        {
            var desc  = AssetLocator.GetEnglishItemMsgbnd(true);
            var files = Directory.GetFileSystemEntries($@"{AssetLocator.GameRootDirectory}\{desc.AssetPath}", @"*.fmg").ToList();

            _ds2fmgs = new Dictionary <string, FMG>();
            foreach (var file in files)
            {
                var modfile = $@"{AssetLocator.GameModDirectory}\{desc.AssetPath}\{Path.GetFileName(file)}";
                if (AssetLocator.GameModDirectory != null && File.Exists(modfile))
                {
                    var fmg = FMG.Read(modfile);
                    _ds2fmgs.Add(Path.GetFileNameWithoutExtension(modfile), fmg);
                }
                else
                {
                    var fmg = FMG.Read(file);
                    _ds2fmgs.Add(Path.GetFileNameWithoutExtension(file), fmg);
                }
            }
        }
Ejemplo n.º 8
0
 public void DumpMessages(string dir)
 {
     foreach (string path in Directory.GetFiles(dir, "*.msgbnd*"))
     {
         string name = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(path));
         try
         {
             IBinder bnd = BND3.Read(path);
             foreach (BinderFile file in bnd.Files)
             {
                 string fileName = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(file.Name));
                 string uname    = System.Text.RegularExpressions.Regex.Replace(fileName, @"[^\x00-\x7F]", c => string.Format(@"u{0:x4}", (int)c.Value[0]));
                 string fname    = $"{name}_{uname}.txt";
                 // Console.WriteLine(fname);
                 // string fileName = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(file.Name));
                 FMG fmg = FMG.Read(file.Bytes);
                 if (fmg.Entries != null)
                 {
                     File.WriteAllLines($@"{dir}\{fname}", fmg.Entries.Select(e => $"{e.ID} {(e.Text == null ? "" : e.Text.Replace("\r", "").Replace("\n", "\\n"))}"));
                 }
             }
         }
         catch (Exception ex)
         {
             throw new Exception($"Failed to load file: {name}: {path}\r\n\r\n{ex}");
         }
     }
     foreach (string path in Directory.GetFiles(dir, "*.fmg"))
     {
         FMG    fmg   = FMG.Read(path);
         string fname = Path.GetFileNameWithoutExtension(path);
         if (fmg.Entries != null)
         {
             File.WriteAllLines($@"{dir}\{fname}.txt", fmg.Entries.Select(e => $"{e.ID} {(e.Text == null ? "" : e.Text.Replace("\r", "").Replace("\n", "\\n"))}"));
         }
     }
 }
Ejemplo n.º 9
0
        public static void LoadAllFMG(bool forceReload)
        {
            if (!forceReload && GameTypeCurrentFmgsAreLoadedFrom == GameDataManager.GameType)
            {
                return;
            }

            FMG weaponNamesFmg    = null;
            FMG protectorNamesFmg = null;

            FMG weaponNamesFmg_dlc1    = null;
            FMG protectorNamesFmg_dlc1 = null;

            FMG weaponNamesFmg_dlc2    = null;
            FMG protectorNamesFmg_dlc2 = null;

            if (GameDataManager.GameType == GameDataManager.GameTypes.DS1)
            {
                var msgbnd = BND3.Read($@"{GameDataManager.InterrootPath}\msg\ENGLISH\item.msgbnd");

                weaponNamesFmg    = FMG.Read(msgbnd.Files.Last(f => f.Name.EndsWith("武器名.fmg")).Bytes);
                protectorNamesFmg = FMG.Read(msgbnd.Files.Last(f => f.Name.EndsWith("防具名.fmg")).Bytes);
            }
            else if (GameDataManager.GameType == GameDataManager.GameTypes.DS1R)
            {
                var msgbnd = BND3.Read($@"{GameDataManager.InterrootPath}\msg\ENGLISH\item.msgbnd.dcx");

                weaponNamesFmg    = FMG.Read(msgbnd.Files.Last(f => f.Name.EndsWith("Weapon_name_.fmg")).Bytes);
                protectorNamesFmg = FMG.Read(msgbnd.Files.Last(f => f.Name.EndsWith("Armor_name_.fmg")).Bytes);
            }
            else if (GameDataManager.GameType == GameDataManager.GameTypes.DS3)
            {
                var msgbnd = BND4.Read($@"{GameDataManager.InterrootPath}\msg\engus\item_dlc2.msgbnd.dcx");

                weaponNamesFmg    = FMG.Read(msgbnd.Files.Last(f => f.Name.EndsWith("武器名.fmg")).Bytes);
                protectorNamesFmg = FMG.Read(msgbnd.Files.Last(f => f.Name.EndsWith("防具名.fmg")).Bytes);

                var weaponNamesFmg_dlc1_entry = msgbnd.Files.LastOrDefault(f => f.Name.EndsWith("武器名_dlc1.fmg"));
                if (weaponNamesFmg_dlc1_entry != null)
                {
                    weaponNamesFmg_dlc1 = FMG.Read(weaponNamesFmg_dlc1_entry.Bytes);
                }

                var weaponNamesFmg_dlc2_entry = msgbnd.Files.LastOrDefault(f => f.Name.EndsWith("武器名_dlc2.fmg"));
                if (weaponNamesFmg_dlc2_entry != null)
                {
                    weaponNamesFmg_dlc2 = FMG.Read(weaponNamesFmg_dlc2_entry.Bytes);
                }

                var protectorNamesFmg_dlc1_entry = msgbnd.Files.LastOrDefault(f => f.Name.EndsWith("防具名_dlc1.fmg"));
                if (protectorNamesFmg_dlc1_entry != null)
                {
                    protectorNamesFmg_dlc1 = FMG.Read(protectorNamesFmg_dlc1_entry.Bytes);
                }

                var protectorNamesFmg_dlc2_entry = msgbnd.Files.LastOrDefault(f => f.Name.EndsWith("防具名_dlc2.fmg"));
                if (protectorNamesFmg_dlc2_entry != null)
                {
                    protectorNamesFmg_dlc2 = FMG.Read(protectorNamesFmg_dlc2_entry.Bytes);
                }
            }
            else if (GameDataManager.GameType == GameDataManager.GameTypes.BB)
            {
                var msgbnd = BND4.Read($@"{GameDataManager.InterrootPath}\msg\engus\item.msgbnd.dcx");

                weaponNamesFmg    = FMG.Read(msgbnd.Files.Last(f => f.Name.EndsWith("武器名.fmg")).Bytes);
                protectorNamesFmg = FMG.Read(msgbnd.Files.Last(f => f.Name.EndsWith("防具名.fmg")).Bytes);
            }

            WeaponNames.Clear();

            void DoWeaponEntry(FMG.Entry entry)
            {
                if (string.IsNullOrWhiteSpace(entry.Text) ||
                    !ParamManager.EquipParamWeapon.ContainsKey(entry.ID))
                {
                    return;
                }

                if (GameDataManager.GameType == GameDataManager.GameTypes.DS3 && (entry.ID % 10000) != 0)
                {
                    return;
                }
                else if ((entry.ID % 1000) != 0)
                {
                    return;
                }

                WeaponNames.Add(entry.ID, entry.Text);
            }

            if (weaponNamesFmg != null)
            {
                foreach (var entry in weaponNamesFmg.Entries)
                {
                    DoWeaponEntry(entry);
                }
            }

            if (weaponNamesFmg_dlc1 != null)
            {
                foreach (var entry in weaponNamesFmg_dlc1.Entries)
                {
                    DoWeaponEntry(entry);
                }
            }

            if (weaponNamesFmg_dlc2 != null)
            {
                foreach (var entry in weaponNamesFmg_dlc2.Entries)
                {
                    DoWeaponEntry(entry);
                }
            }

            ProtectorNames_HD.Clear();
            ProtectorNames_BD.Clear();
            ProtectorNames_AM.Clear();
            ProtectorNames_LG.Clear();

            void DoProtectorParamEntry(FMG.Entry entry)
            {
                if (string.IsNullOrWhiteSpace(entry.Text))
                {
                    return;
                }
                if (entry.ID < 1000000 && GameDataManager.GameType == GameDataManager.GameTypes.DS3)
                {
                    return;
                }
                if (ParamManager.EquipParamProtector.ContainsKey(entry.ID))
                {
                    var protectorParam = ParamManager.EquipParamProtector[entry.ID];
                    if (protectorParam.HeadEquip)
                    {
                        ProtectorNames_HD.Add(entry.ID, entry.Text);
                    }
                    else if (protectorParam.BodyEquip)
                    {
                        ProtectorNames_BD.Add(entry.ID, entry.Text);
                    }
                    else if (protectorParam.ArmEquip)
                    {
                        ProtectorNames_AM.Add(entry.ID, entry.Text);
                    }
                    else if (protectorParam.LegEquip)
                    {
                        ProtectorNames_LG.Add(entry.ID, entry.Text);
                    }
                }
            }

            if (protectorNamesFmg != null)
            {
                foreach (var entry in protectorNamesFmg.Entries)
                {
                    DoProtectorParamEntry(entry);
                }
            }

            if (protectorNamesFmg_dlc1 != null)
            {
                foreach (var entry in protectorNamesFmg_dlc1.Entries)
                {
                    DoProtectorParamEntry(entry);
                }
            }

            if (protectorNamesFmg_dlc2 != null)
            {
                foreach (var entry in protectorNamesFmg_dlc2.Entries)
                {
                    DoProtectorParamEntry(entry);
                }
            }

            WeaponNames       = WeaponNames.OrderBy(x => x.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            ProtectorNames_HD = ProtectorNames_HD.OrderBy(x => x.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            ProtectorNames_BD = ProtectorNames_BD.OrderBy(x => x.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            ProtectorNames_AM = ProtectorNames_AM.OrderBy(x => x.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            ProtectorNames_LG = ProtectorNames_LG.OrderBy(x => x.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            foreach (var protector in ParamManager.EquipParamProtector)
            {
                if (protector.Value.HeadEquip && !ProtectorNames_HD.ContainsKey((int)protector.Key))
                {
                    ProtectorNames_HD.Add((int)protector.Key, $"<Head {protector.Key}>");
                }
                else if (protector.Value.BodyEquip && !ProtectorNames_BD.ContainsKey((int)protector.Key))
                {
                    ProtectorNames_BD.Add((int)protector.Key, $"<Body {protector.Key}>");
                }
                else if (protector.Value.ArmEquip && !ProtectorNames_AM.ContainsKey((int)protector.Key))
                {
                    ProtectorNames_AM.Add((int)protector.Key, $"<Arms {protector.Key}>");
                }
                else if (protector.Value.LegEquip && !ProtectorNames_LG.ContainsKey((int)protector.Key))
                {
                    ProtectorNames_LG.Add((int)protector.Key, $"<Legs {protector.Key}>");
                }
            }

            foreach (var weapon in ParamManager.EquipParamWeapon)
            {
                if (!WeaponNames.ContainsKey((int)weapon.Key))
                {
                    WeaponNames.Add((int)weapon.Key, $"<Weapon {weapon.Key}>");
                }
            }

            GameTypeCurrentFmgsAreLoadedFrom = GameDataManager.GameType;
        }
        private static void PatchFMG(IBinder sourceBND, IBinder destBND, IBinder refBND, string destLang)
        {
            int iFile              = 0; //File counter
            int iRef               = 0; //Reference index counter
            int entriesAdded       = 0; //Total added per file
            int entriesOverwritten = 0; //Total overwritten per file

            Log.Add($"{ new DirectoryInfo(Path.GetDirectoryName(destLang)).Name } { Path.GetFileName(destLang) } start");

            foreach (var file in sourceBND.Files)      //For each FMG in the source BND file
            {
                if (file.ID > destBND.Files[iFile].ID) //Compatability for using program from non-English folders. Does nothing in the English folder.
                {
                    while ((file.ID > destBND.Files[iFile].ID) && (iFile < destBND.Files.Count - 1))
                    {
                        //ConsoleLog("Skipped " + destBND.Files[iFile].ID); //Debug
                        if (iFile < destBND.Files.Count - 1)
                        {
                            iFile++;
                        }
                    }
                }

                if (file.ID == destBND.Files[iFile].ID) //If the file IDs match, update. If not, skip until they do match
                {
                    //Add the source and destination FMG
                    Log.Add($"Destination: { Path.GetFileName(destBND.Files[iFile].Name) } / Source: { Path.GetFileName(file.Name) }");
                    //ConsoleLog(file.ID + " = true"); // Debug
                    FMG sourceFMG = FMG.Read(file.Bytes);
                    FMG destFMG   = FMG.Read((destBND.Files[iFile]).Bytes);

                    //Make dictionaries out of the FMG files
                    Dictionary <int, string> sourceDict = sourceFMG.Entries.GroupBy(x => x.ID).Select(x => x.First()).ToDictionary(x => x.ID, x => x.Text);
                    Dictionary <int, string> destDict   = destFMG.Entries.GroupBy(x => x.ID).Select(x => x.First()).ToDictionary(x => x.ID, x => x.Text);

                    entriesAdded = AddNew(entriesAdded, sourceDict, destDict);

                    //Make a refFMG and refDict if refBND isn't null
                    Dictionary <int, string> refDict = MakeRef(refBND, iRef);

                    //Make dicitonary based on comparing sourceDict to refDict
                    if (refDict != null)
                    {
                        entriesOverwritten = UpdateText(entriesOverwritten, refDict, sourceDict, destDict);
                    }

                    //Clear and rewrite FMG file
                    RewriteFMG(destFMG, destDict);

                    //Replace old null entries if no reference.
                    if (NoRef)
                    {
                        Log.Add("Changed:");
                        entriesOverwritten = NullOverwrite(entriesOverwritten, sourceFMG, destFMG);
                    }

                    #region Debug Stuff
                    //foreach (var entry in destFMG.Entries)
                    //{
                    //    ConsoleLog(entry);
                    //}
                    #endregion
                    //Write the new files
                    destBND.Files[iFile].Bytes = destFMG.Write();

                    //Add to counter if it's not already maxed
                    if (iFile < destBND.Files.Count - 1)
                    {
                        iFile++;
                    }
                }
                #region Debug Stuff
                //else //Debug
                //{
                //    ConsoleLog(file.ID + " = false");
                //}
                #endregion
                iRef++;
            }
            //Print stats for entire BND file
            ConsoleLog($"Patched: { new DirectoryInfo(Path.GetDirectoryName(destLang)).Name } { Path.GetFileName(destLang) }: { entriesAdded } entries added and { entriesOverwritten } entries overwritten");

            //Append log file
            Log.Add($"{ new DirectoryInfo(Path.GetDirectoryName(destLang)).Name } { Path.GetFileName(destLang) } end");
            File.AppendAllLines($@"{ Directory.GetCurrentDirectory() }\LangPatchLog.txt", Log);
            Log.Clear();
        }
        public void WriteList(GameData game, Dictionary <int, EnemyInfo> fullInfos)
        {
            // Generate things
            HashSet <int> allBonfires = new HashSet <int>
            {
                1001950,  // Dragonspring - Hirata Estate
                1001951,  // Estate Path
                1001952,  // Bamboo Thicket Slope
                1001953,  // Hirata Estate - Main Hall
                1001955,  // Hirata Audience Chamber
                1001954,  // Hirata Estate - Hidden Temple
                1101950,  // Dilapidated Temple
                1101956,  // Ashina Outskirts
                1101951,  // Outskirts Wall - Gate Path
                1101952,  // Outskirts Wall - Stairway
                1101953,  // Underbridge Valley
                1101954,  // Ashina Castle Gate Fortress
                1101955,  // Ashina Castle Gate
                1101957,  // Flames of Hatred
                1111950,  // Ashina Castle
                1111951,  // Upper Tower - Antechamber
                1111957,  // Upper Tower - Ashina Dojo
                1111952,  // Castle Tower Lookout
                1111953,  // Upper Tower - Kuro's Room
                1111956,  // Old Grave
                1111954,  // Great Serpent Shrine
                1111955,  // Abandoned Dungeon Entrance
                1121951,  // Ashina Reservoir
                1121950,  // Near Secret Passage
                1301950,  // Underground Waterway
                1301951,  // Bottomless Hole
                1701955,  // Ashina Depths
                1701954,  // Poison Pool
                1701956,  // Guardian Ape's Burrow
                1501950,  // Hidden Forest
                1501951,  // Mibu Village
                1501952,  // Water Mill
                1501953,  // Wedding Cave Door
                1701957,  // Under-Shrine Valley
                1701950,  // Sunken Valley
                1701951,  // Gun Fort
                1701952,  // Riven Cave
                1701958,  // Bodhisattva Valley
                1701953,  // Guardian Ape's Watering Hole
                2001950,  // Senpou Temple,  Mt. Kongo
                2001951,  // Shugendo
                2001952,  // Temple Grounds
                2001953,  // Main Hall
                2001954,  // Inner Sanctum
                2001955,  // Sunken Valley Cavern
                2001956,  // Bell Demon's Temple
                2501950,  // Fountainhead Palace
                2501951,  // Vermilion Bridge
                2501956,  // Mibu Manor
                2501952,  // Flower Viewing Stage
                2501953,  // Great Sakura
                2501954,  // Palace Grounds
                2501957,  // Feeding Grounds
                2501958,  // Near Pot Noble
                2501955,  // Sanctuary
            };

            // Probably shouldn't use tuples, but too late now
            List <(int, List <string>, List <int>, List <int>)> paths = new List <(int, List <string>, List <int>, List <int>)>
            {
                // Tutorial
                (1, new List <string> {
                    "ashinareservoir", "ashinacastle"
                },
                 new List <int> {
                    8306, 0
                }, new List <int>
                {
                    1121951,  // Ashina Reservoir
                    1121950,  // Near Secret Passage
                }),
                // First stretch of Ashina Outskirts
                (1, new List <string> {
                    "ashinaoutskirts"
                },
                 new List <int> {
                    8302, 1, 8302, -1, 1100330, 1
                }, new List <int>
                {
                    1101956,  // Ashina Outskirts
                    1101951,  // Outskirts Wall - Gate Path
                    1101952,  // Outskirts Wall - Stairway
                }),
                // Ashina Outskirts up to Blazing Bull
                (1, new List <string> {
                    "ashinaoutskirts", "ashinacastle"
                },
                 new List <int> {
                    8302, 1, 8302, -1, 8301, 1, 8301, -1, 1100330, 1
                }, new List <int>
                {
                    1101952,  // Outskirts Wall - Stairway
                    1101953,  // Underbridge Valley
                    1101954,  // Ashina Castle Gate Fortress
                    1101955,  // Ashina Castle Gate
                    // 1111950,  // Ashina Castle
                }),
                // Hirata 1
                (1, new List <string> {
                    "hirata"
                },
                 new List <int> {
                    1000353, 1, 1005601, 1, 1000301, 1, 1000900, 1
                }, new List <int>
                {
                    1001950,  // Dragonspring - Hirata Estate
                    1001951,  // Estate Path
                    1001952,  // Bamboo Thicket Slope
                    1001953,  // Hirata Estate - Main Hall
                    1001955,  // Hirata Audience Chamber
                    1001954,  // Hirata Estate - Hidden Temple
                }),
                // Ashina Castle to Genichiro
                (2, new List <string> {
                    "ashinacastle"
                },
                 new List <int> {
                    8301, 1, 8302, 1, 8302, -1
                }, new List <int>
                {
                    1111950,  // Ashina Castle
                    1111951,  // Upper Tower - Antechamber
                    1111957,  // Upper Tower - Ashina Dojo
                    1111952,  // Castle Tower Lookout
                }),
                // Ashina Castle to Reservoir to Dungeon
                (2, new List <string> {
                    "ashinareservoir"
                },
                 new List <int> {
                    8302, 1, 1120300, 0
                }, new List <int>
                {
                    1111950,  // Ashina Castle
                    1121951,  // Ashina Reservoir
                    1301951,  // Bottomless Hole
                }),
                // Dungeon
                (2, new List <string> {
                    "dungeon"
                },
                 new List <int> {
                }, new List <int>
                {
                    1111955,  // Abandoned Dungeon Entrance
                    1301950,  // Underground Waterway
                    1301951,  // Bottomless Hole
                }),
                // Senpou temple
                (2, new List <string> {
                    "senpou"
                },
                 new List <int> {
                }, new List <int>
                {
                    2001950,  // Senpou Temple,  Mt. Kongo
                    2001951,  // Shugendo
                    2001952,  // Temple Grounds
                    2001953,  // Main Hall
                }),
                // Hidden Forest to Water Mill
                (3, new List <string> {
                    "mibuvillage"
                },
                 new List <int> {
                    1700850, 1, 1700520, 1
                }, new List <int>
                {
                    1501950,  // Hidden Forest
                    1501951,  // Mibu Village
                    1501952,  // Water Mill
                }),
                // End of Ashina Depths
                (3, new List <string> {
                    "mibuvillage"
                },
                 new List <int> {
                }, new List <int>
                {
                    1501952,  // Water Mill
                    1501953,  // Wedding Cave Door
                }),
                // Most of Sunken Valley
                (3, new List <string> {
                    "ashinacastle", "sunkenvalley"
                },
                 new List <int> {
                    8301, 1, 8301, -1, 8302, 1, 8302, -1
                }, new List <int>
                {
                    1111952,  // Castle Tower Lookout
                    1111956,  // Old Grave
                    1111954,  // Great Serpent Shrine
                    1701957,  // Under-Shrine Valley
                    1701950,  // Sunken Valley
                    1701951,  // Gun Fort
                    1701952,  // Riven Cave
                    1701958,  // Bodhisattva Valley
                    1701953,  // Guardian Ape's Watering Hole
                }),
                // Sunken Valley to Poison Pool path
                (3, new List <string> {
                    "sunkenvalley"
                },
                 new List <int> {
                    1700850, 0, 1700520, 0
                }, new List <int>
                {
                    1701958,  // Bodhisattva Valley
                    1701954,  // Poison Pool
                    1701956,  // Guardian Ape's Burrow
                }),
                // Ashina Castle Revisited, also down to Masanaga
                (4, new List <string> {
                    "ashinacastle"
                },
                 new List <int> {
                    8301, 0, 8302, 1, 8302, -1
                }, new List <int>
                {
                    1111955,  // Abandoned Dungeon Entrance
                    1111950,  // Ashina Castle
                    1111951,  // Upper Tower - Antechamber
                    1111957,  // Upper Tower - Ashina Dojo
                    1111952,  // Castle Tower Lookout
                    1111956,  // Old Grave
                    1111954,  // Great Serpent Shrine
                }),
                // Fountainhead
                (5, new List <string> {
                    "fountainhead"
                },
                 new List <int> {
                }, new List <int>
                {
                    2501950,  // Fountainhead Palace
                    2501951,  // Vermilion Bridge
                    2501956,  // Mibu Manor
                    2501952,  // Flower Viewing Stage
                    2501958,  // Near Pot Noble
                    2501953,  // Great Sakura
                    2501954,  // Palace Grounds
                    2501955,  // Sanctuary
                }),
                // Hirata Revisited
                (5, new List <string> {
                    "hirata"
                },
                 new List <int> {
                    1000353, 0, 1005601, 0, 1000301, 0, 1000900, 0
                }, new List <int>
                {
                    1001952,  // Bamboo Thicket Slope
                    1001953,  // Hirata Estate - Main Hall
                    1001955,  // Hirata Audience Chamber
                    1001954,  // Hirata Estate - Hidden Temple
                }),
                // Ashina Castle End to Outskirts
                (5, new List <string> {
                    "ashinacastle", "ashinaoutskirts"
                },
                 new List <int> {
                    8302, 0
                }, new List <int>
                {
                    1111953,  // Upper Tower - Kuro's Room
                    1111956,  // Old Grave
                    1101952,  // Outskirts Wall - Stairway
                    1101951,  // Outskirts Wall - Gate Path
                }),
                // Ashina Castle End to Reservoir
                (5, new List <string> {
                    "ashinacastle", "ashinareservoir"
                },
                 new List <int> {
                    8302, 0
                }, new List <int>
                {
                    1111953,  // Upper Tower - Kuro's Room
                    1111957,  // Upper Tower - Ashina Dojo
                    1111951,  // Upper Tower - Antechamber
                    1111950,  // Ashina Castle
                    1121951,  // Ashina Reservoir
                    1121950,  // Near Secret Passage
                }),
            };
            FMG bonfires = new GameEditor(GameSpec.FromGame.SDT).LoadBnd(@"C:\Program Files (x86)\Steam\steamapps\common\Sekiro\msg\engus\menu.msgbnd.dcx", (p, n) => FMG.Read(p))["NTC_\u30e1\u30cb\u30e5\u30fc\u30c6\u30ad\u30b9\u30c8"];
            Dictionary <int, string> names = new Dictionary <int, string>();

            foreach (PARAM.Row r in game.Params["BonfireWarpParam"].Rows)
            {
                // break;
                int    entity  = (int)r["WarpEventId"].Value;
                string bonfire = bonfires[(int)r["BonfireNameId"].Value];
                if (bonfire != null && entity > 0)
                {
                    names[entity] = bonfire;
                    // Console.WriteLine($"{entity},  // {bonfire}");
                }
            }
            Dictionary <int, Vector3> points = new Dictionary <int, Vector3>();

            // Find location of all bonfires
            foreach (KeyValuePair <string, MSBS> entry in game.Smaps)
            {
                if (!game.Locations.ContainsKey(entry.Key))
                {
                    continue;
                }
                string map = game.Locations[entry.Key];
                MSBS   msb = entry.Value;
                foreach (MSBS.Part.Object e in msb.Parts.Objects)
                {
                    if (allBonfires.Contains(e.EntityID))
                    {
                        points[e.EntityID] = e.Position;
                    }
                }
            }
            string pathText(int p)
            {
                int first = paths[p].Item4.First();
                int last  = paths[p].Item4.Last();

                return($"#{paths[p].Item1} {names[first]}->{names[last]}");
            }

            bool investigateScaling = false;
            List <List <EnemyClass> > typeGroups = new List <List <EnemyClass> >
            {
                new List <EnemyClass> {
                    EnemyClass.Boss, EnemyClass.TutorialBoss
                },
                new List <EnemyClass> {
                    EnemyClass.Miniboss
                },
                new List <EnemyClass> {
                    EnemyClass.Basic, EnemyClass.FoldingMonkey, EnemyClass.OldDragon
                }
            };
            List <EnemyClass>           types = typeGroups.SelectMany(c => c).ToList();
            Dictionary <int, EnemyInfo> infos = fullInfos.Values.Where(e => types.Contains(e.Class)).ToDictionary(e => e.ID, e => e);

            if (!investigateScaling)
            {
                infos.Remove(1110920);
                infos.Remove(1110900);
                infos.Remove(1120800);
            }
            Dictionary <int, List <int> > possiblePaths = new Dictionary <int, List <int> >();
            bool explainCat = false;

            for (int i = 0; i < paths.Count; i++)
            {
                if (explainCat)
                {
                    Console.WriteLine($"--- Processing {pathText(i)}");
                }
                (int section, List <string> maps, List <int> cond, List <int> order) = paths[i];
                Dictionary <int, List <int> > eventFlags = new Dictionary <int, List <int> >();
                HashSet <int> excludeEntity = new HashSet <int>();
                HashSet <int> expectEntity  = new HashSet <int>();
                HashSet <int> getEntity     = new HashSet <int>();
                for (int j = 0; j < cond.Count; j += 2)
                {
                    int check = cond[j];
                    int val   = cond[j + 1];
                    if (check >= 1000000)
                    {
                        if (val == 0)
                        {
                            expectEntity.Add(check);
                        }
                        else
                        {
                            excludeEntity.Add(check);
                        }
                    }
                    else
                    {
                        AddMulti(eventFlags, check, val);
                    }
                }
                foreach (KeyValuePair <string, MSBS> entry in game.Smaps)
                {
                    if (!game.Locations.ContainsKey(entry.Key))
                    {
                        continue;
                    }
                    string map = game.Locations[entry.Key];
                    MSBS   msb = entry.Value;

                    if (!maps.Contains(map))
                    {
                        continue;
                    }
                    foreach (MSBS.Part.Enemy e in msb.Parts.Enemies)
                    {
                        if (!infos.ContainsKey(e.EntityID))
                        {
                            continue;
                        }
                        points[e.EntityID] = e.Position;
                        names[e.EntityID]  = game.ModelName(e.ModelName);
                        List <int> ids = new List <int> {
                            e.EntityID
                        };
                        ids.AddRange(e.EntityGroupIDs.Where(id => id > 0));
                        if (excludeEntity.Overlaps(ids))
                        {
                            if (explainCat)
                            {
                                Console.WriteLine($"excluded: {string.Join(",", ids)} from {string.Join(",", excludeEntity)}");
                            }
                            continue;
                        }
                        else if (expectEntity.Overlaps(ids))
                        {
                            getEntity.UnionWith(ids);
                        }
                        else if (eventFlags.Count > 0)
                        {
                            // If not explicitly expected, do a check for game progression
                            Dictionary <int, int> flags = new Dictionary <int, int>();
                            if (e.EventFlagID != -1)
                            {
                                flags[e.EventFlagID] = e.EventFlagCompareState;
                            }
                            if (e.UnkT48 != -1)
                            {
                                flags[e.UnkT48] = e.UnkT4C;
                            }
                            if (e.UnkT50 != -1)
                            {
                                flags[e.UnkT50] = 1;
                            }
                            bool mismatch = false;
                            foreach (KeyValuePair <int, List <int> > flagPair in eventFlags)
                            {
                                int        flag = flagPair.Key;
                                List <int> cmps = flagPair.Value;
                                int        cmp  = flags.TryGetValue(flag, out int tmp) ? tmp : -1;
                                if (explainCat && e.EntityID == 9999999)
                                {
                                    Console.WriteLine($"for {e.EntityID} expected {flag} = {string.Join(",", cmps)}, found result {cmp}");
                                }
                                if (!cmps.Contains(cmp))
                                {
                                    if (explainCat)
                                    {
                                        Console.WriteLine($"excluded: {string.Join(",", ids)} with {flag} = {cmp} (not {string.Join(",", cmps)})");
                                    }
                                    mismatch = true;
                                }
                            }
                            if (mismatch)
                            {
                                continue;
                            }
                        }
                        if (explainCat)
                        {
                            Console.WriteLine($"added: {string.Join(",", ids)}");
                        }
                        AddMulti(possiblePaths, e.EntityID, i);
                    }
                }
                List <int> missing = expectEntity.Except(getEntity).ToList();
                if (missing.Count > 0)
                {
                    throw new Exception($"Missing {string.Join(",", missing)} in {string.Join(",", maps)}");
                }
            }
            // Hardcode headless into Senpou, because it is out of the way and sort of a singleton
            possiblePaths[1100330] = new List <int> {
                7
            };

            Console.WriteLine("Categories");
            Dictionary <int, (int, float)> chosenPath = new Dictionary <int, (int, float)>();

            foreach (EnemyInfo info in infos.Values)
            {
                if (!possiblePaths.TryGetValue(info.ID, out List <int> pathList))
                {
                    throw new Exception($"{info.ID} has no categorization: {info.DebugText}");
                }
                if (paths[pathList[0]].Item2.Contains("hirata"))
                {
                    // If Hirata, greedily choose pre-revisited Hirata
                    pathList = new List <int> {
                        pathList[0]
                    };
                }
                float   score = float.PositiveInfinity;
                Vector3 pos   = points[info.ID];
                foreach (int path in pathList)
                {
                    (int section, List <string> maps, List <int> cond, List <int> order) = paths[path];
                    for (int i = 0; i < order.Count - 1; i++)
                    {
                        Vector3 p1    = points[order[i]];
                        Vector3 p2    = points[order[i + 1]];
                        float   dist1 = Vector3.Distance(p1, pos);
                        float   dist2 = Vector3.Distance(p2, pos);
                        float   dist  = dist1 + dist2;
                        if (info.ID == 9999999)
                        {
                            Console.WriteLine($"Found dist {dist1} to {names[order[i]]}, and {dist2} to {names[order[i + 1]]}. TOTAL {dist}");
                        }
                        if (dist < score)
                        {
                            score = dist;
                            chosenPath[info.ID] = (path, i + Vector3.Distance(p1, pos) / dist);
                        }
                    }
                }
                if (float.IsInfinity(score))
                {
                    throw new Exception($"{info.ID} with paths {string.Join(",", pathList.Select(pathText))} had nothing checked for it");
                }
            }

            // Put bosses in phase order
            foreach (int id in chosenPath.Keys.ToList())
            {
                EnemyInfo info = infos[id];
                if (info.Class == EnemyClass.Boss && info.OwnedBy != 0)
                {
                    chosenPath[id] = chosenPath[info.OwnedBy];
                }
            }

            if (investigateScaling)
            {
                Dictionary <int, MSBS.Part.Enemy> enemies = new Dictionary <int, MSBS.Part.Enemy>();
                foreach (KeyValuePair <string, MSBS> entry in game.Smaps)
                {
                    if (!game.Locations.ContainsKey(entry.Key))
                    {
                        continue;
                    }
                    string map = game.Locations[entry.Key];
                    MSBS   msb = entry.Value;
                    foreach (MSBS.Part.Enemy e in msb.Parts.Enemies)
                    {
                        enemies[e.EntityID] = e;
                    }
                }

                // Exclude these from scaling considerations, since they are not really part of the area (meant for when visiting later)
                HashSet <int> phantomGroups = new HashSet <int>
                {
                    // Ashina phantoms
                    1505201, 1505211, 1705200, 1705201, 2005200, 2005201,
                    // Sunken Valley phantoms
                    1505202, 1505212, 2005210, 2005211,
                    // Mibu Village phantoms
                    1705220, 1705221, 2005220, 2005221,
                };

                // haveSoulRate Unk85: NG+ only
                // EventFlagId: used for scaling speffect
                // There are these overall groups: vitality, damage, experience, cash. (is there haveSoulRate for cash/xp? maybe it's Unk85)
                List <string> scaleSp   = "maxHpRate maxStaminaCutRate physAtkPowerRate magicAtkPowerRate fireAtkPowerRate thunderAtkPowerRate staminaAttackRate darkAttackPowerRate NewGameBonusUnk".Split(' ').ToList();
                List <string> scaleNpc  = "Hp getSoul stamina staminaRecoverBaseVal Experience".Split(' ').ToList();
                List <string> allFields = scaleSp.Concat(scaleNpc).ToList();
                // Disp: ModelDispMask0 -> ModelDispMask31
                // Npc param has GameClearSpEffectID
                Dictionary <(string, int, int), List <float> > allScales = new Dictionary <(string, int, int), List <float> >();
                Dictionary <int, int> allSections = new Dictionary <int, int>();
                foreach (List <EnemyClass> typeGroup in typeGroups)
                {
                    // Consider two enemies the same if they have the same think id, or same disp mask
                    // Or for minibosses, if they are just the same model, that's probably fine
                    Dictionary <string, List <int> > thinks = new Dictionary <string, List <int> >();
                    Dictionary <string, List <int> > masks  = new Dictionary <string, List <int> >();
                    Dictionary <string, List <int> > bosses = new Dictionary <string, List <int> >();
                    List <string>         order             = new List <string>();
                    Dictionary <int, int> sections          = new Dictionary <int, int>();
                    foreach (KeyValuePair <int, (int, float)> entry in chosenPath.OrderBy(e => (e.Value, e.Key)))
                    {
                        int       id   = entry.Key;
                        EnemyInfo info = infos[id];
                        if (!typeGroup.Contains(info.Class))
                        {
                            continue;
                        }
                        MSBS.Part.Enemy e       = enemies[id];
                        int             path    = entry.Value.Item1;
                        int             section = paths[path].Item1;
                        sections[id]    = section;
                        allSections[id] = section;
                        if (e.EntityGroupIDs.Any(g => phantomGroups.Contains(g)))
                        {
                            continue;
                        }
                        string model = game.ModelName(e.ModelName);
                        if (typeGroup.Contains(EnemyClass.Miniboss) || typeGroup.Contains(EnemyClass.Boss))
                        {
                            AddMulti(bosses, model, id);
                            continue;
                        }
                        string think = $"{model} {e.ThinkParamID}";
                        AddMulti(thinks, think, id);
                        PARAM.Row npc = game.Params["NpcParam"][e.NPCParamID];
                        if (e.NPCParamID > 0 && npc != null)
                        {
                            uint mask = 0;
                            for (int i = 0; i < 32; i++)
                            {
                                if ((byte)npc[$"ModelDispMask{i}"].Value == 1)
                                {
                                    mask |= ((uint)1 << i);
                                }
                            }
                            string dispMask = $"{model} 0x{mask:X8}";
                            AddMulti(masks, dispMask, id);
                        }
                    }
                    foreach (KeyValuePair <string, List <int> > entry in thinks.Concat(masks.Concat(bosses)))
                    {
                        if (entry.Value.Count == 1)
                        {
                            continue;
                        }
                        List <int> secs = entry.Value.Select(i => sections[i]).Distinct().ToList();
                        if (secs.Count == 1)
                        {
                            continue;
                        }

                        Console.WriteLine($"{entry.Key}: {string.Join(",", entry.Value.Select(i => $"{i}[{sections[i]}]"))}");
                        SortedDictionary <string, List <(int, float)> > fieldValues = new SortedDictionary <string, List <(int, float)> >();
                        foreach (int id in entry.Value)
                        {
                            MSBS.Part.Enemy e   = enemies[id];
                            PARAM.Row       npc = game.Params["NpcParam"][e.NPCParamID];
                            if (e.NPCParamID == 0 || npc == null)
                            {
                                continue;
                            }
                            Dictionary <string, float> values = new Dictionary <string, float>();
                            foreach (string f in scaleNpc)
                            {
                                values[f] = float.Parse(npc[f].Value.ToString());
                            }
                            int       spVal = (int)npc["EventFlagId"].Value; // GameClearSpEffectID is for NG+ only, or time-of-day only, or something like that
                            PARAM.Row sp    = game.Params["SpEffectParam"][spVal];
                            if (spVal > 0 && sp != null)
                            {
                                foreach (string f in scaleSp)
                                {
                                    values[f] = float.Parse(sp[f].Value.ToString());
                                }
                            }
                            foreach (KeyValuePair <string, float> val in values)
                            {
                                AddMulti(fieldValues, val.Key, (sections[id], val.Value));
                            }
                        }
                        foreach (KeyValuePair <string, List <(int, float)> > val in fieldValues)
                        {
                            // Console.WriteLine($"  {val.Key}: {string.Join(", ", val.Value.OrderBy(v => v).Select(v => $"[{v.Item1}]{v.Item2}"))}");
                            Dictionary <int, float> bySection = val.Value.GroupBy(v => v.Item1).ToDictionary(g => g.Key, g => g.Select(v => v.Item2).Average());
                            List <string>           sorts     = new List <string>();
                            foreach (int i in bySection.Keys)
                            {
                                foreach (int j in bySection.Keys)
                                {
                                    if (i >= j)
                                    {
                                        continue;
                                    }
                                    float ratio = bySection[j] / bySection[i];
                                    if (float.IsNaN(ratio) || float.IsInfinity(ratio) || ratio == 1 || ratio == 0)
                                    {
                                        continue;
                                    }
                                    sorts.Add($"{i}{j}: {ratio:f3}x");
                                    AddMulti(allScales, (val.Key, i, j), ratio);
                                    // Can be used for complete table, but easier to leave out for lower diagonal
                                    // AddMulti(allScales, (val.Key, j, i), 1 / ratio);
                                }
                            }
                            if (sorts.Count > 0)
                            {
                                Console.WriteLine($"  {val.Key}: {string.Join(", ", sorts)}");
                            }
                        }
                    }
                }
                foreach (string field in allFields)
                {
                    Console.WriteLine($"-- {field} ({allScales.Where(k => k.Key.Item1 == field).Sum(e => e.Value.Count)})");
                    for (int i = 1; i <= 5; i++)
                    {
                        // row: the target class. column: the source class. value: how much to multiply to place the source in the target.
                        Console.WriteLine("  " + string.Join(" ", Enumerable.Range(1, 5).Select(j => allScales.TryGetValue((field, j, i), out List <float> floats) ? $"{floats.Average():f5}," : "        ")));
                    }
                }
                foreach (EnemyInfo info in fullInfos.Values)
                {
                    if (!allSections.ContainsKey(info.ID) && info.Class == EnemyClass.Helper && allSections.TryGetValue(info.OwnedBy, out int section))
                    {
                        allSections[info.ID] = section;
                    }
                }
                foreach (KeyValuePair <int, int> entry in allSections.OrderBy(e => (e.Value, e.Key)))
                {
                    Console.WriteLine($"  {entry.Key}: {entry.Value}");
                }
            }

            bool debugOutput = false;

            foreach (List <EnemyClass> typeGroup in typeGroups)
            {
                List <string> order = new List <string>();
                foreach (KeyValuePair <int, (int, float)> entry in chosenPath.OrderBy(e => (e.Value, e.Key)))
                {
                    int       id   = entry.Key;
                    EnemyInfo info = infos[id];
                    if (!typeGroup.Contains(info.Class))
                    {
                        continue;
                    }
                    if (debugOutput)
                    {
                        Console.WriteLine($"{info.DebugText}\n- {pathText(entry.Value.Item1)}, progress {entry.Value.Item2}\n");
                    }
                    order.Add($"{info.ExtraName ?? names[id]} {id}");
                }
                for (int i = 0; i < order.Count; i++)
                {
                    if (!debugOutput)
                    {
                        Console.WriteLine($"  {order[i]}: {order[order.Count - 1 - i]}");
                    }
                }
            }
        }
Ejemplo n.º 12
0
    public static void ReloadFmgs()
    {
        BND4 fmgBnd = BND4.Read(FMGBndPath);

        ItemFMG = FMG.Read(fmgBnd.Files.Find(x => Path.GetFileName(x.Name) == "アイテム名.fmg").Bytes);
    }
Ejemplo n.º 13
0
        public static void LoadAllFMG(bool forceReload)
        {
            if (!forceReload && GameTypeCurrentFmgsAreLoadedFrom == GameDataManager.GameType)
            {
                return;
            }

            List <FMG> weaponNameFMGs = new List <FMG>();
            List <FMG> armorNameFMGs  = new List <FMG>();

            /*
             *  [ptde]
             *  weapon 1
             *  armor 2
             *
             *  [ds1r]
             *  weapon 1, 30
             *  armor 2, 32
             *
             *  [ds3]
             *  weapon 1
             *  armor 2
             *  weapon_dlc1 18
             *  armor_dlc1 19
             *  weapon_dlc2 33
             *  armor_dlc2 34
             *
             *  [bb]
             *  weapon 1
             *  armor 2
             *
             *  [sdt]
             *  weapon 1
             *  armor 2
             */

            void TryToLoadFromMSGBND(string language, string msgbndName, int weaponNamesIdx, int armorNamesIdx)
            {
                var     msgbndRelativePath = $@"msg\{language}\{msgbndName}";
                var     fullMsgbndPath     = GameDataManager.GetInterrootPath(msgbndRelativePath);
                IBinder msgbnd             = null;

                if (File.Exists(fullMsgbndPath))
                {
                    if (BND3.Is(fullMsgbndPath))
                    {
                        msgbnd = BND3.Read(fullMsgbndPath);
                    }
                    else if (BND4.Is(fullMsgbndPath))
                    {
                        msgbnd = BND4.Read(fullMsgbndPath);
                    }

                    weaponNameFMGs.Add(FMG.Read(msgbnd.Files.First(x => x.ID == weaponNamesIdx).Bytes));
                    armorNameFMGs.Add(FMG.Read(msgbnd.Files.First(x => x.ID == armorNamesIdx).Bytes));
                }

                if (msgbnd == null)
                {
                    System.Windows.Forms.MessageBox.Show(
                        $"Unable to find text file '{msgbndRelativePath}'. Some player equipment may not show names.",
                        "Unable to find asset", System.Windows.Forms.MessageBoxButtons.OK,
                        System.Windows.Forms.MessageBoxIcon.Warning);

                    return;
                }
            }

            if (GameDataManager.GameType == GameDataManager.GameTypes.DS1)
            {
                TryToLoadFromMSGBND("ENGLISH", "item.msgbnd", 11, 12);
                TryToLoadFromMSGBND("ENGLISH", "menu.msgbnd", 115, 117); //Patch
            }
            else if (GameDataManager.GameType == GameDataManager.GameTypes.DS1R)
            {
                TryToLoadFromMSGBND("ENGLISH", "item.msgbnd.dcx", 11, 12);
                TryToLoadFromMSGBND("ENGLISH", "item.msgbnd.dcx", 115, 117); //Patch
            }
            else if (GameDataManager.GameType == GameDataManager.GameTypes.DS3)
            {
                TryToLoadFromMSGBND("engus", "item_dlc1.msgbnd.dcx", 11, 12);
                TryToLoadFromMSGBND("engus", "item_dlc1.msgbnd.dcx", 211, 212); //DLC1

                TryToLoadFromMSGBND("engus", "item_dlc2.msgbnd.dcx", 11, 12);
                TryToLoadFromMSGBND("engus", "item_dlc2.msgbnd.dcx", 211, 212); //DLC1
                TryToLoadFromMSGBND("engus", "item_dlc2.msgbnd.dcx", 251, 252); //DLC2
            }
            else if (GameDataManager.GameType == GameDataManager.GameTypes.SDT)
            {
                TryToLoadFromMSGBND("engus", "item.msgbnd.dcx", 11, 12);
            }
            else if (GameDataManager.GameType == GameDataManager.GameTypes.BB)
            {
                TryToLoadFromMSGBND("engus", "item.msgbnd.dcx", 11, 12);
            }

            WeaponNames.Clear();

            void DoWeaponEntry(FMG.Entry entry)
            {
                if (string.IsNullOrWhiteSpace(entry.Text) ||
                    !ParamManager.EquipParamWeapon.ContainsKey(entry.ID))
                {
                    return;
                }

                //if (GameDataManager.GameType == GameDataManager.GameTypes.DS3 && (entry.ID % 10000) != 0)
                //    return;
                //else if ((entry.ID % 1000) != 0)
                //    return;
                string val = entry.Text + $" <{entry.ID}>";

                if (WeaponNames.ContainsKey(entry.ID))
                {
                    WeaponNames[entry.ID] = val;
                }
                else
                {
                    WeaponNames.Add(entry.ID, val);
                }
            }

            foreach (var wpnNameFmg in weaponNameFMGs)
            {
                foreach (var entry in wpnNameFmg.Entries)
                {
                    DoWeaponEntry(entry);
                }
            }

            ProtectorNames_HD.Clear();
            ProtectorNames_BD.Clear();
            ProtectorNames_AM.Clear();
            ProtectorNames_LG.Clear();

            void DoProtectorParamEntry(FMG.Entry entry)
            {
                if (string.IsNullOrWhiteSpace(entry.Text))
                {
                    return;
                }
                //if (entry.ID < 1000000 && GameDataManager.GameType == GameDataManager.GameTypes.DS3)
                //    return;
                if (ParamManager.EquipParamProtector.ContainsKey(entry.ID))
                {
                    string val            = entry.Text + $" <{entry.ID}>";
                    var    protectorParam = ParamManager.EquipParamProtector[entry.ID];
                    if (protectorParam.HeadEquip)
                    {
                        if (ProtectorNames_HD.ContainsKey(entry.ID))
                        {
                            ProtectorNames_HD[entry.ID] = val;
                        }
                        else
                        {
                            ProtectorNames_HD.Add(entry.ID, val);
                        }
                    }
                    else if (protectorParam.BodyEquip)
                    {
                        if (ProtectorNames_BD.ContainsKey(entry.ID))
                        {
                            ProtectorNames_BD[entry.ID] = val;
                        }
                        else
                        {
                            ProtectorNames_BD.Add(entry.ID, entry.Text + $" <{entry.ID}>");
                        }
                    }
                    else if (protectorParam.ArmEquip)
                    {
                        if (ProtectorNames_AM.ContainsKey(entry.ID))
                        {
                            ProtectorNames_AM[entry.ID] = val;
                        }
                        else
                        {
                            ProtectorNames_AM.Add(entry.ID, entry.Text + $" <{entry.ID}>");
                        }
                    }
                    else if (protectorParam.LegEquip)
                    {
                        if (ProtectorNames_LG.ContainsKey(entry.ID))
                        {
                            ProtectorNames_LG[entry.ID] = val;
                        }
                        else
                        {
                            ProtectorNames_LG.Add(entry.ID, entry.Text + $" <{entry.ID}>");
                        }
                    }
                }
            }

            foreach (var armorNameFmg in armorNameFMGs)
            {
                foreach (var entry in armorNameFmg.Entries)
                {
                    DoProtectorParamEntry(entry);
                }
            }

            WeaponNames       = WeaponNames.OrderBy(x => x.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            ProtectorNames_HD = ProtectorNames_HD.OrderBy(x => x.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            ProtectorNames_BD = ProtectorNames_BD.OrderBy(x => x.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            ProtectorNames_AM = ProtectorNames_AM.OrderBy(x => x.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            ProtectorNames_LG = ProtectorNames_LG.OrderBy(x => x.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            foreach (var protector in ParamManager.EquipParamProtector)
            {
                if (protector.Value.HeadEquip && !ProtectorNames_HD.ContainsKey((int)protector.Key))
                {
                    ProtectorNames_HD.Add((int)protector.Key, $"<{protector.Key}>");
                }
                else if (protector.Value.BodyEquip && !ProtectorNames_BD.ContainsKey((int)protector.Key))
                {
                    ProtectorNames_BD.Add((int)protector.Key, $"<{protector.Key}>");
                }
                else if (protector.Value.ArmEquip && !ProtectorNames_AM.ContainsKey((int)protector.Key))
                {
                    ProtectorNames_AM.Add((int)protector.Key, $"<{protector.Key}>");
                }
                else if (protector.Value.LegEquip && !ProtectorNames_LG.ContainsKey((int)protector.Key))
                {
                    ProtectorNames_LG.Add((int)protector.Key, $"<{protector.Key}>");
                }
            }

            foreach (var weapon in ParamManager.EquipParamWeapon)
            {
                if (!WeaponNames.ContainsKey((int)weapon.Key))
                {
                    WeaponNames.Add((int)weapon.Key, $"<{weapon.Key}>");
                }
            }

            ProtectorNames_HD = ProtectorNames_HD.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            ProtectorNames_BD = ProtectorNames_BD.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            ProtectorNames_AM = ProtectorNames_AM.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            ProtectorNames_LG = ProtectorNames_LG.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            WeaponNames       = WeaponNames.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            GameTypeCurrentFmgsAreLoadedFrom = GameDataManager.GameType;
        }
Ejemplo n.º 14
0
        private static bool UnpackFile(string sourceFile)
        {
            string sourceDir = Path.GetDirectoryName(sourceFile);
            string filename  = Path.GetFileName(sourceFile);
            string targetDir = $"{sourceDir}\\{filename.Replace('.', '-')}";

            if (File.Exists(targetDir))
            {
                targetDir += "-ybr";
            }

            if (DCX.Is(sourceFile))
            {
                Console.WriteLine($"Decompressing DCX: {filename}...");
                byte[] bytes = DCX.Decompress(sourceFile, out DCX.Type compression);
                if (BND3.Is(bytes))
                {
                    Console.WriteLine($"Unpacking BND3: {filename}...");
                    BND3 bnd = BND3.Read(bytes);
                    bnd.Compression = compression;
                    bnd.Unpack(filename, targetDir);
                }
                else if (BND4.Is(bytes))
                {
                    Console.WriteLine($"Unpacking BND4: {filename}...");
                    BND4 bnd = BND4.Read(bytes);
                    bnd.Compression = compression;
                    bnd.Unpack(filename, targetDir);
                }
                else if (TPF.Is(bytes))
                {
                    Console.WriteLine($"Unpacking TPF: {filename}...");
                    TPF tpf = TPF.Read(bytes);
                    tpf.Compression = compression;
                    tpf.Unpack(filename, targetDir);
                }
                else if (sourceFile.EndsWith(".gparam.dcx"))
                {
                    Console.WriteLine($"Unpacking GPARAM: {filename}...");
                    GPARAM gparam = GPARAM.Read(bytes);
                    gparam.Unpack(sourceFile);
                }
                else
                {
                    Console.WriteLine($"File format not recognized: {filename}");
                    return(true);
                }
            }
            else
            {
                if (BND3.Is(sourceFile))
                {
                    Console.WriteLine($"Unpacking BND3: {filename}...");
                    BND3 bnd = BND3.Read(sourceFile);
                    bnd.Unpack(filename, targetDir);
                }
                else if (BND4.Is(sourceFile))
                {
                    Console.WriteLine($"Unpacking BND4: {filename}...");
                    BND4 bnd = BND4.Read(sourceFile);
                    bnd.Unpack(filename, targetDir);
                }
                else if (BXF3.IsBHD(sourceFile))
                {
                    string bdtExtension = Path.GetExtension(filename).Replace("bhd", "bdt");
                    string bdtFilename  = $"{Path.GetFileNameWithoutExtension(filename)}{bdtExtension}";
                    string bdtPath      = $"{sourceDir}\\{bdtFilename}";
                    if (File.Exists(bdtPath))
                    {
                        Console.WriteLine($"Unpacking BXF3: {filename}...");
                        BXF3 bxf = BXF3.Read(sourceFile, bdtPath);
                        bxf.Unpack(filename, bdtFilename, targetDir);
                    }
                    else
                    {
                        Console.WriteLine($"BDT not found for BHD: {filename}");
                        return(true);
                    }
                }
                else if (BXF4.IsBHD(sourceFile))
                {
                    string bdtExtension = Path.GetExtension(filename).Replace("bhd", "bdt");
                    string bdtFilename  = $"{Path.GetFileNameWithoutExtension(filename)}{bdtExtension}";
                    string bdtPath      = $"{sourceDir}\\{bdtFilename}";
                    if (File.Exists(bdtPath))
                    {
                        Console.WriteLine($"Unpacking BXF4: {filename}...");
                        BXF4 bxf = BXF4.Read(sourceFile, bdtPath);
                        bxf.Unpack(filename, bdtFilename, targetDir);
                    }
                    else
                    {
                        Console.WriteLine($"BDT not found for BHD: {filename}");
                        return(true);
                    }
                }
                else if (TPF.Is(sourceFile))
                {
                    Console.WriteLine($"Unpacking TPF: {filename}...");
                    TPF tpf = TPF.Read(sourceFile);
                    tpf.Unpack(filename, targetDir);
                }
                else if (sourceFile.EndsWith(".fmg"))
                {
                    Console.WriteLine($"Unpacking FMG: {filename}...");
                    FMG fmg = FMG.Read(sourceFile);
                    fmg.Unpack(sourceFile);
                }
                else if (sourceFile.EndsWith(".fmg.xml"))
                {
                    Console.WriteLine($"Repacking FMG: {filename}...");
                    YFMG.Repack(sourceFile);
                }
                else if (sourceFile.EndsWith(".gparam"))
                {
                    Console.WriteLine($"Unpacking GPARAM: {filename}...");
                    GPARAM gparam = GPARAM.Read(sourceFile);
                    gparam.Unpack(sourceFile);
                }
                else if (sourceFile.EndsWith(".gparam.xml") || sourceFile.EndsWith(".gparam.dcx.xml"))
                {
                    Console.WriteLine($"Repacking GPARAM: {filename}...");
                    YGPARAM.Repack(sourceFile);
                }
                else if (sourceFile.EndsWith(".luagnl"))
                {
                    Console.WriteLine($"Unpacking LUAGNL: {filename}...");
                    LUAGNL gnl = LUAGNL.Read(sourceFile);
                    gnl.Unpack(sourceFile);
                }
                else if (sourceFile.EndsWith(".luagnl.xml"))
                {
                    Console.WriteLine($"Repacking LUAGNL: {filename}...");
                    YLUAGNL.Repack(sourceFile);
                }
                else if (LUAINFO.Is(sourceFile))
                {
                    Console.WriteLine($"Unpacking LUAINFO: {filename}...");
                    LUAINFO info = LUAINFO.Read(sourceFile);
                    info.Unpack(sourceFile);
                }
                else if (sourceFile.EndsWith(".luainfo.xml"))
                {
                    Console.WriteLine($"Repacking LUAINFO: {filename}...");
                    YLUAINFO.Repack(sourceFile);
                }
                else
                {
                    Console.WriteLine($"File format not recognized: {filename}");
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 15
0
        public void WriteEventConfig(AnnotationData ann, Events events, RandomizerOptions opt)
        {
            GameEditor editor = new GameEditor(FromGame.DS3);

            editor.Spec.GameDir = "fogdist";
            Dictionary <string, MSB3>  maps   = editor.Load(@"Base", path => ann.Specs.ContainsKey(GameEditor.BaseName(path)) ? MSB3.Read(path) : null, "*.msb.dcx");
            Dictionary <string, EMEVD> emevds = editor.Load(@"Base", path => ann.Specs.ContainsKey(GameEditor.BaseName(path)) || path.Contains("common") ? EMEVD.Read(path) : null, "*.emevd.dcx");

            void deleteEmpty <K, V>(Dictionary <K, V> d)
            {
                foreach (K key in d.Keys.ToList())
                {
                    if (d[key] == null)
                    {
                        d.Remove(key);
                    }
                }
            }

            // Should this be in GameEditor?
            deleteEmpty(maps);
            deleteEmpty(emevds);

            editor.Spec.NameDir = @"fogdist\Names";
            Dictionary <string, string>    modelNames = editor.LoadNames("ModelName", n => n);
            SortedDictionary <int, string> chars      = new SortedDictionary <int, string>(editor.LoadNames("CharaInitParam", n => int.Parse(n)));

            Dictionary <string, List <string> > description          = new Dictionary <string, List <string> >();
            Dictionary <int, string>            entityNames          = new Dictionary <int, string>();
            Dictionary <int, List <int> >       groupIds             = new Dictionary <int, List <int> >();
            Dictionary <(string, string), MSB3.Event.ObjAct> objacts = new Dictionary <(string, string), MSB3.Event.ObjAct>();

            HashSet <int> highlightIds = new HashSet <int>();
            HashSet <int> selectIds    = new HashSet <int>();

            foreach (Entrance e in ann.Warps.Concat(ann.Entrances))
            {
                int id = e.ID;
                AddMulti(description, id.ToString(), (ann.Warps.Contains(e) ? "" : "fog gate ") + e.Text);
                selectIds.Add(e.ID);
                highlightIds.Add(e.ID);
            }
            HashSet <string> gameObjs = new HashSet <string>();

            foreach (GameObject obj in ann.Objects)
            {
                if (int.TryParse(obj.ID, out int id))
                {
                    AddMulti(description, id.ToString(), obj.Text);
                    selectIds.Add(id);
                    highlightIds.Add(id);
                }
                else
                {
                    gameObjs.Add($"{obj.Area}_{obj.ID}");
                }
            }

            Dictionary <string, Dictionary <string, FMG> > fmgs = new GameEditor(FromGame.DS3).LoadBnds($@"msg\engus", (data, name) => FMG.Read(data), ext: "*_dlc2.msgbnd.dcx");

            void addFMG(FMG fmg, string desc)
            {
                foreach (FMG.Entry e in fmg.Entries)
                {
                    if (e.ID > 25000 && !string.IsNullOrWhiteSpace(e.Text))
                    {
                        highlightIds.Add(e.ID);
                        AddMulti(description, e.ID.ToString(), desc + " " + "\"" + e.Text.Replace("\r", "").Replace("\n", "\\n") + "\"");
                    }
                }
            }

            addFMG(fmgs["item_dlc2"]["NPC名"], "name");
            addFMG(fmgs["menu_dlc2"]["イベントテキスト"], "text");

            foreach (KeyValuePair <string, MSB3> entry in maps)
            {
                string map = ann.Specs[entry.Key].Name;
                MSB3   msb = entry.Value;

                foreach (MSB3.Part e in msb.Parts.GetEntries())
                {
                    string shortName = $"{map}_{e.Name}";
                    if (modelNames.TryGetValue(e.ModelName, out string modelDesc))
                    {
                        if (e is MSB3.Part.Enemy en && modelDesc == "Human NPC" && en.CharaInitID > 0)
                        {
                            modelDesc = CharacterName(chars, en.CharaInitID);
                        }
                        else if (e is MSB3.Part.Player)
                        {
                            modelDesc = "Warp Point";
                        }
                        AddMulti(description, shortName, modelDesc);
                    }
                    AddMulti(description, shortName, $"{map} {e.GetType().Name.ToString().ToLowerInvariant()} {e.Name}");  // {(e.EventEntityID > 0 ? $" {e.EventEntityID}" : "")}
                    if (e.EventEntityID > 10)
                    {
                        highlightIds.Add(e.EventEntityID);
                        string idStr = e.EventEntityID.ToString();
                        if (description.ContainsKey(idStr))
                        {
                            AddMulti(description, shortName, description[idStr]);
                        }
                        description[idStr] = description[shortName];
                        if (e is MSB3.Part.Player || e.ModelName == "o000100")
                        {
                            selectIds.Add(e.EventEntityID);
                        }
                        if (selectIds.Contains(e.EventEntityID))
                        {
                            gameObjs.Add(shortName);
                        }

                        foreach (int id in e.EventEntityGroups)
                        {
                            if (id > 0)
                            {
                                AddMulti(groupIds, id, e.EventEntityID);
                                highlightIds.Add(id);
                            }
                        }
                    }
                }
                foreach (MSB3.Region r in msb.Regions.GetEntries())
                {
                    if (r.EventEntityID < 1000000)
                    {
                        continue;
                    }
                    AddMulti(description, r.EventEntityID.ToString(), $"{map} {r.GetType().Name.ToLowerInvariant()} region {r.Name}");
                    highlightIds.Add(r.EventEntityID);
                }
                foreach (MSB3.Event e in msb.Events.GetEntries())
                {
                    if (e is MSB3.Event.ObjAct oa)
                    {
                        // It can be null, basically for commented out objacts
                        string part = oa.PartName ?? oa.PartName2;
                        if (part == null)
                        {
                            continue;
                        }
                        string desc = description.TryGetValue($"{map}_{part}", out List <string> p) ? string.Join(" - ", p) : throw new Exception($"{map} {oa.Name}");
                        objacts[(map, part)] = oa;
Ejemplo n.º 16
0
 private void LoadText()
 {
     if (Sekiro)
     {
         ItemFMGs = Editor.LoadBnd($@"{dir}\Base\item.msgbnd.dcx", (data, path) => FMG.Read(data));
         ItemFMGs = MaybeOverrideFromModDir(ItemFMGs, @"msg\engus\item.msgbnd.dcx", path => Editor.LoadBnd(path, (data, path2) => FMG.Read(data)));
         MenuFMGs = Editor.LoadBnd($@"{dir}\Base\menu.msgbnd.dcx", (data, path) => FMG.Read(data));
         MenuFMGs = MaybeOverrideFromModDir(MenuFMGs, @"msg\engus\menu.msgbnd.dcx", path => Editor.LoadBnd(path, (data, path2) => FMG.Read(data)));
         foreach (string lang in MiscSetup.Langs)
         {
             if (lang == "engus")
             {
                 continue;
             }
             OtherItemFMGs[lang] = Editor.LoadBnd($@"{dir}\Base\msg\{lang}\item.msgbnd.dcx", (data, path) => FMG.Read(data));
             OtherItemFMGs[lang] = MaybeOverrideFromModDir(OtherItemFMGs[lang], $@"msg\{lang}\item.msgbnd.dcx", path => Editor.LoadBnd(path, (data, path2) => FMG.Read(data)));
         }
     }
     else
     {
         ItemFMGs = Editor.LoadBnd($@"{dir}\Base\item_dlc2.msgbnd.dcx", (data, path) => FMG.Read(data));
         ItemFMGs = MaybeOverrideFromModDir(ItemFMGs, @"msg\engus\item_dlc2.msgbnd.dcx", path => Editor.LoadBnd(path, (data, path2) => FMG.Read(data)));
     }
 }