public static SavedHotkeys Load(BinaryReader reader)
    {
        var hotkeys = new SavedHotkeys();

        for (var keyIndex = reader.ReadInt32(); keyIndex != -1; keyIndex = reader.ReadInt32())
        {
            var hotkey = new SavedHotkey();

            // Originally it just read the radial menu entry, but that contains so much
            // stale data it's not even funny.
            // The hotkey system will search the entire radial menu and compare each entry
            // against the following fields found in the hotkey system's copied radial menu entry:
            // - D20 action type
            // - D20 action data
            // - D20 spell data, spell enum original
            // - The upper 16 bit of the metamagic data
            // - Text Hash for certain action types
            reader.ReadInt32();                   // Stale text pointer
            reader.ReadInt32();                   // Stale text2 pointer
            hotkey.TextHash = reader.ReadInt32(); // Text elfhash
            reader.ReadInt32();                   // Padding
            reader.ReadInt32();                   // Radial menu entry type
            reader.ReadInt32();                   // min arg
            reader.ReadInt32();                   // max arg
            reader.ReadInt32();                   // Stale actual arg pointer
            var hotkeyActionType = reader.ReadInt32();
            hotkey.ActionData = reader.ReadInt32();
            reader.ReadInt32(); // Action CAF
            hotkey.SpellData = SavedD20Action.ReadSpellData(reader);
            reader.ReadInt32(); // Dispatcher key
            reader.ReadInt32(); // Callback pointer
            reader.ReadInt32(); // Flags
            reader.ReadInt32(); // Help text hash
            reader.ReadInt32(); // Spell Id

            hotkey.Text = reader.ReadFixedString(128);

            if (keyIndex >= AssignableKeys.Length)
            {
                throw new CorruptSaveException($"Hotkey table contains key which is outside range: {keyIndex}");
            }

            hotkey.Key = AssignableKeys[keyIndex];

            if (hotkeyActionType == -2)
            {
                continue; // Unassigned
            }

            hotkey.ActionType = (D20ActionType)hotkeyActionType;

            if (!hotkeys.Hotkeys.TryAdd(hotkey.Key, hotkey))
            {
                throw new CorruptSaveException($"Duplicate assignment to key {hotkey.Key}");
            }
        }

        return(hotkeys);
    }
Example #2
0
 /// <summary>
 /// Loads all saved hotkeys from settings.
 /// </summary>
 public void LoadHotkeys()
 {
     if (Settings.Default.Hotkeys != null)
     {
         foreach (var hotkey in Settings.Default.Hotkeys)
         {
             var keyInfo = hotkey.Split(',');
             SavedHotkeys.Add(keyInfo[0], $"{keyInfo[1]},{keyInfo[2]}");
         }
     }
 }
Example #3
0
 /// <summary>
 /// Attempts to create a hotkey with the given name from settings.
 /// </summary>
 /// <param name="name">Name (identifier) of the hotkey.</param>
 /// <param name="action">Action for this hotkey.</param>
 /// <returns></returns>
 public bool RegisterHotkeyFromSettings(string name, Action action)
 {
     // see if the key already exists
     if (SavedHotkeys.TryGetValue(name, out string keyInfo) == true)
     {
         // deserialize key info stored as csv
         var keys = keyInfo.Split(',');
         Int32.TryParse(keys[0], out int modKey);
         Int32.TryParse(keys[1], out int virtKey);
         try
         {
             ActiveHotkeys.Add(new Hotkey(name, (ModifierKeys)modKey, (Key)virtKey, action));
             return(true);
         }
         catch (InvalidOperationException) { return(false); }
     }
     else
     {
         return(false);
     }
 }