# Thread: [OSR] Walking & positioning system

1. ## [OSR] Walking & positioning system

Presenting RSWalker (RSW)

What is RSW?

• It can give you the pixel/point where you are standing (on the world map) with decent accuracy.
• It allows you to walk long distances as well as short once.
• It uses image-processing to locate your position (image cross-correlation) (color)
• It does not use reflection, and works without SMART.
• It can, if preferred scan through your memory to find a map-chunk of the area your are in (works in official client, as well as in SMART) this is used to speed it up.
• It's quite fast!

Motivation

First of SPS doesn't really work for OSR, and some has turned to use some proto-typeish code I wrote some time ago (the so-called SEWalker) which ain't that much better then SPS. Due to this I figured I had to try to make something that works well, and the fact that @Olly kept bugging me about writing a new walker weighted in a bit, I guess.

The performance was better than what I initially expected (before I started working on it): Every test I've ran seems to have been able to quite precisely pinpoint my position (we are talking off by a few tiles at worst), and if I recall correctly it used around 50-60ms on my computer to find my world-position (yes, with the whole world map loaded), tho all my tests are with memory scanning enabled, and that increases the speed and accuracy.

"Memory scanning"?

Some boring text..
The idea was simple, many of us has used tools like Cheat-Engine to find stored values in a single-player games (then modify it eg to get a bit more money ingame). RSW uses the same technique as Cheat-Engine uses to search through the memory owned by any process for a particular value (it doesn't modify anything). This is quite straight forward, and I believe it's fairly safe to do so, you are just parsing through your computes own RAM, right (no fancy-schmacy stuff).

The steps we take:
1. Search for a bitmap in the client using for example known information like the images size, then store it's address. This search must be insensitive to changes like reordering of class-fields.
2. Grab your ingame minimap (the normal way), and cross-correlates that image to the chunk we grabbed from the clients memory.
-- Proceed to extract the best highest rated match from the cross-correlation. Call it our "local position",
-- This is quite useless by itself since it's varies.
3. We crop out a 200x200 bitmap around the "local position" from the chunk we grabbed (This gives us a nice looking ~200x200 bitmap around our player).
4. Using that 200x200 minimap, we cross-correlate it with the "world map" (a map image loaded when you initialized RSWalker).
5. -- Again, we proceed to extract the highest rated match. The result of this is our global position.

The the correlation of our new 200x200 minimap to the world map only happens every time the image in the clients memory is changed, this saves us a lot of time.

How to use in a script

So, version 1 and beyond will be specialized towards SRL, and requires a Simba 1.2 build which you just use instead of your regular Simba (place it in the same old folder).
delphi Code:
{$I SRL/OSR.simba}{$I RSWalker/Walker.simba}var  RSW: TRSWalker;  path: TPointArray;begin  //How to init depends on your usage:  //* Default    : RSW.Init('world.png');            { Automatic detection }  //* if SMART   : RSW.Init('world.png', SMART.PID); { or whatever it's named in your include }  //* no memscan : RSW.Init('world.png', -1);  RSW.Init('world.png');  AddOnTerminate(@RSW.Free); // automatic free once script shuts down  //alternative setup (default works fine tho)  RSW.skipClose := 25;    //how close to the target point before we try to click the next point.    path := [Point(4171, 3457), Point(4136, 3444)]; //some pathend.

Use it to get your world position

Should be quite simple:
1. initialize it with the world bitmap you have (there is one shipped with RSW: world.png)
2. call MyWalker.GetMyPos();
delphi Code:
{$I SRL/OSR.simba}{$I RSWalker/Walker.simba}var  RSW:TRSWalker;  t:UInt32;begin  RSW.Init('world.png');  WriteLn('RSW is setup!');  // The first scan is a lot slower then the next scans, it's used to setup stuff..  t := GetTimeRunning();  WriteLn('I am here: ', RSW.GetMyPos(), ' used: ', GetTimeRunning()-t,'ms');  // scan again.. this time it will be pretty much "instant".. same for all of the future times.  t := GetTimeRunning();  WriteLn('I am here: ', RSW.GetMyPos(), ' used: ', GetTimeRunning()-t,'ms');  // one more time to prove my point..:  t := GetTimeRunning();  WriteLn('I am still here: ', RSW.GetMyPos(), ' used: ', GetTimeRunning()-t,'ms');  RSW.Free();end.
You should keep in mind that the bitmap world.png is very large, you might wanna crop out a smaller part of that bitmap around where you want to use it, both to save memory, and to speed up initialization of your script. Tho it's not needed, I use the whole world map all the time

Other notes

• As of version 1, RSWalker requires you to use SRL
• MemScan only works on Windows (with 32bit Simba), and with Lape as your interpreter, and 32bit Java.
• Path making is done in the same way as with SPS. Open any SPS path-making tool, load your map, make a path, copy the path to your script... done.
• Supports "blindwalk" in the WalkPath function, so you can for example supply it a single point of where you want to walk to that's far away.
• There now exists handling for loading particular "map pieces" (like sps does). I have yet to document this.
• It's shipped with a script to grab world map pieces so you create your own custom maps, it's located in the folder maps under the name MapGrabber.simba.
• With mem-scanning enabled you must provide a map that's extra large, it has a 100px radius which will be "non-walkable", while without mem-scanning it has an extra 55px which is "non-walkable" (or there-about):

Your path must be outside the "none-walkable" area, if it's not, then you need a larger map.

Credits

A thanks to @Olly, he was the one who "manually" (using CheatEngine) parsed through the memory and came across the minimap-buffer, once he found it, and told me about it I started playing around with this idea; Make the search for it "automatic"... And after a little back and forward, some playing around and so on, this walker was created. I didn't really focus on writing pretty code, as it wasn't like super-interesting, just knew we needed something reliable.

2. Extract it to your Includes-Folder (usually located in C:\Simba\)

A nice and useful path making tool: https://github.com/TheTS/SPSToolbox/tree/2
Last edited by slacky; 05-19-2018 at 06:19 AM. Reason: Keep up with changes!

2. SRL Junior Member
Join Date
Dec 2011
Posts
69
Mentioned
0 Post(s)
Quoted
15 Post(s)
Awesome I will test this out tomorrow after work and update how I get along. Looks amazing

3. Great effort! I'll be sure to test this out. If it really works as good as you've experienced so far I could really see this as backup method for when Reflection is out :-)

4. This looks nice, so just to be clear - let's say I want to use this for a RSPS. I would have to 1) have the bitmap I want to use, and 2) I would need the pid of the client correct? How does one go about getting this pid (I can just loop through Tprocess thing?)

5. Originally Posted by Robert
This looks nice, so just to be clear - let's say I want to use this for a RSPS. I would have to 1) have the bitmap I want to use, and 2) I would need the pid of the client correct? How does one go about getting this pid (I can just loop through Tprocess thing?)
w_GetClientPID() returns the PID of the window you have targeted with Simba. If you use SMART and don't wanna target SMART with Simba, you use smarts own SmartGetClientPID(smartInstance). You also don't HAVE to use the memory scanning tho, it can be ignored if you only have like a 500x500 bitmap, maybe even as large as 1000x1000, then just pass -1 as the PID.

Pretty sure this is covered in the initial post.

However it's not designed for anything else the oldschool runescape, so your RSPS has to have the minimap placed in the exact same spot as the official rs07-game for it to work, unless you think about modifying the source. If the RSPS is very modified it might not even find the map-buffer, that is if it has a different than 512x512.
Last edited by slacky; 02-12-2015 at 08:53 PM.

6. Great job!

Maybe hybrid scripts can come back from the dead now.
Last edited by kingarabian; 02-12-2015 at 09:09 PM.

7. RS3 will come eventually too. But that's dead easy compared to this.

8. Looks intriguing! I'll have to have a look at this! Nice job.

EDIT:
I am very impressed!

9. finally!

10. Looks promising, good job.

11. I added this last night and actually did integrate it with AeroLib. I'd like to set it up in the style you used with SEWalker; I think it was neatly written. Yes I did run into some compatibility issues with SimbaExt and, to avoid a mess of "IFDEFINE"/"ELSE", I just replaced the neat, time-saving functions (from SimbaExt) with the original stock Simba functions. Not as tidy as before but this way SimbaExt wouldn't be required to run AL (as SEW being the primary dependent).

It's worked wonderfully for me so far, very accurate and very fast. You've done an amazing job again, Slacky.

12. Originally Posted by ineedbot
Looks intriguing! I'll have to have a look at this! Nice job.
You can debug the local position with the Test2.simba script found in the tests (that is after a couple of modifications). Tho this will only show the local position, but this pos is normally the outcome position only offset based on the loaded worldmap.. but let's not get in to more detail about that.

So, for debugging of your current position this will do:
Simba Code:
var  RSW:TRSWalker;begin  RSW.Init('world.png');  AddOnTerminate(@RSW.Free);  while 1 do    RSW.DebugPos();end;

Debugs made with a modified version of the above + some photoshop (to make it in to one image):
Last edited by slacky; 02-08-2018 at 02:39 AM. Reason: Update example (think it works)

13. SRL Junior Member
Join Date
Dec 2011
Posts
69
Mentioned
0 Post(s)
Quoted
15 Post(s)
awesome^

5e11a65706.png

14. I smell KYAB.

15. Originally Posted by Frement
I smell KYAB.
AFAIK KYAB was reflection-based, the first.

16. Originally Posted by Flight
AFAIK KYAB was reflection-based, the first.
I'm aware, but same concept

17. Originally Posted by Frement
I'm aware, but same concept
I do not see how you can make that claim. It does indeed read the memory which is in a way related to everything in programming (not just reflection), reflection does what I do in a quite different way. I search for a value (width*height), and see if referenced somewhere else in the mem, a place that should hold two other values (width and height) to figure out if it's a bitmap-like structure. If it is.. I know I have a bitmap.. This concept can be used more generally, it's not limited to Java-applications.

Reflection on the other hand just "asks java" to look up some variables based on the variables name.
Last edited by slacky; 02-13-2015 at 10:59 PM.

18. I am having trouble with using OSBuddy and RSWalker accuracy. No biggie, I can use the original client, but OSBuddy has somethings that can be useful.

19. Originally Posted by ineedbot
I am having trouble with using OSBuddy and RSWalker accuracy. No biggie, I can use the original client, but OSBuddy has somethings that can be useful.
Think more info could be helpful. I'm using OSBuddy atm and I'm getting 1-4 pixels out at max (Do you have any plugins that could be messing with it?)

20. Originally Posted by Hawker
Think more info could be helpful. I'm using OSBuddy atm and I'm getting 1-4 pixels out at max (Do you have any plugins that could be messing with it?)
When the map loads a new area on OSBuddy, it takes maybe 20 seconds for it to return to normal. Often i get 'Error: Image buffer can't be found at line 71' On MemScan

On original client, it works just fine and fast.

21. Originally Posted by slacky
I do not see how you can make that claim. It does indeed read the memory which is in a way related to everything in programming (not just reflection), reflection does what I do in a quite different way. I search for a value (width*height), and see if referenced somewhere else in the mem, a place that should hold two other values (width and height) to figure out if it's a bitmap-like structure. If it is.. I know I have a bitmap.. This concept can be used more generally, it's not limited to Java-applications.

Reflection on the other hand just "asks java" to look up some variables based on the variables name.
I meant more in regards to the functionality.

22. Originally Posted by Olly
RS3 will come eventually too. But that's dead easy compared to this.
Really looking forward to it!

23. Originally Posted by ineedbot
I am having trouble with using OSBuddy and RSWalker accuracy. No biggie, I can use the original client, but OSBuddy has somethings that can be useful.
Yeah, I noticed that. It's not that it doesn't work, but memory-scanning is horribly slow on OSBuddy for some reason. I think I can speed it up, but that requires me to rewrite some internal processing stuff. I'll look in to it when/if I feel up for it.
OSBuddy can add up to another ~500MB of memory to scan through on top of the >150MB from the client it self, and that can also mean a bunch of new "almost" matches in memory, and I have to check all these "false-positives" every scan.

You can use it with a smaller part of the world map, and disable memory scanning by passing 0 as PID to the init-procedure.
To do so, just open the world.png in any image editor, and crop out the area you need (pluss the extra of at least 55px radius of "nonwalkable" area, see topic post), save it, and load it in to the walker. Tho keep in mind that without the memscanning, it could turn slow if your custom map is very large, I would _guess_ that up to 1000x1000 image would work.

Hope this helps!

Edit:
A new version is available. It solves the OSBuddy issue, but it will be a few times slower at updating in OSBuddy since it uses MUCH more mem then the official client.
- https://github.com/WarPie/RSWalker/releases/tag/0.32
Last edited by slacky; 04-30-2016 at 01:09 AM. Reason: Updated to match newer RSWalker

24. Great work, seems to run great now on OSBuddy, one small thing; they recently opened up a back door at varrock west bank. And I noticed on your world map there, seems to be outdated.