From 78c88dae3b0af362a90c65c0d97a61944a954acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Wed, 13 Nov 2024 11:39:59 +0800 Subject: [PATCH] some --- README.md | 4 +- cpp/LunaHook/LunaHook/engine32/Alice.cpp | 2 +- cpp/LunaHook/LunaHook/engine32/Alice.h | 7 ++- cpp/LunaHook/LunaHook/engine32/TerraLunar.cpp | 59 +++++++++++++------ cpp/LunaHook/LunaHook/engine32/mono.cpp | 2 +- cpp/LunaHook/LunaHook/engine32/mono.h | 17 ++++-- cpp/LunaHook/LunaHook/engine64/mono.cpp | 2 +- cpp/LunaHook/LunaHook/engine64/mono.h | 7 ++- cpp/LunaHook/LunaHook/engines/python/Renpy.h | 41 +++++++------ .../LunaHook/engines/python/python2.cpp | 1 - cpp/version.cmake | 2 +- docs/en/useapis/ocrapi.md | 4 -- docs/en/useapis/tsapi.md | 4 -- docs/other/README_en.md | 4 +- docs/other/README_ru.md | 4 +- docs/ru/useapis/ocrapi.md | 4 -- docs/ru/useapis/tsapi.md | 4 -- docs/zh/useapis/ocrapi.md | 4 +- docs/zh/useapis/tsapi.md | 4 +- py/LunaTranslator/gui/usefulwidget.py | 2 +- py/LunaTranslator/myutils/post.py | 8 +-- .../ocrengines/{feishu.py => _feishu.py} | 0 .../translator/{feishu.py => _feishu.py} | 0 23 files changed, 105 insertions(+), 81 deletions(-) rename py/LunaTranslator/ocrengines/{feishu.py => _feishu.py} (100%) rename py/LunaTranslator/translator/{feishu.py => _feishu.py} (100%) diff --git a/README.md b/README.md index d0e905d6c1..9d70f0c5ea 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ - **HOOK** 支持使用HOOK方式获取文本,支持使用特殊码,支持自动保存游戏及HOOK、自动加载HOOK等。对于部分引擎,还支持内嵌翻译。对于不支持或支持不好的游戏,请[提交反馈](https://github.com/HIllya51/LunaTranslator/issues/new?assignees=&labels=enhancement&projects=&template=01_game_request.yaml) -- **OCR** 支持 **离线OCR** ( 除内置OCR引擎外,还支持WindowsOCR、Tessearact5、manga-ocr、WeChat/QQ OCR ) 和 **在线OCR** ( 百度、有道、飞书、讯飞、Google Lens、Google Cloud Vision、docsumo、ocrspace、Gemini、ChatGPT兼容接口 ) +- **OCR** 支持 **离线OCR** ( 除内置OCR引擎外,还支持WindowsOCR、Tessearact5、manga-ocr、WeChat/QQ OCR ) 和 **在线OCR** ( 百度、有道、讯飞、Google Lens、Google Cloud Vision、docsumo、ocrspace、Gemini、ChatGPT兼容接口 ) - **剪贴板** 支持从剪贴板中获取文本进行翻译 @@ -32,7 +32,7 @@ - **免费在线翻译** 支持使用百度、必应、谷歌、阿里、有道、彩云、搜狗、讯飞、腾讯、字节、火山、DeepL/DeepLX、papago、yandex、lingva、reverso、TranslateCom、ModernMT -- **注册在线翻译** 支持使用用户注册的 **传统翻译** ( 百度、腾讯、有道、小牛、彩云、火山、DeepL、yandex、google、ibm、Azure、飞书 ) 和 **大模型翻译** ( ChatGPT兼容接口、claude、cohere、gemini、百度千帆、腾讯混元 ) +- **注册在线翻译** 支持使用用户注册的 **传统翻译** ( 百度、腾讯、有道、小牛、彩云、火山、DeepL、yandex、google、ibm、Azure ) 和 **大模型翻译** ( ChatGPT兼容接口、claude、cohere、gemini、百度千帆、腾讯混元 ) - **离线翻译** 支持 **传统翻译** ( J北京7、金山快译、译典通、ezTrans、Sugoi、MT5 ) 和离线部署的 **大模型翻译** ( ChatGPT兼容接口、Sakura大模型 ) diff --git a/cpp/LunaHook/LunaHook/engine32/Alice.cpp b/cpp/LunaHook/LunaHook/engine32/Alice.cpp index 79388fc93a..f7619db628 100644 --- a/cpp/LunaHook/LunaHook/engine32/Alice.cpp +++ b/cpp/LunaHook/LunaHook/engine32/Alice.cpp @@ -101,7 +101,7 @@ bool InsertAliceHook() return ok; } -bool Alice::attach_function() +bool Alice::attach_function_() { return InsertAliceHook(); diff --git a/cpp/LunaHook/LunaHook/engine32/Alice.h b/cpp/LunaHook/LunaHook/engine32/Alice.h index 97215bf013..fa34fecd56 100644 --- a/cpp/LunaHook/LunaHook/engine32/Alice.h +++ b/cpp/LunaHook/LunaHook/engine32/Alice.h @@ -6,7 +6,10 @@ class Alice : public ENGINE Alice() { - check_by = CHECK_BY::ALL_TRUE; + check_by = CHECK_BY::CUSTOM; + check_by_target = [this]() + { return attach_function_(); }; }; - bool attach_function(); + bool attach_function_(); + bool attach_function() { return true; } }; \ No newline at end of file diff --git a/cpp/LunaHook/LunaHook/engine32/TerraLunar.cpp b/cpp/LunaHook/LunaHook/engine32/TerraLunar.cpp index 6a27741f39..f38d6df3d1 100644 --- a/cpp/LunaHook/LunaHook/engine32/TerraLunar.cpp +++ b/cpp/LunaHook/LunaHook/engine32/TerraLunar.cpp @@ -1,25 +1,50 @@ #include "TerraLunar.h" - -bool TerraLunar::attach_function() +namespace { - const BYTE bytes[] = { - // らくえん~あいかわらずなぼく。の場合~ - 0x8A, 0x08, - 0x81, 0xF9, 0x9F, 0x00, 0x00, 0x00, - 0x7E}; - auto addrs = Util::SearchMemory(bytes, sizeof(bytes), PAGE_EXECUTE, processStartAddress, processStopAddress); - auto succ = false; - for (auto addr : addrs) + bool H1() + { + const BYTE bytes[] = { + // らくえん~あいかわらずなぼく。の場合~ + 0x8A, 0x08, + 0x81, 0xF9, 0x9F, 0x00, 0x00, 0x00, + 0x7E}; + auto addrs = Util::SearchMemory(bytes, sizeof(bytes), PAGE_EXECUTE, processStartAddress, processStopAddress); + auto succ = false; + for (auto addr : addrs) + { + HookParam hp; + hp.address = addr; + hp.offset = get_reg(regs::eax); + hp.type = USING_STRING; + hp.filter_fun = [](TextBuffer *buffer, HookParam *hp) + { + StringFilter(buffer, "[w]", 3); + }; + succ |= NewHook(hp, "TerraLunar"); + } + return succ; + } + bool H2() { + const BYTE bytes[] = { + // https://vndb.org/v2416 + // ナースのお勉強 応用編~受けシチュ以外は絶対禁止!~ + 0X8B, 0X4D, 0X0C, 0X0F, 0XBE, 0X51, 0X01, 0XB8, 0X00, 0X01, 0X00, 0X00}; + auto addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStopAddress); + if (!addr) + return false; + addr = MemDbg::findEnclosingAlignedFunction(addr); + if (!addr) + return false; HookParam hp; hp.address = addr; - hp.offset = get_reg(regs::eax); + hp.offset = get_stack(2); hp.type = USING_STRING; - hp.filter_fun = [](TextBuffer *buffer, HookParam *hp) - { - StringFilter(buffer, "[w]", 3); - }; - succ |= NewHook(hp, "TerraLunar"); + return NewHook(hp, "AtelierD"); } - return succ; +} +bool TerraLunar::attach_function() +{ + + return H2() | H1(); } \ No newline at end of file diff --git a/cpp/LunaHook/LunaHook/engine32/mono.cpp b/cpp/LunaHook/LunaHook/engine32/mono.cpp index f042552f3f..a2db0f4d2f 100644 --- a/cpp/LunaHook/LunaHook/engine32/mono.cpp +++ b/cpp/LunaHook/LunaHook/engine32/mono.cpp @@ -50,7 +50,7 @@ bool monodll() return succ; } -bool mono::attach_function() +bool mono::attach_function_() { bool common = monocommon::hook_mono_il2cpp(); diff --git a/cpp/LunaHook/LunaHook/engine32/mono.h b/cpp/LunaHook/LunaHook/engine32/mono.h index b3efd09bbe..e180a0c240 100644 --- a/cpp/LunaHook/LunaHook/engine32/mono.h +++ b/cpp/LunaHook/LunaHook/engine32/mono.h @@ -1,10 +1,15 @@ -class mono:public ENGINE{ - public: - mono(){ - - check_by=CHECK_BY::ALL_TRUE; +class mono : public ENGINE +{ +public: + mono() + { + + check_by = CHECK_BY::CUSTOM; + check_by_target = [this]() + { return attach_function_(); }; }; - bool attach_function(); + bool attach_function_(); + bool attach_function() { return true; } }; diff --git a/cpp/LunaHook/LunaHook/engine64/mono.cpp b/cpp/LunaHook/LunaHook/engine64/mono.cpp index 6d767ee30c..3342b0b28e 100644 --- a/cpp/LunaHook/LunaHook/engine64/mono.cpp +++ b/cpp/LunaHook/LunaHook/engine64/mono.cpp @@ -81,7 +81,7 @@ namespace return suc; } } -bool mono::attach_function() +bool mono::attach_function_() { bool common = monocommon::hook_mono_il2cpp(); return common; diff --git a/cpp/LunaHook/LunaHook/engine64/mono.h b/cpp/LunaHook/LunaHook/engine64/mono.h index 333f835e61..e180a0c240 100644 --- a/cpp/LunaHook/LunaHook/engine64/mono.h +++ b/cpp/LunaHook/LunaHook/engine64/mono.h @@ -6,7 +6,10 @@ class mono : public ENGINE mono() { - check_by = CHECK_BY::ALL_TRUE; + check_by = CHECK_BY::CUSTOM; + check_by_target = [this]() + { return attach_function_(); }; }; - bool attach_function(); + bool attach_function_(); + bool attach_function() { return true; } }; diff --git a/cpp/LunaHook/LunaHook/engines/python/Renpy.h b/cpp/LunaHook/LunaHook/engines/python/Renpy.h index df85c83bc6..f552d89d03 100644 --- a/cpp/LunaHook/LunaHook/engines/python/Renpy.h +++ b/cpp/LunaHook/LunaHook/engines/python/Renpy.h @@ -1,22 +1,29 @@ -#include"python/python.h" +#include "python/python.h" -class Renpy:public ENGINE{ - public: - Renpy(){ - //使用lunatranslator启动游戏,会把cwd修改成exe所在目录,其中没有.py - check_by=CHECK_BY::ALL_TRUE; - // check_by=CHECK_BY::CUSTOM; - // check_by_target=[](){ - // //Renpy - sample game https://vndb.org/v19843 - // return Util::CheckFile(L"*.py")|| GetModuleHandleW(L"librenpython.dll"); - // }; - }; - bool attach_function(){ - #ifndef _WIN64 +class Renpy : public ENGINE +{ +public: + Renpy() + { + // 使用lunatranslator启动游戏,会把cwd修改成exe所在目录,其中没有.py + // check_by=CHECK_BY::CUSTOM; + // check_by_target=[](){ + // //Renpy - sample game https://vndb.org/v19843 + // return Util::CheckFile(L"*.py")|| GetModuleHandleW(L"librenpython.dll"); + // }; + + check_by = CHECK_BY::CUSTOM; + check_by_target = [this]() + { return attach_function_(); }; + }; + bool attach_function() { return true; } + bool attach_function_() + { +#ifndef _WIN64 return InsertRenpyHook(); - #else - return InsertRenpyHook()||InsertRenpy3Hook(); - #endif +#else + return InsertRenpyHook() || InsertRenpy3Hook(); +#endif } }; diff --git a/cpp/LunaHook/LunaHook/engines/python/python2.cpp b/cpp/LunaHook/LunaHook/engines/python/python2.cpp index 375d7addc5..3d6a366275 100644 --- a/cpp/LunaHook/LunaHook/engines/python/python2.cpp +++ b/cpp/LunaHook/LunaHook/engines/python/python2.cpp @@ -111,6 +111,5 @@ bool InsertRenpyHook() } } } - ConsoleOutput("Ren'py failed: failed to find python2X.dll"); return false; } diff --git a/cpp/version.cmake b/cpp/version.cmake index 2f1c06adcc..c33782ad1a 100644 --- a/cpp/version.cmake +++ b/cpp/version.cmake @@ -1,7 +1,7 @@ set(VERSION_MAJOR 5) set(VERSION_MINOR 58) -set(VERSION_PATCH 4) +set(VERSION_PATCH 5) set(VERSION_REVISION 0) add_definitions(-DVERSION_MAJOR=${VERSION_MAJOR}) add_definitions(-DVERSION_MINOR=${VERSION_MINOR}) diff --git a/docs/en/useapis/ocrapi.md b/docs/en/useapis/ocrapi.md index a94be53e26..cbfcdcca79 100644 --- a/docs/en/useapis/ocrapi.md +++ b/docs/en/useapis/ocrapi.md @@ -157,10 +157,6 @@ If your account has multiple applications, the last application you operated wil https://www.xfyun.cn/doc/platform/quickguide.html -#### **Feishu** - -https://open.feishu.cn/document/server-docs/ai/optical_char_recognition-v1/basic_recognize - #### **Google Cloud Vision** https://cloud.google.com/vision/docs diff --git a/docs/en/useapis/tsapi.md b/docs/en/useapis/tsapi.md index 88c2c12a8a..1dfea5874b 100644 --- a/docs/en/useapis/tsapi.md +++ b/docs/en/useapis/tsapi.md @@ -153,10 +153,6 @@ https://yandex.cloud/en/services/translate https://www.huaweicloud.com/product/nlpmt.html -#### **Feishu** - -https://open.feishu.cn/document/server-docs/ai/translation-v1/translate - #### **IBM** https://cloud.ibm.com/apidocs/language-translator diff --git a/docs/other/README_en.md b/docs/other/README_en.md index 4add386f74..5bfd46087e 100644 --- a/docs/other/README_en.md +++ b/docs/other/README_en.md @@ -20,7 +20,7 @@ - **HOOK** Supports obtaining text using HOOK methods, supports the use of special codes, supports automatic saving of games and HOOKs, automatic loading of HOOKs, etc. For some engines, it also supports embedded translation. For games that are not supported or not well supported, please [submit feedback](https://github.com/HIllya51/LunaTranslator/issues/new?assignees=&labels=enhancement&projects=&template=01_game_request.yaml) -- **OCR** supports **offline OCR** (in addition to the built-in OCR engine, it also supports WindowsOCR, Tesseract5, manga-ocr, WeChat/QQ OCR) and **online OCR** (Baidu, Youdao, Feishu, iFlytek, Google Lens, Google Cloud Vision, docsumo, ocrspace, Gemini, ChatGPT-compatible interfaces). +- **OCR** supports **offline OCR** (in addition to the built-in OCR engine, it also supports WindowsOCR, Tesseract5, manga-ocr, WeChat/QQ OCR) and **online OCR** (Baidu, Youdao, iFlytek, Google Lens, Google Cloud Vision, docsumo, ocrspace, Gemini, ChatGPT-compatible interfaces). - **Clipboard** Supports obtaining text from the clipboard for translation @@ -32,7 +32,7 @@ Supports almost all conceivable translation engines, including: - **Free Online Translation** Supports Baidu, Bing, Google, Alibaba, Youdao, Caiyun, Sogou, iFlytek, Tencent, ByteDance, Volcano, DeepL/DeepLX, papago, yandex, lingva, reverso, TranslateCom, ModernMT -- **Registered Online Translation** Supports user-registered **traditional translation** (Baidu, Tencent, Youdao, Xiaoniu, Caiyun, Volcano, DeepL, yandex, google, ibm, Azure, Lark) and **large model translation** (ChatGPT compatible interface, claude, cohere, gemini, Baidu Qianfan, Tencent Hunyuan) +- **Registered Online Translation** Supports user-registered **traditional translation** (Baidu, Tencent, Youdao, Xiaoniu, Caiyun, Volcano, DeepL, yandex, google, ibm, Azure) and **large model translation** (ChatGPT compatible interface, claude, cohere, gemini, Baidu Qianfan, Tencent Hunyuan) - **Offline Translation** Supports **traditional translation** (J Beijing 7, Kingsoft, Yidiantong, ezTrans, Sugoi, MT5) and offline deployed **large model translation** (ChatGPT compatible interface, Sakura large model) diff --git a/docs/other/README_ru.md b/docs/other/README_ru.md index 624e78b473..4a3ebd605d 100644 --- a/docs/other/README_ru.md +++ b/docs/other/README_ru.md @@ -21,7 +21,7 @@ - **HOOK** Поддерживает получение текста с использованием метода HOOK, поддерживает использование специальных кодов, поддерживает автоматическое сохранение игр и HOOK, автоматическое загрузка HOOK и т.д. Для некоторых движков также поддерживается встроенная трансляция. Для игр, которые не поддерживаются или плохо поддерживаются, пожалуйста, [отправьте обратную связь](https://github.com/HIllya51/LunaTranslator/issues/new?assignees=&labels=enhancement&projects=&template=01_game_request.yaml) -- **OCR** поддерживает **офлайн OCR** (помимо встроенного OCR-движка, также поддерживает WindowsOCR, Tesseract5, manga-ocr, WeChat/QQ OCR) и **онлайн OCR** (Baidu, Youdao, Feishu, iFlytek, Google Lens, Google Cloud Vision, docsumo, ocrspace, Gemini, совместимые интерфейсы ChatGPT). +- **OCR** поддерживает **офлайн OCR** (помимо встроенного OCR-движка, также поддерживает WindowsOCR, Tesseract5, manga-ocr, WeChat/QQ OCR) и **онлайн OCR** (Baidu, Youdao, iFlytek, Google Lens, Google Cloud Vision, docsumo, ocrspace, Gemini, совместимые интерфейсы ChatGPT). - **Буфер обмена** Поддерживает получение текста из буфера обмена для перевода @@ -33,7 +33,7 @@ - **Бесплатные онлайн переводы** Поддерживает использование Baidu, Bing, Google, Alibaba, Youdao, Caiyun, Sogou, iFlytek, Tencent, ByteDance, Volcano, DeepL/DeepLX, papago, yandex, lingva, reverso, TranslateCom, ModernMT -- **Зарегистрированные онлайн переводы** Поддерживает использование зарегистрированных пользователем **традиционных переводов** ( Baidu, Tencent, Youdao, Xiaoniu, Caiyun, Volcano, DeepL, yandex, google, ibm, Azure, Lark ) и **больших моделей перевода** ( интерфейс совместимый с ChatGPT, claude, cohere, gemini, Baidu Qianfan, Tencent Hunyuan ) +- **Зарегистрированные онлайн переводы** Поддерживает использование зарегистрированных пользователем **традиционных переводов** ( Baidu, Tencent, Youdao, Xiaoniu, Caiyun, Volcano, DeepL, yandex, google, ibm, Azure ) и **больших моделей перевода** ( интерфейс совместимый с ChatGPT, claude, cohere, gemini, Baidu Qianfan, Tencent Hunyuan ) - **Оффлайн перевод** Поддерживает **традиционный перевод** ( J Beijing 7, Kingsoft, Yidiantong, ezTrans, Sugoi, MT5 ) и оффлайн развернутый **большой модельный перевод** ( интерфейс совместимый с ChatGPT, Sakura большой модель ) diff --git a/docs/ru/useapis/ocrapi.md b/docs/ru/useapis/ocrapi.md index 6268802b48..be5bc8ee13 100644 --- a/docs/ru/useapis/ocrapi.md +++ b/docs/ru/useapis/ocrapi.md @@ -161,10 +161,6 @@ https://www.volcengine.com/docs/6790/116978 https://www.xfyun.cn/doc/platform/quickguide.html -#### **Feishu** - -https://open.feishu.cn/document/server-docs/ai/optical_char_recognition-v1/basic_recognize - #### **Google Cloud Vision** https://cloud.google.com/vision/docs diff --git a/docs/ru/useapis/tsapi.md b/docs/ru/useapis/tsapi.md index 2cad1571bf..b6cea988da 100644 --- a/docs/ru/useapis/tsapi.md +++ b/docs/ru/useapis/tsapi.md @@ -154,10 +154,6 @@ https://yandex.cloud/en/services/translate https://www.huaweicloud.com/product/nlpmt.html -#### **Feishu** - -https://open.feishu.cn/document/server-docs/ai/translation-v1/translate - #### **IBM** https://cloud.ibm.com/apidocs/language-translator diff --git a/docs/zh/useapis/ocrapi.md b/docs/zh/useapis/ocrapi.md index 22d2634392..0eb87b3d72 100644 --- a/docs/zh/useapis/ocrapi.md +++ b/docs/zh/useapis/ocrapi.md @@ -161,9 +161,9 @@ https://www.volcengine.com/docs/6790/116978 https://www.xfyun.cn/doc/platform/quickguide.html -#### **飞书** + #### **Google Cloud Vision** diff --git a/docs/zh/useapis/tsapi.md b/docs/zh/useapis/tsapi.md index 20f20211aa..a1945e174f 100644 --- a/docs/zh/useapis/tsapi.md +++ b/docs/zh/useapis/tsapi.md @@ -154,9 +154,9 @@ https://yandex.cloud/en/services/translate https://www.huaweicloud.com/product/nlpmt.html -#### **飞书** + #### **IBM** diff --git a/py/LunaTranslator/gui/usefulwidget.py b/py/LunaTranslator/gui/usefulwidget.py index e37dc91d14..cd0572c3e5 100644 --- a/py/LunaTranslator/gui/usefulwidget.py +++ b/py/LunaTranslator/gui/usefulwidget.py @@ -191,7 +191,7 @@ def dedumpmodel(self, col): def removeselectedrows(self): curr = self.currentIndex() if not curr.isValid(): - return + return [] row = curr.row() col = curr.column() skip = [] diff --git a/py/LunaTranslator/myutils/post.py b/py/LunaTranslator/myutils/post.py index 24ab855161..49a0b1c968 100644 --- a/py/LunaTranslator/myutils/post.py +++ b/py/LunaTranslator/myutils/post.py @@ -11,7 +11,7 @@ parsemayberegexreplace, safe_escape, is_ascii_symbo, - is_ascii_control + is_ascii_control, ) from myutils.config import ( postprocessconfig, @@ -191,10 +191,8 @@ def _13_fEX(line: str): def _1_f(line): - r = re.compile(r"\{(.*?)/.*?\}") - line = r.sub(lambda x: x.groups()[0], line) - r = re.compile(r"\{(.*?):.*?\}") - line = r.sub(lambda x: x.groups()[0], line) + line = re.sub(r"\{(\w+)\}(.*?)\{\/\1\}", r"\2", line) + line = re.sub(r"\{(.*?)[:/](.*?)\}", r"\1", line) return line diff --git a/py/LunaTranslator/ocrengines/feishu.py b/py/LunaTranslator/ocrengines/_feishu.py similarity index 100% rename from py/LunaTranslator/ocrengines/feishu.py rename to py/LunaTranslator/ocrengines/_feishu.py diff --git a/py/LunaTranslator/translator/feishu.py b/py/LunaTranslator/translator/_feishu.py similarity index 100% rename from py/LunaTranslator/translator/feishu.py rename to py/LunaTranslator/translator/_feishu.py