244 lines
7.8 KiB
C++
244 lines
7.8 KiB
C++
|
|
//************************************
|
|||
|
|
// FileName: D:\VisualStudioSource\dnf_project\src\controller.cpp
|
|||
|
|
// FullName: D:\VisualStudioSource\dnf_project\src
|
|||
|
|
// Date: 2022/09/01
|
|||
|
|
// By: Vance
|
|||
|
|
// Copyright (c) 2022. Vance All rights reserved
|
|||
|
|
//************************************
|
|||
|
|
|
|||
|
|
#include "controller.hpp"
|
|||
|
|
|
|||
|
|
Controller::Controller() :
|
|||
|
|
old_UseJewel_dispatch_sig((UseJewel_dispatch_sig_Type*)base::Dispatcher_UseJewel::dispatch_sig),
|
|||
|
|
old_PacketDispatcher_doDispatch((PacketDispatcher_doDispatch_Type*)base::PacketDispatcher::doDispatch)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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); //<2F><>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>
|
|||
|
|
//.text:085BDF30 83 F8 1E cmp eax, 30
|
|||
|
|
CodeHook::WriteUChar((void*)(base::CParty::addDungeonClear_fix_2 + 2), 0x7E); //Զ<>ű<EFBFBD><C5B1><EFBFBD>
|
|||
|
|
//.text:085BDFC3 83 F8 32 cmp eax, 50
|
|||
|
|
CodeHook::WriteUChar((void*)(base::CParty::addDungeonClear_fix_3 + 2), 0x7E); //<2F><><EFBFBD>类<EFBFBD><E7B1BB>
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
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);
|
|||
|
|
//У<><D0A3><EFBFBD><EFBFBD>ɫ״̬<D7B4>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ
|
|||
|
|
if (state != 3)
|
|||
|
|
return 0;
|
|||
|
|
|
|||
|
|
int isEnableAvatarSocketAction = pUser->isEnableAvatarSocketAction();
|
|||
|
|
if (isEnableAvatarSocketAction)
|
|||
|
|
pUser->SendCmdErrorPacket(205, (unsigned char)isEnableAvatarSocketAction);
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>packet_buf
|
|||
|
|
|
|||
|
|
//ʱװ<CAB1><D7B0><EFBFBD>ڵı<DAB5><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
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);
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><C7B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><>ȡʱװ<CAB1><D7B0><EFBFBD><EFBFBD>
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
//У<><D0A3>ʱװ <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>Ϸ<EFBFBD>
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
//<2F><>ȡʱװ<CAB1><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
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++)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵı<DAB5><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
int emblem_inven_slot = pBuf->get_short();
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>item_id
|
|||
|
|
int emblem_item_id = pBuf->get_int();
|
|||
|
|
//<2F>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><C7B6>ʱװ<CAB1><D7B0><EFBFBD><EFBFBD>id
|
|||
|
|
int avartar_socket_slot = pBuf->get_byte();
|
|||
|
|
|
|||
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD>µ<EFBFBD><C2B5><EFBFBD>
|
|||
|
|
Inven_Item* emblem = inven->GetInvenRef(CInventory::INVENTORY_TYPE_ITEM, emblem_inven_slot);
|
|||
|
|
//У<><D0A3><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>Ϸ<EFBFBD>
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//У<><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>ʱװ<CAB1><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫҪ<C9AB><D2AA>
|
|||
|
|
|
|||
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>pvf<76><66><EFBFBD><EFBFBD>
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//У<><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
if (!citem->is_stackable() || (citem->GetItemType() != 20))
|
|||
|
|
{
|
|||
|
|
printf("citem->is_stackable() || (citem->GetItemType() : error \n");
|
|||
|
|
pUser->SendCmdErrorPacket(205, 209);
|
|||
|
|
return 0;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>֧<EFBFBD>ֵIJ<D6B5><C4B2><EFBFBD>
|
|||
|
|
int emblem_socket_type = citem->getJewelTargetSocket();
|
|||
|
|
|
|||
|
|
//<2F><>ȡҪ<C8A1><D2AA>Ƕ<EFBFBD><C7B6>ʱװ<CAB1><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
int avartar_socket_type = *(short*)(jewel_socket_data + avartar_socket_slot * 6);
|
|||
|
|
if (!(emblem_socket_type & avartar_socket_type))
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD>ƥ<EFBFBD><C6A5>
|
|||
|
|
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("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѷ<EFBFBD>ȡ!!!\n");
|
|||
|
|
|
|||
|
|
for (auto& avartar_socket_slot : emblems)
|
|||
|
|
{
|
|||
|
|
//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
int emblem_inven_slot = avartar_socket_slot.second.first;
|
|||
|
|
inven->delete_item(1, emblem_inven_slot, 1, 8, 1);
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>ʱװ<CAB1><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
int emblem_item_id = avartar_socket_slot.second.second;
|
|||
|
|
*(int*)(jewel_socket_data + avartar_socket_slot.first * 6 + 2) = emblem_item_id;
|
|||
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>item_id=%d <20>ѳɹ<D1B3><C9B9><EFBFBD>Ƕ<EFBFBD><C7B6>avartar_socket_slot=%d <20>IJ<EFBFBD><C4B2><EFBFBD>!\n", emblem_item_id, avartar_socket_slot);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//ʱװ<CAB1><D7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݴ浵
|
|||
|
|
DB_UpdateAvatarJewelSlot::makeRequest(pUser->getCurCharacNo(), avartar->get_ui_id(), (void*)jewel_socket_data);
|
|||
|
|
|
|||
|
|
//֪ͨ<CDA8>ͻ<EFBFBD><CDBB><EFBFBD>ʱװ<CAB1><D7B0><EFBFBD><EFBFBD><EFBFBD>Ѹ<EFBFBD><D1B8><EFBFBD>
|
|||
|
|
pUser->SendUpdateItemList(1, 1, avartar_inven_slot);
|
|||
|
|
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>!!!\n");
|
|||
|
|
//<2F>ذ<EFBFBD><D8B0><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>
|
|||
|
|
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 <20>ֽ<EFBFBD>
|
|||
|
|
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 Controller::Get()->old_PacketDispatcher_doDispatch(a1, user, packet_class, packet_id, packet_src, pecakt_len, a7, a8);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|