Exemplo n.º 1
0
        public static T LoadResource <T>(BattleTechResourceType resourceType, string resourceId, TimeSpan?timeout = null)
            where T : class
        {
            TimeSpan timeoutNotNull = timeout ?? TimeSpan.FromMinutes(1);

            DateTime errorTime = DateTime.Now + timeoutNotNull;

            T resource = null;

            GameInstance gameInstance = UnityGameInstance.BattleTechGame;

            DataManager dataManager = gameInstance.DataManager;

            LoadRequest loadRequest = dataManager.CreateLoadRequest(null, false);

            loadRequest.AddLoadRequest <T>(resourceType, resourceId,
                                           (s, resourceReturned) =>
            {
                resource = resourceReturned;
            }, false);
            loadRequest.ProcessRequests(10u);
            do
            {
                dataManager.Update(UnityEngine.Time.deltaTime);
                if (DateTime.Now > errorTime)
                {
                    throw new Exception("Failed to load resource: " + resourceId);
                }
            } while (resource is null);

            return(resource);
        }
Exemplo n.º 2
0
        private static bool GraduateBackgroundRequest(DataManager me, BattleTechResourceType resourceType, string id)
        {
            string key = GetKey(resourceType, id);

            if (!background.TryGetValue(key, out DataManager.DataManagerLoadRequest dataManagerLoadRequest))
            {
                return(false);
            }
            if (DebugLog)
            {
                Info("Graduating {0} ({1}) from background to foreground.", GetKey(dataManagerLoadRequest), dataManagerLoadRequest.GetType());
            }
            dataManagerLoadRequest.SetAsync(false);
            dataManagerLoadRequest.ResetRequestState();
            background.Remove(key);
            foreground.Add(key, dataManagerLoadRequest);
            if (LoadingQueue && !dataManagerLoadRequest.IsComplete())
            {
                foregroundLoading.Add(dataManagerLoadRequest);
            }
            bool wasLoadingAsync = (bool)isLoadingAsync.GetValue(me);
            bool nowLoadingAsync = !CheckAsyncRequestsComplete();

            if (nowLoadingAsync != wasLoadingAsync)
            {
                isLoadingAsync.SetValue(me, nowLoadingAsync);
                if (wasLoadingAsync)
                {
                    SaveCache.Invoke(me, null);
                    background.Clear();
                    center.PublishMessage(new DataManagerAsyncLoadCompleteMessage());
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        public static void LogLoadRequest(BattleTechResourceType resourceType, string identifier, bool allowRequestStacking)
        {
            logger.Log($"LOAD REQUEST for type: {resourceType}  id: {identifier}  with allowStacking: {allowRequestStacking}");
            StackTrace st = new StackTrace();

            logger.Log($" ST: {st}");
        }
 public static void RemoveFromModTekManifest(this VersionManifestEntry entry, BattleTechResourceType type)
 {
     return;
     //if (modtekManifest.TryGetValue(type, out Dictionary<string, VersionManifestEntry> manifests))
     //{
     //    string id = entry.Id.ToUpper(CultureInfo.InvariantCulture);
     //    manifests.Remove(id);
     //}
 }
Exemplo n.º 5
0
        public void RequestResourcesAndProcess(BattleTechResourceType resourceType, string resourceId, bool filterByOwnership = false)
        {
            LoadRequest loadRequest = UnityGameInstance.BattleTechGame.DataManager.CreateLoadRequest(delegate(LoadRequest request) {
                Main.LogDebug($"[RequestResourcesAndProcess] Finished load request for {resourceId}");
            }, filterByOwnership);

            loadRequest.AddBlindLoadRequest(resourceType, resourceId);
            loadRequest.ProcessRequests(1000u);
        }
 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);
     }
 }
Exemplo n.º 7
0
 static DescriptionDef GetObjectDescriptionByType(BattleTechResourceType type, object theObject)
 {
     return(type switch
     {
         BattleTechResourceType.AmmunitionBoxDef => ((AmmunitionBoxDef)theObject).Description,
         BattleTechResourceType.UpgradeDef => ((UpgradeDef)theObject).Description,
         BattleTechResourceType.HeatSinkDef => ((HeatSinkDef)theObject).Description,
         BattleTechResourceType.JumpJetDef => ((JumpJetDef)theObject).Description,
         BattleTechResourceType.WeaponDef => ((WeaponDef)theObject).Description,
         BattleTechResourceType.MechDef => ((MechDef)theObject).Description,
         _ => throw new InvalidProgramException($"BattleTechResourceType [{type.ToString()}] unhandled.")
     });
Exemplo n.º 8
0
        public void RequestResourcesAndProcess(BattleTechResourceType resourceType, string resourceId, bool filterByOwnership = false)
        {
            LoadRequest loadRequest = UnityGameInstance.BattleTechGame.DataManager.CreateLoadRequest(delegate(LoadRequest request) {
                Main.LogDebug($"[RequestResourcesAndProcess] Finished load request for {resourceId}");
            }, filterByOwnership);

            loadRequest.AddBlindLoadRequest(resourceType, resourceId);

            // Without 1000u this does not work for my usecase
            // Data loading has been updated for the Main Menu loads so it no longer should cause deadlocks
            loadRequest.ProcessRequests(1000u);
        }
Exemplo n.º 9
0
 public ProcGenStoreItem(BattleTechResourceType type, string id, DateTime?appearanceDate, TagSet tagSet,
                         ProcGenStoreContentFeatureSettings.RarityBracket rarityBracket, List <string> requiredTags,
                         List <string> restrictedTags, bool descriptionPurchasable)
 {
     Type = type;
     Id   = id;
     MinAppearanceDate = appearanceDate;
     TagSet            = tagSet;
     RarityBracket     = rarityBracket;
     RequiredTags      = requiredTags;
     RestrictedTags    = restrictedTags;
     Purchasable       = descriptionPurchasable;
 }
Exemplo n.º 10
0
 public static bool Prefix_RequestResource_Internal(DataManager __instance, BattleTechResourceType resourceType, string identifier)
 {
     if (string.IsNullOrEmpty(identifier) || (identifier == lastIdentifier && resourceType == lastResourceType))
     {
         if (DebugLog)
         {
             Verbo("Skipping empty or dup resource {0} {1}", resourceType, identifier);
         }
         return(false);
     }
     lastResourceType = resourceType;
     lastIdentifier   = identifier;
     return(true);
 }
Exemplo n.º 11
0
        static TagSet GetTagsByType(BattleTechResourceType type, object theObject)
        {
            switch (type)
            {
            case BattleTechResourceType.AmmunitionBoxDef: return(((AmmunitionBoxDef)theObject).ComponentTags);

            case BattleTechResourceType.UpgradeDef: return(((UpgradeDef)theObject).ComponentTags);

            case BattleTechResourceType.HeatSinkDef: return(((HeatSinkDef)theObject).ComponentTags);

            case BattleTechResourceType.JumpJetDef: return(((JumpJetDef)theObject).ComponentTags);

            case BattleTechResourceType.WeaponDef: return(((WeaponDef)theObject).ComponentTags);

            case BattleTechResourceType.MechDef: return(((MechDef)theObject).MechTags);

            default:
                throw new InvalidProgramException($"BattleTechResourceType [{type.ToString()}] unhandled.");
            }
        }
Exemplo n.º 12
0
 public static void Skip_DuplicateRequestCompleteMessage(DataManagerRequestCompleteMessage __instance)
 {
     if (String.IsNullOrEmpty(__instance.ResourceId))
     {
         __instance.hasBeenPublished = true; // Skip publishing empty id
         return;
     }
     if (lastComplete == __instance.ResourceId && lastCompleteType == __instance.ResourceType)
     {
         if (DebugLog)
         {
             Verbo("Skipping successive DataManagerRequestCompleteMessage {0} {1}", __instance.ResourceType, __instance.ResourceId);
         }
         __instance.hasBeenPublished = true;
     }
     else
     {
         lastComplete     = __instance.ResourceId;
         lastCompleteType = __instance.ResourceType;
     }
 }
Exemplo n.º 13
0
 public static void Postfix(string id, BattleTechResourceType type, bool filterByOwnership, ref VersionManifestEntry __result)
 {
     RLog.M.TWL(0, "BattleTechResourceLocator.EntryByID " + type + " " + id);
     if (__result == null)
     {
         RLog.M.WL(1, "can't find in internal manifest");
         if (modtekManifest.TryGetValue(type, out Dictionary <string, VersionManifestEntry> manifests))
         {
             id = id.ToUpper(CultureInfo.InvariantCulture);
             if (manifests.TryGetValue(id, out VersionManifestEntry entry))
             {
                 __result = entry;
                 RLog.M.WL(1, "found in external manifest", true);
             }
             else
             {
                 RLog.M.WL(1, "can't find in external manifest:" + manifests.Count);
             }
         }
         else
         {
         }
     }
 }
Exemplo n.º 14
0
 public static bool Override_RequestResourceAsync_Internal(DataManager __instance, BattleTechResourceType resourceType, string identifier, PrewarmRequest prewarm, uint ___backgroundRequestsCurrentAllowedWeight)
 {
     try {
         if (UnpatchManager || string.IsNullOrEmpty(identifier))
         {
             return(false);
         }
         DataManager me  = __instance;
         string      key = GetKey(resourceType, identifier);
         background.TryGetValue(key, out DataManager.DataManagerLoadRequest dataManagerLoadRequest);
         if (dataManagerLoadRequest != null)
         {
             if (dataManagerLoadRequest.State == DataManager.DataManagerLoadRequest.RequestState.Complete)
             {
                 if (!dataManagerLoadRequest.DependenciesLoaded(___backgroundRequestsCurrentAllowedWeight))
                 {
                     dataManagerLoadRequest.ResetRequestState();
                 }
                 else
                 {
                     dataManagerLoadRequest.NotifyLoadComplete();
                 }
             }
             else
             {
                 if (DebugLog)
                 {
                     Warn("Cannot move {0} to top of background queue.", GetKey(dataManagerLoadRequest));
                 }
                 // Move to top of queue. Not supported by HashTable.
                 //backgroundRequest.Remove( dataManagerLoadRequest );
                 //backgroundRequest.Insert( 0, dataManagerLoadRequest );
             }
             return(false);
         }
         bool isForeground = foreground.ContainsKey(key);
         bool isTemplate   = identifier.ToLowerInvariant().Contains("template");
         if (!isForeground && !isTemplate)
         {
             dataManagerLoadRequest = (DataManager.DataManagerLoadRequest)CreateByResourceType.Invoke(me, new object[] { resourceType, identifier, prewarm });
             dataManagerLoadRequest.SetAsync(true);
             if (DebugLog)
             {
                 Info("Queued Async: {0} ({1}) ", key, dataManagerLoadRequest.GetType());
             }
             background.Add(key, dataManagerLoadRequest);
         }
         return(false);
     }                 catch (Exception ex) { return(KillManagerPatch(__instance, ex)); }
 }
Exemplo n.º 15
0
        public static bool GetAllChassis(bool showMechParts, ref List <ChassisDef> __result, SimGameState __instance)
        {
            __result = new List <ChassisDef>();
            ChassisHandler.ClearParts();
            List <string> allInventoryStrings = __instance.GetAllInventoryStrings();

            foreach (string text in allInventoryStrings)
            {
                int count = __instance.CompanyStats.GetValue <int>(text);
                if (count >= 1)
                {
                    string[] array = text.Split(new char[]
                    {
                        '.'
                    });
                    if (array[1] != "MECHPART")
                    {
                        BattleTechResourceType battleTechResourceType =
                            (BattleTechResourceType)Enum.Parse(typeof(BattleTechResourceType), array[1]);
                        if (battleTechResourceType == BattleTechResourceType.MechDef)
                        {
                            var cdef = array[2];
                            var mdef = array[2].Replace("chassisdef", "mechdef");

                            if (__instance.DataManager.Exists(BattleTechResourceType.ChassisDef, cdef) &&
                                __instance.DataManager.Exists(BattleTechResourceType.MechDef, mdef))
                            {
                                var mech = __instance.DataManager.MechDefs.Get(mdef);
                                __result.Add(mech.Chassis);
                                ChassisHandler.RegisterMechDef(mech);
                            }
                            else
                            {
                                Control.LogError($"ERROR: {cdef}/{mdef} not found");
                            }
                        }
                    }
                    else
                    {
                        if (__instance.DataManager.Exists(BattleTechResourceType.MechDef, array[2]))
                        {
                            var mdef = __instance.DataManager.MechDefs.Get(array[2]);
                            if (showMechParts)
                            {
                                var chassisDef = new ChassisDef(mdef.Chassis)
                                {
                                    DataManager = __instance.DataManager
                                };
                                chassisDef.Refresh();
                                chassisDef.MechPartCount = count;
                                chassisDef.MechPartMax   = __instance.Constants.Story.DefaultMechPartMax;
                                __result.Add(chassisDef);
                            }
                            ChassisHandler.RegisterMechDef(mdef, count);
                        }
                        else
                        {
                            Control.LogError($"ERROR: {array[2]} not found");
                            if (show)
                            {
                                Control.LogError($"AllMechDefs:");
                                foreach (var pair in __instance.DataManager.MechDefs)
                                {
                                    Control.LogError($"-- {pair.Key}: {(pair.Value == null ? "null" : "exist")}");
                                }

                                show = false;
                            }
                        }
                    }
                }
            }

            //ChassisHandler.ShowInfo();
            return(false);
        }
Exemplo n.º 16
0
 internal static string GetKey(BattleTechResourceType resourceType, string id)
 {
     return((int)resourceType + "_" + id);
 }
Exemplo n.º 17
0
 public static bool Override_GraduateBackgroundRequest(DataManager __instance, ref bool __result, BattleTechResourceType resourceType, string id)
 {
     try {
         if (UnpatchManager)
         {
             return(true);
         }
         __result = GraduateBackgroundRequest(__instance, resourceType, id);
         return(false);
     }                 catch (Exception ex) { return(KillManagerPatch(__instance, ex)); }
 }
Exemplo n.º 18
0
 public static void AddToModTekManifest(this VersionManifestEntry versionManifestEntry, BattleTechResourceType resourceType)
 {
     return;
     //Dictionary<string, VersionManifestEntry> manifests = null;
     //if (!modtekManifest.TryGetValue(resourceType, out manifests))
     //{
     //    manifests = new Dictionary<string, VersionManifestEntry>();
     //    modtekManifest.Add(resourceType, manifests);
     //}
     //string id = versionManifestEntry.Id.ToUpper(CultureInfo.InvariantCulture);
     //if (manifests.ContainsKey(id))
     //{
     //    modtekManifest[resourceType][id] = versionManifestEntry;
     //}
     //else
     //{
     //    manifests.Add(id, versionManifestEntry);
     //}
 }
Exemplo n.º 19
0
 public static bool Override_RequestResource_Internal(DataManager __instance, BattleTechResourceType resourceType, string identifier, PrewarmRequest prewarm, bool allowRequestStacking, ref bool ___isLoading)
 {
     try {
         if (UnpatchManager || string.IsNullOrEmpty(identifier))
         {
             return(false);
         }
         // Quickly skip duplicate request
         if (resourceType == lastResourceType && identifier == lastIdentifier)
         {
             return(false);
         }
         lastResourceType = resourceType;
         lastIdentifier   = identifier;
         DataManager me  = __instance;
         string      key = GetKey(resourceType, identifier);
         if (monitoringMech != null)
         {
             LogDependee(monitoringMech, key);
         }
         foreground.TryGetValue(key, out DataManager.DataManagerLoadRequest dataManagerLoadRequest);
         if (dataManagerLoadRequest != null)
         {
             if (dataManagerLoadRequest.State != DataManager.DataManagerLoadRequest.RequestState.Complete || !dataManagerLoadRequest.DependenciesLoaded(dataManagerLoadRequest.RequestWeight.RequestWeight))
             {
                 if (allowRequestStacking)
                 {
                     dataManagerLoadRequest.IncrementCacheCount();
                 }
             }
             else
             {
                 NotifyFileLoaded(me, dataManagerLoadRequest, ref ___isLoading);
             }
             return(false);
         }
         bool movedToForeground = GraduateBackgroundRequest(me, resourceType, identifier);
         bool skipLoad          = false;
         bool isTemplate        = identifier.ToLowerInvariant().Contains("template");
         if (!movedToForeground && !skipLoad && !isTemplate)
         {
             dataManagerLoadRequest = (DataManager.DataManagerLoadRequest)CreateByResourceType.Invoke(me, new object[] { resourceType, identifier, prewarm });
             if (foreground.Count <= 0)
             {
                 Info("Starting new queue");
                 stopwatch.Start();
             }
             if (DebugLog)
             {
                 Verbo("Queued: {0} ({1})", key, dataManagerLoadRequest.GetType());
             }
             //if ( key == "19_CombatGameConstants" ) Info( Logger.Stacktrace );
             foreground.Add(key, dataManagerLoadRequest);
             if (LoadingQueue && !dataManagerLoadRequest.IsComplete())
             {
                 foregroundLoading.Add(dataManagerLoadRequest);
             }
         }
         return(false);
     }                 catch (Exception ex) { return(KillManagerPatch(__instance, ex)); }
 }