Пример #1
0
        public XboxTestSlot(XinputController xinputController)
        {
            this.InitializeComponent();
            if (xinputController == null)
            {
                throw new ArgumentNullException("xinputController");
            }

            if (!xinputController.IsConnected)
            {
                this.Content = new TextBlock()
                {
                    Text              = string.Format("Xinput controller #{0} disconnected", xinputController.LedNumber),
                    TextAlignment     = TextAlignment.Center,
                    VerticalAlignment = System.Windows.VerticalAlignment.Center,
                    Foreground        = Brushes.Red
                };

                return;
            }

            this.XinputController = xinputController;
            this.XinputController.StateChanged += this.OnXinputControllerStateChanged;
            var  subType   = this.XinputController.GetControllerSubType();
            bool isVirtual = this.XinputController.Tag != null;
            bool isGamepad = this.XinputController.IsGamepad == true;
            bool isWired   = this.XinputController.IsWired == true;

            if (isVirtual)
            {
                var gamepad = this.XinputController.Tag as XboxGamepad;
                if (gamepad == null)
                {
                    this.descriptionTextBlock.Text = "Unknown virtual controller";
                    return;
                }

                this.connectionTimeTextBlock.Text = string.Format(
                    "Connection time: {0} ms", (int)gamepad.ConnectionTime.TotalMilliseconds);
            }
            else
            {
                if (VirtualXboxController.Exists(this.XinputController.LedNumber) &&
                    !VirtualXboxController.IsOwned(this.XinputController.LedNumber))
                {
                    this.descriptionTextBlock.Text = "Virtual controller is owned in another process.";
                    return;
                }
            }

            string prefix = isVirtual ? "Virtual" : isWired ? "Wired" : "Wireless";
            string suffix = isGamepad ? subType.ToString() : "Headset";

            this.descriptionTextBlock.Text = string.Format(
                "{0} {1} {2} [Led #{3}]",
                prefix,
                "Xbox 360",
                suffix,
                this.XinputController.LedNumber);
        }
        public void Stop()
        {
            foreach (var slot in this.Slots)
            {
                slot.Gamepad.Disconnected -= this.OnGamepadDisconnected;
                if (slot.Gamepad.LedNumber != 0)
                {
                    XinputController.RetrieveController((int)slot.Gamepad.LedNumber - 1).Tag = null;
                    slot.Gamepad.LedNumber = 0;
                }

                slot.Unlock();
                if (slot.Gamepad.IsOwned)
                {
                    if (slot.Gamepad.Unplug(true))
                    {
                        LogWriter.Write(string.Format("Successfully unplugged {0}", slot.Gamepad.FriendlyName));
                    }
                    else
                    {
                        LogWriter.Write(string.Format("Unplug failed: {0}", slot.Gamepad.FriendlyName));
                    }
                }

                this.lastStartOrStopTime = DateTime.Now;
            }

            LogWriter.Write("Emulation stopped");

            this.IsEmulationStarted = false;
            if (this.EmulationStopped != null)
            {
                this.EmulationStopped(this, EventArgs.Empty);
            }
        }
Пример #3
0
        private void OnXinputControllerPluggedChanged(object sender, EventArgs e)
        {
            var controller = sender as XinputController;

            if (controller == null || controller != this.xinputController)
            {
                return;
            }

            this.Dispatcher.BeginInvoke((Action) delegate
            {
                if (controller.IsConnected)
                {
                    this.LedNumber        = controller.LedNumber;
                    controller.Tag        = this;
                    this.xinputController = controller;
                    this.ConnectionTime   = DateTime.Now - this.connectionRequestTime;
                }
                else
                {
                    this.OnDisconnected();
                    this.LedNumber             = 0;
                    controller.Tag             = null;
                    controller.PluggedChanged -= this.OnXinputControllerPluggedChanged;
                    this.xinputController      = null;
                }
            });
        }
Пример #4
0
    /* le nombre de la lib ControllerManager */

    /*
     *    override public int countConnected(){
     * Controller360[] controls = getControllers();
     *            int count = 0;
     * for(int i = 0; i < controls.Length; i++){
     *  XinputController c = (XinputController)controls[i];
     *                    if(c == null)	continue;
     *                    if(c.isConnected())	count++;
     *            }
     *            return count;
     *    }
     */

    public XinputController createXinput(int index)
    {
        XinputController controller = XinputController.add(index);

        //GamePadState state = GamePad.GetState((PlayerIndex)index);
        return(controller);
    }
Пример #5
0
    public XinputController getControllerByXinputId(int id)
    {
        //Debug.Log("getting xinput controller of id "+id);

        for (int i = 0; i < tempControllers.Length; i++)
        {
            if (tempControllers[i] == null)
            {
                //Debug.Log("listTempController (len:"+list.Count+") index:"+i+" is null");
                continue;
            }

            XinputController c = (XinputController)tempControllers[i];
            if (c == null)
            {
                //Debug.Log("controller "+i+" is null");
                continue;
            }

            //Debug.Log("checking for xinput controller with id "+id+", this one is "+c.getXinputIndex());
            if (c.getXinputIndex() == id)
            {
                //Debug.Log("found xinput of id "+c.getXinputIndex());
                return(c);
            }
        }
        return(null);
    }
Пример #6
0
        private void OnTimerTick(object sender, EventArgs e)
        {
            this.timer.Stop();
            this.SizeToContent = SizeToContent.Manual;
            this.panel.Children.Clear();
            for (int i = 0; i < 4; i++)
            {
                var xinputController = XinputController.RetrieveController(i);
                xinputController.PluggedChanged += this.OnXinputControllerPluggedChanged;
                if (xinputController.IsConnected)
                {
                    var slot = new XboxTestSlot(xinputController);
                    this.panel.Children.Add(slot);
                }
            }

            this.SizeToContent    = SizeToContent.WidthAndHeight;
            this.button.IsEnabled = true;
            this.Cursor           = Cursors.Arrow;
        }
        public void Start(bool forced = false)
        {
            if (!forced)
            {
                if (this.lastStartOrStopTime == null)
                {
                    this.lastStartOrStopTime = DateTime.Now;
                }
                else
                {
                    if (DateTime.Now - this.lastStartOrStopTime < TimeSpan.FromSeconds(5))
                    {
                        throw new KeyboardSplitterExceptionBase("You should wait at least 5 seconds, between each emulation start/stop!");
                    }
                }

                this.lastStartOrStopTime = DateTime.Now;
            }

            try
            {
                this.CheckForInvalidatedSlots();
                this.CheckXinputBus();
            }
            catch (Exception)
            {
                throw;
            }

            // Releasing xinput controller tags
            for (int i = 0; i < 4; i++)
            {
                XinputController.RetrieveController(i).Tag = null;
            }

            // Plugging in the virtual controllers
            foreach (var slot in this.Slots)
            {
                if (slot.Keyboard == null && slot.Mouse == null)
                {
                    slot.InvalidateReason = SlotInvalidationReason.No_Input_Device_Selected;
                    throw new SlotInvalidatedException(string.Format("Slot #{0} has no valid input device selected", slot.SlotNumber));
                }

                string errorMessage = string.Format("Plug in {0} failed!", slot.Gamepad.FriendlyName);
                bool   success      = false;
                try
                {
                    success = slot.Gamepad.PlugIn();
                }
                catch (VirtualBusNotInstalledException)
                {
                    slot.InvalidateReason = SlotInvalidationReason.VirtualBus_Not_Installed;
                    errorMessage         += " " + slot.InvalidateReason.ToString();
                    LogWriter.Write(errorMessage);
                    throw;
                }
                catch (XboxAccessoriesNotInstalledException)
                {
                    slot.InvalidateReason = SlotInvalidationReason.Additional_Drivers_Not_Installed;
                    errorMessage         += " " + slot.InvalidateReason.ToString();
                    LogWriter.Write(errorMessage);
                    throw;
                }
                catch (VirtualBusFullException)
                {
                    slot.InvalidateReason = SlotInvalidationReason.VirtualBus_Full;
                    errorMessage         += " " + slot.InvalidateReason.ToString();
                    LogWriter.Write(errorMessage);
                    throw;
                }
                catch (GamepadIsInUseException)
                {
                    slot.InvalidateReason = SlotInvalidationReason.Controller_Already_Plugged_In;
                    errorMessage         += " " + slot.InvalidateReason.ToString();
                    LogWriter.Write(errorMessage);
                    throw;
                }
                catch (GamepadOwnedException)
                {
                    slot.InvalidateReason = SlotInvalidationReason.Controller_In_Use;
                    errorMessage         += " " + slot.InvalidateReason.ToString();
                    LogWriter.Write(errorMessage);
                    throw;
                }
                catch (XinputSlotsFullException)
                {
                    slot.InvalidateReason = SlotInvalidationReason.XinputBus_Full;
                    errorMessage         += " " + slot.InvalidateReason.ToString();
                    LogWriter.Write(errorMessage);
                    throw;
                }

                if (success)
                {
                    slot.Lock();
                    LogWriter.Write(string.Format(
                                        "Plug in {0} - OK | User Index: {1} | {2} | {3} | Slot #{4}",
                                        slot.Gamepad.FriendlyName,
                                        slot.Gamepad.UserIndex,
                                        slot.Keyboard.StrongName,
                                        slot.Mouse.StrongName,
                                        slot.SlotNumber));

                    slot.Gamepad.Disconnected += this.OnGamepadDisconnected;
                }
                else
                {
                    slot.InvalidateReason = SlotInvalidationReason.Controller_Plug_In_Failed;
                    LogWriter.Write(string.Format("Plug in {0} - Failed!", slot.Gamepad.FriendlyName));

                    // Releasing xinput controller tags
                    for (int i = 0; i < 4; i++)
                    {
                        XinputController.RetrieveController(i).Tag = null;
                    }

                    return;
                }
            }

            LogWriter.Write(string.Format("Emulation started. Slots count: {0}", this.Slots.Count));

            this.IsEmulationStarted = true;

            if (this.EmulationStarted != null)
            {
                this.EmulationStarted(this, EventArgs.Empty);
            }
        }
Пример #8
0
        /// <summary>
        /// Plugs the xbox controller into the virtual bus.
        /// </summary>
        /// <returns>Returns true if the process is successfull</returns>
        /// <exception cref="XboxAccessoriesNotInstalledException">XboxAccessoriesNotInstalledException</exception>
        /// <exception cref="VirtualBusNotInstalledException">VirtualBusNotInstalledException</exception>
        /// <exception cref="GamepadIsInUseException">GamepadIsInUseException</exception>
        /// <exception cref="GamepadOwnedException">GamepadOwnedException</exception>
        public bool PlugIn()
        {
            try
            {
                this.CheckDrivers();
            }
            catch (Exception)
            {
                throw;
            }

            if (VirtualXboxBus.EmptySlotsCount == 0)
            {
                throw new VirtualBusFullException("There is no free slot in the virtual bus");
            }

            if (this.Exsists)
            {
                throw new GamepadIsInUseException(this.FriendlyName + " is already mounted!");
            }

            var xinputControllers = new System.Collections.Generic.List <XinputController>();

            for (int i = 0; i < 4; i++)
            {
                xinputControllers.Add(XinputController.RetrieveController(i));
            }

            if (xinputControllers.TrueForAll(x => x.Tag != null))
            {
                throw new KeyboardSplitterExceptionBase("Internal Error: all xinput controllers are marked as virtual!");
            }

            this.xinputController = xinputControllers.FirstOrDefault(x => !x.IsConnected && x.Tag == null);
            if (this.xinputController != null)
            {
                this.xinputController.Tag             = this;
                this.xinputController.PluggedChanged += this.OnXinputControllerPluggedChanged;
            }
            else
            {
                LogWriter.Write("--- Xinput controllers information ---");
                foreach (var xinputController in xinputControllers)
                {
                    LogWriter.Write(
                        string.Format(
                            "Controller #{0} [IsConnected:{1}] [IsVirtual:{2}]",
                            xinputController.LedNumber,
                            xinputController.IsConnected,
                            xinputController.Tag != null));
                }

                LogWriter.Write("--- End of Xinput controllers information---");

                throw new InvalidOperationException("Unknown error occured, just before plugging in the virtual controller!");
            }

            this.connectionRequestTime = DateTime.Now;
            if (!VirtualXboxController.PlugIn(this.UserIndex))
            {
                this.LedNumber                        = 0;
                this.xinputController.Tag             = null;
                this.xinputController.PluggedChanged -= this.OnXinputControllerPluggedChanged;
                this.xinputController                 = null;
                return(false);
            }

            return(true);
        }