Skip to content

Commit

Permalink
Update to latest BTR class from SPT
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Jun 6, 2024
1 parent cb26102 commit e5ef38a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
19 changes: 15 additions & 4 deletions Fika.Core/Coop/BTR/FikaBTRManager_Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

namespace Fika.Core.Coop.BTR
{
/// <summary>
/// Based on <see href="https://dev.sp-tarkov.com/SPT/Modules/src/branch/master/project/SPT.Custom/BTR/BTRManager.cs"/>
/// </summary>
internal class FikaBTRManager_Client : MonoBehaviour
{
private GameWorld gameWorld;
Expand Down Expand Up @@ -257,7 +260,7 @@ private void InitBtr()
btrServerSide.Initialization(btrMapConfig);*/
btrController.method_14(); // creates and assigns the BTR a fake stash

DisableServerSideRenderers();
DisableServerSideObjects();

/*btrServerSide.MoveEnable();*/
btrServerSide.IncomingToDestinationEvent += ToDestinationEvent;
Expand Down Expand Up @@ -383,15 +386,23 @@ private BTRDataPacket UpdateDataPacket()
return btrDataPacket;
}

private void DisableServerSideRenderers()
private void DisableServerSideObjects()
{
var meshRenderers = btrServerSide.transform.GetComponentsInChildren<MeshRenderer>();
foreach (var renderer in meshRenderers)
MeshRenderer[] meshRenderers = btrServerSide.transform.GetComponentsInChildren<MeshRenderer>();
foreach (MeshRenderer renderer in meshRenderers)
{
renderer.enabled = false;
}

btrServerSide.turnCheckerObject.GetComponent<Renderer>().enabled = false; // Disables the red debug sphere

// Something is colliding with each other. We disabled the Main exterior collider on server objects
// and changed the layer of the Client exterior collider to be highPolyCollider to stop it twerking. Needs Proper fix
MeshCollider[] servercolliders = btrServerSide.transform.GetComponentsInChildren<MeshCollider>();
MeshCollider[] clientcolliders = btrClientSide.transform.GetComponentsInChildren<MeshCollider>();

clientcolliders.FirstOrDefault(x => x.gameObject.name == "BTR_82_exterior_COLLIDER").gameObject.layer = LayerMask.NameToLayer("HighPolyCollider");
servercolliders.FirstOrDefault(x => x.gameObject.name == "BTR_82_exterior_COLLIDER").enabled = false;
}

public void ClientInteraction(Player player, PlayerInteractPacket packet)
Expand Down
27 changes: 19 additions & 8 deletions Fika.Core/Coop/BTR/FikaBTRManager_Host.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@

namespace Fika.Core.Coop.BTR
{
/// <summary>
/// Based on <see href="https://dev.sp-tarkov.com/SPT/Modules/src/branch/master/project/SPT.Custom/BTR/BTRManager.cs"/>
/// </summary>
internal class FikaBTRManager_Host : MonoBehaviour
{
private GameWorld gameWorld;
Expand Down Expand Up @@ -278,12 +281,12 @@ private void InitBtr()
// Get config from server and initialise respective settings
ConfigureSettingsFromServer();

var btrMapConfig = btrController.MapPathsConfiguration;
MapPathConfig btrMapConfig = btrController.MapPathsConfiguration;
btrServerSide.CurrentPathConfig = btrMapConfig.PathsConfiguration.pathsConfigurations.RandomElement();
btrServerSide.Initialization(btrMapConfig);
btrController.method_14(); // creates and assigns the BTR a fake stash

DisableServerSideRenderers();
DisableServerSideObjects();

gameWorld.MainPlayer.OnBtrStateChanged += HandleBtrDoorState;

Expand All @@ -297,7 +300,7 @@ private void InitBtr()

// Initialise turret variables
btrTurretServer = btrServerSide.BTRTurret;
var btrTurretDefaultTargetTransform = (Transform)AccessTools.Field(btrTurretServer.GetType(), "defaultTargetTransform").GetValue(btrTurretServer);
Transform btrTurretDefaultTargetTransform = (Transform)AccessTools.Field(btrTurretServer.GetType(), "defaultTargetTransform").GetValue(btrTurretServer);
isTurretInDefaultRotation = btrTurretServer.targetTransform == btrTurretDefaultTargetTransform
&& btrTurretServer.targetPosition == btrTurretServer.defaultAimingPosition;
btrMachineGunAmmo = (BulletClass)BTRUtil.CreateItem(BTRUtil.BTRMachineGunAmmoTplId);
Expand All @@ -311,7 +314,7 @@ private void InitBtr()

private void ConfigureSettingsFromServer()
{
var serverConfig = BTRUtil.GetConfigFromServer();
SPT.Custom.BTR.Models.BTRConfigModel serverConfig = BTRUtil.GetConfigFromServer();

btrServerSide.moveSpeed = serverConfig.MoveSpeed;
btrServerSide.pauseDurationRange.x = serverConfig.PointWaitTime.Min;
Expand All @@ -327,7 +330,7 @@ private void InitBtrBotService()
{
btrBotShooter = btrController.BotShooterBtr;
firearmController = btrBotShooter.GetComponent<Player.FirearmController>();
var weaponPrefab = (WeaponPrefab)AccessTools.Field(firearmController.GetType(), "weaponPrefab_0").GetValue(firearmController);
WeaponPrefab weaponPrefab = (WeaponPrefab)AccessTools.Field(firearmController.GetType(), "weaponPrefab_0").GetValue(firearmController);
weaponSoundPlayer = weaponPrefab.GetComponent<WeaponSoundPlayer>();

btrBotService.Reset(); // Player will be added to Neutrals list and removed from Enemies list
Expand Down Expand Up @@ -520,15 +523,23 @@ private BTRDataPacket UpdateDataPacket()
return btrDataPacket;
}

private void DisableServerSideRenderers()
private void DisableServerSideObjects()
{
var meshRenderers = btrServerSide.transform.GetComponentsInChildren<MeshRenderer>();
foreach (var renderer in meshRenderers)
MeshRenderer[] meshRenderers = btrServerSide.transform.GetComponentsInChildren<MeshRenderer>();
foreach (MeshRenderer renderer in meshRenderers)
{
renderer.enabled = false;
}

btrServerSide.turnCheckerObject.GetComponent<Renderer>().enabled = false; // Disables the red debug sphere

// Something is colliding with each other. We disabled the Main exterior collider on server objects
// and changed the layer of the Client exterior collider to be highPolyCollider to stop it twerking. Needs Proper fix
MeshCollider[] servercolliders = btrServerSide.transform.GetComponentsInChildren<MeshCollider>();
MeshCollider[] clientcolliders = btrClientSide.transform.GetComponentsInChildren<MeshCollider>();

clientcolliders.FirstOrDefault(x => x.gameObject.name == "BTR_82_exterior_COLLIDER").gameObject.layer = LayerMask.NameToLayer("HighPolyCollider");
servercolliders.FirstOrDefault(x => x.gameObject.name == "BTR_82_exterior_COLLIDER").enabled = false;
}

private void UpdateTarget()
Expand Down

0 comments on commit e5ef38a

Please sign in to comment.