217 lines
7.2 KiB
C++
217 lines
7.2 KiB
C++
#pragma once
|
|
|
|
|
|
//-------------------------------------------------------------------------------------------Squirrel
|
|
// PushRoot
|
|
typedef int(SqPushRootFunc)(uint32_t v);
|
|
static SqPushRootFunc* SQPushRootTable = (SqPushRootFunc*)0x1358C50;
|
|
// Push 函数绑定闭包
|
|
typedef int(realSqNewClosure)(uint32_t v, void* funcAddr, int a);
|
|
static realSqNewClosure* RealSqNewClosure = (realSqNewClosure*)0x135B850;
|
|
#define INIT_NUT_ADDRESS 0x135B850
|
|
static realSqNewClosure* MLnewclosure = nullptr;
|
|
// New槽
|
|
typedef int(SqNewSlot)(uint32_t v, int a, bool b);
|
|
static SqNewSlot* SQNewSlot = (SqNewSlot*)0x135AA80;
|
|
// 平栈
|
|
typedef int(SqPopTop)(uint32_t v);
|
|
static SqPopTop* SQPopTop = (SqPopTop*)0x1358FF0;
|
|
// 平栈
|
|
typedef int(SqPop)(uint32_t v, int n);
|
|
static SqPop* SQPop = (SqPop*)0x1358FD0;
|
|
//SQ_Get
|
|
typedef int(Sq_Get)(uint32_t v, int n);
|
|
static Sq_Get* SQ_Get = (Sq_Get*)0x135AE30;
|
|
//SQ_Rawget
|
|
typedef int(Sq_Rawget)(uint32_t v, int n);
|
|
static Sq_Rawget* SQ_Rawget = (Sq_Rawget*)0x135AEA0;
|
|
//SQ*Getlocal
|
|
typedef wchar_t* (SqGetlocal)(uint32_t v, int n, int idx);
|
|
static SqGetlocal* SQGetlocal = (SqGetlocal*)0x135AFD0;
|
|
//SQ_Wakeupvm
|
|
typedef int (Sq_Wakeupvm)(uint32_t v, int n, int retval, int raiseerror);
|
|
static Sq_Wakeupvm* SQ_Wakeupvm = (Sq_Wakeupvm*)0x135B0D0;
|
|
//SQ_Call
|
|
typedef int (Sq_CallFunc)(uint32_t v, int params, int retval, int raiseerror);
|
|
static Sq_CallFunc* SQ_Call = (Sq_CallFunc*)0x1359280;
|
|
//SQ_Remove
|
|
typedef int (SQ_RemoveFunc)(uint32_t v, int idx);
|
|
static SQ_RemoveFunc* SQ_Remove = (SQ_RemoveFunc*)0x1359000;
|
|
//GetInt
|
|
typedef int(SqGetIntFunc)(uint32_t v, uint32_t stackIndex, int* sint);
|
|
static SqGetIntFunc* SQGetInt = (SqGetIntFunc*)0x1358D70;
|
|
//GetFloat
|
|
typedef int(SqGetFloatFunc)(uint32_t v, uint32_t stackIndex, float* sfloat);
|
|
static SqGetFloatFunc* SQGetFloat = (SqGetFloatFunc*)0x1358DD0;
|
|
//GetBool
|
|
typedef int(SqGetBoolFunc)(uint32_t v, uint32_t stackIndex, bool* sbool);
|
|
static SqGetBoolFunc* SQGetBool = (SqGetBoolFunc*)0x1358E30;
|
|
//GetString
|
|
typedef int(SqGetStringFunc)(uint32_t v, uint32_t stackIndex, wchar_t** sstring);
|
|
static SqGetStringFunc* SQGetString = (SqGetStringFunc*)0x1358E70;
|
|
typedef int(SqGetStringCFunc)(uint32_t v, uint32_t stackIndex, char** sstring);
|
|
static SqGetStringCFunc* SQGetStringc = (SqGetStringCFunc*)0x1358E70;
|
|
//GetUserdata
|
|
typedef int(SqGetUserdataFunc)(uint32_t v, uint32_t stackIndex, DWORD* up, DWORD* up1);
|
|
static SqGetUserdataFunc* SQGetUserdata = (SqGetUserdataFunc*)0x1358EC0;
|
|
//GetObjtypetag
|
|
typedef int(SqGetObjtypetagFunc)(uint32_t v, DWORD* up);
|
|
static SqGetObjtypetagFunc* SQGetObjtypetag = (SqGetObjtypetagFunc*)0x1358F20;
|
|
//GetUserpointer
|
|
typedef int(SqGetUserpointerFunc)(uint32_t v, uint32_t idx, DWORD* up);
|
|
static SqGetUserpointerFunc* SQGetUserpointer = (SqGetUserpointerFunc*)0x1358F80;
|
|
//GetTop
|
|
typedef int(SqGetTopFunc)(uint32_t v);
|
|
static SqGetTopFunc* SQGetTop = (SqGetTopFunc*)0x1358FC0;
|
|
//Push
|
|
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);
|
|
static SqPushStringFunc* SQPushString = (SqPushStringFunc*)0x1358A60;
|
|
//PushInt
|
|
typedef int(SqPushIntFunc)(uint32_t v, int sint);
|
|
static SqPushIntFunc* SQPushInt = (SqPushIntFunc*)0x1358AD0;
|
|
//PushBool
|
|
typedef int(SqPushBoolFunc)(uint32_t v, bool sbool);
|
|
static SqPushBoolFunc* SQPushBool = (SqPushBoolFunc*)0x1358B10;
|
|
//PushFloat
|
|
typedef int(SqPushFloatFunc)(uint32_t v, float sfloat);
|
|
static SqPushFloatFunc* SQPushFloat = (SqPushFloatFunc*)0x1358B60;
|
|
|
|
|
|
|
|
//SQLOADFILE
|
|
typedef void* (SQLOADFILEFunc)(uint32_t v, const wchar_t* filename, bool printerror);
|
|
static SQLOADFILEFunc* SQLOADFILEF = (SQLOADFILEFunc*)0x13560E0;
|
|
//SQDOFILE
|
|
typedef void* (SQDOFILEFunc)(uint32_t v, const wchar_t* filename, bool retval, bool printerror);
|
|
static SQDOFILEFunc* SQDOFILE = (SQDOFILEFunc*)0x1356240;
|
|
|
|
|
|
typedef void* (*SQFILE)();
|
|
//SQ_io_file_lexfeed_编码
|
|
//typedef int(LSQLEXREADFUNC)(int n);
|
|
typedef int(*LSQLEXREADFUNC)(int n);
|
|
static LSQLEXREADFUNC SQ_io_file_lexfeed_ASCII = (LSQLEXREADFUNC)0x1355F60;
|
|
static LSQLEXREADFUNC SQ_io_file_lexfeed_UCS2_BE = (LSQLEXREADFUNC)0x1356050;
|
|
static LSQLEXREADFUNC SQ_io_file_lexfeed_UCS2_LE = (LSQLEXREADFUNC)0x1356020;
|
|
static LSQLEXREADFUNC SQ_io_file_lexfeed_UTF8 = (LSQLEXREADFUNC)0x1355F90;
|
|
//SQfopen
|
|
typedef SQFILE* (SQfopenFunc)(const wchar_t* filename, const wchar_t* type);
|
|
static SQfopenFunc* SQfopen = (SQfopenFunc*)0x1355DC0;
|
|
//SQfread
|
|
typedef int(SQfreadFunc)(void* buffer, int a, int b, void* file);
|
|
static SQfreadFunc* SQfread = (SQfreadFunc*)0x1355DD0;
|
|
//SQwrite
|
|
typedef int(SQwriteFunc)(void* buffer, int a, int b, void* file);
|
|
static SQwriteFunc* SQwrite = (SQwriteFunc*)0x1355DE0;
|
|
//SQfseek
|
|
typedef int(SQfseekFunc)(void* buffer, int a, int b);
|
|
static SQfseekFunc* SQfseek = (SQfseekFunc*)0x1355DF0;
|
|
//SQftell
|
|
typedef int(SQftellFunc)(void* file);
|
|
static SQftellFunc* SQftell = (SQftellFunc*)0x1355E50;
|
|
//SQ_File_read
|
|
typedef int(SQ_File_readFunc)(void* file, void* afile, int a);
|
|
static SQ_File_readFunc* SQ_File_read = (SQ_File_readFunc*)0x1356090;
|
|
//SQ_Readclosure
|
|
typedef int(SQ_ReadclosureFunc)(uint32_t v, SQ_File_readFunc a, void* file);
|
|
static SQ_ReadclosureFunc* SQ_Readclosure = (SQ_ReadclosureFunc*)0x1359460;
|
|
//SQ_Fclose
|
|
typedef int(SQ__FcloseFunc)(void* file);
|
|
static SQ__FcloseFunc* SQ__Fclose = (SQ__FcloseFunc*)0x1355E70;
|
|
//SQ_Compile
|
|
typedef int(SQ_CompileFunc)(uint32_t v, LSQLEXREADFUNC FUNC, void* file, const wchar_t* filename, bool printerror);
|
|
static SQ_CompileFunc* SQ_Compile = (SQ_CompileFunc*)0x135A390;
|
|
//SQ_Throwerror
|
|
typedef int(SQ_ThrowerrorFunc)(uint32_t v, const wchar_t* error);
|
|
static SQ_ThrowerrorFunc* SQ_Throwerror = (SQ_ThrowerrorFunc*)0x13591A0;
|
|
|
|
//获取Squirrel v 基址
|
|
inline uint32_t GetSqVm();
|
|
|
|
//新增nut接口funcName绑定C语言函数funcAddr
|
|
void RegisterNutApi(const wchar_t* funcName, void* funcAddr, uint32_t v = NULL);
|
|
|
|
//注册Nut函数
|
|
void RegisterNut();
|
|
|
|
class squirrel
|
|
{
|
|
private:
|
|
|
|
|
|
public:
|
|
//加载
|
|
static int SQloadfile(uint32_t v, const wchar_t* filename, bool printerror);
|
|
static int SQdofile(uint32_t v, const wchar_t* filename, bool retval, bool printerror);
|
|
|
|
|
|
public:
|
|
|
|
//新增nut接口funcName绑定C语言函数funcAddr
|
|
static void RegisterNutApi(const wchar_t* funcName, void* funcAddr, uint32_t v);
|
|
//注册接口
|
|
static void R_Register_Nut();
|
|
};
|
|
|
|
|
|
|
|
//新增Nut接口绑定C函数
|
|
// 示例如下
|
|
/*
|
|
static int GoDungeon(uint32_t v)
|
|
{
|
|
int n1 = 0;
|
|
int n2 = 0;
|
|
int n3 = 0;
|
|
int n4 = 0;
|
|
|
|
int num;
|
|
num = SQGetTop(v);
|
|
|
|
if (num == 2)
|
|
{
|
|
SQGetInt(v, 2, &n1);
|
|
}
|
|
else if (num == 5)
|
|
{
|
|
SQGetInt(v, 2, &n1);
|
|
SQGetInt(v, 3, &n2);
|
|
SQGetInt(v, 4, &n3);
|
|
SQGetInt(v, 5, &n4);
|
|
}
|
|
else
|
|
{
|
|
SQPushBool(v, false);
|
|
return 1;
|
|
}
|
|
|
|
_SendpacksType(*_SendClass, 0, 15);
|
|
_SendPacks();
|
|
|
|
_SendpacksType(*_SendClass, 0, 16);
|
|
_SendPacksWord(*_SendClass, 0, n1);
|
|
_SendPacksByte(*_SendClass, 0, n2);
|
|
_SendPacksByte(*_SendClass, 0, n3);
|
|
_SendPacksByte(*_SendClass, 0, n4);
|
|
_SendPacks();
|
|
|
|
SQPushBool(v, true);
|
|
//return 1 表示该函数有返回值传给nut脚本 0则无
|
|
return 1;
|
|
}
|
|
*/
|
|
//新增C++调用 nut
|
|
// 示例如下
|
|
/*
|
|
uint32_t v = GetSqVm();
|
|
SQPushRootTable(v);
|
|
SQPushString(v, L"dofile", -1);
|
|
SQ_Get(v, -2);
|
|
SQPushRootTable(v);
|
|
SQPushString(v, L"1.cpp", -1);
|
|
SQ_Call(v, 2, 1, 0);
|
|
SQPop(v, 2);
|
|
*/ |