public static Dictionary <char, char> GetDecodeCharMap(IGameInstance instance, Language language)
        {
            string filename = null;
            string packfile = null;

            if (instance.Game == GameSteamID.SaintsRow2)
            {
                filename = String.Format("charlist_{0}.txt", GetLanguageCode(language).ToLowerInvariant());
                packfile = "patch.vpp_pc";
            }
            else
            {
                filename = String.Format("charlist_{0}.dat", GetLanguageCode(language).ToLowerInvariant());
                packfile = "misc.vpp_pc";
            }

            using (Stream stream = instance.OpenLooseFile(filename))
            {
                if (stream != null)
                {
                    return(GetDecodeCharMapFromStream(stream));
                }
            }

            using (Stream stream = instance.OpenPackfileFile(filename, packfile))
            {
                if (stream != null)
                {
                    return(GetDecodeCharMapFromStream(stream));
                }
            }

            return(new Dictionary <char, char>());
        }
Example #2
0
        static IContainer FindContainer(IGameInstance sriv, string containerName)
        {
            string[] asmNames = new string[]
            {
                "customize_item.asm_pc",
                "dlc1_customize_item.asm_pc",
                "dlc2_customize_item.asm_pc",
                "dlc3_customize_item.asm_pc",
                "dlc4_customize_item.asm_pc",
                "dlc5_customize_item.asm_pc",
                "dlc6_customize_item.asm_pc"
            };

            string name = Path.GetFileNameWithoutExtension(containerName);

            foreach (string asmName in asmNames)
            {
                using (Stream s = sriv.OpenPackfileFile(asmName))
                {
                    IAssetAssemblerFile asm = AssetAssemblerFile.FromStream(s);

                    foreach (var container in asm.Containers)
                    {
                        if (container.Name == name)
                        {
                            return(container);
                        }
                    }
                }
            }

            return(null);
        }
 public Stream GetStream()
 {
     if (Packfile == null)
     {
         return(GameInstance.OpenLooseFile(Filename));
     }
     else
     {
         return(GameInstance.OpenPackfileFile(Filename, Packfile));
     }
 }
        public static Dictionary<char, char> GetDecodeCharMap(IGameInstance instance, Language language)
        {
            string filename = null;
            string packfile = null;
            if (instance.Game == GameSteamID.SaintsRow2)
            {
                filename = String.Format("charlist_{0}.txt", GetLanguageCode(language).ToLowerInvariant());
                packfile = "patch.vpp_pc";
            }
            else
            {
                filename = String.Format("charlist_{0}.dat", GetLanguageCode(language).ToLowerInvariant());
                packfile = "misc.vpp_pc";
            }

            using (Stream stream = instance.OpenPackfileFile(filename, packfile))
            {
                return GetDecodeCharMapInternal(stream, language);
            }
        }
Example #5
0
        static void LoadStrings(IGameInstance sriv)
        {
            var results = sriv.SearchForFiles("*.le_strings");

            foreach (var result in results)
            {
                string filename = result.Value.Filename.ToLowerInvariant();
                filename = Path.GetFileNameWithoutExtension(filename);

                string[] pieces       = filename.Split('_');
                string   languageCode = pieces.Last();

                Language language = LanguageUtility.GetLanguageFromCode(languageCode);

                if (!languageStrings.ContainsKey(language))
                {
                    languageStrings.Add(language, new Dictionary <uint, string>());
                }

                Dictionary <uint, string> strings = languageStrings[language];

                using (Stream s = sriv.OpenPackfileFile(result.Value.Filename, result.Value.Packfile))
                {
                    StringFile file = new StringFile(s, language, sriv);

                    foreach (var hash in file.GetHashes())
                    {
                        if (strings.ContainsKey(hash))
                        {
                            continue;
                        }

                        strings.Add(hash, file.GetString(hash));
                    }
                }
            }
        }
Example #6
0
        static XElement FindCustomizationItem(string name, IGameInstance sriv)
        {
            string[] xtblNames = new string[]
            {
                "customization_items.xtbl",
                "dlc1_customization_items.xtbl",
                "dlc2_customization_items.xtbl",
                "dlc3_customization_items.xtbl",
                "dlc4_customization_items.xtbl",
                "dlc5_customization_items.xtbl",
                "dlc6_customization_items.xtbl"
            };

            string targetName = name.ToLowerInvariant();

            foreach (string xtblName in xtblNames)
            {
                using (Stream s = sriv.OpenPackfileFile(xtblName))
                {
                    XDocument xml = XDocument.Load(s);

                    var table = xml.Descendants("Table");

                    foreach (var node in table.Descendants("Customization_Item"))
                    {
                        string itemName = node.Element("Name").Value.ToLowerInvariant();

                        if (itemName == targetName)
                        {
                            return(node);
                        }
                    }
                }
            }

            return(null);
        }
Example #7
0
        static bool ClonePackfile(IGameInstance sriv, string packfileName, string clothSimFilename, string outputFolder, IAssetAssemblerFile newAsm, string oldName, string newName, string newStr2Filename)
        {
            using (Stream oldStream = sriv.OpenPackfileFile(packfileName))
            {
                if (oldStream == null)
                {
                    return(false);
                }

                IContainer oldContainer = FindContainer(sriv, packfileName);
                if (oldContainer == null)
                {
                    return(false);
                }

                oldContainer.Name = Path.GetFileNameWithoutExtension(newStr2Filename);

                using (IPackfile oldPackfile = Packfile.FromStream(oldStream, true))
                {
                    using (IPackfile newPackfile = Packfile.FromVersion(0x0A, true))
                    {
                        newPackfile.IsCompressed = true;
                        newPackfile.IsCondensed  = true;

                        Stream pegStream = null;

                        var pegEntry = FindPackfileEntry(oldPackfile, ".cpeg_pc");
                        if (pegEntry != null)
                        {
                            pegStream = ProcessPeg(pegEntry, newName);
                        }


                        foreach (var file in oldPackfile.Files)
                        {
                            string     extension = Path.GetExtension(file.Name);
                            IPrimitive primitive = FindPrimitive(oldContainer, file.Name);

                            switch (extension)
                            {
                            case ".ccmesh_pc":
                            {
                                Stream newCcmeshStream = ProcessCCMesh(file, oldName, newName);
                                string newMeshName     = newName + extension;
                                newPackfile.AddFile(newCcmeshStream, newMeshName);
                                primitive.Name = newMeshName;
                                break;
                            }

                            case ".cpeg_pc":
                            {
                                string newPegName = newName + extension;

                                newPackfile.AddFile(pegStream, newPegName);
                                primitive.Name = newPegName;
                                break;
                            }

                            case ".cmorph_pc":
                            {
                                string morphSuffix = Path.GetFileNameWithoutExtension(file.Name).Split('_').Last();

                                string newFilename = newName + "_" + morphSuffix + extension;

                                Stream fStream = file.GetStream();
                                // copy the morph to the output folder (fixes some odd issues with the morph not applying when loaded from save)
                                using (Stream s = File.Create(Path.Combine(outputFolder, newFilename)))
                                {
                                    fStream.CopyTo(s);
                                }

                                fStream.Seek(0, SeekOrigin.Begin);

                                newPackfile.AddFile(fStream, newFilename);
                                primitive.Name = newFilename;
                                break;
                            }

                            case ".sim_pc":
                            {
                                string newFilename = newName + extension;
                                Stream newStream   = ProcessClothSim(file, newName);
                                newPackfile.AddFile(newStream, newFilename);
                                primitive.Name = newFilename;
                                break;
                            }

                            case ".gcmesh_pc":
                            case ".gpeg_pc":
                            case ".rig_pc":
                            {
                                string newFilename = newName + extension;
                                newPackfile.AddFile(file.GetStream(), newFilename);
                                if (primitive != null)
                                {
                                    primitive.Name = newFilename;
                                }
                                break;
                            }

                            default:
                                throw new Exception(String.Format("Unrecognised extension: {0}", extension));
                            }
                        }

                        newAsm.Containers.Add(oldContainer);

                        using (Stream s = File.Create(newStr2Filename))
                        {
                            newPackfile.Save(s);
                        }

                        newPackfile.Update(oldContainer);
                    }
                }
            }

            return(true);
        }