示例#1
0
        public VirtualError DisableFeeding(uint userIndex)
        {
            bool success;

            if (userIndex < 1 || userIndex > 4)
            {
                return(VirtualError.Index);
            }
            if (!ViGEmClient.isVBusExists())
            {
                return(VirtualError.Missing);
            }
            if (!ViGEmClient.isControllerExists(userIndex))
            {
                return(VirtualError.None);
            }
            if (ViGEmClient.IsControllerOwned(userIndex))
            {
                success = ViGEmClient.UnPlug(userIndex);
                if (success)
                {
                    return(VirtualError.None);
                }
            }
            else
            {
                success = ViGEmClient.UnPlugForce(userIndex);
                if (success)
                {
                    return(VirtualError.None);
                }
            }
            return(VirtualError.Other);
        }
示例#2
0
        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;
            }
            var isVirtual = ((EmulationType)game.EmulationType).HasFlag(EmulationType.Virtual);

            // If game does not use virtual emulation then...
            if (!isVirtual)
            {
                // Make sure all controllers are unplugged.
                ViGEmClient.UnplugAllControllers();
                return;
            }
            // If virtual driver is missing then return.
            if (!ViGEmClient.isVBusExists())
            {
                return;
            }
            if (ViGEmClient.Targets == null)
            {
                ViGEmClient.Targets = new Xbox360Controller[4];
                for (int i = 0; i < 4; i++)
                {
                    var controller = new Xbox360Controller(ViGEmClient.Client);
                    ViGEmClient.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;
                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 || !ViGEmClient.IsControllerOwned(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 || ViGEmClient.IsControllerOwned(i))
                    {
                        var success = DisableFeeding(i) == VirtualError.None;
                        if (!success)
                        {
                            return;
                        }
                        FeedingState[i - 1] = false;
                    }
                }
            }
        }