0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 07:30:43 -05:00
modules/project/SPT.Custom/Patches/BotDifficultyPatch.cs
2024-10-03 10:28:48 +01:00

37 lines
1.1 KiB
C#

using SPT.Custom.Utils;
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
using EFT;
using EFT.UI;
using System.Reflection;
namespace SPT.Custom.Patches
{
public class BotDifficultyPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
const string methodName = "LoadDifficultyStringInternal";
const BindingFlags flags = BindingFlags.Public | BindingFlags.Static;
return PatchConstants.EftTypes.SingleCustom(x => x.GetMethod(methodName, flags) != null)
.GetMethod(methodName, flags);
}
[PatchPrefix]
public static bool PatchPrefix(ref string __result, BotDifficulty botDifficulty, WildSpawnType role)
{
__result = DifficultyManager.Get(botDifficulty, role);
var resultIsNullEmpty = string.IsNullOrWhiteSpace(__result);
if (resultIsNullEmpty)
{
ConsoleScreen.LogError($"Unable to get difficulty settings for {role} {botDifficulty}");
return true; // Do original method
}
return false; // Skip original
}
}
}