diff --git a/CodeWalker.csproj b/CodeWalker.csproj index 9b7e7d6..1025f1f 100644 --- a/CodeWalker.csproj +++ b/CodeWalker.csproj @@ -262,6 +262,7 @@ + diff --git a/GameFiles/FileTypes/GtxdFile.cs b/GameFiles/FileTypes/GtxdFile.cs new file mode 100644 index 0000000..8a27eba --- /dev/null +++ b/GameFiles/FileTypes/GtxdFile.cs @@ -0,0 +1,140 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CodeWalker.GameFiles +{ + [TypeConverter(typeof(ExpandableObjectConverter))] public class GtxdFile : GameFile, PackedFile + { + + public RbfFile Rbf { get; set; } + + + public Dictionary CMapParentTxds { get; set; } + + + + + public GtxdFile() : base(null, GameFileType.Gtxd) + { + } + public GtxdFile(RpfFileEntry entry) : base(entry, GameFileType.Gtxd) + { + } + + + + public void Load(byte[] data, RpfFileEntry entry) + { + RpfFileEntry = entry; + Name = entry.Name; + FilePath = Name; + + + if (entry.NameLower.EndsWith(".ymt")) + { + MemoryStream ms = new MemoryStream(data); + if (RbfFile.IsRBF(ms)) + { + Rbf = new RbfFile(); + var rbfstruct = Rbf.Load(ms); + + if (rbfstruct.Name == "CMapParentTxds") + { + LoadMapParentTxds(rbfstruct); + } + + Loaded = true; + return; + } + else + { + //not an RBF file... + } + } + else if (entry.NameLower.EndsWith(".meta")) + { + string xml = Encoding.UTF8.GetString(data); + LoadMapParentTxds(xml); + Loaded = true; + } + + + } + + + private void LoadMapParentTxds(RbfStructure rbfstruct) + { + + CMapParentTxds = new Dictionary(); + //StringBuilder sblist = new StringBuilder(); + foreach (var child in rbfstruct.Children) + { + var childstruct = child as RbfStructure; + if ((childstruct != null) && (childstruct.Name == "txdRelationships")) + { + foreach (var txdrel in childstruct.Children) + { + var txdrelstruct = txdrel as RbfStructure; + if ((txdrelstruct != null) && (txdrelstruct.Name == "item")) + { + string parentstr = string.Empty; + string childstr = string.Empty; + foreach (var item in txdrelstruct.Children) + { + var itemstruct = item as RbfStructure; + if ((itemstruct != null)) + { + var strbytes = itemstruct.Children[0] as RbfBytes; + string thisstr = string.Empty; + if (strbytes != null) + { + thisstr = Encoding.ASCII.GetString(strbytes.Value).Replace("\0", ""); + } + switch (item.Name) + { + case "parent": + parentstr = thisstr; + break; + case "child": + childstr = thisstr; + break; + } + } + + } + if ((!string.IsNullOrEmpty(parentstr)) && (!string.IsNullOrEmpty(childstr))) + { + if (!CMapParentTxds.ContainsKey(childstr)) + { + CMapParentTxds.Add(childstr, parentstr); + } + else + { + } + //sblist.AppendLine(childstr + ": " + parentstr); + } + } + } + } + } + //string alltxdmap = sblist.ToString(); + //if (!string.IsNullOrEmpty(alltxdmap)) + //{ + //} + + } + + + + private void LoadMapParentTxds(string xml) + { + //TODO... + } + + } +} diff --git a/GameFiles/GameFile.cs b/GameFiles/GameFile.cs index 146edf3..d03b626 100644 --- a/GameFiles/GameFile.cs +++ b/GameFiles/GameFile.cs @@ -69,6 +69,7 @@ namespace CodeWalker.GameFiles Rel = 13, Ywr = 14, Yvr = 15, + Gtxd = 16, } } diff --git a/GameFiles/GameFileCache.cs b/GameFiles/GameFileCache.cs index b003cfa..53e5483 100644 --- a/GameFiles/GameFileCache.cs +++ b/GameFiles/GameFileCache.cs @@ -940,9 +940,9 @@ namespace CodeWalker.GameFiles { try { - if (entry.NameLower == "gtxd.ymt") + if ((entry.NameLower == "gtxd.ymt") || (entry.NameLower == "gtxd.meta")) { - YmtFile ymt = RpfMan.GetFile(entry); + GtxdFile ymt = RpfMan.GetFile(entry); if (ymt.CMapParentTxds != null) { foreach (var kvp in ymt.CMapParentTxds) @@ -959,9 +959,6 @@ namespace CodeWalker.GameFiles } } } - else if (entry.NameLower == "gtxd.meta") //these still need to be handled! - { - } } catch (Exception ex) { @@ -973,25 +970,39 @@ namespace CodeWalker.GameFiles if (EnableDlc) { - //foreach (var dlcfile in DlcActiveRpfs) - //{ - // foreach (RpfEntry entry in dlcfile.AllEntries) - // { - // try - // { - // if (entry.NameLower == "gtxd.meta") //these still need to be handled! - // { - // //update\x64\dlcpacks\mpheist\dlc.rpf - // //update\x64\dlcpacks\mpluxe\dlc.rpf - // } - // } - // catch (Exception ex) - // { - // string errstr = entry.Path + "\n" + ex.ToString(); - // ErrorLog(errstr); - // } - // } - //} + foreach (var dlcfile in DlcActiveRpfs) + { + foreach (RpfEntry entry in dlcfile.AllEntries) + { + try + { + if (entry.NameLower == "gtxd.meta") + { + GtxdFile ymt = RpfMan.GetFile(entry); + if (ymt.CMapParentTxds != null) + { + foreach (var kvp in ymt.CMapParentTxds) + { + uint chash = JenkHash.GenHash(kvp.Key.ToLowerInvariant()); + uint phash = JenkHash.GenHash(kvp.Value.ToLowerInvariant()); + if (!parentTxds.ContainsKey(chash)) + { + parentTxds.Add(chash, phash); + } + else + { + } + } + } + } + } + catch (Exception ex) + { + string errstr = entry.Path + "\n" + ex.ToString(); + ErrorLog(errstr); + } + } + } }