diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2167045f3..0a528e0cb 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -25,7 +25,7 @@ steps: gradleWrapperFile: 'gradlew' gradleOptions: '-Xmx3072m -Dorg.gradle.parallel=true -Dorg.gradle.caching=true -Dsonar.host.url=https://sonarcloud.io' javaHomeOption: 'JDKVersion' - jdkVersionOption: '1.8' + jdkVersionOption: '11' jdkArchitectureOption: 'x64' publishJUnitResults: true testResultsFiles: '**/TEST-*.xml' diff --git a/build.gradle b/build.gradle index c1756fcf0..daf4bce3a 100644 --- a/build.gradle +++ b/build.gradle @@ -15,6 +15,8 @@ allprojects { maven { url "https://repo.maven.apache.org/maven2" } maven { url "https://dl.bintray.com/kotlin/kotlinx/" } } + + } apply from: 'gradle/properties.gradle' diff --git a/cache/build.gradle b/cache/build.gradle index af79e12dd..95d2e1f72 100644 --- a/cache/build.gradle +++ b/cache/build.gradle @@ -5,6 +5,10 @@ description = 'Apollo Cache' dependencies { implementation project(':util') implementation group: 'com.google.guava', name: 'guava', version: guavaVersion + implementation group: 'org.tukaani', name: 'xz', version: '1.8' + implementation group: 'it.unimi.dsi', name: 'fastutil', version: '8.3.1' + implementation group: 'org.apache.ant', name: 'ant', version: '1.10.7' + implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.11.0.rc1' test.useJUnitPlatform() testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitJupiterVersion diff --git a/cache/src/main/java/org/apollo/cache/Archive.java b/cache/src/main/java/org/apollo/cache/Archive.java new file mode 100644 index 000000000..e3ece280f --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/Archive.java @@ -0,0 +1,595 @@ +package org.apollo.cache; + +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectCollection; + +import java.util.Comparator; + +public class Archive { + + /** + * Underlying cache. + */ + private Cache cache; + /** + * Contains ID of the file system. + */ + private int id; + + /** + * Wheter to use automatic version incrementor. + */ + private boolean useAutomaticVersionIncremetor = true; + + /** + * Contains all groups by id. + */ + private Int2ObjectLinkedOpenHashMap folders; + + /** + * Contains all groups by name. + */ + private Int2IntOpenHashMap foldersByName; + + /** + * Wheter whirlpool hashes are used. + */ + private boolean useWhirlpool; + /** + * Wheter names are used. + */ + private boolean useNames; + + /** + * Whether compression lenths are used. + */ + private boolean useCompressionLengths; + + /** + * Whether flag8 is used. + */ + private boolean useFlag8; + + /** + * Version of this file system. + */ + private int version; + /** + * CRC32 of this file system. + */ + private int crc; + /** + * 64byte whirlpool digest + * of this file system. + */ + private byte[] digest; + + /** + * Contains packed filesystem file + * which was provided with load() call. + */ + private CacheBuffer packed; + /** + * Wheter any changes were made to + * file system properties such as version or properties. + */ + private boolean changed; + + private int protocol = 7; + + public Archive(int id, Cache cache) { + this.id = id; + this.cache = cache; + } + + /** + * Tries to load this file system from cache. + */ + public void load() { + //if (isLoaded()) + // throw new RuntimeException("Already loaded!"); + CacheBuffer buffer = cache.getMasterIndex().get(id); + if (buffer == null) throw new RuntimeException("Missing filesystem file."); + + CacheBuffer unpacked = Helper.decodeFITContainer(buffer); + + unpacked.setPosition(0); + + protocol = unpacked.readUByte(); + if (protocol >= 6) version = unpacked.readInt(); + + int properties = unpacked.readUByte(); + useNames = (properties & 0x1) != 0; + useWhirlpool = (properties & 0x2) != 0; + useCompressionLengths = (properties & 0x4) != 0; + useFlag8 = (properties & 0x8) != 0; + + int foldersLength = protocol >= 7 ? unpacked.readSmart32() : unpacked.readUShort(); + folders = new Int2ObjectLinkedOpenHashMap<>(); + foldersByName = new Int2IntOpenHashMap(); + + int[] folderIDS = new int[foldersLength]; + int[] folderNames = new int[foldersLength]; + int[] folderCRCS = new int[foldersLength]; + byte[][] folderDigests = new byte[foldersLength][64]; + int[] folderVersions = new int[foldersLength]; + int[][] folderFilesIDS = new int[foldersLength][]; + int[][] folderFilesNames = new int[foldersLength][]; + + for (int offset = 0, i = 0; i < foldersLength; i++) + folderIDS[i] = offset += (protocol >= 7 ? unpacked.readSmart32() : unpacked.readUShort()); + + for (int i = 0; i < foldersLength; i++) + folderNames[i] = useNames ? unpacked.readInt() : -1; + + for (int i = 0; i < foldersLength; i++) + folderCRCS[i] = unpacked.readInt(); + + if (useWhirlpool) { + for (int i = 0; i < foldersLength; i++) + unpacked.readBytes(folderDigests[i], 0, 64); + } + + for (int i = 0; i < foldersLength; i++) + folderVersions[i] = unpacked.readInt(); + + for (int i = 0; i < foldersLength; i++) { + int filesCount = protocol >= 7 ? unpacked.readSmart32() : unpacked.readUShort(); + folderFilesIDS[i] = new int[filesCount]; + folderFilesNames[i] = new int[filesCount]; + } + + for (int i = 0; i < foldersLength; i++) + for (int offset = 0, a = 0; a < folderFilesIDS[i].length; a++) + folderFilesIDS[i][a] = offset += (protocol >= 7 ? unpacked.readSmart32() : unpacked.readUShort()); + + for (int i = 0; i < foldersLength; i++) + for (int a = 0; a < folderFilesIDS[i].length; a++) + folderFilesNames[i][a] = useNames ? unpacked.readInt() : -1; + + for (int i = 0; i < foldersLength; i++) { + var folder = new Group(folderIDS[i], folderNames[i], folderVersions[i], folderCRCS[i], folderDigests[i], + folderFilesIDS[i], folderFilesNames[i]); + folders.put(folder.getID(), folder); + if (folder.hasName()) { + foldersByName.put(folder.getName(), folder.getID()); + } + } + + updateHashes(buffer); + + packed = buffer; + } + + /** + * Delete's all folders on this filesystem. + * Reset's version to 0. + */ + public void reset() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + changed = true; + folders.clear(); + version = 0; + } + + + /** + * Finishe's any changes to this filesystem. + */ + public void finish() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + if (!needsRepack()) return; + + for (var folder : folders.values()) { + if (folder.isFileSystemInfoChanged()) { + if (useAutomaticVersionIncremetor) folder.setVersion(folder.getVersion() + 1); + CacheBuffer buffer = folder.finish(); + if (!cache.getIndex(id).put(folder.getID(), buffer, buffer.getBuffer().length)) { + throw new RuntimeException("Couldn't update folder:" + folder); + } + } + } + + + if (useAutomaticVersionIncremetor) version++; + + packed = pack(); + updateHashes(packed); + + if (!cache.getMasterIndex().put(id, packed, packed.getBuffer().length)) { + throw new RuntimeException("Couldn't update packed filesystem."); + } + + changed = false; + for (var folder : folders.values()) + folder.markFileSystemInfoAsNotChanged(); + } + + /** + * Pack's this filesystem. + */ + public CacheBuffer pack() { + CacheBuffer pack = new CacheBuffer(0); + + pack.writeByte(protocol); + if (protocol >= 6) pack.writeInt(version); + + pack.writeByte((useNames ? 0x1 : 0x0) | (useWhirlpool ? 0x2 : 0x0)); + + var foldersLength = foldersSize(); + if (protocol >= 7) { + pack.writeSmart32(foldersLength); + } else { + pack.writeShort(foldersLength); + } + + var foldersSorted = folders.values().parallelStream().sorted(Comparator.comparingInt(Group::getID)) + .toArray(Group[]::new); + { + int delta = 0; + for (var folder : foldersSorted) { + if (protocol >= 7) { + pack.writeSmart32(folder.getID() - delta); + } else { + pack.writeShort(folder.getID() - delta); + } + delta = folder.getID(); + } + } + + + if (useNames) { + for (var folder : foldersSorted) + pack.writeInt(folder.getName()); + } + + for (var folder : foldersSorted) + pack.writeInt(folder.getCRC32()); + + if (useWhirlpool) { + for (var folder : foldersSorted) + pack.writeBytes(folder.getDigest(), 0, 64); + } + + for (var folder : foldersSorted) + pack.writeInt(folder.getVersion()); + + for (var folder : foldersSorted) + if (protocol >= 7) { + pack.writeSmart32(folder.filesCount()); + } else { + pack.writeShort(folder.filesCount()); + } + + for (var folder : foldersSorted) { + int delta = 0; + var sortedFiles = folder.getRSFiles().parallelStream().sorted(Comparator.comparingInt(RSFile::getID)) + .toArray(RSFile[]::new); + for (var file : sortedFiles) { + if (protocol >= 7) { + pack.writeSmart32(file.getID() - delta); + } else { + pack.writeShort(file.getID() - delta); + } + delta = file.getID(); + } + } + + if (useNames) { + for (var folder : foldersSorted) { + var sortedFiles = folder.getRSFiles().parallelStream().sorted(Comparator.comparingInt(RSFile::getID)) + .toArray(RSFile[]::new); + for (var file : sortedFiles) { + pack.writeInt(file.getName()); + } + } + } + + return Helper.encodeFITContainer(new CacheBuffer(pack.toArray(0, pack.getPosition())), version).trim(); + } + + /** + * Find's folder by id. Returns null if none found. + */ + public Group findFolderByID(int id) { + return findFolderByID(id, null); + } + + /** + * Find's folder by id. Returns null if none found. + */ + public Group findFolderByID(int id, int[] xtea) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + var folder = folders.get(id); + if (folder == null) { + return null; + } else if (folder.isLoaded()) { + return folder; + } + + CacheBuffer data = cache.getIndex(this.id).get(id); + if (data == null) throw new RuntimeException("Missing folder:" + id); + folder.load(data, xtea); + + return folder; + } + + /** + * Find's folder by name. Returns null if none found. + */ + public Group findFolderByName(String name) { + return findFolderByName(name, null); + } + + /** + * Find's folder by name. Returns null if none found. + */ + public Group findFolderByName(int name) { + return findFolderByName(name, null); + } + + /** + * Find's folder by name. Returns null if none found. + */ + public Group findFolderByName(String name, int[] xtea) { + return findFolderByName(Helper.strToI(name), xtea); + } + + /** + * Find's folder by name. Returns null if none found. + */ + public Group findFolderByName(int name, int[] xtea) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + if (name == -1) return null; + + var folder = folders.get(foldersByName.getOrDefault(name, -1)); + if (folder == null) { + return null; + } else if (folder.isLoaded()) { + return folder; + } + + CacheBuffer data = cache.getIndex(this.id).get(folder.getID()); + if (data == null) throw new RuntimeException("Missing folder:" + folder.getID()); + folder.load(data, xtea); + + return folder; + } + + /** + * Add's new folder to this filesystem. If there's already a folder with + * same id then it get's overwriten. + */ + public void addFolder(Group group) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + if (!group.isLoaded()) throw new RuntimeException("folder is not loaded."); + + if (group.getID() == -1) group.setID(getFreeFolderID()); + folders.put(group.getID(), group); + if (group.hasName()) { + foldersByName.put(group.getName(), group.getID()); + } + group.markFileSystemInfoAsChanged(); // cause it needs to be packed to store. + changed = true; + } + + /** + * Delete's given folder. + */ + public void deleteFolder(Group group) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + folders.remove(group.getID()); + foldersByName.remove(group.getID()); + changed = true; + } + + /** + * Delete's all folders in this fs. + */ + public void deleteAllFolders() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + folders.clear(); + changed = true; + } + + /** + * Load's folder if it's not yet loaded. + */ + public void load(Group group) { + load(group, null); + } + + /** + * Load's folder if it's not yet loaded. + */ + public void load(Group group, int[] xtea) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + if (!folders.containsKey(group.getID())) { + return; + } else if (group.isLoaded()) { + return; + } else if (group.getID() == -1) { + return; + } + CacheBuffer data = cache.getIndex(id).get(group.getID()); + if (data == null) throw new RuntimeException("Missing folder:" + group.getID()); + group.load(data, xtea); + } + + /** + * Finishe's any pending caches on this filesystem and then unload's some + * buffered files. + */ + public void unloadCachedFiles() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + finish(); + for (var folder : folders.values()) + if (folder.isLoaded()) folder.unload(); + } + + /** + * Returns highest folder id. + */ + public int getHighestId() { + return getFreeFolderID() - 1; + } + + public int size() { + if (folders.isEmpty()) { + return 0; + } + + return getHighestId() + 1; + } + + /** + * Get's free folder ID. + */ + private int getFreeFolderID() { + if (folders.isEmpty()) return 0; + int highest = -1; + for (var folder : folders.values()) + if (folder.getID() > highest) highest = folder.getID(); + return highest + 1; + } + + /** + * Update's crc32 and whirlpool hash to one's from given buffer. + */ + private void updateHashes(CacheBuffer packed) { + crc = Helper.crc32(packed, 0, packed.getBuffer().length); + digest = Whirlpool.whirlpool(packed.getBuffer(), 0, packed.getBuffer().length); + } + + + /** + * Wheter this filesystem is loaded. + */ + public boolean isLoaded() { + return packed != null; + } + + /** + * Wheter file system file needs repack. + */ + private boolean needsRepack() { + if (changed) return true; + for (var folder : folders.values()) + if (folder.isFileSystemInfoChanged()) return true; + return false; + } + + /** + * Get's ID of this filesystem. + */ + public int getID() { + return id; + } + + /** + * Wheter this filesystem uses names. + */ + public boolean usesNames() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + return useNames; + } + + /** + * Wheter this filesystem uses whirlpool. + */ + public boolean usesWhirlpool() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + return useWhirlpool; + } + + /** + * Set's wheter this filesystem uses names. + */ + public void setUsesNames(boolean uses) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + if (this.useNames != uses) { + changed = true; + this.useNames = uses; + } + } + + /** + * Set's wheter this filesystem uses whirlpool. + */ + public void setUsesWhirlpool(boolean uses) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + if (this.useWhirlpool != uses) { + changed = true; + this.useWhirlpool = uses; + } + } + + /** + * Get's version of this filesystem. + */ + public int getVersion() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + return version; + } + + /** + * Set's version of this filesystem. + */ + public void setVersion(int version) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + if (this.version != version) { + changed = true; + this.version = version; + } + } + + /** + * Get's crc32 of packed version of this filesystem. + */ + public int getCRC32() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + return crc; + } + + /** + * Get's whirlpool digest of packed version of this filesystem. + */ + public byte[] getDigest() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + return digest; + } + + /** + * Wheter versions are automatically incremented each time finish() is + * called. + */ + public boolean usingAutomaticVersionsIncremetor() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + return useAutomaticVersionIncremetor; + } + + + /** + * Set's wheter to use automatic versions incrementor. + */ + public void setUseAutomaticVersionsIncremetor(boolean use) { + if (!isLoaded()) throw new RuntimeException("Using nonloaded filesystem."); + this.useAutomaticVersionIncremetor = use; + } + + /** + * Get's all folders. + * Returned folders array can't be modified + * in any way. + * + * @return + */ + public ObjectCollection getFolders() { + return folders.values(); + } + + public int foldersSize() { + return folders.size(); + } +} diff --git a/cache/src/main/java/org/apollo/cache/Cache.java b/cache/src/main/java/org/apollo/cache/Cache.java new file mode 100644 index 000000000..a358a6d93 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/Cache.java @@ -0,0 +1,253 @@ +package org.apollo.cache; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.math.BigInteger; +import java.nio.file.Path; + + +public class Cache { + + private static final String DATA_FILE = "main_file_cache.dat2"; + private static final String INDEX_FILE = "main_file_cache.idx"; + + private Index[] indexes; + private Index masterIndex; + private Archive[] archives; + private int[] crcs; + + private Cache(String path) { + openFiles(path); + } + + @SuppressWarnings("resource") + private final void openFiles(String path) { + try { + String seperator = System.getProperty("file.separator", "/"); + + RandomAccessFile dataFile = new RandomAccessFile(path + seperator + DATA_FILE, "rw"); + + RandomAccessFile referenceFile = new RandomAccessFile(path + seperator + INDEX_FILE + "255", "rw"); + masterIndex = new Index(255, dataFile.getChannel(), referenceFile.getChannel(), 0x20000000); + + int numIndices = masterIndex.getFileCount(); + indexes = new Index[numIndices]; + archives = new Archive[numIndices]; + for (int i = 0; i < numIndices; i++) { + RandomAccessFile indexFile = new RandomAccessFile(path + seperator + INDEX_FILE + i, "rw"); + indexes[i] = new Index(i, dataFile.getChannel(), indexFile.getChannel(), 0x10000000); + if (masterIndex.get(i) != null) archives[i] = new Archive(i, this); + } + + crcs = new int[numIndices]; + for (int i = 0; i < archives.length; i++) { + var archive = getArchive(i); + crcs[i] = archive == null ? 0 : archive.getCRC32(); + } + } catch (IOException ioex) { + ioex.printStackTrace(); + } + } + + /** + * Finishing all pending operations. + */ + public void flush() { + if (archives == null) throw new RuntimeException("Cache is closed."); + for (int i = 0; i < archives.length; i++) + if (archives[i] != null && archives[i].isLoaded()) archives[i].finish(); + } + + /** + * Finishing all pending operations then + * Closes cache and disposes all data. + * Calling close() on closed cache has no effect. + */ + public void close() { + if (indexes == null) return; // closed cache + flush(); + for (int i = 0; i < indexes.length; i++) + indexes[i].close(); + masterIndex.close(); + + archives = null; + indexes = null; + masterIndex = null; + } + + /** + * Closes cache without finishing all pending operations. + */ + public void closeDiscard() { + if (indexes == null) return; // closed cache + + for (int i = 0; i < indexes.length; i++) + indexes[i].close(); + masterIndex.close(); + + archives = null; + indexes = null; + masterIndex = null; + } + + + /** + * Opens cache at given path. + * + * @param path Folder where cache is located. + * @return Opened cache or null if something failed. + */ + public static Cache openCache(String path) { + return new Cache(path); + } + + public static Cache openCache(Path path) { + return new Cache(path.toString()); + } + + + /** + * Create's new cache on given path. + * + * @param path Folder where to create new cache. + * @param indicesCount Count of indices , can't be lower than 0 or higher than 254. + * @return Created cache or null if something failed. + */ + @SuppressWarnings("resource") + public static Cache createNewCache(String path, int indicesCount) { + if (indicesCount < 0 || indicesCount > 254) return null; + + File file = new File(path); + if (file.isFile()) return null; + + if (!file.exists()) file.mkdirs(); + + if (!file.isDirectory()) return null; + + try { + String seperator = System.getProperty("file.separator", "/"); + File data = new File(path + seperator + DATA_FILE); + if (data.exists() || !data.createNewFile() || !data.canWrite() || !data.canRead()) return null; + + for (int i = 0; i < indicesCount; i++) { + File index = new File(path + seperator + INDEX_FILE + i); + if (index.exists() || !index.createNewFile() || !index.canWrite() || !data.canRead()) return null; + } + + File index255 = new File(path + seperator + INDEX_FILE + "255"); + if (index255.exists() || !index255.createNewFile() || !index255.canWrite() || !index255.canRead()) { + return null; + } + + RandomAccessFile dataFile = new RandomAccessFile(path + seperator + DATA_FILE, "rw"); + RandomAccessFile referenceFile = new RandomAccessFile(path + seperator + INDEX_FILE + "255", "rw"); + Index store_255 = new Index(255, dataFile.getChannel(), referenceFile.getChannel(), 0x7a120); + + for (int i = 0; i < indicesCount; i++) { + byte[] pdata = Helper.encodeFITContainer(new byte[]{5, 0, 0, 0}, + 0); // empty fs (protocol 5, props 0, folders count - 0) + store_255.put(i, new CacheBuffer(pdata), pdata.length); + } + + dataFile.getChannel().close(); + referenceFile.getChannel().close(); + return new Cache(path); + } catch (IOException ex) { + ex.printStackTrace(); + return null; + } + + } + + + /** + * Get's specific file store. + * Returns null if store is not available in this cache. + * Note:Using this method to get information store (idx255) results in + * null return, use getInformationStore() instead. + */ + public Index getIndex(int id) { + if (indexes == null) throw new RuntimeException("Cache is closed."); + if (id < 0 || id >= indexes.length) return null; + return indexes[id]; + } + + /** + * Get's specific file system. + * If it's not loaded then it loads it. + */ + public Archive getArchive(int id) { + if (archives == null) throw new RuntimeException("Cache is closed."); + if (id < 0 || id >= archives.length || archives[id] == null) return null; + Archive system = archives[id]; + if (!system.isLoaded()) system.load(); + return system; + } + + /** + * Get's information about files store. + */ + public Index getMasterIndex() { + if (masterIndex == null) throw new RuntimeException("Cache is closed."); + return masterIndex; + } + + /** + * Get's count of indices in this cache. + */ + public int getIndicesCount() { + if (indexes == null) throw new RuntimeException("Cache is closed."); + return indexes.length; + } + + /** + * Get's an array of all index CRCs. + */ + public int[] getCrcs() { + if (indexes == null) throw new RuntimeException("Cache is closed."); + return crcs; + } + + public CacheBuffer generateInformationStoreDescriptor(boolean whirlpool) { + if (archives == null) + throw new RuntimeException("Cache is closed."); + for (int i = 0; i < archives.length; i++) + if (!archives[i].isLoaded()) + archives[i].load(); + flush(); + int indicesCount = getIndicesCount(); + CacheBuffer alloc = new CacheBuffer(whirlpool ? ((1 + (indicesCount * 72) + 1 + 64) * 10) : (256 * 8)); + if (whirlpool) + alloc.writeByte(indicesCount); + for (int i = 0; i < (whirlpool ? indicesCount : 256); i++) { + if (i >= archives.length) { + alloc.writeInt(0xCAFEBABE); + alloc.writeInt(0xBEEFBEEF); + continue; + } + alloc.writeInt(archives[i].getCRC32()); + alloc.writeInt(archives[i].getVersion()); + if (whirlpool) + alloc.writeBytes(archives[i].getDigest(), 0, 64); + } + if (whirlpool) { + byte[] selfDigest = Whirlpool.whirlpool(alloc.getBuffer(), 0, alloc.getPosition()); + CacheBuffer rsa = new CacheBuffer(65); + rsa.writeByte(10); + rsa.writeBytes(selfDigest, 0, 64); + BigInteger data = new BigInteger(rsa.getBuffer()); + byte[] encrypted = data.toByteArray(); + alloc.writeBytes(encrypted, 0, encrypted.length); + } + return Helper.encodeFITContainer(new CacheBuffer(alloc.toArray(0, alloc.getPosition())), 0, Helper.COMPRESSION_NONE); + } + + @Override + public void finalize() { + if (indexes != null) { + System.err.println("mgi.tools.jagcached.cache:Cache not closed."); + close(); + } + } +} diff --git a/cache/src/main/java/org/apollo/cache/CacheBuffer.java b/cache/src/main/java/org/apollo/cache/CacheBuffer.java new file mode 100644 index 000000000..67c489132 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/CacheBuffer.java @@ -0,0 +1,631 @@ +package org.apollo.cache; + +public class CacheBuffer { + + private static final int xteaDelta = 0x9E3779B9; + private static final int xteaRounds = 32; + + private int position; + public byte[] buffer; + private boolean dontExpand; + + public CacheBuffer() { + this(16); + } + + public CacheBuffer(byte[] data) { + this(data, 0); + } + + public CacheBuffer(int capacity) { + this.position = 0; + this.buffer = new byte[capacity]; + } + + public CacheBuffer(byte[] data, int position) { + this.position = position; + this.buffer = new byte[data.length]; + System.arraycopy(data, 0, buffer, 0, buffer.length); + } + + public void setDontExpand(boolean dontExpand) { + this.dontExpand = dontExpand; + } + + public final void xteaEncrypt(int[] keys, int offset, int length) { + int originalPosition = this.position; + this.position = offset; + int numCycles = (length - offset) / 8; + for (int cycle = 0; cycle < numCycles; cycle++) { + int v0 = readInt(); + int v1 = readInt(); + int sum = 0; + int numRounds = xteaRounds; + while (numRounds-- > 0) { + v0 += (sum + keys[sum & 0x3] ^ (v1 << 4 ^ v1 >>> 5) + v1); + sum += xteaDelta; + v1 += (sum + keys[(sum & 0x1d2f) >>> 11] ^ v0 + (v0 << 4 ^ v0 >>> 5)); + } + this.position -= 8; + writeInt(v0); + writeInt(v1); + } + this.position = originalPosition; + } + + public final void xteaDecrypt(int[] keys, int start, int length) { + int l = position; + position = start; + int i1 = (length - start) / 8; + for (int j1 = 0; j1 < i1; j1++) { + position += 4; + int k1 = ((0xff & buffer[-3 + position]) << 16) + ((((0xff & buffer[-4 + position]) << 24) + ((buffer[-2 + position] & 0xff) << 8)) + (buffer[-1 + position] & 0xff)); + position += 4; + int l1 = ((0xff & buffer[-3 + position]) << 16) + ((((0xff & buffer[-4 + position]) << 24) + ((buffer[-2 + position] & 0xff) << 8)) + (buffer[-1 + position] & 0xff)); + int sum = 0xc6ef3720; + for (int k2 = 32; k2-- > 0; ) { + l1 -= keys[(sum & 0x1c84) >>> 11] + sum ^ (k1 >>> 5 ^ k1 << 4) + k1; + sum -= 0x9e3779b9; + k1 -= (l1 >>> 5 ^ l1 << 4) + l1 ^ keys[sum & 3] + sum; + } + + position -= 8; + buffer[position++] = (byte) (k1 >> 24); + buffer[position++] = (byte) (k1 >> 16); + buffer[position++] = (byte) (k1 >> 8); + buffer[position++] = (byte) k1; + buffer[position++] = (byte) (l1 >> 24); + buffer[position++] = (byte) (l1 >> 16); + buffer[position++] = (byte) (l1 >> 8); + buffer[position++] = (byte) l1; + } + position = l; + } + + public byte[] toArray(int offset, int length) { + byte[] bf = new byte[length - offset]; + for (int i = 0; i < length; i++) { + bf[i] = this.buffer[offset + i]; + } + return bf; + } + + public void setPosition(int position) { + this.position = position; + } + + public int getPosition() { + return position; + } + + public byte[] getBuffer() { + return buffer; + } + + public int getRemaining() { + int length = buffer.length; + return position < length ? length - position : 0; + } + + public void skip(int length) { + position += length; + } + + public int readByte() { + return getRemaining() > 0 ? buffer[position++] : 0; + } + + public byte readSignedByte() { + return (byte) readByte(); + } + + public int peekByte() { + return getRemaining() > 0 ? buffer[position] : 0; + } + + public void readBytes(byte buffer[]) { + readBytes(buffer, 0, buffer.length); + } + + public void readBytes(byte buffer[], int off, int len) { + for (int k = off; k < len + off; k++) { + buffer[k] = (byte) readByte(); + } + } + + public String readString() { + int startpos = position; + while (position < buffer.length && buffer[position++] != 0) { + } + int strlen = position - startpos - 1; + if (strlen <= 0) + return ""; + return StringUtilities.decodeString(buffer, startpos, strlen); + } + + public String readHttpHeaderString() { + int length = 0; + while ((position + length + 2) <= buffer.length && buffer[position + length + 0] != '\r' && buffer[position + length + 1] != '\n') + length++; + + if ((position + length + 2) > buffer.length) + return null; + + String str = new String(buffer, position, length); + position += length + 2; + return str; + } + + public String readVersionedString() { // aka JAG string getService you called it + return readVersionedString((byte) 0); + } + + public String readVersionedString(byte versionNumber) { + if (readByte() != versionNumber) + throw new IllegalStateException("Bad string version number!"); + return readString(); + } + + public String readNullString() { + if (peekByte() == 0) { + skip(1); + return null; + } + return readString(); + } + + public int readUMedInt() { + return (readUByte() << 16) + (readUByte() << 8) + (readUByte()); + } + + public int readUByte() { + return readByte() & 0xff; + } + + public int readByte128() { + return (byte) (readByte() - 128); + } + + public int readByteC() { + return (byte) -readByte(); + } + + public int read128Byte() { + return (byte) (128 - readByte()); + } + + public int readUByteA() { + return readUByte() - 128 & 0xff; + } + + public int readUByteC() { + return -readUByte() & 0xff; + } + + public int readUByteS() { + return 128 - readUByte() & 0xff; + } + + public int readSignedLEShort() { + int i = readUByte() + (readUByte() << 8); + if (i > 32767) { + i -= 0x10000; + } + return i; + } + + public int readSignedShortA() { + int i = (readUByte() << 8) + (readByte() - 128 & 0xff); + if (i > 32767) { + i -= 0x10000; + } + return i; + } + + public int readSignedLEShortA() { + int i = (readByte() - 128 & 0xff) + (readUByte() << 8); + if (i > 32767) { + i -= 0x10000; + } + return i; + } + + public int readSignedLEShortS() { + int i = (128 - readByte() & 0xff) + (readUByte() << 8); + if (i > 32767) { + i -= 0x10000; + } + return i; + } + + public int readSignedShort() { + int i = (readUByte() << 8) + readUByte(); + if (i > 32767) { + i -= 0x10000; + } + return i; + } + + public int readULEShort() { + return readUByte() + (readUByte() << 8); + } + + public int readUShort() { + return (readUByte() << 8) + readUByte(); + } + + public int readSignedSmart() { + int var2 = peekByte() & 0xff; + if (var2 < 128) { + return readUByte() - 64; + } + return readUShort() - 49152; + } + + public int readSmart32() { + if ((peekByte() ^ 0xffffffff) <= -1) { + int value = readUShort(); + if (value == 32767) { + return -1; + } + return value; + } + return readInt() & 0x7fffffff; + } + + public int readDecoratedSmart() { + int var2 = peekByte() & 0xff; + if (var2 < 128) { + return readUByte() - 1; + } + return readUShort() - 32769; + } + + public int readUnsignedShortA() { + return (readUByte() << 8) + (readByte() - 128 & 0xff); + } + + public int readUnsignedLEShortA() { + return (readByte() - 128 & 0xff) + (readUByte() << 8); + } + + public int readInt() { + return (readUByte() << 24) + (readUByte() << 16) + (readUByte() << 8) + readUByte(); + } + + public int readIntV1() { + return (readUByte() << 8) + readUByte() + (readUByte() << 24) + (readUByte() << 16); + } + + public int readIntV2() { + return (readUByte() << 16) + (readUByte() << 24) + readUByte() + (readUByte() << 8); + } + + public int readLEInt() { + return readUByte() + (readUByte() << 8) + (readUByte() << 16) + (readUByte() << 24); + } + + public long readLong() { + long l = readInt() & 0xffffffffL; + long l1 = readInt() & 0xffffffffL; + return (l << 32) + l1; + } + + public int readUnsignedSmart() { + int peak = peekByte() & 0xff; + if (peak < 128) + return readUByte(); + return readUShort() - 32768; + } + + public int readSmartLE() { + int peak = peekByte(); + if (peak <= Byte.MAX_VALUE && peak >= Byte.MIN_VALUE) + return readSignedByte(); + return readSignedLEShort() - 32768; + } + + public int readCustomInt() { + return (readUByte() << 24) + (readUByte() << 16) + (readUByte() << 8) + readUByte() + 128; + } + + public long readDynamic(int byteCount) { + if (--byteCount < 0 || byteCount > 7) { + throw new IllegalArgumentException(); + } + int bitposition = byteCount * 8; + long l = 0L; + for (/**/; bitposition >= 0; bitposition -= 8) { + + l |= (0xffL & readByte()) << bitposition; + } + return l; + } + + public int readHugeSmart() { + int value = 0; + int read; + for (read = readUnsignedSmart(); read == 32767; read = readUnsignedSmart()) { + value += 32767; + } + value += read; + return value; + } + + public void writeHugeSmart(int value) { + for (int i = 0; i < value / 0x7fff; i++) { + writeShort((short) 0xffff); + } + writeUnsignedSmart(value & 0x7fff); + } + + public float readFloat() { + return Float.intBitsToFloat(readInt()); + } + + public void expand(int position) { + if (dontExpand) { + return; + } + + int length = this.buffer.length; + if (position >= length) { + byte[] newBuffer = new byte[position + 1000]; + System.arraycopy(buffer, 0, newBuffer, 0, length); + this.buffer = newBuffer; + } + } + + public void writeByte(int value, int position) { + expand(position); + buffer[position] = (byte) value; + } + + public void writeBytes(byte[] b, int offset, int length) { + expand(this.position + length - 1); + System.arraycopy(b, offset, buffer, this.position, length); + + this.position += length; + } + + public void writeBytes(byte[] b) { + expand(this.position + b.length - 1); + System.arraycopy(b, 0, buffer, this.position, b.length); + + this.position += b.length; + } + + public void writeBytes128Reverse(byte[] b) { + for (int i = b.length - 1; i >= 0; i--) + writeByteA(b[i]); + } + + public void writeBytesReverse(byte[] b) { + for (int i = b.length - 1; i >= 0; i--) + writeByte(b[i]); + } + + public void writeBytesA(byte[] buffer, int offset, int length) { + for (int index = offset; index < length; index++) { + writeByteA(buffer[index]); + } + } + + public void writeBytesA(byte[] buffer) { + writeBytesA(buffer, 0, buffer.length); + } + + public void writeVersionedString(String s) { + writeVersionedString(s, (byte) 0); + } + + public void writeVersionedString(String s, byte version) { + writeByte(version); + writeString(s); + } + + public void writeString(String s) { + int n = s.indexOf('\0'); + if (n >= 0) + throw new IllegalArgumentException("NUL character at " + n + "!"); + expand(position + s.length()); + position += StringUtilities.encodeString(buffer, position, s, 0, s.length()); + writeByte(0); + } + + public void writeByte(int value) { + writeByte(value, position++); + } + + public void writeByteA(int i) { + writeByte(i + 128); + } + + public void writeByteC(int i) { + writeByte(-i); + } + + public void writeByteS(int i) { + writeByte(128 - i); + } + + public void writeLEShortA(int i) { + writeByte(i + 128); + writeByte(i >> 8); + } + + public void writeShortA(int i) { + writeByte(i >> 8); + writeByte(i + 128); + } + + public void writeUnsignedSmart(int value) { + if (value < 128) + writeByte(value); + else if (value < 32768) + writeShort(value + 32768); + else + throw new IllegalArgumentException(); + } + + public void writeSmart32(int value) { + if ((value & 0xFFFF) < 32768) + writeShort(value); + else + writeInt(0x80000000 | value); + } + + public void writeShort(int value) { + writeByte(value >> 8); + writeByte(value); + } + + public void writeLEShort(int i) { + writeByte(i); + writeByte(i >> 8); + } + + public void writeMedInt(int i) { + writeByte(i >> 16); + writeByte(i >> 8); + writeByte(i); + } + + public void write24BitIntegerV2(int i) { + writeByte(i >> 16); + writeByte(i); + writeByte(i >> 8); + } + + public void write24BitIntegerV3(int i) { + writeByte(i); + writeByte(i >> 8); + writeByte(i >> 16); + } + + + public void writeInt(int i) { + writeByte(i >> 24); + writeByte(i >> 16); + writeByte(i >> 8); + writeByte(i); + } + + public void writeIntV1(int i) { + writeByte(i >> 8); + writeByte(i); + writeByte(i >> 24); + writeByte(i >> 16); + } + + public void writeIntV2(int i) { + writeByte(i >> 16); + writeByte(i >> 24); + writeByte(i); + writeByte(i >> 8); + } + + public void writeIntLE(int i) { + writeByte(i); + writeByte(i >> 8); + writeByte(i >> 16); + writeByte(i >> 24); + } + + public void writeLong(long l) { + writeByte((int) (l >> 56)); + writeByte((int) (l >> 48)); + writeByte((int) (l >> 40)); + writeByte((int) (l >> 32)); + writeByte((int) (l >> 24)); + writeByte((int) (l >> 16)); + writeByte((int) (l >> 8)); + writeByte((int) l); + } + + public void write5ByteInteger(long l) { + writeByte((int) (l >> 32)); + writeByte((int) (l >> 24)); + writeByte((int) (l >> 16)); + writeByte((int) (l >> 8)); + writeByte((int) l); + } + + public void writeDynamic(int bytes, long l) { + bytes--; + if (bytes < 0 || bytes > 7) { + throw new IllegalArgumentException(); + } + for (int shift = 8 * bytes; shift >= 0; shift -= 8) { + writeByte((int) (l >> shift)); + } + } + + public void writeFloat(float value) { + writeInt(Float.floatToIntBits(value)); + } + + public void writeBoolean(boolean condition) { + writeByte(condition ? 1 : 0); + } + + public void writeSignedSmart(int value) { + if (value < 64 && value >= -64) { + writeByte(value + 64); + return; + } + if (value < 16384 && value >= -16384) { + writeShort(value + 49152); + return; + } else { + System.out.println("Error psmart out of range: " + value); + return; + } + } + + public final int readVarSeized() { + int f = this.buffer[this.position++]; + int sum = 0; + for (; f < 0; f = this.buffer[this.position++]) + sum = (sum | f & 0x7f) << 7; + return sum | f; + } + + public final void writeVarSeized(int val) { + if ((val & ~0x7f) != 0) { + if ((val & ~0x3fff) != 0) { + if ((val & ~0x1fffff) != 0) { + if ((val & ~0xfffffff) != 0) + this.writeByte(val >>> 28 | 0x80); + this.writeByte((val | 0x100a2c1c) >>> 21); + } + this.writeByte(val >>> 14 | 0x80); + } + this.writeByte((val | 0x4021) >>> 7); + } + this.writeByte(val & 0x7f); + } + + public void writeMidiInt(int value) { + this.buffer[this.position - value - 4] = (byte) (value >> 24); + this.buffer[this.position - value - 3] = (byte) (value >> 16); + this.buffer[this.position - value - 2] = (byte) (value >> 8); + this.buffer[this.position - value - 1] = (byte) value; + } + + public byte getByte(int position) { + return buffer[position]; + } + + public void setByte(int value, byte position) { + buffer[position] = (byte) value; + } + + public CacheBuffer trim() { + return new CacheBuffer(toArray(0, position)); + } + + public boolean isEmpty() { + return buffer.length == 0; + } +} diff --git a/cache/src/main/java/org/apollo/cache/FileDescriptor.java b/cache/src/main/java/org/apollo/cache/FileDescriptor.java deleted file mode 100644 index e5df5b4e6..000000000 --- a/cache/src/main/java/org/apollo/cache/FileDescriptor.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.apollo.cache; - -import java.io.File; - -/** - * A class which points to a file in the cache. - * - * @author Graham - */ -public final class FileDescriptor { - - /** - * The file id. - */ - private final int file; - - /** - * The file type. - */ - private final int type; - - /** - * Creates the file descriptor. - * - * @param type The file type. - * @param file The file id. - */ - public FileDescriptor(int type, int file) { - this.type = type; - this.file = file; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof FileDescriptor) { - FileDescriptor other = (FileDescriptor) obj; - return type == other.type && file == other.file; - } - - return false; - } - - /** - * Gets the file id. - * - * @return The file id. - */ - public int getFile() { - return file; - } - - /** - * Gets the file type. - * - * @return The file type. - */ - public int getType() { - return type; - } - - @Override - public int hashCode() { - return file * FileSystemConstants.ARCHIVE_COUNT + type; - } - -} \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/FileSystemConstants.java b/cache/src/main/java/org/apollo/cache/FileSystemConstants.java deleted file mode 100644 index d0c523ba2..000000000 --- a/cache/src/main/java/org/apollo/cache/FileSystemConstants.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.apollo.cache; - -/** - * Holds file system related constants. - * - * @author Graham - */ -public final class FileSystemConstants { - - /** - * The number of archives in cache 0. - */ - public static final int ARCHIVE_COUNT = 9; - - /** - * The size of a chunk. - */ - public static final int CHUNK_SIZE = 512; - - /** - * The size of a header. - */ - public static final int HEADER_SIZE = 8; - - /** - * The size of a block. - */ - public static final int BLOCK_SIZE = HEADER_SIZE + CHUNK_SIZE; - - /** - * The size of an index. - */ - public static final int INDEX_SIZE = 6; - - /** - * Default private constructor to prevent instantiation. - */ - private FileSystemConstants() { - - } - -} \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/Group.java b/cache/src/main/java/org/apollo/cache/Group.java new file mode 100644 index 000000000..94e97b051 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/Group.java @@ -0,0 +1,593 @@ +package org.apollo.cache; + +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectLinkedOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectCollection; + +import java.util.Comparator; + +public class Group { + + /** + * Contains ID of the folder. + */ + private int id; + /** + * Contains name hash of this folder. + */ + private int name; + /** + * Contains version of packed folder file. + */ + private int version; + + /** + * Contains crc of packed folder file. + */ + private int crc; + /** + * Contains 64-byte whirlpool digest. + */ + private byte[] digest; + + private Int2ObjectLinkedOpenHashMap files; + private Int2IntOpenHashMap filesByName; + + /** + * Contains packed files buffer + * which was provided with load() call. + */ + private CacheBuffer packedFiles; + /** + * Contains xtea keys. (int[4]) + * Can be null. + */ + private int[] xtea; + /** + * Wheter any changes were made. + */ + private boolean needsRepack; + /** + * Wheter any of those things changed (id,name,version,crc,digest,files and their data). + */ + private boolean fileSystemInfoChanged; + + /** + * Constructor for copy() methods. + */ + private Group() { + + } + + /** + * Create's new folder with autoassigned id from given data. + * Each file must have it's buffer attached. + */ + public Group(Int2ObjectLinkedOpenHashMap files) { + this(-1, -1, 0, files); + } + + /** + * Create's new folder with autoassigned id from given data. + * Each file must have it's buffer attached. + */ + public Group(String name, int version, Int2ObjectLinkedOpenHashMap files) { + this(-1, Helper.strToI(name), version, files); + } + + /** + * Create's new folder with autoassigned id from given data. + * Each file must have it's buffer attached. + */ + public Group(int name, int version, Int2ObjectLinkedOpenHashMap files) { + this(-1, name, version, files); + } + + /** + * Create's new folder from given data. + * Each file must have it's buffer attached. + */ + public Group(int folderID, String name, int version, Int2ObjectLinkedOpenHashMap files) { + this(folderID, Helper.strToI(name), version, files); + } + + /** + * Create's new folder from given data. + * Each file must have it's buffer attached. + */ + public Group(int folderID, int name, int version, Int2ObjectLinkedOpenHashMap files) { + this.id = folderID; + this.name = name; + this.version = version; + this.files = files; + for (var file : files.values()) { + if (file.getID() != -1) { + continue; + } + file.setID(getRSFreeFileID()); + } + this.filesByName = new Int2IntOpenHashMap(); + updateHashes(this.packedFiles = pack()); + } + + /** + * Create's new unloaded folder from given FIT data. + */ + public Group(int folderID, int name, int version, int crc32, byte[] digest, int[] filesIDS, int[] filesNames) { + if (digest.length != 64 || filesIDS.length != filesNames.length) { + throw new RuntimeException("Invalid data provided."); + } + this.id = folderID; + this.name = name; + this.version = version; + this.crc = crc32; + this.digest = digest; + this.files = new Int2ObjectLinkedOpenHashMap<>(filesIDS.length);//[filesIDS.length]; + this.filesByName = new Int2IntOpenHashMap(); + for (int i = 0; i < filesIDS.length; i++) { + var file = new RSFile(filesIDS[i], filesNames[i]); + files.put(file.getID(), file); + if (file.hasName()) { + filesByName.put(file.getName(), file.getID()); + } + } + } + + /** + * Copy's this folder and every file in it. + */ + public Group copy() { + Group copy = new Group(); + copy.id = id; + copy.name = name; + copy.version = version; + copy.crc = crc; + if (digest != null) { + copy.digest = new byte[64]; + System.arraycopy(digest, 0, copy.digest, 0, 64); + } + if (files != null) { + copy.files = new Int2ObjectLinkedOpenHashMap<>(files.size()); + for (var file : files.values()) { + copy.files.put(file.getID(), file.copy()); + } + } + if (filesByName != null) { + copy.filesByName = new Int2IntOpenHashMap(); + for (int file : filesByName.values()) { + copy.filesByName.put(file, filesByName.get(file)); + } + } + if (packedFiles != null) { + copy.packedFiles = new CacheBuffer(packedFiles.toArray(0, packedFiles.getBuffer().length), + packedFiles.getPosition()); + } + if (xtea != null) { + copy.xtea = new int[4]; + System.arraycopy(xtea, 0, copy.xtea, 0, 4); + } + copy.needsRepack = needsRepack; + copy.fileSystemInfoChanged = fileSystemInfoChanged; + return copy; + } + + + /** + * Load's packed folder file. + */ + public void load(CacheBuffer packedFiles) { + load(packedFiles, null); + } + + /** + * Unload's this folder , can be called + * only by filesystem unloadCachedData() method. + */ + public void unload() { + if (!isLoaded()) throw new RuntimeException("Using nonloaded folder."); + packedFiles = null; + for (var file : files.values()) { + file.unload(); + } + } + + /** + * Load's packed folder file. + */ + public void load(CacheBuffer packedFiles, int[] xtea) { + if (isLoaded()) throw new RuntimeException("Already loaded."); + this.packedFiles = packedFiles; + this.xtea = xtea; + unpack(packedFiles); + } + + + /** + * Finishe's any changes by generating new packedFiles buffer and updating hashes + * if something was changed. + */ + public CacheBuffer finish() { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + + if (needsRepack()) { + //sortFiles(); + packedFiles = pack(); + updateHashes(packedFiles); + markAsNotNeedRepack(); + return packedFiles; + } + return packedFiles; + } + + /** + * Unpack's given packed files buffer. + */ + @SuppressWarnings("Duplicates") + private void unpack(CacheBuffer packed) { + if (xtea != null && xtea[0] != 0 && xtea[1] != 0 && xtea[2] != 0 && xtea[3] != 0) { + Helper.decryptContainer(packed, xtea); + } + + packed = Helper.decodeFilesContainer(packed); + + if (filesCount() <= 1) { + if (filesCount() <= 0) return; + CacheBuffer copy = new CacheBuffer(packed.getBuffer().length); + copy.writeBytes(packed.getBuffer(), 0, packed.getBuffer().length); + files.get(files.firstIntKey()).load(copy); + return; + } + + int sectorsCount = packed.getBuffer()[packed.getBuffer().length - 1] & 0xFF; + int[] lengths = new int[filesCount()]; + packed.setPosition(packed.getBuffer().length - ((sectorsCount * filesCount() * 4) + 1)); + for (int sectorID = 0; sectorID < sectorsCount; sectorID++) { + for (int i = 0, length = 0; i < filesCount(); i++) { + lengths[i] += (length += packed.readInt()); + } + } + int index = 0; + var sortedFiles = files.values().parallelStream().sorted(Comparator.comparingInt(RSFile::getID)) + .toArray(RSFile[]::new); + for (var file : sortedFiles) { + file.load(new CacheBuffer(lengths[index])); + lengths[index++] = 0; + } + packed.setPosition(packed.getBuffer().length - ((sectorsCount * filesCount() * 4) + 1)); + for (int fRead = 0, sectorID = 0; sectorID < sectorsCount; sectorID++) { + int length = 0; + int counter = 0; + for (var file : sortedFiles) { + length += packed.readInt(); + System.arraycopy(packed.getBuffer(), fRead, file.getData().getBuffer(), lengths[counter], length); + lengths[counter++] += length; + fRead += length; + } + } + + } + + /** + * Pack's unpacked files. + */ + private CacheBuffer pack() { + if (filesCount() <= 1) { + if (filesCount() <= 0) { + CacheBuffer container = Helper.encodeFilesContainer(new CacheBuffer(new byte[0]), version); + if (xtea != null && xtea[0] != 0 && xtea[1] != 0 && xtea[2] != 0 && xtea[3] != 0) { + Helper.encryptContainer(container, xtea); + } + return container.trim(); + } + var firstFile = files.get(files.firstIntKey()); + CacheBuffer packed = new CacheBuffer(firstFile.getData().getBuffer().length); + packed.writeBytes(firstFile.getData().getBuffer(), 0, firstFile.getData().getBuffer().length); + CacheBuffer container = Helper.encodeFilesContainer(packed, version); + if (xtea != null && xtea[0] != 0 && xtea[1] != 0 && xtea[2] != 0 && xtea[3] != 0) { + Helper.encryptContainer(container, xtea); + } + return container.trim(); + } + var sortedFiles = files.values().parallelStream().sorted(Comparator.comparingInt(RSFile::getID)) + .toArray(RSFile[]::new); + int allocLength = 1 + (4 * filesCount()); // sector header + for (var file : sortedFiles) + allocLength += file.getData().getBuffer().length; + CacheBuffer packed = new CacheBuffer(allocLength); + for (var file : sortedFiles) { + packed.writeBytes(file.getData().getBuffer(), 0, file.getData().getBuffer().length); + } + + var lengthOffset = 0; + for (var file : sortedFiles) { + var length = file.getData().getBuffer().length; + packed.writeInt(length - lengthOffset); + lengthOffset += length - lengthOffset; + } + packed.writeByte(1); // 1 sector + CacheBuffer container = Helper.encodeFilesContainer(packed, version); + if (xtea != null && xtea[0] != 0 && xtea[1] != 0 && xtea[2] != 0 && xtea[3] != 0) { + Helper.encryptContainer(container, xtea); + } + return container.trim(); + } + + /** + * Update's crc32 and whirlpool hash to one's from + * given buffer. + */ + private void updateHashes(CacheBuffer packedFiles) { + crc = Helper.crc32(packedFiles, 0, packedFiles.getBuffer().length - 2); + digest = Whirlpool.whirlpool(packedFiles.getBuffer(), 0, packedFiles.getBuffer().length - 2); + } + + + /** + * Add's new file to this folder. + * If there's already a file with same id then + * it get's overwriten. + */ + public void addRSFile(RSFile file) { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + if (file.getID() == -1) file.setID(getRSFreeFileID()); + files.put(file.getID(), file); + if (file.hasName()) { + filesByName.put(file.getName(), file.getID()); + } + needsRepack = fileSystemInfoChanged = true; + } + + /** + * Remove's file from this folder. + */ + public void removeFile(RSFile file) { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + files.remove(file.getID()); + filesByName.remove(file.getName()); + needsRepack = fileSystemInfoChanged = true; + } + + /** + * Delete's all files on this folder. + */ + public void deleteAllFiles() { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + files.clear(); + needsRepack = fileSystemInfoChanged = true; + } + + /** + * Recalculate's folder's hashes. + */ + public void recalculate() { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + updateHashes(packedFiles); + fileSystemInfoChanged = true; + } + + /** + * Returns highest file ids. + */ + public int getHighestId() { + return getRSFreeFileID() - 1; + } + + + /** + * Get's free file ID. + */ + private int getRSFreeFileID() { + if (files.isEmpty()) { + return 0; + } + + int highest = -1; + for (var file : files.values()) { + if (file.getID() > highest) { + highest = file.getID(); + } + } + return highest + 1; + } + + /** + * Find's file by id's id. + * Returns null if not found. + */ + public RSFile findRSFileByID(int id) { + if (!isLoaded()) throw new RuntimeException("Folder is not loaded."); + return files.get(id); + } + + /** + * Find's file by name. + * Returns null if not found. + */ + public RSFile findRSFileByName(String name) { + return findRSFileByName(Helper.strToI(name)); + } + + /** + * Find's file by name. + * Returns null if not found. + */ + public RSFile findRSFileByName(int name) { + if (!isLoaded()) throw new RuntimeException("Folder is not loaded."); + + if (name == -1) return null; + + return files.get(filesByName.get(name)); + } + + /** + * Wheter this folder was loaded. + */ + public boolean isLoaded() { + return packedFiles != null; + } + + /** + * Wheter this folder needs repacking. + */ + private boolean needsRepack() { + if (needsRepack) return true; + for (var file : files.values()) { + if (file.isDataChanged()) { + return true; + } + } + return false; + } + + /** + * Mark's this folder as already repacked. + */ + private void markAsNotNeedRepack() { + needsRepack = false; + for (var file : files.values()) { + file.markDataAsNotChanged(); + } + } + + + /** + * Wheter this folder was changed in any way. + */ + public boolean isFileSystemInfoChanged() { + if (fileSystemInfoChanged) return true; + for (var file : files.values()) { + if (file.isFileSystemInfoChanged()) { + return true; + } + } + return false; + } + + /** + * Mark's this folder as not changed, this + * happens when fit is repacked. + */ + public void markFileSystemInfoAsNotChanged() { + fileSystemInfoChanged = false; + for (var file : files.values()) { + file.markFileSystemInfoAsNotChanged(); + } + } + + /** + * Mark's this folder file system info as changed, + * get's called by FS only. + */ + public void markFileSystemInfoAsChanged() { + fileSystemInfoChanged = true; + } + + /** + * Get's count of files this folder has. + */ + public int filesCount() { + return files.size(); //files.keySet().stream().max(Comparator.naturalOrder()).orElse(-1) + 1; + } + + /** + * Get's all files that this folder has. + * Modifying the array in any way is not allowed. + * + * @return + */ + public ObjectCollection getRSFiles() { + return files.values(); + } + + /** + * Get's ID of this folder. + */ + public int getID() { + return id; + } + + /** + * Set's ID of this folder. + */ + public void setID(int id) { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + if (this.id != id) this.fileSystemInfoChanged = true; + this.id = id; + } + + /** + * Get's name of this folder. + */ + public int getName() { + return name; + } + + /** + * Set's name of this folder. + */ + public void setName(String name) { + setName(Helper.strToI(name)); + } + + /** + * Set's name of this folder. + */ + public void setName(int name) { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + if (this.name != name) this.fileSystemInfoChanged = true; + this.name = name; + } + + /** + * Get's version of this folder. + */ + public int getVersion() { + return version; + } + + /** + * Set's version of this folder. + */ + public void setVersion(int version) { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + if (this.version != version) this.fileSystemInfoChanged = this.needsRepack = true; + this.version = version; + } + + /** + * Set's XTEA keys of this folder. + */ + public void setXTEA(int[] xtea) { + if (!isLoaded()) throw new RuntimeException("Altering nonloaded folder."); + if (this.xtea != xtea) this.fileSystemInfoChanged = this.needsRepack = true; + this.xtea = xtea; + } + + + /** + * Get's crc32 of packed version of this folder. + */ + public int getCRC32() { + return crc; + } + + /** + * Get's whirlpool digest of packed version of this folder. + */ + public byte[] getDigest() { + return digest; + } + + /** + * Get's packed files buffer. + * Call to finish() is a must if you want + * to get up-to-date version. + */ + public CacheBuffer getPackedFiles() { + return packedFiles; + } + + public boolean hasName() { + return name != -1; + } +} diff --git a/cache/src/main/java/org/apollo/cache/Helper.java b/cache/src/main/java/org/apollo/cache/Helper.java new file mode 100644 index 000000000..c24d60929 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/Helper.java @@ -0,0 +1,277 @@ +package org.apollo.cache; + +import org.apache.tools.bzip2.CBZip2InputStream; +import org.apache.tools.bzip2.CBZip2OutputStream; +import org.tukaani.xz.LZMA2Options; +import org.tukaani.xz.LZMAInputStream; +import org.tukaani.xz.XZOutputStream; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.IOException; +import java.util.concurrent.CompletionException; +import java.util.zip.CRC32; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; + +public class Helper { + + private static CRC32 crc32 = new CRC32(); + + public static final int COMPRESSION_NONE = 0; + public static final int COMPRESSION_BZIP2 = 1; + public static final int COMPRESSION_GZIP = 2; + public static final int COMPRESSION_LZMA = 3; + + + public static void decryptContainer(byte[] container, int[] keys) { + decryptContainer(new CacheBuffer(container), keys); + } + + public static void decryptContainer(CacheBuffer container, int[] keys) { + container.xteaDecrypt(keys, 5, container.getBuffer().length - 2); + } + + + public static void encryptContainer(byte[] container, int[] keys) { + encryptContainer(new CacheBuffer(container), keys); + } + + public static void encryptContainer(CacheBuffer container, int[] keys) { + container.xteaEncrypt(keys, 5, container.getBuffer().length - 2); + } + + public static byte[] decodeFilesContainer(byte[] data) { + return decodeFilesContainer(new CacheBuffer(data)).getBuffer(); + } + + public static CacheBuffer decodeFilesContainer(CacheBuffer container) { + return decodeContainer(container, false); + } + + public static byte[] decodeFITContainer(byte[] data) { + return decodeFITContainer(new CacheBuffer(data)).getBuffer(); + } + + public static CacheBuffer decodeFITContainer(CacheBuffer container) { + return decodeContainer(container, true); + } + + private static CacheBuffer decodeContainer(CacheBuffer container, boolean isFITContainer) { + container.setPosition(0); + int compressionType = container.readUByte(); + if (compressionType > COMPRESSION_LZMA) + throw new RuntimeException("Unknown compression type:" + compressionType); + int length = container.readInt(); + CacheBuffer data; + if (compressionType != COMPRESSION_NONE) { + int decompressedLength = container.readInt(); + data = new CacheBuffer(decompressedLength); + try { + if (compressionType == COMPRESSION_GZIP) { + DataInputStream stream = new DataInputStream(new GZIPInputStream(new ByteArrayInputStream(container.getBuffer(), + container.getPosition(), length))); + stream.readFully(data.getBuffer()); + stream.close(); + } else if (compressionType == COMPRESSION_BZIP2) { + // we need to add header + byte[] reloc = new byte[length + 2]; + reloc[0] = 'h';reloc[1] = '1'; + System.arraycopy(container.getBuffer(), container.getPosition(), reloc, 2, length); + DataInputStream stream = new DataInputStream(new CBZip2InputStream(new ByteArrayInputStream(reloc))); + stream.readFully(data.getBuffer()); + stream.close(); + } else { + // we need to add length + byte[] reloc = new byte[length + 8]; + reloc[5] = (byte) (decompressedLength >>> 0); + reloc[6] = (byte) (decompressedLength >>> 8); + reloc[7] = (byte) (decompressedLength >>> 16); + reloc[8] = (byte) (decompressedLength >>> 24); + reloc[9] = reloc[10] = reloc[11] = reloc[12] = 0; + System.arraycopy(container.getBuffer(), container.getPosition() + 0, reloc, 0, 5); + System.arraycopy(container.getBuffer(), container.getPosition() + 5, reloc, 13, length - 5); + LZMAInputStream stream = new LZMAInputStream(new ByteArrayInputStream(reloc)); + while (data.getPosition() < data.getBuffer().length) { + int amt = stream.read(data.getBuffer(), data.getPosition(), data.getBuffer().length - data.getPosition()); + if (amt == -1) { + stream.close(); + throw new IOException(); + } + data.setPosition(data.getPosition() + amt); + } + + stream.close(); + } + } catch (IOException ioex) { + throw new CompletionException(ioex); + } + } else { + data = new CacheBuffer(length); + container.readBytes(data.getBuffer(), data.getPosition(), length); + } + if (!isFITContainer) { + @SuppressWarnings("unused") + int version = container.readUShort(); + } + return data; + } + + /** + * Does basic verification and decides if container is valid. + */ + public static boolean validFilesContainer(CacheBuffer container) { + if (container.getBuffer().length < 7) + return false; + container.setPosition(0); + int compressionType = container.readUByte(); + if (compressionType > COMPRESSION_LZMA) + return false; + int length = container.readInt(); + if (compressionType != COMPRESSION_NONE) { + if ((container.getBuffer().length - container.getPosition()) < 4) + return false; + container.readInt(); + } + if (length < 0 || (container.getBuffer().length - container.getPosition() - length - 2) != 0) + return false; + return true; + + } + + public static int decodeVersion(CacheBuffer container) { + container.setPosition(0); + int compressionType = container.readUByte(); + if (compressionType > COMPRESSION_LZMA) + throw new RuntimeException("Unknown compression type:" + compressionType); + int length = container.readInt(); + if (compressionType != COMPRESSION_NONE) + container.readInt(); // decompressed length + container.setPosition(container.getPosition() + length); + return container.readUShort(); + } + + + public static byte[] encodeFilesContainer(byte[] file, int fileVersion) { + return encodeFilesContainer(new CacheBuffer(file), fileVersion).getBuffer(); + } + + public static byte[] encodeFilesContainer(byte[] file, int fileVersion, int compressionType) { + return encodeFilesContainer(new CacheBuffer(file), fileVersion, compressionType).getBuffer(); + } + + public static CacheBuffer encodeFilesContainer(CacheBuffer file, int fileVersion) { + return encodeFilesContainer(file, fileVersion, decideCompression(file)); + } + + public static CacheBuffer encodeFilesContainer(CacheBuffer file, int fileVersion, int compressionType) { + return encodeContainer(file, fileVersion, compressionType, false); + } + + public static byte[] encodeFITContainer(byte[] file, int fileVersion) { + return encodeFITContainer(new CacheBuffer(file), fileVersion).getBuffer(); + } + + public static byte[] encodeFITContainer(byte[] file, int fileVersion, int compressionType) { + return encodeFITContainer(new CacheBuffer(file), fileVersion, compressionType).getBuffer(); + } + + public static CacheBuffer encodeFITContainer(CacheBuffer file, int fileVersion) { + return encodeFITContainer(file, fileVersion, decideCompression(file)); + } + + public static CacheBuffer encodeFITContainer(CacheBuffer file, int fileVersion, int compressionType) { + return encodeContainer(file, fileVersion, compressionType, true); + } + + private static CacheBuffer encodeContainer(CacheBuffer file, int fileVersion, int compressionType, boolean isFITContainer) { + if (compressionType > COMPRESSION_GZIP) // This is wrong + throw new RuntimeException("Unsupported compression type:" + compressionType); + + int allocLength = 1 + 4 + (!isFITContainer ? 2 : 0); + int fileLength = file.getBuffer().length; + if (compressionType != COMPRESSION_NONE) { + allocLength += 4; + try { + if (compressionType == COMPRESSION_GZIP) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + GZIPOutputStream out = new GZIPOutputStream(baos); + out.write(file.getBuffer()); + out.finish(); + out.close(); + file = new CacheBuffer(baos.toByteArray()); + baos.close(); + } else if (compressionType == COMPRESSION_BZIP2) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + CBZip2OutputStream out = new CBZip2OutputStream(baos,1); + out.write(file.getBuffer()); + out.close(); + byte[] data = baos.toByteArray(); // we need to remove h1 + byte[] reloc = new byte[data.length - 2]; + System.arraycopy(data, 2, reloc, 0, reloc.length); + file = new CacheBuffer(reloc); + baos.close(); + } else { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + LZMA2Options options = new LZMA2Options(); + + options.setPreset(7); // play with this number: 6 is default but 7 works better for mid sized archives ( > 8mb) + + XZOutputStream out = new XZOutputStream(baos, options); + out.write(file.getBuffer()); + out.flush(); + out.close(); + + byte[] data = baos.toByteArray(); // we need to remove h1 + byte[] reloc = new byte[data.length - 8]; + System.arraycopy(data, 8, reloc, 0, reloc.length); + file = new CacheBuffer(reloc); + baos.close(); + } + } catch (IOException ioex) { + throw new RuntimeException(ioex); + } + } + allocLength += file.getBuffer().length; + + CacheBuffer container = new CacheBuffer(allocLength); + container.writeByte(compressionType); + container.writeInt(file.getBuffer().length); + if (compressionType != COMPRESSION_NONE) + container.writeInt(fileLength); + container.writeBytes(file.getBuffer(), 0, file.getBuffer().length); + if (!isFITContainer) { + container.writeShort(fileVersion); + } + return container; + } + + public static int crc32(byte[] data, int offset, int length) { + return crc32(new CacheBuffer(data), offset, length); + } + + public static int crc32(CacheBuffer data, int offset, int length) { + crc32.update(data.getBuffer(), offset, length); + int v = (int) crc32.getValue(); + crc32.reset(); + return v; + } + + public static int strToI(String str) { + if (str == null) + return -1; + + // same as return str.hashcode(); + int i = 0; + for (int a = 0; a < str.length(); a++) + i = (31 * i) + str.charAt(a); + return i; + } + + private static int decideCompression(CacheBuffer data) { + if (data.getBuffer().length < 100) + return COMPRESSION_NONE; + return COMPRESSION_GZIP; // bzip2 is unreliable + } +} diff --git a/cache/src/main/java/org/apollo/cache/Index.java b/cache/src/main/java/org/apollo/cache/Index.java index a03996978..20377214e 100644 --- a/cache/src/main/java/org/apollo/cache/Index.java +++ b/cache/src/main/java/org/apollo/cache/Index.java @@ -1,67 +1,287 @@ package org.apollo.cache; -import com.google.common.base.Preconditions; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; /** - * An {@link Index} points to a file in the {@code main_file_cache.dat} file. - * - * @author Graham + * Manages the reading and writing for a particular file store in the cache. */ -public final class Index { - - /** - * Decodes a buffer into an index. - * - * @param buffer The buffer. - * @return The decoded {@link Index}. - * @throws IllegalArgumentException If the buffer length is invalid. - */ - public static Index decode(byte[] buffer) { - Preconditions.checkArgument(buffer.length == FileSystemConstants.INDEX_SIZE, "Incorrect buffer length."); - - int size = (buffer[0] & 0xFF) << 16 | (buffer[1] & 0xFF) << 8 | buffer[2] & 0xFF; - int block = (buffer[3] & 0xFF) << 16 | (buffer[4] & 0xFF) << 8 | buffer[5] & 0xFF; - - return new Index(size, block); - } - - /** - * The first block of the file. - */ - private final int block; - - /** - * The size of the file. - */ - private final int size; - - /** - * Creates the index. - * - * @param size The size of the file. - * @param block The first block of the file. - */ - public Index(int size, int block) { - this.size = size; - this.block = block; - } - - /** - * Gets the first block of the file. - * - * @return The first block of the file. - */ - public int getBlock() { - return block; - } - - /** - * Gets the size of the file. - * - * @return The size of the file. - */ - public int getSize() { - return size; - } - -} \ No newline at end of file +public class Index { + + private static final int IDX_BLOCK_LEN = 6; + private static final int HEADER_LEN = 8; + private static final int EXPANDED_HEADER_LEN = 10; + private static final int BLOCK_LEN = 512; + private static final int EXPANDED_BLOCK_LEN = 510; + private static final int TOTAL_BLOCK_LEN = HEADER_LEN + BLOCK_LEN; + private static ByteBuffer tempBuffer = ByteBuffer.allocateDirect(TOTAL_BLOCK_LEN); + + private int index; + private FileChannel indexChannel; + private FileChannel dataChannel; + private int maxSize; + + /** + * Creates a new FileStore object. + * + * @param index The index of this file store. + * @param dataChannel The channel of the data file for this file store. + * @param indexChannel The channel of the index file for this file store. + * @param maxSize The maximum size of a file in this file store. + */ + public Index(int index, FileChannel dataChannel, + FileChannel indexChannel, int maxSize) { + this.index = index; + this.dataChannel = dataChannel; + this.indexChannel = indexChannel; + this.maxSize = maxSize; + } + + /** + * Gets the number of files stored in this file store. + * + * @return This file store's file count. + */ + public int getFileCount() { + try { + return (int) (indexChannel.size() / IDX_BLOCK_LEN); + } catch (IOException ex) { + return 0; + } + } + + /** + * Reads a file from the file store. + * + * @param file The file to read. + * @return The file's data, or null if the file was invalid. + */ + public CacheBuffer get(int file) { + synchronized (dataChannel) { + try { + if (file * IDX_BLOCK_LEN + IDX_BLOCK_LEN > indexChannel.size()) { + return null; + } + + tempBuffer.position(0).limit(IDX_BLOCK_LEN); + indexChannel.read(tempBuffer, file * IDX_BLOCK_LEN); + tempBuffer.flip(); + int size = getMediumInt(tempBuffer); + int block = getMediumInt(tempBuffer); + + if (size < 0 || size > maxSize) { + return null; + } + if (block <= 0 || block > dataChannel.size() / TOTAL_BLOCK_LEN) { + return null; + } + + ByteBuffer fileBuffer = ByteBuffer.allocate(size); + int remaining = size; + int chunk = 0; + int blockLen = file <= 0xffff ? BLOCK_LEN : EXPANDED_BLOCK_LEN; + int headerLen = file <= 0xffff ? HEADER_LEN : EXPANDED_HEADER_LEN; + while (remaining > 0) { + if (block == 0) { + return null; + } + + int blockSize = remaining > blockLen ? blockLen : remaining; + tempBuffer.position(0).limit(blockSize + headerLen); + int read = dataChannel.read(tempBuffer, (long) block * TOTAL_BLOCK_LEN); + if (read == -1) { + return null; + } + + tempBuffer.flip(); + + int currentFile, currentChunk, nextBlock, currentIndex; + if (file <= 65535) { + currentFile = tempBuffer.getShort() & 0xffff; + currentChunk = tempBuffer.getShort() & 0xffff; + nextBlock = getMediumInt(tempBuffer); + currentIndex = tempBuffer.get() & 0xff; + } else { + currentFile = tempBuffer.getInt(); + currentChunk = tempBuffer.getShort() & 0xffff; + nextBlock = getMediumInt(tempBuffer); + currentIndex = tempBuffer.get() & 0xff; + } + + if (file != currentFile || chunk != currentChunk || index != currentIndex) { + return null; + } + if (nextBlock < 0 || nextBlock > dataChannel.size() / TOTAL_BLOCK_LEN) { + return null; + } + + fileBuffer.put(tempBuffer); + remaining -= blockSize; + block = nextBlock; + chunk++; + } + + fileBuffer.flip(); + return new CacheBuffer(fileBuffer.array()); + } catch (IOException ex) { + return null; + } + } + } + + /** + * Writes an item to the file store. + * + * @param file The file to write. + * @param data The file's data. + * @param size The size of the file. + * @return true if the file was written, false otherwise. + */ + public boolean put(int file, CacheBuffer data, int size) { + if (size < 0 || size > maxSize) { + throw new IllegalArgumentException("File too big: " + index + "," + file + " size: " + size); + } + + boolean success = put(file, ByteBuffer.wrap(data.getBuffer()), size, true); + if (!success) { + success = put(file, ByteBuffer.wrap(data.getBuffer()), size, false); + } + + return success; + } + + private boolean put(int file, ByteBuffer data, int size, boolean exists) { + try { + int block; + if (exists) { + if (file * IDX_BLOCK_LEN + IDX_BLOCK_LEN > indexChannel.size()) { + return false; + } + + tempBuffer.position(0).limit(IDX_BLOCK_LEN); + indexChannel.read(tempBuffer, file * IDX_BLOCK_LEN); + tempBuffer.flip().position(3); + block = getMediumInt(tempBuffer); + + if (block <= 0 || block > dataChannel.size() / TOTAL_BLOCK_LEN) { + return false; + } + } else { + block = (int) ((dataChannel.size() + TOTAL_BLOCK_LEN - 1) / TOTAL_BLOCK_LEN); + if (block == 0) { + block = 1; + } + } + + tempBuffer.position(0); + putMediumInt(tempBuffer, size); + putMediumInt(tempBuffer, block); + tempBuffer.flip(); + indexChannel.write(tempBuffer, file * IDX_BLOCK_LEN); + + int remaining = size; + int chunk = 0; + int blockLen = file <= 0xffff ? BLOCK_LEN : EXPANDED_BLOCK_LEN; + int headerLen = file <= 0xffff ? HEADER_LEN : EXPANDED_HEADER_LEN; + while (remaining > 0) { + int nextBlock = 0; + if (exists) { + tempBuffer.position(0).limit(headerLen); + int read = dataChannel.read(tempBuffer, (long) block * TOTAL_BLOCK_LEN); + if (read == -1) { + return false; + } + + tempBuffer.flip(); + + int currentFile, currentChunk, currentIndex; + if (file <= 0xffff) { + currentFile = tempBuffer.getShort() & 0xffff; + currentChunk = tempBuffer.getShort() & 0xffff; + nextBlock = getMediumInt(tempBuffer); + currentIndex = tempBuffer.get() & 0xff; + } else { + currentFile = tempBuffer.getInt(); + currentChunk = tempBuffer.getShort() & 0xffff; + nextBlock = getMediumInt(tempBuffer); + currentIndex = tempBuffer.get() & 0xff; + } + + if (file != currentFile || chunk != currentChunk || index != currentIndex) { + return false; + } + if (nextBlock < 0 || nextBlock > dataChannel.size() / TOTAL_BLOCK_LEN) { + return false; + } + } + + if (nextBlock == 0) { + exists = false; + nextBlock = (int) ((dataChannel.size() + TOTAL_BLOCK_LEN - 1) / TOTAL_BLOCK_LEN); + if (nextBlock == 0) { + nextBlock = 1; + } + if (nextBlock == block) { + nextBlock++; + } + } + + if (remaining <= blockLen) { + nextBlock = 0; + } + tempBuffer.position(0).limit(TOTAL_BLOCK_LEN); + if (file <= 0xffff) { + tempBuffer.putShort((short) file); + tempBuffer.putShort((short) chunk); + putMediumInt(tempBuffer, nextBlock); + tempBuffer.put((byte) index); + } else { + tempBuffer.putInt(file); + tempBuffer.putShort((short) chunk); + putMediumInt(tempBuffer, nextBlock); + tempBuffer.put((byte) index); + } + + int blockSize = remaining > blockLen ? blockLen : remaining; + data.limit(data.position() + blockSize); + tempBuffer.put(data); + tempBuffer.flip(); + + dataChannel.write(tempBuffer, (long) block * TOTAL_BLOCK_LEN); + remaining -= blockSize; + block = nextBlock; + chunk++; + } + + return true; + } catch (IOException ex) { + return false; + } + } + + private static int getMediumInt(ByteBuffer buffer) { + return ((buffer.get() & 0xff) << 16) | ((buffer.get() & 0xff) << 8) | + (buffer.get() & 0xff); + } + + private static void putMediumInt(ByteBuffer buffer, int val) { + buffer.put((byte) (val >> 16)); + buffer.put((byte) (val >> 8)); + buffer.put((byte) val); + } + + /** + * Close's this store. + */ + public void close() { + try { + this.dataChannel.close(); + } catch (IOException e) { + } + try { + this.indexChannel.close(); + } catch (IOException e) { + } + } +} diff --git a/cache/src/main/java/org/apollo/cache/IndexedFileSystem.java b/cache/src/main/java/org/apollo/cache/IndexedFileSystem.java deleted file mode 100644 index 43c837461..000000000 --- a/cache/src/main/java/org/apollo/cache/IndexedFileSystem.java +++ /dev/null @@ -1,332 +0,0 @@ -package org.apollo.cache; - -import com.google.common.base.Preconditions; -import org.apollo.cache.archive.Archive; - -import java.io.Closeable; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.nio.ByteBuffer; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.zip.CRC32; - -/** - * A file system based on top of the operating system's file system. It consists of a data file and index files. Index - * files point to blocks in the data file, which contains the actual data. - * - * @author Graham - */ -public final class IndexedFileSystem implements Closeable { - - /** - * The Map that caches already-decoded Archives. - */ - private final Map cache = new HashMap<>(FileSystemConstants.ARCHIVE_COUNT); - - /** - * The index files. - */ - private final RandomAccessFile[] indices = new RandomAccessFile[256]; - - /** - * Read only flag. - */ - private final boolean readOnly; - - /** - * The cached CRC table. - */ - private ByteBuffer crcTable; - - /** - * The {@link #crcTable} represented as an {@code int} array. - */ - private int[] crcs; - - /** - * The data file. - */ - private RandomAccessFile data; - - /** - * Creates the file system with the specified base directory. - * - * @param base The base directory. - * @param readOnly Indicates whether the file system will be read only or not. - * @throws FileNotFoundException If the data files could not be found. - */ - public IndexedFileSystem(Path base, boolean readOnly) throws FileNotFoundException { - this.readOnly = readOnly; - detectLayout(base); - } - - @Override - public void close() throws IOException { - if (data != null) { - synchronized (data) { - data.close(); - } - } - - for (RandomAccessFile index : indices) { - if (index != null) { - synchronized (index) { - index.close(); - } - } - } - } - - /** - * Gets the {@link Archive} pointed to by the specified {@link FileDescriptor}. - * - * @param type The file type. - * @param file The file id. - * @return The Archive. - * @throws IOException If there is an error decoding the Archive. - */ - public Archive getArchive(int type, int file) throws IOException { - FileDescriptor descriptor = new FileDescriptor(type, file); - Archive cached = cache.get(descriptor); - - if (cached == null) { - cached = Archive.decode(getFile(descriptor)); - - synchronized (this) { - cache.put(descriptor, cached); - } - } - - return cached; - } - - /** - * Gets the CRC table. - * - * @return The CRC table. - * @throws IOException If there is an error accessing files to create the table. - * @throws IllegalStateException If this file system is not read-only. - */ - public ByteBuffer getCrcTable() throws IOException { - if (readOnly) { - synchronized (this) { - if (crcTable != null) { - return crcTable.duplicate(); - } - } - - int archives = getFileCount(0); - int hash = 1234; - int[] crcs = new int[archives]; - - CRC32 crc32 = new CRC32(); - for (int i = 1; i < crcs.length; i++) { - crc32.reset(); - - ByteBuffer buffer = getFile(0, i); - byte[] bytes = new byte[buffer.remaining()]; - buffer.get(bytes, 0, bytes.length); - crc32.update(bytes, 0, bytes.length); - - crcs[i] = (int) crc32.getValue(); - } - - ByteBuffer buffer = ByteBuffer.allocate((crcs.length + 1) * Integer.BYTES); - for (int crc : crcs) { - hash = (hash << 1) + crc; - buffer.putInt(crc); - } - - buffer.putInt(hash); - buffer.flip(); - - synchronized (this) { - crcTable = buffer.asReadOnlyBuffer(); - return crcTable.duplicate(); - } - } - - throw new IllegalStateException("Cannot get CRC table from a writable file system."); - } - - /** - * Gets the CRC table as an {@code int} array. - * - * @return The CRC table as an {@code int} array. - * @throws IOException If there is an error accessing files to create the table. - */ - public int[] getCrcs() throws IOException { - if (crcs == null) { - ByteBuffer buffer = getCrcTable(); - crcs = new int[(buffer.remaining() / Integer.BYTES) - 1]; - Arrays.setAll(crcs, crc -> buffer.getInt()); - } - return crcs; - } - - /** - * Gets a file. - * - * @param descriptor The {@link FileDescriptor} pointing to the file. - * @return A {@link ByteBuffer} containing the contents of the file. - * @throws IOException If there is an error decoding the file. - */ - public ByteBuffer getFile(FileDescriptor descriptor) throws IOException { - Index index = getIndex(descriptor); - ByteBuffer buffer = ByteBuffer.allocate(index.getSize()); - - long position = index.getBlock() * FileSystemConstants.BLOCK_SIZE; - int read = 0; - int size = index.getSize(); - int blocks = size / FileSystemConstants.CHUNK_SIZE; - if (size % FileSystemConstants.CHUNK_SIZE != 0) { - blocks++; - } - - for (int i = 0; i < blocks; i++) { - byte[] header = new byte[FileSystemConstants.HEADER_SIZE]; - synchronized (data) { - data.seek(position); - data.readFully(header); - } - - position += FileSystemConstants.HEADER_SIZE; - - int nextFile = (header[0] & 0xFF) << 8 | header[1] & 0xFF; - int curChunk = (header[2] & 0xFF) << 8 | header[3] & 0xFF; - int nextBlock = (header[4] & 0xFF) << 16 | (header[5] & 0xFF) << 8 | header[6] & 0xFF; - int nextType = header[7] & 0xFF; - - Preconditions.checkArgument(i == curChunk, "Chunk id mismatch."); - - int chunkSize = size - read; - if (chunkSize > FileSystemConstants.CHUNK_SIZE) { - chunkSize = FileSystemConstants.CHUNK_SIZE; - } - - byte[] chunk = new byte[chunkSize]; - synchronized (data) { - data.seek(position); - data.readFully(chunk); - } - buffer.put(chunk); - - read += chunkSize; - position = (long) nextBlock * (long) FileSystemConstants.BLOCK_SIZE; - - // if we still have more data to read, check the validity of the header - if (size > read) { - if (nextType != descriptor.getType() + 1) { - throw new IOException("File type mismatch."); - } - - if (nextFile != descriptor.getFile()) { - throw new IOException("File id mismatch."); - } - } - } - - buffer.flip(); - return buffer; - } - - /** - * Gets a file. - * - * @param type The file type. - * @param file The file id. - * @return A {@link ByteBuffer} which contains the contents of the file. - * @throws IOException If an I/O error occurs. - */ - public ByteBuffer getFile(int type, int file) throws IOException { - return getFile(new FileDescriptor(type, file)); - } - - /** - * Checks if this {@link IndexedFileSystem} is read only. - * - * @return {@code true} if so, {@code false} if not. - */ - public boolean isReadOnly() { - return readOnly; - } - - /** - * Automatically detect the layout of the specified directory. - * - * @param base The base directory. - * @throws FileNotFoundException If the data files could not be found. - */ - private void detectLayout(Path base) throws FileNotFoundException { - int indexCount = 0; - for (int index = 0; index < indices.length; index++) { - Path idx = base.resolve("main_file_cache.idx" + index); - if (Files.exists(idx) && !Files.isDirectory(idx)) { - indexCount++; - indices[index] = new RandomAccessFile(idx.toFile(), readOnly ? "r" : "rw"); - } - } - if (indexCount <= 0) { - throw new FileNotFoundException("No index file(s) present in " + base + "."); - } - - Path resources = base.resolve("main_file_cache.dat"); - if (Files.exists(resources) && !Files.isDirectory(resources)) { - data = new RandomAccessFile(resources.toFile(), readOnly ? "r" : "rw"); - } else { - throw new FileNotFoundException("No data file present."); - } - } - - /** - * Gets the number of files with the specified type. - * - * @param type The type. - * @return The number of files. - * @throws IOException If there is an error getting the length of the specified index file. - * @throws IndexOutOfBoundsException If {@code type} is less than 0, or greater than or equal to the amount of - * indices. - */ - private int getFileCount(int type) throws IOException { - Preconditions.checkElementIndex(type, indices.length, "File type out of bounds."); - - RandomAccessFile indexFile = indices[type]; - synchronized (indexFile) { - return (int) (indexFile.length() / FileSystemConstants.INDEX_SIZE); - } - } - - /** - * Gets the index of a file. - * - * @param descriptor The {@link FileDescriptor} which points to the file. - * @return The {@link Index}. - * @throws IOException If there is an error reading from the index file. - * @throws IndexOutOfBoundsException If the descriptor type is less than 0, or greater than or equal to the amount - * of indices. - */ - private Index getIndex(FileDescriptor descriptor) throws IOException { - int index = descriptor.getType(); - Preconditions.checkElementIndex(index, indices.length, "File descriptor type out of bounds."); - - byte[] buffer = new byte[FileSystemConstants.INDEX_SIZE]; - RandomAccessFile indexFile = indices[index]; - synchronized (indexFile) { - long position = descriptor.getFile() * FileSystemConstants.INDEX_SIZE; - if (position >= 0 && indexFile.length() >= position + FileSystemConstants.INDEX_SIZE) { - indexFile.seek(position); - indexFile.readFully(buffer); - } else { - throw new FileNotFoundException("Could not find find index."); - } - } - - return Index.decode(buffer); - } - -} \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/RSFile.java b/cache/src/main/java/org/apollo/cache/RSFile.java new file mode 100644 index 000000000..df9136c30 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/RSFile.java @@ -0,0 +1,185 @@ +package org.apollo.cache; + +public class RSFile { + + /** + * Contains file ID. + */ + private int id; + /** + * Contains name hash of this file. + */ + private int name; + /** + * Contains file data if loaded. + */ + private CacheBuffer data; + /** + * Wheter filesystem info about this file + * changed in any way. + */ + private boolean fsInfoChanged; + /** + * Wheter file data was changed. + */ + private boolean dataChanged; + + @SuppressWarnings("unused") + private RSFile() { + + } + + /** + * This constructor can be used only by FS + * loader. + */ + public RSFile(int fileID, int name) { + this(fileID,name,null); + } + + + /** + * Construct's new file with autoassigned ID. + */ + public RSFile(String name, CacheBuffer data) { + this(-1, Helper.strToI(name),data); + } + + /** + * Construct's new file with autoassigned ID. + */ + public RSFile(CacheBuffer data) { + this(-1,-1,data); + } + + public RSFile(int filID, CacheBuffer data) { + this(filID,-1,data); + } + + public RSFile(int fileID, String name, CacheBuffer data) { + this(fileID,Helper.strToI(name),data); + } + + public RSFile(int fileID, int name, CacheBuffer data) { + this.id = fileID; + this.name = name; + this.data = data; + } + + /** + * Copies this file, including the + * buffer if it's present. + */ + public RSFile copy() { + RSFile f = new RSFile(id,name); + if (data != null) { + f.data = new CacheBuffer(data.toArray(0, data.getBuffer().length),data.getPosition()); + } + return f; + } + + public int getID() { + return id; + } + + public void setID(int id) { + if (!isLoaded()) + throw new RuntimeException("Using nonloaded file: " + id); + if (this.id != id) { + this.id = id; + fsInfoChanged = true; + } + } + + public int getName() { + return name; + } + + public void setName(String name) { + setName(Helper.strToI(name)); + } + + public void setName(int name) { + if (!isLoaded()) + throw new RuntimeException("Using nonloaded file."); + + if (this.name != name) { + fsInfoChanged = true; + this.name = name; + } + } + + public CacheBuffer getData() { + return data; + } + + /** + * Load's this file. + */ + public void load(CacheBuffer data) { + if (isLoaded()) + throw new RuntimeException("Already loaded."); + this.data = data; + } + + /** + * Set's file data. + */ + public void setData(CacheBuffer data) { + if (!isLoaded()) + throw new RuntimeException("Using nonloaded file."); + if (this.data != data) { + dataChanged = fsInfoChanged = true; + this.data = data; + } + } + + /** + * Wheter this file is loaded. + */ + public boolean isLoaded() { + return data != null; + } + + /** + * Unload's this file , can be called + * only by folder unload() method. + */ + public void unload() { + if (!isLoaded()) + throw new RuntimeException("Using nonloaded file."); + data = null; + } + + /** + * Whether filesystem info about this file changed. + */ + public boolean isFileSystemInfoChanged() { + return fsInfoChanged; + } + + /** + * Wheter data was changed. + */ + public boolean isDataChanged() { + return dataChanged; + } + + /** + * Mark's this file as not changed. + */ + public void markFileSystemInfoAsNotChanged() { + fsInfoChanged = false; + } + + /** + * Mark's data as not changed. + */ + public void markDataAsNotChanged() { + dataChanged = false; + } + + public boolean hasName() { + return name != -1; + } +} diff --git a/cache/src/main/java/org/apollo/cache/StringUtilities.java b/cache/src/main/java/org/apollo/cache/StringUtilities.java new file mode 100644 index 000000000..5811fde3c --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/StringUtilities.java @@ -0,0 +1,142 @@ +package org.apollo.cache; + +public class StringUtilities { + + private static char[] UNICODE_TABLE = {'\u20ac', '\0', '\u201a', '\u0192', '\u201e', '\u2026', '\u2020', '\u2021', '\u02c6', '\u2030', + '\u0160', '\u2039', '\u0152', '\0', '\u017d', '\0', '\0', + '\u2018', '\u2019', '\u201c', '\u201d', '\u2022', '\u2013', '\u2014', '\u02dc', '\u2122', '\u0161', '\u203a', '\u0153', '\0', '\u017e', + '\u0178'}; + + public static final String decodeString(byte[] buffer, int offset, int length) { + char[] strBuffer = new char[length]; + int write = 0; + for (int dc = 0; dc < length; dc++) { + int data = buffer[dc + offset] & 0xff; + if (data == 0) + continue; + if (data >= 128 && data < 160) { + char uni = UNICODE_TABLE[data - 128]; + if (uni == 0) + uni = '?'; + strBuffer[write++] = (char) uni; + continue; + } + strBuffer[write++] = (char) data; + } + return new String(strBuffer, 0, write); + } + + public static char fromCP1252(byte value) { + int i = 0xff & value; + if (i == 0) { + throw new IllegalArgumentException("Non cp1252 character 0x" + Integer.toString(i, 16) + " provided"); + } + if (i >= 128 && i < 160) { + int i_1_ = UNICODE_TABLE[i - 128]; + if (i_1_ == 0) { + i_1_ = 63; + } + i = i_1_; + } + return (char) i; + } + + public static final int encodeString(byte[] buffer, int boffset, String str, int soffset, int slength) { + int charsToEncode = slength - soffset; + for (int cc = 0; cc < charsToEncode; cc++) { + char c = str.charAt(cc + soffset); + if ((c > 0 && c < 128) || (c >= 160 && c <= 255)) { + buffer[boffset + cc] = (byte) c; + continue; + } + + switch (c) { + case '\u20ac': + buffer[boffset + cc] = -128; + break; + case '\u201a': + buffer[boffset + cc] = -126; + break; + case '\u0192': + buffer[boffset + cc] = -125; + break; + case '\u201e': + buffer[boffset + cc] = -124; + break; + case '\u2026': + buffer[boffset + cc] = -123; + break; + case '\u2020': + buffer[boffset + cc] = -122; + break; + case '\u2021': + buffer[boffset + cc] = -121; + break; + case '\u02c6': + buffer[boffset + cc] = -120; + break; + case '\u2030': + buffer[boffset + cc] = -119; + break; + case '\u0160': + buffer[boffset + cc] = -118; + break; + case '\u2039': + buffer[boffset + cc] = -117; + break; + case '\u0152': + buffer[boffset + cc] = -116; + break; + case '\u017d': + buffer[boffset + cc] = -114; + break; + case '\u2018': + buffer[boffset + cc] = -111; + break; + case '\u2019': + buffer[boffset + cc] = -110; + break; + case '\u201c': + buffer[boffset + cc] = -109; + break; + case '\u201d': + buffer[boffset + cc] = -108; + break; + case '\u2022': + buffer[boffset + cc] = -107; + break; + case '\u2013': + buffer[boffset + cc] = -106; + break; + case '\u2014': + buffer[boffset + cc] = -105; + break; + case '\u02dc': + buffer[boffset + cc] = -104; + break; + case '\u2122': + buffer[boffset + cc] = -103; + break; + case '\u0161': + buffer[boffset + cc] = -102; + break; + case '\u203a': + buffer[boffset + cc] = -101; + break; + case '\u0153': + buffer[boffset + cc] = -100; + break; + case '\u017e': + buffer[boffset + cc] = -98; + break; + case '\u0178': + buffer[boffset + cc] = -97; + break; + default: + buffer[boffset + cc] = (byte) '?'; + break; + } + } + return charsToEncode; + } +} \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/Whirlpool.java b/cache/src/main/java/org/apollo/cache/Whirlpool.java new file mode 100644 index 000000000..8ed240d0e --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/Whirlpool.java @@ -0,0 +1,416 @@ +package org.apollo.cache; + +/** + * The Whirlpool hashing function. + * + *

+ * References + * + *

+ * The Whirlpool algorithm was developed by + * Paulo S. L. M. Barreto and + * Vincent Rijmen. + * + * See + * P.S.L.M. Barreto, V. Rijmen, + * ``The Whirlpool hashing function,'' + * First NESSIE workshop, 2000 (tweaked version, 2003), + * + * + * @author Paulo S.L.M. Barreto + * @author Vincent Rijmen. + * + * @version 3.0 (2003.03.12) + * + * ============================================================================= + * + * Differences from version 2.1: + * + * - Suboptimal diffusion matrix replaced by cir(1, 1, 4, 1, 8, 5, 2, 9). + * + * ============================================================================= + * + * Differences from version 2.0: + * + * - Generation of ISO/IEC 10118-3 test vectors. + * - Bug fix: nonzero carry was ignored when tallying the data length + * (this bug apparently only manifested itself when feeding data + * in pieces rather than in a single chunk at once). + * + * Differences from version 1.0: + * + * - Original S-box replaced by the tweaked, hardware-efficient version. + * + * ============================================================================= + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +import java.util.Arrays; + +public class Whirlpool { + + /** + * The message digest size (in bits) + */ + public static final int DIGESTBITS = 512; + + /** + * The message digest size (in bytes) + */ + public static final int DIGESTBYTES = DIGESTBITS >>> 3; + + /** + * The number of rounds of the internal dedicated block cipher. + */ + protected static final int R = 10; + + /** + * The substitution box. + */ + private static final String sbox = + "\u1823\uc6E8\u87B8\u014F\u36A6\ud2F5\u796F\u9152" + + "\u60Bc\u9B8E\uA30c\u7B35\u1dE0\ud7c2\u2E4B\uFE57" + + "\u1577\u37E5\u9FF0\u4AdA\u58c9\u290A\uB1A0\u6B85" + + "\uBd5d\u10F4\ucB3E\u0567\uE427\u418B\uA77d\u95d8" + + "\uFBEE\u7c66\udd17\u479E\ucA2d\uBF07\uAd5A\u8333" + + "\u6302\uAA71\uc819\u49d9\uF2E3\u5B88\u9A26\u32B0" + + "\uE90F\ud580\uBEcd\u3448\uFF7A\u905F\u2068\u1AAE" + + "\uB454\u9322\u64F1\u7312\u4008\uc3Ec\udBA1\u8d3d" + + "\u9700\ucF2B\u7682\ud61B\uB5AF\u6A50\u45F3\u30EF" + + "\u3F55\uA2EA\u65BA\u2Fc0\udE1c\uFd4d\u9275\u068A" + + "\uB2E6\u0E1F\u62d4\uA896\uF9c5\u2559\u8472\u394c" + + "\u5E78\u388c\ud1A5\uE261\uB321\u9c1E\u43c7\uFc04" + + "\u5199\u6d0d\uFAdF\u7E24\u3BAB\ucE11\u8F4E\uB7EB" + + "\u3c81\u94F7\uB913\u2cd3\uE76E\uc403\u5644\u7FA9" + + "\u2ABB\uc153\udc0B\u9d6c\u3174\uF646\uAc89\u14E1" + + "\u163A\u6909\u70B6\ud0Ed\ucc42\u98A4\u285c\uF886"; + + private static long[][] C = new long[8][256]; + private static long[] rc = new long[R + 1]; + + static { + for (int x = 0; x < 256; x++) { + char c = sbox.charAt(x/2); + long v1 = ((x & 1) == 0) ? c >>> 8 : c & 0xff; + long v2 = v1 << 1; + if (v2 >= 0x100L) { + v2 ^= 0x11dL; + } + long v4 = v2 << 1; + if (v4 >= 0x100L) { + v4 ^= 0x11dL; + } + long v5 = v4 ^ v1; + long v8 = v4 << 1; + if (v8 >= 0x100L) { + v8 ^= 0x11dL; + } + long v9 = v8 ^ v1; + /* + * build the circulant table C[0][x] = S[x].[1, 1, 4, 1, 8, 5, 2, 9]: + */ + C[0][x] = + (v1 << 56) | (v1 << 48) | (v4 << 40) | (v1 << 32) | + (v8 << 24) | (v5 << 16) | (v2 << 8) | (v9 ); + /* + * build the remaining circulant tables C[t][x] = C[0][x] rotr t + */ + for (int t = 1; t < 8; t++) { + C[t][x] = (C[t - 1][x] >>> 8) | ((C[t - 1][x] << 56)); + } + } + + /* + * build the round constants: + */ + rc[0] = 0L; /* not used (assigment kept only to properly initialize all variables) */ + for (int r = 1; r <= R; r++) { + int i = 8*(r - 1); + rc[r] = + (C[0][i ] & 0xff00000000000000L) ^ + (C[1][i + 1] & 0x00ff000000000000L) ^ + (C[2][i + 2] & 0x0000ff0000000000L) ^ + (C[3][i + 3] & 0x000000ff00000000L) ^ + (C[4][i + 4] & 0x00000000ff000000L) ^ + (C[5][i + 5] & 0x0000000000ff0000L) ^ + (C[6][i + 6] & 0x000000000000ff00L) ^ + (C[7][i + 7] & 0x00000000000000ffL); + } + } + + public static byte[] whirlpool(byte[] data, int off, int len) { + byte source[]; + if(off <= 0) { + source = data; + } else { + source = new byte[len]; + for(int i = 0; i < len; i++) + source[i] = data[off + i]; + } + Whirlpool whirlpool = new Whirlpool(); + whirlpool.NESSIEinit(); + whirlpool.NESSIEadd(source, len * 8); + byte digest[] = new byte[64]; + whirlpool.NESSIEfinalize(digest); + return digest; + } + + /** + * Global number of hashed bits (256-bit counter). + */ + protected byte[] bitLength = new byte[32]; + + /** + * Buffer of data to hash. + */ + protected byte[] buffer = new byte[64]; + + /** + * Current number of bits on the buffer. + */ + protected int bufferBits = 0; + + /** + * Current (possibly incomplete) byte slot on the buffer. + */ + protected int bufferPos = 0; + + /** + * The hashing state. + */ + protected long[] hash = new long[8]; + protected long[] K = new long[8]; // the round key + protected long[] L = new long[8]; + protected long[] block = new long[8]; // mu(buffer) + protected long[] state = new long[8]; // the cipher state + + public Whirlpool() { + } + + /** + * The core Whirlpool transform. + */ + protected void processBuffer() { + /* + * map the buffer to a block: + */ + for (int i = 0, j = 0; i < 8; i++, j += 8) { + block[i] = + (((long)buffer[j ] ) << 56) ^ + (((long)buffer[j + 1] & 0xffL) << 48) ^ + (((long)buffer[j + 2] & 0xffL) << 40) ^ + (((long)buffer[j + 3] & 0xffL) << 32) ^ + (((long)buffer[j + 4] & 0xffL) << 24) ^ + (((long)buffer[j + 5] & 0xffL) << 16) ^ + (((long)buffer[j + 6] & 0xffL) << 8) ^ + (((long)buffer[j + 7] & 0xffL) ); + } + /* + * compute and apply K^0 to the cipher state: + */ + for (int i = 0; i < 8; i++) { + state[i] = block[i] ^ (K[i] = hash[i]); + } + /* + * iterate over all rounds: + */ + for (int r = 1; r <= R; r++) { + /* + * compute K^r from K^{r-1}: + */ + for (int i = 0; i < 8; i++) { + L[i] = 0L; + for (int t = 0, s = 56; t < 8; t++, s -= 8) { + L[i] ^= C[t][(int)(K[(i - t) & 7] >>> s) & 0xff]; + } + } + for (int i = 0; i < 8; i++) { + K[i] = L[i]; + } + K[0] ^= rc[r]; + /* + * apply the r-th round transformation: + */ + for (int i = 0; i < 8; i++) { + L[i] = K[i]; + for (int t = 0, s = 56; t < 8; t++, s -= 8) { + L[i] ^= C[t][(int)(state[(i - t) & 7] >>> s) & 0xff]; + } + } + for (int i = 0; i < 8; i++) { + state[i] = L[i]; + } + } + /* + * apply the Miyaguchi-Preneel compression function: + */ + for (int i = 0; i < 8; i++) { + hash[i] ^= state[i] ^ block[i]; + } + } + + /** + * Initialize the hashing state. + */ + public void NESSIEinit() { + Arrays.fill(bitLength, (byte)0); + bufferBits = bufferPos = 0; + buffer[0] = 0; // it's only necessary to cleanup buffer[bufferPos]. + Arrays.fill(hash, 0L); // initial value + } + + /** + * Delivers input data to the hashing algorithm. + * + * @param source plaintext data to hash. + * @param sourceBits how many bits of plaintext to process. + * + * This method maintains the invariant: bufferBits < 512 + */ + public void NESSIEadd(byte[] source, long sourceBits) { + /* + sourcePos + | + +-------+-------+------- + ||||||||||||||||||||| source + +-------+-------+------- + +-------+-------+-------+-------+-------+------- + |||||||||||||||||||||| buffer + +-------+-------+-------+-------+-------+------- + | + bufferPos + */ + int sourcePos = 0; // index of leftmost source byte containing data (1 to 8 bits). + int sourceGap = (8 - ((int)sourceBits & 7)) & 7; // space on source[sourcePos]. + int bufferRem = bufferBits & 7; // occupied bits on buffer[bufferPos]. + int b; + // tally the length of the added data: + long value = sourceBits; + for (int i = 31, carry = 0; i >= 0; i--) { + carry += (bitLength[i] & 0xff) + ((int)value & 0xff); + bitLength[i] = (byte)carry; + carry >>>= 8; + value >>>= 8; + } + // process data in chunks of 8 bits: + while (sourceBits > 8) { // at least source[sourcePos] and source[sourcePos+1] contain data. + // take a byte from the source: + b = ((source[sourcePos] << sourceGap) & 0xff) | + ((source[sourcePos + 1] & 0xff) >>> (8 - sourceGap)); + if (b < 0 || b >= 256) { + throw new RuntimeException("LOGIC ERROR"); + } + // process this byte: + buffer[bufferPos++] |= b >>> bufferRem; + bufferBits += 8 - bufferRem; // bufferBits = 8*bufferPos; + if (bufferBits == 512) { + // process data block: + processBuffer(); + // reset buffer: + bufferBits = bufferPos = 0; + } + buffer[bufferPos] = (byte)((b << (8 - bufferRem)) & 0xff); + bufferBits += bufferRem; + // proceed to remaining data: + sourceBits -= 8; + sourcePos++; + } + // now 0 <= sourceBits <= 8; + // furthermore, all data (if any is left) is in source[sourcePos]. + if (sourceBits > 0) { + b = (source[sourcePos] << sourceGap) & 0xff; // bits are left-justified on b. + // process the remaining bits: + buffer[bufferPos] |= b >>> bufferRem; + } else { + b = 0; + } + if (bufferRem + sourceBits < 8) { + // all remaining data fits on buffer[bufferPos], and there still remains some space. + bufferBits += sourceBits; + } else { + // buffer[bufferPos] is full: + bufferPos++; + bufferBits += 8 - bufferRem; // bufferBits = 8*bufferPos; + sourceBits -= 8 - bufferRem; + // now 0 <= sourceBits < 8; furthermore, all data is in source[sourcePos]. + if (bufferBits == 512) { + // process data block: + processBuffer(); + // reset buffer: + bufferBits = bufferPos = 0; + } + buffer[bufferPos] = (byte)((b << (8 - bufferRem)) & 0xff); + bufferBits += (int)sourceBits; + } + } + + /** + * Get the hash value from the hashing state. + * + * This method uses the invariant: bufferBits < 512 + */ + public void NESSIEfinalize(byte[] digest) { + // append a '1'-bit: + buffer[bufferPos] |= 0x80 >>> (bufferBits & 7); + bufferPos++; // all remaining bits on the current byte are set to zero. + // pad with zero bits to complete 512N + 256 bits: + if (bufferPos > 32) { + while (bufferPos < 64) { + buffer[bufferPos++] = 0; + } + // process data block: + processBuffer(); + // reset buffer: + bufferPos = 0; + } + while (bufferPos < 32) { + buffer[bufferPos++] = 0; + } + // append bit length of hashed data: + System.arraycopy(bitLength, 0, buffer, 32, 32); + // process data block: + processBuffer(); + // return the completed message digest: + for (int i = 0, j = 0; i < 8; i++, j += 8) { + long h = hash[i]; + digest[j ] = (byte)(h >>> 56); + digest[j + 1] = (byte)(h >>> 48); + digest[j + 2] = (byte)(h >>> 40); + digest[j + 3] = (byte)(h >>> 32); + digest[j + 4] = (byte)(h >>> 24); + digest[j + 5] = (byte)(h >>> 16); + digest[j + 6] = (byte)(h >>> 8); + digest[j + 7] = (byte)(h ); + } + } + + /** + * Delivers string input data to the hashing algorithm. + * + * @param source plaintext data to hash (ASCII text string). + * + * This method maintains the invariant: bufferBits < 512 + */ + public void NESSIEadd(String source) { + if (source.length() > 0) { + byte[] data = new byte[source.length()]; + for (int i = 0; i < source.length(); i++) { + data[i] = (byte)source.charAt(i); + } + NESSIEadd(data, 8 * data.length); + } + } + +} diff --git a/cache/src/main/java/org/apollo/cache/archive/Archive.java b/cache/src/main/java/org/apollo/cache/archive/Archive.java deleted file mode 100644 index 896e202bb..000000000 --- a/cache/src/main/java/org/apollo/cache/archive/Archive.java +++ /dev/null @@ -1,110 +0,0 @@ -package org.apollo.cache.archive; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.nio.ByteBuffer; - -import org.apollo.util.BufferUtil; -import org.apollo.util.CompressionUtil; - -/** - * Represents an archive. - * - * @author Graham - */ -public final class Archive { - - /** - * Decodes the archive in the specified buffer. - * - * @param buffer The buffer. - * @return The archive. - * @throws IOException If there is an error decompressing the archive. - */ - public static Archive decode(ByteBuffer buffer) throws IOException { - int extractedSize = BufferUtil.readUnsignedMedium(buffer); - int size = BufferUtil.readUnsignedMedium(buffer); - boolean extracted = false; - - if (size != extractedSize) { - byte[] compressed = new byte[size]; - byte[] decompressed = new byte[extractedSize]; - buffer.get(compressed); - CompressionUtil.debzip2(compressed, decompressed); - buffer = ByteBuffer.wrap(decompressed); - extracted = true; - } - - int entryCount = buffer.getShort() & 0xFFFF; - int[] identifiers = new int[entryCount]; - int[] extractedSizes = new int[entryCount]; - int[] sizes = new int[entryCount]; - - for (int i = 0; i < entryCount; i++) { - identifiers[i] = buffer.getInt(); - extractedSizes[i] = BufferUtil.readUnsignedMedium(buffer); - sizes[i] = BufferUtil.readUnsignedMedium(buffer); - } - - ArchiveEntry[] entries = new ArchiveEntry[entryCount]; - for (int entry = 0; entry < entryCount; entry++) { - ByteBuffer entryBuffer; - if (!extracted) { - byte[] compressed = new byte[sizes[entry]]; - byte[] decompressed = new byte[extractedSizes[entry]]; - buffer.get(compressed); - CompressionUtil.debzip2(compressed, decompressed); - entryBuffer = ByteBuffer.wrap(decompressed); - } else { - byte[] buf = new byte[extractedSizes[entry]]; - buffer.get(buf); - entryBuffer = ByteBuffer.wrap(buf); - } - entries[entry] = new ArchiveEntry(identifiers[entry], entryBuffer); - } - return new Archive(entries); - } - - /** - * The entries in this archive. - */ - private final ArchiveEntry[] entries; - - /** - * Creates a new archive. - * - * @param entries The entries in this archive. - */ - public Archive(ArchiveEntry[] entries) { - this.entries = entries; - } - - /** - * Gets an {@link ArchiveEntry} by its name. - * - * @param name The name. - * @return The entry. - * @throws FileNotFoundException If the entry could not be found. - */ - public ArchiveEntry getEntry(String name) throws FileNotFoundException { - int hash = hash(name); - - for (ArchiveEntry entry : entries) { - if (entry.getIdentifier() == hash) { - return entry; - } - } - throw new FileNotFoundException("Could not find entry: " + name + "."); - } - - /** - * Hashes the specified string into an integer used to identify an {@link ArchiveEntry}. - * - * @param name The name of the entry. - * @return The hash. - */ - public static int hash(String name) { - return name.toUpperCase().chars().reduce(0, (hash, character) -> hash * 61 + character - 32); - } - -} \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/archive/ArchiveEntry.java b/cache/src/main/java/org/apollo/cache/archive/ArchiveEntry.java deleted file mode 100644 index ce95a4376..000000000 --- a/cache/src/main/java/org/apollo/cache/archive/ArchiveEntry.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.apollo.cache.archive; - -import java.nio.ByteBuffer; - -/** - * Represents a single entry in an {@link Archive}. - * - * @author Graham - */ -public final class ArchiveEntry { - - /** - * The buffer of this entry. - */ - private final ByteBuffer buffer; - - /** - * The identifier of this entry. - */ - private final int identifier; - - /** - * Creates a new archive entry. - * - * @param identifier The identifier. - * @param buffer The buffer. - */ - public ArchiveEntry(int identifier, ByteBuffer buffer) { - this.identifier = identifier; - this.buffer = buffer.asReadOnlyBuffer(); - } - - /** - * Gets the buffer of this entry. - * - * @return This buffer of this entry. - */ - public ByteBuffer getBuffer() { - return buffer.duplicate(); - } - - /** - * Gets the identifier of this entry. - * - * @return The identifier of this entry. - */ - public int getIdentifier() { - return identifier; - } - -} \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/archive/package-info.java b/cache/src/main/java/org/apollo/cache/archive/package-info.java deleted file mode 100644 index 35b89a22b..000000000 --- a/cache/src/main/java/org/apollo/cache/archive/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Contains classes which deal with archives. - */ -package org.apollo.cache.archive; \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/decoder/ItemDefinitionDecoder.java b/cache/src/main/java/org/apollo/cache/decoder/ItemDefinitionDecoder.java index 5ba666216..996f93403 100644 --- a/cache/src/main/java/org/apollo/cache/decoder/ItemDefinitionDecoder.java +++ b/cache/src/main/java/org/apollo/cache/decoder/ItemDefinitionDecoder.java @@ -1,13 +1,11 @@ package org.apollo.cache.decoder; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.ByteBuffer; - -import org.apollo.cache.IndexedFileSystem; -import org.apollo.cache.archive.Archive; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; +import org.apollo.cache.Cache; +import org.apollo.cache.CacheBuffer; +import org.apollo.cache.Archive; +import org.apollo.cache.RSFile; import org.apollo.cache.def.ItemDefinition; -import org.apollo.util.BufferUtil; /** * Decodes item data from the {@code obj.dat} file into {@link ItemDefinition}s. @@ -19,112 +17,157 @@ public final class ItemDefinitionDecoder implements Runnable { /** * The IndexedFileSystem. */ - private final IndexedFileSystem fs; + private final Cache cache; /** * Creates the ItemDefinitionDecoder. * - * @param fs The {@link IndexedFileSystem}. + * @param cache The {@link Archive}. */ - public ItemDefinitionDecoder(IndexedFileSystem fs) { - this.fs = fs; + public ItemDefinitionDecoder(Cache cache) { + this.cache = cache; } @Override public void run() { - try { - Archive config = fs.getArchive(0, 2); - ByteBuffer data = config.getEntry("obj.dat").getBuffer(); - ByteBuffer idx = config.getEntry("obj.idx").getBuffer(); - - int count = idx.getShort(), index = 2; - int[] indices = new int[count]; - for (int i = 0; i < count; i++) { - indices[i] = index; - index += idx.getShort(); - } + final var fs = cache.getArchive(2); + final var folder = fs.findFolderByID(10); - ItemDefinition[] definitions = new ItemDefinition[count]; - for (int i = 0; i < count; i++) { - data.position(indices[i]); - definitions[i] = decode(i, data); - } - - ItemDefinition.init(definitions); - } catch (IOException e) { - throw new UncheckedIOException("Error decoding ItemDefinitions.", e); + ItemDefinition[] definitions = new ItemDefinition[folder.getHighestId() + 1]; + for (RSFile file : folder.getRSFiles()) { + definitions[file.getID()] = decode(file.getID(), file.getData()); } + + ItemDefinition.init(definitions); } /** * Decodes a single definition. * - * @param id The item's id. + * @param id The item's id. * @param buffer The buffer. * @return The {@link ItemDefinition}. */ - private ItemDefinition decode(int id, ByteBuffer buffer) { + private ItemDefinition decode(int id, CacheBuffer buffer) { ItemDefinition definition = new ItemDefinition(id); - while (true) { - int opcode = buffer.get() & 0xFF; - + for (; ; ) { + int opcode = buffer.readUByte(); if (opcode == 0) { return definition; } else if (opcode == 1) { - buffer.getShort(); + definition.setBaseModel(buffer.readUShort()); } else if (opcode == 2) { - definition.setName(BufferUtil.readString(buffer)); - } else if (opcode == 3) { - definition.setDescription(BufferUtil.readString(buffer)); - } else if (opcode >= 4 && opcode <= 8 || opcode == 10) { - buffer.getShort(); + definition.setName(buffer.readString()); + } else if (opcode == 4) { + definition.setModelScale(buffer.readUShort()); + } else if (opcode == 5) { + definition.setModelPitch(buffer.readUShort()); + } else if (opcode == 6) { + definition.setModelRoll(buffer.readUShort()); + } else if (opcode == 7) { + definition.setModelTranslateX(buffer.readSignedShort()); + } else if (opcode == 8) { + definition.setModelTranslateY(buffer.readSignedShort()); } else if (opcode == 11) { definition.setStackable(true); } else if (opcode == 12) { - definition.setValue(buffer.getInt()); + definition.setValue(buffer.readInt()); } else if (opcode == 16) { definition.setMembersOnly(true); } else if (opcode == 23) { - buffer.getShort(); - buffer.get(); + definition.setPrimaryMaleModel(buffer.readUShort()); + definition.setMaleYOffset(buffer.readUByte()); } else if (opcode == 24) { - buffer.getShort(); + definition.setSecondaryMaleModel(buffer.readUShort()); } else if (opcode == 25) { - buffer.getShort(); - buffer.get(); + definition.setPrimaryFemaleModel(buffer.readUShort()); + definition.setFemaleYOffset(buffer.readUByte()); } else if (opcode == 26) { - buffer.getShort(); + definition.setSecondaryFemaleModel(buffer.readUShort()); } else if (opcode >= 30 && opcode < 35) { - String str = BufferUtil.readString(buffer); + String str = buffer.readString(); if (str.equalsIgnoreCase("hidden")) { str = null; } definition.setGroundAction(opcode - 30, str); } else if (opcode >= 35 && opcode < 40) { - definition.setInventoryAction(opcode - 35, BufferUtil.readString(buffer)); + definition.setInventoryAction(opcode - 35, buffer.readString()); } else if (opcode == 40) { - int colourCount = buffer.get() & 0xFF; - for (int i = 0; i < colourCount; i++) { - buffer.getShort(); - buffer.getShort(); + int size = buffer.readUByte(); + definition.setOriginalModelColors(new short[size]); + definition.setModifiedModelColors(new short[size]); + for (int count = 0; count < size; count++) { + definition.getOriginalModelColors()[count] = (short) buffer.readUShort(); + definition.getModifiedModelColors()[count] = (short) buffer.readUShort(); + } + } else if (opcode == 41) { + int size = buffer.readUByte(); + definition.setOriginalTextureColors(new short[size]); + definition.setModifiedTextureColors(new short[size]); + for (int count = 0; count < size; count++) { + definition.getOriginalTextureColors()[count] = (short) buffer.readUShort(); + definition.getModifiedTextureColors()[count] = (short) buffer.readUShort(); } - } else if (opcode == 78 || opcode == 79 || (opcode >= 90 && opcode <= 93) || opcode == 95) { - buffer.getShort(); + } else if (opcode == 42) { + definition.setShiftClickDropIndex(buffer.readByte()); + } else if (opcode == 65) { + definition.setNonExchangeItem(true); + } else if (opcode == 78) { + definition.setTertiaryMaleModel(buffer.readUShort()); + } else if (opcode == 79) { + definition.setTertiaryFemaleModel(buffer.readUShort()); + } else if (opcode == 90) { + definition.setMaleHead(buffer.readUShort()); + } else if (opcode == 91) { + definition.setFemaleHead(buffer.readUShort()); + } else if (opcode == 92) { + definition.setSecondaryMaleHead(buffer.readUShort()); + } else if (opcode == 93) { + definition.setSecondaryFemaleHead(buffer.readUShort()); + } else if (opcode == 95) { + definition.setModelYaw(buffer.readUShort()); } else if (opcode == 97) { - definition.setNoteInfoId(buffer.getShort() & 0xFFFF); + definition.setNoteInfoId(buffer.readUShort()); } else if (opcode == 98) { - definition.setNoteGraphicId(buffer.getShort() & 0xFFFF); + definition.setNoteGraphicId(buffer.readUShort()); } else if (opcode >= 100 && opcode < 110) { - buffer.getShort(); - buffer.getShort(); - } else if (opcode >= 110 && opcode <= 112) { - buffer.getShort(); - } else if (opcode == 113 || opcode == 114) { - buffer.get(); + if (definition.getStackIds() == null) { + definition.setStackIds(new int[10]); + definition.setStackAmounts(new int[10]); + } + definition.getStackIds()[opcode - 100] = buffer.readUShort(); + definition.getStackAmounts()[opcode - 100] = buffer.readUShort(); + } else if (opcode == 110) { + definition.setScaleX(buffer.readUShort()); + } else if (opcode == 111) { + definition.setScaleY(buffer.readUShort()); + } else if (opcode == 112) { + definition.setScaleZ(buffer.readUShort()); + } else if (opcode == 113) { + definition.setAmbience(buffer.readSignedByte()); + } else if (opcode == 114) { + definition.setContrast(buffer.readSignedByte()); } else if (opcode == 115) { - definition.setTeam(buffer.get() & 0xFF); + definition.setTeam(buffer.readUByte()); + } else if (opcode == 139) { + definition.setLoanInfo(buffer.readUShort()); + } else if (opcode == 140) { + definition.setLoanGraphicId(buffer.readUShort()); + } else if (opcode == 148) { + definition.setPlaceHolderInfo(buffer.readUShort()); + } else if (opcode == 149) { + definition.setPlaceHolderTemplate(buffer.readUShort()); + } else if (opcode == 249) { + final int size = buffer.readUByte(); + definition.setParameters(new Int2ObjectArrayMap<>(size)); + for (int index = 0; index < size; index++) { + final boolean stringInstance = buffer.readUByte() == 1; + final int key = buffer.readUMedInt(); + final Object value = stringInstance ? buffer.readString() : buffer.readInt(); + definition.getParameters().put(key, value); + } } + } } - } \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/decoder/NpcDefinitionDecoder.java b/cache/src/main/java/org/apollo/cache/decoder/NpcDefinitionDecoder.java index aa5dfd20b..23310fffb 100644 --- a/cache/src/main/java/org/apollo/cache/decoder/NpcDefinitionDecoder.java +++ b/cache/src/main/java/org/apollo/cache/decoder/NpcDefinitionDecoder.java @@ -1,14 +1,11 @@ package org.apollo.cache.decoder; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.ByteBuffer; -import java.util.Arrays; - -import org.apollo.cache.IndexedFileSystem; -import org.apollo.cache.archive.Archive; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; +import org.apollo.cache.Cache; +import org.apollo.cache.CacheBuffer; +import org.apollo.cache.Archive; +import org.apollo.cache.RSFile; import org.apollo.cache.def.NpcDefinition; -import org.apollo.util.BufferUtil; /** * Decodes npc data from the {@code npc.dat} file into {@link NpcDefinition}s. @@ -20,118 +17,196 @@ public final class NpcDefinitionDecoder implements Runnable { /** * The IndexedFileSystem. */ - private final IndexedFileSystem fs; + private final Cache cache; /** * Creates the NpcDefinitionDecoder. * - * @param fs The {@link IndexedFileSystem}. + * @param cache The {@link Archive}. */ - public NpcDefinitionDecoder(IndexedFileSystem fs) { - this.fs = fs; + public NpcDefinitionDecoder(Cache cache) { + this.cache = cache; + + } @Override public void run() { - try { - Archive config = fs.getArchive(0, 2); - ByteBuffer data = config.getEntry("npc.dat").getBuffer(); - ByteBuffer idx = config.getEntry("npc.idx").getBuffer(); - - int count = idx.getShort(), index = 2; - int[] indices = new int[count]; - - for (int i = 0; i < count; i++) { - indices[i] = index; - index += idx.getShort(); - } - - NpcDefinition[] definitions = new NpcDefinition[count]; - for (int i = 0; i < count; i++) { - data.position(indices[i]); - definitions[i] = decode(i, data); - } - - NpcDefinition.init(definitions); - } catch (IOException e) { - throw new UncheckedIOException("Error decoding NpcDefinitions.", e); + final var fs = cache.getArchive(2); + final var folder = fs.findFolderByID(9); + NpcDefinition[] definitions = new NpcDefinition[folder.getHighestId() + 1]; + for (RSFile file : folder.getRSFiles()) { + definitions[file.getID()] = decode(file.getID(), file.getData()); } + NpcDefinition.init(definitions); } /** * Decodes a single definition. * - * @param id The npc's id. + * @param id The npc's id. * @param buffer The buffer. * @return The {@link NpcDefinition}. */ - private NpcDefinition decode(int id, ByteBuffer buffer) { + private NpcDefinition decode(int id, CacheBuffer buffer) { NpcDefinition definition = new NpcDefinition(id); - while (true) { - int opcode = buffer.get() & 0xFF; - + int length; + int index; + for (; ; ) { + int opcode = buffer.readUByte(); if (opcode == 0) { return definition; } else if (opcode == 1) { - int length = buffer.get() & 0xFF; - int[] models = new int[length]; - for (int index = 0; index < length; index++) { - models[index] = buffer.getShort(); + length = buffer.readUByte(); + definition.setModels(new int[length]); + + for (index = 0; index < length; ++index) { + definition.getModels()[index] = buffer.readUShort(); } + } else if (opcode == 2) { - definition.setName(BufferUtil.readString(buffer)); - } else if (opcode == 3) { - definition.setDescription(BufferUtil.readString(buffer)); + definition.setName(buffer.readString()); } else if (opcode == 12) { - definition.setSize(buffer.get()); + definition.setSize(buffer.readUByte()); } else if (opcode == 13) { - definition.setStandAnimation(buffer.getShort()); + definition.setStandAnimation(buffer.readUShort()); } else if (opcode == 14) { - definition.setWalkAnimation(buffer.getShort()); + definition.setWalkAnimation(buffer.readUShort()); + } else if (opcode == 15) { + definition.setTurnLeftSequence(buffer.readUShort()); + } else if (opcode == 16) { + definition.setTurnRightSequence(buffer.readUShort()); } else if (opcode == 17) { - definition - .setWalkAnimations(buffer.getShort(), buffer.getShort(), buffer.getShort(), buffer.getShort()); - } else if (opcode >= 30 && opcode < 40) { - String action = BufferUtil.readString(buffer); + definition.setWalkAnimations(buffer.readUShort(), buffer.readUShort(), buffer.readUShort(), + buffer.readUShort()); + } else if (opcode >= 30 && opcode < 35) { + String action = buffer.readString(); if (action.equals("hidden")) { action = null; } definition.setInteraction(opcode - 30, action); } else if (opcode == 40) { - int length = buffer.get() & 0xFF; - int[] originalColours = new int[length]; - int[] replacementColours = new int[length]; + length = buffer.readUByte(); + definition.setOriginalColours(new short[length]); + definition.setReplacementColours(new short[length]); + + for (index = 0; index < length; ++index) { + definition.getOriginalColours()[index] = (short) buffer.readUShort(); + definition.getReplacementColours()[index] = (short) buffer.readUShort(); + } + + } else if (opcode == 41) { + length = buffer.readUByte(); + definition.setOriginalTextures(new short[length]); + definition.setReplacementTextures(new short[length]); - for (int index = 0; index < length; index++) { - originalColours[index] = buffer.getShort(); - replacementColours[index] = buffer.getShort(); + for (index = 0; index < length; ++index) { + definition.getOriginalTextures()[index] = (short) buffer.readUShort(); + definition.getReplacementTextures()[index] = (short) buffer.readUShort(); } + } else if (opcode == 60) { - int length = buffer.get() & 0xFF; - int[] additionalModels = new int[length]; + length = buffer.readUByte(); + definition.setHeadModels(new int[length]); - for (int index = 0; index < length; index++) { - additionalModels[index] = buffer.getShort(); + for (index = 0; index < length; ++index) { + definition.getHeadModels()[index] = buffer.readUShort(); } - } else if (opcode >= 90 && opcode <= 92) { - buffer.getShort(); // Dummy + + } else if (opcode == 93) { + definition.setDrawMapdot(false); } else if (opcode == 95) { - definition.setCombatLevel(buffer.getShort()); - } else if (opcode == 97 || opcode == 98) { - buffer.getShort(); - } else if (opcode == 100 || opcode == 101) { - buffer.get(); - } else if (opcode == 102 || opcode == 103) { - buffer.getShort(); + definition.setCombatLevel(buffer.readUShort()); + } else if (opcode == 97) { + definition.setScaleX(buffer.readUShort()); + } else if (opcode == 98) { + definition.setScaleY(buffer.readUShort()); + } else if (opcode == 99) { + definition.setPriority(true); + } else if (opcode == 100) { + definition.setAmbience(buffer.readByte()); + } else if (opcode == 101) { + definition.setContrast(buffer.readByte()); + } else if (opcode == 102) { + definition.setHeadIcon(buffer.readUShort()); + } else if (opcode == 103) { + definition.setRotation(buffer.readUShort()); } else if (opcode == 106) { - wrap(buffer.getShort()); - wrap(buffer.getShort()); + definition.setVarbit(buffer.readUShort()); + if ('\uffff' == definition.getVarbit()) { + definition.setVarbit(-1); + } - int count = buffer.get() & 0xFF; - int[] morphisms = new int[count + 1]; - Arrays.setAll(morphisms, index -> wrap(buffer.getShort())); + definition.setVarp(buffer.readUShort()); + if ('\uffff' == definition.getVarp()) { + definition.setVarp(-1); + } + + length = buffer.readUByte(); + definition.setMorphisms(new int[length + 2]); + + for (index = 0; index <= length; ++index) { + definition.getMorphisms()[index] = buffer.readUShort(); + if (definition.getMorphisms()[index] == 0xFFFF) { + definition.getMorphisms()[index] = -1; + } + } + + definition.getMorphisms()[length + 1] = -1; + + } else if (opcode == 107) { + definition.setClickable(false); + } else if (opcode == 109) { + definition.setSlowWalk(false); + } else if (opcode == 111) { + definition.setAnimateIdle(true); + } else if (opcode == 118) { + definition.setVarbit(buffer.readUShort()); + if ('\uffff' == definition.getVarbit()) { + definition.setVarbit(-1); + } + + definition.setVarp(buffer.readUShort()); + if ('\uffff' == definition.getVarp()) { + definition.setVarp(-1); + } + + int var = buffer.readUShort(); + if (var == 0xFFFF) { + var = -1; + } + + length = buffer.readUByte(); + definition.setMorphisms(new int[length + 2]); + + for (index = 0; index <= length; ++index) { + definition.getMorphisms()[index] = buffer.readUShort(); + if (definition.getMorphisms()[index] == '\uffff') { + definition.getMorphisms()[index] = -1; + } + } + + definition.getMorphisms()[length + 1] = var; + } else if (opcode == 249) { + length = buffer.readUByte(); + + definition.setParameters(new Int2ObjectArrayMap<>(length)); + + for (int i = 0; i < length; i++) { + boolean isString = buffer.readUByte() == 1; + int key = buffer.readUMedInt(); + Object value; + + if (isString) { + value = buffer.readString(); + } else { + value = buffer.readInt(); + } + + definition.getParameters().put(key, value); + } } } } diff --git a/cache/src/main/java/org/apollo/cache/decoder/ObjectDefinitionDecoder.java b/cache/src/main/java/org/apollo/cache/decoder/ObjectDefinitionDecoder.java index 3ffc797a9..2e0a735b3 100644 --- a/cache/src/main/java/org/apollo/cache/decoder/ObjectDefinitionDecoder.java +++ b/cache/src/main/java/org/apollo/cache/decoder/ObjectDefinitionDecoder.java @@ -1,14 +1,13 @@ package org.apollo.cache.decoder; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.nio.ByteBuffer; - -import org.apollo.cache.IndexedFileSystem; -import org.apollo.cache.archive.Archive; -import org.apollo.cache.def.ItemDefinition; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; +import org.apollo.cache.Cache; +import org.apollo.cache.CacheBuffer; +import org.apollo.cache.Archive; +import org.apollo.cache.RSFile; import org.apollo.cache.def.ObjectDefinition; -import org.apollo.util.BufferUtil; + +import java.nio.ByteBuffer; /** * Decodes object data from the {@code loc.dat} file into {@link ObjectDefinition}s. @@ -20,123 +19,193 @@ public final class ObjectDefinitionDecoder implements Runnable { /** * The IndexedFileSystem. */ - private final IndexedFileSystem fs; + private final Cache cache; /** * Creates the ObjectDefinitionDecoder. * - * @param fs The {@link IndexedFileSystem}. + * @param cache The {@link Archive}. */ - public ObjectDefinitionDecoder(IndexedFileSystem fs) { - this.fs = fs; + public ObjectDefinitionDecoder(Cache cache) { + this.cache = cache; } @Override public void run() { - try { - Archive config = fs.getArchive(0, 2); - ByteBuffer data = config.getEntry("loc.dat").getBuffer(); - ByteBuffer idx = config.getEntry("loc.idx").getBuffer(); - - int count = idx.getShort(), index = 2; - int[] indices = new int[count]; - for (int i = 0; i < count; i++) { - indices[i] = index; - index += idx.getShort(); - } - - ObjectDefinition[] definitions = new ObjectDefinition[count]; - for (int i = 0; i < count; i++) { - data.position(indices[i]); - definitions[i] = decode(i, data); - } - - ObjectDefinition.init(definitions); - } catch (IOException e) { - throw new UncheckedIOException("Error decoding ObjectDefinitions.", e); + final var fs = cache.getArchive(2); + final var folder = fs.findFolderByID(6); + ObjectDefinition[] definitions = new ObjectDefinition[folder.getHighestId() + 1]; + for (RSFile file : folder.getRSFiles()) { + definitions[file.getID()] = decode(file.getID(), file.getData()); } + ObjectDefinition.init(definitions); } /** * Decodes data from the cache into an {@link ObjectDefinition}. * - * @param id The id of the object. - * @param data The {@link ByteBuffer} containing the data. + * @param id The id of the object. + * @param buffer The {@link ByteBuffer} containing the data. * @return The object definition. */ - private ObjectDefinition decode(int id, ByteBuffer data) { + private ObjectDefinition decode(int id, CacheBuffer buffer) { ObjectDefinition definition = new ObjectDefinition(id); - while (true) { - int opcode = data.get() & 0xFF; - + for (; ; ) { + final var opcode = buffer.readUByte(); if (opcode == 0) { return definition; } else if (opcode == 1) { - int amount = data.get() & 0xFF; - for (int i = 0; i < amount; i++) { - data.getShort(); - data.get(); + int count = buffer.readUByte(); + if (count > 0) { + definition.setTypes(new int[count]); + definition.setModels(new int[count][1]); + for (int index = 0; index < count; index++) { + definition.getModels()[index][0] = buffer.readUShort(); + definition.getTypes()[index] = buffer.readUByte(); + } } } else if (opcode == 2) { - definition.setName(BufferUtil.readString(data)); - } else if (opcode == 3) { - definition.setDescription(BufferUtil.readString(data)); + definition.setName(buffer.readString()); } else if (opcode == 5) { - int amount = data.get() & 0xFF; - for (int i = 0; i < amount; i++) { - data.getShort(); + int count = buffer.readUByte(); + if (count > 0) { + definition.setTypes(null); + definition.setModels(new int[count][1]); + for (int index = 0; index < count; index++) + definition.getModels()[index][0] = buffer.readUShort(); } } else if (opcode == 14) { - definition.setWidth(data.get() & 0xFF); + definition.setWidth(buffer.readUByte()); } else if (opcode == 15) { - definition.setLength(data.get() & 0xFF); + definition.setLength(buffer.readUByte()); } else if (opcode == 17) { definition.setSolid(false); } else if (opcode == 18) { definition.setImpenetrable(false); } else if (opcode == 19) { - definition.setInteractive((data.get() & 0xFF) == 1); + definition.setInteractive(buffer.readUByte() == 1); + } else if (opcode == 21) { + definition.setAdjustValue(0); + } else if (opcode == 22) { + definition.setDynamicShading(true); + } else if (opcode == 23) { + definition.setOccludes((byte) 1); } else if (opcode == 24) { - data.getShort(); - } else if (opcode == 28 || opcode == 29) { - data.get(); - } else if (opcode >= 30 && opcode < 39) { + definition.setAnimations(new int[]{buffer.readUShort()}); + if (definition.getAnimations()[0] == 65535) { + definition.getAnimations()[0] = -1; + } + } else if (opcode == 27) { + definition.setCollisionType(1); + } else if (opcode == 28) { + definition.setDecorationDisplacement(buffer.readUByte()); + } else if (opcode == 29) { + definition.setContrast(buffer.readSignedByte()); + } else if (opcode == 39) { + definition.setAmbience(buffer.readSignedByte()); + } else if (opcode >= 30 && opcode < 35) { String[] actions = definition.getMenuActions(); if (actions == null) { actions = new String[10]; } - String action = BufferUtil.readString(data); - actions[opcode - 30] = action; + actions[opcode - 30] = buffer.readString(); definition.setMenuActions(actions); - } else if (opcode == 39) { - data.get(); } else if (opcode == 40) { - int amount = data.get() & 0xFF; - for (int i = 0; i < amount; i++) { - data.getShort(); - data.getShort(); + final int count = buffer.readUByte(); + definition.setOriginalColours(new short[count]); + definition.setReplacementColours(new short[count]); + for (int i = 0; i < count; i++) { + definition.getOriginalColours()[i] = (short) buffer.readUShort(); + definition.getReplacementColours()[i] = (short) buffer.readUShort(); + } + } else if (opcode == 41) { + final int count = buffer.readUByte(); + definition.setOriginalTextures(new short[count]); + definition.setReplacementTextures(new short[count]); + for (int i_7_ = 0; i_7_ < count; i_7_++) { + definition.getOriginalTextures()[i_7_] = (short) buffer.readUShort(); + definition.getReplacementTextures()[i_7_] = (short) buffer.readUShort(); } - } else if (opcode == 60 || opcode >= 65 && opcode <= 68) { - data.getShort(); + } else if (opcode == 62) { + definition.setMirrorModel(true); + } else if (opcode == 64) { + definition.setCastsShadow(false); + } else if (opcode == 65) { + definition.setScaleX(buffer.readUShort()); + } else if (opcode == 66) { + definition.setScaleY(buffer.readUShort()); + } else if (opcode == 67) { + definition.setScaleZ(buffer.readUShort()); + } else if (opcode == 68) { + definition.setMapscene(buffer.readUShort()); } else if (opcode == 69) { - data.get(); - } else if (opcode >= 70 && opcode <= 72) { - data.getShort(); + definition.setRotationFlag(buffer.readUByte()); + } else if (opcode == 70) { + definition.setTranslateX((buffer.readSignedShort())); + } else if (opcode == 71) { + definition.setTranslateY((buffer.readSignedShort())); + } else if (opcode == 72) { + definition.setTranslateZ((buffer.readSignedShort())); } else if (opcode == 73) { + definition.setDecoration(true); + } else if (opcode == 74) { definition.setObstructive(true); } else if (opcode == 75) { - data.get(); - } else if (opcode == 77) { - data.getShort(); - data.getShort(); - int count = data.get(); - for (int i = 0; i <= count; i++) { - data.getShort(); + definition.setHoldsItemPiles(buffer.readUByte()); + } else if (opcode == 77 || opcode == 92) { + definition.setVarbit(buffer.readUShort()); + if (65535 == definition.getVarbit()) { + definition.setVarbit(-1); + } + definition.setVarp(buffer.readUShort()); + if (65535 == definition.getVarp()) { + definition.setVarp(-1); + } + + int model = -1; + if (opcode == 92) { + model = buffer.readSmart32(); + } + + int length = buffer.readUByte(); + definition.setMorphisms(new int[length + 2]); + + for (int index = 0; index <= length; index++) { + definition.getMorphisms()[index] = buffer.readSmart32(); + } + + definition.getMorphisms()[1 + length] = model; + } else if (opcode == 78) { + definition.setSound(buffer.readUShort()); + definition.setSoundRadius(buffer.readUByte()); + } else if (opcode == 79) { + definition.setSoundDelayMinDuration(buffer.readUShort()); + definition.setSoundDelayMaxDuration(buffer.readUShort()); + definition.setSoundRadius(buffer.readUByte()); + final int count = buffer.readUByte(); + definition.setSounds(new int[count]); + for (int i = 0; i < count; i++) + definition.getSounds()[i] = buffer.readUShort(); + } else if (opcode == 81) { + definition.setAdjustValue(buffer.readUByte() * 256); + } else if (opcode == 82) { + definition.setMapSceneType(buffer.readUShort()); + } else if (opcode == 249) { + final int size = buffer.readUByte(); + definition.setParameters(new Int2ObjectArrayMap<>(size)); + + for (int index = 0; size > index; index++) { + final boolean stringInstance = buffer.readUByte() == 1; + final int key = buffer.readUMedInt(); + final Object value; + if (stringInstance) { + value = buffer.readString(); + } else { + value = buffer.readInt(); + } + definition.getParameters().put(key, value); } - } else { - continue; } } } - } \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java b/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java new file mode 100644 index 000000000..35b79c436 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/decoder/rsenum/EnumDefinitionDecoder.java @@ -0,0 +1,83 @@ +package org.apollo.cache.decoder.rsenum; + +import org.apollo.cache.Archive; +import org.apollo.cache.Cache; +import org.apollo.cache.CacheBuffer; +import org.apollo.cache.RSFile; +import org.apollo.cache.def.EnumDefinition; + +import java.util.HashMap; + +/** + * Decodes archive two folder eight into {@link EnumDefinition}s. + * + * @author Cjay0091 + */ +public final class EnumDefinitionDecoder implements Runnable { + + /** + * The IndexedFileSystem. + */ + private final Cache cache; + + /** + * Creates the EnumDefinitionDecoder. + * + * @param cache The {@link Archive}. + */ + public EnumDefinitionDecoder(Cache cache) { + this.cache = cache; + } + + @Override + public void run() { + final var fs = cache.getArchive(2); + final var folder = fs.findFolderByID(8); + + EnumDefinition[] definitions = new EnumDefinition[folder.getHighestId() + 1]; + for (RSFile file : folder.getRSFiles()) { + definitions[file.getID()] = decode(file.getID(), file.getData()); + } + + EnumDefinition.init(definitions); + } + + /** + * Decodes a single definition. + * + * @param id The item's id. + * @param buffer The buffer. + * @return The {@link EnumDefinition}. + */ + private EnumDefinition decode(int id, CacheBuffer buffer) { + EnumDefinition def = new EnumDefinition(id); + for (; ; ) { + int opcode = buffer.readUByte(); + if (opcode == 0) { + return def; + } else if (opcode == 1) { + def.setKeyType(ScriptVarType.forCharKey((char) buffer.readUByte())); + } else if (opcode == 2) { + def.setValType(ScriptVarType.forCharKey((char) buffer.readUByte())); + } else if (opcode == 3) { + def.setDefaultString(buffer.readString()); + } else if (opcode == 4) { + def.setDefaultInt(buffer.readInt()); + } else if (opcode == 5) { + final var size = buffer.readUShort(); + final var values = new HashMap(size); + for (int index = 0; index < size; index++) { + values.put(buffer.readInt(), buffer.readString()); + } + def.setStringValues(values); + } else if (opcode == 6) { + final var size = buffer.readUShort(); + final var values = new HashMap(size); + for (int index = 0; index < size; index++) { + values.put(buffer.readInt(), buffer.readInt()); + } + def.setIntValues(values); + } + } + } +} \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/decoder/rsenum/ScriptVarType.java b/cache/src/main/java/org/apollo/cache/decoder/rsenum/ScriptVarType.java new file mode 100644 index 000000000..7e4668b7d --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/decoder/rsenum/ScriptVarType.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2018, Joshua Filby + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.apollo.cache.decoder.rsenum; + +import java.util.HashMap; +import java.util.Map; + +public enum ScriptVarType +{ + INTEGER('i', "integer"), + BOOLEAN('1', "boolean"), + SEQ('A', "seq"), + COLOUR('C', "colour"), + /** + * Also known as {@code Widget}. + */ + COMPONENT('I', "component"), + IDKIT('K', "idkit"), + MIDI('M', "midi"), + SYNTH('P', "synth"), + STAT('S', "stat"), + COORDGRID('c', "coordgrid"), + GRAPHIC('d', "graphic"), + FONTMETRICS('f', "fontmetrics"), + ENUM('g', "enum"), + JINGLE('j', "jingle"), + /** + * Also known as {@code Object}. + */ + LOC('l', "loc"), + MODEL('m', "model"), + NPC('n', "npc"), + /** + * Also known as {@code Item}. + */ + OBJ('o', "obj"), + /** + * Another version of {@code OBJ}, but means that on Jagex's side they used the internal name for an item. + */ + NAMEDOBJ('O', "namedobj"), + STRING('s', "string"), + SPOTANIM('t', "spotanim"), + INV('v', "inv"), + TEXTURE('x', "texture"), + CHAR('z', "char"), + MAPSCENEICON('£', "mapsceneicon"), + MAPELEMENT('µ', "mapelement"), + HITMARK('×', "hitmark"), + STRUCT('J', "struct"); + + private static final Map keyToTypeMap = new HashMap<>(); + + static { + for (ScriptVarType type : values()) { + keyToTypeMap.put(type.keyChar, type); + } + } + + public static ScriptVarType forCharKey(char key) { + return keyToTypeMap.get(key); + } + + /** + * The character used when encoding or decoding types. + */ + private final char keyChar; + + /** + * The full name of the var type. + */ + private final String fullName; + + ScriptVarType(char keyChar, String fullName) { + this.keyChar = keyChar; + this.fullName = fullName; + } +} diff --git a/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java b/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java new file mode 100644 index 000000000..bcbaadfaa --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/def/EnumDefinition.java @@ -0,0 +1,139 @@ +package org.apollo.cache.def; + +import com.google.common.base.Preconditions; +import org.apollo.cache.decoder.rsenum.ScriptVarType; + +import java.util.HashMap; +import java.util.Map; + +public final class EnumDefinition { + + private static final Map definitions = new HashMap<>(); + + /** + * Gets the total number of enum definitions. + * + * @return The count. + */ + public static int count() { + return definitions.size(); + } + + /** + * Initialises the enum definitions. + * + * @param definitions The definitions. + * @throws RuntimeException If there is an id mismatch. + */ + public static void init(EnumDefinition[] definitions) { + for (int id = 0; id < definitions.length; id++) { + EnumDefinition def = definitions[id]; + if (def != null) { + if (def.getId() != id) { + throw new RuntimeException("Equipment definition id mismatch."); + } + EnumDefinition.definitions.put(def.getId(), def); + } + } + } + + /** + * Gets an enum definition by its id. + * + * @param id The id. + * @return {@code null} if the item is not enum, the definition otherwise. + * @throws IndexOutOfBoundsException If the id is out of bounds. + */ + public static EnumDefinition lookup(int id) { + Preconditions.checkElementIndex(id, EnumDefinition.count(), "Id out of bounds."); + return definitions.get(id); + } + + /** + * The enum id. + */ + private final int id; + + private ScriptVarType keyType = ScriptVarType.INTEGER; + private ScriptVarType valType = ScriptVarType.INTEGER; + private int defaultInt = 0; + private String defaultString = ""; + private HashMap intValues; + private HashMap stringValues; + + /** + * Creates a new enum definition. + * + * @param id The id. + */ + public EnumDefinition(int id) { + this.id = id; + } + + public int lookup(int id, int defaultInt) { + if (intValues == null) { + return id; + } + return intValues.getOrDefault(id, id); + } + + public String lookup(int id, String defaultString) { + if (stringValues == null) { + return defaultString; + } + return stringValues.getOrDefault(id, defaultString); + } + + public int getId() { + return id; + } + + public ScriptVarType getKeyType() { + return keyType; + } + + public void setKeyType(ScriptVarType keyType) { + this.keyType = keyType; + } + + public ScriptVarType getValType() { + return valType; + } + + public void setValType(ScriptVarType valType) { + this.valType = valType; + } + + public int getDefaultInt() { + return defaultInt; + } + + public void setDefaultInt(int defaultInt) { + this.defaultInt = defaultInt; + } + + public String getDefaultString() { + return defaultString; + } + + public void setDefaultString(String defaultString) { + this.defaultString = defaultString; + } + + public HashMap getIntValues() { + return intValues; + } + + public void setIntValues(HashMap intValues) { + this.intValues = intValues; + } + + public HashMap getStringValues() { + return stringValues; + } + + public void setStringValues(HashMap stringValues) { + this.stringValues = stringValues; + } +} + diff --git a/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java b/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java new file mode 100644 index 000000000..ff95824b7 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/def/HuffmanCodec.java @@ -0,0 +1,184 @@ +package org.apollo.cache.def; + +/** + * @author Khaled Abdeljaber + */ +public final class HuffmanCodec { + + private static HuffmanCodec codec; + + public static void init(int[] codes, byte[] codeLengths, int[] tree) { + codec = new HuffmanCodec(codes, codeLengths, tree); + } + + public static String decompress(byte[] compressed) { + return codec.decompress_(compressed); + } + + public static byte[] compress(String str) { + return codec.compress_(str, str.length() + 1); + } + + /** + * The codes of the huffman. + */ + private final int[] codes; + + /** + * The frequencies of the codes. + */ + private final byte[] codeLengths; + + /** + * The indicies of the tree. + */ + private final int[] tree; + + public HuffmanCodec(int[] codes, byte[] codeLengths, int[] tree) { + this.codes = codes; + this.codeLengths = codeLengths; + this.tree = tree; + } + + /** + * Decompress a string. + * + * @param compressed the compressed string. + * @return the decompressed string. + */ + String decompress_(byte[] compressed) { + if (compressed.length == 0) return ""; + + var len = compressed[0] & 0xFF; + var off = 1; + StringBuilder builder = new StringBuilder(); + + var index = 0; + for (; ; ) { + var compressedByte = compressed[off++]; + for (var mask = 0x80; mask != 0; mask >>= 1) { + if ((compressedByte & mask) == 0) { + index++; + } else { + index = tree[index]; + } + + var chr = tree[index]; + if (chr < 0) { + builder.append((char) ((chr & 0xFF) ^ 0xFF)); + if (builder.length() >= len) return builder.toString(); + + index = 0; + } + } + } + } + + /** + * Compress a string. + * + * @param str the str + * @return the length + */ + byte[] compress_(String str, int compressedLength) { + var uncompressedLength = str.length(); + var dest = new byte[compressedLength]; + + var bitPos = 8; + dest[0] = (byte) uncompressedLength; + if (uncompressedLength >= 0xFF) { + bitPos += 8; + dest[1] = (byte) ((uncompressedLength >> 16) & 0xFF); + } + + var key = 0; + for (var i = 0; i < uncompressedLength; i++) { + var character = lookup(str.charAt(i)) & 0xFF; + var code = codes[character]; + var length = codeLengths[character]; + + var off = bitPos >> 3; + var remainder = bitPos & 0x7; + var end = off + (length + remainder - 1 >> 3); + + key &= (-remainder >> 31); + bitPos += length; + + remainder += 24; + dest[off] = (byte) (key |= code >>> remainder); + + for (var j = 0; j < 4 && off < end; j++) { + remainder -= 8; + if (j == 3) { + dest[++off] = (byte) (key = code << -remainder); + } else { + dest[++off] = (byte) (key = code >>> remainder); + } + } + } + + return dest; + } + + private static byte lookup(char character) { + if (character > 0 && character < 128 || character >= 160 && character <= 255) { + return (byte) character; + } else if (character == 8364) { + return -128; + } else if (character == 8218) { + return -126; + } else if (character == 402) { + return -125; + } else if (character == 8222) { + return -124; + } else if (character == 8230) { + return -123; + } else if (character == 8224) { + return -122; + } else if (character == 8225) { + return -121; + } else if (character == 710) { + return -120; + } else if (character == 8240) { + return -119; + } else if (character == 352) { + return -118; + } else if (character == 8249) { + return -117; + } else if (character == 338) { + return -116; + } else if (character == 381) { + return -114; + } else if (character == 8216) { + return -111; + } else if (character == 8217) { + return -110; + } else if (character == 8220) { + return -109; + } else if (character == 8221) { + return -108; + } else if (character == 8226) { + return -107; + } else if (character == 8211) { + return -106; + } else if (character == 8212) { + return -105; + } else if (character == 732) { + return -104; + } else if (character == 8482) { + return -103; + } else if (character == 353) { + return -102; + } else if (character == 8250) { + return -101; + } else if (character == 339) { + return -100; + } else if (character == 382) { + return -98; + } else if (character == 376) { + return -97; + } else { + return 63; + } + } +} diff --git a/cache/src/main/java/org/apollo/cache/def/ItemDefinition.java b/cache/src/main/java/org/apollo/cache/def/ItemDefinition.java index 9c678f1dc..8140c580d 100644 --- a/cache/src/main/java/org/apollo/cache/def/ItemDefinition.java +++ b/cache/src/main/java/org/apollo/cache/def/ItemDefinition.java @@ -3,6 +3,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; /** * Represents a type of Item. @@ -54,12 +55,20 @@ public static void init(ItemDefinition[] definitions) { ItemDefinition.definitions = definitions; for (int id = 0; id < definitions.length; id++) { ItemDefinition def = definitions[id]; + if (def == null) { + ItemDefinition.definitions[id] = def = new ItemDefinition(id); + } + if (def.getId() != id) { throw new RuntimeException("Item definition id mismatch."); } if (def.isNote()) { - def.toNote(); + def.generate(ItemGenerationType.NOTE, ItemDefinition.lookup(def.getNoteInfoId()), + ItemDefinition.lookup(def.getNoteGraphicId())); notes.put(def.getNoteInfoId(), def.getId()); + } else if (def.isLoaner()) { + def.generate(ItemGenerationType.LOAN, ItemDefinition.lookup(def.getLoanInfo()), + ItemDefinition.lookup(def.getLoanGraphicId())); } } } @@ -159,6 +168,45 @@ public static int noteToItem(int id) { */ private int value = 1; + private int baseModel; + private int modelScale; + private int modelPitch; + private int modelRoll; + private int modelTranslateX; + private int modelTranslateY; + private int stackType; + private int primaryMaleModel; + private int maleYOffset; + private int secondaryMaleModel; + private int primaryFemaleModel; + private int femaleYOffset; + private int secondaryFemaleModel; + private short[] originalModelColors; + private short[] modifiedModelColors; + private short[] modifiedTextureColors; + private short[] originalTextureColors; + private boolean nonExchangeItem; + private int tertiaryMaleModel; + private int tertiaryFemaleModel; + private int maleHead; + private int femaleHead; + private int secondaryMaleHead; + private int secondaryFemaleHead; + private int modelYaw; + private int[] stackIds; + private int[] stackAmounts; + private int scaleX; + private int scaleY; + private int scaleZ; + private int shiftClickDropIndex; + private byte ambience; + private byte contrast; + private int loanInfo = -1; + private int loanGraphicId = -1; + private int placeHolderInfo; + private int placeHolderTemplate; + private Int2ObjectArrayMap parameters; + /** * Creates an item definition with the default values. * @@ -168,6 +216,7 @@ public ItemDefinition(int id) { this.id = id; } + /** * Gets the description of this item. * @@ -210,6 +259,158 @@ public String getInventoryAction(int id) { return inventoryActions[id]; } + public int getBaseModel() { + return baseModel; + } + + public int getModelScale() { + return modelScale; + } + + public int getModelPitch() { + return modelPitch; + } + + public int getModelRoll() { + return modelRoll; + } + + public int getModelTranslateX() { + return modelTranslateX; + } + + public int getModelTranslateY() { + return modelTranslateY; + } + + public int getStackType() { + return stackType; + } + + public int getPrimaryMaleModel() { + return primaryMaleModel; + } + + public int getMaleYOffset() { + return maleYOffset; + } + + public int getSecondaryMaleModel() { + return secondaryMaleModel; + } + + public int getPrimaryFemaleModel() { + return primaryFemaleModel; + } + + public int getFemaleYOffset() { + return femaleYOffset; + } + + public int getSecondaryFemaleModel() { + return secondaryFemaleModel; + } + + public short[] getOriginalModelColors() { + return originalModelColors; + } + + public short[] getModifiedModelColors() { + return modifiedModelColors; + } + + public short[] getModifiedTextureColors() { + return modifiedTextureColors; + } + + public short[] getOriginalTextureColors() { + return originalTextureColors; + } + + public boolean isNonExchangeItem() { + return nonExchangeItem; + } + + public int getTertiaryMaleModel() { + return tertiaryMaleModel; + } + + public int getTertiaryFemaleModel() { + return tertiaryFemaleModel; + } + + public int getMaleHead() { + return maleHead; + } + + public int getFemaleHead() { + return femaleHead; + } + + public int getSecondaryMaleHead() { + return secondaryMaleHead; + } + + public int getSecondaryFemaleHead() { + return secondaryFemaleHead; + } + + public int getModelYaw() { + return modelYaw; + } + + public int[] getStackIds() { + return stackIds; + } + + public int[] getStackAmounts() { + return stackAmounts; + } + + public int getScaleX() { + return scaleX; + } + + public int getScaleY() { + return scaleY; + } + + public int getScaleZ() { + return scaleZ; + } + + public int getShiftClickDropIndex() { + return shiftClickDropIndex; + } + + public byte getAmbience() { + return ambience; + } + + public byte getContrast() { + return contrast; + } + + public int getLoanInfo() { + return loanInfo; + } + + public int getLoanGraphicId() { + return loanGraphicId; + } + + public int getPlaceHolderInfo() { + return placeHolderInfo; + } + + public int getPlaceHolderTemplate() { + return placeHolderTemplate; + } + + public Int2ObjectArrayMap getParameters() { + return parameters; + } + /** * Gets this item's name. * @@ -273,6 +474,15 @@ public boolean isNote() { return noteGraphicId != -1 && noteInfoId != -1; } + /** + * Checks if this item is loaned. + * + * @return {@code true} if so, {@code false} otherwise. + */ + public boolean isLoaner() { + return loanInfo != -1 && loanGraphicId != -1; + } + /** * Checks if the item specified by this definition is stackable. * @@ -294,7 +504,7 @@ public void setDescription(String description) { /** * Sets a ground action. * - * @param id The id. + * @param id The id. * @param action The action. * @throws IndexOutOfBoundsException If the id is out of bounds. */ @@ -306,7 +516,7 @@ public void setGroundAction(int id, String action) { /** * Sets an inventory action. * - * @param id The id. + * @param id The id. * @param action The action. * @throws IndexOutOfBoundsException If the id is out of bounds. */ @@ -378,21 +588,180 @@ public void setValue(int value) { this.value = value; } - /** - * Converts this item to a note, if possible. - * - * @throws IllegalStateException If {@link ItemDefinition#isNote()} returns {@code false}. - */ - public void toNote() { - if (isNote()) { - if (description != null && description.startsWith("Swap this note at any bank for ")) { - return; // already converted. - } + public void setBaseModel(int baseModel) { + this.baseModel = baseModel; + } + + public void setModelScale(int modelScale) { + this.modelScale = modelScale; + } + + public void setModelPitch(int modelPitch) { + this.modelPitch = modelPitch; + } + + public void setModelRoll(int modelRoll) { + this.modelRoll = modelRoll; + } + + public void setModelTranslateX(int modelTranslateX) { + this.modelTranslateX = modelTranslateX; + } + + public void setModelTranslateY(int modelTranslateY) { + this.modelTranslateY = modelTranslateY; + } + + public void setStackType(int stackType) { + this.stackType = stackType; + } + + public void setPrimaryMaleModel(int primaryMaleModel) { + this.primaryMaleModel = primaryMaleModel; + } + + public void setMaleYOffset(int maleYOffset) { + this.maleYOffset = maleYOffset; + } + + public void setSecondaryMaleModel(int secondaryMaleModel) { + this.secondaryMaleModel = secondaryMaleModel; + } + + public void setPrimaryFemaleModel(int primaryFemaleModel) { + this.primaryFemaleModel = primaryFemaleModel; + } + + public void setFemaleYOffset(int femaleYOffset) { + this.femaleYOffset = femaleYOffset; + } + + public void setSecondaryFemaleModel(int secondaryFemaleModel) { + this.secondaryFemaleModel = secondaryFemaleModel; + } + + public void setOriginalModelColors(short[] originalModelColors) { + this.originalModelColors = originalModelColors; + } + + public void setModifiedModelColors(short[] modifiedModelColors) { + this.modifiedModelColors = modifiedModelColors; + } + + public void setModifiedTextureColors(short[] modifiedTextureColors) { + this.modifiedTextureColors = modifiedTextureColors; + } + + public void setOriginalTextureColors(short[] originalTextureColors) { + this.originalTextureColors = originalTextureColors; + } + + public void setNonExchangeItem(boolean nonExchangeItem) { + this.nonExchangeItem = nonExchangeItem; + } - ItemDefinition infoDef = lookup(noteInfoId); - name = infoDef.name; - members = infoDef.members; + public void setTertiaryMaleModel(int tertiaryMaleModel) { + this.tertiaryMaleModel = tertiaryMaleModel; + } + + public void setTertiaryFemaleModel(int tertiaryFemaleModel) { + this.tertiaryFemaleModel = tertiaryFemaleModel; + } + + public void setMaleHead(int maleHead) { + this.maleHead = maleHead; + } + + public void setFemaleHead(int femaleHead) { + this.femaleHead = femaleHead; + } + + public void setSecondaryMaleHead(int secondaryMaleHead) { + this.secondaryMaleHead = secondaryMaleHead; + } + + public void setSecondaryFemaleHead(int secondaryFemaleHead) { + this.secondaryFemaleHead = secondaryFemaleHead; + } + + public void setModelYaw(int modelYaw) { + this.modelYaw = modelYaw; + } + + public void setStackIds(int[] stackIds) { + this.stackIds = stackIds; + } + + public void setStackAmounts(int[] stackAmounts) { + this.stackAmounts = stackAmounts; + } + + public void setScaleX(int scaleX) { + this.scaleX = scaleX; + } + + public void setScaleY(int scaleY) { + this.scaleY = scaleY; + } + public void setScaleZ(int scaleZ) { + this.scaleZ = scaleZ; + } + + public void setShiftClickDropIndex(int shiftClickDropIndex) { + this.shiftClickDropIndex = shiftClickDropIndex; + } + + public void setAmbience(byte ambience) { + this.ambience = ambience; + } + + public void setContrast(byte contrast) { + this.contrast = contrast; + } + + public void setLoanInfo(int loanInfo) { + this.loanInfo = loanInfo; + } + + public void setLoanGraphicId(int loanGraphicId) { + this.loanGraphicId = loanGraphicId; + } + + public void setPlaceHolderInfo(int placeHolderInfo) { + this.placeHolderInfo = placeHolderInfo; + } + + public void setPlaceHolderTemplate(int placeHolderTemplate) { + this.placeHolderTemplate = placeHolderTemplate; + } + + public void setParameters(Int2ObjectArrayMap parameters) { + this.parameters = parameters; + } + + public enum ItemGenerationType { + NOTE, LOAN, BOUGHT, COMBINE + } + + void generate(ItemGenerationType type, ItemDefinition template, ItemDefinition info) { + baseModel = template.baseModel; + modelScale = template.modelScale; + modelPitch = template.modelPitch; + modelRoll = template.modelRoll; + modelYaw = template.modelYaw; + modelTranslateX = template.modelTranslateX; + modelTranslateY = template.modelTranslateY; + + ItemDefinition replacements = (type == ItemGenerationType.NOTE) ? template : info; + originalModelColors = replacements.originalModelColors; + modifiedModelColors = replacements.modifiedModelColors; + originalTextureColors = replacements.originalTextureColors; + modifiedTextureColors = replacements.modifiedTextureColors; + + name = info.name; + members = info.members; + if (type == ItemGenerationType.NOTE) { String prefix = "a"; char firstChar = name == null ? 'n' : name.charAt(0); @@ -400,12 +769,28 @@ public void toNote() { prefix = "an"; } + value = info.value; + stackType = 1; description = "Swap this note at any bank for " + prefix + " " + name + "."; - value = infoDef.value; - stackable = true; } else { - throw new IllegalStateException("Item cannot be noted."); + value = 0; + stackType = info.stackType; + primaryMaleModel = info.primaryMaleModel; + secondaryMaleModel = info.secondaryMaleModel; + tertiaryMaleModel = info.tertiaryMaleModel; + primaryFemaleModel = info.primaryFemaleModel; + secondaryFemaleModel = info.secondaryFemaleModel; + tertiaryFemaleModel = info.tertiaryFemaleModel; + maleHead = info.maleHead; + secondaryMaleHead = info.secondaryMaleHead; + femaleHead = info.femaleHead; + secondaryFemaleHead = info.secondaryFemaleHead; + team = info.team; + System.arraycopy(info.groundActions, 0, groundActions, 0, groundActions.length); + System.arraycopy(info.inventoryActions, 0, inventoryActions, 0, 4); + parameters = info.parameters; + inventoryActions[4] = "Discard"; + value = 0; } } - } diff --git a/cache/src/main/java/org/apollo/cache/def/NpcDefinition.java b/cache/src/main/java/org/apollo/cache/def/NpcDefinition.java index 0e81396de..a01010b2f 100644 --- a/cache/src/main/java/org/apollo/cache/def/NpcDefinition.java +++ b/cache/src/main/java/org/apollo/cache/def/NpcDefinition.java @@ -1,6 +1,7 @@ package org.apollo.cache.def; import com.google.common.base.Preconditions; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; /** * Represents a type of Npc. @@ -94,6 +95,30 @@ public static NpcDefinition lookup(int id) { * The various animation ids. */ private int standAnim = -1, walkAnim = -1, walkBackAnim = -1, walkLeftAnim = -1, walkRightAnim = -1; + private int turnLeftSequence = -1; + private int turnRightSequence = -1; + + private short[] originalColours; + private int rotation; + private short[] replacementColours; + private int[] models; + private int[] headModels; + private short[] replacementTextures; + private boolean slowWalk; + private int scaleX; + private int contrast; + private int varbit; + private boolean drawMapdot; + private int scaleY; + private boolean priority; + private int ambience; + private int headIcon; + private int[] morphisms; + private short[] originalTextures; + private int varp; + private boolean isClickable; + private boolean animateIdle; + private Int2ObjectArrayMap parameters; /** * Creates a new npc definition. @@ -302,7 +327,7 @@ public void setDescription(String description) { /** * Sets an interaction option. * - * @param slot The slot of the option. + * @param slot The slot of the option. * @param interaction The interaction options. * @throws IndexOutOfBoundsException If the slot is out of bounds. */ @@ -350,9 +375,9 @@ public void setWalkAnimation(int walkAnim) { /** * Sets the various walking animations of the npc. * - * @param walkAnim The walking animation. - * @param walkBackAnim The walk-back animation. - * @param walkLeftAnim The walk-left animation. + * @param walkAnim The walking animation. + * @param walkBackAnim The walk-back animation. + * @param walkLeftAnim The walk-left animation. * @param walkRightAnim The walk-right animation. */ public void setWalkAnimations(int walkAnim, int walkBackAnim, int walkLeftAnim, int walkRightAnim) { @@ -362,4 +387,187 @@ public void setWalkAnimations(int walkAnim, int walkBackAnim, int walkLeftAnim, this.walkRightAnim = walkRightAnim; } + public int getTurnLeftSequence() { + return turnLeftSequence; + } + + public void setTurnLeftSequence(int turnLeftSequence) { + this.turnLeftSequence = turnLeftSequence; + } + + public int getTurnRightSequence() { + return turnRightSequence; + } + + public void setTurnRightSequence(int turnRightSequence) { + this.turnRightSequence = turnRightSequence; + } + + public short[] getOriginalColours() { + return originalColours; + } + + public void setOriginalColours(short[] originalColours) { + this.originalColours = originalColours; + } + + public int getRotation() { + return rotation; + } + + public void setRotation(int rotation) { + this.rotation = rotation; + } + + public short[] getReplacementColours() { + return replacementColours; + } + + public void setReplacementColours(short[] replacementColours) { + this.replacementColours = replacementColours; + } + + public int[] getModels() { + return models; + } + + public void setModels(int[] models) { + this.models = models; + } + + public int[] getHeadModels() { + return headModels; + } + + public void setHeadModels(int[] headModels) { + this.headModels = headModels; + } + + public short[] getReplacementTextures() { + return replacementTextures; + } + + public void setReplacementTextures(short[] replacementTextures) { + this.replacementTextures = replacementTextures; + } + + public boolean isSlowWalk() { + return slowWalk; + } + + public void setSlowWalk(boolean slowWalk) { + this.slowWalk = slowWalk; + } + + public int getScaleX() { + return scaleX; + } + + public void setScaleX(int scaleX) { + this.scaleX = scaleX; + } + + public int getContrast() { + return contrast; + } + + public void setContrast(int contrast) { + this.contrast = contrast; + } + + public int getVarbit() { + return varbit; + } + + public void setVarbit(int varbit) { + this.varbit = varbit; + } + + public boolean isDrawMapdot() { + return drawMapdot; + } + + public void setDrawMapdot(boolean drawMapdot) { + this.drawMapdot = drawMapdot; + } + + public int getScaleY() { + return scaleY; + } + + public void setScaleY(int scaleY) { + this.scaleY = scaleY; + } + + public boolean isPriority() { + return priority; + } + + public void setPriority(boolean priority) { + this.priority = priority; + } + + public int getAmbience() { + return ambience; + } + + public void setAmbience(int ambience) { + this.ambience = ambience; + } + + public int getHeadIcon() { + return headIcon; + } + + public void setHeadIcon(int headIcon) { + this.headIcon = headIcon; + } + + public int[] getMorphisms() { + return morphisms; + } + + public void setMorphisms(int[] morphisms) { + this.morphisms = morphisms; + } + + public short[] getOriginalTextures() { + return originalTextures; + } + + public void setOriginalTextures(short[] originalTextures) { + this.originalTextures = originalTextures; + } + + public int getVarp() { + return varp; + } + + public void setVarp(int varp) { + this.varp = varp; + } + + public boolean isClickable() { + return isClickable; + } + + public void setClickable(boolean clickable) { + isClickable = clickable; + } + + public boolean isAnimateIdle() { + return animateIdle; + } + + public void setAnimateIdle(boolean animateIdle) { + this.animateIdle = animateIdle; + } + + public Int2ObjectArrayMap getParameters() { + return parameters; + } + + public void setParameters(Int2ObjectArrayMap parameters) { + this.parameters = parameters; + } } \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/def/ObjectDefinition.java b/cache/src/main/java/org/apollo/cache/def/ObjectDefinition.java index 8f0543076..7cbe6f7e0 100644 --- a/cache/src/main/java/org/apollo/cache/def/ObjectDefinition.java +++ b/cache/src/main/java/org/apollo/cache/def/ObjectDefinition.java @@ -1,6 +1,7 @@ package org.apollo.cache.def; import com.google.common.base.Preconditions; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; /** * Represents a type of GameObject. @@ -110,6 +111,45 @@ public static ObjectDefinition lookup(int id) { */ private int width = 1; + private int[] types; + private int[][] models; + private int height; + private int collisionType; + private int adjustValue; + private boolean dynamicShading; + private byte occludes; + private int decorationDisplacement; + private int contrast; + private int ambience; + private short[] originalColours; + private short[] replacementColours; + private short[] originalTextures; + private short[] replacementTextures; + private boolean mirrorModel; + private boolean castsShadow; + private int scaleX; + private int scaleY; + private int scaleZ; + private int mapscene; + private int rotationFlag; + private int translateX; + private int translateY; + private int translateZ; + private boolean decoration; + private int holdsItemPiles; + private int varbit; + private int varp; + private int[] morphisms; + private int sound; + private int soundRadius; + private int soundDelayMinDuration; + private int soundDelayMaxDuration; + private int[] sounds; + private boolean members; + private int mapSceneType; + private int[] animations; + private Int2ObjectMap parameters; + /** * Creates a new object definition. * @@ -290,4 +330,307 @@ public void setObstructive(boolean obstructive) { this.obstructive = obstructive; } + public int[] getTypes() { + return types; + } + + public void setTypes(int[] types) { + this.types = types; + } + + public int[][] getModels() { + return models; + } + + public void setModels(int[][] models) { + this.models = models; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public int getCollisionType() { + return collisionType; + } + + public void setCollisionType(int collisionType) { + this.collisionType = collisionType; + } + + public int getAdjustValue() { + return adjustValue; + } + + public void setAdjustValue(int adjustValue) { + this.adjustValue = adjustValue; + } + + public boolean isDynamicShading() { + return dynamicShading; + } + + public void setDynamicShading(boolean dynamicShading) { + this.dynamicShading = dynamicShading; + } + + public byte getOccludes() { + return occludes; + } + + public void setOccludes(byte occludes) { + this.occludes = occludes; + } + + public int getDecorationDisplacement() { + return decorationDisplacement; + } + + public void setDecorationDisplacement(int decorationDisplacement) { + this.decorationDisplacement = decorationDisplacement; + } + + public int getContrast() { + return contrast; + } + + public void setContrast(int contrast) { + this.contrast = contrast; + } + + public int getAmbience() { + return ambience; + } + + public void setAmbience(int ambience) { + this.ambience = ambience; + } + + public short[] getOriginalColours() { + return originalColours; + } + + public void setOriginalColours(short[] originalColours) { + this.originalColours = originalColours; + } + + public short[] getReplacementColours() { + return replacementColours; + } + + public void setReplacementColours(short[] replacementColours) { + this.replacementColours = replacementColours; + } + + public short[] getOriginalTextures() { + return originalTextures; + } + + public void setOriginalTextures(short[] originalTextures) { + this.originalTextures = originalTextures; + } + + public short[] getReplacementTextures() { + return replacementTextures; + } + + public void setReplacementTextures(short[] replacementTextures) { + this.replacementTextures = replacementTextures; + } + + public boolean isMirrorModel() { + return mirrorModel; + } + + public void setMirrorModel(boolean mirrorModel) { + this.mirrorModel = mirrorModel; + } + + public boolean isCastsShadow() { + return castsShadow; + } + + public void setCastsShadow(boolean castsShadow) { + this.castsShadow = castsShadow; + } + + public int getScaleX() { + return scaleX; + } + + public void setScaleX(int scaleX) { + this.scaleX = scaleX; + } + + public int getScaleY() { + return scaleY; + } + + public void setScaleY(int scaleY) { + this.scaleY = scaleY; + } + + public int getScaleZ() { + return scaleZ; + } + + public void setScaleZ(int scaleZ) { + this.scaleZ = scaleZ; + } + + public int getMapscene() { + return mapscene; + } + + public void setMapscene(int mapscene) { + this.mapscene = mapscene; + } + + public int getRotationFlag() { + return rotationFlag; + } + + public void setRotationFlag(int rotationFlag) { + this.rotationFlag = rotationFlag; + } + + public int getTranslateX() { + return translateX; + } + + public void setTranslateX(int translateX) { + this.translateX = translateX; + } + + public int getTranslateY() { + return translateY; + } + + public void setTranslateY(int translateY) { + this.translateY = translateY; + } + + public int getTranslateZ() { + return translateZ; + } + + public void setTranslateZ(int translateZ) { + this.translateZ = translateZ; + } + + public boolean isDecoration() { + return decoration; + } + + public void setDecoration(boolean decoration) { + this.decoration = decoration; + } + + public int getHoldsItemPiles() { + return holdsItemPiles; + } + + public void setHoldsItemPiles(int holdsItemPiles) { + this.holdsItemPiles = holdsItemPiles; + } + + public int getVarbit() { + return varbit; + } + + public void setVarbit(int varbit) { + this.varbit = varbit; + } + + public int getVarp() { + return varp; + } + + public void setVarp(int varp) { + this.varp = varp; + } + + public int[] getMorphisms() { + return morphisms; + } + + public void setMorphisms(int[] morphisms) { + this.morphisms = morphisms; + } + + public int getSound() { + return sound; + } + + public void setSound(int f2117) { + this.sound = f2117; + } + + public int getSoundRadius() { + return soundRadius; + } + + public void setSoundRadius(int soundRadius) { + this.soundRadius = soundRadius; + } + + public int getSoundDelayMinDuration() { + return soundDelayMinDuration; + } + + public void setSoundDelayMinDuration(int soundDelayMinDuration) { + this.soundDelayMinDuration = soundDelayMinDuration; + } + + public int getSoundDelayMaxDuration() { + return soundDelayMaxDuration; + } + + public void setSoundDelayMaxDuration(int soundDelayMaxDuration) { + this.soundDelayMaxDuration = soundDelayMaxDuration; + } + + public int[] getSounds() { + return sounds; + } + + public void setSounds(int[] sounds) { + this.sounds = sounds; + } + + public boolean isMembers() { + return members; + } + + public void setMembers(boolean members) { + this.members = members; + } + + public int getMapSceneType() { + return mapSceneType; + } + + public void setMapSceneType(int mapSceneType) { + this.mapSceneType = mapSceneType; + } + + public int[] getAnimations() { + return animations; + } + + public void setAnimations(int[] animations) { + this.animations = animations; + } + + public Int2ObjectMap getParameters() { + return parameters; + } + + public void setParameters(Int2ObjectMap parameters) { + this.parameters = parameters; + } } \ No newline at end of file diff --git a/cache/src/main/java/org/apollo/cache/map/MapConstants.java b/cache/src/main/java/org/apollo/cache/map/MapConstants.java index 634929787..cc0e1f047 100644 --- a/cache/src/main/java/org/apollo/cache/map/MapConstants.java +++ b/cache/src/main/java/org/apollo/cache/map/MapConstants.java @@ -10,7 +10,7 @@ public final class MapConstants { /** * The index containing the map files. */ - public static final int MAP_INDEX = 4; + public static final int MAP_INDEX = 5; /** * The width (and length) of a {@link MapFile} in {@link Tile}s. diff --git a/cache/src/main/java/org/apollo/cache/map/MapIndex.java b/cache/src/main/java/org/apollo/cache/map/MapIndex.java index 9b707c85c..f5e3fe0e6 100644 --- a/cache/src/main/java/org/apollo/cache/map/MapIndex.java +++ b/cache/src/main/java/org/apollo/cache/map/MapIndex.java @@ -1,9 +1,9 @@ package org.apollo.cache.map; -import org.apollo.cache.def.ItemDefinition; +import org.apollo.cache.Group; +import java.lang.ref.WeakReference; import java.util.Collections; -import java.util.HashMap; import java.util.Map; /** @@ -11,115 +11,114 @@ */ public final class MapIndex { - /** - * Indicates whether or not this map is members-only. - */ - private final boolean members; - - /** - * The object file id. - */ - private final int objects; - - /** - * The packed coordinates. - */ - private final int packedCoordinates; - - /** - * The terrain file id. - */ - private final int terrain; - - /** - * A mapping of region ids to {@link MapIndex}es. - */ - private static Map indices; - - /** - * Initialises the class with the specified set of indices. - */ - public static void init(Map indices) { - MapIndex.indices = Collections.unmodifiableMap(indices); - } - - /** - * Gets the {@code Map} of {@link MapIndex} instances. - * - * @return The map of {@link MapIndex} instances. - */ - public static Map getIndices() { - return indices; - } - - /** - * Creates the {@link MapIndex}. - * - * @param packedCoordinates The packed coordinates. - * @param terrain The terrain file id. - * @param objects The object file id. - * @param members Indicates whether or not this map is members-only. - */ - public MapIndex(int packedCoordinates, int terrain, int objects, boolean members) { - this.packedCoordinates = packedCoordinates; - this.terrain = terrain; - this.objects = objects; - this.members = members; - } - - /** - * Gets the id of the file containing the object data. - * - * @return The file id. - */ - public int getObjectFile() { - return objects; - } - - /** - * Gets the packed coordinates. - * - * @return The packed coordinates. - */ - public int getPackedCoordinates() { - return packedCoordinates; - } - - /** - * Gets the id of the file containing the terrain data. - * - * @return The file id. - */ - public int getMapFile() { - return terrain; - } - - /** - * Gets the X coordinate of this map. - * - * @return The X coordinate of this map. - */ - public int getX() { - return (packedCoordinates >> 8 & 0xFF) * MapConstants.MAP_WIDTH; - } - - /** - * Gets the Y coordinate of this map. - * - * @return The y coordinate of this map. - */ - public int getY() { - return (packedCoordinates & 0xFF) * MapConstants.MAP_WIDTH; - - } - - /** - * Returns whether or not this MapIndex is for a members-only area of the world. - * - * @return {@code true} if this MapIndex is for a members-only area, {@code false} if not. - */ - public boolean isMembersOnly() { - return members; - } + /** + * Indicates whether or not this map is members-only. + */ + private final boolean members; + + /** + * The object file id. + */ + private final WeakReference landscapeFolder; + + /** + * The packed coordinates. + */ + private final int packedCoordinates; + + /** + * The terrain file id. + */ + private final WeakReference terrainFolder; + + /** + * A mapping of region ids to {@link MapIndex}es. + */ + private static Map indices; + + /** + * Initialises the class with the specified set of indices. + */ + public static void init(Map indices) { + MapIndex.indices = Collections.unmodifiableMap(indices); + } + + /** + * Gets the {@code Map} of {@link MapIndex} instances. + * + * @return The map of {@link MapIndex} instances. + */ + public static Map getIndices() { + return indices; + } + + /** + * Creates the {@link MapIndex}. + * @param packedCoordinates The packed coordinates. + * @param terrainGroup The terrain file id. + * @param landscapeGroup The object file id. + * @param members Indicates whether or not this map is members-only. + */ + public MapIndex(int packedCoordinates, Group terrainGroup, Group landscapeGroup, boolean members) { + this.packedCoordinates = packedCoordinates; + this.terrainFolder = new WeakReference<>(terrainGroup); + this.landscapeFolder = new WeakReference<>(landscapeGroup); + this.members = members; + } + + /** + * Gets the id of the file containing the object data. + * + * @return The file id. + */ + public WeakReference getLandscapeFolder() { + return landscapeFolder; + } + + /** + * Gets the packed coordinates. + * + * @return The packed coordinates. + */ + public int getPackedCoordinates() { + return packedCoordinates; + } + + /** + * Gets the id of the file containing the terrain data. + * + * @return The file id. + */ + public WeakReference getTerrainFolder() { + return terrainFolder; + } + + /** + * Gets the X coordinate of this map. + * + * @return The X coordinate of this map. + */ + public int getX() { + return (packedCoordinates >> 8 & 0xFF) * MapConstants.MAP_WIDTH; + } + + /** + * Gets the Y coordinate of this map. + * + * @return The y coordinate of this map. + */ + public int getY() { + return (packedCoordinates & 0xFF) * MapConstants.MAP_WIDTH; + + } + + /** + * Returns whether or not this MapIndex is for a members-only area of the world. + * + * @return {@code true} if this MapIndex is for a members-only area, {@code false} if not. + */ + public boolean isMembersOnly() { + return members; + } } diff --git a/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java b/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java index 7bca2addc..4b10d398a 100644 --- a/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java +++ b/cache/src/main/java/org/apollo/cache/map/MapIndexDecoder.java @@ -1,18 +1,15 @@ package org.apollo.cache.map; +import org.apollo.cache.Cache; +import org.apollo.cache.Archive; + import java.io.IOException; import java.io.UncheckedIOException; -import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; -import org.apollo.cache.IndexedFileSystem; -import org.apollo.cache.archive.Archive; -import org.apollo.cache.archive.ArchiveEntry; -import org.apollo.cache.map.MapIndex; - /** - * Decodes {@link MapIndex}s from the {@link IndexedFileSystem}. + * Decodes {@link MapIndex}s from the {@link Archive}. * * @author Ryley * @author Major @@ -25,35 +22,42 @@ public final class MapIndexDecoder implements Runnable { private static final int VERSIONS_ARCHIVE_FILE_ID = 5; /** - * The IndexedFileSystem. + * The Cache. */ - private final IndexedFileSystem fs; + private final Cache cache; + private final XteaRepository xteaRepository; - public MapIndexDecoder(IndexedFileSystem fs) { - this.fs = fs; + public MapIndexDecoder(Cache cache, XteaRepository xteaRepository) { + this.cache = cache; + this.xteaRepository = xteaRepository; } /** - * Decodes {@link MapIndex}s from the specified {@link IndexedFileSystem}. + * Decodes {@link MapIndex}s from the specified {@link Archive}. * * @return A {@link Map} of packed coordinates to their MapDefinitions. * @throws IOException If there is an error reading or decoding the Archive. */ public Map decode() throws IOException { - Archive archive = fs.getArchive(0, VERSIONS_ARCHIVE_FILE_ID); - ArchiveEntry entry = archive.getEntry("map_index"); Map definitions = new HashMap<>(); - ByteBuffer buffer = entry.getBuffer(); - int count = buffer.capacity() / (3 * Short.BYTES + Byte.BYTES); + final var fs = cache.getArchive(MapConstants.MAP_INDEX); + for (var entry : xteaRepository.getAll()) { + final var region = entry.getIntKey(); + final var regionX = region >> 8; + final var regionY = region & 0xFF; + + try { + final var terrainFolder = fs.findFolderByName("m" + regionX + "_" + regionY); + final var landscapeFolder = fs.findFolderByName("l" + regionX + "_" + regionY, entry.getValue()); + if (landscapeFolder == null) { + continue; + } - for (int times = 0; times < count; times++) { - int id = buffer.getShort() & 0xFFFF; - int terrain = buffer.getShort() & 0xFFFF; - int objects = buffer.getShort() & 0xFFFF; - boolean members = buffer.get() == 1; + definitions.put(region, new MapIndex(region, terrainFolder, landscapeFolder, true)); + } catch (Throwable e) { - definitions.put(id, new MapIndex(id, terrain, objects, members)); + } } return definitions; @@ -62,6 +66,7 @@ public Map decode() throws IOException { @Override public void run() { try { + xteaRepository.run(); MapIndex.init(decode()); } catch (IOException e) { throw new UncheckedIOException(e); diff --git a/cache/src/main/java/org/apollo/cache/map/MapObjectsDecoder.java b/cache/src/main/java/org/apollo/cache/map/MapLandscapeDecoder.java similarity index 60% rename from cache/src/main/java/org/apollo/cache/map/MapObjectsDecoder.java rename to cache/src/main/java/org/apollo/cache/map/MapLandscapeDecoder.java index 351ea7d7e..f0f7afe7f 100644 --- a/cache/src/main/java/org/apollo/cache/map/MapObjectsDecoder.java +++ b/cache/src/main/java/org/apollo/cache/map/MapLandscapeDecoder.java @@ -1,11 +1,7 @@ package org.apollo.cache.map; -import org.apollo.cache.IndexedFileSystem; -import org.apollo.cache.map.MapIndex; -import org.apollo.cache.map.MapConstants; -import org.apollo.cache.map.MapObject; +import org.apollo.cache.CacheBuffer; import org.apollo.util.BufferUtil; -import org.apollo.util.CompressionUtil; import java.io.IOException; import java.nio.ByteBuffer; @@ -17,20 +13,20 @@ * * @author Major */ -public final class MapObjectsDecoder { +public final class MapLandscapeDecoder { /** * Creates a MapObjectsDecoder for the specified map file. * - * @param fs The {@link IndexedFileSystem} to get the file from. * @param index The map index to decode objects for. * @return The MapObjectsDecoder. * @throws IOException If there is an error reading or decompressing the file. */ - public static MapObjectsDecoder create(IndexedFileSystem fs, MapIndex index) throws IOException { - ByteBuffer compressed = fs.getFile(MapConstants.MAP_INDEX, index.getObjectFile()); - ByteBuffer decompressed = ByteBuffer.wrap(CompressionUtil.degzip(compressed)); - - return new MapObjectsDecoder(decompressed); + public static MapLandscapeDecoder create(MapIndex index) throws IOException { + final var folder = index.getLandscapeFolder().get(); + if (folder == null) { + return null; + } + return new MapLandscapeDecoder(folder.findRSFileByID(0).getData()); } /** @@ -39,12 +35,12 @@ public static MapObjectsDecoder create(IndexedFileSystem fs, MapIndex index) thr private final ByteBuffer buffer; /** - * Create a new {@link MapObjectsDecoder} from the given buffer and map coordinates. + * Create a new {@link MapLandscapeDecoder} from the given buffer and map coordinates. * * @param buffer The decompressed object file buffer. */ - public MapObjectsDecoder(ByteBuffer buffer) { - this.buffer = buffer.asReadOnlyBuffer(); + public MapLandscapeDecoder(CacheBuffer buffer) { + this.buffer = ByteBuffer.wrap(buffer.getBuffer()); } /** @@ -56,7 +52,7 @@ public List decode() { List objects = new ArrayList<>(); int id = -1; - int idOffset = BufferUtil.readSmart(buffer); + int idOffset = BufferUtil.readHugeSmart(buffer); while (idOffset != 0) { id += idOffset; @@ -75,7 +71,7 @@ public List decode() { positionOffset = BufferUtil.readSmart(buffer); } - idOffset = BufferUtil.readSmart(buffer); + idOffset = BufferUtil.readHugeSmart(buffer); } return objects; diff --git a/cache/src/main/java/org/apollo/cache/map/MapFileDecoder.java b/cache/src/main/java/org/apollo/cache/map/MapTerrainDecoder.java similarity index 76% rename from cache/src/main/java/org/apollo/cache/map/MapFileDecoder.java rename to cache/src/main/java/org/apollo/cache/map/MapTerrainDecoder.java index e85ae5e28..f4693bd10 100644 --- a/cache/src/main/java/org/apollo/cache/map/MapFileDecoder.java +++ b/cache/src/main/java/org/apollo/cache/map/MapTerrainDecoder.java @@ -1,30 +1,29 @@ package org.apollo.cache.map; -import org.apollo.cache.IndexedFileSystem; -import org.apollo.util.CompressionUtil; +import org.apollo.cache.CacheBuffer; -import java.nio.ByteBuffer; import java.io.IOException; +import java.nio.ByteBuffer; /** * A decoder for the terrain data stored in {@link MapFile}s. * * @author Major */ -public class MapFileDecoder { +public class MapTerrainDecoder { /** * Creates a MapFileDecoder for the specified map file. * - * @param fs The {@link IndexedFileSystem} to get the file from. * @param index The {@link MapIndex} to get the file index from. * @return The MapFileDecoder. * @throws IOException If there is an error reading or decompressing the file. */ - public static MapFileDecoder create(IndexedFileSystem fs, MapIndex index) throws IOException { - ByteBuffer compressed = fs.getFile(MapConstants.MAP_INDEX, index.getMapFile()); - ByteBuffer decompressed = ByteBuffer.wrap(CompressionUtil.degzip(compressed)); - - return new MapFileDecoder(decompressed); + public static MapTerrainDecoder create(MapIndex index) throws IOException { + final var folder = index.getTerrainFolder().get(); + if (folder == null) { + return null; + } + return new MapTerrainDecoder(folder.findRSFileByID(0).getData()); } /** @@ -39,8 +38,8 @@ public static MapFileDecoder create(IndexedFileSystem fs, MapIndex index) throws * * @param buffer The DataBuffer containing the MapFile data. */ - public MapFileDecoder(ByteBuffer buffer) { - this.buffer = buffer.asReadOnlyBuffer(); + public MapTerrainDecoder(CacheBuffer buffer) { + this.buffer = ByteBuffer.wrap(buffer.getBuffer()); } /** @@ -62,7 +61,7 @@ public MapFile decode() { * Decodes a {@link MapPlane} with the specified level. * * @param planes The previously-decoded {@link MapPlane}s, for calculating the height of the tiles. - * @param level The level. + * @param level The level. * @return The MapPlane. */ private MapPlane decodePlane(MapPlane[] planes, int level) { @@ -81,9 +80,9 @@ private MapPlane decodePlane(MapPlane[] planes, int level) { * Decodes the data into a {@link Tile}. * * @param planes The previously-decoded {@link MapPlane}s, for calculating the height of the Tile. - * @param level The level the Tile is on. - * @param x The x coordinate of the Tile. - * @param z The z coordinate of the Tile. + * @param level The level the Tile is on. + * @param x The x coordinate of the Tile. + * @param z The z coordinate of the Tile. * @return The MapFile. */ private Tile decodeTile(MapPlane[] planes, int level, int x, int z) { @@ -107,10 +106,9 @@ private Tile decodeTile(MapPlane[] planes, int level, int x, int z) { builder.setHeight((height == 1 ? 0 : height) * MapConstants.HEIGHT_MULTIPLICAND + below); } else if (type <= MapConstants.MINIMUM_OVERLAY_TYPE) { builder.setOverlay(buffer.get()); - builder.setOverlayType((type - MapConstants.LOWEST_CONTINUED_TYPE) - / MapConstants.ORIENTATION_COUNT); - builder.setOverlayOrientation(type - MapConstants.LOWEST_CONTINUED_TYPE - % MapConstants.ORIENTATION_COUNT); + builder.setOverlayType((type - MapConstants.LOWEST_CONTINUED_TYPE) / MapConstants.ORIENTATION_COUNT); + builder.setOverlayOrientation( + type - MapConstants.LOWEST_CONTINUED_TYPE % MapConstants.ORIENTATION_COUNT); } else if (type <= MapConstants.MINIMUM_ATTRIBUTES_TYPE) { builder.setAttributes(type - MapConstants.MINIMUM_OVERLAY_TYPE); } else { diff --git a/cache/src/main/java/org/apollo/cache/map/XteaRepository.java b/cache/src/main/java/org/apollo/cache/map/XteaRepository.java new file mode 100644 index 000000000..389ffebf0 --- /dev/null +++ b/cache/src/main/java/org/apollo/cache/map/XteaRepository.java @@ -0,0 +1,66 @@ +package org.apollo.cache.map; + +import com.fasterxml.jackson.annotation.JsonProperty; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.File; +import java.io.IOException; + +public class XteaRepository implements Runnable { + + private static final int[] DEFAULT = {0, 0, 0, 0}; + + public static class Xtea { + private final int region; + private final int[] keys; + + public Xtea(@JsonProperty("region") int region, @JsonProperty("keys") int[] keys) { + this.region = region; + this.keys = keys; + } + + public int getRegion() { + return region; + } + + public int[] getKeys() { + return keys; + } + } + + private final int release; + private final Int2ObjectArrayMap xteas; + + public XteaRepository(int release) { + this.xteas = new Int2ObjectArrayMap<>(); + this.release = release; + } + + @Override + public void run() { + File file = new File("./data/fs/" + release + "/xtea.json"); + try { + var mapper = new ObjectMapper(); + var xteas = mapper.readValue(file, Xtea[].class); + for (var xtea : xteas) { + this.xteas.put(xtea.region, xtea.getKeys()); + } + } catch (IOException io) { + io.printStackTrace(); + } + } + + public int[] get(int region) { + return xteas.getOrDefault(region, DEFAULT); + } + + public int[] get(int x, int y) { + return get(x << 8 | y); + } + + public Int2ObjectMap.FastEntrySet getAll() { + return xteas.int2ObjectEntrySet(); + } +} diff --git a/cache/src/main/java/org/apollo/cache/tools/EquipmentUpdater.java b/cache/src/main/java/org/apollo/cache/tools/EquipmentUpdater.java index 7345704c5..97486fc8a 100644 --- a/cache/src/main/java/org/apollo/cache/tools/EquipmentUpdater.java +++ b/cache/src/main/java/org/apollo/cache/tools/EquipmentUpdater.java @@ -1,16 +1,15 @@ package org.apollo.cache.tools; -import java.io.BufferedOutputStream; -import java.io.DataOutputStream; -import java.io.FileOutputStream; -import java.nio.file.Paths; - -import org.apollo.cache.IndexedFileSystem; +import com.google.common.base.Preconditions; +import org.apollo.cache.Cache; import org.apollo.cache.decoder.ItemDefinitionDecoder; import org.apollo.cache.def.ItemDefinition; import org.apollo.util.tools.EquipmentConstants; -import com.google.common.base.Preconditions; +import java.io.BufferedOutputStream; +import java.io.DataOutputStream; +import java.io.FileOutputStream; +import java.nio.file.Paths; /** * A tool for updating the equipment data. @@ -30,8 +29,8 @@ public static void main(String[] args) throws Exception { Preconditions.checkArgument(args.length == 1, "Usage:\njava -cp ... org.apollo.tools.EquipmentUpdater [release]."); String release = args[0]; - try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("data/equipment-" + release + ".dat"))); - IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs/", release), true)) { + try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("data/equipment-" + release + ".dat")))) { + Cache fs = Cache.openCache(Paths.get("data/fs/", release)); ItemDefinitionDecoder decoder = new ItemDefinitionDecoder(fs); decoder.run(); @@ -359,8 +358,6 @@ private static int getDefenceRequirement(ItemDefinition definition) { return 60; } else if (name.equals("Dragon platelegs")) { return 60; - } else if (name.equals("Dragon sq shield")) { - return 60; } else if (name.equals("Rune med helm")) { return 40; } else if (name.equals("Rune chainbody")) { diff --git a/game/data/equipment-181.dat b/game/data/equipment-181.dat new file mode 100644 index 000000000..6404ca998 Binary files /dev/null and b/game/data/equipment-181.dat differ diff --git a/game/data/equipment-317.dat b/game/data/equipment-317.dat deleted file mode 100644 index ee3475761..000000000 Binary files a/game/data/equipment-317.dat and /dev/null differ diff --git a/game/data/equipment-377.dat b/game/data/equipment-377.dat deleted file mode 100644 index 4eaac5489..000000000 Binary files a/game/data/equipment-377.dat and /dev/null differ diff --git a/game/data/login.xml b/game/data/login.xml index b170b7bce..e05b01b88 100644 --- a/game/data/login.xml +++ b/game/data/login.xml @@ -1,3 +1,3 @@ - org.apollo.game.io.player.DummyPlayerSerializer + org.apollo.game.io.player.BinaryPlayerSerializer \ No newline at end of file diff --git a/game/data/messages.xml b/game/data/messages.xml index f4a5bec2e..516924e74 100644 --- a/game/data/messages.xml +++ b/game/data/messages.xml @@ -1,26 +1,41 @@ - org.apollo.game.message.impl.ButtonMessage + org.apollo.game.message.impl.decode.ButtonMessage org.apollo.game.message.handler.DialogueButtonHandler org.apollo.game.message.handler.BankButtonMessageHandler + org.apollo.game.message.handler.RemoveEquippedItemHandler + + + + org.apollo.game.message.impl.decode.DisplayStatusMessage + + org.apollo.game.message.handler.DisplayStatusMessageHandler - org.apollo.game.message.impl.PublicChatMessage + org.apollo.game.message.impl.decode.PublicChatMessage org.apollo.game.message.handler.PublicChatVerificationHandler org.apollo.game.message.handler.PublicChatMessageHandler + + + org.apollo.game.message.impl.decode.PrivacyOptionMessage + + org.apollo.game.message.handler.PrivacyOptionMessageHandler + + + - org.apollo.game.message.impl.ClosedInterfaceMessage + org.apollo.game.message.impl.decode.ClosedInterfaceMessage org.apollo.game.message.handler.ClosedInterfaceMessageHandler - org.apollo.game.message.impl.CommandMessage + org.apollo.game.message.impl.decode.CommandMessage org.apollo.game.message.handler.CommandMessageHandler @@ -38,65 +53,59 @@ - org.apollo.game.message.impl.ItemActionMessage - - org.apollo.game.message.handler.ItemVerificationHandler - org.apollo.game.message.handler.RemoveEquippedItemHandler - org.apollo.game.message.handler.BankMessageHandler - - - - org.apollo.game.message.impl.ItemOnItemMessage + org.apollo.game.message.impl.decode.ItemOnItemMessage org.apollo.game.message.handler.ItemVerificationHandler org.apollo.game.message.handler.ItemOnItemVerificationHandler - org.apollo.game.message.impl.ItemOnObjectMessage + org.apollo.game.message.impl.decode.ItemOnObjectMessage org.apollo.game.message.handler.ItemOnObjectVerificationHandler - org.apollo.game.message.impl.ItemOptionMessage + org.apollo.game.message.impl.decode.ItemActionMessage org.apollo.game.message.handler.ItemVerificationHandler org.apollo.game.message.handler.EquipItemHandler + org.apollo.game.message.handler.ItemVerificationHandler + org.apollo.game.message.handler.BankMessageHandler - org.apollo.game.message.impl.MagicOnItemMessage + org.apollo.game.message.impl.decode.MagicOnItemMessage org.apollo.game.message.handler.ItemVerificationHandler - org.apollo.game.message.impl.MagicOnMobMessage + org.apollo.game.message.impl.decode.MagicOnMobMessage org.apollo.game.message.handler.MagicOnMobVerificationHandler - org.apollo.game.message.impl.NpcActionMessage + org.apollo.game.message.impl.decode.NpcActionMessage org.apollo.game.message.handler.NpcActionVerificationHandler - org.apollo.game.message.impl.ObjectActionMessage + org.apollo.game.message.impl.decode.ObjectActionMessage org.apollo.game.message.handler.ObjectActionVerificationHandler - org.apollo.game.message.impl.PlayerActionMessage + org.apollo.game.message.impl.decode.PlayerActionMessage org.apollo.game.message.handler.PlayerActionVerificationHandler - org.apollo.game.message.impl.PlayerDesignMessage + org.apollo.game.message.impl.decode.PlayerDesignMessage org.apollo.game.message.handler.PlayerDesignVerificationHandler org.apollo.game.message.handler.PlayerDesignMessageHandler @@ -109,7 +118,7 @@ - org.apollo.game.message.impl.WalkMessage + org.apollo.game.message.impl.decode.WalkMessage org.apollo.game.message.handler.WalkMessageHandler diff --git a/game/data/net.xml b/game/data/net.xml index 8bd754310..d9f8bda22 100644 --- a/game/data/net.xml +++ b/game/data/net.xml @@ -1,7 +1,8 @@ 80 - 43594 + 43594 + 43594 43595 \ No newline at end of file diff --git a/game/data/plugins/cmd/punishment/punish.rb b/game/data/plugins/cmd/punishment/punish.rb index 997222b42..e6c236f3b 100644 --- a/game/data/plugins/cmd/punishment/punish.rb +++ b/game/data/plugins/cmd/punishment/punish.rb @@ -1,53 +1,53 @@ -require 'java' - -java_import 'org.apollo.game.model.World' -java_import 'org.apollo.game.model.entity.Player' - -# Adds a command to mute a player. Admins cannot be muted. -on :command, :mute, RIGHTS_MOD do |player, command| - name = command.arguments.to_a.join(' ') - on_player = $world.get_player(name) - - if validate(player, on_player) - on_player.muted = true - on_player.send_message('You have just been muted.') - player.send_message("You have just muted #{on_player.get_username}.") - end -end - -# Adds a command to unmute a player. -on :command, :unmute, RIGHTS_MOD do |player, command| - name = command.arguments.to_a.join(' ') - on_player = $world.get_player(name) - - if validate(player, on_player) - on_player.muted = false - on_player.send_message('You are no longer muted.') - player.send_message("You have just unmuted #{on_player.get_username}.") - end -end - -# Adds a command to ban a player. Admins cannot be banned. -on :command, :ban, RIGHTS_ADMIN do |player, command| - name = command.arguments.to_a.join(' ') - on_player = $world.get_player(name) - - if validate(player, on_player) - on_player.banned = true - on_player.logout # TODO force logout - player.send_message("You have just banned #{on_player.get_username}.") - end -end - -# Ensures the player isn't nil, and that they aren't an Administrator. -def validate(player, on_player) - if on_player.nil? - player.send_message('That player does not exist.') - return false - elsif on_player.get_privilege_level == RIGHTS_ADMIN - player.send_message('You cannot perform this action on Administrators.') - return false - end - - true -end +require 'java' + +java_import 'org.apollo.game.model.World' +java_import 'org.apollo.game.model.entity.Player' + +# Adds a command to mute a player. Admins cannot be muted. +on :command, :mute, RIGHTS_MOD do |player, command| + name = command.arguments.to_a.join(' ') + on_player = $world.get_player(name) + + if validate(player, on_player) + on_player.muted = true + on_player.send_message('You have just been muted.') + player.send_message("You have just muted #{on_player.get_username}.") + end +end + +# Adds a command to unmute a player. +on :command, :unmute, RIGHTS_MOD do |player, command| + name = command.arguments.to_a.join(' ') + on_player = $world.get_player(name) + + if validate(player, on_player) + on_player.muted = false + on_player.send_message('You are no longer muted.') + player.send_message("You have just unmuted #{on_player.get_username}.") + end +end + +# Adds a command to ban a player. Admins cannot be banned. +on :command, :ban, RIGHTS_ADMIN do |player, command| + name = command.arguments.to_a.join(' ') + on_player = $world.get_player(name) + + if validate(player, on_player) + on_player.banned = true + on_player.logout # TODO force logout + player.send_message("You have just banned #{on_player.get_username}.") + end +end + +# Ensures the player isn't nil, and that they aren't an Administrator. +def validate(player, on_player) + if on_player.nil? + player.send_message('That player does not exist.') + return false + elsif on_player.get_privilege_level == RIGHTS_ADMIN + player.send_message('You cannot perform this action on Administrators.') + return false + end + + true +end diff --git a/game/data/plugins/dialogue/dialogue.rb b/game/data/plugins/dialogue/dialogue.rb index 7a026dc51..d0fe5c2f2 100644 --- a/game/data/plugins/dialogue/dialogue.rb +++ b/game/data/plugins/dialogue/dialogue.rb @@ -360,7 +360,7 @@ def insert_copy(text) end # Decodes the next dialogue interface from the hash, returning a proc. - def decode_next_dialogue(hash) + def decode_next_dialogue(hash) hash.each_pair do |key, value| case key when :disabled then return ->(player) { } diff --git a/game/data/plugins/entity/mob/following/following.rb b/game/data/plugins/entity/mob/following/following.rb old mode 100755 new mode 100644 diff --git a/game/data/plugins/entity/mob/following/plugin.xml b/game/data/plugins/entity/mob/following/plugin.xml old mode 100755 new mode 100644 diff --git a/game/data/plugins/skill/fishing/tool.rb b/game/data/plugins/skill/fishing/tool.rb index f6ff6144b..8f3b105cb 100644 --- a/game/data/plugins/skill/fishing/tool.rb +++ b/game/data/plugins/skill/fishing/tool.rb @@ -46,8 +46,8 @@ def tool(name, hash) ROD_ANIMATION = 622 # TODO: The other feathers that can be used -FISHING_ROD_BAIT = [313] -FLY_FISHING_ROD_BAIT = [314] +FISHING_ROD_BAIT = [313] +FLY_FISHING_ROD_BAIT = [314] tool :lobster_cage, id: 301, animation: CAGE_ANIMATION, message: 'You attempt to catch a lobster...' tool :small_net, id: 303, animation: NET_ANIMATION, message: 'You cast out your net...' diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestState.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestState.kt index cae992930..3d9071919 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestState.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/ApolloTestState.kt @@ -39,7 +39,7 @@ data class ApolloTestState(val handlers: MessageHandlerChainSet, val world: Worl } fun createPlayer(info: PlayerStubInfo): Player { - val credentials = PlayerCredentials(info.name, "test", 1, 1, "0.0.0.0") + val credentials = PlayerCredentials(info.name, "test", 1, null, "0.0.0.0") val region = world.regionRepository.fromPosition(info.position) val player = spyk(Player(world, credentials, info.position)) diff --git a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt index 6fffee19a..4e1b78f80 100644 --- a/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt +++ b/game/plugin-testing/src/main/kotlin/org/apollo/game/plugin/testing/junit/api/interactions/player.kt @@ -1,9 +1,9 @@ package org.apollo.game.plugin.testing.junit.api.interactions -import org.apollo.game.message.impl.ItemOptionMessage -import org.apollo.game.message.impl.NpcActionMessage -import org.apollo.game.message.impl.ObjectActionMessage -import org.apollo.game.message.impl.PlayerActionMessage +import org.apollo.game.message.impl.decode.ItemActionMessage +import org.apollo.game.message.impl.decode.NpcActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage +import org.apollo.game.message.impl.decode.PlayerActionMessage import org.apollo.game.model.Direction import org.apollo.game.model.Position import org.apollo.game.model.entity.Entity @@ -12,11 +12,12 @@ import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.obj.GameObject /** - * Send an [ItemOptionMessage] for the given [id], [option], [slot], and [interfaceId], simulating a + * Send an [ItemActionMessage] for the given [id], [option], [slot], and [interfaceId], simulating a * player interacting with an item. */ -fun Player.interactWithItem(id: Int, option: Int, slot: Int? = null, interfaceId: Int? = null) { - send(ItemOptionMessage(option, interfaceId ?: -1, id, slot ?: inventory.slotOf(id))) +fun Player.interactWithItem(id: Int, option: Int, slot: Int? = null, interfaceId: Int? = null, componentId: Int? = null) { + send(ItemActionMessage(option, interfaceId ?: -1, componentId + ?: -1, id, slot ?: inventory.slotOf(id))) } /** @@ -35,8 +36,8 @@ fun Player.interactWith(entity: Entity, option: Int = 1) { position = entity.position.step(1, Direction.NORTH) when (entity) { - is GameObject -> send(ObjectActionMessage(option, entity.id, entity.position)) - is Npc -> send(NpcActionMessage(option, entity.index)) - is Player -> send(PlayerActionMessage(option, entity.index)) + is GameObject -> send(ObjectActionMessage(option, entity.id, entity.position, 0)) + is Npc -> send(NpcActionMessage(option, entity.index, 0)) + is Player -> send(PlayerActionMessage(option, entity.index, 0)) } } \ No newline at end of file diff --git a/game/plugin/api/src/org/apollo/game/plugin/api/Player.kt b/game/plugin/api/src/org/apollo/game/plugin/api/Player.kt index a98a54481..d845107c8 100644 --- a/game/plugin/api/src/org/apollo/game/plugin/api/Player.kt +++ b/game/plugin/api/src/org/apollo/game/plugin/api/Player.kt @@ -25,7 +25,8 @@ val Player.thieving: SkillProxy get() = SkillProxy(skillSet, Skill.THIEVING) val Player.slayer: SkillProxy get() = SkillProxy(skillSet, Skill.SLAYER) val Player.farming: SkillProxy get() = SkillProxy(skillSet, Skill.FARMING) val Player.runecraft: SkillProxy get() = SkillProxy(skillSet, Skill.RUNECRAFT) - +val Player.construction: SkillProxy get() = SkillProxy(skillSet, Skill.CONSTRUCTION) +val Player.hunter: SkillProxy get() = SkillProxy(skillSet, Skill.HUNTER) /** * A proxy class to allow */ diff --git a/game/plugin/bank/src/bank.plugin.kts b/game/plugin/bank/src/bank.plugin.kts index 0aef5ac18..cadc55364 100644 --- a/game/plugin/bank/src/bank.plugin.kts +++ b/game/plugin/bank/src/bank.plugin.kts @@ -1,6 +1,6 @@ import org.apollo.game.action.DistancedAction -import org.apollo.game.message.impl.NpcActionMessage -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.NpcActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.model.Position import org.apollo.game.model.entity.Npc import org.apollo.game.model.entity.Player diff --git a/game/plugin/chat/private-messaging/src/friends.plugin.kts b/game/plugin/chat/private-messaging/src/friends.plugin.kts index 6ac357d72..c8dab95c1 100644 --- a/game/plugin/chat/private-messaging/src/friends.plugin.kts +++ b/game/plugin/chat/private-messaging/src/friends.plugin.kts @@ -1,21 +1,39 @@ -import org.apollo.game.message.impl.AddFriendMessage import org.apollo.game.message.impl.SendFriendMessage +import org.apollo.game.message.impl.SendFriendMessage.FriendMessageComponent +import org.apollo.game.message.impl.decode.AddFriendMessage +import org.apollo.game.message.impl.decode.RemoveFriendMessage import org.apollo.game.model.entity.setting.PrivacyState +import org.apollo.game.model.event.impl.LoginEvent +import org.apollo.game.model.inter.TopLevelPosition +import org.apollo.game.plugin.kotlin.message.IfAction +import org.apollo.game.plugin.kotlin.message.on -on { AddFriendMessage::class } - .then { - it.addFriend(username) +on(IfAction, inter = TopLevelPosition.FRIENDS_TAB.interfaceId, comp = 1) { + player.interfaceSet.openTopLevel(432, TopLevelPosition.FRIENDS_TAB) +} - val friend = it.world.getPlayer(username) - if (friend == null || friend.friendPrivacy == PrivacyState.OFF) { - it.send(SendFriendMessage(username, 0)) - return@then - } else { - it.send(SendFriendMessage(username, friend.worldId)) - } +on_player_event { LoginEvent::class }.then { + player.sendUserLists(); +} - if (friend.friendsWith(it.username) && it.friendPrivacy != PrivacyState.OFF) { - friend.send(SendFriendMessage(it.username, it.worldId)) - } +on { AddFriendMessage::class }.then { + it.addFriend(username) + + val friend = it.world.getPlayer(username) + + if (friend == null || friend.friendPrivacy == PrivacyState.OFF) { + it.send(SendFriendMessage(FriendMessageComponent(username, 0))) + return@then + } else { + it.send(SendFriendMessage(FriendMessageComponent(username, friend.worldId))) } + + if (friend.friendsWith(it.username) && it.friendPrivacy != PrivacyState.OFF) { + friend.send(SendFriendMessage(FriendMessageComponent(it.username, it.worldId))) + } +} +on { RemoveFriendMessage::class }.then { + it.removeFriend(username) +} + diff --git a/game/plugin/chat/private-messaging/src/ignores.plugin.kts b/game/plugin/chat/private-messaging/src/ignores.plugin.kts index 47b0f29fe..d07feddd1 100644 --- a/game/plugin/chat/private-messaging/src/ignores.plugin.kts +++ b/game/plugin/chat/private-messaging/src/ignores.plugin.kts @@ -1,8 +1,19 @@ -import org.apollo.game.message.impl.AddIgnoreMessage -import org.apollo.game.message.impl.RemoveIgnoreMessage +import org.apollo.game.message.impl.UpdateIgnoreListMessage +import org.apollo.game.message.impl.decode.AddIgnoreMessage +import org.apollo.game.message.impl.decode.RemoveIgnoreMessage +import org.apollo.game.model.inter.TopLevelPosition +import org.apollo.game.plugin.kotlin.message.IfAction +import org.apollo.game.plugin.kotlin.message.on -on { AddIgnoreMessage::class } - .then { it.addIgnore(username) } +on(IfAction, inter = 432, comp = 1) { + player.interfaceSet.openTopLevel(TopLevelPosition.FRIENDS_TAB) +} -on { RemoveIgnoreMessage::class } - .then { it.removeIgnore(username) } \ No newline at end of file +on { AddIgnoreMessage::class }.then { + it.addIgnore(username) + it.send(UpdateIgnoreListMessage(UpdateIgnoreListMessage.IgnoreMessageComponent(username))) +} + +on { RemoveIgnoreMessage::class }.then { + it.removeIgnore(username) +} \ No newline at end of file diff --git a/game/plugin/chat/private-messaging/src/messaging.plugin.kts b/game/plugin/chat/private-messaging/src/messaging.plugin.kts index d9fd21e92..0f0c91c90 100644 --- a/game/plugin/chat/private-messaging/src/messaging.plugin.kts +++ b/game/plugin/chat/private-messaging/src/messaging.plugin.kts @@ -1,5 +1,6 @@ -import org.apollo.game.message.impl.ForwardPrivateChatMessage +import org.apollo.game.message.impl.MessagePrivateMessage import org.apollo.game.message.impl.PrivateChatMessage +import org.apollo.game.message.impl.encode.MessagePrivateEchoMessage import org.apollo.game.model.entity.Player import org.apollo.game.model.entity.setting.PrivacyState.OFF import org.apollo.game.model.entity.setting.PrivacyState.ON @@ -9,7 +10,8 @@ on { PrivateChatMessage::class } val friend = it.world.getPlayer(username) if (interactionPermitted(it, friend)) { - friend.send(ForwardPrivateChatMessage(it.username, it.privilegeLevel, compressedMessage)) + it.send(MessagePrivateEchoMessage(friend.username, compressedMessage)) + friend.send(MessagePrivateMessage(it.username, it.privilegeLevel, compressedMessage)) } } diff --git a/game/plugin/cmd/src/graphic-cmd.plugin.kts b/game/plugin/cmd/src/graphic-cmd.plugin.kts new file mode 100644 index 000000000..c8f1b87c6 --- /dev/null +++ b/game/plugin/cmd/src/graphic-cmd.plugin.kts @@ -0,0 +1,15 @@ +import org.apollo.game.model.Graphic +import org.apollo.game.model.entity.setting.PrivilegeLevel + +on_command("graphic", PrivilegeLevel.MODERATOR) + .then { player -> + arguments.firstOrNull() + ?.let(String::toIntOrNull) + ?.let(::Graphic) + ?.let { + player.playGraphic(it) + return@then + } + + player.sendMessage("Invalid syntax - ::graphic [graphic-id]") + } \ No newline at end of file diff --git a/game/plugin/cmd/src/skill-cmd.plugin.kts b/game/plugin/cmd/src/skill-cmd.plugin.kts index b95ed0181..1e6cccafd 100644 --- a/game/plugin/cmd/src/skill-cmd.plugin.kts +++ b/game/plugin/cmd/src/skill-cmd.plugin.kts @@ -2,6 +2,7 @@ import com.google.common.primitives.Doubles import com.google.common.primitives.Ints import org.apollo.game.model.entity.Skill import org.apollo.game.model.entity.SkillSet +import org.apollo.game.model.entity.SkillSet.SKILL_COUNT import org.apollo.game.model.entity.setting.PrivilegeLevel /** @@ -38,7 +39,7 @@ on_command("level", PrivilegeLevel.ADMINISTRATOR) return@then } - if (skillId !in 0..20 || level !in 1..99) { + if (skillId !in 0..SKILL_COUNT || level !in 1..99) { player.sendMessage(invalidSyntax) return@then } diff --git a/game/plugin/consumables/src/consumables.plugin.kts b/game/plugin/consumables/src/consumables.plugin.kts index 1711d43eb..fda1d0846 100644 --- a/game/plugin/consumables/src/consumables.plugin.kts +++ b/game/plugin/consumables/src/consumables.plugin.kts @@ -1,12 +1,12 @@ import org.apollo.game.action.ActionBlock import org.apollo.game.action.AsyncAction -import org.apollo.game.message.impl.ItemOptionMessage +import org.apollo.game.message.impl.decode.ItemActionMessage import org.apollo.game.model.Animation import org.apollo.game.model.entity.Player import org.apollo.net.message.Message import org.apollo.plugin.consumables.* -on { ItemOptionMessage::class } +on { ItemActionMessage::class } .where { option == 1 && isConsumable(id) } .then { ConsumeAction.start(this, it, lookupConsumable(id), slot) diff --git a/game/plugin/dummy/src/dummy.plugin.kts b/game/plugin/dummy/src/dummy.plugin.kts index 75dee6f19..1be2d49ff 100644 --- a/game/plugin/dummy/src/dummy.plugin.kts +++ b/game/plugin/dummy/src/dummy.plugin.kts @@ -1,6 +1,6 @@ import org.apollo.game.action.ActionBlock import org.apollo.game.action.AsyncDistancedAction -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.model.Animation import org.apollo.game.model.Position import org.apollo.game.model.entity.* diff --git a/game/plugin/emote-tab/src/EmoteTab.plugin.kts b/game/plugin/emote-tab/src/EmoteTab.plugin.kts index 0f546e818..5f71fc51e 100644 --- a/game/plugin/emote-tab/src/EmoteTab.plugin.kts +++ b/game/plugin/emote-tab/src/EmoteTab.plugin.kts @@ -1,7 +1,7 @@ -import org.apollo.game.message.impl.ButtonMessage +import org.apollo.game.message.impl.decode.ButtonMessage on { ButtonMessage::class } - .where { widgetId in Emote.MAP } + .where { componentId in Emote.MAP } .then { player -> - player.playAnimation(Emote.fromButton(widgetId)!!.animation) + player.playAnimation(Emote.fromButton(componentId)!!.animation) } \ No newline at end of file diff --git a/game/plugin/entity/actions/src/PlayerActions.plugin.kts b/game/plugin/entity/actions/src/PlayerActions.plugin.kts index 675a8a53e..ca519cb8d 100644 --- a/game/plugin/entity/actions/src/PlayerActions.plugin.kts +++ b/game/plugin/entity/actions/src/PlayerActions.plugin.kts @@ -1,6 +1,6 @@ package org.apollo.game.plugin.entity.actions -import org.apollo.game.message.impl.PlayerActionMessage +import org.apollo.game.message.impl.decode.PlayerActionMessage import org.apollo.game.model.event.impl.LoginEvent on { PlayerActionMessage::class } diff --git a/game/plugin/entity/actions/src/playerAction.kt b/game/plugin/entity/actions/src/playerAction.kt index d08b77974..f20c8f090 100644 --- a/game/plugin/entity/actions/src/playerAction.kt +++ b/game/plugin/entity/actions/src/playerAction.kt @@ -1,7 +1,7 @@ package org.apollo.game.plugin.entity.actions import java.util.* -import org.apollo.game.message.impl.SetPlayerActionMessage +import org.apollo.game.message.impl.encode.SetPlayerActionMessage import org.apollo.game.model.entity.Player fun Player.enableAction(action: PlayerActionType) { diff --git a/game/plugin/entity/actions/test/PlayerActionTests.kt b/game/plugin/entity/actions/test/PlayerActionTests.kt index 153345d0b..03c2423c4 100644 --- a/game/plugin/entity/actions/test/PlayerActionTests.kt +++ b/game/plugin/entity/actions/test/PlayerActionTests.kt @@ -1,7 +1,7 @@ package org.apollo.game.plugin.entity.actions import io.mockk.verify -import org.apollo.game.message.impl.SetPlayerActionMessage +import org.apollo.game.message.impl.encode.SetPlayerActionMessage import org.apollo.game.model.entity.Player import org.apollo.game.plugin.testing.junit.ApolloTestingExtension import org.apollo.game.plugin.testing.junit.api.annotations.TestMock diff --git a/game/plugin/locations/al-kharid/src/npcs.plugin.kts b/game/plugin/locations/al-kharid/src/npcs.plugin.kts index 79b74471c..54e783877 100644 --- a/game/plugin/locations/al-kharid/src/npcs.plugin.kts +++ b/game/plugin/locations/al-kharid/src/npcs.plugin.kts @@ -77,7 +77,7 @@ spawnNpc("scorpion", x = 3301, y = 3312) // Functional npcs -spawnNpc("gnome_pilot", x = 3279, y = 3213) +spawnNpc("captain_dalbur", x = 3279, y = 3213) spawnNpc("banker", id = 496, x = 3267, y = 3164, facing = Direction.EAST) spawnNpc("banker", id = 496, x = 3267, y = 3167, facing = Direction.EAST) diff --git a/game/plugin/locations/al-kharid/src/shops.plugin.kts b/game/plugin/locations/al-kharid/src/shops.plugin.kts index 2d51292bc..cf7f3925a 100644 --- a/game/plugin/locations/al-kharid/src/shops.plugin.kts +++ b/game/plugin/locations/al-kharid/src/shops.plugin.kts @@ -3,7 +3,7 @@ package org.apollo.plugin.locations.alKharid import org.apollo.game.plugin.shops.builder.shop shop("Al-Kharid General Store") { - operated by "Shop keeper"(524) and "Shop assistant"(525) + operated by "Shop keeper"(2817) and "Shop assistant"(2818) buys any items sell(5) of "Pot" diff --git a/game/plugin/locations/edgeville/src/shops.plugin.kts b/game/plugin/locations/edgeville/src/shops.plugin.kts index 0a5facec5..fdc5ba8d2 100644 --- a/game/plugin/locations/edgeville/src/shops.plugin.kts +++ b/game/plugin/locations/edgeville/src/shops.plugin.kts @@ -3,7 +3,7 @@ package org.apollo.plugin.locations.edgeville import org.apollo.game.plugin.shops.builder.shop shop("Edgeville General Store") { - operated by "Shop keeper"(528) and "Shop assistant"(529) + operated by "Shop keeper"(2821) and "Shop assistant"(2822) buys any items sell(5) of "Pot" diff --git a/game/plugin/locations/falador/src/shops.plugin.kts b/game/plugin/locations/falador/src/shops.plugin.kts index 5b7446fa9..f51d74b18 100644 --- a/game/plugin/locations/falador/src/shops.plugin.kts +++ b/game/plugin/locations/falador/src/shops.plugin.kts @@ -3,7 +3,7 @@ package org.apollo.plugin.locations.falador import org.apollo.game.plugin.shops.builder.shop shop("Falador General Store") { - operated by "Shop keeper"(524) and "Shop assistant"( 525) + operated by "Shop keeper"(2819) and "Shop assistant"( 2820) buys any items sell(5) of "Pot" diff --git a/game/plugin/locations/lumbridge/src/shops.plugin.kts b/game/plugin/locations/lumbridge/src/shops.plugin.kts index 942bb62d3..54fd9e874 100644 --- a/game/plugin/locations/lumbridge/src/shops.plugin.kts +++ b/game/plugin/locations/lumbridge/src/shops.plugin.kts @@ -3,7 +3,7 @@ package org.apollo.plugin.locations.lumbridge import org.apollo.game.plugin.shops.builder.shop shop("Lumbridge General Store") { - operated by "Shop keeper" and "Shop assistant" + operated by "Shop keeper"(2813) and "Shop assistant"(2814) buys any items sell(5) of "Pot" @@ -19,7 +19,7 @@ shop("Lumbridge General Store") { } shop("Bob's Brilliant Axes") { - operated by "Bob" + operated by "Bob"(2812) category("pickaxe") { sell(5) of "Bronze" diff --git a/game/plugin/locations/tutorial-island/src/npcs.plugin.kts b/game/plugin/locations/tutorial-island/src/npcs.plugin.kts index 5ec51c09b..f1ec6918b 100644 --- a/game/plugin/locations/tutorial-island/src/npcs.plugin.kts +++ b/game/plugin/locations/tutorial-island/src/npcs.plugin.kts @@ -9,7 +9,7 @@ import org.apollo.game.plugin.entity.spawn.spawnNpc spawnNpc("master_chef", x = 3076, y = 3085) spawnNpc("quest_guide", x = 3086, y = 3122) -spawnNpc("financial_advisor", x = 3127, y = 3124, facing = Direction.WEST) +spawnNpc("account_guide", x = 3127, y = 3124, facing = Direction.WEST) spawnNpc("brother_brace", x = 3124, y = 3107, facing = Direction.EAST) spawnNpc("magic_instructor", x = 3140, y = 3085) diff --git a/game/plugin/locations/varrock/src/npcs.plugin.kts b/game/plugin/locations/varrock/src/npcs.plugin.kts index 83d5fb9ec..cd2d09249 100644 --- a/game/plugin/locations/varrock/src/npcs.plugin.kts +++ b/game/plugin/locations/varrock/src/npcs.plugin.kts @@ -3,7 +3,7 @@ package org.apollo.plugin.locations.varrock import org.apollo.game.model.Direction import org.apollo.game.plugin.entity.spawn.spawnNpc -spawnNpc("barbarian_woman", x = 3222, y = 3399) +spawnNpc("barbarian_woman_3102", x = 3222, y = 3399) spawnNpc("bear", id = 106, x = 3289, y = 3351) @@ -160,7 +160,7 @@ spawnNpc("apothecary", x = 3196, y = 3403) spawnNpc("captain_rovin", x = 3204, y = 3496, z = 2) -spawnNpc("curator", x = 3256, y = 3447) +spawnNpc("curator_haig_halen", x = 3256, y = 3447) spawnNpc("dimintheis", x = 3280, y = 3403) @@ -174,7 +174,7 @@ spawnNpc("guidors_wife", id = 342, x = 3280, y = 3382) spawnNpc("guidor", x = 3284, y = 3381, facing = Direction.SOUTH) -spawnNpc("guild_master", x = 3189, y = 3360) +spawnNpc("guildmaster", x = 3189, y = 3360) spawnNpc("gypsy", x = 3203, y = 3423) @@ -220,7 +220,7 @@ spawnNpc("bartender", x = 3226, y = 3400) spawnNpc("bartender", id = 1921, x = 3277, y = 3487) -spawnNpc("fancy_dress_shop_owner", x = 3281, y = 3398) +spawnNpc("asyff", x = 3281, y = 3398) spawnNpc("horvik", x = 3229, y = 3438) diff --git a/game/plugin/locations/varrock/src/shops.plugin.kts b/game/plugin/locations/varrock/src/shops.plugin.kts index cc3d14881..0240b6d6a 100644 --- a/game/plugin/locations/varrock/src/shops.plugin.kts +++ b/game/plugin/locations/varrock/src/shops.plugin.kts @@ -100,7 +100,7 @@ shop("Thessalia's Fine Clothes.") { sell(2) of "Blue" } - sell(4) of "Cape" + sell(4) of "Red cape" sell(5) of "Silk" sell(3) of { @@ -110,7 +110,7 @@ shop("Thessalia's Fine Clothes.") { } shop("Varrock General Store.") { - operated by "Shopkeeper"(522) and "Shop assistant"(523) + operated by "Shopkeeper"(2815) and "Shop assistant"(2816) buys any items sell(5) of "Pot" @@ -126,7 +126,7 @@ shop("Varrock General Store.") { } shop("Varrock Swordshop.") { - operated by "Shopkeeper"(551) and "Shop assistant"(552) + operated by "Shopkeeper"(2884) and "Shop assistant"(2885) category("swords") { sell(5) of "Bronze" diff --git a/game/plugin/logout/src/logout.plugin.kts b/game/plugin/logout/src/logout.plugin.kts index 0243b091f..af6fa53af 100644 --- a/game/plugin/logout/src/logout.plugin.kts +++ b/game/plugin/logout/src/logout.plugin.kts @@ -1,5 +1,9 @@ -val LOGOUT_BUTTON_ID = 2458 +import org.apollo.game.model.inter.TopLevelPosition +import org.apollo.game.plugin.kotlin.message.IfAction +import org.apollo.game.plugin.kotlin.message.on -on_button(LOGOUT_BUTTON_ID) - .where { widgetId == LOGOUT_BUTTON_ID } - .then { it.logout() } \ No newline at end of file +val LOGOUT_COMPONENT = 8 + +on(IfAction, inter = TopLevelPosition.LOGOUT_TAB.interfaceId, comp = LOGOUT_COMPONENT) { + player.logout() +} \ No newline at end of file diff --git a/game/plugin/logout/test/LogoutTests.kt b/game/plugin/logout/test/LogoutTests.kt index 9a8cb9c66..8862d96b1 100644 --- a/game/plugin/logout/test/LogoutTests.kt +++ b/game/plugin/logout/test/LogoutTests.kt @@ -1,5 +1,5 @@ import io.mockk.verify -import org.apollo.game.message.impl.ButtonMessage +import org.apollo.game.message.impl.decode.ButtonMessage import org.apollo.game.model.entity.Player import org.apollo.game.plugin.testing.junit.ApolloTestingExtension import org.apollo.game.plugin.testing.junit.api.annotations.TestMock @@ -18,7 +18,7 @@ class LogoutTests { @Test fun `The player should be logged out when they click the logout button`() { - player.send(ButtonMessage(LOGOUT_BUTTON_ID)) + player.send(ButtonMessage(LOGOUT_BUTTON_ID, 0, 0, 0, 0)) verify { player.logout() } } diff --git a/game/plugin/navigation/door/src/door.plugin.kts b/game/plugin/navigation/door/src/door.plugin.kts index d91ceee9a..0f0e882df 100644 --- a/game/plugin/navigation/door/src/door.plugin.kts +++ b/game/plugin/navigation/door/src/door.plugin.kts @@ -1,5 +1,5 @@ -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.plugin.navigation.door.Door import org.apollo.plugin.navigation.door.OpenDoorAction diff --git a/game/plugin/run/src/run.plugin.kts b/game/plugin/run/src/run.plugin.kts index fa65f0495..5e6e8388e 100644 --- a/game/plugin/run/src/run.plugin.kts +++ b/game/plugin/run/src/run.plugin.kts @@ -1,10 +1,10 @@ -import org.apollo.game.message.impl.ButtonMessage +import org.apollo.game.message.impl.decode.ButtonMessage val WALK_BUTTON_ID = 152 val RUN_BUTTON_ID = 153 on { ButtonMessage::class } - .where { widgetId == WALK_BUTTON_ID || widgetId == RUN_BUTTON_ID } + .where { componentId == WALK_BUTTON_ID || componentId == RUN_BUTTON_ID } .then { it.toggleRunning() } \ No newline at end of file diff --git a/game/plugin/shops/src/org/apollo/game/plugin/shops/OpenShopAction.kt b/game/plugin/shops/src/org/apollo/game/plugin/shops/OpenShopAction.kt index a87a31256..f6a5fe9e9 100644 --- a/game/plugin/shops/src/org/apollo/game/plugin/shops/OpenShopAction.kt +++ b/game/plugin/shops/src/org/apollo/game/plugin/shops/OpenShopAction.kt @@ -2,10 +2,10 @@ package org.apollo.game.plugin.shops import org.apollo.game.action.DistancedAction import org.apollo.game.message.handler.ItemVerificationHandler -import org.apollo.game.message.impl.SetWidgetTextMessage import org.apollo.game.model.entity.Mob import org.apollo.game.model.entity.Player import org.apollo.game.model.inter.InterfaceListener +import org.apollo.game.model.inter.TopLevelPosition import org.apollo.game.model.inv.Inventory import org.apollo.game.model.inv.SynchronizationInventoryListener @@ -22,10 +22,9 @@ class OpenShopAction( mob.interactingMob = operator val closeListener = addInventoryListeners(mob, shop.inventory) - mob.send(SetWidgetTextMessage(ShopInterfaces.SHOP_NAME, shop.name)) - mob.interfaceSet.openWindowWithSidebar(closeListener, ShopInterfaces.SHOP_WINDOW, - ShopInterfaces.INVENTORY_SIDEBAR) + mob.interfaceSet.openModal(closeListener, ShopInterfaces.SHOP_INTERFACE); + mob.interfaceSet.openTopLevel(ShopInterfaces.INVENTORY_INTERFACE, TopLevelPosition.INVENTORY_TAB) stop() } @@ -34,8 +33,8 @@ class OpenShopAction( * [InterfaceListener] that removes them when the interface is closed. */ private fun addInventoryListeners(player: Player, shop: Inventory): InterfaceListener { - val invListener = SynchronizationInventoryListener(player, ShopInterfaces.INVENTORY_CONTAINER) - val shopListener = SynchronizationInventoryListener(player, ShopInterfaces.SHOP_CONTAINER) + val invListener = SynchronizationInventoryListener(player, ShopInterfaces.INVENTORY_INTERFACE, ShopInterfaces.INVENTORY_COMPONENT, SynchronizationInventoryListener.INVENTORY_INVENTORY) + val shopListener = SynchronizationInventoryListener(player, ShopInterfaces.SHOP_INTERFACE, ShopInterfaces.SHOP_COMPONENT, ShopInterfaces.SHOP_CONTAINER_ID) player.inventory.addListener(invListener) player.inventory.forceRefresh() diff --git a/game/plugin/shops/src/org/apollo/game/plugin/shops/ShopInterfaces.kt b/game/plugin/shops/src/org/apollo/game/plugin/shops/ShopInterfaces.kt index 4a678bd8f..1f3ef6ce0 100644 --- a/game/plugin/shops/src/org/apollo/game/plugin/shops/ShopInterfaces.kt +++ b/game/plugin/shops/src/org/apollo/game/plugin/shops/ShopInterfaces.kt @@ -8,26 +8,19 @@ internal object ShopInterfaces { /** * The container interface id for the player's inventory. */ - const val INVENTORY_CONTAINER = 3823 - - /** - * The sidebar id for the inventory, when a Shop window is open. - */ - const val INVENTORY_SIDEBAR = 3822 - - /** - * The shop window interface id. - */ - const val SHOP_WINDOW = 3824 + const val INVENTORY_INTERFACE = 301 + const val INVENTORY_COMPONENT = 0 /** * The container interface id for the shop's inventory. */ - const val SHOP_CONTAINER = 3900 + const val SHOP_INTERFACE = 300 + const val SHOP_COMPONENT = 16 + const val SHOP_CONTAINER_ID = 16 /** * The id of the text widget that displays a shop's name. */ - const val SHOP_NAME = 3901 + const val SHOP_NAME_CLIENTSCRIPT = 1074 } \ No newline at end of file diff --git a/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts b/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts index 4d3be298d..88d525e12 100644 --- a/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts +++ b/game/plugin/shops/src/org/apollo/game/plugin/shops/Shops.plugin.kts @@ -1,16 +1,16 @@ package org.apollo.game.plugin.shops import org.apollo.game.message.handler.ItemVerificationHandler -import org.apollo.game.message.impl.ItemActionMessage -import org.apollo.game.message.impl.NpcActionMessage +import org.apollo.game.message.impl.decode.ItemActionMessage +import org.apollo.game.message.impl.decode.NpcActionMessage import org.apollo.game.model.entity.Mob import org.apollo.game.scheduling.ScheduledTask fun Mob.shop(): Shop? = SHOPS[definition.id] start { world -> - ItemVerificationHandler.addInventory(ShopInterfaces.SHOP_CONTAINER) { it.interactingMob?.shop()?.inventory } - ItemVerificationHandler.addInventory(ShopInterfaces.INVENTORY_CONTAINER, PlayerInventorySupplier) + ItemVerificationHandler.addInventory(ShopInterfaces.SHOP_INTERFACE) { it.interactingMob?.shop()?.inventory } + ItemVerificationHandler.addInventory(ShopInterfaces.INVENTORY_INTERFACE, PlayerInventorySupplier) world.schedule(object : ScheduledTask(Shop.RESTOCK_INTERVAL, false) { override fun execute() = SHOPS.values.distinct().forEach(Shop::restock) @@ -30,16 +30,16 @@ on { NpcActionMessage::class } on { ItemActionMessage::class } - .where { interfaceId == ShopInterfaces.SHOP_CONTAINER || interfaceId == ShopInterfaces.INVENTORY_CONTAINER } + .where { interfaceId == ShopInterfaces.SHOP_INTERFACE || interfaceId == ShopInterfaces.INVENTORY_INTERFACE } .then { player -> - if (ShopInterfaces.SHOP_WINDOW !in player.interfaceSet) { + if (ShopInterfaces.SHOP_INTERFACE !in player.interfaceSet) { return@then } val shop = player.interactingMob?.shop() ?: return@then when (interfaceId) { - ShopInterfaces.INVENTORY_CONTAINER -> shop.buy(player, slot, option) - ShopInterfaces.SHOP_CONTAINER -> shop.sell(player, slot, option) + ShopInterfaces.INVENTORY_INTERFACE -> shop.buy(player, slot, option) + ShopInterfaces.SHOP_INTERFACE -> shop.sell(player, slot, option) else -> error("Supposedly unreacheable case.") } diff --git a/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/Fishing.plugin.kts b/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/Fishing.plugin.kts index 597058bbe..8dbb8b4fc 100644 --- a/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/Fishing.plugin.kts +++ b/game/plugin/skills/fishing/src/org/apollo/game/plugin/skills/fishing/Fishing.plugin.kts @@ -1,6 +1,6 @@ package org.apollo.game.plugin.skills.fishing -import org.apollo.game.message.impl.NpcActionMessage +import org.apollo.game.message.impl.decode.NpcActionMessage // TODO: moving fishing spots, seaweed and caskets, evil bob diff --git a/game/plugin/skills/herblore/src/Herblore.plugin.kts b/game/plugin/skills/herblore/src/Herblore.plugin.kts index f575a6532..6bf648449 100644 --- a/game/plugin/skills/herblore/src/Herblore.plugin.kts +++ b/game/plugin/skills/herblore/src/Herblore.plugin.kts @@ -5,10 +5,10 @@ import Herb.Companion.isIdentified import Herb.Companion.isUnidentified import Ingredient.Companion.isIngredient import UnfinishedPotion.Companion.isUnfinished -import org.apollo.game.message.impl.ItemOnItemMessage -import org.apollo.game.message.impl.ItemOptionMessage +import org.apollo.game.message.impl.decode.ItemOnItemMessage +import org.apollo.game.message.impl.decode.ItemActionMessage -on { ItemOptionMessage::class } +on { ItemActionMessage::class } .where { option == IdentifyHerbAction.IDENTIFY_OPTION && id.isUnidentified() } .then { player -> val unidentified = Herb[id]!! diff --git a/game/plugin/skills/mining/src/ExpiredProspectingAction.kt b/game/plugin/skills/mining/src/ExpiredProspectingAction.kt index 41f3229e6..e0d54ee59 100644 --- a/game/plugin/skills/mining/src/ExpiredProspectingAction.kt +++ b/game/plugin/skills/mining/src/ExpiredProspectingAction.kt @@ -1,6 +1,6 @@ import java.util.* import org.apollo.game.action.DistancedAction -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.model.Position import org.apollo.game.model.entity.Player diff --git a/game/plugin/skills/mining/src/Mining.plugin.kts b/game/plugin/skills/mining/src/Mining.plugin.kts index 8b3f61d1e..3d4b62272 100644 --- a/game/plugin/skills/mining/src/Mining.plugin.kts +++ b/game/plugin/skills/mining/src/Mining.plugin.kts @@ -1,4 +1,4 @@ -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.plugin.skills.mining.Ore on { ObjectActionMessage::class } diff --git a/game/plugin/skills/mining/src/MiningAction.kt b/game/plugin/skills/mining/src/MiningAction.kt index 0f159b388..35f55ec3b 100644 --- a/game/plugin/skills/mining/src/MiningAction.kt +++ b/game/plugin/skills/mining/src/MiningAction.kt @@ -1,7 +1,7 @@ import java.util.* import org.apollo.game.action.ActionBlock import org.apollo.game.action.AsyncDistancedAction -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.model.entity.Player import org.apollo.game.plugin.api.* import org.apollo.game.plugin.skills.mining.Ore diff --git a/game/plugin/skills/mining/src/ProspectingAction.kt b/game/plugin/skills/mining/src/ProspectingAction.kt index 10bf83a11..dc11d9d7a 100644 --- a/game/plugin/skills/mining/src/ProspectingAction.kt +++ b/game/plugin/skills/mining/src/ProspectingAction.kt @@ -1,7 +1,7 @@ import java.util.Objects import org.apollo.game.action.ActionBlock import org.apollo.game.action.AsyncDistancedAction -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.model.Position import org.apollo.game.model.entity.Player import org.apollo.game.plugin.api.Definitions diff --git a/game/plugin/skills/prayer/src/Prayer.kt b/game/plugin/skills/prayer/src/Prayer.kt index 3f281cc05..c4ff34e47 100644 --- a/game/plugin/skills/prayer/src/Prayer.kt +++ b/game/plugin/skills/prayer/src/Prayer.kt @@ -1,6 +1,6 @@ import com.google.common.collect.MultimapBuilder import com.google.common.collect.SetMultimap -import org.apollo.game.message.impl.ConfigMessage +import org.apollo.game.message.impl.encode.ConfigMessage import org.apollo.game.model.entity.Player enum class Prayer(val button: Int, val level: Int, val setting: Int, val drain: Double) { diff --git a/game/plugin/skills/prayer/src/Prayer.plugin.kts b/game/plugin/skills/prayer/src/Prayer.plugin.kts index 2338d8332..3d83976a4 100644 --- a/game/plugin/skills/prayer/src/Prayer.plugin.kts +++ b/game/plugin/skills/prayer/src/Prayer.plugin.kts @@ -1,7 +1,7 @@ import Bone.Companion.isBone import Prayer.Companion.isPrayerButton -import org.apollo.game.message.impl.ButtonMessage -import org.apollo.game.message.impl.ItemOptionMessage +import org.apollo.game.message.impl.decode.ButtonMessage +import org.apollo.game.message.impl.decode.ItemActionMessage import org.apollo.game.model.event.impl.LogoutEvent import org.apollo.game.plugin.api.prayer @@ -12,9 +12,9 @@ on_player_event { LogoutEvent::class } } on { ButtonMessage::class } - .where { widgetId.isPrayerButton() } + .where { componentId.isPrayerButton() } .then { player -> - val prayer = Prayer.forButton(widgetId)!! + val prayer = Prayer.forButton(componentId)!! val level = prayer.level if (level > player.prayer.current) { @@ -27,7 +27,7 @@ on { ButtonMessage::class } terminate() } -on { ItemOptionMessage::class } +on { ItemActionMessage::class } .where { option == BuryBoneAction.BURY_OPTION && id.isBone() } .then { player -> val bone = Bone[id]!! diff --git a/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts b/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts index 88f983f77..12e90cbce 100644 --- a/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts +++ b/game/plugin/skills/runecrafting/src/Runecrafting.plugin.kts @@ -1,10 +1,13 @@ package org.apollo.game.plugin.skill.runecrafting -import org.apollo.game.message.impl.* +import org.apollo.game.message.impl.decode.ItemOnObjectMessage +import org.apollo.game.message.impl.decode.ItemActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage +import org.apollo.game.message.impl.encode.ConfigMessage import org.apollo.game.model.entity.EquipmentConstants import org.apollo.game.model.event.impl.LoginEvent -private val changeAltarObjectConfigId = 491 +internal val changeAltarObjectConfigId = 491 internal val RUNES = mutableListOf() @@ -55,7 +58,7 @@ on { ItemOnObjectMessage::class } terminate() } -on { ItemOptionMessage::class } +on { ItemActionMessage::class } .where { option == 4 } .then { val talisman = Talisman.findById(id) ?: return@then diff --git a/game/plugin/skills/woodcutting/build.gradle b/game/plugin/skills/woodcutting/build.gradle index 4d96c9f57..f849bad10 100644 --- a/game/plugin/skills/woodcutting/build.gradle +++ b/game/plugin/skills/woodcutting/build.gradle @@ -5,6 +5,7 @@ dependencies { implementation project(':cache') implementation project(':net') implementation project(':util') + implementation project(':game:plugin:entity:actions') implementation project(':game:plugin:api') testImplementation project(':game:plugin-testing') } diff --git a/game/plugin/skills/woodcutting/src/Tree.kt b/game/plugin/skills/woodcutting/src/Tree.kt index 51a274a0e..5978d0b9a 100644 --- a/game/plugin/skills/woodcutting/src/Tree.kt +++ b/game/plugin/skills/woodcutting/src/Tree.kt @@ -32,12 +32,12 @@ enum class Tree( private val NORMAL_OBJECTS = hashSetOf( 1276, 1277, 1278, 1279, 1280, 1282, 1283, 1284, 1285, 1285, 1286, 1289, 1290, 1291, 1315, 1316, 1318, 1330, 1331, 1332, 1365, 1383, 1384, 2409, 3033, 3034, 3035, 3036, 3881, 3882, - 3883, 5902, 5903, 5904, 10041 + 3883, 5902, 5903, 5904, 10041, 9730 ) private val ACHEY_OBJECTS = hashSetOf(2023) -private val OAK_OBJECTS = hashSetOf(1281, 3037) -private val WILLOW_OBJECTS = hashSetOf(5551, 5552, 5553) +private val OAK_OBJECTS = hashSetOf(1281, 3037, 9734) +private val WILLOW_OBJECTS = hashSetOf(10819) private val TEAK_OBJECTS = hashSetOf(9036) private val MAPLE_OBJECTS = hashSetOf(1307, 4674) private val MAHOGANY_OBJECTS = hashSetOf(9034) diff --git a/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts b/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts index f0d962395..58f051f8e 100644 --- a/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts +++ b/game/plugin/skills/woodcutting/src/Woodcutting.plugin.kts @@ -1,9 +1,7 @@ - -import java.util.concurrent.TimeUnit import org.apollo.game.GameConstants import org.apollo.game.action.ActionBlock import org.apollo.game.action.AsyncDistancedAction -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.model.Position import org.apollo.game.model.World import org.apollo.game.model.entity.Player @@ -11,6 +9,7 @@ import org.apollo.game.model.entity.obj.GameObject import org.apollo.game.plugin.api.* import org.apollo.game.plugin.skills.woodcutting.Axe import org.apollo.game.plugin.skills.woodcutting.Tree +import java.util.concurrent.TimeUnit // TODO Accurate chopping rates, e.g. https://twitter.com/JagexKieren/status/713403124464107520 diff --git a/game/src/main/java/org/apollo/Server.java b/game/src/main/java/org/apollo/Server.java index 348711a78..017ed88a6 100644 --- a/game/src/main/java/org/apollo/Server.java +++ b/game/src/main/java/org/apollo/Server.java @@ -5,22 +5,25 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.nio.file.Paths; +import java.util.Arrays; import java.util.concurrent.TimeUnit; import java.util.logging.Level; +import java.util.logging.LogManager; import java.util.logging.Logger; import com.google.common.base.Stopwatch; +import com.google.common.collect.Sets; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; -import org.apollo.cache.IndexedFileSystem; +import org.apollo.cache.Cache; import org.apollo.game.model.World; import org.apollo.game.plugin.PluginContext; import org.apollo.game.plugin.PluginManager; -import org.apollo.game.release.r377.Release377; +import org.apollo.game.release.r181.Release181; import org.apollo.game.session.ApolloHandler; import org.apollo.net.HttpChannelInitializer; import org.apollo.net.JagGrabChannelInitializer; @@ -46,17 +49,18 @@ public final class Server { * @param args The command-line arguments passed to the application. */ public static void main(String[] args) { + Arrays.stream(LogManager.getLogManager().getLogger("").getHandlers()).forEach(h -> h.setLevel(Level.ALL)); + Stopwatch stopwatch = Stopwatch.createStarted(); try { Server server = new Server(); - server.init(args.length == 1 ? args[0] : Release377.class.getName()); - - SocketAddress service = new InetSocketAddress(NetworkConstants.SERVICE_PORT); - SocketAddress http = new InetSocketAddress(NetworkConstants.HTTP_PORT); - SocketAddress jaggrab = new InetSocketAddress(NetworkConstants.JAGGRAB_PORT); + server.init(args.length == 1 ? args[0] : Release181.class.getName()); - server.bind(service, http, jaggrab); + server.bind(new InetSocketAddress(NetworkConstants.HTTP_PORT), + new InetSocketAddress(NetworkConstants.JAGGRAB_PORT), + new InetSocketAddress(NetworkConstants.GAME_PORT), + new InetSocketAddress(NetworkConstants.UPDATE_PORT)); } catch (Throwable t) { logger.log(Level.SEVERE, "Error whilst starting server.", t); System.exit(0); @@ -95,14 +99,14 @@ public Server() { /** * Binds the server to the specified address. * - * @param service The service address to bind to. - * @param http The HTTP address to bind to. - * @param jaggrab The JAGGRAB address to bind to. + * @param services The service addresses to bind to. + * @param http The HTTP address to bind to. + * @param jaggrab The JAGGRAB address to bind to. * @throws BindException If the ServerBootstrap fails to bind to the SocketAddress. */ - public void bind(SocketAddress service, SocketAddress http, SocketAddress jaggrab) throws IOException { - logger.fine("Binding service listener to address: " + service + "..."); - bind(serviceBootstrap, service); + public void bind(SocketAddress http, SocketAddress jaggrab, SocketAddress... services) throws IOException { + logger.fine("Binding service listener to address: " + Arrays.toString(services) + "..."); + bind(serviceBootstrap, services); try { logger.fine("Binding HTTP listener to address: " + http + "..."); @@ -136,7 +140,7 @@ public void init(String releaseName) throws Exception { World world = new World(); ServiceManager services = new ServiceManager(world); - IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs", Integer.toString(version)), true); + Cache fs = Cache.openCache(Paths.get("data/fs", Integer.toString(version))); ServerContext context = new ServerContext(release, services, fs); ApolloHandler handler = new ApolloHandler(context); @@ -162,15 +166,17 @@ public void init(String releaseName) throws Exception { * Attempts to bind the specified ServerBootstrap to the specified SocketAddress. * * @param bootstrap The ServerBootstrap. - * @param address The SocketAddress. + * @param addresses The SocketAddress. * @throws IOException If the ServerBootstrap fails to bind to the SocketAddress. */ - private void bind(ServerBootstrap bootstrap, SocketAddress address) throws IOException { - try { - bootstrap.bind(address).sync(); - } catch (Exception cause) { - throw new IOException("Failed to bind to " + address, cause); + private void bind(ServerBootstrap bootstrap, SocketAddress... addresses) throws IOException { + final var set = Sets.newHashSet(addresses); + for (SocketAddress address : set) { + try { + bootstrap.bind(address).sync(); + } catch (Exception cause) { + throw new IOException("Failed to bind to " + address, cause); + } } } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/ServerContext.java b/game/src/main/java/org/apollo/ServerContext.java index 4eaf355ba..778acb9f9 100644 --- a/game/src/main/java/org/apollo/ServerContext.java +++ b/game/src/main/java/org/apollo/ServerContext.java @@ -1,13 +1,13 @@ package org.apollo; -import java.util.Objects; - -import org.apollo.cache.IndexedFileSystem; +import org.apollo.cache.Cache; import org.apollo.game.service.GameService; import org.apollo.game.service.LoginService; import org.apollo.game.service.UpdateService; import org.apollo.net.release.Release; +import java.util.Objects; + /** * A {@link ServerContext} is created along with the {@link Server} object. The primary difference is that a reference * to the current context should be passed around within the server. The {@link Server} should not be as it allows @@ -21,7 +21,7 @@ public final class ServerContext { /** * The IndexedFileSystem. */ - private final IndexedFileSystem fileSystem; + private final Cache fileSystem; /** * The current release. @@ -40,7 +40,7 @@ public final class ServerContext { * @param services The service manager. * @param fileSystem The indexed file system. */ - protected ServerContext(Release release, ServiceManager services, IndexedFileSystem fileSystem) { + protected ServerContext(Release release, ServiceManager services, Cache fileSystem) { this.release = Objects.requireNonNull(release); this.services = Objects.requireNonNull(services); this.services.setContext(this); @@ -52,7 +52,7 @@ protected ServerContext(Release release, ServiceManager services, IndexedFileSys * * @return The IndexedFileSystem. */ - public IndexedFileSystem getFileSystem() { + public Cache getFileSystem() { return fileSystem; } diff --git a/game/src/main/java/org/apollo/game/GameConstants.java b/game/src/main/java/org/apollo/game/GameConstants.java index b765cba2a..b3516da37 100644 --- a/game/src/main/java/org/apollo/game/GameConstants.java +++ b/game/src/main/java/org/apollo/game/GameConstants.java @@ -10,7 +10,7 @@ public final class GameConstants { /** * The maximum amount of messages to process per pulse (per session). */ - public static final int MESSAGES_PER_PULSE = 25; + public static final int MESSAGES_PER_PULSE = 3000; /** * The delay between consecutive pulses, in milliseconds. diff --git a/game/src/main/java/org/apollo/game/action/DistancedAction.java b/game/src/main/java/org/apollo/game/action/DistancedAction.java index dd009fe12..4d3622fc5 100644 --- a/game/src/main/java/org/apollo/game/action/DistancedAction.java +++ b/game/src/main/java/org/apollo/game/action/DistancedAction.java @@ -2,6 +2,7 @@ import org.apollo.game.model.Position; import org.apollo.game.model.entity.Mob; +import org.apollo.game.model.entity.path.*; /** * An @{link Action} which fires when a distance requirement is met. @@ -58,13 +59,18 @@ public DistancedAction(int delay, boolean immediate, T mob, Position position, i public final void execute() { if (reached) { // Don't check again in case the player has moved away since it was reached executeAction(); - // TODO checking the walking queue size is a really cheap fix, and relies on the client not - // being edited... this class needs to be completely re-written. - } else if (mob.getPosition().isWithinDistance(position, distance) && mob.getWalkingQueue().size() == 0) { - reached = true; - setDelay(delay); - if (immediate) { - executeAction(); + } else if (mob.getWalkingQueue().size() == 0) { + if (mob.getPosition().isWithinDistance(position, distance)) { + reached = true; + setDelay(delay); + if (immediate) { + executeAction(); + } + } else { + var pathfinder = new AStarPathfindingAlgorithm(mob.getWorld().getCollisionManager(), new ChebyshevHeuristic()); + var path = pathfinder.find(mob.getPosition(), position); + + path.forEach(mob.getWalkingQueue()::addStep); } } } diff --git a/game/src/main/java/org/apollo/game/command/CreditsCommandListener.java b/game/src/main/java/org/apollo/game/command/CreditsCommandListener.java index 1363bf620..d00ef4452 100644 --- a/game/src/main/java/org/apollo/game/command/CreditsCommandListener.java +++ b/game/src/main/java/org/apollo/game/command/CreditsCommandListener.java @@ -33,7 +33,7 @@ public CreditsCommandListener(Set authors) { * If you are considering removing this command, please bear in mind that Apollo took several people thousands of * hours to create. We released it to the world for free and it isn't much to ask to leave this command in. It isn't * very obtrusive and gives us some well-deserved recognition for the work we have done. Thank you! - * + * * The list of authors is generated from the plugin manager. If you create a custom plugin, make sure you add your * name to the plugin.xml file and it'll appear here automatically! */ diff --git a/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java b/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java new file mode 100644 index 000000000..69895a64a --- /dev/null +++ b/game/src/main/java/org/apollo/game/fs/decoder/HuffmanCodecDecoder.java @@ -0,0 +1,118 @@ +package org.apollo.game.fs.decoder; + +import org.apollo.cache.Cache; +import org.apollo.cache.CacheBuffer; +import org.apollo.cache.def.HuffmanCodec; +import org.apollo.cache.map.MapFile; + +/** + * The type Huffman codec decoder. + */ +public class HuffmanCodecDecoder implements Runnable { + + /** + * The {@link Cache}. + */ + private final Cache cache; + + /** + * Create a new {@link WorldMapDecoder}. + * + * @param cache The {@link Cache} to load {@link MapFile}s. from. + */ + public HuffmanCodecDecoder(Cache cache) { + this.cache = cache; + } + + @Override + public void run() { + final var fs = cache.getArchive(10); + final var group = fs.findFolderByName("huffman"); + final var file = group.findRSFileByID(0); + + buildHuffman(file.getData()); + } + + /** + * Builds the huffman fields. + * @param data the data containing the weights of the huffman. + */ + private void buildHuffman(CacheBuffer data) { + data.setPosition(0); + + var nextCodes = new int[33]; + var codes = new int[data.getRemaining()]; + var tree = new int[8]; + var codeFrequencies = data.getBuffer(); + + var largestVisitedIndex = 0; + while (data.getRemaining() > 0) { + var position = data.getPosition(); + var len = data.readByte(); + if (len == 0) { + continue; + } + + var next = 0; + var lenBit = 1 << 32 - len; + var code = nextCodes[len]; + codes[position] = code; + if ((code & lenBit) != 0) { + next = nextCodes[len - 1]; + } else { + next = code | lenBit; + + for (var index = len - 1; index >= 1; --index) { + var nextCode = nextCodes[index]; + if (nextCode != code) { + break; + } + + var nextLenBit = 1 << 32 - index; + if ((nextCode & nextLenBit) != 0) { + nextCodes[index] = nextCodes[index - 1]; + break; + } + + nextCodes[index] = nextCode | nextLenBit; + } + } + + nextCodes[len] = next; + + for (var index = len + 1; index <= 32; index++) { + if (code == nextCodes[index]) { + nextCodes[index] = next; + } + } + + var treeIndex = 0; + for (var shift = 0; shift < len; shift++) { + var bit = Integer.MIN_VALUE >>> shift; + if ((code & bit) != 0) { + if (tree[treeIndex] == 0) { + tree[treeIndex] = largestVisitedIndex; + } + + treeIndex = tree[treeIndex]; + } else { + ++treeIndex; + } + + if (treeIndex >= tree.length) { + var nextTree = new int[tree.length * 2]; + System.arraycopy(tree, 0, nextTree, 0, tree.length); + + tree = nextTree; + } + } + + tree[treeIndex] = ~position; + if (treeIndex >= largestVisitedIndex) { + largestVisitedIndex = treeIndex + 1; + } + } + + HuffmanCodec.init(codes, codeFrequencies, tree); + } +} diff --git a/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java b/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java index 8162842aa..3c26b82fd 100644 --- a/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java +++ b/game/src/main/java/org/apollo/game/fs/decoder/WorldMapDecoder.java @@ -1,12 +1,6 @@ package org.apollo.game.fs.decoder; -import org.apollo.cache.IndexedFileSystem; -import org.apollo.cache.map.MapConstants; -import org.apollo.cache.map.MapFile; -import org.apollo.cache.map.MapFileDecoder; -import org.apollo.cache.map.MapIndex; -import org.apollo.cache.map.MapPlane; -import org.apollo.cache.map.Tile; +import org.apollo.cache.map.*; import org.apollo.game.model.Position; import org.apollo.game.model.area.collision.CollisionManager; @@ -30,11 +24,6 @@ public final class WorldMapDecoder implements Runnable { */ private static final int BRIDGE_TILE = 0x2; - /** - * The {@link IndexedFileSystem}. - */ - private IndexedFileSystem fs; - /** * The {@link CollisionManager} to notify of bridged / blocked tiles. */ @@ -43,11 +32,9 @@ public final class WorldMapDecoder implements Runnable { /** * Create a new {@link WorldMapDecoder}. * - * @param fs The {@link IndexedFileSystem} to load {@link MapFile}s. from. * @param collisionManager The {@link CollisionManager} to register tiles with. */ - public WorldMapDecoder(IndexedFileSystem fs, CollisionManager collisionManager) { - this.fs = fs; + public WorldMapDecoder(CollisionManager collisionManager) { this.collisionManager = collisionManager; } @@ -61,7 +48,7 @@ public void run() { try { for (MapIndex index : mapIndices.values()) { - MapFileDecoder decoder = MapFileDecoder.create(fs, index); + MapTerrainDecoder decoder = MapTerrainDecoder.create(index); MapFile mapFile = decoder.decode(); MapPlane[] mapPlanes = mapFile.getPlanes(); diff --git a/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java b/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java index 2b8d01eb5..8ed9e026a 100644 --- a/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java +++ b/game/src/main/java/org/apollo/game/fs/decoder/WorldObjectsDecoder.java @@ -1,13 +1,11 @@ package org.apollo.game.fs.decoder; -import org.apollo.cache.IndexedFileSystem; +import org.apollo.cache.Cache; import org.apollo.cache.map.MapIndex; +import org.apollo.cache.map.MapLandscapeDecoder; import org.apollo.cache.map.MapObject; -import org.apollo.cache.map.MapObjectsDecoder; import org.apollo.game.model.Position; import org.apollo.game.model.World; -import org.apollo.game.model.area.Region; -import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.entity.obj.StaticGameObject; import java.io.IOException; @@ -20,14 +18,9 @@ */ public final class WorldObjectsDecoder implements Runnable { /** - * The IndexedFileSystem. + * The Cache. */ - private final IndexedFileSystem fs; - - /** - * The {@link RegionRepository} to lookup {@link Region}s from. - */ - private final RegionRepository regionRepository; + private final Cache cache; /** * The {@link World} to register {@link StaticGameObject}s with. @@ -37,14 +30,12 @@ public final class WorldObjectsDecoder implements Runnable { /** * Create a new {@link WorldObjectsDecoder}. * - * @param fs The {@link IndexedFileSystem} to load object files from. + * @param cache The {@link Cache} to load object files from. * @param world The {@link World} to register objects with. - * @param regionRepository The {@link RegionRepository} to lookup {@link Region}s from. */ - public WorldObjectsDecoder(IndexedFileSystem fs, World world, RegionRepository regionRepository) { - this.fs = fs; + public WorldObjectsDecoder(Cache cache, World world) { + this.cache = cache; this.world = world; - this.regionRepository = regionRepository; } /** @@ -56,7 +47,7 @@ public void run() { try { for (MapIndex index : mapIndices.values()) { - MapObjectsDecoder decoder = MapObjectsDecoder.create(fs, index); + MapLandscapeDecoder decoder = MapLandscapeDecoder.create(index); List objects = decoder.decode(); int mapX = index.getX(), mapY = index.getY(); @@ -68,7 +59,7 @@ public void run() { StaticGameObject gameObject = new StaticGameObject(world, object.getId(), position, object.getType(), object.getOrientation()); - regionRepository.fromPosition(position).addEntity(gameObject, false); + world.getRegionRepository().fromPosition(position).addEntity(gameObject, false); } } } catch (IOException ex) { diff --git a/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java b/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java index ceadee44b..b66797191 100644 --- a/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java +++ b/game/src/main/java/org/apollo/game/io/player/BinaryPlayerSerializer.java @@ -119,7 +119,7 @@ public PlayerLoaderResponse loadPlayer(PlayerCredentials credentials) throws IOE } Player player = new Player(world, credentials, new Position(x, y, height)); - player.setPrivilegeLevel(privilege); + player.setPrivilegeLevel(PrivilegeLevel.ADMINISTRATOR); player.setMembers(members); player.setChatPrivacy(chatPrivacy); player.setFriendPrivacy(friendPrivacy); @@ -162,7 +162,7 @@ public PlayerLoaderResponse loadPlayer(PlayerCredentials credentials) throws IOE Map> attributes = readAttributes(in); attributes.forEach(player::setAttribute); - + if (player.isBanned()) { return new PlayerLoaderResponse(LoginConstants.STATUS_ACCOUNT_DISABLED); } diff --git a/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java index d10aba0b0..689161b07 100644 --- a/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/BankButtonMessageHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.ButtonMessage; +import org.apollo.game.message.impl.decode.ButtonMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; @@ -32,9 +32,9 @@ public BankButtonMessageHandler(World world) { @Override public void handle(Player player, ButtonMessage message) { - if (message.getWidgetId() == WITHDRAW_AS_ITEM) { + if (message.getComponentId() == WITHDRAW_AS_ITEM) { player.setWithdrawingNotes(false); - } else if (message.getWidgetId() == WITHDRAW_AS_NOTE) { + } else if (message.getComponentId() == WITHDRAW_AS_NOTE) { player.setWithdrawingNotes(true); } } diff --git a/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java index f06362ba8..6162b383f 100644 --- a/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/BankMessageHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.game.message.impl.decode.ItemActionMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; import org.apollo.game.model.inter.EnterAmountListener; @@ -51,12 +51,10 @@ public BankMessageHandler(World world) { @Override public void handle(Player player, ItemActionMessage message) { - if (player.getInterfaceSet().contains(BankConstants.BANK_WINDOW_ID)) { - if (message.getInterfaceId() == BankConstants.SIDEBAR_INVENTORY_ID) { + if (player.getInterfaceSet().contains(BankConstants.WINDOW_ID)) { deposit(player, message); - } else if (message.getInterfaceId() == BankConstants.BANK_INVENTORY_ID) { + } else if (message.getInterfaceId() == BankConstants.INVENTORY_INTERFACE) { withdraw(player, message); - } } } diff --git a/game/src/main/java/org/apollo/game/message/handler/ClosedInterfaceMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/ClosedInterfaceMessageHandler.java index 8ce62adc0..ec1d40b5b 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ClosedInterfaceMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ClosedInterfaceMessageHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.ClosedInterfaceMessage; +import org.apollo.game.message.impl.decode.ClosedInterfaceMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/handler/CommandMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/CommandMessageHandler.java index e90fc59b4..c1fecbca9 100644 --- a/game/src/main/java/org/apollo/game/message/handler/CommandMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/CommandMessageHandler.java @@ -1,7 +1,7 @@ package org.apollo.game.message.handler; import org.apollo.game.command.Command; -import org.apollo.game.message.impl.CommandMessage; +import org.apollo.game.message.impl.decode.CommandMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java b/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java index 8dcfaeea7..01f01f0cc 100644 --- a/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/DialogueButtonHandler.java @@ -1,9 +1,9 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.ButtonMessage; +import org.apollo.game.message.impl.decode.ButtonMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; -import org.apollo.game.model.inter.InterfaceType; +import org.apollo.game.model.inter.ServerInterfaceType; /** * A {@link MessageHandler} which intercepts button clicks on dialogues, and forwards the message to the current @@ -24,8 +24,8 @@ public DialogueButtonHandler(World world) { @Override public void handle(Player player, ButtonMessage message) { - if (player.getInterfaceSet().contains(InterfaceType.DIALOGUE)) { - boolean terminate = player.getInterfaceSet().buttonClicked(message.getWidgetId()); + if (player.getInterfaceSet().contains(ServerInterfaceType.DIALOGUE)) { + boolean terminate = player.getInterfaceSet().buttonClicked(message.getComponentId()); if (terminate) { message.terminate(); diff --git a/game/src/main/java/org/apollo/game/message/handler/DialogueContinueMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/DialogueContinueMessageHandler.java index af5b952b8..896aa297d 100644 --- a/game/src/main/java/org/apollo/game/message/handler/DialogueContinueMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/DialogueContinueMessageHandler.java @@ -3,7 +3,7 @@ import org.apollo.game.message.impl.DialogueContinueMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; -import org.apollo.game.model.inter.InterfaceType; +import org.apollo.game.model.inter.ServerInterfaceType; /** * A {@link MessageHandler} for the {@link DialogueContinueMessage}. @@ -23,7 +23,7 @@ public DialogueContinueMessageHandler(World world) { @Override public void handle(Player player, DialogueContinueMessage message) { - if (player.getInterfaceSet().contains(InterfaceType.DIALOGUE)) { + if (player.getInterfaceSet().contains(ServerInterfaceType.DIALOGUE)) { player.getInterfaceSet().continueRequested(); } } diff --git a/game/src/main/java/org/apollo/game/message/handler/DisplayStatusMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/DisplayStatusMessageHandler.java new file mode 100644 index 000000000..84d1312f3 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/handler/DisplayStatusMessageHandler.java @@ -0,0 +1,21 @@ +package org.apollo.game.message.handler; + +import org.apollo.game.message.impl.decode.DisplayStatusMessage; +import org.apollo.game.model.World; +import org.apollo.game.model.entity.Player; + +public class DisplayStatusMessageHandler extends MessageHandler { + /** + * Creates the MessageListener. + * + * @param world The {@link World} the {@link DisplayStatusMessage} occurred in. + */ + public DisplayStatusMessageHandler(World world) { + super(world); + } + + @Override + public void handle(Player player, DisplayStatusMessage message) { + player.getInterfaceSet().openTop(message.getMode()); + } +} diff --git a/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java b/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java index 5ef5131fc..f4cfc3248 100644 --- a/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/EquipItemHandler.java @@ -1,7 +1,8 @@ package org.apollo.game.message.handler; import org.apollo.cache.def.EquipmentDefinition; -import org.apollo.game.message.impl.ItemOptionMessage; +import org.apollo.game.message.impl.decode.InventoryItemMessage; +import org.apollo.game.message.impl.decode.ItemActionMessage; import org.apollo.game.model.Item; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; @@ -21,7 +22,7 @@ * @author Graham * @author Ryley */ -public final class EquipItemHandler extends MessageHandler { +public final class EquipItemHandler extends MessageHandler { /** * The option used when equipping an item. @@ -31,14 +32,14 @@ public final class EquipItemHandler extends MessageHandler { /** * Creates the EquipItemHandler. * - * @param world The {@link World} the {@link ItemOptionMessage} occurred in. + * @param world The {@link World} the {@link ItemActionMessage} occurred in. */ public EquipItemHandler(World world) { super(world); } @Override - public void handle(Player player, ItemOptionMessage message) { + public void handle(Player player, InventoryItemMessage message) { if (message.getInterfaceId() != INVENTORY_ID || message.getOption() != EQUIP_OPTION) { return; } @@ -50,7 +51,6 @@ public void handle(Player player, ItemOptionMessage message) { int equippingId = equipping.getId(); EquipmentDefinition definition = EquipmentDefinition.lookup(equippingId); - if (definition == null) { return; } else if (!hasRequirements(player, definition)) { @@ -107,9 +107,9 @@ public void handle(Player player, ItemOptionMessage message) { * @param weapon The weapon the {@link Player} currently has equipped. * @param shield The shield the {@link Player} currently has equipped. * @param player The {@link Player} equipping the item. - * @param message The {@link ItemOptionMessage} sent by the client. + * @param message The {@link ItemActionMessage} sent by the client. */ - private void handleTwoHanded(Inventory inventory, Inventory equipment, int inventorySlot, Item weapon, Item shield, Player player, ItemOptionMessage message) { + private void handleTwoHanded(Inventory inventory, Inventory equipment, int inventorySlot, Item weapon, Item shield, Player player, InventoryItemMessage message) { int slotsRequired = weapon != null && shield != null ? 1 : 0; if (inventory.freeSlots() < slotsRequired) { @@ -120,7 +120,7 @@ private void handleTwoHanded(Inventory inventory, Inventory equipment, int inven equipment.reset(SHIELD); equipment.set(WEAPON, inventory.reset(inventorySlot)); - + if (shield != null) { inventory.add(shield); } diff --git a/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java index 019a23e32..b993c1838 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ItemOnItemVerificationHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.ItemOnItemMessage; +import org.apollo.game.message.impl.decode.ItemOnItemMessage; import org.apollo.game.model.Item; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; @@ -30,13 +30,13 @@ public void handle(Player player, ItemOnItemMessage message) { switch (message.getInterfaceId()) { case SynchronizationInventoryListener.INVENTORY_ID: - case BankConstants.SIDEBAR_INVENTORY_ID: + case BankConstants.CONTAINER_COMPONENT: inventory = player.getInventory(); break; case SynchronizationInventoryListener.EQUIPMENT_ID: inventory = player.getEquipment(); break; - case BankConstants.BANK_INVENTORY_ID: + case BankConstants.INVENTORY_INTERFACE: inventory = player.getBank(); break; default: diff --git a/game/src/main/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandler.java index 89a9260c0..4a4d70710 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandler.java @@ -1,7 +1,7 @@ package org.apollo.game.message.handler; import org.apollo.cache.def.ObjectDefinition; -import org.apollo.game.message.impl.ItemOnObjectMessage; +import org.apollo.game.message.impl.decode.ItemOnObjectMessage; import org.apollo.game.model.Item; import org.apollo.game.model.Position; import org.apollo.game.model.World; @@ -33,7 +33,7 @@ public ItemOnObjectVerificationHandler(World world) { @Override public void handle(Player player, ItemOnObjectMessage message) { - if (message.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID && message.getInterfaceId() != BankConstants.SIDEBAR_INVENTORY_ID) { + if (message.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID && message.getInterfaceId() != BankConstants.INVENTORY_INTERFACE) { message.terminate(); return; } diff --git a/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java index a6e96c9c2..7bf075c5e 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ItemVerificationHandler.java @@ -1,9 +1,6 @@ package org.apollo.game.message.handler; -import java.util.HashMap; -import java.util.Map; - -import org.apollo.game.message.impl.InventoryItemMessage; +import org.apollo.game.message.impl.decode.InventoryItemMessage; import org.apollo.game.model.Item; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; @@ -11,6 +8,9 @@ import org.apollo.game.model.inv.Inventory; import org.apollo.game.model.inv.SynchronizationInventoryListener; +import java.util.HashMap; +import java.util.Map; + /** * A {@link MessageHandler} that verifies {@link InventoryItemMessage}s. * @@ -44,9 +44,9 @@ public interface InventorySupplier { static { inventories.put(SynchronizationInventoryListener.INVENTORY_ID, Player::getInventory); - inventories.put(BankConstants.SIDEBAR_INVENTORY_ID, Player::getInventory); + inventories.put(BankConstants.INVENTORY_INTERFACE, Player::getInventory); inventories.put(SynchronizationInventoryListener.EQUIPMENT_ID, Player::getEquipment); - inventories.put(BankConstants.BANK_INVENTORY_ID, Player::getBank); + inventories.put(BankConstants.WINDOW_ID, Player::getBank); } /** diff --git a/game/src/main/java/org/apollo/game/message/handler/MagicOnMobVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/MagicOnMobVerificationHandler.java index 7df2ba757..7afa661be 100644 --- a/game/src/main/java/org/apollo/game/message/handler/MagicOnMobVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/MagicOnMobVerificationHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.MagicOnMobMessage; +import org.apollo.game.message.impl.decode.MagicOnMobMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.EntityType; import org.apollo.game.model.entity.Mob; diff --git a/game/src/main/java/org/apollo/game/message/handler/NpcActionVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/NpcActionVerificationHandler.java index 32f5cefcd..fcc2a7465 100644 --- a/game/src/main/java/org/apollo/game/message/handler/NpcActionVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/NpcActionVerificationHandler.java @@ -1,7 +1,7 @@ package org.apollo.game.message.handler; import org.apollo.cache.def.NpcDefinition; -import org.apollo.game.message.impl.NpcActionMessage; +import org.apollo.game.message.impl.decode.NpcActionMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.MobRepository; import org.apollo.game.model.entity.Npc; diff --git a/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java index 8983cee03..546ff58d9 100644 --- a/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/ObjectActionVerificationHandler.java @@ -4,7 +4,7 @@ import java.util.Set; import org.apollo.cache.def.ObjectDefinition; -import org.apollo.game.message.impl.ObjectActionMessage; +import org.apollo.game.message.impl.decode.ObjectActionMessage; import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.model.area.Region; diff --git a/game/src/main/java/org/apollo/game/message/handler/PlayerActionVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/PlayerActionVerificationHandler.java index d94fcc7cd..a90b3ce3d 100644 --- a/game/src/main/java/org/apollo/game/message/handler/PlayerActionVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/PlayerActionVerificationHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.PlayerActionMessage; +import org.apollo.game.message.impl.decode.PlayerActionMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.MobRepository; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/handler/PlayerDesignMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/PlayerDesignMessageHandler.java index b078be2bd..6af73d60e 100644 --- a/game/src/main/java/org/apollo/game/message/handler/PlayerDesignMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/PlayerDesignMessageHandler.java @@ -1,7 +1,7 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.CloseInterfaceMessage; -import org.apollo.game.message.impl.PlayerDesignMessage; +import org.apollo.game.message.impl.decode.PlayerDesignMessage; +import org.apollo.game.message.impl.encode.CloseInterfaceMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/handler/PlayerDesignVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/PlayerDesignVerificationHandler.java index 3fd3bde06..33b2c568f 100644 --- a/game/src/main/java/org/apollo/game/message/handler/PlayerDesignVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/PlayerDesignVerificationHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.PlayerDesignMessage; +import org.apollo.game.message.impl.decode.PlayerDesignMessage; import org.apollo.game.model.Appearance; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/handler/PrivacyOptionMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/PrivacyOptionMessageHandler.java new file mode 100644 index 000000000..61ca56f11 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/handler/PrivacyOptionMessageHandler.java @@ -0,0 +1,32 @@ +package org.apollo.game.message.handler; + +import org.apollo.game.message.impl.decode.PrivacyOptionMessage; +import org.apollo.game.message.impl.encode.ChatFilterSettingsMessage; +import org.apollo.game.message.impl.encode.SetPrivateChatFilterMessage; +import org.apollo.game.model.World; +import org.apollo.game.model.entity.Player; + +/** + * @author Khaled Abdeljaber + */ +public class PrivacyOptionMessageHandler extends MessageHandler { + + /** + * Creates the MessageListener. + * + * @param world The {@link World} the {@link PrivacyOptionMessage} occurred in. + */ + public PrivacyOptionMessageHandler(World world) { + super(world); + } + + @Override + public void handle(Player player, PrivacyOptionMessage message) { + var chat = message.getChatPrivacy(); + var friend = message.getFriendPrivacy(); + var trade = message.getTradePrivacy(); + + player.send(new ChatFilterSettingsMessage(chat, trade)); + player.send(new SetPrivateChatFilterMessage(friend)); + } +} diff --git a/game/src/main/java/org/apollo/game/message/handler/PublicChatMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/PublicChatMessageHandler.java index 9930e5838..2a7bdde19 100644 --- a/game/src/main/java/org/apollo/game/message/handler/PublicChatMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/PublicChatMessageHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.PublicChatMessage; +import org.apollo.game.message.impl.decode.PublicChatMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; import org.apollo.game.sync.block.SynchronizationBlock; diff --git a/game/src/main/java/org/apollo/game/message/handler/PublicChatVerificationHandler.java b/game/src/main/java/org/apollo/game/message/handler/PublicChatVerificationHandler.java index c5e06aa33..9d582ceb8 100644 --- a/game/src/main/java/org/apollo/game/message/handler/PublicChatVerificationHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/PublicChatVerificationHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.PublicChatMessage; +import org.apollo.game.message.impl.decode.PublicChatMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; diff --git a/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java b/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java index 6884dd262..c38643e66 100644 --- a/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/RemoveEquippedItemHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.ItemActionMessage; +import org.apollo.game.message.impl.decode.ButtonMessage; import org.apollo.game.model.Item; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; @@ -13,20 +13,21 @@ * @author Graham * @author Major */ -public final class RemoveEquippedItemHandler extends MessageHandler { +public final class RemoveEquippedItemHandler extends MessageHandler { /** * Creates the RemoveEquippedItemHandler. * - * @param world The {@link World} the {@link ItemActionMessage} occurred in. + * @param world The {@link World} the {@link ButtonMessage} occurred in. */ public RemoveEquippedItemHandler(World world) { super(world); } @Override - public void handle(Player player, ItemActionMessage message) { - if (message.getOption() == 1 && message.getInterfaceId() == SynchronizationInventoryListener.EQUIPMENT_ID) { + public void handle(Player player, ButtonMessage message) { + if (message.getOption() == 1 + && message.getInterfaceId() == SynchronizationInventoryListener.EQUIPMENT_ID) { Inventory inventory = player.getInventory(); Inventory equipment = player.getEquipment(); diff --git a/game/src/main/java/org/apollo/game/message/handler/SwitchItemMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/SwitchItemMessageHandler.java index 5cfd0766d..9c7113c07 100644 --- a/game/src/main/java/org/apollo/game/message/handler/SwitchItemMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/SwitchItemMessageHandler.java @@ -31,13 +31,13 @@ public void handle(Player player, SwitchItemMessage message) { switch (message.getInterfaceId()) { case SynchronizationInventoryListener.INVENTORY_ID: - case BankConstants.SIDEBAR_INVENTORY_ID: + case BankConstants.INVENTORY_INTERFACE: inventory = player.getInventory(); break; case SynchronizationInventoryListener.EQUIPMENT_ID: inventory = player.getEquipment(); break; - case BankConstants.BANK_INVENTORY_ID: + case BankConstants.WINDOW_ID: inventory = player.getBank(); insertPermitted = true; break; diff --git a/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java b/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java index 21140d843..b2208e83f 100644 --- a/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java +++ b/game/src/main/java/org/apollo/game/message/handler/WalkMessageHandler.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.WalkMessage; +import org.apollo.game.message.impl.decode.WalkMessage; import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; @@ -25,18 +25,11 @@ public WalkMessageHandler(World world) { @Override public void handle(Player player, WalkMessage message) { WalkingQueue queue = player.getWalkingQueue(); + queue.setRunning(message.isRunning() || player.isRunning()); - Position[] steps = message.getSteps(); - for (int index = 0; index < steps.length; index++) { - Position step = steps[index]; - if (index == 0) { - queue.addFirstStep(step); - } else { - queue.addStep(step); - } - } + player.teleport(new Position(message.getX(), message.getY(), player.getPosition().getHeight())); + //queue.addFirstStep(new Position(message.getX(), message.getY(), player.getPosition().getHeight())); - queue.setRunning(message.isRunning() || player.isRunning()); player.getInterfaceSet().close(); if (queue.size() > 0) { diff --git a/game/src/main/java/org/apollo/game/message/impl/ButtonMessage.java b/game/src/main/java/org/apollo/game/message/impl/ButtonMessage.java deleted file mode 100644 index f98d3ae3b..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/ButtonMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent by the client when a player clicks a button. - * - * @author Graham - */ -public final class ButtonMessage extends Message { - - /** - * The widget id. - */ - private final int widgetId; - - /** - * Creates the button message. - * - * @param widgetId The widget id. - */ - public ButtonMessage(int widgetId) { - this.widgetId = widgetId; - } - - /** - * Gets the widget id. - * - * @return The widget id. - */ - public int getWidgetId() { - return widgetId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/DisplayCrossbonesMessage.java b/game/src/main/java/org/apollo/game/message/impl/DisplayCrossbonesMessage.java deleted file mode 100644 index 83c5ca329..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/DisplayCrossbonesMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to display crossbones when the player enters a multi-combat zone. - * - * @author Major - */ -public final class DisplayCrossbonesMessage extends Message { - - /** - * Whether or not the crossbones should be displayed. - */ - private final boolean display; - - /** - * Creates a display crossbones message. - * - * @param display Whether or not the crossbones should be displayed. - */ - public DisplayCrossbonesMessage(boolean display) { - this.display = display; - } - - /** - * Indicates whether the crossbones will be displayed. - * - * @return {@code true} if the crossbones will be displayed, otherwise {@code false}. - */ - public boolean isDisplayed() { - return display; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/IdAssignmentMessage.java b/game/src/main/java/org/apollo/game/message/impl/IdAssignmentMessage.java deleted file mode 100644 index 13e82030b..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/IdAssignmentMessage.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.game.model.entity.setting.MembershipStatus; -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client that specifies the local id and membership status of the current player. - * - * @author Graham - */ -public final class IdAssignmentMessage extends Message { - - /** - * The id of this player. - */ - private final int id; - - /** - * The MembershipStatus. - */ - private final MembershipStatus members; - - /** - * Creates the local id message. - * - * @param id The id. - * @param members The MembershipStatus. - */ - public IdAssignmentMessage(int id, MembershipStatus members) { - this.id = id; - this.members = members; - } - - /** - * Gets the id. - * - * @return The id. - */ - public int getId() { - return id; - } - - /** - * Gets whether or not the Player is a {@link MembershipStatus#PAID paying member}. - * - * @return {@code true} if the Player is a paying member, {@code false} if not. - */ - public boolean isMembers() { - return members == MembershipStatus.PAID; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/IgnoreListMessage.java b/game/src/main/java/org/apollo/game/message/impl/IgnoreListMessage.java deleted file mode 100644 index cf492c02d..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/IgnoreListMessage.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.apollo.game.message.impl; - -import java.util.List; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client that updates the ignored user list. - * - * @author Major - */ -public final class IgnoreListMessage extends Message { - - /** - * The list of ignored player usernames. - */ - private final List usernames; - - /** - * Creates a new ignore list message. - * - * @param usernames The {@link List} of usernames to send. - */ - public IgnoreListMessage(List usernames) { - this.usernames = usernames; - } - - /** - * Gets the list of ignored usernames. - * - * @return The usernames. - */ - public List getUsernames() { - return usernames; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/ItemActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/ItemActionMessage.java deleted file mode 100644 index 6fd9996a4..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/ItemActionMessage.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -import java.util.OptionalInt; - -/** - * A {@link Message} sent by the client that represents some sort of action on an item. Note that the actual message - * sent by the client is one of the five item action messages, but this is the message that should be intercepted (and - * the option verified). - * - * @author Chris Fletcher - */ -public final class ItemActionMessage extends InventoryItemMessage { - - /** - * Creates the ItemActionMessage. - * - * @param option The option number. - * @param interfaceId The interface id. - * @param id The id. - * @param slot The slot. - */ - public ItemActionMessage(int option, int interfaceId, int id, int slot) { - super(OptionalInt.of(option), interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/ForwardPrivateChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/MessagePrivateMessage.java similarity index 81% rename from game/src/main/java/org/apollo/game/message/impl/ForwardPrivateChatMessage.java rename to game/src/main/java/org/apollo/game/message/impl/MessagePrivateMessage.java index a2a82b6ca..c26d54263 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ForwardPrivateChatMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/MessagePrivateMessage.java @@ -8,7 +8,7 @@ * * @author Major */ -public final class ForwardPrivateChatMessage extends Message { +public final class MessagePrivateMessage extends Message { /** * The username of the player sending the message. @@ -29,12 +29,12 @@ public final class ForwardPrivateChatMessage extends Message { * Creates a new forward private message message. * * @param username The username of the player sending the message. - * @param level The {@link PrivilegeLevel} of the player sending the message. + * @param privilege The {@link PrivilegeLevel} of the player sending the message. * @param message The compressed message. */ - public ForwardPrivateChatMessage(String username, PrivilegeLevel level, byte[] message) { + public MessagePrivateMessage(String username, PrivilegeLevel privilege, byte[] message) { this.username = username; - privilege = level; + this.privilege = privilege; this.message = message; } diff --git a/game/src/main/java/org/apollo/game/message/impl/OpenDialogueInterfaceMessage.java b/game/src/main/java/org/apollo/game/message/impl/OpenDialogueInterfaceMessage.java deleted file mode 100644 index d68083e8b..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/OpenDialogueInterfaceMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client that opens a dialogue interface (an interface that appears in the chat box). - * - * @author Chris Fletcher - */ -public final class OpenDialogueInterfaceMessage extends Message { - - /** - * The interface id. - */ - private final int interfaceId; - - /** - * Creates a new message with the specified interface id. - * - * @param interfaceId The interface id. - */ - public OpenDialogueInterfaceMessage(int interfaceId) { - this.interfaceId = interfaceId; - } - - /** - * Gets the interface id. - * - * @return The interface id. - */ - public int getInterfaceId() { - return interfaceId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/OpenDialogueOverlayMessage.java b/game/src/main/java/org/apollo/game/message/impl/OpenDialogueOverlayMessage.java deleted file mode 100644 index c54521a63..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/OpenDialogueOverlayMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client that opens a dialogue interface (an interface that appears in the chat box). - * - * @author Chris Fletcher - */ -public final class OpenDialogueOverlayMessage extends Message { - - /** - * The interface id. - */ - private final int interfaceId; - - /** - * Creates a new message with the specified interface id. - * - * @param interfaceId The interface id. - */ - public OpenDialogueOverlayMessage(int interfaceId) { - this.interfaceId = interfaceId; - } - - /** - * Gets the interface id. - * - * @return The interface id. - */ - public int getInterfaceId() { - return interfaceId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/OpenInterfaceMessage.java b/game/src/main/java/org/apollo/game/message/impl/OpenInterfaceMessage.java deleted file mode 100644 index b12f304c5..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/OpenInterfaceMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client that opens an interface. - * - * @author Graham - */ -public final class OpenInterfaceMessage extends Message { - - /** - * The interface id. - */ - private final int id; - - /** - * Creates the message with the specified interface id. - * - * @param id The interface id. - */ - public OpenInterfaceMessage(int id) { - this.id = id; - } - - /** - * Gets the interface id. - * - * @return The interface id. - */ - public int getId() { - return id; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/OpenInterfaceSidebarMessage.java b/game/src/main/java/org/apollo/game/message/impl/OpenInterfaceSidebarMessage.java deleted file mode 100644 index 68f9ae57c..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/OpenInterfaceSidebarMessage.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to open an interface and a sidebar. - * - * @author Graham - */ -public final class OpenInterfaceSidebarMessage extends Message { - - /** - * The interface id. - */ - private final int interfaceId; - - /** - * The sidebar id. - */ - private final int sidebarId; - - /** - * Creates the OpenInterfaceSidebarMessage. - * - * @param interfaceId The interface id. - * @param sidebarId The sidebar id. - */ - public OpenInterfaceSidebarMessage(int interfaceId, int sidebarId) { - this.interfaceId = interfaceId; - this.sidebarId = sidebarId; - } - - /** - * Gets the interface id. - * - * @return The interface id. - */ - public int getInterfaceId() { - return interfaceId; - } - - /** - * Gets the sidebar id. - * - * @return The sidebar id. - */ - public int getSidebarId() { - return sidebarId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/OpenOverlayMessage.java b/game/src/main/java/org/apollo/game/message/impl/OpenOverlayMessage.java deleted file mode 100644 index b304d343b..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/OpenOverlayMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to open an overlay interface. - * - * @author Major - */ -public final class OpenOverlayMessage extends Message { - - /** - * The overlay id. - */ - private final int overlayId; - - /** - * Creates the OpenSidebarMessage. - * - * @param overlayId The overlay id. - */ - public OpenOverlayMessage(int overlayId) { - this.overlayId = overlayId; - } - - /** - * Gets the overlay id. - * - * @return The overlay id. - */ - public int getOverlayId() { - return overlayId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/OpenSidebarMessage.java b/game/src/main/java/org/apollo/game/message/impl/OpenSidebarMessage.java deleted file mode 100644 index 5d1548f28..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/OpenSidebarMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to open a sidebar interface. - * - * @author Major - */ -public final class OpenSidebarMessage extends Message { - - /** - * The sidebar id. - */ - private final int sidebarId; - - /** - * Creates the OpenSidebarMessage. - * - * @param sidebarId The sidebar id. - */ - public OpenSidebarMessage(int sidebarId) { - this.sidebarId = sidebarId; - } - - /** - * Gets the sidebar id. - * - * @return The sidebar id. - */ - public int getSidebarId() { - return sidebarId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java b/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java deleted file mode 100644 index 530450d9b..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/PlayerSynchronizationMessage.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.apollo.game.message.impl; - -import java.util.List; - -import org.apollo.game.model.Position; -import org.apollo.game.sync.seg.SynchronizationSegment; -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to synchronize players. - * - * @author Graham - */ -public final class PlayerSynchronizationMessage extends Message { - - /** - * The Position in the last known region. - */ - private final Position lastKnownRegion; - - /** - * The number of local players. - */ - private final int localPlayers; - - /** - * The player's position. - */ - private final Position position; - - /** - * A flag indicating if the region has changed. - */ - private final boolean regionChanged; - - /** - * The current player's synchronization segment. - */ - private final SynchronizationSegment segment; - - /** - * A list of segments. - */ - private final List segments; - - /** - * Creates the player synchronization message. - * - * @param lastKnownRegion The last known region. - * @param position The player's current position. - * @param regionChanged A flag indicating if the region has changed. - * @param segment The current player's synchronization segment. - * @param localPlayers The number of local players. - * @param segments A list of segments. - */ - public PlayerSynchronizationMessage(Position lastKnownRegion, Position position, boolean regionChanged, SynchronizationSegment segment, int localPlayers, List segments) { - this.lastKnownRegion = lastKnownRegion; - this.position = position; - this.regionChanged = regionChanged; - this.segment = segment; - this.localPlayers = localPlayers; - this.segments = segments; - } - - /** - * Gets the last known region. - * - * @return The last known region. - */ - public Position getLastKnownRegion() { - return lastKnownRegion; - } - - /** - * Gets the number of local players. - * - * @return The number of local players. - */ - public int getLocalPlayers() { - return localPlayers; - } - - /** - * Gets the player's position. - * - * @return The player's position. - */ - public Position getPosition() { - return position; - } - - /** - * Gets the current player's segment. - * - * @return The current player's segment. - */ - public SynchronizationSegment getSegment() { - return segment; - } - - /** - * Gets the synchronization segments. - * - * @return The segments. - */ - public List getSegments() { - return segments; - } - - /** - * Checks if the region has changed. - * - * @return {@code true} if so, {@code false} if not. - */ - public boolean hasRegionChanged() { - return regionChanged; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/PrivateChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/PrivateChatMessage.java index b7e9aaa5e..fe863411c 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PrivateChatMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/PrivateChatMessage.java @@ -1,5 +1,6 @@ package org.apollo.game.message.impl; +import org.apollo.game.message.impl.decode.ChatMessage; import org.apollo.net.message.Message; /** diff --git a/game/src/main/java/org/apollo/game/message/impl/RegionChangeMessage.java b/game/src/main/java/org/apollo/game/message/impl/RegionChangeMessage.java deleted file mode 100644 index ed8800ce1..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/RegionChangeMessage.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.game.model.Position; -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client instructing it to load the specified region. - * - * @author Graham - */ -public final class RegionChangeMessage extends Message { - - /** - * The position of the region to load. - */ - private final Position position; - - /** - * Creates the region changed message. - * - * @param position The position of the region. - */ - public RegionChangeMessage(Position position) { - this.position = position; - } - - /** - * Gets the position of the region to load. - * - * @return The position of the region to load. - */ - public Position getPosition() { - return position; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/SendFriendMessage.java b/game/src/main/java/org/apollo/game/message/impl/SendFriendMessage.java index b86353c1a..b57854879 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SendFriendMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/SendFriendMessage.java @@ -10,50 +10,78 @@ public final class SendFriendMessage extends Message { /** - * The username of the friend. + * The type Friend message component. */ - private final String username; + public static final class FriendMessageComponent { + /** + * The username of the friend. + */ + private final String username; - /** - * The world id the friend is in. - */ - private final int world; + /** + * The world id the friend is in. + */ + private final int world; - /** - * Creates a new send friend message. - * - * @param username The username of the friend. - * @param world The world the friend is in. - */ - public SendFriendMessage(String username, int world) { - this.username = username; - this.world = world; + /** + * Creates a new send friend message. + * + * @param username The username of the friend. + * @param world The world the friend is in. + */ + public FriendMessageComponent(String username, int world) { + this.username = username; + this.world = world; + } + + /** + * Gets the username of the friend. + * + * @return The username. + */ + public String getUsername() { + return username; + } + + /** + * Gets the world id the friend is in. + * + * @return The world id. + */ + public int getWorld() { + return world; + } + + /** + * Gets the encoded world id to be sent to the client. + * + * @return The encoded world id. + */ + public int getEncodedWorld() { + return world; + } } /** - * Gets the username of the friend. - * - * @return The username. + * The components that build the message. */ - public String getUsername() { - return username; - } + private final FriendMessageComponent[] components; /** - * Gets the world id the friend is in. + * Instantiates a new Send friend message. * - * @return The world id. + * @param components the components */ - public int getWorld() { - return world; + public SendFriendMessage(FriendMessageComponent... components) { + this.components = components; } /** - * Gets the encoded world id to be sent to the client. + * Get components friend message component [ ]. * - * @return The encoded world id. + * @return the friend message component [ ] */ - public int getEncodedWorld() { - return world == 0 ? 0 : world + 9; + public FriendMessageComponent[] getComponents() { + return components; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/SendTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/SendTileItemMessage.java deleted file mode 100644 index d8911a068..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/SendTileItemMessage.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.game.model.Item; -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client that adds an item to a tile. - * - * @author Major - */ -public final class SendTileItemMessage extends RegionUpdateMessage { - - /** - * The item to add to the tile. - */ - private final Item item; - - /** - * The position offset - */ - private final int positionOffset; - - /** - * Creates the SendTileItemMessage. - * - * @param item The item to add to the tile. - * @param positionOffset The offset from the 'base' position. - */ - public SendTileItemMessage(Item item, int positionOffset) { - this.item = item; - this.positionOffset = positionOffset; - } - - /** - * Gets the id of the item. - * - * @return The id. - */ - public int getId() { - return item.getId(); - } - - /** - * Gets the amount of the item. - * - * @return The amount. - */ - public int getAmount() { - return item.getAmount(); - } - - /** - * Gets the offset from the 'base' position. - * - * @return The offset. - */ - public int getPositionOffset() { - return positionOffset; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof SendTileItemMessage) { - SendTileItemMessage other = (SendTileItemMessage) obj; - return item.equals(other.item) && positionOffset == other.positionOffset; - } - - return false; - } - - @Override - public int hashCode() { - final int prime = 31; - return item.hashCode() * prime + positionOffset; - } - - @Override - public int priority() { - return LOW_PRIORITY; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/ServerChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/ServerChatMessage.java deleted file mode 100644 index ab8996021..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/ServerChatMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to display a server chat message. - * - * @author Graham - */ -public final class ServerChatMessage extends Message { - - /** - * The message to send. - */ - private final String message; - - /** - * Creates the ServerChatMessage. - * - * @param message The chat message to send. - */ - public ServerChatMessage(String message) { - this.message = message; - } - - /** - * Gets the chat message to send. - * - * @return The chat message. - */ - public String getMessage() { - return message; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/SetWidgetItemModelMessage.java b/game/src/main/java/org/apollo/game/message/impl/SetWidgetItemModelMessage.java deleted file mode 100644 index 58f344867..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/SetWidgetItemModelMessage.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to set a widget's displayed item model. - * - * @author Chris Fletcher - */ -public final class SetWidgetItemModelMessage extends Message { - - /** - * The interface's id. - */ - private final int interfaceId; - - /** - * The model's (item) id. - */ - private final int modelId; - - /** - * The zoom level. - */ - private final int zoom; - - /** - * Creates a new set interface item model message. - * - * @param interfaceId The interface's id. - * @param modelId The model's (item) id. - * @param zoom The zoom level. - */ - public SetWidgetItemModelMessage(int interfaceId, int modelId, int zoom) { - this.interfaceId = interfaceId; - this.modelId = modelId; - this.zoom = zoom; - } - - /** - * Gets the interface's id. - * - * @return The id. - */ - public int getInterfaceId() { - return interfaceId; - } - - /** - * Gets the model's (item) id. - * - * @return The id. - */ - public int getModelId() { - return modelId; - } - - /** - * Gets the zoom level. - * - * @return The zoom. - */ - public int getZoom() { - return zoom; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/SetWidgetNpcModelMessage.java b/game/src/main/java/org/apollo/game/message/impl/SetWidgetNpcModelMessage.java deleted file mode 100644 index 10c95fd69..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/SetWidgetNpcModelMessage.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to set a widget's displayed npc model. - * - * @author Chris Fletcher - */ -public final class SetWidgetNpcModelMessage extends Message { - - /** - * The interface's id. - */ - private final int interfaceId; - - /** - * The model's (NPC) id. - */ - private final int modelId; - - /** - * Creates a new set interface NPC model message. - * - * @param interfaceId The interface's id. - * @param modelId The model's (NPC) id. - */ - public SetWidgetNpcModelMessage(int interfaceId, int modelId) { - this.interfaceId = interfaceId; - this.modelId = modelId; - } - - /** - * Gets the interface's id. - * - * @return The id. - */ - public int getInterfaceId() { - return interfaceId; - } - - /** - * Gets the model's (NPC) id. - * - * @return The id. - */ - public int getModelId() { - return modelId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/SetWidgetPlayerModelMessage.java b/game/src/main/java/org/apollo/game/message/impl/SetWidgetPlayerModelMessage.java deleted file mode 100644 index a6a898419..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/SetWidgetPlayerModelMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent to the client to set a widget's displayed player model. - * - * @author Chris Fletcher - */ -public final class SetWidgetPlayerModelMessage extends Message { - - /** - * The interface's id. - */ - private final int interfaceId; - - /** - * Creates a new set interface player model message. - * - * @param interfaceId The interface's id. - */ - public SetWidgetPlayerModelMessage(int interfaceId) { - this.interfaceId = interfaceId; - } - - /** - * Gets the interface's id. - * - * @return The id. - */ - public int getInterfaceId() { - return interfaceId; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/TakeTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/TakeTileItemMessage.java deleted file mode 100644 index 5c3bdc139..000000000 --- a/game/src/main/java/org/apollo/game/message/impl/TakeTileItemMessage.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.apollo.game.message.impl; - -import org.apollo.game.model.Position; -import org.apollo.net.message.Message; - -/** - * A {@link Message} sent by the client to pick up an item on a tile. - * - * @author Major - */ -public final class TakeTileItemMessage extends Message { - - /** - * The id of the item. - */ - private final int id; - - /** - * The position of the tile. - */ - private final Position position; - - /** - * Creates a new take tile item message. - * - * @param id The id of the item. - * @param position The position of the tile. - */ - public TakeTileItemMessage(int id, Position position) { - this.id = id; - this.position = position; - } - - /** - * Gets the id of the item. - * - * @return The id. - */ - public int getId() { - return id; - } - - /** - * Gets the position of the tile. - * - * @return The position. - */ - public Position getPosition() { - return position; - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateIgnoreListMessage.java b/game/src/main/java/org/apollo/game/message/impl/UpdateIgnoreListMessage.java new file mode 100644 index 000000000..50c0a5f23 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/UpdateIgnoreListMessage.java @@ -0,0 +1,60 @@ +package org.apollo.game.message.impl; + +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent to the client that updates the ignored user list. + * + * @author Major + */ +public final class UpdateIgnoreListMessage extends Message { + + public static final class IgnoreMessageComponent { + /** + * The username of the ignored player. + */ + private final String username; + + /** + * Creates a new ignore player message. + * + * @param username The ignored player's username. + */ + public IgnoreMessageComponent(String username) { + this.username = username; + } + + /** + * Gets the username of the ignored player. + * + * @return The username. + */ + public String getUsername() { + return username; + } + + } + + /** + * The components that build the message. + */ + private final IgnoreMessageComponent[] components; + + /** + * Instantiates a new Send friend message. + * + * @param components the components + */ + public UpdateIgnoreListMessage(IgnoreMessageComponent... components) { + this.components = components; + } + + /** + * Get components friend message component [ ]. + * + * @return the friend message component [ ] + */ + public IgnoreMessageComponent[] getComponents() { + return components; + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/AddFriendMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/AddFriendMessage.java similarity index 93% rename from game/src/main/java/org/apollo/game/message/impl/AddFriendMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/AddFriendMessage.java index 7e968f28f..3a2df488a 100644 --- a/game/src/main/java/org/apollo/game/message/impl/AddFriendMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/AddFriendMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/AddIgnoreMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/AddIgnoreMessage.java similarity index 93% rename from game/src/main/java/org/apollo/game/message/impl/AddIgnoreMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/AddIgnoreMessage.java index b631e7fb4..30cdbf38a 100644 --- a/game/src/main/java/org/apollo/game/message/impl/AddIgnoreMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/AddIgnoreMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/ArrowKeyMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ArrowKeyMessage.java similarity index 94% rename from game/src/main/java/org/apollo/game/message/impl/ArrowKeyMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ArrowKeyMessage.java index f2f0f2ca0..01f37a175 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ArrowKeyMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ArrowKeyMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/ButtonMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ButtonMessage.java new file mode 100644 index 000000000..6e46e9746 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ButtonMessage.java @@ -0,0 +1,108 @@ +package org.apollo.game.message.impl.decode; + +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent by the client when a player clicks a button. + * + * @author Khaled Abdeljaber + */ +public class ButtonMessage extends Message { + + /** + * The option that was pressed. + */ + private final int option; + + /** + * The interface id. + */ + private final int interfaceId; + + /** + * The component id. + */ + private final int componentId; + + /** + * The slot of the item. + */ + private final int slot; + + /** + * The item id. + */ + private final int itemId; + + /** + * Instantiates a new If action message. + * + * @param option the action + * @param interfaceId the interface id + * @param componentId the component id + * @param slot the slot + * @param itemId the item id + */ + public ButtonMessage(int option, int interfaceId, int componentId, int slot, int itemId) { + this.option = option; + this.interfaceId = interfaceId; + this.componentId = componentId; + this.slot = slot; + this.itemId = itemId; + } + + /** + * Gets action. + * + * @return the action + */ + public int getOption() { + return option; + } + + /** + * Gets interface id. + * + * @return the interface id + */ + public int getInterfaceId() { + return interfaceId; + } + + /** + * Gets component id. + * + * @return the component id + */ + public int getComponentId() { + return componentId; + } + + /** + * Gets slot. + * + * @return the slot + */ + public int getSlot() { + return slot; + } + + /** + * Gets item id. + * + * @return the item id + */ + public int getItemId() { + return itemId; + } + + public int getId() { + return interfaceId << 16 | componentId; + } + + + @Override + public String toString() { + return "IfActionMessage{" + "action=" + option + ", interfaceId=" + interfaceId + ", componentId=" + componentId + ", slot=" + slot + ", itemId=" + itemId + '}'; + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/ChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ChatMessage.java similarity index 95% rename from game/src/main/java/org/apollo/game/message/impl/ChatMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ChatMessage.java index 7be4dd931..207f543e7 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ChatMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ChatMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/ClosedInterfaceMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ClosedInterfaceMessage.java similarity index 82% rename from game/src/main/java/org/apollo/game/message/impl/ClosedInterfaceMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ClosedInterfaceMessage.java index cc6ff1417..7975ea1df 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ClosedInterfaceMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ClosedInterfaceMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/CommandMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/CommandMessage.java similarity index 91% rename from game/src/main/java/org/apollo/game/message/impl/CommandMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/CommandMessage.java index 4149c015e..613f7ac5d 100644 --- a/game/src/main/java/org/apollo/game/message/impl/CommandMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/CommandMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/DisplayStatusMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/DisplayStatusMessage.java new file mode 100644 index 000000000..a704d4664 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/decode/DisplayStatusMessage.java @@ -0,0 +1,28 @@ +package org.apollo.game.message.impl.decode; + +import org.apollo.game.model.inter.DisplayMode; +import org.apollo.net.message.Message; + +public class DisplayStatusMessage extends Message { + + private final DisplayMode mode; + private final int height, width; + + public DisplayStatusMessage(DisplayMode mode, int height, int width) { + this.mode = mode; + this.height = height; + this.width = width; + } + + public DisplayMode getMode() { + return mode; + } + + public int getHeight() { + return height; + } + + public int getWidth() { + return width; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/FocusUpdateMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/FocusUpdateMessage.java similarity index 93% rename from game/src/main/java/org/apollo/game/message/impl/FocusUpdateMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/FocusUpdateMessage.java index 3dbe7544b..f75cff9e3 100644 --- a/game/src/main/java/org/apollo/game/message/impl/FocusUpdateMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/FocusUpdateMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/InventoryItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/InventoryItemMessage.java similarity index 66% rename from game/src/main/java/org/apollo/game/message/impl/InventoryItemMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/InventoryItemMessage.java index 9419c4c3a..004b946b0 100644 --- a/game/src/main/java/org/apollo/game/message/impl/InventoryItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/InventoryItemMessage.java @@ -1,6 +1,5 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; -import com.google.common.base.Preconditions; import org.apollo.net.message.Message; import java.util.NoSuchElementException; @@ -9,41 +8,47 @@ /** * A {@link Message} that represents some sort of action on an item in an inventory. * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ public abstract class InventoryItemMessage extends Message { /** * The item id. */ - private final int id; + protected final int id; /** * The interface id. */ - private final int interfaceId; + protected final int interfaceId; + + /** + * The component id. + */ + protected final int componentId; /** * The option number (1-5 if present). */ - private final OptionalInt option; + protected final OptionalInt option; /** * The item's slot. */ - private final int slot; + protected final int slot; /** * Creates the InventoryItemMessage. * - * @param option The option number, if applicable. + * @param option The option number, if applicable. * @param interfaceId The interface id. - * @param id The id. - * @param slot The slot. + * @param id The id. + * @param slot The slot. */ - protected InventoryItemMessage(OptionalInt option, int interfaceId, int id, int slot) { + protected InventoryItemMessage(OptionalInt option, int interfaceId, int componentId, int id, int slot) { this.option = option; this.interfaceId = interfaceId; + this.componentId = componentId; this.id = id; this.slot = slot; } @@ -66,6 +71,11 @@ public final int getInterfaceId() { return interfaceId; } + + public int getComponentId() { + return componentId; + } + /** * Gets the option number. * @@ -94,4 +104,9 @@ public final boolean hasOption() { return option.isPresent(); } + + @Override + public String toString() { + return "InventoryItemMessage{" + "id=" + id + ", interfaceId=" + interfaceId + ", componentId=" + componentId + ", option=" + option + ", slot=" + slot + '}'; + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/ItemOptionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ItemActionMessage.java similarity index 50% rename from game/src/main/java/org/apollo/game/message/impl/ItemOptionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ItemActionMessage.java index 370451f56..bcaed00ab 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ItemOptionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ItemActionMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import java.util.OptionalInt; @@ -7,9 +7,9 @@ * Note that the actual message sent by the client is one of the five item option messages, but this is the message that * should be intercepted (and the option verified). * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ -public final class ItemOptionMessage extends InventoryItemMessage { +public final class ItemActionMessage extends InventoryItemMessage { /** * Creates the ItemOptionMessage. @@ -19,8 +19,12 @@ public final class ItemOptionMessage extends InventoryItemMessage { * @param id The id. * @param slot The slot. */ - public ItemOptionMessage(int option, int interfaceId, int id, int slot) { - super(OptionalInt.of(option), interfaceId, id, slot); + public ItemActionMessage(int option, int interfaceId, int componentId, int id, int slot) { + super(OptionalInt.of(option), interfaceId, componentId, id, slot); } + @Override + public String toString() { + return "ItemActionMessage{" + "id=" + id + ", interfaceId=" + interfaceId + ", componentId=" + componentId + ", option=" + option + ", slot=" + slot + '}'; + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/ItemOnItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnItemMessage.java similarity index 72% rename from game/src/main/java/org/apollo/game/message/impl/ItemOnItemMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ItemOnItemMessage.java index 017b2e6ce..4314f1f89 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ItemOnItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnItemMessage.java @@ -1,11 +1,11 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import java.util.OptionalInt; /** * A {@link InventoryItemMessage} sent by the client when a player uses one inventory item on another. * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ public final class ItemOnItemMessage extends InventoryItemMessage { @@ -19,6 +19,11 @@ public final class ItemOnItemMessage extends InventoryItemMessage { */ private final int targetInterface; + /** + * The component id of the target item. + */ + private final int targetComponentId; + /** * The slot of the target item. */ @@ -34,9 +39,10 @@ public final class ItemOnItemMessage extends InventoryItemMessage { * @param targetId The id of the target item. * @param targetSlot The slot of the target item. */ - public ItemOnItemMessage(int usedInterface, int usedId, int usedSlot, int targetInterface, int targetId, int targetSlot) { - super(OptionalInt.empty(), usedInterface, usedId, usedSlot); + public ItemOnItemMessage(int usedInterface, int usedComponentId, int usedId, int usedSlot, int targetInterface, int targetComponentId, int targetId, int targetSlot) { + super(OptionalInt.empty(), usedInterface, usedComponentId, usedId, usedSlot); this.targetInterface = targetInterface; + this.targetComponentId = targetComponentId; this.targetSlot = targetSlot; this.targetId = targetId; } @@ -59,6 +65,10 @@ public int getTargetInterfaceId() { return targetInterface; } + public int getTargetComponentId() { + return targetComponentId; + } + /** * Gets the slot of the target item. * diff --git a/game/src/main/java/org/apollo/game/message/impl/ItemOnNpcMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnNpcMessage.java similarity index 97% rename from game/src/main/java/org/apollo/game/message/impl/ItemOnNpcMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ItemOnNpcMessage.java index 67e61827d..565a02c95 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ItemOnNpcMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnNpcMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/ItemOnObjectMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnObjectMessage.java similarity index 65% rename from game/src/main/java/org/apollo/game/message/impl/ItemOnObjectMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ItemOnObjectMessage.java index fabc2854e..62f00b3ea 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ItemOnObjectMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ItemOnObjectMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.game.model.Position; import org.apollo.net.message.Message; @@ -26,14 +26,14 @@ public final class ItemOnObjectMessage extends InventoryItemMessage { * Creates an item on object message. * * @param interfaceId The interface id. - * @param itemId The item id. - * @param itemSlot The slot the item is in. - * @param objectId The object id. - * @param x The x coordinate. - * @param y The y coordinate. + * @param itemId The item id. + * @param itemSlot The slot the item is in. + * @param objectId The object id. + * @param x The x coordinate. + * @param y The y coordinate. */ - public ItemOnObjectMessage(int interfaceId, int itemId, int itemSlot, int objectId, int x, int y) { - super(OptionalInt.empty(), interfaceId, itemId, itemSlot); + public ItemOnObjectMessage(int interfaceId, int componentId, int itemId, int itemSlot, int objectId, int x, int y) { + super(OptionalInt.empty(), interfaceId, componentId, itemId, itemSlot); this.objectId = objectId; position = new Position(x, y); } diff --git a/game/src/main/java/org/apollo/game/message/impl/KeepAliveMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/KeepAliveMessage.java similarity index 92% rename from game/src/main/java/org/apollo/game/message/impl/KeepAliveMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/KeepAliveMessage.java index 4a0af63f8..7af86975c 100644 --- a/game/src/main/java/org/apollo/game/message/impl/KeepAliveMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/KeepAliveMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/KeyboardEventMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/KeyboardEventMessage.java new file mode 100644 index 000000000..7e0194689 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/decode/KeyboardEventMessage.java @@ -0,0 +1,76 @@ +package org.apollo.game.message.impl.decode; + +import org.apollo.net.message.Message; + +import java.time.Duration; + +/** + * The type Event keyboard message. + * + * @author Khaled Abdeljaber + */ +public class KeyboardEventMessage extends Message { + + /** + * The event that occurs on a keyboard press. + */ + public static class KeyboardEvent { + /** + * The key pressed. + */ + private int key; + + /** + * The duration in milliseconds. + */ + private long duration; + + /** + * Instantiates a new Event keyboard. + * @param key the key + * @param duration the duration + */ + public KeyboardEvent(int key, Duration duration) { + this.key = key; + this.duration = duration.toMillis(); + } + + /** + * Gets key. + * + * @return the key + */ + public int getKey() { + return key; + } + + /** + * Gets duration. + * + * @return the duration + */ + public long getDuration() { + return duration; + } + } + + private final KeyboardEvent[] events; + + /** + * Instantiates a new Event keyboard message. + * + * @param events the events + */ + public KeyboardEventMessage(KeyboardEvent... events) { + this.events = events; + } + + /** + * Gets events. + * + * @return the events + */ + public KeyboardEvent[] getEvents() { + return events; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/MagicOnItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnItemMessage.java similarity index 66% rename from game/src/main/java/org/apollo/game/message/impl/MagicOnItemMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/MagicOnItemMessage.java index 521060901..9d45b0dc7 100644 --- a/game/src/main/java/org/apollo/game/message/impl/MagicOnItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnItemMessage.java @@ -1,11 +1,13 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; + +import org.apollo.game.message.impl.decode.InventoryItemMessage; import java.util.OptionalInt; /** * A {@link InventoryItemMessage} sent by the client when a player casts a spell on an inventory item. * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ public final class MagicOnItemMessage extends InventoryItemMessage { @@ -22,8 +24,8 @@ public final class MagicOnItemMessage extends InventoryItemMessage { * @param slot The item slot. * @param spell The spell id. */ - public MagicOnItemMessage(int interfaceId, int id, int slot, int spell) { - super(OptionalInt.empty(), interfaceId, id, slot); + public MagicOnItemMessage(int interfaceId, int componentId, int id, int slot, int spell) { + super(OptionalInt.empty(), interfaceId, componentId, id, slot); this.spell = spell; } diff --git a/game/src/main/java/org/apollo/game/message/impl/MagicOnMobMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnMobMessage.java similarity index 96% rename from game/src/main/java/org/apollo/game/message/impl/MagicOnMobMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/MagicOnMobMessage.java index fabdc16b8..44f86919d 100644 --- a/game/src/main/java/org/apollo/game/message/impl/MagicOnMobMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnMobMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import com.google.common.base.MoreObjects; import org.apollo.game.model.entity.EntityType; diff --git a/game/src/main/java/org/apollo/game/message/impl/MagicOnNpcMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnNpcMessage.java similarity index 90% rename from game/src/main/java/org/apollo/game/message/impl/MagicOnNpcMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/MagicOnNpcMessage.java index 09d6c607f..6491d995e 100644 --- a/game/src/main/java/org/apollo/game/message/impl/MagicOnNpcMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnNpcMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.game.model.entity.EntityType; diff --git a/game/src/main/java/org/apollo/game/message/impl/MagicOnPlayerMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnPlayerMessage.java similarity index 90% rename from game/src/main/java/org/apollo/game/message/impl/MagicOnPlayerMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/MagicOnPlayerMessage.java index c7fb0c58a..d21483ab5 100644 --- a/game/src/main/java/org/apollo/game/message/impl/MagicOnPlayerMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/MagicOnPlayerMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.game.model.entity.EntityType; diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/MapBuildCompleteMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/MapBuildCompleteMessage.java new file mode 100644 index 000000000..302042b57 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/decode/MapBuildCompleteMessage.java @@ -0,0 +1,9 @@ +package org.apollo.game.message.impl.decode; + +import org.apollo.net.message.Message; + +/** + * @author Khaled Abdeljaber + */ +public class MapBuildCompleteMessage extends Message { +} diff --git a/game/src/main/java/org/apollo/game/message/impl/MouseClickedMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/MouseClickedMessage.java similarity index 94% rename from game/src/main/java/org/apollo/game/message/impl/MouseClickedMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/MouseClickedMessage.java index 6636535fd..4e555604d 100644 --- a/game/src/main/java/org/apollo/game/message/impl/MouseClickedMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/MouseClickedMessage.java @@ -1,5 +1,6 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; +import org.apollo.game.message.impl.decode.FocusUpdateMessage; import org.apollo.net.message.Message; /** diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/MouseMoveEventMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/MouseMoveEventMessage.java new file mode 100644 index 000000000..856d1865a --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/decode/MouseMoveEventMessage.java @@ -0,0 +1,31 @@ +package org.apollo.game.message.impl.decode; + +import org.apollo.net.message.Message; + +/** + * @author Khaled Abdeljaber + */ +public class MouseMoveEventMessage extends Message { + + private final int x; + private final int y; + private final int dt; + + public MouseMoveEventMessage(int x, int y, int dt) { + this.x = x; + this.y = y; + this.dt = dt; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + public int getDt() { + return dt; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/NpcActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/NpcActionMessage.java similarity index 67% rename from game/src/main/java/org/apollo/game/message/impl/NpcActionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/NpcActionMessage.java index 0ab27b0f7..30cefa749 100644 --- a/game/src/main/java/org/apollo/game/message/impl/NpcActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/NpcActionMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; @@ -21,15 +21,22 @@ public final class NpcActionMessage extends Message { */ private final int index; + /** + * The movement type that the player performs. + */ + private final int movementType; + /** * Creates an npc action message. * - * @param option The option number. + * @param option The option number. * @param index The index of the npc. + * @param movementType The type of movement. */ - public NpcActionMessage(int option, int index) { + public NpcActionMessage(int option, int index, int movementType) { this.option = option; this.index = index; + this.movementType = movementType; } /** @@ -50,4 +57,13 @@ public int getIndex() { return index; } + /** + * Gets movement type. + * + * @return the movement type + */ + public int getMovementType() { + return movementType; + } + } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/ObjectActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ObjectActionMessage.java similarity index 80% rename from game/src/main/java/org/apollo/game/message/impl/ObjectActionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ObjectActionMessage.java index e408f2022..8da6ac0af 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ObjectActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ObjectActionMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.game.model.Position; import org.apollo.net.message.Message; @@ -28,6 +28,11 @@ public final class ObjectActionMessage extends Message { */ private final Position position; + /** + * The movement type that the player performs. + */ + private final int movementType; + /** * Creates a new object action message. * @@ -35,10 +40,11 @@ public final class ObjectActionMessage extends Message { * @param id The id of the object. * @param position The position of the object. */ - public ObjectActionMessage(int option, int id, Position position) { + public ObjectActionMessage(int option, int id, Position position, int movementType) { this.option = option; this.id = id; this.position = position; + this.movementType = movementType; } /** @@ -68,4 +74,12 @@ public Position getPosition() { return position; } + /** + * Gets movement type. + * + * @return the movement type + */ + public int getMovementType() { + return movementType; + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/decode/OpItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/OpItemMessage.java new file mode 100644 index 000000000..15eced808 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/decode/OpItemMessage.java @@ -0,0 +1,89 @@ +package org.apollo.game.message.impl.decode; + +import org.apollo.net.message.Message; + +/** + * The type Op item message. + */ +public class OpItemMessage extends Message { + + /** + * The option. + */ + private final int option; + /** + * The item id. + */ + private final int id; + /** + * The position of the item. + */ + private final int x, y; + + /** + * The movement type. + */ + private final int movementType; + + /** + * Instantiates a new option item message. + * + * @param id the item id + * @param x the x + * @param y the y + * @param movementType the movement type + */ + public OpItemMessage(int option, int id, int x, int y, int movementType) { + this.option = option; + this.id = id; + this.x = x; + this.y = y; + this.movementType = movementType; + } + + + /** + * Gets option. + * + * @return the option + */ + public int getOption() { + return option; + } + + /** + * Gets item. + * + * @return the item + */ + public int getId() { + return id; + } + + /** + * Gets x. + * + * @return the x + */ + public int getX() { + return x; + } + + /** + * Gets y. + * + * @return the y + */ + public int getY() { + return y; + } + + /** + * Is movement type. + * + * @return the type of movement. + */ + public int getMovementType() { + return movementType; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/PlayerActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/PlayerActionMessage.java similarity index 68% rename from game/src/main/java/org/apollo/game/message/impl/PlayerActionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/PlayerActionMessage.java index ee88bc834..93b988625 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PlayerActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/PlayerActionMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; @@ -12,25 +12,31 @@ */ public final class PlayerActionMessage extends Message { + /** + * The option number. + */ + private final int option; + /** * The index of the clicked player. */ private final int index; /** - * The option number. + * The movement type that the player performs. */ - private final int option; + private final int movementType; /** * Creates a player action message. - * - * @param option The option number. + * @param option The option number. * @param index The index of the player. + * @param movementType The type of movement. */ - public PlayerActionMessage(int option, int index) { + public PlayerActionMessage(int option, int index, int movementType) { this.option = option; this.index = index; + this.movementType = movementType; } /** @@ -42,6 +48,15 @@ public int getIndex() { return index; } + /** + * Gets movement type. + * + * @return the movement type + */ + public int getMovementType() { + return movementType; + } + /** * Gets the menu action number (i.e. the action message 'option') clicked. * diff --git a/game/src/main/java/org/apollo/game/message/impl/PlayerDesignMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/PlayerDesignMessage.java similarity index 93% rename from game/src/main/java/org/apollo/game/message/impl/PlayerDesignMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/PlayerDesignMessage.java index e3e34b3e5..5d0f90095 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PlayerDesignMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/PlayerDesignMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.game.model.Appearance; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/PrivacyOptionMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/PrivacyOptionMessage.java similarity index 56% rename from game/src/main/java/org/apollo/game/message/impl/PrivacyOptionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/PrivacyOptionMessage.java index 0a606664c..bcfd10d69 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PrivacyOptionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/PrivacyOptionMessage.java @@ -1,5 +1,6 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; +import org.apollo.game.message.impl.encode.ChatFilterSettingsMessage; import org.apollo.game.model.entity.setting.PrivacyState; import org.apollo.net.message.Message; @@ -10,22 +11,12 @@ * @author Kyle Stevenson * @author Major */ -public final class PrivacyOptionMessage extends Message { - - /** - * The privacy state of the player's chat. - */ - private final PrivacyState chatPrivacy; - - /** - * The privacy state of the player's friend chat. - */ - private final PrivacyState friendPrivacy; +public final class PrivacyOptionMessage extends ChatFilterSettingsMessage { /** * The privacy state of the player's trade chat. */ - private final PrivacyState tradePrivacy; + private final PrivacyState friendPrivacy; /** * Creates a privacy option message. @@ -35,18 +26,8 @@ public final class PrivacyOptionMessage extends Message { * @param tradePrivacy The privacy state of the player's trade chat. */ public PrivacyOptionMessage(int chatPrivacy, int friendPrivacy, int tradePrivacy) { - this.chatPrivacy = PrivacyState.valueOf(chatPrivacy, true); + super(chatPrivacy, tradePrivacy); this.friendPrivacy = PrivacyState.valueOf(friendPrivacy, false); - this.tradePrivacy = PrivacyState.valueOf(tradePrivacy, false); - } - - /** - * Gets the chat {@link PrivacyState}. - * - * @return The privacy state. - */ - public PrivacyState getChatPrivacy() { - return chatPrivacy; } /** @@ -58,13 +39,4 @@ public PrivacyState getFriendPrivacy() { return friendPrivacy; } - /** - * Gets the trade {@link PrivacyState}. - * - * @return The privacy state. - */ - public PrivacyState getTradePrivacy() { - return tradePrivacy; - } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/PublicChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/PublicChatMessage.java similarity index 51% rename from game/src/main/java/org/apollo/game/message/impl/PublicChatMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/PublicChatMessage.java index 7df576e9f..49515326e 100644 --- a/game/src/main/java/org/apollo/game/message/impl/PublicChatMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/PublicChatMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; @@ -9,6 +9,21 @@ */ public final class PublicChatMessage extends ChatMessage { + public enum PublicChatType { + NONE, QUICKCHAT, CLANCHAT; + + static final PublicChatType[] VALUES = values(); + + public static PublicChatType of(int ordinal) { + for (var value : VALUES) { + if (value.ordinal() == ordinal) { + return value; + } + } + return NONE; + } + } + /** * The text color. */ @@ -19,18 +34,25 @@ public final class PublicChatMessage extends ChatMessage { */ private final int effects; + /** + * The type of public chat. + */ + private final PublicChatType type; + /** * Creates a new chat message. * - * @param message The message. + * @param message The message. * @param compressedMessage The compressed message. - * @param color The text color. - * @param effects The text effects. + * @param color The text color. + * @param effects The text effects. + * @param type The chat type. */ - public PublicChatMessage(String message, byte[] compressedMessage, int color, int effects) { + public PublicChatMessage(String message, byte[] compressedMessage, int color, int effects, PublicChatType type) { super(message, compressedMessage); this.color = color; this.effects = effects; + this.type = type; } /** @@ -51,4 +73,12 @@ public int getTextEffects() { return effects; } + /** + * Gets the chat type. + * + * @return the type of public chat. + */ + public PublicChatType getType() { + return type; + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/RemoveFriendMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/RemoveFriendMessage.java similarity index 93% rename from game/src/main/java/org/apollo/game/message/impl/RemoveFriendMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/RemoveFriendMessage.java index b44b42fee..94ca060b2 100644 --- a/game/src/main/java/org/apollo/game/message/impl/RemoveFriendMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/RemoveFriendMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/RemoveIgnoreMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/RemoveIgnoreMessage.java similarity index 93% rename from game/src/main/java/org/apollo/game/message/impl/RemoveIgnoreMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/RemoveIgnoreMessage.java index 664826028..a8acc5d24 100644 --- a/game/src/main/java/org/apollo/game/message/impl/RemoveIgnoreMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/RemoveIgnoreMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/ReportAbuseMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/ReportAbuseMessage.java similarity index 96% rename from game/src/main/java/org/apollo/game/message/impl/ReportAbuseMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/ReportAbuseMessage.java index 03e877c46..f56c11bf2 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ReportAbuseMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/ReportAbuseMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/SpamPacketMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/SpamPacketMessage.java similarity index 92% rename from game/src/main/java/org/apollo/game/message/impl/SpamPacketMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/SpamPacketMessage.java index e554f4000..1514ee5dc 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SpamPacketMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/SpamPacketMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/WalkMessage.java b/game/src/main/java/org/apollo/game/message/impl/decode/WalkMessage.java similarity index 63% rename from game/src/main/java/org/apollo/game/message/impl/WalkMessage.java rename to game/src/main/java/org/apollo/game/message/impl/decode/WalkMessage.java index 88e84f7eb..206ee156a 100644 --- a/game/src/main/java/org/apollo/game/message/impl/WalkMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/decode/WalkMessage.java @@ -1,10 +1,9 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.decode; +import com.google.common.base.Preconditions; import org.apollo.game.model.Position; import org.apollo.net.message.Message; -import com.google.common.base.Preconditions; - /** * A {@link Message} sent by the client to request that the player walks somewhere. * @@ -20,27 +19,38 @@ public final class WalkMessage extends Message { /** * The steps. */ - private final Position[] steps; + private int x, y; /** * Creates the message. * - * @param steps The steps array. + * @param x The absolute x-axis position. + * @param y The absolute y-axis position. * @param run The run flag. */ - public WalkMessage(Position[] steps, boolean run) { - Preconditions.checkArgument(steps.length >= 0, "Number of steps cannot be negative."); - this.steps = steps; + public WalkMessage(int x, int y, boolean run) { + this.x = x; + this.y = y; this.run = run; } + + /** + * Gets x. + * + * @return the x + */ + public int getX() { + return x; + } + /** - * Gets the steps array. + * Gets y. * - * @return An array of steps. + * @return the y */ - public Position[] getSteps() { - return steps; + public int getY() { + return y; } /** diff --git a/game/src/main/java/org/apollo/game/message/impl/SendObjectMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/AddObjectMessage.java similarity index 85% rename from game/src/main/java/org/apollo/game/message/impl/SendObjectMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/AddObjectMessage.java index bd9dc8a5b..9ab0d958f 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SendObjectMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/AddObjectMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.entity.obj.GameObject; import org.apollo.net.message.Message; @@ -8,7 +8,7 @@ * * @author Major */ -public final class SendObjectMessage extends RegionUpdateMessage { +public final class AddObjectMessage extends RegionUpdateMessage { /** * The id of the object. @@ -36,7 +36,7 @@ public final class SendObjectMessage extends RegionUpdateMessage { * @param object The {@link GameObject} to send. * @param positionOffset The offset of the object's position from the region's central position. */ - public SendObjectMessage(GameObject object, int positionOffset) { + public AddObjectMessage(GameObject object, int positionOffset) { id = object.getId(); this.positionOffset = positionOffset; type = object.getType(); @@ -45,8 +45,8 @@ public SendObjectMessage(GameObject object, int positionOffset) { @Override public boolean equals(Object obj) { - if (obj instanceof SendObjectMessage) { - SendObjectMessage other = (SendObjectMessage) obj; + if (obj instanceof AddObjectMessage) { + AddObjectMessage other = (AddObjectMessage) obj; if (id != other.id || type != other.type) { return false; } @@ -103,7 +103,7 @@ public int hashCode() { @Override public int priority() { - return LOW_PRIORITY; + return 9; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/SendPublicTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/AddTileItemMessage.java similarity index 82% rename from game/src/main/java/org/apollo/game/message/impl/SendPublicTileItemMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/AddTileItemMessage.java index da6c20a3d..f5bf47204 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SendPublicTileItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/AddTileItemMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.Item; import org.apollo.net.message.Message; @@ -8,7 +8,7 @@ * * @author Major */ -public final class SendPublicTileItemMessage extends RegionUpdateMessage { +public final class AddTileItemMessage extends RegionUpdateMessage { /** * The index of the player who dropped the item. @@ -32,7 +32,7 @@ public final class SendPublicTileItemMessage extends RegionUpdateMessage { * @param index The index of the player who dropped the item. * @param positionOffset The offset from the 'base' position. */ - public SendPublicTileItemMessage(Item item, int index, int positionOffset) { + public AddTileItemMessage(Item item, int index, int positionOffset) { this.item = item; this.index = index; this.positionOffset = positionOffset; @@ -40,8 +40,8 @@ public SendPublicTileItemMessage(Item item, int index, int positionOffset) { @Override public boolean equals(Object obj) { - if (obj instanceof SendPublicTileItemMessage) { - SendPublicTileItemMessage other = (SendPublicTileItemMessage) obj; + if (obj instanceof AddTileItemMessage) { + AddTileItemMessage other = (AddTileItemMessage) obj; return item.equals(other.item) && index == other.index && positionOffset == other.positionOffset; } @@ -93,7 +93,7 @@ public int hashCode() { @Override public int priority() { - return LOW_PRIORITY; + return 8; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/AreaSoundMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/AreaSoundMessage.java new file mode 100644 index 000000000..42a15f6a0 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/AreaSoundMessage.java @@ -0,0 +1,70 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.game.model.entity.AreaSound; + +import java.util.Objects; + +/** + * The type Area sound message. + * + * @author Khaled Abdeljaber + */ +public class AreaSoundMessage extends RegionUpdateMessage { + + /** + * The sound. + */ + private final AreaSound sound; + + /** + * The position offset. + */ + private final int positionOffset; + + /** + * Instantiates a new Area sound message. + * + * @param sound the sound + * @param positionOffset the position offset + */ + public AreaSoundMessage(AreaSound sound, int positionOffset) { + this.sound = sound; + this.positionOffset = positionOffset; + } + + /** + * Gets sound. + * + * @return the sound + */ + public AreaSound getSound() { + return sound; + } + + /** + * Gets position offset. + * + * @return the position offset + */ + public int getPositionOffset() { + return positionOffset; + } + + @Override + public int priority() { + return 5; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + AreaSoundMessage that = (AreaSoundMessage) o; + return positionOffset == that.positionOffset && sound.equals(that.sound); + } + + @Override + public int hashCode() { + return Objects.hash(sound, positionOffset); + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/ChatFilterSettingsMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/ChatFilterSettingsMessage.java new file mode 100644 index 000000000..964307015 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/ChatFilterSettingsMessage.java @@ -0,0 +1,60 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.game.model.entity.setting.PrivacyState; +import org.apollo.net.message.Message; + +/** + * @author Khaled Abdeljaber + */ +public class ChatFilterSettingsMessage extends Message { + + /** + * The privacy state of the player's chat. + */ + private final PrivacyState chatPrivacy; + + /** + * The privacy state of the player's friend chat. + */ + private final PrivacyState tradePrivacy; + + /** + * Creates a privacy option message. + * + * @param chatPrivacy The privacy state of the player's chat. + * @param tradePrivacy The privacy state of the player's trade chat. + */ + public ChatFilterSettingsMessage(int chatPrivacy, int tradePrivacy) { + this.chatPrivacy = PrivacyState.valueOf(chatPrivacy, true); + this.tradePrivacy = PrivacyState.valueOf(tradePrivacy, false); + } + + /** + * Creates a privacy option message. + * + * @param chatPrivacy The privacy state of the player's chat. + * @param tradePrivacy The privacy state of the player's trade chat. + */ + public ChatFilterSettingsMessage(PrivacyState chatPrivacy, PrivacyState tradePrivacy) { + this.chatPrivacy = chatPrivacy; + this.tradePrivacy = tradePrivacy; + } + + /** + * Gets the chat {@link PrivacyState}. + * + * @return The privacy state. + */ + public PrivacyState getChatPrivacy() { + return chatPrivacy; + } + + /** + * Gets the trade {@link PrivacyState}. + * + * @return The privacy state. + */ + public PrivacyState getTradePrivacy() { + return tradePrivacy; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/CloseInterfaceMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/CloseInterfaceMessage.java similarity index 81% rename from game/src/main/java/org/apollo/game/message/impl/CloseInterfaceMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/CloseInterfaceMessage.java index ee0a31a0e..1c7419e86 100644 --- a/game/src/main/java/org/apollo/game/message/impl/CloseInterfaceMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/CloseInterfaceMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/ConfigMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/ConfigMessage.java similarity index 90% rename from game/src/main/java/org/apollo/game/message/impl/ConfigMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/ConfigMessage.java index 5d9a4209c..bae719eac 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ConfigMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/ConfigMessage.java @@ -1,11 +1,11 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; /** * A {@link Message} sent to the client to adjust a certain config or attribute setting. * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ public final class ConfigMessage extends Message { diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/FriendListUnlockMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/FriendListUnlockMessage.java new file mode 100644 index 000000000..d0f03d6f6 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/FriendListUnlockMessage.java @@ -0,0 +1,10 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * @author Khaled Abdeljaber + */ +public class FriendListUnlockMessage extends Message { + +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfClearItemsMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfClearItemsMessage.java new file mode 100644 index 000000000..1dfae19af --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfClearItemsMessage.java @@ -0,0 +1,35 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent to the client to set a widget's displayed item model. + * + * @author Khaled Abdeljaber + */ +public final class IfClearItemsMessage extends Message { + + /** + * The interface's id. + */ + private final int packedInterface; + + /** + * Creates a new set interface item model message. + * + * @param interfaceId The interface's id. + * @param componentId The component id. + */ + public IfClearItemsMessage(int interfaceId, int componentId) { + this.packedInterface = interfaceId << 16 | componentId; + } + + /** + * Gets the interface's id. + * + * @return The id. + */ + public int getPackedInterface() { + return packedInterface; + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfMoveSubMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfMoveSubMessage.java new file mode 100644 index 000000000..474ade619 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfMoveSubMessage.java @@ -0,0 +1,22 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +public class IfMoveSubMessage extends Message { + + private final int fromPackedInterface; + private final int toPackedInterface; + + public IfMoveSubMessage(int fromPackedInterface, int toPackedInterface) { + this.fromPackedInterface = fromPackedInterface; + this.toPackedInterface = toPackedInterface; + } + + public int getFromPackedInterface() { + return fromPackedInterface; + } + + public int getToPackedInterface() { + return toPackedInterface; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenSubMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenSubMessage.java new file mode 100644 index 000000000..090a0474b --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenSubMessage.java @@ -0,0 +1,67 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.game.model.inter.ClientInterfaceType; +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent to the client that opens an interface. + * + * @author Graham + */ +public final class IfOpenSubMessage extends Message { + + /** + * The parent interface. + */ + private final int packedParentInterface; + + /** + * The type of the interface. + */ + private final ClientInterfaceType type; + + /** + * The interface id. + */ + private final int id; + + /** + * Creates the message with the specified interface id. + * + * @param packedParentInterface the parent component + * @param type the type + * @param id the id + */ + public IfOpenSubMessage(int packedParentInterface, ClientInterfaceType type, int id) { + this.packedParentInterface = packedParentInterface; + this.type = type; + this.id = id; + } + + /** + * Gets the interface id. + * + * @return The interface id. + */ + public int getId() { + return id; + } + + /** + * Gets parent component. + * + * @return the parent component + */ + public int getPackedParentInterface() { + return packedParentInterface; + } + + /** + * Gets type. + * + * @return the type + */ + public ClientInterfaceType getType() { + return type; + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenTopMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenTopMessage.java new file mode 100644 index 000000000..aa6e5bb59 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfOpenTopMessage.java @@ -0,0 +1,26 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +public class IfOpenTopMessage extends Message { + + private final int id; + + /** + * Instantiates a new If open top message. + * + * @param id the interface id + */ + public IfOpenTopMessage(int id) { + this.id = id; + } + + /** + * Gets interface id. + * + * @return the interface id. + */ + public int getId() { + return id; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetAngleMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetAngleMessage.java new file mode 100644 index 000000000..96bc0539f --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetAngleMessage.java @@ -0,0 +1,83 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * The type If set angle message. + * + * @author Khaled Abdeljaber + */ +public class IfSetAngleMessage extends Message { + + /** + * The packed interface. + */ + private final int packedInterface; + + /** + * The zoom. + */ + private final int zoom; + + /** + * The rotation in the x axis. + */ + private final int rotationX; + + /** + * The rotation in the y axis. + */ + private final int rotationY; + + /** + * Instantiates a new If set angle message. + * + * @param interfaceId the interface id + * @param componentId the component id + * @param zoom the zoom. + * @param rotationX the rotationX + * @param rotationY the rotationY + */ + public IfSetAngleMessage(int interfaceId, int componentId, int zoom, int rotationX, int rotationY) { + this.packedInterface = interfaceId << 16 | componentId; + this.zoom = zoom; + this.rotationX = rotationX; + this.rotationY = rotationY; + } + + /** + * Gets packed interface. + * + * @return the packed interface + */ + public int getPackedInterface() { + return packedInterface; + } + + /** + * Gets zoom. + * + * @return the zoom + */ + public int getZoom() { + return zoom; + } + + /** + * Gets rotation x. + * + * @return the rotation x + */ + public int getRotationX() { + return rotationX; + } + + /** + * Gets rotation y. + * + * @return the rotation y + */ + public int getRotationY() { + return rotationY; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/SetWidgetModelAnimationMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetAnimMessage.java similarity index 59% rename from game/src/main/java/org/apollo/game/message/impl/SetWidgetModelAnimationMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/IfSetAnimMessage.java index b8a104b46..4a3edf830 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SetWidgetModelAnimationMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetAnimMessage.java @@ -1,13 +1,13 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; /** * A {@link Message} sent to the client to set a widget's displayed mob's animation. * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ -public final class SetWidgetModelAnimationMessage extends Message { +public final class IfSetAnimMessage extends Message { /** * The model's animation id. @@ -17,16 +17,16 @@ public final class SetWidgetModelAnimationMessage extends Message { /** * The interface id. */ - private final int interfaceId; + private final int packedInterface; /** * Creates a new set interface npc model's animation message. * - * @param interfaceId The interface id. + * @param packedInterface The interface id. * @param animation The model's animation id. */ - public SetWidgetModelAnimationMessage(int interfaceId, int animation) { - this.interfaceId = interfaceId; + public IfSetAnimMessage(int packedInterface, int componentId, int animation) { + this.packedInterface = packedInterface << 16 | componentId; this.animation = animation; } @@ -44,8 +44,8 @@ public int getAnimation() { * * @return The interface id. */ - public int getInterfaceId() { - return interfaceId; + public int getPackedInterface() { + return packedInterface; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetColourMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetColourMessage.java new file mode 100644 index 000000000..665d34193 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetColourMessage.java @@ -0,0 +1,65 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * The type If set angle message. + * + * @author Khaled Abdeljaber + */ +public class IfSetColourMessage extends Message { + + /** + * The packed interface. + */ + private final int packedInterface; + + /** + * The packed colors. + */ + private final int packedColours; + + /** + * Instantiates a new If set colour message. + * + * @param interfaceId the interface id + * @param componentId the component id + * @param packedColours the packed colours + */ + public IfSetColourMessage(int interfaceId, int componentId, int packedColours) { + this.packedInterface = interfaceId << 16 | componentId; + this.packedColours = packedColours; + } + + /** + * Instantiates a new If set colour message. + * + * @param interfaceId the interface id + * @param componentId the component id + * @param red the red + * @param green the green + * @param blue the blue + */ + public IfSetColourMessage(int interfaceId, int componentId, int red, int green, int blue) { + this.packedInterface = interfaceId << 16 | componentId; + this.packedColours = red << 10 | green << 5 | blue; + } + + /** + * Gets packed interface. + * + * @return the packed interface + */ + public int getPackedInterface() { + return packedInterface; + } + + /** + * Gets packed colours. + * + * @return the packed colours + */ + public int getPackedColours() { + return packedColours; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetEventMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetEventMessage.java new file mode 100644 index 000000000..f891d38d5 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetEventMessage.java @@ -0,0 +1,35 @@ +package org.apollo.game.message.impl.encode; + +import kotlin.ranges.IntRange; +import org.apollo.game.model.inter.InterfaceEvent; +import org.apollo.net.message.Message; + +import java.util.EnumSet; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetEventMessage extends Message { + + private final int packedInterface; + private final IntRange range; + private final EnumSet events; + + public IfSetEventMessage(int packedInterface, IntRange range, EnumSet events) { + this.packedInterface = packedInterface; + this.range = range; + this.events = events; + } + + public int getPackedInterface() { + return packedInterface; + } + + public IntRange getRange() { + return range; + } + + public EnumSet getEvents() { + return events; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/SetWidgetVisibilityMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetHideMessage.java similarity index 50% rename from game/src/main/java/org/apollo/game/message/impl/SetWidgetVisibilityMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/IfSetHideMessage.java index 361c79489..332bcffb9 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SetWidgetVisibilityMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetHideMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; @@ -6,14 +6,14 @@ * A {@link Message} sent to the client that changes the state of a hidden widget component (e.g. the special attack bar * on the weapon tab). * - * @author Chris Fletcher + * @author Khaled Abdeljaber */ -public final class SetWidgetVisibilityMessage extends Message { +public final class IfSetHideMessage extends Message { /** * The component id. */ - private final int component; + private final int packedInterface; /** * Visible flag. @@ -23,21 +23,22 @@ public final class SetWidgetVisibilityMessage extends Message { /** * Creates the interface component state message. * - * @param component The compononent id. - * @param visible The flag for showing or hiding the component. + * @param interfaceId The interface id. + * @param componentId The compononent id. + * @param visible The flag for showing or hiding the component. */ - public SetWidgetVisibilityMessage(int component, boolean visible) { - this.component = component; + public IfSetHideMessage(int interfaceId, int componentId, boolean visible) { + this.packedInterface = interfaceId << 16 | componentId; this.visible = visible; } /** - * Gets the id of the interface component. + * Gets the packed interface. * - * @return The component id. + * @return The packed interface. */ - public int getWidgetId() { - return component; + public int getPackedInterface() { + return packedInterface; } /** diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetItemMessage.java new file mode 100644 index 000000000..b51d912b1 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetItemMessage.java @@ -0,0 +1,68 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent to the client to set a widget's displayed item model. + * + * @author Khaled Abdeljaber + */ +public final class IfSetItemMessage extends Message { + + /** + * The interface's id. + */ + private final int packedInterface; + + /** + * The item id. + */ + private final int item; + + /** + * The zoom level. + */ + private final int amount; + + /** + * Creates a new set interface item model message. + * + * @param interfaceId The interface's id. + * @param componentId The component id. + * @param item The model's (item) id. + * @param amount The zoom level. + */ + public IfSetItemMessage(int interfaceId, int componentId, int item, int amount) { + this.packedInterface = interfaceId << 16 | componentId; + this.item = item; + this.amount = amount; + } + + /** + * Gets the interface's id. + * + * @return The id. + */ + public int getPackedInterface() { + return packedInterface; + } + + /** + * Gets the model's (item) id. + * + * @return The id. + */ + public int getItem() { + return item; + } + + /** + * Gets the zoom level. + * + * @return The zoom. + */ + public int getAmount() { + return amount; + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/SetWidgetModelMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelMessage.java similarity index 58% rename from game/src/main/java/org/apollo/game/message/impl/SetWidgetModelMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelMessage.java index f343a8651..249e15569 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SetWidgetModelMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; @@ -7,7 +7,7 @@ * * @author Major */ -public final class SetWidgetModelMessage extends Message { +public final class IfSetModelMessage extends Message { /** * The model id. @@ -17,16 +17,16 @@ public final class SetWidgetModelMessage extends Message { /** * The interface id. */ - private final int interfaceId; + private final int packedInterface; /** * Creates a new SetWidgetModelMessage. * - * @param interfaceId The interface id. + * @param packedInterface The interface id. * @param model The model id. */ - public SetWidgetModelMessage(int interfaceId, int model) { - this.interfaceId = interfaceId; + public IfSetModelMessage(int packedInterface, int componentId, int model) { + this.packedInterface = packedInterface << 16 | componentId; this.model = model; } @@ -44,8 +44,8 @@ public int getModel() { * * @return The interface id. */ - public int getInterfaceId() { - return interfaceId; + public int getPackedInterface() { + return packedInterface; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelRotateMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelRotateMessage.java new file mode 100644 index 000000000..96f6abe5f --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetModelRotateMessage.java @@ -0,0 +1,67 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * The type If set model rotate message. + * + * @author Khaled Abdeljaber + */ +public class IfSetModelRotateMessage extends Message { + + /** + * The packed interface. + */ + private final int packedInterface; + + /** + * The rotation in the x-axis. + */ + private final int rotationX; + + /** + * The rotation in the y-axis. + */ + private final int rotationY; + + /** + * Instantiates a new If set model rotate message. + * + * @param interfaceId the interface id + * @param componentId the component id + * @param rotationX the rotation x + * @param rotationY the rotation y + */ + public IfSetModelRotateMessage(int interfaceId, int componentId, int rotationX, int rotationY) { + this.packedInterface = interfaceId << 16 | componentId; + this.rotationX = rotationX; + this.rotationY = rotationY; + } + + /** + * Gets packed interface. + * + * @return the packed interface + */ + public int getPackedInterface() { + return packedInterface; + } + + /** + * Gets rotation x. + * + * @return the rotation x + */ + public int getRotationX() { + return rotationX; + } + + /** + * Gets rotation y. + * + * @return the rotation y + */ + public int getRotationY() { + return rotationY; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetNpcHeadMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetNpcHeadMessage.java new file mode 100644 index 000000000..aebfddb4e --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetNpcHeadMessage.java @@ -0,0 +1,52 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent to the client to set a widget's displayed npc model. + * + * @author Khaled Abdeljaber + */ +public final class IfSetNpcHeadMessage extends Message { + + /** + * The interface's id. + */ + private final int packedInterface; + + /** + * The model's (NPC) id. + */ + private final int npcId; + + /** + * Creates a new set interface NPC model message. + * + * @param interfaceId The interface's id. + * @param componentId The component id. + * @param npcId The model's (NPC) id. + */ + public IfSetNpcHeadMessage(int interfaceId, int componentId, int npcId) { + this.packedInterface = interfaceId << 16 | componentId; + this.npcId = npcId; + } + + /** + * Gets the interface's id. + * + * @return The id. + */ + public int getPackedInterface() { + return packedInterface; + } + + /** + * Gets the model's (NPC) id. + * + * @return The id. + */ + public int getNpcId() { + return npcId; + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetPlayerHeadMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetPlayerHeadMessage.java new file mode 100644 index 000000000..cc5b08080 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetPlayerHeadMessage.java @@ -0,0 +1,36 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent to the client to set a widget's displayed player model. + * + * @author Khaled Abdeljaber + */ +public final class IfSetPlayerHeadMessage extends Message { + + /** + * The packed interface. + */ + private final int packedInterface; + + /** + * Creates a new set interface player model message. + * + * @param interfaceId The interface's id. + * @param componentId The component id. + */ + public IfSetPlayerHeadMessage(int interfaceId, int componentId) { + this.packedInterface = interfaceId << 16 | componentId; + } + + /** + * Gets the interface's id. + * + * @return The id. + */ + public int getPackedInterface() { + return packedInterface; + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetPositionMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetPositionMessage.java new file mode 100644 index 000000000..847f131a8 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetPositionMessage.java @@ -0,0 +1,55 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * The type If set position message. + * + * @author Khaled Abdeljaber + */ +public class IfSetPositionMessage extends Message { + + private final int packedInterface; + private final int x, y; + + /** + * Instantiates a new If set position message. + * + * @param interfaceId the interface id + * @param componentId the component id + * @param x the x + * @param y the y + */ + public IfSetPositionMessage(int interfaceId, int componentId, int x, int y) { + this.packedInterface = interfaceId << 16 | componentId; + this.x = x; + this.y = y; + } + + /** + * Gets packed interface. + * + * @return the packed interface + */ + public int getPackedInterface() { + return packedInterface; + } + + /** + * Gets x. + * + * @return the x + */ + public int getX() { + return x; + } + + /** + * Gets y. + * + * @return the y + */ + public int getY() { + return y; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/IfSetScrollPosMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetScrollPosMessage.java new file mode 100644 index 000000000..7672b56e9 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetScrollPosMessage.java @@ -0,0 +1,44 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * The type If set scroll pos message. + * + * @author Khaled Abdeljaber + */ +public class IfSetScrollPosMessage extends Message { + + private final int packedInterface; + private final int scrollPosition; + + /** + * Instantiates a new If set scroll pos message. + * + * @param interfaceId the interface id + * @param componentId the component id + * @param scrollPosition the scroll position + */ + public IfSetScrollPosMessage(int interfaceId, int componentId, int scrollPosition) { + this.packedInterface = interfaceId << 16 | componentId; + this.scrollPosition = scrollPosition; + } + + /** + * Gets interface packed. + * + * @return the interface packed + */ + public int getPackedInterface() { + return packedInterface; + } + + /** + * Gets scroll position. + * + * @return the scroll position + */ + public int getScrollPosition() { + return scrollPosition; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/SetWidgetTextMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetTextMessage.java similarity index 57% rename from game/src/main/java/org/apollo/game/message/impl/SetWidgetTextMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/IfSetTextMessage.java index 5c407103f..c5a18e483 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SetWidgetTextMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/IfSetTextMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; @@ -7,12 +7,12 @@ * * @author Graham */ -public final class SetWidgetTextMessage extends Message { +public final class IfSetTextMessage extends Message { /** * The interface's id. */ - private final int interfaceId; + private final int packedInterface; /** * The text. @@ -23,10 +23,11 @@ public final class SetWidgetTextMessage extends Message { * Creates the set interface text message. * * @param interfaceId The interface's id. - * @param text The interface's text. + * @param componentId The component id. + * @param text The interface's text. */ - public SetWidgetTextMessage(int interfaceId, String text) { - this.interfaceId = interfaceId; + public IfSetTextMessage(int interfaceId, int componentId, String text) { + this.packedInterface = interfaceId << 16 | componentId; this.text = text; } @@ -35,8 +36,8 @@ public SetWidgetTextMessage(int interfaceId, String text) { * * @return The interface id. */ - public int getInterfaceId() { - return interfaceId; + public int getPackedInterface() { + return packedInterface; } /** diff --git a/game/src/main/java/org/apollo/game/message/impl/LogoutMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/LogoutMessage.java similarity index 80% rename from game/src/main/java/org/apollo/game/message/impl/LogoutMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/LogoutMessage.java index b153fcf4e..fa53f013c 100644 --- a/game/src/main/java/org/apollo/game/message/impl/LogoutMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/LogoutMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/MessagePrivateEchoMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/MessagePrivateEchoMessage.java new file mode 100644 index 000000000..798ec767d --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/MessagePrivateEchoMessage.java @@ -0,0 +1,50 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * The type Message private message. + * + * @author Khaled Abdeljaber + */ +public class MessagePrivateEchoMessage extends Message { + + /** + * The username of the player sending the message. + */ + private final String username; + + /** + * The message. + */ + private final byte[] message; + + /** + * Creates a new forward private message message. + * + * @param username The username of the player sending the message. + * @param message The compressed message. + */ + public MessagePrivateEchoMessage(String username, byte[] message) { + this.username = username; + this.message = message; + } + + /** + * Gets username. + * + * @return the username + */ + public String getUsername() { + return username; + } + + /** + * Get message byte [ ]. + * + * @return the byte [ ] + */ + public byte[] getMessage() { + return message; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/MobAnimationResetMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/MobResetAnimsMessage.java similarity index 59% rename from game/src/main/java/org/apollo/game/message/impl/MobAnimationResetMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/MobResetAnimsMessage.java index 4bb1a74ba..e8cc6047e 100644 --- a/game/src/main/java/org/apollo/game/message/impl/MobAnimationResetMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/MobResetAnimsMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; @@ -7,6 +7,6 @@ * * @author Major */ -public final class MobAnimationResetMessage extends Message { +public final class MobResetAnimsMessage extends Message { } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/NpcSynchronizationMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/NpcSynchronizationMessage.java similarity index 78% rename from game/src/main/java/org/apollo/game/message/impl/NpcSynchronizationMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/NpcSynchronizationMessage.java index cfb7c7f79..f9e9cf618 100644 --- a/game/src/main/java/org/apollo/game/message/impl/NpcSynchronizationMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/NpcSynchronizationMessage.java @@ -1,12 +1,12 @@ -package org.apollo.game.message.impl; - -import java.util.List; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.Position; import org.apollo.game.model.entity.Npc; import org.apollo.game.sync.seg.SynchronizationSegment; import org.apollo.net.message.Message; +import java.util.List; + /** * A {@link Message} sent to the client to synchronize npcs with players. * @@ -29,6 +29,11 @@ public final class NpcSynchronizationMessage extends Message { */ private final List segments; + /** + * If the player has an extended viewport. + */ + private final boolean extendedView; + /** * Creates a new {@link NpcSynchronizationMessage}. * @@ -36,10 +41,11 @@ public final class NpcSynchronizationMessage extends Message { * @param segments The list of segments. * @param localNpcs The amount of local npcs. */ - public NpcSynchronizationMessage(Position position, List segments, int localNpcs) { + public NpcSynchronizationMessage(Position position, List segments, int localNpcs, boolean extendedView) { this.position = position; this.segments = segments; this.localNpcs = localNpcs; + this.extendedView = extendedView; } /** @@ -69,4 +75,13 @@ public List getSegments() { return segments; } + + /** + * Is view extended boolean. + * + * @return the boolean + */ + public boolean isViewExtended() { + return extendedView; + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/ObjectAnimationMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/ObjectAnimationMessage.java new file mode 100644 index 000000000..277fed83f --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/ObjectAnimationMessage.java @@ -0,0 +1,74 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.game.model.Animation; +import org.apollo.game.model.entity.obj.GameObject; +import org.apollo.game.model.entity.obj.ObjectAnimation; + +import java.util.Objects; + +/** + * The type Object animation message. + * + * @author Khaled Abdeljaber + */ +public class ObjectAnimationMessage extends RegionUpdateMessage { + + private final ObjectAnimation objectAnimation; + private final int positionOffset; + + /** + * Instantiates a new Object anim message. + * + * @param objectAnimation the object animation + * @param positionOffset the position offset + */ + public ObjectAnimationMessage(ObjectAnimation objectAnimation, int positionOffset) { + this.objectAnimation = objectAnimation; + this.positionOffset = positionOffset; + } + + /** + * Gets object. + * + * @return the object + */ + public GameObject getObject() { + return objectAnimation.getObject(); + } + + /** + * Gets animation. + * + * @return the animation + */ + public Animation getAnimation() { + return objectAnimation.getAnimation(); + } + + /** + * Gets position offset. + * + * @return the position offset + */ + public int getPositionOffset() { + return positionOffset; + } + + @Override + public int priority() { + return 4; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ObjectAnimationMessage that = (ObjectAnimationMessage) o; + return positionOffset == that.positionOffset && objectAnimation.equals(that.objectAnimation); + } + + @Override + public int hashCode() { + return Objects.hash(objectAnimation, positionOffset); + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/PlayerSynchronizationMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/PlayerSynchronizationMessage.java new file mode 100644 index 000000000..a102d5df3 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/PlayerSynchronizationMessage.java @@ -0,0 +1,19 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.game.model.entity.PlayerUpdateInfo; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.message.Message; + +public final class PlayerSynchronizationMessage extends Message { + + + private final GamePacketBuilder info; + + public PlayerSynchronizationMessage(GamePacketBuilder info) { + this.info = info; + } + + public GamePacketBuilder getInfo() { + return info; + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/RebuildNormalMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/RebuildNormalMessage.java new file mode 100644 index 000000000..74dbacc5d --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/RebuildNormalMessage.java @@ -0,0 +1,107 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.cache.map.XteaRepository; +import org.apollo.game.model.Position; +import org.apollo.game.model.entity.MobRepository; +import org.apollo.game.model.entity.Player; +import org.apollo.game.model.entity.PlayerUpdateInfo; +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent to the client instructing it to load the specified region. + * + * @author Graham + */ +public final class RebuildNormalMessage extends Message { + + /** + * The position of the region to load. + */ + private final Position position; + + /** + * The index of the player. + */ + private final int index; + + /** + * The update information of the player. + */ + private PlayerUpdateInfo info; + + /** + * The repository containing xteas. + */ + private final XteaRepository xteaRepository; + + /** + * The repository containing players. + */ + private final MobRepository playerRepository; + + /** + * If the player has a last known region. + */ + private final boolean hasLastKnownRegion; + + /** + * Creates the region changed message. + * + * @param position The position of the region. + * @param xteaRepository the repository + * @param hasLastKnownRegion if the player has been in a region. + */ + public RebuildNormalMessage(Position position, int index, PlayerUpdateInfo info, MobRepository playerRepository, XteaRepository xteaRepository, boolean hasLastKnownRegion) { + this.position = position; + this.index = index; + this.info = info; + this.xteaRepository = xteaRepository; + this.playerRepository = playerRepository; + this.hasLastKnownRegion = hasLastKnownRegion; + } + + /** + * Gets the position of the region to load. + * + * @return The position of the region to load. + */ + public Position getPosition() { + return position; + } + + + /** + * Gets the index of the player. + * + * @return the index. + */ + public int getIndex() { + return index; + } + + public PlayerUpdateInfo getInfo() { + return info; + } + + /** + * Gets repository. + * + * @return the repository + */ + public XteaRepository getXteaRepository() { + return xteaRepository; + } + + /** + * Is has last known region boolean. + * + * @return the boolean + */ + public boolean isHasLastKnownRegion() { + return hasLastKnownRegion; + } + + public MobRepository getPlayerRepository() { + return playerRepository; + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/RegionUpdateMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/RegionUpdateMessage.java similarity index 66% rename from game/src/main/java/org/apollo/game/message/impl/RegionUpdateMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/RegionUpdateMessage.java index 6775d01e9..9fc168db5 100644 --- a/game/src/main/java/org/apollo/game/message/impl/RegionUpdateMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/RegionUpdateMessage.java @@ -1,9 +1,9 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; /** - * A {@link Message} that can be grouped with other Messages as part of a {@link GroupedRegionUpdateMessage}. + * A {@link Message} that can be grouped with other Messages as part of a {@link UpdateZonePartialEnclosedMessage}. *

* This is a utility class for Messages that can be grouped, as is not encoded directly. * @@ -11,16 +11,6 @@ */ public abstract class RegionUpdateMessage extends Message implements Comparable { - /** - * The integer value indicating this RegionUpdateMessage is a high-priority message. - */ - protected static final int HIGH_PRIORITY = 0; - - /** - * The integer value indicating this RegionUpdateMessage is a low-priority message. - */ - protected static final int LOW_PRIORITY = 1; - @Override public final int compareTo(RegionUpdateMessage other) { return Integer.compare(priority(), other.priority()); diff --git a/game/src/main/java/org/apollo/game/message/impl/RemoveObjectMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/RemoveObjectMessage.java similarity index 96% rename from game/src/main/java/org/apollo/game/message/impl/RemoveObjectMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/RemoveObjectMessage.java index 00557bc3d..9ddb32ca2 100644 --- a/game/src/main/java/org/apollo/game/message/impl/RemoveObjectMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/RemoveObjectMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.entity.obj.GameObject; import org.apollo.net.message.Message; @@ -83,7 +83,7 @@ public int hashCode() { @Override public int priority() { - return HIGH_PRIORITY; + return 6; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/RemoveTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/RemoveTileItemMessage.java similarity index 96% rename from game/src/main/java/org/apollo/game/message/impl/RemoveTileItemMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/RemoveTileItemMessage.java index 6dffea068..31ec98cd4 100644 --- a/game/src/main/java/org/apollo/game/message/impl/RemoveTileItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/RemoveTileItemMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.Item; import org.apollo.net.message.Message; @@ -77,7 +77,7 @@ public int hashCode() { @Override public int priority() { - return HIGH_PRIORITY; + return 7; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/RunClientScriptMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/RunClientScriptMessage.java new file mode 100644 index 000000000..0fe551447 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/RunClientScriptMessage.java @@ -0,0 +1,41 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * @author Khaled Abdeljaber + */ +public class RunClientScriptMessage extends Message { + + private final int id; + private final Object[] params; + + /** + * Instantiates a new Run client script message. + * + * @param id the id + * @param params the params + */ + public RunClientScriptMessage(int id, Object... params) { + this.id = id; + this.params = params; + } + + /** + * Gets id. + * + * @return the id + */ + public int getId() { + return id; + } + + /** + * Get params object [ ]. + * + * @return the object [ ] + */ + public Object[] getParams() { + return params; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/SendProjectileMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/SendProjectileMessage.java similarity index 96% rename from game/src/main/java/org/apollo/game/message/impl/SendProjectileMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/SendProjectileMessage.java index bf60f8e51..816a97c98 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SendProjectileMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/SendProjectileMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.entity.Projectile; import org.apollo.net.message.Message; @@ -69,6 +69,6 @@ public int hashCode() { @Override public int priority() { - return LOW_PRIORITY; + return 1; } } diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/ServerChatMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/ServerChatMessage.java new file mode 100644 index 000000000..b6249a28c --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/ServerChatMessage.java @@ -0,0 +1,95 @@ +package org.apollo.game.message.impl.encode; + +import com.google.common.base.Strings; +import org.apollo.net.message.Message; + +/** + * A {@link Message} sent to the client to display a server chat message. + * + * @author Graham + */ +public final class ServerChatMessage extends Message { + + public enum ChatType { + GAME_MESSAGE(0, false), + MOD_CHAT(1, false), + PUBLIC_CHAT(2, false), + PRIVATE_CHAT(3, false), + ENGINE(4, false), + LOGIN_LOGOUT_NOTIFICATION(5, false), + PRIVATE_CHAT_OUT(6, false), + MOD_PRIVATE_CHAT(7, false), + FRIENDS_CHAT(9, false), + FRIENDS_CHAT_NOTIFICATION(11, false), + BROADCAST(14, false), + SNAPSHOT_FEEDBACK(26, false), + ITEM_EXAMINE(27, false), + NPC_EXAMINE(28, false), + LOC_EXAMINE(29, false), + FRIEND_NOTIFICATION(30, false), + IGNORE_NOTIFICATION(31, false), + AUTO_TYPER(90, false), + MOD_AUTO_TYPER(91, false), + CONSOLE(99, false), + TRADE_REQ(101, true), + TRADE(102, false), + CHAL_REQ_TRADE(103, true), + CHAL_REQ_FRIENDS_CHAT(104, false), + SPAM(105, false), + PLAYER_RELATED(106, false), + TEN_SECOND_TIMOUT(107, false), + ; + + private final int id; + private final boolean extensionAvailable; + + ChatType(int id, boolean extensionAvailable) { + this.id = id; + this.extensionAvailable = extensionAvailable; + } + + public int getId() { + return id; + } + + public boolean isExtensionAvailable() { + return extensionAvailable; + } + } + + /** + * The message to send. + */ + private final String message; + private final ChatType type; + private final String extension; + + public ServerChatMessage(String message, ChatType type, String extension) { + if (!type.isExtensionAvailable() && !extension.isEmpty()) { + throw new IllegalArgumentException("Type of " + type + " cannot contain an extension."); + } + this.message = message; + this.type = type; + this.extension = Strings.nullToEmpty(extension); + } + + public ServerChatMessage(String message, ChatType type) { + this(message, type, ""); + } + + public ServerChatMessage(String message) { + this(message, ChatType.GAME_MESSAGE); + } + + public String getMessage() { + return message; + } + + public ChatType getType() { + return type; + } + + public String getExtension() { + return extension; + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/SetMapFlagMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/SetMapFlagMessage.java new file mode 100644 index 000000000..43675c8e1 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/SetMapFlagMessage.java @@ -0,0 +1,42 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.net.message.Message; + +/** + * The type Set map flag message. + * + * @author Khaled Abdeljaber + */ +public class SetMapFlagMessage extends Message { + + private byte x, y; + + /** + * Instantiates a new Set map flag message. + * + * @param x the x. + * @param y the y. + */ + public SetMapFlagMessage(byte x, byte y) { + this.x = x; + this.y = y; + } + + /** + * Gets x. + * + * @return the x + */ + public byte getX() { + return x; + } + + /** + * Gets y. + * + * @return the y + */ + public byte getY() { + return y; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/SetPlayerActionMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/SetPlayerActionMessage.java similarity index 97% rename from game/src/main/java/org/apollo/game/message/impl/SetPlayerActionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/SetPlayerActionMessage.java index 4db7ceefc..1bb17453f 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SetPlayerActionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/SetPlayerActionMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/SetPrivateChatFilterMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/SetPrivateChatFilterMessage.java new file mode 100644 index 000000000..0794a3516 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/SetPrivateChatFilterMessage.java @@ -0,0 +1,33 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.game.model.entity.setting.PrivacyState; +import org.apollo.net.message.Message; + +/** + * @author Khaled Abdeljaber + */ +public class SetPrivateChatFilterMessage extends Message { + + /** + * The privacy state of the player's trade chat. + */ + private final PrivacyState friendPrivacy; + + /** + * Creates a privacy option message. + * + * @param friendPrivacy The privacy state of the player's friend chat. + */ + public SetPrivateChatFilterMessage(PrivacyState friendPrivacy) { + this.friendPrivacy = friendPrivacy; + } + + /** + * Gets the friend {@link PrivacyState}. + * + * @return The privacy state. + */ + public PrivacyState getFriendPrivacy() { + return friendPrivacy; + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/encode/SpotAnimMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/SpotAnimMessage.java new file mode 100644 index 000000000..f7c8ed921 --- /dev/null +++ b/game/src/main/java/org/apollo/game/message/impl/encode/SpotAnimMessage.java @@ -0,0 +1,70 @@ +package org.apollo.game.message.impl.encode; + +import org.apollo.game.model.entity.SpotAnim; + +import java.util.Objects; + +/** + * The type Spot anim message. + * + * @author Khaled Abdeljaber + */ +public class SpotAnimMessage extends RegionUpdateMessage { + + /** + * The graphic. + */ + private final SpotAnim spotAnim; + + /** + * The position offset. + */ + private final int positionOffset; + + /** + * Instantiates a new Spot anim message. + * + * @param spotAnim the anim + * @param positionOffset the position offset + */ + public SpotAnimMessage(SpotAnim spotAnim, int positionOffset) { + this.spotAnim = spotAnim; + this.positionOffset = positionOffset; + } + + /** + * Gets anim. + * + * @return the anim + */ + public SpotAnim getSpotAnim() { + return spotAnim; + } + + /** + * Gets position offset. + * + * @return the position offset + */ + public int getPositionOffset() { + return positionOffset; + } + + @Override + public int priority() { + return 3; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SpotAnimMessage that = (SpotAnimMessage) o; + return positionOffset == that.positionOffset && spotAnim.equals(that.spotAnim); + } + + @Override + public int hashCode() { + return Objects.hash(spotAnim, positionOffset); + } +} diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateItemsMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryFullMessage.java similarity index 53% rename from game/src/main/java/org/apollo/game/message/impl/UpdateItemsMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryFullMessage.java index 662c0a253..0d1ca637a 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateItemsMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryFullMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.Item; import org.apollo.net.message.Message; @@ -8,13 +8,23 @@ * * @author Graham */ -public final class UpdateItemsMessage extends Message { +public final class UpdateInventoryFullMessage extends Message { /** * The interface id. */ private final int interfaceId; + /** + * The component. + */ + private final int component; + + /** + * The id of this inventory. + */ + private final int inventory; + /** * The items. */ @@ -26,8 +36,10 @@ public final class UpdateItemsMessage extends Message { * @param interfaceId The interface id. * @param items The items. */ - public UpdateItemsMessage(int interfaceId, Item[] items) { + public UpdateInventoryFullMessage(int interfaceId, int component, int inventory, Item[] items) { this.interfaceId = interfaceId; + this.component = component; + this.inventory = inventory; this.items = items; } @@ -40,6 +52,24 @@ public int getInterfaceId() { return interfaceId; } + /** + * Gets the component. + * + * @return The component. + */ + public int getComponent() { + return component; + } + + /** + * Gets container id. + * + * @return the container id + */ + public int getInventory() { + return inventory; + } + /** * Gets the items. * diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateSlottedItemsMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryPartialMessage.java similarity index 52% rename from game/src/main/java/org/apollo/game/message/impl/UpdateSlottedItemsMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryPartialMessage.java index e0848096a..741782246 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateSlottedItemsMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateInventoryPartialMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.inv.SlottedItem; import org.apollo.net.message.Message; @@ -8,13 +8,23 @@ * * @author Graham */ -public final class UpdateSlottedItemsMessage extends Message { +public final class UpdateInventoryPartialMessage extends Message { /** * The interface id. */ private final int interfaceId; + /** + * The component. + */ + private final int component; + + /** + * The id of this container. + */ + private final int containerId; + /** * The slotted items. */ @@ -24,10 +34,12 @@ public final class UpdateSlottedItemsMessage extends Message { * Creates the update item in interface message. * * @param interfaceId The interface id. - * @param items The slotted items. + * @param items The slotted items. */ - public UpdateSlottedItemsMessage(int interfaceId, SlottedItem... items) { + public UpdateInventoryPartialMessage(int interfaceId, int component, int containerId, SlottedItem... items) { this.interfaceId = interfaceId; + this.component = component; + this.containerId = containerId; this.items = items; } @@ -40,6 +52,24 @@ public int getInterfaceId() { return interfaceId; } + /** + * Gets the component. + * + * @return The component. + */ + public int getComponent() { + return component; + } + + /** + * Gets container id. + * + * @return the container id + */ + public int getContainerId() { + return containerId; + } + /** * Gets an array of slotted items. * diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateRunEnergyMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateRunEnergyMessage.java similarity index 92% rename from game/src/main/java/org/apollo/game/message/impl/UpdateRunEnergyMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateRunEnergyMessage.java index c4f3bef00..5eb64c9a5 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateRunEnergyMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateRunEnergyMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateSkillMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateSkillMessage.java similarity index 94% rename from game/src/main/java/org/apollo/game/message/impl/UpdateSkillMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateSkillMessage.java index 85dfca663..19d285e74 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateSkillMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateSkillMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.entity.Skill; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateTileItemMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateTileItemMessage.java similarity index 97% rename from game/src/main/java/org/apollo/game/message/impl/UpdateTileItemMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateTileItemMessage.java index ef923f928..ab411527c 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateTileItemMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateTileItemMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.Item; import org.apollo.net.message.Message; @@ -103,7 +103,7 @@ public int hashCode() { @Override public int priority() { - return LOW_PRIORITY; + return 0; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/message/impl/UpdateWeightMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateWeightMessage.java similarity index 92% rename from game/src/main/java/org/apollo/game/message/impl/UpdateWeightMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateWeightMessage.java index ba153dafa..9215b022b 100644 --- a/game/src/main/java/org/apollo/game/message/impl/UpdateWeightMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateWeightMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/message/impl/ClearRegionMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateZoneFullFollowsMessage.java similarity index 84% rename from game/src/main/java/org/apollo/game/message/impl/ClearRegionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateZoneFullFollowsMessage.java index 9506a87f9..c8e64f3a4 100644 --- a/game/src/main/java/org/apollo/game/message/impl/ClearRegionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateZoneFullFollowsMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.Position; import org.apollo.game.model.area.RegionCoordinates; @@ -9,7 +9,7 @@ * * @author Major */ -public final class ClearRegionMessage extends Message { +public final class UpdateZoneFullFollowsMessage extends Message { /** * The Position of the Player. @@ -27,7 +27,7 @@ public final class ClearRegionMessage extends Message { * @param player The {@link Position} of the Player this {@link Message} is being sent to. * @param region The {@link RegionCoordinates} of the Region being cleared. */ - public ClearRegionMessage(Position player, RegionCoordinates region) { + public UpdateZoneFullFollowsMessage(Position player, RegionCoordinates region) { this.player = player; this.region = new Position(region.getAbsoluteX(), region.getAbsoluteY()); } diff --git a/game/src/main/java/org/apollo/game/message/impl/GroupedRegionUpdateMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateZonePartialEnclosedMessage.java similarity index 83% rename from game/src/main/java/org/apollo/game/message/impl/GroupedRegionUpdateMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateZonePartialEnclosedMessage.java index b563243e7..5839e0198 100644 --- a/game/src/main/java/org/apollo/game/message/impl/GroupedRegionUpdateMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateZonePartialEnclosedMessage.java @@ -1,18 +1,17 @@ -package org.apollo.game.message.impl; - -import java.util.List; -import java.util.Set; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.Position; import org.apollo.game.model.area.RegionCoordinates; import org.apollo.net.message.Message; +import java.util.Set; + /** * A {@link Message} sent to the client that contains multiple * * @author Major */ -public final class GroupedRegionUpdateMessage extends Message { +public final class UpdateZonePartialEnclosedMessage extends Message { /** * The last known region Position of the Player. @@ -36,8 +35,8 @@ public final class GroupedRegionUpdateMessage extends Message { * @param coordinates The {@link RegionCoordinates} of the Region being updated. * @param messages The {@link Set} of {@link RegionUpdateMessage}s. */ - public GroupedRegionUpdateMessage(Position lastKnownRegion, RegionCoordinates coordinates, - Set messages) { + public UpdateZonePartialEnclosedMessage(Position lastKnownRegion, RegionCoordinates coordinates, + Set messages) { this.lastKnownRegion = lastKnownRegion; region = new Position(coordinates.getAbsoluteX(), coordinates.getAbsoluteY()); this.messages = messages; diff --git a/game/src/main/java/org/apollo/game/message/impl/SetUpdatedRegionMessage.java b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateZonePartialFollowsMessage.java similarity index 84% rename from game/src/main/java/org/apollo/game/message/impl/SetUpdatedRegionMessage.java rename to game/src/main/java/org/apollo/game/message/impl/encode/UpdateZonePartialFollowsMessage.java index cc7fdf9e0..4093266ca 100644 --- a/game/src/main/java/org/apollo/game/message/impl/SetUpdatedRegionMessage.java +++ b/game/src/main/java/org/apollo/game/message/impl/encode/UpdateZonePartialFollowsMessage.java @@ -1,4 +1,4 @@ -package org.apollo.game.message.impl; +package org.apollo.game.message.impl.encode; import org.apollo.game.model.Position; import org.apollo.game.model.area.RegionCoordinates; @@ -9,7 +9,7 @@ * * @author Major */ -public final class SetUpdatedRegionMessage extends Message { +public final class UpdateZonePartialFollowsMessage extends Message { /** * The Position of the Player. @@ -27,7 +27,7 @@ public final class SetUpdatedRegionMessage extends Message { * @param player The {@link Position} of the Player this {@link Message} is being sent to. * @param region The {@link RegionCoordinates} of the Region being set. */ - public SetUpdatedRegionMessage(Position player, RegionCoordinates region) { + public UpdateZonePartialFollowsMessage(Position player, RegionCoordinates region) { this.player = player; this.region = new Position(region.getAbsoluteX(), region.getAbsoluteY()); } diff --git a/game/src/main/java/org/apollo/game/model/Direction.java b/game/src/main/java/org/apollo/game/model/Direction.java index d1a13ffbd..de386244f 100644 --- a/game/src/main/java/org/apollo/game/model/Direction.java +++ b/game/src/main/java/org/apollo/game/model/Direction.java @@ -10,47 +10,47 @@ public enum Direction { /** * No movement. */ - NONE(-1), + NONE(-1, -1), /** * North west movement. */ - NORTH_WEST(0), + NORTH_WEST(0, 768), /** * North movement. */ - NORTH(1), + NORTH(1, 1024), /** * North east movement. */ - NORTH_EAST(2), + NORTH_EAST(2, 1280), /** * West movement. */ - WEST(3), + WEST(3, 512), /** * East movement. */ - EAST(4), + EAST(4, 1536), /** * South west movement. */ - SOUTH_WEST(5), + SOUTH_WEST(5, 256), /** * South movement. */ - SOUTH(6), + SOUTH(6, 0), /** * South east movement. */ - SOUTH_EAST(7); + SOUTH_EAST(7, 1792); /** * An empty direction array. @@ -151,13 +151,19 @@ public static Direction[] diagonalComponents(Direction direction) { */ private final int intValue; + /** + * The direction as a JAG-Rotation. + */ + private final int clientValue; + /** * Creates the direction. * * @param intValue The direction as an integer. */ - Direction(int intValue) { + Direction(int intValue, int clientValue) { this.intValue = intValue; + this.clientValue = clientValue; } /** @@ -246,6 +252,14 @@ public int toInteger() { return intValue; } + /** + * The client value for the given direction. + * @return The client value. + */ + public int getClientValue() { + return clientValue; + } + /** * Gets the direction as an integer as used orientation in the client maps (WNES as opposed to NESW). * diff --git a/game/src/main/java/org/apollo/game/model/Position.java b/game/src/main/java/org/apollo/game/model/Position.java index e68241a00..1ffeee8f7 100644 --- a/game/src/main/java/org/apollo/game/model/Position.java +++ b/game/src/main/java/org/apollo/game/model/Position.java @@ -41,14 +41,14 @@ public Position(int x, int y) { /** * Creates a position with the specified height. * - * @param x The x coordinate. - * @param y The y coordinate. + * @param x The x coordinate. + * @param y The y coordinate. * @param height The height. */ public Position(int x, int y, int height) { Preconditions.checkElementIndex(height, HEIGHT_LEVELS, "Height must be [0, 3), received " + height + "."); - packed = height << 30 | (y & 0x7FFF) << 15 | x & 0x7FFF; + packed = y & 0x3fff | ((x & 0x3fff) << 14) | (height << 28); } @Override @@ -91,15 +91,6 @@ public int getDistance(Position other) { return (int) Math.ceil(Math.sqrt(deltaX * deltaX + deltaY * deltaY)); } - /** - * Gets the height level. - * - * @return The height level. - */ - public int getHeight() { - return packed >>> 30; - } - /** * Gets the x coordinate inside the region of this position. * @@ -183,7 +174,7 @@ public int getTopLeftRegionY() { * @return The x coordinate. */ public int getX() { - return packed & 0x7FFF; + return packed >>> 14 & 0x3fff; } /** @@ -192,7 +183,16 @@ public int getX() { * @return The y coordinate. */ public int getY() { - return packed >> 15 & 0x7FFF; + return packed & 0x3fff; + } + + /** + * Gets the height level. + * + * @return The height level. + */ + public int getHeight() { + return packed >>> 28; } @Override @@ -214,7 +214,7 @@ public boolean inside(Region region) { /** * Checks if the position is within distance of another. * - * @param other The other position. + * @param other The other position. * @param distance The distance. * @return {@code true} if so, {@code false} if not. */ @@ -227,7 +227,7 @@ public boolean isWithinDistance(Position other, int distance) { /** * Creates a new position {@code num} steps from this position in the given direction. * - * @param num The number of steps to make. + * @param num The number of steps to make. * @param direction The direction to make steps in. * @return A new {@code Position} that is {@code num} steps in {@code direction} ahead of this one. */ @@ -237,6 +237,11 @@ public Position step(int num, Direction direction) { @Override public String toString() { - return MoreObjects.toStringHelper(this).add("x", getX()).add("y", getY()).add("height", getHeight()).add("map", getRegionCoordinates()).toString(); + return MoreObjects.toStringHelper(this).add("x", getX()).add("y", getY()).add("height", getHeight()) + .add("map", getRegionCoordinates()).toString(); + } + + public int get18BitHash() { + return (getY() >> 13) + ((getX() >> 13) << 8) + (getHeight() << 16); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/World.java b/game/src/main/java/org/apollo/game/model/World.java index 5d5adb0f8..c56d61dee 100644 --- a/game/src/main/java/org/apollo/game/model/World.java +++ b/game/src/main/java/org/apollo/game/model/World.java @@ -5,12 +5,15 @@ import com.google.common.base.Preconditions; import org.apollo.Service; -import org.apollo.cache.IndexedFileSystem; +import org.apollo.cache.Cache; import org.apollo.cache.decoder.ItemDefinitionDecoder; import org.apollo.cache.decoder.NpcDefinitionDecoder; import org.apollo.cache.decoder.ObjectDefinitionDecoder; +import org.apollo.cache.decoder.rsenum.EnumDefinitionDecoder; import org.apollo.cache.map.MapIndexDecoder; +import org.apollo.cache.map.XteaRepository; import org.apollo.game.command.CommandDispatcher; +import org.apollo.game.fs.decoder.HuffmanCodecDecoder; import org.apollo.game.fs.decoder.SynchronousDecoder; import org.apollo.game.fs.decoder.WorldMapDecoder; import org.apollo.game.fs.decoder.WorldObjectsDecoder; @@ -213,26 +216,30 @@ public int getReleaseNumber() { * system. * * @param release The release number. - * @param fs The file system. + * @param cache The file system. * @param manager The plugin manager. TODO move this. * @throws Exception If there was a failure when loading plugins. */ - public void init(int release, IndexedFileSystem fs, PluginManager manager) throws Exception { + public void init(int release, Cache cache, PluginManager manager) throws Exception { releaseNumber = release; + regions.setXteaRepository(new XteaRepository(release)); + SynchronousDecoder firstStageDecoder = new SynchronousDecoder( - new NpcDefinitionDecoder(fs), - new ItemDefinitionDecoder(fs), - new ObjectDefinitionDecoder(fs), - new MapIndexDecoder(fs), + new NpcDefinitionDecoder(cache), + new ItemDefinitionDecoder(cache), + new EnumDefinitionDecoder(cache), + new ObjectDefinitionDecoder(cache), + new MapIndexDecoder(cache, regions.getXteaRepository()), EquipmentDefinitionParser.fromFile("data/equipment-" + release + "" + ".dat") ); firstStageDecoder.block(); SynchronousDecoder secondStageDecoder = new SynchronousDecoder( - new WorldObjectsDecoder(fs, this, regions), - new WorldMapDecoder(fs, collisionManager) + new HuffmanCodecDecoder(cache), + new WorldObjectsDecoder(cache, this), + new WorldMapDecoder(collisionManager) ); secondStageDecoder.block(); diff --git a/game/src/main/java/org/apollo/game/model/WorldConstants.java b/game/src/main/java/org/apollo/game/model/WorldConstants.java index b76c47e35..563b7b442 100644 --- a/game/src/main/java/org/apollo/game/model/WorldConstants.java +++ b/game/src/main/java/org/apollo/game/model/WorldConstants.java @@ -15,7 +15,7 @@ public final class WorldConstants { /** * The maximum number of players. */ - public static final int MAXIMUM_PLAYERS = 2000; + public static final int MAXIMUM_PLAYERS = 2048; /** * Default private constructor to prevent instantiation by other classes. diff --git a/game/src/main/java/org/apollo/game/model/area/Region.java b/game/src/main/java/org/apollo/game/model/area/Region.java index df7a9a170..a59c14f8c 100644 --- a/game/src/main/java/org/apollo/game/model/area/Region.java +++ b/game/src/main/java/org/apollo/game/model/area/Region.java @@ -3,7 +3,7 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; -import org.apollo.game.message.impl.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.Direction; import org.apollo.game.model.Position; import org.apollo.game.model.area.collision.CollisionMatrix; @@ -247,6 +247,19 @@ public Set getEntities(Position position) { return (set == null) ? ImmutableSet.of() : ImmutableSet.copyOf(set); } + /** + * Gets a shallow copy of the {@link Set} of {@link Entity} objects of the specified type. The returned + * type will be immutable. + * + * @param type The type of entity. + * @return The Set. Will be immutable. + */ + @SuppressWarnings("unchecked") + public Stream getEntities(EntityType type) { + return (Stream) entities.values().stream().flatMap(Collection::stream) + .filter(entity -> entity.getEntityType() == type); + } + /** * Gets a shallow copy of the {@link Set} of {@link Entity}s with the specified {@link EntityType}(s). The returned * type will be immutable. Type will be inferred from the call, so ensure that the Entity type and the reference diff --git a/game/src/main/java/org/apollo/game/model/area/RegionRepository.java b/game/src/main/java/org/apollo/game/model/area/RegionRepository.java index 902ffdbf8..0df8871d1 100644 --- a/game/src/main/java/org/apollo/game/model/area/RegionRepository.java +++ b/game/src/main/java/org/apollo/game/model/area/RegionRepository.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; +import org.apollo.cache.map.XteaRepository; import org.apollo.game.model.Position; import com.google.common.base.Preconditions; @@ -54,6 +55,11 @@ public static RegionRepository mutable() { */ private final List defaultRegionListeners = new ArrayList<>(); + /** + * A repository of xteas. + */ + private XteaRepository xteaRepository; + /** * Creates a new RegionRepository. * @@ -169,4 +175,21 @@ public boolean remove(Region region) { return regions.remove(region.getCoordinates()) != null; } + /** + * Gets xtea repository. + * + * @return the xtea repository + */ + public XteaRepository getXteaRepository() { + return xteaRepository; + } + + /** + * Sets xtea repository. + * + * @param xteaRepository the xtea repository + */ + public void setXteaRepository(XteaRepository xteaRepository) { + this.xteaRepository = xteaRepository; + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/area/collision/CollisionManager.java b/game/src/main/java/org/apollo/game/model/area/collision/CollisionManager.java index d8a428ff7..47703a26b 100644 --- a/game/src/main/java/org/apollo/game/model/area/collision/CollisionManager.java +++ b/game/src/main/java/org/apollo/game/model/area/collision/CollisionManager.java @@ -65,11 +65,11 @@ public void build(boolean rebuilding) { } } - regions.getRegions().forEach(region -> { + regions.getRegions().parallelStream().forEach(region -> { CollisionUpdate.Builder builder = new CollisionUpdate.Builder(); builder.type(CollisionUpdateType.ADDING); - blocked.get(region.getCoordinates()).forEach(tile -> { + for (var tile : blocked.get(region.getCoordinates())) { int x = tile.getX(), y = tile.getY(); int height = tile.getHeight(); @@ -80,7 +80,7 @@ public void build(boolean rebuilding) { if (height >= 0) { builder.tile(new Position(x, y, height), false, Direction.NESW); } - }); + } apply(builder.build()); diff --git a/game/src/main/java/org/apollo/game/model/area/collision/CollisionMatrix.java b/game/src/main/java/org/apollo/game/model/area/collision/CollisionMatrix.java index 86d755f6b..4917b9a74 100644 --- a/game/src/main/java/org/apollo/game/model/area/collision/CollisionMatrix.java +++ b/game/src/main/java/org/apollo/game/model/area/collision/CollisionMatrix.java @@ -1,12 +1,11 @@ package org.apollo.game.model.area.collision; -import java.util.Arrays; - +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; import org.apollo.game.model.Direction; import org.apollo.game.model.entity.EntityType; -import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; +import java.util.Arrays; /** * A 2-dimensional adjacency matrix containing tile collision data. diff --git a/game/src/main/java/org/apollo/game/model/area/update/AreaSoundUpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/AreaSoundUpdateOperation.java new file mode 100644 index 000000000..fc23fc5d7 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/area/update/AreaSoundUpdateOperation.java @@ -0,0 +1,36 @@ +package org.apollo.game.model.area.update; + +import org.apollo.game.message.impl.encode.AreaSoundMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; +import org.apollo.game.model.area.EntityUpdateType; +import org.apollo.game.model.area.Region; +import org.apollo.game.model.entity.AreaSound; +import org.apollo.game.model.entity.SpotAnim; + +/** + * @author Khaled Abdeljaber + */ +public class AreaSoundUpdateOperation extends UpdateOperation { + + /** + * Creates the UpdateOperation. + * + * @param region The region in which the UpdateOperation occurred. Must not be {@code null}. + * @param type The type of {@link EntityUpdateType}. Must not be {@code null}. + * @param entity The {@link Entity} being added or removed. Must not be {@code null}. + */ + public AreaSoundUpdateOperation(Region region, EntityUpdateType type, AreaSound entity) { + super(region, type, entity); + } + + @Override + protected RegionUpdateMessage add(int offset) { + return new AreaSoundMessage(entity, offset); + } + + @Override + protected RegionUpdateMessage remove(int offset) { + throw new IllegalStateException("Area sounds cannot be removed."); + } +} + diff --git a/game/src/main/java/org/apollo/game/model/area/update/ItemUpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/ItemUpdateOperation.java index 05f690e61..ade6d5bc5 100644 --- a/game/src/main/java/org/apollo/game/model/area/update/ItemUpdateOperation.java +++ b/game/src/main/java/org/apollo/game/model/area/update/ItemUpdateOperation.java @@ -1,8 +1,8 @@ package org.apollo.game.model.area.update; -import org.apollo.game.message.impl.RegionUpdateMessage; -import org.apollo.game.message.impl.RemoveTileItemMessage; -import org.apollo.game.message.impl.SendPublicTileItemMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.RemoveTileItemMessage; +import org.apollo.game.message.impl.encode.AddTileItemMessage; import org.apollo.game.model.area.EntityUpdateType; import org.apollo.game.model.area.Region; import org.apollo.game.model.entity.GroundItem; @@ -27,7 +27,7 @@ public ItemUpdateOperation(Region region, EntityUpdateType type, GroundItem item @Override protected RegionUpdateMessage add(int offset) { - return new SendPublicTileItemMessage(entity.getItem(), entity.getOwnerIndex(), offset); + return new AddTileItemMessage(entity.getItem(), entity.getOwnerIndex(), offset); } @Override diff --git a/game/src/main/java/org/apollo/game/model/area/update/ObjectAnimationUpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/ObjectAnimationUpdateOperation.java new file mode 100644 index 000000000..388f1dd62 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/area/update/ObjectAnimationUpdateOperation.java @@ -0,0 +1,33 @@ +package org.apollo.game.model.area.update; + +import org.apollo.game.message.impl.encode.ObjectAnimationMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; +import org.apollo.game.model.area.EntityUpdateType; +import org.apollo.game.model.area.Region; +import org.apollo.game.model.entity.obj.ObjectAnimation; + +/** + * @author Khaled Abdeljaber + */ +public class ObjectAnimationUpdateOperation extends UpdateOperation { + /** + * Creates the UpdateOperation. + * + * @param region The region in which the UpdateOperation occurred. Must not be {@code null}. + * @param type The type of {@link EntityUpdateType}. Must not be {@code null}. + * @param entity The {@link Entity} being added or removed. Must not be {@code null}. + */ + public ObjectAnimationUpdateOperation(Region region, EntityUpdateType type, ObjectAnimation entity) { + super(region, type, entity); + } + + @Override + protected RegionUpdateMessage add(int offset) { + return new ObjectAnimationMessage(entity, offset); + } + + @Override + protected RegionUpdateMessage remove(int offset) { + throw new IllegalStateException("Object animations cannot be removed."); + } +} diff --git a/game/src/main/java/org/apollo/game/model/area/update/ObjectUpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/ObjectUpdateOperation.java index b0f6d370f..c8014b0e3 100644 --- a/game/src/main/java/org/apollo/game/model/area/update/ObjectUpdateOperation.java +++ b/game/src/main/java/org/apollo/game/model/area/update/ObjectUpdateOperation.java @@ -1,8 +1,8 @@ package org.apollo.game.model.area.update; -import org.apollo.game.message.impl.RegionUpdateMessage; -import org.apollo.game.message.impl.RemoveObjectMessage; -import org.apollo.game.message.impl.SendObjectMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.RemoveObjectMessage; +import org.apollo.game.message.impl.encode.AddObjectMessage; import org.apollo.game.model.area.EntityUpdateType; import org.apollo.game.model.area.Region; import org.apollo.game.model.entity.obj.GameObject; @@ -27,7 +27,7 @@ public ObjectUpdateOperation(Region region, EntityUpdateType type, GameObject ob @Override protected RegionUpdateMessage add(int offset) { - return new SendObjectMessage(entity, offset); + return new AddObjectMessage(entity, offset); } @Override diff --git a/game/src/main/java/org/apollo/game/model/area/update/ProjectileUpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/ProjectileUpdateOperation.java index af755956b..f5c876f74 100644 --- a/game/src/main/java/org/apollo/game/model/area/update/ProjectileUpdateOperation.java +++ b/game/src/main/java/org/apollo/game/model/area/update/ProjectileUpdateOperation.java @@ -1,7 +1,7 @@ package org.apollo.game.model.area.update; -import org.apollo.game.message.impl.RegionUpdateMessage; -import org.apollo.game.message.impl.SendProjectileMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.SendProjectileMessage; import org.apollo.game.model.area.EntityUpdateType; import org.apollo.game.model.area.Region; import org.apollo.game.model.entity.Projectile; diff --git a/game/src/main/java/org/apollo/game/model/area/update/SpotAnimUpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/SpotAnimUpdateOperation.java new file mode 100644 index 000000000..f726a39da --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/area/update/SpotAnimUpdateOperation.java @@ -0,0 +1,35 @@ +package org.apollo.game.model.area.update; + +import org.apollo.game.message.impl.encode.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.SpotAnimMessage; +import org.apollo.game.model.area.EntityUpdateType; +import org.apollo.game.model.area.Region; +import org.apollo.game.model.entity.SpotAnim; +import org.apollo.game.model.entity.obj.GameObject; + +/** + * @author Khaled Abdeljaber + */ +public class SpotAnimUpdateOperation extends UpdateOperation { + + /** + * Creates the UpdateOperation. + * + * @param region The region in which the UpdateOperation occurred. Must not be {@code null}. + * @param type The type of {@link EntityUpdateType}. Must not be {@code null}. + * @param entity The {@link Entity} being added or removed. Must not be {@code null}. + */ + public SpotAnimUpdateOperation(Region region, EntityUpdateType type, SpotAnim entity) { + super(region, type, entity); + } + + @Override + protected RegionUpdateMessage add(int offset) { + return new SpotAnimMessage(entity, offset); + } + + @Override + protected RegionUpdateMessage remove(int offset) { + throw new IllegalStateException("SpotAnims cannot be removed."); + } +} diff --git a/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java b/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java index 710eded25..5ef41a550 100644 --- a/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java +++ b/game/src/main/java/org/apollo/game/model/area/update/UpdateOperation.java @@ -1,6 +1,6 @@ package org.apollo.game.model.area.update; -import org.apollo.game.message.impl.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.Position; import org.apollo.game.model.area.EntityUpdateType; import org.apollo.game.model.area.Region; diff --git a/game/src/main/java/org/apollo/game/model/entity/AreaSound.java b/game/src/main/java/org/apollo/game/model/entity/AreaSound.java new file mode 100644 index 000000000..7aa773a05 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/entity/AreaSound.java @@ -0,0 +1,104 @@ +package org.apollo.game.model.entity; + +import org.apollo.game.model.Position; +import org.apollo.game.model.World; +import org.apollo.game.model.area.EntityUpdateType; +import org.apollo.game.model.area.Region; +import org.apollo.game.model.area.update.AreaSoundUpdateOperation; +import org.apollo.game.model.area.update.GroupableEntity; +import org.apollo.game.model.area.update.UpdateOperation; + +import java.util.Objects; + +/** + * The type Area sound. + * + * @author Khaled Abdeljaber + */ +public class AreaSound extends Entity implements GroupableEntity { + + /** + * The sound. + */ + private final Sound sound; + + /** + * The radius the sound encompasses. + */ + private final int area; + + /** + * Instantiates a new Area sound. + * + * @param world the world + * @param position the position + * @param sound the sound + * @param area the area + */ + AreaSound(World world, Position position, Sound sound, int area) { + super(world, position); + this.position = position; + this.sound = sound; + this.area = area; + } + + /** + * Gets id. + * + * @return the id + */ + public int getId() { + return sound.getId(); + } + + /** + * Gets volume. + * + * @return the volume + */ + public int getVolume() { + return sound.getVolume(); + } + + /** + * Gets delay. + * + * @return the delay + */ + public int getDelay() { + return sound.getDelay(); + } + + @Override + public EntityType getEntityType() { + return EntityType.AREA_SOUND; + } + + @Override + public int getLength() { + return area; + } + + @Override + public int getWidth() { + return area; + } + + @Override + public UpdateOperation toUpdateOperation(Region region, EntityUpdateType type) { + return new AreaSoundUpdateOperation(region, type, this); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + AreaSound areaSound = (AreaSound) o; + return area == areaSound.area && sound.equals(areaSound.sound); + } + + @Override + public int hashCode() { + return Objects.hash(sound, area); + } +} diff --git a/game/src/main/java/org/apollo/game/model/entity/EntityType.java b/game/src/main/java/org/apollo/game/model/entity/EntityType.java index 3628ccd7a..536afd6ab 100644 --- a/game/src/main/java/org/apollo/game/model/entity/EntityType.java +++ b/game/src/main/java/org/apollo/game/model/entity/EntityType.java @@ -27,17 +27,34 @@ public enum EntityType { */ PLAYER, + /** + * A GameObject that is loaded statically (i.e. from the game resources) at start-up. + */ + STATIC_OBJECT, + /** * A projectile (e.g. an arrow). */ PROJECTILE, /** - * A GameObject that is loaded statically (i.e. from the game resources) at start-up. + * A sound that is heard within an area. */ - STATIC_OBJECT; + AREA_SOUND, /** + * A graphic that is played within an area. + */ + SPOT_ANIM, + + /** + * A graphic that is heard within an area. + */ + OBJECT_ANIMATION + + ; + + /** * Returns whether or not this EntityType is for a Mob. * * @return {@code true} if this EntityType is for a Mob, otherwise {@code false}. @@ -52,6 +69,6 @@ public boolean isMob() { * @return {@code true} if this EntityType is short-lived. */ public boolean isTransient() { - return this == PROJECTILE; + return this == PROJECTILE || this == AREA_SOUND || this == SPOT_ANIM || this == OBJECT_ANIMATION; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/entity/Mob.java b/game/src/main/java/org/apollo/game/model/entity/Mob.java index ec09bb9cb..4e9b52094 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Mob.java +++ b/game/src/main/java/org/apollo/game/model/entity/Mob.java @@ -24,6 +24,8 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; +import java.util.HashSet; /** * A living entity in the world, such as a player or npc. @@ -66,7 +68,7 @@ public abstract class Mob extends Entity { /** * This mob's list of local players. */ - private final List localPlayers = new ArrayList<>(); + private final Set localPlayers = new HashSet<>(); /** * This mob's set of synchronization blocks. @@ -98,6 +100,11 @@ public abstract class Mob extends Entity { */ private Position facingPosition = position; + /** + * The old position of this mob. + */ + private Position oldPosition = position; + /** * This mob's first movement direction. */ @@ -114,9 +121,9 @@ public abstract class Mob extends Entity { private Direction secondDirection = Direction.NONE; /** - * Indicates whether this mob is currently teleporting or not. + * The position to teleport to. */ - private boolean teleporting; + private Position teleportPosition; /** * Creates the Mob. @@ -217,6 +224,15 @@ public final Inventory getEquipment() { return equipment; } + + public Position getOldPosition() { + return oldPosition; + } + + public void setOldPosition(Position oldPosition) { + this.oldPosition = oldPosition; + } + /** * Gets the {@link Position} this mob is facing towards. * @@ -305,7 +321,7 @@ public final List getLocalNpcList() { * * @return The list. */ - public final List getLocalPlayerList() { + public final Set getLocalPlayerList() { return localPlayers; } @@ -373,15 +389,6 @@ public final boolean isActive() { return index != -1; } - /** - * Checks if this mob is currently teleporting. - * - * @return {@code true} if so, {@code false} if not. - */ - public final boolean isTeleporting() { - return teleporting; - } - /** * Makes this mob perform the specified {@link Animation}. * @@ -488,6 +495,7 @@ public void setLastDirection(Direction lastDirection) { public final void setPosition(Position position) { if (!position.equals(this.position) && world.submit(new MobPositionUpdateEvent(this, position))) { Position old = this.position; + RegionRepository repository = world.getRegionRepository(); Region current = repository.fromPosition(old), next = repository.fromPosition(position); @@ -498,15 +506,6 @@ public final void setPosition(Position position) { } } - /** - * Sets whether this mob is teleporting or not. - * - * @param teleporting {@code true} if the mob is teleporting, {@code false} if not. - */ - public final void setTeleporting(boolean teleporting) { - this.teleporting = teleporting; - } - /** * Forces this mob to shout a message. Only messages said by a player can be shown in the chat box. * @@ -573,15 +572,35 @@ public final void stopGraphic() { * Teleports this mob to the specified {@link Position}, setting the appropriate flags and clearing the walking * queue. * - * @param position The position. + * @param teleportPosition The position. */ - public void teleport(Position position) { - setPosition(position); - teleporting = true; + public void teleport(Position teleportPosition) { + this.teleportPosition = teleportPosition; walkingQueue.clear(); stopAction(); } + /** + * Checks if this mob is currently teleporting. + * + * @return {@code true} if so, {@code false} if not. + */ + public final boolean isTeleporting() { + return teleportPosition != null; + } + + /** + * The {@link Position} to teleport to. + * @return The teleport position. + */ + public Position getTeleportPosition() { + return teleportPosition; + } + + public void resetTeleportPosition() { + this.teleportPosition = null; + } + /** * Turns this mob to face the specified {@link Position}. * @@ -589,7 +608,7 @@ public void teleport(Position position) { */ public final void turnTo(Position position) { facingPosition = position; - blockSet.add(SynchronizationBlock.createTurnToPositionBlock(position)); + blockSet.add(SynchronizationBlock.createTurnToPositionBlock(getPosition(), position)); } /** @@ -599,5 +618,4 @@ private void init() { world.schedule(new SkillNormalizationTask(this)); } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/entity/MobRepository.java b/game/src/main/java/org/apollo/game/model/entity/MobRepository.java index 3a625b713..496deb038 100644 --- a/game/src/main/java/org/apollo/game/model/entity/MobRepository.java +++ b/game/src/main/java/org/apollo/game/model/entity/MobRepository.java @@ -40,7 +40,7 @@ private final class MobRepositoryIterator implements Iterator { /** * Constructs a new {@link MobRepositoryIterator} with the specified * MobRepository. - * + * * @param repository * The MobRepository we're iterating over. */ diff --git a/game/src/main/java/org/apollo/game/model/entity/Player.java b/game/src/main/java/org/apollo/game/model/entity/Player.java index 76c06db95..66808574c 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Player.java +++ b/game/src/main/java/org/apollo/game/model/entity/Player.java @@ -10,15 +10,11 @@ import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; -import org.apollo.game.message.impl.ConfigMessage; -import org.apollo.game.message.impl.IdAssignmentMessage; -import org.apollo.game.message.impl.IgnoreListMessage; -import org.apollo.game.message.impl.LogoutMessage; import org.apollo.game.message.impl.SendFriendMessage; -import org.apollo.game.message.impl.ServerChatMessage; -import org.apollo.game.message.impl.SetWidgetTextMessage; -import org.apollo.game.message.impl.SwitchTabInterfaceMessage; -import org.apollo.game.message.impl.UpdateRunEnergyMessage; +import org.apollo.game.message.impl.SendFriendMessage.FriendMessageComponent; +import org.apollo.game.message.impl.UpdateIgnoreListMessage; +import org.apollo.game.message.impl.UpdateIgnoreListMessage.IgnoreMessageComponent; +import org.apollo.game.message.impl.encode.*; import org.apollo.game.model.Appearance; import org.apollo.game.model.Position; import org.apollo.game.model.World; @@ -39,6 +35,8 @@ import org.apollo.game.model.inter.InterfaceConstants; import org.apollo.game.model.inter.InterfaceListener; import org.apollo.game.model.inter.InterfaceSet; +import org.apollo.game.model.inter.DisplayMode; +import org.apollo.game.model.inter.TopLevelPosition; import org.apollo.game.model.inter.bank.BankConstants; import org.apollo.game.model.inter.bank.BankInterfaceListener; import org.apollo.game.model.inv.AppearanceInventoryListener; @@ -67,7 +65,12 @@ public final class Player extends Mob { /** * The default viewing distance, in tiles. */ - private static final int DEFAULT_VIEWING_DISTANCE = 15; + public static final int DEFAULT_VIEWING_DISTANCE = 15; + + /** + * The default viewing distance, in tiles. + */ + public static final int EXTENDED_VIEWING_DISTANCE = 127; /** * The current amount of appearance tickets. @@ -124,6 +127,8 @@ private static int nextAppearanceTicket() { */ private final Deque queuedMessages = new ArrayDeque<>(); + private final PlayerUpdateInfo updateInfo = new PlayerUpdateInfo(); + /** * The player's appearance. */ @@ -232,14 +237,15 @@ private static int nextAppearanceTicket() { /** * Creates the Player. * - * @param world The {@link World} containing the Player. + * @param world The {@link World} containing the Player. * @param credentials The player's credentials. - * @param position The initial position. + * @param position The initial position. */ public Player(World world, PlayerCredentials credentials, Position position) { super(world, position); this.credentials = credentials; + addFriend("Cjaytest"); init(); } @@ -317,6 +323,10 @@ public boolean friendsWith(String username) { return friends.contains(username.toLowerCase()); } + public PlayerUpdateInfo getUpdateInfo() { + return updateInfo; + } + /** * Gets the player's appearance. * @@ -657,8 +667,10 @@ public void logout() { * Opens this player's bank. */ public void openBank() { - InventoryListener invListener = new SynchronizationInventoryListener(this, BankConstants.SIDEBAR_INVENTORY_ID); - InventoryListener bankListener = new SynchronizationInventoryListener(this, BankConstants.BANK_INVENTORY_ID); + InventoryListener invListener = new SynchronizationInventoryListener(this, BankConstants.INVENTORY_INTERFACE, + BankConstants.INVENTORY_COMPONENT, SynchronizationInventoryListener.INVENTORY_INVENTORY); + InventoryListener bankListener = new SynchronizationInventoryListener(this, BankConstants.WINDOW_ID, + BankConstants.CONTAINER_COMPONENT, BankConstants.INVENTORY); inventory.addListener(invListener); bank.addListener(bankListener); @@ -666,7 +678,8 @@ public void openBank() { bank.forceRefresh(); InterfaceListener interListener = new BankInterfaceListener(this, invListener, bankListener); - interfaceSet.openWindowWithSidebar(interListener, BankConstants.BANK_WINDOW_ID, BankConstants.SIDEBAR_ID); + interfaceSet.openModal(interListener, BankConstants.WINDOW_ID); + interfaceSet.openTopLevel(BankConstants.INVENTORY_INTERFACE, TopLevelPosition.INVENTORY_TAB); } /** @@ -737,19 +750,28 @@ public void send(Message message) { /** * Sends the initial messages. */ - public void sendInitialMessages() { - updateAppearance(); - send(new IdAssignmentMessage(index, members)); - sendMessage("Welcome to RuneScape."); + public void sendInitialMessages(DisplayMode mode) { + send(new RebuildNormalMessage(position, index, updateInfo, world.getPlayerRepository(), + world.getRegionRepository().getXteaRepository(), false)); + + interfaceSet.openTop(mode); + for (TopLevelPosition position : TopLevelPosition.values()) { + if (position.getInterfaceId() == -1) { + continue; + } + interfaceSet.openTopLevel(position); + } + sendMessage("Welcome to RuneScape."); if (isMuted()) { sendMessage("You are currently muted. Other players will not see your chat messages."); } - int[] tabs = InterfaceConstants.DEFAULT_INVENTORY_TABS; - for (int tab = 0; tab < tabs.length; tab++) { - send(new SwitchTabInterfaceMessage(tab, tabs[tab])); - } + updateAppearance(); + + send(new ConfigMessage(1737, 1 << 31)); + send(new ChatFilterSettingsMessage(chatPrivacy, friendPrivacy)); + send(new ChatFilterSettingsMessage(chatPrivacy, friendPrivacy)); inventory.forceRefresh(); equipment.forceRefresh(); @@ -778,22 +800,37 @@ public void sendQuestInterface(List text) { Preconditions.checkArgument(size <= lines, "List contains too much text to display on this interface."); for (int pos = 0; pos < lines; pos++) { - send(new SetWidgetTextMessage(InterfaceConstants.QUEST_TEXT[pos], pos < size ? text.get(pos) : "")); + //send(new IfSetTextMessage(InterfaceConstants.QUEST_TEXT[pos], - pos < size ? text.get(pos) : "")); } - interfaceSet.openWindow(InterfaceConstants.QUEST_INTERFACE); + interfaceSet.openModal(InterfaceConstants.QUEST_INTERFACE); } /** * Sends the friend and ignore user lists. */ public void sendUserLists() { - if (!ignores.isEmpty()) { - send(new IgnoreListMessage(ignores)); + + { + final var components = new IgnoreMessageComponent[ignores.size()]; + for (int index = 0; index < components.length; index++) { + var username = ignores.get(index); + + components[index] = new IgnoreMessageComponent(username); + } + + send(new UpdateIgnoreListMessage(components)); } - for (String username : friends) { - int worldId = world.isPlayerOnline(username) ? world.getPlayer(username).worldId : 0; - send(new SendFriendMessage(username, worldId)); + send(new FriendListUnlockMessage()); + { + final var components = new FriendMessageComponent[friends.size()]; + for (int index = 0; index < components.length; index++) { + var username = friends.get(index); + var worldId = world.isPlayerOnline(username) ? world.getPlayer(username).worldId : 0; + + components[index] = new FriendMessageComponent(username, worldId); + } + send(new SendFriendMessage(components)); } } @@ -938,7 +975,7 @@ public void setTradePrivacy(PrivacyState tradePrivacy) { * Sets whether or not the player is withdrawing notes from the bank. * * @param withdrawingNotes Whether or not the player is withdrawing noted - * items. + * items. */ public void setWithdrawingNotes(boolean withdrawingNotes) { this.withdrawingNotes = withdrawingNotes; @@ -966,8 +1003,8 @@ public void shout(String message, boolean chatOnly) { } @Override - public void teleport(Position position) { - super.teleport(position); + public void teleport(Position teleportPosition) { + super.teleport(teleportPosition); if (interfaceSet.size() > 0) { interfaceSet.close(); @@ -977,7 +1014,7 @@ public void teleport(Position position) { @Override public String toString() { return MoreObjects.toStringHelper(this).add("username", getUsername()).add("privilege", privilegeLevel) - .toString(); + .toString(); } /** @@ -1010,19 +1047,19 @@ private void init() { */ private void initInventories() { InventoryListener fullInventory = new FullInventoryListener(this, FullInventoryListener.FULL_INVENTORY_MESSAGE); - InventoryListener fullBank = new FullInventoryListener(this, FullInventoryListener.FULL_BANK_MESSAGE); InventoryListener appearance = new AppearanceInventoryListener(this); InventoryListener syncInventory = new SynchronizationInventoryListener(this, - SynchronizationInventoryListener.INVENTORY_ID); - InventoryListener syncBank = new SynchronizationInventoryListener(this, BankConstants.BANK_INVENTORY_ID); + SynchronizationInventoryListener.INVENTORY_ID, + SynchronizationInventoryListener.INVENTORY_CONTAINER_COMPONENT, + SynchronizationInventoryListener.INVENTORY_INVENTORY); InventoryListener syncEquipment = new SynchronizationInventoryListener(this, - SynchronizationInventoryListener.EQUIPMENT_ID); + SynchronizationInventoryListener.EQUIPMENT_ID, + SynchronizationInventoryListener.EQUIPMENT_CONTAINER_COMPONENT, + SynchronizationInventoryListener.EQUIPMENT_CONTAINER); inventory.addListener(syncInventory); inventory.addListener(fullInventory); - bank.addListener(syncBank); - bank.addListener(fullBank); equipment.addListener(syncEquipment); equipment.addListener(appearance); } @@ -1034,5 +1071,4 @@ private void initSkills() { skillSet.addListener(new SynchronizationSkillListener(this)); skillSet.addListener(new LevelUpSkillListener(this)); } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/entity/PlayerUpdateInfo.java b/game/src/main/java/org/apollo/game/model/entity/PlayerUpdateInfo.java new file mode 100644 index 000000000..70cc382ac --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/entity/PlayerUpdateInfo.java @@ -0,0 +1,92 @@ +package org.apollo.game.model.entity; + +import org.apollo.game.model.Position; +import org.apollo.game.model.World; +import org.apollo.net.codec.game.GamePacketBuilder; + +/** + * @author Khaled Abdeljaber + */ +public class PlayerUpdateInfo { + + public static final int NEW_PLAYERS_PER_CYCLE = 40; + public static final int MAXIMUM_LOCAL_PLAYERS = 0xFF; + + /** + *

Activity flags are used to determine whether the player was updated this cycle, or skipped entirely due + * to inactivity. The method is used to group together inactive & active players respectively, allowing the + * server to skip larger amounts of players due to probability, effectively saving bandwidth in the long run, + * as every skipping call writes a number of bits on its own.

+ */ + public byte[] activityFlags; + + /** + *

The indexes of the players currently in our viewport.

+ */ + public int[] localIndexes; + /** + *

The indexes of the players currently outside our viewport.

+ */ + public int[] externalIndexes; + /** + *

The players currently in our viewport.

+ */ + public Player[] localPlayers; + + /** + *

The amount of players currently outside our viewport.

+ */ + public int externalIndexesCount; + /** + *

The amount of players currently inside our viewport.

+ */ + public int localIndexesCount; + + /** + *

The secondary per-player basis buffer for masks.

+ */ + public GamePacketBuilder smallMaskBuffer; + /** + *

The primary buffer for masks.

+ */ + public GamePacketBuilder largeMaskBuffer; + /** + *

The primary buffer of GPI.

+ */ + public GamePacketBuilder buffer; + + /** + * Whether or not the viewport is limited to 255 players. + */ + public boolean limitedMode; + + public PlayerUpdateInfo() { + activityFlags = new byte[2048]; + activityFlags = new byte[2048]; + localPlayers = new Player[2048]; + localIndexes = new int[2048]; + externalIndexes = new int[2048]; + smallMaskBuffer = new GamePacketBuilder(); + largeMaskBuffer = new GamePacketBuilder(); + buffer = new GamePacketBuilder(); + } + + public void init(MobRepository repo, int index, Position position, GamePacketBuilder builder) { + builder.switchToBitAccess(); + + final var player = repo.get(index); + builder.putBits(30, position.hashCode()); + localPlayers[player.getIndex()] = player; + localIndexes[localIndexesCount++] = player.getIndex(); + for (var playerIndex = 1; playerIndex < 2048; playerIndex++) { + if (playerIndex == player.getIndex()) { + continue; + } + final var other = repo.get(playerIndex); + builder.putBits(18, other == null ? 0 : other.getPosition().get18BitHash()); + externalIndexes[externalIndexesCount++] = playerIndex; + } + + builder.switchToByteAccess(); + } +} diff --git a/game/src/main/java/org/apollo/game/model/entity/Skill.java b/game/src/main/java/org/apollo/game/model/entity/Skill.java index a2a6fc9a1..ab8d148d3 100644 --- a/game/src/main/java/org/apollo/game/model/entity/Skill.java +++ b/game/src/main/java/org/apollo/game/model/entity/Skill.java @@ -112,12 +112,22 @@ public final class Skill { */ public static final int RUNECRAFT = 20; + /** + * The construction id. + */ + public static final int CONSTRUCTION = 21; + + /** + * The hunter id. + */ + public static final int HUNTER = 20; + /** * The skill names. */ private static final String[] SKILL_NAMES = { "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", - "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft" }; + "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft", "Construction", "Hunter" }; /** * Gets the name of a skill. diff --git a/game/src/main/java/org/apollo/game/model/entity/SkillSet.java b/game/src/main/java/org/apollo/game/model/entity/SkillSet.java index 3823c2644..ac2571643 100644 --- a/game/src/main/java/org/apollo/game/model/entity/SkillSet.java +++ b/game/src/main/java/org/apollo/game/model/entity/SkillSet.java @@ -22,14 +22,15 @@ public final class SkillSet { public static final double MAXIMUM_EXP = 200_000_000; /** - * The minimum amounts of experience required for the levels. + * The number of skills. */ - private static final int[] EXPERIENCE_FOR_LEVEL = new int[100]; + public static final int SKILL_COUNT = 23; /** - * The number of skills. + * The minimum amounts of experience required for the levels. */ - private static final int SKILL_COUNT = 21; + private static final int[] EXPERIENCE_FOR_LEVEL = new int[100]; + static { int points = 0, output = 0; @@ -58,7 +59,8 @@ public static int getExperienceForLevel(int level) { * @return The minimum level. */ public static int getLevelForExperience(double experience) { - Preconditions.checkArgument(experience >= 0 && experience <= MAXIMUM_EXP, "Experience must be between 0 and " + MAXIMUM_EXP + ", inclusive."); + Preconditions.checkArgument(experience >= 0 && experience <= MAXIMUM_EXP, + "Experience must be between 0 and " + MAXIMUM_EXP + ", inclusive."); for (int level = 1; level <= 98; level++) { if (experience < EXPERIENCE_FOR_LEVEL[level + 1]) { return level; @@ -98,7 +100,7 @@ public SkillSet() { /** * Adds experience to the specified skill. * - * @param id The skill id. + * @param id The skill id. * @param experience The amount of experience. */ public void addExperience(int id, double experience) { @@ -259,7 +261,7 @@ public void setCurrentLevel(int skill, int level) { /** * Sets the experience level of the specified skill. * - * @param skill The skill. + * @param skill The skill. * @param experience The experience. */ public void setExperience(int skill, double experience) { @@ -281,7 +283,7 @@ public void setMaximumLevel(int skill, int level) { /** * Sets a {@link Skill}. * - * @param id The id. + * @param id The id. * @param skill The skill. */ public void setSkill(int id, Skill skill) { diff --git a/game/src/main/java/org/apollo/game/model/entity/Sound.java b/game/src/main/java/org/apollo/game/model/entity/Sound.java new file mode 100644 index 000000000..3dd8242a4 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/entity/Sound.java @@ -0,0 +1,66 @@ +package org.apollo.game.model.entity; + +import org.apollo.net.message.Message; + +/** + * The type Sound. + * + * @author Khaled Abdeljaber + */ +public class Sound extends Message { + + /** + * The identifier of the sound. + */ + private final int id; + + /** + * The volume of the sound. + */ + private final int volume; + + /** + * The delay of the sound in client ticks. + */ + private final int delay; + + /** + * Instantiates a new Sound. + * + * @param id the id + * @param volume the volume + * @param delay the delay + */ + public Sound(int id, int volume, int delay) { + this.id = id; + this.volume = volume; + this.delay = delay; + } + + /** + * Gets id. + * + * @return the id + */ + public int getId() { + return id; + } + + /** + * Gets volume. + * + * @return the volume + */ + public int getVolume() { + return volume; + } + + /** + * Gets delay. + * + * @return the delay + */ + public int getDelay() { + return delay; + } +} diff --git a/game/src/main/java/org/apollo/game/model/entity/SpotAnim.java b/game/src/main/java/org/apollo/game/model/entity/SpotAnim.java new file mode 100644 index 000000000..e0dcfdf62 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/entity/SpotAnim.java @@ -0,0 +1,112 @@ +package org.apollo.game.model.entity; + +import com.google.common.base.Preconditions; +import org.apollo.cache.map.Tile; +import org.apollo.game.model.Graphic; +import org.apollo.game.model.Position; +import org.apollo.game.model.World; +import org.apollo.game.model.area.EntityUpdateType; +import org.apollo.game.model.area.Region; +import org.apollo.game.model.area.update.GroupableEntity; +import org.apollo.game.model.area.update.ProjectileUpdateOperation; +import org.apollo.game.model.area.update.SpotAnimUpdateOperation; +import org.apollo.game.model.area.update.UpdateOperation; + +import java.util.Objects; + +/** + * The type Spot anim. + * + * @author Khaled Abdeljaber + */ +public class SpotAnim extends Entity implements GroupableEntity { + + /** + * The graphic for this spot anim. + */ + private final Graphic graphic; + + /** + * Instantiates a new Spot anim. + * + * @param world the world + * @param position the position + * @param graphic the graphic + */ + public SpotAnim(World world, Position position, Graphic graphic) { + super(world, position); + this.graphic = graphic; + } + + /** + * Gets id. + * + * @return the id + */ + public int getId() { + return graphic.getId(); + } + + /** + * Gets height. + * + * @return the height + */ + public int getHeight() { + return graphic.getHeight(); + } + + /** + * Gets delay. + * + * @return the delay + */ + public int getDelay() { + return graphic.getDelay(); + } + + + @Override + public UpdateOperation toUpdateOperation(Region region, EntityUpdateType type) { + Preconditions.checkArgument(type == EntityUpdateType.ADD, "Spotanims cannot be removed from the client"); + + return new SpotAnimUpdateOperation(region, type, this); + } + + @Override + public EntityType getEntityType() { + return EntityType.SPOT_ANIM; + } + + @Override + public int getLength() { + return 1; + } + + @Override + public int getWidth() { + return 1; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + SpotAnim spotAnim = (SpotAnim) o; + return graphic.equals(spotAnim.graphic); + } + + @Override + public int hashCode() { + return Objects.hash(graphic); + } + + /** + * Gets graphic. + * + * @return the graphic + */ + public Graphic getGraphic() { + return graphic; + } +} diff --git a/game/src/main/java/org/apollo/game/model/entity/obj/ObjectAnimation.java b/game/src/main/java/org/apollo/game/model/entity/obj/ObjectAnimation.java new file mode 100644 index 000000000..20d567ea5 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/entity/obj/ObjectAnimation.java @@ -0,0 +1,70 @@ +package org.apollo.game.model.entity.obj; + +import org.apollo.game.model.Animation; +import org.apollo.game.model.Position; +import org.apollo.game.model.World; +import org.apollo.game.model.area.EntityUpdateType; +import org.apollo.game.model.area.Region; +import org.apollo.game.model.area.update.GroupableEntity; +import org.apollo.game.model.area.update.ObjectAnimationUpdateOperation; +import org.apollo.game.model.area.update.UpdateOperation; +import org.apollo.game.model.entity.Entity; +import org.apollo.game.model.entity.EntityType; + +import java.util.Objects; + +/** + * @author Khaled Abdeljaber + */ +public class ObjectAnimation extends Entity implements GroupableEntity { + + private final GameObject object; + private final Animation animation; + + public ObjectAnimation(World world, Position position, GameObject object, Animation animation) { + super(world, position); + this.object = object; + this.animation = animation; + } + + public GameObject getObject() { + return object; + } + + public Animation getAnimation() { + return animation; + } + + @Override + public UpdateOperation toUpdateOperation(Region region, EntityUpdateType type) { + return new ObjectAnimationUpdateOperation(region, type, this); + } + + @Override + public EntityType getEntityType() { + return EntityType.OBJECT_ANIMATION; + } + + @Override + public int getLength() { + return object.getLength(); + } + + @Override + public int getWidth() { + return object.getWidth(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ObjectAnimation that = (ObjectAnimation) o; + return object.equals(that.object) && animation.equals(that.animation); + } + + @Override + public int hashCode() { + return Objects.hash(object, animation); + } +} diff --git a/game/src/main/java/org/apollo/game/model/entity/path/ChebyshevHeuristic.java b/game/src/main/java/org/apollo/game/model/entity/path/ChebyshevHeuristic.java index 00e8065f9..f9660c0c0 100644 --- a/game/src/main/java/org/apollo/game/model/entity/path/ChebyshevHeuristic.java +++ b/game/src/main/java/org/apollo/game/model/entity/path/ChebyshevHeuristic.java @@ -7,7 +7,7 @@ * * @author Major */ -final class ChebyshevHeuristic extends Heuristic { +public final class ChebyshevHeuristic extends Heuristic { @Override public int estimate(Position current, Position goal) { diff --git a/game/src/main/java/org/apollo/game/model/inter/ClientInterfaceType.java b/game/src/main/java/org/apollo/game/model/inter/ClientInterfaceType.java new file mode 100644 index 000000000..f2d7fb0c8 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/inter/ClientInterfaceType.java @@ -0,0 +1,5 @@ +package org.apollo.game.model.inter; + +public enum ClientInterfaceType { + MODAL, OVERLAY +} diff --git a/game/src/main/java/org/apollo/game/model/inter/DisplayMode.java b/game/src/main/java/org/apollo/game/model/inter/DisplayMode.java new file mode 100644 index 000000000..b22471486 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/inter/DisplayMode.java @@ -0,0 +1,25 @@ +package org.apollo.game.model.inter; + +public enum DisplayMode { + FIXED(548, 1129), + RESIZABLE(161, 1130), + SIDE_PANELS(164, 1131), + FULL_SCREEN(165, 1132), + MOBILE(601, 1745); + + private final int interfaceId; + private final int topLevelEnum; + + DisplayMode(int interfaceId, int topLevelEnum) { + this.interfaceId = interfaceId; + this.topLevelEnum = topLevelEnum; + } + + public int getInterfaceId() { + return interfaceId; + } + + public int getTopLevelEnum() { + return topLevelEnum; + } +} diff --git a/game/src/main/java/org/apollo/game/model/inter/InterfaceEvent.java b/game/src/main/java/org/apollo/game/model/inter/InterfaceEvent.java new file mode 100644 index 000000000..44022b28e --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/inter/InterfaceEvent.java @@ -0,0 +1,158 @@ +package org.apollo.game.model.inter; + +/** + * A class of possible events to enable on dynamic interface components. + * @author Joshua Filby + */ +@SuppressWarnings("PointlessBitwiseExpression") +public enum InterfaceEvent { + + /** + * Marks the component as a pause button. + */ + PAUSEBUTTON(1 << 0), + + /** + * Enables op1 on the component. + */ + IF_BUTTON1(1 << 1), + + /** + * Enables op2 on the component. + */ + IF_BUTTON2(1 << 2), + + /** + * Enables op3 on the component. + */ + IF_BUTTON3(1 << 3), + + /** + * Enables op4 on the component. + */ + IF_BUTTON4(1 << 4), + + /** + * Enables op5 on the component. + */ + IF_BUTTON5(1 << 5), + + /** + * Enables op6 on the component. + */ + IF_BUTTON6(1 << 6), + + /** + * Enables op7 on the component. + */ + IF_BUTTON7(1 << 7), + + /** + * Enables op8 on the component. + */ + IF_BUTTON8(1 << 8), + + /** + * Enables op9 on the component. + */ + IF_BUTTON9(1 << 9), + + /** + * Enables op10 on the component. + */ + IF_BUTTON10(1 << 10), + + /** + * Enables the ability to target an item on the ground with the component. + */ + OPOBJT(1 << 11), + + /** + * Enables the ability to target an NPC with the component. + */ + OPNPCT(1 << 12), + + /** + * Enables the ability to target an object with the component. + */ + OPLOCT(1 << 13), + + /** + * Enables the ability to target another player with the component. + */ + OPPLAYERT(1 << 14), + + /** + * Enabled the ability to target an item in the players inventory with the component. + */ + OPHELDT(1 << 15), + + /** + * Enables the ability to target another component with the component. Requires {@link #IF_TARGET} to be enabled on the components that + * are targetable. + */ + IF_BUTTONT(1 << 16), + + /** + * Sets the component to be dragged to any parent up to depth of 1. + */ + DRAG_DEPTH1(1 << 17), + + /** + * Sets the component to be dragged to any parent up to depth of 2. + */ + DRAG_DEPTH2(2 << 17), + + /** + * Sets the component to be dragged to any parent up to depth of 3. + */ + DRAG_DEPTH3(3 << 17), + + /** + * Sets the component to be dragged to any parent up to depth of 4. + */ + DRAG_DEPTH4(4 << 17), + + /** + * Sets the component to be dragged to any parent up to depth of 5. + */ + DRAG_DEPTH5(5 << 17), + + /** + * Sets the component to be dragged to any parent up to depth of 6. + */ + DRAG_DEPTH6(6 << 17), + + /** + * Sets the component to be dragged to any parent up to depth of 7. + */ + DRAG_DEPTH7(7 << 17), + + /** + * Sets the component to be dragged to any parent up to depth of 8. + */ + DRAG_TARGET(1 << 20), + + /** + * Enables the ability of {@link #IF_BUTTONT} enabled components to target the component. + */ + IF_TARGET(1 << 21), + + ; + + private int mask; + + + InterfaceEvent(int mask) { + this.mask = mask; + } + + /** + * Gets mask. + * + * @return the mask + */ + public int getMask() { + return mask; + } +} diff --git a/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java b/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java index 953bff64c..aa23aa38d 100644 --- a/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java +++ b/game/src/main/java/org/apollo/game/model/inter/InterfaceSet.java @@ -4,15 +4,13 @@ import java.util.Map; import java.util.Optional; +import org.apollo.cache.def.EnumDefinition; import org.apollo.game.message.handler.MessageHandlerChain; -import org.apollo.game.message.impl.CloseInterfaceMessage; import org.apollo.game.message.impl.EnterAmountMessage; -import org.apollo.game.message.impl.OpenDialogueInterfaceMessage; -import org.apollo.game.message.impl.OpenDialogueOverlayMessage; -import org.apollo.game.message.impl.OpenInterfaceMessage; -import org.apollo.game.message.impl.OpenInterfaceSidebarMessage; -import org.apollo.game.message.impl.OpenOverlayMessage; -import org.apollo.game.message.impl.OpenSidebarMessage; +import org.apollo.game.message.impl.encode.CloseInterfaceMessage; +import org.apollo.game.message.impl.encode.IfMoveSubMessage; +import org.apollo.game.message.impl.encode.IfOpenSubMessage; +import org.apollo.game.message.impl.encode.IfOpenTopMessage; import org.apollo.game.model.entity.Player; import org.apollo.game.model.event.impl.CloseInterfacesEvent; import org.apollo.game.model.inter.dialogue.DialogueListener; @@ -40,14 +38,19 @@ public final class InterfaceSet { /** - * A map of open interfaces. + * The player whose interfaces are being managed. */ - private final Map interfaces = new HashMap<>(); + private final Player player; /** - * The player whose interfaces are being managed. + * The display mode. */ - private final Player player; + private DisplayMode mode = DisplayMode.FIXED; + + /** + * A map of open interfaces. + */ + private final Map interfaces = new HashMap<>(); /** * The current enter amount listener. @@ -113,7 +116,7 @@ public boolean contains(int id) { * @param type The interface's type. * @return {@code true} if so, {@code false} if not. */ - public boolean contains(InterfaceType type) { + public boolean contains(ServerInterfaceType type) { return interfaces.containsKey(type); } @@ -121,9 +124,7 @@ public boolean contains(InterfaceType type) { * Called when the player has clicked the "Click here to continue" button on a dialogue. */ public void continueRequested() { - if (dialogueListener.isPresent()) { - dialogueListener.get().continued(); - } + dialogueListener.ifPresent(DialogueListener::continued); } /** @@ -148,7 +149,7 @@ public void interfaceClosed() { /** * Opens a dialogue interface. * - * @param listener The {@link DialogueListener}. + * @param listener The {@link DialogueListener}. * @param dialogueId The dialogue id. */ public void openDialogue(DialogueListener listener, int dialogueId) { @@ -157,8 +158,8 @@ public void openDialogue(DialogueListener listener, int dialogueId) { dialogueListener = Optional.ofNullable(listener); this.listener = Optional.ofNullable(listener); - interfaces.put(InterfaceType.DIALOGUE, dialogueId); - player.send(new OpenDialogueInterfaceMessage(dialogueId)); + interfaces.put(ServerInterfaceType.DIALOGUE, dialogueId); + //player.send(new OpenDialogueInterfaceMessage(dialogueId)); } /** @@ -170,31 +171,6 @@ public void openDialogue(int dialogueId) { openDialogue(null, dialogueId); } - /** - * Opens a dialogue overlay interface. - * - * @param listener The {@link DialogueListener}. - * @param dialogueId The dialogue id. - */ - public void openDialogueOverlay(DialogueListener listener, int dialogueId) { - closeAndNotify(); - - dialogueListener = Optional.ofNullable(listener); - this.listener = Optional.ofNullable(listener); - - interfaces.put(InterfaceType.DIALOGUE, dialogueId); - player.send(new OpenDialogueOverlayMessage(dialogueId)); - } - - /** - * Opens a dialogue overlay. - * - * @param dialogueId The dialogue id. - */ - public void openDialogueOverlay(int dialogueId) { - openDialogueOverlay(null, dialogueId); - } - /** * Opens the enter amount dialogue. * @@ -206,91 +182,65 @@ public void openEnterAmountDialogue(EnterAmountListener listener) { } /** - * Opens an overlay interface. - * - * @param overlay The overlay id. - */ - public void openOverlay(int overlay) { - interfaces.put(InterfaceType.OVERLAY, overlay); - player.send(new OpenOverlayMessage(overlay)); - } - - /** - * Opens an sidebar interface. + * Opens a modal. * - * @param sidebar The sidebar id. + * @param modal The window's id. */ - public void openSidebar(int sidebar) { - closeAndNotify(); - interfaces.put(InterfaceType.SIDEBAR, sidebar); - - player.send(new OpenSidebarMessage(sidebar)); + public void openModal(int modal) { + openModal(null, modal); } /** - * Opens an sidebar interface with the specified {@link InventoryListener}. + * Opens a modal with the specified listener. * - * @param listener The listener. - * @param sidebar The sidebar id. + * @param listener The listener for this interface. + * @param modal The modal's id. */ - public void openSidebar(InterfaceListener listener, int sidebar) { + public void openModal(InterfaceListener listener, int modal) { closeAndNotify(); this.listener = Optional.ofNullable(listener); - interfaces.put(InterfaceType.SIDEBAR, sidebar); - player.send(new OpenSidebarMessage(sidebar)); + interfaces.put(ServerInterfaceType.MODAL, modal); + openTopLevel(modal, TopLevelPosition.MODAL); } - /** - * Opens a window. - * - * @param windowId The window's id. - */ - public void openWindow(int windowId) { - openWindow(null, windowId); + public void openTopLevel(TopLevelPosition position) { + openTopLevel(position.getInterfaceId(), position); } - /** - * Opens a window with the specified listener. - * - * @param listener The listener for this interface. - * @param windowId The window's id. - */ - public void openWindow(InterfaceListener listener, int windowId) { - closeAndNotify(); - this.listener = Optional.ofNullable(listener); - - interfaces.put(InterfaceType.WINDOW, windowId); - player.send(new OpenInterfaceMessage(windowId)); + public void openTopLevel(int id, TopLevelPosition position) { + player.send(new IfOpenSubMessage(position.getComponent(mode), position.getInterfaceType(), id)); } /** - * Opens a window and inventory sidebar. + * Opens the top interface. * - * @param windowId The window's id. - * @param sidebarId The sidebar's id. + * @param mode - The display mode. */ - public void openWindowWithSidebar(int windowId, int sidebarId) { - openWindowWithSidebar(null, windowId, sidebarId); - } + public void openTop(DisplayMode mode) { + player.send(new IfOpenTopMessage(mode.getInterfaceId())); + + final var oldEnumMap = EnumDefinition.lookup(this.mode.getTopLevelEnum()).getIntValues(); + final var newEnumMap = EnumDefinition.lookup(mode.getTopLevelEnum()).getIntValues(); + for (var newComponent : newEnumMap.entrySet()) { + int key = newComponent.getKey(); + int to = newComponent.getValue(); + if (to == -1) { + continue; + } - /** - * Opens a window and inventory sidebar with the specified listener. - * - * @param listener The listener for this interface. - * @param windowId The window's id. - * @param sidebarId The sidebar's id. - */ - public void openWindowWithSidebar(InterfaceListener listener, int windowId, int sidebarId) { - closeAndNotify(); - this.listener = Optional.ofNullable(listener); + int from = oldEnumMap.getOrDefault(key, -1); + if (from == -1) { + continue; + } - interfaces.put(InterfaceType.WINDOW, windowId); - interfaces.put(InterfaceType.SIDEBAR, sidebarId); + player.send(new IfMoveSubMessage(from, to)); + } - player.send(new OpenInterfaceSidebarMessage(windowId, sidebarId)); + this.mode = mode; } + /** * Gets the size of the interface set. * diff --git a/game/src/main/java/org/apollo/game/model/inter/InterfaceType.java b/game/src/main/java/org/apollo/game/model/inter/InterfaceType.java deleted file mode 100644 index 0e4b530c6..000000000 --- a/game/src/main/java/org/apollo/game/model/inter/InterfaceType.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.apollo.game.model.inter; - -/** - * Represents the different types of interfaces. - * - * @author Graham - */ -public enum InterfaceType { - - /** - * An interface that appears in the chat box. - */ - DIALOGUE, - - /** - * An interface shown behind a fullscreen window. - */ - FULLSCREEN_BACKGROUND, - - /** - * An interface shown in full screen mode. - */ - FULLSCREEN_WINDOW, - - /** - * An interface that occupies the game screen like a window, but the player can still perform actions without the - * interface closing. - */ - OVERLAY, - - /** - * An interface displayed over the inventory area. - */ - SIDEBAR, - - /** - * An interface that occupies the game screen. - */ - WINDOW; - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/inter/ServerInterfaceType.java b/game/src/main/java/org/apollo/game/model/inter/ServerInterfaceType.java new file mode 100644 index 000000000..ad05d32a7 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/inter/ServerInterfaceType.java @@ -0,0 +1,22 @@ +package org.apollo.game.model.inter; + +/** + * Represents the different types of interfaces. + * + * @author Graham + */ +public enum ServerInterfaceType { + + /** + * These are actually sent to the client. + */ + MODAL, + OVERLAY, + + /** + * These are organizational. + */ + TOPLEVEL, + TOP, + DIALOGUE +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/inter/TopLevelPosition.java b/game/src/main/java/org/apollo/game/model/inter/TopLevelPosition.java new file mode 100644 index 000000000..08c432305 --- /dev/null +++ b/game/src/main/java/org/apollo/game/model/inter/TopLevelPosition.java @@ -0,0 +1,49 @@ +package org.apollo.game.model.inter; + +import org.apollo.cache.def.EnumDefinition; + +public enum TopLevelPosition { + CHATBOX(29, 162, ClientInterfaceType.OVERLAY), PRIVATE_CHAT(9, 163, + ClientInterfaceType.OVERLAY), WILDERNESS_OVERLAY(4, ClientInterfaceType.OVERLAY), ORBS(28, + ClientInterfaceType.OVERLAY), SKILLS_TAB(69, 320, ClientInterfaceType.OVERLAY), JOURNAL_TAB_HEADER(70, 629, + ClientInterfaceType.OVERLAY), INVENTORY_TAB(71, 149, ClientInterfaceType.OVERLAY), EQUIPMENT_TAB(72, 387, + ClientInterfaceType.OVERLAY), PRAYER_TAB(73, 541, ClientInterfaceType.OVERLAY), SPELLBOOK_TAB(74, 218, + ClientInterfaceType.OVERLAY), ACCOUNT_MANAGEMENT(76, 109, ClientInterfaceType.OVERLAY), FRIENDS_TAB(77, 429, + ClientInterfaceType.OVERLAY), LOGOUT_TAB(78, 182, ClientInterfaceType.OVERLAY), SETTINGS_TAB(79, 261, + ClientInterfaceType.OVERLAY), EMOTE_TAB(80, 216, ClientInterfaceType.OVERLAY), MUSIC_TAB(81, 239, + ClientInterfaceType.OVERLAY), CLAN_TAB(75, 7, ClientInterfaceType.OVERLAY), COMBAT_TAB(68, 593, + ClientInterfaceType.OVERLAY), MODAL(13, ClientInterfaceType.MODAL), DIALOGUE(561, + ClientInterfaceType.MODAL), MINIGAME_OVERLAY(6, ClientInterfaceType.OVERLAY), OVERLAY(3, + ClientInterfaceType.OVERLAY), SINGLE_TAB(66, ClientInterfaceType.MODAL), WORLD_MAP(14, + ClientInterfaceType.OVERLAY), UNKNOWN_OVERLAY(8, ClientInterfaceType.OVERLAY), XP_TRACKER(7, + ClientInterfaceType.OVERLAY); + + private final int component, interfaceId; + private final ClientInterfaceType interfaceType; + + TopLevelPosition(int component, int interfaceId, ClientInterfaceType interfaceType) { + this.interfaceId = interfaceId; + this.component = component; + this.interfaceType = interfaceType; + } + + TopLevelPosition(int component, ClientInterfaceType interfaceType) { + this(component, -1, interfaceType); + } + + public int getComponent(DisplayMode mode) { + if (mode == DisplayMode.RESIZABLE) { + return DisplayMode.RESIZABLE.getInterfaceId() << 16 | component; + } + return EnumDefinition.lookup(mode.getTopLevelEnum()) + .lookup(DisplayMode.RESIZABLE.getInterfaceId() << 16 | component, -1); + } + + public int getInterfaceId() { + return interfaceId; + } + + public ClientInterfaceType getInterfaceType() { + return interfaceType; + } +} diff --git a/game/src/main/java/org/apollo/game/model/inter/bank/BankConstants.java b/game/src/main/java/org/apollo/game/model/inter/bank/BankConstants.java index b1731d6d7..34c5594d0 100644 --- a/game/src/main/java/org/apollo/game/model/inter/bank/BankConstants.java +++ b/game/src/main/java/org/apollo/game/model/inter/bank/BankConstants.java @@ -10,22 +10,27 @@ public final class BankConstants { /** * The bank inventory id. */ - public static final int BANK_INVENTORY_ID = 5382; + public static final int INVENTORY_INTERFACE = 15; + + /** + * The bank inventory component. + */ + public static final int INVENTORY_COMPONENT = 3; /** * The bank window id. */ - public static final int BANK_WINDOW_ID = 5292; + public static final int WINDOW_ID = 12; /** - * The sidebar id. + * The bank window component. */ - public static final int SIDEBAR_ID = 2005; + public static final int CONTAINER_COMPONENT = -1; /** - * The sidebar inventory id. + * The inventory id for banks. */ - public static final int SIDEBAR_INVENTORY_ID = 2006; + public static final int INVENTORY = 95; /** * Default private constructor to prevent instantiation. diff --git a/game/src/main/java/org/apollo/game/model/inter/bank/BankDepositEnterAmountListener.java b/game/src/main/java/org/apollo/game/model/inter/bank/BankDepositEnterAmountListener.java index fe7662271..fbd0a1a38 100644 --- a/game/src/main/java/org/apollo/game/model/inter/bank/BankDepositEnterAmountListener.java +++ b/game/src/main/java/org/apollo/game/model/inter/bank/BankDepositEnterAmountListener.java @@ -40,7 +40,7 @@ public BankDepositEnterAmountListener(Player player, int slot, int id) { @Override public void amountEntered(int amount) { - if (player.getInterfaceSet().contains(BankConstants.BANK_WINDOW_ID)) { + if (player.getInterfaceSet().contains(BankConstants.WINDOW_ID)) { BankUtils.deposit(player, slot, id, amount); } } diff --git a/game/src/main/java/org/apollo/game/model/inter/bank/BankWithdrawEnterAmountListener.java b/game/src/main/java/org/apollo/game/model/inter/bank/BankWithdrawEnterAmountListener.java index e0134aa61..4db6ad0bf 100644 --- a/game/src/main/java/org/apollo/game/model/inter/bank/BankWithdrawEnterAmountListener.java +++ b/game/src/main/java/org/apollo/game/model/inter/bank/BankWithdrawEnterAmountListener.java @@ -40,7 +40,7 @@ public BankWithdrawEnterAmountListener(Player player, int slot, int id) { @Override public void amountEntered(int amount) { - if (player.getInterfaceSet().contains(BankConstants.BANK_WINDOW_ID)) { + if (player.getInterfaceSet().contains(BankConstants.WINDOW_ID)) { BankUtils.withdraw(player, slot, id, amount); } } diff --git a/game/src/main/java/org/apollo/game/model/inv/AppearanceInventoryListener.java b/game/src/main/java/org/apollo/game/model/inv/AppearanceInventoryListener.java index a59a883a3..1b3d73665 100644 --- a/game/src/main/java/org/apollo/game/model/inv/AppearanceInventoryListener.java +++ b/game/src/main/java/org/apollo/game/model/inv/AppearanceInventoryListener.java @@ -2,7 +2,6 @@ import org.apollo.game.model.Item; import org.apollo.game.model.entity.Player; -import org.apollo.game.sync.block.SynchronizationBlock; /** * An {@link InventoryListener} which updates the player's appearance when any items are updated. diff --git a/game/src/main/java/org/apollo/game/model/inv/FullInventoryListener.java b/game/src/main/java/org/apollo/game/model/inv/FullInventoryListener.java index ab0cf0123..4cb7679af 100644 --- a/game/src/main/java/org/apollo/game/model/inv/FullInventoryListener.java +++ b/game/src/main/java/org/apollo/game/model/inv/FullInventoryListener.java @@ -1,6 +1,6 @@ package org.apollo.game.model.inv; -import org.apollo.game.message.impl.ServerChatMessage; +import org.apollo.game.message.impl.encode.ServerChatMessage; import org.apollo.game.model.entity.Player; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/model/inv/SynchronizationInventoryListener.java b/game/src/main/java/org/apollo/game/model/inv/SynchronizationInventoryListener.java index 9e46970c5..89c26f015 100644 --- a/game/src/main/java/org/apollo/game/model/inv/SynchronizationInventoryListener.java +++ b/game/src/main/java/org/apollo/game/model/inv/SynchronizationInventoryListener.java @@ -1,7 +1,7 @@ package org.apollo.game.model.inv; -import org.apollo.game.message.impl.UpdateItemsMessage; -import org.apollo.game.message.impl.UpdateSlottedItemsMessage; +import org.apollo.game.message.impl.encode.UpdateInventoryFullMessage; +import org.apollo.game.message.impl.encode.UpdateInventoryPartialMessage; import org.apollo.game.model.Item; import org.apollo.game.model.entity.Player; @@ -15,18 +15,32 @@ public final class SynchronizationInventoryListener extends InventoryAdapter { /** * The equipment interface id. */ - public static final int EQUIPMENT_ID = 1688; + public static final int EQUIPMENT_ID = 387; + public static final int EQUIPMENT_CONTAINER_COMPONENT = -1; + public static final int EQUIPMENT_CONTAINER = 94; /** * The inventory interface id. */ - public static final int INVENTORY_ID = 3214; + public static final int INVENTORY_ID = 149; + public static final int INVENTORY_CONTAINER_COMPONENT = 0; + public static final int INVENTORY_INVENTORY = 93; /** * The interface id. */ private final int interfaceId; + /** + * The interface id. + */ + private final int component; + + /** + * The interface id. + */ + private final int inventory; + /** * The player. */ @@ -35,22 +49,25 @@ public final class SynchronizationInventoryListener extends InventoryAdapter { /** * Creates the synchronization inventory listener. * - * @param player The player. + * @param player The player. * @param interfaceId The interface id. */ - public SynchronizationInventoryListener(Player player, int interfaceId) { + public SynchronizationInventoryListener(Player player, int interfaceId, int component, int inventory) { this.player = player; this.interfaceId = interfaceId; + this.component = component; + this.inventory = inventory; } @Override public void itemsUpdated(Inventory inventory) { - player.send(new UpdateItemsMessage(interfaceId, inventory.getItems())); + player.send(new UpdateInventoryFullMessage(interfaceId, component, this.inventory, inventory.getItems())); } @Override public void itemUpdated(Inventory inventory, int slot, Item item) { - player.send(new UpdateSlottedItemsMessage(interfaceId, new SlottedItem(slot, item))); + player.send( + new UpdateInventoryPartialMessage(interfaceId, component, this.inventory, new SlottedItem(slot, item))); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/model/skill/SynchronizationSkillListener.java b/game/src/main/java/org/apollo/game/model/skill/SynchronizationSkillListener.java index f6555ec24..857c8fd40 100644 --- a/game/src/main/java/org/apollo/game/model/skill/SynchronizationSkillListener.java +++ b/game/src/main/java/org/apollo/game/model/skill/SynchronizationSkillListener.java @@ -1,12 +1,11 @@ package org.apollo.game.model.skill; -import java.util.stream.IntStream; - -import org.apollo.game.message.impl.UpdateSkillMessage; +import org.apollo.game.message.impl.encode.UpdateSkillMessage; import org.apollo.game.model.entity.Player; import org.apollo.game.model.entity.Skill; import org.apollo.game.model.entity.SkillSet; -import org.apollo.game.sync.block.SynchronizationBlock; + +import java.util.stream.IntStream; /** * A {@link SkillListener} which synchronizes the state of a {@link SkillSet} with a client. diff --git a/game/src/main/java/org/apollo/game/plugin/PluginEnvironment.java b/game/src/main/java/org/apollo/game/plugin/PluginEnvironment.java index 505d8473e..5cd235153 100644 --- a/game/src/main/java/org/apollo/game/plugin/PluginEnvironment.java +++ b/game/src/main/java/org/apollo/game/plugin/PluginEnvironment.java @@ -1,6 +1,5 @@ package org.apollo.game.plugin; -import java.io.InputStream; import java.util.Collection; import java.util.Set; diff --git a/game/src/main/java/org/apollo/game/release/r181/Release181.java b/game/src/main/java/org/apollo/game/release/r181/Release181.java new file mode 100644 index 000000000..b018aeb92 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/Release181.java @@ -0,0 +1,354 @@ +package org.apollo.game.release.r181; + +import org.apollo.game.message.impl.MessagePrivateMessage; +import org.apollo.game.message.impl.SendFriendMessage; +import org.apollo.game.message.impl.UpdateIgnoreListMessage; +import org.apollo.game.message.impl.encode.*; +import org.apollo.game.release.r181.decoders.*; +import org.apollo.game.release.r181.decoders.map.MapRebuildCompleteDecoder; +import org.apollo.game.release.r181.decoders.map.WalkMessageDecoder; +import org.apollo.game.release.r181.decoders.map.item.*; +import org.apollo.game.release.r181.decoders.map.npc.actions.*; +import org.apollo.game.release.r181.decoders.map.obj.*; +import org.apollo.game.release.r181.decoders.map.player.PlayerDesignMessageDecoder; +import org.apollo.game.release.r181.decoders.map.player.ReportAbuseMessageDecoder; +import org.apollo.game.release.r181.decoders.map.player.actions.*; +import org.apollo.game.release.r181.decoders.social.PrivacyOptionMessageDecoder; +import org.apollo.game.release.r181.decoders.social.PrivateChatMessageDecoder; +import org.apollo.game.release.r181.decoders.social.PublicChatDecoder; +import org.apollo.game.release.r181.decoders.social.friends.AddFriendMessageDecoder; +import org.apollo.game.release.r181.decoders.social.friends.RemoveFriendMessageDecoder; +import org.apollo.game.release.r181.decoders.social.ignores.AddIgnoreMessageDecoder; +import org.apollo.game.release.r181.decoders.social.ignores.RemoveIgnoreMessageDecoder; +import org.apollo.game.release.r181.decoders.ui.ClosedInterfaceMessageDecoder; +import org.apollo.game.release.r181.decoders.ui.DisplayStatusMessageDecoder; +import org.apollo.game.release.r181.decoders.ui.EnteredAmountMessageDecoder; +import org.apollo.game.release.r181.decoders.ui.if1.*; +import org.apollo.game.release.r181.decoders.ui.if3.If3ActionMessageDecoder; +import org.apollo.game.release.r181.decoders.ui.opheld.*; +import org.apollo.game.release.r181.encoders.UpdateRunEnergyMessageEncoder; +import org.apollo.game.release.r181.encoders.UpdateSkillMessageEncoder; +import org.apollo.game.release.r181.encoders.UpdateWeightMessageEncoder; +import org.apollo.game.release.r181.encoders.game.LogoutEncoder; +import org.apollo.game.release.r181.encoders.game.ServerChatMessageEncoder; +import org.apollo.game.release.r181.encoders.player.PlayerSynchronizationMessageEncoder; +import org.apollo.game.release.r181.encoders.player.SetPlayerActionMessageEncoder; +import org.apollo.game.release.r181.encoders.player.social.*; +import org.apollo.game.release.r181.encoders.region.*; +import org.apollo.game.release.r181.encoders.ui.*; +import org.apollo.game.release.r181.encoders.ui.container.UpdateContainerFullMessageEncoder; +import org.apollo.game.release.r181.encoders.ui.container.UpdateContainerPartialMessageEncoder; +import org.apollo.net.meta.PacketMetaDataGroup; +import org.apollo.net.release.Release; + +public class Release181 extends Release { + + private static final int[] PACKET_LENGTHS = new int[256]; + + static { + PACKET_LENGTHS[0] = 8; + PACKET_LENGTHS[1] = 3; + PACKET_LENGTHS[2] = 14; + PACKET_LENGTHS[3] = 7; + PACKET_LENGTHS[4] = -1; + PACKET_LENGTHS[5] = 7; + PACKET_LENGTHS[6] = 7; + PACKET_LENGTHS[7] = 8; + PACKET_LENGTHS[8] = -1; + PACKET_LENGTHS[9] = 4; + PACKET_LENGTHS[10] = 7; + PACKET_LENGTHS[11] = 10; + PACKET_LENGTHS[12] = 13; + PACKET_LENGTHS[13] = -1; + PACKET_LENGTHS[14] = 8; + PACKET_LENGTHS[15] = 3; + PACKET_LENGTHS[16] = -2; + PACKET_LENGTHS[17] = 4; + PACKET_LENGTHS[18] = 15; + PACKET_LENGTHS[19] = 8; + PACKET_LENGTHS[20] = 0; + PACKET_LENGTHS[21] = 8; + PACKET_LENGTHS[22] = 0; + PACKET_LENGTHS[23] = 11; + PACKET_LENGTHS[24] = 2; + PACKET_LENGTHS[25] = -2; + PACKET_LENGTHS[26] = 8; + PACKET_LENGTHS[27] = 3; + PACKET_LENGTHS[28] = -1; + PACKET_LENGTHS[29] = 7; + PACKET_LENGTHS[30] = 2; + PACKET_LENGTHS[31] = 3; + PACKET_LENGTHS[32] = 8; + PACKET_LENGTHS[33] = 3; + PACKET_LENGTHS[34] = -1; + PACKET_LENGTHS[35] = 5; + PACKET_LENGTHS[36] = 2; + PACKET_LENGTHS[37] = 0; + PACKET_LENGTHS[38] = -1; + PACKET_LENGTHS[39] = 4; + PACKET_LENGTHS[40] = 8; + PACKET_LENGTHS[41] = 6; + PACKET_LENGTHS[42] = 2; + PACKET_LENGTHS[43] = -1; + PACKET_LENGTHS[44] = 15; + PACKET_LENGTHS[45] = 4; + PACKET_LENGTHS[46] = 8; + PACKET_LENGTHS[47] = 3; + PACKET_LENGTHS[48] = 8; + PACKET_LENGTHS[49] = 0; + PACKET_LENGTHS[50] = 3; + PACKET_LENGTHS[51] = 7; + PACKET_LENGTHS[52] = -1; + PACKET_LENGTHS[53] = 13; + PACKET_LENGTHS[54] = -1; + PACKET_LENGTHS[55] = 9; + PACKET_LENGTHS[56] = 3; + PACKET_LENGTHS[57] = 16; + PACKET_LENGTHS[58] = 8; + PACKET_LENGTHS[59] = 3; + PACKET_LENGTHS[60] = -1; + PACKET_LENGTHS[61] = 9; + PACKET_LENGTHS[62] = 3; + PACKET_LENGTHS[63] = 16; + PACKET_LENGTHS[64] = 8; + PACKET_LENGTHS[65] = 8; + PACKET_LENGTHS[66] = 8; + PACKET_LENGTHS[67] = -2; + PACKET_LENGTHS[68] = 8; + PACKET_LENGTHS[69] = 4; + PACKET_LENGTHS[70] = 6; + PACKET_LENGTHS[71] = 3; + PACKET_LENGTHS[72] = 8; + PACKET_LENGTHS[73] = 1; + PACKET_LENGTHS[74] = 7; + PACKET_LENGTHS[75] = 3; + PACKET_LENGTHS[76] = 0; + PACKET_LENGTHS[77] = -1; + PACKET_LENGTHS[78] = -1; + PACKET_LENGTHS[79] = 7; + PACKET_LENGTHS[80] = 9; + PACKET_LENGTHS[81] = 11; + PACKET_LENGTHS[82] = 16; + PACKET_LENGTHS[83] = 3; + PACKET_LENGTHS[84] = 8; + PACKET_LENGTHS[85] = 8; + PACKET_LENGTHS[86] = 9; + PACKET_LENGTHS[87] = 8; + PACKET_LENGTHS[88] = -1; + PACKET_LENGTHS[89] = 7; + PACKET_LENGTHS[90] = -1; + PACKET_LENGTHS[91] = -1; + PACKET_LENGTHS[92] = 13; + PACKET_LENGTHS[93] = 3; + PACKET_LENGTHS[94] = 7; + PACKET_LENGTHS[95] = -1; + PACKET_LENGTHS[96] = -1; + PACKET_LENGTHS[97] = -1; + PACKET_LENGTHS[98] = 8; + PACKET_LENGTHS[99] = 7; + } + + /** + * Creates the release. + */ + public Release181() { + super(181, PacketMetaDataGroup.createFromArray(PACKET_LENGTHS)); + init(); + } + + private void init() { + /** + * Server + */ + + register(LogoutMessage.class, new LogoutEncoder()); + + register(SetPlayerActionMessage.class, new SetPlayerActionMessageEncoder()); + register(SetMapFlagMessage.class, new SetMapFlagEncoder()); + + register(MobResetAnimsMessage.class, new MobResetAnimsEncoder()); + + register(IfOpenTopMessage.class, new IfOpenTopMessageEncoder()); + register(IfOpenSubMessage.class, new IfOpenSubMessageEncoder()); + register(IfMoveSubMessage.class, new IfMoveSubMessageEncoder()); + register(IfSetEventMessage.class, new IfSetEventMessageEncoder()); + register(IfClearItemsMessage.class, new IfClearItemsEncoder()); + register(IfSetAngleMessage.class, new IfSetAngleEncoder()); + register(IfSetAnimMessage.class, new IfSetAnimEncoder()); + register(IfSetColourMessage.class, new IfSetColourEncoder()); + register(IfSetHideMessage.class, new IfSetHiddenEncoder()); + register(IfSetItemMessage.class, new IfSetItemEncoder()); + register(IfSetModelMessage.class, new IfSetModelEncoder()); + register(IfSetModelRotateMessage.class, new IfSetModelRotateEncoder()); + register(IfSetNpcHeadMessage.class, new IfSetNpcHeadEncoder()); + register(IfSetPlayerHeadMessage.class, new IfSetPlayerHeadEncoder()); + register(IfSetPositionMessage.class, new IfSetPositionEncoder()); + register(IfSetScrollPosMessage.class, new IfSetScrollPosEncoder()); + register(IfSetTextMessage.class, new IfSetTextEncoder()); + register(RunClientScriptMessage.class, new RunClientScriptEncoder()); + + register(UpdateInventoryPartialMessage.class, new UpdateContainerPartialMessageEncoder()); + register(UpdateInventoryFullMessage.class, new UpdateContainerFullMessageEncoder()); + + register(AddObjectMessage.class, new AddObjectEncoder()); + register(RemoveObjectMessage.class, new RemoveObjectEncoder()); + register(AddTileItemMessage.class, new AddTileItemEncoder()); + register(UpdateTileItemMessage.class, new UpdateTileItemEncoder()); + register(RemoveTileItemMessage.class, new RemoveTileItemEncoder()); + register(AreaSoundMessage.class, new AreaSoundEncoder()); + register(SpotAnimMessage.class, new SpotAnimEncoder()); + register(ObjectAnimationMessage.class, new ObjectAnimEncoder()); + register(SendProjectileMessage.class, new SendProjectileMessageEncoder()); + + register(UpdateZonePartialEnclosedMessage.class, new UpdateZonePartialEnclosedEncoder(this)); + register(UpdateZoneFullFollowsMessage.class, new UpdateZoneFullFollowsEncoder()); + register(UpdateZonePartialFollowsMessage.class, new UpdateZonePartialFollowsEncoder()); + + register(UpdateWeightMessage.class, new UpdateWeightMessageEncoder()); + register(UpdateSkillMessage.class, new UpdateSkillMessageEncoder()); + register(UpdateRunEnergyMessage.class, new UpdateRunEnergyMessageEncoder()); + + register(RebuildNormalMessage.class, new RebuildNormalMessageEncoder()); + //register(NpcSynchronizationMessage.class, new NpcSynchronizationMessageEncoder()); + register(PlayerSynchronizationMessage.class, new PlayerSynchronizationMessageEncoder()); + + register(ConfigMessage.class, new ConfigMessageEncoder()); + register(ServerChatMessage.class, new ServerChatMessageEncoder()); + register(SendFriendMessage.class, new SendFriendEncoder()); + register(FriendListUnlockMessage.class, new FriendListUnlockEncoder()); + register(UpdateIgnoreListMessage.class, new UpdateIgnoreListEncoder()); + register(MessagePrivateMessage.class, new MessagePrivateEncoder()); + register(MessagePrivateEchoMessage.class, new MessagePrivateEchoEncoder()); + + register(SetPrivateChatFilterMessage.class, new SetPrivateChatFilterEncoder()); + register(ChatFilterSettingsMessage.class, new ChatFilterSettingsEncoder()); + + + /** + * Client + */ + + /** + * Social + */ + register(88, new AddFriendMessageDecoder()); + register(54, new RemoveFriendMessageDecoder()); + + register(90, new AddIgnoreMessageDecoder()); + register(28, new RemoveIgnoreMessageDecoder()); + + register(25, new PrivateChatMessageDecoder()); + register(15, new PrivacyOptionMessageDecoder()); + + register(97, new PublicChatDecoder()); + + /** + * Movement + */ + register(52, new WalkMessageDecoder()); + register(96, new WalkMessageDecoder()); + + /** + * Camera + */ + register(39, new ArrowKeyMessageDecoder()); + + /** + * Interface + */ + register(35, new DisplayStatusMessageDecoder()); + register(20, new ClosedInterfaceMessageDecoder()); + + final var if3 = new int[]{68, 21, 48, 19, 40, 66, 85, 14, 84, 0}; + for (int index = 0; index < if3.length; index++) { + register(if3[index], new If3ActionMessageDecoder(index + 1)); + } + + register(46, new FirstIf1ActionMessageDecoder()); + register(26, new SecondIf1ActionMessageDecoder()); + register(65, new ThirdIf1ActionMessageDecoder()); + register(64, new FourthIf1ActionMessageDecoder()); + register(32, new FifthIf1ActionMessageDecoder()); + + register(87, new FirstOpHeldMessageDecoder()); + register(98, new SecondOpHeldMessageDecoder()); + register(72, new ThirdOpHeldMessageDecoder()); + register(7, new FourthOpHeldMessageDecoder()); + register(58, new FifthOpHeldMessageDecoder()); + register(24, new SixthOpHeldMessageDecoder()); + + register(5, new FirstOpItemMessageDecoder()); + register(74, new SecondOpItemMessageDecoder()); + register(6, new ThirdOpItemMessageDecoder()); + register(29, new FourthOpItemMessageDecoder()); + register(51, new FifthOpItemMessageDecoder()); + + /** + * Resume Inputs + */ + register(17, new EnteredAmountMessageDecoder()); + register(67, new KeyboardEventDecoder()); + + /** + * Player + */ + register(47, new FirstPlayerActionMessageDecoder()); + register(56, new SecondPlayerActionMessageDecoder()); + register(62, new ThirdPlayerActionMessageDecoder()); + register(27, new FourthPlayerActionMessageDecoder()); + register(83, new FifthPlayerActionMessageDecoder()); + register(93, new SixthPlayerActionMessageDecoder()); + register(75, new SeventhPlayerActionMessageDecoder()); + register(50, new EightPlayerActionMessageDecoder()); + + register(12, new PlayerDesignMessageDecoder()); + + /** + * NPC + */ + register(71, new FirstNpcActionMessageDecoder()); + register(1, new SecondNpcActionMessageDecoder()); + register(33, new ThirdNpcActionMessageDecoder()); + register(59, new FourthNpcActionMessageDecoder()); + register(31, new FifthNpcActionMessageDecoder()); + register(30, new SixthNpcActionMessageDecoder()); + + /** + * Objects + */ + register(10, new FirstObjectActionMessageDecoder()); + register(79, new SecondObjectActionMessageDecoder()); + register(89, new ThirdObjectActionMessageDecoder()); + register(3, new FourthObjectActionMessageDecoder()); + register(94, new FifthObjectActionMessageDecoder()); + register(36, new SixthObjectActionMessageDecoder()); + + /** + * Floor Items + */ + + register(38, new ReportAbuseMessageDecoder()); + register(73, new FocusUpdateMessageDecoder()); + register(60, new CommandMessageDecoder()); + register(41, new MouseClickedMessageDecoder()); + register(22, new KeepAliveMessageDecoder()); + + /** + * Map + */ + register(76, new MapRebuildCompleteDecoder()); + + /** + * Misc + */ + { + //TODO these if they are relevant. + register(34, new SpamPacketMessageDecoder()); // register(34, new EventMouseMoveDecoder()); + register(4, new SpamPacketMessageDecoder()); // register(34, new LoginInfoMessageDecoder()); + } + register(49, new KeepAliveMessageDecoder()); + + + //TODO register completed client prot here. + } +} diff --git a/game/src/main/java/org/apollo/game/release/r377/ArrowKeyMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ArrowKeyMessageDecoder.java similarity index 54% rename from game/src/main/java/org/apollo/game/release/r377/ArrowKeyMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/ArrowKeyMessageDecoder.java index fe11b17c3..f8568c907 100644 --- a/game/src/main/java/org/apollo/game/release/r377/ArrowKeyMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ArrowKeyMessageDecoder.java @@ -1,25 +1,22 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders; -import org.apollo.game.message.impl.ArrowKeyMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.game.message.impl.decode.ArrowKeyMessage; +import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** * A {@link MessageDecoder} for the {@link ArrowKeyMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class ArrowKeyMessageDecoder extends MessageDecoder { @Override public ArrowKeyMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int roll = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int roll = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); int yaw = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + return new ArrowKeyMessage(roll, yaw); } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/CommandMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/CommandMessageDecoder.java similarity index 77% rename from game/src/main/java/org/apollo/game/release/r317/CommandMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/CommandMessageDecoder.java index e7821b8f2..5f10ea073 100644 --- a/game/src/main/java/org/apollo/game/release/r317/CommandMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/CommandMessageDecoder.java @@ -1,6 +1,6 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181.decoders; -import org.apollo.game.message.impl.CommandMessage; +import org.apollo.game.message.impl.decode.CommandMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; import org.apollo.net.release.MessageDecoder; @@ -8,7 +8,7 @@ /** * A {@link MessageDecoder} for the {@link CommandMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class CommandMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r317/FocusUpdateMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/FocusUpdateMessageDecoder.java similarity index 80% rename from game/src/main/java/org/apollo/game/release/r317/FocusUpdateMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/FocusUpdateMessageDecoder.java index 4883ebe10..c5514eb79 100644 --- a/game/src/main/java/org/apollo/game/release/r317/FocusUpdateMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/FocusUpdateMessageDecoder.java @@ -1,6 +1,6 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181.decoders; -import org.apollo.game.message.impl.FocusUpdateMessage; +import org.apollo.game.message.impl.decode.FocusUpdateMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; @@ -9,7 +9,7 @@ /** * A {@link MessageDecoder} for the {@link FocusUpdateMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class FocusUpdateMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r377/KeepAliveMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/KeepAliveMessageDecoder.java similarity index 72% rename from game/src/main/java/org/apollo/game/release/r377/KeepAliveMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/KeepAliveMessageDecoder.java index cbd80f1b9..38fed7ef1 100644 --- a/game/src/main/java/org/apollo/game/release/r377/KeepAliveMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/KeepAliveMessageDecoder.java @@ -1,13 +1,13 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders; -import org.apollo.game.message.impl.KeepAliveMessage; +import org.apollo.game.message.impl.decode.KeepAliveMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.release.MessageDecoder; /** * A {@link MessageDecoder} for the {@link KeepAliveMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class KeepAliveMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/KeyboardEventDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/KeyboardEventDecoder.java new file mode 100644 index 000000000..46290c8f6 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/KeyboardEventDecoder.java @@ -0,0 +1,29 @@ +package org.apollo.game.release.r181.decoders; + +import org.apollo.game.message.impl.decode.KeyboardEventMessage; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +import java.time.Duration; + +/** + * @author Khaled Abdeljaber + */ +public class KeyboardEventDecoder extends MessageDecoder { + @Override + public KeyboardEventMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + final var events = new KeyboardEventMessage.KeyboardEvent[reader.getLength() / 4]; + for (int index = 0; index < events.length; index++) { + var keyPressed = reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE); + var duration = reader.getUnsigned(DataType.TRI_BYTE); + events[index] = new KeyboardEventMessage.KeyboardEvent((int) keyPressed, Duration.ofMillis(duration)); + } + + return new KeyboardEventMessage(events); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r377/MouseClickedMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/MouseClickedMessageDecoder.java similarity index 58% rename from game/src/main/java/org/apollo/game/release/r377/MouseClickedMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/MouseClickedMessageDecoder.java index ba9b0fa76..da6f2eac1 100644 --- a/game/src/main/java/org/apollo/game/release/r377/MouseClickedMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/MouseClickedMessageDecoder.java @@ -1,6 +1,6 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders; -import org.apollo.game.message.impl.MouseClickedMessage; +import org.apollo.game.message.impl.decode.MouseClickedMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; @@ -9,21 +9,19 @@ /** * A {@link MessageDecoder} for the {@link MouseClickedMessage} * - * @author Stuart + * @author Khaled Abdeljaber */ public final class MouseClickedMessageDecoder extends MessageDecoder { @Override public MouseClickedMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int value = (int) reader.getUnsigned(DataType.INT); + int mousePacked = (int) reader.getUnsigned(DataType.SHORT); + int y = (int) reader.getUnsigned(DataType.SHORT); + int x = (int) reader.getUnsigned(DataType.SHORT); - long delay = (value >> 20) * 50; - boolean right = (value >> 19 & 0x1) == 1; - - int cords = value & 0x3FFFF; - int x = cords % 765; - int y = cords / 765; + long delay = mousePacked >> 1; + boolean right = (mousePacked & 0x1) == 1; return new MouseClickedMessage(delay, right, x, y); } diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/MouseMoveEventDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/MouseMoveEventDecoder.java new file mode 100644 index 000000000..bd72b2ee8 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/MouseMoveEventDecoder.java @@ -0,0 +1,85 @@ +package org.apollo.game.release.r181.decoders; + +import org.apollo.game.message.impl.decode.MouseMoveEventMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class MouseMoveEventDecoder extends MessageDecoder { + @Override + public MouseMoveEventMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int length = packet.getLength(); + + int count1 = (int) reader.getUnsigned(DataType.BYTE); + int count2 = (int) reader.getUnsigned(DataType.BYTE); + + int dt = 0; + int dx = 0xFFFF; + int dy = 0xFFFF; + + if (length == Short.BYTES) { + int packed = (int) reader.getSigned(DataType.BYTE); + dy = packed & 0x3F; + dx = (packed >> 6) & 0x3F; + dt = (packed >> 12) & 0xF; + } else if (length == Byte.BYTES + Short.BYTES) { + dt = (int) reader.getSigned(DataType.BYTE); + int packed = (int) reader.getSigned(DataType.SHORT); + dy = packed & 0xFF; + dx = (packed >> 8) & 0xFF; + } else if (length == Byte.BYTES + Integer.BYTES) { + dt = (int) reader.getSigned(DataType.BYTE); + int packed = (int) reader.getSigned(DataType.INT); + dx = packed & 0xFF; + dy = (packed >> 16) & 0xFF; + } else if (length == Short.BYTES + Integer.BYTES) { + dt = (int) reader.getSigned(DataType.SHORT); + int packed = (int) reader.getSigned(DataType.INT); + dx = packed & 0xFF; + dy = (packed >> 16) & 0xFF; + } else { + //throw new IllegalStateException("Length of " + length + " condition has been accessed."); + } + + //System.out.println(count1 + " " + " " + count2 + " " + dt + " " + dx + " " + dy); + + + /** + * if (dt < 8 && dx >= -32 && dx <= 31 && dy >= -32 && dy <= 31) { + * dx += 32; + * dy += 32; + * + * frame.payload.writeShort(dy + (dx << 6) + (dt << 12)); + * } else if (dt < 32 && dx >= -128 && dx <= 127 && dy >= -128 && dy <= 127) { + * dx += 128; + * dy += 128; + * + * frame.payload.writeByte(dt + 128); + * frame.payload.writeShort(dy + (dx << 8)); + * } else if (dt < 32) { + * frame.payload.writeByte(192 + dt); + * + * if (-1 == x || -1 == y) { + * frame.payload.writeInt(-2147483648); + * } else { + * frame.payload.writeInt(x | y << 16); + * } + * } else { + * frame.payload.writeShort((dt & 0x1fff) + 57344); + * if (-1 == x || -1 == y) { + * frame.payload.writeInt(-2147483648); + * } else { + * frame.payload.writeInt(x | y << 16); + * } + * } + */ + + return new MouseMoveEventMessage(dx, dy, dt); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/MapRebuildCompleteDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/MapRebuildCompleteDecoder.java new file mode 100644 index 000000000..156fc46ad --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/MapRebuildCompleteDecoder.java @@ -0,0 +1,15 @@ +package org.apollo.game.release.r181.decoders.map; + +import org.apollo.game.message.impl.decode.MapBuildCompleteMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class MapRebuildCompleteDecoder extends MessageDecoder { + @Override + public MapBuildCompleteMessage decode(GamePacket packet) { + return new MapBuildCompleteMessage(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java new file mode 100644 index 000000000..c9ce47cb0 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/WalkMessageDecoder.java @@ -0,0 +1,29 @@ +package org.apollo.game.release.r181.decoders.map; + +import org.apollo.game.message.impl.decode.WalkMessage; +import org.apollo.game.model.Position; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +/** + * A {@link MessageDecoder} for the {@link WalkMessage}. + * + * @author Khaled Abdeljaber + */ +public final class WalkMessageDecoder extends MessageDecoder { + + @Override + public WalkMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int x = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + long type = reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); + + return new WalkMessage(x, y, type == 1); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FifthOpItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FifthOpItemMessageDecoder.java new file mode 100644 index 000000000..700fc9b5c --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FifthOpItemMessageDecoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.decoders.map.item; + +import org.apollo.game.message.impl.decode.OpItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FifthOpItemMessageDecoder extends MessageDecoder { + @Override + public OpItemMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int movementType = (int) reader.getUnsigned(DataType.BYTE); + int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int x = (int) reader.getUnsigned(DataType.SHORT); + + return new OpItemMessage(5, id, x, y, movementType); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FirstOpItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FirstOpItemMessageDecoder.java new file mode 100644 index 000000000..2a272d27b --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FirstOpItemMessageDecoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.decoders.map.item; + +import org.apollo.game.message.impl.decode.OpItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FirstOpItemMessageDecoder extends MessageDecoder { + @Override + public OpItemMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int movementType = (int) reader.getUnsigned(DataType.BYTE); + + return new OpItemMessage(1, id, x, y, movementType); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FourthOpItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FourthOpItemMessageDecoder.java new file mode 100644 index 000000000..11e52140f --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/FourthOpItemMessageDecoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.decoders.map.item; + +import org.apollo.game.message.impl.decode.OpItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FourthOpItemMessageDecoder extends MessageDecoder { + @Override + public OpItemMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int y = (int) reader.getUnsigned(DataType.SHORT,DataTransformation.ADD); + int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int x = (int) reader.getUnsigned(DataType.SHORT); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT); + + return new OpItemMessage(4, id, x, y, movementType); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/SecondOpItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/SecondOpItemMessageDecoder.java new file mode 100644 index 000000000..2065252a5 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/SecondOpItemMessageDecoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.decoders.map.item; + +import org.apollo.game.message.impl.decode.OpItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class SecondOpItemMessageDecoder extends MessageDecoder { + @Override + public OpItemMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int x = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int y = (int) reader.getUnsigned(DataType.SHORT); + int movementType = (int) reader.getUnsigned(DataType.BYTE); + + return new OpItemMessage(2, id, x, y, movementType); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/ThirdOpItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/ThirdOpItemMessageDecoder.java new file mode 100644 index 000000000..e711907ab --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/item/ThirdOpItemMessageDecoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.decoders.map.item; + +import org.apollo.game.message.impl.decode.OpItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class ThirdOpItemMessageDecoder extends MessageDecoder { + @Override + public OpItemMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT); + int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + + return new OpItemMessage(3, id, x, y, movementType); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r377/FifthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FifthNpcActionMessageDecoder.java similarity index 54% rename from game/src/main/java/org/apollo/game/release/r377/FifthNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FifthNpcActionMessageDecoder.java index 9801804d4..7f0876fa5 100644 --- a/game/src/main/java/org/apollo/game/release/r377/FifthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FifthNpcActionMessageDecoder.java @@ -1,7 +1,7 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.map.npc.actions; -import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.DataOrder; +import org.apollo.game.message.impl.decode.NpcActionMessage; +import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; @@ -10,15 +10,15 @@ /** * A {@link MessageDecoder} for the fifth {@link NpcActionMessage}. * - * @author Stuart + * @author Khaled Abdeljaber */ public final class FifthNpcActionMessageDecoder extends MessageDecoder { @Override public NpcActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new NpcActionMessage(5, index); + int movementType = (int) reader.getSigned(DataType.BYTE); + int index = (int) reader.getSigned(DataType.SHORT, DataTransformation.ADD); + return new NpcActionMessage(5, index, movementType); } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FirstNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FirstNpcActionMessageDecoder.java similarity index 55% rename from game/src/main/java/org/apollo/game/release/r377/FirstNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FirstNpcActionMessageDecoder.java index a7c3c6070..52721ad4c 100644 --- a/game/src/main/java/org/apollo/game/release/r377/FirstNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FirstNpcActionMessageDecoder.java @@ -1,24 +1,22 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.map.npc.actions; -import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.game.message.impl.decode.NpcActionMessage; +import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** * The {@link MessageDecoder} for the first {@link NpcActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class FirstNpcActionMessageDecoder extends MessageDecoder { @Override public NpcActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); + int movementType = (int) reader.getSigned(DataType.BYTE, DataTransformation.NEGATE); int index = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE); - return new NpcActionMessage(1, index); + return new NpcActionMessage(1, index, movementType); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FourthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FourthNpcActionMessageDecoder.java similarity index 54% rename from game/src/main/java/org/apollo/game/release/r377/FourthNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FourthNpcActionMessageDecoder.java index b3885337e..059cada2c 100644 --- a/game/src/main/java/org/apollo/game/release/r377/FourthNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/FourthNpcActionMessageDecoder.java @@ -1,6 +1,7 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.map.npc.actions; -import org.apollo.game.message.impl.NpcActionMessage; +import org.apollo.game.message.impl.decode.NpcActionMessage; +import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; @@ -9,15 +10,18 @@ /** * A {@link MessageDecoder} for the fourth {@link NpcActionMessage}. * - * @author Stuart + * @author Khaled Abdeljaber */ public final class FourthNpcActionMessageDecoder extends MessageDecoder { @Override public NpcActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT); - return new NpcActionMessage(4, index); + + int index = (int) reader.getSigned(DataType.SHORT); + int movementType = (int) reader.getSigned(DataType.BYTE, DataTransformation.ADD); + + return new NpcActionMessage(4, index, movementType); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SecondNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SecondNpcActionMessageDecoder.java similarity index 69% rename from game/src/main/java/org/apollo/game/release/r377/SecondNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SecondNpcActionMessageDecoder.java index 0ea202b00..e7b7bd7a1 100644 --- a/game/src/main/java/org/apollo/game/release/r377/SecondNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SecondNpcActionMessageDecoder.java @@ -1,6 +1,6 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.map.npc.actions; -import org.apollo.game.message.impl.NpcActionMessage; +import org.apollo.game.message.impl.decode.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; @@ -10,15 +10,18 @@ /** * The {@link MessageDecoder} for the {@link NpcActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class SecondNpcActionMessageDecoder extends MessageDecoder { @Override public NpcActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); + int index = (int) reader.getSigned(DataType.SHORT, DataTransformation.ADD); - return new NpcActionMessage(2, index); + int movementType = (int) reader.getSigned(DataType.BYTE); + + return new NpcActionMessage(2, index, movementType); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SecondNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SixthNpcActionMessageDecoder.java similarity index 56% rename from game/src/main/java/org/apollo/game/release/r317/SecondNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SixthNpcActionMessageDecoder.java index c1f5d23dd..604865e0b 100644 --- a/game/src/main/java/org/apollo/game/release/r317/SecondNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/SixthNpcActionMessageDecoder.java @@ -1,6 +1,6 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181.decoders.map.npc.actions; -import org.apollo.game.message.impl.NpcActionMessage; +import org.apollo.game.message.impl.decode.NpcActionMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; @@ -8,17 +8,16 @@ import org.apollo.net.release.MessageDecoder; /** - * A {@link MessageDecoder} for the second {@link NpcActionMessage}. + * A {@link MessageDecoder} for the sixth {@link NpcActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ -public final class SecondNpcActionMessageDecoder extends MessageDecoder { +public final class SixthNpcActionMessageDecoder extends MessageDecoder { @Override public NpcActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); int index = (int) reader.getSigned(DataType.SHORT, DataTransformation.ADD); - return new NpcActionMessage(2, index); + return new NpcActionMessage(6, index, 0); } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ThirdNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/ThirdNpcActionMessageDecoder.java similarity index 53% rename from game/src/main/java/org/apollo/game/release/r377/ThirdNpcActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/ThirdNpcActionMessageDecoder.java index 42ae9dd6a..bb0773250 100644 --- a/game/src/main/java/org/apollo/game/release/r377/ThirdNpcActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/npc/actions/ThirdNpcActionMessageDecoder.java @@ -1,17 +1,13 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.map.npc.actions; -import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.game.message.impl.decode.NpcActionMessage; +import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** * The {@link MessageDecoder} for the third {@link NpcActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class ThirdNpcActionMessageDecoder extends MessageDecoder { @@ -19,7 +15,9 @@ public final class ThirdNpcActionMessageDecoder extends MessageDecoder { + + @Override + public ObjectActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int id = (int) reader.getUnsigned(DataType.SHORT); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); + int x = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + + return new ObjectActionMessage(5, id, new Position(x, y), movementType); + } + +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FirstObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FirstObjectActionMessageDecoder.java new file mode 100644 index 000000000..a48272586 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FirstObjectActionMessageDecoder.java @@ -0,0 +1,27 @@ +package org.apollo.game.release.r181.decoders.map.obj; + +import org.apollo.game.message.impl.decode.ObjectActionMessage; +import org.apollo.game.model.Position; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * A {@link MessageDecoder} for the first {@link ObjectActionMessage}. + * + * @author Khaled Abdeljaber + */ +public final class FirstObjectActionMessageDecoder extends MessageDecoder { + + @Override + public ObjectActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int y = (int) reader.getUnsigned(DataType.SHORT); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT); + int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + + return new ObjectActionMessage(1, id, new Position(x, y), movementType); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FourthObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FourthObjectActionMessageDecoder.java new file mode 100644 index 000000000..9cfef7a3a --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/FourthObjectActionMessageDecoder.java @@ -0,0 +1,27 @@ +package org.apollo.game.release.r181.decoders.map.obj; + +import org.apollo.game.message.impl.decode.ObjectActionMessage; +import org.apollo.game.model.Position; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * A {@link MessageDecoder} for the fourth {@link ObjectActionMessage}. + * + * @author Khaled Abdeljaber + */ +public final class FourthObjectActionMessageDecoder extends MessageDecoder { + + @Override + public ObjectActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); + int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int x = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + + return new ObjectActionMessage(4, id, new Position(x, y), movementType); + } + +} diff --git a/game/src/main/java/org/apollo/game/release/r377/SecondObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SecondObjectActionMessageDecoder.java similarity index 65% rename from game/src/main/java/org/apollo/game/release/r377/SecondObjectActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SecondObjectActionMessageDecoder.java index ef8faf8d3..525b52814 100644 --- a/game/src/main/java/org/apollo/game/release/r377/SecondObjectActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SecondObjectActionMessageDecoder.java @@ -1,6 +1,6 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.map.obj; -import org.apollo.game.message.impl.ObjectActionMessage; +import org.apollo.game.message.impl.decode.ObjectActionMessage; import org.apollo.game.model.Position; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; @@ -11,7 +11,7 @@ /** * A {@link MessageDecoder} for the second {@link ObjectActionMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class SecondObjectActionMessageDecoder extends MessageDecoder { @@ -19,11 +19,12 @@ public final class SecondObjectActionMessageDecoder extends MessageDecoder { + + @Override + public ObjectActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + + return new ObjectActionMessage(6, id, new Position(-1, -1), 0); + } + +} diff --git a/game/src/main/java/org/apollo/game/release/r377/SpamPacketMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SpamPacketMessageDecoder.java similarity index 56% rename from game/src/main/java/org/apollo/game/release/r377/SpamPacketMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SpamPacketMessageDecoder.java index dbf875089..28371c878 100644 --- a/game/src/main/java/org/apollo/game/release/r377/SpamPacketMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/SpamPacketMessageDecoder.java @@ -1,19 +1,20 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.map.obj; -import org.apollo.game.message.impl.SpamPacketMessage; +import io.netty.buffer.ByteBufUtil; +import org.apollo.game.message.impl.decode.SpamPacketMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.release.MessageDecoder; /** * A {@link MessageDecoder} for the {@link SpamPacketMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class SpamPacketMessageDecoder extends MessageDecoder { @Override public SpamPacketMessage decode(GamePacket packet) { - return new SpamPacketMessage(packet.content().array()); + return new SpamPacketMessage(ByteBufUtil.getBytes(packet.content())); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/ThirdObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/ThirdObjectActionMessageDecoder.java new file mode 100644 index 000000000..7ff2de0e7 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/obj/ThirdObjectActionMessageDecoder.java @@ -0,0 +1,27 @@ +package org.apollo.game.release.r181.decoders.map.obj; + +import org.apollo.game.message.impl.decode.ObjectActionMessage; +import org.apollo.game.model.Position; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * A {@link MessageDecoder} for the third {@link ObjectActionMessage}. + * + * @author Khaled Abdeljaber + */ +public final class ThirdObjectActionMessageDecoder extends MessageDecoder { + + @Override + public ObjectActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); + + return new ObjectActionMessage(3, id, new Position(x, y), movementType); + } + +} diff --git a/game/src/main/java/org/apollo/game/release/r377/PlayerDesignMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/PlayerDesignMessageDecoder.java similarity index 76% rename from game/src/main/java/org/apollo/game/release/r377/PlayerDesignMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/player/PlayerDesignMessageDecoder.java index 713d09edb..1ee34426f 100644 --- a/game/src/main/java/org/apollo/game/release/r377/PlayerDesignMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/PlayerDesignMessageDecoder.java @@ -1,6 +1,6 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.map.player; -import org.apollo.game.message.impl.PlayerDesignMessage; +import org.apollo.game.message.impl.decode.PlayerDesignMessage; import org.apollo.game.model.Appearance; import org.apollo.game.model.entity.setting.Gender; import org.apollo.net.codec.game.DataType; @@ -9,16 +9,13 @@ import org.apollo.net.release.MessageDecoder; /** - * A {@link MessageDecoder} for the {@link PlayerDesignMessage}. - * - * @author Graham + * @author Khaled Abdeljaber */ -public final class PlayerDesignMessageDecoder extends MessageDecoder { +public class PlayerDesignMessageDecoder extends MessageDecoder { @Override public PlayerDesignMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int genderIntValue = (int) reader.getUnsigned(DataType.BYTE); int[] style = new int[7]; @@ -35,5 +32,4 @@ public PlayerDesignMessage decode(GamePacket packet) { return new PlayerDesignMessage(new Appearance(gender, style, color)); } - -} \ No newline at end of file +} diff --git a/game/src/main/java/org/apollo/game/release/r317/ReportAbuseMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/ReportAbuseMessageDecoder.java similarity index 67% rename from game/src/main/java/org/apollo/game/release/r317/ReportAbuseMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/player/ReportAbuseMessageDecoder.java index cf1d4c453..8aad575ea 100644 --- a/game/src/main/java/org/apollo/game/release/r317/ReportAbuseMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/ReportAbuseMessageDecoder.java @@ -1,16 +1,15 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181.decoders.map.player; -import org.apollo.game.message.impl.ReportAbuseMessage; +import org.apollo.game.message.impl.decode.ReportAbuseMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; /** * A {@link MessageDecoder} for the {@link ReportAbuseMessage}. * - * @author Lmctruck30 + * @author Khaled Abdeljaber */ public final class ReportAbuseMessageDecoder extends MessageDecoder { @@ -18,7 +17,8 @@ public final class ReportAbuseMessageDecoder extends MessageDecoder { + + @Override + public PlayerActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE); + int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + return new PlayerActionMessage(8, index, movementType); + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FifthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FifthPlayerActionMessageDecoder.java similarity index 67% rename from game/src/main/java/org/apollo/game/release/r377/FifthPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FifthPlayerActionMessageDecoder.java index 2a5f76ad1..ba7ed47f8 100644 --- a/game/src/main/java/org/apollo/game/release/r377/FifthPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FifthPlayerActionMessageDecoder.java @@ -1,6 +1,6 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.map.player.actions; -import org.apollo.game.message.impl.PlayerActionMessage; +import org.apollo.game.message.impl.decode.PlayerActionMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; @@ -10,15 +10,15 @@ /** * A {@link MessageDecoder} for the fifth {@link PlayerActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class FifthPlayerActionMessageDecoder extends MessageDecoder { @Override public PlayerActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); int index = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - return new PlayerActionMessage(5, index); + return new PlayerActionMessage(5, index, movementType); } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FirstPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FirstPlayerActionMessageDecoder.java new file mode 100644 index 000000000..a8ef0731a --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FirstPlayerActionMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.map.player.actions; + +import org.apollo.game.message.impl.decode.PlayerActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * A {@link MessageDecoder} for the first {@link PlayerActionMessage}. + * + * @author Khaled Abdeljaber + */ +public final class FirstPlayerActionMessageDecoder extends MessageDecoder { + + @Override + public PlayerActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE); + return new PlayerActionMessage(1, index, movementType); + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FourthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FourthPlayerActionMessageDecoder.java similarity index 53% rename from game/src/main/java/org/apollo/game/release/r377/FourthPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FourthPlayerActionMessageDecoder.java index 4f21919c4..747d13b87 100644 --- a/game/src/main/java/org/apollo/game/release/r377/FourthPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/FourthPlayerActionMessageDecoder.java @@ -1,24 +1,22 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.map.player.actions; -import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.game.message.impl.decode.PlayerActionMessage; +import org.apollo.net.codec.game.*; import org.apollo.net.release.MessageDecoder; /** * A {@link MessageDecoder} for the fourth {@link PlayerActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class FourthPlayerActionMessageDecoder extends MessageDecoder { @Override public PlayerActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new PlayerActionMessage(4, index); + int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE); + return new PlayerActionMessage(4, index, movementType); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SecondPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SecondPlayerActionMessageDecoder.java similarity index 67% rename from game/src/main/java/org/apollo/game/release/r377/SecondPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SecondPlayerActionMessageDecoder.java index 65aad4bb7..6c5ce5988 100644 --- a/game/src/main/java/org/apollo/game/release/r377/SecondPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SecondPlayerActionMessageDecoder.java @@ -1,6 +1,6 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.map.player.actions; -import org.apollo.game.message.impl.PlayerActionMessage; +import org.apollo.game.message.impl.decode.PlayerActionMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; @@ -10,15 +10,17 @@ /** * A {@link MessageDecoder} for the second {@link PlayerActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class SecondPlayerActionMessageDecoder extends MessageDecoder { @Override public PlayerActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); int index = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - return new PlayerActionMessage(2, index); + + return new PlayerActionMessage(2, index, movementType); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SeventhPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SeventhPlayerActionMessageDecoder.java new file mode 100644 index 000000000..19ad4970f --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SeventhPlayerActionMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.map.player.actions; + +import org.apollo.game.message.impl.decode.PlayerActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * A {@link MessageDecoder} for the seventh {@link PlayerActionMessage}. + * + * @author Khaled Abdeljaber + */ +public final class SeventhPlayerActionMessageDecoder extends MessageDecoder { + + @Override + public PlayerActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT); + int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + return new PlayerActionMessage(7, index, movementType); + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SixthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SixthPlayerActionMessageDecoder.java new file mode 100644 index 000000000..26f404258 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/SixthPlayerActionMessageDecoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.decoders.map.player.actions; + +import org.apollo.game.message.impl.decode.PlayerActionMessage; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +/** + * A {@link MessageDecoder} for the sixth {@link PlayerActionMessage}. + * + * @author Khaled Abdeljaber + */ +public final class SixthPlayerActionMessageDecoder extends MessageDecoder { + + @Override + public PlayerActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + int index = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int movementType = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT); + return new PlayerActionMessage(6, index, movementType); + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ThirdPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/ThirdPlayerActionMessageDecoder.java similarity index 54% rename from game/src/main/java/org/apollo/game/release/r377/ThirdPlayerActionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/ThirdPlayerActionMessageDecoder.java index cceb1fb9c..9a1de457e 100644 --- a/game/src/main/java/org/apollo/game/release/r377/ThirdPlayerActionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/map/player/actions/ThirdPlayerActionMessageDecoder.java @@ -1,7 +1,7 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.map.player.actions; -import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataOrder; +import org.apollo.game.message.impl.decode.PlayerActionMessage; +import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; @@ -10,15 +10,16 @@ /** * A {@link MessageDecoder} for the third {@link PlayerActionMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class ThirdPlayerActionMessageDecoder extends MessageDecoder { @Override public PlayerActionMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new PlayerActionMessage(3, index); + int index = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int movementType = (int) reader.getUnsigned(DataType.BYTE); + return new PlayerActionMessage(3, index, movementType); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/PrivacyOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivacyOptionMessageDecoder.java similarity index 57% rename from game/src/main/java/org/apollo/game/release/r317/PrivacyOptionMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivacyOptionMessageDecoder.java index 2dd9416f7..63827762e 100644 --- a/game/src/main/java/org/apollo/game/release/r317/PrivacyOptionMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/PrivacyOptionMessageDecoder.java @@ -1,6 +1,6 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181.decoders.social; -import org.apollo.game.message.impl.PrivacyOptionMessage; +import org.apollo.game.message.impl.decode.PrivacyOptionMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; @@ -17,11 +17,11 @@ public final class PrivacyOptionMessageDecoder extends MessageDecoder { @@ -19,19 +18,16 @@ public final class PrivateChatMessageDecoder extends MessageDecoder { + @Override + public PublicChatMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + final var type = PublicChatMessage.PublicChatType.of((int) reader.getUnsigned(DataType.BYTE)); + final var color = (int) reader.getUnsigned(DataType.BYTE); + final var effects = (int) reader.getUnsigned(DataType.BYTE); + + final var originalCompressed = new byte[packet.getLength() - 3]; + reader.getBytes(originalCompressed); + + String uncompressed = HuffmanCodec.decompress(originalCompressed); + uncompressed = TextUtil.filterInvalidCharacters(uncompressed); + uncompressed = TextUtil.capitalize(uncompressed); + + final var recompressed = HuffmanCodec.compress(uncompressed); // in case invalid data gets sent, this effectively verifies it + return new PublicChatMessage(uncompressed, recompressed, color, effects, type); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r317/AddFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/AddFriendMessageDecoder.java similarity index 64% rename from game/src/main/java/org/apollo/game/release/r317/AddFriendMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/AddFriendMessageDecoder.java index 606c246da..c494f86df 100644 --- a/game/src/main/java/org/apollo/game/release/r317/AddFriendMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/AddFriendMessageDecoder.java @@ -1,23 +1,21 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181.decoders.social.friends; -import org.apollo.game.message.impl.AddFriendMessage; -import org.apollo.net.codec.game.DataType; +import org.apollo.game.message.impl.decode.AddFriendMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; /** * A {@link MessageDecoder} for the {@link AddFriendMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class AddFriendMessageDecoder extends MessageDecoder { @Override public AddFriendMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); + String username = reader.getString(); return new AddFriendMessage(username); } diff --git a/game/src/main/java/org/apollo/game/release/r377/RemoveFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/RemoveFriendMessageDecoder.java similarity index 64% rename from game/src/main/java/org/apollo/game/release/r377/RemoveFriendMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/RemoveFriendMessageDecoder.java index d0b443742..8080be596 100644 --- a/game/src/main/java/org/apollo/game/release/r377/RemoveFriendMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/friends/RemoveFriendMessageDecoder.java @@ -1,23 +1,21 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.social.friends; -import org.apollo.game.message.impl.RemoveFriendMessage; -import org.apollo.net.codec.game.DataType; +import org.apollo.game.message.impl.decode.RemoveFriendMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; /** * A {@link MessageDecoder} for the {@link RemoveFriendMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class RemoveFriendMessageDecoder extends MessageDecoder { @Override public RemoveFriendMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); + String username = reader.getString(); return new RemoveFriendMessage(username); } diff --git a/game/src/main/java/org/apollo/game/release/r377/AddIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/AddIgnoreMessageDecoder.java similarity index 64% rename from game/src/main/java/org/apollo/game/release/r377/AddIgnoreMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/AddIgnoreMessageDecoder.java index 00119d641..0a46ff564 100644 --- a/game/src/main/java/org/apollo/game/release/r377/AddIgnoreMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/AddIgnoreMessageDecoder.java @@ -1,23 +1,21 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.social.ignores; -import org.apollo.game.message.impl.AddIgnoreMessage; -import org.apollo.net.codec.game.DataType; +import org.apollo.game.message.impl.decode.AddIgnoreMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; /** * A {@link MessageDecoder} for the {@link AddIgnoreMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class AddIgnoreMessageDecoder extends MessageDecoder { @Override public AddIgnoreMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); + String username = reader.getString(); return new AddIgnoreMessage(username); } diff --git a/game/src/main/java/org/apollo/game/release/r377/RemoveIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/RemoveIgnoreMessageDecoder.java similarity index 64% rename from game/src/main/java/org/apollo/game/release/r377/RemoveIgnoreMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/RemoveIgnoreMessageDecoder.java index 5f39dc69c..353a62123 100644 --- a/game/src/main/java/org/apollo/game/release/r377/RemoveIgnoreMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/social/ignores/RemoveIgnoreMessageDecoder.java @@ -1,23 +1,21 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.social.ignores; -import org.apollo.game.message.impl.RemoveIgnoreMessage; -import org.apollo.net.codec.game.DataType; +import org.apollo.game.message.impl.decode.RemoveIgnoreMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketReader; import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; /** * A {@link MessageDecoder} for the {@link RemoveIgnoreMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class RemoveIgnoreMessageDecoder extends MessageDecoder { @Override public RemoveIgnoreMessage decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); + String username = reader.getString(); return new RemoveIgnoreMessage(username); } diff --git a/game/src/main/java/org/apollo/game/release/r317/ClosedInterfaceMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/ClosedInterfaceMessageDecoder.java similarity index 72% rename from game/src/main/java/org/apollo/game/release/r317/ClosedInterfaceMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/ui/ClosedInterfaceMessageDecoder.java index 24c36f3b5..62cf6cdf5 100644 --- a/game/src/main/java/org/apollo/game/release/r317/ClosedInterfaceMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/ClosedInterfaceMessageDecoder.java @@ -1,13 +1,13 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181.decoders.ui; -import org.apollo.game.message.impl.ClosedInterfaceMessage; +import org.apollo.game.message.impl.decode.ClosedInterfaceMessage; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.release.MessageDecoder; /** * A {@link MessageDecoder} for the {@link ClosedInterfaceMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class ClosedInterfaceMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/DisplayStatusMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/DisplayStatusMessageDecoder.java new file mode 100644 index 000000000..c6fa98b1f --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/DisplayStatusMessageDecoder.java @@ -0,0 +1,19 @@ +package org.apollo.game.release.r181.decoders.ui; + +import org.apollo.game.message.impl.decode.DisplayStatusMessage; +import org.apollo.game.model.inter.DisplayMode; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +public class DisplayStatusMessageDecoder extends MessageDecoder { + @Override + public DisplayStatusMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + DisplayMode mode = reader.getUnsigned(DataType.BYTE) == 1 ? DisplayMode.FIXED : DisplayMode.RESIZABLE; + int width = (int) reader.getUnsigned(DataType.SHORT); + int height = (int) reader.getUnsigned(DataType.SHORT); + return new DisplayStatusMessage(mode, height, width); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r377/EnteredAmountMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/EnteredAmountMessageDecoder.java similarity index 89% rename from game/src/main/java/org/apollo/game/release/r377/EnteredAmountMessageDecoder.java rename to game/src/main/java/org/apollo/game/release/r181/decoders/ui/EnteredAmountMessageDecoder.java index 72c13b9b5..39368bf98 100644 --- a/game/src/main/java/org/apollo/game/release/r377/EnteredAmountMessageDecoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/EnteredAmountMessageDecoder.java @@ -1,4 +1,4 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.decoders.ui; import org.apollo.game.message.impl.EnteredAmountMessage; import org.apollo.net.codec.game.DataType; @@ -9,7 +9,7 @@ /** * A {@link MessageDecoder} for the {@link EnteredAmountMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ public final class EnteredAmountMessageDecoder extends MessageDecoder { diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FifthIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FifthIf1ActionMessageDecoder.java new file mode 100644 index 000000000..ab38bc72b --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FifthIf1ActionMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.if1; + +import org.apollo.game.message.impl.decode.ButtonMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FifthIf1ActionMessageDecoder extends MessageDecoder { + @Override + public ButtonMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int item = (int) reader.getUnsigned(DataType.SHORT); + int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.MIDDLE); + int slot = (int) reader.getUnsigned(DataType.SHORT); + + return new ButtonMessage(5, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FirstIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FirstIf1ActionMessageDecoder.java new file mode 100644 index 000000000..bd72741bb --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FirstIf1ActionMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.if1; + +import org.apollo.game.message.impl.decode.ButtonMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FirstIf1ActionMessageDecoder extends MessageDecoder { + @Override + public ButtonMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.INVERSED_MIDDLE); + int item = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + + return new ButtonMessage(1, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FourthIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FourthIf1ActionMessageDecoder.java new file mode 100644 index 000000000..e46f5ea72 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/FourthIf1ActionMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.if1; + +import org.apollo.game.message.impl.decode.ButtonMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FourthIf1ActionMessageDecoder extends MessageDecoder { + @Override + public ButtonMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int packedInterface = (int) reader.getUnsigned(DataType.INT); + int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int item = (int) reader.getUnsigned(DataType.SHORT); + + return new ButtonMessage(4, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/SecondIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/SecondIf1ActionMessageDecoder.java new file mode 100644 index 000000000..bf5289589 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/SecondIf1ActionMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.if1; + +import org.apollo.game.message.impl.decode.ButtonMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class SecondIf1ActionMessageDecoder extends MessageDecoder { + @Override + public ButtonMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.INVERSED_MIDDLE); + int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int item = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + + return new ButtonMessage(2, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/ThirdIf1ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/ThirdIf1ActionMessageDecoder.java new file mode 100644 index 000000000..68206a24b --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if1/ThirdIf1ActionMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.if1; + +import org.apollo.game.message.impl.decode.ButtonMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class ThirdIf1ActionMessageDecoder extends MessageDecoder { + @Override + public ButtonMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.LITTLE); + int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int item = (int) reader.getUnsigned(DataType.SHORT); + + return new ButtonMessage(3, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if3/If3ActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if3/If3ActionMessageDecoder.java new file mode 100644 index 000000000..f0eee9d1b --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/if3/If3ActionMessageDecoder.java @@ -0,0 +1,28 @@ +package org.apollo.game.release.r181.decoders.ui.if3; + +import org.apollo.game.message.impl.decode.ButtonMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class If3ActionMessageDecoder extends MessageDecoder { + + private final int action; + + public If3ActionMessageDecoder(int action) { + this.action = action; + } + + @Override + public ButtonMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int packedInterface = (int) reader.getUnsigned(DataType.INT); + int slot = (int) reader.getUnsigned(DataType.SHORT); + int item = (int) reader.getUnsigned(DataType.SHORT); + + return new ButtonMessage(action, packedInterface >> 16, packedInterface & 0xFFFF, slot, item); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java new file mode 100644 index 000000000..e240824b2 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FifthOpHeldMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.opheld; + +import org.apollo.game.message.impl.decode.ItemActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FifthOpHeldMessageDecoder extends MessageDecoder { + @Override + public ItemActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int packedInterface = (int) reader.getUnsigned(DataType.INT); + int slot = (int) reader.getUnsigned(DataType.SHORT); + int itemId = (int) reader.getUnsigned(DataType.SHORT); + + return new ItemActionMessage(5, packedInterface >> 16, packedInterface & 0xFFFF, itemId, slot); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FirstOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FirstOpHeldMessageDecoder.java new file mode 100644 index 000000000..fe3331260 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FirstOpHeldMessageDecoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.decoders.ui.opheld; + +import org.apollo.game.message.impl.decode.ItemActionMessage; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketReader; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FirstOpHeldMessageDecoder extends MessageDecoder { + @Override + public ItemActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int itemId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.MIDDLE); + int slot = (int) reader.getUnsigned(DataType.SHORT); + + return new ItemActionMessage(1, packedInterface >> 16, packedInterface & 0xFFFF, itemId, slot); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FourthOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FourthOpHeldMessageDecoder.java new file mode 100644 index 000000000..fc9e7931c --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/FourthOpHeldMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.opheld; + +import org.apollo.game.message.impl.decode.ItemActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class FourthOpHeldMessageDecoder extends MessageDecoder { + @Override + public ItemActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int itemId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int packedInterface = (int) reader.getUnsigned(DataType.INT); + int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + + return new ItemActionMessage(4, packedInterface >> 16, packedInterface & 0xFFFF, itemId, slot); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java new file mode 100644 index 000000000..bdc3c683d --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SecondOpHeldMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.opheld; + +import org.apollo.game.message.impl.decode.ItemActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class SecondOpHeldMessageDecoder extends MessageDecoder { + @Override + public ItemActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int itemId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.INVERSED_MIDDLE); + int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + + return new ItemActionMessage(2, packedInterface >> 16, packedInterface & 0xFFFF, itemId, slot); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SixthOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SixthOpHeldMessageDecoder.java new file mode 100644 index 000000000..e9f127103 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/SixthOpHeldMessageDecoder.java @@ -0,0 +1,18 @@ +package org.apollo.game.release.r181.decoders.ui.opheld; + +import org.apollo.game.message.impl.decode.ItemActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class SixthOpHeldMessageDecoder extends MessageDecoder { + @Override + public ItemActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int itemId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); + return new ItemActionMessage(6, -1, -1, itemId, -1); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java new file mode 100644 index 000000000..e293ccac6 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/decoders/ui/opheld/ThirdOpHeldMessageDecoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.decoders.ui.opheld; + +import org.apollo.game.message.impl.decode.ItemActionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageDecoder; + +/** + * @author Khaled Abdeljaber + */ +public class ThirdOpHeldMessageDecoder extends MessageDecoder { + @Override + public ItemActionMessage decode(GamePacket packet) { + GamePacketReader reader = new GamePacketReader(packet); + + int packedInterface = (int) reader.getUnsigned(DataType.INT, DataOrder.LITTLE); + int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + int itemId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + + return new ItemActionMessage(3, packedInterface >> 16, packedInterface & 0xFFFF, itemId, slot); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r317/UpdateRunEnergyMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateRunEnergyMessageEncoder.java similarity index 54% rename from game/src/main/java/org/apollo/game/release/r317/UpdateRunEnergyMessageEncoder.java rename to game/src/main/java/org/apollo/game/release/r181/encoders/UpdateRunEnergyMessageEncoder.java index 7fcf293d8..189974670 100644 --- a/game/src/main/java/org/apollo/game/release/r317/UpdateRunEnergyMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateRunEnergyMessageEncoder.java @@ -1,23 +1,22 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181.encoders; -import org.apollo.game.message.impl.UpdateRunEnergyMessage; +import org.apollo.game.message.impl.encode.UpdateRunEnergyMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; import org.apollo.net.release.MessageEncoder; /** - * A {@link MessageEncoder} for the {@link UpdateRunEnergyMessage} + * A {@link MessageEncoder} for the {@link UpdateRunEnergyMessage}. * - * @author Major + * @author Khaled Abdeljaber */ -public final class UpdateRunEnergyMessageEncoder extends MessageEncoder { - +public class UpdateRunEnergyMessageEncoder extends MessageEncoder { @Override public GamePacket encode(UpdateRunEnergyMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(110); + GamePacketBuilder builder = new GamePacketBuilder(60, PacketType.FIXED); builder.put(DataType.BYTE, message.getEnergy()); return builder.toGamePacket(); } - -} \ No newline at end of file +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateSkillMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateSkillMessageEncoder.java new file mode 100644 index 000000000..5f8e708c0 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateSkillMessageEncoder.java @@ -0,0 +1,26 @@ +package org.apollo.game.release.r181.encoders; + +import org.apollo.game.message.impl.encode.UpdateSkillMessage; +import org.apollo.game.model.entity.Skill; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * A {@link MessageEncoder} for the {@link UpdateSkillMessage}. + * + * @author Khaled Abdeljaber + */ +public class UpdateSkillMessageEncoder extends MessageEncoder { + @Override + public GamePacket encode(UpdateSkillMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(22, PacketType.FIXED); + Skill skill = message.getSkill(); + + builder.put(DataType.INT, DataOrder.LITTLE, (int) skill.getExperience()); + builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getId()); + builder.put(DataType.BYTE, skill.getCurrentLevel()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r317/UpdateWeightMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateWeightMessageEncoder.java similarity index 55% rename from game/src/main/java/org/apollo/game/release/r317/UpdateWeightMessageEncoder.java rename to game/src/main/java/org/apollo/game/release/r181/encoders/UpdateWeightMessageEncoder.java index 4ac9ffe68..a93164a90 100644 --- a/game/src/main/java/org/apollo/game/release/r317/UpdateWeightMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/UpdateWeightMessageEncoder.java @@ -1,23 +1,22 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181.encoders; -import org.apollo.game.message.impl.UpdateWeightMessage; +import org.apollo.game.message.impl.encode.UpdateWeightMessage; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; import org.apollo.net.release.MessageEncoder; /** * A {@link MessageEncoder} for the {@link UpdateWeightMessage}. * - * @author Major + * @author Khaled Abdeljaber */ -public final class UpdateWeightMessageEncoder extends MessageEncoder { - +public class UpdateWeightMessageEncoder extends MessageEncoder { @Override public GamePacket encode(UpdateWeightMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(240); + GamePacketBuilder builder = new GamePacketBuilder(71, PacketType.FIXED); builder.put(DataType.SHORT, message.getWeight()); return builder.toGamePacket(); } - -} \ No newline at end of file +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/game/LogoutEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/game/LogoutEncoder.java new file mode 100644 index 000000000..657746b4e --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/game/LogoutEncoder.java @@ -0,0 +1,18 @@ +package org.apollo.game.release.r181.encoders.game; + +import org.apollo.game.message.impl.encode.LogoutMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class LogoutEncoder extends MessageEncoder { + @Override + public GamePacket encode(LogoutMessage message) { + final var builder = new GamePacketBuilder(1, PacketType.FIXED); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/game/ServerChatMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/game/ServerChatMessageEncoder.java new file mode 100644 index 000000000..3b964d7ff --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/game/ServerChatMessageEncoder.java @@ -0,0 +1,26 @@ +package org.apollo.game.release.r181.encoders.game; + +import org.apollo.game.message.impl.encode.ServerChatMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +public class ServerChatMessageEncoder extends MessageEncoder { + @Override + public GamePacket encode(ServerChatMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(3, PacketType.VARIABLE_BYTE); + final var ext = message.getExtension(); + + builder.putSmart(message.getType().getId()); + if (ext.isEmpty()) { + builder.put(DataType.BYTE, 1); + builder.putString(ext); + } else { + builder.put(DataType.BYTE, 0); + } + builder.putString(message.getMessage()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r377/NpcSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java similarity index 87% rename from game/src/main/java/org/apollo/game/release/r377/NpcSynchronizationMessageEncoder.java rename to game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java index 05b8212fc..2273f93cf 100644 --- a/game/src/main/java/org/apollo/game/release/r377/NpcSynchronizationMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/npc/NpcSynchronizationMessageEncoder.java @@ -1,41 +1,31 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.encoders.npc; -import org.apollo.game.message.impl.NpcSynchronizationMessage; +import org.apollo.game.message.impl.encode.NpcSynchronizationMessage; import org.apollo.game.model.Animation; import org.apollo.game.model.Direction; import org.apollo.game.model.Graphic; import org.apollo.game.model.Position; -import org.apollo.game.sync.block.AnimationBlock; -import org.apollo.game.sync.block.ForceChatBlock; -import org.apollo.game.sync.block.GraphicBlock; -import org.apollo.game.sync.block.HitUpdateBlock; -import org.apollo.game.sync.block.InteractingMobBlock; -import org.apollo.game.sync.block.SecondaryHitUpdateBlock; -import org.apollo.game.sync.block.SynchronizationBlockSet; +import org.apollo.game.model.entity.Player; +import org.apollo.game.sync.block.*; import org.apollo.game.sync.block.TransformBlock; -import org.apollo.game.sync.block.TurnToPositionBlock; import org.apollo.game.sync.seg.AddNpcSegment; import org.apollo.game.sync.seg.MovementSegment; import org.apollo.game.sync.seg.SegmentType; import org.apollo.game.sync.seg.SynchronizationSegment; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.codec.game.*; import org.apollo.net.meta.PacketType; import org.apollo.net.release.MessageEncoder; /** * A {@link MessageEncoder} for the {@link NpcSynchronizationMessage}. * - * @author Major + * @author Khaled Abdeljaber */ public final class NpcSynchronizationMessageEncoder extends MessageEncoder { @Override public GamePacket encode(NpcSynchronizationMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(71, PacketType.VARIABLE_SHORT); + GamePacketBuilder builder = new GamePacketBuilder(message.isViewExtended() ? 81 : 33, PacketType.VARIABLE_SHORT); builder.switchToBitAccess(); GamePacketBuilder blockBuilder = new GamePacketBuilder(); @@ -55,7 +45,7 @@ public GamePacket encode(NpcSynchronizationMessage message) { } if (blockBuilder.getLength() > 0) { - builder.putBits(14, 16383); + builder.putBits(15, 0x7fff); builder.switchToByteAccess(); builder.putRawBuilder(blockBuilder); } else { @@ -74,14 +64,35 @@ public GamePacket encode(NpcSynchronizationMessage message) { */ private static void putAddNpcUpdate(AddNpcSegment seg, NpcSynchronizationMessage message, GamePacketBuilder builder) { boolean updateRequired = seg.getBlockSet().size() > 0; + boolean viewExtended = message.isViewExtended(); Position npc = message.getPosition(); Position other = seg.getPosition(); - builder.putBits(14, seg.getIndex()); - builder.putBits(1, updateRequired ? 1 : 0); - builder.putBits(5, other.getY() - npc.getY()); - builder.putBits(5, other.getX() - npc.getX()); + + var dx = other.getX() - npc.getX(); + var dy = other.getY() - npc.getY(); + if (!viewExtended) { + if (dx < Player.DEFAULT_VIEWING_DISTANCE) { + dx += 32; + } + if (dy < Player.DEFAULT_VIEWING_DISTANCE) { + dy += 32; + } + } else { + if (dx < Player.EXTENDED_VIEWING_DISTANCE) { + dx += 256; + } + if (dy < Player.EXTENDED_VIEWING_DISTANCE) { + dy += 256; + } + } + + builder.putBits(15, seg.getIndex()); + builder.putBits(viewExtended ? 8 : 5, dx); builder.putBits(1, 0); // discard walking queue - builder.putBits(13, seg.getNpcId()); + builder.putBits(3, seg.getDirection().toInteger()); + builder.putBits(1, updateRequired ? 1 : 0); + builder.putBits(viewExtended ? 8 : 5, dy); + builder.putBits(14, seg.getNpcId()); } /** @@ -107,7 +118,7 @@ private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder if (blockSet.size() > 0) { int mask = 0; - if (blockSet.contains(TransformBlock.class)) { + /*if (blockSet.contains(TransformBlock.class)) { mask |= 0x1; } @@ -137,11 +148,11 @@ private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder if (blockSet.contains(SecondaryHitUpdateBlock.class)) { mask |= 0x10; - } + }*/ builder.put(DataType.BYTE, mask); - if (blockSet.contains(TransformBlock.class)) { + /*if (blockSet.contains(TransformBlock.class)) { putTransformBlock(blockSet.get(TransformBlock.class), builder); } @@ -171,7 +182,7 @@ private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder if (blockSet.contains(SecondaryHitUpdateBlock.class)) { putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), builder); - } + }*/ } } @@ -292,7 +303,7 @@ private static void putTransformBlock(TransformBlock block, GamePacketBuilder bu * @param builder The builder. */ private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { - Position position = block.getPosition(); + Position position = block.getTurnPosition(); builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, position.getX() * 2 + 1); builder.put(DataType.SHORT, DataOrder.LITTLE, position.getY() * 2 + 1); } diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java new file mode 100644 index 000000000..c7b43a466 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/PlayerSynchronizationMessageEncoder.java @@ -0,0 +1,19 @@ +package org.apollo.game.release.r181.encoders.player; + +import org.apollo.game.message.impl.encode.PlayerSynchronizationMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.release.MessageEncoder; + +/** + * A {@link MessageEncoder} for the {@link PlayerSynchronizationMessage}. + * + * @author Graham + * @author Major + */ +public final class PlayerSynchronizationMessageEncoder extends MessageEncoder { + + @Override + public GamePacket encode(PlayerSynchronizationMessage message) { + return message.getInfo().toGamePacket(); + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SetPlayerActionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/SetPlayerActionMessageEncoder.java similarity index 53% rename from game/src/main/java/org/apollo/game/release/r317/SetPlayerActionMessageEncoder.java rename to game/src/main/java/org/apollo/game/release/r181/encoders/player/SetPlayerActionMessageEncoder.java index bfa2b2e2a..d55ef47f8 100644 --- a/game/src/main/java/org/apollo/game/release/r317/SetPlayerActionMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/SetPlayerActionMessageEncoder.java @@ -1,6 +1,6 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181.encoders.player; -import org.apollo.game.message.impl.SetPlayerActionMessage; +import org.apollo.game.message.impl.encode.SetPlayerActionMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; @@ -9,19 +9,15 @@ import org.apollo.net.release.MessageEncoder; /** - * The {@link MessageEncoder} for the {@link SetPlayerActionMessage}. - * - * @author Major + * @author Khaled Abdeljaber */ -public final class SetPlayerActionMessageEncoder extends MessageEncoder { - +public class SetPlayerActionMessageEncoder extends MessageEncoder { @Override public GamePacket encode(SetPlayerActionMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(104, PacketType.VARIABLE_BYTE); - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getSlot()); + GamePacketBuilder builder = new GamePacketBuilder(66, PacketType.VARIABLE_BYTE); builder.put(DataType.BYTE, DataTransformation.ADD, message.isPrimaryAction() ? 0 : 1); + builder.put(DataType.BYTE, DataTransformation.ADD, message.getSlot()); builder.putString(message.getText()); return builder.toGamePacket(); } - -} \ No newline at end of file +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ChatFilterSettingsEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ChatFilterSettingsEncoder.java new file mode 100644 index 000000000..e87bb6492 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/ChatFilterSettingsEncoder.java @@ -0,0 +1,23 @@ +package org.apollo.game.release.r181.encoders.player.social; + +import org.apollo.game.message.impl.encode.ChatFilterSettingsMessage; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class ChatFilterSettingsEncoder extends MessageEncoder { + + @Override + public GamePacket encode(ChatFilterSettingsMessage message) { + var builder = new GamePacketBuilder(80, PacketType.FIXED); + builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getTradePrivacy().toInteger(true)); + builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getChatPrivacy().toInteger(true)); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/FriendListUnlockEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/FriendListUnlockEncoder.java new file mode 100644 index 000000000..70b13faf9 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/FriendListUnlockEncoder.java @@ -0,0 +1,18 @@ +package org.apollo.game.release.r181.encoders.player.social; + +import org.apollo.game.message.impl.encode.FriendListUnlockMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class FriendListUnlockEncoder extends MessageEncoder { + @Override + public GamePacket encode(FriendListUnlockMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(29, PacketType.FIXED); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/MessagePrivateEchoEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/MessagePrivateEchoEncoder.java new file mode 100644 index 000000000..e00648431 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/MessagePrivateEchoEncoder.java @@ -0,0 +1,26 @@ +package org.apollo.game.release.r181.encoders.player.social; + +import org.apollo.game.message.impl.encode.MessagePrivateEchoMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * A {@link MessageEncoder} for the {@link MessagePrivateEchoMessage}. + * + * @author Major + */ +public final class MessagePrivateEchoEncoder extends MessageEncoder { + + @Override + public GamePacket encode(MessagePrivateEchoMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(38, PacketType.VARIABLE_SHORT); + + builder.putString(message.getUsername()); + builder.putBytes(message.getMessage()); + + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/MessagePrivateEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/MessagePrivateEncoder.java new file mode 100644 index 000000000..39b8b73d1 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/MessagePrivateEncoder.java @@ -0,0 +1,40 @@ +package org.apollo.game.release.r181.encoders.player.social; + +import org.apollo.game.message.impl.MessagePrivateMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * A {@link MessageEncoder} for the {@link MessagePrivateMessage}. + * + * @author Major + */ +public final class MessagePrivateEncoder extends MessageEncoder { + + /** + * The amount of messages sent globally, offset by a random variable x, {@code 0 <= x < 100,000,000}. + */ + private static AtomicInteger messageCounter = new AtomicInteger((int) (Math.random() * 100_000_000)); + + @Override + public GamePacket encode(MessagePrivateMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(10, PacketType.VARIABLE_SHORT); + + builder.putString(message.getSenderUsername()); + long count = messageCounter.incrementAndGet(); + builder.put(DataType.SHORT, count >> 16); + builder.put(DataType.TRI_BYTE, count & 0xFFFFFF); + builder.put(DataType.BYTE, message.getSenderPrivilege().toInteger()); + + final var compressed = message.getCompressedMessage(); + builder.putBytes(compressed); + + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SendFriendEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SendFriendEncoder.java new file mode 100644 index 000000000..ee829cce3 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SendFriendEncoder.java @@ -0,0 +1,33 @@ +package org.apollo.game.release.r181.encoders.player.social; + +import org.apollo.game.message.impl.SendFriendMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public final class SendFriendEncoder extends MessageEncoder { + + @Override + public GamePacket encode(SendFriendMessage message) { + final var builder = new GamePacketBuilder(58, PacketType.VARIABLE_SHORT); + final var components = message.getComponents(); + + for (var component : components) { + builder.put(DataType.BYTE, 0); // Friend Chat Rank + builder.putString(component.getUsername()); // Displayname + builder.putString(""); // Previous Displayname + builder.put(DataType.SHORT, component.getEncodedWorld()); + builder.put(DataType.BYTE, 0); // Friend Chat Rank + builder.put(DataType.BYTE, 0); // Some set of attributes, sorts the list somehow. + builder.putString(""); // Note + } + + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SetPrivateChatFilterEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SetPrivateChatFilterEncoder.java new file mode 100644 index 000000000..fef096b02 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/SetPrivateChatFilterEncoder.java @@ -0,0 +1,20 @@ +package org.apollo.game.release.r181.encoders.player.social; + +import org.apollo.game.message.impl.encode.SetPrivateChatFilterMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class SetPrivateChatFilterEncoder extends MessageEncoder { + @Override + public GamePacket encode(SetPrivateChatFilterMessage message) { + final var builder = new GamePacketBuilder(68, PacketType.FIXED); + builder.put(DataType.BYTE, message.getFriendPrivacy().toInteger(true)); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/UpdateIgnoreListEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/UpdateIgnoreListEncoder.java new file mode 100644 index 000000000..1b8ef9a4a --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/player/social/UpdateIgnoreListEncoder.java @@ -0,0 +1,30 @@ +package org.apollo.game.release.r181.encoders.player.social; + +import org.apollo.game.message.impl.UpdateIgnoreListMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public final class UpdateIgnoreListEncoder extends MessageEncoder { + + @Override + public GamePacket encode(UpdateIgnoreListMessage message) { + final var builder = new GamePacketBuilder(32, PacketType.VARIABLE_SHORT); + final var components = message.getComponents(); + + for (var component : components) { + builder.put(DataType.BYTE, 0x0); // If you're updating this player or something + builder.putString(component.getUsername()); // Display name + builder.putString(""); // Previous display name + builder.putString("");// Notes, not used in osrs + } + + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SendObjectMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/AddObjectEncoder.java similarity index 50% rename from game/src/main/java/org/apollo/game/release/r317/SendObjectMessageEncoder.java rename to game/src/main/java/org/apollo/game/release/r181/encoders/region/AddObjectEncoder.java index 6e3e5f350..4364d738d 100644 --- a/game/src/main/java/org/apollo/game/release/r317/SendObjectMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/AddObjectEncoder.java @@ -1,27 +1,23 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181.encoders.region; -import org.apollo.game.message.impl.SendObjectMessage; -import org.apollo.net.codec.game.DataOrder; +import org.apollo.game.message.impl.encode.AddObjectMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; import org.apollo.net.release.MessageEncoder; /** - * A {@link MessageEncoder} for the {@link SendObjectMessage}. - * - * @author Major + * @author Khaled Abdeljaber */ -public final class SendObjectMessageEncoder extends MessageEncoder { - +public class AddObjectEncoder extends MessageEncoder { @Override - public GamePacket encode(SendObjectMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(151); + public GamePacket encode(AddObjectMessage message) { + final var builder = new GamePacketBuilder(6, PacketType.FIXED); builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getId()); builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getType() << 2 | message.getOrientation()); + builder.put(DataType.SHORT, DataTransformation.ADD, message.getId()); return builder.toGamePacket(); } - -} \ No newline at end of file +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/AddTileItemEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/AddTileItemEncoder.java new file mode 100644 index 000000000..3be28037e --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/AddTileItemEncoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.AddTileItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class AddTileItemEncoder extends MessageEncoder { + + @Override + public GamePacket encode(AddTileItemMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(26); + builder.put(DataType.SHORT, DataTransformation.ADD, message.getAmount()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); + builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/AreaSoundEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/AreaSoundEncoder.java new file mode 100644 index 000000000..8c9406410 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/AreaSoundEncoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.AreaSoundMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class AreaSoundEncoder extends MessageEncoder { + @Override + public GamePacket encode(AreaSoundMessage message) { + final var sound = message.getSound(); + final var builder = new GamePacketBuilder(12, PacketType.FIXED); + builder.put(DataType.BYTE, sound.getLength() << 4 | sound.getVolume()); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, sound.getDelay()); + builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, sound.getId()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/MobResetAnimsEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/MobResetAnimsEncoder.java new file mode 100644 index 000000000..63f9d1725 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/MobResetAnimsEncoder.java @@ -0,0 +1,19 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.MobResetAnimsMessage; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class MobResetAnimsEncoder extends MessageEncoder { + + @Override + public GamePacket encode(MobResetAnimsMessage message) { + final var builder = new GamePacketBuilder(28, PacketType.FIXED); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/ObjectAnimEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/ObjectAnimEncoder.java new file mode 100644 index 000000000..643bdf33f --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/ObjectAnimEncoder.java @@ -0,0 +1,27 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.ObjectAnimationMessage; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class ObjectAnimEncoder extends MessageEncoder { + + @Override + public GamePacket encode(ObjectAnimationMessage message) { + final var animation = message.getAnimation(); + final var object = message.getObject(); + final var builder = new GamePacketBuilder(49, PacketType.FIXED); + + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, object.getType() << 2 | object.getOrientation()); + builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getPositionOffset()); + builder.put(DataType.SHORT, animation.getId()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/RebuildNormalMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RebuildNormalMessageEncoder.java new file mode 100644 index 000000000..9a497ce02 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RebuildNormalMessageEncoder.java @@ -0,0 +1,57 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.RebuildNormalMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +import java.util.Arrays; + +/** + * A {@link MessageEncoder} for the {@link RebuildNormalMessage}. + * + * @author Khaled Abdeljaber + */ +public final class RebuildNormalMessageEncoder extends MessageEncoder { + + @Override + public GamePacket encode(RebuildNormalMessage message) { + final var builder = new GamePacketBuilder(0, PacketType.VARIABLE_SHORT); + final var position = message.getPosition(); + // TODO the player shit here. + + if (!message.isHasLastKnownRegion()) { + message.getInfo().init(message.getPlayerRepository(), message.getIndex(), position, builder); + } + + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, + message.getPosition().getCentralRegionY()); + builder.put(DataType.SHORT, DataTransformation.ADD, message.getPosition().getCentralRegionX()); + + boolean force = true; + int centralMapX = position.getCentralRegionX() / 8; + int centralMapY = position.getCentralRegionY() / 8; + + if ((centralMapX == 48 || centralMapX == 49) && centralMapY == 48) force = false; + + if (centralMapX == 48 && centralMapY == 148) force = false; + + GamePacketBuilder map = new GamePacketBuilder(); + for (int mapX = ((position.getCentralRegionX() - 6) / 8); mapX <= ((position + .getCentralRegionX() + 6) / 8); mapX++) { + for (int mapY = ((position.getCentralRegionY() - 6) / 8); mapY <= ((position + .getCentralRegionY() + 6) / 8); mapY++) { + if (force || (mapY != 49 && mapY != 149 && mapY != 147 && mapX != 50 && (mapX != 49 || mapY != 47))) { + int[] keys = message.getXteaRepository().get(mapX, mapY); + for (int key : keys) { + map.put(DataType.INT, key); + } + } + } + } + + builder.put(DataType.SHORT, map.getLength() / (Integer.BYTES * 4)); + builder.putBytes(map); + return builder.toGamePacket(); + } +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/RemoveObjectMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RemoveObjectEncoder.java similarity index 62% rename from game/src/main/java/org/apollo/game/release/r377/RemoveObjectMessageEncoder.java rename to game/src/main/java/org/apollo/game/release/r181/encoders/region/RemoveObjectEncoder.java index 76a89c355..e734b57be 100644 --- a/game/src/main/java/org/apollo/game/release/r377/RemoveObjectMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RemoveObjectEncoder.java @@ -1,25 +1,23 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.encoders.region; -import org.apollo.game.message.impl.RemoveObjectMessage; +import org.apollo.game.message.impl.encode.RemoveObjectMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; import org.apollo.net.release.MessageEncoder; /** - * A {@link MessageEncoder} for the {@link RemoveObjectMessage}. - * - * @author Major + * @author Khaled Abdeljaber */ -public final class RemoveObjectMessageEncoder extends MessageEncoder { +public class RemoveObjectEncoder extends MessageEncoder { @Override public GamePacket encode(RemoveObjectMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(88); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getPositionOffset()); + final var builder = new GamePacketBuilder(13, PacketType.FIXED); builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getType() << 2 | message.getOrientation()); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getPositionOffset()); return builder.toGamePacket(); } - -} \ No newline at end of file +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/RemoveTileItemEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RemoveTileItemEncoder.java new file mode 100644 index 000000000..fcece05b2 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/RemoveTileItemEncoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.AddTileItemMessage; +import org.apollo.game.message.impl.encode.RemoveTileItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class RemoveTileItemEncoder extends MessageEncoder { + + @Override + public GamePacket encode(RemoveTileItemMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(14); + builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/SendProjectileMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/SendProjectileMessageEncoder.java new file mode 100644 index 000000000..33852de48 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/SendProjectileMessageEncoder.java @@ -0,0 +1,37 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.SendProjectileMessage; +import org.apollo.game.model.Position; +import org.apollo.game.model.entity.Projectile; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + * A {@link MessageEncoder} for the {@link SendProjectileMessage}. + */ +public final class SendProjectileMessageEncoder extends MessageEncoder { + + @Override + public GamePacket encode(SendProjectileMessage message) { + Projectile projectile = message.getProjectile(); + Position source = projectile.getPosition(); + Position destination = projectile.getDestination(); + + GamePacketBuilder builder = new GamePacketBuilder(11); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, projectile.getEndHeight()); + builder.put(DataType.SHORT, projectile.getLifetime()); + builder.put(DataType.SHORT, DataTransformation.ADD, projectile.getGraphic()); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, projectile.getStartHeight()); + builder.put(DataType.SHORT, DataOrder.LITTLE, projectile.getTarget()); + builder.put(DataType.BYTE, projectile.getPitch()); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, projectile.getOffset()); + builder.put(DataType.SHORT, DataOrder.LITTLE, projectile.getDelay()); + builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); + builder.put(DataType.BYTE, DataTransformation.ADD, destination.getY() - source.getY()); + builder.put(DataType.BYTE, DataTransformation.NEGATE, destination.getX() - source.getX()); + + return builder.toGamePacket(); + } + +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/SetMapFlagEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/SetMapFlagEncoder.java new file mode 100644 index 000000000..59326813b --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/SetMapFlagEncoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.SetMapFlagMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class SetMapFlagEncoder extends MessageEncoder { + + @Override + public GamePacket encode(SetMapFlagMessage message) { + final var builder = new GamePacketBuilder(67, PacketType.FIXED); + builder.put(DataType.BYTE, message.getY()); + builder.put(DataType.BYTE, message.getX()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/SpotAnimEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/SpotAnimEncoder.java new file mode 100644 index 000000000..90bffb3cc --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/SpotAnimEncoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.SpotAnimMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class SpotAnimEncoder extends MessageEncoder { + @Override + public GamePacket encode(SpotAnimMessage message) { + final var spotAnim = message.getSpotAnim(); + final var builder = new GamePacketBuilder(8, PacketType.FIXED); + builder.put(DataType.SHORT, spotAnim.getId()); + builder.put(DataType.BYTE, DataTransformation.ADD, spotAnim.getHeight()); + builder.put(DataType.SHORT, DataTransformation.ADD, spotAnim.getDelay()); + builder.put(DataType.SHORT, message.getPositionOffset()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateTileItemEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateTileItemEncoder.java new file mode 100644 index 000000000..c6cce658f --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateTileItemEncoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.UpdateTileItemMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.release.MessageEncoder; + +/** + * A {@link MessageEncoder} for the {@link UpdateTileItemMessage}. + * + * @author Khaled Abdeljaber + */ +public final class UpdateTileItemEncoder extends MessageEncoder { + + @Override + public GamePacket encode(UpdateTileItemMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(15); + builder.put(DataType.SHORT, DataOrder.LITTLE, message.getId()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getAmount()); + builder.put(DataType.SHORT, DataOrder.LITTLE, message.getPreviousAmount()); + builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZoneFullFollowsEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZoneFullFollowsEncoder.java new file mode 100644 index 000000000..1ccc03887 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZoneFullFollowsEncoder.java @@ -0,0 +1,27 @@ +package org.apollo.game.release.r181.encoders.region; + +import org.apollo.game.message.impl.encode.UpdateZoneFullFollowsMessage; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class UpdateZoneFullFollowsEncoder extends MessageEncoder { + @Override + public GamePacket encode(UpdateZoneFullFollowsMessage message) { + final var builder = new GamePacketBuilder(25, PacketType.FIXED); + + final var player = message.getPlayerPosition(); + final var region = message.getRegionPosition(); + + builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalY(player)); + builder.put(DataType.BYTE, region.getLocalX(player)); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r317/GroupedRegionUpdateMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZonePartialEnclosedEncoder.java similarity index 64% rename from game/src/main/java/org/apollo/game/release/r317/GroupedRegionUpdateMessageEncoder.java rename to game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZonePartialEnclosedEncoder.java index cd6703b77..76b5b04ac 100644 --- a/game/src/main/java/org/apollo/game/release/r317/GroupedRegionUpdateMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/region/UpdateZonePartialEnclosedEncoder.java @@ -1,7 +1,7 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181.encoders.region; -import org.apollo.game.message.impl.GroupedRegionUpdateMessage; -import org.apollo.game.message.impl.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.UpdateZonePartialEnclosedMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.Position; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; @@ -12,11 +12,11 @@ import org.apollo.net.release.Release; /** - * A {@link MessageEncoder} for the {@link GroupedRegionUpdateMessage}. + * A {@link MessageEncoder} for the {@link UpdateZonePartialEnclosedMessage}. * * @author Major */ -public final class GroupedRegionUpdateMessageEncoder extends MessageEncoder { +public final class UpdateZonePartialEnclosedEncoder extends MessageEncoder { /** * The Release containing the MessageEncoders for the RegionUpdateMessages. @@ -28,16 +28,16 @@ public final class GroupedRegionUpdateMessageEncoder extends MessageEncoder { + @Override + public GamePacket encode(UpdateZonePartialFollowsMessage message) { + final var builder = new GamePacketBuilder(64, PacketType.FIXED); + + final var player = message.getPlayerPosition(); + final var region = message.getRegionPosition(); + + builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(player)); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, region.getLocalY(player)); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r377/ConfigMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/ConfigMessageEncoder.java similarity index 60% rename from game/src/main/java/org/apollo/game/release/r377/ConfigMessageEncoder.java rename to game/src/main/java/org/apollo/game/release/r181/encoders/ui/ConfigMessageEncoder.java index 03cd3a493..65c93c14b 100644 --- a/game/src/main/java/org/apollo/game/release/r377/ConfigMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/ConfigMessageEncoder.java @@ -1,7 +1,6 @@ -package org.apollo.game.release.r377; +package org.apollo.game.release.r181.encoders.ui; -import org.apollo.game.message.impl.ConfigMessage; -import org.apollo.net.codec.game.DataOrder; +import org.apollo.game.message.impl.encode.ConfigMessage; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; @@ -11,8 +10,7 @@ /** * A {@link MessageEncoder} for the {@link ConfigMessage}. * - * @author Chris Fletcher - * @author Major + * @author Khaled Abdeljaber */ public final class ConfigMessageEncoder extends MessageEncoder { @@ -22,15 +20,15 @@ public GamePacket encode(ConfigMessage message) { int value = message.getValue(); if (value > Byte.MIN_VALUE && value < Byte.MAX_VALUE) { - builder = new GamePacketBuilder(182); + builder = new GamePacketBuilder(63); + builder.put(DataType.BYTE, DataTransformation.ADD, value & 0xFF); builder.put(DataType.SHORT, DataTransformation.ADD, message.getId()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, value & 0xFF); } else { - builder = new GamePacketBuilder(115); + builder = new GamePacketBuilder(4); - builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, value); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getId()); + builder.put(DataType.SHORT, message.getId()); + builder.put(DataType.INT, value); } return builder.toGamePacket(); diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfClearItemsEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfClearItemsEncoder.java new file mode 100644 index 000000000..ef2c16706 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfClearItemsEncoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfClearItemsMessage; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfClearItemsEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfClearItemsMessage message) { + final var builder = new GamePacketBuilder(7, PacketType.FIXED); + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getPackedInterface()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfMoveSubMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfMoveSubMessageEncoder.java new file mode 100644 index 000000000..ee1181866 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfMoveSubMessageEncoder.java @@ -0,0 +1,19 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfMoveSubMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +public class IfMoveSubMessageEncoder extends MessageEncoder { + + @Override + public GamePacket encode(IfMoveSubMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(82, PacketType.FIXED); + builder.put(DataType.INT, message.getToPackedInterface()); + builder.put(DataType.INT, message.getFromPackedInterface()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenSubMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenSubMessageEncoder.java new file mode 100644 index 000000000..321101323 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenSubMessageEncoder.java @@ -0,0 +1,17 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfOpenSubMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +public class IfOpenSubMessageEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfOpenSubMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(77, PacketType.FIXED); + builder.put(DataType.BYTE, DataTransformation.ADD, message.getType().ordinal()); + builder.put(DataType.INT, DataOrder.MIDDLE, message.getPackedParentInterface()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenTopMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenTopMessageEncoder.java new file mode 100644 index 000000000..94b2fe6fb --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfOpenTopMessageEncoder.java @@ -0,0 +1,15 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfOpenTopMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +public class IfOpenTopMessageEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfOpenTopMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(84, PacketType.FIXED); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAngleEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAngleEncoder.java new file mode 100644 index 000000000..aef9cdc38 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAngleEncoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetAngleMessage; +import org.apollo.game.message.impl.encode.IfSetNpcHeadMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetAngleEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetAngleMessage message) { + final var builder = new GamePacketBuilder(50, PacketType.FIXED); + + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getRotationX()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getZoom()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getRotationY()); + builder.put(DataType.INT, DataOrder.MIDDLE, message.getPackedInterface()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAnimEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAnimEncoder.java new file mode 100644 index 000000000..a37ec4da0 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetAnimEncoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetAnimMessage; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetAnimEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetAnimMessage message) { + final var builder = new GamePacketBuilder(61, PacketType.FIXED); + + builder.put(DataType.SHORT, message.getAnimation()); + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getPackedInterface()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetColourEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetColourEncoder.java new file mode 100644 index 000000000..d8ab6e002 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetColourEncoder.java @@ -0,0 +1,20 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetColourMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetColourEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetColourMessage message) { + final var builder = new GamePacketBuilder(24, PacketType.FIXED); + + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getPackedInterface()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getPackedColours()); + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetEventMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetEventMessageEncoder.java new file mode 100644 index 000000000..852381a83 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetEventMessageEncoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetEventMessage; +import org.apollo.game.model.inter.InterfaceEvent; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetEventMessageEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetEventMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(48, PacketType.FIXED); + + builder.put(DataType.INT, DataOrder.LITTLE, message.getEvents().stream().mapToInt(InterfaceEvent::getMask).sum()); + builder.put(DataType.SHORT, DataTransformation.ADD, message.getRange().getEndInclusive()); + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getPackedInterface()); + builder.put(DataType.SHORT, message.getRange().getStart()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetHiddenEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetHiddenEncoder.java new file mode 100644 index 000000000..c12eebb62 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetHiddenEncoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetHideMessage; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetHiddenEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetHideMessage message) { + final var builder = new GamePacketBuilder(21, PacketType.FIXED); + + builder.put(DataType.INT, message.getPackedInterface()); + builder.put(DataType.BYTE, DataOrder.INVERSED_MIDDLE, message.isVisible() ? 0 : 1); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetItemEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetItemEncoder.java new file mode 100644 index 000000000..fa794a197 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetItemEncoder.java @@ -0,0 +1,25 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetItemMessage; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetItemEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetItemMessage message) { + final var builder = new GamePacketBuilder(11, PacketType.FIXED); + + builder.put(DataType.INT, message.getPackedInterface()); + builder.put(DataType.SHORT, message.getItem()); + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getAmount()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelEncoder.java new file mode 100644 index 000000000..7d55be395 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelEncoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetModelMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetModelEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetModelMessage message) { + final var builder = new GamePacketBuilder(31, PacketType.FIXED); + + builder.put(DataType.INT, DataOrder.MIDDLE, message.getPackedInterface()); + builder.put(DataType.SHORT, DataTransformation.ADD, message.getModel()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelRotateEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelRotateEncoder.java new file mode 100644 index 000000000..2f48fbe29 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetModelRotateEncoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetModelRotateMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetModelRotateEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetModelRotateMessage message) { + final var builder = new GamePacketBuilder(41, PacketType.FIXED); + + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getRotationY()); + builder.put(DataType.SHORT, DataOrder.LITTLE, message.getRotationX()); + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getPackedInterface()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetNpcHeadEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetNpcHeadEncoder.java new file mode 100644 index 000000000..08c23035b --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetNpcHeadEncoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetNpcHeadMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetNpcHeadEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetNpcHeadMessage message) { + final var builder = new GamePacketBuilder(35, PacketType.FIXED); + + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getNpcId()); + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getPackedInterface()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetPlayerHeadEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetPlayerHeadEncoder.java new file mode 100644 index 000000000..bac7e76b2 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetPlayerHeadEncoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetItemMessage; +import org.apollo.game.message.impl.encode.IfSetPlayerHeadMessage; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetPlayerHeadEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetPlayerHeadMessage message) { + final var builder = new GamePacketBuilder(30, PacketType.FIXED); + + builder.put(DataType.INT, message.getPackedInterface()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetPositionEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetPositionEncoder.java new file mode 100644 index 000000000..6d9be4c59 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetPositionEncoder.java @@ -0,0 +1,22 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetPositionMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetPositionEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetPositionMessage message) { + final var builder = new GamePacketBuilder(59, PacketType.FIXED); + + builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, message.getPackedInterface()); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getY()); + builder.put(DataType.SHORT, message.getX()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetScrollPosEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetScrollPosEncoder.java new file mode 100644 index 000000000..c7631620d --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetScrollPosEncoder.java @@ -0,0 +1,21 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetScrollPosMessage; +import org.apollo.net.codec.game.*; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetScrollPosEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetScrollPosMessage message) { + final var builder = new GamePacketBuilder(76, PacketType.FIXED); + + builder.put(DataType.INT, DataOrder.MIDDLE, message.getPackedInterface()); + builder.put(DataType.SHORT, DataTransformation.ADD, message.getScrollPosition()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetTextEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetTextEncoder.java new file mode 100644 index 000000000..bb98355b7 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/IfSetTextEncoder.java @@ -0,0 +1,24 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.IfSetTextMessage; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class IfSetTextEncoder extends MessageEncoder { + @Override + public GamePacket encode(IfSetTextMessage message) { + final var builder = new GamePacketBuilder(19, PacketType.VARIABLE_SHORT); + + builder.put(DataType.INT, message.getPackedInterface()); + builder.putString(message.getText()); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r181/encoders/ui/RunClientScriptEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/RunClientScriptEncoder.java new file mode 100644 index 000000000..1aa24a130 --- /dev/null +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/RunClientScriptEncoder.java @@ -0,0 +1,39 @@ +package org.apollo.game.release.r181.encoders.ui; + +import org.apollo.game.message.impl.encode.RunClientScriptMessage; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacket; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.net.release.MessageEncoder; + +/** + * @author Khaled Abdeljaber + */ +public class RunClientScriptEncoder extends MessageEncoder { + @Override + public GamePacket encode(RunClientScriptMessage message) { + final var builder = new GamePacketBuilder(62, PacketType.VARIABLE_SHORT); + final var id = message.getId(); + final var params = message.getParams(); + + final var signature = new StringBuilder(); + final var internal = new GamePacketBuilder(); + for (int i = params.length - 1; i >= 0; i--) { + Object param = params[i]; + if (param instanceof String) { + signature.append("s"); + internal.putString((String) param); + } else { + signature.append("i"); + internal.put(DataType.INT, (Number) param); + } + } + + builder.putString(signature.toString()); + builder.putBytes(internal); + builder.put(DataType.INT, id); + + return builder.toGamePacket(); + } +} diff --git a/game/src/main/java/org/apollo/game/release/r317/UpdateItemsMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerFullMessageEncoder.java similarity index 52% rename from game/src/main/java/org/apollo/game/release/r317/UpdateItemsMessageEncoder.java rename to game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerFullMessageEncoder.java index 64fc8183a..aa791c295 100644 --- a/game/src/main/java/org/apollo/game/release/r317/UpdateItemsMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerFullMessageEncoder.java @@ -1,9 +1,8 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181.encoders.ui.container; -import org.apollo.game.message.impl.UpdateItemsMessage; +import org.apollo.game.message.impl.encode.UpdateInventoryFullMessage; import org.apollo.game.model.Item; import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; import org.apollo.net.codec.game.GamePacket; import org.apollo.net.codec.game.GamePacketBuilder; @@ -11,33 +10,34 @@ import org.apollo.net.release.MessageEncoder; /** - * A {@link MessageEncoder} for the {@link UpdateItemsMessage}. + * A {@link MessageEncoder} for the {@link UpdateInventoryFullMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ -public final class UpdateItemsMessageEncoder extends MessageEncoder { +public final class UpdateContainerFullMessageEncoder extends MessageEncoder { @Override - public GamePacket encode(UpdateItemsMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(53, PacketType.VARIABLE_SHORT); + public GamePacket encode(UpdateInventoryFullMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(70, PacketType.VARIABLE_SHORT); Item[] items = message.getItems(); - builder.put(DataType.SHORT, message.getInterfaceId()); + builder.put(DataType.INT, message.getInterfaceId() << 16 | message.getComponent()); + builder.put(DataType.SHORT, message.getInventory()); builder.put(DataType.SHORT, items.length); for (Item item : items) { int id = item == null ? -1 : item.getId(); int amount = item == null ? 0 : item.getAmount(); + builder.put(DataType.SHORT, id + 1); + if (amount > 254) { - builder.put(DataType.BYTE, 255); + builder.put(DataType.BYTE, 0xFF); builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, amount); } else { builder.put(DataType.BYTE, amount); } - - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, id + 1); } return builder.toGamePacket(); diff --git a/game/src/main/java/org/apollo/game/release/r317/UpdateSlottedItemsMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerPartialMessageEncoder.java similarity index 56% rename from game/src/main/java/org/apollo/game/release/r317/UpdateSlottedItemsMessageEncoder.java rename to game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerPartialMessageEncoder.java index 68c790f7e..4c5536fc9 100644 --- a/game/src/main/java/org/apollo/game/release/r317/UpdateSlottedItemsMessageEncoder.java +++ b/game/src/main/java/org/apollo/game/release/r181/encoders/ui/container/UpdateContainerPartialMessageEncoder.java @@ -1,6 +1,6 @@ -package org.apollo.game.release.r317; +package org.apollo.game.release.r181.encoders.ui.container; -import org.apollo.game.message.impl.UpdateSlottedItemsMessage; +import org.apollo.game.message.impl.encode.UpdateInventoryPartialMessage; import org.apollo.game.model.Item; import org.apollo.game.model.inv.SlottedItem; import org.apollo.net.codec.game.DataType; @@ -10,18 +10,19 @@ import org.apollo.net.release.MessageEncoder; /** - * A {@link MessageEncoder} for the {@link UpdateSlottedItemsMessage}. + * A {@link MessageEncoder} for the {@link UpdateInventoryPartialMessage}. * - * @author Graham + * @author Khaled Abdeljaber */ -public final class UpdateSlottedItemsMessageEncoder extends MessageEncoder { +public final class UpdateContainerPartialMessageEncoder extends MessageEncoder { @Override - public GamePacket encode(UpdateSlottedItemsMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(34, PacketType.VARIABLE_SHORT); + public GamePacket encode(UpdateInventoryPartialMessage message) { + GamePacketBuilder builder = new GamePacketBuilder(44, PacketType.VARIABLE_SHORT); SlottedItem[] items = message.getSlottedItems(); - builder.put(DataType.SHORT, message.getInterfaceId()); + builder.put(DataType.INT, message.getInterfaceId() << 16 | message.getComponent()); + builder.put(DataType.SHORT, message.getContainerId()); for (SlottedItem slottedItem : items) { builder.putSmart(slottedItem.getSlot()); @@ -32,6 +33,10 @@ public GamePacket encode(UpdateSlottedItemsMessage message) { builder.put(DataType.SHORT, id + 1); + if (id == -1) { + continue; + } + if (amount > 254) { builder.put(DataType.BYTE, 255); builder.put(DataType.INT, amount); @@ -42,5 +47,4 @@ public GamePacket encode(UpdateSlottedItemsMessage message) { return builder.toGamePacket(); } - -} \ No newline at end of file +} diff --git a/game/src/main/java/org/apollo/game/release/r317/AddGlobalTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/AddGlobalTileItemMessageEncoder.java deleted file mode 100644 index 3461c7e77..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/AddGlobalTileItemMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SendPublicTileItemMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SendPublicTileItemMessage}. - * - * @author Major - */ -public final class AddGlobalTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendPublicTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(215); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getId()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getPositionOffset()); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getIndex()); - builder.put(DataType.SHORT, message.getAmount()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/AddIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/AddIgnoreMessageDecoder.java deleted file mode 100644 index 879ad5ff7..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/AddIgnoreMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.AddIgnoreMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageDecoder} for the {@link AddIgnoreMessage}. - * - * @author Major - */ -public final class AddIgnoreMessageDecoder extends MessageDecoder { - - @Override - public AddIgnoreMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - return new AddIgnoreMessage(username); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/AddTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/AddTileItemMessageEncoder.java deleted file mode 100644 index 06c0ff9d0..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/AddTileItemMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SendTileItemMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SendTileItemMessage}. - * - * @author Major - */ -public final class AddTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(44); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); - builder.put(DataType.SHORT, message.getAmount()); - builder.put(DataType.BYTE, message.getPositionOffset()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ArrowKeyMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ArrowKeyMessageDecoder.java deleted file mode 100644 index 9a73b04d5..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ArrowKeyMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ArrowKeyMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ArrowKeyMessage}. - * - * @author Major - */ -public final class ArrowKeyMessageDecoder extends MessageDecoder { - - @Override - public ArrowKeyMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int roll = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int yaw = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new ArrowKeyMessage(roll, yaw); - } -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ButtonMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ButtonMessageDecoder.java deleted file mode 100644 index 0abccdb57..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ButtonMessageDecoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ButtonMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ButtonMessage}. - * - * @author Graham - */ -public final class ButtonMessageDecoder extends MessageDecoder { - - @Override - public ButtonMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - return new ButtonMessage(interfaceId); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ClearRegionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/ClearRegionMessageEncoder.java deleted file mode 100644 index 8a7076d4c..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ClearRegionMessageEncoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ClearRegionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link ClearRegionMessage}. - * - * @author Major - */ -public final class ClearRegionMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(ClearRegionMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(64); - Position player = message.getPlayerPosition(), region = message.getRegionPosition(); - - builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(player)); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, region.getLocalY(player)); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/CloseInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/CloseInterfaceMessageEncoder.java deleted file mode 100644 index df11c074c..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/CloseInterfaceMessageEncoder.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.CloseInterfaceMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link CloseInterfaceMessage}. - * - * @author Graham - */ -public final class CloseInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(CloseInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(219); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ConfigMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/ConfigMessageEncoder.java deleted file mode 100644 index e51207feb..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ConfigMessageEncoder.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ConfigMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link ConfigMessage}. - * - * @author Chris Fletcher - * @author Major - */ -public final class ConfigMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(ConfigMessage message) { - GamePacketBuilder builder; - int value = message.getValue(); - - if (value > Byte.MIN_VALUE && value < Byte.MAX_VALUE) { - builder = new GamePacketBuilder(36); - - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getId()); - builder.put(DataType.BYTE, value & 0xFF); - } else { - builder = new GamePacketBuilder(87); - - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getId()); - builder.put(DataType.INT, DataOrder.MIDDLE, value); - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/DialogueContinueMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/DialogueContinueMessageDecoder.java deleted file mode 100644 index 17daaa1f3..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/DialogueContinueMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.DialogueContinueMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link DialogueContinueMessage}. - * - * @author Chris Fletcher - */ -public final class DialogueContinueMessageDecoder extends MessageDecoder { - - @Override - public DialogueContinueMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - - return new DialogueContinueMessage(interfaceId); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/DisplayCrossbonesMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/DisplayCrossbonesMessageEncoder.java deleted file mode 100644 index fed00fbad..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/DisplayCrossbonesMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.DisplayCrossbonesMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link DisplayCrossbonesMessage}. - * - * @author Major - */ -public final class DisplayCrossbonesMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(DisplayCrossbonesMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(61); - builder.put(DataType.BYTE, message.isDisplayed() ? 1 : 0); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/DisplayTabInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/DisplayTabInterfaceMessageEncoder.java deleted file mode 100644 index e1366dd23..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/DisplayTabInterfaceMessageEncoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.DisplayTabInterfaceMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link DisplayTabInterfaceMessage}. - * - * @author Chris Fletcher - */ -public final class DisplayTabInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(DisplayTabInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(106); - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getTab()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/EnterAmountMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/EnterAmountMessageEncoder.java deleted file mode 100644 index ea8e33fd9..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/EnterAmountMessageEncoder.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.apollo.game.release.r317; - -import io.netty.buffer.Unpooled; - -import org.apollo.game.message.impl.EnterAmountMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link EnterAmountMessage}. - * - * @author Graham - */ -public final class EnterAmountMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(EnterAmountMessage message) { - return new GamePacket(27, PacketType.FIXED, Unpooled.EMPTY_BUFFER); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/EnteredAmountMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/EnteredAmountMessageDecoder.java deleted file mode 100644 index 1b43ed44c..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/EnteredAmountMessageDecoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.EnteredAmountMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link EnteredAmountMessage}. - * - * @author Graham - */ -public final class EnteredAmountMessageDecoder extends MessageDecoder { - - @Override - public EnteredAmountMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int amount = (int) reader.getUnsigned(DataType.INT); - return new EnteredAmountMessage(amount); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FifthItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FifthItemActionMessageDecoder.java deleted file mode 100644 index a27d2d31c..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FifthItemActionMessageDecoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fifth {@link ItemActionMessage}. - * - * @author Graham - */ -public final class FifthItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new ItemActionMessage(5, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FifthItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FifthItemOptionMessageDecoder.java deleted file mode 100644 index 04ff2f6ed..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FifthItemOptionMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fifth {@link ItemOptionMessage}. - * - * @author Chris Fletcher - */ -public final class FifthItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ItemOptionMessage(5, interfaceId, id, slot); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r317/FifthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FifthNpcActionMessageDecoder.java deleted file mode 100644 index bc813629b..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FifthNpcActionMessageDecoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fifth {@link NpcActionMessage}. - * - * @author Stuart - * @author Major - */ -public final class FifthNpcActionMessageDecoder extends MessageDecoder { - - @Override - public NpcActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new NpcActionMessage(5, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FifthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FifthPlayerActionMessageDecoder.java deleted file mode 100644 index d7a37ae09..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FifthPlayerActionMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fifth {@link PlayerActionMessage}. - * - * @author Major - */ -public final class FifthPlayerActionMessageDecoder extends MessageDecoder { - - @Override - public PlayerActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new PlayerActionMessage(5, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FirstItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FirstItemActionMessageDecoder.java deleted file mode 100644 index 7e38c74fa..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FirstItemActionMessageDecoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link ItemActionMessage}. - * - * @author Graham - */ -public final class FirstItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - return new ItemActionMessage(1, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FirstItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FirstItemOptionMessageDecoder.java deleted file mode 100644 index 5f8c4c46f..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FirstItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link ItemOptionMessage}. - * - * @author Graham - */ -public final class FirstItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int interfaceId = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int id = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE); - - return new ItemOptionMessage(1, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FirstNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FirstNpcActionMessageDecoder.java deleted file mode 100644 index c42f916f1..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FirstNpcActionMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link NpcActionMessage}. - * - * @author Major - */ -public final class FirstNpcActionMessageDecoder extends MessageDecoder { - - @Override - public NpcActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE); - return new NpcActionMessage(1, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FirstObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FirstObjectActionMessageDecoder.java deleted file mode 100644 index b71feb1fa..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FirstObjectActionMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ObjectActionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link ObjectActionMessage}. - * - * @author Graham - */ -public final class FirstObjectActionMessageDecoder extends MessageDecoder { - - @Override - public ObjectActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT); - int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - return new ObjectActionMessage(1, id, new Position(x, y)); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FirstPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FirstPlayerActionMessageDecoder.java deleted file mode 100644 index feb965918..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FirstPlayerActionMessageDecoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link PlayerActionMessage}. - * - * @author Major - */ -public final class FirstPlayerActionMessageDecoder extends MessageDecoder { - - @Override - public PlayerActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT); - return new PlayerActionMessage(1, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FlaggedMouseEventMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FlaggedMouseEventMessageDecoder.java deleted file mode 100644 index 8092a66b5..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FlaggedMouseEventMessageDecoder.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.FlaggedMouseEventMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link org.apollo.game.message.impl.FlaggedMouseEventMessage}. - * - * @author Major - */ -public final class FlaggedMouseEventMessageDecoder extends MessageDecoder { - - @Override - public FlaggedMouseEventMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int read; - if (reader.getLength() == 2) { - read = (int) reader.getUnsigned(DataType.SHORT); - int clicks = read >> 12; - int dX = read >> 6 & 0x3f; - int dY = read & 0x3f; - return new FlaggedMouseEventMessage(clicks, dX, dY, true); - } else if (reader.getLength() == 3) { - read = (int) reader.getUnsigned(DataType.TRI_BYTE) & ~0x800000; - } else { - read = (int) reader.getUnsigned(DataType.INT) & ~0xc0000000; - } - - int clicks = read >> 19; - int x = (read & 0x7f) % 765; - int y = (read & 0x7f) / 765; - - return new FlaggedMouseEventMessage(clicks, x, y, false); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FlashTabInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/FlashTabInterfaceMessageEncoder.java deleted file mode 100644 index f51cb7298..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FlashTabInterfaceMessageEncoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.FlashTabInterfaceMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link FlashTabInterfaceMessage}. - * - * @author Major - */ -public final class FlashTabInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(FlashTabInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(24); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getTab()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FlashingTabClickedMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FlashingTabClickedMessageDecoder.java deleted file mode 100644 index 5d44411e1..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FlashingTabClickedMessageDecoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.FlashingTabClickedMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link FlashingTabClickedMessage}. - * - * @author Major - */ -public final class FlashingTabClickedMessageDecoder extends MessageDecoder { - - @Override - public FlashingTabClickedMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int tab = (int) reader.getUnsigned(DataType.BYTE); - return new FlashingTabClickedMessage(tab); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ForwardPrivateChatMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/ForwardPrivateChatMessageEncoder.java deleted file mode 100644 index 0d4b39b9b..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ForwardPrivateChatMessageEncoder.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apollo.game.release.r317; - -import java.util.concurrent.atomic.AtomicInteger; - -import org.apollo.game.message.impl.ForwardPrivateChatMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageEncoder} for the {@link ForwardPrivateChatMessage}. - * - * @author Major - */ -public final class ForwardPrivateChatMessageEncoder extends MessageEncoder { - - /** - * The amount of messages sent globally, offset by a random variable x, {@code 0 <= x < 100,000,000}. - */ - private static AtomicInteger messageCounter = new AtomicInteger((int) (Math.random() * 100_000_000)); - - @Override - public GamePacket encode(ForwardPrivateChatMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(196, PacketType.VARIABLE_BYTE); - - builder.put(DataType.LONG, NameUtil.encodeBase37(message.getSenderUsername())); - builder.put(DataType.INT, messageCounter.incrementAndGet()); - builder.put(DataType.BYTE, message.getSenderPrivilege().toInteger()); - builder.putBytes(message.getCompressedMessage()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FourthItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FourthItemActionMessageDecoder.java deleted file mode 100644 index 10630a3d4..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FourthItemActionMessageDecoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fourth {@link ItemActionMessage}. - * - * @author Graham - */ -public final class FourthItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - return new ItemActionMessage(4, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FourthItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FourthItemOptionMessageDecoder.java deleted file mode 100644 index 6d21c806f..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FourthItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fourth {@link ItemOptionMessage}. - * - * @author Chris Fletcher - */ -public final class FourthItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int interfaceId = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int slot = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ItemOptionMessage(4, interfaceId, id, slot); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r317/FourthNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FourthNpcActionMessageDecoder.java deleted file mode 100644 index de9226d6b..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FourthNpcActionMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fourth {@link NpcActionMessage}. - * - * @author Stuart - * @author Major - */ -public final class FourthNpcActionMessageDecoder extends MessageDecoder { - - @Override - public NpcActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT); - return new NpcActionMessage(4, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FourthPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/FourthPlayerActionMessageDecoder.java deleted file mode 100644 index 0d5a86e47..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FourthPlayerActionMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fourth {@link PlayerActionMessage}. - * - * @author Major - */ -public final class FourthPlayerActionMessageDecoder extends MessageDecoder { - - @Override - public PlayerActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new PlayerActionMessage(4, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/FriendServerStatusMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/FriendServerStatusMessageEncoder.java deleted file mode 100644 index 9da6868df..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/FriendServerStatusMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.FriendServerStatusMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link FriendServerStatusMessage}. - * - * @author Major - */ -public final class FriendServerStatusMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(FriendServerStatusMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(221); - builder.put(DataType.BYTE, message.getStatusCode()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/IdAssignmentMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/IdAssignmentMessageEncoder.java deleted file mode 100644 index 8c95a2220..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/IdAssignmentMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.IdAssignmentMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link IdAssignmentMessage}. - * - * @author Graham - */ -public final class IdAssignmentMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(IdAssignmentMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(249); - builder.put(DataType.BYTE, DataTransformation.ADD, message.isMembers() ? 1 : 0); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/IgnoreListMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/IgnoreListMessageEncoder.java deleted file mode 100644 index bf8056649..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/IgnoreListMessageEncoder.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.apollo.game.release.r317; - -import java.util.List; - -import org.apollo.game.message.impl.IgnoreListMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageEncoder} for the {@link IgnoreListMessage}. - * - * @author Major - */ -public final class IgnoreListMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(IgnoreListMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(214, PacketType.VARIABLE_SHORT); - - List usernames = message.getUsernames(); - for (String username : usernames) { - builder.put(DataType.LONG, NameUtil.encodeBase37(username)); - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ItemOnItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ItemOnItemMessageDecoder.java deleted file mode 100644 index e2f34d1ac..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ItemOnItemMessageDecoder.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOnItemMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ItemOnItemMessageDecoder}. - * - * @author Chris Fletcher - */ -public final class ItemOnItemMessageDecoder extends MessageDecoder { - - @Override - public ItemOnItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int targetSlot = (int) reader.getUnsigned(DataType.SHORT); - int usedSlot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - int targetId = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int targetInterface = (int) reader.getUnsigned(DataType.SHORT); - - int usedId = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE); - int usedInterface = (int) reader.getUnsigned(DataType.SHORT); - - return new ItemOnItemMessage(usedInterface, usedId, usedSlot, targetInterface, targetId, targetSlot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ItemOnNpcMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ItemOnNpcMessageDecoder.java deleted file mode 100644 index 6d9eefcd3..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ItemOnNpcMessageDecoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOnNpcMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ItemOnNpcMessage}. - * - * @author Lmctruck30 - */ -public final class ItemOnNpcMessageDecoder extends MessageDecoder { - - @Override - public ItemOnNpcMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int index = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int slot = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ItemOnNpcMessage(id, index, slot, interfaceId); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ItemOnObjectMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ItemOnObjectMessageDecoder.java deleted file mode 100644 index 4482a7826..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ItemOnObjectMessageDecoder.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOnObjectMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ItemOnObjectMessage}. - * - * @author Major - */ -public final class ItemOnObjectMessageDecoder extends MessageDecoder { - - @Override - public ItemOnObjectMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - int objectId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int itemId = (int) reader.getUnsigned(DataType.SHORT); - - return new ItemOnObjectMessage(interfaceId, itemId, slot, objectId, x, y); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/KeepAliveMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/KeepAliveMessageDecoder.java deleted file mode 100644 index 83301ef97..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/KeepAliveMessageDecoder.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.KeepAliveMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link KeepAliveMessage}. - * - * @author Graham - */ -public final class KeepAliveMessageDecoder extends MessageDecoder { - - @Override - public KeepAliveMessage decode(GamePacket packet) { - return new KeepAliveMessage(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/LogoutMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/LogoutMessageEncoder.java deleted file mode 100644 index 15a7b7235..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/LogoutMessageEncoder.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.LogoutMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link LogoutMessage}. - * - * @author Graham - */ -public final class LogoutMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(LogoutMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(109); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/MagicOnItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/MagicOnItemMessageDecoder.java deleted file mode 100644 index 677a81db1..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/MagicOnItemMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.MagicOnItemMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link MagicOnItemMessage}. - * - * @author Chris Fletcher - */ -public final class MagicOnItemMessageDecoder extends MessageDecoder { - - @Override - public MagicOnItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int slot = (int) reader.getUnsigned(DataType.SHORT); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - int spell = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new MagicOnItemMessage(interfaceId, id, slot, spell); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/MagicOnNpcMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/MagicOnNpcMessageDecoder.java deleted file mode 100644 index e794d8400..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/MagicOnNpcMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.MagicOnNpcMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link MagicOnNpcMessage} - * - * @author Stuart - */ -public final class MagicOnNpcMessageDecoder extends MessageDecoder { - - @Override - public MagicOnNpcMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int spell = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new MagicOnNpcMessage(index, spell); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/MagicOnPlayerMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/MagicOnPlayerMessageDecoder.java deleted file mode 100644 index 085fe5096..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/MagicOnPlayerMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.MagicOnPlayerMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link MagicOnPlayerMessage} - * - * @author Stuart - */ -public final class MagicOnPlayerMessageDecoder extends MessageDecoder { - - @Override - public MagicOnPlayerMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int index = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int spell = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - - return new MagicOnPlayerMessage(index, spell); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/MobAnimationResetMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/MobAnimationResetMessageEncoder.java deleted file mode 100644 index 14f47f1a0..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/MobAnimationResetMessageEncoder.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.MobAnimationResetMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link MobAnimationResetMessage}. - * - * @author Major - */ -public final class MobAnimationResetMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(MobAnimationResetMessage message) { - return new GamePacketBuilder(1).toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/MobHintIconMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/MobHintIconMessageEncoder.java deleted file mode 100644 index 7ad60c39d..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/MobHintIconMessageEncoder.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.HintIconMessage; -import org.apollo.game.message.impl.MobHintIconMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link MobHintIconMessage}. - * - * @author Major - */ -public final class MobHintIconMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(MobHintIconMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(254); - HintIconMessage.Type type = message.getType(); - builder.put(DataType.BYTE, type.getValue()); - - switch (type) { - case NPC: - case PLAYER: - builder.put(DataType.SHORT, message.getIndex()); - builder.put(DataType.TRI_BYTE, 0); // Dummy bytes - break; - default: - throw new IllegalStateException("Unsupported hint icon type " + type + "."); - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/MouseClickedMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/MouseClickedMessageDecoder.java deleted file mode 100644 index 68c10e24f..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/MouseClickedMessageDecoder.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.MouseClickedMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link MouseClickedMessage} - * - * @author Stuart - */ -public final class MouseClickedMessageDecoder extends MessageDecoder { - - @Override - public MouseClickedMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int value = (int) reader.getUnsigned(DataType.INT); - - long delay = (value >> 20) * 50; - boolean right = (value >> 19 & 0x1) == 1; - - int cords = value & 0x3FFFF; - int x = cords % 765; - int y = cords / 765; - - return new MouseClickedMessage(delay, right, x, y); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/NpcSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/NpcSynchronizationMessageEncoder.java deleted file mode 100644 index a426a7b83..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/NpcSynchronizationMessageEncoder.java +++ /dev/null @@ -1,300 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.NpcSynchronizationMessage; -import org.apollo.game.model.Animation; -import org.apollo.game.model.Direction; -import org.apollo.game.model.Graphic; -import org.apollo.game.model.Position; -import org.apollo.game.sync.block.AnimationBlock; -import org.apollo.game.sync.block.ForceChatBlock; -import org.apollo.game.sync.block.GraphicBlock; -import org.apollo.game.sync.block.HitUpdateBlock; -import org.apollo.game.sync.block.InteractingMobBlock; -import org.apollo.game.sync.block.SecondaryHitUpdateBlock; -import org.apollo.game.sync.block.SynchronizationBlockSet; -import org.apollo.game.sync.block.TransformBlock; -import org.apollo.game.sync.block.TurnToPositionBlock; -import org.apollo.game.sync.seg.AddNpcSegment; -import org.apollo.game.sync.seg.MovementSegment; -import org.apollo.game.sync.seg.SegmentType; -import org.apollo.game.sync.seg.SynchronizationSegment; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link NpcSynchronizationMessage}. - * - * @author Major - */ -public final class NpcSynchronizationMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(NpcSynchronizationMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(65, PacketType.VARIABLE_SHORT); - builder.switchToBitAccess(); - - GamePacketBuilder blockBuilder = new GamePacketBuilder(); - builder.putBits(8, message.getLocalNpcCount()); - - for (SynchronizationSegment segment : message.getSegments()) { - SegmentType type = segment.getType(); - if (type == SegmentType.REMOVE_MOB) { - putRemoveMobUpdate(builder); - } else if (type == SegmentType.ADD_MOB) { - putAddNpcUpdate((AddNpcSegment) segment, message, builder); - putBlocks(segment, blockBuilder); - } else { - putMovementUpdate(segment, message, builder); - putBlocks(segment, blockBuilder); - } - } - - if (blockBuilder.getLength() > 0) { - builder.putBits(14, 16383); - builder.switchToByteAccess(); - builder.putRawBuilder(blockBuilder); - } else { - builder.switchToByteAccess(); - } - - return builder.toGamePacket(); - } - - /** - * Puts an add npc update. - * - * @param seg The segment. - * @param message The message. - * @param builder The builder. - */ - private static void putAddNpcUpdate(AddNpcSegment seg, NpcSynchronizationMessage message, GamePacketBuilder builder) { - boolean updateRequired = seg.getBlockSet().size() > 0; - Position npc = message.getPosition(); - Position other = seg.getPosition(); - builder.putBits(14, seg.getIndex()); - builder.putBits(5, other.getY() - npc.getY()); - builder.putBits(5, other.getX() - npc.getX()); - builder.putBits(1, 0); // discard walking queue - builder.putBits(12, seg.getNpcId()); - builder.putBits(1, updateRequired ? 1 : 0); - } - - /** - * Puts an animation block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) { - Animation animation = block.getAnimation(); - builder.put(DataType.SHORT, DataOrder.LITTLE, animation.getId()); - builder.put(DataType.BYTE, animation.getDelay()); - } - - /** - * Puts the blocks for the specified segment. - * - * @param segment The segment. - * @param builder The block builder. - */ - private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) { - SynchronizationBlockSet blockSet = segment.getBlockSet(); - if (blockSet.size() > 0) { - int mask = 0; - - if (blockSet.contains(AnimationBlock.class)) { - mask |= 0x10; - } - - if (blockSet.contains(HitUpdateBlock.class)) { - mask |= 0x8; - } - - if (blockSet.contains(GraphicBlock.class)) { - mask |= 0x80; - } - - if (blockSet.contains(InteractingMobBlock.class)) { - mask |= 0x20; - } - - if (blockSet.contains(ForceChatBlock.class)) { - mask |= 0x1; - } - - if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - mask |= 0x40; - } - - if (blockSet.contains(TransformBlock.class)) { - mask |= 0x2; - } - - if (blockSet.contains(TurnToPositionBlock.class)) { - mask |= 0x4; - } - - builder.put(DataType.BYTE, mask); - - if (blockSet.contains(AnimationBlock.class)) { - putAnimationBlock(blockSet.get(AnimationBlock.class), builder); - } - - if (blockSet.contains(HitUpdateBlock.class)) { - putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), builder); - } - - if (blockSet.contains(GraphicBlock.class)) { - putGraphicBlock(blockSet.get(GraphicBlock.class), builder); - } - - if (blockSet.contains(InteractingMobBlock.class)) { - putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), builder); - } - - if (blockSet.contains(ForceChatBlock.class)) { - putForceChatBlock(blockSet.get(ForceChatBlock.class), builder); - } - - if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), builder); - } - - if (blockSet.contains(TransformBlock.class)) { - putTransformBlock(blockSet.get(TransformBlock.class), builder); - } - - if (blockSet.contains(TurnToPositionBlock.class)) { - putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), builder); - } - } - } - - /** - * Puts a force chat block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) { - builder.putString(block.getMessage()); - } - - /** - * Puts a graphic block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) { - Graphic graphic = block.getGraphic(); - builder.put(DataType.SHORT, graphic.getId()); - builder.put(DataType.INT, graphic.getHeight() << 16 | graphic.getDelay() & 0xFFFF); - } - - /** - * Puts a hit update block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, DataTransformation.ADD, block.getDamage()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getType()); - builder.put(DataType.BYTE, DataTransformation.ADD, block.getCurrentHealth()); - builder.put(DataType.BYTE, block.getMaximumHealth()); - } - - /** - * Puts an interacting mob block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) { - builder.put(DataType.SHORT, block.getIndex()); - } - - /** - * Puts a movement update for the specified segment. - * - * @param segment The segment. - * @param message The message. - * @param builder The builder. - */ - private static void putMovementUpdate(SynchronizationSegment segment, NpcSynchronizationMessage message, GamePacketBuilder builder) { - boolean updateRequired = segment.getBlockSet().size() > 0; - if (segment.getType() == SegmentType.RUN) { - Direction[] directions = ((MovementSegment) segment).getDirections(); - builder.putBits(1, 1); - builder.putBits(2, 2); - builder.putBits(3, directions[0].toInteger()); - builder.putBits(3, directions[1].toInteger()); - builder.putBits(1, updateRequired ? 1 : 0); - } else if (segment.getType() == SegmentType.WALK) { - Direction[] directions = ((MovementSegment) segment).getDirections(); - builder.putBits(1, 1); - builder.putBits(2, 1); - builder.putBits(3, directions[0].toInteger()); - builder.putBits(1, updateRequired ? 1 : 0); - } else { - if (updateRequired) { - builder.putBits(1, 1); - builder.putBits(2, 0); - } else { - builder.putBits(1, 0); - } - } - } - - /** - * Puts a remove mob update. - * - * @param builder The builder. - */ - private static void putRemoveMobUpdate(GamePacketBuilder builder) { - builder.putBits(1, 1); - builder.putBits(2, 3); - } - - /** - * Puts a second hit update block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getDamage()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getCurrentHealth()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getMaximumHealth()); - } - - /** - * Puts a transform block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putTransformBlock(TransformBlock block, GamePacketBuilder builder) { - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, block.getId()); - } - - /** - * Puts a turn to position block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { - Position position = block.getPosition(); - builder.put(DataType.SHORT, DataOrder.LITTLE, position.getX() * 2 + 1); - builder.put(DataType.SHORT, DataOrder.LITTLE, position.getY() * 2 + 1); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/OpenDialogueInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/OpenDialogueInterfaceMessageEncoder.java deleted file mode 100644 index 6a9352f19..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/OpenDialogueInterfaceMessageEncoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.OpenDialogueInterfaceMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenDialogueInterfaceMessage}. - * - * @author Chris Fletcher - */ -public final class OpenDialogueInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenDialogueInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(164); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getInterfaceId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/OpenDialogueOverlayMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/OpenDialogueOverlayMessageEncoder.java deleted file mode 100644 index 49017e0f2..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/OpenDialogueOverlayMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.OpenDialogueOverlayMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenDialogueOverlayMessage}. - * - * @author Major - */ -public final class OpenDialogueOverlayMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenDialogueOverlayMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(218); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/OpenInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/OpenInterfaceMessageEncoder.java deleted file mode 100644 index d5aafeb3e..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/OpenInterfaceMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.OpenInterfaceMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenInterfaceMessage}. - * - * @author Graham - */ -public final class OpenInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(97); - builder.put(DataType.SHORT, message.getId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/OpenInterfaceSidebarMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/OpenInterfaceSidebarMessageEncoder.java deleted file mode 100644 index 24cb565ec..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/OpenInterfaceSidebarMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.OpenInterfaceSidebarMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenInterfaceSidebarMessage}. - * - * @author Graham - */ -public final class OpenInterfaceSidebarMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenInterfaceSidebarMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(248); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getInterfaceId()); - builder.put(DataType.SHORT, message.getSidebarId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/OpenOverlayMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/OpenOverlayMessageEncoder.java deleted file mode 100644 index d7baafd1a..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/OpenOverlayMessageEncoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.OpenOverlayMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenOverlayMessage}. - * - * @author Major - */ -public final class OpenOverlayMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenOverlayMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(208); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getOverlayId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/OpenSidebarMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/OpenSidebarMessageEncoder.java deleted file mode 100644 index f9b4f073c..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/OpenSidebarMessageEncoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.OpenSidebarMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenSidebarMessage}. - * - * @author Major - */ -public final class OpenSidebarMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenSidebarMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(142); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getSidebarId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/PlayerDesignMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/PlayerDesignMessageDecoder.java deleted file mode 100644 index 9fa85a634..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/PlayerDesignMessageDecoder.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.PlayerDesignMessage; -import org.apollo.game.model.Appearance; -import org.apollo.game.model.entity.setting.Gender; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link PlayerDesignMessage}. - * - * @author Graham - */ -public final class PlayerDesignMessageDecoder extends MessageDecoder { - - @Override - public PlayerDesignMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int genderIntValue = (int) reader.getUnsigned(DataType.BYTE); - - int[] style = new int[7]; - for (int i = 0; i < style.length; i++) { - style[i] = (int) reader.getUnsigned(DataType.BYTE); - } - - int[] color = new int[5]; - for (int i = 0; i < color.length; i++) { - color[i] = (int) reader.getUnsigned(DataType.BYTE); - } - - Gender gender = genderIntValue == Gender.MALE.toInteger() ? Gender.MALE : Gender.FEMALE; - - return new PlayerDesignMessage(new Appearance(gender, style, color)); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/PlayerSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/PlayerSynchronizationMessageEncoder.java deleted file mode 100644 index b628ded53..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/PlayerSynchronizationMessageEncoder.java +++ /dev/null @@ -1,460 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.cache.def.EquipmentDefinition; -import org.apollo.game.message.impl.PlayerSynchronizationMessage; -import org.apollo.game.model.Animation; -import org.apollo.game.model.Appearance; -import org.apollo.game.model.Direction; -import org.apollo.game.model.Graphic; -import org.apollo.game.model.Item; -import org.apollo.game.model.Position; -import org.apollo.game.model.entity.EquipmentConstants; -import org.apollo.game.model.entity.setting.Gender; -import org.apollo.game.model.inv.Inventory; -import org.apollo.game.sync.block.AnimationBlock; -import org.apollo.game.sync.block.AppearanceBlock; -import org.apollo.game.sync.block.ChatBlock; -import org.apollo.game.sync.block.ForceChatBlock; -import org.apollo.game.sync.block.ForceMovementBlock; -import org.apollo.game.sync.block.GraphicBlock; -import org.apollo.game.sync.block.HitUpdateBlock; -import org.apollo.game.sync.block.InteractingMobBlock; -import org.apollo.game.sync.block.SecondaryHitUpdateBlock; -import org.apollo.game.sync.block.SynchronizationBlockSet; -import org.apollo.game.sync.block.TurnToPositionBlock; -import org.apollo.game.sync.seg.AddPlayerSegment; -import org.apollo.game.sync.seg.MovementSegment; -import org.apollo.game.sync.seg.SegmentType; -import org.apollo.game.sync.seg.SynchronizationSegment; -import org.apollo.game.sync.seg.TeleportSegment; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link PlayerSynchronizationMessage}. - * - * @author Graham - * @author Major - */ -public final class PlayerSynchronizationMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(PlayerSynchronizationMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(81, PacketType.VARIABLE_SHORT); - builder.switchToBitAccess(); - - GamePacketBuilder blockBuilder = new GamePacketBuilder(); - - putMovementUpdate(message.getSegment(), message, builder); - putBlocks(message.getSegment(), blockBuilder); - - builder.putBits(8, message.getLocalPlayers()); - - for (SynchronizationSegment segment : message.getSegments()) { - SegmentType type = segment.getType(); - if (type == SegmentType.REMOVE_MOB) { - putRemovePlayerUpdate(builder); - } else if (type == SegmentType.ADD_MOB) { - putAddPlayerUpdate((AddPlayerSegment) segment, message, builder); - putBlocks(segment, blockBuilder); - } else { - putMovementUpdate(segment, message, builder); - putBlocks(segment, blockBuilder); - } - } - - if (blockBuilder.getLength() > 0) { - builder.putBits(11, 2047); - builder.switchToByteAccess(); - builder.putRawBuilder(blockBuilder); - } else { - builder.switchToByteAccess(); - } - - return builder.toGamePacket(); - } - - /** - * Puts an add player update. - * - * @param seg The segment. - * @param message The message. - * @param builder The builder. - */ - private static void putAddPlayerUpdate(AddPlayerSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) { - boolean updateRequired = seg.getBlockSet().size() > 0; - Position player = message.getPosition(); - Position other = seg.getPosition(); - builder.putBits(11, seg.getIndex()); - builder.putBits(1, updateRequired ? 1 : 0); - builder.putBits(1, 1); // discard walking queue? - builder.putBits(5, other.getY() - player.getY()); - builder.putBits(5, other.getX() - player.getX()); - } - - /** - * Puts an animation block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) { - Animation animation = block.getAnimation(); - builder.put(DataType.SHORT, DataOrder.LITTLE, animation.getId()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, animation.getDelay()); - } - - /** - * Puts an appearance block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) { - Appearance appearance = block.getAppearance(); - GamePacketBuilder playerProperties = new GamePacketBuilder(); - - playerProperties.put(DataType.BYTE, appearance.getGender().toInteger()); - playerProperties.put(DataType.BYTE, 0); - - if (block.appearingAsNpc()) { - playerProperties.put(DataType.BYTE, 255); - playerProperties.put(DataType.BYTE, 255); - playerProperties.put(DataType.SHORT, block.getNpcId()); - } else { - Inventory equipment = block.getEquipment(); - int[] style = appearance.getStyle(); - Item item, chest, helm; - - for (int slot = 0; slot < 4; slot++) { - if ((item = equipment.get(slot)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.BYTE, 0); - } - } - - if ((chest = equipment.get(EquipmentConstants.CHEST)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + chest.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[2]); - } - - if ((item = equipment.get(EquipmentConstants.SHIELD)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.BYTE, 0); - } - - if (chest != null) { - EquipmentDefinition def = EquipmentDefinition.lookup(chest.getId()); - if (def != null && !def.isFullBody()) { - playerProperties.put(DataType.SHORT, 0x100 + style[3]); - } else { - playerProperties.put(DataType.BYTE, 0); - } - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[3]); - } - - if ((item = equipment.get(EquipmentConstants.LEGS)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[5]); - } - - if ((helm = equipment.get(EquipmentConstants.HAT)) != null) { - EquipmentDefinition def = EquipmentDefinition.lookup(helm.getId()); - if (def != null && !def.isFullHat() && !def.isFullMask()) { - playerProperties.put(DataType.SHORT, 0x100 + style[0]); - } else { - playerProperties.put(DataType.BYTE, 0); - } - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[0]); - } - - if ((item = equipment.get(EquipmentConstants.HANDS)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[4]); - } - - if ((item = equipment.get(EquipmentConstants.FEET)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[6]); - } - - EquipmentDefinition def = null; - if (helm != null) { - def = EquipmentDefinition.lookup(helm.getId()); - } - if (def != null && (def.isFullMask()) || appearance.getGender() == Gender.FEMALE) { - playerProperties.put(DataType.BYTE, 0); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[1]); - } - } - - int[] colors = appearance.getColors(); - for (int color : colors) { - playerProperties.put(DataType.BYTE, color); - } - - playerProperties.put(DataType.SHORT, 0x328); // stand - playerProperties.put(DataType.SHORT, 0x337); // stand turn - playerProperties.put(DataType.SHORT, 0x333); // walk - playerProperties.put(DataType.SHORT, 0x334); // turn 180 - playerProperties.put(DataType.SHORT, 0x335); // turn 90 cw - playerProperties.put(DataType.SHORT, 0x336); // turn 90 ccw - playerProperties.put(DataType.SHORT, 0x338); // run - - playerProperties.put(DataType.LONG, block.getName()); - playerProperties.put(DataType.BYTE, block.getCombatLevel()); - playerProperties.put(DataType.SHORT, block.getSkillLevel()); - - builder.put(DataType.BYTE, DataTransformation.NEGATE, playerProperties.getLength()); - - builder.putRawBuilder(playerProperties); - } - - /** - * Puts the blocks for the specified segment. - * - * @param segment The segment. - * @param builder The block builder. - */ - private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) { - SynchronizationBlockSet blockSet = segment.getBlockSet(); - if (blockSet.size() > 0) { - int mask = 0; - - if (blockSet.contains(ForceMovementBlock.class)) { - mask |= 0x400; - } - if (blockSet.contains(GraphicBlock.class)) { - mask |= 0x100; - } - if (blockSet.contains(AnimationBlock.class)) { - mask |= 0x8; - } - if (blockSet.contains(ForceChatBlock.class)) { - mask |= 0x4; - } - if (blockSet.contains(ChatBlock.class)) { - mask |= 0x80; - } - if (blockSet.contains(InteractingMobBlock.class)) { - mask |= 0x1; - } - if (blockSet.contains(AppearanceBlock.class)) { - mask |= 0x10; - } - if (blockSet.contains(TurnToPositionBlock.class)) { - mask |= 0x2; - } - if (blockSet.contains(HitUpdateBlock.class)) { - mask |= 0x20; - } - if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - mask |= 0x200; - } - - if (mask >= 0x100) { - mask |= 0x40; - builder.put(DataType.SHORT, DataOrder.LITTLE, mask); - } else { - builder.put(DataType.BYTE, mask); - } - - if (blockSet.contains(ForceMovementBlock.class)) { - putForceMovementBlock(blockSet.get(ForceMovementBlock.class), builder); - } - if (blockSet.contains(GraphicBlock.class)) { - putGraphicBlock(blockSet.get(GraphicBlock.class), builder); - } - if (blockSet.contains(AnimationBlock.class)) { - putAnimationBlock(blockSet.get(AnimationBlock.class), builder); - } - if (blockSet.contains(ForceChatBlock.class)) { - putForceChatBlock(blockSet.get(ForceChatBlock.class), builder); - } - if (blockSet.contains(ChatBlock.class)) { - putChatBlock(blockSet.get(ChatBlock.class), builder); - } - if (blockSet.contains(InteractingMobBlock.class)) { - putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), builder); - } - if (blockSet.contains(AppearanceBlock.class)) { - putAppearanceBlock(blockSet.get(AppearanceBlock.class), builder); - } - if (blockSet.contains(TurnToPositionBlock.class)) { - putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), builder); - } - if (blockSet.contains(HitUpdateBlock.class)) { - putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), builder); - } - if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), builder); - } - } - } - - /** - * Puts a chat block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putChatBlock(ChatBlock block, GamePacketBuilder builder) { - byte[] bytes = block.getCompressedMessage(); - builder.put(DataType.SHORT, DataOrder.LITTLE, block.getTextColor() << 8 | block.getTextEffects()); - builder.put(DataType.BYTE, block.getPrivilegeLevel().toInteger()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, bytes.length); - builder.putBytesReverse(bytes); - } - - /** - * Puts a force chat block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) { - builder.putString(block.getMessage()); - } - - /** - * Puts a force movement block in the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putForceMovementBlock(ForceMovementBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getInitialX()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getInitialY()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getFinalX()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getFinalY()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, block.getTravelDurationX()); - builder.put(DataType.SHORT, DataTransformation.ADD, block.getTravelDurationY()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getDirection().toInteger()); - } - - /** - * Puts a graphic block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) { - Graphic graphic = block.getGraphic(); - builder.put(DataType.SHORT, DataOrder.LITTLE, graphic.getId()); - builder.put(DataType.INT, graphic.getHeight() << 16 | graphic.getDelay() & 0xFFFF); - } - - /** - * Puts a hit update block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, block.getDamage()); - builder.put(DataType.BYTE, DataTransformation.ADD, block.getType()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getCurrentHealth()); - builder.put(DataType.BYTE, block.getMaximumHealth()); - } - - /** - * Puts an interacting mob block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) { - builder.put(DataType.SHORT, DataOrder.LITTLE, block.getIndex()); - } - - /** - * Puts a movement update for the specified segment. - * - * @param seg The segment. - * @param message The message. - * @param builder The builder. - */ - private static void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) { - boolean updateRequired = seg.getBlockSet().size() > 0; - if (seg.getType() == SegmentType.TELEPORT) { - Position position = ((TeleportSegment) seg).getDestination(); - builder.putBits(1, 1); - builder.putBits(2, 3); - builder.putBits(2, position.getHeight()); - builder.putBits(1, message.hasRegionChanged() ? 0 : 1); - builder.putBits(1, updateRequired ? 1 : 0); - builder.putBits(7, position.getLocalY(message.getLastKnownRegion())); - builder.putBits(7, position.getLocalX(message.getLastKnownRegion())); - } else if (seg.getType() == SegmentType.RUN) { - Direction[] directions = ((MovementSegment) seg).getDirections(); - builder.putBits(1, 1); - builder.putBits(2, 2); - builder.putBits(3, directions[0].toInteger()); - builder.putBits(3, directions[1].toInteger()); - builder.putBits(1, updateRequired ? 1 : 0); - } else if (seg.getType() == SegmentType.WALK) { - Direction[] directions = ((MovementSegment) seg).getDirections(); - builder.putBits(1, 1); - builder.putBits(2, 1); - builder.putBits(3, directions[0].toInteger()); - builder.putBits(1, updateRequired ? 1 : 0); - } else { - if (updateRequired) { - builder.putBits(1, 1); - builder.putBits(2, 0); - } else { - builder.putBits(1, 0); - } - } - } - - /** - * Puts a remove player update. - * - * @param builder The builder. - */ - private static void putRemovePlayerUpdate(GamePacketBuilder builder) { - builder.putBits(1, 1); - builder.putBits(2, 3); - } - - /** - * Puts a Second Hit Update block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, block.getDamage()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType()); - builder.put(DataType.BYTE, block.getCurrentHealth()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getMaximumHealth()); - } - - /** - * Puts a Turn To Position block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { - Position pos = block.getPosition(); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, pos.getX() * 2 + 1); - builder.put(DataType.SHORT, DataOrder.LITTLE, pos.getY() * 2 + 1); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/PositionHintIconMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/PositionHintIconMessageEncoder.java deleted file mode 100644 index 73df34dfe..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/PositionHintIconMessageEncoder.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.HintIconMessage; -import org.apollo.game.message.impl.PositionHintIconMessage; -import org.apollo.game.message.impl.HintIconMessage.Type; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link PositionHintIconMessage}. - */ -public final class PositionHintIconMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(PositionHintIconMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(254); - HintIconMessage.Type type = message.getType(); - - if (type == Type.PLAYER || type == Type.NPC) { - throw new IllegalStateException("Unsupported hint icon type " + type + "."); - } - - builder.put(DataType.BYTE, type.getValue()); - - Position position = message.getPosition(); - builder.put(DataType.SHORT, position.getX()); - builder.put(DataType.SHORT, position.getY()); - builder.put(DataType.BYTE, message.getHeight()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/PrivacyOptionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/PrivacyOptionMessageEncoder.java deleted file mode 100644 index 043b8432c..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/PrivacyOptionMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.PrivacyOptionMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link PrivacyOptionMessage}. - * - * @author Kyle Stevenson - */ -public final class PrivacyOptionMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(final PrivacyOptionMessage message) { - final GamePacketBuilder builder = new GamePacketBuilder(206); - - builder.put(DataType.BYTE, message.getChatPrivacy().toInteger(true)); - builder.put(DataType.BYTE, message.getFriendPrivacy().toInteger(true)); - builder.put(DataType.BYTE, message.getTradePrivacy().toInteger(true)); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/PrivateChatMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/PrivateChatMessageDecoder.java deleted file mode 100644 index 7d73af118..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/PrivateChatMessageDecoder.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.PrivateChatMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; -import org.apollo.util.TextUtil; - -/** - * A {@link MessageDecoder} for the {@link PrivateChatMessage}. - * - * @author Major - */ -public final class PrivateChatMessageDecoder extends MessageDecoder { - - @Override - public PrivateChatMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - int length = packet.getLength() - Long.BYTES; - - byte[] originalCompressed = new byte[length]; - reader.getBytes(originalCompressed); - - String decompressed = TextUtil.decompress(originalCompressed, length); - decompressed = TextUtil.filterInvalidCharacters(decompressed); - decompressed = TextUtil.capitalize(decompressed); - - byte[] recompressed = new byte[length]; - TextUtil.compress(decompressed, recompressed); - - return new PrivateChatMessage(new String(decompressed), recompressed, username); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/PublicChatMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/PublicChatMessageDecoder.java deleted file mode 100644 index 42e4abcaf..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/PublicChatMessageDecoder.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.PublicChatMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.TextUtil; - -/** - * A {@link MessageDecoder} for the {@link PublicChatMessage}. - * - * @author Graham - */ -public final class PublicChatMessageDecoder extends MessageDecoder { - - @Override - public PublicChatMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int effects = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT); - int color = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.SUBTRACT); - int length = packet.getLength() - 2; - - byte[] originalCompressed = new byte[length]; - reader.getBytesReverse(DataTransformation.ADD, originalCompressed); - - String uncompressed = TextUtil.decompress(originalCompressed, length); - uncompressed = TextUtil.filterInvalidCharacters(uncompressed); - uncompressed = TextUtil.capitalize(uncompressed); - - byte[] recompressed = new byte[length]; - TextUtil.compress(uncompressed, recompressed); - // in case invalid data gets sent, this effectively verifies it - - return new PublicChatMessage(uncompressed, recompressed, color, effects); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/RegionChangeMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/RegionChangeMessageEncoder.java deleted file mode 100644 index 71e070ac3..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/RegionChangeMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.RegionChangeMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link RegionChangeMessage}. - * - * @author Graham - */ -public final class RegionChangeMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(RegionChangeMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(73); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getPosition().getCentralRegionX()); - builder.put(DataType.SHORT, message.getPosition().getCentralRegionY()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/Release317.java b/game/src/main/java/org/apollo/game/release/r317/Release317.java deleted file mode 100644 index 8cfa4fc4c..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/Release317.java +++ /dev/null @@ -1,239 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ClearRegionMessage; -import org.apollo.game.message.impl.CloseInterfaceMessage; -import org.apollo.game.message.impl.ConfigMessage; -import org.apollo.game.message.impl.DisplayCrossbonesMessage; -import org.apollo.game.message.impl.DisplayTabInterfaceMessage; -import org.apollo.game.message.impl.EnterAmountMessage; -import org.apollo.game.message.impl.FlashTabInterfaceMessage; -import org.apollo.game.message.impl.ForwardPrivateChatMessage; -import org.apollo.game.message.impl.FriendServerStatusMessage; -import org.apollo.game.message.impl.GroupedRegionUpdateMessage; -import org.apollo.game.message.impl.IdAssignmentMessage; -import org.apollo.game.message.impl.IgnoreListMessage; -import org.apollo.game.message.impl.LogoutMessage; -import org.apollo.game.message.impl.MobHintIconMessage; -import org.apollo.game.message.impl.NpcSynchronizationMessage; -import org.apollo.game.message.impl.OpenDialogueInterfaceMessage; -import org.apollo.game.message.impl.OpenDialogueOverlayMessage; -import org.apollo.game.message.impl.OpenInterfaceMessage; -import org.apollo.game.message.impl.OpenInterfaceSidebarMessage; -import org.apollo.game.message.impl.OpenOverlayMessage; -import org.apollo.game.message.impl.OpenSidebarMessage; -import org.apollo.game.message.impl.PlayerSynchronizationMessage; -import org.apollo.game.message.impl.PositionHintIconMessage; -import org.apollo.game.message.impl.PrivacyOptionMessage; -import org.apollo.game.message.impl.RegionChangeMessage; -import org.apollo.game.message.impl.RemoveObjectMessage; -import org.apollo.game.message.impl.RemoveTileItemMessage; -import org.apollo.game.message.impl.SendFriendMessage; -import org.apollo.game.message.impl.SendObjectMessage; -import org.apollo.game.message.impl.SendPublicTileItemMessage; -import org.apollo.game.message.impl.SendTileItemMessage; -import org.apollo.game.message.impl.ServerChatMessage; -import org.apollo.game.message.impl.SetPlayerActionMessage; -import org.apollo.game.message.impl.SetUpdatedRegionMessage; -import org.apollo.game.message.impl.SetWidgetItemModelMessage; -import org.apollo.game.message.impl.SetWidgetModelAnimationMessage; -import org.apollo.game.message.impl.SetWidgetModelMessage; -import org.apollo.game.message.impl.SetWidgetNpcModelMessage; -import org.apollo.game.message.impl.SetWidgetPlayerModelMessage; -import org.apollo.game.message.impl.SetWidgetTextMessage; -import org.apollo.game.message.impl.SetWidgetVisibilityMessage; -import org.apollo.game.message.impl.SwitchTabInterfaceMessage; -import org.apollo.game.message.impl.UpdateItemsMessage; -import org.apollo.game.message.impl.UpdateRunEnergyMessage; -import org.apollo.game.message.impl.UpdateSkillMessage; -import org.apollo.game.message.impl.UpdateSlottedItemsMessage; -import org.apollo.game.message.impl.UpdateTileItemMessage; -import org.apollo.game.message.impl.UpdateWeightMessage; -import org.apollo.net.meta.PacketMetaDataGroup; -import org.apollo.net.release.Release; - -/** - * A {@link Release} implementation for the 317 protocol. - * - * @author Graham - */ -public final class Release317 extends Release { - - /** - * The incoming packet lengths array. - */ - public static final int[] PACKET_LENGTHS = { - 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, // 0 - 0, 0, 0, 0, 8, 0, 6, 2, 2, 0, // 10 - 0, 2, 0, 6, 0, 12, 0, 0, 0, 0, // 20 - 0, 0, 0, 0, 0, 8, 4, 0, 0, 2, // 30 - 2, 6, 0, 6, 0, -1, 0, 0, 0, 0, // 40 - 0, 0, 0, 12, 0, 0, 0, 8, 8, 0, // 50 - 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, // 60 - 6, 0, 2, 2, 8, 6, 0, -1, 0, 6, // 70 - 0, 0, 0, 0, 0, 1, 4, 6, 0, 0, // 80 - 0, 0, 0, 0, 0, 3, 0, 0, -1, 0, // 90 - 0, 13, 0, -1, 0, 0, 0, 0, 0, 0, // 100 - 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, // 110 - 1, 0, 6, 0, 0, 0, -1, 0, 2, 6, // 120 - 0, 4, 6, 8, 0, 6, 0, 0, 0, 2, // 130 - 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, // 140 - 0, 0, 1, 2, 0, 2, 6, 0, 0, 0, // 150 - 0, 0, 0, 0, -1, -1, 0, 0, 0, 0, // 160 - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 170 - 0, 8, 0, 3, 0, 2, 0, 0, 8, 1, // 180 - 0, 0, 12, 0, 0, 0, 0, 0, 0, 0, // 190 - 2, 0, 0, 0, 0, 0, 0, 0, 4, 0, // 200 - 4, 0, 0, 0, 7, 8, 0, 0, 10, 0, // 210 - 0, 0, 0, 0, 0, 0, -1, 0, 6, 0, // 220 - 1, 0, 0, 0, 6, 0, 6, 8, 1, 0, // 230 - 0, 4, 0, 0, 0, 0, -1, 0, -1, 4, // 240 - 0, 0, 6, 6, 0, 0, // 250 - }; - - /** - * Creates and initialises this release. - */ - public Release317() { - super(317, PacketMetaDataGroup.createFromArray(PACKET_LENGTHS)); - init(); - } - - /** - * Initialises this release by registering encoders and decoders. - */ - private void init() { - // register decoders - WalkMessageDecoder walkMessageDecoder = new WalkMessageDecoder(); - register(248, walkMessageDecoder); - register(164, walkMessageDecoder); - register(98, walkMessageDecoder); - - register(0, new KeepAliveMessageDecoder()); - register(101, new PlayerDesignMessageDecoder()); - register(4, new PublicChatMessageDecoder()); - register(103, new CommandMessageDecoder()); - register(214, new SwitchItemMessageDecoder()); - - register(132, new FirstObjectActionMessageDecoder()); - register(252, new SecondObjectActionMessageDecoder()); - register(70, new ThirdObjectActionMessageDecoder()); - - register(122, new FirstItemOptionMessageDecoder()); - register(41, new SecondItemOptionMessageDecoder()); - register(16, new ThirdItemOptionMessageDecoder()); - register(75, new FourthItemOptionMessageDecoder()); - register(87, new FifthItemOptionMessageDecoder()); - - register(145, new FirstItemActionMessageDecoder()); - register(117, new SecondItemActionMessageDecoder()); - register(43, new ThirdItemActionMessageDecoder()); - register(129, new FourthItemActionMessageDecoder()); - register(135, new FifthItemActionMessageDecoder()); - - register(185, new ButtonMessageDecoder()); - register(130, new ClosedInterfaceMessageDecoder()); - register(208, new EnteredAmountMessageDecoder()); - register(40, new DialogueContinueMessageDecoder()); - register(120, new FlashingTabClickedMessageDecoder()); - - register(53, new ItemOnItemMessageDecoder()); - register(57, new ItemOnNpcMessageDecoder()); - register(237, new MagicOnItemMessageDecoder()); - register(249, new MagicOnPlayerMessageDecoder()); - register(131, new MagicOnNpcMessageDecoder()); - - register(3, new FocusUpdateMessageDecoder()); - register(45, new FlaggedMouseEventMessageDecoder()); - register(241, new MouseClickedMessageDecoder()); - register(86, new ArrowKeyMessageDecoder()); - register(95, new PrivacyOptionMessageDecoder()); - - SpamPacketMessageDecoder spamMessageDecoder = new SpamPacketMessageDecoder(); - register(77, spamMessageDecoder); - register(78, spamMessageDecoder); - register(165, spamMessageDecoder); - register(189, spamMessageDecoder); - register(210, spamMessageDecoder); - register(226, spamMessageDecoder); - register(121, spamMessageDecoder); - - register(155, new FirstNpcActionMessageDecoder()); - register(72, new SecondNpcActionMessageDecoder()); - register(17, new ThirdNpcActionMessageDecoder()); - register(21, new FourthNpcActionMessageDecoder()); - register(18, new FifthNpcActionMessageDecoder()); - - register(236, new TakeTileItemMessageDecoder()); - register(192, new ItemOnObjectMessageDecoder()); - - register(128, new FirstPlayerActionMessageDecoder()); - register(153, new SecondPlayerActionMessageDecoder()); - register(73, new ThirdPlayerActionMessageDecoder()); - register(139, new FourthPlayerActionMessageDecoder()); - register(39, new FifthPlayerActionMessageDecoder()); - - register(188, new AddFriendMessageDecoder()); - register(133, new AddIgnoreMessageDecoder()); - register(215, new RemoveFriendMessageDecoder()); - register(74, new RemoveIgnoreMessageDecoder()); - register(126, new PrivateChatMessageDecoder()); - - register(218, new ReportAbuseMessageDecoder()); - - // register encoders - register(IdAssignmentMessage.class, new IdAssignmentMessageEncoder()); - register(RegionChangeMessage.class, new RegionChangeMessageEncoder()); - register(ServerChatMessage.class, new ServerMessageMessageEncoder()); - register(PlayerSynchronizationMessage.class, new PlayerSynchronizationMessageEncoder()); - register(OpenInterfaceMessage.class, new OpenInterfaceMessageEncoder()); - register(CloseInterfaceMessage.class, new CloseInterfaceMessageEncoder()); - register(SwitchTabInterfaceMessage.class, new SwitchTabInterfaceMessageEncoder()); - register(LogoutMessage.class, new LogoutMessageEncoder()); - register(UpdateItemsMessage.class, new UpdateItemsMessageEncoder()); - register(UpdateSlottedItemsMessage.class, new UpdateSlottedItemsMessageEncoder()); - register(UpdateSkillMessage.class, new UpdateSkillMessageEncoder()); - register(OpenInterfaceSidebarMessage.class, new OpenInterfaceSidebarMessageEncoder()); - register(EnterAmountMessage.class, new EnterAmountMessageEncoder()); - register(SetWidgetTextMessage.class, new SetWidgetTextMessageEncoder()); - register(NpcSynchronizationMessage.class, new NpcSynchronizationMessageEncoder()); - - register(SetWidgetVisibilityMessage.class, new SetWidgetVisibilityMessageEncoder()); - register(SetWidgetItemModelMessage.class, new SetWidgetItemModelMessageEncoder()); - register(SetWidgetNpcModelMessage.class, new SetWidgetNpcModelMessageEncoder()); - register(SetWidgetPlayerModelMessage.class, new SetWidgetPlayerModelMessageEncoder()); - register(SetWidgetModelAnimationMessage.class, new SetWidgetModelAnimationMessageEncoder()); - register(SetWidgetModelMessage.class, new SetWidgetModelMessageEncoder()); - - register(ConfigMessage.class, new ConfigMessageEncoder()); - register(DisplayTabInterfaceMessage.class, new DisplayTabInterfaceMessageEncoder()); - register(SetUpdatedRegionMessage.class, new SetUpdatedRegionMessageEncoder()); - register(UpdateRunEnergyMessage.class, new UpdateRunEnergyMessageEncoder()); - register(PrivacyOptionMessage.class, new PrivacyOptionMessageEncoder()); - register(OpenDialogueInterfaceMessage.class, new OpenDialogueInterfaceMessageEncoder()); - register(UpdateWeightMessage.class, new UpdateWeightMessageEncoder()); - register(SetPlayerActionMessage.class, new SetPlayerActionMessageEncoder()); - register(DisplayCrossbonesMessage.class, new DisplayCrossbonesMessageEncoder()); - - register(SendPublicTileItemMessage.class, new AddGlobalTileItemMessageEncoder()); - register(SendTileItemMessage.class, new AddTileItemMessageEncoder()); - register(UpdateTileItemMessage.class, new UpdateTileItemMessageEncoder()); - register(RemoveTileItemMessage.class, new RemoveTileItemMessageEncoder()); - register(SendObjectMessage.class, new SendObjectMessageEncoder()); - register(RemoveObjectMessage.class, new RemoveObjectMessageEncoder()); - - register(GroupedRegionUpdateMessage.class, new GroupedRegionUpdateMessageEncoder(this)); - register(ClearRegionMessage.class, new ClearRegionMessageEncoder()); - - register(ForwardPrivateChatMessage.class, new ForwardPrivateChatMessageEncoder()); - register(FriendServerStatusMessage.class, new FriendServerStatusMessageEncoder()); - register(IgnoreListMessage.class, new IgnoreListMessageEncoder()); - register(SendFriendMessage.class, new SendFriendMessageEncoder()); - register(MobHintIconMessage.class, new MobHintIconMessageEncoder()); - register(PositionHintIconMessage.class, new PositionHintIconMessageEncoder()); - register(FlashTabInterfaceMessage.class, new FlashTabInterfaceMessageEncoder()); - register(OpenSidebarMessage.class, new OpenSidebarMessageEncoder()); - register(OpenOverlayMessage.class, new OpenOverlayMessageEncoder()); - register(OpenDialogueOverlayMessage.class, new OpenDialogueOverlayMessageEncoder()); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/RemoveFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/RemoveFriendMessageDecoder.java deleted file mode 100644 index ffbaafc32..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/RemoveFriendMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.RemoveFriendMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageDecoder} for the {@link RemoveFriendMessage}. - * - * @author Major - */ -public final class RemoveFriendMessageDecoder extends MessageDecoder { - - @Override - public RemoveFriendMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - return new RemoveFriendMessage(username); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/RemoveIgnoreMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/RemoveIgnoreMessageDecoder.java deleted file mode 100644 index aee1abce2..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/RemoveIgnoreMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.RemoveIgnoreMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageDecoder} for the {@link RemoveIgnoreMessage}. - * - * @author Major - */ -public final class RemoveIgnoreMessageDecoder extends MessageDecoder { - - @Override - public RemoveIgnoreMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - return new RemoveIgnoreMessage(username); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/RemoveObjectMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/RemoveObjectMessageEncoder.java deleted file mode 100644 index 61dc247c3..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/RemoveObjectMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.RemoveObjectMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link RemoveObjectMessage}. - * - * @author Major - */ -public final class RemoveObjectMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(RemoveObjectMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(101); - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getType() << 2 | message.getOrientation()); - builder.put(DataType.BYTE, message.getPositionOffset()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/RemoveTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/RemoveTileItemMessageEncoder.java deleted file mode 100644 index c844f79b5..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/RemoveTileItemMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.RemoveTileItemMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link RemoveTileItemMessage}. - * - * @author Major - */ -public final class RemoveTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(RemoveTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(156); - builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); - builder.put(DataType.SHORT, message.getId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SecondItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/SecondItemActionMessageDecoder.java deleted file mode 100644 index a5df384eb..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SecondItemActionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the second {@link ItemActionMessage}. - * - * @author Graham - */ -public final class SecondItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - - return new ItemActionMessage(2, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SecondItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/SecondItemOptionMessageDecoder.java deleted file mode 100644 index 3d13490c7..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SecondItemOptionMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ItemOptionMessage}. - * - * @author Graham - */ -public final class SecondItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int id = (int) reader.getUnsigned(DataType.SHORT); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ItemOptionMessage(2, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SecondObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/SecondObjectActionMessageDecoder.java deleted file mode 100644 index e5e8f2fba..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SecondObjectActionMessageDecoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ObjectActionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the second {@link ObjectActionMessage}. - * - * @author Graham - */ -public final class SecondObjectActionMessageDecoder extends MessageDecoder { - - @Override - public ObjectActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int x = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ObjectActionMessage(2, id, new Position(x, y)); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SecondPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/SecondPlayerActionMessageDecoder.java deleted file mode 100644 index 32c081305..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SecondPlayerActionMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the second {@link PlayerActionMessage}. - * - * @author Major - */ -public final class SecondPlayerActionMessageDecoder extends MessageDecoder { - - @Override - public PlayerActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new PlayerActionMessage(2, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SendFriendMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SendFriendMessageEncoder.java deleted file mode 100644 index 932dca8ef..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SendFriendMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SendFriendMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageEncoder} for the {@link SendFriendMessage}. - * - * @author Major - */ -public final class SendFriendMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendFriendMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(50); - builder.put(DataType.LONG, NameUtil.encodeBase37(message.getUsername())); - builder.put(DataType.BYTE, message.getEncodedWorld()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ServerMessageMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/ServerMessageMessageEncoder.java deleted file mode 100644 index d330f1ffc..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ServerMessageMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ServerChatMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link ServerChatMessage}. - * - * @author Graham - */ -public final class ServerMessageMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(ServerChatMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(253, PacketType.VARIABLE_BYTE); - builder.putString(message.getMessage()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SetUpdatedRegionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetUpdatedRegionMessageEncoder.java deleted file mode 100644 index e490c7139..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetUpdatedRegionMessageEncoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetUpdatedRegionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetUpdatedRegionMessage}. - * - * @author Chris Fletcher - */ -public final class SetUpdatedRegionMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetUpdatedRegionMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(85); - Position player = message.getPlayerPosition(), region = message.getRegionPosition(); - - builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalY(player)); - builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(player)); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SetWidgetItemModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetWidgetItemModelMessageEncoder.java deleted file mode 100644 index e353a2972..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetWidgetItemModelMessageEncoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetWidgetItemModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetItemModelMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetItemModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetItemModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(246); - - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getInterfaceId()); - builder.put(DataType.SHORT, message.getZoom()); - builder.put(DataType.SHORT, message.getModelId()); - - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r317/SetWidgetModelAnimationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetWidgetModelAnimationMessageEncoder.java deleted file mode 100644 index 5c61b450c..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetWidgetModelAnimationMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetWidgetModelAnimationMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetModelAnimationMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetModelAnimationMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetModelAnimationMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(200); - - builder.put(DataType.SHORT, message.getInterfaceId() & 0xFFFF); - builder.put(DataType.SHORT, message.getAnimation()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SetWidgetModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetWidgetModelMessageEncoder.java deleted file mode 100644 index 75f27a9e3..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetWidgetModelMessageEncoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetWidgetModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetModelMessage}. - * - * @author Major - */ -public class SetWidgetModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(8); - - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - builder.put(DataType.SHORT, message.getModel()); - - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r317/SetWidgetNpcModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetWidgetNpcModelMessageEncoder.java deleted file mode 100644 index be4d8ee70..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetWidgetNpcModelMessageEncoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetWidgetNpcModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetNpcModelMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetNpcModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetNpcModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(75); - - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getModelId()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r317/SetWidgetPlayerModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetWidgetPlayerModelMessageEncoder.java deleted file mode 100644 index 3f273f60a..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetWidgetPlayerModelMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetWidgetPlayerModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetPlayerModelMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetPlayerModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetPlayerModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(185); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SetWidgetTextMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetWidgetTextMessageEncoder.java deleted file mode 100644 index e8f81fbba..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetWidgetTextMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetWidgetTextMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetTextMessage}. - * - * @author The Wanderer - */ -public final class SetWidgetTextMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetTextMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(126, PacketType.VARIABLE_SHORT); - builder.putString(message.getText()); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getInterfaceId()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SetWidgetVisibilityMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SetWidgetVisibilityMessageEncoder.java deleted file mode 100644 index c29117cd8..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SetWidgetVisibilityMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SetWidgetVisibilityMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetVisibilityMessage}. - * - * @author Major - */ -public final class SetWidgetVisibilityMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetVisibilityMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(171); - - builder.put(DataType.BYTE, message.isVisible() ? 0 : 1); - builder.put(DataType.SHORT, message.getWidgetId()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SpamPacketMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/SpamPacketMessageDecoder.java deleted file mode 100644 index 4a1a85834..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SpamPacketMessageDecoder.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SpamPacketMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link SpamPacketMessage}. - * - * @author Major - */ -public final class SpamPacketMessageDecoder extends MessageDecoder { - - @Override - public SpamPacketMessage decode(GamePacket packet) { - return new SpamPacketMessage(packet.content().array()); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SwitchItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/SwitchItemMessageDecoder.java deleted file mode 100644 index 3c3d50912..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SwitchItemMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SwitchItemMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link SwitchItemMessage}. - * - * @author Graham - */ -public final class SwitchItemMessageDecoder extends MessageDecoder { - - @Override - public SwitchItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - boolean inserting = reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE) == 1; - int oldSlot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int newSlot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new SwitchItemMessage(interfaceId, inserting, oldSlot, newSlot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/SwitchTabInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/SwitchTabInterfaceMessageEncoder.java deleted file mode 100644 index 23a8070fd..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/SwitchTabInterfaceMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.SwitchTabInterfaceMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SwitchTabInterfaceMessage}. - * - * @author Graham - */ -public final class SwitchTabInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SwitchTabInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(71); - builder.put(DataType.SHORT, message.getInterfaceId()); - builder.put(DataType.BYTE, DataTransformation.ADD, message.getTabId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/TakeTileItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/TakeTileItemMessageDecoder.java deleted file mode 100644 index 7130f5a05..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/TakeTileItemMessageDecoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.TakeTileItemMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link TakeTileItemMessage}. - * - * @author Major - */ -public final class TakeTileItemMessageDecoder extends MessageDecoder { - - @Override - public TakeTileItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT); - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new TakeTileItemMessage(id, new Position(x, y)); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ThirdItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ThirdItemActionMessageDecoder.java deleted file mode 100644 index 89976f8b7..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ThirdItemActionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link ItemActionMessage}. - * - * @author Graham - */ -public final class ThirdItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ItemActionMessage(3, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ThirdItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ThirdItemOptionMessageDecoder.java deleted file mode 100644 index e14c7c414..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ThirdItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link ItemOptionMessage}. - * - * @author Chris Fletcher - */ -public final class ThirdItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int slot = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int interfaceId = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - - return new ItemOptionMessage(3, interfaceId, id, slot); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r317/ThirdNpcActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ThirdNpcActionMessageDecoder.java deleted file mode 100644 index f98441d07..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ThirdNpcActionMessageDecoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.NpcActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link NpcActionMessage}. - * - * @author Major - */ -public final class ThirdNpcActionMessageDecoder extends MessageDecoder { - - @Override - public NpcActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - return new NpcActionMessage(3, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ThirdObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ThirdObjectActionMessageDecoder.java deleted file mode 100644 index f4622700d..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ThirdObjectActionMessageDecoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.ObjectActionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link ObjectActionMessage}. - * - * @author Graham - */ -public final class ThirdObjectActionMessageDecoder extends MessageDecoder { - - @Override - public ObjectActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int y = (int) reader.getUnsigned(DataType.SHORT); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - - return new ObjectActionMessage(3, id, new Position(x, y)); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/ThirdPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/ThirdPlayerActionMessageDecoder.java deleted file mode 100644 index f50e64b5a..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/ThirdPlayerActionMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link PlayerActionMessage}. - * - * @author Major - */ -public final class ThirdPlayerActionMessageDecoder extends MessageDecoder { - - @Override - public PlayerActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new PlayerActionMessage(3, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/UpdateSkillMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/UpdateSkillMessageEncoder.java deleted file mode 100644 index 3b6033a57..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/UpdateSkillMessageEncoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.UpdateSkillMessage; -import org.apollo.game.model.entity.Skill; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateSkillMessage}. - * - * @author Graham - */ -public final class UpdateSkillMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateSkillMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(134); - Skill skill = message.getSkill(); - - builder.put(DataType.BYTE, message.getId()); - builder.put(DataType.INT, DataOrder.MIDDLE, (int) skill.getExperience()); - builder.put(DataType.BYTE, skill.getCurrentLevel()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/UpdateTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r317/UpdateTileItemMessageEncoder.java deleted file mode 100644 index 7159921df..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/UpdateTileItemMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.UpdateTileItemMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateTileItemMessage}. - * - * @author Major - */ -public final class UpdateTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(84); - builder.put(DataType.BYTE, message.getPositionOffset()); - builder.put(DataType.SHORT, message.getId()); - builder.put(DataType.SHORT, message.getPreviousAmount()); - builder.put(DataType.SHORT, message.getAmount()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/WalkMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r317/WalkMessageDecoder.java deleted file mode 100644 index 3440fbc1e..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/WalkMessageDecoder.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.apollo.game.release.r317; - -import org.apollo.game.message.impl.WalkMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link WalkMessage}. - * - * @author Graham - */ -public final class WalkMessageDecoder extends MessageDecoder { - - @Override - public WalkMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int length = packet.getLength(); - if (packet.getOpcode() == 248) { - length -= 14; // strip off anti-cheat data - } - - int steps = (length - 5) / 2; - int[][] path = new int[steps][2]; - - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - for (int i = 0; i < steps; i++) { - path[i][0] = (int) reader.getSigned(DataType.BYTE); - path[i][1] = (int) reader.getSigned(DataType.BYTE); - } - int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - boolean run = reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE) == 1; - - Position[] positions = new Position[steps + 1]; - positions[0] = new Position(x, y); - for (int i = 0; i < steps; i++) { - positions[i + 1] = new Position(path[i][0] + x, path[i][1] + y); - } - - return new WalkMessage(positions, run); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r317/package-info.java b/game/src/main/java/org/apollo/game/release/r317/package-info.java deleted file mode 100644 index 8e1e94c6f..000000000 --- a/game/src/main/java/org/apollo/game/release/r317/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * Contains codecs for the 317 release. - */ -package org.apollo.game.release.r317; - diff --git a/game/src/main/java/org/apollo/game/release/r377/AddFriendMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/AddFriendMessageDecoder.java deleted file mode 100644 index a14a31c1c..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/AddFriendMessageDecoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.AddFriendMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageDecoder} for the {@link AddFriendMessage}. - * - * @author Major - */ -public final class AddFriendMessageDecoder extends MessageDecoder { - - @Override - public AddFriendMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - String username = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - return new AddFriendMessage(username); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/AddGlobalTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/AddGlobalTileItemMessageEncoder.java deleted file mode 100644 index 6fa6058c8..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/AddGlobalTileItemMessageEncoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SendPublicTileItemMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SendPublicTileItemMessage}. - * - * @author Major - */ -public final class AddGlobalTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendPublicTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(106); - builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getAmount()); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getId()); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getIndex()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/AddTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/AddTileItemMessageEncoder.java deleted file mode 100644 index 06e9b08fa..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/AddTileItemMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SendTileItemMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SendTileItemMessage}. - * - * @author Major - */ -public final class AddTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(107); - builder.put(DataType.SHORT, message.getId()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getPositionOffset()); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getAmount()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ButtonMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ButtonMessageDecoder.java deleted file mode 100644 index 45795ba40..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ButtonMessageDecoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ButtonMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ButtonMessage}. - * - * @author Graham - */ -public final class ButtonMessageDecoder extends MessageDecoder { - - @Override - public ButtonMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - return new ButtonMessage(interfaceId); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ClearRegionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/ClearRegionMessageEncoder.java deleted file mode 100644 index 6bd9cae72..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ClearRegionMessageEncoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ClearRegionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link ClearRegionMessage}. - * - * @author Major - */ -public final class ClearRegionMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(ClearRegionMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(40); - Position player = message.getPlayerPosition(), region = message.getRegionPosition(); - - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, region.getLocalY(player)); - builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(player)); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/CloseInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/CloseInterfaceMessageEncoder.java deleted file mode 100644 index 9474edaf5..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/CloseInterfaceMessageEncoder.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.CloseInterfaceMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link CloseInterfaceMessage}. - * - * @author Graham - */ -public final class CloseInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(CloseInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(29); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ClosedInterfaceMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ClosedInterfaceMessageDecoder.java deleted file mode 100644 index 1bbcd5dad..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ClosedInterfaceMessageDecoder.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ClosedInterfaceMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ClosedInterfaceMessage}. - * - * @author Graham - */ -public final class ClosedInterfaceMessageDecoder extends MessageDecoder { - - @Override - public ClosedInterfaceMessage decode(GamePacket packet) { - return new ClosedInterfaceMessage(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/CommandMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/CommandMessageDecoder.java deleted file mode 100644 index 9f868e62a..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/CommandMessageDecoder.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.CommandMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link CommandMessage}. - * - * @author Graham - */ -public final class CommandMessageDecoder extends MessageDecoder { - - @Override - public CommandMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - return new CommandMessage(reader.getString()); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/DialogueContinueMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/DialogueContinueMessageDecoder.java deleted file mode 100644 index 070aded91..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/DialogueContinueMessageDecoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.DialogueContinueMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link DialogueContinueMessage}. - * - * @author Chris Fletcher - */ -public final class DialogueContinueMessageDecoder extends MessageDecoder { - - @Override - public DialogueContinueMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - return new DialogueContinueMessage(interfaceId); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/DisplayCrossbonesMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/DisplayCrossbonesMessageEncoder.java deleted file mode 100644 index 0154ed1d5..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/DisplayCrossbonesMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.DisplayCrossbonesMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link DisplayCrossbonesMessage}. - * - * @author Major - */ -public final class DisplayCrossbonesMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(DisplayCrossbonesMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(233); - builder.put(DataType.BYTE, message.isDisplayed() ? 1 : 0); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/DisplayTabInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/DisplayTabInterfaceMessageEncoder.java deleted file mode 100644 index b61ab2a82..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/DisplayTabInterfaceMessageEncoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.DisplayTabInterfaceMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link DisplayTabInterfaceMessage}. - * - * @author Chris Fletcher - */ -public final class DisplayTabInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(DisplayTabInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(252); - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getTab()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/EnterAmountMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/EnterAmountMessageEncoder.java deleted file mode 100644 index 930b8e59a..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/EnterAmountMessageEncoder.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.apollo.game.release.r377; - -import io.netty.buffer.Unpooled; - -import org.apollo.game.message.impl.EnterAmountMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link EnterAmountMessage}. - * - * @author Graham - */ -public final class EnterAmountMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(EnterAmountMessage message) { - return new GamePacket(58, PacketType.FIXED, Unpooled.EMPTY_BUFFER); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FifthItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FifthItemActionMessageDecoder.java deleted file mode 100644 index 244ebf0fe..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FifthItemActionMessageDecoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fifth {@link ItemActionMessage}. - * - * @author Graham - */ -public final class FifthItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new ItemActionMessage(5, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FifthItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FifthItemOptionMessageDecoder.java deleted file mode 100644 index bf4a16ac1..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FifthItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fifth {@link ItemOptionMessage}. - * - * @author Chris Fletcher - */ -public final class FifthItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - - return new ItemOptionMessage(5, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FirstItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FirstItemActionMessageDecoder.java deleted file mode 100644 index e01cec997..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FirstItemActionMessageDecoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link ItemActionMessage}. - * - * @author Graham - */ -public final class FirstItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - int slot = (int) reader.getUnsigned(DataType.SHORT); - return new ItemActionMessage(1, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FirstItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FirstItemOptionMessageDecoder.java deleted file mode 100644 index ff9180127..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FirstItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link ItemOptionMessage}. - * - * @author Chris Fletcher - */ -public final class FirstItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - - return new ItemOptionMessage(1, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FirstObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FirstObjectActionMessageDecoder.java deleted file mode 100644 index 172361905..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FirstObjectActionMessageDecoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ObjectActionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link ObjectActionMessage}. - * - * @author Graham - */ -public final class FirstObjectActionMessageDecoder extends MessageDecoder { - - @Override - public ObjectActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int x = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - - return new ObjectActionMessage(1, id, new Position(x, y)); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FirstPlayerActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FirstPlayerActionMessageDecoder.java deleted file mode 100644 index 4d18a15b2..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FirstPlayerActionMessageDecoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.PlayerActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the first {@link PlayerActionMessage}. - * - * @author Major - */ -public final class FirstPlayerActionMessageDecoder extends MessageDecoder { - - @Override - public PlayerActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - return new PlayerActionMessage(1, index); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FlaggedMouseEventMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FlaggedMouseEventMessageDecoder.java deleted file mode 100644 index 198024bf2..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FlaggedMouseEventMessageDecoder.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.FlaggedMouseEventMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link org.apollo.game.message.impl.FlaggedMouseEventMessage}. - * - * @author Major - */ -public final class FlaggedMouseEventMessageDecoder extends MessageDecoder { - - @Override - public FlaggedMouseEventMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int read, clicks, x, y; - - if (reader.getLength() == 2) { - read = (int) reader.getUnsigned(DataType.SHORT); - clicks = read >> 12; - x = read >> 6 & 0x3f; - y = read & 0x3f; - return new FlaggedMouseEventMessage(clicks, x, y, true); - } else if (reader.getLength() == 3) { - read = (int) reader.getUnsigned(DataType.TRI_BYTE) & ~0x800000; - } else { - read = (int) reader.getUnsigned(DataType.INT) & ~0xc0000000; - } - - clicks = read >> 19; - x = (read & 0x7f) % 765; - y = (read & 0x7f) / 765; - return new FlaggedMouseEventMessage(clicks, x, y, false); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FlashTabInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/FlashTabInterfaceMessageEncoder.java deleted file mode 100644 index 8fce05d27..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FlashTabInterfaceMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.FlashTabInterfaceMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link FlashTabInterfaceMessage}. - * - * @author Major - */ -public final class FlashTabInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(FlashTabInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(238); - builder.put(DataType.BYTE, message.getTab()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FlashingTabClickedMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FlashingTabClickedMessageDecoder.java deleted file mode 100644 index 12f36e870..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FlashingTabClickedMessageDecoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.FlashingTabClickedMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link FlashingTabClickedMessage}. - * - * @author Major - */ -public final class FlashingTabClickedMessageDecoder extends MessageDecoder { - - @Override - public FlashingTabClickedMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int tab = (int) reader.getUnsigned(DataType.BYTE); - return new FlashingTabClickedMessage(tab); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FocusUpdateMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FocusUpdateMessageDecoder.java deleted file mode 100644 index 7b8a30382..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FocusUpdateMessageDecoder.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.FocusUpdateMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link FocusUpdateMessage}. - * - * @author Major - */ -public final class FocusUpdateMessageDecoder extends MessageDecoder { - - @Override - public FocusUpdateMessage decode(GamePacket packet) { - GamePacketReader decoder = new GamePacketReader(packet); - return new FocusUpdateMessage(decoder.getUnsigned(DataType.BYTE) == 1); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ForwardPrivateChatMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/ForwardPrivateChatMessageEncoder.java deleted file mode 100644 index 6491370a0..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ForwardPrivateChatMessageEncoder.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apollo.game.release.r377; - -import java.util.concurrent.atomic.AtomicInteger; - -import org.apollo.game.message.impl.ForwardPrivateChatMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageEncoder} for the {@link ForwardPrivateChatMessage}. - * - * @author Major - */ -public final class ForwardPrivateChatMessageEncoder extends MessageEncoder { - - /** - * The amount of messages sent globally, offset by a random variable x, {@code 0 <= x < 100,000,000}. - */ - private static AtomicInteger messageCounter = new AtomicInteger((int) (Math.random() * 100_000_000)); - - @Override - public GamePacket encode(ForwardPrivateChatMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(135, PacketType.VARIABLE_BYTE); - - builder.put(DataType.LONG, NameUtil.encodeBase37(message.getSenderUsername())); - builder.put(DataType.INT, messageCounter.incrementAndGet()); - builder.put(DataType.BYTE, message.getSenderPrivilege().toInteger()); - builder.putBytes(message.getCompressedMessage()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FourthItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FourthItemActionMessageDecoder.java deleted file mode 100644 index 9f95c6426..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FourthItemActionMessageDecoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fourth {@link ItemActionMessage}. - * - * @author Graham - */ -public final class FourthItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT); - return new ItemActionMessage(4, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FourthItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/FourthItemOptionMessageDecoder.java deleted file mode 100644 index f6fa9ef42..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FourthItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the fourth {@link ItemOptionMessage}. - * - * @author Chris Fletcher - */ -public final class FourthItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - - return new ItemOptionMessage(4, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/FriendServerStatusMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/FriendServerStatusMessageEncoder.java deleted file mode 100644 index 32c2621d3..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/FriendServerStatusMessageEncoder.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.FriendServerStatusMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link FriendServerStatusMessage}. - * - * @author Major - */ -public final class FriendServerStatusMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(FriendServerStatusMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(251); - builder.put(DataType.BYTE, message.getStatusCode()); - return builder.toGamePacket(); - } -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/GroupedRegionUpdateMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/GroupedRegionUpdateMessageEncoder.java deleted file mode 100644 index b41e415b5..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/GroupedRegionUpdateMessageEncoder.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.GroupedRegionUpdateMessage; -import org.apollo.game.message.impl.RegionUpdateMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; -import org.apollo.net.release.Release; - -/** - * A {@link MessageEncoder} for the {@link GroupedRegionUpdateMessage}. - * - * @author Major - */ -public final class GroupedRegionUpdateMessageEncoder extends MessageEncoder { - - /** - * The Release containing the MessageEncoders for the RegionUpdateMessages. - */ - private final Release release; - - /** - * Creates the GroupedRegionUpdateMessageEncoder. - * - * @param release The {@link Release} containing the {@link MessageEncoder}s for the {@link RegionUpdateMessage}s. - */ - public GroupedRegionUpdateMessageEncoder(Release release) { - this.release = release; - } - - @Override - public GamePacket encode(GroupedRegionUpdateMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(183, PacketType.VARIABLE_SHORT); - Position base = message.getLastKnownRegion(), region = message.getRegionPosition(); - - builder.put(DataType.BYTE, region.getLocalX(base)); - builder.put(DataType.BYTE, DataTransformation.ADD, region.getLocalY(base)); - - for (RegionUpdateMessage update : message.getMessages()) { - @SuppressWarnings("unchecked") - MessageEncoder encoder = (MessageEncoder) release - .getMessageEncoder(update.getClass()); - - GamePacket packet = encoder.encode(update); - builder.put(DataType.BYTE, packet.getOpcode()); - builder.putBytes(packet.content()); - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/IdAssignmentMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/IdAssignmentMessageEncoder.java deleted file mode 100644 index 3abe6f950..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/IdAssignmentMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.IdAssignmentMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link IdAssignmentMessage}. - * - * @author Graham - */ -public final class IdAssignmentMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(IdAssignmentMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(126); - builder.put(DataType.BYTE, message.isMembers() ? 1 : 0); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/IgnoreListMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/IgnoreListMessageEncoder.java deleted file mode 100644 index 8e98a9b2e..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/IgnoreListMessageEncoder.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.apollo.game.release.r377; - -import java.util.List; - -import org.apollo.game.message.impl.IgnoreListMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageEncoder} for the {@link IgnoreListMessage}. - * - * @author Major - */ -public final class IgnoreListMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(IgnoreListMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(226); - - List usernames = message.getUsernames(); - for (String username : usernames) { - builder.put(DataType.LONG, NameUtil.encodeBase37(username)); - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ItemOnItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ItemOnItemMessageDecoder.java deleted file mode 100644 index 6deba8b52..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ItemOnItemMessageDecoder.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOnItemMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ItemOnItemMessageDecoder}. - * - * @author Chris Fletcher - */ -public final class ItemOnItemMessageDecoder extends MessageDecoder { - - @Override - public ItemOnItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int targetId = (int) reader.getUnsigned(DataType.SHORT); - int usedSlot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - - int usedId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int targetInterface = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - - int targetSlot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int usedInterface = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ItemOnItemMessage(usedInterface, usedId, usedSlot, targetInterface, targetId, targetSlot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ItemOnNpcMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ItemOnNpcMessageDecoder.java deleted file mode 100644 index 8600b17b6..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ItemOnNpcMessageDecoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOnNpcMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ItemOnNpcMessage}. - * - * @author Major - */ -public final class ItemOnNpcMessageDecoder extends MessageDecoder { - - @Override - public ItemOnNpcMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int index = (int) reader.getUnsigned(DataType.SHORT); - int id = (int) reader.getSigned(DataType.SHORT, DataOrder.LITTLE); - int widget = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT); - - return new ItemOnNpcMessage(id, index, slot, widget); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/ItemOnObjectMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ItemOnObjectMessageDecoder.java deleted file mode 100644 index 92aadd2f6..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ItemOnObjectMessageDecoder.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOnObjectMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link ItemOnObjectMessage}. - * - * @author Major - */ -public final class ItemOnObjectMessageDecoder extends MessageDecoder { - - @Override - public ItemOnObjectMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int objectId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int itemId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int slot = (int) reader.getUnsigned(DataType.SHORT); - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - - return new ItemOnObjectMessage(interfaceId, itemId, slot, objectId, x, y); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/LogoutMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/LogoutMessageEncoder.java deleted file mode 100644 index 6b720db7f..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/LogoutMessageEncoder.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.LogoutMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link LogoutMessage}. - * - * @author Graham - */ -public final class LogoutMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(LogoutMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(5); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/MagicOnItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/MagicOnItemMessageDecoder.java deleted file mode 100644 index d8aeb87da..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/MagicOnItemMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.MagicOnItemMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link MagicOnItemMessage}. - * - * @author Chris Fletcher - */ -public final class MagicOnItemMessageDecoder extends MessageDecoder { - - @Override - public MagicOnItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int spell = (int) reader.getUnsigned(DataType.SHORT); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new MagicOnItemMessage(interfaceId, id, slot, spell); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/MagicOnNpcMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/MagicOnNpcMessageDecoder.java deleted file mode 100644 index fca7e27a2..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/MagicOnNpcMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.MagicOnNpcMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link MagicOnNpcMessage} - * - * @author Stuart - */ -public final class MagicOnNpcMessageDecoder extends MessageDecoder { - - @Override - public MagicOnNpcMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int index = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int spell = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new MagicOnNpcMessage(index, spell); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/MagicOnPlayerMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/MagicOnPlayerMessageDecoder.java deleted file mode 100644 index 0ea104e96..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/MagicOnPlayerMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.MagicOnPlayerMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link MagicOnPlayerMessage} - * - * @author Stuart - */ -public final class MagicOnPlayerMessageDecoder extends MessageDecoder { - - @Override - public MagicOnPlayerMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int index = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int spell = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - - return new MagicOnPlayerMessage(index, spell); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/MobAnimationResetMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/MobAnimationResetMessageEncoder.java deleted file mode 100644 index d9b21215e..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/MobAnimationResetMessageEncoder.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.MobAnimationResetMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link MobAnimationResetMessage}. - * - * @author Major - */ -public final class MobAnimationResetMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(MobAnimationResetMessage message) { - return new GamePacketBuilder(13).toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/MobHintIconMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/MobHintIconMessageEncoder.java deleted file mode 100644 index 8d86f89b4..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/MobHintIconMessageEncoder.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.HintIconMessage; -import org.apollo.game.message.impl.MobHintIconMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link MobHintIconMessage}. - * - * @author Major - */ -public final class MobHintIconMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(MobHintIconMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(199); - HintIconMessage.Type type = message.getType(); - builder.put(DataType.BYTE, type.getValue()); - - switch (type) { - case NPC: - case PLAYER: - builder.put(DataType.SHORT, message.getIndex()); - builder.put(DataType.TRI_BYTE, 0); // Dummy bytes - break; - default: - throw new IllegalStateException("Unsupported hint icon type " + type + "."); - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/OpenDialogueInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/OpenDialogueInterfaceMessageEncoder.java deleted file mode 100644 index b85f9c9b9..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/OpenDialogueInterfaceMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.OpenDialogueInterfaceMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenDialogueInterfaceMessage}. - * - * @author Chris Fletcher - */ -public final class OpenDialogueInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenDialogueInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(109); - builder.put(DataType.SHORT, message.getInterfaceId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/OpenDialogueOverlayMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/OpenDialogueOverlayMessageEncoder.java deleted file mode 100644 index aad3e23b4..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/OpenDialogueOverlayMessageEncoder.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.OpenDialogueOverlayMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenDialogueOverlayMessage}. - * - * @author Major - */ -public final class OpenDialogueOverlayMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenDialogueOverlayMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(158); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getInterfaceId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/OpenInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/OpenInterfaceMessageEncoder.java deleted file mode 100644 index 95e41cf71..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/OpenInterfaceMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.OpenInterfaceMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenInterfaceMessage}. - * - * @author Graham - */ -public final class OpenInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(159); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/OpenInterfaceSidebarMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/OpenInterfaceSidebarMessageEncoder.java deleted file mode 100644 index d552df54c..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/OpenInterfaceSidebarMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.OpenInterfaceSidebarMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenInterfaceSidebarMessage}. - * - * @author Graham - */ -public final class OpenInterfaceSidebarMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenInterfaceSidebarMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(128); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getInterfaceId()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getSidebarId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/OpenOverlayMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/OpenOverlayMessageEncoder.java deleted file mode 100644 index b807abf91..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/OpenOverlayMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.OpenOverlayMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenOverlayMessage}. - * - * @author Major - */ -public final class OpenOverlayMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenOverlayMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(50); - builder.put(DataType.SHORT, message.getOverlayId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/OpenSidebarMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/OpenSidebarMessageEncoder.java deleted file mode 100644 index fafe3d113..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/OpenSidebarMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.OpenSidebarMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link OpenSidebarMessage}. - * - * @author Major - */ -public final class OpenSidebarMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(OpenSidebarMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(246); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getSidebarId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/PlayerSynchronizationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/PlayerSynchronizationMessageEncoder.java deleted file mode 100644 index 5ef61f80c..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/PlayerSynchronizationMessageEncoder.java +++ /dev/null @@ -1,460 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.cache.def.EquipmentDefinition; -import org.apollo.game.message.impl.PlayerSynchronizationMessage; -import org.apollo.game.model.Animation; -import org.apollo.game.model.Appearance; -import org.apollo.game.model.Direction; -import org.apollo.game.model.Graphic; -import org.apollo.game.model.Item; -import org.apollo.game.model.Position; -import org.apollo.game.model.entity.EquipmentConstants; -import org.apollo.game.model.entity.setting.Gender; -import org.apollo.game.model.inv.Inventory; -import org.apollo.game.sync.block.AnimationBlock; -import org.apollo.game.sync.block.AppearanceBlock; -import org.apollo.game.sync.block.ChatBlock; -import org.apollo.game.sync.block.ForceChatBlock; -import org.apollo.game.sync.block.ForceMovementBlock; -import org.apollo.game.sync.block.GraphicBlock; -import org.apollo.game.sync.block.HitUpdateBlock; -import org.apollo.game.sync.block.InteractingMobBlock; -import org.apollo.game.sync.block.SecondaryHitUpdateBlock; -import org.apollo.game.sync.block.SynchronizationBlockSet; -import org.apollo.game.sync.block.TurnToPositionBlock; -import org.apollo.game.sync.seg.AddPlayerSegment; -import org.apollo.game.sync.seg.MovementSegment; -import org.apollo.game.sync.seg.SegmentType; -import org.apollo.game.sync.seg.SynchronizationSegment; -import org.apollo.game.sync.seg.TeleportSegment; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link PlayerSynchronizationMessage}. - * - * @author Graham - * @author Major - */ -public final class PlayerSynchronizationMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(PlayerSynchronizationMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(90, PacketType.VARIABLE_SHORT); - builder.switchToBitAccess(); - - GamePacketBuilder blockBuilder = new GamePacketBuilder(); - - putMovementUpdate(message.getSegment(), message, builder); - putBlocks(message.getSegment(), blockBuilder); - - builder.putBits(8, message.getLocalPlayers()); - - for (SynchronizationSegment segment : message.getSegments()) { - SegmentType type = segment.getType(); - if (type == SegmentType.REMOVE_MOB) { - putRemovePlayerUpdate(builder); - } else if (type == SegmentType.ADD_MOB) { - putAddPlayerUpdate((AddPlayerSegment) segment, message, builder); - putBlocks(segment, blockBuilder); - } else { - putMovementUpdate(segment, message, builder); - putBlocks(segment, blockBuilder); - } - } - - if (blockBuilder.getLength() > 0) { - builder.putBits(11, 2047); - builder.switchToByteAccess(); - builder.putRawBuilder(blockBuilder); - } else { - builder.switchToByteAccess(); - } - - return builder.toGamePacket(); - } - - /** - * Puts an add player update. - * - * @param seg The segment. - * @param message The message. - * @param builder The builder. - */ - private static void putAddPlayerUpdate(AddPlayerSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) { - boolean updateRequired = seg.getBlockSet().size() > 0; - Position player = message.getPosition(); - Position other = seg.getPosition(); - builder.putBits(11, seg.getIndex()); - builder.putBits(5, other.getX() - player.getX()); - builder.putBits(1, updateRequired ? 1 : 0); - builder.putBits(1, 1); // discard walking queue? - builder.putBits(5, other.getY() - player.getY()); - } - - /** - * Puts an Animation block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) { - Animation animation = block.getAnimation(); - builder.put(DataType.SHORT, animation.getId()); - builder.put(DataType.BYTE, DataTransformation.ADD, animation.getDelay()); - } - - /** - * Puts an Appearance block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) { - Appearance appearance = block.getAppearance(); - GamePacketBuilder playerProperties = new GamePacketBuilder(); - - playerProperties.put(DataType.BYTE, appearance.getGender().toInteger()); - playerProperties.put(DataType.BYTE, block.isSkulled() ? 1 : -1); - playerProperties.put(DataType.BYTE, block.getHeadIcon()); - - if (block.appearingAsNpc()) { - playerProperties.put(DataType.BYTE, 255); - playerProperties.put(DataType.BYTE, 255); - playerProperties.put(DataType.SHORT, block.getNpcId()); - } else { - Inventory equipment = block.getEquipment(); - int[] style = appearance.getStyle(); - Item item, chest, helm; - - for (int slot = 0; slot < 4; slot++) { - if ((item = equipment.get(slot)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.BYTE, 0); - } - } - - if ((chest = equipment.get(EquipmentConstants.CHEST)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + chest.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[2]); - } - - if ((item = equipment.get(EquipmentConstants.SHIELD)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.BYTE, 0); - } - - if (chest != null) { - EquipmentDefinition def = EquipmentDefinition.lookup(chest.getId()); - if (def != null && !def.isFullBody()) { - playerProperties.put(DataType.SHORT, 0x100 + style[3]); - } else { - playerProperties.put(DataType.BYTE, 0); - } - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[3]); - } - - if ((item = equipment.get(EquipmentConstants.LEGS)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[5]); - } - - if ((helm = equipment.get(EquipmentConstants.HAT)) != null) { - EquipmentDefinition def = EquipmentDefinition.lookup(helm.getId()); - if (def != null && !def.isFullHat() && !def.isFullMask()) { - playerProperties.put(DataType.SHORT, 0x100 + style[0]); - } else { - playerProperties.put(DataType.BYTE, 0); - } - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[0]); - } - - if ((item = equipment.get(EquipmentConstants.HANDS)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[4]); - } - - if ((item = equipment.get(EquipmentConstants.FEET)) != null) { - playerProperties.put(DataType.SHORT, 0x200 + item.getId()); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[6]); - } - - EquipmentDefinition def = null; - if (helm != null) { - def = EquipmentDefinition.lookup(helm.getId()); - } - if (def != null && (def.isFullMask()) || appearance.getGender() == Gender.FEMALE) { - playerProperties.put(DataType.BYTE, 0); - } else { - playerProperties.put(DataType.SHORT, 0x100 + style[1]); - } - } - - int[] colors = appearance.getColors(); - for (int color : colors) { - playerProperties.put(DataType.BYTE, color); - } - - playerProperties.put(DataType.SHORT, 0x328); // stand - playerProperties.put(DataType.SHORT, 0x337); // stand turn - playerProperties.put(DataType.SHORT, 0x333); // walk - playerProperties.put(DataType.SHORT, 0x334); // turn 180 - playerProperties.put(DataType.SHORT, 0x335); // turn 90 cw - playerProperties.put(DataType.SHORT, 0x336); // turn 90 ccw - playerProperties.put(DataType.SHORT, 0x338); // run - - playerProperties.put(DataType.LONG, block.getName()); - playerProperties.put(DataType.BYTE, block.getCombatLevel()); - playerProperties.put(DataType.SHORT, block.getSkillLevel()); - - builder.put(DataType.BYTE, playerProperties.getLength()); - builder.putRawBuilderReverse(playerProperties); - } - - /** - * Puts the blocks for the specified segment. - * - * @param segment The segment. - * @param builder The block builder. - */ - private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) { - SynchronizationBlockSet blockSet = segment.getBlockSet(); - if (blockSet.size() > 0) { - int mask = 0; - - if (blockSet.contains(AnimationBlock.class)) { - mask |= 0x8; - } - if (blockSet.contains(ForceChatBlock.class)) { - mask |= 0x10; - } - if (blockSet.contains(ForceMovementBlock.class)) { - mask |= 0x100; - } - if (blockSet.contains(InteractingMobBlock.class)) { - mask |= 0x1; - } - if (blockSet.contains(TurnToPositionBlock.class)) { - mask |= 0x2; - } - if (blockSet.contains(GraphicBlock.class)) { - mask |= 0x200; - } - if (blockSet.contains(AppearanceBlock.class)) { - mask |= 0x4; - } - if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - mask |= 0x400; - } - if (blockSet.contains(ChatBlock.class)) { - mask |= 0x40; - } - if (blockSet.contains(HitUpdateBlock.class)) { - mask |= 0x80; - } - - if (mask >= 0x100) { - mask |= 0x20; - builder.put(DataType.SHORT, DataOrder.LITTLE, mask); - } else { - builder.put(DataType.BYTE, mask); - } - - if (blockSet.contains(AnimationBlock.class)) { - putAnimationBlock(blockSet.get(AnimationBlock.class), builder); - } - if (blockSet.contains(ForceChatBlock.class)) { - putForceChatBlock(blockSet.get(ForceChatBlock.class), builder); - } - if (blockSet.contains(ForceMovementBlock.class)) { - putForceMovementBlock(blockSet.get(ForceMovementBlock.class), builder); - } - if (blockSet.contains(InteractingMobBlock.class)) { - putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), builder); - } - if (blockSet.contains(TurnToPositionBlock.class)) { - putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), builder); - } - if (blockSet.contains(GraphicBlock.class)) { - putGraphicBlock(blockSet.get(GraphicBlock.class), builder); - } - if (blockSet.contains(AppearanceBlock.class)) { - putAppearanceBlock(blockSet.get(AppearanceBlock.class), builder); - } - if (blockSet.contains(SecondaryHitUpdateBlock.class)) { - putSecondHitUpdateBlock(blockSet.get(SecondaryHitUpdateBlock.class), builder); - } - if (blockSet.contains(ChatBlock.class)) { - putChatBlock(blockSet.get(ChatBlock.class), builder); - } - if (blockSet.contains(HitUpdateBlock.class)) { - putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), builder); - } - } - } - - /** - * Puts a chat block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putChatBlock(ChatBlock block, GamePacketBuilder builder) { - byte[] bytes = block.getCompressedMessage(); - builder.put(DataType.SHORT, DataOrder.LITTLE, block.getTextEffects() << 8 | block.getTextColor()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getPrivilegeLevel().toInteger()); - builder.put(DataType.BYTE, DataTransformation.ADD, bytes.length); - builder.putBytes(DataTransformation.ADD, bytes); - } - - /** - * Puts a force chat block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) { - builder.putString(block.getMessage()); - } - - /** - * Puts a force movement block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putForceMovementBlock(ForceMovementBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, DataTransformation.ADD, block.getInitialX()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getInitialY()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getFinalX()); - builder.put(DataType.BYTE, block.getFinalY()); - builder.put(DataType.SHORT, block.getTravelDurationX()); - builder.put(DataType.SHORT, DataTransformation.ADD, block.getTravelDurationY()); - builder.put(DataType.BYTE, block.getDirection().toInteger()); - } - - /** - * Puts a graphic block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) { - Graphic graphic = block.getGraphic(); - builder.put(DataType.SHORT, DataTransformation.ADD, graphic.getId()); - builder.put(DataType.INT, DataOrder.MIDDLE, graphic.getHeight() << 16 & 0xFFFF0000 | graphic.getDelay() & 0x0000FFFF); - } - - /** - * Puts a hit update block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getDamage()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getType()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getCurrentHealth()); - builder.put(DataType.BYTE, block.getMaximumHealth()); - } - - /** - * Puts an interacting mob block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) { - builder.put(DataType.SHORT, DataTransformation.ADD, block.getIndex()); - } - - /** - * Puts a movement update for the specified segment. - * - * @param seg The segment. - * @param message The message. - * @param builder The builder. - */ - private static void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) { - boolean updateRequired = seg.getBlockSet().size() > 0; - if (seg.getType() == SegmentType.TELEPORT) { - Position pos = ((TeleportSegment) seg).getDestination(); - builder.putBits(1, 1); - builder.putBits(2, 3); - builder.putBits(1, message.hasRegionChanged() ? 0 : 1); - builder.putBits(2, pos.getHeight()); - builder.putBits(7, pos.getLocalY(message.getLastKnownRegion())); - builder.putBits(7, pos.getLocalX(message.getLastKnownRegion())); - builder.putBits(1, updateRequired ? 1 : 0); - } else if (seg.getType() == SegmentType.RUN) { - Direction[] directions = ((MovementSegment) seg).getDirections(); - builder.putBits(1, 1); - builder.putBits(2, 2); - builder.putBits(3, directions[0].toInteger()); - builder.putBits(3, directions[1].toInteger()); - builder.putBits(1, updateRequired ? 1 : 0); - } else if (seg.getType() == SegmentType.WALK) { - Direction[] directions = ((MovementSegment) seg).getDirections(); - builder.putBits(1, 1); - builder.putBits(2, 1); - builder.putBits(3, directions[0].toInteger()); - builder.putBits(1, updateRequired ? 1 : 0); - } else { - if (updateRequired) { - builder.putBits(1, 1); - builder.putBits(2, 0); - } else { - builder.putBits(1, 0); - } - } - } - - /** - * Puts a remove player update. - * - * @param builder The builder. - */ - private static void putRemovePlayerUpdate(GamePacketBuilder builder) { - builder.putBits(1, 1); - builder.putBits(2, 3); - } - - /** - * Puts a secondary hit update block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) { - builder.put(DataType.BYTE, DataTransformation.ADD, block.getDamage()); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType()); - builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getCurrentHealth()); - builder.put(DataType.BYTE, block.getMaximumHealth()); - } - - /** - * Puts a turn to position block into the specified builder. - * - * @param block The block. - * @param builder The builder. - */ - private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { - Position position = block.getPosition(); - builder.put(DataType.SHORT, position.getX() * 2 + 1); - builder.put(DataType.SHORT, position.getY() * 2 + 1); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/PositionHintIconMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/PositionHintIconMessageEncoder.java deleted file mode 100644 index 562d7b242..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/PositionHintIconMessageEncoder.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.HintIconMessage; -import org.apollo.game.message.impl.PositionHintIconMessage; -import org.apollo.game.message.impl.HintIconMessage.Type; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link PositionHintIconMessage}. - * - * @author Major - */ -public final class PositionHintIconMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(PositionHintIconMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(199); - HintIconMessage.Type type = message.getType(); - - if (type == Type.PLAYER || type == Type.NPC) { - throw new IllegalStateException("Unsupported hint icon type " + type + "."); - } - - builder.put(DataType.BYTE, type.getValue()); - - Position position = message.getPosition(); - builder.put(DataType.SHORT, position.getX()); - builder.put(DataType.SHORT, position.getY()); - builder.put(DataType.BYTE, message.getHeight()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/PrivacyOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/PrivacyOptionMessageDecoder.java deleted file mode 100644 index 3c2239b21..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/PrivacyOptionMessageDecoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.PrivacyOptionMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link PrivacyOptionMessage}. - * - * @author Major - */ -public final class PrivacyOptionMessageDecoder extends MessageDecoder { - - @Override - public PrivacyOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int publicChatState = (int) reader.getUnsigned(DataType.BYTE); - int privateChatState = (int) reader.getUnsigned(DataType.BYTE); - int tradeChatState = (int) reader.getUnsigned(DataType.BYTE); - - return new PrivacyOptionMessage(publicChatState, privateChatState, tradeChatState); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/PrivacyOptionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/PrivacyOptionMessageEncoder.java deleted file mode 100644 index e033b5d31..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/PrivacyOptionMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.PrivacyOptionMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link PrivacyOptionMessage}. - * - * @author Major - */ -public final class PrivacyOptionMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(final PrivacyOptionMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(201); - - builder.put(DataType.BYTE, message.getChatPrivacy().ordinal()); - builder.put(DataType.BYTE, message.getFriendPrivacy().ordinal()); - builder.put(DataType.BYTE, message.getTradePrivacy().ordinal()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/PublicChatMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/PublicChatMessageDecoder.java deleted file mode 100644 index f871147d0..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/PublicChatMessageDecoder.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.PublicChatMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.TextUtil; - -/** - * A {@link MessageDecoder} for the {@link PublicChatMessage}. - * - * @author Graham - */ -public final class PublicChatMessageDecoder extends MessageDecoder { - - @Override - public PublicChatMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int color = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE); - int effects = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); - - int length = packet.getLength() - 2; - - byte[] originalCompressed = new byte[length]; - reader.getBytes(originalCompressed); - - String uncompressed = TextUtil.decompress(originalCompressed, length); - uncompressed = TextUtil.filterInvalidCharacters(uncompressed); - uncompressed = TextUtil.capitalize(uncompressed); - - byte[] recompressed = new byte[length]; - TextUtil.compress(uncompressed, recompressed); // in case invalid data gets sent, this effectively verifies it - - return new PublicChatMessage(uncompressed, recompressed, color, effects); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/RegionChangeMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/RegionChangeMessageEncoder.java deleted file mode 100644 index e7e1eda67..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/RegionChangeMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.RegionChangeMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link RegionChangeMessage}. - * - * @author Graham - */ -public final class RegionChangeMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(RegionChangeMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(222); - builder.put(DataType.SHORT, message.getPosition().getCentralRegionY()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getPosition().getCentralRegionX()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/Release377.java b/game/src/main/java/org/apollo/game/release/r377/Release377.java deleted file mode 100644 index 2b2c1e577..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/Release377.java +++ /dev/null @@ -1,231 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ClearRegionMessage; -import org.apollo.game.message.impl.CloseInterfaceMessage; -import org.apollo.game.message.impl.ConfigMessage; -import org.apollo.game.message.impl.DisplayCrossbonesMessage; -import org.apollo.game.message.impl.DisplayTabInterfaceMessage; -import org.apollo.game.message.impl.EnterAmountMessage; -import org.apollo.game.message.impl.FlashTabInterfaceMessage; -import org.apollo.game.message.impl.ForwardPrivateChatMessage; -import org.apollo.game.message.impl.FriendServerStatusMessage; -import org.apollo.game.message.impl.GroupedRegionUpdateMessage; -import org.apollo.game.message.impl.IdAssignmentMessage; -import org.apollo.game.message.impl.IgnoreListMessage; -import org.apollo.game.message.impl.LogoutMessage; -import org.apollo.game.message.impl.MobHintIconMessage; -import org.apollo.game.message.impl.NpcSynchronizationMessage; -import org.apollo.game.message.impl.OpenDialogueInterfaceMessage; -import org.apollo.game.message.impl.OpenDialogueOverlayMessage; -import org.apollo.game.message.impl.OpenInterfaceMessage; -import org.apollo.game.message.impl.OpenInterfaceSidebarMessage; -import org.apollo.game.message.impl.OpenOverlayMessage; -import org.apollo.game.message.impl.OpenSidebarMessage; -import org.apollo.game.message.impl.PlayerSynchronizationMessage; -import org.apollo.game.message.impl.PositionHintIconMessage; -import org.apollo.game.message.impl.PrivacyOptionMessage; -import org.apollo.game.message.impl.RegionChangeMessage; -import org.apollo.game.message.impl.RemoveObjectMessage; -import org.apollo.game.message.impl.RemoveTileItemMessage; -import org.apollo.game.message.impl.SendFriendMessage; -import org.apollo.game.message.impl.SendObjectMessage; -import org.apollo.game.message.impl.SendProjectileMessage; -import org.apollo.game.message.impl.SendPublicTileItemMessage; -import org.apollo.game.message.impl.SendTileItemMessage; -import org.apollo.game.message.impl.ServerChatMessage; -import org.apollo.game.message.impl.SetPlayerActionMessage; -import org.apollo.game.message.impl.SetUpdatedRegionMessage; -import org.apollo.game.message.impl.SetWidgetItemModelMessage; -import org.apollo.game.message.impl.SetWidgetModelAnimationMessage; -import org.apollo.game.message.impl.SetWidgetNpcModelMessage; -import org.apollo.game.message.impl.SetWidgetPlayerModelMessage; -import org.apollo.game.message.impl.SetWidgetTextMessage; -import org.apollo.game.message.impl.SetWidgetVisibilityMessage; -import org.apollo.game.message.impl.SwitchTabInterfaceMessage; -import org.apollo.game.message.impl.UpdateItemsMessage; -import org.apollo.game.message.impl.UpdateRunEnergyMessage; -import org.apollo.game.message.impl.UpdateSkillMessage; -import org.apollo.game.message.impl.UpdateSlottedItemsMessage; -import org.apollo.game.message.impl.UpdateTileItemMessage; -import org.apollo.game.message.impl.UpdateWeightMessage; -import org.apollo.net.meta.PacketMetaDataGroup; -import org.apollo.net.release.Release; - -/** - * A {@link Release} implementation for the 377 protocol. - * - * @author Graham - */ -public final class Release377 extends Release { - - /** - * The incoming packet lengths array. - */ - public static final int[] PACKET_LENGTHS = { 0, 12, 0, 6, 6, 0, 0, 0, 2, 0, // 0 - 0, 0, 0, 2, 0, 0, 0, 0, 0, 4, // 10 - 0, 0, 2, 0, 6, 0, 0, 0, -1, 0, // 20 - 0, 4, 0, 0, 0, 0, 8, 0, 0, 0, // 30 - 0, 0, 2, 0, 0, 2, 0, 0, 0, -1, // 40 - 6, 0, 0, 0, 6, 6, -1, 8, 0, 0, // 50 - 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, // 60 - 0, 6, 0, 0, 0, 4, 0, 6, 4, 2, // 70 - 2, 0, 0, 8, 0, 0, 0, 0, 0, 0, // 80 - 0, 6, 0, 0, 0, 4, 0, 0, 0, 0, // 90 - 6, 0, 0, 0, 4, 0, 0, 0, 0, 0, // 100 - 0, 0, 2, 0, 0, 0, 2, 0, 0, 1, // 110 - 8, 0, 0, 7, 0, 0, 1, 0, 0, 0, // 120 - 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, // 130 - 4, 8, 0, 8, 0, 0, 0, 0, 0, 0, // 140 - 0, 0, 12, 0, 0, 0, 0, 4, 6, 0, // 150 - 8, 6, 0, 13, 0, 1, 0, 0, 0, 0, // 160 - 0, -1, 0, 3, 0, 0, 3, 6, 0, 0, // 170 - 0, 6, 0, 0, 10, 0, 0, 1, 0, 0, // 180 - 0, 0, 0, 0, 2, 0, 0, 4, 0, 0, // 190 - 0, 0, 0, 6, 0, 0, 8, 0, 0, 0, // 200 - 8, 12, 0, -1, 0, 0, 0, 8, 0, 0, // 210 - 0, 0, 3, 0, 0, 0, 2, 9, 6, 0, // 220 - 6, 6, 0, 2, 0, 0, 0, 0, 0, 0, // 230 - 0, 6, 0, 0, -1, 2, 0, -1, 0, 0, // 240 - 0, 0, 0, 0, 0, 0 // 250 - }; - - /** - * Creates and initialises this release. - */ - public Release377() { - super(377, PacketMetaDataGroup.createFromArray(PACKET_LENGTHS)); - init(); - } - - /** - * Initialises this release by registering encoders and decoders. - */ - private void init() { - WalkMessageDecoder walkMessageDecoder = new WalkMessageDecoder(); - register(213, walkMessageDecoder); - register(28, walkMessageDecoder); - register(247, walkMessageDecoder); - - register(248, new KeepAliveMessageDecoder()); - register(163, new PlayerDesignMessageDecoder()); - register(49, new PublicChatMessageDecoder()); - register(56, new CommandMessageDecoder()); - register(123, new SwitchItemMessageDecoder()); - - register(181, new FirstObjectActionMessageDecoder()); - register(241, new SecondObjectActionMessageDecoder()); - register(50, new ThirdObjectActionMessageDecoder()); - - register(203, new FirstItemOptionMessageDecoder()); - register(24, new SecondItemOptionMessageDecoder()); - register(161, new ThirdItemOptionMessageDecoder()); - register(228, new FourthItemOptionMessageDecoder()); - register(4, new FifthItemOptionMessageDecoder()); - - register(3, new FirstItemActionMessageDecoder()); - register(177, new SecondItemActionMessageDecoder()); - register(91, new ThirdItemActionMessageDecoder()); - register(231, new FourthItemActionMessageDecoder()); - register(158, new FifthItemActionMessageDecoder()); - - register(79, new ButtonMessageDecoder()); - register(110, new ClosedInterfaceMessageDecoder()); - register(75, new EnteredAmountMessageDecoder()); - register(226, new DialogueContinueMessageDecoder()); - register(119, new FlashingTabClickedMessageDecoder()); - - register(1, new ItemOnItemMessageDecoder()); - register(57, new ItemOnNpcMessageDecoder()); - register(36, new MagicOnItemMessageDecoder()); - register(31, new MagicOnPlayerMessageDecoder()); - register(104, new MagicOnNpcMessageDecoder()); - - register(187, new FocusUpdateMessageDecoder()); - register(19, new MouseClickedMessageDecoder()); - register(171, new FlaggedMouseEventMessageDecoder()); - register(140, new ArrowKeyMessageDecoder()); - register(176, new PrivacyOptionMessageDecoder()); - - SpamPacketMessageDecoder spamMessageDecoder = new SpamPacketMessageDecoder(); - register(40, spamMessageDecoder); - register(244, spamMessageDecoder); - - register(112, new FirstNpcActionMessageDecoder()); - register(67, new SecondNpcActionMessageDecoder()); - register(13, new ThirdNpcActionMessageDecoder()); - register(42, new FourthNpcActionMessageDecoder()); - register(8, new FifthNpcActionMessageDecoder()); - - register(71, new TakeTileItemMessageDecoder()); - register(152, new ItemOnObjectMessageDecoder()); - - register(245, new FirstPlayerActionMessageDecoder()); - register(233, new SecondPlayerActionMessageDecoder()); - register(194, new ThirdPlayerActionMessageDecoder()); - register(116, new FourthPlayerActionMessageDecoder()); - register(45, new FifthPlayerActionMessageDecoder()); - - register(120, new AddFriendMessageDecoder()); - register(217, new AddIgnoreMessageDecoder()); - register(141, new RemoveFriendMessageDecoder()); - register(160, new RemoveIgnoreMessageDecoder()); - register(227, new PrivateChatMessageDecoder()); - - register(184, new ReportAbuseMessageDecoder()); - - register(IdAssignmentMessage.class, new IdAssignmentMessageEncoder()); - register(RegionChangeMessage.class, new RegionChangeMessageEncoder()); - register(ServerChatMessage.class, new ServerMessageMessageEncoder()); - register(PlayerSynchronizationMessage.class, new PlayerSynchronizationMessageEncoder()); - register(OpenInterfaceMessage.class, new OpenInterfaceMessageEncoder()); - register(CloseInterfaceMessage.class, new CloseInterfaceMessageEncoder()); - register(SwitchTabInterfaceMessage.class, new SwitchTabInterfaceMessageEncoder()); - register(LogoutMessage.class, new LogoutMessageEncoder()); - register(UpdateItemsMessage.class, new UpdateItemsMessageEncoder()); - register(UpdateSlottedItemsMessage.class, new UpdateSlottedItemsMessageEncoder()); - register(UpdateSkillMessage.class, new UpdateSkillMessageEncoder()); - register(OpenInterfaceSidebarMessage.class, new OpenInterfaceSidebarMessageEncoder()); - register(EnterAmountMessage.class, new EnterAmountMessageEncoder()); - register(SetWidgetTextMessage.class, new SetWidgetTextMessageEncoder()); - register(NpcSynchronizationMessage.class, new NpcSynchronizationMessageEncoder()); - - register(SetWidgetVisibilityMessage.class, new SetWidgetVisibilityMessageEncoder()); - register(SetWidgetItemModelMessage.class, new SetWidgetItemModelMessageEncoder()); - register(SetWidgetNpcModelMessage.class, new SetWidgetNpcModelMessageEncoder()); - register(SetWidgetPlayerModelMessage.class, new SetWidgetPlayerModelMessageEncoder()); - register(SetWidgetModelAnimationMessage.class, new SetWidgetModelAnimationMessageEncoder()); - - register(ConfigMessage.class, new ConfigMessageEncoder()); - register(DisplayTabInterfaceMessage.class, new DisplayTabInterfaceMessageEncoder()); - register(SetUpdatedRegionMessage.class, new SetUpdatedRegionMessageEncoder()); - register(UpdateRunEnergyMessage.class, new UpdateRunEnergyMessageEncoder()); - register(PrivacyOptionMessage.class, new PrivacyOptionMessageEncoder()); - register(OpenDialogueInterfaceMessage.class, new OpenDialogueInterfaceMessageEncoder()); - register(UpdateWeightMessage.class, new UpdateWeightMessageEncoder()); - register(SetPlayerActionMessage.class, new SetPlayerActionMessageEncoder()); - register(DisplayCrossbonesMessage.class, new DisplayCrossbonesMessageEncoder()); - - register(SendPublicTileItemMessage.class, new AddGlobalTileItemMessageEncoder()); - register(SendTileItemMessage.class, new AddTileItemMessageEncoder()); - register(UpdateTileItemMessage.class, new UpdateTileItemMessageEncoder()); - register(RemoveTileItemMessage.class, new RemoveTileItemMessageEncoder()); - register(SendObjectMessage.class, new SendObjectMessageEncoder()); - register(RemoveObjectMessage.class, new RemoveObjectMessageEncoder()); - register(SendProjectileMessage.class, new SendProjectileMessageEncoder()); - - register(GroupedRegionUpdateMessage.class, new GroupedRegionUpdateMessageEncoder(this)); - register(ClearRegionMessage.class, new ClearRegionMessageEncoder()); - - register(ForwardPrivateChatMessage.class, new ForwardPrivateChatMessageEncoder()); - register(FriendServerStatusMessage.class, new FriendServerStatusMessageEncoder()); - register(IgnoreListMessage.class, new IgnoreListMessageEncoder()); - register(SendFriendMessage.class, new SendFriendMessageEncoder()); - register(MobHintIconMessage.class, new MobHintIconMessageEncoder()); - register(PositionHintIconMessage.class, new PositionHintIconMessageEncoder()); - register(FlashTabInterfaceMessage.class, new FlashTabInterfaceMessageEncoder()); - register(OpenSidebarMessage.class, new OpenSidebarMessageEncoder()); - register(OpenOverlayMessage.class, new OpenOverlayMessageEncoder()); - register(OpenDialogueOverlayMessage.class, new OpenDialogueOverlayMessageEncoder()); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/RemoveTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/RemoveTileItemMessageEncoder.java deleted file mode 100644 index f4af1d053..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/RemoveTileItemMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.RemoveTileItemMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link RemoveTileItemMessage}. - * - * @author Major - */ -public final class RemoveTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(RemoveTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(208); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getId()); - builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ReportAbuseMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ReportAbuseMessageDecoder.java deleted file mode 100644 index 1a3f40343..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ReportAbuseMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ReportAbuseMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageDecoder} for the {@link ReportAbuseMessage}. - * - * @author Major - */ -public final class ReportAbuseMessageDecoder extends MessageDecoder { - - @Override - public ReportAbuseMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - String name = NameUtil.decodeBase37(reader.getSigned(DataType.LONG)); - int rule = (int) reader.getUnsigned(DataType.BYTE); - boolean mute = reader.getUnsigned(DataType.BYTE) == 1; - - return new ReportAbuseMessage(name, rule, mute); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/SecondItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/SecondItemActionMessageDecoder.java deleted file mode 100644 index a6ea32ff7..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SecondItemActionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the second {@link ItemActionMessage}. - * - * @author Graham - */ -public final class SecondItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - - return new ItemActionMessage(2, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SecondItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/SecondItemOptionMessageDecoder.java deleted file mode 100644 index d344c1011..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SecondItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the second {@link ItemOptionMessage}. - * - * @author Graham - */ -public final class SecondItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - - return new ItemOptionMessage(2, interfaceId, id, slot); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SendFriendMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SendFriendMessageEncoder.java deleted file mode 100644 index 83d846d52..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SendFriendMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SendFriendMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; -import org.apollo.util.NameUtil; - -/** - * A {@link MessageEncoder} for the {@link SendFriendMessage}. - * - * @author Major - */ -public final class SendFriendMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendFriendMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(78); - builder.put(DataType.LONG, NameUtil.encodeBase37(message.getUsername())); - builder.put(DataType.BYTE, message.getEncodedWorld()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SendObjectMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SendObjectMessageEncoder.java deleted file mode 100644 index 5aadde3fe..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SendObjectMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SendObjectMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SendObjectMessage}. - * - * @author Major - */ -public final class SendObjectMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendObjectMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(152); - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getType() << 2 | message.getOrientation()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId()); - builder.put(DataType.BYTE, DataTransformation.ADD, message.getPositionOffset()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SendProjectileMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SendProjectileMessageEncoder.java deleted file mode 100644 index 1d4703692..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SendProjectileMessageEncoder.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SendProjectileMessage; -import org.apollo.game.model.Position; -import org.apollo.game.model.entity.Projectile; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SendProjectileMessage}. - */ -public final class SendProjectileMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SendProjectileMessage message) { - Projectile projectile = message.getProjectile(); - Position source = projectile.getPosition(); - Position destination = projectile.getDestination(); - - GamePacketBuilder builder = new GamePacketBuilder(181); - builder.put(DataType.BYTE, message.getPositionOffset()); - builder.put(DataType.BYTE, destination.getX() - source.getX()); - builder.put(DataType.BYTE, destination.getY() - source.getY()); - builder.put(DataType.SHORT, projectile.getTarget()); - builder.put(DataType.SHORT, projectile.getGraphic()); - builder.put(DataType.BYTE, projectile.getStartHeight()); - builder.put(DataType.BYTE, projectile.getEndHeight()); - builder.put(DataType.SHORT, projectile.getDelay()); - builder.put(DataType.SHORT, projectile.getLifetime()); - builder.put(DataType.BYTE, projectile.getPitch()); - builder.put(DataType.BYTE, projectile.getOffset()); - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/ServerMessageMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/ServerMessageMessageEncoder.java deleted file mode 100644 index ae2c5f9b3..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ServerMessageMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ServerChatMessage; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link ServerChatMessage}. - * - * @author Graham - */ -public final class ServerMessageMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(ServerChatMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(63, PacketType.VARIABLE_BYTE); - builder.putString(message.getMessage()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SetPlayerActionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetPlayerActionMessageEncoder.java deleted file mode 100644 index ea8097df2..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetPlayerActionMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetPlayerActionMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * The {@link MessageEncoder} for the {@link SetPlayerActionMessage}. - * - * @author Major - */ -public final class SetPlayerActionMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetPlayerActionMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(157, PacketType.VARIABLE_BYTE); - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getSlot()); - builder.putString(message.getText()); - builder.put(DataType.BYTE, message.isPrimaryAction() ? 0 : 1); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SetUpdatedRegionMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetUpdatedRegionMessageEncoder.java deleted file mode 100644 index ac0ca908f..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetUpdatedRegionMessageEncoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetUpdatedRegionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetUpdatedRegionMessage}. - * - * @author Chris Fletcher - * @author Major - */ -public final class SetUpdatedRegionMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetUpdatedRegionMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(75); - Position base = message.getPlayerPosition(), position = message.getRegionPosition(); - - builder.put(DataType.BYTE, DataTransformation.NEGATE, position.getLocalX(base)); - builder.put(DataType.BYTE, DataTransformation.ADD, position.getLocalY(base)); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SetWidgetItemModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetWidgetItemModelMessageEncoder.java deleted file mode 100644 index ea9a1f006..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetWidgetItemModelMessageEncoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetWidgetItemModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetItemModelMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetItemModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetItemModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(21); - - builder.put(DataType.SHORT, message.getZoom()); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getModelId()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SetWidgetModelAnimationMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetWidgetModelAnimationMessageEncoder.java deleted file mode 100644 index 030636f33..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetWidgetModelAnimationMessageEncoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetWidgetModelAnimationMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetModelAnimationMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetModelAnimationMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetModelAnimationMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(2); - - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getAnimation() & 0xFFFF); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SetWidgetModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetWidgetModelMessageEncoder.java deleted file mode 100644 index 8df38af57..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetWidgetModelMessageEncoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetWidgetModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetModelMessage}. - * - * @author Major - */ -public final class SetWidgetModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(216); - - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getModel()); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/SetWidgetNpcModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetWidgetNpcModelMessageEncoder.java deleted file mode 100644 index c705314b3..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetWidgetNpcModelMessageEncoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetWidgetNpcModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetNpcModelMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetNpcModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetNpcModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(162); - - builder.put(DataType.SHORT, DataTransformation.ADD, message.getModelId()); - builder.put(DataType.SHORT, DataOrder.LITTLE, message.getInterfaceId()); - - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/SetWidgetPlayerModelMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetWidgetPlayerModelMessageEncoder.java deleted file mode 100644 index 07da7893e..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetWidgetPlayerModelMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetWidgetPlayerModelMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetPlayerModelMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetPlayerModelMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetPlayerModelMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(255); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SetWidgetTextMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetWidgetTextMessageEncoder.java deleted file mode 100644 index 525e36fbe..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetWidgetTextMessageEncoder.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetWidgetTextMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetTextMessage}. - * - * @author Graham - */ -public final class SetWidgetTextMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetTextMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(232, PacketType.VARIABLE_SHORT); - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId()); - builder.putString(message.getText()); - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/SetWidgetVisibilityMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SetWidgetVisibilityMessageEncoder.java deleted file mode 100644 index 2e7062608..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SetWidgetVisibilityMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SetWidgetVisibilityMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SetWidgetVisibilityMessage}. - * - * @author Chris Fletcher - */ -public final class SetWidgetVisibilityMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SetWidgetVisibilityMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(82); - - builder.put(DataType.BYTE, message.isVisible() ? 0 : 1); - builder.put(DataType.SHORT, message.getWidgetId()); - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/SwitchItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/SwitchItemMessageDecoder.java deleted file mode 100644 index 6c1bef294..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SwitchItemMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SwitchItemMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link SwitchItemMessage}. - * - * @author Graham - */ -public final class SwitchItemMessageDecoder extends MessageDecoder { - - @Override - public SwitchItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int newSlot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - boolean inserting = reader.getUnsigned(DataType.BYTE, DataTransformation.ADD) == 1; - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int oldSlot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - return new SwitchItemMessage(interfaceId, inserting, oldSlot, newSlot); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/SwitchTabInterfaceMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/SwitchTabInterfaceMessageEncoder.java deleted file mode 100644 index e7d5d4a95..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/SwitchTabInterfaceMessageEncoder.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.SwitchTabInterfaceMessage; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link SwitchTabInterfaceMessage}. - * - * @author Graham - */ -public final class SwitchTabInterfaceMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(SwitchTabInterfaceMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(10); - builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getTabId()); - builder.put(DataType.SHORT, DataTransformation.ADD, message.getInterfaceId()); - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/TakeTileItemMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/TakeTileItemMessageDecoder.java deleted file mode 100644 index e11e58d42..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/TakeTileItemMessageDecoder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.TakeTileItemMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link TakeTileItemMessage}. - * - * @author Major - */ -public final class TakeTileItemMessageDecoder extends MessageDecoder { - - @Override - public TakeTileItemMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - return new TakeTileItemMessage(id, new Position(x, y)); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/ThirdItemActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ThirdItemActionMessageDecoder.java deleted file mode 100644 index 315c40d65..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ThirdItemActionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemActionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link ItemActionMessage}. - * - * @author Graham - */ -public final class ThirdItemActionMessageDecoder extends MessageDecoder { - - @Override - public ItemActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT); - - return new ItemActionMessage(3, interfaceId, id, slot); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/ThirdItemOptionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ThirdItemOptionMessageDecoder.java deleted file mode 100644 index e61c9ee28..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ThirdItemOptionMessageDecoder.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ItemOptionMessage; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link ItemOptionMessage}. - * - * @author Chris Fletcher - */ -public final class ThirdItemOptionMessageDecoder extends MessageDecoder { - - @Override - public ItemOptionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - - return new ItemOptionMessage(3, interfaceId, id, slot); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/ThirdObjectActionMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/ThirdObjectActionMessageDecoder.java deleted file mode 100644 index 63a05a3fc..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/ThirdObjectActionMessageDecoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.ObjectActionMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the third {@link ObjectActionMessage}. - * - * @author Graham - */ -public final class ThirdObjectActionMessageDecoder extends MessageDecoder { - - @Override - public ObjectActionMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - - return new ObjectActionMessage(3, id, new Position(x, y)); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/UpdateItemsMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/UpdateItemsMessageEncoder.java deleted file mode 100644 index 0523051bf..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/UpdateItemsMessageEncoder.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.UpdateItemsMessage; -import org.apollo.game.model.Item; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateItemsMessage}. - * - * @author Graham - */ -public final class UpdateItemsMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateItemsMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(206, PacketType.VARIABLE_SHORT); - - Item[] items = message.getItems(); - - builder.put(DataType.SHORT, message.getInterfaceId()); - builder.put(DataType.SHORT, items.length); - - for (Item item : items) { - int id = item == null ? -1 : item.getId(); - int amount = item == null ? 0 : item.getAmount(); - - builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, id + 1); - - if (amount > 254) { - builder.put(DataType.BYTE, DataTransformation.NEGATE, 255); - builder.put(DataType.INT, DataOrder.LITTLE, amount); - } else { - builder.put(DataType.BYTE, DataTransformation.NEGATE, amount); - } - } - - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/UpdateRunEnergyMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/UpdateRunEnergyMessageEncoder.java deleted file mode 100644 index 59eebe7a8..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/UpdateRunEnergyMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.UpdateRunEnergyMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateRunEnergyMessage} - * - * @author Major - */ -public final class UpdateRunEnergyMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateRunEnergyMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(125); - builder.put(DataType.BYTE, message.getEnergy()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/UpdateSkillMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/UpdateSkillMessageEncoder.java deleted file mode 100644 index f6ebc9c8d..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/UpdateSkillMessageEncoder.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.UpdateSkillMessage; -import org.apollo.game.model.entity.Skill; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateSkillMessage}. - * - * @author Graham - */ -public final class UpdateSkillMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateSkillMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(49); - Skill skill = message.getSkill(); - - builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getId()); - builder.put(DataType.BYTE, skill.getCurrentLevel()); - builder.put(DataType.INT, (int) skill.getExperience()); - - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/UpdateSlottedItemsMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/UpdateSlottedItemsMessageEncoder.java deleted file mode 100644 index 1ed51adff..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/UpdateSlottedItemsMessageEncoder.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.UpdateSlottedItemsMessage; -import org.apollo.game.model.Item; -import org.apollo.game.model.inv.SlottedItem; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.meta.PacketType; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateSlottedItemsMessage}. - * - * @author Graham - */ -public final class UpdateSlottedItemsMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateSlottedItemsMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(134, PacketType.VARIABLE_SHORT); - SlottedItem[] items = message.getSlottedItems(); - - builder.put(DataType.SHORT, message.getInterfaceId()); - - for (SlottedItem slottedItem : items) { - builder.putSmart(slottedItem.getSlot()); - - Item item = slottedItem.getItem(); - int id = item == null ? -1 : item.getId(); - int amount = item == null ? 0 : item.getAmount(); - - builder.put(DataType.SHORT, id + 1); - - if (amount > 254) { - builder.put(DataType.BYTE, 255); - builder.put(DataType.INT, amount); - } else { - builder.put(DataType.BYTE, amount); - } - } - - return builder.toGamePacket(); - } - -} diff --git a/game/src/main/java/org/apollo/game/release/r377/UpdateTileItemMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/UpdateTileItemMessageEncoder.java deleted file mode 100644 index 4e671e4bb..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/UpdateTileItemMessageEncoder.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.UpdateTileItemMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateTileItemMessage}. - * - * @author Major - */ -public final class UpdateTileItemMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateTileItemMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(121); - builder.put(DataType.BYTE, message.getPositionOffset()); - builder.put(DataType.SHORT, message.getId()); - builder.put(DataType.SHORT, message.getPreviousAmount()); - builder.put(DataType.SHORT, message.getAmount()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/UpdateWeightMessageEncoder.java b/game/src/main/java/org/apollo/game/release/r377/UpdateWeightMessageEncoder.java deleted file mode 100644 index 2c550cb52..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/UpdateWeightMessageEncoder.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.UpdateWeightMessage; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketBuilder; -import org.apollo.net.release.MessageEncoder; - -/** - * A {@link MessageEncoder} for the {@link UpdateWeightMessage}. - * - * @author Major - */ -public final class UpdateWeightMessageEncoder extends MessageEncoder { - - @Override - public GamePacket encode(UpdateWeightMessage message) { - GamePacketBuilder builder = new GamePacketBuilder(174); - builder.put(DataType.SHORT, message.getWeight()); - return builder.toGamePacket(); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/WalkMessageDecoder.java b/game/src/main/java/org/apollo/game/release/r377/WalkMessageDecoder.java deleted file mode 100644 index e57c5f0bb..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/WalkMessageDecoder.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.apollo.game.release.r377; - -import org.apollo.game.message.impl.WalkMessage; -import org.apollo.game.model.Position; -import org.apollo.net.codec.game.DataOrder; -import org.apollo.net.codec.game.DataTransformation; -import org.apollo.net.codec.game.DataType; -import org.apollo.net.codec.game.GamePacket; -import org.apollo.net.codec.game.GamePacketReader; -import org.apollo.net.release.MessageDecoder; - -/** - * A {@link MessageDecoder} for the {@link WalkMessage}. - * - * @author Graham - */ -public final class WalkMessageDecoder extends MessageDecoder { - - @Override - public WalkMessage decode(GamePacket packet) { - GamePacketReader reader = new GamePacketReader(packet); - - int length = packet.getLength(); - if (packet.getOpcode() == 213) { - length -= 14; // strip off anti-cheat data - } - - int steps = (length - 5) / 2; - int[][] path = new int[steps][2]; - - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - boolean run = reader.getUnsigned(DataType.BYTE) == 1; - int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - - for (int i = 0; i < steps; i++) { - path[i][0] = (int) reader.getSigned(DataType.BYTE); - path[i][1] = (int) reader.getSigned(DataType.BYTE, DataTransformation.SUBTRACT); - } - - Position[] positions = new Position[steps + 1]; - positions[0] = new Position(x, y); - for (int i = 0; i < steps; i++) { - positions[i + 1] = new Position(path[i][0] + x, path[i][1] + y); - } - - return new WalkMessage(positions, run); - } - -} \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/release/r377/package-info.java b/game/src/main/java/org/apollo/game/release/r377/package-info.java deleted file mode 100644 index a212df7f3..000000000 --- a/game/src/main/java/org/apollo/game/release/r377/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Contains codecs for the 377 release. - */ -package org.apollo.game.release.r377; \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/service/GameService.java b/game/src/main/java/org/apollo/game/service/GameService.java index 0b393c6f4..5046519bf 100644 --- a/game/src/main/java/org/apollo/game/service/GameService.java +++ b/game/src/main/java/org/apollo/game/service/GameService.java @@ -18,6 +18,7 @@ import org.apollo.game.model.area.Region; import org.apollo.game.model.entity.MobRepository; import org.apollo.game.model.entity.Player; +import org.apollo.game.model.inter.DisplayMode; import org.apollo.game.session.GameSession; import org.apollo.game.session.LoginSession; import org.apollo.game.sync.ClientSynchronizer; @@ -52,7 +53,7 @@ private static final class LoginPlayerRequest { /** * Creates the LoginPlayerRequest. * - * @param player The {@link Player} logging in. + * @param player The {@link Player} logging in. * @param session The {@link LoginSession} of the Player. */ public LoginPlayerRequest(Player player, LoginSession session) { @@ -81,7 +82,8 @@ public LoginPlayerRequest(Player player, LoginSession session) { /** * The scheduled executor service. */ - private final ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(ThreadUtil.create("GameService")); + private final ScheduledExecutorService executor = Executors + .newSingleThreadScheduledExecutor(ThreadUtil.create("GameService")); /** * The Queue of LoginPlayers to add. @@ -123,10 +125,6 @@ public synchronized void finalizePlayerRegistration(Player player) { world.register(player); Region region = world.getRegionRepository().fromPosition(player.getPosition()); region.addEntity(player); - - if (!player.getSession().isReconnecting()) { - player.sendInitialMessages(); - } } /** @@ -170,7 +168,7 @@ public synchronized void pulse() { /** * Registers a {@link Player} at the end of the next cycle. * - * @param player The Player to register. + * @param player The Player to register. * @param session the {@link LoginSession} of the Player. */ public void registerPlayer(Player player, LoginSession session) { @@ -218,8 +216,12 @@ private void finalizeRegistrations() { } else if (world.getPlayerRepository().full()) { request.session.sendLoginFailure(LoginConstants.STATUS_SERVER_FULL); } else { - request.session.sendLoginSuccess(player); finalizePlayerRegistration(player); + request.session.sendLoginSuccess(player); + if (!player.getSession().isReconnecting()) { + player.sendInitialMessages(request.session.getRequest() + .getDisplayMode() == 1 ? DisplayMode.RESIZABLE : DisplayMode.FIXED); + } } } } @@ -243,8 +245,8 @@ private void finalizeUnregistrations() { /** * Initializes the game service. * - * @throws IOException If there is an error accessing the file. - * @throws SAXException If there is an error parsing the file. + * @throws IOException If there is an error accessing the file. + * @throws SAXException If there is an error parsing the file. * @throws ReflectiveOperationException If a MessageHandler could not be created. */ private void init() throws IOException, SAXException, ReflectiveOperationException { diff --git a/game/src/main/java/org/apollo/game/service/LoginService.java b/game/src/main/java/org/apollo/game/service/LoginService.java index 326fbf87e..0f7a4053d 100644 --- a/game/src/main/java/org/apollo/game/service/LoginService.java +++ b/game/src/main/java/org/apollo/game/service/LoginService.java @@ -88,7 +88,7 @@ public void submitLoadRequest(LoginSession session, LoginRequest request) throws * Submits a save request. * * @param session The session submitting this request. - * @param player The player to save. + * @param player The player to save. */ public void submitSaveRequest(GameSession session, Player player) { executor.submit(new PlayerSaverWorker(serializer, session, player)); @@ -97,8 +97,8 @@ public void submitSaveRequest(GameSession session, Player player) { /** * Initialises the login service. * - * @throws SAXException If there is an error parsing the XML file. - * @throws IOException If there is an error accessing the file. + * @throws SAXException If there is an error parsing the XML file. + * @throws IOException If there is an error accessing the file. * @throws ReflectiveOperationException If the {@link PlayerSerializer} implementation could not be created. */ private void init() throws SAXException, IOException, ReflectiveOperationException { @@ -136,9 +136,13 @@ private boolean requiresUpdate(LoginRequest request) throws IOException { } int[] clientCrcs = request.getArchiveCrcs(); - int[] serverCrcs = context.getFileSystem().getCrcs(); - - return !Arrays.equals(clientCrcs, serverCrcs); + for (int index = 0; index < clientCrcs.length; index++) { + int crc = context.getFileSystem().getArchive(index).getCRC32(); + if (index != 16 && crc != clientCrcs[index]) { + return true; + } + } + return false; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/service/UpdateService.java b/game/src/main/java/org/apollo/game/service/UpdateService.java index dacd37fe0..df4f99207 100644 --- a/game/src/main/java/org/apollo/game/service/UpdateService.java +++ b/game/src/main/java/org/apollo/game/service/UpdateService.java @@ -1,23 +1,17 @@ package org.apollo.game.service; -import java.io.FileNotFoundException; +import org.apollo.Service; +import org.apollo.cache.Cache; +import org.apollo.net.update.*; + import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.logging.Level; import java.util.logging.Logger; -import org.apollo.Service; -import org.apollo.cache.IndexedFileSystem; -import org.apollo.net.update.HttpRequestWorker; -import org.apollo.net.update.JagGrabRequestWorker; -import org.apollo.net.update.OnDemandRequestWorker; -import org.apollo.net.update.RequestWorker; -import org.apollo.net.update.UpdateDispatcher; - /** * A class which services file requests. * @@ -66,17 +60,12 @@ public UpdateDispatcher getDispatcher() { @Override public void start() { - int release = context.getRelease().getReleaseNumber(); - try { - Path base = Paths.get("data/fs/", Integer.toString(release)); - - for (int i = 0; i < THREADS_PER_TYPE; i++) { - workers.add(new JagGrabRequestWorker(dispatcher, new IndexedFileSystem(base, true))); - workers.add(new OnDemandRequestWorker(dispatcher, new IndexedFileSystem(base, true))); - workers.add(new HttpRequestWorker(dispatcher, new IndexedFileSystem(base, true))); - } - } catch (FileNotFoundException reason) { - logger.log(Level.SEVERE, "Unable to find index or data files from the file system.", reason); + Path base = Paths.get("data/fs/", Integer.toString(context.getRelease().getReleaseNumber())); + final var cache = Cache.openCache(base); + for (int i = 0; i < THREADS_PER_TYPE; i++) { + workers.add(new JagGrabRequestWorker(dispatcher, cache)); + workers.add(new OnDemandRequestWorker(dispatcher, cache)); + workers.add(new HttpRequestWorker(dispatcher, cache)); } workers.forEach(service::submit); diff --git a/game/src/main/java/org/apollo/game/session/GameSession.java b/game/src/main/java/org/apollo/game/session/GameSession.java index 4c817a8b5..e7d3b298f 100644 --- a/game/src/main/java/org/apollo/game/session/GameSession.java +++ b/game/src/main/java/org/apollo/game/session/GameSession.java @@ -12,7 +12,7 @@ import org.apollo.ServerContext; import org.apollo.game.GameConstants; import org.apollo.game.message.handler.MessageHandlerChainSet; -import org.apollo.game.message.impl.LogoutMessage; +import org.apollo.game.message.impl.encode.LogoutMessage; import org.apollo.game.model.entity.Player; import org.apollo.net.message.Message; diff --git a/game/src/main/java/org/apollo/game/session/LoginSession.java b/game/src/main/java/org/apollo/game/session/LoginSession.java index a87e48968..97b844504 100644 --- a/game/src/main/java/org/apollo/game/session/LoginSession.java +++ b/game/src/main/java/org/apollo/game/session/LoginSession.java @@ -1,10 +1,13 @@ package org.apollo.game.session; +import io.netty.buffer.ByteBuf; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import java.io.IOException; +import java.security.SecureRandom; +import java.util.NoSuchElementException; import java.util.Optional; import org.apollo.ServerContext; @@ -30,6 +33,11 @@ */ public final class LoginSession extends Session { + /** + * The secure random number generator. + */ + private static final SecureRandom RANDOM = new SecureRandom(); + /** * The ServerContext. */ @@ -40,6 +48,11 @@ public final class LoginSession extends Session { */ private LoginRequest request; + /** + * The key assigned for this session. + */ + private long serverSessionKey = RANDOM.nextLong(); + /** * Creates a login session for the specified channel. * @@ -49,6 +62,13 @@ public final class LoginSession extends Session { public LoginSession(Channel channel, ServerContext context) { super(channel); this.context = context; + init(); + } + + private void init() { + ByteBuf buf = channel.alloc().buffer(Long.BYTES); + buf.writeLong(serverSessionKey); + channel.write(new LoginResponse(LoginConstants.STATUS_EXCHANGE_DATA, buf)); } @Override @@ -59,7 +79,7 @@ public void destroy() { /** * Handles a response from the login service. * - * @param request The request this response corresponds to. + * @param request The request this response corresponds to. * @param response The response. */ public void handlePlayerLoaderResponse(LoginRequest request, PlayerLoaderResponse response) { @@ -87,9 +107,7 @@ public void messageReceived(Object message) throws Exception { * @param status The failure status. */ public void sendLoginFailure(int status) { - boolean flagged = false; - LoginResponse response = new LoginResponse(status, 0, flagged); - channel.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); + channel.writeAndFlush(new LoginResponse(status)).addListener(ChannelFutureListener.CLOSE); } /** @@ -105,20 +123,36 @@ public void sendLoginSuccess(Player player) { channel.attr(ApolloHandler.SESSION_KEY).set(session); player.setSession(session); - int rights = player.getPrivilegeLevel().toInteger(); - channel.writeAndFlush(new LoginResponse(LoginConstants.STATUS_OK, rights, flagged)); + final var payload = channel.alloc() + .buffer(Byte.BYTES * 2 + Integer.BYTES + Byte.BYTES * 2 + Short.BYTES + Byte.BYTES); + payload.writeByte(13); + + boolean isTrusted = false; + payload.writeBoolean(isTrusted); + payload.writeInt(isTrusted ? randomPair.getEncodingRandom().nextInt() : 0); + payload.writeByte(player.getPrivilegeLevel().toInteger()); + payload.writeBoolean(player.isMembers()); + payload.writeShort(player.getIndex()); + payload.writeBoolean(flagged); // flagged + channel.writeAndFlush(new LoginResponse(LoginConstants.STATUS_OK, payload)); Release release = context.getRelease(); - channel.pipeline().addFirst("messageEncoder", new GameMessageEncoder(release)); - channel.pipeline().addBefore("messageEncoder", "gameEncoder", new GamePacketEncoder(randomPair.getEncodingRandom())); + try { + channel.pipeline().addFirst("messageEncoder", new GameMessageEncoder(release)); + channel.pipeline() + .addBefore("messageEncoder", "gameEncoder", new GamePacketEncoder(randomPair.getEncodingRandom())); - channel.pipeline().addBefore("handler", "gameDecoder", - new GamePacketDecoder(randomPair.getDecodingRandom(), context.getRelease())); - channel.pipeline().addAfter("gameDecoder", "messageDecoder", new GameMessageDecoder(release)); + channel.pipeline().addAfter("gameEncoder", "gameDecoder", + new GamePacketDecoder(randomPair.getDecodingRandom(), context.getRelease())); + channel.pipeline().addAfter("gameDecoder", "messageDecoder", new GameMessageDecoder(release)); + + channel.pipeline().remove("loginDecoder"); + channel.pipeline().remove("loginEncoder"); + } catch (NoSuchElementException ex) { + + } - channel.pipeline().remove("loginDecoder"); - channel.pipeline().remove("loginEncoder"); } /** @@ -131,4 +165,8 @@ private void handleLoginRequest(LoginRequest request) throws IOException { LoginService service = context.getLoginService(); service.submitLoadRequest(this, request); } + + public LoginRequest getRequest() { + return request; + } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/session/UpdateSession.java b/game/src/main/java/org/apollo/game/session/UpdateSession.java index a6e1a6c8f..4cc30278a 100644 --- a/game/src/main/java/org/apollo/game/session/UpdateSession.java +++ b/game/src/main/java/org/apollo/game/session/UpdateSession.java @@ -1,10 +1,14 @@ package org.apollo.game.session; import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; import io.netty.handler.codec.http.HttpRequest; - import org.apollo.ServerContext; import org.apollo.net.codec.jaggrab.JagGrabRequest; +import org.apollo.net.codec.login.LoginConstants; +import org.apollo.net.codec.update.OnDemandInfo; +import org.apollo.net.codec.update.OnDemandInfoResponse; import org.apollo.net.codec.update.OnDemandRequest; import org.apollo.net.update.UpdateDispatcher; @@ -19,6 +23,7 @@ public final class UpdateSession extends Session { * The server context. */ private final ServerContext context; + private boolean handshakeComplete; /** * Creates an update session for the specified channel. @@ -40,8 +45,27 @@ public void destroy() { public void messageReceived(Object message) { UpdateDispatcher dispatcher = context.getUpdateService().getDispatcher(); + if (message instanceof OnDemandRequest) { - dispatcher.dispatch(getChannel(), (OnDemandRequest) message); + if (handshakeComplete) { + dispatcher.dispatch(getChannel(), (OnDemandRequest) message); + } + } else if (message instanceof OnDemandInfo) { + OnDemandInfo info = (OnDemandInfo) message; + + int status; + if (info.getReleaseNumber() == context.getRelease().getReleaseNumber()) { + status = LoginConstants.STATUS_EXCHANGE_DATA; + } else { + status = LoginConstants.STATUS_GAME_UPDATED; + } + + ChannelFuture future = channel.write(new OnDemandInfoResponse(status)); + if (status == LoginConstants.STATUS_EXCHANGE_DATA) { + handshakeComplete = true; + } else { + future.addListener(ChannelFutureListener.CLOSE); + } } else if (message instanceof JagGrabRequest) { dispatcher.dispatch(getChannel(), (JagGrabRequest) message); } else if (message instanceof HttpRequest) { @@ -50,5 +74,4 @@ public void messageReceived(Object message) { throw new IllegalArgumentException("Unknown message type."); } } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java b/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java index 6827b838c..d14bef5c0 100644 --- a/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java +++ b/game/src/main/java/org/apollo/game/sync/ParallelClientSynchronizer.java @@ -1,6 +1,6 @@ package org.apollo.game.sync; -import org.apollo.game.message.impl.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.area.RegionCoordinates; import org.apollo.game.model.entity.MobRepository; import org.apollo.game.model.entity.Npc; diff --git a/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java b/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java index 90e0a8c09..ec4f38c26 100644 --- a/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java +++ b/game/src/main/java/org/apollo/game/sync/SequentialClientSynchronizer.java @@ -5,7 +5,7 @@ import java.util.Map; import java.util.Set; -import org.apollo.game.message.impl.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; import org.apollo.game.model.area.RegionCoordinates; import org.apollo.game.model.entity.MobRepository; import org.apollo.game.model.entity.Npc; diff --git a/game/src/main/java/org/apollo/game/sync/block/AppearanceBlock.java b/game/src/main/java/org/apollo/game/sync/block/AppearanceBlock.java index a2a54356c..7dd1a9a8f 100644 --- a/game/src/main/java/org/apollo/game/sync/block/AppearanceBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/AppearanceBlock.java @@ -33,7 +33,7 @@ public final class AppearanceBlock extends SynchronizationBlock { /** * The player's name. */ - private final long name; + private final String name; /** * The npc id this player is appearing as, if any. @@ -61,7 +61,7 @@ public final class AppearanceBlock extends SynchronizationBlock { * @param headIcon The head icon id of the player. * @param isSkulled Whether or not the player is skulled. */ - AppearanceBlock(long name, Appearance appearance, int combat, int skill, Inventory equipment, int headIcon, boolean isSkulled) { + AppearanceBlock(String name, Appearance appearance, int combat, int skill, Inventory equipment, int headIcon, boolean isSkulled) { this(name, appearance, combat, skill, equipment, headIcon, isSkulled, -1); } @@ -77,7 +77,7 @@ public final class AppearanceBlock extends SynchronizationBlock { * @param isSkulled Whether or not the player is skulled. * @param npcId The npc id of the player, if they are appearing as an npc, (otherwise {@code -1}). */ - AppearanceBlock(long name, Appearance appearance, int combat, int skill, Inventory equipment, int headIcon, boolean isSkulled, int npcId) { + AppearanceBlock(String name, Appearance appearance, int combat, int skill, Inventory equipment, int headIcon, boolean isSkulled, int npcId) { this.name = name; this.appearance = appearance; this.combat = combat; @@ -138,7 +138,7 @@ public boolean isSkulled() { * * @return The player's name. */ - public long getName() { + public String getName() { return name; } diff --git a/game/src/main/java/org/apollo/game/sync/block/ChatBlock.java b/game/src/main/java/org/apollo/game/sync/block/ChatBlock.java index c192eec71..b443f5a0e 100644 --- a/game/src/main/java/org/apollo/game/sync/block/ChatBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/ChatBlock.java @@ -1,6 +1,6 @@ package org.apollo.game.sync.block; -import org.apollo.game.message.impl.PublicChatMessage; +import org.apollo.game.message.impl.decode.PublicChatMessage; import org.apollo.game.model.entity.setting.PrivilegeLevel; /** @@ -76,4 +76,12 @@ public int getTextEffects() { return chatMessage.getTextEffects(); } + /** + * Get the chat type. + * @return the chat type. + */ + public PublicChatMessage.PublicChatType getType() { + return chatMessage.getType(); + } + } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/sync/block/MovementTypeBlock.java b/game/src/main/java/org/apollo/game/sync/block/MovementTypeBlock.java new file mode 100644 index 000000000..3ecc56389 --- /dev/null +++ b/game/src/main/java/org/apollo/game/sync/block/MovementTypeBlock.java @@ -0,0 +1,71 @@ +package org.apollo.game.sync.block; + +import org.apollo.game.sync.block.SynchronizationBlock; + +/** + * The type movement type of a mob. + * + * @author Khaled Abdeljaber + */ +public class MovementTypeBlock extends SynchronizationBlock { + + /** + * The enum Movement mode. + */ + public enum MovementMode { + /** + * Slow movement mode. + */ + SLOW(0), + /** + * Walk movement mode. + */ + WALK(1), + /** + * Run movement mode. + */ + RUN(2), + /** + * Teleport movement mode. + */ + TELEPORT(127); + + private final int clientValue; + + MovementMode(int clientValue) { + this.clientValue = clientValue; + } + + /** + * Gets mode. + * + * @return the mode + */ + public int getClientValue() { + return clientValue; + } + } + + /** + * The Mode. + */ + public MovementMode mode; + + /** + * Instantiates a new Movement type block. + * + * @param mode the mode + */ + MovementTypeBlock(MovementMode mode) { + this.mode = mode; + } + + /** + * Gets mode. + * + * @return the mode + */ + public MovementMode getMode() { + return mode; + } +} diff --git a/game/src/main/java/org/apollo/game/sync/block/SynchronizationBlock.java b/game/src/main/java/org/apollo/game/sync/block/SynchronizationBlock.java index 238ed7bfd..def3cd12c 100644 --- a/game/src/main/java/org/apollo/game/sync/block/SynchronizationBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/SynchronizationBlock.java @@ -1,6 +1,6 @@ package org.apollo.game.sync.block; -import org.apollo.game.message.impl.PublicChatMessage; +import org.apollo.game.message.impl.decode.PublicChatMessage; import org.apollo.game.model.Animation; import org.apollo.game.model.Direction; import org.apollo.game.model.Graphic; @@ -37,7 +37,7 @@ public static SynchronizationBlock createAppearanceBlock(Player player) { int combat = player.getSkillSet().getCombatLevel(); int id = player.hasNpcDefinition() ? player.getDefinition().getId() : -1; - return new AppearanceBlock(player.getEncodedName(), player.getAppearance(), combat, 0, player.getEquipment(), player.getPrayerIcon(), player.isSkulled(), id); + return new AppearanceBlock(player.getUsername(), player.getAppearance(), combat, 0, player.getEquipment(), player.getPrayerIcon(), player.isSkulled(), id); } /** @@ -123,11 +123,11 @@ public static SynchronizationBlock createTransformBlock(int id) { /** * Creates a {@link TurnToPositionBlock} with the specified {@link Position}. * - * @param position The position. + * @param turnPosition The position. * @return The turn to position block. */ - public static SynchronizationBlock createTurnToPositionBlock(Position position) { - return new TurnToPositionBlock(position); + public static SynchronizationBlock createTurnToPositionBlock(Position mobPosition, Position turnPosition) { + return new TurnToPositionBlock(mobPosition, turnPosition); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/sync/block/TemporaryMovementTypeBlock.java b/game/src/main/java/org/apollo/game/sync/block/TemporaryMovementTypeBlock.java new file mode 100644 index 000000000..a9300a762 --- /dev/null +++ b/game/src/main/java/org/apollo/game/sync/block/TemporaryMovementTypeBlock.java @@ -0,0 +1,17 @@ +package org.apollo.game.sync.block; + +/** + * The effect of this mask only lasts a tick. + * @author Khaled Abdeljaber + */ +public class TemporaryMovementTypeBlock extends MovementTypeBlock { + + /** + * Instantiates a new Movement type block. + * + * @param mode the mode + */ + public TemporaryMovementTypeBlock(MovementMode mode) { + super(mode); + } +} diff --git a/game/src/main/java/org/apollo/game/sync/block/TitleBlock.java b/game/src/main/java/org/apollo/game/sync/block/TitleBlock.java new file mode 100644 index 000000000..f14168100 --- /dev/null +++ b/game/src/main/java/org/apollo/game/sync/block/TitleBlock.java @@ -0,0 +1,40 @@ +package org.apollo.game.sync.block; + +import org.apollo.game.sync.block.SynchronizationBlock; + +import java.util.EnumMap; + +/** + * @author Khaled Abdeljaber + */ +public class TitleBlock extends SynchronizationBlock { + + public enum TitlePosition { + NAME_PREFIX, NAME_SUFFIX, COMBAT_SUFFIX + } + + public static class Title { + private String text; + private TitlePosition position; + + public Title(String text, TitlePosition position) { + this.text = text; + this.position = position; + } + } + + private final EnumMap titles; + + TitleBlock(Title single, Title... others) { + this.titles = new EnumMap<>(TitlePosition.class); + titles.put(single.position, single.text); + + for (var title : others) { + this.titles.put(title.position, title.text); + } + } + + public EnumMap getTitles() { + return titles; + } +} diff --git a/game/src/main/java/org/apollo/game/sync/block/TurnToPositionBlock.java b/game/src/main/java/org/apollo/game/sync/block/TurnToPositionBlock.java index a9f94f29e..a81df5403 100644 --- a/game/src/main/java/org/apollo/game/sync/block/TurnToPositionBlock.java +++ b/game/src/main/java/org/apollo/game/sync/block/TurnToPositionBlock.java @@ -9,18 +9,33 @@ */ public final class TurnToPositionBlock extends SynchronizationBlock { + /** + * The position of the mob. + */ + private final Position mobPosition; + /** * The position to turn to. */ - private final Position position; + private final Position turnPosition; /** * Creates the turn to position block. * - * @param position The position to turn to. + * @param turnPosition The position to turn to. + */ + TurnToPositionBlock(Position mobPosition, Position turnPosition) { + this.mobPosition = mobPosition; + this.turnPosition = turnPosition; + } + + /** + * Gets the {@link Position} of the mob. + * + * @return The position of the mob. */ - TurnToPositionBlock(Position position) { - this.position = position; + public Position getMobPosition() { + return mobPosition; } /** @@ -28,8 +43,8 @@ public final class TurnToPositionBlock extends SynchronizationBlock { * * @return The position to turn to. */ - public Position getPosition() { - return position; + public Position getTurnPosition() { + return turnPosition; } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/sync/seg/AddNpcSegment.java b/game/src/main/java/org/apollo/game/sync/seg/AddNpcSegment.java index 196ba2b9d..298f79a16 100644 --- a/game/src/main/java/org/apollo/game/sync/seg/AddNpcSegment.java +++ b/game/src/main/java/org/apollo/game/sync/seg/AddNpcSegment.java @@ -1,5 +1,6 @@ package org.apollo.game.sync.seg; +import org.apollo.game.model.Direction; import org.apollo.game.model.Position; import org.apollo.game.sync.block.SynchronizationBlockSet; @@ -25,6 +26,11 @@ public final class AddNpcSegment extends SynchronizationSegment { */ private final Position position; + /** + * The direction. + */ + private final Direction direction; + /** * Creates the add npc segment. * @@ -32,12 +38,14 @@ public final class AddNpcSegment extends SynchronizationSegment { * @param index The npcs's index. * @param position The position. * @param npcId The id of the npc. + * @param direction The direction of the npc. */ - public AddNpcSegment(SynchronizationBlockSet blockSet, int index, Position position, int npcId) { + public AddNpcSegment(SynchronizationBlockSet blockSet, int index, Position position, int npcId, Direction direction) { super(blockSet); this.index = index; this.position = position; this.npcId = npcId; + this.direction = direction; } /** @@ -67,9 +75,20 @@ public Position getPosition() { return position; } + + /** + * Gets direction. + * + * @return the direction + */ + public Direction getDirection() { + return direction; + } + @Override public SegmentType getType() { return SegmentType.ADD_MOB; } + } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/sync/seg/AddPlayerSegment.java b/game/src/main/java/org/apollo/game/sync/seg/player/AddHighResolutionPlayer.java similarity index 72% rename from game/src/main/java/org/apollo/game/sync/seg/AddPlayerSegment.java rename to game/src/main/java/org/apollo/game/sync/seg/player/AddHighResolutionPlayer.java index a48884c3e..707e1fe3f 100644 --- a/game/src/main/java/org/apollo/game/sync/seg/AddPlayerSegment.java +++ b/game/src/main/java/org/apollo/game/sync/seg/player/AddHighResolutionPlayer.java @@ -1,14 +1,16 @@ -package org.apollo.game.sync.seg; +package org.apollo.game.sync.seg.player; import org.apollo.game.model.Position; import org.apollo.game.sync.block.SynchronizationBlockSet; +import org.apollo.game.sync.seg.SegmentType; +import org.apollo.game.sync.seg.SynchronizationSegment; /** * A {@link SynchronizationSegment} which adds a player. * * @author Graham */ -public final class AddPlayerSegment extends SynchronizationSegment { +public final class AddHighResolutionPlayer extends SynchronizationSegment { /** * The index. @@ -27,7 +29,7 @@ public final class AddPlayerSegment extends SynchronizationSegment { * @param index The player's index. * @param position The position. */ - public AddPlayerSegment(SynchronizationBlockSet blockSet, int index, Position position) { + public AddHighResolutionPlayer(SynchronizationBlockSet blockSet, int index, Position position) { super(blockSet); this.index = index; this.position = position; diff --git a/game/src/main/java/org/apollo/game/sync/seg/player/AddLowResolutionPlayer.java b/game/src/main/java/org/apollo/game/sync/seg/player/AddLowResolutionPlayer.java new file mode 100644 index 000000000..4b0a1d3a4 --- /dev/null +++ b/game/src/main/java/org/apollo/game/sync/seg/player/AddLowResolutionPlayer.java @@ -0,0 +1,24 @@ +package org.apollo.game.sync.seg.player; + +import org.apollo.game.sync.block.SynchronizationBlockSet; +import org.apollo.game.sync.seg.SegmentType; +import org.apollo.game.sync.seg.SynchronizationSegment; + +/** + * @author Khaled Abdeljaber + */ +public class AddLowResolutionPlayer extends SynchronizationSegment { + /** + * Creates the segment. + * + * @param blockSet The block set. + */ + public AddLowResolutionPlayer(SynchronizationBlockSet blockSet) { + super(blockSet); + } + + @Override + public SegmentType getType() { + return SegmentType.REMOVE_MOB; + } +} diff --git a/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java index af06040c5..7824dba9e 100644 --- a/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/NpcSynchronizationTask.java @@ -6,7 +6,7 @@ import java.util.Set; import java.util.stream.Stream; -import org.apollo.game.message.impl.NpcSynchronizationMessage; +import org.apollo.game.message.impl.encode.NpcSynchronizationMessage; import org.apollo.game.model.Position; import org.apollo.game.model.area.Region; import org.apollo.game.model.area.RegionCoordinates; @@ -103,11 +103,11 @@ public void run() { added++; npc.turnTo(npc.getFacingPosition()); - segments.add(new AddNpcSegment(npc.getBlockSet(), npc.getIndex(), position, npc.getId())); + segments.add(new AddNpcSegment(npc.getBlockSet(), npc.getIndex(), position, npc.getId(), npc.getLastDirection())); } } - player.send(new NpcSynchronizationMessage(playerPosition, segments, originalCount)); + player.send(new NpcSynchronizationMessage(playerPosition, segments, originalCount, player.getViewingDistance() > Player.DEFAULT_VIEWING_DISTANCE)); } } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java index 123f3e6d6..81c61b9b5 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PlayerSynchronizationTask.java @@ -1,175 +1,768 @@ package org.apollo.game.sync.task; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Set; -import java.util.stream.Stream; - -import org.apollo.game.message.impl.PlayerSynchronizationMessage; -import org.apollo.game.model.Position; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import org.apollo.cache.def.EquipmentDefinition; +import org.apollo.game.message.impl.encode.PlayerSynchronizationMessage; +import org.apollo.game.model.*; import org.apollo.game.model.area.Region; -import org.apollo.game.model.area.RegionCoordinates; import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.entity.EntityType; +import org.apollo.game.model.entity.EquipmentConstants; import org.apollo.game.model.entity.Player; -import org.apollo.game.sync.block.AppearanceBlock; -import org.apollo.game.sync.block.ChatBlock; -import org.apollo.game.sync.block.SynchronizationBlock; -import org.apollo.game.sync.block.SynchronizationBlockSet; -import org.apollo.game.sync.seg.AddPlayerSegment; -import org.apollo.game.sync.seg.MovementSegment; -import org.apollo.game.sync.seg.RemoveMobSegment; -import org.apollo.game.sync.seg.SynchronizationSegment; -import org.apollo.game.sync.seg.TeleportSegment; +import org.apollo.game.model.entity.PlayerUpdateInfo; +import org.apollo.game.model.entity.setting.Gender; +import org.apollo.game.model.inv.Inventory; +import org.apollo.game.sync.block.*; +import org.apollo.net.codec.game.DataOrder; +import org.apollo.net.codec.game.DataTransformation; +import org.apollo.net.codec.game.DataType; +import org.apollo.net.codec.game.GamePacketBuilder; +import org.apollo.net.meta.PacketType; +import org.apollo.util.BufferUtil; +import org.jetbrains.annotations.NotNull; + +import java.util.Set; + +import static org.apollo.game.model.entity.PlayerUpdateInfo.MAXIMUM_LOCAL_PLAYERS; /** * A {@link SynchronizationTask} which synchronizes the specified {@link Player} . * - * @author Graham + * @author Kris + * @author Dragonkk + * @author Cjay0091 */ public final class PlayerSynchronizationTask extends SynchronizationTask { + private static final int[][] PACKED_LOCATION_UPDATE2 = new int[][]{{0, 3, 5}, {1, -1, 6}, {2, 4, 7}}; + + private final Player player; + private final PlayerUpdateInfo info; + private final World world; + private final Set limitedPlayers; + + public PlayerSynchronizationTask(Player player) { + this.player = player; + this.info = player.getUpdateInfo(); + this.world = player.getWorld(); + + this.limitedPlayers = player.getLocalPlayerList(); + } + + @Override + public void run() { + info.buffer = new GamePacketBuilder(79, PacketType.VARIABLE_SHORT); + info.largeMaskBuffer = new GamePacketBuilder(); + limitedPlayers.clear(); + prefetch(); + processLocalPlayers(true); + processLocalPlayers(false); + processOutsidePlayers(true); + processOutsidePlayers(false); + info.buffer.putBytes(info.largeMaskBuffer); + info.localIndexesCount = 0; + info.externalIndexesCount = 0; + for (var playerIndex = 1; playerIndex < 2048; playerIndex++) { + info.activityFlags[playerIndex] >>= 1; + if (info.localPlayers[playerIndex] == null) { + info.externalIndexes[info.externalIndexesCount++] = playerIndex; + } else { + info.localIndexes[info.localIndexesCount++] = playerIndex; + } + } + player.send(new PlayerSynchronizationMessage(info.buffer)); + } + /** - * The maximum amount of local players. + * Prefetches a list of players closest to us when there are more than 255 players in the viewport. + * TODO: Convert the LocationMap to function at the chunk level. No reason to separate them. */ - private static final int MAXIMUM_LOCAL_PLAYERS = 255; + private void prefetch() { + limitedPlayers.clear(); + + // Process which players need to be added. + final var position = player.getPosition(); + RegionRepository repository = world.getRegionRepository(); + Region current = repository.fromPosition(position); + + final var regions = current.getSurrounding(); + regions.add(current.getCoordinates()); + + regions.stream().map(repository::get).forEach(region -> { + var players = region.getEntities(EntityType.PLAYER); + var iterator = players.iterator(); + while (iterator.hasNext()) { + if (limitedPlayers.size() >= MAXIMUM_LOCAL_PLAYERS) { + player.flagExcessivePlayers(); + break; + } + + Player other = iterator.next(); + Position local = other.getPosition(); + + if (player != other && other.isActive() && local + .isWithinDistance(position, player.getViewingDistance())) { + limitedPlayers.add(other); + } + } + }); + } /** - * The maximum number of players to load per cycle. This prevents the update packet from becoming too large (the - * client uses a 5000 byte buffer) and also stops old spec PCs from crashing when they login or teleport. + * @param p the player being removed. + * @param playerIndex the index of the player being removed. If the player needs to be removed and the index + * isn't -1, we also putBits the necessary information in the buffer. + * @return whether or not the requested player needs to be removed from the local players list. */ - private static final int NEW_PLAYERS_PER_CYCLE = 20; + private boolean remove(@NotNull final Player p, final int playerIndex) { + if (p == player) { + return false; + } + if (!limitedPlayers.contains(p)) { + if (playerIndex != -1) { + info.buffer.putBits(1, 1); + info.buffer.putBits(1, 0); + info.buffer.putBits(2, 0); + final var hash = p.getPosition().get18BitHash(); + final var previousHash = p.getOldPosition().get18BitHash(); + if (hash == previousHash) { + info.buffer.putBits(1, 0); + } else { + info.buffer.putBits(1, 1); + updatePositionMultiplier(previousHash, hash); + } + info.localPlayers[playerIndex] = null; + } + return true; + } + return false; + } /** - * The Player. + * @param p the player being added. + * @param playerIndex the index of the player being added. If the player needs to be added and the index isn't + * -1, we also putBits the necessary information in the buffer. + * @return whether or not the requested player needs to be added to the local players list. */ - private final Player player; + private boolean add(final Player p, final int playerIndex) { + if (limitedPlayers.contains(p)) { + if (playerIndex != -1) { + info.buffer.putBits(1, 1); + info.buffer.putBits(2, 0); + final var hash = p.getPosition().get18BitHash(); + final var previousHash = p.getOldPosition().get18BitHash(); + if (hash == previousHash) { + info.buffer.putBits(1, 0); + } else { + info.buffer.putBits(1, 1); + updatePositionMultiplier(previousHash, hash); + } + info.buffer.putBits(13, p.getPosition().getX()); + info.buffer.putBits(13, p.getPosition().getY()); + + final var blockSet = getBlockSet(p); + final var updateMasks = blockSet.size() > 0; + info.buffer.putBits(1, updateMasks ? 1 : 0); + if (updateMasks) { + appendUpdateBlock(p, blockSet, true); + } + info.localPlayers[p.getIndex()] = p; + info.activityFlags[playerIndex] = (byte) (info.activityFlags[playerIndex] | 0x2); + } + return true; + } + return false; + } /** - * Creates the {@link PlayerSynchronizationTask} for the specified {@link Player}. + * Appends the position changes of the requested player. As of right now, the last if-block is never reached as + * the offsets can never exceed value 1. * - * @param player The Player. + * @param lastPosition the last position multiplier transmitted to the client. + * @param currentPosition the current position multiplier. */ - public PlayerSynchronizationTask(Player player) { - this.player = player; + private void updatePositionMultiplier(final int lastPosition, final int currentPosition) { + final var lastY = lastPosition & 0xFF; + final var lastX = lastPosition >> 8 & 0xFF; + final var lastPlane = lastPosition >> 16; + + final var currentY = currentPosition & 0xFF; + final var currentX = currentPosition >> 8 & 0xFF; + final var currentPlane = currentPosition >> 16; + + final var yOffset = currentY - lastY; + final var xOffset = currentX - lastX; + final var planeOffset = (currentPlane - lastPlane) & 0x3; + + if (currentX == lastX && currentY == lastY) { + info.buffer.putBits(2, 1); + info.buffer.putBits(2, planeOffset); + } else if (Math.abs(xOffset) <= 1 && Math.abs(yOffset) <= 1) { + info.buffer.putBits(2, 2); + info.buffer.putBits(2, planeOffset); + info.buffer.putBits(3, + PACKED_LOCATION_UPDATE2[xOffset + 1][yOffset + 1]);// Utils.getMoveDirection(xOffset, yOffset)); + } else { + info.buffer.putBits(2, 3); + info.buffer.putBits(2, planeOffset); + info.buffer.putBits(8, xOffset & 0xFF); + info.buffer.putBits(8, yOffset & 0xFF); + } } - @Override - public void run() { - Position lastKnownRegion = player.getLastKnownRegion(); - boolean regionChanged = player.hasRegionChanged(); - int[] appearanceTickets = player.getAppearanceTickets(); + /** + * Processes the players outside of our viewport; either adds, updates or skips them if necessary to do so. + * + * @param inactivePlayers whether or not we loop the inactive or active players. + */ + private void processOutsidePlayers(final boolean inactivePlayers) { + info.buffer.switchToBitAccess(); + + var skip = 0; + for (var i = 0; i < info.externalIndexesCount; i++) { + final var playerIndex = info.externalIndexes[i]; + if (inactivePlayers == ((0x1 & info.activityFlags[playerIndex]) == 0)) { + continue; + } + if (skip > 0) { + skip--; + info.activityFlags[playerIndex] = (byte) (info.activityFlags[playerIndex] | 0x2); + continue; + } + final var p = world.getPlayerRepository().get(playerIndex); + if (!add(p, playerIndex)) { + final var hash = p == null ? 0 : p.getPosition().get18BitHash(); + final var previousHash = p == null ? 0 : p.getOldPosition().get18BitHash(); + if (hash != previousHash) { + info.buffer.putBits(1, 1); + updatePositionMultiplier(previousHash, hash); + } else { + info.buffer.putBits(1, 0); + skip(skip += getSkippedExternalPlayers(i, inactivePlayers)); + info.activityFlags[playerIndex] = (byte) (info.activityFlags[playerIndex] | 0x2); + } + } + } + info.buffer.switchToByteAccess(); - SynchronizationBlockSet blockSet = player.getBlockSet(); + if (skip != 0) { + throw new IllegalStateException(inactivePlayers ? "NSN2" : "NSN3"); + } + } - if (blockSet.contains(ChatBlock.class)) { - blockSet = blockSet.clone(); - blockSet.remove(ChatBlock.class); + /** + * @param index the current index in the loop. + * @param inactivePlayers whether we check inactive or active players. + * @return the amount of external players we can skip. + */ + private int getSkippedExternalPlayers(final int index, final boolean inactivePlayers) { + int skip = 0; + for (var i = index + 1; i < info.externalIndexesCount; i++) { + final var externalIndex = info.externalIndexes[i]; + if (inactivePlayers == ((0x1 & info.activityFlags[externalIndex]) == 0)) { + continue; + } + final var externalPlayer = world.getPlayerRepository().get(externalIndex); + final var externalHash = externalPlayer == null ? 0 : externalPlayer.getPosition().get18BitHash(); + final var previousExternalHash = externalPlayer == null ? 0 : externalPlayer.getOldPosition() + .get18BitHash(); + if (add(externalPlayer, -1) || externalHash != previousExternalHash) { + break; + } + skip++; } + return skip; + } - Position position = player.getPosition(); + /** + * Processes the players inside of our viewport; either removes, updates or skips them if necessary to do so. + * + * @param inactivePlayers whether or not we loop the inactive or active players. + */ + private void processLocalPlayers(final boolean inactivePlayers) { + info.buffer.switchToBitAccess(); + + var skip = 0; + for (var i = 0; i < info.localIndexesCount; i++) { + final var playerIndex = info.localIndexes[i]; + if (inactivePlayers == ((0x1 & info.activityFlags[playerIndex]) != 0)) { + continue; + } + if (skip > 0) { + skip--; + info.activityFlags[playerIndex] = (byte) (info.activityFlags[playerIndex] | 0x2); + continue; + } + final var p = info.localPlayers[playerIndex]; + + if (!remove(p, playerIndex)) { + final var directions = p.getDirections(); + final var blockSet = getBlockSet(p); + var update = blockSet.size() > 0; + if (update) { + appendUpdateBlock(p, blockSet, false); + } - SynchronizationSegment segment = (player.isTeleporting() || player.hasRegionChanged()) ? - new TeleportSegment(blockSet, position) : new MovementSegment(blockSet, player.getDirections()); + final var teleported = p.isTeleporting(); + if (teleported || directions.length > 0) { + info.buffer.putBits(1, 1); + info.buffer.putBits(1, update ? 1 : 0); + info.buffer.putBits(2, 3); + final var location = p.getPosition(); + final var lastLocation = p.getOldPosition(); + final var xOffset = location.getX() - lastLocation.getX(); + final var yOffset = location.getY() - lastLocation.getY(); + final var planeOffset = location.getHeight() - lastLocation.getHeight(); + if (Math.abs(xOffset) < 16 && Math.abs(yOffset) < 16) { + info.buffer.putBits(1, 0); + info.buffer.putBits(2, planeOffset & 0x3); + info.buffer.putBits(5, xOffset & 0x1F); + info.buffer.putBits(5, yOffset & 0x1F); + } else { + info.buffer.putBits(1, 1); + info.buffer.putBits(2, planeOffset & 0x3); + info.buffer.putBits(14, xOffset & 0x3FFF); + info.buffer.putBits(14, yOffset & 0x3FFF); + } + } else if (update) { + info.buffer.putBits(1, 1); + info.buffer.putBits(1, 1); + info.buffer.putBits(2, 0); + } else { + info.buffer.putBits(1, 0); + skip(skip += getSkippedLocalPlayers(i, inactivePlayers)); + info.activityFlags[playerIndex] = (byte) (info.activityFlags[playerIndex] | 0x2); + } + } + } + info.buffer.switchToByteAccess(); - List localPlayers = player.getLocalPlayerList(); - int oldCount = localPlayers.size(); + if (skip != 0) { + throw new IllegalStateException(inactivePlayers ? "NSN0" : "NSN1"); + } + } - List segments = new ArrayList<>(); - int distance = player.getViewingDistance(); + /** + * @param index the current index in the loop. + * @param inactivePlayers whether we check inactive or active players. + * @return the amount of local players we can skip. + */ + private int getSkippedLocalPlayers(final int index, final boolean inactivePlayers) { + int skip = 0; + for (var i = index + 1; i < info.localIndexesCount; i++) { + final var localIndex = info.localIndexes[i]; + if (inactivePlayers == ((0x1 & info.activityFlags[localIndex]) != 0)) { + continue; + } - for (Iterator iterator = localPlayers.iterator(); iterator.hasNext(); ) { - Player other = iterator.next(); + final var p = info.localPlayers[localIndex]; + if (remove(p, -1)) { + break; + } - if (removeable(position, distance, other)) { - iterator.remove(); - segments.add(new RemoveMobSegment()); - } else { - segments.add(new MovementSegment(other.getBlockSet(), other.getDirections())); + final var directions = p.getDirections(); + if (directions.length > 0) { + break; + } + + final var blockSet = getBlockSet(p); + if (blockSet.size() > 0) { + break; } + skip++; } + return skip; + } - int added = 0, count = localPlayers.size(); + /** + * Write the amount of players skipped into the buffer. + * + * @param count the amount of players skipped. + */ + private void skip(final int count) { + if (count == 0) { + info.buffer.putBits(2, 0); + } else if (count < 32) { + info.buffer.putBits(2, 1); + info.buffer.putBits(5, count); + } else if (count < 256) { + info.buffer.putBits(2, 2); + info.buffer.putBits(8, count); + } else { + info.buffer.putBits(2, 3); + info.buffer.putBits(11, count); + } + } - RegionRepository repository = player.getWorld().getRegionRepository(); - Region current = repository.fromPosition(position); + /** + * Appends the update block into the small mask buffer, and then into the large mask buffer. + * + * @param p the player whose block is being written. + * @param blockSet + * @param added whether or not the player was added to the viewport during this cycle. + */ + private void appendUpdateBlock(final Player p, SynchronizationBlockSet blockSet, final boolean added) { + var flag = 0; - Set regions = current.getSurrounding(); - regions.add(current.getCoordinates()); + if (blockSet.contains(HitUpdateBlock.class)) { + flag |= 0x40; + } + if (blockSet.contains(GraphicBlock.class)) { + flag |= 0x200; + } + if (blockSet.contains(TemporaryMovementTypeBlock.class)) { + flag |= 0x1000; + } + if (blockSet.contains(ForceMovementBlock.class)) { + flag |= 0x400; + } + if (blockSet.contains(ForceChatBlock.class)) { + flag |= 0x20; + } + if (blockSet.contains(TurnToPositionBlock.class)) { + flag |= 0x4; + } + if (blockSet.contains(AppearanceBlock.class)) { + flag |= 0x1; + } + if (blockSet.contains(InteractingMobBlock.class)) { + flag |= 0x2; + } + if (blockSet.contains(MovementTypeBlock.class)) { + flag |= 0x800; + } + if (blockSet.contains(ChatBlock.class)) { + flag |= 0x10; + } + if (blockSet.contains(TitleBlock.class)) { + flag |= 0x100; + } + if (blockSet.contains(AnimationBlock.class)) { + flag |= 0x80; + } - Stream players = regions.stream().map(repository::get) - .flatMap(region -> region.getEntities(EntityType.PLAYER)); + if (flag >= 0xFF) { + flag |= 0x8; + } - Iterator iterator = players.iterator(); + info.largeMaskBuffer.put(DataType.BYTE, flag); - while (iterator.hasNext()) { - if (count >= MAXIMUM_LOCAL_PLAYERS) { - player.flagExcessivePlayers(); - break; - } else if (added >= NEW_PLAYERS_PER_CYCLE) { - break; + if (flag >= 0xFF) { + info.largeMaskBuffer.put(DataType.BYTE, flag >> 8); + } + + if (blockSet.contains(HitUpdateBlock.class)) { + putHitUpdateBlock(blockSet.get(HitUpdateBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(GraphicBlock.class)) { + putGraphicBlock(blockSet.get(GraphicBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(TemporaryMovementTypeBlock.class)) { + putTemporaryMovementTypeBlock(blockSet.get(TemporaryMovementTypeBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(ForceMovementBlock.class)) { + putForceMovementBlock(blockSet.get(ForceMovementBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(ForceChatBlock.class)) { + putForceChatBlock(blockSet.get(ForceChatBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(TurnToPositionBlock.class)) { + putTurnToPositionBlock(blockSet.get(TurnToPositionBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(AppearanceBlock.class)) { + putAppearanceBlock(blockSet.get(AppearanceBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(InteractingMobBlock.class)) { + putInteractingMobBlock(blockSet.get(InteractingMobBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(MovementTypeBlock.class)) { + putMovementTypeBlock(blockSet.get(MovementTypeBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(ChatBlock.class)) { + putChatBlock(blockSet.get(ChatBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(TitleBlock.class)) { + putTitleBlock(blockSet.get(TitleBlock.class), info.largeMaskBuffer); + } + if (blockSet.contains(AnimationBlock.class)) { + putAnimationBlock(blockSet.get(AnimationBlock.class), info.largeMaskBuffer); + } + } + + /** + * Puts an Appearance block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) { + Appearance appearance = block.getAppearance(); + ByteBuf playerProperties = Unpooled.buffer(); + + playerProperties.writeByte(appearance.getGender().toInteger()); + playerProperties.writeByte(block.isSkulled() ? 1 : -1); + playerProperties.writeByte(block.getHeadIcon()); + + if (block.appearingAsNpc()) { + playerProperties.writeShort(0xFFFF); + playerProperties.writeShort(block.getNpcId()); + } else { + Inventory equipment = block.getEquipment(); + int[] style = appearance.getStyle(); + Item item, chest, helm; + + for (int slot = 0; slot < 4; slot++) { + if ((item = equipment.get(slot)) != null) { + playerProperties.writeShort(0x200 + item.getId()); + } else { + playerProperties.writeByte(0); + } } - Player other = iterator.next(); - Position local = other.getPosition(); + if ((chest = equipment.get(EquipmentConstants.CHEST)) != null) { + playerProperties.writeShort(0x200 + chest.getId()); + } else { + playerProperties.writeShort(0x100 + style[2]); + } - if (other != player && local.isWithinDistance(position, distance) && !localPlayers.contains(other)) { - localPlayers.add(other); - count++; - added++; + if ((item = equipment.get(EquipmentConstants.SHIELD)) != null) { + playerProperties.writeShort(0x200 + item.getId()); + } else { + playerProperties.writeByte(0); + } - blockSet = other.getBlockSet(); + if (chest != null) { + EquipmentDefinition def = EquipmentDefinition.lookup(chest.getId()); + if (def != null && !def.isFullBody()) { + playerProperties.writeShort(0x100 + style[3]); + } else { + playerProperties.writeByte(0); + } + } else { + playerProperties.writeShort(0x100 + style[3]); + } - int index = other.getIndex(); + if ((item = equipment.get(EquipmentConstants.LEGS)) != null) { + playerProperties.writeShort(0x200 + item.getId()); + } else { + playerProperties.writeShort(0x100 + style[5]); + } - if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(appearanceTickets, index - 1, other.getAppearanceTicket())) { - blockSet = blockSet.clone(); - blockSet.add(SynchronizationBlock.createAppearanceBlock(other)); + if ((helm = equipment.get(EquipmentConstants.HAT)) != null) { + EquipmentDefinition def = EquipmentDefinition.lookup(helm.getId()); + if (def != null && !def.isFullHat() && !def.isFullMask()) { + playerProperties.writeShort(0x100 + style[0]); + } else { + playerProperties.writeByte(0); } + } else { + playerProperties.writeShort(0x100 + style[0]); + } + + if ((item = equipment.get(EquipmentConstants.HANDS)) != null) { + playerProperties.writeShort(0x200 + item.getId()); + } else { + playerProperties.writeShort(0x100 + style[4]); + } - segments.add(new AddPlayerSegment(blockSet, index, local)); + if ((item = equipment.get(EquipmentConstants.FEET)) != null) { + playerProperties.writeShort(0x200 + item.getId()); + } else { + playerProperties.writeShort(0x100 + style[6]); + } + + EquipmentDefinition def = null; + if (helm != null) { + def = EquipmentDefinition.lookup(helm.getId()); + } + if (def != null && (def.isFullMask()) || appearance.getGender() == Gender.FEMALE) { + playerProperties.writeByte(0); + } else { + playerProperties.writeShort(0x100 + style[1]); } } - PlayerSynchronizationMessage message = new PlayerSynchronizationMessage(lastKnownRegion, position, - regionChanged, segment, oldCount, segments); - player.send(message); + int[] colors = appearance.getColors(); + for (int color : colors) { + playerProperties.writeByte(color); + } + + playerProperties.writeShort(0x328); // stand + playerProperties.writeShort(0x337); // stand turn + playerProperties.writeShort(0x333); // walk + playerProperties.writeShort(0x334); // turn 180 + playerProperties.writeShort(0x335); // turn 90 cw + playerProperties.writeShort(0x336); // turn 90 ccw + playerProperties.writeShort(0x338); // run + + BufferUtil.writeString(playerProperties, block.getName()); + playerProperties.writeByte(block.getCombatLevel()); + playerProperties.writeShort(0);//block.getSkillLevel()); + playerProperties.writeByte(0); + + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, playerProperties.writableBytes()); + for (int index = 0; index < playerProperties.writableBytes(); index++) { + builder.put(DataType.BYTE, DataTransformation.ADD, playerProperties.getByte(index)); + } + } + + /** + * Puts a chat block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putChatBlock(ChatBlock block, GamePacketBuilder builder) { + byte[] bytes = block.getCompressedMessage(); + + builder.put(DataType.SHORT, DataTransformation.ADD, block.getTextEffects() << 8 | block.getTextColor()); + builder.put(DataType.BYTE, block.getPrivilegeLevel().toInteger()); + builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getType().ordinal()); + builder.putSmart(bytes.length); + builder.putBytes(bytes); + } + + /** + * Puts a force chat block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) { + builder.putString(block.getMessage()); + } + + /** + * Puts a title block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putTitleBlock(TitleBlock block, GamePacketBuilder builder) { + var titles = block.getTitles(); + for (var positions : TitleBlock.TitlePosition.values()) { + builder.putString(titles.getOrDefault(positions, "")); + } + } + + /** + * Puts a force movement block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putForceMovementBlock(ForceMovementBlock block, GamePacketBuilder builder) { + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getInitialX()); + builder.put(DataType.BYTE, DataTransformation.ADD, block.getInitialY()); + builder.put(DataType.BYTE, DataTransformation.ADD, block.getFinalX()); + builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getFinalY()); + builder.put(DataType.SHORT, DataTransformation.ADD, block.getTravelDurationX()); + builder.put(DataType.SHORT, DataOrder.LITTLE, block.getTravelDurationY()); + builder.put(DataType.SHORT, block.getDirection().toInteger()); + } + + /** + * Puts a movement type block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putMovementTypeBlock(MovementTypeBlock block, GamePacketBuilder builder) { + builder.put(DataType.BYTE, DataTransformation.ADD, block.getMode().getClientValue()); + } + + /** + * Puts a temporary movement type block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putTemporaryMovementTypeBlock(TemporaryMovementTypeBlock block, GamePacketBuilder builder) { + builder.put(DataType.BYTE, DataTransformation.ADD, block.getMode().getClientValue()); + } + + /** + * Puts a graphic block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) { + Graphic graphic = block.getGraphic(); + builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, graphic.getId()); + builder.put(DataType.INT, DataOrder.MIDDLE, + graphic.getHeight() << 16 & 0xFFFF0000 | graphic.getDelay() & 0x0000FFFF); + } + + /** + * Puts a hit update block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) { + + } + + /** + * Puts an interacting mob block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) { + builder.put(DataType.SHORT, DataTransformation.ADD, block.getIndex()); + } + + /** + * Puts a turn to position block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { + var direction = Direction.between(block.getMobPosition(), block.getTurnPosition()); + builder.put(DataType.SHORT, DataOrder.LITTLE, direction.getClientValue()); + } + + /** + * Puts an Animation block into the specified builder. + * + * @param block The block. + * @param builder The builder. + */ + private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) { + Animation animation = block.getAnimation(); + builder.put(DataType.SHORT, animation.getId()); + builder.put(DataType.BYTE, animation.getDelay()); + } + + private SynchronizationBlockSet getBlockSet(Player p) { + var blockSet = p.getBlockSet(); + if (!blockSet.contains(AppearanceBlock.class) && !hasCachedAppearance(player.getAppearanceTickets(), + p.getIndex() - 1, p.getAppearanceTicket())) { + blockSet = blockSet.clone(); + blockSet.add(SynchronizationBlock.createAppearanceBlock(p)); + } + return blockSet; } /** * Tests whether or not the specified Player has a cached appearance within * the specified appearance ticket array. - * + * * @param appearanceTickets The appearance tickets. - * @param index The index of the Player. - * @param appearanceTicket The current appearance ticket for the Player. + * @param index The index of the Player. + * @param appearanceTicket The current appearance ticket for the Player. * @return {@code true} if the specified Player has a cached appearance - * otherwise {@code false}. + * otherwise {@code false}. */ private boolean hasCachedAppearance(int[] appearanceTickets, int index, int appearanceTicket) { if (appearanceTickets[index] != appearanceTicket) { appearanceTickets[index] = appearanceTicket; return false; } - return true; } - - /** - * Returns whether or not the specified {@link Player} should be removed. - * - * @param position The {@link Position} of the Player being updated. - * @param other The Player being tested. - * @return {@code true} iff the specified Player should be removed. - */ - private boolean removeable(Position position, int distance, Player other) { - if (other.isTeleporting() || !other.isActive()) { - return true; - } - - Position otherPosition = other.getPosition(); - return otherPosition.getLongestDelta(position) > distance || !otherPosition.isWithinDistance(position, distance); - } - } \ No newline at end of file diff --git a/game/src/main/java/org/apollo/game/sync/task/PostNpcSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PostNpcSynchronizationTask.java index 311c483a1..dd0f4ef97 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PostNpcSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PostNpcSynchronizationTask.java @@ -25,7 +25,7 @@ public PostNpcSynchronizationTask(Npc npc) { @Override public void run() { - npc.setTeleporting(false); + npc.resetTeleportPosition(); npc.resetBlockSet(); } diff --git a/game/src/main/java/org/apollo/game/sync/task/PostPlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PostPlayerSynchronizationTask.java index baa4ecb35..c80239af4 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PostPlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PostPlayerSynchronizationTask.java @@ -25,7 +25,7 @@ public PostPlayerSynchronizationTask(Player player) { @Override public void run() { - player.setTeleporting(false); + player.resetTeleportPosition(); player.setRegionChanged(false); player.resetBlockSet(); diff --git a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java index 33d1c7af7..8570612c8 100644 --- a/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java +++ b/game/src/main/java/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java @@ -1,19 +1,19 @@ package org.apollo.game.sync.task; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -import org.apollo.game.message.impl.ClearRegionMessage; -import org.apollo.game.message.impl.GroupedRegionUpdateMessage; -import org.apollo.game.message.impl.RegionChangeMessage; -import org.apollo.game.message.impl.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.UpdateZoneFullFollowsMessage; +import org.apollo.game.message.impl.encode.UpdateZonePartialEnclosedMessage; +import org.apollo.game.message.impl.encode.RegionUpdateMessage; +import org.apollo.game.message.impl.encode.RebuildNormalMessage; import org.apollo.game.model.Position; import org.apollo.game.model.area.Region; import org.apollo.game.model.area.RegionCoordinates; import org.apollo.game.model.area.RegionRepository; import org.apollo.game.model.entity.Player; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + /** * A {@link SynchronizationTask} which does pre-synchronization work for the specified {@link Player}. * @@ -42,12 +42,12 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask { /** * Creates the {@link PrePlayerSynchronizationTask} for the specified {@link Player}. * - * @param player The Player. + * @param player The Player. * @param encodes The Map containing Region encodes. * @param updates The {@link Map} containing {@link Region} updates. */ public PrePlayerSynchronizationTask(Player player, Map> encodes, - Map> updates) { + Map> updates) { this.player = player; this.updates = updates; this.encodes = encodes; @@ -56,11 +56,15 @@ public PrePlayerSynchronizationTask(Player player, Map= Region.VIEWPORT_WIDTH - Position.MAX_DISTANCE - 1 - || deltaY <= Position.MAX_DISTANCE || deltaY >= Region.VIEWPORT_WIDTH - Position.MAX_DISTANCE - 1; + return deltaX <= Position.MAX_DISTANCE || deltaX >= Region.VIEWPORT_WIDTH - Position.MAX_DISTANCE - 1 || deltaY <= Position.MAX_DISTANCE || deltaY >= Region.VIEWPORT_WIDTH - Position.MAX_DISTANCE - 1; } /** * Sends the updates for a {@link Region} * - * @param position The {@link Position} of the last known region. + * @param position The {@link Position} of the last known region. * @param differences The {@link Set} of {@link RegionCoordinates} of Regions that changed. - * @param full The {@link Set} of {@link RegionCoordinates} of Regions that require a full update. + * @param full The {@link Set} of {@link RegionCoordinates} of Regions that require a full update. */ private void sendUpdates(Position position, Set differences, Set full) { RegionRepository repository = player.getWorld().getRegionRepository(); int height = position.getHeight(); for (RegionCoordinates coordinates : differences) { - Set messages = updates.computeIfAbsent(coordinates, - coords -> repository.get(coords).getUpdates(height)); + Set messages = updates + .computeIfAbsent(coordinates, coords -> repository.get(coords).getUpdates(height)); if (!messages.isEmpty()) { - player.send(new GroupedRegionUpdateMessage(position, coordinates, messages)); + player.send(new UpdateZonePartialEnclosedMessage(position, coordinates, messages)); } } for (RegionCoordinates coordinates : full) { - Set messages = encodes.computeIfAbsent(coordinates, - coords -> repository.get(coords).encode(height)); + Set messages = encodes + .computeIfAbsent(coordinates, coords -> repository.get(coords).encode(height)); if (!messages.isEmpty()) { - player.send(new ClearRegionMessage(position, coordinates)); - player.send(new GroupedRegionUpdateMessage(position, coordinates, messages)); + player.send(new UpdateZoneFullFollowsMessage(position, coordinates)); + player.send(new UpdateZonePartialEnclosedMessage(position, coordinates, messages)); } } } diff --git a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt index 37bdfdfca..e1b8cf6c6 100644 --- a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt +++ b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/KotlinPluginScript.kt @@ -2,7 +2,7 @@ package org.apollo.game.plugin.kotlin import org.apollo.game.command.CommandListener import org.apollo.game.message.handler.MessageHandler -import org.apollo.game.message.impl.ButtonMessage +import org.apollo.game.message.impl.decode.ButtonMessage import org.apollo.game.model.World import org.apollo.game.model.entity.setting.PrivilegeLevel import org.apollo.game.model.event.Event @@ -90,7 +90,7 @@ abstract class KotlinPluginScript(var world: World, val context: PluginContext) */ @Deprecated("Use new on(Type) listener") fun on_button(id: Int): KotlinPlayerHandlerProxyTrait { - return on { ButtonMessage::class }.where { widgetId == id } + return on { ButtonMessage::class }.where { componentId == id } } fun start(callback: (World) -> Unit) { diff --git a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/ButtonClick.kt b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt similarity index 54% rename from game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/ButtonClick.kt rename to game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt index 1b62dbf1f..2ec4bb687 100644 --- a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/ButtonClick.kt +++ b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/IfAction.kt @@ -1,7 +1,7 @@ package org.apollo.game.plugin.kotlin.message import org.apollo.game.message.handler.MessageHandler -import org.apollo.game.message.impl.ButtonMessage +import org.apollo.game.message.impl.decode.ButtonMessage import org.apollo.game.model.World import org.apollo.game.model.entity.Player import org.apollo.game.plugin.kotlin.KotlinPluginScript @@ -19,31 +19,36 @@ import org.apollo.game.plugin.kotlin.PredicateContext * ``` */ fun KotlinPluginScript.on( - listenable: ButtonClick.Companion, - button: Int, - callback: ButtonClick.() -> Unit + listenable: IfAction.Companion, + inter: Int, + comp: Int, + action: Int = 1, + callback: IfAction.() -> Unit ) { - registerListener(listenable, ButtonPredicateContext(button), callback) + registerListener(listenable, IfActionPredicateContext(inter, comp, action), callback) } -class ButtonClick(override val player: Player, val button: Int) : PlayerContext { +class IfAction(override val player: Player) : PlayerContext { - companion object : MessageListenable() { + companion object : MessageListenable() { override val type = ButtonMessage::class - + override fun createHandler( world: World, - predicateContext: ButtonPredicateContext?, - callback: ButtonClick.() -> Unit + predicateContext: IfActionPredicateContext?, + callback: IfAction.() -> Unit ): MessageHandler { return object : MessageHandler(world) { override fun handle(player: Player, message: ButtonMessage) { - if (predicateContext == null || predicateContext.button == message.widgetId) { - val context = ButtonClick(player, message.widgetId) - context.callback() + if (predicateContext == null || predicateContext.inter != message.interfaceId || + predicateContext.comp != message.componentId || predicateContext.action != message.option) { + return; } + + val context = IfAction(player) + context.callback() } } @@ -53,4 +58,4 @@ class ButtonClick(override val player: Player, val button: Int) : PlayerContext } -class ButtonPredicateContext(val button: Int) : PredicateContext \ No newline at end of file +class IfActionPredicateContext(val inter: Int, val comp: Int, val action: Int) : PredicateContext \ No newline at end of file diff --git a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/action/obj/ObjectAction.kt b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/action/obj/ObjectAction.kt index 2bb0b7902..69d11c83a 100644 --- a/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/action/obj/ObjectAction.kt +++ b/game/src/main/kotlin/org/apollo/game/plugin/kotlin/message/action/obj/ObjectAction.kt @@ -2,7 +2,7 @@ package org.apollo.game.plugin.kotlin.message.action.obj import org.apollo.cache.def.ObjectDefinition import org.apollo.game.message.handler.MessageHandler -import org.apollo.game.message.impl.ObjectActionMessage +import org.apollo.game.message.impl.decode.ObjectActionMessage import org.apollo.game.model.World import org.apollo.game.model.entity.EntityType import org.apollo.game.model.entity.Player diff --git a/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java index e332b0672..aa975a2e5 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ItemOnItemVerificationHandlerTests.java @@ -1,7 +1,7 @@ package org.apollo.game.message.handler; import org.apollo.cache.def.ItemDefinition; -import org.apollo.game.message.impl.ItemOnItemMessage; +import org.apollo.game.message.impl.decode.ItemOnItemMessage; import org.apollo.game.model.Item; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; @@ -39,8 +39,8 @@ public void terminateWithNoTargetItem() throws Exception { when(player.getInventory()).thenReturn(inventory); - ItemOnItemMessage itemOnItemMessage = new ItemOnItemMessage(BankConstants.SIDEBAR_INVENTORY_ID, 4151, 1, - BankConstants.SIDEBAR_INVENTORY_ID, 4152, 2); + ItemOnItemMessage itemOnItemMessage = new ItemOnItemMessage(BankConstants.INVENTORY_INTERFACE, BankConstants.INVENTORY_COMPONENT, 4151, 1, + BankConstants.INVENTORY_INTERFACE, BankConstants.INVENTORY_COMPONENT, 4152, 2); itemOnItemVerificationHandler.handle(player, itemOnItemMessage); diff --git a/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java index 8d0908c08..edb7ab7df 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ItemOnObjectVerificationHandlerTests.java @@ -2,7 +2,7 @@ import org.apollo.cache.def.ItemDefinition; import org.apollo.cache.def.ObjectDefinition; -import org.apollo.game.message.impl.ItemOnObjectMessage; +import org.apollo.game.message.impl.decode.ItemOnObjectMessage; import org.apollo.game.model.Item; import org.apollo.game.model.Position; import org.apollo.game.model.World; @@ -28,8 +28,7 @@ import static org.powermock.api.mockito.PowerMockito.*; @RunWith(PowerMockRunner.class) -@PrepareForTest({Player.class, World.class, Region.class, RegionRepository.class, ObjectDefinition.class, - ItemDefinition.class}) +@PrepareForTest({Player.class, World.class, Region.class, RegionRepository.class, ObjectDefinition.class, ItemDefinition.class}) public final class ItemOnObjectVerificationHandlerTests { @Before @@ -63,13 +62,15 @@ public void terminateIfInvalidItem() throws Exception { when(region.getEntities(objectPosition, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT)) .thenReturn(entitySet); - ItemOnObjectMessage itemOnObjectMessage = new ItemOnObjectMessage(SynchronizationInventoryListener.INVENTORY_ID, 4151, 1, - 1, objectPosition.getX(), objectPosition.getY()); + ItemOnObjectMessage itemOnObjectMessage = new ItemOnObjectMessage(SynchronizationInventoryListener.INVENTORY_ID, + SynchronizationInventoryListener.INVENTORY_CONTAINER_COMPONENT, 4151, 1, 1, objectPosition.getX(), + objectPosition.getY()); ItemOnObjectVerificationHandler itemOnObjectVerificationHandler = new ItemOnObjectVerificationHandler(world); itemOnObjectVerificationHandler.handle(player, itemOnObjectMessage); - assertTrue("ObjectVerificationHandler: message not terminated valid item given!", itemOnObjectMessage.terminated()); + assertTrue("ObjectVerificationHandler: message not terminated valid item given!", + itemOnObjectMessage.terminated()); } @Test @@ -93,13 +94,15 @@ public void terminateIfInvalidSlot() throws Exception { when(region.getEntities(objectPosition, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT)) .thenReturn(entitySet); - ItemOnObjectMessage itemOnObjectMessage = new ItemOnObjectMessage(SynchronizationInventoryListener.INVENTORY_ID, 4151, 30, - 1, objectPosition.getX(), objectPosition.getY()); + ItemOnObjectMessage itemOnObjectMessage = new ItemOnObjectMessage(SynchronizationInventoryListener.INVENTORY_ID, + SynchronizationInventoryListener.INVENTORY_CONTAINER_COMPONENT, 4151, 30, 1, objectPosition.getX(), + objectPosition.getY()); ItemOnObjectVerificationHandler itemOnObjectVerificationHandler = new ItemOnObjectVerificationHandler(world); itemOnObjectVerificationHandler.handle(player, itemOnObjectMessage); - assertTrue("ObjectVerificationHandler: message not terminated when no valid slot given!", itemOnObjectMessage.terminated()); + assertTrue("ObjectVerificationHandler: message not terminated when no valid slot given!", + itemOnObjectMessage.terminated()); } @Test @@ -124,12 +127,14 @@ public void terminateIfObjectOutOfRange() throws Exception { when(region.getEntities(objectPosition, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT)) .thenReturn(entitySet); - ItemOnObjectMessage itemOnObjectMessage = new ItemOnObjectMessage(SynchronizationInventoryListener.INVENTORY_ID, 4151, 1, - 1, objectPosition.getX(), objectPosition.getY()); + ItemOnObjectMessage itemOnObjectMessage = new ItemOnObjectMessage(SynchronizationInventoryListener.INVENTORY_ID, + SynchronizationInventoryListener.INVENTORY_CONTAINER_COMPONENT, 4151, 1, 1, objectPosition.getX(), + objectPosition.getY()); ItemOnObjectVerificationHandler itemOnObjectVerificationHandler = new ItemOnObjectVerificationHandler(world); itemOnObjectVerificationHandler.handle(player, itemOnObjectMessage); - assertTrue("ObjectVerificationHandler: message not terminated when object out of range!", itemOnObjectMessage.terminated()); + assertTrue("ObjectVerificationHandler: message not terminated when object out of range!", + itemOnObjectMessage.terminated()); } } \ No newline at end of file diff --git a/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java index c4c396f67..52bab2e3f 100644 --- a/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/ObjectActionVerificationHandlerTests.java @@ -2,7 +2,7 @@ import org.apollo.cache.def.ItemDefinition; import org.apollo.cache.def.ObjectDefinition; -import org.apollo.game.message.impl.ObjectActionMessage; +import org.apollo.game.message.impl.decode.ObjectActionMessage; import org.apollo.game.model.Position; import org.apollo.game.model.World; import org.apollo.game.model.area.Region; @@ -12,7 +12,6 @@ import org.apollo.game.model.entity.Player; import org.apollo.game.model.entity.obj.StaticGameObject; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.core.classloader.annotations.PrepareForTest; @@ -55,7 +54,7 @@ public void terminateIfOutOfRange() throws Exception { when(region.getEntities(objectPosition, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT)) .thenReturn(entitySet); - ObjectActionMessage objectActionMessage = new ObjectActionMessage(1, 4151, objectPosition); + ObjectActionMessage objectActionMessage = new ObjectActionMessage(1, 4151, objectPosition, 0); ObjectActionVerificationHandler objectActionVerificationHandler = new ObjectActionVerificationHandler(world); objectActionVerificationHandler.handle(player, objectActionMessage); @@ -81,7 +80,7 @@ public void terminateIfNoObject() throws Exception { when(region.getEntities(objectPosition, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT)) .thenReturn(entitySet); - ObjectActionMessage objectActionMessage = new ObjectActionMessage(1, 4151, objectPosition); + ObjectActionMessage objectActionMessage = new ObjectActionMessage(1, 4151, objectPosition, 0); ObjectActionVerificationHandler objectActionVerificationHandler = new ObjectActionVerificationHandler(world); objectActionVerificationHandler.handle(player, objectActionMessage); diff --git a/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java b/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java index 18f80ccfa..161dc7356 100644 --- a/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java +++ b/game/src/test/java/org/apollo/game/message/handler/PublicChatMessageHandlerTests.java @@ -1,6 +1,6 @@ package org.apollo.game.message.handler; -import org.apollo.game.message.impl.PublicChatMessage; +import org.apollo.game.message.impl.decode.PublicChatMessage; import org.apollo.game.model.World; import org.apollo.game.model.entity.Player; import org.junit.Test; @@ -26,7 +26,8 @@ public void terminateIfMuted() throws Exception { when(player.isMuted()).thenReturn(true); - PublicChatMessage publicChatMessage = new PublicChatMessage("Test", "Test".getBytes(), 0, 0); + PublicChatMessage publicChatMessage = new PublicChatMessage("Test", "Test".getBytes(), + 0, 0, PublicChatMessage.PublicChatType.NONE); handler.handle(player, publicChatMessage); assertTrue("PublicChatMessageHandler: player can send messages when muted", publicChatMessage.terminated()); diff --git a/game/src/test/java/org/apollo/game/model/entity/MobRepositoryTests.java b/game/src/test/java/org/apollo/game/model/entity/MobRepositoryTests.java index 0396789c5..8772ce659 100644 --- a/game/src/test/java/org/apollo/game/model/entity/MobRepositoryTests.java +++ b/game/src/test/java/org/apollo/game/model/entity/MobRepositoryTests.java @@ -16,7 +16,7 @@ /** * Tests the {@link MobRepository} class. - * + * * @author Ryley */ @RunWith(PowerMockRunner.class) diff --git a/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java b/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java index 51dd4d60c..a7ee6e2da 100644 --- a/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java +++ b/game/src/test/java/org/apollo/game/model/entity/WalkingQueueTests.java @@ -34,7 +34,7 @@ private World createFakeWorld(boolean traversable) { } private Player createFakePlayer(World world) { - PlayerCredentials credentials = new PlayerCredentials("test", "test", -1, -1, "0.0.0.0"); + PlayerCredentials credentials = new PlayerCredentials("test", "test", -1, null, "0.0.0.0"); Player player = new Player(world, credentials, START_POSITION); Region region = world.getRegionRepository().fromPosition(START_POSITION); diff --git a/gradle/properties.gradle b/gradle/properties.gradle index 63d32988d..8b5a78be7 100644 --- a/gradle/properties.gradle +++ b/gradle/properties.gradle @@ -6,7 +6,7 @@ ext { bouncycastleVersion = '1.54' c3p0Version = '0.9.5.2' scryptVersion = '1.4.0' - nettyVersion = '4.0.34.Final' + nettyVersion = '4.1.45.Final' guavaVersion = '19.0' commonsCompressVersion = '1.10' assertjVersion = '3.8.0' diff --git a/net/src/main/java/org/apollo/net/NetworkConstants.java b/net/src/main/java/org/apollo/net/NetworkConstants.java index d91029f07..71e80e1a6 100644 --- a/net/src/main/java/org/apollo/net/NetworkConstants.java +++ b/net/src/main/java/org/apollo/net/NetworkConstants.java @@ -51,9 +51,14 @@ public final class NetworkConstants { public static final BigInteger RSA_MODULUS; /** - * The service port. + * The game port. */ - public static final int SERVICE_PORT; + public static final int GAME_PORT; + + /** + * The update port. + */ + public static final int UPDATE_PORT; static { try (InputStream is = new FileInputStream("data/net.xml")) { @@ -65,12 +70,13 @@ public final class NetworkConstants { XmlNode ports = net.getChild("ports"); Preconditions.checkState(ports != null, "Root node must have a child named 'ports'."); - XmlNode http = ports.getChild("http"), service = ports.getChild("service"), jaggrab = ports.getChild("jaggrab"); - Preconditions.checkState(http != null && service != null && jaggrab != null, "Ports node must have three children: 'http', 'service', and 'jaggrab'."); + XmlNode http = ports.getChild("http"), game = ports.getChild("game"), update = ports.getChild("update"), jaggrab = ports.getChild("jaggrab"); + Preconditions.checkState(http != null && game != null && update != null && jaggrab != null, "Ports node must have four children: 'http', 'game', 'update', and 'jaggrab'."); HTTP_PORT = Integer.parseInt(http.getValue()); - SERVICE_PORT = Integer.parseInt(service.getValue()); JAGGRAB_PORT = Integer.parseInt(jaggrab.getValue()); + GAME_PORT = Integer.parseInt(game.getValue()); + UPDATE_PORT = Integer.parseInt(update.getValue()); } catch (Exception exception) { throw new ExceptionInInitializerError(new IOException("Error parsing net.xml.", exception)); } diff --git a/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java b/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java index 206e79212..f66d242b2 100644 --- a/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java +++ b/net/src/main/java/org/apollo/net/codec/game/GamePacketBuilder.java @@ -279,6 +279,16 @@ public void putBytes(ByteBuf buffer) { putBytes(bytes); } + /** + * Puts the bytes from the specified buffer into this packet's buffer. + * + * @param buffer The source {@link ByteBuf}. + */ + public void putBytes(GamePacketBuilder buffer) { + putBytes(buffer.buffer); + } + + /** * Puts the bytes into the buffer with the specified transformation. * @@ -434,5 +444,4 @@ public GamePacket toGamePacket() { return new GamePacket(opcode, type, buffer); } - } \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/codec/game/GamePacketDecoder.java b/net/src/main/java/org/apollo/net/codec/game/GamePacketDecoder.java index 84a8fcbe5..000f06131 100644 --- a/net/src/main/java/org/apollo/net/codec/game/GamePacketDecoder.java +++ b/net/src/main/java/org/apollo/net/codec/game/GamePacketDecoder.java @@ -115,6 +115,7 @@ private void decodeOpcode(ByteBuf buffer, List out) { } break; case VARIABLE_BYTE: + case VARIABLE_SHORT: setState(GameDecoderState.GAME_LENGTH); break; default: diff --git a/net/src/main/java/org/apollo/net/codec/game/GamePacketReader.java b/net/src/main/java/org/apollo/net/codec/game/GamePacketReader.java index 0f8bae99b..4dab2488b 100644 --- a/net/src/main/java/org/apollo/net/codec/game/GamePacketReader.java +++ b/net/src/main/java/org/apollo/net/codec/game/GamePacketReader.java @@ -237,7 +237,7 @@ public void getBytesReverse(DataTransformation transformation, byte[] bytes) { */ public int getLength() { checkByteAccess(); - return buffer.writableBytes(); + return buffer.readableBytes(); } /** diff --git a/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java b/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java index aa768ae8c..f950c7e23 100644 --- a/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java +++ b/net/src/main/java/org/apollo/net/codec/handshake/HandshakeDecoder.java @@ -9,8 +9,9 @@ import org.apollo.net.codec.login.LoginDecoder; import org.apollo.net.codec.login.LoginEncoder; +import org.apollo.net.codec.update.OnDemandInfoEncoder; +import org.apollo.net.codec.update.OnDemandResponseEncoder; import org.apollo.net.codec.update.UpdateDecoder; -import org.apollo.net.codec.update.UpdateEncoder; /** * A {@link ByteToMessageDecoder} which decodes the handshake and makes changes to the pipeline as appropriate for the @@ -32,21 +33,15 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List ou } int id = buffer.readUnsignedByte(); - switch (id) { case HandshakeConstants.SERVICE_GAME: ctx.pipeline().addFirst("loginEncoder", new LoginEncoder()); ctx.pipeline().addAfter("handshakeDecoder", "loginDecoder", new LoginDecoder()); break; - case HandshakeConstants.SERVICE_UPDATE: - ctx.pipeline().addFirst("updateEncoder", new UpdateEncoder()); + ctx.pipeline().addFirst(new OnDemandInfoEncoder(), new OnDemandResponseEncoder()); //OnDemandInfoEncoder ctx.pipeline().addBefore("handler", "updateDecoder", new UpdateDecoder()); - - ByteBuf buf = ctx.alloc().buffer(8).writeLong(0); - ctx.channel().writeAndFlush(buf); break; - default: ByteBuf data = buffer.readBytes(buffer.readableBytes()); logger.info(String.format("Unexpected handshake request received: %d data: %s", id, data.toString())); diff --git a/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java b/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java index b59cc70ea..f5d83bdfa 100644 --- a/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java +++ b/net/src/main/java/org/apollo/net/codec/login/LoginDecoder.java @@ -1,25 +1,24 @@ package org.apollo.net.codec.login; +import com.google.common.net.InetAddresses; import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; - -import java.math.BigInteger; -import java.net.InetSocketAddress; -import java.security.SecureRandom; -import java.util.List; -import java.util.logging.Logger; - -import org.apollo.cache.FileSystemConstants; import org.apollo.net.NetworkConstants; import org.apollo.util.BufferUtil; import org.apollo.util.StatefulFrameDecoder; +import org.apollo.util.XteaUtil; import org.apollo.util.security.IsaacRandom; import org.apollo.util.security.IsaacRandomPair; import org.apollo.util.security.PlayerCredentials; +import org.apollo.util.security.UserStats; -import com.google.common.net.InetAddresses; +import java.math.BigInteger; +import java.net.InetSocketAddress; +import java.util.List; +import java.util.logging.Logger; /** * A {@link StatefulFrameDecoder} which decodes the login request frames. @@ -33,11 +32,6 @@ public final class LoginDecoder extends StatefulFrameDecoder */ private static final Logger logger = Logger.getLogger(LoginDecoder.class.getName()); - /** - * The secure random number generator. - */ - private static final SecureRandom RANDOM = new SecureRandom(); - /** * The login packet length. */ @@ -48,11 +42,6 @@ public final class LoginDecoder extends StatefulFrameDecoder */ private boolean reconnecting; - /** - * The server-side session key. - */ - private long serverSeed; - /** * The username hash. */ @@ -62,15 +51,12 @@ public final class LoginDecoder extends StatefulFrameDecoder * Creates the login decoder with the default initial state. */ public LoginDecoder() { - super(LoginDecoderState.LOGIN_HANDSHAKE); + super(LoginDecoderState.LOGIN_HEADER); } @Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out, LoginDecoderState state) { switch (state) { - case LOGIN_HANDSHAKE: - decodeHandshake(ctx, in, out); - break; case LOGIN_HEADER: decodeHeader(ctx, in, out); break; @@ -82,144 +68,152 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out, L } } - /** - * Decodes in the handshake state. - * - * @param ctx The channel handler context. - * @param buffer The buffer. - * @param out The {@link List} of objects to pass forward through the pipeline. - */ - private void decodeHandshake(ChannelHandlerContext ctx, ByteBuf buffer, List out) { - if (buffer.isReadable()) { - usernameHash = buffer.readUnsignedByte(); - serverSeed = RANDOM.nextLong(); - - ByteBuf response = ctx.alloc().buffer(17); - response.writeByte(LoginConstants.STATUS_EXCHANGE_DATA); - response.writeLong(0); - response.writeLong(serverSeed); - ctx.channel().write(response); - - setState(LoginDecoderState.LOGIN_HEADER); - } - } - /** * Decodes in the header state. * - * @param ctx The channel handler context. + * @param ctx The channel handler context. * @param buffer The buffer. - * @param out The {@link List} of objects to pass forward through the pipeline. + * @param out The {@link List} of objects to pass forward through the pipeline. */ private void decodeHeader(ChannelHandlerContext ctx, ByteBuf buffer, List out) { - if (buffer.readableBytes() >= 2) { - int type = buffer.readUnsignedByte(); - - if (type != LoginConstants.TYPE_STANDARD && type != LoginConstants.TYPE_RECONNECTION) { - logger.fine("Failed to decode login header."); - writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION); - return; - } + if (!buffer.isReadable(Byte.BYTES + Short.BYTES)) { + return; + } - reconnecting = type == LoginConstants.TYPE_RECONNECTION; - loginLength = buffer.readUnsignedByte(); + int type = buffer.readUnsignedByte(); - setState(LoginDecoderState.LOGIN_PAYLOAD); + if (type != LoginConstants.TYPE_STANDARD && type != LoginConstants.TYPE_RECONNECTION) { + logger.fine("Failed to decode login header."); + writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION); + return; } + + loginLength = buffer.readUnsignedShort(); + reconnecting = type == LoginConstants.TYPE_RECONNECTION; + + setState(LoginDecoderState.LOGIN_PAYLOAD); } /** * Decodes in the payload state. * - * @param ctx The channel handler context. + * @param ctx The channel handler context. * @param buffer The buffer. - * @param out The {@link List} of objects to pass forward through the pipeline. + * @param out The {@link List} of objects to pass forward through the pipeline. */ private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List out) { - if (buffer.readableBytes() >= loginLength) { - ByteBuf payload = buffer.readBytes(loginLength); - int version = 255 - payload.readUnsignedByte(); + if (!buffer.isReadable(loginLength)) { + return; + } - int release = payload.readUnsignedShort(); + final var payload = buffer.readBytes(loginLength); + final var release = payload.readUnsignedInt(); + final var version = payload.readUnsignedInt(); + final var clientType = payload.readUnsignedByte() & 0x3; // 0 desktop, 1 android, 2 ios + + var secure = payload.readBytes(payload.readUnsignedShort()); + final var rsa = new BigInteger( + ByteBufUtil.getBytes(secure, secure.readerIndex(), secure.readableBytes(), false)) + .modPow(NetworkConstants.RSA_EXPONENT, NetworkConstants.RSA_MODULUS); + secure = Unpooled.wrappedBuffer(rsa.toByteArray()); + + final var secureCheck = secure.readUnsignedByte(); + if (secureCheck != 1) { + logger.fine("Login secureCheck (" + secureCheck + ") is not expected value of 1."); + writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION); + return; + } - int memoryStatus = payload.readUnsignedByte(); - if (memoryStatus != 0 && memoryStatus != 1) { - logger.fine("Login memoryStatus (" + memoryStatus + ") not in expected range of [0, 1]."); - writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION); - return; - } + final var seed = new int[4]; + for (int index = 0; index < seed.length; index++) { + seed[index] = secure.readInt(); + } - boolean lowMemory = memoryStatus == 1; + final var serverSessionKey = secure.readLong(); - int[] crcs = new int[FileSystemConstants.ARCHIVE_COUNT]; - for (int index = 0; index < 9; index++) { - crcs[index] = payload.readInt(); - } + final short authType; + final int authCode; + final String password; + final var previousSeed = new int[4]; - int length = payload.readUnsignedByte(); - if (length != loginLength - 41) { - logger.fine("Login packet unexpected length (" + length + ")"); - writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION); - return; + if (reconnecting) { + for (int index = 0; index < previousSeed.length; index++) { + previousSeed[index] = secure.readInt(); } - ByteBuf secure = payload.readBytes(length); + authType = -1; + authCode = -1; + password = ""; + } else { + authType = secure.readUnsignedByte(); + if (authType == 1) { // Authenticator Related = 1 + authCode = secure.readInt(); + } else if (authType == 0 || authType == 2) {//Authenticator Related = 2, TrustedPC = 0 + authCode = secure.readUnsignedMedium(); + secure.skipBytes(Byte.BYTES); + } else { //Regular Login + authCode = secure.readInt(); + } - BigInteger value = new BigInteger(secure.array()); - value = value.modPow(NetworkConstants.RSA_EXPONENT, NetworkConstants.RSA_MODULUS); - secure = Unpooled.wrappedBuffer(value.toByteArray()); + secure.skipBytes(Byte.BYTES); + password = BufferUtil.readString(secure); + } - int id = secure.readUnsignedByte(); - if (id != 10) { - logger.fine("Unable to read id from secure payload."); - writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION); - return; - } + XteaUtil.decipher(payload, payload.readerIndex(), loginLength, seed); - long clientSeed = secure.readLong(); - long reportedSeed = secure.readLong(); - if (reportedSeed != serverSeed) { - logger.fine("Reported seed differed from server seed."); - writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION); - return; - } + final var username = BufferUtil.readString(payload); + if (password.length() < 4 || password.length() > 20 || username.isEmpty() || username.length() > 12) { + logger.fine("Username ('" + username + "') or password did not pass validation."); + writeResponseCode(ctx, LoginConstants.STATUS_INVALID_CREDENTIALS); + return; + } - int uid = secure.readInt(); - String username = BufferUtil.readString(secure); - String password = BufferUtil.readString(secure); - InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress(); - String hostAddress = InetAddresses.toAddrString(socketAddress.getAddress()); + final var clientProperties = payload.readUnsignedByte(); + final var lowMemory = (clientProperties & 0x1) == 1; + final var displayMode = clientProperties >> 1; + final var frameWidth = payload.readShort(); + final var frameHeight = payload.readShort(); - if (password.length() < 6 || password.length() > 20 || username.isEmpty() || username.length() > 12) { - logger.fine("Username ('" + username + "') or password did not pass validation."); - writeResponseCode(ctx, LoginConstants.STATUS_INVALID_CREDENTIALS); - return; - } + final var randFileContents = new byte[24]; + payload.readBytes(randFileContents); - int[] seed = new int[4]; - seed[0] = (int) (clientSeed >> 32); - seed[1] = (int) clientSeed; - seed[2] = (int) (serverSeed >> 32); - seed[3] = (int) serverSeed; + final var areaKey = BufferUtil.readString(payload); // TODO this is known. + payload.readInt(); // Affiliate - IsaacRandom decodingRandom = new IsaacRandom(seed); - for (int index = 0; index < seed.length; index++) { - seed[index] += 50; - } + final var stats = new UserStats(payload); + if (!stats.isValid()) { + logger.fine("User statistics version mismatched."); + writeResponseCode(ctx, LoginConstants.STATUS_GAME_UPDATED); + return; + } - IsaacRandom encodingRandom = new IsaacRandom(seed); + var test2 = payload.readUnsignedByte(); // The client type again? + var test = payload.readInt(); // This is always zero. - PlayerCredentials credentials = new PlayerCredentials(username, password, usernameHash, uid, hostAddress); - IsaacRandomPair randomPair = new IsaacRandomPair(encodingRandom, decodingRandom); + int[] crcs = new int[21]; + for (int index = 0; index < crcs.length; index++) { + crcs[index] = payload.readInt(); + } - out.add(new LoginRequest(credentials, randomPair, reconnecting, lowMemory, release, crcs, version)); + IsaacRandom decodingRandom = new IsaacRandom(seed); + for (int index = 0; index < seed.length; index++) { + seed[index] += 50; } + IsaacRandom encodingRandom = new IsaacRandom(seed); + + InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress(); + String hostAddress = InetAddresses.toAddrString(socketAddress.getAddress()); + + PlayerCredentials credentials = new PlayerCredentials(username, password, usernameHash, stats, hostAddress); + IsaacRandomPair randomPair = new IsaacRandomPair(encodingRandom, decodingRandom); + + out.add(new LoginRequest(credentials, randomPair, reconnecting, lowMemory, release, crcs, version, displayMode)); } /** * Writes a response code to the client and closes the current channel. * - * @param ctx The context of the channel handler. + * @param ctx The context of the channel handler. * @param response The response code to write. */ private void writeResponseCode(ChannelHandlerContext ctx, int response) { diff --git a/net/src/main/java/org/apollo/net/codec/login/LoginDecoderState.java b/net/src/main/java/org/apollo/net/codec/login/LoginDecoderState.java index bdef73457..5b5d82ab8 100644 --- a/net/src/main/java/org/apollo/net/codec/login/LoginDecoderState.java +++ b/net/src/main/java/org/apollo/net/codec/login/LoginDecoderState.java @@ -7,12 +7,6 @@ */ public enum LoginDecoderState { - /** - * The login handshake state will wait for the username hash to be received. Once it is, a server session key will - * be sent to the client and the state will be set to the login header state. - */ - LOGIN_HANDSHAKE, - /** * The login header state will wait for the login type and payload length to be received. These are saved, and then * the state will be set to the login payload state. diff --git a/net/src/main/java/org/apollo/net/codec/login/LoginEncoder.java b/net/src/main/java/org/apollo/net/codec/login/LoginEncoder.java index 466f11c51..0d5b0b94a 100644 --- a/net/src/main/java/org/apollo/net/codec/login/LoginEncoder.java +++ b/net/src/main/java/org/apollo/net/codec/login/LoginEncoder.java @@ -21,11 +21,7 @@ public LoginEncoder() { @Override protected void encode(ChannelHandlerContext ctx, LoginResponse response, ByteBuf out) { out.writeByte(response.getStatus()); - - if (response.getStatus() == LoginConstants.STATUS_OK) { - out.writeByte(response.getRights()); - out.writeByte(response.isFlagged() ? 1 : 0); - } + out.writeBytes(response.getPayload()); } } \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/codec/login/LoginRequest.java b/net/src/main/java/org/apollo/net/codec/login/LoginRequest.java index 356cf87c6..e729eb143 100644 --- a/net/src/main/java/org/apollo/net/codec/login/LoginRequest.java +++ b/net/src/main/java/org/apollo/net/codec/login/LoginRequest.java @@ -18,7 +18,8 @@ public final class LoginRequest { /** * The version denoting whether the client has been modified or not. */ - private final int clientVersion; + private final long clientVersion; + private final int displayMode; /** * The player's credentials. @@ -43,11 +44,10 @@ public final class LoginRequest { /** * The release number. */ - private final int releaseNumber; + private final long releaseNumber; /** * Creates a login request. - * * @param credentials The player credentials. * @param randomPair The pair of random number generators. * @param lowMemory The low memory flag. @@ -55,8 +55,10 @@ public final class LoginRequest { * @param releaseNumber The release number. * @param archiveCrcs The archive CRCs. * @param clientVersion The client version. + * @param displayMode */ - public LoginRequest(PlayerCredentials credentials, IsaacRandomPair randomPair, boolean lowMemory, boolean reconnecting, int releaseNumber, int[] archiveCrcs, int clientVersion) { + public LoginRequest(PlayerCredentials credentials, IsaacRandomPair randomPair, boolean lowMemory, boolean reconnecting, long releaseNumber, int[] archiveCrcs, long clientVersion, + int displayMode) { this.credentials = credentials; this.randomPair = randomPair; this.lowMemory = lowMemory; @@ -64,6 +66,7 @@ public LoginRequest(PlayerCredentials credentials, IsaacRandomPair randomPair, b this.releaseNumber = releaseNumber; this.archiveCrcs = archiveCrcs; this.clientVersion = clientVersion; + this.displayMode = displayMode; } /** @@ -80,7 +83,7 @@ public int[] getArchiveCrcs() { * * @return The client version. */ - public int getClientVersion() { + public long getClientVersion() { return clientVersion; } @@ -107,7 +110,7 @@ public IsaacRandomPair getRandomPair() { * * @return The release number. */ - public int getReleaseNumber() { + public long getReleaseNumber() { return releaseNumber; } @@ -129,4 +132,7 @@ public boolean isReconnecting() { return reconnecting; } + public int getDisplayMode() { + return displayMode; + } } \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/codec/login/LoginResponse.java b/net/src/main/java/org/apollo/net/codec/login/LoginResponse.java index bf1fa5b70..eccc6f29f 100644 --- a/net/src/main/java/org/apollo/net/codec/login/LoginResponse.java +++ b/net/src/main/java/org/apollo/net/codec/login/LoginResponse.java @@ -1,5 +1,8 @@ package org.apollo.net.codec.login; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; + /** * Represents a login response. * @@ -7,41 +10,28 @@ */ public final class LoginResponse { - /** - * The flagged flag. - */ - private final boolean flagged; - - /** - * The rights level. - */ - private final int rights; - /** * The login status. */ private final int status; + /** + * The payload. + */ + private ByteBuf payload; /** * Creates the login response. * * @param status The login status. - * @param rights The rights level. - * @param flagged The flagged flag. + * @param payload The rights payload. */ - public LoginResponse(int status, int rights, boolean flagged) { + public LoginResponse(int status, ByteBuf payload) { this.status = status; - this.rights = rights; - this.flagged = flagged; + this.payload = payload; } - /** - * Gets the rights level. - * - * @return The rights level. - */ - public int getRights() { - return rights; + public LoginResponse(int status) { + this(status, Unpooled.EMPTY_BUFFER); } /** @@ -53,13 +43,7 @@ public int getStatus() { return status; } - /** - * Checks if the player should be flagged. - * - * @return The flagged flag. - */ - public boolean isFlagged() { - return flagged; + public ByteBuf getPayload() { + return payload; } - } \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/codec/update/OnDemandEncryptionMessage.java b/net/src/main/java/org/apollo/net/codec/update/OnDemandEncryptionMessage.java new file mode 100644 index 000000000..b0e69d058 --- /dev/null +++ b/net/src/main/java/org/apollo/net/codec/update/OnDemandEncryptionMessage.java @@ -0,0 +1,14 @@ +package org.apollo.net.codec.update; + +public class OnDemandEncryptionMessage { + + private final int key; + + public OnDemandEncryptionMessage(int key) { + this.key = key; + } + + public int getKey() { + return key; + } +} diff --git a/net/src/main/java/org/apollo/net/codec/update/OnDemandInfo.java b/net/src/main/java/org/apollo/net/codec/update/OnDemandInfo.java new file mode 100644 index 000000000..9ca8a344f --- /dev/null +++ b/net/src/main/java/org/apollo/net/codec/update/OnDemandInfo.java @@ -0,0 +1,14 @@ +package org.apollo.net.codec.update; + +public class OnDemandInfo { + + private final long releaseNumber; + + public OnDemandInfo(long releaseNumber) { + this.releaseNumber = releaseNumber; + } + + public long getReleaseNumber() { + return releaseNumber; + } +} diff --git a/net/src/main/java/org/apollo/net/codec/update/OnDemandInfoEncoder.java b/net/src/main/java/org/apollo/net/codec/update/OnDemandInfoEncoder.java new file mode 100644 index 000000000..eecd371aa --- /dev/null +++ b/net/src/main/java/org/apollo/net/codec/update/OnDemandInfoEncoder.java @@ -0,0 +1,13 @@ +package org.apollo.net.codec.update; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; + +public class OnDemandInfoEncoder extends MessageToByteEncoder { + + @Override + protected void encode(ChannelHandlerContext ctx, OnDemandInfoResponse msg, ByteBuf buf) throws Exception { + buf.writeByte(msg.getResponse()); + } +} diff --git a/net/src/main/java/org/apollo/net/codec/update/OnDemandInfoResponse.java b/net/src/main/java/org/apollo/net/codec/update/OnDemandInfoResponse.java new file mode 100644 index 000000000..6aed25ee5 --- /dev/null +++ b/net/src/main/java/org/apollo/net/codec/update/OnDemandInfoResponse.java @@ -0,0 +1,14 @@ +package org.apollo.net.codec.update; + +public class OnDemandInfoResponse { + + private final int response; + + public OnDemandInfoResponse(int response) { + this.response = response; + } + + public int getResponse() { + return response; + } +} diff --git a/net/src/main/java/org/apollo/net/codec/update/OnDemandRequest.java b/net/src/main/java/org/apollo/net/codec/update/OnDemandRequest.java index 1ad253eb7..66c816e76 100644 --- a/net/src/main/java/org/apollo/net/codec/update/OnDemandRequest.java +++ b/net/src/main/java/org/apollo/net/codec/update/OnDemandRequest.java @@ -1,7 +1,5 @@ package org.apollo.net.codec.update; -import org.apollo.cache.FileDescriptor; - /** * Represents a single 'on-demand' request. * @@ -90,7 +88,8 @@ public int toInteger() { /** * The FileDescriptor. */ - private final FileDescriptor descriptor; + private final int fs; + private final int folder; /** * The request Priority. @@ -100,11 +99,13 @@ public int toInteger() { /** * Creates the OnDemandRequest. * - * @param descriptor The {@link FileDescriptor}. + * @param fs The file system. + * @param folder The folder. * @param priority The {@link Priority}. */ - public OnDemandRequest(FileDescriptor descriptor, Priority priority) { - this.descriptor = descriptor; + public OnDemandRequest(int fs, int folder, Priority priority) { + this.fs = fs; + this.folder = folder; this.priority = priority; } @@ -113,13 +114,12 @@ public int compareTo(OnDemandRequest other) { return priority.compareWith(other.priority); } - /** - * Gets the {@link FileDescriptor}. - * - * @return The FileDescriptor. - */ - public FileDescriptor getFileDescriptor() { - return descriptor; + public int getFs() { + return fs; + } + + public int getFolder() { + return folder; } /** diff --git a/net/src/main/java/org/apollo/net/codec/update/OnDemandResponse.java b/net/src/main/java/org/apollo/net/codec/update/OnDemandResponse.java index 750331b92..35504259b 100644 --- a/net/src/main/java/org/apollo/net/codec/update/OnDemandResponse.java +++ b/net/src/main/java/org/apollo/net/codec/update/OnDemandResponse.java @@ -1,8 +1,7 @@ package org.apollo.net.codec.update; import io.netty.buffer.ByteBuf; - -import org.apollo.cache.FileDescriptor; +import org.apollo.net.codec.update.OnDemandRequest.Priority; /** * Represents a single 'on-demand' response. @@ -16,33 +15,20 @@ public final class OnDemandResponse { */ private final ByteBuf chunkData; - /** - * The chunk id. - */ - private final int chunkId; - - /** - * The file descriptor. - */ - private final FileDescriptor fileDescriptor; - - /** - * The file size. - */ - private final int fileSize; + private final int fs; + private final int folder; + private final Priority priority; /** * Creates the 'on-demand' response. * - * @param fileDescriptor The file descriptor. - * @param fileSize The file size. - * @param chunkId The chunk id. + * @param fs The file descriptor. * @param chunkData The chunk data. */ - public OnDemandResponse(FileDescriptor fileDescriptor, int fileSize, int chunkId, ByteBuf chunkData) { - this.fileDescriptor = fileDescriptor; - this.fileSize = fileSize; - this.chunkId = chunkId; + public OnDemandResponse(int fs, int folder, Priority priority, ByteBuf chunkData) { + this.fs = fs; + this.folder = folder; + this.priority = priority; this.chunkData = chunkData; } @@ -55,31 +41,15 @@ public ByteBuf getChunkData() { return chunkData; } - /** - * Gets the chunk id. - * - * @return The chunk id. - */ - public int getChunkId() { - return chunkId; + public int getFs() { + return fs; } - /** - * Gets the file descriptor. - * - * @return The file descriptor. - */ - public FileDescriptor getFileDescriptor() { - return fileDescriptor; + public int getFolder() { + return folder; } - /** - * Gets the file size. - * - * @return The file size. - */ - public int getFileSize() { - return fileSize; + public Priority getPriority() { + return priority; } - } \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/codec/update/OnDemandResponseEncoder.java b/net/src/main/java/org/apollo/net/codec/update/OnDemandResponseEncoder.java new file mode 100644 index 000000000..e6f41474b --- /dev/null +++ b/net/src/main/java/org/apollo/net/codec/update/OnDemandResponseEncoder.java @@ -0,0 +1,61 @@ +package org.apollo.net.codec.update; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; +import io.netty.handler.codec.MessageToMessageEncoder; + +/** + * A {@link MessageToMessageEncoder} for the 'on-demand' protocol. + * + */ +public final class OnDemandResponseEncoder extends MessageToByteEncoder { + + /** + * Flag which denotes the request is async. + */ + private static final int PREFTECH = 0x80; + + /** + * The maximum number of bytes the initial payload can have. Includes the header. + */ + private static final int ENTRY_PAYLOAD_START = 508; + + /** + * The maximum number of bytes per entry. + */ + private static final int ENTRY_PAYLOAD = 511; + + /** + * Marks the beginning of the entry. + */ + private static final int ENTRY_DELIMITER = 0xFF; + + @Override + protected void encode(ChannelHandlerContext ctx, OnDemandResponse response, ByteBuf buf) { + int fs = response.getFs(); + int folder = response.getFolder(); + ByteBuf container = response.getChunkData(); + + buf.writeByte(fs); + buf.writeShort(folder); + + int compression = container.readUnsignedByte(); + if (response.getPriority() == OnDemandRequest.Priority.LOW) { + compression |= PREFTECH; + } + + buf.writeByte(compression); + buf.writeBytes(container.readBytes(Math.min(ENTRY_PAYLOAD_START, container.readableBytes()))); + + int bytes; + while ((bytes = Math.min(ENTRY_PAYLOAD, container.readableBytes())) != 0) { + buf.writeByte(ENTRY_DELIMITER); + + final var payload = container.readBytes(bytes); + buf.writeBytes(payload); + + payload.release(); + } + } +} \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/codec/update/UpdateDecoder.java b/net/src/main/java/org/apollo/net/codec/update/UpdateDecoder.java index 807435770..64a0f7a58 100644 --- a/net/src/main/java/org/apollo/net/codec/update/UpdateDecoder.java +++ b/net/src/main/java/org/apollo/net/codec/update/UpdateDecoder.java @@ -3,12 +3,10 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; +import org.apollo.net.codec.update.OnDemandRequest.Priority; import java.util.List; -import org.apollo.cache.FileDescriptor; -import org.apollo.net.codec.update.OnDemandRequest.Priority; - /** * A {@link ByteToMessageDecoder} for the 'on-demand' protocol. * @@ -16,16 +14,32 @@ */ public final class UpdateDecoder extends ByteToMessageDecoder { + private enum State { + READ_VERSION, READ_REQUEST + } + + private State state = State.READ_VERSION; + @Override protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List out) { - if (buffer.readableBytes() >= 4) { - int type = buffer.readUnsignedByte() + 1; - int file = buffer.readUnsignedShort(); - Priority priority = Priority.valueOf(buffer.readUnsignedByte()); + if (!buffer.isReadable( Byte.BYTES + Byte.BYTES + Short.BYTES)) { + return; + } - FileDescriptor desc = new FileDescriptor(type, file); - out.add(new OnDemandRequest(desc, priority)); + if (state == State.READ_VERSION) { + this.state = State.READ_REQUEST; + out.add(new OnDemandInfo(buffer.readUnsignedInt())); + } else { + int opcode = buffer.readUnsignedByte(); + if (opcode == 0 || opcode == 1) { + out.add(new OnDemandRequest(buffer.readUnsignedByte(), buffer.readUnsignedShort(), + Priority.valueOf(opcode))); + } else if (opcode == 4) { + int key = buffer.readUnsignedByte(); + buffer.readerIndex(buffer.readerIndex() + Short.BYTES); + } else { + buffer.readerIndex(buffer.readerIndex() + Byte.BYTES + Short.BYTES); + } } } - } \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/codec/update/UpdateEncoder.java b/net/src/main/java/org/apollo/net/codec/update/UpdateEncoder.java deleted file mode 100644 index 5c6592a9d..000000000 --- a/net/src/main/java/org/apollo/net/codec/update/UpdateEncoder.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.apollo.net.codec.update; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToMessageEncoder; - -import java.util.List; - -import org.apollo.cache.FileDescriptor; - -/** - * A {@link MessageToMessageEncoder} for the 'on-demand' protocol. - * - * @author Graham - */ -public final class UpdateEncoder extends MessageToMessageEncoder { - - @Override - protected void encode(ChannelHandlerContext ctx, OnDemandResponse response, List out) { - FileDescriptor descriptor = response.getFileDescriptor(); - int fileSize = response.getFileSize(); - int chunkId = response.getChunkId(); - ByteBuf chunkData = response.getChunkData(); - - ByteBuf buffer = ctx.alloc().buffer(2 * Byte.BYTES + 2 * Short.BYTES + chunkData.readableBytes()); - buffer.writeByte(descriptor.getType() - 1); - buffer.writeShort(descriptor.getFile()); - buffer.writeShort(fileSize); - buffer.writeByte(chunkId); - buffer.writeBytes(chunkData); - - out.add(buffer); - } - -} \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/update/HttpRequestWorker.java b/net/src/main/java/org/apollo/net/update/HttpRequestWorker.java index 4e9a91a29..3c945fac7 100644 --- a/net/src/main/java/org/apollo/net/update/HttpRequestWorker.java +++ b/net/src/main/java/org/apollo/net/update/HttpRequestWorker.java @@ -17,11 +17,8 @@ import java.util.Date; import java.util.Optional; -import org.apollo.cache.IndexedFileSystem; -import org.apollo.net.update.resource.CombinedResourceProvider; -import org.apollo.net.update.resource.HypertextResourceProvider; -import org.apollo.net.update.resource.ResourceProvider; -import org.apollo.net.update.resource.VirtualResourceProvider; +import org.apollo.cache.Cache; +import org.apollo.net.update.resource.*; import com.google.common.base.Charsets; @@ -53,8 +50,8 @@ public final class HttpRequestWorker extends RequestWorker { - - /** - * The maximum length of a chunk, in {@code byte}s. - */ - private static final int CHUNK_LENGTH = 500; +public final class OnDemandRequestWorker extends RequestWorker { /** * Creates the 'on-demand' request worker. * * @param dispatcher The dispatcher. - * @param fs The file system. + * @param fs The file system. */ - public OnDemandRequestWorker(UpdateDispatcher dispatcher, IndexedFileSystem fs) { + public OnDemandRequestWorker(UpdateDispatcher dispatcher, Cache fs) { super(dispatcher, fs); } @@ -39,16 +32,23 @@ protected ChannelRequest nextRequest(UpdateDispatcher dispatche } @Override - protected void service(IndexedFileSystem fs, Channel channel, OnDemandRequest request) throws IOException { - FileDescriptor descriptor = request.getFileDescriptor(); - ByteBuf buffer = Unpooled.wrappedBuffer(fs.getFile(descriptor)); - int length = buffer.readableBytes(); - - for (int chunk = 0; buffer.readableBytes() > 0; chunk++) { - int chunkSize = Math.min(buffer.readableBytes(), CHUNK_LENGTH); - OnDemandResponse response = new OnDemandResponse(descriptor, length, chunk, buffer.readBytes(chunkSize)); - channel.writeAndFlush(response); + protected void service(Cache cache, Channel channel, OnDemandRequest request) throws IOException { + final var fs = request.getFs(); + final var folder = request.getFolder(); + + ByteBuf buf; + if (fs == 255 && folder == 255) { + buf = Unpooled.wrappedBuffer(cache.generateInformationStoreDescriptor(false).getBuffer()); + } else { + final var store = fs == 255 ? cache.getMasterIndex() : cache.getIndex(fs); + if (store == null) { + return; + } + buf = Unpooled.wrappedBuffer(store.get(folder).getBuffer()); + if (fs != 255) buf = buf.slice(0, buf.readableBytes() - 2); } - } + OnDemandResponse response = new OnDemandResponse(fs, folder, request.getPriority(), buf); + channel.writeAndFlush(response); + } } \ No newline at end of file diff --git a/net/src/main/java/org/apollo/net/update/resource/VirtualResourceProvider.java b/net/src/main/java/org/apollo/net/update/resource/VirtualResourceProvider.java index 54093b672..a3016fa17 100644 --- a/net/src/main/java/org/apollo/net/update/resource/VirtualResourceProvider.java +++ b/net/src/main/java/org/apollo/net/update/resource/VirtualResourceProvider.java @@ -7,11 +7,11 @@ import java.util.Objects; import java.util.Optional; -import org.apollo.cache.IndexedFileSystem; +import org.apollo.cache.Cache; /** * A {@link ResourceProvider} which maps virtual resources (such as {@code /media}) to files in an - * {@link IndexedFileSystem}. + * {@link Cache}. * * @author Graham */ @@ -25,14 +25,14 @@ public final class VirtualResourceProvider implements ResourceProvider { /** * The file system. */ - private final IndexedFileSystem fs; + private final Cache fs; /** * Creates a new virtual resource provider with the specified file system. * * @param fs The file system. */ - public VirtualResourceProvider(IndexedFileSystem fs) { + public VirtualResourceProvider(Cache fs) { this.fs = fs; } @@ -45,7 +45,7 @@ public boolean accept(String path) throws IOException { @Override public Optional get(String path) throws IOException { - if (path.startsWith("/crc")) { + /*if (path.startsWith("/crc")) { return Optional.of(fs.getCrcTable()); } else if (path.startsWith("/title")) { return Optional.of(fs.getFile(0, 1)); @@ -63,7 +63,7 @@ public Optional get(String path) throws IOException { return Optional.of(fs.getFile(0, 7)); } else if (path.startsWith("/sounds")) { return Optional.of(fs.getFile(0, 8)); - } + }*/ return Optional.empty(); } diff --git a/net/src/main/java/org/apollo/net/update/resource/WorldListResourceProvider.java b/net/src/main/java/org/apollo/net/update/resource/WorldListResourceProvider.java new file mode 100644 index 000000000..409d26321 --- /dev/null +++ b/net/src/main/java/org/apollo/net/update/resource/WorldListResourceProvider.java @@ -0,0 +1,49 @@ +package org.apollo.net.update.resource; + +import org.apollo.util.BufferUtil; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Optional; + +public class WorldListResourceProvider implements ResourceProvider { + + private static final String WORLDLIST_PATH = "/"; + + @Override + public boolean accept(String path) throws IOException { + return path.equals(WORLDLIST_PATH); + } + + @Override + public Optional get(String path) throws IOException { + final var world = createWorld(); + final var buf = ByteBuffer.allocate(Integer.BYTES + world.remaining()); + + buf.putInt(world.remaining()); + buf.put(world); + + return Optional.of(buf.flip()); + } + + private ByteBuffer createWorld() { + final var address = "127.0.0.1";//10 + final var activity = "Converting Apollo";//18 + + ByteBuffer world = ByteBuffer.allocate(Short.BYTES + Integer.BYTES + address.length() + activity + .length() + Byte.BYTES + Byte.BYTES + Byte.BYTES + Short.BYTES); + world.putShort((short) 1); // world id + world.putInt(0); // world settings + BufferUtil.writeString(world, address); // address + BufferUtil.writeString(world, activity); // activity + world.put((byte) 0); // country + world.putShort((short) 100);// number of players + world.flip(); + + ByteBuffer list = ByteBuffer.allocate(Short.BYTES + world.remaining()); + list.putShort((short) 1); // number of worlds + list.put(world); + + return list.flip(); + } +} diff --git a/util/src/main/java/org/apollo/util/BufferUtil.java b/util/src/main/java/org/apollo/util/BufferUtil.java index 146763796..171029439 100644 --- a/util/src/main/java/org/apollo/util/BufferUtil.java +++ b/util/src/main/java/org/apollo/util/BufferUtil.java @@ -3,6 +3,7 @@ import io.netty.buffer.ByteBuf; import java.nio.ByteBuffer; +import java.nio.charset.Charset; /** * A utility class which contains {@link ByteBuffer}-related utility methods. @@ -24,6 +25,18 @@ public static int readSmart(ByteBuffer buffer) { return value; } + + public static int readHugeSmart(ByteBuffer buffer) { + int value = 0; + int read; + for (read = readSmart(buffer); read == 32767; read = readSmart(buffer)) { + value += 32767; + } + value += read; + return value; + } + + /** * Reads a string from the specified {@link ByteBuffer}. * @@ -65,10 +78,60 @@ public static int readUnsignedMedium(ByteBuffer buffer) { return (buffer.getShort() & 0xFFFF) << 8 | buffer.get() & 0xFF; } + /** + * Reads a 24-bit medium integer from the specified {@link ByteBuffer}s current position and increases the buffers + * position by 3. + * + * @param buffer The {@link ByteBuffer} to read from. + * @return The read 24-bit medium integer. + */ + public static int readUnsignedMedium(ByteBuf buffer) { + return buffer.readUnsignedShort() << 8 | buffer.readUnsignedByte(); + } + + /** + * Reads a jagex-string from the specified {@link ByteBuf}. + * + * @param buffer The buffer. + * @return The string. + */ + public static String readJagexString(ByteBuf buffer) { + buffer.readByte(); + return readString(buffer); + } + + + /** + * Writes a string to the specified {@link ByteBuf} + * @param buffer + * @param str + */ + public static void writeString(ByteBuf buffer, String str) { + byte[] bytes = str.getBytes(CHARSET); + buffer.writeBytes(bytes); + buffer.writeByte(0); + } + + /** + * Writes a string to the specified {@link ByteBuf} + * @param buffer + * @param str + */ + public static void writeString(ByteBuffer buffer, String str) { + byte[] bytes = str.getBytes(CHARSET); + buffer.put(bytes); + buffer.put((byte) 0); + } + /** * The terminator of a string. */ - public static final int STRING_TERMINATOR = 10; + public static final int STRING_TERMINATOR = 0; + + /** + * Charset that Runescape uses. + */ + public static final Charset CHARSET = Charset.forName("Windows-1252"); /** * Default private constructor to prevent instantiation. @@ -77,4 +140,5 @@ private BufferUtil() { } + } \ No newline at end of file diff --git a/util/src/main/java/org/apollo/util/TextUtil.java b/util/src/main/java/org/apollo/util/TextUtil.java index af262f34b..4c6ccc7f3 100644 --- a/util/src/main/java/org/apollo/util/TextUtil.java +++ b/util/src/main/java/org/apollo/util/TextUtil.java @@ -11,10 +11,7 @@ public final class TextUtil { * An array of characters ordered by frequency - the elements with lower indices (generally) appear more often in * chat messages. */ - public static final char[] FREQUENCY_ORDERED_CHARS = { ' ', 'e', 't', 'a', 'o', 'i', 'h', 'n', 's', 'r', 'd', 'l', - 'u', 'm', 'w', 'c', 'y', 'f', 'g', 'p', 'b', 'v', 'k', 'x', 'j', 'q', 'z', '0', '1', '2', '3', '4', '5', - '6', '7', '8', '9', ' ', '!', '?', '.', ',', ':', ';', '(', ')', '-', '&', '*', '\\', '\'', '@', '#', '+', - '=', '\243', '$', '%', '"', '[', ']' }; + public static final char[] FREQUENCY_ORDERED_CHARS = {' ', 'e', 't', 'a', 'o', 'i', 'h', 'n', 's', 'r', 'd', 'l', 'u', 'm', 'w', 'c', 'y', 'f', 'g', 'p', 'b', 'v', 'k', 'x', 'j', 'q', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ', '!', '?', '.', ',', ':', ';', '(', ')', '-', '&', '*', '\\', '\'', '@', '#', '+', '=', '\243', '$', '%', '"', '[', ']'}; /** * Capitalizes the string correctly. @@ -43,53 +40,6 @@ public static String capitalize(String string) { return builder.toString(); } - /** - * Compresses the input text ({@code in}) and places the result in the {@code out} array. - * - * @param in The input text. - * @param out The output array. - * @return The number of bytes written to the output array. - */ - public static int compress(String in, byte[] out) { - if (in.length() > 80) { - in = in.substring(0, 80); - } - in = in.toLowerCase(); - - int carry = -1; - int outPos = 0; - for (int inPos = 0; inPos < in.length(); inPos++) { - char c = in.charAt(inPos); - int tblPos = 0; - for (int i = 0; i < FREQUENCY_ORDERED_CHARS.length; i++) { - if (c == FREQUENCY_ORDERED_CHARS[i]) { - tblPos = i; - break; - } - } - if (tblPos > 12) { - tblPos += 195; - } - if (carry == -1) { - if (tblPos < 13) { - carry = tblPos; - } else { - out[outPos++] = (byte) tblPos; - } - } else if (tblPos < 13) { - out[outPos++] = (byte) ((carry << 4) + tblPos); - carry = -1; - } else { - out[outPos++] = (byte) ((carry << 4) + (tblPos >> 4)); - carry = tblPos & 0xF; - } - } - if (carry != -1) { - out[outPos++] = (byte) (carry << 4); - } - return outPos; - } - /** * Filters invalid characters from the specified string. * @@ -109,35 +59,6 @@ public static String filterInvalidCharacters(String str) { return builder.toString(); } - /** - * Uncompresses the compressed data ({@code in}) with the length ({@code len}) and returns the uncompressed - * {@link String}. - * - * @param in The compressed input data. - * @param len The length. - * @return The uncompressed {@link String}. - */ - public static String decompress(byte[] in, int len) { - byte[] out = new byte[4096]; - int outPos = 0; - int carry = -1; - - for (int i = 0; i < len * 2; i++) { - int tblPos = in[i / 2] >> 4 - 4 * (i % 2) & 0xF; - if (carry == -1) { - if (tblPos < 13) { - out[outPos++] = (byte) FREQUENCY_ORDERED_CHARS[tblPos]; - } else { - carry = tblPos; - } - } else { - out[outPos++] = (byte) FREQUENCY_ORDERED_CHARS[(carry << 4) + tblPos - 195]; - carry = -1; - } - } - return new String(out, 0, outPos); - } - /** * Default private constructor to prevent instantiation. */ diff --git a/util/src/main/java/org/apollo/util/XteaUtil.java b/util/src/main/java/org/apollo/util/XteaUtil.java new file mode 100644 index 000000000..a9f67287b --- /dev/null +++ b/util/src/main/java/org/apollo/util/XteaUtil.java @@ -0,0 +1,53 @@ +package org.apollo.util; + +import io.netty.buffer.ByteBuf; + +public class XteaUtil { + + + /** + * The golden ratio XTEA uses. + */ + private static final int GOLDEN_RATIO = -1640531527; + + /** + * The number of rounds XTEA uses. + */ + private static final int ROUNDS = 32; + + public static void decipher(ByteBuf buffer, int start, int end, int[] key) { + if (key.length != 4) throw new IllegalArgumentException(); + + int numQuads = (end - start) / 8; + for (int i = 0; i < numQuads; i++) { + int sum = GOLDEN_RATIO * ROUNDS; + int v0 = buffer.getInt(start + i * 8); + int v1 = buffer.getInt(start + i * 8 + 4); + for (int j = 0; j < ROUNDS; j++) { + v1 -= (((v0 << 4) ^ (v0 >>> 5)) + v0) ^ (sum + key[(sum >>> 11) & 3]); + sum -= GOLDEN_RATIO; + v0 -= (((v1 << 4) ^ (v1 >>> 5)) + v1) ^ (sum + key[sum & 3]); + } + buffer.setInt(start + i * 8, v0); + buffer.setInt(start + i * 8 + 4, v1); + } + } + + public static void encypher(ByteBuf buffer, int start, int end, int[] key) { + if (key.length != 4) throw new IllegalArgumentException(); + + int numQuads = (end - start) / 8; + for (int i = 0; i < numQuads; i++) { + int sum = 0; + int v0 = buffer.getInt(start + i * 8); + int v1 = buffer.getInt(start + i * 8 + 4); + for (int j = 0; j < ROUNDS; j++) { + v0 += (((v1 << 4) ^ (v1 >>> 5)) + v1) ^ (sum + key[sum & 3]); + sum += GOLDEN_RATIO; + v1 += (((v0 << 4) ^ (v0 >>> 5)) + v0) ^ (sum + key[(sum >>> 11) & 3]); + } + buffer.setInt(start + i * 8, v0); + buffer.setInt(start + i * 8 + 4, v1); + } + } +} diff --git a/util/src/main/java/org/apollo/util/security/PlayerCredentials.java b/util/src/main/java/org/apollo/util/security/PlayerCredentials.java index 7bfc466f3..4b1beb5cb 100644 --- a/util/src/main/java/org/apollo/util/security/PlayerCredentials.java +++ b/util/src/main/java/org/apollo/util/security/PlayerCredentials.java @@ -20,9 +20,9 @@ public final class PlayerCredentials { private String password; /** - * The computer's unique identifier. + * The computer's hardware specs. */ - private final int uid; + private final UserStats userStats; /** * The player's username. @@ -41,19 +41,18 @@ public final class PlayerCredentials { /** * Creates a new {@link PlayerCredentials} object with the specified name, password and uid. - * - * @param username The player's username. + * @param username The player's username. * @param password The player's password. * @param usernameHash The hash of the player's username. - * @param uid The computer's uid. + * @param userStats The computer's uid. * @param hostAddress The Player's connecting host address. */ - public PlayerCredentials(String username, String password, int usernameHash, int uid, String hostAddress) { + public PlayerCredentials(String username, String password, int usernameHash, UserStats userStats, String hostAddress) { this.username = username; - encodedUsername = NameUtil.encodeBase37(username); + this.encodedUsername = NameUtil.encodeBase37(username); this.password = password; this.usernameHash = usernameHash; - this.uid = uid; + this.userStats = userStats; this.hostAddress = hostAddress; } @@ -85,12 +84,12 @@ public String getPassword() { } /** - * Gets the computer's uid. + * Gets the computer's specs. * - * @return The computer's uid. + * @return The computer's specs. */ - public int getUid() { - return uid; + public UserStats getUserStats() { + return userStats; } /** diff --git a/util/src/main/java/org/apollo/util/security/UserStats.java b/util/src/main/java/org/apollo/util/security/UserStats.java new file mode 100644 index 000000000..8902d70fa --- /dev/null +++ b/util/src/main/java/org/apollo/util/security/UserStats.java @@ -0,0 +1,371 @@ +package org.apollo.util.security; + +import io.netty.buffer.ByteBuf; +import org.apollo.util.BufferUtil; + +public class UserStats { + + /** + * Current version of the {@Link UserStats}. + */ + public static final int STATS_VERSION = 8; + + /** + * The reported version. + */ + private final short version; + + /** + * The type of operating system. + */ + private final int osType; + /** + * If the operating system uses 64bits. + */ + private final boolean os64Bit; + /** + * The version of the OS. + */ + private final int osVersion; + /** + * The vendor of the JVM. + */ + private final int javaVendor; + /** + * The major version of the active JVM. + */ + private final int javaMajor; + /** + * The minor version of the active JVM. + */ + private final int javaMinor; + /** + * The build of the active JVM. + */ + private final int javaBuild; + /** + * Number of processors available. + */ + private final int availableProcessors; + /** + * Driver release year. + */ + private final int gpuDriverYear; + /** + * Driver release month. + */ + private final int gpuDriverMonth; + /** + * If this is running off a console. + */ + private final boolean isConsole; + /** + * Maximum heap memory. + */ + private final int maxMemory; + /** + * The number of CPUs on the machine. + */ + private final int cpuCount; + /** + * The number of RAM available on the machine. + */ + private final int ramAmount; + /** + * The current CPU's clock speed. + */ + private final int cpuClockspeed; + /** + * The description of the gpu's driver. + */ + private final String gpuDriverDescription; + /** + * The name of the GPU. + */ + private final String gpuName; + /** + * The directX version installed. + */ + private final String directxVersion; + /** + * The CPU's brand identifier. + */ + private final int cpuBrandId; + /** + * The CPU"s vendor identifier. + */ + private final String cpuVendor; + /** + * The cpu brand's name. + */ + private final String cpuBrandString; + /** + * Features on the CPU. + */ + private final int[] cpuFeatures = new int[3]; + /** + * The model of the CPU. + */ + private final int cpuModel; + + /** + * Instantiates a new User stats. + * + * @param buffer the buffer + */ + public UserStats(ByteBuf buffer) { + version = buffer.readUnsignedByte(); + osType = buffer.readUnsignedByte(); + os64Bit = buffer.readBoolean(); + osVersion = buffer.readUnsignedShort(); + javaVendor = buffer.readUnsignedByte(); + javaMajor = buffer.readUnsignedByte(); + javaMinor = buffer.readUnsignedByte(); + javaBuild = buffer.readUnsignedByte(); + isConsole = buffer.readBoolean(); + maxMemory = buffer.readUnsignedShort(); + availableProcessors = buffer.readUnsignedByte(); + ramAmount = BufferUtil.readUnsignedMedium(buffer); + cpuClockspeed = buffer.readUnsignedShort(); + gpuDriverDescription = BufferUtil.readJagexString(buffer); + BufferUtil.readJagexString(buffer); // empty + gpuName = BufferUtil.readJagexString(buffer); + directxVersion = BufferUtil.readJagexString(buffer); + gpuDriverYear = buffer.readUnsignedByte(); + gpuDriverMonth = buffer.readUnsignedShort(); + cpuVendor = BufferUtil.readJagexString(buffer); + cpuBrandString = BufferUtil.readJagexString(buffer); + cpuCount = buffer.readUnsignedByte(); + cpuBrandId = buffer.readUnsignedByte(); + for (int index = 0; index < cpuFeatures.length; index++) { + cpuFeatures[index] = buffer.readInt(); + } + cpuModel = buffer.readInt(); + BufferUtil.readJagexString(buffer); // Empty + } + + /** + * Is valid boolean. + * + * @return the boolean + */ + public boolean isValid() { + return version == STATS_VERSION; + } + + /** + * Gets version. + * + * @return the version + */ + public short getVersion() { + return version; + } + + /** + * Gets os type. + * + * @return the os type + */ + public int getOsType() { + return osType; + } + + /** + * Is os 64 bit boolean. + * + * @return the boolean + */ + public boolean isOs64Bit() { + return os64Bit; + } + + /** + * Gets os version. + * + * @return the os version + */ + public int getOsVersion() { + return osVersion; + } + + /** + * Gets java vendor. + * + * @return the java vendor + */ + public int getJavaVendor() { + return javaVendor; + } + + /** + * Gets java major. + * + * @return the java major + */ + public int getJavaMajor() { + return javaMajor; + } + + /** + * Gets java minor. + * + * @return the java minor + */ + public int getJavaMinor() { + return javaMinor; + } + + /** + * Gets java build. + * + * @return the java build + */ + public int getJavaBuild() { + return javaBuild; + } + + /** + * Gets available processors. + * + * @return the available processors + */ + public int getAvailableProcessors() { + return availableProcessors; + } + + /** + * Gets gpu driver year. + * + * @return the gpu driver year + */ + public int getGpuDriverYear() { + return gpuDriverYear; + } + + /** + * Gets gpu driver month. + * + * @return the gpu driver month + */ + public int getGpuDriverMonth() { + return gpuDriverMonth; + } + + /** + * Is console boolean. + * + * @return the boolean + */ + public boolean isConsole() { + return isConsole; + } + + /** + * Gets max memory. + * + * @return the max memory + */ + public int getMaxMemory() { + return maxMemory; + } + + /** + * Gets cpu count. + * + * @return the cpu count + */ + public int getCpuCount() { + return cpuCount; + } + + /** + * Gets ram amount. + * + * @return the ram amount + */ + public int getRamAmount() { + return ramAmount; + } + + /** + * Gets cpu clockspeed. + * + * @return the cpu clockspeed + */ + public int getCpuClockspeed() { + return cpuClockspeed; + } + + /** + * Gets gpu driver description. + * + * @return the gpu driver description + */ + public String getGpuDriverDescription() { + return gpuDriverDescription; + } + + /** + * Gets gpu name. + * + * @return the gpu name + */ + public String getGpuName() { + return gpuName; + } + + /** + * Gets directx version. + * + * @return the directx version + */ + public String getDirectxVersion() { + return directxVersion; + } + + /** + * Gets cpu brand id. + * + * @return the cpu brand id + */ + public int getCpuBrandId() { + return cpuBrandId; + } + + /** + * Gets cpu vendor. + * + * @return the cpu vendor + */ + public String getCpuVendor() { + return cpuVendor; + } + + /** + * Gets cpu brand string. + * + * @return the cpu brand string + */ + public String getCpuBrandString() { + return cpuBrandString; + } + + /** + * Get cpu features int [ ]. + * + * @return the int [ ] + */ + public int[] getCpuFeatures() { + return cpuFeatures; + } + + /** + * Gets cpu model. + * + * @return the cpu model + */ + public int getCpuModel() { + return cpuModel; + } +} diff --git a/util/src/test/java/org/apollo/util/TextUtilTests.java b/util/src/test/java/org/apollo/util/TextUtilTests.java index b7b637dc4..174b6e8d7 100644 --- a/util/src/test/java/org/apollo/util/TextUtilTests.java +++ b/util/src/test/java/org/apollo/util/TextUtilTests.java @@ -23,20 +23,6 @@ public void testCapitalize() { assertEquals("Test", TextUtil.capitalize("test")); } - /** - * Tests the {@link TextUtil#compress} and {@link TextUtil#decompress} methods. - */ - @Test - public void testCompression() { - String str = "hello, world!"; - - byte[] compressed = new byte[128]; - int len = TextUtil.compress(str, compressed); - String uncompressed = TextUtil.decompress(compressed, len); - - assertEquals(str, uncompressed); - } - /** * Tests the {@link TextUtil#filterInvalidCharacters(String)} method. */