Jump to content
shadowrecon

Animation Detection System

Recommended Posts

So after messing around with porting over SRL's animation detection system i stumbled upon a new way for detecting animation/pixel displacement. I figured id post this to see if anyone had any ideas on changes improvements?

 

Heres Working Method: // alot less lines than original method

[scar]{===============================================================================

RS2

Player Animation Detection System (PADS)

--------------------------------------------------------------------------------

* Function: PixelArea(B: TBox): T2DIntArray;

By: ShadowRecon.

* Function: PixelShift(B: TBox; T: Integer): Integer;

By: ShadowRecon.

* Function AveragePixelShift(b: TBox; waitPerLoop, maxTime: integer): Integer;

By: ShadowRecon,Coh3n.

* Function AnimationEx(B: TBox; MinT,MaxT, PixelShifts: Integer; North: Boolean): Boolean;

By: ShadowRecon.

* Function IsWalking:Boolean;

By: ShadowRecon.

* Function IsAnimating:Boolean;

By: ShadowRecon.

===============================================================================}

 

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

function PixelArea(B: TBox): T2DIntArray;

Description: Turns box into bitmap, and then get all colors found on Bitmap.

Contributors: ShadowRecon.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

function PixelArea(B: TBox): T2DIntArray;

var

PB, W, H: Integer;

Client: Hwnd;

begin

Try

Client := GetClientWindowHandle;

PB := BitmapFromString(B.X2 - B.X1, B.Y2 - B.Y1, '');

CopyClientToBitmap(PB, B.X1, B.Y1, B.X2, B.Y2);

SetTargetBitmap(PB);

GetBitmapSize(PB, W, H);

Result := GetBitmapAreaColors(0, 0, W - 1, H - 1);

SetClientWindowHandle(Client);

FreeBitmap(PB);

except end;

end;

 

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

function PixelShift(B: TBox; T: Integer): Integer;

Description: Takse 2 bitmaps and compares all colors. If color does not match then

it is treated as a pixel shift, and pixel's shifted is inc.

Contributors: ShadowRecon.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

function PixelShift(B: TBox; T: Integer): Integer;

var

PB, PB2 :T2DIntArray;

I, II, W, H :Integer;

begin

Try

W := (B.X2 - B.X1);

H := (B.Y2 - B.Y1);

PB := PixelArea(B);

Wait(T);

PB2 := PixelArea(B);

for I := 0 to W do

for II := 0 to H do

If PB[iI] <> PB2[iI] then

Inc(Result);

except

result := 0;

end;

end;

 

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Function AveragePixelShift(b: TBox; waitPerLoop, maxTime: integer): Integer;

Description: Gets the average pixel shift every 'waitPerLoop' ms over the time 'maxTime'

Contributors: ShadowRecon,Coh3n.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

function AveragePixelShift(b: TBox; waitPerLoop, maxTime: integer): Integer;

var

T: integer;

shifts: TIntArray;

begin

Try

T := (getSystemTime + maxTime);

 

while (getSystemTime < T) do

begin

setLength(shifts, length(shifts)+1);

shifts[high(shifts)] := pixelShift(b, waitPerLoop);

end;

 

Result := Round(TIAMean(shifts));

except

Result := 0;

finally

//Writeln('Average Pixel Shift: ' +IntToStr(Result));//debuging animations

end;

end;

 

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Function AnimationEx(North: Boolean): Boolean;

Description: Detects Animation, if North True Then Makes Compass North;

Contributors: ShadowRecon.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

Function AnimationEx(B: TBox; MinT,MaxT, PixelShifts: Integer; North: Boolean): Boolean;

Var

PS,A:Integer;

begin

Result := False;

 

if North then

begin

A := Round(GetCompassAngleDegrees);

if InRange(A,10,350) then

begin

MakeCompass(Dir_North);

Wait(450);

end;

end;

 

PS := AveragePixelShift(B,MinT,MaxT);

 

if (PS > PixelShifts) then // if this is true it exits.

begin

Result := True;

Exit;

end;

 

PS := AveragePixelShift(B,MinT,MaxT); // if the first time it wasnt true, then

// it checks one more time jsut incase..

if (PS > PixelShifts) then

begin

Result := True;

Exit;

end;

 

end;

 

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Function IsWalking:Boolean;

Description: Detects if player is Walking. Checks Mini Map for Pixel Changes.

Contributors: ShadowRecon.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

Function IsWalking:Boolean;

begin

Result := AnimationEx(Box(MMCX-30, MMCY-30, MMCX+30, MMCY+30),50,500,500,False);

end;

 

{=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Function IsAnimating:Boolean;

Description: Detects if player is animating.

Contributors: ShadowRecon.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=}

Function IsAnimating:Boolean;

begin

Result := AnimationEx(Box(MSCX-17, MSCY-24, MSCX+12, MSCY+12),100,500,30,False);

end; [/scar]

Edited by shadowrecon
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...