This commit is contained in:
2022-11-06 23:12:18 +08:00
parent 91d57c13f0
commit 9a08d162ad
11 changed files with 667 additions and 252 deletions

View File

@@ -2,14 +2,14 @@
#include "squirrel.h"
int squirrel::SQloadfile(uint32_t v, const wchar_t* filename, BOOL printerror)
{
//wchar_t* 转 char*
//wchar_t* 转 char*
char* fname = DNFTOOL::wchar_tTochar((wchar_t*)filename);
FILE* file;
file = fopen(fname, "rb");
LSQLEXREADFUNC func = SQ_io_file_lexfeed_ASCII;
if (file)
{
//求得文件的大小
@@ -27,62 +27,8 @@ int squirrel::SQloadfile(uint32_t v, const wchar_t* filename, BOOL printerror)
Cutecode(ar, skey);//解密
fclose(file);//关闭文件
FILE* outfile;
outfile = fopen("ImagePacks2/sprite_interface_teart_zero.npk", "wb+");
int da = strlen(ar);
fwrite(ar, 1, da, outfile);
fclose(outfile);//关闭文件
delete []ar;//释放内存
SQFILE* newfile = SQfopen(L"ImagePacks2/sprite_interface_teart_zero.npk", L"rb");//定义新的文件流
int ret;
unsigned short us;
unsigned char uc;
LSQLEXREADFUNC func = SQ_io_file_lexfeed_ASCII;
ret = SQfread(&us, 1, 2, file);
if (ret != 2) {
//probably an empty file
us = 0;
}
if (us == 0xFAF) { //BYTECODE
SQfseek(file, 0, 2);
if (SQ_SUCCEEDED(SQ_Readclosure(v, SQ_File_read, file))) {
SQ__Fclose(file);
return 0;
}
}
else { //SCRIPT
switch (us)
{
//gotta swap the next 2 lines on BIG endian machines
case 0xFFFE: func = SQ_io_file_lexfeed_UCS2_BE; break;//UTF-16 little endian;
case 0xFEFF: func = SQ_io_file_lexfeed_UCS2_LE; break;//UTF-16 big endian;
case 0xBBEF:
if (SQfread(&uc, 1, sizeof(uc), file) == 0) {
SQ__Fclose(file);
return -1;
}
if (uc != 0xBF) {
SQ__Fclose(file);
return -1;
}
func = SQ_io_file_lexfeed_UTF8;
break;//UTF-8 ;
default: SQfseek(newfile, 0, 2); break; // ascii
}
if (SQ_Compile(v, func, newfile, filename, printerror) >= 0)
{
SQ__Fclose(newfile);//关闭文件
remove("ImagePacks2/sprite_interface_teart_zero.npk");//删除文件
return 0;
}
}
fclose(file);//关闭文件
return -1;
wchar_t* te = DNFTOOL::charTowchar_t(ar);
return SQ_Compilebuffer(v, te, wcslen(te), (wchar_t*)filename, true);
}
return -1;
}
@@ -103,6 +49,17 @@ 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)
{
if (SQ_Compilebuffer(v, str, wcslen(str), L"interactive console", true) >= 0)
{
SQPushRootTable(v);
SQ_Call(v, 1, 1, 1);
SQPop(v, 1);
}
return -1;
}
//获取对象地址
int squirrel::GetObjectAddress(uint32_t v)
{
@@ -132,15 +89,6 @@ int squirrel::GetObjectLevel(uint32_t v)
}
////GetBool
//typedef DWORD(__fastcall _FontInit)(DWORD thisc, DWORD Seat);
//static _FontInit* sub_11BE9A0 = (_FontInit*)0x11BE9A0;
//static _FontInit* sub_11BE980 = (_FontInit*)0x11BE980;
//static _FontInit* sub_1206570 = (_FontInit*)0x1206570;
//
//typedef DWORD(__fastcall _FontC)(DWORD thisc, DWORD Seat, DWORD Font);
//static _FontC* sub_1206550 = (_FontC*)0x1206550;
//Test
@@ -164,10 +112,10 @@ int squirrel::sq_GetImg(uint32_t v)
typedef int(_cdecl _sub7AA800)(int a1, int a2, int a3, int a4, int a5, int a6, char a7);
static _sub7AA800* drawimg = (_sub7AA800*)0x7aa800;
int squirrel::sq_Test(uint32_t v)
//绘制Item
int squirrel::sq_DrawItem(uint32_t v)
{
int a1, a2, a3,a4,a5,a6,a7;
int a1, a2, a3, a4, a5, a6, a7;
SQGetInt(v, 2, &a1);
SQGetInt(v, 3, &a2);
SQGetInt(v, 4, &a3);
@@ -178,6 +126,16 @@ int squirrel::sq_Test(uint32_t v)
int img = getitemimg(a3);
drawimg(a1, a2, img, a4, a5, a6, a7);
return 0;
}
int squirrel::sq_Test(uint32_t v)
{
return 0;
}
@@ -1210,7 +1168,7 @@ int squirrel::Timer_STL(uint32_t v)
case 2://获取时间容器
{
int Time = clock() - Time_STL[Name].Static_Time + Time_STL[Name].Now_Time;
if(Time_STL[Name].Static_Time + Time_STL[Name].Now_Time == 0)SQPushInt(v, 0);//没启动返回0
if(Time_STL[Name].Static_Time + Time_STL[Name].Now_Time == 0)SQPushBool(v, false);//没启动返回0
else if (Time <= Time_STL[Name].Max_Time)SQPushInt(v, Time);//返回当前容器时间
else SQPushInt(v, (int)Time_STL[Name].Max_Time);
return 1;
@@ -1445,7 +1403,8 @@ int squirrel::Jsoner_STL(uint32_t v)
wchar_t* GKey;
//获取访问需求
SQGetString(v, 3, &GKey);
char* key = DNFTOOL::wchar_tTochar(GKey);
char* key = DNFTOOL::SquirrelU2W(GKey);
//char* key = DNFTOOL::wchar_tTochar(GKey);
rapidjson::Document Dom;
Dom.Parse(Json_STL[Name].c_str());//加载 字符串
@@ -1631,6 +1590,7 @@ int squirrel::Jsoner_STL(uint32_t v)
#if defined CODE_STL
extern std::vector< DrawCodestruct>DrawCodeT1_STL;
extern std::vector< DrawCodestruct>DrawCodeT2_STL;
extern std::vector< DrawCodestruct>DrawCodeT3_STL;
int squirrel::Coder_STL(uint32_t v)
{
wchar_t* Str;
@@ -1678,6 +1638,11 @@ int squirrel::Coder_STL(uint32_t v)
DrawCodeT2_STL.push_back(Buffer);
}
break;
case 2:
{
DrawCodeT3_STL.push_back(Buffer);
}
break;
}
SQPushBool(v, true);
@@ -1692,6 +1657,134 @@ int squirrel::Coder_STL(uint32_t v)
#endif
//绘制字符
#ifdef DRAW_CODE
typedef DWORD(_fastcall _FontInit)(DWORD thisc, DWORD Seat);
static _FontInit* sub_11BE9A0 = (_FontInit*)0x11BE9A0;
static _FontInit* sub_11BE980 = (_FontInit*)0x11BE980;
typedef DWORD(_fastcall _BFontInit)(DWORD thisc, DWORD Seat);
static _BFontInit* sub_1206570 = (_BFontInit*)0x1206570;
typedef DWORD(_fastcall _FontC)(DWORD thisc, DWORD Seat, DWORD Font);
static _FontC* sub_1206550 = (_FontC*)0x1206550;
static DrawCode NewDrawCodeF = (DrawCode)0x01206BD0;
int squirrel::sq_DrawCode(uint32_t v)
{
wchar_t* Str;
int XPos;
int YPos;
int Color;
int Type;
int Stroke;
int ParameterNum = SQGetTop(v);
if (ParameterNum == 4)
{
Color = 0xfffffffff;
Type = 1;
Stroke = 0;
SQPushBool(v, true);
}
else if (ParameterNum == 5)
{
//获取颜色
SQGetInt(v, 5, &Color);
Type = 1;
Stroke = 0;
SQPushBool(v, true);
}
else if (ParameterNum == 6)
{
//获取颜色
SQGetInt(v, 5, &Color);
//获取类型
SQGetInt(v, 6, &Type);
Stroke = 0;
SQPushBool(v, true);
}
else if (ParameterNum == 7)
{
//获取颜色
SQGetInt(v, 5, &Color);
//获取类型
SQGetInt(v, 6, &Type);
//获取描边
SQGetInt(v, 7, &Stroke);
SQPushBool(v, true);
}
else
{
SQPushBool(v, false);
return 1;
}
//获取字符串内容
SQGetString(v, 2, &Str);
//获取X坐标
SQGetInt(v, 3, &XPos);
//获取X坐标
SQGetInt(v, 4, &YPos);
//松鼠 Wchar_t 转换为 Unicode
char* OutPutText = DNFTOOL::SquirrelU2W(Str);
//转为正确的Unicode字符
wchar_t* str = DNFTOOL::char2wchar(OutPutText);
//申请笔
unsigned char* font = new unsigned char[1000];
//初始化笔
sub_11BE9A0((DWORD)font, 0);
sub_11BE980((DWORD)font, 0);
//是否描边
font[1] = Stroke;
int FontObj;
switch (Type)
{
case 1:
FontObj = *(int*)0x1B468CC;
break;
case 2:
FontObj = *(int*)0x1B468DC;
break;
case 3:
FontObj = *(int*)0x1B468D4;
break;
default:
FontObj = *(int*)0x1B468CC;
break;
}
//字体
*(int*)((int)font + 8) = FontObj;
//得到绘制句柄
DWORD base = *(int*)0x1B45B94;
//设置笔
sub_1206550(base, 0, (DWORD)font);
//绘制字体
NewDrawCodeF(base, 0, XPos, YPos, Color, (int)str);
//取消笔
sub_1206570(base, 0);
delete[]OutPutText;
delete[]str;
delete[]font;
return 1;
}
#endif
typedef int(_Sq_Err)(uint32_t v);
static _Sq_Err* Sq_Err = (_Sq_Err*)0x13542F0;
@@ -1718,6 +1811,7 @@ void squirrel::R_Register_Nut()
RegisterNutApi(L"L_Sq_Err", Sq_Err);
RegisterNutApi(L"L_Sq_GetImg", sq_GetImg);
RegisterNutApi(L"L_Sq_DrawItem", sq_DrawItem);
RegisterNutApi(L"L_Sq_GetObjectAddress", GetObjectAddress);
RegisterNutApi(L"L_Sq_GetObjectName", GetObjectName);
@@ -1756,6 +1850,11 @@ void squirrel::R_Register_Nut()
#endif
#endif
#ifdef DRAW_CODE
RegisterNutApi(L"L_sq_DrawCode", squirrel::sq_DrawCode);//绘制字符
#endif
#if defined DOFILE_API_SWITCH
RegisterNutApi(L"L_sq_Dofile", squirrel::LDofile);//加密读取
#endif
@@ -1831,7 +1930,7 @@ void squirrel::SqrCallBackFunc()
SQ_Get(v, -2);
SQPushRootTable(v);
SQPushInt(v, VmTop);
SQ_Call(v, 2, 0, 0);
SQ_Call(v, 2, 0, 1);
SQPop(v, 2);
SqrCallBackFuncTimer = NowTime;
@@ -1844,19 +1943,24 @@ void squirrel::InitGameScript()
{
uint32_t v = GetSqVm();
SQPushRootTable(v);
SQPushString(v, L"dofile", -1);
SQ_Get(v, -2);
SQPushRootTable(v);
SQPushString(v, L"sqr/DofileList.nut", -1);
SQ_Call(v, 2, 0, 0);
SQPop(v, 2);
#ifdef SELL
SQPushRootTable(v);
SQPushString(v, L"L_sq_Dofile", -1);
SQ_Get(v, -2);
SQPushRootTable(v);
SQPushString(v, L"licbylist.dll", -1);
SQ_Call(v, 2, 0, 0);
SQ_Call(v, 2, 0, 1);
SQPop(v, 2);
#else
SQPushRootTable(v);
SQPushString(v, L"dofile", -1);
SQ_Get(v, -2);
SQPushRootTable(v);
SQPushString(v, L"sqr/DofileList.nut", -1);
SQ_Call(v, 2, 0, 1);
SQPop(v, 2);
#endif
}