From 85dbc146e690b3c6b3f89b3ed887c7eb67ff9d72 Mon Sep 17 00:00:00 2001 From: Richard Griffiths Date: Tue, 28 Jul 2020 18:58:22 +0200 Subject: [PATCH 1/5] Fixed save fix causing problems in mechlab & broken skirmish --- src/Core/MissionControl.cs | 20 ++++++++++++------- src/Patches/ContractBeginPatch.cs | 2 -- ...nterLayerParentInitFromSavePassOnePatch.cs | 12 ----------- 3 files changed, 13 insertions(+), 21 deletions(-) delete mode 100644 src/Patches/SaveSupport/EncounterLayerParentInitFromSavePassOnePatch.cs diff --git a/src/Core/MissionControl.cs b/src/Core/MissionControl.cs index 245cea18..48b3cc59 100644 --- a/src/Core/MissionControl.cs +++ b/src/Core/MissionControl.cs @@ -54,7 +54,7 @@ public static MissionControl Instance { public bool IsContractValid { get; private set; } = false; public bool IsMCLoadingFinished { get; set; } = false; - public bool IsLoadingFromSave { get; set; } = false; + public bool IsLoadingFromSave { get => UnityGameInstance.Instance.Game.Combat.IsLoadingFromSave; } private Dictionary> AvailableEncounters = new Dictionary>(); @@ -247,14 +247,18 @@ public void SetActiveAdditionalLances(Contract contract) { } public void SetContractSettingsOverride() { - string contractId = CurrentContract.Override.ID; - string type = IsAnyFlashpointContract() ? "flashpoint" : "contract"; + if (!IsSkirmish(CurrentContract)) { + string contractId = CurrentContract.Override.ID; + string type = IsAnyFlashpointContract() ? "flashpoint" : "contract"; - 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]; + 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]; + } else { + Main.Logger.Log($"[MissionControl] No {type} MC settings override found for '{contractId}'."); + Main.Settings.ActiveContractSettings = new Config.ContractSettingsOverrides(); + } } else { - Main.Logger.Log($"[MissionControl] No {type} MC settings override found for '{contractId}'."); Main.Settings.ActiveContractSettings = new Config.ContractSettingsOverrides(); } } @@ -464,6 +468,8 @@ public FactionDef GetFactionFromTeamType(string teamType) { } public bool AllowMissionControl() { + if (CurrentContract == null) return false; + if (IsLoadingFromSave) return false; if (CurrentContract.IsStoryContract) return false; if (CurrentContract.IsRestorationContract) return false; diff --git a/src/Patches/ContractBeginPatch.cs b/src/Patches/ContractBeginPatch.cs index 1a49be67..6c4dc320 100644 --- a/src/Patches/ContractBeginPatch.cs +++ b/src/Patches/ContractBeginPatch.cs @@ -13,8 +13,6 @@ namespace MissionControl.Patches { public class ContractBeginPatch { public static void Prefix(Contract __instance) { if (!__instance.Accepted) return; - MissionControl.Instance.IsLoadingFromSave = UnityGameInstance.Instance.Game.Combat.IsLoadingFromSave; - PathFinderManager.Instance.FullReset(); Main.Logger.Log($"[ContractBeginPatch Postfix] Patching Begin"); diff --git a/src/Patches/SaveSupport/EncounterLayerParentInitFromSavePassOnePatch.cs b/src/Patches/SaveSupport/EncounterLayerParentInitFromSavePassOnePatch.cs deleted file mode 100644 index 47eb9f73..00000000 --- a/src/Patches/SaveSupport/EncounterLayerParentInitFromSavePassOnePatch.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Harmony; - -using BattleTech; - -namespace MissionControl.Patches { - [HarmonyPatch(typeof(EncounterLayerParent), "InitFromSavePassOne")] - public class EncounterLayerParentInitFromSavePassOnePatch { - public static void Prefix(EncounterLayerParent __instance) { - MissionControl.Instance.IsLoadingFromSave = true; - } - } -} \ No newline at end of file From 7bb2f7bd3284b4348be523fd5793bc4e61c480b9 Mon Sep 17 00:00:00 2001 From: Richard Griffiths Date: Tue, 28 Jul 2020 18:58:46 +0200 Subject: [PATCH 2/5] 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 5b5daf1e..8ed72f90 100644 --- a/mod.json +++ b/mod.json @@ -1,7 +1,7 @@ { "Name": "Mission Control", "Enabled": true, - "Version": "1.1.1", + "Version": "1.1.2", "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 13904929..ca4c5e66 100644 --- a/src/MissionControl.csproj +++ b/src/MissionControl.csproj @@ -1,6 +1,6 @@ - 1.1.1 + 1.1.2 Library net471 From 2bca45f860125391b6ae367b49ee1d0f870282c9 Mon Sep 17 00:00:00 2001 From: Richard Griffiths Date: Tue, 28 Jul 2020 21:59:12 +0200 Subject: [PATCH 3/5] Better fix for mechbay being broken --- src/Core/MissionControl.cs | 8 ++++++-- .../AssetBundleManagerGetAssetFromBundlePatch.cs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Core/MissionControl.cs b/src/Core/MissionControl.cs index 48b3cc59..1b73f3df 100644 --- a/src/Core/MissionControl.cs +++ b/src/Core/MissionControl.cs @@ -54,7 +54,12 @@ public static MissionControl Instance { public bool IsContractValid { get; private set; } = false; public bool IsMCLoadingFinished { get; set; } = false; - public bool IsLoadingFromSave { get => UnityGameInstance.Instance.Game.Combat.IsLoadingFromSave; } + public bool IsLoadingFromSave { + get { + if (UnityGameInstance.Instance.Game.Combat == null) return false; + return UnityGameInstance.Instance.Game.Combat.IsLoadingFromSave; + } + } private Dictionary> AvailableEncounters = new Dictionary>(); @@ -470,7 +475,6 @@ public FactionDef GetFactionFromTeamType(string teamType) { public bool AllowMissionControl() { if (CurrentContract == null) return false; - if (IsLoadingFromSave) return false; if (CurrentContract.IsStoryContract) return false; if (CurrentContract.IsRestorationContract) return false; if (!IsAnyFlashpointContract()) return true; diff --git a/src/Patches/SaveSupport/AssetBundleManagerGetAssetFromBundlePatch.cs b/src/Patches/SaveSupport/AssetBundleManagerGetAssetFromBundlePatch.cs index e063029a..18162828 100644 --- a/src/Patches/SaveSupport/AssetBundleManagerGetAssetFromBundlePatch.cs +++ b/src/Patches/SaveSupport/AssetBundleManagerGetAssetFromBundlePatch.cs @@ -31,7 +31,7 @@ private static bool IsIgnoredBundle(string bundleName) { } public static void Postfix(AssetBundleManager __instance, string assetName, string bundleName, ref GameObject __result) { - if (MissionControl.Instance.AllowMissionControl() && !IsIgnoredBundle(bundleName)) { + if (MissionControl.Instance.IsLoadingFromSave && MissionControl.Instance.AllowMissionControl() && !IsIgnoredBundle(bundleName)) { if (__result == null) { Main.LogDebug($"[AssetBundleManagerGetAssetFromBundlePatch Postfix] Final stage of trying to load an asset bundle. Attempted to recovery before critical failure."); if (lookup.ContainsKey(assetName)) { From 8c370f945588ddd6eb167d5e13e2a7f899aa8fb5 Mon Sep 17 00:00:00 2001 From: Richard Griffiths Date: Wed, 29 Jul 2020 09:46:12 +0200 Subject: [PATCH 4/5] Returned behaviour to disable MC on loading of a save --- src/Core/MissionControl.cs | 6 +++++- .../AssetBundleManagerGetAssetFromBundlePatch.cs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Core/MissionControl.cs b/src/Core/MissionControl.cs index 1b73f3df..9793d26a 100644 --- a/src/Core/MissionControl.cs +++ b/src/Core/MissionControl.cs @@ -472,9 +472,13 @@ public FactionDef GetFactionFromTeamType(string teamType) { return null; } - public bool AllowMissionControl() { + public bool AllowMissionControl(bool SkipFromSaveCheck = false) { if (CurrentContract == null) return false; + if (!SkipFromSaveCheck) { + if (IsLoadingFromSave) return false; + } + if (CurrentContract.IsStoryContract) return false; if (CurrentContract.IsRestorationContract) return false; if (!IsAnyFlashpointContract()) return true; diff --git a/src/Patches/SaveSupport/AssetBundleManagerGetAssetFromBundlePatch.cs b/src/Patches/SaveSupport/AssetBundleManagerGetAssetFromBundlePatch.cs index 18162828..b6e1cda6 100644 --- a/src/Patches/SaveSupport/AssetBundleManagerGetAssetFromBundlePatch.cs +++ b/src/Patches/SaveSupport/AssetBundleManagerGetAssetFromBundlePatch.cs @@ -31,7 +31,7 @@ private static bool IsIgnoredBundle(string bundleName) { } public static void Postfix(AssetBundleManager __instance, string assetName, string bundleName, ref GameObject __result) { - if (MissionControl.Instance.IsLoadingFromSave && MissionControl.Instance.AllowMissionControl() && !IsIgnoredBundle(bundleName)) { + if (MissionControl.Instance.IsLoadingFromSave && MissionControl.Instance.AllowMissionControl(SkipFromSaveCheck: true) && !IsIgnoredBundle(bundleName)) { if (__result == null) { Main.LogDebug($"[AssetBundleManagerGetAssetFromBundlePatch Postfix] Final stage of trying to load an asset bundle. Attempted to recovery before critical failure."); if (lookup.ContainsKey(assetName)) { From 4e954698fed5a5694e1dc28683ddeae02955eb4e Mon Sep 17 00:00:00 2001 From: Richard Griffiths Date: Wed, 29 Jul 2020 16:33:46 +0200 Subject: [PATCH 5/5] Fix save load bug --- src/Core/Data/LogicState.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core/Data/LogicState.cs b/src/Core/Data/LogicState.cs index 2533cf8b..b9ea772e 100644 --- a/src/Core/Data/LogicState.cs +++ b/src/Core/Data/LogicState.cs @@ -10,11 +10,11 @@ public void Set(string key, bool flag) { } public void Set(string key, List keys) { - objectState.Add(key, keys); + objectState[key] = keys; } public void Set(string key, List keys) { - objectState.Add(key, keys); + objectState[key] = keys; } public bool GetBool(string key) {