1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Tutorial What Varps and Varbits are, and how to work with them

Discussion in 'Tutorials & Resources' started by Snufalufugus, Apr 4, 2017.

  1. Snufalufugus

    Joined:
    Aug 23, 2015
    Messages:
    1,961
    Likes Received:
    757
    Why are Varps and Varbits important at RM:
    Varps and Varbits hold tons of information that will be necessary for nearly any advanced bot you would want to make. Depending on the gamemode you're coding for, they could hold information about slayer tasks, quest progression, farming patch status, whether or not a potion effect is active, and many, many more things.

    Tools Used in this Tutorial:
    Open Varp Explorer
    Open Varbit Explorer

    Numerical systems:
    • Decimal: The numerical system you're used to. It is sometimes referred to as base-10.
    • Hexadecimal: Another numeral system where numerical values are represented using 0-9 and A-F.
    • Binary: The binary numeral system is a system used to represent conventional (base 10) numerical values using only 1s and 0s. In the real world, this translates to discrete voltage levels, typically 0V and 5V, which represent an off (0) or on (1) state. This is the concept that modern electronics operate on at a transistor level.
    Bit: The basic unit of information for computers: a single 1 or 0.
    Ex) 1

    Nibble: A cluster of four bits.
    Ex) 1 0 1 1

    Byte: A cluster of eight bits, or two nibbles. This is THE unit of storage everyone is familiar with (A 500GB or Giga-Byte Hard Drive, for example).
    Ex) 1 0 1 0 0 1 1 1

    Word: A cluster of thirty-two bits, four bytes, or eight nibbles.
    Ex) 1 0 1 0 0 1 1 1 1 0 1 0 0 1 1 1 1 0 1 0 0 1 1 1 1 0 1 0 0 1 1 1

    Bitwise operations: Much like you can use AND/OR statements in the condition of an IF statement, you can use AND/OR statements to manipulate individual bits of a binary number. You can also use XOR, but you don't need to know about that for this application. Bitwise operations compare the bits in the same position, perform the designated action on those bits, and produce the appropriate result.

    For example:
    Bitwise AND
    ...1 1 0 0
    + 1 0 1 0
    = 1 0 0 0

    Bitwise OR
    ...1 1 0 0
    + 1 0 1 0
    = 1 1 1 0

    Bit Masking: Using bitwise operations to get rid of unnecessary information.
    For example, if we only care about the last three bits of a byte, we use a Bitwise AND:
    ...1 0 1 1 0 0 1 0 <-- We want the last three bits
    + 0 0 0 0 0 1 1 1 <-- Mask
    = 0 0 0 0 0 0 1 0 <-- Masked information

    For more information, check out the Wikipedia pages for each numerical system. What I provided is probably more than you'll need for Runemate.

    Understanding Varps:
    As stated in the Runemate Jdocs:
    "local player variables" - Varps are known to contain data related to questing, farming, and other local player data.

    My explanation: A Varp is a cluser of 32 bits (a word) used to represent various information about your player. A full Varp typically holds much more information than you need, and in order to utilize it you need to figure out what the Varp value means, and where in the 32 bits the information you need is kept. When using Slashnhax's Varp Explorer, you may notice that the displayed Varps are only displayed as 31 bits if you're particularly observant. This is because the 32nd bit is always a 0 to signify that the Varp is positive, so there is no need to display that information.

    I have a suspicion they are a full word in length, but Slashnhax's Open Varp Explorer shows them at 31 bits long so I will assume that is correct.

    Example of Varps: Rune pouches
    [​IMG]

    This is a picture of the output log of Open Varp Explorer as I did the following actions:
    1. Fill a small rune pouch
    2. Empty a small rune pouch
    3. Fill a medium rune pouch
    4. Empty a medium rune pouch
    5. Fill a small rune pouch
    6. Fill a medium rune pouch
    I have labelled each action in the image to make it easier to understand, as it can be quite overwhelming at first.

    Understanding the Open Varp Explorer Interface:
    • Time: The time at which the change occured
    • Index: The location of the Varp that is changing
    • Binary new: The updated Varp value, after the change occured
    • Binary old: The previous Varp value, before the change occured
    • Decimal new/old: The binary value of the Varp converted to Base 10 (decimal)
    • Hex new/old: The binary value of the Varp converted to Hexadecimal
    Understanding the data:
    The first step is figuring out which Varp you will be using. In some cases, only one Varp will change, and that makes things easy. In this case, two Varps changed: Index 486 and Index 720. To figure out which Varp you want to use, look for patterns relating to the information you want. In our case, it is crucial to know that a small pouch can hold 0-3 essence, and a medium pouch can hold 0-6 essence.

    Let's take a look at the first Varp change: Index 486 at 17:55:01. As we fill the pouch, our decimal value equivalent increases by three. That's an indication that this may be the Varp we want - the pouch has 3 more essence in it, and the decimal equivalent of our Varp increased by three.

    As we continue to look at Varp 486, we can identify the pattern: the decimal value of the varp is changing by the number of essence we have stored in pouches. We empty the small pouch and it decreases by three. We fill the medium pouch, and it increases by 6. We empty the medium pouch, and it decreases by 6. We fill the small pouch -> increase of three -> fill medium pouch -> increase of six = Total increase of 9. We have 9 stored essence. This is the Varp we want.

    Now that we have identified the Varp and it's patterns, we can determine where the data we want is stored, and manipulate the Varp to obtain the data we want. Typically, this manipulation involves taking the bits of the Varp and masking out the useless information. I won't be showing an example of this since someone who is doing something that requires this won't be needing a tutorial to show them how.

    As you probably now realize, using a Varp to get the data you want can be very tricky and time consuming. Luckily for us, we have Varbits to use instead!



    Understanding Varbits:
    As stated in the Runemate Jdocs:

    My explanation: A Varbit is like a heavily condensed version of a Varp. It contains information about your player, but in an easily accessible and understandable format. Think of it as a piece of a Varp that has already been bit-wise manipulated to save you time, effort, and frustration. It's better to view it as a piece of a Varp instead of the entire thing since Varps typically hold the data of multiple Varbits in them. A full Varp is a word in length - plenty of room for data storage.

    Example of Varbits: Rune pouches
    [​IMG]

    This is a picture of the output log of Open Varbit Explorer as I did the following actions:
    1. Fill a small rune pouch
    2. Empty a small rune pouch
    3. Fill a medium rune pouch
    4. Empty a medium rune pouch
    5. Fill a small rune pouch
    6. Fill a medium rune pouch
    I have labelled each action in the image to make it easier to understand, as it can be quite overwhelming at first.

    Understanding the Open Varbit Explorer Interface:
    • Time: The time at which the change occured
    • Index: The location of the Varbit that is changing
    • Binary new: The updated Varbit value, after the change occured
    • Binary old: The previous Varbit value, before the change occured
    • Decimal new/old: The binary value of the Varbit converted to Base 10 (decimal)
    • Hex new/old: The binary value of the Varbit converted to Hexadecimal
    Understanding the data:
    The first step is figuring out which Varbit you will be using. In some cases, only one Varbit will change, and that makes things easy. In this case, four varbits changed: Indexes 603, 2088, 604, 2089. To figure out which Varbit you want to use, look for patterns relating to the information you want.

    Like before, a pattern that jumps out at us is the decimal equivalent changing by the number of rune essence we are adding or removing. This is shown to us in Varbits 603 and 604. When we fill or empty the small pouch, varbit 603 changes by +/- decimal 3. When we fill or empty the medium pouch, varbit 604 changes by +/- decimal 6.

    One change you should notice is that when we fill or empty one pouch, the varbit for the other does not change. This is a HUGE benefit of using varbits instead of varps. While the varps may include all of the data you need in one index location, you have to figure out how the information is all merged together into those 31 bits of data.

    Coding with Varbits:
    Now that we have found the varbit we will be using, and have found how it changes with the information we want, we can write the code to utilize what we have found.

    I'll show code that can be used to determine the contents of a small runecrafting pouch:
    Code (Text):
    1.     private boolean smallPouchFull() {
    2.         Varbit varbit = Varbits.load(603);
    3.         if(varbit == null) {
    4.             System.out.println("Varbit smallpouch was null");
    5.             return false;
    6.         } else {
    7.             return varbit.getValue() > 0;
    8.         }
    9.     }
    Stop for a moment, and think about what this code is doing, why each part is important, and what could be improved.

    Code (Text):
    1.     public boolean smallPouchFull() { //creates a method to call in the class that will return a boolean
    2.         Varbit varbit = Varbits.load(603); //creates a variable named "varbit" of the "Varbit" type, and assigns the varbit in index 603 to it
    3.         if(varbit == null) { //checks if the data we loaded into our varbit variable exists
    4.             System.out.println("Varbit smallpouch was null"); //if it doesn't let us know and return false
    5.             return false;
    6.         } else { //if the data does exist
    7.             return varbit.getValue() > 0; //tell us if the value of the varbit is > 0 (contained ess is > 0)
    8.         }
    9.     }

    As for possible improvements, I'll let you be creative and think of those on your own.


    Go figure out what the Varp and Varbits that I skipped over during this tutorial represent ;)
     
    #1 Snufalufugus, Apr 4, 2017
    Last edited: Apr 6, 2017
    TYG123, Ridz, Sharkplushie and 6 others like this.
  2. proxi

    proxi s̶c̶r̶i̶p̶t̶ bot*

    Joined:
    Aug 23, 2015
    Messages:
    2,223
    Likes Received:
    501
    Damn Paul

     
    Snufalufugus likes this.
  3. awesome123man

    awesome123man Go check out new bots and give helpful feedback.

    Joined:
    Jan 31, 2016
    Messages:
    5,413
    Likes Received:
    1,662
    Great Tutorial! Extremely helpful!
     
    Snufalufugus likes this.
  4. Snufalufugus

    Joined:
    Aug 23, 2015
    Messages:
    1,961
    Likes Received:
    757
    Slightly updated to clarify what a Varbit is along with more info about the length of Varps. Big thanks to Slashnhax for the information!
     
    proxi likes this.
  5. Jux7apose

    Joined:
    Mar 28, 2017
    Messages:
    286
    Likes Received:
    58
    Does the Open Varps Viewer also show NPC's varps, or is that only in the Dev toolkit?
     
  6. sickness0666

    Joined:
    Mar 14, 2017
    Messages:
    156
    Likes Received:
    48
    any idea if there is a varbit for the Coal bag? i wasnt able to get it using this tutorial
     
  7. Guru

    Joined:
    Dec 31, 2015
    Messages:
    602
    Likes Received:
    175
    No there isn't one for coal bag (OSRS) not sure about rs3
     
  8. sickness0666

    Joined:
    Mar 14, 2017
    Messages:
    156
    Likes Received:
    48
    RS3 is what i was searching in, wasnt able to find anything. so i use message listener to check if it was filled
     
  9. fast_fletcher

    Joined:
    Apr 19, 2017
    Messages:
    5
    Likes Received:
    1
    I think you mean to say that 32 bits is a DWord as a Word is only 16 bits!
     
  10. Sirbottery

    Joined:
    Apr 22, 2017
    Messages:
    34
    Likes Received:
    3
    So this should also keep track of all the items in your bank correct & amounts?
     
  11. awesome123man

    awesome123man Go check out new bots and give helpful feedback.

    Joined:
    Jan 31, 2016
    Messages:
    5,413
    Likes Received:
    1,662
    I dont think so... Some things are stored server side.
     
  12. Snufalufugus

    Joined:
    Aug 23, 2015
    Messages:
    1,961
    Likes Received:
    757
    No, varps do not store that information.
     
  13. proxi

    proxi s̶c̶r̶i̶p̶t̶ bot*

    Joined:
    Aug 23, 2015
    Messages:
    2,223
    Likes Received:
    501
    That's incorrect. A dword is the same bits as a word (32 or 64 bits in modern architectures). Assuming we're on a 32-bit system, the reason it's phrased 'dword' or 'double word' is because it carries an unsigned 32-bit value, with it's max integer value is double the max integer value of a signed 32-bit (a word).

    Word (computer architecture) - Wikipedia
     
  14. Sirbottery

    Joined:
    Apr 22, 2017
    Messages:
    34
    Likes Received:
    3
    Dang thought they'd might be storing them for some sort of quick caching system and maybe it would of kept track of GE prices for a easy wealth checker script bot.
     
  15. Snufalufugus

    Joined:
    Aug 23, 2015
    Messages:
    1,961
    Likes Received:
    757
    Although according to wikipedia you're technically correct, the only reason that definition of a word is accurate is to maintain backwards comparability with very old systems. Newer ones typically wouldn't use a word size of 16 bits.
     
    proxi likes this.
  16. Savior

    Savior Java Warlord

    Joined:
    Nov 17, 2014
    Messages:
    4,906
    Likes Received:
    2,748
    Something like that may be implemented at some point for RuneMate. Although the bank would have to be opened at least once when running a bot before you could actually access the cached data.
     
  17. rickp

    Joined:
    Sep 20, 2017
    Messages:
    40
    Likes Received:
    7
    Tools Used in this Tutorial:
    Open Varp Explorer
    Open Varbit Explorer


    both of these are gone, is there a new tool available that can do all this?
    im trying to find some data on the herb sack and gem bag for someone
     
    #17 rickp, Oct 17, 2017
    Last edited: Oct 17, 2017
  18. Snufalufugus

    Joined:
    Aug 23, 2015
    Messages:
    1,961
    Likes Received:
    757
    Just use the dev toolkit
    --- Double Post Merged, Dec 12, 2017, Original Post Date: Oct 17, 2017 ---
    Forums won't let me edit OP, so hopefully this will be seen here.

     

Share This Page

Loading...