This commit is contained in:
2024-05-21 12:30:12 +08:00
parent c1da677abb
commit b5dbfdf73a
12 changed files with 222 additions and 67 deletions

View File

@@ -1,7 +1,51 @@
#include "pch.h"
#include "lsquirrel.h"
#include "sqstdsystem.h"
#include <ctime>
#include <sstream>
struct BufState {
const wchar_t* buf;
int ptr;
int size;
};
int sq_mycompilebuffer(uint32_t v, const wchar_t* s, int size, const wchar_t* filename, BOOL printerror) {
BufState buf;
buf.buf = s;
buf.size = size;
buf.ptr = 0;
return SQ_Compile(v, (LSQLEXREADFUNC)0x1359AD0, &buf, filename, printerror);
}
int squirrel::SQdofileBuffer(uint32_t v, const wchar_t* filename, const wchar_t* str)
{
//sq_compilebuffer((HSQUIRRELVM)v, str, wcslen(str), L"interactive console", false);
////int oldtop = SQGetTop(v);
//if (SQ_Compilebuffer(v, str, wcslen(str), L"interactive console", false) >= 0)
//{
// SQPushRootTable(v);
// SQ_Call(v, 1, 1, 1);
// SQPop(v, 1);
//}
////SQPop(v, oldtop);
#ifdef SELLDEBUG
if (sq_mycompilebuffer(v, str, wcslen(str), filename, true) >= 0) {
SQPushRootTable(v);
SQ_Call(v, 1, 1, 1);
SQPop(v, 1);
}
#else
if (sq_mycompilebuffer(v, str, wcslen(str), L"interactive console", false) >= 0) {
SQPushRootTable(v);
SQ_Call(v, 1, 1, 0);
SQPop(v, 1);
}
#endif // SELLDEBUG
return -1;
}
int squirrel::SQloadfile(uint32_t v, const wchar_t* filename, BOOL printerror)
@@ -50,18 +94,7 @@ int squirrel::SQdofile(uint32_t v, const wchar_t* filename, BOOL retval, BOOL pr
}
int squirrel::SQdofileBuffer(uint32_t v, const wchar_t* filename, const wchar_t* str)
{
//int oldtop = SQGetTop(v);
if (SQ_Compilebuffer(v, str, wcslen(str), L"interactive console", false) >= 0)
{
SQPushRootTable(v);
SQ_Call(v, 1, 1, 1);
SQPop(v, 1);
}
//SQPop(v, oldtop);
return -1;
}
int squirrel::LenheartGetIntData(uint32_t v)
{
@@ -2513,9 +2546,43 @@ int squirrel::sq_Cmd(uint32_t v)
char* OutPutText = DNFTOOL::SquirrelU2W(OutPutBuffer);
system(OutPutText);
//WinExec(OutPutText, SW_NORMAL);
//WinExec(OutPutText, SW_HIDE);
delete[]OutPutText;
return 1;
return 0;
}
int sq_CmdEx(uint32_t v)
{
wchar_t* OutPutBuffer;
SQGetString(v, 2, &OutPutBuffer);
char* OutPutText = DNFTOOL::SquirrelU2W(OutPutBuffer);
STARTUPINFOA si = { sizeof(STARTUPINFO) };
PROCESS_INFORMATION pi;
// 创建新进程
BOOL result = CreateProcessA(
NULL, // 应用程序名称
OutPutText, // 命令行参数
NULL, // 进程安全属性
NULL, // 线程安全属性
FALSE, // 继承句柄选项
0, // 创建标志
NULL, // 环境变量
NULL, // 当前目录
&si, // STARTUPINFO
&pi // PROCESS_INFORMATION
);
if (result) {
// 不等待新进程结束,直接关闭句柄
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
else {
}
delete[]OutPutText;
return 0;
}
//设置UI槽坐标
int squirrel::SetSlot(uint32_t v)
@@ -3671,6 +3738,7 @@ void squirrel::R_Register_Nut()
#if defined NEW_WINDOW_API_SWITCH
RegisterNutApi(L"L_NewWindows", squirrel::NewWindows);//创建窗口
RegisterNutApi(L"L_Cmd", squirrel::sq_Cmd);//创建窗口
RegisterNutApi(L"L_CmdEx", sq_CmdEx);//创建窗口
#endif
#if defined SET_SLOT_API_SWITCH
@@ -3837,6 +3905,10 @@ void printfunc(HSQUIRRELVM v, const SQChar* s, ...)
void squirrel::InitGameScript()
{
uint32_t v = GetSqVm();
//消息框黏贴
#ifdef COPY_MESSAGE
* (WORD*)0x011C53B0 = 0x01B0;