Jump to content
stencil

Client Problem

Recommended Posts

I have a client Called BlueStacks that runs app in windows. Im making a script to solve a puzle game. but my scar doesnt seem to recognize the client, because does weird things, and it returns color value -1 when pick it.

 

The script works with a static image in photoshop, so is not script problem, i think is client problem, i tried to do many things, like ActivateClient command, (had to return to 3.34 ver) but didnt work.

 

 

Any ideas? here is the cript anyways:

 

 

 

program LastPang;

const
OX = 365;
OY = 195;
Des = 50;

var
x, y: Integer;
Columna: Integer;
OX1, OY1: Integer;
ax, bx, cx: Integer;
ay, by, cy: Integer;
col1: Integer; 
col2: Integer;
Par: Integer;
Tolerance: Integer; 
Loop: Integer; 
Tol: Integer;


Procedure ClickClient;
Begin
  ClickMouse(50,59,mbLeft);
end;

Procedure WriteCol;
Begin
  WriteLn(IntToStr(col2));
end;

Procedure Move1;
Begin
 WriteCol;
 MoveMouse(cx,cy);
 wait(700);
 TerminateScript;
End;  



//Checks Columnas
Procedure CheckSolColA1;
Begin
cx:= bx+Des 
cy:= by-Des 
if FindColoredAreaTolerance(x, y, col2, cx, cy, (cx+10), (cy+10), 1, Tol) then
Move1;  
end;

Procedure CheckSolColA2;
Begin
cx:= bx+Des 
cy:= by+Des 
if FindColoredAreaTolerance(x, y, col2, cx, cy, (cx+10), (cy+10), 1, Tol) then
Move1;  
end; 

Procedure CheckSolColA3;
Begin
cx:= bx+(Des*2) 
cy:= by 
if FindColoredAreaTolerance(x, y, col2, cx, cy, (cx+10), (cy+10), 1, Tol) then
Move1;  
end; 

Procedure CheckSolColA4;
Begin
cx:= ax-Des 
cy:= ay-Des 
if FindColoredAreaTolerance(x, y, col2, cx, cy, (cx+10), (cy+10), 1, Tol) then
Move1;  
end;

Procedure CheckSolColA5;
Begin
cx:= ax-Des 
cy:= ay+Des 
if FindColoredAreaTolerance(x, y, col2, cx, cy, (cx+10), (cy+10), 3, Tol) then
Move1;  
end;

Procedure CheckSolColA6;
Begin
cx:= ax-(2*Des) 
cy:= ay 
if FindColoredAreaTolerance(x, y, col2, cx, cy, (cx+10), (cy+10), 3, Tol) then
Move1;  
end;





Procedure ColumnaSolA;
Begin
Tol:= 10;
Columna:= 0;
Repeat
Begin
Par := 0; 

Repeat
OX1:= OX;
OY1:= OY+(Columna*Des); 
ax := OX1+(Par*Des);
ay := OY1;
bx := OX1+((Par+1)*Des);
by := OY1;
col1:= GetColor(ax, ay);   
col2:= GetColor(bx, by); 
Tolerance:= GetTolerance(Col1, Col2); 
if Tolerance < 10 then 
    begin
      CheckSolColA1;       
      CheckSolColA2;
      CheckSolColA3;
      CheckSolColA4;
      CheckSolColA5;
      CheckSolColA6;
    end;

Inc(Par);  
until Par=6 ; 
end;   

Inc(Columna);  
until Columna=7 ;
end;     


//MainLoop
Begin
Wait(1000);
Loop:=0 ;
Repeat
ColumnaSolA; 
Inc(Loop);  
until Loop=2;
end.

 

 

this is the debbug

New client targeted (328706)
Successfully compiled (23,4278 ms)
-1

 

-1 is the color that returns with WriteCol procedure

 

any ideas would be aprreciated, the scripts contain some spanish words, cuz i speak spanish.

 

Thx

Link to comment
Share on other sites

You must use GetClient.Activate;, it is the new ActivateClient. ActivateClient is deprecated in 3.35+.

 

What this does is makes the client window the forthmost "active" window so that SCAR can do things with it.

 

e.g.

 

[scar]

var

x, y: Integer;

begin

GetClient.Activate;

if FindColor(x, y, 0, 0, 0, 50, 50) then

WriteLn('Woot' + ' ' + IntToStr(x) + ', ' + IntToStr(y));

end.

[/scar]

Link to comment
Share on other sites

I have the same problem:

 

[scar]

begin

Starttime:=Time

n:=0;

Wait (3000);

//activateclient;

wait (1000);

GetClient.Activate;

WRITER ('Starting!');

r:=1;

writer ('Color = '+inttostr(getcolor(508,32)));

Bmp := GetClient.Capture;

try

DebugBitmap(Bmp);

finally

Bmp.Free;

end;

repeat

if findcolor(x,y,3570052,507,31, 509,33)then Gogogo;

if getcolor(508,32)=5496048 then Gogogo;

wait(5000);

writer ('Color = '+inttostr(getcolor(508,32)));

getmousepos(x,y);

writer ('ColorMouse ('+inttostr(x)+','+inttostr(y)+') = '+inttostr(getcolor(x,y)));

until n=400;

end.[/scar]

 

Oh, by the way, writer is a custom procedure that includes some more details and time and so on.

 

What I get is every color as -1 (earlier with the old version of SCAR) and now as 0 and the following picture (it's not like that when I pick colors manually...):

14jw7qb.png

 

Help would be appreciated!

 

/Edit:

Oh, and the GetClient.Activate resizes my client. How come? I would rather have it maximised...

 

/Another Edit:

It appears that Bluestacks either uses OpenGL, DirectX or something similar, which is why it does not work. Is there any reasonable workaround?

Edited by Erpel
Link to comment
Share on other sites

You can try this:

 

[scar]var

OrigClient: TSCARWindowClient;

 

procedure UpdateClient;

var

OldClient: TSCARClient;

Client: TSCARWindowClient;

begin

OrigClient.Update;

Client := TSCARWindowClient.Create(GetDesktopWindow);

Client.InputArea := OrigClient.InputArea;

Client.ImageArea := OrigClient.InputArea;

OldClient := SetClient(Client);

if OldClient <> OrigClient then

OldClient.Free;

end;

 

procedure SetupClient;

var

Client: TSCARClient;

begin

Client := GetClient;

if not (Client is TSCARWindowClient) then

begin

WriteLn('Selected client isn''t a window!');

TerminateScript;

end;

OrigClient := TSCARWindowClient(Client);

UpdateClient;

end;

 

begin

SetupClient;

DebugBitmap(GetClient.Capture);

end.[/scar]

 

Just select the client with the crosshair before you run the script. Call SetupClient at the start of the script. If the window moves or w/e, which requires a client update, call UpdateClient.

 

The reason you get a black canvas is that that part of the window isn't drawn to the device context you're using. I can't guarantee it'll work, but my code above will probably work if you can see the client window when you pick a color. Either you do that or you have to figure out where the content of the window is drawn.

 

EDIT: Note that with this approach, the window HAS to be on top. So calling GetClient.Activate; at the start would also be a good idea.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
  • Create New...