Guest User

Untitled

a guest
Jun 25th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. #include <cstring>
  2. #include <memory>
  3. #include <Windows.h>
  4. #include <Psapi.h>
  5.  
  6. // client.dll Build 5454
  7. #define IN_JUMP_OFFSET 0xF52670 // /src/game/client/in_main.cpp
  8. #define KEYDOWN_OFFSET 0x165EF // /src/game/client/in_main.cpp
  9. #define KEYUP_OFFSET 0x17305 // /src/game/client/in_main.cpp
  10. #define CC_CTOR_OFFSET 0x986C00 // /src/tier1/convar.cpp
  11.  
  12. using _Msg = void(__cdecl*)(const char* pMsgFormat, ...);
  13. using _Warning = void(__cdecl*)(const char* pMsgFormat, ...);
  14. using _CommandCallbackArgs = void(*)(const void* args);
  15. using _ConCommandCtor = void(__fastcall*)(void* thisptr, void* edx, const char* name, void* callback, const char* helpstr, int flags, void* compfunc);
  16. using _KeyDown = int(__cdecl*)(void* b, const char* c);
  17. using _KeyUp = int(__cdecl*)(void* b, const char* c);
  18.  
  19. struct ConCommandBase {
  20. void* VTable_ConCommandBase;
  21. ConCommandBase* Next;
  22. bool Registered;
  23. const char* Name;
  24. const char* HelpString;
  25. int Flags;
  26. };
  27. struct ConCommand : ConCommandBase {
  28. union {
  29. void* CommandCallbackV1;
  30. void* CommandCallback;
  31. void* CommandCallbackInterface;
  32. };
  33. union {
  34. void* CompletionCallback;
  35. void* CommandCompletionCallback;
  36. };
  37. bool HasCompletionCallback : 1;
  38. bool UsingNewCommandCallback : 1;
  39. bool UsingCommandCallbackInterface : 1;
  40. };
  41. struct ConCommandArgs {
  42. enum {
  43. COMMAND_MAX_ARGC = 64,
  44. COMMAND_MAX_LENGTH = 512,
  45. };
  46. int ArgC;
  47. int ArgV0Size;
  48. char ArgSBuffer[COMMAND_MAX_LENGTH];
  49. char ArgVBuffer[COMMAND_MAX_LENGTH];
  50. const char* ArgV[COMMAND_MAX_ARGC];
  51.  
  52. int count() const {
  53. return this->ArgC;
  54. }
  55. const char* at(int index) const {
  56. return this->ArgV[index];
  57. }
  58. };
  59.  
  60. void* in_jump;
  61. _KeyDown KeyDown;
  62. _KeyUp KeyUp;
  63.  
  64. void IN_BhopDown(const void* ptr)
  65. {
  66. auto args = reinterpret_cast<const ConCommandArgs*>(ptr);
  67. KeyDown(in_jump, (args->count() > 1) ? args->at(1) : NULL);
  68. }
  69. void IN_BhopUp(const void* ptr)
  70. {
  71. auto args = reinterpret_cast<const ConCommandArgs*>(ptr);
  72. KeyUp(in_jump, (args->count() > 1) ? args->at(1) : NULL);
  73. }
  74.  
  75. struct Command {
  76. void* ptr;
  77. std::unique_ptr<uint8_t[]> data;
  78.  
  79. void* create() {
  80. auto size = sizeof(ConCommand);
  81. data = std::make_unique<uint8_t[]>(size);
  82. ptr = data.get();
  83. std::memset(ptr, 0, size);
  84. return ptr;
  85. }
  86. };
  87.  
  88. static Command startbhop;
  89. static Command endbhop;
  90.  
  91. unsigned __stdcall Main(void* args)
  92. {
  93. auto tier0 = GetModuleHandleA("tier0.dll");
  94. auto client = GetModuleHandleA("client.dll");
  95.  
  96. auto Msg = reinterpret_cast<_Msg>(GetProcAddress(tier0, "Msg"));
  97. auto Warning = reinterpret_cast<_Warning>(GetProcAddress(tier0, "Warning"));
  98.  
  99. auto info = MODULEINFO();
  100. if (GetModuleInformation(GetCurrentProcess(), client, &info, sizeof(MODULEINFO))) {
  101. in_jump = reinterpret_cast<void*>((uintptr_t)info.lpBaseOfDll + IN_JUMP_OFFSET);
  102. KeyDown = reinterpret_cast<_KeyDown>((uintptr_t)info.lpBaseOfDll + KEYDOWN_OFFSET);
  103. KeyUp = reinterpret_cast<_KeyUp>((uintptr_t)info.lpBaseOfDll + KEYUP_OFFSET);
  104.  
  105. auto ConCommandCtor = reinterpret_cast<_ConCommandCtor>((uintptr_t)info.lpBaseOfDll + CC_CTOR_OFFSET);
  106. auto CreateCommand = [ConCommandCtor, Msg](const char* name, _CommandCallbackArgs callback, const char* helpstr = "", int flags = 0)
  107. {
  108. auto ret = Command();
  109. ConCommandCtor(ret.create(), nullptr, name, callback, helpstr, flags, nullptr);
  110. Msg("[tsp-bhop] Created ConCommand %s at %p\n", name, ret.ptr);
  111. return ret;
  112. };
  113.  
  114. startbhop = CreateCommand("+bhop", IN_BhopDown);
  115. endbhop = CreateCommand("-bhop", IN_BhopUp);
  116.  
  117. Msg("--- Loaded tsp-bhop v1.0 (by NeKz) ---\n");
  118. return 0;
  119. }
  120.  
  121. Warning("--- Failed to load tsp-bhop! ---\n");
  122. return 1;
  123. }
  124.  
  125. BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved)
  126. {
  127. if (reason == DLL_PROCESS_ATTACH) {
  128. DisableThreadLibraryCalls(module);
  129. CreateThread(0, 0, LPTHREAD_START_ROUTINE(Main), 0, 0, 0);
  130. }
  131. return TRUE;
  132. }
Add Comment
Please, Sign In to add comment