0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/SPT.Custom/Patches/BossSpawnChancePatch.cs

58 lines
1.8 KiB
C#
Raw Normal View History

2024-05-21 19:10:17 +01:00
using SPT.Reflection.Patching;
using SPT.Reflection.Utils;
2023-03-03 18:52:31 +00:00
using System.Linq;
using System.Reflection;
2024-05-21 19:10:17 +01:00
namespace SPT.Custom.Patches
2023-03-03 18:52:31 +00:00
{
/// <summary>
/// Boss spawn chance is 100%, all the time, this patch adjusts the chance to the maps boss wave value
/// </summary>
public class BossSpawnChancePatch : ModulePatch
{
private static float[] _bossSpawnPercent;
protected override MethodBase GetTargetMethod()
{
var desiredType = PatchConstants.LocalGameType;
var desiredMethod = desiredType
.GetMethods(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)
.SingleOrDefault(IsTargetMethod);
2023-03-03 18:52:31 +00:00
Logger.LogDebug($"{this.GetType().Name} Type: {desiredType.Name}");
Logger.LogDebug($"{this.GetType().Name} Method: {desiredMethod?.Name ?? "NOT FOUND"}");
2023-03-03 18:52:31 +00:00
return desiredMethod;
}
private static bool IsTargetMethod(MethodInfo mi)
{
var parameters = mi.GetParameters();
2024-07-04 21:22:23 +01:00
return (parameters.Length == 3
&& parameters[0].Name == "isPVEOffline"
&& parameters[1].Name == "wavesSettings"
&& parameters[2].Name == "bossLocationSpawn");
2023-03-03 18:52:31 +00:00
}
[PatchPrefix]
private static void PatchPrefix(BossLocationSpawn[] bossLocationSpawn)
{
_bossSpawnPercent = bossLocationSpawn.Select(s => s.BossChance).ToArray();
}
[PatchPostfix]
private static void PatchPostfix(ref BossLocationSpawn[] __result)
{
if (__result.Length != _bossSpawnPercent.Length)
{
return;
}
for (var i = 0; i < _bossSpawnPercent.Length; i++)
{
__result[i].BossChance = _bossSpawnPercent[i];
}
}
}
}