From 6e2c81675e5556cd9bbee2477cb1c53b37becd28 Mon Sep 17 00:00:00 2001 From: dexy Date: Thu, 20 Dec 2018 22:35:19 +1100 Subject: [PATCH] Added basic DLC subpacks support --- .../GameFiles/FileTypes/DlcSetupFile.cs | 1 + CodeWalker.Core/GameFiles/GameFileCache.cs | 41 +++++++++++++++--- CodeWalker.Core/GameFiles/RpfManager.cs | 2 +- CodeWalker.Core/World/Space.cs | 42 +++++++++++-------- 4 files changed, 62 insertions(+), 24 deletions(-) diff --git a/CodeWalker.Core/GameFiles/FileTypes/DlcSetupFile.cs b/CodeWalker.Core/GameFiles/FileTypes/DlcSetupFile.cs index 43b47ee..760453a 100644 --- a/CodeWalker.Core/GameFiles/FileTypes/DlcSetupFile.cs +++ b/CodeWalker.Core/GameFiles/FileTypes/DlcSetupFile.cs @@ -21,6 +21,7 @@ namespace CodeWalker.GameFiles public bool isLevelPack { get; set; } public RpfFile DlcFile { get; set; } //used by GameFileCache + public List DlcSubpacks { get; set; } //used by GameFileCache public DlcContentFile ContentFile { get; set; } public void Load(XmlDocument doc) diff --git a/CodeWalker.Core/GameFiles/GameFileCache.cs b/CodeWalker.Core/GameFiles/GameFileCache.cs index 896868c..5da14c3 100644 --- a/CodeWalker.Core/GameFiles/GameFileCache.cs +++ b/CodeWalker.Core/GameFiles/GameFileCache.cs @@ -490,6 +490,21 @@ namespace CodeWalker.GameFiles DlcActiveRpfs.Add(dlcfile); + for (int i = 1; i <= setupfile.subPackCount; i++) + { + var subpackPath = dlcfile.Path.Replace("\\dlc.rpf", "\\dlc" + i.ToString() + ".rpf"); + var subpack = RpfMan.FindRpfFile(subpackPath); + if (subpack != null) + { + DlcActiveRpfs.Add(subpack); + + if (setupfile.DlcSubpacks == null) setupfile.DlcSubpacks = new List(); + setupfile.DlcSubpacks.Add(subpack); + } + } + + + string dlcname = GetDlcNameFromPath(dlcfile.Path); @@ -502,7 +517,7 @@ namespace CodeWalker.GameFiles //if (rpfkvp.Value.overlay) AddDlcOverlayRpf(rpfkvp.Key, umpath, setupfile, overlays); - AddDlcActiveMapRpfFile(rpfkvp.Key, phpath); + AddDlcActiveMapRpfFile(rpfkvp.Key, phpath, setupfile); } @@ -561,7 +576,7 @@ namespace CodeWalker.GameFiles //if (rpfdatafile.overlay) AddDlcOverlayRpf(dfn, rpfdatafile.filename, setupfile, overlays); - AddDlcActiveMapRpfFile(dfn, phpath); + AddDlcActiveMapRpfFile(dfn, phpath, setupfile); } else { @@ -608,7 +623,7 @@ namespace CodeWalker.GameFiles AddDlcOverlayRpf(fpath, umpath, setupfile, overlays); - AddDlcActiveMapRpfFile(fpath, phpath); + AddDlcActiveMapRpfFile(fpath, phpath, setupfile); } } } @@ -627,7 +642,7 @@ namespace CodeWalker.GameFiles } } - private void AddDlcActiveMapRpfFile(string vpath, string phpath) + private void AddDlcActiveMapRpfFile(string vpath, string phpath, DlcSetupFile setupfile) { vpath = vpath.ToLowerInvariant(); phpath = phpath.ToLowerInvariant(); @@ -684,10 +699,26 @@ namespace CodeWalker.GameFiles { string devname = setupfile.deviceName.ToLowerInvariant(); string fpath = GetDlcPlatformPath(path).ToLowerInvariant(); - string kpath = fpath.Replace(devname + ":\\", ""); + string kpath = fpath;//.Replace(devname + ":\\", ""); string dlcpath = setupfile.DlcFile.Path; fpath = fpath.Replace(devname + ":", dlcpath); fpath = fpath.Replace("x64:", dlcpath + "\\x64").Replace('/', '\\'); + if (setupfile.DlcSubpacks != null) + { + if (RpfMan.FindRpfFile(fpath) == null) + { + foreach (var subpack in setupfile.DlcSubpacks) + { + dlcpath = subpack.Path; + var tpath = kpath.Replace(devname + ":", dlcpath); + tpath = tpath.Replace("x64:", dlcpath + "\\x64").Replace('/', '\\'); + if (RpfMan.FindRpfFile(tpath) != null) + { + return GetDlcPatchedPath(tpath); + } + } + } + } return GetDlcPatchedPath(fpath); } private string GetDlcOverlayPath(string path, DlcSetupFile setupfile) diff --git a/CodeWalker.Core/GameFiles/RpfManager.cs b/CodeWalker.Core/GameFiles/RpfManager.cs index cadc31f..49a1b43 100644 --- a/CodeWalker.Core/GameFiles/RpfManager.cs +++ b/CodeWalker.Core/GameFiles/RpfManager.cs @@ -124,7 +124,7 @@ namespace CodeWalker.GameFiles private void AddRpfFile(RpfFile file, bool isdlc, bool ismod) { - isdlc = isdlc || (file.NameLower == "dlc.rpf") || (file.NameLower == "update.rpf"); + isdlc = isdlc || (file.NameLower == "update.rpf") || (file.NameLower.StartsWith("dlc") && file.NameLower.EndsWith(".rpf")); ismod = ismod || (file.Path.StartsWith("mods\\")); if (file.AllEntries != null) diff --git a/CodeWalker.Core/World/Space.cs b/CodeWalker.Core/World/Space.cs index 44ec6db..5e95911 100644 --- a/CodeWalker.Core/World/Space.cs +++ b/CodeWalker.Core/World/Space.cs @@ -420,19 +420,22 @@ namespace CodeWalker.World { AddRpfYnds(rpffile, yndentries); } - var updrpf = rpfman.FindRpfFile("update\\update.rpf"); //load nodes from patch area... - if (updrpf != null) + if (GameFileCache.EnableDlc) { - foreach (var rpffile in updrpf.Children) + var updrpf = rpfman.FindRpfFile("update\\update.rpf"); //load nodes from patch area... + if (updrpf != null) { - AddRpfYnds(rpffile, yndentries); + foreach (var rpffile in updrpf.Children) + { + AddRpfYnds(rpffile, yndentries); + } } - } - foreach (var dlcrpf in GameFileCache.DlcActiveRpfs) //load nodes from current dlc rpfs - { - foreach (var rpffile in dlcrpf.Children) + foreach (var dlcrpf in GameFileCache.DlcActiveRpfs) //load nodes from current dlc rpfs { - AddRpfYnds(rpffile, yndentries); + foreach (var rpffile in dlcrpf.Children) + { + AddRpfYnds(rpffile, yndentries); + } } } @@ -721,19 +724,22 @@ namespace CodeWalker.World { AddRpfYnvs(rpffile, ynventries); } - foreach (var dlcrpf in GameFileCache.DlcActiveRpfs) //load navmeshes from current dlc rpfs + if (GameFileCache.EnableDlc) { - foreach (var rpffile in dlcrpf.Children) + var updrpf = rpfman.FindRpfFile("update\\update.rpf"); //load navmeshes from patch area... + if (updrpf != null) { - AddRpfYnvs(rpffile, ynventries); + foreach (var rpffile in updrpf.Children) + { + AddRpfYnvs(rpffile, ynventries); + } } - } - var updrpf = rpfman.FindRpfFile("update\\update.rpf"); //load navmeshes from patch area... - if (updrpf != null) - { - foreach (var rpffile in updrpf.Children) + foreach (var dlcrpf in GameFileCache.DlcActiveRpfs) //load navmeshes from current dlc rpfs { - AddRpfYnvs(rpffile, ynventries); + foreach (var rpffile in dlcrpf.Children) + { + AddRpfYnvs(rpffile, ynventries); + } } }