diff --git a/app/src/main/cpp/GakumasLocalify/Hook.cpp b/app/src/main/cpp/GakumasLocalify/Hook.cpp index 389f03c..e01b143 100644 --- a/app/src/main/cpp/GakumasLocalify/Hook.cpp +++ b/app/src/main/cpp/GakumasLocalify/Hook.cpp @@ -226,7 +226,12 @@ namespace GakumasLocal::HookMain { return; } Local::DumpI18nItem(key->ToString(), value->ToString()); - I18nHelper_SetValue_Orig(_this, key, value); + if (Config::textTest) { + I18nHelper_SetValue_Orig(_this, key, Il2cppString::New("[I18]" + value->ToString())); + } + else { + I18nHelper_SetValue_Orig(_this, key, value); + } } void* fontCache = nullptr; @@ -286,8 +291,12 @@ namespace GakumasLocal::HookMain { return TMP_Text_set_text_Orig(_this, UnityResolve::UnityType::String::New(transText)); } - // TMP_Text_set_text_Orig(_this, UnityResolve::UnityType::String::New("[TS]" + text->ToString())); - TMP_Text_set_text_Orig(_this, text); + if (Config::textTest) { + TMP_Text_set_text_Orig(_this, UnityResolve::UnityType::String::New("[TS]" + text->ToString())); + } + else { + TMP_Text_set_text_Orig(_this, text); + } static auto set_font = Il2cppUtils::GetMethod("Unity.TextMeshPro.dll", "TMPro", "TMP_Text", "set_font"); @@ -308,7 +317,12 @@ namespace GakumasLocal::HookMain { //Log::InfoFmt("TextMeshProUGUI_Awake: %s", currText->ToString().c_str()); std::string transText; if (Local::GetGenericText(currText->ToString(), &transText)) { - TMP_Text_set_text_Orig(_this, UnityResolve::UnityType::String::New(transText)); + if (Config::textTest) { + TMP_Text_set_text_Orig(_this, UnityResolve::UnityType::String::New("[TA]" + transText)); + } + else { + TMP_Text_set_text_Orig(_this, UnityResolve::UnityType::String::New(transText)); + } } } @@ -317,7 +331,7 @@ namespace GakumasLocal::HookMain { TextMeshProUGUI_Awake_Orig(_this, method); } - // TODO 文本未hook完整 思路:从tips下手... + // TODO 文本未hook完整 DEFINE_HOOK(void, TextField_set_value, (void* _this, Il2cppString* value)) { Log::DebugFmt("TextField_set_value: %s", value->ToString().c_str()); TextField_set_value_Orig(_this, value); @@ -326,7 +340,6 @@ namespace GakumasLocal::HookMain { DEFINE_HOOK(Il2cppString*, OctoCaching_GetResourceFileName, (void* data, void* method)) { auto ret = OctoCaching_GetResourceFileName_Orig(data, method); //Log::DebugFmt("OctoCaching_GetResourceFileName: %s", ret->ToString().c_str()); - return ret; } diff --git a/app/src/main/cpp/GakumasLocalify/Local.cpp b/app/src/main/cpp/GakumasLocalify/Local.cpp index c48014d..be981ca 100644 --- a/app/src/main/cpp/GakumasLocalify/Local.cpp +++ b/app/src/main/cpp/GakumasLocalify/Local.cpp @@ -14,7 +14,7 @@ namespace GakumasLocal::Local { std::unordered_map i18nData{}; std::unordered_map i18nDumpData{}; std::unordered_map genericText{}; - std::unordered_map genericTextDumpData{}; + std::vector genericTextDumpData{}; std::unordered_set translatedText{}; std::filesystem::path GetBasePath() { @@ -76,6 +76,36 @@ namespace GakumasLocal::Local { } } + void DumpVectorDataToJson(const std::filesystem::path& dumpBasePath, const std::filesystem::path& fileName, + const std::vector& vec) { + const auto dumpFilePath = dumpBasePath / fileName; + try { + if (!is_directory(dumpBasePath)) { + std::filesystem::create_directories(dumpBasePath); + } + if (!std::filesystem::exists(dumpFilePath)) { + std::ofstream dumpWriteLrcFile(dumpFilePath, std::ofstream::out); + dumpWriteLrcFile << "{}"; + dumpWriteLrcFile.close(); + } + + std::ifstream dumpLrcFile(dumpFilePath); + std::string fileContent((std::istreambuf_iterator(dumpLrcFile)), std::istreambuf_iterator()); + dumpLrcFile.close(); + auto fileData = nlohmann::ordered_json::parse(fileContent); + for (const auto& i : vec) { + fileData[i] = i; + } + const auto newStr = fileData.dump(4, 32, false); + std::ofstream dumpWriteLrcFile(dumpFilePath, std::ofstream::out); + dumpWriteLrcFile << newStr.c_str(); + dumpWriteLrcFile.close(); + } + catch (std::exception& e) { + Log::ErrorFmt("DumpVectorDataToJson %s failed: %s", dumpFilePath.c_str(), e.what()); + } + } + void LoadData() { static auto localizationFile = GetBasePath() / "local-files" / "localization.json"; static auto genericFile = GetBasePath() / "local-files" / "generic.json"; @@ -155,14 +185,18 @@ namespace GakumasLocal::Local { if (translatedText.contains(origText)) return false; - genericTextDumpData.emplace(origText, origText); + if (std::find(genericTextDumpData.begin(), genericTextDumpData.end(), "") != genericTextDumpData.end()) { + return false; + } + + genericTextDumpData.push_back(origText); static auto dumpBasePath = GetBasePath() / "dump-files"; if (inDumpGeneric) return false; inDumpGeneric = true; std::thread([](){ std::this_thread::sleep_for(std::chrono::seconds(5)); - DumpMapDataToJson(dumpBasePath, "generic.json", genericTextDumpData); + DumpVectorDataToJson(dumpBasePath, "generic.json", genericTextDumpData); genericTextDumpData.clear(); inDumpGeneric = false; }).detach(); diff --git a/app/src/main/cpp/GakumasLocalify/config/Config.cpp b/app/src/main/cpp/GakumasLocalify/config/Config.cpp index b2f0c13..3df4cde 100644 --- a/app/src/main/cpp/GakumasLocalify/config/Config.cpp +++ b/app/src/main/cpp/GakumasLocalify/config/Config.cpp @@ -6,6 +6,7 @@ namespace GakumasLocal::Config { bool isConfigInit = false; bool enabled = true; + bool textTest = false; bool enableFreeCamera = false; int targetFrameRate = 0; bool unlockAllLive = false; @@ -29,6 +30,7 @@ namespace GakumasLocal::Config { #define GetConfigItem(name) if (config.contains(#name)) name = config[#name] GetConfigItem(enabled); + GetConfigItem(textTest); GetConfigItem(targetFrameRate); GetConfigItem(enableFreeCamera); GetConfigItem(unlockAllLive); diff --git a/app/src/main/cpp/GakumasLocalify/config/Config.hpp b/app/src/main/cpp/GakumasLocalify/config/Config.hpp index 0de274e..92d9d2d 100644 --- a/app/src/main/cpp/GakumasLocalify/config/Config.hpp +++ b/app/src/main/cpp/GakumasLocalify/config/Config.hpp @@ -6,6 +6,7 @@ namespace GakumasLocal::Config { extern bool isConfigInit; extern bool enabled; + extern bool textTest; extern bool enableFreeCamera; extern int targetFrameRate; extern bool unlockAllLive; diff --git a/app/src/main/java/io/github/chinosk/gakumas/localify/MainActivity.kt b/app/src/main/java/io/github/chinosk/gakumas/localify/MainActivity.kt index 323dd79..b93feda 100644 --- a/app/src/main/java/io/github/chinosk/gakumas/localify/MainActivity.kt +++ b/app/src/main/java/io/github/chinosk/gakumas/localify/MainActivity.kt @@ -20,6 +20,7 @@ import java.io.File interface ConfigListener { fun onClickStartGame() fun onEnabledChanged(value: Boolean) + fun onTextTestChanged(value: Boolean) fun onEnableFreeCameraChanged(value: Boolean) fun onTargetFpsChanged(s: CharSequence, start: Int, before: Int, count: Int) fun onUnlockAllLiveChanged(value: Boolean) @@ -92,6 +93,11 @@ class MainActivity : AppCompatActivity(), ConfigListener { saveConfig() } + override fun onTextTestChanged(value: Boolean) { + binding.config!!.textTest = value + saveConfig() + } + override fun onEnableFreeCameraChanged(value: Boolean) { binding.config!!.enableFreeCamera = value saveConfig() diff --git a/app/src/main/java/io/github/chinosk/gakumas/localify/models/GakumasConfig.kt b/app/src/main/java/io/github/chinosk/gakumas/localify/models/GakumasConfig.kt index 9f2ab3f..64f38d0 100644 --- a/app/src/main/java/io/github/chinosk/gakumas/localify/models/GakumasConfig.kt +++ b/app/src/main/java/io/github/chinosk/gakumas/localify/models/GakumasConfig.kt @@ -4,6 +4,7 @@ import androidx.databinding.BaseObservable data class GakumasConfig ( var enabled: Boolean = true, + var textTest: Boolean = false, var enableFreeCamera: Boolean = false, var targetFrameRate: Int = 0, var unlockAllLive: Boolean = false, diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 2069330..1eec71a 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -64,6 +64,19 @@ android:text="@string/enable_plugin" /> + + + + +