From c038c9fced0862c6d704d05d4ae152c6c60f4c44 Mon Sep 17 00:00:00 2001 From: Dev Date: Fri, 7 Jul 2023 16:15:22 +0100 Subject: [PATCH] Fix bots not spawning: Correctly look for public method + force bot to be cleared from client cache on spawn --- .../Patches/RaidFix/GetNewBotTemplatesPatch.cs | 12 ++++++++---- .../Patches/RaidFix/RemoveUsedBotProfilePatch.cs | 3 +-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/project/Aki.SinglePlayer/Patches/RaidFix/GetNewBotTemplatesPatch.cs b/project/Aki.SinglePlayer/Patches/RaidFix/GetNewBotTemplatesPatch.cs index 7450bfe..05b24a5 100644 --- a/project/Aki.SinglePlayer/Patches/RaidFix/GetNewBotTemplatesPatch.cs +++ b/project/Aki.SinglePlayer/Patches/RaidFix/GetNewBotTemplatesPatch.cs @@ -23,8 +23,12 @@ namespace Aki.SinglePlayer.Patches.RaidFix public GetNewBotTemplatesPatch() { - _getNewProfileMethod = typeof(BotsPresets) - .GetMethod(nameof(BotsPresets.GetNewProfile), PatchConstants.PrivateFlags); + var desiredType = typeof(BotsPresets); + _getNewProfileMethod = desiredType + .GetMethod(nameof(BotsPresets.GetNewProfile), PatchConstants.PublicFlags); + + Logger.LogDebug($"{this.GetType().Name} Type: {desiredType?.Name}"); + Logger.LogDebug($"{this.GetType().Name} Method: {_getNewProfileMethod?.Name}"); } protected override MethodBase GetTargetMethod() @@ -43,7 +47,7 @@ namespace Aki.SinglePlayer.Patches.RaidFix } [PatchPrefix] - private static bool PatchPrefix(ref Task __result, BotsPresets __instance, IBotData data) + private static bool PatchPrefix(ref Task __result, BotsPresets __instance, GClass626 data, bool withDelete) { /* in short when client wants new bot and GetNewProfile() return null (if not more available templates or they don't satisfy by Role and Difficulty condition) @@ -58,7 +62,7 @@ namespace Aki.SinglePlayer.Patches.RaidFix var taskScheduler = TaskScheduler.FromCurrentSynchronizationContext(); var taskAwaiter = (Task)null; - var profile = (Profile)_getNewProfileMethod.Invoke(__instance, new object[] { data }); + var profile = (Profile)_getNewProfileMethod.Invoke(__instance, new object[] { data, true }); // load from server var source = data.PrepareToLoadBackend(1).ToList(); diff --git a/project/Aki.SinglePlayer/Patches/RaidFix/RemoveUsedBotProfilePatch.cs b/project/Aki.SinglePlayer/Patches/RaidFix/RemoveUsedBotProfilePatch.cs index f8a727f..4740b12 100644 --- a/project/Aki.SinglePlayer/Patches/RaidFix/RemoveUsedBotProfilePatch.cs +++ b/project/Aki.SinglePlayer/Patches/RaidFix/RemoveUsedBotProfilePatch.cs @@ -2,7 +2,6 @@ using Aki.Reflection.Patching; using Aki.Reflection.Utils; using EFT; using System; -using System.Collections.Generic; using System.Linq; using System.Reflection; @@ -21,7 +20,7 @@ namespace Aki.SinglePlayer.Patches.RaidFix _flags = BindingFlags.Instance | BindingFlags.NonPublic; _targetInterface = PatchConstants.EftTypes.Single(IsTargetInterface); - _targetType = PatchConstants.EftTypes.Single(IsTargetType); + _targetType = typeof(BotsPresets); _profilesField = _targetType.GetField("list_0", _flags); }