YDR/YDD/YFT/YPT/XML conversion progress

This commit is contained in:
dexy 2020-01-18 04:20:40 +11:00
parent f81958679a
commit cd4c87cd71
9 changed files with 965 additions and 223 deletions

View File

@ -5,6 +5,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml;
namespace CodeWalker.GameFiles namespace CodeWalker.GameFiles
{ {
@ -93,4 +94,68 @@ namespace CodeWalker.GameFiles
} }
} }
public class YddXml : MetaXmlBase
{
public static string GetXml(YddFile ydd, string outputFolder = "")
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(XmlHeader);
var ddsfolder = outputFolder;
if (!string.IsNullOrEmpty(ddsfolder))
{
ddsfolder = Path.Combine(outputFolder, ydd.Name);
if (!Directory.Exists(ddsfolder))
{
Directory.CreateDirectory(ddsfolder);
}
}
if (ydd?.DrawableDict != null)
{
DrawableDictionary.WriteXmlNode(ydd.DrawableDict, sb, 0, ddsfolder);
}
return sb.ToString();
}
}
public class XmlYdd
{
public static YddFile GetYdd(string xml, string inputFolder = "")
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
return GetYdd(doc, inputFolder);
}
public static YddFile GetYdd(XmlDocument doc, string inputFolder = "")
{
YddFile r = new YddFile();
var ddsfolder = inputFolder;
var node = doc.DocumentElement;
if (node != null)
{
r.DrawableDict = DrawableDictionary.ReadXmlNode(node, ddsfolder);
}
r.Name = Path.GetFileName(inputFolder);
return r;
}
}
} }

View File

@ -4,6 +4,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml;
namespace CodeWalker.GameFiles namespace CodeWalker.GameFiles
{ {
@ -62,5 +63,64 @@ namespace CodeWalker.GameFiles
public class YdrXml : MetaXmlBase
{
public static string GetXml(YdrFile ydr, string outputFolder = "")
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(XmlHeader);
var ddsfolder = outputFolder;
if (!string.IsNullOrEmpty(ddsfolder))
{
ddsfolder = Path.Combine(outputFolder, ydr.Name);
if (!Directory.Exists(ddsfolder))
{
Directory.CreateDirectory(ddsfolder);
}
}
if (ydr?.Drawable != null)
{
Drawable.WriteXmlNode(ydr.Drawable, sb, 0, ddsfolder);
}
return sb.ToString();
}
}
public class XmlYdr
{
public static YdrFile GetYdr(string xml, string inputFolder = "")
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
return GetYdr(doc, inputFolder);
}
public static YdrFile GetYdr(XmlDocument doc, string inputFolder = "")
{
YdrFile r = new YdrFile();
var ddsfolder = inputFolder;
var node = doc.DocumentElement;
if (node != null)
{
r.Drawable = Drawable.ReadXmlNode(node, ddsfolder);
}
r.Name = Path.GetFileName(inputFolder);
return r;
}
}
} }

View File

@ -5,6 +5,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml;
namespace CodeWalker.GameFiles namespace CodeWalker.GameFiles
{ {
@ -61,4 +62,70 @@ namespace CodeWalker.GameFiles
} }
public class YftXml : MetaXmlBase
{
public static string GetXml(YftFile yft, string outputFolder = "")
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(XmlHeader);
var ddsfolder = outputFolder;
if (!string.IsNullOrEmpty(ddsfolder))
{
ddsfolder = Path.Combine(outputFolder, yft.Name);
if (!Directory.Exists(ddsfolder))
{
Directory.CreateDirectory(ddsfolder);
}
}
if (yft?.Fragment != null)
{
FragType.WriteXmlNode(yft.Fragment, sb, 0, ddsfolder);
}
return sb.ToString();
}
}
public class XmlYft
{
public static YftFile GetYft(string xml, string inputFolder = "")
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
return GetYft(doc, inputFolder);
}
public static YftFile GetYft(XmlDocument doc, string inputFolder = "")
{
YftFile r = new YftFile();
var ddsfolder = inputFolder;
var node = doc.DocumentElement;
if (node != null)
{
r.Fragment = FragType.ReadXmlNode(node, ddsfolder);
}
r.Name = Path.GetFileName(inputFolder);
return r;
}
}
} }

View File

@ -1,8 +1,10 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml;
namespace CodeWalker.GameFiles namespace CodeWalker.GameFiles
{ {
@ -50,12 +52,29 @@ namespace CodeWalker.GameFiles
} }
BuildDrawableDict();
Loaded = true;
}
public byte[] Save()
{
byte[] data = ResourceBuilder.Build(PtfxList, 68); //ypt is type/version 68...
return data;
}
private void BuildDrawableDict()
{
var dDict = PtfxList?.DrawableDictionary; var dDict = PtfxList?.DrawableDictionary;
if ((dDict != null) && if ((dDict?.Drawables?.data_items != null) && (dDict?.Hashes != null))
(dDict.Drawables != null) &&
(dDict.Drawables.data_items != null) &&
(dDict.Hashes != null))
{ {
DrawableDict = new Dictionary<uint, Drawable>(); DrawableDict = new Dictionary<uint, Drawable>();
var drawables = dDict.Drawables.data_items; var drawables = dDict.Drawables.data_items;
@ -85,29 +104,76 @@ namespace CodeWalker.GameFiles
} }
} }
} }
} }
Loaded = true;
} }
public byte[] Save()
{
byte[] data = ResourceBuilder.Build(PtfxList, 68); //ypt is type/version 68...
return data;
}
} }
public class YptXml : MetaXmlBase
{
public static string GetXml(YptFile ypt, string outputFolder = "")
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(XmlHeader);
var ddsfolder = outputFolder;
if (!string.IsNullOrEmpty(ddsfolder))
{
ddsfolder = Path.Combine(outputFolder, ypt.Name);
if (!Directory.Exists(ddsfolder))
{
Directory.CreateDirectory(ddsfolder);
}
}
if (ypt?.PtfxList != null)
{
ParticleEffectsList.WriteXmlNode(ypt.PtfxList, sb, 0, ddsfolder);
}
return sb.ToString();
}
}
public class XmlYpt
{
public static YptFile GetYpt(string xml, string inputFolder = "")
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
return GetYpt(doc, inputFolder);
}
public static YptFile GetYpt(XmlDocument doc, string inputFolder = "")
{
YptFile r = new YptFile();
var ddsfolder = inputFolder;
var node = doc.DocumentElement;
if (node != null)
{
r.PtfxList = ParticleEffectsList.ReadXmlNode(node, ddsfolder);
}
r.Name = Path.GetFileName(inputFolder);
return r;
}
}
} }

View File

@ -71,6 +71,26 @@ namespace CodeWalker.GameFiles
YtdFile ytd = RpfFile.GetFile<YtdFile>(e, data); YtdFile ytd = RpfFile.GetFile<YtdFile>(e, data);
return GetXml(ytd, out filename, outputfolder); return GetXml(ytd, out filename, outputfolder);
} }
else if (fnl.EndsWith(".ydr"))
{
YdrFile ydr = RpfFile.GetFile<YdrFile>(e, data);
return GetXml(ydr, out filename, outputfolder);
}
else if (fnl.EndsWith(".ydd"))
{
YddFile ydd = RpfFile.GetFile<YddFile>(e, data);
return GetXml(ydd, out filename, outputfolder);
}
else if (fnl.EndsWith(".yft"))
{
YftFile yft = RpfFile.GetFile<YftFile>(e, data);
return GetXml(yft, out filename, outputfolder);
}
else if (fnl.EndsWith(".ypt"))
{
YptFile ypt = RpfFile.GetFile<YptFile>(e, data);
return GetXml(ypt, out filename, outputfolder);
}
filename = fn; filename = fn;
return string.Empty; return string.Empty;
} }
@ -154,6 +174,30 @@ namespace CodeWalker.GameFiles
filename = fn + ".xml"; filename = fn + ".xml";
return YtdXml.GetXml(ytd, outputfolder); return YtdXml.GetXml(ytd, outputfolder);
} }
public static string GetXml(YdrFile ydr, out string filename, string outputfolder)
{
var fn = (ydr?.Name) ?? "";
filename = fn + ".xml";
return YdrXml.GetXml(ydr, outputfolder);
}
public static string GetXml(YddFile ydd, out string filename, string outputfolder)
{
var fn = (ydd?.Name) ?? "";
filename = fn + ".xml";
return YddXml.GetXml(ydd, outputfolder);
}
public static string GetXml(YftFile yft, out string filename, string outputfolder)
{
var fn = (yft?.Name) ?? "";
filename = fn + ".xml";
return YftXml.GetXml(yft, outputfolder);
}
public static string GetXml(YptFile ypt, out string filename, string outputfolder)
{
var fn = (ypt?.Name) ?? "";
filename = fn + ".xml";
return YptXml.GetXml(ypt, outputfolder);
}
@ -2041,6 +2085,10 @@ namespace CodeWalker.GameFiles
Ycd = 7, Ycd = 7,
Ybn = 8, Ybn = 8,
Ytd = 9, Ytd = 9,
Ydr = 10,
Ydd = 11,
Yft = 12,
Ypt = 13,
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -31,7 +31,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml;
namespace CodeWalker.GameFiles namespace CodeWalker.GameFiles
{ {
@ -123,9 +123,6 @@ namespace CodeWalker.GameFiles
public YftFile Yft { get; set; } public YftFile Yft { get; set; }
/// <summary>
/// Reads the data-block from a stream.
/// </summary>
public override void Read(ResourceDataReader reader, params object[] parameters) public override void Read(ResourceDataReader reader, params object[] parameters)
{ {
base.Read(reader, parameters); base.Read(reader, parameters);
@ -250,10 +247,6 @@ namespace CodeWalker.GameFiles
} }
/// <summary>
/// Writes the data-block to a stream.
/// </summary>
public override void Write(ResourceDataWriter writer, params object[] parameters) public override void Write(ResourceDataWriter writer, params object[] parameters)
{ {
base.Write(writer, parameters); base.Write(writer, parameters);
@ -332,10 +325,29 @@ namespace CodeWalker.GameFiles
writer.Write(this.Unknown_128h); writer.Write(this.Unknown_128h);
writer.Write(this.Unknown_12Ch); writer.Write(this.Unknown_12Ch);
} }
public void WriteXml(StringBuilder sb, int indent, string ddsfolder)
{
//TODO
}
public void ReadXml(XmlNode node, string ddsfolder)
{
//TODO
}
public static void WriteXmlNode(FragType f, StringBuilder sb, int indent, string ddsfolder, string name = "Fragment")
{
if (f == null) return;
YftXml.OpenTag(sb, indent, name);
f.WriteXml(sb, indent + 1, ddsfolder);
YftXml.CloseTag(sb, indent, name);
}
public static FragType ReadXmlNode(XmlNode node, string ddsfolder)
{
if (node == null) return null;
var f = new FragType();
f.ReadXml(node, ddsfolder);
return f;
}
/// <summary>
/// Returns a list of data blocks which are referenced by this block.
/// </summary>
public override IResourceBlock[] GetReferences() public override IResourceBlock[] GetReferences()
{ {
var list = new List<IResourceBlock>(base.GetReferences()); var list = new List<IResourceBlock>(base.GetReferences());
@ -413,9 +425,6 @@ namespace CodeWalker.GameFiles
private ResourceSystemStructBlock<Matrix> Unknown_108h_DataBlock = null; private ResourceSystemStructBlock<Matrix> Unknown_108h_DataBlock = null;
private string_r NameBlock = null; private string_r NameBlock = null;
/// <summary>
/// Reads the data-block from a stream.
/// </summary>
public override void Read(ResourceDataReader reader, params object[] parameters) public override void Read(ResourceDataReader reader, params object[] parameters)
{ {
base.Read(reader, parameters); base.Read(reader, parameters);
@ -465,10 +474,6 @@ namespace CodeWalker.GameFiles
if (FragMatrices != null) if (FragMatrices != null)
{ } { }
} }
/// <summary>
/// Writes the data-block to a stream.
/// </summary>
public override void Write(ResourceDataWriter writer, params object[] parameters) public override void Write(ResourceDataWriter writer, params object[] parameters)
{ {
base.Write(writer, parameters); base.Write(writer, parameters);
@ -508,10 +513,31 @@ namespace CodeWalker.GameFiles
writer.Write(this.Unknown_148h); writer.Write(this.Unknown_148h);
writer.Write(this.Unknown_14Ch); writer.Write(this.Unknown_14Ch);
} }
public override void WriteXml(StringBuilder sb, int indent, string ddsfolder)
{
base.WriteXml(sb, indent, ddsfolder);
//TODO
}
public override void ReadXml(XmlNode node, string ddsfolder)
{
base.ReadXml(node, ddsfolder);
//TODO
}
public static void WriteXmlNode(FragDrawable d, StringBuilder sb, int indent, string ddsfolder, string name = "FragDrawable")
{
if (d == null) return;
YftXml.OpenTag(sb, indent, name);
d.WriteXml(sb, indent + 1, ddsfolder);
YftXml.CloseTag(sb, indent, name);
}
public static FragDrawable ReadXmlNode(XmlNode node, string ddsfolder)
{
if (node == null) return null;
var d = new FragDrawable();
d.ReadXml(node, ddsfolder);
return d;
}
/// <summary>
/// Returns a list of data blocks which are referenced by this block.
/// </summary>
public override IResourceBlock[] GetReferences() public override IResourceBlock[] GetReferences()
{ {
var list = new List<IResourceBlock>(base.GetReferences()); var list = new List<IResourceBlock>(base.GetReferences());

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml;
using TC = System.ComponentModel.TypeConverterAttribute; using TC = System.ComponentModel.TypeConverterAttribute;
using EXP = System.ComponentModel.ExpandableObjectConverter; using EXP = System.ComponentModel.ExpandableObjectConverter;
@ -110,7 +111,6 @@ namespace CodeWalker.GameFiles
this.EffectRuleDictionaryPointer // offset this.EffectRuleDictionaryPointer // offset
); );
} }
public override void Write(ResourceDataWriter writer, params object[] parameters) public override void Write(ResourceDataWriter writer, params object[] parameters)
{ {
base.Write(writer, parameters); base.Write(writer, parameters);
@ -139,6 +139,28 @@ namespace CodeWalker.GameFiles
writer.Write(this.Unknown_58h); writer.Write(this.Unknown_58h);
writer.Write(this.Unknown_5Ch); writer.Write(this.Unknown_5Ch);
} }
public void WriteXml(StringBuilder sb, int indent, string ddsfolder)
{
//TODO
}
public void ReadXml(XmlNode node, string ddsfolder)
{
//TODO
}
public static void WriteXmlNode(ParticleEffectsList p, StringBuilder sb, int indent, string ddsfolder, string name = "ParticleEffectsList")
{
if (p == null) return;
YptXml.OpenTag(sb, indent, name);
p.WriteXml(sb, indent + 1, ddsfolder);
YptXml.CloseTag(sb, indent, name);
}
public static ParticleEffectsList ReadXmlNode(XmlNode node, string ddsfolder)
{
if (node == null) return null;
var p = new ParticleEffectsList();
p.ReadXml(node, ddsfolder);
return p;
}
public override IResourceBlock[] GetReferences() public override IResourceBlock[] GetReferences()
{ {

View File

@ -244,9 +244,9 @@ namespace CodeWalker
InitFileType(".asi", "ASI Plugin", 9); InitFileType(".asi", "ASI Plugin", 9);
InitFileType(".dll", "Dynamic Link Library", 9); InitFileType(".dll", "Dynamic Link Library", 9);
InitFileType(".exe", "Executable", 10); InitFileType(".exe", "Executable", 10);
InitFileType(".yft", "Fragment", 11, FileTypeAction.ViewModel); InitFileType(".yft", "Fragment", 11, FileTypeAction.ViewModel, true);
InitFileType(".ydr", "Drawable", 11, FileTypeAction.ViewModel); InitFileType(".ydr", "Drawable", 11, FileTypeAction.ViewModel, true);
InitFileType(".ydd", "Drawable Dictionary", 12, FileTypeAction.ViewModel); InitFileType(".ydd", "Drawable Dictionary", 12, FileTypeAction.ViewModel, true);
InitFileType(".cut", "Cutscene", 12, FileTypeAction.ViewCut, true); InitFileType(".cut", "Cutscene", 12, FileTypeAction.ViewCut, true);
InitFileType(".ysc", "Script", 13); InitFileType(".ysc", "Script", 13);
InitFileType(".ymf", "Manifest", 14, FileTypeAction.ViewYmf, true); InitFileType(".ymf", "Manifest", 14, FileTypeAction.ViewYmf, true);
@ -259,7 +259,7 @@ namespace CodeWalker
InitFileType(".ytd", "Texture Dictionary", 16, FileTypeAction.ViewYtd, true); InitFileType(".ytd", "Texture Dictionary", 16, FileTypeAction.ViewYtd, true);
InitFileType(".mrf", "MRF File", 18); InitFileType(".mrf", "MRF File", 18);
InitFileType(".ycd", "Clip Dictionary", 18, FileTypeAction.ViewYcd, true); InitFileType(".ycd", "Clip Dictionary", 18, FileTypeAction.ViewYcd, true);
InitFileType(".ypt", "Particle Effect", 18, FileTypeAction.ViewModel); InitFileType(".ypt", "Particle Effect", 18, FileTypeAction.ViewModel, true);
InitFileType(".ybn", "Static Collisions", 19, FileTypeAction.ViewModel, true); InitFileType(".ybn", "Static Collisions", 19, FileTypeAction.ViewModel, true);
InitFileType(".ide", "Item Definitions", 20, FileTypeAction.ViewText); InitFileType(".ide", "Item Definitions", 20, FileTypeAction.ViewText);
InitFileType(".ytyp", "Archetype Definitions", 20, FileTypeAction.ViewYtyp, true); InitFileType(".ytyp", "Archetype Definitions", 20, FileTypeAction.ViewYtyp, true);
@ -2470,6 +2470,22 @@ namespace CodeWalker
{ {
mformat = MetaFormat.Ytd; mformat = MetaFormat.Ytd;
} }
if (fnamel.EndsWith(".ydr.xml"))
{
mformat = MetaFormat.Ydr;
}
if (fnamel.EndsWith(".ydd.xml"))
{
mformat = MetaFormat.Ydd;
}
if (fnamel.EndsWith(".yft.xml"))
{
mformat = MetaFormat.Yft;
}
if (fnamel.EndsWith(".ypt.xml"))
{
mformat = MetaFormat.Ypt;
}
fname = fname.Substring(0, fname.Length - trimlength); fname = fname.Substring(0, fname.Length - trimlength);
fnamel = fnamel.Substring(0, fnamel.Length - trimlength); fnamel = fnamel.Substring(0, fnamel.Length - trimlength);
@ -2574,6 +2590,50 @@ namespace CodeWalker
data = ytd.Save(); data = ytd.Save();
break; break;
} }
case MetaFormat.Ydr:
{
var ydr = XmlYdr.GetYdr(doc, fpathin);
if (ydr.Drawable == null)
{
MessageBox.Show(fname + ": Schema not supported.", "Cannot import YDR XML");
continue;
}
data = ydr.Save();
break;
}
case MetaFormat.Ydd:
{
var ydd = XmlYdd.GetYdd(doc, fpathin);
if (ydd.DrawableDict == null)
{
MessageBox.Show(fname + ": Schema not supported.", "Cannot import YDD XML");
continue;
}
data = ydd.Save();
break;
}
case MetaFormat.Yft:
{
var yft = XmlYft.GetYft(doc, fpathin);
if (yft.Fragment == null)
{
MessageBox.Show(fname + ": Schema not supported.", "Cannot import YFT XML");
continue;
}
data = yft.Save();
break;
}
case MetaFormat.Ypt:
{
var ypt = XmlYpt.GetYpt(doc, fpathin);
if (ypt.PtfxList == null)
{
MessageBox.Show(fname + ": Schema not supported.", "Cannot import YPT XML");
continue;
}
data = ypt.Save();
break;
}
} }