Chiddix

ActionSender

Jun 8th, 2011
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.49 KB | None | 0 0
  1. # Hyperion configuration file
  2.  
  3. # world loader
  4. worldLoader: org.hyperion.rs2.GenericWorldLoader
  5.  
  6. # login server
  7. loginServer: localhost
  8. # world password
  9. nodePassword: changeme
  10. # world id
  11. nodeId: 1
  12.  
  13. # quiet
  14. # 40, 248, 19, 140, 187, 78, 6, 110, 244, 22
  15. packetHandlers[40]: org.hyperion.rs2.packet.QuietPacketHandler
  16. packetHandlers[248]: org.hyperion.rs2.packet.QuietPacketHandler
  17. packetHandlers[19]: org.hyperion.rs2.packet.QuietPacketHandler
  18. packetHandlers[140]: org.hyperion.rs2.packet.QuietPacketHandler
  19. packetHandlers[187]: org.hyperion.rs2.packet.QuietPacketHandler
  20. packetHandlers[78]: org.hyperion.rs2.packet.QuietPacketHandler
  21. packetHandlers[6]: org.hyperion.rs2.packet.QuietPacketHandler
  22. packetHandlers[110]: org.hyperion.rs2.packet.QuietPacketHandler
  23. packetHandlers[244]: org.hyperion.rs2.packet.QuietPacketHandler
  24. packetHandlers[22]: org.hyperion.rs2.packet.QuietPacketHandler
  25.  
  26. # chat
  27. # 49
  28. packetHandlers[49]: org.hyperion.rs2.packet.ChatPacketHandler
  29.  
  30. # walking
  31. # 213, 28, 247
  32. packetHandlers[213]: org.hyperion.rs2.packet.WalkingPacketHandler
  33. packetHandlers[28]: org.hyperion.rs2.packet.WalkingPacketHandler
  34. packetHandlers[247]: org.hyperion.rs2.packet.WalkingPacketHandler
  35.  
  36. # equipment
  37. # 24
  38. packetHandlers[24]: org.hyperion.rs2.packet.WieldPacketHandler
  39.  
  40. # items
  41. # 3, 177, 91, 231, 158
  42. packetHandlers[3]: org.hyperion.rs2.packet.ItemOptionPacketHandler
  43. packetHandlers[177]: org.hyperion.rs2.packet.ItemOptionPacketHandler
  44. packetHandlers[91]: org.hyperion.rs2.packet.ItemOptionPacketHandler
  45. packetHandlers[231]: org.hyperion.rs2.packet.ItemOptionPacketHandler
  46. packetHandlers[158]: org.hyperion.rs2.packet.ItemOptionPacketHandler
  47.  
  48. # input
  49. # 75
  50. packetHandlers[75]: org.hyperion.rs2.packet.EnterAmountPacketHandler
  51.  
  52. # action buttons
  53. # 79
  54. packetHandlers[79]: org.hyperion.rs2.packet.ActionButtonPacketHandler
  55.  
  56. # commands
  57. # 56
  58. packetHandlers[56]: org.hyperion.rs2.packet.CommandPacketHandler
  59.  
  60. package org.hyperion.rs2.net;
  61.  
  62. import org.hyperion.rs2.Constants;
  63. import org.hyperion.rs2.model.Item;
  64. import org.hyperion.rs2.model.Palette;
  65. import org.hyperion.rs2.model.Player;
  66. import org.hyperion.rs2.model.Skills;
  67. import org.hyperion.rs2.model.Palette.PaletteTile;
  68. import org.hyperion.rs2.model.container.Equipment;
  69. import org.hyperion.rs2.model.container.Inventory;
  70. import org.hyperion.rs2.model.container.impl.EquipmentContainerListener;
  71. import org.hyperion.rs2.model.container.impl.InterfaceContainerListener;
  72. import org.hyperion.rs2.model.container.impl.WeaponContainerListener;
  73. import org.hyperion.rs2.net.Packet.Type;
  74.  
  75. /**
  76. * A utility class for sending packets.
  77. *
  78. * @author Graham Edgecombe
  79. *
  80. */
  81. public class ActionSender {
  82.  
  83. /**
  84. * The player.
  85. */
  86. private Player player;
  87.  
  88. /**
  89. * Creates an action sender for the specified player.
  90. *
  91. * @param player
  92. * The player to create the action sender for.
  93. */
  94. public ActionSender(Player player) {
  95. this.player = player;
  96. }
  97.  
  98. /**
  99. * Sends an inventory interface.
  100. *
  101. * @param interfaceId
  102. * The interface id.
  103. * @param inventoryInterfaceId
  104. * The inventory interface id.
  105. * @return The action sender instance, for chaining.
  106. */
  107. public ActionSender sendInterfaceInventory(int interfaceId,
  108. int inventoryInterfaceId) {
  109. player.getInterfaceState().interfaceOpened(interfaceId);
  110. player.write(new PacketBuilder(128).putShortA(interfaceId).putLEShortA(
  111. inventoryInterfaceId).toPacket());
  112. return this;
  113. }
  114.  
  115. public ActionSender resetCameraPosition() {
  116. player.write(new PacketBuilder(148).toPacket());
  117. return this;
  118. }
  119.  
  120. public ActionSender resetButtons() {
  121. player.write(new PacketBuilder(113).toPacket());
  122. return this;
  123. }
  124.  
  125. public ActionSender resetItems(int interfaceId) {
  126. player.write(new PacketBuilder(219).putLEInt(interfaceId).toPacket());
  127. return this;
  128. }
  129.  
  130. public ActionSender sendConfig(int id, int value) {
  131. if (value > 254) {
  132. player.write(new PacketBuilder(115).putInt2(value).putLEShort(id)
  133. .toPacket());
  134. } else {
  135. player.write(new PacketBuilder(182).putShortA(id)
  136. .putByteS((byte) value).toPacket());
  137. }
  138. return this;
  139. }
  140.  
  141. public ActionSender sendInterface(int interfaceId) {
  142. player
  143. .write(new PacketBuilder(159).putLEShortA(interfaceId)
  144. .toPacket());
  145. return this;
  146. }
  147.  
  148. public ActionSender sendInterfaceConfig(int interfaceId, boolean active) {
  149. player.write(new PacketBuilder(82).put((byte) (active ? 0 : 1))
  150. .putShort(interfaceId).toPacket());
  151. return this;
  152. }
  153.  
  154. /**
  155. * Sends all the login packets.
  156. *
  157. * @return The action sender instance, for chaining.
  158. */
  159. public ActionSender sendLogin() {
  160. player.setActive(true);
  161.  
  162. resetCameraPosition();
  163. resetButtons();
  164.  
  165. sendWelcomeScreen();
  166.  
  167. sendDetails();
  168. sendMessage("Welcome to RuneScape.");
  169.  
  170. sendMapRegion();
  171. sendSidebarInterfaces();
  172. sendSkills();
  173. // player.write(new PacketBuilder(251).put((byte)2).toPacket());
  174.  
  175. InterfaceContainerListener inventoryListener = new InterfaceContainerListener(
  176. player, Inventory.INTERFACE);
  177. player.getInventory().addListener(inventoryListener);
  178.  
  179. InterfaceContainerListener equipmentListener = new InterfaceContainerListener(
  180. player, Equipment.INTERFACE);
  181. player.getEquipment().addListener(equipmentListener);
  182. player.getEquipment().addListener(
  183. new EquipmentContainerListener(player));
  184. player.getEquipment().addListener(new WeaponContainerListener(player));
  185.  
  186. sendInterfaceConfig(12323, true);
  187. sendConfig(300, 857);
  188. sendConfig(301, 1);
  189.  
  190. // player.write(new
  191. // PacketBuilder(82).put((byte)0).putShort(12323).toPacket());
  192.  
  193. // for (int i = 12325; i <= 12334; i ++) {
  194. // player.write(new
  195. // PacketBuilder(166).putLEShort(500).putLEShort(0).putShort(i).toPacket());
  196. // }
  197.  
  198. return this;
  199. }
  200.  
  201. public ActionSender sendWelcomeScreen() {
  202. PacketBuilder packet = new PacketBuilder(76);
  203. packet.putLEShort(0); // Days ago requested recovery question changes.
  204. packet.putLEShortA(0);
  205. packet.putShort(0);
  206. packet.putShort(0);
  207. packet.putLEShort(0);
  208. packet.putShortA(0); // Unread messages.
  209. packet.putShortA(0);
  210. packet.putShort(30); // Days of membership credit remaining.
  211. packet.putLEInt(0); // Last IP.
  212. packet.putLEShort(0);
  213. packet.putByteS((byte) 1); // Membership
  214. sendFullScreenInterface(15244, 5993);
  215. player.write(packet.toPacket());
  216. return this;
  217. }
  218.  
  219. public ActionSender sendFullScreenInterface(int interfaceID,
  220. int bgInterfaceID) {
  221. player.write(new PacketBuilder(253).putLEShort(bgInterfaceID)
  222. .putShortA(interfaceID).toPacket());
  223. return this;
  224. }
  225.  
  226. /**
  227. * Sends the packet to construct a map region.
  228. *
  229. * @param palette
  230. * The palette of map regions.
  231. * @return The action sender instance, for chaining.
  232. */
  233. public ActionSender sendConstructMapRegion(Palette palette) {
  234. player.setLastKnownRegion(player.getLocation());
  235. PacketBuilder bldr = new PacketBuilder(53, Type.VARIABLE_SHORT);
  236. bldr.putShortA(player.getLocation().getRegionX() + 6);
  237. bldr.startBitAccess();
  238. for (int z = 0; z < 4; z++) {
  239. for (int x = 0; x < 13; x++) {
  240. for (int y = 0; y < 13; y++) {
  241. PaletteTile tile = palette.getTile(x, y, z);
  242. bldr.putBits(1, tile != null ? 1 : 0);
  243. if (tile != null) {
  244. bldr.putBits(26, tile.getX() << 14 | tile.getY() << 3
  245. | tile.getZ() << 24 | tile.getRotation() << 1);
  246. }
  247. }
  248. }
  249. }
  250. bldr.finishBitAccess();
  251. bldr.putShort(player.getLocation().getRegionY() + 6);
  252. player.write(bldr.toPacket());
  253. return this;
  254. }
  255.  
  256. /**
  257. * Sends the initial login packet (e.g. members, player id).
  258. *
  259. * @return The action sender instance, for chaining.
  260. */
  261. public ActionSender sendDetails() {
  262. // player.write(new PacketBuilder(249).putByteA(player.isMembers() ? 1 :
  263. // 0).putLEShortA(player.getIndex()).toPacket());
  264. // player.write(new PacketBuilder(107).toPacket());
  265. return this;
  266. }
  267.  
  268. /**
  269. * Sends the player's skills.
  270. *
  271. * @return The action sender instance, for chaining.
  272. */
  273. public ActionSender sendSkills() {
  274. for (int i = 0; i < Skills.SKILL_COUNT; i++) {
  275. sendSkill(i);
  276. }
  277. return this;
  278. }
  279.  
  280. /**
  281. * Sends a specific skill.
  282. *
  283. * @param skill
  284. * The skill to send.
  285. * @return The action sender instance, for chaining.
  286. */
  287. public ActionSender sendSkill(int skill) {
  288. PacketBuilder bldr = new PacketBuilder(49);
  289. bldr.putByteC((byte) skill);
  290. bldr.put((byte) player.getSkills().getLevel(skill));
  291. bldr.putInt((int) player.getSkills().getExperience(skill));
  292. player.write(bldr.toPacket());
  293. return this;
  294. }
  295.  
  296. /**
  297. * Sends all the sidebar interfaces.
  298. *
  299. * @return The action sender instance, for chaining.
  300. */
  301. public ActionSender sendSidebarInterfaces() {
  302. final int[] icons = Constants.SIDEBAR_INTERFACES[0];
  303. final int[] interfaces = Constants.SIDEBAR_INTERFACES[1];
  304. for (int i = 0; i < icons.length; i++) {
  305. sendSidebarInterface(icons[i], interfaces[i]);
  306. }
  307. return this;
  308. }
  309.  
  310. /**
  311. * Sends a specific sidebar interface.
  312. *
  313. * @param icon
  314. * The sidebar icon.
  315. * @param interfaceId
  316. * The interface id.
  317. * @return The action sender instance, for chaining.
  318. */
  319. public ActionSender sendSidebarInterface(int icon, int interfaceId) {
  320. player.write(new PacketBuilder(10).putByteS((byte) icon).putShortA(
  321. interfaceId).toPacket());
  322. return this;
  323. }
  324.  
  325. /**
  326. * Sends a message.
  327. *
  328. * @param message
  329. * The message to send.
  330. * @return The action sender instance, for chaining.
  331. */
  332. public ActionSender sendMessage(String message) {
  333. player.write(new PacketBuilder(63, Type.VARIABLE).putRS2String(message)
  334. .toPacket());
  335. return this;
  336. }
  337.  
  338. /**
  339. * Sends the map region load command.
  340. *
  341. * @return The action sender instance, for chaining.
  342. */
  343. public ActionSender sendMapRegion() {
  344. player.setLastKnownRegion(player.getLocation());
  345. player.write(new PacketBuilder(222).putShort(
  346. player.getLocation().getRegionY() + 6).putLEShortA(
  347. player.getLocation().getRegionX() + 6).toPacket());
  348. return this;
  349. }
  350.  
  351. /**
  352. * Sends the logout packet.
  353. *
  354. * @return The action sender instance, for chaining.
  355. */
  356. public ActionSender sendLogout() {
  357. player.write(new PacketBuilder(5).toPacket()); // TODO IoFuture
  358. return this;
  359. }
  360.  
  361. /**
  362. * Sends a packet to update a group of items.
  363. *
  364. * @param interfaceId
  365. * The interface id.
  366. * @param items
  367. * The items.
  368. * @return The action sender instance, for chaining.
  369. */
  370. public ActionSender sendUpdateItems(int interfaceId, Item[] items) {
  371. PacketBuilder bldr = new PacketBuilder(206, Type.VARIABLE_SHORT);
  372. bldr.putShort(interfaceId);
  373. bldr.putShort(items.length);
  374. for (Item item : items) {
  375. if (item != null) {
  376. bldr.putLEShortA(item.getId() + 1);
  377. int count = item.getCount();
  378. if (count > 254) {
  379. bldr.putByteC((byte) 255);
  380. bldr.putLEInt(count);
  381. } else {
  382. bldr.putByteC((byte) count);
  383. }
  384. } else {
  385. bldr.putLEShortA(0);
  386. bldr.putByteC((byte) 0);
  387. }
  388. }
  389. player.write(bldr.toPacket());
  390. return this;
  391. }
  392.  
  393. /**
  394. * Sends a packet to update a single item.
  395. *
  396. * @param interfaceId
  397. * The interface id.
  398. * @param slot
  399. * The slot.
  400. * @param item
  401. * The item.
  402. * @return The action sender instance, for chaining.
  403. */
  404. public ActionSender sendUpdateItem(int interfaceId, int slot, Item item) {
  405. PacketBuilder bldr = new PacketBuilder(134, Type.VARIABLE_SHORT);
  406. bldr.putShort(interfaceId).putSmart(slot);
  407. if (item != null) {
  408. bldr.putShort(item.getId() + 1);
  409. int count = item.getCount();
  410. if (count > 254) {
  411. bldr.put((byte) 255);
  412. bldr.putInt(count);
  413. } else {
  414. bldr.put((byte) count);
  415. }
  416. } else {
  417. bldr.putShort(0);
  418. bldr.put((byte) 0);
  419. }
  420. player.write(bldr.toPacket());
  421. return this;
  422. }
  423.  
  424. /**
  425. * Sends a packet to update multiple (but not all) items.
  426. *
  427. * @param interfaceId
  428. * The interface id.
  429. * @param slots
  430. * The slots.
  431. * @param items
  432. * The item array.
  433. * @return The action sender instance, for chaining.
  434. */
  435. public ActionSender sendUpdateItems(int interfaceId, int[] slots,
  436. Item[] items) {
  437. PacketBuilder bldr = new PacketBuilder(134, Type.VARIABLE_SHORT)
  438. .putShort(interfaceId);
  439. for (int slot : slots) {
  440. Item item = items[slot];
  441. bldr.putSmart(slot);
  442. if (item != null) {
  443. bldr.putShort(item.getId() + 1);
  444. int count = item.getCount();
  445. if (count > 254) {
  446. bldr.put((byte) 255);
  447. bldr.putInt(count);
  448. } else {
  449. bldr.put((byte) count);
  450. }
  451. } else {
  452. bldr.putShort(0);
  453. bldr.put((byte) 0);
  454. }
  455. }
  456. player.write(bldr.toPacket());
  457. return this;
  458. }
  459.  
  460. /**
  461. * Sends the enter amount interface.
  462. *
  463. * @return The action sender instance, for chaining.
  464. */
  465. public ActionSender sendEnterAmountInterface() {
  466. player.write(new PacketBuilder(58).toPacket());
  467. return this;
  468. }
  469.  
  470. /**
  471. * Sends the player an option.
  472. *
  473. * @param slot
  474. * The slot to place the option in the menu.
  475. * @param top
  476. * Flag which indicates the item should be placed at the top.
  477. * @param option
  478. * Option string which is the actual text.
  479. * @return The action sender instance, for chaining.
  480. */
  481. public ActionSender sendInteractionOption(String option, int slot,
  482. boolean top) {
  483. PacketBuilder bldr = new PacketBuilder(157, Type.VARIABLE);
  484. bldr.putByteC((byte) -slot);
  485. bldr.putRS2String(option);
  486. bldr.put(top ? (byte) 0 : (byte) 1);
  487. player.write(bldr.toPacket());
  488. return this;
  489. }
  490.  
  491. /**
  492. * Sends a string.
  493. *
  494. * @param id
  495. * The interface id.
  496. * @param string
  497. * The string.
  498. * @return The action sender instance, for chaining.
  499. */
  500. public ActionSender sendString(int id, String string) {
  501. PacketBuilder bldr = new PacketBuilder(232, Type.VARIABLE_SHORT);
  502. bldr.putLEShortA(id);
  503. bldr.putRS2String(string);
  504. player.write(bldr.toPacket());
  505. return this;
  506. }
  507.  
  508. /**
  509. * Sends a model in an interface.
  510. *
  511. * @param id
  512. * The interface id.
  513. * @param zoom
  514. * The zoom.
  515. * @param model
  516. * The model id.
  517. * @return The action sender instance, for chaining.
  518. */
  519. public ActionSender sendInterfaceModel(int id, int zoom, int model) {
  520. PacketBuilder bldr = new PacketBuilder(21);
  521. bldr.putShort(zoom).putLEShort(model).putLEShortA(id);
  522. player.write(bldr.toPacket());
  523. return this;
  524. }
  525. }
Advertisement
Add Comment
Please, Sign In to add comment