Skip to content

Commit

Permalink
added overlay for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
ekknod committed Oct 19, 2023
1 parent 5575982 commit cd1ae8c
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 13 deletions.
8 changes: 7 additions & 1 deletion cs2/shared/cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ static BOOL cs::initialize(void)
return 0;
}

#ifndef __linux__
#ifdef __linux__
JZ(sdl::sdl_window = vm::get_module_export(game_handle, sdl, "SDL_GetKeyboardFocus"), E1);
sdl::sdl_window = vm::get_relative_address(game_handle, sdl::sdl_window, 2, 6);
JZ(sdl::sdl_window = vm::read_i64(game_handle, sdl::sdl_window), E1);
sdl::sdl_window = vm::get_relative_address(game_handle, sdl::sdl_window, 3, 7);
#else
JZ(sdl::sdl_window = vm::get_module_export(game_handle, sdl, "SDL_GetKeyboardFocus"), E1);
sdl::sdl_window = vm::get_relative_address(game_handle, sdl::sdl_window, 3, 7);
JZ(sdl::sdl_window = vm::read_i64(game_handle, sdl::sdl_window), E1);
Expand Down Expand Up @@ -536,6 +541,7 @@ static BOOL cs::initialize(void)
JZ(netvars::m_iIDEntIndex, E1);
JZ(netvars::m_vOldOrigin, E1);


return 1;
}

Expand Down
30 changes: 21 additions & 9 deletions cs2/shared/features.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -691,18 +691,21 @@ static void features::esp(QWORD local_player, QWORD target_player, vec3 head)
if (sdl_window == 0)
return;

QWORD sdl_window_data = cs::sdl::get_window_data(sdl_window);
if (sdl_window_data == 0)
return;

cs::WINDOW_INFO window{};
if (!cs::sdl::get_window_info(sdl_window, &window))
return;

#ifndef __linux__
QWORD sdl_window_data = cs::sdl::get_window_data(sdl_window);
if (sdl_window_data == 0)
return;

QWORD hwnd = cs::sdl::get_hwnd(sdl_window_data);
#endif


float view = cs::player::get_vec_view(local_player) - 10.0f;


vec3 bottom;
bottom.x = head.x;
Expand Down Expand Up @@ -760,13 +763,18 @@ static void features::esp(QWORD local_player, QWORD target_player, vec3 head)
float g = target_health;
float b = 0.00f;


#ifdef __linux__
client::DrawFillRect((void *)0, x, y, w, h, (unsigned char)r, (unsigned char)g, (unsigned char)b);
#else
client::DrawFillRect((void *)hwnd, x, y, w, h, (unsigned char)r, (unsigned char)g, (unsigned char)b);
#endif

/*
#ifndef __linux__
UNREFERENCED_PARAMETER(local_player);
UNREFERENCED_PARAMETER(head);
#endif
vec3 origin = cs::player::get_origin(target_player);
vec3 top_origin = origin;
Expand Down Expand Up @@ -795,10 +803,10 @@ static void features::esp(QWORD local_player, QWORD target_player, vec3 head)
int box_height = (int)(screen_bottom.y - screen_top.y);
int box_width = box_height / 2;
LONG x = (LONG)window.x + (LONG)(screen_top.x - box_width / 2);
LONG y = (LONG)window.y + (LONG)(screen_top.y);
int x = (int)window.x + (int)(screen_top.x - box_width / 2);
int y = (int)window.y + (int)(screen_top.y);
if (x > (LONG)(window.x + screen_size.x - (box_width)))
if (x > (int)(window.x + screen_size.x - (box_width)))
{
return;
}
Expand All @@ -807,7 +815,7 @@ static void features::esp(QWORD local_player, QWORD target_player, vec3 head)
return;
}
if (y > (LONG)(screen_size.y + window.y - (box_height)))
if (y > (int)(screen_size.y + window.y - (box_height)))
{
return;
}
Expand All @@ -816,7 +824,11 @@ static void features::esp(QWORD local_player, QWORD target_player, vec3 head)
return;
}
#ifdef __linux__
client::DrawRect((void *)0, x, y, box_width, box_height, (unsigned char)r, (unsigned char)g, (unsigned char)b);
#else
client::DrawRect((void *)hwnd, x, y, box_width, box_height, (unsigned char)r, (unsigned char)g, (unsigned char)b);
#endif
*/
}

Expand Down
Binary file added library/glfw/lib/libglfw3.a
Binary file not shown.
108 changes: 107 additions & 1 deletion projects - CS2/LINUX/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,46 @@
#include <unistd.h>
#include <fcntl.h>


#include <GL/gl.h>
#include "../../library/glfw/include/GLFW/glfw3.h"

static const GLFWvidmode *mode;

namespace gl
{
void DrawFillRect(float x, float y, float width, float height, int r, int g, int b)
{
glBegin(GL_QUADS);
glColor4f(r / 255.f, g / 255.f, b / 255.f, 1);
glVertex2f(x - (width / 2), y);
glVertex2f(x - (width / 2), y - height);
glVertex2f(x + (width / 2), y - height);
glVertex2f(x + (width / 2), y);
glEnd();
}

void DrawRect(float x, float y, float width, float height, int r, int g, int b)
{
glLineWidth(2);
glBegin(GL_LINE_LOOP);
glColor4f(r / 255.f, g / 255.f, b / 255.f, 1);
glVertex2f(x - (width / 2), y);
glVertex2f(x - (width / 2), y - height);
glVertex2f(x + (width / 2), y - height);
glVertex2f(x + (width / 2), y);
glEnd();
}
}









static int fd;

struct input_event
Expand Down Expand Up @@ -79,13 +119,40 @@ namespace client

void DrawRect(void *hwnd, int x, int y, int w, int h, unsigned char r, unsigned char g, unsigned b)
{
float fl_x = ((float)x / (float)mode->width) * 2.0f;
float fl_y = ((mode->height - (float)y) / (float)mode->height) * 2.0f;

fl_x -= 1.0f;
fl_y -= 1.0f;

float fl_w = ((float)w / mode->width) * 2.0f;
float fl_h = ((float)h / mode->height) * 2.0f;

fl_x -= (fl_w/2.0f);

gl::DrawRect(fl_x, fl_y, fl_w, fl_h, r, g, b);
}

void DrawFillRect(void *hwnd, int x, int y, int w, int h, unsigned char r, unsigned char g, unsigned b)
{
float fl_x = ((float)x / (float)mode->width) * 2.0f;
float fl_y = ((mode->height - (float)y) / (float)mode->height) * 2.0f;

fl_x -= 1.0f;
fl_y -= 1.0f;

float fl_w = ((float)w / mode->width) * 2.0f;
float fl_h = ((float)h / mode->height) * 2.0f;

fl_x += (fl_w/2.0f);

gl::DrawFillRect(fl_x, fl_y, fl_w, fl_h, r, g, b);
}
}

//
// to-do fix: for some reason esp position is little off
//
int main(void)
{
fd = open_device("event-mouse", 11);
Expand All @@ -95,10 +162,49 @@ int main(void)
return 0;
}

while (1)
if (!glfwInit())
{
return 0;
}


glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

glfwDefaultWindowHints();
glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
glfwWindowHint(GLFW_DECORATED, GL_FALSE);
glfwWindowHint(GLFW_FLOATING, GLFW_TRUE);
mode = glfwGetVideoMode(glfwGetPrimaryMonitor());

GLFWwindow *window = glfwCreateWindow(mode->width, mode->height, "EC", NULL, NULL);

glfwMakeContextCurrent(window);

glfwSetWindowAttrib(window, GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
glfwSetWindowAttrib(window, GLFW_FLOATING, GLFW_TRUE);
glfwSetWindowAttrib(window, GLFW_MOUSE_PASSTHROUGH, GLFW_TRUE);

glfwSwapInterval(1);

while (!glfwWindowShouldClose(window))
{
glfwPollEvents();

int w, h;
glfwGetFramebufferSize(window, &w, &h);
glViewport(0, 0, w, h);

glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

cs2::run();

glfwSwapBuffers(window);
}
glfwDestroyWindow(window);
return 0;
}

4 changes: 2 additions & 2 deletions projects - CS2/LINUX/run
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
g++ main.cpp ../../cs2/shared/cs.cpp ../../cs2/shared/features.cpp ../../library/vm_linux/vm.cpp -o tux
sudo ./tux
g++ -o tux main.cpp ../../cs2/shared/cs.cpp ../../cs2/shared/features.cpp ../../library/vm_linux/vm.cpp -L../../library/glfw/lib -lGL -lglfw3
sudo ./tux

0 comments on commit cd1ae8c

Please sign in to comment.