Esempio n. 1
0
        public static void Repack(string sourceFile)
        {
            var gparam = new GPARAM();
            var xml    = new XmlDocument();

            xml.Load(sourceFile);
            Enum.TryParse(xml.SelectSingleNode("gparam/compression")?.InnerText ?? "None", out gparam.Compression);
            Enum.TryParse(xml.SelectSingleNode("gparam/game").InnerText, out gparam.Game);
            gparam.Unk0D = bool.Parse(xml.SelectSingleNode("gparam/unk0D").InnerText);
            gparam.Unk14 = int.Parse(xml.SelectSingleNode("gparam/unk14").InnerText);
            if (gparam.Game == GPARAM.GPGame.Sekiro)
            {
                gparam.Unk50 = float.Parse(xml.SelectSingleNode("gparam/unk50").InnerText);
            }

            foreach (XmlNode groupNode in xml.SelectNodes("gparam/groups/group"))
            {
                string       groupName1 = groupNode.Attributes["name1"].InnerText;
                GPARAM.Group group;
                if (gparam.Game == GPARAM.GPGame.DarkSouls2)
                {
                    group = new GPARAM.Group(groupName1, null);
                }
                else
                {
                    string groupName2 = groupNode.Attributes["name2"].InnerText;
                    group = new GPARAM.Group(groupName1, groupName2);
                    foreach (XmlNode commentNode in groupNode.SelectNodes("comments/comment"))
                    {
                        group.Comments.Add(commentNode.InnerText);
                    }
                }

                foreach (XmlNode paramNode in groupNode.SelectNodes("param"))
                {
                    string       paramName1 = paramNode.Attributes["name1"].InnerText;
                    var          paramType  = (GPARAM.ParamType)Enum.Parse(typeof(GPARAM.ParamType), paramNode.Attributes["type"].InnerText);
                    GPARAM.Param param;

                    if (gparam.Game == GPARAM.GPGame.DarkSouls2)
                    {
                        param = new GPARAM.Param(paramName1, null, paramType);
                    }
                    else
                    {
                        string paramName2 = paramNode.Attributes["name2"].InnerText;
                        param = new GPARAM.Param(paramName1, paramName2, paramType);
                        if (gparam.Game == GPARAM.GPGame.Sekiro)
                        {
                            param.UnkFloats = new List <float>();
                        }
                    }

                    foreach (XmlNode value in paramNode.SelectNodes("value"))
                    {
                        param.ValueIDs.Add(int.Parse(value.Attributes["id"].InnerText));
                        if (gparam.Game == GPARAM.GPGame.Sekiro)
                        {
                            param.UnkFloats.Add(float.Parse(value.Attributes["float"].InnerText));
                        }

                        switch (param.Type)
                        {
                        case GPARAM.ParamType.BoolA:
                            param.Values.Add(bool.Parse(value.InnerText));
                            break;

                        case GPARAM.ParamType.BoolB:
                            param.Values.Add(bool.Parse(value.InnerText));
                            break;

                        case GPARAM.ParamType.Byte:
                            param.Values.Add(byte.Parse(value.InnerText));
                            break;

                        case GPARAM.ParamType.Byte4:
                            byte[] bytes = value.InnerText.Split(' ').Select(b => byte.Parse(b, NumberStyles.AllowHexSpecifier)).ToArray();
                            param.Values.Add(bytes);
                            break;

                        case GPARAM.ParamType.Float:
                            param.Values.Add(float.Parse(value.InnerText));
                            break;

                        case GPARAM.ParamType.Float2:
                            float[] vec2 = value.InnerText.Split(' ').Select(f => float.Parse(f)).ToArray();
                            param.Values.Add(new Vector2(vec2[0], vec2[1]));
                            break;

                        case GPARAM.ParamType.Float3:
                            float[] vec3 = value.InnerText.Split(' ').Select(f => float.Parse(f)).ToArray();
                            param.Values.Add(new Vector3(vec3[0], vec3[1], vec3[1]));
                            break;

                        case GPARAM.ParamType.Float4:
                            float[] vec4 = value.InnerText.Split(' ').Select(f => float.Parse(f)).ToArray();
                            param.Values.Add(new Vector4(vec4[0], vec4[1], vec4[2], vec4[3]));
                            break;

                        case GPARAM.ParamType.IntA:
                            param.Values.Add(int.Parse(value.InnerText));
                            break;

                        case GPARAM.ParamType.IntB:
                            param.Values.Add(int.Parse(value.InnerText));
                            break;

                        case GPARAM.ParamType.Short:
                            param.Values.Add(short.Parse(value.InnerText));
                            break;
                        }
                    }
                    group.Params.Add(param);
                }
                gparam.Groups.Add(group);
            }

            foreach (XmlNode unk3Node in xml.SelectNodes("gparam/unk3s/unk3"))
            {
                int groupIndex = int.Parse(unk3Node.Attributes["group_index"].InnerText);
                var unk3       = new GPARAM.Unk3(groupIndex);
                if (gparam.Game == GPARAM.GPGame.Sekiro)
                {
                    unk3.Unk0C = int.Parse(unk3Node.Attributes["unk0C"].InnerText);
                }
                foreach (XmlNode value in unk3Node.SelectNodes("value_id"))
                {
                    unk3.ValueIDs.Add(int.Parse(value.InnerText));
                }
                gparam.Unk3s.Add(unk3);
            }

            gparam.UnkBlock2 = xml.SelectSingleNode("gparam/unk_block_2").InnerText
                               .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                               .Select(s => Convert.ToByte(s, 16)).ToArray();

            string outPath;

            if (sourceFile.EndsWith(".gparam.xml"))
            {
                outPath = sourceFile.Replace(".gparam.xml", ".gparam");
            }
            else if (sourceFile.EndsWith(".gparam.dcx.xml"))
            {
                outPath = sourceFile.Replace(".gparam.dcx.xml", ".gparam.dcx");
            }
            else if (sourceFile.EndsWith(".fltparam.xml"))
            {
                outPath = sourceFile.Replace(".fltparam.xml", ".fltparam");
            }
            else if (sourceFile.EndsWith(".fltparam.dcx.xml"))
            {
                outPath = sourceFile.Replace(".fltparam.dcx.xml", ".fltparam.dcx");
            }
            else
            {
                throw new InvalidOperationException("Invalid GPARAM xml filename.");
            }
            YBUtil.Backup(outPath);
            gparam.Write(outPath);
        }
Esempio n. 2
0
        public static void Repack(string sourceFile)
        {
            GPARAM      gparam = new GPARAM();
            XmlDocument xml    = new XmlDocument();

            xml.Load(sourceFile);
            gparam.Unk1 = int.Parse(xml.SelectSingleNode("gparam/unk1").InnerText);
            foreach (XmlNode group in xml.SelectNodes("gparam/groups/group"))
            {
                var g = new GPARAM.Group();
                g.Name1 = group.Attributes.GetNamedItem("name1").InnerText;
                g.Name2 = group.Attributes.GetNamedItem("name2").InnerText;
                bool addedComments = false;
                foreach (XmlNode param in group.SelectNodes("param"))
                {
                    var p = new GPARAM.Param();
                    p.Name1 = param.Attributes.GetNamedItem("name1").InnerText;
                    p.Name2 = param.Attributes.GetNamedItem("name2").InnerText;
                    p.Type  = (GPARAM.ParamType)Enum.Parse(typeof(GPARAM.ParamType), param.Attributes.GetNamedItem("type").InnerText);
                    foreach (XmlNode value in param.SelectNodes("value"))
                    {
                        p.Unk1Values.Add(int.Parse(value.Attributes.GetNamedItem("id").InnerText));
                        if (!addedComments)
                        {
                            g.Comments.Add(value.Attributes.GetNamedItem("comment").InnerText);
                        }
                        switch (p.Type)
                        {
                        case GPARAM.ParamType.BoolA:
                            p.Values.Add(bool.Parse(value.InnerText));
                            break;

                        case GPARAM.ParamType.BoolB:
                            p.Values.Add(bool.Parse(value.InnerText));
                            break;

                        case GPARAM.ParamType.Byte:
                            p.Values.Add(byte.Parse(value.InnerText));
                            break;

                        case GPARAM.ParamType.Byte4:
                            var str = value.InnerText;
                            p.Values.Add(str.Split(' ').Select(x => byte.Parse(x)).ToArray());
                            break;

                        case GPARAM.ParamType.Float:
                            p.Values.Add(float.Parse(value.InnerText));
                            break;

                        case GPARAM.ParamType.Float2:
                            var arr = value.InnerText.Split(' ').Select(x => float.Parse(x)).ToArray();
                            p.Values.Add(new Vector2(arr[0], arr[1]));
                            break;

                        case GPARAM.ParamType.Float4:
                            var arr2 = value.InnerText.Split(' ').Select(x => float.Parse(x)).ToArray();
                            p.Values.Add(new Vector4(arr2[0], arr2[1], arr2[2], arr2[3]));
                            break;

                        case GPARAM.ParamType.IntA:
                            p.Values.Add(int.Parse(value.InnerText));
                            break;

                        case GPARAM.ParamType.IntB:
                            p.Values.Add(int.Parse(value.InnerText));
                            break;

                        case GPARAM.ParamType.Short:
                            p.Values.Add(short.Parse(value.InnerText));
                            break;
                        }
                    }
                    addedComments = true;
                    g.Params.Add(p);
                }
                gparam.Groups.Add(g);
            }

            foreach (XmlNode unk in xml.SelectNodes("gparam/unk3s/unk3"))
            {
                var u = new GPARAM.Unk3();
                u.ID = int.Parse(unk.Attributes.GetNamedItem("id").InnerText);
                foreach (XmlNode value in unk.SelectNodes("value"))
                {
                    u.Values.Add(int.Parse(value.InnerText));
                }
                gparam.Unk3s.Add(u);
            }

            gparam.UnkBlock2 = Convert.FromBase64String(xml.SelectSingleNode("gparam/unkBlock").InnerText);

            if (sourceFile.EndsWith(".gparam.xml"))
            {
                string outPath = sourceFile.Replace(".gparam.xml", ".gparam");
                if (File.Exists(outPath) && !File.Exists(outPath + ".bak"))
                {
                    File.Copy(outPath, outPath + ".bak");
                }
                gparam.Write(outPath);
            }
            else
            {
                string outPath = sourceFile.Replace(".gparam.dcx.xml", ".gparam.dcx");
                if (File.Exists(outPath) && !File.Exists(outPath + ".bak"))
                {
                    File.Copy(outPath, outPath + ".bak");
                }
                gparam.Write(outPath, DCX.Type.DarkSouls3);
            }
        }