SCAR Code:
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- » Login Routines --//
//-----------------------------------------------------------------//
// * function RSReady: Boolean; // * by ZephyrsFury
// * Procedure LoginScreenMusic(State: Variant); // * by Wizzup?
// * procedure Login_SetAudio(Volume, SFX, Area: Integer; SMSetting: (Stereo, Mono, NoChange) ); // * by ZephyrsFury
// * procedure Login_SetGraphics(Brightness: Integer; vl, rr, gd, td, ia, fl, gt, cs: string); // * by ZephyrsFury
// * procedure SetAutoingDefaults; // * by ZephyrsFury
// * procedure Logout; // * by Starblaster100 and Raymond
// * procedure LoginPlayer; // * by SRL Developers
// * function NextPlayerIndex: Integer; // * by Dankness, Ron, Raymond & ZephyrsFury
// * function RandomPlayerIndex: Integer; // * by Dankness, Ron, Raymond & ZephyrsFury
// * function SwitchToPlayer(PlayerNo: Integer; Active: Boolean): Boolean; // * by Dankness, Ron, Raymond & ZephyrsFury
// * procedure NextPlayer(Active: Boolean); // * by ZephyrsFury
// * procedure RandomNextPlayer(Active: Boolean); // * by ZephyrsFury
// * procedure CheckUserNicks; // * by Sumilion, Raymond and Nava2
{ var SRL_Logs: Integer;
Description: Variables needed for some login functions. }
{ var RandomPlayer, GraphicsSet: Boolean;
Description: Variables needed for some login functions. }
var
SRL_Logs: Integer;
RandomPlayer, GraphicsSet, AllowPVP: Boolean;
procedure NextPlayer(Active: Boolean); forward;
procedure RandomNextPlayer(Active: Boolean); forward;
const
UBx1 = 250; // Username tBox
UBy1 = 210;
UBx2 = 515;
UBy2 = 240;
PBx1 = 250; // Password tBox
PBy1 = 265;
PBx2 = 515;
PBy2 = 290;
GBx1 = 230; // greeting box in final screen
GBy1 = 330;
GBx2 = 660;
GBy2 = 400;
WDx1 = 88; // window box (to enter game) "click here to play"
WDy1 = 450;
WDx2 = 545;
WDy2 = 473;
WHITE_TEXT = 16777215; // white text color
MESSAGE_BOX = 11452366; // The "helpful message" box color
INFO_BOX = 7428416; // Blue information box color
LOGIN_COLOR = 6865381; // Login button color
ERROR_BOX = 2044518; // Error box (comes up on incorrect pw/un or banned acc
SWORD_COLOR = 11848397; // used for RSReady (the sword between "Runescape" title
{*******************************************************************************
function RSReady: Boolean;
By: ZephyrsFury
Description: Returns true if we are ready to auto (on loginscreen or logged in).
Useful for waiting until RS has fully loaded.
*******************************************************************************}
function RSReady: Boolean;
begin
Result := (countcolor(SWORD_COLOR, 364, 12, 396, 106) > 0) or (LoggedIn);
end;
{*******************************************************************************
Procedure LoginScreenMusic(State: Variant);
By: Wizzup?
Description: Takes Boolean(True, False) or Integer(1..5) as arguments.
1 or True = Off, 5 or False = Max.
1 2 3 4 5
<-o---o---o---o---o->
*******************************************************************************}
Procedure LoginScreenMusic(State: Variant);
Var
RealState: Variant;
x: Extended;
Begin
if (LoggedIn) then Exit;
TypeByte(vk_Escape);
Wait(500);
if (CountColor(51, 342, 396, 419, 410) <> 158) then Exit;
Case VarType(State) Of
11: RealState := (State + 1) * 4;
3, 5: if (State >= 1) and (State <= 5) then//If InRange(State, 1, 5) Then
RealState := State - 1;
Else
RealState := 0;
End;
x := (421.0 - 333.0) * RealState / 4.0 + 333.0;
If CountColorTolerance(1647966, Round(x) - 5, 375, Round(x) + 5, 385, 20) < 5 Then
If CountColorTolerance(991349, Round(x) - 5, 375, Round(x) + 5, 385, 20) < 5 Then
Mouse(Round(x), RandomRange(375, 385), 0, 0, True);
End;
{*******************************************************************************
procedure Login_SetAudio(Volume, SFX, Area: Integer; SMSetting: (Stereo, Mono, NoChange) );
By: ZephyrsFury
Description: Sets audio options through the login screen.
Use: Enter the desired Setting for the desired Option. Make option 0 for no change.
EG. Login_SetAudio(1, 5, 2, NoChange);
1 2 3 4 5
Volume, SFX, Area: <-o---o---o---o---o->
*******************************************************************************}
procedure Login_SetAudio(Volume, SFX, Area: Integer; SMSetting: TSMSetting);
var
II, Tx, Ty, T, AudioMask: Integer;
Pts: TIntegerArray;
begin
if (LoggedIn) then Exit;
AudioMask := BitmapFromString(25, 8, 'beNpjYICA/zCAzEWTgovgEf+PA' +
'2AqQBPBz8aqEb96PC7Ho5huRlHRg7iij6BRRPoXWTHWaMUiCAAICy' +
'rk');
TypeByte(vk_Escape);
T := GetSystemTime;
while (not(FindBitmapMaskTolerance(AudioMask, TX, TY, 300, 352, 463, 389, 0, 0))) and (GetSystemTime - T < 5000) do
Wait(100);
if (FindBitmapMaskTolerance(AudioMask, TX, TY, 300, 352, 463, 389, 0, 0)) then
Mouse(TX - 20, TY + 3, 50, 5, True)
else
begin
FreeBitmap(AudioMask);
Exit;
end;
Wait(100);
Pts := [Volume, SFX, Area];
for II := 0 to 2 do
begin
if (Pts[II] = 0) then Continue;
if (not(InRange(Pts[II], 0, 5))) then
begin
srl_Warn('Login_SetAudio', 'Points must be between 0 and 5', warn_AllVersions);
Continue;
end;
if Pts[II] = 1 then Tx:=305 else
Tx := 337 + Round((425 - 337) * (Pts[II] - 1) / 4);
Ty := Round(3.5 * II * II + 46.5 * II + 245);
if (GetColor(Tx, Ty) <> 1121100) then
Mouse(Tx + 2, Ty - 14, 0, 0, True);
Wait(50);
end;
if (GetColor(337, 389) = 181) and (SMSetting = Stereo) then
Mouse(421, 385, 10, 10, True)
else
if (GetColor(426, 389) = 181) and (SMSetting = Mono) then
Mouse(332, 385, 10, 10, True);
Wait(100);
TypeByte(vk_Escape);
FreeBitmap(AudioMask);
end;
{*******************************************************************************
procedure Login_SetGraphics(Brightness: Integer);
By: ZephyrsFury Fixed by J_Pizzle
Description: Sets graphic options in the login screen.
*******************************************************************************}
procedure Login_SetGraphics(Brightness: Integer);
var
T, x, y, tx, ty, GraphicsMask: Integer;
P: TPoint;
begin
if (LoggedIn) then Exit;
GraphicsMask := BitmapFromString(20, 8, 'beNpjYPiPBBiQwH9UgFUcmYumA' +
'JOLJoipGNMNuMwkQy8eR+LRi1U7JhuPdvx2YXUYZvgQExdYtTAAAF' +
'Km3SM=');
TypeByte(vk_Escape); //347, 273, 393, 292
T := GetSystemTime;
while (not(FindBitmapMaskTolerance(GraphicsMask, X, Y, 279, 272, 483, 352, 0, 0))) and (GetSystemTime - T < 5000) do
Wait(100);
if (FindBitmapMaskTolerance(GraphicsMask, X, Y, 279, 272, 483, 352, 0, 0)) then
Mouse(X - 20, Y + 3, 50, 5, True)
else
begin
FreeBitmap(GraphicsMask);
Exit;
end;
Wait(100);
if (Brightness > 4) then
srl_Warn('Login_SetGraphics', 'Brightness must be between 0 and 4', warn_AllVersions)
else
if (Brightness <> 0) then
begin
x := 0;
repeat
P := Point(260 + (Brightness - 1) * 32, 315);
if (GetColor(P.x, P.y) <> 16748688) then
begin
Mouse(P.x - 3, P.y, 3, 3, True);
if WaitColor(P.x, P.Y, 16748688, 1, 1000) then
break;
Inc(x);
end else
break;
until(x >= 5)
end;
repeat
if FindColor(x, y, 16777215, 143, 287, 621, 429) then
begin
Mouse(x + 10, y + 3, 10, 7, True);
getmousepos(tx, ty);
mouse(tx, ty + 10, 4, 4, true);
wait(300);
end;
until(not(FindColor(x, y, 16777215, 143, 287, 621, 429)));
Wait(100);
TypeByte(vk_Escape);
FreeBitmap(GraphicsMask);
end;
{*******************************************************************************
procedure SetAudioOff;
By: ZephyrsFury
Description: Sets the Audio to off (1 for each bar). Works logged in and out.
*******************************************************************************}
procedure SetAudioOff;
begin
if (LoggedIn) then
SetAudio(1, 1, 1, NoChange)
else
Login_SetAudio(1, 1, 1, NoChange);
end;
{*******************************************************************************
procedure SetAutoingDefaults;
By: ZephyrsFury
Description: Sets the graphic options for best SRL compatibility. Works both logged in and out.
*******************************************************************************}
procedure SetAutoingDefaults;
begin
if (LoggedIn) then
FixGraphics
else
Login_SetGraphics(4);
end;
{*******************************************************************************
procedure Logout;
By: Starblaster100 / Raymond
Description: Logs you out.
*******************************************************************************}
function Logout: Boolean;
var
c, i: Integer;
begin
Result := (not (LoggedIn));
if Result = True then
Exit;
if (SRL_Procs[srl_OnLogOut] <> nil) then
SRL_Procs[srl_OnLogOut]();
if GameTab(tab_LogOut) = False then
Exit;
Wait(200 + Random(100));
while (LoggedIn) and (c < 10) do
begin
Inc(c);
if(ClickText('here', UpChars, MIX1, MIY1, MIX2, MIY2, True))then
for i := 0 to 10 do
begin
Wait(1000);
if not(LoggedIn)then
begin
Result := True;
Exit;
end;
end;
end;
end;
{*******************************************************************************
procedure LoginPlayer;
By: SRL Developers & Blumblebee
Description: Logs in the Player[CurrentPlayer]. Detects most Client Login Errors
*******************************************************************************}
procedure clearEditBox(x1, y1, x2, y2: integer);
begin
while countColor(WHITE_TEXT, x1, y1, x2, y2) > 12 do
begin
TypeByte(VK_BACK);
Wait(50 + Random(50));
end;
end;
procedure LogInPlayer();
var
t, mark: LongInt;
c: Integer;
tries: byte;
// Actions: TVariantArray;
jump: boolean;
label
retype;
begin
ActivateClient;
wait(randomRange(50, 250));
if countcolor(MESSAGE_BOX, GBx1, GBy1, GBx2, GBy2) > 0 then // if at final screen ("lobby")
begin
wait(randomRange(750, 1500));
mouseBox(672, 18, 700, 46, 1); // straight values. I can add constants if you want, I don't want to bloat constants.
t := getSystemTime();
while (getSystemTime()-t < 30000) and (countcolor(INFO_BOX, 208, 460, 555, 464) < 0) do
wait(randomRange(1000, 2000));
end;
if (not(RSReady)) then // kept the same as original. I can adjust if deemed neccessary.
begin
MarkTime(Mark);
while (not(RSReady)) do
begin
Wait(100);
if (TimeFromMark(Mark) > 180000) then
begin
WriteLn('It has been 3 minutes and Runescape is not yet ready... Terminating.');
TerminateScript;
end;
end;
WriteLn('Welcome to Runescape.');
end;
{LoginScreenMusic(True);
if (not(GraphicsSet)) then
begin
SetAutoingDefaults;
GraphicsSet := True;
end;}
if (not(LoggedIn)) then
begin
if (not(Players[CurrentPlayer].Active)) then
begin
WriteLn('Player is not Active...');
NextPlayer(False);
Exit;
end;
wait(randomRange(500, 900));
if (countcolor(INFO_BOX, 208, 460, 555, 464) > 0) then // if it finds the information bar (blue color). means mainscreen
begin
wait(randomRange(50, 200));
mouseBox(215, 404, 368, 421, 1);
t := getSystemTime();
while (getSystemTime()-t < 30000) and (getcolor(287, 312) <> LOGIN_COLOR) do
wait(randomRange(1000, 2000));
end;
reType:
c := countcolor(WHITE_TEXT, UBx1, UBy1, UBx2, UBy2);
if ((c <= 0) or (c > 25)) then // if the userbox is not highlighted it clicks it.
mousebox(UBx1, UBy1, UBx2, UBy2, 1);
wait(randomRange(500, 750));
// Enter Username
clearEditBox(UBx1, UBy1, UBx2, UBy2);
Wait(100 + Random(200));
WriteLn(Capitalize(Players[CurrentPlayer].Name));
TypeSend(Players[CurrentPlayer].Name);
Wait(100+random(50));
// Enter Password
clearEditBox(PBx1, PBy1, PBx2, PBy2);
Wait(100 + Random(200));
TypeSend(Players[CurrentPlayer].Pass);
Wait(1000+random(750));
if countcolor(ERROR_BOX, 262, 150, 500, 300) > 0 then // if the error box comes up.
begin
case countcolor(WHITE_TEXT, 269, 233, 493, 305) of
900..1000: // incorrect username or password (exact = 949)
begin
writeLn('Incorrect Password used. Attempted to try again.');
if random(3) = 1 then
mouseBox(265, 329, 489, 356, 1)
else
TypeByte(vk_Escape);
jump := true;
end;
1800..2800: // banned account (exact : unknown, I got 2137 as my most frequent result.)
begin
writeLn('Your Account Has been Banned.');
mouseBox(285, 344, 470, 376, 1);
wait(randomRange(500, 1250));
TypeByte(vk_Escape);
NextPlayer(False);
Exit;
end;
end;
end;
if jump then
begin
if tries > 0 then
begin
writeLn('Incorrect Password inputted. Please Enter your password/username correctly');
NextPlayer(False);
Exit;
end;
inc(tries);
jump := false;
goto reType;
end;
t := getSystemTime();
while ( (getSystemTime-t < 30000) and (countcolor(MESSAGE_BOX, GBx1, GBy1, GBx2, GBy2) <= 0) ) do // if the "message box" comes up
wait(randomRange(500, 1000));
if (countcolor(MESSAGE_BOX, GBx1, GBy1, GBx2, GBy2) <= 0) then // did not enter the lobby screen.
begin
SRL_Warn('LoginPlayer', 'LogInPlayer() could not enter Lobby screen.', Warn_AllVersions);
NextPlayer(False);
Exit;
end;
wait(randomRange(500, 1000));
mouseBox(WDx1, WDy1, WDx2, WDy2, 1); // click here to play tBox.
wait(randomRange(750, 1500));
t := getsystemTime();
while not LoggedIn() do
begin
if getSystemtime()-t > randomRange(25000, 30000) then
break;
wait(randomRange(750, 1500));
end;
end;
if (LoggedIn) then
begin
PlayerStartTime := GetSystemTime; // PlayerStartTime
if Length(Players[CurrentPlayer].NickTPA) < 2 then
begin;
Writeln('Creating the NickTPA.');
if Players[CurrentPlayer].Nick <> '' then
Players[CurrentPlayer].NickTPA := CreateTPAFromText(Players[CurrentPlayer].Nick, UpChars)
else
if (Players[CurrentPlayer].Name <> '') then
Players[CurrentPlayer].NickTPA := CreateTPAFromText(Players[CurrentPlayer].Name, UpChars);
end;
AddToSRLLog('Current player: ' + Capitalize(Players[CurrentPlayer].Name));
ClickText('here to con', NPCChars, MCX1, MCY1, MCX2, MCY2, True);
end;
end;
{*******************************************************************************
function NextPlayerIndex: Integer;
By: Dankness, Ron, Raymond & ZephyrsFury
Description: Returns the player number of the next active player.
*******************************************************************************}
function NextPlayerIndex: Integer;
begin
if (AllPlayersInactive) then
begin
Result := -1;
Exit;
end;
Result := (CurrentPlayer + 1) mod Length(Players);
while (Players[Result].Active = False) do
Result := (Result + 1) mod Length(Players);
end;
{*******************************************************************************
function RandomPlayerIndex: Integer;
By: Dankness, Ron, Raymond & ZephyrsFury
Description: Returns the Player number of a random active player.
*******************************************************************************}
function RandomPlayerIndex: Integer;
var
N: Integer;
begin
if (AllPlayersInactive) then
begin
Result := -1;
Exit;
end;
N := Random(Length(Players));
while (Players[N].Active = False) or (N = CurrentPlayer) do
begin
if (PlayersActive = 1) and (N = CurrentPlayer) then Break;
N := Random(Length(Players));
end;
Result := N;
end;
{*******************************************************************************
function SwitchToPlayer(PlayerNo: Integer; Active: Boolean): Boolean;
By: Dankness, Ron, Raymond & ZephyrsFury
Description: Switches to a specific player, setting the current player's
activity to True or False.
*******************************************************************************}
function SwitchToPlayer(PlayerNo: Integer; Active: Boolean): Boolean;
begin
WriteLn('SwitchToPlayer(PlayerNo: ' + IntToStr(PlayerNo) + ', Active: ' + BoolToStr(Active)+ ');');
Players[CurrentPlayer].Active := Active;
Logout;
if (SRL_Procs[srl_OnNextPlayer] <> nil) then
SRL_Procs[srl_OnNextPlayer]();
PlayerCurTime := GetSystemTime;
Players[CurrentPlayer].Worked := Players[CurrentPlayer].Worked + (PlayerCurTime - PlayerStartTime);
CurrentPlayer := PlayerNo;
SRL_Logs := SRL_Logs + 1;
LoginPlayer;
Result := LoggedIn;
end;
{*******************************************************************************
procedure NextPlayer(Active: Boolean);
By: ZephyrsFury
Description: Logs in the next player that isn't inactive.
Boolean: True - Current player is ok. False - Current player is false.
*******************************************************************************}
procedure NextPlayer(Active: Boolean);
var
srl_PlayerIndexFunc: function: Integer;
cP: Integer;
begin
if (RandomPlayer) then
srl_PlayerIndexFunc := @RandomPlayerIndex
else
srl_PlayerIndexFunc := @NextPlayerIndex;
WriteLn('NextPlayer');
LogOut;
cP := srl_PlayerIndexFunc();
while (cP = -1) do
begin
cP := srl_PlayerIndexFunc();
if (SRL_Procs[srl_InNextPlayerLoop] <> nil) then
SRL_Procs[srl_InNextPlayerLoop]();
Wait(5000); //Endless loop
end;
SwitchToPlayer(cP, Active);
end;
{*******************************************************************************
procedure RandomNextPlayer(Active: Boolean);
By: ZephyrsFury
Description: Logs in a random player that isn't inactive.
Boolean: True - Current player is ok. False - Current player is false.
*******************************************************************************}
procedure RandomNextPlayer(Active: Boolean);
var
tmpBool: Boolean;
begin
tmpBool := RandomPlayer;
RandomPlayer := True;
NextPlayer(Active);
RandomPlayer := tmpBool;
end;
{*******************************************************************************
procedure CheckUserNicks;
By: Sumilion, Raymond, and Nava2
Description: Checks if all nicks are set correct.
*******************************************************************************}
procedure CheckUserNicks;
var
I, II: Integer;
Wrong, FWrong: Boolean;
WarnStrings: TStringArray;
begin
WarnStrings := ['Please fill in your nickname.', 'Please Uncapitalise your nickname.',
'Dont use the first letter in your nick.', 'Dont use spaces in your Nick.',
'Nick does NOT match the name.'];
for i := 0 to HowManyPlayers - 1 do
for II := 0 to 4 do
begin
case II of
0: Wrong := (Players[i].Nick = '');
1: Wrong := (Players[i].Nick <> LowerCase(Players[i].Nick));
2: Wrong := (Pos(Players[i].Nick, LowerCase(Players[i].Name)) = 1);
3: Wrong := (Pos(' ', Players[i].Nick) > 0);
4: Wrong := (Pos(LowerCase(Players[i].Nick), Capitalize(LowerCase(Players[i].Name))) = 0);
end;
if Wrong then
begin;
Writeln('--');
Writeln('WARNING: ' + WarnStrings[II] + ' with player: ' + Players[i].Name);
FWrong := True;
end;
end;
if FWrong then
begin
Writeln('');
Writeln('For more information, visit ht'+'tp://w'+'ww.villavu.com/forum/showthread.php?t=5410');
end;
end;