zstars
2006-05-23 11:23:31
This is my first post so to start, hello everyone :)
Ok, the functions:
Apparently (to me at least) the InPin() function included with SRL 2.01 doesn't work.
I wanted to be able to open the bank with a pin, so I made my own InPinEx().
I made one IsPinOpen() function too, which it uses.
The most remarkable things about my InPinEx() are, as the comment below explains, that it is non-blocking (will always return) and that it returns true, no matter the real outcome, if it manages to insert three digits successfully.
*BTW I know that my coding style in Pascal is rather bad, feel free to suggest improvements.
Ok, the functions:
Apparently (to me at least) the InPin() function included with SRL 2.01 doesn't work.
I wanted to be able to open the bank with a pin, so I made my own InPinEx().
I made one IsPinOpen() function too, which it uses.
The most remarkable things about my InPinEx() are, as the comment below explains, that it is non-blocking (will always return) and that it returns true, no matter the real outcome, if it manages to insert three digits successfully.
*BTW I know that my coding style in Pascal is rather bad, feel free to suggest improvements.
// Function: IsPinOpen() : bool
// Author: zstars
// Purpose & Usage:
// Returns true if the pin window is open, false otherwise.
function IsPinOpen() : Boolean;
begin
Result := False;
if (GetColor(410, 150) = 8973040) and (GetColor(395, 262) = 255) then
Result := True;
end;
// Function: InPinEx(string) : bool
// Author: zstars
// Purpose & Usage:
// This function will whether the pin window or the bank is open.
// If one of them is, it will try to insert the pin.
// It will use the question marks to check if the digits
// are inserted. However, the last digit can't really be checked and
// it is a non-blocking function, so it is your duty to check whether the
// bank was successfully opened or not.
function InPinEx(pin : String) : Boolean;
var
i: Integer;
x, y: Integer;
b : array [0..10] of Integer;
bres: boolean;
begin
b[0] := BitmapFromString(8, 11, 'z78DA33304000370C60800360AAC1' +
'A58B187152CDC1AF9E1859F2D413E33B52D5931A9E0664C517F10' +
'000287879B1');
b[1] := BitmapFromString(7, 11, 'z78DA333040003724608003B86100' +
'62D4E0379378DB87934A372280018900008525648D');
b[2] := BitmapFromString(7, 11, 'z78DA33300001371CC00009902A8E' +
'0B10AF9E189543518D01DE30C71F0BF801008CB06595');
b[4] := BitmapFromString(8, 11, 'z78DA73734300032280DBA0578FDF' +
'047AAAC70F062AC4F00300632B72FD');
b[3] := BitmapFromString(7, 11, 'z78DA33300001371CC00009902A8E' +
'092857498C3B69673B312A29093D527D840900A4FD6619');
b[5] := BitmapFromString(8, 11, 'z78DA7373230C0C90002E715C8012' +
'F5A4EA25CF46FAFB8B12716A85122E000093B47279');
b[6] := BitmapFromString(8, 11, 'z78DA33304000370C60800360AAC1' +
'A58B18D3A8A59E18F7E352439EFB893787545B488D05E2430C3F0' +
'000E75E7591');
b[7] := BitmapFromString(7, 11, 'z78DA7373230C0CF00262548E9A46' +
'894AE2010048E26301');
b[8] := BitmapFromString(8, 11, 'z78DA33304000370C60800360AAC1' +
'A50BBF69C4EB22D55503E5FEC1E95FE20100FFAB7615');
b[9] := BitmapFromString(8, 11, 'z78DA3330000137BCC00009E012C7' +
'254B6BF5E4891B90E86B5C60A8ABC70400AAA87489');
// If there is no red where there should or if the bank screen is already open.
if (not IsPinOpen or BankScreen) then
begin
Result := True;
Exit;
end;
for i := 1 to Length(Pin) do
begin
// just in case.
x := 395;
y := 175;
MMouse(395, 175, 10, 10);
Wait(100+Random(200));
bres := false;
// Try to find the digit bitmap.
bres := FindBitmapMaskTolerance(b[strtoint(Pin[i])], x, y, 26, 97, 423, 322, 10, 40);
if(bres = false) then
begin
bres := false;
// A second try.
bres := FindBitmapMaskTolerance(b[strtoint(Pin[i])], x, y, 26, 97, 423, 322, 10, 40);
if(bres = false) then
begin
Result := false;
Exit;
end;
end;
Wait(500 + Random(500));
// If the bitmap was found.
if(bres = true) then
begin
// Hit twice, fast, because otherwise sometimes it seems to fail.
Mouse(x+Random(2), y + Random(2), 2 , 0, True);
Sleep(25+Random(25));
Mouse(x+Random(2), y + Random(2), 2 , 0, True);
Wait(600+Random(100));
// Make sure the last digit was in fact entered.
// Note: Can't really check whether the last one was entered or not.
// It assumes it did, but you have to check whether the bank opened.
if(i = 1) then
begin
if(GetColor(435, 35) = 65535) then
begin
writeln('First digit failed');
Exit;
end;
end
else if(i = 2) then
begin
if(GetColor(452, 35) = 65535) then
begin
writeln('Second digit failed');
Exit;
end;
end
else if(i = 3) then
begin
if(GetColor(468, 35) = 65535) then
begin
writeln('Third digit failed');
end
else
begin
Result := true;
end;
end
end;
Wait(200+Random(200));
end;
end;