Пример #1
0
        public override void OnSaveData()
        {
            base.OnSaveData();

            if (!LoadingExtension.installed)
            {
                return;
            }

            CODebug.Log(LogChannel.Modding, Mod.modName + " - try saving data");
            try {
                if (m_serializedData != null)
                {
                    BinaryFormatter bFormatter2 = new BinaryFormatter();
                    MemoryStream    mStream2    = new MemoryStream();
                    bFormatter2.Serialize(mStream2, SAVE_DATA_VERSION);
                    byte[] data2 = mStream2.ToArray();
                    if (data2 != null)
                    {
                        m_serializedData.SaveData(RESILIENTS_VERSION_ID, data2);
                    }

                    BinaryFormatter bFormatter = new BinaryFormatter();
                    MemoryStream    mStream    = new MemoryStream();
                    bFormatter.Serialize(mStream, s_info.m_resilients);
                    byte[] data = mStream.ToArray();
                    if (data != null)
                    {
                        m_serializedData.SaveData(RESILIENTS_DATA_ID, data);
                    }

                    BinaryFormatter bFormatter4 = new BinaryFormatter();
                    MemoryStream    mStream4    = new MemoryStream();
                    bFormatter4.Serialize(mStream4, s_info.m_districts);
                    byte[] data4 = mStream4.ToArray();
                    if (data4 != null)
                    {
                        m_serializedData.SaveData(RESILIENTS_DISTRICTS_ID, data4);
                    }

                    BinaryFormatter bFormatter3 = new BinaryFormatter();
                    MemoryStream    mStream3    = new MemoryStream();
                    bFormatter3.Serialize(mStream3, Settings.inst);
                    byte[] data3 = mStream3.ToArray();

                    if (data3 != null)
                    {
                        m_serializedData.SaveData(RESILIENTS_SETTINGS_ID, data3);
                    }

                    CODebug.Log(LogChannel.Modding, Mod.modName + " - successful saving data");
                }
                else
                {
                }
            } catch (Exception e) {
                CODebug.Log(LogChannel.Modding, Mod.modName + " - Error saving data " + e.StackTrace);
            }
        }
Пример #2
0
        public override void OnSaveData()
        {
            if (Loader.CurrentLoadMode == LoadMode.LoadGame || Loader.CurrentLoadMode == LoadMode.NewGame)
            {
                DebugLog.LogToFileOnly("StartSave");
                //1
                var saveData = new byte[2448];
                RealCityEconomyManager.Save(ref saveData);
                _serializableData.SaveData("RealCity RealCityEconomyManager", saveData);

                //2
                saveData = new byte[131];
                MainDataStore.Save(ref saveData);
                _serializableData.SaveData("RealCity MainDataStore", saveData);

                //3
                saveData = new byte[48];
                RealCityResidentAI.Save(ref saveData);
                _serializableData.SaveData("RealCity RealCityResidentAI", saveData);

                //4
                saveData = new byte[60];
                RealCityPrivateBuildingAI.Save(ref saveData);
                _serializableData.SaveData("RealCity RealCityPrivateBuildingAI", saveData);

                //5
                saveData = new byte[4194304];
                CitizenData.Save(ref saveData);
                _serializableData.SaveData("RealCity CitizenData", saveData);

                //6
                saveData = new byte[58];
                Politics.Save(ref saveData);
                _serializableData.SaveData("RealCity Politics", saveData);

                //7
                saveData = new byte[1536];
                TransportLineData.Save(ref saveData);
                _serializableData.SaveData("RealCity TransportLineData", saveData);

                //8
                saveData = new byte[442368];
                BuildingData.Save(ref saveData);
                _serializableData.SaveData("RealCity BuildingData", saveData);

                //9
                saveData = new byte[196608];
                VehicleData.Save(ref saveData);
                _serializableData.SaveData("RealCity VehicleData", saveData);

                //10
                saveData = new byte[3145728];
                CitizenUnitData.Save(ref saveData);
                _serializableData.SaveData("RealCity CitizenUnitData", saveData);
            }
        }
Пример #3
0
        public void OnSaveData()
        {
            try
            {
                byte[] data;

                using (var stream = new MemoryStream())
                {
                    EnhancedDisastersManager edm = Singleton <EnhancedDisastersManager> .instance;

                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new DisastersContainer.Data());

                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new EnhancedForestFire.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new EnhancedThunderstorm.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new EnhancedSinkhole.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new EnhancedTsunami.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new EnhancedTornado.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new EnhancedEarthquake.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new EnhancedMeteorStrike.Data());
                    data = stream.ToArray();
                }

                serializableData.SaveData(DataID, data);
            }
            catch (Exception ex)
            {
                Debug.Log(Mod.LogMsgPrefix + "(save error) " + ex.Message);
            }
        }
Пример #4
0
        /// <summary>
        /// When the game is saved. Connect this up to the OnSaveData method in your mod which
        /// should be inherited from SerializableDataExtensionBase.
        /// </summary>
        /// <param name="serialisableDataManager">The data manager passed from SerializableDataExtensionBase</param>
        public void SaveData(ISerializableData serialisableDataManager)
        {
            if (serialisableDataManager != null)
            {
                if (_toolBase.ModSettings.ModName != null)
                {
                    StringWriter stringWriter = new StringWriter();

                    if (_xmlManager.Save(stringWriter))
                    {
                        BinaryFormatter binaryFormatter = new BinaryFormatter();
                        MemoryStream    memoryStream    = new MemoryStream();

                        _toolBase.NamedLogger.Log("Saving data to save file.");
                        _toolBase.DetailedLogger.Log(stringWriter.ToString());

                        binaryFormatter.Serialize(memoryStream, stringWriter.ToString());
                        serialisableDataManager.SaveData(_toolBase.ModSettings.ModName + "Data" + _toolBase.Strings.VERSION, memoryStream.ToArray());

                        _toolBase.NamedLogger.Log("Saved.");

                        memoryStream.Close();
                    }
                    else
                    {
                        _toolBase.NamedLogger.LogError("Failed to save options");
                    }
                }
            }
            else
            {
                _toolBase.NamedLogger.LogError("The serialisableDataManager passed to SaveData was null. No data was saved!");
            }
        }
        public void OnSaveData()
        {
            try
            {
                byte[] data;

                using (var stream = new MemoryStream())
                {
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new AutobudgetElectricity.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new AutobudgetWater.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new AutobudgetHeating.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new AutobudgetGarbage.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new AutobudgetHealthcare.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new AutobudgetEducation.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new AutobudgetPolice.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new AutobudgetIndustry.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new AutobudgetFire.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new AutobudgetRoad.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new AutobudgetPost.Data());
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new AutobudgetTaxi.Data());
                    data = stream.ToArray();
                }

                serializedData.SaveData(DataID, data);
            }
            catch (Exception ex)
            {
                Debug.Log(Mod.LogMsgPrefix + "save error: " + ex.Message);
            }
        }
Пример #6
0
        public void Serialize(ISerializableData serializableDataManager, uint version)
        {
            Serializer serializer;

            if (!Serializers.TryGetValue(version, out serializer))
            {
                throw new InvalidOperationException($"No Serializer with version {version} found!");
            }

            DebugLog.Message("Serialize version {0}", version);

            if (serializer.ShouldDeleteData())
            {
                DebugLog.Info($"Deleting saved data because serializer version {version} requested deletion.");
                serializableDataManager.EraseData(Id);
            }
            else
            {
                var data = serializer.SerializeData();
                if (data == null)
                {
                    DebugLog.Info($"No data to serialize (-> delete data if present)");
                    serializableDataManager.EraseData(Id);
                }
                else
                {
                    var bytesVersion    = BitConverter.GetBytes(version);
                    var dataWithVersion = bytesVersion.Concat(data).ToArray();

                    serializableDataManager.SaveData(Id, dataWithVersion);

                    DebugLog.Message("Serialized {0} bytes", dataWithVersion.Length - 4);
                }
            }
        }
        public override void OnSaveData()
        {
#if DEBUG
            if (Loader.CurrentLoadMode == LoadMode.LoadGame || Loader.CurrentLoadMode == LoadMode.NewGame)
            {
                DebugLog.LogToFileOnly("startsave");
                MainDataStore.SaveData = new byte[4194304];
                gather_saveData();
                _serializableData.SaveData("AdvancedRoadTools MainDataStore", MainDataStore.SaveData);
            }
#endif
        }
Пример #8
0
        public void OnSaveData()
        {
            byte[] data;

            using (var stream = new MemoryStream())
            {
                DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new SavedTaxValues.Data());
                data = stream.ToArray();
            }

            serializedData.SaveData(DataID, data);
        }
Пример #9
0
        public override void OnSaveData()
        {
            // Why don't we use exceptions?
            bool success = true;

            Log.Info("Saving Mod Data.");

            /*try {
             *                  Log.Info("Recalculating segment geometries");
             *                  SegmentGeometry.OnBeforeSaveData();
             *          } catch (Exception e) {
             *                  Log.Error($"OnSaveData: Exception occurred while calling SegmentGeometry.OnBeforeSaveData: {e.ToString()}");
             *                  error = true;
             *          }*/

            OnBeforeGameSaved(ref success);

            try {
                try
                {
                    // save options
                    _serializableData.SaveData("TMPE_Options", OptionsManager.Instance.SaveData(ref success));
                }
                catch (Exception ex)
                {
                    Log.Error("Unexpected error while saving options: " + ex.Message);
                    success = false;
                }

                Configuration config = CreateConfiguration(ref success);
                _serializableData.SaveData(DataId, Serialize <Configuration>(config, ref success));
            } catch (Exception e) {
                success = false;
                Log.Error($"Error occurred while saving data: {e.ToString()}");
                //UIView.library.ShowModal<ExceptionPanel>("ExceptionPanel").SetMessage("An error occurred while saving", "Traffic Manager: President Edition detected an error while saving. To help preventing future errors, please navigate to http://steamcommunity.com/sharedfiles/filedetails/?id=583429740 and follow the steps under 'In case problems arise'.", true);
            }

            OnAfterGameSaved(ref success);
        }
Пример #10
0
 internal void OnSaveData(ISerializableData serializableDataManager)
 {
     if (MixID == null)
     {
         return;
     }
     using (var memoryStream = new MemoryStream()) {
         try {
             var binaryFormatter = new BinaryFormatter();
             binaryFormatter.Serialize(memoryStream, MixID);
             serializableDataManager.SaveData(DataID, memoryStream.ToArray());
         } catch (Exception exception) {
             Debug.LogError(exception);
         }
     }
 }
        public void OnSaveData()
        {
            try
            {
                byte[] data;

                using (var stream = new MemoryStream())
                {
                    DataSerializer.Serialize(stream, DataSerializer.Mode.Memory, DataVersion, new GameSpeedManager.Data());
                    data = stream.ToArray();
                }

                serializedData.SaveData(DataID, data);
            }
            catch (Exception ex)
            {
                Debug.Log("GameSpeedMod: save error: " + ex.Message);
            }
        }
Пример #12
0
        public void Serialize(ISerializableData serializableDataManager, uint version)
        {
            Serializer s;

            if (!Serializers.TryGetValue(version, out s))
            {
                //TODO: Fehlerbehandlung
                throw new InvalidOperationException(string.Format("No Serializer with version {0} found!", version));
            }

            DebugLog.Message("Serialize version {0}", version);

            var data = s.SerializeData();

            var bytesVersion    = BitConverter.GetBytes(version);
            var dataWithVersion = bytesVersion.Concat(data).ToArray();

            serializableDataManager.SaveData(Id, dataWithVersion);

            DebugLog.Message("Serialized {0} bytes", dataWithVersion.Length - 4);
        }
Пример #13
0
        public static void Serialize(ISerializableData serializableData, string dataID, Configuration config)
        {
            config.ComputeHashCodes();
            Debug.Log("serializing to save data");
            Debug.Log(config.ToString());

            var serializer             = new XmlSerializer(typeof(Configuration));
            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();

            ns.Add("", "");
            RegisterEvents(ref serializer);
            byte[] configData;

            using (var memoryStream = new MemoryStream()) {
                config.OnPreSerialize();
                serializer.Serialize(memoryStream, config, ns);
                configData = memoryStream.ToArray();
            }

            serializableData.SaveData(dataID, configData);
        }
Пример #14
0
        /// <summary>
        /// Saves the serialized data.
        /// </summary>
        /// <param name="serializableData">The serializable data inteface object.</param>
        /// <param name="id">The identifier.</param>
        public void Save(ISerializableData serializableData, string id)
        {
            if (!this.isWriteable)
            {
                throw new InvalidOperationException("Container is readonly");
            }

            if (this.serializedData != null)
            {
                FletcherChecksum.ControlBytes control = FletcherChecksum.GetControlBytes(this.serializedData, 0, this.index);

                byte[] data = new byte[this.index + 2];
                if (this.index > 0)
                {
                    Buffer.BlockCopy(this.serializedData, 0, data, 0, this.index);
                }

                data[this.index]     = control.First;
                data[this.index + 1] = control.Second;

                Log.Debug(this, "Save", id, data.Length);
                serializableData.SaveData(id, data);
            }
        }
        public override void OnSaveData()
        {
            bool success = true;

            /*try {
             *      Log.Info("Recalculating segment geometries");
             *      SegmentGeometry.OnBeforeSaveData();
             * } catch (Exception e) {
             *      Log.Error($"OnSaveData: Exception occurred while calling SegmentGeometry.OnBeforeSaveData: {e.ToString()}");
             *      error = true;
             * }*/

            foreach (ICustomManager manager in LoadingExtension.RegisteredManagers)
            {
                try {
                    Log.Info($"OnBeforeSaveData: {manager.GetType().Name}");
                    manager.OnBeforeSaveData();
                } catch (Exception e) {
                    Log.Error($"OnSaveData: Error while notifying {manager.GetType().Name}.OnBeforeSaveData: {e.ToString()}");
                    success = false;
                }
            }

            try {
                Log.Info("Saving Mod Data.");
                var configuration = new Configuration();

                TrafficPriorityManager prioMan = TrafficPriorityManager.Instance;

                configuration.ExtCitizens         = ExtCitizenManager.Instance.SaveData(ref success);
                configuration.ExtCitizenInstances = ExtCitizenInstanceManager.Instance.SaveData(ref success);

                configuration.PrioritySegments       = ((ICustomDataManager <List <int[]> >)TrafficPriorityManager.Instance).SaveData(ref success);
                configuration.CustomPrioritySegments = ((ICustomDataManager <List <Configuration.PrioritySegment> >)TrafficPriorityManager.Instance).SaveData(ref success);

                configuration.SegmentNodeConfs = JunctionRestrictionsManager.Instance.SaveData(ref success);

                configuration.TimedLights = TrafficLightSimulationManager.Instance.SaveData(ref success);

                //configuration.NodeTrafficLights = ((ICustomDataManager<string>)TrafficLightManager.Instance).SaveData(ref success);
                //configuration.ToggledTrafficLights = ((ICustomDataManager<List<Configuration.NodeTrafficLight>>)TrafficLightManager.Instance).SaveData(ref success);

                configuration.LaneFlags  = ((ICustomDataManager <string>)LaneArrowManager.Instance).SaveData(ref success);
                configuration.LaneArrows = ((ICustomDataManager <List <Configuration.LaneArrowData> >)LaneArrowManager.Instance).SaveData(ref success);

                configuration.LaneConnections = LaneConnectionManager.Instance.SaveData(ref success);

                configuration.LaneSpeedLimits = ((ICustomDataManager <List <Configuration.LaneSpeedLimit> >)SpeedLimitManager.Instance).SaveData(ref success);

                configuration.CustomDefaultSpeedLimits = ((ICustomDataManager <Dictionary <string, float> >)SpeedLimitManager.Instance).SaveData(ref success);

                configuration.LaneAllowedVehicleTypes = VehicleRestrictionsManager.Instance.SaveData(ref success);
                configuration.ParkingRestrictions     = ParkingRestrictionsManager.Instance.SaveData(ref success);

                try {
                    // save options
                    _serializableData.SaveData("TMPE_Options", OptionsManager.Instance.SaveData(ref success));
                } catch (Exception ex) {
                    Log.Error("Unexpected error while saving options: " + ex.Message);
                    success = false;
                }

                var binaryFormatter = new BinaryFormatter();
                var memoryStream    = new MemoryStream();

                try {
                    binaryFormatter.Serialize(memoryStream, configuration);
                    memoryStream.Position = 0;
                    Log.Info($"Save data byte length {memoryStream.Length}");
                    _serializableData.SaveData(DataId, memoryStream.ToArray());
                } catch (Exception ex) {
                    Log.Error("Unexpected error while saving data: " + ex.ToString());
                    success = false;
                } finally {
                    memoryStream.Close();
                }

                foreach (ICustomManager manager in LoadingExtension.RegisteredManagers)
                {
                    try {
                        Log.Info($"OnAfterSaveData: {manager.GetType().Name}");
                        manager.OnAfterSaveData();
                    } catch (Exception e) {
                        Log.Error($"OnSaveData: Error while notifying {manager.GetType().Name}.OnAfterSaveData: {e.ToString()}");
                        success = false;
                    }
                }
            } catch (Exception e) {
                success = false;
                Log.Error($"Error occurred while saving data: {e.ToString()}");
                //UIView.library.ShowModal<ExceptionPanel>("ExceptionPanel").SetMessage("An error occurred while saving", "Traffic Manager: President Edition detected an error while saving. To help preventing future errors, please navigate to http://steamcommunity.com/sharedfiles/filedetails/?id=583429740 and follow the steps under 'In case problems arise'.", true);
            }
        }
        public void OnSaveData()
        {
            if (Debugger.Enabled)
            {
                Debugger.Log("Building Themes: SerializableDataExtension.OnSaveData was called.");
                Debugger.Log("ON_SAVE_DATA");
            }

            var data = new FastList <byte>();

            GenerateUniqueId();

            var uniqueIdBytes = BitConverter.GetBytes(UniqueId);

            foreach (var uniqueIdByte in uniqueIdBytes)
            {
                data.Add(uniqueIdByte);
            }

            var dataToSave = data.ToArray();

            SerializableData.SaveData(DataId, dataToSave);

            var filepath = BuildSaveFilePath();

            var configuration = new DistrictsConfiguration();

            var themesManager = Singleton <BuildingThemesManager> .instance;

            for (byte i = 0; i < 128; i++)
            {
                if (!themesManager.IsThemeManagementEnabled(i))
                {
                    continue;
                }

                var themes = themesManager.GetDistrictThemes(i, false);
                if (themes == null)
                {
                    continue;;
                }
                var themesNames = new string[themes.Count];
                var j           = 0;
                foreach (var theme in themes)
                {
                    themesNames[j] = theme.name;
                    j++;
                }
                configuration.Districts.Add(new DistrictsConfiguration.District()
                {
                    id            = i,
                    blacklistMode = themesManager.IsBlacklistModeEnabled(i),
                    themes        = themesNames
                });
                if (Debugger.Enabled)
                {
                    Debugger.LogFormat("Building Themes: Saving: {0} themes enabled for district {1}", themes.Count, i);
                }
            }

            if (configuration.Districts.Count > 0)
            {
                DistrictsConfiguration.Serialize(filepath, configuration);
            }

            if (Debugger.Enabled)
            {
                Debugger.LogFormat("Building Themes: Serialization done.");
                Debugger.AppendThemeList();
            }
        }
        public override void OnSaveData()
        {
            Log.Warning("Saving Mod Data.");
            var configuration = new Configuration();

            for (ushort i = 0; i < 36864; i++)
            {
                if (TrafficPriority.PrioritySegments != null)
                {
                    AddPrioritySegment(i, configuration);
                }

                if (TrafficPriority.LightSimByNodeId != null)
                {
                    AddNodeToDictionary(i, configuration);
                }

                if (TrafficLightsManual.ManualSegments != null)
                {
                    AddManualTrafficLight(i, configuration);
                }

                if (TrafficLightsTimed.TimedScripts != null)
                {
                    AddTimedTrafficLight(i, configuration);
                }
            }

            if (Singleton <NetManager> .instance?.m_nodes?.m_buffer != null)
            {
                for (var i = 0; i < Singleton <NetManager> .instance.m_nodes.m_buffer.Length; i++)
                {
                    if (AddNodeLightsAndCrosswalks(i, configuration))
                    {
                        continue;
                    }
                }
            }

            if (LoadingExtension.IsPathManagerCompatible && Singleton <NetManager> .instance?.m_lanes?.m_buffer != null)
            {
                for (var i = 0; i < Singleton <NetManager> .instance.m_lanes.m_buffer.Length; i++)
                {
                    AddLaneData(i, configuration);
                }
            }
            else
            {
                // Traffic++ compatibility
                configuration.LaneFlags = "";
            }

            var binaryFormatter = new BinaryFormatter();
            var memoryStream    = new MemoryStream();

            try {
                binaryFormatter.Serialize(memoryStream, configuration);
                memoryStream.Position = 0;
                Log.Message($"Save data byte length {memoryStream.Length}");
                _serializableData.SaveData(DataId, memoryStream.ToArray());

                Log.Message("Erasing old save data.");
                _serializableData.SaveData(LegacyDataId, new byte[] { });
            } catch (Exception ex) {
                Log.Error("Unexpected error saving data: " + ex.Message);
            } finally {
                memoryStream.Close();
            }
        }
        public override void OnSaveData()
        {
            Log.Info("Recalculating segment geometries");
            SegmentGeometry.OnBeforeSaveData();
            Log.Info("Saving Mod Data.");
            var configuration = new Configuration();

            if (TrafficPriority.TrafficSegments != null)
            {
                for (ushort i = 0; i < Singleton <NetManager> .instance.m_segments.m_size; i++)
                {
                    try {
                        SavePrioritySegment(i, configuration);
                    } catch (Exception e) {
                        Log.Error($"Exception occurred while saving priority segment @ {i}: {e.ToString()}");
                    }

                    try {
                        SaveSegmentNodeFlags(i, configuration);
                    } catch (Exception e) {
                        Log.Error($"Exception occurred while saving segment node flags @ {i}: {e.ToString()}");
                    }
                }
            }

            for (ushort i = 0; i < Singleton <NetManager> .instance.m_nodes.m_size; i++)
            {
                /*if (TrafficLightSimulation.LightSimulationByNodeId != null) {
                 *      SaveTrafficLightSimulation(i, configuration);
                 * }*/

                /*if (TrafficLightsManual.ManualSegments != null) {
                 *      SaveManualTrafficLight(i, configuration);
                 * }*/

                TrafficLightSimulation sim = TrafficLightSimulation.GetNodeSimulation(i);
                if (sim != null && sim.IsTimedLight())
                {
                    try {
                        SaveTimedTrafficLight(i, configuration);
                    } catch (Exception e) {
                        Log.Error($"Exception occurred while saving timed traffic light @ {i}: {e.ToString()}");
                    }
                    // TODO save new traffic lights
                }

                try {
                    SaveNodeLights(i, configuration);
                } catch (Exception e) {
                    Log.Error($"Exception occurred while saving node traffic light @ {i}: {e.ToString()}");
                }
            }

#if !TAM
            if (LoadingExtension.IsPathManagerCompatible)
            {
#endif
            for (uint i = 0; i < Singleton <NetManager> .instance.m_lanes.m_buffer.Length; i++)
            {
                try {
                    SaveLaneData(i, configuration);
                } catch (Exception e) {
                    Log.Error($"Exception occurred while saving lane data @ {i}: {e.ToString()}");
                }
            }
#if !TAM
        }
#endif

            foreach (KeyValuePair <uint, ushort> e in Flags.getAllLaneSpeedLimits())
            {
                try {
                    SaveLaneSpeedLimit(new Configuration.LaneSpeedLimit(e.Key, e.Value), configuration);
                } catch (Exception ex) {
                    Log.Error($"Exception occurred while saving lane speed limit @ {e.Key}: {ex.ToString()}");
                }
            }

            foreach (KeyValuePair <uint, ExtVehicleType> e in Flags.getAllLaneAllowedVehicleTypes())
            {
                try {
                    SaveLaneAllowedVehicleTypes(new Configuration.LaneVehicleTypes(e.Key, e.Value), configuration);
                } catch (Exception ex) {
                    Log.Error($"Exception occurred while saving lane vehicle restrictions @ {e.Key}: {ex.ToString()}");
                }
            }

            var binaryFormatter = new BinaryFormatter();
            var memoryStream    = new MemoryStream();

            try {
                binaryFormatter.Serialize(memoryStream, configuration);
                memoryStream.Position = 0;
                Log.Info($"Save data byte length {memoryStream.Length}");
                _serializableData.SaveData(DataId, memoryStream.ToArray());

                // save options
                _serializableData.SaveData("TMPE_Options", new byte[] {
                    (byte)Options.simAccuracy,
                    (byte)0,                    //Options.laneChangingRandomization,
                    (byte)Options.recklessDrivers,
                    (byte)(Options.relaxedBusses ? 1 : 0),
                    (byte)(Options.nodesOverlay ? 1 : 0),
                    (byte)(Options.allowEnterBlockedJunctions ? 1 : 0),
                    (byte)(Options.advancedAI ? 1 : 0),
                    (byte)(Options.highwayRules ? 1 : 0),
                    (byte)(Options.prioritySignsOverlay ? 1 : 0),
                    (byte)(Options.timedLightsOverlay ? 1 : 0),
                    (byte)(Options.speedLimitsOverlay ? 1 : 0),
                    (byte)(Options.vehicleRestrictionsOverlay ? 1 : 0),
                    (byte)(Options.strongerRoadConditionEffects ? 1 : 0),
                    (byte)(Options.allowUTurns ? 1 : 0),
                    (byte)(Options.allowLaneChangesWhileGoingStraight ? 1 : 0),
                    (byte)(Options.enableDespawning ? 1 : 0),
                    (byte)(Options.IsDynamicPathRecalculationActive() ? 1 : 0),
                    (byte)(Options.connectedLanesOverlay ? 1 : 0)
                });
            } catch (Exception ex) {
                Log.Error("Unexpected error saving data: " + ex.Message);
            } finally {
                memoryStream.Close();
            }
        }
Пример #19
0
        public void OnSaveData()
        {
            FastList <byte> data = new FastList <byte>();

            GenerateUniqueID();

            byte[] uniqueIdBytes = BitConverter.GetBytes(uniqueID);
            foreach (byte uniqueIdByte in uniqueIdBytes)
            {
                data.Add(uniqueIdByte);
            }

            byte[] dataToSave = data.ToArray();
            SerializableData.SaveData(dataID, dataToSave);

            var filepath = Path.Combine(Application.dataPath, "trafficManagerSave_" + uniqueID + ".xml");

            var configuration = new Configuration();

            for (var i = 0; i < 32768; i++)
            {
                if (TrafficPriority.prioritySegments.ContainsKey(i))
                {
                    if (TrafficPriority.prioritySegments[i].node_1 != 0)
                    {
                        configuration.prioritySegments.Add(new int[3] {
                            TrafficPriority.prioritySegments[i].node_1, i, (int)TrafficPriority.prioritySegments[i].instance_1.type
                        });
                    }
                    if (TrafficPriority.prioritySegments[i].node_2 != 0)
                    {
                        configuration.prioritySegments.Add(new int[3] {
                            TrafficPriority.prioritySegments[i].node_2, i, (int)TrafficPriority.prioritySegments[i].instance_2.type
                        });
                    }
                }

                if (CustomRoadAI.nodeDictionary.ContainsKey((ushort)i))
                {
                    var nodeDict = CustomRoadAI.nodeDictionary[(ushort)i];

                    configuration.nodeDictionary.Add(new int[4] {
                        nodeDict.NodeId, Convert.ToInt32(nodeDict._manualTrafficLights), Convert.ToInt32(nodeDict._timedTrafficLights), Convert.ToInt32(nodeDict.TimedTrafficLightsActive)
                    });
                }

                if (TrafficLightsManual.ManualSegments.ContainsKey(i))
                {
                    if (TrafficLightsManual.ManualSegments[i].node_1 != 0)
                    {
                        var manualSegment = TrafficLightsManual.ManualSegments[i].instance_1;

                        configuration.manualSegments.Add(new int[10]
                        {
                            (int)manualSegment.node,
                            manualSegment.segment,
                            (int)manualSegment.currentMode,
                            (int)manualSegment.lightLeft,
                            (int)manualSegment.lightMain,
                            (int)manualSegment.lightRight,
                            (int)manualSegment.lightPedestrian,
                            (int)manualSegment.lastChange,
                            (int)manualSegment.lastChangeFrame,
                            Convert.ToInt32(manualSegment.pedestrianEnabled)
                        });
                    }
                    if (TrafficLightsManual.ManualSegments[i].node_2 != 0)
                    {
                        var manualSegment = TrafficLightsManual.ManualSegments[i].instance_2;

                        configuration.manualSegments.Add(new int[10]
                        {
                            (int)manualSegment.node,
                            manualSegment.segment,
                            (int)manualSegment.currentMode,
                            (int)manualSegment.lightLeft,
                            (int)manualSegment.lightMain,
                            (int)manualSegment.lightRight,
                            (int)manualSegment.lightPedestrian,
                            (int)manualSegment.lastChange,
                            (int)manualSegment.lastChangeFrame,
                            Convert.ToInt32(manualSegment.pedestrianEnabled)
                        });
                    }
                }

                if (TrafficLightsTimed.timedScripts.ContainsKey((ushort)i))
                {
                    var timedNode = TrafficLightsTimed.GetTimedLight((ushort)i);

                    configuration.timedNodes.Add(new int[3] {
                        timedNode.nodeID, timedNode.currentStep, timedNode.NumSteps()
                    });

                    var nodeGroup = new ushort[timedNode.nodeGroup.Count];

                    for (var j = 0; j < timedNode.nodeGroup.Count; j++)
                    {
                        nodeGroup[j] = timedNode.nodeGroup[j];
                    }

                    configuration.timedNodeGroups.Add(nodeGroup);

                    for (var j = 0; j < timedNode.NumSteps(); j++)
                    {
                        configuration.timedNodeSteps.Add(new int[2]
                        {
                            timedNode.steps[j].numSteps,
                            timedNode.steps[j].segments.Count
                        });

                        for (var k = 0; k < timedNode.steps[j].segments.Count; k++)
                        {
                            configuration.timedNodeStepSegments.Add(new int[4]
                            {
                                (int)timedNode.steps[j].lightLeft[k],
                                (int)timedNode.steps[j].lightMain[k],
                                (int)timedNode.steps[j].lightRight[k],
                                (int)timedNode.steps[j].lightPedestrian[k],
                            });
                        }
                    }
                }
            }

            for (var i = 0; i < Singleton <NetManager> .instance.m_nodes.m_buffer.Length; i++)
            {
                var nodeFlags = Singleton <NetManager> .instance.m_nodes.m_buffer[i].m_flags;

                if (nodeFlags != 0)
                {
                    if (Singleton <NetManager> .instance.m_nodes.m_buffer[i].Info.m_class.m_service ==
                        ItemClass.Service.Road)
                    {
                        configuration.nodeTrafficLights +=
                            Convert.ToInt16((nodeFlags & NetNode.Flags.TrafficLights) != NetNode.Flags.None);
                        configuration.nodeCrosswalk +=
                            Convert.ToInt16((nodeFlags & NetNode.Flags.Junction) != NetNode.Flags.None);
                    }
                }
            }

            for (var i = 0; i < Singleton <NetManager> .instance.m_lanes.m_buffer.Length; i++)
            {
                var laneSegment = Singleton <NetManager> .instance.m_lanes.m_buffer[i].m_segment;

                if (TrafficPriority.prioritySegments.ContainsKey(laneSegment))
                {
                    configuration.laneFlags += i + ":" + Singleton <NetManager> .instance.m_lanes.m_buffer[i].m_flags + ",";
                }
            }

            Configuration.Serialize(filepath, configuration);
        }
Пример #20
0
        public void OnSaveData()
        {
            if (Debugger.Enabled)
            {
                Debugger.Log("Building Themes: Saving Data...");
            }

            try
            {
                var configuration = new DistrictsConfiguration();

                var themesManager = Singleton <BuildingThemesManager> .instance;
                for (byte i = 0; i < 128; i++)
                {
                    if (!themesManager.IsThemeManagementEnabled(i))
                    {
                        continue;
                    }

                    var themes = themesManager.GetDistrictThemes(i, false);
                    if (themes == null)
                    {
                        continue;;
                    }
                    var themesNames = new string[themes.Count];
                    var j           = 0;
                    foreach (var theme in themes)
                    {
                        themesNames[j] = theme.name;
                        j++;
                    }
                    configuration.Districts.Add(new DistrictsConfiguration.District()
                    {
                        id            = i,
                        blacklistMode = themesManager.IsBlacklistModeEnabled(i),
                        themes        = themesNames
                    });
                    if (Debugger.Enabled)
                    {
                        Debugger.LogFormat("Building Themes: Saving: {0} themes enabled for district {1}", themes.Count, i);
                    }
                }

                if (configuration.Districts.Count > 0)
                {
                    byte[] configurationData;

                    var xmlSerializer          = new XmlSerializer(typeof(DistrictsConfiguration));
                    XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                    ns.Add("", "");
                    using (var memoryStream = new MemoryStream())
                    {
                        xmlSerializer.Serialize(memoryStream, configuration, ns);
                        configurationData = memoryStream.ToArray();
                    }
                    SerializableData.SaveData(XMLSaveDataId, configurationData);

                    // output for debugging

                    /*
                     * using (System.IO.StreamWriter streamWriter = new System.IO.StreamWriter("BuildingThemesData.xml"))
                     * {
                     *  xmlSerializer.Serialize(streamWriter, configuration, ns);
                     * }
                     */
                }

                if (Debugger.Enabled)
                {
                    Debugger.LogFormat("Building Themes: Serialization done.");
                    Debugger.AppendThemeList();
                }
            }

            catch (Exception ex)
            {
                Debugger.LogError("Building Themes: Error saving theme data");
                Debugger.LogException(ex);
            }
        }
        public static void Serialize(ISerializableData serializableData, string dataID, Configuration config)
        {
            config.ComputeHashCodes();
            Debug.Log("serializing to save data");
            Debug.Log(config.ToString());

            var serializer = new XmlSerializer(typeof(Configuration));
            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
            ns.Add("", "");
            RegisterEvents(ref serializer);
            byte[] configData;

            using (var memoryStream = new MemoryStream()) {
                config.OnPreSerialize();
                serializer.Serialize(memoryStream, config, ns);
                configData = memoryStream.ToArray();
            }

            serializableData.SaveData(dataID, configData);
        }
        public override void OnSaveData()
        {
            bool error = false;

            /*try {
             *      Log.Info("Recalculating segment geometries");
             *      SegmentGeometry.OnBeforeSaveData();
             * } catch (Exception e) {
             *      Log.Error($"OnSaveData: Exception occurred while calling SegmentGeometry.OnBeforeSaveData: {e.ToString()}");
             *      error = true;
             * }*/

            try {
                Log.Info("Applying all flags");
                Flags.applyAllFlags();
            } catch (Exception e) {
                Log.Error($"OnSaveData: Exception occurred while applying all flags: {e.ToString()}");
                error = true;
            }

            try {
                Log.Info("Saving Mod Data.");
                var configuration = new Configuration();

                TrafficPriorityManager prioMan = TrafficPriorityManager.Instance();

                if (prioMan.TrafficSegments != null)
                {
                    for (ushort i = 0; i < Singleton <NetManager> .instance.m_segments.m_size; i++)
                    {
                        try {
                            SavePrioritySegment(i, configuration);
                        } catch (Exception e) {
                            Log.Error($"Exception occurred while saving priority segment @ {i}: {e.ToString()}");
                            error = true;
                        }

                        try {
                            SaveSegmentNodeFlags(i, configuration);
                        } catch (Exception e) {
                            Log.Error($"Exception occurred while saving segment node flags @ {i}: {e.ToString()}");
                            error = true;
                        }
                    }
                }

                TrafficLightSimulationManager tlsMan = TrafficLightSimulationManager.Instance();

                for (ushort i = 0; i < Singleton <NetManager> .instance.m_nodes.m_size; i++)
                {
                    /*if (TrafficLightSimulation.LightSimulationByNodeId != null) {
                     *      SaveTrafficLightSimulation(i, configuration);
                     * }*/

                    /*if (TrafficLightsManual.ManualSegments != null) {
                     *      SaveManualTrafficLight(i, configuration);
                     * }*/

                    TrafficLightSimulation sim = tlsMan.GetNodeSimulation(i);
                    if (sim != null && sim.IsTimedLight())
                    {
                        try {
                            SaveTimedTrafficLight(i, configuration);
                        } catch (Exception e) {
                            Log.Error($"Exception occurred while saving timed traffic light @ {i}: {e.ToString()}");
                            error = true;
                        }
                        // TODO save new traffic lights
                    }

                    try {
                        SaveNodeLights(i, configuration);
                    } catch (Exception e) {
                        Log.Error($"Exception occurred while saving node traffic light @ {i}: {e.ToString()}");
                        error = true;
                    }
                }

#if !TAM
                if (LoadingExtension.IsPathManagerCompatible)
                {
#endif
                for (uint i = 0; i < Singleton <NetManager> .instance.m_lanes.m_buffer.Length; i++)
                {
                    try {
                        SaveLaneData(i, configuration);
                    } catch (Exception e) {
                        Log.Error($"Exception occurred while saving lane data @ {i}: {e.ToString()}");
                        error = true;
                    }
                }
#if !TAM
            }
#endif

                foreach (KeyValuePair <uint, ushort> e in Flags.getAllLaneSpeedLimits())
                {
                    try {
                        SaveLaneSpeedLimit(new Configuration.LaneSpeedLimit(e.Key, e.Value), configuration);
                    } catch (Exception ex) {
                        Log.Error($"Exception occurred while saving lane speed limit @ {e.Key}: {ex.ToString()}");
                        error = true;
                    }
                }

                foreach (KeyValuePair <uint, ExtVehicleType> e in Flags.getAllLaneAllowedVehicleTypes())
                {
                    try {
                        SaveLaneAllowedVehicleTypes(new Configuration.LaneVehicleTypes(e.Key, e.Value), configuration);
                    } catch (Exception ex) {
                        Log.Error($"Exception occurred while saving lane vehicle restrictions @ {e.Key}: {ex.ToString()}");
                        error = true;
                    }
                }

                var binaryFormatter = new BinaryFormatter();
                var memoryStream    = new MemoryStream();

                try {
                    binaryFormatter.Serialize(memoryStream, configuration);
                    memoryStream.Position = 0;
                    Log.Info($"Save data byte length {memoryStream.Length}");
                    _serializableData.SaveData(DataId, memoryStream.ToArray());
                } catch (Exception ex) {
                    Log.Error("Unexpected error while saving data: " + ex.ToString());
                    error = true;
                } finally {
                    memoryStream.Close();
                }

                try {
                    // save options
                    _serializableData.SaveData("TMPE_Options", new byte[] {
                        (byte)Options.simAccuracy,
                        (byte)0,                        //Options.laneChangingRandomization,
                        (byte)Options.recklessDrivers,
                        (byte)(Options.relaxedBusses ? 1 : 0),
                        (byte)(Options.nodesOverlay ? 1 : 0),
                        (byte)(Options.allowEnterBlockedJunctions ? 1 : 0),
                        (byte)(Options.advancedAI ? 1 : 0),
                        (byte)(Options.highwayRules ? 1 : 0),
                        (byte)(Options.prioritySignsOverlay ? 1 : 0),
                        (byte)(Options.timedLightsOverlay ? 1 : 0),
                        (byte)(Options.speedLimitsOverlay ? 1 : 0),
                        (byte)(Options.vehicleRestrictionsOverlay ? 1 : 0),
                        (byte)(Options.strongerRoadConditionEffects ? 1 : 0),
                        (byte)(Options.allowUTurns ? 1 : 0),
                        (byte)(Options.allowLaneChangesWhileGoingStraight ? 1 : 0),
                        (byte)(Options.enableDespawning ? 1 : 0),
                        (byte)(Options.IsDynamicPathRecalculationActive() ? 1 : 0),
                        (byte)(Options.connectedLanesOverlay ? 1 : 0),
                        (byte)(Options.prioritySignsEnabled ? 1 : 0),
                        (byte)(Options.timedLightsEnabled ? 1 : 0),
                        (byte)(Options.customSpeedLimitsEnabled ? 1 : 0),
                        (byte)(Options.vehicleRestrictionsEnabled ? 1 : 0),
                        (byte)(Options.laneConnectorEnabled ? 1 : 0),
                        (byte)(Options.junctionRestrictionsOverlay ? 1 : 0),
                        (byte)(Options.junctionRestrictionsEnabled ? 1 : 0)
                    });
                } catch (Exception ex) {
                    Log.Error("Unexpected error while saving options: " + ex.Message);
                    error = true;
                }
            } catch (Exception e) {
                error = true;
                Log.Error($"Error occurred while saving data: {e.ToString()}");
                //UIView.library.ShowModal<ExceptionPanel>("ExceptionPanel").SetMessage("An error occurred while saving", "Traffic Manager: President Edition detected an error while saving. To help preventing future errors, please navigate to http://steamcommunity.com/sharedfiles/filedetails/?id=583429740 and follow the steps under 'In case problems arise'.", true);
            }
        }
Пример #23
0
        public void OnSaveData()
        {
            FastList <byte> data = new FastList <byte>();

//            Debug.Log("OnSaveData() 1");
            GenerateUniqueID();

            byte[] uniqueIdBytes = BitConverter.GetBytes(uniqueID);
            foreach (byte uniqueIdByte in uniqueIdBytes)
            {
                data.Add(uniqueIdByte);
            }
//            Debug.Log("OnSaveData() 2");

            byte[] dataToSave = data.ToArray();
            SerializableData.SaveData(dataID, dataToSave);

//            Debug.Log("OnSaveData() 3");
            var filepath = Path.Combine(Application.dataPath, "trafficManagerSave_" + uniqueID + ".xml");
//            Debug.Log("OnSaveData()");

            var configuration = new Configuration();

//            Debug.Log("OnSaveData() 4");

            configuration.laneFlags         = "";
            configuration.nodeCrosswalk     = "";
            configuration.nodeTrafficLights = "";

            for (var i = 0; i < 32768; i++)
            {
                if (TrafficPriority.prioritySegments.ContainsKey(i))
                {
                    if (TrafficPriority.prioritySegments[i].node_1 != 0)
                    {
                        configuration.prioritySegments.Add(new int[3] {
                            TrafficPriority.prioritySegments[i].node_1,
                            i,
                            (int)TrafficPriority.prioritySegments[i].instance_1.type
                        });
                    }
                    //Debug.Log("OnSaveData() 5");

                    if (TrafficPriority.prioritySegments[i].node_2 != 0)
                    {
                        configuration.prioritySegments.Add(new int[3] {
                            TrafficPriority.prioritySegments[i].node_2,
                            i,
                            (int)TrafficPriority.prioritySegments[i].instance_2.type
                        });
                    }
                }
                //Debug.Log("OnSaveData() 6");

                if (CustomRoadAI.nodeDictionary.ContainsKey((ushort)i))
                {
                    var nodeDict = CustomRoadAI.nodeDictionary[(ushort)i];

                    configuration.nodeDictionary.Add(new int[4] {
                        nodeDict.NodeId,
                        Convert.ToInt32(nodeDict._manualTrafficLights),
                        Convert.ToInt32(nodeDict._timedTrafficLights),
                        Convert.ToInt32(nodeDict.TimedTrafficLightsActive)
                    });
                }
//                Debug.Log("OnSaveData() 7");

                if (TrafficLightsManual.ManualSegments.ContainsKey(i))
                {
                    if (TrafficLightsManual.ManualSegments[i].node_1 != 0)
                    {
                        var manualSegment = TrafficLightsManual.ManualSegments[i].instance_1;

                        configuration.manualSegments.Add(new int[10] {
                            (int)manualSegment.node,
                            manualSegment.segment,
                            (int)manualSegment.currentMode,
                            (int)manualSegment.lightLeft,
                            (int)manualSegment.lightMain,
                            (int)manualSegment.lightRight,
                            (int)manualSegment.lightPedestrian,
                            (int)manualSegment.lastChange,
                            (int)manualSegment.lastChangeFrame,
                            Convert.ToInt32(manualSegment.pedestrianEnabled)
                        });
                    }
                    //Debug.Log("OnSaveData() 8");

                    if (TrafficLightsManual.ManualSegments[i].node_2 != 0)
                    {
                        var manualSegment = TrafficLightsManual.ManualSegments[i].instance_2;
                        //Debug.Log("OnSaveData() 9");

                        configuration.manualSegments.Add(new int[10] {
                            (int)manualSegment.node,
                            manualSegment.segment,
                            (int)manualSegment.currentMode,
                            (int)manualSegment.lightLeft,
                            (int)manualSegment.lightMain,
                            (int)manualSegment.lightRight,
                            (int)manualSegment.lightPedestrian,
                            (int)manualSegment.lastChange,
                            (int)manualSegment.lastChangeFrame,
                            Convert.ToInt32(manualSegment.pedestrianEnabled)
                        });
                    }
                }
//                Debug.Log("OnSaveData() 10");

                if (TrafficLightsTimed.timedScripts.ContainsKey((ushort)i))
                {
                    var timedNode = TrafficLightsTimed.GetTimedLight((ushort)i);

                    configuration.timedNodes.Add(new int[4] {
                        timedNode.nodeID,
                        timedNode.currentStep,
                        timedNode.NumSteps(),
                        Convert.ToInt32(timedNode.isStarted())
                    });

                    var nodeGroup = new ushort[timedNode.nodeGroup.Count];

                    for (var j = 0; j < timedNode.nodeGroup.Count; j++)
                    {
                        nodeGroup[j] = timedNode.nodeGroup[j];
                    }

                    configuration.timedNodeGroups.Add(nodeGroup);

                    for (var j = 0; j < timedNode.NumSteps(); j++)
                    {
                        configuration.timedNodeSteps.Add(new int[2] {
                            timedNode.steps[j].numSteps,
                            timedNode.steps[j].segments.Count
                        });

                        for (var k = 0; k < timedNode.steps[j].segments.Count; k++)
                        {
                            configuration.timedNodeStepSegments.Add(new int[4] {
                                (int)timedNode.steps[j].lightLeft[k],
                                (int)timedNode.steps[j].lightMain[k],
                                (int)timedNode.steps[j].lightRight[k],
                                (int)timedNode.steps[j].lightPedestrian[k],
                            });
                        }
                    }
                }
            }
            //Debug.Log("OnSaveData() 11");

            for (var i = 0; i < Singleton <NetManager> .instance.m_nodes.m_buffer.Length; i++)
            {
                var nodeFlags = Singleton <NetManager> .instance.m_nodes.m_buffer[i].m_flags;

                if (nodeFlags != 0)
                {
                    if (Singleton <NetManager> .instance.m_nodes.m_buffer[i].Info.m_class.m_service ==
                        ItemClass.Service.Road)
                    {
                        configuration.nodeTrafficLights +=
                            Convert.ToInt16((nodeFlags & NetNode.Flags.TrafficLights) != NetNode.Flags.None);
                        configuration.nodeCrosswalk +=
                            Convert.ToInt16((nodeFlags & NetNode.Flags.Junction) != NetNode.Flags.None);
                    }
                }
            }
            //Debug.Log("OnSaveData() 12");

            var laneCount = 0;

            for (var i = 0; i < Singleton <NetManager> .instance.m_lanes.m_buffer.Length; i++)
            {
                var laneSegment = Singleton <NetManager> .instance.m_lanes.m_buffer[i].m_segment;

                if (TrafficPriority.prioritySegments.ContainsKey(laneSegment))
                {
                    configuration.laneFlags += i + ":" + Singleton <NetManager> .instance.m_lanes.m_buffer[i].m_flags + ",";
                    laneCount++;
                }
            }

            if (configuration.laneFlags != null && configuration.laneFlags.Length > 0)
            {
                configuration.laneFlags = configuration.laneFlags.TrimEnd(',');
            }

            configuration.aiConfig.congestionCostFactor   = CustomPathFind.congestionCostFactor;
            configuration.aiConfig.minLaneSpace           = CustomPathFind.minLaneSpace;
            configuration.aiConfig.lookaheadLanes         = CustomPathFind.lookaheadLanes;
            configuration.aiConfig.congestedLaneThreshold = CustomPathFind.congestedLaneThreshold;
            configuration.aiConfig.obeyTMLaneFlags        = CustomPathFind.obeyTMLaneFlags;

            for (var i = 0; i < CSL_Traffic.RoadManager.sm_lanes.Length; i++)
            {
                var lane = CSL_Traffic.RoadManager.sm_lanes[i];
                if (lane != null && lane.ConnectionCount() > 0)
                {
                    configuration.laneMarkers.Add(lane);
                }
            }

            Configuration.Serialize(filepath, configuration);
        }