diff --git a/LunaHook/engines/v8/v8.cpp b/LunaHook/engines/v8/v8.cpp index e459694..5d3e4cc 100644 --- a/LunaHook/engines/v8/v8.cpp +++ b/LunaHook/engines/v8/v8.cpp @@ -7,23 +7,30 @@ #include"embed_util.h" #include"stackoffset.hpp" namespace{ - + constexpr auto magicsend =L"\x01LUNAFROMJS\x01"; + constexpr auto magicrecv =L"\x01LUNAFROMHOST\x01"; bool hookClipboard(){ HookParam hp; hp.address=(uintptr_t)SetClipboardData; hp.type= USING_STRING|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; - *data=(uintptr_t)GlobalLock(hClipboardData); - *len=wcslen((wchar_t*)*data)*2; + auto text=(wchar_t*)GlobalLock(hClipboardData); + if(startWith(text,magicsend)){ + text+=wcslen(magicsend); + auto spl=wcschr(text,L'\x02'); + *split=std::stoi(std::wstring(text,spl-text)); + text=spl+1; + *data=(uintptr_t)text; + *len=wcslen(text)*2; + } + GlobalUnlock(hClipboardData); }; hp.hook_after=[](hook_stack*s,void* data, size_t len){ - - std::wstring transwithfont; - transwithfont+=L'\x01'; + std::wstring transwithfont=magicrecv; transwithfont+=embedsharedmem->fontFamily; - transwithfont+=L'\x01'; + transwithfont+=L'\x02'; transwithfont+=std::wstring((wchar_t*)data,len/2); HGLOBAL hClipboardData = GlobalAlloc(GMEM_MOVEABLE, transwithfont.size()*2 +2); auto pchData = (wchar_t*)GlobalLock(hClipboardData); diff --git a/LunaHook/resource/lunajspatch.js b/LunaHook/resource/lunajspatch.js index ece376a..5c588d8 100644 --- a/LunaHook/resource/lunajspatch.js +++ b/LunaHook/resource/lunajspatch.js @@ -1,10 +1,17 @@ var fontface=''; - +const magicsend='\x01LUNAFROMJS\x01' +const magicrecv='\x01LUNAFROMHOST\x01' function splitfonttext(transwithfont){ - if(transwithfont[0]=='\x01'){ - transwithfont=transwithfont.substr(1) - split=transwithfont.search('\x01') - if(split==-1)return transwithfont; + if(transwithfont.substr(0,magicsend.length)==magicsend) //not trans + { + split=transwithfont.search('\x02') + return transwithfont.substr(split+1); + } + else if(transwithfont.substr(0,magicrecv.length)==magicrecv) + { + transwithfont=transwithfont.substr(magicrecv.length) + //magic font \x02 text + split=transwithfont.search('\x02') fontface=transwithfont.substr(0,split) text=transwithfont.substr(split+1) return text; @@ -13,7 +20,10 @@ function splitfonttext(transwithfont){ return transwithfont; } } -function clipboardsender(s){ +function clipboardsender(s,lpsplit){ + lpsplit = typeof lpsplit !== 'undefined' ? lpsplit : 0 + //magic split \x02 text + s=magicsend+lpsplit.toString()+'\x02'+s; try{ const _clipboard = require('nw.gui').Clipboard.get(); _clipboard.set(s, 'text'); @@ -21,7 +31,6 @@ function clipboardsender(s){ } catch(err){ try{ - const clipboard = require('electron').clipboard; clipboard.writeText(s); transwithfont= clipboard.readText(); @@ -56,6 +65,7 @@ function tyranohook() { if(tyrano.plugin.kag.tag.text.originstart)return; tyrano.plugin.kag.tag.text.originstart=tyrano.plugin.kag.tag.text.start; + 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); @@ -65,6 +75,10 @@ function tyranohook() { } return this.originstart(pm) } + tyrano.plugin.kag.tag.chara_ptext.start = function (pm) { + pm.name=clipboardsender(pm.name,1) + return this.startorigin(pm) + } } function retryinject(times){ if(times==0)return;