Results 1 to 9 of 9

Thread: Antiban Diagnostics Tool

  1. #1
    Join Date
    Dec 2011
    Posts
    2,142
    Mentioned
    221 Post(s)
    Quoted
    1067 Post(s)

    Default Antiban Diagnostics Tool

    Hi all,
    Here is a quick and simple tool I wrote today to help get a better sense of mouse behavior during my scripts, and highlight potential problems that could lead to a ban if left unchecked, like forgetting to add waits or click randomness.

    The include file adds several information tracking variables and an override to fastClick(), which is used by all or almost all (?) SRL-6 methods that click the mouse. Of course, this can easily be translated to OSRS includes, which I'll get to later. Warnings can be given during the script run, and statistics are reported on script termination.

    At this point it's only looking at clicks, but I am updating it with more behavioral analysis stuff when I get the chance, hence the more general title 'Antiban Diagnostics' for now.

    Current Features
    - Warns if distance between current click and previous click is below diagnostics.distanceWarningLevel (pixels, default 2)
    - Warns if time between current click and previous click is below diagnostics.timeWarningLevel (ms, default 200)
    - Warns if the script-requested click is out of bounds, and automatically prevents the click from happening unless diagnostics.preventOutOfBounds is set to false (default true)
    - Prints a final summary of click statistics when your script terminates, and also prints the entire list of warnings that happened during the run with timestamps
    - Visual plot of clicks performed, color coded to match the warnings so that you can actually see where the problems were happening (diagnostics.visuals())

    In Progress
    - More advanced and helpful distance warning system that incorporates click groupings and trends rather than standalone pairs, so you can see if in the long run your randomness is poor and you are probably getting pattern detected
    - Scoring/grading based on performance against pattern detection function (heuristics, neural net)
    - OSRS include version

    How to Use
    - Include the code below in any script (easiest to save to a file in Includes like diagnostics.simba and then add {$i diagnostics.simba} to your script, put this after SRL-6 is included)
    - At the start of your script, add diagnostics.init();
    - Optionally assign different values to the warning level variables (diagnostics.distanceWarningLevel, diagnostics.timeWarningLevel, diagnostics.preventOutOfBounds)
    - Use diagnostics.visuals() for visual plot

    Sample debug output of one of my scripts:
    Code:
    [AB Diagnostics] -- Final Report --
    [AB Diagnostics] Average time between clicks: 1288ms (Low: 485ms, High: 2703ms)
    [AB Diagnostics] Average distance between clicks: 143px (Low: 35px, High: 923px)
    [AB Diagnostics] Total Warnings: 0 TIME, 0 OUT OF BOUNDS, 0 DISTANCE
    [AB Diagnostics] -- End of Report --
    Sample warnings when I forced Simba to do silly things:
    Code:
    [AB Diagnostics] -- Final Report --
    [AB Diagnostics] Average time between clicks: 53ms (Low: 15ms, High: 485ms)
    [AB Diagnostics] Average distance between clicks: 41px (Low: 1px, High: 1177px)
    [AB Diagnostics] Total Warnings: 31 TIME, 0 OUT OF BOUNDS, 6 DISTANCE
    [AB Diagnostics] TIME WARNING (1): Time between clicks was 47ms! [@2469ms]
    [AB Diagnostics] TIME WARNING (2): Time between clicks was 78ms! [@2703ms]
    [AB Diagnostics] TIME WARNING (3): Time between clicks was 31ms! [@2938ms]
    [AB Diagnostics] DISTANCE WARNING (1): Script clicked around the same pixel, X = 1099, Y = 397 twice! [@3172ms]
    [AB Diagnostics] TIME WARNING (4): Time between clicks was 15ms! [@3172ms]
    [AB Diagnostics] TIME WARNING (5): Time between clicks was 47ms! [@3407ms]
    [AB Diagnostics] DISTANCE WARNING (2): Script clicked around the same pixel, X = 1097, Y = 400 twice! [@3610ms]
    [AB Diagnostics] TIME WARNING (6): Time between clicks was 47ms! [@3625ms]
    [AB Diagnostics] TIME WARNING (7): Time between clicks was 15ms! [@3797ms]
    [AB Diagnostics] TIME WARNING (8): Time between clicks was 16ms! [@4032ms]
    [AB Diagnostics] DISTANCE WARNING (3): Script clicked around the same pixel, X = 1096, Y = 402 twice! [@4203ms]
    [AB Diagnostics] TIME WARNING (9): Time between clicks was 15ms! [@4203ms]
    [AB Diagnostics] DISTANCE WARNING (4): Script clicked around the same pixel, X = 1097, Y = 402 twice! [@4407ms]
    [AB Diagnostics] TIME WARNING (10): Time between clicks was 16ms! [@4407ms]
    [AB Diagnostics] TIME WARNING (11): Time between clicks was 31ms! [@4578ms]
    [AB Diagnostics] TIME WARNING (12): Time between clicks was 32ms! [@4735ms]
    [AB Diagnostics] TIME WARNING (13): Time between clicks was 78ms! [@4875ms]
    [AB Diagnostics] TIME WARNING (14): Time between clicks was 47ms! [@5016ms]
    [AB Diagnostics] TIME WARNING (15): Time between clicks was 16ms! [@5219ms]
    [AB Diagnostics] TIME WARNING (16): Time between clicks was 62ms! [@5500ms]
    [AB Diagnostics] TIME WARNING (17): Time between clicks was 62ms! [@5750ms]
    [AB Diagnostics] TIME WARNING (18): Time between clicks was 16ms! [@5985ms]
    [AB Diagnostics] TIME WARNING (19): Time between clicks was 31ms! [@6078ms]
    [AB Diagnostics] TIME WARNING (20): Time between clicks was 31ms! [@6250ms]
    [AB Diagnostics] TIME WARNING (21): Time between clicks was 63ms! [@6532ms]
    [AB Diagnostics] DISTANCE WARNING (5): Script clicked around the same pixel, X = 1099, Y = 397 twice! [@6782ms]
    [AB Diagnostics] TIME WARNING (22): Time between clicks was 32ms! [@6782ms]
    [AB Diagnostics] TIME WARNING (23): Time between clicks was 31ms! [@6891ms]
    [AB Diagnostics] TIME WARNING (24): Time between clicks was 31ms! [@7047ms]
    [AB Diagnostics] DISTANCE WARNING (6): Script clicked around the same pixel, X = 1103, Y = 404 twice! [@7219ms]
    [AB Diagnostics] TIME WARNING (25): Time between clicks was 16ms! [@7235ms]
    [AB Diagnostics] TIME WARNING (26): Time between clicks was 31ms! [@7594ms]
    [AB Diagnostics] TIME WARNING (27): Time between clicks was 16ms! [@7813ms]
    [AB Diagnostics] TIME WARNING (28): Time between clicks was 31ms! [@8016ms]
    [AB Diagnostics] TIME WARNING (29): Time between clicks was 47ms! [@8172ms]
    [AB Diagnostics] TIME WARNING (30): Time between clicks was 63ms! [@8360ms]
    [AB Diagnostics] TIME WARNING (31): Time between clicks was 63ms! [@8641ms]
    [AB Diagnostics] -- End of Report --
    Sample of visual debug (all green crosses indicating no warnings):


    Here is the code for the tool (v1.1 - May 28th, 2018):

    Simba Code:
    {Antiban Diagnostics v1.1}
    {by Clarity}

    const
      WARNING_NONE = 0;
      WARNING_TIME = 1;
      WARNING_DISTANCE = 2;
      WARNING_BOUNDS = 3;

    type tEvent = record
      x, y, clickType, warningType: integer;
      timeStamp: uInt64;
    end;

    type tEventArray = array of tEvent;

    type tDiagnostics = record
      events: tEventArray;

      //Basic Statistics and Warnings
      TBCData, distanceData: tIntegerArray;
      warnings: tStringArray;
      warning: string;
      index, TBCLow, TBCHigh, TBCMean, timeWarningLevel, distanceWarningLevel,
      warningCountBounds, warningCountTime, warningCountDistance, clientW, clientH,
      prevX, prevY, distanceLow, distanceHigh, distanceMean: integer;
      TBC: tTimeMarker;
      preventOutOfBounds, debugEvents: boolean;
    end;

    var
      diagnostics: tDiagnostics;

    procedure tEventArray.append(const evt: tEvent);
    begin
      insert(evt, self, length(self));
    end;

    //Mouse Clicks
    procedure fastClick(button: integer); override;
    var
      x, y: integer;
      evt: tEvent;
    begin
      if (button = MOUSE_MOVE) then
        exit();

      getMousePos(x, y);

      //Event Recording for Pattern Recognition
      evt.x := x;
      evt.y := y;
      evt.clickType := button;
      evt.timeStamp := getTimeRunning();
      evt.warningType := WARNING_NONE;

      //Basic Statistics and Warnings
      if (x <= 0) or (y <= 0) or (x >= diagnostics.clientW) or (y >= diagnostics.clientH) then
      begin
        evt.warningType := WARNING_BOUNDS;
        inc(diagnostics.warningCountBounds);
        diagnostics.warning := '[AB Diagnostics] BOUNDS WARNING (' + toStr(diagnostics.warningCountBounds) + '): Mouse was instructed to click at X = ' + toStr(x) + ', Y = ' + toStr(y) + '! [@' + toStr(getTimeRunning()) + 'ms]';
        diagnostics.warnings.append(diagnostics.warning);
        writeln(diagnostics.warning);
        if diagnostics.preventOutOfBounds then
        begin
          writeln('[AB Diagnostics] Prevented click from occurring.  Check your script!');
          diagnostics.events.append(evt);
          exit();
        end;
      end;
      setLength(diagnostics.distanceData, length(diagnostics.distanceData) + 1);
      setLength(diagnostics.TBCData, length(diagnostics.TBCData) + 1);
      diagnostics.distanceData[diagnostics.index] := distance(x, y, diagnostics.prevX, diagnostics.prevY);
      if (diagnostics.distanceData[diagnostics.index] <= diagnostics.distanceWarningLevel) then
      begin
        evt.warningType := WARNING_DISTANCE;
        inc(diagnostics.warningCountDistance);
        diagnostics.warning := '[AB Diagnostics] DISTANCE WARNING (' + toStr(diagnostics.warningCountDistance) + '): Script clicked around the same pixel, X = ' + toStr(x) + ', Y = ' + toStr(y) + ' twice! [@' + toStr(getTimeRunning()) + 'ms]';
        diagnostics.warnings.append(diagnostics.warning);
        writeln(diagnostics.warning);
      end;
      diagnostics.TBCData[diagnostics.index] := diagnostics.TBC.getTime();
      if (diagnostics.TBCData[diagnostics.index] <= diagnostics.timeWarningLevel) then
      begin
        evt.warningType := WARNING_TIME;
        inc(diagnostics.warningCountTime);
        diagnostics.warning := '[AB Diagnostics] TIME WARNING (' + toStr(diagnostics.warningCountTime) + '): Time between clicks was ' + toStr(diagnostics.TBCData[diagnostics.index]) + 'ms! [@' + toStr(getTimeRunning()) + 'ms]';
        diagnostics.warnings.append(diagnostics.warning);
        writeln(diagnostics.warning);
      end;
      inc(diagnostics.index);
      diagnostics.prevX := x;
      diagnostics.prevY := y;

      holdMouse(x, y, button);

      wait(randomRange(60, 150));

      getMousePos(x, y);
      releaseMouse(x, y, button);

      diagnostics.TBC.reset();
      diagnostics.TBC.start();
      diagnostics.events.append(evt);
    end;

    function tEventArray.toTPA(): tPointArray;
    var
      i: integer;
    begin
      setLength(result, length(diagnostics.events));
      for i := 0 to high(diagnostics.events) do
        result[i] := point(diagnostics.events[i].x, diagnostics.events[i].y);
    end;

    //Reporting
    procedure tDiagnostics.visuals();
    var
      clusters: t2DPointArray;
      tmb: tMufasaBitmap;
      i, bmp, warningColor: integer;
    begin
      bmp := createBitmap(self.clientW, self.clientH);
      tmb := getMufasaBitmap(bmp);
      for i := 0 to high(events) do
      begin
        case events[i].warningType of
          WARNING_NONE: warningColor := clLime;
          WARNING_DISTANCE: warningColor := clOrange;
          WARNING_TIME: warningColor := clYellow;
          WARNING_BOUNDS: warningColor := clRed;
        end;
        tmb.drawCross(point(events[i].x, events[i].y), 5, warningColor);
      end;
      {clusters := clusterTPA(events.toTPA(), 20);
      for i := 0 to high(clusters) do
      begin
        tmb.drawPolygon(clusters[i].getConvexHull(), clWhite);
      end;}

      //tmb.drawPolygon(events.toTPA().getConvexHull(), clWhite);
      tmb.debug();
    end;

    procedure tDiagnostics.report();
    var
      i: integer;
    begin
      self.distanceLow := minA(self.distanceData);
      self.distanceHigh := maxA(self.distanceData);
      self.distanceMean := averageTIA(self.distanceData);
      self.TBCLow := minA(self.TBCData);
      self.TBCHigh := maxA(self.TBCData);
      self.TBCMean := averageTIA(self.TBCData);
      writeln('[AB Diagnostics] -- Final Report --');
      writeln('[AB Diagnostics] Average time between clicks: ' + toStr(self.TBCMean) + 'ms (Low: ' + toStr(self.TBCLow) + 'ms, High: ' + toStr(self.TBCHigh) + 'ms)');
      writeln('[AB Diagnostics] Average distance between clicks: ' + toStr(self.distanceMean) + 'px (Low: ' + toStr(self.distanceLow) + 'px, High: ' + toStr(self.distanceHigh) + 'px)');
      writeln('[AB Diagnostics] Total Warnings: ' + toStr(self.warningCountTime) + ' TIME, ' + toStr(self.warningCountBounds) + ' OUT OF BOUNDS, ' + toStr(self.warningCountDistance) + ' DISTANCE');

      for i := 0 to high(self.warnings) do
        writeln(self.warnings[i]);
      writeln('[AB Diagnostics] -- End of Report --');
      if self.debugEvents then
      begin
        writeln(' ');
        for i := 0 to high(events) do
          writeln(events[i]);
      end;
      self.visuals();
    end;

    //Wrapper
    procedure diagnosticsReport();
    begin
      diagnostics.report();
    end;

    //Init
    procedure tDiagnostics.init();
    begin
      getClientDimensions(self.clientW, self.clientH);
      addOnTerminate('diagnosticsReport');
      self.debugEvents := true;
      self.timeWarningLevel := 200;
      self.distanceWarningLevel := 2;
      self.preventOutOfBounds := true;
      self.TBC.reset();
      self.TBC.start();
    end;
    Last edited by Clarity; 05-28-2018 at 10:40 PM.

  2. #2
    Join Date
    Sep 2012
    Location
    Netherlands
    Posts
    2,745
    Mentioned
    193 Post(s)
    Quoted
    1465 Post(s)

    Default

    AB LEAKING?!
    @Kasi; @Sjoe; @The Killer; @Benny; @Ian;

  3. #3
    Join Date
    Feb 2012
    Location
    Canada
    Posts
    1,159
    Mentioned
    25 Post(s)
    Quoted
    433 Post(s)

  4. #4
    Join Date
    Jun 2014
    Location
    EastCoast
    Posts
    76
    Mentioned
    0 Post(s)
    Quoted
    31 Post(s)

    Default

    I was looking for something like this, nicely done!

  5. #5
    Join Date
    Dec 2006
    Location
    Program TEXAS home of AUTOERS
    Posts
    7,938
    Mentioned
    26 Post(s)
    Quoted
    236 Post(s)

    Default

    Creative and a useful tool for scripters.

  6. #6
    Join Date
    Dec 2011
    Posts
    2,142
    Mentioned
    221 Post(s)
    Quoted
    1067 Post(s)

    Default

    Quote Originally Posted by Hoodz View Post
    AB LEAKING?!
    @Kasi; @Sjoe; @The Killer; @Benny; @Ian;
    Lol.

    Quote Originally Posted by StickToTheScript View Post
    Oh my... This is fantastic! Great work, Clarity!
    Quote Originally Posted by P1nky View Post
    Creative and a useful tool for scripters.
    Quote Originally Posted by Wire View Post
    I was looking for something like this, nicely done!
    Thanks! Hope it is helpful for ya.

    Updated with visual plot option, will debug all click events after script termination, color coded based on warning/no warning. Also changed it to be based on a tDiagnostics type, so things are now diagnostics.report(), etc.

    Example of the basic visual debug atm:

  7. #7
    Join Date
    Apr 2012
    Posts
    3,359
    Mentioned
    34 Post(s)
    Quoted
    218 Post(s)

    Default

    Quote Originally Posted by Hoodz View Post
    AB LEAKING?!
    @Kasi; @Sjoe; @The Killer; @Benny; @Ian;
    Confirmed.

  8. #8
    Join Date
    Jun 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    cool stuff

  9. #9
    Join Date
    Jun 2009
    Posts
    12
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    5.5hrs.PNG

    This is so cool! I really wanted to see everywhere I had clicked in a session, this even colour codes it

    Although now I have this vast amount of information I have no Idea what to do with it ha.

    Attached is 5.5hrs of barb fishing, I did an procedure TMouse.Click(Button: Int32); override; for the mouse click and changed TBC to tstopwatch so it works on OSRS with SRL

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •