Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
19 changes: 5 additions & 14 deletions TLM/TLM/LoadingExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,10 @@ public class LoadingExtension : LoadingExtensionBase {
private const string HARMONY_ID = "de.viathinksoft.tmpe";
internal static LoadingExtension Instance = null;

internal bool InGameHotReload { get; private set; } = false;

internal static AppMode currentMode => SimulationManager.instance.m_ManagersWrapper.loading.currentMode;

internal static bool InGame() {
try {
return currentMode == AppMode.Game;
} catch {
return false;
}
}

FastList<ISimulationManager> simManager =>
typeof(SimulationManager).GetField("m_managers", BindingFlags.Static | BindingFlags.NonPublic)
?.GetValue(null) as FastList<ISimulationManager>;


public class Detour {
public MethodInfo OriginalMethod;
public MethodInfo CustomMethod;
Expand Down Expand Up @@ -275,6 +262,11 @@ public override void OnCreated(ILoading loading) {

// SelfDestruct.DestructOldInstances(this);
base.OnCreated(loading);
if(IsGameLoaded) {
// When another mod is detected, OnCreated is called again for god - or CS team - knows what reason!
Log._Debug("Hot reload of another mod detected. Skipping LoadingExtension.OnCreated() ...");
return;
}

Detours = new List<Detour>();
RegisteredManagers = new List<ICustomManager>();
Expand All @@ -284,7 +276,6 @@ public override void OnCreated(ILoading loading) {
RegisterCustomManagers();

Instance = this;
InGameHotReload = InGame();
}

private void RegisterCustomManagers() {
Expand Down
9 changes: 6 additions & 3 deletions TLM/TLM/State/SerializableDataExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ public class SerializableDataExtension
public static bool StateLoading;

public override void OnCreated(ISerializableData serializableData) {
_serializableData = serializableData;

Log._Debug("SerializableDataExtension.OnCreated() called");
if(LoadingExtension.IsGameLoaded) {
Log._Debug("Hot reload of another mod detected. Skipping SerializableDataExtension.OnCreated() ...");
return;
}
_serializableData = serializableData;

if (LoadingExtension.Instance.InGameHotReload) {
if (TrafficManagerMod.Instance.InGameHotReload) {
Log._Debug("HOT RELOAD ...");
OnLoadData();
LoadingExtension.Instance.OnLevelLoaded(LoadMode.LoadGame);
Expand Down
13 changes: 12 additions & 1 deletion TLM/TLM/TrafficManagerMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace TrafficManager {
using TrafficManager.Util;
using static TrafficManager.Util.Shortcuts;
using ColossalFramework;
using UnityEngine.SceneManagement;

public class TrafficManagerMod : IUserMod {
#if LABS
Expand Down Expand Up @@ -41,6 +42,12 @@ public class TrafficManagerMod : IUserMod {

public string Description => "Manage your city's traffic";

internal static TrafficManagerMod Instance = null;

internal bool InGameHotReload { get; private set; } = false;

internal static bool InGame() => SceneManager.GetActiveScene().name == "Game";

[UsedImplicitly]
public void OnEnabled() {
Log.InfoFormat(
Expand Down Expand Up @@ -75,6 +82,9 @@ public void OnEnabled() {
Log.InfoFormat("Mono version: {0}", displayName.Invoke(null, null));
}
}

Instance = this;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this getting used exaclty? When I look at the code in VS2019, it's not showing any references to it.

I can see down on line 110 (in updated TrafficManagerMod.cs) that it gets set to null in the OnDisabled() method, but other than that it's not getting used.

Was it supposed to be referenced in line 105 in the OnDisabled() method?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see
TLM/TLM/State/SerializableDataExtension.cs :29
VersionLabel.cs :14

InGameHotReload = InGame();
}

[UsedImplicitly]
Expand All @@ -84,11 +94,12 @@ public void OnDisabled() {
LocaleManager.eventLocaleChanged -= Translation.HandleGameLocaleChange;
Translation.IsListeningToGameLocaleChanged = false; // is this necessary?

if (LoadingExtension.InGame() && LoadingExtension.Instance != null) {
if (InGame() && LoadingExtension.Instance != null) {
//Hot reload Unloading
LoadingExtension.Instance.OnLevelUnloading();
LoadingExtension.Instance.OnReleased();
}
Instance = null;
}

[UsedImplicitly]
Expand Down
2 changes: 1 addition & 1 deletion TLM/TLM/UI/MainMenu/VersionLabel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public override void Start() {
MainMenuPanel.ScaledSize.GetTitlebarHeight());
text = TrafficManagerMod.ModName;

if(LoadingExtension.Instance.InGameHotReload) {
if(TrafficManagerMod.Instance.InGameHotReload) {
// make it easier to Identify Hot reload.
text += " HOT RELOAD " +
Assembly.GetExecutingAssembly().GetName().Version;
Expand Down