Advertisement
WarPie90

PinScreen.InputPin update

May 31st, 2018
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 4.28 KB | None | 0 0
  1. program new;
  2. {$I SRL/OSR.simba}
  3.  
  4. // ----------------------------------------------------------------------------
  5. // Searches for the number boxes for a ceritan amount of time
  6. function TRSPinScreen.FindButtons(out Buttons: TBoxArray; SearchTime: Int32): Boolean;
  7. var
  8.   i: Int32;
  9.   TPA: TPointArray;
  10.   ATPA: T2DPointArray;
  11.   t: TCountDown;
  12. begin
  13.   t.Init(SearchTime);
  14.   repeat
  15.     if srl.FindColors(TPA, CTS2(988769, 10, 0.06, 1.28), MainScreen.GetBounds) then
  16.     begin
  17.       ATPA := TPA.Cluster(4);
  18.       ATPA.FilterDimensions(45,45, 70,70);
  19.  
  20.       for i:=0 to High(ATPA) do
  21.         Buttons += ATPA[i].Bounds();
  22.  
  23.       if (Length(Buttons) >= 10) then
  24.         Exit(True);
  25.     end;
  26.   until t.IsFinished();
  27. end;
  28.  
  29. // ----------------------------------------------------------------------------
  30. // Sorts the boxes, so that box[0] contains the number 0, and so on
  31. // will wait for 4 seconds, or until the text appears
  32. function TRSPinScreen.SortButtons(var Buttons: TBoxArray; SearchTime: Int32): Boolean;
  33. var
  34.   i,j,count: Int32;
  35.   p: TPoint;
  36.   TBA: TBoxArray;
  37.   _: TPointArray;
  38.   t: TCountDown;
  39. begin
  40.   TBA := Copy(Buttons);
  41.   Buttons := [];
  42.  
  43.   // wait for text to appear in the boxes
  44.   t.Init(SearchTime);
  45.   repeat
  46.     count := 0;
  47.     for i:=0 to High(TBA) do
  48.       if (srl.FindColors(_, CTS1(32767,16), TBA[i]) > 0) then
  49.         Inc(count);
  50.     Wait(100,150);
  51.   until t.IsFinished() or (count >= 9);
  52.  
  53.   // ensure that we found acceptable amount of pixels
  54.   if (count < 9) then
  55.     Exit(False);
  56.  
  57.   // now order the boxes so that Buttons[4] is the button for the number 4, and so on.
  58.   SetLength(Buttons, 10);
  59.   count := 0;
  60.   for i:=0 to 9 do
  61.     for j:=0 to High(TBA) do
  62.       if srl.FindText(p, ToStr(i), 'UpChars07_s', 32767, 16, TBA[j].ExpandFunc(4)) then
  63.       begin
  64.         Buttons[i] := TBA[j];
  65.         TBA.Del(j);
  66.         Inc(count);
  67.         Break;
  68.       end;
  69.  
  70.   // if the mouse is over a number, it will disappear, this trick "guesses it"
  71.   for i:=0 to 9 do
  72.     if (TBA <> []) and (Buttons[i] = []) then
  73.     begin
  74.       Buttons[i] := TBA[0];
  75.       Inc(count);
  76.       Break;
  77.     end;
  78.  
  79.   // only return true if 10 numbers was added
  80.   Result := (count = 10);
  81. end;
  82.  
  83. // ----------------------------------------------------------------------------
  84. // Debugging is always nice to have, and exists within the various interfaces
  85. procedure TRSPinScreen.Debug();
  86. var
  87.   i: Int32;
  88.   buttons: TBoxArray;
  89.   muf: TMufasaBitmap;
  90. begin
  91.   muf := GetMufasaBitmap(BitmapFromClient(srl.DefaultClientBounds));
  92.  
  93.   FindButtons(buttons, Random(3000,4500));
  94.   SortButtons(buttons, Random(4000,6500));
  95.   for i:=0 to High(buttons) do
  96.   begin
  97.     muf.DrawBox(buttons[i], False, $00FF00);
  98.     muf.DrawText(ToStr(i), Point(buttons[i].X1+5, buttons[i].Y1+5), $00FF00);
  99.   end;
  100.  
  101.   muf.Debug();
  102. end;
  103.  
  104. // ----------------------------------------------------------------------------
  105. // Select that one key
  106. function TRSPinScreen.SelectKey(x: Int32): Boolean;
  107. var
  108.   i: Int32;
  109.   buttons: TBoxArray;
  110. begin
  111.   if (not FindButtons(buttons, Random(3000,4500))) then
  112.     Exit(srl.WriteLn('Pinscreen.FindButtons Failed', False));
  113.  
  114.   if (not SortButtons(buttons, Random(4000,6500))) then
  115.     Exit(srl.WriteLn('Pinscreen.SortButtons Failed', False));
  116.  
  117.   Mouse.Move(buttons[x]);
  118.   Wait(90, 1000, wdLeft);
  119.   Mouse.Click(buttons[x], MOUSE_LEFT);
  120.  
  121.   //if Random(4) = 0 then
  122.   //begin
  123.   //  Wait(50,120);
  124.   //  Mouse.Move(buttons[Random(10)]);
  125.   //  Wait(460, 1400, wdLeft);
  126.   //end;
  127.  
  128.   Result := True;
  129. end;
  130.  
  131. // ----------------------------------------------------------------------------
  132. // Input the given pin sequence
  133. function TRSPinScreen.InputPin(pin: String): Boolean;
  134. var
  135.   i: Int32;
  136.   b: TBoxArray;
  137.   t: TCountDown;
  138.   p: TPoint;
  139.   atStage: Boolean;
  140.   stages: TStringArray = ['First', 'Now', 'Time', 'Finally'];
  141. begin
  142.   for i:=0 to High(stages) do
  143.   begin
  144.     atStage := False;
  145.     t.Init(Random(3500, 5000));
  146.     while(not t.IsFinished()) do
  147.       if (atStage := srl.FindText(p, stages[i], 'UpChars07_s', Box(100, 80, 380, 100))) then
  148.         Break;
  149.  
  150.     if (not atStage) or (not SelectKey(StrToInt(pin[i+1]))) then
  151.       Exit(False);
  152.  
  153.     Wait(90,1000, wdLeft);
  154.   end;
  155.  
  156.   Result := True;
  157. end;
  158.  
  159. begin
  160.   WriteLn PinScreen.InputPin('1234'); //set your pin, and run
  161. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement