0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
Arys a124ace054 Fixed exception caused by BTR not being destroyed at correct time (!68)
Todo:

* Make BTR spawn at random time during raid instead of at start
* ~~Fix BTR trader services not working for subsequent raids in Streets~~ Drakia provided me with a fix and it's included in this PR

TL;DR - It's ready for testing

Co-authored-by: Nympfonic <arys.steam@gmail.com>
Reviewed-on: SPT-AKI/Modules#68
Co-authored-by: Arys <arys@noreply.dev.sp-tarkov.com>
Co-committed-by: Arys <arys@noreply.dev.sp-tarkov.com>
2024-01-26 08:28:29 +00:00

47 lines
1.5 KiB
C#

using System.Linq;
using System.Reflection;
using Aki.Reflection.Patching;
using Comfort.Common;
using EFT;
using EFT.UI;
using HarmonyLib;
namespace Aki.Custom.BTR.Patches
{
/// <summary>
/// Adds a BTRManager component to the GameWorld game object when raid starts.
/// </summary>
public class BTRPatch : ModulePatch
{
protected override MethodBase GetTargetMethod()
{
// Note: This may seem like a weird place to hook, but `SetTime` requires that the BtrController
// exist and be setup, so we'll use this as the entry point
return AccessTools.Method(typeof(ExtractionTimersPanel), nameof(ExtractionTimersPanel.SetTime));
}
[PatchPrefix]
private static void PatchPrefix()
{
try
{
var btrSettings = Singleton<BackendConfigSettingsClass>.Instance.BTRSettings;
var gameWorld = Singleton<GameWorld>.Instance;
// Only run on maps that have the BTR enabled
string location = gameWorld.MainPlayer.Location;
if (!btrSettings.LocationsWithBTR.Contains(location))
{
return;
}
gameWorld.gameObject.AddComponent<BTRManager>();
}
catch (System.Exception)
{
ConsoleScreen.LogError("[AKI-BTR] Exception thrown, check logs.");
throw;
}
}
}
}