diff --git a/README.md b/README.md index c3f5a9b..8dbb673 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,14 @@ unlock_songs = true mode_collabo025 = false # enable ai soshina mode mode_collabo026 = false + +[card_reader] +# enable card reader emulation +enabled = true [qr] +# enable qr emulation +enabled = true # qr image path image_path = "" diff --git a/dist/config.toml b/dist/config.toml index 2774114..34b379a 100644 --- a/dist/config.toml +++ b/dist/config.toml @@ -24,7 +24,11 @@ unlock_songs = true mode_collabo025 = false mode_collabo026 = false +[card_reader] +enabled = true + [qr] +enabled = true image_path = "" [qr.data] diff --git a/src/bnusio.cpp b/src/bnusio.cpp index 354f917..a6d2fd2 100644 --- a/src/bnusio.cpp +++ b/src/bnusio.cpp @@ -299,45 +299,52 @@ HOOK (u64, bngrw_reqWaitTouch, PROC_ADDRESS ("bngrw.dll", "BngRwReqWaitTouch"), void Init () { - INSTALL_HOOK (bngrw_DevReset); - INSTALL_HOOK (bngrw_ReadMifare); - INSTALL_HOOK (bngrw_fin); - INSTALL_HOOK (bngrw_GetFwVersion); - INSTALL_HOOK (bngrw_GetStationID); - INSTALL_HOOK (bngrw_GetRetryCount); - INSTALL_HOOK (bngrw_IsCmdExec); - INSTALL_HOOK (bngrw_ReqAction); - INSTALL_HOOK (bngrw_ReqAiccAuth); - INSTALL_HOOK (bngrw_ReqBeep); - INSTALL_HOOK (bngrw_ReqFwCleanup); - INSTALL_HOOK (bngrw_ReqFwVersionUp); - INSTALL_HOOK (bngrw_ReqLatchID); - INSTALL_HOOK (bngrw_ReqLed); - INSTALL_HOOK (bngrw_ReqSendMail); - INSTALL_HOOK (bngrw_ReqSendUrl); - INSTALL_HOOK (bngrw_ReqSetLedPower); - INSTALL_HOOK (bngrw_reqCancel); - INSTALL_HOOK (bngrw_Init) - INSTALL_HOOK (bngrw_attach); - INSTALL_HOOK (bngrw_reqWaitTouch); - auto configPath = std::filesystem::current_path () / "config.toml"; std::unique_ptr config_ptr (openConfig (configPath), toml_free); - toml_table_t *config = config_ptr.get (); - if (config) { - auto drum = openConfigSection (config, "drum"); + if (config_ptr) { + toml_table_t *config = config_ptr.get (); + auto drum = openConfigSection (config, "drum"); if (drum) drumWaitPeriod = readConfigInt (drum, "wait_period", drumWaitPeriod); auto taikoController = openConfigSection (config, "controller"); if (taikoController) { useTaikoController = readConfigBool (taikoController, "analog", useTaikoController); if (useTaikoController) printf ("Using analog input mode. All the keyboard drum inputs have been disabled.\n"); } + auto card = openConfigSection (config, "card_reader"); + if (card) { + bool cardEnabled = readConfigBool (card, "enabled", true); + if (cardEnabled) { + INSTALL_HOOK (bngrw_DevReset); + INSTALL_HOOK (bngrw_ReadMifare); + INSTALL_HOOK (bngrw_fin); + INSTALL_HOOK (bngrw_GetFwVersion); + INSTALL_HOOK (bngrw_GetStationID); + INSTALL_HOOK (bngrw_GetRetryCount); + INSTALL_HOOK (bngrw_IsCmdExec); + INSTALL_HOOK (bngrw_ReqAction); + INSTALL_HOOK (bngrw_ReqAiccAuth); + INSTALL_HOOK (bngrw_ReqBeep); + INSTALL_HOOK (bngrw_ReqFwCleanup); + INSTALL_HOOK (bngrw_ReqFwVersionUp); + INSTALL_HOOK (bngrw_ReqLatchID); + INSTALL_HOOK (bngrw_ReqLed); + INSTALL_HOOK (bngrw_ReqSendMail); + INSTALL_HOOK (bngrw_ReqSendUrl); + INSTALL_HOOK (bngrw_ReqSetLedPower); + INSTALL_HOOK (bngrw_reqCancel); + INSTALL_HOOK (bngrw_Init) + INSTALL_HOOK (bngrw_attach); + INSTALL_HOOK (bngrw_reqWaitTouch); + } else { + std::cout << "[Init] Card reader emulation disabled" << std::endl; + } + } } auto keyconfigPath = std::filesystem::current_path () / "keyconfig.toml"; std::unique_ptr keyconfig_ptr (openConfig (keyconfigPath), toml_free); - toml_table_t *keyconfig = keyconfig_ptr.get (); - if (keyconfig) { + if (keyconfig_ptr) { + toml_table_t *keyconfig = keyconfig_ptr.get (); SetConfigValue (keyconfig, "EXIT", &EXIT); SetConfigValue (keyconfig, "TEST", &TEST); diff --git a/src/dllmain.cpp b/src/dllmain.cpp index 91fde58..738fa17 100644 --- a/src/dllmain.cpp +++ b/src/dllmain.cpp @@ -21,10 +21,7 @@ char chipId1[33] = "00000000000000000000000000000001"; char chipId2[33] = "00000000000000000000000000000002"; HOOK (i32, ShowMouse, PROC_ADDRESS ("user32.dll", "ShowCursor"), bool) { return originalShowMouse (true); } -HOOK (i32, ExitWindows, PROC_ADDRESS ("user32.dll", "ExitWindowsEx")) { - ExitProcess (0); - return true; -} +HOOK (i32, ExitWindows, PROC_ADDRESS ("user32.dll", "ExitWindowsEx")) { ExitProcess (0); } HOOK (i32, XinputGetState, PROC_ADDRESS ("xinput9_1_0.dll", "XInputGetState")) { return ERROR_DEVICE_NOT_CONNECTED; } HOOK (i32, XinputSetState, PROC_ADDRESS ("xinput9_1_0.dll", "XInputSetState")) { return ERROR_DEVICE_NOT_CONNECTED; } @@ -46,23 +43,23 @@ HOOK (i32, ws2_getaddrinfo, PROC_ADDRESS ("ws2_32.dll", "getaddrinfo"), const ch void GetGameVersion () { wchar_t w_path[MAX_PATH]; - GetModuleFileNameW (0, w_path, MAX_PATH); + GetModuleFileNameW (nullptr, w_path, MAX_PATH); std::filesystem::path path (w_path); if (!std::filesystem::exists (path) || !path.has_filename ()) { - MessageBoxA (0, "Failed to find executable", 0, MB_OK); + MessageBoxA (nullptr, "Failed to find executable", nullptr, MB_OK); ExitProcess (0); } std::ifstream stream (path, std::ios::binary); if (!stream.is_open ()) { - MessageBoxA (0, "Failed to read executable", 0, MB_OK); + MessageBoxA (nullptr, "Failed to read executable", nullptr, MB_OK); ExitProcess (0); } - stream.seekg (0, stream.end); + stream.seekg (0, std::ifstream::end); size_t length = stream.tellg (); - stream.seekg (0, stream.beg); + stream.seekg (0, std::ifstream::beg); char *buf = (char *)calloc (length + 1, sizeof (char)); stream.read (buf, length); @@ -76,7 +73,7 @@ GetGameVersion () { case GameVersion::JP_NOV_2020: case GameVersion::JP_APR_2023: case GameVersion::CN_JUN_2023: break; - default: MessageBoxA (0, "Unknown game version", 0, MB_OK); ExitProcess (0); + default: MessageBoxA (nullptr, "Unknown game version", nullptr, MB_OK); ExitProcess (0); } } @@ -84,7 +81,7 @@ void createCard () { const char hexCharacterTable[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; char buf[64] = {0}; - srand (time (0)); + srand (time (nullptr)); std::generate (buf, buf + 20, [&] () { return hexCharacterTable[rand () % 10]; }); WritePrivateProfileStringA ("card", "accessCode1", buf, ".\\card.ini"); @@ -105,9 +102,9 @@ DllMain (HMODULE module, DWORD reason, LPVOID reserved) { std::string version = "auto"; auto configPath = std::filesystem::current_path () / "config.toml"; std::unique_ptr config_ptr (openConfig (configPath), toml_free); - toml_table_t *config = config_ptr.get (); - if (config) { - auto amauth = openConfigSection (config, "amauth"); + if (config_ptr) { + toml_table_t *config = config_ptr.get (); + auto amauth = openConfigSection (config, "amauth"); if (amauth) { server = readConfigString (amauth, "server", server); port = readConfigString (amauth, "port", port); @@ -136,14 +133,14 @@ DllMain (HMODULE module, DWORD reason, LPVOID reserved) { } else if (version == "cn_jun_2023") { gameVersion = GameVersion::CN_JUN_2023; } else { - MessageBoxA (0, "Unknown patch version", 0, MB_OK); + MessageBoxA (nullptr, "Unknown patch version", nullptr, MB_OK); ExitProcess (0); } auto pluginPath = std::filesystem::current_path () / "plugins"; if (std::filesystem::exists (pluginPath)) { - for (auto entry : std::filesystem::directory_iterator (pluginPath)) { + for (const auto &entry : std::filesystem::directory_iterator (pluginPath)) { if (entry.path ().extension () == ".dll") { auto name = entry.path ().wstring (); HMODULE hModule = LoadLibraryW (name.c_str ()); diff --git a/src/patches/cn_jun_2023.cpp b/src/patches/cn_jun_2023.cpp index 9c69e36..91298bd 100644 --- a/src/patches/cn_jun_2023.cpp +++ b/src/patches/cn_jun_2023.cpp @@ -37,7 +37,7 @@ HOOK (i64, NUSCDeviceInit, ASLR (0x140777F70), void *a1, void *a2, void *a3, voi HOOK (bool, LoadASIODriver, ASLR (0x1407808C0), void *a1, const char *a2) { auto result = originalLoadASIODriver (a1, a2); if (!result) { - MessageBoxA (0, "Failed to load ASIO driver", 0, MB_OK); + MessageBoxA (nullptr, "Failed to load ASIO driver", nullptr, MB_OK); ExitProcess (0); } return result; @@ -144,9 +144,8 @@ Init () { auto configPath = std::filesystem::current_path () / "config.toml"; std::unique_ptr config_ptr (openConfig (configPath), toml_free); - toml_table_t *config = config_ptr.get (); - if (config) { - auto patches = openConfigSection (config, "patches"); + if (config_ptr) { + auto patches = openConfigSection (config_ptr.get (), "patches"); if (patches) { auto res = openConfigSection (patches, "res"); if (res) { diff --git a/src/patches/jp_apr_2023.cpp b/src/patches/jp_apr_2023.cpp index 28e5faa..00bb60d 100644 --- a/src/patches/jp_apr_2023.cpp +++ b/src/patches/jp_apr_2023.cpp @@ -17,7 +17,7 @@ HOOK (i64, NUSCDeviceInit, ASLR (0x1407C8620), void *a1, void *a2, void *a3, voi HOOK (bool, LoadASIODriver, ASLR (0x1407D0F70), void *a1, const char *a2) { auto result = originalLoadASIODriver (a1, a2); if (!result) { - MessageBoxA (0, "Failed to load ASIO driver", 0, MB_OK); + MessageBoxA (nullptr, "Failed to load ASIO driver", nullptr, MB_OK); ExitProcess (0); } return result; @@ -68,9 +68,8 @@ Init () { auto configPath = std::filesystem::current_path () / "config.toml"; std::unique_ptr config_ptr (openConfig (configPath), toml_free); - toml_table_t *config = config_ptr.get (); - if (config) { - auto patches = openConfigSection (config, "patches"); + if (config_ptr) { + auto patches = openConfigSection (config_ptr.get (), "patches"); if (patches) { auto res = openConfigSection (patches, "res"); if (res) { diff --git a/src/patches/jp_nov_2020.cpp b/src/patches/jp_nov_2020.cpp index 27ff058..31791f7 100644 --- a/src/patches/jp_nov_2020.cpp +++ b/src/patches/jp_nov_2020.cpp @@ -26,7 +26,7 @@ HOOK (i64, NUSCDeviceInit, ASLR (0x140692E00), void *a1, void *a2, void *a3, voi HOOK (bool, LoadASIODriver, ASLR (0x14069B750), void *a1, const char *a2) { auto result = originalLoadASIODriver (a1, a2); if (!result) { - MessageBoxA (0, "Failed to load ASIO driver", 0, MB_OK); + MessageBoxA (nullptr, "Failed to load ASIO driver", nullptr, MB_OK); ExitProcess (0); } return result; @@ -72,9 +72,8 @@ Init () { auto configPath = std::filesystem::current_path () / "config.toml"; std::unique_ptr config_ptr (openConfig (configPath), toml_free); - toml_table_t *config = config_ptr.get (); - if (config) { - auto patches = openConfigSection (config, "patches"); + if (config_ptr) { + auto patches = openConfigSection (config_ptr.get (), "patches"); if (patches) { auto res = openConfigSection (patches, "res"); if (res) { diff --git a/src/patches/qr.cpp b/src/patches/qr.cpp index 77bf813..cdd9678 100644 --- a/src/patches/qr.cpp +++ b/src/patches/qr.cpp @@ -18,6 +18,7 @@ extern Keybindings QR_DATA_READ; extern Keybindings QR_IMAGE_READ; extern char accessCode1[21]; extern char accessCode2[21]; +bool qrEnabled = true; namespace patches::Qr { @@ -55,7 +56,6 @@ HOOK_DYNAMIC (i64, __fastcall, copy_data, i64, void *dest, int length) { auto configPath = std::filesystem::current_path () / "config.toml"; std::unique_ptr config_ptr (openConfig (configPath), toml_free); - toml_table_t *config = config_ptr.get (); if (gMode == Mode::Card) { memcpy (dest, accessCode.c_str (), accessCode.size () + 1); @@ -66,8 +66,8 @@ HOOK_DYNAMIC (i64, __fastcall, copy_data, i64, void *dest, int length) { u16 type = 0; std::vector songNoes; - if (config) { - auto qr = openConfigSection (config, "qr"); + if (config_ptr) { + auto qr = openConfigSection (config_ptr.get (), "qr"); if (qr) { auto data = openConfigSection (qr, "data"); if (data) { @@ -110,8 +110,8 @@ HOOK_DYNAMIC (i64, __fastcall, copy_data, i64, void *dest, int length) { } else { std::string imagePath = ""; - if (config) { - auto qr = openConfigSection (config, "qr"); + if (config_ptr) { + auto qr = openConfigSection (config_ptr.get (), "qr"); if (qr) imagePath = readConfigString (qr, "image_path", ""); } @@ -157,6 +157,7 @@ HOOK_DYNAMIC (i64, __fastcall, copy_data, i64, void *dest, int length) { void Update () { + if (!qrEnabled) return; if (gState == State::Ready) { if (IsButtonTapped (CARD_INSERT_1)) { if (gameVersion != GameVersion::CN_JUN_2023) return; @@ -188,6 +189,23 @@ Update () { void Init () { + auto configPath = std::filesystem::current_path () / "config.toml"; + std::unique_ptr config_ptr (openConfig (configPath), toml_free); + if (!config_ptr) { + std::cerr << "[Init] Config file not found" << std::endl; + return; + } + auto qr = openConfigSection (config_ptr.get (), "qr"); + if (!qr) { + std::cerr << "[Init] QR config section not found! QR emulation disabled" << std::endl; + qrEnabled = false; + return; + } + qrEnabled = readConfigBool (qr, "enabled", true); + if (!qrEnabled) { + std::cout << "[Init] QR emulation disabled" << std::endl; + return; + } SetConsoleOutputCP (CP_UTF8); auto amHandle = (u64)GetModuleHandle ("AMFrameWork.dll"); switch (gameVersion) {