Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. public void sendDynamicGameScene(boolean sendLswp) {
  2. OutputStream stream = new OutputStream();
  3. stream.writePacketVarShort(player, 173);
  4. if (sendLswp) // exists on newer protocol, sends all player encoded
  5. // region ids, afterwards new pupdate protocol is
  6. // regionbased
  7. player.getLocalPlayerUpdate().init(stream);
  8. int middleChunkX = player.getChunkX();
  9. int middleChunkY = player.getChunkY();
  10.  
  11. stream.writeByte128(2);
  12. stream.writeShort(middleChunkY);
  13. stream.writeByte128(player.getMapSize());
  14. stream.writeShortLE128(middleChunkX);
  15. stream.writeByte(player.isForceNextMapLoadRefresh() ? 1 : 0);
  16. stream.write128Byte((1 << 65 + 1) + 1);// new on 876 client
  17.  
  18. // supporting npcs
  19. stream.initBitAccess();
  20. /*
  21. * cene length in chunks. scene tiles length / 16, 8 is a chunk size, 16
  22. * because the code behind its signed and goes from middle-length to
  23. * middle+length
  24. */
  25. int sceneLength = Settings.MAP_SIZES[player.getMapSize()] >> 4;
  26. // the regionids(maps files) that will be used to load this scene
  27. int[] regionIds = new int[4 * sceneLength * sceneLength];
  28. int newRegionIdsCount = 0;
  29. for (int plane = 0; plane < 4; plane++) {
  30. for (int realChunkX = (middleChunkX - sceneLength); realChunkX <= ((middleChunkX
  31. + sceneLength)); realChunkX++) {
  32. int regionX = realChunkX / 8;
  33. y: for (int realChunkY = (middleChunkY - sceneLength); realChunkY <= ((middleChunkY
  34. + sceneLength)); realChunkY++) {
  35. int regionY = realChunkY / 8;
  36. // rcx / 8 = rx, rcy / 8 = ry, regionid is encoded region x
  37. // and y
  38. int regionId = (regionX << 8) + regionY;
  39. Region region = World.getRegions().get(regionId);
  40. int newChunkX;
  41. int newChunkY;
  42. int newPlane;
  43. int rotation;
  44. if (region instanceof DynamicRegion) { // generated map
  45. DynamicRegion dynamicRegion = (DynamicRegion) region;
  46. int[] pallete = dynamicRegion.getRegionCoords()[plane][realChunkX - (regionX * 8)][realChunkY
  47. - (regionY * 8)];
  48. newChunkX = pallete[0];
  49. newChunkY = pallete[1];
  50. newPlane = pallete[2];
  51. rotation = pallete[3];
  52. } else { // real map
  53. newChunkX = realChunkX;
  54. newChunkY = realChunkY;
  55. newPlane = plane;
  56. rotation = 0;// no rotation
  57. }
  58. // invalid chunk, not built chunk
  59. if (newChunkX == 0 || newChunkY == 0)
  60. stream.writeBits(1, 0);
  61. else {
  62. stream.writeBits(1, 1);
  63. // chunk encoding = (x << 14) | (y << 3) | (plane <<
  64. // 24), theres addition of two more bits for rotation
  65. stream.writeBits(26, (rotation << 1) | (newPlane << 24) | (newChunkX << 14) | (newChunkY << 3));
  66. int newRegionId = (((newChunkX / 8) << 8) + (newChunkY / 8));
  67. for (int index = 0; index < newRegionIdsCount; index++)
  68. if (regionIds[index] == newRegionId)
  69. continue y;
  70. regionIds[newRegionIdsCount++] = newRegionId;
  71. }
  72.  
  73. }
  74. }
  75.  
  76. }
  77. stream.finishBitAccess();
  78. stream.writeByte(newRegionIdsCount);
  79. /*
  80. * for (int index = 0; index < newRegionIdsCount; index++) { int[] xteas
  81. * = MapArchiveKeys.getMapKeys(regionIds[index]); if (xteas == null)
  82. * xteas = new int[4]; for (int keyIndex = 0; keyIndex < 4; keyIndex++)
  83. * stream.writeInt(xteas[keyIndex]); }
  84. */
  85. stream.endPacketVarShort();
  86. session.write(stream);
  87. }
  88.  
  89. public void sendIComponentInputInteger(int interfaceId, int componentId, int length) {
  90. player.getPackets().sendCSVarInteger(2235, (interfaceId << 16 | componentId));
  91. player.getPackets().sendCSVarInteger(2236, 7);
  92. player.getPackets().sendCSVarInteger(2237, length);
  93. }
  94.  
  95. public void sendIComponentInputText(int interfaceId, int componentId, int length) {
  96. player.getPackets().sendCSVarInteger(2235, (interfaceId << 16 | componentId));
  97. player.getPackets().sendCSVarInteger(2236, 9);
  98. player.getPackets().sendCSVarInteger(2237, length);
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement