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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
         }
     }
 }
        //[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)));
            }
        }
Exemplo n.º 5
0
 private static bool Contains(string id, ISerializableData serializableDataManager)
 => serializableDataManager.EnumerateData().Contains(id);