Advertisement
Juantlo

Untitled

Oct 8th, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. void sendWorld(ENetPeer* peer, WorldInfo* worldInfo)
  2. {
  3. #ifdef TOTAL_LOG
  4. cout << "Entering a world..." << endl;
  5. #endif
  6. ((PlayerInfo*)(peer->data))->joinClothesUpdated = false;
  7. string asdf = "0400000004A7379237BB2509E8E0EC04F8720B050000000000000000FBBB0000010000007D920100FDFDFDFD04000000040000000000000000000000070000000000"; // 0400000004A7379237BB2509E8E0EC04F8720B050000000000000000FBBB0000010000007D920100FDFDFDFD04000000040000000000000000000000080000000000000000000000000000000000000000000000000000000000000048133A0500000000BEBB0000070000000000
  8. string worldName = worldInfo->name;
  9. int xSize = worldInfo->width;
  10. int ySize = worldInfo->height;
  11. int square = xSize*ySize;
  12. __int16 nameLen = worldName.length();
  13. int payloadLen = asdf.length() / 2;
  14. int dataLen = payloadLen + 2 + nameLen + 12 + (square * 8) + 4;
  15. int allocMem = payloadLen + 2 + nameLen + 12 + (square * 8) + 4 + 16000;
  16. BYTE* data = new BYTE[allocMem];
  17. for (int i = 0; i < asdf.length(); i += 2)
  18. {
  19. char x = ch2n(asdf[i]);
  20. x = x << 4;
  21. x += ch2n(asdf[i + 1]);
  22. memcpy(data + (i / 2), &x, 1);
  23. }
  24. int zero = 0;
  25. __int16 item = 0;
  26. int smth = 0;
  27. for (int i = 0; i < square * 8; i += 4) memcpy(data + payloadLen + i + 14 + nameLen, &zero, 4);
  28. for (int i = 0; i < square * 8; i += 8) memcpy(data + payloadLen + i + 14 + nameLen, &item, 2);
  29. memcpy(data + payloadLen, &nameLen, 2);
  30. memcpy(data + payloadLen + 2, worldName.c_str(), nameLen);
  31. memcpy(data + payloadLen + 2 + nameLen, &xSize, 4);
  32. memcpy(data + payloadLen + 6 + nameLen, &ySize, 4);
  33. memcpy(data + payloadLen + 10 + nameLen, &square, 4);
  34. BYTE* blockPtr = data + payloadLen + 14 + nameLen;
  35. for (int i = 0; i < square; i++) {
  36. if ((worldInfo->items[i].foreground == 0) || (worldInfo->items[i].foreground == 2) || (worldInfo->items[i].foreground == 8) || (worldInfo->items[i].foreground == 100)/* || (worldInfo->items[i].foreground%2)*/)
  37. {
  38. memcpy(blockPtr, &worldInfo->items[i].foreground, 2);
  39. int type = 0x00000000;
  40. // type 1 = locked
  41. if (worldInfo->items[i].water)
  42. type |= 0x04000000;
  43. if (worldInfo->items[i].glue)
  44. type |= 0x08000000;
  45. if (worldInfo->items[i].fire)
  46. type |= 0x10000000;
  47. if (worldInfo->items[i].red)
  48. type |= 0x20000000;
  49. if (worldInfo->items[i].green)
  50. type |= 0x40000000;
  51. if (worldInfo->items[i].blue)
  52. type |= 0x80000000;
  53.  
  54. // int type = 0x04000000; = water
  55. // int type = 0x08000000 = glue
  56. // int type = 0x10000000; = fire
  57. // int type = 0x20000000; = red color
  58. // int type = 0x40000000; = green color
  59. // int type = 0x80000000; = blue color
  60. memcpy(blockPtr + 4, &type, 4);
  61. /*if (worldInfo->items[i].foreground % 2)
  62. {
  63. blockPtr += 6;
  64. }*/
  65. }
  66. else
  67. {
  68. memcpy(blockPtr, &zero, 2);
  69. }
  70. memcpy(blockPtr + 2, &worldInfo->items[i].background, 2);
  71. blockPtr += 8;
  72. /*if (blockPtr - data < allocMem - 2000) // realloc
  73. {
  74. int wLen = blockPtr - data;
  75. BYTE* oldData = data;
  76.  
  77. data = new BYTE[allocMem + 16000];
  78. memcpy(data, oldData, allocMem);
  79. allocMem += 16000;
  80. delete oldData;
  81. blockPtr = data + wLen;
  82.  
  83. }*/
  84. }
  85. memcpy(data + dataLen - 4, &smth, 4);
  86. ENetPacket * packet2 = enet_packet_create(data,
  87. dataLen,
  88. ENET_PACKET_FLAG_RELIABLE);
  89. enet_peer_send(peer, 0, packet2);
  90. //enet_host_flush(server);
  91. for (int i = 0; i < square; i++) {
  92. if ((worldInfo->items[i].foreground == 0) || (worldInfo->items[i].foreground == 2) || (worldInfo->items[i].foreground == 8) || (worldInfo->items[i].foreground == 100))
  93. ; // nothing
  94. else
  95. {
  96. PlayerMoving data;
  97. //data.packetType = 0x14;
  98. data.packetType = 0x3;
  99.  
  100. //data.characterState = 0x924; // animation
  101. data.characterState = 0x0; // animation
  102. data.x = i%worldInfo->width;
  103. data.y = i/worldInfo->height;
  104. data.punchX = i%worldInfo->width;
  105. data.punchY = i / worldInfo->width;
  106. data.XSpeed = 0;
  107. data.YSpeed = 0;
  108. data.netID = -1;
  109. data.plantingTree = worldInfo->items[i].foreground;
  110. SendPacketRaw(4, packPlayerMoving(&data), 56, 0, peer, ENET_PACKET_FLAG_RELIABLE);
  111. }
  112. }
  113. ((PlayerInfo*)(peer->data))->currentWorld = worldInfo->name;
  114.  
  115. if (((PlayerInfo*)(peer->data))->haveGrowId) {
  116.  
  117. PlayerInfo* p = ((PlayerInfo*)(peer->data));
  118. std::ifstream ifff("players/" + PlayerDB::getProperName(p->rawName) + ".json");
  119. json j;
  120. ifff >> j;
  121.  
  122. p->currentWorld = worldInfo->name;
  123.  
  124. int bac, han, fac, hai, fee, pan, nec, shi, mas;
  125. bac = j["ClothBack"];
  126. han = j["ClothHand"];
  127. fac = j["ClothFace"];
  128. hai = j["ClothHair"];
  129. fee = j["ClothFeet"];
  130. pan = j["ClothPants"];
  131. nec = j["ClothNeck"];
  132. shi = j["ClothShirt"];
  133. mas = j["ClothMask"];
  134.  
  135. p->cloth_back = bac;
  136. p->cloth_hand = han;
  137. p->cloth_face = fac;
  138. p->cloth_hair = hai;
  139. p->cloth_feet = fee;
  140. p->cloth_pants = pan;
  141. p->cloth_necklace = nec;
  142. p->cloth_shirt = shi;
  143. p->cloth_mask = mas;
  144.  
  145. sendClothes(peer);
  146.  
  147. ifff.close();
  148.  
  149. }
  150.  
  151. delete data;
  152.  
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement