Exemplo n.º 1
0
        public static bool MultiThreadDataHash(ref string __result, byte[] ___secret_key, params BattleTechResourceType[] typesToHash)
        {
            try {
                if (DebugLog)
                {
                    Verbo("Prepare to get data hash.");
                }
                SecretKey = ___secret_key;
                if (SecretKey == null)
                {
                    throw new NullReferenceException("DataManager.secret_key is null");
                }

                int manifestCounter = 0, pos = 0;
                // For me, over half the pre-Turbine time is spent on this new BattleTechResourceLocator.  Post-Turbine it consume most time!
                BattleTechResourceLocator battleTechResourceLocator = new BattleTechResourceLocator();
                Dictionary <int, VersionManifestEntry> manifestMap  = new Dictionary <int, VersionManifestEntry>(4000); // Vanilla has 900+. Mods may adds a lot more.
                foreach (BattleTechResourceType type in typesToHash)
                {
                    foreach (VersionManifestEntry versionManifestEntry in battleTechResourceLocator.AllEntriesOfResource(type))
                    {
                        manifestMap.Add(manifestCounter++, versionManifestEntry);
                    }
                }
                battleTechResourceLocator = null;

                Dictionary <int, byte[]> hashMap = new Dictionary <int, byte[]>();
                RunHashs(manifestMap, hashMap);

                byte[] allHash = new byte[HashSize * hashMap.Count];
                for (int i = 0; i < manifestCounter; i++)
                {
                    if (!hashMap.TryGetValue(i, out byte[] hash))
 public static void Postfix(BattleTechResourceLocator __instance, BattleTechResourceType type, VersionManifestAddendum addendum, ref VersionManifestEntry[] __result)
 {
     RLog.M.TWL(0, "BattleTechResourceLocator.AllEntriesOfResourceFromAddendum " + addendum.Name + " type:" + type);
     RLog.M.TWL(0, "BattleTechResourceLocator.AllEntriesOfResourceFromAddendum " + addendum.Name + " type:" + type);
     foreach (VersionManifestEntry entry in __result)
     {
         RLog.M.WL(1, entry.FileName);
     }
 }
        public static void Prefix(BattleTechResourceLocator __instance)
        {
            RLog.M.TWL(0, "BattleTechResourceLocator.RefreshTypedEntries");
            VersionManifest versionManifest = __instance.manifest();

            if (versionManifest != ModTek.CachedVersionManifest)
            {
                RLog.M.TWL(0, "WARNING! STRANGE BEHAVIOR cachedManifest does not much locator manifest. Resolving");
                __instance.manifest(ModTek.CachedVersionManifest);
            }
        }
Exemplo n.º 4
0
        public static void Prefix(BattleTechResourceLocator __instance, ref Stopwatch __state, int ___typedEntriesCount)
        {
            __state = new Stopwatch();
            __state.Start();

            VersionManifest versionManifest = __instance.manifest();

            if (ModTek.Config.EnableDebugLogging)
            {
                RLog.M.TWL(0, "BattleTechResourceLocator.RefreshTypedEntries");
                RLog.M.TWL(0, $"  typedEntriesCount: {___typedEntriesCount}  versionManifest.Count: {versionManifest.Count}");
                RLog.M.TWL(0, $"  addBTRLEntries: {ModTek.AddBTRLEntries.Count}  removeBTRLEntries: {ModTek.RemoveBTRLEntries.Count}");
            }


            if (versionManifest != ModTek.CachedVersionManifest)
            {
                RLog.M.TWL(0, "WARNING! STRANGE BEHAVIOR cachedManifest does not much locator manifest. Resolving");
                __instance.manifest(ModTek.CachedVersionManifest);
            }
        }
        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)
        {
            foreach (var entry in ModTek.AddBTRLEntries)
            {
                var versionManifestEntry = entry.GetVersionManifestEntry();
                var resourceType         = (BattleTechResourceType)Enum.Parse(typeof(BattleTechResourceType), entry.Type);
                versionManifestEntry.AddToModTekManifest(resourceType);

                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);
                    }

                    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;
                    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))
                    {
                        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;
                    RLog.M.WL(1, "addendumsManifest[" + addendum.Name + "][" + resourceType + "][" + entry.Id + "] " + versionManifestEntry.FilePath);
                }
            }

            foreach (var entry in ModTek.RemoveBTRLEntries)
            {
                var resourceType = (BattleTechResourceType)Enum.Parse(typeof(BattleTechResourceType), entry.Type);
                entry.RemoveFromModTekManifest(resourceType);

                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);
                }
            }
        }
 private static void manifest(this BattleTechResourceLocator locator, VersionManifest manifest)
 {
     f_manifest.SetValue(locator, manifest);
 }
 private static VersionManifest manifest(this BattleTechResourceLocator locator)
 {
     return((VersionManifest)f_manifest.GetValue(locator));
 }
Exemplo n.º 8
0
        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");
            }
        }