public override void OnLevelUnloading() { Log.Info("OnLevelUnloading"); base.OnLevelUnloading(); if (Instance == null) { Instance = this; } revertDetours(); gameLoaded = false; try { TrafficPriority.OnLevelUnloading(); CustomCarAI.OnLevelUnloading(); CustomRoadAI.OnLevelUnloading(); CustomTrafficLights.OnLevelUnloading(); TrafficLightSimulation.OnLevelUnloading(); Flags.OnLevelUnloading(); Translation.OnLevelUnloading(); if (Instance != null) { Instance.NodeSimulationLoaded = false; } } catch (Exception e) { Log.Error("Exception unloading mod. " + e.Message); // ignored - prevents collision with other mods } }
public override void OnLevelUnloading() { Log.Info("OnLevelUnloading"); base.OnLevelUnloading(); Instance = this; revertDetours(); gameLoaded = false; Object.Destroy(UI); UI = null; try { TrafficPriority.OnLevelUnloading(); CustomCarAI.OnLevelUnloading(); CustomRoadAI.OnLevelUnloading(); CustomTrafficLights.OnLevelUnloading(); TrafficLightSimulation.OnLevelUnloading(); VehicleRestrictionsManager.OnLevelUnloading(); Flags.OnLevelUnloading(); Translation.OnLevelUnloading(); } catch (Exception e) { Log.Error("Exception unloading mod. " + e.Message); // ignored - prevents collision with other mods } }
public void OnDisabled() { Log.Info("TM:PE disabled."); LoadingManager.instance.m_introLoaded -= CheckForIncompatibleMods; LocaleManager.eventLocaleChanged -= Translation.HandleGameLocaleChange; Translation.IsListeningToGameLocaleChanged = false; // is this necessary? if (LoadingExtension.InGame() && LoadingExtension.Instance != null) { //Hot reload Unloading LoadingExtension.Instance.OnLevelUnloading(); LoadingExtension.Instance.OnReleased(); } }
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; } }
public override void OnCreated(ILoading loading) { Log._Debug("LoadingExtension.OnCreated() called"); // SelfDestruct.DestructOldInstances(this); base.OnCreated(loading); Detours = new List <Detour>(); RegisteredManagers = new List <ICustomManager>(); DetourInited = false; CustomPathManager = new CustomPathManager(); RegisterCustomManagers(); Instance = this; InGameHotReload = InGame(); }
public override void OnCreated(ILoading loading) { Log._Debug("LoadingExtension.OnCreated() called"); // 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; } RegisteredManagers = new List <ICustomManager>(); CustomPathManager = new CustomPathManager(); RegisterCustomManagers(); Instance = this; }
public override void OnCreated(ILoading loading) { base.OnCreated(loading); if (Instance == null) { Instance = this; } 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); }
public override void OnLevelUnloading() { base.OnLevelUnloading(); if (Instance == null) { Instance = this; } revertDetours(); try { TrafficPriority.OnLevelUnloading(); CustomCarAI.OnLevelUnloading(); TrafficLightsManual.OnLevelUnloading(); TrafficLightsTimed.OnLevelUnloading(); if (Instance != null) { Instance.NodeSimulationLoaded = false; } } catch (Exception e) { Log.Error("Exception unloading mod. " + e.Message); // ignored - prevents collision with other mods } }
public override void OnReleased() { Instance = null; base.OnReleased(); }
public override void OnLevelLoaded(LoadMode mode) { Debug.Log("OnLevelLoaded calling base method"); base.OnLevelLoaded(mode); Debug.Log("OnLevelLoaded Returned from base, calling custom code."); switch (mode) { case LoadMode.NewGame: OnNewGame(); break; case LoadMode.LoadGame: OnLoaded(); break; } if (mode == LoadMode.NewGame || mode == LoadMode.LoadGame) { if (Instance == null) { Debug.Log("Instance is NULL. Set Instance to this."); if (Singleton<PathManager>.instance.GetType() != typeof (PathManager)) { PathfinderIncompatibility = true; } Instance = this; } if (!PathfinderIncompatibility) { Debug.Log("Pathfinder Compatible. Setting up CustomPathManager and SimManager."); var pathManagerInstance = typeof (Singleton<PathManager>).GetField("sInstance", BindingFlags.Static | BindingFlags.NonPublic); var stockPathManager = PathManager.instance; CustomPathManager = stockPathManager.gameObject.AddComponent<CustomPathManager>(); CustomPathManager.UpdateWithPathManagerValues(stockPathManager); pathManagerInstance?.SetValue(null, CustomPathManager); var simManager = typeof (SimulationManager).GetField("m_managers", BindingFlags.Static | BindingFlags.NonPublic)? .GetValue(null) as FastList<ISimulationManager>; simManager?.Remove(stockPathManager); simManager?.Add(CustomPathManager); Object.Destroy(stockPathManager, 10f); } Debug.Log("Adding Controls to UI."); UI = ToolsModifierControl.toolController.gameObject.AddComponent<UIBase>(); TrafficPriority.LeftHandDrive = Singleton<SimulationManager>.instance.m_metaData.m_invertTraffic == SimulationMetaData.MetaBool.True; } }
public override void OnReleased() { TrafficManagerMod.Instance.InGameHotReload = false; Instance = null; base.OnReleased(); }
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 OnLevelUnloading() { Log.Info("OnLevelUnloading"); base.OnLevelUnloading(); if (Instance == null) Instance = this; revertDetours(); gameLoaded = false; try { TrafficPriority.OnLevelUnloading(); CustomCarAI.OnLevelUnloading(); CustomRoadAI.OnLevelUnloading(); CustomTrafficLights.OnLevelUnloading(); TrafficLightSimulation.OnLevelUnloading(); Flags.OnLevelUnloading(); Translation.OnLevelUnloading(); if (Instance != null) Instance.NodeSimulationLoaded = false; } catch (Exception e) { Log.Error("Exception unloading mod. " + e.Message); // ignored - prevents collision with other mods } }
public override void OnLevelLoaded(LoadMode mode) { Log.Info("OnLevelLoaded"); 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.Info("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); Log._Debug("Should be custom: " + Singleton <PathManager> .instance.GetType().ToString()); IsPathManagerReplaced = true; } catch (Exception ex) { Log.Error($"Path manager replacement error: {ex.ToString()}"); 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.Info("Adding Controls to UI."); UI = ToolsModifierControl.toolController.gameObject.AddComponent <UIBase>(); initDetours(); Log.Info("OnLevelLoaded complete."); #endif }
public override void OnLevelLoaded(LoadMode mode) { Log.Warning("OnLevelLoaded calling base method"); base.OnLevelLoaded(mode); Log.Message("OnLevelLoaded Returned from base, calling custom code."); switch (mode) { case LoadMode.NewGame: OnNewGame(); break; case LoadMode.LoadGame: OnLoaded(); break; } if (mode == LoadMode.NewGame || mode == LoadMode.LoadGame) { determinePathManagerCompatible(); Instance = this; initDetours(); if (IsPathManagerCompatible && !PathManagerReplaced) { Log.Warning("#####################################"); Log.Message("Pathfinder Compatible. Setting up CustomPathManager and SimManager."); var pathManagerInstance = typeof(Singleton <PathManager>).GetField("sInstance", BindingFlags.Static | BindingFlags.NonPublic); var stockPathManager = PathManager.instance; Log.Message($"Got stock PathManager instance {stockPathManager.GetName()}"); CustomPathManager = stockPathManager.gameObject.AddComponent <CustomPathManager>(); Log.Message("Added CustomPathManager to gameObject List"); if (CustomPathManager == null) { Log.Error("CustomPathManager null. Error creating it."); return; } CustomPathManager.UpdateWithPathManagerValues(stockPathManager); Log.Message("UpdateWithPathManagerValues success"); pathManagerInstance?.SetValue(null, CustomPathManager); Log.Message("Getting Current SimulationManager"); var simManager = typeof(SimulationManager).GetField("m_managers", BindingFlags.Static | BindingFlags.NonPublic)? .GetValue(null) as FastList <ISimulationManager>; Log.Message("Removing Stock PathManager"); simManager?.Remove(stockPathManager); Log.Message("Adding Custom PathManager"); simManager?.Add(CustomPathManager); Object.Destroy(stockPathManager, 10f); PathManagerReplaced = true; } Log.Message("Adding Controls to UI."); UI = ToolsModifierControl.toolController.gameObject.AddComponent <UIBase>(); TrafficPriority.LeftHandDrive = Singleton <SimulationManager> .instance.m_metaData.m_invertTraffic == SimulationMetaData.MetaBool.True; } }
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; } }