예제 #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)
        {
            monitor = this.Monitor;
            _helper = helper;

            RegCommand(helper);

            helper.Events.GameLoop.UpdateTicked += Overrides.HandleMouseEvents;

            tsf = new TSF();
            tsf.AssociateFocus(Game1.game1.Window.Handle);

            textbox_h = new TextBoxHelper(tsf, Game1.game1.Window.Handle);

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

            MethodInfo m_HookProc = typeof(KeyboardInput).GetMethod("HookProc", BindingFlags.NonPublic | BindingFlags.Static);

            harmony.Patch(m_HookProc, new HarmonyMethod(typeof(Overrides), "KeyboardInput_HookProc"));

            MethodInfo m_selected = typeof(KeyboardDispatcher).GetMethod("set_Subscriber", BindingFlags.Public | BindingFlags.Instance);

            harmony.Patch(m_selected, null, new HarmonyMethod(typeof(Overrides), "Subscriber_Set"));

            MethodInfo m_text = typeof(TextBox).GetMethod("set_Text", BindingFlags.Public | BindingFlags.Instance);

            harmony.Patch(m_text, null, new HarmonyMethod(typeof(Overrides), "TextBox_Text"));

            MethodInfo m_draw = typeof(TextBox).GetMethod("Draw", BindingFlags.Public | BindingFlags.Instance);

            harmony.Patch(m_draw, new HarmonyMethod(typeof(Overrides), "Draw"));

            MethodInfo m_draw2 = typeof(ChatTextBox).GetMethod("Draw", BindingFlags.Public | BindingFlags.Instance);

            harmony.Patch(m_draw2, new HarmonyMethod(typeof(Overrides), "Draw"));

            MethodInfo m_emoji = typeof(ChatTextBox).GetMethod("receiveEmoji", BindingFlags.Public | BindingFlags.Instance);

            harmony.Patch(m_emoji, new HarmonyMethod(typeof(Overrides), "receiveEmoji"));


            FieldInfo  host   = typeof(Game).GetField("host", BindingFlags.NonPublic | BindingFlags.Instance);
            Type       type   = host.GetValue(Game1.game1).GetType();
            MethodInfo m_idle = type.GetMethod("ApplicationIdle", BindingFlags.NonPublic | BindingFlags.Instance);

            harmony.Patch(m_idle, null, new HarmonyMethod(typeof(ModEntry), "HandleMsgFirst"));

            //compatible with ChatCommands
            if (Helper.ModRegistry.Get("cat.chatcommands") != null)
            {
                monitor.Log("Compatible with ChatCommands", LogLevel.Info);
                Compatibility.PatchChatCommands(monitor, harmony);
            }
        }
예제 #2
0
        private void InitTSF()
        {
            tsf = new TSF();                        //Need to init at STA Thread
            tsf.AssociateFocus(this.Window.Handle); //Window need to create in a STA Thread
            tsf.Active();
            tsf.CreateContext(this.Window.Handle);
            tsf.PushContext();
#if XNA
            FieldInfo  host    = typeof(Game).GetField("host", BindingFlags.NonPublic | BindingFlags.Instance);
            Type       type    = host.GetValue(Game1.game1).GetType();
            MethodInfo m_idle  = type.GetMethod("ApplicationIdle", BindingFlags.NonPublic | BindingFlags.Instance);
            Harmony    harmony = new Harmony("StardewValley_TSF");
            harmony.Patch(m_idle, null, new HarmonyMethod(typeof(Game1), "HandleMsgFirst"));
#endif
#if Mono
            Type       type    = Game1.game1.Window.GetType();
            MethodInfo m_idle  = type.GetMethod("TickOnIdle", BindingFlags.NonPublic | BindingFlags.Instance);
            Harmony    harmony = new Harmony("StardewValley_TSF");
            harmony.Patch(m_idle, null, new HarmonyMethod(typeof(Game1), "HandleMsgFirst"));//need to handle msg first, or the game will struck after IME actived
#endif
        }