From 820e4f41ae454e7a0d791cd4f9653eb49ad3501e Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Thu, 9 Jan 2025 08:24:20 +0100 Subject: [PATCH 1/4] Change fetching to earlier stage --- Fika.Core/Coop/GameMode/CoopGame.cs | 36 +++++++++++++---------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 28776fd1..e6c5d428 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -55,15 +55,15 @@ public sealed class CoopGame : BaseLocalGame, IBotGame, IFik { public string InfiltrationPoint; public ExitStatus ExitStatus { get; set; } = ExitStatus.Survived; - public string ExitLocation { get; set; } = null; + public string ExitLocation { get; set; } public ISpawnSystem SpawnSystem; public Dictionary Bots = []; public List ExtractedPlayers { get; } = []; public string SpawnId; - public bool InteractablesInitialized { get; set; } = false; - public bool HasReceivedLoot { get; set; } = false; + public bool InteractablesInitialized { get; set; } + public bool HasReceivedLoot { get; set; } public List ThrownGrenades; - public bool WeatherReady; + public bool WeatherReady { get; internal set; } public bool RaidStarted { get; set; } private readonly Dictionary botQueue = []; @@ -1479,6 +1479,8 @@ private async Task SetStatus(LocalPlayer myPlayer, LobbyEntry.ELobbyStatus statu /// public override async Task vmethod_1(BotControllerSettings controllerSettings, ISpawnSystem spawnSystem) { + await GenerateWeathers(); + GameWorld gameWorld = Singleton.Instance; gameWorld.RegisterRestrictableZones(); @@ -1599,7 +1601,7 @@ public override async Task vmethod_1(BotControllerSettings controllerSettings, I GameWorld_0.RegisterBorderZones(); } - public override IEnumerator vmethod_5(Action runCallback) + private async Task GenerateWeathers() { if (WeatherController.Instance != null) { @@ -1607,12 +1609,7 @@ public override IEnumerator vmethod_5(Action runCallback) Logger.LogInfo("Generating and initializing weather..."); if (isServer) { - Task weatherTask = iSession.WeatherRequest(); - while (!weatherTask.IsCompleted) - { - yield return new WaitForEndOfFrame(); - } - GClass1310 weather = weatherTask.Result; + GClass1310 weather = await iSession.WeatherRequest(); Season = weather.Season; SeasonsSettings = weather.SeasonsSettings; if (!OfflineRaidSettingsMenuPatch_Override.UseCustomWeather) @@ -1623,28 +1620,27 @@ public override IEnumerator vmethod_5(Action runCallback) } else { - Task getWeather = GetWeather(); - while (!getWeather.IsCompleted) - { - yield return new WaitForEndOfFrame(); - } + await GetWeather(); WeatherController.Instance.method_0(WeatherClasses); } } + WeatherReady = true; + OfflineRaidSettingsMenuPatch_Override.UseCustomWeather = false; + } + + public override IEnumerator vmethod_5(Action runCallback) + { SetMatchmakerStatus(LocaleUtils.UI_FINISHING_RAID_INIT.Localized()); GameWorld_0.TriggersModule = gameObject.AddComponent(); GameWorld_0.FillLampControllers(); - WeatherReady = true; - OfflineRaidSettingsMenuPatch_Override.UseCustomWeather = false; - Class442 seasonController = new(); GameWorld_0.GInterface29_0 = seasonController; #if DEBUG - Logger.LogWarning("Running season handler"); + Logger.LogWarning($"Running season handler for season: {Season}"); #endif Task runSeason = seasonController.Run(Season, SeasonsSettings); while (!runSeason.IsCompleted) From f85508979ac87e1b986feaba9cf40f979e8584a4 Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Thu, 9 Jan 2025 08:25:59 +0100 Subject: [PATCH 2/4] Skip labs --- Fika.Core/Coop/GameMode/CoopGame.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index e6c5d428..dfd30726 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -1603,6 +1603,16 @@ public override async Task vmethod_1(BotControllerSettings controllerSettings, I private async Task GenerateWeathers() { + if (Location_0.Id == "laboratory") + { + Logger.LogInfo("Location is 'Laboratory', skipping weather generation"); + Season = ESeason.Summer; + WeatherReady = true; + OfflineRaidSettingsMenuPatch_Override.UseCustomWeather = false; + + return; + } + if (WeatherController.Instance != null) { SetMatchmakerStatus(LocaleUtils.UI_INIT_WEATHER.Localized()); From 3f0dc316d543802fbcbd39a730a1e0e95cc816dd Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Thu, 9 Jan 2025 08:32:49 +0100 Subject: [PATCH 3/4] Use Session settings rather than request --- Fika.Core/Coop/GameMode/CoopGame.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index dfd30726..8235a5b9 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -1620,8 +1620,8 @@ private async Task GenerateWeathers() if (isServer) { GClass1310 weather = await iSession.WeatherRequest(); - Season = weather.Season; - SeasonsSettings = weather.SeasonsSettings; + Season = iSession.Season; + SeasonsSettings = iSession.SeasonsSettings; if (!OfflineRaidSettingsMenuPatch_Override.UseCustomWeather) { WeatherClasses = weather.Weathers; From c10640a637afba0e2eb0d1252c802071a3b67beb Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Thu, 9 Jan 2025 08:48:09 +0100 Subject: [PATCH 4/4] Refactor properties --- Fika.Core/Coop/GameMode/CoopGame.cs | 36 +++++++++++++++------------- Fika.Core/Coop/GameMode/IFikaGame.cs | 4 ++-- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Fika.Core/Coop/GameMode/CoopGame.cs b/Fika.Core/Coop/GameMode/CoopGame.cs index 8235a5b9..ccb1c700 100644 --- a/Fika.Core/Coop/GameMode/CoopGame.cs +++ b/Fika.Core/Coop/GameMode/CoopGame.cs @@ -53,18 +53,22 @@ namespace Fika.Core.Coop.GameMode /// public sealed class CoopGame : BaseLocalGame, IBotGame, IFikaGame { - public string InfiltrationPoint; + public string InfiltrationPoint { get; internal set; } public ExitStatus ExitStatus { get; set; } = ExitStatus.Survived; public string ExitLocation { get; set; } - public ISpawnSystem SpawnSystem; + public ISpawnSystem SpawnSystem { get; internal set; } public Dictionary Bots = []; public List ExtractedPlayers { get; } = []; - public string SpawnId; - public bool InteractablesInitialized { get; set; } - public bool HasReceivedLoot { get; set; } - public List ThrownGrenades; + public string SpawnId { get; internal set; } + public bool InteractablesInitialized { get; internal set; } + public bool HasReceivedLoot { get; internal set; } + public List ThrownGrenades { get; internal set; } public bool WeatherReady { get; internal set; } - public bool RaidStarted { get; set; } + public bool RaidStarted { get; internal set; } + public FikaDynamicAI DynamicAI { get; private set; } + public RaidSettings RaidSettings { get; private set; } + public byte[] HostLootItems { get; private set; } + public GClass1315 LootItems { get; internal set; } = []; private readonly Dictionary botQueue = []; private Coroutine extractRoutine; @@ -85,11 +89,7 @@ public sealed class CoopGame : BaseLocalGame, IBotGame, IFik private TimeSpan? sessionTime; private BotStateManager botStateManager; private ESeason season; - - public FikaDynamicAI DynamicAI { get; private set; } - public RaidSettings RaidSettings { get; private set; } - public byte[] HostLootItems { get; private set; } - public GClass1315 LootItems { get; internal set; } = []; + BossSpawnScenario IBotGame.BossSpawnScenario { get @@ -131,6 +131,7 @@ public ESeason Season { season = value; Logger.LogInfo($"Setting Season to: {value}"); + WeatherReady = true; } } @@ -1606,8 +1607,7 @@ private async Task GenerateWeathers() if (Location_0.Id == "laboratory") { Logger.LogInfo("Location is 'Laboratory', skipping weather generation"); - Season = ESeason.Summer; - WeatherReady = true; + Season = ESeason.Summer; OfflineRaidSettingsMenuPatch_Override.UseCustomWeather = false; return; @@ -1635,7 +1635,6 @@ private async Task GenerateWeathers() } } - WeatherReady = true; OfflineRaidSettingsMenuPatch_Override.UseCustomWeather = false; } @@ -1671,10 +1670,13 @@ private async Task GetWeather() FikaClient client = Singleton.Instance; client.SendData(ref packet, DeliveryMethod.ReliableUnordered); - while (WeatherClasses == null) + while (!WeatherReady) { await Task.Delay(1000); - client.SendData(ref packet, DeliveryMethod.ReliableUnordered); + if (!WeatherReady) + { + client.SendData(ref packet, DeliveryMethod.ReliableUnordered); + } } } diff --git a/Fika.Core/Coop/GameMode/IFikaGame.cs b/Fika.Core/Coop/GameMode/IFikaGame.cs index 6590d86c..0e59f447 100644 --- a/Fika.Core/Coop/GameMode/IFikaGame.cs +++ b/Fika.Core/Coop/GameMode/IFikaGame.cs @@ -16,8 +16,8 @@ public interface IFikaGame public void Stop(string profileId, ExitStatus exitStatus, string exitName, float delay = 0f); - public ESeason Season { get; set; } + public ESeason Season { get; internal set; } - public SeasonsSettingsClass SeasonsSettings { get; set; } + public SeasonsSettingsClass SeasonsSettings { get; internal set; } } }