public PoloniexBagAndDustHandler(IMicroBus bus, PoloniexService poloService, DatabaseService databaseService, BagConfig bagConfig, DustConfig dustConfig) { _bus = bus; _poloService = poloService; _databaseService = databaseService; _bagConfig = bagConfig; _dustConfig = dustConfig; }
public BittrexBagAndDustHandler(IMicroBus bus, BittrexService bittrexService, DatabaseService databaseService, BagConfig bagConfig, BittrexConfig bittrexConfig, DustConfig dustConfig) { _bus = bus; _bittrexService = bittrexService; _databaseService = databaseService; _bagConfig = bagConfig; _bittrexConfig = bittrexConfig; _dustConfig = dustConfig; }
public override void Entry(IModHelper helper) { ModInstance = this; LoadUserConfig(); LoadGlobalConfig(); LoadModdedItems(); LoadModdedBags(); BagConfig.AfterLoaded(); helper.Events.Display.MenuChanged += Display_MenuChanged; helper.Events.Display.WindowResized += Display_WindowResized; helper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked; helper.Events.GameLoop.Saving += (sender, e) => { SaveLoadHelpers.OnSaving(); }; helper.Events.GameLoop.Saved += (sender, e) => { SaveLoadHelpers.OnSaved(); }; helper.Events.GameLoop.SaveLoaded += (sender, e) => { SaveLoadHelpers.OnLoaded(); }; helper.Events.GameLoop.GameLaunched += (sender, e) => { // Add compatibility with the Save Anywhere mod string SaveAnywhereUniqueId = "Omegasis.SaveAnywhere"; bool IsSaveAnywhereInstalled = Helper.ModRegistry.IsLoaded(SaveAnywhereUniqueId) || Helper.ModRegistry.GetAll().Any(x => x.Manifest.Name.Equals("Save Anywhere", StringComparison.CurrentCultureIgnoreCase)); if (IsSaveAnywhereInstalled) { try { ISaveAnywhereAPI API = Helper.ModRegistry.GetApi <ISaveAnywhereAPI>(SaveAnywhereUniqueId); if (API != null) { API.addBeforeSaveEvent(ModUniqueId, () => { SaveLoadHelpers.OnSaving(); }); API.addAfterSaveEvent(ModUniqueId, () => { SaveLoadHelpers.OnSaved(); }); API.addAfterLoadEvent(ModUniqueId, () => { SaveLoadHelpers.OnLoaded(); }); } } catch (Exception ex) { Monitor.Log(string.Format("Failed to bind to Save Anywhere's Mod API. Your game may crash while saving with Save Anywhere! Error: {0}", ex.Message), LogLevel.Warn); } } ModdedBag.OnGameLaunched(); }; InputHandler.OnModEntry(helper); CraftingHandler.OnModEntry(helper); CommandHandler.OnModEntry(helper); AutofillHandler.OnModEntry(helper); MultiplayerHandler.OnModEntry(helper); MonsterLootHandler.OnModEntry(helper); }
public BittrexBagAndDustHandler( IMicroBus bus, GeneralConfig generalConfig, BittrexService bittrexService, PriceService priceService, DatabaseService databaseService, BagConfig bagConfig, DustConfig dustConfig, LowBtcConfig lowBtcConfig) { _bus = bus; _generalConfig = generalConfig; _bittrexService = bittrexService; _priceService = priceService; _databaseService = databaseService; _bagConfig = bagConfig; _dustConfig = dustConfig; _lowBtcConfig = lowBtcConfig; }
public StartupCheckingService( IMicroBus bus, TelegramConfig telegramConfig, TelegramBot bot, CoinigyConfig coinigyConfig, PoloniexConfig poloniexConfig, BittrexConfig bittrexConfig, DustConfig dustConfig, BagConfig bagConfig, LowBtcConfig lowBtcConfig ) { _bus = bus; _telegramConfig = telegramConfig; _bot = bot; _coinigyConfig = coinigyConfig; _poloniexConfig = poloniexConfig; _bittrexConfig = bittrexConfig; _dustConfig = dustConfig; _bagConfig = bagConfig; _lowBtcConfig = lowBtcConfig; }
/// <summary>Restores custom items used by this mod that were modified by <see cref="OnSaving"/>. Intended to be used after the game is saved or a save file is loaded.<para/> /// (On PC versions of this mod, the bags are saved using PyTK, but PyTK doesn't work with Android)</summary> private static void LoadCustomItems() { PlayerBags OwnedBags = PlayerBags.DeserializeFromCurrentSaveFile(); if (OwnedBags == null) { return; } else { BagConfig GlobalConfig = ItemBagsMod.BagConfig; // Index the saved bags by their instance ids Dictionary <int, BagInstance> IndexedBagInstances = new Dictionary <int, BagInstance>(); foreach (BagInstance BagInstance in OwnedBags.Bags) { if (!IndexedBagInstances.ContainsKey(BagInstance.InstanceId)) { IndexedBagInstances.Add(BagInstance.InstanceId, BagInstance); } else { string Warning = string.Format("Warning - multiple bag instances were found with the same InstanceId. Did you manually edit your {0} json file or add multiple .json files to the 'Modded Bags' folder with the same ModUniqueId values? Only the first bag with InstanceId = {1} will be loaded.", PlayerBags.OwnedBagsDataKey, BagInstance.InstanceId); ItemBagsMod.ModInstance.Monitor.Log(Warning, LogLevel.Warn); } } // Decode all of our Encoded custom items back into their original form ReplaceAllInstances(IsEncodedCustomItem, Encoded => { int BagInstanceId = Encoded.ParentSheetIndex - EncodedItemStartIndex; if (IndexedBagInstances.TryGetValue(BagInstanceId, out BagInstance BagInstance)) { if (BagInstance.TryDecode(out ItemBag Replacement)) { return(Replacement); }
public override void Entry(IModHelper helper) { ModInstance = this; if (Constants.TargetPlatform != GamePlatform.Android) // Android version saves items without the use of PyTK. See Helpers\SaveLoadHelpers.cs { // SpaceCore v1.5.0 introduced a breaking change to the game's saving/loading logic that is not compatible with my custom items if (Helper.ModRegistry.IsLoaded(SpaceCoreUniqueId)) { IModInfo SpaceCoreInfo = Helper.ModRegistry.Get(SpaceCoreUniqueId); if (SpaceCoreInfo.Manifest.Version.IsNewerThan("1.4.1")) { throw new InvalidOperationException("This mod is not compatible with SpaceCore v1.5.0 due to the changes SpaceCore makes to the game's save serializer, " + "which are not compatible with PyTK's CustomElementHandler.ISaveElement that this mod utilizes. " + "To use Item Bags, consider downgrading to an earlier version of SpaceCore such as v1.3.5."); } } } LoadUserConfig(); LoadGlobalConfig(); LoadModdedItems(); LoadModdedBags(); BagConfig.AfterLoaded(); helper.Events.Display.MenuChanged += Display_MenuChanged; helper.Events.Display.WindowResized += Display_WindowResized; helper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked; helper.Events.GameLoop.Saving += (sender, e) => { SaveLoadHelpers.OnSaving(); }; helper.Events.GameLoop.Saved += (sender, e) => { SaveLoadHelpers.OnSaved(); }; helper.Events.GameLoop.SaveLoaded += (sender, e) => { SaveLoadHelpers.OnLoaded(); }; helper.Events.GameLoop.GameLaunched += (sender, e) => { // Add compatibility with the Save Anywhere mod bool IsSaveAnywhereInstalled = Helper.ModRegistry.IsLoaded(SaveAnywhereUniqueId) || Helper.ModRegistry.GetAll().Any(x => x.Manifest.Name.Equals("Save Anywhere", StringComparison.CurrentCultureIgnoreCase)); if (IsSaveAnywhereInstalled) { try { ISaveAnywhereAPI API = Helper.ModRegistry.GetApi <ISaveAnywhereAPI>(SaveAnywhereUniqueId); if (API != null) { API.addBeforeSaveEvent(ModUniqueId, () => { SaveLoadHelpers.OnSaving(); }); API.addAfterSaveEvent(ModUniqueId, () => { SaveLoadHelpers.OnSaved(); }); API.addAfterLoadEvent(ModUniqueId, () => { SaveLoadHelpers.OnLoaded(); }); } } catch (Exception ex) { Monitor.Log(string.Format("Failed to bind to Save Anywhere's Mod API. Your game may crash while saving with Save Anywhere! Error: {0}", ex.Message), LogLevel.Warn); } } // Add compatibility with v1.5.0 of SpaceCore (v1.5.0 added changes that use Harmony to override the game's XmlSerializer for saving/loading save files) /*if (Helper.ModRegistry.IsLoaded(SpaceCoreUniqueId)) * { * IModInfo SpaceCoreInfo = Helper.ModRegistry.Get(SpaceCoreUniqueId); * if (SpaceCoreInfo.Manifest.Version.IsNewerThan("1.4.0")) * { * try * { * SpaceCoreAPI API = Helper.ModRegistry.GetApi<SpaceCoreAPI>(SpaceCoreUniqueId); * if (API != null) * { * // I couldn't get this to work with PyTK. Most of my items' data is loaded via PyTK's ISaveElement.rebuild function, which doesn't play nicely with SpaceCore * // (I'm not sure what's happening, but I assume that either rebuild isn't getting called, or it's getting called before SpaceCore finishes deserializing, so the data is overwritten with default values.) * API.RegisterSerializerType(typeof(BoundedBag)); * API.RegisterSerializerType(typeof(BundleBag)); * API.RegisterSerializerType(typeof(OmniBag)); * API.RegisterSerializerType(typeof(Rucksack)); * } * } * catch (Exception ex) * { * Monitor.Log(string.Format("Failed to bind to SpaceCore's Mod API. If your bags are not loading or you have errors while saving, " + * "try downgrading to SpaceCore version 1.4.0! Error: {0}", ex.Message), LogLevel.Warn); * } * } * }*/ ModdedBag.OnGameLaunched(); }; InputHandler.OnModEntry(helper); CraftingHandler.OnModEntry(helper); CommandHandler.OnModEntry(helper); AutofillHandler.OnModEntry(helper); MultiplayerHandler.OnModEntry(helper); MonsterLootHandler.OnModEntry(helper); }
private static void LoadGlobalConfig() { BagConfig GlobalBagConfig = ModInstance.Helper.Data.ReadGlobalData <BagConfig>(BagConfigDataKey); #if DEBUG //GlobalBagConfig = null; // force full re-creation of types for testing #endif if (GlobalBagConfig != null) { bool RewriteConfig = false; // Update the config with new Bag Types that were added in later versions if (GlobalBagConfig.CreatedByVersion == null) { GlobalBagConfig.EnsureBagTypesExist( BagTypeFactory.GetOceanFishBagType(), BagTypeFactory.GetRiverFishBagType(), BagTypeFactory.GetLakeFishBagType(), BagTypeFactory.GetMiscFishBagType() ); RewriteConfig = true; } if (GlobalBagConfig.CreatedByVersion == null || GlobalBagConfig.CreatedByVersion < new Version(1, 2, 4)) { if (Constants.TargetPlatform != GamePlatform.Android) { GlobalBagConfig.EnsureBagTypesExist(BagTypeFactory.GetFishBagType()); RewriteConfig = true; } } if (GlobalBagConfig.CreatedByVersion == null || GlobalBagConfig.CreatedByVersion < new Version(1, 3, 1)) { GlobalBagConfig.EnsureBagTypesExist( BagTypeFactory.GetFarmerBagType(), BagTypeFactory.GetFoodBagType() ); RewriteConfig = true; } if (GlobalBagConfig.CreatedByVersion == null || GlobalBagConfig.CreatedByVersion < new Version(1, 3, 3)) { GlobalBagConfig.EnsureBagTypesExist(BagTypeFactory.GetCropBagType()); RewriteConfig = true; } if (GlobalBagConfig.CreatedByVersion == null || GlobalBagConfig.CreatedByVersion < new Version(1, 4, 6)) { // I was accidentally serializing BagConfig.IndexedBagTypes which doubled the file size. Whatever, doesn't really matter since it's a small file RewriteConfig = true; // Lots of rebalancing happened in v1.4.6, so completely remake the config but save a backup copy of the existing file in case user manually edited it ModInstance.Helper.Data.WriteGlobalData(BagConfigDataKey + "-backup_before_v1.4.6_update", GlobalBagConfig); GlobalBagConfig = new BagConfig() { CreatedByVersion = CurrentVersion }; } if (GlobalBagConfig.CreatedByVersion == null || GlobalBagConfig.CreatedByVersion < new Version(1, 5, 2)) { RewriteConfig = true; // Added numerous new items from the Stardew Valley 1.5 update to existing bag types ModInstance.Helper.Data.WriteGlobalData(BagConfigDataKey + "-backup_before_v1.5.2_update", GlobalBagConfig); GlobalBagConfig = new BagConfig() { CreatedByVersion = CurrentVersion }; } // Suppose you just added a new BagType "Scarecrow Bag" to version 1.0.12 // Then keep the BagConfig up-to-date by doing: /*if (GlobalBagConfig.CreatedByVersion == null || GlobalBagConfig.CreatedByVersion < new Version(1, 0, 12)) * { * GlobalBagConfig.EnsureBagTypesExist( * BagTypeFactory.GetScarecrowBagType() * ); * ChangesMade = true; * }*/ // Would also need to add more entries to the i18n/default.json and other translation files if (RewriteConfig) { GlobalBagConfig.CreatedByVersion = CurrentVersion; ModInstance.Helper.Data.WriteGlobalData(BagConfigDataKey, GlobalBagConfig); } } else { GlobalBagConfig = new BagConfig() { CreatedByVersion = CurrentVersion }; ModInstance.Helper.Data.WriteGlobalData(BagConfigDataKey, GlobalBagConfig); } BagConfig = GlobalBagConfig; }
public override void Entry(IModHelper helper) { ModInstance = this; if (Helper.ModRegistry.IsLoaded(EntoaroxFrameworkUniqueId) && Helper.ModRegistry.Get(EntoaroxFrameworkUniqueId).Manifest.Version.IsOlderThan("2.5.5")) { Monitor.Log("WARNING - Your game may fail to save with ItemBags and Entoarox Framework installed, " + "since both of these mods attempt to override the game's save serializer to handle saving/loading of custom items. " + "Consider updating to a newer version of Entoarox Framework to resolve this compatibility issue.", LogLevel.Warn); } LoadUserConfig(); LoadGlobalConfig(); LoadModdedItems(); LoadModdedBags(); BagConfig.AfterLoaded(); helper.Events.Display.MenuChanged += Display_MenuChanged; helper.Events.Display.WindowResized += Display_WindowResized; helper.Events.GameLoop.UpdateTicked += GameLoop_UpdateTicked; helper.Events.GameLoop.Saving += (sender, e) => { SaveLoadHelpers.OnSaving(); }; helper.Events.GameLoop.Saved += (sender, e) => { SaveLoadHelpers.OnSaved(); }; helper.Events.GameLoop.SaveLoaded += (sender, e) => { SaveLoadHelpers.OnLoaded(); }; helper.Events.GameLoop.GameLaunched += (sender, e) => { // Add compatibility with the Save Anywhere mod bool IsSaveAnywhereInstalled = Helper.ModRegistry.IsLoaded(SaveAnywhereUniqueId) || Helper.ModRegistry.GetAll().Any(x => x.Manifest.Name.Equals("Save Anywhere", StringComparison.CurrentCultureIgnoreCase)); if (IsSaveAnywhereInstalled) { try { ISaveAnywhereAPI API = Helper.ModRegistry.GetApi <ISaveAnywhereAPI>(SaveAnywhereUniqueId); if (API != null) { API.addBeforeSaveEvent(ModUniqueId, () => { SaveLoadHelpers.OnSaving(); }); API.addAfterSaveEvent(ModUniqueId, () => { SaveLoadHelpers.OnSaved(); }); API.addAfterLoadEvent(ModUniqueId, () => { SaveLoadHelpers.OnLoaded(); }); } } catch (Exception ex) { Monitor.Log(string.Format("Failed to bind to Save Anywhere's Mod API. Your game may crash while saving with Save Anywhere! Error: {0}", ex.Message), LogLevel.Warn); } } // Add compatibility with Entoarox Framework mod // (By default, Entoarox Framework overrides the game's save serializer. SpaceCore also overrides the serializer, causing a conflicts since this mod relies on SpaceCore to handle saving/loading items) if (Helper.ModRegistry.IsLoaded(EntoaroxFrameworkUniqueId) && !Helper.ModRegistry.Get(EntoaroxFrameworkUniqueId).Manifest.Version.IsOlderThan("2.5.5")) { try { IEntoaroxFrameworkAPI API = Helper.ModRegistry.GetApi <IEntoaroxFrameworkAPI>(EntoaroxFrameworkUniqueId); if (API != null) { // Disable Entoarox Frameworks logic for overriding the save serializer API.HoistSerializerOwnership(); } } catch (Exception ex) { Monitor.Log(string.Format("Failed to bind to Entoarox Framework's Mod API. Your game may crash while saving with Entoarox Framework! Error: {0}", ex.Message), LogLevel.Warn); } } // Register custom types for serialization #if !ANDROID if (Helper.ModRegistry.IsLoaded(SpaceCoreUniqueId)) { IModInfo SpaceCoreInfo = Helper.ModRegistry.Get(SpaceCoreUniqueId); ISpaceCoreAPI API = Helper.ModRegistry.GetApi <ISpaceCoreAPI>(SpaceCoreUniqueId); API.RegisterSerializerType(typeof(BoundedBag)); API.RegisterSerializerType(typeof(BundleBag)); API.RegisterSerializerType(typeof(OmniBag)); API.RegisterSerializerType(typeof(Rucksack)); } #endif ModdedBag.OnGameLaunched(); }; InputHandler.OnModEntry(helper); CraftingHandler.OnModEntry(helper); CommandHandler.OnModEntry(helper); AutofillHandler.OnModEntry(helper); MultiplayerHandler.OnModEntry(helper); MonsterLootHandler.OnModEntry(helper); LegacyDataMigrator.OnModEntry(helper); }
public Bag() { BagConfig = new BagConfig(); }