public override void OnLoadData()
        {
            Log.Warning("Loading Mod Data");
            var keys = _serializableData.EnumerateData().Where(k => k.StartsWith("TrafficManager"));

            byte[] data = null;
            foreach (var key in keys)
            {
                Log.Message($"Checking for save data at key: {key}");
                data = _serializableData.LoadData(key);

                if (data == null || data.Length <= 0)
                {
                    continue;
                }

                Log.Message($"Save Data Found. Deserializing.");
                break;
            }
            if (data == null)
            {
                Log.Message($"No Save Data Found. Possibly a new game?");
                return;
            }
            DeserializeData(data);
        }
예제 #2
0
 public static TLMTransportTypeConfigurations GetLoadData(ISerializableData serializableData, string ID)
 {
     if (ID == null || ToolManager.instance.m_properties.m_mode != ItemClass.Availability.Game)
     {
         LogUtils.DoWarnLog($"Trying to load out of game!");
         return(null);
     }
     if (!serializableData.EnumerateData().Contains(ID))
     {
         LogUtils.DoLog($"Savegame has no legacy {ID} (default)");
         return(null);
     }
     using (var memoryStream = new MemoryStream(serializableData.LoadData(ID)))
     {
         try
         {
             byte[] storage = memoryStream.ToArray();
             var    file    = System.Text.Encoding.UTF8.GetString(storage);
             if (!file.StartsWith("<"))
             {
                 file = ZipUtils.Unzip(storage);
             }
             file = file.Replace(ID.Split('.').Last(), "TransportTypeExtension");
             return(XmlUtils.DefaultXmlDeserialize <TLMTransportTypeConfigurations>(file));
         }
         catch (Exception e)
         {
             LogUtils.DoErrorLog($"Error trying to load legacy TLMTransportTypeExtension (ID = {ID}): {e.Message}\n{e.StackTrace}");
             return(null);
         }
     }
 }
        /// <summary>
        /// Loads the data for the specified identifier using the specified serializable data inteface object.
        /// </summary>
        /// <param name="serializableData">The serializable data.</param>
        /// <param name="id">The identifier.</param>
        private static byte[] Load(ISerializableData serializableData, string id)
        {
            byte[] data = serializableData.LoadData(id);

            if (data == null)
            {
                Log.Debug(typeof(BinaryData), "Load", id, "-");
                return(null);
            }

            Log.Debug(typeof(BinaryData), "Load", id, data.Length);

            if (data.Length > 0)
            {
                if (data.Length < 2)
                {
                    throw new InvalidOperationException("Serialized data corruption");
                }

                if (!FletcherChecksum.Validate(data, 0, data.Length))
                {
                    throw new InvalidOperationException("Serialized data corruption");
                }

                Array.Resize(ref data, data.Length - 2);
            }

            return(data);
        }
예제 #4
0
        public void Deserialize(ISerializableData serializableDataManager)
        {
            if (!serializableDataManager.EnumerateData().Contains(Id))
            {
                return;
            }

            var data = serializableDataManager.LoadData(Id);

            const int versionLength = 4;

            Debug.Assert(data.Length > versionLength);

            var version = BitConverter.ToUInt32(data.Take(versionLength).ToArray(), 0);

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

            Serializer s;

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

            //TODO: Fehlerhandlung?
            s.DeserializeData(data.Skip(versionLength));

            DebugLog.Message("Deserialized {0} bytes", data.Length - 4);
        }
예제 #5
0
        internal void OnLoadData(ISerializableData serializableDataManager)
        {
            var data = serializableDataManager.LoadData(DataID);

            if (data == null || data.Length == 0)
            {
                return;
            }

            var binaryFormatter = new BinaryFormatter();

            using (var memoryStream = new MemoryStream(data)) {
                try {
                    MixID = binaryFormatter.Deserialize(memoryStream) as string;
                } catch (Exception exception) {
                    Debug.LogError(exception);
                }
            }

            if (MixID == null)
            {
                return;
            }
            ThemeMix mix = SerializationService.Instance.GetMix(MixID);

            if (mix != null && !mix.ThemesMissing() && mix.Load())
            {
                CurrentMix = mix;
            }
        }
예제 #6
0
        public void OnLoadData()
        {
            byte[] data = SerializableData.LoadData(dataID);

            if (data == null)
            {
                GenerateUniqueID();
            }
            else
            {
                _timer = new System.Timers.Timer(2000);
                // Hook up the Elapsed event for the timer.
                _timer.Elapsed += OnLoadDataTimed;
                _timer.Enabled  = true;
            }
        }
예제 #7
0
        public void OnLoadData()
        {
            try
            {
                byte[] data = serializableData.LoadData(DataID);

                if (data == null)
                {
                    Debug.Log(Mod.LogMsgPrefix + "No saved data");
                    return;
                }

                using (var stream = new MemoryStream(data))
                {
                    DataSerializer.Deserialize <DisastersContainer.Data>(stream, DataSerializer.Mode.Memory);

                    DataSerializer.Deserialize <EnhancedForestFire.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <EnhancedThunderstorm.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <EnhancedSinkhole.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <EnhancedTsunami.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <EnhancedTornado.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <EnhancedEarthquake.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <EnhancedMeteorStrike.Data>(stream, DataSerializer.Mode.Memory);
                }
            }
            catch (Exception ex)
            {
                Debug.Log(Mod.LogMsgPrefix + "(load error) " + ex.Message);
            }

            Mod.UpdateUI();
        }
예제 #8
0
        public void OnLoadData()
        {
            configLoaded = false;
            byte[] data = SerializableData.LoadData(legacyDataID);
            saveData = SerializableData.LoadData(saveDataID);

            if ((data == null && saveData == null) || LoadingExtension.ignoreSavedData)
            {
                LoadingExtension.ignoreSavedData = false;
                GenerateUniqueID();
            }
            else
            {
                _timer = new System.Timers.Timer(2000);
                // Hook up the Elapsed event for the timer.
                _timer.Elapsed  += OnLoadDataTimed;
                _timer.Enabled   = true;
                _timer.AutoReset = false;
            }
        }
        public void OnLoadData()
        {
            if (Debugger.Enabled)
            {
                Debugger.Log("Building Themes: SerializableDataExtension.OnLoadData was called.");
            }

            byte[] data = SerializableData.LoadData(DataId);

            if (data == null)
            {
                GenerateUniqueId();
            }
            else
            {
                _timer = new Timer(2000);
                // Hook up the Elapsed event for the timer.
                _timer.Elapsed += OnLoadDataTimed;
                _timer.Enabled  = true;
            }
        }
예제 #10
0
        public void OnLoadData()
        {
            byte[] data = serializedData.LoadData(DataID);

            if (data == null)
            {
                return;
            }

            using (var stream = new MemoryStream(data))
            {
                DataSerializer.Deserialize <SavedValues.Data>(stream, DataSerializer.Mode.Memory);
            }
        }
예제 #11
0
        public void LoadData(ISerializableData serialisableDataManager)
        {
            if (serialisableDataManager != null)
            {
                if (_toolBase.ModSettings.ModName != null)
                {
                    byte[] deserialisedData = serialisableDataManager.LoadData(_toolBase.ModSettings.ModName + "Data" + _toolBase.Strings.VERSION);

                    if (deserialisedData != null)
                    {
                        MemoryStream memoryStream = new MemoryStream();
                        memoryStream.Write(deserialisedData, 0, deserialisedData.Length);
                        memoryStream.Position = 0;

                        BinaryFormatter binaryFormatter = new BinaryFormatter();

                        try
                        {
                            string xmlData = binaryFormatter.Deserialize(memoryStream) as string;

                            if (xmlData != null)
                            {
                                StringReader stringReader = new StringReader(xmlData);

                                _toolBase.NamedLogger.Log("Loading data from save file.");

                                _xmlManager.Load(stringReader);

                                _toolBase.DetailedLogger.Log(stringReader.ToString());
                                _toolBase.NamedLogger.Log("Loaded.");
                            }
                        }
                        catch (Exception ex)
                        {
                            _toolBase.NamedLogger.LogError("Failed to load options");
                            Debug.LogException(ex);
                        }
                        finally
                        {
                            memoryStream.Close();
                        }
                    }
                }
            }
            else
            {
                _toolBase.NamedLogger.LogError("The serialisableDataManager passed to LoadData was null. No data was loaded!");
            }
        }
예제 #12
0
        public void OnLoadData()
        {
            byte[] data = serializedData.LoadData(DataID);

            if (data == null)
            {
                Debug.Log("TaxHelperMod >>> No saved data ");
                return;
            }

            using (var stream = new MemoryStream(data))
            {
                DataSerializer.Deserialize <SavedTaxValues.Data>(stream, DataSerializer.Mode.Memory);
            }
        }
        //[XmlIgnore]
        //public IManagers Managers => SerializableDataManager?.managers;
        //[XmlIgnore]
        //public ISerializableData SerializableDataManager { get; private set; }

        //public void OnCreated(ISerializableData serializableData) => SerializableDataManager = serializableData;
        public I GetLoadData(ISerializableData serializableData)
        {
            if (ID == null || Singleton <ToolManager> .instance.m_properties.m_mode != ItemClass.Availability.Game)
            {
                return(null);
            }
            if (!serializableData.EnumerateData().Contains(ID))
            {
                return(null);
            }
            using (var memoryStream = new MemoryStream(serializableData.LoadData(ID)))
            {
                byte[] storage = memoryStream.ToArray();
                return(Deserialize(System.Text.Encoding.UTF8.GetString(storage)));
            }
        }
        public void OnLoadData()
        {
            try
            {
                byte[] data = serializedData.LoadData(DataID);

                if (data == null)
                {
                    Debug.Log(Mod.LogMsgPrefix + "No saved data ");
                    return;
                }

                using (var stream = new MemoryStream(data))
                {
                    DataSerializer.Deserialize <AutobudgetElectricity.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <AutobudgetWater.Data>(stream, DataSerializer.Mode.Memory);
                    if (LastReadDataVersion >= 6)
                    {
                        DataSerializer.Deserialize <AutobudgetHeating.Data>(stream, DataSerializer.Mode.Memory);
                    }
                    DataSerializer.Deserialize <AutobudgetGarbage.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <AutobudgetHealthcare.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <AutobudgetEducation.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <AutobudgetPolice.Data>(stream, DataSerializer.Mode.Memory);
                    if (LastReadDataVersion >= 5)
                    {
                        DataSerializer.Deserialize <AutobudgetIndustry.Data>(stream, DataSerializer.Mode.Memory);
                    }
                    DataSerializer.Deserialize <AutobudgetFire.Data>(stream, DataSerializer.Mode.Memory);
                    DataSerializer.Deserialize <AutobudgetRoad.Data>(stream, DataSerializer.Mode.Memory);
                    if (LastReadDataVersion >= 4)
                    {
                        DataSerializer.Deserialize <AutobudgetPost.Data>(stream, DataSerializer.Mode.Memory);
                    }
                    DataSerializer.Deserialize <AutobudgetTaxi.Data>(stream, DataSerializer.Mode.Memory);
                }
            }
            catch (Exception ex)
            {
                Debug.Log(Mod.LogMsgPrefix + "load error: " + ex.Message);
            }

            Mod.UpdateUI();
            BudgetControlsManager.UpdateControls();
        }
예제 #15
0
        public void Deserialize(ISerializableData serializableDataManager)
        {
            if (!Contains(Id, serializableDataManager))
            {
                DebugLog.Message("Save does not contain data with id {0}", Id);
                return;
            }

            var data = serializableDataManager.LoadData(Id);

            DebugLog.Message("Read {0} bytes for Id {1}", data.Length, Id);

            const int versionLength = 4;

            Debug.Assert(data.Length > versionLength);
            if (data.Length < versionLength)
            {
                throw new InvalidOperationException($"Data with id {Id} should be at least {versionLength} bytes long, but is only {data.Length}B");
            }

            var version = BitConverter.ToUInt32(data.Take(versionLength).ToArray(), 0);

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

            Serializer serializer;

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

            if (serializer.ShouldDeleteData())
            {
                Log.Info($"Deleting saved data because serializer version {version} requested deletion.");
                serializableDataManager.EraseData(Id);
            }
            else
            {
                var rData = data.Skip(versionLength).ToArray();
                serializer.DeserializeData(rData);
                DebugLog.Message("Deserialized {0} bytes", rData.Length);
            }
        }
        public override void OnLoadData()
        {
#if DEBUG
            Loader.DataInit();
            DebugLog.LogToFileOnly("OnLoadData");
            if (true)
            {
                DebugLog.LogToFileOnly("startload");

                MainDataStore.SaveData = _serializableData.LoadData("AdvancedRoadTools MainDataStore");
                if (MainDataStore.SaveData == null)
                {
                    DebugLog.LogToFileOnly("no MainDataStore save data, please check");
                }
                else
                {
                    MainDataStore.Load();
                }
            }
#endif
        }
        public void OnLoadData()
        {
            try
            {
                byte[] data = serializedData.LoadData(DataID);

                if (data == null)
                {
                    Debug.Log("GameSpeedMod: No saved data ");
                    return;
                }

                using (var stream = new MemoryStream(data))
                {
                    DataSerializer.Deserialize <GameSpeedManager.Data>(stream, DataSerializer.Mode.Memory);
                }

                Mod.UpdateUI();
            }
            catch (Exception ex)
            {
                Debug.Log("GameSpeedMod: load error: " + ex.Message);
            }
        }
예제 #18
0
        public void LoadData(ISerializableData serialisableDataManager)
        {
            if (_modSettings.ModName != null)
            {
                byte[] deserialisedData = serialisableDataManager.LoadData(_modSettings.ModName + "Data");

                if (deserialisedData != null)
                {
                    MemoryStream memoryStream = new MemoryStream();
                    memoryStream.Write(deserialisedData, 0, deserialisedData.Length);
                    memoryStream.Position = 0;

                    BinaryFormatter binaryFormatter = new BinaryFormatter();

                    try
                    {
                        string xmlData = binaryFormatter.Deserialize(memoryStream) as string;

                        if (xmlData != null)
                        {
                            StringReader stringReader = new StringReader(xmlData);
                            _xmlManager.Load(stringReader);
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.Log("Failed to load options");
                        Debug.LogException(ex);
                    }
                    finally
                    {
                        memoryStream.Close();
                    }
                }
            }
        }
        public override void OnLoadData()
        {
            Log.Info("Loading Traffic Manager: PE Data");
            StateLoading = true;
            try {
                Log.Info("Initializing flags");
                Flags.OnBeforeLoadData();
                Log.Info("Initializing node geometries");
                NodeGeometry.OnBeforeLoadData();
                Log.Info("Initializing segment geometries");
                SegmentGeometry.OnBeforeLoadData();
                Log.Info("Initializing lane connection manager");
                Singleton <LaneConnectionManager> .instance.OnBeforeLoadData();               // requires segment geometries

                Log.Info("Initializing CustomRoadAI");
                CustomRoadAI.OnBeforeLoadData();
                Log.Info("Initialization done. Loading mod data now.");
                byte[] data = _serializableData.LoadData(DataId);
                DeserializeData(data);

                // load options
                byte[] options = _serializableData.LoadData("TMPE_Options");
                if (options != null)
                {
                    if (options.Length >= 1)
                    {
                        Options.setSimAccuracy(options[0]);
                    }

                    if (options.Length >= 2)
                    {
                        //Options.setLaneChangingRandomization(options[1]);
                    }

                    if (options.Length >= 3)
                    {
                        Options.setRecklessDrivers(options[2]);
                    }

                    if (options.Length >= 4)
                    {
                        Options.setRelaxedBusses(options[3] == (byte)1);
                    }

                    if (options.Length >= 5)
                    {
                        Options.setNodesOverlay(options[4] == (byte)1);
                    }

                    if (options.Length >= 6)
                    {
                        Options.setMayEnterBlockedJunctions(options[5] == (byte)1);
                    }

                    if (options.Length >= 7)
                    {
#if !TAM
                        if (!LoadingExtension.IsPathManagerCompatible)
                        {
                            Options.setAdvancedAI(false);
                        }
                        else
                        {
#endif
                        Options.setAdvancedAI(options[6] == (byte)1);
#if !TAM
                    }
#endif
                    }

                    if (options.Length >= 8)
                    {
                        Options.setHighwayRules(options[7] == (byte)1);
                    }

                    if (options.Length >= 9)
                    {
                        Options.setPrioritySignsOverlay(options[8] == (byte)1);
                    }

                    if (options.Length >= 10)
                    {
                        Options.setTimedLightsOverlay(options[9] == (byte)1);
                    }

                    if (options.Length >= 11)
                    {
                        Options.setSpeedLimitsOverlay(options[10] == (byte)1);
                    }

                    if (options.Length >= 12)
                    {
                        Options.setVehicleRestrictionsOverlay(options[11] == (byte)1);
                    }

                    if (options.Length >= 13)
                    {
                        Options.setStrongerRoadConditionEffects(options[12] == (byte)1);
                    }

                    if (options.Length >= 14)
                    {
                        Options.setAllowUTurns(options[13] == (byte)1);
                    }

                    if (options.Length >= 15)
                    {
                        Options.setAllowLaneChangesWhileGoingStraight(options[14] == (byte)1);
                    }

                    if (options.Length >= 16)
                    {
                        Options.setEnableDespawning(options[15] == (byte)1);
                    }

                    if (options.Length >= 17)
                    {
                        Options.setDynamicPathRecalculation(options[16] == (byte)1);
                    }

                    if (options.Length >= 18)
                    {
                        Options.setConnectedLanesOverlay(options[17] == (byte)1);
                    }
                }
            } catch (Exception e) {
                Log.Error($"OnLoadData: {e.ToString()}");
            } finally {
                StateLoading = false;
            }

            Log.Info("OnLoadData completed.");

            // load toggled traffic lights
            //byte[] trafficLight = _serializableData.LoadData("TMPE_Options");
        }
        public override void OnLoadData()
        {
            Log.Info("Loading Traffic Manager: PE Data");
            StateLoading = true;
            bool loadingSucceeded = true;

            try {
                Log.Info("Initializing flags");
                Flags.OnBeforeLoadData();
            } catch (Exception e) {
                Log.Error($"OnLoadData: Error while initializing Flags: {e.ToString()}");
                loadingSucceeded = false;
            }

            try {
                Log.Info("Initializing node geometries");
                NodeGeometry.OnBeforeLoadData();
            } catch (Exception e) {
                Log.Error($"OnLoadData: Error while initializing NodeGeometry: {e.ToString()}");
                loadingSucceeded = false;
            }

            try {
                Log.Info("Initializing segment geometries");
                SegmentGeometry.OnBeforeLoadData();
            } catch (Exception e) {
                Log.Error($"OnLoadData: Error while initializing SegmentGeometry: {e.ToString()}");
                loadingSucceeded = false;
            }

            try {
                Log.Info("Initializing lane connection manager");
                LaneConnectionManager.Instance().OnBeforeLoadData();                 // requires segment geometries
            } catch (Exception e) {
                Log.Error($"OnLoadData: Error while initializing LaneConnectionManager: {e.ToString()}");
                loadingSucceeded = false;
            }

            try {
                Log.Info("Initializing CustomRoadAI");
                CustomRoadAI.OnBeforeLoadData();
            } catch (Exception e) {
                Log.Error($"OnLoadData: Error while initializing CustomRoadAI: {e.ToString()}");
                loadingSucceeded = false;
            }

            Log.Info("Initialization done. Loading mod data now.");

            try {
                byte[] data = _serializableData.LoadData(DataId);
                DeserializeData(data);
            } catch (Exception e) {
                Log.Error($"OnLoadData: Error while deserializing data: {e.ToString()}");
                loadingSucceeded = false;
            }

            // load options
            try {
                byte[] options = _serializableData.LoadData("TMPE_Options");
                if (options != null)
                {
                    if (options.Length >= 1)
                    {
                        Options.setSimAccuracy(options[0]);
                    }

                    if (options.Length >= 2)
                    {
                        //Options.setLaneChangingRandomization(options[1]);
                    }

                    if (options.Length >= 3)
                    {
                        Options.setRecklessDrivers(options[2]);
                    }

                    if (options.Length >= 4)
                    {
                        Options.setRelaxedBusses(options[3] == (byte)1);
                    }

                    if (options.Length >= 5)
                    {
                        Options.setNodesOverlay(options[4] == (byte)1);
                    }

                    if (options.Length >= 6)
                    {
                        Options.setMayEnterBlockedJunctions(options[5] == (byte)1);
                    }

                    if (options.Length >= 7)
                    {
#if !TAM
                        if (!LoadingExtension.IsPathManagerCompatible)
                        {
                            Options.setAdvancedAI(false);
                        }
                        else
                        {
#endif
                        Options.setAdvancedAI(options[6] == (byte)1);
#if !TAM
                    }
#endif
                    }

                    if (options.Length >= 8)
                    {
                        Options.setHighwayRules(options[7] == (byte)1);
                    }

                    if (options.Length >= 9)
                    {
                        Options.setPrioritySignsOverlay(options[8] == (byte)1);
                    }

                    if (options.Length >= 10)
                    {
                        Options.setTimedLightsOverlay(options[9] == (byte)1);
                    }

                    if (options.Length >= 11)
                    {
                        Options.setSpeedLimitsOverlay(options[10] == (byte)1);
                    }

                    if (options.Length >= 12)
                    {
                        Options.setVehicleRestrictionsOverlay(options[11] == (byte)1);
                    }

                    if (options.Length >= 13)
                    {
                        Options.setStrongerRoadConditionEffects(options[12] == (byte)1);
                    }

                    if (options.Length >= 14)
                    {
                        Options.setAllowUTurns(options[13] == (byte)1);
                    }

                    if (options.Length >= 15)
                    {
                        Options.setAllowLaneChangesWhileGoingStraight(options[14] == (byte)1);
                    }

                    if (options.Length >= 16)
                    {
                        Options.setEnableDespawning(options[15] == (byte)1);
                    }

                    if (options.Length >= 17)
                    {
                        Options.setDynamicPathRecalculation(options[16] == (byte)1);
                    }

                    if (options.Length >= 18)
                    {
                        Options.setConnectedLanesOverlay(options[17] == (byte)1);
                    }

                    if (options.Length >= 19)
                    {
                        Options.setPrioritySignsEnabled(options[18] == (byte)1);
                    }

                    if (options.Length >= 20)
                    {
                        Options.setTimedLightsEnabled(options[19] == (byte)1);
                    }

                    if (options.Length >= 21)
                    {
                        Options.setCustomSpeedLimitsEnabled(options[20] == (byte)1);
                    }

                    if (options.Length >= 22)
                    {
                        Options.setVehicleRestrictionsEnabled(options[21] == (byte)1);
                    }

                    if (options.Length >= 23)
                    {
                        Options.setLaneConnectorEnabled(options[22] == (byte)1);
                    }

                    if (options.Length >= 24)
                    {
                        Options.setJunctionRestrictionsOverlay(options[23] == (byte)1);
                    }

                    if (options.Length >= 25)
                    {
                        Options.setJunctionRestrictionsEnabled(options[24] == (byte)1);
                    }
                }
            } catch (Exception e) {
                Log.Error($"OnLoadData: Error while loading options: {e.ToString()}");
                loadingSucceeded = false;
            }

            if (loadingSucceeded)
            {
                Log.Info("OnLoadData completed successfully.");
            }
            else
            {
                Log.Info("An error occurred while loading.");
                //UIView.library.ShowModal<ExceptionPanel>("ExceptionPanel").SetMessage("An error occurred while loading", "Traffic Manager: President Edition detected an error while loading. Please do NOT save this game under the old filename, otherwise your timed traffic lights, custom lane arrows, etc. are in danger. Instead, please navigate to http://steamcommunity.com/sharedfiles/filedetails/?id=583429740 and follow the steps under 'In case problems arise'.", true);
            }
            StateLoading = false;
        }
예제 #21
0
        public override void OnLoadData()
        {
            Loader.InitData();
            DebugLog.LogToFileOnly("StartLoad");
            //1
            var saveData = _serializableData.LoadData("RealCity RealCityEconomyManager");

            if (saveData == null)
            {
                DebugLog.LogToFileOnly("no RealCity RealCityEconomyManager, please check");
            }
            else
            {
                RealCityEconomyManager.Load(ref saveData);
            }

            //2
            saveData = _serializableData.LoadData("RealCity MainDataStore");
            if (saveData == null)
            {
                DebugLog.LogToFileOnly("no RealCity MainDataStore, please check");
            }
            else
            {
                MainDataStore.Load(ref saveData);
            }

            //3
            saveData = _serializableData.LoadData("RealCity RealCityResidentAI");
            if (saveData == null)
            {
                DebugLog.LogToFileOnly("no RealCity RealCityResidentAI, please check");
            }
            else
            {
                RealCityResidentAI.Load(ref saveData);
            }

            //4
            saveData = _serializableData.LoadData("RealCity RealCityPrivateBuildingAI");
            if (saveData == null)
            {
                DebugLog.LogToFileOnly("no RealCity RealCityPrivateBuildingAI, please check");
            }
            else
            {
                RealCityPrivateBuildingAI.Load(ref saveData);
            }

            //5
            saveData = _serializableData.LoadData("RealCity CitizenData");
            if (saveData == null)
            {
                DebugLog.LogToFileOnly("no RealCity CitizenData, please check");
            }
            else
            {
                CitizenData.Load(ref saveData);
            }

            //6
            saveData = _serializableData.LoadData("RealCity Politics");
            if (saveData == null)
            {
                DebugLog.LogToFileOnly("no RealCity Politics, please check");
            }
            else
            {
                Politics.Load(ref saveData);
            }

            //7
            saveData = _serializableData.LoadData("RealCity TransportLineData");
            if (saveData == null)
            {
                DebugLog.LogToFileOnly("no RealCity TransportLineData, please check");
            }
            else
            {
                TransportLineData.Load(ref saveData);
            }

            //8
            saveData = _serializableData.LoadData("RealCity BuildingData");
            if (saveData == null)
            {
                DebugLog.LogToFileOnly("no RealCity BuildingData, please check");
            }
            else
            {
                BuildingData.Load(ref saveData);
            }

            //9
            saveData = _serializableData.LoadData("RealCity VehicleData");
            if (saveData == null)
            {
                DebugLog.LogToFileOnly("no RealCity VehicleData, please check");
            }
            else
            {
                VehicleData.Load(ref saveData);
            }

            //10
            saveData = _serializableData.LoadData("RealCity CitizenUnitData");
            if (saveData == null)
            {
                DebugLog.LogToFileOnly("no RealCity CitizenUnitData, please check");
            }
            else
            {
                CitizenUnitData.Load(ref saveData);
            }
        }
예제 #22
0
        public void OnLoadData()
        {
            try
            {
                byte[] saveData = SerializableData.LoadData(XMLSaveDataId);

                if (saveData != null)
                {
                    if (Debugger.Enabled)
                    {
                        Debugger.Log("Building Themes: Loading Save Data...");
                    }

                    DistrictsConfiguration configuration = null;

                    var xmlSerializer = new XmlSerializer(typeof(DistrictsConfiguration));
                    using (var memoryStream = new MemoryStream(saveData))
                    {
                        configuration = xmlSerializer.Deserialize(new MemoryStream(saveData)) as DistrictsConfiguration;
                    }

                    ApplyConfiguration(configuration);
                }
                else
                {
                    // search for legacy save data
                    byte[] legacyData = SerializableData.LoadData(LegacyDataId);

                    if (legacyData != null)
                    {
                        if (Debugger.Enabled)
                        {
                            Debugger.Log("Building Themes: Loading Legacy Save Data...");
                        }

                        var UniqueId = 0u;

                        for (var i = 0; i < legacyData.Length - 3; i++)
                        {
                            UniqueId = BitConverter.ToUInt32(legacyData, i);
                        }

                        Debug.Log(UniqueId);

                        var filepath = Path.Combine(Application.dataPath, String.Format("buildingThemesSave_{0}.xml", UniqueId));

                        Debug.Log(filepath);

                        if (!File.Exists(filepath))
                        {
                            if (Debugger.Enabled)
                            {
                                Debugger.Log(filepath + " not found!");
                            }
                            return;
                        }

                        DistrictsConfiguration configuration;

                        var serializer = new XmlSerializer(typeof(DistrictsConfiguration));
                        try
                        {
                            using (var reader = new StreamReader(filepath))
                            {
                                configuration = (DistrictsConfiguration)serializer.Deserialize(reader);
                            }
                        }
                        catch
                        {
                            configuration = null;
                        }

                        ApplyConfiguration(configuration);
                    }
                    else
                    {
                        if (Debugger.Enabled)
                        {
                            Debugger.Log("No legacy save data found!");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debugger.LogError("Building Themes: Error loading theme data");
                Debugger.LogException(ex);
            }
        }
        public override void OnLoadData()
        {
            Log.Info("Loading Traffic Manager: PE Data");
            StateLoading = true;
            bool loadingSucceeded = true;

            try {
                Log.Info("Initializing flags");
                Flags.OnBeforeLoadData();
            } catch (Exception e) {
                Log.Error($"OnLoadData: Error while initializing Flags: {e.ToString()}");
                loadingSucceeded = false;
            }

            try {
                Log.Info("Initializing node geometries");
                NodeGeometry.OnBeforeLoadData();
            } catch (Exception e) {
                Log.Error($"OnLoadData: Error while initializing NodeGeometry: {e.ToString()}");
                loadingSucceeded = false;
            }

            try {
                Log.Info("Initializing segment geometries");
                SegmentGeometry.OnBeforeLoadData();
            } catch (Exception e) {
                Log.Error($"OnLoadData: Error while initializing SegmentGeometry: {e.ToString()}");
                loadingSucceeded = false;
            }

            foreach (ICustomManager manager in LoadingExtension.RegisteredManagers)
            {
                try {
                    Log.Info($"OnBeforeLoadData: {manager.GetType().Name}");
                    manager.OnBeforeLoadData();
                } catch (Exception e) {
                    Log.Error($"OnLoadData: Error while initializing {manager.GetType().Name}: {e.ToString()}");
                    loadingSucceeded = false;
                }
            }

            Log.Info("Initialization done. Loading mod data now.");

            try {
                byte[] data = _serializableData.LoadData(DataId);
                DeserializeData(data);
            } catch (Exception e) {
                Log.Error($"OnLoadData: Error while deserializing data: {e.ToString()}");
                loadingSucceeded = false;
            }

            // load options
            try {
                byte[] options = _serializableData.LoadData("TMPE_Options");
                if (options != null)
                {
                    if (!OptionsManager.Instance.LoadData(options))
                    {
                        loadingSucceeded = false;
                    }
                }
            } catch (Exception e) {
                Log.Error($"OnLoadData: Error while loading options: {e.ToString()}");
                loadingSucceeded = false;
            }

            if (loadingSucceeded)
            {
                Log.Info("OnLoadData completed successfully.");
            }
            else
            {
                Log.Info("An error occurred while loading.");
                //UIView.library.ShowModal<ExceptionPanel>("ExceptionPanel").SetMessage("An error occurred while loading", "Traffic Manager: President Edition detected an error while loading. Please do NOT save this game under the old filename, otherwise your timed traffic lights, custom lane arrows, etc. are in danger. Instead, please navigate to http://steamcommunity.com/sharedfiles/filedetails/?id=583429740 and follow the steps under 'In case problems arise'.", true);
            }

            StateLoading = false;

            foreach (ICustomManager manager in LoadingExtension.RegisteredManagers)
            {
                try {
                    Log.Info($"OnAfterLoadData: {manager.GetType().Name}");
                    manager.OnAfterLoadData();
                } catch (Exception e) {
                    Log.Error($"OnLoadData: Error while initializing {manager.GetType().Name}: {e.ToString()}");
                    loadingSucceeded = false;
                }
            }
        }
예제 #24
0
        public override void OnLoadData()
        {
            base.OnLoadData();

            CODebug.Log(LogChannel.Modding, Mod.modName + " - try loading data");

            //			if (s_info == null) {
            //				s_info
            //			}

            try {
                if (m_serializedData != null)
                {
                    byte[] data2 = m_serializedData.LoadData(RESILIENTS_VERSION_ID);
                    if (data2 != null)
                    {
                        BinaryFormatter bFormatter = new BinaryFormatter();
                        MemoryStream    mStream    = new MemoryStream(data2);
                        s_savedDataVersion = (int)bFormatter.Deserialize(mStream);
                    }
                    else
                    {
                        //save had no data
                    }

                    if (s_savedDataVersion >= 0 && s_savedDataVersion <= SAVE_DATA_VERSION)
                    {
                        byte[] data = m_serializedData.LoadData(RESILIENTS_DATA_ID);
                        if (data != null)
                        {
                            BinaryFormatter bFormatter = new BinaryFormatter();
                            MemoryStream    mStream    = new MemoryStream(data);
                            switch (s_savedDataVersion)
                            {
                            case 0:
                                List <ResilientBuildings.ResilientInfo> legacyList = (List <ResilientBuildings.ResilientInfo>)bFormatter.Deserialize(mStream);
                                s_data = convertVersionZeroListToOne(legacyList);
                                break;

                            case 1:
                            case 2:
                            case 3:
                                s_data = (List <ResilientBuildings.ResilientInfoV1>)bFormatter.Deserialize(mStream);
                                break;
                            }

                            CODebug.Log(LogChannel.Modding, Mod.modName + " - successful loading buildings data");
                        }
                        else
                        {
                        }

                        data = m_serializedData.LoadData(RESILIENTS_DISTRICTS_ID);
                        if (data != null)
                        {
                            BinaryFormatter bFormatter = new BinaryFormatter();
                            MemoryStream    mStream    = new MemoryStream(data);
                            switch (s_savedDataVersion)
                            {
                            case 3:
                                s_districts = (List <ResilientBuildings.ResilientDistrict>)bFormatter.Deserialize(mStream);
                                break;
                            }

                            CODebug.Log(LogChannel.Modding, Mod.modName + " - successful loading districts data");
                        }
                        else
                        {
                        }

                        data = m_serializedData.LoadData(RESILIENTS_SETTINGS_ID);
                        if (data != null)
                        {
                            BinaryFormatter bFormatter = new BinaryFormatter();
                            MemoryStream    mStream    = new MemoryStream(data);
                            switch (s_savedDataVersion)
                            {
                            case 2:
                            case 3:
                                Settings.inst = (ResilientSettings)bFormatter.Deserialize(mStream);
                                break;
                            }

                            CODebug.Log(LogChannel.Modding, Mod.modName + " - successful loading settings");
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        CODebug.Error(LogChannel.Modding, Mod.modName + " - invalid saved data version");
                    }
                }
            } catch (Exception e) {
                CODebug.Log(LogChannel.Modding, Mod.modName + " - Error loading data " + e.Message);
            }
        }