Clone of PhatAC @ https://github.com/floaterxk/PhatAC

ChatMsgs.cpp 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include "StdAfx.h"
  2. #include "PhysicsObj.h"
  3. #include "Monster.h"
  4. #include "Player.h"
  5. //Network access.
  6. #include "Client.h"
  7. #include "BinaryWriter.h"
  8. #include "ChatMsgs.h"
  9. #define MESSAGE_BEGIN(x) BinaryWriter *x = new BinaryWriter
  10. #define MESSAGE_END(x) return x
  11. BinaryWriter *LocalChat(const char *szText, const char *szName, DWORD dwSourceID, long lColor)
  12. {
  13. MESSAGE_BEGIN(LocalChat);
  14. LocalChat->WriteDWORD(0x02BB);
  15. LocalChat->WriteString(szText);
  16. LocalChat->WriteString(szName);
  17. LocalChat->WriteDWORD(dwSourceID);
  18. LocalChat->WriteLong(lColor);
  19. MESSAGE_END(LocalChat);
  20. }
  21. BinaryWriter *EmoteChat(const char* szText, const char* szName, DWORD dwSourceID)
  22. {
  23. MESSAGE_BEGIN(EmoteChat);
  24. EmoteChat->WriteDWORD(0x1E0);
  25. EmoteChat->WriteDWORD(dwSourceID);
  26. EmoteChat->WriteString(szName);
  27. EmoteChat->WriteString(szText);
  28. MESSAGE_END(EmoteChat);
  29. }
  30. //0x5719F5DB
  31. BinaryWriter *DirectChat(const char* szText, const char* szName, DWORD dwSourceID, DWORD dwDestID, long lColor)
  32. {
  33. //Fake-tells: bit 10 must be set.
  34. //Envoy: bit 21 must be set.
  35. //Example:
  36. //Step 1. Take a DWORD of any value. (entirely random if you wish, it doesn't matter.)
  37. //Step 2. Remove bits 10 and 21 from that DWORD.
  38. //Step 3. If FAKE-tell: set bit 10 (other don't.) These tells will never be drawn to the chat.
  39. //Step 4. If Envoy: set bit 21 (otherwise don't.) These tells will be prefixed with '+Envoy'.
  40. //Step 5. Now take the DWORD and XOR it against the source player's GUID.
  41. //The final result will be the magic number.
  42. #define RANDOM_LONG() ((rand() << 30) | (rand()<<15) | rand()) // RAND_MAX=7fff
  43. BOOL bFakeTell = FALSE;
  44. BOOL bEnvoy = FALSE;
  45. DWORD dwMagicValue;
  46. dwMagicValue = RANDOM_LONG(); //Step 1
  47. dwMagicValue &= ~((1 << 10) | (1 << 21)); //Step 2
  48. if (bFakeTell) //Step 3
  49. dwMagicValue |= 1 << 10;
  50. if (bEnvoy) //Step 4
  51. dwMagicValue |= 1 << 21;
  52. dwMagicValue ^= dwSourceID; //Step 5
  53. MESSAGE_BEGIN(DirectChat);
  54. DirectChat->WriteDWORD(0x2BD);
  55. DirectChat->WriteString(szText);
  56. DirectChat->WriteString(szName);
  57. DirectChat->WriteDWORD(dwSourceID);
  58. DirectChat->WriteDWORD(dwDestID);
  59. DirectChat->WriteLong(lColor);
  60. DirectChat->WriteDWORD(dwMagicValue);
  61. MESSAGE_END(DirectChat);
  62. }
  63. BinaryWriter *ActionChat(const char* szText, const char* szName, DWORD dwSourceID)
  64. {
  65. MESSAGE_BEGIN(EmoteChat);
  66. EmoteChat->WriteDWORD(0x1E2);
  67. EmoteChat->WriteDWORD(dwSourceID);
  68. EmoteChat->WriteString(szName);
  69. EmoteChat->WriteString(szText);
  70. MESSAGE_END(EmoteChat);
  71. }
  72. BinaryWriter *ServerText(const char *szText, long lColor)
  73. {
  74. MESSAGE_BEGIN(ServerText);
  75. ServerText->WriteDWORD(0xF7E0);
  76. ServerText->WriteString(szText);
  77. ServerText->WriteLong(lColor);
  78. MESSAGE_END(ServerText);
  79. }
  80. BinaryWriter *ServerBroadcast(const char *szSource, const char *szText, long lColor)
  81. {
  82. // Using string class to prevent from static buffer collisions.
  83. std::string strBroadcast;
  84. strBroadcast = "Broadcast from ";
  85. strBroadcast += szSource;
  86. strBroadcast += "> ";
  87. strBroadcast += szText;
  88. MESSAGE_END(ServerText(strBroadcast.c_str(), lColor));
  89. }
  90. BinaryWriter *ChannelChat(DWORD dwChannel, const char* szName, const char* szText)
  91. {
  92. MESSAGE_BEGIN(ChannelChat);
  93. ChannelChat->WriteDWORD(0x14A);
  94. ChannelChat->WriteDWORD(dwChannel);
  95. ChannelChat->WriteString(szName);
  96. ChannelChat->WriteString(szText);
  97. MESSAGE_END(ChannelChat);
  98. }