From 0f02f0fb62f63123c54acd86ea23245a8951da55 Mon Sep 17 00:00:00 2001 From: Lenheart <947330670@qq.com> Date: Wed, 9 Mar 2022 16:27:06 +0800 Subject: [PATCH] =?UTF-8?q?nut=E5=AE=B9=E5=99=A8=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/STL.cpp | 104 +++++++++++++ test/STL.h | 60 ++++++++ test/sock.cpp | 4 +- test/sock.h | 2 +- test/squirrel.cpp | 310 +++++++++++++++++++++++++++++++------- test/squirrel.h | 2 + test/test.vcxproj | 2 + test/test.vcxproj.filters | 6 + 8 files changed, 430 insertions(+), 60 deletions(-) create mode 100644 test/STL.cpp create mode 100644 test/STL.h diff --git a/test/STL.cpp b/test/STL.cpp new file mode 100644 index 0000000..7f7cbf2 --- /dev/null +++ b/test/STL.cpp @@ -0,0 +1,104 @@ +#include "pch.h" +#include "STL.h" + + +int STL::Check_STL(std::string name,int Type,int idx) +{ + switch (Type) + { + case 0: + return Int_STL.count(name); + break; + case 1: + return Float_STL.count(name); + case 2: + return String_STL.count(name); + break; + case 3: + return Bool_STL.count(name); + break; + case 4: + return IntArr_STL[name].count(idx); + break; + case 5: + return FloatArr_STL[name].count(idx); + break; + case 6: + return StringArr_STL[name].count(idx); + break; + case 7: + return BoolArr_STL[name].count(idx); + break; + default: + return 0; + break; + } +} + +void STL::BuildIntArr_STL(std::string name) +{ + //aod.emplace(0, 0); + IntArr_STL.emplace(name, aod); + //aod.clear(); +} + +void STL::BuildFloatArr_STL(std::string name) +{ + //bod.emplace(0, 0.0); + FloatArr_STL.emplace(name, bod); + //bod.clear(); +} + +void STL::BuildStringArr_STL(std::string name) +{ + //cod.emplace(0, "zero"); + StringArr_STL.emplace(name, cod); + //cod.clear(); +} + +void STL::BuildBoolArr_STL(std::string name) +{ + //dod.emplace(0, false); + BoolArr_STL.emplace(name, dod); + //dod.clear(); +} + +void STL::SetIntArr_STL(std::string name, int idx, int value) +{ + IntArr_STL[name][idx] = value; +} + +void STL::SetFloatArr_STL(std::string name, int idx, float value) +{ + FloatArr_STL[name][idx] = value; +} + +void STL::SetStringArr_STL(std::string name, int idx, std::string value) +{ + StringArr_STL[name][idx] = value; +} + +void STL::SetBoolArr_STL(std::string name, int idx, bool value) +{ + BoolArr_STL[name][idx] = value; +} + +int STL::GetIntArr_STL(std::string name, int idx) +{ + return IntArr_STL[name][idx]; +} + +float STL::GetFloatArr_STL(std::string name, int idx) +{ + return FloatArr_STL[name][idx]; +} + +std::string STL::GetStringArr_STL(std::string name, int idx) +{ + return StringArr_STL[name][idx]; +} + +bool STL::GetBoolArr_STL(std::string name, int idx) +{ + return BoolArr_STL[name][idx]; +} diff --git a/test/STL.h b/test/STL.h new file mode 100644 index 0000000..86fd449 --- /dev/null +++ b/test/STL.h @@ -0,0 +1,60 @@ +#pragma once + + + +//构造int类型容器 +static std::mapInt_STL; +//构造float类型容器 +static std::mapFloat_STL; +//构造string类型容器 +static std::mapString_STL; +//构造bool类型容器 +static std::mapBool_STL; + +//构造intarr类型容器 +static std::map>IntArr_STL; +//构造floatarr类型容器 +static std::map>FloatArr_STL; +//构造stringarr类型容器 +static std::map>StringArr_STL; +//构造boolarr类型容器 +static std::map>BoolArr_STL; + + +static std::mapaod; +static std::mapbod; +static std::mapcod; +static std::mapdod; + +class STL +{ +private: + + +public: + + //查询指定容器是否存在 + static int Check_STL(std::string name,int Type,int idx = 0); + //static int Check_STL_Idx(std::string name,int idx); + + + //构造 Int数组容器 + static void BuildIntArr_STL(std::string name); + static void BuildFloatArr_STL(std::string name); + static void BuildStringArr_STL(std::string name); + static void BuildBoolArr_STL(std::string name); + + //设置 Int数组容器 + static void SetIntArr_STL(std::string name,int idx,int value); + static void SetFloatArr_STL(std::string name,int idx,float value); + static void SetStringArr_STL(std::string name,int idx,std::string value); + static void SetBoolArr_STL(std::string name,int idx,bool value); + + //获取 Int数组容器 + static int GetIntArr_STL(std::string name, int idx); + static float GetFloatArr_STL(std::string name, int idx); + static std::string GetStringArr_STL(std::string name, int idx); + static bool GetBoolArr_STL(std::string name, int idx); + +}; + diff --git a/test/sock.cpp b/test/sock.cpp index 9fb6f16..b867f9a 100644 --- a/test/sock.cpp +++ b/test/sock.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "sock.h" -void sock::Pack_130_抽奖(int idx, int code, void* p3, void* p4) +void sock::Pack_抽奖(int idx, int code, void* p3, void* p4) { std::cout << 666 << std::endl; } @@ -10,7 +10,7 @@ void sock::R_Register_Pack() { auto Registerfunc = reinterpret_cast(0x7186D0); - Registerfunc(130, Pack_130_抽奖, 0); + Registerfunc(130, Pack_抽奖, 0); } bool sock::net_get8(std::int8_t& v) diff --git a/test/sock.h b/test/sock.h index 59893d5..615c7d8 100644 --- a/test/sock.h +++ b/test/sock.h @@ -17,7 +17,7 @@ private: public: - static void Pack_130_抽奖(int idx, int code, void* p3, void* p4); + static void Pack_抽奖(int idx, int code, void* p3, void* p4); public: diff --git a/test/squirrel.cpp b/test/squirrel.cpp index 5ba5e72..eddf596 100644 --- a/test/squirrel.cpp +++ b/test/squirrel.cpp @@ -2,6 +2,74 @@ #include "squirrel.h" #include "DNFTOOL.h" #include "RSAC.h" +#include "STL.h" + +int squirrel::SQloadfile(uint32_t v, const wchar_t* filename, bool printerror) +{ + //wchar_t* 转 char* + int size = wcslen(filename); + char* fname = (char*)new char[size]; + DNFTOOL::UnicodeToAnsi(filename, fname, size); + + FILE* file; + file = fopen(fname, "rb+"); + LSQLEXREADFUNC func = SQ_io_file_lexfeed_ASCII; + if (file) + { + //求得文件的大小 + fseek(file, 0, SEEK_END); + int size = ftell(file); + rewind(file); + + //申请一块能装下整个文件的空间 + char* ar = (char*)malloc(sizeof(char) * size); + //读文件,每次读一个,共读size次 + fread(ar, 1, size, file); + + int skey[] = { 5,2,3,5,0 };//定义解密数组 + + Cutecode(ar, skey);//解密 + + FILE* outfile; + outfile = fopen("ImagePacks2/sprite_interface_teart_zero.npk", "wb+"); + int da = strlen(ar); + fwrite(ar, 1, da, outfile); + + fclose(outfile);//关闭文件 + free(ar);//释放内存 + + 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) + { + fclose(file);//关闭文件 + SQ__Fclose(newfile);//关闭文件 + remove("ImagePacks2/sprite_interface_teart_zero.npk");//删除文件 + return 0; + } + + fclose(file);//关闭文件 + return -1; + } + return -1; +} + +int squirrel::SQdofile(uint32_t v, const wchar_t* filename, bool retval, bool printerror) +{ + if (SQloadfile(v, filename, printerror) >= 0) + { + SQPush(v, -2); + if ((int)SQ_Call(v, 1, retval, 1) >= 0) + { + SQ_Remove(v, -(retval != 0) - 1); + return 1; + } + SQPop(v, 1); + } + return -1; +} + //Test static int sq_Test(uint32_t v) { @@ -474,72 +542,195 @@ static int SetSlot(uint32_t v) return 1; } -int squirrel::SQloadfile(uint32_t v, const wchar_t* filename, bool printerror) + +//查询 类型容器 +static int Get_STL(uint32_t v) { - //wchar_t* 转 char* - int size = wcslen(filename); - char* fname = (char*)new char[size]; - DNFTOOL::UnicodeToAnsi(filename, fname, size); + char* Name; + int Type; + int Idx; + int ParameterNum = SQGetTop(v); - FILE* file; - file = fopen(fname, "rb+"); - LSQLEXREADFUNC func = SQ_io_file_lexfeed_ASCII; - if (file) + if (ParameterNum == 4) { - //求得文件的大小 - fseek(file, 0, SEEK_END); - int size = ftell(file); - rewind(file); - - //申请一块能装下整个文件的空间 - char* ar = (char*)malloc(sizeof(char) * size); - //读文件,每次读一个,共读size次 - fread(ar, 1, size, file); - - int skey[] = { 5,2,3,5,0 };//定义解密数组 - - Cutecode(ar, skey);//解密 - - FILE* outfile; - outfile = fopen("ImagePacks2/sprite_interface_teart_zero.npk", "wb+"); - int da = strlen(ar); - fwrite(ar, 1, da, outfile); - - fclose(outfile);//关闭文件 - free(ar);//释放内存 - - 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) + //获取容器名字 + SQGetStringc(v, 2, &Name); + //获取容器类型 + SQGetInt(v, 3, &Type); + //获取查询号位 + SQGetInt(v, 4, &Idx); + if (STL::Check_STL(Name, Type) == 0) { - fclose(file);//关闭文件 - SQ__Fclose(newfile);//关闭文件 - remove("ImagePacks2/sprite_interface_teart_zero.npk");//删除文件 - return 0; - } - - fclose(file);//关闭文件 - return -1; - } - return -1; -} - -int squirrel::SQdofile(uint32_t v, const wchar_t* filename, bool retval, bool printerror) -{ - if (SQloadfile(v, filename, printerror) >= 0) - { - SQPush(v, -2); - if ((int)SQ_Call(v, 1, retval, 1) >= 0) - { - SQ_Remove(v, -(retval != 0) - 1); + SQPushBool(v, false); return 1; } - SQPop(v, 1); + switch (Type) + { + case 0: + SQPushInt(v, Int_STL[Name]); + break; + case 1: + SQPushFloat(v, Float_STL[Name]); + break; + case 2: + SQPushStringc(v, String_STL[Name].c_str(), strlen(String_STL[Name].c_str())); + break; + case 3: + SQPushBool(v, Bool_STL[Name]); + break; + case 4: + SQPushInt(v, STL::GetIntArr_STL(Name, Idx)); + break; + case 5: + SQPushFloat(v, STL::GetFloatArr_STL(Name, Idx)); + break; + case 6: + SQPushStringc(v, STL::GetStringArr_STL(Name, Idx).c_str(), strlen(STL::GetStringArr_STL(Name, Idx).c_str())); + break; + case 7: + SQPushBool(v, STL::GetBoolArr_STL(Name, Idx)); + break; + default: + return 0; + break; + } + return 1; + } + else + { + return 0; } - return -1; } +//设置 类型容器 +static int Set_STL(uint32_t v) +{ + char* Name; + int Type; + int Idx; + int ParameterNum = SQGetTop(v); + + int IntValue; + float FloatValue; + char* StrValue; + bool BoolValue; + if (ParameterNum == 5) + { + //获取容器名字 + SQGetStringc(v, 2, &Name); + //获取容器类型 + SQGetInt(v, 3, &Type); + //获取修改号位 + SQGetInt(v, 4, &Idx); + + //获取修改值 + switch (Type) + { + case 0: + SQGetInt(v, 5, &IntValue); + Int_STL[Name] = IntValue; + break; + case 1: + SQGetFloat(v, 5, &FloatValue); + Float_STL[Name] = FloatValue; + break; + case 2: + SQGetStringc(v, 5, &StrValue); + String_STL[Name] = StrValue; + break; + case 3: + SQGetBool(v, 5, &BoolValue); + Bool_STL[Name] = BoolValue; + break; + case 4: + SQGetInt(v, 5, &IntValue); + STL::SetIntArr_STL(Name,Idx, IntValue); + break; + case 5: + SQGetFloat(v, 5, &FloatValue); + STL::SetFloatArr_STL(Name, Idx, FloatValue); + break; + case 6: + SQGetStringc(v, 5, &StrValue); + STL::SetStringArr_STL(Name, Idx, StrValue); + break; + case 7: + SQGetBool(v, 5, &BoolValue); + STL::SetBoolArr_STL(Name, Idx, BoolValue); + break; + default: + SQPushBool(v, false); + return 1; + break; + } + SQPushBool(v, true); + } + else + { + SQPushBool(v, false); + } + return 1; +} + + +//new 类型容器 +static int New_STL(uint32_t v) +{ + char* Name; + int Type; + int ParameterNum = SQGetTop(v); + if (ParameterNum == 3) + { + //获取容器名字 + SQGetStringc(v, 2, &Name); + //获取容器类型 + SQGetInt(v, 3, &Type); + if (STL::Check_STL(Name, Type) != 0) + { + SQPushBool(v, false); + return 1; + } + switch (Type) + { + case 0: + Int_STL[Name] = 0;//单Int容器 + break; + case 1: + Float_STL[Name] = 0.0;//单Float容器 + break; + case 2: + String_STL[Name] = "zero";//单String容器 + break; + case 3: + Bool_STL[Name] = false;//单Bool容器 + break; + case 4: + STL::BuildIntArr_STL(Name);//Int数组容器 + break; + case 5: + STL::BuildFloatArr_STL(Name);//Float数组容器 + break; + case 6: + STL::BuildStringArr_STL(Name);//String数组容器 + break; + case 7: + STL::BuildBoolArr_STL(Name);//Bool数组容器 + break; + default: + SQPushBool(v, false); + return 1; + break; + } + SQPushBool(v, true); + } + else + { + SQPushBool(v, false); + } + return 1; +} + + //获取Squirrel v 基址 inline uint32_t GetSqVm() { @@ -578,4 +769,9 @@ void squirrel::R_Register_Nut() RegisterNutApi(L"L_cout", Lcout); RegisterNutApi(L"L_NewWindows", NewWindows); RegisterNutApi(L"L_SetSlot", SetSlot); + + + RegisterNutApi(L"L_New_STL", New_STL); + RegisterNutApi(L"L_Set_STL", Set_STL); + RegisterNutApi(L"L_Get_STL", Get_STL); } diff --git a/test/squirrel.h b/test/squirrel.h index 1c5455b..2aed4f2 100644 --- a/test/squirrel.h +++ b/test/squirrel.h @@ -68,7 +68,9 @@ typedef int(SqPushFunc)(uint32_t v, int idx); static SqPushFunc* SQPush = (SqPushFunc*)0x1358C90; //PushString typedef int(SqPushStringFunc)(uint32_t v, const wchar_t* s, int len); +typedef int(SqPushStringFuncs)(uint32_t v, const char* s, int len); static SqPushStringFunc* SQPushString = (SqPushStringFunc*)0x1358A60; +static SqPushStringFuncs* SQPushStringc = (SqPushStringFuncs*)0x1358A60; //PushInt typedef int(SqPushIntFunc)(uint32_t v, int sint); static SqPushIntFunc* SQPushInt = (SqPushIntFunc*)0x1358AD0; diff --git a/test/test.vcxproj b/test/test.vcxproj index 7f30e2b..9fd1a4c 100644 --- a/test/test.vcxproj +++ b/test/test.vcxproj @@ -178,6 +178,7 @@ + @@ -193,6 +194,7 @@ + diff --git a/test/test.vcxproj.filters b/test/test.vcxproj.filters index 2d365db..b4f9b62 100644 --- a/test/test.vcxproj.filters +++ b/test/test.vcxproj.filters @@ -39,6 +39,9 @@ 澶存枃浠 + + 澶存枃浠 + @@ -65,5 +68,8 @@ 婧愭枃浠 + + 婧愭枃浠 + \ No newline at end of file