diff --git a/TLM/TLM/Lifecycle/TMPELifecycle.cs b/TLM/TLM/Lifecycle/TMPELifecycle.cs index 38f4369e1..f1b58c0c9 100644 --- a/TLM/TLM/Lifecycle/TMPELifecycle.cs +++ b/TLM/TLM/Lifecycle/TMPELifecycle.cs @@ -18,6 +18,7 @@ namespace TrafficManager.Lifecycle { using UnityEngine; using JetBrains.Annotations; using UI.WhatsNew; + using System.Diagnostics.CodeAnalysis; /// /// Do not use Singleton.instance to prevent memory leak. @@ -32,6 +33,9 @@ public static TMPELifecycle Instance { public IDisposable GeometryNotifierDisposable; + /// Cached value of . + private static bool cache_m_continue; + /// TMPE is in the middle of deserializing data. public bool Deserializing { get; set; } @@ -72,10 +76,42 @@ internal static bool PlayMode { } } + /// Resumes PDX launcher auto-load of last city if necessary. + [SuppressMessage("Type Safety", "UNT0016:Unsafe way to get the method name", Justification = "Using same code as C:SL.")] + private static void AutoResumeLastCityIfNecessary() { + if (!cache_m_continue) { + return; + } + + cache_m_continue = false; + + if (InGameOrEditor()) { + return; + } + + try { + MainMenu menu = FindObjectOfType(); + if (menu != null) { + // code from global::MainMenu.Refresh() game code + menu.m_BackgroundImage.zOrder = int.MaxValue; + menu.Invoke("AutoContinue", 2.5f); + } + } + catch (Exception e) { + Log.ErrorFormat("Resume AutoContinue Failed:\n{0}", e.ToString()); + } + } + private static void CompatibilityCheck() { + bool success = true; + ModsCompatibilityChecker mcc = new ModsCompatibilityChecker(); - mcc.PerformModCheck(); - VersionUtil.CheckGameVersion(); + success &= mcc.PerformModCheck(); + success &= VersionUtil.CheckGameVersion(); + + if (success) { + AutoResumeLastCityIfNecessary(); + } } internal void Preload() { @@ -194,6 +230,11 @@ void OnDestroy() { #endif internal static void StartMod() { + // Prevent launcher auto-resume now, because we can't do it later + // If `CompatibilityCheck()` passes, we'll invoke `AutoResumeLastCityIfNecessary()` + cache_m_continue = LauncherLoginData.instance.m_continue; + LauncherLoginData.instance.m_continue = false; + var go = new GameObject(nameof(TMPELifecycle), typeof(TMPELifecycle)); DontDestroyOnLoad(go); // don't destroy when scene changes. } diff --git a/TLM/TLM/Util/ModsCompatibilityChecker.cs b/TLM/TLM/Util/ModsCompatibilityChecker.cs index c5b77a1fa..c7b48eebf 100644 --- a/TLM/TLM/Util/ModsCompatibilityChecker.cs +++ b/TLM/TLM/Util/ModsCompatibilityChecker.cs @@ -32,9 +32,11 @@ public ModsCompatibilityChecker() { } /// - /// Initiates scan for incompatible mods. If any found, and the user has enabled the mod checker, it creates and initialises the modal dialog panel. + /// Initiates scan for incompatible mods. If any found, and the user has enabled the mod checker, + /// it creates and initialises the modal dialog panel. /// - public void PerformModCheck() { + /// Returns false if incompatible mods found (ie. mcc dialog shown). + public bool PerformModCheck() { try { Dictionary detected = ScanForIncompatibleMods(); @@ -46,6 +48,7 @@ public void PerformModCheck() { panel.Initialize(); UIView.PushModal(panel); UIView.SetFocus(panel); + return false; } } catch (Exception e) { @@ -53,6 +56,7 @@ public void PerformModCheck() { "Something went wrong while checking incompatible mods - see main game log for details."); Debug.LogException(e); } + return true; } /// diff --git a/TLM/TLM/Util/VersionUtil.cs b/TLM/TLM/Util/VersionUtil.cs index 7b949f242..e2b5ed611 100644 --- a/TLM/TLM/Util/VersionUtil.cs +++ b/TLM/TLM/Util/VersionUtil.cs @@ -29,10 +29,10 @@ public static class VersionUtil { // we could alternatively use BuildConfig.APPLICATION_VERSION because const values are evaluated at compile time. // but I have decided not to do this because I don't want this to happen automatically with a rebuild if // CS updates. these values should be changed manaually so as to force us to acknowledge that they have changed. - public const uint EXPECTED_GAME_VERSION_U = 189262096U; + public const uint EXPECTED_GAME_VERSION_U = 193061904u; // see comments for EXPECTED_GAME_VERSION_U. - public static Version ExpectedGameVersion => new Version(1, 13, 3, 9); + public static Version ExpectedGameVersion => new Version(1, 14, 0, 4); public static string ExpectedGameVersionString => BuildConfig.VersionToString(EXPECTED_GAME_VERSION_U, false); @@ -116,41 +116,38 @@ public static void LogMonoVersion() { } } - /// - /// Checks to see if game version is what TMPE expects, and if not warns users. - /// - /// This will be replaced as part of #699. - /// - public static void CheckGameVersion() { + /// Checks to see if game version is what TMPE expects, and if not warns users. + /// Returns false if there is a game/mod version problem. + public static bool CheckGameVersion() { if (CurrentGameVersionU != EXPECTED_GAME_VERSION_U) { Log.Info($"Detected game version v{BuildConfig.applicationVersion}. TMPE built for {ExpectedGameVersionString}"); Log._Debug($"CurrentGameVersion={CurrentGameVersion} ExpectedGameVersion={ExpectedGameVersion}"); Version current = CurrentGameVersion.Take(VERSION_COMPONENTS_COUNT); Version expected = ExpectedGameVersion.Take(VERSION_COMPONENTS_COUNT); - if (current < expected) { - // game too old - string msg = string.Format( - "Traffic Manager: President Edition detected that you are running " + - "a newer game version ({0}) than TM:PE has been built for ({1}). " + - "Please be aware that TM:PE has not been updated for the newest game " + - "version yet and thus it is very likely it will not work as expected.", - BuildConfig.applicationVersion, - ExpectedGameVersionString); - Log.Error(msg); - Shortcuts.ShowErrorDialog("TM:PE has not been updated yet", msg); - } else if (current > expected) { - // TMPE too old + if (current != expected) { string msg = string.Format( - "Traffic Manager: President Edition has been built for game version {0}. " + - "You are running game version {1}. Some features of TM:PE will not " + - "work with older game versions. Please let Steam update your game.", + "{0} is designed for Cities: Skylines {1}. However you are using Cities: " + + "Skylines {2} - this is likely to cause severe problems or crashes." + + "\n\n" + + "Please ensure you're using the right version of TM:PE for this version of " + + "Cities: Skylines before proceeding, or disable TM:PE until the problem is " + + "resolved. If you need help, contact us via Steam Workshop page or Discord chat.", + TrafficManagerMod.ModName, ExpectedGameVersionString, BuildConfig.applicationVersion); Log.Error(msg); - Shortcuts.ShowErrorDialog("Your game should be updated", msg); + + Shortcuts.ShowErrorDialog( + current > expected + ? "TM:PE needs updating!" + : "Cities: Skylines needs updating!", + msg); + + return false; } } + return true; } } } \ No newline at end of file