uhhh go brrr?

This commit is contained in:
Ceikry
2021-03-11 20:42:32 -06:00
parent 89d51b788b
commit 76c7b16108
2757 changed files with 0 additions and 0 deletions
+238
View File
@@ -0,0 +1,238 @@
package core.cache;
import java.io.File;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import core.ServerConstants;
import core.cache.def.impl.AnimationDefinition;
import core.cache.def.impl.GraphicDefinition;
import core.cache.def.impl.ItemDefinition;
import core.cache.def.impl.NPCDefinition;
import core.cache.def.impl.ObjectDefinition;
import core.game.system.SystemLogger;
/**
* A cache reader.
*
* @author Emperor
* @author Dragonkk
*/
public final class Cache {
/**
* The cache file manager.
*/
private static CacheFileManager[] cacheFileManagers;
/**
* The container cache file informer.
*/
private static CacheFile referenceFile;
/**
* Construct a new instance.
*/
private Cache(String location) {
try {
init(location);
} catch (Throwable e) {
e.printStackTrace();
}
}
/**
* Initialize the cache reader.
*
* @param path The cache path.x
* @throws Throwable When an exception occurs.
*/
public static void init(String path) throws Throwable {
SystemLogger.logInfo("Initializing cache...");
byte[] cacheFileBuffer = new byte[520];
RandomAccessFile containersInformFile = new RandomAccessFile(path + File.separator + "main_file_cache.idx255", "r");
RandomAccessFile dataFile = new RandomAccessFile(path + File.separator + "main_file_cache.dat2", "r");
referenceFile = new CacheFile(255, containersInformFile, dataFile, 500000, cacheFileBuffer);
int length = (int) (containersInformFile.length() / 6);
cacheFileManagers = new CacheFileManager[length];
for (int i = 0; i < length; i++) {
File f = new File(path + File.separator + "main_file_cache.idx" + i);
if (f.exists() && f.length() > 0) {
CacheFile cacheFile = new CacheFile(i, new RandomAccessFile(f, "r"), dataFile, 1000000, cacheFileBuffer);
cacheFileManagers[i] = new CacheFileManager(cacheFile, true);
if (cacheFileManagers[i].getInformation() == null) {
SystemLogger.logErr("Error loading cache index " + i + ": no information.");
cacheFileManagers[i] = null;
}
}
}
ItemDefinition.parse();
ObjectDefinition.parse();
}
/**
* Initializes the cache.
*/
public static void init() {
try {
init(ServerConstants.CACHE_PATH);
} catch (Throwable e) {
e.printStackTrace();
}
}
/**
* Gets the archive buffer for the grab requests.
*
* @param index The index id.
* @param archive The archive id.
* @param priority The priority.
* @param encryptionValue The current encryption value.
* @return The byte buffer.
*/
public static ByteBuffer getArchiveData(int index, int archive, boolean priority, int encryptionValue) {
byte[] data = index == 255 ? referenceFile.getContainerData(archive) : cacheFileManagers[index].getCacheFile().getContainerData(archive);
if (data == null || data.length < 1) {
SystemLogger.logErr("Invalid JS-5 request - " + index + ", " + archive + ", " + priority + ", " + encryptionValue + "!");
return null;
}
int compression = data[0] & 0xff;
int length = ((data[1] & 0xff) << 24) + ((data[2] & 0xff) << 16) + ((data[3] & 0xff) << 8) + (data[4] & 0xff);
int settings = compression;
if (!priority) {
settings |= 0x80;
}
int realLength = compression != 0 ? length + 4 : length;
// TODO There are two archives that lack two bytes at the end (The version, most likely). This causes the client CRC to be miscalculated. To combat this, we simply send two more bytes if the length seems to be off.
realLength += (index != 255 && compression != 0 && data.length - length == 9) ? 2 : 0;
ByteBuffer buffer = ByteBuffer.allocate((realLength + 5) + (realLength / 512) + 10);
buffer.put((byte) index);
buffer.putShort((short) archive);
buffer.put((byte) settings);
buffer.putInt(length);
for (int i = 5; i < realLength + 5; i++) {
if (buffer.position() % 512 == 0) {
buffer.put((byte) 255);
}
if (data.length > i)
buffer.put(data[i]);
else
buffer.put((byte) 0);
}
if (encryptionValue != 0) {
for (int i = 0; i < buffer.position(); i++) {
buffer.put(i, (byte) (buffer.get(i) ^ encryptionValue));
}
}
buffer.flip();
return buffer;
}
/**
* Generate the reference data for the cache files.
*
* @return The reference data byte array.
*/
public static final byte[] generateReferenceData() {
ByteBuffer buffer = ByteBuffer.allocate(cacheFileManagers.length * 8);
for (int index = 0; index < cacheFileManagers.length; index++) {
if (cacheFileManagers[index] == null) {
buffer.putInt(index == 24 ? 609698396 : 0);
buffer.putInt(0);
continue;
}
buffer.putInt(cacheFileManagers[index].getInformation().getInformationContainer().getCrc());
buffer.putInt(cacheFileManagers[index].getInformation().getRevision());
}
return buffer.array();
}
/**
* Get the cache file managers.
*
* @return The cache file managers.
*/
public static final CacheFileManager[] getIndexes() {
return cacheFileManagers;
}
/**
* Get the container cache file informer.
*
* @return The container cache file informer.
*/
public static final CacheFile getReferenceFile() {
return referenceFile;
}
/**
* Method used to return the component size of the interface.
*
* @param interfaceId the interface.
* @return the value.
*/
public static final int getInterfaceDefinitionsComponentsSize(int interfaceId) {
return getIndexes()[3].getFilesSize(interfaceId);
}
/**
* Method used to return the max size of the interface definitions.
*
* @return the size.
*/
public static final int getInterfaceDefinitionsSize() {
return getIndexes()[3].getContainersSize();
}
/**
* Method used to return the {@link NPCDefinition} size.
*
* @return the size.
*/
public static final int getNPCDefinitionsSize() {
int lastContainerId = getIndexes()[18].getContainersSize() - 1;
return lastContainerId * 128 + getIndexes()[18].getFilesSize(lastContainerId);
}
/**
* Method used to return the {@link GraphicDefinition} size.
*
* @return the size.
*/
public static final int getGraphicDefinitionsSize() {
int lastContainerId = getIndexes()[21].getContainersSize() - 1;
return lastContainerId * 256 + getIndexes()[21].getFilesSize(lastContainerId);
}
/**
* Method used to return the {@link AnimationDefinition} size.
*
* @return the size.
*/
public static final int getAnimationDefinitionsSize() {
int lastContainerId = getIndexes()[20].getContainersSize() - 1;
return lastContainerId * 128 + getIndexes()[20].getFilesSize(lastContainerId);
}
/**
* Method used to return the {@link ObjectDefinition} size.
*
* @return the size.
*/
public static final int getObjectDefinitionsSize() {
int lastContainerId = getIndexes()[16].getContainersSize() - 1;
return lastContainerId * 256 + getIndexes()[16].getFilesSize(lastContainerId);
}
/**
* Method used to return the item definition size.
*
* @return the size.
*/
public static final int getItemDefinitionsSize() {
int lastContainerId = getIndexes()[19].getContainersSize() - 1;
return lastContainerId * 256 + getIndexes()[19].getFilesSize(lastContainerId);
}
}
+148
View File
@@ -0,0 +1,148 @@
package core.cache;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import core.cache.crypto.XTEACryption;
import core.cache.misc.ContainersInformation;
/**
* A cache file.
* @author Dragonkk
*/
public final class CacheFile {
/**
* The index file id.
*/
private int indexFileId;
/**
* The cache file buffer.
*/
private byte[] cacheFileBuffer;
/**
* The maximum container size.
*/
private int maxContainerSize;
/**
* The index file.
*/
private RandomAccessFile indexFile;
/**
* The data file.
*/
private RandomAccessFile dataFile;
/**
* Construct a new cache file.
* @param indexFileId The index file id.
* @param indexFile The index file.
* @param dataFile The data file.
* @param maxContainerSize The maximum container size.
* @param cacheFileBuffer The cache file buffer.
*/
public CacheFile(int indexFileId, RandomAccessFile indexFile, RandomAccessFile dataFile, int maxContainerSize, byte[] cacheFileBuffer) {
this.cacheFileBuffer = cacheFileBuffer;
this.indexFileId = indexFileId;
this.maxContainerSize = maxContainerSize;
this.indexFile = indexFile;
this.dataFile = dataFile;
}
/**
* Get the unpacked container data.
* @param containerId The container id.
* @param xteaKeys The container keys.
* @return The unpacked container data.
*/
public final byte[] getContainerUnpackedData(int containerId, int[] xteaKeys) {
byte[] packedData = getContainerData(containerId);
if (packedData == null) {
return null;
}
if (xteaKeys != null && (xteaKeys[0] != 0 || xteaKeys[1] != 0 || xteaKeys[2] != 0 || xteaKeys[3] != 0)) {
packedData = XTEACryption.decrypt(xteaKeys, ByteBuffer.wrap(packedData), 5, packedData.length).array();
}
return ContainersInformation.unpackCacheContainer(packedData);
}
/**
* Get the container data for the specified container id.
* @param containerId The container id.
* @return The container data.
*/
public final byte[] getContainerData(int containerId) {
synchronized (dataFile) {
try {
if (indexFile.length() < (6 * containerId + 6)) {
return null;
}
indexFile.seek(6 * containerId);
indexFile.read(cacheFileBuffer, 0, 6);
int containerSize = (cacheFileBuffer[2] & 0xff) + (((0xff & cacheFileBuffer[0]) << 16) + (cacheFileBuffer[1] << 8 & 0xff00));
int sector = ((cacheFileBuffer[3] & 0xff) << 16) - (-(0xff00 & cacheFileBuffer[4] << 8) - (cacheFileBuffer[5] & 0xff));
if (containerSize < 0 || containerSize > maxContainerSize) {
return null;
}
if (sector <= 0 || dataFile.length() / 520L < sector) {
return null;
}
byte data[] = new byte[containerSize];
int dataReadCount = 0;
int part = 0;
while (containerSize > dataReadCount) {
if (sector == 0) {
return null;
}
dataFile.seek(520 * sector);
int dataToReadCount = containerSize - dataReadCount;
if (dataToReadCount > 512) {
dataToReadCount = 512;
}
dataFile.read(cacheFileBuffer, 0, 8 + dataToReadCount);
int currentContainerId = (0xff & cacheFileBuffer[1]) + (0xff00 & cacheFileBuffer[0] << 8);
int currentPart = ((cacheFileBuffer[2] & 0xff) << 8) + (0xff & cacheFileBuffer[3]);
int nextSector = (cacheFileBuffer[6] & 0xff) + (0xff00 & cacheFileBuffer[5] << 8) + ((0xff & cacheFileBuffer[4]) << 16);
int currentIndexFileId = cacheFileBuffer[7] & 0xff;
if (containerId != currentContainerId || currentPart != part || indexFileId != currentIndexFileId) {
return null;
}
if (nextSector < 0 || (dataFile.length() / 520L) < nextSector) {
return null;
}
for (int index = 0; dataToReadCount > index; index++) {
data[dataReadCount++] = cacheFileBuffer[8 + index];
}
part++;
sector = nextSector;
}
return data;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
/**
* Get the index file id.
* @return
*/
public int getIndexFileId() {
return indexFileId;
}
/**
* Get the unpacked container data.
* @param containerId The container id.
* @return The unpacked container data.
*/
public final byte[] getContainerUnpackedData(int containerId) {
return getContainerUnpackedData(containerId, null);
}
}
+293
View File
@@ -0,0 +1,293 @@
package core.cache;
import java.nio.ByteBuffer;
import core.cache.misc.ContainersInformation;
import core.tools.StringUtils;
/**
* A cache file manager.
* @author Dragonkk
*/
public final class CacheFileManager {
/**
* The cache file.
*/
private CacheFile cacheFile;
/**
* The containers information.
*/
private ContainersInformation information;
/**
* Discard a files data.
*/
private boolean discardFilesData;
/**
* A array holding file data.
*/
private byte[][][] filesData;
/**
* Construct a new cache file manager.
* @param cacheFile The cache file.
* @param discardFilesData To discard a files data.
*/
public CacheFileManager(CacheFile cacheFile, boolean discardFilesData) {
this.cacheFile = cacheFile;
this.discardFilesData = discardFilesData;
byte[] informContainerPackedData = Cache.getReferenceFile().getContainerData(cacheFile.getIndexFileId());
if (informContainerPackedData == null) {
return;
}
information = new ContainersInformation(informContainerPackedData);
resetFilesData();
}
/**
* Get the cache file.
* @return The cache file.
*/
public CacheFile getCacheFile() {
return cacheFile;
}
/**
* Get the containers size.
* @return The containers size.
*/
public int getContainersSize() {
return information.getContainers().length;
}
/**
* Get the files size.
* @param containerId The container id.
* @return The files size.
*/
public int getFilesSize(int containerId) {
if (!validContainer(containerId)) {
return -1;
}
return information.getContainers()[containerId].getFiles().length;
}
/**
* Reset the file data.
*/
public void resetFilesData() {
filesData = new byte[information.getContainers().length][][];
}
/**
* Check if a file is valid.
* @param containerId The container id.
* @param fileId The file id.
* @return If the file is valid {@code true}.
*/
public boolean validFile(int containerId, int fileId) {
if (!validContainer(containerId)) {
return false;
}
if (fileId < 0 || information.getContainers()[containerId] == null || information.getContainers()[containerId].getFiles().length <= fileId) {
return false;
}
return true;
}
/**
* If a container is valid.
* @param containerId The container id.
* @return If the container is valid {@code true}.
*/
public boolean validContainer(int containerId) {
if (containerId < 0 || information.getContainers().length <= containerId) {
return false;
}
return true;
}
/**
* Get the file ids.
* @param containerId The container id.
* @return The file ids.
*/
public int[] getFileIds(int containerId) {
if (!validContainer(containerId)) {
return null;
}
return information.getContainers()[containerId].getFilesIndexes();
}
/**
* Get the archive id.
* @param name The archive name.
* @return The archive id.
*/
public int getArchiveId(String name) {
if (name == null) {
return -1;
}
int hash = StringUtils.getNameHash(name);
for (int containerIndex = 0; containerIndex < information.getContainersIndexes().length; containerIndex++) {
if (information.getContainers()[information.getContainersIndexes()[containerIndex]].getNameHash() == hash) {
return information.getContainersIndexes()[containerIndex];
}
}
return -1;
}
/**
* Get the file data.
* @param containerId The container id.
* @param fileId The file id.
* @return The get file data.
*/
public byte[] getFileData(int containerId, int fileId) {
return getFileData(containerId, fileId, null);
}
/**
* Load the file data.
* @param archiveId The container id.
* @param keys The container keys.
* @return If the file data is loaded {@code true}.
*/
public boolean loadFilesData(int archiveId, int[] keys) {
byte[] data = cacheFile.getContainerUnpackedData(archiveId, keys);
if (data == null) {
return false;
}
if (filesData[archiveId] == null) {
if (information.getContainers()[archiveId] == null) {
return false; // container inform doesnt exist anymore
}
filesData[archiveId] = new byte[information.getContainers()[archiveId].getFiles().length][];
}
if (information.getContainers()[archiveId].getFilesIndexes().length == 1) {
int fileId = information.getContainers()[archiveId].getFilesIndexes()[0];
filesData[archiveId][fileId] = data;
} else {
int readPosition = data.length;
int amtOfLoops = data[--readPosition] & 0xff;
readPosition -= amtOfLoops * (information.getContainers()[archiveId].getFilesIndexes().length * 4);
ByteBuffer buffer = ByteBuffer.wrap(data);
int filesSize[] = new int[information.getContainers()[archiveId].getFilesIndexes().length];
buffer.position(readPosition);
for (int loop = 0; loop < amtOfLoops; loop++) {
int offset = 0;
for (int fileIndex = 0; fileIndex < information.getContainers()[archiveId].getFilesIndexes().length; fileIndex++) {
filesSize[fileIndex] += offset += buffer.getInt();
}
}
byte[][] filesBufferData = new byte[information.getContainers()[archiveId].getFilesIndexes().length][];
for (int fileIndex = 0; fileIndex < information.getContainers()[archiveId].getFilesIndexes().length; fileIndex++) {
filesBufferData[fileIndex] = new byte[filesSize[fileIndex]];
filesSize[fileIndex] = 0;
}
buffer.position(readPosition);
int sourceOffset = 0;
for (int loop = 0; loop < amtOfLoops; loop++) {
int dataRead = 0;
for (int fileIndex = 0; fileIndex < information.getContainers()[archiveId].getFilesIndexes().length; fileIndex++) {
dataRead += buffer.getInt();
System.arraycopy(data, sourceOffset, filesBufferData[fileIndex], filesSize[fileIndex], dataRead);
sourceOffset += dataRead;
filesSize[fileIndex] += dataRead;
}
}
for (int fileIndex = 0; fileIndex < information.getContainers()[archiveId].getFilesIndexes().length; fileIndex++) {
filesData[archiveId][information.getContainers()[archiveId].getFilesIndexes()[fileIndex]] = filesBufferData[fileIndex];
}
}
return true;
}
/**
* Get the file data.
* @param containerId The container id.
* @param fileId The file id.
* @param xteaKeys The container keys.
* @return The file data.
*/
public byte[] getFileData(int containerId, int fileId, int[] xteaKeys) {
if (!validFile(containerId, fileId)) {
return null;
}
if (filesData[containerId] == null || filesData[containerId][fileId] == null) {
if (!loadFilesData(containerId, xteaKeys)) {
return null;
}
}
byte[] data = filesData[containerId][fileId];
if (discardFilesData) {
if (filesData[containerId].length == 1) {
filesData[containerId] = null;
} else {
filesData[containerId][fileId] = null;
}
}
return data;
}
/**
* Get the containers information.
* @return The containers information.
*/
public ContainersInformation getInformation() {
return information;
}
/**
* Gets the discardFilesData.
* @return the discardFilesData.
*/
public boolean isDiscardFilesData() {
return discardFilesData;
}
/**
* Sets the discardFilesData.
* @param discardFilesData the discardFilesData to set
*/
public void setDiscardFilesData(boolean discardFilesData) {
this.discardFilesData = discardFilesData;
}
/**
* Gets the filesData.
* @return the filesData.
*/
public byte[][][] getFilesData() {
return filesData;
}
/**
* Sets the filesData.
* @param filesData the filesData to set
*/
public void setFilesData(byte[][][] filesData) {
this.filesData = filesData;
}
/**
* Sets the cacheFile.
* @param cacheFile the cacheFile to set
*/
public void setCacheFile(CacheFile cacheFile) {
this.cacheFile = cacheFile;
}
/**
* Sets the information.
* @param information the information to set
*/
public void setInformation(ContainersInformation information) {
this.information = information;
}
}
+193
View File
@@ -0,0 +1,193 @@
package core.cache;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.util.HashMap;
import java.util.Map;
import core.cache.misc.buffer.ByteBufferUtils;
/**
* The server data storage.
* @author Emperor
*/
public final class ServerStore {
/**
* The storage.
*/
private static Map<String, StoreFile> storage = new HashMap<>();
/**
* If the store has initialized.
*/
private static boolean initialized;
/**
* Initializes the store.
* @param path The file path.
*/
public static void init(String path) {
storage = new HashMap<>();
File file = new File(path + "/dynamic_cache.keldagrim");
if (file.exists()) {
try (RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
FileChannel channel = raf.getChannel();
ByteBuffer buffer = channel.map(MapMode.READ_WRITE, 0, channel.size());
int size = buffer.getShort() & 0xFFFF;
for (int i = 0; i < size; i++) {
StoreFile store = new StoreFile();
store.setDynamic(true);
String archive = ByteBufferUtils.getString(buffer);
byte[] data = new byte[buffer.getInt()];
buffer.get(data);
store.setData(data);
storage.put(archive, store);
}
if (buffer.hasRemaining()) {
throw new IllegalStateException("Unable to read all dynamic data (size=" + size + ")!");
}
channel.close();
raf.close();
} catch (IOException e) {
e.printStackTrace();
}
}
initialized = true;
}
/**
* Used for writing the static store.
* @param path The path.
*/
public static void createStaticStore(String path) {
write(path + "/static_cache.keldagrim", false);
}
/**
* Writes all the dynamic storage files (on server termination).
* @param path The path.
*/
public static void dump(String path) {
write(path + "/dynamic_cache.keldagrim", true);
}
/**
* Writes the store file to the given file path.
* @param filePath The file path.
* @param dynamic If the dynamic store is being written.
*/
public static void write(String filePath, boolean dynamic) {
if (!initialized) {
throw new IllegalStateException("Server store has not been initialized!");
}
File f = new File(filePath);
if (f.exists()) {
f.delete();
}
ByteBuffer buffer = ByteBuffer.allocate(1 << 28);
buffer.putShort((short) 0);
int size = 0;
for (String archive : storage.keySet()) {
StoreFile file = storage.get(archive);
if (file.isDynamic() != dynamic) {
continue;
}
size++;
ByteBuffer buf = file.data();
ByteBufferUtils.putString(archive, buffer);
buffer.putInt(buf.remaining());
buffer.put(buf);
}
buffer.putShort(0, (short) size);
buffer.flip();
try (RandomAccessFile raf = new RandomAccessFile(f, "rw")) {
FileChannel channel = raf.getChannel();
channel.write(buffer);
channel.close();
raf.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* Sets the archive data.
* @param archive The archive id.
* @param buffer The readable buffer.
*/
public static void setArchive(String archive, ByteBuffer buffer) {
setArchive(archive, buffer, true);
}
/**
* Sets the archive data.
* @param archive The archive id.
* @param buffer The readable buffer.
* @param dynamic If the data changes during server runtime.
*/
public static void setArchive(String archive, ByteBuffer buffer, boolean dynamic) {
byte[] data = new byte[buffer.remaining()];
buffer.get(data);
setArchive(archive, data, dynamic, true);
}
/**
* Sets the archive data.
* @param archive The archive index.
* @param data The archive data.
* @param dynamic If the data changes during server runtime.
*/
public static void setArchive(String archive, byte[] data, boolean dynamic) {
setArchive(archive, data, dynamic, true);
}
/**
* Sets the archive data.
* @param archive The archive index.
* @param data The archive data.
* @param dynamic If the data changes during server runtime.
* @param overwrite If the archive should be overwritten.
*/
public static void setArchive(String archive, byte[] data, boolean dynamic, boolean overwrite) {
StoreFile file = storage.get(archive);
if (file == null) {
storage.put(archive, file = new StoreFile());
} else if (!overwrite) {
throw new IllegalStateException("Already contained archive " + archive + "!");
}
file.setDynamic(dynamic);
file.setData(data);
}
/**
* Gets the archive data for the given archive id.
* @param archive The archive index.
* @return The archive data.
*/
public static ByteBuffer getArchive(String archive) {
return get(archive).data();
}
/**
* Sets the archive file.
* @param archive The archive.
* @param file The file.
*/
public static void set(String archive, StoreFile file) {
storage.put(archive, file);
}
/**
* Gets the store file for the given archive.
* @param archive The archive id.
* @return The store file.
*/
public static StoreFile get(String archive) {
return storage.get(archive);
}
}
+72
View File
@@ -0,0 +1,72 @@
package core.cache;
import java.nio.ByteBuffer;
/**
* Represents a file used in the server store.
* @author Emperor
*/
public final class StoreFile {
/**
* If the data can change during server runtime.
*/
private boolean dynamic;
/**
* The file data.
*/
private byte[] data;
/**
* Constructs a new {@code StoreFile} {@code Object}.
*/
public StoreFile() {
/*
* empty.
*/
}
/**
* Puts the data on the buffer.
* @param buffer The buffer.
*/
public void put(ByteBuffer buffer) {
byte[] data = new byte[buffer.remaining()];
buffer.get(data);
this.data = data;
}
/**
* Creates a byte buffer containing the file data.
* @return The buffer.
*/
public ByteBuffer data() {
return ByteBuffer.wrap(data);
}
/**
* Sets the data.
* @param data The data.
*/
public void setData(byte[] data) {
this.data = data;
}
/**
* Gets the dynamic.
* @return The dynamic.
*/
public boolean isDynamic() {
return dynamic;
}
/**
* Sets the dynamic.
* @param dynamic The dynamic to set.
*/
public void setDynamic(boolean dynamic) {
this.dynamic = dynamic;
}
}
@@ -0,0 +1,56 @@
package core.cache.bzip2;
public class BZip2BlockEntry {
boolean aBooleanArray2205[];
boolean aBooleanArray2213[];
byte aByte2201;
byte aByteArray2204[];
byte aByteArray2211[];
byte aByteArray2212[];
byte aByteArray2214[];
byte aByteArray2219[];
byte aByteArray2224[];
byte aByteArrayArray2229[][];
int anInt2202;
int anInt2203;
int anInt2206;
int anInt2207;
int anInt2208;
int anInt2209;
int anInt2215;
int anInt2216;
int anInt2217;
int anInt2221;
int anInt2222;
int anInt2223;
int anInt2225;
int anInt2227;
int anInt2232;
int anIntArray2200[];
int anIntArray2220[];
int anIntArray2226[];
int anIntArray2228[];
int anIntArrayArray2210[][];
int anIntArrayArray2218[][];
int anIntArrayArray2230[][];
public BZip2BlockEntry() {
anIntArray2200 = new int[6];
anInt2203 = 0;
aByteArray2204 = new byte[4096];
aByteArray2211 = new byte[256];
aByteArray2214 = new byte[18002];
aByteArray2219 = new byte[18002];
anIntArray2220 = new int[257];
anIntArrayArray2218 = new int[6][258];
aBooleanArray2205 = new boolean[16];
aBooleanArray2213 = new boolean[256];
anInt2209 = 0;
anIntArray2226 = new int[16];
anIntArrayArray2210 = new int[6][258];
aByteArrayArray2229 = new byte[6][258];
anIntArrayArray2230 = new int[6][258];
anIntArray2228 = new int[256];
}
}
@@ -0,0 +1,536 @@
package core.cache.bzip2;
public class BZip2Decompressor {
private static int anIntArray257[];
private static BZip2BlockEntry entryInstance = new BZip2BlockEntry();
public static final void decompress(byte decompressedData[], byte packedData[], int containerSize, int blockSize) {
synchronized (entryInstance) {
entryInstance.aByteArray2224 = packedData;
entryInstance.anInt2209 = blockSize;
entryInstance.aByteArray2212 = decompressedData;
entryInstance.anInt2203 = 0;
entryInstance.anInt2206 = decompressedData.length;
entryInstance.anInt2232 = 0;
entryInstance.anInt2207 = 0;
entryInstance.anInt2217 = 0;
entryInstance.anInt2216 = 0;
method1793(entryInstance);
entryInstance.aByteArray2224 = null;
entryInstance.aByteArray2212 = null;
}
}
private static final void method1785(BZip2BlockEntry entry) {
entry.anInt2215 = 0;
for (int i = 0; i < 256; i++) {
if (entry.aBooleanArray2213[i]) {
entry.aByteArray2211[entry.anInt2215] = (byte) i;
entry.anInt2215++;
}
}
}
private static final void method1786(int ai[], int ai1[], int ai2[], byte abyte0[], int i, int j, int k) {
int l = 0;
for (int i1 = i; i1 <= j; i1++) {
for (int l2 = 0; l2 < k; l2++) {
if (abyte0[l2] == i1) {
ai2[l] = l2;
l++;
}
}
}
for (int j1 = 0; j1 < 23; j1++) {
ai1[j1] = 0;
}
for (int k1 = 0; k1 < k; k1++) {
ai1[abyte0[k1] + 1]++;
}
for (int l1 = 1; l1 < 23; l1++) {
ai1[l1] += ai1[l1 - 1];
}
for (int i2 = 0; i2 < 23; i2++) {
ai[i2] = 0;
}
int i3 = 0;
for (int j2 = i; j2 <= j; j2++) {
i3 += ai1[j2 + 1] - ai1[j2];
ai[j2] = i3 - 1;
i3 <<= 1;
}
for (int k2 = i + 1; k2 <= j; k2++) {
ai1[k2] = (ai[k2 - 1] + 1 << 1) - ai1[k2];
}
}
private static final void method1787(BZip2BlockEntry entry) {
byte byte4 = entry.aByte2201;
int i = entry.anInt2222;
int j = entry.anInt2227;
int k = entry.anInt2221;
int ai[] = anIntArray257;
int l = entry.anInt2208;
byte abyte0[] = entry.aByteArray2212;
int i1 = entry.anInt2203;
int j1 = entry.anInt2206;
int k1 = j1;
int l1 = entry.anInt2225 + 1;
label0: do {
if (i > 0) {
do {
if (j1 == 0) {
break label0;
}
if (i == 1) {
break;
}
abyte0[i1] = byte4;
i--;
i1++;
j1--;
} while (true);
if (j1 == 0) {
i = 1;
break;
}
abyte0[i1] = byte4;
i1++;
j1--;
}
boolean flag = true;
while (flag) {
flag = false;
if (j == l1) {
i = 0;
break label0;
}
byte4 = (byte) k;
l = ai[l];
byte byte0 = (byte) (l & 0xff);
l >>= 8;
j++;
if (byte0 != k) {
k = byte0;
if (j1 == 0) {
i = 1;
} else {
abyte0[i1] = byte4;
i1++;
j1--;
flag = true;
continue;
}
break label0;
}
if (j != l1) {
continue;
}
if (j1 == 0) {
i = 1;
break label0;
}
abyte0[i1] = byte4;
i1++;
j1--;
flag = true;
}
i = 2;
l = ai[l];
byte byte1 = (byte) (l & 0xff);
l >>= 8;
if (++j != l1) {
if (byte1 != k) {
k = byte1;
} else {
i = 3;
l = ai[l];
byte byte2 = (byte) (l & 0xff);
l >>= 8;
if (++j != l1) {
if (byte2 != k) {
k = byte2;
} else {
l = ai[l];
byte byte3 = (byte) (l & 0xff);
l >>= 8;
j++;
i = (byte3 & 0xff) + 4;
l = ai[l];
k = (byte) (l & 0xff);
l >>= 8;
j++;
}
}
}
}
} while (true);
entry.anInt2216 += k1 - j1;
entry.aByte2201 = byte4;
entry.anInt2222 = i;
entry.anInt2227 = j;
entry.anInt2221 = k;
anIntArray257 = ai;
entry.anInt2208 = l;
entry.aByteArray2212 = abyte0;
entry.anInt2203 = i1;
entry.anInt2206 = j1;
}
private static final byte method1788(BZip2BlockEntry entry) {
return (byte) method1790(1, entry);
}
private static final byte method1789(BZip2BlockEntry entryInstance2) {
return (byte) method1790(8, entryInstance2);
}
private static final int method1790(int i, BZip2BlockEntry entry) {
int j;
do {
if (entry.anInt2232 >= i) {
int k = entry.anInt2207 >> entry.anInt2232 - i & (1 << i) - 1;
entry.anInt2232 -= i;
j = k;
break;
}
entry.anInt2207 = entry.anInt2207 << 8 | entry.aByteArray2224[entry.anInt2209] & 0xff;
entry.anInt2232 += 8;
entry.anInt2209++;
entry.anInt2217++;
} while (true);
return j;
}
public static void clearBlockEntryInstance() {
entryInstance = null;
}
private static final void method1793(BZip2BlockEntry entryInstance2) {
// unused
/*
* boolean flag = false; boolean flag1 = false; boolean flag2 = false;
* boolean flag3 = false; boolean flag4 = false; boolean flag5 = false;
* boolean flag6 = false; boolean flag7 = false; boolean flag8 = false;
* boolean flag9 = false; boolean flag10 = false; boolean flag11 =
* false; boolean flag12 = false; boolean flag13 = false; boolean flag14
* = false; boolean flag15 = false; boolean flag16 = false; boolean
* flag17 = false;
*/
int j8 = 0;
int ai[] = null;
int ai1[] = null;
int ai2[] = null;
entryInstance2.anInt2202 = 1;
if (anIntArray257 == null) {
anIntArray257 = new int[entryInstance2.anInt2202 * 0x186a0];
}
boolean flag18 = true;
while (flag18) {
byte byte0 = method1789(entryInstance2);
if (byte0 == 23) {
return;
}
byte0 = method1789(entryInstance2);
byte0 = method1789(entryInstance2);
byte0 = method1789(entryInstance2);
byte0 = method1789(entryInstance2);
byte0 = method1789(entryInstance2);
byte0 = method1789(entryInstance2);
byte0 = method1789(entryInstance2);
byte0 = method1789(entryInstance2);
byte0 = method1789(entryInstance2);
byte0 = method1788(entryInstance2);
entryInstance2.anInt2223 = 0;
byte0 = method1789(entryInstance2);
entryInstance2.anInt2223 = entryInstance2.anInt2223 << 8 | byte0 & 0xff;
byte0 = method1789(entryInstance2);
entryInstance2.anInt2223 = entryInstance2.anInt2223 << 8 | byte0 & 0xff;
byte0 = method1789(entryInstance2);
entryInstance2.anInt2223 = entryInstance2.anInt2223 << 8 | byte0 & 0xff;
for (int j = 0; j < 16; j++) {
byte byte1 = method1788(entryInstance2);
if (byte1 == 1) {
entryInstance2.aBooleanArray2205[j] = true;
} else {
entryInstance2.aBooleanArray2205[j] = false;
}
}
for (int k = 0; k < 256; k++) {
entryInstance2.aBooleanArray2213[k] = false;
}
for (int l = 0; l < 16; l++) {
if (entryInstance2.aBooleanArray2205[l]) {
for (int i3 = 0; i3 < 16; i3++) {
byte byte2 = method1788(entryInstance2);
if (byte2 == 1) {
entryInstance2.aBooleanArray2213[l * 16 + i3] = true;
}
}
}
}
method1785(entryInstance2);
int i4 = entryInstance2.anInt2215 + 2;
int j4 = method1790(3, entryInstance2);
int k4 = method1790(15, entryInstance2);
for (int i1 = 0; i1 < k4; i1++) {
int j3 = 0;
do {
byte byte3 = method1788(entryInstance2);
if (byte3 == 0) {
break;
}
j3++;
} while (true);
entryInstance2.aByteArray2214[i1] = (byte) j3;
}
byte abyte0[] = new byte[6];
for (byte byte16 = 0; byte16 < j4; byte16++) {
abyte0[byte16] = byte16;
}
for (int j1 = 0; j1 < k4; j1++) {
byte byte17 = entryInstance2.aByteArray2214[j1];
byte byte15 = abyte0[byte17];
for (; byte17 > 0; byte17--) {
abyte0[byte17] = abyte0[byte17 - 1];
}
abyte0[0] = byte15;
entryInstance2.aByteArray2219[j1] = byte15;
}
for (int k3 = 0; k3 < j4; k3++) {
int k6 = method1790(5, entryInstance2);
for (int k1 = 0; k1 < i4; k1++) {
do {
byte byte4 = method1788(entryInstance2);
if (byte4 == 0) {
break;
}
byte4 = method1788(entryInstance2);
if (byte4 == 0) {
k6++;
} else {
k6--;
}
} while (true);
entryInstance2.aByteArrayArray2229[k3][k1] = (byte) k6;
}
}
for (int l3 = 0; l3 < j4; l3++) {
byte byte8 = 32;
int i = 0;
for (int l1 = 0; l1 < i4; l1++) {
if (entryInstance2.aByteArrayArray2229[l3][l1] > i) {
i = entryInstance2.aByteArrayArray2229[l3][l1];
}
if (entryInstance2.aByteArrayArray2229[l3][l1] < byte8) {
byte8 = entryInstance2.aByteArrayArray2229[l3][l1];
}
}
method1786(entryInstance2.anIntArrayArray2230[l3], entryInstance2.anIntArrayArray2218[l3], entryInstance2.anIntArrayArray2210[l3], entryInstance2.aByteArrayArray2229[l3], byte8, i, i4);
entryInstance2.anIntArray2200[l3] = byte8;
}
int l4 = entryInstance2.anInt2215 + 1;
int i5 = -1;
int j5 = 0;
for (int i2 = 0; i2 <= 255; i2++) {
entryInstance2.anIntArray2228[i2] = 0;
}
int i9 = 4095;
for (int k8 = 15; k8 >= 0; k8--) {
for (int l8 = 15; l8 >= 0; l8--) {
entryInstance2.aByteArray2204[i9] = (byte) (k8 * 16 + l8);
i9--;
}
entryInstance2.anIntArray2226[k8] = i9 + 1;
}
int l5 = 0;
if (j5 == 0) {
i5++;
j5 = 50;
byte byte12 = entryInstance2.aByteArray2219[i5];
j8 = entryInstance2.anIntArray2200[byte12];
ai = entryInstance2.anIntArrayArray2230[byte12];
ai2 = entryInstance2.anIntArrayArray2210[byte12];
ai1 = entryInstance2.anIntArrayArray2218[byte12];
}
j5--;
int l6 = j8;
int k7;
byte byte9;
for (k7 = method1790(l6, entryInstance2); k7 > ai[l6]; k7 = k7 << 1 | byte9) {
l6++;
byte9 = method1788(entryInstance2);
}
for (int k5 = ai2[k7 - ai1[l6]]; k5 != l4;) {
if (k5 == 0 || k5 == 1) {
int i6 = -1;
int j6 = 1;
do {
if (k5 == 0) {
i6 += j6;
} else if (k5 == 1) {
i6 += 2 * j6;
}
j6 *= 2;
if (j5 == 0) {
i5++;
j5 = 50;
byte byte13 = entryInstance2.aByteArray2219[i5];
j8 = entryInstance2.anIntArray2200[byte13];
ai = entryInstance2.anIntArrayArray2230[byte13];
ai2 = entryInstance2.anIntArrayArray2210[byte13];
ai1 = entryInstance2.anIntArrayArray2218[byte13];
}
j5--;
int i7 = j8;
int l7;
byte byte10;
for (l7 = method1790(i7, entryInstance2); l7 > ai[i7]; l7 = l7 << 1 | byte10) {
i7++;
byte10 = method1788(entryInstance2);
}
k5 = ai2[l7 - ai1[i7]];
} while (k5 == 0 || k5 == 1);
i6++;
byte byte5 = entryInstance2.aByteArray2211[entryInstance2.aByteArray2204[entryInstance2.anIntArray2226[0]] & 0xff];
entryInstance2.anIntArray2228[byte5 & 0xff] += i6;
for (; i6 > 0; i6--) {
anIntArray257[l5] = byte5 & 0xff;
l5++;
}
} else {
int i11 = k5 - 1;
byte byte6;
if (i11 < 16) {
int i10 = entryInstance2.anIntArray2226[0];
byte6 = entryInstance2.aByteArray2204[i10 + i11];
for (; i11 > 3; i11 -= 4) {
int j11 = i10 + i11;
entryInstance2.aByteArray2204[j11] = entryInstance2.aByteArray2204[j11 - 1];
entryInstance2.aByteArray2204[j11 - 1] = entryInstance2.aByteArray2204[j11 - 2];
entryInstance2.aByteArray2204[j11 - 2] = entryInstance2.aByteArray2204[j11 - 3];
entryInstance2.aByteArray2204[j11 - 3] = entryInstance2.aByteArray2204[j11 - 4];
}
for (; i11 > 0; i11--) {
entryInstance2.aByteArray2204[i10 + i11] = entryInstance2.aByteArray2204[(i10 + i11) - 1];
}
entryInstance2.aByteArray2204[i10] = byte6;
} else {
int k10 = i11 / 16;
int l10 = i11 % 16;
int j10 = entryInstance2.anIntArray2226[k10] + l10;
byte6 = entryInstance2.aByteArray2204[j10];
for (; j10 > entryInstance2.anIntArray2226[k10]; j10--) {
entryInstance2.aByteArray2204[j10] = entryInstance2.aByteArray2204[j10 - 1];
}
entryInstance2.anIntArray2226[k10]++;
for (; k10 > 0; k10--) {
entryInstance2.anIntArray2226[k10]--;
entryInstance2.aByteArray2204[entryInstance2.anIntArray2226[k10]] = entryInstance2.aByteArray2204[(entryInstance2.anIntArray2226[k10 - 1] + 16) - 1];
}
entryInstance2.anIntArray2226[0]--;
entryInstance2.aByteArray2204[entryInstance2.anIntArray2226[0]] = byte6;
if (entryInstance2.anIntArray2226[0] == 0) {
int l9 = 4095;
for (int j9 = 15; j9 >= 0; j9--) {
for (int k9 = 15; k9 >= 0; k9--) {
entryInstance2.aByteArray2204[l9] = entryInstance2.aByteArray2204[entryInstance2.anIntArray2226[j9] + k9];
l9--;
}
entryInstance2.anIntArray2226[j9] = l9 + 1;
}
}
}
entryInstance2.anIntArray2228[entryInstance2.aByteArray2211[byte6 & 0xff] & 0xff]++;
anIntArray257[l5] = entryInstance2.aByteArray2211[byte6 & 0xff] & 0xff;
l5++;
if (j5 == 0) {
i5++;
j5 = 50;
byte byte14 = entryInstance2.aByteArray2219[i5];
j8 = entryInstance2.anIntArray2200[byte14];
ai = entryInstance2.anIntArrayArray2230[byte14];
ai2 = entryInstance2.anIntArrayArray2210[byte14];
ai1 = entryInstance2.anIntArrayArray2218[byte14];
}
j5--;
int j7 = j8;
int i8;
byte byte11;
for (i8 = method1790(j7, entryInstance2); i8 > ai[j7]; i8 = i8 << 1 | byte11) {
j7++;
byte11 = method1788(entryInstance2);
}
k5 = ai2[i8 - ai1[j7]];
}
}
entryInstance2.anInt2222 = 0;
entryInstance2.aByte2201 = 0;
entryInstance2.anIntArray2220[0] = 0;
for (int j2 = 1; j2 <= 256; j2++) {
entryInstance2.anIntArray2220[j2] = entryInstance2.anIntArray2228[j2 - 1];
}
for (int k2 = 1; k2 <= 256; k2++) {
entryInstance2.anIntArray2220[k2] += entryInstance2.anIntArray2220[k2 - 1];
}
for (int l2 = 0; l2 < l5; l2++) {
byte byte7 = (byte) (anIntArray257[l2] & 0xff);
anIntArray257[entryInstance2.anIntArray2220[byte7 & 0xff]] |= l2 << 8;
entryInstance2.anIntArray2220[byte7 & 0xff]++;
}
entryInstance2.anInt2208 = anIntArray257[entryInstance2.anInt2223] >> 8;
entryInstance2.anInt2227 = 0;
entryInstance2.anInt2208 = anIntArray257[entryInstance2.anInt2208];
entryInstance2.anInt2221 = (byte) (entryInstance2.anInt2208 & 0xff);
entryInstance2.anInt2208 >>= 8;
entryInstance2.anInt2227++;
entryInstance2.anInt2225 = l5;
method1787(entryInstance2);
if (entryInstance2.anInt2227 == entryInstance2.anInt2225 + 1 && entryInstance2.anInt2222 == 0) {
flag18 = true;
} else {
flag18 = false;
}
}
}
}
+271
View File
@@ -0,0 +1,271 @@
package core.cache.crypto;
/**
* <p> An implementation of an ISAAC cipher. See <a
* href="http://en.wikipedia.org/wiki/ISAAC_(cipher)">
* http://en.wikipedia.org/wiki/ISAAC_(cipher)</a> for more information. </p>
* <p> This implementation is based on the one written by Bob Jenkins, which is
* available at <a href="http://www.burtleburtle.net/bob/java/rand/Rand.java">
* http://www.burtleburtle.net/bob/java/rand/Rand.java</a>. </p>
* @author Graham Edgecombe
*/
public class ISAACCipher {
/**
* The golden ratio.
*/
public static final int RATIO = 0x9e3779b9;
/**
* The log of the size of the results and memory arrays.
*/
public static final int SIZE_LOG = 8;
/**
* The size of the results and memory arrays.
*/
public static final int SIZE = 1 << SIZE_LOG;
/**
* For pseudorandom lookup.
*/
public static final int MASK = (SIZE - 1) << 2;
/**
* The count through the results.
*/
private int count = 0;
/**
* The results.
*/
private int results[] = new int[SIZE];
/**
* The internal memory state.
*/
private int memory[] = new int[SIZE];
/**
* The accumulator.
*/
private int a;
/**
* The last result.
*/
private int b;
/**
* The counter.
*/
private int c;
/**
* Creates the ISAAC cipher.
* @param seed The seed.
*/
public ISAACCipher(int[] seed) {
for (int i = 0; i < seed.length; i++) {
results[i] = seed[i];
}
init(true);
}
/**
* Gets the next value.
* @return The next value.
*/
public int getNextValue() {
if (count-- == 0) {
isaac();
count = SIZE - 1;
}
return 0;//results[count];
}
/**
* Generates 256 results.
*/
public void isaac() {
int i, j, x, y;
b += ++c;
for (i = 0, j = SIZE / 2; i < SIZE / 2;) {
x = memory[i];
a ^= a << 13;
a += memory[j++];
memory[i] = y = memory[(x & MASK) >> 2] + a + b;
results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
x = memory[i];
a ^= a >>> 6;
a += memory[j++];
memory[i] = y = memory[(x & MASK) >> 2] + a + b;
results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
x = memory[i];
a ^= a << 2;
a += memory[j++];
memory[i] = y = memory[(x & MASK) >> 2] + a + b;
results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
x = memory[i];
a ^= a >>> 16;
a += memory[j++];
memory[i] = y = memory[(x & MASK) >> 2] + a + b;
results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
}
for (j = 0; j < SIZE / 2;) {
x = memory[i];
a ^= a << 13;
a += memory[j++];
memory[i] = y = memory[(x & MASK) >> 2] + a + b;
results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
x = memory[i];
a ^= a >>> 6;
a += memory[j++];
memory[i] = y = memory[(x & MASK) >> 2] + a + b;
results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
x = memory[i];
a ^= a << 2;
a += memory[j++];
memory[i] = y = memory[(x & MASK) >> 2] + a + b;
results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
x = memory[i];
a ^= a >>> 16;
a += memory[j++];
memory[i] = y = memory[(x & MASK) >> 2] + a + b;
results[i++] = b = memory[((y >> SIZE_LOG) & MASK) >> 2] + x;
}
}
/**
* Initialises the ISAAC.
* @param flag Flag indicating if we should perform a second pass.
*/
public void init(boolean flag) {
int i;
int a, b, c, d, e, f, g, h;
a = b = c = d = e = f = g = h = RATIO;
for (i = 0; i < 4; ++i) {
a ^= b << 11;
d += a;
b += c;
b ^= c >>> 2;
e += b;
c += d;
c ^= d << 8;
f += c;
d += e;
d ^= e >>> 16;
g += d;
e += f;
e ^= f << 10;
h += e;
f += g;
f ^= g >>> 4;
a += f;
g += h;
g ^= h << 8;
b += g;
h += a;
h ^= a >>> 9;
c += h;
a += b;
}
for (i = 0; i < SIZE; i += 8) {
if (flag) {
a += results[i];
b += results[i + 1];
c += results[i + 2];
d += results[i + 3];
e += results[i + 4];
f += results[i + 5];
g += results[i + 6];
h += results[i + 7];
}
a ^= b << 11;
d += a;
b += c;
b ^= c >>> 2;
e += b;
c += d;
c ^= d << 8;
f += c;
d += e;
d ^= e >>> 16;
g += d;
e += f;
e ^= f << 10;
h += e;
f += g;
f ^= g >>> 4;
a += f;
g += h;
g ^= h << 8;
b += g;
h += a;
h ^= a >>> 9;
c += h;
a += b;
memory[i] = a;
memory[i + 1] = b;
memory[i + 2] = c;
memory[i + 3] = d;
memory[i + 4] = e;
memory[i + 5] = f;
memory[i + 6] = g;
memory[i + 7] = h;
}
if (flag) {
for (i = 0; i < SIZE; i += 8) {
a += memory[i];
b += memory[i + 1];
c += memory[i + 2];
d += memory[i + 3];
e += memory[i + 4];
f += memory[i + 5];
g += memory[i + 6];
h += memory[i + 7];
a ^= b << 11;
d += a;
b += c;
b ^= c >>> 2;
e += b;
c += d;
c ^= d << 8;
f += c;
d += e;
d ^= e >>> 16;
g += d;
e += f;
e ^= f << 10;
h += e;
f += g;
f ^= g >>> 4;
a += f;
g += h;
g ^= h << 8;
b += g;
h += a;
h ^= a >>> 9;
c += h;
a += b;
memory[i] = a;
memory[i + 1] = b;
memory[i + 2] = c;
memory[i + 3] = d;
memory[i + 4] = e;
memory[i + 5] = f;
memory[i + 6] = g;
memory[i + 7] = h;
}
}
isaac();
count = SIZE;
}
}
+45
View File
@@ -0,0 +1,45 @@
package core.cache.crypto;
/**
* Represents a ISAAC key pair, for both input and output.
* @author `Discardedx2
*/
public final class ISAACPair {
/**
* The input cipher.
*/
private ISAACCipher input;
/**
* The output cipher.
*/
private ISAACCipher output;
/**
* Constructs a new {@code ISAACPair} {@code Object}.
* @param input The input cipher.
* @param output The output cipher.
*/
public ISAACPair(ISAACCipher input, ISAACCipher output) {
this.input = input;
this.output = output;
}
/**
* Gets the input cipher.
* @return The input cipher.
*/
public ISAACCipher getInput() {
return input;
}
/**
* Gets the output cipher.
* @return The output cipher.
*/
public ISAACCipher getOutput() {
return output;
}
}
+124
View File
@@ -0,0 +1,124 @@
package core.cache.crypto;
import java.nio.ByteBuffer;
/**
* Holds XTEA cryption methods.
* @author ?
* @author Emperor
*/
public final class XTEACryption {
/**
* The delta value
*/
private static final int DELTA = -1640531527;
/**
* The sum.
*/
private static final int SUM = -957401312;
/**
* The amount of "cryption cycles".
*/
private static final int NUM_ROUNDS = 32;
/**
* Constructs a new {@code XTEACryption}.
*/
private XTEACryption() {
/*
* empty.
*/
}
/**
* Decrypts the contents of the buffer.
* @param keys The cryption keys.
* @param buffer The buffer.
*/
public static ByteBuffer decrypt(int[] keys, ByteBuffer buffer) {
return decrypt(keys, buffer, buffer.position(), buffer.limit());
}
/**
* Decrypts the buffer data.
* @param keys The keys.
* @param buffer The buffer to decrypt.
* @param offset The offset of the data to decrypt.
* @param length The length.
* @return The decrypted data.
*/
public static ByteBuffer decrypt(int[] keys, ByteBuffer buffer, int offset, int length) {
int numBlocks = (length - offset) / 8;
int[] block = new int[2];
for (int i = 0; i < numBlocks; i++) {
int index = i * 8 + offset;
block[0] = buffer.getInt(index);
block[1] = buffer.getInt(index + 4);
decipher(keys, block);
buffer.putInt(index, block[0]);
buffer.putInt(index + 4, block[1]);
}
return buffer;
}
/**
* Deciphers the values.
* @param keys The cryption key.
* @param block The values to decipher.
*/
private static void decipher(int[] keys, int[] block) {
long sum = SUM;
for (int i = 0; i < NUM_ROUNDS; i++) {
block[1] -= (keys[(int) ((sum & 0x1933) >>> 11)] + sum ^ block[0] + (block[0] << 4 ^ block[0] >>> 5));
sum -= DELTA;
block[0] -= ((block[1] << 4 ^ block[1] >>> 5) + block[1] ^ keys[(int) (sum & 0x3)] + sum);
}
}
/**
* Encrypts the contents of the byte buffer.
* @param keys The cryption keys.
* @param buffer The buffer to encrypt.
*/
public static void encrypt(int[] keys, ByteBuffer buffer) {
encrypt(keys, buffer, buffer.position(), buffer.limit());
}
/**
* Encrypts the buffer data.
* @param keys The keys.
* @param buffer The buffer to encrypt.
* @param offset The offset of the data to encrypt.
* @param length The length.
* @return The encrypted data.
*/
public static void encrypt(int[] keys, ByteBuffer buffer, int offset, int length) {
int numBlocks = (length - offset) / 8;
int[] block = new int[2];
for (int i = 0; i < numBlocks; i++) {
int index = i * 8 + offset;
block[0] = buffer.getInt(index);
block[1] = buffer.getInt(index + 4);
encipher(keys, block);
buffer.putInt(index, block[0]);
buffer.putInt(index + 4, block[1]);
}
}
/**
* Enciphers the values of the block.
* @param keys The cryption keys.
* @param block The block to encipher.
*/
private static void encipher(int[] keys, int[] block) {
long sum = 0;
for (int i = 0; i < NUM_ROUNDS; i++) {
block[0] += ((block[1] << 4 ^ block[1] >>> 5) + block[1] ^ keys[(int) (sum & 0x3)] + sum);
sum += DELTA;
block[1] += (keys[(int) ((sum & 0x1933) >>> 11)] + sum ^ block[0] + (block[0] << 4 ^ block[0] >>> 5));
}
}
}
+187
View File
@@ -0,0 +1,187 @@
package core.cache.def;
import java.util.HashMap;
import java.util.Map;
import core.tools.StringUtils;
import core.game.node.Node;
/**
* Represent's a node's definitions.
* @author Emperor
* @param <T> The node type.
*/
public class Definition<T extends Node> {
/**
* The node id.
*/
protected int id;
/**
* The name.
*/
protected String name = "null";
/**
* The examine info.
*/
protected String examine;
/**
* The options.
*/
protected String[] options;
/**
* The configurations.
*/
protected final Map<String, Object> handlers = new HashMap<String, Object>();
/**
* Constructs a new {@code Definition} {@code Object}.
*/
public Definition() {
/*
* empty.
*/
}
/**
* Checks if this node has options.
* @return {@code True} if so.
*/
public boolean hasOptions() {
return hasOptions(true);
}
/**
* Checks if this node has options.
* @param examine If examine should be treated as an option.
* @return {@code True} if so.
*/
public boolean hasOptions(boolean examine) {
if (name.equals("null") || options == null) {
return false;
}
for (String option : options) {
if (option != null && !option.equals("null")) {
if (examine || !option.equals("Examine")) {
return true;
}
}
}
return false;
}
/**
* Gets a configuration of this item's definitions.
* @param key The key.
* @return The configuration value.
*/
@SuppressWarnings("unchecked")
public <V> V getConfiguration(String key) {
return (V) handlers.get(key);
}
/**
* Gets a configuration from this item's definitions.
* @param key The key.
* @param fail The object to return if there was no value found for this
* key.
* @return The value, or the fail object.
*/
@SuppressWarnings("unchecked")
public <V> V getConfiguration(String key, V fail) {
V object = (V) handlers.get(key);
if (object == null) {
return fail;
}
return object;
}
/**
* Gets the id.
* @return The id.
*/
public int getId() {
return id;
}
/**
* Sets the id.
* @param id The id to set.
*/
public void setId(int id) {
this.id = id;
}
/**
* Gets the name.
* @return The name.
*/
public String getName() {
return name;
}
/**
* Sets the name.
* @param name The name to set.
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the examine.
* @return The examine.
*/
public String getExamine() {
if (examine == null) {
try {
examine = handlers.get("examine").toString();
} catch (Exception e){}
if(examine == null) {
if (name.length() > 0) {
examine = "It's a" + (StringUtils.isPlusN(name) ? "n " : " ") + name + ".";
} else {
examine = "null";
}
}
}
return examine;
}
/**
* Sets the examine.
* @param examine The examine to set.
*/
public void setExamine(String examine) {
this.examine = examine;
}
/**
* Gets the options.
* @return The options.
*/
public String[] getOptions() {
return options;
}
/**
* Sets the options.
* @param options The options to set.
*/
public void setOptions(String[] options) {
this.options = options;
}
/**
* Gets the configurations.
* @return The configurations.
*/
public Map<String, Object> getHandlers() {
return handlers;
}
}
@@ -0,0 +1,201 @@
package core.cache.def.impl;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import core.cache.Cache;
import core.cache.misc.buffer.ByteBufferUtils;
/**
* Represents an animation's definitions.
* @author Emperor
*/
public final class AnimationDefinition {
public int anInt2136;
public int anInt2137;
public int[] anIntArray2139;
public int anInt2140;
public boolean aBoolean2141 = false;
public int anInt2142;
public int emoteItem;
public int anInt2144 = -1;
public int[][] handledSounds;
public boolean[] aBooleanArray2149;
public int[] anIntArray2151;
public boolean aBoolean2152;
public int[] durations;
public int anInt2155;
public boolean aBoolean2158;
public boolean aBoolean2159;
public int anInt2162;
public int anInt2163;
boolean newHeader;
// added
public int[] soundMinDelay;
public int[] soundMaxDelay;
public int[] anIntArray1362;
public boolean effect2Sound;
private static final Map<Integer, AnimationDefinition> animDefs = new HashMap<>();
public static final AnimationDefinition forId(int emoteId) {
try {
AnimationDefinition defs = animDefs.get(emoteId);
if (defs != null) {
return defs;
}
byte[] data = Cache.getIndexes()[20].getFileData(emoteId >>> 7, emoteId & 0x7f);
defs = new AnimationDefinition();
if (data != null) {
defs.readValueLoop(ByteBuffer.wrap(data));
}
defs.method2394();
animDefs.put(emoteId, defs);
return defs;
} catch (Throwable t) {
return null;
}
}
private void readValueLoop(ByteBuffer buffer) {
for (;;) {
int opcode = buffer.get() & 0xFF;
if (opcode == 0) {
break;
}
readValues(buffer, opcode);
}
}
/**
* Gets the duration of this animation in milliseconds.
* @return The duration.
*/
public int getDuration() {
if (durations == null) {
return 0;
}
int duration = 0;
for (int i : durations) {
if (i > 100) {
continue;
}
duration += i * 20;
}
return duration;
}
/**
* Gets the duration of this animation in (600ms) ticks.
* @return The duration in ticks.
*/
public int getDurationTicks() {
int ticks = getDuration() / 600;
return Math.max(ticks, 1);
}
private void readValues(ByteBuffer buffer, int opcode) {
if (opcode == 1) {
int length = buffer.getShort() & 0xFFFF;
durations = new int[length];
for (int i = 0; i < length; i++) {
durations[i] = buffer.getShort() & 0xFFFF;
}
anIntArray2139 = new int[length];
for (int i = 0; i < length; i++) {
anIntArray2139[i] = buffer.getShort() & 0xFFFF;
}
for (int i = 0; i < length; i++) {
anIntArray2139[i] = ((buffer.getShort() & 0xFFFF << 16) + anIntArray2139[i]);
}
} else if (opcode != 2) {
if (opcode != 3) {
if (opcode == 4)
aBoolean2152 = true;
else if (opcode == 5)
anInt2142 = buffer.get() & 0xFF;
else if (opcode != 6) {
if (opcode == 7)
emoteItem = buffer.getShort() & 0xFFFF;
else if ((opcode ^ 0xffffffff) != -9) {
if (opcode != 9) {
if (opcode != 10) {
if (opcode == 11)
anInt2155 = buffer.get() & 0xFF;
else if (opcode == 12) {
int i = buffer.get() & 0xFF;
anIntArray2151 = new int[i];
for (int i_19_ = 0; ((i_19_ ^ 0xffffffff) > (i ^ 0xffffffff)); i_19_++) {
anIntArray2151[i_19_] = buffer.getShort() & 0xFFFF;
}
for (int i_20_ = 0; i > i_20_; i_20_++)
anIntArray2151[i_20_] = ((buffer.getShort() & 0xFFFF << 16) + anIntArray2151[i_20_]);
} else if (opcode == 13) {
// opcode 13
int i = buffer.getShort() & 0xFFFF;
handledSounds = new int[i][];
for (int i_21_ = 0; i_21_ < i; i_21_++) {
int i_22_ = buffer.get() & 0xFF;
if ((i_22_ ^ 0xffffffff) < -1) {
handledSounds[i_21_] = new int[i_22_];
handledSounds[i_21_][0] = ByteBufferUtils.getTriByte(buffer);
for (int i_23_ = 1; ((i_22_ ^ 0xffffffff) < (i_23_ ^ 0xffffffff)); i_23_++) {
handledSounds[i_21_][i_23_] = buffer.getShort() & 0xFFFF;
}
}
}
} else if (opcode == 14) {
aBoolean2141 = true;
} else {
System.out.println("Unhandled animation opcode " + opcode);
}
} else
anInt2162 = buffer.get() & 0xFF;
} else
anInt2140 = buffer.get() & 0xFF;
} else
anInt2136 = buffer.get() & 0xFF;
} else
anInt2144 = buffer.getShort() & 0xFFFF;
} else {
aBooleanArray2149 = new boolean[256];
int length = buffer.get() & 0xFF;
for (int i = 0; i < length; i++) {
aBooleanArray2149[buffer.get() & 0xFF] = true;
}
}
} else
anInt2163 = buffer.getShort() & 0xFFFF;
}
public void method2394() {
if (anInt2140 == -1) {
if (aBooleanArray2149 == null)
anInt2140 = 0;
else
anInt2140 = 2;
}
if (anInt2162 == -1) {
if (aBooleanArray2149 == null)
anInt2162 = 0;
else
anInt2162 = 2;
}
}
public AnimationDefinition() {
anInt2136 = 99;
emoteItem = -1;
anInt2140 = -1;
aBoolean2152 = false;
anInt2142 = 5;
aBoolean2159 = false;
anInt2163 = -1;
anInt2155 = 2;
aBoolean2158 = false;
anInt2162 = -1;
}
}
+255
View File
@@ -0,0 +1,255 @@
package core.cache.def.impl;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import core.cache.Cache;
import core.cache.misc.buffer.ByteBufferUtils;
import core.game.world.GameWorld;
/**
* The CS2 mapping.
* @author Emperor
*/
public final class CS2Mapping {
/**
* The CS2 mappings.
*/
private static final Map<Integer, CS2Mapping> maps = new HashMap<>();
/**
* The script id.
*/
private final int scriptId;
/**
* Unknown value.
*/
private int unknown;
/**
* Second unknown value.
*/
private int unknown1;
/**
* The default string value.
*/
private String defaultString;
/**
* The default integer value.
*/
private int defaultInt;
/**
* The mapping.
*/
private HashMap<Integer, Object> map;
/**
* The array of the objects.
*/
private Object[] array;
/**
* Constructs a new {@code CS2Mapping} {@code Object}.
* @param scriptId The script id.
*/
public CS2Mapping(int scriptId) {
this.scriptId = scriptId;
}
/**
* The main method.
* @param args The arguments cast on runtime.
* @throws Throwable When an exception occurs.
*/
public static void main(String... args) throws Throwable {
GameWorld.prompt(false);
BufferedWriter bw = new BufferedWriter(new FileWriter("./cs2.txt"));
for (int i = 0; i < 10000; i++) {
CS2Mapping mapping = forId(i);
if (mapping == null) {
continue;
}
if (mapping.map == null) {
continue;
}
bw.append("ScriptAPI - " + i + " [");
for (int index : mapping.map.keySet()) {
bw.append(mapping.map.get(index) + ": " + index + " ");
}
bw.append("]");
bw.newLine();
}
bw.flush();
bw.close();
}
/**
* Gets the mapping for the given script id.
* @param scriptId The script id.
* @return The mapping.
*/
public static CS2Mapping forId(int scriptId) {
CS2Mapping mapping = maps.get(scriptId);
if (mapping != null) {
return mapping;
}
mapping = new CS2Mapping(scriptId);
byte[] bs = Cache.getIndexes()[17].getFileData(scriptId >>> 8, scriptId & 0xFF);
if (bs != null) {
mapping.load(ByteBuffer.wrap(bs));
} else {
return null;
}
maps.put(scriptId, mapping);
return mapping;
}
/**
* Loads the mapping data.
* @param buffer The buffer to read the data from.
*/
private void load(ByteBuffer buffer) {
int opcode;
while ((opcode = buffer.get() & 0xFF) != 0) {
switch (opcode) {
case 1:
unknown = buffer.get() & 0xFF;
break;
case 2:
unknown1 = buffer.get() & 0xFF;
break;
case 3:
defaultString = ByteBufferUtils.getString(buffer);
break;
case 4:
defaultInt = buffer.getInt();
break;
case 5:
case 6:
int size = buffer.getShort() & 0xFFFF;
String string = null;
int val = 0;
map = new HashMap<>(size);
array = new Object[size];
for (int i = 0; i < size; i++) {
int key = buffer.getInt();
if (opcode == 5) {
string = ByteBufferUtils.getString(buffer);
array[i] = string;
map.put(key, string);
} else {
val = buffer.getInt();
array[i] = val;
map.put(key, val);
}
}
break;
}
}
}
/**
* Gets the array of objects.
* @return the objects.
*/
public Object[] getArray() {
return array;
}
/**
* Gets the scriptId.
* @return The scriptId.
*/
public int getScriptId() {
return scriptId;
}
/**
* Gets the unknown.
* @return The unknown.
*/
public int getUnknown() {
return unknown;
}
/**
* Sets the unknown.
* @param unknown The unknown to set.
*/
public void setUnknown(int unknown) {
this.unknown = unknown;
}
/**
* Gets the unknown1.
* @return The unknown1.
*/
public int getUnknown1() {
return unknown1;
}
/**
* Sets the unknown1.
* @param unknown1 The unknown1 to set.
*/
public void setUnknown1(int unknown1) {
this.unknown1 = unknown1;
}
/**
* Gets the defaultString.
* @return The defaultString.
*/
public String getDefaultString() {
return defaultString;
}
/**
* Sets the defaultString.
* @param defaultString The defaultString to set.
*/
public void setDefaultString(String defaultString) {
this.defaultString = defaultString;
}
/**
* Gets the defaultInt.
* @return The defaultInt.
*/
public int getDefaultInt() {
return defaultInt;
}
/**
* Sets the defaultInt.
* @param defaultInt The defaultInt to set.
*/
public void setDefaultInt(int defaultInt) {
this.defaultInt = defaultInt;
}
/**
* Gets the map.
* @return The map.
*/
public HashMap<Integer, Object> getMap() {
return map;
}
/**
* Sets the map.
* @param map The map to set.
*/
public void setMap(HashMap<Integer, Object> map) {
this.map = map;
}
}
@@ -0,0 +1,208 @@
package core.cache.def.impl;
import java.nio.ByteBuffer;
import java.util.Arrays;
import core.ServerConstants;
import core.cache.Cache;
/**
* The definitions for player clothing/look.
* @author Emperor
*/
public final class ClothDefinition {
/**
* The equipment slot.
*/
private int equipmentSlot;
/**
* The model ids.
*/
private int[] modelIds;
/**
* Unknown boolean.
*/
private boolean unknownBool;
/**
* Original colors.
*/
private int[] originalColors;
/**
* The colors to change to.
*/
private int[] modifiedColors;
/**
* Original texture colors.
*/
private int[] originalTextureColors;
/**
* Texture colors to change to.
*/
private int[] modifiedTextureColors;
/**
* Other model ids(?)
*/
private int[] models = { -1, -1, -1, -1, -1 };
/**
* Gets the definitions for the given cloth id.
* @param clothId The clothing id.
* @return The definition.
*/
public static ClothDefinition forId(int clothId) {
ClothDefinition def = new ClothDefinition();
byte[] bs = Cache.getIndexes()[2].getFileData(3, clothId);
if (bs != null) {
def.load(ByteBuffer.wrap(bs));
}
return def;
}
/**
* The main method.
* @param args The arguments cast on runtime.
*/
public static void main(String... args) {
try {
Cache.init(ServerConstants.CACHE_PATH);
} catch (Throwable e) {
e.printStackTrace();
}
int length = Cache.getIndexes()[2].getFilesSize(3);
System.out.println("Definition size: " + length + ".");
for (int i = 0; i < length; i++) {
ClothDefinition def = forId(i);
if (def.unknownBool)
System.out.println("Clothing " + i + ": " + def.equipmentSlot + ", " + def.unknownBool + ", " + Arrays.toString(def.modelIds) + ", " + Arrays.toString(def.models));
}
}
/**
* Loads the definitions.
* @param buffer The buffer.
*/
public void load(ByteBuffer buffer) {
int opcode;
while ((opcode = buffer.get() & 0xFF) != 0) {
parse(opcode, buffer);
}
}
/**
* Parses an opcode.
* @param opcode The opcode.
* @param buffer The buffer to read the data from.
*/
private void parse(int opcode, ByteBuffer buffer) {
switch (opcode) {
case 1:
equipmentSlot = buffer.get() & 0xFF;
break;
case 2:
int length = buffer.get() & 0xFF;
modelIds = new int[length];
for (int i = 0; i < length; i++) {
modelIds[i] = buffer.getShort() & 0xFFFF;
}
break;
case 3:
unknownBool = true;
break;
case 40:
length = buffer.get() & 0xFF;
originalColors = new int[length];
modifiedColors = new int[length];
for (int i = 0; i < length; i++) {
originalColors[i] = buffer.getShort();
modifiedColors[i] = buffer.getShort();
}
break;
case 41:
length = buffer.get() & 0xFF;
originalTextureColors = new int[length];
modifiedTextureColors = new int[length];
for (int i = 0; i < length; i++) {
originalTextureColors[i] = buffer.getShort();
modifiedTextureColors[i] = buffer.getShort();
}
break;
default:
if (opcode >= 60 && opcode < 70) {
models[opcode - 60] = buffer.getShort() & 0xFFFF;
}
break;
}
}
/**
* Gets the unknown.
* @return The unknown.
*/
public int getUnknown() {
return equipmentSlot;
}
/**
* Gets the modelIds.
* @return The modelIds.
*/
public int[] getModelIds() {
return modelIds;
}
/**
* Gets the unknownBool.
* @return The unknownBool.
*/
public boolean isUnknownBool() {
return unknownBool;
}
/**
* Gets the originalColors.
* @return The originalColors.
*/
public int[] getOriginalColors() {
return originalColors;
}
/**
* Gets the modifiedColors.
* @return The modifiedColors.
*/
public int[] getModifiedColors() {
return modifiedColors;
}
/**
* Gets the originalTextureColors.
* @return The originalTextureColors.
*/
public int[] getOriginalTextureColors() {
return originalTextureColors;
}
/**
* Gets the modifiedTextureColors.
* @return The modifiedTextureColors.
*/
public int[] getModifiedTextureColors() {
return modifiedTextureColors;
}
/**
* Gets the models.
* @return The models.
*/
public int[] getModels() {
return models;
}
}
@@ -0,0 +1,189 @@
package core.cache.def.impl;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import core.ServerConstants;
import core.cache.Cache;
/**
* Represents a Graphic's definition.
* @author Jagex
*/
public class GraphicDefinition {
public short[] aShortArray1435;
public short[] aShortArray1438;
public int anInt1440;
public boolean aBoolean1442;
public int defaultModel;
public int anInt1446;
public boolean aBoolean1448 = false;
public int anInt1449;
public int animationId;
public int anInt1451;
public int graphicsId;
public int anInt1454;
public short[] aShortArray1455;
public short[] aShortArray1456;
// added
public byte byteValue;
// added
public int intValue;
/**
* The definitions mapping.
*/
private static final Map<Integer, GraphicDefinition> graphicDefinitions = new HashMap<>();
/**
* Gets the graphic definition for the given graphic id.
* @param gfxId The graphic id.
* @return The definition.
*/
public static final GraphicDefinition forId(int gfxId) {
GraphicDefinition def = graphicDefinitions.get(gfxId);
if (def != null) {
return def;
}
byte[] data = Cache.getIndexes()[21].getFileData(gfxId >>> 735411752, gfxId & 0xff);
def = new GraphicDefinition();
def.graphicsId = gfxId;
if (data != null) {
def.readValueLoop(ByteBuffer.wrap(data));
}
graphicDefinitions.put(gfxId, def);
return def;
}
/**
* The main method, used for running a graphic definition search.
* @param s The arguments cast on runtime.
*/
public static final void main(String... s) {
try {
Cache.init(ServerConstants.CACHE_PATH);
} catch (Throwable e) {
e.printStackTrace();
}
// 5046 - 5050 are related anims & 2148
GraphicDefinition d = GraphicDefinition.forId(803);
System.out.println("Graphic " + d.graphicsId + " anim id = " + d.animationId + ", " + d.defaultModel + ".");
for (int i = 0; i < 5000; i++) {
GraphicDefinition def = GraphicDefinition.forId(i);
if (def == null) {
continue;
}
if ((def.animationId > 2000 && def.animationId < 2200) || (def.defaultModel >= 1300 && def.defaultModel < 1500)) {
System.out.println("Possible match [id=" + i + ", anim=" + def.animationId + "].");
}
}
}
/**
* Reads and handles all data from the input stream.
* @param buffer The input stream.
*/
private void readValueLoop(ByteBuffer buffer) {
for (;;) {
int opcode = buffer.get() & 0xFF;
if (opcode == 0) {
break;
}
readValues(buffer, opcode);
}
}
/**
* Reads the opcode values from the input stream.
* @param buffer The input stream.
* @param opcode The opcode to handle.
*/
public void readValues(ByteBuffer buffer, int opcode) {
if (opcode != 1) {
if (opcode == 2)
animationId = buffer.getShort();
else if (opcode == 4)
anInt1446 = buffer.getShort() & 0xFFFF;
else if (opcode != 5) {
if ((opcode ^ 0xffffffff) != -7) {
if (opcode == 7)
anInt1440 = buffer.get() & 0xFF;
else if ((opcode ^ 0xffffffff) == -9)
anInt1451 = buffer.get() & 0xFF;
else if (opcode != 9) {
if (opcode != 10) {
if (opcode == 11) { // added opcode
// aBoolean1442 = true;
byteValue = (byte) 1;
} else if (opcode == 12) { // added opcode
// aBoolean1442 = true;
byteValue = (byte) 4;
} else if (opcode == 13) { // added opcode
// aBoolean1442 = true;
byteValue = (byte) 5;
} else if (opcode == 14) { // added opcode
// aBoolean1442 = true;
// aByte2856 = 2;
byteValue = (byte) 2;
intValue = (buffer.get() & 0xFF) * 256;
} else if (opcode == 15) {
// aByte2856 = 3;
byteValue = (byte) 3;
intValue = buffer.getShort() & 0xFFFF;
} else if (opcode == 16) {
// aByte2856 = 3;
byteValue = (byte) 3;
intValue = buffer.getInt();
} else if (opcode != 40) {
if ((opcode ^ 0xffffffff) == -42) {
int i = buffer.get() & 0xFF;
aShortArray1455 = new short[i];
aShortArray1435 = new short[i];
for (int i_0_ = 0; i > i_0_; i_0_++) {
aShortArray1455[i_0_] = (short) (buffer.getShort() & 0xFFFF);
aShortArray1435[i_0_] = (short) (buffer.getShort() & 0xFFFF);
}
}
} else {
int i = buffer.get() & 0xFF;
aShortArray1438 = new short[i];
aShortArray1456 = new short[i];
for (int i_1_ = 0; ((i ^ 0xffffffff) < (i_1_ ^ 0xffffffff)); i_1_++) {
aShortArray1438[i_1_] = (short) (buffer.getShort() & 0xFFFF);
aShortArray1456[i_1_] = (short) (buffer.getShort() & 0xFFFF);
}
}
} else
aBoolean1448 = true;
} else {
// aBoolean1442 = true;
byteValue = (byte) 3;
intValue = 8224;
}
} else
anInt1454 = buffer.getShort() & 0xFFFF;
} else
anInt1449 = buffer.getShort() & 0xFFFF;
} else
defaultModel = buffer.getShort();
}
/**
* Constructs a new {@code GraphicDefinition} {@code Object}.
*/
public GraphicDefinition() {
byteValue = 0;
intValue = -1;
anInt1446 = 128;
aBoolean1442 = false;
anInt1449 = 128;
anInt1451 = 0;
animationId = -1;
anInt1454 = 0;
anInt1440 = 0;
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,329 @@
package core.cache.def.impl;
import core.cache.Cache;
import core.game.system.SystemLogger;
import core.game.world.GameWorld;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.ByteBuffer;
/**
* Holds definitions for render animations.
* @author Jagex
* @author Emperor
*
*/
public class RenderAnimationDefinition {
public int turn180Animation;
public int anInt951 = -1;
public int anInt952;
public int turnCWAnimation = -1;
public int anInt954;
public int anInt955;
public int anInt956;
public int anInt957;
public int anInt958;
public int[] anIntArray959 = null;
public int anInt960;
public int anInt961 = 0;
public int anInt962;
public int walkAnimationId;
public int anInt964;
public int anInt965;
public int anInt966;
public int[] standAnimationIds;
public int anInt969;
public int[] anIntArray971;
public int standAnimationId;
public int anInt973;
public int anInt974;
public int anInt975;
public int runAnimationId;
public int anInt977;
public boolean aBoolean978;
public int[][] anIntArrayArray979;
public int anInt980;
public int turnCCWAnimation;
public int anInt983;
public int anInt985;
public int anInt986;
public int anInt987;
public int anInt988;
public int anInt989;
public int anInt990;
public int anInt992;
public int anInt993;
public int anInt994;
/**
* Gets the render animation definitions for the given id.
* @param animId The render animation id.
* @return The render animation definitions.
*/
public static RenderAnimationDefinition forId(int animId) {
RenderAnimationDefinition defs = new RenderAnimationDefinition();
if (animId == -1) {
return null;
}
byte[] data = Cache.getIndexes()[2].getFileData(32, animId);
defs = new RenderAnimationDefinition();
if (data != null) {
defs.parse(ByteBuffer.wrap(data));
} else {
SystemLogger.logErr("No definitions found for render animation " + animId + ", size=" + Cache.getIndexes()[2].getFilesSize(32) + "!");
}
return defs;
}
private void parse(ByteBuffer buffer) {
for (;;) {
int opcode = buffer.get() & 0xFF;
if (opcode == 0) {
break;
}
parseOpcode(buffer, opcode);
}
}
private void parseOpcode(ByteBuffer buffer, int opcode) {
if (opcode == 54) {
@SuppressWarnings("unused")
int anInt1260 = (buffer.get() & 0xFF) << 6;
@SuppressWarnings("unused")
int anInt1227 = (buffer.get() & 0xFF) << 6;
} else if (opcode == 55) {
int[] anIntArray1246 = new int[12];
int i_14_ = buffer.get() & 0xFF;
anIntArray1246[i_14_] = buffer.getShort() & 0xFFFF;
} else if (opcode == 56) {
int[][] anIntArrayArray1217 = new int[12][];
int i_12_ = buffer.get() & 0xFF;
anIntArrayArray1217[i_12_] = new int[3];
for (int i_13_ = 0; i_13_ < 3; i_13_++)
anIntArrayArray1217[i_12_][i_13_] = buffer.getShort();
} else if ((opcode ^ 0xffffffff) != -2) {
if ((opcode ^ 0xffffffff) != -3) {
if (opcode != 3) {
if ((opcode ^ 0xffffffff) != -5) {
if (opcode == 5)
anInt977 = buffer.getShort() & 0xFFFF;
else if ((opcode ^ 0xffffffff) != -7) {
if (opcode == 7)
anInt960 = buffer.getShort() & 0xFFFF;
else if ((opcode ^ 0xffffffff) == -9)
anInt985 = buffer.getShort() & 0xFFFF;
else if (opcode == 9)
anInt957 = buffer.getShort() & 0xFFFF;
else if (opcode == 26) {
anInt973 = (short) (4 * buffer
.get() & 0xFF);
anInt975 = (short) (buffer.get() & 0xFF * 4);
} else if ((opcode ^ 0xffffffff) == -28) {
if (anIntArrayArray979 == null)
anIntArrayArray979 = new int[12][];
int i = buffer.get() & 0xFF;
anIntArrayArray979[i] = new int[6];
for (int i_1_ = 0; (i_1_ ^ 0xffffffff) > -7; i_1_++)
anIntArrayArray979[i][i_1_] = buffer
.getShort();
} else if ((opcode ^ 0xffffffff) == -29) {
anIntArray971 = new int[12];
for (int i = 0; i < 12; i++) {
anIntArray971[i] = buffer
.get() & 0xFF;
if (anIntArray971[i] == 255)
anIntArray971[i] = -1;
}
} else if (opcode != 29) {
if (opcode != 30) {
if ((opcode ^ 0xffffffff) != -32) {
if (opcode != 32) {
if ((opcode ^ 0xffffffff) != -34) {
if (opcode != 34) {
if (opcode != 35) {
if ((opcode ^ 0xffffffff) != -37) {
if ((opcode ^ 0xffffffff) != -38) {
if (opcode != 38) {
if ((opcode ^ 0xffffffff) != -40) {
if ((opcode ^ 0xffffffff) != -41) {
if ((opcode ^ 0xffffffff) == -42)
turnCWAnimation = buffer
.getShort() & 0xFFFF;
else if (opcode != 42) {
if ((opcode ^ 0xffffffff) == -44)
buffer.getShort();
else if ((opcode ^ 0xffffffff) != -45) {
if ((opcode ^ 0xffffffff) == -46)
anInt964 = buffer
.getShort() & 0xFFFF;
else if ((opcode ^ 0xffffffff) != -47) {
if (opcode == 47)
anInt966 = buffer
.getShort() & 0xFFFF;
else if (opcode == 48)
anInt989 = buffer
.getShort() & 0xFFFF;
else if (opcode != 49) {
if ((opcode ^ 0xffffffff) != -51) {
if (opcode != 51) {
if (opcode == 52) {
int i = buffer
.get() & 0xFF;
anIntArray959 = new int[i];
standAnimationIds = new int[i];
for (int i_2_ = 0; i_2_ < i; i_2_++) {
standAnimationIds[i_2_] = buffer
.getShort() & 0xFFFF;
int i_3_ = buffer
.get() & 0xFF;
anIntArray959[i_2_] = i_3_;
anInt994 += i_3_;
}
} else if (opcode == 53)
aBoolean978 = false;
} else
anInt962 = buffer
.getShort() & 0xFFFF;
} else
anInt990 = buffer
.getShort() & 0xFFFF;
} else
anInt952 = buffer
.getShort() & 0xFFFF;
} else
anInt983 = buffer
.getShort() & 0xFFFF;
} else
anInt955 = buffer
.getShort() & 0xFFFF;
} else
turnCCWAnimation = buffer
.getShort() & 0xFFFF;
} else
turn180Animation = buffer
.getShort() & 0xFFFF;
} else
anInt954 = buffer
.getShort() & 0xFFFF;
} else
anInt958 = (buffer
.getShort() & 0xFFFF);
} else
anInt951 = (buffer
.get() & 0xFF);
} else
anInt965 = (buffer
.getShort());
} else
anInt969 = (buffer
.getShort() & 0xFFFF);
} else
anInt993 = buffer
.get() & 0xFF;
} else
anInt956 = (buffer.getShort());
} else
anInt961 = buffer
.getShort() & 0xFFFF;
} else
anInt988 = buffer.get() & 0xFF;
} else
anInt980 = buffer.getShort() & 0xFFFF;
} else
anInt992 = buffer.get() & 0xFF;
} else
runAnimationId = buffer.getShort() & 0xFFFF;
} else
anInt986 = buffer.getShort() & 0xFFFF;
} else
anInt987 = buffer.getShort() & 0xFFFF;
} else
anInt974 = buffer.getShort() & 0xFFFF;
} else {
standAnimationId = buffer.getShort() & 0xFFFF;
walkAnimationId = buffer.getShort() & 0xFFFF;
if ((standAnimationId ^ 0xffffffff) == -65536)
standAnimationId = -1;
if ((walkAnimationId ^ 0xffffffff) == -65536)
walkAnimationId = -1;
}
}
public RenderAnimationDefinition() {
anInt957 = -1;
anInt954 = -1;
anInt960 = -1;
anInt958 = -1;
anInt965 = 0;
anInt973 = 0;
turn180Animation = -1;
anInt956 = 0;
standAnimationId = -1;
standAnimationIds = null;
anInt952 = -1;
anInt983 = -1;
anInt985 = -1;
anInt962 = -1;
anInt966 = -1;
anInt977 = -1;
anInt975 = 0;
runAnimationId = -1;
anInt988 = 0;
turnCCWAnimation = -1;
anInt987 = -1;
anInt980 = 0;
anInt964 = -1;
walkAnimationId = -1;
anInt986 = -1;
aBoolean978 = true;
anInt992 = 0;
anInt955 = -1;
anInt989 = -1;
anInt974 = -1;
anInt969 = 0;
anInt994 = 0;
anInt990 = -1;
anInt993 = 0;
}
public static void main(String...args) throws Throwable {
GameWorld.prompt(false);
RenderAnimationDefinition def = RenderAnimationDefinition.forId(1426);
System.out.println("size: " + def.getClass().getDeclaredFields().length);
for (Field f : def.getClass().getDeclaredFields()) {
if (!Modifier.isStatic(f.getModifiers())) {
if (f.getType().isArray()) {
Object object = f.get(def);
if (object != null) {
int length = Array.getLength(object);
System.out.print(f.getName() + ", [");
for (int i = 0; i < length; i++) {
System.out.print(Array.get(object, i) + (i < (length - 1) ? ", " : "]"));
}
continue;
}
}
System.out.println(f.getName() + ", " + f.get(def));
}
}
for (Field f : def.getClass().getSuperclass().getDeclaredFields()) {
if (!Modifier.isStatic(f.getModifiers())) {
if (f.getType().isArray()) {
Object object = f.get(def);
if (object != null) {
int length = Array.getLength(object);
System.out.print(f.getName() + ", [");
for (int i = 0; i < length; i++) {
System.out.print(Array.get(object, i) + (i < (length - 1) ? ", " : "]"));
}
continue;
}
}
System.out.println(f.getName() + ", " + f.get(def));
}
}
}
}
@@ -0,0 +1,176 @@
package core.cache.def.impl;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import core.cache.Cache;
import core.game.Varbit;
import core.game.node.entity.player.Player;
import core.game.system.SystemLogger;
import core.game.world.GameWorld;
/**
* Handles config definition reading.
* @author Emperor
*/
public final class VarbitDefinition {
/**
* The config definitions mapping.
*/
private static final Map<Integer, VarbitDefinition> MAPPING = new HashMap<>();
/**
* The bit size flags.
*/
private static final int[] BITS = new int[32];
/**
* The file id.
*/
private final int id;
/**
* The config id.
*/
private int configId;
/**
* The bit shift amount.
*/
private int bitShift;
/**
* The bit amount.
*/
private int bitSize;
/**
* Constructs a new {@code ConfigFileDefinition} {@code Object}.
* @param id The file id.
*/
public VarbitDefinition(int id) {
this.id = id;
}
/**
* Initializes the bit flags.
*/
static {
int flag = 2;
for (int i = 0; i < 32; i++) {
BITS[i] = flag - 1;
flag += flag;
}
}
/**
* Gets the config file definitions for the given file id.
* @param id The file id.
* @return The definition.
*/
public static VarbitDefinition forObjectID(int id) {
return forId(id,10);
}
public static VarbitDefinition forNPCID(int id){
return forId(id,10);
}
public static VarbitDefinition forItemID(int id){
return forId(id,30);
}
public static VarbitDefinition forId(int id, int shiftAmount){
/*VarbitDefinition def = MAPPING.get(id);
if (def != null) {
return def;
}*/
VarbitDefinition def;
def = new VarbitDefinition(id);
byte[] bs = Cache.getIndexes()[22].getFileData(id >>> 10, id & 0x3ff);
if (bs != null) {
ByteBuffer buffer = ByteBuffer.wrap(bs);
int opcode = 0;
while ((opcode = buffer.get() & 0xFF) != 0) {
if (opcode == 1) {
def.configId = buffer.getShort() & 0xFFFF;
def.bitShift = buffer.get() & 0xFF;
def.bitSize = buffer.get() & 0xFF;
}
}
}
MAPPING.put(id, def);
return def;
}
public static void main(String... args) throws Throwable {
GameWorld.prompt(false);
for (int i = 0; i < 15000; i++) {
VarbitDefinition def = forObjectID(i);
if (def != null && def.configId == 33) {
System.out.println("Config file [id=" + i + ", shift=" + def.bitShift + "]!");
}
}
}
/**
* Gets the current config value for this file.
* @param player The player.
* @return The config value.
*/
public int getValue(Player player) {
int size = BITS[bitSize - bitShift];
int bitValue = player.varpManager.get(getConfigId()).getBitRangeValue(getBitShift(), getBitShift() + (bitSize - bitShift));
if(bitValue != 0){
return bitValue >>> bitShift;
}
return size & (player.getConfigManager().get(configId) >>> bitShift);
}
/**
* Gets the mapping.
* @return The mapping.
*/
public static Map<Integer, VarbitDefinition> getMapping() {
return MAPPING;
}
/**
* Gets the id.
* @return The id.
*/
public int getId() {
return id;
}
/**
* Gets the configId.
* @return The configId.
*/
public int getConfigId() {
return configId;
}
/**
* Gets the bitShift.
* @return The bitShift.
*/
public int getBitShift() {
return bitShift;
}
/**
* Gets the bitSize.
* @return The bitSize.
*/
public int getBitSize() {
return bitSize;
}
@Override
public String toString() {
return "ConfigFileDefinition [id=" + id + ", configId=" + configId + ", bitShift=" + bitShift + ", bitSize=" + bitSize + "]";
}
}
+365
View File
@@ -0,0 +1,365 @@
private void readValues(int i, InputStream stream, int opcode) {
if (opcode != 1 && opcode != 5) {
if (opcode != 2) {
if (opcode != 14) {
if (opcode != 15) {
if (opcode == 17) {
projectileCliped = false;
clipType = 0;
} else if (opcode != 18) {
if (opcode == 19)
secondInt = stream.readUnsignedByte();
else if (opcode == 21)
aByte3912 = (byte) 1;
else if (opcode != 22) {
if (opcode != 23) {
if (opcode != 24) {
if (opcode == 27)
clipType = 1;
else if (opcode == 28)
anInt3892 = (stream
.readUnsignedByte() << 2);
else if (opcode != 29) {
if (opcode != 39) {
if (opcode < 30 || opcode >= 35) {
if (opcode == 40) {
int i_53_ = (stream
.readUnsignedByte());
originalColors = new short[i_53_];
modifiedColors = new short[i_53_];
for (int i_54_ = 0; i_53_ > i_54_; i_54_++) {
originalColors[i_54_] = (short) (stream
.readUnsignedShort());
modifiedColors[i_54_] = (short) (stream
.readUnsignedShort());
}
} else if (opcode != 41) {
if (opcode != 42) {
if (opcode != 62) {
if (opcode != 64) {
if (opcode == 65)
anInt3902 = stream
.readUnsignedShort();
else if (opcode != 66) {
if (opcode != 67) {
if (opcode == 69)
anInt3925 = stream
.readUnsignedByte();
else if (opcode != 70) {
if (opcode == 71)
anInt3889 = stream
.readShort() << 2;
else if (opcode != 72) {
if (opcode == 73)
secondBool = true;
else if (opcode == 74)
notCliped = true;
else if (opcode != 75) {
if (opcode != 77
&& opcode != 92) {
if (opcode == 78) {
anInt3860 = stream
.readUnsignedShort();
anInt3904 = stream
.readUnsignedByte();
} else if (opcode != 79) {
if (opcode == 81) {
aByte3912 = (byte) 2;
anInt3882 = 256 * stream
.readUnsignedByte();
} else if (opcode != 82) {
if (opcode == 88)
aBoolean3853 = false;
else if (opcode != 89) {
if (opcode == 90)
aBoolean3870 = true;
else if (opcode != 91) {
if (opcode != 93) {
if (opcode == 94)
aByte3912 = (byte) 4;
else if (opcode != 95) {
if (opcode != 96) {
if (opcode == 97)
aBoolean3866 = true;
else if (opcode == 98)
aBoolean3923 = true;
else if (opcode == 99) {
anInt3857 = stream
.readUnsignedByte();
anInt3835 = stream
.readUnsignedShort();
} else if (opcode == 100) {
anInt3844 = stream
.readUnsignedByte();
anInt3913 = stream
.readUnsignedShort();
} else if (opcode != 101) {
if (opcode == 102)
anInt3838 = stream
.readUnsignedShort();
else if (opcode == 103)
thirdInt = 0;
else if (opcode != 104) {
if (opcode == 105)
aBoolean3906 = true;
else if (opcode == 106) {
int i_55_ = stream
.readUnsignedByte();
anIntArray3869 = new int[i_55_];
anIntArray3833 = new int[i_55_];
for (int i_56_ = 0; i_56_ < i_55_; i_56_++) {
anIntArray3833[i_56_] = stream
.readUnsignedShort();
int i_57_ = stream
.readUnsignedByte();
anIntArray3869[i_56_] = i_57_;
anInt3881 += i_57_;
}
} else if (opcode == 107)
anInt3851 = stream
.readUnsignedShort();
else if (opcode >= 150
&& opcode < 155) {
options[opcode
+ -150] = stream
.readString();
/*if (!loader.showOptions)
options[opcode + -150] = null;*/
} else if (opcode != 160) {
if (opcode == 162) {
aByte3912 = (byte) 3;
anInt3882 = stream
.readInt();
} else if (opcode == 163) {
aByte3847 = (byte) stream
.readByte();
aByte3849 = (byte) stream
.readByte();
aByte3837 = (byte) stream
.readByte();
aByte3914 = (byte) stream
.readByte();
} else if (opcode != 164) {
if (opcode != 165) {
if (opcode != 166) {
if (opcode == 167)
anInt3921 = stream
.readUnsignedShort();
else if (opcode != 168) {
if (opcode == 169) {
aBoolean3845 = true;
//added opcode
}else if (opcode == 170) {
int anInt3383 = stream.readUnsignedSmart();
//added opcode
}else if (opcode == 171) {
int anInt3362 = stream.readUnsignedSmart();
//added opcode
}else if (opcode == 173) {
int anInt3302 = stream.readUnsignedShort();
int anInt3336 = stream.readUnsignedShort();
//added opcode
}else if (opcode == 177) {
boolean ub = true;
//added opcode
}else if (opcode == 178) {
int db = stream.readUnsignedByte();
} else if (opcode == 249) {
int i_58_ = stream
.readUnsignedByte();
if (aClass194_3922 == null) {
/*int i_59_ = Class307
.method3331(
(byte) -117,
i_58_);
aClass194_3922 = new HashTable(
i_59_);*/
}
for (int i_60_ = 0; i_60_ < i_58_; i_60_++) {
boolean bool = stream
.readUnsignedByte() == 1;
int i_61_ = stream.read24BitInt();
Object class279;
if (!bool)
/*class279 = new IntegerNode(*/
stream
.readInt();//);
else
/*class279 = new Class279_Sub4(*/
stream
.readString();//);
/*aClass194_3922
.method1598(
(long) i_61_,
-125,
class279);*/
}
}
} else
aBoolean3894 = true;
} else
anInt3877 = stream
.readShort();
} else
anInt3875 = stream
.readShort();
} else
anInt3834 = stream
.readShort();
} else {
int i_62_ = stream
.readUnsignedByte();
anIntArray3908 = new int[i_62_];
for (int i_63_ = 0; i_62_ > i_63_; i_63_++)
anIntArray3908[i_63_] = stream
.readUnsignedShort();
}
} else
anInt3865 = stream
.readUnsignedByte();
} else
anInt3850 = stream
.readUnsignedByte();
} else
aBoolean3924 = true;
} else {
aByte3912 = (byte) 5;
anInt3882 = stream
.readShort();
}
} else {
aByte3912 = (byte) 3;
anInt3882 = stream
.readUnsignedShort();
}
} else
aBoolean3873 = true;
} else
aBoolean3895 = false;
} else
aBoolean3891 = true;
} else {
anInt3900 = stream
.readUnsignedShort();
anInt3905 = stream
.readUnsignedShort();
anInt3904 = stream
.readUnsignedByte();
int i_64_ = stream
.readUnsignedByte();
anIntArray3859 = new int[i_64_];
for (int i_65_ = 0; i_65_ < i_64_; i_65_++)
anIntArray3859[i_65_] = stream
.readUnsignedShort();
}
} else {
configFileId = stream
.readUnsignedShort();
if (configFileId == 65535)
configFileId = -1;
configId = stream
.readUnsignedShort();
if (configId == 65535)
configId = -1;
int i_66_ = -1;
if (opcode == 92) {
i_66_ = stream
.readUnsignedShort();
if (i_66_ == 65535)
i_66_ = -1;
}
int i_67_ = stream
.readUnsignedByte();
childrenIds = new int[i_67_
- -2];
for (int i_68_ = 0; i_67_ >= i_68_; i_68_++) {
childrenIds[i_68_] = stream
.readUnsignedShort();
if (childrenIds[i_68_] == 65535)
childrenIds[i_68_] = -1;
}
childrenIds[i_67_ + 1] = i_66_;
}
} else
anInt3855 = stream
.readUnsignedByte();
} else
anInt3915 = stream
.readShort() << 2;
} else
anInt3883 = stream
.readShort() << 2;
} else
anInt3917 = stream
.readUnsignedShort();
} else
anInt3841 = stream
.readUnsignedShort();
} else
aBoolean3872 = false;
} else
aBoolean3839 = true;
} else {
int i_69_ = (stream
.readUnsignedByte());
aByteArray3858 = (new byte[i_69_]);
for (int i_70_ = 0; i_70_ < i_69_; i_70_++)
aByteArray3858[i_70_] = (byte) (stream
.readByte());
}
} else {
int i_71_ = (stream
.readUnsignedByte());
aShortArray3920 = new short[i_71_];
aShortArray3919 = new short[i_71_];
for (int i_72_ = 0; i_71_ > i_72_; i_72_++) {
aShortArray3920[i_72_] = (short) (stream
.readUnsignedShort());
aShortArray3919[i_72_] = (short) (stream
.readUnsignedShort());
}
}
} else
options[-30
+ opcode] = (stream
.readString());
} else
anInt3840 = (stream.readByte() * 5);
} else
anInt3878 = stream.readByte();
} else {
anInt3876 = stream.readUnsignedShort();
if (anInt3876 == 65535)
anInt3876 = -1;
}
} else
thirdInt = 1;
} else
aBoolean3867 = true;
} else
projectileCliped = false;
} else
sizeY = stream.readUnsignedByte();
} else
sizeX = stream.readUnsignedByte();
} else
name = stream.readString();
} else {
boolean aBoolean1162 = false;
if (opcode == 5 && aBoolean1162)
method3297(stream);
int i_73_ = stream.readUnsignedByte();
anIntArrayArray3916 = new int[i_73_][];
aByteArray3899 = new byte[i_73_];
for (int i_74_ = 0; i_74_ < i_73_; i_74_++) {
aByteArray3899[i_74_] = (byte) stream.readByte();
int i_75_ = stream.readUnsignedByte();
anIntArrayArray3916[i_74_] = new int[i_75_];
for (int i_76_ = 0; i_75_ > i_76_; i_76_++)
anIntArrayArray3916[i_74_][i_76_] = stream
.readUnsignedShort();
}
if (opcode == 5 && !aBoolean1162)
method3297(stream);
}
}
@@ -0,0 +1,47 @@
package core.cache.gzip;
import java.nio.ByteBuffer;
import java.util.zip.Inflater;
public class GZipDecompressor {
private static final Inflater inflaterInstance = new Inflater(true);
public static final void decompress(ByteBuffer buffer, byte data[]) {
synchronized (inflaterInstance) {
if (~buffer.get(buffer.position()) != -32 || buffer.get(buffer.position() + 1) != -117) {
data = null;
// throw new RuntimeException("Invalid GZIP header!");
}
try {
inflaterInstance.setInput(buffer.array(), buffer.position() + 10, -buffer.position() - 18 + buffer.limit());
inflaterInstance.inflate(data);
} catch (Exception e) {
// inflaterInstance.reset();
data = null;
// throw new RuntimeException("Invalid GZIP compressed data!");
}
inflaterInstance.reset();
}
}
public static final boolean decompress(byte[] compressed, byte data[], int offset, int length) {
synchronized (inflaterInstance) {
if (data[offset] != 31 || data[offset + 1] != -117)
return false;
// throw new RuntimeException("Invalid GZIP header!");
try {
inflaterInstance.setInput(data, offset + 10, -offset - 18 + length);
inflaterInstance.inflate(compressed);
} catch (Exception e) {
inflaterInstance.reset();
e.printStackTrace();
return false;
// throw new RuntimeException("Invalid GZIP compressed data!");
}
inflaterInstance.reset();
return true;
}
}
}
+109
View File
@@ -0,0 +1,109 @@
package core.cache.misc;
/**
* A container.
* @author Dragonkk
*/
public class Container {
/**
* The version.
*/
private int version;
/**
* The CRC.
*/
private int crc;
/**
* The name hash.
*/
private int nameHash;
/**
* If updated.
*/
private boolean updated;
/**
* Construct a new container.
*/
public Container() {
nameHash = -1;
version = -1;
crc = -1;
}
/**
* Set the version.
* @param version
*/
public void setVersion(int version) {
this.version = version;
}
/**
* Update the version.
*/
public void updateVersion() {
version++;
updated = true;
}
/**
* Get the version.
* @return The version.
*/
public int getVersion() {
return version;
}
/**
* Get the next version.
* @return The next version.
*/
public int getNextVersion() {
return updated ? version : version + 1;
}
/**
* Set the CRC.
* @param crc The cRC.
*/
public void setCrc(int crc) {
this.crc = crc;
}
/**
* Get the CRC.
* @return The CRC.
*/
public int getCrc() {
return crc;
}
/**
* Set the name hash.
* @param nameHash The name hash.
*/
public void setNameHash(int nameHash) {
this.nameHash = nameHash;
}
/**
* Get the name hash.
* @return The name hash.
*/
public int getNameHash() {
return nameHash;
}
/**
* If is updated.
* @return If is updated.
*/
public boolean isUpdated() {
return updated;
}
}
@@ -0,0 +1,228 @@
package core.cache.misc;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.zip.CRC32;
import core.cache.bzip2.BZip2Decompressor;
import core.cache.gzip.GZipDecompressor;
/**
* A class holding the containers information.
* @author Dragonkk
*/
public final class ContainersInformation {
/**
* The information container.
*/
private Container informationContainer;
/**
* The protocol.
*/
private int protocol;
/**
* The revision.
*/
private int revision;
/**
* The container indexes.
*/
private int[] containersIndexes;
/**
* The containers.
*/
private FilesContainer[] containers;
/**
* If files have to be named.
*/
private boolean filesNamed;
/**
* If it has to be whirpool.
*/
private boolean whirpool;
/**
* The data.
*/
private final byte[] data;
/**
* Construct a new containers information.
* @param informationContainerPackedData The information container data
* packed.
*/
public ContainersInformation(byte[] informationContainerPackedData) {
this.data = Arrays.copyOf(informationContainerPackedData, informationContainerPackedData.length);
informationContainer = new Container();
informationContainer.setVersion((informationContainerPackedData[informationContainerPackedData.length - 2] << 8 & 0xff00) + (informationContainerPackedData[-1 + informationContainerPackedData.length] & 0xff));
CRC32 crc32 = new CRC32();
crc32.update(informationContainerPackedData);
informationContainer.setCrc((int) crc32.getValue());
decodeContainersInformation(unpackCacheContainer(informationContainerPackedData));
}
/**
* Unpacks a container.
* @param packedData The packed container data.
* @return The unpacked data.
*/
public static final byte[] unpackCacheContainer(byte[] packedData) {
ByteBuffer buffer = ByteBuffer.wrap(packedData);
int compression = buffer.get() & 0xFF;
int containerSize = buffer.getInt();
if (containerSize < 0 || containerSize > 5000000) {
return null;
// throw new RuntimeException();
}
if (compression == 0) {
byte unpacked[] = new byte[containerSize];
buffer.get(unpacked, 0, containerSize);
return unpacked;
}
int decompressedSize = buffer.getInt();
if (decompressedSize < 0 || decompressedSize > 20000000) {
return null;
// throw new RuntimeException();
}
byte decompressedData[] = new byte[decompressedSize];
if (compression == 1) {
BZip2Decompressor.decompress(decompressedData, packedData, containerSize, 9);
} else {
GZipDecompressor.decompress(buffer, decompressedData);
}
return decompressedData;
}
/**
* Get the container indexes.
* @return The container indexes.
*/
public int[] getContainersIndexes() {
return containersIndexes;
}
/**
* Get the containers.
* @return The containers.
*/
public FilesContainer[] getContainers() {
return containers;
}
/**
* Get the information container.
* @return The information container.
*/
public Container getInformationContainer() {
return informationContainer;
}
/**
* Get the revision.
* @return The revision.
*/
public int getRevision() {
return revision;
}
/**
* Decode the containers information.
* @param data The data.
*/
public void decodeContainersInformation(byte[] data) {
ByteBuffer buffer = ByteBuffer.wrap(data);
protocol = buffer.get() & 0xFF;
if (protocol != 5 && protocol != 6) {
throw new RuntimeException();
}
revision = protocol < 6 ? 0 : buffer.getInt();
int nameHash = buffer.get() & 0xFF;
filesNamed = (0x1 & nameHash) != 0;
whirpool = (0x2 & nameHash) != 0;
containersIndexes = new int[buffer.getShort() & 0xFFFF];
int lastIndex = -1;
for (int index = 0; index < containersIndexes.length; index++) {
containersIndexes[index] = (buffer.getShort() & 0xFFFF) + (index == 0 ? 0 : containersIndexes[index - 1]);
if (containersIndexes[index] > lastIndex) {
lastIndex = containersIndexes[index];
}
}
containers = new FilesContainer[lastIndex + 1];
for (int index = 0; index < containersIndexes.length; index++) {
containers[containersIndexes[index]] = new FilesContainer();
}
if (filesNamed) {
for (int index = 0; index < containersIndexes.length; index++) {
containers[containersIndexes[index]].setNameHash(buffer.getInt());
}
}
byte[][] filesHashes = null;
if (whirpool) {
filesHashes = new byte[containers.length][];
for (int index = 0; index < containersIndexes.length; index++) {
filesHashes[containersIndexes[index]] = new byte[64];
buffer.get(filesHashes[containersIndexes[index]], 0, 64);
}
}
for (int index = 0; index < containersIndexes.length; index++) {
containers[containersIndexes[index]].setCrc(buffer.getInt());
}
for (int index = 0; index < containersIndexes.length; index++) {
containers[containersIndexes[index]].setVersion(buffer.getInt());
}
for (int index = 0; index < containersIndexes.length; index++) {
containers[containersIndexes[index]].setFilesIndexes(new int[buffer.getShort() & 0xFFFF]);
}
for (int index = 0; index < containersIndexes.length; index++) {
int lastFileIndex = -1;
for (int fileIndex = 0; fileIndex < containers[containersIndexes[index]].getFilesIndexes().length; fileIndex++) {
containers[containersIndexes[index]].getFilesIndexes()[fileIndex] = (buffer.getShort() & 0xFFFF) + (fileIndex == 0 ? 0 : containers[containersIndexes[index]].getFilesIndexes()[fileIndex - 1]);
if (containers[containersIndexes[index]].getFilesIndexes()[fileIndex] > lastFileIndex) {
lastFileIndex = containers[containersIndexes[index]].getFilesIndexes()[fileIndex];
}
}
containers[containersIndexes[index]].setFiles(new Container[lastFileIndex + 1]);
for (int fileIndex = 0; fileIndex < containers[containersIndexes[index]].getFilesIndexes().length; fileIndex++) {
containers[containersIndexes[index]].getFiles()[containers[containersIndexes[index]].getFilesIndexes()[fileIndex]] = new Container();
}
}
if (whirpool) {
for (int index = 0; index < containersIndexes.length; index++) {
for (int fileIndex = 0; fileIndex < containers[containersIndexes[index]].getFilesIndexes().length; fileIndex++) {
containers[containersIndexes[index]].getFiles()[containers[containersIndexes[index]].getFilesIndexes()[fileIndex]].setVersion(filesHashes[containersIndexes[index]][containers[containersIndexes[index]].getFilesIndexes()[fileIndex]]);
}
}
}
if (filesNamed) {
for (int index = 0; index < containersIndexes.length; index++) {
for (int fileIndex = 0; fileIndex < containers[containersIndexes[index]].getFilesIndexes().length; fileIndex++) {
containers[containersIndexes[index]].getFiles()[containers[containersIndexes[index]].getFilesIndexes()[fileIndex]].setNameHash(buffer.getInt());
}
}
}
}
/**
* If is whirpool.
* @return If is whirpool {@code true}.
*/
public boolean isWhirpool() {
return whirpool;
}
/**
* Gets the data.
* @return The data.
*/
public byte[] getData() {
return data;
}
}
@@ -0,0 +1,57 @@
package core.cache.misc;
/**
* A class holding the file containers.
* @author Dragonkk
*/
public final class FilesContainer extends Container {
/**
* The file indexes.
*/
private int[] filesIndexes;
/**
* The files.
*/
private Container[] files;
/**
* Construct a new files container.
*/
public FilesContainer() {
}
/**
* Set the files.
* @param containers The files.
*/
public void setFiles(Container[] containers) {
this.files = containers;
}
/**
* Get the files.
* @return The files.
*/
public Container[] getFiles() {
return files;
}
/**
* Set the file indexes.
* @param containersIndexes The file indexes.
*/
public void setFilesIndexes(int[] containersIndexes) {
this.filesIndexes = containersIndexes;
}
/**
* Get the file indexes.
* @return The file indexes.
*/
public int[] getFilesIndexes() {
return filesIndexes;
}
}
@@ -0,0 +1,39 @@
package core.cache.misc.buffer;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
/**
* Handles the reading of data from a byte buffer.
* @author Emperor
*/
public final class BufferInputStream extends InputStream {
/**
* The buffer to write on.
*/
private final ByteBuffer buffer;
/**
* The buffer input stream.
* @param buffer The buffer.
*/
public BufferInputStream(ByteBuffer buffer) throws IOException {
this.buffer = buffer;
}
@Override
public int read() throws IOException {
return buffer.get();
}
/**
* Gets the buffer.
* @return The buffer.
*/
public ByteBuffer getBuffer() {
return buffer;
}
}
@@ -0,0 +1,57 @@
package core.cache.misc.buffer;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
/**
* Handles the writing of data on a byte buffer.
* @author Emperor
*/
public final class BufferOutputStream extends OutputStream {
/**
* The buffer to write on.
*/
private final ByteBuffer buffer;
/**
* Constructs a new {@code BufferOutputStream} {@code Object}.
* @param buffer The buffer to write on.
* @throws IOException When an I/O exception occurs.
* @throws SecurityException If a security manager exists and its
* checkPermission method denies enabling subclassing.
*/
public BufferOutputStream(ByteBuffer buffer) throws IOException, SecurityException {
super();
this.buffer = buffer;
}
@Override
public void write(int b) throws IOException {
buffer.put((byte) b);
}
@Override
public void flush() {
/*
* empty.
*/
}
@Override
public void close() {
/*
* empty.
*/
}
/**
* Gets the buffer.
* @return The buffer.
*/
public ByteBuffer getBuffer() {
return buffer;
}
}
@@ -0,0 +1,181 @@
package core.cache.misc.buffer;
import java.io.ObjectInputStream;
import java.nio.ByteBuffer;
/**
* Holds utility methods for reading/writing a byte buffer.
* @author Emperor
*/
public final class ByteBufferUtils {
/**
* Gets a string from the byte buffer.
* @param buffer The byte buffer.
* @return The string.
*/
public static String getString(ByteBuffer buffer) {
StringBuilder sb = new StringBuilder();
byte b;
while ((b = buffer.get()) != 0) {
sb.append((char) b);
}
return sb.toString();
}
/**
* Puts a string on the byte buffer.
* @param s The string to put.
* @param buffer The byte buffer.
*/
public static void putString(String s, ByteBuffer buffer) {
buffer.put(s.getBytes()).put((byte) 0);
}
/**
* Gets a string from the byte buffer.
* @param s The string.
* @param buffer The byte buffer.
* @return The string.
*/
public static ByteBuffer putGJ2String(String s, ByteBuffer buffer) {
byte[] packed = new byte[256];
int length = packGJString2(0, packed, s);
return buffer.put((byte) 0).put(packed, 0, length).put((byte) 0);
}
/**
* Decodes the XTEA encryption.
* @param keys The keys.
* @param start The start index.
* @param end The end index.
* @param buffer The byte buffer.
*/
public static void decodeXTEA(int[] keys, int start, int end, ByteBuffer buffer) {
int l = buffer.position();
buffer.position(start);
int length = (end - start) / 8;
for (int i = 0; i < length; i++) {
int firstInt = buffer.getInt();
int secondInt = buffer.getInt();
int sum = 0xc6ef3720;
int delta = 0x9e3779b9;
for (int j = 32; j-- > 0;) {
secondInt -= keys[(sum & 0x1c84) >>> 11] + sum ^ (firstInt >>> 5 ^ firstInt << 4) + firstInt;
sum -= delta;
firstInt -= (secondInt >>> 5 ^ secondInt << 4) + secondInt ^ keys[sum & 3] + sum;
}
buffer.position(buffer.position() - 8);
buffer.putInt(firstInt);
buffer.putInt(secondInt);
}
buffer.position(l);
}
/**
* Converts a String to an Integer?
* @param position The position.
* @param buffer The buffer used.
* @param string The String to convert.
* @return The Integer.
*/
public static int packGJString2(int position, byte[] buffer, String string) {
int length = string.length();
int offset = position;
for (int i = 0; length > i; i++) {
int character = string.charAt(i);
if (character > 127) {
if (character > 2047) {
buffer[offset++] = (byte) ((character | 919275) >> 12);
buffer[offset++] = (byte) (128 | ((character >> 6) & 63));
buffer[offset++] = (byte) (128 | (character & 63));
} else {
buffer[offset++] = (byte) ((character | 12309) >> 6);
buffer[offset++] = (byte) (128 | (character & 63));
}
} else
buffer[offset++] = (byte) character;
}
return offset - position;
}
/**
* Gets a tri-byte from the buffer.
* @param buffer The buffer.
* @return The value.
*/
public static int getTriByte(ByteBuffer buffer) {
return ((buffer.get() & 0xFF) << 16) + ((buffer.get() & 0xFF) << 8) + (buffer.get() & 0xFF);
}
/**
* Gets a smart from the buffer.
* @param buffer The buffer.
* @return The value.
*/
public static int getSmart(ByteBuffer buffer) {
int peek = buffer.get() & 0xFF;
if (peek <= Byte.MAX_VALUE) {
return peek;
}
return ((peek << 8) | (buffer.get() & 0xFF)) - 32768;
}
/**
* Gets a smart from the buffer.
* @param buffer The buffer.
* @return The value.
*/
public static int getBigSmart(ByteBuffer buffer) {
int value = 0;
int current = getSmart(buffer);
while (current == 32767) {
current = getSmart(buffer);
value += 32767;
}
value += current;
return value;
}
/* *//**
* Writes an object on the buffer.
* @param buffer The buffer to write on.
* @param o The object.
*/
/*
* public static void putObject(ByteBuffer buffer, Object o) { ByteBuffer b;
* try (ObjectOutputStream out = new ObjectOutputStream(new
* BufferOutputStream(b = ByteBuffer.allocate(99999)))) {
* out.writeObject(o); b.flip(); } catch (Throwable e) {
* e.printStackTrace(); b = (ByteBuffer) ByteBuffer.allocate(0).flip(); }
* buffer.putInt(b.remaining()); if (b.remaining() > 0) { buffer.put(b); } }
*/
/**
* Gets an object from the byte buffer.
* @param buffer The buffer.
* @return The object.
*/
public static Object getObject(ByteBuffer buffer) {
int length = buffer.getInt();
if (length > 0) {
byte[] bytes = new byte[length];
buffer.get(bytes);
try (ObjectInputStream str = new ObjectInputStream(new BufferInputStream(ByteBuffer.wrap(bytes)))) {
return (Object) str.readObject();
} catch (Throwable e) {
e.printStackTrace();
}
}
return null;
}
/**
* Constructs a new {@code ByteBufferUtils} {@code Object}.
*/
private ByteBufferUtils() {
/*
* empty.
*/
}
}