Skip to content

Commit

Permalink
Merge pull request #4 from m22spencer/master
Browse files Browse the repository at this point in the history
Allow ModTek to override the manifest for users with FlashPoint
  • Loading branch information
janxious authored Nov 29, 2018
2 parents a462138 + bd54479 commit 595240b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
22 changes: 21 additions & 1 deletion ModTek/ModTek.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public static class ModTek
{
public static VersionManifest cachedManifest = null;

// Lookup for all manifest entries that modtek adds
public static Dictionary<string, VersionManifestEntry> modtekOverrides = null;

private static bool hasLoadedMods; //defaults to false

// file/directory names
Expand Down Expand Up @@ -1005,7 +1008,24 @@ internal static IEnumerator<ProgressReport> 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;
}
}
Expand Down
15 changes: 15 additions & 0 deletions ModTek/Patches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit 595240b

Please sign in to comment.