コード例 #1
0
        protected override bool ParseDat(BinaryReader stream)
        {
            keybindList.Clear();
            if (base.ParseDat(stream))
            {
                stream.BaseStream.Seek(0x11, SeekOrigin.Begin);
                while (stream.BaseStream.Position < header.dataSize)
                {
                    KeybindSection command = ParseSection(stream);
                    KeybindSection keybind = ParseSection(stream);

                    string key = System.Text.Encoding.UTF8.GetString(command.data);
                    key = key.Substring(0, key.Length - 1);                     // Trim off \0
                    string   dat     = System.Text.Encoding.UTF8.GetString(keybind.data);
                    string[] datKeys = dat.Split(',');
                    if (datKeys.Length == 3)
                    {
                        string[] key1 = datKeys[0].Split('.');
                        string[] key2 = datKeys[1].Split('.');
                        keybindList.Add(key, new Keybind {
                            mainKey1 = int.Parse(key1[0], System.Globalization.NumberStyles.HexNumber),
                            mainKey2 = int.Parse(key2[0], System.Globalization.NumberStyles.HexNumber),
                            modKey1  = int.Parse(key1[1], System.Globalization.NumberStyles.HexNumber),
                            modKey2  = int.Parse(key2[1], System.Globalization.NumberStyles.HexNumber),
                        });
                    }
                }
            }
            Console.WriteLine("Read " + keybindList.Count + " keys");
            return(true);
        }
コード例 #2
0
        private static void ApplyConfigToKeybinds(Dictionary <KeyAction, KeyCode> keybinds,
                                                  KeybindSection keybindsSection)
        {
            foreach (NameValueConfigurationElement e in keybindsSection.Settings)
            {
                var action = (KeyAction)Enum.Parse(typeof(KeyAction), e.Name);

                if (!Enum.IsDefined(typeof(KeyAction), action)) // Ignore, old config ? malformed ? -> delete ?
                {
                    return;
                }
                var code = (KeyCode)Enum.Parse(typeof(KeyCode), e.Value);
                if (!Enum.IsDefined(typeof(KeyCode), code))
                {
                    //Wrong key, write default value instead
                    if (DefaultKeyBinds.TryGetValue(action, out var bind))
                    {
                        keybindsSection.Settings.Add(new NameValueConfigurationElement(e.Name, bind.ToString()));
                    }
                }
                else
                {
                    keybinds[action] = code;
                }
            }

            _config.Save(ConfigurationSaveMode.Full);
        }
コード例 #3
0
        private static void WriteDefaultConfig(KeybindSection keybindsSection)
        {
            if (keybindsSection == null)
            {
                keybindsSection = new KeybindSection();
                _config.Sections.Add("keybinds", keybindsSection);
            }

            if (DefaultKeyBinds.TryGetValue(KeyAction.Forward, out var bind))
            {
                keybindsSection.Settings.Add(
                    new NameValueConfigurationElement(nameof(KeyAction.Forward), bind.ToString()));
            }
            if (DefaultKeyBinds.TryGetValue(KeyAction.Left, out bind))
            {
                keybindsSection.Settings.Add(
                    new NameValueConfigurationElement(nameof(KeyAction.Left), bind.ToString()));
            }
            if (DefaultKeyBinds.TryGetValue(KeyAction.Backward, out bind))
            {
                keybindsSection.Settings.Add(
                    new NameValueConfigurationElement(nameof(KeyAction.Backward), bind.ToString()));
            }
            if (DefaultKeyBinds.TryGetValue(KeyAction.Right, out bind))
            {
                keybindsSection.Settings.Add(
                    new NameValueConfigurationElement(nameof(KeyAction.Right), bind.ToString()));
            }
            if (DefaultKeyBinds.TryGetValue(KeyAction.Use, out bind))
            {
                keybindsSection.Settings.Add(new NameValueConfigurationElement(nameof(KeyAction.Use), bind.ToString()));
            }
            if (DefaultKeyBinds.TryGetValue(KeyAction.Report, out bind))
            {
                keybindsSection.Settings.Add(
                    new NameValueConfigurationElement(nameof(KeyAction.Report), bind.ToString()));
            }
            if (DefaultKeyBinds.TryGetValue(KeyAction.Kill, out bind))
            {
                keybindsSection.Settings.Add(
                    new NameValueConfigurationElement(nameof(KeyAction.Kill), bind.ToString()));
            }
            if (DefaultKeyBinds.TryGetValue(KeyAction.Map, out bind))
            {
                keybindsSection.Settings.Add(new NameValueConfigurationElement(nameof(KeyAction.Map), bind.ToString()));
            }
            if (DefaultKeyBinds.TryGetValue(KeyAction.Tasks, out bind))
            {
                keybindsSection.Settings.Add(
                    new NameValueConfigurationElement(nameof(KeyAction.Tasks), bind.ToString()));
            }


            _config.Save(ConfigurationSaveMode.Modified);
        }
コード例 #4
0
        private KeybindSection ParseSection(BinaryReader stream)
        {
            byte[]         headerBytes = XorTools.ReadXorBytes(stream, 3, 0x73);
            KeybindSection section     = new KeybindSection {
                type = headerBytes[0],
                size = headerBytes[1],
            };

            section.data = XorTools.ReadXorBytes(stream, section.size, 0x73);
            Array.Reverse(section.data);
            return(section);
        }