Guest User

860->870

a guest
Nov 1st, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.43 KB | None | 0 0
  1. #include "hook.h"
  2.  
  3. #include <string>
  4. #include <vector>
  5.  
  6. enum MessageClasses
  7. {
  8. MESSAGE_STATUS_CONSOLE_RED = 18, /*Red message in the console*/
  9. MESSAGE_EVENT_ORANGE = 19, /*Orange message in the console*/
  10. MESSAGE_STATUS_CONSOLE_ORANGE = 20, /*Orange message in the console*/
  11. MESSAGE_STATUS_WARNING = 21, /*Red message in game window and in the console*/
  12. MESSAGE_EVENT_ADVANCE = 22, /*White message in game window and in the console*/
  13. MESSAGE_EVENT_DEFAULT = 23, /*White message at the bottom of the game window and in the console*/
  14. MESSAGE_STATUS_DEFAULT = 24, /*White message at the bottom of the game window and in the console*/
  15. MESSAGE_INFO_DESCR = 25, /*Green message in game window and in the console*/
  16. MESSAGE_STATUS_SMALL = 26, /*White message at the bottom of the game window"*/
  17. MESSAGE_STATUS_CONSOLE_BLUE = 27, /*FIXME Blue message in the console*/
  18. };
  19.  
  20. enum TalkTypes
  21. {
  22. TALKTYPE_SAY = 1,
  23. TALKTYPE_WHISPER = 2,
  24. TALKTYPE_YELL = 3,
  25. TALKTYPE_PRIVATE_PN = 4,
  26. TALKTYPE_PRIVATE_NP = 5,
  27. TALKTYPE_PRIVATE = 6,
  28. TALKTYPE_CHANNEL_Y = 7,
  29. TALKTYPE_CHANNEL_W = 8,
  30. TALKTYPE_RVR_CHANNEL = 9,
  31. TALKTYPE_RVR_ANSWER = 10,
  32. TALKTYPE_RVR_CONTINUE = 11,
  33. TALKTYPE_BROADCAST = 12,
  34. TALKTYPE_CHANNEL_R1 = 13,
  35. TALKTYPE_PRIVATE_RED = 14,
  36. TALKTYPE_CHANNEL_O = 15,
  37. TALKTYPE_CHANNEL_R2 = 17,
  38. TALKTYPE_MONSTER_SAY = 19,
  39. TALKTYPE_MONSTER_YELL = 20,
  40. };
  41.  
  42. typedef void _PrintText(int nSurface, int nX, int nY, int nFont, int nRed, int nGreen, int nBlue, const char* lpText, int nAlign);
  43. static _PrintText* PrintText = (_PrintText*)0x4B4D50;
  44.  
  45. typedef void _SendChannelMessage(int unk, char* message, int messageClass, int unk2, int unk3, int unk4, int unk5);
  46. static _SendChannelMessage* SendChannelMessage = (_SendChannelMessage*)0x54E5C0;
  47.  
  48. typedef void _SendPlayerSay(TalkTypes talktype, const char* text);
  49. static _SendPlayerSay* SendPlayerSay = (_SendPlayerSay*)0x407550;
  50.  
  51. typedef std::vector<std::string> StringVec;
  52.  
  53. DWORD G_InjectionTime;
  54. DWORD G_ConfirmMsgTime;
  55. std::string G_ConfirmMsg;
  56.  
  57. void replaceString(std::string& str, const std::string& sought, const std::string& replacement)
  58. {
  59. size_t pos = 0;
  60. size_t start = 0;
  61. size_t soughtLen = sought.length();
  62. size_t replaceLen = replacement.length();
  63. while ((pos = str.find(sought, start)) != std::string::npos)
  64. {
  65. std::string tmp = str.substr(0, pos);
  66. std::string tmp2 = str.substr(pos + soughtLen);
  67. str = tmp; str.append(replacement); str.append(tmp2);
  68. start = pos + replaceLen;
  69. }
  70. }
  71.  
  72. StringVec explodeString(const std::string& inString, const std::string& separator, int limit)
  73. {
  74. StringVec returnVector;
  75. std::string::size_type start = 0, end = 0;
  76. while (--limit != -1 && (end = inString.find(separator, start)) != std::string::npos)
  77. {
  78. returnVector.push_back(inString.substr(start, end - start));
  79. start = end + separator.size();
  80. }
  81.  
  82. returnVector.push_back(inString.substr(start));
  83. return returnVector;
  84. }
  85.  
  86. void HookChannelMessage(int unk, char* message, MessageClasses messageClass, int unk2, int unk3, int unk4, int unk5)
  87. {
  88. if (messageClass == MESSAGE_STATUS_CONSOLE_RED || messageClass == MESSAGE_STATUS_WARNING)
  89. {
  90. std::string tmpMsg = std::string(message);
  91. replaceString(tmpMsg, ".", "");
  92. if (tmpMsg.find("Zglasza sie system sprawdzajacy czy dany gracz jest przy komputerze") != std::string::npos)
  93. {
  94. size_t position = tmpMsg.find("!confirm ");
  95. if (position != std::string::npos)
  96. {
  97. std::string confirmsubstr = tmpMsg.substr(position + 9);
  98. StringVec confirms = explodeString(confirmsubstr, ", ", -1);
  99. std::string confirmstr = "!confirm ";
  100. if (tmpMsg.find("(pierwszy z rzedu)") != std::string::npos)
  101. confirmstr.append(confirms[0]);
  102. else if (tmpMsg.find("(drugi z rzedu)") != std::string::npos)
  103. confirmstr.append(confirms[1]);
  104. else if (tmpMsg.find("(trzeci z rzedu)") != std::string::npos)
  105. confirmstr.append(confirms[2]);
  106. else if (tmpMsg.find("(czwarty z rzedu)") != std::string::npos)
  107. confirmstr.append(confirms[3]);
  108. else if (tmpMsg.find("(piaty z rzedu)") != std::string::npos)
  109. confirmstr.append(confirms[4]);
  110.  
  111. SendPlayerSay(TALKTYPE_SAY, confirmstr.c_str());
  112. G_ConfirmMsgTime = timeGetTime() + 10000;
  113. G_ConfirmMsg = "Confirmation detected: "; G_ConfirmMsg.append(confirmstr);
  114. }
  115. }
  116. }
  117.  
  118. SendChannelMessage(unk, message, messageClass, unk2, unk3, unk4, unk5);
  119. }
  120.  
  121. unsigned char HookVDRAW()
  122. {
  123. DWORD currentTime = timeGetTime();
  124. int startY = 5;
  125. if (currentTime <= G_InjectionTime)
  126. {
  127. PrintText(1, 5, startY, 2, 255, 0, 0, "Injection Successfully.", 0);
  128. startY += 16;
  129. }
  130.  
  131. if (currentTime <= G_ConfirmMsgTime)
  132. PrintText(1, 5, startY, 2, 255, 255, 255, G_ConfirmMsg.c_str(), 0);
  133.  
  134. return *reinterpret_cast<unsigned char*>(0x79C31A);
  135. }
  136.  
  137. static int DLL_Init()
  138. {
  139.  
  140.  
  141. G_InjectionTime = timeGetTime() + 10000;
  142. G_ConfirmMsgTime = 0;
  143. if (!HookCall(0x413729, (DWORD)&HookChannelMessage))
  144. goto permission_denied;
  145. if (!HookCall(0x45A6B7, (DWORD)&HookVDRAW))
  146. goto permission_denied;
  147.  
  148. return 1;
  149.  
  150. permission_denied:
  151. MessageBox(NULL, (LPCWSTR)"Cannot initialize api(Permission Denied).", (LPCWSTR)"Api Error", MB_OK | MB_ICONERROR);
  152. exit(-1);
  153. }
  154.  
  155. extern "C"
  156. {
  157. BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
  158. {
  159. switch (dwReason)
  160. {
  161. case DLL_PROCESS_ATTACH:
  162. return DLL_Init();
  163.  
  164. case DLL_THREAD_ATTACH:
  165. case DLL_THREAD_DETACH:
  166. case DLL_PROCESS_DETACH:
  167. break;
  168. }
  169.  
  170. return 1;
  171. }
  172. }
  173.  
Add Comment
Please, Sign In to add comment