issues/32

Update texthook.cc
This commit is contained in:
恍兮惚兮 2024-05-11 13:01:02 +08:00
parent 2270542de5
commit 69a729ebbf
4 changed files with 54 additions and 15 deletions

View File

@ -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);

View File

@ -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))

View File

@ -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
}

View File

@ -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))