Implementation of Gradle build framework (#369)

* Cleanup

* Add build file

* The great migration

* Restore MINA to 1.1.7

* Removed .gradle

* Added flatdir for libs with no artifact repository

* Add README.md, rename Implementation-Title
This commit is contained in:
Damion
2020-02-04 09:13:57 +11:00
committed by GitHub
parent 54f42aaf8a
commit 02b4df2666
858 changed files with 99 additions and 124579 deletions
@@ -0,0 +1,112 @@
package com.rebotted.util;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;
/*
* Author: Nightleaf <colton.thompson@live.com>
*/
public class GameLogger {
public static String getTime() {
Calendar cal = new GregorianCalendar();
String day, month, hour, minute;
int YEAR = cal.get(Calendar.YEAR);
int MONTH = cal.get(Calendar.MONTH) + 1;
int DAY = cal.get(Calendar.DAY_OF_MONTH);
int HOUR = cal.get(Calendar.HOUR_OF_DAY);
int MIN = cal.get(Calendar.MINUTE);
day = DAY < 10 ? "0" + DAY : "" + DAY;
month = MONTH < 10 ? "0" + MONTH : "" + MONTH;
hour = HOUR < 10 ? "0" + HOUR : "" + HOUR;
minute = MIN < 10 ? "0" + MIN : "" + MIN;
return "[" + YEAR + "/" + month + "/" + day + "] " + hour + ":" + minute + " ";
}
/**
* Formats a currency string just like RS.
*
* @param cash
* @return
*/
public static String formatCurrency(int cash) {
String s = String.valueOf(cash);
for (int k = s.length() - 3; k > 0; k -= 3) {
s = s.substring(0, k).replace(",", ".") + "," + s.substring(k);
}
if (s.length() > 8) {
s = s.substring(0, s.length() - 8).replace(",", ".") + " million (" + s + ")";
} else if (s.length() > 4) {
s = s.substring(0, s.length() - 4) + "K (" + s + ")";
}
return " " + s;
}
/**
* Writes to a log file.
*
* @param log
* the log file.
* @param data
* the data we are writing to the log.
*/
public static void writeLog(String player, String logType, String data) {
File log = null;
if (logType.equalsIgnoreCase("alchemy")) {
log = new File("./data/logs/alchlogs/" + player + ".txt");
} else if (logType.equalsIgnoreCase("shopselling")) {
log = new File("./data/logs/shopselling/" + player + ".txt");
} else if (logType.equalsIgnoreCase("shopbuying")) {
log = new File("./data/logs/shopbuying/" + player + ".txt");
} else if (logType.equalsIgnoreCase("dropitem")) {
log = new File("./data/logs/dropitem/" + player + ".txt");
} else if (logType.equalsIgnoreCase("clickitem")) {
log = new File("./data/logs/clickitem/" + player + ".txt");
} else if (logType.equalsIgnoreCase("pickupitem")) {
log = new File("./data/logs/pickupitem/" + player + ".txt");
} else if (logType.equalsIgnoreCase("commands")) {
log = new File("./data/logs/commands/" + player + ".txt");
} else if (logType.equalsIgnoreCase("pmsent")) {
log = new File("./data/logs/privatemessages/pmsent/" + player + ".txt");
} else if (logType.equalsIgnoreCase("pmrecieved")) {
log = new File("./data/logs/privatemessages/pmrecieved/" + player + ".txt");
} else if (logType.equalsIgnoreCase("tradesgave")) {
log = new File("./data/logs/trades/gave/" + player + ".txt");
} else if (logType.equalsIgnoreCase("tradesrecieved")) {
log = new File("./data/logs/trades/recieved/" + player + ".txt");
} else if (logType.equalsIgnoreCase("pkingkilled")) {
log = new File("./data/logs/pking/killed/" + player + ".txt");
} else if (logType.equalsIgnoreCase("pkingkiller")) {
log = new File("./data/logs/pking/killer/" + player + ".txt");
} else if (logType.equalsIgnoreCase("duelingkilled")) {
log = new File("./data/logs/dueling/killed/" + player + ".txt");
} else if (logType.equalsIgnoreCase("duelingkiller")) {
log = new File("./data/logs/dueling/killer/" + player + ".txt");
} else {
log = new File("./data/logs/" + player + ".txt");
}
if (!log.exists()) {
try {
log.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
FileWriter logFile = new FileWriter(log, true);
BufferedWriter bf = new BufferedWriter(logFile);
bf.write(getTime() + "" + data + "");
bf.newLine();
bf.flush();
bf.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
@@ -0,0 +1,36 @@
package com.rebotted.util;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
public class HostBlacklist {
private static final String BLACKLIST_DIR = "./data/blacklist.txt";
private static List<String> blockedHostnames = new ArrayList<String>();
public static List<String> getBlockedHostnames() {
return blockedHostnames;
}
public static boolean isBlocked(String host) {
return blockedHostnames.contains(host.toLowerCase());
}
public static void loadBlacklist() {
String word = null;
try {
BufferedReader in = new BufferedReader(
new FileReader(BLACKLIST_DIR));
while ((word = in.readLine()) != null) {
blockedHostnames.add(word.toLowerCase());
}
in.close();
in = null;
} catch (final Exception e) {
System.out.println("Could not load blacklisted hosts.");
}
}
}
@@ -0,0 +1,175 @@
package com.rebotted.util;
public class ISAACRandomGen {
public int count;
public int[] results;
public int[] memory;
public int accumulator;
public int lastResult;
public int counter;
public ISAACRandomGen(int[] seed) {
memory = new int[256];
results = new int[256];
System.arraycopy(seed, 0, results, 0, seed.length);
initializeKeySet();
}
public int getNextKey() {
// Server.add(Thread.currentThread().getName());
// System.out.println(Thread.currentThread().getName());
if (count-- == 0) {
generateNextKeySet();
count = 255;
}
return results[count];
}
public void generateNextKeySet() {
lastResult += ++counter;
for (int i = 0; i < 256; i++) {
int j = memory[i];
if ((i & 3) == 0) {
accumulator ^= accumulator << 13;
} else if ((i & 3) == 1) {
accumulator ^= accumulator >>> 6;
} else if ((i & 3) == 2) {
accumulator ^= accumulator << 2;
} else if ((i & 3) == 3) {
accumulator ^= accumulator >>> 16;
}
accumulator += memory[i + 128 & 0xff];
int k;
memory[i] = k = memory[(j & 0x3fc) >> 2] + accumulator + lastResult;
results[i] = lastResult = memory[(k >> 8 & 0x3fc) >> 2] + j;
}
}
public void initializeKeySet() {
int i1;
int j1;
int k1;
int l1;
int i2;
int j2;
int k2;
int l = i1 = j1 = k1 = l1 = i2 = j2 = k2 = 0x9e3779b9;
for (int i = 0; i < 4; i++) {
l ^= i1 << 11;
k1 += l;
i1 += j1;
i1 ^= j1 >>> 2;
l1 += i1;
j1 += k1;
j1 ^= k1 << 8;
i2 += j1;
k1 += l1;
k1 ^= l1 >>> 16;
j2 += k1;
l1 += i2;
l1 ^= i2 << 10;
k2 += l1;
i2 += j2;
i2 ^= j2 >>> 4;
l += i2;
j2 += k2;
j2 ^= k2 << 8;
i1 += j2;
k2 += l;
k2 ^= l >>> 9;
j1 += k2;
l += i1;
}
for (int j = 0; j < 256; j += 8) {
l += results[j];
i1 += results[j + 1];
j1 += results[j + 2];
k1 += results[j + 3];
l1 += results[j + 4];
i2 += results[j + 5];
j2 += results[j + 6];
k2 += results[j + 7];
l ^= i1 << 11;
k1 += l;
i1 += j1;
i1 ^= j1 >>> 2;
l1 += i1;
j1 += k1;
j1 ^= k1 << 8;
i2 += j1;
k1 += l1;
k1 ^= l1 >>> 16;
j2 += k1;
l1 += i2;
l1 ^= i2 << 10;
k2 += l1;
i2 += j2;
i2 ^= j2 >>> 4;
l += i2;
j2 += k2;
j2 ^= k2 << 8;
i1 += j2;
k2 += l;
k2 ^= l >>> 9;
j1 += k2;
l += i1;
memory[j] = l;
memory[j + 1] = i1;
memory[j + 2] = j1;
memory[j + 3] = k1;
memory[j + 4] = l1;
memory[j + 5] = i2;
memory[j + 6] = j2;
memory[j + 7] = k2;
}
for (int k = 0; k < 256; k += 8) {
l += memory[k];
i1 += memory[k + 1];
j1 += memory[k + 2];
k1 += memory[k + 3];
l1 += memory[k + 4];
i2 += memory[k + 5];
j2 += memory[k + 6];
k2 += memory[k + 7];
l ^= i1 << 11;
k1 += l;
i1 += j1;
i1 ^= j1 >>> 2;
l1 += i1;
j1 += k1;
j1 ^= k1 << 8;
i2 += j1;
k1 += l1;
k1 ^= l1 >>> 16;
j2 += k1;
l1 += i2;
l1 ^= i2 << 10;
k2 += l1;
i2 += j2;
i2 ^= j2 >>> 4;
l += i2;
j2 += k2;
j2 ^= k2 << 8;
i1 += j2;
k2 += l;
k2 ^= l >>> 9;
j1 += k2;
l += i1;
memory[k] = l;
memory[k + 1] = i1;
memory[k + 2] = j1;
memory[k + 3] = k1;
memory[k + 4] = l1;
memory[k + 5] = i2;
memory[k + 6] = j2;
memory[k + 7] = k2;
}
generateNextKeySet();
count = 256;
}
}
@@ -0,0 +1,9 @@
package com.rebotted.util;
/**
* Easy access to common interface IDs
*/
public class MainFrameIDs {
public static final int DEPOSIT_BOX = 4465;
public static final int BANK = 5292; //Might be incorrect!!
}
@@ -0,0 +1,319 @@
package com.rebotted.util;
import java.text.NumberFormat;
import java.util.ArrayList;
public class Misc {
public static String formatPlayerName(String str) {
str = ucFirst(str);
str.replace("_", " ");
return str;
}
public static int random(final float range) {
return (int) (java.lang.Math.random() * (range + 1));
}
// return a random number from 0 → range - 1
public static int randomMinusOne(int range) {
return (int) Math.random() * range;
}
public static double distance(int x1, int y1, int x2, int y2 ) {
return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
}
public static boolean goodDistance(int objectX, int objectY, int playerX, int playerY, int distance) {
return objectX - playerX <= distance && objectX - playerX >= -distance && objectY - playerY <= distance && objectY - playerY >= -distance;
}
public static String longToReportPlayerName(long l) {
int i = 0;
final char ac[] = new char[12];
while (l != 0L) {
final long l1 = l;
l /= 37L;
ac[11 - i++] = Misc.playerNameXlateTable[(int) (l1 - l * 37L)];
}
return new String(ac, 12 - i, i);
}
public static int random3(int range) {
return (int) (java.lang.Math.random() * range);
}
public static int randomNumber(int range) {
return (int) (Math.random() * range);
}
public static String longToPlayerName(long l) {
int i = 0;
char ac[] = new char[12];
while (l != 0L) {
long l1 = l;
l /= 37L;
ac[11 - i++] = xlateTable[(int) (l1 - l * 37L)];
}
return new String(ac, 12 - i, i);
}
public static final char playerNameXlateTable[] = { '_', 'a', 'b', 'c',
'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2',
'3', '4', '5', '6', '7', '8', '9', '[', ']', '/', '-', ' ' };
public static String longToPlayerName2(long l) {
int i = 0;
char ac[] = new char[99];
while (l != 0L) {
long l1 = l;
l /= 37L;
ac[11 - i++] = playerNameXlateTable[(int) (l1 - l * 37L)];
}
return new String(ac, 12 - i, i);
}
public static String format(int num) {
return NumberFormat.getInstance().format(num);
}
public static String ucFirst(String str) {
str = str.toLowerCase();
if (str.length() > 1) {
str = str.substring(0, 1).toUpperCase() + str.substring(1);
} else {
return str.toUpperCase();
}
return str;
}
public static void print_debug(String str) {
System.out.print(str);
}
public static void println_debug(String str) {
System.out.println(str);
}
public static void print(String str) {
System.out.print(str);
}
public static void println(String str) {
System.out.println(str);
}
public static String Hex(byte data[]) {
return Hex(data, 0, data.length);
}
public static String Hex(byte data[], int offset, int len) {
String temp = "";
for (int cntr = 0; cntr < len; cntr++) {
int num = data[offset + cntr] & 0xFF;
String myStr;
if (num < 16) {
myStr = "0";
} else {
myStr = "";
}
temp += myStr + Integer.toHexString(num) + " ";
}
return temp.toUpperCase().trim();
}
public static int hexToInt(byte data[], int offset, int len) {
int temp = 0;
int i = 1000;
for (int cntr = 0; cntr < len; cntr++) {
int num = (data[offset + cntr] & 0xFF) * i;
temp += num;
if (i > 1) {
i = i / 1000;
}
}
return temp;
}
public static int random2(int range) {
return (int) (java.lang.Math.random() * range + 1);
}
// return a random number from 0 → range (including range)
public static int random(int range) {
return (int) (java.lang.Math.random() * (++range));
}
// return a random number between & including the min/max values
public static int random(int min, int max) {
++max;
return (int) Math.floor(Math.random() * (max - min)) + min;
}
public static int randomArrayItem(int[] arr) {
return arr[(int) Math.floor(Math.random() * arr.length)];
}
public static int randomArrayListItem(ArrayList<Integer> arr) {
int index = (int) Math.floor(Math.random() * arr.size());
return arr.get(index);
}
public static long playerNameToInt64(String s) {
long l = 0L;
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
l *= 37L;
if (c >= 'A' && c <= 'Z') {
l += 1 + c - 65;
} else if (c >= 'a' && c <= 'z') {
l += 1 + c - 97;
} else if (c >= '0' && c <= '9') {
l += 27 + c - 48;
}
}
while (l % 37L == 0L && l != 0L) {
l /= 37L;
}
return l;
}
private static char decodeBuf[] = new char[4096];
public static String textUnpack(byte packedData[], int size) {
int idx = 0, highNibble = -1;
for (int i = 0; i < size * 2; i++) {
int val = packedData[i / 2] >> 4 - 4 * (i % 2) & 0xf;
if (highNibble == -1) {
if (val < 13) {
decodeBuf[idx++] = xlateTable[val];
} else {
highNibble = val;
}
} else {
decodeBuf[idx++] = xlateTable[(highNibble << 4) + val - 195];
highNibble = -1;
}
}
return new String(decodeBuf, 0, idx);
}
public static String optimizeText(String text) {
char buf[] = text.toCharArray();
boolean endMarker = true;
for (int i = 0; i < buf.length; i++) {
char c = buf[i];
if (endMarker && c >= 'a' && c <= 'z') {
buf[i] -= 0x20;
endMarker = false;
}
if (c == '.' || c == '!' || c == '?') {
endMarker = true;
}
}
return new String(buf, 0, buf.length);
}
public static void textPack(Stream inStream, String text) {
if (text.length() > 80) {
text = text.substring(0, 80);
}
text = text.toLowerCase();
int carryOverNibble = -1;
inStream.currentOffset = 0;
for (int idx = 0; idx < text.length(); idx++) {
char c = text.charAt(idx);
int tableIdx = 0;
for (int i = 0; i < xlateTable.length; i++) {
if (c == xlateTable[i]) {
tableIdx = i;
break;
}
}
if (tableIdx > 12) {
tableIdx += 195;
}
if (carryOverNibble == -1) {
if (tableIdx < 13) {
carryOverNibble = tableIdx;
} else {
inStream.buffer[inStream.currentOffset++] = (byte) tableIdx;
}
} else if (tableIdx < 13) {
inStream.buffer[inStream.currentOffset++] = (byte) ((carryOverNibble << 4) + tableIdx);
carryOverNibble = -1;
} else {
inStream.buffer[inStream.currentOffset++] = (byte) ((carryOverNibble << 4) + (tableIdx >> 4));
carryOverNibble = tableIdx & 0xf;
}
}
if (carryOverNibble != -1) {
inStream.buffer[inStream.currentOffset++] = (byte) (carryOverNibble << 4);
}
}
public static char xlateTable[] = { ' ', 'e', 't', 'a', 'o', 'i', 'h', 'n',
's', 'r', 'd', 'l', 'u', 'm', 'w', 'c', 'y', 'f', 'g', 'p', 'b',
'v', 'k', 'x', 'j', 'q', 'z', '0', '1', '2', '3', '4', '5', '6',
'7', '8', '9', ' ', '!', '?', '.', ',', ':', ';', '(', ')', '-',
'&', '*', '\\', '\'', '@', '#', '+', '=', '\243', '$', '%', '"',
'[', ']' };
public static int[] delta(int x1, int y1, int x2, int y2) {
return new int[] {x2 - x1, y2 - y1};
}
public static int directionFromDelta(int x, int y) {
for (int a = 0; a < directionDeltaX.length; a++) {
if (directionDeltaX[a] == x && directionDeltaY[a] == y) {
return xlateDirectionToClient[a];
}
}
throw new IllegalArgumentException(String.format("Cannot find direction %d %d", x, y));
}
public static int direction(int srcX, int srcY, int x, int y) {
double dx = (double) x - srcX, dy = (double) y - srcY;
double angle = Math.atan(dy / dx);
angle = Math.toDegrees(angle);
if (Double.isNaN(angle)) {
return -1;
}
if (Math.signum(dx) < 0) {
angle += 180.0;
}
return (int) (((90 - angle) / 22.5 + 16) % 16);
/*
* int changeX = x - srcX; int changeY = y - srcY; for (int j = 0; j <
* directionDeltaX.length; j++) { if (changeX == directionDeltaX[j] &&
* changeY == directionDeltaY[j]) return j; } return -1;
*/
}
public static byte directionDeltaX[] = new byte[] { 0, 1, 1, 1, 0, -1, -1, -1 };
public static byte directionDeltaY[] = new byte[] { 1, 1, 0, -1, -1, -1, 0, 1 };
public static byte xlateDirectionToClient[] = new byte[] { 1, 2, 4, 7, 6,
5, 3, 0 };
public static String capitalize(String s) {
for (int i = 0; i < s.length(); i++) {
if (i == 0) {
s = String.format("%s%s", Character.toUpperCase(s.charAt(0)),
s.substring(1));
}
if (!Character.isLetterOrDigit(s.charAt(i))) {
if (i + 1 < s.length()) {
s = String.format("%s%s%s", s.subSequence(0, i + 1), Character.toUpperCase(s.charAt(i + 1)), s.substring(i + 2));
}
}
}
return s;
}
}
@@ -0,0 +1,419 @@
package com.rebotted.util;
import com.rebotted.GameConstants;
public class Stream {
public Stream() {
}
public Stream(byte abyte0[]) {
buffer = abyte0;
currentOffset = 0;
}
public long readQWord2() {
final long l = readDWord() & 0xffffffffL;
final long l1 = readDWord() & 0xffffffffL;
return (l << 32) + l1;
}
public byte readSignedByteA() {
return (byte) (buffer[currentOffset++] - 128);
}
public byte readSignedByteC() {
return (byte) -buffer[currentOffset++];
}
public byte readSignedByteS() {
return (byte) (128 - buffer[currentOffset++]);
}
public int readUnsignedByteA() {
return buffer[currentOffset++] - 128 & 0xff;
}
public int readUnsignedByteC() {
return -buffer[currentOffset++] & 0xff;
}
public int readUnsignedByteS() {
return 128 - buffer[currentOffset++] & 0xff;
}
public void writeByteA(int i) {
ensureCapacity(1);
buffer[currentOffset++] = (byte) (i + 128);
}
public void writeByteS(int i) {
ensureCapacity(1);
buffer[currentOffset++] = (byte) (128 - i);
}
public void writeByteC(int i) {
ensureCapacity(1);
buffer[currentOffset++] = (byte) -i;
}
public int readSignedWordBigEndian() {
currentOffset += 2;
int i = ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] & 0xff);
if (i > 32767) {
i -= 0x10000;
}
return i;
}
public int readSignedWordA() {
currentOffset += 2;
int i = ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] - 128 & 0xff);
if (i > 32767) {
i -= 0x10000;
}
return i;
}
public int readSignedWordBigEndianA() {
currentOffset += 2;
int i = ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] - 128 & 0xff);
if (i > 32767) {
i -= 0x10000;
}
return i;
}
public int readUnsignedWordBigEndian() {
currentOffset += 2;
return ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] & 0xff);
}
public int readUnsignedWordA() {
currentOffset += 2;
return ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] - 128 & 0xff);
}
public int readUnsignedWordBigEndianA() {
currentOffset += 2;
return ((buffer[currentOffset - 1] & 0xff) << 8) + (buffer[currentOffset - 2] - 128 & 0xff);
}
public void writeWordBigEndianA(int i) {
ensureCapacity(2);
buffer[currentOffset++] = (byte) (i + 128);
buffer[currentOffset++] = (byte) (i >> 8);
}
public void writeWordA(int i) {
ensureCapacity(2);
buffer[currentOffset++] = (byte) (i >> 8);
buffer[currentOffset++] = (byte) (i + 128);
}
public void writeWordBigEndian_dup(int i) {
ensureCapacity(2);
buffer[currentOffset++] = (byte) i;
buffer[currentOffset++] = (byte) (i >> 8);
}
public int readDWord_v1() {
currentOffset += 4;
return ((buffer[currentOffset - 2] & 0xff) << 24)
+ ((buffer[currentOffset - 1] & 0xff) << 16)
+ ((buffer[currentOffset - 4] & 0xff) << 8)
+ (buffer[currentOffset - 3] & 0xff);
}
public int readDWord_v2() {
currentOffset += 4;
return ((buffer[currentOffset - 3] & 0xff) << 24)
+ ((buffer[currentOffset - 4] & 0xff) << 16)
+ ((buffer[currentOffset - 1] & 0xff) << 8)
+ (buffer[currentOffset - 2] & 0xff);
}
public void writeDWord_v1(int i) {
ensureCapacity(4);
buffer[currentOffset++] = (byte) (i >> 8);
buffer[currentOffset++] = (byte) i;
buffer[currentOffset++] = (byte) (i >> 24);
buffer[currentOffset++] = (byte) (i >> 16);
}
public void writeDWord_v2(int i) {
ensureCapacity(4);
buffer[currentOffset++] = (byte) (i >> 16);
buffer[currentOffset++] = (byte) (i >> 24);
buffer[currentOffset++] = (byte) i;
buffer[currentOffset++] = (byte) (i >> 8);
}
public void readBytes_reverse(byte abyte0[], int i, int j) {
for (int k = j + i - 1; k >= j; k--) {
abyte0[k] = buffer[currentOffset++];
}
}
public void writeBytes_reverse(byte abyte0[], int i, int j) {
ensureCapacity(i);
for (int k = j + i - 1; k >= j; k--) {
buffer[currentOffset++] = abyte0[k];
}
}
public void readBytes_reverseA(byte abyte0[], int i, int j) {
ensureCapacity(i);
for (int k = j + i - 1; k >= j; k--) {
abyte0[k] = (byte) (buffer[currentOffset++] - 128);
}
}
public void writeBytes_reverseA(byte abyte0[], int i, int j) {
ensureCapacity(i);
for (int k = j + i - 1; k >= j; k--) {
buffer[currentOffset++] = (byte) (abyte0[k] + 128);
}
}
public void createFrame(int id) {
ensureCapacity(1);
buffer[currentOffset++] = (byte) (id + packetEncryption.getNextKey());
}
private static final int frameStackSize = 10;
private int frameStackPtr = -1;
private final int frameStack[] = new int[frameStackSize];
public void createFrameVarSize(int id) {
ensureCapacity(3);
buffer[currentOffset++] = (byte) (id + packetEncryption.getNextKey());
buffer[currentOffset++] = 0;
if (frameStackPtr >= frameStackSize - 1) {
throw new RuntimeException("Stack overflow");
} else {
frameStack[++frameStackPtr] = currentOffset;
}
}
public void createFrameVarSizeWord(int id) {
ensureCapacity(2);
buffer[currentOffset++] = (byte) (id + packetEncryption.getNextKey());
writeWord(0);
if (frameStackPtr >= frameStackSize - 1) {
throw new RuntimeException("Stack overflow");
} else {
frameStack[++frameStackPtr] = currentOffset;
}
}
public void endFrameVarSize() {
if (frameStackPtr < 0) {
throw new RuntimeException("Stack empty");
} else {
writeFrameSize(currentOffset - frameStack[frameStackPtr--]);
}
}
public void endFrameVarSizeWord() {
if (frameStackPtr < 0) {
throw new RuntimeException("Stack empty");
} else {
writeFrameSizeWord(currentOffset - frameStack[frameStackPtr--]);
}
}
public void writeByte(int i) {
ensureCapacity(1);
buffer[currentOffset++] = (byte) i;
}
public void writeWord(int i) {
ensureCapacity(2);
buffer[currentOffset++] = (byte) (i >> 8);
buffer[currentOffset++] = (byte) i;
}
public void writeWordBigEndian(int i) {
ensureCapacity(2);
buffer[currentOffset++] = (byte) i;
buffer[currentOffset++] = (byte) (i >> 8);
}
public void write3Byte(int i) {
ensureCapacity(3);
buffer[currentOffset++] = (byte) (i >> 16);
buffer[currentOffset++] = (byte) (i >> 8);
buffer[currentOffset++] = (byte) i;
}
public void writeDWord(int i) {
ensureCapacity(4);
buffer[currentOffset++] = (byte) (i >> 24);
buffer[currentOffset++] = (byte) (i >> 16);
buffer[currentOffset++] = (byte) (i >> 8);
buffer[currentOffset++] = (byte) i;
}
public void writeDWordBigEndian(int i) {
ensureCapacity(4);
buffer[currentOffset++] = (byte) i;
buffer[currentOffset++] = (byte) (i >> 8);
buffer[currentOffset++] = (byte) (i >> 16);
buffer[currentOffset++] = (byte) (i >> 24);
}
public void writeQWord(long l) {
ensureCapacity(8);
buffer[currentOffset++] = (byte) (int) (l >> 56);
buffer[currentOffset++] = (byte) (int) (l >> 48);
buffer[currentOffset++] = (byte) (int) (l >> 40);
buffer[currentOffset++] = (byte) (int) (l >> 32);
buffer[currentOffset++] = (byte) (int) (l >> 24);
buffer[currentOffset++] = (byte) (int) (l >> 16);
buffer[currentOffset++] = (byte) (int) (l >> 8);
buffer[currentOffset++] = (byte) (int) l;
}
public void writeString(java.lang.String s) {
ensureCapacity(s.length());
System.arraycopy(s.getBytes(), 0, buffer, currentOffset, s.length());
currentOffset += s.length();
buffer[currentOffset++] = 10;
}
public void writeBytes(byte abyte0[], int i, int j) {
ensureCapacity(i);
for (int k = j; k < j + i; k++) {
buffer[currentOffset++] = abyte0[k];
}
}
public void writeFrameSize(int i) {
buffer[currentOffset - i - 1] = (byte) i;
}
public void writeFrameSizeWord(int i) {
buffer[currentOffset - i - 2] = (byte) (i >> 8);
buffer[currentOffset - i - 1] = (byte) i;
}
public int readUnsignedByte() {
return buffer[currentOffset++] & 0xff;
}
public byte readSignedByte() {
return buffer[currentOffset++];
}
public int readUnsignedWord() {
currentOffset += 2;
return ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] & 0xff);
}
public int readSignedWord() {
currentOffset += 2;
int i = ((buffer[currentOffset - 2] & 0xff) << 8) + (buffer[currentOffset - 1] & 0xff);
if (i > 32767) {
i -= 0x10000;
}
return i;
}
public int readDWord() {
currentOffset += 4;
return ((buffer[currentOffset - 4] & 0xff) << 24)
+ ((buffer[currentOffset - 3] & 0xff) << 16)
+ ((buffer[currentOffset - 2] & 0xff) << 8)
+ (buffer[currentOffset - 1] & 0xff);
}
public long readQWord() {
long l = readDWord() & 0xffffffffL;
long l1 = readDWord() & 0xffffffffL;
return (l << 32) + l1;
}
public java.lang.String readString() {
int i = currentOffset;
while (buffer[currentOffset++] != 10) {
;
}
return new String(buffer, i, currentOffset - i - 1);
}
public void readBytes(byte abyte0[], int i, int j) {
for (int k = j; k < j + i; k++) {
abyte0[k] = buffer[currentOffset++];
}
}
public void initBitAccess() {
bitPosition = currentOffset * 8;
}
public void writeBits(int numBits, int value) {
ensureCapacity((int) Math.ceil(numBits * 8) * 4);
int bytePos = bitPosition >> 3;
int bitOffset = 8 - (bitPosition & 7);
bitPosition += numBits;
for (; numBits > bitOffset; bitOffset = 8) {
buffer[bytePos] &= ~bitMaskOut[bitOffset];
buffer[bytePos++] |= value >> numBits - bitOffset
& bitMaskOut[bitOffset];
numBits -= bitOffset;
}
if (numBits == bitOffset) {
buffer[bytePos] &= ~bitMaskOut[bitOffset];
buffer[bytePos] |= value & bitMaskOut[bitOffset];
} else {
buffer[bytePos] &= ~(bitMaskOut[numBits] << bitOffset - numBits);
buffer[bytePos] |= (value & bitMaskOut[numBits]) << bitOffset
- numBits;
}
}
public void finishBitAccess() {
currentOffset = (bitPosition + 7) / 8;
}
public byte buffer[] = null;
public int currentOffset = 0;
public int bitPosition = 0;
public static int bitMaskOut[] = new int[32];
static {
for (int i = 0; i < 32; i++) {
bitMaskOut[i] = (1 << i) - 1;
}
}
public void ensureCapacity(int len) {
if (currentOffset + len + 1 >= buffer.length) {
byte[] oldBuffer = buffer;
int newLength = buffer.length * 2;
buffer = new byte[newLength];
System.arraycopy(oldBuffer, 0, buffer, 0, oldBuffer.length);
ensureCapacity(len);
}
}
public void reset() {
if (!(currentOffset > GameConstants.BUFFER_SIZE)) {
byte[] oldBuffer = buffer;
buffer = new byte[GameConstants.BUFFER_SIZE];
for (int i = 0; i < currentOffset; i++) {
buffer[i] = oldBuffer[i];
}
}
}
public ISAACRandomGen packetEncryption = null;
}
@@ -0,0 +1,37 @@
package com.rebotted.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import com.rebotted.game.npcs.NPCDefinition;
import com.thoughtworks.xstream.XStream;
public class XStreamUtil {
private static XStreamUtil instance = new XStreamUtil();
private static XStream xStream = new XStream();
public static XStreamUtil getInstance() {
return instance;
}
static {
xStream.alias("npcDefinition", NPCDefinition.class);
}
public static XStream getXStream() {
return xStream;
}
public static void writeXML(Object object, File file) throws IOException {
FileOutputStream out = new FileOutputStream(file);
try {
xStream.toXML(object, out);
out.flush();
} finally {
out.close();
}
}
}