Exemple #1
0
        /*********
        ** Public methods
        *********/
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            this.Serializer = new JsonSerializer();
            this.Serializer.Converters.Add(new RectangleConverter());
            this.Serializer.Formatting           = Formatting.None;
            this.Serializer.NullValueHandling    = NullValueHandling.Ignore;
            this.Serializer.DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate;
            this.Serializer.ContractResolver     = new ReadonlyContractResolver();
            DeferredAssetHandler typeHandler = new DeferredAssetHandler();

            helper.Content.AssetEditors.Add(typeHandler);
            helper.Content.AssetEditors.Add(typeHandler);
            helper.Content.AssetEditors.Add(new DeferredTypeHandler());
            helper.Content.AssetLoaders.Add(new XnbLoader());
            helper.Content.AssetEditors.Add(new TextureInjector());
            helper.Content.AssetEditors.Add(new DictionaryInjector());
            EntoaroxFrameworkMod.SHelper = this.Helper;
            EntoaroxFrameworkMod.Logger  = this.Monitor;
            EntoaroxFrameworkMod.Config  = this.Helper.ReadConfig <ModConfig>();
            this.PrepareCustomEvents();
            this.Helper.ConsoleCommands.Add("world_bushreset", "Resets bushes in the whole game, use this if you installed a map mod and want to keep using your old save.", this.Commands);
            if (EntoaroxFrameworkMod.Config.TrainerCommands)
            {
                helper.ConsoleCommands
                .Add("farm_settype", "farm_settype <type> | Enables you to change your farm type to any of the following: " + string.Join(",", EntoaroxFrameworkMod.Farms), this.Commands)
                .Add("farm_clear", "farm_clear | Removes ALL objects from your farm, this cannot be undone!", this.Commands)
                .Add("player_warp", "player_warp <location> <x> <y> | Warps the player to the given position in the game.", this.Commands);
            }

            GameEvents.UpdateTick += this.GameEvents_FirstUpdateTick;
            SaveEvents.BeforeSave += this.SaveEvents_BeforeSave;
            SaveEvents.AfterLoad  += this.SaveEvents_AfterSave;
            SaveEvents.AfterSave  += this.SaveEvents_AfterSave;
        }
Exemple #2
0
        /*********
        ** Public methods
        *********/
        /// <summary>The mod entry point, called after the mod is first loaded.</summary>
        /// <param name="helper">Provides simplified APIs for writing mods.</param>
        public override void Entry(IModHelper helper)
        {
            Serializer = new JsonSerializer
            {
                Formatting = Formatting.None,
                /*NullValueHandling = NullValueHandling.Ignore,*/
                /*DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate,*/
                ContractResolver = new CustomContractResolver()
            };
            Serializer.Converters.Add(new RectangleConverter());
            DeferredAssetHandler typeHandler = new DeferredAssetHandler();

            helper.Content.AssetLoaders.Add(typeHandler);
            helper.Content.AssetEditors.Add(typeHandler);
            helper.Content.AssetEditors.Add(new DeferredTypeHandler());
            helper.Content.AssetLoaders.Add(new XnbLoader());
            helper.Content.AssetEditors.Add(new TextureInjector());
            helper.Content.AssetEditors.Add(new DictionaryInjector());
            EntoaroxFrameworkMod.SHelper = this.Helper;
            EntoaroxFrameworkMod.Logger  = this.Monitor;
            EntoaroxFrameworkMod.Config  = this.Helper.ReadConfig <ModConfig>();

            this.Helper.ConsoleCommands.Add("world_bushreset", "Resets bushes in the whole game, use this if you installed a map mod and want to keep using your old save.", this.Commands);
            this.Helper.ConsoleCommands.Add("world_reset", "world_reset (bushes|characters) - Resets the selected data by reloading it from disk.", this.WorldReset);
            if (EntoaroxFrameworkMod.Config.TrainerCommands)
            {
                helper.ConsoleCommands
                .Add("farm_settype", "farm_settype <type> | Enables you to change your farm type to any of the following: " + string.Join(",", EntoaroxFrameworkMod.Farms), this.Commands)
                .Add("farm_clear", "farm_clear | Removes ALL objects from your farm, this cannot be undone!", this.Commands)
                .Add("player_warp", "player_warp <location> <x> <y> | Warps the player to the given position in the game.", this.Commands);
            }

            helper.Events.GameLoop.GameLaunched += this.OnGameLaunched;
            helper.Events.GameLoop.UpdateTicked += this.OnUpdateTicked;
            helper.Events.GameLoop.SaveLoaded   += this.OnSaveLoaded;
            helper.Events.GameLoop.Saving       += this.OnSaving;
            helper.Events.GameLoop.Saved        += this.OnSaved;
            helper.Events.Input.ButtonReleased  += this.OnButtonReleased;

            // Check if the serializer override should be skipped
            if (typeof(SaveGame).GetField("contract") != null)
            {
                this.Monitor.Log("Detected incompatible SDV version for serializer function, function is disabled.", LogLevel.Warn);
                return;
            }
            helper.Events.GameLoop.GameLaunched += this.SetupSerializer;
            helper.Events.GameLoop.UpdateTicked += this.EnforceSerializer;
        }