Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #include <thread>
  2. #include "Hooks.h"
  3. #include "Utils\Utils.h"
  4. #include "Utils\GlobalVars.h"
  5. #include "Utils/Math.h"
  6. #include <iostream>
  7. #include <ctime>
  8. #include <fstream>
  9. #include <string>
  10. #include "Features/SkinChanger/KnifeHandler.h"
  11.  
  12. inline float RandomFloat(float min, float max) {
  13. static auto fn = (decltype(&RandomFloat))(GetProcAddress(GetModuleHandle("vstdlib.dll"), "RandomFloat"));
  14. return fn(min, max);
  15. }
  16.  
  17. #include <ShlObj.h>
  18. DWORD WINAPI OnDllAttach(PVOID base)
  19. {
  20. #ifdef _DEBUG
  21. AllocConsole();
  22. freopen_s((FILE**)stdin, "CONIN$", "r", stdin); // ----------------------------------------------
  23. freopen_s((FILE**)stdout, "CONOUT$", "w", stdout); // Make iostream library use our console handle
  24. ----------------------------------------------
  25. SetConsoleTitleA(" debug console");
  26. #endif
  27.  
  28. Utils::Log("Console Allocated!");
  29. Hooks::Init();
  30.  
  31. // доделать обратную загрузку
  32. while (true)
  33. {
  34. using namespace std::literals::chrono_literals;
  35. std::this_thread::sleep_for(1s);
  36. }
  37. FreeLibraryAndExitThread(static_cast<HMODULE>(base), 1);
  38. }
  39.  
  40. VOID WINAPI OnDllDetach()
  41. {
  42. #ifdef _DEBUG
  43. fclose((FILE*)stdin);
  44. fclose((FILE*)stdout);
  45.  
  46. HWND hw_ConsoleHwnd = GetConsoleWindow();
  47. FreeConsole();
  48. PostMessageW(hw_ConsoleHwnd, WM_CLOSE, 0, 0);
  49. #endif
  50. }
  51.  
  52. BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
  53. {
  54. if (dwReason == DLL_PROCESS_ATTACH)
  55. {
  56. DisableThreadLibraryCalls(hModule);
  57. auto h = CreateThread(nullptr, NULL, OnDllAttach, hModule, NULL, nullptr);
  58. Globals::Module = HMODULE(hModule);
  59. CloseHandle(h);
  60. }
  61. else if (dwReason == DLL_PROCESS_DETACH)
  62. {
  63. if (!lpReserved)
  64. {
  65. Hooks::Restore();
  66. using namespace std::literals::chrono_literals;
  67. std::this_thread::sleep_for(1s);
  68. }
  69.  
  70. OnDllDetach();
  71. }
  72. return TRUE;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement