A RuneTek3 client (377) that is deobfuscated, converted to Kotlin, and includes QoL improvements.
0

Configure Feed

Select the types of activity you want to include in your feed.

renaming of Buffer is 100% completed, started writing tests, and will replace with more efficient code where applicable

+56 -55
+8
build.gradle
··· 9 9 10 10 dependencies { 11 11 compile 'org.yaml:snakeyaml:1.25' 12 + testImplementation('org.junit.jupiter:junit-jupiter:5.5.2') 12 13 } 14 + 15 + test { 16 + useJUnitPlatform() 17 + testLogging { 18 + events "passed", "skipped", "failed" 19 + } 20 + }
+20 -55
src/main/java/com/jagex/runescape/net/Buffer.java
··· 1 1 package com.jagex.runescape.net; 2 2 3 3 import com.jagex.runescape.collection.CacheableNode; 4 - import com.jagex.runescape.util.LinkedList; 5 4 6 5 import java.math.BigInteger; 7 6 8 7 public class Buffer extends CacheableNode { 9 8 10 9 11 - public byte buffer[]; 10 + public byte[] buffer; 12 11 public int currentPosition; 13 12 public int bitPosition; 14 - public static int CRC32_TABLE[] = new int[256]; 15 - public static final int BIT_MASKS[] = { 0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 13 + private static final int[] BIT_MASKS = {0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 16 14 32767, 65535, 0x1ffff, 0x3ffff, 0x7ffff, 0xfffff, 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff, 0x1ffffff, 17 - 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, -1 }; 15 + 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, -1}; 18 16 public ISAACCipher random; 19 - public static int smallBufferCount; 20 - public static int mediumBufferCount; 21 - public static int largeBufferCount; 22 - public static LinkedList smallBuffers = new LinkedList(); 23 - public static LinkedList mediumBuffers = new LinkedList(); 24 - public static LinkedList largeBuffers = new LinkedList(); 25 17 26 18 27 19 public static Buffer allocate(int sizeMode) { 28 - synchronized (mediumBuffers) { 29 - Buffer buffer = null; 30 - if (sizeMode == 0 && smallBufferCount > 0) { 31 - smallBufferCount--; 32 - buffer = (Buffer) smallBuffers.pop(); 33 - } else if (sizeMode == 1 && mediumBufferCount > 0) { 34 - mediumBufferCount--; 35 - buffer = (Buffer) mediumBuffers.pop(); 36 - } else if (sizeMode == 2 && largeBufferCount > 0) { 37 - largeBufferCount--; 38 - buffer = (Buffer) largeBuffers.pop(); 39 - } 40 - if (buffer != null) { 41 - buffer.currentPosition = 0; 42 - return buffer; 43 - } 44 - } 45 20 Buffer buffer = new Buffer(); 46 21 buffer.currentPosition = 0; 47 22 if (sizeMode == 0) ··· 56 31 public Buffer() { 57 32 } 58 33 59 - public Buffer(byte buffer[]) { 34 + public Buffer(byte[] buffer) { 60 35 this.buffer = buffer; 61 36 this.currentPosition = 0; 62 37 } ··· 120 95 buffer[currentPosition++] = 10; 121 96 } 122 97 123 - public void putBytes(byte bytes[], int start, int length) { 98 + public void putBytes(byte[] bytes, int start, int length) { 124 99 for (int pos = start; pos < start + length; pos++) 125 100 buffer[currentPosition++] = bytes[pos]; 126 101 } ··· 170 145 171 146 public String getString() { 172 147 int start = currentPosition; 173 - while (buffer[currentPosition++] != 10); 148 + moveBufferToTarget((byte) 10); 174 149 return new String(buffer, start, currentPosition - start - 1); 175 150 } 176 151 152 + private void moveBufferToTarget(byte target) { 153 + if(buffer[currentPosition++] != target){ 154 + moveBufferToTarget(target); 155 + } 156 + } 157 + 177 158 public byte[] getStringBytes() { 178 159 int start = currentPosition; 179 - while (buffer[currentPosition++] != 10); 180 - byte bytes[] = new byte[currentPosition - start - 1]; 181 - for (int pos = start; pos < currentPosition - 1; pos++) 182 - bytes[pos - start] = buffer[pos]; 160 + moveBufferToTarget((byte) 10); 161 + byte[] bytes = new byte[currentPosition - start - 1]; 162 + if (currentPosition - 1 - start >= 0) 163 + System.arraycopy(buffer, start, bytes, 0, currentPosition - 1 - start); 183 164 return bytes; 184 165 } 185 166 186 - public void getBytes(byte bytes[], int start, int len) { 167 + public void getBytes(byte[] bytes, int start, int len) { 187 168 for (int pos = start; pos < start + len; pos++) 188 169 bytes[pos] = buffer[currentPosition++]; 189 170 } ··· 232 213 public void encrypt(BigInteger modulus, BigInteger key) { 233 214 int length = currentPosition; 234 215 currentPosition = 0; 235 - byte bytes[] = new byte[length]; 216 + byte[] bytes = new byte[length]; 236 217 237 218 getBytes(bytes, 0, length); 238 219 ··· 351 332 + ((buffer[currentPosition - 1] & 0xff) << 8) + (buffer[currentPosition - 2] & 0xff); 352 333 } 353 334 354 - public void getBytesReverse(byte bytes[], int start, int len) { 335 + public void getBytesReverse(byte[] bytes, int start, int len) { 355 336 for (int pos = (start + len) - 1; pos >= start; pos--) 356 337 bytes[pos] = buffer[currentPosition++]; 357 338 } 358 339 359 - public void getBytesAdded(byte bytes[], int start, int len) { 340 + public void getBytesAdded(byte[] bytes, int start, int len) { 360 341 for (int pos = start; pos < start + len; pos++) 361 342 bytes[pos] = (byte) (buffer[currentPosition++] - 128); 362 343 } 363 - 364 344 365 345 366 - 367 - static { 368 - int pos = 0; 369 - while (pos < 256) { 370 - int value = pos; 371 - for (int pass = 0; pass < 8; pass++) 372 - if ((value & 1) == 1) 373 - value = value >>> 1 ^ 0xedb88320; 374 - else 375 - value >>>= 1; 376 - CRC32_TABLE[pos] = value; 377 - pos++; 378 - } 379 - 380 - } 381 346 }
+28
src/test/java/com/jagex/runescape/net/BufferTests.java
··· 1 + package com.jagex.runescape.net; 2 + 3 + import org.junit.jupiter.api.Assertions; 4 + import org.junit.jupiter.api.DisplayName; 5 + import org.junit.jupiter.api.Test; 6 + import org.junit.jupiter.params.ParameterizedTest; 7 + import org.junit.jupiter.params.provider.CsvSource; 8 + 9 + public class BufferTests { 10 + 11 + @ParameterizedTest(name = "Buffer allocate") 12 + @CsvSource({ 13 + "0, 100", 14 + "1, 5000", 15 + "2, 30000", 16 + "3, 30000" 17 + }) 18 + void allocateBuffer(int sizeMode, int expectedBufferSize) { 19 + Buffer buffer = Buffer.allocate(sizeMode); 20 + Assertions.assertEquals(0, buffer.currentPosition, "buffer position should be 0"); 21 + Assertions.assertArrayEquals(buffer.buffer, new byte[expectedBufferSize], "Buffer should be completely empty"); 22 + Assertions.assertEquals(expectedBufferSize, buffer.buffer.length, 23 + () -> "buffer length should be " + expectedBufferSize + " with sizeMode: " + sizeMode); 24 + 25 + } 26 + 27 + 28 + }