Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Hyperion configuration file
- # world loader
- worldLoader: org.hyperion.rs2.GenericWorldLoader
- # login server
- loginServer: localhost
- # world password
- nodePassword: changeme
- # world id
- nodeId: 1
- # quiet
- # 40, 248, 19, 140, 187, 78, 6, 110, 244, 22
- packetHandlers[40]: org.hyperion.rs2.packet.QuietPacketHandler
- packetHandlers[248]: org.hyperion.rs2.packet.QuietPacketHandler
- packetHandlers[19]: org.hyperion.rs2.packet.QuietPacketHandler
- packetHandlers[140]: org.hyperion.rs2.packet.QuietPacketHandler
- packetHandlers[187]: org.hyperion.rs2.packet.QuietPacketHandler
- packetHandlers[78]: org.hyperion.rs2.packet.QuietPacketHandler
- packetHandlers[6]: org.hyperion.rs2.packet.QuietPacketHandler
- packetHandlers[110]: org.hyperion.rs2.packet.QuietPacketHandler
- packetHandlers[244]: org.hyperion.rs2.packet.QuietPacketHandler
- packetHandlers[22]: org.hyperion.rs2.packet.QuietPacketHandler
- # chat
- # 49
- packetHandlers[49]: org.hyperion.rs2.packet.ChatPacketHandler
- # walking
- # 213, 28, 247
- packetHandlers[213]: org.hyperion.rs2.packet.WalkingPacketHandler
- packetHandlers[28]: org.hyperion.rs2.packet.WalkingPacketHandler
- packetHandlers[247]: org.hyperion.rs2.packet.WalkingPacketHandler
- # equipment
- # 24
- packetHandlers[24]: org.hyperion.rs2.packet.WieldPacketHandler
- # items
- # 3, 177, 91, 231, 158
- packetHandlers[3]: org.hyperion.rs2.packet.ItemOptionPacketHandler
- packetHandlers[177]: org.hyperion.rs2.packet.ItemOptionPacketHandler
- packetHandlers[91]: org.hyperion.rs2.packet.ItemOptionPacketHandler
- packetHandlers[231]: org.hyperion.rs2.packet.ItemOptionPacketHandler
- packetHandlers[158]: org.hyperion.rs2.packet.ItemOptionPacketHandler
- # input
- # 75
- packetHandlers[75]: org.hyperion.rs2.packet.EnterAmountPacketHandler
- # action buttons
- # 79
- packetHandlers[79]: org.hyperion.rs2.packet.ActionButtonPacketHandler
- # commands
- # 56
- packetHandlers[56]: org.hyperion.rs2.packet.CommandPacketHandler
- package org.hyperion.rs2.net;
- import org.hyperion.rs2.Constants;
- import org.hyperion.rs2.model.Item;
- import org.hyperion.rs2.model.Palette;
- import org.hyperion.rs2.model.Player;
- import org.hyperion.rs2.model.Skills;
- import org.hyperion.rs2.model.Palette.PaletteTile;
- import org.hyperion.rs2.model.container.Equipment;
- import org.hyperion.rs2.model.container.Inventory;
- import org.hyperion.rs2.model.container.impl.EquipmentContainerListener;
- import org.hyperion.rs2.model.container.impl.InterfaceContainerListener;
- import org.hyperion.rs2.model.container.impl.WeaponContainerListener;
- import org.hyperion.rs2.net.Packet.Type;
- /**
- * A utility class for sending packets.
- *
- * @author Graham Edgecombe
- *
- */
- public class ActionSender {
- /**
- * The player.
- */
- private Player player;
- /**
- * Creates an action sender for the specified player.
- *
- * @param player
- * The player to create the action sender for.
- */
- public ActionSender(Player player) {
- this.player = player;
- }
- /**
- * Sends an inventory interface.
- *
- * @param interfaceId
- * The interface id.
- * @param inventoryInterfaceId
- * The inventory interface id.
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendInterfaceInventory(int interfaceId,
- int inventoryInterfaceId) {
- player.getInterfaceState().interfaceOpened(interfaceId);
- player.write(new PacketBuilder(128).putShortA(interfaceId).putLEShortA(
- inventoryInterfaceId).toPacket());
- return this;
- }
- public ActionSender resetCameraPosition() {
- player.write(new PacketBuilder(148).toPacket());
- return this;
- }
- public ActionSender resetButtons() {
- player.write(new PacketBuilder(113).toPacket());
- return this;
- }
- public ActionSender resetItems(int interfaceId) {
- player.write(new PacketBuilder(219).putLEInt(interfaceId).toPacket());
- return this;
- }
- public ActionSender sendConfig(int id, int value) {
- if (value > 254) {
- player.write(new PacketBuilder(115).putInt2(value).putLEShort(id)
- .toPacket());
- } else {
- player.write(new PacketBuilder(182).putShortA(id)
- .putByteS((byte) value).toPacket());
- }
- return this;
- }
- public ActionSender sendInterface(int interfaceId) {
- player
- .write(new PacketBuilder(159).putLEShortA(interfaceId)
- .toPacket());
- return this;
- }
- public ActionSender sendInterfaceConfig(int interfaceId, boolean active) {
- player.write(new PacketBuilder(82).put((byte) (active ? 0 : 1))
- .putShort(interfaceId).toPacket());
- return this;
- }
- /**
- * Sends all the login packets.
- *
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendLogin() {
- player.setActive(true);
- resetCameraPosition();
- resetButtons();
- sendWelcomeScreen();
- sendDetails();
- sendMessage("Welcome to RuneScape.");
- sendMapRegion();
- sendSidebarInterfaces();
- sendSkills();
- // player.write(new PacketBuilder(251).put((byte)2).toPacket());
- InterfaceContainerListener inventoryListener = new InterfaceContainerListener(
- player, Inventory.INTERFACE);
- player.getInventory().addListener(inventoryListener);
- InterfaceContainerListener equipmentListener = new InterfaceContainerListener(
- player, Equipment.INTERFACE);
- player.getEquipment().addListener(equipmentListener);
- player.getEquipment().addListener(
- new EquipmentContainerListener(player));
- player.getEquipment().addListener(new WeaponContainerListener(player));
- sendInterfaceConfig(12323, true);
- sendConfig(300, 857);
- sendConfig(301, 1);
- // player.write(new
- // PacketBuilder(82).put((byte)0).putShort(12323).toPacket());
- // for (int i = 12325; i <= 12334; i ++) {
- // player.write(new
- // PacketBuilder(166).putLEShort(500).putLEShort(0).putShort(i).toPacket());
- // }
- return this;
- }
- public ActionSender sendWelcomeScreen() {
- PacketBuilder packet = new PacketBuilder(76);
- packet.putLEShort(0); // Days ago requested recovery question changes.
- packet.putLEShortA(0);
- packet.putShort(0);
- packet.putShort(0);
- packet.putLEShort(0);
- packet.putShortA(0); // Unread messages.
- packet.putShortA(0);
- packet.putShort(30); // Days of membership credit remaining.
- packet.putLEInt(0); // Last IP.
- packet.putLEShort(0);
- packet.putByteS((byte) 1); // Membership
- sendFullScreenInterface(15244, 5993);
- player.write(packet.toPacket());
- return this;
- }
- public ActionSender sendFullScreenInterface(int interfaceID,
- int bgInterfaceID) {
- player.write(new PacketBuilder(253).putLEShort(bgInterfaceID)
- .putShortA(interfaceID).toPacket());
- return this;
- }
- /**
- * Sends the packet to construct a map region.
- *
- * @param palette
- * The palette of map regions.
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendConstructMapRegion(Palette palette) {
- player.setLastKnownRegion(player.getLocation());
- PacketBuilder bldr = new PacketBuilder(53, Type.VARIABLE_SHORT);
- bldr.putShortA(player.getLocation().getRegionX() + 6);
- bldr.startBitAccess();
- for (int z = 0; z < 4; z++) {
- for (int x = 0; x < 13; x++) {
- for (int y = 0; y < 13; y++) {
- PaletteTile tile = palette.getTile(x, y, z);
- bldr.putBits(1, tile != null ? 1 : 0);
- if (tile != null) {
- bldr.putBits(26, tile.getX() << 14 | tile.getY() << 3
- | tile.getZ() << 24 | tile.getRotation() << 1);
- }
- }
- }
- }
- bldr.finishBitAccess();
- bldr.putShort(player.getLocation().getRegionY() + 6);
- player.write(bldr.toPacket());
- return this;
- }
- /**
- * Sends the initial login packet (e.g. members, player id).
- *
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendDetails() {
- // player.write(new PacketBuilder(249).putByteA(player.isMembers() ? 1 :
- // 0).putLEShortA(player.getIndex()).toPacket());
- // player.write(new PacketBuilder(107).toPacket());
- return this;
- }
- /**
- * Sends the player's skills.
- *
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendSkills() {
- for (int i = 0; i < Skills.SKILL_COUNT; i++) {
- sendSkill(i);
- }
- return this;
- }
- /**
- * Sends a specific skill.
- *
- * @param skill
- * The skill to send.
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendSkill(int skill) {
- PacketBuilder bldr = new PacketBuilder(49);
- bldr.putByteC((byte) skill);
- bldr.put((byte) player.getSkills().getLevel(skill));
- bldr.putInt((int) player.getSkills().getExperience(skill));
- player.write(bldr.toPacket());
- return this;
- }
- /**
- * Sends all the sidebar interfaces.
- *
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendSidebarInterfaces() {
- final int[] icons = Constants.SIDEBAR_INTERFACES[0];
- final int[] interfaces = Constants.SIDEBAR_INTERFACES[1];
- for (int i = 0; i < icons.length; i++) {
- sendSidebarInterface(icons[i], interfaces[i]);
- }
- return this;
- }
- /**
- * Sends a specific sidebar interface.
- *
- * @param icon
- * The sidebar icon.
- * @param interfaceId
- * The interface id.
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendSidebarInterface(int icon, int interfaceId) {
- player.write(new PacketBuilder(10).putByteS((byte) icon).putShortA(
- interfaceId).toPacket());
- return this;
- }
- /**
- * Sends a message.
- *
- * @param message
- * The message to send.
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendMessage(String message) {
- player.write(new PacketBuilder(63, Type.VARIABLE).putRS2String(message)
- .toPacket());
- return this;
- }
- /**
- * Sends the map region load command.
- *
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendMapRegion() {
- player.setLastKnownRegion(player.getLocation());
- player.write(new PacketBuilder(222).putShort(
- player.getLocation().getRegionY() + 6).putLEShortA(
- player.getLocation().getRegionX() + 6).toPacket());
- return this;
- }
- /**
- * Sends the logout packet.
- *
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendLogout() {
- player.write(new PacketBuilder(5).toPacket()); // TODO IoFuture
- return this;
- }
- /**
- * Sends a packet to update a group of items.
- *
- * @param interfaceId
- * The interface id.
- * @param items
- * The items.
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendUpdateItems(int interfaceId, Item[] items) {
- PacketBuilder bldr = new PacketBuilder(206, Type.VARIABLE_SHORT);
- bldr.putShort(interfaceId);
- bldr.putShort(items.length);
- for (Item item : items) {
- if (item != null) {
- bldr.putLEShortA(item.getId() + 1);
- int count = item.getCount();
- if (count > 254) {
- bldr.putByteC((byte) 255);
- bldr.putLEInt(count);
- } else {
- bldr.putByteC((byte) count);
- }
- } else {
- bldr.putLEShortA(0);
- bldr.putByteC((byte) 0);
- }
- }
- player.write(bldr.toPacket());
- return this;
- }
- /**
- * Sends a packet to update a single item.
- *
- * @param interfaceId
- * The interface id.
- * @param slot
- * The slot.
- * @param item
- * The item.
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendUpdateItem(int interfaceId, int slot, Item item) {
- PacketBuilder bldr = new PacketBuilder(134, Type.VARIABLE_SHORT);
- bldr.putShort(interfaceId).putSmart(slot);
- if (item != null) {
- bldr.putShort(item.getId() + 1);
- int count = item.getCount();
- if (count > 254) {
- bldr.put((byte) 255);
- bldr.putInt(count);
- } else {
- bldr.put((byte) count);
- }
- } else {
- bldr.putShort(0);
- bldr.put((byte) 0);
- }
- player.write(bldr.toPacket());
- return this;
- }
- /**
- * Sends a packet to update multiple (but not all) items.
- *
- * @param interfaceId
- * The interface id.
- * @param slots
- * The slots.
- * @param items
- * The item array.
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendUpdateItems(int interfaceId, int[] slots,
- Item[] items) {
- PacketBuilder bldr = new PacketBuilder(134, Type.VARIABLE_SHORT)
- .putShort(interfaceId);
- for (int slot : slots) {
- Item item = items[slot];
- bldr.putSmart(slot);
- if (item != null) {
- bldr.putShort(item.getId() + 1);
- int count = item.getCount();
- if (count > 254) {
- bldr.put((byte) 255);
- bldr.putInt(count);
- } else {
- bldr.put((byte) count);
- }
- } else {
- bldr.putShort(0);
- bldr.put((byte) 0);
- }
- }
- player.write(bldr.toPacket());
- return this;
- }
- /**
- * Sends the enter amount interface.
- *
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendEnterAmountInterface() {
- player.write(new PacketBuilder(58).toPacket());
- return this;
- }
- /**
- * Sends the player an option.
- *
- * @param slot
- * The slot to place the option in the menu.
- * @param top
- * Flag which indicates the item should be placed at the top.
- * @param option
- * Option string which is the actual text.
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendInteractionOption(String option, int slot,
- boolean top) {
- PacketBuilder bldr = new PacketBuilder(157, Type.VARIABLE);
- bldr.putByteC((byte) -slot);
- bldr.putRS2String(option);
- bldr.put(top ? (byte) 0 : (byte) 1);
- player.write(bldr.toPacket());
- return this;
- }
- /**
- * Sends a string.
- *
- * @param id
- * The interface id.
- * @param string
- * The string.
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendString(int id, String string) {
- PacketBuilder bldr = new PacketBuilder(232, Type.VARIABLE_SHORT);
- bldr.putLEShortA(id);
- bldr.putRS2String(string);
- player.write(bldr.toPacket());
- return this;
- }
- /**
- * Sends a model in an interface.
- *
- * @param id
- * The interface id.
- * @param zoom
- * The zoom.
- * @param model
- * The model id.
- * @return The action sender instance, for chaining.
- */
- public ActionSender sendInterfaceModel(int id, int zoom, int model) {
- PacketBuilder bldr = new PacketBuilder(21);
- bldr.putShort(zoom).putLEShort(model).putLEShortA(id);
- player.write(bldr.toPacket());
- return this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment