diff --git a/src/GameDataManager.h b/src/GameDataManager.h index 08548c6..b200b8d 100644 --- a/src/GameDataManager.h +++ b/src/GameDataManager.h @@ -2,78 +2,88 @@ #ifndef __GAMEDATAMANAGER_H__ #define __GAMEDATAMANAGER_H__ -struct AWARD_ITEM +struct CeraShopBonusCodeType { + int code_min; + int code_max; + int code_count; +}; + +struct CeraShopBonusItemType +{ + int item_id; int item_num; + bool is_random; }; + class CGameDataManager { public: SINGLETON_DEFINE_S(CGameDataManager); - CGameDataManager() : - cera_award_begin_id(0), - cera_award_end_id(0) + CGameDataManager() { - + cera_shop_bonus_code_array.clear(); + cera_shop_bonus_item_map.Clear(); } ~CGameDataManager() {}; public: - void set_cera_award_begin_id(int id) + + bool is_cera_shop_bonus_code(int code_id, CeraShopBonusCodeType* res = NULL) { - cera_award_begin_id = id; - } - void set_cera_award_end_id(int id) - { - cera_award_end_id = id; - } - int get_cera_award_begin_id() - { - return cera_award_begin_id; - } - int get_cera_award_end_id() - { - return cera_award_end_id; - } - bool add_cera_awarw_item(int count_, int item_id, int item_num) - { - cera_award_item.Push(count_, { item_id ,item_num }); + for (size_t i = 0; i < cera_shop_bonus_code_array.size(); i++) + { + CeraShopBonusCodeType cera_shop_bonus_code_ = cera_shop_bonus_code_array.at(i); + if (code_id >= cera_shop_bonus_code_.code_min && code_id <= cera_shop_bonus_code_.code_max) + { + if (res != NULL) *res = cera_shop_bonus_code_; + return true; + } + } + return false; } - Utils::TMap* get_cera_award_item_map() + bool get_rand_cera_shop_bonus_item(CeraShopBonusItemType* res = NULL) { - return &cera_award_item; + int size = get_random_item_num(); + for (int i = 0; i < size; i++) + { + int random_value = Utils::Rand(1, size - 1); + CeraShopBonusItemType cera_shop_bonusi_temt = cera_shop_bonus_item_map_rand.Map.at(random_value); + if (cera_shop_bonusi_temt.is_random == true) + { + if (res != NULL) *res = cera_shop_bonusi_temt; + return true; + } + } + return false; } - - - void set_cera_award_package_begin_id(int id) + int get_random_item_num() { - cera_award_package_begin_id = id; - } - void set_cera_award_package_end_id(int id) - { - cera_award_package_end_id = id; - } - int get_cera_award_package_begin_id() - { - return cera_award_package_begin_id; - } - int get_cera_award_package_end_id() - { - return cera_award_package_end_id; + return cera_shop_bonus_item_map_rand.Size(); } - bool add_cera_award_package_item(int count_, int item_id, int item_num) + bool add_cera_shop_bonus_item(int count_, int item_id, int item_num, bool is_random) { - cera_award_package_item.Push(count_, { item_id ,item_num }); + cera_shop_bonus_item_map.Push(count_, { item_id ,item_num ,is_random }); } - Utils::TMap* get_cera_award_package_item_map() + Utils::TMap* get_cera_shop_bonus_item_map() { - return &cera_award_package_item; + return &cera_shop_bonus_item_map; + } + + std::vector* get_cera_shop_bonus_code_array() + { + return &cera_shop_bonus_code_array; + } + + Utils::TMap* get_cera_shop_bonus_item_map_rand() + { + return &cera_shop_bonus_item_map_rand; } @@ -81,13 +91,11 @@ protected: private: - int cera_award_begin_id; //商城奖励开始id - int cera_award_end_id; //商城奖励结束id - int cera_award_package_begin_id; //商城礼包奖励开始id - int cera_award_package_end_id; //商城礼包奖励结束id - Utils::TMap cera_award_item; // 次数 + 数据 - Utils::TMap cera_award_package_item; // 次数 + 数据 + std::vector cera_shop_bonus_code_array; + + Utils::TMap cera_shop_bonus_item_map; // 次数 + 数据 + Utils::TMap cera_shop_bonus_item_map_rand; // 次数 + 数据 }; diff --git a/src/controller.cpp b/src/controller.cpp index 0028880..7beb0f6 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -106,6 +106,8 @@ void Controller::init() HOOK_SETUP(DisPatcher_ReturnToSelectCharacter_dispatch_sig); + HOOK_SETUP(Init); + LOG("Controller::init()"); } @@ -230,7 +232,7 @@ int Controller::hook_DisPatcher_MoveMap_dispatch_sig(void* a1, CUser* pUser, Pac { //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); + return Get()->old_DisPatcher_MoveMap_dispatch_sig(a1, pUser, pBuf); } int Controller::hook_Inter_LoadEtc_dispatch_sig(void* a1, CUser* pUser, char* a3) @@ -247,46 +249,8 @@ int Controller::hook_DisPatcher_ReturnToSelectCharacter_dispatch_sig(void* a1, C void Controller::hook_importCashShopItemList(const std::string* str) { - if (str == NULL) return; - if (*str == "[start end id]") - { - int item_id_begin_ = ScanInt(); - int item_id_end_ = ScanInt(); - - CGameDataManager::Get()->set_cera_award_begin_id(item_id_begin_); - CGameDataManager::Get()->set_cera_award_end_id(item_id_end_); - } - else if (*str == "[reward item]") - { - int _total = ScanInt(); - for (int i = 0; i < _total; i++) - { - int count_ = ScanInt(); - int item_id = ScanInt(); - int item_num = ScanInt(); - CGameDataManager::Get()->add_cera_awarw_item(count_, item_id, item_num); - } - } - else if (*str == "[start end package]") - { - int item_id_begin_ = ScanInt(); - int item_id_end_ = ScanInt(); - - CGameDataManager::Get()->set_cera_award_package_begin_id(item_id_begin_); - CGameDataManager::Get()->set_cera_award_package_end_id(item_id_end_); - } - else if (*str == "[package item]") - { - int _total = ScanInt(); - for (int i = 0; i < _total; i++) - { - int count_ = ScanInt(); - int item_id = ScanInt(); - int item_num = ScanInt(); - CGameDataManager::Get()->add_cera_award_package_item(count_, item_id, item_num); - } - } - + 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) @@ -299,3 +263,13 @@ int Controller::hook_Dispatcher_BuyCeraShopItem_dispatch_sig(void* a1, CUser* pU return 0; } +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); + } + return result; +} + diff --git a/src/controller.h b/src/controller.h index 84b2f1c..90bf33b 100644 --- a/src/controller.h +++ b/src/controller.h @@ -69,6 +69,9 @@ private: static void hook_ProcessIPG_ResultOutput(CUser* user, int Goods_No, int item_id, int Cera_Type, InterfacePacketBuf* pbuf); static int hook_Dispatcher_BuyCeraShopItem_dispatch_sig(void* a1, CUser* pUser, PacketBuf* pBuf); + + static bool hook_Init(int a1, char** a2); + private: INIT_HOOK(IPacketDispatcher_ParamBase_dispatch_template, base::IPacketDispatcher::ParamBase::dispatch_template); @@ -78,6 +81,7 @@ private: 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); + INIT_HOOK(Init, base::Init); private: diff --git a/src/dispatch.cpp b/src/dispatch.cpp index 4255b58..fcdb09f 100644 --- a/src/dispatch.cpp +++ b/src/dispatch.cpp @@ -470,7 +470,7 @@ ENUM_PACK_RET_TYPE CDispatch::UseJewel_dispatch_sig(void* pDispatcher_UseJewel, sizeof(stAvatarEmblemInfo_t); - + int avartar_socket_type = JewelSocketData->EmblemSocketData[avartar_socket_slot].slot_type; LOG("emblem_socket_type :%d avartar_socket_type :%d", emblem_socket_type, avartar_socket_type); @@ -561,133 +561,86 @@ ENUM_PACK_RET_TYPE CDispatch::ProcessIPG_ResultOutput(CUser* user, int Goods_No, if (Cera_Type == 0) //0是点券 1是代币 { - if (Goods_No >= CGameDataManager::Get()->get_cera_award_begin_id() && Goods_No <= CGameDataManager::Get()->get_cera_award_end_id()) + CeraShopBonusCodeType cera_shop_bonus_code_; + if (CGameDataManager::Get()->is_cera_shop_bonus_code(Goods_No, &cera_shop_bonus_code_)) { - int cur_purchase_count = 1; - AWARD_ITEM BonusItem; - - LOG("Size:%d", CGameDataManager::Get()->get_cera_award_item_map()->Size()); - if (CGameDataManager::Get()->get_cera_award_item_map()->Find(cur_purchase_count, &BonusItem)) + CeraShopBonusItemType BonusItem; + int cur_purchase_count = cera_shop_bonus_code_.code_count; + if (cur_purchase_count > 0) { - if (user->getCurCharacR()) + if (!CGameDataManager::Get()->get_cera_shop_bonus_item_map()->Find(cur_purchase_count, &BonusItem)) { - if (BonusItem.item_id == 1) - { - WongWork::CCeraShop::G_CCeraShop()->_processCoin(user, BonusItem.item_num, 0); - } - else - { - auto item = CDataManager::G_CDataManager()->find_item(BonusItem.item_id); - if (item) - { - //if (item->is_stackable() - // && ((*(int(**)(CItem*))(*(_DWORD*)item + 12))(item) == 16 // GetItemType - // || (*(int(**)(CItem*))(*(_DWORD*)item + 12))(item) == 34)) // GetItemType - { - int inserted = -1; - Inven_Item v60 = {}; - *(_DWORD*)((char*)&v60 + 2) = BonusItem.item_id; - *(_DWORD*)((char*)&v60 + 7) = BonusItem.item_num; - - (*(void(**)(CItem*, Inven_Item*))(*(_DWORD*)item + 8))(item, &v60); - - auto CurCharacInvenW = user->getCurCharacInvenW(); - - inserted = CurCharacInvenW->insertItemIntoInventory(v60, 15, 1, 0); - if (inserted == -1) - { - auto CurCharacNo = user->getCurCharacNo(); - - ((WongWork::CMailBoxHelper*)(user))->ReqDBSendNewMailCashShop(&v60, 0, CurCharacNo, 1, 0, 0); - - } - else - { - user->SendUpdateItemList(1, 0, inserted); - } - } - - } - } + goto IPG_END; } - - pbuf->put_int(BonusItem.item_id); - pbuf->put_int(BonusItem.item_num); - - std::vector code; - for (int i = 0; i < 0x30; i++) - { - code.push_back(0x90); - } - //0817964F 0817967F - CMem::WriteBytes((void*)0x0817964F, code.data(), code.size()); - return; } - } - else if (Goods_No >= CGameDataManager::Get()->get_cera_award_package_begin_id() && Goods_No <= CGameDataManager::Get()->get_cera_award_package_end_id()) - { - int cur_purchase_count = 1; - AWARD_ITEM BonusItem; - LOG("Size:%d", CGameDataManager::Get()->get_cera_award_package_item_map()->Size()); - if (CGameDataManager::Get()->get_cera_award_package_item_map()->Find(cur_purchase_count, &BonusItem)) + else { - if (user->getCurCharacR()) + if (!CGameDataManager::Get()->get_rand_cera_shop_bonus_item(&BonusItem)) { - if (BonusItem.item_id == 1) - { - WongWork::CCeraShop::G_CCeraShop()->_processCoin(user, BonusItem.item_num, 0); - } - else - { - auto item = CDataManager::G_CDataManager()->find_item(BonusItem.item_id); - if (item) - { - //if (item->is_stackable() - // && ((*(int(**)(CItem*))(*(_DWORD*)item + 12))(item) == 16 // GetItemType - // || (*(int(**)(CItem*))(*(_DWORD*)item + 12))(item) == 34)) // GetItemType - { - int inserted = -1; - Inven_Item v60 = {}; - *(_DWORD*)((char*)&v60 + 2) = BonusItem.item_id; - *(_DWORD*)((char*)&v60 + 7) = BonusItem.item_num; - - (*(void(**)(CItem*, Inven_Item*))(*(_DWORD*)item + 8))(item, &v60); - - auto CurCharacInvenW = user->getCurCharacInvenW(); - - inserted = CurCharacInvenW->insertItemIntoInventory(v60, 15, 1, 0); - if (inserted == -1) - { - auto CurCharacNo = user->getCurCharacNo(); - - ((WongWork::CMailBoxHelper*)(user))->ReqDBSendNewMailCashShop(&v60, 0, CurCharacNo, 1, 0, 0); - - } - else - { - user->SendUpdateItemList(1, 0, inserted); - } - } - - } - } + goto IPG_END; } - - pbuf->put_int(BonusItem.item_id); - pbuf->put_int(BonusItem.item_num); - - std::vector code; - for (int i = 0; i < 0x30; i++) - { - code.push_back(0x90); - } - //0817964F 0817967F - CMem::WriteBytes((void*)0x0817964F, code.data(), code.size()); - return; } + + if (user->getCurCharacR()) + { + if (BonusItem.item_num == 0) + { + goto IPG_END; + } + else if (BonusItem.item_id == 1) + { + WongWork::CCeraShop::G_CCeraShop()->_processCoin(user, BonusItem.item_num, 0); + } + else + { + auto item = CDataManager::G_CDataManager()->find_item(BonusItem.item_id); + if (item) + { + //if (item->is_stackable() + // && ((*(int(**)(CItem*))(*(_DWORD*)item + 12))(item) == 16 // GetItemType + // || (*(int(**)(CItem*))(*(_DWORD*)item + 12))(item) == 34)) // GetItemType + { + int inserted = -1; + Inven_Item v60 = {}; + *(_DWORD*)((char*)&v60 + 2) = BonusItem.item_id; + *(_DWORD*)((char*)&v60 + 7) = BonusItem.item_num; + + (*(void(**)(CItem*, Inven_Item*))(*(_DWORD*)item + 8))(item, &v60); + + auto CurCharacInvenW = user->getCurCharacInvenW(); + + inserted = CurCharacInvenW->insertItemIntoInventory(v60, 15, 1, 0); + if (inserted == -1) + { + auto CurCharacNo = user->getCurCharacNo(); + + ((WongWork::CMailBoxHelper*)(user))->ReqDBSendNewMailCashShop(&v60, 0, CurCharacNo, 1, 0, 0); + + } + else + { + user->SendUpdateItemList(1, 0, inserted); + } + } + + } + } + } + + pbuf->put_int(BonusItem.item_id); + pbuf->put_int(BonusItem.item_num); + + std::vector code; + for (int i = 0; i < 0x30; i++) + { + code.push_back(0x90); + } + //0817964F 0817967F + CMem::WriteBytes((void*)0x0817964F, code.data(), code.size()); + return PAK_OK; } } - +IPG_END: std::vector code = { 0x8B, 0x85, 0x04, 0xFF, 0xFF, 0xFF, 0x89, 0x44, 0x24, 0x04, 0x8D, 0x85, 0x14, 0xFF, 0xFF, 0xFF, 0x89, 0x04, 0x24, 0xE8, 0xD5, 0x22, 0xF5, 0xFF, 0x8B, 0x85, 0x00, 0xFF, 0xFF, 0xFF, 0x89, 0x44, @@ -697,6 +650,62 @@ ENUM_PACK_RET_TYPE CDispatch::ProcessIPG_ResultOutput(CUser* user, int Goods_No, return PAK_OK; } +ENUM_PACK_RET_TYPE CDispatch::Init_done(int argc, const char** argv) +{ + + + return PAK_OK; +} + +ENUM_PACK_RET_TYPE CDispatch::importCashShopItemList(const std::string* str) +{ + /** + + [cash_shop_bonus_code] + 3 + 10000 10053 0 0 随机获取一个发送 + 10054 10110 1 1 发第一个 + 100178 100180 3 3 发第三个 + + [cash_shop_bonus_item] + 3 + 1 3037 10 + 2 3037 100 + 3 3037 1000 + + */ + if (*str == "[cash_shop_bonus_code]") + { + int _total = ScanInt(); + + for (int i = 0; i < _total; i++) + { + CeraShopBonusCodeType cera_shop_bonus_ = {}; + cera_shop_bonus_.code_min = ScanInt(); + cera_shop_bonus_.code_max = ScanInt(); + cera_shop_bonus_.code_count = ScanInt(); + CGameDataManager::Get()->get_cera_shop_bonus_code_array()->push_back(cera_shop_bonus_); + } + } + else if (*str == "[cash_shop_bonus_item]") + { + int _total = ScanInt(); + for (int i = 0; i < _total; i++) + { + int index_ = ScanInt(); + int item_id = ScanInt(); + int item_num = ScanInt(); + int is_random = ScanInt(); + if (is_random == 1) + { + CGameDataManager::Get()->get_cera_shop_bonus_item_map_rand()->Push(index_, { item_id, item_num, true }); + } + CGameDataManager::Get()->add_cera_shop_bonus_item(index_, item_id, item_num, is_random); + } + } + return PAK_OK; +} + void CDispatch::SendMsg(CUser* user, int pack_id, int status, const std::string& str) { char out_str[0xff] = {}; diff --git a/src/dispatch.h b/src/dispatch.h index 4324a13..ea0b46a 100644 --- a/src/dispatch.h +++ b/src/dispatch.h @@ -41,6 +41,10 @@ public: ENUM_PACK_RET_TYPE ProcessIPG_ResultOutput(CUser* user, int Goods_No, int item_id, int Cera_Type, InterfacePacketBuf* pbuf); + ENUM_PACK_RET_TYPE Init_done(int argc, const char** argv); + + ENUM_PACK_RET_TYPE importCashShopItemList(const std::string* str); + 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); diff --git a/src/sdk/MySQL.h b/src/sdk/MySQL.h index b5a326a..beeb051 100644 --- a/src/sdk/MySQL.h +++ b/src/sdk/MySQL.h @@ -277,7 +277,7 @@ public: int open(char* a2, uint a3, char* a4, char* a5, char* a6) { - return CallT(base::MySQL::open, this, a2, a3, a4, a5, a6); + return CallT(base::MySQL::open2, this, a2, a3, a4, a5, a6); } int ping() diff --git a/src/sdk/ShutdowManager.h b/src/sdk/ShutdowManager.h index c8f7d78..cdf0150 100644 --- a/src/sdk/ShutdowManager.h +++ b/src/sdk/ShutdowManager.h @@ -52,6 +52,7 @@ public: return CallT(base::CShutdowManager::SendLastMsgDBQueue, this, a2); } + //发送关机信号 int SendShutdownSignal() { return CallT(base::CShutdowManager::SendShutdownSignal, this); diff --git a/src/sdk/base.h b/src/sdk/base.h index 215837c..40f8f31 100644 --- a/src/sdk/base.h +++ b/src/sdk/base.h @@ -451,7 +451,7 @@ namespace base const int is_valid_col = 0x080E22D0; const int is_valid_data = 0x085F41B2; const int open = 0x083F3E9E; - const int open = 0x083F4024; + const int open2 = 0x083F4024; const int ping = 0x083F4514; const int select = 0x083F4678; const int select2 = 0x083F4630; diff --git a/src/utils.h b/src/utils.h index 1ecf199..4b72bc2 100644 --- a/src/utils.h +++ b/src/utils.h @@ -11,6 +11,15 @@ namespace Utils { + static int Rand(int v_min, int v_max) + { + int rNum = 0; + srand((unsigned int)time(0)); + for (int i = 0; i < 31; i++) + rNum |= (rand() & 1) << i; + return v_min + rNum % (v_max - v_min + 1); + } + static void* alloc(size_t len) { int fd = open("/dev/zero", O_RDONLY);