コード例 #1
0
        public static bool Prefix(ref Profile __result, object __instance, BotData data)
        {
            List <Profile> profiles = profilesField(__instance);

            if (profiles.Count > 0)
            {
                // second parameter makes client remove used profiles
                __result = data.ChooseProfile(profiles, true);
            }
            else
            {
                __result = null;
            }

            return(false);
        }
コード例 #2
0
        public static bool Prefix(ref Task <Profile> __result, BotsPresets __instance, BotData data)
        {
            /*
             *  in short when client wants new bot and GetNewProfile() return null (if not more available templates or they don't satisfied by Role and Difficulty condition)
             *  then client gets new piece of WaveInfo collection (with Limit = 30 by default) and make request to server
             *  but use only first value in response (this creates a lot of garbage and cause freezes)
             *  after patch we request only 1 template from server
             *
             *  along with other patches this one causes to call data.PrepareToLoadBackend(1) gets the result with required role and difficulty:
             *  new[] { new WaveInfo() { Limit = 1, Role = role, Difficulty = difficulty } }
             *  then perform request to server and get only first value of resulting single element collection
             */

            var session = _sessionField(__instance);

            if (session == null)
            {
                throw new InvalidOperationException("Something went wrong. Where is session?");
            }

            Task <Profile> taskAwaiter   = null;
            TaskScheduler  taskScheduler = TaskScheduler.FromCurrentSynchronizationContext();

            // try get profile from cache
            var profile = _getNewProfileFunc(__instance, data);

            if (profile == null)
            {
                // load from server
                Debug.LogError("EmuTarkov.SinglePlayer: Loading bot profile from server");

                List <WaveInfo> source = data.PrepareToLoadBackend(1).ToList();
                taskAwaiter = session.LoadBots(source)
                              .ContinueWith(GetFirstResult, taskScheduler);
            }
            else
            {
                // return cached profile
                Debug.LogError("EmuTarkov.SinglePlayer: Loading bot profile from cache");

                taskAwaiter = Task.FromResult(profile);
            }

            // load bundles for bot profile
            var continuation = new Continuation(taskScheduler);

            __result = taskAwaiter
                       .ContinueWith(continuation.LoadBundles, taskScheduler)
                       .Unwrap();

            return(false);
        }