protected override void OnHidReportReceived()

in ScpControl/RootHub.cs [560:622]


        protected override void OnHidReportReceived(object sender, ScpHidReport e)
        {
            // get current pad ID
            var serial = (int)e.PadId;

            if (GlobalConfiguration.Instance.ProfilesEnabled)
            {
                // pass current report through user profiles
                DualShockProfileManager.Instance.PassThroughAllProfiles(e);
            }

            if (e.PadState == DsState.Connected)
            {
                // translate current report to Xbox format and send it to bus device
                XOutputWrapper.Instance.SetState((uint) serial, _scpBus.Parse(e));
                
                // set currently assigned XInput slot
                Pads[serial].XInputSlot = XOutputWrapper.Instance.GetRealIndex((uint) serial);

                byte largeMotor = 0;
                byte smallMotor = 0;

                // forward rumble request to pad
                if (XOutputWrapper.Instance.GetState((uint) serial, ref largeMotor, ref smallMotor) 
                    && (largeMotor != _vibration[serial][0] || smallMotor != _vibration[serial][1]))
                {
                    _vibration[serial][0] = largeMotor;
                    _vibration[serial][1] = smallMotor;

                    Pads[serial].Rumble(largeMotor, smallMotor);
                }
            }
            else
            {
                // reset rumble/vibration to off state
                _vibration[serial][0] = _vibration[serial][1] = 0;
                _mNative[serial][0] = _mNative[serial][1] = 0;

                if (GlobalConfiguration.Instance.AlwaysUnPlugVirtualBusDevice)
                {
                    _scpBus.Unplug(_scpBus.IndexToSerial((byte)e.PadId));
                }
            }

            // skip broadcast if native feed is disabled
            if (GlobalConfiguration.Instance.DisableNative)
                return;

            // send native controller inputs to subscribed clients
            foreach (
                var channel in _nativeFeedSubscribers.Select(nativeFeedSubscriber => nativeFeedSubscriber.Value))
            {
                try
                {
                    channel.SendAsync(e.RawBytes);
                }
                catch (AggregateException)
                {
                    /* This might happen if the client disconnects while sending the 
                     * response is still in progress. The exception can be ignored. */
                }
            }
        }