This commit is contained in:
恍兮惚兮 2024-08-19 09:34:18 +08:00
parent f05fc33cee
commit 5bf9eeb490
7 changed files with 29 additions and 37 deletions

View File

@ -344,18 +344,8 @@ def gethookembedgrid(self):
], ],
[ [
"限制每行字数", "限制每行字数",
D_getsimpleswitch( D_getsimpleswitch(globalconfig["embedded"], "limittextlength_use"),
globalconfig["embedded"], D_getspinbox(0, 1000, globalconfig["embedded"], "limittextlength_length"),
"limittextlength_use",
callback=lambda _: gobject.baseobject.textsource.flashembedsettings(),
),
D_getspinbox(
0,
1000,
globalconfig["embedded"],
"limittextlength_length",
callback=lambda x: gobject.baseobject.textsource.flashembedsettings(),
),
], ],
[ [
"修改游戏字体", "修改游戏字体",

View File

@ -7,6 +7,7 @@ from myutils.utils import (
checkmd5reloadmodule, checkmd5reloadmodule,
LRUCache, LRUCache,
getlangsrc, getlangsrc,
getlanguagespace,
parsemayberegexreplace, parsemayberegexreplace,
) )
from myutils.config import ( from myutils.config import (
@ -202,10 +203,7 @@ def _4_f(line):
def _6_fEX(line): def _6_fEX(line):
srclang = getlangsrc() srclang = getlangsrc()
if srclang in ["zh", "ja", "cht"]: white = getlanguagespace(srclang)
white = ""
else:
white = " "
line = ( line = (
line.replace("\r ", " ") line.replace("\r ", " ")
.replace("\n ", " ") .replace("\n ", " ")

View File

@ -81,6 +81,10 @@ def getlangtgt():
return __internal__getlang("private_tgtlang_2", "tgtlang4") return __internal__getlang("private_tgtlang_2", "tgtlang4")
def getlanguagespace(lang):
return "" if (lang in ("zh", "ja", "cht")) else " "
def findenclose(text, tag): def findenclose(text, tag):
i = 0 i = 0
tags = f"<{tag}" tags = f"<{tag}"

View File

@ -1,4 +1,5 @@
from myutils.config import globalconfig, ocrsetting, ocrerrorfix from myutils.config import globalconfig, ocrsetting, ocrerrorfix
from myutils.utils import getlanguagespace
from myutils.commonbase import commonbase from myutils.commonbase import commonbase
@ -18,10 +19,8 @@ class baseocr(commonbase):
def space(self): def space(self):
if globalconfig["ocrmergelines"] == False: if globalconfig["ocrmergelines"] == False:
space = "\n" space = "\n"
elif self.srclang_1 in ["zh", "ja", "cht"]:
space = ""
else: else:
space = " " space = getlanguagespace(self.srclang_1)
return space return space
############################################################ ############################################################

View File

@ -66,12 +66,8 @@ class OCR(baseocr):
+ ", ".join([_TR(getlang_inner2show(f)) for f in _allsupport]) + ", ".join([_TR(getlang_inner2show(f)) for f in _allsupport])
) )
if self.srclang in ["zh", "ja", "cht"]:
space = ""
else:
space = " "
ret = winrtutils.OCR_f(imagebinary, self.supportmap[self.srclang], space) ret = winrtutils.OCR_f(imagebinary, self.supportmap[self.srclang], self.space)
boxs = [_[1:] for _ in ret] boxs = [_[1:] for _ in ret]
texts = [_[0] for _ in ret] texts = [_[0] for _ in ret]

View File

@ -11,7 +11,7 @@ from myutils.config import (
findgameuidofpath, findgameuidofpath,
) )
from textsource.textsourcebase import basetext from textsource.textsourcebase import basetext
from myutils.utils import checkchaos, getfilemd5 from myutils.utils import checkchaos, getfilemd5, getlangtgt, getlanguagespace
from myutils.hwnd import injectdll, test_injectable, ListProcess, getpidexe from myutils.hwnd import injectdll, test_injectable, ListProcess, getpidexe
from myutils.wrapper import threader from myutils.wrapper import threader
from traceback import print_exc from traceback import print_exc
@ -158,7 +158,6 @@ class texthook(basetext):
c_uint32, c_uint32,
c_uint32, c_uint32,
c_bool, c_bool,
c_uint32,
) )
self.Luna_checkisusingembed = LunaHost.Luna_checkisusingembed self.Luna_checkisusingembed = LunaHost.Luna_checkisusingembed
self.Luna_checkisusingembed.argtypes = DWORD, c_uint64, c_uint64, c_uint64 self.Luna_checkisusingembed.argtypes = DWORD, c_uint64, c_uint64, c_uint64
@ -358,19 +357,30 @@ class texthook(basetext):
@threader @threader
def getembedtext(self, text, tp): def getembedtext(self, text, tp):
if self.safeembedcheck(text) == False: if self.safeembedcheck(text) == False:
self.embedcallback(text, text) self.embedcallback(text, "")
return return
if not self.isautorunning: if not self.isautorunning:
self.embedcallback(text, text) self.embedcallback(text, "")
return return
if self.checkisusingembed(tp.addr, tp.ctx, tp.ctx2): if self.checkisusingembed(tp.addr, tp.ctx, tp.ctx2):
trans = self.waitfortranslation(text) trans = self.waitfortranslation(text)
if not trans: if not trans:
trans = text trans = ""
self.embedcallback(text, trans) self.embedcallback(text, trans)
def embedcallback(self, text, trans): def embedcallback(self, text: str, trans: str):
if len(trans) and globalconfig["embedded"]["limittextlength_use"]:
length = globalconfig["embedded"]["limittextlength_length"]
lines = trans.split("\n")
newlines = []
space = getlanguagespace(getlangtgt())
for line in lines:
line = line.split(space) if space else line
while len(line):
newlines.append(space.join(line[:length]))
line = line[length:]
trans = "\n".join(newlines)
print(trans)
for pid in self.pids.copy(): for pid in self.pids.copy():
self.Luna_embedcallback(pid, text, trans) self.Luna_embedcallback(pid, text, trans)
@ -393,11 +403,6 @@ class texthook(basetext):
globalconfig["embedded"]["insertspace_policy"], globalconfig["embedded"]["insertspace_policy"],
globalconfig["embedded"]["keeprawtext"], globalconfig["embedded"]["keeprawtext"],
True, True,
(
globalconfig["embedded"]["limittextlength_length"]
if globalconfig["embedded"]["limittextlength_use"]
else 0
),
) )
def onremovehook(self, hc, hn, tp): def onremovehook(self, hc, hn, tp):

View File

@ -29,7 +29,7 @@ include(generate_product_version)
set(VERSION_MAJOR 5) set(VERSION_MAJOR 5)
set(VERSION_MINOR 28) set(VERSION_MINOR 28)
set(VERSION_PATCH 5) set(VERSION_PATCH 6)
add_library(pch pch.cpp) add_library(pch pch.cpp)
target_precompile_headers(pch PUBLIC pch.h) target_precompile_headers(pch PUBLIC pch.h)