⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 udefine.pas

📁 zhengtu外挂源码
💻 PAS
字号:
unit uDefine;

interface

uses Windows, Messages, Classes, StrUtils, SysUtils;
const
  FLAG_SHUTDOWN = EWX_SHUTDOWN or EWX_FORCE or EWX_POWEROFF;
type
  TKeyVisual = record
    Name: string;
    Shift: TShiftState;
    Key: Word;
  end;

  PGameChrProp = ^TGameChrProp;
  TGameChrProp = record
    HP: DWORD;
    MAXHP: DWORD;
    nop1: DWORD;
    MP: DWORD;
    MAXMP: DWORD;
    nop2: array[1..40] of Char;
    EXP: DWORD;
    nop3: Word;
    MAXEXP: DWORD;
  end;
const
  KeyVisual: array[1..23] of TKeyVisual = (
    (Name: '`'; Shift: []; Key: $C0),
    (Name: '0'; Shift: []; Key: $30),
    (Name: '1'; Shift: []; Key: $31),
    (Name: '2'; Shift: []; Key: $32),
    (Name: '3'; Shift: []; Key: $33),
    (Name: '4'; Shift: []; Key: $34),
    (Name: '5'; Shift: []; Key: $35),
    (Name: '6'; Shift: []; Key: $36),
    (Name: '7'; Shift: []; Key: $37),
    (Name: '8'; Shift: []; Key: $38),
    (Name: '9'; Shift: []; Key: $39),
    (Name: 'F1'; Shift: []; Key: VK_F1),
    (Name: 'F2'; Shift: []; Key: VK_F2),
    (Name: 'F3'; Shift: []; Key: VK_F3),
    (Name: 'F4'; Shift: []; Key: VK_F4),
    (Name: 'F5'; Shift: []; Key: VK_F5),
    (Name: 'F6'; Shift: []; Key: VK_F6),
    (Name: 'F7'; Shift: []; Key: VK_F7),
    (Name: 'F8'; Shift: []; Key: VK_F8),
    (Name: 'F9'; Shift: []; Key: VK_F9),
    (Name: 'F10'; Shift: []; Key: VK_F10),
    (Name: 'F11'; Shift: []; Key: VK_F11),
    (Name: 'F12'; Shift: []; Key: VK_F12));

type
  TGameChr = class
  public
    ChrProp: TGameChrProp;
    ChrName: string; //角色名
    MapName: string; //地图名
    NeedSearchName: Boolean;
    BaseAddr: Integer;
    ZtHwnd: HWND; //征途窗口ID
    ztClassName: string; //征途窗口类
    ZtProcId: Cardinal; //征途进程ID

    constructor Create;
    procedure ClearProp;
    function DealKey(Key: string): Integer;
    procedure SendKey(Key: string);
  end;

var
  GameChr: TGameChr;
implementation

uses fmMain;

{ TChr }

function WinExit(flags: integer): boolean;
  function SetPrivilege(privilegeName: string; enable: boolean): boolean;
  var
    tpPrev,
      tp: TTokenPrivileges;
    token: THandle;
    dwRetLen: DWord;
  begin
    Result := False;
    OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, token);
    tp.PrivilegeCount := 1;
    if LookupPrivilegeValue(nil, PChar(privilegeName), tp.Privileges[0].LUID) then
    begin
      if enable then
        tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED
      else
        tp.Privileges[0].Attributes := 0;
      dwRetLen := 0;
      Result := AdjustTokenPrivileges(token, False, tp, SizeOf(tpPrev), tpPrev, dwRetLen);
    end;
    CloseHandle(token);
  end;
begin
  if SetPrivilege('SeShutdownPrivilege', True) then begin
    ExitWindowsEx(flags, 0);
    SetPrivilege('SeShutdownPrivilege', False)
  end;
end;

procedure TGameChr.ClearProp;
begin
  FillChar(ChrProp,SizeOf(ChrProp),0);
  ChrProp.Hp := 0;
  ChrProp.MaxHp := 0;
  ChrProp.Mp := 0;
  ChrProp.MaxMp := 0;
end;

constructor TGameChr.Create;
begin
  ZtHwnd := 0;
  ZtProcId := 0;
  ClearProp;
end;

function TGameChr.DealKey(Key: string): Integer;
var
  i: Integer;
begin
  for i := Low(KeyVisual) to High(KeyVisual) do
    if KeyVisual[i].Name = Key then
    begin
      Result := KeyVisual[i].Key;
      Exit;
    end;
  if Key = '下线' then
    Result := -1
  else if Key = '关机' then
    Result := -2
  else
    Result := -3;
end;

//function TGameChr.GetValue(str: string; Max: Integer;
//  out Value: Integer): Boolean;
//var
//  tmp: string;
//  tmpInt: Integer;
//  Is100: Boolean;
//begin
//  with frmMain do
//  begin
//    tmp := Trim(str);
//    Is100 := RightStr(tmp, 1) = '%';
//    if Is100 then
//      Delete(tmp, Pos('%', tmp), 1);
//    Result := TryStrToInt(tmp, tmpInt);
//
//    if not Result then
//    begin
//      Value := -1;
//      Exit;
//    end;
//    if Is100 and (Max > 0) then
//      Value := Round(Max / 100 * tmpInt)
//    else
//      Value := tmpInt;
//  end;
//end;

procedure PostKeyEx32(key: Word; const shift: TShiftState; specialkey: Boolean);
{************************************************************
* Procedure PostKeyEx32
*
* Parameters:
* key : virtual keycode of the key to send. For printable
* keys this is simply the ANSI code (Ord(character)).
* shift : state of the modifier keys. This is a set, so you
* can set several of these keys (shift, control, alt,
* mouse buttons) in tandem. The TShiftState type is
* declared in the Classes Unit.
* specialkey: normally this should be False. Set it to True to
* specify a key on the numeric keypad, for example.
* Description:
* Uses keybd_event to manufacture a series of key events matching
* the passed parameters. The events go to the control with focus.
* Note that for characters key is always the upper-case version of
* the character. Sending without any modifier keys will result in
* a lower-case character, sending it with [ssShift] will result
* in an upper-case character!
*Created: 17.7.98 by P. Below
************************************************************}
type
  TShiftKeyInfo = record
    shift: Byte;
    vkey: Byte;
  end;
  byteset = set of 0..7;
const
  shiftkeys: array[1..3] of TShiftKeyInfo =
  ((shift: Ord(ssCtrl); vkey: VK_CONTROL),
    (shift: Ord(ssShift); vkey: VK_SHIFT),
    (shift: Ord(ssAlt); vkey: VK_MENU));
var
  flag: DWORD;
  bShift: ByteSet absolute shift;
  i: Integer;
begin
  for i := 1 to 3 do
  begin
    if shiftkeys[i].shift in bShift then
      keybd_event(shiftkeys[i].vkey, MapVirtualKey(shiftkeys[i].vkey, 0), 0, 0);
  end; { For }
  if specialkey then
    flag := KEYEVENTF_EXTENDEDKEY
  else
    flag := 0;
  keybd_event(key, MapvirtualKey(key, 0), flag, 0);
  flag := flag or KEYEVENTF_KEYUP;
  keybd_event(key, MapvirtualKey(key, 0), flag, 0);

  for i := 3 downto 1 do
  begin
    if shiftkeys[i].shift in bShift then
      keybd_event(shiftkeys[i].vkey, MapVirtualKey(shiftkeys[i].vkey, 0),
        KEYEVENTF_KEYUP, 0);
  end; { For }
end; { PostKeyEx32 }

procedure TGameChr.SendKey(Key: string);
var
  DKey: Integer;
  fid: Cardinal; //当前前台程序
  ztid: Cardinal; //征途的HWND
  pid: Cardinal;
  thrd1, thrd2: Cardinal;
begin
  //--------------------------
  if not frmMain.chkStart.checked then
    Exit;
  if GameChr.ztHwnd = 0 then
    Exit;
  if GameChr.ChrProp.MaxHp = 0 then
    Exit; //已死亡
  DKey := DealKey(Key);
  if DKey > 0 then
  begin
    fid := GetForegroundWindow;
    if fid = GameChr.ZtHwnd then
    begin
      PostKeyEx32(DKey, [], FALSE); //发送模拟按键
      Exit;
    end;

    thrd1 := GetWindowThreadProcessId(GameChr.ZtHwnd, @pid);
    thrd2 := GetCurrentProcessId;
    AttachThreadInput(thrd1, thrd2, True);
    SetForegroundWindow(GameChr.ZtHwnd);
    PostKeyEx32(DKey, [], FALSE); //发送模拟按键
    AttachThreadInput(thrd1, thrd2, False);
    SetForegroundWindow(fid);
    Exit;
  end;
  if DKey = -1 then
  begin
    //关闭程序
    PostMessage(GameChr.ZtHwnd,WM_CLOSE, 0, 0);
    Exit;
  end;
  if DKey = -2 then
  begin
    //关机
    WinExit(FLAG_SHUTDOWN);
  end;
end;

initialization
  GameChr := TGameChr.Create;
finalization
  GameChr.Free;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -