追逐自己的梦想----------辅助制作第三十七课:物品购买实现

本次我们将对上次找到的物品商店进行遍历,然后实现物品购买功能

具体代码如下:

#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;
}



具体代码实现就是上面那样了,还是很简单的

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值