Пример #1
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);
                }
            }
        }
Пример #2
0
        public void Deserialize(ByteBuffer byteBuffer)
        {
            /// length field is useless here, just skip it.
            byteBuffer.position = byteBuffer.position + NetMessage.LEN_SIZE;

            short dataType = _deserializeHeader(byteBuffer);

            switch (dataType)
            {
            case _DataTypes.EMPTY_OBJECT:
                _data = new EmptyObject();
                break;

            case _DataTypes.SIMPLE_ARRAY:
                _data = new SimpleArray();
                break;

            case _DataTypes.SIMPLE_OBJECT:
                _data = new SimpleObject();
                break;

            case _DataTypes.POJO_OBJECT:
                _data = new PojoObject();
                break;
            }

            _data.Deserialize(byteBuffer);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #6
0
        public void Serialize(ISerializableData serializableDataManager)
        {
            //get newest version
            var version = Serializers.Keys.Max();

            Serialize(serializableDataManager, version);
        }
Пример #7
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 override void Initialize(ISerializableData data)
 {
     if (data != null)
     {
         FillFromSerializableData(data);
     }
 }
Пример #9
0
        static void InitializeAppSettings(ISerializableData data, IDataSerializationAdapter dataFormatter, Action onInitializeCompleted = null, Action onInitializeFailed = null)
        {
            bool isInitialized = true;

            try
            {
                AppSettings.Database.DataFormatter = dataFormatter;
                AppSettings.Database.Initialize(data);

                isInitialized = true;
            }
            catch
            {
                isInitialized = false;
            }

            if (isInitialized)
            {
                m_AppSettingsInitializationStatus = InitializationStatus.Initialized;
                onInitializeCompleted?.Invoke();
            }
            else
            {
                UninitializeAppSettings();

                Debug.LogWarning("AppSettings can't be initialized.");

                m_AppSettingsInitializationStatus = InitializationStatus.Failed;
                onInitializeFailed?.Invoke();
            }
        }
Пример #10
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;
            }
        }
        public override void FillFromSerializableData(ISerializableData data)
        {
            var appStatsData = data as DefaultLocalizationSettingsSerializableData;

            m_textLanguage  = appStatsData.textLanguage;
            m_voiceLanguage = appStatsData.voiceLanguage;
        }
Пример #12
0
        public CorporationsSaveData CreateSaveData(ISerializableData serializableData)
        {
            CitiesCorporations.Utils.LogHelper.LogFormat("Saving {0}", (object)serializableData);
            CorporationsSaveData saveData = new CorporationsSaveData(serializableData);

            saveData.MissionList = MissionManager.MissionList;
            return(saveData);
        }
        public void OnCreated(ISerializableData serializedData)
        {
            #if DEBUG
            Logger.Info("SerializableDataExtension Created");
            #endif

            this.sd = serializedData;
        }
Пример #14
0
        public override void FillFromSerializableData(ISerializableData data)
        {
            var appStatsData = data as DefaultPostProcessingSettingsSerializableData;

            m_bloom        = appStatsData.bloom;
            m_colorGrading = appStatsData.colorGrading;
            m_vignette     = appStatsData.vignette;
        }
Пример #15
0
 public static void DeleteAllData(ISerializableData serializableDataManager)
 {
     // test for contains is unnecessary
     if (Contains(Id, serializableDataManager))
     {
         Log.Info($"Removing data with ID {Id}");
         serializableDataManager.EraseData(Id);
     }
 }
        public override void FillFromSerializableData(ISerializableData data)
        {
            var appStatsData = data as DefaultAppStatsSettingsSerializableData;

            m_fps          = appStatsData.fps;
            m_ram          = appStatsData.ram;
            m_audio        = appStatsData.audio;
            m_advancedInfo = appStatsData.advancedInfo;
        }
Пример #17
0
        public _NetRPCReturn(short rpcType, ushort rpcID, ISerializableData data) : base()
        {
            _headerType = HeaderType.RPCReturn;

            _rpcID = rpcID;
            _data  = data;

            this.type = rpcType;
        }
        public override void FillFromSerializableData(ISerializableData data)
        {
            var appStatsData = data as DefaultAudioSettingsSerializableData;

            m_music       = appStatsData.music;
            m_musicVolume = appStatsData.musicVolume;
            m_sfxs        = appStatsData.sfxs;
            m_sfxsVolume  = appStatsData.sfxsVolume;
        }
Пример #19
0
 private void SaveLevel(ISerializableData serializeData)
 {
     try
     {
         SerializerManager.Serialize(serializeData);
     }
     catch (Exception e)
     {
         Log.Error($"Error while saving data: {e.Message}");
     }
 }
Пример #20
0
        public override void OnCreated(ISerializableData serializableData)
        {
            base.OnCreated(serializableData);
            Instance = this;

            RenderManagerDetour.EventUpdateDataPost += OnUpdateData;

            NetManagerDetour.EventSegmentCreate       += OnSegmentCreate;
            NetManagerDetour.EventSegmentRelease      += OnSegmentRelease;
            NetManagerDetour.EventSegmentTransferData += OnSegmentTransferData;
        }
    public void OnSerializeLinks(ref ISerializableData data)
    {
        var d = data as Data;

        d.value = 666;

        if (child)
        {
            d.childId = Serializer.e.GetIdOf(child);
        }
    }
        public override void OnCreated(ISerializableData serializableData)
        {
            RICOInstanceData = new RICOInstanceData[63000];

            for (uint i = 0; i < 62000; i++)
            {
                RICOInstanceData[i] = new RICOInstanceData();
            }

            base.OnCreated(serializableData);
        }
Пример #23
0
        public override void OnCreated(ISerializableData serializableData)
        {
            base.OnCreated(serializableData);
            Instance = this;

            RenderManagerDetour.EventUpdateDataPost += OnUpdateData;

            NetManagerDetour.EventSegmentCreate += OnSegmentCreate;
            NetManagerDetour.EventSegmentRelease += OnSegmentRelease;
            NetManagerDetour.EventSegmentTransferData += OnSegmentTransferData;
        }
        public static CorporationsSaveData CreateLoadData(ISerializableData serializableData)
        {
            LogHelper.Log("Loadings");
            CorporationsSaveData data = new CorporationsSaveData(serializableData);

            LogHelper.Log("Data created");
            data.Load();

            LogHelper.Log("Data created");
            UnityEngine.Debug.Break();
            return(data);
        }
Пример #25
0
        void ISerializableDataExtension.OnCreated(ISerializableData serializedData)
        {
            Log.Output = new FileLogger(ModDllPath + ".log");

            _managers = serializedData.managers;

            _settings = new AutosaveSettings(ModDllPath);

            RestartTimer();

            Log.Info("{0} running with interval {1}min...", Name, _settings.Interval);
        }
Пример #26
0
 //This get fired once per app 'Session'
 //It does not fire once per each map load unless you exit to mainmenu.
 public override void OnCreated(ISerializableData serializedData)
 {
     if (OptionsWrapper <Configuration> .Options.IsLoggingEnabled())
     {
         Logger.dbgLog("Oncreated() fired  " + DateTime.Now.ToString(Mod.DTMilli));
     }
     try
     {
         DataExtension._serializableData = serializedData;
     }
     catch (Exception ex)
     { Logger.dbgLog(ex.ToString()); }
 }
Пример #27
0
        public override void OnCreated(ISerializableData serializableData)
        {
            _serializableData = serializableData;

            Log._Debug("SerializableDataExtension.OnCreated() called");

            if (LoadingExtension.Instance.InGameHotReload)
            {
                Log._Debug("HOT RELOAD ...");
                OnLoadData();
                LoadingExtension.Instance.OnLevelLoaded(LoadMode.LoadGame);
            }
        }
 public override void LoadDefaults(ISerializableData serializableData)
 {
     base.LoadDefaults(serializableData);
     foreach (var entry in legacyLinks)
     {
         var legacyData = TLMTransportTypeConfigurations.GetLoadData(serializableData, entry.Key);
         if (legacyData != null)
         {
             LogUtils.DoWarnLog($"Loaded transport type extension from legacy: {entry.Key} to {entry.Value}");
             m_cachedList[entry.Value.Id ?? 0] = legacyData;
         }
     }
 }
Пример #29
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BinaryData"/> class.
        /// </summary>
        /// <param name="serializableData">The serializable data interface object.</param>
        /// <param name="id">The identifier.</param>
        public BinaryData(ISerializableData serializableData, string id)
        {
            this.isWriteable = false;

            try
            {
                this.serializedData = Load(serializableData, id);
            }
            catch (Exception ex)
            {
                Log.Error(this, "Load", ex);
                this.DeserializationError = true;
            }
        }
Пример #30
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!");
            }
        }
Пример #31
0
        /// <summary>
        /// Ignore identifier, don't need here
        /// </summary>
        /// <param name="identifier"></param>
        /// <param name="content"></param>
        /// <param name="onSaveCompleted"></param>
        /// <param name="onSaveFailed"></param>
        public override void Save(string identifier, ISerializableData content, Action onSaveCompleted = null, Action onSaveFailed = null)
        {
            var playerPrefsPairs = content as IPlayerPrefsActions;

            if (playerPrefsPairs != null)
            {
                playerPrefsPairs.Save(m_encrypted);

                onSaveCompleted?.Invoke();
            }
            else
            {
                onSaveFailed?.Invoke();
            }
        }
 public void OnCreated(ISerializableData serializableData)
 {
     UniqueId = 0u;
     SerializableData = serializableData;
 }
Пример #33
0
 public override void OnCreated(ISerializableData serializableData)
 {
     base.OnCreated(serializableData);
     instance = this;
 }
        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);
        }
 //Thread: Main
 public override void OnCreated(ISerializableData serializedData)
 {
     ChirpLog.Debug("ISerialization Created");
 }
		public override void OnCreated(ISerializableData serializableData) {
			_serializableData = serializableData;
		}
 public void OnCreated(ISerializableData serializableData)
 {
     SerializableData = serializableData;
 }
 public void OnCreated(ISerializableData serializableData)
 {
     uniqueID = 0u;
     SerializableData = serializableData;
     loaded = false;
 }
Пример #39
0
 public void OnCreated(ISerializableData data)
 {
     Debug.PrintMessage ("OnCreated");
     m_dataSerializer = data;
 }