This commit is contained in:
root
2024-04-24 10:25:44 +08:00
parent 627bf43ee3
commit 248388a322
5271 changed files with 3753425 additions and 803 deletions

View File

@@ -7,40 +7,40 @@
//************************************
#include "controller.h"
extern HSQUIRRELVM v;
extern std::recursive_mutex SqMtx;
Controller::Controller() :
assembler(Arch::kX86),
Asm(NULL)
Controller::Controller() : assembler(Arch::kX86),
Asm(NULL)
{
Asm = assembler.GetAssembler();
}
Controller::~Controller()
{
}
void Controller::init()
{
CMem::WriteUChar((void*)(base::GlobalData::Init_fix_1 - 0x1), 0);
CMem::WriteUChar((void *)(base::GlobalData::Init_fix_1 - 0x1), 0);
//.text:085BDE9D 83 F8 0A cmp eax, 10
CMem::WriteUChar((void*)(base::CParty::addDungeonClear_fix_1 + 2), 0x7E); //普通被击
CMem::WriteUChar((void *)(base::CParty::addDungeonClear_fix_1 + 2), 0x7E); // 普通被击
//.text:085BDF30 83 F8 1E cmp eax, 30
CMem::WriteUChar((void*)(base::CParty::addDungeonClear_fix_2 + 2), 0x7E); //远古被击
CMem::WriteUChar((void *)(base::CParty::addDungeonClear_fix_2 + 2), 0x7E); // 远古被击
//.text:085BDFC3 83 F8 32 cmp eax, 50
CMem::WriteUChar((void*)(base::CParty::addDungeonClear_fix_3 + 2), 0x7E); //异界被击
CMem::WriteUChar((void *)(base::CParty::addDungeonClear_fix_3 + 2), 0x7E); // 异界被击
CMem::WriteUChar((void *)(0x081C025F + 1), 0x0B);
CMem::WriteUChar((void *)(0x081C029E + 1), 0x0B);
/* 修正使用代币增加积分
地址 长度 原始字节 已修补字节
08179043 0x1 97 B8
0817904E 0x1 8C AD
*/
CMem::WriteUChar((void*)(0x08179043), 0xB8);
CMem::WriteUChar((void*)(0x0817904E), 0xAD);
CMem::WriteUChar((void *)(0x08179043), 0xB8);
CMem::WriteUChar((void *)(0x0817904E), 0xAD);
//mov dword ptr [esp+4], 8E0F448h
// mov dword ptr [esp+4], 8E0F448h
Asm->lea(eax, dword_ptr(ebp, -0x84));
Asm->mov(dword_ptr(esp), eax);
Asm->mov(eax, int(&hook_importCashShopItemList));
@@ -49,9 +49,9 @@ void Controller::init()
Asm->mov(eax, base::importCashShopItemList_hook_end);
Asm->jmp(eax);
auto code_importCashShopItemList = assembler.GetBytes(true);
void* new_importCashShopItemList_addr = Utils::alloc(code_importCashShopItemList.size());
void *new_importCashShopItemList_addr = Utils::alloc(code_importCashShopItemList.size());
CMem::WriteBytes(new_importCashShopItemList_addr, code_importCashShopItemList.data(), code_importCashShopItemList.size());
LOG("code :%s", Utils::ToHexString((const unsigned char*)code_importCashShopItemList.data(), code_importCashShopItemList.size()).c_str());
LOG("code :%s", Utils::ToHexString((const unsigned char *)code_importCashShopItemList.data(), code_importCashShopItemList.size()).c_str());
LOG("code_addr :%p", new_importCashShopItemList_addr);
CMem::HookJmp(base::importCashShopItemList_hook_begin, (int)new_importCashShopItemList_addr);
@@ -59,7 +59,7 @@ void Controller::init()
/************************************************************************/
/* HOOK 商城购买物品成功处理 */
/************************************************************************/
//mov dword ptr [ebp-0FCh], 0FFFFFFFFh
// mov dword ptr [ebp-0FCh], 0FFFFFFFFh
Asm->lea(eax, dword_ptr(ebp, -0xEC));
Asm->mov(dword_ptr(esp, 0x10), eax);
@@ -79,20 +79,18 @@ void Controller::init()
Asm->mov(eax, int(&hook_ProcessIPG_ResultOutput));
Asm->call(eax);
Asm->mov(dword_ptr(ebp, -0xfc), 0x0FFFFFFFF);
Asm->mov(eax, base::ItemVendingMachine::ProcessIPG_ResultOutput_hook_end);
Asm->jmp(eax);
auto code_ProcessIPG_ResultOutput = assembler.GetBytes(true);
void* new_ProcessIPG_ResultOutput_addr = Utils::alloc(code_ProcessIPG_ResultOutput.size());
void *new_ProcessIPG_ResultOutput_addr = Utils::alloc(code_ProcessIPG_ResultOutput.size());
CMem::WriteBytes(new_ProcessIPG_ResultOutput_addr, code_ProcessIPG_ResultOutput.data(), code_ProcessIPG_ResultOutput.size());
LOG("code_2 :%s", Utils::ToHexString((const unsigned char*)code_ProcessIPG_ResultOutput.data(), code_ProcessIPG_ResultOutput.size()).c_str());
LOG("code_2 :%s", Utils::ToHexString((const unsigned char *)code_ProcessIPG_ResultOutput.data(), code_ProcessIPG_ResultOutput.size()).c_str());
LOG("code_addr_2 :%p", new_ProcessIPG_ResultOutput_addr);
CMem::HookJmp(base::ItemVendingMachine::ProcessIPG_ResultOutput_hook_begin, (int)new_ProcessIPG_ResultOutput_addr);
//HOOK_SETUP(IPacketDispatcher_ParamBase_dispatch_template);
// HOOK_SETUP(IPacketDispatcher_ParamBase_dispatch_template);
HOOK_SETUP(UseJewel_dispatch_sig);
@@ -109,7 +107,11 @@ void Controller::init()
HOOK_SETUP(Init);
LOG("Controller::init()");
}
void Controller::Jinit()
{
// HOOK_SETUP(LenDispatcher_New_Gmdebug_Command);
}
int Controller::hook_IPacketDispatcher_ParamBase_dispatch_template(int a1, int a2, int a3)
@@ -120,16 +122,15 @@ int Controller::hook_IPacketDispatcher_ParamBase_dispatch_template(int a1, int a
// [DNF_PROJECT] + 20 0x8bd8d5c : Dispatcher_ModItemAttr::read(PacketBuf &,MSG_BASE &)
// [DNF_PROJECT] + 24 0x8bd8d60 : Dispatcher_ModItemAttr::process(CUser *,MSG_BASE &,ParamBase &)
// [DNF_PROJECT] + 28 0x8bd8d64 : IPacketDispatcher<MSG_BASE,ParamBase,(ch_state)0>::send(CUser *,ParamBase&)
//
//
//
//
// [DNF_PROJECT] + 12 0x8bd7dd4 : Dispatcher_Antibot::dispatch_sig
// [DNF_PROJECT] + 16 0x8bd7dd8 : IPacketDispatcher<MSG_BASE,ParamBase,(ch_state)0>::check_state(CUser *,PacketBuf &)
// [DNF_PROJECT] + 20 0x8bd7ddc : Dispatcher_Antibot::read(PacketBuf &,MSG_BASE &)
// [DNF_PROJECT] + 24 0x8bd7de0 : Dispatcher_Antibot::process(CUser *,MSG_BASE &,ParamBase &)
// [DNF_PROJECT] + 28 0x8bd7de4 : IPacketDispatcher<MSG_BASE,ParamBase,(ch_state)0>::send(CUser *,ParamBase&)
//LOG("ParamBase_dispatch_template[ +12 :%p +16 :%p +20 :%p +24 :%p +28 :%p ]"
// LOG("ParamBase_dispatch_template[ +12 :%p +16 :%p +20 :%p +24 :%p +28 :%p ]"
// , *(int*)a1 + 12
// , *(int*)a1 + 16
// , *(int*)a1 + 20
@@ -139,7 +140,7 @@ int Controller::hook_IPacketDispatcher_ParamBase_dispatch_template(int a1, int a
Controller::Get()->old_IPacketDispatcher_ParamBase_dispatch_template(a1, a2, a3);
}
int Controller::hook_UseJewel_dispatch_sig(void* pDispatcher_UseJewel, CUser* user, PacketBuf* pBuf)
int Controller::hook_UseJewel_dispatch_sig(void *pDispatcher_UseJewel, CUser *user, PacketBuf *pBuf)
{
ENUM_PACK_RET_TYPE ret = CDispatch::Get()->UseJewel_dispatch_sig(pDispatcher_UseJewel, user, pBuf);
int result = (ret == PAK_ERROR) ? 1 : 0;
@@ -147,7 +148,7 @@ int Controller::hook_UseJewel_dispatch_sig(void* pDispatcher_UseJewel, CUser* us
return result;
}
int Controller::hook_Dispatcher_ModItemAttr_dispatch_sig(Dispatcher_ModItemAttr* dis_mod, CUser* user, PacketBuf* pBuf)
int Controller::hook_Dispatcher_ModItemAttr_dispatch_sig(Dispatcher_ModItemAttr *dis_mod, CUser *user, PacketBuf *pBuf)
{
PacketBuf new_buf;
memcpy(&new_buf, pBuf, sizeof(PacketBuf));
@@ -155,16 +156,13 @@ int Controller::hook_Dispatcher_ModItemAttr_dispatch_sig(Dispatcher_ModItemAttr*
int equipment_id = 0;
short item_pos = 0;
if ((unsigned __int8)new_buf.get_short(&equipment_pos) != 1
|| (unsigned __int8)new_buf.get_int(&equipment_id) != 1
|| (unsigned __int8)new_buf.get_short(&item_pos) != 1)
if ((unsigned __int8)new_buf.get_short(&equipment_pos) != 1 || (unsigned __int8)new_buf.get_int(&equipment_id) != 1 || (unsigned __int8)new_buf.get_short(&item_pos) != 1)
{
user->SendCmdErrorPacket(84, -1);
return 0;
}
CInventory* CurCharacInvenW = user->getCurCharacInvenR();
CInventory *CurCharacInvenW = user->getCurCharacInvenR();
auto item_inven = CurCharacInvenW->GetInvenRef(CInventory::INVENTORY_TYPE_ITEM, item_pos);
@@ -177,43 +175,35 @@ int Controller::hook_Dispatcher_ModItemAttr_dispatch_sig(Dispatcher_ModItemAttr*
return Get()->old_Dispatcher_ModItemAttr_dispatch_sig(dis_mod, user, pBuf);
}
int Controller::hook_PacketDispatcher_doDispatch(PacketDispatcher* a1, CUser* user, int packet_class, int packet_id, char* packet_src, int packet_len, int a7, int a8)
int Controller::hook_PacketDispatcher_doDispatch(PacketDispatcher *a1, CUser *user, int packet_class, int packet_id, char *packet_src, int packet_len, int a7, int a8)
{
int(***dispatcher)(int, CUser*, char*) = (int(***)(int, CUser*, char*))a1->get_dispatcher(packet_id);
int (***dispatcher)(int, CUser *, char *) = (int (***)(int, CUser *, char *))a1->get_dispatcher(packet_id);
if (dispatcher)
{
//v32 = (**dispatcher)(dispatcher, user, v25);
LOG("Recv() class:%d id:%d len:%d %p [ +00 :%p +12 :%p +16 :%p +20 :%p +24 :%p +28 :%p ]"
, packet_class
, packet_id
, packet_len
, (**dispatcher)
, *(int*)dispatcher
, *(int*)dispatcher + 12
, *(int*)dispatcher + 16
, *(int*)dispatcher + 20
, *(int*)dispatcher + 24
, *(int*)dispatcher + 28
);
// v32 = (**dispatcher)(dispatcher, user, v25);
// LOG("Recv() class:%d id:%d len:%d %p [ +00 :%p +12 :%p +16 :%p +20 :%p +24 :%p +28 :%p ]"
// , packet_class
// , packet_id
// , packet_len
// , (**dispatcher)
// , *(int*)dispatcher
// , *(int*)dispatcher + 12
// , *(int*)dispatcher + 16
// , *(int*)dispatcher + 20
// , *(int*)dispatcher + 24
// , *(int*)dispatcher + 28
// );
}
// LOG("Recv() class:%d id:%d len:%d packet_data :%s ", packet_class, packet_id, packet_len, Utils::ToHexString((const unsigned char *)packet_src, packet_len).c_str());
if (packet_id == PACKET_ID_ITEM_USE_EQUIPMENT_MOVEITEM)
{
int result = 0;
PacketBuf* v25 = PacketBuf::NewPacketBuf();
PacketBuf *v25 = PacketBuf::NewPacketBuf();
user->setLastPacketID(packet_id);
v25->bind_packet(packet_src, packet_len);
LOG("Recv() class:%d id:%d len:%d packet_data :%s "
, packet_class
, packet_id
, packet_len
, Utils::ToHexString((const unsigned char*)packet_src, packet_len).c_str()
);
LOG("Recv() class:%d id:%d len:%d packet_data :%s ", packet_class, packet_id, packet_len, Utils::ToHexString((const unsigned char *)packet_src, packet_len).c_str());
if (v25)
{
@@ -225,51 +215,177 @@ int Controller::hook_PacketDispatcher_doDispatch(PacketDispatcher* a1, CUser* us
}
return result;
}
// 区域移动
else if (packet_id == 38)
{
std::lock_guard<std::recursive_mutex> lock(SqMtx);
SQBool R;
// 执行虚拟机Main函数
SQInteger top = sq_gettop(v); // saves the stack size before the call
sq_pushroottable(v); // pushes the global table
sq_pushstring(v, _SC("Cb_move_area"), -1);
if (SQ_SUCCEEDED(sq_get(v, -2)))
{ // gets the fie123oo' from the global table
sq_pushroottable(v); // push the 'this' (in this case is the global table)
sq_pushuserpointer(v, user);
sq_pushinteger(v, int(*(unsigned char *)(packet_src + 0x0D)));
sq_pushinteger(v, int(*(unsigned char *)(packet_src + 0x0E)));
sq_call(v, 4, SQTrue, SQTrue); // calls the function
sq_getbool(v, -1, &R);
}
sq_settop(v, top); // restores the original stack size
if (!R)
return 0;
}
// 普通输入
else if (packet_id == 17)
{
std::string str = Utils::PackToHexString((const unsigned char *)packet_src, 20);
std::lock_guard<std::recursive_mutex> lock(SqMtx);
SQBool R;
// 执行虚拟机Main函数
SQInteger top = sq_gettop(v); // saves the stack size before the call
sq_pushroottable(v); // pushes the global table
sq_pushstring(v, _SC("Cb_base_input"), -1);
if (SQ_SUCCEEDED(sq_get(v, -2)))
{ // gets the fie123oo' from the global table
sq_pushroottable(v); // push the 'this' (in this case is the global table)
sq_pushuserpointer(v, user);
sq_pushstring(v, _SC(str.c_str()), -1);
sq_call(v, 3, SQTrue, SQTrue); // calls the function
sq_getbool(v, -1, &R);
}
sq_settop(v, top); // restores the original stack size
if (!R)
return 0;
}
// GM输入
else if (packet_id == 179)
{
// std::cout << "传入的: " << std::hex << (int)user << std::endl;
std::string str = Utils::PackToHexString((const unsigned char *)packet_src, 13);
str = str.substr(2);
std::lock_guard<std::recursive_mutex> lock(SqMtx);
// 执行虚拟机Main函数
SQInteger top = sq_gettop(v); // saves the stack size before the call
sq_pushroottable(v); // pushes the global table
sq_pushstring(v, _SC("Cb_gm_input"), -1);
if (SQ_SUCCEEDED(sq_get(v, -2)))
{ // gets the fie123oo' from the global table
sq_pushroottable(v); // push the 'this' (in this case is the global table)
sq_pushuserpointer(v, user);
sq_pushstring(v, _SC(str.c_str()), -1);
sq_call(v, 3, SQFalse, SQTrue); // calls the function
}
sq_settop(v, top); // restores the original stack size
}
// 特殊道具使用
else if (packet_id == 255)
{
std::lock_guard<std::recursive_mutex> lock(SqMtx);
// 执行虚拟机Main函数
SQInteger top = sq_gettop(v); // saves the stack size before the call
sq_pushroottable(v); // pushes the global table
sq_pushstring(v, _SC("Cb_use_item_sp"), -1);
if (SQ_SUCCEEDED(sq_get(v, -2)))
{ // gets the fie123oo' from the global table
sq_pushroottable(v); // push the 'this' (in this case is the global table)
sq_pushuserpointer(v, user);
sq_pushinteger(v, int(*(int *)(packet_src + 0x0D)));
sq_call(v, 3, SQFalse, SQTrue); // calls the function
}
sq_settop(v, top); // restores the original stack size
}
// 自定义包
else if (packet_id == 130)
{
std::string str = Utils::PackToHexString((const unsigned char *)packet_src, 13);
std::lock_guard<std::recursive_mutex> lock(SqMtx);
// 执行虚拟机Main函数
SQInteger top = sq_gettop(v); // saves the stack size before the call
sq_pushroottable(v); // pushes the global table
sq_pushstring(v, _SC("OnClientSocketMsg"), -1);
if (SQ_SUCCEEDED(sq_get(v, -2)))
{ // gets the fie123oo' from the global table
sq_pushroottable(v); // push the 'this' (in this case is the global table)
sq_pushuserpointer(v, user);
sq_pushstring(v, _SC(str.c_str()), -1);
sq_call(v, 3, SQFalse, SQTrue); // calls the function
}
sq_settop(v, top); // restores the original stack size
}
return Get()->old_PacketDispatcher_doDispatch(a1, user, packet_class, packet_id, packet_src, packet_len, a7, a8);
}
int Controller::hook_DisPatcher_MoveMap_dispatch_sig(void* a1, CUser* pUser, PacketBuf* pBuf)
int Controller::hook_LenDispatcher_New_Gmdebug_Command(void *Command, void *CUser, void *PacketBuf)
{
//ENUM_PACK_RET_TYPE ret = CDispatch::Get()->MoveMap_dispatch_sig(a1, pUser, pBuf);
//int result = (ret == PAK_ERROR) ? 1 : 0;
void *Pck = (void *)((*(int *)(PacketBuf + 20)) + 13);
int msg_len = *(int *)(Pck);
std::string msg((char *)(Pck + 4), msg_len);
msg = msg.substr(2);
std::lock_guard<std::recursive_mutex> lock(SqMtx);
// 执行虚拟机Main函数
SQInteger top = sq_gettop(v); // saves the stack size before the call
sq_pushroottable(v); // pushes the global table
sq_pushstring(v, _SC("Cb_gm_input"), -1);
if (SQ_SUCCEEDED(sq_get(v, -2)))
{ // gets the fie123oo' from the global table
sq_pushroottable(v); // push the 'this' (in this case is the global table)
sq_pushuserpointer(v, Command);
sq_pushuserpointer(v, CUser);
sq_pushstring(v, _SC(msg.c_str()), -1);
sq_call(v, 4, SQFalse, SQTrue); // calls the function
}
sq_settop(v, top); // restores the original stack size
int Ret = Get()->old_LenDispatcher_New_Gmdebug_Command(Command, CUser, PacketBuf);
return Ret;
}
int Controller::hook_DisPatcher_MoveMap_dispatch_sig(void *a1, CUser *pUser, PacketBuf *pBuf)
{
// ENUM_PACK_RET_TYPE ret = CDispatch::Get()->MoveMap_dispatch_sig(a1, pUser, pBuf);
// int result = (ret == PAK_ERROR) ? 1 : 0;
return Get()->old_DisPatcher_MoveMap_dispatch_sig(a1, pUser, pBuf);
}
int Controller::hook_Inter_LoadEtc_dispatch_sig(void* a1, CUser* pUser, char* a3)
int Controller::hook_Inter_LoadEtc_dispatch_sig(void *a1, CUser *pUser, char *a3)
{
CDispatch::Get()->Inter_LoadEtc_dispatch_sig(a1, pUser, a3);
return Get()->old_Inter_LoadEtc_dispatch_sig(a1, pUser, a3);
}
int Controller::hook_DisPatcher_ReturnToSelectCharacter_dispatch_sig(void* a1, CUser* pUser, char* a3)
int Controller::hook_DisPatcher_ReturnToSelectCharacter_dispatch_sig(void *a1, CUser *pUser, char *a3)
{
CDispatch::Get()->DisPatcher_ReturnToSelectCharacter_dispatch_sig(a1, pUser, a3);
return Get()->old_DisPatcher_ReturnToSelectCharacter_dispatch_sig(a1, pUser, a3);
}
void Controller::hook_importCashShopItemList(const std::string* str)
void Controller::hook_importCashShopItemList(const std::string *str)
{
if (str != NULL)
CDispatch::Get()->importCashShopItemList(str);
}
void Controller::hook_ProcessIPG_ResultOutput(CUser* user, int Goods_No, int item_id, int Cera_Type, InterfacePacketBuf* pbuf)
void Controller::hook_ProcessIPG_ResultOutput(CUser *user, int Goods_No, int item_id, int Cera_Type, InterfacePacketBuf *pbuf)
{
CDispatch::Get()->ProcessIPG_ResultOutput(user, Goods_No, item_id, Cera_Type, pbuf);
}
int Controller::hook_Dispatcher_BuyCeraShopItem_dispatch_sig(void* a1, CUser* pUser, PacketBuf* pBuf)
int Controller::hook_Dispatcher_BuyCeraShopItem_dispatch_sig(void *a1, CUser *pUser, PacketBuf *pBuf)
{
return 0;
}
bool Controller::hook_Init(int a1, char** a2)
bool Controller::hook_Init(int a1, char **a2)
{
auto result = Get()->old_Init(a1, a2);
if (result)
{
CDispatch::Get()->Init_done(a1, (const char**)a2);
CDispatch::Get()->Init_done(a1, (const char **)a2);
}
return result;
}