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

52 lines
2.0 KiB
C#
Raw Normal View History

2024-05-21 19:10:17 +01:00
using SPT.Common.Http;
using SPT.Reflection.Patching;
2023-03-03 18:52:31 +00:00
using EFT;
using System.Reflection;
using HarmonyLib;
2023-03-03 18:52:31 +00:00
2024-05-21 19:10:17 +01:00
namespace SPT.SinglePlayer.Patches.Quests
2023-03-03 18:52:31 +00:00
{
/// <summary>
/// Having the raid timer reach zero results in a successful extract,
/// this patch makes it so letting the time reach zero results in a MIA result
/// </summary>
public class EndByTimerPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
2024-04-03 15:38:14 +01:00
return AccessTools.Method(typeof(BaseLocalGame<EftGamePlayerOwner>), nameof(BaseLocalGame<EftGamePlayerOwner>.Stop));
2023-03-03 18:52:31 +00:00
}
// Unused, but left here in case patch breaks and finding the intended method is difficult
2023-03-03 18:52:31 +00:00
private static bool IsStopRaidMethod(MethodInfo mi)
{
var parameters = mi.GetParameters();
return (parameters.Length == 4
&& parameters[0].Name == "profileId"
&& parameters[1].Name == "exitStatus"
&& parameters[2].Name == "exitName"
&& parameters[3].Name == "delay"
&& parameters[0].ParameterType == typeof(string)
&& parameters[1].ParameterType == typeof(ExitStatus)
&& parameters[2].ParameterType == typeof(string)
&& parameters[3].ParameterType == typeof(float));
}
[PatchPrefix]
private static bool PrefixPatch(ref ExitStatus exitStatus, ref string exitName)
2023-03-03 18:52:31 +00:00
{
var isParsed = bool.TryParse(RequestHandler.GetJson("/singleplayer/settings/raid/endstate"), out bool MIAOnRaidEnd);
if (isParsed)
2023-03-03 18:52:31 +00:00
{
// No extract name and successful, its a MIA
if (MIAOnRaidEnd && string.IsNullOrEmpty(exitName?.Trim()) && exitStatus == ExitStatus.Survived)
{
exitStatus = ExitStatus.MissingInAction;
exitName = null;
}
2023-03-03 18:52:31 +00:00
}
return true; // Do original
}
}
}