Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update Buffer to use correct names #20

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/com/jagex/runescape/Animation.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public static void method529(final byte[] data) {
final Buffer buffer = new Buffer(data);
buffer.position = data.length - 8;

final int attributesOffset = buffer.getUnsignedLEShort();
final int transformationOffset = buffer.getUnsignedLEShort();
final int durationOffset = buffer.getUnsignedLEShort();
final int baseOffset = buffer.getUnsignedLEShort();
final int attributesOffset = buffer.getUnsignedBEShort();
final int transformationOffset = buffer.getUnsignedBEShort();
final int durationOffset = buffer.getUnsignedBEShort();
final int baseOffset = buffer.getUnsignedBEShort();

int offset = 0;
final Buffer headerBuffer = new Buffer(data);
Expand All @@ -53,15 +53,15 @@ public static void method529(final byte[] data) {
baseBuffer.position = offset;

final Skins base = new Skins(baseBuffer);
final int count = headerBuffer.getUnsignedLEShort();
final int count = headerBuffer.getUnsignedBEShort();

final int[] transformationIndices = new int[500];
final int[] transformX = new int[500];
final int[] transformY = new int[500];
final int[] transformZ = new int[500];

for (int i = 0; i < count; i++) {
final int id = headerBuffer.getUnsignedLEShort();
final int id = headerBuffer.getUnsignedBEShort();

final Animation anim = animations[id] = new Animation();
anim.displayLength = durationBuffer.getUnsignedByte();
Expand Down
4 changes: 2 additions & 2 deletions src/com/jagex/runescape/Archive.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public Archive(final byte[] data) {
this.decompressed = false;
}

this.fileCount = buffer.getUnsignedLEShort();
this.fileCount = buffer.getUnsignedBEShort();
this.hashes = new int[this.fileCount];
this.decompressedSizes = new int[this.fileCount];
this.compressedSizes = new int[this.fileCount];
this.initialOffsets = new int[this.fileCount];
int offset = buffer.position + this.fileCount * 10;

for (int index = 0; index < this.fileCount; index++) {
this.hashes[index] = buffer.getInt();
this.hashes[index] = buffer.getIntBE();
this.decompressedSizes[index] = buffer.get3Bytes();
this.compressedSizes[index] = buffer.get3Bytes();
this.initialOffsets[index] = offset;
Expand Down
30 changes: 15 additions & 15 deletions src/com/jagex/runescape/Buffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public int getSignedLEShortA() {
return j;
}

public int getInt() {
public int getIntBE() {
this.position += 4;
return ((this.buffer[this.position - 4] & 0xff) << 24) + ((this.buffer[this.position - 3] & 0xff) << 16)
+ ((this.buffer[this.position - 2] & 0xff) << 8) + (this.buffer[this.position - 1] & 0xff);
Expand All @@ -130,13 +130,13 @@ public int getMESInt() { // Middle endian small int: B2 A1 D4 C3 (A1 smallest D4
+ ((this.buffer[this.position - 4] & 0xff) << 8) + (this.buffer[this.position - 3] & 0xff);
}

public long getLong() {
final long ms = this.getInt() & 0xffffffffL;
final long ls = this.getInt() & 0xffffffffL;
public long getLongBE() {
final long ms = this.getIntBE() & 0xffffffffL;
final long ls = this.getIntBE() & 0xffffffffL;
return (ms << 32) + ls;
}

public int getShort() {
public int getShortBE() {
this.position += 2;
int i = ((this.buffer[this.position - 2] & 0xff) << 8) + (this.buffer[this.position - 1] & 0xff);
if (i > 32767) {
Expand All @@ -150,7 +150,7 @@ public int getSmartA() {
if (i < 128) {
return this.getUnsignedByte() - 64;
} else {
return this.getUnsignedLEShort() - 49152;
return this.getUnsignedBEShort() - 49152;
}
}

Expand All @@ -159,7 +159,7 @@ public int getSmartB() {
if (i < 128) {
return this.getUnsignedByte();
} else {
return this.getUnsignedLEShort() - 32768;
return this.getUnsignedBEShort() - 32768;
}
}

Expand All @@ -186,22 +186,22 @@ public int getUnsignedByteS() {
return 128 - this.buffer[this.position++] & 0xff;
}

public int getUnsignedLEShort() {
public int getUnsignedBEShort() {
this.position += 2;
return ((this.buffer[this.position - 2] & 0xff) << 8) + (this.buffer[this.position - 1] & 0xff);
}

public int getUnsignedLEShortA() {
public int getUnsignedBEShortA() {
this.position += 2;
return ((this.buffer[this.position - 2] & 0xff) << 8) + (this.buffer[this.position - 1] - 128 & 0xff);
}

public int getUnsignedShort() {
public int getUnsignedLEShort() {
this.position += 2;
return ((this.buffer[this.position - 1] & 0xff) << 8) + (this.buffer[this.position - 2] & 0xff);
}

public int getUnsignedShortA() {
public int getUnsignedLEShortA() {
this.position += 2;
return ((this.buffer[this.position - 1] & 0xff) << 8) + (this.buffer[this.position - 2] - 128 & 0xff);
}
Expand Down Expand Up @@ -242,7 +242,7 @@ public void putBytesA(final int i, final byte[] buf, final int j) {

}

public void putInt(final int i) {
public void putIntBE(final int i) {
this.buffer[this.position++] = (byte) (i >> 24);
this.buffer[this.position++] = (byte) (i >> 16);
this.buffer[this.position++] = (byte) (i >> 8);
Expand All @@ -266,7 +266,7 @@ public void putLEShortA(final int j) {
this.buffer[this.position++] = (byte) (j >> 8);
}

public void putLong(final long l) {
public void putLongBE(final long l) {
try {
this.buffer[this.position++] = (byte) (int) (l >> 56);
this.buffer[this.position++] = (byte) (int) (l >> 48);
Expand All @@ -286,12 +286,12 @@ public void putOpcode(final int i) {
this.buffer[this.position++] = (byte) (i + this.encryptor.value());
}

public void putShort(final int i) {
public void putShortBE(final int i) {
this.buffer[this.position++] = (byte) (i >> 8);
this.buffer[this.position++] = (byte) i;
}

public void putShortA(final int j) {
public void putShortBEA(final int j) {
this.buffer[this.position++] = (byte) (j >> 8);
this.buffer[this.position++] = (byte) (j + 128);
}
Expand Down
10 changes: 5 additions & 5 deletions src/com/jagex/runescape/Censor.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private static void load(final Buffer fragmentsenc, final Buffer badenc, final B
}

private static void loadTldList(final Buffer buffer) {
final int length = buffer.getInt();
final int length = buffer.getIntBE();
tlds = new char[length][];
tldTypes = new int[length];

Expand All @@ -53,22 +53,22 @@ private static void loadTldList(final Buffer buffer) {
}

private static void loadBadEnc(final Buffer buffer) {
final int length = buffer.getInt();
final int length = buffer.getIntBE();
bads = new char[length][];
badCombinations = new byte[length][][];
loadBadEnc(buffer, badCombinations, bads);
}

private static void loadDomainEnc(final Buffer buffer) {
final int i = buffer.getInt();
final int i = buffer.getIntBE();
domains = new char[i][];
loadDomainEnc(buffer, domains);
}

private static void loadFragmentsEnc(final Buffer buffer) {
fragments = new int[buffer.getInt()];
fragments = new int[buffer.getIntBE()];
for (int i = 0; i < fragments.length; i++) {
fragments[i] = buffer.getUnsignedShort();
fragments[i] = buffer.getUnsignedLEShort();
}
}

Expand Down
Loading