YPT/XML conversion progress

This commit is contained in:
dexy 2020-02-01 07:03:02 +11:00
parent 39eed4c2e9
commit b11d350294
4 changed files with 932 additions and 108 deletions

View File

@ -4655,6 +4655,57 @@ namespace CodeWalker.GameFiles
writer.Write(this.DrawablesCount2);
writer.Write(this.Unknown_3Ch);
}
public void WriteXml(StringBuilder sb, int indent, string ddsfolder)
{
if (Drawables?.data_items != null)
{
for (int i=0; i< Drawables.data_items.Length; i++)
{
var d = Drawables.data_items[i];
var h = (MetaHash)((i < (Hashes?.Length ?? 0)) ? Hashes[i] : 0);
YddXml.OpenTag(sb, indent, "Item");
YddXml.StringTag(sb, indent + 1, "Name", YddXml.XmlEscape(h.ToCleanString()));
d.WriteXml(sb, indent + 1, ddsfolder);
YddXml.CloseTag(sb, indent, "Item");
}
}
}
public void ReadXml(XmlNode node, string ddsfolder)
{
var drawables = new List<DrawableBase>();
var drawablehashes = new List<uint>();
var inodes = node.SelectNodes("Item");
if (inodes != null)
{
foreach (XmlNode inode in inodes)
{
var h = XmlMeta.GetHash(Xml.GetChildInnerText(inode, "Name"));
var d = new DrawableBase();
d.ReadXml(inode, ddsfolder);
drawables.Add(d);
drawablehashes.Add(h);
}
}
Hashes = drawablehashes.ToArray();
Drawables = new ResourcePointerArray64<DrawableBase>();
Drawables.data_items = drawables.ToArray();
}
public static void WriteXmlNode(DrawableBaseDictionary d, StringBuilder sb, int indent, string ddsfolder, string name = "DrawableDictionary")
{
if (d == null) return;
YddXml.OpenTag(sb, indent, name);
d.WriteXml(sb, indent + 1, ddsfolder);
YddXml.CloseTag(sb, indent, name);
}
public static DrawableBaseDictionary ReadXmlNode(XmlNode node, string ddsfolder)
{
if (node == null) return null;
var d = new DrawableBaseDictionary();
d.ReadXml(node, ddsfolder);
return d;
}
public override IResourceBlock[] GetReferences()
{

File diff suppressed because it is too large Load Diff

View File

@ -736,7 +736,7 @@ namespace CodeWalker.GameFiles
// reference data
//public ResourceSimpleArray<T> Entries;
public T[] data_items { get; private set; }
public T[] data_items { get; set; }
private ResourceSimpleArray<T> data_block;//used for saving.
@ -1395,9 +1395,11 @@ namespace CodeWalker.GameFiles
}
public ulong[] data_pointers { get; private set; }
public ulong[] data_pointers { get; set; }
public T[] data_items { get; set; }
public bool ManualPointerOverride = false;//use this to manually write data_pointers
public ResourcePointerArray64()
@ -1424,13 +1426,22 @@ namespace CodeWalker.GameFiles
public override void Write(ResourceDataWriter writer, params object[] parameters)
{
// update...
var list = new List<ulong>();
foreach (var x in data_items)
if (x != null)
list.Add((uint)x.FilePosition);
else
list.Add((uint)0);
data_pointers = list.ToArray();
if (ManualPointerOverride == false)
{
var list = new List<ulong>();
foreach (var x in data_items)
{
if (x != null)
{
list.Add((uint)x.FilePosition);
}
else
{
list.Add(0);
}
}
data_pointers = list.ToArray();
}
// write...
foreach (var x in data_pointers)
@ -1442,8 +1453,13 @@ namespace CodeWalker.GameFiles
{
var list = new List<IResourceBlock>();
foreach (var x in data_items)
list.Add(x);
if (ManualPointerOverride == false)
{
foreach (var x in data_items)
{
list.Add(x);
}
}
return list.ToArray();
}

View File

@ -1042,7 +1042,7 @@ namespace CodeWalker.Forms
{
items.Add(kvp);
}
//items.Sort((a, b) => { return a.Value?.Name?.CompareTo(b.Value?.Name ?? "") ?? 0; });
items.Sort((a, b) => { return ((MetaHash)a.Key).ToCleanString().CompareTo(((MetaHash)b.Key).ToCleanString()); });
foreach (var kvp in items)
{
AddDrawableTreeNode(kvp.Value, kvp.Key, check);