From 74ee4f77b763a9a7d3fa2e4f0ec5083b808a85a8 Mon Sep 17 00:00:00 2001 From: Richard Griffiths Date: Sun, 13 Jun 2021 10:45:54 +0200 Subject: [PATCH 1/6] Expose divergence to settings so modpacks can turn it off --- settings.json | 6 +++++ .../Misc/LanceSelectionDivergenceOverride.cs | 11 +++++++++ src/Core/Settings/MiscSettings.cs | 8 +++++++ src/Core/Settings/Settings.cs | 5 +++- src/Core/Settings/SettingsOverride.cs | 9 ++++++++ ...anceOverrideSelectLanceDefFromListPatch.cs | 23 +++++++++---------- 6 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 src/Core/Settings/Misc/LanceSelectionDivergenceOverride.cs create mode 100644 src/Core/Settings/MiscSettings.cs diff --git a/settings.json b/settings.json index 98e6b6e2..cfccffce 100644 --- a/settings.json +++ b/settings.json @@ -128,5 +128,11 @@ "MinBuffer": 100, "MaxBuffer": 200 } + }, + "Misc": { + "LanceSelectionDivergenceOverride": { + "Enable": true, + "Divergence": 20 + } } } diff --git a/src/Core/Settings/Misc/LanceSelectionDivergenceOverride.cs b/src/Core/Settings/Misc/LanceSelectionDivergenceOverride.cs new file mode 100644 index 00000000..f5bb9999 --- /dev/null +++ b/src/Core/Settings/Misc/LanceSelectionDivergenceOverride.cs @@ -0,0 +1,11 @@ +using Newtonsoft.Json; + +namespace MissionControl.Config { + public class LanceSelectionDivergenceOverride { + [JsonProperty("Enable")] + public bool Enable { get; set; } = true; + + [JsonProperty("Divergence")] + public int Divergence { get; set; } = 20; + } +} \ No newline at end of file diff --git a/src/Core/Settings/MiscSettings.cs b/src/Core/Settings/MiscSettings.cs new file mode 100644 index 00000000..965e384f --- /dev/null +++ b/src/Core/Settings/MiscSettings.cs @@ -0,0 +1,8 @@ +using Newtonsoft.Json; + +namespace MissionControl.Config { + public class MiscSettings { + [JsonProperty("LanceSelectionDivergenceOverride")] + public LanceSelectionDivergenceOverride LanceSelectionDivergenceOverride { get; set; } = new LanceSelectionDivergenceOverride(); + } +} \ No newline at end of file diff --git a/src/Core/Settings/Settings.cs b/src/Core/Settings/Settings.cs index 4597649a..f444c459 100644 --- a/src/Core/Settings/Settings.cs +++ b/src/Core/Settings/Settings.cs @@ -36,7 +36,7 @@ public class Settings { [JsonProperty("NeverFailSimGameInFlashpoints")] public bool NeverFailSimGameInFlashpoints { get; set; } = true; - + [JsonProperty("EnableStoryOverrides")] public bool EnableStoryOverrides { get; set; } = false; @@ -75,6 +75,9 @@ public class Settings { [JsonProperty("Spawners")] public SpawnerSettings Spawners { get; set; } = new SpawnerSettings(); + [JsonProperty("Misc")] + public MiscSettings Misc { get; set; } = new MiscSettings(); + public Dictionary ContractSettingsOverrides = new Dictionary(); public ContractSettingsOverrides ActiveContractSettings { get; set; } diff --git a/src/Core/Settings/SettingsOverride.cs b/src/Core/Settings/SettingsOverride.cs index f2568a6b..f607b6c5 100644 --- a/src/Core/Settings/SettingsOverride.cs +++ b/src/Core/Settings/SettingsOverride.cs @@ -107,6 +107,9 @@ public class SettingsOverride { public static string Spawners_SpawnLanceAtEdgeBoundary_MinBuffer = "Spawners.SpawnLanceAtEdgeBoundary.MinBuffer"; public static string Spawners_SpawnLanceAtEdgeBoundary_MaxBuffer = "Spawners.SpawnLanceAtEdgeBoundary.MaxBuffer"; + public static string Misc_LanceSelectionDivergenceOverride_Enable = "Misc.LanceSelectionDivergenceOverride.Enable"; + public static string Misc_LanceSelectionDivergenceOverride_Divergence = "Misc.LanceSelectionDivergenceOverride.Divergence"; + public static string AdditionalPlayerMechs_Enable = "AdditionalPlayerMechs"; JsonSerializerSettings serialiserSettings = new JsonSerializerSettings() { @@ -177,6 +180,7 @@ public Settings LoadOverrides(Settings settings) { LoadDynamicWithdraw(settings); LoadAI(settings); LoadSpawners(settings); + LoadMisc(settings); } return settings; @@ -310,5 +314,10 @@ public void LoadSpawners(Settings settings) { if (Has(Spawners_SpawnLanceAtEdgeBoundary_MinBuffer)) settings.Spawners.SpawnLanceAtBoundary.MinBuffer = GetInt(Spawners_SpawnLanceAtEdgeBoundary_MinBuffer); if (Has(Spawners_SpawnLanceAtEdgeBoundary_MaxBuffer)) settings.Spawners.SpawnLanceAtBoundary.MaxBuffer = GetInt(Spawners_SpawnLanceAtEdgeBoundary_MaxBuffer); } + + public void LoadMisc(Settings settings) { + if (Has(Misc_LanceSelectionDivergenceOverride_Enable)) settings.Misc.LanceSelectionDivergenceOverride.Enable = GetBool(Misc_LanceSelectionDivergenceOverride_Enable); + if (Has(Misc_LanceSelectionDivergenceOverride_Divergence)) settings.Misc.LanceSelectionDivergenceOverride.Divergence = GetInt(Misc_LanceSelectionDivergenceOverride_Divergence); + } } } \ No newline at end of file diff --git a/src/Patches/Bug Fixes/LanceOverrideSelectLanceDefFromListPatch.cs b/src/Patches/Bug Fixes/LanceOverrideSelectLanceDefFromListPatch.cs index 4353d436..50cb5877 100644 --- a/src/Patches/Bug Fixes/LanceOverrideSelectLanceDefFromListPatch.cs +++ b/src/Patches/Bug Fixes/LanceOverrideSelectLanceDefFromListPatch.cs @@ -7,17 +7,16 @@ using BattleTech; using BattleTech.Framework; -namespace MissionControl.Patches -{ - // Under weird circumstances it can ask for a lance at too high difficulty and for unknown reasons it only wants to grab lances within 10 difficulty. - // Allowing over 10 difference in difficulty in it's search in this method should fix the issue. This isn't a Mission Control specific fix as other - // mod set ups could cause this but Mission Control with certain settings could induce this issue in of itself so worth fixing here. - [HarmonyPatch(typeof(LanceOverride), "SelectLanceDefFromList")] - public static class LanceOverrideSelectLanceDefFromListPatch - { - public static void Prefix(ref int ___MAX_DIFF_DIVERGENCE) - { - ___MAX_DIFF_DIVERGENCE = 20; - } +namespace MissionControl.Patches { + // Under weird circumstances it can ask for a lance at too high difficulty and for unknown reasons it only wants to grab lances within 10 difficulty. + // Allowing over 10 difference in difficulty in it's search in this method should fix the issue. This isn't a Mission Control specific fix as other + // mod set ups could cause this but Mission Control with certain settings could induce this issue in of itself so worth fixing here. + [HarmonyPatch(typeof(LanceOverride), "SelectLanceDefFromList")] + public static class LanceOverrideSelectLanceDefFromListPatch { + public static void Prefix(ref int ___MAX_DIFF_DIVERGENCE) { + if (Main.Settings.Misc.LanceSelectionDivergenceOverride.Enable) { + ___MAX_DIFF_DIVERGENCE = Main.Settings.Misc.LanceSelectionDivergenceOverride.Divergence; + } } + } } From 122eb1268d68df8a77e41781c3b405917390fbd0 Mon Sep 17 00:00:00 2001 From: Richard Griffiths Date: Mon, 14 Jun 2021 09:01:41 +0200 Subject: [PATCH 2/6] Add error check for null or empty contract override ID --- src/Core/MissionControl.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Core/MissionControl.cs b/src/Core/MissionControl.cs index 4d0e981c..dd98294d 100644 --- a/src/Core/MissionControl.cs +++ b/src/Core/MissionControl.cs @@ -267,6 +267,8 @@ public void SetContractSettingsOverride() { string contractId = CurrentContract.Override.ID; string type = IsAnyFlashpointContract() ? "flashpoint" : "contract"; + if (contractId == null || contractId == "") Main.Logger.LogError($"[MissionControl] [SetContractSettingsOverride] 'contractId' is null or empty string. This indicates a badly created or corrupt contract override."); + if (Main.Settings.ContractSettingsOverrides.ContainsKey(contractId)) { Main.Logger.Log($"[MissionControl] Setting a {type} MC settings override for '{contractId}'."); Main.Settings.ActiveContractSettings = Main.Settings.ContractSettingsOverrides[contractId]; From eed46860e57d2d281777610b6c6eba0ae1210a2c Mon Sep 17 00:00:00 2001 From: Richard Griffiths Date: Wed, 23 Jun 2021 11:54:09 +0200 Subject: [PATCH 3/6] Added error checking for IsInActiveFlashpoint --- src/Core/MissionControl.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Core/MissionControl.cs b/src/Core/MissionControl.cs index dd98294d..11ed29a0 100644 --- a/src/Core/MissionControl.cs +++ b/src/Core/MissionControl.cs @@ -483,8 +483,17 @@ public bool IsAnyFlashpointContract() { public bool IsInActiveFlashpointContract() { if (IsSkirmish()) return false; + if (CurrentContract == null) { + Main.Logger.LogError("[IsInActiveFlashpointContract] MC's CurrentContract is null. This is a possible mod conflict or a cascade error causing the CurrentContract never to be assigned in MC."); + return false; + } + + Flashpoint activeFlashpoint = UnityGameInstance.BattleTechGame.Simulation.ActiveFlashpoint; + if (activeFlashpoint != null && activeFlashpoint.ActiveContract == null) { + Main.Logger.LogWarning("[IsInActiveFlashpointContract] Simulation.ActiveFlashpoint is present but there is no ActiveContract within that Flashpoint. This may be harmless or a cause of other errors causing problems. Not MC related."); + } - return UnityGameInstance.BattleTechGame.Simulation.ActiveFlashpoint?.ActiveContract.encounterObjectGuid == this.CurrentContract.encounterObjectGuid; + return activeFlashpoint?.ActiveContract?.encounterObjectGuid == this.CurrentContract.encounterObjectGuid; } public bool IsAnyStoryContract() { From f07399586909a1a10abef7c75ac49d154826f938 Mon Sep 17 00:00:00 2001 From: Richard Griffiths Date: Wed, 23 Jun 2021 11:54:19 +0200 Subject: [PATCH 4/6] Fixed bad comment --- src/Core/Settings/Ai/FollowAiSettings.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Settings/Ai/FollowAiSettings.cs b/src/Core/Settings/Ai/FollowAiSettings.cs index 748a850d..a2d2878f 100644 --- a/src/Core/Settings/Ai/FollowAiSettings.cs +++ b/src/Core/Settings/Ai/FollowAiSettings.cs @@ -8,7 +8,7 @@ public class FollowAiSettings { public string Pathfinding { get; set; } = "Alternative"; // Original, Alternative [JsonProperty("Target")] - public string Target { get; set; } = "HeaviestMech"; // HeaviestMech, FirstLanceMember + public string Target { get; set; } = "HeaviestMech"; // HeaviestMech, LanceOrder [JsonProperty("StopWhen")] public string StopWhen { get; set; } = "OnEnemyDetected"; // OnEnemyDetected, OnEnemyVisible, WhenNotNeeded From 76282eb87c5303b4e6058fa957d6b6647ef62841 Mon Sep 17 00:00:00 2001 From: Richard Griffiths Date: Wed, 23 Jun 2021 15:35:38 +0200 Subject: [PATCH 5/6] Removed log to prevent spam --- src/Core/MissionControl.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Core/MissionControl.cs b/src/Core/MissionControl.cs index 11ed29a0..9fc08b3f 100644 --- a/src/Core/MissionControl.cs +++ b/src/Core/MissionControl.cs @@ -489,10 +489,6 @@ public bool IsInActiveFlashpointContract() { } Flashpoint activeFlashpoint = UnityGameInstance.BattleTechGame.Simulation.ActiveFlashpoint; - if (activeFlashpoint != null && activeFlashpoint.ActiveContract == null) { - Main.Logger.LogWarning("[IsInActiveFlashpointContract] Simulation.ActiveFlashpoint is present but there is no ActiveContract within that Flashpoint. This may be harmless or a cause of other errors causing problems. Not MC related."); - } - return activeFlashpoint?.ActiveContract?.encounterObjectGuid == this.CurrentContract.encounterObjectGuid; } From 93847f7c1bc825d9a52523dfdaba604521c90ccc Mon Sep 17 00:00:00 2001 From: Richard Griffiths Date: Wed, 23 Jun 2021 16:13:07 +0200 Subject: [PATCH 6/6] Version bump --- mod.json | 2 +- src/MissionControl.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mod.json b/mod.json index 09e86ed8..a4a7c973 100644 --- a/mod.json +++ b/mod.json @@ -1,7 +1,7 @@ { "Name": "Mission Control", "Enabled": true, - "Version": "1.2.0", + "Version": "1.2.1", "Description": "A HBS BattleTech mod that adds custom contract types and varies the encounter specifics such as encounter boundary size, spawn locations, lance numbers and objectives", "Author": "CWolf", "Contact": "cwolfs@gmail.com", diff --git a/src/MissionControl.csproj b/src/MissionControl.csproj index a47df4eb..95bfb0c0 100644 --- a/src/MissionControl.csproj +++ b/src/MissionControl.csproj @@ -1,6 +1,6 @@ - 1.2.0 + 1.2.1 Library net471