diff --git a/src/cardio_plugin/cardio.h b/src/cardio_plugin/cardio.h index d2d96c0..c333da8 100644 --- a/src/cardio_plugin/cardio.h +++ b/src/cardio_plugin/cardio.h @@ -30,12 +30,12 @@ #include #include - extern CRITICAL_SECTION CARDIO_HID_CRIT_SECTION; extern struct cardio_hid_device *CARDIO_HID_CONTEXTS; extern size_t CARDIO_HID_CONTEXTS_LENGTH; -struct cardio_hid_device { +struct cardio_hid_device +{ LPWSTR dev_path; HANDLE dev_handle; OVERLAPPED read_state; @@ -43,9 +43,9 @@ struct cardio_hid_device { BOOL io_pending; BYTE report_buffer[128]; - union { + union + { unsigned char usage_value[128]; - uint64_t usage64[8]; } u; DWORD read_size; @@ -55,13 +55,15 @@ struct cardio_hid_device { USHORT collection_length; }; -typedef enum cardio_poll_value { +typedef enum cardio_poll_value +{ HID_POLL_ERROR = 0, HID_POLL_CARD_NOT_READY = 1, HID_POLL_CARD_READY = 2, } cardio_hid_poll_value_t; -typedef enum cardio_hid_card_type { +typedef enum cardio_hid_card_type +{ HID_CARD_NONE = 0, HID_CARD_ISO_15693 = 0x41, HID_CARD_ISO_18092 = 0x42, @@ -83,4 +85,4 @@ cardio_hid_poll_value_t cardio_hid_device_poll(struct cardio_hid_device *ctx); cardio_hid_card_type_t cardio_hid_device_read(struct cardio_hid_device *ctx); -#endif //SPICETOOLS_CARDIO_HID_H \ No newline at end of file +#endif // SPICETOOLS_CARDIO_HID_H \ No newline at end of file diff --git a/src/cardio_plugin/dllmain.c b/src/cardio_plugin/dllmain.c index f30e773..96052e4 100644 --- a/src/cardio_plugin/dllmain.c +++ b/src/cardio_plugin/dllmain.c @@ -11,7 +11,7 @@ static bool HasCard = false; typedef void (*callbackTouch)(i32, i32, u8[168], u64); callbackTouch touchCallback; u64 touchData; -static char AccessID[21] = "00000000000000000001"; +char AccessID[21] = "00000000000000000001"; static u8 cardData[168] = {0x01, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x92, 0x2E, 0x58, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x5C, 0x97, 0x44, 0xF0, 0x88, 0x04, 0x00, 0x43, 0x26, 0x2C, 0x33, 0x00, 0x04, 0x06, 0x10, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, @@ -23,6 +23,12 @@ static u8 cardData[168] = {0x01, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, void PollReader() { + if (HasCard) // A card scan is already in progress + { + Sleep(1000); + return; + } + // update HID devices EnterCriticalSection(&CARDIO_HID_CRIT_SECTION); for (size_t device_no = 0; device_no < CARDIO_HID_CONTEXTS_LENGTH; device_no++) @@ -45,10 +51,11 @@ void PollReader() if (waitingForTouch) { - // Convert card to proper format - sprintf(AccessID, "%020llu", device->u.usage64[0]); - // Format the AccessID in a way that doesn't crash the game. - // memset(AccessID, '0', 10); + // Properly format the AccessID + u64 ReversedAccessID; + for (int i = 0; i < 8; i++) + ReversedAccessID = (ReversedAccessID << 8) | device->u.usage_value[i]; + sprintf(AccessID, "%020llu", ReversedAccessID); HasCard = true; }