Example #1
0
        public static bool Override_ProcessAsyncRequests(DataManager __instance, uint ___backgroundRequestsCurrentAllowedWeight)
        {
            if (UnpatchManager)
            {
                return(true);
            }
            if (background.Count < 0)
            {
                return(false);                     // Early abort before reflection
            }
            DataManager me = __instance;

            if (DebugLog)
            {
                Trace("Processing {0} background requests", background.Count);
            }
            foreach (DataManager.DataManagerLoadRequest request in background.Values)
            {
                request.RequestWeight.SetAllowedWeight(___backgroundRequestsCurrentAllowedWeight);
                DataManager.DataManagerLoadRequest.RequestState state = request.State;
                if (state == DataManager.DataManagerLoadRequest.RequestState.Processing)
                {
                    return(false);
                }
                if (state == DataManager.DataManagerLoadRequest.RequestState.RequestedAsync)
                {
                    if (request.IsMemoryRequest)
                    {
                        me.RemoveObjectOfType(request.ResourceId, request.ResourceType);
                    }
                    if (request.AlreadyLoaded)
                    {
                        if (!request.DependenciesLoaded(___backgroundRequestsCurrentAllowedWeight))
                        {
                            DataManager.ILoadDependencies dependencyLoader = request.TryGetDependencyLoader();
                            if (dependencyLoader != null)
                            {
                                request.RequestWeight.SetAllowedWeight(___backgroundRequestsCurrentAllowedWeight);
                                dependencyLoader.RequestDependencies(me, () => {
                                    if (dependencyLoader.DependenciesLoaded(request.RequestWeight.AllowedWeight))
                                    {
                                        request.NotifyLoadComplete();
                                    }
                                }, request);
                                isLoadingAsync.SetValue(me, true);
                                if (EnableTimeout)
                                {
                                    me.ResetAsyncRequestsTimeout();
                                }
                            }
                        }
                        else
                        {
                            request.NotifyLoadComplete();
                        }
                    }
                    else if (!request.ManifestEntryValid)
                    {
                        logger.LogError(string.Format("LoadRequest for {0} of type {1} has an invalid manifest entry. Any requests for this object will fail.", request.ResourceId, request.ResourceType));
                        request.NotifyLoadFailed();
                    }
                    else if (!request.RequestWeight.RequestAllowed)
                    {
                        request.NotifyLoadComplete();
                    }
                    else
                    {
                        isLoadingAsync.SetValue(me, true);
                        if (DebugLog)
                        {
                            Verbo("Loading Async {0}.", GetKey(request));
                        }
                        request.Load();
                        if (EnableTimeout)
                        {
                            me.ResetAsyncRequestsTimeout();
                        }
                    }
                    return(false);
                }
            }
            return(false);
        }
Example #2
0
 public static bool Override_ProcessRequests(DataManager __instance, uint ___foregroundRequestsCurrentAllowedWeight, ref bool ___isLoading)
 {
     try {
         if (UnpatchManager)
         {
             return(true);
         }
         if (queue.Count <= 0)
         {
             return(false);             // Early abort before reflection
         }
         DataManager me = __instance;
         int         lightLoad = 0, heavyLoad = 0;
         if (DebugLog)
         {
             Trace("Processing {0} foreground requests", queue.Count);
         }
         foreach (DataManager.DataManagerLoadRequest request in queue.ToArray())
         {
             if (EnableLoadCheck)
             {
                 if (lightLoad >= DataManager.MaxConcurrentLoadsLight && heavyLoad >= DataManager.MaxConcurrentLoadsHeavy)
                 {
                     break;
                 }
             }
             request.RequestWeight.SetAllowedWeight(___foregroundRequestsCurrentAllowedWeight);
             if (request.State == DataManager.DataManagerLoadRequest.RequestState.Requested)
             {
                 if (request.IsMemoryRequest)
                 {
                     me.RemoveObjectOfType(request.ResourceId, request.ResourceType);
                 }
                 if (request.AlreadyLoaded)
                 {
                     if (!request.DependenciesLoaded(___foregroundRequestsCurrentAllowedWeight))
                     {
                         DataManager.ILoadDependencies dependencyLoader = request.TryGetDependencyLoader();
                         if (dependencyLoader != null)
                         {
                             request.RequestWeight.SetAllowedWeight(___foregroundRequestsCurrentAllowedWeight);
                             dependencyLoader.RequestDependencies(me, () => {
                                 if (dependencyLoader.DependenciesLoaded(___foregroundRequestsCurrentAllowedWeight))
                                 {
                                     request.NotifyLoadComplete();
                                 }
                             }, request);
                             if (EnableLoadCheck)
                             {
                                 if (request.RequestWeight.RequestWeight == 10u)
                                 {
                                     if (DataManager.MaxConcurrentLoadsLight > 0)
                                     {
                                         lightLoad++;
                                     }
                                 }
                                 else if (DataManager.MaxConcurrentLoadsHeavy > 0)
                                 {
                                     heavyLoad++;
                                 }
                             }
                             ___isLoading = true;
                             if (EnableTimeout)
                             {
                                 me.ResetRequestsTimeout();
                             }
                         }
                     }
                     else
                     {
                         request.NotifyLoadComplete();
                     }
                 }
                 else
                 {
                     if (EnableLoadCheck)
                     {
                         if (lightLoad >= DataManager.MaxConcurrentLoadsLight && heavyLoad >= DataManager.MaxConcurrentLoadsHeavy)
                         {
                             break;
                         }
                     }
                     if (!request.ManifestEntryValid)
                     {
                         logger.LogError(string.Format("LoadRequest for {0} of type {1} has an invalid manifest entry. Any requests for this object will fail.", request.ResourceId, request.ResourceType));
                         request.NotifyLoadFailed();
                     }
                     else if (!request.RequestWeight.RequestAllowed)
                     {
                         request.NotifyLoadComplete();
                     }
                     else
                     {
                         if (EnableLoadCheck)
                         {
                             if (request.RequestWeight.RequestWeight == 10u)
                             {
                                 if (DataManager.MaxConcurrentLoadsLight > 0)
                                 {
                                     lightLoad++;
                                 }
                             }
                             else if (DataManager.MaxConcurrentLoadsHeavy > 0)
                             {
                                 heavyLoad++;
                             }
                         }
                         ___isLoading = true;
                         if (DebugLog)
                         {
                             Verbo("Loading {0}.", GetKey(request));
                         }
                         request.Load();
                         if (EnableTimeout)
                         {
                             me.ResetRequestsTimeout();
                         }
                     }
                 }
             }
         }
         return(false);
     }                 catch (Exception ex) { return(KillManagerPatch(__instance, ex)); }
 }