diff --git a/src/controller.cpp b/src/controller.cpp index 21ccc7a..81ba387 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -8,11 +8,7 @@ #include "controller.h" -Controller::Controller() : - old_IPacketDispatcher_ParamBase_dispatch_template((IPacketDispatcher_ParamBase_dispatch_template_Type*)base::IPacketDispatcher::ParamBase::dispatch_template), - old_UseJewel_dispatch_sig((UseJewel_dispatch_sig_Type*)base::Dispatcher_UseJewel::dispatch_sig), - old_Dispatcher_ModItemAttr_dispatch_sig((Dispatcher_ModItemAttr_dispatch_sig_Type*)base::Dispatcher_ModItemAttr::dispatch_sig), - old_PacketDispatcher_doDispatch((PacketDispatcher_doDispatch_Type*)base::PacketDispatcher::doDispatch) +Controller::Controller() { } @@ -45,15 +41,17 @@ void Controller::init() - //mhook_IPacketDispatcher_ParamBase_dispatch_template.Hook((void**)&old_IPacketDispatcher_ParamBase_dispatch_template, (void*)hook_IPacketDispatcher_ParamBase_dispatch_template); + //HOOK_SETUP(IPacketDispatcher_ParamBase_dispatch_template); + HOOK_SETUP(UseJewel_dispatch_sig); - mhook_UseJewel_dispatch_sig.Hook((void**)&old_UseJewel_dispatch_sig, (void*)hook_UseJewel_dispatch_sig); + HOOK_SETUP(Dispatcher_ModItemAttr_dispatch_sig); - mhook_Dispatcher_ModItemAttr_dispatch_sig.Hook((void**)&old_Dispatcher_ModItemAttr_dispatch_sig, (void*)hook_Dispatcher_ModItemAttr_dispatch_sig); + HOOK_SETUP(PacketDispatcher_doDispatch); - mhook_PacketDispatcher_doDispatch.Hook((void**)&old_PacketDispatcher_doDispatch, (void*)hook_PacketDispatcher_doDispatch); + HOOK_SETUP(DisPatcher_MoveMap_dispatch_sig); + HOOK_SETUP(Inter_LoadEtc_dispatch_sig); LOG("Controller::init()"); @@ -99,8 +97,8 @@ int Controller::hook_Dispatcher_ModItemAttr_dispatch_sig(Dispatcher_ModItemAttr* PacketBuf new_buf; memcpy(&new_buf, pBuf, sizeof(PacketBuf)); short equipment_pos = 0; - int equipment_id = 0; - short item_pos = 0; + 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 @@ -121,7 +119,7 @@ int Controller::hook_Dispatcher_ModItemAttr_dispatch_sig(Dispatcher_ModItemAttr* int result = (ret == PAK_ERROR) ? 1 : 0; return result; } - return Controller::Get()->old_Dispatcher_ModItemAttr_dispatch_sig(dis_mod, user, pBuf); + 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) @@ -172,7 +170,25 @@ int Controller::hook_PacketDispatcher_doDispatch(PacketDispatcher* a1, CUser* us } return result; } - return Controller::Get()->old_PacketDispatcher_doDispatch(a1, user, packet_class, packet_id, packet_src, packet_len, a7, a8); + 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) +{ + ENUM_PACK_RET_TYPE ret = CDispatch::Get()->MoveMap_dispatch_sig(a1, pUser, pBuf); + int result = (ret == PAK_ERROR) ? 1 : 0; + return result; +} + +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) +{ + CDispatch::Get()->DisPatcher_ReturnToSelectCharacter_dispatch_sig(a1, pUser, a3); + return Get()->old_DisPatcher_ReturnToSelectCharacter_dispatch_sig(a1, pUser, a3); +} diff --git a/src/controller.h b/src/controller.h index 5784235..88ebd93 100644 --- a/src/controller.h +++ b/src/controller.h @@ -8,6 +8,13 @@ #define SUBHOOK_SETUP(func) h##func.Hook((void **)&func, (void *)_##func) +#define INIT_HOOK(func, addr) \ + using Type_##func = decltype(hook_##func); \ + Type_##func * old_##func = (Type_##func *)addr; \ + FuncHook mhook_##func + +#define HOOK_SETUP(func) mhook_##func.Hook((void **)&old_##func, (void *)hook_##func) + class Controller { public: @@ -50,26 +57,19 @@ private: */ static int hook_PacketDispatcher_doDispatch(PacketDispatcher* a1, CUser* a2, int a3, int packet_id, char* packet_src, int pecakt_len, int a7, int a8); + static int hook_DisPatcher_MoveMap_dispatch_sig(void* a1, CUser* pUser, PacketBuf* pBuf); + static int hook_Inter_LoadEtc_dispatch_sig(void* a1, CUser* pUser, char* a3); + + static int hook_DisPatcher_ReturnToSelectCharacter_dispatch_sig(void* a1, CUser* pUser, char* a3); private: - using IPacketDispatcher_ParamBase_dispatch_template_Type = decltype(hook_IPacketDispatcher_ParamBase_dispatch_template); - IPacketDispatcher_ParamBase_dispatch_template_Type* old_IPacketDispatcher_ParamBase_dispatch_template; - - using UseJewel_dispatch_sig_Type = decltype(hook_UseJewel_dispatch_sig); - UseJewel_dispatch_sig_Type* old_UseJewel_dispatch_sig; - - using Dispatcher_ModItemAttr_dispatch_sig_Type = decltype(hook_Dispatcher_ModItemAttr_dispatch_sig); - Dispatcher_ModItemAttr_dispatch_sig_Type* old_Dispatcher_ModItemAttr_dispatch_sig; - - using PacketDispatcher_doDispatch_Type = decltype(hook_PacketDispatcher_doDispatch); - PacketDispatcher_doDispatch_Type* old_PacketDispatcher_doDispatch; - - -private: - FuncHook mhook_IPacketDispatcher_ParamBase_dispatch_template; - FuncHook mhook_UseJewel_dispatch_sig; - FuncHook mhook_Dispatcher_ModItemAttr_dispatch_sig; - FuncHook mhook_PacketDispatcher_doDispatch; + INIT_HOOK(IPacketDispatcher_ParamBase_dispatch_template, base::IPacketDispatcher::ParamBase::dispatch_template); + INIT_HOOK(PacketDispatcher_doDispatch, base::PacketDispatcher::doDispatch); + INIT_HOOK(Dispatcher_ModItemAttr_dispatch_sig, base::Dispatcher_ModItemAttr::dispatch_sig); + INIT_HOOK(UseJewel_dispatch_sig, base::Dispatcher_UseJewel::dispatch_sig); + INIT_HOOK(DisPatcher_MoveMap_dispatch_sig, base::DisPatcher_MoveMap::dispatch_sig); + INIT_HOOK(Inter_LoadEtc_dispatch_sig, base::Inter_LoadEtc::dispatch_sig); + INIT_HOOK(DisPatcher_ReturnToSelectCharacter_dispatch_sig, base::DisPatcher_ReturnToSelectCharacter::dispatch_sig); }; \ No newline at end of file diff --git a/src/df_main.cpp b/src/df_main.cpp index 90c65ef..15758d3 100644 --- a/src/df_main.cpp +++ b/src/df_main.cpp @@ -605,7 +605,7 @@ void loga() SUBHOOK_SETUP(GetPvPTeamCount); SUBHOOK_SETUP(set_add_info); SUBHOOK_SETUP(reach_game_world); - SUBHOOK_SETUP(Inter_LoadEtc_dispatch_sig); + //SUBHOOK_SETUP(Inter_LoadEtc_dispatch_sig); Controller::Get()->init(); //SUBHOOK_SETUP(isSocketAvatar); if (nMaxGrade > 70) diff --git a/src/dispatch.cpp b/src/dispatch.cpp index 1fb2725..4b0bf78 100644 --- a/src/dispatch.cpp +++ b/src/dispatch.cpp @@ -8,7 +8,8 @@ #include "dispatch.h" -CDispatch::CDispatch() +CDispatch::CDispatch() : + last_move_map_tickcount(0) { } @@ -124,6 +125,11 @@ ENUM_PACK_RET_TYPE CDispatch::UseEquipmentMoveItem(CUser* user, PacketBuf* pBuf) //Data: equipment_citem->GetItemType=147418664 item_citem->is_stackable=1 item_citem->GetItemType=11 int equipment_Type = ((CEquipItem*)equipment_citem)->GetItemType(); int rarity = equipment_citem->get_rarity(); + if (rarity != 4) + { + return PAK_OK; + } + LOG(u8"Data: equipment_citem->GetItemType=%d item_citem->is_stackable=%d item_citem->GetItemType=%d" , equipment_Type @@ -190,7 +196,7 @@ ENUM_PACK_RET_TYPE CDispatch::UseEquipmentMoveItem(CUser* user, PacketBuf* pBuf) //inven->delete_item(1, emblem_inven_slot, 1, 8, 1); auto invenW = user->getCurCharacInvenW(); InterfacePacketBuf* packet_guard = (InterfacePacketBuf*)PacketGuard::NewPacketGuard(); - + LOG("%p", invenW); if (invenW->delete_item(CInventory::INVENTORY_TYPE_ITEM, equipment_pos, 1, 37, 1) && invenW->delete_item(CInventory::INVENTORY_TYPE_ITEM, item_pos, 1, 37, 1)) { int a9 = AccountCargo->InsertItem(&new_equipment_item, empty_slot); @@ -203,7 +209,8 @@ ENUM_PACK_RET_TYPE CDispatch::UseEquipmentMoveItem(CUser* user, PacketBuf* pBuf) packet_guard->finalize(1); user->Send((PacketGuard*)packet_guard); PacketGuard::DelPacketGuard((PacketGuard*)packet_guard); - LOG(u8"user->Send((PacketGuard*)packet_guard)", a9); + SendNoti(user, "已完成装备跨界"); + return PAK_OK; } else @@ -213,6 +220,7 @@ ENUM_PACK_RET_TYPE CDispatch::UseEquipmentMoveItem(CUser* user, PacketBuf* pBuf) packet_guard->finalize(0); user->Send((PacketGuard*)packet_guard); PacketGuard::DelPacketGuard((PacketGuard*)packet_guard); + SendNoti(user, "装备跨界失败"); } return PAK_IGNORE; } @@ -457,7 +465,6 @@ ENUM_PACK_RET_TYPE CDispatch::UseJewel_dispatch_sig(void* pDispatcher_UseJewel, LOG("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); } - LOG("数据已读取!!!\n"); for (auto& avartar_socket_slot : emblems) { @@ -468,7 +475,6 @@ ENUM_PACK_RET_TYPE CDispatch::UseJewel_dispatch_sig(void* pDispatcher_UseJewel, //设置时装插槽数据 int emblem_item_id = avartar_socket_slot.second.second; *(int*)(jewel_socket_data + avartar_socket_slot.first * 6 + 2) = emblem_item_id; - LOG("徽章item_id=%d 已成功镶嵌进avartar_socket_slot=%d 的槽内!\n", emblem_item_id, avartar_socket_slot); } //时装插槽数据存档 @@ -476,7 +482,6 @@ ENUM_PACK_RET_TYPE CDispatch::UseJewel_dispatch_sig(void* pDispatcher_UseJewel, //通知客户端时装数据已更新 user->SendUpdateItemList(1, 1, avartar_inven_slot); - LOG("徽章镶嵌完毕!!!"); //回包给客户端 InterfacePacketBuf* packet_guard = (InterfacePacketBuf*)PacketGuard::NewPacketGuard(); @@ -485,8 +490,74 @@ ENUM_PACK_RET_TYPE CDispatch::UseJewel_dispatch_sig(void* pDispatcher_UseJewel, packet_guard->finalize(1); user->Send((PacketGuard*)packet_guard); PacketGuard::DelPacketGuard((PacketGuard*)packet_guard); + SendNoti(user, u8"已完成徽章镶嵌"); return PAK_OK; } return PAK_IGNORE; } +ENUM_PACK_RET_TYPE CDispatch::MoveMap_dispatch_sig(void* a1, CUser* user, PacketBuf* pBuf) +{ + USER_DATA data; + if (user_map.Find(user, &data)) + { + auto CurTickCount = CSystemTime::G_CSystemTime()->getCurTickCount(); + + if (CurTickCount >= last_move_map_tickcount) + { + if ((CurTickCount - last_move_map_tickcount) <= 1000) + { + data.abnormal_data_count++; + } + last_move_map_tickcount = CurTickCount; + } + + user_map.Change(user, data); + + //判断异常次数是否大于等于3 + if (data.abnormal_data_count >= 3) + { + return PAK_ERROR; + } + } + return PAK_OK; +} + +ENUM_PACK_RET_TYPE CDispatch::Inter_LoadEtc_dispatch_sig(void* a1, CUser* user, char* a3) +{ + user->getCurCharacNo(); + user->getCurCharacName(); + + user_map.Push(user, {}); + return PAK_OK; +} + +ENUM_PACK_RET_TYPE CDispatch::DisPatcher_ReturnToSelectCharacter_dispatch_sig(void* a1, CUser* user, char* a3) +{ + + user_map.Erase(user); + return PAK_OK; +} + +void CDispatch::SendMsg(CUser* user, int pack_id, int status, const std::string& str) +{ + char out_str[0xff] = {}; + memset(out_str, 0, sizeof(out_str)); + DNFFLib::ConvertGBKtoUTF8((char*)str.c_str(), out_str); + InterfacePacketBuf* packet_guard = (InterfacePacketBuf*)PacketGuard::NewPacketGuard(); + packet_guard->put_header(1, pack_id); + packet_guard->put_int(status); + packet_guard->put_int(strlen(out_str)); + packet_guard->put_str(out_str, strlen(out_str)); + user->Send((PacketGuard*)packet_guard); + PacketGuard::DelPacketGuard((PacketGuard*)packet_guard); +} + +void CDispatch::SendNoti(CUser* user, const std::string& str, NOTI_PACKETMESSAGE_TYPE type) +{ + char out_str[0xff] = {}; + memset(out_str, 0, sizeof(out_str)); + DNFFLib::ConvertGBKtoUTF8((char*)str.c_str(), out_str); + user->SendNotiPacketMessage(out_str, type); +} + diff --git a/src/dispatch.h b/src/dispatch.h index ecfe1ea..8f52e47 100644 --- a/src/dispatch.h +++ b/src/dispatch.h @@ -7,6 +7,18 @@ #include "./sdk/sdk_class.h" #include "utils.h" +enum NOTI_PACKETMESSAGE_TYPE : int +{ + NOTI_SYSTEM = 0, + +}; + +struct USER_DATA +{ + int abnormal_data_count; //异常数据计次 要使用map进行用户数据存储 + +}; + class CDispatch { public: @@ -15,17 +27,27 @@ public: ~CDispatch(); public: ENUM_PACK_RET_TYPE UseEquipmentMoveItem(CUser* user, PacketBuf* pBuf); - + ENUM_PACK_RET_TYPE Dispatcher_ModItemAttr_dispatch_sig(Dispatcher_ModItemAttr* dis_mod, CUser* user, PacketBuf* pBuf); ENUM_PACK_RET_TYPE UseJewel_dispatch_sig(void* pDispatcher_UseJewel, CUser* user, PacketBuf* pBuf); + ENUM_PACK_RET_TYPE MoveMap_dispatch_sig(void* a1, CUser* user, PacketBuf* pBuf); + ENUM_PACK_RET_TYPE Inter_LoadEtc_dispatch_sig(void* a1, CUser* user, char* a3); + + ENUM_PACK_RET_TYPE DisPatcher_ReturnToSelectCharacter_dispatch_sig(void* a1, CUser* user, char* a3); + + + void SendMsg(CUser* user, int pack_id, int status, const std::string& str); + + void SendNoti(CUser* user, const std::string& str, NOTI_PACKETMESSAGE_TYPE type = NOTI_SYSTEM); protected: - -private: +private: + int last_move_map_tickcount; + Utils::TMap user_map; }; diff --git a/src/sdk/PacketBuf.h b/src/sdk/PacketBuf.h index 9345073..9222580 100644 --- a/src/sdk/PacketBuf.h +++ b/src/sdk/PacketBuf.h @@ -247,57 +247,141 @@ public: }; - - -class InterfacePacketBuf +class InterfacePacketBuf :public PacketBuf { public: - int put_header(int a2, int a3) + + InterfacePacketBuf() { - typedef int (*__func)(InterfacePacketBuf* a1, int a2, int a3); - return ((__func)base::InterfacePacketBuf::put_header)(this, a2, a3); + CallT(base::InterfacePacketBuf::InterfacePacketBuf_make, this); } - int put_byte(char a2) + ~InterfacePacketBuf() { - typedef int (*__func)(InterfacePacketBuf* a1, char a2); - return ((__func)base::InterfacePacketBuf::put_byte)(this, a2); - } - int put_short(short a2) - { - typedef int (*__func)(InterfacePacketBuf* a1, short a2); - return ((__func)base::InterfacePacketBuf::put_short)(this, a2); + CallT(base::InterfacePacketBuf::InterfacePacketBuf_destroy, this); } - int put_int(int a2) + int AcquirePacketBuf(PacketBuf* a2) { - typedef int (*__func)(InterfacePacketBuf* a1, int a2); - return ((__func)base::InterfacePacketBuf::put_int)(this, a2); + return CallT(base::InterfacePacketBuf::AcquirePacketBuf, this, a2); } - int put_binary(char* a2, int a3) + int bind_packet(char* a2, int a3) { - typedef int (*__func)(InterfacePacketBuf* a1, char* a2, int a3); - return ((__func)base::InterfacePacketBuf::put_binary)(this, a2, a3); + return CallT(base::InterfacePacketBuf::bind_packet, this, a2, a3); + } + + int clear() + { + return CallT(base::InterfacePacketBuf::clear, this); } int finalize(bool a2) { - typedef int (*__func)(InterfacePacketBuf* a1, bool a2); - return ((__func)base::InterfacePacketBuf::finalize)(this, a2); + return CallT(base::InterfacePacketBuf::finalize, this, a2); } - int put_str(const char* a2, int a3) + int get() { - typedef int (*__func)(InterfacePacketBuf* a1, const char* a2, int a3); - return ((__func)base::InterfacePacketBuf::put_str)(this, a2, a3); + return CallT(base::InterfacePacketBuf::get, this); } - int put_packet(const Inven_Item* a2) + int getLastError() { - typedef int (*__func)(InterfacePacketBuf* a1, const Inven_Item* a2); - return ((__func)base::InterfacePacketBuf::put_packet)(this, a2); + return CallT(base::InterfacePacketBuf::getLastError, this); } + + int get_binary(char* a2, int a3) + { + return CallT(base::InterfacePacketBuf::get_binary, this, a2, a3); + } + + int get_index() + { + return CallT(base::InterfacePacketBuf::get_index, this); + } + + int get_int(int* a2) + { + return CallT(base::InterfacePacketBuf::get_int, this, a2); + } + + int get_len() + { + return CallT(base::InterfacePacketBuf::get_len, this); + } + + int get_packet(int a2) + { + return CallT(base::InterfacePacketBuf::get_packet, this, a2); + } + + int get_short(short* a2) + { + return CallT(base::InterfacePacketBuf::get_short, this, a2); + } + + int is_finallized() + { + return CallT(base::InterfacePacketBuf::is_finallized, this); + } + + int put_binary(char* a2, int a3) + { + return CallT(base::InterfacePacketBuf::put_binary, this, a2, a3); + } + + int put_binary_c(char const* a2, int a3) + { + return CallT(base::InterfacePacketBuf::put_binary_c, this, a2, a3); + } + + int put_byte(int a2) + { + return CallT(base::InterfacePacketBuf::put_byte, this, a2); + } + + int put_header(int a2, int a3) + { + return CallT(base::InterfacePacketBuf::put_header, this, a2, a3); + } + + int put_int(int a2) + { + return CallT(base::InterfacePacketBuf::put_int, this, a2); + } + + int put_item_idx(ulong a2) + { + return CallT(base::InterfacePacketBuf::put_item_idx, this, a2); + } + + int put_packet(Inven_Item const& a2) + { + return CallT(base::InterfacePacketBuf::put_packet, this, a2); + } + + int put_short(int a2) + { + return CallT(base::InterfacePacketBuf::put_short, this, a2); + } + + int put_str(char* a2, int a3) + { + return CallT(base::InterfacePacketBuf::put_str, this, a2, a3); + } + + int put_str_c(char const* a2, int a3) + { + return CallT(base::InterfacePacketBuf::put_str_c, this, a2, a3); + } + + int set_index(int a2) + { + return CallT(base::InterfacePacketBuf::set_index, this, a2); + } + + }; class PacketGuard diff --git a/src/sdk/SystemTime.h b/src/sdk/SystemTime.h new file mode 100644 index 0000000..7e7ad53 --- /dev/null +++ b/src/sdk/SystemTime.h @@ -0,0 +1,50 @@ +#pragma once +#ifndef __SYSTEMTIME_H__ +#define __SYSTEMTIME_H__ + +#pragma pack(push, 0x01) + +class CSystemTime +{ +public: + static CSystemTime* G_CSystemTime(void) + { + return *(CSystemTime**)base::CSystemTime::s_systemTime_; + } + + CSystemTime() + { + CallT(base::CSystemTime::CSystemTime_make, this); + } + + ~CSystemTime() + { + CallT(base::CSystemTime::CSystemTime_destroy, this); + } + + int getCurSec() + { + return CallT(base::CSystemTime::getCurSec, this); + } + + int getCurTickCount() + { + return CallT(base::CSystemTime::getCurTickCount, this); + } + + int getCurDate() + { + return CallT(base::CSystemTime::getCurDate, this); + } + + int update() + { + return CallT(base::CSystemTime::update, this); + } + +}; + +#pragma pack(pop) + +#endif // __SYSTEMTIME_H__ + diff --git a/src/sdk/base.h b/src/sdk/base.h index c7d48b5..18e3941 100644 --- a/src/sdk/base.h +++ b/src/sdk/base.h @@ -2,11 +2,29 @@ namespace base { + namespace DNFFLib + { + const int ConvertGBKtoUTF8 = 0x08108D0E; + const int ConvertUTF8toGBK = 0x08108D4B; + + } + namespace CGameManager { const int G_CGameManager = 0x080CC18E; } + namespace CSystemTime + { + const int s_systemTime_ = 0x0941F714; + const int getCurSec = 0x080CBC9E; + const int getCurTickCount = 0x081458AC; + const int getCurDate = 0x0823445E; + const int update = 0x082A68C8; + const int CSystemTime_make = 0x082A6936; + const int CSystemTime_destroy = 0x082A6986; + } + namespace Dispatcher_UseJewel { const int dispatch_sig = 0x8217BD6; @@ -14,6 +32,22 @@ namespace base } + namespace DisPatcher_MoveMap + { + const int process = 0x081C5330; + const int dispatch_sig = 0x082595B2; + } + + namespace Inter_LoadEtc + { + const int dispatch_sig = 0x084C0264; + } + + namespace DisPatcher_ReturnToSelectCharacter + { + const int dispatch_sig = 0x081FD25C; + } + namespace GlobalData { const int Init = 0x08299FA0; @@ -213,14 +247,33 @@ namespace base namespace InterfacePacketBuf { - const int put_header = 0x080CB8FC; + const int AcquirePacketBuf = 0x0858E2A0; + const int InterfacePacketBuf_make = 0x0858E294; + const int bind_packet = 0x0848F39C; + const int clear = 0x080CB8E6; + const int finalize = 0x080CB958; + const int get = 0x0822B766; + const int getLastError = 0x086D18EE; + const int get_binary = 0x0848F3F8; + const int get_index = 0x08110B4C; + const int get_int = 0x0848F3DC; + const int get_len = 0x0848F438; + const int get_packet = 0x0848F41C; + const int get_short = 0x0848F3C0; + const int is_finallized = 0x0848F44E; + const int put_binary = 0x0811DF08; + const int put_binary_c = 0x0815096A; const int put_byte = 0x080CB920; - const int put_short = 0x80D9EA4; - const int put_int = 0x80CB93C; - const int put_binary = 0x811DF08; - const int finalize = 0x80CB958; - const int put_str = 0x0822B770; - const int put_packet = 0x0822B794; + const int put_header = 0x080CB8FC; + const int put_int = 0x080CB93C; + const int put_item_idx = 0x0822B794; + const int put_packet = 0x0815098E; + const int put_short = 0x080D9EA4; + const int put_str = 0x081B73E4; + const int put_str_c = 0x0822B770; + const int set_index = 0x0822B7B0; + const int InterfacePacketBuf_destroy = 0x0858E29A; + } namespace PacketGuard diff --git a/src/sdk/sdk_class.h b/src/sdk/sdk_class.h index b91de0b..b02b253 100644 --- a/src/sdk/sdk_class.h +++ b/src/sdk/sdk_class.h @@ -42,6 +42,22 @@ class Dispatcher_ModItemAttr; #pragma pack(push, 0x01) +class DNFFLib +{ +public: + static int ConvertGBKtoUTF8(char* a2, char* a3) + { + return CallT(base::DNFFLib::ConvertGBKtoUTF8, a2, a3); + } + + static int ConvertUTF8toGBK(char* a2, char* a3) + { + return CallT(base::DNFFLib::ConvertUTF8toGBK, a2, a3); + } + + +}; + namespace WongWork { @@ -115,6 +131,7 @@ public: #include "DataManager.h" #include "Inventory.h" #include "PacketBuf.h" +#include "SystemTime.h" #endif // __DXFBASE_H__ diff --git a/src/utils.h b/src/utils.h index 7374b7b..0968362 100644 --- a/src/utils.h +++ b/src/utils.h @@ -2,14 +2,214 @@ #define utils_h__ #include #include +#include #include #define BUFFCOUNT (3196) #define SET_TEXTW(X) L#X #define SET_TEXTA(X) #X - namespace Utils { + + + class NLock + { + public: + typedef pthread_mutex_t OSLockType; + + NLock() + { + pthread_mutex_init(&os_lock_, NULL); + } + + ~NLock() + { + pthread_mutex_destroy(&os_lock_); + } + + // If the lock is not held, take it and return true. If the lock is already + // held by something else, immediately return false. + bool Try() + { + int rv = pthread_mutex_trylock(&os_lock_); + return rv == 0; + } + + // Take the lock, blocking until it is available if necessary. + void Lock() + { + pthread_mutex_lock(&os_lock_); + } + + // Release the lock. This must only be called by the lock's holder: after + // a successful call to Try, or a call to Lock. + void Unlock() + { + pthread_mutex_unlock(&os_lock_); + } + + // Return the native underlying lock. Not supported for Windows builds. + OSLockType* os_lock() { return &os_lock_; } + + private: + OSLockType os_lock_; + }; + + class NAutoLock + { + public: + NAutoLock(NLock* lock) + { + lock_ = lock; + lock_->Lock(); + } + + ~NAutoLock() + { + if (lock_) + lock_->Unlock(); + } + + private: + NLock* lock_; + }; + + class NAutoUnlock + { + public: + NAutoUnlock(NLock* lock) + { + lock_ = lock; + lock_->Unlock(); + } + + ~NAutoUnlock() + { + if (lock_) + lock_->Lock(); + } + + private: + NLock* lock_; + }; + + + template > + class TMap + { + public: + /** + * @brief 淇濆瓨 + * @param key + * @param data + * @return + */ + bool Push(V1 key, V2 data) + { + NAutoLock auto_lock(&Lock); + auto itrM = Map.find(key); + if (itrM != Map.end()) + { + return false; + } + Map.insert(std::make_pair(key, data)); + return true; + } + + /** + * @brief 鍒犻櫎 + * @param key + * @return + */ + bool Erase(V1 key) + { + NAutoLock auto_lock(&Lock); + auto itrM = Map.find(key); + if (itrM != Map.end()) + { + Map.erase(key); + return true; + } + return false; + } + + /** + * @brief 娓呯┖ + */ + void Clear() + { + NAutoLock auto_lock(&Lock); + Map.clear(); + } + + /** + * @brief 澶у皬 + * @return + */ + size_t Size() + { + return Map.size(); + } + + /** + * @brief 杩唬鍣ㄥご + * @return + */ + typename std::map::iterator Begin() + { + return Map.begin(); + } + + /** + * @brief 杩唬鍣ㄥ熬 + * @return + */ + typename std::map::iterator End() + { + return Map.end(); + } + + /** + * @brief 鏌ユ壘鏁版嵁 + * @param key + * @param data + * @return + */ + bool Find(V1 key, V2* data = NULL) + { + NAutoLock auto_lock(&Lock); + auto itr = Map.find(key); + if (itr != Map.end()) + { + if (data) + { + *data = itr->second; + } + return true; + } + return false; + } + + /** + * @brief 鏇存敼鏁版嵁 + * @param key + * @param data + * @return + */ + bool Change(V1 key, V2 data) + { + NAutoLock auto_lock(&Lock); + auto itr = Map.find(key); + if (itr != Map.end()) + { + itr->second = data; + return true; + } + return false; + } + std::mapMap; + NLock Lock; + }; /** * @brief 鍒16杩涘埗Hex鏂囨湰 * @param buf @@ -49,7 +249,6 @@ namespace Utils } - #define LOG(format,...) Utils::_Log(format,##__VA_ARGS__)