  KeyCode.Alpha7},
                {HK_TYPE.HK_BATTEL_SKILL_8,  KeyCode.Alpha8},
                {HK_TYPE.HK_BATTEL_SKILL_9,  KeyCode.Alpha9},

                {HK_TYPE.HK_BATTEL_SPECIAL_1,  KeyCode.Alpha1},
                {HK_TYPE.HK_BATTEL_SPECIAL_2,  KeyCode.Alpha2},
                {HK_TYPE.HK_BATTEL_SPECIAL_3,  KeyCode.Alpha3},
                {HK_TYPE.HK_BATTEL_SPECIAL_4,  KeyCode.Alpha4},
                {HK_TYPE.HK_BATTEL_SPECIAL_5,  KeyCode.Alpha5},
                {HK_TYPE.HK_BATTEL_SPECIAL_6,  KeyCode.Alpha6},
                {HK_TYPE.HK_BATTEL_SPECIAL_7,  KeyCode.Alpha7},
                {HK_TYPE.HK_BATTEL_SPECIAL_8,  KeyCode.Alpha8},
                {HK_TYPE.HK_BATTEL_SPECIAL_9,  KeyCode.Alpha9},
            };

            foreach (var kv in hotkeys)
                Main.Logger.Log($"Hotkey: {kv.Key}, key: {kv.Value}, desc: {Settings.hotkeyNames[kv.Key]}");

            return hotkeys;
        }


        public override void Save(UnityModManager.ModEntry modEntry)
        {
            Save(this, modEntry);
        }


        public void Save()
        {
            Main.Logger.Log("hotkey saved");
            Save(modee);
        }
    }


    public static class Main
    {
        public static List<HK_TYPE> mainskilllist = new List<HK_TYPE>()
        {
            HK_TYPE.HK_BATTEL_SKILL_1,
            HK_TYPE.HK_BATTEL_SKILL_2,
            HK_TYPE.HK_BATTEL_SKILL_3,
            HK_TYPE.HK_BATTEL_SKILL_4,
            HK_TYPE.HK_BATTEL_SKILL_5,
            HK_TYPE.HK_BATTEL_SKILL_6,
            HK_TYPE.HK_BATTEL_SKILL_7,
            HK_TYPE.HK_BATTEL_SKILL_8,
            HK_TYPE.HK_BATTEL_SKILL_9,
        };

        public static List<HK_TYPE> qinggongskilllist = new List<HK_TYPE>()
        {
            HK_TYPE.HK_BATTEL_QINGGONG_1,
            HK_TYPE.HK_BATTEL_QINGGONG_2,
            HK_TYPE.HK_BATTEL_QINGGONG_3,
            HK_TYPE.HK_BATTEL_QINGGONG_4,
            HK_TYPE.HK_BATTEL_QINGGONG_5,
            HK_TYPE.HK_BATTEL_QINGGONG_6,
            HK_TYPE.HK_BATTEL_QINGGONG_7,
            HK_TYPE.HK_BATTEL_QINGGONG_8,
            HK_TYPE.HK_BATTEL_QINGGONG_9,
        };

        public static List<HK_TYPE> specialskilllist = new List<HK_TYPE>()
        {
            HK_TYPE.HK_BATTEL_SPECIAL_1,
            HK_TYPE.HK_BATTEL_SPECIAL_2,
            HK_TYPE.HK_BATTEL_SPECIAL_3,
            HK_TYPE.HK_BATTEL_SPECIAL_4,
            HK_TYPE.HK_BATTEL_SPECIAL_5,
            HK_TYPE.HK_BATTEL_SPECIAL_6,
            HK_TYPE.HK_BATTEL_SPECIAL_7,
            HK_TYPE.HK_BATTEL_SPECIAL_8,
            HK_TYPE.HK_BATTEL_SPECIAL_9,
        };

        public static bool enabled;
        public static Settings settings;

        public static bool notify_reset_key = false;
        public static GameObject _go_gongfatree = null;

        public static UnityModManager.ModEntry.ModLogger Logger;

        public static bool binding_key = false;
        static HK_TYPE current_binding_key = HK_TYPE.HK_NONE;
        static KeyCode last_key_code = KeyCode.None;


        public static bool Load(UnityModManager.ModEntry modEntry)
        {
            Logger = modEntry.Logger;
            modEntry.OnToggle = OnToggle;
            settings = Settings.Load<Settings>(modEntry);
            settings.modee = modEntry;
            modEntry.OnGUI = OnGUI;
            modEntry.OnSaveGUI = OnSaveGUI;
            var harmony = HarmonyInstance.Create(modEntry.Info.Id);
            harmony.PatchAll(Assembly.GetExecutingAssembly());

            Main.Logger.Log("Hotkey count: " + Main.settings.hotkeys.Count);
            if (Main.settings.hotkeys.Count!= Settings.nHotkeys)
            {
                Main.settings.hotkeys = Settings.GetDefaultHotKeys();
                notify_reset_key = true;
                Main.settings.Save();
                Main.Logger.Log("Hotkeys reinitialized: " + Main.settings.hotkeys.Count);
            }
            return true;
        }


        public static bool OnToggle(UnityModManager.ModEntry modEntry, bool value)
        {
            if (!value) return false;
            enabled = value;
            return true;
        }


        static void OnGUI(UnityModManager.ModEntry modEntry)
        {
            processKeyPress();
            GUILayout.BeginVertical("box");
            settings.enable_close = GUILayout.Toggle(settings.enable_close, "是否使用本Mod的Esc/鼠标右键关闭功能（需要重启游戏生效）");
            settings.escAsLastOption = GUILayout.Toggle(settings.escAsLastOption, "是否在对话窗口使用Esc/鼠标右键选择最后一个选项");
            settings.useNumpadKeysInMessageWindow = GUILayout.Toggle(settings.useNumpadKeysInMessageWindow, "是否在对话窗口增加小键盘选择功能");

            GUILayout.Label("战斗中释放轻功技能的装饰键");
            settings.qinggong_modifier_key = (MODIFIER_KEY_TYPE)GUILayout.SelectionGrid((int)settings.qinggong_modifier_key,
                new string[] { "Shift", "Ctrl", "Alt" }, 3);
            GUILayout.Label("战斗中释放绝技的装饰键");
            settings.special_modifierkey = (MODIFIER_KEY_TYPE)GUILayout.SelectionGrid((int)settings.special_modifierkey,
                new string[] { "Shift", "Ctrl", "Alt" }, 3);
            GUILayout.EndVertical();

            GUILayout.BeginVertical("box", new GUILayoutOption[] { GUILayout.MinWidth(700.0f), GUILayout.MaxWidth(700.0f) });
            var keys = settings.hotkeys.Keys.ToArray();

            for (int index = 0; index < keys.Length; index++)
            {
                HK_TYPE key = keys[index];
                KeyCode keyCode = settings.hotkeys[key];
                string desc = Settings.hotkeyNames[key];
                // Do not allow modifying the close key 
                if (key == HK_TYPE.HK_CLOSE)
                {
                    settings.hotkeys[key] = KeyCode.Escape;
                }
                else
                {
                    renderHK_GUI(key, keyCode, desc);
                }
            }
            GUILayout.EndVertical();
        }


        /// <summary>
        /// 每次渲染 GUI 时处理绑定事件
        /// 若处于绑定事件中，且按下了键盘上的键，则设置快捷键并结束绑定事件
        /// </summary>
        private static void processKeyPress