2017-09-21 18:33:05 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-01-18 01:20:40 +08:00
|
|
|
|
using System.Xml;
|
2017-09-21 18:33:05 +08:00
|
|
|
|
|
|
|
|
|
namespace CodeWalker.GameFiles
|
|
|
|
|
{
|
|
|
|
|
[TypeConverter(typeof(ExpandableObjectConverter))] public class YddFile : GameFile, PackedFile
|
|
|
|
|
{
|
2017-09-23 19:46:49 +08:00
|
|
|
|
public DrawableDictionary DrawableDict { get; set; }
|
2017-09-21 18:33:05 +08:00
|
|
|
|
|
|
|
|
|
public Dictionary<uint, Drawable> Dict { get; set; }
|
|
|
|
|
public Drawable[] Drawables { get; set; }
|
|
|
|
|
|
|
|
|
|
public YddFile() : base(null, GameFileType.Ydd)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
public YddFile(RpfFileEntry entry) : base(entry, GameFileType.Ydd)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Load(byte[] data, RpfFileEntry entry)
|
|
|
|
|
{
|
|
|
|
|
Name = entry.Name;
|
|
|
|
|
RpfFileEntry = entry;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2017-09-23 19:46:49 +08:00
|
|
|
|
DrawableDict = rd.ReadBlock<DrawableDictionary>();
|
2017-09-21 18:33:05 +08:00
|
|
|
|
|
|
|
|
|
//MemoryUsage = 0; //uses decompressed filesize now...
|
|
|
|
|
//if (DrawableDict != null)
|
|
|
|
|
//{
|
|
|
|
|
// MemoryUsage += DrawableDict.MemoryUsage;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
if ((DrawableDict != null) &&
|
|
|
|
|
(DrawableDict.Drawables != null) &&
|
|
|
|
|
(DrawableDict.Drawables.data_items != null) &&
|
|
|
|
|
(DrawableDict.Hashes != null))
|
|
|
|
|
{
|
|
|
|
|
Dict = new Dictionary<uint, Drawable>();
|
|
|
|
|
var drawables = DrawableDict.Drawables.data_items;
|
|
|
|
|
var hashes = DrawableDict.Hashes;
|
|
|
|
|
for (int i = 0; (i < drawables.Length) && (i < hashes.Length); i++)
|
|
|
|
|
{
|
|
|
|
|
var drawable = drawables[i];
|
|
|
|
|
var hash = hashes[i];
|
|
|
|
|
Dict[hash] = drawable;
|
|
|
|
|
drawable.Owner = this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; (i < drawables.Length) && (i < hashes.Length); i++)
|
|
|
|
|
{
|
|
|
|
|
var drawable = drawables[i];
|
|
|
|
|
var hash = hashes[i];
|
|
|
|
|
if ((drawable.Name == null) || (drawable.Name.EndsWith("#dd")))
|
|
|
|
|
{
|
|
|
|
|
string hstr = JenkIndex.TryGetString(hash);
|
|
|
|
|
if (!string.IsNullOrEmpty(hstr))
|
|
|
|
|
{
|
|
|
|
|
drawable.Name = hstr;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Drawables = Dict.Values.ToArray();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Loaded = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-28 10:13:45 +08:00
|
|
|
|
public byte[] Save()
|
|
|
|
|
{
|
|
|
|
|
byte[] data = ResourceBuilder.Build(DrawableDict, 165); //ydd is type/version 165...
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|
2020-01-18 01:20:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class YddXml : MetaXmlBase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public static string GetXml(YddFile ydd, string outputFolder = "")
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
sb.AppendLine(XmlHeader);
|
|
|
|
|
|
|
|
|
|
if (ydd?.DrawableDict != null)
|
|
|
|
|
{
|
2020-01-27 15:19:45 +08:00
|
|
|
|
DrawableDictionary.WriteXmlNode(ydd.DrawableDict, sb, 0, outputFolder);
|
2020-01-18 01:20:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-09-21 18:33:05 +08:00
|
|
|
|
}
|