研究天龙八部(网游), 写了个辅助自动打怪、答题提示的辅助工具

来源:互联网 发布:ar拍照软件 编辑:程序博客网 时间:2024/04/30 19:32

  最近玩了玩天龙八部,玩这个游戏简直就是遭罪,升级非常慢,而且杀怪也很累,纯手工,我都不知道为什么还有那么多人玩。玩到40多级了,实在是受不了,游戏的颜色搭配也是非常的伤眼睛,于是我就想写一个自动打怪的辅助工具得了。

  接下来我就花了1天多的时间写了程序。有自动寻怪、自动加血、自动加蓝、自动释放技能、防外挂答题报警(利用Fetion发送短信到手机)。有了这个工具后我就可以挂上,关掉电脑,需要答题的时候就来答一下题。

附上主要代码(有需要代码邮件和我联系吧:pim@263.net):

  1. unit BackMainFrm;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, ExtCtrls, Menus, GlobalDefs, StdCtrls;
  6. type
  7.   TNumItem = record
  8.     StartCol: Byte;
  9.     EndCol: Byte;
  10.   end;
  11.   TNumItemAry = array of TNumItem;
  12.   TBackMainForm = class(TForm)
  13.     MainTray: TTrayIcon;
  14.     TrayMenu: TPopupMenu;
  15.     SysSetMenuItem: TMenuItem;
  16.     ExitSysMenuItem: TMenuItem;
  17.     N4: TMenuItem;
  18.     TimerFinder: TTimer;
  19.     procedure ExitSysMenuItemClick(Sender: TObject);
  20.     procedure SysSetMenuItemClick(Sender: TObject);
  21.     procedure FormCreate(Sender: TObject);
  22.     procedure TimerFinderTimer(Sender: TObject);
  23.     procedure FormDestroy(Sender: TObject);
  24.     procedure MainTrayClick(Sender: TObject);
  25.   private
  26.     FSCBitMap: TBitmap;
  27.     FNumBitMapAry: array[0..9of TBitmap;
  28.     FCurGamePos: TPoint;
  29.     FFightUnixTick: Cardinal;
  30.     FIsFighting: Boolean;
  31.     FIsNeedAnswerQT: Boolean;
  32.     FLastCalcAnswerUnixTick: Cardinal;
  33.     FLifeCurrent: Integer;
  34.     FMagicCurrent: Integer;
  35.     FBBLifeCurrent: Integer;
  36.     FPressF1UnixTick: Cardinal;
  37.     FPressF2UnixTick: Cardinal;
  38.     FPressF3UnixTick: Cardinal;
  39.     FPressF4UnixTick: Cardinal;
  40.     procedure CreateNumBitmapAry;
  41.     procedure LoadNumBitmapAry(const DirPath: string);
  42.     procedure DestroyNumBitmapAry;
  43.   private
  44.     procedure WMHotKey(var Message: TMessage); message WM_HOTKEY;
  45.     procedure RegisterHotKeys;
  46.     procedure InitializeLifeAndMagicColor;
  47.     procedure CalcCurrentPos;
  48.     procedure CalcFightState;
  49.     procedure CalcLifeAndMagic;
  50.     procedure CalcQuestionState;
  51.     procedure AutoPressMagicKeys;
  52.     function TranslateWinHotKeyToLocal(HotKeyValue: Cardinal): Word;
  53.     
  54.     procedure AnalyseNum(ABitmap: TBitmap; NumAry: TNumItemAry; List: TStringList);
  55.     procedure GetNumList(BitMap: TBitmap; var NumAry: TNumItemAry);
  56.   public
  57.   end;
  58.   TBeepThread = class(TThread)
  59.   private
  60.     FBeepSecs: Integer;
  61.     procedure SyncSendFetionMsg;
  62.   protected
  63.     procedure Execute; override;
  64.   public
  65.     constructor Create(BeepSecs: Integer);
  66.   end;
  67. procedure SendFetionMsg(const Msg: string);
  68. var
  69.   BackMainForm: TBackMainForm;
  70. implementation
  71. uses SystemSetFrm, BcConfigMgr, PisConfig, VirtualKeys, FetchWindow, Math,
  72.   DateUtils;
  73. {$R *.dfm}
  74. var
  75.   BeepThread: TBeepThread = nil;
  76. procedure SendFetionMsg(const Msg: string);
  77. begin
  78.   if FetionWindowHandle <> 0 then
  79.   begin
  80.     ShowWindow(FetionWindowHandle, SW_NORMAL);
  81.     SetForegroundWindow(FetionWindowHandle);
  82.     SendMessage(FetionInputHandle, WM_SETTEXT, 0, Integer(PChar(Msg)));
  83.     Sleep(20);
  84.     SendMessage(FetionSendBtnHandle, WM_LBUTTONDOWN, MK_LBUTTON, 0);
  85.     Sleep(10);
  86.     SendMessage(FetionSendBtnHandle, WM_LBUTTONUP, 00);
  87.     ShowWindow(FetionWindowHandle, SW_HIDE);
  88.   end;
  89. end;
  90. procedure TBackMainForm.GetNumList(BitMap: TBitmap; var NumAry: TNumItemAry);
  91.   procedure FetchStartCol(var LoopVar: Integer; BackColor: Integer);
  92.   var
  93.     J: Integer;
  94.   begin
  95.     while (LoopVar < BitMap.Width) do
  96.     begin
  97.       for J := 0 to BitMap.Height - 1 do
  98.       begin
  99.         //如果不是背景
  100.         if (BitMap.Canvas.Pixels[LoopVar, J] xor BackColor) <> 0 then
  101.         begin
  102.           Break;
  103.         end;
  104.       end;
  105.       //如果不是背景,则找到字符
  106.       if J < BitMap.Height then
  107.         Break;
  108.           
  109.       Inc(LoopVar);
  110.     end;
  111.   end;
  112.   procedure FetchEndCol(var LoopVar: Integer; BackColor: Integer);
  113.   var
  114.     J: Integer;
  115.   begin
  116.     while (LoopVar < BitMap.Width) do
  117.     begin
  118.       for J := 0 to BitMap.Height - 1 do
  119.       begin
  120.         //如果是字符
  121.         if (BitMap.Canvas.Pixels[LoopVar, J] xor BackColor) <> 0 then
  122.         begin
  123.           Break;
  124.         end;
  125.       end;
  126.       //如果不是字符,则找到背景
  127.       if J >= BitMap.Height then
  128.         Break;
  129.       Inc(LoopVar);
  130.     end;
  131.   end;
  132.     
  133. var
  134.   I: Integer;
  135.   BackColor: Integer;
  136.   StartCol, EndCol: Byte;
  137. begin
  138.   BackColor := BitMap.Canvas.Pixels[00];
  139.   I := 0;
  140.   while I < BitMap.Width do
  141.   begin
  142.     FetchStartCol(I, BackColor);
  143.     if I >= BitMap.Width then
  144.       Break;
  145.     StartCol := I;
  146.     FetchEndCol(I, BackColor);
  147.     if I >= BitMap.Width then
  148.       Break;
  149.     EndCol := I - 1;
  150.     SetLength(NumAry, Length(NumAry) + 1);
  151.     NumAry[High(NumAry)].StartCol := StartCol;
  152.     NumAry[High(NumAry)].EndCol := EndCol;
  153.   end;
  154. end;
  155. procedure TBackMainForm.InitializeLifeAndMagicColor;
  156. begin
  157.   if LifeColor = 0 then
  158.     LifeColor := FSCBitMap.Canvas.Pixels[LifeX, LifeY];
  159.   if MagicColor = 0 then
  160.     MagicColor := FSCBitMap.Canvas.Pixels[MagicX, MagicY];
  161.   BBLifeColor := LifeColor;
  162.   MonsterLifeColor := LifeColor;
  163. end;
  164. procedure TBackMainForm.AnalyseNum(ABitmap: TBitmap; NumAry: TNumItemAry;
  165.   List: TStringList);
  166.   function SameNum(const NumItem: TNumItem; Num: Integer): Boolean;
  167.   var
  168.     J, K: Integer;
  169.     RealWidth: Integer;
  170.     RefIsBgColor, IsBgColor: Boolean;
  171.     LRefBgColor, LBgColor: Integer;
  172.   begin
  173.     Result := True;
  174.     RealWidth := NumItem.EndCol - NumItem.StartCol + 1;
  175.     if RealWidth > FNumBitMapAry[Num].Width then
  176.       RealWidth := FNumBitMapAry[Num].Width;
  177.     LRefBgColor := FNumBitMapAry[0].Canvas.Pixels[00];
  178.     LBgColor := ABitmap.Canvas.Pixels[0,0];
  179.     for J := 0 to RealWidth - 1 do
  180.     begin
  181.       for K := 0 to 7 do
  182.       begin
  183.         RefIsBgColor := FNumBitMapAry[Num].Canvas.Pixels[J, K] = LRefBgColor;
  184.         IsBgColor := ABitmap.Canvas.Pixels[J + NumItem.StartCol, K] = LBgColor;
  185.         // 不相同退出
  186.         if RefIsBgColor xor IsBgColor = True then
  187.         begin
  188.           Result := False;
  189.           Exit;
  190.         end;
  191.       end;
  192.     end;
  193.   end;
  194.   function GetStringNum(const NumItem: TNumItem): string;
  195.   var
  196.     I: Integer;
  197.   begin
  198.     Result := '';
  199.     for I := 0 to 9 do
  200.     begin
  201.       if SameNum(NumItem, I) then
  202.       begin
  203.         Result := IntToStr(I);
  204.         Break;
  205.       end;
  206.     end;
  207.   end;
  208. var
  209.   I: Integer;
  210.   LNumStr, TmpStr: string;
  211. begin
  212.   LNumStr := '';
  213.   for I := 0 to High(NumAry) do
  214.   begin
  215.     TmpStr := GetStringNum(NumAry[I]);
  216.     if TmpStr <> '' then
  217.     begin
  218.       LNumStr := LNumStr + TmpStr;
  219.     end;
  220.     if I < High(NumAry) then
  221.     begin
  222.       if (NumAry[I+1].StartCol - NumAry[I].EndCol) > 8 then
  223.       begin
  224.         List.Add(LNumStr);
  225.         LNumStr := '';
  226.       end;
  227.     end;
  228.   end;
  229.   List.Add(LNumStr);
  230. end;
  231. procedure TBackMainForm.AutoPressMagicKeys;
  232. begin
  233.   if PressKeyF1Secs <> 0 then
  234.   begin
  235.     if (DateTimeToUnix(Now) - FPressF1UnixTick) > PressKeyF1Secs then
  236.     begin
  237.       MonitorKeyPress([], VK_F1);
  238.       FPressF1UnixTick := DateTimeToUnix(Now);
  239.       Sleep(10);
  240.     end;
  241.   end;
  242.   if PressKeyF2Secs <> 0 then
  243.   begin
  244.     if (DateTimeToUnix(Now) - FPressF2UnixTick) > PressKeyF2Secs then
  245.     begin
  246.       MonitorKeyPress([], VK_F2);
  247.       FPressF2UnixTick := DateTimeToUnix(Now);
  248.       Sleep(10);
  249.     end;
  250.   end;
  251.   if PressKeyF3Secs <> 0 then
  252.   begin
  253.     if (DateTimeToUnix(Now) - FPressF3UnixTick) > PressKeyF3Secs then
  254.     begin
  255.       MonitorKeyPress([], VK_F3);
  256.       FPressF3UnixTick := DateTimeToUnix(Now);
  257.       Sleep(10);
  258.     end;
  259.   end;
  260.   if PressKeyF4Secs <> 0 then
  261.   begin
  262.     if (DateTimeToUnix(Now) - FPressF4UnixTick) > PressKeyF4Secs then
  263.     begin
  264.       MonitorKeyPress([], VK_F4);
  265.       FPressF4UnixTick := DateTimeToUnix(Now);
  266.       Sleep(10);
  267.     end;
  268.   end;    
  269. end;
  270. procedure TBackMainForm.CalcCurrentPos;
  271. var
  272.   LBitMap: TBitmap;
  273.   NumAry: TNumItemAry;
  274.   StrList: TStringList;
  275. begin
  276.   LBitMap := TBitmap.Create;
  277.   StrList := TStringList.Create;
  278.   try
  279.     LBitMap.PixelFormat := pf24bit;
  280.     LBitMap.Width := 80;
  281.     LBitMap.Height := 8;
  282.     LBitMap.Canvas.CopyRect(Rect(00808), FSCBitMap.Canvas,
  283.       Rect(FSCBitMap.Width-11029, FSCBitMap.Width-3037));
  284.     GetNumList(LBitMap, NumAry);
  285.     if Length(NumAry) <= 0 then
  286.       Exit;
  287.     AnalyseNum(LBitMap, NumAry, StrList);
  288.     FCurGamePos.X := StrToInt(StrList[0]);
  289.     FCurGamePos.Y := StrToInt(StrList[1]);
  290.   finally
  291.     StrList.Free;
  292.     LBitMap.Free;
  293.   end;
  294. end;
  295. procedure TBackMainForm.CalcFightState;
  296. begin
  297.   FIsFighting :=
  298.     FSCBitMap.Canvas.Pixels[MonsterLifeX, MonsterLifeY] = MonsterLifeColor;
  299. end;
  300. procedure TBackMainForm.CalcLifeAndMagic;
  301. var
  302.   I: Integer;
  303. begin
  304.   // 初始化数据
  305.   InitializeLifeAndMagicColor;
  306.   // 计算生命
  307.   I := 0;
  308.   FLifeCurrent := 0;
  309.   while True do
  310.   begin
  311.     if GetRValue(FSCBitMap.Canvas.Pixels[LifeX+I, LifeY]) <> GetRValue(LifeColor) then
  312.       Break;
  313.     Inc(I);
  314.     Inc(FLifeCurrent);
  315.   end;
  316.   // 计算魔法
  317.   I := 0;
  318.   FMagicCurrent := 0;
  319.   while True do
  320.   begin
  321.     if GetBValue(FSCBitMap.Canvas.Pixels[MagicX+I, MagicY]) <> GetBValue(MagicColor) then
  322.       Break;
  323.     Inc(I);
  324.     Inc(FMagicCurrent);
  325.   end;
  326.   // 计算宝宝生命
  327.   I := 0;
  328.   FBBLifeCurrent := 0;
  329.   while True do
  330.   begin
  331.     if GetRValue(FSCBitMap.Canvas.Pixels[BBLifeX+I, BBLifeY]) <> GetRValue(BBLifeColor) then
  332.       Break;
  333.     Inc(I);
  334.     Inc(FBBLifeCurrent);
  335.   end;
  336. end;
  337. procedure TBackMainForm.CalcQuestionState;
  338.   // 判断颜色是否有效
  339.   function IsValidPoint(X, Y: Integer): Boolean;
  340.   var
  341.     AColor: TColor;
  342.   begin
  343.     AColor := FSCBitMap.Canvas.Pixels[X, Y];
  344.     Result := True;
  345.     Result := Result and (GetRValue(AColor) >= GetRValue(QT_MIN_COLOR));
  346.     Result := Result and (GetGValue(AColor) >= GetGValue(QT_MIN_COLOR));
  347.     Result := Result and (GetBValue(AColor) >= GetBValue(QT_MIN_COLOR));
  348.   end;
  349.   // 判断是否是问题窗口
  350.   function IsValidQuestion(X, Y: Integer): Boolean;
  351.   begin
  352.     Result := True;
  353.     Result := Result and IsValidPoint(X+QT_WIDTH, Y);
  354.     Result := Result and IsValidPoint(X, Y+QT_HEIGHT);
  355.     Result := Result and IsValidPoint(X+QT_WIDTH, Y+QT_HEIGHT);
  356.   end;
  357. var
  358.   I, J: Integer;
  359. begin
  360.   if (DateTimeToUnix(Now) - FLastCalcAnswerUnixTick) < 5 then
  361.     Exit;
  362.   // 记录最后计算时间
  363.   FLastCalcAnswerUnixTick := DateTimeToUnix(Now);
  364.   FIsNeedAnswerQT := False;
  365.   for I := 0 to (FSCBitMap.Width div 2) - 1 do
  366.   begin
  367.     for J := 0 to (FSCBitMap.Height div 2) - 1 do
  368.     begin
  369.       if IsValidPoint(I, J) then
  370.       begin
  371.         if IsValidQuestion(I, J) then
  372.         begin
  373.           FIsNeedAnswerQT := True;
  374.           Exit;
  375.         end;
  376.       end;
  377.     end;
  378.   end;
  379. end;
  380. procedure TBackMainForm.CreateNumBitmapAry;
  381. var
  382.   I: Integer;
  383. begin
  384.   for I := 0 to 9 do
  385.   begin
  386.     FNumBitMapAry[I] := TBitmap.Create;
  387.     FNumBitMapAry[I].PixelFormat := pf24bit;
  388.   end;
  389. end;
  390. procedure TBackMainForm.DestroyNumBitmapAry;
  391. var
  392.   I: Integer;
  393. begin
  394.   for I := 0 to 9 do
  395.   begin
  396.     FNumBitMapAry[I].Free;
  397.   end;
  398. end;
  399. procedure TBackMainForm.ExitSysMenuItemClick(Sender: TObject);
  400. begin
  401.   if Application.MessageBox('确实要退出?''提示信息',
  402.     MB_YESNO + MB_ICONQUESTION) = mrYes  then
  403.   begin
  404.     Application.Terminate;
  405.   end;
  406. end;
  407. procedure TBackMainForm.FormCreate(Sender: TObject);
  408.   procedure LoadConfig;
  409.   begin
  410.     FetionWindowIncText := ConfigMgr.FetionWindowText;
  411.     FetionWindowHandle := ConfigMgr.FetionWindowHandle;
  412.     FetionInputHandle := ConfigMgr.FetionInputWindowHandle;
  413.     FetionSendBtnHandle := ConfigMgr.FetionSendBtnWindowHandle;
  414.   end;
  415. begin
  416.   FSCBitMap := TBitmap.Create;
  417.   FFightUnixTick := 0;
  418.   Randomize;
  419.   MainTray.Hint := '天龙八部自助打怪 1.0';
  420.   LoadConfig;
  421.   CreateNumBitmapAry;
  422.   LoadNumBitmapAry('./DigitalImages/');
  423.   RegisterHotKeys;
  424.   FCurGamePos.X := 0;
  425.   FCurGamePos.Y := 0;
  426.   TimerFinder.Interval := FinderTimerMSec;
  427. end;
  428. procedure TBackMainForm.FormDestroy(Sender: TObject);
  429. begin
  430.   FSCBitMap.Free;
  431.   DestroyNumBitmapAry;
  432. end;
  433. procedure TBackMainForm.LoadNumBitmapAry(const DirPath: string);
  434. var
  435.   I: Integer;
  436. begin
  437.   for I := 0 to 9 do
  438.   begin
  439.     FNumBitMapAry[I].LoadFromFile(Format('%s%d.bmp', [DirPath, I]));
  440.   end;
  441. end;
  442. procedure TBackMainForm.MainTrayClick(Sender: TObject);
  443. begin
  444.   BackMainForm.Show;
  445. end;
  446. procedure TBackMainForm.RegisterHotKeys;
  447. var
  448.   GlobalId: Word;
  449.   AModifiers: Cardinal;
  450. begin
  451.   AModifiers := MOD_CONTROL + MOD_ALT;;
  452.   // 开关 CTRL + ALT + F10
  453.   GlobalId := GlobalAddAtom(PChar('HotKey_TLBBHelperF10'));
  454.   RegisterHotKey(Self.Handle, GlobalId, AModifiers, VK_F10);
  455.   // 设定原点 CTRL + ALT + F11
  456.   GlobalId := GlobalAddAtom(PChar('HotKey_TLBBHelperF11'));
  457.   RegisterHotKey(Self.Handle, GlobalId, AModifiers, VK_F11);
  458.   // 调出设定对话框 CTRL + ALT + F12
  459.   GlobalId := GlobalAddAtom(PChar('HotKey_TLBBHelperF12'));
  460.   RegisterHotKey(Self.Handle, GlobalId, AModifiers, VK_F12);
  461.   // 终止发送报警消息线程 CTRL + ALT + F1
  462.   GlobalId := GlobalAddAtom(PChar('HotKey_TLBBHelperF1'));
  463.   RegisterHotKey(Self.Handle, GlobalId, AModifiers, VK_F1);
  464.   // 发送Fetion测试包 CTRL + ALT + F1
  465.   GlobalId := GlobalAddAtom(PChar('HotKey_TLBBHelperF2'));
  466.   RegisterHotKey(Self.Handle, GlobalId, AModifiers, VK_F2);  
  467. end;
  468. procedure TBackMainForm.SysSetMenuItemClick(Sender: TObject);
  469. var
  470.   OldState: Boolean;
  471. begin
  472.   if TSystemSetForm.IsExist then Exit;
  473.   OldState := TimerFinder.Enabled;
  474.   TimerFinder.Enabled := False;
  475.   with TSystemSetForm.Create(Self) do
  476.   try
  477.     if ShowModal = mrOk then
  478.     begin
  479.       TimerFinder.Interval := FinderTimerMSec;
  480.     end;
  481.   finally
  482.     Free;
  483.   end;
  484.   TimerFinder.Enabled := OldState;
  485. end;
  486. procedure TBackMainForm.TimerFinderTimer(Sender: TObject);
  487.   procedure RandomFinderMonster;
  488.   var
  489.     X, Y: Integer;
  490.   begin
  491.     if FCurGamePos.X < CenterPosX then
  492.       X := RandomRange(FinderMinX, FinderMaxX)
  493.     else
  494.       X := RandomRange(-FinderMaxX, -FinderMinX);
  495.     if FCurGamePos.Y < CenterPosY then
  496.       Y := RandomRange(FinderMinY, FinderMaxY)
  497.     else
  498.       Y := RandomRange(-FinderMaxY, -FinderMinY);
  499.     X := Screen.Width div 2 + X;
  500.     Y := Screen.Height div 2 + Y;
  501.     MonitorMouseMove(X, Y);
  502.     Sleep(10);
  503.   end;
  504.   procedure FindMonster;
  505.   begin
  506.     // 寻找怪物
  507.     if not FIsFighting then
  508.     begin
  509.       FFightUnixTick := 0;
  510.       RandomFinderMonster;
  511.       MonitorMouseClick(1);
  512.     end else
  513.     begin
  514.       if FFightUnixTick  = 0 then
  515.         FFightUnixTick := DateTimeToUnix(Now)
  516.       else
  517.       begin
  518.         // 如果找怪超时,则重新寻找
  519.         if DateTimeToUnix(Now) - FFightUnixTick > 15 then
  520.         begin
  521.           // 随机移动位置(必须执行此操作,否则会死锁)
  522.           MonitorMouseMove(RandomRange(0, Screen.Width div 2),
  523.             RandomRange(0, Screen.Height div 2));
  524.           Sleep(10);
  525.           MonitorMouseClick(2);
  526.         end else
  527.         begin
  528.           // 释放魔法
  529.           AutoPressMagicKeys;
  530.         end;
  531.       end;
  532.     end;
  533.   end;
  534.   procedure FillLifeAndMagic;
  535.   begin
  536.     // 补人物血
  537.     if ((FLifeCurrent*100div LIFE_MAX) <= LifeMin then
  538.     begin
  539.       MonitorKeyPress([], KeyLifeAdd);
  540.     end;
  541.     Sleep(20);
  542.     // 补宝宝血
  543.     if ((FBBLifeCurrent*100div BB_LIFE_MAX) <= BBLifeMin then
  544.     begin
  545.       MonitorKeyPress([], KeyBBLifeAdd);
  546.     end;
  547.     Sleep(20);
  548.     // 补任务魔法
  549.     if ((FMagicCurrent*100div MAGIC_MAX) <= MagicMin then
  550.     begin
  551.       MonitorKeyPress([], KeyMagicAdd);
  552.     end;
  553.   end;
  554.   procedure PickGoods;
  555.   begin
  556.     // 一定要在没有打怪状态
  557.     if not FIsFighting then
  558.     begin
  559.       RandomFinderMonster;
  560.       MonitorMouseClick(2);
  561.       Sleep(10);
  562.     end;
  563.   end;
  564. begin
  565.   try
  566.     FetchWindowImage(FSCBitMap);
  567.     CalcFightState;
  568.     CalcCurrentPos;
  569.     CalcQuestionState;
  570.     CalcLifeAndMagic;
  571.     //PickGoods;(暂时不开启,有问题)
  572.     FindMonster;
  573.     Sleep(20);
  574.     FillLifeAndMagic;
  575.     // 启动报警程序
  576.     if FIsNeedAnswerQT and (BeepThread = nilthen
  577.       TBeepThread.Create(50).Resume;
  578.   except
  579.   end;
  580. end;
  581. function TBackMainForm.TranslateWinHotKeyToLocal(
  582.   HotKeyValue: Cardinal): Word;
  583. var
  584.   ALWord, AHWord: Word;
  585. begin
  586.   Result := 0;
  587.   AHWord := HiWord(HotKeyValue);
  588.   ALWord := HotKeyValue and $FFFF;
  589.   if ALWord and MOD_SHIFT <> 0 then
  590.     Result := Result + scShift;
  591.   if ALWord and MOD_ALT <> 0 then
  592.     Result := Result + scAlt;
  593.   if ALWord and MOD_CONTROL <> 0 then
  594.     Result := Result + scCtrl;
  595.   Result := Result + AHWord;
  596. end;
  597. procedure TBackMainForm.WMHotKey(var Message: TMessage);
  598. var
  599.   LocalKey: Word;
  600. begin
  601.   LocalKey := TranslateWinHotKeyToLocal(Message.LParam);
  602.   if LocalKey = scCtrl + scAlt + VK_F10 then
  603.   begin
  604.     // 系统开关
  605.     TimerFinder.Enabled := not TimerFinder.Enabled;
  606.     Windows.Beep(3000100);
  607.   end else if LocalKey = scCtrl + scAlt + VK_F11 then
  608.   begin
  609.     // 设置原点
  610.     FetchWindowImage(FSCBitMap);
  611.     CalcCurrentPos;
  612.     
  613.     CenterPosX := FCurGamePos.X;
  614.     CenterPosY := FCurGamePos.Y;
  615.     Windows.Beep(2000100);
  616.     Windows.Beep(2500100);
  617.   end else if LocalKey = scCtrl + scAlt + VK_F12 then
  618.   begin
  619.     // 调出设置框
  620.     SysSetMenuItemClick(nil);
  621.   end else if LocalKey = scCtrl + scAlt + VK_F1 then
  622.   begin
  623.     // 关闭线程
  624.     try
  625.       if Assigned(BeepThread) then
  626.       begin
  627.         BeepThread.Terminate;
  628.       end;
  629.     except
  630.     end;
  631.   end else if LocalKey = scCtrl + scAlt + VK_F2 then
  632.   begin
  633.     SendFetionMsg('天龙八部助手测试!');
  634.   end;
  635. end;
  636. { TBeepThread }
  637. constructor TBeepThread.Create(BeepSecs: Integer);
  638. begin
  639.   inherited Create(True);
  640.   FreeOnTerminate := True;
  641.   FBeepSecs := BeepSecs;
  642.   // 记录自己
  643.   BeepThread := Self;
  644. end;
  645. procedure TBeepThread.Execute;
  646. var
  647.   StartUnixTick: Cardinal;
  648. begin
  649.   StartUnixTick := DateTimeToUnix(Now);
  650.   SyncSendFetionMsg;
  651.   while not Terminated do
  652.   begin
  653.     if DateTimeToUnix(now) - StartUnixTick > FBeepSecs then
  654.       Break;
  655.     Windows.Beep(4000300);
  656.     Sleep(700);
  657.   end;
  658.   BeepThread := nil;
  659. end;
  660. procedure TBeepThread.SyncSendFetionMsg;
  661. begin
  662.   SendFetionMsg('TLBBHelper: 需要输入验证码!');
  663. end;
  664. end.

 

  1. unit GlobalDefs;
  2. interface
  3. uses
  4.   Windows;
  5. { 相关配置参数 }
  6. const
  7.   LIFE_MAX        = 124;
  8.   MAGIC_MAX       = 124;
  9.   BB_LIFE_MAX     = 96;
  10.   QT_MIN_COLOR = $FAFAFA;
  11.   QT_WIDTH = 237;
  12.   QT_HEIGHT = 298;
  13. var
  14.   FinderTimerMSec: Integer = 200;     // 系统Timer执行时间
  15.   LifeX: Integer = 64;                // 人物生命值X坐标
  16.   LifeY: Integer = 32;                // 人物生命值Y坐标
  17.   LifeColor: Integer = 0;             // 人物生命值取样颜色(加载时初始化)
  18.   LifeMin: Integer = 50;              // 人物生命最小百分比
  19.   MagicX: Integer = 64;               // 人物魔法值X坐标
  20.   MagicY: Integer = 38;               // 人物魔法值Y坐标
  21.   MagicColor: Integer = 0;            // 人物魔法值取样颜色(加载时初始化)
  22.   MagicMin: Integer = 50;             // 人物魔法最小百分比
  23.   BBLifeX: Integer = 91;              // 宝宝生命值X坐标
  24.   BBLifeY: Integer = 71;              // 宝宝生命值Y坐标
  25.   BBLifeColor: Integer = 0;           // 宝宝生命值取样颜色(加载时初始化)
  26.   BBLifeMin: Integer = 30;            // 宝宝生命最小百分比
  27.   MonsterLifeX: Integer = 247;        // 怪物生命值X坐标
  28.   MonsterLifeY: Integer = 32;         // 怪物生命值Y坐标
  29.   MonsterLifeColor: Integer = 0;      // 怪物生命值取样颜色(加载时初始化)
  30.   CenterPosX: Integer = 185;          // 自动打怪中心位置X坐标
  31.   CenterPosY: Integer = 215;          // 自动打怪中心位置Y坐标
  32.   FinderMaxX: Integer = 100;          // 自动打怪寻怪X轴距离最大值
  33.   FinderMinX: Integer = 30;           // 自动打怪寻怪X轴距离最小值
  34.   FinderMaxY: Integer = 100;          // 自动打怪寻怪Y轴距离最大值
  35.   FinderMinY: Integer = 30;           // 自动打怪寻怪Y轴距离最小值
  36.   AvgKillMonsterSecs: Integer = 15;   // 平均每个怪的打怪时间(校正用)
  37.   KeyLifeAdd: Word = VK_F8;           // 人物加血键
  38.   KeyMagicAdd: Word = VK_F9;          // 人物加魔法键
  39.   KeyBBLifeAdd: Word = VK_F10;        // 宝宝加血键
  40.   PressKeyF1Secs: Integer = 10;       // 自动按F1键时间间隔
  41.   PressKeyF2Secs: Integer = 15;       // 自动按F2键时间间隔
  42.   PressKeyF3Secs: Integer = 40;       // 自动按F3键时间间隔
  43.   PressKeyF4Secs: Integer = 0;        // 自动按F4键时间间隔
  44.   FetionWindowHandle: Integer = 0;
  45.   FetionWindowIncText: string = '--';
  46.   FetionInputHandle: Integer = 0;
  47.   FetionSendBtnHandle: Integer = 0;
  48. implementation
  49. end.
原创粉丝点击