mirror of
https://github.com/sp-tarkov/modules.git
synced 2025-02-13 09:50:43 -05:00
Current progress: * BTR spawns in, clientside BTR is synced with serverside BTR * BTR Bot spawns in, is assigned to BTRController (GClass2911) correctly * BTR Bot is initialized properly (invisible, makes no sound, doesn't shoot at player) Todo: BTR is currently missing functionality * It needs to allow player to enter and exit * Player should be able to interact with BTR driver/open BTR stash UI/pay money to get taxi'd to a chosen location/pay money for it to provide covering fire * Turret should rotate to shoot player if they attack it * It should be able to drive on its own from raid start, going from location to location, on a set path Co-authored-by: Nympfonic <arys.steam@gmail.com> Reviewed-on: SPT-AKI/Modules#50 Co-authored-by: Arys <arys@noreply.dev.sp-tarkov.com> Co-committed-by: Arys <arys@noreply.dev.sp-tarkov.com>
88 lines
3.9 KiB
C#
88 lines
3.9 KiB
C#
using Aki.Reflection.Patching;
|
|
using EFT.UI;
|
|
using EFT.Vehicle;
|
|
using EFT;
|
|
using HarmonyLib;
|
|
using System.Reflection;
|
|
using UnityEngine;
|
|
using Comfort.Common;
|
|
using System;
|
|
using EFT.NextObservedPlayer;
|
|
|
|
namespace Aki.Debugging.BTR.Patches
|
|
{
|
|
// Fixes the BTR Bot initialization in method_1() of BTRTurretView
|
|
//
|
|
// Context:
|
|
// ClientGameWorld in LiveEFT will register the server-side BTR Bot as type ObservedPlayerView and is stored in GameWorld's allObservedPlayersByID dictionary.
|
|
// In SPT, allObservedPlayersByID is empty which results in the game never finishing the initialization of the BTR Bot which includes disabling its gun, voice and mesh renderers.
|
|
// Perhaps some research should be done into getting the dictionary populated as ObservedPlayerView seems to be utilised by several aspects of the BTR's functionality.
|
|
// For now, we do dirty patches to work around the lack of ObservedPlayerView, using Player instead.
|
|
public class BTRBotInitPatch : ModulePatch
|
|
{
|
|
protected override MethodBase GetTargetMethod()
|
|
{
|
|
return AccessTools.Method(typeof(BTRTurretView), "method_1");
|
|
}
|
|
|
|
[PatchPostfix]
|
|
public static void PatchPostfix(object __instance, int btrBotId, ref bool __result)
|
|
{
|
|
var gameWorld = Singleton<GameWorld>.Instance;
|
|
var btrTurretView = (BTRTurretView)__instance;
|
|
|
|
foreach (var playerKeyValue in gameWorld.allAlivePlayersByID)
|
|
{
|
|
if (playerKeyValue.Value.Id == btrBotId)
|
|
{
|
|
try
|
|
{
|
|
Renderer[] array = playerKeyValue.Value.GetComponentsInChildren<Renderer>();
|
|
for (int i = 0; i < array.Length; i++)
|
|
{
|
|
array[i].enabled = false;
|
|
}
|
|
|
|
var aiFirearmController = playerKeyValue.Value.gameObject.GetComponent<Player.FirearmController>();
|
|
var currentWeaponPrefab = (WeaponPrefab)AccessTools.Field(aiFirearmController.GetType(), "weaponPrefab_0").GetValue(aiFirearmController);
|
|
if (currentWeaponPrefab.RemoveChildrenOf != null)
|
|
{
|
|
foreach (var text in currentWeaponPrefab.RemoveChildrenOf)
|
|
{
|
|
var transform = currentWeaponPrefab.transform.FindTransform(text);
|
|
if (transform != null)
|
|
{
|
|
transform.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
foreach (var renderer in currentWeaponPrefab.GetComponentsInChildren<Renderer>())
|
|
{
|
|
if (renderer.name == "MuzzleJetCombinedMesh")
|
|
{
|
|
renderer.transform.localPosition = new Vector3(0.18f, 0f, -0.095f);
|
|
}
|
|
else
|
|
{
|
|
renderer.enabled = false;
|
|
}
|
|
}
|
|
|
|
var tuple = new ValueTuple<ObservedPlayerView, bool>(new ObservedPlayerView(), true);
|
|
var btrTurretViewTupleField = AccessTools.Field(btrTurretView.GetType(), "valueTuple_0");
|
|
btrTurretViewTupleField.SetValue(btrTurretView, tuple);
|
|
|
|
__result = true;
|
|
return;
|
|
}
|
|
catch
|
|
{
|
|
ConsoleScreen.LogError("[AKI-BTR] BtrBot initialization failed, BtrBot will be visible ingame. Check logs.");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|