From 31f590c90e495f07104cb73fb05609d8922b9d4a Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 9 Jul 2024 13:09:22 +0200 Subject: [PATCH 01/25] Don't show cancel button as scav --- Fika.Core/Coop/GameMode/CoopGame.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index f4c0b6fb..4eaa3efd 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -930,6 +930,11 @@ public override async Task vmethod_2(int playerId, Vector3 position /// private GameObject CreateCancelButton(LocalPlayer myPlayer, CoopPlayer coopPlayer, GameObject customButton) { + if (myPlayer.Side is EPlayerSide.Savage) + { + return null; + } + if (MenuUI.Instantiated) { MenuUI menuUI = MenuUI.Instance; From 015582bdb3d28bddb9ea2eb95e322773ce56d1d2 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 9 Jul 2024 13:53:03 +0200 Subject: [PATCH 02/25] Update 'IsSingleplayer' --- Fika.Core/Coop/Utils/FikaBackendUtils.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Fika.Core/Coop/Utils/FikaBackendUtils.cs b/Fika.Core/Coop/Utils/FikaBackendUtils.cs index 61cb69b8..42d181dc 100644 --- a/Fika.Core/Coop/Utils/FikaBackendUtils.cs +++ b/Fika.Core/Coop/Utils/FikaBackendUtils.cs @@ -1,5 +1,7 @@ -using EFT; +using Comfort.Common; +using EFT; using EFT.UI.Matchmaker; +using Fika.Core.Networking; using Fika.Core.Networking.Http; using Fika.Core.Networking.Http.Models; using System; @@ -22,7 +24,15 @@ public static class FikaBackendUtils public static EMatchmakerType MatchingType = EMatchmakerType.Single; public static bool IsServer => MatchingType == EMatchmakerType.GroupLeader; public static bool IsClient => MatchingType == EMatchmakerType.GroupPlayer; - public static bool IsSinglePlayer => MatchingType == EMatchmakerType.Single; + public static bool IsSinglePlayer + { + get + { + return Singleton.Instantiated + && Singleton.Instance.NetServer.ConnectedPeersCount == 0; + } + } + public static bool IsDedicated = false; public static PlayersRaidReadyPanel PlayersRaidReadyPanel; public static MatchMakerGroupPreview MatchMakerGroupPreview; public static int HostExpectedNumberOfPlayers = 1; From 8b0776e25939a2ef299b0da92ca4a257d2dd6537 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 9 Jul 2024 21:41:03 +0200 Subject: [PATCH 03/25] Disable chat by default --- Fika.Core/FikaPlugin.cs | 15 +++++++++------ Fika.Core/Networking/FikaClient.cs | 5 ++++- Fika.Core/Networking/FikaServer.cs | 5 ++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Fika.Core/FikaPlugin.cs b/Fika.Core/FikaPlugin.cs index aafb8e5c..1a3fee5d 100644 --- a/Fika.Core/FikaPlugin.cs +++ b/Fika.Core/FikaPlugin.cs @@ -102,6 +102,7 @@ public class FikaPlugin : BaseUnityPlugin public static ConfigEntry FasterInventoryScroll { get; set; } public static ConfigEntry FasterInventoryScrollSpeed { get; set; } public static ConfigEntry ExtractKey { get; set; } + public static ConfigEntry EnableChat { get; set; } public static ConfigEntry ChatKey { get; set; } // Coop | Name Plates @@ -302,17 +303,19 @@ private void SetupConfig() // Coop - ShowNotifications = Instance.Config.Bind("Coop", "Show Feed", true, new ConfigDescription("Enable custom notifications when a player dies, extracts, kills a boss, etc.", tags: new ConfigurationManagerAttributes() { Order = 6 })); + ShowNotifications = Instance.Config.Bind("Coop", "Show Feed", true, new ConfigDescription("Enable custom notifications when a player dies, extracts, kills a boss, etc.", tags: new ConfigurationManagerAttributes() { Order = 7 })); - AutoExtract = Config.Bind("Coop", "Auto Extract", false, new ConfigDescription("Automatically extracts after the extraction countdown. As a host, this will only work if there are no clients connected.", tags: new ConfigurationManagerAttributes() { Order = 5 })); + AutoExtract = Config.Bind("Coop", "Auto Extract", false, new ConfigDescription("Automatically extracts after the extraction countdown. As a host, this will only work if there are no clients connected.", tags: new ConfigurationManagerAttributes() { Order = 6 })); - ShowExtractMessage = Config.Bind("Coop", "Show Extract Message", true, new ConfigDescription("Whether to show the extract message after dying/extracting.", tags: new ConfigurationManagerAttributes() { Order = 4 })); + ShowExtractMessage = Config.Bind("Coop", "Show Extract Message", true, new ConfigDescription("Whether to show the extract message after dying/extracting.", tags: new ConfigurationManagerAttributes() { Order = 5 })); - FasterInventoryScroll = Config.Bind("Coop", "Faster Inventory Scroll", false, new ConfigDescription("Toggle to increase the inventory scroll speed", tags: new ConfigurationManagerAttributes() { Order = 3 })); + FasterInventoryScroll = Config.Bind("Coop", "Faster Inventory Scroll", false, new ConfigDescription("Toggle to increase the inventory scroll speed", tags: new ConfigurationManagerAttributes() { Order = 4 })); - FasterInventoryScrollSpeed = Config.Bind("Coop", "Faster Inventory Scroll Speed", 63, new ConfigDescription("The speed at which the inventory scrolls at. Default is 63.", new AcceptableValueRange(63, 500), new ConfigurationManagerAttributes() { Order = 2 })); + FasterInventoryScrollSpeed = Config.Bind("Coop", "Faster Inventory Scroll Speed", 63, new ConfigDescription("The speed at which the inventory scrolls at. Default is 63.", new AcceptableValueRange(63, 500), new ConfigurationManagerAttributes() { Order = 3 })); - ExtractKey = Config.Bind("Coop", "Extract Key", new KeyboardShortcut(KeyCode.F8), new ConfigDescription("The key used to extract from the raid.", tags: new ConfigurationManagerAttributes() { Order = 1 })); + ExtractKey = Config.Bind("Coop", "Extract Key", new KeyboardShortcut(KeyCode.F8), new ConfigDescription("The key used to extract from the raid.", tags: new ConfigurationManagerAttributes() { Order = 2 })); + + EnableChat = Config.Bind("Coop", "Enable Chat", false, new ConfigDescription("Toggle to enable chat in game. Cannot be change mid raid", tags: new ConfigurationManagerAttributes() { Order = 1 })); ChatKey = Config.Bind("Coop", "Chat Key", new KeyboardShortcut(KeyCode.RightControl), new ConfigDescription("The key used to open the chat window.", tags: new ConfigurationManagerAttributes() { Order = 0 })); diff --git a/Fika.Core/Networking/FikaClient.cs b/Fika.Core/Networking/FikaClient.cs index 8fb72c10..80cf4605 100644 --- a/Fika.Core/Networking/FikaClient.cs +++ b/Fika.Core/Networking/FikaClient.cs @@ -165,7 +165,10 @@ public void SetupGameVariables(CoopPlayer coopPlayer) { coopHandler = CoopHandler.CoopHandlerParent.GetComponent(); MyPlayer = coopPlayer; - fikaChat = gameObject.AddComponent(); + if (FikaPlugin.EnableChat.Value) + { + fikaChat = gameObject.AddComponent(); + } } private void OnOperationCallbackPacketReceived(OperationCallbackPacket packet) diff --git a/Fika.Core/Networking/FikaServer.cs b/Fika.Core/Networking/FikaServer.cs index 7a69e051..3fbc3efb 100644 --- a/Fika.Core/Networking/FikaServer.cs +++ b/Fika.Core/Networking/FikaServer.cs @@ -281,7 +281,10 @@ public void SetupGameVariables(CoopPlayer coopPlayer) { coopHandler = CoopHandler.CoopHandlerParent.GetComponent(); MyPlayer = coopPlayer; - fikaChat = gameObject.AddComponent(); + if (FikaPlugin.EnableChat.Value) + { + fikaChat = gameObject.AddComponent(); + } } private void OnSendCharacterPacketReceived(SendCharacterPacket packet, NetPeer peer) From 084846bfd1b4fc31c5424d4c24feb1509fb90b76 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 9 Jul 2024 22:16:30 +0200 Subject: [PATCH 04/25] Improve inertia classes --- .../ClientClasses/NoInertiaMovementContext.cs | 57 +++++++++++++++++++ .../Coop/ClientClasses/NoInertiaPhysical.cs | 3 + Fika.Core/Coop/Players/CoopPlayer.cs | 17 +++++- 3 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 Fika.Core/Coop/ClientClasses/NoInertiaMovementContext.cs diff --git a/Fika.Core/Coop/ClientClasses/NoInertiaMovementContext.cs b/Fika.Core/Coop/ClientClasses/NoInertiaMovementContext.cs new file mode 100644 index 00000000..0d39124d --- /dev/null +++ b/Fika.Core/Coop/ClientClasses/NoInertiaMovementContext.cs @@ -0,0 +1,57 @@ +using Comfort.Common; +using EFT; +using System; +using UnityEngine; + +namespace Fika.Core.Coop.ClientClasses +{ + /// + /// Used to simulate having near no inertia + /// + public class NoInertiaMovementContext : MovementContext + { + public new static NoInertiaMovementContext Create(Player player, Func animatorGetter, Func characterControllerGetter, LayerMask groundMask) + { + NoInertiaMovementContext movementContext = Create(player, animatorGetter, characterControllerGetter, groundMask); + return movementContext; + } + + public override void Init() + { + base.Init(); + TiltInertia = 0.22f; + WalkInertia = 0.005f; + SprintBrakeInertia = 0f; + } + + public override void WeightRelatedValuesUpdated() + { + if (_player.ProceduralWeaponAnimation != null) + { + _player.ProceduralWeaponAnimation.Overweight = _player.Physical.Overweight; + _player.ProceduralWeaponAnimation.UpdateSwayFactors(); + _player.ProceduralWeaponAnimation.UpdateSwaySettings(); + _player.ProceduralWeaponAnimation.WeaponFlipSpeed = InertiaSettings.WeaponFlipSpeed.Evaluate(_player.Physical.Inertia); + } + UpdateCovertEfficiency(_player.MovementContext.ClampedSpeed, true); + _player.UpdateStepSoundRolloff(); + _player.HealthController.FallSafeHeight = Mathf.Lerp(Singleton.Instance.Health.Falling.SafeHeight, Singleton.Instance.Stamina.SafeHeightOverweight, _player.Physical.Overweight); + PlayerAnimatorTransitionSpeed = TransitionSpeed; + if (PoseLevel > _player.Physical.MaxPoseLevel && CurrentState is MovementState movementState) + { + movementState.ChangePose(_player.Physical.MaxPoseLevel - PoseLevel); + } + if (_player.PoseMemo > _player.Physical.MaxPoseLevel) + { + _player.PoseMemo = _player.Physical.MaxPoseLevel; + } + float walkSpeedLimit = _player.Physical.WalkSpeedLimit; + RemoveStateSpeedLimit(Player.ESpeedLimit.Weight); + if (walkSpeedLimit < 1f) + { + AddStateSpeedLimit(walkSpeedLimit * MaxSpeed, Player.ESpeedLimit.Weight); + } + UpdateCharacterControllerSpeedLimit(); + } + } +} diff --git a/Fika.Core/Coop/ClientClasses/NoInertiaPhysical.cs b/Fika.Core/Coop/ClientClasses/NoInertiaPhysical.cs index 6b0d1792..41718af3 100644 --- a/Fika.Core/Coop/ClientClasses/NoInertiaPhysical.cs +++ b/Fika.Core/Coop/ClientClasses/NoInertiaPhysical.cs @@ -5,6 +5,9 @@ namespace Fika.Core.Coop.ClientClasses { + /// + /// Currently unused + /// public class NoInertiaPhysical : PlayerPhysicalClass { private CoopPlayer coopPlayer; diff --git a/Fika.Core/Coop/Players/CoopPlayer.cs b/Fika.Core/Coop/Players/CoopPlayer.cs index e1d2414c..9e2b1d6c 100644 --- a/Fika.Core/Coop/Players/CoopPlayer.cs +++ b/Fika.Core/Coop/Players/CoopPlayer.cs @@ -118,9 +118,24 @@ await player.Init(rotation, layerName, pointOfView, profile, inventoryController return player; } - public override BasePhysicalClass CreatePhysical() + /*public override BasePhysicalClass CreatePhysical() { return FikaPlugin.Instance.UseInertia ? new PlayerPhysicalClass() : new NoInertiaPhysical(); + }*/ + + public override void CreateMovementContext() + { + LayerMask movement_MASK = EFTHardSettings.Instance.MOVEMENT_MASK; + if (FikaPlugin.Instance.UseInertia) + { + MovementContext = MovementContext.Create(this, new Func(GetBodyAnimatorCommon), + new Func(GetCharacterControllerCommon), movement_MASK); + } + else + { + MovementContext = NoInertiaMovementContext.Create(this, new Func(GetBodyAnimatorCommon), + new Func(GetCharacterControllerCommon), movement_MASK); + } } public override void OnSkillLevelChanged(GClass1778 skill) From dd58015dd39fc3c56c85a6f3cbb255215172c087 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Wed, 10 Jul 2024 08:47:15 +0200 Subject: [PATCH 05/25] Cleanup LocalGamePatch --- ...arkovApplication_LocalGameCreator_Patch.cs | 23 +++++-------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/Fika.Core/Coop/Patches/LocalGame/TarkovApplication_LocalGameCreator_Patch.cs b/Fika.Core/Coop/Patches/LocalGame/TarkovApplication_LocalGameCreator_Patch.cs index 4756e10d..54b844a1 100644 --- a/Fika.Core/Coop/Patches/LocalGame/TarkovApplication_LocalGameCreator_Patch.cs +++ b/Fika.Core/Coop/Patches/LocalGame/TarkovApplication_LocalGameCreator_Patch.cs @@ -25,8 +25,6 @@ internal class TarkovApplication_LocalGameCreator_Patch : ModulePatch { protected override MethodBase GetTargetMethod() => typeof(TarkovApplication).GetMethod(nameof(TarkovApplication.method_47)); - static ISession CurrentSession { get; set; } - [PatchPrefix] public static bool Prefix(TarkovApplication __instance) { @@ -37,15 +35,6 @@ public static bool Prefix(TarkovApplication __instance) return true; } - ISession session = __instance.GetClientBackEndSession(); - if (session == null) - { - Logger.LogError("Session is NULL. Continuing as Single-player."); - return true; - } - - CurrentSession = session; - return false; } @@ -58,11 +47,6 @@ public static async Task Postfix(Task __result, TarkovApplication __instance, Ti return; } - if (CurrentSession == null) - { - return; - } - if (____raidSettings == null) { Logger.LogError("RaidSettings is Null"); @@ -92,7 +76,12 @@ public static async Task Postfix(Task __result, TarkovApplication __instance, Ti NetManagerUtils.StartPinger(); } - ISession session = CurrentSession; + ISession session = __instance.GetClientBackEndSession(); + + if (session == null) + { + throw new NullReferenceException("Backend session was null when initializing game!"); + } Profile profile = session.GetProfileBySide(____raidSettings.Side); From 70b8465d8cb75eb4d171f71ac0ecc40e60dcca6c Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Wed, 10 Jul 2024 09:49:36 +0200 Subject: [PATCH 06/25] Add SniperScav filter option to Dynamic AI --- Fika.Core/Coop/Custom/FikaDynamicAI.cs | 8 ++++++++ Fika.Core/FikaPlugin.cs | 17 ++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Fika.Core/Coop/Custom/FikaDynamicAI.cs b/Fika.Core/Coop/Custom/FikaDynamicAI.cs index 4eafb7a4..3a917ff1 100644 --- a/Fika.Core/Coop/Custom/FikaDynamicAI.cs +++ b/Fika.Core/Coop/Custom/FikaDynamicAI.cs @@ -77,6 +77,14 @@ private void Spawner_OnBotCreated(BotOwner botOwner) return; } + if (FikaPlugin.DynamicAIIgnoreSnipers.Value) + { + if (botOwner.IsRole(WildSpawnType.marksman)) + { + return; + } + } + bots.Add((CoopBot)botOwner.GetPlayer); } diff --git a/Fika.Core/FikaPlugin.cs b/Fika.Core/FikaPlugin.cs index 1a3fee5d..ba01ab60 100644 --- a/Fika.Core/FikaPlugin.cs +++ b/Fika.Core/FikaPlugin.cs @@ -99,8 +99,8 @@ public class FikaPlugin : BaseUnityPlugin public static ConfigEntry ShowNotifications { get; set; } public static ConfigEntry AutoExtract { get; set; } public static ConfigEntry ShowExtractMessage { get; set; } - public static ConfigEntry FasterInventoryScroll { get; set; } - public static ConfigEntry FasterInventoryScrollSpeed { get; set; } + //public static ConfigEntry FasterInventoryScroll { get; set; } + //public static ConfigEntry FasterInventoryScrollSpeed { get; set; } public static ConfigEntry ExtractKey { get; set; } public static ConfigEntry EnableChat { get; set; } public static ConfigEntry ChatKey { get; set; } @@ -143,6 +143,7 @@ public class FikaPlugin : BaseUnityPlugin public static ConfigEntry DynamicAI { get; set; } public static ConfigEntry DynamicAIRange { get; set; } public static ConfigEntry DynamicAIRate { get; set; } + public static ConfigEntry DynamicAIIgnoreSnipers { get; set; } //public static ConfigEntry CullPlayers { get; set; } //public static ConfigEntry CullingRange { get; set; } @@ -309,9 +310,9 @@ private void SetupConfig() ShowExtractMessage = Config.Bind("Coop", "Show Extract Message", true, new ConfigDescription("Whether to show the extract message after dying/extracting.", tags: new ConfigurationManagerAttributes() { Order = 5 })); - FasterInventoryScroll = Config.Bind("Coop", "Faster Inventory Scroll", false, new ConfigDescription("Toggle to increase the inventory scroll speed", tags: new ConfigurationManagerAttributes() { Order = 4 })); + //FasterInventoryScroll = Config.Bind("Coop", "Faster Inventory Scroll", false, new ConfigDescription("Toggle to increase the inventory scroll speed", tags: new ConfigurationManagerAttributes() { Order = 4 })); - FasterInventoryScrollSpeed = Config.Bind("Coop", "Faster Inventory Scroll Speed", 63, new ConfigDescription("The speed at which the inventory scrolls at. Default is 63.", new AcceptableValueRange(63, 500), new ConfigurationManagerAttributes() { Order = 3 })); + //FasterInventoryScrollSpeed = Config.Bind("Coop", "Faster Inventory Scroll Speed", 63, new ConfigDescription("The speed at which the inventory scrolls at. Default is 63.", new AcceptableValueRange(63, 500), new ConfigurationManagerAttributes() { Order = 3 })); ExtractKey = Config.Bind("Coop", "Extract Key", new KeyboardShortcut(KeyCode.F8), new ConfigDescription("The key used to extract from the raid.", tags: new ConfigurationManagerAttributes() { Order = 2 })); @@ -381,11 +382,13 @@ private void SetupConfig() // Performance - DynamicAI = Config.Bind("Performance", "Dynamic AI", false, new ConfigDescription("Use the dynamic AI system, disabling AI when they are outside of any player's range.", tags: new ConfigurationManagerAttributes() { Order = 5 })); + DynamicAI = Config.Bind("Performance", "Dynamic AI", false, new ConfigDescription("Use the dynamic AI system, disabling AI when they are outside of any player's range.", tags: new ConfigurationManagerAttributes() { Order = 3 })); - DynamicAIRange = Config.Bind("Performance", "Dynamic AI Range", 100f, new ConfigDescription("The range at which AI will be disabled dynamically.", new AcceptableValueRange(150f, 1000f), new ConfigurationManagerAttributes() { Order = 4 })); + DynamicAIRange = Config.Bind("Performance", "Dynamic AI Range", 100f, new ConfigDescription("The range at which AI will be disabled dynamically.", new AcceptableValueRange(150f, 1000f), new ConfigurationManagerAttributes() { Order = 2 })); - DynamicAIRate = Config.Bind("Performance", "Dynamic AI Rate", EDynamicAIRates.Medium, new ConfigDescription("How often DynamicAI should scan for the range from all players.", tags: new ConfigurationManagerAttributes() { Order = 3 })); + DynamicAIRate = Config.Bind("Performance", "Dynamic AI Rate", EDynamicAIRates.Medium, new ConfigDescription("How often DynamicAI should scan for the range from all players.", tags: new ConfigurationManagerAttributes() { Order = 1 })); + + DynamicAIIgnoreSnipers = Config.Bind("Performance", "Dynamic AI - Ignore Snipers", true, new ConfigDescription("Whether Dynamic AI should ignore sniper scavs.", tags: new ConfigurationManagerAttributes() { Order = 0 })); //CullPlayers = Config.Bind("Performance", "Culling System", true, new ConfigDescription("Whether to use the culling system or not. When players are outside of the culling range, their animations will be simplified. This can dramatically improve performance in certain scenarios.", tags: new ConfigurationManagerAttributes() { Order = 2 })); From 48c87e4e38fb3d30f4ccc2dccad26982b98b4ea4 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Wed, 10 Jul 2024 09:51:33 +0200 Subject: [PATCH 07/25] Remove FasterInventoryScroll option --- Fika.Core/FikaPlugin.cs | 2 +- Fika.Core/UI/Patches/InventoryScroll_Patch.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Fika.Core/FikaPlugin.cs b/Fika.Core/FikaPlugin.cs index ba01ab60..92729f0c 100644 --- a/Fika.Core/FikaPlugin.cs +++ b/Fika.Core/FikaPlugin.cs @@ -220,7 +220,7 @@ protected void Awake() new MatchmakerAcceptScreen_Show_Patch().Enable(); new Minefield_method_2_Patch().Enable(); new BotCacher_Patch().Enable(); - new InventoryScroll_Patch().Enable(); + //new InventoryScroll_Patch().Enable(); new AbstractGame_InRaid_Patch().Enable(); new DisconnectButton_Patch().Enable(); new ChangeGameModeButton_Patch().Enable(); diff --git a/Fika.Core/UI/Patches/InventoryScroll_Patch.cs b/Fika.Core/UI/Patches/InventoryScroll_Patch.cs index 2998303e..4e1e0ed1 100644 --- a/Fika.Core/UI/Patches/InventoryScroll_Patch.cs +++ b/Fika.Core/UI/Patches/InventoryScroll_Patch.cs @@ -1,4 +1,4 @@ -using EFT.UI; +/*using EFT.UI; using SPT.Reflection.Patching; using System.Reflection; using UnityEngine.UI; @@ -28,4 +28,4 @@ public static void Prefix(ScrollRect ____stashScroll) } } } -} +}*/ \ No newline at end of file From 773e6b683234436630cd72896c6f23ad65da0f04 Mon Sep 17 00:00:00 2001 From: hel0t Date: Thu, 20 Jun 2024 18:52:01 +1000 Subject: [PATCH 08/25] Force local raid even when grouping --- .../MatchmakerOfflineRaidScreen_Patch.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Fika.Core/UI/Patches/MatchmakerOfflineRaidScreen_Patch.cs diff --git a/Fika.Core/UI/Patches/MatchmakerOfflineRaidScreen_Patch.cs b/Fika.Core/UI/Patches/MatchmakerOfflineRaidScreen_Patch.cs new file mode 100644 index 00000000..4e7b50c3 --- /dev/null +++ b/Fika.Core/UI/Patches/MatchmakerOfflineRaidScreen_Patch.cs @@ -0,0 +1,32 @@ +using EFT.UI.Matchmaker; +using SPT.Reflection.Patching; +using System.Reflection; +using EFT; +using EFT.UI; + +namespace Fika.Core.UI.Patches +{ + public class MatchmakerOfflineRaidScreen_Patch : ModulePatch + { + protected override MethodBase GetTargetMethod() => typeof(MatchmakerOfflineRaidScreen).GetMethod("method_6"); + + [PatchPrefix] + private static bool PatchPrefix(MatchmakerOfflineRaidScreen __instance, RaidSettings ___raidSettings_0, UpdatableToggle ____offlineModeToggle, UiElementBlocker ____onlineBlocker) + { + // Force local + ___raidSettings_0.RaidMode = ERaidMode.Local; + + // Default checkbox to be ticked + ____offlineModeToggle.isOn = true; + + // Use default SPT message + ____onlineBlocker.SetBlock(true, "Raids in SPT are always Offline raids. Don't worry - your progress will be saved!"); + + // Skip method_5 since it updates raid settings + __instance.method_8(true); + + // Skip all of method_6, since we're avoiding its side effects + return false; + } + } +} \ No newline at end of file From 2784cb189a1f351f6fc075851940427542ed09ea Mon Sep 17 00:00:00 2001 From: hel0t Date: Thu, 20 Jun 2024 18:54:19 +1000 Subject: [PATCH 09/25] Add class & patch to contain matchmaking group info --- Fika.Core/Coop/Utils/FikaGroupUtils.cs | 6 ++++++ Fika.Core/UI/Patches/MenuScreen_Patch.cs | 26 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 Fika.Core/Coop/Utils/FikaGroupUtils.cs create mode 100644 Fika.Core/UI/Patches/MenuScreen_Patch.cs diff --git a/Fika.Core/Coop/Utils/FikaGroupUtils.cs b/Fika.Core/Coop/Utils/FikaGroupUtils.cs new file mode 100644 index 00000000..1e81083c --- /dev/null +++ b/Fika.Core/Coop/Utils/FikaGroupUtils.cs @@ -0,0 +1,6 @@ +namespace Fika.Core.Coop.Utils; + +public static class FikaGroupUtils +{ + public static MatchmakerPlayerControllerClass GroupController { get; set; } +} \ No newline at end of file diff --git a/Fika.Core/UI/Patches/MenuScreen_Patch.cs b/Fika.Core/UI/Patches/MenuScreen_Patch.cs new file mode 100644 index 00000000..0d35097b --- /dev/null +++ b/Fika.Core/UI/Patches/MenuScreen_Patch.cs @@ -0,0 +1,26 @@ +using Fika.Core.Coop.Utils; +using SPT.Reflection.Patching; +using System.Linq; +using System.Reflection; +using EFT.UI; + +namespace Fika.Core.UI.Patches +{ + public class MenuScreen_Patch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return typeof(MenuScreen).GetMethods(BindingFlags.Public | BindingFlags.Instance) + .First(x => x.Name == "Show" && x.GetParameters()[0].Name == "profile"); + } + + [PatchPrefix] + private static bool PreFix(MenuScreen __instance, MatchmakerPlayerControllerClass matchmaker) + { + // Get the group controller straight from the main screen setup + FikaGroupUtils.GroupController = matchmaker; + + return true; + } + } +} \ No newline at end of file From 82264891b24a6ae60ce6f1685bc1d93a3a9e24c5 Mon Sep 17 00:00:00 2001 From: hel0t Date: Thu, 20 Jun 2024 18:55:56 +1000 Subject: [PATCH 10/25] Forward all network game creations into local game & local game patches --- ...kovApplication_NetworkGameCreator_Patch.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Fika.Core/Coop/Patches/LocalGame/TarkovApplication_NetworkGameCreator_Patch.cs diff --git a/Fika.Core/Coop/Patches/LocalGame/TarkovApplication_NetworkGameCreator_Patch.cs b/Fika.Core/Coop/Patches/LocalGame/TarkovApplication_NetworkGameCreator_Patch.cs new file mode 100644 index 00000000..9dacc494 --- /dev/null +++ b/Fika.Core/Coop/Patches/LocalGame/TarkovApplication_NetworkGameCreator_Patch.cs @@ -0,0 +1,34 @@ +using EFT; +using SPT.Reflection.Patching; +using System.Reflection; +using System.Threading.Tasks; +using EFT.UI; +using HarmonyLib; +using SPT.Reflection.Utils; + +namespace Fika.Core.Coop.Patches.LocalGame +{ + internal class TarkovApplication_NetworkGameCreator_Patch : ModulePatch + { + protected override MethodBase GetTargetMethod() + { + return AccessTools.GetDeclaredMethods(typeof(TarkovApplication)).SingleCustom(m => + m.Name == nameof(TarkovApplication.method_39) && m.GetParameters().Length == 2); + } + + [PatchPrefix] + public static bool Prefix(TarkovApplication __instance, RaidSettings ____raidSettings, string groupId, EMatchingType type, ref Task __result) + { + // Assuming method_38 is now async and returns Task + __result = __instance.method_38(____raidSettings.TimeAndWeatherSettings); + + // Log and handle other necessary parts from method_39 + FikaPlugin.Instance.FikaLogger.LogDebug("Matching with group id: " + groupId); + if (MonoBehaviourSingleton.Instantiated) + MonoBehaviourSingleton.Instance.MenuTaskBar.PreparingRaid(); + + // Return false to skip the original method_39 + return false; + } + } +} \ No newline at end of file From 89ccf47d55ced8e1a4f0418052472f522472742c Mon Sep 17 00:00:00 2001 From: hel0t Date: Thu, 20 Jun 2024 18:58:57 +1000 Subject: [PATCH 11/25] Add group utils helpers --- Fika.Core/Coop/Utils/FikaGroupUtils.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Fika.Core/Coop/Utils/FikaGroupUtils.cs b/Fika.Core/Coop/Utils/FikaGroupUtils.cs index 1e81083c..a8c37db6 100644 --- a/Fika.Core/Coop/Utils/FikaGroupUtils.cs +++ b/Fika.Core/Coop/Utils/FikaGroupUtils.cs @@ -2,5 +2,19 @@ namespace Fika.Core.Coop.Utils; public static class FikaGroupUtils { - public static MatchmakerPlayerControllerClass GroupController { get; set; } + public static MatchmakerPlayerControllerClass GroupController { get; set; } + + public static bool InGroup => GroupController is { GroupPlayers.Count: >= 1 }; + public static int GroupSize => InGroup ? GroupController.GroupPlayers.Count : 1; + public static bool IsGroupLeader + { + get + { + if (GroupController?.Group == null) return true; + if (GroupController?.GroupPlayers == null) return true; + if (GroupController.GroupPlayers.Count <= 1) return true; + if (GroupController?.Group?.Owner?.Value?.Id == null) return true; + return GroupController.Group.Owner.Value.Id == FikaBackendUtils.Profile.ProfileId || GroupController.IsLeader; + } + } } \ No newline at end of file From 68d33be5c3d8d0768e4d8bd629c4f7f912790a57 Mon Sep 17 00:00:00 2001 From: hel0t Date: Thu, 20 Jun 2024 19:09:08 +1000 Subject: [PATCH 12/25] Add helper classes to contain useful functions for matching and grouping --- Fika.Core/Coop/Components/CoopHandler.cs | 2 +- Fika.Core/Coop/GameMode/CoopGame.cs | 6 +-- Fika.Core/Coop/Utils/FikaBackendUtils.cs | 32 ++++++------- Fika.Core/Coop/Utils/FikaGroupUtils.cs | 29 ++++++++++-- Fika.Core/Networking/Models/PingRequest.cs | 2 +- Fika.Core/UI/Custom/MatchMakerUIScript.cs | 47 ++++++++++--------- .../MatchmakerAcceptScreen_Show_Patch.cs | 10 ++-- 7 files changed, 76 insertions(+), 52 deletions(-) diff --git a/Fika.Core/Coop/Components/CoopHandler.cs b/Fika.Core/Coop/Components/CoopHandler.cs index 83061f09..d9580d6f 100644 --- a/Fika.Core/Coop/Components/CoopHandler.cs +++ b/Fika.Core/Coop/Components/CoopHandler.cs @@ -83,7 +83,7 @@ public static string GetServerId() CoopHandler coopGC = GetCoopHandler(); if (coopGC == null) { - return FikaBackendUtils.GetGroupId(); + return FikaBackendUtils.GetServerId(); } return coopGC.ServerId; diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 4eaa3efd..101f531c 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -268,9 +268,9 @@ public Task CreateCoopHandler() coopHandler = CoopHandler.CoopHandlerParent.AddComponent(); coopHandler.LocalGameInstance = this; - if (!string.IsNullOrEmpty(FikaBackendUtils.GetGroupId())) + if (!string.IsNullOrEmpty(FikaBackendUtils.GetServerId())) { - coopHandler.ServerId = FikaBackendUtils.GetGroupId(); + coopHandler.ServerId = FikaBackendUtils.GetServerId(); } else { @@ -885,7 +885,7 @@ public override async Task vmethod_2(int playerId, Vector3 position coopHandler.Players.Add(coopPlayer.NetId, coopPlayer); coopPlayer.SetupMainPlayer(); - PlayerSpawnRequest body = new(myPlayer.ProfileId, FikaBackendUtils.GetGroupId()); + PlayerSpawnRequest body = new(myPlayer.ProfileId, FikaBackendUtils.GetServerId()); await FikaRequestHandler.UpdatePlayerSpawn(body); myPlayer.SpawnPoint = spawnPoint; diff --git a/Fika.Core/Coop/Utils/FikaBackendUtils.cs b/Fika.Core/Coop/Utils/FikaBackendUtils.cs index 42d181dc..c0377d8e 100644 --- a/Fika.Core/Coop/Utils/FikaBackendUtils.cs +++ b/Fika.Core/Coop/Utils/FikaBackendUtils.cs @@ -6,24 +6,18 @@ using Fika.Core.Networking.Http.Models; using System; using System.Reflection; +using Fika.Core.UI.Custom; namespace Fika.Core.Coop.Utils { - public enum EMatchmakerType - { - Single = 0, - GroupPlayer = 1, - GroupLeader = 2 - } - public static class FikaBackendUtils { public static MatchMakerAcceptScreen MatchMakerAcceptScreenInstance; - public static Profile Profile; + public static IProfileDataContainer Profile; public static string PMCName; - public static EMatchmakerType MatchingType = EMatchmakerType.Single; - public static bool IsServer => MatchingType == EMatchmakerType.GroupLeader; - public static bool IsClient => MatchingType == EMatchmakerType.GroupPlayer; + public static EMatchingType MatchingType = EMatchingType.Single; + public static bool IsServer => Profile.ProfileId == serverId; + public static bool IsClient => MatchingType is EMatchingType.GroupPlayer or EMatchingType.GroupLeader; public static bool IsSinglePlayer { get @@ -41,19 +35,21 @@ public static bool IsSinglePlayer public static int RemotePort; public static int LocalPort = 0; public static bool IsHostNatPunch = false; - private static string groupId; + private static string serverId; private static string raidCode; public static MatchmakerTimeHasCome.TimeHasComeScreenClass ScreenController; + public static RaidSettings RaidSettings { get; set; } + public static MatchMakerUIScript MatchMakerUIScript; - public static string GetGroupId() + public static string GetServerId() { - return groupId; + return serverId; } - public static void SetGroupId(string newId) + public static void SetServerId(string newId) { - groupId = newId; + serverId = newId; } public static void SetRaidCode(string newCode) @@ -106,8 +102,8 @@ public static void CreateMatch(string profileId, string hostUsername, RaidSettin FikaRequestHandler.RaidCreate(body); - SetGroupId(profileId); - MatchingType = EMatchmakerType.GroupLeader; + SetServerId(profileId); + MatchingType = EMatchingType.GroupLeader; SetRaidCode(raidCode); } diff --git a/Fika.Core/Coop/Utils/FikaGroupUtils.cs b/Fika.Core/Coop/Utils/FikaGroupUtils.cs index a8c37db6..72193037 100644 --- a/Fika.Core/Coop/Utils/FikaGroupUtils.cs +++ b/Fika.Core/Coop/Utils/FikaGroupUtils.cs @@ -10,11 +10,32 @@ public static bool IsGroupLeader { get { - if (GroupController?.Group == null) return true; - if (GroupController?.GroupPlayers == null) return true; - if (GroupController.GroupPlayers.Count <= 1) return true; - if (GroupController?.Group?.Owner?.Value?.Id == null) return true; + if (GroupController?.Group == null) + { + return true; + } + + if (GroupController?.GroupPlayers == null) + { + return true; + } + + if (GroupController.GroupPlayers.Count <= 1) + { + return true; + } + + if (GroupController?.Group?.Owner?.Value?.Id == null) + { + return true; + } + return GroupController.Group.Owner.Value.Id == FikaBackendUtils.Profile.ProfileId || GroupController.IsLeader; } } + + public static void GroupJoinMatch(string profileId, string serverId) + { + FikaBackendUtils.MatchMakerUIScript.JoinMatchCoroutine(profileId, serverId); + } } \ No newline at end of file diff --git a/Fika.Core/Networking/Models/PingRequest.cs b/Fika.Core/Networking/Models/PingRequest.cs index 45add8ba..c502d86d 100644 --- a/Fika.Core/Networking/Models/PingRequest.cs +++ b/Fika.Core/Networking/Models/PingRequest.cs @@ -11,7 +11,7 @@ public struct PingRequest public PingRequest() { - ServerId = FikaBackendUtils.GetGroupId(); + ServerId = FikaBackendUtils.GetServerId(); } } } \ No newline at end of file diff --git a/Fika.Core/UI/Custom/MatchMakerUIScript.cs b/Fika.Core/UI/Custom/MatchMakerUIScript.cs index 6142daa7..6c32fb4b 100644 --- a/Fika.Core/UI/Custom/MatchMakerUIScript.cs +++ b/Fika.Core/UI/Custom/MatchMakerUIScript.cs @@ -18,10 +18,9 @@ namespace Fika.Core.UI.Custom { - internal class MatchMakerUIScript : MonoBehaviour + public class MatchMakerUIScript : MonoBehaviour { private MatchMakerUI fikaMatchMakerUi; - public RaidSettings RaidSettings { get; set; } private LobbyEntry[] Matches { get; set; } private List MatchesListObjects { get; set; } = []; private bool StopQuery = false; @@ -103,6 +102,7 @@ private void CreateMatchMakerUI() if (!fikaMatchMakerUi.PlayerAmountSelection.active) { fikaMatchMakerUi.PlayerAmountSelection.SetActive(true); + fikaMatchMakerUi.PlayerAmountText.text = FikaGroupUtils.GroupSize.ToString(); } else { @@ -158,7 +158,7 @@ private void CreateMatchMakerUI() } } FikaBackendUtils.HostExpectedNumberOfPlayers = int.Parse(fikaMatchMakerUi.PlayerAmountText.text); - FikaBackendUtils.CreateMatch(FikaBackendUtils.Profile.ProfileId, FikaBackendUtils.PMCName, RaidSettings); + FikaBackendUtils.CreateMatch(FikaBackendUtils.Profile.ProfileId, FikaBackendUtils.PMCName, FikaBackendUtils.RaidSettings); AcceptButton.OnClick.Invoke(); DestroyThis(); }); @@ -189,7 +189,7 @@ private void CreateMatchMakerUI() private void AutoRefresh() { - Matches = FikaRequestHandler.LocationRaids(RaidSettings); + Matches = FikaRequestHandler.LocationRaids(FikaBackendUtils.RaidSettings); _lastRefreshed = Time.time; @@ -199,15 +199,25 @@ private void AutoRefresh() private void ManualRefresh() { Singleton.Instance.PlayUISound(EUISoundType.ButtonClick); - Matches = FikaRequestHandler.LocationRaids(RaidSettings); + Matches = FikaRequestHandler.LocationRaids(FikaBackendUtils.RaidSettings); _lastRefreshed = Time.time; RefreshUI(); } - private IEnumerator JoinMatch(string profileId, string serverId, Button button) + public void JoinMatchCoroutine(string profileId, string serverId, Button button = null) { + StartCoroutine(JoinMatch(profileId, serverId, button)); + } + + private IEnumerator JoinMatch(string profileId, string serverId, Button button = null) + { + if (fikaMatchMakerUi.PlayerAmountSelection.active) + { + fikaMatchMakerUi.PlayerAmountSelection.SetActive(false); + } + if (button != null) { button.enabled = false; @@ -260,8 +270,8 @@ private IEnumerator JoinMatch(string profileId, string serverId, Button button) if (FikaBackendUtils.JoinMatch(profileId, serverId, out CreateMatch result, out string errorMessage)) { - FikaBackendUtils.SetGroupId(result.ServerId); - FikaBackendUtils.MatchingType = EMatchmakerType.GroupPlayer; + FikaBackendUtils.SetServerId(result.ServerId); + FikaBackendUtils.MatchingType = EMatchingType.GroupPlayer; FikaBackendUtils.HostExpectedNumberOfPlayers = result.ExpectedNumberOfPlayers; if (FikaBackendUtils.IsHostNatPunch) @@ -330,20 +340,15 @@ private void RefreshUI() Button button = joinButton.GetComponent