mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2026-05-14 16:04:49 +08:00
YLD/XML conversion
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user