Results 1 to 7 of 7

Thread: Java/NXT and interface re-sizing?

  1. #1
    Join Date
    Oct 2007
    Posts
    187
    Mentioned
    7 Post(s)
    Quoted
    61 Post(s)

    Default Java/NXT and interface re-sizing?

    Since getting back into RS3 and finally starting to develop scripts, I've quite a few questions.

    First of all, does Jagex in any way track use of client choice from session to session? For instance, I mainly use NXT when i'm actually playing my character (I know I should have alts for botting, but it's only a game right? + I'm lazy AF), and switch to java when botting with simba/smart. Should I grab the official java client and discontinue use of NXT if i'm botting strictly with java?

    Next, I find myself switching back and forth between UI presets a LOT. I have a preset for normal use, and a preset for SRL use. Where should I start looking in order to dynamically allocate user-interface objects (backpack/abilitybar/etc.) for use with adjustable UI's? I've perused through the SRL-6 include files hoping to find something I can alter, but i'm a huge noob, so I don't really know what i'm looking at.

    @Clarity this is some of the stuff I was trying to chat with you about earlier on discord

  2. #2
    Join Date
    Dec 2010
    Posts
    483
    Mentioned
    30 Post(s)
    Quoted
    328 Post(s)

    Default

    I would say it's safe to assume that jagex can see which client you're connecting from since you request a different collection of assets.

    Having said that, there is overwhelming evidence to suggest that the java clients are of higher risk or more closely watched than the nxt client. Likely due to confidence in the nxt client as well as a lack of public nxt utilities.

    #TheBank2017

  3. #3
    Join Date
    Dec 2011
    Posts
    2,147
    Mentioned
    221 Post(s)
    Quoted
    1068 Post(s)

    Default

    Quote Originally Posted by klamor View Post
    @Clarity this is some of the stuff I was trying to chat with you about earlier on discord
    IIRC SRL-6 bases its layout knowledge on the actionbar, specifically detecting the actionbar corner button. From there, it uses a lot of offsets or just static XY values, making assumptions that you've followed the correct layout settings, in order to set the bounds of mainscreen, inventory, etc.

    These operations are found in the .__init() or .__find() or .__setup() functions, depending on the interface. For instance, see the code for determining mainscreen bounds:

    Simba Code:
    procedure TRSMainScreen.__setup();
    const
      PLAYER_BOX_WIDTH = 28;
      PLAYER_BOX_HEIGHT = 58;
    begin
      self.setBounds([0, 0, gameTabs.tabArea.x1-1, actionBar.y1-1]);
      self.playerPoint := middleBox([1, 1, 574, 387]); // the whole 3d gamescreen
      self.playerBox := [self.playerPoint.x - PLAYER_BOX_WIDTH div 2, self.playerPoint.y - PLAYER_BOX_HEIGHT div 2,
                         self.playerPoint.x + PLAYER_BOX_WIDTH div 2, self.playerPoint.y + PLAYER_BOX_HEIGHT div 2];
    end;

    When I modified it for resizable, I replaced the coordinate offsets with various combinations of search techniques (findDTMs, findBitmaps, findColors) that would arrive at the same relative coordinates.

    Note that unless you set your interface accordingly, the mainscreen will obviously not be rectangular/TBox as in OS layout, but a polygon region. So you can set the mainscreen bounds as the entire client dimensions if you're lazy, or change the mainscreen functions to work with a polygon area rather than a TBox.

    And, of course, miscellaneous functions like isLoggedIn() break because they look for a color at a specific point assuming OS layout. You have to figure out a new check for that.
    Last edited by Clarity; 09-25-2017 at 10:16 PM.

  4. #4
    Join Date
    Oct 2007
    Posts
    187
    Mentioned
    7 Post(s)
    Quoted
    61 Post(s)

    Default

    IIRC SRL-6 bases its layout knowledge on the actionbar
    I find this pretty ironic, considering most of SRL-6's actionbar functions are broken :P

    anyways, thanks for the help. It's a lot easier for me to bookmark a post than dig through the nonsense in discord

  5. #5
    Join Date
    Oct 2007
    Posts
    187
    Mentioned
    7 Post(s)
    Quoted
    61 Post(s)

    Default

    @Clarity
    I'm making some progess!



    do you have any suggestions for navigation? I'm having difficulties porting SPS-RS3 over
    Attached Images Attached Images

  6. #6
    Join Date
    May 2012
    Posts
    499
    Mentioned
    23 Post(s)
    Quoted
    228 Post(s)

    Default

    Quote Originally Posted by klamor View Post
    @Clarity
    I'm making some progess!



    do you have any suggestions for navigation? I'm having difficulties porting SPS-RS3 over
    Simba Code:
    {$loadlib sps}

    {$include_once srl-6/lib/interfaces/minimap.simba}
    {$include_once srl-6/lib/core/debug.simba}
    {$include_once srl-6/lib/core/players.simba}
    {$include_once srl-6/lib/utilities/drawing.simba}

    type
      TSPSArea = record
        __mapPath: string;
        __areaMap: T3DIntegerArray;
        _accuracy: integer;
        _tolerance, _minMatchPercent: extended;
        isSetup: boolean;
      end;

    const
      SPS_IMG_PATH = IncludePath + 'SPS\img\';
      SPS_IMG_FMT  = '.png';

    const
      RUNESCAPE_SURFACE = 'runescape_surface\';
      RUNESCAPE_OTHER = 'runescape_other\';

    const
      __DEFAULT_ACCURACY: integer = 4;
      __DEFAULT_TOLERANCE: extended = 600.0;
      __DEFAULT_MIN_MATCH_PERCENT: extended = 0.40;

    var
      spsAnyAngle: boolean = false;
      spsMultiMouse: boolean = true;

    var
      sps: TSPSArea;

    (*
      Returns the name of the TSPSArea variable.

      Example:
        writeln(sps.getName());
    *)

    function TSPSArea.getName(): string;
    begin
      result := GetGlobalName(@Self);
    end;

    (*
      Loads and setups the TSPSArea.

      Example:
        sps.setup('my_map_name', RUNESCAPE_SURFACE, 4, 600.0, 0.40);
      Example using default params:
        sps.setup('my_map_name', RUNESCAPE_SURFACE);
    *)

    procedure TSPSArea.setup(imgName, imgFolder: string; accuracy: integer = __DEFAULT_ACCURACY; tolerance: extended = __DEFAULT_TOLERANCE; minMatchPercent: extended = __DEFAULT_MIN_MATCH_PERCENT);
    var
      bmp: TMufasaBitmap;
      t: integer;
      m: extended;
    begin
      print(self.getName()+'.init()', TDebug.HEADER);

      t := getSystemTime();

      if (fileExists(SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT)) then
      begin
        print('Path exists ('+SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT+')');

        self._accuracy := accuracy;
        self._tolerance := tolerance;
        self._minMatchPercent := minMatchPercent;
        self.__mapPath := SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT;
        SetLength(self.__areaMap, 0);
       
        if (spsAnyAngle) then
          self._minMatchPercent := 0.10;

        try
          bmp.init(client.getMBitmaps());
          bmp.loadFromFile(self.__mapPath);

          SPS_BitmapToMap(bmp, self._accuracy, self.__areaMap);
        except
          print(self.getName()+'.setup(): Unable to load map or bitmap to map failed', TDebug.FATAL);
        finally
          bmp.free();
        end;

        self.isSetup := true;
      end else
        print(self.getName()+'.setup(): Unable to find map, searched path '+ SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT, TDebug.FATAL);

      print('Setup area "' + imgName + '" in ' + intToStr(getSystemTime() - t) + 'ms');
      print(self.getName()+'.init()', TDebug.FOOTER);
    end;

    (*
      Gathers a 140x140 bitmap of the minimap.

      Example:
        bmp := SPS_GatherMinimap(true, 50.0);
    *)

    function SPS_GatherMinimap(const rotated: boolean; const deg: extended): TMufasaBitmap;
    var
      temp: TMufasaBitmap;
    begin
      result.init();

      if (rotated) and (inRange(deg, 10.0, 350.0)) then
      begin
        temp.init();

        try
          temp.copyClientToBitmap(client.getIOManager(), true, minimap.cx - 70, minimap.cy - 70, minimap.cx + 70, minimap.cy + 70);
          temp.rotateBitmap(radians(deg), result);
        finally
          temp.free();
        end;
      end else
        result.copyClientToBitmap(client.getIOManager(), true, minimap.cx - 70, minimap.cy - 70, minimap.cx + 70, minimap.cy + 70);

      Result.ReplaceColor(0, 1);
    end;

    (*
      Debugs your players postion on the loaded map.

      Example:
        sps.debugPlayerPos();
    *)

    procedure TSPSArea.debugPlayerPos();
    var
      b: TBox;
      bmp, w, h, t, timeTook: integer;
      mid, pos: TPoint;
      mbp : TMufasaBitmap;
    begin
      t := getSystemTime();
      pos := self.getPlayerPos();
      timeTook := (getSystemTime() - t);

      if (pos.equals(point(-1, -1))) or (not isLoggedIn()) then
        exit();

      bmp := loadBitmap(self.__mapPath);

      if (bitmapExists(bmp)) then
      begin
        getBitmapSize(bmp, w, h);

        dec(w);
        dec(h);

        try // draw player pos, the minimap area and crop the bitmap
        mbp := getMufasaBitmap(bmp);
          mbp.drawCircle(pos, 2 , true, clLime);
          mbp.drawBox(intToBox(max(1, pos.x - 70), max(1, pos.y - 70),
                                       min(w, pos.x + 70), min(h, pos.y + 70)), false, clLime);

          cropBitmap(bmp, max(1, pos.x - 150), max(1, pos.y - 150), min(w, pos.x + 150), min(h, pos.y + 150));
        except
          print('Exception on drawing/cropping TSPSArea.debugPlayerPos()', TDebug.ERROR);
        end;

        getBitmapSize(bmp, w, h);
        setBitmapSize(bmp, mbp.getWidth() + 160, mbp.getHeight()); // add more width so we can print infomation on

        mbp.copyClientToBitmap(client.getIOManager(), false, w + 10, 10, // draw picture of client on bitmap
                                                minimap.cx - 70, minimap.cy - 70, minimap.cx + 70, minimap.cy + 70);

        mbp.drawText('Map: '+between('\', '.', between('runescape_', 'png', self.__mapPath)), point(w + 10, 160), clRed); // draw infomation
        mbp.drawText('Pos: ('+toStr(pos.x) + ', '+toStr(pos.y) + ')', point(w + 10, 180), clRed);
        mbp.drawText('Took: '+toStr(timeTook) + 'ms', point(w + 10, 200), clRed);

        debugBitmap(bmp);
        freeBitmap(bmp);
      end;
    end;

    (*
      Gets the players postion.

      Example:
        writeln(sps.getPlayerPos());
    *)

    function TSPSArea.getPlayerPos(): TPoint;
    var
      foundMatches, wid, hei, t: integer;
      bmp: TMufasaBitmap;
      map: T3DIntegerArray;
      p: TPoint;
      searches, a: extended;
    begin
      result := [-1, -1];

      if (not isLoggedIn()) then
        exit();

      if (not self.isSetup) then
      begin
        print('Unable to get players postion, sps isn''t setup', TDebug.ERROR);
        exit();
      end;

      t := getSystemTime();
      a := minimap.getAngleDegrees();

      if (inRange(a, 10.0, 350.0)) and (not spsAnyAngle) then
      begin
        print(self.getName()+'.getPlayerPos(): Angle is at '+floatToStr(a)+', Setting angle to 0 degrees');
        minimap.clickCompass();
      //  mainScreen.setAngle(MS_ANGLE_HIGH);
      end;

      bmp := SPS_GatherMinimap(spsAnyAngle, a);

      wid := bmp.getWidth();
      hei := bmp.getHeight();

      SPS_BitmapToMap(bmp, self._accuracy, map);

      if (length(map) > 0) then
      begin
        foundMatches := SPS_FindMapInMap(p.x, p.y, self.__areaMap, map, self._tolerance);
        searches := ((wid / self._accuracy) * (hei / self._accuracy));

        if ((foundMatches / searches) > self._minMatchPercent) then
        begin
          result.x := (p.x * self._accuracy + (wid div 2));
          result.y := (p.y * self._accuracy + (wid div 2));
        end else
          print(self.getName()+'.getPlayerPos(): Didn''t find enough matches accurately calc your postion', TDebug.WARNING);
      end;

      bmp.free();
      if (result = [-1, -1]) then
        writeLn('Failed finding position');
      print(self.getName()+'.getPlayerPos(): result = ' + toStr(result) + ', took ' + intToStr(getSystemTime() - t) + ' ms');
    end;

    (*
      Converts a postion onto the minimap, based on the players pos.

      Example:
        SPS_PosToMM(point(50, 50), sps.getPlayerPos(), p);
    *)

    function SPS_PosToMM(pos, playerPos: TPoint; out res: TPoint): boolean;
    var
      a: extended;
    begin
      if (spsAnyAngle) then
      begin
        a := minimap.getAngleRadians();

        if (not inRange(degrees(a), 8, 352)) then // no need to rotate
          res := Point(minimap.cx + pos.x - playerPos.x, minimap.cy + pos.y - playerPos.y)
        else
          res := rotatePoint(Point(minimap.cx + pos.x - playerPos.x, minimap.cy + pos.y - playerPos.y), a, minimap.cx, minimap.cy);
      end else
        res := Point(minimap.cx + pos.x - playerPos.x, minimap.cy + pos.y - playerPos.y);

      result := minimap.isPointOn(res);

      if (not result) then
        res := [-1, -1];
    end;

    (*
      Walks to postion 'pos', judged on the players postion.

      Example:
        sps.walkToPos(point(250, 250), sps.getPlayerPos());
    *)

    function TSPSArea.walkToPos(pos: TPoint; playerPos: TPoint; waitMoving: Boolean = True; shiftInterval: Integer = 500): boolean;
    var
      p: TPoint;
    begin
      result := false;

      if (SPS_PosToMM(pos, playerPos, p)) then
      begin
        result := true;

        // if distance is less than 10 then there is no real point walking.
        if (distance(p, minimap.getCenterPoint()) < 10) then
          exit;

        if (spsMultiMouse) then
          multiClick(p, 25, 3)
        else
          mouse(p, MOUSE_LEFT);

        if waitMoving then
        begin
          if (minimap.isFlagPresent(3000 + random(500))) then
            minimap.waitPlayerMoving(shiftInterval);

          if (minimap.isFlagPresent()) then  //case failed
            minimap.waitPlayerMoving(shiftInterval);
        end;
      end;

      print(self.getName()+'.walkToPos(): result = '+boolToStr(result));
    end;

    (*
      Overloaded function, reqiures no playerPos var, will automaticly call self.getPlayerPos().

      Example:
        sps.walkToPos(point(250, 250));
    *)

    function TSPSArea.walkToPos(pos: TPoint): boolean; overload;
    begin
      result := self.walkToPos(pos, self.getPlayerPos());
    end;

    (*
      Overloaded function, reqiures no playerPos var, will automaticly call
      self.getPlayerPos(), but has waitMoving parameter.

      Example:
        sps.walkToPos(point(250, 250));
    *)


    function TSPSArea.walkToPos(pos: TPoint; waitMoving: Boolean): boolean; overload;
    begin
      result := self.walkToPos(pos, self.getPlayerPos(), waitMoving);
    end;

    (*
      Walks a path of points.

      Example:
        sps.walkPath([point(50, 50), point(100, 100)]);
        sps.walkPath(PathToBank);
        sps.walkPath(PathToBank, False); // Won't wait until the player is not moving
    *)

    function TSPSArea.walkPath(path: TPointArray; waitMoving: Boolean = True; shiftInterval: Integer = 500): boolean;
    var
      p, lastPos, mmPoint: TPoint;
      t, fails, h, l, i: integer;
    begin
      result := false;;

      h := high(path);
      l := low(path);

      t := (getSystemTime() + randomRange(15000, 20000));

      repeat
        if (not isLoggedIn()) then
          exit(false);

        p := self.getPlayerPos();

        for i := h downto l do
          if (SPS_PosToMM(path[i], p, mmPoint)) then
          begin
            if (distance(minimap.getCenterPoint(), mmPoint) >= 10) then
            begin
              if (spsMultiMouse) then
                multiClick(mmPoint, 25, 3)
              else
                mouse(mmPoint, MOUSE_LEFT);

              if (minimap.isFlagPresent(2500 + random(500))) then
                minimap.waitFlag(10 + random(25));
            end;

            t := (getSystemTime() + randomRange(15000, 20000));

            result := (i = h) or (distance(path[i], path[h]) < 10);

            if (result) then
              break(2)
            else
              break();

          end;

        if (p.x = lastPos.x) and (p.y = lastPos.y) then
          inc(fails);
         
        lastPos := p;

      until (getSystemTime() > t) or (fails > 5);

      if waitMoving then
        if (minimap.isFlagPresent() or minimap.isPlayerMoving()) then
          minimap.waitPlayerMoving(shiftInterval);

      print(self.getName()+'.walkPath(): result = '+boolToStr(result));
    end;

    (*
      Walks blindly to point 'pos'.

      Example:
        sps.blindWalk(point(50, 50));
    *)

    function TSPSArea.blindWalk(pos: TPoint): boolean;
    var
      tries: integer;
      ctrlPoints: TPointArray;
      p: TPoint;
    begin
      result := false;

      repeat
        if (not isLoggedIn()) then
          exit();

        p := self.getPlayerPos();

        inc(tries);

        if ((tries) > 10) then
          break();
      until (not p.equals([-1, -1]));

      if (tries <= 10) then
      begin
        ctrlPoints := TPABetweenPoints(p, pos, 15 + random(25), 15);
        result := self.walkPath(ctrlPoints);
      end;

      print(self.getName()+'.blindWalk(): result = '+boolToStr(result));
    end;

    (*
      Returns true if the player is inside the TBox 'box'

      Example:
        myArea := intToBox(10, 10, 100, 150);
        sps.isInBox(myArea);
    *)

    function TSPSArea.isInBox(box: TBox): boolean;
    begin
      result := PointInBox(self.getPlayerPos(), box);
      print(self.getName() + '.isInBox: result = ' + boolToStr(result));
    end;

    (*
      Returns true if the player is inside the TBox **b**, if not it'll walk towards
      the center of the box.

      Example:
        fishArea := intToBox(10, 10, 100, 150);
        if sps.walkToBox(fishArea) then
          doSomeFishing();
    *)


    function TSPSArea.walkToBox(b: tbox): boolean;
    var
      pos: TPoint;
      x, y: integer;
    begin
      pos := self.getPlayerPos();

      if (pos.x = -1) or (pos.y = -1) then
        exit(false);

      result := pointInBox(pos, b);

      if (not result) then
      begin

          x := randomRange(0, gaussBox(b).x - pos.x);

          if (x > 75) then
            x := randomRange(65, 75)
          else if (x < -75) then
            x := randomRange(-65, -75)
          else if inRange(x, 1, 10) then
            x := randomRange(10, 20)
          else if inRange(x, -1, -10) then
            x := randomRange(-10, -20);

          y := randomRange(0, gaussBox(b).y - pos.y);

          if (y > 75) then
            y := randomRange(65, 75)
          else if (y < -75) then
            y := randomRange(-65, -75)
          else if inRange(y, 1, 10) then
            y := randomRange(10, 20)
          else if inRange(y, -1, -10) then
            y := randomRange(-10, -20);

        self.walkToPos(point(pos.x + x, pos.y + y), false);
      end;

      print('TSPSArea.walkToBox(): Result = ' + boolToStr(result));
    end;

    (*
      Returns true if the player is inside the TBox **b**, if not it'll walk towards
      the center of the box. But will repeat untill **waitTime** has been reached.

      Example:
        fishArea := intToBox(10, 10, 100, 150);
        if sps.walkToBox(fishArea, randomRange(5000, 7000)) then
          doSomeFishing();
    *)

    function TSPSArea.walkToBox(b: tbox; waitTime: integer): boolean; overload;
    var
      t: TCountDown;
      pos: TPoint;
    begin
      t.setTime(waitTime);

      repeat
        result := self.walkToBox(b);

        if (not result) then
          wait(randomRange(1200, 1800));

      until result or t.isFinished();

    print('TSPSArea.walkToBox(): Result = ' + boolToStr(result));
    end;

    (*
      Returns true if the player is inside the polygon 'polygon'

      Example:
        myPoly := [Point(10, 10), Point(15, 10), Point(25, 20)];
        sps.isInPolygon(myPoly);
    *)

    function TSPSArea.isInPolygon(polygon: TPointArray): boolean;
    var
      p: TPoint;
      i, j: integer;
    begin
      result := false;

      if (length(polygon) < 3) then
      begin
        print(self.getName() + '.isInPolygon: less than 3 vertice points in TPA', TDebug.ERROR);
        exit;
      end;

      p := self.getPlayerPos();
      j := high(polygon);

      for i := low(polygon) to high(polygon) do
      begin
        if ((((polygon[i].y <= p.y) and (p.y < polygon[j].y)) or ((polygon[j].y <= p.y) and
           (p.y < polygon[i].y)) ) and (p.x < ((polygon[j].x - polygon[i].x) *
           (p.y - polygon[i].y) / (polygon[j].y - polygon[i].y) + polygon[i].x))) then
           result := not result;

        j := i;
      end;

      print(self.getName() + '.isInPolygon: result = ' + boolToStr(result));
    end;

  7. #7
    Join Date
    Oct 2007
    Posts
    187
    Mentioned
    7 Post(s)
    Quoted
    61 Post(s)

    Default

    @Thomas the only modifications I made were changing the directories of the includes to fetch the includes that I've modified for re-sizeable nxt client.
    Simba Code:
    {$loadlib sps}

    {$include_once SRL-6-SIMBA1.2/lib/interfaces/minimap.simba}
    {$include_once SRL-6-SIMBA1.2/lib/core/debug.simba}
    {$include_once SRL-6-SIMBA1.2/lib/core/players.simba}
    {$include_once SRL-6-SIMBA1.2/lib/utilities/drawing.simba}

    type
      TSPSArea = record
        __mapPath: string;
        __areaMap: T3DIntegerArray;
        _accuracy: integer;
        _tolerance, _minMatchPercent: extended;
        isSetup: boolean;
      end;

    const
      SPS_IMG_PATH = IncludePath + 'SPS\img\';
      SPS_IMG_FMT  = '.png';

    const
      RUNESCAPE_SURFACE = 'runescape_surface\';
      RUNESCAPE_OTHER = 'runescape_other\';

    const
      __DEFAULT_ACCURACY: integer = 4;
      __DEFAULT_TOLERANCE: extended = 600.0;
      __DEFAULT_MIN_MATCH_PERCENT: extended = 0.40;

    var
      spsAnyAngle: boolean = false;
      spsMultiMouse: boolean = true;

    var
      sps: TSPSArea;

    (*
      Returns the name of the TSPSArea variable.

      Example:
        writeln(sps.getName());
    *)

    function TSPSArea.getName(): string;
    begin
      result := GetGlobalName(@Self);
    end;

    (*
      Loads and setups the TSPSArea.

      Example:
        sps.setup('my_map_name', RUNESCAPE_SURFACE, 4, 600.0, 0.40);
      Example using default params:
        sps.setup('my_map_name', RUNESCAPE_SURFACE);
    *)

    procedure TSPSArea.setup(imgName, imgFolder: string; accuracy: integer = __DEFAULT_ACCURACY; tolerance: extended = __DEFAULT_TOLERANCE; minMatchPercent: extended = __DEFAULT_MIN_MATCH_PERCENT);
    var
      bmp: TMufasaBitmap;
      t: integer;
      m: extended;
    begin
      print(self.getName()+'.init()', TDebug.HEADER);

      t := getSystemTime();

      if (fileExists(SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT)) then
      begin
        print('Path exists ('+SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT+')');

        self._accuracy := accuracy;
        self._tolerance := tolerance;
        self._minMatchPercent := minMatchPercent;
        self.__mapPath := SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT;
        SetLength(self.__areaMap, 0);
       
        if (spsAnyAngle) then
          self._minMatchPercent := 0.10;

        try
          bmp.init(client.getMBitmaps());
          bmp.loadFromFile(self.__mapPath);

          SPS_BitmapToMap(bmp, self._accuracy, self.__areaMap);
        except
          print(self.getName()+'.setup(): Unable to load map or bitmap to map failed', TDebug.FATAL);
        finally
          bmp.free();
        end;

        self.isSetup := true;
      end else
        print(self.getName()+'.setup(): Unable to find map, searched path '+ SPS_IMG_PATH + imgFolder + imgName + SPS_IMG_FMT, TDebug.FATAL);

      print('Setup area "' + imgName + '" in ' + intToStr(getSystemTime() - t) + 'ms');
      print(self.getName()+'.init()', TDebug.FOOTER);
    end;

    (*
      Gathers a 140x140 bitmap of the minimap.

      Example:
        bmp := SPS_GatherMinimap(true, 50.0);
    *)

    function SPS_GatherMinimap(const rotated: boolean; const deg: extended): TMufasaBitmap;
    var
      temp: TMufasaBitmap;
    begin
      result.init();

      if (rotated) and (inRange(deg, 10.0, 350.0)) then
      begin
        temp.init();

        try
          temp.copyClientToBitmap(client.getIOManager(), true, minimap.cx - 70, minimap.cy - 70, minimap.cx + 70, minimap.cy + 70);
          temp.rotateBitmap(radians(deg), result);
        finally
          temp.free();
        end;
      end else
        result.copyClientToBitmap(client.getIOManager(), true, minimap.cx - 70, minimap.cy - 70, minimap.cx + 70, minimap.cy + 70);

      Result.ReplaceColor(0, 1);
    end;

    (*
      Debugs your players postion on the loaded map.

      Example:
        sps.debugPlayerPos();
    *)

    procedure TSPSArea.debugPlayerPos();
    var
      b: TBox;
      bmp, w, h, t, timeTook: integer;
      mid, pos: TPoint;
    begin
      t := getSystemTime();
      pos := self.getPlayerPos();
      timeTook := (getSystemTime() - t);

      if (pos.equals(point(-1, -1))) or (not isLoggedIn()) then
        exit();

      bmp := loadBitmap(self.__mapPath);

      if (bitmapExists(bmp)) then
      begin
        getBitmapSize(bmp, w, h);

        dec(w);
        dec(h);

        try // draw player pos, the minimap area and crop the bitmap
          getMufasaBitmap(bmp).drawCircle(pos, 2 , true, clLime);
          getMufasaBitmap(bmp).drawBox(intToBox(max(1, pos.x - 70), max(1, pos.y - 70),
                                       min(w, pos.x + 70), min(h, pos.y + 70)), false, clLime);

          cropBitmap(bmp, max(1, pos.x - 150), max(1, pos.y - 150), min(w, pos.x + 150), min(h, pos.y + 150));
        except
          print('Exception on drawing/cropping TSPSArea.debugPlayerPos()', TDebug.ERROR);
        end;

        getBitmapSize(bmp, w, h);
        setBitmapSize(bmp, getMufasaBitmap(bmp).getWidth() + 160, getMufasaBitmap(bmp).getHeight()); // add more width so we can print infomation on

        getMufasaBitmap(bmp).copyClientToBitmap(client.getIOManager(), false, w + 10, 10, // draw picture of client on bitmap
                                                minimap.cx - 70, minimap.cy - 70, minimap.cx + 70, minimap.cy + 70);

        getMufasaBitmap(bmp).drawText('Map: '+between('\', '.', between('runescape_', 'png', self.__mapPath)), point(w + 10, 160), clRed); // draw infomation
        getMufasaBitmap(bmp).drawText('Pos: ('+toStr(pos.x) + ', '+toStr(pos.y) + ')', point(w + 10, 180), clRed);
        getMufasaBitmap(bmp).drawText('Took: '+toStr(timeTook) + 'ms', point(w + 10, 200), clRed);

        debugBitmap(bmp);
        freeBitmap(bmp);
      end;
    end;

    (*
      Gets the players postion.

      Example:
        writeln(sps.getPlayerPos());
    *)

    function TSPSArea.getPlayerPos(): TPoint;
    var
      foundMatches, wid, hei, t: integer;
      bmp: TMufasaBitmap;
      map: T3DIntegerArray;
      p: TPoint;
      searches, a: extended;
    begin
      result := [-1, -1];

      if (not isLoggedIn()) then
        exit();

      if (not self.isSetup) then
      begin
        print('Unable to get players postion, sps isn''t setup', TDebug.ERROR);
        exit();
      end;

      t := getSystemTime();
      a := minimap.getAngleDegrees();

      if (inRange(a, 10.0, 350.0)) and (not spsAnyAngle) then
      begin
        print(self.getName()+'.getPlayerPos(): Angle is at '+floatToStr(a)+', Setting angle to 0 degrees');
        minimap.clickCompass();
      //  mainScreen.setAngle(MS_ANGLE_HIGH);
      end;

      bmp := SPS_GatherMinimap(spsAnyAngle, a);

      wid := bmp.getWidth();
      hei := bmp.getHeight();

      SPS_BitmapToMap(bmp, self._accuracy, map);

      if (length(map) > 0) then
      begin
        foundMatches := SPS_FindMapInMap(p.x, p.y, self.__areaMap, map, self._tolerance);
        searches := ((wid / self._accuracy) * (hei / self._accuracy));

        if ((foundMatches / searches) > self._minMatchPercent) then
        begin
          result.x := (p.x * self._accuracy + (wid div 2));
          result.y := (p.y * self._accuracy + (wid div 2));
        end else
          print(self.getName()+'.getPlayerPos(): Didn''t find enough matches accurately calc your postion', TDebug.WARNING);
      end;

      bmp.free();

      print(self.getName()+'.getPlayerPos(): result = ' + toStr(result) + ', took ' + intToStr(getSystemTime() - t) + ' ms');
    end;

    (*
      Converts a postion onto the minimap, based on the players pos.

      Example:
        SPS_PosToMM(point(50, 50), sps.getPlayerPos(), p);
    *)

    function SPS_PosToMM(pos, playerPos: TPoint; out res: TPoint): boolean;
    var
      a: extended;
    begin
      if (spsAnyAngle) then
      begin
        a := minimap.getAngleRadians();

        if (not inRange(degrees(a), 8, 352)) then // no need to rotate
          res := Point(minimap.cx + pos.x - playerPos.x, minimap.cy + pos.y - playerPos.y)
        else
          res := rotatePoint(Point(minimap.cx + pos.x - playerPos.x, minimap.cy + pos.y - playerPos.y), a, minimap.cx, minimap.cy);
      end else
        res := Point(minimap.cx + pos.x - playerPos.x, minimap.cy + pos.y - playerPos.y);

      result := minimap.isPointOn(res);

      if (not result) then
        res := [-1, -1];
    end;

    (*
      Walks to postion 'pos', judged on the players postion.

      Example:
        sps.walkToPos(point(250, 250), sps.getPlayerPos());
    *)

    function TSPSArea.walkToPos(pos: TPoint; playerPos: TPoint; waitMoving: Boolean = True; shiftInterval: Integer = 500): boolean;
    var
      p: TPoint;
    begin
      result := false;

      if (SPS_PosToMM(pos, playerPos, p)) then
      begin
        result := true;

        // if distance is less than 10 then there is no real point walking.
        if (distance(p, minimap.getCenterPoint()) < 10) then
          exit;

        if (spsMultiMouse) then
          multiClick(p, 25, 3)
        else
          mouse(p, MOUSE_LEFT);

        if waitMoving then
        begin
          if (minimap.isFlagPresent(3000 + random(500))) then
            minimap.waitPlayerMoving(shiftInterval);

          if (minimap.isFlagPresent()) then  //case failed
            minimap.waitPlayerMoving(shiftInterval);
        end;
      end;

      print(self.getName()+'.walkToPos(): result = '+boolToStr(result));
    end;

    (*
      Overloaded function, reqiures no playerPos var, will automaticly call self.getPlayerPos().

      Example:
        sps.walkToPos(point(250, 250));
    *)

    function TSPSArea.walkToPos(pos: TPoint): boolean; overload;
    begin
      result := self.walkToPos(pos, self.getPlayerPos());
    end;

    (*
      Overloaded function, reqiures no playerPos var, will automaticly call
      self.getPlayerPos(), but has waitMoving parameter.

      Example:
        sps.walkToPos(point(250, 250));
    *)


    function TSPSArea.walkToPos(pos: TPoint; waitMoving: Boolean): boolean; overload;
    begin
      result := self.walkToPos(pos, self.getPlayerPos(), waitMoving);
    end;

    (*
      Walks a path of points.

      Example:
        sps.walkPath([point(50, 50), point(100, 100)]);
        sps.walkPath(PathToBank);
        sps.walkPath(PathToBank, False); // Won't wait until the player is not moving
    *)

    function TSPSArea.walkPath(path: TPointArray; waitMoving: Boolean = True; shiftInterval: Integer = 500): boolean;
    var
      p, lastPos, mmPoint: TPoint;
      t, fails, h, l, i: integer;
    begin
      result := false;;

      h := high(path);
      l := low(path);

      t := (getSystemTime() + randomRange(15000, 20000));

      repeat
        if (not isLoggedIn()) then
          exit(false);

        p := self.getPlayerPos();

        for i := h downto l do
          if (SPS_PosToMM(path[i], p, mmPoint)) then
          begin
            if (distance(minimap.getCenterPoint(), mmPoint) >= 10) then
            begin
              if (spsMultiMouse) then
                multiClick(mmPoint, 25, 3)
              else
                mouse(mmPoint, MOUSE_LEFT);

              if (minimap.isFlagPresent(2500 + random(500))) then
                minimap.waitFlag(10 + random(25));
            end;

            t := (getSystemTime() + randomRange(15000, 20000));

            result := (i = h) or (distance(path[i], path[h]) < 10);

            if (result) then
              break(2)
            else
              break();

          end;

        if (p.x = lastPos.x) and (p.y = lastPos.y) then
          inc(fails);
         
        lastPos := p;

      until (getSystemTime() > t) or (fails > 5);

      if waitMoving then
        if (minimap.isFlagPresent() or minimap.isPlayerMoving()) then
          minimap.waitPlayerMoving(shiftInterval);

      print(self.getName()+'.walkPath(): result = '+boolToStr(result));
    end;

    (*
      Walks blindly to point 'pos'.

      Example:
        sps.blindWalk(point(50, 50));
    *)

    function TSPSArea.blindWalk(pos: TPoint): boolean;
    var
      tries: integer;
      ctrlPoints: TPointArray;
      p: TPoint;
    begin
      result := false;

      repeat
        if (not isLoggedIn()) then
          exit();

        p := self.getPlayerPos();

        inc(tries);

        if ((tries) > 10) then
          break();
      until (not p.equals([-1, -1]));

      if (tries <= 10) then
      begin
        ctrlPoints := TPABetweenPoints(p, pos, 15 + random(25), 15);
        result := self.walkPath(ctrlPoints);
      end;

      print(self.getName()+'.blindWalk(): result = '+boolToStr(result));
    end;

    (*
      Returns true if the player is inside the TBox 'box'

      Example:
        myArea := intToBox(10, 10, 100, 150);
        sps.isInBox(myArea);
    *)

    function TSPSArea.isInBox(box: TBox): boolean;
    begin
      result := PointInBox(self.getPlayerPos(), box);
      print(self.getName() + '.isInBox: result = ' + boolToStr(result));
    end;

    (*
      Returns true if the player is inside the TBox **b**, if not it'll walk towards
      the center of the box.

      Example:
        fishArea := intToBox(10, 10, 100, 150);
        if sps.walkToBox(fishArea) then
          doSomeFishing();
    *)


    function TSPSArea.walkToBox(b: tbox): boolean;
    var
      pos: TPoint;
      x, y: integer;
    begin
      pos := self.getPlayerPos();

      if (pos.x = -1) or (pos.y = -1) then
        exit(false);

      result := pointInBox(pos, b);

      if (not result) then
      begin

          x := randomRange(0, gaussBox(b).x - pos.x);

          if (x > 75) then
            x := randomRange(65, 75)
          else if (x < -75) then
            x := randomRange(-65, -75)
          else if inRange(x, 1, 10) then
            x := randomRange(10, 20)
          else if inRange(x, -1, -10) then
            x := randomRange(-10, -20);

          y := randomRange(0, gaussBox(b).y - pos.y);

          if (y > 75) then
            y := randomRange(65, 75)
          else if (y < -75) then
            y := randomRange(-65, -75)
          else if inRange(y, 1, 10) then
            y := randomRange(10, 20)
          else if inRange(y, -1, -10) then
            y := randomRange(-10, -20);

        self.walkToPos(point(pos.x + x, pos.y + y), false);
      end;

      print('TSPSArea.walkToBox(): Result = ' + boolToStr(result));
    end;

    (*
      Returns true if the player is inside the TBox **b**, if not it'll walk towards
      the center of the box. But will repeat untill **waitTime** has been reached.

      Example:
        fishArea := intToBox(10, 10, 100, 150);
        if sps.walkToBox(fishArea, randomRange(5000, 7000)) then
          doSomeFishing();
    *)

    function TSPSArea.walkToBox(b: tbox; waitTime: integer): boolean; overload;
    var
      t: TCountDown;
      pos: TPoint;
    begin
      t.setTime(waitTime);

      repeat
        result := self.walkToBox(b);

        if (not result) then
          wait(randomRange(1200, 1800));

      until result or t.isFinished();

    print('TSPSArea.walkToBox(): Result = ' + boolToStr(result));
    end;

    (*
      Returns true if the player is inside the polygon 'polygon'

      Example:
        myPoly := [Point(10, 10), Point(15, 10), Point(25, 20)];
        sps.isInPolygon(myPoly);
    *)

    function TSPSArea.isInPolygon(polygon: TPointArray): boolean;
    var
      p: TPoint;
      i, j: integer;
    begin
      result := false;

      if (length(polygon) < 3) then
      begin
        print(self.getName() + '.isInPolygon: less than 3 vertice points in TPA', TDebug.ERROR);
        exit;
      end;

      p := self.getPlayerPos();
      j := high(polygon);

      for i := low(polygon) to high(polygon) do
      begin
        if ((((polygon[i].y <= p.y) and (p.y < polygon[j].y)) or ((polygon[j].y <= p.y) and
           (p.y < polygon[i].y)) ) and (p.x < ((polygon[j].x - polygon[i].x) *
           (p.y - polygon[i].y) / (polygon[j].y - polygon[i].y) + polygon[i].x))) then
           result := not result;

        j := i;
      end;

      print(self.getName() + '.isInPolygon: result = ' + boolToStr(result));
    end;

    I'm not even trying to use any methods yet, just declaring the include via:
    Code:
    {$I SPS/LIB/SPS-RS3.simba}
    It refuses to compile, and points me to line 155 within SPS-RS3.simba stating "Error: Variable expected"

    Simba Code:
    getMufasaBitmap(bmp).drawCircle(pos, 2 , true, clLime);

    It seems like an issue cause by me using NAS rather than SMART. Am I correct in this assumption? Is there a way to get around this?

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
  •