From 33dbdb7d32f27d792d504647fb3fb3360e2ce38e Mon Sep 17 00:00:00 2001 From: giang6996 Date: Wed, 21 Jan 2026 16:02:57 +0700 Subject: [PATCH] Fix career mode unlock immediately --- MechJeb2/ComputerModule.cs | 83 +++-- MechJeb2/DisplayModule.cs | 2 +- MechJeb2/MechJeb2.csproj | 543 +++++++++++++++-------------- MechJeb2/packages.config | 6 + MechJebLibBindings/packages.config | 5 + alglib/packages.config | 5 + 6 files changed, 338 insertions(+), 306 deletions(-) create mode 100644 MechJeb2/packages.config create mode 100644 MechJebLibBindings/packages.config create mode 100644 alglib/packages.config diff --git a/MechJeb2/ComputerModule.cs b/MechJeb2/ComputerModule.cs index ef57605ad..6534bbcda 100644 --- a/MechJeb2/ComputerModule.cs +++ b/MechJeb2/ComputerModule.cs @@ -14,9 +14,9 @@ public class ComputerModule : IComparable public readonly MechJebCore Core; //conveniences: - public Vessel Vessel => Part.vessel; - public CelestialBody MainBody => Part.vessel.mainBody; - public VesselState VesselState => Core.VesselState; + public Vessel Vessel => Part.vessel; + public CelestialBody MainBody => Part.vessel.mainBody; + public VesselState VesselState => Core.VesselState; [UsedImplicitly] public Part Part => Core.part; @@ -29,11 +29,11 @@ public class ComputerModule : IComparable [UsedImplicitly] [Persistent(pass = (int)Pass.LOCAL)] - public readonly string UnlockParts = ""; + public string unlockParts = ""; [UsedImplicitly] [Persistent(pass = (int)Pass.LOCAL)] - public readonly string UnlockTechs = ""; + public string unlockTechs = ""; public bool UnlockChecked; @@ -48,7 +48,7 @@ public bool Enabled { if (value == _enabled) return; - Dirty = true; + Dirty = true; _enabled = value; if (_enabled) @@ -79,7 +79,7 @@ public bool Enabled protected ComputerModule(MechJebCore core) { - Core = core; + Core = core; ProfilerName = GetType().Name; Users = new UserPool(this); @@ -190,50 +190,65 @@ public virtual void UnlockCheck() { if (UnlockChecked) return; + // Bypass check for Sandbox mode + if (HighLogic.CurrentGame != null && HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX) + { + UnlockChecked = true; + return; + } + + if (ResearchAndDevelopment.Instance == null) return; + bool unlock = true; - if (ResearchAndDevelopment.Instance != null) + string[] parts = unlockParts.Split(new[] { ' ', ',', ';', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + if (parts.Length > 0) { - string[] parts = UnlockParts.Split(new[] { ' ', ',', ';', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); - if (parts.Length > 0) + unlock = false; + foreach (string p in parts) { - unlock = false; - foreach (string p in parts) + if (PartLoader.LoadedPartsList.Count(a => a.name == p) > 0 && + ResearchAndDevelopment.PartModelPurchased(PartLoader.LoadedPartsList.First(a => a.name == p))) { - if (PartLoader.LoadedPartsList.Count(a => a.name == p) > 0 && - ResearchAndDevelopment.PartModelPurchased(PartLoader.LoadedPartsList.First(a => a.name == p))) - { - unlock = true; - break; - } + unlock = true; + break; } } + } - string[] techs = UnlockTechs.Split(new[] { ' ', ',', ';', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); - if (techs.Length > 0) + string[] techs = unlockTechs.Split(new[] { ' ', ',', ';', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + if (techs.Length > 0) + { + if (parts.Length == 0) { - if (parts.Length == 0) - { - unlock = false; - } + unlock = false; + } - foreach (string t in techs) + foreach (string t in techs) + { + if (ResearchAndDevelopment.GetTechnologyState(t) == RDTech.State.Available) { - if (ResearchAndDevelopment.GetTechnologyState(t) == RDTech.State.Available) - { - unlock = true; - break; - } + unlock = true; + break; } } } unlock = unlock && IsSpaceCenterUpgradeUnlocked(); + // Debug start + + Debug.Log($"[MechJeb2] UnlockCheck {GetType().Name}: unlock={unlock}, " + + $"mode={HighLogic.CurrentGame?.Mode}, " + + $"RnD={(ResearchAndDevelopment.Instance != null)}, " + + $"unlockTechs='{unlockTechs}', unlockParts='{unlockParts}'"); + + // End of debug UnlockChecked = true; + if (!unlock) { - Enabled = false; + Enabled = false; Core.someModuleAreLocked = true; } } @@ -252,8 +267,8 @@ public virtual void UnlockCheck() [Flags] public enum Pass { - LOCAL = 1, - TYPE = 2, + LOCAL = 1, + TYPE = 2, GLOBAL = 4 } @@ -261,7 +276,7 @@ public class ModuleEvent { public delegate void OnEvent(); - private readonly List _events = new List(); + private readonly List _events = new List(); private readonly Dictionary _eventIndex = new Dictionary(); public void Add(OnEvent evt) diff --git a/MechJeb2/DisplayModule.cs b/MechJeb2/DisplayModule.cs index ece5a3870..7bb4935a6 100644 --- a/MechJeb2/DisplayModule.cs +++ b/MechJeb2/DisplayModule.cs @@ -295,7 +295,7 @@ public override void UnlockCheck() bool prevEn = Enabled; Enabled = true; base.UnlockCheck(); - if (UnlockParts.Trim().Length > 0 || UnlockTechs.Trim().Length > 0 || !IsSpaceCenterUpgradeUnlocked()) + if (unlockParts.Trim().Length > 0 || unlockTechs.Trim().Length > 0 || !IsSpaceCenterUpgradeUnlocked()) { Hidden = !Enabled; if (Hidden) diff --git a/MechJeb2/MechJeb2.csproj b/MechJeb2/MechJeb2.csproj index f4e45b97f..ef3806ea6 100644 --- a/MechJeb2/MechJeb2.csproj +++ b/MechJeb2/MechJeb2.csproj @@ -1,279 +1,280 @@  - - - Debug - AnyCPU - {9FC90AE6-C2E4-47F1-A6D1-DB4731A40BE3} - Library - Properties - MuMech - MechJeb2 - v4.8 - true - 512 - - - - 8 - - - true - portable - false - bin\Debug\ - TRACE;DEBUG;ENABLE_PROFILER;UNITY_2017_1 - prompt - 4 - false - false - - - None - True - bin\Release\ - TRACE;UNITY_2017_1 - prompt - 4 - AnyCPU - false - MechJeb2.ruleset - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - False - False - - - False - False - - - ..\packages\JetBrains.Annotations.2023.3.0\lib\net20\JetBrains.Annotations.dll - JetBrainsAnnotations - - - - - - - - - False - False - - - False - False - - - False - False - - - False - False - - - False - False - - - False - False - - - False - False - - - False - False - - - False - False - - - False - False - - - False - False - - - - - {e8cbcddd-bcfc-4f03-9309-f58395ca4762} - alglib - - - {da770208-1300-4c86-8996-c1790b945999} - MechJebLibBindings - - - {ba86665b-a72e-41fb-858a-c0ff29e05768} - MechJebLib - - - - - - - - - - - + \ No newline at end of file diff --git a/MechJeb2/packages.config b/MechJeb2/packages.config new file mode 100644 index 000000000..10cb0f3e4 --- /dev/null +++ b/MechJeb2/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MechJebLibBindings/packages.config b/MechJebLibBindings/packages.config new file mode 100644 index 000000000..a775de190 --- /dev/null +++ b/MechJebLibBindings/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/alglib/packages.config b/alglib/packages.config new file mode 100644 index 000000000..a775de190 --- /dev/null +++ b/alglib/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file