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..ae5d9882 100644 --- a/Fika.Core/Coop/ClientClasses/CoopClientInventoryController.cs +++ b/Fika.Core/Coop/ClientClasses/CoopClientInventoryController.cs @@ -26,34 +26,36 @@ public override void CallMalfunctionRepaired(Weapon weapon) base.CallMalfunctionRepaired(weapon); if (!Player.IsAI && (bool)Singleton.Instance.Game.Settings.MalfunctionVisability) { - MonoBehaviourSingleton.Instance.MalfunctionGlow.ShowGlow(BattleUIMalfunctionGlow.GlowType.Repaired, force: true, method_44()); + MonoBehaviourSingleton.Instance.MalfunctionGlow.ShowGlow(BattleUIMalfunctionGlow.GlowType.Repaired, true, method_44()); } } public override void Execute(GClass2837 operation, [CanBeNull] Callback callback) { + // Do not replicate picking up quest items, throws an error on the other clients + if (operation is GClass2839 pickupOperation) + { + if (pickupOperation.Item.Template.QuestItem) + { + base.Execute(operation, callback); + return; + } + } + if (MatchmakerAcceptPatches.IsServer) { + // Do not replicate quest operations + if (operation is GClass2866 or GClass2879) + { + base.Execute(operation, callback); + return; + } + HostInventoryOperationManager operationManager = new(this, operation, callback); if (vmethod_0(operationManager.operation)) { operationManager.operation.vmethod_0(operationManager.HandleResult); - // Do not replicate picking up quest items, throws an error on the other clients - if (operation is GClass2839 pickupOperation) - { - if (pickupOperation.Item.Template.QuestItem) - { - return; - } - } - - // TODO: Check for glass increments - if (operation is GClass2870) - { - return; - } - InventoryPacket packet = new() { HasItemControllerExecutePacket = true @@ -69,7 +71,7 @@ public override void Execute(GClass2837 operation, [CanBeNull] Callback callback OperationBytes = opBytes }; - CoopPlayer.PacketSender?.InventoryPackets?.Enqueue(packet); + CoopPlayer.PacketSender.InventoryPackets.Enqueue(packet); return; } @@ -78,14 +80,11 @@ public override void Execute(GClass2837 operation, [CanBeNull] Callback callback } else if (MatchmakerAcceptPatches.IsClient) { - // Do not replicate picking up quest items, throws an error on the other clients - if (operation is GClass2839 pickupOperation) + // Do not replicate quest operations + if (operation is GClass2866 or GClass2879) { - if (pickupOperation.Item.Template.QuestItem) - { - base.Execute(operation, callback); - return; - } + base.Execute(operation, callback); + return; } InventoryPacket packet = new() @@ -113,7 +112,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..cd92be42 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() @@ -237,7 +237,7 @@ public override void InitiateShot(GInterface322 weapon, BulletClass ammo, Vector FireportPosition = fireportPosition, ChamberIndex = chamberIndex, Overheat = overheat, - UnderbarrelShot = weapon.IsUnderbarrelWeapon, + UnderbarrelShot = Weapon.IsUnderBarrelDeviceActive, AmmoTemplate = ammo.AmmoTemplate._id, LastShotOverheat = weapon.MalfState.LastShotOverheat, LastShotTime = weapon.MalfState.LastShotTime, @@ -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() @@ -308,18 +308,36 @@ public override void ReloadGrenadeLauncher(GClass2495 ammoPack, Callback callbac return; } - CurrentOperation.ReloadGrenadeLauncher(ammoPack, callback); - string[] reloadingAmmoIds = ammoPack.GetReloadingAmmoIds(); - - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { + HasReloadLauncherPacket = true, ReloadLauncher = new() { Reload = true, AmmoIds = reloadingAmmoIds } }); + + CurrentOperation.ReloadGrenadeLauncher(ammoPack, callback); + } + + public override void UnderbarrelSightingRangeUp() + { + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() + { + UnderbarrelSightingRangeUp = true + }); + base.UnderbarrelSightingRangeUp(); + } + + public override void UnderbarrelSightingRangeDown() + { + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() + { + UnderbarrelSightingRangeDown = true + }); + base.UnderbarrelSightingRangeDown(); } public override void ReloadMag(MagazineClass magazine, GClass2769 gridItemAddress, Callback callback) @@ -352,7 +370,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 +390,7 @@ public override void SetScopeMode(GStruct164[] scopeStates) return; } - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { ChangeSightMode = true, ScopeStatesPacket = new() @@ -408,7 +426,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 +447,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 +458,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 +467,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 +477,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 +491,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 +506,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 +525,7 @@ public override void RollCylinder(bool rollToZeroCamora) return; } - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { HasRollCylinder = true, RollToZeroCamora = rollToZeroCamora @@ -518,7 +536,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 +550,7 @@ private void SendEndReloadPacket(int amount) private void SendBoltActionReloadPacket() { - coopPlayer.PacketSender?.FirearmPackets?.Enqueue(new() + coopPlayer.PacketSender.FirearmPackets.Enqueue(new() { ReloadBoltAction = true }); @@ -684,7 +702,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 +727,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 +774,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 +797,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..66bfc26c 100644 --- a/Fika.Core/Coop/Components/CoopExfilManager.cs +++ b/Fika.Core/Coop/Components/CoopExfilManager.cs @@ -73,7 +73,7 @@ protected void Update() if (!exfiltrationPoint.UnmetRequirements(player).Any()) { game.MyExitLocation = exfiltrationPoint.Settings.Name; - game.Extract(player, exfiltrationPoint); + game.Extract((CoopPlayer)player, exfiltrationPoint); } } @@ -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..b881b263 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,19 +353,19 @@ 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"); } }); - LocalPlayer otherPlayer = SpawnObservedPlayer(spawnObject.Profile, spawnObject.Position, playerId, spawnObject.IsAI, spawnObject.NetId); + ObservedCoopPlayer otherPlayer = SpawnObservedPlayer(spawnObject.Profile, spawnObject.Position, playerId, spawnObject.IsAI, spawnObject.NetId); if (!spawnObject.IsAlive) { @@ -453,9 +453,9 @@ public WorldInteractiveObject GetInteractiveObject(string objectId, out WorldInt return null; } - private LocalPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int playerId, bool isAI, int netId) + private ObservedCoopPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int playerId, bool isAI, int netId) { - LocalPlayer otherPlayer = ObservedCoopPlayer.CreateObservedPlayer(playerId, position, Quaternion.identity, + ObservedCoopPlayer otherPlayer = ObservedCoopPlayer.CreateObservedPlayer(playerId, position, Quaternion.identity, "Player", isAI == true ? "Bot_" : $"Player_{profile.Nickname}_", EPointOfView.ThirdPerson, profile, isAI, EUpdateQueue.Update, Player.EUpdateMode.Manual, Player.EUpdateMode.Auto, GClass549.Config.CharacterController.ObservedPlayerMode, @@ -468,7 +468,7 @@ private LocalPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int p return null; } - ((CoopPlayer)otherPlayer).NetId = netId; + otherPlayer.NetId = netId; Logger.LogInfo($"SpawnObservedPlayer: {profile.Nickname} spawning with NetId {netId}"); if (!isAI) { @@ -477,7 +477,7 @@ private LocalPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int p if (!Players.ContainsKey(netId)) { - Players.Add(netId, (CoopPlayer)otherPlayer); + Players.Add(netId, otherPlayer); } else { @@ -532,6 +532,8 @@ private LocalPlayer SpawnObservedPlayer(Profile profile, Vector3 position, int p } } + otherPlayer.InitObservedPlayer(); + Logger.LogDebug($"CreateLocalPlayer::{profile.Info.Nickname}::Spawned."); SetWeaponInHandsOfNewPlayer(otherPlayer, () => { }); diff --git a/Fika.Core/Coop/Custom/FikaDynamicAI.cs b/Fika.Core/Coop/Custom/FikaDynamicAI.cs index 4728bdb1..909212e8 100644 --- a/Fika.Core/Coop/Custom/FikaDynamicAI.cs +++ b/Fika.Core/Coop/Custom/FikaDynamicAI.cs @@ -5,8 +5,8 @@ using EFT; using Fika.Core.Coop.Components; using Fika.Core.Coop.Players; -using System; using System.Collections.Generic; +using System.Linq; using UnityEngine; namespace Fika.Core.Coop.Custom @@ -59,10 +59,16 @@ protected void Awake() private void Spawner_OnBotRemoved(BotOwner botOwner) { - if (!bots.Remove((CoopBot)botOwner.GetPlayer)) + CoopBot bot = (CoopBot)botOwner.GetPlayer; + if (!bots.Remove(bot)) { logger.LogWarning($"Could not remove {botOwner.gameObject.name} from bots list."); } + + if (disabledBots.Contains(bot)) + { + disabledBots.Remove(bot); + } } private void Spawner_OnBotCreated(BotOwner botOwner) @@ -117,7 +123,7 @@ private void DeactivateBot(CoopBot bot) if (!disabledBots.Contains(bot)) { - disabledBots.Add(bot); + disabledBots.Add(bot); } else { @@ -184,17 +190,29 @@ private void CheckForPlayers(CoopBot bot) } } - public void SettingChanged(bool value) + public void EnabledChange(bool value) { if (!value) { - foreach (CoopBot bot in disabledBots) + CoopBot[] disabledBotsArray = [.. disabledBots]; + for (int i = 0; i < disabledBotsArray.Length; i++) { - bot.gameObject.SetActive(true); + ActivateBot(disabledBotsArray[i]); } disabledBots.Clear(); } } + + internal void RateChanged(FikaPlugin.DynamicAIRates value) + { + resetCounter = value switch + { + FikaPlugin.DynamicAIRates.Low => 600, + FikaPlugin.DynamicAIRates.Medium => 300, + FikaPlugin.DynamicAIRates.High => 120, + _ => 300, + }; + } } } diff --git a/Fika.Core/Coop/Custom/FikaHealthBar.cs b/Fika.Core/Coop/Custom/FikaHealthBar.cs index cb2dc73a..177caabf 100644 --- a/Fika.Core/Coop/Custom/FikaHealthBar.cs +++ b/Fika.Core/Coop/Custom/FikaHealthBar.cs @@ -99,7 +99,7 @@ private void UpdateScreenSpacePosition(bool throttleUpdate) float processedDistance = Mathf.Clamp(sqrDistance / 625, 0.6f, 1f); Vector3 position = new(currentPlayer.PlayerBones.Neck.position.x, currentPlayer.PlayerBones.Neck.position.y + (1f * processedDistance), currentPlayer.PlayerBones.Neck.position.z); - + if (!WorldToScreen.GetScreenPoint(position, mainPlayer, out Vector3 screenPoint)) { UpdateColorTextMeshProUGUI(playerPlate.playerNameScreen, 0); diff --git a/Fika.Core/Coop/FreeCamera/FreeCameraController.cs b/Fika.Core/Coop/FreeCamera/FreeCameraController.cs index 8c7d2d9e..812b80bb 100644 --- a/Fika.Core/Coop/FreeCamera/FreeCameraController.cs +++ b/Fika.Core/Coop/FreeCamera/FreeCameraController.cs @@ -6,8 +6,10 @@ using Fika.Core.Coop.GameMode; using Fika.Core.Coop.Players; using Fika.Core.UI; +using HarmonyLib; using Koenigz.PerfectCulling; using Koenigz.PerfectCulling.EFT; +using System.Collections; using System.Collections.Generic; using System.Linq; using TMPro; @@ -31,7 +33,8 @@ public class FreeCameraController : MonoBehaviour private bool _effectsCleared = false; private GamePlayerOwner _gamePlayerOwner; - private Player _player => Singleton.Instance.MainPlayer; + private CoopPlayer _player => (CoopPlayer)Singleton.Instance.MainPlayer; + private CoopHandler coopHandler; public GameObject CameraParent; public Camera CameraFreeCamera { get; private set; } @@ -41,7 +44,6 @@ public class FreeCameraController : MonoBehaviour private bool extracted = false; private DeathFade deathFade; private bool deathFadeEnabled; - private float DeadTime = 0f; private DisablerCullingObjectBase[] allCullingObjects; private List previouslyActiveBakeGroups; @@ -80,32 +82,41 @@ protected void Start() allCullingObjects = FindObjectsOfType(); previouslyActiveBakeGroups = []; - } - protected void Update() - { - if (_gamePlayerOwner == null) + _player.ActiveHealthController.DiedEvent += MainPlayer_DiedEvent; + + if (CoopHandler.TryGetCoopHandler(out CoopHandler cHandler)) { - return; + coopHandler = cHandler; } + } - if (_player == null) + private void MainPlayer_DiedEvent(EDamageType obj) + { + _player.ActiveHealthController.DiedEvent -= MainPlayer_DiedEvent; + + if (!deathFadeEnabled) { - return; + deathFade.EnableEffect(); + deathFadeEnabled = true; } - if (_player.PlayerHealthController == null) + StartCoroutine(DeathRoutine()); + } + + protected void Update() + { + if (_gamePlayerOwner == null) { return; } - if (!CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler)) + if (_player == null) { return; } - CoopGame coopGame = (CoopGame)coopHandler.LocalGameInstance; - if (coopGame == null) + if (_player.PlayerHealthController == null) { return; } @@ -134,7 +145,8 @@ protected void Update() if (quitState == CoopHandler.EQuitState.YouHaveExtracted && !extracted) { - if (coopGame.ExtractedPlayers.Contains(((CoopPlayer)_player).NetId)) + CoopGame coopGame = (CoopGame)coopHandler.LocalGameInstance; + if (coopGame.ExtractedPlayers.Contains((_player).NetId)) { extracted = true; ShowExtractMessage(); @@ -161,56 +173,50 @@ protected void Update() _effectsCleared = true; } } + } + + private IEnumerator DeathRoutine() + { + yield return new WaitForSeconds(5); - if (!_player.HealthController.IsAlive) + CameraClass cameraClassInstance = CameraClass.Instance; + if (cameraClassInstance == null) { - DeadTime += Time.deltaTime; - if (!deathFadeEnabled) - { - deathFade.EnableEffect(); - deathFadeEnabled = true; - } + yield break; } - // Player is dead. Remove all effects! - if (!_player.HealthController.IsAlive && !_freeCamScript.IsActive && DeadTime > 5f) + if (cameraClassInstance.EffectsController == null) { - CameraClass cameraClassInstance = CameraClass.Instance; - if (cameraClassInstance == null) - { - return; - } - - if (cameraClassInstance.EffectsController == null) - { - return; - } + yield break; + } - if (cameraClassInstance.Camera != null) - { - cameraClassInstance.Camera.fieldOfView = Singleton.Instance.Game.Settings.FieldOfView; - } + if (cameraClassInstance.Camera != null) + { + cameraClassInstance.Camera.fieldOfView = Singleton.Instance.Game.Settings.FieldOfView; + } - // Disable the DeathFade effect & Toggle the Camera - deathFade.DisableEffect(); + // Disable the DeathFade effect & Toggle the Camera + deathFade.DisableEffect(); + if (!_freeCamScript.IsActive) + { ToggleCamera(); ToggleUi(); - ShowExtractMessage(); + } + ShowExtractMessage(); - if (!_effectsCleared) + if (!_effectsCleared) + { + if (_player != null) { - if (_player != null) - { - _player.Muffled = false; - _player.HeavyBreath = false; - } + _player.Muffled = false; + _player.HeavyBreath = false; + } - if (CameraClass.Exist) - { - ClearEffects(); - } - _effectsCleared = true; + if (CameraClass.Exist) + { + ClearEffects(); } + _effectsCleared = true; } } @@ -218,7 +224,44 @@ private void ClearEffects() { CameraClass cameraClass = CameraClass.Instance; cameraClass.EffectsController.method_4(false); - cameraClass.EffectsController.enabled = false; + + Traverse effectsController = Traverse.Create(cameraClass.EffectsController); + + BloodOnScreen bloodOnScreen = effectsController.Field("bloodOnScreen_0").GetValue(); + if (bloodOnScreen != null) + { + Destroy(bloodOnScreen); + } + + List effectsManagerList = effectsController.Field("list_0").GetValue>(); + if (effectsManagerList != null) + { + foreach (EffectsController.Class566 effectsManager in effectsManagerList) + { + while (effectsManager.ActiveEffects.Count > 0) + { + IEffect effect = effectsManager.ActiveEffects[0]; + effectsManager.DeleteEffect(effect); + } + } + effectsManagerList.Clear(); + } + + CC_Wiggle wiggleEffect = cameraClass.Camera.gameObject.GetComponent(); + if (wiggleEffect != null) + { + wiggleEffect.enabled = false; + } + + CC_Blend[] blendEffects = cameraClass.Camera.gameObject.GetComponents(); + if (blendEffects.Length > 0) + { + foreach (CC_Blend blendEffect in blendEffects) + { + blendEffect.enabled = false; + } + } + Destroy(cameraClass.EffectsController); cameraClass.VisorEffect.Clear(); Destroy(cameraClass.VisorEffect); @@ -432,11 +475,11 @@ public void OnDestroy() // Destroy FreeCamScript before FreeCamController if exists Destroy(_freeCamScript); - Destroy(this); if (extractText != null) { Destroy(extractText); } + Destroy(this); } } } 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..b1acc974 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,7 +37,10 @@ public BotsController PBotsController { 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; } } diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index f177d7ba..3e368d87 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -1,6 +1,10 @@ -using Aki.Custom.Airdrops; +using Aki.Common.Http; +using Aki.Custom.Airdrops; using Aki.Reflection.Utils; -using BepInEx.Configuration; +using Aki.SinglePlayer.Models.Progression; +using Aki.SinglePlayer.Utils.Healing; +using Aki.SinglePlayer.Utils.Insurance; +using Aki.SinglePlayer.Utils.Progression; using BepInEx.Logging; using Comfort.Common; using CommonAssets.Scripts.Game; @@ -35,6 +39,7 @@ using HarmonyLib; using JsonType; using LiteNetLib.Utils; +using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; @@ -50,26 +55,32 @@ namespace Fika.Core.Coop.GameMode /// internal sealed class CoopGame : BaseLocalGame, IBotGame, IFikaGame { - public new bool InRaid { get => true; } - public string InfiltrationPoint; - public bool HasAddedFenceRep = false; - public bool forceStart = false; + public ExitStatus MyExitStatus { get; set; } = ExitStatus.Survived; + public string MyExitLocation { get; set; } = null; + public ISpawnSystem SpawnSystem; + + public Dictionary Bots = []; private CoopExfilManager exfilManager; private GameObject fikaStartButton; private readonly Dictionary botQueue = []; - private FikaDynamicAI dynamicAI; + private Coroutine extractRoutine; + private GClass2928 spawnPoints = null; + private ISpawnPoint spawnPoint = null; + private GClass579 GClass579; + private WavesSpawnScenario wavesSpawnScenario_0; + private NonWavesSpawnScenario nonWavesSpawnScenario_0; + private Func func_1; + private bool hasSaved = false; + public FikaDynamicAI DynamicAI { get; private set; } public RaidSettings RaidSettings { get; private set; } - //WildSpawnType for sptUsec and sptBear const int sptUsecValue = 47; const int sptBearValue = 48; - public ISession BackEndSession { get => PatchConstants.BackEndSession; } - BotsController IBotGame.BotsController { get @@ -77,7 +88,6 @@ BotsController IBotGame.BotsController return botsController_0; } } - public BotsController BotsController { get @@ -85,7 +95,6 @@ public BotsController BotsController return botsController_0; } } - public IWeatherCurve WeatherCurve { get @@ -94,7 +103,6 @@ public IWeatherCurve WeatherCurve } } - private static ManualLogSource Logger; internal static CoopGame Create(InputTree inputTree, Profile profile, GameDateTime backendDateTime, InsuranceCompanyClass insurance, MenuUI menuUI, @@ -215,8 +223,6 @@ public async Task CreateCoopHandler() } } - public Dictionary Bots { get; set; } = []; - private List GetPlayers(CoopHandler coopHandler) { List humanPlayers = []; @@ -317,7 +323,7 @@ private async Task CreateBot(Profile profile, Vector3 position) if (!CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler)) { - Logger.LogDebug($"{nameof(CreateBot)}:Unable to find {nameof(CoopHandler)}"); + Logger.LogError($"{nameof(CreateBot)}: Unable to find {nameof(CoopHandler)}"); return null; } @@ -331,7 +337,7 @@ private async Task CreateBot(Profile profile, Vector3 position) isSpecial = true; } - if (FikaPlugin.EnforcedSpawnLimits.Value && botsController_0.AliveAndLoadingBotsCount >= botsController_0.BotSpawner.MaxBots) + if (FikaPlugin.EnforcedSpawnLimits.Value && Bots.Count >= botsController_0.BotSpawner.MaxBots) { bool despawned = false; @@ -370,7 +376,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) { @@ -479,6 +485,9 @@ private bool TryDespawnFurthest(Profile profile, Vector3 position, CoopHandler c if (botKey == string.Empty) { +#if DEBUG + Logger.LogWarning("TryDespawnFurthest: botKey was empty"); +#endif return false; } @@ -517,7 +526,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 +560,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 +578,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 +616,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) { @@ -676,9 +697,6 @@ private async Task SendOrReceiveSpawnPoint() } } - GClass2928 spawnPoints = null; - ISpawnPoint spawnPoint = null; - /// /// Creating the EFT.LocalPlayer /// @@ -705,7 +723,7 @@ public override async Task vmethod_2(int playerId, Vector3 position CharacterControllerSpawner.Mode characterControllerMode, Func getSensitivity, Func getAimingSensitivity, IStatisticsManager statisticsManager, AbstractQuestControllerClass questController, AbstractAchievementControllerClass achievementsController) { - Logger.LogInfo("Creating CoopHandler!"); + Logger.LogInfo("Creating CoopHandler"); await CreateCoopHandler(); CoopHandler.GetCoopHandler().LocalGameInstance = this; @@ -719,16 +737,13 @@ public override async Task vmethod_2(int playerId, Vector3 position if (!CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler)) { Logger.LogDebug($"{nameof(vmethod_2)}:Unable to find {nameof(CoopHandler)}"); - await Task.Delay(5000); + throw new MissingComponentException("CoopHandler was missing during CoopGame init"); } - if (MatchmakerAcceptPatches.IsServer) + if (RaidSettings.MetabolismDisabled) { - if (RaidSettings.MetabolismDisabled) - { - myPlayer.HealthController.DisableMetabolism(); - NotificationManagerClass.DisplayMessageNotification("Metabolism disabled", iconType: EFT.Communications.ENotificationIconType.Alert); - } + myPlayer.HealthController.DisableMetabolism(); + NotificationManagerClass.DisplayMessageNotification("Metabolism disabled", iconType: EFT.Communications.ENotificationIconType.Alert); } CoopPlayer coopPlayer = (CoopPlayer)myPlayer; @@ -793,10 +808,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; } } @@ -809,7 +830,7 @@ public override async Task vmethod_2(int playerId, Vector3 position } else { - Singleton.Instance?.SendData(new NetDataWriter(), ref packet, LiteNetLib.DeliveryMethod.ReliableUnordered); + Singleton.Instance.SendData(new NetDataWriter(), ref packet, LiteNetLib.DeliveryMethod.ReliableUnordered); } if (MatchmakerAcceptPatches.IsServer) @@ -830,7 +851,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; @@ -965,7 +989,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) @@ -1118,28 +1145,31 @@ public override IEnumerator vmethod_4(float startDelay, BotControllerSettings co botsController_0.SetSettings(numberOfBots, BackEndSession.BackEndConfig.BotPresets, BackEndSession.BackEndConfig.BotWeaponScatterings); botsController_0.AddActivePLayer(PlayerOwner.Player); - int limits = Location_0.Id.ToLower() switch - { - "factory4_day" => FikaPlugin.MaxBotsFactory.Value, - "factory4_night" => FikaPlugin.MaxBotsFactory.Value, - "bigmap" => FikaPlugin.MaxBotsCustoms.Value, - "interchange" => FikaPlugin.MaxBotsInterchange.Value, - "rezervbase" => FikaPlugin.MaxBotsReserve.Value, - "woods" => FikaPlugin.MaxBotsWoods.Value, - "shoreline" => FikaPlugin.MaxBotsShoreline.Value, - "tarkovstreets" => FikaPlugin.MaxBotsStreets.Value, - "sandbox" => FikaPlugin.MaxBotsGroundZero.Value, - "laboratory" => FikaPlugin.MaxBotsLabs.Value, - "lighthouse" => FikaPlugin.MaxBotsLighthouse.Value, - _ => 0 - }; - - if (limits > 0) + if (FikaPlugin.EnforcedSpawnLimits.Value) { - botsController_0.BotSpawner.SetMaxBots(limits); + int limits = Location_0.Id.ToLower() switch + { + "factory4_day" => FikaPlugin.MaxBotsFactory.Value, + "factory4_night" => FikaPlugin.MaxBotsFactory.Value, + "bigmap" => FikaPlugin.MaxBotsCustoms.Value, + "interchange" => FikaPlugin.MaxBotsInterchange.Value, + "rezervbase" => FikaPlugin.MaxBotsReserve.Value, + "woods" => FikaPlugin.MaxBotsWoods.Value, + "shoreline" => FikaPlugin.MaxBotsShoreline.Value, + "tarkovstreets" => FikaPlugin.MaxBotsStreets.Value, + "sandbox" => FikaPlugin.MaxBotsGroundZero.Value, + "laboratory" => FikaPlugin.MaxBotsLabs.Value, + "lighthouse" => FikaPlugin.MaxBotsLighthouse.Value, + _ => 0 + }; + + if (limits > 0) + { + botsController_0.BotSpawner.SetMaxBots(limits); + } } - dynamicAI = gameObject.AddComponent(); + DynamicAI = gameObject.AddComponent(); } else if (MatchmakerAcceptPatches.IsClient) { @@ -1196,24 +1226,40 @@ 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); FikaPlugin.DynamicAI.SettingChanged += DynamicAI_SettingChanged; + FikaPlugin.DynamicAIRate.SettingChanged += DynamicAIRate_SettingChanged; } 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(); @@ -1237,11 +1283,19 @@ public override IEnumerator vmethod_4(float startDelay, BotControllerSettings co yield break; } + private void DynamicAIRate_SettingChanged(object sender, EventArgs e) + { + if (DynamicAI != null) + { + DynamicAI.RateChanged(FikaPlugin.DynamicAIRate.Value); + } + } + private void DynamicAI_SettingChanged(object sender, EventArgs e) { - if (dynamicAI != null) + if (DynamicAI != null) { - dynamicAI.SettingChanged(FikaPlugin.DynamicAI.Value); + DynamicAI.EnabledChange(FikaPlugin.DynamicAI.Value); } } @@ -1389,7 +1443,7 @@ public void ResetExfilPointsFromServer(ExfiltrationPoint[] points) /// /// The local player to start the Coroutine on /// - public void Extract(Player player, ExfiltrationPoint point) + public void Extract(CoopPlayer player, ExfiltrationPoint point) { PreloaderUI preloaderUI = Singleton.Instance; @@ -1416,7 +1470,7 @@ public void Extract(Player player, ExfiltrationPoint point) GenericPacket genericPacket = new() { - NetId = ((CoopPlayer)player).NetId, + NetId = player.NetId, PacketType = EPackageType.ClientExtract }; @@ -1424,11 +1478,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); } } @@ -1451,6 +1505,8 @@ public void Extract(Player player, ExfiltrationPoint point) player.ActiveHealthController.DisableMetabolism(); player.ActiveHealthController.PauseAllEffects(); + extractRoutine = StartCoroutine(ExtractRoutine(player)); + // Prevents players from looting after extracting GClass3107.Instance.CloseAllScreensForced(); @@ -1480,6 +1536,30 @@ public void Extract(Player player, ExfiltrationPoint point) } } + /// + /// Used to make sure no stims or mods reset the DamageCoeff + /// + /// The to run the coroutine on + /// + private IEnumerator ExtractRoutine(CoopPlayer player) + { + while (true) + { + if (player != null && player.ActiveHealthController != null) + { + if (player.ActiveHealthController.DamageCoeff != 0) + { + player.ActiveHealthController.SetDamageCoeff(0); + } + } + else + { + yield break; + } + yield return new WaitForEndOfFrame(); + } + } + public void ClearHostAI(Player player) { if (player != null) @@ -1506,10 +1586,6 @@ public void ClearHostAI(Player player) } } - public ExitStatus MyExitStatus { get; set; } = ExitStatus.Survived; - public string MyExitLocation { get; set; } = null; - public ISpawnSystem SpawnSystem { get; set; } - private void HealthController_DiedEvent(EDamageType obj) { gparam_0.Player.HealthController.DiedEvent -= method_15; @@ -1518,6 +1594,11 @@ private void HealthController_DiedEvent(EDamageType obj) PlayerOwner.vmethod_1(); MyExitStatus = ExitStatus.Killed; MyExitLocation = null; + + if (FikaPlugin.Instance.ForceSaveOnDeath) + { + SavePlayer((CoopPlayer)gparam_0.Player, MyExitStatus, null, true); + } } public override void Stop(string profileId, ExitStatus exitStatus, string exitName, float delay = 0f) @@ -1525,7 +1606,19 @@ 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) + { + if (myPlayer.Equipment.GetSlot(EquipmentSlot.Dogtag).ContainedItem != null) + { + GStruct414 result = InteractionsHandlerClass.Remove(myPlayer.Equipment.GetSlot(EquipmentSlot.Dogtag).ContainedItem, myPlayer.GClass2761_0, false, true); + if (result.Error != null) + { + FikaPlugin.Instance.FikaLogger.LogWarning("CoopGame::Stop: Error removing dog tag!"); + } + } + } if (!myPlayer.ActiveHealthController.IsAlive && exitStatus == ExitStatus.Survived) { @@ -1546,9 +1639,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 { @@ -1593,13 +1695,7 @@ public override void Stop(string profileId, ExitStatus exitStatus, string exitNa Destroy(CoopHandler.CoopHandlerParent); } - Class1364 stopManager = new() - { - baseLocalGame_0 = this, - exitStatus = exitStatus, - exitName = exitName, - delay = delay - }; + ExitManager stopManager = new(this, exitStatus, exitName, delay, myPlayer); EndByExitTrigerScenario endByExitTrigger = GetComponent(); EndByTimerScenario endByTimerScenario = GetComponent(); @@ -1622,17 +1718,66 @@ public override void Stop(string profileId, ExitStatus exitStatus, string exitNa { gameUI.TimerPanel.Close(); } - EnvironmentManager.Instance?.Stop(); - MonoBehaviourSingleton.Instance.StartBlackScreenShow(1f, 1f, new Action(stopManager.method_0)); + if (EnvironmentManager.Instance != null) + { + EnvironmentManager.Instance.Stop(); + } + MonoBehaviourSingleton.Instance.StartBlackScreenShow(1f, 1f, new Action(stopManager.HandleExit)); GClass549.Config.UseSpiritPlayer = false; } + private void SavePlayer(CoopPlayer player, ExitStatus exitStatus, string exitName, bool fromDeath) + { + if (hasSaved) + { + return; + } + + if (fromDeath) + { + //Since we're bypassing saving on exiting, run this now. + player.Profile.EftStats.LastPlayerState = null; + player.StatisticsManager.EndStatisticsSession(exitStatus, PastTime); + player.CheckAndResetControllers(exitStatus, PastTime, Location_0.Id, exitName); + } + + //Method taken directly from AKI, can be found in the aki-singleplayer assembly as OfflineSaveProfilePatch + Type converterClass = typeof(AbstractGame).Assembly.GetTypes().First(t => t.GetField("Converters", BindingFlags.Static | BindingFlags.Public) != null); + + JsonConverter[] Converters = Traverse.Create(converterClass).Field("Converters").Value; + + SaveProfileRequest SaveRequest = new() + { + Exit = exitStatus.ToString().ToLowerInvariant(), + Profile = player.Profile, + Health = HealthListener.Instance.CurrentHealth, + Insurance = InsuredItemManager.Instance.GetTrackedItems(), + IsPlayerScav = player.Side is EPlayerSide.Savage + }; + + RequestHandler.PutJson("/raid/profile/save", SaveRequest.ToJson(Converters.AddItem(new NotesJsonConverter()).ToArray())); + + hasSaved = true; + } + private void StopFromError(string profileId, ExitStatus exitStatus) { Logger.LogInfo("CoopGame::StopFromError"); CoopPlayer myPlayer = (CoopPlayer)Singleton.Instance.MainPlayer; - myPlayer.PacketSender?.DestroyThis(); + myPlayer.PacketSender.DestroyThis(); + + if (myPlayer.Side != EPlayerSide.Savage) + { + if (myPlayer.Equipment.GetSlot(EquipmentSlot.Dogtag).ContainedItem != null) + { + GStruct414 result = InteractionsHandlerClass.Remove(myPlayer.Equipment.GetSlot(EquipmentSlot.Dogtag).ContainedItem, myPlayer.GClass2761_0, false, true); + if (result.Error != null) + { + FikaPlugin.Instance.FikaLogger.LogWarning("CoopGame::StopFromError: Error removing dog tag!"); + } + } + } string exitName = null; float delay = 0f; @@ -1667,11 +1812,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() { @@ -1693,17 +1845,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; } @@ -1737,12 +1901,17 @@ public override void Dispose() Singleton.Instance.MineManager.OnExplosion -= OnMineExplode; } + if (extractRoutine != null) + { + StopCoroutine(extractRoutine); + } + 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(); @@ -1752,10 +1921,11 @@ public override void Dispose() } FikaPlugin.DynamicAI.SettingChanged -= DynamicAI_SettingChanged; + FikaPlugin.DynamicAIRate.SettingChanged -= DynamicAIRate_SettingChanged; } 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 @@ -1784,10 +1954,48 @@ public override void Dispose() base.Dispose(); } - private GClass579 GClass579; - private WavesSpawnScenario wavesSpawnScenario_0; - private NonWavesSpawnScenario nonWavesSpawnScenario_0; - private Func func_1; + private class ExitManager(CoopGame localGame, ExitStatus exitStatus, string exitName, float delay, CoopPlayer localPlayer) + { + private readonly CoopGame localGame = localGame; + private readonly ExitStatus exitStatus = exitStatus; + private readonly string exitName = exitName; + private readonly float delay = delay; + private readonly CoopPlayer localPlayer = localPlayer; + private Action EndAction; + + public void HandleExit() + { + GClass3107 screenManager = GClass3107.Instance; + if (screenManager.CheckCurrentScreen(EEftScreenType.Reconnect)) + { + screenManager.CloseAllScreensForced(); + } + localGame.gparam_0.Player.OnGameSessionEnd(exitStatus, localGame.PastTime, localGame.Location_0.Id, exitName); + localGame.CleanUp(); + localGame.Status = GameStatus.Stopped; + TimeSpan timeSpan = GClass1296.Now - localGame.dateTime_0; + localGame.ginterface145_0.OfflineRaidEnded(exitStatus, exitName, timeSpan.TotalSeconds).HandleExceptions(); + MonoBehaviourSingleton.Instance.FadeOutVolumeAfterRaid(); + StaticManager staticManager = StaticManager.Instance; + float num = delay; + Action action; + if ((action = EndAction) == null) + { + action = (EndAction = new Action(FireCallback)); + } + staticManager.WaitSeconds(num, action); + } + + private void FireCallback() + { + Callback endCallback = Traverse.Create(localGame).Field("callback_0").GetValue>(); + + localGame.SavePlayer(localPlayer, exitStatus, exitName, false); + + endCallback(new Result(exitStatus, GClass1296.Now - localGame.dateTime_0, new MetricsClass())); + UIEventSystem.Instance.Enable(); + } + } private class ErrorExitManager : Class1364 { @@ -1798,12 +2006,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; @@ -1815,10 +2026,9 @@ public void ExitOverride() } } - public new void method_6(string backendUrl, string locationId, int variantId) { - Logger.LogInfo("CoopGame:method_6"); + Logger.LogDebug("CoopGame::method_6"); return; } } diff --git a/Fika.Core/Coop/GameMode/IMPTGame.cs b/Fika.Core/Coop/GameMode/IFikaGame.cs similarity index 100% rename from Fika.Core/Coop/GameMode/IMPTGame.cs rename to Fika.Core/Coop/GameMode/IFikaGame.cs diff --git a/Fika.Core/Coop/Matchmaker/MatchmakerAccept/MatchmakerAcceptPatches.cs b/Fika.Core/Coop/Matchmaker/MatchmakerAccept/MatchmakerAcceptPatches.cs index fa521a98..5aac7c1c 100644 --- a/Fika.Core/Coop/Matchmaker/MatchmakerAccept/MatchmakerAcceptPatches.cs +++ b/Fika.Core/Coop/Matchmaker/MatchmakerAccept/MatchmakerAcceptPatches.cs @@ -74,7 +74,7 @@ public static void SetTimestamp(long ts) timestamp = ts; } - public static bool JoinMatch(RaidSettings settings, string profileId, string serverId, out CreateMatch result, out string errorMessage) + public static bool JoinMatch(string profileId, string serverId, out CreateMatch result, out string errorMessage) { result = new CreateMatch(); errorMessage = $"No server matches the data provided or the server no longer exists"; diff --git a/Fika.Core/Coop/Matchmaker/MatchmakerAccept/MatchmakerAcceptScreen_Show_Patch.cs b/Fika.Core/Coop/Matchmaker/MatchmakerAccept/MatchmakerAcceptScreen_Show_Patch.cs index 7e0ba5af..247f50a3 100644 --- a/Fika.Core/Coop/Matchmaker/MatchmakerAccept/MatchmakerAcceptScreen_Show_Patch.cs +++ b/Fika.Core/Coop/Matchmaker/MatchmakerAccept/MatchmakerAcceptScreen_Show_Patch.cs @@ -12,12 +12,10 @@ namespace Fika.Core.Coop.Matchmaker public class MatchmakerAcceptScreen_Show_Patch : ModulePatch { protected override MethodBase GetTargetMethod() => typeof(MatchMakerAcceptScreen).GetMethods(BindingFlags.Public | BindingFlags.Instance).First(x => x.Name == "Show" && x.GetParameters()[0].Name == "session"); - private static GameObject MatchmakerObject { get; set; } [PatchPrefix] - private static void PreFix(ref ISession session, ref RaidSettings raidSettings, Profile ___profile_0, MatchMakerAcceptScreen __instance, - DefaultUIButton ____acceptButton, DefaultUIButton ____backButton, MatchMakerPlayerPreview ____playerModelView) + private static void PreFix(ref RaidSettings raidSettings, DefaultUIButton ____acceptButton, DefaultUIButton ____backButton) { if (MatchmakerObject == null) { diff --git a/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedFirearmController.cs b/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedFirearmController.cs index c3290abb..c7507469 100644 --- a/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedFirearmController.cs +++ b/Fika.Core/Coop/ObservedClasses/HandsControllers/CoopObservedFirearmController.cs @@ -3,8 +3,10 @@ using Comfort.Common; using EFT; using EFT.InventoryLogic; +using EFT.UI; using Fika.Core.Coop.Players; using Fika.Core.Networking; +using HarmonyLib; using System; using System.Collections; using System.Collections.Generic; @@ -28,6 +30,7 @@ public class CoopObservedFirearmController : FirearmController private float aimMovementSpeed = 1f; private bool hasFired = false; private WeaponPrefab weaponPrefab; + private GClass1582 underBarrelManager; public override bool IsAiming { get => base.IsAiming; @@ -43,7 +46,7 @@ public override bool IsAiming } _isAiming = value; - _player.Skills.FastAimTimer.Target = (value ? 0f : 2f); + _player.Skills.FastAimTimer.Target = value ? 0f : 2f; _player.MovementContext.SetAimingSlowdown(IsAiming, 0.33f + aimMovementSpeed); _player.Physical.Aim((!_isAiming || !(_player.MovementContext.StationaryWeapon == null)) ? 0f : ErgonomicWeight); coopPlayer.ProceduralWeaponAnimation.IsAiming = _isAiming; @@ -62,6 +65,10 @@ protected void Start() _objectInHandsAnimator.SetAiming(false); aimMovementSpeed = coopPlayer.Skills.GetWeaponInfo(Item).AimMovementSpeed; weaponPrefab = ControllerGameObject.GetComponent(); + if (UnderbarrelWeapon != null) + { + underBarrelManager = Traverse.Create(this).Field("gclass1582_0").GetValue(); + } } public static CoopObservedFirearmController Create(CoopPlayer player, Weapon weapon) @@ -226,7 +233,7 @@ public void HandleFirearmPacket(in WeaponPacket packet, InventoryControllerClass } BulletClass ammo = (BulletClass)Singleton.Instance.CreateItem(MongoID.Generate(), packet.ShotInfoPacket.AmmoTemplate, null); - InitiateShot(Item, ammo, packet.ShotInfoPacket.ShotPosition, packet.ShotInfoPacket.ShotDirection, + InitiateShot(packet.ShotInfoPacket.UnderbarrelShot ? UnderbarrelWeapon : Item, ammo, packet.ShotInfoPacket.ShotPosition, packet.ShotInfoPacket.ShotDirection, packet.ShotInfoPacket.FireportPosition, packet.ShotInfoPacket.ChamberIndex, packet.ShotInfoPacket.Overheat); if (Weapon.SelectedFireMode == Weapon.EFireMode.fullauto) @@ -254,6 +261,18 @@ public void HandleFirearmPacket(in WeaponPacket packet, InventoryControllerClass FirearmsAnimator.SetFire(true); + if (packet.ShotInfoPacket.UnderbarrelShot) + { + if (UnderbarrelWeapon.Chamber.ContainedItem is BulletClass grenadeBullet && !grenadeBullet.IsUsed) + { + grenadeBullet.IsUsed = true; + UnderbarrelWeapon.Chamber.RemoveItem(); + underBarrelManager?.DestroyPatronInWeapon(); + } + FirearmsAnimator.SetFire(false); + return; + } + if (Weapon.HasChambers) { if (Weapon.ReloadMode is Weapon.EReloadMode.OnlyBarrel) @@ -284,7 +303,7 @@ public void HandleFirearmPacket(in WeaponPacket packet, InventoryControllerClass } else { - Weapon.Chambers[0].RemoveItem(false); + Weapon.Chambers[0].RemoveItem(); if (weaponPrefab != null && weaponPrefab.ObjectInHands is GClass1668 weaponEffectsManager) { HandleShellEvent(weaponEffectsManager, packet, ammo, magazine); @@ -521,8 +540,6 @@ public void HandleFirearmPacket(in WeaponPacket packet, InventoryControllerClass { CurrentOperation.SetTriggerPressed(true); } - - }*/ if (packet.HasRollCylinder && Weapon is GClass2696 rollWeapon) @@ -594,6 +611,16 @@ public void HandleFirearmPacket(in WeaponPacket packet, InventoryControllerClass { StartCoroutine(ObservedBoltAction(FirearmsAnimator, this, inventoryController)); } + + if (packet.UnderbarrelSightingRangeUp) + { + UnderbarrelSightingRangeUp(); + } + + if (packet.UnderbarrelSightingRangeDown) + { + UnderbarrelSightingRangeDown(); + } } private IEnumerator ObservedBoltAction(FirearmsAnimator animator, FirearmController controller, InventoryControllerClass inventoryController) 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 c545e3d6..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(); } } @@ -140,10 +140,6 @@ private IEnumerator SyncWorld() yield return null; } - Writer?.Reset(); - SessionSettingsPacket settingsPacket = new(true); - Client?.SendData(Writer, ref settingsPacket, DeliveryMethod.ReliableOrdered); - CoopGame coopGame = (CoopGame)Singleton.Instance; if (coopGame == null) @@ -158,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() @@ -192,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..042467f3 100644 --- a/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs +++ b/Fika.Core/Coop/PacketHandlers/ServerPacketSender.cs @@ -47,7 +47,7 @@ protected void Start() protected void FixedUpdate() { - if (player == null || Writer == null) + if (player == null || Writer == null || Server == null) { return; } @@ -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/AbstractGame/AbstractGame_InRaid_Patch.cs b/Fika.Core/Coop/Patches/AbstractGame/AbstractGame_InRaid_Patch.cs index 43043ca0..8a5f9a6e 100644 --- a/Fika.Core/Coop/Patches/AbstractGame/AbstractGame_InRaid_Patch.cs +++ b/Fika.Core/Coop/Patches/AbstractGame/AbstractGame_InRaid_Patch.cs @@ -16,7 +16,7 @@ protected override MethodBase GetTargetMethod() } [PatchPrefix] - private static bool PreFix(AbstractGame __instance, bool __result) + private static bool PreFix(AbstractGame __instance, ref bool __result) { __result = __instance is CoopGame; return false; diff --git a/Fika.Core/Coop/Patches/LocalGame/TarkovApplication_LocalGameCreator_Patch.cs b/Fika.Core/Coop/Patches/LocalGame/TarkovApplication_LocalGameCreator_Patch.cs index c84b2c7b..cd340717 100644 --- a/Fika.Core/Coop/Patches/LocalGame/TarkovApplication_LocalGameCreator_Patch.cs +++ b/Fika.Core/Coop/Patches/LocalGame/TarkovApplication_LocalGameCreator_Patch.cs @@ -8,6 +8,8 @@ using Fika.Core.Coop.Matchmaker; using Fika.Core.Modding; using Fika.Core.Modding.Events; +using Fika.Core.Networking.Http; +using Fika.Core.Networking.Http.Models; using System; using System.Linq; using System.Reflection; @@ -82,15 +84,11 @@ public static async Task Postfix(Task __result, TarkovApplication __instance, Ti ISession session = CurrentSession; - /*Profile profile = session.Profile; - Profile profileScav = session.ProfileOfPet;*/ - Profile profile = session.GetProfileBySide(____raidSettings.Side); profile.Inventory.Stash = null; profile.Inventory.QuestStashItems = null; profile.Inventory.DiscardLimits = Singleton.Instance.GetDiscardLimits(); - //____raidSettings.RaidMode = ERaidMode.Online; Logger.LogDebug("TarkovApplication_LocalGameCreator_Patch:Postfix: Attempt to set Raid Settings"); @@ -99,6 +97,12 @@ public static async Task Postfix(Task __result, TarkovApplication __instance, Ti if (MatchmakerAcceptPatches.IsClient) { timeHasComeScreenController.ChangeStatus("Joining Coop Game"); + + RaidSettingsRequest data = new(); + RaidSettingsResponse raidSettingsResponse = await FikaRequestHandler.GetRaidSettings(data); + + ____raidSettings.MetabolismDisabled = raidSettingsResponse.MetabolismDisabled; + ____raidSettings.PlayersSpawnPlace = (EPlayersSpawnPlace)Enum.Parse(typeof(EPlayersSpawnPlace), raidSettingsResponse.PlayersSpawnPlace); } else { @@ -114,6 +118,7 @@ public static async Task Postfix(Task __result, TarkovApplication __instance, Ti ____raidSettings.WavesSettings, ____raidSettings.SelectedDateTime, new Callback(startHandler.HandleStart), ____fixedDeltaTime, EUpdateQueue.Update, session, TimeSpan.FromSeconds(60 * ____raidSettings.SelectedLocation.EscapeTimeLimit), ____raidSettings ); + Singleton.Create(localGame); FikaEventDispatcher.DispatchEvent(new AbstractGameCreatedEvent(localGame)); 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..f414af6f 100644 --- a/Fika.Core/Coop/Players/CoopBot.cs +++ b/Fika.Core/Coop/Players/CoopBot.cs @@ -51,6 +51,9 @@ public static async Task CreateBot(int playerId, Vector3 position, InventoryControllerClass inventoryController = new CoopBotInventoryController(player, profile, true); + player.PacketSender = player.gameObject.AddComponent(); + player.PacketReceiver = player.gameObject.AddComponent(); + await player.Init(rotation, layerName, pointOfView, profile, inventoryController, new CoopBotHealthController(profile.Health, player, inventoryController, profile.Skills, aiControl), new CoopObservedStatisticsManager(), null, null, filter, @@ -137,14 +140,6 @@ public override GClass1676 ApplyShot(DamageInfo damageInfo, EBodyPart bodyPartTy protected override void Start() { - PacketSender = gameObject.AddComponent(); - PacketReceiver = gameObject.AddComponent(); - - /*if (FikaPlugin.DynamicAI.Value) - { - dynamicAi = gameObject.AddComponent(); - }*/ - if (FikaPlugin.DisableBotMetabolism.Value) { HealthController.DisableMetabolism(); @@ -253,7 +248,10 @@ private IEnumerator DestroyNetworkedComponents() { yield return new WaitForSeconds(2); - PacketSender?.DestroyThis(); + if (PacketSender != null) + { + PacketSender.DestroyThis(); + } } public override void UpdateTick() @@ -359,7 +357,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..5da9fe75 100644 --- a/Fika.Core/Coop/Players/CoopPlayer.cs +++ b/Fika.Core/Coop/Players/CoopPlayer.cs @@ -62,16 +62,29 @@ public static async Task Create(int playerId, Vector3 position, Qua player.IsYourPlayer = true; player.NetId = netId; - CoopClientInventoryController inventoryController = new(player, profile, true); + CoopClientInventoryController inventoryController = new(player, profile, false); - GClass3206 questController = new(profile, inventoryController, null, true); + ISession session = Singleton>.Instance.GetClientBackEndSession(); + + GClass3206 questController = new(profile, inventoryController, session, true); questController.Init(); questController.Run(); - AchievementControllerClass achievementsController = new(profile, inventoryController, null, true); + AchievementControllerClass achievementsController = new(profile, inventoryController, session, true); achievementsController.Init(); achievementsController.Run(); + if (MatchmakerAcceptPatches.IsServer) + { + player.PacketSender = player.gameObject.AddComponent(); + } + else if (MatchmakerAcceptPatches.IsClient) + { + player.PacketSender = player.gameObject.AddComponent(); + } + + player.PacketReceiver = player.gameObject.AddComponent(); + await player.Init(rotation, layerName, pointOfView, profile, inventoryController, new CoopClientHealthController(profile.Health, player, inventoryController, profile.Skills, aiControl), statisticsManager, questController, achievementsController, filter, @@ -124,8 +137,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 +155,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 +171,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 +232,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 +338,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 +358,7 @@ public override void SetInventoryOpened(bool opened) } base.SetInventoryOpened(opened); - PacketSender?.CommonPlayerPackets?.Enqueue(new() + PacketSender.CommonPlayerPackets.Enqueue(new() { HasInventoryChanged = true, SetInventoryOpen = opened @@ -352,7 +368,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,15 +389,18 @@ public override void SendHeadlightsPacket(bool isSilent) { GStruct163[] lightStates = _helmetLightControllers.Select(new Func(ClientPlayer.Class1430.class1430_0.method_0)).ToArray(); - PacketSender?.CommonPlayerPackets?.Enqueue(new() + if (PacketSender != null) { - HasHeadLightsPacket = true, - HeadLightsPacket = new() + PacketSender.CommonPlayerPackets.Enqueue(new() { - Amount = lightStates.Count(), - LightStates = lightStates - } - }); + HasHeadLightsPacket = true, + HeadLightsPacket = new() + { + Amount = lightStates.Count(), + LightStates = lightStates + } + }); + } } public override void OnItemAddedOrRemoved(Item item, ItemAddress location, bool added) @@ -395,7 +414,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 +425,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 +466,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 +491,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 +499,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 +549,10 @@ private IEnumerator DestroyNetworkedComponents() { yield return new WaitForSeconds(2); - PacketSender?.DestroyThis(); + if (PacketSender != null) + { + PacketSender.DestroyThis(); + } } public override void Move(Vector2 direction) @@ -761,7 +783,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 +795,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) @@ -821,15 +843,6 @@ public override void TryInteractionCallback(LootableContainer container) protected virtual void Start() { - if (MatchmakerAcceptPatches.IsServer) - { - PacketSender = gameObject.AddComponent(); - } - else if (MatchmakerAcceptPatches.IsClient) - { - PacketSender = gameObject.AddComponent(); - } - PacketReceiver = gameObject.AddComponent(); Profile.Info.GroupId = "Fika"; if (Side != EPlayerSide.Savage) @@ -934,7 +947,7 @@ public virtual void HandleCommonPacket(in CommonPlayerPacket packet) { if (this is ObservedCoopPlayer observedCoopPlayer) { - observedCoopPlayer?.HandleProceedPacket(packet.ProceedPacket); + observedCoopPlayer.HandleProceedPacket(packet.ProceedPacket); } } @@ -1326,6 +1339,15 @@ public virtual void SetupDogTag() } } + public void CheckAndResetControllers(ExitStatus exitStatus, float pastTime, string locationId, string exitName) + { + _questController?.CheckExitConditionCounters(exitStatus, pastTime, locationId, exitName, HealthController.BodyPartEffects, TriggerZones); + _questController?.ResetCurrentNullableCounters(); + + _achievementsController?.CheckExitConditionCounters(exitStatus, pastTime, locationId, exitName, HealthController.BodyPartEffects, TriggerZones); + _achievementsController?.ResetCurrentNullableCounters(); + } + public virtual void SetInventory(EquipmentClass equipmentClass) { // Do nothing @@ -1339,7 +1361,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 +1372,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 +1382,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 +1446,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 +1484,7 @@ internal void SendPacket() return; } - coopPlayer.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() @@ -1494,7 +1519,7 @@ internal QuickUseItemController ReturnController() internal void SendPacket() { - coopPlayer.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() @@ -1531,7 +1556,7 @@ internal MedsController ReturnController() internal void SendPacket() { - coopPlayer.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() @@ -1571,7 +1596,7 @@ internal MedsController ReturnController() internal void SendPacket() { - coopPlayer.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() @@ -1609,7 +1634,7 @@ internal CoopClientKnifeController ReturnController() internal void SendPacket() { - coopPlayer.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() @@ -1644,7 +1669,7 @@ internal QuickKnifeKickController ReturnController() internal void SendPacket() { - coopPlayer.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() @@ -1679,7 +1704,7 @@ internal CoopClientGrenadeController ReturnController() internal void SendPacket() { - coopPlayer.PacketSender?.CommonPlayerPackets?.Enqueue(new() + coopPlayer.PacketSender.CommonPlayerPackets.Enqueue(new() { HasProceedPacket = true, ProceedPacket = new() @@ -1714,7 +1739,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..0df67055 100644 --- a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs +++ b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs @@ -37,6 +37,7 @@ public class ObservedCoopPlayer : CoopPlayer private readonly float interpolationRatio = 0.5f; private float observedFixedTime = 0f; private FikaHealthBar healthBar = null; + private Coroutine waitForStartRoutine; public GClass2417 NetworkHealthController { get => HealthController as GClass2417; @@ -115,7 +116,7 @@ public override float SqrCameraDistance } #endregion - public static async Task CreateObservedPlayer(int playerId, Vector3 position, Quaternion rotation, + public static async Task CreateObservedPlayer(int playerId, Vector3 position, Quaternion rotation, string layerName, string prefix, EPointOfView pointOfView, Profile profile, bool aiControl, EUpdateQueue updateQueue, EUpdateMode armsUpdateMode, EUpdateMode bodyUpdateMode, CharacterControllerSpawner.Mode characterControllerMode, Func getSensitivity, @@ -261,7 +262,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 +334,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 +402,7 @@ public override GClass1676 ApplyShot(DamageInfo damageInfo, EBodyPart bodyPartTy colliderType = bodyPartCollider.BodyPartColliderType; } - PacketSender?.DamagePackets?.Enqueue(new() + PacketSender.DamagePackets.Enqueue(new() { DamageInfo = new() { @@ -461,7 +462,7 @@ public override GClass1676 ApplyShot(DamageInfo damageInfo, EBodyPart bodyPartTy colliderType = bodyPartCollider.BodyPartColliderType; } - PacketSender?.DamagePackets?.Enqueue(new() + PacketSender.DamagePackets.Enqueue(new() { DamageInfo = new() { @@ -602,7 +603,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 +830,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); @@ -884,7 +891,7 @@ private IEnumerator DestroyNetworkedComponents() } } - protected override async void Start() + public void InitObservedPlayer() { if (gameObject.name.StartsWith("Bot_")) { @@ -892,6 +899,7 @@ protected override async void Start() } PacketSender = gameObject.AddComponent(); + Traverse playerTraverse = Traverse.Create(this); if (IsObservedAI) { @@ -903,18 +911,20 @@ protected override async void Start() PacketSender.Writer.Reset(); PacketSender.Client.SendData(PacketSender.Writer, ref genericPacket, LiteNetLib.DeliveryMethod.ReliableOrdered); - IVaultingComponent vaultingComponent = Traverse.Create(this).Field("_vaultingComponent").GetValue(); + IVaultingComponent vaultingComponent = playerTraverse.Field("_vaultingComponent").GetValue(); if (vaultingComponent != null) { UpdateEvent -= vaultingComponent.DoVaultingTick; } - Traverse.Create(this).Field("_vaultingComponent").SetValue(null); - Traverse.Create(this).Field("_vaultingComponentDebug").SetValue(null); - Traverse.Create(this).Field("_vaultingParameters").SetValue(null); - Traverse.Create(this).Field("_vaultingGameplayRestrictions").SetValue(null); - Traverse.Create(this).Field("_vaultAudioController").SetValue(null); - Traverse.Create(this).Field("_sprintVaultAudioController").SetValue(null); - Traverse.Create(this).Field("_climbAudioController").SetValue(null); + + + playerTraverse.Field("_vaultingComponent").SetValue(null); + playerTraverse.Field("_vaultingComponentDebug").SetValue(null); + playerTraverse.Field("_vaultingParameters").SetValue(null); + playerTraverse.Field("_vaultingGameplayRestrictions").SetValue(null); + playerTraverse.Field("_vaultAudioController").SetValue(null); + playerTraverse.Field("_sprintVaultAudioController").SetValue(null); + playerTraverse.Field("_climbAudioController").SetValue(null); if (FikaPlugin.CullPlayers.Value) { @@ -928,17 +938,19 @@ protected override async void Start() { Profile.Info.GroupId = "Fika"; + var asd = Side; + CoopGame coopGame = (CoopGame)Singleton.Instance; - IVaultingComponent vaultingComponent = Traverse.Create(this).Field("_vaultingComponent").GetValue(); + IVaultingComponent vaultingComponent = playerTraverse.Field("_vaultingComponent").GetValue(); if (vaultingComponent != null) { UpdateEvent -= vaultingComponent.DoVaultingTick; } - Traverse.Create(this).Field("_vaultingComponent").SetValue(null); - Traverse.Create(this).Field("_vaultingComponentDebug").SetValue(null); - Traverse.Create(this).Field("_vaultingParameters").SetValue(null); - Traverse.Create(this).Field("_vaultingGameplayRestrictions").SetValue(null); + playerTraverse.Field("_vaultingComponent").SetValue(null); + playerTraverse.Field("_vaultingComponentDebug").SetValue(null); + playerTraverse.Field("_vaultingParameters").SetValue(null); + playerTraverse.Field("_vaultingGameplayRestrictions").SetValue(null); InitVaultingAudioControllers(ObservedVaultingParameters); @@ -948,16 +960,34 @@ protected override async void Start() EFT.Communications.ENotificationDurationType.Default, EFT.Communications.ENotificationIconType.Friend); } - // Spawn these later to prevent errors - while (coopGame.Status != GameStatus.Started) - { - await Task.Delay(TimeSpan.FromSeconds(1)); - } + waitForStartRoutine = StartCoroutine(CreateHealthBar()); + + RaycastCameraTransform = playerTraverse.Field("_playerLookRaycastTransform").GetValue(); + } + } - healthBar = gameObject.AddComponent(); + private IEnumerator CreateHealthBar() + { + CoopGame coopGame = (CoopGame)Singleton.Instance; - RaycastCameraTransform = Traverse.Create(this).Field("_playerLookRaycastTransform").GetValue(); + if (coopGame == null) + { + yield break; + } + + while (coopGame.Status != GameStatus.Started) + { + yield return null; } + + healthBar = gameObject.AddComponent(); + + yield break; + } + + protected override void Start() + { + // Do nothing } public override void LateUpdate() @@ -1010,7 +1040,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 +1172,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/EssentialPatches/FikaVersionLabel_Patch.cs b/Fika.Core/EssentialPatches/FikaVersionLabel_Patch.cs index 1ad96296..5d7f1d23 100644 --- a/Fika.Core/EssentialPatches/FikaVersionLabel_Patch.cs +++ b/Fika.Core/EssentialPatches/FikaVersionLabel_Patch.cs @@ -33,8 +33,10 @@ internal static void PatchPostfix(string major, object __result) string fikaVersion = Assembly.GetAssembly(typeof(FikaVersionLabel_Patch)).GetName().Version.ToString(); - Traverse.Create(MonoBehaviourSingleton.Instance).Field("_alphaVersionLabel").Property("LocalizationKey").SetValue("{0}"); - Traverse.Create(MonoBehaviourSingleton.Instance).Field("string_2").SetValue($"Fika {fikaVersion} |"); + Traverse preloaderUiTraverse = Traverse.Create(MonoBehaviourSingleton.Instance); + + preloaderUiTraverse.Field("_alphaVersionLabel").Property("LocalizationKey").SetValue("{0}"); + preloaderUiTraverse.Field("string_2").SetValue($"Fika {fikaVersion} |"); Traverse.Create(__result).Field("Major").SetValue($"FIKA BETA {fikaVersion} | {_versionLabel}"); } } diff --git a/Fika.Core/FikaPlugin.cs b/Fika.Core/FikaPlugin.cs index daf2a0ce..d351c479 100644 --- a/Fika.Core/FikaPlugin.cs +++ b/Fika.Core/FikaPlugin.cs @@ -44,7 +44,7 @@ namespace Fika.Core /// Originally by: Paulov
/// Re-written by: Lacyway /// - [BepInPlugin("com.fika.core", "Fika.Core", "0.9.89")] + [BepInPlugin("com.fika.core", "Fika.Core", "0.9.8906")] [BepInProcess("EscapeFromTarkov.exe")] [BepInDependency("com.spt-aki.custom", BepInDependency.DependencyFlags.HardDependency)] // This is used so that we guarantee to load after aki-custom, that way we can disable its patches [BepInDependency("com.spt-aki.singleplayer", BepInDependency.DependencyFlags.HardDependency)] // This is used so that we guarantee to load after aki-singleplayer, that way we can disable its patches @@ -180,6 +180,7 @@ public class FikaPlugin : BaseUnityPlugin public bool DynamicVExfils; public bool AllowFreeCam; public bool AllowItemSending; + public bool ForceSaveOnDeath; #endregion protected void Awake() @@ -258,6 +259,7 @@ private void GetClientConfig() DynamicVExfils = clientConfig.DynamicVExfils; AllowFreeCam = clientConfig.AllowFreeCam; AllowItemSending = clientConfig.AllowItemSending; + ForceSaveOnDeath = clientConfig.ForceSaveOnDeath; clientConfig.ToString(); } @@ -348,25 +350,25 @@ private void SetupConfig() DespawnMinimumDistance = Config.Bind("Performance | Max Bots", "Despawn Minimum Distance", 200.0f, new ConfigDescription("Don't despawn bots within this distance.", new AcceptableValueRange(50f, 3000f), new ConfigurationManagerAttributes() { Order = 12 })); - MaxBotsFactory = Config.Bind("Performance | Max Bots", "Max Bots Factory", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Factory. Useful if you have a weaker PC. Set to 0 to use vanilla limits.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 11 })); + MaxBotsFactory = Config.Bind("Performance | Max Bots", "Max Bots Factory", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Factory. Useful if you have a weaker PC. Set to 0 to use vanilla limits. Cannot be changed during a raid.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 11 })); - MaxBotsCustoms = Config.Bind("Performance | Max Bots", "Max Bots Customs", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Customs. Useful if you have a weaker PC. Set to 0 to use vanilla limits.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 10 })); + MaxBotsCustoms = Config.Bind("Performance | Max Bots", "Max Bots Customs", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Customs. Useful if you have a weaker PC. Set to 0 to use vanilla limits. Cannot be changed during a raid.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 10 })); - MaxBotsInterchange = Config.Bind("Performance | Max Bots", "Max Bots Interchange", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Interchange. Useful if you have a weaker PC. Set to 0 to use vanilla limits.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 8 })); + MaxBotsInterchange = Config.Bind("Performance | Max Bots", "Max Bots Interchange", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Interchange. Useful if you have a weaker PC. Set to 0 to use vanilla limits. Cannot be changed during a raid.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 8 })); - MaxBotsReserve = Config.Bind("Performance | Max Bots", "Max Bots Reserve", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Reserve. Useful if you have a weaker PC. Set to 0 to use vanilla limits.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 7 })); + MaxBotsReserve = Config.Bind("Performance | Max Bots", "Max Bots Reserve", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Reserve. Useful if you have a weaker PC. Set to 0 to use vanilla limits. Cannot be changed during a raid.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 7 })); - MaxBotsWoods = Config.Bind("Performance | Max Bots", "Max Bots Woods", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Woods. Useful if you have a weaker PC. Set to 0 to use vanilla limits.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 6 })); + MaxBotsWoods = Config.Bind("Performance | Max Bots", "Max Bots Woods", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Woods. Useful if you have a weaker PC. Set to 0 to use vanilla limits. Cannot be changed during a raid.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 6 })); - MaxBotsShoreline = Config.Bind("Performance | Max Bots", "Max Bots Shoreline", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Shoreline. Useful if you have a weaker PC. Set to 0 to use vanilla limits.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 5 })); + MaxBotsShoreline = Config.Bind("Performance | Max Bots", "Max Bots Shoreline", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Shoreline. Useful if you have a weaker PC. Set to 0 to use vanilla limits. Cannot be changed during a raid.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 5 })); - MaxBotsStreets = Config.Bind("Performance | Max Bots", "Max Bots Streets", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Streets of Tarkov. Useful if you have a weaker PC. Set to 0 to use vanilla limits.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 4 })); + MaxBotsStreets = Config.Bind("Performance | Max Bots", "Max Bots Streets", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Streets of Tarkov. Useful if you have a weaker PC. Set to 0 to use vanilla limits. Cannot be changed during a raid.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 4 })); - MaxBotsGroundZero = Config.Bind("Performance | Max Bots", "Max Bots Ground Zero", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Ground Zero. Useful if you have a weaker PC. Set to 0 to use vanilla limits.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 3 })); + MaxBotsGroundZero = Config.Bind("Performance | Max Bots", "Max Bots Ground Zero", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Ground Zero. Useful if you have a weaker PC. Set to 0 to use vanilla limits. Cannot be changed during a raid.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 3 })); - MaxBotsLabs = Config.Bind("Performance | Max Bots", "Max Bots Labs", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Labs. Useful if you have a weaker PC. Set to 0 to use vanilla limits.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 2 })); + MaxBotsLabs = Config.Bind("Performance | Max Bots", "Max Bots Labs", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Labs. Useful if you have a weaker PC. Set to 0 to use vanilla limits. Cannot be changed during a raid.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 2 })); - MaxBotsLighthouse = Config.Bind("Performance | Max Bots", "Max Bots Lighthouse", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Lighthouse. Useful if you have a weaker PC. Set to 0 to use vanilla limits.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 1 })); + MaxBotsLighthouse = Config.Bind("Performance | Max Bots", "Max Bots Lighthouse", 0, new ConfigDescription("Max amount of bots that can be active at the same time on Lighthouse. Useful if you have a weaker PC. Set to 0 to use vanilla limits. Cannot be changed during a raid.", new AcceptableValueRange(0, 50), new ConfigurationManagerAttributes() { Order = 1 })); // Network @@ -449,6 +451,7 @@ private void DisableSPTPatches() new AmmoUsedCounterPatch().Disable(); new ArmorDamageCounterPatch().Disable(); new DogtagPatch().Disable(); + new OfflineSaveProfilePatch().Disable(); // We handle this with our own exit manager new BTRInteractionPatch().Disable(); new BTRExtractPassengersPatch().Disable(); diff --git a/Fika.Core/Models/ClientConfigModel.cs b/Fika.Core/Models/ClientConfigModel.cs index bcabfec6..bdaa2e37 100644 --- a/Fika.Core/Models/ClientConfigModel.cs +++ b/Fika.Core/Models/ClientConfigModel.cs @@ -21,13 +21,17 @@ public struct ClientConfigModel [DataMember(Name = "allowItemSending")] public bool AllowItemSending; - public ClientConfigModel(bool useBTR, bool friendlyFire, bool dynamicVExfils, bool allowFreeCam, bool allowItemSending) + [DataMember(Name = "forceSaveOnDeath")] + public bool ForceSaveOnDeath; + + public ClientConfigModel(bool useBTR, bool friendlyFire, bool dynamicVExfils, bool allowFreeCam, bool allowItemSending, bool forceSaveOnDeath) { UseBTR = useBTR; FriendlyFire = friendlyFire; DynamicVExfils = dynamicVExfils; AllowFreeCam = allowFreeCam; AllowItemSending = allowItemSending; + ForceSaveOnDeath = forceSaveOnDeath; } public new void ToString() diff --git a/Fika.Core/Networking/FikaClient.cs b/Fika.Core/Networking/FikaClient.cs index d27e79b5..dce47735 100644 --- a/Fika.Core/Networking/FikaClient.cs +++ b/Fika.Core/Networking/FikaClient.cs @@ -80,7 +80,6 @@ protected void Start() packetProcessor.SubscribeNetSerializable(OnAssignNetIdPacketReceived); packetProcessor.SubscribeNetSerializable(OnSyncNetIdPacketReceived); packetProcessor.SubscribeNetSerializable(OnOperationCallbackPacketReceived); - packetProcessor.SubscribeNetSerializable(OnSessionSettingsPacketReceived); _netClient = new NetManager(this) { @@ -115,18 +114,6 @@ protected void Start() ClientReady = true; } - private void OnSessionSettingsPacketReceived(SessionSettingsPacket packet) - { - if (!packet.IsRequest) - { - if (packet.MetabolismDisabled) - { - Singleton.Instance.MainPlayer.HealthController.DisableMetabolism(); - NotificationManagerClass.DisplayMessageNotification("Metabolism disabled", iconType: EFT.Communications.ENotificationIconType.Alert); - } - } - } - private void OnOperationCallbackPacketReceived(OperationCallbackPacket packet) { if (Players.TryGetValue(packet.NetId, out CoopPlayer player) && player.IsYourPlayer) @@ -258,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) @@ -436,13 +426,20 @@ 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: { if (CoopHandler.Players.TryGetValue(packet.BotNetId, out CoopPlayer botToDispose)) { + if (!botToDispose.gameObject.activeSelf) + { + botToDispose.gameObject.SetActive(true); + } if (CoopHandler.Players.Remove(packet.BotNetId)) { @@ -512,7 +509,7 @@ private void OnHealthSyncPacketReceived(HealthSyncPacket packet) { if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { - playerToApply?.PacketReceiver?.HealthSyncPackets?.Enqueue(packet); + playerToApply.PacketReceiver?.HealthSyncPackets?.Enqueue(packet); } } @@ -606,7 +603,7 @@ private void OnCommonPlayerPacketReceived(CommonPlayerPacket packet) { if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { - playerToApply?.PacketReceiver?.CommonPlayerPackets?.Enqueue(packet); + playerToApply.PacketReceiver?.CommonPlayerPackets?.Enqueue(packet); } } @@ -614,7 +611,7 @@ private void OnInventoryPacketReceived(InventoryPacket packet) { if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { - playerToApply?.PacketReceiver?.InventoryPackets?.Enqueue(packet); + playerToApply.PacketReceiver?.InventoryPackets?.Enqueue(packet); } } @@ -622,7 +619,7 @@ private void OnDamagePacketReceived(DamagePacket packet) { if (Players.TryGetValue(packet.NetId, out CoopPlayer playerToApply)) { - playerToApply?.PacketReceiver?.DamagePackets?.Enqueue(packet); + playerToApply.PacketReceiver?.DamagePackets?.Enqueue(packet); } } @@ -630,7 +627,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 b6a25dd2..68da25bc 100644 --- a/Fika.Core/Networking/FikaServer.cs +++ b/Fika.Core/Networking/FikaServer.cs @@ -83,7 +83,6 @@ public async void Start() packetProcessor.SubscribeNetSerializable(OnMinePacketReceived); packetProcessor.SubscribeNetSerializable(OnBorderZonePacketReceived); packetProcessor.SubscribeNetSerializable(OnSendCharacterPacketReceived); - packetProcessor.SubscribeNetSerializable(OnSessionSettingsPacketReceived); _netServer = new NetManager(this) { @@ -165,23 +164,6 @@ await Task.Run(async () => ServerReady = true; } - private void OnSessionSettingsPacketReceived(SessionSettingsPacket packet, NetPeer peer) - { - if (packet.IsRequest) - { - CoopGame coopGame = (CoopGame)Singleton.Instance; - if (coopGame != null) - { - SessionSettingsPacket returnPacket = new(false) - { - MetabolismDisabled = coopGame.RaidSettings.MetabolismDisabled - }; - - SendDataToPeer(peer, new(), ref returnPacket, DeliveryMethod.ReliableUnordered); - } - } - } - public int PopNetId() { int netId = _currentNetId; @@ -247,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) @@ -407,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(); @@ -433,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) @@ -487,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(); @@ -589,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(); @@ -600,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(); diff --git a/Fika.Core/Networking/Http/FikaHttpHandler.cs b/Fika.Core/Networking/Http/FikaHttpHandler.cs index 232b7db0..28abbce5 100644 --- a/Fika.Core/Networking/Http/FikaHttpHandler.cs +++ b/Fika.Core/Networking/Http/FikaHttpHandler.cs @@ -135,5 +135,10 @@ public static Dictionary AvailableReceivers(AvailableReceiversRe { return PostJson>("/fika/senditem/availablereceivers", data); } + + public static async Task GetRaidSettings(RaidSettingsRequest data) + { + return await PostJsonAsync("/fika/raid/getsettings", data); + } } } \ No newline at end of file diff --git a/Fika.Core/Networking/Models/RaidSettingsRequest.cs b/Fika.Core/Networking/Models/RaidSettingsRequest.cs new file mode 100644 index 00000000..b6df6a28 --- /dev/null +++ b/Fika.Core/Networking/Models/RaidSettingsRequest.cs @@ -0,0 +1,17 @@ +using Fika.Core.Coop.Components; +using System.Runtime.Serialization; + +namespace Fika.Core.Networking.Http.Models +{ + [DataContract] + public struct RaidSettingsRequest + { + [DataMember(Name = "serverId")] + public string ServerId; + + public RaidSettingsRequest() + { + ServerId = CoopHandler.GetServerId(); + } + } +} \ No newline at end of file diff --git a/Fika.Core/Networking/Models/RaidSettingsResponse.cs b/Fika.Core/Networking/Models/RaidSettingsResponse.cs new file mode 100644 index 00000000..bb627ba5 --- /dev/null +++ b/Fika.Core/Networking/Models/RaidSettingsResponse.cs @@ -0,0 +1,13 @@ +using System.Runtime.Serialization; + +namespace Fika.Core.Networking.Http.Models +{ + [DataContract] + public struct RaidSettingsResponse(bool metabolismDisabled, string playersSpawnPlace) + { + [DataMember(Name = "metabolismDisabled")] + public bool MetabolismDisabled = metabolismDisabled; + [DataMember(Name = "playersSpawnPlace")] + public string PlayersSpawnPlace = playersSpawnPlace; + } +} \ No newline at end of file diff --git a/Fika.Core/Networking/Packets/Backend/SessionSettingsPacket.cs b/Fika.Core/Networking/Packets/Backend/SessionSettingsPacket.cs deleted file mode 100644 index d71661c5..00000000 --- a/Fika.Core/Networking/Packets/Backend/SessionSettingsPacket.cs +++ /dev/null @@ -1,28 +0,0 @@ -using LiteNetLib.Utils; - -namespace Fika.Core.Networking -{ - public struct SessionSettingsPacket(bool isRequest) : INetSerializable - { - public bool IsRequest = isRequest; - public bool MetabolismDisabled; - - public void Deserialize(NetDataReader reader) - { - IsRequest = reader.GetBool(); - if (!IsRequest) - { - MetabolismDisabled = reader.GetBool(); - } - } - - public void Serialize(NetDataWriter writer) - { - writer.Put(IsRequest); - if (!IsRequest) - { - writer.Put(MetabolismDisabled); - } - } - } -} diff --git a/Fika.Core/Networking/Packets/FirearmController/WeaponPacket.cs b/Fika.Core/Networking/Packets/FirearmController/WeaponPacket.cs index ede93653..7a841088 100644 --- a/Fika.Core/Networking/Packets/FirearmController/WeaponPacket.cs +++ b/Fika.Core/Networking/Packets/FirearmController/WeaponPacket.cs @@ -54,6 +54,8 @@ public struct WeaponPacket(int netId) : INetSerializable public bool ReloadBoltAction = false; public bool HasRollCylinder = false; public bool RollToZeroCamora = false; + public bool UnderbarrelSightingRangeUp = false; + public bool UnderbarrelSightingRangeDown = false; public void Deserialize(NetDataReader reader) { @@ -123,6 +125,8 @@ public void Deserialize(NetDataReader reader) HasRollCylinder = reader.GetBool(); if (HasRollCylinder) RollToZeroCamora = reader.GetBool(); + UnderbarrelSightingRangeUp = reader.GetBool(); + UnderbarrelSightingRangeDown = reader.GetBool(); } public void Serialize(NetDataWriter writer) @@ -189,6 +193,8 @@ public void Serialize(NetDataWriter writer) writer.Put(HasRollCylinder); if (HasRollCylinder) writer.Put(RollToZeroCamora); + writer.Put(UnderbarrelSightingRangeUp); + writer.Put(UnderbarrelSightingRangeDown); } } } diff --git a/Fika.Core/UI/Custom/MatchMakerUIScript.cs b/Fika.Core/UI/Custom/MatchMakerUIScript.cs index 67e837d9..18697328 100644 --- a/Fika.Core/UI/Custom/MatchMakerUIScript.cs +++ b/Fika.Core/UI/Custom/MatchMakerUIScript.cs @@ -34,14 +34,14 @@ internal class MatchMakerUIScript : MonoBehaviour private float _lastRefreshed; - private void Start() + protected void Start() { CreateMatchMakerUI(); StartCoroutine(ServerQuery()); } - void Update() + protected void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { @@ -64,7 +64,7 @@ private void DestroyThis() Destroy(this); } - private void OnDestroy() + protected void OnDestroy() { StopQuery = true; if (NewBackButton != null) @@ -232,7 +232,7 @@ private IEnumerator JoinMatch(string profileId, string serverId, Button button) pingingClient.NetClient?.Stop(); pingingClient = null; - if (MatchmakerAcceptPatches.JoinMatch(RaidSettings, profileId, serverId, out CreateMatch result, out string errorMessage)) + if (MatchmakerAcceptPatches.JoinMatch(profileId, serverId, out CreateMatch result, out string errorMessage)) { MatchmakerAcceptPatches.SetGroupId(result.ServerId); MatchmakerAcceptPatches.SetTimestamp(result.Timestamp); diff --git a/Fika.Core/UI/FikaUIUtils.cs b/Fika.Core/UI/FikaUIUtils.cs index 957870d9..bbb6c72e 100644 --- a/Fika.Core/UI/FikaUIUtils.cs +++ b/Fika.Core/UI/FikaUIUtils.cs @@ -1,12 +1,17 @@ // © 2024 Lacyway All Rights Reserved +using Diz.Utils; +using EFT.InputSystem; using EFT.UI; +using HarmonyLib; +using System; +using System.Reflection; using TMPro; using UnityEngine; namespace Fika.Core.UI { - internal class FikaUIUtils + internal static class FikaUIUtils { public static TextMeshProUGUI CreateOverlayText(string overlayText) { @@ -15,13 +20,13 @@ public static TextMeshProUGUI CreateOverlayText(string overlayText) if (labelObj != null) { - Object.Destroy(labelObj); + UnityEngine.Object.Destroy(labelObj); } ClientWatermark watermarkText = obj.GetComponent(); if (watermarkText != null) { - Object.Destroy(watermarkText); + UnityEngine.Object.Destroy(watermarkText); } obj.active = true; @@ -33,5 +38,96 @@ public static TextMeshProUGUI CreateOverlayText(string overlayText) return text; } + + public static GClass3085 ShowFikaMessage(this PreloaderUI preloaderUI, string header, string message, + ErrorScreen.EButtonType buttonType, float waitingTime, Action acceptCallback, Action endTimeCallback) + { + Traverse preloaderUiTraverse = Traverse.Create(preloaderUI); + + PreloaderUI.Class2561 messageHandler = new() + { + preloaderUI_0 = preloaderUI, + acceptCallback = acceptCallback, + endTimeCallback = endTimeCallback + }; + + if (!AsyncWorker.CheckIsMainThread()) + { + FikaPlugin.Instance.FikaLogger.LogError("You are trying to show error screen from non-main thread!"); + return new GClass3085(); + } + + ErrorScreen errorScreenTemplate = preloaderUiTraverse.Field("_criticalErrorScreenTemplate").GetValue(); + EmptyInputNode errorScreenContainer = preloaderUiTraverse.Field("_criticalErrorScreenContainer").GetValue(); + + messageHandler.errorScreen = UnityEngine.Object.Instantiate(errorScreenTemplate, errorScreenContainer.transform, false); + errorScreenContainer.AddChildNode(messageHandler.errorScreen); + return messageHandler.errorScreen.ShowFikaMessage(header, message, new Action(messageHandler.method_1), waitingTime, new Action(messageHandler.method_2), buttonType, true); + } + + public static GClass3087 ShowFikaMessage(this ErrorScreen errorScreen, string title, string message, + Action closeManuallyCallback = null, float waitingTime = 0f, Action timeOutCallback = null, + ErrorScreen.EButtonType buttonType = ErrorScreen.EButtonType.OkButton, bool removeHtml = true) + { + Traverse errorScreenTraverse = Traverse.Create(errorScreen); + + ErrorScreen.Class2352 errorScreenHandler = new() + { + errorScreen_0 = errorScreen + }; + if (!MonoBehaviourSingleton.Instance.CanShowErrorScreen) + { + return new GClass3087(); + } + if (removeHtml) + { + message = ErrorScreen.smethod_0(message); + } + ItemUiContext.Instance.CloseAllWindows(); + + Action action_1 = timeOutCallback ?? closeManuallyCallback; + errorScreenTraverse.Field("action_1").SetValue(action_1); + MethodBase baseShow = typeof(ErrorScreen).BaseType.GetMethod("Show"); + + errorScreenHandler.context = (GClass3087)baseShow.Invoke(errorScreen, [closeManuallyCallback]); + errorScreenHandler.context.OnAccept += errorScreen.method_3; + errorScreenHandler.context.OnDecline += errorScreen.method_4; + errorScreenHandler.context.OnCloseSilent += errorScreen.method_4; + + GClass767 ui = Traverse.Create(errorScreen).Field("UI").GetValue(); + + ui.AddDisposable(new Action(errorScreenHandler.method_0)); + string text = buttonType switch + { + ErrorScreen.EButtonType.OkButton => "I UNDERSTAND", + ErrorScreen.EButtonType.CancelButton => "CANCEL", + ErrorScreen.EButtonType.QuitButton => "I DECLINE", + _ => throw new ArgumentOutOfRangeException() + }; + + DefaultUIButton exitButton = errorScreenTraverse.Field("_exitButton").GetValue(); + + exitButton.SetHeaderText(text, exitButton.HeaderSize); + errorScreen.RectTransform.anchoredPosition = Vector2.zero; + + errorScreen.Caption.SetText(string.IsNullOrEmpty(title) ? "ERROR" : title); + + string string_1 = message.SubstringIfNecessary(500); + errorScreenTraverse.Field("string_1").SetValue(string_1); + + TextMeshProUGUI errorDescription = Traverse.Create(errorScreen).Field("_errorDescription").GetValue(); + errorDescription.text = string_1; + + Coroutine coroutine_0 = errorScreenTraverse.Field("coroutine_0").GetValue(); + if (coroutine_0 != null) + { + errorScreen.StopCoroutine(coroutine_0); + } + if (waitingTime > 0f) + { + errorScreenTraverse.Field("coroutine_0").SetValue(errorScreen.StartCoroutine(errorScreen.method_2(GClass1296.Now.AddSeconds((double)waitingTime)))); + } + return errorScreenHandler.context; + } } } diff --git a/Fika.Core/UI/Patches/ItemContext_Patch.cs b/Fika.Core/UI/Patches/ItemContext_Patch.cs index 2af2a52d..e0aff788 100644 --- a/Fika.Core/UI/Patches/ItemContext_Patch.cs +++ b/Fika.Core/UI/Patches/ItemContext_Patch.cs @@ -40,6 +40,14 @@ private static void Prefix(ItemInfoInteractionsAbstractClass co return; } + // Save as variable in case we need to add more checks later... + MenuUI menuUI = Singleton.Instance; + + if (menuUI.HideoutAreaTransferItemsScreen.isActiveAndEnabled) + { + return; + } + IEnumerable parentItems = item.GetAllParentItems(); if (parentItems.Any(x => x is EquipmentClass)) { diff --git a/Fika.Core/UI/Patches/TOS_Patch.cs b/Fika.Core/UI/Patches/TOS_Patch.cs index d387aac3..ad221cb2 100644 --- a/Fika.Core/UI/Patches/TOS_Patch.cs +++ b/Fika.Core/UI/Patches/TOS_Patch.cs @@ -32,18 +32,22 @@ public static void PostFix() { byte[] str_1_b = Convert.FromBase64String(str_1); string str_1_d = Encoding.UTF8.GetString(str_1_b); - Singleton.Instance.ShowCriticalErrorScreen("Fika", str_1_d, ErrorScreen.EButtonType.QuitButton, 30f, - Application.Quit, - () => { FikaPlugin.AcceptedTOS.Value = true; }); + Singleton.Instance.ShowFikaMessage("FIKA", str_1_d, ErrorScreen.EButtonType.QuitButton, 30f, + Application.Quit, AcceptTos); } else { byte[] str_2_b = Convert.FromBase64String(str_2); string str_2_d = Encoding.UTF8.GetString(str_2_b); - Singleton.Instance.ShowCriticalErrorScreen("Fika", str_2_d, ErrorScreen.EButtonType.OkButton, 0f, + Singleton.Instance.ShowFikaMessage("FIKA", str_2_d, ErrorScreen.EButtonType.OkButton, 0f, null, null); } } + + private static void AcceptTos() + { + FikaPlugin.AcceptedTOS.Value = true; + } } }