0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 01:50:45 -05:00

Renamed patch and added more comments

This commit is contained in:
Dev 2024-10-03 10:20:46 +01:00
parent 69dc7e5ae2
commit 73bec0777a
3 changed files with 50 additions and 55 deletions

View File

@ -1,54 +0,0 @@
using Comfort.Common;
using EFT;
using SPT.Common.Http;
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
using System.Reflection;
namespace SPT.SinglePlayer.Patches.RaidFix
{
/// <summary>
/// Alter the max bot cap with value stored in server, if value is -1, use existing value
/// </summary>
public class MaxBotPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance;
const string methodName = "SetSettings";
var desiredType = PatchConstants.EftTypes.SingleCustom(x => x.GetMethod(methodName, flags) != null && IsTargetMethod(x.GetMethod(methodName, flags)));
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]
public static void PatchPreFix(ref int maxCount)
{
var gameWorld = Singleton<GameWorld>.Instance;
var location = gameWorld.MainPlayer.Location;
if (int.TryParse(RequestHandler.GetJson($"/singleplayer/settings/bot/maxCap/{location ?? "default"}"), out int parsedMaxCount))
{
Logger.LogWarning($"Set max bot cap to: {parsedMaxCount}");
maxCount = parsedMaxCount;
}
else
{
Logger.LogWarning($"Unable to parse data from singleplayer/settings/bot/maxCap, using existing map max of {maxCount}");
}
}
}
}

View File

@ -0,0 +1,49 @@
using Comfort.Common;
using EFT;
using SPT.Common.Http;
using SPT.Reflection.Patching;
using System.Reflection;
using HarmonyLib;
namespace SPT.SinglePlayer.Patches.RaidFix
{
/// <summary>
/// Alter the max bot cap with value stored in servers config/bot.json/maxBotCap, if value is -1, use existing value
/// Adjusted value is set by client when 'botamount' is chosen in pre-raid dropdown,
/// AsOnline = 20, Low = 15, Medium 20, High = 25, horde = 35
/// Does not affect ALL bots, some bot types (e.g. bosses) are exempt
/// </summary>
public class OverrideMaxAiAliveInRaidValuePatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(BotsController), nameof(BotsController.SetSettings));
}
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]
public static void PatchPreFix(ref int maxCount)
{
var gameWorld = Singleton<GameWorld>.Instance;
var location = gameWorld.MainPlayer?.Location ?? "default";
if (int.TryParse(RequestHandler.GetJson($"/singleplayer/settings/bot/maxCap/{location}"), out var parsedMaxCount))
{
Logger.LogError($"Set max bot cap for: {location} from: {maxCount} to: {parsedMaxCount}");
maxCount = parsedMaxCount;
}
else
{
Logger.LogError($"Unable to parse data from singleplayer/settings/bot/maxCap, using existing: {location} max: {maxCount}");
}
}
}
}

View File

@ -21,7 +21,7 @@ namespace SPT.SinglePlayer
// TODO: check if these patches are needed
new TinnitusFixPatch().Enable(); // Probably needed
//new EmptyInfilFixPatch().Enable();
new MaxBotPatch().Enable(); // Custom code, needed
new OverrideMaxAiAliveInRaidValuePatch().Enable();
//new PostRaidHealingPricePatch().Enable(); // Client handles this now
//new HideoutQuestIgnorePatch().Enable(); // Was only needed because FixQuestAchieveControllersPatch was causing issues
//new SpawnProcessNegativeValuePatch().Enable(); // Client handles this edge case, revisit if bot count keeps going up