Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
273 changes: 273 additions & 0 deletions usermode/UpgradeLog.htm

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions usermode/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"m_use_localhost": true,
"m_local_ip": "192.168.x.x",
"m_public_ip": "x.x.x.x"
}
1 change: 0 additions & 1 deletion usermode/ext/easywsclient/easywsclient.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#ifdef _WIN32
#if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS)
#define _CRT_SECURE_NO_WARNINGS // _CRT_SECURE_NO_WARNINGS for sscanf errors in MSVC2013 Express
Expand Down
40 changes: 35 additions & 5 deletions usermode/src/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,44 @@

/* custom defines */
#define LOG_INFO(str, ...) \
printf(" [info] " str "\n", __VA_ARGS__)
{ \
FILE* log = fopen("WR_Log.txt", "a+"); \
if (log) { \
fprintf(log, "[INFO] " str "\n", __VA_ARGS__); \
fclose(log); \
} \
}

#define LOG_WARNING(str, ...) \
printf(" [warning] " str "\n", __VA_ARGS__)
{ \
FILE* log = fopen("WR_Log.txt", "a+"); \
if (log) { \
fprintf(log, "[WARNING] " str "\n", __VA_ARGS__); \
fclose(log); \
} \
}

#define LOG_ERROR(str, ...) \
{ \
const auto filename = std::filesystem::path(__FILE__).filename().string(); \
printf(" [error] [%s:%d] " str "\n", filename.c_str(), __LINE__, __VA_ARGS__); \
std::this_thread::sleep_for(std::chrono::seconds(5)); \
}
FILE* log = fopen("WR_Log.txt", "a+"); \
if (log) { \
fprintf(log, "[ERROR] [%s:%d] " str "\n", filename.c_str(), __LINE__, __VA_ARGS__); \
fclose(log); \
} \
}

#define LOG_CLEAR() \
{ \
FILE* log = fopen("WR_Log.txt", "w+"); \
if (log) { \
fclose(log); \
} \
}

#define SLEEP(sec) \
{ \
auto wait_to = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()) + sec; \
while (wait_to >= std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())) {}; \
}

6 changes: 6 additions & 0 deletions usermode/src/core/schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
return m_memory->read_t<std::string>(name_ptr); \
}

#define SCHEMA_ADD_ARRAY(arrtype, arrsize, name, field) \
inline std::array<arrtype, arrsize> name() \
{ \
return m_memory->read_t<std::array<arrtype, arrsize>>(reinterpret_cast<DWORD64>(this) + schema::get_offset(fnv1a::hash_const(field))); \
}

#define SCHEMA_ADD_OFFSET(type, name, offset) \
inline type name() \
{ \
Expand Down
244 changes: 214 additions & 30 deletions usermode/src/dllmain.cpp
Original file line number Diff line number Diff line change
@@ -1,89 +1,273 @@
#include "pch.hpp"

bool main()
HWND g_hMainWnd = NULL;
HWND g_hLogEdit = NULL;
UINT const WM_APP_LOG = WM_APP + 1;

void LogMessage(const std::string& msg, int type = 1)
{
std::string prefixMsg = "";
if (!g_hMainWnd) return;

char* pText = new char[msg.length() + 10];
switch (type) {
case 1:
prefixMsg = "[INFO] " + msg;
break;
case 2:
prefixMsg = "[WARNING] " + msg;
break;
case 3:
prefixMsg = "[ERROR] " + msg;
break;
default:
prefixMsg = "[OTHER] " + msg;
break;
}


strcpy_s(pText, prefixMsg.length() + 1, prefixMsg.c_str());

PostMessage(g_hMainWnd, WM_APP_LOG, 0, (LPARAM)pText);
}

DWORD WINAPI AppLogic(LPVOID lpParam)
{
if (!utils::is_updated())
LOG_CLEAR();

if (!utils::is_updated()) {
LogMessage("Radar is not updated! Check LOG for more info.", 3);
return {};
}

LogMessage("Radar is up to date.");
LOG_INFO("Radar is up to date.");

config_data_t config_data = {};
if (!cfg::setup(config_data))
switch (cfg::setup(config_data))
{
std::this_thread::sleep_for(std::chrono::seconds(5));
return {};
case 0:
break;
case 1:
LogMessage("Couldn't open config.json file, please check files and configure it.", 3);
return {};
break;
case 2:
LogMessage("Failed to parse config.json, please check syntax.", 3);
return {};
break;
case 3:
LogMessage("Failed to deserialize config.json.", 3);
return {};
break;
default:
LogMessage("Error", 3);
break;
}
LOG_INFO("config system initialization completed");
LogMessage("Config system initialization completed.");

if (!exc::setup())
{
std::this_thread::sleep_for(std::chrono::seconds(5));
LogMessage("Exception setup failed! Check LOG for more info.", 3);
return {};
}
LOG_INFO("exception handler initialization completed");
LogMessage("Exception handler initialization completed.");

if (!m_memory->setup())
{
std::this_thread::sleep_for(std::chrono::seconds(5));
return {};
switch (m_memory->setup()) {
case 0:
LogMessage("Found CS2.exe, continuing...");
break;
case 1:
LogMessage("One or more anti-cheats are running, please close them.", 3);
return {};
break;
case 2:
LogMessage("Waiting for CS2.exe process...");
while (m_memory->setup() == 2) {SLEEP(1)};
LogMessage("Found CS2.exe, initializing...");
SLEEP(5);
break;
case 3:
LogMessage("Memory initialization failed.", 3);
return {};
break;
}
LOG_INFO("memory initialization completed");
LogMessage("Memory initialization completed.");

if (!i::setup())
{
std::this_thread::sleep_for(std::chrono::seconds(5));
return {};
LogMessage("Waiting for game to load...");
while (!i::setup()) { SLEEP(3); };
LogMessage("Game loaded.");
}
LOG_INFO("interfaces initialization completed");
LogMessage("Interfaces initialization completed.");

if (!schema::setup())
{
std::this_thread::sleep_for(std::chrono::seconds(5));
LogMessage("Schema setup failed! Check LOG for more info.", 3);
return {};
}
LOG_INFO("schema initialization completed");
LogMessage("Schema initialization completed.");

WSADATA wsa_data = {};
const auto wsa_startup = WSAStartup(MAKEWORD(2, 2), &wsa_data);
if (wsa_startup != 0)
{
std::this_thread::sleep_for(std::chrono::seconds(5));
return {};
}
LOG_INFO("winsock initialization completed");
LogMessage("Winsock initialization completed.");

const auto ipv4_address = utils::get_ipv4_address(config_data);
if (ipv4_address.empty())
LOG_WARNING("failed to automatically get your ipv4 address!\n we will use '%s' from 'config.json'. if the local ip is wrong, please set it", config_data.m_local_ip);
LogMessage(std::format("Failed to automatically get your ipv4 address!\n we will use '{}' from 'config.json'. If the local ip is wrong, please set it.", config_data.m_local_ip), 2);

const auto formatted_address = std::format("ws://{}:22006/cs2_webradar", ipv4_address);
static auto web_socket = easywsclient::WebSocket::from_url(formatted_address);
if (!web_socket)
{
LOG_ERROR("failed to connect to the web socket ('%s')", formatted_address.c_str());
return {};

while (!web_socket) {
web_socket = easywsclient::WebSocket::from_url(formatted_address);
if (!web_socket)
{
LogMessage(std::format("Failed to connect to the web socket ({}), retrying...", formatted_address.c_str()), 3);
}
}
LOG_INFO("connected to the web socket ('%s')", formatted_address.data());
LogMessage(std::format("Connected to the web socket ({}).", formatted_address.data()));

auto start = std::chrono::system_clock::now();
bool in_match = false;

for (;;)
{
const auto now = std::chrono::system_clock::now();
const auto duration = now - start;
if (duration >= std::chrono::milliseconds(100))
if (duration >= std::chrono::milliseconds(30))
{
start = now;

sdk::update();
f::run();

in_match = f::run();
if (!in_match) {
f::m_data["m_map"] = "invalid";
}
web_socket->send(f::m_data.dump());
}

web_socket->poll();
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}

system("pause");
LogMessage("WebRadar had stopped for no apparent reason...", 3);

return true;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
{
g_hLogEdit = CreateWindow(TEXT("EDIT"),
TEXT(""),
WS_CHILD | WS_VISIBLE | WS_BORDER |
ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY,
10, 0, 360, 210,
hWnd, (HMENU)1, NULL, NULL);

SendMessage(g_hLogEdit, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), TRUE);
break;
}

case WM_APP_LOG:
{
char* pText = (char*)lParam;

int len = GetWindowTextLength(g_hLogEdit);
SendMessage(g_hLogEdit, EM_SETSEL, (WPARAM)len, (LPARAM)len);
SendMessage(g_hLogEdit, EM_REPLACESEL, 0, (LPARAM)pText);
SendMessage(g_hLogEdit, EM_REPLACESEL, 0, (LPARAM)TEXT("\r\n"));

delete[] pText;
break;
}

case WM_DESTROY:
{
g_hLogEdit = NULL;
g_hMainWnd = NULL;
PostQuitMessage(0);
break;
}

default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);

const char CLASS_NAME[] = "AppWindowClass";

WNDCLASS wc = {};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);

RegisterClass(&wc);

g_hMainWnd = CreateWindowEx(
0,
CLASS_NAME,
"WBFCS",
WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME,

CW_USEDEFAULT, CW_USEDEFAULT, 400, 260,

NULL,
NULL,
hInstance,
NULL
);

if (g_hMainWnd == NULL)
{
return 0;
}

ShowWindow(g_hMainWnd, nCmdShow);
UpdateWindow(g_hMainWnd);

HANDLE hThread = CreateThread(
NULL,
0,
AppLogic,
(LPVOID)g_hMainWnd,
0,
NULL
);

if (hThread == NULL)
{
MessageBox(g_hMainWnd, "Failed to create worker thread!", "Fatal Error", MB_OK | MB_ICONERROR);
return 0;
}
CloseHandle(hThread);

MSG msg = {};
while (GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return (int)msg.wParam;
}
2 changes: 2 additions & 0 deletions usermode/src/features/bomb/bomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ void f::bomb::get_carried_bomb(c_base_entity* bomb)

m_data["m_bomb"]["x"] = scene_origin.m_x;
m_data["m_bomb"]["y"] = scene_origin.m_y;
m_data["m_bomb"]["owner_entity"] = reinterpret_cast<uintptr_t>(bomb->m_hOwnerEntity());

}

void f::bomb::get_planted_bomb(c_planted_c4* planted_c4)
Expand Down
Loading