/* * private static void removeControllerConfig_gamecube() * { * string path = Program.AppConfig.GetFullPath("dolphin"); * * string iniFile = Path.Combine(path, "User", "Config", "GCPadNew.ini"); * if (!File.Exists(iniFile)) * return; * * File.Delete(iniFile); * }*/ private static void generateControllerConfig_realwiimotes(string path, string filename, string anyDefKey) { string iniFile = Path.Combine(path, "User", "Config", filename); using (IniFile ini = new IniFile(iniFile, true)) { for (int i = 0; i < 5; i++) { ini.ClearSection("[" + anyDefKey + i.ToString() + "]"); ini.WriteValue("[" + anyDefKey + i.ToString() + "]", "Source", "2"); } ini.Save(); } }
private static void generateControllerConfig_any(string path, string filename, string anyDefKey, InputKeyMapping anyMapping, Dictionary <string, string> anyReverseAxes, Dictionary <string, string> anyReplacements, Dictionary <string, string> extraOptions = null) { //string path = Program.AppConfig.GetFullPath("dolphin"); string iniFile = Path.Combine(path, "User", "Config", filename); int nsamepad = 0; Dictionary <string, int> double_pads = new Dictionary <string, int>(); using (IniFile ini = new IniFile(iniFile, true)) { foreach (var pad in Program.Controllers) { string gcpad = anyDefKey + pad.PlayerIndex; ini.ClearSection(gcpad); if (pad.Config == null) { continue; } // SIDevice0 = 7 -> Keyb GCKeyNew.ini // SIDevice1 = 6 -> controlleur standard GCPadNew.ini string tech = "XInput"; string deviceName = "Gamepad"; if (pad.Config.Type == "keyboard") { tech = "DInput"; deviceName = "Keyboard Mouse"; } else if (!pad.Config.IsXInputDevice()) { var di = pad.Config.GetDirectInputInfo(); if (di == null) { continue; } tech = "DInput"; deviceName = di.Name; } if (double_pads.ContainsKey(tech + "/" + deviceName)) { nsamepad = double_pads[tech + "/" + deviceName]; } else { nsamepad = 0; } double_pads[tech + "/" + deviceName] = nsamepad + 1; ini.WriteValue(gcpad, "Device", tech + "/" + nsamepad.ToString() + "/" + deviceName); if (extraOptions != null) { foreach (var xtra in extraOptions) { ini.WriteValue(gcpad, xtra.Key, xtra.Value); } } foreach (var x in anyMapping) { string keyName = x.Value; if (pad.Config.Type == "keyboard") { var value = x.Value; if (x.Key == InputKey.a) { value = "Buttons/A"; } else if (x.Key == InputKey.b) { value = "Buttons/B"; } else if (x.Key == InputKey.up) { value = "Main Stick/Up"; } else if (x.Key == InputKey.down) { value = "Main Stick/Down"; } else if (x.Key == InputKey.left) { value = "Main Stick/Left"; } else if (x.Key == InputKey.right) { value = "Main Stick/Right"; } if (x.Key == InputKey.joystick1left || x.Key == InputKey.joystick1up) { continue; } var input = pad.Config[x.Key]; if (input == null) { continue; } var name = ToDolphinKey(input.Id); ini.WriteValue(gcpad, value, name); } else if (tech == "XInput") { var mapping = pad.Config.GetXInputMapping(x.Key); if (mapping != XINPUTMAPPING.UNKNOWN && xInputMapping.ContainsKey(mapping)) { ini.WriteValue(gcpad, x.Value, xInputMapping[mapping]); } string reverseAxis; if (anyReverseAxes.TryGetValue(x.Value, out reverseAxis)) { mapping = pad.Config.GetXInputMapping(x.Key, true); if (mapping != XINPUTMAPPING.UNKNOWN && xInputMapping.ContainsKey(mapping)) { ini.WriteValue(gcpad, reverseAxis, xInputMapping[mapping]); } } } else { var input = pad.Config[x.Key]; if (input == null) { continue; } if (input.Type == "button") { if (input.Id == 0) // Invert A & B { ini.WriteValue(gcpad, x.Value, "`Button 1`"); } else if (input.Id == 1) // Invert A & B { ini.WriteValue(gcpad, x.Value, "`Button 0`"); } else { ini.WriteValue(gcpad, x.Value, "`Button " + input.Id.ToString() + "`"); } } else if (input.Type == "hat") { string hat = "`Hat " + input.Id + " N`"; if (input.Value == 2) // SDL_HAT_RIGHT { hat = "`Hat " + input.Id + " E`"; } else if (input.Value == 4) // SDL_HAT_DOWN { hat = "`Hat " + input.Id + " S`"; } else if (input.Value == 8) // SDL_HAT_LEFT { hat = "`Hat " + input.Id + " W`"; } ini.WriteValue(gcpad, x.Value, hat); } else if (input.Type == "axis") { Func <Input, bool, string> axisValue = (inp, revertAxis) => { string axis = "`Axis "; if (inp.Id == 2 || inp.Id == 5) { axis += "Z"; } else if (inp.Id == 0 || inp.Id == 3) { axis += "X"; } else { axis += "Y"; } if (inp.Id == 3 || inp.Id == 4) { axis += "r"; } if (inp.Id == 5) { revertAxis = !revertAxis; } if ((!revertAxis && inp.Value > 0) || (revertAxis && inp.Value < 0)) { axis += "+"; } else { axis += "-"; } return(axis + "`"); }; ini.WriteValue(gcpad, x.Value, axisValue(input, false)); string reverseAxis; if (anyReverseAxes.TryGetValue(x.Value, out reverseAxis)) { ini.WriteValue(gcpad, reverseAxis, axisValue(input, true)); } } } } if (tech == "XInput") { // ini.WriteValue(gcpad, "Main Stick/Modifier", "`Thumb L`"); // ini.WriteValue(gcpad, "C-Stick/Modifier" , "`Thumb R`"); ini.WriteValue(gcpad, "Main Stick/Dead Zone", "5.0000000000000000"); ini.WriteValue(gcpad, "C-Stick/Dead Zone", "5.0000000000000000"); ini.WriteValue(gcpad, "Rumble/Motor", "`Motor L``Motor R`"); } } ini.Save(); } }