示例#1
0
        public static bool Load()
        {
            try
            {
                Directory.CreateDirectory(GameUtils.GetSaveGameDir() + "/BCMData/");

                var obj        = new PersistentContainer();
                var bFormatter = new BinaryFormatter();

                // todo: add files for players stats, position, buff, inventory histories
                Stream streamPlayers = File.Open(GameUtils.GetSaveGameDir() + "/BCMData/Players.bin", FileMode.OpenOrCreate);
                if (streamPlayers.Length > 0)
                {
                    obj._players = (Players)bFormatter.Deserialize(streamPlayers);
                }
                streamPlayers.Close();

                Stream streamSettings = File.Open(GameUtils.GetSaveGameDir() + "/BCMData/Settings.bin", FileMode.OpenOrCreate);
                if (streamSettings.Length > 0)
                {
                    obj._settings = (BCMSettings)bFormatter.Deserialize(streamSettings);
                }
                streamSettings.Close();

                _instance = obj;

                return(true);
            }
            catch (Exception e)
            {
                Log.Error("" + Config.ModPrefix + " Error in PersistentContainer." + MethodBase.GetCurrentMethod().Name + ": " + e);
            }

            return(false);
        }
示例#2
0
        public static bool Load()
        {
            try
            {
                var obj = new PersistentContainer();

                //PLAYERS
                Stream streamPlayers = File.Open(_playersfile, FileMode.OpenOrCreate);
                if (streamPlayers.Length > 0)
                {
                    obj._players = (Players)bFormatter.Deserialize(streamPlayers);
                }
                streamPlayers.Close();

                //SETTINGS
                Stream streamSettings = File.Open(_settingsfile, FileMode.OpenOrCreate);
                if (streamSettings.Length > 0)
                {
                    obj._settings = (BCMSettings)bFormatter.Deserialize(streamSettings);
                }
                streamSettings.Close();

                //PLAYER LOGS
                Stream streamPlayerLogs = File.Open(_playerlogsfile, FileMode.Create);
                streamPlayerLogs.Close();

                //EVENTS CONFIG
                Stream streamEventsConfig = File.Open(_eventsconfigsfile, FileMode.OpenOrCreate);
                if (streamEventsConfig.Length > 0)
                {
                    obj._eventsConfig = (BCMEventsConfig)bFormatter.Deserialize(streamEventsConfig);
                }
                streamEventsConfig.Close();

                _instance = obj;
                return(true);
            }
            catch (Exception e)
            {
                Log.Error($"{Config.ModPrefix} Error in PersistentContainer.{MethodBase.GetCurrentMethod().Name}: {e}");
            }

            return(false);
        }