Welcome to hackvshack.net Forum!
Download Free HvH CS2/CS:GO Cheats, CFG, LUA/JS Scripts, and More!
Register

C++ Software cs2 all offset/pattern and everything you need to make a cheat downloader

TomiHVH

Legendary HvHer
User ID:
12010
Messages:
80
Reactions:
2,911
Badges:
21
REP:
−0/1+
Level:
201
made this because i got tired of downloading cs2 files manually. this grabs offsets and patterns from cs2 sdk and a2x cs2 dumper and saves them into one folder. You can choose either source or both and pick a file format for a2x with up to four downloads running at once. All credit goes to cs2 sdk and a2x for the files.

you can also run it from the console with optional arguments
main.exe --source both --format cpp --no-pause
this downloads from both sources and selects c++ files for a2x while keeping all cs2 sdk files
use --output "c:\downloads\cs2" to choose a folder
--no-pause skips the prompts after downloading
run main.exe --help to see all options
enjoy it!

code:
C++:
Expand Collapse Copy
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX

#include <atomic>
#include <chrono>
#include <filesystem>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <mutex>
#include <regex>
#include <string>
#include <thread>
#include <vector>
#include <windows.h>
#include <shellapi.h>
#include <winhttp.h>

namespace fs = std::filesystem;

struct Handle
{
    HINTERNET h;

    explicit Handle(HINTERNET value) : h(value)
    {
    }

    ~Handle()
    {
        if (h)
        {
            WinHttpCloseHandle(h);
        }
    }

    Handle(const Handle&) = delete;
};

static bool download(HINTERNET connection, const std::wstring& url, const fs::path& target,
    std::atomic<unsigned long long>* transferred = nullptr)
{
    Handle request(WinHttpOpenRequest(connection, L"GET", url.c_str(), nullptr, WINHTTP_NO_REFERER,
        WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE));

    if (!request.h)
    {
        return false;
    }

    if (!WinHttpSendRequest(request.h, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0) ||
        !WinHttpReceiveResponse(request.h, nullptr))
    {
        return false;
    }

    DWORD status = 0, size = sizeof(status);

    if (!WinHttpQueryHeaders(request.h, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER,
            WINHTTP_HEADER_NAME_BY_INDEX, &status, &size, WINHTTP_NO_HEADER_INDEX))
    {
        return false;
    }

    if (status != 200)
    {
        return false;
    }

    fs::create_directories(target.parent_path());
    fs::path temporary = target;
    temporary += L".part";
    std::ofstream output(temporary, std::ios::binary | std::ios::trunc);

    if (!output)
    {
        return false;
    }

    char buffer[65536];
    DWORD received = 0;
    unsigned long long total = 0;
    bool ok = true;

    for (;;)
    {
        if (!WinHttpReadData(request.h, buffer, sizeof(buffer), &received))
        {
            ok = false;
            break;
        }

        if (!received)
        {
            break;
        }

        output.write(buffer, received);

        if (!output)
        {
            ok = false;
            break;
        }

        total += received;

        if (transferred)
        {
            transferred->fetch_add(received);
        }
    }

    output.close();
    ok = ok && !output.fail() && total > 0;

    if (ok)
    {
        ok = MoveFileExW(temporary.c_str(), target.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH) != 0;
    }

    if (!ok)
    {
        std::error_code ec;
        fs::remove(temporary, ec);
    }

    return ok;
}

static bool matches_format(const fs::path& path, const std::wstring& format)
{
    const auto extension = path.extension().wstring();
    return format == L"all" ||
           (format == L"cpp" ? (extension == L".hpp" || extension == L".h") : extension == L"." + format);
}

static bool valid_format(const std::wstring& format)
{
    return format == L"cpp" || format == L"cs" || format == L"json" || format == L"rs" || format == L"zig" ||
           format == L"txt" || format == L"all";
}

struct Task
{
    std::wstring host, url, label;
    fs::path target;
};

static unsigned run_downloads(HINTERNET session, const std::vector<Task>& tasks)
{
    if (tasks.empty())
    {
        return 0;
    }

    std::atomic<size_t> next{0}, completed{0};
    std::atomic<unsigned> failed{0};
    std::atomic<unsigned long long> transferred{0};
    std::mutex output_mutex;
    std::vector<std::thread> workers;
    const auto start = std::chrono::steady_clock::now();
    auto worker = [&]
    {
        for (;;)
        {
            const size_t index = next.fetch_add(1);

            if (index >= tasks.size())
            {
                break;
            }

            const auto& task = tasks[index];
            bool ok = false;

            try
            {
                Handle connection(WinHttpConnect(session, task.host.c_str(), INTERNET_DEFAULT_HTTPS_PORT, 0));

                for (int attempt = 0; connection.h && attempt < 3 && !ok; ++attempt)
                {
                    if (attempt)
                    {
                        Sleep(1000 * attempt);
                    }

                    ok = download(connection.h, task.url, task.target, &transferred);
                }
            }
            catch (const std::exception&)
            {
                ok = false;
            }

            if (!ok)
            {
                ++failed;
            }

            {
                std::lock_guard<std::mutex> lock(output_mutex);
                std::wcout << L"\r" << std::wstring(110, L' ') << L"\r" << task.label
                           << (ok ? L" ... ok\n" : L" ... failed\n");
            }

            ++completed;
        }
    };

    try
    {
        for (size_t i = 0; i < (std::min)(size_t{4}, tasks.size()); ++i)
        {
            workers.emplace_back(worker);
        }
    }
    catch (...)
    {
        worker();
    }

    while (completed.load() < tasks.size())
    {
        const double seconds = std::chrono::duration<double>(std::chrono::steady_clock::now() - start).count();
        const double mib = transferred.load() / (1024.0 * 1024.0);
        {
            std::lock_guard<std::mutex> lock(output_mutex);
            std::cout << "\r" << completed.load() << "/" << tasks.size() << " files | " << std::fixed
                      << std::setprecision(2) << mib << " mib downloaded | " << mib / (std::max)(seconds, 0.001)
                      << " mib/s avg                 " << std::flush;
        }

        Sleep(250);
    }

    for (auto& thread : workers)
    {
        thread.join();
    }

    std::cout << "\r" << std::string(110, ' ') << "\r";
    std::cout << std::fixed << std::setprecision(2) << transferred.load() / (1024.0 * 1024.0) << " mib downloaded in "
              << std::chrono::duration<double>(std::chrono::steady_clock::now() - start).count() << " seconds\n";
    return failed.load();
}

static unsigned list_github(
    HINTERNET session, const fs::path& folder, const std::wstring& format, std::vector<Task>& tasks)
{
    Handle api(WinHttpConnect(session, L"api.github.com", INTERNET_DEFAULT_HTTPS_PORT, 0));

    if (!api.h)
    {
        std::cout << "github connection failed\n";
        return 1;
    }

    fs::path manifest = folder / L"cs2-dumper" / L"tree.json.part";
    bool fetched = false;

    for (int attempt = 0; attempt < 3 && !fetched; ++attempt)
    {
        if (attempt)
        {
            Sleep(1000 * attempt);
        }

        fetched = download(api.h, L"/repos/a2x/cs2-dumper/git/trees/main?recursive=1", manifest);
    }

    if (!fetched)
    {
        std::cout << "github folder listing failed\n";
        return 1;
    }

    std::ifstream input(manifest, std::ios::binary);
    std::string json((std::istreambuf_iterator<char>(input)), std::istreambuf_iterator<char>());
    input.close();
    std::error_code ec;
    fs::remove(manifest, ec);

    if (std::regex_search(json, std::regex("\"truncated\"\\s*:\\s*true")))
    {
        std::cout << "github folder listing is incomplete\n";
        return 1;
    }

    const std::regex object("\\{[^{}]*\\}");
    const std::regex path_key("\"path\"\\s*:\\s*\"(output/[a-zA-Z0-9_./-]+)\"");
    const std::regex blob_key("\"type\"\\s*:\\s*\"blob\"");
    const std::regex sha_key("\"sha\"\\s*:\\s*\"([a-f0-9]{40})\"");
    std::smatch root_sha;

    if (!std::regex_search(json, root_sha, sha_key))
    {
        std::cout << "github revision missing\n";
        return 1;
    }

    const std::string revision = root_sha[1].str();
    unsigned found = 0;

    for (auto it = std::sregex_iterator(json.begin(), json.end(), object); it != std::sregex_iterator(); ++it)
    {
        std::string entry = it->str();
        std::smatch match;

        if (!std::regex_search(entry, match, path_key) || !std::regex_search(entry, blob_key))
        {
            continue;
        }

        std::string path = match[1].str();

        if (path.find("..") != std::string::npos || path.find("//") != std::string::npos)
        {
            continue;
        }

        if (!matches_format(fs::path(path), format))
        {
            continue;
        }

        ++found;
        std::wstring wide(path.begin(), path.end());
        std::wstring commit(revision.begin(), revision.end());
        tasks.push_back({L"raw.githubusercontent.com", L"/a2x/cs2-dumper/" + commit + L"/" + wide,
            L"a2x/cs2-dumper/" + wide, folder / L"cs2-dumper" / fs::path(wide)});
    }

    if (!found)
    {
        std::cout << "a2x/cs2-dumper: no files available in the selected format\n";
    }

    return 0;
}

int wmain(int argc, wchar_t** argv)
{
    SetConsoleTitleW(L"cs2 all offset/patterns downloader");

    try
    {
        bool pause = argc == 1;
        std::vector<wchar_t> executable(32768);
        DWORD length = GetModuleFileNameW(nullptr, executable.data(), static_cast<DWORD>(executable.size()));

        if (!length || length >= executable.size())
        {
            return 1;
        }

        fs::path folder = fs::path(executable.data()).parent_path() / L"cs2-sdk";
        std::wstring format;
        std::wstring source;

        for (int i = 1; i < argc; ++i)
        {
            std::wstring arg = argv[i];

            if (arg == L"--help")
            {
                std::cout << "usage: main.exe [--output folder] [--source sdk|a2x|both]\n"
                             "                      [--format cpp|cs|json|rs|zig|txt|all] "
                             "[--no-pause]\n";
                return 0;
            }
            else if (arg == L"--no-pause")
            {
                pause = false;
            }
            else if (arg == L"--output" && i + 1 < argc)
            {
                folder = argv[++i];
            }
            else if (arg == L"--format" && i + 1 < argc)
            {
                format = argv[++i];
            }
            else if (arg == L"--source" && i + 1 < argc)
            {
                source = argv[++i];
            }
            else
            {
                std::cerr << "unknown or incomplete argument. use --help.\n";
                return 1;
            }
        }

        std::cout << "credits:\n  cs2-sdk.com - https://cs2-sdk.com\n"
                     "  a2x/cs2-dumper - https://github.com/a2x/cs2-dumper\n\n";

        if (!format.empty() && !valid_format(format))
        {
            std::cerr << "invalid format. use --help.\n";
            return 1;
        }

        if (!source.empty() && source != L"sdk" && source != L"a2x" && source != L"both")
        {
            std::cerr << "invalid source. use --help.\n";
            return 1;
        }

        while (source.empty())
        {
            std::cout << "select download sources:\n  1. cs2-sdk.com\n  2. "
                         "a2x/cs2-dumper\n  3. both\nchoice: "
                      << std::flush;
            std::string choice;

            if (!std::getline(std::cin, choice))
            {
                return 1;
            }

            if (choice == "1")
            {
                source = L"sdk";
            }
            else if (choice == "2")
            {
                source = L"a2x";
            }
            else if (choice == "3")
            {
                source = L"both";
            }
            else
            {
                std::cout << "invalid choice. enter a number from 1 to 3.\n\n";
            }
        }

        while (source != L"sdk" && format.empty())
        {
            std::cout << "select a file format for a2x/cs2-dumper:\n"
                         "  1. c++ (.hpp, .h)\n  2. c# (.cs)\n  3. json (.json)\n"
                         "  4. rust (.rs)\n  5. zig (.zig)\n  6. text (.txt)\n"
                         "  7. all formats\nchoice: "
                      << std::flush;
            std::string choice;

            if (!std::getline(std::cin, choice))
            {
                return 1;
            }

            const std::vector<std::wstring> formats = {L"cpp", L"cs", L"json", L"rs", L"zig", L"txt", L"all"};

            if (choice.size() == 1 && choice[0] >= '1' && choice[0] <= '7')
            {
                format = formats[choice[0] - '1'];
            }
            else
            {
                std::cout << "invalid choice. enter a number from 1 to 7.\n\n";
            }
        }

        if (source != L"a2x")
        {
            std::cout << "\ncs2-sdk.com: downloading all 25 files.\n";
        }

        if (source != L"sdk")
        {
            std::cout << "a2x/cs2-dumper: downloading only the selected format.\n";
        }

        std::cout << "up to 4 simultaneous downloads.\n\n";
        const std::vector<std::wstring> files = {L"protobufs/protobufs.json", L"interfaces/vtables.json",
            L"entities/entities.json", L"gameevents/gameevents.json", L"weapons/weapons.json", L"convars/convars.json",
            L"schemas/schemas.json", L"cs2.hpp", L"offsets/offsets.json", L"offsets/offsets.hpp",
            L"engine/engine_structs.json", L"engine/cviewsetup.h", L"engine/cusercmd.h", L"engine/cswapchaindx11.h",
            L"engine/csubtickmovestep.h", L"engine/csgointerpolationinfopb.h", L"engine/cmsgvector.h",
            L"engine/cmsgqangle.h", L"engine/cinbuttonstatepb.h", L"engine/ccsgousercmdpb.h",
            L"engine/ccsgoinputhistoryentrypb.h", L"engine/ccsgoinput.h", L"engine/cbaseusercmdpb.h",
            L"patterns/patterns.json", L"patterns/patterns.txt"};
        Handle session(WinHttpOpen(L"cs2-sdk-downloader/1.0", WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY,
            WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0));

        if (!session.h)
        {
            throw std::runtime_error("cannot initialize https.");
        }

        WinHttpSetTimeouts(session.h, 30000, 30000, 30000, 60000);
        std::wcout << L"saving files to: " << fs::absolute(folder).wstring() << L"\n";
        unsigned failed = 0;
        std::vector<Task> tasks;

        if (source != L"a2x")
        {
            for (const auto& file : files)
            {
                std::wstring url = file == L"patterns/patterns.txt" ? L"/api/export/patterns.txt" : L"/raw/" + file;
                tasks.push_back({L"cs2-sdk.com", url, L"cs2-sdk.com/" + file, folder / fs::path(file)});
            }
        }

        if (source != L"sdk")
        {
            std::cout << "loading a2x/cs2-dumper file list...\n";
            failed += list_github(session.h, folder, format, tasks);
        }

        failed += run_downloads(session.h, tasks);
        std::cout << (failed ? "\nfinished with errors\n" : "\nfinished\n");

        if (pause)
        {
            if (fs::is_directory(folder))
            {
                std::cout << "open download folder? [y/n]: " << std::flush;
                std::string answer;

                if (std::getline(std::cin, answer) && (answer == "y" || answer == "yes"))
                {
                    const auto absolute = fs::absolute(folder).wstring();

                    if (reinterpret_cast<INT_PTR>(
                            ShellExecuteW(nullptr, L"open", absolute.c_str(), nullptr, nullptr, SW_SHOWNORMAL)) <= 32)
                    {
                        std::cout << "could not open download folder.\n";
                    }
                }
            }

            std::cout << "press enter to close...";
            std::cin.get();
        }

        return failed ? 1 : 0;
    }
    catch (const std::exception& e)
    {
        std::cerr << "error: " << e.what() << '\n';
        return 1;
    }
}
 
Last edited by a moderator:

Who has read this thread (Total: 0) in last 1 hours View details