#pragma once

#include "pch.h"
#include <Windows.h>
#include <stdio.h>
#include <iostream>
#include <thread>
#include <chrono>
#include "Menu.h"
#include <Windows.h>
#include <iostream>
#include <stdlib.h>
using namespace std;

#include "ini.h"
#ifdef _WIN32
#include <io.h> 
#define access    _access_s
#else
#include <unistd.h>
#endif

#define INAME L"VALORANT  " 


using namespace std;

typedef int(*pDD_btn)(int btn);
typedef int(*pDD_movR)(int dx, int dy);

pDD_btn      DD_btn;          //Mouse button
pDD_movR   DD_movR;	     //VK to ddcode


int snapValue;
int fovW;
int fovH;

int colorMode = 0;

int get_screen_width(void) {
    return GetSystemMetrics(SM_CXSCREEN);
}

int get_screen_height(void) {
    return GetSystemMetrics(SM_CYSCREEN);
}

struct point {
    double x;
    double y;
    point(double x, double y) : x(x), y(y) {}
};

//to hide console cursor (doesn't work for some reason? it did before.)
void ShowConsoleCursor(bool showFlag)
{
    HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);

    CONSOLE_CURSOR_INFO     cursorInfo;

    GetConsoleCursorInfo(out, &cursorInfo);
    cursorInfo.bVisible = showFlag;
    SetConsoleCursorInfo(out, &cursorInfo);
}

//to avoid system()
void clear() {
    COORD topLeft = { 0, 0 };
    HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO screen;
    DWORD written;

    GetConsoleScreenBufferInfo(console, &screen);
    FillConsoleOutputCharacterA(
        console, ' ', screen.dwSize.X * screen.dwSize.Y, topLeft, &written
    );
    FillConsoleOutputAttribute(
        console, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE,
        screen.dwSize.X * screen.dwSize.Y, topLeft, &written
    );
    SetConsoleCursorPosition(console, topLeft);
}

inline bool is_color(int red, int green, int blue) {

    //original color purple
    if (colorMode == 0) {
        if (green >= 190) {
            return false;
        }

        if (green >= 140) {
            return abs(red - blue) <= 8 &&
                red - green >= 50 &&
                blue - green >= 50 &&
                red >= 105 &&
                blue >= 105;
        }

        return abs(red - blue) <= 13 &&
            red - green >= 60 &&
            blue - green >= 60 &&
            red >= 110 &&
            blue >= 100;
    }

    // yellow
    else {
        if (red < 160)
        {
            return false;
        }
        if (red > 161 && red < 255) {
            return green > 150 && green < 255 && blue > 0 && blue < 79;
        }
        return false;
    }
}

BOOL is_treigger(unsigned short red, unsigned short green, unsigned short blue) {

    if (green >= 170) {
        return FALSE;
    }

    if (green >= 120) {
        return abs(red - blue) <= 8 &&
            red - green >= 50 &&
            blue - green >= 50 &&
            red >= 105 &&
            blue >= 105;
    }

    return abs(red - blue) <= 13 &&
        red - green >= 60 &&
        blue - green >= 60 &&
        red >= 110 &&
        blue >= 100;

}

BOOL scan(HDC dc, int area_x, int area_y) {
    COLORREF col;
    for (int y = 2 * (-1); y < 2; ++y) {

        for (int x = 3 * (-1); x < 3; ++x) {

            col = GetPixel(dc, area_x + x, area_y + y);
            if (is_treigger((short)GetRValue(col), (short)GetGValue(col), (short)GetBValue(col))) {
                return TRUE;
            }
        }
    }
    return FALSE;
}

//checking if settings.ini is present
bool FileExists(const std::string& Filename)
{
    return access(Filename.c_str(), 0) == 0;
}

BYTE* screenData = 0;
bool run_threads = true;
const int screen_width = get_screen_width(), screen_height = get_screen_height();

int aim_x = 0;
int aim_y = 0;

//bot with purple (original (again not default))
void bot() {
    int w = fovW, h = fovH;
    auto t_start = std::chrono::high_resolution_clock::now();
    auto t_end = std::chrono::high_resolution_clock::now();

    HDC hScreen = GetDC(NULL);
    HBITMAP hBitmap = CreateCompatibleBitmap(hScreen, w, h);
    screenData = (BYTE*)malloc(5 * screen_width * screen_height);
    HDC hDC = CreateCompatibleDC(hScreen);
    point middle_screen(screen_width / 2, screen_height / 2);

    BITMAPINFOHEADER oplokers = { 0 };
    oplokers.biSize = sizeof(BITMAPINFOHEADER);
    oplokers.biPlanes = 1;
    oplokers.biBitCount = 32;
    oplokers.biWidth = w;
    oplokers.biHeight = -h;
    oplokers.biCompression = BI_RGB;
    oplokers.biSizeImage = 0;

    while (run_threads) {
        Sleep(6);
        HGDIOBJ old_obj = SelectObject(hDC, hBitmap);
        BOOL bRet = BitBlt(hDC, 0, 0, w, h, hScreen, middle_screen.x - (w / 2), middle_screen.y - (h / 2), SRCCOPY);
        SelectObject(hDC, old_obj);
        GetDIBits(hDC, hBitmap, 0, h, screenData, (BITMAPINFO*)&oplokers, DIB_RGB_COLORS);
        bool stop_loop = false;
        for (int j = 0; j < h; ++j) {
            for (int i = 0; i < w * 4; i += 4) {
#define red screenData[i + (j*w*4) + 2]
#define green screenData[i + (j*w*4) + 1]
#define blue screenData[i + (j*w*4) + 0]

                if (is_color(red, green, blue)) {
                    aim_x = (i / 4) - (w / 2);
                    aim_y = j - (h / 2) + snapValue;
                    stop_loop = true;
                    break;
                }
            }
            if (stop_loop) {
                break;
            }
        }
        if (!stop_loop) {
            aim_x = 0;
            aim_y = 0;
        }
    }
}

int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
    HMODULE hDll = LoadLibraryW(L"yawa.dll");
    if (hDll == nullptr)
    {
        return -1;
    }
    DD_btn = (pDD_btn)GetProcAddress(hDll, "DD_btn");
    DD_movR = (pDD_movR)GetProcAddress(hDll, "DD_movR");

    if (!(DD_btn && DD_movR))
    {
        return -2;
    }
    int st = DD_btn(0);
    if (st != 1)
    {
        return st;
    }

    //for toggle keys
    bool toggleKey = false;
    bool toggleActive = true;
    bool ha = false;
    bool yawajey = false;
    bool lClick = false;
    bool Lalt = false;
    bool hold = false;

    HWND yawa;
    yawa = FindWindowW(NULL, INAME);
    HDC nDC = GetDC(yawa);
    BOOL steam_check;

    string color;
    int mode = 0;

    double sensitivity = 0.52;
    double smoothing = 0.5;
    AllocConsole();
    AttachConsole(GetCurrentProcessId());
    auto w_f = freopen("CON", "w", stdout);
    auto r_f = freopen("CON", "r", stdin);

    string selecta;

    INIReader basa("config.ini");

    if (FileExists("config.ini") == true) {
        cout << "config check" << endl << endl;
        system("Color E4");

        cout << "Do you want to load it (YES OR NO): ";
        cin >> selecta;

        if (selecta == "YES") {
            cout << "config is injecting..";
            Sleep(1000);
            clear();
            system("Color E4");
            cout << "'config.ini' injected." << endl << endl;

            system("Color E4");
            Sleep(1000);
            fclose(w_f);
            fclose(r_f);
            FreeConsole();

            sensitivity = basa.GetFloat("config", "sensitivity", 0.00);
            smoothing = basa.GetFloat("config", "smoothing", 0.00);
            mode = basa.GetInteger("config", "mode", 0);

            color = basa.Get("settings", "aim color", "");
            if (basa.Get("settings", "snapping area", "") == "HEAD") {
                snapValue = 1;
            }
            else if (basa.Get("settings", "snapping area", "") == "NECK") {
                snapValue = 3;
            }
            if (basa.Get("settings", "toggle key", "") == "LCLICK") {
                lClick = true;
            }
            else if (basa.Get("settings", "toggle key", "") == "Lalt") {
                Lalt = true;
            }
            if (basa.Get("settings", "hold or toggle", "") == "TOGGLE") {
                hold = false;
            }
            if (basa.Get("settings", "hold or toggle", "") == "HOLD") {
                hold = true;
            }

            fovW = basa.GetInteger("settings", "hFov", 0);
            fovH = basa.GetInteger("settings", "vFov", 0);

            if (color == "roxo") {
                // set color mode
                colorMode = 0;
            }

            else if (color == "z") {
                // set color mode
                colorMode = 1;
            }
            thread(bot).detach();

            auto t_start = std::chrono::high_resolution_clock::now();
            auto t_end = std::chrono::high_resolution_clock::now();
            auto left_start = std::chrono::high_resolution_clock::now();
            auto left_end = std::chrono::high_resolution_clock::now();
            double sensitivity_x = 1.0 / sensitivity / (screen_width / 1920.0) * 1.08;
            double sensitivity_y = 1.0 / sensitivity / (screen_height / 1080.0) * 1.08;
            bool left_down = false;

            while (run_threads) {
                t_end = std::chrono::high_resolution_clock::now();
                double elapsed_time_ms = std::chrono::duration<double, std::milli>(t_end - t_start).count();

                if (GetAsyncKeyState(VK_LBUTTON))
                {
                    left_down = true;
                }
                else
                {
                    left_down = false;
                }

                if (toggleActive == true) {

                    if (hold == true) {
                        if (lClick == true) {
                            if (GetAsyncKeyState(VK_LBUTTON))
                            {
                                ha = true;
                            }
                            else
                            {
                                ha = false;
                            }
                        }

                        if (Lalt == true) {
                            if (GetAsyncKeyState(VK_MENU))
                            {
                                ha = true;
                            }
                            else
                            {
                                ha = false;
                            }
                        }

                    }

                    if (hold == false) {
                        if (lClick == true) {
                            if (GetAsyncKeyState(VK_LBUTTON) & 1)
                            {
                                ha = !ha;

                            }
                        }

                        if (Lalt == true) {
                            if (GetAsyncKeyState(VK_MENU) & 1)
                            {
                                ha = !ha;
                                if (ha) {
                                }
                                else if (!ha) {
                                }
                            }
                        }

                    }
                    if (ha) {
                        CURSORINFO cursorInfo = { 0 };
                        cursorInfo.cbSize = sizeof(cursorInfo);
                        GetCursorInfo(&cursorInfo);
                        if (cursorInfo.flags != 1) {
                            if (((mode & 1) > 0) && (VK_LBUTTON)) {
                                left_down = true;
                                if (elapsed_time_ms > 7) {
                                    t_start = std::chrono::high_resolution_clock::now();
                                    left_start = std::chrono::high_resolution_clock::now();
                                    if (aim_x != 0 || aim_y != 0) {
                                        DD_movR(double(aim_x) * sensitivity_x, double(aim_y) * sensitivity_y);
                                    }
                                }
                            }
                            else if (((mode & 2) > 0)) {
                                if (elapsed_time_ms > 7) {
                                    t_start = std::chrono::high_resolution_clock::now();
                                    if (aim_x != 0 || aim_y != 0) {
                                        left_end = std::chrono::high_resolution_clock::now();
                                        double recoil_ms = std::chrono::duration<double, std::milli>(left_end - left_start).count();
                                        double extra = 38.0 * (screen_height / 1080.0) * (recoil_ms / 1000.0);
                                        if (!left_down) {
                                            extra = 0;
                                        }
                                        else if (extra > 38.0) {
                                            extra = 38.0;
                                        }
                                        double v_x = double(aim_x) * sensitivity_x * smoothing;
                                        double v_y = double(aim_y + extra) * sensitivity_y * smoothing;
                                        if (fabs(v_x) < 1.0) {
                                            v_x = v_x > 0 ? 1.05 : -1.05;
                                        }
                                        if (fabs(v_y) < 1.0) {
                                            v_y = v_y > 0 ? 1.05 : -1.05;
                                        }
                                        DD_movR(v_x, v_y);
                                    }
                                }
                            }
                        }
                    }
                }
                //end

            }

        }
    }


    // fix later
    if (selecta == "YES" || FileExists("config.ini") == false) {
        ShowCursor(false);
    }
    return 0;
} 

C++ Online Compiler

Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++ and start coding!

Read inputs from stdin

OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.

#include <iostream>
#include <string>
using namespace std;

int main() 
{
    string name;
    cout << "Enter name:";
    getline (cin, name);
    cout << "Hello " << name;
    return 0;
}

About C++

C++ is a widely used middle-level programming language.

  • Supports different platforms like Windows, various Linux flavours, MacOS etc
  • C++ supports OOPS concepts like Inheritance, Polymorphism, Encapsulation and Abstraction.
  • Case-sensitive
  • C++ is a compiler based language
  • C++ supports structured programming language
  • C++ provides alot of inbuilt functions and also supports dynamic memory allocation.
  • Like C, C++ also allows you to play with memory using Pointers.

Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition If-Else is used.

if(conditional-expression) {
   //code
}
else {
   //code
}

You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.

2. Switch:

Switch is an alternative to If-Else-If ladder.

switch(conditional-expression){    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
......    
    
default:     
 code to be executed when all the above cases are not matched;    
} 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
  //code  
} 

4. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while (condition) {  
// code 
}  

5. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {  
 // code 
} while (condition); 

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity. Function gets run only when it is called.

How to declare a Function:

return_type function_name(parameters);

How to call a Function:

function_name (parameters)

How to define a Function:

return_type function_name(parameters) {  
 // code
}