读取游戏数据

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label3: TLabel;
    label1: TLabel;
    Label2: TLabel;
    Labname: TLabel;
    Labhp: TLabel;
    Labmp: TLabel;
    Button1: TButton;
    Label4: TLabel;
    Lablevel: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  ProcessID: Thandle;
  ProcID: Thandle;
  Ghwnd: Thandle;
  Ecxi: Cardinal;
  r_level,r_hp,r_maxhp,r_mp,r_maxmp:Cardinal;
  r_Name:array[0..16] of WideChar;
  r_Name1:integer;
  const baseadr = $912BA4;  //一级基址

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  Num: Cardinal;
begin
  Ghwnd := FindWindow('QElementClient Window', 'Element Client');  //获取窗口
  if Ghwnd = 0 then
  begin
    ShowMessage('游戏未启动');
    Application.Terminate();
  end;
  GetWindowThreadProcessId(Ghwnd, ProcID);    //进程ID
  ProcessID := OpenProcess(PROCESS_ALL_ACCESS, False, ProcID);      // 进程句柄
  if ProcessID = 0 then
  begin
    showMessage('无法打开线程');
    Application.Terminate();
  end;
  ReadProcessMemory(ProcessID, Pointer(baseadr), @ECXI, 4, Num);
  ReadProcessMemory(ProcessID, Pointer(ECXI + $24), @ECXI, 4, Num);
  ReadProcessMemory(ProcessID, Pointer(ECXI + $25C), @r_HP, 4, Num);    //血
  ReadProcessMemory(ProcessID, Pointer(ECXI + $274), @r_MAXHP, 4, Num);  //血最大值
  ReadProcessMemory(ProcessID, Pointer(ECXI + $260), @r_mp, 4, Num);    //蓝
  ReadProcessMemory(ProcessID, Pointer(ECXI + $278), @r_maxmp, 4, Num);  //蓝最大值
  ReadProcessMemory(ProcessID, Pointer(ECXI + $250), @r_level, 4, Num);
  ReadProcessMemory(ProcessID, Pointer(ECXI + $398), @r_Name1, 4, Num);
  ReadProcessMemory(ProcessID, Pointer(r_Name1), @r_Name, 34, Num);
  labhp.Caption:=inttostr(r_hp)+'/'+inttostr(r_maxhp);
  labmp.Caption:=inttostr(r_mp)+'/'+inttostr(r_maxmp);
  lablevel.Caption:=inttostr(r_level)+'级';
  LabName.Caption := r_Name;
  CloseHandle(ProcessID);                    //关闭进程句柄
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
close;
end;

end.

posted @ 2011-05-12 10:29  星星的学习小志  阅读(382)  评论(0编辑  收藏  举报