Exemplo n.º 1
0
        public static void LoadParams(SQLiteConnection con, string paramdefFilepath, IList <string> paramDirs)
        {
            // The metadata tables should be created ahead of time.
            CreateBndMetadataTables(con);
            CreateBndTableOfContentsTable(con);
            CreateParamMetadataTables(con);

            // Reading an original paramdefbnd
            var paramdefs   = new Dictionary <string, PARAMDEF>();
            var paramdefbnd = BND3.Read(paramdefFilepath);

            foreach (BinderFile file in paramdefbnd.Files)
            {
                var paramdef = PARAMDEF.Read(file.Bytes);
                paramdefs[paramdef.ParamType] = paramdef;
            }
            ReadParamdefsIntoDatabase(con, paramdefs.Values.ToList());

            // Loading parambnd
            List <string> paramFilepaths = new List <string>();

            foreach (var paramDir in paramDirs)
            {
                // DeS has both a gameparam.parambnd.dcx and a gameparamna.parambnd.dcx.
                // Only grab gameparamna.parambnd.dcx if we have it.
                string filterPattern = "*.parambnd.dcx";
                if (Directory.GetFiles(paramDir, "*gameparamna.parambnd.dcx").Length > 0)
                {
                    Console.WriteLine("Skipping gameparam.parambnd.dcx");
                    filterPattern = "*gameparamna.parambnd.dcx";
                }

                paramFilepaths.AddRange(Directory.GetFiles(paramDir, filterPattern));
            }

            foreach (var paramFilepath in paramFilepaths)
            {
                // Have to construct Table of Contents as we go through, since the info isn't all at BND level, but is needed when reconstructing
                var bndContents = new List <BndContentsEntry>();
                Console.WriteLine("Loading file: " + paramFilepath);
                var parambnd = BND3.Read(paramFilepath);
                foreach (BinderFile file in parambnd.Files)
                {
                    PARAM param = PARAM.Read(file.Bytes);
                    // DSR doesn't seem to like applying carefully, specifically SP_EFFECT_PARAM_ST in Gameparam. At minimum.
                    param.ApplyParamdef(paramdefs[param.ParamType]);

                    var entry = new BndContentsEntry(paramFilepath, file.ID, file.Name, file.Flags, file.CompressionType, param.ParamType);
                    bndContents.Add(entry);
                    ReadParamIntoDatabase(con, Path.GetFileNameWithoutExtension(file.Name), param);
                }

                // Create the metadata tables
                ReadBndMetadataIntoDatabase(con, paramFilepath, parambnd);
                ReadBndTableOfContentsIntoDatabase(con, Path.GetFileName(paramFilepath), bndContents);
            }
        }
Exemplo n.º 2
0
        static void translateParamDefs(string a)
        {
            string paramDefDir = a.EndsWith("\\") ? a.Substring(a.Length - 1, 1) : a;

            string[]        paramDefFileList     = Directory.GetFiles(paramDefDir);
            List <string>   paramDefFileNameList = new List <string>();
            List <PARAMDEF> paramDefs            = new List <PARAMDEF>();

            Console.WriteLine("### " + paramDefDir);

            for (int i = 0; i < paramDefFileList.Length; i++)
            {
                string fn = paramDefFileList[i].Substring(paramDefDir.Length + 1, paramDefFileList[i].Length - (paramDefDir.Length + 1));
                paramDefFileNameList.Add(fn);
                paramDefs.Add(PARAMDEF.Read(File.ReadAllBytes(paramDefFileList[i])));
            }

            TranslationClient client = TranslationClient.Create(GoogleCredential.FromFile("C:\\Users\\dmtin\\google-translate-api-key.txt"));

            for (int i = 0; i < paramDefs.Count; i++)
            {
                PARAMDEF pd = paramDefs[i];
                Console.WriteLine("\n\n\n\n==================" + pd.ParamType + "==================");

                for (int j = 0; j < pd.Fields.Count; j++)
                {
                    PARAMDEF.Field field = pd.Fields[j];
                    try
                    {
                        TranslationResult responseA = client.TranslateText(field.DisplayName, LanguageCodes.English, LanguageCodes.Japanese); // Translate request
                        if (responseA != null && responseA.TranslatedText != null && responseA.TranslatedText.Trim().Length > 0)
                        {
                            field.DisplayName = responseA.TranslatedText;
                        }

                        TranslationResult responseB = client.TranslateText(field.Description, LanguageCodes.English, LanguageCodes.Japanese); // Translate request
                        if (responseB != null && responseB.TranslatedText != null && responseB.TranslatedText.Trim().Length > 0)
                        {
                            field.Description = responseB.TranslatedText;
                        }
                    }
                    catch (Exception ex) { Console.WriteLine("EXCEPTION :: " + ex.Message); }
                    Console.WriteLine(field.DisplayName + ":: " + field.Description);
                }
            }

            Directory.CreateDirectory(paramDefDir + "\\translated\\");
            for (int i = 0; i < paramDefs.Count; i++)
            {
                string outPath = paramDefDir + "\\translated\\" + paramDefFileNameList[i];
                byte[] outData = paramDefs[i].Write();
                File.WriteAllBytes(outPath, outData);
            }
        }
Exemplo n.º 3
0
        private void UnpackGameBNDFile()
        {
            // Reading an original paramdefbnd
            paramDefs   = new Dictionary <string, PARAMDEF>();
            paramDefBnd = BND3.Read(pathToParamDef);

            foreach (BinderFile file in paramDefBnd.Files)
            {
                var paramdef = PARAMDEF.Read(file.Bytes);
                paramDefs[paramdef.ParamType] = paramdef;
            }

            parms    = new Dictionary <string, PARAM>();
            paramBnd = BND3.Read(pathToParamDataFile);

            foreach (BinderFile file in paramBnd.Files)
            {
                string name  = Path.GetFileNameWithoutExtension(file.Name);
                var    param = PARAM.Read(file.Bytes);
                param.ApplyParamdef(paramDefs[param.ParamType]);
                parms[name] = param;
            }
        }
Exemplo n.º 4
0
        public SoulsMod(string gameDir, string backupExt = ".smbak",
                        byte[] paramBNDData   = null, byte[] paramdefBNDData = null,
                        byte[] itemMSGBNDData = null, byte[] menuMSGBNDData  = null)
        {
            if (!gameDir.EndsWith(@"\"))
            {
                gameDir += @"\";
            }
            GameDir   = gameDir;
            BackupExt = backupExt;
            // RestoreBackups();  // No need to restore backups automatically, as all files are loaded directly FROM the backups anyway.

            // Text is loaded first so it can be passed to `GameParamHandler`.
#if DEBUG
            Console.Write("Loading Text... ");
#endif
            if (itemMSGBNDData == null)
            {
                itemMSGBNDData = File.ReadAllBytes(GameDir + @"msg/ENGLISH/item.msgbnd.dcx");
            }
            if (menuMSGBNDData == null)
            {
                menuMSGBNDData = File.ReadAllBytes(GameDir + @"msg/ENGLISH/menu.msgbnd.dcx");
            }
            Text = new TextHandler(itemMSGBNDData, menuMSGBNDData);
#if DEBUG
            Console.Write("Done.\n");
            Console.Write("Loading Text (vanilla copy)... ");
#endif
            VanillaText = new TextHandler(itemMSGBNDData, menuMSGBNDData);
#if DEBUG
            Console.Write("Done.\n");
            Console.Write("Loading ParamDefs... ");
#endif
            if (paramdefBNDData == null)
            {
                paramdefBNDData = File.ReadAllBytes(GameDir + @"paramdef\paramdef.paramdefbnd.dcx");
            }
            BND3 paramdefBnd = BND3.Read(paramdefBNDData);
            foreach (BinderFile file in paramdefBnd.Files)
            {
                PARAMDEF paramdef = PARAMDEF.Read(file.Bytes);
                ParamDefs[paramdef.ParamType] = paramdef;
            }
#if DEBUG
            Console.Write("Done.\n");
            Console.Write("Loading GameParams... ");
#endif
            if (paramBNDData == null)
            {
                paramBNDData = File.ReadAllBytes(GameDir + @"param\GameParam\GameParam.parambnd.dcx");
            }
            GPARAM = new GameParamHandler(ParamDefs, Text, paramBNDData);
#if DEBUG
            Console.Write("Done.\n");
            Console.Write("Loading GameParams (vanilla copy)... ");
#endif
            if (paramBNDData != null)
            {
                VanillaGPARAM = new GameParamHandler(ParamDefs, VanillaText, paramBNDData);
            }
            else
            {
                VanillaGPARAM = new GameParamHandler(ParamDefs, VanillaText, GameDir + @"param\GameParam\GameParam.parambnd.dcx");
            }
#if DEBUG
            Console.Write("Done.\n");
#endif
        }
Exemplo n.º 5
0
        static void translateParams(string a, string b)
        {
            string paramDir    = a.EndsWith("\\") ? a.Substring(a.Length - 1, 1) : a;
            string paramDefDir = b.EndsWith("\\") ? b.Substring(b.Length - 1, 1) : b;

            string[]        paramFileList     = Directory.GetFiles(paramDir);
            string[]        paramDefFileList  = Directory.GetFiles(paramDefDir);
            List <string>   paramFileNameList = new List <string>();
            List <PARAMDEF> paramDefs         = new List <PARAMDEF>();
            List <PARAM>    paramaroos        = new List <PARAM>();

            Console.WriteLine("### " + paramDir);
            Console.WriteLine("### " + paramDefDir + "\n");

            for (int i = 0; i < paramFileList.Length; i++)
            {
                string fn = paramFileList[i].Substring(paramDir.Length + 1, paramFileList[i].Length - (paramDir.Length + 1));
                paramFileNameList.Add(fn);
                paramaroos.Add(PARAM.Read(File.ReadAllBytes(paramFileList[i])));
            }

            for (int i = 0; i < paramDefFileList.Length; i++)
            {
                paramDefs.Add(PARAMDEF.Read(File.ReadAllBytes(paramDefFileList[i])));
            }

            for (int i = 0; i < paramaroos.Count; i++)
            {
                PARAM p = paramaroos[i];
                for (int j = 0; j < paramDefs.Count; j++)
                {
                    PARAMDEF pd = paramDefs[j];

                    if (p.ParamType.Equals(pd.ParamType))
                    {
                        p.ApplyParamdef(pd);
                    }
                }
            }

            TranslationClient client = TranslationClient.Create(GoogleCredential.FromFile("C:\\Users\\dmtin\\google-translate-api-key.txt"));

            for (int i = 0; i < paramaroos.Count; i++)
            {
                Console.WriteLine("\n\n\n\n==================" + paramaroos[i].ParamType + "==================");
                for (int j = 0; j < paramaroos[i].Rows.Count; j++)
                {
                    PARAM.Row row = paramaroos[i].Rows[j];
                    try
                    {
                        if (row.Name != null && !row.Name.Trim().Equals("") && !row.Name.Trim().Equals("0"))
                        {
                            TranslationResult response = client.TranslateText(row.Name, LanguageCodes.English, LanguageCodes.Japanese); // Translate request
                            if (response != null && response.TranslatedText != null && response.TranslatedText.Trim().Length > 0)
                            {
                                row.Name = response.TranslatedText;
                            }
                        }
                    }
                    catch (Exception ex) { Console.WriteLine("EXCEPTION :: " + ex.Message); }
                    Console.WriteLine(row.ID + ":: " + row.Name);
                }
            }

            Directory.CreateDirectory(paramDir + "\\translated\\");
            for (int i = 0; i < paramaroos.Count; i++)
            {
                string outPath = paramDir + "\\translated\\" + paramFileNameList[i];
                byte[] outData = paramaroos[i].Write();
                File.WriteAllBytes(outPath, outData);
            }

            Console.WriteLine("\n\n Done!");
        }