Advertisement
CasualGamer

Terraria 3/3

Dec 5th, 2019
2,128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.17 KB | None | 0 0
  1. // dllmain.cpp : Defines the entry point for the DLL application.
  2. #include <Windows.h>
  3. #include<iostream>
  4. #include <vector>
  5.  
  6. HMODULE myhModule;
  7.  
  8. DWORD __stdcall EjectThread(LPVOID lpParameter) {
  9.     Sleep(100);
  10.     FreeLibraryAndExitThread(myhModule, 0);
  11. }
  12.  
  13. DWORD GetAddressFromSignature(std::vector<int> signature, DWORD startaddress=0, DWORD endaddress=0) {
  14.     SYSTEM_INFO si;
  15.     GetSystemInfo(&si);
  16.     if (startaddress == 0) {
  17.         startaddress = (DWORD)(si.lpMinimumApplicationAddress);
  18.     }
  19.     if (endaddress == 0) {
  20.         endaddress = (DWORD)(si.lpMaximumApplicationAddress);
  21.     }
  22.  
  23.     MEMORY_BASIC_INFORMATION mbi{ 0 };
  24.     DWORD protectflags = (PAGE_GUARD | PAGE_NOCACHE | PAGE_NOACCESS);
  25.  
  26.     for (DWORD i = startaddress; i < endaddress -signature.size(); i++) {
  27.         //std::cout << "scanning: " << std::hex << i << std::endl;
  28.         if (VirtualQuery((LPCVOID)i, &mbi, sizeof(mbi))) {
  29.             if (mbi.Protect & protectflags || !(mbi.State & MEM_COMMIT)) {
  30.                 std::cout << "Bad Region! Region Base Address: " << mbi.BaseAddress << " | Region end address: " << std::hex << (int)((DWORD)mbi.BaseAddress + mbi.RegionSize) << std::endl;
  31.                 i += mbi.RegionSize;
  32.                 continue; // if bad adress then dont read from it
  33.             }
  34.             std::cout << "Good Region! Region Base Address: " << mbi.BaseAddress << " | Region end address: " << std::hex << (int)((DWORD)mbi.BaseAddress + mbi.RegionSize) << std::endl;
  35.             for (DWORD k = (DWORD)mbi.BaseAddress; k < (DWORD)mbi.BaseAddress + mbi.RegionSize - signature.size(); k++) {
  36.                 for (DWORD j = 0; j < signature.size(); j++) {
  37.                     if (signature.at(j) != -1 && signature.at(j) != *(byte*)(k + j))
  38.                         break;
  39.                     if (j + 1 == signature.size())
  40.                         return k;
  41.                 }
  42.             }
  43.             i = (DWORD)mbi.BaseAddress + mbi.RegionSize;
  44.         }
  45.     }
  46.     return NULL;
  47. }
  48.  
  49. struct _Player {
  50.     void* pThis = NULL;
  51.     bool bghost = false;
  52.     DWORD ghostoffset = 0x00000549;
  53.     DWORD xoffset = 0x20;
  54.     DWORD yoffset = 0x24;
  55.     DWORD xteleport = 0;
  56.     DWORD yteleport = 0;
  57. }Player;
  58.  
  59. DWORD GetPlayerBase() {
  60.     std::vector<int> sig = { 0xA1, -1, -1, -1, -1, 0x8B, 0x15, -1, -1, -1, -1, 0x3B, 0x50, 0x04, 0x73, 0x05, 0x8B, 0x44, 0x90, 0x08 };
  61.     DWORD Entry = GetAddressFromSignature(sig, 0x4A000000, 0x50000000);
  62.     if (Entry == NULL)
  63.         Entry = GetAddressFromSignature(sig, 0x1F000000, 0x4A000000);
  64.     if (Entry == NULL)
  65.         Entry = GetAddressFromSignature(sig);
  66.     DWORD eax = *(DWORD*)(*(DWORD*)(Entry + 0x01));
  67.     DWORD edx = *(DWORD*)(*(DWORD*)(Entry + 0x07));
  68.     return *(DWORD*)(eax + edx * 4 + 0x08);
  69. }
  70.  
  71. DWORD WINAPI Menue() {
  72.     AllocConsole();
  73.     FILE* fp;
  74.     freopen_s(&fp, "CONOUT$", "w", stdout); // output only
  75.     std::cout << "Press 0 to Exit | Press 1 for Scanning" << std::endl;
  76.     while (1) {
  77.         Sleep(100);
  78.         if (GetAsyncKeyState(VK_NUMPAD0))
  79.             break;
  80.         if (GetAsyncKeyState(VK_NUMPAD1)) {
  81.             std::cout << "Starting ghost function" << std::endl;
  82.             if (Player.pThis == NULL)
  83.                 Player.pThis = (void*)GetPlayerBase();
  84.             if (!Player.bghost) {
  85.                 *(byte*)((DWORD)Player.pThis + Player.ghostoffset) = 0x01; //turn ghost on
  86.             }
  87.             else {
  88.                 *(byte*)((DWORD)Player.pThis + Player.ghostoffset) = 0x00; //turn ghost off
  89.             }
  90.             Player.bghost = !Player.bghost;
  91.             Sleep(500);
  92.         }
  93.         if (GetAsyncKeyState(VK_NUMPAD2)) {
  94.             std::cout << "setting teleport location" << std::endl;
  95.             if (Player.pThis == NULL)
  96.                 Player.pThis = (void*)GetPlayerBase();
  97.             Player.xteleport = *(DWORD*)((DWORD)Player.pThis + Player.xoffset);
  98.             Player.yteleport = *(DWORD*)((DWORD)Player.pThis + Player.yoffset);
  99.         }
  100.         if (GetAsyncKeyState(VK_NUMPAD3)) {
  101.             if (Player.xteleport != 0) { // only teleport if we have a location set
  102.                 *(DWORD*)((DWORD)Player.pThis + Player.xoffset) = Player.xteleport;
  103.                 *(DWORD*)((DWORD)Player.pThis + Player.yoffset) = Player.yteleport;
  104.             }
  105.         }
  106.     }
  107.     fclose(fp);
  108.     FreeConsole();
  109.     CreateThread(0, 0, EjectThread, 0, 0, 0);
  110.     int i = 0;
  111.     return 0;
  112. }
  113.  
  114.  
  115. BOOL APIENTRY DllMain(HMODULE hModule,
  116.     DWORD  ul_reason_for_call,
  117.     LPVOID lpReserved
  118. )
  119. {
  120.     switch (ul_reason_for_call)
  121.     {
  122.     case DLL_PROCESS_ATTACH:
  123.         myhModule = hModule;
  124.         CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Menue, NULL, 0, NULL);
  125.     case DLL_THREAD_ATTACH:
  126.     case DLL_THREAD_DETACH:
  127.     case DLL_PROCESS_DETACH:
  128.         break;
  129.     }
  130.     return TRUE;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement