static bool Prefix(string id, string type, ref VersionManifestAddendum __result, List <VersionManifestAddendum> ___addendums) { VersionManifestAddendum queryValue; if (!VersionManifestAddendumCache.FindInCache(id, type, out queryValue)) { queryValue = VersionManifestAddendumCache.FindInAddendums(id, type, ___addendums); } __result = queryValue; return(false); }
public static void Postfix(BattleTechResourceLocator __instance, ContentPackIndex ___contentPackIndex, ref Dictionary <BattleTechResourceType, Dictionary <string, VersionManifestEntry> > ___baseManifest, ref Dictionary <BattleTechResourceType, Dictionary <string, VersionManifestEntry> > ___contentPacksManifest, ref Dictionary <VersionManifestAddendum, Dictionary <BattleTechResourceType, Dictionary <string, VersionManifestEntry> > > ___addendumsManifest, Stopwatch __state) { Stopwatch sw = new Stopwatch(); sw.Start(); foreach (var entry in ModTek.AddBTRLEntries) { var versionManifestEntry = entry.GetVersionManifestEntry(); var resourceType = (BattleTechResourceType)Enum.Parse(typeof(BattleTechResourceType), entry.Type); // versionManifestEntry.AddToModTekManifest(resourceType); THIS WAS A NOP if (___contentPackIndex == null || ___contentPackIndex.IsResourceOwned(versionManifestEntry.Id)) { // add to baseManifest Dictionary <string, VersionManifestEntry> manifests = null; if (!___baseManifest.TryGetValue(resourceType, out manifests)) { manifests = new Dictionary <string, VersionManifestEntry>(); ___baseManifest.Add(resourceType, manifests); } if (manifests.ContainsKey(versionManifestEntry.Id)) { ___baseManifest[resourceType][versionManifestEntry.Id] = versionManifestEntry; } else { manifests.Add(versionManifestEntry.Id, versionManifestEntry); } if (ModTek.Config.EnableDebugLogging) { RLog.M.WL(1, "baseManifest add:" + resourceType + " " + entry.Id + " " + (versionManifestEntry == null?"null": versionManifestEntry.FilePath)); } } else { // add to contentPackManifest if (!___contentPacksManifest.ContainsKey(resourceType)) { ___contentPacksManifest.Add(resourceType, new Dictionary <string, VersionManifestEntry>()); } ___contentPacksManifest[resourceType][entry.Id] = versionManifestEntry; if (ModTek.Config.EnableDebugLogging) { RLog.M.WL(1, "contentPacksManifest add:" + resourceType + " " + entry.Id); } } if (string.IsNullOrEmpty(entry.AddToAddendum)) { continue; } // add to addendumsManifest var addendum = ModTek.CachedVersionManifest.GetAddendumByName(entry.AddToAddendum); //var addendum = __instance.GetAddendumByName(entry.AddToAddendum); if (addendum != null) { if (!___addendumsManifest.ContainsKey(addendum)) { if (ModTek.Config.EnableDebugLogging) { RLog.M.WL(1, "adding new enum:" + addendum.Name); } ___addendumsManifest.Add(addendum, new Dictionary <BattleTechResourceType, Dictionary <string, VersionManifestEntry> >()); } if (!___addendumsManifest[addendum].ContainsKey(resourceType)) { ___addendumsManifest[addendum].Add(resourceType, new Dictionary <string, VersionManifestEntry>()); } ___addendumsManifest[addendum][resourceType][entry.Id] = versionManifestEntry; // Invalidate the cache we've created for this addendum VersionManifestAddendumCache.InvalidateAddendum(addendum); if (ModTek.Config.EnableDebugLogging) { RLog.M.WL(1, "addendumsManifest[" + addendum.Name + "][" + resourceType + "][" + entry.Id + "] " + versionManifestEntry.FilePath); } } } sw.Stop(); //RLog.M.WL(0, $"BTRL ADD took: {sw.ElapsedMilliseconds}ms"); sw.Restart(); foreach (var entry in ModTek.RemoveBTRLEntries) { var resourceType = (BattleTechResourceType)Enum.Parse(typeof(BattleTechResourceType), entry.Type); // entry.RemoveFromModTekManifest(resourceType); THIS WAS A NOP if (___baseManifest.ContainsKey(resourceType) && ___baseManifest[resourceType].ContainsKey(entry.Id)) { ___baseManifest[resourceType].Remove(entry.Id); RLog.M.WL(1, "baseManifest remove:" + resourceType + " " + entry.Id); } if (___contentPacksManifest.ContainsKey(resourceType) && ___contentPacksManifest[resourceType].ContainsKey(entry.Id)) { ___contentPacksManifest[resourceType].Remove(entry.Id); RLog.M.WL(1, "contentPacksManifest remove:" + resourceType + " " + entry.Id); } var containingAddendums = ___addendumsManifest.Where(pair => pair.Value.ContainsKey(resourceType) && pair.Value[resourceType].ContainsKey(entry.Id)); foreach (var containingAddendum in containingAddendums) { RLog.M.WL(1, "remove addendumsManifest[" + resourceType + "][" + entry.Id + "]"); containingAddendum.Value[resourceType].Remove(entry.Id); // Invalidate the cache we've created for this addendum VersionManifestAddendumCache.InvalidateAddendum(containingAddendum.Key); } } sw.Stop(); __state.Stop(); if (ModTek.Config.EnableDebugLogging) { RLog.M.TWL(0, $"BattleTechResourceLocator.RefreshTypedEntries complete in {__state.ElapsedMilliseconds}ms"); } }