SRL Archive - Delphi/FPC Help and Tutorials

Delphi MMouse/WindMouse


Cazax

2009-03-24 20:08:49

MMouse/WindMouse for Delphi…
procedure WindMouse(xs, ys, xe, ye, gravity, wind, minWait, maxWait, maxStep, targetArea: extended);
var
veloX, veloY, windX, windY, veloMag, dist, randomDist, lastDist, step: extended;
lastX, lastY: integer;
sqrt2, sqrt3, sqrt5: extended;
begin
veloX := 0.0;
veloY := 0.0;
windx := 0.0;
windy := 0.0;
velomag := 0.0;
dist := 0.0;
randomdist := 0.0;
lastdist := 0.0;
step := 0.0;
sqrt2:= sqrt(2);
sqrt3:= sqrt(3);
sqrt5:= sqrt(5);
while hypot(xs - xe, ys - ye) > 1 do
begin
dist:= hypot(xs - xe, ys - ye);
wind:= min(wind, dist);
if dist >= targetArea then
begin
windX:= windX / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
windY:= windY / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
end else
begin
windX:= windX / sqrt2;
windY:= windY / sqrt2;
if (maxStep < 3) then
begin
maxStep:= random(3) + 3.0;
end else
begin
maxStep:= maxStep / sqrt5;
end;
end;
veloX:= veloX + windX;
veloY:= veloY + windY;
veloX:= veloX + gravity * (xe - xs) / dist;
veloY:= veloY + gravity * (ye - ys) / dist;
if hypot(veloX, veloY) > maxStep then
begin
randomDist:= maxStep / 2.0 + random(round(round(maxStep) / 2));
veloMag:= sqrt(veloX * veloX + veloY * veloY);
veloX:= (veloX / veloMag) * randomDist;
veloY:= (veloY / veloMag) * randomDist;
end;
lastX:= Round(xs);
lastY:= Round(ys);
xs:= xs + veloX;
ys:= ys + veloY;
if (lastX <> Round(xs)) or (lastY <> Round(ys)) then
SetCursorPos(Round(xs), Round(ys));
step:= hypot(xs - lastX, ys - lastY);
wait(round((maxWait - minWait) * (step / maxStep) + minWait));
lastdist:= dist;
end;
if (Round(xe) <> Round(xs)) or (Round(ye) <> Round(ys)) then
SetCursorPos(Round(xe), Round(ye));
end;

procedure MMouse(x, y, rx, ry: integer);
var
cx, cy: integer;
tp : tpoint;
randSpeed: extended;
begin
randSpeed:= (random(MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
if randSpeed = 0.0 then
randSpeed := 0.1;
getCursorPos(tp);
cx := tp.x;
cy := tp.y;
X := x + random(rx);
Y := y + random(ry);
WindMouse(cx,cy,x,y,9.0,3.0,10.0/randSpeed,15.0/randSpeed,10.0*randSpeed,10.0*randSpeed);
end;
Just remember to declare MouseSpeed as Integer
I have a project full of RS/SRL functions if anyone is interested on making rs bots with Delphi

_ChArMz

2009-03-24 20:50:15

post em all

cuz all you added was SetCursorPos and GetCursorPos, and set some values equal to zero so it would compile :P

Cazax

2009-03-24 21:06:24


var
MouseSpeed, AllocationSize : Integer;

const
MMX1 = 550;
MMY1 = 8;
MMX2 = 703;
MMY2 = 161;

{ const MMCX, MMCY;
Description: MiniMap Centre Point. }
const
MMCX = 627;
MMCY = 85;

{ const MSX1, MSY1, MSX2, MSY2;
Description: Main Screen EdgePoints. }
const
MSX1 = 4;
MSY1 = 4;
MSX2 = 516;
MSY2 = 338;

{ const MSCX, MSCY;
Description: Main Screen Centre Points. }
const
MSCX = 259;
MSCY = 170;

{ const MIX1, MIY1, MIX2, MIY2;
Description: Inventory EdgePoints. }
const
MIX1 = 547;
MIY1 = 202;
MIX2 = 737;
MIY2 = 466;

{ const MICX, MICY;
Description: Inventory Centre Points. }
const
MICX = 642;
MICY = 334;

{ const MCX1, MCY1, MCX2, MCY2;
Description: Chat Screen EdgePoints. }
const
MCX1 = 4;
MCY1 = 342;
MCX2 = 496;
MCY2 = 460;

{ const MCCX, MCCY;
Description: Chat Screen Centre Points. }
const
MCCX = 250;
MCCY = 401;

procedure Wait(Ms: Cardinal); //by: Freddy1990
var
t: Cardinal;
begin
t := GetTickCount;
while (t + Ms) > GetTickCount do
Application.ProcessMessages;
end;

function SimilarColors(Color1, Color2, Tolerance: Integer): Boolean; //By: Freddy1990
begin
Result := ((Abs((Color1 and $ff) - (Color2 and $ff)) <= Tolerance) and
(Abs(((Color1 and $ff00) shr 8) - ((Color2 and $ff00) shr 8)) <= Tolerance) and
(Abs(((Color1 and $ff0000) shr 16) - ((Color2 and $ff0000) shr 16)) <= Tolerance));
end;

type TPointArray = Array Of TPoint;

function FindColorsTolerance(var TPA : TPointArray; Color, xs, ys, xe, ye, Tolerance: Integer; Window: Hwnd): Boolean; //By Freddy1990
var
Bmp: TBitmap; // Bitmap of the client
tmpDC: HDC; // Device context of the client's window handle
Size: TRect; // Rect(angle) of the client's window
cx, cy: Integer; // For-loop vars
Line: PRGB32Array; // The scanline
begin
Result := False; // In case the color isn't found => Result = False
Bmp := TBitmap.Create; // We create our bitmap instance
tmpDC := GetWindowDC(Window); // We get the device context of the client's window handle
GetWindowRect(Window, Size); // We get the rect(angle) of the client's window
Bmp.Width := Size.Right - Size.Left; // We set the width of our bitmap
Bmp.Height := Size.Bottom - Size.Top; // We set the height of our bitmap
BitBlt(Bmp.Canvas.Handle, 0, 0, Bmp.Width, Bmp.Height, tmpDC, 0, 0, SRCCOPY);
// ^^^ We copy the client's canvas onto the bitmap
Bmp.PixelFormat := pf32bit; // We set the bitmap to 32bits
DeleteDC(tmpDC); // We delete the device context to avoid memory leakage
for cy := ys to ye do // Loop for the rows of pixels (y)
begin
if cy >= Bmp.Height then Break; // Break the loop if you reach the end of the bitmap
Line := Bmp.ScanLine[cy]; // We retrieve the scanline (line of pixels) from the bitmap for the current y
for cx := xs to xe do // Loop for the colums of pixels (x)
begin
if cx >= Bmp.Width then Break; // Break the loop if you reach the end of the bitmap
if (SimilarColors(RGB(Line[cx].R, Line[cx].G, Line[cx].B), Color, Tolerance)) then
// ^^^ We convert the RGB values of the current pixel to a color and compare it with the tolerance to the entered color
begin // If the color is similar (or for tol 0 the same) then...
Result := True; // Result of the function
SetLength(TPA, Length(TPA) + 1);
TPA[High(TPA)].X := cx; // Returned x-value
TPA[High(TPA)].Y := cy; // Returned y-value
end;
end;
end;
Line := nil; // Free the scanline to avoid memory leaks
Bmp.Free; // Free the bitmap to avoid memory leaks
end;

function GetColor(x, y: Integer; Handle: Cardinal): TColor;//By Freddy1990
var DC: HDC;
begin
DC := GetWindowDC(Handle);
result := TColor(GetPixel(DC, x, y));
ReleaseDC(Handle, DC);
end;

procedure Mouse(X, Y, Rx, Ry : Integer; Left : Boolean);//By SRL
var
p : TPoint;
begin
MMouse(X, Y, Rx, Ry);
wait(100 + Random(100));
getcursorpos(p);
If Left Then
Mouse_Event(MOUSEEVENTF_LEFTDOWN, p.X, p.Y, 0, 0)
Else
Mouse_Event(MOUSEEVENTF_RIGHTDOWN, p.X, p.Y, 0, 0);
wait(100 + Random(100));
If Left Then
Mouse_Event(MOUSEEVENTF_LEFTUP, p.X, p.Y, 0, 0)
Else
Mouse_Event(MOUSEEVENTF_RIGHTUP, p.X, p.Y, 0, 0);
end;

function GetPage(site: string): WideString; //By RsN
var
ie, fh: HINTERNET;
lpBuffer: array[0..1024+1] of Char;
dwBytesRead: DWORD;
begin
ie := InternetOpen('Client', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
fh := InternetOpenUrl(ie, PChar(site), nil, 0,
INTERNET_FLAG_RELOAD, 0);
if Assigned(fh) then
while True do
begin
dwBytesRead := 1024;
Application.ProcessMessages;
InternetReadFile(fh, @lpBuffer, 1024, dwBytesRead);
if dwBytesRead = 0 then
Break;
lpBuffer[dwBytesRead] := #0;
Application.ProcessMessages;
Result:= Result + lpBuffer;
end;
InternetCloseHandle(fh);
InternetCloseHandle(ie)
end;

function AppActivate(WindowHandle : HWND) : boolean;/By RsN
result := SetForegroundWindow(WindowHandle);
except
on Exception do Result:=false;
end;
end;

procedure StealRS2(wHandle: Hwnd); //By Freddy1990
var
RSHwnd, RSSunJava, RSSunJava6: Hwnd;
begin
RSHwnd := FindWindowEx(wHandle, 0, 'shell embedding', nil);
RSHwnd := FindWindowEx(RSHwnd, 0, 'shell docobject view', nil);
RSHwnd := FindWindowEx(RSHwnd, 0, 'internet explorer_server', nil);
RSSunJava := FindWindowEx(RSHwnd, 0, 'Java Plug-in Control Window', nil);
RSSunJava6 := FindWindowEx(RSSunJava, 0, 'SunAwtFrame', nil);
RSSunJava := FindWindowEx(RSSunJava, 0, 'sun.plugin.viewer.frame.IExplorerEmbeddedFrame', nil);
RSHwnd := FindWindowEx(RSHwnd, 0, 'microsoft vm for java(tm) host window class', nil);
RSHwnd := FindWindowEx(RSHwnd, 0, 'msawt_comp_class', nil);
if (RSSunJava = 0) then RSSunJava := RSSunJava6;
if (RSHwnd = 0) then RSHwnd := RSSunJava;
if (RSHwnd = 0) then Exit;
SetParent(RSHwnd, wHandle);
SetWindowPos(RSHwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOOWNERZORDER or SWP_NOSIZE);
end;

function GetCurrentTab: Integer;//SRL
var
i: Integer;
b: Boolean;
begin
b := False;
Result := 0;
for i := 1 to 15 do
begin
case i of
1: b := (GetColor(543, 178, ClientHandle) = 1580634);
2: b := (GetColor(570, 179, ClientHandle) = 1778795);
3: b := (GetColor(604, 174, ClientHandle) = 1910385);
4: b := (GetColor(632, 172, ClientHandle) = 1910385);
5: b := (GetColor(666, 182, ClientHandle) = 1647204);
6: b := (GetColor(699, 177, ClientHandle) = 1910385);
7: b := (GetColor(735, 177, ClientHandle) = 1778795);
8: b := (GetColor(569, 471, ClientHandle) = 1910385);
9: b := (GetColor(598, 471, ClientHandle) = 1910385);
10: b := (GetColor(633, 478, ClientHandle) = 1778795);
11: b := (GetColor(668, 476, ClientHandle) = 1778795);
12: b := (GetColor(703, 481, ClientHandle) = 1580634);
13: b := (GetColor(740, 471, ClientHandle) = 1778795);
14: b := (GetColor(555, 275, ClientHandle) = 2070783);
15: b := (GetColor(533, 475, ClientHandle) = 1581150);
end;
if b then
begin
Result := i;
Exit;
end;
end;
end;

function TabExists(TabNumber: Integer): Boolean;//SRL
begin
Result := False;
case TabNumber of
1: Result := (GetColor(533, 177, ClientHandle) = 65536);
2: Result := (GetColor(565, 175, ClientHandle) = 65536);
3: Result := (GetColor(609, 175, ClientHandle) = 1052432);
4: Result := (GetColor(638, 174, ClientHandle) = 65536);
5: Result := (GetColor(670, 176, ClientHandle) = 65536);
6: Result := (GetColor(708, 171, ClientHandle) = 65536);
7: Result := (GetColor(740, 175, ClientHandle) = 65536);
8: Result := (GetColor(575, 474, ClientHandle) = 65536);
9: Result := (GetColor(605, 474, ClientHandle) = 65536);
10: Result := (GetColor(640, 472, ClientHandle) = 65536);
11: Result := (GetColor(680, 472, ClientHandle) = 65536);
12: Result := (GetColor(710, 470, ClientHandle) = 65536);
13: Result := (GetColor(735, 473, ClientHandle) = 65536);
14: Result := (GetColor(743, 1, ClientHandle) = 65536);
15: Result := (GetColor(537, 477, ClientHandle) = 65536);
end;
end;

function GameTab(tabnumber: Integer): Boolean;//SRL
var
c: Integer;
Coords: TPoint;
begin
C := 0;
if (tabnumber = 14) then
Coords := Point(752, 12)
else if (tabnumber = 15) then
Coords := Point(538, 485)
else if (tabnumber <= 7) then
Coords := Point(540 + ((tabnumber -1) * 33), 185)
else
Coords := Point(540 + ((tabnumber mod 7) * 33), 485);
while not(GetCurrentTab = tabnumber) and (c < 4) do
Begin
Mouse(Coords.x, Coords.y, 8, 8, true);
Inc(c);
end;
Result := (GetCurrentTab = tabnumber);
end;

Function SendKeys(SendKeysString : PChar; Wait : Boolean) : Boolean;//by unknown
type
WBytes = array[0..pred(SizeOf(Word))] of Byte;

TSendKey = record
Name : ShortString;
VKey : Byte;
end;

const
{Array of keys that SendKeys recognizes.

If you add to this list, you must be sure to keep it sorted alphabetically
by Name because a binary search routine is used to scan it.}

MaxSendKeyRecs = 41;
SendKeyRecs : array[1..MaxSendKeyRecs] of TSendKey =
(
(Name:'BACKSPACE'; VKey:VK_BACK),
(Name:'BKSP'; VKey:VK_BACK),
(Name:'BREAK'; VKey:VK_CANCEL),
(Name:'BS'; VKey:VK_BACK),
(Name:'CAPSLOCK'; VKey:VK_CAPITAL),
(Name:'CLEAR'; VKey:VK_CLEAR),
(Name:'DEL'; VKey:VK_DELETE),
(Name:'DELETE'; VKey:VK_DELETE),
(Name:'DOWN'; VKey:VK_DOWN),
(Name:'END'; VKey:VK_END),
(Name:'ENTER'; VKey:VK_RETURN),
(Name:'ESC'; VKey:VK_ESCAPE),
(Name:'ESCAPE'; VKey:VK_ESCAPE),
(Name:'F1'; VKey:VK_F1),
(Name:'F10'; VKey:VK_F10),
(Name:'F11'; VKey:VK_F11),
(Name:'F12'; VKey:VK_F12),
(Name:'F13'; VKey:VK_F13),
(Name:'F14'; VKey:VK_F14),
(Name:'F15'; VKey:VK_F15),
(Name:'F16'; VKey:VK_F16),
(Name:'F2'; VKey:VK_F2),
(Name:'F3'; VKey:VK_F3),
(Name:'F4'; VKey:VK_F4),
(Name:'F5'; VKey:VK_F5),
(Name:'F6'; VKey:VK_F6),
(Name:'F7'; VKey:VK_F7),
(Name:'F8'; VKey:VK_F8),
(Name:'F9'; VKey:VK_F9),
(Name:'HELP'; VKey:VK_HELP),
(Name:'HOME'; VKey:VK_HOME),
(Name:'INS'; VKey:VK_INSERT),
(Name:'LEFT'; VKey:VK_LEFT),
(Name:'NUMLOCK'; VKey:VK_NUMLOCK),
(Name:'PGDN'; VKey:VK_NEXT),
(Name:'PGUP'; VKey:VK_PRIOR),
(Name:'PRTSC'; VKey:VK_PRINT),
(Name:'RIGHT'; VKey:VK_RIGHT),
(Name:'SCROLLLOCK'; VKey:VK_SCROLL),
(Name:'TAB'; VKey:VK_TAB),
(Name:'UP'; VKey:VK_UP)
);

{Extra VK constants missing from Delphi's Windows API interface}
VK_NULL=0;
VK_SemiColon=186;
VK_Equal=187;
VK_Comma=188;
VK_Minus=189;
VK_Period=190;
VK_Slash=191;
VK_BackQuote=192;
VK_LeftBracket=219;
VK_BackSlash=220;
VK_RightBracket=221;
VK_Quote=222;
VK_Last=VK_Quote;

ExtendedVKeys : set of byte =
[VK_Up,
VK_Down,
VK_Left,
VK_Right,
VK_Home,
VK_End,
VK_Prior, {PgUp}
VK_Next, {PgDn}
VK_Insert,
VK_Delete];

const
INVALIDKEY = $FFFF {Unsigned -1};
VKKEYSCANSHIFTON = $01;
VKKEYSCANCTRLON = $02;
VKKEYSCANALTON = $04;
UNITNAME = 'SendKeys';
var
UsingParens, ShiftDown, ControlDown, AltDown, FoundClose : Boolean;
PosSpace : Byte;
I, L : Integer;
NumTimes, MKey : Word;
KeyString : String[20];

procedure DisplayMessage(Message : PChar);
begin
MessageBox(0,Message,UNITNAME,0);
end;

function BitSet(BitTable, BitMask : Byte) : Boolean;
begin
Result:=ByteBool(BitTable and BitMask);
end;

procedure SetBit(var BitTable : Byte; BitMask : Byte);
begin
BitTable:=BitTable or Bitmask;
end;

Procedure KeyboardEvent(VKey, ScanCode : Byte; Flags : Longint);
var
KeyboardMsg : TMsg;
begin
keybd_event(VKey, ScanCode, Flags,0);
If (Wait) then While (PeekMessage(KeyboardMsg,0,WM_KEYFIRST, WM_KEYLAST, PM_REMOVE)) do begin
TranslateMessage(KeyboardMsg);
DispatchMessage(KeyboardMsg);
end;
end;

Procedure SendKeyDown(VKey: Byte; NumTimes : Word; GenUpMsg : Boolean);
var
Cnt : Word;
ScanCode : Byte;
NumState : Boolean;
KeyBoardState : TKeyboardState;
begin
If (VKey=VK_NUMLOCK) then begin
NumState:=ByteBool(GetKeyState(VK_NUMLOCK) and 1);
GetKeyBoardState(KeyBoardState);
If NumState then KeyBoardState[VK_NUMLOCK]:=(KeyBoardState[VK_NUMLOCK] and not 1)
else KeyBoardState[VK_NUMLOCK]:=(KeyBoardState[VK_NUMLOCK] or 1);
SetKeyBoardState(KeyBoardState);
exit;
end;

ScanCode:=Lo(MapVirtualKey(VKey,0));
For Cnt:=1 to NumTimes do
If (VKey in ExtendedVKeys)then begin
KeyboardEvent(VKey, ScanCode, KEYEVENTF_EXTENDEDKEY);
If (GenUpMsg) then
KeyboardEvent(VKey, ScanCode, KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP)
end else begin
KeyboardEvent(VKey, ScanCode, 0);
If (GenUpMsg) then KeyboardEvent(VKey, ScanCode, KEYEVENTF_KEYUP);
end;
end;

Procedure SendKeyUp(VKey: Byte);
var
ScanCode : Byte;
begin
ScanCode:=Lo(MapVirtualKey(VKey,0));
If (VKey in ExtendedVKeys)then
KeyboardEvent(VKey, ScanCode, KEYEVENTF_EXTENDEDKEY and KEYEVENTF_KEYUP)
else KeyboardEvent(VKey, ScanCode, KEYEVENTF_KEYUP);
end;

Procedure SendKey(MKey: Word; NumTimes : Word; GenDownMsg : Boolean);
begin
If (BitSet(Hi(MKey),VKKEYSCANSHIFTON)) then SendKeyDown(VK_SHIFT,1,False);
If (BitSet(Hi(MKey),VKKEYSCANCTRLON)) then SendKeyDown(VK_CONTROL,1,False);
If (BitSet(Hi(MKey),VKKEYSCANALTON)) then SendKeyDown(VK_MENU,1,False);
SendKeyDown(Lo(MKey), NumTimes, GenDownMsg);
If (BitSet(Hi(MKey),VKKEYSCANSHIFTON)) then SendKeyUp(VK_SHIFT);
If (BitSet(Hi(MKey),VKKEYSCANCTRLON)) then SendKeyUp(VK_CONTROL);
If (BitSet(Hi(MKey),VKKEYSCANALTON)) then SendKeyUp(VK_MENU);
end;

{Implements a simple binary search to locate special key name strings}

Function StringToVKey(KeyString : ShortString) : Word;
var
Found, Collided : Boolean;
Bottom, Top, Middle : Byte;
begin
Result:=INVALIDKEY;
Bottom:=1;
Top:=MaxSendKeyRecs;
Found:=false;
Middle:=(Bottom+Top) div 2;
Repeat
Collided:=((Bottom=Middle) or (Top=Middle));
If (KeyString=SendKeyRecs[Middle].Name) then begin
Found:=True;
Result:=SendKeyRecs[Middle].VKey;
end else begin
If (KeyString>SendKeyRecs[Middle].Name) then Bottom:=Middle
else Top:=Middle;
Middle:=(Succ(Bottom+Top)) div 2;
end;
Until (Found or Collided);
If (Result=INVALIDKEY) then DisplayMessage('Invalid Key Name');
end;

procedure PopUpShiftKeys;
begin
If (not UsingParens) then begin
If ShiftDown then SendKeyUp(VK_SHIFT);
If ControlDown then SendKeyUp(VK_CONTROL);
If AltDown then SendKeyUp(VK_MENU);
ShiftDown:=false;
ControlDown:=false;
AltDown:=false;
end;
end;

begin
AllocationSize:=MaxInt;
Result:=false;
UsingParens:=false;
ShiftDown:=false;
ControlDown:=false;
AltDown:=false;
I:=0;
L:=StrLen(SendKeysString);
If (L>AllocationSize) then L:=AllocationSize;
If (L=0) then Exit;

While (I<L) do begin
case SendKeysString[I] of
'(' : begin
UsingParens:=True;
Inc(I);
end;
')' : begin
UsingParens:=False;
PopUpShiftKeys;
Inc(I);
end;
'%' : begin
AltDown:=True;
SendKeyDown(VK_MENU,1,False);
Inc(I);
end;
'+' : begin
ShiftDown:=True;
SendKeyDown(VK_SHIFT,1,False);
Inc(I);
end;
'^' : begin
ControlDown:=True;
SendKeyDown(VK_CONTROL,1,False);
Inc(I);
end;
'{' : begin
NumTimes:=1;
If (SendKeysString[Succ(I)]='{') then begin
MKey:=VK_LEFTBRACKET;
SetBit(Wbytes(MKey)[1],VKKEYSCANSHIFTON);
SendKey(MKey,1,True);
PopUpShiftKeys;
Inc(I,3);
Continue;
end;
KeyString:='';
FoundClose:=False;
While (I<=L) do begin
Inc(I);
If (SendKeysString[I]='}') then begin
FoundClose:=True;
Inc(I);
Break;
end;
KeyString:=KeyString+Upcase(SendKeysString[I]);
end;
If (Not FoundClose) then begin
DisplayMessage('No Close');
Exit;
end;
If (SendKeysString[I]='}') then begin
MKey:=VK_RIGHTBRACKET;
SetBit(Wbytes(MKey)[1],VKKEYSCANSHIFTON);
SendKey(MKey,1,True);
PopUpShiftKeys;
Inc(I);
Continue;
end;
PosSpace:=Pos(' ',KeyString);
If (PosSpace<>0) then begin
NumTimes:=StrToInt(Copy(KeyString,Succ(PosSpace),Length(KeyString)-PosSpace));
KeyString:=Copy(KeyString,1,Pred(PosSpace));
end;
If (Length(KeyString)=1) then MKey:=vkKeyScan(KeyString[1])
else MKey:=StringToVKey(KeyString);
If (MKey<>INVALIDKEY) then begin
SendKey(MKey,NumTimes,True);
PopUpShiftKeys;
Continue;
end;
end;
'~' : begin
SendKeyDown(VK_RETURN,1,True);
PopUpShiftKeys;
Inc(I);
end;
else begin
MKey:=vkKeyScan(SendKeysString[I]);
If (MKey<>INVALIDKEY) then begin
SendKey(MKey,1,True);
PopUpShiftKeys;
end else DisplayMessage('Invalid KeyName');
Inc(I);
end;
end;
end;
Result:=true;
PopUpShiftKeys;
end;

procedure SendKeysHuman(Text: String);//Freddy1990//By Freddy1990
begin
SendKeys(PChar(MidStr(Text, a, 1)), True);
Wait(100 + Random(150));
Application.ProcessMessages;
end;
end;

function StringToCaseSelect
(Selector : string;
CaseList: array of string): Integer;//by Freddy1990
var cnt: integer;
begin
Result:=-1;
for cnt:=0 to Length(CaseList)-1 do
begin
if CompareText(Selector, CaseList[cnt]) = 0 then
begin
Result:=cnt;
Break;
end;
end;
end;

function Asc(Char: String): Integer;//Freddy1990

begin
Result := 0;
case StringToCaseSelect(Char, ['a','b','c','d','e','f','g','h','i',

'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y',

'z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',

'P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4',

'5','6','7','8','9','?','?','&','?','"','''','(','?','?','!','?',

'?',')','-','?','_','^','$','?','*','?','?','%','?',',',';',':',

'=','?','.','/','+','<','>','\','~','?','`','[',']','}','{','#',

'@','?','|',' ']) of

0: Result := 97;

1: Result := 98;

2: Result := 99;

3: Result := 100;

4: Result := 101;

5: Result := 102;

6: Result := 103;

7: Result := 104;

8: Result := 105;

9: Result := 106;

10: Result := 107;

11: Result := 108;

12: Result := 109;

13: Result := 110;

14: Result := 111;

15: Result := 112;

16: Result := 113;

17: Result := 114;

18: Result := 115;

19: Result := 116;

20: Result := 117;

21: Result := 118;

22: Result := 119;

23: Result := 120;

24: Result := 121;

25: Result := 122;

26: Result := 65;

27: Result := 66;

28: Result := 67;

29: Result := 68;

30: Result := 69;

31: Result := 70;

32: Result := 71;

33: Result := 72;

34: Result := 73;

35: Result := 74;

36: Result := 75;

37: Result := 76;

38: Result := 77;

39: Result := 78;

40: Result := 79;

41: Result := 80;

42: Result := 81;

43: Result := 82;

44: Result := 83;

45: Result := 84;

46: Result := 85;

47: Result := 86;

48: Result := 87;

49: Result := 88;

50: Result := 89;

51: Result := 90;

52: Result := 48;

53: Result := 49;

54: Result := 50;

55: Result := 51;

56: Result := 52;

57: Result := 53;

58: Result := 54;

59: Result := 55;

60: Result := 56;

61: Result := 57;

62: Result := 178;

63: Result := 179;

64: Result := 38;

65: Result := 233;

66: Result := 34;

67: Result := 39;

68: Result := 40;

69: Result := 167;

70: Result := 232;

71: Result := 33;

72: Result := 231;

73: Result := 224;

74: Result := 41;

75: Result := 45;

76: Result := 176;

77: Result := 95;

78: Result := 94;

79: Result := 36;

80: Result := 168;

81: Result := 42;

82: Result := 249;

83: Result := 181;

84: Result := 37;

85: Result := 163;

86: Result := 44;

87: Result := 59;

88: Result := 58;

89: Result := 61;

90: Result := 63;

91: Result := 46;

92: Result := 47;

93: Result := 43;

94: Result := 60;

95: Result := 62;

96: Result := 92;

97: Result := 126;

98: Result := 180;

99: Result := 96;

100: Result := 91;

101: Result := 93;

102: Result := 125;

103: Result := 123;

104: Result := 35;

105: Result := 64;

106: Result := 128;

107: Result := 124;

108: Result := 32;

end;

end;

Procedure KeyDown(KeyID : Integer);//by Cazax
begin
Keybd_Event(KeyID, 1, 0, 0);
end;

Procedure KeyUp(KeyID : Integer);//By Cazax
begin
Keybd_Event(KeyID, 1, KEYEVENTF_KEYUP, 0);
end;

Function GetKeyCode(Character : Char): Integer;//Freddy
begin
Result := Asc(Character);
end;

procedure TypeByte(k: Byte);//SRL
begin
KeyDown(k);
Wait(10 + Random(50));
KeyUp(k);
end;

function StrGet(S : String; I : Integer): Char;//Cazax
begin
Result := S[I];
end;

procedure TypeSend(Text: string);//SRL
var
S: string;
I, A: Integer;
C: Byte;
Shift: Boolean;
begin
C := 0;
S:= 'ABCDEFGHIJKLMNOPQRSTUVWXZ' + '~!@#$%^&*()_+{}|:"<>?';
for I:= 1 to Length(Text) do
begin
Shift:= (Pos(Text[i], S) > 0);
if(Shift)then
begin
KeyDown(VK_SHIFT);
Wait(40 + Random(40));
A := I;
while(Pos(Text[a], S) > 0)and(A <= Length(Text))do
begin
C := GetKeyCode(StrGet(Text, A));
TypeByte(c);
A := A + 1;
if(A > Length(Text))then Break;
end;
end;
if(Shift)then
KeyUp(VK_SHIFT);
Wait(40 + Random(40));
if(I <= Length(Text))then
begin
C:= GetKeyCode(StrGet(Text, I));
TypeByte(C);
Wait(40 + Random(40));
end;
end;
C := GetKeyCode(Chr(13));
TypeByte(C);
end;

function LoggedIn: Boolean;
Begin
Result := (GetColor(439, 461, ClientHandle) = 16777215);
End;

procedure MouseBox(x1, y1, x2, y2: Integer; ClickType: Integer);//SRL
begin
case ClickType of
1 : Mouse(RandomRange(x1, x2), RandomRange(y1, y2), 0, 0, True);
2 : Mouse(RandomRange(x1, x2), RandomRange(y1, y2), 0, 0, False);
3 : MMouse(RandomRange(x1, x2), RandomRange(y1, y2), 0, 0);
end;
end;

procedure RandomRClick;
var
M: Integer;
begin
if not LoggedIn then exit;
M := MouseSpeed;
MouseSpeed := 7;
case Random(7) of
0: MouseBox(533, 7, 757, 200, 2);
1: MouseBox(521, 3, 553, 496, 2);
2: MouseBox(743, 3, 764, 497, 2);
3: MouseBox(4, 467, 763, 498, 2);
4: MouseBox(499, 343, 552, 496, 2);
5: MouseBox(3, 343, 521, 355, 2);
6: MouseBox(2, 346, 14, 499, 2);
end;
MouseSpeed := M;
end;

procedure PickUpMouse;//SRL
var
cx, cy, XX, YY: Integer;
tp : TPoint;
begin
if not LoggedIn then exit;
GetCursorPos(tp);
cx := tp.x;
cy := tp.y;
XX := cx;
YY := cy;
if Random(2) = 0 then
MMouse(cx - 3 - Random(5), cy - 8 - Random(17), 0, 0)
else MMouse(cx + 3, cy - 8 - Random(17), 5, 0);
Wait(1131 + Random(358));
if Random(2) = 0 then
MMouse(XX + 3, YY + 8, 5, 9)
else MMouse(XX - 3 - Random(5), YY + 8, 0, 9);
end;

procedure RMovement;//SRL
var
PL : Array[0..3] Of Integer;
Times, C, f : Integer;
begin
Times := Random(3) + 1;
PL[0] := VK_DOWN;
PL[1] := VK_UP;
PL[2] := VK_LEFT;
PL[3] := VK_RIGHT;
f := Random(3);
C := 0;
Repeat
C := C + 1;
KeyDown(PL[f]);
Wait(250 + Random(750));
KeyUp(PL[f]);
Until C = Times;
end;

procedure RandomTab;//Cazax
Var
Ct : Integer;
Begin
Ct := GetCurrentTab;
GameTab(Random(11) + 1);
Wait(500 + Random(1000));
GameTab(Ct);
End;

procedure RandomHover;//Cazax
Var
CT : Integer;
begin
Ct := GetCurrentTab;
GameTab(Random(11) + 1);
Wait(250 + Random(500));
MouseBox(MIX1, MIY1, MIX2, MIY2, 3);
Wait(1500 + random(1000));
GameTab(Ct);
end;

procedure LogOut;//Cazax
begin
Mouse(753, 10, 5, 5, True);
Wait(250 + Random(500));
Mouse(639, 377, 5, 5, True);
end;

function Radians(degs : integer): extended;//Cazax
begin
result := degs * (Pi / 180);
end;

function InFight: Boolean;//Cazax
var
TPA : TPointArray;
begin
FindColorsTolerance(TPA, 65280, 217, 129, 297, 209, 0, Clienthandle);
Result := Length(TPA) > 0;
end;

function InRandom: Boolean;//SRL
var
II: Integer;
begin
Result := True;
for II := 1 to 14 do
if not TabExists(II) then Exit;
Result := False;
end;
They are quite a lot

Quickmarch

2009-03-25 11:34:38

From: Cazax

var
MouseSpeed, AllocationSize : Integer;

const
MMX1 = 550;
MMY1 = 8;
MMX2 = 703;
MMY2 = 161;

{ const MMCX, MMCY;
Description: MiniMap Centre Point. }
const
MMCX = 627;
MMCY = 85;

{ const MSX1, MSY1, MSX2, MSY2;
Description: Main Screen EdgePoints. }
const
MSX1 = 4;
MSY1 = 4;
MSX2 = 516;
MSY2 = 338;

{ const MSCX, MSCY;
Description: Main Screen Centre Points. }
const
MSCX = 259;
MSCY = 170;

{ const MIX1, MIY1, MIX2, MIY2;
Description: Inventory EdgePoints. }
const
MIX1 = 547;
MIY1 = 202;
MIX2 = 737;
MIY2 = 466;

{ const MICX, MICY;
Description: Inventory Centre Points. }
const
MICX = 642;
MICY = 334;

{ const MCX1, MCY1, MCX2, MCY2;
Description: Chat Screen EdgePoints. }
const
MCX1 = 4;
MCY1 = 342;
MCX2 = 496;
MCY2 = 460;

{ const MCCX, MCCY;
Description: Chat Screen Centre Points. }
const
MCCX = 250;
MCCY = 401;

procedure Wait(Ms: Cardinal);
var
t: Cardinal;
begin
t := GetTickCount;
while (t + Ms) > GetTickCount do
Application.ProcessMessages;
end;

function SimilarColors(Color1, Color2, Tolerance: Integer): Boolean;
begin
Result := ((Abs((Color1 and $ff) - (Color2 and $ff)) <= Tolerance) and
(Abs(((Color1 and $ff00) shr 8) - ((Color2 and $ff00) shr 8)) <= Tolerance) and
(Abs(((Color1 and $ff0000) shr 16) - ((Color2 and $ff0000) shr 16)) <= Tolerance));
end;

type TPointArray = Array Of TPoint;

function FindColorsTolerance(var TPA : TPointArray; Color, xs, ys, xe, ye, Tolerance: Integer; Window: Hwnd): Boolean;
var
Bmp: TBitmap; // Bitmap of the client
tmpDC: HDC; // Device context of the client's window handle
Size: TRect; // Rect(angle) of the client's window
cx, cy: Integer; // For-loop vars
Line: PRGB32Array; // The scanline
begin
Result := False; // In case the color isn't found => Result = False
Bmp := TBitmap.Create; // We create our bitmap instance
tmpDC := GetWindowDC(Window); // We get the device context of the client's window handle
GetWindowRect(Window, Size); // We get the rect(angle) of the client's window
Bmp.Width := Size.Right - Size.Left; // We set the width of our bitmap
Bmp.Height := Size.Bottom - Size.Top; // We set the height of our bitmap
BitBlt(Bmp.Canvas.Handle, 0, 0, Bmp.Width, Bmp.Height, tmpDC, 0, 0, SRCCOPY);
// ^^^ We copy the client's canvas onto the bitmap
Bmp.PixelFormat := pf32bit; // We set the bitmap to 32bits
DeleteDC(tmpDC); // We delete the device context to avoid memory leakage
for cy := ys to ye do // Loop for the rows of pixels (y)
begin
if cy >= Bmp.Height then Break; // Break the loop if you reach the end of the bitmap
Line := Bmp.ScanLine[cy]; // We retrieve the scanline (line of pixels) from the bitmap for the current y
for cx := xs to xe do // Loop for the colums of pixels (x)
begin
if cx >= Bmp.Width then Break; // Break the loop if you reach the end of the bitmap
if (SimilarColors(RGB(Line[cx].R, Line[cx].G, Line[cx].B), Color, Tolerance)) then
// ^^^ We convert the RGB values of the current pixel to a color and compare it with the tolerance to the entered color
begin // If the color is similar (or for tol 0 the same) then...
Result := True; // Result of the function
SetLength(TPA, Length(TPA) + 1);
TPA[High(TPA)].X := cx; // Returned x-value
TPA[High(TPA)].Y := cy; // Returned y-value
end;
end;
end;
Line := nil; // Free the scanline to avoid memory leaks
Bmp.Free; // Free the bitmap to avoid memory leaks
end;

function GetColor(x, y: Integer; Handle: Cardinal): TColor;
var DC: HDC;
begin
DC := GetWindowDC(Handle);
result := TColor(GetPixel(DC, x, y));
ReleaseDC(Handle, DC);
end;

procedure Mouse(X, Y, Rx, Ry : Integer; Left : Boolean);
var
p : TPoint;
begin
MMouse(X, Y, Rx, Ry);
wait(100 + Random(100));
getcursorpos(p);
If Left Then
Mouse_Event(MOUSEEVENTF_LEFTDOWN, p.X, p.Y, 0, 0)
Else
Mouse_Event(MOUSEEVENTF_RIGHTDOWN, p.X, p.Y, 0, 0);
wait(100 + Random(100));
If Left Then
Mouse_Event(MOUSEEVENTF_LEFTUP, p.X, p.Y, 0, 0)
Else
Mouse_Event(MOUSEEVENTF_RIGHTUP, p.X, p.Y, 0, 0);
end;

function GetPage(site: string): WideString;
var
ie, fh: HINTERNET;
lpBuffer: array[0..1024+1] of Char;
dwBytesRead: DWORD;
begin
ie := InternetOpen('Client', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
fh := InternetOpenUrl(ie, PChar(site), nil, 0,
INTERNET_FLAG_RELOAD, 0);
if Assigned(fh) then
while True do
begin
dwBytesRead := 1024;
Application.ProcessMessages;
InternetReadFile(fh, @lpBuffer, 1024, dwBytesRead);
if dwBytesRead = 0 then
Break;
lpBuffer[dwBytesRead] := #0;
Application.ProcessMessages;
Result:= Result + lpBuffer;
end;
InternetCloseHandle(fh);
InternetCloseHandle(ie)
end;

function AppActivate(WindowHandle : HWND) : boolean;
begin
try
SendMessage(WindowHandle, WM_SYSCOMMAND, SC_HOTKEY, WindowHandle);
SendMessage(WindowHandle, WM_SYSCOMMAND, SC_RESTORE, WindowHandle);
result := SetForegroundWindow(WindowHandle);
except
on Exception do Result:=false;
end;
end;

procedure StealRS2(wHandle: Hwnd);
var
RSHwnd, RSSunJava, RSSunJava6: Hwnd;
begin
RSHwnd := FindWindowEx(wHandle, 0, 'shell embedding', nil);
RSHwnd := FindWindowEx(RSHwnd, 0, 'shell docobject view', nil);
RSHwnd := FindWindowEx(RSHwnd, 0, 'internet explorer_server', nil);
RSSunJava := FindWindowEx(RSHwnd, 0, 'Java Plug-in Control Window', nil);
RSSunJava6 := FindWindowEx(RSSunJava, 0, 'SunAwtFrame', nil);
RSSunJava := FindWindowEx(RSSunJava, 0, 'sun.plugin.viewer.frame.IExplorerEmbeddedFrame', nil);
RSHwnd := FindWindowEx(RSHwnd, 0, 'microsoft vm for java(tm) host window class', nil);
RSHwnd := FindWindowEx(RSHwnd, 0, 'msawt_comp_class', nil);
if (RSSunJava = 0) then RSSunJava := RSSunJava6;
if (RSHwnd = 0) then RSHwnd := RSSunJava;
if (RSHwnd = 0) then Exit;
SetParent(RSHwnd, wHandle);
SetWindowPos(RSHwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOOWNERZORDER or SWP_NOSIZE);
end;

function GetCurrentTab: Integer;
var
i: Integer;
b: Boolean;
begin
b := False;
Result := 0;
for i := 1 to 15 do
begin
case i of
1: b := (GetColor(543, 178, ClientHandle) = 1580634);
2: b := (GetColor(570, 179, ClientHandle) = 1778795);
3: b := (GetColor(604, 174, ClientHandle) = 1910385);
4: b := (GetColor(632, 172, ClientHandle) = 1910385);
5: b := (GetColor(666, 182, ClientHandle) = 1647204);
6: b := (GetColor(699, 177, ClientHandle) = 1910385);
7: b := (GetColor(735, 177, ClientHandle) = 1778795);
8: b := (GetColor(569, 471, ClientHandle) = 1910385);
9: b := (GetColor(598, 471, ClientHandle) = 1910385);
10: b := (GetColor(633, 478, ClientHandle) = 1778795);
11: b := (GetColor(668, 476, ClientHandle) = 1778795);
12: b := (GetColor(703, 481, ClientHandle) = 1580634);
13: b := (GetColor(740, 471, ClientHandle) = 1778795);
14: b := (GetColor(555, 275, ClientHandle) = 2070783);
15: b := (GetColor(533, 475, ClientHandle) = 1581150);
end;
if b then
begin
Result := i;
Exit;
end;
end;
end;

function TabExists(TabNumber: Integer): Boolean;
begin
Result := False;
case TabNumber of
1: Result := (GetColor(533, 177, ClientHandle) = 65536);
2: Result := (GetColor(565, 175, ClientHandle) = 65536);
3: Result := (GetColor(609, 175, ClientHandle) = 1052432);
4: Result := (GetColor(638, 174, ClientHandle) = 65536);
5: Result := (GetColor(670, 176, ClientHandle) = 65536);
6: Result := (GetColor(708, 171, ClientHandle) = 65536);
7: Result := (GetColor(740, 175, ClientHandle) = 65536);
8: Result := (GetColor(575, 474, ClientHandle) = 65536);
9: Result := (GetColor(605, 474, ClientHandle) = 65536);
10: Result := (GetColor(640, 472, ClientHandle) = 65536);
11: Result := (GetColor(680, 472, ClientHandle) = 65536);
12: Result := (GetColor(710, 470, ClientHandle) = 65536);
13: Result := (GetColor(735, 473, ClientHandle) = 65536);
14: Result := (GetColor(743, 1, ClientHandle) = 65536);
15: Result := (GetColor(537, 477, ClientHandle) = 65536);
end;
end;

function GameTab(tabnumber: Integer): Boolean;
var
c: Integer;
Coords: TPoint;
begin
C := 0;
if (tabnumber = 14) then
Coords := Point(752, 12)
else if (tabnumber = 15) then
Coords := Point(538, 485)
else if (tabnumber <= 7) then
Coords := Point(540 + ((tabnumber -1) * 33), 185)
else
Coords := Point(540 + ((tabnumber mod 7) * 33), 485);
while not(GetCurrentTab = tabnumber) and (c < 4) do
Begin
Mouse(Coords.x, Coords.y, 8, 8, true);
Inc(c);
end;
Result := (GetCurrentTab = tabnumber);
end;

Function SendKeys(SendKeysString : PChar; Wait : Boolean) : Boolean;
type
WBytes = array[0..pred(SizeOf(Word))] of Byte;

TSendKey = record
Name : ShortString;
VKey : Byte;
end;

const
{Array of keys that SendKeys recognizes.

If you add to this list, you must be sure to keep it sorted alphabetically
by Name because a binary search routine is used to scan it.}

MaxSendKeyRecs = 41;
SendKeyRecs : array[1..MaxSendKeyRecs] of TSendKey =
(
(Name:'BACKSPACE'; VKey:VK_BACK),
(Name:'BKSP'; VKey:VK_BACK),
(Name:'BREAK'; VKey:VK_CANCEL),
(Name:'BS'; VKey:VK_BACK),
(Name:'CAPSLOCK'; VKey:VK_CAPITAL),
(Name:'CLEAR'; VKey:VK_CLEAR),
(Name:'DEL'; VKey:VK_DELETE),
(Name:'DELETE'; VKey:VK_DELETE),
(Name:'DOWN'; VKey:VK_DOWN),
(Name:'END'; VKey:VK_END),
(Name:'ENTER'; VKey:VK_RETURN),
(Name:'ESC'; VKey:VK_ESCAPE),
(Name:'ESCAPE'; VKey:VK_ESCAPE),
(Name:'F1'; VKey:VK_F1),
(Name:'F10'; VKey:VK_F10),
(Name:'F11'; VKey:VK_F11),
(Name:'F12'; VKey:VK_F12),
(Name:'F13'; VKey:VK_F13),
(Name:'F14'; VKey:VK_F14),
(Name:'F15'; VKey:VK_F15),
(Name:'F16'; VKey:VK_F16),
(Name:'F2'; VKey:VK_F2),
(Name:'F3'; VKey:VK_F3),
(Name:'F4'; VKey:VK_F4),
(Name:'F5'; VKey:VK_F5),
(Name:'F6'; VKey:VK_F6),
(Name:'F7'; VKey:VK_F7),
(Name:'F8'; VKey:VK_F8),
(Name:'F9'; VKey:VK_F9),
(Name:'HELP'; VKey:VK_HELP),
(Name:'HOME'; VKey:VK_HOME),
(Name:'INS'; VKey:VK_INSERT),
(Name:'LEFT'; VKey:VK_LEFT),
(Name:'NUMLOCK'; VKey:VK_NUMLOCK),
(Name:'PGDN'; VKey:VK_NEXT),
(Name:'PGUP'; VKey:VK_PRIOR),
(Name:'PRTSC'; VKey:VK_PRINT),
(Name:'RIGHT'; VKey:VK_RIGHT),
(Name:'SCROLLLOCK'; VKey:VK_SCROLL),
(Name:'TAB'; VKey:VK_TAB),
(Name:'UP'; VKey:VK_UP)
);

{Extra VK constants missing from Delphi's Windows API interface}
VK_NULL=0;
VK_SemiColon=186;
VK_Equal=187;
VK_Comma=188;
VK_Minus=189;
VK_Period=190;
VK_Slash=191;
VK_BackQuote=192;
VK_LeftBracket=219;
VK_BackSlash=220;
VK_RightBracket=221;
VK_Quote=222;
VK_Last=VK_Quote;

ExtendedVKeys : set of byte =
[VK_Up,
VK_Down,
VK_Left,
VK_Right,
VK_Home,
VK_End,
VK_Prior, {PgUp}
VK_Next, {PgDn}
VK_Insert,
VK_Delete];

const
INVALIDKEY = $FFFF {Unsigned -1};
VKKEYSCANSHIFTON = $01;
VKKEYSCANCTRLON = $02;
VKKEYSCANALTON = $04;
UNITNAME = 'SendKeys';
var
UsingParens, ShiftDown, ControlDown, AltDown, FoundClose : Boolean;
PosSpace : Byte;
I, L : Integer;
NumTimes, MKey : Word;
KeyString : String[20];

procedure DisplayMessage(Message : PChar);
begin
MessageBox(0,Message,UNITNAME,0);
end;

function BitSet(BitTable, BitMask : Byte) : Boolean;
begin
Result:=ByteBool(BitTable and BitMask);
end;

procedure SetBit(var BitTable : Byte; BitMask : Byte);
begin
BitTable:=BitTable or Bitmask;
end;

Procedure KeyboardEvent(VKey, ScanCode : Byte; Flags : Longint);
var
KeyboardMsg : TMsg;
begin
keybd_event(VKey, ScanCode, Flags,0);
If (Wait) then While (PeekMessage(KeyboardMsg,0,WM_KEYFIRST, WM_KEYLAST, PM_REMOVE)) do begin
TranslateMessage(KeyboardMsg);
DispatchMessage(KeyboardMsg);
end;
end;

Procedure SendKeyDown(VKey: Byte; NumTimes : Word; GenUpMsg : Boolean);
var
Cnt : Word;
ScanCode : Byte;
NumState : Boolean;
KeyBoardState : TKeyboardState;
begin
If (VKey=VK_NUMLOCK) then begin
NumState:=ByteBool(GetKeyState(VK_NUMLOCK) and 1);
GetKeyBoardState(KeyBoardState);
If NumState then KeyBoardState[VK_NUMLOCK]:=(KeyBoardState[VK_NUMLOCK] and not 1)
else KeyBoardState[VK_NUMLOCK]:=(KeyBoardState[VK_NUMLOCK] or 1);
SetKeyBoardState(KeyBoardState);
exit;
end;

ScanCode:=Lo(MapVirtualKey(VKey,0));
For Cnt:=1 to NumTimes do
If (VKey in ExtendedVKeys)then begin
KeyboardEvent(VKey, ScanCode, KEYEVENTF_EXTENDEDKEY);
If (GenUpMsg) then
KeyboardEvent(VKey, ScanCode, KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP)
end else begin
KeyboardEvent(VKey, ScanCode, 0);
If (GenUpMsg) then KeyboardEvent(VKey, ScanCode, KEYEVENTF_KEYUP);
end;
end;

Procedure SendKeyUp(VKey: Byte);
var
ScanCode : Byte;
begin
ScanCode:=Lo(MapVirtualKey(VKey,0));
If (VKey in ExtendedVKeys)then
KeyboardEvent(VKey, ScanCode, KEYEVENTF_EXTENDEDKEY and KEYEVENTF_KEYUP)
else KeyboardEvent(VKey, ScanCode, KEYEVENTF_KEYUP);
end;

Procedure SendKey(MKey: Word; NumTimes : Word; GenDownMsg : Boolean);
begin
If (BitSet(Hi(MKey),VKKEYSCANSHIFTON)) then SendKeyDown(VK_SHIFT,1,False);
If (BitSet(Hi(MKey),VKKEYSCANCTRLON)) then SendKeyDown(VK_CONTROL,1,False);
If (BitSet(Hi(MKey),VKKEYSCANALTON)) then SendKeyDown(VK_MENU,1,False);
SendKeyDown(Lo(MKey), NumTimes, GenDownMsg);
If (BitSet(Hi(MKey),VKKEYSCANSHIFTON)) then SendKeyUp(VK_SHIFT);
If (BitSet(Hi(MKey),VKKEYSCANCTRLON)) then SendKeyUp(VK_CONTROL);
If (BitSet(Hi(MKey),VKKEYSCANALTON)) then SendKeyUp(VK_MENU);
end;

{Implements a simple binary search to locate special key name strings}

Function StringToVKey(KeyString : ShortString) : Word;
var
Found, Collided : Boolean;
Bottom, Top, Middle : Byte;
begin
Result:=INVALIDKEY;
Bottom:=1;
Top:=MaxSendKeyRecs;
Found:=false;
Middle:=(Bottom+Top) div 2;
Repeat
Collided:=((Bottom=Middle) or (Top=Middle));
If (KeyString=SendKeyRecs[Middle].Name) then begin
Found:=True;
Result:=SendKeyRecs[Middle].VKey;
end else begin
If (KeyString>SendKeyRecs[Middle].Name) then Bottom:=Middle
else Top:=Middle;
Middle:=(Succ(Bottom+Top)) div 2;
end;
Until (Found or Collided);
If (Result=INVALIDKEY) then DisplayMessage('Invalid Key Name');
end;

procedure PopUpShiftKeys;
begin
If (not UsingParens) then begin
If ShiftDown then SendKeyUp(VK_SHIFT);
If ControlDown then SendKeyUp(VK_CONTROL);
If AltDown then SendKeyUp(VK_MENU);
ShiftDown:=false;
ControlDown:=false;
AltDown:=false;
end;
end;

begin
AllocationSize:=MaxInt;
Result:=false;
UsingParens:=false;
ShiftDown:=false;
ControlDown:=false;
AltDown:=false;
I:=0;
L:=StrLen(SendKeysString);
If (L>AllocationSize) then L:=AllocationSize;
If (L=0) then Exit;

While (I<L) do begin
case SendKeysString[I] of
'(' : begin
UsingParens:=True;
Inc(I);
end;
')' : begin
UsingParens:=False;
PopUpShiftKeys;
Inc(I);
end;
'%' : begin
AltDown:=True;
SendKeyDown(VK_MENU,1,False);
Inc(I);
end;
'+' : begin
ShiftDown:=True;
SendKeyDown(VK_SHIFT,1,False);
Inc(I);
end;
'^' : begin
ControlDown:=True;
SendKeyDown(VK_CONTROL,1,False);
Inc(I);
end;
'{' : begin
NumTimes:=1;
If (SendKeysString[Succ(I)]='{') then begin
MKey:=VK_LEFTBRACKET;
SetBit(Wbytes(MKey)[1],VKKEYSCANSHIFTON);
SendKey(MKey,1,True);
PopUpShiftKeys;
Inc(I,3);
Continue;
end;
KeyString:='';
FoundClose:=False;
While (I<=L) do begin
Inc(I);
If (SendKeysString[I]='}') then begin
FoundClose:=True;
Inc(I);
Break;
end;
KeyString:=KeyString+Upcase(SendKeysString[I]);
end;
If (Not FoundClose) then begin
DisplayMessage('No Close');
Exit;
end;
If (SendKeysString[I]='}') then begin
MKey:=VK_RIGHTBRACKET;
SetBit(Wbytes(MKey)[1],VKKEYSCANSHIFTON);
SendKey(MKey,1,True);
PopUpShiftKeys;
Inc(I);
Continue;
end;
PosSpace:=Pos(' ',KeyString);
If (PosSpace<>0) then begin
NumTimes:=StrToInt(Copy(KeyString,Succ(PosSpace),Length(KeyString)-PosSpace));
KeyString:=Copy(KeyString,1,Pred(PosSpace));
end;
If (Length(KeyString)=1) then MKey:=vkKeyScan(KeyString[1])
else MKey:=StringToVKey(KeyString);
If (MKey<>INVALIDKEY) then begin
SendKey(MKey,NumTimes,True);
PopUpShiftKeys;
Continue;
end;
end;
'~' : begin
SendKeyDown(VK_RETURN,1,True);
PopUpShiftKeys;
Inc(I);
end;
else begin
MKey:=vkKeyScan(SendKeysString[I]);
If (MKey<>INVALIDKEY) then begin
SendKey(MKey,1,True);
PopUpShiftKeys;
end else DisplayMessage('Invalid KeyName');
Inc(I);
end;
end;
end;
Result:=true;
PopUpShiftKeys;
end;

procedure SendKeysHuman(Text: String);
var
a: integer;
begin
for a := 1 To Length(Text) do
begin
SendKeys(PChar(MidStr(Text, a, 1)), True);
Wait(100 + Random(150));
Application.ProcessMessages;
end;
end;

function StringToCaseSelect
(Selector : string;
CaseList: array of string): Integer;
var cnt: integer;
begin
Result:=-1;
for cnt:=0 to Length(CaseList)-1 do
begin
if CompareText(Selector, CaseList[cnt]) = 0 then
begin
Result:=cnt;
Break;
end;
end;
end;

function Asc(Char: String): Integer;

begin
Result := 0;
case StringToCaseSelect(Char, ['a','b','c','d','e','f','g','h','i',

'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y',

'z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O',

'P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4',

'5','6','7','8','9','?','?','&','?','"','''','(','?','?','!','?',

'?',')','-','?','_','^','$','?','*','?','?','%','?',',',';',':',

'=','?','.','/','+','<','>','\','~','?','`','[',']','}','{','#',

'@','?','|',' ']) of

0: Result := 97;

1: Result := 98;

2: Result := 99;

3: Result := 100;

4: Result := 101;

5: Result := 102;

6: Result := 103;

7: Result := 104;

8: Result := 105;

9: Result := 106;

10: Result := 107;

11: Result := 108;

12: Result := 109;

13: Result := 110;

14: Result := 111;

15: Result := 112;

16: Result := 113;

17: Result := 114;

18: Result := 115;

19: Result := 116;

20: Result := 117;

21: Result := 118;

22: Result := 119;

23: Result := 120;

24: Result := 121;

25: Result := 122;

26: Result := 65;

27: Result := 66;

28: Result := 67;

29: Result := 68;

30: Result := 69;

31: Result := 70;

32: Result := 71;

33: Result := 72;

34: Result := 73;

35: Result := 74;

36: Result := 75;

37: Result := 76;

38: Result := 77;

39: Result := 78;

40: Result := 79;

41: Result := 80;

42: Result := 81;

43: Result := 82;

44: Result := 83;

45: Result := 84;

46: Result := 85;

47: Result := 86;

48: Result := 87;

49: Result := 88;

50: Result := 89;

51: Result := 90;

52: Result := 48;

53: Result := 49;

54: Result := 50;

55: Result := 51;

56: Result := 52;

57: Result := 53;

58: Result := 54;

59: Result := 55;

60: Result := 56;

61: Result := 57;

62: Result := 178;

63: Result := 179;

64: Result := 38;

65: Result := 233;

66: Result := 34;

67: Result := 39;

68: Result := 40;

69: Result := 167;

70: Result := 232;

71: Result := 33;

72: Result := 231;

73: Result := 224;

74: Result := 41;

75: Result := 45;

76: Result := 176;

77: Result := 95;

78: Result := 94;

79: Result := 36;

80: Result := 168;

81: Result := 42;

82: Result := 249;

83: Result := 181;

84: Result := 37;

85: Result := 163;

86: Result := 44;

87: Result := 59;

88: Result := 58;

89: Result := 61;

90: Result := 63;

91: Result := 46;

92: Result := 47;

93: Result := 43;

94: Result := 60;

95: Result := 62;

96: Result := 92;

97: Result := 126;

98: Result := 180;

99: Result := 96;

100: Result := 91;

101: Result := 93;

102: Result := 125;

103: Result := 123;

104: Result := 35;

105: Result := 64;

106: Result := 128;

107: Result := 124;

108: Result := 32;

end;

end;

Procedure KeyDown(KeyID : Integer);
begin
Keybd_Event(KeyID, 1, 0, 0);
end;

Procedure KeyUp(KeyID : Integer);
begin
Keybd_Event(KeyID, 1, KEYEVENTF_KEYUP, 0);
end;

Function GetKeyCode(Character : Char): Integer;
begin
Result := Asc(Character);
end;

procedure TypeByte(k: Byte);
begin
KeyDown(k);
Wait(10 + Random(50));
KeyUp(k);
end;

function StrGet(S : String; I : Integer): Char;
begin
Result := S[I];
end;

procedure TypeSend(Text: string);
var
S: string;
I, A: Integer;
C: Byte;
Shift: Boolean;
begin
C := 0;
S:= 'ABCDEFGHIJKLMNOPQRSTUVWXZ' + '~!@#$%^&*()_+{}|:"<>?';
for I:= 1 to Length(Text) do
begin
Shift:= (Pos(Text[i], S) > 0);
if(Shift)then
begin
KeyDown(VK_SHIFT);
Wait(40 + Random(40));
A := I;
while(Pos(Text[a], S) > 0)and(A <= Length(Text))do
begin
C := GetKeyCode(StrGet(Text, A));
TypeByte(c);
A := A + 1;
if(A > Length(Text))then Break;
end;
end;
if(Shift)then
KeyUp(VK_SHIFT);
Wait(40 + Random(40));
if(I <= Length(Text))then
begin
C:= GetKeyCode(StrGet(Text, I));
TypeByte(C);
Wait(40 + Random(40));
end;
end;
C := GetKeyCode(Chr(13));
TypeByte(C);
end;

function LoggedIn: Boolean;
Begin
Result := (GetColor(439, 461, ClientHandle) = 16777215);
End;

procedure MouseBox(x1, y1, x2, y2: Integer; ClickType: Integer);
begin
case ClickType of
1 : Mouse(RandomRange(x1, x2), RandomRange(y1, y2), 0, 0, True);
2 : Mouse(RandomRange(x1, x2), RandomRange(y1, y2), 0, 0, False);
3 : MMouse(RandomRange(x1, x2), RandomRange(y1, y2), 0, 0);
end;
end;

procedure RandomRClick;
var
M: Integer;
begin
if not LoggedIn then exit;
M := MouseSpeed;
MouseSpeed := 7;
case Random(7) of
0: MouseBox(533, 7, 757, 200, 2);
1: MouseBox(521, 3, 553, 496, 2);
2: MouseBox(743, 3, 764, 497, 2);
3: MouseBox(4, 467, 763, 498, 2);
4: MouseBox(499, 343, 552, 496, 2);
5: MouseBox(3, 343, 521, 355, 2);
6: MouseBox(2, 346, 14, 499, 2);
end;
MouseSpeed := M;
end;

procedure PickUpMouse;
var
cx, cy, XX, YY: Integer;
tp : TPoint;
begin
if not LoggedIn then exit;
GetCursorPos(tp);
cx := tp.x;
cy := tp.y;
XX := cx;
YY := cy;
if Random(2) = 0 then
MMouse(cx - 3 - Random(5), cy - 8 - Random(17), 0, 0)
else MMouse(cx + 3, cy - 8 - Random(17), 5, 0);
Wait(1131 + Random(358));
if Random(2) = 0 then
MMouse(XX + 3, YY + 8, 5, 9)
else MMouse(XX - 3 - Random(5), YY + 8, 0, 9);
end;

procedure RMovement;
var
PL : Array[0..3] Of Integer;
Times, C, f : Integer;
begin
Times := Random(3) + 1;
PL[0] := VK_DOWN;
PL[1] := VK_UP;
PL[2] := VK_LEFT;
PL[3] := VK_RIGHT;
f := Random(3);
C := 0;
Repeat
C := C + 1;
KeyDown(PL[f]);
Wait(250 + Random(750));
KeyUp(PL[f]);
Until C = Times;
end;

procedure RandomTab;
Var
Ct : Integer;
Begin
Ct := GetCurrentTab;
GameTab(Random(11) + 1);
Wait(500 + Random(1000));
GameTab(Ct);
End;

procedure RandomHover;
Var
CT : Integer;
begin
Ct := GetCurrentTab;
GameTab(Random(11) + 1);
Wait(250 + Random(500));
MouseBox(MIX1, MIY1, MIX2, MIY2, 3);
Wait(1500 + random(1000));
GameTab(Ct);
end;

procedure LogOut;
begin
Mouse(753, 10, 5, 5, True);
Wait(250 + Random(500));
Mouse(639, 377, 5, 5, True);
end;

function Radians(degs : integer): extended;
begin
result := degs * (Pi / 180);
end;

function RunPoint: TPoint; //uses Math;
begin
Result.X := MMCX + Round(65 * Math.Cosecant(Radians(0 - 90)));
Result.Y := MMCY + Round(65 * Math.Secant(Radians(0 - 90)));
end;

function InFight: Boolean;
var
TPA : TPointArray;
begin
FindColorsTolerance(TPA, 65280, 217, 129, 297, 209, 0, Clienthandle);
Result := Length(TPA) > 0;
end;

function InRandom: Boolean;
var
II: Integer;
begin
Result := True;
for II := 1 to 14 do
if not TabExists(II) then Exit;
Result := False;
end;
They are quite a lot



:eek: Where did you get them??? <3 And do i need anything to use them? Also, if you have any more could you PM me them? :)

Naike

2009-03-25 12:17:42

Uhm.. Where did you get this stuff from?

I don't think you made it all yourself ;I

Cazax

2009-03-25 18:08:35

Credits:
Wait, SimilarColors, FindColorsTolerance(modified a bit), StealRS, SendKeysHuman, StringToCaseSelect, Asc - Freddy
GetColor, GetPage - RsN
AppActivate, SendKeys - Don't remember his name

All the rest functions are made by me or from SRL.
From: Quickmarch
:eek: Where did you get them??? <3 And do i need anything to use them? Also, if you have any more could you PM me them? :)

It's a compile of RS functions from forums and googled pages. You don't need anything more, you just need to use the correct Uses. If you get any compiling errors with them I'll tell you how to make it work.

marpis

2009-07-02 18:20:48

i don't this is gravedigging because Delphi programmin is a very silent forum.

So, is it possible to make a delphi program work like reflection?
If so, it'd be awesome add :) I'd try to make my own simple bot with delphi

Cazax

2009-07-03 01:41:01

It's not that easy. Freddy was making a reflection and color bot(Genesis), I don't know if he still develops it.

EvilChicken!

2009-07-04 04:03:34

Thanks for posting this, Cazax. ++.

Naum

2009-07-04 14:37:23

Thanks, Iroki would love this.

mastaraymond

2009-07-04 16:36:05

Should be using some credits there ;).

Freddy1990

2009-07-13 04:55:56

From: Cazax
Credits:
Wait, SimilarColors, FindColorsTolerance(modified a bit), StealRS, SendKeysHuman, StringToCaseSelect, Asc - Freddy
GetColor, GetPage - RsN
AppActivate, SendKeys - Don't remember his name

All the rest functions are made by me or from SRL.

It's a compile of RS functions from forums and googled pages. You don't need anything more, you just need to use the correct Uses. If you get any compiling errors with them I'll tell you how to make it work.


No offence, but randomly grabbing stuff from my old site and putting it into an include is just a bad idea, half of the code is either really slow or just completely useless like the Asc function because using Ord does just that, only faster. seeing all of the stuff on my site are the first things I ever wrote in Delphi…

And yea, you should add credits to the "include"

Cazax

2009-07-14 00:40:38

What's wrong by adding your functions? I don't care if they're slow(a few ms don't matter) but they work. And I use the functions for private use, that's why I don't have them with credits…Anyway I added them.

Iroki

2009-07-15 00:53:39

From: Cazax
but they work
TypeSend fuction seems that it doesnt works:/ and getkeycode/asc uhmm.. no coment :) I fixed type send and it should works now, same as GetKeyCode :)


Function GetKeyCode(Character : Char): Integer;
begin
Result := VkKeyScan(Character);
end;


procedure TypeSend(Text: string);
var
s: string;
i, k: Integer;
c: Byte;
Shift: Boolean;
begin
k := 1;
s := 'ABCDEFGHIJKLMNOPQRSTUVWXZ' + '~!@#$%^&*()_+{}|:"<>?';

for i := 1 to Length(Text); do
begin
Shift := (Pos(Text[k], S) > 0);
if(Shift)then
begin
KeyDown(VK_SHIFT);
Sleep(40 + Random(40));
while (Pos(Text[k], S) > 0) and (k <= Length(Text))do
begin
c := GetKeyCode(StrGet(Text, k));
TypeByte(c);
inc(k);
if(k > Length(Text))then Break;
end;
end;
if(Shift)then
KeyUp(VK_SHIFT);
Sleep(40 + Random(40));
if(k <= Length(Text))then
begin
C:= GetKeyCode(StrGet(Text, k));
TypeByte(C);
Sleep(40 + Random(40));
end;
inc(k);
end;
C := GetKeyCode(Chr(13));
TypeByte(C);
end;