コード例 #1
0
        /// <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)
        {
            context  = this;
            Config   = Helper.ReadConfig <ModConfig>();
            SHelper  = helper;
            SMonitor = Monitor;

            if (!Config.EnableMod)
            {
                return;
            }
            mp = helper.Reflection.GetField <Multiplayer>(typeof(Game1), "multiplayer").GetValue();

            FamiliarsPatches.Initialize(Monitor, Helper, Config);
            FamiliarsHelperEvents.Initialize(Monitor, Helper, Config);
            FamiliarsUtils.Initialize(Monitor, Helper, Config);

            Helper.ConsoleCommands.Add("DispelFamiliars", "Dispel all familiars.", new Action <string, string[]>(DispelFamiliars));
            Helper.ConsoleCommands.Add("DF", "Dispel all familiars.", new System.Action <string, string[]>(DispelFamiliars));
            Helper.ConsoleCommands.Add("SummonFamiliars", "Summon all familiars to you.", new System.Action <string, string[]>(SummonFamiliars));
            Helper.ConsoleCommands.Add("SF", "Summon all familiars to you.", new System.Action <string, string[]>(SummonFamiliars));
            if (Config.IAmAStinkyCheater)
            {
                Helper.ConsoleCommands.Add("CallFamiliar", "Call a familiar. Usage: CallFamiliar <familiarType>", new System.Action <string, string[]>(CallFamiliar));
                Helper.ConsoleCommands.Add("CF", "Call a familiar. Usage: CF <familiarType>", new System.Action <string, string[]>(CallFamiliar));
            }

            Helper.Events.GameLoop.GameLaunched += FamiliarsHelperEvents.GameLoop_GameLaunched;
            Helper.Events.GameLoop.SaveLoaded   += FamiliarsHelperEvents.GameLoop_SaveLoaded;
            Helper.Events.GameLoop.Saving       += FamiliarsHelperEvents.GameLoop_Saving;
            Helper.Events.GameLoop.DayStarted   += FamiliarsHelperEvents.GameLoop_DayStarted;
            Helper.Events.Input.ButtonPressed   += FamiliarsHelperEvents.Input_ButtonPressed;


            Helper.Events.Player.Warped += FamiliarsHelperEvents.Player_Warped;

            var harmony = HarmonyInstance.Create(ModManifest.UniqueID);

            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.drawAboveFrontLayer)),
                postfix: new HarmonyMethod(typeof(FamiliarsPatches), nameof(FamiliarsPatches.GameLocation_drawAboveFrontLayer_Postfix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Object), nameof(Object.performObjectDropInAction)),
                prefix: new HarmonyMethod(typeof(FamiliarsPatches), nameof(FamiliarsPatches.Object_performObjectDropInAction_Prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Object), nameof(Object.minutesElapsed)),
                postfix: new HarmonyMethod(typeof(FamiliarsPatches), nameof(FamiliarsPatches.Object_minutesElapsed_Postfix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.performTouchAction)),
                postfix: new HarmonyMethod(typeof(FamiliarsPatches), nameof(FamiliarsPatches.GameLocation_performTouchAction_Postfix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Utility), nameof(Utility.checkForCharacterInteractionAtTile)),
                postfix: new HarmonyMethod(typeof(FamiliarsPatches), nameof(FamiliarsPatches.Utility_checkForCharacterInteractionAtTile_Postfix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.isVillager)),
                prefix: new HarmonyMethod(typeof(FamiliarsPatches), nameof(FamiliarsPatches.NPC_isVillager_Prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(NPC), nameof(NPC.checkAction)),
                prefix: new HarmonyMethod(typeof(FamiliarsPatches), nameof(FamiliarsPatches.NPC_checkAction_Prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Character), nameof(Character.checkForFootstep)),
                prefix: new HarmonyMethod(typeof(FamiliarsPatches), nameof(FamiliarsPatches.Character_checkForFootstep_Prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Bush), "shake"),
                prefix: new HarmonyMethod(typeof(FamiliarsPatches), nameof(FamiliarsPatches.Bush_shake_Prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), "updateCharacters"),
                prefix: new HarmonyMethod(typeof(FamiliarsPatches), nameof(FamiliarsPatches.GameLocation_updateCharacters_Prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.isCharacterAtTile)),
                postfix: new HarmonyMethod(typeof(FamiliarsPatches), nameof(FamiliarsPatches.GameLocation_isCharacterAtTile_Postfix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), "drawCharacters"),
                prefix: new HarmonyMethod(typeof(FamiliarsPatches), nameof(FamiliarsPatches.GameLocation_drawCharacters_Prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(AnimalHouse), nameof(AnimalHouse.incubator)),
                prefix: new HarmonyMethod(typeof(FamiliarsPatches), nameof(FamiliarsPatches.AnimalHouse_incubator_Prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Utility), nameof(Utility.isThereAFarmerOrCharacterWithinDistance)),
                postfix: new HarmonyMethod(typeof(FamiliarsPatches), nameof(FamiliarsPatches.Utility_isThereAFarmerOrCharacterWithinDistance_Postfix))
                );
        }
コード例 #2
0
 public static void Initialize(IMonitor monitor, IModHelper helper, ModConfig config)
 {
     Monitor = monitor;
     Config  = config;
     Helper  = helper;
 }