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;
{*******************************************************************************
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 := (LoggedIn) or (GetColor(520, 146) = 4038981);
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;
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; vl, rr, gd, td, ia, fe, gt, cs: string);
By: ZephyrsFury
Description: Sets graphic options in the login screen.
Use: Enter the desired Setting for the desired Option.
Leave as 0 for no change of brightness and '' for no change in anything else.
Parameter Option Setting
Brightness Brightness 1 - 4 (0 for no change)
vl Visible Levels Current / All
rr Remove Roofs Always / Selectively
gd Ground Decoration Off / On
td Texture Detail Low / High
ia Idle Animations Few / Many
fe Flickering Effects Off / On
gt Ground Textures Few / Many
cs Chracter Shadows Off / On
1 2 3 4
Brightness: <---o---o---o---o--->
EG. Login_SetGraphics(2, 'current', '', 'off', 'low', 'few', '', 'few', 'off');
For Autoing:
Login_SetGraphics(4, 'current', 'always', 'off', 'low', 'few', 'off', 'few', 'off');
*******************************************************************************}
procedure Login_SetGraphics(Brightness: Integer; vl, rr, gd, td, ia, fe, gt, cs: string);
var
Settings, PosSettings, OptionName: TStringArray;
II, T, W, tCol, x, y, GraphicsMask: Integer;
TB: TBox;
P: TPoint;
begin
if (LoggedIn) then Exit;
GraphicsMask := BitmapFromString(20, 8, 'beNpjYPiPBBiQwH9UgFUcmYumA' +
'JOLJoipGNMNuMwkQy8eR+LRi1U7JhuPdvx2YXUYZvgQExdYtTAAAF' +
'Km3SM=');
Settings := [vl, rr, gd, td, ia, fe, gt, cs];
PosSettings := ['Current', 'All', 'Always', 'Selectively', 'Off', 'On', 'Low',
'High', 'Few', 'Many', 'Off', 'On', 'Few', 'Many', 'Off', 'On'];
OptionName := ['Visible levels', 'Remove roofs', 'Ground decoration', 'Texture detail',
'Idle animations', 'Flickering effects', 'Ground textures', 'Character shadows'];
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
P := Point(89 + (Brightness - 1) * 21, 266);
if (GetColor(P.x, P.y) <> 1121100) then
Mouse(P.x - 3, P.y - 17, 6, 6, True);
end;
for II := 0 to 7 do
begin
TB.x1 := 67 + 130 * ((II + 1) mod 5);
TB.y1 := 245 + 60 * ((II + 1) div 5);
TB.x2 := TB.x1 + 109;
TB.y2 := TB.y1 + 15;
if (not(InStrArrEx(Capitalize(Settings[II]), [PosSettings[II * 2], PosSettings[II * 2 + 1]], W))) then
begin
srl_Warn('Login_SetGraphics', 'Invalid Setting: ' + Settings[II] + ' for Option: ' + OptionName[II] + '.', warn_AllVersions);
Continue;
end;
tCol := (W mod 2) * 16777088 + 127;
if (not(FindColor(x, y, tCol, TB.x1, TB.y1, TB.x2, TB.y2))) then
begin
Mouse(TB.x1 + 10, TB.y1 + 3, 10, 7, True);
if (FindColor(x, y, tCol, TB.x1, TB.y2 + 1, TB.x2, TB.y2 + 1 + 51)) then
Mouse(x, y, 10, 7, True)
else
MouseBox(TB.x1 + 10, TB.y1 + 3, TB.x2 - 40, TB.y2 - 3, 1);
end;
end;
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
SetGraphics(4, 'current', 'always', 'off', 'low', 'few', 'off', 'few', 'off')
else
Login_SetGraphics(4, 'current', 'always', 'off', 'low', 'few', 'off', 'few', 'off');
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(14) = 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
Description: Logs in the Player[CurrentPlayer]. Detects most Client Login Errors
*******************************************************************************}
procedure LoginPlayer;
var
Mark, Attempts: Integer;
Actions: TVariantArray;
RetryLogin: Boolean;
label
ProcStart;
begin
ActivateClient;
Wait(100);
TypeByte(vk_Escape);
if (GetColor(207, 409) = 238301) then //At Welcome Screen
begin
Wait(500 + Random(1000));
MouseBox(249, 419, 521, 445, 1);
MarkTime(Mark);
while (TimeFromMark(Mark) < 30000) and (not(LoggedIn)) do
Wait(1000 + Random(1000));
end;
if (not(RSReady)) then
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;
ProcStart:
if (not(LoggedIn)) then
begin
if (not(Players[CurrentPlayer].Active)) then
begin
WriteLn('Player is not Active...');
NextPlayer(False);
Exit;
end;
Wait(900 + random(60));
//Click 'Log In' on main menu
while (GetColor(343, 175) <> 7750) do
begin
MouseBox(360, 184, 400, 190, 1);
Wait(100 + Random(100));
end;
//Type Username
Mouse(315, 272, 10, 5, True);
while (CountColor(7750, 311, 269, 452, 284) > 0) do
begin
TypeByte(VK_BACK);
Wait(50 + Random(50));
end;
Wait(100 + Random(200));
WriteLn(Capitalize(Players[CurrentPlayer].Name));
TypeSend(Players[CurrentPlayer].Name);
Wait(100+random(50));
//Type Password
Mouse(315, 334, 10, 5, True);
while (CountColor(7750, 311, 337, 452, 352) > 0) do
begin
TypeByte(VK_BACK);
Wait(50 + Random(50));
end;
Wait(100 + Random(200));
TypeSend(Players[CurrentPlayer].Pass);
Wait(500 + Random(300));
if (GetColor(315, 239) = 197552) then //Check for pvp warning and click
if AllowPVP then
MouseBox(434, 416, 481, 425, 1)
else
begin
SRL_Warn('LoginPlayer', 'Attempted to log into PVP World when AllowPVP was false. Terminating.', Warn_AllVersions);
TerminateScript;
end;
MarkTime(Mark);
repeat
SetLength(Actions, 0);
if (TimeFromMark(Mark) > 60000) then
Actions := ['One minute has passed...', 0, 2, 'NextPlayer', 'Login Failed']
else
case (CountColor(12509695, 288, 205, 475, 247)) of //Number of text colour points
// Actions := ['WriteLn Text', TimeToWait, NumberOfRetries, 'FinalAction', 'PlayerStatus'];
760: Actions := ['Too many incorrect logins.', 5 * 60000, 2, 'NextPlayer', ''];
536: Actions := ['Login limit exceeded. Please wait 1 minute and try again.', 60000, 2, 'NextPlayer', ''];
711: If (CountColor(16711680, 341, 219, 391, 233) = 128) then
Actions := ['Your account has been disabled', 0, 0, 'NextPlayer', 'Acc Disabled'];
598: Actions := ['Invalid Username / Password', 0, 2, 'NextPlayer', 'Wrong User/Pass'];
787: Actions := ['Not a Members Account', 0, 0, 'NextPlayer', 'Non-member'];
408: Actions := ['World is full.', 5000, 20, 'RandomNextPlayer', ''];
669: Actions := ['Your account is already logged in', 5000, 0, 'RandomNextPlayer', ''];
555: Actions := ['The Server is being updated.', 60000, 4, 'Terminate', 'Server Updating'];
218: Actions := ['Error Connecting.', 20000, 9, 'Terminate', 'Error Connecting'];
335: Actions := ['Unable to connect Login Server offline.',(20000) + Random(6000), 4, 'Terminate', 'Login Server Offline'];
512: Actions := ['RuneScape has been updated. Script Terminated.', 0, 0, 'Terminate', 'RS Updated'];
489: Actions := ['Connection timed out.', 0, 4, 'Terminate', 'Connection Timed Out'];
737: Actions := ['You are standing in a members-only area.', 0, 0, 'NextPlayer', 'In Mems-Only Area'];
end;
if (Length(Actions) > 0) then
begin
WriteLn(Actions[0]);
Wait(Actions[1] + Random(100));
if (Actions[2] <> 0) then
if (Attempts < Actions[2]) or (Actions[2] = -1) then
begin
RetryLogin := True;
Break;
end;
if (Actions[4] <> '') then
Players[CurrentPlayer].Loc := Actions[4];
case Actions[3] of
'NextPlayer': NextPlayer(False);
'RandomNextPlayer': RandomNextPlayer(True);
'Terminate': TerminateScript;
end;
Exit;
end;
Wait(100);
until (GetColor(207, 409) = 238301) or (LoggedIn);
if (RetryLogin) then
begin
RetryLogin := False;
Inc(Attempts);
goto ProcStart;
end;
if (GetColor(207, 409) = 238301) then
begin
Wait(500 + Random(1000));
MouseBox(249, 419, 521, 445, 1);
end;
MarkTime(Mark);
while (TimeFromMark(Mark) < 30000) and (not(LoggedIn)) do
Wait(1000 + Random(1000));
end;
if (LoggedIn) then
begin
PlayerStartTime := (GetSystemTime div 1000); // 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
Players[CurrentPlayer].NickTPA := CreateTPAFromText(Players[CurrentPlayer].Name, UpChars);
end;
AddToSRLLog('Current player: ' + Capitalize(Players[CurrentPlayer].Name));
ClickText('here to con', UpChars, 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 div 1000);
Players[CurrentPlayer].Worked := Players[CurrentPlayer].Worked + ((PlayerCurTime - PlayerStartTime) / 60);
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 [url]http://www.villavu.com/forum/showthread.php?t=5410');[/url]
end;
end;