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 }
public override void OnLevelLoaded(LoadMode mode) { base.OnLevelLoaded(mode); switch (mode) { case LoadMode.NewGame: OnNewGame(); break; case LoadMode.LoadGame: OnLoaded(); break; default: break; } if (mode == LoadMode.NewGame || mode == LoadMode.LoadGame) { if (Instance == null) { if (Singleton<PathManager>.instance.GetType() != typeof(PathManager)) { LoadingExtension.PathfinderIncompatibility = true; } Instance = this; } if (!LoadingExtension.PathfinderIncompatibility) { FieldInfo pathManagerInstance = typeof(Singleton<PathManager>).GetField("sInstance", BindingFlags.Static | BindingFlags.NonPublic); PathManager stockPathManager = PathManager.instance; customPathManager = stockPathManager.gameObject.AddComponent<CustomPathManager>(); customPathManager.UpdateWithPathManagerValues(stockPathManager); pathManagerInstance.SetValue(null, customPathManager); FastList<ISimulationManager> managers = typeof(SimulationManager).GetField("m_managers", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as FastList<ISimulationManager>; managers.Remove(stockPathManager); managers.Add(customPathManager); GameObject.Destroy(stockPathManager, 10f); } UI = ToolsModifierControl.toolController.gameObject.AddComponent<UIBase>(); TrafficPriority.leftHandDrive = Singleton<SimulationManager>.instance.m_metaData.m_invertTraffic == SimulationMetaData.MetaBool.True; } }