Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- #include <Psapi.h>
- #include <TlHelp32.h>
- #include <vector>
- #include <thread>
- #include <sstream>
- typedef struct _SotConnectionData {
- LPVOID ptrIpv4; //Unicode l24
- BYTE p0[8];
- int port;
- }SotConnectionData, * LPSotConnectionData;
- typedef struct _SOTDATA {
- bool isConnected;
- wchar_t ipv4[24];
- int port;
- }SOTDATA, * LPSOTDATA;
- int baseOffsets = 0x0683B230;
- std::vector<int> offsets{ 0xA00, 0x0, 0xF0 };
- const wchar_t* nSOT = L"SoTGame.exe";
- const wchar_t* wClassName = L"SOTViewerClass";
- int width, height;
- HANDLE hSOT = NULL;
- HMODULE hMOD;
- HWND hwnd;
- HWND hwndSOT;
- SOTDATA sotData;
- void Update() {
- LPBYTE p;
- SotConnectionData sotConnectionData;
- while (true) {
- p = (LPBYTE)hMOD + baseOffsets;
- for (int i = 0; i < offsets.size(); i++) {
- ReadProcessMemory(hSOT, p, &p, sizeof(p), nullptr);
- p += offsets[i];
- }
- ReadProcessMemory(hSOT, p, &sotConnectionData, sizeof(sotConnectionData), nullptr);
- if ((long)sotConnectionData.ptrIpv4 == 0) {
- sotData.isConnected = false;
- }
- else {
- sotData.isConnected = true;
- ReadProcessMemory(hSOT, sotConnectionData.ptrIpv4, sotData.ipv4, sizeof(wchar_t) * 24, nullptr);
- sotData.port = sotConnectionData.port;
- }
- UpdateWindow(hwnd);
- Sleep(1000);
- }
- }
- std::wstring GetIpv4Text() {
- std::wstringstream out;
- out << L"Ip : ";
- if (sotData.isConnected) {
- out << sotData.ipv4;
- }
- else {
- out << "?";
- }
- return out.str();
- }
- std::wstring GetPortText() {
- std::wstringstream out;
- out << L"Port : ";
- if (sotData.isConnected) {
- out << sotData.port;
- }
- else {
- out << "?";
- }
- return out.str();
- }
- LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- switch (msg)
- {
- case WM_PAINT:
- {
- HDC hdc = GetDC(hwnd);
- HDC hdcBuffer = CreateCompatibleDC(hdc);
- HBITMAP bmpBuffer = CreateCompatibleBitmap(hdc, 400, 400);
- SelectObject(hdcBuffer, bmpBuffer);
- TextOutW(hdcBuffer, 20, 50, GetIpv4Text().c_str(), GetIpv4Text().length());
- TextOutW(hdcBuffer, 20, 100, GetPortText().c_str(), GetPortText().length());
- BitBlt(hdc, 0, 0, 400, 400, hdcBuffer, 0, 0, SRCCOPY);
- DeleteObject(bmpBuffer);
- DeleteDC(hdcBuffer);
- ReleaseDC(hwnd, hdc);
- }
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
- return 0;
- }
- int InitSOTOverlay() {
- WNDCLASSEX wc;
- wc.cbSize = sizeof(WNDCLASSEX);
- wc.style = CS_HREDRAW | CS_VREDRAW;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = NULL;
- wc.hIcon = NULL;
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = CreateSolidBrush(RGB(0, 0, 0));
- wc.lpszMenuName = NULL;
- wc.lpszClassName = wClassName;
- wc.hIconSm = NULL;
- RegisterClassEx(&wc);
- hwndSOT = FindWindowW(0, L"Sea of Thieves");
- RECT rect;
- GetWindowRect(hwndSOT, &rect);
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
- hwnd = CreateWindowExW(WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_LAYERED, wClassName, L"SOTOverlay", WS_POPUP, 0, 0, width, height, NULL, NULL, NULL, NULL);
- if (hwnd == NULL)
- {
- MessageBoxW(NULL, L"Window Creation Failed!", L"Error!", MB_ICONEXCLAMATION | MB_OK);
- return EXIT_FAILURE;
- }
- SetLayeredWindowAttributes(hwnd, RGB(0, 0, 0), 0, LWA_COLORKEY);
- ShowWindow(hwnd, TRUE);
- UpdateWindow(hwnd);
- return EXIT_SUCCESS;
- }
- int InitSOTData() {
- PROCESSENTRY32 entry;
- HANDLE snapshot;
- wchar_t sotFileName[MAX_PATH];
- DWORD cbNeeded;
- wchar_t modFileName[MAX_PATH];
- int filenameLength = 0;
- entry.dwSize = sizeof(PROCESSENTRY32);
- snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
- if (Process32FirstW(snapshot, &entry) == TRUE) {
- do {
- if (memcmp(nSOT, entry.szExeFile, 11) == 0) {
- hSOT = OpenProcess(PROCESS_ALL_ACCESS, NULL, entry.th32ProcessID);
- break;
- }
- } while (Process32NextW(snapshot, &entry) == TRUE);
- }
- if (hSOT == NULL) {
- MessageBoxW(NULL, L"Error, can't find the game.", L"Error!", MB_ICONEXCLAMATION | MB_OK);
- return EXIT_FAILURE;
- }
- if (GetModuleBaseName(hSOT, NULL, sotFileName, MAX_PATH) == 0) {
- std::cout << "Unable to get process name." << std::endl;
- CloseHandle(hSOT);
- return EXIT_FAILURE;
- }
- if (EnumProcessModules(hSOT, &hMOD, sizeof(hMOD), &cbNeeded) == 0) {
- std::cout << "Error at EnumProcessMemory." << std::endl;
- CloseHandle(hSOT);
- return EXIT_FAILURE;
- }
- filenameLength = GetModuleBaseName(hSOT, hMOD, modFileName, MAX_PATH);
- if (filenameLength == 0) {
- std::cout << "Error at GetModuleBaseName." << std::endl;
- CloseHandle(hSOT);
- return EXIT_FAILURE;
- }
- if (memcmp(sotFileName, modFileName, filenameLength) != 0) {
- std::cout << "Unable to find main module." << std::endl;
- CloseHandle(hSOT);
- return EXIT_FAILURE;
- }
- }
- int main() {
- if (InitSOTData() == EXIT_FAILURE) {
- return EXIT_FAILURE;
- }
- if (InitSOTOverlay() == EXIT_FAILURE) {
- return EXIT_FAILURE;
- }
- std::thread updateThread(Update);
- MSG msg;
- while (true) {
- if (PeekMessageW(&msg, hwnd, 0, 0, PM_REMOVE) == TRUE) {
- if (msg.message == WM_QUIT)
- break;
- TranslateMessage(&msg);
- DispatchMessageW(&msg);
- }
- RECT rect;
- GetWindowRect(hwndSOT, &rect);
- width = rect.right - rect.left;
- height = rect.bottom - rect.top;
- MoveWindow(hwnd, rect.left, rect.top, width, height, TRUE);
- }
- CloseHandle(hSOT);
- return EXIT_SUCCESS;
- }
Add Comment
Please, Sign In to add comment