89.网游逆向分析与插件开发-物品使用-实现物品使用策略的功能

内容参考于:易道云信息技术研究院VIP课

上一个内容:物品使用策略管理UI的设计-CSDN博客

码云地址(ui显示角色数据 分支):https://gitee.com/dye_your_fingers/sro_-ex.git

码云版本号:2104fdde4761ce846c6d0e52d9c5139fd62ece23

代码下载地址,在 SRO_EX 目录下,文件名为:SRO_Ex-实现物品使用策略的功能.zip

链接:https://pan.baidu.com/s/1W-JpUcGOWbSJmMdmtMzYZg

提取码:q9n5

--来自百度网盘超级会员V4的分享

HOOK引擎,文件名为:黑兔sdk.zip

链接:https://pan.baidu.com/s/1IB-Zs6hi3yU8LC2f-8hIEw

提取码:78h8

--来自百度网盘超级会员V4的分享

以 物品使用策略管理UI的设计-CSDN博客 它的代码为基础进行修改

CUIWnd_0.h文件的修改:新加 UseItemByName函数

#pragma once
#include "afxdialogex.h"
#include "ITEM.h"

// CUIWnd_0 对话框

class CUIWnd_0 : public CDialogEx
{
	DECLARE_DYNAMIC(CUIWnd_0)

public:
	CUIWnd_0(CWnd* pParent = nullptr);   // 标准构造函数
	virtual ~CUIWnd_0();

// 对话框数据
#ifdef AFX_DESIGN_TIME
	enum { IDD = IDD_PAGE_0 };
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

	DECLARE_MESSAGE_MAP()
public:
	// 玩家信息
	CString txt_Player;
	BOOL OnInitDialog();
	void ShowPlayerTxt();
	// 武器低音
	CString txtWeapon;
	CString txtMP;
	CString txtHPEx;
	CString txtHP;
	int HpMin;
	int HpExMin;
	int MpMin;
	afx_msg void OnBnClickedButton1();

	PITEM UseItemByName(CString& name);
};

CUIWnd_0.cpp文件的修改:新加 UseItemByName函数,修改了 ShowPlayerTxt函数

// CUIWnd_0.cpp: 实现文件
//

#include "pch.h"
#include "htdMfcDll.h"
#include "CUIWnd_0.h"
#include "GameBase.h"
#include "extern_all.h"

// CUIWnd_0 对话框
CUIWnd_0* UI_0;
void _stdcall TimeProc(HWND, UINT, UINT_PTR, DWORD) {
	if (UI_0) {
		UI_0->ShowPlayerTxt();
	}
}

IMPLEMENT_DYNAMIC(CUIWnd_0, CDialogEx)

CUIWnd_0::CUIWnd_0(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_PAGE_0, pParent)
	, txt_Player(_T(""))
	, txtWeapon(_T("瞬间回城卷轴"))
	, txtMP(_T("MP 回复草药 (特)"))
	, txtHPEx(_T("紫色棒棒糖"))
	, txtHP(_T("HP 回复草药 (特)"))
	, HpMin(75)
	, HpExMin(40)
	, MpMin(60)
{
	UI_0 = this;
}

CUIWnd_0::~CUIWnd_0()
{
}

void CUIWnd_0::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, txt_Player);
	DDX_Text(pDX, IDC_EDIT9, txtWeapon);
	DDX_Text(pDX, IDC_EDIT5, txtMP);
	DDX_Text(pDX, IDC_EDIT6, txtHPEx);
	DDX_Text(pDX, IDC_EDIT7, txtHP);
	DDX_Text(pDX, IDC_EDIT2, HpMin);
	DDX_Text(pDX, IDC_EDIT3, HpExMin);
	DDX_Text(pDX, IDC_EDIT4, MpMin);
}

BOOL CUIWnd_0::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	::SetTimer(this->m_hWnd, 0x100001, 100, TimeProc);
	return TRUE;
}

void CUIWnd_0::ShowPlayerTxt()
{
	// UpdateData(TRUE);
	if ((_pgamebase) && (_pgamebase->SRO_Player)) {
		CString txtTmp;
		txtTmp.Format(L"角色名:[%s] 等级[lv:%d]\r\n", _pgamebase->SRO_Player->Name.wcstrByName(), _pgamebase->SRO_Player->LV);
		txt_Player = txtTmp;
		txtTmp.Format(L"经验值:[%d] 技能点[%d]\r\n", _pgamebase->SRO_Player->Exp, _pgamebase->SRO_Player->SkillPoint);
		txt_Player += txtTmp;
		txtTmp.Format(L"血量:[%d/%d]\r\n", _pgamebase->SRO_Player->HP, _pgamebase->SRO_Player->MaxHP);
		txt_Player += txtTmp;
		txtTmp.Format(L"蓝量:[%d/%d]\r\n", _pgamebase->SRO_Player->MP, _pgamebase->SRO_Player->MaxMP);
		txt_Player += txtTmp;
		txtTmp.Format(L"坐标:[%f][%f][%f]\r\n", _pgamebase->SRO_Player->x, _pgamebase->SRO_Player->h, _pgamebase->SRO_Player->y);
		txt_Player += txtTmp;
		// 计算百分比
		txtTmp.Format(L"怒气:[%f/100]\r\n", (float)_pgamebase->SRO_Player->Rage/5*100);
		txt_Player += txtTmp;

		float _hpP = _pgamebase->SRO_Player->HP * 100;
		_hpP = _hpP / _pgamebase->SRO_Player->MaxHP;
		float _mpP = _pgamebase->SRO_Player->MP * 100;
		_mpP = _mpP / _pgamebase->SRO_Player->MaxMP;
		if (_hpP < HpExMin) {
			UseItemByName(txtHPEx);
		}else if (_hpP < HpMin) {
			UseItemByName(txtHP);
		}else if(_mpP < MpMin){
			UseItemByName(txtMP);
		}
		auto weapon = _pgamebase->SRO_Control->GetPPack()->GetEquipBack()->GetItem(EquipType::Weapon);
		if (weapon) {
			if ((weapon->Type > 0) && (weapon->MaxDurabillty == 0)) {
				UseItemByName(txtWeapon);
			}
		}
	}
	GetDlgItem(IDC_EDIT1)->SetWindowText(txt_Player);
	// UpdateData(FALSE);
}


BEGIN_MESSAGE_MAP(CUIWnd_0, CDialogEx)
	ON_BN_CLICKED(IDC_BUTTON1, &CUIWnd_0::OnBnClickedButton1)
END_MESSAGE_MAP()


// CUIWnd_0 消息处理程序


void CUIWnd_0::OnBnClickedButton1()
{
	UpdateData(TRUE);
}

PITEM CUIWnd_0::UseItemByName(CString& name)
{
	CString tmp;
	// tmp.Format(L"%d", count);
	// AfxMessageBox(tmp);
	PBackPack _PackBack = _pgamebase->SRO_Control->GetPPack()->GetPackBack();

	for (int i = 0; i < _PackBack->PackCount(); i++)
	{

		PITEM item = _PackBack->GetItem(i);
		if ((item != NULL) && (item->Type)) {
			tmp.Format(L"%s", item->GetNameByWide());
			if (tmp == name) {
				_pgamebase->SRO_Control->UseItem(i);
				return item;
			}
		}
	}
	return NULL;
}

你可能感兴趣的:(网游逆向,游戏,c++)