From c449a652d9ca9e304fe072748ad0568b80461b63 Mon Sep 17 00:00:00 2001 From: chinosk <2248589280@qq.com> Date: Fri, 19 Jan 2024 18:27:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20dump=EF=BC=9B=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E6=AD=8C=E8=AF=8D=E6=9C=AC=E5=9C=B0=E5=8C=96=E5=A4=B1?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hook.cpp | 25 ++++++++++++++++++++++++- src/local/local.cpp | 8 ++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/hook.cpp b/src/hook.cpp index dfc2441..103046b 100644 --- a/src/hook.cpp +++ b/src/hook.cpp @@ -384,7 +384,25 @@ namespace void LiveMVView_UpdateLyrics_hook(void* _this, Il2CppString* text) { const std::wstring origWstr(text->start_char); const auto newText = SCLocal::getLyricsTrans(origWstr); - reinterpret_cast(LiveMVView_UpdateLyrics_orig)(_this, il2cpp_string_new(newText.c_str())); + return reinterpret_cast(LiveMVView_UpdateLyrics_orig)(_this, il2cpp_string_new(newText.c_str())); + } + + std::pair lastLrc{}; + void* TimelineController_SetLyric_orig; + void TimelineController_SetLyric_hook(void* _this, Il2CppString* text) { + const std::wstring origWstr(text->start_char); + std::string newText = ""; + if (!origWstr.empty()) { + if (lastLrc.first.compare(origWstr) != 0) { + newText = SCLocal::getLyricsTrans(origWstr); + lastLrc.first = origWstr; + lastLrc.second = newText; + } + else { + newText = lastLrc.second; + } + } + return reinterpret_cast(TimelineController_SetLyric_orig)(_this, il2cpp_string_new(newText.c_str())); } void* TMP_Text_set_text_orig; @@ -1005,6 +1023,10 @@ namespace "PRISM.Legacy.dll", "PRISM.Live", "LiveMVView", "UpdateLyrics", 1 ); + auto TimelineController_SetLyric_addr = il2cpp_symbols::get_method_pointer( + "PRISM.Legacy.dll", "PRISM", + "TimelineController", "SetLyric", 1 + ); auto get_baseCamera_addr = il2cpp_symbols::get_method_pointer( "PRISM.Legacy.dll", "PRISM", @@ -1085,6 +1107,7 @@ namespace ADD_HOOK(LocalizationManager_GetTextOrNull, "LocalizationManager_GetTextOrNull at %p"); ADD_HOOK(get_NeedsLocalization, "get_NeedsLocalization at %p"); ADD_HOOK(LiveMVView_UpdateLyrics, "LiveMVView_UpdateLyrics at %p"); + ADD_HOOK(TimelineController_SetLyric, "TimelineController_SetLyric at %p"); ADD_HOOK(get_baseCamera, "get_baseCamera at %p"); ADD_HOOK(Unity_set_pos_injected, "Unity_set_pos_injected at %p"); ADD_HOOK(Unity_get_pos_injected, "Unity_get_pos_injected at %p"); diff --git a/src/local/local.cpp b/src/local/local.cpp index eb1de14..807a1a9 100644 --- a/src/local/local.cpp +++ b/src/local/local.cpp @@ -145,7 +145,7 @@ namespace SCLocal { return false; } - void dumpGenericText(const std::string& dumpStr, const char* fileName) { + void dumpGenericText(const std::string& dumpStr, const char* fileName, bool withOrigText = false) { try { const std::filesystem::path dumpBasePath("dumps"); const auto dumpFilePath = dumpBasePath / fileName; @@ -162,8 +162,8 @@ namespace SCLocal { std::ifstream dumpLrcFile(dumpFilePath); std::string fileContent((std::istreambuf_iterator(dumpLrcFile)), std::istreambuf_iterator()); dumpLrcFile.close(); - auto fileData = nlohmann::json::parse(fileContent); - fileData[dumpStr] = ""; + auto fileData = nlohmann::ordered_json::parse(fileContent); + fileData[dumpStr] = withOrigText ? dumpStr : ""; const auto newStr = fileData.dump(4, 32, false); std::ofstream dumpWriteLrcFile(dumpFilePath, std::ofstream::out); dumpWriteLrcFile << newStr.c_str(); @@ -193,7 +193,7 @@ namespace SCLocal { } else { if (g_dump_untrans_lyrics) { - dumpGenericText(lrcStr, "lyrics.json"); + dumpGenericText(lrcStr, "lyrics.json", true); } } return lrcStr;