diff --git a/dist/config.toml b/dist/config.toml index 6ba34a5..cb23b76 100644 --- a/dist/config.toml +++ b/dist/config.toml @@ -21,7 +21,6 @@ unlock_songs = true mode_collabo026 = false [qr] -card = "" data = { serial = "", type = 0, song_no = [] } [drum] diff --git a/dist/keyconfig.toml b/dist/keyconfig.toml index fc192d7..2952a72 100644 --- a/dist/keyconfig.toml +++ b/dist/keyconfig.toml @@ -7,9 +7,8 @@ DEBUG_DOWN = ["DOWNARROW"] DEBUG_ENTER = ["ENTER"] COIN_ADD = ["ENTER", "SDL_START"] -CARD_INSERT_1 = [] +CARD_INSERT_1 = ["P"] CARD_INSERT_2 = [] -QR_CARD_READ = [] QR_DATA_READ = ["Q"] P1_LEFT_BLUE = ["D", "SDL_LTRIGGER"] @@ -21,16 +20,6 @@ P2_LEFT_RED = [] P2_RIGHT_RED = [] P2_RIGHT_BLUE = [] -# For First User's QRCode -[[QRCODE_CARD]] -READ_KEY = ["W"] # Bind Keys -CARD = "BNTTCNID1" # Card Number - -# For Second User's QRCode -[[QRCODE_CARD]] -READ_KEY = ["E"] # Bind Keys -CARD = "BNTTCNID2" # Card Number - # ESCAPE F1 through F12 # ` 1 through 0 -= BACKSPACE # TAB QWERTYUIOP [ ] BACKSLASH diff --git a/src/bnusio.cpp b/src/bnusio.cpp index 40a7720..2f1a197 100644 --- a/src/bnusio.cpp +++ b/src/bnusio.cpp @@ -20,30 +20,24 @@ u64 touchData; callbackAttach attachCallback; i32 *attachData; -Keybindings EXIT = {.keycodes = {VK_ESCAPE}}; -Keybindings TEST = {.keycodes = {VK_F1}}; -Keybindings SERVICE = {.keycodes = {VK_F2}}; -Keybindings DEBUG_UP = {.keycodes = {VK_UP}}; -Keybindings DEBUG_DOWN = {.keycodes = {VK_DOWN}}; -Keybindings DEBUG_ENTER = {.keycodes = {VK_RETURN}}; -Keybindings COIN_ADD = {.keycodes = {VK_RETURN}, .buttons = {SDL_CONTROLLER_BUTTON_START}}; -Keybindings CARD_INSERT_1 = {}; -Keybindings CARD_INSERT_2 = {}; -Keybindings QR_CARD_READ = {}; -Keybindings QR_DATA_READ = {.keycodes = {'Q'}}; -Keybindings P1_LEFT_BLUE = {.keycodes = {'D'}, .axis = {SDL_AXIS_LEFT_DOWN}}; -Keybindings P1_LEFT_RED = {.keycodes = {'F'}, .axis = {SDL_AXIS_LEFT_RIGHT}}; -Keybindings P1_RIGHT_RED = {.keycodes = {'J'}, .axis = {SDL_AXIS_RIGHT_RIGHT}}; -Keybindings P1_RIGHT_BLUE = {.keycodes = {'K'}, .axis = {SDL_AXIS_RIGHT_DOWN}}; -Keybindings P2_LEFT_BLUE = {}; -Keybindings P2_LEFT_RED = {}; -Keybindings P2_RIGHT_RED = {}; -Keybindings P2_RIGHT_BLUE = {}; -CardKeybindings *QRCODE_CARDS = new CardKeybindings[]{ - {.keybindings = {.keycodes = {'W'}}, .card = "BNTTCNID1"}, - {.keybindings = {.keycodes = {'E'}}, .card = "BNTTCNID2"}, -}; -size_t QRCODE_CARDS_LENG = 2; +Keybindings EXIT = {.keycodes = {VK_ESCAPE}}; +Keybindings TEST = {.keycodes = {VK_F1}}; +Keybindings SERVICE = {.keycodes = {VK_F2}}; +Keybindings DEBUG_UP = {.keycodes = {VK_UP}}; +Keybindings DEBUG_DOWN = {.keycodes = {VK_DOWN}}; +Keybindings DEBUG_ENTER = {.keycodes = {VK_RETURN}}; +Keybindings COIN_ADD = {.keycodes = {VK_RETURN}, .buttons = {SDL_CONTROLLER_BUTTON_START}}; +Keybindings CARD_INSERT_1 = {.keycodes = {'P'}}; +Keybindings CARD_INSERT_2 = {}; +Keybindings QR_DATA_READ = {.keycodes = {'Q'}}; +Keybindings P1_LEFT_BLUE = {.keycodes = {'D'}, .axis = {SDL_AXIS_LEFT_DOWN}}; +Keybindings P1_LEFT_RED = {.keycodes = {'F'}, .axis = {SDL_AXIS_LEFT_RIGHT}}; +Keybindings P1_RIGHT_RED = {.keycodes = {'J'}, .axis = {SDL_AXIS_RIGHT_RIGHT}}; +Keybindings P1_RIGHT_BLUE = {.keycodes = {'K'}, .axis = {SDL_AXIS_RIGHT_DOWN}}; +Keybindings P2_LEFT_BLUE = {}; +Keybindings P2_LEFT_RED = {}; +Keybindings P2_RIGHT_RED = {}; +Keybindings P2_RIGHT_BLUE = {}; namespace bnusio { #define RETURN_FALSE(returnType, functionName, ...) \ @@ -353,7 +347,6 @@ Init () { SetConfigValue (keyconfig, "COIN_ADD", &COIN_ADD); SetConfigValue (keyconfig, "CARD_INSERT_1", &CARD_INSERT_1); SetConfigValue (keyconfig, "CARD_INSERT_2", &CARD_INSERT_2); - SetConfigValue (keyconfig, "QR_CARD_READ", &QR_CARD_READ); SetConfigValue (keyconfig, "QR_DATA_READ", &QR_DATA_READ); SetConfigValue (keyconfig, "P1_LEFT_BLUE", &P1_LEFT_BLUE); @@ -365,8 +358,6 @@ 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); } } diff --git a/src/patches/qr.cpp b/src/patches/qr.cpp index 3bf74fa..6916ca6 100644 --- a/src/patches/qr.cpp +++ b/src/patches/qr.cpp @@ -5,22 +5,22 @@ #include #include #include -#include #include extern GameVersion gameVersion; -extern Keybindings QR_CARD_READ; +extern Keybindings CARD_INSERT_1; +extern Keybindings CARD_INSERT_2; extern Keybindings QR_DATA_READ; -extern CardKeybindings *QRCODE_CARDS; -extern size_t QRCODE_CARDS_LENG; +extern char accessCode1[21]; +extern char accessCode2[21]; namespace patches::Qr { enum class State { Ready, CopyWait }; -enum class Mode { Card, Data, MultiCard }; -State gState = State::Ready; -Mode gMode = Mode::Card; -std::string gCardNumber = ""; +enum class Mode { Card, Data }; +State gState = State::Ready; +Mode gMode = Mode::Card; +std::string accessCode; HOOK_DYNAMIC (char, __fastcall, qrInit, i64) { return 1; } HOOK_DYNAMIC (char, __fastcall, qrRead, i64 a1) { @@ -52,21 +52,11 @@ HOOK_DYNAMIC (i64, __fastcall, copy_data, i64, void *dest, int length) { toml_table_t *config = openConfig (configPath); if (gMode == Mode::Card) { - std::string card = ""; - if (config) { - auto qr = openConfigSection (config, "qr"); - if (qr) card = readConfigString (qr, "card", ""); - toml_free (config); - } - - memcpy (dest, card.c_str (), card.size () + 1); - gState = State::Ready; - return card.size () + 1; - } else if (gMode == Mode::MultiCard) { if (config) toml_free (config); - memcpy (dest, gCardNumber.c_str (), gCardNumber.size () + 1); + + memcpy (dest, accessCode.c_str (), accessCode.size () + 1); gState = State::Ready; - return gCardNumber.size () + 1; + return accessCode.size () + 1; } else { std::string serial = ""; u16 type = 0; @@ -122,24 +112,26 @@ HOOK_DYNAMIC (i64, __fastcall, copy_data, i64, void *dest, int length) { void Update () { if (gState == State::Ready) { - if (IsButtonTapped (QR_CARD_READ)) { + if (IsButtonTapped (CARD_INSERT_1)) { + if (gameVersion != GameVersion::CN_JUN_2023) return; + std::cout << "Insert" << std::endl; + accessCode = "BNTTCNID"; + accessCode += accessCode1; + gState = State::CopyWait; + gMode = Mode::Card; + } else if (IsButtonTapped (CARD_INSERT_2)) { + if (gameVersion != GameVersion::CN_JUN_2023) return; + + std::cout << "Insert" << std::endl; + accessCode = "BNTTCNID"; + accessCode += accessCode2; gState = State::CopyWait; gMode = Mode::Card; } else if (IsButtonTapped (QR_DATA_READ)) { std::cout << "Insert" << std::endl; gState = State::CopyWait; gMode = Mode::Data; - } else if (QRCODE_CARDS != nullptr) { - for (size_t i = 0; i < QRCODE_CARDS_LENG; i++) { - if (IsButtonTapped (QRCODE_CARDS[i].keybindings)) { - std::cout << "Insert: " << QRCODE_CARDS[i].card << std::endl; - gState = State::CopyWait; - gMode = Mode::MultiCard; - gCardNumber = QRCODE_CARDS[i].card; - break; - } - } } } } diff --git a/src/poll.cpp b/src/poll.cpp index b5efef1..1c75896 100644 --- a/src/poll.cpp +++ b/src/poll.cpp @@ -247,81 +247,6 @@ 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 *top_array = toml_array_in (table, key); - if (!top_array) { - printWarning ("%s (%s): Cannot find array\n", __func__, key); - return; - } - - *leng = toml_array_nelem(top_array); - *cards = (CardKeybindings*) calloc (*leng, sizeof(CardKeybindings)); - - 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) { - 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()); - - 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; - } - - 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; - - 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 (keybind->keycodes); i++) { - if (keybind->keycodes[i] == 0) { - keybind->keycodes[i] = value.keycode; - break; - } - } - break; - case button: - for (size_t i = 0; i < COUNTOFARR (keybind->buttons); i++) { - if (keybind->buttons[i] == SDL_CONTROLLER_BUTTON_INVALID) { - keybind->buttons[i] = value.button; - break; - } - } - break; - case axis: - for (size_t i = 0; i < COUNTOFARR (keybind->axis); i++) { - if (keybind->axis[i] == 0) { - keybind->axis[i] = value.axis; - break; - } - } - case scroll: - for (size_t i = 0; i < COUNTOFARR (keybind->scroll); i++) { - if (keybind->scroll[i] == 0) { - keybind->scroll[i] = value.scroll; - break; - } - } - break; - default: - break; - } - } - } - } -} - bool InitializePoll (HWND windowHandle) { bool hasRumble = true; diff --git a/src/poll.h b/src/poll.h index a2dbbcc..f7b63dd 100644 --- a/src/poll.h +++ b/src/poll.h @@ -4,7 +4,6 @@ #include #include #include -#include enum SDLAxis { SDL_AXIS_NULL, @@ -43,11 +42,6 @@ struct Keybindings { Scroll scroll[2]; }; -struct CardKeybindings { - Keybindings keybindings; - char* card; -}; - enum EnumType { none, keycode, button, axis, scroll }; struct ConfigValue { @@ -71,7 +65,6 @@ 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); InternalButtonState GetInternalButtonState (Keybindings bindings); void SetRumble (int left, int right, int length);