From 78b3872334e11901d218faa867b0af80c2da881b Mon Sep 17 00:00:00 2001 From: Ji O Date: Fri, 31 May 2024 00:24:17 +0900 Subject: [PATCH] Change charset to unicode --- premake5.lua | 2 +- src/hook.cpp | 60 ++++++++++++++++++++++----------------------- src/main.cpp | 6 ++--- src/stdinclude.hpp | 6 ++--- src/steam/steam.cpp | 8 +++--- 5 files changed, 40 insertions(+), 42 deletions(-) diff --git a/premake5.lua b/premake5.lua index f842c2d..90bd8a0 100644 --- a/premake5.lua +++ b/premake5.lua @@ -52,7 +52,7 @@ workspace "umamusume-localify" staticruntime "On" editandcontinue "Off" warnings "Off" - characterset "ASCII" + characterset "Unicode" cppdialect "C++20" cdialect "C17" diff --git a/src/hook.cpp b/src/hook.cpp index a7a4105..b440b53 100644 --- a/src/hook.cpp +++ b/src/hook.cpp @@ -191,7 +191,7 @@ namespace void init_il2cpp(bool attachIl2CppThread = false) { - il2cpp_symbols::init(GetModuleHandle("GameAssembly.dll")); + il2cpp_symbols::init(GetModuleHandleW(L"GameAssembly.dll")); void* t = nullptr; @@ -221,7 +221,7 @@ namespace MH_CreateHook(set_resolution, set_resolution_hook, &set_resolution_orig); MH_EnableHook(set_resolution); - KillProcessByName("ucldr_Umamusume_KR_loader_x64.exe"); + KillProcessByName(L"ucldr_Umamusume_KR_loader_x64.exe"); auto UncheaterInit_OnApplicationPause_addr = il2cpp_symbols::get_method_pointer( "umamusume.dll", @@ -956,9 +956,9 @@ namespace EnumWindows(reinterpret_cast(*([](HWND hWnd, LPARAM lParam) { TCHAR buf[MAX_CLASS_NAME]; - GetClassName(hWnd, (LPTSTR)&buf, MAX_CLASS_NAME); + GetClassNameW(hWnd, (LPTSTR)&buf, MAX_CLASS_NAME); - if (string(buf).find("UnityWndClass") != string::npos) + if (wstring(buf).find(L"UnityWndClass") != wstring::npos) { DWORD dwWndProcID = 0; GetWindowThreadProcessId(hWnd, &dwWndProcID); @@ -1036,7 +1036,7 @@ namespace if (!doc.HasParseError()) { - auto params = doc.GetArray()[2].GetObjectA(); + auto params = doc.GetArray()[2].GetObjectW(); auto display = display_get_main(); auto systemHeight = get_system_height(display); @@ -1162,7 +1162,7 @@ namespace } if (has_json_parse_error) { - MessageBox(hWnd, json_parse_error_msg.data(), "Umamusume Localify", MB_OK | MB_ICONWARNING); + MessageBoxW(hWnd, local::u8_wide(json_parse_error_msg).data(), L"Umamusume Localify", MB_OK | MB_ICONWARNING); } } @@ -1272,7 +1272,7 @@ namespace if (code_map.HasMember("!common")) { - auto commonMap = code_map["!common"].GetObjectA(); + auto commonMap = code_map["!common"].GetObjectW(); if (commonMap.HasMember(name)) { auto field = il2cpp_class_get_field_from_name(klass, commonMap[name].GetString()); @@ -1288,7 +1288,7 @@ namespace return il2cpp_class_get_field_from_name(klass, name); } - auto classMap = code_map[className.data()].GetObjectA(); + auto classMap = code_map[className.data()].GetObjectW(); if (classMap.HasMember(name)) { @@ -1317,7 +1317,7 @@ namespace if (classMap.HasMember("!extends")) { auto parentName = classMap["!extends"].GetString(); - auto parentMap = code_map[parentName].GetObjectA(); + auto parentMap = code_map[parentName].GetObjectW(); auto parentClass = klass->parent; if (parentMap.HasMember((name + ".index"s).data())) @@ -7887,7 +7887,7 @@ namespace il2cpp_class_get_method_from_name_type(dialogData->klass, "AddDestroyCallback", 1)->methodPointer(dialogData, onDestroy); il2cpp_symbols::get_method_pointer("umamusume.dll", "Gallop", "DialogManager", "PushDialog", 1)(dialogData); - }); + }); dialogData = reinterpret_cast("umamusume.dll", "Gallop", "DialogManager", "PushDialog", 1)(dialogData); - } + } void OpenLiveSettings() { @@ -10318,7 +10318,7 @@ namespace if (document.HasMember("result_code") && document["result_code"].GetInt() == 100) { - return string(document["data"].GetObjectA()["url"].GetString()); + return string(document["data"].GetObjectW()["url"].GetString()); } return ""; @@ -10471,7 +10471,7 @@ namespace if (document.HasMember("result_code") && document["result_code"].GetInt() == 100) { - return string(document["data"].GetObjectA()["execute_args"].GetString()); + return string(document["data"].GetObjectW()["execute_args"].GetString()); } else if (document.HasMember("error") && document["error"].IsString()) { @@ -10542,18 +10542,18 @@ namespace wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; - wcex.hIcon = LoadIcon(hInstance, reinterpret_cast(IDI_APP_ICON)); + wcex.hIcon = LoadIconW(hInstance, reinterpret_cast(IDI_APP_ICON)); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = reinterpret_cast(COLOR_WINDOW + 1); wcex.lpszMenuName = NULL; - wcex.lpszClassName = "WebViewWindow"; - wcex.hIconSm = LoadIcon(wcex.hInstance, reinterpret_cast(IDI_APP_ICON)); + wcex.lpszClassName = L"WebViewWindow"; + wcex.hIconSm = LoadIconW(wcex.hInstance, reinterpret_cast(IDI_APP_ICON)); RegisterClassEx(&wcex); SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE); - const auto hWnd = CreateWindowEx(NULL, "WebViewWindow", "Login DMM", + const auto hWnd = CreateWindowExW(NULL, L"WebViewWindow", L"Login DMM", WS_OVERLAPPEDWINDOW ^ WS_MAXIMIZEBOX ^ WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 900, 900, @@ -10807,8 +10807,8 @@ namespace char* buf1 = reinterpret_cast(data) + kIl2CppSizeOfArray; memcpy(buf1, modified.data(), modified.size()); + } } - } #endif return reinterpret_cast(UploadHandlerRaw_Create_orig)(self, data); @@ -10841,14 +10841,14 @@ namespace char* buf1 = reinterpret_cast(data) + kIl2CppSizeOfArray; memcpy(buf1, modified.data(), modified.size()); + } } - } #endif MsgPackData::ReadResponse(buf, data->max_length); return data; -} + } void* HttpHelper_CompressRequest_orig = nullptr; @@ -10875,8 +10875,8 @@ namespace char* buf1 = reinterpret_cast(data) + kIl2CppSizeOfArray; memcpy(buf1, modified.data(), modified.size()); + } } - } #endif return reinterpret_cast(HttpHelper_CompressRequest_orig)(data); @@ -10909,8 +10909,8 @@ namespace char* buf1 = reinterpret_cast(data) + kIl2CppSizeOfArray; memcpy(buf1, modified.data(), modified.size()); + } } - } #endif MsgPackData::ReadResponse(buf, data->max_length); @@ -11038,7 +11038,7 @@ namespace printf("Trying to patch GameAssembly.dll...\n"); - auto il2cpp_module = GetModuleHandle("GameAssembly.dll"); + auto il2cpp_module = GetModuleHandleW(L"GameAssembly.dll"); // load il2cpp exported functions il2cpp_symbols::init(il2cpp_module); @@ -13062,7 +13062,7 @@ BOOL WINAPI HttpSendRequestW_hook( { if (doc.IsObject() && doc.HasMember("os")) { - doc.GetObjectA()["os"].SetString(rapidjson::StringRef("android")); + doc.GetObjectW()["os"].SetString(rapidjson::StringRef("android")); rapidjson::StringBuffer buffer; buffer.Clear(); @@ -13253,7 +13253,6 @@ FindFirstFileExW_hook( return result; } - bool init_hook_base() { if (mh_inited) @@ -13281,12 +13280,11 @@ bool init_hook_base() #endif } - MH_CreateHook(FindFirstFileExW, FindFirstFileExW_hook, &FindFirstFileExW_orig); - MH_EnableHook(FindFirstFileExW); + MH_CreateHook(FindFirstFileExW, FindFirstFileExW_hook, &FindFirstFileExW_orig); + MH_EnableHook(FindFirstFileExW); - MH_CreateHook(FindNextFileW, FindNextFileW_hook, &FindNextFileW_orig); - MH_EnableHook(FindNextFileW); -} + MH_CreateHook(FindNextFileW, FindNextFileW_hook, &FindNextFileW_orig); + MH_EnableHook(FindNextFileW); if (!g_allow_delete_cookie && Game::CurrentGameRegion == Game::Region::KOR) { @@ -13297,7 +13295,7 @@ bool init_hook_base() MH_CreateHook(LoadLibraryW, load_library_w_hook, &load_library_w_orig); MH_EnableHook(LoadLibraryW); - auto UnityPlayer = GetModuleHandle("UnityPlayer.dll"); + auto UnityPlayer = GetModuleHandleW(L"UnityPlayer.dll"); auto UnityMain_addr = GetProcAddress(UnityPlayer, "UnityMain"); MH_CreateHook(UnityMain_addr, UnityMain_hook, &UnityMain_orig); diff --git a/src/main.cpp b/src/main.cpp index 2f4be1f..b5cf5bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -83,7 +83,7 @@ namespace _ = freopen("CONOUT$", "w", stderr); _ = freopen("CONIN$", "r", stdin); - SetConsoleTitle("Umamusume - Debug Console"); + SetConsoleTitleW(L"Umamusume - Debug Console"); // set this to avoid turn japanese texts into question mark SetConsoleOutputCP(CP_UTF8); @@ -539,9 +539,9 @@ void DoStopSvc() // Get a handle to the service. - schService = OpenService( + schService = OpenServiceW( schSCManager, // SCM database - "ucldr_Umamusume_KR", // name of service + L"ucldr_Umamusume_KR", // name of service SERVICE_STOP | SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS); diff --git a/src/stdinclude.hpp b/src/stdinclude.hpp index 69f0483..c3ce451 100644 --- a/src/stdinclude.hpp +++ b/src/stdinclude.hpp @@ -141,15 +141,15 @@ namespace { return fRet; } - void KillProcessByName(const char* filename) + void KillProcessByName(const wchar_t* filename) { HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL); PROCESSENTRY32 pEntry; pEntry.dwSize = sizeof(pEntry); - BOOL hRes = Process32First(hSnapShot, &pEntry); + BOOL hRes = Process32FirstW(hSnapShot, &pEntry); while (hRes) { - if (strcmp(pEntry.szExeFile, filename) == 0) + if (wcscmp(pEntry.szExeFile, filename) == 0) { HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0, (DWORD)pEntry.th32ProcessID); diff --git a/src/steam/steam.cpp b/src/steam/steam.cpp index 99caa37..3c9d1d8 100644 --- a/src/steam/steam.cpp +++ b/src/steam/steam.cpp @@ -35,10 +35,10 @@ namespace if (steam_path.empty()) return; - LoadLibrary((steam_path / "tier0_s64.dll").string().data()); - LoadLibrary((steam_path / "vstdlib_s64.dll").string().data()); - steam_overlay_module = LoadLibrary((steam_path / "gameoverlayrenderer64.dll").string().data()); - steam_client_module = LoadLibrary((steam_path / "steamclient64.dll").string().data()); + LoadLibraryA((steam_path / "tier0_s64.dll").string().data()); + LoadLibraryA((steam_path / "vstdlib_s64.dll").string().data()); + steam_overlay_module = LoadLibraryA((steam_path / "gameoverlayrenderer64.dll").string().data()); + steam_client_module = LoadLibraryA((steam_path / "steamclient64.dll").string().data()); if (!steam_client_module) return;