public override void OnLevelLoaded(LoadMode mode) {
Log._Debug("OnLevelLoaded calling base method");
base.OnLevelLoaded(mode);
Log._Debug("OnLevelLoaded Returned from base, calling custom code.");
Instance = this;
gameLoaded = false;
switch (mode) {
case LoadMode.NewGame:
case LoadMode.LoadGame:
gameLoaded = true;
break;
default:
return;
}
TrafficPriority.OnLevelLoading();
#if !TAM
determinePathManagerCompatible();
//SpeedLimitManager.GetDefaultSpeedLimits();
if (IsPathManagerCompatible && ! IsPathManagerReplaced) {
try {
Log._Debug("Pathfinder Compatible. Setting up CustomPathManager and SimManager.");
var pathManagerInstance = typeof(Singleton<PathManager>).GetField("sInstance", BindingFlags.Static | BindingFlags.NonPublic);
var stockPathManager = PathManager.instance;
Log._Debug($"Got stock PathManager instance {stockPathManager.GetName()}");
CustomPathManager = stockPathManager.gameObject.AddComponent<CustomPathManager>();
Log._Debug("Added CustomPathManager to gameObject List");
if (CustomPathManager == null) {
Log.Error("CustomPathManager null. Error creating it.");
return;
}
CustomPathManager.UpdateWithPathManagerValues(stockPathManager);
Log._Debug("UpdateWithPathManagerValues success");
pathManagerInstance?.SetValue(null, CustomPathManager);
Log._Debug("Getting Current SimulationManager");
var simManager =
typeof(SimulationManager).GetField("m_managers", BindingFlags.Static | BindingFlags.NonPublic)?
.GetValue(null) as FastList<ISimulationManager>;
Log._Debug("Removing Stock PathManager");
simManager?.Remove(stockPathManager);
Log._Debug("Adding Custom PathManager");
simManager?.Add(CustomPathManager);
Object.Destroy(stockPathManager, 10f);
IsPathManagerReplaced = true;
} catch (Exception) {
UIView.library.ShowModal<ExceptionPanel>("ExceptionPanel").SetMessage("Incompatibility Issue", "Traffic Manager: President Edition detected an incompatibility with another mod! You can continue playing but it's NOT recommended. Traffic Manager will not work as expected.", true);
IsPathManagerCompatible = false;
}
}
Log._Debug("Adding Controls to UI.");
UI = ToolsModifierControl.toolController.gameObject.AddComponent<UIBase>();
initDetours();
#endif
}