From 42847d9da47a06ec3e42fc04660624a196b37a69 Mon Sep 17 00:00:00 2001 From: Ji O Date: Tue, 28 Feb 2023 01:22:37 +0900 Subject: [PATCH] Show warning message box when JSON parsing fails (#7) --- src/VERSIONINFO.rc | 12 ++++++------ src/hook.cpp | 12 ++++++++++-- src/main.cpp | 9 +++++++++ src/stdinclude.hpp | 3 +++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/VERSIONINFO.rc b/src/VERSIONINFO.rc index 247fb01..b90207f 100644 --- a/src/VERSIONINFO.rc +++ b/src/VERSIONINFO.rc @@ -7,8 +7,8 @@ // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,17,0,0 - PRODUCTVERSION 1,17,0,0 + FILEVERSION 1,17,1,0 + PRODUCTVERSION 1,17,1,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x1L @@ -25,19 +25,19 @@ BEGIN BEGIN VALUE "LegalCopyright", "Copyright © Ji O Kim\0" VALUE "FileDescription", "우마무스메 현지화 패치\0" - VALUE "FileVersion", "1.17.0.0\0" + VALUE "FileVersion", "1.17.1.0\0" VALUE "InternalName", "umamusume-localify\0" VALUE "ProductName", "Umamusume Localify\0" - VALUE "ProductVersion", "1.17.0\0" + VALUE "ProductVersion", "1.17.1\0" END BLOCK "000004b0" BEGIN VALUE "LegalCopyright", "Copyright © Ji O Kim\0" VALUE "FileDescription", "Localization patch for Umamusume\0" - VALUE "FileVersion", "1.17.0.0\0" + VALUE "FileVersion", "1.17.1.0\0" VALUE "InternalName", "umamusume-localify\0" VALUE "ProductName", "Umamusume Localify\0" - VALUE "ProductVersion", "1.17.0\0" + VALUE "ProductVersion", "1.17.1\0" END END BLOCK "VarFileInfo" diff --git a/src/hook.cpp b/src/hook.cpp index 8ba066b..86d64b2 100644 --- a/src/hook.cpp +++ b/src/hook.cpp @@ -57,9 +57,17 @@ namespace MH_DisableHook(LoadLibraryW); MH_RemoveHook(LoadLibraryW); - if (!g_custom_title_name.empty()) + auto hWnd = FindWindowW(L"UnityWndClass", L"umamusume"); + if (hWnd) { - SetWindowText(GetActiveWindow(), local::wide_acp(local::u8_wide(g_custom_title_name)).data()); + if (!g_custom_title_name.empty()) + { + SetWindowText(hWnd, local::wide_acp(local::u8_wide(g_custom_title_name)).data()); + } + if (has_json_parse_error) + { + MessageBox(hWnd, json_parse_error_msg.data(), "Umamusume Localify", MB_OK | MB_ICONWARNING); + } } // use original function beacuse we have unhooked that diff --git a/src/main.cpp b/src/main.cpp index f227ad1..f8a15f6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ #include +#include extern bool init_hook(); extern void uninit_hook(); @@ -36,6 +37,9 @@ int g_cyspring_update_mode = -1; bool g_hide_now_loading = false; std::string text_id_dict; +bool has_json_parse_error = false; +std::string json_parse_error_msg; + namespace { void create_debug_console() @@ -255,6 +259,11 @@ namespace dicts.emplace_back(dict); } } + } else { + has_json_parse_error = true; + std::stringstream str_stream; + str_stream << "JSON parse error: " << GetParseError_En(document.GetParseError()) << " (" << document.GetErrorOffset() << ")"; + json_parse_error_msg = str_stream.str(); } config_stream.close(); diff --git a/src/stdinclude.hpp b/src/stdinclude.hpp index d80c26b..9a237f0 100644 --- a/src/stdinclude.hpp +++ b/src/stdinclude.hpp @@ -68,6 +68,9 @@ extern bool g_character_system_text_caption; extern int g_cyspring_update_mode; extern bool g_hide_now_loading; +extern bool has_json_parse_error; +extern std::string json_parse_error_msg; + namespace { // copy-pasted from https://stackoverflow.com/questions/3418231/replace-part-of-a-string-with-another-string void replaceAll(std::string& str, const std::string& from, const std::string& to)