diff --git a/project/Aki.Custom/AkiCustomPlugin.cs b/project/Aki.Custom/AkiCustomPlugin.cs index 4635721..f2c19de 100644 --- a/project/Aki.Custom/AkiCustomPlugin.cs +++ b/project/Aki.Custom/AkiCustomPlugin.cs @@ -54,8 +54,8 @@ namespace Aki.Custom new BTRActivateTraderDialogPatch().Enable(); new BTRInteractionPatch().Enable(); new BTRExtractPassengersPatch().Enable(); - new BTRBotAttachPatch().Enable(); new BTRBotInitPatch().Enable(); + new BTRBotAttachPatch().Enable(); new BTRReceiveDamageInfoPatch().Enable(); new BTRTurretCanShootPatch().Enable(); new BTRTurretDefaultAimingPositionPatch().Enable(); diff --git a/project/Aki.Custom/BTR/BTRManager.cs b/project/Aki.Custom/BTR/BTRManager.cs index 1b0cedc..d7f25ad 100644 --- a/project/Aki.Custom/BTR/BTRManager.cs +++ b/project/Aki.Custom/BTR/BTRManager.cs @@ -3,6 +3,7 @@ using Aki.SinglePlayer.Utils.TraderServices; using Comfort.Common; using EFT; using EFT.InventoryLogic; +using EFT.UI; using EFT.Vehicle; using HarmonyLib; using System; @@ -28,20 +29,25 @@ namespace Aki.Custom.BTR private BotOwner btrBotShooter; private BTRDataPacket btrDataPacket = default; private bool btrBotShooterInitialized = false; - private float coverFireTime = 90f; - private EPlayerBtrState previousPlayerBtrState; + private float coverFireTime = 90f; + private Coroutine _coverFireTimerCoroutine; + private BTRSide lastInteractedBtrSide; public BTRSide LastInteractedBtrSide => lastInteractedBtrSide; - private Coroutine _coverFireTimerCoroutine; - private BTRTurretServer btrTurretServer; - private Transform btrTurretDefaultTargetTransform; private Coroutine _shootingTargetCoroutine; - private IPlayer currentTarget = null; + private BTRTurretServer btrTurretServer; + private bool isTurretInDefaultRotation; + private EnemyInfo currentTarget = null; private bool isShooting = false; + private float machineGunAimDelay = 0.4f; + private Vector2 machineGunBurstCount; + private Vector2 machineGunRecoveryTime; private BulletClass btrMachineGunAmmo; private Item btrMachineGunWeapon; + private Player.FirearmController firearmController; + private WeaponSoundPlayer weaponSoundPlayer; private MethodInfo _updateTaxiPriceMethod; @@ -56,65 +62,29 @@ namespace Aki.Custom.BTR try { gameWorld = Singleton.Instance; - if (gameWorld == null) { Destroy(this); return; } - if (gameWorld.BtrController == null) + if (gameWorld.BtrController == null && !Singleton.Instantiated) { - if (!Singleton.Instantiated) - { - Singleton.Create(new BTRControllerClass()); - } - - gameWorld.BtrController = btrController = Singleton.Instance; + Singleton.Create(new BTRControllerClass()); } - InitBTR(); + gameWorld.BtrController = btrController = Singleton.Instance; + + InitBtr(); } catch { - Debug.LogError("[AKI-BTR]: Unable to spawn BTR"); + ConsoleScreen.LogError("[AKI-BTR] Unable to spawn BTR. Check logs."); DestroyGameObjects(); throw; } } - // Find `BTRControllerClass.method_9(PathDestination currentDestinationPoint, bool lastRoutePoint)` - private bool IsUpdateTaxiPriceMethod(MethodInfo method) - { - return (method.GetParameters().Length == 2 && method.GetParameters()[0].ParameterType == typeof(PathDestination)); - } - - private void Update() - { - btrController.SyncBTRVehicleFromServer(UpdateDataPacket()); - - if (btrController.BotShooterBtr == null) return; - - // BotShooterBtr doesn't get assigned to BtrController immediately so we check this in Update - if (!btrBotShooterInitialized) - { - btrBotShooter = btrController.BotShooterBtr; - btrBotService.Reset(); // Player will be added to Neutrals list and removed from Enemies list - TraderServicesManager.Instance.OnTraderServicePurchased += BTRTraderServicePurchased; - btrBotShooterInitialized = true; - } - - if (HasTarget() && IsAimingAtTarget() && !isShooting) - { - _shootingTargetCoroutine = StaticManager.BeginCoroutine(ShootTarget()); - } - - if (_coverFireTimerCoroutine != null && ShouldCancelCoverFireSupport()) - { - CancelCoverFireSupport(); - } - } - public void OnPlayerInteractDoor(PlayerInteractPacket interactPacket) { btrServerSide.LeftSlot0State = 0; @@ -148,11 +118,44 @@ namespace Aki.Custom.BTR } } - private void InitBTR() + // Find `BTRControllerClass.method_9(PathDestination currentDestinationPoint, bool lastRoutePoint)` + private bool IsUpdateTaxiPriceMethod(MethodInfo method) { - // Fetch config from the server - var serverConfig = BTRUtil.GetConfigFromServer(); + return (method.GetParameters().Length == 2 && method.GetParameters()[0].ParameterType == typeof(PathDestination)); + } + private void Update() + { + btrController.SyncBTRVehicleFromServer(UpdateDataPacket()); + + if (btrController.BotShooterBtr == null) return; + + // BotShooterBtr doesn't get assigned to BtrController immediately so we check this in Update + if (!btrBotShooterInitialized) + { + InitBtrBotService(); + btrBotShooterInitialized = true; + } + + UpdateTarget(); + + if (HasTarget()) + { + SetAim(); + + if (!isShooting && CanShoot()) + { + StartShooting(); + } + } + else if (!isTurretInDefaultRotation) + { + btrTurretServer.DisableAiming(); + } + } + + private void InitBtr() + { // Initial setup botEventHandler = Singleton.Instance; var botsController = Singleton.Instance.BotsController; @@ -162,14 +165,11 @@ namespace Aki.Custom.BTR // Initial BTR configuration btrServerSide = btrController.BtrVehicle; + btrClientSide = btrController.BtrView; btrServerSide.transform.Find("KillBox").gameObject.AddComponent(); - // Update values from server side config - btrServerSide.moveSpeed = serverConfig.MoveSpeed; - btrServerSide.pauseDurationRange.x = serverConfig.PointWaitTime.Min; - btrServerSide.pauseDurationRange.y = serverConfig.PointWaitTime.Max; - btrServerSide.readyToDeparture = serverConfig.TaxiWaitTime; - coverFireTime = serverConfig.CoverFireTime; + // Get config from server and initialise respective settings + ConfigureSettingsFromServer(); var btrMapConfig = btrController.MapPathsConfiguration; btrServerSide.CurrentPathConfig = btrMapConfig.PathsConfiguration.pathsConfigurations.RandomElement(); @@ -185,13 +185,14 @@ namespace Aki.Custom.BTR // Sync initial position and rotation UpdateDataPacket(); - btrClientSide = btrController.BtrView; btrClientSide.transform.position = btrDataPacket.position; btrClientSide.transform.rotation = btrDataPacket.rotation; // Initialise turret variables btrTurretServer = btrServerSide.BTRTurret; - btrTurretDefaultTargetTransform = (Transform)AccessTools.Field(btrTurretServer.GetType(), "defaultTargetTransform").GetValue(btrTurretServer); + var btrTurretDefaultTargetTransform = (Transform)AccessTools.Field(btrTurretServer.GetType(), "defaultTargetTransform").GetValue(btrTurretServer); + isTurretInDefaultRotation = btrTurretServer.targetTransform == btrTurretDefaultTargetTransform + && btrTurretServer.targetPosition == btrTurretServer.defaultAimingPosition; btrMachineGunAmmo = (BulletClass)BTRUtil.CreateItem(BTRUtil.BTRMachineGunAmmoTplId); btrMachineGunWeapon = BTRUtil.CreateItem(BTRUtil.BTRMachineGunWeaponTplId); @@ -199,6 +200,31 @@ namespace Aki.Custom.BTR TraderServicesManager.Instance.GetTraderServicesDataFromServer(BTRUtil.BTRTraderId); } + private void ConfigureSettingsFromServer() + { + var serverConfig = BTRUtil.GetConfigFromServer(); + + btrServerSide.moveSpeed = serverConfig.MoveSpeed; + btrServerSide.pauseDurationRange.x = serverConfig.PointWaitTime.Min; + btrServerSide.pauseDurationRange.y = serverConfig.PointWaitTime.Max; + btrServerSide.readyToDeparture = serverConfig.TaxiWaitTime; + coverFireTime = serverConfig.CoverFireTime; + machineGunAimDelay = serverConfig.MachineGunAimDelay; + machineGunBurstCount = new Vector2(serverConfig.MachineGunBurstCount.Min, serverConfig.MachineGunBurstCount.Max); + machineGunRecoveryTime = new Vector2(serverConfig.MachineGunRecoveryTime.Min, serverConfig.MachineGunRecoveryTime.Max); + } + + private void InitBtrBotService() + { + btrBotShooter = btrController.BotShooterBtr; + firearmController = btrBotShooter.GetComponent(); + var weaponPrefab = (WeaponPrefab)AccessTools.Field(firearmController.GetType(), "weaponPrefab_0").GetValue(firearmController); + weaponSoundPlayer = weaponPrefab.GetComponent(); + + btrBotService.Reset(); // Player will be added to Neutrals list and removed from Enemies list + TraderServicesManager.Instance.OnTraderServicePurchased += BtrTraderServicePurchased; + } + /** * BTR has arrived at a destination, re-calculate taxi prices and remove purchased taxi service */ @@ -226,7 +252,7 @@ namespace Aki.Custom.BTR return false; } - private void BTRTraderServicePurchased(ETraderServiceType serviceType, string subserviceId) + private void BtrTraderServicePurchased(ETraderServiceType serviceType, string subserviceId) { if (!IsBtrService(serviceType)) { @@ -255,23 +281,6 @@ namespace Aki.Custom.BTR _coverFireTimerCoroutine = StaticManager.BeginCoroutine(CoverFireTimer(time)); } - private bool ShouldCancelCoverFireSupport() - { - var friendlyPlayersByBtrSupport = (List)AccessTools.Field(btrBotService.GetType(), "_friendlyPlayersByBtrSupport").GetValue(btrBotService); - if (!friendlyPlayersByBtrSupport.Any()) - { - return true; - } - - return false; - } - - private void CancelCoverFireSupport() - { - StaticManager.KillCoroutine(ref _coverFireTimerCoroutine); - botEventHandler.StopTraderServiceBtrSupport(); - } - private IEnumerator CoverFireTimer(float time) { yield return new WaitForSecondsRealtime(time); @@ -280,44 +289,42 @@ namespace Aki.Custom.BTR private void HandleBtrDoorState(EPlayerBtrState playerBtrState) { - if (previousPlayerBtrState == EPlayerBtrState.Approach && playerBtrState == EPlayerBtrState.GoIn - || previousPlayerBtrState == EPlayerBtrState.Inside && playerBtrState == EPlayerBtrState.GoOut) + if (playerBtrState == EPlayerBtrState.GoIn || playerBtrState == EPlayerBtrState.GoOut) { // Open Door UpdateBTRSideDoorState(1); } - else if (previousPlayerBtrState == EPlayerBtrState.GoIn && playerBtrState == EPlayerBtrState.Inside - || previousPlayerBtrState == EPlayerBtrState.GoOut && playerBtrState == EPlayerBtrState.Outside) + else if (playerBtrState == EPlayerBtrState.Inside || playerBtrState == EPlayerBtrState.Outside) { // Close Door UpdateBTRSideDoorState(0); } - - previousPlayerBtrState = playerBtrState; } private void UpdateBTRSideDoorState(byte state) { - var player = gameWorld.MainPlayer; - var btrSides = (BTRSide[])AccessTools.Field(typeof(BTRView), "_btrSides").GetValue(btrController.BtrView); - - for (int i = 0; i < btrSides.Length; i++) + try { - if (player.BtrInteractionSide != null && btrSides[i] == player.BtrInteractionSide - || lastInteractedBtrSide != null && btrSides[i] == lastInteractedBtrSide) - { - switch (i) - { - case 0: - btrServerSide.LeftSideState = state; - break; - case 1: - btrServerSide.RightSideState = state; - break; - } + var player = gameWorld.MainPlayer; - lastInteractedBtrSide = player.BtrInteractionSide; + BTRSide btrSide = player.BtrInteractionSide != null ? player.BtrInteractionSide : lastInteractedBtrSide; + byte sideId = btrClientSide.GetSideId(btrSide); + switch (sideId) + { + case 0: + btrServerSide.LeftSideState = state; + break; + case 1: + btrServerSide.RightSideState = state; + break; } + + lastInteractedBtrSide = player.BtrInteractionSide; + } + catch + { + ConsoleScreen.LogError("[AKI-BTR] lastInteractedBtrSide is null when it shouldn't be. Check logs."); + throw; } } @@ -325,7 +332,7 @@ namespace Aki.Custom.BTR { btrDataPacket.position = btrServerSide.transform.position; btrDataPacket.rotation = btrServerSide.transform.rotation; - if (btrTurretServer?.gunsBlockRoot != null) + if (btrTurretServer != null && btrTurretServer.gunsBlockRoot != null) { btrDataPacket.turretRotation = btrTurretServer.transform.rotation; btrDataPacket.gunsBlockRotation = btrTurretServer.gunsBlockRoot.rotation; @@ -342,7 +349,7 @@ namespace Aki.Custom.BTR btrDataPacket.timeToEndPause = btrServerSide.timeToEndPause; btrDataPacket.moveDirection = (byte)btrServerSide.VehicleMoveDirection; btrDataPacket.MoveSpeed = btrServerSide.moveSpeed; - if (btrController.BotShooterBtr != null) + if (btrController != null && btrController.BotShooterBtr != null) { btrDataPacket.BtrBotId = btrController.BotShooterBtr.Id; } @@ -359,92 +366,95 @@ namespace Aki.Custom.BTR } } + private void UpdateTarget() + { + currentTarget = btrBotShooter.Memory.GoalEnemy; + } + private bool HasTarget() { - var enemies = btrBotShooter.BotsGroup.Enemies; - if (enemies.Any()) + if (currentTarget != null) { - currentTarget = enemies.First().Key; - if (!currentTarget.HealthController.IsAlive) - { - enemies.Remove(currentTarget); - currentTarget = null; - return false; - } - return true; } return false; } - private bool IsAimingAtTarget() - { - bool turretInDefaultRotation = btrTurretServer.targetTransform == btrTurretDefaultTargetTransform - && btrTurretServer.targetPosition == btrTurretServer.defaultAimingPosition; - - if (currentTarget != null) + private void SetAim() + { + if (currentTarget.IsVisible) { - Transform currentTargetTransform = currentTarget.Transform.Original; - EnemyInfo currentTargetInfo = btrBotShooter.EnemiesController.EnemyInfos[currentTarget]; - - if (currentTargetInfo.IsVisible) + Vector3 targetPos = currentTarget.CurrPosition; + Transform targetTransform = currentTarget.Person.Transform.Original; + if (btrTurretServer.CheckPositionInAimingZone(targetPos) && btrTurretServer.targetTransform != targetTransform) { - Vector3 currentTargetPosition = currentTargetTransform.position; - if (btrTurretServer.CheckPositionInAimingZone(currentTargetPosition)) - { - if (btrTurretServer.targetTransform == currentTargetTransform && btrBotShooter.BotBtrData.CanShoot()) - { - return true; - } - - if (btrTurretServer.targetTransform != currentTargetTransform) - { - btrTurretServer.EnableAimingObject(currentTargetTransform); - } - } + btrTurretServer.EnableAimingObject(targetTransform); } - // Turret will hold the angle where target was last seen for 3 seconds before resetting its rotation - else if (btrTurretServer.targetPosition != currentTargetInfo.EnemyLastPosition && btrTurretServer.targetTransform != null) + } + else + { + Vector3 targetLastPos = currentTarget.EnemyLastPositionReal; + if (btrTurretServer.CheckPositionInAimingZone(targetLastPos) + && Time.time - currentTarget.PersonalLastSeenTime < 3f + && btrTurretServer.targetPosition != targetLastPos) { - btrTurretServer.EnableAimingPosition(currentTargetInfo.EnemyLastPosition); + btrTurretServer.EnableAimingPosition(targetLastPos); + } - else if (currentTargetInfo.TimeLastSeen >= 3f && !turretInDefaultRotation) + else if (Time.time - currentTarget.PersonalLastSeenTime >= 3f && !isTurretInDefaultRotation) { - currentTarget = null; btrTurretServer.DisableAiming(); } } - else if (!turretInDefaultRotation) + } + + private bool CanShoot() + { + if (currentTarget.IsVisible && btrBotShooter.BotBtrData.CanShoot()) { - btrTurretServer.DisableAiming(); + return true; } return false; } + private void StartShooting() + { + _shootingTargetCoroutine = StaticManager.BeginCoroutine(ShootMachineGun()); + } + /// /// Custom method to make the BTR coaxial machine gun shoot. /// - private IEnumerator ShootTarget() + private IEnumerator ShootMachineGun() { isShooting = true; - Transform machineGunMuzzle = btrTurretServer.machineGunLaunchPoint; - Player.FirearmController firearmController = btrBotShooter.GetComponent(); - WeaponPrefab weaponPrefab = (WeaponPrefab)AccessTools.Field(firearmController.GetType(), "weaponPrefab_0").GetValue(firearmController); - WeaponSoundPlayer weaponSoundPlayer = weaponPrefab.GetComponent(); + yield return new WaitForSecondsRealtime(machineGunAimDelay); + if (!currentTarget.IsVisible || !btrBotShooter.BotBtrData.CanShoot()) + { + isShooting = false; + yield break; + } - int burstCount = Random.Range(5, 8); + Transform machineGunMuzzle = btrTurretServer.machineGunLaunchPoint; + var ballisticCalculator = gameWorld.SharedBallisticsCalculator; + + int burstMin = Mathf.FloorToInt(machineGunBurstCount.x); + int burstMax = Mathf.FloorToInt(machineGunBurstCount.y); + int burstCount = Random.Range(burstMin, burstMax + 1); while (burstCount > 0) { - gameWorld.SharedBallisticsCalculator.Shoot(btrMachineGunAmmo, machineGunMuzzle.position, machineGunMuzzle.forward, btrBotShooter.ProfileId, btrMachineGunWeapon, 1f, 0); - firearmController.method_54(weaponSoundPlayer, btrMachineGunAmmo, machineGunMuzzle.position, machineGunMuzzle.forward, false); + Vector3 targetHeadPos = currentTarget.Person.PlayerBones.Head.position; + Vector3 aimDirection = Vector3.Normalize(targetHeadPos - machineGunMuzzle.position); + ballisticCalculator.Shoot(btrMachineGunAmmo, machineGunMuzzle.position, aimDirection, btrBotShooter.ProfileId, btrMachineGunWeapon, 1f, 0); + firearmController.method_54(weaponSoundPlayer, btrMachineGunAmmo, machineGunMuzzle.position, aimDirection, false); burstCount--; yield return new WaitForSecondsRealtime(0.092308f); // 650 RPM } - float waitTime = Random.Range(0.8f, 1.7f); // 0.8 - 1.7 second pause between bursts + float waitTime = Random.Range(machineGunRecoveryTime.x, machineGunRecoveryTime.y); yield return new WaitForSecondsRealtime(waitTime); isShooting = false; @@ -471,14 +481,14 @@ namespace Aki.Custom.BTR btrController.Dispose(); } - if (gameWorld?.MainPlayer != null) + if (gameWorld.MainPlayer != null) { gameWorld.MainPlayer.OnBtrStateChanged -= HandleBtrDoorState; } if (TraderServicesManager.Instance != null) { - TraderServicesManager.Instance.OnTraderServicePurchased -= BTRTraderServicePurchased; + TraderServicesManager.Instance.OnTraderServicePurchased -= BtrTraderServicePurchased; } StaticManager.KillCoroutine(ref _shootingTargetCoroutine); diff --git a/project/Aki.Custom/BTR/Models/BtrConfigModel.cs b/project/Aki.Custom/BTR/Models/BtrConfigModel.cs index 437ca8d..ec48fba 100644 --- a/project/Aki.Custom/BTR/Models/BtrConfigModel.cs +++ b/project/Aki.Custom/BTR/Models/BtrConfigModel.cs @@ -1,9 +1,9 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; -namespace Aki.Debugging.BTR.Models +namespace Aki.Custom.BTR.Models { - public class BtrConfigModel + public class BTRConfigModel { [JsonProperty("moveSpeed")] public float MoveSpeed { get; set; } @@ -16,6 +16,15 @@ namespace Aki.Debugging.BTR.Models [JsonProperty("taxiWaitTime")] public float TaxiWaitTime { get; set; } + + [JsonProperty("machineGunAimDelay")] + public float MachineGunAimDelay { get; set; } + + [JsonProperty("machineGunBurstCount")] + public BtrMinMaxValue MachineGunBurstCount { get; set; } + + [JsonProperty("machineGunRecoveryTime")] + public BtrMinMaxValue MachineGunRecoveryTime { get; set; } } public class BtrMinMaxValue diff --git a/project/Aki.Custom/BTR/Patches/BTRActivateTraderDialogPatch.cs b/project/Aki.Custom/BTR/Patches/BTRActivateTraderDialogPatch.cs index 7004cbb..d0c44a1 100644 --- a/project/Aki.Custom/BTR/Patches/BTRActivateTraderDialogPatch.cs +++ b/project/Aki.Custom/BTR/Patches/BTRActivateTraderDialogPatch.cs @@ -6,7 +6,6 @@ using EFT.Vehicle; using HarmonyLib; using System; using System.Reflection; -using static EFT.UI.TraderDialogScreen; using BTRDialog = EFT.UI.TraderDialogScreen.GClass3132; namespace Aki.Custom.BTR.Patches diff --git a/project/Aki.Custom/BTR/Patches/BTRBotAttachPatch.cs b/project/Aki.Custom/BTR/Patches/BTRBotAttachPatch.cs index d497442..d1cce20 100644 --- a/project/Aki.Custom/BTR/Patches/BTRBotAttachPatch.cs +++ b/project/Aki.Custom/BTR/Patches/BTRBotAttachPatch.cs @@ -27,27 +27,36 @@ namespace Aki.Custom.BTR.Patches private static bool PatchPrefix(BTRTurretView __instance, int btrBotId) { var gameWorld = Singleton.Instance; - - var __instanceTupleField = (ValueTuple)AccessTools.Field(__instance.GetType(), "valueTuple_0") - .GetValue(__instance); - - if (!__instanceTupleField.Item2) - { - var __instanceMethod = AccessTools.Method(__instance.GetType(), "method_1"); - __instanceMethod.Invoke(__instance, new object[] { btrBotId }); - } - if (!__instanceTupleField.Item2) + if (gameWorld == null) { + Logger.LogError("[AKI-BTR] BTRBotAttachPatch - GameWorld is null"); return false; } - var btrBot = gameWorld.BtrController.BotShooterBtr?.GetPlayer; - if (btrBot == null) + var btrTurretViewTupleField = (ValueTuple)AccessTools.Field(__instance.GetType(), "valueTuple_0").GetValue(__instance); + if (!btrTurretViewTupleField.Item2) { + __instance.method_1(btrBotId); return false; } + + var btrController = gameWorld.BtrController; + if (btrController == null) + { + Logger.LogError("[AKI-BTR] BTRBotAttachPatch - BtrController is null"); + return false; + } + + var btrBotShooter = btrController.BotShooterBtr; + if (btrBotShooter == null) + { + Logger.LogError("[AKI-BTR] BTRBotAttachPatch - BtrBotShooter is null"); + return false; + } + try { + var btrBot = btrBotShooter.GetPlayer; var botRootTransform = __instance.BotRoot; btrBot.Transform.position = botRootTransform.position; @@ -62,7 +71,7 @@ namespace Aki.Custom.BTR.Patches } catch { - ConsoleScreen.LogError("[AKI-BTR]: Could not finish BtrBot initialization. Check logs."); + ConsoleScreen.LogError("[AKI-BTR] Could not finish BtrBot initialization. Check logs."); throw; } } diff --git a/project/Aki.Custom/BTR/Patches/BTRBotInitPatch.cs b/project/Aki.Custom/BTR/Patches/BTRBotInitPatch.cs index 4102446..4598955 100644 --- a/project/Aki.Custom/BTR/Patches/BTRBotInitPatch.cs +++ b/project/Aki.Custom/BTR/Patches/BTRBotInitPatch.cs @@ -22,7 +22,7 @@ namespace Aki.Custom.BTR.Patches { protected override MethodBase GetTargetMethod() { - return AccessTools.Method(typeof(BTRTurretView), "method_1"); + return AccessTools.Method(typeof(BTRTurretView), nameof(BTRTurretView.method_1)); } [PatchPostfix] @@ -31,6 +31,7 @@ namespace Aki.Custom.BTR.Patches var gameWorld = Singleton.Instance; if (gameWorld == null) { + Logger.LogError("[AKI-BTR] BTRBotInitPatch - GameWorld is null"); return; } @@ -55,7 +56,7 @@ namespace Aki.Custom.BTR.Patches foreach (var text in currentWeaponPrefab.RemoveChildrenOf) { var transform = currentWeaponPrefab.transform.FindTransform(text); - transform?.gameObject.SetActive(false); + transform.gameObject.SetActive(false); } } foreach (var renderer in currentWeaponPrefab.GetComponentsInChildren()) diff --git a/project/Aki.Custom/BTR/Patches/BTREndRaidItemDeliveryPatch.cs b/project/Aki.Custom/BTR/Patches/BTREndRaidItemDeliveryPatch.cs index afc722a..8eec3b3 100644 --- a/project/Aki.Custom/BTR/Patches/BTREndRaidItemDeliveryPatch.cs +++ b/project/Aki.Custom/BTR/Patches/BTREndRaidItemDeliveryPatch.cs @@ -30,10 +30,15 @@ namespace Aki.Custom.BTR.Patches public static void PatchPrefix() { GameWorld gameWorld = Singleton.Instance; - var player = gameWorld?.MainPlayer; - if (gameWorld == null || player == null) + if (gameWorld == null) { - Logger.LogError("[AKI-BTR] End Raid - GameWorld or Player is null"); + Logger.LogError("[AKI-BTR] BTREndRaidItemDeliveryPatch - GameWorld is null"); + return; + } + var player = gameWorld.MainPlayer; + if (player == null) + { + Logger.LogError("[AKI-BTR] BTREndRaidItemDeliveryPatch - Player is null"); return; } @@ -45,7 +50,7 @@ namespace Aki.Custom.BTR.Patches if (!gameWorld.BtrController.HasNonEmptyTransferContainer(player.Profile.Id)) { - Logger.LogDebug("[AKI-BTR] End Raid - No items in transfer container"); + Logger.LogDebug("[AKI-BTR] BTREndRaidItemDeliveryPatch - No items in transfer container"); return; } diff --git a/project/Aki.Custom/BTR/Patches/BTRExtractPassengersPatch.cs b/project/Aki.Custom/BTR/Patches/BTRExtractPassengersPatch.cs index 4335bea..b90bb0b 100644 --- a/project/Aki.Custom/BTR/Patches/BTRExtractPassengersPatch.cs +++ b/project/Aki.Custom/BTR/Patches/BTRExtractPassengersPatch.cs @@ -24,6 +24,7 @@ namespace Aki.Custom.BTR.Patches var btrSide = btrManager.LastInteractedBtrSide; if (btrSide == null) { + Logger.LogError($"[AKI-BTR] BTRExtractPassengersPatch - btrSide is null"); return; } @@ -35,11 +36,12 @@ namespace Aki.Custom.BTR.Patches BTRView btrView = gameWorld.BtrController.BtrView; if (btrView == null) { + Logger.LogError($"[AKI-BTR] BTRExtractPassengersPatch - btrView is null"); return; } - btrManager.OnPlayerInteractDoor(interactionBtrPacket); btrView.Interaction(player, interactionBtrPacket); + btrManager.OnPlayerInteractDoor(interactionBtrPacket); } } } diff --git a/project/Aki.Custom/BTR/Patches/BTRInteractionPatch.cs b/project/Aki.Custom/BTR/Patches/BTRInteractionPatch.cs index 82a14fd..d1fbca6 100644 --- a/project/Aki.Custom/BTR/Patches/BTRInteractionPatch.cs +++ b/project/Aki.Custom/BTR/Patches/BTRInteractionPatch.cs @@ -47,11 +47,12 @@ namespace Aki.Custom.BTR.Patches BTRView btrView = gameWorld.BtrController.BtrView; if (btrView == null) { + Logger.LogError("[AKI-BTR] BTRInteractionPatch - btrView is null"); return; } - btrManager.OnPlayerInteractDoor(interactionBtrPacket); btrView.Interaction(__instance, interactionBtrPacket); + btrManager.OnPlayerInteractDoor(interactionBtrPacket); } } } diff --git a/project/Aki.Custom/BTR/Patches/BTRIsDoorsClosedPatch.cs b/project/Aki.Custom/BTR/Patches/BTRIsDoorsClosedPatch.cs index 95030f3..379b893 100644 --- a/project/Aki.Custom/BTR/Patches/BTRIsDoorsClosedPatch.cs +++ b/project/Aki.Custom/BTR/Patches/BTRIsDoorsClosedPatch.cs @@ -16,9 +16,17 @@ namespace Aki.Custom.BTR.Patches [PatchPrefix] private static bool PatchPrefix(ref bool __result) { - var serverSideBTR = Singleton.Instance?.BtrController.BtrVehicle; + var gameWorld = Singleton.Instance; + if (gameWorld == null) + { + Logger.LogError("[AKI-BTR] BTRIsDoorsClosedPatch - GameWorld is null"); + return true; + } + + var serverSideBTR = gameWorld.BtrController.BtrVehicle; if (serverSideBTR == null) { + Logger.LogError("[AKI-BTR] BTRIsDoorsClosedPatch - serverSideBTR is null"); return true; } diff --git a/project/Aki.Custom/BTR/Patches/BTRPatch.cs b/project/Aki.Custom/BTR/Patches/BTRPatch.cs index fcff139..765939d 100644 --- a/project/Aki.Custom/BTR/Patches/BTRPatch.cs +++ b/project/Aki.Custom/BTR/Patches/BTRPatch.cs @@ -40,7 +40,7 @@ namespace Aki.Custom.BTR.Patches } catch (System.Exception) { - ConsoleScreen.LogError("[AKI-BTR]: Exception thrown, check logs."); + ConsoleScreen.LogError("[AKI-BTR] Exception thrown, check logs."); throw; } } diff --git a/project/Aki.Custom/BTR/Patches/BTRPathLoadPatch.cs b/project/Aki.Custom/BTR/Patches/BTRPathLoadPatch.cs index ec6602d..455fffe 100644 --- a/project/Aki.Custom/BTR/Patches/BTRPathLoadPatch.cs +++ b/project/Aki.Custom/BTR/Patches/BTRPathLoadPatch.cs @@ -16,7 +16,7 @@ namespace Aki.Custom.BTR.Patches { _statusProperty = AccessTools.Property(typeof(AbstractGame), nameof(AbstractGame.Status)); - return AccessTools.Method(typeof(BTRControllerClass), "method_1"); + return AccessTools.Method(typeof(BTRControllerClass), nameof(BTRControllerClass.method_1)); } [PatchPrefix] diff --git a/project/Aki.Custom/BTR/Patches/BTRReceiveDamageInfoPatch.cs b/project/Aki.Custom/BTR/Patches/BTRReceiveDamageInfoPatch.cs index 6493fec..d73d027 100644 --- a/project/Aki.Custom/BTR/Patches/BTRReceiveDamageInfoPatch.cs +++ b/project/Aki.Custom/BTR/Patches/BTRReceiveDamageInfoPatch.cs @@ -24,6 +24,7 @@ namespace Aki.Custom.BTR.Patches var botEventHandler = Singleton.Instance; if (botEventHandler == null) { + Logger.LogError($"[AKI-BTR] BTRReceiveDamageInfoPatch - BotEventHandler is null"); return; } diff --git a/project/Aki.Custom/BTR/Utils/BTRUtil.cs b/project/Aki.Custom/BTR/Utils/BTRUtil.cs index e02b7b2..26f0b4f 100644 --- a/project/Aki.Custom/BTR/Utils/BTRUtil.cs +++ b/project/Aki.Custom/BTR/Utils/BTRUtil.cs @@ -1,5 +1,5 @@ using Aki.Common.Http; -using Aki.Debugging.BTR.Models; +using Aki.Custom.BTR.Models; using Comfort.Common; using EFT; using EFT.InventoryLogic; @@ -23,10 +23,10 @@ namespace Aki.Custom.BTR.Utils return Singleton.Instance.CreateItem(id, tplId, null); } - public static BtrConfigModel GetConfigFromServer() + public static BTRConfigModel GetConfigFromServer() { string json = RequestHandler.GetJson("/singleplayer/btr/config"); - return JsonConvert.DeserializeObject(json); + return JsonConvert.DeserializeObject(json); } } }