mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2026-05-15 09:04:52 +08:00
YED/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
|
||||
{
|
||||
@@ -56,10 +58,68 @@ namespace CodeWalker.GameFiles
|
||||
InitDictionaries();
|
||||
}
|
||||
|
||||
public byte[] Save()
|
||||
{
|
||||
byte[] data = ResourceBuilder.Build(ExpressionDictionary, 25); //yed is type/version 25...
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
public void InitDictionaries()
|
||||
{
|
||||
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);
|
||||
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
|
||||
|
||||
@@ -105,7 +105,12 @@ namespace CodeWalker.GameFiles
|
||||
else if (fnl.EndsWith(".yld"))
|
||||
{
|
||||
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"))
|
||||
{
|
||||
@@ -235,11 +240,17 @@ namespace CodeWalker.GameFiles
|
||||
filename = fn + ".xml";
|
||||
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) ?? "";
|
||||
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)
|
||||
{
|
||||
@@ -2169,8 +2180,9 @@ namespace CodeWalker.GameFiles
|
||||
Yft = 13,
|
||||
Ypt = 14,
|
||||
Yld = 15,
|
||||
Awc = 16,
|
||||
Heightmap = 17,
|
||||
Yed = 16,
|
||||
Awc = 17,
|
||||
Heightmap = 18,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user