43public final class Buffer {
46 public void setOffset(
int offset) {
47 this.position = offset;
50 public int readSmart() {
51 int value = array[position] & 0xff;
53 return readUnsignedByte() - 64;
55 return readUShort() - 49152;
57 public String readStringNew() {
59 while (array[position++] != 0)
61 return new String(array, i, position - i - 1);
64 public int readShort2() {
66 int i = ((array[position - 2] & 0xff) << 8) + (array[position - 1] & 0xff);
73 public int readSignedShort() {
75 int value = ((this.array[this.position - 2] & 0xff) << 8) + (this.array[this.position - 1] & 0xff);
82 public int readShortSmart()
84 int peek = array[position] & 0xFF;
85 return peek < 128 ? this.readUnsignedByte() - 64 : this.readUnsignedShort() - 0xc000;
88 public int read24Int() {
90 return ((array[position - 3] & 0xff) << 16) + ((array[position - 2] & 0xff) << 8) + (array[position - 1] & 0xff);
93 public int readMedium() {
95 return ((this.array[this.position - 3] & 255) << 16) + (this.array[this.position - 1] & 255) + ((this.array[this.position - 2] & 255) << 8);
99 public int readUShort() {
101 return ((array[position - 2] & 0xff) << 8)
102 + (array[position - 1] & 0xff);
105 public int readInt() {
107 return ((array[position - 4] & 0xff) << 24)
108 + ((array[position - 3] & 0xff) << 16)
109 + ((array[position - 2] & 0xff) << 8)
110 + (array[position - 1] & 0xff);
113 public int readShort() {
115 int value = ((array[position - 2] & 0xff) << 8)
116 + (array[position - 1] & 0xff);
124 public int readShortOSRS() {
126 int var1 = (this.array[this.position - 1] & 255) + ((this.array[this.position - 2] & 255) << 8);
136 return (0xff & array[position - 3] << 16) + (0xff & array[position - 2] << 8) + (0xff & array[position - 1]);
142 public Buffer(
byte[] array) {
147 public static Buffer fromByteBuffer(
final ByteBuffer byteBuffer) {
148 final byte[] array =
new byte[byteBuffer.capacity()];
149 byteBuffer.get(array);
150 return new Buffer(array);
153 public int readUnsignedShortSmart()
155 int peek = this.peek() & 0xFF;
156 return peek < 128 ? this.readUnsignedByte() : this.readUnsignedShort() - 0x8000;
159 public int readUnsignedIntSmartShortCompat()
164 for (var2 = this.readUnsignedShortSmart(); var2 == 32767; var2 = this.readUnsignedShortSmart())
173 public int readUSmart2() {
176 while ((lastVal = method422()) == 32767) {
179 return baseVal + lastVal;
182 public String readNewString() {
184 while (array[position++] != 0)
186 return new String(array, i, position - i - 1);
189 public void writeOpcode(
int i) {
191 array[position++] = (byte) (i + encryption.getKey());
194 public void writeByte(
int i) {
195 array[position++] = (byte) i;
198 public void writeShort(
int i) {
199 array[position++] = (byte) (i >> 8);
200 array[position++] = (byte) i;
203 public void writeDWordBigEndian(
int i) {
204 array[position++] = (byte) (i >> 16);
205 array[position++] = (byte) (i >> 8);
206 array[position++] = (byte) i;
209 public void writeDWord(
int i) {
210 array[position++] = (byte) (i >> 24);
211 array[position++] = (byte) (i >> 16);
212 array[position++] = (byte) (i >> 8);
213 array[position++] = (byte) i;
216 public void method403(
int j) {
217 array[position++] = (byte) j;
218 array[position++] = (byte) (j >> 8);
219 array[position++] = (byte) (j >> 16);
220 array[position++] = (byte) (j >> 24);
223 public void writeQWord(
long l) {
225 array[position++] = (byte) (
int) (l >> 56);
226 array[position++] = (byte) (
int) (l >> 48);
227 array[position++] = (byte) (
int) (l >> 40);
228 array[position++] = (byte) (
int) (l >> 32);
229 array[position++] = (byte) (
int) (l >> 24);
230 array[position++] = (byte) (
int) (l >> 16);
231 array[position++] = (byte) (
int) (l >> 8);
232 array[position++] = (byte) (
int) l;
233 }
catch (RuntimeException runtimeexception) {
234 throw new RuntimeException();
238 public void writeString(String s) {
240 System.arraycopy(s.getBytes(), 0, array, position, s.length());
241 position += s.length();
242 array[position++] = 10;
245 public void writeBytes(
byte[] abyte0,
int i,
int j) {
246 for (
int k = j; k < j + i; k++)
247 array[position++] = abyte0[k];
250 public void writeBytes(
int i) {
251 array[position - i - 1] = (byte) i;
254 public int readUnsignedByte() {
255 return array[position++] & 0xff;
258 public int readSignedSmart() {
259 int value = peek() & 0xff;
261 return this.readUnsignedByte() - 64;
263 return this.readUnsignedShort() - 49152;
268 return array[position];
271 public int readUnsignedShortSmartMinusOne()
273 int peek = this.peek() & 0xFF;
274 return peek < 128 ? this.readUnsignedByte() - 1 : this.readUnsignedShort() - 0x8001;
277 public int readBigSmart2()
281 return readInt() & Integer.MAX_VALUE;
283 int value = readUnsignedShort();
284 return value == 32767 ? -1 : value;
287 public byte readSignedByte() {
288 return array[position++];
291 public int readUnsignedShort() {
293 return ((array[position - 2] & 0xff) << 8) + (array[position - 1] & 0xff);
296 public int readSignedWord() {
298 int i = ((array[position - 2] & 0xff) << 8) + (array[position - 1] & 0xff);
305 public int getUIncrementalSmart() {
306 int value = 0, remainder;
307 for (remainder = method422(); remainder == 32767; remainder = method422()) {
314 public int readUnsignedTriByte() {
316 return ((array[position - 3] & 0xff) << 16) + ((array[position - 2] & 0xff) << 8) + (array[position - 1] & 0xff);
319 public int readUnsignedInt() {
321 return ((array[position - 4] & 0xff) << 24) + ((array[position - 3] & 0xff) << 16) + ((array[position - 2] & 0xff) << 8) + (array[position - 1] & 0xff);
324 public long readUnsignedLong() {
325 long big = (long) readUnsignedInt() & 0xFFFF_FFFFL;
326 long little = (long) readUnsignedInt() & 0xFFFF_FFFFL;
327 return (big << 32) + little;
330 public String readString() {
331 int start = position;
332 while (array[position++] != 10);
333 return new String(array, start, position - start - 1);
336 public String readStringCp1252NullTerminated() {
337 int var1 = this.position;
339 while(this.array[++this.position - 1] != 0) {
343 int var2 = this.position - var1 - 1;
344 return var2 == 0 ?
"" : decodeStringCp1252(this.array, var1, var2);
347 public static String decodeStringCp1252(
byte[] var0,
int var1,
int var2) {
348 char[] var3 =
new char[var2];
351 for(
int var5 = 0; var5 < var2; ++var5) {
352 int var6 = var0[var5 + var1] & 255;
354 if (var6 >= 128 && var6 < 160) {
355 char var7 = cp1252AsciiExtension[var6 - 128];
363 var3[var4++] = (char)var6;
367 return new String(var3, 0, var4);
370 public static final char[] cp1252AsciiExtension =
new char[]{
'€',
'\u0000',
'‚',
'ƒ',
'„',
'…',
'†',
'‡',
'ˆ',
'‰',
'Š',
'‹',
'Œ',
'\u0000',
'Ž',
'\u0000',
'\u0000',
'‘',
'’',
'“',
'”',
'•',
'–',
'—',
'˜',
'™',
'š',
'›',
'œ',
'\u0000',
'ž',
'Ÿ'};
372 public byte[] readBytes() {
373 int start = position;
374 while (array[position++] != 10);
375 byte[] bytes =
new byte[position - start - 1];
376 System.arraycopy(array, start, bytes, start - start, position - 1 - start);
380 public void readBytes(
int amount,
int offset,
byte[] destination) {
381 for (
int l = offset; l < offset + amount; l++)
382 destination[l] = array[position++];
385 public void initBitAccess() {
386 bitPosition = position * 8;
389 public int readBits(
int amount) {
390 int bytePos = bitPosition >> 3;
391 int bitOffset = 8 - (bitPosition & 7);
394 bitPosition += amount;
396 for (; amount > bitOffset; bitOffset = 8) {
397 value += (array[bytePos++] & BIT_MASK[bitOffset]) << amount - bitOffset;
401 if (amount == bitOffset) {
402 value += array[bytePos] & BIT_MASK[bitOffset];
404 value += array[bytePos] >> bitOffset - amount & BIT_MASK[amount];
410 public void finishBitAccess() {
411 position = (bitPosition + 7) / 8;
414 public int method421() {
415 int i = array[position] & 0xff;
417 return readUnsignedByte() - 64;
419 return readUnsignedShort() - 49152;
422 public int method422() {
423 int i = array[position] & 0xff;
425 return readUnsignedByte();
427 return readUnsignedShort() - 32768;
430 public void encodeRSA(BigInteger exponent, BigInteger modulus) {
433 byte[] abyte0 =
new byte[i];
434 readBytes(i, 0, abyte0);
436 byte[] rsa =
new BigInteger(abyte0).modPow(exponent, modulus).toByteArray();
439 writeByte(rsa.length);
440 writeBytes(rsa, rsa.length, 0);
443 public void writeNegatedByte(
int i) {
444 array[position++] = (byte) (-i);
447 public void method425(
int j) {
448 array[position++] = (byte) (128 - j);
451 public int readUByteA() {
452 return array[position++] - 128 & 0xff;
455 public int readNegUByte() {
456 return -array[position++] & 0xff;
459 public int readUByteS() {
460 return 128 - array[position++] & 0xff;
463 public byte method429() {
464 return (
byte) (-array[position++]);
467 public byte method430() {
468 return (
byte) (128 - array[position++]);
471 public void writeLEShort(
int i) {
472 array[position++] = (byte) i;
473 array[position++] = (byte) (i >> 8);
476 public void writeShortA(
int j) {
477 array[position++] = (byte) (j >> 8);
478 array[position++] = (byte) (j + 128);
481 public void writeLEShortA(
int j) {
482 array[position++] = (byte) (j + 128);
483 array[position++] = (byte) (j >> 8);
486 public int readLEUShort() {
488 return ((array[position - 1] & 0xff) << 8) + (array[position - 2] & 0xff);
491 public int readUShortA() {
493 return ((array[position - 2] & 0xff) << 8) + (array[position - 1] - 128 & 0xff);
496 public int readLEUShortA() {
498 return ((array[position - 1] & 0xff) << 8) + (array[position - 2] - 128 & 0xff);
501 public int readLEShort() {
503 int j = ((array[position - 1] & 0xff) << 8) + (array[position - 2] & 0xff);
509 public int method438() {
511 int j = ((array[position - 1] & 0xff) << 8) + (array[position - 2] - 128 & 0xff);
517 public int method439() {
519 return ((array[position - 2] & 0xff) << 24) + ((array[position - 1] & 0xff) << 16) + ((array[position - 4] & 0xff) << 8) + (array[position - 3] & 0xff);
522 public int method440() {
524 return ((array[position - 3] & 0xff) << 24) + ((array[position - 4] & 0xff) << 16) + ((array[position - 1] & 0xff) << 8) + (array[position - 2] & 0xff);
527 public void method441(
int i,
byte[] abyte0,
int j) {
528 for (
int k = (i + j) - 1; k >= i; k--)
529 array[position++] = (
byte) (abyte0[k] + 128);
533 public void readReverseData(
int i,
int j,
byte[] abyte0) {
534 for (
int k = (j + i) - 1; k >= j; k--)
535 abyte0[k] = array[position++];
539 public float readFloat() {
540 return Float.intBitsToFloat(readInt());
543 public byte[] readBytes(
final int length) {
544 final byte[] bytes =
new byte[length];
545 System.arraycopy(array, position, bytes, 0, length);
552 public int bitPosition;
553 private static final int[] BIT_MASK = {0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 0x1ffff, 0x3ffff, 0x7ffff, 0xfffff, 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff, 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, -1};
555 private static int anInt1412;
557 public void setPosition(
int offset) {
558 this.position = offset;