public void Install() { Console.WriteLine("Final installation..."); #if DEBUG //Console.Write($"Exporting GameParam..."); #endif GPARAM.Export(GameDir); #if DEBUG //Console.Write($"Done.\n"); //Console.Write($"Exporting Text..."); #endif Text.Export(GameDir); #if DEBUG //Console.Write($"Done.\n"); #endif foreach (KeyValuePair <int, ChrHandler> kv in Characters) { string chrFile = $"c{kv.Key:0000}"; //Console.Write($"Exporting {chrFile}..."); try { kv.Value.Export(); //Console.Write("Done.\n"); } catch (Exception e) { Console.Write("FAILED.\n"); Console.WriteLine(Environment.NewLine + e.ToString()); Console.WriteLine(Environment.NewLine + $"Modification of {chrFile} failed."); Console.WriteLine("Continue anyway? [Y/N]"); ConsoleKey key = Console.ReadKey(true).Key; while (key != ConsoleKey.Y && key != ConsoleKey.N) { key = Console.ReadKey(true).Key; } if (key == ConsoleKey.N) { Environment.Exit(0); } else { Console.WriteLine(Environment.NewLine); } } } Console.WriteLine("\nInstallation successful! Press ENTER to exit."); Console.ReadLine(); }
public void Install() { #if DEBUG Console.WriteLine("Final installation..."); Console.Write($"Exporting GameParam..."); #endif GPARAM.Export(GameDir); #if DEBUG Console.Write($"Done.\n"); Console.Write($"Exporting Text..."); #endif Text.Export(GameDir); #if DEBUG Console.Write($"Done.\n"); #endif InstallAnimations(); }
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); }
public static void Unpack(this GPARAM gparam, string sourceFile) { var xws = new XmlWriterSettings(); xws.Indent = true; XmlWriter xw = XmlWriter.Create($"{sourceFile}.xml", xws); xw.WriteStartElement("gparam"); xw.WriteElementString("compression", gparam.Compression.ToString()); xw.WriteElementString("game", gparam.Game.ToString()); xw.WriteElementString("unk0D", gparam.Unk0D.ToString()); xw.WriteElementString("unk14", gparam.Unk14.ToString()); if (gparam.Game == GPARAM.GPGame.Sekiro) { xw.WriteElementString("unk50", gparam.Unk50.ToString()); } xw.WriteStartElement("groups"); foreach (GPARAM.Group group in gparam.Groups) { xw.WriteStartElement("group"); xw.WriteAttributeString("name1", group.Name1); if (gparam.Game == GPARAM.GPGame.DarkSouls3 || gparam.Game == GPARAM.GPGame.Sekiro) { xw.WriteAttributeString("name2", group.Name2); xw.WriteStartElement("comments"); foreach (string comment in group.Comments) { xw.WriteElementString("comment", comment); } xw.WriteEndElement(); } foreach (GPARAM.Param param in group.Params) { xw.WriteStartElement("param"); xw.WriteAttributeString("name1", param.Name1); if (gparam.Game == GPARAM.GPGame.DarkSouls3 || gparam.Game == GPARAM.GPGame.Sekiro) { xw.WriteAttributeString("name2", param.Name2); } xw.WriteAttributeString("type", param.Type.ToString()); for (var i = 0; i < param.Values.Count; i++) { xw.WriteStartElement("value"); xw.WriteAttributeString("id", param.ValueIDs[i].ToString()); if (gparam.Game == GPARAM.GPGame.Sekiro) { xw.WriteAttributeString("float", param.UnkFloats[i].ToString()); } if (param.Type == GPARAM.ParamType.Float2) { var value = (Vector2)param.Values[i]; xw.WriteString($"{value.X} {value.Y}"); } else if (param.Type == GPARAM.ParamType.Float3) { var value = (Vector3)param.Values[i]; xw.WriteString($"{value.X} {value.Y} {value.Z}"); } else if (param.Type == GPARAM.ParamType.Float4) { var value = (Vector4)param.Values[i]; xw.WriteString($"{value.X} {value.Y} {value.Z} {value.W}"); } else if (param.Type == GPARAM.ParamType.Byte4) { var value = (byte[])param.Values[i]; xw.WriteString($"{value[0]:X2} {value[1]:X2} {value[2]:X2} {value[3]:X2}"); } else { xw.WriteString(param.Values[i].ToString()); } xw.WriteEndElement(); } xw.WriteEndElement(); } xw.WriteEndElement(); } xw.WriteEndElement(); xw.WriteStartElement("unk3s"); foreach (var unk3 in gparam.Unk3s) { xw.WriteStartElement("unk3"); xw.WriteAttributeString("group_index", unk3.GroupIndex.ToString()); if (gparam.Game == GPARAM.GPGame.Sekiro) { xw.WriteAttributeString("unk0C", unk3.Unk0C.ToString()); } foreach (var id in unk3.ValueIDs) { xw.WriteElementString("value_id", id.ToString()); } xw.WriteEndElement(); } xw.WriteEndElement(); xw.WriteElementString("unk_block_2", string.Join(" ", gparam.UnkBlock2.Select(b => b.ToString("X2")))); xw.WriteEndElement(); xw.Close(); }
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); } }
public static void Unpack(this GPARAM gparam, string sourceFile) { XmlWriterSettings xws = new XmlWriterSettings(); xws.Indent = true; XmlWriter xw = XmlWriter.Create($"{sourceFile}.xml", xws); xw.WriteStartElement("gparam"); xw.WriteElementString("unk1", gparam.Unk1.ToString()); xw.WriteStartElement("groups"); foreach (GPARAM.Group group in gparam.Groups) { xw.WriteStartElement("group"); xw.WriteAttributeString("name1", group.Name1); xw.WriteAttributeString("name2", group.Name2); foreach (GPARAM.Param param in group.Params) { xw.WriteStartElement("param"); xw.WriteAttributeString("name1", param.Name1); xw.WriteAttributeString("name2", param.Name2); xw.WriteAttributeString("type", param.Type.ToString()); for (var i = 0; i < param.Values.Count; i++) { xw.WriteStartElement("value"); xw.WriteAttributeString("id", param.Unk1Values[i].ToString()); if (i < group.Comments.Count) { xw.WriteAttributeString("comment", group.Comments[i]); } if (param.Type == GPARAM.ParamType.Float2) { var value = (Vector2)param.Values[i]; xw.WriteString($"{value.X} {value.Y}"); } else if (param.Type == GPARAM.ParamType.Float4) { var value = (Vector4)param.Values[i]; xw.WriteString($"{value.X} {value.Y} {value.Z} {value.W}"); } else if (param.Type == GPARAM.ParamType.Byte4) { var value = (byte[])param.Values[i]; xw.WriteString($"{value[0]:X2} {value[1]:X2} {value[2]:X2} {value[3]:X2}"); } else { xw.WriteString(param.Values[i].ToString()); } xw.WriteEndElement(); } xw.WriteEndElement(); } xw.WriteEndElement(); } xw.WriteEndElement(); xw.WriteStartElement("unk3s"); foreach (var unk in gparam.Unk3s) { xw.WriteStartElement("unk3"); xw.WriteAttributeString("id", unk.ID.ToString()); foreach (var val in unk.Values) { xw.WriteElementString("value", val.ToString()); } xw.WriteEndElement(); } xw.WriteEndElement(); xw.WriteElementString("unkBlock", Convert.ToBase64String(gparam.UnkBlock2)); xw.WriteEndElement(); xw.Close(); }
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); }