Пример #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;
            if (!Config.EnableMod)
            {
                return;
            }

            api = (MobilePhoneApi)GetApi();

            MobilePhoneApp.Initialize(Helper, Monitor, Config);
            MobilePhoneCall.Initialize(Helper, Monitor, Config);
            ThemeApp.Initialize(Helper, Monitor, Config);
            PhoneVisuals.Initialize(Helper, Monitor, Config);
            PhoneInput.Initialize(Helper, Monitor, Config);
            PhoneGameLoop.Initialize(Helper, Monitor, Config);
            PhoneUtils.Initialize(Helper, Monitor, Config);
            PhonePatches.Initialize(Helper, Monitor, Config);

            if (Config.AddRotateApp)
            {
                apps.Add(Helper.ModRegistry.ModID + "_Rotate", new MobileApp(helper.Translation.Get("rotate-phone"), null, helper.Content.Load <Texture2D>("assets/rotate_icon.png")));
            }

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

            harmony.Patch(
                original: AccessTools.Method(typeof(Game1), nameof(Game1.pressSwitchToolButton)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Game1_pressSwitchToolButton_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.endBehaviors)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_endBehaviors_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Farmer), nameof(Farmer.changeFriendship)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Farmer_changeFriendship_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), "resetLocalState"),
                postfix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.GameLocation_resetLocalState_postfix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), nameof(GameLocation.answerDialogue)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.GameLocation_answerDialogue_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_awardFestivalPrize)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_addTool)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_addConversationTopic)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_addCookingRecipe)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_addCraftingRecipe)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_money)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_removeItem)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_friendship)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_dump)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_addQuest)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_cutscene)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_cutscene_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.skipEvent)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_skipEvent_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), "namePet"),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_namePet_prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(CarpenterMenu), nameof(CarpenterMenu.returnToCarpentryMenu)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.CarpenterMenu_returnToCarpentryMenu_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(CarpenterMenu), nameof(CarpenterMenu.returnToCarpentryMenuAfterSuccessfulBuild)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.CarpenterMenu_returnToCarpentryMenuAfterSuccessfulBuild_prefix))
                );

            Helper.Events.Input.ButtonPressed            += PhoneInput.Input_ButtonPressed;
            Helper.Events.GameLoop.SaveLoaded            += PhoneGameLoop.GameLoop_SaveLoaded;
            Helper.Events.GameLoop.GameLaunched          += PhoneGameLoop.GameLoop_GameLaunched;
            Helper.Events.GameLoop.ReturnedToTitle       += PhoneGameLoop.ReturnedToTitle;
            Helper.Events.GameLoop.TimeChanged           += PhoneGameLoop.GameLoop_TimeChanged;
            Helper.Events.GameLoop.OneSecondUpdateTicked += PhoneGameLoop.GameLoop_OneSecondUpdateTicked;
            Helper.Events.Display.WindowResized          += PhoneVisuals.Display_WindowResized;

            /*
             * var files = Directory.GetFiles(Path.Combine(Helper.DirectoryPath, Path.Combine("assets", "events")));
             * foreach(string file in files)
             * {
             *  Reminiscence r = Helper.Data.ReadJsonFile<Reminiscence>(Path.Combine("assets", Path.Combine("events", Path.GetFileName(file))));
             *  for(int i = 0; i < r.events.Count; i++)
             *  {
             *      string t = $"{Path.GetFileName(file).Replace(".json", "")}-event-{i}";
             *      Monitor.Log($"\"{t}\":\"{r.events[i].name}\"");
             *      r.events[i].name = t;
             *  }
             *  Helper.Data.WriteJsonFile(Path.Combine("tmp", Path.GetFileName(file)),r);
             * }
             */
        }
Пример #2
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;
            if (!Config.EnableMod)
            {
                return;
            }

            api = (MobilePhoneApi)GetApi();

            MobilePhoneApp.Initialize(Helper, Monitor, Config);
            MobilePhoneCall.Initialize(Helper, Monitor, Config);
            ThemeApp.Initialize(Helper, Monitor, Config);
            PhoneVisuals.Initialize(Helper, Monitor, Config);
            PhoneInput.Initialize(Helper, Monitor, Config);
            PhoneGameLoop.Initialize(Helper, Monitor, Config);
            PhoneUtils.Initialize(Helper, Monitor, Config);
            PhonePatches.Initialize(Helper, Monitor, Config);

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

            harmony.Patch(
                original: AccessTools.Method(typeof(Game1), nameof(Game1.pressSwitchToolButton)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Game1_pressSwitchToolButton_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.endBehaviors)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_endBehaviors_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Farmer), nameof(Farmer.changeFriendship)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Farmer_changeFriendship_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(GameLocation), "resetLocalState"),
                postfix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.GameLocation_resetLocalState_postfix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_awardFestivalPrize)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_addTool)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_addConversationTopic)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_addCookingRecipe)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_addCraftingRecipe)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_money)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_removeItem)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_friendship)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_dump)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), nameof(Event.command_cutscene)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_command_cutscene_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(Event), "namePet"),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.Event_namePet_prefix))
                );

            harmony.Patch(
                original: AccessTools.Method(typeof(CarpenterMenu), nameof(CarpenterMenu.returnToCarpentryMenu)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.CarpenterMenu_returnToCarpentryMenu_prefix))
                );
            harmony.Patch(
                original: AccessTools.Method(typeof(CarpenterMenu), nameof(CarpenterMenu.returnToCarpentryMenuAfterSuccessfulBuild)),
                prefix: new HarmonyMethod(typeof(PhonePatches), nameof(PhonePatches.CarpenterMenu_returnToCarpentryMenuAfterSuccessfulBuild_prefix))
                );

            Helper.Events.Input.ButtonPressed            += PhoneInput.Input_ButtonPressed;
            Helper.Events.GameLoop.SaveLoaded            += PhoneGameLoop.GameLoop_SaveLoaded;
            Helper.Events.GameLoop.GameLaunched          += PhoneGameLoop.GameLoop_GameLaunched;
            Helper.Events.GameLoop.ReturnedToTitle       += PhoneGameLoop.ReturnedToTitle;
            Helper.Events.GameLoop.TimeChanged           += PhoneGameLoop.GameLoop_TimeChanged;
            Helper.Events.GameLoop.OneSecondUpdateTicked += PhoneGameLoop.GameLoop_OneSecondUpdateTicked;
            Helper.Events.Display.WindowResized          += PhoneVisuals.Display_WindowResized;
        }