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

60 lines
2.4 KiB
C#
Raw Normal View History

2024-05-21 19:10:17 +01:00
using SPT.Reflection.Patching;
2023-03-03 18:52:31 +00:00
using Comfort.Common;
using EFT;
using System.Reflection;
using HarmonyLib;
using EFT.Interactive;
using System.Linq;
2023-03-03 18:52:31 +00:00
2024-05-21 19:10:17 +01:00
namespace SPT.SinglePlayer.Patches.ScavMode
2023-03-03 18:52:31 +00:00
{
/// <summary>
/// Disable PMC exfil points when playing as pscav, without this patch PMC extracts do not show in the side menu but can be extracted from
2023-03-03 18:52:31 +00:00
/// </summary>
public class DisablePMCExtractsForScavsPatch : ModulePatch
2023-03-03 18:52:31 +00:00
{
protected override MethodBase GetTargetMethod()
{
return AccessTools.Method(typeof(GameWorld), nameof(GameWorld.OnGameStarted));
2023-03-03 18:52:31 +00:00
}
[PatchPostfix]
public static void PatchPostFix()
{
var gameWorld = Singleton<GameWorld>.Instance;
// checks nothing is null otherwise bad things happen
2023-03-03 18:52:31 +00:00
if (gameWorld == null || gameWorld.RegisteredPlayers == null || gameWorld.ExfiltrationController == null)
{
Logger.LogError("Could not find GameWorld or RegisterPlayers... Unable to disable extracts for Scav raid");
2023-03-03 18:52:31 +00:00
}
Player player = gameWorld.MainPlayer;
2023-03-03 18:52:31 +00:00
// Only disable PMC extracts if current player is a scav
2023-03-03 18:52:31 +00:00
if (player.Fraction == ETagStatus.Scav && player.Location != "hideout")
{
foreach (var exfil in gameWorld.ExfiltrationController.ExfiltrationPoints)
2023-03-03 18:52:31 +00:00
{
if (exfil is ScavExfiltrationPoint scavExfil)
{
// We are checking if player exists in list so we dont disable the wrong extract
if(!scavExfil.EligibleIds.Contains(player.ProfileId))
{
Logger.LogError($"Disabled exfil: {exfil.name}");
exfil.Disable();
}
}
else
{
// Disabling extracts that aren't scav extracts
exfil.Disable();
// _authorityToChangeStatusExternally Changing this to false stop buttons from re-enabling extracts (d-2 extract, zb-013)
exfil.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance).First(x => x.Name == "_authorityToChangeStatusExternally").SetValue(exfil, false);
}
2023-03-03 18:52:31 +00:00
}
}
}
}
}