From 31b4bce7ed22b2bb05b5b6060f66b9eeaa1327e8 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Thu, 23 May 2024 09:14:06 +0200 Subject: [PATCH 1/4] Cleanup --- .../ClientClasses/CoopClientInventoryController.cs | 2 +- Fika.Core/Coop/Custom/FikaDynamicAI.cs | 3 +-- Fika.Core/Coop/Custom/FikaHealthBar.cs | 2 +- Fika.Core/Coop/GameMode/AFikaGame.cs | 12 ++++++------ Fika.Core/Coop/GameMode/CoopGame.cs | 6 +++--- .../TarkovApplication_LocalGameCreator_Patch.cs | 2 +- Fika.Core/Coop/Players/CoopBot.cs | 2 +- Fika.Core/Coop/Players/CoopPlayer.cs | 8 ++++---- Fika.Core/Coop/Players/ObservedCoopPlayer.cs | 6 +++--- Fika.Core/FikaPlugin.cs | 2 +- Fika.Core/Networking/FikaClient.cs | 4 ++-- Fika.Core/Networking/FikaServer.cs | 2 +- Fika.Core/UI/Custom/MatchMakerUIScript.cs | 2 +- 13 files changed, 26 insertions(+), 27 deletions(-) diff --git a/Fika.Core/Coop/ClientClasses/CoopClientInventoryController.cs b/Fika.Core/Coop/ClientClasses/CoopClientInventoryController.cs index e4eb6aa4..ae5d9882 100644 --- a/Fika.Core/Coop/ClientClasses/CoopClientInventoryController.cs +++ b/Fika.Core/Coop/ClientClasses/CoopClientInventoryController.cs @@ -54,7 +54,7 @@ public override void Execute(GClass2837 operation, [CanBeNull] Callback callback HostInventoryOperationManager operationManager = new(this, operation, callback); if (vmethod_0(operationManager.operation)) { - operationManager.operation.vmethod_0(operationManager.HandleResult); + operationManager.operation.vmethod_0(operationManager.HandleResult); InventoryPacket packet = new() { diff --git a/Fika.Core/Coop/Custom/FikaDynamicAI.cs b/Fika.Core/Coop/Custom/FikaDynamicAI.cs index 59081045..16d3af2e 100644 --- a/Fika.Core/Coop/Custom/FikaDynamicAI.cs +++ b/Fika.Core/Coop/Custom/FikaDynamicAI.cs @@ -5,7 +5,6 @@ using EFT; using Fika.Core.Coop.Components; using Fika.Core.Coop.Players; -using System; using System.Collections.Generic; using UnityEngine; @@ -123,7 +122,7 @@ private void DeactivateBot(CoopBot bot) if (!disabledBots.Contains(bot)) { - disabledBots.Add(bot); + disabledBots.Add(bot); } else { 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/GameMode/AFikaGame.cs b/Fika.Core/Coop/GameMode/AFikaGame.cs index 75ae3cb4..b1acc974 100644 --- a/Fika.Core/Coop/GameMode/AFikaGame.cs +++ b/Fika.Core/Coop/GameMode/AFikaGame.cs @@ -26,7 +26,7 @@ BotsController IBotGame.BotsController if (BotsController == null) { BotsController = (BotsController)GetType().GetFields().Where(x => x.FieldType == typeof(BotsController)).FirstOrDefault().GetValue(this); - } + } return BotsController; } } @@ -37,11 +37,11 @@ public BotsController PBotsController { get { - if (BotsController == null) - { - BotsController = (BotsController)GetType().GetFields().Where(x => x.FieldType == typeof(BotsController)).FirstOrDefault().GetValue(this); - } - return BotsController; + if (BotsController == null) + { + BotsController = (BotsController)GetType().GetFields().Where(x => x.FieldType == typeof(BotsController)).FirstOrDefault().GetValue(this); + } + return BotsController; } } diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 9cf75756..2cd42b87 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -1516,7 +1516,7 @@ public void Extract(CoopPlayer player, ExfiltrationPoint point) player.ActiveHealthController.DiedEvent -= MainPlayerDied; - if(FikaPlugin.Instance.ForceSaveOnDeath) + if (FikaPlugin.Instance.ForceSaveOnDeath) { SavePlayer(coopPlayer, MyExitStatus, null); } @@ -1548,7 +1548,7 @@ private IEnumerator ExtractRoutine(CoopPlayer player) if (player.ActiveHealthController.DamageCoeff != 0) { player.ActiveHealthController.SetDamageCoeff(0); - } + } } else { @@ -1593,7 +1593,7 @@ private void HealthController_DiedEvent(EDamageType obj) MyExitStatus = ExitStatus.Killed; MyExitLocation = null; - if(FikaPlugin.Instance.ForceSaveOnDeath) + if (FikaPlugin.Instance.ForceSaveOnDeath) { SavePlayer((CoopPlayer)gparam_0.Player, MyExitStatus, null); } diff --git a/Fika.Core/Coop/Patches/LocalGame/TarkovApplication_LocalGameCreator_Patch.cs b/Fika.Core/Coop/Patches/LocalGame/TarkovApplication_LocalGameCreator_Patch.cs index f39d1200..cd340717 100644 --- a/Fika.Core/Coop/Patches/LocalGame/TarkovApplication_LocalGameCreator_Patch.cs +++ b/Fika.Core/Coop/Patches/LocalGame/TarkovApplication_LocalGameCreator_Patch.cs @@ -8,8 +8,8 @@ using Fika.Core.Coop.Matchmaker; using Fika.Core.Modding; using Fika.Core.Modding.Events; -using Fika.Core.Networking.Http.Models; using Fika.Core.Networking.Http; +using Fika.Core.Networking.Http.Models; using System; using System.Linq; using System.Reflection; diff --git a/Fika.Core/Coop/Players/CoopBot.cs b/Fika.Core/Coop/Players/CoopBot.cs index 6b9dc07b..f414af6f 100644 --- a/Fika.Core/Coop/Players/CoopBot.cs +++ b/Fika.Core/Coop/Players/CoopBot.cs @@ -250,7 +250,7 @@ private IEnumerator DestroyNetworkedComponents() if (PacketSender != null) { - PacketSender.DestroyThis(); + PacketSender.DestroyThis(); } } diff --git a/Fika.Core/Coop/Players/CoopPlayer.cs b/Fika.Core/Coop/Players/CoopPlayer.cs index d2be9f3f..ce0c2ed4 100644 --- a/Fika.Core/Coop/Players/CoopPlayer.cs +++ b/Fika.Core/Coop/Players/CoopPlayer.cs @@ -173,7 +173,7 @@ public void ProcessInteractWithBTR(BTRInteractionPacket packet) { if (coopHandler.clientBTR != null) { - coopHandler.clientBTR.ClientInteraction(this, packet.InteractPacket); + coopHandler.clientBTR.ClientInteraction(this, packet.InteractPacket); } } } @@ -399,7 +399,7 @@ public override void SendHeadlightsPacket(bool isSilent) Amount = lightStates.Count(), LightStates = lightStates } - }); + }); } } @@ -551,7 +551,7 @@ private IEnumerator DestroyNetworkedComponents() if (PacketSender != null) { - PacketSender.DestroyThis(); + PacketSender.DestroyThis(); } } @@ -1363,7 +1363,7 @@ public override void Dispose() base.Dispose(); if (PacketSender != null) { - PacketSender.DestroyThis(); + PacketSender.DestroyThis(); } } diff --git a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs index ab3764e4..0df67055 100644 --- a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs +++ b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs @@ -605,7 +605,7 @@ public override void vmethod_3(EGesture gesture) InteractionRaycast(); if (InteractablePlayer != null) { - InteractablePlayer.ShowHelloNotification(Profile.Nickname); + InteractablePlayer.ShowHelloNotification(Profile.Nickname); } } base.vmethod_3(gesture); @@ -832,7 +832,7 @@ public override void SetInventory(EquipmentClass equipmentClass) PlayerBody.GClass1860 gclass2 = PlayerBody.SlotViews.AddOrReplace(equipmentSlot, gclass); if (gclass2 != null) { - gclass2.Dispose(); + gclass2.Dispose(); } } @@ -1174,7 +1174,7 @@ private void SetSoundRollOff() { if (NestedStepSoundSource != null) { - NestedStepSoundSource.SetRolloff(60f * ProtagonistHearing); + NestedStepSoundSource.SetRolloff(60f * ProtagonistHearing); } } diff --git a/Fika.Core/FikaPlugin.cs b/Fika.Core/FikaPlugin.cs index ca473c8a..a1345d6f 100644 --- a/Fika.Core/FikaPlugin.cs +++ b/Fika.Core/FikaPlugin.cs @@ -229,7 +229,7 @@ protected void Awake() new ItemContext_Patch().Enable(); } - if(ForceSaveOnDeath) + if (ForceSaveOnDeath) { new OfflineSaveProfilePatch().Disable(); //Disable this as we've moved it forward immediately after extraction or death } diff --git a/Fika.Core/Networking/FikaClient.cs b/Fika.Core/Networking/FikaClient.cs index 81d1c141..dce47735 100644 --- a/Fika.Core/Networking/FikaClient.cs +++ b/Fika.Core/Networking/FikaClient.cs @@ -247,7 +247,7 @@ private void OnBTRPacketReceived(BTRPacket packet) { if (CoopHandler.clientBTR != null) { - CoopHandler.clientBTR.btrPackets.Enqueue(packet); + CoopHandler.clientBTR.btrPackets.Enqueue(packet); } } @@ -428,7 +428,7 @@ private void OnGenericPacketReceived(GenericPacket packet) { if (CoopHandler.clientBTR) { - CoopHandler.clientBTR.DisplayNetworkNotification(packet.TraderServiceType); + CoopHandler.clientBTR.DisplayNetworkNotification(packet.TraderServiceType); } } break; diff --git a/Fika.Core/Networking/FikaServer.cs b/Fika.Core/Networking/FikaServer.cs index 20d0a820..68da25bc 100644 --- a/Fika.Core/Networking/FikaServer.cs +++ b/Fika.Core/Networking/FikaServer.cs @@ -231,7 +231,7 @@ private void OnBTRServicePacketReceived(BTRServicePacket packet, NetPeer peer) { if (CoopHandler.serverBTR != null) { - CoopHandler.serverBTR.NetworkBtrTraderServicePurchased(packet); + CoopHandler.serverBTR.NetworkBtrTraderServicePurchased(packet); } } diff --git a/Fika.Core/UI/Custom/MatchMakerUIScript.cs b/Fika.Core/UI/Custom/MatchMakerUIScript.cs index c0a6c4d8..18697328 100644 --- a/Fika.Core/UI/Custom/MatchMakerUIScript.cs +++ b/Fika.Core/UI/Custom/MatchMakerUIScript.cs @@ -237,7 +237,7 @@ private IEnumerator JoinMatch(string profileId, string serverId, Button button) MatchmakerAcceptPatches.SetGroupId(result.ServerId); MatchmakerAcceptPatches.SetTimestamp(result.Timestamp); MatchmakerAcceptPatches.MatchingType = EMatchmakerType.GroupPlayer; - MatchmakerAcceptPatches.HostExpectedNumberOfPlayers = result.ExpectedNumberOfPlayers; + MatchmakerAcceptPatches.HostExpectedNumberOfPlayers = result.ExpectedNumberOfPlayers; DestroyThis(); From 8ab45ce6b5ccddae21cd901716db1588a68a6760 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Thu, 23 May 2024 10:09:55 +0200 Subject: [PATCH 2/4] Use own saving methods to support new saveondeath --- Fika.Core/Coop/GameMode/CoopGame.cs | 73 +++++++++++++++++++++-------- Fika.Core/FikaPlugin.cs | 6 +-- 2 files changed, 55 insertions(+), 24 deletions(-) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 2cd42b87..212fac93 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -1516,11 +1516,6 @@ public void Extract(CoopPlayer player, ExfiltrationPoint point) player.ActiveHealthController.DiedEvent -= MainPlayerDied; - if (FikaPlugin.Instance.ForceSaveOnDeath) - { - SavePlayer(coopPlayer, MyExitStatus, null); - } - if (FikaPlugin.AutoExtract.Value) { if (MatchmakerAcceptPatches.IsClient) @@ -1595,7 +1590,7 @@ private void HealthController_DiedEvent(EDamageType obj) if (FikaPlugin.Instance.ForceSaveOnDeath) { - SavePlayer((CoopPlayer)gparam_0.Player, MyExitStatus, null); + SavePlayer((CoopPlayer)gparam_0.Player, MyExitStatus, null, true); } } @@ -1693,13 +1688,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(); @@ -1726,16 +1715,19 @@ public override void Stop(string profileId, ExitStatus exitStatus, string exitNa { EnvironmentManager.Instance.Stop(); } - MonoBehaviourSingleton.Instance.StartBlackScreenShow(1f, 1f, new Action(stopManager.method_0)); + MonoBehaviourSingleton.Instance.StartBlackScreenShow(1f, 1f, new Action(stopManager.HandleExit)); GClass549.Config.UseSpiritPlayer = false; } - private void SavePlayer(CoopPlayer player, ExitStatus exitStatus, string exitName) + private void SavePlayer(CoopPlayer player, ExitStatus exitStatus, string exitName, bool fromDeath) { - //Since we're bypassing saving on exiting, run this now. - player.Profile.EftStats.LastPlayerState = null; - player.StatisticsManager.EndStatisticsSession(exitStatus, base.PastTime); - player.CheckAndResetControllers(exitStatus, base.PastTime, base.Location_0.Id, exitName); + 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); @@ -1948,6 +1940,49 @@ public override void Dispose() base.Dispose(); } + 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 { public void ExitOverride() diff --git a/Fika.Core/FikaPlugin.cs b/Fika.Core/FikaPlugin.cs index a1345d6f..954b3ca5 100644 --- a/Fika.Core/FikaPlugin.cs +++ b/Fika.Core/FikaPlugin.cs @@ -229,11 +229,6 @@ protected void Awake() new ItemContext_Patch().Enable(); } - if (ForceSaveOnDeath) - { - new OfflineSaveProfilePatch().Disable(); //Disable this as we've moved it forward immediately after extraction or death - } - BotDifficulties = FikaRequestHandler.GetBotDifficulties(); ConsoleScreen.Processor.RegisterCommandGroup(); @@ -456,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(); From 634f1b70c87004ba3eab900719eb99208c6dd29e Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Thu, 23 May 2024 11:26:54 +0200 Subject: [PATCH 3/4] More checks to save --- Fika.Core/Coop/GameMode/CoopGame.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 212fac93..3343d109 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -73,6 +73,7 @@ internal sealed class CoopGame : BaseLocalGame, IBotGame, IFika 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; } @@ -1721,6 +1722,11 @@ public override void Stop(string profileId, ExitStatus exitStatus, string exitNa 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. @@ -1734,7 +1740,7 @@ private void SavePlayer(CoopPlayer player, ExitStatus exitStatus, string exitNam JsonConverter[] Converters = Traverse.Create(converterClass).Field("Converters").Value; - SaveProfileRequest SaveRequest = new SaveProfileRequest + SaveProfileRequest SaveRequest = new() { Exit = exitStatus.ToString().ToLowerInvariant(), Profile = player.Profile, @@ -1744,6 +1750,8 @@ private void SavePlayer(CoopPlayer player, ExitStatus exitStatus, string exitNam }; RequestHandler.PutJson("/raid/profile/save", SaveRequest.ToJson(Converters.AddItem(new NotesJsonConverter()).ToArray())); + + hasSaved = true; } private void StopFromError(string profileId, ExitStatus exitStatus) From e841bd02bdd869793f3f2db5afe19cca676122f8 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Thu, 23 May 2024 11:27:01 +0200 Subject: [PATCH 4/4] CameraController improvements --- .../Coop/FreeCamera/FreeCameraController.cs | 152 +++++++++++------- 1 file changed, 98 insertions(+), 54 deletions(-) diff --git a/Fika.Core/Coop/FreeCamera/FreeCameraController.cs b/Fika.Core/Coop/FreeCamera/FreeCameraController.cs index 8c7d2d9e..b5e8cca0 100644 --- a/Fika.Core/Coop/FreeCamera/FreeCameraController.cs +++ b/Fika.Core/Coop/FreeCamera/FreeCameraController.cs @@ -6,10 +6,13 @@ 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 System.Reflection; using TMPro; using UnityEngine; @@ -31,7 +34,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 +45,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,6 +83,26 @@ protected void Start() allCullingObjects = FindObjectsOfType(); previouslyActiveBakeGroups = []; + + _player.ActiveHealthController.DiedEvent += MainPlayer_DiedEvent; + + if (CoopHandler.TryGetCoopHandler(out CoopHandler cHandler)) + { + coopHandler = cHandler; + } + } + + private void MainPlayer_DiedEvent(EDamageType obj) + { + _player.ActiveHealthController.DiedEvent -= MainPlayer_DiedEvent; + + if (!deathFadeEnabled) + { + deathFade.EnableEffect(); + deathFadeEnabled = true; + } + + StartCoroutine(DeathRoutine()); } protected void Update() @@ -97,18 +120,7 @@ protected void Update() if (_player.PlayerHealthController == null) { return; - } - - if (!CoopHandler.TryGetCoopHandler(out CoopHandler coopHandler)) - { - return; - } - - CoopGame coopGame = (CoopGame)coopHandler.LocalGameInstance; - if (coopGame == null) - { - return; - } + } CoopHandler.EQuitState quitState = coopHandler.GetQuitState(); @@ -134,7 +146,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,64 +174,95 @@ protected void Update() _effectsCleared = true; } } + } - if (!_player.HealthController.IsAlive) + private IEnumerator DeathRoutine() + { + yield return new WaitForSeconds(5); + + 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; - } + yield break; + } + + if (cameraClassInstance.Camera != null) + { + cameraClassInstance.Camera.fieldOfView = Singleton.Instance.Game.Settings.FieldOfView; + } + + // Disable the DeathFade effect & Toggle the Camera + deathFade.DisableEffect(); + if (!_freeCamScript.IsActive) + { + ToggleCamera(); + ToggleUi(); + } + ShowExtractMessage(); - if (cameraClassInstance.EffectsController == null) + if (!_effectsCleared) + { + if (_player != null) { - return; + _player.Muffled = false; + _player.HeavyBreath = false; } - if (cameraClassInstance.Camera != null) + if (CameraClass.Exist) { - cameraClassInstance.Camera.fieldOfView = Singleton.Instance.Game.Settings.FieldOfView; + ClearEffects(); } + _effectsCleared = true; + } + } - // Disable the DeathFade effect & Toggle the Camera - deathFade.DisableEffect(); - ToggleCamera(); - ToggleUi(); - ShowExtractMessage(); + private void ClearEffects() + { + CameraClass cameraClass = CameraClass.Instance; + cameraClass.EffectsController.method_4(false); - if (!_effectsCleared) + 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) { - if (_player != null) + while (effectsManager.ActiveEffects.Count > 0) { - _player.Muffled = false; - _player.HeavyBreath = false; + IEffect effect = effectsManager.ActiveEffects[0]; + effectsManager.DeleteEffect(effect); } + } + effectsManagerList.Clear(); + } - if (CameraClass.Exist) - { - ClearEffects(); - } - _effectsCleared = true; + 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; } } - } - private void ClearEffects() - { - CameraClass cameraClass = CameraClass.Instance; - cameraClass.EffectsController.method_4(false); - cameraClass.EffectsController.enabled = false; Destroy(cameraClass.EffectsController); cameraClass.VisorEffect.Clear(); Destroy(cameraClass.VisorEffect); @@ -432,11 +476,11 @@ public void OnDestroy() // Destroy FreeCamScript before FreeCamController if exists Destroy(_freeCamScript); - Destroy(this); if (extractText != null) { Destroy(extractText); } + Destroy(this); } } }