mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-12 22:30:44 -05:00
Partial revert of getnewbottemplate fix, added check to perform original method if bot profiles are already present
This commit is contained in:
parent
24d6f12e0e
commit
dd4366efcf
@ -6,6 +6,7 @@ using Aki.Reflection.Patching;
|
||||
using Aki.Reflection.Utils;
|
||||
using Aki.SinglePlayer.Models.RaidFix;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Aki.SinglePlayer.Patches.RaidFix
|
||||
{
|
||||
@ -50,12 +51,50 @@ namespace Aki.SinglePlayer.Patches.RaidFix
|
||||
&& parameters[2].Name == "withDelete");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// BotsPresets.GetNewProfile()
|
||||
/// </summary>
|
||||
[PatchPrefix]
|
||||
private static bool PatchPrefix(ref Task<Profile> __result, BotsPresets __instance, GClass626 data, ref bool withDelete)
|
||||
private static bool PatchPrefix(ref Task<Profile> __result, BotsPresets __instance, List<Profile> ___list_0, GClass626 data, ref bool withDelete)
|
||||
{
|
||||
withDelete = true;
|
||||
/*
|
||||
When client wants new bot and GetNewProfile() return null (if not more available templates or they don't satisfy 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
|
||||
*/
|
||||
|
||||
return true; // do original method
|
||||
if (___list_0?.Count > 0)
|
||||
{
|
||||
// List of profiles already has data, do original function
|
||||
return true; // Do original function
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// Force true to ensure bot profile is deleted after use
|
||||
_getNewProfileMethod.Invoke(__instance, new object[] { data, true });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogDebug($"getnewbot failed: {e.Message} {e.InnerException}");
|
||||
throw;
|
||||
}
|
||||
|
||||
// Load from server
|
||||
var source = data.PrepareToLoadBackend(1).Take(1).ToList();
|
||||
|
||||
var taskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
|
||||
var taskAwaiter = (Task<Profile>)null;
|
||||
taskAwaiter = PatchConstants.BackEndSession.LoadBots(source).ContinueWith(GetFirstResult, taskScheduler);
|
||||
|
||||
// Load bundles for bot profile
|
||||
var continuation = new BundleLoader(taskScheduler);
|
||||
__result = taskAwaiter.ContinueWith(continuation.LoadBundles, taskScheduler).Unwrap();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Profile GetFirstResult(Task<Profile[]> task)
|
||||
|
Loading…
x
Reference in New Issue
Block a user