mirror of
https://git.chinosk6.cn/chinosk/gkms-local.git
synced 2026-02-05 17:31:41 +00:00
generic text 有序 dump
增加文本 hook 测试 (beta版用)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace GakumasLocal::Local {
|
||||
std::unordered_map<std::string, std::string> i18nData{};
|
||||
std::unordered_map<std::string, std::string> i18nDumpData{};
|
||||
std::unordered_map<std::string, std::string> genericText{};
|
||||
std::unordered_map<std::string, std::string> genericTextDumpData{};
|
||||
std::vector<std::string> genericTextDumpData{};
|
||||
std::unordered_set<std::string> 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<std::string>& 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<char>(dumpLrcFile)), std::istreambuf_iterator<char>());
|
||||
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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user