111
This commit is contained in:
52
include/SqrReg_Battle_Field.hpp
Normal file
52
include/SqrReg_Battle_Field.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
#include "squirrel.h"
|
||||
#include "sqstdaux.h"
|
||||
#include "sqstdblob.h"
|
||||
#include "sqstdio.h"
|
||||
#include "sqstdmath.h"
|
||||
#include "sqstdstring.h"
|
||||
#include "sqstdsystem.h"
|
||||
#include <iostream>
|
||||
|
||||
template <typename R, typename A, typename... ARG>
|
||||
R CallBattleField(A call_addr, const ARG... arguments)
|
||||
{
|
||||
if (!call_addr)
|
||||
{
|
||||
return R();
|
||||
}
|
||||
const auto control = reinterpret_cast<R (*)(ARG...)>(call_addr);
|
||||
try
|
||||
{
|
||||
return control(arguments...);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
return R();
|
||||
}
|
||||
|
||||
// 获取副本对象
|
||||
static SQInteger BattleField_GetDgn(HSQUIRRELVM v)
|
||||
{
|
||||
SQUserPointer P;
|
||||
sq_getuserpointer(v, 2, &P);
|
||||
SQUserPointer B = CallBattleField<void *>(0x80FDCFC, P);
|
||||
sq_pushuserpointer(v, B);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger register_BattleField_func(HSQUIRRELVM v, SQFUNCTION f, const char *fname)
|
||||
{
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v, fname, -1);
|
||||
sq_newclosure(v, f, 0); // create a new function
|
||||
sq_newslot(v, -3, SQFalse);
|
||||
sq_pop(v, 1); // pops the root table
|
||||
}
|
||||
|
||||
static void RegisterBattleField(HSQUIRRELVM v)
|
||||
{
|
||||
// 获取副本对象
|
||||
register_BattleField_func(v, BattleField_GetDgn, _SC("Sq_BattleField_GetDgn"));
|
||||
}
|
||||
52
include/SqrReg_Dungeon.hpp
Normal file
52
include/SqrReg_Dungeon.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
#include "squirrel.h"
|
||||
#include "sqstdaux.h"
|
||||
#include "sqstdblob.h"
|
||||
#include "sqstdio.h"
|
||||
#include "sqstdmath.h"
|
||||
#include "sqstdstring.h"
|
||||
#include "sqstdsystem.h"
|
||||
#include <iostream>
|
||||
|
||||
template <typename R, typename A, typename... ARG>
|
||||
R CallDungeon(A call_addr, const ARG... arguments)
|
||||
{
|
||||
if (!call_addr)
|
||||
{
|
||||
return R();
|
||||
}
|
||||
const auto control = reinterpret_cast<R (*)(ARG...)>(call_addr);
|
||||
try
|
||||
{
|
||||
return control(arguments...);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
return R();
|
||||
}
|
||||
|
||||
// 获取副本编号
|
||||
static SQInteger Dungeon_GetIdex(HSQUIRRELVM v)
|
||||
{
|
||||
SQUserPointer P;
|
||||
sq_getuserpointer(v, 2, &P);
|
||||
SQInteger Idx = CallDungeon<int>(0x80FDCF0, P);
|
||||
sq_pushinteger(v, Idx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger register_Dungeon_func(HSQUIRRELVM v, SQFUNCTION f, const char *fname)
|
||||
{
|
||||
sq_pushroottable(v);
|
||||
sq_pushstring(v, fname, -1);
|
||||
sq_newclosure(v, f, 0); // create a new function
|
||||
sq_newslot(v, -3, SQFalse);
|
||||
sq_pop(v, 1); // pops the root table
|
||||
}
|
||||
|
||||
static void RegisterDungeon(HSQUIRRELVM v)
|
||||
{
|
||||
// 获取编号
|
||||
register_Dungeon_func(v, Dungeon_GetIdex, _SC("Sq_Dungeon_GetIdex"));
|
||||
}
|
||||
@@ -7,7 +7,20 @@
|
||||
#include "sqstdstring.h"
|
||||
#include "sqstdsystem.h"
|
||||
#include "CConnectPool.h"
|
||||
#include "l_socket.h"
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
#include <list>
|
||||
|
||||
// 函数返回值类型枚举
|
||||
enum RETTYPE
|
||||
{
|
||||
INT,
|
||||
FLOAT,
|
||||
BOOL,
|
||||
STRING,
|
||||
POINTER
|
||||
};
|
||||
|
||||
template <typename R, typename A, typename... ARG>
|
||||
R CallGameT(A call_addr, const ARG... arguments)
|
||||
@@ -169,6 +182,25 @@ static SQInteger L_ReadAddress(HSQUIRRELVM v)
|
||||
sq_pushinteger(v, *(int *)Address);
|
||||
return 1;
|
||||
}
|
||||
// 读内存字符串
|
||||
static SQInteger L_ReadAddressString(HSQUIRRELVM v)
|
||||
{
|
||||
// 内存地址 int型
|
||||
SQUserPointer Address;
|
||||
// 获取地址
|
||||
sq_getuserpointer(v, 2, &Address);
|
||||
if (sq_gettop(v) == 3)
|
||||
{
|
||||
SQInteger Length;
|
||||
sq_getinteger(v, 3, &Length);
|
||||
sq_pushstring(v, (char *)(Address), Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
sq_pushstring(v, (char *)(Address), -1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 读取字节数组
|
||||
static SQInteger L_ReadByteArr(HSQUIRRELVM v)
|
||||
@@ -254,6 +286,24 @@ static SQInteger L_GetNameByIdFromPvf(HSQUIRRELVM v)
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
// 通过ID从Pvf中查询Data
|
||||
static SQInteger L_GetDataByIdFromPvf(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger Idx;
|
||||
sq_getinteger(v, 2, &Idx);
|
||||
|
||||
void *Ret = CallGameT<void *>(0x835FA32, CallGameT<void *>(0x80CC19B), (unsigned int)Idx);
|
||||
if (Ret)
|
||||
{
|
||||
sq_pushuserpointer(v, Ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
sq_pushnull(v);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
// 创建数据库连接池
|
||||
static SQInteger L_CreatCConnectPool(HSQUIRRELVM v)
|
||||
{
|
||||
@@ -285,6 +335,42 @@ static SQInteger L_MysqlExecNoRet(HSQUIRRELVM v)
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct CreateSocketInfo
|
||||
{
|
||||
std::string Ip;
|
||||
std::string Port;
|
||||
};
|
||||
|
||||
static void *SocketThread_function(void *arg)
|
||||
{
|
||||
CreateSocketInfo *Info = (CreateSocketInfo *)arg;
|
||||
l_socket::getInstance().Init(Info->Ip, Info->Port);
|
||||
delete Info;
|
||||
// 在这里编写线程的具体操作
|
||||
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
// 创建Socket连接
|
||||
static SQInteger L_CreatSocketConnect(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *Host;
|
||||
const SQChar *Port;
|
||||
sq_getstring(v, 2, &Host);
|
||||
sq_getstring(v, 3, &Port);
|
||||
CreateSocketInfo *Info = new CreateSocketInfo();
|
||||
Info->Ip = Host;
|
||||
Info->Port = Port;
|
||||
|
||||
pthread_t SocketThread;
|
||||
// 创建线程1
|
||||
if (pthread_create(&SocketThread, NULL, SocketThread_function, Info) != 0)
|
||||
{
|
||||
std::cerr << "Error creating thread 1" << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger register_Game_func(HSQUIRRELVM v, SQFUNCTION f, const char *fname)
|
||||
{
|
||||
sq_pushroottable(v);
|
||||
@@ -294,6 +380,103 @@ static SQInteger register_Game_func(HSQUIRRELVM v, SQFUNCTION f, const char *fna
|
||||
sq_pop(v, 1); // pops the root table
|
||||
}
|
||||
|
||||
static void Aprintfunc(const SQChar *s, ...)
|
||||
{
|
||||
fflush(stdout);
|
||||
va_list vl;
|
||||
va_start(vl, s);
|
||||
scvprintf(stdout, s, vl);
|
||||
va_end(vl);
|
||||
printf("\n");
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
// CallFunc
|
||||
static SQInteger L_CallFunc(HSQUIRRELVM v)
|
||||
{
|
||||
SQInteger Count = sq_gettop(v);
|
||||
// 得到函数地址
|
||||
SQUserPointer FuncAddress;
|
||||
sq_getuserpointer(v, 2, &FuncAddress);
|
||||
SQInteger RetType;
|
||||
sq_getinteger(v, 3, &RetType);
|
||||
|
||||
// 头部信息个数
|
||||
int HeaderCount = 3;
|
||||
|
||||
char *m = (char *)malloc((Count - HeaderCount) * 4);
|
||||
void *bm = m;
|
||||
for (int i = 0; i < (Count - HeaderCount); i++)
|
||||
{
|
||||
SQObjectType Type = sq_gettype(v, HeaderCount + 1 + i);
|
||||
switch (Type)
|
||||
{
|
||||
case OT_INTEGER:
|
||||
{
|
||||
SQInteger Buf;
|
||||
sq_getinteger(v, HeaderCount + 1 + i, &Buf);
|
||||
(*(int *)m) = Buf;
|
||||
m += sizeof(int);
|
||||
break;
|
||||
}
|
||||
case OT_FLOAT:
|
||||
{
|
||||
SQFloat Buf;
|
||||
sq_getfloat(v, HeaderCount + 1 + i, &Buf);
|
||||
(*(float *)m) = Buf;
|
||||
m += sizeof(float);
|
||||
break;
|
||||
}
|
||||
case OT_BOOL:
|
||||
{
|
||||
SQBool Buf;
|
||||
sq_getbool(v, HeaderCount + 1 + i, &Buf);
|
||||
(*(bool *)m) = Buf;
|
||||
m += sizeof(bool);
|
||||
break;
|
||||
}
|
||||
case OT_STRING:
|
||||
{
|
||||
const SQChar *Buf;
|
||||
sq_getstring(v, HeaderCount + 1 + i, &Buf);
|
||||
(*(char **)m) = (char *)Buf;
|
||||
m += sizeof(char *);
|
||||
break;
|
||||
}
|
||||
case OT_USERPOINTER:
|
||||
{
|
||||
SQUserPointer Buf;
|
||||
sq_getuserpointer(v, HeaderCount + 1 + i, &Buf);
|
||||
(*(void **)m) = Buf;
|
||||
m += sizeof(void *);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (RetType)
|
||||
{
|
||||
case POINTER:
|
||||
{
|
||||
void *B = CallGameT<void *>(FuncAddress, (va_list)bm);
|
||||
free(bm);
|
||||
sq_pushuserpointer(v, B);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
static SQInteger L_S_Ptr(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *str;
|
||||
sq_getstring(v, 2, &str);
|
||||
unsigned long long addr = std::stoull(str, 0, 16);
|
||||
void *ptr = reinterpret_cast<void *>(addr);
|
||||
sq_pushuserpointer(v, ptr);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void RegisterGame(HSQUIRRELVM v)
|
||||
{
|
||||
getConfigPath(szGamePath, sizeof(szGamePath));
|
||||
@@ -301,6 +484,7 @@ static void RegisterGame(HSQUIRRELVM v)
|
||||
// int 和指针相互转换
|
||||
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"));
|
||||
|
||||
// 获取频道配置
|
||||
register_World_func(v, Game_GetConfig, _SC("Sq_Game_GetConfig"));
|
||||
@@ -308,6 +492,8 @@ static void RegisterGame(HSQUIRRELVM v)
|
||||
register_World_func(v, L_WriteAddress, _SC("Sq_WriteAddress"));
|
||||
// 读地址int
|
||||
register_World_func(v, L_ReadAddress, _SC("Sq_ReadAddress"));
|
||||
// 读地址字符串
|
||||
register_World_func(v, L_ReadAddressString, _SC("Sq_ReadAddressString"));
|
||||
// 读取Byte
|
||||
register_World_func(v, L_ReadByteArr, _SC("Sq_ReadByteArr"));
|
||||
// 写入Byte
|
||||
@@ -318,8 +504,14 @@ static void RegisterGame(HSQUIRRELVM v)
|
||||
register_World_func(v, L_WriteBlobToAddress, _SC("Sq_WriteBlobToAddress"));
|
||||
// 通过ID从Pvf中查询名称
|
||||
register_World_func(v, L_GetNameByIdFromPvf, _SC("Sq_GetNameByIdFromPvf"));
|
||||
// 通过ID从Pvf中查询Data
|
||||
register_World_func(v, L_GetDataByIdFromPvf, _SC("Sq_GetDataByIdFromPvf"));
|
||||
// 创建数据库连接池
|
||||
register_World_func(v, L_CreatCConnectPool, _SC("Sq_CreatCConnectPool"));
|
||||
// 阻塞线程的数据库操作 无返回值
|
||||
register_World_func(v, L_MysqlExecNoRet, _SC("Sq_MysqlExecNoRet"));
|
||||
// 创建Socket连接
|
||||
register_World_func(v, L_CreatSocketConnect, _SC("Sq_CreatSocketConnect"));
|
||||
|
||||
register_World_func(v, L_CallFunc, _SC("Sq_CallFunc"));
|
||||
}
|
||||
@@ -8,6 +8,23 @@
|
||||
#include "sqstdsystem.h"
|
||||
#include <iostream>
|
||||
|
||||
template <typename R, typename A, typename... ARG>
|
||||
R CallParty(A call_addr, const ARG... arguments)
|
||||
{
|
||||
if (!call_addr)
|
||||
{
|
||||
return R();
|
||||
}
|
||||
const auto control = reinterpret_cast<R (*)(ARG...)>(call_addr);
|
||||
try
|
||||
{
|
||||
return control(arguments...);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
return R();
|
||||
}
|
||||
typedef int (*__CreateParty)(void *CParty, void *CUser);
|
||||
static SQInteger Party_CreateParty(HSQUIRRELVM v)
|
||||
{
|
||||
@@ -44,6 +61,16 @@ static SQInteger Party_SendPartyIpInfo(HSQUIRRELVM v)
|
||||
((__SendPartyIpInfo)0x0859CEA2)(P);
|
||||
return 0;
|
||||
}
|
||||
// 获取战斗对象
|
||||
static SQInteger Party_GetBattle_Field(HSQUIRRELVM v)
|
||||
{
|
||||
SQUserPointer P;
|
||||
sq_getuserpointer(v, 2, &P);
|
||||
|
||||
sq_pushuserpointer(v, P + 2852);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static SQInteger register_Party_func(HSQUIRRELVM v, SQFUNCTION f, const char *fname)
|
||||
{
|
||||
sq_pushroottable(v);
|
||||
@@ -63,4 +90,6 @@ static void RegisterParty(HSQUIRRELVM v)
|
||||
register_Party_func(v, Party_JoinParty, _SC("Sq_Party_JoinParty"));
|
||||
// 广播队伍玩家IP
|
||||
register_Party_func(v, Party_SendPartyIpInfo, _SC("Sq_Party_SendPartyIpInfo"));
|
||||
// 获取副本编号
|
||||
register_Party_func(v, Party_GetBattle_Field, _SC("Sq_Party_GetBattle_Field"));
|
||||
}
|
||||
@@ -413,6 +413,30 @@ static SQInteger CUser_RefreshLastQuestTime(HSQUIRRELVM v)
|
||||
*(int *)((void *)P + 0x79644) = 0;
|
||||
return 0;
|
||||
}
|
||||
// 充值点券
|
||||
static SQInteger CUser_RechargeCoupons(HSQUIRRELVM v)
|
||||
{
|
||||
SQUserPointer User;
|
||||
sq_getuserpointer(v, 2, &User);
|
||||
SQInteger Amount;
|
||||
sq_getinteger(v, 3, &Amount);
|
||||
CallUser<int>(0x80FFCA4, *(uintptr_t *)0x941F734, User, 5, Amount, (void *)0x8C7FA20, (void *)0x8C7FA20, "Gm", (void *)0, (void *)0, (void *)0);
|
||||
|
||||
CallUser<int>(0x8100790, *(uintptr_t *)0x941F734, User);
|
||||
return 0;
|
||||
}
|
||||
// 充值点券
|
||||
static SQInteger CUser_RechargeCouponsPoint(HSQUIRRELVM v)
|
||||
{
|
||||
SQUserPointer User;
|
||||
sq_getuserpointer(v, 2, &User);
|
||||
SQInteger Amount;
|
||||
sq_getinteger(v, 3, &Amount);
|
||||
CallUser<int>(0x80FFFC0, *(uintptr_t *)0x941F734, User, Amount, 4, (void *)0, (void *)0);
|
||||
|
||||
CallUser<int>(0x8100790, *(uintptr_t *)0x941F734, User);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SQInteger register_User_func(HSQUIRRELVM v, SQFUNCTION f, const char *fname)
|
||||
{
|
||||
@@ -497,4 +521,8 @@ static void RegisterUser(HSQUIRRELVM v)
|
||||
register_User_func(v, CUser_QuestAction, "Sq_CUser_QuestAction");
|
||||
// 刷新上次任务完成时间
|
||||
register_User_func(v, CUser_RefreshLastQuestTime, "Sq_CUser_RefreshLastQuestTime");
|
||||
// 充值点券
|
||||
register_User_func(v, CUser_RechargeCoupons, "Sq_CUser_RechargeCoupons");
|
||||
// 充值代币券
|
||||
register_User_func(v, CUser_RechargeCouponsPoint, "Sq_CUser_RechargeCouponsPoint");
|
||||
}
|
||||
@@ -28,6 +28,8 @@ public:
|
||||
static void Warring(std::string W);
|
||||
// 常规输出
|
||||
static void Logger(std::string L);
|
||||
//分割字符串
|
||||
static void Split(const std::string &src, std::vector<std::string> &dest, const std::string &separator);
|
||||
|
||||
// 获取当前时间戳
|
||||
static long long get_cur_time();
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
bool ConnectState = false;
|
||||
|
||||
public:
|
||||
Client(asio::io_context &io_context)
|
||||
Client(asio::io_context &io_context, std::string Ip, std::string Port)
|
||||
: resolver(io_context),
|
||||
socket(io_context)
|
||||
{
|
||||
@@ -209,7 +209,7 @@ public:
|
||||
|
||||
void InitSqr();
|
||||
void InitPackLogic();
|
||||
void Init();
|
||||
void Init(std::string Ip, std::string Port);
|
||||
void Send(const SQChar *Pck);
|
||||
void Logic();
|
||||
void IntToByteLittle(unsigned char *b, int Count);
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "sqstdmath.h"
|
||||
#include "sqstdstring.h"
|
||||
#include "sqstdsystem.h"
|
||||
#include "l_squirrel_register.hpp"
|
||||
#include "Tool.h"
|
||||
#include <map>
|
||||
#include <fstream>
|
||||
|
||||
@@ -6,18 +6,22 @@
|
||||
#include "sqstdmath.h"
|
||||
#include "sqstdstring.h"
|
||||
#include "sqstdsystem.h"
|
||||
#include "SqrReg_User.hpp" //用户类
|
||||
#include "SqrReg_Packet.hpp" //发包类
|
||||
#include "SqrReg_World.hpp" //世界类
|
||||
#include "SqrReg_Game.hpp" //游戏类
|
||||
#include "SqrReg_GameManager.hpp" //游戏管理器类
|
||||
#include "SqrReg_Party.hpp" //队伍类
|
||||
#include "SqrReg_Inven.hpp" //背包类
|
||||
#include "SqrReg_User.hpp" //用户类
|
||||
#include "SqrReg_Packet.hpp" //发包类
|
||||
#include "SqrReg_World.hpp" //世界类
|
||||
#include "SqrReg_Game.hpp" //游戏类
|
||||
#include "SqrReg_GameManager.hpp" //游戏管理器类
|
||||
#include "SqrReg_Party.hpp" //队伍类
|
||||
#include "SqrReg_Inven.hpp" //背包类
|
||||
#include "SqrReg_Battle_Field.hpp" //战斗对象类
|
||||
#include "SqrReg_Dungeon.hpp" //副本类
|
||||
#include <iostream>
|
||||
#include <stdarg.h>
|
||||
|
||||
static void GlobaRegisterSquirrel(HSQUIRRELVM v)
|
||||
{
|
||||
RegisterBattleField(v); // 战斗对象类
|
||||
RegisterDungeon(v); // 副本类
|
||||
RegisterInven(v); // 背包类
|
||||
RegisterGameManager(v); // 游戏管理器类
|
||||
RegisterParty(v); // 队伍类
|
||||
|
||||
Reference in New Issue
Block a user