读取游戏数据

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.

转载于:https://www.cnblogs.com/94YY/archive/2011/05/12/2044085.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值