Guest User

Untitled

a guest
Jan 27th, 2021
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.34 KB | None | 0 0
  1. //Hooking.cpp
  2. #pragma once
  3. #include "stdafx.h"
  4.  
  5.  
  6. using namespace Memory;
  7.  
  8. ScriptThread*(*GetActiveThread)() = nullptr;
  9. HMODULE _hmoduleDLL;
  10. HANDLE mainFiber;
  11. DWORD wakeAt;
  12.  
  13. std::vector<LPVOID> Hooking::m_hooks;
  14. uint64_t* Hooking::m_frameCount;
  15. fpIsDLCPresent Hooking::is_DLC_present;
  16. fpStatSetInt Hooking::stat_set_int;
  17. static eGameState* m_gameState;
  18. static uint64_t m_worldPtr;
  19. static BlipList* m_blipList;
  20. static Hooking::NativeRegistrationNew** m_registrationTable;
  21. static std::unordered_map<uint64_t, Hooking::NativeHandler> m_handlerCache;
  22. static std::vector<LPVOID> m_hookedNative;
  23. static __int64** m_globalPtr;
  24.  
  25. const int EVENT_COUNT = 78;
  26. static std::vector<void*> EventPtr;
  27. static char EventRestore[EVENT_COUNT] = {};
  28.  
  29. bool rdev;
  30.  
  31. /* Start Hooking */
  32. void Hooking::Start(HMODULE hmoduleDLL)
  33. {
  34. _hmoduleDLL = hmoduleDLL;
  35. Log::Init(hmoduleDLL);
  36. FindPatterns();
  37. if (!InitializeHooks()) Cleanup();
  38. }
  39. BOOL Hooking::InitializeHooks()
  40. {
  41. BOOL returnVal = TRUE;
  42.  
  43. if (!iHook.Initialize()) {
  44.  
  45. Log::Error("Failed to initialize InputHook");
  46. returnVal = FALSE;
  47. }
  48.  
  49. if (MH_Initialize() != MH_OK) {
  50. Log::Error("MinHook failed to initialize");
  51. returnVal = FALSE;
  52. }
  53.  
  54. if (!HookNatives()) {
  55.  
  56. Log::Error("Failed to initialize NativeHooks");
  57. returnVal = FALSE;
  58. }
  59.  
  60. return returnVal;
  61. }
  62.  
  63. template <typename T>
  64. bool Native(DWORD64 hash, LPVOID hookFunction, T** trampoline)
  65. {
  66. if (*reinterpret_cast<*LPVOID>(trampoline) != NULL)
  67. return true;
  68. auto originalFunction = Hooking::GetNativeHandler(hash);
  69. if (originalFunction != 0) {
  70. MH_STATUS createHookStatus = MH_CreateHook(originalFunction, hookFunction, reinterpret_cast<*LPVOID>(trampoline));
  71. if (((createHookStatus == MH_OK) || (createHookStatus == MH_ERROR_ALREADY_CREATED)) && (MH_EnableHook(originalFunction) == MH_OK))
  72. {
  73. m_hookedNative.push_back((LPVOID)originalFunction);
  74. DEBUGMSG("Hooked Native 0x%#p", hash);
  75. return true;
  76. }
  77. }
  78.  
  79. return false;
  80. }
  81.  
  82. uint64_t CMetaData::m_begin = 0;
  83. uint64_t CMetaData::m_end = 0;
  84. DWORD CMetaData::m_size = 0;
  85.  
  86. uint64_t CMetaData::begin()
  87. {
  88. return m_begin;
  89. }
  90. uint64_t CMetaData::end()
  91. {
  92. return m_end;
  93. }
  94. DWORD CMetaData::size()
  95. {
  96. return m_size;
  97. }
  98.  
  99. void CMetaData::init()
  100. {
  101. if (m_begin && m_size)
  102. return;
  103.  
  104. m_begin = (uint64_t)GetModuleHandleA(nullptr);
  105. const IMAGE_DOS_HEADER* headerDos = (const IMAGE_DOS_HEADER*)m_begin;
  106. const IMAGE_NT_HEADERS* headerNt = (const IMAGE_NT_HEADERS64*)((const BYTE*)headerDos + headerDos->e_lfanew);
  107. m_size = headerNt->OptionalHeader.SizeOfCode;
  108. m_end = m_begin + m_size;
  109. return;
  110. }
  111.  
  112. bool stealth10m = false;
  113.  
  114.  
  115. fpIsDLCPresent OG_IS_DLC_PRESENT = nullptr;
  116. BOOL __cdecl HK_IS_DLC_PRESENT(Hash dlchash)
  117. {
  118.  
  119. if (stealth10m) {//Stealth 10M
  120. Any transactionID = GAMEPLAY::GET_RANDOM_INT_IN_RANGE(1000000000, 2999999999);
  121. if (UNK3::_NETWORK_SHOP_BEGIN_SERVICE(&transactionID, 1474183246, 312105838, 1445302971, 10000000, 4))
  122. UNK3::_NETWORK_SHOP_CHECKOUT_START(transactionID);
  123. }
  124.  
  125. static uint64_t last = 0;
  126. uint64_t cur = *Hooking::m_frameCount;
  127. if (last != cur)
  128. {
  129. last = cur;
  130. Hooking::onTickInit();
  131. }
  132. if (rdev) {
  133. if (dlchash == 2532323046)return true;
  134. else return OG_IS_DLC_PRESENT(dlchash);
  135. }
  136. else
  137. return OG_IS_DLC_PRESENT(dlchash);
  138. }
  139. typedef bool(__cdecl * pNetworkShopBeginService)(int* value, Any p1, Any p2, Any p3, Any p4, int p5);
  140. pNetworkShopBeginService hNetworkShopBeginService;
  141. bool fNetworkShopBeginService(int* value, Any p1, Any p2, Any p3, Any p4, int p5) {
  142. if (stealth10m) {
  143. return hNetworkShopBeginService(value, p1, 312105838, p3, 10000000, 4);
  144.  
  145. }
  146.  
  147. return hNetworkShopBeginService(value, p1, p2, p3, p4, p5);
  148. }
  149. Hooking::NativeHandler ORIG_WAIT = NULL;
  150. void* __cdecl MY_WAIT(NativeContext *cxt)
  151. {
  152. static int lastThread = 0;
  153. int threadId = SCRIPT::GET_ID_OF_THIS_THREAD();
  154. if (!lastThread)
  155. {
  156. char* name = SCRIPT::_GET_NAME_OF_THREAD(threadId);
  157. if (strcmp(name, "main_persistent") == 0)
  158. {
  159. lastThread = threadId;
  160. Log::Msg("Hooked Script NAME: %s ID: %i", name, threadId);
  161. }
  162. }
  163. if (threadId == lastThread) Hooking::onTickInit();
  164. ORIG_WAIT(cxt);
  165. return cxt;
  166. }
  167.  
  168. Hooking::NativeHandler ORIG_NETWORK_SESSION_KICK_PLAYER = NULL;
  169. void *__cdecl MY_NETWORK_SESSION_KICK_PLAYER(NativeContext* cxt)
  170. {
  171. Player player = cxt->GetArgument<int>(0);
  172. if (player == PLAYER::PLAYER_ID())
  173. {
  174. ORIG_NETWORK_SESSION_KICK_PLAYER(cxt);
  175. }
  176. return nullptr;
  177. }
  178.  
  179.  
  180. Hooking::NativeHandler ORIG_NETWORK_ADD_PED_TO_SYNCHRONISED_SCENE = NULL;
  181. void *__cdecl MY_NETWORK_ADD_PED_TO_SYNCHRONISED_SCENE(NativeContext* cxt)
  182. {
  183. Player player = cxt->GetArgument<int>(0);
  184. if (player == PLAYER::PLAYER_ID())
  185. {
  186. ORIG_NETWORK_ADD_PED_TO_SYNCHRONISED_SCENE(cxt);
  187. }
  188. return nullptr;
  189. }
  190.  
  191. Hooking::NativeHandler ORIG_ATTACH_ENTITY_TO_ENTITY = NULL;
  192. void *__cdecl MY_ATTACH_ENTITY_TO_ENTITY(NativeContext* cxt)
  193. {
  194. Player player = cxt->GetArgument<int>(0);
  195. if (player == PLAYER::PLAYER_ID())
  196. {
  197. ORIG_ATTACH_ENTITY_TO_ENTITY(cxt);
  198. }
  199. return nullptr;
  200. }
  201.  
  202. Hooking::NativeHandler ORIG_CLEAR_PED_TASKS_IMMEDIATELY = NULL;
  203. void *__cdecl MY_CLEAR_PED_TASKS_IMMEDIATELY(NativeContext *cxt)
  204. {
  205. if (cxt->GetArgument<Ped>(0) != PLAYER::PLAYER_PED_ID())
  206. {
  207. ORIG_CLEAR_PED_TASKS_IMMEDIATELY(cxt);
  208. }
  209.  
  210. return nullptr;
  211. }
  212.  
  213. Hooking::NativeHandler ORIG_CLEAR_PED_TASKS = NULL;
  214. void *__cdecl MY_CLEAR_PED_TASKS(NativeContext *cxt)
  215. {
  216. if (cxt->GetArgument<Ped>(0) != PLAYER::PLAYER_PED_ID())
  217. {
  218. ORIG_CLEAR_PED_TASKS(cxt);
  219. }
  220.  
  221. return nullptr;
  222. }
  223.  
  224. Hooking::NativeHandler ORIG_CLEAR_PED_SECONDARY_TASK = NULL;
  225. void *__cdecl MY_CLEAR_PED_SECONDARY_TASK(NativeContext *cxt)
  226. {
  227. if (cxt->GetArgument<Ped>(0) != PLAYER::PLAYER_PED_ID())
  228. {
  229. ORIG_CLEAR_PED_SECONDARY_TASK(cxt);
  230. }
  231. return nullptr;
  232. }
  233.  
  234. Hooking::NativeHandler ORIG_CLONE_PED = NULL;
  235. void *__cdecl MY_CLONE_PED(NativeContext *cxt)
  236. {
  237. if (cxt->GetArgument<Ped>(0) != PLAYER::PLAYER_PED_ID())
  238. {
  239. ORIG_CLONE_PED(cxt);
  240. }
  241. return nullptr;
  242. }
  243.  
  244.  
  245. bool Hooking::HookNatives()
  246. {
  247. MH_STATUS status = MH_CreateHook(Hooking::is_DLC_present, HK_IS_DLC_PRESENT, (void**)&OG_IS_DLC_PRESENT);
  248. if ((status != MH_OK && status != MH_ERROR_ALREADY_CREATED) || MH_EnableHook(Hooking::is_DLC_present) != MH_OK)
  249. return false;
  250. Hooking::m_hooks.push_back(Hooking::is_DLC_present);
  251. return true;
  252. }
  253.  
  254. void __stdcall ScriptFunction(LPVOID lpParameter)
  255. {
  256. try
  257. {
  258. ScriptMain();
  259. }
  260. catch (...)
  261. {
  262. Log::Fatal("Failed scriptFiber");
  263. }
  264. }
  265.  
  266. void Hooking::onTickInit()
  267. {
  268. if (mainFiber == nullptr)
  269. mainFiber = ConvertThreadToFiber(nullptr);
  270.  
  271. if (timeGetTime() < wakeAt)
  272. return;
  273.  
  274. static HANDLE scriptFiber;
  275. if (scriptFiber)
  276. SwitchToFiber(scriptFiber);
  277. else
  278. scriptFiber = CreateFiber(NULL, ScriptFunction, nullptr);
  279. }
  280.  
  281. void Hooking::FailPatterns(const char* name)
  282. {
  283. char buf[4096];
  284. sprintf_s(buf, "finding %s", name);
  285. Log::Error(buf);
  286. Cleanup();
  287. }
  288.  
  289. /*
  290. //CPatternResult
  291. */
  292.  
  293. CPatternResult::CPatternResult(void* pVoid) :
  294. m_pVoid(pVoid)
  295. {}
  296. CPatternResult::CPatternResult(void* pVoid, void* pBegin, void* pEnd) :
  297. m_pVoid(pVoid),
  298. m_pBegin(pBegin),
  299. m_pEnd(pEnd)
  300. {}
  301. CPatternResult::~CPatternResult() {}
  302.  
  303. /*
  304. //CPattern Public
  305. */
  306.  
  307. CPattern::CPattern(char* szByte, char* szMask) :
  308. m_szByte(szByte),
  309. m_szMask(szMask),
  310. m_bSet(false)
  311. {}
  312. CPattern::~CPattern() {}
  313.  
  314. CPattern& CPattern::find(int i, uint64_t startAddress)
  315. {
  316. match(i, startAddress, false);
  317. if (m_result.size() <= i)
  318. m_result.push_back(nullptr);
  319. return *this;
  320. }
  321.  
  322. CPattern& CPattern::virtual_find(int i, uint64_t startAddress)
  323. {
  324. match(i, startAddress, true);
  325. if (m_result.size() <= i)
  326. m_result.push_back(nullptr);
  327. return *this;
  328. }
  329.  
  330. CPatternResult CPattern::get(int i)
  331. {
  332. if (m_result.size() > i)
  333. return m_result[i];
  334. return nullptr;
  335. }
  336.  
  337. /*
  338. //CPattern Private
  339. */
  340. bool CPattern::match(int i, uint64_t startAddress, bool virt)
  341. {
  342. if (m_bSet)
  343. return false;
  344. uint64_t begin = 0;
  345. uint64_t end = 0;
  346. if (!virt)
  347. {
  348. CMetaData::init();
  349. begin = CMetaData::begin() + startAddress;
  350. end = CMetaData::end();
  351. if (begin >= end)
  352. return false;
  353. }
  354. int j = 0;
  355. do
  356. {
  357. if (virt)
  358. begin = virtual_find_pattern(startAddress, (BYTE*)m_szByte, m_szMask) + 1;
  359. else
  360. begin = find_pattern(begin, end, (BYTE*)m_szByte, m_szMask) + 1;
  361. if (begin == NULL)
  362. break;
  363. j++;
  364. } while (j < i);
  365.  
  366. m_bSet = true;
  367. return true;
  368. }
  369.  
  370. bool CPattern::byte_compare(const BYTE* pData, const BYTE* btMask, const char* szMask)
  371. {
  372. for (; *szMask; ++szMask, ++pData, ++btMask)
  373. if (*szMask == 'x' && *pData != *btMask)
  374. break;
  375. if ((*szMask) != 0)
  376. return false;
  377. return true;
  378. }
  379.  
  380.  
  381. uint64_t CPattern::find_pattern(uint64_t address, uint64_t end, BYTE *btMask, char *szMask)
  382. {
  383. size_t len = strlen(szMask) + 1;
  384. for (uint64_t i = 0; i < (end - address - len); i++)
  385. {
  386. BYTE* ptr = (BYTE*)(address + i);
  387. if (byte_compare(ptr, btMask, szMask))
  388. {
  389. m_result.push_back(CPatternResult((void*)(address + i)));
  390. return address + i;
  391. }
  392. }
  393. return NULL;
  394. }
  395.  
  396. uint64_t CPattern::virtual_find_pattern(uint64_t address, BYTE *btMask, char *szMask)
  397. {
  398. MEMORY_BASIC_INFORMATION mbi;
  399. char* pStart = nullptr;
  400. char* pEnd = nullptr;
  401. char* res = nullptr;
  402. size_t maskLen = strlen(szMask);
  403.  
  404. while (res == nullptr && sizeof(mbi) == VirtualQuery(pEnd, &mbi, sizeof(mbi)))
  405. {
  406. pStart = pEnd;
  407. pEnd += mbi.RegionSize;
  408. if (mbi.Protect != PAGE_READWRITE || mbi.State != MEM_COMMIT)
  409. continue;
  410.  
  411. for (int i = 0; pStart < pEnd - maskLen && res == nullptr; ++pStart)
  412. {
  413. if (byte_compare((BYTE*)pStart, btMask, szMask))
  414. {
  415. m_result.push_back(CPatternResult((void*)pStart, mbi.BaseAddress, pEnd));
  416. res = pStart;
  417. }
  418. }
  419.  
  420. mbi = {};
  421. }
  422. return (uint64_t)res;
  423. }
  424.  
  425. void failPat(const char* name)
  426. {
  427. Log::Fatal("Failed to find %s pattern.", name);
  428. exit(0);
  429. }
  430.  
  431. template <typename T>
  432. void setPat
  433. (
  434. const char* name,
  435. char* pat,
  436. char* mask,
  437. T** out,
  438. bool rel,
  439. int offset = 0,
  440. int deref = 0,
  441. int skip = 0
  442. )
  443. {
  444. T* ptr = nullptr;
  445.  
  446. CPattern pattern(pat, mask);
  447. pattern.find(1 + skip);
  448. if (rel)
  449. ptr = pattern.get(skip).get_rel<T>(offset);
  450. else
  451. ptr = pattern.get(skip).get<T>(offset);
  452.  
  453. while (true)
  454. {
  455. if (ptr == nullptr)
  456. failPat(name);
  457.  
  458. if (deref <= 0)
  459. break;
  460. ptr = *(T**)ptr;
  461. --deref;
  462. }
  463.  
  464. *out = ptr;
  465. return;
  466. }
  467.  
  468. template <typename T>
  469. void setFn
  470. (
  471. const char* name,
  472. char* pat,
  473. char* mask,
  474. T* out,
  475. int skip = 0
  476. )
  477. {
  478. char* ptr = nullptr;
  479.  
  480. CPattern pattern(pat, mask);
  481. pattern.find(1 + skip);
  482. ptr = pattern.get(skip).get<char>(0);
  483.  
  484. if (ptr == nullptr)
  485. failPat(name);
  486.  
  487. *out = (T)ptr;
  488. return;
  489. }
  490.  
  491. void Hooking::FindPatterns()
  492. {
  493. HANDLE steam = GetModuleHandleA("steam_api64.dll");
  494.  
  495. auto p_activeThread = pattern("E8 ? ? ? ? 48 8B 88 10 01 00 00");
  496. auto p_blipList = pattern("4C 8D 05 ? ? ? ? 0F B7 C1");
  497. auto p_fixVector3Result = pattern("83 79 18 00 48 8B D1 74 4A FF 4A 18");
  498. auto p_gameLegals = pattern("72 1F E8 ? ? ? ? 8B 0D");
  499. auto p_gameLogos = pattern("70 6C 61 74 66 6F 72 6D 3A");
  500. auto p_gameState = pattern("83 3D ? ? ? ? ? 8A D9 74 0A");
  501. auto p_modelCheck = pattern("48 85 C0 0F 84 ? ? ? ? 8B 48 50");
  502. auto p_modelSpawn = pattern("48 8B C8 FF 52 30 84 C0 74 05 48");
  503. auto p_nativeTable = pattern("76 32 48 8B 53 40 48 8D 0D");
  504. auto p_worldPtr = pattern("48 8B 05 ? ? ? ? 45 ? ? ? ? 48 8B 48 08 48 85 C9 74 07");
  505. auto p_globalPtr = pattern("4C 8D 05 ? ? ? ? 4D 8B 08 4D 85 C9 74 11");
  506. auto p_eventHook = pattern("48 83 EC 28 E8 ? ? ? ? 48 8B 0D ? ? ? ? 4C 8D 0D ? ? ? ? 4C 8D 05 ? ? ? ? BA 03");
  507.  
  508. setPat<uint64_t>("frame count",
  509. "\x8B\x15\x00\x00\x00\x00\x41\xFF\xCF",
  510. "xx????xxx",
  511. &Hooking::m_frameCount,
  512. true,
  513. 2);
  514.  
  515. setFn<fpIsDLCPresent>("is_DLC_present",
  516. "\x48\x89\x5C\x24\x00\x57\x48\x83\xEC\x20\x81\xF9\x00\x00\x00\x00",
  517. "xxxx?xxxxxxx????",
  518. &Hooking::is_DLC_present);
  519.  
  520. setFn<fpStatSetInt>("stat_set_int",
  521. "\x89\x54\x24\x10\x55\x53\x56\x57\x41\x57",
  522. "xxxxxxxxxx",
  523. &Hooking::stat_set_int);
  524.  
  525. char * c_location = nullptr;
  526. void * v_location = nullptr;
  527.  
  528. Sleep(5000);
  529.  
  530. Log::Msg("Getting Game State...");
  531. c_location = p_gameState.count(1).get(0).get<char>(2);
  532. c_location == nullptr ? FailPatterns("gameState") : m_gameState = reinterpret_cast<decltype(m_gameState)>(c_location + *(int32_t*)c_location + 5);
  533.  
  534. Log::Msg("Getting vector3 result fixer func...");
  535. v_location = p_fixVector3Result.count(1).get(0).get<void>(0);
  536. if (v_location != nullptr) scrNativeCallContext::SetVectorResults = (void(*)(scrNativeCallContext*))(v_location);
  537.  
  538. Log::Msg("Getting native registration table...");
  539. c_location = p_nativeTable.count(1).get(0).get<char>(9);
  540. c_location == nullptr ? FailPatterns("native registration table") : m_registrationTable = reinterpret_cast<decltype(m_registrationTable)>(c_location + *(int32_t*)c_location + 4);
  541.  
  542. Log::Msg("Getting World Pointer...");
  543. c_location = p_worldPtr.count(1).get(0).get<char>(0);
  544. c_location == nullptr ? FailPatterns("world Pointer") : m_worldPtr = reinterpret_cast<uint64_t>(c_location) + *reinterpret_cast<int*>(reinterpret_cast<uint64_t>(c_location) + 3) + 7;
  545.  
  546. Log::Msg("Getting Blip List...");
  547. c_location = p_blipList.count(1).get(0).get<char>(0);
  548. c_location == nullptr ? FailPatterns("blip List") : m_blipList = (BlipList*)(c_location + *reinterpret_cast<int*>(c_location + 3) + 7);
  549.  
  550.  
  551. Log::Msg("Bypassing Object restrictions..");
  552.  
  553. if (p_modelCheck.size() > 0) {
  554.  
  555. v_location = p_modelCheck.count(1).get(0).get<void>(0);
  556. Memory::nop(v_location, 24);
  557. }
  558.  
  559. if (p_modelSpawn.size() > 0) {
  560.  
  561. v_location = p_modelSpawn.count(1).get(0).get<void>(8);
  562. Memory::nop(v_location, 2);
  563. }
  564.  
  565. Log::Msg("Getting active script thread...");
  566. c_location = p_activeThread.count(1).get(0).get<char>(1);
  567. c_location == nullptr ? FailPatterns("Active Script Thread") : GetActiveThread = reinterpret_cast<decltype(GetActiveThread)>(c_location + *(int32_t*)c_location + 4);
  568.  
  569. Log::Msg("Getting World Pointer...");
  570. c_location = p_globalPtr.count(1).get(0).get<char>(0);
  571. __int64 patternAddr = NULL;
  572. c_location == nullptr ? FailPatterns("globalTable") : patternAddr = reinterpret_cast<decltype(patternAddr)>(c_location);
  573. m_globalPtr = (__int64**)(patternAddr + *(int*)(patternAddr + 3) + 7);
  574.  
  575. Log::Msg("Getting Event Hook...");
  576. if ((c_location = p_eventHook.count(1).get(0).get<char>(0)))
  577. {
  578. int i = 0, j = 0, matches = 0, found = 0;
  579. char* pattern = "\x4C\x8D\x05";
  580. while (found != EVENT_COUNT)
  581. {
  582. if (c_location[i] == pattern[j])
  583. {
  584. if (++matches == 3)
  585. {
  586. EventPtr.push_back((void*)(reinterpret_cast<uint64_t>(c_location + i - j) + *reinterpret_cast<int*>(c_location + i + 1) + 7));
  587. found++;
  588. j = matches = 0;
  589. }
  590. j++;
  591. }
  592. else
  593. {
  594. matches = j = 0;
  595. }
  596. i++;
  597. }
  598. }
  599.  
  600. Log::Msg("Initializing natives...");
  601. CrossMapping::initNativeMap();
  602.  
  603. Log::Msg("Checking if GTA V is ready...");
  604. while (*m_gameState != GameStatePlaying) {
  605. Sleep(200);
  606. }
  607. Log::Msg("GTA V ready!");
  608. }
  609.  
  610. static Hooking::NativeHandler _Handler(uint64_t origHash)
  611. {
  612. uint64_t newHash = CrossMapping::MapNative(origHash);
  613. if (newHash == 0)
  614. {
  615. return nullptr;
  616. }
  617.  
  618. Hooking::NativeRegistrationNew * table = m_registrationTable[newHash & 0xFF];
  619.  
  620. for (; table; table = table->getNextRegistration())
  621. {
  622. for (uint32_t i = 0; i < table->getNumEntries(); i++)
  623. {
  624. if (newHash == table->getHash(i))
  625. {
  626. return table->handlers[i];
  627. }
  628. }
  629. }
  630. return nullptr;
  631. }
  632.  
  633. Hooking::NativeHandler Hooking::GetNativeHandler(uint64_t origHash)
  634. {
  635. auto& handler = m_handlerCache[origHash];
  636.  
  637. if (handler == nullptr)
  638. {
  639. handler = _Handler(origHash);
  640. }
  641.  
  642. return handler;
  643. }
  644.  
  645. eGameState Hooking::GetGameState()
  646. {
  647. return *m_gameState;
  648. }
  649.  
  650. uint64_t Hooking::getWorldPtr()
  651. {
  652. return m_worldPtr;
  653. }
  654. void WAIT(DWORD ms)
  655. {
  656. wakeAt = timeGetTime() + ms;
  657. SwitchToFiber(mainFiber);
  658. }
  659.  
  660. void Hooking::Cleanup()
  661. {
  662.  
  663.  
  664.  
  665. Log::Msg("Cleaning up hooks");
  666. for (int i = 0; i < m_hooks.size(); i++)
  667. if (MH_DisableHook(m_hooks[i]) != MH_OK && MH_RemoveHook(m_hooks[i]) != MH_OK)
  668. Log::Error("Failed to unhook %p", (void*)m_hooks[i]);
  669. MH_Uninitialize();
  670.  
  671. FreeLibraryAndExitThread(static_cast<HMODULE>(_hmoduleDLL), 1);
  672. }
  673.  
  674.  
  675.  
  676. __int64** Hooking::getGlobalPtr()
  677. {
  678. return m_globalPtr;
  679. }
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
Add Comment
Please, Sign In to add comment