Exemplo n.º 1
0
        /// <summary>
        /// Deserializes the data described by the specified <paramref name="data"/> from this level's storage.
        /// </summary>
        ///
        /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
        ///
        /// <param name="data">An <see cref="IStorageData"/> instance that describes the data to deserialize.</param>
        internal void Deserialize(IStorageData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            string dataKey = StorageDataPrefix + data.StorageDataId;

            try
            {
                byte[] rawData = serializableDataManager.LoadData(dataKey);
                if (rawData == null)
                {
                    return;
                }

                using (var stream = new MemoryStream(rawData))
                {
                    data.ReadData(stream);
                }
            }
            catch (Exception ex)
            {
                Log.Error($"The 'Real Time' mod failed to load its data (key {dataKey}), error message: {ex}");
            }
        }
Exemplo n.º 2
0
        internal void Serialize(IStorageData data)
        {
            string dataKey = StorageDataPrefix + data.StorageDataId;

            try
            {
                using (var stream = new MemoryStream())
                {
                    data.StoreData(stream);
                    serializableDataManager.SaveData(dataKey, stream.ToArray());
                }
            }
            catch (Exception ex)
            {
                Log.Error($"The 'Real Time' mod failed to save its data (key {dataKey}), error message: {ex}");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Serializes the data described by the specified <paramref name="data"/> to this level's storage.
        /// </summary>
        ///
        /// <exception cref="ArgumentNullException">Thrown when the argument is null.</exception>
        ///
        /// <param name="data">An <see cref="IStorageData"/> instance that describes the data to serialize.</param>
        public void Serialize(IStorageData data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            string dataKey = storageDataPrefix + data.StorageDataId;

            try
            {
                using (var stream = new MemoryStream())
                {
                    data.StoreData(stream);
                    serializableDataManager.SaveData(dataKey, stream.ToArray());
                }
            }
            catch (Exception ex)
            {
                Log.Error($"Failed to save the mod's data (key {dataKey}), error message: {ex}");
            }
        }
Exemplo n.º 4
0
        public static RealTimeCore Run(
            ConfigurationProvider<RealTimeConfig> configProvider,
            string rootPath,
            ILocalizationProvider localizationProvider,
            bool setDefaultTime,
            Compatibility compatibility)
        {
            if (configProvider == null)
            {
                throw new ArgumentNullException(nameof(configProvider));
            }

            if (string.IsNullOrEmpty(rootPath))
            {
                throw new ArgumentException("The root path cannot be null or empty string", nameof(rootPath));
            }

            if (localizationProvider == null)
            {
                throw new ArgumentNullException(nameof(localizationProvider));
            }

            if (compatibility == null)
            {
                throw new ArgumentNullException(nameof(compatibility));
            }

            List<IPatch> patches = GetMethodPatches(compatibility);
            var patcher = new MethodPatcher(HarmonyId, patches);

            HashSet<IPatch> appliedPatches = patcher.Apply();
            if (!CheckRequiredMethodPatches(appliedPatches))
            {
                Log.Error("The 'Real Time' mod failed to perform method redirections for required methods");
                patcher.Revert();
                return null;
            }

            if (StorageBase.CurrentLevelStorage != null)
            {
                LoadStorageData(new[] { configProvider }, StorageBase.CurrentLevelStorage);
            }

            localizationProvider.SetEnglishUSFormatsState(configProvider.Configuration.UseEnglishUSFormats);

            var timeInfo = new TimeInfo(configProvider.Configuration);
            var buildingManager = new BuildingManagerConnection();
            var randomizer = new GameRandomizer();

            var weatherInfo = new WeatherInfo(new WeatherManagerConnection(), randomizer);

            var gameConnections = new GameConnections<Citizen>(
                timeInfo,
                new CitizenConnection(),
                new CitizenManagerConnection(),
                buildingManager,
                randomizer,
                new TransferManagerConnection(),
                weatherInfo);

            var eventManager = new RealTimeEventManager(
                configProvider.Configuration,
                CityEventsLoader.Instance,
                new EventManagerConnection(),
                buildingManager,
                randomizer,
                timeInfo);

            if (!SetupCustomAI(timeInfo, configProvider.Configuration, gameConnections, eventManager))
            {
                Log.Error("The 'Real Time' mod failed to setup the customized AI and will now be deactivated.");
                patcher.Revert();
                return null;
            }

            var timeAdjustment = new TimeAdjustment(configProvider.Configuration);
            DateTime gameDate = timeAdjustment.Enable(setDefaultTime);
            SimulationHandler.CitizenProcessor.UpdateFrameDuration();

            CityEventsLoader.Instance.ReloadEvents(rootPath);

            var customTimeBar = new CustomTimeBar();
            customTimeBar.Enable(gameDate);
            customTimeBar.CityEventClick += CustomTimeBarCityEventClick;

            var vanillaEvents = VanillaEvents.Customize();

            var result = new RealTimeCore(timeAdjustment, customTimeBar, eventManager, patcher, vanillaEvents);
            eventManager.EventsChanged += result.CityEventsChanged;

            var statistics = new Statistics(timeInfo, localizationProvider);
            if (statistics.Initialize())
            {
                statistics.RefreshUnits();
            }
            else
            {
                statistics = null;
            }

            SimulationHandler.NewDay += result.CityEventsChanged;

            SimulationHandler.TimeAdjustment = timeAdjustment;
            SimulationHandler.DayTimeSimulation = new DayTimeSimulation(configProvider.Configuration);
            SimulationHandler.EventManager = eventManager;
            SimulationHandler.WeatherInfo = weatherInfo;
            SimulationHandler.Buildings = BuildingAIPatches.RealTimeAI;
            SimulationHandler.Buildings.UpdateFrameDuration();

            if (appliedPatches.Contains(BuildingAIPatches.GetColor))
            {
                SimulationHandler.Buildings.InitializeLightState();
            }

            SimulationHandler.Statistics = statistics;

            if (appliedPatches.Contains(WorldInfoPanelPatches.UpdateBindings))
            {
                WorldInfoPanelPatches.CitizenInfoPanel = CustomCitizenInfoPanel.Enable(ResidentAIPatch.RealTimeAI, localizationProvider);
                WorldInfoPanelPatches.VehicleInfoPanel = CustomVehicleInfoPanel.Enable(ResidentAIPatch.RealTimeAI, localizationProvider);
            }

            AwakeSleepSimulation.Install(configProvider.Configuration);

            IStorageData schedulesStorage = ResidentAIPatch.RealTimeAI.GetStorageService(
                schedules => new CitizenScheduleStorage(schedules, gameConnections.CitizenManager.GetCitizensArray, timeInfo));

            result.storageData.Add(schedulesStorage);
            result.storageData.Add(eventManager);
            if (StorageBase.CurrentLevelStorage != null)
            {
                StorageBase.CurrentLevelStorage.GameSaving += result.GameSaving;
                LoadStorageData(result.storageData, StorageBase.CurrentLevelStorage);
            }

            result.storageData.Add(configProvider);
            result.Translate(localizationProvider);
            result.IsRestrictedMode = appliedPatches.Count != patches.Count;

            return result;
        }
Exemplo n.º 5
0
 public StorageService()
 {
     this.local = new StorageServiceLocal(Environment.CurrentDirectory);
     this.temp  = new StorageServiceTemp(Path.GetTempPath());
     this.data  = new StorageServiceData(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "adma", "bob"));
 }
Exemplo n.º 6
0
 public ConversationManager(IBrokerConnection brokerManager, IStorageData storageData, Contact me)
 {
     this.brokerConnection = brokerManager;
     this.storageData      = storageData;
     this.me = me;
 }