2017-09-21 18:33:05 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-11-07 20:14:39 +08:00
|
|
|
|
using System.ComponentModel;
|
2017-09-21 18:33:05 +08:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-01-17 20:02:55 +08:00
|
|
|
|
using System.Xml;
|
2017-09-21 18:33:05 +08:00
|
|
|
|
|
|
|
|
|
namespace CodeWalker.GameFiles
|
|
|
|
|
{
|
2019-11-07 20:14:39 +08:00
|
|
|
|
[TypeConverter(typeof(ExpandableObjectConverter))]
|
2017-09-21 18:33:05 +08:00
|
|
|
|
public class YtdFile : GameFile, PackedFile
|
|
|
|
|
{
|
|
|
|
|
public TextureDictionary TextureDict { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public YtdFile() : base(null, GameFileType.Ytd)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
public YtdFile(RpfFileEntry entry) : base(entry, GameFileType.Ytd)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Load(byte[] data, RpfFileEntry entry)
|
|
|
|
|
{
|
|
|
|
|
Name = entry.Name;
|
2021-12-28 20:26:35 +08:00
|
|
|
|
RpfFileEntry = entry;
|
2017-09-21 18:33:05 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RpfResourceFileEntry resentry = entry as RpfResourceFileEntry;
|
|
|
|
|
if (resentry == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("File entry wasn't a resource! (is it binary data?)");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResourceDataReader rd = new ResourceDataReader(resentry, data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TextureDict = rd.ReadBlock<TextureDictionary>();
|
|
|
|
|
|
|
|
|
|
//MemoryUsage = 0; //uses decompressed file size now..
|
|
|
|
|
//if (TextureDict != null)
|
|
|
|
|
//{
|
|
|
|
|
// MemoryUsage += TextureDict.MemoryUsage;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-01-27 14:14:10 +08:00
|
|
|
|
public byte[] Save()
|
|
|
|
|
{
|
|
|
|
|
byte[] data = ResourceBuilder.Build(TextureDict, 13); //ytd is type/version 13...
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|
2020-01-17 20:02:55 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class YtdXml : MetaXmlBase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public static string GetXml(YtdFile ytd, string outputFolder = "")
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.AppendLine(XmlHeader);
|
|
|
|
|
|
|
|
|
|
if (ytd?.TextureDict != null)
|
|
|
|
|
{
|
2020-01-27 15:19:45 +08:00
|
|
|
|
TextureDictionary.WriteXmlNode(ytd.TextureDict, sb, 0, outputFolder);
|
2020-01-17 20:02:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class XmlYtd
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public static YtdFile GetYtd(string xml, string inputFolder = "")
|
|
|
|
|
{
|
|
|
|
|
XmlDocument doc = new XmlDocument();
|
|
|
|
|
doc.LoadXml(xml);
|
|
|
|
|
return GetYtd(doc, inputFolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static YtdFile GetYtd(XmlDocument doc, string inputFolder = "")
|
|
|
|
|
{
|
|
|
|
|
YtdFile r = new YtdFile();
|
|
|
|
|
|
|
|
|
|
var ddsfolder = inputFolder;
|
|
|
|
|
|
|
|
|
|
var node = doc.DocumentElement;
|
|
|
|
|
if (node != null)
|
|
|
|
|
{
|
|
|
|
|
r.TextureDict = TextureDictionary.ReadXmlNode(node, ddsfolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r.Name = Path.GetFileName(inputFolder);
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|