private void ErrorCheckOn(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { KeyCode boundKeyCode = GetBoundKeyCode(keyDef, slot); if (boundKeyCode != 0) { foreach (KeyBindingDef item in ConflictingBindings(keyDef, boundKeyCode)) { bool flag = boundKeyCode != keyDef.GetDefaultKeyCode(slot); Log.Warning("Key binding conflict: " + item + " and " + keyDef + " are both bound to " + boundKeyCode + "." + (flag ? " Fixed automatically." : "")); if (flag) { if (slot == KeyPrefs.BindingSlot.A) { keyPrefs[keyDef].keyBindingA = keyDef.defaultKeyCodeA; } else { keyPrefs[keyDef].keyBindingB = keyDef.defaultKeyCodeB; } KeyPrefs.Save(); } } } }
public static string AdjustedForKeys(this string text) { while (true) { int num = text.IndexOf("{Key:"); if (num < 0) { break; } int num2 = num; while (text[num2] != '}') { num2++; if (num2 == text.Length - 1) { goto Block_1; } } string defName = text.Substring(num + 5, num2 - (num + 5)); KeyBindingDef namedSilentFail = DefDatabase <KeyBindingDef> .GetNamedSilentFail(defName); if (namedSilentFail != null) { text = text.Substring(0, num) + namedSilentFail.MainKeyLabel + text.Substring(num2 + 1); } } return(text); Block_1: Log.Error("Cannot adjust for keys (mismatched braces): '" + text + "'"); return(text); }
public bool SetBinding(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot, KeyCode keyCode) { KeyBindingData keyBindingData = default(KeyBindingData); if (this.keyPrefs.TryGetValue(keyDef, out keyBindingData)) { switch (slot) { case KeyPrefs.BindingSlot.A: keyBindingData.keyBindingA = keyCode; break; case KeyPrefs.BindingSlot.B: keyBindingData.keyBindingB = keyCode; break; default: Log.Error("Tried to set a key binding for \"" + keyDef.LabelCap + "\" on a nonexistent slot: " + slot.ToString()); return(false); } return(true); } Log.Error("Key not found in keyprefs: \"" + keyDef.LabelCap + "\""); return(false); }
public bool SetBinding(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot, KeyCode keyCode) { KeyBindingData keyBindingData; bool result; if (this.keyPrefs.TryGetValue(keyDef, out keyBindingData)) { if (slot != KeyPrefs.BindingSlot.A) { if (slot != KeyPrefs.BindingSlot.B) { Log.Error("Tried to set a key binding for \"" + keyDef.LabelCap + "\" on a nonexistent slot: " + slot.ToString(), false); return(false); } keyBindingData.keyBindingB = keyCode; } else { keyBindingData.keyBindingA = keyCode; } result = true; } else { Log.Error("Key not found in keyprefs: \"" + keyDef.LabelCap + "\"", false); result = false; } return(result); }
public static void Init() { bool flag = !new FileInfo(GenFilePaths.KeyPrefsFilePath).Exists; Dictionary <string, KeyBindingData> dictionary = DirectXmlLoader.ItemFromXmlFile <Dictionary <string, KeyBindingData> >(GenFilePaths.KeyPrefsFilePath, true); KeyPrefs.data = new KeyPrefsData(); KeyPrefs.unresolvedBindings = new Dictionary <string, KeyBindingData>(); foreach (KeyValuePair <string, KeyBindingData> current in dictionary) { KeyBindingDef namedSilentFail = DefDatabase <KeyBindingDef> .GetNamedSilentFail(current.Key); if (namedSilentFail != null) { KeyPrefs.data.keyPrefs[namedSilentFail] = current.Value; } else { KeyPrefs.unresolvedBindings[current.Key] = current.Value; } } if (flag) { KeyPrefs.data.ResetToDefaults(); } KeyPrefs.data.AddMissingDefaultBindings(); KeyPrefs.data.ErrorCheck(); if (flag) { KeyPrefs.Save(); } }
public static IEnumerable <KeyBindingDef> ImpliedKeyBindingDefs() { foreach (MainButtonDef item in from td in DefDatabase <MainButtonDef> .AllDefs orderby td.order select td) { if (item.defaultHotKey != 0) { KeyBindingDef keyDef = new KeyBindingDef { label = "Toggle " + item.label + " tab", defName = "MainTab_" + item.defName, category = KeyBindingCategoryDefOf.MainTabs, defaultKeyCodeA = item.defaultHotKey, modContentPack = item.modContentPack }; item.hotKey = keyDef; yield return(keyDef); /*Error: Unable to find new state assignment for yield return*/; } } yield break; IL_0187: /*Error near IL_0188: Unexpected return in MoveNext()*/; }
public static string AdjustedForKeys(this string text, List <string> outErrors = null, bool resolveKeys = true) { outErrors?.Clear(); if (text.NullOrEmpty()) { return(text); } int num = 0; while (true) { num++; if (num > 500000) { Log.Error("Too many iterations."); outErrors?.Add("The parsed string caused an infinite loop"); break; } int num2 = text.IndexOf("{Key:"); if (num2 < 0) { break; } int num3 = num2; while (text[num3] != '}') { num3++; if (num3 >= text.Length) { outErrors?.Add("Mismatched braces"); return(text); } } string text2 = text.Substring(num2 + 5, num3 - (num2 + 5)); KeyBindingDef namedSilentFail = DefDatabase <KeyBindingDef> .GetNamedSilentFail(text2); string str = text.Substring(0, num2); if (namedSilentFail != null) { str = ((!resolveKeys) ? (str + "placeholder") : (str + namedSilentFail.MainKeyLabel)); } else { str += "error"; if (outErrors != null) { string text3 = "Could not find key '" + text2 + "'"; string text4 = BackCompatibility.BackCompatibleDefName(typeof(KeyBindingDef), text2); if (text4 != text2) { text3 = text3 + " (hint: it was renamed to '" + text4 + "')"; } outErrors.Add(text3); } } str += text.Substring(num3 + 1); text = str; } return(text); }
private void ErrorCheckOn(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { KeyCode boundKeyCode = this.GetBoundKeyCode(keyDef, slot); if (boundKeyCode != KeyCode.None) { foreach (KeyBindingDef keyBindingDef in this.ConflictingBindings(keyDef, boundKeyCode)) { bool flag = boundKeyCode != keyDef.GetDefaultKeyCode(slot); Log.Error(string.Concat(new object[] { "Key binding conflict: ", keyBindingDef, " and ", keyDef, " are both bound to ", boundKeyCode, ".", (!flag) ? "" : " Fixed automatically." }), false); if (flag) { if (slot == KeyPrefs.BindingSlot.A) { this.keyPrefs[keyDef].keyBindingA = keyDef.defaultKeyCodeA; } else { this.keyPrefs[keyDef].keyBindingB = keyDef.defaultKeyCodeB; } KeyPrefs.Save(); } } } }
public void CheckConflictsFor(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { KeyCode boundKeyCode = this.GetBoundKeyCode(keyDef, slot); if (boundKeyCode != KeyCode.None) { this.EraseConflictingBindingsForKeyCode(keyDef, boundKeyCode, null); this.SetBinding(keyDef, slot, boundKeyCode); } }
private IEnumerable <KeyBindingDef> ConflictingBindings(KeyBindingDef keyDef, KeyCode code) { foreach (KeyBindingDef def in DefDatabase <KeyBindingDef> .AllDefs) { if (def != keyDef && ((def.category == keyDef.category && def.category.selfConflicting) || keyDef.category.checkForConflicts.Contains(def.category) || (keyDef.extraConflictTags != null && def.extraConflictTags != null && keyDef.extraConflictTags.Any((string tag) => def.extraConflictTags.Contains(tag)))) && keyPrefs.TryGetValue(def, out KeyBindingData value) && (value.keyBindingA == code || value.keyBindingB == code)) { yield return(def); } } }
public void CheckConflictsFor(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { KeyCode boundKeyCode = GetBoundKeyCode(keyDef, slot); if (boundKeyCode != 0) { EraseConflictingBindingsForKeyCode(keyDef, boundKeyCode); SetBinding(keyDef, slot, boundKeyCode); } }
public bool MoveNext() { uint num = (uint)this.$PC; this.$PC = -1; bool flag = false; switch (num) { case 0u: enumerator = DefDatabase <KeyBindingDef> .AllDefs.GetEnumerator(); num = 4294967293u; break; case 1u: break; default: return(false); } try { switch (num) { } while (enumerator.MoveNext()) { KeyBindingDef def = enumerator.Current; if (def != keyDef && ((def.category == keyDef.category && def.category.selfConflicting) || keyDef.category.checkForConflicts.Contains(def.category) || (keyDef.extraConflictTags != null && def.extraConflictTags != null && keyDef.extraConflictTags.Any((string tag) => def.extraConflictTags.Contains(tag)))) && this.keyPrefs.TryGetValue(def, out prefData) && (prefData.keyBindingA == code || prefData.keyBindingB == code)) { this.$current = def; if (!this.$disposing) { this.$PC = 1; } flag = true; return(true); } } } finally { if (!flag) { if (enumerator != null) { enumerator.Dispose(); } } } this.$PC = -1; return(false); }
public KeyCode GetBoundKeyCode(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { if (!keyPrefs.TryGetValue(keyDef, out var value)) { Log.Error("Key not found in keyprefs: \"" + keyDef.LabelCap + "\""); return(KeyCode.None); } return(slot switch { KeyPrefs.BindingSlot.A => value.keyBindingA, KeyPrefs.BindingSlot.B => value.keyBindingB, _ => throw new InvalidOperationException(), });
private IEnumerable <KeyBindingDef> ConflictingBindings(KeyBindingDef keyDef, KeyCode code) { using (IEnumerator <KeyBindingDef> enumerator = DefDatabase <KeyBindingDef> .AllDefs.GetEnumerator()) { while (enumerator.MoveNext()) { KeyBindingDef def = enumerator.Current; KeyBindingData prefData; if (def != keyDef && ((def.category == keyDef.category && def.category.selfConflicting) || keyDef.category.checkForConflicts.Contains(def.category) || (keyDef.extraConflictTags != null && def.extraConflictTags != null && keyDef.extraConflictTags.Any((string tag) => def.extraConflictTags.Contains(tag)))) && this.keyPrefs.TryGetValue(def, out prefData) && (prefData.keyBindingA == code || prefData.keyBindingB == code)) { yield return(def); } } } yield break; }
public void EraseConflictingBindingsForKeyCode(KeyBindingDef keyDef, KeyCode keyCode, Action <KeyBindingDef> callBackOnErase = null) { foreach (KeyBindingDef item in ConflictingBindings(keyDef, keyCode)) { KeyBindingData keyBindingData = keyPrefs[item]; if (keyBindingData.keyBindingA == keyCode) { keyBindingData.keyBindingA = KeyCode.None; } if (keyBindingData.keyBindingB == keyCode) { keyBindingData.keyBindingB = KeyCode.None; } callBackOnErase?.Invoke(item); } }
public static IEnumerable <KeyBindingDef> ImpliedKeyBindingDefs() { foreach (MainButtonDef item in DefDatabase <MainButtonDef> .AllDefs.OrderBy((MainButtonDef td) => td.order)) { if (item.defaultHotKey != 0) { KeyBindingDef keyBindingDef = new KeyBindingDef(); keyBindingDef.label = "Toggle " + item.label + " tab"; keyBindingDef.defName = "MainTab_" + item.defName; keyBindingDef.category = KeyBindingCategoryDefOf.MainTabs; keyBindingDef.defaultKeyCodeA = item.defaultHotKey; keyBindingDef.modContentPack = item.modContentPack; item.hotKey = keyBindingDef; yield return(keyBindingDef); } } }
public static IEnumerable <KeyBindingDef> ImpliedKeyBindingDefs() { foreach (MainButtonDef mainTab in from td in DefDatabase <MainButtonDef> .AllDefs orderby td.order select td) { if (mainTab.defaultHotKey != KeyCode.None) { KeyBindingDef keyDef = new KeyBindingDef(); keyDef.label = "Toggle " + mainTab.label + " tab"; keyDef.defName = "MainTab_" + mainTab.defName; keyDef.category = KeyBindingCategoryDefOf.MainTabs; keyDef.defaultKeyCodeA = mainTab.defaultHotKey; mainTab.hotKey = keyDef; yield return(keyDef); } } }
public KeyCode GetBoundKeyCode(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { if (!keyPrefs.TryGetValue(keyDef, out KeyBindingData value)) { Log.Error("Key not found in keyprefs: \"" + keyDef.LabelCap + "\""); return(KeyCode.None); } switch (slot) { case KeyPrefs.BindingSlot.A: return(value.keyBindingA); case KeyPrefs.BindingSlot.B: return(value.keyBindingB); default: throw new InvalidOperationException(); } }
public KeyCode GetBoundKeyCode(KeyBindingDef keyDef, KeyPrefs.BindingSlot slot) { KeyBindingData keyBindingData; if (!this.keyPrefs.TryGetValue(keyDef, out keyBindingData)) { Log.Error("Key not found in keyprefs: \"" + keyDef.LabelCap + "\"", false); return(KeyCode.None); } if (slot == KeyPrefs.BindingSlot.A) { return(keyBindingData.keyBindingA); } if (slot != KeyPrefs.BindingSlot.B) { throw new InvalidOperationException(); } return(keyBindingData.keyBindingB); }
public void EraseConflictingBindingsForKeyCode(KeyBindingDef keyDef, KeyCode keyCode, Action <KeyBindingDef> callBackOnErase = null) { foreach (KeyBindingDef keyBindingDef in this.ConflictingBindings(keyDef, keyCode)) { KeyBindingData keyBindingData = this.keyPrefs[keyBindingDef]; if (keyBindingData.keyBindingA == keyCode) { keyBindingData.keyBindingA = KeyCode.None; } if (keyBindingData.keyBindingB == keyCode) { keyBindingData.keyBindingB = KeyCode.None; } if (callBackOnErase != null) { callBackOnErase(keyBindingDef); } } }
private IEnumerable <KeyBindingDef> ConflictingBindings(KeyBindingDef keyDef, KeyCode code) { using (IEnumerator <KeyBindingDef> enumerator = DefDatabase <KeyBindingDef> .AllDefs.GetEnumerator()) { while (enumerator.MoveNext()) { _003CConflictingBindings_003Ec__Iterator0 _003CConflictingBindings_003Ec__Iterator = (_003CConflictingBindings_003Ec__Iterator0) /*Error near IL_0058: stateMachine*/; KeyBindingDef def = enumerator.Current; KeyBindingData prefData; if (def != keyDef && ((def.category == keyDef.category && def.category.selfConflicting) || keyDef.category.checkForConflicts.Contains(def.category) || (keyDef.extraConflictTags != null && def.extraConflictTags != null && keyDef.extraConflictTags.Any((string tag) => def.extraConflictTags.Contains(tag)))) && keyPrefs.TryGetValue(def, out prefData) && (prefData.keyBindingA == code || prefData.keyBindingB == code)) { yield return(def); /*Error: Unable to find new state assignment for yield return*/; } } } yield break; IL_01eb: /*Error near IL_01ec: Unexpected return in MoveNext()*/; }