mirror of
https://github.com/AkaiiKitsune/TAL_CardReader
synced 2024-11-24 01:20:10 +01:00
Moving Card Insert event to Update()
This commit is contained in:
parent
c047663c90
commit
824cf5efce
@ -2,5 +2,6 @@ LIBRARY cardio
|
||||
|
||||
EXPORTS
|
||||
Init
|
||||
Update
|
||||
WaitTouch
|
||||
Exit
|
@ -6,34 +6,13 @@ static bool CARDIO_RUNNER_INITIALIZED = false;
|
||||
static HANDLE CARDIO_POLL_THREAD;
|
||||
static bool CARDIO_POLL_STOP_FLAG;
|
||||
static bool waitingForTouch = false;
|
||||
static bool HasCard = false;
|
||||
|
||||
typedef void (*callbackTouch)(i32, i32, u8[168], u64);
|
||||
callbackTouch touchCallback;
|
||||
u64 touchData;
|
||||
static char AccessID[21] = "00000000000000000001";
|
||||
// static char ChipID[33] = "00000000000000000000000000000001";
|
||||
|
||||
void PollReader(){
|
||||
// update HID devices
|
||||
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];
|
||||
|
||||
// get status
|
||||
cardio_hid_poll_value_t status = cardio_hid_device_poll(device);
|
||||
if (status == HID_POLL_CARD_READY) {
|
||||
|
||||
// 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) {
|
||||
printWarning ("%s (%s): Read card %02X%02X%02X%02X%02X%02X%02X%02X\n", __func__, module, device->u.usage_value[0], device->u.usage_value[1], device->u.usage_value[2], device->u.usage_value[3], device->u.usage_value[4], device->u.usage_value[5], device->u.usage_value[6], device->u.usage_value[7]);
|
||||
|
||||
if(waitingForTouch){
|
||||
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,
|
||||
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,
|
||||
0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x30, 0x30,
|
||||
@ -42,62 +21,79 @@ void PollReader(){
|
||||
0x00, 0x00, 0xFA, 0xE9, 0x69, 0x00, 0xF6, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
void PollReader()
|
||||
{
|
||||
// update HID devices
|
||||
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];
|
||||
|
||||
// get status
|
||||
cardio_hid_poll_value_t status = cardio_hid_device_poll(device);
|
||||
if (status == HID_POLL_CARD_READY)
|
||||
{
|
||||
|
||||
// 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)
|
||||
{
|
||||
printWarning("%s (%s): Read card %02X%02X%02X%02X%02X%02X%02X%02X\n", __func__, module, device->u.usage_value[0], device->u.usage_value[1], device->u.usage_value[2], device->u.usage_value[3], device->u.usage_value[4], device->u.usage_value[5], device->u.usage_value[6], device->u.usage_value[7]);
|
||||
|
||||
if (waitingForTouch)
|
||||
{
|
||||
// Convert card to proper format
|
||||
sprintf(AccessID, "%020llu", device->u.usage64[0]);
|
||||
LeaveCriticalSection(&CARDIO_HID_CRIT_SECTION);
|
||||
memset(AccessID, '0', 10);
|
||||
// Format the AccessID in a way that doesn't crash the game.
|
||||
// memset(AccessID, '0', 10);
|
||||
|
||||
//Generating a ChipID Derived from the AccessID
|
||||
char ChipID[33] = "000000000000";
|
||||
strcat(ChipID, AccessID);
|
||||
memset(ChipID, '0', 25);
|
||||
|
||||
//Insert card in game
|
||||
printWarning ("%s (%s): AccessID %s, ChipID %s\n", __func__, module, AccessID, ChipID);
|
||||
memcpy (cardData + 0x2C, ChipID, 33);
|
||||
memcpy (cardData + 0x50, AccessID, 21);
|
||||
touchCallback(0, 0, cardData, touchData);
|
||||
}else{
|
||||
HasCard = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LeaveCriticalSection(&CARDIO_HID_CRIT_SECTION);
|
||||
}
|
||||
}else{
|
||||
LeaveCriticalSection(&CARDIO_HID_CRIT_SECTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
Sleep(500);
|
||||
Sleep(15);
|
||||
}
|
||||
|
||||
static unsigned int __stdcall cardio_poll_thread_proc(void *ctx)
|
||||
{
|
||||
while (!CARDIO_POLL_STOP_FLAG) {
|
||||
while (!CARDIO_POLL_STOP_FLAG)
|
||||
{
|
||||
PollReader();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cardio_runner_start() {
|
||||
void cardio_runner_start()
|
||||
{
|
||||
// initialize
|
||||
if (!CARDIO_RUNNER_INITIALIZED) {
|
||||
if (!CARDIO_RUNNER_INITIALIZED)
|
||||
{
|
||||
CARDIO_RUNNER_INITIALIZED = true;
|
||||
printWarning("%s (%s): Initializing CARDIO\n", __func__, module);
|
||||
|
||||
// initialize
|
||||
if (!cardio_hid_init()) {
|
||||
if (!cardio_hid_init())
|
||||
{
|
||||
printWarning("%s (%s): Couldn't init CARDIO HID\n", __func__, module);
|
||||
return;
|
||||
}
|
||||
|
||||
// scan HID devices
|
||||
if (!cardio_hid_scan()) {
|
||||
if (!cardio_hid_scan())
|
||||
{
|
||||
printWarning("%s (%s): Couldn't scan for CARDIO devices\n", __func__, module);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void cardio_runner_stop() {
|
||||
void cardio_runner_stop()
|
||||
{
|
||||
// shutdown HID
|
||||
cardio_hid_close();
|
||||
|
||||
@ -105,7 +101,8 @@ void cardio_runner_stop() {
|
||||
CARDIO_RUNNER_INITIALIZED = false;
|
||||
}
|
||||
|
||||
void Init(){
|
||||
void Init()
|
||||
{
|
||||
printWarning("%s (%s): Starting HID Service...\n", __func__, module);
|
||||
// Find and initialize reader(s)
|
||||
cardio_runner_start();
|
||||
@ -121,14 +118,34 @@ void Init(){
|
||||
NULL);
|
||||
}
|
||||
|
||||
void WaitTouch(i32 (*callback) (i32, i32, u8[168], u64), u64 data){
|
||||
void Update()
|
||||
{
|
||||
if (HasCard)
|
||||
{
|
||||
HasCard = false;
|
||||
|
||||
// Generating a ChipID Derived from the AccessID
|
||||
char ChipID[33] = "000000000000";
|
||||
strcat(ChipID, AccessID);
|
||||
|
||||
// Insert card in game
|
||||
printWarning("%s (%s): Inserting Card %s, with ChipID %s\n", __func__, module, AccessID, ChipID);
|
||||
memcpy(cardData + 0x2C, ChipID, 33);
|
||||
memcpy(cardData + 0x50, AccessID, 21);
|
||||
touchCallback(0, 0, cardData, touchData);
|
||||
}
|
||||
}
|
||||
|
||||
void WaitTouch(i32 (*callback)(i32, i32, u8[168], u64), u64 data)
|
||||
{
|
||||
printWarning("%s (%s): Waiting for touch\n", __func__, module);
|
||||
waitingForTouch = true;
|
||||
touchCallback = callback;
|
||||
touchData = data;
|
||||
}
|
||||
|
||||
void Exit(){
|
||||
void Exit()
|
||||
{
|
||||
cardio_runner_stop();
|
||||
CARDIO_POLL_STOP_FLAG = true;
|
||||
WaitForSingleObject(CARDIO_POLL_THREAD, INFINITE);
|
||||
|
Loading…
Reference in New Issue
Block a user