Esempio n. 1
0
        /// <summary>
        /// Enable or disable virtual controllers depending on game settings.
        /// </summary>
        /// <param name="game"></param>
        void UpdateVirtualDevices(UserGame game)
        {
            // Allow if not testing or testing with option enabled.
            var o     = SettingsManager.Options;
            var allow = !o.TestEnabled || o.TestSetXInputStates;

            if (!allow)
            {
                return;
            }
            // If virtual driver is missing then return.
            if (!ViGEmClient.isVBusExists())
            {
                return;
            }
            var isVirtual = game != null && ((EmulationType)game.EmulationType).HasFlag(EmulationType.Virtual);

            // If game does not use virtual emulation then...
            if (!isVirtual)
            {
                ViGEmClient.DisposeCurrent();
                return;
            }
            var client = ViGEmClient.Current;

            if (client.Targets == null)
            {
                client.Targets = new Xbox360Controller[4];
                for (int i = 0; i < 4; i++)
                {
                    var controller = new Xbox360Controller(client);
                    client.Targets[i]            = controller;
                    controller.FeedbackReceived += Controller_FeedbackReceived;
                }
            }
            for (uint i = 1; i <= 4; i++)
            {
                var mapTo          = (MapTo)i;
                var flag           = AppHelper.GetMapFlag(mapTo);
                var value          = (MapToMask)(game?.EnableMask ?? (int)MapToMask.None);
                var virtualEnabled = value.HasFlag(flag);
                var feedingState   = FeedingState[i - 1];
                if (virtualEnabled)
                {
                    // If feeding status unknown or not enabled then...
                    if (!feedingState.HasValue || !feedingState.Value || !client.IsControllerConnected(i))
                    {
                        var success = EnableFeeding(i) == VirtualError.None;
                        if (!success)
                        {
                            return;
                        }
                        FeedingState[i - 1] = true;
                    }
                    FeedDevice(i);
                }
                else
                {
                    // If feeding status unknown or enabled then...
                    if (!feedingState.HasValue || feedingState.Value || client.IsControllerConnected(i))
                    {
                        var success = DisableFeeding(i) == VirtualError.None;
                        if (!success)
                        {
                            return;
                        }
                        FeedingState[i - 1] = false;
                    }
                }
            }
        }
Esempio n. 2
0
        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");
        }
Esempio n. 3
0
 public DS4OutDevice(ViGEmClient client)
 {
     Controller = new DualShock4Controller(client);
     report     = new DualShock4Report();
 }
Esempio n. 4
0
 public Xbox360OutDevice(ViGEmClient client)
 {
     cont   = new Xbox360Controller(client);
     report = new Xbox360Report();
 }
Esempio n. 5
0
 public DS4OutDevice(ViGEmClient client)
 {
     cont = client.CreateDualShock4Controller();
     cont.AutoSubmitReport = false;
 }
Esempio n. 6
0
        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";
                        }
                    }
                } 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";
                }

                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";
                }
            }
            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";
        }
Esempio n. 7
0
 /// <inheritdoc />
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:Nefarius.ViGEm.Client.Targets.Xbox360Controller" /> class bound to a
 ///     <see cref="T:Nefarius.ViGEm.Client.ViGEmClient" />.
 /// </summary>
 /// <param name="client">The <see cref="T:Nefarius.ViGEm.Client.ViGEmClient" /> this device is attached to.</param>
 public Xbox360Controller(ViGEmClient client) : base(client)
 {
     NativeHandle = ViGEmClient.vigem_target_x360_alloc();
 }
Esempio n. 8
0
        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 Service");
                    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 - 虽然没有它程序也能正常工作,但如果你需要它,请退出程序后以管理员权限安装HidGuardian。\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("无法将程序添加到白名单。\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("无法启动VigemBus,请确保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["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("全部系统就绪。\r\n");
        }
Esempio n. 9
0
        public static void Main(string[] args)
        {
            Console.Title = "GHL HID Emulator";
            UsbDevice guitar = null;
            bool      isPS4  = false;

            foreach (WinUsbRegistry device in LibUsbDotNet.UsbDevice.AllWinUsbDevices)
            {
                // USB\VID_12BA&PID_074B
                if ((device.Vid == 0x12BA && device.Pid == 0x074B) || (device.Vid == 0x1430 && device.Pid == 0x07BB))
                {
                    guitar = device.Device;
                    isPS4  = (device.Pid == 0x07BB);
                }
            }
            if (guitar == null)
            {
                Console.WriteLine("Could not find any Guitar Hero Live guitars.");
                Console.WriteLine("Make sure you are using a PS3/Wii U/PS4 Guitar Hero Live dongle with the WinUSB driver installed.");
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey(true);
                return;
            }

            // Set up Virtual Xbox 360 controller
            ViGEmClient client;

            try
            {
                client = new ViGEmClient();
            } catch (Exception)
            {
                Console.WriteLine("Failed to initialise ViGEm Client. Make sure you have the ViGEm bus driver installed.");
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey(true);
                return;
            }

            IXbox360Controller controller = client.CreateXbox360Controller();

            controller.Connect();
            Console.WriteLine($"Found a Guitar Hero Live guitar!");

            var reader = guitar.OpenEndpointReader(ReadEndpointID.Ep01);

            byte[] readBuffer = new byte[100];
            int    runner     = 0;

            while (true)
            {
                if (runner == 0)
                {
                    // Send control packet (to enable strumming)
                    byte[] buffer;
                    if (isPS4)
                    {
                        buffer = new byte[9] {
                            0x30, 0x02, 0x08, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00
                        }
                    }
                    ;
                    else
                    {
                        buffer = new byte[9] {
                            0x02, 0x08, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                        }
                    };
                    int            bytesWrote;
                    UsbSetupPacket setupPacket = new UsbSetupPacket(0x21, 0x09, 0x0201, 0x0000, 0x0008);
                    guitar.ControlTransfer(ref setupPacket, buffer, 0x0008, out bytesWrote);
                }
                runner++;
                if (runner > 500)
                {
                    runner = 0;
                }

                int bytesRead;
                reader.Read(readBuffer, 100, out bytesRead);
                Console.SetCursorPosition(0, 1);
                Console.WriteLine("Frets:    " + BitConverter.ToString(new byte[] { readBuffer[0] }));
                Console.WriteLine("Buttons:  " + BitConverter.ToString(new byte[] { readBuffer[1] }));
                Console.WriteLine("Tilt:     " + BitConverter.ToString(new byte[] { readBuffer[19] }));
                Console.WriteLine("Whammy:   " + BitConverter.ToString(new byte[] { readBuffer[6] }));
                Console.WriteLine("Strum:    " + (readBuffer[4] == 0x00 || readBuffer[4] == 0xFF) + " ");
                Console.WriteLine("Raw Data: " + BitConverter.ToString(readBuffer));

                byte frets = readBuffer[0];
                controller.SetButtonState(Xbox360Button.A, (frets & 0x02) != 0x00);             // B1
                controller.SetButtonState(Xbox360Button.B, (frets & 0x04) != 0x00);             // B2
                controller.SetButtonState(Xbox360Button.Y, (frets & 0x08) != 0x00);             // B3
                controller.SetButtonState(Xbox360Button.X, (frets & 0x01) != 0x00);             // W1
                controller.SetButtonState(Xbox360Button.LeftShoulder, (frets & 0x10) != 0x00);  // W2
                controller.SetButtonState(Xbox360Button.RightShoulder, (frets & 0x20) != 0x00); // W3

                byte strum = readBuffer[4];
                if (strum == 0xFF)
                {
                    // Strum Down
                    controller.SetButtonState(Xbox360Button.Down, true);
                    controller.SetButtonState(Xbox360Button.Up, false);
                }
                else if (strum == 0x00)
                {
                    // Strum Up
                    controller.SetButtonState(Xbox360Button.Down, false);
                    controller.SetButtonState(Xbox360Button.Up, true);
                }
                else
                {
                    // No Strum
                    controller.SetButtonState(Xbox360Button.Down, false);
                    controller.SetButtonState(Xbox360Button.Up, false);
                }

                byte buttons = readBuffer[1];
                controller.SetButtonState(Xbox360Button.Start, (buttons & 0x02) != 0x00); // Pause
                controller.SetButtonState(Xbox360Button.Back, (buttons & 0x01) != 0x00);  // Hero Power

                // ViGEm isn't co-operating here - setting to some weird value causes an issue.
                //controller.SetAxisValue(Xbox360Axis.RightThumbY, (short)(~readBuffer[6]-128));
                //controller.SetAxisValue(Xbox360Axis.RightThumbX, readBuffer[19]);

                Console.WriteLine("Emulating as Xbox 360 Controller " + (controller.UserIndex + 1));
            }
        }
    }
Esempio n. 10
0
 public DualShock4Controller(ViGEmClient client, ushort vendorId, ushort productId) : this(client)
 {
     VendorId  = vendorId;
     ProductId = productId;
 }
Esempio n. 11
0
 public DualShock4Controller(ViGEmClient client) : base(client)
 {
     NativeHandle = ViGEmClient.vigem_target_ds4_alloc();
 }
Esempio n. 12
0
        static void Main(string[] args)
        {
            var client = new ViGEmClient();
            var x360   = new Xbox360Controller(client);

            IPEndPoint ipep     = new IPEndPoint(IPAddress.Parse(ConfigurationManager.AppSettings["bindAddr"]), UInt16.Parse(ConfigurationManager.AppSettings["bindPort"]));
            UdpClient  newsock  = new UdpClient(ipep);
            IPEndPoint senderep = new IPEndPoint(IPAddress.Any, 0);

            x360.FeedbackReceived +=
                (sender, eventArgs) =>
            {
            };

            x360.Connect();
            Console.WriteLine("Controller connected.");

            Console.WriteLine("Listening on {0}", ipep);

            var   report         = new Xbox360Report();
            var   lastRecv       = DateTime.Now;
            float tt             = 0;
            int   second_counter = 0;

            while (true)
            {
                var dt_t = DateTime.Now - lastRecv;
                lastRecv = DateTime.Now;
                float       dt = dt_t.Milliseconds / 1000.0f;
                InputStatus status;
                unsafe
                {
                    fixed(byte *data = &newsock.Receive(ref senderep)[0])
                    {
                        InputStatus *s = (InputStatus *)data;

                        status = *s;
                    }
                }
                report.Buttons = 0;
                for (int i = 0; i < 32; ++i)
                {
                    if ((status.kHeld & (1 << i)) != 0)
                    {
                        Xbox360Buttons?button = X3DSMap[i];
                        if (button != null)
                        {
                            report.SetButtons(button.Value);
                        }
                    }
                }
                if (status.touch.px > 0 && status.touch.py > 0)
                {
                    if (status.touch.px < 320 / 3)
                    {
                        report.SetButtons(Xbox360Buttons.LeftThumb);
                    }
                    else if (status.touch.px > 320 / 3 * 2)
                    {
                        report.SetButtons(Xbox360Buttons.RightThumb);
                    }
                    else
                    {
                        report.SetButtons(Xbox360Buttons.LeftThumb, Xbox360Buttons.RightThumb);
                    }
                }
                report.SetAxis(Xbox360Axes.LeftThumbX, (short)((float)status.pad.dx * Int16.MaxValue / 160.0f));
                report.SetAxis(Xbox360Axes.LeftThumbY, (short)((float)status.pad.dy * Int16.MaxValue / 160.0f));
                report.SetAxis(Xbox360Axes.RightThumbX, (short)((float)status.cstick.dx * Int16.MaxValue / 160.0f));
                report.SetAxis(Xbox360Axes.RightThumbY, (short)((float)status.cstick.dy * Int16.MaxValue / 160.0f));
                if ((status.kHeld & (1 << 14)) != 0)
                {
                    report.SetAxis(Xbox360Axes.LeftTrigger, Int16.MaxValue);
                }
                else
                {
                    report.SetAxis(Xbox360Axes.LeftTrigger, Int16.MinValue);
                }
                if ((status.kHeld & (1 << 15)) != 0)
                {
                    report.SetAxis(Xbox360Axes.RightTrigger, Int16.MaxValue);
                }
                else
                {
                    report.SetAxis(Xbox360Axes.RightTrigger, Int16.MinValue);
                }
                x360.SendReport(report);

                second_counter++;
                tt += dt;
                if (tt > 1.0f)
                {
                    Console.WriteLine("{0} packet received", second_counter);
                    tt             = 0;
                    second_counter = 0;
                }
            }
            Console.ReadKey();
        }
Esempio n. 13
0
        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();
        }
Esempio n. 14
0
 public XInputManager()
 {
     _ViGEmClient = new ViGEmClient();
     _Gamepads    = new Dictionary <string, MiGamepad>();
 }
Esempio n. 15
0
 public DS4OutDeviceBasic(ViGEmClient client) : base(client)
 {
 }
Esempio n. 16
0
 public VigemDevice()
 {
     InitMapping();
     client = new ViGEmClient();
 }
Esempio n. 17
0
 public Xbox360OutDevice(ViGEmClient client)
 {
     cont = client.CreateXbox360Controller();
     cont.AutoSubmitReport = false;
 }
Esempio n. 18
0
        private static void Main(string[] args)
        {
            var client = new ViGEmClient();

#if X360
            var x360 = new Xbox360Controller(client);

            x360.FeedbackReceived +=
                (sender, eventArgs) => Console.WriteLine(
                    $"LM: {eventArgs.LargeMotor}, " +
                    $"SM: {eventArgs.SmallMotor}, " +
                    $"LED: {eventArgs.LedNumber}");

            x360.Connect();

            var report = new Xbox360Report();
            report.SetButtons(Xbox360Buttons.A, Xbox360Buttons.B);
            report.SetAxis(Xbox360Axes.LeftTrigger, 0xFF);
            report.SetAxis(Xbox360Axes.RightTrigger, 0xFF);

            x360.SendReport(report);
#endif

            Console.Title = "ViGEm Benchmark - CLOSE THIS WINDOW TO STOP!";
            Console.WriteLine(Console.Title);

            var controllers = new ObservableCollection <DualShock4Controller>();

            controllers.CollectionChanged += (sender, eventArgs) =>
            {
                switch (eventArgs.Action)
                {
                case NotifyCollectionChangedAction.Add:
                    Console.WriteLine("Added Controller");
                    break;

                case NotifyCollectionChangedAction.Remove:
                    Console.WriteLine("Removed Controller");

                    if (((ObservableCollection <DualShock4Controller>)sender).Count == 0)
                    {
                        Console.WriteLine(" > Finished! Press any key to exit!");
                    }

                    break;
                }
            };

            for (int i = 0; i < 500; i++)
            {
                Console.WriteLine($" > Spawning device {i}");

                Task.Run(() =>
                {
                    var ds4 = new DualShock4Controller(client);

                    try
                    {
                        lock (controllers)
                            controllers.Add(ds4);

                        ds4.Connect();

                        var report = new DualShock4Report();
                        report.SetButtons(DualShock4Buttons.Cross);
                        ds4.SendReport(report);

                        Thread.Sleep(1000);
                        ds4.Disconnect();
                    }
                    finally
                    {
                        lock (controllers)
                            controllers.Remove(ds4);
                    }
                });

                Thread.Sleep(20);
            }

            /*
             * var x360 = new Xbox360Controller();
             * x360.FeedbackReceived +=
             *  (sender, eventArgs) => Console.WriteLine(
             *      $"LM: {eventArgs.LargeMotor}, " +
             *      $"SM: {eventArgs.SmallMotor}, " +
             *      $"LED: {eventArgs.LedNumber}");
             * x360.PlugIn();
             *
             * var report = new Xbox360Report();
             * report.SetButtons(Xbox360Buttons.A, Xbox360Buttons.B);
             * report.SetAxis(Xbox360Axes.LeftTrigger, 0xFF);
             * report.SetAxis(Xbox360Axes.RightTrigger, 0xFF);
             *
             * x360.SendReport(report);
             *
             * Console.ReadKey();
             *
             * var ds4 = new DualShock4Controller();
             * ds4.FeedbackReceived +=
             *  (sender, eventArgs) => Console.WriteLine(
             *      $"LM: {eventArgs.LargeMotor}, " +
             *      $"SM: {eventArgs.SmallMotor}, ");
             * ds4.PlugIn();
             */

            Console.ReadKey();
        }
Esempio n. 19
0
        public override void Disconnect()
        {
            ViGEmClient.vigem_target_x360_unregister_notification(NativeHandle);

            base.Disconnect();
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            try
            {
                client     = new ViGEmClient();
                controller = client.CreateXbox360Controller();
                controller.Connect();
                Console.WriteLine("Virtual Xbox360 gamepad connected.");
            }
            catch (Exception e)
            {
                Console.WriteLine("Could not connect to ViGEmClient\n");
                Console.WriteLine(e);
                Console.WriteLine("\nNote that you need to install ViGemBus for this app to work\n");
                Console.Read();
                return;
            }

            int i = 0;

            while (true)
            {
                // We'll cycle through 8 different stick states
                i++;
                i %= 80;
                int state = i / 10;

                short amount = Int16.MaxValue / 2;

                if (i == 0)
                {
                    controller.SetButtonState(Xbox360Button.A, true);
                }
                else
                {
                    controller.SetButtonState(Xbox360Button.A, false);
                }

                if (state == 0)
                {
                    controller.SetAxisValue(Xbox360Axis.LeftThumbX, amount);
                }
                else if (state == 1)
                {
                    controller.SetAxisValue(Xbox360Axis.LeftThumbX, (short)(-amount));
                }
                else
                {
                    controller.SetAxisValue(Xbox360Axis.LeftThumbX, 0);
                }

                if (state == 2)
                {
                    controller.SetAxisValue(Xbox360Axis.LeftThumbY, amount);
                }
                else if (state == 3)
                {
                    controller.SetAxisValue(Xbox360Axis.LeftThumbY, (short)(-amount));
                }
                else
                {
                    controller.SetAxisValue(Xbox360Axis.LeftThumbY, 0);
                }

                if (state == 4)
                {
                    controller.SetAxisValue(Xbox360Axis.RightThumbX, amount);
                }
                else if (state == 5)
                {
                    controller.SetAxisValue(Xbox360Axis.RightThumbX, (short)(-amount));
                }
                else
                {
                    controller.SetAxisValue(Xbox360Axis.RightThumbX, 0);
                }

                if (state == 6)
                {
                    controller.SetAxisValue(Xbox360Axis.RightThumbY, amount);
                }
                else if (state == 7)
                {
                    controller.SetAxisValue(Xbox360Axis.RightThumbY, (short)(-amount));
                }
                else
                {
                    controller.SetAxisValue(Xbox360Axis.RightThumbY, 0);
                }


                System.Threading.Thread.Sleep(50);
            }
        }
Esempio n. 21
0
 /// <inheritdoc />
 /// <summary>
 ///     Initializes a new instance of the <see cref="T:Nefarius.ViGEm.Client.Targets.Xbox360Controller" /> class bound to a
 ///     <see cref="T:Nefarius.ViGEm.Client.ViGEmClient" /> overriding the default Vendor and Product IDs with the provided
 ///     values.
 /// </summary>
 /// <param name="client">The <see cref="T:Nefarius.ViGEm.Client.ViGEmClient" /> this device is attached to.</param>
 /// <param name="vendorId">The Vendor ID to use.</param>
 /// <param name="productId">The Product ID to use.</param>
 public Xbox360Controller(ViGEmClient client, ushort vendorId, ushort productId) : this(client)
 {
     VendorId  = vendorId;
     ProductId = productId;
 }
Esempio n. 22
0
 public BatterySink()
 {
     _client = new ViGEmClient();
 }
Esempio n. 23
0
        static void Main(string[] args)
        {
            ViGEmClient        client     = new ViGEmClient();
            IXbox360Controller controller = client.CreateXbox360Controller();

            controller.AutoSubmitReport = false;
            controller.Connect();

            using (Host server = new Host()) {
                server.InitializeServer(6789, 2);

                Event netEvent;

                while (true)
                {
                    bool polled = false;

                    while (!polled)
                    {
                        if (server.CheckEvents(out netEvent) == false)
                        {
                            if (server.Service(15, out netEvent) == false)
                            {
                                break;
                            }

                            polled = true;
                        }

                        switch (netEvent.Type)
                        {
                        case EventType.None:
                            break;

                        case EventType.Connect:
                            Console.WriteLine("Client connected - ID: " + netEvent.ChannelID + ", IP: " + netEvent.Peer.Host);
                            break;

                        case EventType.Disconnect:
                            Console.WriteLine("Client disconnected - ID: " + netEvent.ChannelID + ", IP: " + netEvent.Peer.Host);
                            break;


                        case EventType.Receive:
                            Console.WriteLine("Packet received from - ID: " + netEvent.ChannelID + ", IP: " + netEvent.Peer.Host + ", Channel ID: " + netEvent.ChannelID + ", Data length: " + netEvent.Packet.Length);
                            int t;
                            Console.WriteLine(System.Text.Encoding.Default.GetString(netEvent.Packet.GetBytes()));
                            if (Int32.TryParse(System.Text.Encoding.Default.GetString(netEvent.Packet.GetBytes()), out t))
                            {
                                bool press = t < 20;

                                if (!keyboard_mode)
                                {
                                    if (t % 20 < 14)
                                    {
                                        controller.SetButtonState(t % 20, press);
                                    }
                                    else if (t % 20 == 14)
                                    {
                                        controller.SetSliderValue(Xbox360Slider.LeftTrigger, press ? (byte)0xFF : (byte)0x00);
                                    }
                                    else if (t % 20 == 15)
                                    {
                                        controller.SetSliderValue(Xbox360Slider.RightTrigger, press ? (byte)0xFF : (byte)0x00);
                                    }

                                    controller.SubmitReport();
                                }
                                else
                                {
                                    switch (t % 20)
                                    {
                                    case 0:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.D4).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.D4).Invoke();
                                        }
                                        break;

                                    case 1:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.D5).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.D5).Invoke();
                                        }
                                        break;

                                    case 2:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.D6).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.D6).Invoke();
                                        }
                                        break;

                                    case 3:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.D7).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.D7).Invoke();
                                        }
                                        break;

                                    case 4:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.R).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.R).Invoke();
                                        }
                                        break;

                                    case 5:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.T).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.T).Invoke();
                                        }
                                        break;

                                    case 6:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.Y).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.Y).Invoke();
                                        }
                                        break;

                                    case 7:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.U).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.U).Invoke();
                                        }
                                        break;

                                    case 8:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.F).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.F).Invoke();
                                        }
                                        break;

                                    case 9:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.G).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.G).Invoke();
                                        }
                                        break;

                                    case 10:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.H).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.H).Invoke();
                                        }
                                        break;

                                    case 11:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.J).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.J).Invoke();
                                        }
                                        break;

                                    case 12:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.V).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.V).Invoke();
                                        }
                                        break;

                                    case 13:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.B).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.B).Invoke();
                                        }
                                        break;

                                    case 14:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.N).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.N).Invoke();
                                        }
                                        break;

                                    case 15:
                                        if (press)
                                        {
                                            WindowsInput.Simulate.Events().Hold(WindowsInput.Events.KeyCode.M).Invoke();
                                        }
                                        else
                                        {
                                            WindowsInput.Simulate.Events().Release(WindowsInput.Events.KeyCode.M).Invoke();
                                        }
                                        break;
                                    }
                                }
                            }
                            netEvent.Packet.Dispose();
                            break;
                        }
                    }
                }

                server.Flush();
            }

            controller.Disconnect();
        }
Esempio n. 24
0
 public DS4OutDeviceExt(ViGEmClient client) : base(client)
 {
 }