This commit is contained in:
lenheart
2024-09-18 11:35:30 +08:00
parent 2ade285084
commit c4d95cb07f
6 changed files with 461 additions and 126 deletions

View File

@@ -149,6 +149,52 @@ static SQInteger Game_GetConfig(HSQUIRRELVM v)
return 1;
}
// 加密函数
static std::string Buf_encryptDecrypt(const std::string &input, const std::string &key)
{
std::string output = input;
for (size_t i = 0; i < input.size(); i++)
{
output[i] = input[i] ^ key[i % key.size()]; // 使用异或运算进行加密
}
return output;
}
// 判断是否处理加密
static std::string Buf_IsencryptDecrypt(const std::string &input, const std::string &FileName)
{
if (FileName.find(".nut") != std::string::npos)
return input;
else
return Buf_encryptDecrypt(input, "Lenheart-asdhfjiaednkljanslk");
}
// 执行脚本
static SQInteger RunScript(HSQUIRRELVM v)
{
const SQChar *Path;
sq_getstring(v, 2, &Path);
std::string RealPath(Path);
RealPath = "/dp_s/" + RealPath;
std::fstream F;
F.open(RealPath, std::ios::in);
std::stringstream ContentStringStream;
ContentStringStream << F.rdbuf();
std::string ContentString(ContentStringStream.str());
F.close();
std::string RealContentString = Buf_IsencryptDecrypt(ContentString, RealPath);
if (SQ_SUCCEEDED(sq_compilebuffer(v, (SQChar *)(RealContentString.c_str()), RealContentString.length(), (SQChar *)(RealPath.c_str()), true)))
{
sq_pushroottable(v);
sq_call(v, 1, 1, 1);
sq_pop(v, 1);
}
return 0;
}
// 指针转int
static SQInteger L_Ptr2Int(HSQUIRRELVM v)
{
@@ -659,6 +705,8 @@ static void RegisterGame(HSQUIRRELVM v)
getConfigPath(szGamePath, sizeof(szGamePath));
// int 和指针相互转换
register_World_func(v, RunScript, _SC("sq_RunScript"));
register_World_func(v, L_Ptr2Int, _SC("Sq_Ptr2Int"));
register_World_func(v, L_Int2Ptr, _SC("Sq_Int2Ptr"));
register_World_func(v, L_S_Ptr, _SC("S_Ptr"));