Exemplo n.º 1
0
        public override void OnSaveData()
        {
            LoggerUtils.Log("Saving props");

            BinaryFormatter binaryFormatter  = new BinaryFormatter();
            MemoryStream    propMemoryStream = new MemoryStream();

            try
            {
                PropWrapper[] propInfos = PropUnlimiterManager.instance.GetAllPropWrappers();
                if (propInfos != null)
                {
                    binaryFormatter.Serialize(propMemoryStream, propInfos);
                    serializableDataManager.SaveData(dataKey, propMemoryStream.ToArray());
                    LoggerUtils.Log("Props have been saved!");
                }
                else
                {
                    LoggerUtils.LogWarning("Couldn't save props, as the array is null!");
                }
            }
            catch (Exception e)
            {
                LoggerUtils.LogError(e);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load all options from the disk.
        /// </summary>
        public static void LoadPropInfo()
        {
            if (File.Exists("BAPropPositioningInfo.xml"))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(PropPositioningInfoObject[]), new XmlRootAttribute()
                {
                    ElementName = "PropPositioningInfo"
                });
                StreamReader reader = new StreamReader("BAPropPositioningInfo.xml");
                Dictionary <string, PropPositioningInfo> routeShieldDict = ((PropPositioningInfoObject[])serializer.Deserialize(reader)).ToDictionary(i => i.key, i => i.value);
                reader.Close();

                if (routeShieldDict != null)
                {
                    Instance().propPositioningDict = routeShieldDict;

                    LoggerUtils.Log("Loaded prop position info file.");
                }
                else
                {
                    Instance().propPositioningDict = fallbackDict;
                    LoggerUtils.LogError("Created prop position file is invalid!");
                }
            }
            else
            {
                Instance().propPositioningDict = fallbackDict;
                LoggerUtils.LogWarning("Could not load the prop position file!");
            }
        }
Exemplo n.º 3
0
        public override void OnSaveData()
        {
            LoggerUtils.Log("Saving routes and signs");

            BinaryFormatter binaryFormatter         = new BinaryFormatter();
            MemoryStream    routeMemoryStream       = new MemoryStream();
            MemoryStream    signMemoryStream        = new MemoryStream();
            MemoryStream    dynamicSignMemoryStream = new MemoryStream();

            try
            {
                RouteContainer[]       routeNames   = RouteManager.Instance().SaveRoutes();
                SignContainer[]        signs        = RouteManager.Instance().m_signList.ToArray();
                DynamicSignContainer[] dynamicSigns = RouteManager.Instance().m_dynamicSignList.ToArray();

                if (routeNames != null)
                {
                    binaryFormatter.Serialize(routeMemoryStream, routeNames);
                    serializableDataManager.SaveData(routeDataKey, routeMemoryStream.ToArray());
                    LoggerUtils.Log("Routes have been saved!");
                }
                else
                {
                    LoggerUtils.LogWarning("Couldn't save routes, as the array is null!");
                }

                if (signs != null)
                {
                    binaryFormatter.Serialize(signMemoryStream, signs);
                    serializableDataManager.SaveData(signDataKey, signMemoryStream.ToArray());
                    LoggerUtils.Log("Signs have been saved!");
                }
                else
                {
                    LoggerUtils.LogWarning("Couldn't save signs, as the array is null!");
                }

                if (dynamicSignMemoryStream != null)
                {
                    binaryFormatter.Serialize(dynamicSignMemoryStream, dynamicSigns);
                    serializableDataManager.SaveData(dynamicSignDataKey, dynamicSignMemoryStream.ToArray());
                    LoggerUtils.Log("Dynamic signs have been saved!");
                }
                else
                {
                    LoggerUtils.LogWarning("Couldn't save dynamic signs, as the array is null!");
                }
            }
            catch (Exception ex)
            {
                LoggerUtils.LogException(ex);
            }
            finally
            {
                routeMemoryStream.Close();
            }
        }
        public override void OnSaveData()
        {
            LoggerUtils.Log("Saving Screen Objects");

            BinaryFormatter binaryFormatter    = new BinaryFormatter();
            MemoryStream    propDictStream     = new MemoryStream();
            MemoryStream    buildingDictStream = new MemoryStream();

            try
            {
                ScreenObj[] propDict     = ScreenManager.instance.saveScreen(true);
                ScreenObj[] buildingDict = ScreenManager.instance.saveScreen(false);

                if (propDict != null)
                {
                    binaryFormatter.Serialize(propDictStream, propDict);
                    serializableDataManager.SaveData(propDictKey, propDictStream.ToArray());
                    LoggerUtils.Log("Prop screen objs have been saved!");
                }
                else
                {
                    LoggerUtils.LogWarning("Couldn't save props, as the array is null!");
                }


                if (buildingDict != null)
                {
                    binaryFormatter.Serialize(buildingDictStream, buildingDict);
                    serializableDataManager.SaveData(buildingDictKey, buildingDictStream.ToArray());
                    LoggerUtils.Log("building screen objs have been saved!");
                }
                else
                {
                    LoggerUtils.LogWarning("Couldn't save buildings, as the array is null!");
                }
            }
            catch (Exception ex)
            {
                LoggerUtils.LogException(ex);
            }
            finally
            {
                buildingDictStream.Close();
                propDictStream.Close();
            }
        }
Exemplo n.º 5
0
        public override void OnLoadData()
        {
            LoggerUtils.Log("Loading data");
            BinaryFormatter binaryFormatter = new BinaryFormatter();

            lock (thisLock)
            {
                byte[] loadedPropData = serializableDataManager.LoadData(dataKey);
                LoggerUtils.Log("Props loaded, parsing data");
                if (loadedPropData != null && loadedPropData.Length > 0)
                {
                    MemoryStream memoryStream = new MemoryStream(loadedPropData);

                    try
                    {
                        PropWrapper[] props = binaryFormatter.Deserialize(memoryStream) as PropWrapper[];

                        if (props != null && props.Length > 0)
                        {
                            PropUnlimiterManager.instance.LoadWrappers(props.ToList());
                        }
                        else
                        {
                            LoggerUtils.LogWarning("Couldn't load props, as the array is null!");
                        }
                    }
                    catch (Exception ex)
                    {
                        LoggerUtils.LogException(ex);
                    }
                    finally
                    {
                        memoryStream.Close();
                    }
                }
                else
                {
                    LoggerUtils.LogWarning("Found no data to load");
                }
            }
        }
Exemplo n.º 6
0
        public override void OnLoadData()
        {
            LoggerUtils.Log("Loading routes");

            byte[] loadedRouteData       = serializableDataManager.LoadData(routeDataKey);
            byte[] loadedSignData        = serializableDataManager.LoadData(signDataKey);
            byte[] loadedDynamicSignData = serializableDataManager.LoadData(dynamicSignDataKey);

            if (loadedRouteData != null)
            {
                MemoryStream routeMemoryStream = new MemoryStream();

                routeMemoryStream.Write(loadedRouteData, 0, loadedRouteData.Length);
                routeMemoryStream.Position = 0;

                BinaryFormatter binaryFormatter = new BinaryFormatter();

                try
                {
                    RouteContainer[] routeNames = binaryFormatter.Deserialize(routeMemoryStream) as RouteContainer[];

                    if (routeNames != null)
                    {
                        RouteManager.Instance().Load(routeNames);
                    }
                    else
                    {
                        LoggerUtils.LogWarning("Couldn't load routes, as the array is null!");
                    }
                }
                catch (Exception ex)
                {
                    LoggerUtils.LogException(ex);
                }
                finally
                {
                    routeMemoryStream.Close();
                }
            }
            else
            {
                LoggerUtils.LogWarning("Found no data to load");
            }

            if (loadedSignData != null)
            {
                MemoryStream signMemoryStream = new MemoryStream();

                signMemoryStream.Write(loadedSignData, 0, loadedSignData.Length);
                signMemoryStream.Position = 0;

                BinaryFormatter binaryFormatter = new BinaryFormatter();

                try
                {
                    SignContainer[] signNames = binaryFormatter.Deserialize(signMemoryStream) as SignContainer[];

                    if (signNames != null)
                    {
                        RouteManager.Instance().LoadSigns(signNames);
                    }
                    else
                    {
                        LoggerUtils.LogWarning("Couldn't load routes, as the array is null!");
                    }
                }
                catch (Exception ex)
                {
                    LoggerUtils.LogException(ex);
                }
                finally
                {
                    signMemoryStream.Close();
                }
            }
            else
            {
                LoggerUtils.LogWarning("Found no data to load");
            }

            if (loadedDynamicSignData != null)
            {
                MemoryStream dynamicSignMemoryStream = new MemoryStream();

                dynamicSignMemoryStream.Write(loadedDynamicSignData, 0, loadedDynamicSignData.Length);
                dynamicSignMemoryStream.Position = 0;

                BinaryFormatter binaryFormatter = new BinaryFormatter();

                try
                {
                    DynamicSignContainer[] signNames = binaryFormatter.Deserialize(dynamicSignMemoryStream) as DynamicSignContainer[];

                    if (signNames != null)
                    {
                        RouteManager.Instance().LoadDynamicSigns(signNames);
                    }
                    else
                    {
                        LoggerUtils.LogWarning("Couldn't load routes, as the array is null!");
                    }
                }
                catch (Exception ex)
                {
                    LoggerUtils.LogException(ex);
                }
                finally
                {
                    dynamicSignMemoryStream.Close();
                }
            }
            else
            {
                LoggerUtils.LogWarning("Found no data to load");
            }
        }
        public override void OnLoadData()
        {
            LoggerUtils.Log("Loading routes");

            byte[] loadPropDict     = serializableDataManager.LoadData(propDictKey);
            byte[] loadBuildingDict = serializableDataManager.LoadData(buildingDictKey);

            if (loadPropDict != null)
            {
                MemoryStream propDictStream = new MemoryStream();

                propDictStream.Write(loadPropDict, 0, loadPropDict.Length);
                propDictStream.Position = 0;

                BinaryFormatter binaryFormatter = new BinaryFormatter();

                try
                {
                    ScreenObj[] propArray = binaryFormatter.Deserialize(propDictStream) as ScreenObj[];

                    if (propArray != null)
                    {
                        ScreenManager.instance.loadScreen(true, propArray);
                    }
                    else
                    {
                        LoggerUtils.LogWarning("Couldn't load props, as the array is null!");
                    }
                }
                catch (Exception ex)
                {
                    LoggerUtils.LogException(ex);
                }
                finally
                {
                    propDictStream.Close();
                }
            }
            else
            {
                LoggerUtils.LogWarning("Found no data to load");
            }

            if (loadBuildingDict != null)
            {
                MemoryStream buildingPropDict = new MemoryStream();

                buildingPropDict.Write(loadBuildingDict, 0, loadBuildingDict.Length);
                buildingPropDict.Position = 0;

                BinaryFormatter binaryFormatter = new BinaryFormatter();

                try
                {
                    ScreenObj[] buildingArray = binaryFormatter.Deserialize(buildingPropDict) as ScreenObj[];

                    if (buildingArray != null)
                    {
                        ScreenManager.instance.loadScreen(false, buildingArray);
                    }
                    else
                    {
                        LoggerUtils.LogWarning("Couldn't load building, as the array is null!");
                    }
                }
                catch (Exception ex)
                {
                    LoggerUtils.LogException(ex);
                }
                finally
                {
                    buildingPropDict.Close();
                }
            }
            else
            {
                LoggerUtils.LogWarning("Found no data to load");
            }
        }