From bd54479e3839a0b582fc0d60711eaaf566f4b00d Mon Sep 17 00:00:00 2001 From: Matthew Spencer Date: Wed, 28 Nov 2018 03:33:16 -0600 Subject: [PATCH] Allow ModTek to override the manifest for users with FlashPoint --- ModTek/ModTek.cs | 22 +++++++++++++++++++++- ModTek/Patches.cs | 15 +++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/ModTek/ModTek.cs b/ModTek/ModTek.cs index c91f7520..af50a3f1 100644 --- a/ModTek/ModTek.cs +++ b/ModTek/ModTek.cs @@ -24,6 +24,9 @@ public static class ModTek { public static VersionManifest cachedManifest = null; + // Lookup for all manifest entries that modtek adds + public static Dictionary modtekOverrides = null; + private static bool hasLoadedMods; //defaults to false // file/directory names @@ -1005,7 +1008,24 @@ internal static IEnumerator BuildCachedManifestLoop(VersionManif // Cache the completed manifest ModTek.cachedManifest = manifest; - + + try + { + if (manifest != null && ModTek.modEntries != null) + { + ModTek.modtekOverrides = manifest.Entries.Where(e => ModTek.modEntries.Any(m => e.Id == m.Id)) + // ToDictionary expects distinct keys, so take the last entry of each Id + .GroupBy(ks => ks.Id) + .Select(v => v.Last()) + .ToDictionary(ks => ks.Id); + } + Logger.Log("Built {0} modtek overrides", ModTek.modtekOverrides.Count()); + } + catch (Exception e) + { + Logger.Log("Failed to build overrides {0}", e); + } + yield break; } } diff --git a/ModTek/Patches.cs b/ModTek/Patches.cs index 99adf18e..817c7b18 100644 --- a/ModTek/Patches.cs +++ b/ModTek/Patches.cs @@ -153,6 +153,21 @@ public static bool Prefix(ref VersionManifest __result) } } + // Flashpoint (and presumably all future DLC) modify the manifest later + // Rather than trying to maintain a valid manifest, it's easier to just + // intercept the asset lookups, and provide a modtek asset if necessary + [HarmonyPatch(typeof(BattleTechResourceLocator), "EntryByID")] + public static class BattleTechResourceLocator_EntryByID_Patch + { + public static void Postfix(string id, ref VersionManifestEntry __result) + { + if (ModTek.modtekOverrides != null && ModTek.modtekOverrides.TryGetValue(id, out var entry)) + { + __result = entry; + } + } + } + // This will disable activateAfterInit from functioning for the Start() on the "Main" game object which activates the BattleTechGame object // This stops the main game object from loading immediately -- so work can be done beforehand [HarmonyPatch(typeof(ActivateAfterInit), "Start")]