237 lines
7.6 KiB
C++
237 lines
7.6 KiB
C++
#include "controller.hpp"
|
|
|
|
|
|
controller* controller::pThis = NULL;
|
|
|
|
|
|
controller::controller() :
|
|
old_UseJewel_dispatch_sig((UseJewel_dispatch_sig_Type*)base::Dispatcher_UseJewel::dispatch_sig),
|
|
old_PacketDispatcher_doDispatch((PacketDispatcher_doDispatch_Type*)base::PacketDispatcher::doDispatch)
|
|
{
|
|
pThis = this;
|
|
}
|
|
|
|
controller::~controller()
|
|
{
|
|
|
|
}
|
|
|
|
void controller::init()
|
|
{
|
|
CodeHook::WriteUChar((void*)(base::GlobalData::Init_fix_1 - 0x1), 0);
|
|
//.text:085BDE9D 83 F8 0A cmp eax, 10
|
|
CodeHook::WriteUChar((void*)(base::CParty::addDungeonClear_fix_1 + 2), 0x7E); //普通被击
|
|
//.text:085BDF30 83 F8 1E cmp eax, 30
|
|
CodeHook::WriteUChar((void*)(base::CParty::addDungeonClear_fix_2 + 2), 0x7E); //远古被击
|
|
//.text:085BDFC3 83 F8 32 cmp eax, 50
|
|
CodeHook::WriteUChar((void*)(base::CParty::addDungeonClear_fix_3 + 2), 0x7E); //异界被击
|
|
|
|
|
|
|
|
mhook_PacketDispatcher_doDispatch.Hook((void**)&old_PacketDispatcher_doDispatch, (void*)hook_PacketDispatcher_doDispatch);
|
|
|
|
mhook_UseJewel_dispatch_sig.Hook((void**)&old_UseJewel_dispatch_sig, (void*)hook_UseJewel_dispatch_sig);
|
|
|
|
LOG("controller::init()");
|
|
|
|
}
|
|
|
|
int controller::hook_UseJewel_dispatch_sig(void* pDispatcher_UseJewel, CUser* pUser, PacketBuf* pBuf)
|
|
{
|
|
printf("getCurCharacName :%s \n", pUser->getCurCharacName().c_str());
|
|
printf("getCurCharacNo :%d \n", pUser->getCurCharacNo());
|
|
printf("get_buf_ptr :%p %p \n", pBuf->get_buf_ptr(0));
|
|
printf("get_len :%d \n", pBuf->get_len());
|
|
|
|
// printf("pBuf :%s \n", Util::ToHexString((const unsigned char*)pBuf->get_buf_ptr(0),40).c_str());
|
|
int state = pUser->get_state();
|
|
printf("state :%d \n", state);
|
|
//校验角色状态是否允许镶嵌
|
|
if (state != 3)
|
|
return 0;
|
|
|
|
int isEnableAvatarSocketAction = pUser->isEnableAvatarSocketAction();
|
|
if (isEnableAvatarSocketAction)
|
|
pUser->SendCmdErrorPacket(205, (unsigned char)isEnableAvatarSocketAction);
|
|
//解析packet_buf
|
|
|
|
//时装所在的背包槽
|
|
int avartar_inven_slot = pBuf->get_short();
|
|
printf("avartar_inven_slot :%d \n", avartar_inven_slot);
|
|
//时装item_id
|
|
int avartar_item_id = pBuf->get_int();
|
|
printf("avartar_item_id :%d \n", avartar_item_id);
|
|
//本次镶嵌徽章数量
|
|
int emblem_cnt = pBuf->get_byte();
|
|
printf("emblem_cnt :%d \n", emblem_cnt);
|
|
|
|
if (pUser->CheckItemLock(2, avartar_inven_slot))
|
|
{
|
|
pUser->SendCmdErrorPacket(205, 213);
|
|
return 0;
|
|
}
|
|
|
|
//获取时装道具
|
|
CInventory* inven = pUser->getCurCharacInvenW();
|
|
if (!inven)
|
|
{
|
|
printf("pUser->getCurCharacInvenW : error \n");
|
|
return 0;
|
|
}
|
|
Inven_Item* avartar = inven->GetInvenRef(CInventory::INVENTORY_TYPE_AVARTAR, avartar_inven_slot);
|
|
if (!avartar)
|
|
{
|
|
printf("inven->GetInvenRef : error \n");
|
|
return 0;
|
|
}
|
|
//校验时装 数据是否合法
|
|
if (avartar->isEmpty() || (avartar->getKey() != avartar_item_id) || pUser->CheckItemLock(2, avartar_inven_slot))
|
|
{
|
|
|
|
printf("avartar->isEmpty() || avartar->getKey() || pUser->CheckItemLock() : error \n");
|
|
return 0;
|
|
}
|
|
//获取时装插槽数据
|
|
WongWork::CAvatarItemMgr* avartar_add_info = avartar->get_add_info();
|
|
WongWork::CAvatarItemMgr* inven_avartar_mgr = inven->GetAvatarItemMgrR();
|
|
int jewel_socket_data = inven_avartar_mgr->getJewelSocketData(avartar_add_info);
|
|
if (!jewel_socket_data)
|
|
{
|
|
printf("jewel_socket_data : error \n");
|
|
return 0;
|
|
}
|
|
|
|
printf("jewel_socket_data :%s \n", Util::ToHexString((const unsigned char*)jewel_socket_data, 40).c_str());
|
|
if (emblem_cnt <= 3)
|
|
{
|
|
std::map<int, std::pair<int, int>> emblems;
|
|
for (int i = 0; i < emblem_cnt; i++)
|
|
{
|
|
//徽章所在的背包槽
|
|
int emblem_inven_slot = pBuf->get_short();
|
|
//徽章item_id
|
|
int emblem_item_id = pBuf->get_int();
|
|
//该徽章镶嵌的时装插槽id
|
|
int avartar_socket_slot = pBuf->get_byte();
|
|
|
|
//获取徽章道具
|
|
Inven_Item* emblem = inven->GetInvenRef(CInventory::INVENTORY_TYPE_ITEM, emblem_inven_slot);
|
|
//校验徽章及插槽数据是否合法
|
|
if (emblem->isEmpty() || (emblem->getKey() != emblem_item_id) || (avartar_socket_slot >= 3))
|
|
{
|
|
printf("emblem->isEmpty() || (emblem->getKey() : error \n");
|
|
pUser->SendCmdErrorPacket(205, 209);
|
|
return 0;
|
|
}
|
|
|
|
//校验徽章是否满足时装插槽颜色要求
|
|
|
|
//获取徽章pvf数据
|
|
CDataManager* DataManager = CDataManager::G_CDataManager();
|
|
if (!DataManager)
|
|
{
|
|
printf("CDataManager::G_CDataManager() : error \n");
|
|
pUser->SendCmdErrorPacket(205, 209);
|
|
return 0;
|
|
}
|
|
CItem* citem = DataManager->find_item(emblem_item_id);
|
|
if (!citem)
|
|
{
|
|
printf("DataManager->find_item() : error \n");
|
|
pUser->SendCmdErrorPacket(205, 209);
|
|
return 0;
|
|
}
|
|
|
|
//校验徽章类型
|
|
if (!citem->is_stackable() || (citem->GetItemType() != 20))
|
|
{
|
|
printf("citem->is_stackable() || (citem->GetItemType() : error \n");
|
|
pUser->SendCmdErrorPacket(205, 209);
|
|
return 0;
|
|
}
|
|
|
|
//获取徽章支持的插槽
|
|
int emblem_socket_type = citem->getJewelTargetSocket();
|
|
|
|
//获取要镶嵌的时装插槽类型
|
|
int avartar_socket_type = *(short*)(jewel_socket_data + avartar_socket_slot * 6);
|
|
if (!(emblem_socket_type & avartar_socket_type))
|
|
{
|
|
//插槽类型不匹配
|
|
printf("emblem_socket_type & avartar_socket_type\n");
|
|
pUser->SendCmdErrorPacket(205, 209);
|
|
return 0;
|
|
}
|
|
printf("avartar_socket_slot:%d emblem_inven_slot:%d emblem_item_id:%d\n", avartar_socket_slot, emblem_inven_slot, emblem_item_id);
|
|
emblems[avartar_socket_slot] = std::make_pair(emblem_inven_slot, emblem_item_id);
|
|
}
|
|
printf("数据已读取!!!\n");
|
|
|
|
for (auto& avartar_socket_slot : emblems)
|
|
{
|
|
//删除徽章
|
|
int emblem_inven_slot = avartar_socket_slot.second.first;
|
|
inven->delete_item(1, emblem_inven_slot, 1, 8, 1);
|
|
|
|
//设置时装插槽数据
|
|
int emblem_item_id = avartar_socket_slot.second.second;
|
|
*(int*)(jewel_socket_data + avartar_socket_slot.first * 6 + 2) = emblem_item_id;
|
|
printf("徽章item_id=%d 已成功镶嵌进avartar_socket_slot=%d 的槽内!\n", emblem_item_id, avartar_socket_slot);
|
|
}
|
|
|
|
//时装插槽数据存档
|
|
DB_UpdateAvatarJewelSlot::makeRequest(pUser->getCurCharacNo(), avartar->get_ui_id(), (void*)jewel_socket_data);
|
|
|
|
//通知客户端时装数据已更新
|
|
pUser->SendUpdateItemList(1, 1, avartar_inven_slot);
|
|
printf("徽章镶嵌完毕!!!\n");
|
|
//回包给客户端
|
|
InterfacePacketBuf* packet_guard = (InterfacePacketBuf*)PacketGuard::NewPacketGuard();
|
|
|
|
packet_guard->put_header(1, 204);
|
|
packet_guard->put_int(1);
|
|
packet_guard->finalize(1);
|
|
pUser->Send((PacketGuard*)packet_guard);
|
|
PacketGuard::DelPacketGuard((PacketGuard*)packet_guard);
|
|
}
|
|
|
|
// 08217C06 分解
|
|
return 0;
|
|
}
|
|
|
|
int controller::hook_PacketDispatcher_doDispatch(PacketDispatcher* a1, CUser* user, int packet_class, int packet_id, void* packet_src, int pecakt_len, int a7, int a8)
|
|
{
|
|
//void* pAction = *a1->get_dispatcher(packet_id);
|
|
//
|
|
//if (pAction)
|
|
//{
|
|
// LOG("Recv() class:%d id:%d len:%d data:%s callback:%p %p %p %p %p %p "
|
|
// , packet_class
|
|
// , packet_id
|
|
// , pecakt_len
|
|
// , Util::ToHexString((const unsigned char*)packet_src, pecakt_len).c_str()
|
|
// , *((void**)pAction)
|
|
// , (void*)*((unsigned int*)pAction + 12)
|
|
// , (void*)*((unsigned int*)pAction + 16)
|
|
// , (void*)*((unsigned int*)pAction + 20)
|
|
// , (void*)*((unsigned int*)pAction + 24)
|
|
// , (void*)*((unsigned int*)pAction + 28)
|
|
// );
|
|
//}
|
|
//else
|
|
//{
|
|
// LOG("Recv() class:%d id:%d len:%d data:%s "
|
|
// , packet_class
|
|
// , packet_id
|
|
// , pecakt_len
|
|
// , Util::ToHexString((const unsigned char*)packet_src, pecakt_len).c_str()
|
|
// );
|
|
//}
|
|
|
|
if (packet_id == Packet_UseItem)
|
|
{
|
|
LOG("hook_PacketDispatcher_doDispatch packet_data :%s ", Util::ToHexString((const unsigned char*)packet_src, pecakt_len).c_str());
|
|
}
|
|
return pThis->old_PacketDispatcher_doDispatch(a1, user, packet_class, packet_id, packet_src, pecakt_len, a7, a8);
|
|
}
|