HeroInfo.WinHand := FindWindow('Heroes4', 'Heroes 4');
If HeroInfo.WinHand = 0 Then
Begin
ShowMessage('没有找到游戏窗口!!');
Exit;
End;
HeroInfo.ThreadId := GetWindowThreadProcessId(HeroInfo.WinHand, @HeroInfo.pId);
If HeroInfo.ThreadId = 0 Then
Begin
ShowMessage('没有找到游戏窗口!!');
Exit;
End;
//HeroInfo.hProcess := OpenProcess(PROCESS_ALL_ACCESS, true, HeroInfo.pId);
HeroInfo.hProcess := OpenProcess(PROCESS_VM_OPERATION Or PROCESS_VM_READ Or PROCESS_QUERY_INFORMATION, false, HeroInfo.pId);
If HeroInfo.hProcess = 0 Then
Begin
ShowMessage('没有找到游戏窗口!!');
Exit;
End;
GetSystemInfo(SysInfo);
PMemoAddr := SysInfo.lpMinimumApplicationAddress;
MaxMemoAddr := DWORD(SysInfo.lpMaximumApplicationAddress);
ProgressBar1.Visible := True;
ProgressBar1.Min := 1;
ProgressBar1.Max := Trunc((DWord(SysInfo.lpMaximumApplicationAddress) - DWord(SysInfo.lpMinimumApplicationAddress)) / $10000);
Try
While true Do
Begin
VirtualQueryEx(HeroInfo.hProcess, PMemoAddr, MBI, SizeOf(MBI));
nSize := MBI.RegionSize;
If MBI.State = MEM_COMMIT Then
Begin
FreeMem(DataBuffer);
GetMem(DataBuffer, nSize);
ReadProcessMemory(HeroInfo.hProcess, PMemoAddr, DataBuffer, nSize, lpNumberOfBytesRead);
j := Trunc(lpNumberOfBytesRead / 4);
ResultFind := False;
ProgressBar1.Position := Trunc((DWord(DWORD(PMemoAddr)) - DWord(SysInfo.lpMinimumApplicationAddress)) / $10000);
Application.ProcessMessages;
For i := 1 To j Do
Begin
// If (i Shr 10) Shl 10 = i Then
// Begin
// ProgressBar1.Position := Trunc((DWord(DWORD(PMemoAddr)) - DWord(SysInfo.lpMinimumApplicationAddress) + i * 4) / $10000);
// Application.ProcessMessages;
// End;
If DataBuffer^[i] = SearchDate1 Then //检查经验值
If DataBuffer^[i + Trunc(AddInfo.Offset4 / 4)] = SearchDate2 Then //检查剩余魔法点
If DataBuffer^[i + Trunc(AddInfo.Offset5 / 4)] = SearchDate3 Then //检查英雄等级
Begin
//检查辅助技能
CopyMemory(@Skill2Info, @DataBuffer^[i + Trunc(AddInfo.Offset2 / 4)], SizeOf(TSkill2Info));
For K := 1 To 36 Do If Skill2Info.Integer[k] > 4 Then Break;
If K = 37 Then //循环正常结束,没有执行过Break
Begin
Inc(ResultCount);
If ResultCount > 1 Then Break;
EditExp.Text := IntToHex(DWORD(PMemoAddr) + i * 4, 8);
End;
End;
End;
End;
If ResultCount > 1 Then Break;
MemoAddr := DWORD(PMemoAddr) + nSize;
If MemoAddr >= MaxMemoAddr Then Break;
PMemoAddr := Pointer(MemoAddr);
End;
Except
End;
FreeMem(DataBuffer);
CloseHandle(HeroInfo.hProcess);
HeroInfo.hProcess := 0;
If ResultCount = 0 Then
Begin
EditExp.Text := '';
ShowMessage('没有找到游戏数据,请检查查询条件!!');
End
Else
If ResultCount = 1 Then
Begin
Button1Click(Application);
//ShowMessage('找到一个合适的结果!!')
End
Else
ShowMessage('找到游戏数据太多,去玩一会再试!!');