mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-11-26 00:43:00 +08:00
YLD/XML conversion
This commit is contained in:
parent
7bc7d9612a
commit
bd18610dca
@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace CodeWalker.GameFiles
|
||||
{
|
||||
@ -69,5 +71,74 @@ namespace CodeWalker.GameFiles
|
||||
|
||||
Loaded = true;
|
||||
}
|
||||
|
||||
public byte[] Save()
|
||||
{
|
||||
byte[] data = ResourceBuilder.Build(ClothDictionary, 8); //yld is type/version 8...
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class YldXml : MetaXmlBase
|
||||
{
|
||||
|
||||
public static string GetXml(YldFile yld, string outputFolder = "")
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.AppendLine(XmlHeader);
|
||||
|
||||
var ddsfolder = outputFolder;
|
||||
if (!string.IsNullOrEmpty(ddsfolder))
|
||||
{
|
||||
ddsfolder = Path.Combine(outputFolder, yld.Name);
|
||||
|
||||
if (!Directory.Exists(ddsfolder))
|
||||
{
|
||||
Directory.CreateDirectory(ddsfolder);
|
||||
}
|
||||
}
|
||||
|
||||
if (yld?.ClothDictionary != null)
|
||||
{
|
||||
ClothDictionary.WriteXmlNode(yld.ClothDictionary, sb, 0);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class XmlYld
|
||||
{
|
||||
|
||||
public static YldFile GetYld(string xml, string inputFolder = "")
|
||||
{
|
||||
XmlDocument doc = new XmlDocument();
|
||||
doc.LoadXml(xml);
|
||||
return GetYld(doc, inputFolder);
|
||||
}
|
||||
|
||||
public static YldFile GetYld(XmlDocument doc, string inputFolder = "")
|
||||
{
|
||||
YldFile r = new YldFile();
|
||||
|
||||
var ddsfolder = inputFolder;
|
||||
|
||||
var node = doc.DocumentElement;
|
||||
if (node != null)
|
||||
{
|
||||
r.ClothDictionary = ClothDictionary.ReadXmlNode(node);
|
||||
}
|
||||
|
||||
r.Name = Path.GetFileName(inputFolder);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -91,6 +91,11 @@ namespace CodeWalker.GameFiles
|
||||
YptFile ypt = RpfFile.GetFile<YptFile>(e, data);
|
||||
return GetXml(ypt, out filename, outputfolder);
|
||||
}
|
||||
else if (fnl.EndsWith(".yld"))
|
||||
{
|
||||
YldFile yld = RpfFile.GetFile<YldFile>(e, data);
|
||||
return GetXml(yld, out filename, outputfolder);
|
||||
}
|
||||
filename = fn;
|
||||
return string.Empty;
|
||||
}
|
||||
@ -198,6 +203,12 @@ namespace CodeWalker.GameFiles
|
||||
filename = fn + ".xml";
|
||||
return YptXml.GetXml(ypt, outputfolder);
|
||||
}
|
||||
public static string GetXml(YldFile yld, out string filename, string outputfolder)
|
||||
{
|
||||
var fn = (yld?.Name) ?? "";
|
||||
filename = fn + ".xml";
|
||||
return YldXml.GetXml(yld, outputfolder);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -2104,6 +2115,7 @@ namespace CodeWalker.GameFiles
|
||||
Ydd = 11,
|
||||
Yft = 12,
|
||||
Ypt = 13,
|
||||
Yld = 14,
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16217,6 +16217,42 @@ namespace CodeWalker.GameFiles
|
||||
b20, b21, b22, b23, b24, b25, b26, b27, b28, b29,
|
||||
b30, b31;
|
||||
|
||||
public PsoChar32(string s)
|
||||
{
|
||||
s = s.PadRight(32, '\0');
|
||||
b00 = (byte)s[0];
|
||||
b01 = (byte)s[1];
|
||||
b02 = (byte)s[2];
|
||||
b03 = (byte)s[3];
|
||||
b04 = (byte)s[4];
|
||||
b05 = (byte)s[5];
|
||||
b06 = (byte)s[6];
|
||||
b07 = (byte)s[7];
|
||||
b08 = (byte)s[8];
|
||||
b09 = (byte)s[9];
|
||||
b10 = (byte)s[10];
|
||||
b11 = (byte)s[11];
|
||||
b12 = (byte)s[12];
|
||||
b13 = (byte)s[13];
|
||||
b14 = (byte)s[14];
|
||||
b15 = (byte)s[15];
|
||||
b16 = (byte)s[16];
|
||||
b17 = (byte)s[17];
|
||||
b18 = (byte)s[18];
|
||||
b19 = (byte)s[19];
|
||||
b20 = (byte)s[20];
|
||||
b21 = (byte)s[21];
|
||||
b22 = (byte)s[22];
|
||||
b23 = (byte)s[23];
|
||||
b24 = (byte)s[24];
|
||||
b25 = (byte)s[25];
|
||||
b26 = (byte)s[26];
|
||||
b27 = (byte)s[27];
|
||||
b28 = (byte)s[28];
|
||||
b29 = (byte)s[29];
|
||||
b30 = (byte)s[30];
|
||||
b31 = (byte)s[31];
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
byte[] bytes = new byte[]
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -428,7 +428,23 @@ namespace CodeWalker.GameFiles
|
||||
}
|
||||
if ((Cloths?.data_items?.Length ?? 0) > 0)
|
||||
{
|
||||
YftXml.WriteItemArray(sb, Cloths.data_items, indent, "Cloths");
|
||||
YftXml.OpenTag(sb, indent, "Cloths");
|
||||
var cind = indent + 1;
|
||||
var cind2 = indent + 2;
|
||||
for (int i = 0; i < Cloths.data_items.Length; i++)
|
||||
{
|
||||
if (Cloths.data_items[i] != null)
|
||||
{
|
||||
YftXml.OpenTag(sb, cind, "Item");
|
||||
Cloths.data_items[i].WriteXml(sb, cind2, ddsfolder);
|
||||
YftXml.CloseTag(sb, cind, "Item");
|
||||
}
|
||||
else
|
||||
{
|
||||
YftXml.SelfClosingTag(sb, cind, "Item");
|
||||
}
|
||||
}
|
||||
YftXml.CloseTag(sb, indent, "Cloths");
|
||||
}
|
||||
}
|
||||
public void ReadXml(XmlNode node, string ddsfolder)
|
||||
@ -498,7 +514,22 @@ namespace CodeWalker.GameFiles
|
||||
LightAttributes = new ResourceSimpleList64_s<LightAttributes_s>();
|
||||
LightAttributes.data_items = XmlMeta.ReadItemArray<LightAttributes_s>(node, "Lights");
|
||||
Cloths = new ResourcePointerList64<EnvironmentCloth>();
|
||||
Cloths.data_items = XmlMeta.ReadItemArray<EnvironmentCloth>(node, "Cloths");
|
||||
var cnode = node.SelectSingleNode("Cloths");
|
||||
if (cnode != null)
|
||||
{
|
||||
var inodes = cnode.SelectNodes("Item");
|
||||
if (inodes?.Count > 0)
|
||||
{
|
||||
var vlist = new List<EnvironmentCloth>();
|
||||
foreach (XmlNode inode in inodes)
|
||||
{
|
||||
var v = new EnvironmentCloth();
|
||||
v.ReadXml(inode, ddsfolder);
|
||||
vlist.Add(v);
|
||||
}
|
||||
Cloths.data_items = vlist.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
AssignChildrenSkeletonsAndBounds();
|
||||
AssignChildrenShaders();
|
||||
|
@ -1102,7 +1102,7 @@ namespace CodeWalker.GameFiles
|
||||
public ushort EntriesCapacity { get; private set; }
|
||||
|
||||
// reference data
|
||||
public ushort[] data_items { get; private set; }
|
||||
public ushort[] data_items { get; set; }
|
||||
|
||||
private ResourceSystemStructBlock<ushort> data_block;//used for saving.
|
||||
|
||||
@ -1336,7 +1336,7 @@ namespace CodeWalker.GameFiles
|
||||
public ushort EntriesCapacity { get; private set; }
|
||||
|
||||
// reference data
|
||||
public float[] data_items { get; private set; }
|
||||
public float[] data_items { get; set; }
|
||||
|
||||
private ResourceSystemStructBlock<float> data_block;//used for saving.
|
||||
|
||||
|
@ -229,6 +229,12 @@ namespace CodeWalker
|
||||
var cnode = node.SelectSingleNode(name);
|
||||
return GetRawByteArray(cnode, fromBase);
|
||||
}
|
||||
public static byte[] GetChildRawByteArrayNullable(XmlNode node, string name, int fromBase = 16)
|
||||
{
|
||||
var cnode = node.SelectSingleNode(name);
|
||||
var arr = GetRawByteArray(cnode, fromBase);
|
||||
return ((arr != null) && (arr.Length > 0)) ? arr : null;
|
||||
}
|
||||
|
||||
public static ushort[] GetRawUshortArray(XmlNode node)
|
||||
{
|
||||
@ -253,6 +259,12 @@ namespace CodeWalker
|
||||
var cnode = node.SelectSingleNode(name);
|
||||
return GetRawUshortArray(cnode);
|
||||
}
|
||||
public static ushort[] GetChildRawUshortArrayNullable(XmlNode node, string name)
|
||||
{
|
||||
var cnode = node.SelectSingleNode(name);
|
||||
var arr = GetRawUshortArray(cnode);
|
||||
return ((arr != null) && (arr.Length > 0)) ? arr : null;
|
||||
}
|
||||
|
||||
public static uint[] GetRawUintArray(XmlNode node)
|
||||
{
|
||||
@ -277,6 +289,12 @@ namespace CodeWalker
|
||||
var cnode = node.SelectSingleNode(name);
|
||||
return GetRawUintArray(cnode);
|
||||
}
|
||||
public static uint[] GetChildRawUintArrayNullable(XmlNode node, string name)
|
||||
{
|
||||
var cnode = node.SelectSingleNode(name);
|
||||
var arr = GetRawUintArray(cnode);
|
||||
return ((arr != null) && (arr.Length > 0)) ? arr : null;
|
||||
}
|
||||
|
||||
public static int[] GetRawIntArray(XmlNode node)
|
||||
{
|
||||
@ -301,6 +319,12 @@ namespace CodeWalker
|
||||
var cnode = node.SelectSingleNode(name);
|
||||
return GetRawIntArray(cnode);
|
||||
}
|
||||
public static int[] GetChildRawIntArrayNullable(XmlNode node, string name)
|
||||
{
|
||||
var cnode = node.SelectSingleNode(name);
|
||||
var arr = GetRawIntArray(cnode);
|
||||
return ((arr != null) && (arr.Length > 0)) ? arr : null;
|
||||
}
|
||||
|
||||
public static float[] GetRawFloatArray(XmlNode node)
|
||||
{
|
||||
@ -321,6 +345,12 @@ namespace CodeWalker
|
||||
var cnode = node.SelectSingleNode(name);
|
||||
return GetRawFloatArray(cnode);
|
||||
}
|
||||
public static float[] GetChildRawFloatArrayNullable(XmlNode node, string name)
|
||||
{
|
||||
var cnode = node.SelectSingleNode(name);
|
||||
var arr = GetRawFloatArray(cnode);
|
||||
return ((arr != null) && (arr.Length > 0)) ? arr : null;
|
||||
}
|
||||
|
||||
public static Vector2[] GetRawVector2Array(XmlNode node)
|
||||
{
|
||||
@ -457,6 +487,12 @@ namespace CodeWalker
|
||||
var cnode = node.SelectSingleNode(name);
|
||||
return GetRawVector4Array(cnode);
|
||||
}
|
||||
public static Vector4[] GetChildRawVector4ArrayNullable(XmlNode node, string name)
|
||||
{
|
||||
var cnode = node.SelectSingleNode(name);
|
||||
var arr = GetRawVector4Array(cnode);
|
||||
return ((arr != null) && (arr.Length > 0)) ? arr : null;
|
||||
}
|
||||
|
||||
public static Matrix GetMatrix(XmlNode node)
|
||||
{
|
||||
|
@ -239,7 +239,7 @@ namespace CodeWalker
|
||||
InitFileType(".ywr", "Waypoint Record", 9, FileTypeAction.ViewYwr);
|
||||
InitFileType(".fxc", "Compiled Shaders", 9, FileTypeAction.ViewFxc);
|
||||
InitFileType(".yed", "Expression Dictionary", 9, FileTypeAction.ViewYed);
|
||||
InitFileType(".yld", "Cloth Dictionary", 9, FileTypeAction.ViewYld);
|
||||
InitFileType(".yld", "Cloth Dictionary", 9, FileTypeAction.ViewYld, true);
|
||||
InitFileType(".yfd", "Frame Filter Dictionary", 9, FileTypeAction.ViewYfd);
|
||||
InitFileType(".asi", "ASI Plugin", 9);
|
||||
InitFileType(".dll", "Dynamic Link Library", 9);
|
||||
@ -2490,6 +2490,10 @@ namespace CodeWalker
|
||||
{
|
||||
mformat = MetaFormat.Ypt;
|
||||
}
|
||||
if (fnamel.EndsWith(".yld.xml"))
|
||||
{
|
||||
mformat = MetaFormat.Yld;
|
||||
}
|
||||
|
||||
fname = fname.Substring(0, fname.Length - trimlength);
|
||||
fnamel = fnamel.Substring(0, fnamel.Length - trimlength);
|
||||
@ -2638,6 +2642,17 @@ namespace CodeWalker
|
||||
data = ypt.Save();
|
||||
break;
|
||||
}
|
||||
case MetaFormat.Yld:
|
||||
{
|
||||
var yld = XmlYld.GetYld(doc, fpathin);
|
||||
if (yld.ClothDictionary == null)
|
||||
{
|
||||
MessageBox.Show(fname + ": Schema not supported.", "Cannot import YLD XML");
|
||||
continue;
|
||||
}
|
||||
data = yld.Save();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user