From e0c7287af523b3c0f95603cd89803cd021d2160b Mon Sep 17 00:00:00 2001 From: Major- Date: Sun, 27 Oct 2013 19:31:44 +0000 Subject: [PATCH] Implement various fixes from Major-/Apollo. --- FIXES | 19 +++ data/plugins/mining/gem.rb | 14 +- data/plugins/mining/mining.rb | 2 +- src/org/apollo/fs/archive/Archive.java | 31 ++-- .../fs/parser/ItemDefinitionParser.java | 112 ++++++--------- .../handler/chain/EventHandlerChain.java | 1 + .../event/handler/impl/EquipEventHandler.java | 16 +-- .../handler/impl/RemoveEventHandler.java | 31 ++-- src/org/apollo/game/model/SkillSet.java | 88 ++++++++---- src/org/apollo/game/model/WalkingQueue.java | 42 ++++-- .../apollo/game/model/obj/StaticObject.java | 22 ++- .../sync/task/PlayerSynchronizationTask.java | 48 ++++--- .../task/PrePlayerSynchronizationTask.java | 1 - .../apollo/io/EventHandlerChainParser.java | 52 ++++--- .../net/release/r317/ChatEventDecoder.java | 12 +- .../r317/FifthItemActionEventDecoder.java | 14 +- .../r317/FirstObjectActionEventDecoder.java | 15 +- .../PlayerSynchronizationEventEncoder.java | 136 ++++++++++++------ .../apollo/net/release/r317/Release317.java | 4 +- .../r317/SecondItemActionEventDecoder.java | 14 +- .../r317/SetInterfaceTextEventEncoder.java | 30 ++++ .../release/r317/SwitchItemEventDecoder.java | 13 +- .../r317/ThirdItemActionEventDecoder.java | 15 +- .../apollo/net/release/r377/Release377.java | 131 +++++------------ .../r377/ThirdObjectActionEventDecoder.java | 12 +- src/org/apollo/tools/EquipmentConstants.java | 60 +++++--- 26 files changed, 565 insertions(+), 370 deletions(-) create mode 100644 FIXES create mode 100644 src/org/apollo/net/release/r317/SetInterfaceTextEventEncoder.java diff --git a/FIXES b/FIXES new file mode 100644 index 00000000..0fc9a4fe --- /dev/null +++ b/FIXES @@ -0,0 +1,19 @@ +This version of Apollo contains code from the following people: + Graham and the rest of the Apollo team + Chris Fletcher (http://www.rune-server.org/members/chris%20fletcher) + Major (http://www.rune-server.org/members/major) + The Wanderer (http://www.rune-server.org/members/the%20wanderer) + +Current fixes include: + 317 ChatEventDecoder fix (data read incorrectly) - http://www.rune-server.org/runescape-development/rs2-server/snippets/420815-apollo-317-chat-event-decoder-bug-fix.html. + Player region changing fix (appeared to teleport) - http://www.rune-server.org/runescape-development/rs2-server/snippets/420865-apollo-players-changing-regions-appear-teleport-bug.html + Walking height level fix (always set to 0) + ThirdObjectActionEvent fix (data read incorrectly) + Combat level formula fix (calculated incorrectly) + Item equipping fix (wasn't removing them correctly) + 2-handed weapon equip fix + SwitchItemEventDecoder fix (data read incorrectly) + SetInterfaceTextEventencoder fix (entire class was missing from 317) + 317 and 377 packet length fixes. + Archive decoding fix (data wasn't being extracted properly) + Mining plugin: JRuby name clash with 'Gem' diff --git a/data/plugins/mining/gem.rb b/data/plugins/mining/gem.rb index 956b34dd..eb48be7a 100644 --- a/data/plugins/mining/gem.rb +++ b/data/plugins/mining/gem.rb @@ -1,6 +1,6 @@ -GEMS = {} +GEMSTONES = {} -class Gem +class Gemstone attr_reader :id, :chance def initialize(id, chance) @@ -10,10 +10,10 @@ class Gem end def append_gem(gem) - GEMS[gem.id] = gem + GEMSTONES[gem.id] = gem end -append_gem(Gem.new(1623, 0)) # uncut sapphire -append_gem(Gem.new(1605, 0)) # uncut emerald -append_gem(Gem.new(1619, 0)) # uncut ruby -append_gem(Gem.new(1617, 0)) # uncut diamond +append_gem(Gemstone.new(1623, 0)) # uncut sapphire +append_gem(Gemstone.new(1605, 0)) # uncut emerald +append_gem(Gemstone.new(1619, 0)) # uncut ruby +append_gem(Gemstone.new(1617, 0)) # uncut diamond diff --git a/data/plugins/mining/mining.rb b/data/plugins/mining/mining.rb index 8b882da4..7ddcb74e 100644 --- a/data/plugins/mining/mining.rb +++ b/data/plugins/mining/mining.rb @@ -45,7 +45,7 @@ class MiningAction < DistancedAction def executeAction skills = character.skill_set - level = skills.get_skill(Skill::MINING).maximum_level # TODO: is using max level correct? + level = skills.get_skill(Skill::MINING).current_level pickaxe = find_pickaxe # verify the player can mine with their pickaxe diff --git a/src/org/apollo/fs/archive/Archive.java b/src/org/apollo/fs/archive/Archive.java index a8e99928..329a7789 100644 --- a/src/org/apollo/fs/archive/Archive.java +++ b/src/org/apollo/fs/archive/Archive.java @@ -9,21 +9,24 @@ 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. + * + * @param buffer + * The buffer. * @return The archive. - * @throws IOException if an I/O error occurs. + * @throws IOException + * if an I/O error occurs. */ public static Archive decode(ByteBuffer buffer) throws IOException { int extractedSize = ByteBufferUtil.readUnsignedTriByte(buffer); int size = ByteBufferUtil.readUnsignedTriByte(buffer); boolean extracted = false; - if (size != extractedSize) { byte[] compressed = new byte[size]; byte[] uncompressed = new byte[extractedSize]; @@ -32,32 +35,31 @@ public final class Archive { buffer = ByteBuffer.wrap(uncompressed); extracted = true; } - int entries = buffer.getShort() & 0xFFFF; int[] identifiers = new int[entries]; int[] extractedSizes = new int[entries]; int[] sizes = new int[entries]; - for (int i = 0; i < entries; i++) { identifiers[i] = buffer.getInt(); extractedSizes[i] = ByteBufferUtil.readUnsignedTriByte(buffer); sizes[i] = ByteBufferUtil.readUnsignedTriByte(buffer); } - ArchiveEntry[] entry = new ArchiveEntry[entries]; - for (int i = 0; i < entries; i++) { - ByteBuffer entryBuffer = ByteBuffer.allocate(extractedSizes[i]); + ByteBuffer entryBuffer; if (!extracted) { byte[] compressed = new byte[sizes[i]]; byte[] uncompressed = new byte[extractedSizes[i]]; buffer.get(compressed); CompressionUtil.unbzip2(compressed, uncompressed); entryBuffer = ByteBuffer.wrap(uncompressed); + } else { + byte[] buf = new byte[extractedSizes[i]]; + buffer.get(buf); + entryBuffer = ByteBuffer.wrap(buf); } entry[i] = new ArchiveEntry(identifiers[i], entryBuffer); } - return new Archive(entry); } @@ -68,7 +70,9 @@ public final class Archive { /** * Creates a new archive. - * @param entries The entries in this archive. + * + * @param entries + * The entries in this archive. */ public Archive(ArchiveEntry[] entries) { this.entries = entries; @@ -76,9 +80,12 @@ public final class Archive { /** * Gets an entry by its name. - * @param name The name. + * + * @param name + * The name. * @return The entry. - * @throws FileNotFoundException if the file could not be found. + * @throws FileNotFoundException + * if the file could not be found. */ public ArchiveEntry getEntry(String name) throws FileNotFoundException { int hash = 0; diff --git a/src/org/apollo/fs/parser/ItemDefinitionParser.java b/src/org/apollo/fs/parser/ItemDefinitionParser.java index bfc58692..fa4b0aa0 100644 --- a/src/org/apollo/fs/parser/ItemDefinitionParser.java +++ b/src/org/apollo/fs/parser/ItemDefinitionParser.java @@ -10,6 +10,7 @@ import org.apollo.util.ByteBufferUtil; /** * A class which parses item definitions. + * * @author Graham */ public final class ItemDefinitionParser { @@ -21,7 +22,9 @@ public final class ItemDefinitionParser { /** * Creates the item definition parser. - * @param fs The indexed file system. + * + * @param fs + * The indexed file system. */ public ItemDefinitionParser(IndexedFileSystem fs) { this.fs = fs; @@ -29,8 +32,10 @@ public final class ItemDefinitionParser { /** * Parses the item definitions. + * * @return The item definitions. - * @throws IOException if an I/O error occurs. + * @throws IOException + * if an I/O error occurs. */ public ItemDefinition[] parse() throws IOException { Archive config = Archive.decode(fs.getFile(0, 2)); @@ -56,65 +61,54 @@ public final class ItemDefinitionParser { /** * Parses a single definition. - * @param id The item's id. - * @param buffer The buffer. + * + * @param id + * The item's id. + * @param buffer + * The buffer. * @return The definition. */ private ItemDefinition parseDefinition(int id, ByteBuffer buffer) { ItemDefinition def = new ItemDefinition(id); - while (true) { int code = buffer.get() & 0xFF; if (code == 0) { return def; } else if (code == 1) { - @SuppressWarnings("unused") - int modelId = buffer.getShort() & 0xFFFF; + buffer.getShort();// & 0xFFFF; // model Id } else if (code == 2) { def.setName(ByteBufferUtil.readString(buffer)); } else if (code == 3) { def.setDescription(ByteBufferUtil.readString(buffer)); } else if (code == 4) { - @SuppressWarnings("unused") - int modelScale = buffer.getShort() & 0xFFFF; + buffer.getShort();// & 0xFFFF; // sprite scale } else if (code == 5) { - @SuppressWarnings("unused") - int modelRotationX = buffer.getShort() & 0xFFFF; + buffer.getShort();// & 0xFFFF; // sprite pitch } else if (code == 6) { - @SuppressWarnings("unused") - int modelRotationY = buffer.getShort() & 0xFFFF; + buffer.getShort();// & 0xFFFF; //sprite camera roll } else if (code == 7) { - @SuppressWarnings("unused") - int modelTransformationX = buffer.getShort(); + buffer.getShort(); // sprite dX } else if (code == 8) { - @SuppressWarnings("unused") - int modelTransformationY = buffer.getShort(); + buffer.getShort(); // sprite dY } else if (code == 10) { - @SuppressWarnings("unused") - int unknown = buffer.getShort() & 0xFFFF; + buffer.getShort();// & 0xFFFF; } else if (code == 11) { def.setStackable(true); } else if (code == 12) { - def.setValue(buffer.getInt()); + buffer.getInt(); // model height } else if (code == 16) { def.setMembersOnly(true); } else if (code == 23) { - @SuppressWarnings("unused") - int unknownShort = buffer.getShort() & 0xFFFF; - @SuppressWarnings("unused") - int unknownByte = buffer.get(); + buffer.getShort(); // & 0xFFFF; //primaryMaleEquipModelId + buffer.get(); // maleEquipYTranslation } else if (code == 24) { - @SuppressWarnings("unused") - int unknownShort = buffer.getShort() & 0xFFFF; + buffer.getShort(); // & 0xFFFF; // secondaryMaleEquipModelId } else if (code == 25) { - @SuppressWarnings("unused") - int unknownShort = buffer.getShort() & 0xFFFF; - @SuppressWarnings("unused") - int unknownByte = buffer.get(); + buffer.getShort(); // & 0xFFFF; // primaryFemaleEquipModelId + buffer.get(); // femaleEquipYTranslation } else if (code == 26) { - @SuppressWarnings("unused") - int unknownShort = buffer.getShort() & 0xFFFF; + buffer.getShort(); // & 0xFFFF; // secondaryFemaleEquipModelId } else if (code >= 30 && code < 35) { String str = ByteBufferUtil.readString(buffer); if (str.equalsIgnoreCase("hidden")) { @@ -125,34 +119,25 @@ public final class ItemDefinitionParser { String str = ByteBufferUtil.readString(buffer); def.setInventoryAction(code - 35, str); } else if (code == 40) { - int colorCount = buffer.get() & 0xFF; - for (int i = 0; i < colorCount; i++) { - @SuppressWarnings("unused") - int oldColor = buffer.getShort() & 0xFFFF; - @SuppressWarnings("unused") - int newColor = buffer.getShort() & 0xFFFF; + int colourCount = buffer.get() & 0xFF; + for (int i = 0; i < colourCount; i++) { + buffer.getShort(); // & 0xFFFF; // original colour + buffer.getShort(); // & 0xFFFF; // replacement colour } } else if (code == 78) { - @SuppressWarnings("unused") - int unknown = buffer.getShort() & 0xFFFF; + buffer.getShort(); // & 0xFFFF; // tertiaryMaleEquipModelId } else if (code == 79) { - @SuppressWarnings("unused") - int unknown = buffer.getShort() & 0xFFFF; + buffer.getShort(); // & 0xFFFF; // tertiaryFemaleEquipModelId } else if (code == 90) { - @SuppressWarnings("unused") - int unknown = buffer.getShort() & 0xFFFF; + buffer.getShort(); // & 0xFFFF; // primaryMaleHeadPiece } else if (code == 91) { - @SuppressWarnings("unused") - int unknown = buffer.getShort() & 0xFFFF; + buffer.getShort(); // & 0xFFFF; // primaryFemaleHeadPiece } else if (code == 92) { - @SuppressWarnings("unused") - int unknown = buffer.getShort() & 0xFFFF; + buffer.getShort(); // & 0xFFFF; // secondaryMaleHeadPiece } else if (code == 93) { - @SuppressWarnings("unused") - int unknown = buffer.getShort() & 0xFFFF; + buffer.getShort(); // & 0xFFFF; // secondaryFemaleHeadPiece } else if (code == 95) { - @SuppressWarnings("unused") - int unknown = buffer.getShort() & 0xFFFF; + buffer.getShort(); // & 0xFFFF; // spriteCameraYaw } else if (code == 97) { int noteInfoId = buffer.getShort() & 0xFFFF; def.setNoteInfoId(noteInfoId); @@ -160,25 +145,20 @@ public final class ItemDefinitionParser { int noteGraphicId = buffer.getShort() & 0xFFFF; def.setNoteGraphicId(noteGraphicId); } else if (code >= 100 && code < 110) { - @SuppressWarnings("unused") - int stackId = buffer.getShort() & 0xFFFF; - @SuppressWarnings("unused") - int stackAmount = buffer.getShort() & 0xFFFF; + buffer.getShort(); // & 0xFFFF; // stack id + buffer.getShort(); // & 0xFFFF; // stack size } else if (code == 110) { - @SuppressWarnings("unused") - int unknown = buffer.getShort() & 0xFFFF; + buffer.getShort(); // & 0xFFFF; // groundScaleX } else if (code == 111) { - @SuppressWarnings("unused") - int unknown = buffer.getShort() & 0xFFFF; + buffer.getShort(); // & 0xFFFF; // groundScaleY } else if (code == 112) { - @SuppressWarnings("unused") - int unknown = buffer.getShort() & 0xFFFF; + buffer.getShort(); // & 0xFFFF; // groundScaleZ + } else if (code == 113) { + buffer.get(); // light ambiance } else if (code == 114) { - @SuppressWarnings("unused") - int unknown = buffer.getShort() * 5; + buffer.getShort(); // * 5; // light diffusion } else if (code == 115) { - @SuppressWarnings("unused") - int team = buffer.get() & 0xFF; + buffer.get(); // & 0xFF; // team } } } diff --git a/src/org/apollo/game/event/handler/chain/EventHandlerChain.java b/src/org/apollo/game/event/handler/chain/EventHandlerChain.java index da085098..12b6a675 100644 --- a/src/org/apollo/game/event/handler/chain/EventHandlerChain.java +++ b/src/org/apollo/game/event/handler/chain/EventHandlerChain.java @@ -21,6 +21,7 @@ public final class EventHandlerChain { * Creates the event handler chain. * @param handlers The handlers. */ + @SafeVarargs public EventHandlerChain(EventHandler... handlers) { this.handlers = handlers; } diff --git a/src/org/apollo/game/event/handler/impl/EquipEventHandler.java b/src/org/apollo/game/event/handler/impl/EquipEventHandler.java index 42915dca..3fe0711a 100644 --- a/src/org/apollo/game/event/handler/impl/EquipEventHandler.java +++ b/src/org/apollo/game/event/handler/impl/EquipEventHandler.java @@ -77,16 +77,12 @@ public final class EquipEventHandler extends EventHandler { // TODO: put all this into another method somewhere // check if there is enough space for a two handed weapon - if (equipDef.isTwoHanded()) { - Item currentShield = equipment.get(EquipmentConstants.SHIELD); - if (currentShield != null) { - if (inventory.freeSlots() < 1) { - inventory.forceCapacityExceeded(); - ctx.breakHandlerChain(); - return; - } - } - } + if (equipDef.isTwoHanded()) { + if(equipment.get(EquipmentConstants.SHIELD) != null){ + Item shield = equipment.reset(EquipmentConstants.SHIELD); + inventory.add(shield); + } + } // check if a shield is being added with a two handed weapon boolean removeWeapon = false; diff --git a/src/org/apollo/game/event/handler/impl/RemoveEventHandler.java b/src/org/apollo/game/event/handler/impl/RemoveEventHandler.java index 5cd1c168..a5482aae 100644 --- a/src/org/apollo/game/event/handler/impl/RemoveEventHandler.java +++ b/src/org/apollo/game/event/handler/impl/RemoveEventHandler.java @@ -10,16 +10,29 @@ import org.apollo.game.model.inv.SynchronizationInventoryListener; /** * An event handler which removes equipped items. + * * @author Graham */ public final class RemoveEventHandler extends EventHandler { @Override - public void handle(EventHandlerContext ctx, Player player, ItemActionEvent event) { - if (event.getOption() == 1 && event.getInterfaceId() == SynchronizationInventoryListener.EQUIPMENT_ID) { + public void handle(EventHandlerContext ctx, Player player, + ItemActionEvent event) { + + if (event.getOption() == 1 + && event.getInterfaceId() == SynchronizationInventoryListener.EQUIPMENT_ID) { Inventory inventory = player.getInventory(); Inventory equipment = player.getEquipment(); + if (inventory.freeSlots() < 1) { // TODO what if the item is + // stackable and the player has + // the item in his inventory + // already. + inventory.forceCapacityExceeded(); + ctx.breakHandlerChain(); + return; + } + int slot = event.getSlot(); if (slot < 0 || slot >= equipment.capacity()) { ctx.breakHandlerChain(); @@ -39,10 +52,11 @@ public final class RemoveEventHandler extends EventHandler { try { equipment.set(slot, null); - Item tmp = inventory.add(item); - if (tmp != null) { + Item copy = item; + inventory.add(item.getId(), item.getAmount()); + if (copy != null) { removed = false; - equipment.set(slot, tmp); + equipment.set(slot, copy); } } finally { inventory.startFiringEvents(); @@ -50,12 +64,13 @@ public final class RemoveEventHandler extends EventHandler { } if (removed) { - inventory.forceRefresh(); // TODO find out the specific slot that got used? - equipment.forceRefresh(slot); + inventory.forceRefresh(); // TODO find out the specific slot + // that got used? + equipment.forceRefresh(); } else { inventory.forceCapacityExceeded(); } } } -} +} \ No newline at end of file diff --git a/src/org/apollo/game/model/SkillSet.java b/src/org/apollo/game/model/SkillSet.java index e3063eab..f02c88f8 100644 --- a/src/org/apollo/game/model/SkillSet.java +++ b/src/org/apollo/game/model/SkillSet.java @@ -7,6 +7,7 @@ import org.apollo.game.model.skill.SkillListener; /** * Represents the set of the player's skills. + * * @author Graham */ public final class SkillSet { @@ -45,6 +46,7 @@ public final class SkillSet { /** * Gets the number of skills. + * * @return The number of skills. */ public int size() { @@ -67,9 +69,12 @@ public final class SkillSet { /** * Gets a skill by its id. - * @param id The id. + * + * @param id + * The id. * @return The skill. - * @throws IndexOutOfBoundsException if the id is out of bounds. + * @throws IndexOutOfBoundsException + * if the id is out of bounds. */ public Skill getSkill(int id) { checkBounds(id); @@ -78,8 +83,11 @@ public final class SkillSet { /** * Adds experience to the specified skill. - * @param id The skill id. - * @param experience The amount of experience. + * + * @param id + * The skill id. + * @param experience + * The amount of experience. */ public void addExperience(int id, double experience) { checkBounds(id); @@ -110,11 +118,12 @@ public final class SkillSet { /** * Gets the total level for this skill set. + * * @return The total level. */ public int getTotalLevel() { int total = 0; - for(int i = 0; i < skills.length; i++) { + for (int i = 0; i < skills.length; i++) { total += skills[i].getMaximumLevel(); } return total; @@ -122,6 +131,12 @@ public final class SkillSet { /** * Gets the combat level for this skill set. + * + * @return The combat level. + */ + /** + * Gets the combat level for this skill set. + * * @return The combat level. */ public int getCombatLevel() { @@ -133,26 +148,22 @@ public final class SkillSet { int ranged = skills[Skill.RANGED].getMaximumLevel(); int magic = skills[Skill.MAGIC].getMaximumLevel(); - int combat = (int) (((defence + hitpoints + prayer / 2) * 0.235) + 1); + double combatLevel = (defence + hitpoints + Math.floor(prayer / 2)) * 0.25; double melee = (attack + strength) * 0.325; - double ranger = Math.floor(ranged * 1.5) * 0.325; - double mage = Math.floor(magic * 1.5) * 0.325; - if (melee >= ranger && melee >= mage) { - combat += melee; - } else if (ranger >= melee && ranger >= mage) { - combat += ranger; - } else if (mage >= melee && mage >= ranger) { - combat += mage; - } + double range = ranged * 0.4875; - return combat < 126 ? combat : 126; + double mage = magic * 0.4875; + + return (int) (combatLevel + Math.max(melee, Math.max(range, mage))); } /** * Gets the minimum experience required for the specified level. - * @param level The level. + * + * @param level + * The level. * @return The minimum experience. */ public static double getExperienceForLevel(int level) { @@ -170,7 +181,9 @@ public final class SkillSet { /** * Gets the minimum level to get the specified experience. - * @param experience The experience. + * + * @param experience + * The experience. * @return The minimum level. */ public static int getLevelForExperience(double experience) { @@ -209,9 +222,13 @@ public final class SkillSet { /** * Sets a skill. - * @param id The id. - * @param skill The skill. - * @throws IndexOutOfBoundsException if the id is out of bounds. + * + * @param id + * The id. + * @param skill + * The skill. + * @throws IndexOutOfBoundsException + * if the id is out of bounds. */ public void setSkill(int id, Skill skill) { checkBounds(id); @@ -221,8 +238,11 @@ public final class SkillSet { /** * Checks the bounds of the id. - * @param id The id. - * @throws IndexOutOfBoundsException if the id is out of bounds. + * + * @param id + * The id. + * @throws IndexOutOfBoundsException + * if the id is out of bounds. */ private void checkBounds(int id) { if (id < 0 || id >= skills.length) { @@ -232,8 +252,11 @@ public final class SkillSet { /** * Notifies listeners that a skill has been levelled up. - * @param id The skill's id. - * @throws IndexOutOfBoundsException if the id is out of bounds. + * + * @param id + * The skill's id. + * @throws IndexOutOfBoundsException + * if the id is out of bounds. */ private void notifyLevelledUp(int id) { checkBounds(id); @@ -246,8 +269,11 @@ public final class SkillSet { /** * Notifies listeners that a skill has been updated. - * @param id The skill's id. - * @throws IndexOutOfBoundsException if the id is out of bounds. + * + * @param id + * The skill's id. + * @throws IndexOutOfBoundsException + * if the id is out of bounds. */ private void notifySkillUpdated(int id) { checkBounds(id); @@ -292,7 +318,9 @@ public final class SkillSet { /** * Adds a listener. - * @param listener The listener to add. + * + * @param listener + * The listener to add. */ public void addListener(SkillListener listener) { listeners.add(listener); @@ -300,7 +328,9 @@ public final class SkillSet { /** * Removes a listener. - * @param listener The listener to remove. + * + * @param listener + * The listener to remove. */ public void removeListener(SkillListener listener) { listeners.remove(listener); diff --git a/src/org/apollo/game/model/WalkingQueue.java b/src/org/apollo/game/model/WalkingQueue.java index f748dea9..d9416b64 100644 --- a/src/org/apollo/game/model/WalkingQueue.java +++ b/src/org/apollo/game/model/WalkingQueue.java @@ -6,6 +6,7 @@ import java.util.Queue; /** * A queue of {@link Direction}s which a {@link Character} will follow. + * * @author Graham */ public final class WalkingQueue { @@ -18,6 +19,7 @@ public final class WalkingQueue { /** * Represents a single point in the queue. + * * @author Graham */ private static final class Point { @@ -34,8 +36,11 @@ public final class WalkingQueue { /** * Creates a point. - * @param position The position. - * @param direction The direction. + * + * @param position + * The position. + * @param direction + * The direction. */ public Point(Position position, Direction direction) { this.position = position; @@ -44,7 +49,8 @@ public final class WalkingQueue { @Override public String toString() { - return Point.class.getName() + " [direction=" + direction + ", position=" + position + "]"; + return Point.class.getName() + " [direction=" + direction + + ", position=" + position + "]"; } } @@ -71,7 +77,9 @@ public final class WalkingQueue { /** * Creates a walking queue for the specified character. - * @param character The character. + * + * @param character + * The character. */ public WalkingQueue(Character character) { this.character = character; @@ -106,7 +114,9 @@ public final class WalkingQueue { /** * Sets the running queue flag. - * @param running The running queue flag. + * + * @param running + * The running queue flag. */ public void setRunningQueue(boolean running) { this.runningQueue = running; @@ -115,9 +125,11 @@ public final class WalkingQueue { /** * Adds the first step to the queue, attempting to connect the server and * client position by looking at the previous queue. - * @param clientConnectionPosition The first step. + * + * @param clientConnectionPosition + * The first step. * @return {@code true} if the queues could be connected correctly, - * {@code false} if not. + * {@code false} if not. */ public boolean addFirstStep(Position clientConnectionPosition) { Position serverPosition = character.getPosition(); @@ -163,7 +175,9 @@ public final class WalkingQueue { /** * Adds a step to the queue. - * @param step The step to add. + * + * @param step + * The step to add. */ public void addStep(Position step) { Point last = getLast(); @@ -195,8 +209,11 @@ public final class WalkingQueue { /** * Adds a step. - * @param x The x coordinate of this step. - * @param y The y coordinate of this step. + * + * @param x + * The x coordinate of this step. + * @param y + * The y coordinate of this step. */ private void addStep(int x, int y) { if (points.size() >= MAXIMUM_SIZE) { @@ -211,7 +228,8 @@ public final class WalkingQueue { Direction direction = Direction.fromDeltas(deltaX, deltaY); if (direction != Direction.NONE) { - Point p = new Point(new Position(x, y), direction); + Point p = new Point(new Position(x, y, character.getPosition() + .getHeight()), direction); points.add(p); oldPoints.add(p); } @@ -219,6 +237,7 @@ public final class WalkingQueue { /** * Gets the last point. + * * @return The last point. */ private Point getLast() { @@ -239,6 +258,7 @@ public final class WalkingQueue { /** * Gets the size of the queue. + * * @return The size of the queue. */ public int size() { diff --git a/src/org/apollo/game/model/obj/StaticObject.java b/src/org/apollo/game/model/obj/StaticObject.java index fc4f48c3..4d5086d3 100644 --- a/src/org/apollo/game/model/obj/StaticObject.java +++ b/src/org/apollo/game/model/obj/StaticObject.java @@ -4,6 +4,7 @@ import org.apollo.game.model.def.StaticObjectDefinition; /** * Represents a static object in the game world. + * * @author Graham */ public final class StaticObject { @@ -11,14 +12,25 @@ public final class StaticObject { /** * The object definition. */ - private final StaticObjectDefinition def; + private final StaticObjectDefinition definition; /** * Creates the game object. - * @param def The object's definition. + * + * @param definition + * The object's definition. */ - public StaticObject(StaticObjectDefinition def) { - this.def = def; + public StaticObject(StaticObjectDefinition definition) { + this.definition = definition; } -} + /** + * Gets the object's definition. + * + * @return The definition. + */ + public StaticObjectDefinition getDefinition() { + return definition; + } + +} \ No newline at end of file diff --git a/src/org/apollo/game/sync/task/PlayerSynchronizationTask.java b/src/org/apollo/game/sync/task/PlayerSynchronizationTask.java index 770b9dd5..a918058c 100644 --- a/src/org/apollo/game/sync/task/PlayerSynchronizationTask.java +++ b/src/org/apollo/game/sync/task/PlayerSynchronizationTask.java @@ -20,17 +20,17 @@ import org.apollo.game.sync.seg.TeleportSegment; import org.apollo.util.CharacterRepository; /** - * A {@link SynchronizationTask} which synchronizes the specified - * {@link Player}. + * A {@link SynchronizationTask} which synchronizes the specified {@link Player} + * . + * * @author Graham */ public final class PlayerSynchronizationTask extends SynchronizationTask { /** - * 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. + * 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. */ private static final int NEW_PLAYERS_PER_CYCLE = 20; @@ -41,7 +41,9 @@ public final class PlayerSynchronizationTask extends SynchronizationTask { /** * Creates the {@link PlayerSynchronizationTask} for the specified player. - * @param player The player. + * + * @param player + * The player. */ public PlayerSynchronizationTask(Player player) { this.player = player; @@ -59,7 +61,7 @@ public final class PlayerSynchronizationTask extends SynchronizationTask { blockSet.remove(ChatBlock.class); } - if (player.isTeleporting()) { + if (player.isTeleporting() || player.hasRegionChanged()) { segment = new TeleportSegment(blockSet, player.getPosition()); } else { segment = new MovementSegment(blockSet, player.getDirections()); @@ -69,20 +71,25 @@ public final class PlayerSynchronizationTask extends SynchronizationTask { int oldLocalPlayers = localPlayers.size(); List segments = new ArrayList(); - for (Iterator it = localPlayers.iterator(); it.hasNext(); ) { + for (Iterator it = localPlayers.iterator(); it.hasNext();) { Player p = it.next(); - if (!p.isActive() || p.isTeleporting() || p.getPosition().getLongestDelta(player.getPosition()) > player.getViewingDistance()) { + if (!p.isActive() + || p.isTeleporting() + || p.getPosition().getLongestDelta(player.getPosition()) > player + .getViewingDistance()) { it.remove(); segments.add(new RemoveCharacterSegment()); } else { - segments.add(new MovementSegment(p.getBlockSet(), p.getDirections())); + segments.add(new MovementSegment(p.getBlockSet(), p + .getDirections())); } } int added = 0; - CharacterRepository repository = World.getWorld().getPlayerRepository(); - for (Iterator it = repository.iterator(); it.hasNext(); ) { + CharacterRepository repository = World.getWorld() + .getPlayerRepository(); + for (Iterator it = repository.iterator(); it.hasNext();) { Player p = it.next(); if (localPlayers.size() >= 255) { player.flagExcessivePlayers(); @@ -90,8 +97,12 @@ public final class PlayerSynchronizationTask extends SynchronizationTask { } else if (added >= NEW_PLAYERS_PER_CYCLE) { break; } - // we do not check p.isActive() here, since if they are active they must be in the repository - if (p != player && p.getPosition().isWithinDistance(player.getPosition(), player.getViewingDistance()) && !localPlayers.contains(p)) { + // we do not check p.isActive() here, since if they are active they + // must be in the repository + if (p != player + && p.getPosition().isWithinDistance(player.getPosition(), + player.getViewingDistance()) + && !localPlayers.contains(p)) { localPlayers.add(p); added++; @@ -102,11 +113,14 @@ public final class PlayerSynchronizationTask extends SynchronizationTask { blockSet.add(SynchronizationBlock.createAppearanceBlock(p)); } - segments.add(new AddCharacterSegment(blockSet, p.getIndex(), p.getPosition())); + segments.add(new AddCharacterSegment(blockSet, p.getIndex(), p + .getPosition())); } } - PlayerSynchronizationEvent event = new PlayerSynchronizationEvent(lastKnownRegion, player.getPosition(), regionChanged, segment, oldLocalPlayers, segments); + PlayerSynchronizationEvent event = new PlayerSynchronizationEvent( + lastKnownRegion, player.getPosition(), regionChanged, segment, + oldLocalPlayers, segments); player.send(event); } diff --git a/src/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java b/src/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java index 7e1468fd..8f134cc5 100644 --- a/src/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java +++ b/src/org/apollo/game/sync/task/PrePlayerSynchronizationTask.java @@ -38,7 +38,6 @@ public final class PrePlayerSynchronizationTask extends SynchronizationTask { } if (!player.hasLastKnownRegion() || isRegionUpdateRequired()) { - player.setTeleporting(true); player.setRegionChanged(true); Position position = player.getPosition(); diff --git a/src/org/apollo/io/EventHandlerChainParser.java b/src/org/apollo/io/EventHandlerChainParser.java index 2fa33bf5..80cba83a 100644 --- a/src/org/apollo/io/EventHandlerChainParser.java +++ b/src/org/apollo/io/EventHandlerChainParser.java @@ -18,6 +18,7 @@ import org.xml.sax.SAXException; /** * A class which parses the {@code events.xml} file to produce * {@link EventHandlerChainGroup}s. + * * @author Graham */ public final class EventHandlerChainParser { @@ -34,8 +35,11 @@ public final class EventHandlerChainParser { /** * Creates the event chain parser. - * @param is The source {@link InputStream}. - * @throws SAXException if a SAX error occurs. + * + * @param is + * The source {@link InputStream}. + * @throws SAXException + * if a SAX error occurs. */ public EventHandlerChainParser(InputStream is) throws SAXException { this.parser = new XmlParser(); @@ -44,15 +48,23 @@ public final class EventHandlerChainParser { /** * Parses the XML and produces a group of {@link EventHandlerChain}s. - * @throws IOException if an I/O error occurs. - * @throws SAXException if a SAX error occurs. - * @throws ClassNotFoundException if a class was not found. - * @throws IllegalAccessException if a class was accessed illegally. - * @throws InstantiationException if a class could not be instantiated. + * + * @throws IOException + * if an I/O error occurs. + * @throws SAXException + * if a SAX error occurs. + * @throws ClassNotFoundException + * if a class was not found. + * @throws IllegalAccessException + * if a class was accessed illegally. + * @throws InstantiationException + * if a class could not be instantiated. * @return An {@link EventHandlerChainGroup}. */ @SuppressWarnings("unchecked") - public EventHandlerChainGroup parse() throws IOException, SAXException, ClassNotFoundException, InstantiationException, IllegalAccessException { + public EventHandlerChainGroup parse() throws IOException, SAXException, + ClassNotFoundException, InstantiationException, + IllegalAccessException { XmlNode rootNode = parser.parse(is); if (!rootNode.getName().equals("events")) { throw new IOException("root node name is not 'events'"); @@ -62,16 +74,19 @@ public final class EventHandlerChainParser { for (XmlNode eventNode : rootNode) { if (!eventNode.getName().equals("event")) { - throw new IOException("only expected nodes named 'event' beneath the root node"); + throw new IOException( + "only expected nodes named 'event' beneath the root node"); } XmlNode typeNode = eventNode.getChild("type"); if (typeNode == null) { - throw new IOException("no node named 'type' beneath current event node"); + throw new IOException( + "no node named 'type' beneath current event node"); } XmlNode chainNode = eventNode.getChild("chain"); if (chainNode == null) { - throw new IOException("no node named 'chain' beneath current event node"); + throw new IOException( + "no node named 'chain' beneath current event node"); } String eventClassName = typeNode.getValue(); @@ -79,12 +94,14 @@ public final class EventHandlerChainParser { throw new IOException("type node must have a value"); } - Class eventClass = (Class) Class.forName(eventClassName); + Class eventClass = (Class) Class + .forName(eventClassName); List> handlers = new ArrayList>(); for (XmlNode handlerNode : chainNode) { if (!handlerNode.getName().equals("handler")) { - throw new IOException("only expected nodes named 'handler' beneath the root node"); + throw new IOException( + "only expected nodes named 'handler' beneath the root node"); } String handlerClassName = handlerNode.getValue(); @@ -92,12 +109,15 @@ public final class EventHandlerChainParser { throw new IOException("handler node must have a value"); } - Class> handlerClass = (Class>) Class.forName(handlerClassName); + Class> handlerClass = (Class>) Class + .forName(handlerClassName); EventHandler handler = handlerClass.newInstance(); handlers.add(handler); } - EventHandler[] handlersArray = handlers.toArray(new EventHandler[handlers.size()]); + EventHandler[] handlersArray = handlers + .toArray(new EventHandler[handlers.size()]); + @SuppressWarnings("rawtypes") EventHandlerChain chain = new EventHandlerChain(handlersArray); chains.put(eventClass, chain); @@ -106,4 +126,4 @@ public final class EventHandlerChainParser { return new EventHandlerChainGroup(chains); } -} +} \ No newline at end of file diff --git a/src/org/apollo/net/release/r317/ChatEventDecoder.java b/src/org/apollo/net/release/r317/ChatEventDecoder.java index 072ae517..dcf764de 100644 --- a/src/org/apollo/net/release/r317/ChatEventDecoder.java +++ b/src/org/apollo/net/release/r317/ChatEventDecoder.java @@ -10,6 +10,7 @@ import org.apollo.util.TextUtil; /** * An {@link EventDecoder} for the {@link ChatEvent}. + * * @author Graham */ public final class ChatEventDecoder extends EventDecoder { @@ -18,8 +19,10 @@ public final class ChatEventDecoder extends EventDecoder { public ChatEvent decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int effects = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); - int color = (int) reader.getUnsigned(DataType.BYTE, DataTransformation.ADD); + 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]; @@ -30,9 +33,10 @@ public final class ChatEventDecoder extends EventDecoder { uncompressed = TextUtil.capitalize(uncompressed); byte[] recompressed = new byte[length]; - TextUtil.compress(uncompressed, recompressed); // in case invalid data gets sent, this effectively verifies it + TextUtil.compress(uncompressed, recompressed); + // in case invalid data gets sent, this effectively verifies it return new ChatEvent(uncompressed, recompressed, color, effects); } -} +} \ No newline at end of file diff --git a/src/org/apollo/net/release/r317/FifthItemActionEventDecoder.java b/src/org/apollo/net/release/r317/FifthItemActionEventDecoder.java index 54b89dc7..2f2cdbf9 100644 --- a/src/org/apollo/net/release/r317/FifthItemActionEventDecoder.java +++ b/src/org/apollo/net/release/r317/FifthItemActionEventDecoder.java @@ -1,7 +1,6 @@ package org.apollo.net.release.r317; import org.apollo.game.event.impl.FifthItemActionEvent; -import org.apollo.game.event.impl.FourthItemActionEvent; import org.apollo.net.codec.game.DataOrder; import org.apollo.net.codec.game.DataTransformation; import org.apollo.net.codec.game.DataType; @@ -10,18 +9,21 @@ import org.apollo.net.codec.game.GamePacketReader; import org.apollo.net.release.EventDecoder; /** - * An {@link EventDecoder} for the {@link FourthItemActionEvent}. + * An {@link EventDecoder} for the {@link FifthItemActionEvent}. + * * @author Graham */ -public final class FifthItemActionEventDecoder extends EventDecoder { +public final class FifthItemActionEventDecoder extends + EventDecoder { @Override public FifthItemActionEvent decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int interfaceId = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + 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 FifthItemActionEvent(interfaceId, id, slot); } -} +} \ No newline at end of file diff --git a/src/org/apollo/net/release/r317/FirstObjectActionEventDecoder.java b/src/org/apollo/net/release/r317/FirstObjectActionEventDecoder.java index 28b82480..662ff364 100644 --- a/src/org/apollo/net/release/r317/FirstObjectActionEventDecoder.java +++ b/src/org/apollo/net/release/r317/FirstObjectActionEventDecoder.java @@ -11,17 +11,20 @@ import org.apollo.net.release.EventDecoder; /** * An {@link EventDecoder} for the {@link FirstObjectActionEvent}. + * * @author Graham */ -public final class FirstObjectActionEventDecoder extends EventDecoder { +public final class FirstObjectActionEventDecoder extends + EventDecoder { - @Override public FirstObjectActionEvent decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); - int y = (int) reader.getUnsigned(DataType.SHORT); - int id = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + 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 FirstObjectActionEvent(id, new Position(x, y)); } -} +} \ No newline at end of file diff --git a/src/org/apollo/net/release/r317/PlayerSynchronizationEventEncoder.java b/src/org/apollo/net/release/r317/PlayerSynchronizationEventEncoder.java index 401e35b9..4684c194 100644 --- a/src/org/apollo/net/release/r317/PlayerSynchronizationEventEncoder.java +++ b/src/org/apollo/net/release/r317/PlayerSynchronizationEventEncoder.java @@ -32,13 +32,16 @@ import org.apollo.net.release.EventEncoder; /** * An {@link EventEncoder} for the {@link PlayerSynchronizationEvent}. + * * @author Graham */ -public final class PlayerSynchronizationEventEncoder extends EventEncoder { +public final class PlayerSynchronizationEventEncoder extends + EventEncoder { @Override public GamePacket encode(PlayerSynchronizationEvent event) { - GamePacketBuilder builder = new GamePacketBuilder(81, PacketType.VARIABLE_SHORT); + GamePacketBuilder builder = new GamePacketBuilder(81, + PacketType.VARIABLE_SHORT); builder.switchToBitAccess(); GamePacketBuilder blockBuilder = new GamePacketBuilder(); @@ -53,7 +56,8 @@ public final class PlayerSynchronizationEventEncoder extends EventEncoder 0; Position player = event.getPosition(); Position other = seg.getPosition(); @@ -100,11 +111,16 @@ public final class PlayerSynchronizationEventEncoder extends EventEncoder 0; if (seg.getType() == SegmentType.TELEPORT) { Position pos = ((TeleportSegment) seg).getDestination(); @@ -140,10 +156,14 @@ public final class PlayerSynchronizationEventEncoder extends EventEncoder 0) { int mask = 0; @@ -152,7 +172,7 @@ public final class PlayerSynchronizationEventEncoder extends EventEncoder> 16) & 0x0000FFFF) | (graphic.getDelay() & 0xFFFF)); + blockBuilder.put(DataType.INT, + (graphic.getHeight() << 16) | (graphic.getDelay() & 0xFFFF)); } /** * Puts an animation block into the specified builder. - * @param block The block. - * @param blockBuilder The builder. + * + * @param block + * The block. + * @param blockBuilder + * The builder. */ - private void putAnimationBlock(AnimationBlock block, GamePacketBuilder blockBuilder) { + private void putAnimationBlock(AnimationBlock block, + GamePacketBuilder blockBuilder) { Animation animation = block.getAnimation(); blockBuilder.put(DataType.SHORT, DataOrder.LITTLE, animation.getId()); - blockBuilder.put(DataType.BYTE, DataTransformation.NEGATE, animation.getDelay()); + blockBuilder.put(DataType.BYTE, DataTransformation.NEGATE, + animation.getDelay()); } /** * Puts a chat block into the specified builder. - * @param block The block. - * @param blockBuilder The builder. + * + * @param block + * The block. + * @param blockBuilder + * The builder. */ private void putChatBlock(ChatBlock block, GamePacketBuilder blockBuilder) { byte[] bytes = block.getCompressedMessage(); - blockBuilder.put(DataType.SHORT, DataOrder.LITTLE, (block.getTextColor() << 8) | block.getTextEffects()); + blockBuilder.put(DataType.SHORT, DataOrder.LITTLE, + (block.getTextColor() << 8) | block.getTextEffects()); blockBuilder.put(DataType.BYTE, block.getPrivilegeLevel().toInteger()); - blockBuilder.put(DataType.BYTE, DataTransformation.NEGATE, bytes.length); + blockBuilder + .put(DataType.BYTE, DataTransformation.NEGATE, bytes.length); blockBuilder.putBytesReverse(bytes); } /** * Puts an appearance block into the specified builder. - * @param block The block. - * @param blockBuilder The builder. + * + * @param block + * The block. + * @param blockBuilder + * The builder. */ - private void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder blockBuilder) { + private void putAppearanceBlock(AppearanceBlock block, + GamePacketBuilder blockBuilder) { Appearance appearance = block.getAppearance(); GamePacketBuilder playerProperties = new GamePacketBuilder(); @@ -323,7 +370,8 @@ public final class PlayerSynchronizationEventEncoder extends EventEncoder { +public final class SecondItemActionEventDecoder extends + EventDecoder { @Override public SecondItemActionEvent 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, DataTransformation.ADD); + 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 SecondItemActionEvent(interfaceId, id, slot); } -} +} \ No newline at end of file diff --git a/src/org/apollo/net/release/r317/SetInterfaceTextEventEncoder.java b/src/org/apollo/net/release/r317/SetInterfaceTextEventEncoder.java new file mode 100644 index 00000000..148035ae --- /dev/null +++ b/src/org/apollo/net/release/r317/SetInterfaceTextEventEncoder.java @@ -0,0 +1,30 @@ +package org.apollo.net.release.r317; + +import org.apollo.game.event.impl.SetInterfaceTextEvent; +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.EventEncoder; + +/** + * An {@link EventEncoder} for the {@link SetInterfaceTextEvent}. + * + * @author The Wanderer + */ +public final class SetInterfaceTextEventEncoder extends + EventEncoder { + + @Override + public GamePacket encode(SetInterfaceTextEvent event) { + GamePacketBuilder builder = new GamePacketBuilder(126, + PacketType.VARIABLE_SHORT); + builder.putString(event.getText()); + builder.put(DataType.SHORT, DataTransformation.ADD, + event.getInterfaceId()); + + return builder.toGamePacket(); + } + +} \ No newline at end of file diff --git a/src/org/apollo/net/release/r317/SwitchItemEventDecoder.java b/src/org/apollo/net/release/r317/SwitchItemEventDecoder.java index 0679181e..ca9f5513 100644 --- a/src/org/apollo/net/release/r317/SwitchItemEventDecoder.java +++ b/src/org/apollo/net/release/r317/SwitchItemEventDecoder.java @@ -10,6 +10,7 @@ import org.apollo.net.release.EventDecoder; /** * An {@link EventDecoder} for the {@link SwitchItemEvent}. + * * @author Graham */ public final class SwitchItemEventDecoder extends EventDecoder { @@ -17,10 +18,14 @@ public final class SwitchItemEventDecoder extends EventDecoder @Override public SwitchItemEvent 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, DataTransformation.ADD); + 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 SwitchItemEvent(interfaceId, inserting, oldSlot, newSlot); } diff --git a/src/org/apollo/net/release/r317/ThirdItemActionEventDecoder.java b/src/org/apollo/net/release/r317/ThirdItemActionEventDecoder.java index 8b9e783a..72ad45ec 100644 --- a/src/org/apollo/net/release/r317/ThirdItemActionEventDecoder.java +++ b/src/org/apollo/net/release/r317/ThirdItemActionEventDecoder.java @@ -10,17 +10,22 @@ import org.apollo.net.release.EventDecoder; /** * An {@link EventDecoder} for the {@link ThirdItemActionEvent}. + * * @author Graham */ -public final class ThirdItemActionEventDecoder extends EventDecoder { +public final class ThirdItemActionEventDecoder extends + EventDecoder { @Override public ThirdItemActionEvent 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, DataTransformation.ADD); - int slot = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); + 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 ThirdItemActionEvent(interfaceId, id, slot); } -} +} \ No newline at end of file diff --git a/src/org/apollo/net/release/r377/Release377.java b/src/org/apollo/net/release/r377/Release377.java index 282baa60..9998099c 100644 --- a/src/org/apollo/net/release/r377/Release377.java +++ b/src/org/apollo/net/release/r377/Release377.java @@ -19,6 +19,7 @@ import org.apollo.net.release.Release; /** * An implementation of {@link Release} for the 377 protocol. + * * @author Graham */ public final class Release377 extends Release { @@ -26,94 +27,33 @@ public final class Release377 extends Release { /** * The incoming packet lengths array. */ - public static final int[] PACKET_LENGTHS = new int[256]; - - /** - * Initialises the {@link #PACKET_LENGTHS} array. - * TODO make it like the 317 one. - */ - static { - PACKET_LENGTHS[1] = 12; - PACKET_LENGTHS[3] = 6; - PACKET_LENGTHS[4] = 6; - PACKET_LENGTHS[6] = 0; - PACKET_LENGTHS[8] = 2; - PACKET_LENGTHS[13] = 2; - PACKET_LENGTHS[19] = 4; - PACKET_LENGTHS[22] = 2; - PACKET_LENGTHS[24] = 6; - PACKET_LENGTHS[28] = -1; - PACKET_LENGTHS[31] = 4; - PACKET_LENGTHS[36] = 8; - PACKET_LENGTHS[40] = 0; - PACKET_LENGTHS[42] = 2; - PACKET_LENGTHS[45] = 2; - PACKET_LENGTHS[49] = -1; - PACKET_LENGTHS[50] = 6; - PACKET_LENGTHS[54] = 6; - PACKET_LENGTHS[55] = 6; - PACKET_LENGTHS[56] = -1; - PACKET_LENGTHS[57] = 8; - PACKET_LENGTHS[67] = 2; - PACKET_LENGTHS[71] = 6; - PACKET_LENGTHS[75] = 4; - PACKET_LENGTHS[77] = 6; - PACKET_LENGTHS[78] = 4; - PACKET_LENGTHS[79] = 2; - PACKET_LENGTHS[80] = 2; - PACKET_LENGTHS[83] = 8; - PACKET_LENGTHS[91] = 6; - PACKET_LENGTHS[95] = 4; - PACKET_LENGTHS[100] = 6; - PACKET_LENGTHS[104] = 4; - PACKET_LENGTHS[110] = 0; - PACKET_LENGTHS[112] = 2; - PACKET_LENGTHS[116] = 2; - PACKET_LENGTHS[119] = 1; - PACKET_LENGTHS[120] = 8; - PACKET_LENGTHS[123] = 7; - PACKET_LENGTHS[126] = 1; - PACKET_LENGTHS[136] = 6; - PACKET_LENGTHS[140] = 4; - PACKET_LENGTHS[141] = 8; - PACKET_LENGTHS[143] = 8; - PACKET_LENGTHS[152] = 12; - PACKET_LENGTHS[157] = 4; - PACKET_LENGTHS[158] = 6; - PACKET_LENGTHS[160] = 8; - PACKET_LENGTHS[161] = 6; - PACKET_LENGTHS[163] = 13; - PACKET_LENGTHS[165] = 1; - PACKET_LENGTHS[168] = 0; - PACKET_LENGTHS[171] = -1; - PACKET_LENGTHS[173] = 3; - PACKET_LENGTHS[176] = 3; - PACKET_LENGTHS[177] = 6; - PACKET_LENGTHS[181] = 6; - PACKET_LENGTHS[184] = 10; - PACKET_LENGTHS[187] = 1; - PACKET_LENGTHS[194] = 2; - PACKET_LENGTHS[197] = 4; - PACKET_LENGTHS[202] = 0; - PACKET_LENGTHS[203] = 6; - PACKET_LENGTHS[206] = 8; - PACKET_LENGTHS[210] = 8; - PACKET_LENGTHS[211] = 12; - PACKET_LENGTHS[213] = -1; - PACKET_LENGTHS[217] = 8; - PACKET_LENGTHS[222] = 3; - PACKET_LENGTHS[226] = 2; - PACKET_LENGTHS[227] = 9; - PACKET_LENGTHS[228] = 6; - PACKET_LENGTHS[230] = 6; - PACKET_LENGTHS[231] = 6; - PACKET_LENGTHS[233] = 2; - PACKET_LENGTHS[241] = 6; - PACKET_LENGTHS[244] = -1; - PACKET_LENGTHS[245] = 2; - PACKET_LENGTHS[247] = -1; - PACKET_LENGTHS[248] = 0; - } + 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. @@ -154,17 +94,22 @@ public final class Release377 extends Release { register(IdAssignmentEvent.class, new IdAssignmentEventEncoder()); register(RegionChangeEvent.class, new RegionChangeEventEncoder()); register(ServerMessageEvent.class, new ServerMessageEventEncoder()); - register(PlayerSynchronizationEvent.class, new PlayerSynchronizationEventEncoder()); + register(PlayerSynchronizationEvent.class, + new PlayerSynchronizationEventEncoder()); register(OpenInterfaceEvent.class, new OpenInterfaceEventEncoder()); register(CloseInterfaceEvent.class, new CloseInterfaceEventEncoder()); - register(SwitchTabInterfaceEvent.class, new SwitchTabInterfaceEventEncoder()); + register(SwitchTabInterfaceEvent.class, + new SwitchTabInterfaceEventEncoder()); register(LogoutEvent.class, new LogoutEventEncoder()); register(UpdateItemsEvent.class, new UpdateItemsEventEncoder()); - register(UpdateSlottedItemsEvent.class, new UpdateSlottedItemsEventEncoder()); + register(UpdateSlottedItemsEvent.class, + new UpdateSlottedItemsEventEncoder()); register(UpdateSkillEvent.class, new UpdateSkillEventEncoder()); - register(OpenInterfaceSidebarEvent.class, new OpenInterfaceSidebarEventEncoder()); + register(OpenInterfaceSidebarEvent.class, + new OpenInterfaceSidebarEventEncoder()); register(EnterAmountEvent.class, new EnterAmountEventEncoder()); - register(SetInterfaceTextEvent.class, new SetInterfaceTextEventEncoder()); + register(SetInterfaceTextEvent.class, + new SetInterfaceTextEventEncoder()); } } diff --git a/src/org/apollo/net/release/r377/ThirdObjectActionEventDecoder.java b/src/org/apollo/net/release/r377/ThirdObjectActionEventDecoder.java index dedd3cbb..2e4cbe67 100644 --- a/src/org/apollo/net/release/r377/ThirdObjectActionEventDecoder.java +++ b/src/org/apollo/net/release/r377/ThirdObjectActionEventDecoder.java @@ -11,16 +11,20 @@ import org.apollo.net.release.EventDecoder; /** * An {@link EventDecoder} for the {@link ThirdObjectActionEvent}. + * * @author Graham */ -public final class ThirdObjectActionEventDecoder extends EventDecoder { +public final class ThirdObjectActionEventDecoder extends + EventDecoder { @Override public ThirdObjectActionEvent decode(GamePacket packet) { GamePacketReader reader = new GamePacketReader(packet); - int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD); - int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE); - int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD); + 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 ThirdObjectActionEvent(id, new Position(x, y)); } diff --git a/src/org/apollo/tools/EquipmentConstants.java b/src/org/apollo/tools/EquipmentConstants.java index 51f74cd4..d457fdf1 100644 --- a/src/org/apollo/tools/EquipmentConstants.java +++ b/src/org/apollo/tools/EquipmentConstants.java @@ -2,6 +2,7 @@ package org.apollo.tools; /** * Contains equipment name constants. + * * @author Graham * @author Palidino76 */ @@ -10,75 +11,100 @@ public final class EquipmentConstants { /** * Capes. */ - public static final String[] CAPES = {"cape","Cape"}; + public static final String[] CAPES = { "cape", "Cape" }; /** * Hats. */ - public static final String[] HATS = {"helm","hood","coif","Coif","hat","partyhat","Hat","full helm (t)","full helm (g)","hat (t)","hat (g)","cav","boater","helmet","mask","Helm of neitiznot"}; + public static final String[] HATS = { "helm", "hood", "coif", "Coif", + "hat", "partyhat", "Hat", "full helm (t)", "full helm (g)", + "hat (t)", "hat (g)", "cav", "boater", "helmet", "mask", + "Helm of neitiznot" }; /** * Boots. */ - public static final String[] BOOTS = {"boots","Boots"}; + public static final String[] BOOTS = { "boots", "Boots" }; /** * Gloves. */ - public static final String[] GLOVES = {"gloves","gauntlets","Gloves","vambraces","vamb","bracers"}; + public static final String[] GLOVES = { "gloves", "gauntlets", "Gloves", + "vambraces", "vamb", "bracers" }; /** * Shields. */ - public static final String[] SHIELDS = {"kiteshield","sq shield","Toktz-ket","books","book","kiteshield (t)","kiteshield (g)","kiteshield(h)","defender","shield"}; + public static final String[] SHIELDS = { "kiteshield", "sq shield", + "Toktz-ket", "books", "book", "kiteshield (t)", "kiteshield (g)", + "kiteshield(h)", "defender", "shield" }; /** * Amulets. */ - public static final String[] AMULETS = {"amulet","necklace","Amulet of"}; + public static final String[] AMULETS = { "amulet", "necklace", "Amulet of" }; /** * Arrows. */ - public static final String[] ARROWS = {"arrow","arrows","arrow(p)","arrow(+)","arrow(s)","bolt","Bolt rack","Opal bolts","Dragon bolts"}; + public static final String[] ARROWS = { "arrow", "arrows", "arrow(p)", + "arrow(+)", "arrow(s)", "bolt", "Bolt rack", "Opal bolts", + "Dragon bolts" }; /** * Rings. */ - public static final String[] RINGS = {"ring"}; + public static final String[] RINGS = { "ring", "Ring of" }; /** * Bodies. */ - public static final String[] BODY = {"platebody","chainbody","robetop","leathertop","platemail","top","brassard","Robe top","body","platebody (t)","platebody (g)","body(g)","body_(g)","chestplate","torso","shirt"}; + public static final String[] BODY = { "platebody", "chainbody", "robetop", + "leathertop", "platemail", "top", "brassard", "Robe top", "body", + "platebody (t)", "platebody (g)", "body(g)", "body_(g)", + "chestplate", "torso", "shirt" }; /** * Legs. */ - public static final String[] LEGS = {"platelegs","plateskirt","skirt","bottoms","chaps","platelegs (t)","platelegs (g)","bottom","skirt","skirt (g)","skirt (t)","chaps (g)","chaps (t)","tassets","legs","Flared trousers"}; + public static final String[] LEGS = { "platelegs", "plateskirt", "skirt", + "bottoms", "chaps", "platelegs (t)", "platelegs (g)", "bottom", + "skirt", "skirt (g)", "skirt (t)", "chaps (g)", "chaps (t)", + "tassets", "legs", "Flared trousers" }; /** * Weapons. */ - public static final String[] WEAPONS = {"scimitar","longsword","sword","longbow","shortbow","dagger","mace","halberd","spear", - "Abyssal whip","axe","flail","crossbow","Torags hammers","dagger(p)","dagger(+)","dagger(s)","spear(p)","spear(+)", - "spear(s)","spear(kp)","maul","dart","dart(p)","javelin","javelin(p)","knife","knife(p)","Longbow","Shortbow", - "Crossbow","Toktz-xil","Toktz-mej","Tzhaar-ket","staff","Staff","godsword","c'bow","Crystal bow","Dark bow", "Magic butterfly net"}; + public static final String[] WEAPONS = { "scimitar", "longsword", "sword", + "longbow", "shortbow", "dagger", "mace", "halberd", "spear", + "Abyssal whip", "axe", "flail", "crossbow", "Torags hammers", + "dagger(p)", "dagger(+)", "dagger(s)", "spear(p)", "spear(+)", + "spear(s)", "spear(kp)", "maul", "dart", "dart(p)", "javelin", + "javelin(p)", "knife", "knife(p)", "Longbow", "Shortbow", + "Crossbow", "Toktz-xil", "Toktz-mej", "Tzhaar-ket", "staff", + "Staff", "godsword", "c'bow", "Crystal bow", "Dark bow", + "Magic butterfly net" }; /** * Full bodies. */ - public static final String[] FULL_BODIES = {"top","shirt","platebody","Ahrims robetop","Karils leathertop","brassard","Robe top","robetop","platebody (t)","platebody (g)","chestplate","torso"}; + public static final String[] FULL_BODIES = { "top", "shirt", "platebody", + "Ahrims robetop", "Karils leathertop", "brassard", "Robe top", + "robetop", "platebody (t)", "platebody (g)", "chestplate", "torso" }; /** * Full hats. */ - public static final String[] FULL_HATS = {"med helm","coif","Dharoks helm","hood","Initiate helm","Coif","Helm of neitiznot"}; + public static final String[] FULL_HATS = { "med helm", "coif", + "Dharoks helm", "hood", "Initiate helm", "Coif", + "Helm of neitiznot" }; /** * Full masks. */ - public static final String[] FULL_MASKS = {"full helm","mask","Veracs helm","Guthans helm","Torags helm","Karils coif","full helm (t)","full helm (g)","mask"}; + public static final String[] FULL_MASKS = { "full helm", "mask", + "Veracs helm", "Guthans helm", "Torags helm", "Karils coif", + "full helm (t)", "full helm (g)", "mask" }; /** * Default private construcotr to prevent instantiation.