mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-11-26 00:43:00 +08:00
YED/XML conversion
This commit is contained in:
parent
8c037e24f0
commit
7a8977b277
@ -1,9 +1,11 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
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
|
||||||
{
|
{
|
||||||
@ -56,10 +58,68 @@ namespace CodeWalker.GameFiles
|
|||||||
InitDictionaries();
|
InitDictionaries();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte[] Save()
|
||||||
|
{
|
||||||
|
byte[] data = ResourceBuilder.Build(ExpressionDictionary, 25); //yed is type/version 25...
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void InitDictionaries()
|
public void InitDictionaries()
|
||||||
{
|
{
|
||||||
ExprMap = ExpressionDictionary?.ExprMap ?? new Dictionary<MetaHash, Expression>();
|
ExprMap = ExpressionDictionary?.ExprMap ?? new Dictionary<MetaHash, Expression>();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public class YedXml : MetaXmlBase
|
||||||
|
{
|
||||||
|
|
||||||
|
public static string GetXml(YedFile yed, string outputFolder = "")
|
||||||
|
{
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.AppendLine(XmlHeader);
|
||||||
|
|
||||||
|
if (yed?.ExpressionDictionary != null)
|
||||||
|
{
|
||||||
|
ExpressionDictionary.WriteXmlNode(yed.ExpressionDictionary, sb, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class XmlYed
|
||||||
|
{
|
||||||
|
|
||||||
|
public static YedFile GetYed(string xml, string inputFolder = "")
|
||||||
|
{
|
||||||
|
XmlDocument doc = new XmlDocument();
|
||||||
|
doc.LoadXml(xml);
|
||||||
|
return GetYed(doc, inputFolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static YedFile GetYed(XmlDocument doc, string inputFolder = "")
|
||||||
|
{
|
||||||
|
YedFile r = new YedFile();
|
||||||
|
|
||||||
|
var node = doc.DocumentElement;
|
||||||
|
if (node != null)
|
||||||
|
{
|
||||||
|
r.ExpressionDictionary = ExpressionDictionary.ReadXmlNode(node);
|
||||||
|
|
||||||
|
r.InitDictionaries();
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Name = Path.GetFileName(inputFolder);
|
||||||
|
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3518,6 +3518,16 @@ namespace CodeWalker.GameFiles
|
|||||||
YedFile yed = new YedFile(rfe);
|
YedFile yed = new YedFile(rfe);
|
||||||
RpfMan.LoadFile(yed, rfe);
|
RpfMan.LoadFile(yed, rfe);
|
||||||
|
|
||||||
|
var data1 = entry.File.ExtractFile(rfe);
|
||||||
|
var xml = YedXml.GetXml(yed);
|
||||||
|
var yed2 = XmlYed.GetYed(xml);
|
||||||
|
var data2 = yed2.Save();
|
||||||
|
var yed3 = new YedFile();
|
||||||
|
RpfFile.LoadResourceFile(yed3, data2, 25);//full roundtrip
|
||||||
|
var xml2 = YedXml.GetXml(yed3);
|
||||||
|
if (xml != xml2)
|
||||||
|
{ }
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if !DEBUG
|
#if !DEBUG
|
||||||
|
@ -105,7 +105,12 @@ namespace CodeWalker.GameFiles
|
|||||||
else if (fnl.EndsWith(".yld"))
|
else if (fnl.EndsWith(".yld"))
|
||||||
{
|
{
|
||||||
YldFile yld = RpfFile.GetFile<YldFile>(e, data);
|
YldFile yld = RpfFile.GetFile<YldFile>(e, data);
|
||||||
return GetXml(yld, out filename, outputfolder);
|
return GetXml(yld, out filename);
|
||||||
|
}
|
||||||
|
else if (fnl.EndsWith(".yed"))
|
||||||
|
{
|
||||||
|
YedFile yed = RpfFile.GetFile<YedFile>(e, data);
|
||||||
|
return GetXml(yed, out filename);
|
||||||
}
|
}
|
||||||
else if (fnl.EndsWith(".awc"))
|
else if (fnl.EndsWith(".awc"))
|
||||||
{
|
{
|
||||||
@ -235,11 +240,17 @@ namespace CodeWalker.GameFiles
|
|||||||
filename = fn + ".xml";
|
filename = fn + ".xml";
|
||||||
return YptXml.GetXml(ypt, outputfolder);
|
return YptXml.GetXml(ypt, outputfolder);
|
||||||
}
|
}
|
||||||
public static string GetXml(YldFile yld, out string filename, string outputfolder)
|
public static string GetXml(YldFile yld, out string filename)
|
||||||
{
|
{
|
||||||
var fn = (yld?.Name) ?? "";
|
var fn = (yld?.Name) ?? "";
|
||||||
filename = fn + ".xml";
|
filename = fn + ".xml";
|
||||||
return YldXml.GetXml(yld, outputfolder);
|
return YldXml.GetXml(yld);
|
||||||
|
}
|
||||||
|
public static string GetXml(YedFile yed, out string filename)
|
||||||
|
{
|
||||||
|
var fn = (yed?.Name) ?? "";
|
||||||
|
filename = fn + ".xml";
|
||||||
|
return YedXml.GetXml(yed);
|
||||||
}
|
}
|
||||||
public static string GetXml(AwcFile awc, out string filename, string outputfolder)
|
public static string GetXml(AwcFile awc, out string filename, string outputfolder)
|
||||||
{
|
{
|
||||||
@ -2169,8 +2180,9 @@ namespace CodeWalker.GameFiles
|
|||||||
Yft = 13,
|
Yft = 13,
|
||||||
Ypt = 14,
|
Ypt = 14,
|
||||||
Yld = 15,
|
Yld = 15,
|
||||||
Awc = 16,
|
Yed = 16,
|
||||||
Heightmap = 17,
|
Awc = 17,
|
||||||
|
Heightmap = 18,
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -279,7 +279,7 @@ namespace CodeWalker
|
|||||||
InitFileType(".yvr", "Vehicle Record", 9, FileTypeAction.ViewYvr);
|
InitFileType(".yvr", "Vehicle Record", 9, FileTypeAction.ViewYvr);
|
||||||
InitFileType(".ywr", "Waypoint Record", 9, FileTypeAction.ViewYwr);
|
InitFileType(".ywr", "Waypoint Record", 9, FileTypeAction.ViewYwr);
|
||||||
InitFileType(".fxc", "Compiled Shaders", 9, FileTypeAction.ViewFxc);
|
InitFileType(".fxc", "Compiled Shaders", 9, FileTypeAction.ViewFxc);
|
||||||
InitFileType(".yed", "Expression Dictionary", 9, FileTypeAction.ViewYed);
|
InitFileType(".yed", "Expression Dictionary", 9, FileTypeAction.ViewYed, true);
|
||||||
InitFileType(".yld", "Cloth Dictionary", 9, FileTypeAction.ViewYld, true);
|
InitFileType(".yld", "Cloth Dictionary", 9, FileTypeAction.ViewYld, true);
|
||||||
InitFileType(".yfd", "Frame Filter Dictionary", 9, FileTypeAction.ViewYfd);
|
InitFileType(".yfd", "Frame Filter Dictionary", 9, FileTypeAction.ViewYfd);
|
||||||
InitFileType(".asi", "ASI Plugin", 9);
|
InitFileType(".asi", "ASI Plugin", 9);
|
||||||
@ -1748,16 +1748,16 @@ namespace CodeWalker
|
|||||||
private void ViewYed(string name, string path, byte[] data, RpfFileEntry e)
|
private void ViewYed(string name, string path, byte[] data, RpfFileEntry e)
|
||||||
{
|
{
|
||||||
var yed = RpfFile.GetFile<YedFile>(e, data);
|
var yed = RpfFile.GetFile<YedFile>(e, data);
|
||||||
GenericForm f = new GenericForm(this);
|
MetaForm f = new MetaForm(this);
|
||||||
f.Show();
|
f.Show();
|
||||||
f.LoadFile(yed, yed.RpfFileEntry);
|
f.LoadMeta(yed);
|
||||||
}
|
}
|
||||||
private void ViewYld(string name, string path, byte[] data, RpfFileEntry e)
|
private void ViewYld(string name, string path, byte[] data, RpfFileEntry e)
|
||||||
{
|
{
|
||||||
var yld = RpfFile.GetFile<YldFile>(e, data);
|
var yld = RpfFile.GetFile<YldFile>(e, data);
|
||||||
GenericForm f = new GenericForm(this);
|
MetaForm f = new MetaForm(this);
|
||||||
f.Show();
|
f.Show();
|
||||||
f.LoadFile(yld, yld.RpfFileEntry);
|
f.LoadMeta(yld);
|
||||||
}
|
}
|
||||||
private void ViewYfd(string name, string path, byte[] data, RpfFileEntry e)
|
private void ViewYfd(string name, string path, byte[] data, RpfFileEntry e)
|
||||||
{
|
{
|
||||||
@ -2741,6 +2741,10 @@ namespace CodeWalker
|
|||||||
{
|
{
|
||||||
mformat = MetaFormat.Yld;
|
mformat = MetaFormat.Yld;
|
||||||
}
|
}
|
||||||
|
if (fnamel.EndsWith(".yed.xml"))
|
||||||
|
{
|
||||||
|
mformat = MetaFormat.Yed;
|
||||||
|
}
|
||||||
if (fnamel.EndsWith(".awc.xml"))
|
if (fnamel.EndsWith(".awc.xml"))
|
||||||
{
|
{
|
||||||
mformat = MetaFormat.Awc;
|
mformat = MetaFormat.Awc;
|
||||||
@ -2924,6 +2928,17 @@ namespace CodeWalker
|
|||||||
data = yld.Save();
|
data = yld.Save();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case MetaFormat.Yed:
|
||||||
|
{
|
||||||
|
var yed = XmlYed.GetYed(doc, fpathin);
|
||||||
|
if (yed.ExpressionDictionary == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show(fname + ": Schema not supported.", "Cannot import YED XML");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
data = yed.Save();
|
||||||
|
break;
|
||||||
|
}
|
||||||
case MetaFormat.Awc:
|
case MetaFormat.Awc:
|
||||||
{
|
{
|
||||||
var awc = XmlAwc.GetAwc(doc, fpathin);
|
var awc = XmlAwc.GetAwc(doc, fpathin);
|
||||||
|
@ -318,6 +318,34 @@ namespace CodeWalker.Forms
|
|||||||
metaFormat = MetaFormat.Ynd;
|
metaFormat = MetaFormat.Ynd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void LoadMeta(YldFile yld)
|
||||||
|
{
|
||||||
|
var fn = ((yld?.RpfFileEntry?.Name) ?? "") + ".xml";
|
||||||
|
Xml = MetaXml.GetXml(yld, out fn);
|
||||||
|
FileName = fn;
|
||||||
|
RawPropertyGrid.SelectedObject = yld;
|
||||||
|
rpfFileEntry = yld?.RpfFileEntry;
|
||||||
|
modified = false;
|
||||||
|
metaFormat = MetaFormat.XML;
|
||||||
|
if (yld?.RpfFileEntry != null)
|
||||||
|
{
|
||||||
|
metaFormat = MetaFormat.Yld;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void LoadMeta(YedFile yed)
|
||||||
|
{
|
||||||
|
var fn = ((yed?.RpfFileEntry?.Name) ?? "") + ".xml";
|
||||||
|
Xml = MetaXml.GetXml(yed, out fn);
|
||||||
|
FileName = fn;
|
||||||
|
RawPropertyGrid.SelectedObject = yed;
|
||||||
|
rpfFileEntry = yed?.RpfFileEntry;
|
||||||
|
modified = false;
|
||||||
|
metaFormat = MetaFormat.XML;
|
||||||
|
if (yed?.RpfFileEntry != null)
|
||||||
|
{
|
||||||
|
metaFormat = MetaFormat.Yed;
|
||||||
|
}
|
||||||
|
}
|
||||||
public void LoadMeta(CacheDatFile cachedat)
|
public void LoadMeta(CacheDatFile cachedat)
|
||||||
{
|
{
|
||||||
var fn = ((cachedat?.FileEntry?.Name) ?? "") + ".xml";
|
var fn = ((cachedat?.FileEntry?.Name) ?? "") + ".xml";
|
||||||
@ -404,6 +432,24 @@ namespace CodeWalker.Forms
|
|||||||
}
|
}
|
||||||
data = ynd.Save();
|
data = ynd.Save();
|
||||||
break;
|
break;
|
||||||
|
case MetaFormat.Yld:
|
||||||
|
var yld = XmlYld.GetYld(doc);
|
||||||
|
if (yld.ClothDictionary == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Schema not supported.", "Cannot import YLD XML");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
data = yld.Save();
|
||||||
|
break;
|
||||||
|
case MetaFormat.Yed:
|
||||||
|
var yed = XmlYed.GetYed(doc);
|
||||||
|
if (yed.ExpressionDictionary == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Schema not supported.", "Cannot import YED XML");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
data = yed.Save();
|
||||||
|
break;
|
||||||
case MetaFormat.CacheFile:
|
case MetaFormat.CacheFile:
|
||||||
MessageBox.Show("Sorry, CacheFile import is not supported.", "Cannot import CacheFile XML");
|
MessageBox.Show("Sorry, CacheFile import is not supported.", "Cannot import CacheFile XML");
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user