0
0
mirror of https://github.com/sp-tarkov/modules.git synced 2025-02-13 09:50:43 -05:00
modules/project/Aki.Custom/BTR/Patches/BTRActivateTraderDialogPatch.cs
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

56 lines
1.9 KiB
C#

using Aki.Reflection.Patching;
using Comfort.Common;
using EFT;
using EFT.UI.Screens;
using EFT.Vehicle;
using HarmonyLib;
using System;
using System.Reflection;
using BTRDialog = EFT.UI.TraderDialogScreen.GClass3132;
namespace Aki.Custom.BTR.Patches
{
public class BTRActivateTraderDialogPatch : ModulePatch
{
private static FieldInfo _playerInventoryControllerField;
private static FieldInfo _playerQuestControllerField;
protected override MethodBase GetTargetMethod()
{
_playerInventoryControllerField = AccessTools.Field(typeof(Player), "_inventoryController");
_playerQuestControllerField = AccessTools.Field(typeof(Player), "_questController");
var targetType = AccessTools.FirstInner(typeof(GetActionsClass), IsTargetType);
return AccessTools.Method(targetType, "method_2");
}
private bool IsTargetType(Type type)
{
FieldInfo btrField = type.GetField("btr");
if (btrField != null && btrField.FieldType == typeof(BTRSide))
{
return true;
}
return false;
}
[PatchPrefix]
private static bool PatchPrefix()
{
var gameWorld = Singleton<GameWorld>.Instance;
var player = gameWorld.MainPlayer;
InventoryControllerClass inventoryController = _playerInventoryControllerField.GetValue(player) as InventoryControllerClass;
AbstractQuestControllerClass questController = _playerQuestControllerField.GetValue(player) as AbstractQuestControllerClass;
BTRDialog btrDialog = new BTRDialog(player.Profile, Profile.TraderInfo.TraderServiceToId[Profile.ETraderServiceSource.Btr], questController, inventoryController, null);
btrDialog.OnClose += player.UpdateInteractionCast;
btrDialog.ShowScreen(EScreenState.Queued);
return false;
}
}
}