SCAR Code:
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- ยป Text Routines --//
//-----------------------------------------------------------------//
// * procedure TypeByte(k: Byte); // * by Mutant Squirrle
// * procedure TypeSend(Text: String); // * by Mutant Squirrle
// * function SendText2(Text: String): Boolean; // * by RSN | Modded By: Spky
// * procedure SendText(Text: String); // * by RSN
// * function GetOption: String; // * by WT-Fakawi
// * function GetUpText: String; // * by WT-Fakawi
// * function Option2(Text: String): Boolean; // * by Freddy1990
// * function IsUpText(UpText: String): Boolean; // * by Masquerader
// * function IsUpTextMulti(UT1, UT2, UT3: String): Boolean; // * by WT-Fakawi
// * function FindText(var cx, cy: Integer; txt: String; font, xs, ys, xe, ye: Integer): Boolean; // * by Stupid3ooo
// * function FindNpcChatText(txt: String): Boolean; // * by Kernel Klink or Stupid3000, font by Masquerader
// * function ClickNpcChatText(txt: String): Boolean; // * by Kernel Klink or Stupid3000, font by Masquerader
// * function FindInventoryText(txt: String): Boolean; // * by Stupid3ooo
// * function ChooseOption(x, y: Integer; txt: String): Boolean; // * by Stupid3ooo
// * function ChooseOptionEx(txt: String): Boolean; // * by Freddy1990
// * procedure CloseWindow; // * by Stupid3ooo
// * function hitkeys(send: Boolean): Integer; // * by Pyro
// * function HumanText(Text: String; Chance: Integer): String; // * by Pyro
// * function LastChatter(var name: String): Boolean; // * by masquerader
// * function GetLastChatText(var chat: String): Boolean; // * by masquerader
// * function SaveToChatLog: Boolean; // * by WT-Fakawi / masquerader
// * function GetNewChatMsg: String; // * by Stupid3ooo
// * function ClearSpaces(Text: String): String; // * by Mad Cow
// * function IsChatMessage(s: String): Boolean; // * by ?
// * function InChat(Text: String): Boolean; // * by WT-Fakawi
// * function InChatMulti(Text1, Text2, Text3: String): Boolean; // * by WT-Fakawi
// * function FindChatText(txt: String): Boolean; // * by Stupid3ooo
// * Function GetUpTextColor(Color, Tol: Integer; Range: TCharRange): String; // * by Wizzup?
// * Function ChatsBlackText: Array Of String; // * by Wizzup?
// * Function GetBlackChatMessage: String; // * by Wizzup?
// * Function FindBlackChatMessage(ChatMsg: String): Boolean; // * by Wizzup?
// * function PopUp(Option: String): Boolean; // * by RsN
// * function ClickOption(s: String; i: Integer): Boolean; // * by RSN
// * function ClickText2(txt: String; font, xs, ys, xe, ye: Integer; left: Boolean): Boolean; // * by Stupid3ooo
{*******************************************************************************
procedure TypeByte(k: Byte);
By: Mutant Squirrle
Description: Types one char.
*******************************************************************************}
procedure TypeByte(k: Byte);
begin
KeyDown(k);
Wait(10 + Random(50));
KeyUp(k);
end;
{*******************************************************************************
procedure TypeSend(Text: String);
By: Mutant Squirrle
Description: Types text humanlike using random timeing on keys.
*******************************************************************************}
procedure TypeSend(Text: string);
var
i: Integer;
Shift: Boolean;
begin
for i := 1 to Length(Text) do
begin
Shift:= (Text[i] = ':')or(Text[i] = '!')or(Text[i] = '+')or
(Text[i] = '?')or(Text[i] = '<')or(Text[i] = '>')or
(Text[i] = '@')or(Text[i] = '#')or(Text[i] = '$')or
(Text[i] = '&')or(Text[i] = '%')or(Text[i] = '*');
if(Shift)then
begin
KeyDown(VK_Shift);
Wait(5 + Random(20));
end;
TypeByte(GetKeyCode(Text[i]));
if(Shift)then
begin
KeyUp(VK_Shift);
Wait(5 + Random(20));
end;
Wait(50 + Random(120));
end;
Wait(200 + Random(500));
TypeByte(13);
end;
{*******************************************************************************
function SendText2(Text: String): Boolean;
By: RSN | Modded By: Spky
Description: Types text humanlike making mistakes, returns true if mistake has
been made.
*******************************************************************************}
function SendText2(Text: string): Boolean;
var
i, j, w: Integer;
S: string;
begin
for i := 1 to Length(Text) do
begin
S := Text[i];
if (Random(5) + 1 = 1) and (w < 3) then
begin
w := w + 1;
Result := True;
j := Ord(S[1]);
if (j <> 13) then
S := Chr(j + (Random(5) + 1));
if (S = Chr(13)) then
S := 'l';
end;
SendKeys(S);
Wait(50 + Random(100));
end;
end;
{*******************************************************************************
procedure SendText(Text: String);
By: RSN
Description: Types text humanlike.
*******************************************************************************}
procedure SendText(Text: string);
var
i: Integer;
begin
for i := 1 to Length(Text) do
begin
SendKeys(Text[i]);
Wait(50 + Random(100));
end;
end;
{*******************************************************************************
function GetUpText: String;
By: WT-Fakawi
Description: Returns text in upperleft corner.
*******************************************************************************}
function GetUpText: string;
begin
Result := GetTextAtEx(7, 7, 100, upchars, True, True, 0, 2, -1, 50, False,
tr_AllChars);
end;
{*******************************************************************************
function Option2(Text: String): Boolean;
By: Freddy1990
Description: Searches for text in upperleft corner.
*******************************************************************************}
function Option2(Text: string): Boolean;
begin
Result := (Pos(Text, GetUpText) > 0);
end;
{*******************************************************************************
function IsUpText(UpText: String): Boolean;
By: Masquerader
Description: Returns up text that might be to the right
*******************************************************************************}
function IsUpText(UpText: string): Boolean;
var
tempx, tempy: Integer;
begin
if (IsTextInAreaEx(7, 7, 334, 20, tempx, tempy, UpText, 100, upchars, True,
True, 0, 2, -1)) then
Result := True;
end;
{*******************************************************************************
function IsUpTextMulti(UT1, UT2, UT3: String): Boolean;
By: WT-Fakawi
Description: Returns any of three UpText that might be to the right
Usefull when text is partially masked.
Use: IsUpTextMulti('Attack','tta','ack')
*******************************************************************************}
function IsUpTextMulti(UT1, UT2, UT3: string): Boolean;
var
tempx, tempy, I: Integer;
var
TheText: string;
begin
for I := 1 to 3 do
begin
case I of
1: TheText := UT1;
2: TheText := UT2;
3: TheText := UT3;
end;
if IsTextInAreaEx(7, 7, 334, 20, tempx, tempy, TheText, 100, upchars, True,
True, 0, 2, -1) then
Result := True;
end;
end;
{*******************************************************************************
function FindText(var cx, cy: Integer; txt: String; font, xs, ys, xe, ye: Integer): Boolean;
By: Stupid3ooo
Description: Searches for text in specified box with specified font.
*******************************************************************************}
function FindText(var cx, cy: Integer; txt: string; font, xs, ys, xe, ye:
Integer): Boolean; //by Stupid3ooo
var
S: Integer;
begin
S := CreateBitmapMaskFromText(txt, font);
if xs <= 0 then xs := 0;
if ys <= 0 then ys := 0;
Result := FindBitmapMaskTolerance(S, cx, cy, xs, ys, xe, ye, 10, 50);
FreeBitmap(S);
end;
{*******************************************************************************
function FindNpcChatText(txt: String): Boolean;
By: Kernel Klink or Stupid3000, font by Masquerader
Description: Get last chat message.
*******************************************************************************}
function FindNpcChatText(txt: string): Boolean;
var
S: Integer;
begin
S := CreateBitmapMaskFromText(txt, npcchars);
Result := FindBitmapMaskTolerance(S, x, y, 9, 348, 523, 471, 50, 10);
FreeBitmap(S);
end;
{*******************************************************************************
function ClickNpcChatText(txt: String): Boolean;
By: Kernel Klink or Stupid3000, font by Masquerader
Description: Get last chat message.
*******************************************************************************}
function ClickNpcChatText(txt: string): Boolean;
var
tx, ty, S: Integer;
begin
if txt <> '' then
begin
S := CreateBitmapMaskFromText(txt, npcchars);
if FindBitmapMaskTolerance(S, tx, ty, 9, 348, 523, 471, 50, 10) then
begin
Mouse(tx + 5, ty + 8, 0, 0, True);
Result := True;
end;
FreeBitmap(S);
end;
end;
{*******************************************************************************
function FindInventoryText(txt: String): Boolean;
By: Stupid3ooo
Description: Finds inventory text.
*******************************************************************************}
function FindInventoryText(txt: string): Boolean; ////Small(3)
begin
Result := FindText(x, y, txt, SmallChars, 553, 206, 742, 465);
end;
{*******************************************************************************
function ChooseOption(x, y: Integer; txt: String): Boolean;
By: Stupid3ooo
Description: Finds Popup menu, then clicks on it.
*******************************************************************************}
function ChooseOption(x, y: Integer; txt: string): Boolean;
var
x1, y1, x2, y2, LeftCorner, RightCorner: Integer;
begin
LeftCorner := BitmapFromString(4, 4, 'z78DA33753135313137C5' +
'411A600064715CEA914500CACE13F0');
RightCorner := BitmapFromString(4, 4, 'z78DA33753135313137' +
'C5200D30002E35F8C501C9C013F0');
if (FindBitmap(LeftCorner, x1, y1)) and (FindBitmap(RightCorner, x2, y2)) then
begin
if (FindText(x, y, txt, upchars, x1, y1, x2, 502)) then
begin
Result := True;
Mouse(x + Length(txt) * 3, y + 3, 2, 2, True);
end
else if (FindText(x, y, 'Cancel', upchars, x1, y1, x2, 502)) then
Mouse(x + 9, y + 3, 2, 2, True);
end;
FreeBitmap(LeftCorner);
FreeBitmap(RightCorner);
end;
{*******************************************************************************
function ChooseOptionEx(txt: String): Boolean;
By: Freddy1990
Description: Finds Popup menu, then clicks on it.
*******************************************************************************}
function ChooseOptionEx(txt: string): Boolean;
var
x, y: Integer;
begin
Result := ChooseOption(x, y, txt);
end;
{*******************************************************************************
procedure CloseWindow;
By: Stupid3ooo
Description: Closes frontmost window.
*******************************************************************************}
procedure CloseWindow;
begin
if (FindBitmapMaskTolerance(CWindow, x, y, 400, 3, 515, 100, 0, 85)) then
Mouse(x + 8, y + 3, 3, 1, True);
end;
{*******************************************************************************
function hitkeys(send: Boolean): Integer;
By: Pyro
Description: Hits Random 4 Keys that are random 4 dist away. Good for smelt or cook x
*******************************************************************************}
function hitkeys(send: Boolean): Integer;
var
i, k: Integer;
full: string;
begin
i := Random(6) + 1;
for k := 1 to 4 do
full := full + IntToStr(i + Random(4));
Result := (StrToInt(full));
if (send) then TypeSend(IntToStr(Result));
end;
{*******************************************************************************
function HumanText(Text: String; Chance: Integer): String;
By: Pyro
Description: Returns A text humanly. DOES NOT TYPE. But will make ACTUAL human Mistakes
Chance is like well think of it as 1 out of ......
*******************************************************************************}
function HumanText(Text: string; Chance: Integer): string;
var
Keyboard: array[1..8] of string;
Tempi, i, l, NewKey: Integer;
Temps, Newtext: string;
begin
keyboard[1] := '1234567890-=';
keyboard[2] := 'qwertyuiop[]\';
keyboard[3] := 'asdfghjkl;';
keyboard[4] := 'zxcvbnm,./';
keyboard[5] := '!@#$%^&*()_+';
keyboard[6] := 'QWERTYUIOP{}|';
keyboard[7] := 'ASDFGHJKL:"';
keyboard[8] := 'ZXCVBNM<>?';
for l := 1 to Length(Text) do
begin
Temps := Copy(Text, l, 1)
if (Random(Chance) = 0) then
begin
for i := 1 to 8 do
begin
Tempi := Pos(Temps, keyboard[i])
if (tempi <> 0) then
begin
if (Tempi = 1) then NewKey := 2
if (Tempi = Length(keyboard[i])) then Newkey := Tempi - 1
if (Tempi <> 1) and (Tempi <> 10) then
Newkey := Tempi + Random(2) - Random(2)
NewText := Copy(keyboard[i], NewKey, 1)
break;
end;
end;
end else Newtext := Temps
Result := Result + Newtext;
end;
end;
{*******************************************************************************
function LastChatter(var name: String): Boolean;
By: masquerader
Description:
*******************************************************************************}
function LastChatter(var name: string): Boolean;
var
i: Integer;
begin
name := LowerCase(Trim(GetTextAtEx(21, 415, 0, SmallChars, False, False, 0, 0,
0, 50, False, tr_allChars)))
i := Pos(':', name)
if (i <> 0) then
begin
Delete(name, i, i);
Result := True;
end;
end;
{*******************************************************************************
function GetLastChatText(var chat: String): Boolean;
By: masquerader
Description:
*******************************************************************************}
function GetLastChatText(var chat: string): Boolean;
var
textx, texty: Integer;
begin
if (IsTextInAreaEx(40, 415, 130, 415, textx, texty, ':', 0, smallchars, False,
True, 0, 0, 0)) then
begin
chat := LowerCase(Trim(GetTextAtEx(textx + 8, 415, 0, SmallChars, False,
False, 0, 1, 16711680, 40, False, tr_allChars)));
Result := True;
end;
end;
procedure FixChat; forward;
{*******************************************************************************
function SaveToChatLog: Boolean;
By: WT-Fakawi / masquerader
Description: Saves chat to log file
*******************************************************************************}
procedure SaveToChatLog;
begin
FixChat;
OldLine := TheLine;
if (GetLastChatText(theline)) then
begin
if OldLine <> theLine then
begin
LastChatter(thename)
WriteFileString(thefile, TheTime + ' ' + thename + ': ' + theline +
Chr(13));
// writeln(thetime+' '+thename+': '+theline);
end
end else
begin
LastChatter(theline)
if OldLine <> theLine then
begin
WriteFileString(thefile, TheTime + ' ' + theline + Chr(13));
// writeln(thetime+' '+theline);
end
end
end;
{*******************************************************************************
function GetNewChatMsg: String;
By: Stupid3ooo
Description: Get last chat message.
*******************************************************************************}
function GetNewChatMsg: string;
begin
if (not (GetLastChatText(Result))) then
LastChatter(Result);
end;
{*******************************************************************************
function ClearSpaces(Text: String): String;
By: Mad Cow
Description: Clears spaces in an area of text(Needed in 'GetXP');
*******************************************************************************}
function ClearSpaces(Text: String): String;
var
Nums: String;
I, II: Integer;
begin
Nums := '01234567890';
for I := 1 to Length(Text) do
begin
for II := 1 to 10 do
begin
if(Copy(Text, I, 1) = Copy(Nums, II, 1)) then
Result := Result + Copy(Text, I, 1);
end;
end;
end;
{*******************************************************************************
function IsChatMessage(s: String): Boolean;
By:
Description: Checks if last chat message matches specified.
*******************************************************************************}
function IsChatMessage(S: string): Boolean;
begin
Result := (Pos(S, GetNewChatMsg) > 0);
end;
{*******************************************************************************
function InChat(Text: String): Boolean;
By: WT-Fakawi
Description: Grabs Last Chat Line and performs checks on occurence of text
*******************************************************************************}
function InChat(Text: string): Boolean;
begin
Result := IsChatMessage(text);
end;
{*******************************************************************************
function InChatMulti(Text1, Text2, Text3: String): Boolean;
By: WT-Fakawi
Description: Grabs Last Chat Line and performs checks on three occurences of text
*******************************************************************************}
function InChatMulti(Text1, Text2, Text3: string): Boolean;
var
temp: string;
begin
temp := GetNewChatMsg;
if (Pos(Text1, temp) <> 0) or (Pos(Text2, temp) <> 0) or (Pos(Text3, temp) <> 0) then
Result := True
end;
{*******************************************************************************
function FindChatText(txt: String): Boolean;
By: Stupid3ooo
Description: Searches for text in chat window.
*******************************************************************************}
function FindChatText(txt: string): Boolean; //Chat(1)
begin
Result := FindText(x, y, txt, SmallChars, 9, 348, 479, 433);
end;
{*******************************************************************************
function GetUpTextColor(Color, Tol: Integer; Range: TCharRange): String;
By: Wizzup?
Description: Performs GetTextAtEx with The chosen color, tol and TCharRange.
*******************************************************************************}
function GetUpTextColor(Color, Tol: Integer; Range: TCharRange): String;
begin
Result := Trim(GetTextAtEx(7, 7, Tol, upchars, true,
true, 0, 2, Color, 50, True, Range));
WriteLn(Result);
end;
{*******************************************************************************
function ChatsBlackText: Array Of String;
By: Wizzup?
Description: Gets all text with color 0 in chatbox:
line 1 is result[0]
line 2 is result[1]
line 3 is result[2]
line 4 is result[3]
line 5 is result[4]
*******************************************************************************}
function ChatsBlackText: Array Of String;
var
I : Byte;
begin
SetArrayLength(Result, 5);
for I := 0 to 4 do
Result[I] := Trim(GetTextAtEx(20, 415 - (14 * I), 0, SmallChars, False,
False, 0, 1, 0, 80, False, tr_AllChars));
end;
{*******************************************************************************
function IsChatBlackTextAnyLine(ChatTxt: String): Boolean;
By: Wizzup?
Description: Returns true if ChatTxt is found in any of the 5 lines in ChatBox.
*******************************************************************************}
function IsChatBlackTextAnyLine(ChatTxt: String): Boolean;
var
TheLines: Array Of String;
I : Byte;
begin
TheLines := ChatsBlackText;
for I := 0 To 4 Do
if (Pos(ChatTxt, TheLines[I]) <> 0) then
begin
Result := True;
Exit;
end;
end;
{*******************************************************************************
function GetBlackChatMessage: String;
By: Wizzup?
Description: Gets text with color 0 in last chat line.
*******************************************************************************}
function GetBlackChatMessage: String;
begin
Result := Trim(GetTextAtEx(20, 415, 0, SmallChars, False,
False, 0, 1, 0, 80, False, tr_AllChars));
end;
{*******************************************************************************
function FindBlackChatMessage(ChatMsg: String): Boolean;
By: Wizzup?
Description: Returns True if text with color 0 in last chat line is found.
*******************************************************************************}
function FindBlackChatMessage(ChatMsg: String): Boolean;
begin
Result := (Pos(ChatMsg, GetBlackChatMessage) <> 0);
end;
{*******************************************************************************
function Capitalize(S: String): String;
By: RSN/StarBlaster/Ron
Description: Will Capitalize strings as Runescape i are noob = I Are Noob
*******************************************************************************}
function Capitalize(S: String): String;
var
i: Integer;
begin
Result := trim(s);
Result[1] := Uppercase(Result[1])[1];
for i := 2 to Length(Result) do
if (Result[i] = ' ') or (Result[i] = '_') then
Result[i + 1] := Uppercase(Result[i + 1])[1];
end;
{*******************************************************************************
function PopUp(Option: String): Boolean;
By: RsN
Description: Finds Popup menu, then clicks Option.
*******************************************************************************}
function PopUp(Option: string): Boolean;
var
Top, Bottom: TPoint;
dtmTop, dtmBottom, x, y: Integer;
begin
dtmTop := DTMFromString('78DA63146464606801622C0026CA28006435A' +
'3AA890D7147552345841A90393D04D4880259DD04D4880359ED04' +
'D4280059AD04FC2504644DC4AF06000DC909E0');
dtmBottom := DTMFromString('78DA635CCCC8C070198891406C883B9886893' +
'22E02B22EA1AA8101B89A8540D64522CCB948843984EC02B9F910' +
'01BBA610E1AF6944D80572F311026AE6005967F0DB05007BD4134' +
'5');
if (FindDTM(dtmTop, Top.x, Top.y, 10, 10, 764, 502) and FindDTM(dtmBottom,
Bottom.x, Bottom.y, Top.x, Top.y, 764, 502)) then
if (FindText(x, y, Option, upchars, 0, 0, Bottom.x, Bottom.y)) then
begin
Result := True;
Mouse(x + Length(Option) * 3, y + 2, 4, 3, True);
Wait(150 + Random(200));
end else
if (FindText(x, y, 'Cancel', upchars, Top.x, Top.y, Bottom.x, Bottom.y))
then
Mouse(x + 3, y + 2, 4, 3, True);
FreeDTM(dtmTop);
FreeDTM(dtmBottom);
end;
{*******************************************************************************
function ClickOption(s: String; i: Integer): Boolean;
By: RSN
Description: Clicks Option in Specified Area (1 for Main Screen, 2 Inventory,
3 for Chat Window), returns True if text was found
*******************************************************************************}
function ClickOption(S: string; i: Integer): Boolean;
var
x, y, tmpMask: Integer;
begin
tmpMask := CreateBitmapMaskFromText(S, upchars);
case i of
1:
begin
if (FindBitmapMaskTolerance(tmpMask, x, y, 0, 0, 520, 340, 10, 50)) then
begin
Wait(25 + Random(50));
Mouse(x + (Length(S) * 6 div 2), y + 5, 3, 3, True);
Result := True;
end;
end;
2:
begin
if (FindBitmapMaskTolerance(tmpMask, x, y, 550, 200, 750, 470, 10, 50))
then
begin
Wait(25 + Random(50));
Mouse(x + (Length(S) * 6 div 2), y + 5, 3, 3, True);
Result := True;
end;
end;
3:
begin
if (FindBitmapMaskTolerance(tmpMask, x, y, 0, 340, 500, 460, 10, 50))
then
begin
Wait(25 + Random(50));
Mouse(x + (Length(S) * 6 div 2), y + 5, 3, 3, True);
Result := True;
end;
end;
end;
FreeBitmap(tmpMask);
end;
{*******************************************************************************
function ClickText2(txt: String; font, xs, ys, xe, ye: Integer; left: Boolean): Boolean;
By: Stupid3ooo
Description: Clicks text if found in box.
*******************************************************************************}
function ClickText2(txt: string; font, xs, ys, xe, ye: Integer; left: Boolean):
Boolean;
begin
Result := FindText(x, y, txt, font, xs, ys, xe, ye);
if (Result) then
Mouse(x + Length(txt) * 3, y + 3, 0, 0, left);
end;