support for MultiQrCode Accounts
This commit is contained in:
parent
ced6fc6e92
commit
dfa36bf030
10
dist/keyconfig.toml
vendored
10
dist/keyconfig.toml
vendored
@ -21,6 +21,16 @@ P2_LEFT_RED = []
|
||||
P2_RIGHT_RED = []
|
||||
P2_RIGHT_BLUE = []
|
||||
|
||||
# For First User's QRCode
|
||||
[[QRCODE_CARD]]
|
||||
READ_KEY = ["Q"] # Bind Keys
|
||||
CARD = "BNTTCNID1" # Card Number
|
||||
|
||||
# For Second User's QRCode
|
||||
[[QRCODE_CARD]]
|
||||
READ_KEY = ["W"] # Bind Keys
|
||||
CARD = "BNTTCNID2" # Card Number
|
||||
|
||||
# F1 through F12
|
||||
# NUM0 through NUM9
|
||||
# QWERTYUIOPASDFGHJKLZXCVBNM
|
||||
|
@ -39,6 +39,8 @@ Keybindings P2_LEFT_BLUE = {};
|
||||
Keybindings P2_LEFT_RED = {};
|
||||
Keybindings P2_RIGHT_RED = {};
|
||||
Keybindings P2_RIGHT_BLUE = {};
|
||||
CardKeybingings* QRCODE_CARDS = {{.keybindings.keycodes = {'W'}, .card = "BNTTCNID1"}, {.keybindings.keycodes = {'E'}, .card = "BNTTCNID2"}};
|
||||
size_t QRCODE_CARDS_LENG = 2;
|
||||
|
||||
namespace bnusio {
|
||||
#define RETURN_FALSE(returnType, functionName, ...) \
|
||||
@ -342,6 +344,8 @@ Init () {
|
||||
SetConfigValue (keyconfig, "P2_RIGHT_RED", &P2_RIGHT_RED);
|
||||
SetConfigValue (keyconfig, "P2_RIGHT_BLUE", &P2_RIGHT_BLUE);
|
||||
|
||||
SetCardConfigValue (keyconfig, "QRCODE_CARD", &QRCODE_CARDS, &QRCODE_CARDS_LENG);
|
||||
|
||||
toml_free (keyconfig);
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,13 @@
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
|
||||
extern GameVersion gameVersion;
|
||||
extern Keybindings QR_CARD_READ;
|
||||
extern Keybindings QR_DATA_READ;
|
||||
extern CardKeybingings *QRCODE_CARDS;
|
||||
extern size_t QRCODE_CARDS_LENG;
|
||||
|
||||
namespace patches::Qr {
|
||||
|
||||
@ -17,6 +20,7 @@ enum class State { Ready, CopyWait, AfterCopy1, AfterCopy2 };
|
||||
enum class Mode { Card, Data };
|
||||
State gState = State::Ready;
|
||||
Mode gMode = Mode::Card;
|
||||
std::string card_number = "";
|
||||
|
||||
HOOK_DYNAMIC (char, __fastcall, qrInit, i64) { return 1; }
|
||||
HOOK_DYNAMIC (char, __fastcall, qrRead, i64 a1) {
|
||||
@ -73,6 +77,10 @@ HOOK_DYNAMIC (i64, __fastcall, copy_data, i64, void *dest, int length) {
|
||||
memcpy (dest, card.c_str (), card.size () + 1);
|
||||
gState = State::AfterCopy1;
|
||||
return card.size () + 1;
|
||||
} else if (gMode == Mode::MultiCard) {
|
||||
memcpy (dest, card_number.c_str (), card_number.size () + 1);
|
||||
gState = State::AfterCopy1;
|
||||
return card_number.size () + 1;
|
||||
} else {
|
||||
std::string serial = "";
|
||||
u16 type = 0;
|
||||
@ -145,7 +153,16 @@ Update () {
|
||||
std::cout << "Insert" << std::endl;
|
||||
gState = State::CopyWait;
|
||||
gMode = Mode::Data;
|
||||
}
|
||||
} else {
|
||||
for (size_t i = 0; i < QRCODE_CARDS_LENG; i++) {
|
||||
if (IsButtonTapped (QRCODE_CARDS[i].keybindings)) {
|
||||
std::cout << "Insert" << std::endl;
|
||||
gState = State::CopyWait;
|
||||
gMode = Mode::MultiCard;
|
||||
card_number = QRCODE_CARDS[i].card;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
67
src/poll.cpp
67
src/poll.cpp
@ -184,6 +184,73 @@ SetConfigValue (toml_table_t *table, const char *key, Keybindings *keybind) {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
SetCardConfigValue (toml_table_t *table, const char *key, CardKeybindings **cards, size_t *leng) {
|
||||
toml_array_t *array = toml_array_in (table, key);
|
||||
if (!array) {
|
||||
printWarning ("%s (%s): Cannot find array\n", __func__, key);
|
||||
return;
|
||||
}
|
||||
|
||||
size_t length = toml_array_nelem(array);
|
||||
*leng = length;
|
||||
cards = memset(*cards, 0, length * (sizeof (*cards)));
|
||||
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
const toml_table_t* card_obj = toml_table_at(arr, i);
|
||||
if (card_obj) {
|
||||
memset (cards[i], 0, sizeof (**cards));
|
||||
cards[i]->card = toml_string_in(obj, "CARD")
|
||||
|
||||
for (size_t i = 0; i < COUNTOFARR (keybind->buttons); i++)
|
||||
cards[i]->keybindings.buttons[i] = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
|
||||
for (size_t i = 0;; i++) {
|
||||
toml_datum_t bind = toml_string_at (array, i);
|
||||
if (!bind.ok) break;
|
||||
ConfigValue value = StringToConfigEnum (bind.u.s);
|
||||
free (bind.u.s);
|
||||
|
||||
switch (value.type) {
|
||||
case keycode:
|
||||
for (size_t i = 0; i < COUNTOFARR (cards[i]->keybindings.keycodes); i++) {
|
||||
if (cards[i]->keybindings.keycodes[i] == 0) {
|
||||
cards[i]->keybindings.keycodes[i] = value.keycode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case button:
|
||||
for (size_t i = 0; i < COUNTOFARR (cards[i]->keybindings.buttons); i++) {
|
||||
if (cards[i]->keybindings.buttons[i] == SDL_CONTROLLER_BUTTON_INVALID) {
|
||||
cards[i]->keybindings.buttons[i] = value.button;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case axis:
|
||||
for (size_t i = 0; i < COUNTOFARR (cards[i]->keybindings.axis); i++) {
|
||||
if (cards[i]->keybindings.axis[i] == 0) {
|
||||
cards[i]->keybindings.axis[i] = value.axis;
|
||||
break;
|
||||
}
|
||||
}
|
||||
case scroll:
|
||||
for (size_t i = 0; i < COUNTOFARR (cards[i]->keybindings.scroll); i++) {
|
||||
if (cards[i]->keybindings.scroll[i] == 0) {
|
||||
cards[i]->keybindings.scroll[i] = value.scroll;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
InitializePoll (HWND windowHandle) {
|
||||
bool hasRumble = true;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <stdint.h>
|
||||
#include <toml.h>
|
||||
#include <windows.h>
|
||||
#include <iostream>
|
||||
|
||||
enum SDLAxis {
|
||||
SDL_AXIS_NULL,
|
||||
@ -42,6 +43,11 @@ struct Keybindings {
|
||||
Scroll scroll[2];
|
||||
};
|
||||
|
||||
struct CardKeybingings {
|
||||
Keybindings keybindings;
|
||||
std::string card;
|
||||
}
|
||||
|
||||
enum EnumType { none, keycode, button, axis, scroll };
|
||||
|
||||
struct ConfigValue {
|
||||
@ -65,6 +71,7 @@ void UpdatePoll (HWND windowHandle);
|
||||
void DisposePoll ();
|
||||
ConfigValue StringToConfigEnum (const char *value);
|
||||
void SetConfigValue (toml_table_t *table, const char *key, Keybindings *keybind);
|
||||
void SetCardConfigValue (toml_table_t *table, const char *key, CardKeybingings **keybind, size_t *leng);
|
||||
InternalButtonState GetInternalButtonState (Keybindings bindings);
|
||||
void SetRumble (int left, int right, int length);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user