Esempio n. 1
0
        public override void OnLevelLoaded(LoadMode mode)
        {
            base.OnLevelLoaded(mode);

            if (mode == LoadMode.LoadGame || mode == LoadMode.NewGame || (ExperimentsToggle.EnableInScenarios && mode == (LoadMode)11)) //11 is some new mode not implemented in ICities...
            {
                LoggingWrapper.Log("Loading mod");
                CimTools.CimToolsHandler.CimToolBase.Changelog.DownloadChangelog();
                CimTools.CimToolsHandler.CimToolBase.XMLFileOptions.Load();

                if (!ExperimentsToggle.GhostMode)
                {
                    if (_dateTimeGameObject == null)
                    {
                        _dateTimeGameObject = new GameObject("DateTimeBar");
                    }

                    if (_mainUIGameObject == null)
                    {
                        _mainUIGameObject = new GameObject("RushHourUI");
                        EventPopupManager popupManager = EventPopupManager.Instance;
                    }

                    if (_dateTimeBar == null)
                    {
                        _dateTimeBar = _dateTimeGameObject.AddComponent <DateTimeBar>();
                        _dateTimeBar.Initialise();
                    }

                    if (!_simulationRegistered)
                    {
                        SimulationManager.RegisterSimulationManager(_simulationManager);
                        _simulationRegistered = true;
                        LoggingWrapper.Log("Simulation hooked");
                    }

                    Redirect();
                }
            }
            else
            {
                Debug.Log("Rush Hour is not set to start up in this mode. " + mode.ToString());
            }
        }
        public override void OnLevelLoaded(LoadMode mode)
        {
            base.OnLevelLoaded(mode);

            if (mode != LoadMode.LoadGame && mode != LoadMode.NewGame)
            {
                return;
            }

            CimTools.CimToolsHandler.CimToolBase.DetailedLogger.Log("Loading mod");
            CimTools.CimToolsHandler.CimToolBase.Changelog.DownloadChangelog();
            CimTools.CimToolsHandler.CimToolBase.XMLFileOptions.Load();

            if (!ExperimentsToggle.GhostMode)
            {
                if (_dateTimeGameObject == null)
                {
                    _dateTimeGameObject = new GameObject("DateTimeBar");
                }

                if (_mainUIGameObject == null)
                {
                    _mainUIGameObject = new GameObject("RushHourUI");
                    EventPopupManager popupManager = EventPopupManager.Instance;
                }

                if (_dateTimeBar == null)
                {
                    _dateTimeBar = _dateTimeGameObject.AddComponent <DateTimeBar>();
                    _dateTimeBar.Initialise();
                }

                if (!_simulationRegistered)
                {
                    SimulationManager.RegisterSimulationManager(_simulationManager);
                    _simulationRegistered = true;
                }

                Redirect();
            }
        }
Esempio n. 3
0
        public override void OnLevelLoaded(LoadMode mode)
        {
            base.OnLevelLoaded(mode);

            if (mode == LoadMode.LoadGame || mode == LoadMode.NewGame || (ExperimentsToggle.EnableInScenarios && mode == (LoadMode)11)) //11 is some new mode not implemented in ICities...
            {
                LoggingWrapper.Log("Loading mod");
                CimTools.CimToolsHandler.CimToolBase.Changelog.DownloadChangelog();
                CimTools.CimToolsHandler.CimToolBase.XMLFileOptions.Load();

                if (!ExperimentsToggle.GhostMode)
                {
                    if (_dateTimeGameObject == null)
                    {
                        _dateTimeGameObject = new GameObject("DateTimeBar");
                    }

                    if (_mainUIGameObject == null)
                    {
                        _mainUIGameObject = new GameObject("RushHourUI");
                        EventPopupManager popupManager = EventPopupManager.Instance;
                    }

                    if (_dateTimeBar == null)
                    {
                        _dateTimeBar = _dateTimeGameObject.AddComponent <DateTimeBar>();
                        _dateTimeBar.Initialise();
                    }

                    if (!_simulationRegistered)
                    {
                        SimulationManager.RegisterSimulationManager(_simulationManager);
                        _simulationRegistered = true;
                        LoggingWrapper.Log("Simulation hooked");
                    }

                    Redirect();

                    Detours = new List <Detour>();
                    bool detourFailed = false;
                    try
                    {
                        var methodToReplace = typeof(TransportLineAI).GetMethod("SimulationStep",
                                                                                new[]
                        {
                            typeof(ushort),
                            typeof(NetNode).MakeByRefType()
                        });
                        var methodToReplaceWith = typeof(CustomTransportLineAI).GetMethod("CustomNodeSimulationStep");

                        if (methodToReplace == null)
                        {
                            Log.Info("methodToReplace == null");
                        }

                        if (methodToReplaceWith == null)
                        {
                            Log.Info("methodToReplaceWith == null");
                        }

                        var detour = new Detour(methodToReplace,
                                                methodToReplaceWith);

                        Detours.Add(detour);
                    }
                    catch (Exception ex)
                    {
                        detourFailed = true;
                    }

                    Log.Info("Redirection TransportTool::RenderOverlay calls");
                    detourFailed = false;
                    try
                    {
                        var methodToReplace = typeof(TransportManager).GetMethod("RenderLines",
                                                                                 BindingFlags.NonPublic | BindingFlags.Instance);

                        var methodToReplaceWith = typeof(TransportLineRenderer).GetMethod("CustomRenderLines",
                                                                                          BindingFlags.NonPublic | BindingFlags.Instance);

                        if (methodToReplace == null)
                        {
                            Log.Info("methodToReplace == null");
                        }

                        if (methodToReplaceWith == null)
                        {
                            Log.Info("methodToReplaceWith == null");
                        }

                        var detour = new Detour(methodToReplace,
                                                methodToReplaceWith);
                        Log.Info("Redirection TransportLineAI::RenderOverlay calls step 2");

                        Detours.Add(detour);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Could not redirect TransportTool::RenderOverlay " + ex.Message);
                        detourFailed = true;
                    }
                }
            }
            else
            {
                Debug.Log("Rush Hour is not set to start up in this mode. " + mode.ToString());
            }
        }