Change
This commit is contained in:
1 parent
d8a0b0e9ea
commit
52ffdc89c9
9 files changed
+11395
-11461
No files matched your search
+267
-262
@@ -2,6 +2,7 @@ import org.apache.commons.math3.random.ISAACRandom;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* A {@link Buffer} encapsulates a finite amount of data and provides methods for reading and writing to that data.
|
||||
@@ -28,319 +29,323 @@ import java.nio.charset.StandardCharsets;
|
||||
*/
|
||||
public class Buffer extends DoublyLinkedList.Node {
|
||||
|
||||
private static final int[] BITMASK = {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};
|
||||
private static final int[] BITMASK = {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};
|
||||
|
||||
public static Buffer create(int sizeType) {
|
||||
Buffer buffer = new Buffer();
|
||||
buffer.position = 0;
|
||||
public static Buffer create(int sizeType) {
|
||||
Buffer buffer = new Buffer();
|
||||
buffer.position = 0;
|
||||
|
||||
if (sizeType == 0) {
|
||||
buffer.data = new byte[100];
|
||||
} else if (sizeType == 1) {
|
||||
buffer.data = new byte[5000];
|
||||
} else {
|
||||
buffer.data = new byte[30000];
|
||||
}
|
||||
if (sizeType == 0) {
|
||||
buffer.data = new byte[100];
|
||||
} else if (sizeType == 1) {
|
||||
buffer.data = new byte[5000];
|
||||
} else {
|
||||
buffer.data = new byte[30000];
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public byte[] data;
|
||||
public int position;
|
||||
public int bitPosition;
|
||||
public ISAACRandom random;
|
||||
public byte[] data;
|
||||
public int position;
|
||||
public int bitPosition;
|
||||
public ISAACRandom random;
|
||||
|
||||
public Buffer() {
|
||||
}
|
||||
public Buffer() {
|
||||
}
|
||||
|
||||
public Buffer(byte[] src) {
|
||||
data = src;
|
||||
position = 0;
|
||||
}
|
||||
public Buffer(byte[] src) {
|
||||
data = src;
|
||||
position = 0;
|
||||
}
|
||||
|
||||
public void putOp(int i) {
|
||||
data[position++] = (byte) (i + random.nextInt());
|
||||
}
|
||||
public void putOp(int i) {
|
||||
data[position++] = (byte) (i + random.nextInt());
|
||||
}
|
||||
|
||||
public void putSize1(int i) {
|
||||
data[position - i - 1] = (byte) i;
|
||||
}
|
||||
public void putSize1(int i) {
|
||||
data[position - i - 1] = (byte) i;
|
||||
}
|
||||
|
||||
public void put1(int i) {
|
||||
data[position++] = (byte) i;
|
||||
}
|
||||
public void put1(int i) {
|
||||
data[position++] = (byte) i;
|
||||
}
|
||||
|
||||
public void put1C(int i) {
|
||||
data[position++] = (byte) (-i);
|
||||
}
|
||||
public void put1C(int i) {
|
||||
data[position++] = (byte) (-i);
|
||||
}
|
||||
|
||||
public void put1S(int j) {
|
||||
data[position++] = (byte) (128 - j);
|
||||
}
|
||||
public void put1S(int j) {
|
||||
data[position++] = (byte) (128 - j);
|
||||
}
|
||||
|
||||
public void put2(int i) {
|
||||
data[position++] = (byte) (i >> 8);
|
||||
data[position++] = (byte) i;
|
||||
}
|
||||
public void put2(int i) {
|
||||
data[position++] = (byte) (i >> 8);
|
||||
data[position++] = (byte) i;
|
||||
}
|
||||
|
||||
public void put2A(int j) {
|
||||
data[position++] = (byte) (j >> 8);
|
||||
data[position++] = (byte) (j + 128);
|
||||
}
|
||||
public void put2A(int j) {
|
||||
data[position++] = (byte) (j >> 8);
|
||||
data[position++] = (byte) (j + 128);
|
||||
}
|
||||
|
||||
public void put2LE(int i) {
|
||||
data[position++] = (byte) i;
|
||||
data[position++] = (byte) (i >> 8);
|
||||
}
|
||||
public void put2LE(int i) {
|
||||
data[position++] = (byte) i;
|
||||
data[position++] = (byte) (i >> 8);
|
||||
}
|
||||
|
||||
public void put2LEA(int j) {
|
||||
data[position++] = (byte) (j + 128);
|
||||
data[position++] = (byte) (j >> 8);
|
||||
}
|
||||
public void put2LEA(int j) {
|
||||
data[position++] = (byte) (j + 128);
|
||||
data[position++] = (byte) (j >> 8);
|
||||
}
|
||||
|
||||
public void put3(int i) {
|
||||
data[position++] = (byte) (i >> 16);
|
||||
data[position++] = (byte) (i >> 8);
|
||||
data[position++] = (byte) i;
|
||||
}
|
||||
public void put3(int i) {
|
||||
data[position++] = (byte) (i >> 16);
|
||||
data[position++] = (byte) (i >> 8);
|
||||
data[position++] = (byte) i;
|
||||
}
|
||||
|
||||
public void put4(int i) {
|
||||
data[position++] = (byte) (i >> 24);
|
||||
data[position++] = (byte) (i >> 16);
|
||||
data[position++] = (byte) (i >> 8);
|
||||
data[position++] = (byte) i;
|
||||
}
|
||||
public void put4(int i) {
|
||||
data[position++] = (byte) (i >> 24);
|
||||
data[position++] = (byte) (i >> 16);
|
||||
data[position++] = (byte) (i >> 8);
|
||||
data[position++] = (byte) i;
|
||||
}
|
||||
|
||||
public void put4LE(int j) {
|
||||
data[position++] = (byte) j;
|
||||
data[position++] = (byte) (j >> 8);
|
||||
data[position++] = (byte) (j >> 16);
|
||||
data[position++] = (byte) (j >> 24);
|
||||
}
|
||||
public void put4LE(int j) {
|
||||
data[position++] = (byte) j;
|
||||
data[position++] = (byte) (j >> 8);
|
||||
data[position++] = (byte) (j >> 16);
|
||||
data[position++] = (byte) (j >> 24);
|
||||
}
|
||||
|
||||
public void put8(long l) {
|
||||
data[position++] = (byte) (int) (l >> 56);
|
||||
data[position++] = (byte) (int) (l >> 48);
|
||||
data[position++] = (byte) (int) (l >> 40);
|
||||
data[position++] = (byte) (int) (l >> 32);
|
||||
data[position++] = (byte) (int) (l >> 24);
|
||||
data[position++] = (byte) (int) (l >> 16);
|
||||
data[position++] = (byte) (int) (l >> 8);
|
||||
data[position++] = (byte) (int) l;
|
||||
}
|
||||
public void put8(long l) {
|
||||
data[position++] = (byte) (int) (l >> 56);
|
||||
data[position++] = (byte) (int) (l >> 48);
|
||||
data[position++] = (byte) (int) (l >> 40);
|
||||
data[position++] = (byte) (int) (l >> 32);
|
||||
data[position++] = (byte) (int) (l >> 24);
|
||||
data[position++] = (byte) (int) (l >> 16);
|
||||
data[position++] = (byte) (int) (l >> 8);
|
||||
data[position++] = (byte) (int) l;
|
||||
}
|
||||
|
||||
public void put(String s) {
|
||||
put(s.getBytes(StandardCharsets.ISO_8859_1));
|
||||
put1('\n');
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
System.out.println(Arrays.toString("Test".getBytes(StandardCharsets.UTF_8)));
|
||||
}
|
||||
|
||||
public void put(byte[] src, int len, int off) {
|
||||
System.arraycopy(src, off, data, position, len);
|
||||
position += len;
|
||||
}
|
||||
public void put(String s) {
|
||||
put(s.getBytes());
|
||||
put1('\n');
|
||||
}
|
||||
|
||||
public void put(byte[] src) {
|
||||
put(src, 0, src.length);
|
||||
}
|
||||
public void put(byte[] src, int len, int off) {
|
||||
System.arraycopy(src, off, data, position, len);
|
||||
position += len;
|
||||
}
|
||||
|
||||
public void putA(byte[] src, int off, int len) {
|
||||
for (int i = (off + len) - 1; i >= off; i--) {
|
||||
data[position++] = (byte) (src[i] + 128);
|
||||
}
|
||||
}
|
||||
public void put(byte[] src) {
|
||||
put(src, 0, src.length);
|
||||
}
|
||||
|
||||
public byte get1() {
|
||||
return data[position++];
|
||||
}
|
||||
public void putA(byte[] src, int off, int len) {
|
||||
for (int i = (off + len) - 1; i >= off; i--) {
|
||||
data[position++] = (byte) (src[i] + 128);
|
||||
}
|
||||
}
|
||||
|
||||
public byte get1C() {
|
||||
return (byte) (-data[position++]);
|
||||
}
|
||||
public byte get1() {
|
||||
return data[position++];
|
||||
}
|
||||
|
||||
public byte get1S() {
|
||||
return (byte) (128 - data[position++]);
|
||||
}
|
||||
public byte get1C() {
|
||||
return (byte) (-data[position++]);
|
||||
}
|
||||
|
||||
public int get1U() {
|
||||
return data[position++] & 0xff;
|
||||
}
|
||||
public byte get1S() {
|
||||
return (byte) (128 - data[position++]);
|
||||
}
|
||||
|
||||
public int get1UA() {
|
||||
return (data[position++] - 128) & 0xff;
|
||||
}
|
||||
public int get1U() {
|
||||
return data[position++] & 0xff;
|
||||
}
|
||||
|
||||
public int get1UC() {
|
||||
return -data[position++] & 0xff;
|
||||
}
|
||||
public int get1UA() {
|
||||
return (data[position++] - 128) & 0xff;
|
||||
}
|
||||
|
||||
public int get1US() {
|
||||
return (128 - data[position++]) & 0xff;
|
||||
}
|
||||
public int get1UC() {
|
||||
return -data[position++] & 0xff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a 1 or 2 byte varint which has the range [-16384...16383].
|
||||
*
|
||||
* @return the value.
|
||||
*/
|
||||
public int getSmart() {
|
||||
int i = data[position] & 0xff;
|
||||
if (i < 0x80) {
|
||||
return get1U() - 0x40;
|
||||
} else {
|
||||
return get2U() - 0xC000;
|
||||
}
|
||||
}
|
||||
public int get1US() {
|
||||
return (128 - data[position++]) & 0xff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a 1 or 2 byte varint which has the range [0...32768].
|
||||
*
|
||||
* @return the value.
|
||||
*/
|
||||
public int getSmartU() {
|
||||
int i = data[position] & 0xff;
|
||||
if (i < 0x80) {
|
||||
return get1U();
|
||||
} else {
|
||||
return get2U() - 0x8000;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Gets a 1 or 2 byte varint which has the range [-16384...16383].
|
||||
*
|
||||
* @return the value.
|
||||
*/
|
||||
public int getSmart() {
|
||||
int i = data[position] & 0xff;
|
||||
if (i < 0x80) {
|
||||
return get1U() - 0x40;
|
||||
} else {
|
||||
return get2U() - 0xC000;
|
||||
}
|
||||
}
|
||||
|
||||
public int get2U() {
|
||||
position += 2;
|
||||
return ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
|
||||
}
|
||||
/**
|
||||
* Gets a 1 or 2 byte varint which has the range [0...32768].
|
||||
*
|
||||
* @return the value.
|
||||
*/
|
||||
public int getSmartU() {
|
||||
int i = data[position] & 0xff;
|
||||
if (i < 0x80) {
|
||||
return get1U();
|
||||
} else {
|
||||
return get2U() - 0x8000;
|
||||
}
|
||||
}
|
||||
|
||||
public int get2UA() {
|
||||
position += 2;
|
||||
return ((data[position - 2] & 0xff) << 8) + ((data[position - 1] - 128) & 0xff);
|
||||
}
|
||||
public int get2U() {
|
||||
position += 2;
|
||||
return ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
|
||||
}
|
||||
|
||||
public int get2ULE() {
|
||||
position += 2;
|
||||
return ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
|
||||
}
|
||||
public int get2UA() {
|
||||
position += 2;
|
||||
return ((data[position - 2] & 0xff) << 8) + ((data[position - 1] - 128) & 0xff);
|
||||
}
|
||||
|
||||
public int get2ULEA() {
|
||||
position += 2;
|
||||
return ((data[position - 1] & 0xff) << 8) + ((data[position - 2] - 128) & 0xff);
|
||||
}
|
||||
public int get2ULE() {
|
||||
position += 2;
|
||||
return ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
|
||||
}
|
||||
|
||||
public int get2() {
|
||||
position += 2;
|
||||
int i = ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
|
||||
if (i > 0x7fff) {
|
||||
i -= 0x10000;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
public int get2ULEA() {
|
||||
position += 2;
|
||||
return ((data[position - 1] & 0xff) << 8) + ((data[position - 2] - 128) & 0xff);
|
||||
}
|
||||
|
||||
public int get2LE() {
|
||||
position += 2;
|
||||
int j = ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
|
||||
if (j > 0x7fff) {
|
||||
j -= 0x10000;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
public int get2() {
|
||||
position += 2;
|
||||
int i = ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
|
||||
if (i > 0x7fff) {
|
||||
i -= 0x10000;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public int get2LEA() {
|
||||
position += 2;
|
||||
int j = ((data[position - 1] & 0xff) << 8) + ((data[position - 2] - 128) & 0xff);
|
||||
if (j > 0x7fff) {
|
||||
j -= 0x10000;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
public int get2LE() {
|
||||
position += 2;
|
||||
int j = ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
|
||||
if (j > 0x7fff) {
|
||||
j -= 0x10000;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
public int get3() {
|
||||
position += 3;
|
||||
return ((data[position - 3] & 0xff) << 16) + ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
|
||||
}
|
||||
public int get2LEA() {
|
||||
position += 2;
|
||||
int j = ((data[position - 1] & 0xff) << 8) + ((data[position - 2] - 128) & 0xff);
|
||||
if (j > 0x7fff) {
|
||||
j -= 0x10000;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
public int get4() {
|
||||
position += 4;
|
||||
return ((data[position - 4] & 0xff) << 24) + ((data[position - 3] & 0xff) << 16) + ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
|
||||
}
|
||||
public int get3() {
|
||||
position += 3;
|
||||
return ((data[position - 3] & 0xff) << 16) + ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
|
||||
}
|
||||
|
||||
public int get4ME() {
|
||||
position += 4;
|
||||
return ((data[position - 3] & 0xff) << 24) + ((data[position - 4] & 0xff) << 16) + ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
|
||||
}
|
||||
public int get4() {
|
||||
position += 4;
|
||||
return ((data[position - 4] & 0xff) << 24) + ((data[position - 3] & 0xff) << 16) + ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
|
||||
}
|
||||
|
||||
public int get4RME() {
|
||||
position += 4;
|
||||
return ((data[position - 2] & 0xff) << 24) + ((data[position - 1] & 0xff) << 16) + ((data[position - 4] & 0xff) << 8) + (data[position - 3] & 0xff);
|
||||
}
|
||||
public int get4ME() {
|
||||
position += 4;
|
||||
return ((data[position - 3] & 0xff) << 24) + ((data[position - 4] & 0xff) << 16) + ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
|
||||
}
|
||||
|
||||
public long get8() {
|
||||
long l = (long) get4() & 0xffffffffL;
|
||||
long l1 = (long) get4() & 0xffffffffL;
|
||||
return (l << 32) + l1;
|
||||
}
|
||||
public int get4RME() {
|
||||
position += 4;
|
||||
return ((data[position - 2] & 0xff) << 24) + ((data[position - 1] & 0xff) << 16) + ((data[position - 4] & 0xff) << 8) + (data[position - 3] & 0xff);
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
int start = position;
|
||||
while (data[position++] != '\n') {
|
||||
}
|
||||
return new String(data, start, position - start - 1);
|
||||
}
|
||||
public long get8() {
|
||||
long l = (long) get4() & 0xffffffffL;
|
||||
long l1 = (long) get4() & 0xffffffffL;
|
||||
return (l << 32) + l1;
|
||||
}
|
||||
|
||||
public byte[] getStringRaw() {
|
||||
int start = position;
|
||||
while (data[position++] != '\n') {
|
||||
}
|
||||
byte[] raw = new byte[position - start - 1];
|
||||
for (int j = start; j < (position - 1); j++) {
|
||||
raw[j - start] = data[j];
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
public String getString() {
|
||||
int start = position;
|
||||
while (data[position++] != '\n') {
|
||||
}
|
||||
return new String(data, start, position - start - 1);
|
||||
}
|
||||
|
||||
public void get(byte[] dst, int off, int len) {
|
||||
System.arraycopy(data, position, dst, off, len);
|
||||
position += len;
|
||||
}
|
||||
public byte[] getStringRaw() {
|
||||
int start = position;
|
||||
while (data[position++] != '\n') {
|
||||
}
|
||||
byte[] raw = new byte[position - start - 1];
|
||||
for (int j = start; j < (position - 1); j++) {
|
||||
raw[j - start] = data[j];
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
|
||||
public void getReversed(byte[] dst, int off, int len) {
|
||||
for (int i = (off + len) - 1; i >= off; i--) {
|
||||
dst[i] = data[position++];
|
||||
}
|
||||
}
|
||||
public void get(byte[] dst, int off, int len) {
|
||||
System.arraycopy(data, position, dst, off, len);
|
||||
position += len;
|
||||
}
|
||||
|
||||
public void accessBits() {
|
||||
bitPosition = position * 8;
|
||||
}
|
||||
public void getReversed(byte[] dst, int off, int len) {
|
||||
for (int i = (off + len) - 1; i >= off; i--) {
|
||||
dst[i] = data[position++];
|
||||
}
|
||||
}
|
||||
|
||||
public int getBits(int n) {
|
||||
int bytePos = bitPosition >> 3;
|
||||
int remaining = 8 - (bitPosition & 7);
|
||||
int value = 0;
|
||||
bitPosition += n;
|
||||
for (; n > remaining; remaining = 8) {
|
||||
value += (data[bytePos++] & BITMASK[remaining]) << (n - remaining);
|
||||
n -= remaining;
|
||||
}
|
||||
if (n == remaining) {
|
||||
value += data[bytePos] & BITMASK[remaining];
|
||||
} else {
|
||||
value += (data[bytePos] >> (remaining - n)) & BITMASK[n];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
public void accessBits() {
|
||||
bitPosition = position * 8;
|
||||
}
|
||||
|
||||
public void accessBytes() {
|
||||
position = (bitPosition + 7) / 8;
|
||||
}
|
||||
public int getBits(int n) {
|
||||
int bytePos = bitPosition >> 3;
|
||||
int remaining = 8 - (bitPosition & 7);
|
||||
int value = 0;
|
||||
bitPosition += n;
|
||||
for (; n > remaining; remaining = 8) {
|
||||
value += (data[bytePos++] & BITMASK[remaining]) << (n - remaining);
|
||||
n -= remaining;
|
||||
}
|
||||
if (n == remaining) {
|
||||
value += data[bytePos] & BITMASK[remaining];
|
||||
} else {
|
||||
value += (data[bytePos] >> (remaining - n)) & BITMASK[n];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public void encrypt(BigInteger exponent, BigInteger modulus) {
|
||||
int length = position;
|
||||
position = 0;
|
||||
byte[] raw = new byte[length];
|
||||
get(raw, 0, length);
|
||||
byte[] encrypted = new BigInteger(raw).toByteArray();//.modPow(exponent, modulus).toByteArray();
|
||||
position = 0;
|
||||
put1(encrypted.length);
|
||||
put(encrypted, encrypted.length, 0);
|
||||
}
|
||||
public void accessBytes() {
|
||||
position = (bitPosition + 7) / 8;
|
||||
}
|
||||
|
||||
public void encrypt(BigInteger exponent, BigInteger modulus) {
|
||||
int length = position;
|
||||
position = 0;
|
||||
byte[] raw = new byte[length];
|
||||
get(raw, 0, length);
|
||||
byte[] encrypted = new BigInteger(raw).modPow(exponent, modulus).toByteArray();
|
||||
position = 0;
|
||||
put1(encrypted.length);
|
||||
put(encrypted, encrypted.length, 0);
|
||||
}
|
||||
|
||||
}
|
||||
+11112
-11173
File diff suppressed because it is too large.
Load diff
@@ -289,7 +289,7 @@ public class OnDemand implements Runnable {
|
||||
return;
|
||||
}
|
||||
socketOpenTime = now;
|
||||
socket = game.method19(43594 + Game.portOffset);
|
||||
socket = game.openSocket(43594 + Game.portOffset);
|
||||
in = socket.getInputStream();
|
||||
out = socket.getOutputStream();
|
||||
out.write(15);
|
||||
|
||||
Reference in new issue
Block a user