2024-05-31 22:00:29 +01:00
|
|
|
using Comfort.Common;
|
|
|
|
using EFT;
|
2024-05-21 19:10:17 +01:00
|
|
|
using SPT.Common.Http;
|
|
|
|
using SPT.Reflection.Patching;
|
|
|
|
using SPT.Reflection.Utils;
|
2023-03-03 18:52:31 +00:00
|
|
|
using System.Reflection;
|
|
|
|
|
2024-05-21 19:10:17 +01:00
|
|
|
namespace SPT.SinglePlayer.Patches.RaidFix
|
2023-03-03 18:52:31 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Alter the max bot cap with value stored in server, if value is -1, use existing value
|
|
|
|
/// </summary>
|
2024-03-02 15:50:50 +00:00
|
|
|
public class MaxBotPatch : ModulePatch
|
2023-03-03 18:52:31 +00:00
|
|
|
{
|
|
|
|
protected override MethodBase GetTargetMethod()
|
|
|
|
{
|
|
|
|
const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
|
|
|
|
const string methodName = "SetSettings";
|
2024-01-13 22:08:29 +00:00
|
|
|
var desiredType = PatchConstants.EftTypes.SingleCustom(x => x.GetMethod(methodName, flags) != null && IsTargetMethod(x.GetMethod(methodName, flags)));
|
2023-03-03 18:52:31 +00:00
|
|
|
var desiredMethod = desiredType.GetMethod(methodName, flags);
|
|
|
|
|
|
|
|
Logger.LogDebug($"{this.GetType().Name} Type: {desiredType?.Name}");
|
|
|
|
Logger.LogDebug($"{this.GetType().Name} Method: {desiredMethod?.Name}");
|
|
|
|
|
|
|
|
return desiredMethod;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static bool IsTargetMethod(MethodInfo mi)
|
|
|
|
{
|
|
|
|
var parameters = mi.GetParameters();
|
|
|
|
return parameters.Length == 3
|
|
|
|
&& parameters[0].Name == "maxCount"
|
|
|
|
&& parameters[1].Name == "botPresets"
|
|
|
|
&& parameters[2].Name == "botScatterings";
|
|
|
|
}
|
|
|
|
|
|
|
|
[PatchPrefix]
|
|
|
|
private static void PatchPreFix(ref int maxCount)
|
|
|
|
{
|
2024-05-31 22:00:29 +01:00
|
|
|
var gameWorld = Singleton<GameWorld>.Instance;
|
|
|
|
var location = gameWorld.MainPlayer.Location;
|
|
|
|
|
|
|
|
if (int.TryParse(RequestHandler.GetJson($"/singleplayer/settings/bot/maxCap/{location ?? "default"}"), out int parsedMaxCount))
|
2023-03-03 18:52:31 +00:00
|
|
|
{
|
2023-07-12 18:02:18 +01:00
|
|
|
Logger.LogWarning($"Set max bot cap to: {parsedMaxCount}");
|
2023-07-12 17:59:58 +01:00
|
|
|
maxCount = parsedMaxCount;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Logger.LogWarning($"Unable to parse data from singleplayer/settings/bot/maxCap, using existing map max of {maxCount}");
|
2023-03-03 18:52:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|