From 9e4ce5a59aa0b411553b162abf863d2ee249b0b8 Mon Sep 17 00:00:00 2001 From: RyuMiya Date: Mon, 25 Dec 2023 23:04:51 +0800 Subject: [PATCH] Fix --- src/bnusio.cpp | 9 ++++++--- src/patches/qr.cpp | 2 +- src/poll.cpp | 21 +++++++++++++-------- src/poll.h | 4 ++-- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/bnusio.cpp b/src/bnusio.cpp index 5fb34e3..7343042 100644 --- a/src/bnusio.cpp +++ b/src/bnusio.cpp @@ -39,8 +39,11 @@ Keybindings P2_LEFT_BLUE = {}; Keybindings P2_LEFT_RED = {}; Keybindings P2_RIGHT_RED = {}; Keybindings P2_RIGHT_BLUE = {}; -CardKeybindings *QRCODE_CARDS = new CardKeybindings[0]; -size_t QRCODE_CARDS_LENG = 0; +CardKeybindings *QRCODE_CARDS = new CardKeybindings[] { + {.keybindings = {.keycodes = {'W'}}, .card = "BNTTCNID1"}, + {.keybindings = {.keycodes = {'E'}}, .card = "BNTTCNID2"}, +}; +size_t QRCODE_CARDS_LENG = 2; namespace bnusio { #define RETURN_FALSE(returnType, functionName, ...) \ @@ -344,7 +347,7 @@ 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); + SetCardConfigValue (keyconfig, "QRCODE_CARD", &QRCODE_CARDS, &QRCODE_CARDS_LENG); toml_free (keyconfig); } diff --git a/src/patches/qr.cpp b/src/patches/qr.cpp index 7ec8da2..0780c2b 100644 --- a/src/patches/qr.cpp +++ b/src/patches/qr.cpp @@ -157,7 +157,7 @@ Update () { } 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; + std::cout << "Insert: " << QRCODE_CARDS[i].card << std::endl; gState = State::CopyWait; gMode = Mode::MultiCard; gCardNumber = QRCODE_CARDS[i].card; diff --git a/src/poll.cpp b/src/poll.cpp index fffd1f8..b9fb738 100644 --- a/src/poll.cpp +++ b/src/poll.cpp @@ -130,6 +130,7 @@ SDL_GameController *controllers[255]; void SetConfigValue (toml_table_t *table, const char *key, Keybindings *keybind) { + std::cout << "Name: " << key << std::endl; toml_array_t *array = toml_array_in (table, key); if (!array) { printWarning ("%s (%s): Cannot find array\n", __func__, key); @@ -143,6 +144,7 @@ SetConfigValue (toml_table_t *table, const char *key, Keybindings *keybind) { for (size_t i = 0;; i++) { toml_datum_t bind = toml_string_at (array, i); if (!bind.ok) break; + std::cout << "Key: " << bind.u.s << std::endl; ConfigValue value = StringToConfigEnum (bind.u.s); free (bind.u.s); @@ -185,22 +187,24 @@ SetConfigValue (toml_table_t *table, const char *key, Keybindings *keybind) { } void -SetCardConfigValue (toml_table_t *table, const char *key, CardKeybindings *cards, size_t *leng) { +SetCardConfigValue (toml_table_t *table, const char *key, CardKeybindings **cards, size_t *leng) { 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(top_array); - *leng = length; - cards = new CardKeybindings[length]; + *leng = toml_array_nelem(top_array); + *cards = (CardKeybindings*) calloc (*leng, sizeof(CardKeybindings)); - for (size_t top_i = 0; top_i < length; ++top_i) { + for (size_t top_i = 0; top_i < *leng; ++top_i) { toml_table_t* card_obj = toml_table_at(top_array, top_i); if (card_obj) { - CardKeybindings cardInfo = cards[top_i] = {}; - cardInfo.card = readConfigString(card_obj, "CARD", ""); + std::string read_card = readConfigString (card_obj, "CARD", ""); + (*cards)[top_i].card = (char*) calloc (read_card.size() + 1, sizeof(char)); + strcpy((*cards)[top_i].card, read_card.c_str()); + + std::cout << "Card: " << (*cards)[top_i].card << std::endl; toml_array_t *array = toml_array_in (card_obj, "READ_KEY"); if (!array) { @@ -208,7 +212,7 @@ SetCardConfigValue (toml_table_t *table, const char *key, CardKeybindings *cards return; } - Keybindings *keybind = &(cardInfo.keybindings); + Keybindings *keybind = &((*cards)[top_i].keybindings); memset (keybind, 0, sizeof (*keybind)); for (size_t i = 0; i < COUNTOFARR (keybind->buttons); i++) keybind->buttons[i] = SDL_CONTROLLER_BUTTON_INVALID; @@ -216,6 +220,7 @@ SetCardConfigValue (toml_table_t *table, const char *key, CardKeybindings *cards for (size_t i = 0;; i++) { toml_datum_t bind = toml_string_at (array, i); if (!bind.ok) break; + std::cout << "Key: " << bind.u.s << std::endl; ConfigValue value = StringToConfigEnum (bind.u.s); free (bind.u.s); diff --git a/src/poll.h b/src/poll.h index 0415ab7..a2dbbcc 100644 --- a/src/poll.h +++ b/src/poll.h @@ -45,7 +45,7 @@ struct Keybindings { struct CardKeybindings { Keybindings keybindings; - std::string card; + char* 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, CardKeybindings *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);