This commit is contained in:
恍兮惚兮 2024-12-23 14:24:12 +08:00
parent 006c6b0f0e
commit ddbe526e27
15 changed files with 370 additions and 67 deletions

View File

@ -276,6 +276,20 @@ namespace
{ {
CharFilter(buffer, '\n'); CharFilter(buffer, '\n');
} }
void PCSG01068(TextBuffer *buffer, HookParam *hp)
{
StringCharReplacer(buffer, "\\\\", 2, '\n');
CharFilter(buffer, '\\');
auto s = buffer->viewA();
if (endWith(s, u8"。!"))
buffer->from(s.substr(0, s.size() - 1));
}
void PCSG01167(TextBuffer *buffer, HookParam *hp)
{
auto s = buffer->strA();
s = std::regex_replace(s, std::regex(u8R"(<(.*?)>(.*?)\|)"), "$2");
buffer->from(s);
}
void PCSG00917(TextBuffer *buffer, HookParam *hp) void PCSG00917(TextBuffer *buffer, HookParam *hp)
{ {
auto s = buffer->strA(); auto s = buffer->strA();
@ -772,6 +786,15 @@ namespace
{0x8001701C, {CODEC_UTF8, 1, 0, 0, PCSG00787, "PCSG00561"}}, {0x8001701C, {CODEC_UTF8, 1, 0, 0, PCSG00787, "PCSG00561"}},
// ハートの国のアリスWonderful Wonder World // ハートの国のアリスWonderful Wonder World
{0x8100F0CA, {CODEC_UTF8, 1, 0, 0, PCSG00787, "PCSG00614"}}, // 手动解压 {0x8100F0CA, {CODEC_UTF8, 1, 0, 0, PCSG00787, "PCSG00614"}}, // 手动解压
{0x800173F4, {CODEC_UTF8, 1, 0, 0, PCSG00787, "PCSG00614"}},
// 新装版魔法使いとご主人様Wizard and The Master
{0x8001733C, {CODEC_UTF8, 1, 0, 0, PCSG00787, "PCSG00580"}},
// 円環のメモーリア -カケラ灯し-
{0x80029AB2, {0, 0, 0, 0, PCSG01167, "PCSG01167"}},
// ネオ アンジェリーク 天使の涙
{0x8005426C, {CODEC_UTF8, 0, 0, 0, PCSG01068, "PCSG01068"}},
// スカーレッドライダーゼクス Rev.
{0x800BEE38, {CODEC_UTF8, 0, 0, 0, PCSG00787, "PCSG00745"}},
}; };
return 1; return 1;
}(); }();

View File

@ -538,10 +538,8 @@ int atlaswmain(int argc, wchar_t *argv[])
HANDLE hPipe = CreateNamedPipe(argv[1], PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 65535, 65535, NMPWAIT_WAIT_FOREVER, 0); HANDLE hPipe = CreateNamedPipe(argv[1], PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 65535, 65535, NMPWAIT_WAIT_FOREVER, 0);
SetEvent(CreateEvent(&allAccess, FALSE, FALSE, argv[2])); SetEvent(CreateEvent(&allAccess, FALSE, FALSE, argv[2]));
if (ConnectNamedPipe(hPipe, NULL) != NULL) if (!ConnectNamedPipe(hPipe, NULL))
{ return 0;
DWORD len = 0;
}
while (true) while (true)
{ {
wchar_t src[4096] = {0}; wchar_t src[4096] = {0};

View File

@ -17,7 +17,7 @@ if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
add_executable(shareddllproxy ${shareddllproxy_common}) add_executable(shareddllproxy ${shareddllproxy_common})
else() else()
add_executable(shareddllproxy ${shareddllproxy_common} Atlas.cpp eztrans.cpp dreye.cpp jbj7.cpp kingsoft.cpp neospeech.cpp ../implsapi.cpp) add_executable(shareddllproxy ${shareddllproxy_common} lec.cpp Atlas.cpp eztrans.cpp dreye.cpp jbj7.cpp kingsoft.cpp neospeech.cpp ../implsapi.cpp)
add_subdirectory(voiceroid2) add_subdirectory(voiceroid2)
endif() endif()

View File

@ -4,7 +4,6 @@ extern "C"
typedef int(__stdcall *TranTextFlowCJ)(char *src, char *dest, int, int); typedef int(__stdcall *TranTextFlowCJ)(char *src, char *dest, int, int);
} }
int dreyewmain(int argc, wchar_t *argv[]) int dreyewmain(int argc, wchar_t *argv[])
{ {
SetCurrentDirectory(argv[1]); SetCurrentDirectory(argv[1]);
@ -32,10 +31,8 @@ int dreyewmain(int argc, wchar_t *argv[])
HANDLE hPipe = CreateNamedPipe(argv[4], PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 65535, 65535, NMPWAIT_WAIT_FOREVER, 0); HANDLE hPipe = CreateNamedPipe(argv[4], PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 65535, 65535, NMPWAIT_WAIT_FOREVER, 0);
SetEvent(CreateEvent(&allAccess, FALSE, FALSE, argv[5])); SetEvent(CreateEvent(&allAccess, FALSE, FALSE, argv[5]));
if (ConnectNamedPipe(hPipe, NULL) != NULL) if (!ConnectNamedPipe(hPipe, NULL))
{ return 0;
DWORD len = 0;
}
while (true) while (true)
{ {
char src[4096] = {0}; char src[4096] = {0};

View File

@ -690,10 +690,8 @@ int eztrans(int argc, wchar_t *argv[])
TransEngine->Init(_p); TransEngine->Init(_p);
SetEvent(CreateEvent(&allAccess, FALSE, FALSE, argv[3])); SetEvent(CreateEvent(&allAccess, FALSE, FALSE, argv[3]));
if (ConnectNamedPipe(hPipe, NULL) != NULL) if (!ConnectNamedPipe(hPipe, NULL))
{ return 0;
DWORD len = 0;
}
WCHAR buff[6000]; WCHAR buff[6000];
while (true) while (true)
{ {

View File

@ -38,10 +38,8 @@ int jbjwmain(int argc, wchar_t *argv[])
wchar_t *buf = new wchar_t[3000]; wchar_t *buf = new wchar_t[3000];
SetEvent(CreateEvent(&allAccess, FALSE, FALSE, argv[3])); SetEvent(CreateEvent(&allAccess, FALSE, FALSE, argv[3]));
if (ConnectNamedPipe(hPipe, NULL) != NULL) if (!ConnectNamedPipe(hPipe, NULL))
{ return 0;
DWORD len = 0;
}
unsigned char intcache[4]; unsigned char intcache[4];
while (true) while (true)
{ {

227
cpp/shareddllproxy/lec.cpp Normal file
View File

@ -0,0 +1,227 @@
// https://github.com/uyjulian/LECTranslate
// #if 1
// // Jp->En engine
// #define CODEPAGE 932
// #define PATH "Nova\\JaEn\\EngineDll_je.dll"
// #else
// // Ko->En engine
// #define CODEPAGE 949
// #define PATH "Nova\\KoEn\\keeglib.dll"
// #endif
int CODEPAGE;
char *PATH;
typedef int(__cdecl *eg_init_t)(const char *path);
typedef int(__cdecl *eg_init2_t)(const char *path, int);
typedef int(__cdecl *eg_end_t)();
typedef int(__cdecl *eg_translate_multi_t)(int, const char *in, size_t out_size, char *out);
// typedef int(__cdecl *eg_translate_one_t)(int, const char *in, const char *, size_t out_size, char *out, void*, void*);
// typedef int(__cdecl *eg_setcallback_t)(int(__cdecl *callback)());
HMODULE hLEC;
eg_end_t eg_end;
eg_translate_multi_t eg_translate_multi;
int lecState; // 0 - not initialized, 1 - ready, -1 - not available;
wchar_t *LECTranslateFull(wchar_t *src)
{
size_t src_size = wcslen(src) + 1, dst_size;
// direct engine call doesn't handle those characters well
// better handling would be manual sentence splitting with
// brackets content replacement with signle symbol which is
// replaced back after independent translation of content
for (size_t i = 0; i < src_size; i++)
{
switch (src[i])
{
case L'': // src[i] = L'{'; break;
case L'':
case L'':
src[i] = L'[';
break;
case L'': // src[i] = L'}'; break;
case L'':
case L'':
src[i] = L']';
break;
case L'':
case L'':
src[i] = L'(';
break;
case L'':
case L'':
src[i] = L')';
break;
case L'':
src[i] = L' ';
break;
case L'':
src[i] = L'';
break;
case L'':
src[i] = L'.';
break;
}
}
char *src_buf = (char *)malloc(src_size * 2);
WideCharToMultiByte(CODEPAGE, 0, src, src_size, src_buf, src_size * 2, "_", NULL);
// we have no idea how much buffer we actually need here
// src_size*3 looks like a good guess, but let's play it a bit more safe
char *dst_buf = NULL;
for (size_t size = src_size * 4 + 0x100;;)
{
char *d = (char *)realloc(dst_buf, size);
if (!d)
break;
dst_buf = d;
// window_->eg_translate_one(0, src_buf, NULL, size, dst_buf, NULL, NULL);
eg_translate_multi(0, src_buf, size, dst_buf);
dst_size = strlen(dst_buf) + 1;
if (dst_size < size)
break;
size *= 2;
}
free(src_buf);
wchar_t *dst = (wchar_t *)malloc(dst_size * sizeof(wchar_t));
MultiByteToWideChar(CODEPAGE, 0, dst_buf, dst_size, dst, dst_size);
free(dst_buf);
return dst;
}
bool LoadLECFromPath(char *path)
{
strcat(path, PATH);
if (hLEC = LoadLibraryA(path))
{
eg_init_t eg_init;
eg_init2_t eg_init2 = (eg_init2_t)GetProcAddress(hLEC, "eg_init2");
if (!eg_init2)
eg_init = (eg_init_t)GetProcAddress(hLEC, "eg_init");
eg_end = (eg_end_t)GetProcAddress(hLEC, "eg_end");
eg_translate_multi = (eg_translate_multi_t)GetProcAddress(hLEC, "eg_translate_multi");
if ((eg_init2 || eg_init) && eg_end && eg_translate_multi)
{
path[strlen(path) - strlen(PATH) + 10] = 0;
if (eg_init2 ? !eg_init2(path, 0) : !eg_init(path))
{
lecState = 1;
return true;
}
}
FreeLibrary(hLEC);
hLEC = NULL;
}
return false;
}
void SetUpLEC()
{
char path[MAX_PATH + 7 + sizeof(PATH)];
path[GetModuleFileNameA(NULL, path, MAX_PATH)] = 0;
if (char *p = strrchr(path, '\\'))
p[1] = 0;
strcat(path, "Plugins\\");
if (LoadLECFromPath(path))
return;
lecState = -1;
HKEY key;
if (!RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\LogoMedia\\LEC Power Translator 15\\Configuration", 0, KEY_QUERY_VALUE, &key))
{
DWORD size = MAX_PATH;
if (!RegQueryValueExA(key, "ApplicationPath", NULL, NULL, (LPBYTE)path, &size))
{
if (size && !path[size - 1])
size--;
if (size && path[size - 1] == '\\')
size--;
for (; size && path[size - 1] != '\\'; size--)
;
if (size)
{
path[size] = 0;
LoadLECFromPath(path);
}
}
RegCloseKey(key);
}
}
static void writestring(wchar_t *text, HANDLE hPipe)
{
DWORD _;
auto len = 2 * wcslen(text);
if (!WriteFile(hPipe, &len, 4, &_, NULL))
return;
if (!WriteFile(hPipe, text, len, &_, NULL))
return;
}
static wchar_t *readstring(HANDLE hPipe)
{
DWORD _;
int len;
if (!ReadFile(hPipe, &len, 4, &_, NULL))
return nullptr;
wchar_t *otext = new wchar_t[len / 2 + 1];
if (!ReadFile(hPipe, otext, len, &_, NULL))
return nullptr;
otext[len / 2] = 0;
return otext;
}
int lecwmain(int argc, wchar_t *argv[])
{
HANDLE hPipe = CreateNamedPipe(argv[1], PIPE_ACCESS_DUPLEX, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, PIPE_UNLIMITED_INSTANCES, 65535, 65535, NMPWAIT_WAIT_FOREVER, 0);
SetEvent(CreateEvent(&allAccess, FALSE, FALSE, argv[2]));
if (!ConnectNamedPipe(hPipe, NULL))
return 0;
std::wstring src = argv[3];
std::wstring tgt = argv[4];
if (src == L"ja" && tgt == L"en")
{
CODEPAGE = 932;
PATH = "Nova\\JaEn\\EngineDll_je.dll";
}
else if (src == L"ko" && tgt == L"en")
{
CODEPAGE = 949;
PATH = "Nova\\KoEn\\keeglib.dll";
}
else
{
CODEPAGE = 932;
PATH = "Nova\\JaEn\\EngineDll_je.dll";
}
DWORD _;
wchar_t __[] = L"not installed";
while (true)
{
wchar_t *otext = readstring(hPipe);
if (!otext)
break;
if (!lecState)
{
SetUpLEC();
if (lecState < 0)
{
writestring(__, hPipe);
continue;
}
}
if (lecState < 0)
{
writestring(__, hPipe);
continue;
}
wchar_t *text = LECTranslateFull(otext);
delete[] otext;
writestring(text, hPipe);
delete[] text;
}
return 0;
}

View File

@ -35,10 +35,8 @@ int neospeech(int argc, wchar_t *argv[])
memset(mapview, 0, 1024 * 1024 * 10); memset(mapview, 0, 1024 * 1024 * 10);
SetEvent(CreateEvent(&allAccess, FALSE, FALSE, argv[2])); SetEvent(CreateEvent(&allAccess, FALSE, FALSE, argv[2]));
if (ConnectNamedPipe(hPipe, NULL) != NULL) if (!ConnectNamedPipe(hPipe, NULL))
{ return 0;
DWORD len = 0;
}
wchar_t text[10000]; wchar_t text[10000];
DWORD _; DWORD _;
while (true) while (true)

View File

@ -4,6 +4,7 @@ int dllinjectwmain(int argc, wchar_t *argv[]);
int updatewmain(int argc, wchar_t *wargv[]); int updatewmain(int argc, wchar_t *wargv[]);
bool checkisapatch(); bool checkisapatch();
#ifndef _WIN64 #ifndef _WIN64
int lecwmain(int argc, wchar_t *argv[]);
int jbjwmain(int argc, wchar_t *argv[]); int jbjwmain(int argc, wchar_t *argv[]);
int dreyewmain(int argc, wchar_t *argv[]); int dreyewmain(int argc, wchar_t *argv[]);
int kingsoftwmain(int argc, wchar_t *argv[]); int kingsoftwmain(int argc, wchar_t *argv[]);
@ -61,6 +62,7 @@ int wmain(int argc, wchar_t *argv[])
{L"listpm", listprocessmodule}, {L"listpm", listprocessmodule},
{L"update", updatewmain}, {L"update", updatewmain},
#ifndef _WIN64 #ifndef _WIN64
{L"lec", lecwmain},
{L"jbj7", jbjwmain}, {L"jbj7", jbjwmain},
{L"dreye", dreyewmain}, {L"dreye", dreyewmain},
{L"kingsoft", kingsoftwmain}, {L"kingsoft", kingsoftwmain},

View File

@ -1,7 +1,7 @@
set(VERSION_MAJOR 6) set(VERSION_MAJOR 6)
set(VERSION_MINOR 14) set(VERSION_MINOR 14)
set(VERSION_PATCH 12) set(VERSION_PATCH 13)
set(VERSION_REVISION 0) set(VERSION_REVISION 0)
set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}") set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}")
add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp) add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp)

View File

@ -13,50 +13,43 @@ class TS(basetrans):
def checkpath(self): def checkpath(self):
t = time.time() t = time.time()
t = str(t) t = str(t)
pipename = "\\\\.\\Pipe\\dreye_" + t pipename = "\\\\.\\Pipe\\dreye_" + t
waitsignal = "dreyewaitload_" + t waitsignal = "dreyewaitload_" + t
self.engine = autoproc( self.engine = autoproc(
subproc_w( subproc_w(
'./files/plugins/shareddllproxy32.exe atlaswmain {} {} '.format( "./files/plugins/shareddllproxy32.exe atlaswmain {} {} ".format(
pipename, waitsignal pipename, waitsignal
), ),
name="atlaswmain", name="atlaswmain",
)
) )
)
windows.WaitForSingleObject( windows.WaitForSingleObject(
windows.AutoHandle(windows.CreateEvent(False, False, waitsignal)), windows.AutoHandle(windows.CreateEvent(False, False, waitsignal)),
windows.INFINITE, windows.INFINITE,
)
windows.WaitNamedPipe(pipename, windows.NMPWAIT_WAIT_FOREVER)
self.hPipe = windows.AutoHandle(
windows.CreateFile(
pipename,
windows.GENERIC_READ | windows.GENERIC_WRITE,
0,
None,
windows.OPEN_EXISTING,
windows.FILE_ATTRIBUTE_NORMAL,
None,
) )
windows.WaitNamedPipe(pipename, windows.NMPWAIT_WAIT_FOREVER) )
self.hPipe = windows.AutoHandle( return True
windows.CreateFile(
pipename,
windows.GENERIC_READ | windows.GENERIC_WRITE,
0,
None,
windows.OPEN_EXISTING,
windows.FILE_ATTRIBUTE_NORMAL,
None,
)
)
return True
def x64(self, content): def x64(self, content):
self.checkpath()
if self.checkpath() == False: windows.WriteFile(self.hPipe, content.encode("utf-16-le"))
raise Exception(_TR("翻译器加载失败"))
ress = [] return windows.ReadFile(self.hPipe, 4096).decode("utf-16-le")
for line in content.split("\n"):
if len(line) == 0:
continue
windows.WriteFile(self.hPipe, content.encode('utf-16-le'))
ress.append(
windows.ReadFile(self.hPipe, 4096).decode('utf-16-le')
)
return "\n".join(ress)
def translate(self, content): def translate(self, content):
return self.x64(content) return self.x64(content)

View File

@ -11,6 +11,9 @@ class TS(basetrans):
self.pair = None self.pair = None
self.checkpath() self.checkpath()
def langmap(self):
return {"auto": "ja"}
def checkpath(self): def checkpath(self):
if self.config["path"] == "": if self.config["path"] == "":
return False return False
@ -69,9 +72,7 @@ class TS(basetrans):
if len(line) == 0: if len(line) == 0:
continue continue
windows.WriteFile(self.hPipe, line.encode(codes[self.srclang])) windows.WriteFile(self.hPipe, line.encode(codes[self.srclang]))
ress.append( ress.append(windows.ReadFile(self.hPipe, 4096).decode(codes[self.tgtlang]))
windows.ReadFile(self.hPipe, 4096).decode(codes[self.tgtlang])
)
return "\n".join(ress) return "\n".join(ress)
def translate(self, content): def translate(self, content):

View File

@ -81,4 +81,4 @@ class TS(basetrans):
return self.x64(content) return self.x64(content)
def langmap(self): def langmap(self):
return {"zh": "SChinese", "cht": "TChinese", "en": "English", "ja": "Japanese"} return {"zh": "SChinese", "cht": "TChinese", "en": "English", "ja": "Japanese", "auto": "Japanese"}

View File

@ -0,0 +1,62 @@
from myutils.subproc import subproc_w, autoproc
from translator.basetranslator import basetrans
import ctypes, time
import windows
class TS(basetrans):
def inittranslator(self):
self.path = None
self.pair = None
self.checkpath()
def langmap(self):
return {"auto": "ja"}
def checkpath(self):
pairs = (self.srclang, self.tgtlang)
if pairs == self.pair:
return
self.pair = pairs
t = time.time()
t = str(t)
pipename = "\\\\.\\Pipe\\dreye_" + t
waitsignal = "dreyewaitload_" + t
self.engine = autoproc(
subproc_w(
"./files/plugins/shareddllproxy32.exe lec {} {} {} {}".format(
pipename, waitsignal, self.srclang, self.tgtlang
),
name="lec",
)
)
windows.WaitForSingleObject(
windows.AutoHandle(windows.CreateEvent(False, False, waitsignal)),
windows.INFINITE,
)
windows.WaitNamedPipe(pipename, windows.NMPWAIT_WAIT_FOREVER)
self.hPipe = windows.AutoHandle(
windows.CreateFile(
pipename,
windows.GENERIC_READ | windows.GENERIC_WRITE,
0,
None,
windows.OPEN_EXISTING,
windows.FILE_ATTRIBUTE_NORMAL,
None,
)
)
def x64(self, content: str):
self.checkpath()
l = content.encode("utf-16-le")
windows.WriteFile(self.hPipe, bytes(ctypes.c_int(len(l))))
windows.WriteFile(self.hPipe, l)
size = ctypes.c_int.from_buffer_copy(windows.ReadFile(self.hPipe, 4)).value
return windows.ReadFile(self.hPipe, size).decode("utf-16-le")
def translate(self, content):
return self.x64(content)

View File

@ -1702,6 +1702,12 @@
"color": "#1839f0", "color": "#1839f0",
"name": "Atlas" "name": "Atlas"
}, },
"lec": {
"type": "offline",
"use": false,
"color": "#1839f0",
"name": "LEC"
},
"sougou2": { "sougou2": {
"use": false, "use": false,
"color": "blue", "color": "blue",