diff --git a/Fika.Core/Coop/BTR/FikaBTRManager_Host.cs b/Fika.Core/Coop/BTR/FikaBTRManager_Host.cs index e0ef2313..b5bcbb52 100644 --- a/Fika.Core/Coop/BTR/FikaBTRManager_Host.cs +++ b/Fika.Core/Coop/BTR/FikaBTRManager_Host.cs @@ -456,7 +456,7 @@ private void UpdateBTRSideDoorState(byte state) { try { - BTRSide btrSide = lastInteractPlayer.BtrInteractionSide ?? lastInteractedBtrSide; + BTRSide btrSide = lastInteractPlayer.BtrInteractionSide != null ? lastInteractPlayer.BtrInteractionSide : lastInteractedBtrSide; byte sideId = btrClientSide.GetSideId(btrSide); switch (sideId) { diff --git a/Fika.Core/Coop/BotClasses/CoopBotHealthController.cs b/Fika.Core/Coop/BotClasses/CoopBotHealthController.cs index 67876d7f..15c779f2 100644 --- a/Fika.Core/Coop/BotClasses/CoopBotHealthController.cs +++ b/Fika.Core/Coop/BotClasses/CoopBotHealthController.cs @@ -22,11 +22,11 @@ public override void SendNetworkSyncPacket(GStruct346 packet) { if (packet.SyncType == GStruct346.ESyncType.IsAlive && !packet.Data.IsAlive.IsAlive) { - coopBot?.PacketSender?.HealthSyncPackets.Enqueue(coopBot.SetupDeathPacket(packet)); + coopBot.PacketSender.HealthSyncPackets.Enqueue(coopBot.SetupDeathPacket(packet)); return; } - coopBot?.PacketSender?.HealthSyncPackets.Enqueue(new(coopBot.NetId) + coopBot.PacketSender.HealthSyncPackets.Enqueue(new(coopBot.NetId) { Packet = packet }); diff --git a/Fika.Core/Coop/BotClasses/CoopBotInventoryController.cs b/Fika.Core/Coop/BotClasses/CoopBotInventoryController.cs index 3dd9336a..03410663 100644 --- a/Fika.Core/Coop/BotClasses/CoopBotInventoryController.cs +++ b/Fika.Core/Coop/BotClasses/CoopBotInventoryController.cs @@ -33,7 +33,7 @@ public override void Execute(GClass2837 operation, [CanBeNull] Callback callback OperationBytes = opBytes }; - CoopBot.PacketSender?.InventoryPackets?.Enqueue(packet); + CoopBot.PacketSender.InventoryPackets.Enqueue(packet); } } } diff --git a/Fika.Core/Coop/ClientClasses/CoopClientHealthController.cs b/Fika.Core/Coop/ClientClasses/CoopClientHealthController.cs index 8ab98cf0..1263336e 100644 --- a/Fika.Core/Coop/ClientClasses/CoopClientHealthController.cs +++ b/Fika.Core/Coop/ClientClasses/CoopClientHealthController.cs @@ -22,11 +22,11 @@ public override void SendNetworkSyncPacket(GStruct346 packet) { if (packet.SyncType == GStruct346.ESyncType.IsAlive && !packet.Data.IsAlive.IsAlive) { - coopPlayer?.PacketSender?.HealthSyncPackets.Enqueue(coopPlayer.SetupDeathPacket(packet)); + coopPlayer.PacketSender.HealthSyncPackets.Enqueue(coopPlayer.SetupDeathPacket(packet)); return; } - coopPlayer?.PacketSender?.HealthSyncPackets.Enqueue(new(coopPlayer.NetId) + coopPlayer.PacketSender.HealthSyncPackets.Enqueue(new(coopPlayer.NetId) { Packet = packet }); diff --git a/Fika.Core/Coop/ClientClasses/CoopClientInventoryController.cs b/Fika.Core/Coop/ClientClasses/CoopClientInventoryController.cs index 355164a4..d8edf451 100644 --- a/Fika.Core/Coop/ClientClasses/CoopClientInventoryController.cs +++ b/Fika.Core/Coop/ClientClasses/CoopClientInventoryController.cs @@ -69,7 +69,7 @@ public override void Execute(GClass2837 operation, [CanBeNull] Callback callback OperationBytes = opBytes }; - CoopPlayer.PacketSender?.InventoryPackets?.Enqueue(packet); + CoopPlayer.PacketSender.InventoryPackets.Enqueue(packet); return; } @@ -113,7 +113,7 @@ public override void Execute(GClass2837 operation, [CanBeNull] Callback callback OperationBytes = opBytes }; - CoopPlayer.PacketSender?.InventoryPackets?.Enqueue(packet); + CoopPlayer.PacketSender.InventoryPackets.Enqueue(packet); } } diff --git a/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientFirearmController.cs b/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientFirearmController.cs index e442c781..91802259 100644 --- a/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientFirearmController.cs +++ b/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientFirearmController.cs @@ -95,7 +95,7 @@ public override bool CheckChamber() bool flag = base.CheckChamber(); if (flag) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { CheckChamber = true }); @@ -108,7 +108,7 @@ public override bool CheckAmmo() bool flag = base.CheckAmmo(); if (flag) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { CheckAmmo = true }); @@ -121,7 +121,7 @@ public override bool ChangeFireMode(Weapon.EFireMode fireMode) bool flag = base.ChangeFireMode(fireMode); if (flag) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { ChangeFireMode = true, FireMode = fireMode @@ -133,7 +133,7 @@ public override bool ChangeFireMode(Weapon.EFireMode fireMode) public override void ChangeAimingMode() { base.ChangeAimingMode(); - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { ToggleAim = true, AimingIndex = IsAiming ? Item.AimIndex.Value : -1 @@ -147,7 +147,7 @@ public override void SetAim(bool value) base.SetAim(value); if (IsAiming != isAiming || aimingInterruptedByOverlap) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { ToggleAim = true, AimingIndex = IsAiming ? Item.AimIndex.Value : -1 @@ -160,7 +160,7 @@ public override bool CheckFireMode() bool flag = base.CheckFireMode(); if (flag) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { CheckFireMode = true }); @@ -171,7 +171,7 @@ public override bool CheckFireMode() public override void DryShot(int chamberIndex = 0, bool underbarrelShot = false) { base.DryShot(chamberIndex, underbarrelShot); - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasShotInfo = true, ShotInfoPacket = new() @@ -190,7 +190,7 @@ public override bool ExamineWeapon() bool flag = base.ExamineWeapon(); if (flag) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { ExamineWeapon = true }); @@ -224,7 +224,7 @@ public override void InitiateShot(GInterface322 weapon, BulletClass ammo, Vector break; } - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasShotInfo = true, ShotInfoPacket = new() @@ -259,7 +259,7 @@ public override void QuickReloadMag(MagazineClass magazine, Callback callback) base.QuickReloadMag(magazine, callback); - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasQuickReloadMagPacket = true, QuickReloadMagPacket = new() @@ -312,7 +312,7 @@ public override void ReloadGrenadeLauncher(GClass2495 ammoPack, Callback callbac string[] reloadingAmmoIds = ammoPack.GetReloadingAmmoIds(); - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { ReloadLauncher = new() { @@ -352,7 +352,7 @@ public override void SetLightsState(GStruct163[] lightsStates, bool force = fals { if (force || CurrentOperation.CanChangeLightState(lightsStates)) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { ToggleTacticalCombo = true, LightStatesPacket = new() @@ -372,7 +372,7 @@ public override void SetScopeMode(GStruct164[] scopeStates) return; } - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { ChangeSightMode = true, ScopeStatesPacket = new() @@ -408,7 +408,7 @@ public override void ShotMisfired(BulletClass ammo, Weapon.EMalfunctionState mal break; } - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasShotInfo = true, ShotInfoPacket = new() @@ -429,7 +429,7 @@ public override bool ToggleLauncher() bool flag = base.ToggleLauncher(); if (flag) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { ToggleLauncher = true }); @@ -440,7 +440,7 @@ public override bool ToggleLauncher() public override void Loot(bool p) { base.Loot(p); - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { Loot = p }); @@ -449,7 +449,7 @@ public override void Loot(bool p) public override void SetInventoryOpened(bool opened) { base.SetInventoryOpened(opened); - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { EnableInventory = true, InventoryStatus = opened @@ -459,7 +459,7 @@ public override void SetInventoryOpened(bool opened) public override void ChangeLeftStance() { base.ChangeLeftStance(); - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasStanceChange = true, LeftStanceState = coopPlayer.MovementContext.LeftStanceEnabled @@ -473,7 +473,7 @@ public override void SendStartOneShotFire() public override void CreateFlareShot(BulletClass flareItem, Vector3 shotPosition, Vector3 forward) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasFlareShot = true, FlareShotPacket = new() @@ -488,7 +488,7 @@ public override void CreateFlareShot(BulletClass flareItem, Vector3 shotPosition private void SendAbortReloadPacket(int amount) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasReloadWithAmmoPacket = true, ReloadWithAmmo = new() @@ -507,7 +507,7 @@ public override void RollCylinder(bool rollToZeroCamora) return; } - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasRollCylinder = true, RollToZeroCamora = rollToZeroCamora @@ -518,7 +518,7 @@ public override void RollCylinder(bool rollToZeroCamora) private void SendEndReloadPacket(int amount) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasReloadWithAmmoPacket = true, ReloadWithAmmo = new() @@ -532,7 +532,7 @@ private void SendEndReloadPacket(int amount) private void SendBoltActionReloadPacket() { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { ReloadBoltAction = true }); @@ -684,7 +684,7 @@ public void Process(IResult error) if (error.Succeed) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasReloadMagPacket = true, ReloadMagPacket = new() @@ -709,7 +709,7 @@ private class ReloadCylinderMagazineHandler(CoopPlayer coopPlayer, CoopClientFir public void Process(IResult error) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasReloadWithAmmoPacket = true, ReloadWithAmmo = new() @@ -756,7 +756,7 @@ public void Process(IResult error) if (coopPlayer.HealthController.IsAlive) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasReloadBarrelsPacket = true, ReloadBarrels = new() @@ -779,7 +779,7 @@ public void Process(IResult error) { if (error.Succeed) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasReloadWithAmmoPacket = true, ReloadWithAmmo = new() diff --git a/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientGrenadeController.cs b/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientGrenadeController.cs index ee72f5d9..a34d3617 100644 --- a/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientGrenadeController.cs +++ b/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientGrenadeController.cs @@ -24,7 +24,7 @@ public static CoopClientGrenadeController Create(CoopPlayer player, GrenadeClass public override void ExamineWeapon() { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasGrenadePacket = true, GrenadePacket = new() @@ -37,7 +37,7 @@ public override void ExamineWeapon() public override void HighThrow() { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasGrenadePacket = true, GrenadePacket = new() @@ -50,7 +50,7 @@ public override void HighThrow() public override void LowThrow() { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasGrenadePacket = true, GrenadePacket = new() @@ -63,7 +63,7 @@ public override void LowThrow() public override void PullRingForHighThrow() { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasGrenadePacket = true, GrenadePacket = new() @@ -76,7 +76,7 @@ public override void PullRingForHighThrow() public override void PullRingForLowThrow() { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasGrenadePacket = true, GrenadePacket = new() @@ -89,7 +89,7 @@ public override void PullRingForLowThrow() public override void vmethod_2(float timeSinceSafetyLevelRemoved, Vector3 position, Quaternion rotation, Vector3 force, bool lowThrow) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasGrenadePacket = true, GrenadePacket = new() @@ -109,7 +109,7 @@ public override void ActualDrop(Result controller, float { // TODO: Override Class1025 - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { CancelGrenade = true }); diff --git a/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientKnifeController.cs b/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientKnifeController.cs index df26a601..273560a8 100644 --- a/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientKnifeController.cs +++ b/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientKnifeController.cs @@ -23,7 +23,7 @@ public override void ExamineWeapon() { base.ExamineWeapon(); - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasKnifePacket = true, KnifePacket = new() @@ -39,7 +39,7 @@ public override bool MakeKnifeKick() if (knifeKick) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasKnifePacket = true, KnifePacket = new() @@ -58,7 +58,7 @@ public override bool MakeAlternativeKick() if (alternateKnifeKick) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasKnifePacket = true, KnifePacket = new() @@ -75,7 +75,7 @@ public override void BrakeCombo() { base.BrakeCombo(); - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasKnifePacket = true, KnifePacket = new() diff --git a/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientQuickGrenadeController.cs b/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientQuickGrenadeController.cs index 131a71b1..aa1d8316 100644 --- a/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientQuickGrenadeController.cs +++ b/Fika.Core/Coop/ClientClasses/HandsControllers/CoopClientQuickGrenadeController.cs @@ -25,7 +25,7 @@ public static CoopClientQuickGrenadeController Create(CoopPlayer player, Grenade public override void vmethod_2(float timeSinceSafetyLevelRemoved, Vector3 position, Quaternion rotation, Vector3 force, bool lowThrow) { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasGrenadePacket = true, GrenadePacket = new() diff --git a/Fika.Core/Coop/Components/CoopExfilManager.cs b/Fika.Core/Coop/Components/CoopExfilManager.cs index 7e3ef0ee..b7a587e4 100644 --- a/Fika.Core/Coop/Components/CoopExfilManager.cs +++ b/Fika.Core/Coop/Components/CoopExfilManager.cs @@ -201,16 +201,16 @@ private void ExfiltrationPoint_OnStatusChanged(ExfiltrationPoint point, EExfiltr ExfilStartTime = point.ExfiltrationStartTime }; - NetDataWriter writer = mainPlayer.PacketSender?.Writer; + NetDataWriter writer = mainPlayer.PacketSender.Writer; writer.Reset(); if (MatchmakerAcceptPatches.IsServer) { - mainPlayer.PacketSender?.Server?.SendDataToAll(writer, ref packet, DeliveryMethod.ReliableOrdered); + mainPlayer.PacketSender.Server.SendDataToAll(writer, ref packet, DeliveryMethod.ReliableOrdered); } else if (MatchmakerAcceptPatches.IsClient) { - mainPlayer.PacketSender?.Client?.SendData(writer, ref packet, DeliveryMethod.ReliableOrdered); + mainPlayer.PacketSender.Client.SendData(writer, ref packet, DeliveryMethod.ReliableOrdered); } } countdownPoints.Add(point); diff --git a/Fika.Core/Coop/Components/CoopHandler.cs b/Fika.Core/Coop/Components/CoopHandler.cs index 8ef25c45..25fad416 100644 --- a/Fika.Core/Coop/Components/CoopHandler.cs +++ b/Fika.Core/Coop/Components/CoopHandler.cs @@ -315,7 +315,7 @@ private void ReadFromServerCharacters() if (writer != null) { writer.Reset(); - Singleton.Instance?.SendData(writer, ref requestPacket, DeliveryMethod.ReliableOrdered); + Singleton.Instance.SendData(writer, ref requestPacket, DeliveryMethod.ReliableOrdered); } } @@ -353,15 +353,15 @@ await Singleton.Instance.LoadBundlesAndCreatePools(PoolManager.Pool { if (x.IsCompleted) { - Logger.LogDebug($"SpawnPlayer::{spawnObject.Profile.Info.Nickname}::Load Complete."); + Logger.LogDebug($"SpawnPlayer::{spawnObject.Profile.Info.Nickname}::Load Complete"); } else if (x.IsFaulted) { - Logger.LogError($"SpawnPlayer::{spawnObject.Profile.Info.Nickname}::Load Failed."); + Logger.LogError($"SpawnPlayer::{spawnObject.Profile.Info.Nickname}::Load Failed"); } else if (x.IsCanceled) { - Logger.LogError($"SpawnPlayer::{spawnObject.Profile.Info.Nickname}::Load Cancelled?"); + Logger.LogError($"SpawnPlayer::{spawnObject.Profile.Info.Nickname}::Load Cancelled"); } }); diff --git a/Fika.Core/Coop/GameMode/AMPTGame.cs b/Fika.Core/Coop/GameMode/AFikaGame.cs similarity index 90% rename from Fika.Core/Coop/GameMode/AMPTGame.cs rename to Fika.Core/Coop/GameMode/AFikaGame.cs index 54ff351c..75ae3cb4 100644 --- a/Fika.Core/Coop/GameMode/AMPTGame.cs +++ b/Fika.Core/Coop/GameMode/AFikaGame.cs @@ -23,7 +23,10 @@ BotsController IBotGame.BotsController { get { - BotsController ??= (BotsController)GetType().GetFields().Where(x => x.FieldType == typeof(BotsController)).FirstOrDefault().GetValue(this); + if (BotsController == null) + { + BotsController = (BotsController)GetType().GetFields().Where(x => x.FieldType == typeof(BotsController)).FirstOrDefault().GetValue(this); + } return BotsController; } } @@ -34,8 +37,11 @@ public BotsController PBotsController { get { - BotsController ??= (BotsController)GetType().GetFields().Where(x => x.FieldType == typeof(BotsController)).FirstOrDefault().GetValue(this); - return BotsController; + if (BotsController == null) + { + BotsController = (BotsController)GetType().GetFields().Where(x => x.FieldType == typeof(BotsController)).FirstOrDefault().GetValue(this); + } + return BotsController; } } diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 768c2422..76e76a27 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -370,7 +370,7 @@ private async Task CreateBot(Profile profile, Vector3 position) netId = server.PopNetId(); SendCharacterPacket packet = new(new FikaSerialization.PlayerInfoPacket() { Profile = profile }, true, true, position, netId); - Singleton.Instance?.SendDataToAll(new NetDataWriter(), ref packet, LiteNetLib.DeliveryMethod.ReliableUnordered); + Singleton.Instance.SendDataToAll(new NetDataWriter(), ref packet, LiteNetLib.DeliveryMethod.ReliableUnordered); if (server.NetServer.ConnectedPeersCount > 0) { @@ -517,7 +517,10 @@ private void DespawnBot(CoopHandler coopHandler, Player bot) BotsController.Bots.Remove(botOwner); bot.HealthController.DiedEvent -= botOwner.method_6; // Unsubscribe from the event to prevent errors. BotUnspawn(botOwner); - botOwner?.Dispose(); + if (botOwner != null) + { + botOwner.Dispose(); + } CoopPlayer coopPlayer = (CoopPlayer)bot; coopHandler.Players.Remove(coopPlayer.NetId); @@ -548,7 +551,10 @@ private async void DeployScreen(float timeBeforeDeploy) Destroy(fikaStartButton); } - dynamicAI?.AddHumans(); + if (dynamicAI != null) + { + dynamicAI.AddHumans(); + } SetStatusModel status = new(coopHandler.MyPlayer.ProfileId, LobbyEntry.ELobbyStatus.IN_GAME); await FikaRequestHandler.UpdateSetStatus(status); @@ -563,7 +569,10 @@ private async void DeployScreen(float timeBeforeDeploy) MatchmakerAcceptPatches.GClass3163.ChangeStatus("Waiting for other players to finish loading..."); - fikaStartButton?.SetActive(true); + if (fikaStartButton != null) + { + fikaStartButton.SetActive(true); + } if (MatchmakerAcceptPatches.IsServer) { @@ -598,7 +607,10 @@ private async void DeployScreen(float timeBeforeDeploy) Singleton.Instance.SendDataToAll(writer, ref syncPacket, LiteNetLib.DeliveryMethod.ReliableUnordered); } - dynamicAI?.AddHumans(); + if (dynamicAI != null) + { + dynamicAI.AddHumans(); + } } else if (MatchmakerAcceptPatches.IsClient) { @@ -790,10 +802,16 @@ public override async Task vmethod_2(int playerId, Vector3 position writer.Reset(); Singleton.Instance.SendDataToAll(writer, ref packet, LiteNetLib.DeliveryMethod.ReliableOrdered); - fikaStartButton?.SetActive(false); + if (fikaStartButton != null) + { + fikaStartButton.SetActive(false); + } }); Traverse.Create(startButtonComponent).Field("OnClick").SetValue(newStartEvent); - customButton?.SetActive(true); + if (customButton != null) + { + customButton.SetActive(true); + } fikaStartButton = customButtonStart; } } @@ -827,7 +845,10 @@ public override async Task vmethod_2(int playerId, Vector3 position await WaitForPlayers(); Destroy(customButton); - fikaStartButton?.SetActive(false); + if (fikaStartButton != null) + { + fikaStartButton.SetActive(false); + } myPlayer.ActiveHealthController.DiedEvent += MainPlayerDied; @@ -962,7 +983,10 @@ private async Task WaitForPlayers() { Logger.LogInfo("Starting task to wait for other players."); - MatchmakerAcceptPatches.GClass3163?.ChangeStatus($"Initializing Coop Game..."); + if (MatchmakerAcceptPatches.GClass3163 != null) + { + MatchmakerAcceptPatches.GClass3163.ChangeStatus($"Initializing Coop Game..."); + } int numbersOfPlayersToWaitFor = 0; if (MatchmakerAcceptPatches.IsServer) @@ -1193,14 +1217,20 @@ public override IEnumerator vmethod_4(float startDelay, BotControllerSettings co if (Location_0.OldSpawn && wavesSpawnScenario_0.SpawnWaves != null && wavesSpawnScenario_0.SpawnWaves.Length != 0) { Logger.LogInfo("Running old spawn system. Waves: " + wavesSpawnScenario_0.SpawnWaves.Length); - wavesSpawnScenario_0?.Run(EBotsSpawnMode.Anyway); + if (wavesSpawnScenario_0 != null) + { + wavesSpawnScenario_0.Run(EBotsSpawnMode.Anyway); + } } if (Location_0.NewSpawn) { Logger.LogInfo("Running new spawn system."); - nonWavesSpawnScenario_0?.Run(); - } + if (nonWavesSpawnScenario_0 != null) + { + nonWavesSpawnScenario_0.Run(); + } + } GClass579.Run(EBotsSpawnMode.Anyway); @@ -1208,9 +1238,18 @@ public override IEnumerator vmethod_4(float startDelay, BotControllerSettings co } else { - wavesSpawnScenario_0?.Stop(); - nonWavesSpawnScenario_0?.Stop(); - GClass579?.Stop(); + if (wavesSpawnScenario_0 != null) + { + wavesSpawnScenario_0.Stop(); + } + if (nonWavesSpawnScenario_0 != null) + { + nonWavesSpawnScenario_0.Stop(); + } + if (GClass579 != null) + { + GClass579.Stop(); + } } yield return new WaitForEndOfFrame(); @@ -1421,11 +1460,11 @@ public void Extract(Player player, ExfiltrationPoint point) { if (MatchmakerAcceptPatches.IsClient) { - Singleton.Instance?.SendData(new NetDataWriter(), ref genericPacket, LiteNetLib.DeliveryMethod.ReliableOrdered); + Singleton.Instance.SendData(new NetDataWriter(), ref genericPacket, LiteNetLib.DeliveryMethod.ReliableOrdered); } else if (MatchmakerAcceptPatches.IsServer) { - Singleton.Instance?.SendDataToAll(new NetDataWriter(), ref genericPacket, LiteNetLib.DeliveryMethod.ReliableOrdered); + Singleton.Instance.SendDataToAll(new NetDataWriter(), ref genericPacket, LiteNetLib.DeliveryMethod.ReliableOrdered); ClearHostAI(player); } } @@ -1522,7 +1561,7 @@ public override void Stop(string profileId, ExitStatus exitStatus, string exitNa Logger.LogInfo("CoopGame::Stop"); CoopPlayer myPlayer = (CoopPlayer)Singleton.Instance.MainPlayer; - myPlayer.PacketSender?.DestroyThis(); + myPlayer.PacketSender.DestroyThis(); if (myPlayer.Side != EPlayerSide.Savage) { @@ -1555,9 +1594,18 @@ public override void Stop(string profileId, ExitStatus exitStatus, string exitNa botsController_0.DestroyInfo(gparam_0.Player); } - GClass579?.Stop(); - nonWavesSpawnScenario_0?.Stop(); - wavesSpawnScenario_0?.Stop(); + if (GClass579 != null) + { + GClass579.Stop(); + } + if (nonWavesSpawnScenario_0 != null) + { + nonWavesSpawnScenario_0.Stop(); + } + if (wavesSpawnScenario_0 != null) + { + wavesSpawnScenario_0.Stop(); + } try { @@ -1631,7 +1679,10 @@ public override void Stop(string profileId, ExitStatus exitStatus, string exitNa { gameUI.TimerPanel.Close(); } - EnvironmentManager.Instance?.Stop(); + if (EnvironmentManager.Instance != null) + { + EnvironmentManager.Instance.Stop(); + } MonoBehaviourSingleton.Instance.StartBlackScreenShow(1f, 1f, new Action(stopManager.method_0)); GClass549.Config.UseSpiritPlayer = false; } @@ -1641,7 +1692,7 @@ private void StopFromError(string profileId, ExitStatus exitStatus) Logger.LogInfo("CoopGame::StopFromError"); CoopPlayer myPlayer = (CoopPlayer)Singleton.Instance.MainPlayer; - myPlayer.PacketSender?.DestroyThis(); + myPlayer.PacketSender.DestroyThis(); string exitName = null; float delay = 0f; @@ -1676,11 +1727,18 @@ private void StopFromError(string profileId, ExitStatus exitStatus) Destroy(CoopHandler.CoopHandlerParent); } - GClass579?.Stop(); - - nonWavesSpawnScenario_0?.Stop(); - - wavesSpawnScenario_0?.Stop(); + if (GClass579 != null) + { + GClass579.Stop(); + } + if (nonWavesSpawnScenario_0 != null) + { + nonWavesSpawnScenario_0.Stop(); + } + if (wavesSpawnScenario_0 != null) + { + wavesSpawnScenario_0.Stop(); + } ErrorExitManager stopManager = new() { @@ -1702,17 +1760,29 @@ private void StopFromError(string profileId, ExitStatus exitStatus) } } - exfilManager?.Stop(); + if (exfilManager != null) + { + exfilManager.Stop(); + } Status = GameStatus.Stopping; - GameTimer?.TryStop(); - endByExitTrigger?.Stop(); + if (GameTimer != null) + { + GameTimer.TryStop(); + } + if (endByExitTrigger != null) + { + endByExitTrigger.Stop(); + } if (gameUI.TimerPanel.enabled) { gameUI.TimerPanel.Close(); } - EnvironmentManager.Instance?.Stop(); + if (EnvironmentManager.Instance != null) + { + EnvironmentManager.Instance.Stop(); + } MonoBehaviourSingleton.Instance.StartBlackScreenShow(1f, 1f, new Action(stopManager.ExitOverride)); GClass549.Config.UseSpiritPlayer = false; } @@ -1749,9 +1819,9 @@ public override void Dispose() if (MatchmakerAcceptPatches.IsServer) { CoopPlayer coopPlayer = (CoopPlayer)Singleton.Instance.MainPlayer; - coopPlayer?.PacketSender.DestroyThis(); + coopPlayer.PacketSender.DestroyThis(); - Singleton.Instance?.NetServer.Stop(); + Singleton.Instance.NetServer.Stop(); Singleton.TryRelease(Singleton.Instance); FikaDynamicAI newDynamicAI = gameObject.GetComponent(); @@ -1764,7 +1834,7 @@ public override void Dispose() } else if (MatchmakerAcceptPatches.IsClient) { - Singleton.Instance?.NetClient.Stop(); + Singleton.Instance.NetClient.Stop(); Singleton.TryRelease(Singleton.Instance); // Resetting this array to null forces the game to re-allocate it if the client hosts the next session @@ -1807,12 +1877,15 @@ public void ExitOverride() { instance.CloseAllScreensForced(); } - baseLocalGame_0?.CleanUp(); - if (baseLocalGame_0 is not null) + if (baseLocalGame_0 != null) { + baseLocalGame_0.CleanUp(); baseLocalGame_0.Status = GameStatus.Stopped; } - MonoBehaviourSingleton.Instance?.FadeOutVolumeAfterRaid(); + if (MonoBehaviourSingleton.Instance != null) + { + MonoBehaviourSingleton.Instance.FadeOutVolumeAfterRaid(); + } MonoBehaviour instance2 = StaticManager.Instance; float num = delay; Action action; diff --git a/Fika.Core/Coop/PacketHandlers/BotPacketSender.cs b/Fika.Core/Coop/PacketHandlers/BotPacketSender.cs index 02fc1b1e..ef51e3eb 100644 --- a/Fika.Core/Coop/PacketHandlers/BotPacketSender.cs +++ b/Fika.Core/Coop/PacketHandlers/BotPacketSender.cs @@ -50,7 +50,7 @@ protected void FixedUpdate() player.hasGround, player.CurrentSurface, player.MovementContext.SurfaceNormal); Writer.Reset(); - Server?.SendDataToAll(Writer, ref playerStatePacket, DeliveryMethod.Unreliable); + Server.SendDataToAll(Writer, ref playerStatePacket, DeliveryMethod.Unreliable); player.LastDirection = Vector2.zero; // Bots give a constant input for some odd reason, resetting on FixedUpdate should be ok from my testing and does not cause sliding for clients } @@ -65,8 +65,8 @@ protected void Update() WeaponPacket firearmPacket = FirearmPackets.Dequeue(); firearmPacket.NetId = player.NetId; - Writer?.Reset(); - Server?.SendDataToAll(Writer, ref firearmPacket, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Server.SendDataToAll(Writer, ref firearmPacket, DeliveryMethod.ReliableOrdered); } } int healthPackets = DamagePackets.Count; @@ -77,8 +77,8 @@ protected void Update() DamagePacket healthPacket = DamagePackets.Dequeue(); healthPacket.NetId = player.NetId; - Writer?.Reset(); - Server?.SendDataToAll(Writer, ref healthPacket, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Server.SendDataToAll(Writer, ref healthPacket, DeliveryMethod.ReliableOrdered); } } int inventoryPackets = InventoryPackets.Count; @@ -89,8 +89,8 @@ protected void Update() InventoryPacket inventoryPacket = InventoryPackets.Dequeue(); inventoryPacket.NetId = player.NetId; - Writer?.Reset(); - Server?.SendDataToAll(Writer, ref inventoryPacket, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Server.SendDataToAll(Writer, ref inventoryPacket, DeliveryMethod.ReliableOrdered); } } int commonPlayerPackets = CommonPlayerPackets.Count; @@ -101,8 +101,8 @@ protected void Update() CommonPlayerPacket commonPlayerPacket = CommonPlayerPackets.Dequeue(); commonPlayerPacket.NetId = player.NetId; - Writer?.Reset(); - Server?.SendDataToAll(Writer, ref commonPlayerPacket, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Server.SendDataToAll(Writer, ref commonPlayerPacket, DeliveryMethod.ReliableOrdered); } } int healthSyncPackets = HealthSyncPackets.Count; @@ -113,8 +113,8 @@ protected void Update() HealthSyncPacket healthSyncPacket = HealthSyncPackets.Dequeue(); healthSyncPacket.NetId = player.NetId; - Writer?.Reset(); - Server?.SendDataToAll(Writer, ref healthSyncPacket, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Server.SendDataToAll(Writer, ref healthSyncPacket, DeliveryMethod.ReliableOrdered); } } } diff --git a/Fika.Core/Coop/PacketHandlers/ClientPacketSender.cs b/Fika.Core/Coop/PacketHandlers/ClientPacketSender.cs index 1e7169d4..3475682a 100644 --- a/Fika.Core/Coop/PacketHandlers/ClientPacketSender.cs +++ b/Fika.Core/Coop/PacketHandlers/ClientPacketSender.cs @@ -53,7 +53,7 @@ protected void FixedUpdate() player.hasGround, player.CurrentSurface, player.MovementContext.SurfaceNormal); Writer.Reset(); - Client?.SendData(Writer, ref playerStatePacket, DeliveryMethod.Unreliable); + Client.SendData(Writer, ref playerStatePacket, DeliveryMethod.Unreliable); if (player.MovementIdlingTime > 0.01f) { @@ -71,8 +71,8 @@ protected void Update() WeaponPacket firearmPacket = FirearmPackets.Dequeue(); firearmPacket.NetId = player.NetId; - Writer?.Reset(); - Client?.SendData(Writer, ref firearmPacket, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Client.SendData(Writer, ref firearmPacket, DeliveryMethod.ReliableOrdered); } } int healthPackets = DamagePackets.Count; @@ -83,8 +83,8 @@ protected void Update() DamagePacket healthPacket = DamagePackets.Dequeue(); healthPacket.NetId = player.NetId; - Writer?.Reset(); - Client?.SendData(Writer, ref healthPacket, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Client.SendData(Writer, ref healthPacket, DeliveryMethod.ReliableOrdered); } } int inventoryPackets = InventoryPackets.Count; @@ -95,8 +95,8 @@ protected void Update() InventoryPacket inventoryPacket = InventoryPackets.Dequeue(); inventoryPacket.NetId = player.NetId; - Writer?.Reset(); - Client?.SendData(Writer, ref inventoryPacket, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Client.SendData(Writer, ref inventoryPacket, DeliveryMethod.ReliableOrdered); } } int commonPlayerPackets = CommonPlayerPackets.Count; @@ -107,8 +107,8 @@ protected void Update() CommonPlayerPacket commonPlayerPacket = CommonPlayerPackets.Dequeue(); commonPlayerPacket.NetId = player.NetId; - Writer?.Reset(); - Client?.SendData(Writer, ref commonPlayerPacket, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Client.SendData(Writer, ref commonPlayerPacket, DeliveryMethod.ReliableOrdered); } } int healthSyncPackets = HealthSyncPackets.Count; @@ -119,8 +119,8 @@ protected void Update() HealthSyncPacket healthSyncPacket = HealthSyncPackets.Dequeue(); healthSyncPacket.NetId = player.NetId; - Writer?.Reset(); - Client?.SendData(Writer, ref healthSyncPacket, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Client.SendData(Writer, ref healthSyncPacket, DeliveryMethod.ReliableOrdered); } } if (FikaPlugin.UsePingSystem.Value @@ -129,7 +129,7 @@ protected void Update() && Input.GetKey(FikaPlugin.PingButton.Value.MainKey) && FikaPlugin.PingButton.Value.Modifiers.All(Input.GetKey)) { - player?.Ping(); + player.Ping(); } } @@ -154,13 +154,13 @@ private IEnumerator SyncWorld() yield return new WaitForSeconds(10f); - Writer?.Reset(); + Writer.Reset(); GameTimerPacket gameTimerPacket = new(true); - Client?.SendData(Writer, ref gameTimerPacket, DeliveryMethod.ReliableOrdered); + Client.SendData(Writer, ref gameTimerPacket, DeliveryMethod.ReliableOrdered); - Writer?.Reset(); + Writer.Reset(); ExfiltrationPacket exfilPacket = new(true); - Client?.SendData(Writer, ref exfilPacket, DeliveryMethod.ReliableOrdered); + Client.SendData(Writer, ref exfilPacket, DeliveryMethod.ReliableOrdered); } private IEnumerator SyncWeather() @@ -188,8 +188,8 @@ private IEnumerator SyncWeather() HasData = false }; - Writer?.Reset(); - Client?.SendData(Writer, ref packet, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Client.SendData(Writer, ref packet, DeliveryMethod.ReliableOrdered); } public void DestroyThis() diff --git a/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs b/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs index 99f40b1e..58efa421 100644 --- a/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs +++ b/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs @@ -60,7 +60,7 @@ protected void FixedUpdate() player.hasGround, player.CurrentSurface, player.MovementContext.SurfaceNormal); Writer.Reset(); - Server?.SendDataToAll(Writer, ref playerStatePacket, DeliveryMethod.Unreliable); + Server.SendDataToAll(Writer, ref playerStatePacket, DeliveryMethod.Unreliable); if (player.MovementIdlingTime > 0.01f) { @@ -78,8 +78,8 @@ protected void Update() WeaponPacket firearmPacket = FirearmPackets.Dequeue(); firearmPacket.NetId = player.NetId; - Writer?.Reset(); - Server?.SendDataToAll(Writer, ref firearmPacket, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Server.SendDataToAll(Writer, ref firearmPacket, DeliveryMethod.ReliableOrdered); } } int healthPackets = DamagePackets.Count; @@ -90,8 +90,8 @@ protected void Update() DamagePacket healthPacket = DamagePackets.Dequeue(); healthPacket.NetId = player.NetId; - Writer?.Reset(); - Server?.SendDataToAll(Writer, ref healthPacket, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Server.SendDataToAll(Writer, ref healthPacket, DeliveryMethod.ReliableOrdered); } } int inventoryPackets = InventoryPackets.Count; @@ -102,8 +102,8 @@ protected void Update() InventoryPacket inventoryPacket = InventoryPackets.Dequeue(); inventoryPacket.NetId = player.NetId; - Writer?.Reset(); - Server?.SendDataToAll(Writer, ref inventoryPacket, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Server.SendDataToAll(Writer, ref inventoryPacket, DeliveryMethod.ReliableOrdered); } } int commonPlayerPackets = CommonPlayerPackets.Count; @@ -114,8 +114,8 @@ protected void Update() CommonPlayerPacket commonPlayerPacket = CommonPlayerPackets.Dequeue(); commonPlayerPacket.NetId = player.NetId; - Writer?.Reset(); - Server?.SendDataToAll(Writer, ref commonPlayerPacket, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Server.SendDataToAll(Writer, ref commonPlayerPacket, DeliveryMethod.ReliableOrdered); } } int healthSyncPackets = HealthSyncPackets.Count; @@ -126,8 +126,8 @@ protected void Update() HealthSyncPacket healthSyncPacket = HealthSyncPackets.Dequeue(); healthSyncPacket.NetId = player.NetId; - Writer?.Reset(); - Server?.SendDataToAll(Writer, ref healthSyncPacket, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Server.SendDataToAll(Writer, ref healthSyncPacket, DeliveryMethod.ReliableOrdered); } } if (FikaPlugin.UsePingSystem.Value @@ -136,7 +136,7 @@ protected void Update() && Input.GetKey(FikaPlugin.PingButton.Value.MainKey) && FikaPlugin.PingButton.Value.Modifiers.All(Input.GetKey)) { - player?.Ping(); + player.Ping(); } } @@ -178,8 +178,8 @@ private IEnumerator SendTrainTime() DepartureTime = time }; - Writer?.Reset(); - Server?.SendDataToAll(Writer, ref packet, DeliveryMethod.ReliableOrdered); + Writer.Reset(); + Server.SendDataToAll(Writer, ref packet, DeliveryMethod.ReliableOrdered); } else { diff --git a/Fika.Core/Coop/Patches/Minefield/Minefield_method_2_Patch.cs b/Fika.Core/Coop/Patches/Minefield/Minefield_method_2_Patch.cs index f774406f..386fcdaf 100644 --- a/Fika.Core/Coop/Patches/Minefield/Minefield_method_2_Patch.cs +++ b/Fika.Core/Coop/Patches/Minefield/Minefield_method_2_Patch.cs @@ -74,7 +74,7 @@ private static void DoReplicatedMineDamage(IPlayer player, float distance, bool foreach (BodyPartCollider bodyPartCollider in enumerable) { - coopPlayer.PacketSender?.DamagePackets?.Enqueue(new() + coopPlayer.PacketSender.DamagePackets.Enqueue(new() { DamageInfo = new() { diff --git a/Fika.Core/Coop/Players/CoopBot.cs b/Fika.Core/Coop/Players/CoopBot.cs index e1d594de..e5ad3f05 100644 --- a/Fika.Core/Coop/Players/CoopBot.cs +++ b/Fika.Core/Coop/Players/CoopBot.cs @@ -253,7 +253,10 @@ private IEnumerator DestroyNetworkedComponents() { yield return new WaitForSeconds(2); - PacketSender?.DestroyThis(); + if (PacketSender != null) + { + PacketSender.DestroyThis(); + } } public override void UpdateTick() @@ -359,7 +362,7 @@ internal void SendPacket() return; } - coopBot.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopBot.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() diff --git a/Fika.Core/Coop/Players/CoopPlayer.cs b/Fika.Core/Coop/Players/CoopPlayer.cs index eb50eb76..4bef608b 100644 --- a/Fika.Core/Coop/Players/CoopPlayer.cs +++ b/Fika.Core/Coop/Players/CoopPlayer.cs @@ -124,8 +124,8 @@ public override void BtrInteraction(BTRSide btr, byte placeId, EInteractionType InteractPacket = btr.GetInteractWithBtrPacket(placeId, interaction) }; - PacketSender?.Writer?.Reset(); - PacketSender?.Client?.SendData(PacketSender?.Writer, ref packet, LiteNetLib.DeliveryMethod.ReliableOrdered); + PacketSender.Writer.Reset(); + PacketSender.Client.SendData(PacketSender.Writer, ref packet, LiteNetLib.DeliveryMethod.ReliableOrdered); } else if (MatchmakerAcceptPatches.IsServer) { @@ -142,8 +142,8 @@ public override void BtrInteraction(BTRSide btr, byte placeId, EInteractionType InteractPacket = interactPacket }; - PacketSender?.Writer?.Reset(); - PacketSender?.Server?.SendDataToAll(PacketSender?.Writer, ref packet, LiteNetLib.DeliveryMethod.ReliableOrdered); + PacketSender.Writer.Reset(); + PacketSender.Server.SendDataToAll(PacketSender.Writer, ref packet, LiteNetLib.DeliveryMethod.ReliableOrdered); } } } @@ -158,7 +158,10 @@ public void ProcessInteractWithBTR(BTRInteractionPacket packet) { if (CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler)) { - coopHandler.clientBTR?.ClientInteraction(this, packet.InteractPacket); + if (coopHandler.clientBTR != null) + { + coopHandler.clientBTR.ClientInteraction(this, packet.InteractPacket); + } } } } @@ -216,7 +219,7 @@ public override GClass1676 ApplyShot(DamageInfo damageInfo, EBodyPart bodyPartTy public override void Proceed(bool withNetwork, Callback callback, bool scheduled = true) { base.Proceed(withNetwork, callback, scheduled); - PacketSender?.CommonPlayerPackets?.Enqueue(new() + PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() @@ -322,7 +325,7 @@ public override void DropCurrentController(Action callback, bool fastDrop, Item { base.DropCurrentController(callback, fastDrop, nextControllerItem); - /*PacketSender?.CommonPlayerPackets?.Enqueue(new() + /*PacketSender.CommonPlayerPackets.Enqueue(new() { HasDrop = true, DropPacket = new() @@ -342,7 +345,7 @@ public override void SetInventoryOpened(bool opened) } base.SetInventoryOpened(opened); - PacketSender?.CommonPlayerPackets?.Enqueue(new() + PacketSender.CommonPlayerPackets.Enqueue(new() { HasInventoryChanged = true, SetInventoryOpen = opened @@ -352,7 +355,7 @@ public override void SetInventoryOpened(bool opened) public override void SetCompassState(bool value) { base.SetCompassState(value); - PacketSender?.FirearmPackets?.Enqueue(new() + PacketSender.FirearmPackets.Enqueue(new() { HasCompassChange = true, CompassState = value @@ -373,7 +376,7 @@ public override void SendHeadlightsPacket(bool isSilent) { GStruct163[] lightStates = _helmetLightControllers.Select(new Func(ClientPlayer.Class1430.class1430_0.method_0)).ToArray(); - PacketSender?.CommonPlayerPackets?.Enqueue(new() + PacketSender.CommonPlayerPackets.Enqueue(new() { HasHeadLightsPacket = true, HeadLightsPacket = new() @@ -395,7 +398,7 @@ public override void OnPhraseTold(EPhraseTrigger @event, TaggedClip clip, TagBan if (ActiveHealthController.IsAlive) { - PacketSender?.CommonPlayerPackets?.Enqueue(new() + PacketSender.CommonPlayerPackets.Enqueue(new() { Phrase = @event, PhraseIndex = clip.NetId @@ -406,7 +409,7 @@ public override void OnPhraseTold(EPhraseTrigger @event, TaggedClip clip, TagBan public override void OperateStationaryWeapon(StationaryWeapon stationaryWeapon, GStruct169.EStationaryCommand command) { base.OperateStationaryWeapon(stationaryWeapon, command); - PacketSender?.CommonPlayerPackets?.Enqueue(new() + PacketSender.CommonPlayerPackets.Enqueue(new() { HasStationaryPacket = true, StationaryPacket = new() @@ -447,7 +450,7 @@ public override void vmethod_0(WorldInteractiveObject interactiveObject, Interac ItemId = (interactionResult is GClass2964 keyInteractionResult) ? keyInteractionResult.Key.Item.Id : string.Empty } }; - PacketSender?.CommonPlayerPackets?.Enqueue(packet); + PacketSender.CommonPlayerPackets.Enqueue(packet); } // Execute @@ -472,7 +475,7 @@ public override void vmethod_1(WorldInteractiveObject door, InteractionResult in ItemId = (interactionResult is GClass2964 keyInteractionResult) ? keyInteractionResult.Key.Item.Id : string.Empty } }; - PacketSender?.CommonPlayerPackets?.Enqueue(packet); + PacketSender.CommonPlayerPackets.Enqueue(packet); UpdateInteractionCast(); } @@ -480,7 +483,7 @@ public override void vmethod_1(WorldInteractiveObject door, InteractionResult in public override void vmethod_3(EGesture gesture) { base.vmethod_3(gesture); - PacketSender?.FirearmPackets?.Enqueue(new() + PacketSender.FirearmPackets.Enqueue(new() { Gesture = gesture }); @@ -530,7 +533,10 @@ private IEnumerator DestroyNetworkedComponents() { yield return new WaitForSeconds(2); - PacketSender?.DestroyThis(); + if (PacketSender != null) + { + PacketSender.DestroyThis(); + } } public override void Move(Vector2 direction) @@ -761,7 +767,7 @@ public void Ping() Color pingColor = FikaPlugin.PingColor.Value; pingColor = new(pingColor.r, pingColor.g, pingColor.b, 1); // ref so that we can mutate it if we want to, ex: if I ping a switch I want it at the switch.gameObject.position + Vector3.up - abstractPing?.Initialize(ref hitPoint, userData, pingColor); + abstractPing.Initialize(ref hitPoint, userData, pingColor); GenericPacket genericPacket = new() { @@ -773,14 +779,14 @@ public void Ping() Nickname = Profile.Nickname }; - PacketSender?.Writer?.Reset(); + PacketSender.Writer.Reset(); if (MatchmakerAcceptPatches.IsServer) { - PacketSender?.Server?.SendDataToAll(PacketSender.Writer, ref genericPacket, LiteNetLib.DeliveryMethod.ReliableOrdered); + PacketSender.Server.SendDataToAll(PacketSender.Writer, ref genericPacket, LiteNetLib.DeliveryMethod.ReliableOrdered); } else if (MatchmakerAcceptPatches.IsClient) { - PacketSender?.Client?.SendData(PacketSender.Writer, ref genericPacket, LiteNetLib.DeliveryMethod.ReliableOrdered); + PacketSender.Client.SendData(PacketSender.Writer, ref genericPacket, LiteNetLib.DeliveryMethod.ReliableOrdered); } if (FikaPlugin.PlayPingAnimation.Value) @@ -934,7 +940,7 @@ public virtual void HandleCommonPacket(in CommonPlayerPacket packet) { if (this is ObservedCoopPlayer observedCoopPlayer) { - observedCoopPlayer?.HandleProceedPacket(packet.ProceedPacket); + observedCoopPlayer.HandleProceedPacket(packet.ProceedPacket); } } @@ -1339,7 +1345,10 @@ public override void OnDestroy() public override void Dispose() { base.Dispose(); - PacketSender?.DestroyThis(); + if (PacketSender != null) + { + PacketSender.DestroyThis(); + } } public override void SendHandsInteractionStateChanged(bool value, int animationId) @@ -1347,7 +1356,7 @@ public override void SendHandsInteractionStateChanged(bool value, int animationI base.SendHandsInteractionStateChanged(value, animationId); if (value) { - PacketSender?.CommonPlayerPackets?.Enqueue(new() + PacketSender.CommonPlayerPackets.Enqueue(new() { Pickup = value, PickupAnimation = animationId @@ -1357,7 +1366,7 @@ public override void SendHandsInteractionStateChanged(bool value, int animationI public override void OnVaulting() { - PacketSender?.CommonPlayerPackets?.Enqueue(new() + PacketSender.CommonPlayerPackets.Enqueue(new() { HasVaultPacket = true, VaultPacket = new() @@ -1421,7 +1430,7 @@ private class LootableContainerInteractionHandler(CoopPlayer player, LootableCon public void Handle() { - player.PacketSender?.CommonPlayerPackets?.Enqueue(new() + player.PacketSender.CommonPlayerPackets.Enqueue(new() { HasContainerInteractionPacket = true, ContainerInteractionPacket = new() @@ -1459,7 +1468,7 @@ internal void SendPacket() return; } - coopPlayer.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() @@ -1494,7 +1503,7 @@ internal QuickUseItemController ReturnController() internal void SendPacket() { - coopPlayer.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() @@ -1531,7 +1540,7 @@ internal MedsController ReturnController() internal void SendPacket() { - coopPlayer.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() @@ -1571,7 +1580,7 @@ internal MedsController ReturnController() internal void SendPacket() { - coopPlayer.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() @@ -1609,7 +1618,7 @@ internal CoopClientKnifeController ReturnController() internal void SendPacket() { - coopPlayer.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() @@ -1644,7 +1653,7 @@ internal QuickKnifeKickController ReturnController() internal void SendPacket() { - coopPlayer.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() @@ -1679,7 +1688,7 @@ internal CoopClientGrenadeController ReturnController() internal void SendPacket() { - coopPlayer.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() @@ -1714,7 +1723,7 @@ internal CoopClientQuickGrenadeController ReturnController() internal void SendPacket() { - coopPlayer.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() diff --git a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs index a604f011..64ed3d5d 100644 --- a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs +++ b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs @@ -261,7 +261,7 @@ public override void ApplyDamageInfo(DamageInfo damageInfo, EBodyPart bodyPartTy { if (damageInfo.DamageType == EDamageType.Landmine && MatchmakerAcceptPatches.IsServer) { - PacketSender?.DamagePackets?.Enqueue(new() + PacketSender.DamagePackets.Enqueue(new() { DamageInfo = new() { @@ -333,7 +333,7 @@ public override GClass1676 ApplyShot(DamageInfo damageInfo, EBodyPart bodyPartTy if (damageInfo.DamageType == EDamageType.Sniper && MatchmakerAcceptPatches.IsServer) { ShotReactions(damageInfo, bodyPartType); - PacketSender?.DamagePackets?.Enqueue(new() + PacketSender.DamagePackets.Enqueue(new() { DamageInfo = new() { @@ -401,7 +401,7 @@ public override GClass1676 ApplyShot(DamageInfo damageInfo, EBodyPart bodyPartTy colliderType = bodyPartCollider.BodyPartColliderType; } - PacketSender?.DamagePackets?.Enqueue(new() + PacketSender.DamagePackets.Enqueue(new() { DamageInfo = new() { @@ -461,7 +461,7 @@ public override GClass1676 ApplyShot(DamageInfo damageInfo, EBodyPart bodyPartTy colliderType = bodyPartCollider.BodyPartColliderType; } - PacketSender?.DamagePackets?.Enqueue(new() + PacketSender.DamagePackets.Enqueue(new() { DamageInfo = new() { @@ -602,7 +602,10 @@ public override void vmethod_3(EGesture gesture) if (gesture == EGesture.Hello) { InteractionRaycast(); - InteractablePlayer?.ShowHelloNotification(Profile.Nickname); + if (InteractablePlayer != null) + { + InteractablePlayer.ShowHelloNotification(Profile.Nickname); + } } base.vmethod_3(gesture); } @@ -826,7 +829,10 @@ public override void SetInventory(EquipmentClass equipmentClass) Transform alternativeHolsterBone = PlayerBody.GetAlternativeHolsterBone(equipmentSlot); PlayerBody.GClass1860 gclass = new(PlayerBody, Inventory.Equipment.GetSlot(equipmentSlot), slotBone, equipmentSlot, Inventory.Equipment.GetSlot(EquipmentSlot.Backpack), alternativeHolsterBone); PlayerBody.GClass1860 gclass2 = PlayerBody.SlotViews.AddOrReplace(equipmentSlot, gclass); - gclass2?.Dispose(); + if (gclass2 != null) + { + gclass2.Dispose(); + } } //PlayerBody.Init(PlayerBody.BodyCustomization, Inventory.Equipment, shouldSet ? itemInHands : null, LayerMask.NameToLayer("Player"), Side); @@ -1010,7 +1016,7 @@ public override void LandingAdjustments(float d) transform.localRotation = Quaternion.identity; transform.localPosition = Vector3.zero; method_29(transform.gameObject); - compassInstantiated = true; + Traverse.Create(this).Field("_compassInstantiated").SetValue(true); return; } } @@ -1142,7 +1148,10 @@ public override void InitAudioController() private void SetSoundRollOff() { - NestedStepSoundSource?.SetRolloff(60f * ProtagonistHearing); + if (NestedStepSoundSource != null) + { + NestedStepSoundSource.SetRolloff(60f * ProtagonistHearing); + } } public override bool UpdateGrenadeAnimatorDuePoV() diff --git a/Fika.Core/Networking/FikaClient.cs b/Fika.Core/Networking/FikaClient.cs index eca51392..ec69f925 100644 --- a/Fika.Core/Networking/FikaClient.cs +++ b/Fika.Core/Networking/FikaClient.cs @@ -245,7 +245,10 @@ private void OnBTRInteractionPacketReceived(BTRInteractionPacket packet) private void OnBTRPacketReceived(BTRPacket packet) { - CoopHandler.clientBTR?.btrPackets.Enqueue(packet); + if (CoopHandler.clientBTR != null) + { + CoopHandler.clientBTR.btrPackets.Enqueue(packet); + } } private void OnWeatherPacketReceived(WeatherPacket packet) @@ -423,7 +426,10 @@ private void OnGenericPacketReceived(GenericPacket packet) break; case EPackageType.TraderServiceNotification: { - CoopHandler.clientBTR?.DisplayNetworkNotification(packet.TraderServiceType); + if (CoopHandler.clientBTR) + { + CoopHandler.clientBTR.DisplayNetworkNotification(packet.TraderServiceType); + } } break; case EPackageType.DisposeBot: @@ -499,7 +505,7 @@ private void OnHealthSyncPacketReceived(HealthSyncPacket packet) { if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { - playerToApply?.PacketReceiver?.HealthSyncPackets?.Enqueue(packet); + playerToApply.PacketReceiver?.HealthSyncPackets?.Enqueue(packet); } } @@ -593,7 +599,7 @@ private void OnCommonPlayerPacketReceived(CommonPlayerPacket packet) { if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { - playerToApply?.PacketReceiver?.CommonPlayerPackets?.Enqueue(packet); + playerToApply.PacketReceiver?.CommonPlayerPackets?.Enqueue(packet); } } @@ -601,7 +607,7 @@ private void OnInventoryPacketReceived(InventoryPacket packet) { if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { - playerToApply?.PacketReceiver?.InventoryPackets?.Enqueue(packet); + playerToApply.PacketReceiver?.InventoryPackets?.Enqueue(packet); } } @@ -609,7 +615,7 @@ private void OnDamagePacketReceived(DamagePacket packet) { if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { - playerToApply?.PacketReceiver?.DamagePackets?.Enqueue(packet); + playerToApply.PacketReceiver?.DamagePackets?.Enqueue(packet); } } @@ -617,7 +623,7 @@ private void OnFirearmPacketReceived(WeaponPacket packet) { if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { - playerToApply?.PacketReceiver?.FirearmPackets?.Enqueue(packet); + playerToApply.PacketReceiver?.FirearmPackets?.Enqueue(packet); } } diff --git a/Fika.Core/Networking/FikaServer.cs b/Fika.Core/Networking/FikaServer.cs index 3ce0aaed..20d0a820 100644 --- a/Fika.Core/Networking/FikaServer.cs +++ b/Fika.Core/Networking/FikaServer.cs @@ -229,7 +229,10 @@ private void OnDeathPacketReceived(DeathPacket packet, NetPeer peer) private void OnBTRServicePacketReceived(BTRServicePacket packet, NetPeer peer) { - CoopHandler.serverBTR?.NetworkBtrTraderServicePurchased(packet); + if (CoopHandler.serverBTR != null) + { + CoopHandler.serverBTR.NetworkBtrTraderServicePurchased(packet); + } } private void OnBTRInteractionPacketReceived(BTRInteractionPacket packet, NetPeer peer) @@ -389,7 +392,7 @@ private void OnHealthSyncPacketReceived(HealthSyncPacket packet, NetPeer peer) { if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { - playerToApply?.PacketReceiver?.HealthSyncPackets?.Enqueue(packet); + playerToApply.PacketReceiver?.HealthSyncPackets?.Enqueue(packet); } _dataWriter.Reset(); @@ -415,7 +418,6 @@ private void OnInformationPacketReceived(InformationPacket packet, NetPeer peer) private void OnAllCharacterRequestPacketReceived(AllCharacterRequestPacket packet, NetPeer peer) { - // This method needs to be refined. For some reason the ping-pong has to be run twice for it to work on the host? if (packet.IsRequest) { foreach (CoopPlayer player in CoopHandler.Players.Values) @@ -469,7 +471,7 @@ private void OnCommonPlayerPacketReceived(CommonPlayerPacket packet, NetPeer pee { if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { - playerToApply?.PacketReceiver?.CommonPlayerPackets?.Enqueue(packet); + playerToApply.PacketReceiver?.CommonPlayerPackets?.Enqueue(packet); } _dataWriter.Reset(); @@ -571,7 +573,7 @@ private void OnDamagePacketReceived(DamagePacket packet, NetPeer peer) { if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { - playerToApply?.PacketReceiver?.DamagePackets?.Enqueue(packet); + playerToApply.PacketReceiver?.DamagePackets?.Enqueue(packet); } _dataWriter.Reset(); @@ -582,7 +584,7 @@ private void OnFirearmPacketReceived(WeaponPacket packet, NetPeer peer) { if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { - playerToApply?.PacketReceiver?.FirearmPackets?.Enqueue(packet); + playerToApply.PacketReceiver?.FirearmPackets?.Enqueue(packet); } _dataWriter.Reset();