1
0
mirror of synced 2024-12-01 02:27:25 +01:00

修复异常

This commit is contained in:
RyuMiya 2023-12-25 15:24:47 +08:00
parent c50ab88ce1
commit b510c1e535
4 changed files with 29 additions and 23 deletions

View File

@ -39,8 +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;
CardKeybindings *QRCODE_CARDS = {};
size_t QRCODE_CARDS_LENG = 0;
namespace bnusio {
#define RETURN_FALSE(returnType, functionName, ...) \

View File

@ -11,16 +11,16 @@
extern GameVersion gameVersion;
extern Keybindings QR_CARD_READ;
extern Keybindings QR_DATA_READ;
extern CardKeybingings *QRCODE_CARDS;
extern CardKeybindings *QRCODE_CARDS;
extern size_t QRCODE_CARDS_LENG;
namespace patches::Qr {
enum class State { Ready, CopyWait, AfterCopy1, AfterCopy2 };
enum class Mode { Card, Data };
State gState = State::Ready;
Mode gMode = Mode::Card;
std::string card_number = "";
enum class Mode { Card, Data, MultiCard };
State gState = State::Ready;
Mode gMode = Mode::Card;
std::string gCardNumber = "";
HOOK_DYNAMIC (char, __fastcall, qrInit, i64) { return 1; }
HOOK_DYNAMIC (char, __fastcall, qrRead, i64 a1) {
@ -79,9 +79,9 @@ HOOK_DYNAMIC (i64, __fastcall, copy_data, i64, void *dest, int length) {
return card.size () + 1;
} else if (gMode == Mode::MultiCard) {
if (config) toml_free (config);
memcpy (dest, card_number.c_str (), card_number.size () + 1);
memcpy (dest, gCardNumber.c_str (), gCardNumber.size () + 1);
gState = State::AfterCopy1;
return card_number.size () + 1;
return gCardNumber.size () + 1;
} else {
std::string serial = "";
u16 type = 0;
@ -154,13 +154,13 @@ Update () {
std::cout << "Insert" << std::endl;
gState = State::CopyWait;
gMode = Mode::Data;
} else {
} else if (QRCODE_CARDS != nullptr) {
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;
gState = State::CopyWait;
gMode = Mode::MultiCard;
gCardNumber = QRCODE_CARDS[i].card;
break;
}
}

View File

@ -186,23 +186,29 @@ 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) {
toml_array_t *top_array = toml_array_in (table, key);
if (!top_array) {
printWarning ("%s (%s): Cannot find array\n", __func__, key);
return;
}
size_t length = toml_array_nelem(array);
size_t length = toml_array_nelem(top_array);
*leng = length;
cards = memset(*cards, 0, length * (sizeof (*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);
toml_table_t* card_obj = toml_table_at(top_array, i);
if (card_obj) {
memset (cards[i], 0, sizeof (**cards));
cards[i]->card = toml_string_in(obj, "CARD")
cards[i]->card = readConfigString(card_obj, "CARD", "");
for (size_t i = 0; i < COUNTOFARR (keybind->buttons); i++)
toml_array_t *array = toml_array_in (card_obj, "READ_KEY");
if (!array) {
printWarning ("%s (%s): Cannot find READ_KEY in CARD_INFO\n", __func__, key);
return;
}
for (size_t i = 0; i < COUNTOFARR (cards[i]->keybindings.buttons); i++)
cards[i]->keybindings.buttons[i] = SDL_CONTROLLER_BUTTON_INVALID;
for (size_t i = 0;; i++) {

View File

@ -43,10 +43,10 @@ struct Keybindings {
Scroll scroll[2];
};
struct CardKeybingings {
struct CardKeybindings {
Keybindings keybindings;
std::string card;
}
};
enum EnumType { none, keycode, button, axis, scroll };
@ -71,7 +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);
void SetCardConfigValue (toml_table_t *table, const char *key, CardKeybindings **keybind, size_t *leng);
InternalButtonState GetInternalButtonState (Keybindings bindings);
void SetRumble (int left, int right, int length);