// hzyDlg.cpp : implementation file
//

#include "stdafx.h"
#include "hzy.h"
#include "hzyDlg.h"
#include "GameProc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CHzyDlg dialog

CHzyDlg::CHzyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CHzyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CHzyDlg)
	m_HP = 0;
	m_MP = 0;
	m_level = 0;
	m_HPMax = 0;
	m_MPMax = 0;
	m_magicDef = 0;
	m_magicAtt = 0;
	m_precision = 0;
	m_speed = 0;
	m_attack = 0;
	m_avoid = 0;
	m_defence = 0;
	m_doubleAtt = 0;
	m_property = 0;
	m_experience = 0;
	m_static_state = _T("");
	m_money = 0;
	m_monsterAtt = 0;
	m_monsterDef = 0;
	m_monsterHP = 0;
	m_monsterMagicAtt = 0;
	m_monsterMagicDef = 0;
	m_monsterMP = 0;
	m_monsterNum = 0;
	m_monsterPrecision = 0;
	m_monsterSpeed = 0;
	m_goodsNum = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	//m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON1);
	m_hIcon = (HICON)LoadImage(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDI_ICON1),IMAGE_ICON,64,64,LR_DEFAULTCOLOR);

}

void CHzyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CHzyDlg)
	DDX_Control(pDX, IDC_COMBO_goods, m_goods);
	DDX_Control(pDX, IDC_COMBO_monster, m_monster);
	DDX_Control(pDX, IDC_COMBO_personality, m_personality);
	DDX_Control(pDX, IDC_STATIC_authorQQ, m_authorQQ);
	DDX_Control(pDX, IDC_COMBO_RoleSele, m_RoleSele);
	DDX_Text(pDX, IDC_EDIT_HP, m_HP);
	DDX_Text(pDX, IDC_EDIT_MP, m_MP);
	DDX_Text(pDX, IDC_EDIT_level, m_level);
	DDX_Text(pDX, IDC_EDIT_HPMax, m_HPMax);
	DDX_Text(pDX, IDC_EDIT_MPMax, m_MPMax);
	DDX_Text(pDX, IDC_EDIT_magicDef, m_magicDef);
	DDX_Text(pDX, IDC_EDIT_magicAtt, m_magicAtt);
	DDX_Text(pDX, IDC_EDIT_precision, m_precision);
	DDX_Text(pDX, IDC_EDIT_speed, m_speed);
	DDX_Text(pDX, IDC_EDIT_attack, m_attack);
	DDX_Text(pDX, IDC_EDIT_avoid, m_avoid);
	DDX_Text(pDX, IDC_EDIT_defence, m_defence);
	DDX_Text(pDX, IDC_EDIT_doubleAtt, m_doubleAtt);
	DDX_Text(pDX, IDC_EDIT_property, m_property);
	DDX_Text(pDX, IDC_EDIT_experience, m_experience);
	DDX_Text(pDX, IDC_STATIC_state, m_static_state);
	DDX_Text(pDX, IDC_EDIT_money, m_money);
	DDX_Text(pDX, IDC_EDIT_monsterAtt, m_monsterAtt);
	DDX_Text(pDX, IDC_EDIT_monsterDef, m_monsterDef);
	DDX_Text(pDX, IDC_EDIT_monsterHP, m_monsterHP);
	DDX_Text(pDX, IDC_EDIT_monsterMagicAtt, m_monsterMagicAtt);
	DDX_Text(pDX, IDC_EDIT_monsterMagicDef, m_monsterMagicDef);
	DDX_Text(pDX, IDC_EDIT_monsterMP, m_monsterMP);
	DDX_Text(pDX, IDC_EDIT_monsterNum, m_monsterNum);
	DDX_Text(pDX, IDC_EDIT_monsterPrecision, m_monsterPrecision);
	DDX_Text(pDX, IDC_EDIT_monsterSpeed, m_monsterSpeed);
	DDX_Text(pDX, IDC_EDIT_goodsNum, m_goodsNum);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CHzyDlg, CDialog)
	//{{AFX_MSG_MAP(CHzyDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BTN_READDATA, OnBtnReaddata)
	ON_BN_CLICKED(IDC_BTN_EDITDATA, OnBtnEditdata)
	ON_CBN_SELCHANGE(IDC_COMBO_RoleSele, OnSelchangeCOMBORoleSele)
	ON_WM_TIMER()
	ON_WM_CTLCOLOR()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_CBN_SELCHANGE(IDC_COMBO_personality, OnSelchangeCOMBOpersonality)
	ON_BN_CLICKED(IDC_BTN_ReadGoods, OnBtnReadGoods)
	ON_BN_CLICKED(IDC_BTN_EditGoods, OnBtnEditGoods)
	ON_CBN_SELCHANGE(IDC_COMBO_monster, OnSelchangeCOMBOmonster)
	ON_CBN_SELCHANGE(IDC_COMBO_goods, OnSelchangeCOMBOgoods)
	ON_BN_CLICKED(IDC_CHECK_omitAnimation, OnCHECKomitAnimation)
	ON_BN_CLICKED(IDC_CHECK_noFight, OnCHECKnoFight)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHzyDlg message handlers

BOOL CHzyDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, FALSE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	//设置定时器,检测游戏运行状态
	SetTimer(1,800,NULL);

	// TODO: Add extra initialization here
	m_RoleSele.AddString(_T("焉逢"));
	m_RoleSele.AddString(_T("横艾"));
	m_RoleSele.AddString(_T("疆梧"));
	m_RoleSele.AddString(_T("徒维"));
	m_RoleSele.AddString(_T("游兆"));
	m_RoleSele.AddString(_T("尚章"));
	m_RoleSele.AddString(_T("耶亚希"));
	m_RoleSele.AddString(_T("青冥"));
	m_RoleSele.AddString(_T("马弃"));
	m_RoleSele.AddString(_T("司徒蔷"));
	m_RoleSele.SetCurSel(0);
	//设置组合框字体
	roleSeleFont.CreatePointFont(140,"STKaiti");
	m_RoleSele.SetFont(&roleSeleFont);
	//超链接，保存控件的坐标
	GetDlgItem(IDC_STATIC_authorQQ)->GetWindowRect(&m_Rect);
	ScreenToClient(&m_Rect);
	//超链接，下划线
	m_cfNtr = this->GetFont();
	m_cfNtr->GetLogFont(&m_lfNtr);
	m_cfNtr->GetLogFont(&m_lfUL);
	m_lfUL.lfUnderline = true;
	m_cfUL.CreateFontIndirect(&m_lfUL);
	return TRUE;  // return TRUE  unless you set the focus to a control
}


// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CHzyDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CHzyDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
//存放读取长度
DWORD byread;
//金钱基址
LPVOID pBaseMoney = (LPVOID)0x007831DC;
void CHzyDlg::OnBtnReaddata()
{
	//取得窗口句柄/线程ID/线程句柄
	if(!startGame())
		return;
	
	/*
	//这种方法导致m数组为局部数组，外面访问不到,
	//所以只好在父类中定义m数组，子类中赋值.
	LPVOID m[][2] = {
		{(LPVOID)0x00783A40,(LPVOID)&m_HP},
		{(LPVOID)0x00783A4C,(LPVOID)&m_MP}
	};*/
	/* 测试：打印组合框选择项索引号
	CString str;
	str.Format(_T("%d"),selectedRole);
	AfxMessageBox(str);*/
	//给二维数组赋值：基址 与 编辑框变量
	switch(selectedRole)
	{
		case 1://焉逢
			m[0][0] = (LPVOID)0x00783A3c; m[0][1] = (LPVOID)&m_level;
			m[1][0] = (LPVOID)0x00783A40; m[1][1] = (LPVOID)&m_HP;
			m[2][0] = (LPVOID)0x00783A44; m[2][1] = (LPVOID)&m_HPMax;
			m[3][0] = (LPVOID)0x00783A4C; m[3][1] = (LPVOID)&m_MP;
			m[4][0] = (LPVOID)0x00783A4E; m[4][1] = (LPVOID)&m_MPMax;
			m[5][0] = (LPVOID)0x00783A54; m[5][1] = (LPVOID)&m_attack;
			m[6][0] = (LPVOID)0x00783A56; m[6][1] = (LPVOID)&m_defence;
			m[7][0] = (LPVOID)0x00783A68; m[7][1] = (LPVOID)&m_magicAtt;
			m[8][0] = (LPVOID)0x00783A6a; m[8][1] = (LPVOID)&m_magicDef;
			m[9][0] = (LPVOID)0x00783A58; m[9][1] = (LPVOID)&m_speed;
			m[10][0] = (LPVOID)0x00783A5a; m[10][1] = (LPVOID)&m_precision;
			m[11][0] = (LPVOID)0x00783A5c; m[11][1] = (LPVOID)&m_avoid;
			m[12][0] = (LPVOID)0x00783A5e; m[12][1] = (LPVOID)&m_doubleAtt;
			m[13][0] = (LPVOID)0x00783A62; m[13][1] = (LPVOID)&m_property;
			m[14][0] = (LPVOID)0x00783A60; m[14][1] = (LPVOID)&m_personality;
			m[15][0] = (LPVOID)0x00783AA0; m[15][1] = (LPVOID)&m_experience;
			break;
		case 2://横艾
			m[0][0] = (LPVOID)0x00783BB0; m[0][1] = (LPVOID)&m_level;
			m[1][0] = (LPVOID)0x00783BB4; m[1][1] = (LPVOID)&m_HP;
			m[2][0] = (LPVOID)0x00783BB8; m[2][1] = (LPVOID)&m_HPMax;
			m[3][0] = (LPVOID)0x00783BBC; m[3][1] = (LPVOID)&m_MP;
			m[4][0] = (LPVOID)0x00783BBE; m[4][1] = (LPVOID)&m_MPMax;
			m[5][0] = (LPVOID)0x00783BC8; m[5][1] = (LPVOID)&m_attack;
			m[6][0] = (LPVOID)0x00783BCA; m[6][1] = (LPVOID)&m_defence;
			m[7][0] = (LPVOID)0x00783Bdc; m[7][1] = (LPVOID)&m_magicAtt;
			m[8][0] = (LPVOID)0x00783Bde; m[8][1] = (LPVOID)&m_magicDef;
			m[9][0] = (LPVOID)0x00783BCc; m[9][1] = (LPVOID)&m_speed;
			m[10][0] = (LPVOID)0x00783BCe; m[10][1] = (LPVOID)&m_precision;
			m[11][0] = (LPVOID)0x00783Bd0; m[11][1] = (LPVOID)&m_avoid;
			m[12][0] = (LPVOID)0x00783Bd2; m[12][1] = (LPVOID)&m_doubleAtt;
			m[13][0] = (LPVOID)0x00783Bd6; m[13][1] = (LPVOID)&m_property;
			m[14][0] = (LPVOID)0x00783Bd4; m[14][1] = (LPVOID)&m_personality;
			m[15][0] = (LPVOID)0x00783C14; m[15][1] = (LPVOID)&m_experience;
			break;
		case 3://疆梧
			m[0][0] = (LPVOID)0x00783D24; m[0][1] = (LPVOID)&m_level;
			m[1][0] = (LPVOID)0x00783D28; m[1][1] = (LPVOID)&m_HP;
			m[2][0] = (LPVOID)0x00783D2C; m[2][1] = (LPVOID)&m_HPMax;
			m[3][0] = (LPVOID)0x00783D34; m[3][1] = (LPVOID)&m_MP;
			m[4][0] = (LPVOID)0x00783D36; m[4][1] = (LPVOID)&m_MPMax;
			m[5][0] = (LPVOID)0x00783D3c; m[5][1] = (LPVOID)&m_attack;
			m[6][0] = (LPVOID)0x00783D3e; m[6][1] = (LPVOID)&m_defence;
			m[7][0] = (LPVOID)0x00783D50; m[7][1] = (LPVOID)&m_magicAtt;
			m[8][0] = (LPVOID)0x00783D52; m[8][1] = (LPVOID)&m_magicDef;
			m[9][0] = (LPVOID)0x00783D40; m[9][1] = (LPVOID)&m_speed;
			m[10][0] = (LPVOID)0x00783D42; m[10][1] = (LPVOID)&m_precision;
			m[11][0] = (LPVOID)0x00783D44; m[11][1] = (LPVOID)&m_avoid;
			m[12][0] = (LPVOID)0x00783D46; m[12][1] = (LPVOID)&m_doubleAtt;
			m[13][0] = (LPVOID)0x00783D4a; m[13][1] = (LPVOID)&m_property;
			m[14][0] = (LPVOID)0x00783D48; m[14][1] = (LPVOID)&m_personality;
			m[15][0] = (LPVOID)0x00783D88; m[15][1] = (LPVOID)&m_experience;
			break;
		case 4://徒维
			m[0][0] = (LPVOID)0x00783E98; m[0][1] = (LPVOID)&m_level;
			m[1][0] = (LPVOID)0x00783E9C; m[1][1] = (LPVOID)&m_HP;
			m[2][0] = (LPVOID)0x00783EA0; m[2][1] = (LPVOID)&m_HPMax;
			m[3][0] = (LPVOID)0x00783EA4; m[3][1] = (LPVOID)&m_MP;
			m[4][0] = (LPVOID)0x00783EA6; m[4][1] = (LPVOID)&m_MPMax;
			m[5][0] = (LPVOID)0x00783Eb0; m[5][1] = (LPVOID)&m_attack;
			m[6][0] = (LPVOID)0x00783Eb2; m[6][1] = (LPVOID)&m_defence;
			m[7][0] = (LPVOID)0x00783Ec4; m[7][1] = (LPVOID)&m_magicAtt;
			m[8][0] = (LPVOID)0x00783Ec6; m[8][1] = (LPVOID)&m_magicDef;
			m[9][0] = (LPVOID)0x00783Eb4; m[9][1] = (LPVOID)&m_speed;
			m[10][0] = (LPVOID)0x00783Eb6; m[10][1] = (LPVOID)&m_precision;
			m[11][0] = (LPVOID)0x00783Eb8; m[11][1] = (LPVOID)&m_avoid;
			m[12][0] = (LPVOID)0x00783Eba; m[12][1] = (LPVOID)&m_doubleAtt;
			m[13][0] = (LPVOID)0x00783Ebe; m[13][1] = (LPVOID)&m_property;
			m[14][0] = (LPVOID)0x00783Ebc; m[14][1] = (LPVOID)&m_personality;
			m[15][0] = (LPVOID)0x00783EFC; m[15][1] = (LPVOID)&m_experience;
			break;
		case 5://游兆
			m[0][0] = (LPVOID)0x0078400c; m[0][1] = (LPVOID)&m_level;
			m[1][0] = (LPVOID)0x00784010; m[1][1] = (LPVOID)&m_HP;
			m[2][0] = (LPVOID)0x00784014; m[2][1] = (LPVOID)&m_HPMax;
			m[3][0] = (LPVOID)0x0078401c; m[3][1] = (LPVOID)&m_MP;
			m[4][0] = (LPVOID)0x0078401e; m[4][1] = (LPVOID)&m_MPMax;
			m[5][0] = (LPVOID)0x00784024; m[5][1] = (LPVOID)&m_attack;
			m[6][0] = (LPVOID)0x00784026; m[6][1] = (LPVOID)&m_defence;
			m[7][0] = (LPVOID)0x00784038; m[7][1] = (LPVOID)&m_magicAtt;
			m[8][0] = (LPVOID)0x0078403a; m[8][1] = (LPVOID)&m_magicDef;
			m[9][0] = (LPVOID)0x00784028; m[9][1] = (LPVOID)&m_speed;
			m[10][0] = (LPVOID)0x0078402a; m[10][1] = (LPVOID)&m_precision;
			m[11][0] = (LPVOID)0x0078402c; m[11][1] = (LPVOID)&m_avoid;
			m[12][0] = (LPVOID)0x0078402e; m[12][1] = (LPVOID)&m_doubleAtt;
			m[13][0] = (LPVOID)0x00784032; m[13][1] = (LPVOID)&m_property;
			m[14][0] = (LPVOID)0x00784030; m[14][1] = (LPVOID)&m_personality;
			m[15][0] = (LPVOID)0x00784070; m[15][1] = (LPVOID)&m_experience;
			break;
		case 6://尚章
			m[0][0] = (LPVOID)0x00784180; m[0][1] = (LPVOID)&m_level;
			m[1][0] = (LPVOID)0x00784184; m[1][1] = (LPVOID)&m_HP;
			m[2][0] = (LPVOID)0x00784188; m[2][1] = (LPVOID)&m_HPMax;
			m[3][0] = (LPVOID)0x00784190; m[3][1] = (LPVOID)&m_MP;
			m[4][0] = (LPVOID)0x00784192; m[4][1] = (LPVOID)&m_MPMax;
			m[5][0] = (LPVOID)0x00784198; m[5][1] = (LPVOID)&m_attack;
			m[6][0] = (LPVOID)0x0078419a; m[6][1] = (LPVOID)&m_defence;
			m[7][0] = (LPVOID)0x007841ac; m[7][1] = (LPVOID)&m_magicAtt;
			m[8][0] = (LPVOID)0x007841ae; m[8][1] = (LPVOID)&m_magicDef;
			m[9][0] = (LPVOID)0x0078419c; m[9][1] = (LPVOID)&m_speed;
			m[10][0] = (LPVOID)0x0078419e; m[10][1] = (LPVOID)&m_precision;
			m[11][0] = (LPVOID)0x007841a0; m[11][1] = (LPVOID)&m_avoid;
			m[12][0] = (LPVOID)0x007841a2; m[12][1] = (LPVOID)&m_doubleAtt;
			m[13][0] = (LPVOID)0x007841a6; m[13][1] = (LPVOID)&m_property;
			m[14][0] = (LPVOID)0x007841a4; m[14][1] = (LPVOID)&m_personality;
			m[15][0] = (LPVOID)0x007841E4; m[15][1] = (LPVOID)&m_experience;
			break;
		case 7://耶亚希
			m[0][0] = (LPVOID)0x00784468; m[0][1] = (LPVOID)&m_level;
			m[1][0] = (LPVOID)0x0078446C; m[1][1] = (LPVOID)&m_HP;
			m[2][0] = (LPVOID)0x00784470; m[2][1] = (LPVOID)&m_HPMax;
			m[3][0] = (LPVOID)0x00784474; m[3][1] = (LPVOID)&m_MP;
			m[4][0] = (LPVOID)0x00784476; m[4][1] = (LPVOID)&m_MPMax;
			m[5][0] = (LPVOID)0x00784480; m[5][1] = (LPVOID)&m_attack;
			m[6][0] = (LPVOID)0x00784482; m[6][1] = (LPVOID)&m_defence;
			m[7][0] = (LPVOID)0x00784494; m[7][1] = (LPVOID)&m_magicAtt;
			m[8][0] = (LPVOID)0x00784496; m[8][1] = (LPVOID)&m_magicDef;
			m[9][0] = (LPVOID)0x00784484; m[9][1] = (LPVOID)&m_speed;
			m[10][0] = (LPVOID)0x00784486; m[10][1] = (LPVOID)&m_precision;
			m[11][0] = (LPVOID)0x00784488; m[11][1] = (LPVOID)&m_avoid;
			m[12][0] = (LPVOID)0x0078448a; m[12][1] = (LPVOID)&m_doubleAtt;
			m[13][0] = (LPVOID)0x0078448e; m[13][1] = (LPVOID)&m_property;
			m[14][0] = (LPVOID)0x0078448c; m[14][1] = (LPVOID)&m_personality;
			m[15][0] = (LPVOID)0x007844cc; m[15][1] = (LPVOID)&m_experience;
			break;
		case 8://青冥
			m[0][0] = (LPVOID)0x007845dc; m[0][1] = (LPVOID)&m_level;
			m[1][0] = (LPVOID)0x007845E0; m[1][1] = (LPVOID)&m_HP;
			m[2][0] = (LPVOID)0x007845E4; m[2][1] = (LPVOID)&m_HPMax;
			m[3][0] = (LPVOID)0x007845E8; m[3][1] = (LPVOID)&m_MP;
			m[4][0] = (LPVOID)0x007845Ea; m[4][1] = (LPVOID)&m_MPMax;
			m[5][0] = (LPVOID)0x007845f4; m[5][1] = (LPVOID)&m_attack;
			m[6][0] = (LPVOID)0x007845f6; m[6][1] = (LPVOID)&m_defence;
			m[7][0] = (LPVOID)0x00784608; m[7][1] = (LPVOID)&m_magicAtt;
			m[8][0] = (LPVOID)0x0078460a; m[8][1] = (LPVOID)&m_magicDef;
			m[9][0] = (LPVOID)0x007845f8; m[9][1] = (LPVOID)&m_speed;
			m[10][0] = (LPVOID)0x007845fa; m[10][1] = (LPVOID)&m_precision;
			m[11][0] = (LPVOID)0x007845fc; m[11][1] = (LPVOID)&m_avoid;
			m[12][0] = (LPVOID)0x007845fe; m[12][1] = (LPVOID)&m_doubleAtt;
			m[13][0] = (LPVOID)0x00784602; m[13][1] = (LPVOID)&m_property;
			m[14][0] = (LPVOID)0x00784600; m[14][1] = (LPVOID)&m_personality;
			m[15][0] = (LPVOID)0x00784640; m[15][1] = (LPVOID)&m_experience;
			break;
		case 9://马弃
			m[0][0] = (LPVOID)0x00784750; m[0][1] = (LPVOID)&m_level;
			m[1][0] = (LPVOID)0x00784754; m[1][1] = (LPVOID)&m_HP;
			m[2][0] = (LPVOID)0x00784758; m[2][1] = (LPVOID)&m_HPMax;
			m[3][0] = (LPVOID)0x00784760; m[3][1] = (LPVOID)&m_MP;
			m[4][0] = (LPVOID)0x00784762; m[4][1] = (LPVOID)&m_MPMax;
			m[5][0] = (LPVOID)0x00784768; m[5][1] = (LPVOID)&m_attack;
			m[6][0] = (LPVOID)0x0078476a; m[6][1] = (LPVOID)&m_defence;
			m[7][0] = (LPVOID)0x0078477c; m[7][1] = (LPVOID)&m_magicAtt;
			m[8][0] = (LPVOID)0x0078477e; m[8][1] = (LPVOID)&m_magicDef;
			m[9][0] = (LPVOID)0x0078476c; m[9][1] = (LPVOID)&m_speed;
			m[10][0] = (LPVOID)0x0078476e; m[10][1] = (LPVOID)&m_precision;
			m[11][0] = (LPVOID)0x00784770; m[11][1] = (LPVOID)&m_avoid;
			m[12][0] = (LPVOID)0x00784772; m[12][1] = (LPVOID)&m_doubleAtt;
			m[13][0] = (LPVOID)0x00784776; m[13][1] = (LPVOID)&m_property;
			m[14][0] = (LPVOID)0x00784774; m[14][1] = (LPVOID)&m_personality;
			m[15][0] = (LPVOID)0x007847B4; m[15][1] = (LPVOID)&m_experience;
			break;
		case 10://司徒蔷
			m[0][0] = (LPVOID)0x007848C4; m[0][1] = (LPVOID)&m_level;
			m[1][0] = (LPVOID)0x007848C8; m[1][1] = (LPVOID)&m_HP;
			m[2][0] = (LPVOID)0x007848CC; m[2][1] = (LPVOID)&m_HPMax;
			m[3][0] = (LPVOID)0x007848d0; m[3][1] = (LPVOID)&m_MP;
			m[4][0] = (LPVOID)0x007848d2; m[4][1] = (LPVOID)&m_MPMax;
			m[5][0] = (LPVOID)0x007848dc; m[5][1] = (LPVOID)&m_attack;
			m[6][0] = (LPVOID)0x007848de; m[6][1] = (LPVOID)&m_defence;
			m[7][0] = (LPVOID)0x007848f0; m[7][1] = (LPVOID)&m_magicAtt;
			m[8][0] = (LPVOID)0x007848f2; m[8][1] = (LPVOID)&m_magicDef;
			m[9][0] = (LPVOID)0x007848e0; m[9][1] = (LPVOID)&m_speed;
			m[10][0] = (LPVOID)0x007848e2; m[10][1] = (LPVOID)&m_precision;
			m[11][0] = (LPVOID)0x007848e4; m[11][1] = (LPVOID)&m_avoid;
			m[12][0] = (LPVOID)0x007848e6; m[12][1] = (LPVOID)&m_doubleAtt;
			m[13][0] = (LPVOID)0x007848ea; m[13][1] = (LPVOID)&m_property;
			m[14][0] = (LPVOID)0x007848e8; m[14][1] = (LPVOID)NULL;
			m[15][0] = (LPVOID)0x00784928; m[15][1] = (LPVOID)&m_experience;
			break;
		default:
			AfxMessageBox("请选择人物！");
			return;

	}
	//计算m数组的一维长度
	int len2 = sizeof(m)/sizeof(LPVOID);
	int len3 = sizeof(m[0])/sizeof(LPVOID);
	len = len2/len3;
	//区别4字节数据,初始化dwordData
	dwordData = 2;

	//循环读内存
	for(size_t i=0; i<len; i++)
	{
		int a = 0;//中转变量
		switch(i)
		{
			case 14://对"个性"属性单独处理
				::ReadProcessMemory(processH,m[i][0],(LPVOID)&a,dwordData,&byread);
				m_personality.SetCurSel(a);
				//给selectedPersonality赋初值,不然为0xCCCCCCCC (-858993460)
				selectedPersonality = a;
				continue;
			case 15:
				dwordData += 2;//区别4字节数据
				break;
		}
		
		::ReadProcessMemory(processH,m[i][0],m[i][1],dwordData,&byread);

	}
	//读金钱
	::ReadProcessMemory(processH,pBaseMoney,(LPVOID)&m_money,4,&byread);
	UpdateData(false);
}

void CHzyDlg::OnBtnEditdata() 
{
	//更新编辑框值
	UpdateData(true);
	//区别4字节数据,初始化dwordData
	dwordData = 2;
	//写入内存
	for(int i=0; i<len; i++)
	{
		switch(i)
		{
			case 14:
				::WriteProcessMemory(processH,m[i][0],(LPVOID)&selectedPersonality,2,NULL);
				continue;
			case 15:
				dwordData += 2;//区别4字节数据
				break;
		}
		::WriteProcessMemory(processH,m[i][0],m[i][1],dwordData,NULL);
		dwordData = 2;
	}
	::WriteProcessMemory(processH,pBaseMoney,(LPVOID)&m_money,4,NULL);//写金钱	
}
//CBN_SELCHANGE "人物选择"组合框,获取选择项索引
void CHzyDlg::OnSelchangeCOMBORoleSele() 
{
	// 取得选择项的索引
	selectedRole = ((CComboBox *)GetDlgItem(IDC_COMBO_RoleSele))->GetCurSel();
}

// 人物属性-> "个性",获取选择项索引
void CHzyDlg::OnSelchangeCOMBOpersonality() 
{
	selectedPersonality = ((CComboBox *)GetDlgItem(IDC_COMBO_personality))->GetCurSel();
}
//WM_TIMER消息处理函数，定时检测游戏运行状态
void CHzyDlg::OnTimer(UINT nIDEvent) 
{
	CDialog::OnTimer(nIDEvent);
	UpdateData(true);
	if(::FindWindow(NULL,gameCaption) == NULL)
	{
		m_static_state = _T("游戏没有运行！");
	}
	else
	{
		m_static_state = _T("游戏已运行！");
	}
	UpdateData(false);
}

//设置外观
HBRUSH CHzyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	//设置静态文本框->作者信息 的样式
	switch(pWnd->GetDlgCtrlID())
	{
		case IDC_STATIC_QQLable:
			pDC->SetTextColor(RGB(0,50,200));
			break;
		case IDC_STATIC_authorQQ:
			pDC->SetTextColor(RGB(5,15,125));
			break;
		default:
			break;
	}
	if(pWnd->GetDlgCtrlID() == IDC_COMBO_RoleSele)
	{
		pDC->SetTextColor(RGB(122,122,122));
	}
	return hbr;
}
//响应鼠标左键消息，定位超链接区域
void CHzyDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{	
	//超链接->作者QQ号
	if(point.x > m_Rect.left && point.x < m_Rect.right &&
	   point.y < m_Rect.bottom && point.y > m_Rect.top)
	{
		ShellExecute(NULL,NULL,"http://1060184838.qzone.qq.com",NULL,NULL,SW_NORMAL);
	}
	CDialog::OnLButtonUp(nFlags, point);
}
//鼠标move消息
void CHzyDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	//设置移上超链接的鼠标形状
	if(point.x > m_Rect.left && point.x < m_Rect.right && 
	   point.y < m_Rect.bottom && point.y > m_Rect.top)
	{
		HCURSOR hCursor;
		hCursor = ::LoadCursor(NULL,MAKEINTRESOURCE(32649));//手型
		::SetCursor(hCursor);
		//下划线
		GetDlgItem(IDC_STATIC_authorQQ)->SetFont(&m_cfUL);
	}
	else
	{	//还原(去除下划线)
		GetDlgItem(IDC_STATIC_authorQQ)->SetFont(m_cfNtr);
	}
	CDialog::OnMouseMove(nFlags, point);
}

//物品基址
LPVOID pBaseGoods = (LPVOID)0x007831B4;
//物品基址指针
DWORD pGoodsTmp1;
//物品2级偏移
DWORD pGoodsTmp2;
//物品数量
int goodsNum = 0;
DWORD lastGoods;
//物品数量基址
LPVOID pBaseGoodsNum = (LPVOID)0x007831D8;
//物品名字
LPVOID goodsName;
//壶妖基址
LPVOID pBaseMonster = (LPVOID)0x007CFD80;
//壶妖偏移
DWORD pBaseMonsterTMP;
//壶妖名字数组
LPVOID monsterName;
//壶妖数量基址
LPVOID pBaseMonsterNum = (LPVOID)0x007CEF84;
//壶妖数量偏移
DWORD pBaseMonsterNumTMP;
//壶妖数量
int monsterNum = 0;
DWORD lastMonster;
//读取物品
void CHzyDlg::OnBtnReadGoods()
{
	if(!startGame())
		return;

	//取物品基址指针
	::ReadProcessMemory(processH,pBaseGoods,&pGoodsTmp1,4,&byread);
	//取物品数量
	::ReadProcessMemory(processH,pBaseGoodsNum,&lastGoods,4,&byread);
	//判断物品数量
	if(lastGoods>0)
		goodsNum=lastGoods;//取数量值的首选方式,下策是else
	else
	{
		do
		{
			::ReadProcessMemory(processH,(LPVOID)(pGoodsTmp1+goodsNum*0x4),&lastGoods,4,&byread);
			goodsNum++;
		}while(lastGoods !=0 );
		goodsNum-=1;
	}

	if(m_goods.GetCount() != goodsNum)//与物品数量比较,如不相等才刷新
	{
		m_goods.ResetContent();//添加列表项之前,清空列表项
		for(int h=0; h<goodsNum; h++)
		{
			::ReadProcessMemory(processH,(LPVOID)(pGoodsTmp1+h*0x4),&pGoodsTmp2,4,&byread);//读物品地址

			goodsName = malloc(8);//动态分配内存
			if(!goodsName)goodsName = realloc(goodsName,9);//内存不足,则扩容

			::ReadProcessMemory(processH,(LPVOID)(pGoodsTmp2+0x10),goodsName,8,&byread);//读物品名称
			LPSTR goodsNameGBK = Big52GBKTraditional((char *)goodsName);//Big5转GBK繁体
			m_goods.AddString(goodsNameGBK);//给"物品"组合框添加项
		}
		free(goodsName);
	}

	m_goods.SetCurSel(0);//设置默认显示项
	//读第1个物品的数量
	::ReadProcessMemory(processH,(LPVOID)(pGoodsTmp1+0*0x4),&pGoodsTmp2,4,&byread);//读物品地址
	::ReadProcessMemory(processH,(LPVOID)(pGoodsTmp2+0x4),(LPVOID)&m_goodsNum,4,&byread);

/* --------------------------------以下是读壶妖---------------------------------------------- */
	//读取壶妖基址
	::ReadProcessMemory(processH,pBaseMonster,&pBaseMonsterTMP,4,&byread);
	//读取壶妖数量
	::ReadProcessMemory(processH,pBaseMonsterNum,&pBaseMonsterNumTMP,4,&byread);//从数量基址读数量
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterNumTMP+0x124),&pBaseMonsterNumTMP,4,&byread);

	if(pBaseMonsterNumTMP > 0)//如果进入过"鬼神之塔"即能读取数量,否则用下策(这个数量地址不靠谱)
		monsterNum = pBaseMonsterNumTMP;
	else
	{
		do
		{	//壶妖ID如果为0,则退出循环. 循环次数=壶妖数量.
			::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+monsterNum*0xc8),&lastMonster,4,&byread);
			monsterNum++;
		}while(lastMonster != 0);
		monsterNum-=1;
	}

	if(m_monster.GetCount() != monsterNum)
	{
		m_monster.ResetContent();
		//内存中读取壶妖名字
		for(int i=0; i<monsterNum; i++)
		{
			//动态内存分配，4个汉字=8字节
			monsterName = malloc(8);
			if(!monsterName)
				monsterName = realloc(monsterName,9);//如果内存不足, 则扩容

			::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+i*0xc8+0x8),monsterName,8,&byread);
			LPSTR monsterNameGBK = Big52GBKTraditional((char *)monsterName);//Big5码转GBK繁体
			m_monster.AddString(monsterNameGBK);//添加组合框列表项
		}
		free(monsterName);//释放内存
	}

	m_monster.SetCurSel(0);//组合框默认显示项目
	
	//读第1个壶妖的各属性
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+0*0xc8+0x4),(LPVOID)&m_monsterNum,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+0*0xc8+0x34),(LPVOID)&m_monsterHP,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+0*0xc8+0x3c),(LPVOID)&m_monsterMP,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+0*0xc8+0x40),(LPVOID)&m_monsterAtt,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+0*0xc8+0x44),(LPVOID)&m_monsterDef,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+0*0xc8+0x48),(LPVOID)&m_monsterMagicAtt,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+0*0xc8+0x4c),(LPVOID)&m_monsterMagicDef,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+0*0xc8+0x50),(LPVOID)&m_monsterSpeed,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+0*0xc8+0x54),(LPVOID)&m_monsterPrecision,4,&byread);
	UpdateData(false);

}

//修改物品
void CHzyDlg::OnBtnEditGoods() 
{
	if(selectedGoods<0)selectedGoods=0;
	::ReadProcessMemory(processH,(LPVOID)(pGoodsTmp1+selectedGoods*0x4),&pGoodsTmp2,4,&byread); //读物品地址
	::WriteProcessMemory(processH,(LPVOID)(pGoodsTmp2+0x4),(LPVOID)&m_goodsNum,4,NULL);		//写物品数量

	//修改壶妖属性
	int n = selectedMonster;
	if(n<0)n=0;//判断不为:0xcccccccc
	::WriteProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x4),(LPVOID)&m_monsterNum,4,NULL);   //写壶妖数量
	::WriteProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x34),(LPVOID)&m_monsterHP,4,NULL);   //写壶妖生命
	::WriteProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x3c),(LPVOID)&m_monsterMP,4,NULL);   //写壶妖体力
	::WriteProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x40),(LPVOID)&m_monsterAtt,4,NULL);   //写壶妖攻击
	::WriteProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x44),(LPVOID)&m_monsterDef,4,NULL);   //写壶妖防御
	::WriteProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x48),(LPVOID)&m_monsterMagicAtt,4,NULL);   //写壶妖仙攻
	::WriteProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x4c),(LPVOID)&m_monsterMagicDef,4,NULL);   //写壶妖仙防
	::WriteProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x50),(LPVOID)&m_monsterSpeed,4,NULL);   //写壶妖速度
	::WriteProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x54),(LPVOID)&m_monsterPrecision,4,NULL);   //写壶妖命中

}

//"物品" 组合框被选择时
void CHzyDlg::OnSelchangeCOMBOgoods() 
{
	selectedGoods = ((CComboBox *)GetDlgItem(IDC_COMBO_goods))->GetCurSel();//获取当前选择的物品索引
	::ReadProcessMemory(processH,(LPVOID)(pGoodsTmp1+selectedGoods*0x4),&pGoodsTmp2,4,&byread);//读物品地址
	::ReadProcessMemory(processH,(LPVOID)(pGoodsTmp2+0x4),(LPVOID)&m_goodsNum,4,&byread);
	UpdateData(false);
}

//"壶妖" 组合框被选择时
void CHzyDlg::OnSelchangeCOMBOmonster() 
{
	selectedMonster = ((CComboBox *)GetDlgItem(IDC_COMBO_monster))->GetCurSel();//获取当前选择的壶妖索引
	int n = selectedMonster;

	//按索引读对应壶妖的各属性
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x4),(LPVOID)&m_monsterNum,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x34),(LPVOID)&m_monsterHP,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x3c),(LPVOID)&m_monsterMP,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x40),(LPVOID)&m_monsterAtt,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x44),(LPVOID)&m_monsterDef,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x48),(LPVOID)&m_monsterMagicAtt,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x4c),(LPVOID)&m_monsterMagicDef,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x50),(LPVOID)&m_monsterSpeed,4,&byread);
	::ReadProcessMemory(processH,(LPVOID)(pBaseMonsterTMP+n*0xc8+0x54),(LPVOID)&m_monsterPrecision,4,&byread);
	UpdateData(false);
}
LPVOID pBaseOmitAnimation = (LPVOID)0x016307b6;//战斗开头动画call的地址
//复选框：去掉战斗开场动画
void CHzyDlg::OnCHECKomitAnimation()
{
	if(!startGame())
		return;

	byte omitAnimation[] = {0x83,0xc4,0x14,0x90,0x90};//add esp,0x14  ; nop nop
	byte backAnimation[] = {0xE8,0xD5,0xA1,0xE6,0xFE};//016307B6  E8 D5A1E6FE  call SwdHC.0049A990

	int checkState = ((CButton *)GetDlgItem(IDC_CHECK_omitAnimation))->GetCheck();//获取复选框状态
	if(checkState == 1)
		::WriteProcessMemory(processH,pBaseOmitAnimation,(LPVOID)&omitAnimation,5,&byread);
	else
		::WriteProcessMemory(processH,pBaseOmitAnimation,(LPVOID)&backAnimation,5,&byread);
}

LPVOID pBaseNoFight = (LPVOID)0x0040788E;//步数统计(猜的)地址. mov dword ptr ds:[0x784C58],eax
//复选框：不遇敌
void CHzyDlg::OnCHECKnoFight() 
{
	if(!startGame())
		return;

	byte noFight[] = {0x90,0x90,0x90,0x90,0x90};//用nop填充
	byte backFight[] = {0xA3,0x58,0x4C,0x78,0x00};//还原

	int checkState = ((CButton *)GetDlgItem(IDC_CHECK_noFight))->GetCheck();//获取复选框状态
	if(checkState == 1)
		::WriteProcessMemory(processH,pBaseNoFight,(LPVOID)&noFight,5,&byread);//写内存
	else
		::WriteProcessMemory(processH,pBaseNoFight,(LPVOID)&backFight,5,&byread);
}
