本次我们将对上次找到的物品商店进行遍历,然后实现物品购买功能
具体代码如下:
#define nSizeGoodsList 60
typedef struct TGoodsShopList
{
TBACK_PACK_OBJ mtGoodlist[nSizeGoodsList];
TGoodsShopList* TGoodsShopList::GetData(); //初始化函数
void TGoodsShopList::DbgPrintGoodsList();
BOOL TGoodsShopList::BuyGoodsByName(char * szpName, DWORD ndNum);
}_TGoodsShopList;
#pragma pack(1)
#define ndBuyType 1
#define ndSelType 2
typedef struct _tBuyGoodsData{
BYTE nd111[2];
DWORD ndSendCmdType;
DWORD ndBuySelType;
DWORD nd1111;
DWORD ndGoodsType;
DWORD nd2222;
DWORD ndNum;
BYTE nb[0x80];
}_tBuyGoodsData;
#pragma pack()
//背包结构定义
typedef struct TBACK_PACK_OBJ{
char* szpGoodName; //+5C
char* szpGoodMsg; //+F1
DWORD ndGoodNum;//+c44
DWORD ndID1;// +4c
QWORD ndID2; //+54
BYTE ndIndexForPack; //+1f4
}_TBACK_PACK_OBJ;
TGoodsShopList* TGoodsShopList::GetData() //初始化函数
{
DWORD ndObj = NULL;
DWORD ndBase = NULL;
memset(this, 0, sizeof(TGoodsShopList));
__try{
ndObj = *(DWORD*)( *(DWORD*)(Base_GoodsShopAddr + 0x2e0 * 4 + 0x4) + 0x4);
for (int i = 0; i < 60; i++){
ndBase = *(DWORD*)(ndObj + 0x410 + 4 * i);
//DbgPrintf_Mine("%X", ndBase);
if (ndBase == NULL){
mtGoodlist[i].szpGoodName = NULL;
continue;
}
mtGoodlist[i].szpGoodName = (char*)(ndBase + 0x5c);
mtGoodlist[i].ndIndexForPack = *(BYTE*)(ndBase + 0x1f4);
mtGoodlist[i].ndID1 = *(DWORD*)(ndBase + 0x4c);
}
}
__except (1){
DbgPrintf_Mine("TGoodsShopList* TGoodsShopList::GetData() //初始化函数 出现异常");
}
return this;
}
void TGoodsShopList::DbgPrintGoodsList(){
for (int i = 0; i < 60; i++){
if (mtGoodlist[i].szpGoodName == NULL){
//DbgPrintf_Mine("%d", i);
continue;
}
DbgPrintf_Mine("商店物品名字: %s 物品类型 %X 物品下表%d",
mtGoodlist[i].szpGoodName,
mtGoodlist[i].ndID1,
mtGoodlist[i].ndIndexForPack);
}
}
BOOL TGoodsShopList::BuyGoodsByName(char * szpName, DWORD ndNum){
__try{
for (int i = 0; i < nSizeGoodsList; i++){
if (strcmp(szpName, mtGoodlist[i].szpGoodName) == 0){
_tBuyGoodsData tBuygoodList = { 0 };
tBuygoodList.ndSendCmdType = 0x00800092;
tBuygoodList.ndBuySelType = ndBuyType;
tBuygoodList.ndGoodsType = mtGoodlist[i].ndID1;
tBuygoodList.ndNum = ndNum;
__asm{
lea ecx, tBuygoodList
push 0x86
push ecx
MOV ECX, DWORD PTR DS : [Base_CallSendDataEcx]
mov eax, Base_CallSendDataCALL
CALL eax
}
return TRUE;
}
}
}
__except (1){
DbgPrintf_Mine("BOOL TGoodsShopList::BuyGoodsByName(char * szpName, DWORD ndNum) 出现异常");
return FALSE;
}
return FALSE;
}