private static void DeserializeData(byte[] data) { try { if (data != null && data.Length != 0) { Log.Info("Loading Data from New Load Routine!"); var memoryStream = new MemoryStream(); memoryStream.Write(data, 0, data.Length); memoryStream.Position = 0; var binaryFormatter = new BinaryFormatter(); _configuration = (Configuration)binaryFormatter.Deserialize(memoryStream); } else { Log.Warning("No data to deserialize!"); } } catch (Exception e) { Log.Error($"Error deserializing data: {e.Message}"); } LoadDataState(); Flags.clearHighwayLaneArrows(); Flags.applyAllFlags(); VehicleStateManager.InitAllVehicles(); }
private static void onHighwayRulesChanged(bool newHighwayRules) { if (!checkGameLoaded()) { return; } #if !TAM if (!LoadingExtension.IsPathManagerCompatible) { if (newHighwayRules) { setAdvancedAI(false); setDynamicPathRecalculation(false); setHighwayRules(false); UIView.library.ShowModal <ExceptionPanel>("ExceptionPanel").SetMessage(Translation.GetString("Advanced_AI_cannot_be_activated"), Translation.GetString("The_Advanced_Vehicle_AI_cannot_be_activated"), false); } } else { #endif Log._Debug($"Highway rules changed to {newHighwayRules}"); highwayRules = newHighwayRules; Flags.clearHighwayLaneArrows(); Flags.applyAllFlags(); if (newHighwayRules) { setAdvancedAI(true); } #if !TAM } #endif }
private static void onHighwayRulesChanged(bool newHighwayRules) { if (!checkGameLoaded()) { return; } Log._Debug($"Highway rules changed to {newHighwayRules}"); highwayRules = newHighwayRules; Flags.clearHighwayLaneArrows(); Flags.applyAllFlags(); }
private static void DeserializeData(byte[] data) { bool error = false; try { if (data != null && data.Length != 0) { Log.Info("Loading Data from New Load Routine!"); var memoryStream = new MemoryStream(); memoryStream.Write(data, 0, data.Length); memoryStream.Position = 0; var binaryFormatter = new BinaryFormatter(); _configuration = (Configuration)binaryFormatter.Deserialize(memoryStream); } else { Log.Warning("No data to deserialize!"); } } catch (Exception e) { Log.Error($"Error deserializing data: {e.ToString()}"); error = true; } if (!error) { LoadDataState(out error); } try { Flags.clearHighwayLaneArrows(); } catch (Exception e) { Log.Error($"Error while clearing highway lane arrows: {e.ToString()}"); } try { Flags.applyAllFlags(); } catch (Exception e) { Log.Error($"Error while applying all flags: {e.ToString()}"); } try { VehicleStateManager.Instance().InitAllVehicles(); } catch (Exception e) { Log.Error($"Error while initializing all vehicles: {e.ToString()}"); } if (error) { throw new ApplicationException("An error occurred while loading"); } }
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); } }