Package com.kraken.api.core.packet
Class BufferUtils
- java.lang.Object
-
- com.kraken.api.core.packet.BufferUtils
-
public class BufferUtils extends java.lang.ObjectA static utility class that uses reflection to interact with the client's obfuscated buffer objects (e.g., PacketBuffer). This class provides a stable API to get/set the buffer's underlying byte array and its current offset, and to write data using the client's specific (and obfuscated) methods.This class is a copy (with comments) of the BufferMethods from the EthanVann PacketUtils class found here: https://github.com/Ethan-Vann/PacketUtils/blob/master/src/main/java/com/example/Packets/BufferMethods.java
-
-
Constructor Summary
Constructors Constructor Description BufferUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intencodeStringCp1252(java.lang.CharSequence data, int startIndex, int endIndex, byte[] output, int outputStartIndex)Encodes a Java String (CharSequence) into a byte array using the CP1252 character set.static byte[]getArray(java.lang.Object bufferInstance)Reflectively gets the underlying 'array' (the byte[]) from a buffer instance.static intgetOffset(java.lang.Object bufferInstance)Reflectively gets the 'offset' (current write position) from a buffer instance.static intnextIndex(int offset)Calculates the *next logical offset* by adding the obfuscated offset multiplier.static voidsetArray(java.lang.Object bufferInstance, byte[] array)Reflectively sets the underlying 'array' (the byte[]) on a buffer instance.static voidsetOffset(java.lang.Object bufferInstance, int offset)Reflectively sets the 'offset' (current write position) on a buffer instance.static voidwriteStringCp1252NullCircumfixed(java.lang.String val, java.lang.Object bufferInstance)Writes a string to the buffer, encoded in CP1252, with a null (0) byte *before* and *after* the string.static voidwriteStringCp1252NullTerminated(java.lang.String val, java.lang.Object bufferInstance)Writes a string to the buffer, encoded in CP1252, followed by a single null (0) byte terminator.static voidwriteValue(java.lang.String writeDescription, int value, java.lang.Object bufferInstance)Writes a single integer value to the buffer using a specified "write description".
-
-
-
Method Detail
-
setOffset
public static void setOffset(java.lang.Object bufferInstance, int offset)Reflectively sets the 'offset' (current write position) on a buffer instance.- Parameters:
bufferInstance- The obfuscated buffer object (e.g., PacketBuffer).offset- The new offset value to set.
-
getOffset
public static int getOffset(java.lang.Object bufferInstance)
Reflectively gets the 'offset' (current write position) from a buffer instance.- Parameters:
bufferInstance- The obfuscated buffer object.- Returns:
- The current offset, or -1 if retrieval fails.
-
setArray
public static void setArray(java.lang.Object bufferInstance, byte[] array)Reflectively sets the underlying 'array' (the byte[]) on a buffer instance.- Parameters:
bufferInstance- The obfuscated buffer object.array- The new byte[] to set as the buffer's data.
-
getArray
public static byte[] getArray(java.lang.Object bufferInstance)
Reflectively gets the underlying 'array' (the byte[]) from a buffer instance.- Parameters:
bufferInstance- The obfuscated buffer object.- Returns:
- The buffer's byte[] data, or null if retrieval fails.
-
writeValue
public static void writeValue(java.lang.String writeDescription, int value, java.lang.Object bufferInstance)Writes a single integer value to the buffer using a specified "write description". This method handles the client's obfuscated write types (add, subtract, etc.) and the complex index calculation.- Parameters:
writeDescription- A string (e.g., "a128", "s", "v") defining the write operation.value- The integer value to write.bufferInstance- The obfuscated buffer object.
-
writeStringCp1252NullTerminated
public static void writeStringCp1252NullTerminated(java.lang.String val, java.lang.Object bufferInstance)Writes a string to the buffer, encoded in CP1252, followed by a single null (0) byte terminator.- Parameters:
val- The string to write.bufferInstance- The obfuscated buffer object.
-
writeStringCp1252NullCircumfixed
public static void writeStringCp1252NullCircumfixed(java.lang.String val, java.lang.Object bufferInstance)Writes a string to the buffer, encoded in CP1252, with a null (0) byte *before* and *after* the string.- Parameters:
val- The string to write.bufferInstance- The obfuscated buffer object.
-
nextIndex
public static int nextIndex(int offset)
Calculates the *next logical offset* by adding the obfuscated offset multiplier.- Parameters:
offset- The current logical offset.- Returns:
- The next logical offset.
-
encodeStringCp1252
public static int encodeStringCp1252(java.lang.CharSequence data, int startIndex, int endIndex, byte[] output, int outputStartIndex)Encodes a Java String (CharSequence) into a byte array using the CP1252 character set. This is the standard string encoding used by OSRS, which includes special characters like €, ‚, ƒ, „, etc., that are not in standard ASCII.- Parameters:
data- The string data to encode.startIndex- The starting character index from the string.endIndex- The ending character index from the string.output- The destination byte array.outputStartIndex- The starting index in the byte array to write to.- Returns:
- The total number of bytes written.
-
-