UpdateWithPathManagerValues() публичный Метод

public UpdateWithPathManagerValues ( PathManager stockPathManager ) : void
stockPathManager PathManager
Результат void
Пример #1
0
        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;
            }
        }
Пример #2
0
        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);
        }
Пример #3
0
        public override void OnLevelLoaded(LoadMode mode)
        {
            SimulationManager.UpdateMode updateMode = SimulationManager.instance.m_metaData.m_updateMode;
            Log.Info($"OnLevelLoaded({mode}) called. updateMode={updateMode}");
            base.OnLevelLoaded(mode);

            Log._Debug("OnLevelLoaded Returned from base, calling custom code.");

            IsGameLoaded = false;
            switch (updateMode)
            {
            case SimulationManager.UpdateMode.NewGameFromMap:
            case SimulationManager.UpdateMode.NewGameFromScenario:
            case SimulationManager.UpdateMode.LoadGame:
                if (BuildConfig.applicationVersion != BuildConfig.VersionToString(TrafficManagerMod.GameVersion, false))
                {
                    string[] majorVersionElms = BuildConfig.applicationVersion.Split('-');
                    string[] versionElms      = majorVersionElms[0].Split('.');
                    uint     versionA         = Convert.ToUInt32(versionElms[0]);
                    uint     versionB         = Convert.ToUInt32(versionElms[1]);
                    uint     versionC         = Convert.ToUInt32(versionElms[2]);

                    Log.Info($"Detected game version v{BuildConfig.applicationVersion}");

                    bool isModTooOld = TrafficManagerMod.GameVersionA < versionA ||
                                       (TrafficManagerMod.GameVersionA == versionA && TrafficManagerMod.GameVersionB < versionB) /* ||
                                                                                                                                  * (TrafficManagerMod.GameVersionA == versionA && TrafficManagerMod.GameVersionB == versionB && TrafficManagerMod.GameVersionC < versionC)*/;

                    bool isModNewer = TrafficManagerMod.GameVersionA < versionA ||
                                      (TrafficManagerMod.GameVersionA == versionA && TrafficManagerMod.GameVersionB > versionB) /* ||
                                                                                                                                 * (TrafficManagerMod.GameVersionA == versionA && TrafficManagerMod.GameVersionB == versionB && TrafficManagerMod.GameVersionC > versionC)*/;

                    if (isModTooOld)
                    {
                        string msg = $"Traffic Manager: President Edition detected that you are running a newer game version ({BuildConfig.applicationVersion}) than TM:PE has been built for ({BuildConfig.VersionToString(TrafficManagerMod.GameVersion, false)}). 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.";
                        Log.Error(msg);
                        Singleton <SimulationManager> .instance.m_ThreadingWrapper.QueueMainThread(() => {
                            UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("TM:PE has not been updated yet", msg, false);
                        });
                    }
                    else if (isModNewer)
                    {
                        string msg = $"Traffic Manager: President Edition has been built for game version {BuildConfig.VersionToString(TrafficManagerMod.GameVersion, false)}. You are running game version {BuildConfig.applicationVersion}. Some features of TM:PE will not work with older game versions. Please let Steam update your game.";
                        Log.Error(msg);
                        Singleton <SimulationManager> .instance.m_ThreadingWrapper.QueueMainThread(() => {
                            UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("Your game should be updated", msg, false);
                        });
                    }
                }
                IsGameLoaded = true;
                break;

            default:
                Log.Info($"OnLevelLoaded: Unsupported game mode {mode}");
                return;
            }

            if (!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) {
                    string error = "Traffic Manager: President Edition failed to load. You can continue playing but it's NOT recommended. Traffic Manager will not work as expected.";
                    Log.Error(error);
                    Log.Error($"Path manager replacement error: {ex.ToString()}");
                    Singleton <SimulationManager> .instance.m_ThreadingWrapper.QueueMainThread(() => {
                        UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage("TM:PE failed to load", error, true);
                    });
                }
            }

            Log.Info("Adding Controls to UI.");
            if (BaseUI == null)
            {
                Log._Debug("Adding UIBase instance.");
                BaseUI = ToolsModifierControl.toolController.gameObject.AddComponent <UIBase>();
            }

            // Init transport demand UI
            if (TransportDemandUI == null)
            {
                var uiView = UIView.GetAView();
                TransportDemandUI = (UITransportDemand)uiView.AddUIComponent(typeof(UITransportDemand));
            }

            // add "remove vehicle" button
            UIView.GetAView().gameObject.AddComponent <RemoveVehicleButtonExtender>();

            // add "remove citizen instance" button
            UIView.GetAView().gameObject.AddComponent <RemoveCitizenInstanceButtonExtender>();

            initDetours();

            //Log.Info("Fixing non-created nodes with problems...");
            //FixNonCreatedNodeProblems();

            Log.Info("Notifying managers...");
            foreach (ICustomManager manager in RegisteredManagers)
            {
                Log.Info($"OnLevelLoading: {manager.GetType().Name}");
                manager.OnLevelLoading();
            }

            //InitTool();
            //Log._Debug($"Current tool: {ToolManager.instance.m_properties.CurrentTool}");

            Log.Info("OnLevelLoaded complete.");
        }
Пример #4
0
        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)
        {
            SimulationManager.UpdateMode updateMode = SimulationManager.instance.m_metaData.m_updateMode;
            string scene = SceneManager.GetActiveScene().name;

            Log.Info($"OnLevelLoaded({mode}) called. updateMode={updateMode}, scene={scene}");

            if (scene == "ThemeEditor")
            {
                return;
            }

            IsGameLoaded = false;

            if (BuildConfig.applicationVersion != BuildConfig.VersionToString(
                    TrafficManagerMod.GAME_VERSION,
                    false))
            {
                string[] majorVersionElms = BuildConfig.applicationVersion.Split('-');
                string[] versionElms      = majorVersionElms[0].Split('.');
                uint     versionA         = Convert.ToUInt32(versionElms[0]);
                uint     versionB         = Convert.ToUInt32(versionElms[1]);
                uint     versionC         = Convert.ToUInt32(versionElms[2]);

                Log.Info($"Detected game version v{BuildConfig.applicationVersion}");

                bool isModTooOld = TrafficManagerMod.GAME_VERSION_A < versionA ||
                                   (TrafficManagerMod.GAME_VERSION_A == versionA &&
                                    TrafficManagerMod.GAME_VERSION_B < versionB);
                // || (TrafficManagerMod.GameVersionA == versionA
                // && TrafficManagerMod.GameVersionB == versionB
                // && TrafficManagerMod.GameVersionC < versionC);

                bool isModNewer = TrafficManagerMod.GAME_VERSION_A < versionA ||
                                  (TrafficManagerMod.GAME_VERSION_A == versionA &&
                                   TrafficManagerMod.GAME_VERSION_B > versionB);
                // || (TrafficManagerMod.GameVersionA == versionA
                // && TrafficManagerMod.GameVersionB == versionB
                // && TrafficManagerMod.GameVersionC > versionC);

                if (isModTooOld)
                {
                    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,
                        BuildConfig.VersionToString(TrafficManagerMod.GAME_VERSION, false));

                    Log.Error(msg);
                    Singleton <SimulationManager> .instance.m_ThreadingWrapper.QueueMainThread(
                        () => {
                        UIView.library
                        .ShowModal <ExceptionPanel>("ExceptionPanel")
                        .SetMessage(
                            "TM:PE has not been updated yet",
                            msg,
                            false);
                    });
                }
                else if (isModNewer)
                {
                    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.",
                        BuildConfig.VersionToString(TrafficManagerMod.GAME_VERSION, false),
                        BuildConfig.applicationVersion);

                    Log.Error(msg);
                    Singleton <SimulationManager>
                    .instance.m_ThreadingWrapper.QueueMainThread(
                        () => {
                        UIView.library
                        .ShowModal <ExceptionPanel>("ExceptionPanel")
                        .SetMessage(
                            "Your game should be updated",
                            msg,
                            false);
                    });
                }
            }

            IsGameLoaded = true;

            //it will replace stock PathManager or already Replaced before HotReload
            if (!IsPathManagerReplaced || TrafficManagerMod.Instance.InGameHotReload)
            {
                try {
                    Log.Info("Pathfinder Compatible. Setting up CustomPathManager and SimManager.");
                    FieldInfo pathManagerInstance = typeof(Singleton <PathManager>).GetField(
                        "sInstance",
                        BindingFlags.Static | BindingFlags.NonPublic);
                    if (pathManagerInstance == null)
                    {
                        throw new Exception("pathManagerInstance is null");
                    }


                    PathManager stockPathManager = PathManager.instance;
                    if (stockPathManager == null)
                    {
                        throw new Exception("stockPathManager is null");
                    }

                    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 = this.simManager;
                    if (simManager == null)
                    {
                        throw new Exception("simManager is null");
                    }

                    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());

                    IsPathManagerReplaced = true;
                }
                catch (Exception ex) {
                    string error =
                        "Traffic Manager: President Edition failed to load. You can continue " +
                        "playing but it's NOT recommended. Traffic Manager will not work as expected.";
                    Log.Error(error);
                    Log.Error($"Path manager replacement error: {ex}");

                    Singleton <SimulationManager> .instance.m_ThreadingWrapper.QueueMainThread(
                        () => {
                        UIView.library
                        .ShowModal <ExceptionPanel>(
                            "ExceptionPanel")
                        .SetMessage(
                            "TM:PE failed to load",
                            error,
                            true);
                    });
                }
            }

            ModUI.OnLevelLoaded();
            if (PlayMode)
            {
                // Init transport demand UI
                if (TransportDemandUI == null)
                {
                    UIView uiView = UIView.GetAView();
                    TransportDemandUI = (UITransportDemand)uiView.AddUIComponent(typeof(UITransportDemand));
                }

                // add "remove vehicle" button
                UIView.GetAView().gameObject.AddComponent <RemoveVehicleButtonExtender>();

                // add "remove citizen instance" button
                UIView.GetAView().gameObject.AddComponent <RemoveCitizenInstanceButtonExtender>();

                UIView.GetAView().gameObject.AddComponent <RoadSelectionPanels>();
            }

            Patcher.Create().Install();

            // Log.Info("Fixing non-created nodes with problems...");
            // FixNonCreatedNodeProblems();
            Log.Info("Notifying managers...");
            foreach (ICustomManager manager in RegisteredManagers)
            {
                Log.Info($"OnLevelLoading: {manager.GetType().Name}");
                manager.OnLevelLoading();
            }

            // InitTool();
            // Log._Debug($"Current tool: {ToolManager.instance.m_properties.CurrentTool}");
            Log.Info("OnLevelLoaded complete.");
        }
Пример #6
0
        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;
            }
        }
Пример #7
0
        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;
            }
        }