- Joined
- Aug 23, 2015
- Messages
- 1,961
- Thread Author
- #1
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
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
This is a picture of the output log of Open Varp Explorer as I did the following actions:
Understanding the Open Varp Explorer Interface:
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
This is a picture of the output log of Open Varbit Explorer as I did the following actions:
Understanding the Open Varbit Explorer Interface:
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:
Stop for a moment, and think about what this code is doing, why each part is important, and what could be improved.
As for possible improvements, I'll let you be creative and think of those on your own.
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:
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.
- 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.
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
This is a picture of the output log of Open Varp Explorer as I did the following actions:
- Fill a small rune pouch
- Empty a small rune pouch
- Fill a medium rune pouch
- Empty a medium rune pouch
- Fill a small rune pouch
- Fill a medium rune pouch
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
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
This is a picture of the output log of Open Varbit Explorer as I did the following actions:
- Fill a small rune pouch
- Empty a small rune pouch
- Fill a medium rune pouch
- Empty a medium rune pouch
- Fill a small rune pouch
- Fill a medium rune pouch
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
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:
private boolean smallPouchFull() {
Varbit varbit = Varbits.load(603);
if(varbit == null) {
System.out.println("Varbit smallpouch was null");
return false;
} else {
return varbit.getValue() > 0;
}
}
Stop for a moment, and think about what this code is doing, why each part is important, and what could be improved.
Code:
public boolean smallPouchFull() { //creates a method to call in the class that will return a boolean
Varbit varbit = Varbits.load(603); //creates a variable named "varbit" of the "Varbit" type, and assigns the varbit in index 603 to it
if(varbit == null) { //checks if the data we loaded into our varbit variable exists
System.out.println("Varbit smallpouch was null"); //if it doesn't let us know and return false
return false;
} else { //if the data does exist
return varbit.getValue() > 0; //tell us if the value of the varbit is > 0 (contained ess is > 0)
}
}
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
Last edited: