From db6a0c061bdd371efe92507fc3dcc0c8eb57ac51 Mon Sep 17 00:00:00 2001 From: esuo1198 <54134.es@gmail.com> Date: Sun, 24 Sep 2023 01:08:12 +0900 Subject: [PATCH] Add QR customfolder support --- dist/config.toml | 9 ++++-- dist/keyconfig.toml | 4 +-- src/dllmain.cpp | 5 +++- src/helpers.cpp | 15 ++++++++++ src/helpers.h | 1 + src/keyconfig.cpp | 4 +-- src/patches/amauth.cpp | 2 +- src/patches/cn_jun_2023.cpp | 17 ++++++----- src/patches/jp_nov_2020.cpp | 17 ++++++----- src/patches/qr.cpp | 57 +++++++++++++++++++++++++++++-------- 10 files changed, 97 insertions(+), 34 deletions(-) diff --git a/dist/config.toml b/dist/config.toml index f6c2edd..1e36054 100644 --- a/dist/config.toml +++ b/dist/config.toml @@ -1,7 +1,12 @@ +[amauth] server = "127.0.0.1" + +[patches] res = { x = 1920, y = 1080 } unlock_songs = true shared_audio = true vsync = false -qr_card_string = "" -qr_data_string = "" \ No newline at end of file + +[qr] +card = "" +data = { serial = "", type = 0, song_no = [] } \ No newline at end of file diff --git a/dist/keyconfig.toml b/dist/keyconfig.toml index d09a890..aaa4205 100644 --- a/dist/keyconfig.toml +++ b/dist/keyconfig.toml @@ -7,9 +7,9 @@ DEBUG_DOWN = ["DOWNARROW"] DEBUG_ENTER = ["ENTER"] COIN_ADD = ["ENTER", "SDL_START"] -CARD_INSERT_1 = ["P"] +CARD_INSERT_1 = [] CARD_INSERT_2 = [] -QR_CARD_READ = ["O"] +QR_CARD_READ = [] QR_DATA_READ = ["Q"] P1_LEFT_BLUE = ["D", "SDL_LTRIGGER"] diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 24185e9..575c476 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -114,7 +114,10 @@ DllMain (HMODULE module, DWORD reason, LPVOID reserved) { auto configPath = std::filesystem::current_path () / "config.toml"; toml_table_t *config = openConfig (configPath); if (config) { - server = readConfigString (config, "server", server); + auto amauth = openConfigSection(config, "amauth"); + if (amauth) { + server = readConfigString(amauth, "server", server); + } toml_free (config); } diff --git a/src/helpers.cpp b/src/helpers.cpp index 2c84b68..eb51f32 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -71,6 +71,21 @@ readConfigString (toml_table_t *table, const char *key, const char *notFoundValu return data.u.s; } +std::vector +readConfigIntArray (toml_table_t *table, const char *key, std::vector notFoundValue) { + toml_array_t *array = toml_array_in (table, key); + if (!array) return notFoundValue; + + std::vector datas; + for (int i = 0; ; i++) { + toml_datum_t data = toml_int_at (array, i); + if (!data.ok) break; + datas.push_back (data.u.i); + } + + return datas; +} + void printColour (int colour, const char *format, ...) { va_list args; diff --git a/src/helpers.h b/src/helpers.h index 522855f..e3261b4 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -119,4 +119,5 @@ toml_table_t *openConfigSection (toml_table_t *config, const char *sectionName); bool readConfigBool (toml_table_t *table, const char *key, bool notFoundValue); int64_t readConfigInt (toml_table_t *table, const char *key, int64_t notFoundValue); const char *readConfigString (toml_table_t *table, const char *key, const char *notFoundValue); +std::vector readConfigIntArray (toml_table_t *table, const char *key, std::vector notFoundValue); void printColour (int colour, const char *format, ...); diff --git a/src/keyconfig.cpp b/src/keyconfig.cpp index 915b5bb..4c2cb59 100644 --- a/src/keyconfig.cpp +++ b/src/keyconfig.cpp @@ -9,9 +9,9 @@ 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_1 = {}; Keybindings CARD_INSERT_2 = {}; -Keybindings QR_CARD_READ = {.keycodes = {'O'}}; +Keybindings QR_CARD_READ = {}; Keybindings QR_DATA_READ = {.keycodes = {'Q'}}; Keybindings P1_LEFT_BLUE = {.keycodes = {'D'}, .axis = {SDL_AXIS_LTRIGGER_DOWN}}; Keybindings P1_LEFT_RED = {.keycodes = {'F'}, .buttons = {SDL_CONTROLLER_BUTTON_LEFTSTICK}}; diff --git a/src/patches/amauth.cpp b/src/patches/amauth.cpp index 3236a9e..3791748 100644 --- a/src/patches/amauth.cpp +++ b/src/patches/amauth.cpp @@ -13,7 +13,7 @@ DWORD reg = 0; #undef DEFINE_GUID #endif -#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } +#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) const GUID name = {l, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}} DEFINE_GUID (IID_CAuthFactory, 0x4603BB03, 0x058D, 0x43D9, 0xB9, 0x6F, 0x63, 0x9B, 0xE9, 0x08, 0xC1, 0xED); DEFINE_GUID (IID_CAuth, 0x045A5150, 0xD2B3, 0x4590, 0xA3, 0x8B, 0xC1, 0x15, 0x86, 0x78, 0xE1, 0xAC); diff --git a/src/patches/cn_jun_2023.cpp b/src/patches/cn_jun_2023.cpp index 8f65dd4..6b0e117 100644 --- a/src/patches/cn_jun_2023.cpp +++ b/src/patches/cn_jun_2023.cpp @@ -48,14 +48,17 @@ Init () { auto configPath = std::filesystem::current_path () / "config.toml"; toml_table_t *config = openConfig (configPath); if (config) { - auto res = openConfigSection (config, "res"); - if (res) { - xRes = readConfigInt (res, "x", xRes); - yRes = readConfigInt (res, "y", yRes); + auto patches = openConfigSection(config, "patches"); + if (patches) { + auto res = openConfigSection (patches, "res"); + if (res) { + xRes = readConfigInt (res, "x", xRes); + yRes = readConfigInt (res, "y", yRes); + } + unlockSongs = readConfigBool (patches, "unlock_songs", unlockSongs); + sharedAudio = readConfigBool (patches, "shared_audio", sharedAudio); + vsync = readConfigBool (patches, "vsync", vsync); } - unlockSongs = readConfigBool (config, "unlock_songs", unlockSongs); - sharedAudio = readConfigBool (config, "shared_audio", sharedAudio); - vsync = readConfigBool (config, "vsync", vsync); toml_free (config); } diff --git a/src/patches/jp_nov_2020.cpp b/src/patches/jp_nov_2020.cpp index 5113997..e513385 100644 --- a/src/patches/jp_nov_2020.cpp +++ b/src/patches/jp_nov_2020.cpp @@ -22,14 +22,17 @@ Init () { auto configPath = std::filesystem::current_path () / "config.toml"; toml_table_t *config = openConfig (configPath); if (config) { - auto res = openConfigSection (config, "res"); - if (res) { - xRes = readConfigInt (res, "x", xRes); - yRes = readConfigInt (res, "y", yRes); + auto patches = openConfigSection(config, "patches"); + if (patches) { + auto res = openConfigSection (patches, "res"); + if (res) { + xRes = readConfigInt (res, "x", xRes); + yRes = readConfigInt (res, "y", yRes); + } + unlockSongs = readConfigBool (patches, "unlock_songs", unlockSongs); + sharedAudio = readConfigBool (patches, "shared_audio", sharedAudio); + vsync = readConfigBool (patches, "vsync", vsync); } - unlockSongs = readConfigBool (config, "unlock_songs", unlockSongs); - sharedAudio = readConfigBool (config, "shared_audio", sharedAudio); - vsync = readConfigBool (config, "vsync", vsync); toml_free (config); } diff --git a/src/patches/qr.cpp b/src/patches/qr.cpp index 2d2a432..8f457b2 100644 --- a/src/patches/qr.cpp +++ b/src/patches/qr.cpp @@ -65,31 +65,64 @@ HOOK_DYNAMIC (bool, __fastcall, Send4, int64_t a1) { HOOK_DYNAMIC (int64_t, __fastcall, copy_data, int64_t this_, void *dest, int length) { if (gState == State::CopyWait) { std::cout << "Copy data, length: " << length << std::endl; + auto configPath = std::filesystem::current_path () / "config.toml"; toml_table_t *config = openConfig (configPath); - std::string data = ""; - + if (gMode == Mode::Card) { + std::string card = ""; if (config) { - data = readConfigString (config, "qr_card_string", ""); - toml_free (config); + auto qr = openConfigSection(config, "qr"); + if (qr) { + card = readConfigString(qr, "card", ""); + } + toml_free(config); } - memcpy (dest, data.c_str (), data.size () + 1); + memcpy (dest, card.c_str (), card.size () + 1); gState = State::AfterCopy1; - return data.size () + 1; - } else if (gMode == Mode::Data) { + return card.size () + 1; + } else { + std::string serial = ""; + u16 type = 0; + std::vector songNoes; + if (config) { - data = readConfigString (config, "qr_data_string", ""); - toml_free (config); + auto qr = openConfigSection (config, "qr"); + if (qr) { + auto data = openConfigSection (qr, "data"); + if (data) { + serial = readConfigString (data, "serial", ""); + type = readConfigInt (data, "type", 0); + songNoes = readConfigIntArray (data, "song_no", songNoes); + } + } } - BYTE data_length = static_cast (data.size ()); - std::vector byteBuffer = {0x53, 0x31, 0x32, 0x00, 0x00, 0xFF, 0xFF, data_length, 0x01, 0x00}; + BYTE serial_length = static_cast (serial.size ()); + std::vector byteBuffer = {0x53, 0x31, 0x32, 0x00, 0x00, 0xFF, 0xFF, serial_length, 0x01, 0x00}; - for (char c : data) + for (char c : serial) byteBuffer.push_back (static_cast (c)); + if (type == 5) { + std::vector folderData = {0xFF, 0xFF}; + + folderData.push_back (songNoes.size() * 2); + + folderData.push_back (static_cast (type & 0xFF)); + folderData.push_back (static_cast ((type >> 8) & 0xFF)); + + for (u16 songNo:songNoes) { + folderData.push_back (static_cast (songNo & 0xFF)); + folderData.push_back (static_cast ((songNo >> 8) & 0xFF)); + } + + for (auto c:folderData) { + byteBuffer.push_back (c); + } + } + byteBuffer.push_back (0xEE); byteBuffer.push_back (0xFF);