111
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
#include "l_squirrel.h"
|
||||
#include "l_squirrel_register.hpp"
|
||||
|
||||
// 虚拟机对象
|
||||
HSQUIRRELVM v;
|
||||
// Lock
|
||||
@@ -25,17 +27,36 @@ static void errorfunc(HSQUIRRELVM v, const SQChar *s, ...)
|
||||
printf("\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
// 加密函数
|
||||
static std::string 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 void ReloadingScript(HSQUIRRELVM v)
|
||||
// 判断是否处理加密
|
||||
static std::string IsencryptDecrypt(const std::string &input, const std::string &FileName)
|
||||
{
|
||||
if (FileName.find(".nut") != std::string::npos)
|
||||
return input;
|
||||
else
|
||||
return encryptDecrypt(input, "Rindro-Aurora");
|
||||
}
|
||||
|
||||
static void ReloadingScript(HSQUIRRELVM v, std::string FilePath)
|
||||
{
|
||||
// 爬取出所有的脚本文件
|
||||
std::vector<std::string> vec = Tool::GetListFilesR("/Dnf_Sqr");
|
||||
std::vector<std::string> vec = Tool::GetListFilesR(FilePath);
|
||||
std::map<std::string, std::string> SquirrelFilePath;
|
||||
|
||||
for (auto it = vec.cbegin(); it != vec.cend(); ++it)
|
||||
{
|
||||
std::string FileName = "/Dnf_Sqr/" + *it;
|
||||
if (FileName.find(".nut") == std::string::npos)
|
||||
std::string FileName = FilePath + *it;
|
||||
if (FileName.find(".nut") == std::string::npos && FileName.find(".sut") == std::string::npos)
|
||||
continue;
|
||||
std::fstream F;
|
||||
F.open((FileName).c_str(), std::ios::in);
|
||||
@@ -43,7 +64,8 @@ static void ReloadingScript(HSQUIRRELVM v)
|
||||
ContentStringStream << F.rdbuf();
|
||||
std::string ContentString(ContentStringStream.str());
|
||||
F.close();
|
||||
SquirrelFilePath[FileName] = ContentString;
|
||||
std::string RealContentString = IsencryptDecrypt(ContentString, FileName);
|
||||
SquirrelFilePath[FileName] = RealContentString;
|
||||
}
|
||||
|
||||
std::map<std::string, std::string> SquirrelLastFilePath;
|
||||
@@ -98,7 +120,9 @@ static void ReloadingScript(HSQUIRRELVM v)
|
||||
|
||||
static SQInteger SqReloadScript(HSQUIRRELVM v)
|
||||
{
|
||||
ReloadingScript(v);
|
||||
ReloadingScript(v, "/dp_s/Dps_A/");
|
||||
ReloadingScript(v, "/dp_s/Dps_B/");
|
||||
ReloadingScript(v, "/dp_s/Dps_C/");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -126,7 +150,9 @@ void InitSquirrel()
|
||||
GlobaRegisterSquirrel(v);
|
||||
|
||||
// 加载基础脚本文件
|
||||
ReloadingScript(v);
|
||||
ReloadingScript(v, "/dp_s/Dps_A/");
|
||||
ReloadingScript(v, "/dp_s/Dps_B/");
|
||||
ReloadingScript(v, "/dp_s/Dps_C/");
|
||||
|
||||
// 执行虚拟机Main函数
|
||||
SQInteger top = sq_gettop(v); // saves the stack size before the call
|
||||
|
||||
Reference in New Issue
Block a user