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 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); }
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); }