1212
This commit is contained in:
271
test/函数块.cpp
271
test/函数块.cpp
@@ -237,6 +237,96 @@ int GetEquAddr(int addr)
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
//加载
|
||||
static int SQloadfile(uint32_t v, const wchar_t* filename, bool printerror)
|
||||
{
|
||||
void* file = SQfopen(filename, L"rb");
|
||||
//void* file = (void*)"IIIAAA <- 66487";
|
||||
int ret;
|
||||
unsigned short us;
|
||||
unsigned char uc;
|
||||
LSQLEXREADFUNC func = SQ_io_file_lexfeed_ASCII;
|
||||
if (file)
|
||||
{
|
||||
ret = SQfread(&us, 1, 2, file);
|
||||
if (ret != 2)
|
||||
{
|
||||
us = 0;
|
||||
}
|
||||
if (us == 0xFAFA)
|
||||
{
|
||||
SQfseek(file, 0, 2);
|
||||
if (SQ_Readclosure(v, SQ_File_read, file) > 0)
|
||||
{
|
||||
SQ__Fclose(file);
|
||||
return SQ_OK;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (us)
|
||||
{
|
||||
case 0xFFFE: func = SQ_io_file_lexfeed_UCS2_BE; break;//UTF-16 little endian;
|
||||
case 0xFEFF: func = SQ_io_file_lexfeed_UCS2_LE; break;//UTF-16 big endian;
|
||||
case 0xBBEF:
|
||||
if (SQfread(&uc, 1, sizeof(uc), file) == 0)
|
||||
{
|
||||
SQ__Fclose(file);
|
||||
return SQ_Throwerror(v, _SC("io error"));
|
||||
}
|
||||
if (uc != 0xBF)
|
||||
{
|
||||
SQ__Fclose(file);
|
||||
return SQ_Throwerror(v, _SC("Unrecognozed ecoding"));
|
||||
}
|
||||
func = SQ_io_file_lexfeed_UTF8;
|
||||
break;//UTF-8 ;
|
||||
default: SQfseek(file, 0, 2); break; // ascii
|
||||
}
|
||||
|
||||
if (SQ_Compile(v, func, file, filename, printerror) >= 0)
|
||||
{
|
||||
SQ__Fclose(file);
|
||||
return SQ_OK;
|
||||
}
|
||||
}
|
||||
SQ__Fclose(file);
|
||||
return -1;
|
||||
}
|
||||
return SQ_Throwerror(v, _SC("cannot open the file"));
|
||||
}
|
||||
|
||||
static int 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------------------------Squirrel
|
||||
@@ -256,209 +346,210 @@ void RegisterNutApi(const wchar_t* funcName, void* funcAddr, uint32_t v)
|
||||
SQNewSlot(v, -3, false);
|
||||
SQPopTop(v);
|
||||
}
|
||||
|
||||
//Test
|
||||
static SQInteger sq_Test(uint32_t v)
|
||||
static int sq_Test(uint32_t v)
|
||||
{
|
||||
|
||||
//sq_pushinteger(v, n1);
|
||||
SQdofile(v, L"1.cpp", false, false);
|
||||
return 0;
|
||||
}
|
||||
//读人物 或 装备属性
|
||||
static SQInteger GetCharacterAttribute(HSQUIRRELVM v)
|
||||
static int GetCharacterAttribute(uint32_t v)
|
||||
{
|
||||
SQInteger n1 ,n2 ;
|
||||
sq_getinteger(v, 2, &n1);
|
||||
sq_getinteger(v, 3, &n2);
|
||||
int n1 ,n2 ;
|
||||
int num = SQGetTop(v);
|
||||
|
||||
int CharAddr = *(int*)(0x1AB7CDC);
|
||||
if (n1 > 0 && n2 > 0 && n2 <= 27)
|
||||
if (num == 3)
|
||||
{
|
||||
SQGetInt(v, 2, &n1);
|
||||
SQGetInt(v, 3, &n2);
|
||||
int TValue = *(int*)(CharAddr + GetEquAddr(n2));
|
||||
int SValue = (TValue + n1);
|
||||
if (n1 != 0x8 && n1 != 0x1C && n1 != 0xF4)
|
||||
sq_pushinteger(v, (SQInteger)(DNFDeCode(SValue)));
|
||||
SQPushInt(v, (DNFDeCode(SValue)));
|
||||
else
|
||||
sq_pushinteger(v, (SQInteger)(*(int*)(SValue)));
|
||||
SQPushInt(v, (*(int*)(SValue)));
|
||||
}
|
||||
else if (n1 > 0)
|
||||
else if (num == 2)
|
||||
{
|
||||
SQGetInt(v, 2, &n1);
|
||||
int Value = (CharAddr + n1);
|
||||
|
||||
sq_pushinteger(v, (SQInteger)(DNFDeCode(Value)));
|
||||
SQPushInt(v, (DNFDeCode(Value)));
|
||||
}
|
||||
else
|
||||
{
|
||||
sq_pushinteger(v, -1);
|
||||
SQPushString(v, L"parameter error",-1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
//写人物 或 装备属性
|
||||
static SQInteger SetCharacterAttribute(HSQUIRRELVM v)
|
||||
static int SetCharacterAttribute(uint32_t v)
|
||||
{
|
||||
SQInteger n1, n2,n3;
|
||||
sq_getinteger(v, 2, &n1);
|
||||
sq_getinteger(v, 3, &n2);
|
||||
sq_getinteger(v, 4, &n3);
|
||||
int n1, n2, n3;
|
||||
|
||||
int num = SQGetTop(v);
|
||||
|
||||
std::cout << n1 << std::endl;
|
||||
std::cout << n2 << std::endl;
|
||||
std::cout << n3 << std::endl;
|
||||
|
||||
int CharAddr = *(int*)(0x1AB7CDC);
|
||||
if (n1 > 0 && n2 > 0 && n3 > 0)
|
||||
if (num == 4)
|
||||
{
|
||||
SQGetInt(v, 2, &n1);
|
||||
SQGetInt(v, 3, &n2);
|
||||
SQGetInt(v, 4, &n3);
|
||||
|
||||
int TValue = *(int*)(CharAddr + GetEquAddr(n2));
|
||||
int SValue = (TValue + n1);
|
||||
if (n1 != 0x8 && n1 != 0x1C && n1 != 0xF4)
|
||||
//sq_pushinteger(v, (SQInteger)(DNFDeCode(SValue)));
|
||||
DNFEnCode(SValue, n3);
|
||||
else
|
||||
//sq_pushinteger(v, (SQInteger)(*(int*)(SValue)));
|
||||
*(int*)SValue = n3;
|
||||
sq_pushinteger(v, (SQInteger)1);
|
||||
SQPushBool(v, true);
|
||||
}
|
||||
else if (n1 > 0 && n2 >0)
|
||||
else if (num == 3)
|
||||
{
|
||||
SQGetInt(v, 2, &n1);
|
||||
SQGetInt(v, 3, &n2);
|
||||
|
||||
int Value = (CharAddr + n1);
|
||||
DNFEnCode(Value, n2);
|
||||
sq_pushinteger(v, (SQInteger)1);
|
||||
SQPushBool(v, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
sq_pushinteger(v, -1);
|
||||
SQPushBool(v, false);
|
||||
}
|
||||
|
||||
sq_pushinteger(v, -1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
//获取城镇编号
|
||||
static SQInteger GetTownIndex(HSQUIRRELVM v)
|
||||
static int GetTownIndex(uint32_t v)
|
||||
{
|
||||
sq_pushinteger(v, GetHook(0x1A5E258, "0xAC+0xD4+"));
|
||||
SQPushInt(v, GetHook(0x1A5E258, "0xAC+0xD4+"));
|
||||
return 1;
|
||||
}
|
||||
//获取城镇区域编号
|
||||
static SQInteger GetRegionIndex(HSQUIRRELVM v)
|
||||
static int GetRegionIndex(uint32_t v)
|
||||
{
|
||||
sq_pushinteger(v, *(int*)(GetHook(0x1A5E258, "0xAC+0xD8+")));
|
||||
SQPushInt(v, *(int*)(GetHook(0x1A5E258, "0xAC+0xD8+")));
|
||||
return 1;
|
||||
}
|
||||
//获取城镇X坐标
|
||||
static SQInteger GetTownXpos(HSQUIRRELVM v)
|
||||
static int GetTownXpos(uint32_t v)
|
||||
{
|
||||
sq_pushinteger(v, GetHook(0x1AB7CE0, "0x2BC+"));
|
||||
SQPushInt(v, GetHook(0x1AB7CE0, "0x2BC+"));
|
||||
return 1;
|
||||
}
|
||||
//获取城镇Y坐标
|
||||
static SQInteger GetTownYpos(HSQUIRRELVM v)
|
||||
static int GetTownYpos(uint32_t v)
|
||||
{
|
||||
sq_pushinteger(v, GetHook(0x1AB7CE0, "0x2C0+"));
|
||||
SQPushInt(v, GetHook(0x1AB7CE0, "0x2C0+"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
//发包类型
|
||||
static SQInteger SendPackType(HSQUIRRELVM v)
|
||||
static int SendPackType(uint32_t v)
|
||||
{
|
||||
SQInteger n1;
|
||||
sq_getinteger(v, 2, &n1);
|
||||
int n1;
|
||||
SQGetInt(v, 2, &n1);
|
||||
_SendpacksType(*_SendClass, 0, n1);
|
||||
|
||||
sq_pushinteger(v, 1);
|
||||
SQPushInt(v, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//发包Byte
|
||||
static SQInteger SendPackByte(HSQUIRRELVM v)
|
||||
static int SendPackByte(uint32_t v)
|
||||
{
|
||||
SQInteger n1;
|
||||
sq_getinteger(v, 2, &n1);
|
||||
int n1;
|
||||
SQGetInt(v, 2, &n1);
|
||||
_SendPacksByte(*_SendClass, 0, n1);
|
||||
|
||||
sq_pushinteger(v, 1);
|
||||
SQPushInt(v, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//发包Word
|
||||
static SQInteger SendPackWord(HSQUIRRELVM v)
|
||||
static int SendPackWord(uint32_t v)
|
||||
{
|
||||
SQInteger n1;
|
||||
sq_getinteger(v, 2, &n1);
|
||||
int n1;
|
||||
SQGetInt(v, 2, &n1);
|
||||
_SendPacksWord(*_SendClass, 0, n1);
|
||||
|
||||
sq_pushinteger(v, 1);
|
||||
SQPushInt(v, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//发包DWord
|
||||
static SQInteger SendPackDWord(HSQUIRRELVM v)
|
||||
static int SendPackDWord(uint32_t v)
|
||||
{
|
||||
SQInteger n1;
|
||||
sq_getinteger(v, 2, &n1);
|
||||
int n1;
|
||||
SQGetInt(v, 2, &n1);
|
||||
_SendPacksDWord(*_SendClass, 0, n1);
|
||||
|
||||
sq_pushinteger(v, 1);
|
||||
SQPushInt(v, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//发包
|
||||
static SQInteger SendPack(HSQUIRRELVM v)
|
||||
static int SendPack(uint32_t v)
|
||||
{
|
||||
_SendPacks();
|
||||
sq_pushinteger(v, 1);
|
||||
SQPushInt(v, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
//发物品给玩家
|
||||
static SQInteger GivePlayerItem(HSQUIRRELVM v)
|
||||
static int GivePlayerItem(uint32_t v)
|
||||
{
|
||||
SQInteger n1,n2;
|
||||
int n1,n2;
|
||||
|
||||
int num = SQGetTop(v);
|
||||
|
||||
sq_getinteger(v, 2, &n1);
|
||||
sq_getinteger(v, 3, &n2);
|
||||
|
||||
if (n1>0 && n2>0)
|
||||
if (num == 3)
|
||||
{
|
||||
SQGetInt(v, 2, &n1);
|
||||
SQGetInt(v, 3, &n2);
|
||||
|
||||
_SendpacksType(*_SendClass, 0, 65);
|
||||
_SendPacksDWord(*_SendClass, 0, 1);
|
||||
_SendPacksDWord(*_SendClass, 0, n1);
|
||||
_SendPacksDWord(*_SendClass, 0, n2);
|
||||
_SendPacks();
|
||||
|
||||
sq_pushinteger(v, 1);
|
||||
SQPushBool(v, true);
|
||||
}
|
||||
|
||||
if (!n1 || !n2)
|
||||
else
|
||||
{
|
||||
sq_pushinteger(v, 0);
|
||||
SQPushBool(v, false);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
//发装备给玩家
|
||||
static SQInteger GivePlayerEqu(HSQUIRRELVM v)
|
||||
static int GivePlayerEqu(uint32_t v)
|
||||
{
|
||||
SQInteger n1, n2;
|
||||
int n1, n2;
|
||||
|
||||
int num = SQGetTop(v);
|
||||
|
||||
sq_getinteger(v, 2, &n1);
|
||||
sq_getinteger(v, 3, &n2);
|
||||
|
||||
if (n1 > 0 && n2 > 0)
|
||||
if (num == 3)
|
||||
{
|
||||
SQGetInt(v, 2, &n1);
|
||||
SQGetInt(v, 3, &n2);
|
||||
|
||||
_SendpacksType(*_SendClass, 0, 65);
|
||||
_SendPacksDWord(*_SendClass, 0, 2);
|
||||
_SendPacksDWord(*_SendClass, 0, n1);
|
||||
_SendPacksDWord(*_SendClass, 0, n2);
|
||||
_SendPacks();
|
||||
|
||||
sq_pushinteger(v, 1);
|
||||
SQPushBool(v, true);
|
||||
}
|
||||
|
||||
if (!n1 || !n2)
|
||||
else
|
||||
{
|
||||
sq_pushinteger(v, 0);
|
||||
SQPushBool(v, false);
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -472,8 +563,7 @@ static int GoDungeon(uint32_t v)
|
||||
int n3 = 0;
|
||||
int n4 = 0;
|
||||
|
||||
int num;
|
||||
num = SQGetTop(v);
|
||||
int num = SQGetTop(v);
|
||||
|
||||
if (num == 2)
|
||||
{
|
||||
@@ -506,6 +596,28 @@ static int GoDungeon(uint32_t v)
|
||||
return 1;
|
||||
}
|
||||
|
||||
//Ldofile
|
||||
static int LDofile(uint32_t v)
|
||||
{
|
||||
wchar_t* n1;
|
||||
|
||||
int num = SQGetTop(v);
|
||||
|
||||
if (num == 2)
|
||||
{
|
||||
SQGetString(v, 2, &n1);
|
||||
SQPopTop(v);
|
||||
SQdofile(v, n1, false, false);
|
||||
SQPushBool(v, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
SQPushBool(v, false);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void RegisterNut()
|
||||
{
|
||||
RegisterNutApi(L"L_sq_Test", sq_Test);
|
||||
@@ -523,6 +635,7 @@ void RegisterNut()
|
||||
RegisterNutApi(L"L_sq_GivePlayerItem", GivePlayerItem);
|
||||
RegisterNutApi(L"L_sq_GivePlayerEqu", GivePlayerEqu);
|
||||
RegisterNutApi(L"L_sq_GoDungeon", GoDungeon);
|
||||
RegisterNutApi(L"L_sq_Dofile", LDofile);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user