0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
Arys 89f0db250d BTR code refactors and turret aim improvements (!67)
Todo:

* Make BTR spawn at random time during raid instead of at the start
* Find out why some players receive error relating to `BTRBotAttachPatch` resulting BTR failing to initialise

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

48 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;
}
var btrManager = gameWorld.gameObject.AddComponent<BTRManager>();
btrManager.Init();
}
catch (System.Exception)
{
ConsoleScreen.LogError("[AKI-BTR] Exception thrown, check logs.");
throw;
}
}
}
}