2024-05-05 20:53:51 +08:00
|
|
|
|
var fontface = '';
|
|
|
|
|
var magicsend = '\x01LUNAFROMJS\x01'
|
|
|
|
|
var magicrecv = '\x01LUNAFROMHOST\x01'
|
2024-10-19 22:17:10 +08:00
|
|
|
|
var is_packed = IS_PACKED
|
|
|
|
|
var is_useclipboard = IS_USECLIPBOARD
|
|
|
|
|
var internal_http_port = INTERNAL_HTTP_PORT
|
2024-05-05 20:53:51 +08:00
|
|
|
|
function splitfonttext(transwithfont) {
|
|
|
|
|
if (transwithfont.substr(0, magicsend.length) == magicsend) //not trans
|
2024-03-25 14:59:33 +08:00
|
|
|
|
{
|
2024-05-05 20:53:51 +08:00
|
|
|
|
split = transwithfont.search('\x02')
|
|
|
|
|
return transwithfont.substr(split + 1);
|
2024-03-25 14:59:33 +08:00
|
|
|
|
}
|
2024-05-05 20:53:51 +08:00
|
|
|
|
else if (transwithfont.substr(0, magicrecv.length) == magicrecv) {
|
|
|
|
|
transwithfont = transwithfont.substr(magicrecv.length)
|
2024-03-25 14:59:33 +08:00
|
|
|
|
//magic font \x02 text
|
2024-05-05 20:53:51 +08:00
|
|
|
|
split = transwithfont.search('\x02')
|
|
|
|
|
fontface = transwithfont.substr(0, split)
|
|
|
|
|
text = transwithfont.substr(split + 1)
|
2024-03-19 23:14:08 +08:00
|
|
|
|
return text;
|
|
|
|
|
}
|
2024-05-05 20:53:51 +08:00
|
|
|
|
else {
|
2024-03-19 23:14:08 +08:00
|
|
|
|
return transwithfont;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-19 22:17:10 +08:00
|
|
|
|
function syncquery(s) {
|
|
|
|
|
if (internal_http_port == 0) { throw new Error('') }
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
2024-10-20 00:10:15 +08:00
|
|
|
|
var url = 'http://127.0.0.1:' + internal_http_port + '/fuck?' + s
|
|
|
|
|
xhr.open('GET', url, false);
|
2024-10-19 22:17:10 +08:00
|
|
|
|
xhr.send();
|
|
|
|
|
if (xhr.status === 200) {
|
2024-10-20 00:10:15 +08:00
|
|
|
|
return xhr.responseText;//解析这个会导致v8::String::Length的v8StringUtf8Length出现错误,但不影响。
|
2024-10-19 22:17:10 +08:00
|
|
|
|
} else {
|
|
|
|
|
throw new Error('')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2024-10-20 00:10:15 +08:00
|
|
|
|
function makecomplexs(name, s_raw, lpsplit) {
|
|
|
|
|
return magicsend + name + '\x03' + lpsplit.toString() + '\x02' + s_raw;
|
2024-10-19 22:17:10 +08:00
|
|
|
|
}
|
2024-10-20 00:10:15 +08:00
|
|
|
|
function cppjsio(s) {
|
2024-05-05 20:53:51 +08:00
|
|
|
|
try {
|
2024-10-20 00:10:15 +08:00
|
|
|
|
return syncquery(s)
|
2024-03-15 21:51:59 +08:00
|
|
|
|
}
|
2024-05-05 20:53:51 +08:00
|
|
|
|
catch (err) {
|
|
|
|
|
try {
|
2024-10-19 22:17:10 +08:00
|
|
|
|
if (!is_useclipboard) { throw new Error('') }
|
2024-10-20 00:10:15 +08:00
|
|
|
|
const _clipboard = require('nw.gui').Clipboard.get();
|
|
|
|
|
_clipboard.set(s, 'text');
|
|
|
|
|
return _clipboard.get('text');
|
2024-03-20 22:51:24 +08:00
|
|
|
|
}
|
2024-05-05 20:53:51 +08:00
|
|
|
|
catch (err2) {
|
2024-10-19 22:17:10 +08:00
|
|
|
|
try {
|
2024-10-20 00:10:15 +08:00
|
|
|
|
if (!is_useclipboard) { throw new Error('') }
|
|
|
|
|
const clipboard = require('electron').clipboard;
|
|
|
|
|
clipboard.writeText(s);
|
|
|
|
|
return clipboard.readText();
|
2024-10-19 22:17:10 +08:00
|
|
|
|
}
|
|
|
|
|
catch (err3) {
|
|
|
|
|
return s_raw;
|
|
|
|
|
}
|
2024-03-20 22:51:24 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-20 00:10:15 +08:00
|
|
|
|
}
|
|
|
|
|
function clipboardsender(name, s_raw, lpsplit) {
|
|
|
|
|
//magic split \x02 text
|
|
|
|
|
if (!s_raw)
|
|
|
|
|
return s_raw
|
|
|
|
|
transwithfont = cppjsio(makecomplexs(name, s_raw, lpsplit))
|
2024-10-19 16:11:19 +08:00
|
|
|
|
if (transwithfont.length == 0) return s_raw;
|
2024-03-20 22:51:24 +08:00
|
|
|
|
return splitfonttext(transwithfont)
|
|
|
|
|
}
|
2024-05-12 13:45:50 +08:00
|
|
|
|
|
2024-10-19 22:17:10 +08:00
|
|
|
|
function clipboardsender_only_send(name, s_raw, lpsplit) {
|
2024-05-12 13:45:50 +08:00
|
|
|
|
//magic split \x02 text
|
2024-10-20 00:10:15 +08:00
|
|
|
|
if (!s_raw)
|
2024-10-19 22:17:10 +08:00
|
|
|
|
return s_raw
|
2024-10-20 00:10:15 +08:00
|
|
|
|
cppjsio(makecomplexs(name, s_raw, lpsplit))
|
2024-05-12 13:45:50 +08:00
|
|
|
|
}
|
2024-05-05 20:53:51 +08:00
|
|
|
|
function rpgmakerhook() {
|
|
|
|
|
|
2024-05-11 13:01:02 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
2024-05-05 20:53:51 +08:00
|
|
|
|
Bitmap.prototype._makeFontNameText = function () {
|
2024-10-20 00:10:15 +08:00
|
|
|
|
if (!fontface) return this.origin_makeFontNameText();
|
2024-03-19 23:14:08 +08:00
|
|
|
|
return (this.fontItalic ? 'Italic ' : '') +
|
|
|
|
|
this.fontSize + 'px ' + fontface;
|
|
|
|
|
}
|
2024-08-12 21:00:40 +08:00
|
|
|
|
Bitmap.prototype.collectstring = { 2: '', 5: '', 6: '' };
|
|
|
|
|
setInterval(function () {
|
2024-10-19 16:11:19 +08:00
|
|
|
|
for (lpsplit in Bitmap.prototype.collectstring) {
|
2024-08-12 21:00:40 +08:00
|
|
|
|
if (Bitmap.prototype.collectstring[lpsplit].length) {
|
|
|
|
|
clipboardsender_only_send('rpgmakermv', Bitmap.prototype.collectstring[lpsplit], lpsplit)
|
|
|
|
|
Bitmap.prototype.collectstring[lpsplit] = ''
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}, 100);
|
|
|
|
|
if (!is_packed) {
|
|
|
|
|
|
2024-05-12 16:48:32 +08:00
|
|
|
|
Bitmap.prototype.drawText = function (text, x, y, maxWidth, lineHeight, align) {
|
|
|
|
|
//y>100的有重复;慢速是单字符,快速是多字符
|
|
|
|
|
if (text && (y < 100)) {
|
|
|
|
|
extra = 5 + ((text.length == 1) ? 0 : 1);
|
2024-08-12 21:00:40 +08:00
|
|
|
|
if (y != Bitmap.prototype.last_y) {
|
|
|
|
|
Bitmap.prototype.collectstring[extra] += '\n'
|
|
|
|
|
}
|
|
|
|
|
Bitmap.prototype.collectstring[extra] += text;
|
2024-05-12 16:48:32 +08:00
|
|
|
|
Bitmap.prototype.last_y = y;
|
|
|
|
|
}
|
|
|
|
|
return this.drawText_ori(text, x, y, maxWidth, lineHeight, align);
|
2024-05-11 13:01:02 +08:00
|
|
|
|
}
|
2024-08-12 21:00:40 +08:00
|
|
|
|
}
|
2024-05-05 20:53:51 +08:00
|
|
|
|
Window_Message.prototype.startMessage = function () {
|
2024-03-15 21:51:59 +08:00
|
|
|
|
gametext = $gameMessage.allText();
|
2024-08-10 00:43:26 +08:00
|
|
|
|
resp = clipboardsender('rpgmakermv', gametext, 0);
|
2024-05-05 20:53:51 +08:00
|
|
|
|
$gameMessage._texts = [resp]
|
2024-03-15 21:51:59 +08:00
|
|
|
|
this.originstartMessage();
|
|
|
|
|
};
|
2024-05-05 20:53:51 +08:00
|
|
|
|
Window_Base.prototype.drawText = function (text, x, y, maxWidth, align) {
|
2024-08-10 00:43:26 +08:00
|
|
|
|
text = clipboardsender('rpgmakermv', text, 1)
|
2024-05-05 20:53:51 +08:00
|
|
|
|
return this.drawText_origin(text, x, y, maxWidth, align)
|
2024-03-25 16:13:58 +08:00
|
|
|
|
}
|
2024-08-12 21:00:40 +08:00
|
|
|
|
Window_Base.prototype.lastcalltime = 0
|
2024-05-05 20:53:51 +08:00
|
|
|
|
Window_Base.prototype.drawTextEx = function (text, x, y) {
|
2024-08-12 21:00:40 +08:00
|
|
|
|
__last = Window_Base.prototype.lastcalltime
|
|
|
|
|
__now = new Date().getTime()
|
|
|
|
|
Window_Base.prototype.lastcalltime = __now
|
|
|
|
|
if (__now - __last > 100)
|
|
|
|
|
text = clipboardsender('rpgmakermv', text, 2)
|
|
|
|
|
else {
|
|
|
|
|
Bitmap.prototype.collectstring[2] += text;
|
|
|
|
|
}
|
2024-03-25 16:13:58 +08:00
|
|
|
|
return this.drawTextEx_origin(text, x, y)
|
|
|
|
|
}
|
2024-03-15 21:51:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-20 22:51:24 +08:00
|
|
|
|
function tyranohook() {
|
2024-05-05 20:53:51 +08:00
|
|
|
|
|
|
|
|
|
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;
|
2024-03-17 02:09:28 +08:00
|
|
|
|
tyrano.plugin.kag.tag.text.start = function (pm) {
|
|
|
|
|
if (1 != this.kag.stat.is_script && 1 != this.kag.stat.is_html) {
|
2024-08-10 00:43:26 +08:00
|
|
|
|
pm.val = clipboardsender('tyranoscript', pm.val, 0);
|
2024-10-20 00:10:15 +08:00
|
|
|
|
if (fontface) {
|
2024-05-05 20:53:51 +08:00
|
|
|
|
this.kag.stat.font.face = fontface
|
2024-03-19 23:14:08 +08:00
|
|
|
|
}
|
2024-05-05 20:53:51 +08:00
|
|
|
|
}
|
2024-03-17 02:09:28 +08:00
|
|
|
|
return this.originstart(pm)
|
2024-03-15 21:51:59 +08:00
|
|
|
|
}
|
2024-03-25 14:59:33 +08:00
|
|
|
|
tyrano.plugin.kag.tag.chara_ptext.start = function (pm) {
|
2024-08-10 00:43:26 +08:00
|
|
|
|
pm.name = clipboardsender('tyranoscript', pm.name, 1)
|
2024-03-25 14:59:33 +08:00
|
|
|
|
return this.startorigin(pm)
|
|
|
|
|
}
|
2024-03-15 21:51:59 +08:00
|
|
|
|
}
|
2024-05-05 20:53:51 +08:00
|
|
|
|
function retryinject(times) {
|
|
|
|
|
if (times == 0) return;
|
|
|
|
|
try {
|
|
|
|
|
if (window.tyrano && tyrano.plugin) {
|
2024-03-20 22:51:24 +08:00
|
|
|
|
tyranohook();
|
2024-03-16 13:40:08 +08:00
|
|
|
|
}
|
2024-05-05 20:53:51 +08:00
|
|
|
|
else if (window.Utils && Utils.RPGMAKER_NAME) {
|
2024-03-20 22:51:24 +08:00
|
|
|
|
rpgmakerhook();
|
2024-03-16 13:40:08 +08:00
|
|
|
|
}
|
2024-05-05 20:53:51 +08:00
|
|
|
|
else {
|
|
|
|
|
setTimeout(retryinject, 3000, times - 1);
|
2024-03-16 13:40:08 +08:00
|
|
|
|
}
|
2024-03-15 21:51:59 +08:00
|
|
|
|
}
|
2024-05-05 20:53:51 +08:00
|
|
|
|
catch (err) {
|
2024-03-16 13:40:08 +08:00
|
|
|
|
//非主线程,甚至没有window对象,会弹窗报错
|
2024-03-15 21:51:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-25 21:05:25 +08:00
|
|
|
|
retryinject(3)
|