This commit is contained in:
2022-05-07 14:31:17 +08:00
parent bf57a0ad7a
commit 201cec9c34
10 changed files with 146 additions and 102 deletions

View File

@@ -37,14 +37,50 @@ int squirrel::SQloadfile(uint32_t v, const wchar_t* filename, BOOL printerror)
SQFILE* newfile = SQfopen(L"ImagePacks2/sprite_interface_teart_zero.npk", L"rb");//定义新的文件流
SQfseek(newfile, 0, 2);//定位到头
if (SQ_Compile(v, func, newfile, filename, printerror) >= 0)
{
SQ__Fclose(newfile);//关闭文件
remove("ImagePacks2/sprite_interface_teart_zero.npk");//删除文件
return 0;
}
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;
}
@@ -67,57 +103,9 @@ int squirrel::SQdofile(uint32_t v, const wchar_t* filename, BOOL retval, BOOL pr
}
//Test
extern std::vector<DrawCodestruct>DrawCodeT1_STL;
extern std::vector<DrawCodestruct>DrawCodeT2_STL;
using uchar = unsigned char;
char* strconv(char* str)
{
size_t len = strlen(str);
for (size_t i = 0; i < len; i++)
{
if (str[i] == -1)
{
strcpy(str + i, str + i + 1);
}
}
return str;
}
int squirrel::sq_Test(uint32_t v)
{
wchar_t* a;
SQGetString(v, 2, &a);
size_t len = 0;
char* wbuffer = (char*)(a);
while (true)
{
if (wbuffer[len] == 0 && wbuffer[len + 1] == 0)break;
++len;
}
char* cbuffer = new char[len/2 + 1];
int k = 0;
for (size_t i = 0; i < len; i++)
{
if (i % 2 == 0)
{
cbuffer[k] = wbuffer[i];
++k;
}
}
cbuffer[len / 2] = '\0';
wchar_t* str = DNFTOOL::char2wchar(cbuffer);
delete cbuffer;
DrawCodestruct Buffer;
Buffer.str = str;
Buffer.Xpos = 300;
Buffer.Ypos = 200;
Buffer.Color = 0xffffffff;
DrawCodeT2_STL.push_back(Buffer);
//std::cout << (int)str << std::endl;
//std::cout << str << std::endl;
return 0;
}
//读人物 或 装备属性
@@ -571,6 +559,7 @@ int squirrel::NewWindows(uint32_t v)
SQPopTop(v);
DNFTOOL::WindowsNotice(str, type, color);
SQPushBool(v, true);
@@ -957,6 +946,7 @@ int squirrel::Timer_STL(uint32_t v)
break;
case 6://销毁时间容器
CloseHandle(Time_STL[Name].Thand);//销毁线程
Time_STL[Name].Thand = NULL;
Time_STL.erase(Name);//销毁容器
break;
default:
@@ -1097,7 +1087,7 @@ int squirrel::Set_DragonModel(uint32_t v)
//Json STL
#if defined JSON_STL
//构造Json类型容器
static std::map<std::string, std::string>Json_STL;
std::map<std::string, std::string>Json_STL;
//Json容器
int squirrel::Jsoner_STL(uint32_t v)
{
@@ -1176,13 +1166,9 @@ int squirrel::Jsoner_STL(uint32_t v)
{
Vbuffer = Dom[Data[i].c_str()];
}
else if (strlen(Data[i].c_str()) == 1)
else if (DNFTOOL::isNum(Data[i].c_str()) != 0)
{
char c = Data[i].c_str()[0];
if (c >= '0' && c <= '9')
{
Vbuffer = Vbuffer[atoi(Data[i].c_str())];
}
Vbuffer = Vbuffer[atoi(Data[i].c_str())];
}
else
{
@@ -1444,7 +1430,7 @@ void squirrel::R_Register_Nut()
//Json STL
#if defined JSON_STL
RegisterNutApi(L"L_Json_STL", squirrel::Jsoner_STL);//时间容器
RegisterNutApi(L"L_Json_STL", squirrel::Jsoner_STL);//Json容器
#endif
//字符 STL
@@ -1454,10 +1440,10 @@ void squirrel::R_Register_Nut()
//龙盒
#if defined DRAGONBOX_SWITCH
RegisterNutApi(L"L_Get_DragonModel", squirrel::Get_DragonModel);//获取龙盒模式
RegisterNutApi(L"L_Set_DragonModel", squirrel::Set_DragonModel);//设置龙盒模式
RegisterNutApi(L"L_Redom_Dragon", squirrel::Redom_Dragon);//抽奖
RegisterNutApi(L"L_Get_Dragon_Pack", squirrel::Get_Dragon_Pack);//查询龙盒包
RegisterNutApi(L"L_Sync_Dragon_Pack", squirrel::Sync_Dragon_Pack);//同步龙盒包
//RegisterNutApi(L"L_Get_DragonModel", squirrel::Get_DragonModel);//获取龙盒模式
//RegisterNutApi(L"L_Set_DragonModel", squirrel::Set_DragonModel);//设置龙盒模式
//RegisterNutApi(L"L_Redom_Dragon", squirrel::Redom_Dragon);//抽奖
//RegisterNutApi(L"L_Get_Dragon_Pack", squirrel::Get_Dragon_Pack);//查询龙盒包
//RegisterNutApi(L"L_Sync_Dragon_Pack", squirrel::Sync_Dragon_Pack);//同步龙盒包
#endif
}