Skip to content

Commit

Permalink
优化 dump;修复歌词本地化失效
Browse files Browse the repository at this point in the history
  • Loading branch information
chinosk6 committed Jan 19, 2024
1 parent 566d5b9 commit c449a65
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
25 changes: 24 additions & 1 deletion src/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<decltype(LiveMVView_UpdateLyrics_hook)*>(LiveMVView_UpdateLyrics_orig)(_this, il2cpp_string_new(newText.c_str()));
return reinterpret_cast<decltype(LiveMVView_UpdateLyrics_hook)*>(LiveMVView_UpdateLyrics_orig)(_this, il2cpp_string_new(newText.c_str()));
}

std::pair<std::wstring, std::string> 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<decltype(TimelineController_SetLyric_hook)*>(TimelineController_SetLyric_orig)(_this, il2cpp_string_new(newText.c_str()));
}

void* TMP_Text_set_text_orig;
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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");
Expand Down
8 changes: 4 additions & 4 deletions src/local/local.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -162,8 +162,8 @@ namespace SCLocal {
std::ifstream dumpLrcFile(dumpFilePath);
std::string fileContent((std::istreambuf_iterator<char>(dumpLrcFile)), std::istreambuf_iterator<char>());
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();
Expand Down Expand Up @@ -193,7 +193,7 @@ namespace SCLocal {
}
else {
if (g_dump_untrans_lyrics) {
dumpGenericText(lrcStr, "lyrics.json");
dumpGenericText(lrcStr, "lyrics.json", true);
}
}
return lrcStr;
Expand Down

0 comments on commit c449a65

Please sign in to comment.