Update #4
Thanks to Daniel (blackd), the weird numbers (like with object ids, and some flags) has been solved.
If a value is greater-than-or-equal to 0x80 then there will be another value following it. If that value is greater-than-or-equal to 0x80 there will be another value following it. So on and so forth until the next value is less-than 0x80, but it should never be more than four values. Furthermore, the value of each byte can be calculated with the following formula: ((128^x)*(n))-(128^x) where x is the index of the current byte (0-based) and n is the value of the byte. Using recursion, and adding each calculated value, we can get the final value.
For example, the object id of rope is 0xBB 0x17 which, when read as a 2-byte integer gives the value 6075, but we know that the item id of rope is 3003. If we plug 0xBB (187) into the equation we get ((128^0)*(187))-(128^0)=186. We use 0 for x because 0xBB is the first byte and we count up from 0. Now, if we plug 0x17 (23) into the equation we get ((128^1)*(23))-(128^1)=2816. We use 1 for x here because it's the second byte but we count up from 0. Take the sum of both values and you get 186+2816=3002. The item id of rope is actually 3003, so we just need to add 1 to the sum.
pseudo-code:
Code:
int readValue(byte[] buffer, int position, int index = 0) {
byte num1 = buffer[position];
int num2 = ((128^index)*(num1))-(128^index);
if (index == 0) {
num2++;
}
if (num1 < 128) {
return num2;
}
return num2 + readValue(buffer, position++, index++);
}
I'm not the best at formulas, so if anyone can write a better one to remove that first if-statement that would be great.