HITOA

SOT ip/port viewer overlay

Feb 1st, 2021 (edited)
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <Psapi.h>
  4. #include <TlHelp32.h>
  5. #include <vector>
  6. #include <thread>
  7. #include <sstream>
  8.  
  9. typedef struct _SotConnectionData {
  10.     LPVOID ptrIpv4; //Unicode l24
  11.     BYTE p0[8];
  12.     int port;
  13. }SotConnectionData, * LPSotConnectionData;
  14.  
  15. typedef struct _SOTDATA {
  16.     bool isConnected;
  17.     wchar_t ipv4[24];
  18.     int port;
  19. }SOTDATA, * LPSOTDATA;
  20.  
  21. int baseOffsets = 0x0683B230;
  22. std::vector<int> offsets{ 0xA00, 0x0, 0xF0 };
  23.  
  24. const wchar_t* nSOT = L"SoTGame.exe";
  25. const wchar_t* wClassName = L"SOTViewerClass";
  26. int width, height;
  27. HANDLE hSOT = NULL;
  28. HMODULE hMOD;
  29. HWND hwnd;
  30. HWND hwndSOT;
  31. SOTDATA sotData;
  32.  
  33. void Update() {
  34.     LPBYTE p;
  35.     SotConnectionData sotConnectionData;
  36.  
  37.     while (true) {
  38.         p = (LPBYTE)hMOD + baseOffsets;
  39.         for (int i = 0; i < offsets.size(); i++) {
  40.             ReadProcessMemory(hSOT, p, &p, sizeof(p), nullptr);
  41.             p += offsets[i];
  42.         }
  43.  
  44.         ReadProcessMemory(hSOT, p, &sotConnectionData, sizeof(sotConnectionData), nullptr);
  45.  
  46.         if ((long)sotConnectionData.ptrIpv4 == 0) {
  47.             sotData.isConnected = false;
  48.         }
  49.         else {
  50.             sotData.isConnected = true;
  51.             ReadProcessMemory(hSOT, sotConnectionData.ptrIpv4, sotData.ipv4, sizeof(wchar_t) * 24, nullptr);
  52.             sotData.port = sotConnectionData.port;
  53.         }
  54.         UpdateWindow(hwnd);
  55.         Sleep(1000);
  56.     }
  57. }
  58.  
  59. std::wstring GetIpv4Text() {
  60.     std::wstringstream out;
  61.     out << L"Ip : ";
  62.     if (sotData.isConnected) {
  63.         out << sotData.ipv4;
  64.     }
  65.     else {
  66.         out << "?";
  67.     }
  68.     return out.str();
  69. }
  70.  
  71. std::wstring GetPortText() {
  72.     std::wstringstream out;
  73.     out << L"Port : ";
  74.     if (sotData.isConnected) {
  75.         out << sotData.port;
  76.     }
  77.     else {
  78.         out << "?";
  79.     }
  80.     return out.str();
  81. }
  82.  
  83. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  84. {
  85.     switch (msg)
  86.     {
  87.     case WM_PAINT:
  88.         {
  89.         HDC hdc = GetDC(hwnd);
  90.         HDC hdcBuffer = CreateCompatibleDC(hdc);
  91.         HBITMAP bmpBuffer = CreateCompatibleBitmap(hdc, 400, 400);
  92.  
  93.         SelectObject(hdcBuffer, bmpBuffer);
  94.  
  95.         TextOutW(hdcBuffer, 20, 50, GetIpv4Text().c_str(), GetIpv4Text().length());
  96.         TextOutW(hdcBuffer, 20, 100, GetPortText().c_str(), GetPortText().length());
  97.  
  98.         BitBlt(hdc, 0, 0, 400, 400, hdcBuffer, 0, 0, SRCCOPY);
  99.  
  100.         DeleteObject(bmpBuffer);
  101.         DeleteDC(hdcBuffer);
  102.         ReleaseDC(hwnd, hdc);
  103.         }
  104.         break;
  105.     case WM_DESTROY:
  106.         PostQuitMessage(0);
  107.         break;
  108.     default:
  109.         return DefWindowProc(hwnd, msg, wParam, lParam);
  110.     }
  111.     return 0;
  112. }
  113.  
  114. int InitSOTOverlay() {
  115.     WNDCLASSEX wc;
  116.  
  117.     wc.cbSize = sizeof(WNDCLASSEX);
  118.  
  119.     wc.style = CS_HREDRAW | CS_VREDRAW;
  120.     wc.lpfnWndProc = WndProc;
  121.     wc.cbClsExtra = 0;
  122.     wc.cbWndExtra = 0;
  123.     wc.hInstance = NULL;
  124.     wc.hIcon = NULL;
  125.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  126.     wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
  127.     wc.lpszMenuName = NULL;
  128.     wc.lpszClassName = wClassName;
  129.     wc.hIconSm = NULL;
  130.  
  131.     RegisterClassEx(&wc);
  132.  
  133.     hwndSOT = FindWindowW(0, L"Sea of Thieves");
  134.    
  135.     RECT rect;
  136.     GetWindowRect(hwndSOT, &rect);
  137.     width = rect.right - rect.left;
  138.     height = rect.bottom - rect.top;
  139.  
  140.     hwnd = CreateWindowExW(WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED, wClassName, L"SOTOverlay", WS_POPUP, 0, 0, width, height, NULL, NULL, NULL, NULL);
  141.  
  142.     if (hwnd == NULL)
  143.     {
  144.         MessageBoxW(NULL, L"Window Creation Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
  145.         return EXIT_FAILURE;
  146.     }
  147.  
  148.     SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), 0, LWA_COLORKEY);
  149.  
  150.     ShowWindow(hwnd, TRUE);
  151.     UpdateWindow(hwnd);
  152.  
  153.     return EXIT_SUCCESS;
  154. }
  155.  
  156. int InitSOTData() {
  157.     PROCESSENTRY32 entry;
  158.     HANDLE snapshot;
  159.     wchar_t sotFileName[MAX_PATH];
  160.     DWORD cbNeeded;
  161.     wchar_t modFileName[MAX_PATH];
  162.     int filenameLength = 0;
  163.  
  164.     entry.dwSize = sizeof(PROCESSENTRY32);
  165.  
  166.     snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
  167.  
  168.     if (Process32FirstW(snapshot, &entry) == TRUE) {
  169.         do {
  170.             if (memcmp(nSOT, entry.szExeFile, 11) == 0) {
  171.                 hSOT = OpenProcess(PROCESS_ALL_ACCESS, NULL, entry.th32ProcessID);
  172.                 break;
  173.             }
  174.         } while (Process32NextW(snapshot, &entry) == TRUE);
  175.     }
  176.  
  177.     if (hSOT == NULL) {
  178.         MessageBoxW(NULL, L"Error, can't find the game.", L"Error!", MB_ICONEXCLAMATION | MB_OK);
  179.         return EXIT_FAILURE;
  180.     }
  181.  
  182.     if (GetModuleBaseName(hSOT, NULL, sotFileName, MAX_PATH) == 0) {
  183.         std::cout << "Unable to get process name." << std::endl;
  184.         CloseHandle(hSOT);
  185.         return EXIT_FAILURE;
  186.     }
  187.  
  188.     if (EnumProcessModules(hSOT, &hMOD, sizeof(hMOD), &cbNeeded) == 0) {
  189.         std::cout << "Error at EnumProcessMemory." << std::endl;
  190.         CloseHandle(hSOT);
  191.         return EXIT_FAILURE;
  192.     }
  193.  
  194.     filenameLength = GetModuleBaseName(hSOT, hMOD, modFileName, MAX_PATH);
  195.     if (filenameLength == 0) {
  196.         std::cout << "Error at GetModuleBaseName." << std::endl;
  197.         CloseHandle(hSOT);
  198.         return EXIT_FAILURE;
  199.     }
  200.  
  201.     if (memcmp(sotFileName, modFileName, filenameLength) != 0) {
  202.         std::cout << "Unable to find main module." << std::endl;
  203.         CloseHandle(hSOT);
  204.         return EXIT_FAILURE;
  205.     }
  206. }
  207.  
  208. int main() {
  209.     if (InitSOTData() == EXIT_FAILURE) {
  210.         return EXIT_FAILURE;
  211.     }
  212.  
  213.     if (InitSOTOverlay() == EXIT_FAILURE) {
  214.         return EXIT_FAILURE;
  215.     }
  216.  
  217.     std::thread updateThread(Update);
  218.  
  219.     MSG msg;
  220.  
  221.     while (true) {
  222.         if (PeekMessageW(&msg, hwnd, 0, 0, PM_REMOVE) == TRUE) {
  223.             if (msg.message == WM_QUIT)
  224.                 break;
  225.             TranslateMessage(&msg);
  226.             DispatchMessageW(&msg);
  227.         }
  228.  
  229.         RECT rect;
  230.         GetWindowRect(hwndSOT, &rect);
  231.         width = rect.right - rect.left;
  232.         height = rect.bottom - rect.top;
  233.  
  234.         MoveWindow(hwnd, rect.left, rect.top, width, height, TRUE);
  235.     }
  236.  
  237.     CloseHandle(hSOT);
  238.     return EXIT_SUCCESS;
  239. }
Add Comment
Please, Sign In to add comment