Update thirdperson.c, hooks.c, and 3 more files...

This commit is contained in:
2025-04-04 17:07:54 -04:00
parent 0c63d7c969
commit 07b05f02c4
5 changed files with 77 additions and 224 deletions

View File

@@ -1,37 +1,29 @@
#include <stdlib.h>
#include <stdio.h>
// This file needs to be compiled as C++
#define IMGUI_IMPLEMENTATION
#include "include/menu.h"
#include "include/sdk.h"
#include "include/globals.h"
#include "include/settings.h"
#include "include/hooks.h" // For hook function declarations
#include "include/hooks.h"
#include <GL/gl.h>
// Include for mouse button constants
#include "include/sdk/public/keydefs.h"
// Access to hitbox enum from aim.c
extern const char* hitbox_names[];
extern int current_hitbox;
// Menu state
bool g_menu_open = false;
// ImGui context and state
ImGuiContext* g_imgui_context = NULL;
bool g_imgui_initialized = false;
// Key binding state
static bool g_waiting_for_key_bind = false;
static const char* g_current_key_binding_action = NULL;
bool g_waiting_for_key_bind = false;
const char* g_current_key_binding_action = NULL;
// Fallback menu if ImGui fails
static void render_fallback_menu(void);
// Verify OpenGL state is valid
static bool check_gl_state(void) {
GLenum error = glGetError();
if (error != GL_NO_ERROR) {
@@ -52,24 +44,19 @@ static bool check_gl_state(void) {
}
extern "C" bool menu_init(void) {
// Print debug message
printf("Initializing ImGui menu...\n");
i_engine->Con_Printf("Initializing ImGui menu...\n");
// Check for existing context and cleanup
if (g_imgui_context) {
printf("ImGui context already exists, shutting down first\n");
menu_shutdown();
}
// Check OpenGL state
if (!check_gl_state()) {
printf("OpenGL not ready for ImGui initialization\n");
i_engine->Con_Printf("Warning: OpenGL state not clean, continuing anyway\n");
// Not fatal, just a warning
}
// Create ImGui context
g_imgui_context = ImGui::CreateContext();
if (!g_imgui_context) {
printf("Failed to create ImGui context\n");
@@ -80,20 +67,16 @@ extern "C" bool menu_init(void) {
printf("ImGui context created successfully\n");
i_engine->Con_Printf("ImGui context created successfully\n");
// Configure ImGui
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
// Enable mouse input
io.MouseDrawCursor = false; // Don't draw cursor until menu is open
io.MouseDrawCursor = false;
// Get initial screen dimensions
SCREENINFO scr_inf;
scr_inf.iSize = sizeof(SCREENINFO);
i_engine->pfnGetScreenInfo(&scr_inf);
// Verify and set default dimensions
if (scr_inf.iWidth <= 0 || scr_inf.iHeight <= 0) {
scr_inf.iWidth = 800;
scr_inf.iHeight = 600;
@@ -104,10 +87,8 @@ extern "C" bool menu_init(void) {
scr_inf.iWidth, scr_inf.iHeight);
}
// Set initial display size - critical for NewFrame to succeed
io.DisplaySize = ImVec2((float)scr_inf.iWidth, (float)scr_inf.iHeight);
// Initialize OpenGL implementation for ImGui
bool init_result = ImGui_ImplOpenGL2_Init();
if (!init_result) {
printf("Failed to initialize ImGui OpenGL2 backend\n");
@@ -120,7 +101,6 @@ extern "C" bool menu_init(void) {
printf("ImGui OpenGL2 backend initialized successfully\n");
i_engine->Con_Printf("ImGui OpenGL2 backend initialized successfully\n");
// Set ImGui style
ImGui::StyleColorsDark();
ImGuiStyle& style = ImGui::GetStyle();
style.WindowRounding = 5.0f;
@@ -133,11 +113,9 @@ extern "C" bool menu_init(void) {
style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.3f, 0.3f, 0.3f, 1.0f);
style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.4f, 0.4f, 0.4f, 1.0f);
// Menu starts closed
g_menu_open = false;
g_imgui_initialized = true;
// Ensure game has mouse control at start
i_client->IN_ActivateMouse();
i_engine->Con_Printf("ImGui menu initialized successfully\n");
@@ -158,70 +136,54 @@ extern "C" void menu_shutdown(void) {
i_engine->Con_Printf("ImGui shutdown complete\n");
}
// Always reset menu state on shutdown
g_menu_open = false;
// Make sure the game mouse is active when we shut down
i_client->IN_ActivateMouse();
// Restore mouse bindings
i_engine->pfnClientCmd("bind mouse1 +attack; bind mouse2 +attack2");
}
extern "C" void menu_render(void) {
// Skip rendering if menu is not open
if (!g_menu_open)
return;
if (g_imgui_initialized && g_imgui_context) {
// Set the current context
ImGui::SetCurrentContext(g_imgui_context);
// Get screen dimensions
SCREENINFO scr_inf;
scr_inf.iSize = sizeof(SCREENINFO);
i_engine->pfnGetScreenInfo(&scr_inf);
// Validate screen dimensions
if (scr_inf.iWidth <= 0 || scr_inf.iHeight <= 0) {
i_engine->Con_Printf("Warning: Invalid screen dimensions, using defaults\n");
scr_inf.iWidth = 800;
scr_inf.iHeight = 600;
}
// Set display size for ImGui
ImGuiIO& io = ImGui::GetIO();
io.DisplaySize = ImVec2((float)scr_inf.iWidth, (float)scr_inf.iHeight);
// Start new ImGui frame
ImGui_ImplOpenGL2_NewFrame();
ImGui::NewFrame();
// Set window position and size
ImGui::SetNextWindowPos(ImVec2(scr_inf.iWidth * 0.5f, scr_inf.iHeight * 0.5f),
ImGuiCond_Once, ImVec2(0.5f, 0.5f));
ImGui::SetNextWindowSize(ImVec2(600, 400), ImGuiCond_Once);
// Begin main window
if (ImGui::Begin("GoldSource Cheat", &g_menu_open,
ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize)) {
// Create tabs
if (ImGui::BeginTabBar("##Tabs", ImGuiTabBarFlags_None)) {
// Aimbot tab
if (ImGui::BeginTabItem("Aimbot")) {
if (ImGui::Checkbox("Enable Aimbot", &g_settings.aimbot_enabled)) {
// No need to set cvar value
}
if (g_settings.aimbot_enabled) {
if (ImGui::SliderFloat("FOV", &g_settings.aimbot_fov, 0.1f, 180.0f, "%.1f")) {
// No need to set cvar value
}
if (ImGui::SliderFloat("Smoothing", &g_settings.aimbot_smooth, 1.0f, 100.0f, "%.1f")) {
// No need to set cvar value
}
const char* hitbox_items[] = { "Head", "Chest", "Stomach", "Pelvis", "Nearest" };
@@ -240,7 +202,6 @@ extern "C" void menu_render(void) {
ImGui::EndTabItem();
}
// Visuals tab
if (ImGui::BeginTabItem("Visuals")) {
const char* esp_modes[] = {"Off", "2D Box", "Name", "All"};
int esp_mode = (int)g_settings.esp_mode;
@@ -251,7 +212,6 @@ extern "C" void menu_render(void) {
ImGui::Checkbox("ESP Friendly", &g_settings.esp_friendly);
if (ImGui::SliderFloat("FOV Changer", &g_settings.fov, 70.0f, 140.0f, "%.1f")) {
// No need to set cvar value
}
ImGui::Checkbox("Chams", &g_settings.chams);
@@ -263,7 +223,6 @@ extern "C" void menu_render(void) {
ImGui::EndTabItem();
}
// Movement tab
if (ImGui::BeginTabItem("Movement")) {
ImGui::Checkbox("Bunny Hop", &g_settings.bhop);
@@ -282,7 +241,6 @@ extern "C" void menu_render(void) {
ImGui::EndTabItem();
}
// Misc tab with extra options
if (ImGui::BeginTabItem("Misc")) {
ImGui::Checkbox("Name Changer", &g_settings.namechanger);
@@ -298,7 +256,6 @@ extern "C" void menu_render(void) {
ImGui::Separator();
// Menu options
ImGui::Text("Menu Settings:");
ImGui::Checkbox("Allow Movement (WASD) With Menu Open", &g_settings.menu_allow_movement);
@@ -312,15 +269,12 @@ extern "C" void menu_render(void) {
ImGui::EndTabItem();
}
// View settings tab
if (ImGui::BeginTabItem("View")) {
ImGui::Text("Camera Settings:");
// Third-person settings
bool thirdperson_changed = ImGui::Checkbox("Third-Person View", &g_settings.thirdperson);
if (g_settings.thirdperson) {
// Distance preset buttons with direct setting of values
ImGui::BeginGroup();
if (ImGui::Button("100")) {
g_settings.thirdperson_dist = 100.0f;
@@ -335,20 +289,15 @@ extern "C" void menu_render(void) {
}
ImGui::EndGroup();
// Distance slider - DIRECTLY changes the value without console commands
ImGui::SliderFloat("Camera Distance", &g_settings.thirdperson_dist, 30.0f, 800.0f, "%.1f");
// Remove multiplier message since we don't multiply anymore
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "Camera distance updates in real-time");
// Key binding for third-person toggle
ImGui::Separator();
ImGui::Text("Keybind for Third-Person Toggle:");
// Display current key binding
const char* key_name = "None";
if (g_settings.thirdperson_key > 0) {
// Get better key names
switch(g_settings.thirdperson_key) {
case 'F': key_name = "F"; break;
case 'V': key_name = "V"; break;
@@ -369,13 +318,11 @@ extern "C" void menu_render(void) {
case K_MOUSE2: key_name = "Mouse2"; break;
case K_MOUSE3: key_name = "Mouse3"; break;
default: {
// For printable characters
if (g_settings.thirdperson_key >= 32 && g_settings.thirdperson_key <= 126) {
static char chr[2] = {0};
chr[0] = (char)g_settings.thirdperson_key;
key_name = chr;
} else {
// For other keys, show keycode
static char code[32] = {0};
snprintf(code, sizeof(code), "Key %d", g_settings.thirdperson_key);
key_name = code;
@@ -386,35 +333,18 @@ extern "C" void menu_render(void) {
ImGui::Text("Current Key: %s", key_name);
// TEMP: Disabled key binding until fixed
// Disable any active key bindings
if (g_waiting_for_key_bind) {
g_waiting_for_key_bind = false;
g_current_key_binding_action = NULL;
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.1f, 0.1f, 1.0f));
ImGui::Button("Press any key...", ImVec2(150, 25));
ImGui::PopStyleColor();
} else {
if (ImGui::Button("Bind new key", ImVec2(150, 25))) {
g_waiting_for_key_bind = true;
g_current_key_binding_action = "thirdperson";
i_engine->Con_Printf("Press any key to bind for third-person toggle\n");
}
}
// Show preset buttons instead
if (ImGui::Button("Bind to C", ImVec2(100, 25))) {
g_settings.thirdperson_key = 'C';
i_engine->Con_Printf("Third-person toggle bound to C key\n");
}
ImGui::SameLine();
if (ImGui::Button("Bind to V", ImVec2(100, 25))) {
g_settings.thirdperson_key = 'V';
i_engine->Con_Printf("Third-person toggle bound to V key\n");
}
ImGui::SameLine();
if (ImGui::Button("Bind to F", ImVec2(100, 25))) {
g_settings.thirdperson_key = 'F';
i_engine->Con_Printf("Third-person toggle bound to F key\n");
}
ImGui::SameLine();
if (ImGui::Button("Clear", ImVec2(80, 25))) {
g_settings.thirdperson_key = 0;
i_engine->Con_Printf("Third-person key binding cleared\n");
@@ -432,7 +362,6 @@ extern "C" void menu_render(void) {
ImGui::End();
}
// Render ImGui
ImGui::Render();
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
} else {
@@ -440,36 +369,28 @@ extern "C" void menu_render(void) {
}
}
// This is our fallback menu that we know works
static void render_fallback_menu(void) {
// Get screen dimensions
SCREENINFO scr_inf;
scr_inf.iSize = sizeof(SCREENINFO);
i_engine->pfnGetScreenInfo(&scr_inf);
// Draw simple menu background
int x1 = scr_inf.iWidth / 4;
int y1 = scr_inf.iHeight / 4;
int x2 = scr_inf.iWidth * 3 / 4;
int y2 = scr_inf.iHeight * 3 / 4;
// More visible background (darker black with higher alpha)
i_engine->pfnFillRGBA(x1, y1, x2-x1, y2-y1, 0, 0, 0, 230);
// Draw bright border for visibility
i_engine->pfnFillRGBA(x1, y1, x2-x1, 2, 255, 0, 0, 255); // Top
i_engine->pfnFillRGBA(x1, y2-2, x2-x1, 2, 255, 0, 0, 255); // Bottom
i_engine->pfnFillRGBA(x1, y1, 2, y2-y1, 255, 0, 0, 255); // Left
i_engine->pfnFillRGBA(x2-2, y1, 2, y2-y1, 255, 0, 0, 255); // Right
i_engine->pfnFillRGBA(x1, y1, x2-x1, 2, 255, 0, 0, 255);
i_engine->pfnFillRGBA(x1, y2-2, x2-x1, 2, 255, 0, 0, 255);
i_engine->pfnFillRGBA(x1, y1, 2, y2-y1, 255, 0, 0, 255);
i_engine->pfnFillRGBA(x2-2, y1, 2, y2-y1, 255, 0, 0, 255);
// Title
i_engine->pfnDrawSetTextColor(1.0f, 1.0f, 0.0f);
i_engine->pfnDrawConsoleString(x1+10, y1+10, "===== GoldSource Cheat Menu (Fallback) =====");
// Reset color for menu items
i_engine->pfnDrawSetTextColor(0.0f, 1.0f, 1.0f);
// Draw menu items
int y = y1 + 40;
i_engine->pfnDrawConsoleString(x1+20, y, "-- Aimbot Settings --");
y += 20;
@@ -506,40 +427,39 @@ static void render_fallback_menu(void) {
i_engine->pfnDrawConsoleString(x1+30, y, buffer);
y += 30;
// Instructions
i_engine->pfnDrawSetTextColor(1.0f, 1.0f, 0.0f);
i_engine->pfnDrawConsoleString(x1+20, y, "Press INSERT to close menu");
y += 20;
i_engine->pfnDrawConsoleString(x1+20, y, "Use console to change settings");
// Draw help in bottom corner
i_engine->pfnDrawSetTextColor(0.7f, 0.7f, 0.7f);
i_engine->pfnDrawConsoleString(5, scr_inf.iHeight - 20, "Type 'dz_menu' in console to toggle menu");
}
// Update the key event handler to support key binding
extern "C" void menu_key_event(int keynum, int down) {
// Add debug output
i_engine->Con_Printf("menu_key_event called: keynum=%d, down=%d\n", keynum, down);
i_engine->Con_Printf("menu_key_event called: keynum=%d, down=%d, waiting_for_key=%d\n",
keynum, down, g_waiting_for_key_bind);
// If we're waiting for a key bind and a key is pressed down
if (g_waiting_for_key_bind && down && keynum != K_ESCAPE) {
// Don't bind mouse wheel or menu toggle key
i_engine->Con_Printf("Processing key bind: keynum=%d, action=%s\n",
keynum, g_current_key_binding_action ? g_current_key_binding_action : "none");
// Skip wheel events and menu toggle key
if (keynum != K_MWHEELDOWN && keynum != K_MWHEELUP && keynum != K_INS) {
// Bind the key based on current action
if (g_current_key_binding_action && strcmp(g_current_key_binding_action, "thirdperson") == 0) {
g_settings.thirdperson_key = keynum;
i_engine->Con_Printf("Third-person key bound to keycode: %d\n", keynum);
}
// Exit binding mode
g_waiting_for_key_bind = false;
g_current_key_binding_action = NULL;
i_engine->Con_Printf("Key binding completed!\n");
return;
} else {
i_engine->Con_Printf("Ignored wheel/INS key: %d\n", keynum);
}
}
// Cancel key binding if escape is pressed
if (g_waiting_for_key_bind && down && keynum == K_ESCAPE) {
g_waiting_for_key_bind = false;
g_current_key_binding_action = NULL;
@@ -548,31 +468,24 @@ extern "C" void menu_key_event(int keynum, int down) {
}
if (keynum == K_INS && down) {
// Toggle menu state
g_menu_open = !g_menu_open;
i_engine->Con_Printf("Menu %s\n", g_menu_open ? "opened" : "closed");
// Update ImGui IO if initialized
if (g_imgui_initialized && g_imgui_context) {
ImGui::SetCurrentContext(g_imgui_context);
ImGuiIO& io = ImGui::GetIO();
io.MouseDrawCursor = g_menu_open;
}
// Activate or deactivate mouse based on menu state
if (g_menu_open) {
// When opening menu, deactivate mouse in game and use our own cursor
i_client->IN_DeactivateMouse();
i_client->IN_ClearStates();
// Fixes potential issues with key state
i_engine->pfnClientCmd("unbind mouse1; unbind mouse2");
i_engine->Con_Printf("Mouse deactivated for game, using ImGui cursor\n");
} else {
// When closing menu, reactivate mouse in game
i_client->IN_ActivateMouse();
// Restore default bindings
i_engine->pfnClientCmd("bind mouse1 +attack; bind mouse2 +attack2");
i_engine->Con_Printf("Mouse reactivated for game\n");
}