diff --git a/src/cardreader_plugin/dllmain.c b/src/cardreader_plugin/dllmain.c index 0e9b623..bd7579f 100644 --- a/src/cardreader_plugin/dllmain.c +++ b/src/cardreader_plugin/dllmain.c @@ -25,53 +25,55 @@ static unsigned int __stdcall reader_poll_thread_proc(void *ctx) if (HasCard && !usingSmartCard) // A Cardio scan is already in progress, SmartCard doesn't need any extra cooldown. { Sleep(500); - return 0; } - - uint8_t UID[8] = {0}; - - // update devices - if (!usingSmartCard) // CardIO + else { - EnterCriticalSection(&CARDIO_HID_CRIT_SECTION); - for (size_t device_no = 0; device_no < CARDIO_HID_CONTEXTS_LENGTH; device_no++) + + uint8_t UID[8] = {0}; + + // update devices + if (!usingSmartCard) // CardIO { - struct cardio_hid_device *device = &CARDIO_HID_CONTEXTS[device_no]; - - // get status - cardio_hid_poll_value_t status = cardio_hid_device_poll(device); - if (status == HID_POLL_CARD_READY) + EnterCriticalSection(&CARDIO_HID_CRIT_SECTION); + for (size_t device_no = 0; device_no < CARDIO_HID_CONTEXTS_LENGTH; device_no++) { + struct cardio_hid_device *device = &CARDIO_HID_CONTEXTS[device_no]; - // read card - if (cardio_hid_device_read(device) == HID_CARD_NONE) - continue; + // get status + cardio_hid_poll_value_t status = cardio_hid_device_poll(device); + if (status == HID_POLL_CARD_READY) + { - // if card not empty - if (*((uint64_t *)&device->u.usage_value[0]) > 0) - for (int i = 0; i < 8; ++i) - UID[i] = device->u.usage_value[i]; + // read card + if (cardio_hid_device_read(device) == HID_CARD_NONE) + continue; + + // if card not empty + if (*((uint64_t *)&device->u.usage_value[0]) > 0) + for (int i = 0; i < 8; ++i) + UID[i] = device->u.usage_value[i]; + } } + LeaveCriticalSection(&CARDIO_HID_CRIT_SECTION); + Sleep(readCooldown); + } + else // SmartCard + { + scard_update(UID); } - LeaveCriticalSection(&CARDIO_HID_CRIT_SECTION); - Sleep(readCooldown); - } - else // SmartCard - { - scard_update(UID); - } - if (UID[0] > 0) // If a card was read, format it properly and set HasCard to true so the game can insert it on next frame. - { - printWarning("%s (%s): Read card %02X%02X%02X%02X%02X%02X%02X%02X\n", __func__, module, UID[0], UID[1], UID[2], UID[3], UID[4], UID[5], UID[6], UID[7]); + if (UID[0] > 0) // If a card was read, format it properly and set HasCard to true so the game can insert it on next frame. + { + printWarning("%s (%s): Read card %02X%02X%02X%02X%02X%02X%02X%02X\n", __func__, module, UID[0], UID[1], UID[2], UID[3], UID[4], UID[5], UID[6], UID[7]); - // Properly format the AccessID - u64 ReversedAccessID; - for (int i = 0; i < 8; i++) - ReversedAccessID = (ReversedAccessID << 8) | UID[i]; - sprintf(AccessID, "%020llu", ReversedAccessID); + // Properly format the AccessID + u64 ReversedAccessID; + for (int i = 0; i < 8; i++) + ReversedAccessID = (ReversedAccessID << 8) | UID[i]; + sprintf(AccessID, "%020llu", ReversedAccessID); - HasCard = true; + HasCard = true; + } } }