IOReturn XboxOneControllerClass::handleReport(IOMemoryDescriptor * descriptor, IOHIDReportType reportType, IOOptionBits options)
{
    if (descriptor->getLength() >= sizeof(XBOXONE_IN_GUIDE_REPORT)) {
        IOBufferMemoryDescriptor *desc = OSDynamicCast(IOBufferMemoryDescriptor, descriptor);
        if (desc != NULL) {
            XBOXONE_ELITE_IN_REPORT *report=(XBOXONE_ELITE_IN_REPORT*)desc->getBytesNoCopy();
            if ((report->header.command==0x07) && (report->header.size==(sizeof(XBOXONE_IN_GUIDE_REPORT)-4)))
            {
                XBOXONE_IN_GUIDE_REPORT *guideReport=(XBOXONE_IN_GUIDE_REPORT*)report;
                isXboxOneGuideButtonPressed = (bool)guideReport->state;
                XBOX360_IN_REPORT *oldReport = (XBOX360_IN_REPORT*)lastData;
                oldReport->buttons ^= (-isXboxOneGuideButtonPressed ^ oldReport->buttons) & (1 << GetOwner(this)->mapping[10]);
                memcpy(report, lastData, sizeof(XBOX360_IN_REPORT));
            }
            else if (report->header.command==0x20)
            {
                if (report->header.size==0x0e || report->header.size==0x1d || report->header.size==0x1a)
                {
                    convertFromXboxOne(report, report->header.size);
                    XBOX360_IN_REPORT *report360=(XBOX360_IN_REPORT*)report;
                    if (!(GetOwner(this)->noMapping))
                        remapButtons(report360);
                    GetOwner(this)->fiddleReport(report360->left, report360->right);

                    if (GetOwner(this)->swapSticks)
                        remapAxes(report360);

                    memcpy(lastData, report360, sizeof(XBOX360_IN_REPORT));
                }
            }
        }
    }
    IOReturn ret = IOHIDDevice::handleReport(descriptor, reportType, options);
    return ret;
}
void Wireless360Controller::receivedHIDupdate(unsigned char *data, int length)
{
    fiddleReport(data, length);
    if (!noMapping)
        remapButtons(data);
    if (swapSticks)
        remapAxes(data);
    super::receivedHIDupdate(data, length);
}
IOReturn Xbox360ControllerClass::handleReport(IOMemoryDescriptor * descriptor, IOHIDReportType reportType, IOOptionBits options) {
    if (descriptor->getLength() >= sizeof(XBOX360_IN_REPORT)) {
        IOBufferMemoryDescriptor *desc = OSDynamicCast(IOBufferMemoryDescriptor, descriptor);
        if (desc != NULL) {
            XBOX360_IN_REPORT *report=(XBOX360_IN_REPORT*)desc->getBytesNoCopy();
            if ((report->header.command==inReport) && (report->header.size==sizeof(XBOX360_IN_REPORT))) {
                GetOwner(this)->fiddleReport(desc);
                remapButtons(report);
            }
        }
    }
    IOReturn ret = IOHIDDevice::handleReport(descriptor, reportType, options);
    return ret;
}