From 47d26831da6532b3e6cd8ca9a4342c03ef67fc3e Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:19:40 +0100 Subject: [PATCH 01/11] Rework game start --- Fika.Core/Coop/GameMode/CoopGame.cs | 161 ++++++++++-------- Fika.Core/Coop/Utils/FikaBackendUtils.cs | 9 +- Fika.Core/Networking/FikaClient.cs | 21 ++- Fika.Core/Networking/FikaServer.cs | 7 +- .../Packets/Backend/InformationPacket.cs | 20 +-- Fika.Core/UI/Custom/MatchMakerUIScript.cs | 4 +- 6 files changed, 119 insertions(+), 103 deletions(-) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 8ee13c34..1a7db391 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -65,6 +65,7 @@ public sealed class CoopGame : BaseLocalGame, IBotGame, IFik public bool HasReceivedLoot { get; set; } = false; public List ThrownGrenades; public bool WeatherReady; + public bool RaidStarted { get; set; } private readonly Dictionary botQueue = []; private Coroutine extractRoutine; @@ -578,9 +579,9 @@ public override IEnumerator vmethod_2() server.GameStartTime = startTime; sessionTime = GameTimer.SessionTime; - InformationPacket packet = new(false) + InformationPacket packet = new() { - NumberOfPlayers = server.NetServer.ConnectedPeersCount, + RaidStarted = RaidStarted, ReadyPlayers = server.ReadyClients, HostReady = true, GameTime = gameTime.Value, @@ -684,9 +685,9 @@ private async Task WaitForOtherPlayers() SetMatchmakerStatus(LocaleUtils.UI_WAIT_FOR_OTHER_PLAYERS.Localized(), (float)server.ReadyClients / expectedPlayers); } while (coopHandler.AmountOfHumans < expectedPlayers); - InformationPacket packet = new(false) + InformationPacket packet = new() { - NumberOfPlayers = server.NetServer.ConnectedPeersCount, + RaidStarted = RaidStarted, ReadyPlayers = server.ReadyClients }; @@ -712,9 +713,9 @@ private async Task WaitForOtherPlayers() DynamicAI.AddHumans(); } - InformationPacket finalPacket = new(false) + InformationPacket finalPacket = new() { - NumberOfPlayers = server.NetServer.ConnectedPeersCount, + RaidStarted = RaidStarted, ReadyPlayers = server.ReadyClients }; @@ -733,7 +734,7 @@ private async Task WaitForOtherPlayers() } while (coopHandler.AmountOfHumans < expectedPlayers); - InformationPacket packet = new(true) + InformationPacket packet = new() { ReadyPlayers = 1 }; @@ -928,6 +929,55 @@ public override async Task vmethod_3(GameWorld gameWorld, int playe return coopPlayer; } + /// + /// This creates a "custom" Back button so that we can back out if we get stuck + /// + /// + /// + /// + /// + private GameObject CreateStartButton() + { + if (MenuUI.Instantiated) + { + MenuUI menuUI = MenuUI.Instance; + DefaultUIButton backButton = Traverse.Create(menuUI.MatchmakerTimeHasCome).Field("_cancelButton").Value; + GameObject customButton = Instantiate(backButton.gameObject, backButton.gameObject.transform.parent); + customButton.gameObject.name = "FikaStartButton"; + //customButton.gameObject.transform.position = new(customButton.transform.position.x, customButton.transform.position.y - 20, customButton.transform.position.z); + customButton.gameObject.SetActive(true); + DefaultUIButton backButtonComponent = customButton.GetComponent(); + backButtonComponent.SetHeaderText("Start", 32); + backButtonComponent.SetEnabledTooltip("Starts the raid."); + UnityEngine.Events.UnityEvent newEvent = new(); + newEvent.AddListener(() => + { + if (isServer) + { + RaidStarted = true; + return; + } + + FikaClient fikaClient = Singleton.Instance; + if (fikaClient == null) + { + throw new NullReferenceException("CreateStartButton::FikaClient was null!"); + } + + InformationPacket packet = new() + { + RequestStart = true + }; + fikaClient.SendData(ref packet, DeliveryMethod.ReliableOrdered); + }); + Traverse.Create(backButtonComponent).Field("OnClick").SetValue(newEvent); + + return customButton; + } + + return null; + } + /// /// This creates a "custom" Back button so that we can back out if we get stuck /// @@ -1101,7 +1151,7 @@ public async Task InitPlayer(BotControllerSettings botsSettings, string backendU } } - await WaitForPlayersToConnect(); + await WaitForHostToStart(); LocationSettingsClass.Location location = localRaidSettings_0.selectedLocation; if (isServer) @@ -1163,7 +1213,7 @@ private async Task WaitForHostToLoad() { FikaClient client = Singleton.Instance; - InformationPacket packet = new(true); + InformationPacket packet = new(); do { SetMatchmakerStatus(LocaleUtils.UI_WAIT_FOR_HOST_INIT.Localized()); @@ -1338,88 +1388,50 @@ private async Task InitInteractables() /// - /// used to wait for all other players to join the game + /// used to wait for host to start the raid /// /// - private async Task WaitForPlayersToConnect() + private async Task WaitForHostToStart() { - Logger.LogInfo("Starting task to wait for other players."); - - SetMatchmakerStatus(LocaleUtils.UI_INIT_COOP_GAME.Localized()); - int numbersOfPlayersToWaitFor = 0; + Logger.LogInfo("Starting task to wait for host to start the raid."); - string localizedPlayer = LocaleUtils.UI_WAIT_FOR_PLAYER.Localized(); - string localizedPlayers = LocaleUtils.UI_WAIT_FOR_PLAYERS.Localized(); + SetMatchmakerStatus("Waiting for host to start the raid..."); + GameObject startButton = null; if (isServer) { + startButton = CreateStartButton() ?? throw new NullReferenceException("Start button could not be created!"); FikaServer server = Singleton.Instance; server.RaidInitialized = true; - do + while (!RaidStarted) { - numbersOfPlayersToWaitFor = FikaBackendUtils.HostExpectedNumberOfPlayers - (server.NetServer.ConnectedPeersCount + 1); - if (numbersOfPlayersToWaitFor > 0) - { - bool multiple = numbersOfPlayersToWaitFor > 1; - SetMatchmakerStatus(string.Format(multiple ? localizedPlayers : localizedPlayer, - numbersOfPlayersToWaitFor)); - } - else - { - SetMatchmakerStatus(LocaleUtils.UI_ALL_PLAYERS_JOINED.Localized()); - } await Task.Delay(100); - } while (numbersOfPlayersToWaitFor > 0); - } - else - { - FikaClient client = Singleton.Instance; - - while (client.NetClient == null) - { - await Task.Delay(500); } - int connectionAttempts = 0; - - while (client.ServerConnection == null && connectionAttempts < 5) + if (startButton != null) { - // Server retries 10 times with a 500ms interval, we give it 5 seconds to try - SetMatchmakerStatus(LocaleUtils.UI_WAITING_FOR_CONNECT.Localized()); - connectionAttempts++; - await Task.Delay(1000); - - if (client.ServerConnection == null && connectionAttempts == 5) - { - Singleton.Instance.ShowErrorScreen(LocaleUtils.UI_ERROR_CONNECTING.Localized(), - LocaleUtils.UI_ERROR_CONNECTING_TO_RAID.Localized()); - } - } - - while (client == null) - { - await Task.Delay(500); + Destroy(startButton); } + return; + } - InformationPacket packet = new(true); + if (FikaBackendUtils.IsDedicatedRequester) + { + startButton = CreateStartButton() ?? throw new NullReferenceException("Start button could not be created!"); + } + FikaClient client = Singleton.Instance; + InformationPacket packet = new(); + client.SendData(ref packet, DeliveryMethod.ReliableUnordered); + while (!RaidStarted) + { + await Task.Delay(100); client.SendData(ref packet, DeliveryMethod.ReliableUnordered); - do - { - numbersOfPlayersToWaitFor = FikaBackendUtils.HostExpectedNumberOfPlayers - (client.ConnectedClients + 1); - if (numbersOfPlayersToWaitFor > 0) - { - bool multiple = numbersOfPlayersToWaitFor > 1; - SetMatchmakerStatus(string.Format(multiple ? localizedPlayers : localizedPlayer, - numbersOfPlayersToWaitFor)); - } - else - { - SetMatchmakerStatus(LocaleUtils.UI_ALL_PLAYERS_JOINED.Localized()); - } - client.SendData(ref packet, DeliveryMethod.ReliableUnordered); - await Task.Delay(1000); - } while (numbersOfPlayersToWaitFor > 0); + } + + if (startButton != null) + { + Destroy(startButton); } } @@ -2454,11 +2466,12 @@ private void CleanUpFikaBackendUtils() { FikaBackendUtils.HostExpectedNumberOfPlayers = 1; FikaBackendUtils.IsSpectator = false; + FikaBackendUtils.IsDedicatedRequester = false; } FikaBackendUtils.RequestFikaWorld = false; FikaBackendUtils.IsReconnect = false; - FikaBackendUtils.ReconnectPosition = Vector3.zero; + FikaBackendUtils.ReconnectPosition = Vector3.zero; } private class ExitManager : Class1491 diff --git a/Fika.Core/Coop/Utils/FikaBackendUtils.cs b/Fika.Core/Coop/Utils/FikaBackendUtils.cs index e156929a..10e65d30 100644 --- a/Fika.Core/Coop/Utils/FikaBackendUtils.cs +++ b/Fika.Core/Coop/Utils/FikaBackendUtils.cs @@ -34,11 +34,12 @@ public static class FikaBackendUtils public static string PMCName { get; internal set; } public static EMatchmakerType MatchingType { get; internal set; } = EMatchmakerType.Single; public static bool IsDedicated = false; - public static bool IsReconnect { get; internal set; } = false; + public static bool IsReconnect { get; internal set; } public static bool IsDedicatedGame { get; set; } = false; - public static bool IsTransit { get; internal set; } = false; - public static bool IsSpectator { get; internal set; } = false; - public static bool IsHostNatPunch { get; internal set; } = false; + public static bool IsDedicatedRequester { get; set; } + public static bool IsTransit { get; internal set; } + public static bool IsSpectator { get; internal set; } + public static bool IsHostNatPunch { get; internal set; } public static int HostExpectedNumberOfPlayers { get; set; } = 1; public static string RemoteIp { get; internal set; } public static int RemotePort { get; internal set; } diff --git a/Fika.Core/Networking/FikaClient.cs b/Fika.Core/Networking/FikaClient.cs index 60cfd044..03213706 100644 --- a/Fika.Core/Networking/FikaClient.cs +++ b/Fika.Core/Networking/FikaClient.cs @@ -46,7 +46,6 @@ public class FikaClient : MonoBehaviour, INetEventListener, IFikaNetworkManager public CoopPlayer MyPlayer; public int Ping = 0; public int ServerFPS = 0; - public int ConnectedClients = 0; public int ReadyClients = 0; public bool HostReady = false; public bool HostLoaded = false; @@ -1060,18 +1059,18 @@ private void OnHealthSyncPacketReceived(HealthSyncPacket packet) private void OnInformationPacketReceived(InformationPacket packet) { - if (!packet.IsRequest) + CoopGame coopGame = CoopHandler.LocalGameInstance; + if (coopGame != null) { - ConnectedClients = packet.NumberOfPlayers; - ReadyClients = packet.ReadyPlayers; - HostReady = packet.HostReady; - HostLoaded = packet.HostLoaded; + coopGame.RaidStarted = packet.RaidStarted; + } + ReadyClients = packet.ReadyPlayers; + HostReady = packet.HostReady; + HostLoaded = packet.HostLoaded; - if (packet.HostReady) - { - CoopGame coopGame = (CoopGame)Singleton.Instance; - coopGame.SetClientTime(packet.GameTime, packet.SessionTime); - } + if (packet.HostReady) + { + coopGame.SetClientTime(packet.GameTime, packet.SessionTime); } } diff --git a/Fika.Core/Networking/FikaServer.cs b/Fika.Core/Networking/FikaServer.cs index 0a047d33..d593dbbc 100644 --- a/Fika.Core/Networking/FikaServer.cs +++ b/Fika.Core/Networking/FikaServer.cs @@ -985,11 +985,12 @@ private void OnInformationPacketReceived(InformationPacket packet, NetPeer peer) { ReadyClients += packet.ReadyPlayers; - bool hostReady = coopHandler != null && coopHandler.LocalGameInstance != null && coopHandler.LocalGameInstance.Status == GameStatus.Started; + bool gameExists = coopHandler != null && coopHandler.LocalGameInstance != null; + bool hostReady = gameExists && coopHandler.LocalGameInstance.Status == GameStatus.Started; - InformationPacket respondPackage = new(false) + InformationPacket respondPackage = new() { - NumberOfPlayers = netServer.ConnectedPeersCount, + RaidStarted = gameExists && coopHandler.LocalGameInstance.RaidStarted, ReadyPlayers = ReadyClients, HostReady = hostReady, HostLoaded = RaidInitialized diff --git a/Fika.Core/Networking/Packets/Backend/InformationPacket.cs b/Fika.Core/Networking/Packets/Backend/InformationPacket.cs index ebaf4ab1..41ad5932 100644 --- a/Fika.Core/Networking/Packets/Backend/InformationPacket.cs +++ b/Fika.Core/Networking/Packets/Backend/InformationPacket.cs @@ -5,20 +5,20 @@ namespace Fika.Core.Networking { - public struct InformationPacket(bool isRequest) : INetSerializable + public struct InformationPacket : INetSerializable { - public bool IsRequest = isRequest; - public int NumberOfPlayers = 0; - public int ReadyPlayers = 0; - public bool HostReady = false; - public bool HostLoaded = false; + public bool RaidStarted; + public bool RequestStart; + public int ReadyPlayers; + public bool HostReady; + public bool HostLoaded; public DateTime GameTime; public TimeSpan SessionTime; public void Deserialize(NetDataReader reader) { - IsRequest = reader.GetBool(); - NumberOfPlayers = reader.GetInt(); + RaidStarted = reader.GetBool(); + RequestStart = reader.GetBool(); ReadyPlayers = reader.GetInt(); HostReady = reader.GetBool(); if (HostReady) @@ -31,8 +31,8 @@ public void Deserialize(NetDataReader reader) public void Serialize(NetDataWriter writer) { - writer.Put(IsRequest); - writer.Put(NumberOfPlayers); + writer.Put(RaidStarted); + writer.Put(RequestStart); writer.Put(ReadyPlayers); writer.Put(HostReady); if (HostReady) diff --git a/Fika.Core/UI/Custom/MatchMakerUIScript.cs b/Fika.Core/UI/Custom/MatchMakerUIScript.cs index 984f767d..423fed1e 100644 --- a/Fika.Core/UI/Custom/MatchMakerUIScript.cs +++ b/Fika.Core/UI/Custom/MatchMakerUIScript.cs @@ -300,16 +300,18 @@ private void CreateMatchMakerUI() }; StartDedicatedResponse response = await FikaRequestHandler.StartDedicated(request); + FikaBackendUtils.IsDedicatedRequester = true; if (!string.IsNullOrEmpty(response.Error)) { PreloaderUI.Instance.ShowErrorScreen(LocaleUtils.UI_DEDICATED_ERROR.Localized(), response.Error); - ToggleLoading(false); + FikaBackendUtils.IsDedicatedRequester = false; } else { NotificationManagerClass.DisplaySingletonWarningNotification(LocaleUtils.STARTING_RAID_ON_DEDICATED.Localized()); + FikaBackendUtils.IsDedicatedRequester = false; } } }); From 92beadbe1e26a1a885a6a720ae859243090845f9 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:21:16 +0100 Subject: [PATCH 02/11] Handle RequestStart on server --- Fika.Core/Networking/FikaServer.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Fika.Core/Networking/FikaServer.cs b/Fika.Core/Networking/FikaServer.cs index d593dbbc..7190118b 100644 --- a/Fika.Core/Networking/FikaServer.cs +++ b/Fika.Core/Networking/FikaServer.cs @@ -996,6 +996,11 @@ private void OnInformationPacketReceived(InformationPacket packet, NetPeer peer) HostLoaded = RaidInitialized }; + if (gameExists && packet.RequestStart) + { + coopHandler.LocalGameInstance.RaidStarted = true; + } + if (hostReady) { respondPackage.GameTime = gameStartTime.Value; From 15db138726508a622b9f798407b6fb6d15ce5a46 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:59:04 +0100 Subject: [PATCH 03/11] Fix logic --- Fika.Core/UI/Custom/MatchMakerUIScript.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Fika.Core/UI/Custom/MatchMakerUIScript.cs b/Fika.Core/UI/Custom/MatchMakerUIScript.cs index 423fed1e..4b4cb246 100644 --- a/Fika.Core/UI/Custom/MatchMakerUIScript.cs +++ b/Fika.Core/UI/Custom/MatchMakerUIScript.cs @@ -136,6 +136,8 @@ protected void OnDestroy() private void CreateMatchMakerUI() { + FikaBackendUtils.IsDedicatedRequester = false; + GetDedicatedStatusResponse response = FikaRequestHandler.GetDedicatedStatus(); GameObject matchMakerUiPrefab = InternalBundleLoader.Instance.GetAssetBundle("newmatchmakerui").LoadAsset("NewMatchMakerUI"); @@ -311,7 +313,6 @@ private void CreateMatchMakerUI() else { NotificationManagerClass.DisplaySingletonWarningNotification(LocaleUtils.STARTING_RAID_ON_DEDICATED.Localized()); - FikaBackendUtils.IsDedicatedRequester = false; } } }); From a823185d849e7ee68e5a2ff4f567b7916914cc18 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:09:20 +0100 Subject: [PATCH 04/11] Improve logic and add locales --- Fika.Core/Coop/GameMode/CoopGame.cs | 18 +++++++++--------- Fika.Core/Networking/FikaClient.cs | 5 ++--- Fika.Core/Utils/LocaleUtils.cs | 1 + 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 1a7db391..f8fea22d 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -947,14 +947,15 @@ private GameObject CreateStartButton() //customButton.gameObject.transform.position = new(customButton.transform.position.x, customButton.transform.position.y - 20, customButton.transform.position.z); customButton.gameObject.SetActive(true); DefaultUIButton backButtonComponent = customButton.GetComponent(); - backButtonComponent.SetHeaderText("Start", 32); - backButtonComponent.SetEnabledTooltip("Starts the raid."); + backButtonComponent.SetHeaderText(LocaleUtils.UI_MM_START_BUTTON.Localized(), 32); + backButtonComponent.SetEnabledTooltip(LocaleUtils.UI_START_DESCRIPTION.Localized()); UnityEngine.Events.UnityEvent newEvent = new(); newEvent.AddListener(() => { if (isServer) { RaidStarted = true; + FikaBackendUtils.HostExpectedNumberOfPlayers = Singleton.Instance.NetServer.ConnectedPeersCount; return; } @@ -1406,13 +1407,16 @@ private async Task WaitForHostToStart() while (!RaidStarted) { - await Task.Delay(100); + await Task.Yield(); } if (startButton != null) { Destroy(startButton); } + + SetStatusModel status = new(FikaBackendUtils.GroupId, LobbyEntry.ELobbyStatus.IN_GAME); + await FikaRequestHandler.UpdateSetStatus(status); return; } @@ -1425,7 +1429,7 @@ private async Task WaitForHostToStart() client.SendData(ref packet, DeliveryMethod.ReliableUnordered); while (!RaidStarted) { - await Task.Delay(100); + await Task.Delay(250); client.SendData(ref packet, DeliveryMethod.ReliableUnordered); } @@ -1557,11 +1561,7 @@ public override async Task vmethod_1(BotControllerSettings controllerSettings, I botsController_0.EventsController.SpawnAction(); FikaPlugin.DynamicAI.SettingChanged += DynamicAI_SettingChanged; - FikaPlugin.DynamicAIRate.SettingChanged += DynamicAIRate_SettingChanged; - - SetStatusModel status = new(FikaBackendUtils.GroupId, LobbyEntry.ELobbyStatus.IN_GAME); - - await FikaRequestHandler.UpdateSetStatus(status); + FikaPlugin.DynamicAIRate.SettingChanged += DynamicAIRate_SettingChanged; } // Add FreeCamController to GameWorld GameObject diff --git a/Fika.Core/Networking/FikaClient.cs b/Fika.Core/Networking/FikaClient.cs index 03213706..d7f0e014 100644 --- a/Fika.Core/Networking/FikaClient.cs +++ b/Fika.Core/Networking/FikaClient.cs @@ -22,9 +22,7 @@ using Fika.Core.Coop.Utils; using Fika.Core.Modding; using Fika.Core.Modding.Events; -using Fika.Core.Networking.Packets; using Fika.Core.Utils; -using FlyingWormConsole3; using HarmonyLib; using LiteNetLib; using LiteNetLib.Utils; @@ -1062,7 +1060,8 @@ private void OnInformationPacketReceived(InformationPacket packet) CoopGame coopGame = CoopHandler.LocalGameInstance; if (coopGame != null) { - coopGame.RaidStarted = packet.RaidStarted; + coopGame.RaidStarted = packet.RaidStarted; + FikaBackendUtils.HostExpectedNumberOfPlayers = packet.ReadyPlayers; } ReadyClients = packet.ReadyPlayers; HostReady = packet.HostReady; diff --git a/Fika.Core/Utils/LocaleUtils.cs b/Fika.Core/Utils/LocaleUtils.cs index 3a95e70f..82b1bc74 100644 --- a/Fika.Core/Utils/LocaleUtils.cs +++ b/Fika.Core/Utils/LocaleUtils.cs @@ -155,6 +155,7 @@ public static bool IsBoss(WildSpawnType wildSpawnType, out string name) public const string UI_MM_LOADING_HEADER = "F_MMUI_LoadingScreenHeader"; public const string UI_MM_LOADING_DESCRIPTION = "F_MMUI_LoadingScreenDescription"; public const string UI_MM_JOIN_AS_SPECTATOR = "F_MMUI_JoinAsSpectator"; + public const string UI_START_DESCRIPTION = "F_UI_StartRaidDescription"; public const string UI_CANNOT_JOIN_RAID_OTHER_MAP = "F_UI_CannotJoinRaidOtherMap"; public const string UI_CANNOT_JOIN_RAID_OTHER_TIME = "F_UI_CannotJoinRaidOtherTime"; public const string UI_CANNOT_JOIN_RAID_SCAV_AS_PMC = "F_UI_CannotJoinRaidScavAsPMC"; From 6b9d36e07696abd51200eab1d701e3841475f8f3 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:10:34 +0100 Subject: [PATCH 05/11] Change const name --- Fika.Core/Coop/GameMode/CoopGame.cs | 2 +- Fika.Core/Utils/LocaleUtils.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index f8fea22d..e2dc36fd 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -948,7 +948,7 @@ private GameObject CreateStartButton() customButton.gameObject.SetActive(true); DefaultUIButton backButtonComponent = customButton.GetComponent(); backButtonComponent.SetHeaderText(LocaleUtils.UI_MM_START_BUTTON.Localized(), 32); - backButtonComponent.SetEnabledTooltip(LocaleUtils.UI_START_DESCRIPTION.Localized()); + backButtonComponent.SetEnabledTooltip(LocaleUtils.UI_START_RAID_DESCRIPTION.Localized()); UnityEngine.Events.UnityEvent newEvent = new(); newEvent.AddListener(() => { diff --git a/Fika.Core/Utils/LocaleUtils.cs b/Fika.Core/Utils/LocaleUtils.cs index 82b1bc74..3fbe4aed 100644 --- a/Fika.Core/Utils/LocaleUtils.cs +++ b/Fika.Core/Utils/LocaleUtils.cs @@ -155,7 +155,7 @@ public static bool IsBoss(WildSpawnType wildSpawnType, out string name) public const string UI_MM_LOADING_HEADER = "F_MMUI_LoadingScreenHeader"; public const string UI_MM_LOADING_DESCRIPTION = "F_MMUI_LoadingScreenDescription"; public const string UI_MM_JOIN_AS_SPECTATOR = "F_MMUI_JoinAsSpectator"; - public const string UI_START_DESCRIPTION = "F_UI_StartRaidDescription"; + public const string UI_START_RAID_DESCRIPTION = "F_UI_StartRaidDescription"; public const string UI_CANNOT_JOIN_RAID_OTHER_MAP = "F_UI_CannotJoinRaidOtherMap"; public const string UI_CANNOT_JOIN_RAID_OTHER_TIME = "F_UI_CannotJoinRaidOtherTime"; public const string UI_CANNOT_JOIN_RAID_SCAV_AS_PMC = "F_UI_CannotJoinRaidScavAsPMC"; From 13124137c2a418061ec8091e00dad17d0a2343ed Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:14:13 +0100 Subject: [PATCH 06/11] Add new locale --- Fika.Core/Coop/GameMode/CoopGame.cs | 2 +- Fika.Core/Utils/LocaleUtils.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index e2dc36fd..be0403ef 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -947,7 +947,7 @@ private GameObject CreateStartButton() //customButton.gameObject.transform.position = new(customButton.transform.position.x, customButton.transform.position.y - 20, customButton.transform.position.z); customButton.gameObject.SetActive(true); DefaultUIButton backButtonComponent = customButton.GetComponent(); - backButtonComponent.SetHeaderText(LocaleUtils.UI_MM_START_BUTTON.Localized(), 32); + backButtonComponent.SetHeaderText(LocaleUtils.UI_START_RAID.Localized(), 32); backButtonComponent.SetEnabledTooltip(LocaleUtils.UI_START_RAID_DESCRIPTION.Localized()); UnityEngine.Events.UnityEvent newEvent = new(); newEvent.AddListener(() => diff --git a/Fika.Core/Utils/LocaleUtils.cs b/Fika.Core/Utils/LocaleUtils.cs index 3fbe4aed..0353ab2b 100644 --- a/Fika.Core/Utils/LocaleUtils.cs +++ b/Fika.Core/Utils/LocaleUtils.cs @@ -155,6 +155,7 @@ public static bool IsBoss(WildSpawnType wildSpawnType, out string name) public const string UI_MM_LOADING_HEADER = "F_MMUI_LoadingScreenHeader"; public const string UI_MM_LOADING_DESCRIPTION = "F_MMUI_LoadingScreenDescription"; public const string UI_MM_JOIN_AS_SPECTATOR = "F_MMUI_JoinAsSpectator"; + public const string UI_START_RAID = "F_UI_StartRaid"; public const string UI_START_RAID_DESCRIPTION = "F_UI_StartRaidDescription"; public const string UI_CANNOT_JOIN_RAID_OTHER_MAP = "F_UI_CannotJoinRaidOtherMap"; public const string UI_CANNOT_JOIN_RAID_OTHER_TIME = "F_UI_CannotJoinRaidOtherTime"; From fcce93362b31d34b5e1e97fdec3ada305adfa4b8 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:53:57 +0100 Subject: [PATCH 07/11] Use coalesce expression --- Fika.Core/Coop/GameMode/CoopGame.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index be0403ef..fe3013ef 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -959,12 +959,7 @@ private GameObject CreateStartButton() return; } - FikaClient fikaClient = Singleton.Instance; - if (fikaClient == null) - { - throw new NullReferenceException("CreateStartButton::FikaClient was null!"); - } - + FikaClient fikaClient = Singleton.Instance ?? throw new NullReferenceException("CreateStartButton::FikaClient was null!"); InformationPacket packet = new() { RequestStart = true From 914b21af69fa5a674edc9b1ee22f9621e31b1392 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:56:36 +0100 Subject: [PATCH 08/11] Localize button --- Fika.Core/UI/Patches/MenuTaskBar_Patch.cs | 2 +- Fika.Core/Utils/LocaleUtils.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs b/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs index ff95e2b1..2da9382a 100644 --- a/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs +++ b/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs @@ -42,7 +42,7 @@ public static void Postfix(MenuTaskBar __instance) LocalizedText text = downloadProfileGameObject.GetComponentInChildren(); if (text != null) { - text.method_2("DOWNLOAD PROFILE"); + text.method_2(LocaleUtils.UI_DOWNLOAD_PROFILE.Localized()); text.LocalizationKey = ""; } diff --git a/Fika.Core/Utils/LocaleUtils.cs b/Fika.Core/Utils/LocaleUtils.cs index 0353ab2b..079b355f 100644 --- a/Fika.Core/Utils/LocaleUtils.cs +++ b/Fika.Core/Utils/LocaleUtils.cs @@ -209,6 +209,7 @@ public static bool IsBoss(WildSpawnType wildSpawnType, out string name) public const string UI_NOTIFICATION_RECEIVED_ITEM = "F_Notification_ItemReceived"; public const string UI_NOTIFICATION_RAIDSETTINGS_DISABLED = "F_Notification_RaidSettingsDisabled"; public const string UI_EXTRACT_MESSAGE = "F_UI_ExtractMessage"; + public const string UI_DOWNLOAD_PROFILE = "F_UI_DownloadProfile"; // Main Menu UI public const string UI_MMUI_ONLINE_PLAYERS = "F_MMUI_OnlinePlayers"; From 19bf80792f5b795d4777376963983f1712d60c2e Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:24:04 +0100 Subject: [PATCH 09/11] Block DL profile during load & delete survey --- Fika.Core/UI/Patches/MenuTaskBar_Patch.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs b/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs index 2da9382a..ffd57f5c 100644 --- a/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs +++ b/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs @@ -6,6 +6,7 @@ using Newtonsoft.Json.Linq; using SPT.Reflection.Patching; using System; +using System.Collections.Generic; using System.IO; using System.Reflection; using UnityEngine; @@ -22,7 +23,7 @@ protected override MethodBase GetTargetMethod() } [PatchPostfix] - public static void Postfix(MenuTaskBar __instance) + public static void Postfix(Dictionary ____toggleButtons, Dictionary ____hoverTooltipAreas) { GameObject watchlistGameobject = GameObject.Find("Preloader UI/Preloader UI/BottomPanel/Content/TaskBar/Tabs/Watchlist"); if (watchlistGameobject != null) @@ -91,6 +92,8 @@ public static void Postfix(MenuTaskBar __instance) NotificationManagerClass.DisplayMessageNotification(string.Format(LocaleUtils.SAVED_PROFILE.Localized(), [ColorizeText(EColor.BLUE, profileId), fikaDir])); + ____toggleButtons.Remove(EMenuType.NewsHub); + ____hoverTooltipAreas.Remove(EMenuType.NewsHub); GameObject.Destroy(downloadProfileGameObject); } } @@ -105,6 +108,14 @@ public static void Postfix(MenuTaskBar __instance) FikaPlugin.Instance.FikaLogger.LogError(ex.Message); } }); + + HoverTooltipArea surveryButton = ____hoverTooltipAreas[EMenuType.NewsHub]; + GameObject.Destroy(surveryButton.gameObject); + + ____toggleButtons.Remove(EMenuType.NewsHub); + ____hoverTooltipAreas.Remove(EMenuType.NewsHub); + ____toggleButtons.Add(EMenuType.NewsHub, animatedToggle); + ____hoverTooltipAreas.Add(EMenuType.NewsHub, downloadProfileGameObject.GetComponent()); } } } From ea15acbebc6a7560b66662fc118f6462b7d67fd0 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:36:01 +0100 Subject: [PATCH 10/11] use Path.Combine --- Fika.Core/UI/Patches/MenuTaskBar_Patch.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs b/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs index ffd57f5c..1d372660 100644 --- a/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs +++ b/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs @@ -72,7 +72,7 @@ public static void Postfix(Dictionary ____toggleButto { Singleton.Instance.PlayUISound(EUISoundType.ButtonBottomBarClick); string installDir = Environment.CurrentDirectory; - string fikaDir = installDir + @"\user\fika"; + string fikaDir = Path.Combine(installDir, @"\user\fika"); if (!string.IsNullOrEmpty(installDir)) { From a8dd1d2de0d58da234caf2ce10d517855b7de347 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:28:01 +0100 Subject: [PATCH 11/11] Fix nullref --- Fika.Core/UI/Patches/MenuTaskBar_Patch.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs b/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs index 1d372660..ffeda5dc 100644 --- a/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs +++ b/Fika.Core/UI/Patches/MenuTaskBar_Patch.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Reflection; using UnityEngine; using UnityEngine.UI; @@ -23,7 +24,8 @@ protected override MethodBase GetTargetMethod() } [PatchPostfix] - public static void Postfix(Dictionary ____toggleButtons, Dictionary ____hoverTooltipAreas) + public static void Postfix(Dictionary ____toggleButtons, Dictionary ____hoverTooltipAreas, ref GameObject[] ____newInformation) { GameObject watchlistGameobject = GameObject.Find("Preloader UI/Preloader UI/BottomPanel/Content/TaskBar/Tabs/Watchlist"); if (watchlistGameobject != null) @@ -109,11 +111,15 @@ public static void Postfix(Dictionary ____toggleButto } }); - HoverTooltipArea surveryButton = ____hoverTooltipAreas[EMenuType.NewsHub]; - GameObject.Destroy(surveryButton.gameObject); + HoverTooltipArea surveyButton = ____hoverTooltipAreas[EMenuType.NewsHub]; ____toggleButtons.Remove(EMenuType.NewsHub); ____hoverTooltipAreas.Remove(EMenuType.NewsHub); + GameObject.Destroy(surveyButton.gameObject); + List newList = new(____newInformation); + newList.Remove(newList.Last()); + ____newInformation = [.. newList]; + ____toggleButtons.Add(EMenuType.NewsHub, animatedToggle); ____hoverTooltipAreas.Add(EMenuType.NewsHub, downloadProfileGameObject.GetComponent()); }