Exemplo n.º 1
0
        static void Main(string[] args)
        {
            if (!IsSingleInstance())
            {
                Environment.Exit(0);
            }
            NIcon = new NotifyIcon();
            //ScpBus scpBus = null;
            ScpBus scpBus = new ScpBus();

            scpBus.UnplugAll();
            global_scpBus = scpBus;

            handler = new ConsoleEventDelegate(ConsoleEventCallback);
            SetConsoleCtrlHandler(handler, true);

            Thread.Sleep(400);
            var controllersManager = new Thread(() => ManageControllers(scpBus));


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                try
                {
                    using (var pi = new ProcessIcon())
                    {
                        pi.Display();
                        controllersManager.Start();
                        Application.Run();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Program Terminated Unexpectedly",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                controllersManager.Abort();
                scpBus.UnplugAll();
                foreach (var device in Gamepads.Select(g => g.Device))
                {
                    device.CloseDevice();
                }
                singleInstanceMutex.ReleaseMutex();
            }
            finally
            {
                Environment.Exit(0);
            }
        }
Exemplo n.º 2
0
        public static void Start()
        {
            if (Started)
            {
                return;
            }

            scp.UnplugAll();

            scp = new ScpBus();
            scp.PlugIn(gamepadIndex);

            Started = true;

            Task.Run(() => Loop());
        }
Exemplo n.º 3
0
 static bool ConsoleEventCallback(int eventType)
 {
     if (eventType == 2)
     {
         global_scpBus.UnplugAll();
     }
     return(false);
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            ScpBus scpBus = new ScpBus();

            scpBus.UnplugAll();
            global_scpBus = scpBus;

            handler = new ConsoleEventDelegate(ConsoleEventCallback);
            SetConsoleCtrlHandler(handler, true);

            Thread.Sleep(400);

            Xiaomi_gamepad[] gamepads = new Xiaomi_gamepad[4];
            int index             = 1;
            var compatibleDevices = HidDevices.Enumerate(0x2717, 0x3144).ToList();

            foreach (var deviceInstance in compatibleDevices)
            {
                Console.WriteLine(deviceInstance);
                HidDevice Device = deviceInstance;
                try {
                    Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                } catch (Exception exception)
                {
                    Console.WriteLine("Could not open gamepad in exclusive mode. Please close anything that could be using the controller\nAttempting to open it in shared mode.");
                    Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                }

                byte[] Vibration = { 0x20, 0x00, 0x00 };
                if (Device.WriteFeatureData(Vibration) == false)
                {
                    Console.WriteLine("Could not write to gamepad (is it closed?), skipping");
                    Device.CloseDevice();
                    continue;
                }

                byte[] serialNumber;
                byte[] product;
                Device.ReadSerialNumber(out serialNumber);
                Device.ReadProduct(out product);


                gamepads[index - 1] = new Xiaomi_gamepad(Device, scpBus, index);
                ++index;

                if (index >= 5)
                {
                    break;
                }
            }

            Console.WriteLine("{0} controllers connected", index - 1);

            while (true)
            {
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 5
0
        private void Connect()
        {
            ScpBus scpBus = new ScpBus();

            scpBus.UnplugAll();
            global_scpBus = scpBus;

            gamepads = new Xiaomi_gamepad[4];
            int index             = 1;
            var compatibleDevices = HidDevices.Enumerate(0x2717, 0x3144).ToList();

            foreach (var deviceInstance in compatibleDevices)
            {
                //Console.WriteLine(deviceInstance);
                textBox.AppendText(deviceInstance + Environment.NewLine);
                HidDevice Device = deviceInstance;
                global_device = deviceInstance;
                try
                {
                    Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                }
                catch (Exception exception)
                {
                    //Console.WriteLine("Could not open gamepad in exclusive mode. Please close anything that could be using the controller\nAttempting to open it in shared mode.");
                    textBox.AppendText("Could not open gamepad in exclusive mode.Please close anything that could be using the controller" + Environment.NewLine + "Attempting to open it in shared mode." + Environment.NewLine);
                    Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                }

                byte[] Vibration = { 0x20, 0x00, 0x00 };
                if (Device.WriteFeatureData(Vibration) == false)
                {
                    //Console.WriteLine("Could not write to gamepad (is it closed?), skipping");
                    textBox.AppendText("Could not write to gamepad (is it closed?), skipping" + Environment.NewLine);
                    Device.CloseDevice();
                    continue;
                }

                byte[] serialNumber;
                byte[] product;
                Device.ReadSerialNumber(out serialNumber);
                Device.ReadProduct(out product);


                gamepads[index - 1] = new Xiaomi_gamepad(Device, scpBus, index);
                ++index;

                if (index >= 5)
                {
                    break;
                }
            }

            //Console.WriteLine("{0} controllers connected", index - 1);
            textBox.AppendText(index - 1 + " controllers connected" + Environment.NewLine);

            connected_controllers = index - 1;
        }
Exemplo n.º 6
0
        public void UnplugAll()
        {
            // Reset all inputs
            foreach (var index in Program.KeyboardMapperInstance.MappedControllerIndexes)
            {
                Bus.Report(index + 1, new X360Controller().GetReport());
            }

            System.Threading.Thread.Sleep(250);
            Bus.UnplugAll();
            System.Threading.Thread.Sleep(250);
        }
Exemplo n.º 7
0
        private void unplugAll_Click(object sender, EventArgs e)
        {
            bool result = _scpBus.UnplugAll();

            status.Text = result.ToString();

            if (result)
            {
                _controller = new X360Controller();
                ResetControls();
            }
        }
Exemplo n.º 8
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            WindowState     = FormWindowState.Minimized;
            FormBorderStyle = FormBorderStyle.FixedToolWindow;
            ShowInTaskbar   = false;
//            Hide();

            var scpBus = new ScpBus();

            scpBus.UnplugAll();
            GlobalScpBus = scpBus;

            MappedDevices = new Dictionary <string, XiaomiGamepad>();

            var detectThread = new Thread(DetectDevices);

            detectThread.IsBackground = true;
            detectThread.Start();
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            ScpBus scpBus = new ScpBus();

            scpBus.UnplugAll();
            global_scpBus = scpBus;

            handler = new ConsoleEventDelegate(ConsoleEventCallback);
            SetConsoleCtrlHandler(handler, true);

            Thread.Sleep(400);

            Xiaomi_gamepad[] gamepads = new Xiaomi_gamepad[4];
            int index             = 1;
            var compatibleDevices = HidDevices.Enumerate(0x2717, 0x3144).ToList();

            foreach (var deviceInstance in compatibleDevices)
            {
                Console.WriteLine(deviceInstance);
                HidDevice Device = deviceInstance;
                Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                byte[] serialNumber;
                byte[] product;
                Device.ReadSerialNumber(out serialNumber);
                Device.ReadProduct(out product);


                gamepads[index - 1] = new Xiaomi_gamepad(Device, scpBus, index);
                ++index;

                if (index >= 5)
                {
                    break;
                }
            }

            Console.WriteLine("{0} controllers connected", index - 1);

            while (true)
            {
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 10
0
        public static void Run(BackgroundWorker bw)
        {
            ScpBus scpBus = new ScpBus();

            scpBus.UnplugAll();
            _globalScpBus = scpBus;

            _handler = ConsoleEventCallback;
            SetConsoleCtrlHandler(_handler, true);

            Thread.Sleep(400);

            XiaomiGamepad[] gamepads          = new XiaomiGamepad[4];
            int             index             = 1;
            var             compatibleDevices = HidDevices.Enumerate(0x2717, 0x3144).ToList();

            foreach (var deviceInstance in compatibleDevices)
            {
                Console.WriteLine(deviceInstance);
                HidDevice device = deviceInstance;
                try
                {
                    device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                }
                catch
                {
                    bw.ReportProgress(0, "Could not open gamepad in exclusive mode. Try re-enable device.");
                    var instanceId = DevicePathToInstanceId(deviceInstance.DevicePath);
                    if (TryReEnableDevice(instanceId))
                    {
                        try
                        {
                            device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                            bw.ReportProgress(0, "Opened in exclusive mode.");
                        }
                        catch
                        {
                            device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                            bw.ReportProgress(0, "Opened in shared mode.");
                        }
                    }
                    else
                    {
                        device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                        bw.ReportProgress(0, "Opened in shared mode.");
                    }
                }

                byte[] vibration = { 0x20, 0x00, 0x00 };
                if (device.WriteFeatureData(vibration) == false)
                {
                    bw.ReportProgress(0, "Could not write to gamepad (is it closed?), skipping");
                    device.CloseDevice();
                    continue;
                }

                device.ReadSerialNumber(out _);
                device.ReadProduct(out _);


                gamepads[index - 1] = new XiaomiGamepad(device, scpBus, index);
                ++index;

                if (index >= 5)
                {
                    break;
                }
            }
            bw.ReportProgress(0, $"{index - 1} controllers connected");

            while (!bw.CancellationPending)
            {
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            ScpBus scpBus = new ScpBus();

            scpBus.UnplugAll();
            global_scpBus = scpBus;

            handler = new ConsoleEventDelegate(ConsoleEventCallback);
            SetConsoleCtrlHandler(handler, true);

            Thread.Sleep(400);

            Xiaomi_gamepad[] gamepads = new Xiaomi_gamepad[4];
            int index = 1;

            string[] connectedDevices = new string[4];
            while (true)
            {
                var compatibleDevices = HidDevices.Enumerate(0x2717, 0x3144).ToList();
                foreach (var deviceInstance in compatibleDevices)
                {
                    if (index >= 5 || connectedDevices.Contains(deviceInstance.DevicePath))
                    {
                        continue;
                    }

                    HidDevice Device = deviceInstance;
                    try
                    {
                        Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                    }
                    catch
                    {
                        Console.WriteLine("Could not open gamepad in exclusive mode. Try re-enable device.");
                        var instanceId = devicePathToInstanceId(deviceInstance.DevicePath);
                        if (TryReEnableDevice(instanceId))
                        {
                            try
                            {
                                Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                                Console.WriteLine("Opened in exclusive mode.");
                            }
                            catch
                            {
                                Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                                Console.WriteLine("Opened in shared mode.");
                            }
                        }
                        else
                        {
                            Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                            Console.WriteLine("Opened in shared mode.");
                        }
                    }

                    byte[] Vibration = { 0x20, 0x00, 0x00 };
                    if (Device.WriteFeatureData(Vibration) == false)
                    {
                        Device.CloseDevice();
                        continue;
                    }

                    byte[] serialNumber;
                    byte[] product;
                    Device.ReadSerialNumber(out serialNumber);
                    Device.ReadProduct(out product);

                    gamepads[index - 1] = new Xiaomi_gamepad(Device, scpBus, index);
                    ++index;

                    Console.WriteLine(deviceInstance);
                    Console.WriteLine("Added new device.");
                    connectedDevices[index - 1] = deviceInstance.DevicePath;
                }

                Thread.Sleep(5000);
            }
        }
Exemplo n.º 12
0
        private static void Init()
        {
            ScpBus scpBus = new ScpBus();

            scpBus.UnplugAll();
            global_scpBus = scpBus;

            handler = new ConsoleEventDelegate(ConsoleEventCallback);
            SetConsoleCtrlHandler(handler, true);

            var compatibleDevices = HidDevices.Enumerate(0x79, 0x181c).ToList();

            Thread.Sleep(400);

            FuzeGamepad[] gamepads = new FuzeGamepad[4];
            int           index    = 1;

            //compatibleDevices.RemoveRange(1, compatibleDevices.Count - 1);
            foreach (var deviceInstance in compatibleDevices)
            {
                //Console.WriteLine(deviceInstance);
                HidDevice Device = deviceInstance;
                try
                {
                    Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                }
                catch
                {
                    Log.WriteLine("Could not open gamepad in exclusive mode. Try re-enable device.", Log.LogType.warning);
                    var instanceId = devicePathToInstanceId(deviceInstance.DevicePath);
                    if (TryReEnableDevice(instanceId))
                    {
                        try
                        {
                            Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                            Log.WriteLine("Opened in exclusive mode.");
                        }
                        catch
                        {
                            Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                            Log.WriteLine("Opened in shared mode.");
                        }
                    }
                    else
                    {
                        Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                        Log.WriteLine("Opened in shared mode.");
                    }
                }

                //byte[] Vibration = { 0x20, 0x00, 0x00 };
                //if (Device.WriteFeatureData(Vibration) == false)
                //{
                //    Console.WriteLine("Could not write to gamepad (is it closed?), skipping");
                //    Device.CloseDevice();
                //    continue;
                //}

                byte[] serialNumber;
                byte[] product;
                Device.ReadSerialNumber(out serialNumber);
                Device.ReadProduct(out product);


                gamepads[index - 1] = new FuzeGamepad(Device, scpBus, index);
                ++index;

                if (index >= 5)
                {
                    break;
                }
            }

            Log.WriteLine(string.Format("{0} controllers connected", index - 1));

            while (true)
            {
                Thread.Sleep(1000);
            }
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            string newInputEndpoint       = "http://127.0.0.1:5000/gbmode_input_request_bizhawk";
            string doneInputEndpoint      = "http://127.0.0.1:5000/gbmode_input_complete";
            int    controller             = 1;
            int    minHeldFrames          = 1;
            int    maxSleepFrames         = 100;
            int    maxHeldFrames          = 100;
            int    maxHoldFrames          = 0;    //24;
            bool   toggleTriggers         = false;
            bool   eternalHolds           = true; //false;
            string forceFocusProgram      = null;
            int    forceSaveBackupSeconds = 0;
            string saveBackupEndpoint     = "http://127.0.0.1:5000/back_up_savestate";

            try
            {
                for (var i = 0; i < args.Length; i++)
                {
                    switch (args[i].ToLower())
                    {
                    case "-h":
                    case "-help":
                        PrintHelpText();
                        return;

                    case "-inputendpoint":
                        newInputEndpoint = args[i + 1];
                        ConsoleLogger.Info($"Input endpoint: {newInputEndpoint}");
                        break;

                    case "-doneendpoint":
                        doneInputEndpoint = args[i + 1];
                        ConsoleLogger.Info($"Done endpoint: {doneInputEndpoint}");
                        break;

                    case "-savebackupendpoint":
                        saveBackupEndpoint = args[i + 1];
                        ConsoleLogger.Info($"Save Backup endpoint: {saveBackupEndpoint}");
                        break;

                    case "-controller":
                        controller = int.Parse(args[i + 1]);
                        ConsoleLogger.Info($"Simulating controller #{controller}");
                        break;

                    case "-lstickthrow":
                        TPPInput.LThrowGlobalMult = double.Parse(args[i + 1]);
                        ConsoleLogger.Info($"Left Stick max throw set to {(TPPInput.LThrowGlobalMult * 100).ToString("0")}%");
                        break;

                    case "-rstickthrow":
                        TPPInput.RThrowGlobalMult = double.Parse(args[i + 1]);
                        ConsoleLogger.Info($"Right Stick max throw set to {(TPPInput.RThrowGlobalMult * 100).ToString("0")}%");
                        break;

                    case "-toggletriggers":
                        toggleTriggers = true;
                        ConsoleLogger.Info("Left and Right Triggers will be toggled");
                        break;

                    case "-eternalholds":
                        eternalHolds  = true;
                        maxHoldFrames = 0;
                        ConsoleLogger.Info("Held inputs will last until the next held input");
                        break;

                    case "-minheldframes":
                        minHeldFrames = int.Parse(args[i + 1]);
                        ConsoleLogger.Info($"Minimum Held Frames: {minHeldFrames}");
                        break;

                    case "-maxsleepframes":
                        maxSleepFrames = int.Parse(args[i + 1]);
                        ConsoleLogger.Info($"Maximum Sleep Frames: {maxSleepFrames}");
                        break;

                    case "-maxheldframes":
                        maxHeldFrames = int.Parse(args[i + 1]);
                        ConsoleLogger.Info($"Maximum Held Frames: {maxHeldFrames}");
                        break;

                    case "-maxholdframes":
                        maxHoldFrames = int.Parse(args[i + 1]);
                        ConsoleLogger.Info($"Maximum Hold Input Frames: {maxHoldFrames}");
                        break;

                    case "-forcefocus":
                        forceFocusProgram = args[i + 1];
                        ConsoleLogger.Info($"Forcing {forceFocusProgram} to have focus for each input");
                        break;

                    case "-forcesavebackup":
                        forceSaveBackupSeconds = int.Parse(args[i + 1]);
                        ConsoleLogger.Info($"Forcing save backup every {forceSaveBackupSeconds} seconds");
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleLogger.Critical(e.Message);
                PrintHelpText();
                return;
            }

            ScpBus scpBus;

            try
            {
                scpBus = new ScpBus();
            }
            catch
            {
                ConsoleLogger.Critical("Could not create virtual controller. Please make sure the SCP Virtual Bus Driver is installed.");
                return;
            }

            scpBus.PlugIn(1);
            ConsoleLogger.Info("Virtual controller connected.");


            Console.CancelKeyPress += delegate {
                scpBus.UnplugAll();
                ConsoleLogger.Info("Virtual controller(s) disconnected.");
                scpBus.Dispose();
            };

            var inputFetcher = new FetchInput(scpBus, controller, minHeldFrames, maxHeldFrames, maxSleepFrames, maxHoldFrames, toggleTriggers, eternalHolds, newInputEndpoint, doneInputEndpoint, forceFocusProgram);

            var worker = new Worker(() => inputFetcher.Frame());

            worker.Start();

            var willBackupSave = forceSaveBackupSeconds > 0 && !string.IsNullOrWhiteSpace(saveBackupEndpoint);

            while (true)
            {
                for (var i = 0; i < forceSaveBackupSeconds; i += forceSaveBackupSeconds / 10)
                {
                    if (willBackupSave)
                    {
                        ConsoleLogger.Info($"{forceSaveBackupSeconds - i} seconds until save backup...");
                    }
                    Thread.Sleep(forceSaveBackupSeconds * 100);
                }
                if (willBackupSave)
                {
                    using (var webClient = new ImpatientWebClient(forceSaveBackupSeconds * 1000))
                    {
                        ConsoleLogger.Info("Backing up save...");
                        webClient.DownloadStringAsync(new Uri(saveBackupEndpoint));
                    }
                }
            }
        }
Exemplo n.º 14
0
 public static void DestroyAll()
 {
     scp.UnplugAll();
 }
Exemplo n.º 15
0
 private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     global_scpBus.UnplugAll();
 }
Exemplo n.º 16
0
        public MainForm()
        {
            InitializeComponent();
            ScpBus scpBus = new ScpBus();

            scpBus.UnplugAll();
            global_scpBus = scpBus;

            Thread.Sleep(400);

            Xiaomi_gamepad[] gamepads = new Xiaomi_gamepad[4];
            int index             = 1;
            var compatibleDevices = HidDevices.Enumerate(0x2717, 0x3144).ToList();

            foreach (var deviceInstance in compatibleDevices)
            {
                Log(deviceInstance.ToString());
                HidDevice Device = deviceInstance;
                try
                {
                    Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                }
                catch
                {
                    Log("Could not open gamepad in exclusive mode. Try re-enable device.");
                    var instanceId = devicePathToInstanceId(deviceInstance.DevicePath);
                    if (TryReEnableDevice(instanceId))
                    {
                        try
                        {
                            Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.Exclusive);
                            Log("Opened in exclusive mode.");
                        }
                        catch
                        {
                            Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                            Log("Opened in shared mode.");
                        }
                    }
                    else
                    {
                        Device.OpenDevice(DeviceMode.Overlapped, DeviceMode.Overlapped, ShareMode.ShareRead | ShareMode.ShareWrite);
                        Log("Opened in shared mode.");
                    }
                }

                byte[] Vibration = { 0x20, 0x00, 0x00 };
                if (Device.WriteFeatureData(Vibration) == false)
                {
                    Log("Could not write to gamepad (is it closed?), skipping");
                    Device.CloseDevice();
                    continue;
                }

                byte[] serialNumber;
                byte[] product;
                Device.ReadSerialNumber(out serialNumber);
                Device.ReadProduct(out product);


                gamepads[index - 1] = new Xiaomi_gamepad(Device, scpBus, index);
                ++index;

                if (index >= 5)
                {
                    break;
                }
            }
            Log(index - 1 + " controllers connected");
        }
Exemplo n.º 17
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     global_scpBus.UnplugAll();
     notifyIcon.Dispose();
     Environment.Exit(0);
 }