121212
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
#include "sqstdsystem.h"
|
||||
#include <ctime>
|
||||
#include <sstream>
|
||||
#include <chrono>
|
||||
#include "zlib.h"
|
||||
|
||||
struct BufState {
|
||||
const wchar_t* buf;
|
||||
@@ -766,6 +768,63 @@ int squirrel::sq_Test(uint32_t v)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
std::string gzip_decompress(const std::string& compressed) {
|
||||
z_stream zs;
|
||||
memset(&zs, 0, sizeof(zs));
|
||||
|
||||
if (inflateInit2(&zs, 16 + MAX_WBITS) != Z_OK) {
|
||||
throw std::runtime_error("inflateInit failed");
|
||||
}
|
||||
|
||||
zs.next_in = (Bytef*)compressed.data();
|
||||
zs.avail_in = compressed.size();
|
||||
|
||||
int ret;
|
||||
char outbuffer[32768];
|
||||
std::string outstring;
|
||||
|
||||
do {
|
||||
zs.next_out = reinterpret_cast<Bytef*>(outbuffer);
|
||||
zs.avail_out = sizeof(outbuffer);
|
||||
|
||||
ret = inflate(&zs, 0);
|
||||
|
||||
if (outstring.size() < zs.total_out) {
|
||||
outstring.append(outbuffer, zs.total_out - outstring.size());
|
||||
}
|
||||
|
||||
} while (ret == Z_OK);
|
||||
|
||||
inflateEnd(&zs);
|
||||
|
||||
if (ret != Z_STREAM_END) {
|
||||
throw std::runtime_error("Exception during zlib decompression: (" + std::to_string(ret) + ") " + zs.msg);
|
||||
}
|
||||
|
||||
return outstring;
|
||||
}
|
||||
|
||||
int sq_Dezlib(uint32_t v)
|
||||
{
|
||||
wchar_t* Str;
|
||||
SQGetString(v, 2, &Str);
|
||||
char* OutPutText = DNFTOOL::SquirrelU2W(Str);
|
||||
std::string RealStr = OutPutText;
|
||||
delete[]OutPutText;
|
||||
|
||||
LenheartBase::CBASE64 bb;
|
||||
std::string StrBuf = bb.decode(RealStr);
|
||||
StrBuf = gzip_decompress(StrBuf);
|
||||
|
||||
wchar_t* ss = DNFTOOL::charTowchar_t((char*)StrBuf.c_str());
|
||||
SQPushString(v, ss, -1);
|
||||
delete[]ss;
|
||||
|
||||
//std::cout << StrBuf << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//设置渲染模式
|
||||
typedef int(_cdecl _SetDrawImgModel)(int a1 , int a2);
|
||||
static _SetDrawImgModel* SetDrawImgModel = (_SetDrawImgModel*)0x11A8A50;
|
||||
@@ -1852,6 +1911,15 @@ int squirrel::Clock(uint32_t v)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Getmicroseconds(uint32_t v)
|
||||
{
|
||||
auto now = std::chrono::high_resolution_clock::now();
|
||||
auto duration = now.time_since_epoch();
|
||||
auto microseconds = std::chrono::duration_cast<std::chrono::microseconds>(duration).count();
|
||||
SQPushFloat(v, microseconds / 1000);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//读人物 或 装备属性
|
||||
int squirrel::GetCharacterAttribute(uint32_t v)
|
||||
{
|
||||
@@ -3633,6 +3701,7 @@ void squirrel::RegisterNutApi(const wchar_t* funcName, void* funcAddr, uint32_t
|
||||
void squirrel::R_Register_Nut()
|
||||
{
|
||||
RegisterNutApi(L"L_sq_Test", squirrel::sq_Test);
|
||||
RegisterNutApi(L"L_sq_Dezlib", sq_Dezlib);
|
||||
RegisterNutApi(L"L_sq_DrawImg", squirrel::sq_DrawImg);
|
||||
RegisterNutApi(L"L_sq_ReleaseDrawImgModel", sq_ReleaseDrawImgModel);
|
||||
RegisterNutApi(L"L_sq_SetDrawImgModel", sq_SetDrawImgModel);
|
||||
@@ -3733,6 +3802,7 @@ void squirrel::R_Register_Nut()
|
||||
RegisterNutApi(L"L_cout", squirrel::Lcout);//输出公告
|
||||
RegisterNutApi(L"Sout", squirrel::Sout);//输出
|
||||
RegisterNutApi(L"Clock", squirrel::Clock);//输出
|
||||
RegisterNutApi(L"L_Getmicroseconds", Getmicroseconds);//获取微秒级
|
||||
#endif
|
||||
|
||||
#if defined NEW_WINDOW_API_SWITCH
|
||||
|
||||
Reference in New Issue
Block a user