static void Main(string[] args) { emClient = new ViGEmClient(); // Manages emulated XInput foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) { // Get local BT host MAC if (nic.NetworkInterfaceType != NetworkInterfaceType.FastEthernetFx && nic.NetworkInterfaceType != NetworkInterfaceType.Wireless80211) { if (nic.Name.Split()[0] == "Bluetooth") { btMAC = nic.GetPhysicalAddress(); } } } JoyconManager mgr = new JoyconManager(); mgr.Awake(); mgr.Start(); server = new UdpServer(mgr.j); server.Start(IPAddress.Parse(ConfigurationSettings.AppSettings["IP"]), Int32.Parse(ConfigurationSettings.AppSettings["Port"])); HighResTimer timer = new HighResTimer(pollsPerSecond, new HighResTimer.ActionDelegate(mgr.Update)); timer.Start(); Console.Write("Press enter to quit."); Console.ReadLine(); server.Stop(); timer.Stop(); mgr.OnApplicationQuit(); }
static void Main(string[] args) { foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) { // Get local BT host MAC if (nic.NetworkInterfaceType != NetworkInterfaceType.FastEthernetFx && nic.NetworkInterfaceType != NetworkInterfaceType.Wireless80211) { if (nic.Name.Split()[0] == "Bluetooth") { btMAC = nic.GetPhysicalAddress(); } } } JoyconManager mgr = new JoyconManager(); mgr.Awake(); mgr.Start(); server = new UdpServer(mgr.j); //updateThread = new Thread(new ThreadStart(mgr.Update)); //updateThread.Start(); server.Start(26760); HighResTimer timer = new HighResTimer(pollsPerSecond, new HighResTimer.ActionDelegate(mgr.Update)); timer.Start(); Console.Write("Press enter to quit."); Console.ReadLine(); server.Stop(); timer.Stop(); mgr.OnApplicationQuit(); }
public void Awake() { instance = this; j = new ConcurrentList <Joycon>(); HIDapi.hid_init(); }
public static void Start() { pid = Process.GetCurrentProcess().Id.ToString(); // get current process id for HidCerberus.Srv if (useHIDG) { form.console.AppendText("HidGuardian is enabled.\r\n"); try { var HidCerberusService = new ServiceController("HidCerberus Service"); if (HidCerberusService.Status == ServiceControllerStatus.Stopped) { form.console.AppendText("HidGuardian was stopped. Starting...\r\n"); try { HidCerberusService.Start(); } catch (Exception e) { form.console.AppendText("Unable to start HidGuardian - everything should work fine without it, but if you need it, run the app again as an admin.\r\n"); useHIDG = false; } } } catch (Exception e) { form.console.AppendText("Unable to start HidGuardian - everything should work fine without it, but if you need it, install it properly as admin.\r\n"); useHIDG = false; } HttpWebResponse response; if (Boolean.Parse(ConfigurationManager.AppSettings["PurgeWhitelist"])) { try { response = (HttpWebResponse)WebRequest.Create(@"http://*****:*****@"http://localhost:26762/api/v1/hidguardian/whitelist/add/" + pid).GetResponse(); // add BetterJoyForCemu to allowed processes } catch (Exception e) { form.console.AppendText("Unable to add program to whitelist.\r\n"); useHIDG = false; } } if (Boolean.Parse(ConfigurationManager.AppSettings["ShowAsXInput"]) || Boolean.Parse(ConfigurationManager.AppSettings["ShowAsDS4"])) { try { emClient = new ViGEmClient(); // Manages emulated XInput } catch (Nefarius.ViGEm.Client.Exceptions.VigemBusNotFoundException) { form.console.AppendText("Could not start VigemBus. Make sure drivers are installed correctly.\r\n"); } } foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) { // Get local BT host MAC if (nic.NetworkInterfaceType != NetworkInterfaceType.FastEthernetFx && nic.NetworkInterfaceType != NetworkInterfaceType.Wireless80211) { if (nic.Name.Split()[0] == "Bluetooth") { btMAC = nic.GetPhysicalAddress(); } } } // a bit hacky _3rdPartyControllers partyForm = new _3rdPartyControllers(); partyForm.CopyCustomControllers(); mgr = new JoyconManager(); mgr.form = form; mgr.Awake(); mgr.CheckForNewControllers(); mgr.Start(); server = new UdpServer(mgr.j); server.form = form; server.Start(IPAddress.Parse(ConfigurationManager.AppSettings["IP"]), Int32.Parse(ConfigurationManager.AppSettings["Port"])); // Capture keyboard + mouse events for binding's sake keyboard = WindowsInput.Capture.Global.KeyboardAsync(); keyboard.KeyEvent += Keyboard_KeyEvent; mouse = WindowsInput.Capture.Global.MouseAsync(); mouse.MouseEvent += Mouse_MouseEvent; form.console.AppendText("All systems go\r\n"); }
public static void Start() { pid = Process.GetCurrentProcess().Id.ToString(); // get current process id for HidCerberus.Srv if (useHIDG) { try { var HidCerberusService = new ServiceController("HidCerberus Service"); if (HidCerberusService.Status == ServiceControllerStatus.Stopped) { form.console.Text += "HidGuardian was stopped. Starting...\r\n"; try { HidCerberusService.Start(); } catch (Exception e) { form.console.Text += "Unable to start HidGuardian - everything should work fine without it, but if you need it, run the app again as an admin.\r\n"; useHIDG = false; } } } catch (Exception e) { form.console.Text += "Unable to start HidGuardian - everything should work fine without it, but if you need it, install it properly as admin.\r\n"; useHIDG = false; } HttpWebResponse response; if (Boolean.Parse(ConfigurationManager.AppSettings["PurgeWhitelist"])) { try { response = (HttpWebResponse)WebRequest.Create(@"http://*****:*****@"http://localhost:26762/api/v1/hidguardian/whitelist/add/" + pid).GetResponse(); // add BetterJoyForCemu to allowed processes } catch (Exception e) { form.console.Text += "Unable to add program to whitelist.\r\n"; useHIDG = false; } } else { form.console.Text += "HidGuardian is disabled.\r\n"; } emClient = new ViGEmClient(); // Manages emulated XInput foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) { // Get local BT host MAC if (nic.NetworkInterfaceType != NetworkInterfaceType.FastEthernetFx && nic.NetworkInterfaceType != NetworkInterfaceType.Wireless80211) { if (nic.Name.Split()[0] == "Bluetooth") { btMAC = nic.GetPhysicalAddress(); } } } mgr = new JoyconManager(); mgr.form = form; mgr.Awake(); mgr.CheckForNewControllers(); mgr.Start(); server = new UdpServer(mgr.j); server.form = form; server.Start(IPAddress.Parse(ConfigurationManager.AppSettings["IP"]), Int32.Parse(ConfigurationManager.AppSettings["Port"])); timer = new HighResTimer(pollsPerSecond, new HighResTimer.ActionDelegate(mgr.Update)); timer.Start(); form.console.Text += "All systems go\r\n"; }
public void Awake() { _instance = this; j = new List <Joycon>(); HIDapi.hid_init(); }
public static void Start() { pid = Process.GetCurrentProcess().Id.ToString(); // get current process id for HidCerberus.Srv if (useHIDG) { form.console.AppendText("HidGuardian已启用.\r\n"); try { var HidCerberusService = new ServiceController("HidCerberus服务"); if (HidCerberusService.Status == ServiceControllerStatus.Stopped) { form.console.AppendText("HidGuardian已停止. 启动中...\r\n"); try { HidCerberusService.Start(); } catch (Exception e) { form.console.AppendText("无法启动HidGuardian - 没有它一切都可以正常工作,但是如果需要,请以管理员身份再次运行.\r\n"); useHIDG = false; } } } catch (Exception e) { form.console.AppendText("无法启动HidGuardian - 没有它一切都可以正常工作,但是如果需要,请以管理员身份正确安装.\r\n"); useHIDG = false; } HttpWebResponse response; if (Boolean.Parse(ConfigurationManager.AppSettings["清除白名单"])) { try { response = (HttpWebResponse)WebRequest.Create(@"http://*****:*****@"http://localhost:26762/api/v1/hidguardian/whitelist/add/" + pid).GetResponse(); // add BetterJoyForCemu to allowed processes } catch (Exception e) { form.console.AppendText("无法添加程序至白名单.\r\n"); useHIDG = false; } } if (Boolean.Parse(ConfigurationManager.AppSettings["以XInput显示"]) || Boolean.Parse(ConfigurationManager.AppSettings["以DS4显示"])) { try { emClient = new ViGEmClient(); // Manages emulated XInput } catch (Nefarius.ViGEm.Client.Exceptions.VigemBusNotFoundException) { form.console.AppendText("无法启动VigemBus驱动程序.请确认驱动已正确安装.\r\n"); } } foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) { // Get local BT host MAC if (nic.NetworkInterfaceType != NetworkInterfaceType.FastEthernetFx && nic.NetworkInterfaceType != NetworkInterfaceType.Wireless80211) { if (nic.Name.Split()[0] == "Bluetooth") { btMAC = nic.GetPhysicalAddress(); } } } // a bit hacky _3rdPartyControllers partyForm = new _3rdPartyControllers(); partyForm.CopyCustomControllers(); mgr = new JoyconManager(); mgr.form = form; mgr.Awake(); mgr.CheckForNewControllers(); mgr.Start(); server = new UdpServer(mgr.j); server.form = form; server.Start(IPAddress.Parse(ConfigurationManager.AppSettings["IP"]), Int32.Parse(ConfigurationManager.AppSettings["端口"])); // Capture keyboard + mouse events for binding's sake keyboard = WindowsInput.Capture.Global.KeyboardAsync(); keyboard.KeyEvent += Keyboard_KeyEvent; mouse = WindowsInput.Capture.Global.MouseAsync(); mouse.MouseEvent += Mouse_MouseEvent; form.console.AppendText("一切就绪\r\n"); }
public void Awake() { instance = this; int i = 0; j = new List <Joycon>(); bool isLeft = false; HIDapi.hid_init(); IntPtr ptr = HIDapi.hid_enumerate(vendor_id, 0x0); IntPtr top_ptr = ptr; if (ptr == IntPtr.Zero) { ptr = HIDapi.hid_enumerate(vendor_id_, 0x0); if (ptr == IntPtr.Zero) { HIDapi.hid_free_enumeration(ptr); Console.WriteLine("No Joy-Cons found!"); } } hid_device_info enumerate; while (ptr != IntPtr.Zero) { enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info)); if (enumerate.product_id == product_l || enumerate.product_id == product_r || enumerate.product_id == product_pro) { if (enumerate.product_id == product_l) { isLeft = true; Console.WriteLine("Left Joy-Con connected."); } else if (enumerate.product_id == product_r) { isLeft = false; Console.WriteLine("Right Joy-Con connected."); } else if (enumerate.product_id == product_pro) { isLeft = true; Console.WriteLine("Pro controller connected."); } else { Console.WriteLine("Non Joy-Con input device skipped."); } IntPtr handle = HIDapi.hid_open_path(enumerate.path); try { HIDapi.hid_set_nonblocking(handle, 1); } catch (Exception e) { Console.WriteLine("Unable to open path to device - are you using the correct (64 vs 32-bit) version for your PC?"); break; } j.Add(new Joycon(handle, EnableIMU, EnableLocalize & EnableIMU, 0.05f, isLeft, j.Count, enumerate.product_id == product_pro, enumerate.serial_number == "000000000001")); byte[] mac = new byte[6]; for (int n = 0; n < 6; n++) { mac[n] = byte.Parse(enumerate.serial_number.Substring(n * 2, 2), System.Globalization.NumberStyles.HexNumber); } j[j.Count - 1].PadMacAddress = new PhysicalAddress(mac); ++i; } ptr = enumerate.next; } int found = 0; foreach (Joycon v in j) { if (v.isLeft && !v.isPro) { found++; } if (!v.isLeft && !v.isPro) { found++; } } if (found == 2) { Console.WriteLine("Both joycons successfully found."); Joycon temp = null; foreach (Joycon v in j) { if (v.isLeft && !v.isPro) { if (temp == null) { temp = v; } else { temp.other = v; v.other = temp; } } if (!v.isLeft && !v.isPro) { if (temp == null) { temp = v; } else { temp.other = v; v.other = temp; } } } // Join up the two joycons } else if (found != 0) { Console.WriteLine("Only one joycon found. Please connect both and then restart the program."); } HIDapi.hid_free_enumeration(top_ptr); }
public static void Start() { if (useHidHide) { form.console.AppendText("HidHide is enabled.\r\n"); if (useHidHide && Boolean.Parse(ConfigurationManager.AppSettings["PurgeAffectedDevices"])) { try { HidHide.blacklistDevices(new List <string>(), false); } catch (Exception /*e*/) { form.console.AppendText("Unable to purge blacklisted devices.\r\n"); useHidHide = false; } } if (useHidHide) { try { List <string> applications = new List <string>(); applications.Add(System.Environment.ProcessPath); bool keepExisting = true; if (Boolean.Parse(ConfigurationManager.AppSettings["PurgeWhitelist"])) { keepExisting = false; } HidHide.whitelistApplications(applications, keepExisting); } catch (Exception /*e*/) { form.console.AppendText("Unable to add program to whitelist.\r\n"); useHidHide = false; } } if (useHidHide) { try { HidHide.setStatus(true); } catch (Exception /*e*/) { form.console.AppendText("Unable to hide devices.\r\n"); useHidHide = false; } } } if (Boolean.Parse(ConfigurationManager.AppSettings["ShowAsXInput"]) || Boolean.Parse(ConfigurationManager.AppSettings["ShowAsDS4"])) { try { emClient = new ViGEmClient(); // Manages emulated XInput } catch (Nefarius.ViGEm.Client.Exceptions.VigemBusNotFoundException) { form.console.AppendText("Could not start VigemBus. Make sure drivers are installed correctly.\r\n"); } } foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces()) { // Get local BT host MAC if (nic.NetworkInterfaceType != NetworkInterfaceType.FastEthernetFx && nic.NetworkInterfaceType != NetworkInterfaceType.Wireless80211) { if (nic.Name.Split()[0] == "Bluetooth") { btMAC = nic.GetPhysicalAddress(); } } } // a bit hacky _3rdPartyControllers partyForm = new _3rdPartyControllers(); partyForm.CopyCustomControllers(); mgr = new JoyconManager(); mgr.form = form; mgr.Awake(); server = new UdpServer(mgr.j); server.form = form; server.Start(IPAddress.Parse(ConfigurationManager.AppSettings["IP"]), Int32.Parse(ConfigurationManager.AppSettings["Port"])); // Capture keyboard + mouse events for binding's sake keyboard = WindowsInput.Capture.Global.KeyboardAsync(); keyboard.KeyEvent += Keyboard_KeyEvent; mouse = WindowsInput.Capture.Global.MouseAsync(); mouse.MouseEvent += Mouse_MouseEvent; form.console.AppendText("All systems go\r\n"); mgr.Start(); }
public void Awake() { instance = this; int i = 0; j = new List <Joycon>(); bool isLeft = false; HIDapi.hid_init(); IntPtr ptr = HIDapi.hid_enumerate(vendor_id, 0x0); IntPtr top_ptr = ptr; if (ptr == IntPtr.Zero) { ptr = HIDapi.hid_enumerate(vendor_id_, 0x0); if (ptr == IntPtr.Zero) { HIDapi.hid_free_enumeration(ptr); form.console.Text += "No Joy-Cons found!\r\n"; } } hid_device_info enumerate; while (ptr != IntPtr.Zero) { enumerate = (hid_device_info)Marshal.PtrToStructure(ptr, typeof(hid_device_info)); if (enumerate.product_id == product_l || enumerate.product_id == product_r || enumerate.product_id == product_pro) { if (enumerate.product_id == product_l) { isLeft = true; form.console.Text += "Left Joy-Con connected.\r\n"; } else if (enumerate.product_id == product_r) { isLeft = false; form.console.Text += "Right Joy-Con connected.\r\n"; } else if (enumerate.product_id == product_pro) { isLeft = true; form.console.Text += "Pro controller connected.\r\n"; } else { form.console.Text += "Non Joy-Con input device skipped.\r\n"; } // Add controller to block-list for HidGuardian HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://*****:*****@"hwids=HID\" + enumerate.path.Split('#')[1].ToUpper(); var data = Encoding.UTF8.GetBytes(postData); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8"; request.ContentLength = data.Length; using (var stream = request.GetRequestStream()) stream.Write(data, 0, data.Length); try { var response = (HttpWebResponse)request.GetResponse(); var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); } catch (Exception e) { form.console.Text += "Unable to add controller to block-list.\r\n"; } // -------------------- // IntPtr handle = HIDapi.hid_open_path(enumerate.path); try { HIDapi.hid_set_nonblocking(handle, 1); } catch (Exception e) { form.console.Text += "Unable to open path to device - are you using the correct (64 vs 32-bit) version for your PC?\r\n"; break; } j.Add(new Joycon(handle, EnableIMU, EnableLocalize & EnableIMU, 0.05f, isLeft, j.Count, enumerate.product_id == product_pro, enumerate.serial_number == "000000000001")); j.Last().form = form; byte[] mac = new byte[6]; for (int n = 0; n < 6; n++) { mac[n] = byte.Parse(enumerate.serial_number.Substring(n * 2, 2), System.Globalization.NumberStyles.HexNumber); } j[j.Count - 1].PadMacAddress = new PhysicalAddress(mac); ++i; } ptr = enumerate.next; } int found = 0; foreach (Joycon v in j) { if (v.isLeft && !v.isPro) { found++; } if (!v.isLeft && !v.isPro) { found++; } } if (found == 2) { form.console.Text += "Both joycons successfully found.\r\n"; Joycon temp = null; foreach (Joycon v in j) { if (v.isLeft && !v.isPro) { if (temp == null) { temp = v; } else { temp.other = v; v.other = temp; } } if (!v.isLeft && !v.isPro) { if (temp == null) { temp = v; } else { temp.other = v; v.other = temp; } } } // Join up the two joycons } else if (found != 0) { form.console.Text += "Only one joycon found. Please connect both and then restart the program.\r\n"; } HIDapi.hid_free_enumeration(top_ptr); }