From 69a729ebbf474846282a7059c53087d5daf7a5e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Sat, 11 May 2024 13:01:02 +0800 Subject: [PATCH] issues/32 Update texthook.cc --- LunaHook/engines/v8/v8.cpp | 2 +- LunaHook/main.cc | 1 - LunaHook/resource/lunajspatch.js | 34 +++++++++++++++++++++++--------- LunaHook/texthook.cc | 32 ++++++++++++++++++++++++++---- 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/LunaHook/engines/v8/v8.cpp b/LunaHook/engines/v8/v8.cpp index cfea8af..be6e6aa 100644 --- a/LunaHook/engines/v8/v8.cpp +++ b/LunaHook/engines/v8/v8.cpp @@ -5,7 +5,7 @@ namespace{ bool hookClipboard(){ HookParam hp; hp.address=(uintptr_t)SetClipboardData; - hp.type= USING_STRING|CODEC_UTF16|EMBED_ABLE|EMBED_BEFORE_SIMPLE; + hp.type= USING_STRING|NO_CONTEXT|CODEC_UTF16|EMBED_ABLE|EMBED_BEFORE_SIMPLE; hp.text_fun=[](hook_stack* stack, HookParam *hp, uintptr_t* data, uintptr_t* split, size_t* len){ HGLOBAL hClipboardData=(HGLOBAL)stack->ARG2; auto text=(wchar_t*)GlobalLock(hClipboardData); diff --git a/LunaHook/main.cc b/LunaHook/main.cc index 1196858..5bdcaa6 100644 --- a/LunaHook/main.cc +++ b/LunaHook/main.cc @@ -175,7 +175,6 @@ bool NewHook_1(HookParam& hp, LPCSTR lpname) return false; } if (lpname && *lpname) strncpy_s(hp.name, lpname, HOOK_NAME_SIZE - 1); - ConsoleOutput(INSERTING_HOOK, hp.name,hp.address); wcscpy_s(hp.hookcode,HOOKCODE_LEN,HookCode::Generate(hp, GetCurrentProcessId()).c_str()); if (!(*hooks)[currentHook].Insert(hp)) diff --git a/LunaHook/resource/lunajspatch.js b/LunaHook/resource/lunajspatch.js index b1e59f4..4c02530 100644 --- a/LunaHook/resource/lunajspatch.js +++ b/LunaHook/resource/lunajspatch.js @@ -20,7 +20,6 @@ function splitfonttext(transwithfont) { } } function clipboardsender(s, lpsplit) { - lpsplit = typeof lpsplit !== 'undefined' ? lpsplit : 0 //magic split \x02 text s = magicsend + lpsplit.toString() + '\x02' + s; try { @@ -43,19 +42,36 @@ function clipboardsender(s, lpsplit) { } function rpgmakerhook() { - if (Window_Message.prototype.originstartMessage) return; - Window_Base.prototype.drawTextEx_origin = Window_Base.prototype.drawTextEx; - Window_Base.prototype.drawText_origin = Window_Base.prototype.drawText; - Window_Message.prototype.originstartMessage = Window_Message.prototype.startMessage; - Bitmap.prototype.origin_makeFontNameText = Bitmap.prototype._makeFontNameText; + if (Window_Message.prototype.originstartMessage) { } + else { + Window_Base.prototype.drawTextEx_origin = Window_Base.prototype.drawTextEx; + Window_Base.prototype.drawText_origin = Window_Base.prototype.drawText; + Window_Message.prototype.originstartMessage = Window_Message.prototype.startMessage; + + Bitmap.prototype.drawText_ori = Bitmap.prototype.drawText; + Bitmap.prototype.last_y = 0; + + Bitmap.prototype.origin_makeFontNameText = Bitmap.prototype._makeFontNameText; + } Bitmap.prototype._makeFontNameText = function () { if (fontface == '') return this.origin_makeFontNameText(); return (this.fontItalic ? 'Italic ' : '') + this.fontSize + 'px ' + fontface; } + Bitmap.prototype.drawText = function (text, x, y, maxWidth, lineHeight, align) { + //y>100的有重复;慢速是单字符,快速是多字符 + if (y < 100) { + extra = 5 + ((text.length == 1) ? 0 : 1); + if (y != Bitmap.prototype.last_y) + clipboardsender('\n', extra) + clipboardsender(text, extra) + Bitmap.prototype.last_y = y; + } + return this.drawText_ori(text, x, y, maxWidth, lineHeight, align); + } Window_Message.prototype.startMessage = function () { gametext = $gameMessage.allText(); - resp = clipboardsender(gametext); + resp = clipboardsender(gametext, 0); $gameMessage._texts = [resp] this.originstartMessage(); }; @@ -64,7 +80,7 @@ function rpgmakerhook() { return this.drawText_origin(text, x, y, maxWidth, align) } Window_Base.prototype.drawTextEx = function (text, x, y) { - text = clipboardsender(text, 1) + text = clipboardsender(text, 2) return this.drawTextEx_origin(text, x, y) } } @@ -76,7 +92,7 @@ function tyranohook() { tyrano.plugin.kag.tag.chara_ptext.startorigin = tyrano.plugin.kag.tag.chara_ptext.start; tyrano.plugin.kag.tag.text.start = function (pm) { if (1 != this.kag.stat.is_script && 1 != this.kag.stat.is_html) { - pm.val = clipboardsender(pm.val); + pm.val = clipboardsender(pm.val, 0); if (fontface != '') { this.kag.stat.font.face = fontface } diff --git a/LunaHook/texthook.cc b/LunaHook/texthook.cc index 7c20790..0e394c9 100644 --- a/LunaHook/texthook.cc +++ b/LunaHook/texthook.cc @@ -110,7 +110,7 @@ bool TextHook::Insert(HookParam hp) if(!addr)return false; RemoveHook(addr, 0); - + ConsoleOutput(INSERTING_HOOK, hp.name,addr); local_buffer=new BYTE[PIPE_BUFFER_SIZE]; { std::scoped_lock lock(viewMutex); @@ -174,6 +174,18 @@ uintptr_t jitgetaddr(hook_stack* stack, HookParam* hp){ return 0; } } +bool checklengthembedable(const HookParam&hp,size_t size){ + size_t len; + if (hp.type & CODEC_UTF16) + len = 2; + else if(hp.type&CODEC_UTF32) + len = 4; + else + { + len = 1; + } + return size>len; +} void TextHook::Send(uintptr_t lpDataBase) { auto buffer =(TextOutput_T*) local_buffer; @@ -295,12 +307,24 @@ void TextHook::Send(uintptr_t lpDataBase) parsenewlineseperator(pbData, &lpCount); - if((hp.type&EMBED_ABLE)&&(checktranslatedok(pbData,lpCount))) - buffer->type=buffer->type&(~EMBED_ABLE); + bool canembed;; + if(hp.type&EMBED_ABLE){ + if(!checklengthembedable(hp,lpCount)){ + buffer->type&=(~EMBED_ABLE); + canembed=false; + } + else if(checktranslatedok(pbData,lpCount)){ + buffer->type&=(~EMBED_ABLE); + canembed=true; + } + else{ + canembed=true; + } + } TextOutput(tp, buffer, lpCount); - if((hp.type&EMBED_ABLE)&&(check_embed_able(tp))) + if(canembed&&(check_embed_able(tp))) { auto lpCountsave=lpCount; if(waitfornotify(buffer,pbData,&lpCount,tp))