Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions TLM/TLM/Lifecycle/TMPELifecycle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace TrafficManager.Lifecycle {
using UnityEngine;
using JetBrains.Annotations;
using UI.WhatsNew;
using System.Diagnostics.CodeAnalysis;

/// <summary>
/// Do not use Singleton<TMPELifecycle>.instance to prevent memory leak.
Expand All @@ -32,6 +33,9 @@ public static TMPELifecycle Instance {

public IDisposable GeometryNotifierDisposable;

/// <summary>Cached value of <see cref="LauncherLoginData.instance.m_continue"/>.</summary>
private static bool cache_m_continue;

/// <summary>TMPE is in the middle of deserializing data.</summary>
public bool Deserializing { get; set; }

Expand Down Expand Up @@ -72,10 +76,42 @@ internal static bool PlayMode {
}
}

/// <summary>Resumes PDX launcher auto-load of last city if necessary.</summary>
[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<MainMenu>();
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() {
Expand Down Expand Up @@ -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.
}
Expand Down
8 changes: 6 additions & 2 deletions TLM/TLM/Util/ModsCompatibilityChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ public ModsCompatibilityChecker() {
}

/// <summary>
/// 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.
/// </summary>
public void PerformModCheck() {
/// <returns>Returns <c>false</c> if incompatible mods found (ie. mcc dialog shown).</returns>
public bool PerformModCheck() {
try {
Dictionary<PluginInfo, string> detected = ScanForIncompatibleMods();

Expand All @@ -46,13 +48,15 @@ public void PerformModCheck() {
panel.Initialize();
UIView.PushModal(panel);
UIView.SetFocus(panel);
return false;
}
}
catch (Exception e) {
Log.Info(
"Something went wrong while checking incompatible mods - see main game log for details.");
Debug.LogException(e);
}
return true;
}

/// <summary>
Expand Down
47 changes: 22 additions & 25 deletions TLM/TLM/Util/VersionUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -116,41 +116,38 @@ public static void LogMonoVersion() {
}
}

/// <summary>
/// Checks to see if game version is what TMPE expects, and if not warns users.
///
/// This will be replaced as part of #699.
/// </summary>
public static void CheckGameVersion() {
/// <summary>Checks to see if game version is what TMPE expects, and if not warns users.</summary>
/// <returns>Returns <c>false</c> if there is a game/mod version problem.</returns>
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;
}
}
}