From 780cc66c4f9786798774fab0062ea6fefcbcbe08 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: Wed, 20 Mar 2024 22:51:24 +0800 Subject: [PATCH] js --- LunaHook/engines/v8/v8.cpp | 1 + LunaHook/resource/lunajspatch.js | 39 +++++++++++++++++++------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/LunaHook/engines/v8/v8.cpp b/LunaHook/engines/v8/v8.cpp index 579bae8..244c5d2 100644 --- a/LunaHook/engines/v8/v8.cpp +++ b/LunaHook/engines/v8/v8.cpp @@ -129,6 +129,7 @@ bool v8runscript_isolate(void* isolate){ ConsoleOutput("script %p",script); if(script==0)return; ((Runt1)Run)(script,&useless); + ConsoleOutput("useless %p",useless); } else if(NewFromUtf8v2) { diff --git a/LunaHook/resource/lunajspatch.js b/LunaHook/resource/lunajspatch.js index 7f4f0cf..ece376a 100644 --- a/LunaHook/resource/lunajspatch.js +++ b/LunaHook/resource/lunajspatch.js @@ -1,4 +1,5 @@ var fontface=''; + function splitfonttext(transwithfont){ if(transwithfont[0]=='\x01'){ transwithfont=transwithfont.substr(1) @@ -12,14 +13,27 @@ function splitfonttext(transwithfont){ return transwithfont; } } -function NWjshook(){ - function NWjssend(s) { +function clipboardsender(s){ + try{ const _clipboard = require('nw.gui').Clipboard.get(); _clipboard.set(s, 'text'); transwithfont=_clipboard.get('text'); - if(transwithfont.length==0)return s; - return splitfonttext(transwithfont) } + catch(err){ + try{ + + const clipboard = require('electron').clipboard; + clipboard.writeText(s); + transwithfont= clipboard.readText(); + } + catch(err2){ + return s; + } + } + if(transwithfont.length==0)return s; + return splitfonttext(transwithfont) +} +function rpgmakerhook(){ if(Window_Message.prototype.originstartMessage)return; Window_Message.prototype.originstartMessage=Window_Message.prototype.startMessage; @@ -32,26 +46,19 @@ function NWjshook(){ Window_Message.prototype.startMessage = function() { gametext = $gameMessage.allText(); - resp=NWjssend(gametext); + resp=clipboardsender(gametext); $gameMessage._texts=[resp] this.originstartMessage(); }; } -function Electronhook() { +function tyranohook() { - function Electronsend(s) { - const clipboard = require('electron').clipboard; - clipboard.writeText(s); - transwithfont= clipboard.readText(); - if(transwithfont.length==0)return s; - return splitfonttext(transwithfont) - } if(tyrano.plugin.kag.tag.text.originstart)return; tyrano.plugin.kag.tag.text.originstart=tyrano.plugin.kag.tag.text.start; tyrano.plugin.kag.tag.text.start = function (pm) { if (1 != this.kag.stat.is_script && 1 != this.kag.stat.is_html) { - pm.val=Electronsend(pm.val); + pm.val=clipboardsender(pm.val); if(fontface!=''){ this.kag.stat.font.face=fontface } @@ -63,10 +70,10 @@ function retryinject(times){ if(times==0)return; try{ if(window.tyrano && tyrano.plugin){ - Electronhook(); + tyranohook(); } else if(window.Utils && Utils.RPGMAKER_NAME){ - NWjshook(); + rpgmakerhook(); } else{ setTimeout(retryinject,3000,times-1);