├── .gitignore ├── README.md ├── core ├── hooks │ ├── hooks.cpp │ └── hooks.hpp ├── main.cpp └── menu │ ├── menu.cpp │ ├── menu.hpp │ └── zgui │ ├── menu.cpp │ ├── menu.hpp │ ├── zgui.cpp │ └── zgui.hpp ├── csgo-cheat.sln ├── csgo-cheat.vcxproj ├── csgo-cheat.vcxproj.user ├── dependencies ├── common_includes.hpp ├── interfaces │ ├── cglobalvarsbase.hpp │ ├── ibaseclientdll.hpp │ ├── icliententitylist.hpp │ ├── iclientmode.hpp │ ├── iclientstate.hpp │ ├── iconsole.hpp │ ├── igameeventmanager.hpp │ ├── iinput.hpp │ ├── ilocalize.hpp │ ├── imaterialsystem.hpp │ ├── interfaces.cpp │ ├── interfaces.hpp │ ├── ipanel.hpp │ ├── isurface.hpp │ ├── ivdebugoverlay.hpp │ ├── iveffects.hpp │ ├── ivengineclient.hpp │ ├── ivmodelinfo.hpp │ └── ivmodelrender.hpp └── utilities │ ├── fnv.hpp │ ├── hook.cpp │ ├── hook.hpp │ ├── netvars.cpp │ ├── netvars.hpp │ ├── render.cpp │ ├── render.hpp │ ├── utilities.cpp │ └── utilities.hpp └── source-sdk ├── classes ├── c_usercmd.hpp ├── client_class.hpp ├── collideable.hpp ├── convar.hpp ├── entities.hpp ├── gameevent.hpp ├── recv_props.hpp └── studio.hpp ├── math ├── vector2d.hpp ├── vector3d.cpp └── vector3d.hpp ├── misc └── color.hpp ├── sdk.hpp └── structs ├── dlight.hpp ├── materials.hpp ├── models.hpp ├── vertex_t.hpp └── weaponinfo.hpp /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | \.vs/csgo-cheat/v16/ 3 | 4 | intermediates/csgo-cheat\.tlog/CL\.command\.1\.tlog 5 | 6 | *.log 7 | 8 | intermediates/csgo-cheat\.tlog/ 9 | 10 | *.idb 11 | 12 | *.pdb 13 | 14 | *.obj 15 | 16 | output/debug/ 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sdk 2 | 3 | ___________________________________________ 4 | a clean sdk to start writing a cheat on 5 | for csgo. this has everything you need for 6 | a fully featured internal cheat. 7 | 8 | ___________________________________________ 9 | many of my close friends may know this as ayysense. 10 | this was the initial sdk, without the menu, aimbot, esp, and everything else 11 | that ayysense had. 12 | 13 | credits to wzn, rifk/czapek, duxe. 14 | 15 | apologies to rifk/czapek; i know that you didnt want this public, but at this point 16 | i know you don't care about it, and you no longer work on it. this is without the menu 17 | that ayysense had, so it shouldn't be a big deal. 18 | -------------------------------------------------------------------------------- /core/hooks/hooks.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "..//menu/menu.hpp" 3 | #include "../../dependencies/common_includes.hpp" 4 | #include 5 | 6 | std::unique_ptr hooks::client_hook; 7 | std::unique_ptr hooks::clientmode_hook; 8 | std::unique_ptr hooks::panel_hook; 9 | std::unique_ptr hooks::renderview_hook; 10 | WNDPROC hooks::wndproc_original = NULL; 11 | 12 | void hooks::initialize( ) { 13 | client_hook = std::make_unique( ); 14 | clientmode_hook = std::make_unique( ); 15 | panel_hook = std::make_unique( ); 16 | renderview_hook = std::make_unique( ); 17 | 18 | client_hook->setup( interfaces::client ); 19 | client_hook->hook_index( 37, reinterpret_cast< void* >( frame_stage_notify ) ); 20 | 21 | clientmode_hook->setup( interfaces::clientmode ); 22 | clientmode_hook->hook_index( 24, reinterpret_cast< void* >( create_move ) ); 23 | 24 | panel_hook->setup( interfaces::panel ); 25 | panel_hook->hook_index( 41, reinterpret_cast< void* >( paint_traverse ) ); 26 | 27 | renderview_hook->setup( interfaces::render_view ); 28 | renderview_hook->hook_index( 9, reinterpret_cast< void* >( scene_end ) ); 29 | 30 | wndproc_original = reinterpret_cast< WNDPROC >( SetWindowLongPtrA( FindWindow( "Valve001", NULL ), GWL_WNDPROC, reinterpret_cast< LONG >( wndproc ) ) ); 31 | 32 | interfaces::console->get_convar( "viewmodel_fov" )->callbacks.SetSize( 0 ); 33 | interfaces::console->get_convar( "mat_postprocess_enable" )->set_value( 0 ); 34 | interfaces::console->get_convar( "crosshair" )->set_value( 1 ); 35 | 36 | render::setup_fonts( ); 37 | 38 | zgui::functions.draw_line = render::line; 39 | zgui::functions.draw_rect = render::rect; 40 | zgui::functions.draw_filled_rect = render::filled_rect; 41 | zgui::functions.draw_text = render::text; 42 | zgui::functions.get_text_size = render::get_text_size; 43 | zgui::functions.get_frametime = render::get_frametime; 44 | } 45 | 46 | void hooks::shutdown( ) { 47 | client_hook->release( ); 48 | clientmode_hook->release( ); 49 | panel_hook->release( ); 50 | renderview_hook->release( ); 51 | 52 | SetWindowLongPtrA( FindWindow( "Valve001", NULL ), GWL_WNDPROC, reinterpret_cast< LONG >( wndproc_original ) ); 53 | } 54 | 55 | bool __stdcall hooks::create_move( float frame_time, c_usercmd* user_cmd ) { 56 | static auto original_fn = reinterpret_cast< create_move_fn >( clientmode_hook->get_original( 24 ) )( interfaces::clientmode, frame_time, user_cmd ); 57 | 58 | if ( !user_cmd || !user_cmd->command_number ) 59 | return original_fn; 60 | 61 | if ( !interfaces::entity_list->get_client_entity( interfaces::engine->get_local_player( ) ) ) 62 | return original_fn; 63 | 64 | return false; 65 | } 66 | 67 | void __stdcall hooks::frame_stage_notify( int frame_stage ) { 68 | reinterpret_cast< frame_stage_notify_fn >( client_hook->get_original( 37 ) )( interfaces::client, frame_stage ); 69 | } 70 | 71 | void __stdcall hooks::paint_traverse( unsigned int panel, bool force_repaint, bool allow_force ) { 72 | std::string panel_name = interfaces::panel->get_panel_name( panel ); 73 | 74 | reinterpret_cast< paint_traverse_fn >( panel_hook->get_original( 41 ) )( interfaces::panel, panel, force_repaint, allow_force ); 75 | 76 | static unsigned int _panel = 0; 77 | static bool once = false; 78 | 79 | if ( !once ) { 80 | char* panel_char = ( char* )( interfaces::panel->get_panel_name( panel ) ); 81 | if ( strstr( panel_char, "MatSystemTopPanel" ) ) { 82 | _panel = panel; 83 | once = true; 84 | } 85 | } 86 | else if ( _panel == panel ) { 87 | g_menu.render( ); 88 | } 89 | } 90 | 91 | void __stdcall hooks::scene_end( ) { 92 | reinterpret_cast< scene_end_fn >( renderview_hook->get_original( 9 ) )( interfaces::render_view ); 93 | } 94 | 95 | LRESULT __stdcall hooks::wndproc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam ) { 96 | return CallWindowProcA( wndproc_original, hwnd, message, wparam, lparam ); 97 | } 98 | -------------------------------------------------------------------------------- /core/hooks/hooks.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace hooks { 4 | extern std::unique_ptr client_hook; 5 | extern std::unique_ptr clientmode_hook; 6 | extern std::unique_ptr panel_hook; 7 | extern std::unique_ptr renderview_hook; 8 | extern WNDPROC wndproc_original; 9 | 10 | void initialize( ); 11 | void shutdown( ); 12 | 13 | using create_move_fn = bool( __thiscall* )( i_client_mode*, float, c_usercmd* ); 14 | using frame_stage_notify_fn = void( __thiscall* )( i_base_client_dll*, int ); 15 | using paint_traverse_fn = void( __thiscall* )( i_panel*, unsigned int, bool, bool ); 16 | using scene_end_fn = void( __thiscall* )( void* ); 17 | 18 | bool __stdcall create_move( float frame_time, c_usercmd* user_cmd ); 19 | void __stdcall frame_stage_notify( int frame_stage ); 20 | void __stdcall paint_traverse( unsigned int panel, bool force_repaint, bool allow_force ); 21 | void __stdcall scene_end( ); 22 | LRESULT __stdcall wndproc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam ); 23 | } -------------------------------------------------------------------------------- /core/main.cpp: -------------------------------------------------------------------------------- 1 | #include "../dependencies/common_includes.hpp" 2 | 3 | unsigned long __stdcall initial_thread( void* reserved ) { 4 | 5 | AllocConsole( ); 6 | SetConsoleTitleW( L"Counter-Strike: Global Offensive" ); 7 | freopen_s( reinterpret_cast< FILE** >stdin, "CONIN$", "r", stdin ); 8 | freopen_s( reinterpret_cast< FILE** >stdout, "CONOUT$", "w", stdout ); 9 | 10 | interfaces::initialize( ); 11 | 12 | g_netvar_mgr.initialize( interfaces::client->get_client_classes( ) ); 13 | 14 | hooks::initialize( ); 15 | 16 | while ( !GetAsyncKeyState( VK_END ) ) 17 | std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) ); 18 | 19 | hooks::shutdown( ); 20 | std::this_thread::sleep_for( std::chrono::milliseconds( 100 ) ); 21 | 22 | FreeLibraryAndExitThread( reinterpret_cast< HMODULE >( reserved ), 0 ); 23 | return 0ul; 24 | } 25 | 26 | bool __stdcall DllMain( void* instance, unsigned long reason_to_call, void* reserved ) { 27 | if ( reason_to_call == DLL_PROCESS_ATTACH ) { 28 | CreateThread( 0, 0, initial_thread, instance, 0, 0 ); 29 | } 30 | 31 | return true; 32 | } 33 | -------------------------------------------------------------------------------- /core/menu/menu.cpp: -------------------------------------------------------------------------------- 1 | #include "menu.hpp" 2 | 3 | c_menu g_menu; 4 | 5 | void c_menu::render( ) { 6 | static bool checkbox; 7 | static float sliderf; 8 | static int slideri, dropdown; 9 | 10 | zgui::poll_input( "Counter-Strike: Global Offensive" ); 11 | 12 | if ( zgui::begin_window( "sdk for counter-strike: global offensive", { 500, 350 }, render::main_font ) ) { 13 | zgui::begin_groupbox( "Example groupbox", { 468, 311 } ); 14 | { 15 | zgui::checkbox( "Example checkbox", checkbox ); 16 | zgui::slider_float( "Example slider (float)", 0.0f, 100.0f, sliderf ); 17 | zgui::slider_int( "Example slider (int)", 0, 100, slideri ); 18 | zgui::combobox( "Example dropdown", { "aaaa", "bbbb", "cccc", "dddd" }, dropdown ); 19 | } 20 | zgui::end_groupbox( ); 21 | 22 | zgui::end_window( ); 23 | } 24 | } -------------------------------------------------------------------------------- /core/menu/menu.hpp: -------------------------------------------------------------------------------- 1 | #include "..//..//dependencies/common_includes.hpp" 2 | #include "zgui/zgui.hpp" 3 | 4 | class c_menu { 5 | public: 6 | void render( ); 7 | }; 8 | 9 | extern c_menu g_menu; -------------------------------------------------------------------------------- /core/menu/zgui/menu.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "zgui.hpp" 8 | 9 | // zgui by zxvnme (https://github.com/zxvnme) 10 | // heres defines that are designed to be modified by your preferences. 11 | // see zgui.hh for complete documentation. 12 | // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 13 | 14 | // Color definition. Can be changed at any time just simply by editing this struct. 15 | static struct { 16 | zgui::color window_border_inner_fill{ 60, 60, 60, 255 }; 17 | zgui::color window_border_fill{ 40, 40, 40, 255 }; 18 | zgui::color window_border_color{ 10, 10, 10, 255 }; 19 | zgui::color window_background{ 40, 40, 40, 255 }; 20 | 21 | zgui::color control_outline{ 23, 23, 30, 255 }; 22 | zgui::color control_active_or_clicked{ 108, 92, 231, 255 }; 23 | zgui::color control_idle{ 62, 62, 72, 255 }; 24 | 25 | zgui::color color_groupbox_bg{ 50, 50, 50, 255 }; 26 | zgui::color color_text{ 203, 203, 203, 255 }; 27 | zgui::color color_text_dimmer{ 99, 110, 114, 255 }; 28 | zgui::color color_slider{ 108, 92, 231, 255 }; 29 | zgui::color color_combo_bg{ 108, 92, 231, 255 }; 30 | } global_colors; 31 | 32 | static struct { 33 | // Base position of first drawn control (px). DO NOT change if its necessary 34 | zgui::vec2 base_pos{ 16, 23 }; 35 | // Spacing between items (px) 36 | int item_spacing = 16; 37 | // Key that will toggle menu visibility unless zgui_window_flags_always_open is set 38 | int menu_toggle_key = VK_INSERT; 39 | } global_config; 40 | 41 | // Window definitions. 42 | static struct gui_context_t { 43 | zgui::gui_window_context_t window; 44 | } context; 45 | 46 | // "Proxy" functions stuff... 47 | zgui::functions_t zgui::functions; 48 | 49 | // Globals 50 | static zgui::vec2 mouse_pos; 51 | static zgui::vec2 previous_mouse_pos; 52 | 53 | // Input handling stuff 54 | static bool key_state[256]; 55 | static bool prev_key_state[256]; 56 | 57 | // Check for input polling. 58 | static bool input_loop_started = false; 59 | 60 | // Function for starting our input loop. 61 | void zgui::poll_input(std::string_view window_name) 62 | { 63 | if (window_name.empty()) 64 | throw std::exception("No window from where input should be read from specified in function parameter."); 65 | 66 | for (int i = 0; i < 256; i++) { 67 | prev_key_state[i] = key_state[i]; 68 | key_state[i] = GetAsyncKeyState(i); 69 | } 70 | 71 | POINT p_mouse_pos; 72 | GetCursorPos(&p_mouse_pos); 73 | ScreenToClient(FindWindow(nullptr, window_name.data()), &p_mouse_pos); 74 | previous_mouse_pos = mouse_pos; 75 | mouse_pos = vec2{ static_cast(p_mouse_pos.x), static_cast(p_mouse_pos.y) }; 76 | 77 | if (!input_loop_started) 78 | input_loop_started = true; 79 | } 80 | 81 | // Function for starting our input loop. 82 | void zgui::poll_input(HWND hwnd) 83 | { 84 | if (!hwnd) 85 | throw std::exception("No window from where input should be read from specified in function parameter."); 86 | 87 | for (int i = 0; i < 256; i++) { 88 | prev_key_state[i] = key_state[i]; 89 | key_state[i] = GetAsyncKeyState(i); 90 | } 91 | 92 | POINT p_mouse_pos; 93 | GetCursorPos(&p_mouse_pos); 94 | ScreenToClient(hwnd, &p_mouse_pos); 95 | previous_mouse_pos = mouse_pos; 96 | mouse_pos = vec2{ static_cast(p_mouse_pos.x), static_cast(p_mouse_pos.y) }; 97 | 98 | if (!input_loop_started) 99 | input_loop_started = true; 100 | } 101 | 102 | // Input utilities. 103 | constexpr bool key_pressed(const int key) noexcept 104 | { 105 | return key_state[key] && !prev_key_state[key]; 106 | } 107 | 108 | constexpr bool key_down(const int key) noexcept 109 | { 110 | return key_state[key]; 111 | } 112 | 113 | constexpr bool key_released(const int key) noexcept 114 | { 115 | return !key_state[key] && prev_key_state[key]; 116 | } 117 | 118 | // Check if mouse is hovered over specified region. 119 | bool mouse_in_region(const int x, const int y, const int w, const int h) noexcept 120 | { 121 | return mouse_pos.x > x && mouse_pos.y > y && mouse_pos.x < w + x && mouse_pos.y < h + y; 122 | } 123 | 124 | // Push cursor position to the stack 125 | void zgui::push_cursor_pos(const vec2 pos) noexcept 126 | { 127 | context.window.cursor_pos.push(pos); 128 | } 129 | 130 | // Pop cursor position from the stack 131 | zgui::vec2 zgui::pop_cursor_pos() noexcept 132 | { 133 | const vec2 pos = context.window.cursor_pos.top(); 134 | context.window.cursor_pos.pop(); 135 | return pos; 136 | } 137 | 138 | void zgui::push_font(const unsigned long font) noexcept 139 | { 140 | context.window.fonts.push(font); 141 | } 142 | 143 | unsigned long zgui::pop_font() 144 | { 145 | const unsigned long font = context.window.fonts.top(); 146 | context.window.fonts.pop(); 147 | return font; 148 | } 149 | 150 | // Hashing util 151 | std::vector split_str(const char* str, const char separator) noexcept 152 | { 153 | std::vector output; 154 | std::string substring; 155 | std::istringstream stream{ str }; 156 | 157 | while (std::getline(stream, substring, separator)) 158 | output.push_back(substring); 159 | 160 | return output; 161 | } 162 | 163 | static constexpr uint32_t hash(const char* str, const uint32_t value = 0x811c9dc5) noexcept 164 | { 165 | return *str ? hash(str + 1, (value ^ *str) * 0x1000193ull) : value; 166 | } 167 | 168 | // Names for each of VKs 169 | constexpr std::string_view keys_list[]{ 170 | "Error", "Left Mouse", "Right Mouse", "Break", "Middle Mouse", "Mouse 4", "Mouse 5", 171 | "Error", "Backspace", "TAB", "Error", "Error", "Error", "ENTER", "Error", "Error", "SHIFT", 172 | "CTRL", "ALT","PAUSE","CAPS LOCK", "Error", "Error", "Error", "Error", "Error", "Error", 173 | "Error", "Error", "Error", "Error", "Error", "SPACEBAR","PG UP", "PG DOWN", "END", "HOME", "Left", 174 | "Up", "Right", "Down", "Error", "Print", "Error", "Print Screen", "Insert","Delete", "Error", "0", "1", 175 | "2", "3", "4", "5", "6", "7", "8", "9", "Error", "Error", "Error", "Error", "Error", "Error", 176 | "Error", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", 177 | "V", "W", "X","Y", "Z", "Left Windows", "Right Windows", "Error", "Error", "Error", "NUM 0", "NUM 1", 178 | "NUM 2", "NUM 3", "NUM 4", "NUM 5", "NUM 6","NUM 7", "NUM 8", "NUM 9", "*", "+", "_", "-", ".", "/", "F1", "F2", "F3", 179 | "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12","F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21", 180 | "F22", "F23", "F24", "Error", "Error", "Error", "Error", "Error","Error", "Error", "Error", 181 | "NUM LOCK", "SCROLL LOCK", "Error", "Error", "Error", "Error", "Error", "Error", "Error", 182 | "Error", "Error","Error", "Error", "Error", "Error", "Error", "LSHIFT", "RSHIFT", "LCONTROL", 183 | "RCONTROL", "LMENU", "RMENU", "Error","Error", "Error","Error", "Error", "Error", "Error", 184 | "Error", "Error", "Error", "Next Track", "Previous Track", "Stop", "Play/Pause", "Error", "Error", 185 | "Error", "Error", "Error", "Error", ";", "+", ",", "-", ".", "/?", "~", "Error", "Error", 186 | "Error", "Error","Error", "Error", "Error", "Error", "Error", "Error", "Error", 187 | "Error", "Error", "Error", "Error", "Error", "Error", "Error", "Error","Error", 188 | "Error", "Error", "Error", "Error", "Error", "Error", "[{", "\\|", "}]", "'\"", "Error", 189 | "Error", "Error", "Error","Error", "Error", "Error", "Error", "Error", "Error", 190 | "Error", "Error", "Error", "Error", "Error", "Error", "Error", "Error", "Error", 191 | "Error", "Error", "Error", "Error", "Error", "Error", "Error", "Error", "Error", 192 | "Error", "Error" 193 | }; 194 | 195 | struct key_code_info { 196 | int vk; 197 | 198 | char regular; 199 | char shift; 200 | }; 201 | 202 | static key_code_info special_characters[22] = { 203 | { 48, '0', ')' }, 204 | { 49, '1', '!' }, 205 | { 50, '2', '@' }, 206 | { 51, '3', '#' }, 207 | { 52, '4', '$' }, 208 | { 53, '5', '%' }, 209 | { 54, '6', '^' }, 210 | { 55, '7', '&' }, 211 | { 56, '8', '*' }, 212 | { 57, '9', '(' }, 213 | { 32, ' ', ' ' }, 214 | { 192, '`', '~' }, 215 | { 189, '-', '_' }, 216 | { 187, '=', '+' }, 217 | { 219, '[', '{' }, 218 | { 220, '\\', '|' }, 219 | { 221, ']', '}' }, 220 | { 186, ';', ':' }, 221 | { 222, '\'', '"' }, 222 | { 188, ',', '<' }, 223 | { 190, '.', '>' }, 224 | { 191, '/', '?' } 225 | }; 226 | 227 | bool zgui::begin_window(std::string_view title, const vec2 default_size, const unsigned long font, const int flags) 228 | { 229 | if (!input_loop_started) 230 | throw std::exception("Input loop didnt start or didnt start properly.");; 231 | 232 | if (!(flags & zgui_window_flags_always_open)) 233 | { 234 | if (key_pressed(global_config.menu_toggle_key)) 235 | context.window.opened = !context.window.opened; 236 | } 237 | else 238 | context.window.opened = true; 239 | 240 | if (const int prev_alpha = context.window.alpha; !(flags & zgui_window_flags_no_ontoggle_animation)) 241 | { 242 | const int fade_factor = static_cast(1.0f / 0.15f * functions.get_frametime() * 255); 243 | context.window.alpha = std::clamp(context.window.alpha + (context.window.opened ? fade_factor : -fade_factor), 0, 255); 244 | 245 | if (context.window.alpha != prev_alpha) 246 | { 247 | global_colors.window_border_inner_fill.a = context.window.alpha; 248 | global_colors.window_border_fill.a = context.window.alpha; 249 | global_colors.window_border_color.a = context.window.alpha; 250 | global_colors.window_background.a = context.window.alpha; 251 | 252 | global_colors.control_outline.a = context.window.alpha; 253 | global_colors.control_active_or_clicked.a = context.window.alpha; 254 | global_colors.control_idle.a = context.window.alpha; 255 | 256 | global_colors.color_groupbox_bg.a = context.window.alpha; 257 | global_colors.color_text.a = context.window.alpha; 258 | global_colors.color_text_dimmer.a = context.window.alpha; 259 | global_colors.color_slider.a = context.window.alpha; 260 | } 261 | } 262 | 263 | if (context.window.opened || context.window.alpha > 0) 264 | { 265 | if (!(flags & zgui_window_flags_no_move)) 266 | { 267 | if ((flags & zgui_window_flags_no_border ? mouse_in_region(context.window.position.x + 9, context.window.position.y + 14, context.window.size.x - 18, 14) 268 | : mouse_in_region(context.window.position.x - 6, context.window.position.y - 10, context.window.size.x + 12, 16)) 269 | && key_pressed(VK_LBUTTON) && !context.window.dragging) 270 | { 271 | context.window.dragging = true; 272 | } 273 | else if (key_down(VK_LBUTTON) && context.window.dragging) 274 | { 275 | const vec2 mouse_delta{ mouse_pos.x - previous_mouse_pos.x, mouse_pos.y - previous_mouse_pos.y }; 276 | const vec2 new_position{ context.window.position.x + mouse_delta.x, context.window.position.y + mouse_delta.y }; 277 | 278 | context.window.position = new_position; 279 | } 280 | else if (!key_down(VK_LBUTTON) && context.window.dragging) 281 | { 282 | context.window.dragging = false; 283 | } 284 | } 285 | 286 | if (context.window.size.x < 1 && context.window.size.y < 1) 287 | context.window.size = default_size; 288 | 289 | if (!(flags & zgui_window_flags_no_border)) 290 | { 291 | functions.draw_filled_rect(context.window.position.x - 6, context.window.position.y - 10, context.window.size.x + 12, context.window.size.y + 16, global_colors.window_border_inner_fill); 292 | functions.draw_filled_rect(context.window.position.x - 5, context.window.position.y - 9, context.window.size.x + 10, context.window.size.y + 14, global_colors.window_border_color); 293 | functions.draw_filled_rect(context.window.position.x - 4, context.window.position.y - 8, context.window.size.x + 8, context.window.size.y + 12, global_colors.window_border_fill); 294 | functions.draw_filled_rect(context.window.position.x, context.window.position.y + 7, context.window.size.x, context.window.size.y - 7, global_colors.window_border_color); 295 | functions.draw_filled_rect(context.window.position.x + 1, context.window.position.y + 8, context.window.size.x - 2, context.window.size.y - 9, global_colors.window_border_inner_fill); 296 | functions.draw_filled_rect(context.window.position.x + 8, context.window.position.y + 15, context.window.size.x - 16, context.window.size.y - 23, global_colors.window_border_color); 297 | } 298 | 299 | if (!(flags & zgui_window_flags_no_titlebar)) 300 | functions.draw_text(context.window.position.x + context.window.size.x * 0.5, context.window.position.y + (context.window.size.y * 0.010) - 10, global_colors.color_text, font, true, title.data()); 301 | 302 | functions.draw_filled_rect(context.window.position.x + 9, context.window.position.y + 16, context.window.size.x - 18, context.window.size.y - 25, global_colors.window_background); 303 | 304 | 305 | push_font(font); 306 | push_cursor_pos(global_config.base_pos); 307 | } 308 | 309 | return context.window.opened || context.window.alpha > 0; 310 | } 311 | 312 | void zgui::end_window() noexcept 313 | { 314 | for (int i = context.window.render.size() - 1; i >= 0; i--) 315 | { 316 | switch (context.window.render[i].render_type) 317 | { 318 | case zgui_render_type::zgui_line: 319 | functions.draw_line(context.window.render[i].draw_position.x, context.window.render[i].draw_position.y, context.window.render[i].size.x, context.window.render[i].size.y, context.window.render[i].color); 320 | break; 321 | case zgui_render_type::zgui_rect: 322 | functions.draw_rect(context.window.render[i].draw_position.x, context.window.render[i].draw_position.y, context.window.render[i].size.x, context.window.render[i].size.y, context.window.render[i].color); 323 | break; 324 | case zgui_render_type::zgui_filled_rect: 325 | functions.draw_filled_rect(context.window.render[i].draw_position.x, context.window.render[i].draw_position.y, context.window.render[i].size.x, context.window.render[i].size.y, context.window.render[i].color); 326 | break; 327 | case zgui_render_type::zgui_text: 328 | functions.draw_text(context.window.render[i].draw_position.x, context.window.render[i].draw_position.y, context.window.render[i].color, context.window.render[i].font, false, context.window.render[i].text.c_str()); 329 | break; 330 | } 331 | } 332 | 333 | context.window.render.clear(); 334 | 335 | while (!context.window.cursor_pos.empty()) 336 | context.window.cursor_pos.pop(); 337 | 338 | } 339 | 340 | void zgui::begin_groupbox(std::string_view title, const vec2 size, const int flags) noexcept 341 | { 342 | const int font = pop_font(); 343 | 344 | const vec2 cursor_pos = pop_cursor_pos(); 345 | const vec2 draw_pos{ context.window.position.x + cursor_pos.x, context.window.position.y + cursor_pos.y }; 346 | 347 | functions.draw_rect(draw_pos.x - 1, draw_pos.y - 1, size.x + 2, size.y + 2, global_colors.control_outline); 348 | functions.draw_filled_rect(draw_pos.x, draw_pos.y, size.x, size.y, global_colors.color_groupbox_bg); 349 | 350 | if (title.length() > 0) 351 | { 352 | if (!(flags & zgui_groupbox_flags_title_centered)) 353 | { 354 | functions.draw_text(draw_pos.x + 4, draw_pos.y - 8, global_colors.color_text, font, false, title.data()); 355 | } 356 | else 357 | { 358 | int text_wide, text_tall; 359 | functions.get_text_size(font, title.data(), text_wide, text_tall); 360 | functions.draw_text(draw_pos.x + size.x / 2 - text_wide / 2, draw_pos.y - 8, global_colors.color_text, font, false, title.data()); 361 | } 362 | } 363 | 364 | context.window.next_cursor_pos = vec2{ cursor_pos.x, cursor_pos.y + size.y + 10 }; 365 | 366 | push_cursor_pos(vec2{ cursor_pos.x + 8, cursor_pos.y + 14 }); 367 | 368 | push_font(font); 369 | } 370 | 371 | void zgui::end_groupbox() noexcept 372 | { 373 | push_cursor_pos(context.window.next_cursor_pos); 374 | context.window.next_cursor_pos = { }; 375 | } 376 | 377 | void zgui::checkbox(const char* id, bool& value) noexcept 378 | { 379 | std::vector id_split = split_str(id, '#'); 380 | 381 | const int control_height = 8; 382 | const int control_width = 8; 383 | 384 | const int font = pop_font(); 385 | 386 | const vec2 cursor_pos = pop_cursor_pos(); 387 | const vec2 draw_pos{ context.window.position.x + cursor_pos.x, context.window.position.y + cursor_pos.y }; 388 | 389 | int text_wide, text_tall; 390 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 391 | 392 | const bool active = context.window.blocking == hash(id); 393 | 394 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width + 6 + text_wide, control_height); !active && hovered && key_pressed(VK_LBUTTON)) 395 | { 396 | context.window.blocking = hash(id); 397 | } 398 | else if (active && !key_down(VK_LBUTTON)) 399 | { 400 | context.window.blocking = 0; 401 | value = !value; 402 | } 403 | 404 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 14, draw_pos.y - 2 }, zgui_render_type::zgui_text, value ? global_colors.color_text : global_colors.color_text_dimmer, id_split[0], vec2{0,0}, font }); 405 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, value ? global_colors.control_active_or_clicked : global_colors.control_idle, "", { control_width - 2, control_height - 2 } }); 406 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline,"", { control_width, control_height } }); 407 | 408 | push_cursor_pos(vec2{ cursor_pos.x + 14 + text_wide + global_config.item_spacing, cursor_pos.y }); 409 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + global_config.item_spacing }); 410 | 411 | push_font(font); 412 | } 413 | 414 | void zgui::toggle_button(const char* id, const vec2 size, bool& value) noexcept 415 | { 416 | std::vector id_split = split_str(id, '#'); 417 | 418 | const int font = pop_font(); 419 | 420 | const vec2 cursor_pos = pop_cursor_pos(); 421 | const vec2 draw_pos{ context.window.position.x + cursor_pos.x, context.window.position.y + cursor_pos.y }; 422 | 423 | const bool active = context.window.blocking == hash(id); 424 | 425 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, size.x, size.y); !active && hovered && key_pressed(VK_LBUTTON)) 426 | { 427 | context.window.blocking = hash(id); 428 | } 429 | else if (active && !key_down(VK_LBUTTON)) 430 | { 431 | context.window.blocking = 0; 432 | value = !value; 433 | } 434 | 435 | int text_wide, text_tall; 436 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 437 | 438 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + size.x / 2 - text_wide / 2, draw_pos.y + size.y / 2 - text_tall / 2 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 439 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, value ? global_colors.control_active_or_clicked : global_colors.control_idle, "", size }); 440 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline, "", { size.x + 2, size.y + 2 } }); 441 | 442 | push_cursor_pos(vec2{ cursor_pos.x + size.x + global_config.item_spacing, cursor_pos.y }); 443 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + size.y / 2 + global_config.item_spacing }); 444 | 445 | push_font(font); 446 | } 447 | 448 | bool zgui::button(const char* id, const vec2 size) noexcept 449 | { 450 | std::vector id_split = split_str(id, '#'); 451 | 452 | const int font = pop_font(); 453 | 454 | const vec2 cursor_pos = pop_cursor_pos(); 455 | const vec2 draw_pos{ context.window.position.x + cursor_pos.x, context.window.position.y + cursor_pos.y }; 456 | 457 | const bool active = context.window.blocking == hash(id); 458 | 459 | bool result = false; 460 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, size.x, size.y); !active && hovered && key_pressed(VK_LBUTTON)) 461 | { 462 | context.window.blocking = hash(id); 463 | } 464 | else if (active && !key_down(VK_LBUTTON)) 465 | { 466 | context.window.blocking = 0; 467 | result = hovered; 468 | } 469 | 470 | int text_wide, text_tall; 471 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 472 | 473 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + size.x / 2 - text_wide / 2, draw_pos.y + size.y / 2 - text_tall / 2 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 474 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, active ? global_colors.control_active_or_clicked : global_colors.control_idle, "", {size.x - 2, size.y - 2} }); 475 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline, "", size }); 476 | 477 | push_cursor_pos(vec2{ cursor_pos.x + size.x + global_config.item_spacing, cursor_pos.y }); 478 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + size.y / 2 + global_config.item_spacing }); 479 | 480 | push_font(font); 481 | 482 | return result; 483 | } 484 | 485 | void zgui::key_bind(const char* id, int& value) noexcept 486 | { 487 | std::vector id_split = split_str(id, '#'); 488 | 489 | const int control_width = 80; 490 | const int control_height = 20; 491 | 492 | value = std::clamp(value, 0, 255); 493 | 494 | const int font = pop_font(); 495 | 496 | const vec2 cursor_pos = pop_cursor_pos(); 497 | vec2 draw_pos{ context.window.position.x + cursor_pos.x + 14, context.window.position.y + cursor_pos.y }; 498 | 499 | const bool inlined = id_split[0].empty(); 500 | 501 | if (!inlined) 502 | { 503 | int text_wide, text_tall; 504 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 505 | 506 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y - 4 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 507 | 508 | draw_pos.y += text_tall; 509 | } 510 | 511 | const bool active = context.window.blocking == hash(id); 512 | 513 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width, control_height); hovered && key_pressed(VK_LBUTTON) && context.window.blocking == 0) 514 | { 515 | context.window.blocking = hash(id); 516 | } 517 | else if (active) 518 | { 519 | for (int i = 0; i < 256; i++) 520 | { 521 | if (key_pressed(i)) 522 | { 523 | if (keys_list[i] != "Error") 524 | value = i; 525 | 526 | context.window.blocking = 0; 527 | } 528 | } 529 | } 530 | 531 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 4, draw_pos.y + 4 }, zgui_render_type::zgui_text, global_colors.color_text, active ? "Press any key" : keys_list[value].data(), vec2{0,0}, font }); 532 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, active ? global_colors.control_active_or_clicked : global_colors.control_idle, "", { control_width, control_height } }); 533 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline,"", { control_width + 2, control_height + 2 } }); 534 | 535 | push_cursor_pos(vec2{ cursor_pos.x + control_width + global_config.item_spacing, cursor_pos.y }); 536 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + control_height / 2 + global_config.item_spacing + (inlined ? 0 : 12) }); 537 | 538 | push_font(font); 539 | } 540 | 541 | void zgui::text_input(const char* id, std::string& value, const int max_length, const int flags) noexcept 542 | { 543 | std::vector id_split = split_str(id, '#'); 544 | 545 | const int control_width = 80; 546 | const int control_height = 20; 547 | 548 | const int font = pop_font(); 549 | 550 | const vec2 cursor_pos = pop_cursor_pos(); 551 | vec2 draw_pos{ context.window.position.x + cursor_pos.x + 14, context.window.position.y + cursor_pos.y }; 552 | 553 | const bool inlined = id_split[0].empty(); 554 | 555 | if (!inlined) 556 | { 557 | int text_wide, text_tall; 558 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 559 | 560 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y - 4 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 561 | 562 | draw_pos.y += text_tall; 563 | } 564 | 565 | const bool active = context.window.blocking == hash(id); 566 | const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width, control_height); 567 | 568 | if (hovered && key_pressed(VK_LBUTTON) && !active) 569 | { 570 | context.window.blocking = hash(id); 571 | } 572 | else if (active) 573 | { 574 | if (key_pressed(VK_ESCAPE) || key_pressed(VK_RETURN) || (!hovered && key_pressed(VK_LBUTTON))) 575 | { 576 | context.window.blocking = 0; 577 | } 578 | else if (key_pressed(VK_BACK) && !value.empty()) 579 | { 580 | value.pop_back(); 581 | } 582 | else if (value.length() < max_length) 583 | { 584 | for (int i = 32; i <= 222; i++) 585 | { 586 | if ((i > 32 && i < 48) || (i > 57 && i < 65) || (i > 90 && i < 186)) 587 | continue; 588 | 589 | if (i > 57 && i <= 90) 590 | { 591 | if (key_pressed(i)) 592 | value += key_down(VK_SHIFT) ? static_cast(i) : static_cast(i + 32); 593 | } 594 | else 595 | { 596 | if (key_pressed(i)) 597 | { 598 | for (int j = 0; j < sizeof(special_characters); j++) 599 | { 600 | if (special_characters[j].vk == i) 601 | value += key_down(VK_SHIFT) ? special_characters[j].shift : special_characters[j].regular; 602 | } 603 | } 604 | } 605 | } 606 | } 607 | } 608 | 609 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 4, draw_pos.y + 4 }, zgui_render_type::zgui_text, global_colors.color_text, flags & zgui_text_input_flags_password ? std::string(value.length(), '*').c_str() : value.c_str(), vec2{0,0}, font }); 610 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, active ? global_colors.control_active_or_clicked : global_colors.control_idle, "", { control_width - 2, control_height - 2 } }); 611 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline,"", { control_width, control_height } }); 612 | 613 | push_cursor_pos(vec2{ cursor_pos.x + control_width + global_config.item_spacing, cursor_pos.y }); 614 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + control_height / 2 + global_config.item_spacing + (inlined ? 0 : 12) }); 615 | 616 | push_font(font); 617 | } 618 | 619 | void zgui::slider_int(const char* id, const int min, const int max, int& value) noexcept 620 | { 621 | std::vector id_split = split_str(id, '#'); 622 | 623 | const int font = pop_font(); 624 | 625 | const int control_width = 120; 626 | const int control_height = 10; 627 | 628 | const vec2 cursor_pos = pop_cursor_pos(); 629 | vec2 draw_pos{ context.window.position.x + cursor_pos.x + 14, context.window.position.y + cursor_pos.y }; 630 | 631 | const bool inlined = id_split[0].empty(); 632 | 633 | if (!inlined) 634 | { 635 | int text_wide, text_tall; 636 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 637 | 638 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y - 4 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 639 | 640 | draw_pos.y += text_tall; 641 | } 642 | 643 | if (context.window.blocking == 0 && mouse_in_region(draw_pos.x - (control_height - 2), draw_pos.y, 8, 10) && key_pressed(VK_LBUTTON)) 644 | value = std::clamp(value - 1, min, max); 645 | else if (context.window.blocking == 0 && mouse_in_region(draw_pos.x + control_width, draw_pos.y, 8, 10) && key_pressed(VK_LBUTTON)) 646 | value = std::clamp(value + 1, min, max); 647 | 648 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width, control_height); hovered && key_pressed(VK_LBUTTON) && context.window.blocking == 0) 649 | { 650 | context.window.blocking = hash(id); 651 | } 652 | else if (key_down(VK_LBUTTON) && context.window.blocking == hash(id)) 653 | { 654 | float value_unmapped = std::clamp(mouse_pos.x - draw_pos.x, 0.0f, static_cast(control_width)); 655 | int value_mapped = static_cast(value_unmapped / control_width * (max - min) + min); 656 | 657 | value = value_mapped; 658 | } 659 | else if (!key_down(VK_LBUTTON) && context.window.blocking == hash(id)) 660 | { 661 | context.window.blocking = 0; 662 | } 663 | 664 | const int dynamic_width = (static_cast(value) - min) / (max - min) * control_width - 2; 665 | 666 | int text_wide, text_tall; 667 | std::string value_str = std::to_string(value); 668 | functions.get_text_size(font, value_str.c_str(), text_wide, text_tall); 669 | 670 | int text_x = dynamic_width - text_wide; 671 | 672 | if (text_x < 0) 673 | text_x = 0; 674 | 675 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x - (control_height - 2), draw_pos.y - 2 }, zgui_render_type::zgui_text, global_colors.color_text_dimmer, "-", vec2{0,0}, font }); 676 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + (control_width + 4), draw_pos.y - 2 }, zgui_render_type::zgui_text, global_colors.color_text_dimmer, "+", vec2{0,0}, font }); 677 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + text_x, draw_pos.y }, zgui_render_type::zgui_text, global_colors.color_text, value_str, vec2{0,0}, font }); 678 | 679 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, global_colors.color_slider, "", { static_cast(dynamic_width), control_height - 2 } }); 680 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1}, zgui_render_type::zgui_filled_rect, global_colors.control_idle,"", { control_width - 2, control_height - 2 } }); 681 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline,"", { control_width, control_height } }); 682 | 683 | 684 | push_cursor_pos(vec2{ cursor_pos.x + control_width + 14 + global_config.item_spacing, cursor_pos.y }); 685 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + control_height / 2 + global_config.item_spacing + (inlined ? 0 : 12) }); 686 | 687 | push_font(font); 688 | } 689 | 690 | void zgui::slider_float(const char* id, const float min, const float max, float& value) noexcept 691 | { 692 | std::vector id_split = split_str(id, '#'); 693 | 694 | const int control_width = 120; 695 | const int control_height = 10; 696 | 697 | const int font = pop_font(); 698 | 699 | const vec2 cursor_pos = pop_cursor_pos(); 700 | vec2 draw_pos{ context.window.position.x + cursor_pos.x + 14, context.window.position.y + cursor_pos.y }; 701 | 702 | const bool inlined = id_split[0].empty(); 703 | 704 | if (!inlined) 705 | { 706 | int text_wide, text_tall; 707 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 708 | 709 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y - 4 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 710 | 711 | draw_pos.y += text_tall; 712 | } 713 | 714 | if (context.window.blocking == 0 && mouse_in_region(draw_pos.x - (control_height - 2), draw_pos.y, 8, 10) && key_pressed(VK_LBUTTON)) 715 | value = std::clamp(value - 1, min, max); 716 | else if (context.window.blocking == 0 && mouse_in_region(draw_pos.x + control_width, draw_pos.y, 8, 10) && key_pressed(VK_LBUTTON)) 717 | value = std::clamp(value + 1, min, max); 718 | 719 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width, control_height); hovered && key_pressed(VK_LBUTTON) && context.window.blocking == 0) 720 | { 721 | context.window.blocking = hash(id); 722 | } 723 | else if (key_down(VK_LBUTTON) && context.window.blocking == hash(id)) 724 | { 725 | float value_unmapped = std::clamp(mouse_pos.x - draw_pos.x, 0.0f, static_cast(control_width)); 726 | float value_mapped = static_cast((value_unmapped / static_cast(control_width)) * (max - min) + min); 727 | 728 | value = value_mapped; 729 | } 730 | else if (!key_down(VK_LBUTTON) && context.window.blocking == hash(id)) 731 | { 732 | context.window.blocking = 0; 733 | } 734 | 735 | const float dynamic_width = (static_cast(value) - min) / (max - min) * control_width - 2; 736 | 737 | int text_wide, text_tall; 738 | std::stringstream ss; 739 | ss << std::fixed << std::setprecision(2) << value; 740 | std::string value_str = ss.str(); 741 | functions.get_text_size(font, value_str.c_str(), text_wide, text_tall); 742 | 743 | int text_x = dynamic_width - text_wide; 744 | 745 | if (text_x < 0) 746 | text_x = 0; 747 | 748 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x - (control_height - 2), draw_pos.y - 2 }, zgui_render_type::zgui_text, global_colors.color_text_dimmer, "-", vec2{0,0}, font }); 749 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + (control_width + 4), draw_pos.y - 2 }, zgui_render_type::zgui_text, global_colors.color_text_dimmer, "+", vec2{0,0}, font }); 750 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + text_x, draw_pos.y }, zgui_render_type::zgui_text, global_colors.color_text, value_str, vec2{0,0}, font }); 751 | 752 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, global_colors.color_slider, "", { dynamic_width, control_height - 2 } }); 753 | context.window.render.emplace_back(zgui_control_render_t{ {draw_pos.x + 1, draw_pos.y + 1}, zgui_render_type::zgui_filled_rect, global_colors.control_idle,"", { control_width - 2, control_height - 2 } }); 754 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline,"", { control_width, control_height } }); 755 | 756 | 757 | push_cursor_pos(vec2{ cursor_pos.x + control_width + 14 + global_config.item_spacing, cursor_pos.y }); 758 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + control_height / 2 + global_config.item_spacing + (inlined ? 0 : 12) }); 759 | 760 | push_font(font); 761 | } 762 | 763 | void zgui::combobox(const char* id, std::vectoritems, int& value) noexcept 764 | { 765 | std::vector id_split = split_str(id, '#'); 766 | 767 | const int control_width = 70; 768 | const int control_height = 20; 769 | 770 | value = std::clamp(value, 0, static_cast(items.size()) - 1); 771 | 772 | const int font = pop_font(); 773 | 774 | const vec2 cursor_pos = pop_cursor_pos(); 775 | vec2 draw_pos{ context.window.position.x + cursor_pos.x + 14, context.window.position.y + cursor_pos.y }; 776 | 777 | const bool inlined = id_split[0].empty(); 778 | 779 | if (!inlined) 780 | { 781 | int text_wide, text_tall; 782 | 783 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 784 | 785 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y - 4 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 786 | 787 | draw_pos.y += text_tall; 788 | } 789 | 790 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + control_width - 10, draw_pos.y + 4 }, zgui_render_type::zgui_text, global_colors.color_text, "+", vec2{0,0}, font }); 791 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 4, draw_pos.y + 4 }, zgui_render_type::zgui_text, global_colors.color_text, items.at(value), vec2{0,0}, font }); 792 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, global_colors.control_idle, "", { control_width - 2, control_height - 2 } }); 793 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline, "", { control_width, control_height } }); 794 | 795 | push_cursor_pos(vec2{ cursor_pos.x + control_width + global_config.item_spacing, cursor_pos.y }); 796 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + control_height / 2 + global_config.item_spacing + (inlined ? 0 : 12) }); 797 | 798 | 799 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width, control_height); hovered && key_pressed(VK_LBUTTON) && context.window.blocking == 0) 800 | { 801 | context.window.blocking = hash(id); 802 | } 803 | else if (context.window.blocking == hash(id)) 804 | { 805 | for (int i = 1; i <= items.size(); i++) 806 | { 807 | bool hovered = mouse_in_region(draw_pos.x, draw_pos.y + (control_height - 1) * i, control_width, control_height); 808 | 809 | if (hovered && key_pressed(VK_LBUTTON)) 810 | { 811 | context.window.blocking = 0; 812 | value = i - 1; 813 | } 814 | 815 | if (!hovered && key_pressed(VK_LBUTTON)) 816 | { 817 | context.window.blocking = 0; 818 | } 819 | 820 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 4, draw_pos.y + (control_height - 1) * i + 4 }, zgui_render_type::zgui_text, global_colors.color_text, items.at(i - 1), vec2{0,0}, font }); 821 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + (19 * i) + 1 }, zgui_render_type::zgui_filled_rect, hovered ? global_colors.color_combo_bg : global_colors.control_idle, "", { control_width - 2, control_height - 2 } }); 822 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y + 19 * i }, zgui_render_type::zgui_filled_rect, global_colors.control_outline, "", { control_width, control_height } }); 823 | } 824 | } 825 | 826 | push_font(font); 827 | } 828 | 829 | void zgui::multi_combobox(const char* id, std::vector items) noexcept 830 | { 831 | std::vector id_split = split_str(id, '#'); 832 | 833 | const int control_width = 100; 834 | const int control_height = 20; 835 | 836 | const int font = pop_font(); 837 | 838 | const vec2 cursor_pos = pop_cursor_pos(); 839 | vec2 draw_pos{ context.window.position.x + cursor_pos.x + 14, context.window.position.y + cursor_pos.y }; 840 | 841 | const bool inlined = id_split[0].empty(); 842 | 843 | if (!inlined) 844 | { 845 | int text_wide, text_tall; 846 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 847 | 848 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y - 4 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 849 | 850 | draw_pos.y += text_tall; 851 | } 852 | 853 | std::string value_str; 854 | int text_wide, text_tall; 855 | 856 | for (auto& item_t : items) { 857 | if (*item_t.value) { 858 | if (value_str.length() > 0) 859 | value_str += ", "; 860 | 861 | value_str += item_t.name; 862 | } 863 | } 864 | 865 | functions.get_text_size(font, value_str.c_str(), text_wide, text_tall); 866 | if (text_wide > control_width - 18) 867 | { 868 | value_str.resize(control_width / 10); 869 | value_str += " ..."; 870 | } 871 | if (!value_str.length()) 872 | value_str += "None"; 873 | 874 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + control_width - 10, draw_pos.y + 4 }, zgui_render_type::zgui_text, global_colors.color_text, "+", vec2{0,0}, font }); 875 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 4, draw_pos.y + 4 }, zgui_render_type::zgui_text, global_colors.color_text, value_str, vec2{0,0}, font }); 876 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, global_colors.control_idle, "", { control_width - 2, control_height - 2 } }); 877 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline, "", { control_width, control_height } }); 878 | 879 | push_cursor_pos(vec2{ cursor_pos.x + control_width + global_config.item_spacing, cursor_pos.y }); 880 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + control_height / 2 + global_config.item_spacing + (inlined ? 0 : 12) }); 881 | 882 | 883 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width, control_height); hovered && key_pressed(VK_LBUTTON) && context.window.blocking == 0) 884 | { 885 | context.window.blocking = hash(id); 886 | } 887 | else if (context.window.blocking == hash(id)) 888 | { 889 | for (int i = 1; i <= items.size(); i++) 890 | { 891 | bool hovered = mouse_in_region(draw_pos.x, draw_pos.y + (control_height - 1) * i, control_width, control_height); 892 | 893 | if (hovered && key_pressed(VK_LBUTTON)) 894 | { 895 | context.window.blocking = 0; 896 | *items[i - 1].value = !*items[i - 1].value; 897 | } 898 | if (!hovered && key_pressed(VK_LBUTTON)) 899 | { 900 | context.window.blocking = 0; 901 | } 902 | 903 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 4, draw_pos.y + (control_height - 1) * i + 4 }, zgui_render_type::zgui_text, global_colors.color_text, items[i - 1].name.data(), vec2{0,0}, font }); 904 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + (19 * i) + 1 }, zgui_render_type::zgui_filled_rect, hovered ? global_colors.color_combo_bg : global_colors.control_idle, "", { control_width - 2, control_height - 2 } }); 905 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y + 19 * i }, zgui_render_type::zgui_filled_rect, global_colors.control_outline, "", { control_width, control_height } }); 906 | } 907 | } 908 | 909 | push_font(font); 910 | } 911 | 912 | void zgui::listbox(const char* id, std::vector items) noexcept 913 | { 914 | std::vector id_split = split_str(id, '#'); 915 | 916 | const int control_width = 100; 917 | const int control_height = 20; 918 | 919 | const int font = pop_font(); 920 | 921 | const vec2 cursor_pos = pop_cursor_pos(); 922 | vec2 draw_pos{ context.window.position.x + cursor_pos.x, context.window.position.y + cursor_pos.y }; 923 | 924 | const bool inlined = id_split[0].empty(); 925 | 926 | if (!inlined) 927 | { 928 | int text_wide, text_tall; 929 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 930 | 931 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y - 4 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 932 | 933 | draw_pos.y += text_tall; 934 | } 935 | 936 | for (int i = 1; i <= items.size(); i++) 937 | { 938 | const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y + (control_height - 1) * (i - 1), control_width, control_height); 939 | 940 | if (hovered && key_pressed(VK_LBUTTON)) 941 | { 942 | context.window.blocking = 0; 943 | *items[i - 1].value = !*items[i - 1].value; 944 | } 945 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 4, draw_pos.y + (control_height - 1) * (i - 1) + 4}, zgui_render_type::zgui_text, *items[i - 1].value || hovered ? global_colors.control_active_or_clicked : global_colors.color_text, items[i - 1].name.data(), vec2{0,0}, font }); 946 | } 947 | 948 | 949 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, global_colors.control_idle, "", { control_width - 2, static_cast(control_height * items.size() - 2) } }); 950 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline, "", { control_width, static_cast(control_height * items.size()) } }); 951 | 952 | push_cursor_pos(vec2{ cursor_pos.x + control_width + global_config.item_spacing, cursor_pos.y }); 953 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + control_height / 2 + global_config.item_spacing + (inlined ? 0 : 12) + control_height * (items.size() - 1) }); 954 | 955 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width, control_height); hovered && key_pressed(VK_LBUTTON) && context.window.blocking == 0) 956 | { 957 | context.window.blocking = hash(id); 958 | } 959 | 960 | push_font(font); 961 | } 962 | 963 | bool zgui::clickable_text(const char* id) noexcept 964 | { 965 | std::vector id_split = split_str(id, '#'); 966 | 967 | const int font = pop_font(); 968 | 969 | const vec2 cursor_pos = pop_cursor_pos(); 970 | const vec2 draw_pos{ context.window.position.x + cursor_pos.x, context.window.position.y + cursor_pos.y }; 971 | 972 | int text_width, text_tall; 973 | functions.get_text_size(font, id_split[0].c_str(), text_width, text_tall); 974 | 975 | const bool active = context.window.blocking == hash(id); 976 | const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, text_width, text_tall); 977 | 978 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y}, zgui_render_type::zgui_text, (hovered || context.window.blocking == hash(id)) ? global_colors.control_active_or_clicked : global_colors.color_text, id_split[0], vec2{0,0}, font }); 979 | 980 | push_cursor_pos(vec2{ cursor_pos.x + text_width + global_config.item_spacing, cursor_pos.y }); 981 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + text_tall / 2 + global_config.item_spacing }); 982 | 983 | bool result = false; 984 | 985 | if (!active && hovered && key_pressed(VK_LBUTTON)) 986 | { 987 | context.window.blocking = hash(id); 988 | } 989 | else if (active && !key_down(VK_LBUTTON)) 990 | { 991 | context.window.blocking = 0; 992 | result = hovered; 993 | } 994 | 995 | push_font(font); 996 | 997 | return result; 998 | } 999 | 1000 | void zgui::text(const char* text) noexcept 1001 | { 1002 | const int font = pop_font(); 1003 | 1004 | const vec2 cursor_pos = pop_cursor_pos(); 1005 | const vec2 draw_pos{ context.window.position.x + cursor_pos.x, context.window.position.y + cursor_pos.y }; 1006 | 1007 | int text_width, text_tall; 1008 | functions.get_text_size(font, text, text_width, text_tall); 1009 | 1010 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_text, global_colors.color_text, text, vec2{0,0}, font }); 1011 | 1012 | push_cursor_pos(vec2{ cursor_pos.x + text_width + global_config.item_spacing, cursor_pos.y }); 1013 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + text_tall / 2 + global_config.item_spacing }); 1014 | 1015 | push_font(font); 1016 | } 1017 | 1018 | void zgui::dummy() noexcept 1019 | { 1020 | const vec2 cursor_pos = pop_cursor_pos(); 1021 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + global_config.item_spacing }); 1022 | } 1023 | 1024 | void zgui::next_column(const int pusher_x, const int pusher_y) noexcept 1025 | { 1026 | const vec2 cursor_pos = pop_cursor_pos(); 1027 | vec2 new_cursor_pos{ cursor_pos.x + pusher_x, global_config.base_pos.y + pusher_y }; 1028 | 1029 | if (context.window.next_cursor_pos.y != 0) 1030 | new_cursor_pos.y += 14; 1031 | 1032 | push_cursor_pos(new_cursor_pos); 1033 | } 1034 | 1035 | void zgui::same_line(const float x_axis) noexcept 1036 | { 1037 | const vec2 cursor_pos = pop_cursor_pos(); 1038 | 1039 | if (x_axis != -1) 1040 | push_cursor_pos(vec2{ global_config.base_pos.x + x_axis, cursor_pos.x }); 1041 | } 1042 | 1043 | void zgui::backup_line() noexcept 1044 | { 1045 | const vec2 cursor_pos = pop_cursor_pos(); 1046 | 1047 | push_cursor_pos(vec2{ context.window.next_cursor_pos.x, cursor_pos.y }); 1048 | } -------------------------------------------------------------------------------- /core/menu/zgui/menu.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../../dependencies/utilities/render.hpp" 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | #define ZGUI_API __declspec(dllexport) 15 | 16 | // zgui by zxvnme (https://github.com/zxvnme) and all the community contributors 17 | #define ZGUI_VER "1.4.8" // the number after second dot is snapshot version. 18 | /* =============================[general]=============================== 19 | * 20 | * zgui is an simple framework created to help people with GUI rendering during their game hacking (but not only) journey. 21 | * here is glance zgui feature presentation: 22 | * - easy to use immediate mode rendering (all you need is to include zgui header and source files to your project). 23 | * - simple and aesthetic design. 24 | * - extensible code. 25 | * ... and function documentation in section below: 26 | * 27 | * ================================[pseudo documentation]===================================== 28 | * 29 | * get_functions() 30 | * -- function that is used to get our wrapped ones. 31 | * 32 | * begin_window(std::string_view title, vec2 default_size, unsigned long font, int flags); 33 | * end_window(); 34 | * -- functions used to create and end window. 35 | * 36 | * begin_groupbox(std::string_view name, vec2 size); 37 | * end_groupbox(); 38 | * -- functions uses to create our groupbox with desired size and end it. 39 | * 40 | * slider_int(std::string_view id, int min, int max, int* value); 41 | * slider_float(std::string_view id, float min, float max, float* value); 42 | * -- functions used to create sliders with value type described in function name. 43 | * 44 | * combobox(std::string_view id, std::vector items, int* value); 45 | * multi_combobox(std::string id, std::vector items) 46 | * -- functions used for creating combo boxes. 47 | * 48 | * checkbox(std::string_view id, bool* value); 49 | * -- function that creates checkbox. 50 | * 51 | * toggle_button(std::string_view id, vec2 size, bool* value); 52 | * -- function that creates toggle button. 53 | * 54 | * button(std::string_view id, vec2 size); 55 | * -- function that creates button. 56 | * 57 | * key_bind(std::string_view id, int* value); 58 | * -- function that creates key binder. 59 | * 60 | * text_input(std::string_view id, std::string* value, int max_length = 18); 61 | * -- functions that creates text input box. 62 | * 63 | * clickable_text(std::string_view text); 64 | * -- function that creates text that can be clicked and eventually perform an action. 65 | * 66 | * text(std::string_view text); 67 | * -- function that creates text. 68 | * 69 | * dummy(); 70 | * -- function that pushes cursor_pos.x to make empty space between our controls. 71 | * 72 | * same_line(float x_axis = -1); 73 | * backup_line(); 74 | * -- functions used for inline controls positioning. NOTE: there can be only one item between these two functions called. 75 | * 76 | * ================================[hashing controls names]================================ 77 | * 78 | * the '#' thing in control name is separator that splits our name to two elements; actual displayed name & the one that is "hidden" 79 | * 80 | * bad example: 81 | * zgui::button("button", { 120, 30 }); 82 | * zgui::button("button", { 120, 30 }); 83 | * 84 | * code above won't work correctly because of same name provided. (known consequence is clicking 2 buttons at once) 85 | * 86 | * good example: 87 | * zgui::button("button#button_1", { 120, 30 }); 88 | * zgui::button("button#button_2", { 120, 30 }); 89 | * 90 | * and now, code above works fine because unique id (used in window input blocking) is provided after '#' 91 | * 92 | * ==================================[input handling]====================================== 93 | * 94 | * IMPORTANT NOTE: poll_input(); HAS to be called before everything. Otherwise zgui will throw an exception or won't work properly. 95 | * 96 | * poll_input("type_your_window_name") is function used to start reading input from window we specify in function parameter (string_view) 97 | * 98 | * bad example: 99 | * zgui::poll_input(""); 100 | * ... not calling this before whole zgui :) 101 | * 102 | * code above won't work correctly because window name string_view size is equal to 0. 103 | * 104 | * good example: 105 | * zgui::poll_input("zgui directx9 example"); 106 | * zgui::poll_input("Minecraft 1.8.9"); 107 | * 108 | * and now, code above will work fine if your window titles are "zgui directx9 example" or "Minecraft 1.8.9" 109 | * 110 | * ================================================================================================ 111 | * 112 | * ================================================================================================ 113 | */ 114 | 115 | // For examples and function descriptions see zgui header file. 116 | namespace zgui { 117 | 118 | // Multi selectable item. 119 | struct multi_select_item { std::string_view name; bool* value; }; 120 | // Two dimensional vector. 121 | struct vec2 { float x, y; }; 122 | // Color with 4 paremeters; red, green, blue and alpha. 123 | struct color { int r, g, b, a; }; 124 | 125 | /// "Proxy" functions definitions. 126 | using line_t = std::add_pointer_t; 127 | using rect_t = std::add_pointer_t; 128 | using filled_rect_t = std::add_pointer_t; 129 | using text_t = std::add_pointer_t; 130 | using get_text_size_t = std::add_pointer_t; 131 | using get_frametime = std::add_pointer_t; 132 | /// 133 | 134 | // "Proxy" functions stuff... 135 | struct functions_t 136 | { 137 | line_t draw_line; 138 | rect_t draw_rect; 139 | filled_rect_t draw_filled_rect; 140 | text_t draw_text; 141 | get_text_size_t get_text_size; 142 | get_frametime get_frametime; 143 | }; 144 | extern functions_t functions; 145 | 146 | // Flags for window appereance and its behavior. 147 | // ex: (zgui_window_flags_no_border | zgui_window_flags_no_titlebar) will cause window to be borderless and without title bar. 148 | enum zgui_window_flags 149 | { 150 | zgui_window_flags_none = 0, 151 | zgui_window_flags_no_border = 1 << 0, 152 | zgui_window_flags_no_titlebar = 1 << 1, 153 | zgui_window_flags_no_ontoggle_animation = 1 << 2, 154 | zgui_window_flags_no_move = 1 << 3, 155 | zgui_window_flags_always_open = 1 << 4, 156 | }; 157 | 158 | // Flags for text input appereance. 159 | // ex: (zgui_text_input_flags_password) will convert text input (ex: "abcdef") to "******". 160 | enum zgui_text_input_flags 161 | { 162 | zgui_text_input_flags_none = 0, 163 | zgui_text_input_flags_password = 1 << 0 164 | }; 165 | 166 | // Flags for groupboxes appereance. 167 | // ex: (zgui_groupbox_flags_title_centered) will center align title of groupbox. 168 | enum zgui_groupbox_flags 169 | { 170 | zgui_groupbox_flags_none = 0, 171 | zgui_groupbox_flags_title_centered = 1 << 0, 172 | }; 173 | 174 | enum class zgui_render_type 175 | { 176 | zgui_line = 1, 177 | zgui_rect, 178 | zgui_filled_rect, 179 | zgui_text 180 | }; 181 | 182 | struct zgui_control_render_t 183 | { 184 | vec2 draw_position; 185 | zgui_render_type render_type; 186 | color color; 187 | std::string text; 188 | vec2 size; 189 | int font = 0; 190 | }; 191 | 192 | struct gui_window_context_t 193 | { 194 | uint32_t blocking; 195 | std::stack cursor_pos; 196 | std::stack fonts; 197 | std::vector render; 198 | vec2 position, size; 199 | vec2 next_cursor_pos; 200 | bool dragging; 201 | bool opened; 202 | int alpha; 203 | }; 204 | 205 | // Start Input loop 206 | ZGUI_API void poll_input(std::string_view window_name); 207 | ZGUI_API void poll_input(HWND hwnd); 208 | 209 | // Push cursor position to the stack defined in window context 210 | ZGUI_API void push_cursor_pos(vec2 pos) noexcept; 211 | // Pop cursor position from the stack defined in window context 212 | ZGUI_API vec2 pop_cursor_pos() noexcept; 213 | 214 | // Push font to the stack defined in window context 215 | ZGUI_API void push_font(unsigned long font) noexcept; 216 | // Pop font from the stack defined in window context 217 | ZGUI_API unsigned long pop_font(); 218 | 219 | ZGUI_API bool begin_window(std::string_view title, vec2 default_size, unsigned long font, int flags = 0); 220 | ZGUI_API void end_window() noexcept; 221 | 222 | ZGUI_API void begin_groupbox(std::string_view title, vec2 size, int flags = 0) noexcept; 223 | ZGUI_API void end_groupbox() noexcept; 224 | 225 | ZGUI_API void checkbox(const char* id, bool& value) noexcept; 226 | 227 | ZGUI_API void toggle_button(const char* id, vec2 size, bool& value) noexcept; 228 | 229 | ZGUI_API bool button(const char* id, vec2 size) noexcept; 230 | 231 | ZGUI_API void key_bind(const char* id, int& value) noexcept; 232 | 233 | ZGUI_API void text_input(const char* id, std::string& value, int max_length = 16, int flags = 0) noexcept; 234 | 235 | ZGUI_API void slider_int(const char* id, int min, int max, int& value) noexcept; 236 | 237 | ZGUI_API void slider_float(const char* id, float min, float max, float& value) noexcept; 238 | 239 | ZGUI_API void combobox(const char*, std::vector items, int& value) noexcept; 240 | 241 | ZGUI_API void multi_combobox(const char* id, std::vector items) noexcept; 242 | 243 | ZGUI_API void listbox(const char* id, std::vector items) noexcept; 244 | 245 | ZGUI_API bool clickable_text(const char* id) noexcept; 246 | 247 | ZGUI_API void text(const char* text) noexcept; 248 | 249 | ZGUI_API void dummy() noexcept; 250 | 251 | ZGUI_API void next_column(int pusher_x = 174, int pusher_y = 14) noexcept; 252 | 253 | ZGUI_API void same_line(float x_axis = -1) noexcept; 254 | 255 | ZGUI_API void backup_line() noexcept; 256 | } -------------------------------------------------------------------------------- /core/menu/zgui/zgui.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "zgui.hpp" 8 | // zgui by zxvnme (https://github.com/zxvnme) 9 | // heres defines that are designed to be modified by your preferences. 10 | // see zgui.hh for complete documentation. 11 | // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 12 | 13 | // Color definition. Can be changed at any time just simply by editing this struct. 14 | static struct { 15 | color window_border_inner_fill{ 60, 60, 60, 255 }; 16 | color window_border_fill{ 40, 40, 40, 255 }; 17 | color window_border_color{ 10, 10, 10, 255 }; 18 | color window_background{ 40, 40, 40, 255 }; 19 | 20 | color control_outline{ 23, 23, 30, 255 }; 21 | color control_active_or_clicked{ 108, 92, 231, 255 }; 22 | color control_idle{ 62, 62, 72, 255 }; 23 | 24 | color color_groupbox_bg{ 50, 50, 50, 255 }; 25 | color color_text{ 203, 203, 203, 255 }; 26 | color color_text_dimmer{ 99, 110, 114, 255 }; 27 | color color_slider{ 108, 92, 231, 255 }; 28 | color color_combo_bg{ 108, 92, 231, 255 }; 29 | } global_colors; 30 | 31 | static struct { 32 | // Base position of first drawn control (px). DO NOT change if its necessary 33 | zgui::vec2 base_pos{ 16, 23 }; 34 | // Spacing between items (px) 35 | int item_spacing = 16; 36 | // Key that will toggle menu visibility unless zgui_window_flags_always_open is set 37 | int menu_toggle_key = VK_INSERT; 38 | } global_config; 39 | 40 | // Window definitions. 41 | static struct gui_context_t { 42 | zgui::gui_window_context_t window; 43 | } context; 44 | 45 | // "Proxy" functions stuff... 46 | zgui::functions_t zgui::functions; 47 | 48 | // Globals 49 | static zgui::vec2 mouse_pos; 50 | static zgui::vec2 previous_mouse_pos; 51 | 52 | // Input handling stuff 53 | static bool key_state[256]; 54 | static bool prev_key_state[256]; 55 | 56 | // Check for input polling. 57 | static bool input_loop_started = false; 58 | 59 | // Function for starting our input loop. 60 | void zgui::poll_input(std::string_view window_name) 61 | { 62 | if (window_name.empty()) 63 | throw std::exception("No window from where input should be read from specified in function parameter."); 64 | 65 | for (int i = 0; i < 256; i++) { 66 | prev_key_state[i] = key_state[i]; 67 | key_state[i] = GetAsyncKeyState(i); 68 | } 69 | 70 | POINT p_mouse_pos; 71 | GetCursorPos(&p_mouse_pos); 72 | ScreenToClient(FindWindow(nullptr, window_name.data()), &p_mouse_pos); 73 | previous_mouse_pos = mouse_pos; 74 | mouse_pos = vec2{ static_cast(p_mouse_pos.x), static_cast(p_mouse_pos.y) }; 75 | 76 | if (!input_loop_started) 77 | input_loop_started = true; 78 | } 79 | 80 | // Function for starting our input loop. 81 | void zgui::poll_input(HWND hwnd) 82 | { 83 | if (!hwnd) 84 | throw std::exception("No window from where input should be read from specified in function parameter."); 85 | 86 | for (int i = 0; i < 256; i++) { 87 | prev_key_state[i] = key_state[i]; 88 | key_state[i] = GetAsyncKeyState(i); 89 | } 90 | 91 | POINT p_mouse_pos; 92 | GetCursorPos(&p_mouse_pos); 93 | ScreenToClient(hwnd, &p_mouse_pos); 94 | previous_mouse_pos = mouse_pos; 95 | mouse_pos = vec2{ static_cast(p_mouse_pos.x), static_cast(p_mouse_pos.y) }; 96 | 97 | if (!input_loop_started) 98 | input_loop_started = true; 99 | } 100 | 101 | // Input utilities. 102 | constexpr bool key_pressed(const int key) noexcept 103 | { 104 | return key_state[key] && !prev_key_state[key]; 105 | } 106 | 107 | constexpr bool key_down(const int key) noexcept 108 | { 109 | return key_state[key]; 110 | } 111 | 112 | constexpr bool key_released(const int key) noexcept 113 | { 114 | return !key_state[key] && prev_key_state[key]; 115 | } 116 | 117 | // Check if mouse is hovered over specified region. 118 | bool mouse_in_region(const int x, const int y, const int w, const int h) noexcept 119 | { 120 | return mouse_pos.x > x && mouse_pos.y > y && mouse_pos.x < w + x && mouse_pos.y < h + y; 121 | } 122 | 123 | // Push cursor position to the stack 124 | void zgui::push_cursor_pos(const vec2 pos) noexcept 125 | { 126 | context.window.cursor_pos.push(pos); 127 | } 128 | 129 | // Pop cursor position from the stack 130 | zgui::vec2 zgui::pop_cursor_pos() noexcept 131 | { 132 | const vec2 pos = context.window.cursor_pos.top(); 133 | context.window.cursor_pos.pop(); 134 | return pos; 135 | } 136 | 137 | void zgui::push_font(const unsigned long font) noexcept 138 | { 139 | context.window.fonts.push(font); 140 | } 141 | 142 | unsigned long zgui::pop_font() 143 | { 144 | const unsigned long font = context.window.fonts.top(); 145 | context.window.fonts.pop(); 146 | return font; 147 | } 148 | 149 | // Hashing util 150 | std::vector split_str(const char* str, const char separator) noexcept 151 | { 152 | std::vector output; 153 | std::string substring; 154 | std::istringstream stream{ str }; 155 | 156 | while (std::getline(stream, substring, separator)) 157 | output.push_back(substring); 158 | 159 | return output; 160 | } 161 | 162 | static constexpr uint32_t hash(const char* str, const uint32_t value = 0x811c9dc5) noexcept 163 | { 164 | return *str ? hash(str + 1, (value ^ *str) * 0x1000193ull) : value; 165 | } 166 | 167 | // Names for each of VKs 168 | constexpr std::string_view keys_list[]{ 169 | "Error", "Left Mouse", "Right Mouse", "Break", "Middle Mouse", "Mouse 4", "Mouse 5", 170 | "Error", "Backspace", "TAB", "Error", "Error", "Error", "ENTER", "Error", "Error", "SHIFT", 171 | "CTRL", "ALT","PAUSE","CAPS LOCK", "Error", "Error", "Error", "Error", "Error", "Error", 172 | "Error", "Error", "Error", "Error", "Error", "SPACEBAR","PG UP", "PG DOWN", "END", "HOME", "Left", 173 | "Up", "Right", "Down", "Error", "Print", "Error", "Print Screen", "Insert","Delete", "Error", "0", "1", 174 | "2", "3", "4", "5", "6", "7", "8", "9", "Error", "Error", "Error", "Error", "Error", "Error", 175 | "Error", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", 176 | "V", "W", "X","Y", "Z", "Left Windows", "Right Windows", "Error", "Error", "Error", "NUM 0", "NUM 1", 177 | "NUM 2", "NUM 3", "NUM 4", "NUM 5", "NUM 6","NUM 7", "NUM 8", "NUM 9", "*", "+", "_", "-", ".", "/", "F1", "F2", "F3", 178 | "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12","F13", "F14", "F15", "F16", "F17", "F18", "F19", "F20", "F21", 179 | "F22", "F23", "F24", "Error", "Error", "Error", "Error", "Error","Error", "Error", "Error", 180 | "NUM LOCK", "SCROLL LOCK", "Error", "Error", "Error", "Error", "Error", "Error", "Error", 181 | "Error", "Error","Error", "Error", "Error", "Error", "Error", "LSHIFT", "RSHIFT", "LCONTROL", 182 | "RCONTROL", "LMENU", "RMENU", "Error","Error", "Error","Error", "Error", "Error", "Error", 183 | "Error", "Error", "Error", "Next Track", "Previous Track", "Stop", "Play/Pause", "Error", "Error", 184 | "Error", "Error", "Error", "Error", ";", "+", ",", "-", ".", "/?", "~", "Error", "Error", 185 | "Error", "Error","Error", "Error", "Error", "Error", "Error", "Error", "Error", 186 | "Error", "Error", "Error", "Error", "Error", "Error", "Error", "Error","Error", 187 | "Error", "Error", "Error", "Error", "Error", "Error", "[{", "\\|", "}]", "'\"", "Error", 188 | "Error", "Error", "Error","Error", "Error", "Error", "Error", "Error", "Error", 189 | "Error", "Error", "Error", "Error", "Error", "Error", "Error", "Error", "Error", 190 | "Error", "Error", "Error", "Error", "Error", "Error", "Error", "Error", "Error", 191 | "Error", "Error" 192 | }; 193 | 194 | struct key_code_info { 195 | int vk; 196 | 197 | char regular; 198 | char shift; 199 | }; 200 | 201 | static key_code_info special_characters[22] = { 202 | { 48, '0', ')' }, 203 | { 49, '1', '!' }, 204 | { 50, '2', '@' }, 205 | { 51, '3', '#' }, 206 | { 52, '4', '$' }, 207 | { 53, '5', '%' }, 208 | { 54, '6', '^' }, 209 | { 55, '7', '&' }, 210 | { 56, '8', '*' }, 211 | { 57, '9', '(' }, 212 | { 32, ' ', ' ' }, 213 | { 192, '`', '~' }, 214 | { 189, '-', '_' }, 215 | { 187, '=', '+' }, 216 | { 219, '[', '{' }, 217 | { 220, '\\', '|' }, 218 | { 221, ']', '}' }, 219 | { 186, ';', ':' }, 220 | { 222, '\'', '"' }, 221 | { 188, ',', '<' }, 222 | { 190, '.', '>' }, 223 | { 191, '/', '?' } 224 | }; 225 | 226 | bool zgui::begin_window(std::string_view title, const vec2 default_size, const unsigned long font, const int flags) 227 | { 228 | if (!input_loop_started) 229 | throw std::exception("Input loop didnt start or didnt start properly.");; 230 | 231 | if (!(flags & zgui_window_flags_always_open)) 232 | { 233 | if (key_pressed(global_config.menu_toggle_key)) 234 | context.window.opened = !context.window.opened; 235 | } 236 | else 237 | context.window.opened = true; 238 | 239 | if (const int prev_alpha = context.window.alpha; !(flags & zgui_window_flags_no_ontoggle_animation)) 240 | { 241 | const int fade_factor = static_cast(1.0f / 0.15f * functions.get_frametime() * 255); 242 | context.window.alpha = std::clamp(context.window.alpha + (context.window.opened ? fade_factor : -fade_factor), 0, 255); 243 | 244 | if (context.window.alpha != prev_alpha) 245 | { 246 | global_colors.window_border_inner_fill.a = context.window.alpha; 247 | global_colors.window_border_fill.a = context.window.alpha; 248 | global_colors.window_border_color.a = context.window.alpha; 249 | global_colors.window_background.a = context.window.alpha; 250 | 251 | global_colors.control_outline.a = context.window.alpha; 252 | global_colors.control_active_or_clicked.a = context.window.alpha; 253 | global_colors.control_idle.a = context.window.alpha; 254 | 255 | global_colors.color_groupbox_bg.a = context.window.alpha; 256 | global_colors.color_text.a = context.window.alpha; 257 | global_colors.color_text_dimmer.a = context.window.alpha; 258 | global_colors.color_slider.a = context.window.alpha; 259 | } 260 | } 261 | 262 | if (context.window.opened || context.window.alpha > 0) 263 | { 264 | if (!(flags & zgui_window_flags_no_move)) 265 | { 266 | if ((flags & zgui_window_flags_no_border ? mouse_in_region(context.window.position.x + 9, context.window.position.y + 14, context.window.size.x - 18, 14) 267 | : mouse_in_region(context.window.position.x - 6, context.window.position.y - 10, context.window.size.x + 12, 16)) 268 | && key_pressed(VK_LBUTTON) && !context.window.dragging) 269 | { 270 | context.window.dragging = true; 271 | } 272 | else if (key_down(VK_LBUTTON) && context.window.dragging) 273 | { 274 | const vec2 mouse_delta{ mouse_pos.x - previous_mouse_pos.x, mouse_pos.y - previous_mouse_pos.y }; 275 | const vec2 new_position{ context.window.position.x + mouse_delta.x, context.window.position.y + mouse_delta.y }; 276 | 277 | context.window.position = new_position; 278 | } 279 | else if (!key_down(VK_LBUTTON) && context.window.dragging) 280 | { 281 | context.window.dragging = false; 282 | } 283 | } 284 | 285 | if (context.window.size.x < 1 && context.window.size.y < 1) 286 | context.window.size = default_size; 287 | 288 | if (!(flags & zgui_window_flags_no_border)) 289 | { 290 | functions.draw_filled_rect(context.window.position.x - 6, context.window.position.y - 10, context.window.size.x + 12, context.window.size.y + 16, global_colors.window_border_inner_fill); 291 | functions.draw_filled_rect(context.window.position.x - 5, context.window.position.y - 9, context.window.size.x + 10, context.window.size.y + 14, global_colors.window_border_color); 292 | functions.draw_filled_rect(context.window.position.x - 4, context.window.position.y - 8, context.window.size.x + 8, context.window.size.y + 12, global_colors.window_border_fill); 293 | functions.draw_filled_rect(context.window.position.x, context.window.position.y + 7, context.window.size.x, context.window.size.y - 7, global_colors.window_border_color); 294 | functions.draw_filled_rect(context.window.position.x + 1, context.window.position.y + 8, context.window.size.x - 2, context.window.size.y - 9, global_colors.window_border_inner_fill); 295 | functions.draw_filled_rect(context.window.position.x + 8, context.window.position.y + 15, context.window.size.x - 16, context.window.size.y - 23, global_colors.window_border_color); 296 | } 297 | 298 | if (!(flags & zgui_window_flags_no_titlebar)) 299 | functions.draw_text(context.window.position.x + context.window.size.x * 0.5, context.window.position.y + (context.window.size.y * 0.010) - 10, global_colors.color_text, font, true, title.data()); 300 | 301 | functions.draw_filled_rect(context.window.position.x + 9, context.window.position.y + 16, context.window.size.x - 18, context.window.size.y - 25, global_colors.window_background); 302 | 303 | 304 | push_font(font); 305 | push_cursor_pos(global_config.base_pos); 306 | } 307 | 308 | return context.window.opened || context.window.alpha > 0; 309 | } 310 | 311 | void zgui::end_window() noexcept 312 | { 313 | for (int i = context.window.render.size() - 1; i >= 0; i--) 314 | { 315 | switch (context.window.render[i].render_type) 316 | { 317 | case zgui_render_type::zgui_line: 318 | functions.draw_line(context.window.render[i].draw_position.x, context.window.render[i].draw_position.y, context.window.render[i].size.x, context.window.render[i].size.y, context.window.render[i].color); 319 | break; 320 | case zgui_render_type::zgui_rect: 321 | functions.draw_rect(context.window.render[i].draw_position.x, context.window.render[i].draw_position.y, context.window.render[i].size.x, context.window.render[i].size.y, context.window.render[i].color); 322 | break; 323 | case zgui_render_type::zgui_filled_rect: 324 | functions.draw_filled_rect(context.window.render[i].draw_position.x, context.window.render[i].draw_position.y, context.window.render[i].size.x, context.window.render[i].size.y, context.window.render[i].color); 325 | break; 326 | case zgui_render_type::zgui_text: 327 | functions.draw_text(context.window.render[i].draw_position.x, context.window.render[i].draw_position.y, context.window.render[i].color, context.window.render[i].font, false, context.window.render[i].text.c_str()); 328 | break; 329 | } 330 | } 331 | 332 | context.window.render.clear(); 333 | 334 | while (!context.window.cursor_pos.empty()) 335 | context.window.cursor_pos.pop(); 336 | 337 | } 338 | 339 | void zgui::begin_groupbox(std::string_view title, const vec2 size, const int flags) noexcept 340 | { 341 | const int font = pop_font(); 342 | 343 | const vec2 cursor_pos = pop_cursor_pos(); 344 | const vec2 draw_pos{ context.window.position.x + cursor_pos.x, context.window.position.y + cursor_pos.y }; 345 | 346 | functions.draw_rect(draw_pos.x - 1, draw_pos.y - 1, size.x + 2, size.y + 2, global_colors.control_outline); 347 | functions.draw_filled_rect(draw_pos.x, draw_pos.y, size.x, size.y, global_colors.color_groupbox_bg); 348 | 349 | if (title.length() > 0) 350 | { 351 | if (!(flags & zgui_groupbox_flags_title_centered)) 352 | { 353 | functions.draw_text(draw_pos.x + 4, draw_pos.y - 8, global_colors.color_text, font, false, title.data()); 354 | } 355 | else 356 | { 357 | int text_wide, text_tall; 358 | functions.get_text_size(font, title.data(), text_wide, text_tall); 359 | functions.draw_text(draw_pos.x + size.x / 2 - text_wide / 2, draw_pos.y - 8, global_colors.color_text, font, false, title.data()); 360 | } 361 | } 362 | 363 | context.window.next_cursor_pos = vec2{ cursor_pos.x, cursor_pos.y + size.y + 10 }; 364 | 365 | push_cursor_pos(vec2{ cursor_pos.x + 8, cursor_pos.y + 14 }); 366 | 367 | push_font(font); 368 | } 369 | 370 | void zgui::end_groupbox() noexcept 371 | { 372 | push_cursor_pos(context.window.next_cursor_pos); 373 | context.window.next_cursor_pos = { }; 374 | } 375 | 376 | void zgui::checkbox(const char* id, bool& value) noexcept 377 | { 378 | std::vector id_split = split_str(id, '#'); 379 | 380 | const int control_height = 8; 381 | const int control_width = 8; 382 | 383 | const int font = pop_font(); 384 | 385 | const vec2 cursor_pos = pop_cursor_pos(); 386 | const vec2 draw_pos{ context.window.position.x + cursor_pos.x, context.window.position.y + cursor_pos.y }; 387 | 388 | int text_wide, text_tall; 389 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 390 | 391 | const bool active = context.window.blocking == hash(id); 392 | 393 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width + 6 + text_wide, control_height); !active && hovered && key_pressed(VK_LBUTTON)) 394 | { 395 | context.window.blocking = hash(id); 396 | } 397 | else if (active && !key_down(VK_LBUTTON)) 398 | { 399 | context.window.blocking = 0; 400 | value = !value; 401 | } 402 | 403 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 14, draw_pos.y - 2 }, zgui_render_type::zgui_text, value ? global_colors.color_text : global_colors.color_text_dimmer, id_split[0], vec2{0,0}, font }); 404 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, value ? global_colors.control_active_or_clicked : global_colors.control_idle, "", { control_width - 2, control_height - 2 } }); 405 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline,"", { control_width, control_height } }); 406 | 407 | push_cursor_pos(vec2{ cursor_pos.x + 14 + text_wide + global_config.item_spacing, cursor_pos.y }); 408 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + global_config.item_spacing }); 409 | 410 | push_font(font); 411 | } 412 | 413 | void zgui::toggle_button(const char* id, const vec2 size, bool& value) noexcept 414 | { 415 | std::vector id_split = split_str(id, '#'); 416 | 417 | const int font = pop_font(); 418 | 419 | const vec2 cursor_pos = pop_cursor_pos(); 420 | const vec2 draw_pos{ context.window.position.x + cursor_pos.x, context.window.position.y + cursor_pos.y }; 421 | 422 | const bool active = context.window.blocking == hash(id); 423 | 424 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, size.x, size.y); !active && hovered && key_pressed(VK_LBUTTON)) 425 | { 426 | context.window.blocking = hash(id); 427 | } 428 | else if (active && !key_down(VK_LBUTTON)) 429 | { 430 | context.window.blocking = 0; 431 | value = !value; 432 | } 433 | 434 | int text_wide, text_tall; 435 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 436 | 437 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + size.x / 2 - text_wide / 2, draw_pos.y + size.y / 2 - text_tall / 2 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 438 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, value ? global_colors.control_active_or_clicked : global_colors.control_idle, "", size }); 439 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline, "", { size.x + 2, size.y + 2 } }); 440 | 441 | push_cursor_pos(vec2{ cursor_pos.x + size.x + global_config.item_spacing, cursor_pos.y }); 442 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + size.y / 2 + global_config.item_spacing }); 443 | 444 | push_font(font); 445 | } 446 | 447 | bool zgui::button(const char* id, const vec2 size) noexcept 448 | { 449 | std::vector id_split = split_str(id, '#'); 450 | 451 | const int font = pop_font(); 452 | 453 | const vec2 cursor_pos = pop_cursor_pos(); 454 | const vec2 draw_pos{ context.window.position.x + cursor_pos.x, context.window.position.y + cursor_pos.y }; 455 | 456 | const bool active = context.window.blocking == hash(id); 457 | 458 | bool result = false; 459 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, size.x, size.y); !active && hovered && key_pressed(VK_LBUTTON)) 460 | { 461 | context.window.blocking = hash(id); 462 | } 463 | else if (active && !key_down(VK_LBUTTON)) 464 | { 465 | context.window.blocking = 0; 466 | result = hovered; 467 | } 468 | 469 | int text_wide, text_tall; 470 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 471 | 472 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + size.x / 2 - text_wide / 2, draw_pos.y + size.y / 2 - text_tall / 2 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 473 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, active ? global_colors.control_active_or_clicked : global_colors.control_idle, "", {size.x - 2, size.y - 2} }); 474 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline, "", size }); 475 | 476 | push_cursor_pos(vec2{ cursor_pos.x + size.x + global_config.item_spacing, cursor_pos.y }); 477 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + size.y / 2 + global_config.item_spacing }); 478 | 479 | push_font(font); 480 | 481 | return result; 482 | } 483 | 484 | void zgui::key_bind(const char* id, int& value) noexcept 485 | { 486 | std::vector id_split = split_str(id, '#'); 487 | 488 | const int control_width = 80; 489 | const int control_height = 20; 490 | 491 | value = std::clamp(value, 0, 255); 492 | 493 | const int font = pop_font(); 494 | 495 | const vec2 cursor_pos = pop_cursor_pos(); 496 | vec2 draw_pos{ context.window.position.x + cursor_pos.x + 14, context.window.position.y + cursor_pos.y }; 497 | 498 | const bool inlined = id_split[0].empty(); 499 | 500 | if (!inlined) 501 | { 502 | int text_wide, text_tall; 503 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 504 | 505 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y - 4 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 506 | 507 | draw_pos.y += text_tall; 508 | } 509 | 510 | const bool active = context.window.blocking == hash(id); 511 | 512 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width, control_height); hovered && key_pressed(VK_LBUTTON) && context.window.blocking == 0) 513 | { 514 | context.window.blocking = hash(id); 515 | } 516 | else if (active) 517 | { 518 | for (int i = 0; i < 256; i++) 519 | { 520 | if (key_pressed(i)) 521 | { 522 | if (keys_list[i] != "Error") 523 | value = i; 524 | 525 | context.window.blocking = 0; 526 | } 527 | } 528 | } 529 | 530 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 4, draw_pos.y + 4 }, zgui_render_type::zgui_text, global_colors.color_text, active ? "Press any key" : keys_list[value].data(), vec2{0,0}, font }); 531 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, active ? global_colors.control_active_or_clicked : global_colors.control_idle, "", { control_width, control_height } }); 532 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline,"", { control_width + 2, control_height + 2 } }); 533 | 534 | push_cursor_pos(vec2{ cursor_pos.x + control_width + global_config.item_spacing, cursor_pos.y }); 535 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + control_height / 2 + global_config.item_spacing + (inlined ? 0 : 12) }); 536 | 537 | push_font(font); 538 | } 539 | 540 | void zgui::text_input(const char* id, std::string& value, const int max_length, const int flags) noexcept 541 | { 542 | std::vector id_split = split_str(id, '#'); 543 | 544 | const int control_width = 80; 545 | const int control_height = 20; 546 | 547 | const int font = pop_font(); 548 | 549 | const vec2 cursor_pos = pop_cursor_pos(); 550 | vec2 draw_pos{ context.window.position.x + cursor_pos.x + 14, context.window.position.y + cursor_pos.y }; 551 | 552 | const bool inlined = id_split[0].empty(); 553 | 554 | if (!inlined) 555 | { 556 | int text_wide, text_tall; 557 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 558 | 559 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y - 4 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 560 | 561 | draw_pos.y += text_tall; 562 | } 563 | 564 | const bool active = context.window.blocking == hash(id); 565 | const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width, control_height); 566 | 567 | if (hovered && key_pressed(VK_LBUTTON) && !active) 568 | { 569 | context.window.blocking = hash(id); 570 | } 571 | else if (active) 572 | { 573 | if (key_pressed(VK_ESCAPE) || key_pressed(VK_RETURN) || (!hovered && key_pressed(VK_LBUTTON))) 574 | { 575 | context.window.blocking = 0; 576 | } 577 | else if (key_pressed(VK_BACK) && !value.empty()) 578 | { 579 | value.pop_back(); 580 | } 581 | else if (value.length() < max_length) 582 | { 583 | for (int i = 32; i <= 222; i++) 584 | { 585 | if ((i > 32 && i < 48) || (i > 57 && i < 65) || (i > 90 && i < 186)) 586 | continue; 587 | 588 | if (i > 57 && i <= 90) 589 | { 590 | if (key_pressed(i)) 591 | value += key_down(VK_SHIFT) ? static_cast(i) : static_cast(i + 32); 592 | } 593 | else 594 | { 595 | if (key_pressed(i)) 596 | { 597 | for (int j = 0; j < sizeof(special_characters); j++) 598 | { 599 | if (special_characters[j].vk == i) 600 | value += key_down(VK_SHIFT) ? special_characters[j].shift : special_characters[j].regular; 601 | } 602 | } 603 | } 604 | } 605 | } 606 | } 607 | 608 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 4, draw_pos.y + 4 }, zgui_render_type::zgui_text, global_colors.color_text, flags & zgui_text_input_flags_password ? std::string(value.length(), '*').c_str() : value.c_str(), vec2{0,0}, font }); 609 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, active ? global_colors.control_active_or_clicked : global_colors.control_idle, "", { control_width - 2, control_height - 2 } }); 610 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline,"", { control_width, control_height } }); 611 | 612 | push_cursor_pos(vec2{ cursor_pos.x + control_width + global_config.item_spacing, cursor_pos.y }); 613 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + control_height / 2 + global_config.item_spacing + (inlined ? 0 : 12) }); 614 | 615 | push_font(font); 616 | } 617 | 618 | void zgui::slider_int(const char* id, const int min, const int max, int& value) noexcept 619 | { 620 | std::vector id_split = split_str(id, '#'); 621 | 622 | const int font = pop_font(); 623 | 624 | const int control_width = 120; 625 | const int control_height = 10; 626 | 627 | const vec2 cursor_pos = pop_cursor_pos(); 628 | vec2 draw_pos{ context.window.position.x + cursor_pos.x + 14, context.window.position.y + cursor_pos.y }; 629 | 630 | const bool inlined = id_split[0].empty(); 631 | 632 | if (!inlined) 633 | { 634 | int text_wide, text_tall; 635 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 636 | 637 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y - 4 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 638 | 639 | draw_pos.y += text_tall; 640 | } 641 | 642 | if (context.window.blocking == 0 && mouse_in_region(draw_pos.x - (control_height - 2), draw_pos.y, 8, 10) && key_pressed(VK_LBUTTON)) 643 | value = std::clamp(value - 1, min, max); 644 | else if (context.window.blocking == 0 && mouse_in_region(draw_pos.x + control_width, draw_pos.y, 8, 10) && key_pressed(VK_LBUTTON)) 645 | value = std::clamp(value + 1, min, max); 646 | 647 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width, control_height); hovered && key_pressed(VK_LBUTTON) && context.window.blocking == 0) 648 | { 649 | context.window.blocking = hash(id); 650 | } 651 | else if (key_down(VK_LBUTTON) && context.window.blocking == hash(id)) 652 | { 653 | float value_unmapped = std::clamp(mouse_pos.x - draw_pos.x, 0.0f, static_cast(control_width)); 654 | int value_mapped = static_cast(value_unmapped / control_width * (max - min) + min); 655 | 656 | value = value_mapped; 657 | } 658 | else if (!key_down(VK_LBUTTON) && context.window.blocking == hash(id)) 659 | { 660 | context.window.blocking = 0; 661 | } 662 | 663 | const int dynamic_width = (static_cast(value) - min) / (max - min) * control_width - 2; 664 | 665 | int text_wide, text_tall; 666 | std::string value_str = std::to_string(value); 667 | functions.get_text_size(font, value_str.c_str(), text_wide, text_tall); 668 | 669 | int text_x = dynamic_width - text_wide; 670 | 671 | if (text_x < 0) 672 | text_x = 0; 673 | 674 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x - (control_height - 2), draw_pos.y - 2 }, zgui_render_type::zgui_text, global_colors.color_text_dimmer, "-", vec2{0,0}, font }); 675 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + (control_width + 4), draw_pos.y - 2 }, zgui_render_type::zgui_text, global_colors.color_text_dimmer, "+", vec2{0,0}, font }); 676 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + text_x, draw_pos.y }, zgui_render_type::zgui_text, global_colors.color_text, value_str, vec2{0,0}, font }); 677 | 678 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, global_colors.color_slider, "", { static_cast(dynamic_width), control_height - 2 } }); 679 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1}, zgui_render_type::zgui_filled_rect, global_colors.control_idle,"", { control_width - 2, control_height - 2 } }); 680 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline,"", { control_width, control_height } }); 681 | 682 | 683 | push_cursor_pos(vec2{ cursor_pos.x + control_width + 14 + global_config.item_spacing, cursor_pos.y }); 684 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + control_height / 2 + global_config.item_spacing + (inlined ? 0 : 12) }); 685 | 686 | push_font(font); 687 | } 688 | 689 | void zgui::slider_float(const char* id, const float min, const float max, float& value) noexcept 690 | { 691 | std::vector id_split = split_str(id, '#'); 692 | 693 | const int control_width = 120; 694 | const int control_height = 10; 695 | 696 | const int font = pop_font(); 697 | 698 | const vec2 cursor_pos = pop_cursor_pos(); 699 | vec2 draw_pos{ context.window.position.x + cursor_pos.x + 14, context.window.position.y + cursor_pos.y }; 700 | 701 | const bool inlined = id_split[0].empty(); 702 | 703 | if (!inlined) 704 | { 705 | int text_wide, text_tall; 706 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 707 | 708 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y - 4 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 709 | 710 | draw_pos.y += text_tall; 711 | } 712 | 713 | if (context.window.blocking == 0 && mouse_in_region(draw_pos.x - (control_height - 2), draw_pos.y, 8, 10) && key_pressed(VK_LBUTTON)) 714 | value = std::clamp(value - 1, min, max); 715 | else if (context.window.blocking == 0 && mouse_in_region(draw_pos.x + control_width, draw_pos.y, 8, 10) && key_pressed(VK_LBUTTON)) 716 | value = std::clamp(value + 1, min, max); 717 | 718 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width, control_height); hovered && key_pressed(VK_LBUTTON) && context.window.blocking == 0) 719 | { 720 | context.window.blocking = hash(id); 721 | } 722 | else if (key_down(VK_LBUTTON) && context.window.blocking == hash(id)) 723 | { 724 | float value_unmapped = std::clamp(mouse_pos.x - draw_pos.x, 0.0f, static_cast(control_width)); 725 | float value_mapped = static_cast((value_unmapped / static_cast(control_width)) * (max - min) + min); 726 | 727 | value = value_mapped; 728 | } 729 | else if (!key_down(VK_LBUTTON) && context.window.blocking == hash(id)) 730 | { 731 | context.window.blocking = 0; 732 | } 733 | 734 | const float dynamic_width = (static_cast(value) - min) / (max - min) * control_width - 2; 735 | 736 | int text_wide, text_tall; 737 | std::stringstream ss; 738 | ss << std::fixed << std::setprecision(2) << value; 739 | std::string value_str = ss.str(); 740 | functions.get_text_size(font, value_str.c_str(), text_wide, text_tall); 741 | 742 | int text_x = dynamic_width - text_wide; 743 | 744 | if (text_x < 0) 745 | text_x = 0; 746 | 747 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x - (control_height - 2), draw_pos.y - 2 }, zgui_render_type::zgui_text, global_colors.color_text_dimmer, "-", vec2{0,0}, font }); 748 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + (control_width + 4), draw_pos.y - 2 }, zgui_render_type::zgui_text, global_colors.color_text_dimmer, "+", vec2{0,0}, font }); 749 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + text_x, draw_pos.y }, zgui_render_type::zgui_text, global_colors.color_text, value_str, vec2{0,0}, font }); 750 | 751 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, global_colors.color_slider, "", { dynamic_width, control_height - 2 } }); 752 | context.window.render.emplace_back(zgui_control_render_t{ {draw_pos.x + 1, draw_pos.y + 1}, zgui_render_type::zgui_filled_rect, global_colors.control_idle,"", { control_width - 2, control_height - 2 } }); 753 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline,"", { control_width, control_height } }); 754 | 755 | 756 | push_cursor_pos(vec2{ cursor_pos.x + control_width + 14 + global_config.item_spacing, cursor_pos.y }); 757 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + control_height / 2 + global_config.item_spacing + (inlined ? 0 : 12) }); 758 | 759 | push_font(font); 760 | } 761 | 762 | void zgui::combobox(const char* id, std::vectoritems, int& value) noexcept 763 | { 764 | std::vector id_split = split_str(id, '#'); 765 | 766 | const int control_width = 70; 767 | const int control_height = 20; 768 | 769 | value = std::clamp(value, 0, static_cast(items.size()) - 1); 770 | 771 | const int font = pop_font(); 772 | 773 | const vec2 cursor_pos = pop_cursor_pos(); 774 | vec2 draw_pos{ context.window.position.x + cursor_pos.x + 14, context.window.position.y + cursor_pos.y }; 775 | 776 | const bool inlined = id_split[0].empty(); 777 | 778 | if (!inlined) 779 | { 780 | int text_wide, text_tall; 781 | 782 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 783 | 784 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y - 4 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 785 | 786 | draw_pos.y += text_tall; 787 | } 788 | 789 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + control_width - 10, draw_pos.y + 4 }, zgui_render_type::zgui_text, global_colors.color_text, "+", vec2{0,0}, font }); 790 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 4, draw_pos.y + 4 }, zgui_render_type::zgui_text, global_colors.color_text, items.at(value), vec2{0,0}, font }); 791 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, global_colors.control_idle, "", { control_width - 2, control_height - 2 } }); 792 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline, "", { control_width, control_height } }); 793 | 794 | push_cursor_pos(vec2{ cursor_pos.x + control_width + global_config.item_spacing, cursor_pos.y }); 795 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + control_height / 2 + global_config.item_spacing + (inlined ? 0 : 12) }); 796 | 797 | 798 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width, control_height); hovered && key_pressed(VK_LBUTTON) && context.window.blocking == 0) 799 | { 800 | context.window.blocking = hash(id); 801 | } 802 | else if (context.window.blocking == hash(id)) 803 | { 804 | for (int i = 1; i <= items.size(); i++) 805 | { 806 | bool hovered = mouse_in_region(draw_pos.x, draw_pos.y + (control_height - 1) * i, control_width, control_height); 807 | 808 | if (hovered && key_pressed(VK_LBUTTON)) 809 | { 810 | context.window.blocking = 0; 811 | value = i - 1; 812 | } 813 | 814 | if (!hovered && key_pressed(VK_LBUTTON)) 815 | { 816 | context.window.blocking = 0; 817 | } 818 | 819 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 4, draw_pos.y + (control_height - 1) * i + 4 }, zgui_render_type::zgui_text, global_colors.color_text, items.at(i - 1), vec2{0,0}, font }); 820 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + (19 * i) + 1 }, zgui_render_type::zgui_filled_rect, hovered ? global_colors.color_combo_bg : global_colors.control_idle, "", { control_width - 2, control_height - 2 } }); 821 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y + 19 * i }, zgui_render_type::zgui_filled_rect, global_colors.control_outline, "", { control_width, control_height } }); 822 | } 823 | } 824 | 825 | push_font(font); 826 | } 827 | 828 | void zgui::multi_combobox(const char* id, std::vector items) noexcept 829 | { 830 | std::vector id_split = split_str(id, '#'); 831 | 832 | const int control_width = 100; 833 | const int control_height = 20; 834 | 835 | const int font = pop_font(); 836 | 837 | const vec2 cursor_pos = pop_cursor_pos(); 838 | vec2 draw_pos{ context.window.position.x + cursor_pos.x + 14, context.window.position.y + cursor_pos.y }; 839 | 840 | const bool inlined = id_split[0].empty(); 841 | 842 | if (!inlined) 843 | { 844 | int text_wide, text_tall; 845 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 846 | 847 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y - 4 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 848 | 849 | draw_pos.y += text_tall; 850 | } 851 | 852 | std::string value_str; 853 | int text_wide, text_tall; 854 | 855 | for (auto& item_t : items) { 856 | if (*item_t.value) { 857 | if (value_str.length() > 0) 858 | value_str += ", "; 859 | 860 | value_str += item_t.name; 861 | } 862 | } 863 | 864 | functions.get_text_size(font, value_str.c_str(), text_wide, text_tall); 865 | if (text_wide > control_width - 18) 866 | { 867 | value_str.resize(control_width / 10); 868 | value_str += " ..."; 869 | } 870 | if (!value_str.length()) 871 | value_str += "None"; 872 | 873 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + control_width - 10, draw_pos.y + 4 }, zgui_render_type::zgui_text, global_colors.color_text, "+", vec2{0,0}, font }); 874 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 4, draw_pos.y + 4 }, zgui_render_type::zgui_text, global_colors.color_text, value_str, vec2{0,0}, font }); 875 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, global_colors.control_idle, "", { control_width - 2, control_height - 2 } }); 876 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline, "", { control_width, control_height } }); 877 | 878 | push_cursor_pos(vec2{ cursor_pos.x + control_width + global_config.item_spacing, cursor_pos.y }); 879 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + control_height / 2 + global_config.item_spacing + (inlined ? 0 : 12) }); 880 | 881 | 882 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width, control_height); hovered && key_pressed(VK_LBUTTON) && context.window.blocking == 0) 883 | { 884 | context.window.blocking = hash(id); 885 | } 886 | else if (context.window.blocking == hash(id)) 887 | { 888 | for (int i = 1; i <= items.size(); i++) 889 | { 890 | bool hovered = mouse_in_region(draw_pos.x, draw_pos.y + (control_height - 1) * i, control_width, control_height); 891 | 892 | if (hovered && key_pressed(VK_LBUTTON)) 893 | { 894 | context.window.blocking = 0; 895 | *items[i - 1].value = !*items[i - 1].value; 896 | } 897 | if (!hovered && key_pressed(VK_LBUTTON)) 898 | { 899 | context.window.blocking = 0; 900 | } 901 | 902 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 4, draw_pos.y + (control_height - 1) * i + 4 }, zgui_render_type::zgui_text, global_colors.color_text, items[i - 1].name.data(), vec2{0,0}, font }); 903 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + (19 * i) + 1 }, zgui_render_type::zgui_filled_rect, hovered ? global_colors.color_combo_bg : global_colors.control_idle, "", { control_width - 2, control_height - 2 } }); 904 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y + 19 * i }, zgui_render_type::zgui_filled_rect, global_colors.control_outline, "", { control_width, control_height } }); 905 | } 906 | } 907 | 908 | push_font(font); 909 | } 910 | 911 | void zgui::listbox(const char* id, std::vector items) noexcept 912 | { 913 | std::vector id_split = split_str(id, '#'); 914 | 915 | const int control_width = 100; 916 | const int control_height = 20; 917 | 918 | const int font = pop_font(); 919 | 920 | const vec2 cursor_pos = pop_cursor_pos(); 921 | vec2 draw_pos{ context.window.position.x + cursor_pos.x, context.window.position.y + cursor_pos.y }; 922 | 923 | const bool inlined = id_split[0].empty(); 924 | 925 | if (!inlined) 926 | { 927 | int text_wide, text_tall; 928 | functions.get_text_size(font, id_split[0].c_str(), text_wide, text_tall); 929 | 930 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y - 4 }, zgui_render_type::zgui_text, global_colors.color_text, id_split[0], vec2{0,0}, font }); 931 | 932 | draw_pos.y += text_tall; 933 | } 934 | 935 | for (int i = 1; i <= items.size(); i++) 936 | { 937 | const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y + (control_height - 1) * (i - 1), control_width, control_height); 938 | 939 | if (hovered && key_pressed(VK_LBUTTON)) 940 | { 941 | context.window.blocking = 0; 942 | *items[i - 1].value = !*items[i - 1].value; 943 | } 944 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 4, draw_pos.y + (control_height - 1) * (i - 1) + 4}, zgui_render_type::zgui_text, *items[i - 1].value || hovered ? global_colors.control_active_or_clicked : global_colors.color_text, items[i - 1].name.data(), vec2{0,0}, font }); 945 | } 946 | 947 | 948 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x + 1, draw_pos.y + 1 }, zgui_render_type::zgui_filled_rect, global_colors.control_idle, "", { control_width - 2, static_cast(control_height * items.size() - 2) } }); 949 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_filled_rect, global_colors.control_outline, "", { control_width, static_cast(control_height * items.size()) } }); 950 | 951 | push_cursor_pos(vec2{ cursor_pos.x + control_width + global_config.item_spacing, cursor_pos.y }); 952 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + control_height / 2 + global_config.item_spacing + (inlined ? 0 : 12) + control_height * (items.size() - 1) }); 953 | 954 | if (const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, control_width, control_height); hovered && key_pressed(VK_LBUTTON) && context.window.blocking == 0) 955 | { 956 | context.window.blocking = hash(id); 957 | } 958 | 959 | push_font(font); 960 | } 961 | 962 | bool zgui::clickable_text(const char* id) noexcept 963 | { 964 | std::vector id_split = split_str(id, '#'); 965 | 966 | const int font = pop_font(); 967 | 968 | const vec2 cursor_pos = pop_cursor_pos(); 969 | const vec2 draw_pos{ context.window.position.x + cursor_pos.x, context.window.position.y + cursor_pos.y }; 970 | 971 | int text_width, text_tall; 972 | functions.get_text_size(font, id_split[0].c_str(), text_width, text_tall); 973 | 974 | const bool active = context.window.blocking == hash(id); 975 | const bool hovered = mouse_in_region(draw_pos.x, draw_pos.y, text_width, text_tall); 976 | 977 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y}, zgui_render_type::zgui_text, (hovered || context.window.blocking == hash(id)) ? global_colors.control_active_or_clicked : global_colors.color_text, id_split[0], vec2{0,0}, font }); 978 | 979 | push_cursor_pos(vec2{ cursor_pos.x + text_width + global_config.item_spacing, cursor_pos.y }); 980 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + text_tall / 2 + global_config.item_spacing }); 981 | 982 | bool result = false; 983 | 984 | if (!active && hovered && key_pressed(VK_LBUTTON)) 985 | { 986 | context.window.blocking = hash(id); 987 | } 988 | else if (active && !key_down(VK_LBUTTON)) 989 | { 990 | context.window.blocking = 0; 991 | result = hovered; 992 | } 993 | 994 | push_font(font); 995 | 996 | return result; 997 | } 998 | 999 | void zgui::text(const char* text) noexcept 1000 | { 1001 | const int font = pop_font(); 1002 | 1003 | const vec2 cursor_pos = pop_cursor_pos(); 1004 | const vec2 draw_pos{ context.window.position.x + cursor_pos.x, context.window.position.y + cursor_pos.y }; 1005 | 1006 | int text_width, text_tall; 1007 | functions.get_text_size(font, text, text_width, text_tall); 1008 | 1009 | context.window.render.emplace_back(zgui_control_render_t{ { draw_pos.x, draw_pos.y }, zgui_render_type::zgui_text, global_colors.color_text, text, vec2{0,0}, font }); 1010 | 1011 | push_cursor_pos(vec2{ cursor_pos.x + text_width + global_config.item_spacing, cursor_pos.y }); 1012 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + text_tall / 2 + global_config.item_spacing }); 1013 | 1014 | push_font(font); 1015 | } 1016 | 1017 | void zgui::dummy() noexcept 1018 | { 1019 | const vec2 cursor_pos = pop_cursor_pos(); 1020 | push_cursor_pos(vec2{ cursor_pos.x, cursor_pos.y + global_config.item_spacing }); 1021 | } 1022 | 1023 | void zgui::next_column(const int pusher_x, const int pusher_y) noexcept 1024 | { 1025 | const vec2 cursor_pos = pop_cursor_pos(); 1026 | vec2 new_cursor_pos{ cursor_pos.x + pusher_x, global_config.base_pos.y + pusher_y }; 1027 | 1028 | if (context.window.next_cursor_pos.y != 0) 1029 | new_cursor_pos.y += 14; 1030 | 1031 | push_cursor_pos(new_cursor_pos); 1032 | } 1033 | 1034 | void zgui::same_line(const float x_axis) noexcept 1035 | { 1036 | const vec2 cursor_pos = pop_cursor_pos(); 1037 | 1038 | if (x_axis != -1) 1039 | push_cursor_pos(vec2{ global_config.base_pos.x + x_axis, cursor_pos.x }); 1040 | } 1041 | 1042 | void zgui::backup_line() noexcept 1043 | { 1044 | const vec2 cursor_pos = pop_cursor_pos(); 1045 | 1046 | push_cursor_pos(vec2{ context.window.next_cursor_pos.x, cursor_pos.y }); 1047 | } -------------------------------------------------------------------------------- /core/menu/zgui/zgui.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../../dependencies/utilities/render.hpp" 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | #define ZGUI_API __declspec(dllexport) 13 | 14 | // zgui by zxvnme (https://github.com/zxvnme) and all the community contributors 15 | #define ZGUI_VER "1.4.8" // the number after second dot is snapshot version. 16 | /* =============================[general]=============================== 17 | * 18 | * zgui is an simple framework created to help people with GUI rendering during their game hacking (but not only) journey. 19 | * here is glance zgui feature presentation: 20 | * - easy to use immediate mode rendering (all you need is to include zgui header and source files to your project). 21 | * - simple and aesthetic design. 22 | * - extensible code. 23 | * ... and function documentation in section below: 24 | * 25 | * ================================[pseudo documentation]===================================== 26 | * 27 | * get_functions() 28 | * -- function that is used to get our wrapped ones. 29 | * 30 | * begin_window(std::string_view title, vec2 default_size, unsigned long font, int flags); 31 | * end_window(); 32 | * -- functions used to create and end window. 33 | * 34 | * begin_groupbox(std::string_view name, vec2 size); 35 | * end_groupbox(); 36 | * -- functions uses to create our groupbox with desired size and end it. 37 | * 38 | * slider_int(std::string_view id, int min, int max, int* value); 39 | * slider_float(std::string_view id, float min, float max, float* value); 40 | * -- functions used to create sliders with value type described in function name. 41 | * 42 | * combobox(std::string_view id, std::vector items, int* value); 43 | * multi_combobox(std::string id, std::vector items) 44 | * -- functions used for creating combo boxes. 45 | * 46 | * checkbox(std::string_view id, bool* value); 47 | * -- function that creates checkbox. 48 | * 49 | * toggle_button(std::string_view id, vec2 size, bool* value); 50 | * -- function that creates toggle button. 51 | * 52 | * button(std::string_view id, vec2 size); 53 | * -- function that creates button. 54 | * 55 | * key_bind(std::string_view id, int* value); 56 | * -- function that creates key binder. 57 | * 58 | * text_input(std::string_view id, std::string* value, int max_length = 18); 59 | * -- functions that creates text input box. 60 | * 61 | * clickable_text(std::string_view text); 62 | * -- function that creates text that can be clicked and eventually perform an action. 63 | * 64 | * text(std::string_view text); 65 | * -- function that creates text. 66 | * 67 | * dummy(); 68 | * -- function that pushes cursor_pos.x to make empty space between our controls. 69 | * 70 | * same_line(float x_axis = -1); 71 | * backup_line(); 72 | * -- functions used for inline controls positioning. NOTE: there can be only one item between these two functions called. 73 | * 74 | * ================================[hashing controls names]================================ 75 | * 76 | * the '#' thing in control name is separator that splits our name to two elements; actual displayed name & the one that is "hidden" 77 | * 78 | * bad example: 79 | * zgui::button("button", { 120, 30 }); 80 | * zgui::button("button", { 120, 30 }); 81 | * 82 | * code above won't work correctly because of same name provided. (known consequence is clicking 2 buttons at once) 83 | * 84 | * good example: 85 | * zgui::button("button#button_1", { 120, 30 }); 86 | * zgui::button("button#button_2", { 120, 30 }); 87 | * 88 | * and now, code above works fine because unique id (used in window input blocking) is provided after '#' 89 | * 90 | * ==================================[input handling]====================================== 91 | * 92 | * IMPORTANT NOTE: poll_input(); HAS to be called before everything. Otherwise zgui will throw an exception or won't work properly. 93 | * 94 | * poll_input("type_your_window_name") is function used to start reading input from window we specify in function parameter (string_view) 95 | * 96 | * bad example: 97 | * zgui::poll_input(""); 98 | * ... not calling this before whole zgui :) 99 | * 100 | * code above won't work correctly because window name string_view size is equal to 0. 101 | * 102 | * good example: 103 | * zgui::poll_input("zgui directx9 example"); 104 | * zgui::poll_input("Minecraft 1.8.9"); 105 | * 106 | * and now, code above will work fine if your window titles are "zgui directx9 example" or "Minecraft 1.8.9" 107 | * 108 | * ================================================================================================ 109 | * 110 | * ================================================================================================ 111 | */ 112 | 113 | // For examples and function descriptions see zgui header file. 114 | namespace zgui { 115 | 116 | // Multi selectable item. 117 | struct multi_select_item { std::string_view name; bool* value; }; 118 | // Two dimensional vector. 119 | struct vec2 { float x, y; }; 120 | 121 | /// "Proxy" functions definitions. 122 | 123 | using line_t = std::add_pointer_t; 124 | using rect_t = std::add_pointer_t; 125 | using filled_rect_t = std::add_pointer_t; 126 | using text_t = std::add_pointer_t; 127 | using get_text_size_t = std::add_pointer_t; 128 | using get_frametime = std::add_pointer_t; 129 | /// 130 | 131 | // "Proxy" functions stuff... 132 | struct functions_t 133 | { 134 | line_t draw_line; 135 | rect_t draw_rect; 136 | filled_rect_t draw_filled_rect; 137 | text_t draw_text; 138 | get_text_size_t get_text_size; 139 | get_frametime get_frametime; 140 | }; 141 | extern functions_t functions; 142 | 143 | // Flags for window appereance and its behavior. 144 | // ex: (zgui_window_flags_no_border | zgui_window_flags_no_titlebar) will cause window to be borderless and without title bar. 145 | enum zgui_window_flags 146 | { 147 | zgui_window_flags_none = 0, 148 | zgui_window_flags_no_border = 1 << 0, 149 | zgui_window_flags_no_titlebar = 1 << 1, 150 | zgui_window_flags_no_ontoggle_animation = 1 << 2, 151 | zgui_window_flags_no_move = 1 << 3, 152 | zgui_window_flags_always_open = 1 << 4, 153 | }; 154 | 155 | // Flags for text input appereance. 156 | // ex: (zgui_text_input_flags_password) will convert text input (ex: "abcdef") to "******". 157 | enum zgui_text_input_flags 158 | { 159 | zgui_text_input_flags_none = 0, 160 | zgui_text_input_flags_password = 1 << 0 161 | }; 162 | 163 | // Flags for groupboxes appereance. 164 | // ex: (zgui_groupbox_flags_title_centered) will center align title of groupbox. 165 | enum zgui_groupbox_flags 166 | { 167 | zgui_groupbox_flags_none = 0, 168 | zgui_groupbox_flags_title_centered = 1 << 0, 169 | }; 170 | 171 | enum class zgui_render_type 172 | { 173 | zgui_line = 1, 174 | zgui_rect, 175 | zgui_filled_rect, 176 | zgui_text 177 | }; 178 | 179 | struct zgui_control_render_t 180 | { 181 | vec2 draw_position; 182 | zgui_render_type render_type; 183 | color color; 184 | std::string text; 185 | vec2 size; 186 | int font = 0; 187 | }; 188 | 189 | struct gui_window_context_t 190 | { 191 | uint32_t blocking; 192 | std::stack cursor_pos; 193 | std::stack fonts; 194 | std::vector render; 195 | vec2 position, size; 196 | vec2 next_cursor_pos; 197 | bool dragging; 198 | bool opened; 199 | int alpha; 200 | }; 201 | 202 | // Start Input loop 203 | ZGUI_API void poll_input(std::string_view window_name); 204 | ZGUI_API void poll_input(HWND hwnd); 205 | 206 | // Push cursor position to the stack defined in window context 207 | ZGUI_API void push_cursor_pos(vec2 pos) noexcept; 208 | // Pop cursor position from the stack defined in window context 209 | ZGUI_API vec2 pop_cursor_pos() noexcept; 210 | 211 | // Push font to the stack defined in window context 212 | ZGUI_API void push_font(unsigned long font) noexcept; 213 | // Pop font from the stack defined in window context 214 | ZGUI_API unsigned long pop_font(); 215 | 216 | ZGUI_API bool begin_window(std::string_view title, vec2 default_size, unsigned long font, int flags = 0); 217 | ZGUI_API void end_window() noexcept; 218 | 219 | ZGUI_API void begin_groupbox(std::string_view title, vec2 size, int flags = 0) noexcept; 220 | ZGUI_API void end_groupbox() noexcept; 221 | 222 | ZGUI_API void checkbox(const char* id, bool& value) noexcept; 223 | 224 | ZGUI_API void toggle_button(const char* id, vec2 size, bool& value) noexcept; 225 | 226 | ZGUI_API bool button(const char* id, vec2 size) noexcept; 227 | 228 | ZGUI_API void key_bind(const char* id, int& value) noexcept; 229 | 230 | ZGUI_API void text_input(const char* id, std::string& value, int max_length = 16, int flags = 0) noexcept; 231 | 232 | ZGUI_API void slider_int(const char* id, int min, int max, int& value) noexcept; 233 | 234 | ZGUI_API void slider_float(const char* id, float min, float max, float& value) noexcept; 235 | 236 | ZGUI_API void combobox(const char*, std::vector items, int& value) noexcept; 237 | 238 | ZGUI_API void multi_combobox(const char* id, std::vector items) noexcept; 239 | 240 | ZGUI_API void listbox(const char* id, std::vector items) noexcept; 241 | 242 | ZGUI_API bool clickable_text(const char* id) noexcept; 243 | 244 | ZGUI_API void text(const char* text) noexcept; 245 | 246 | ZGUI_API void dummy() noexcept; 247 | 248 | ZGUI_API void next_column(int pusher_x = 174, int pusher_y = 14) noexcept; 249 | 250 | ZGUI_API void same_line(float x_axis = -1) noexcept; 251 | 252 | ZGUI_API void backup_line() noexcept; 253 | } -------------------------------------------------------------------------------- /csgo-cheat.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "csgo-cheat", "csgo-cheat.vcxproj", "{AF041675-F00D-4A72-B40F-78D0C4BB72D9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {AF041675-F00D-4A72-B40F-78D0C4BB72D9}.Debug|x64.ActiveCfg = Debug|x64 17 | {AF041675-F00D-4A72-B40F-78D0C4BB72D9}.Debug|x64.Build.0 = Debug|x64 18 | {AF041675-F00D-4A72-B40F-78D0C4BB72D9}.Debug|x86.ActiveCfg = Debug|Win32 19 | {AF041675-F00D-4A72-B40F-78D0C4BB72D9}.Debug|x86.Build.0 = Debug|Win32 20 | {AF041675-F00D-4A72-B40F-78D0C4BB72D9}.Release|x64.ActiveCfg = Release|x64 21 | {AF041675-F00D-4A72-B40F-78D0C4BB72D9}.Release|x64.Build.0 = Release|x64 22 | {AF041675-F00D-4A72-B40F-78D0C4BB72D9}.Release|x86.ActiveCfg = Release|Win32 23 | {AF041675-F00D-4A72-B40F-78D0C4BB72D9}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {BB5EEA13-1F46-49E7-8ED1-B56C1ACFEF5D} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /csgo-cheat.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {AF041675-F00D-4A72-B40F-78D0C4BB72D9} 24 | ayysense 25 | 10.0.18362.0 26 | csgo-cheat 27 | 28 | 29 | 30 | DynamicLibrary 31 | true 32 | v142 33 | MultiByte 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | MultiByte 41 | 42 | 43 | Application 44 | true 45 | v142 46 | MultiByte 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | MultiByte 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | D:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Include;$(IncludePath) 75 | D:\Program Files %28x86%29\Microsoft DirectX SDK %28June 2010%29\Lib\x86;$(LibraryPath) 76 | .\output\debug\ 77 | .\intermediates\ 78 | 79 | 80 | .\output\debug\ 81 | .\intermediates\ 82 | 83 | 84 | 85 | TurnOffAllWarnings 86 | Disabled 87 | true 88 | true 89 | _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) 90 | stdcpp17 91 | 92 | 93 | 94 | 95 | Level3 96 | Disabled 97 | true 98 | true 99 | 100 | 101 | 102 | 103 | Level3 104 | MaxSpeed 105 | true 106 | true 107 | true 108 | true 109 | 110 | 111 | true 112 | true 113 | 114 | 115 | 116 | 117 | Level3 118 | MaxSpeed 119 | true 120 | true 121 | true 122 | true 123 | 124 | 125 | true 126 | true 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | -------------------------------------------------------------------------------- /csgo-cheat.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | true 5 | 6 | -------------------------------------------------------------------------------- /dependencies/common_includes.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | #include 18 | #pragma comment(lib, "d3d9.lib") 19 | #pragma comment(lib, "d3dx9.lib") 20 | 21 | #include "utilities/fnv.hpp" 22 | #include "utilities/utilities.hpp" 23 | #include "utilities/render.hpp" 24 | #include "utilities/hook.hpp" 25 | #include "interfaces/interfaces.hpp" 26 | #include "utilities/netvars.hpp" 27 | 28 | #include "../source-sdk/sdk.hpp" 29 | #include "../core/hooks/hooks.hpp" -------------------------------------------------------------------------------- /dependencies/interfaces/cglobalvarsbase.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class c_global_vars_base { 4 | public: 5 | float realtime; 6 | int frame_count; 7 | float absolute_frametime; 8 | float absolute_frame_start_time; 9 | float cur_time; 10 | float frame_time; 11 | int max_clients; 12 | int tick_count; 13 | float interval_per_tick; 14 | float interpolation_amount; 15 | int sim_ticks_this_frame; 16 | int network_protocol; 17 | void* p_save_data; 18 | bool is_client; 19 | bool is_remote_client; 20 | int timestamp_networking_base; 21 | int timestamp_randomize_window; 22 | }; -------------------------------------------------------------------------------- /dependencies/interfaces/ibaseclientdll.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../source-sdk/classes/client_class.hpp" 3 | 4 | class i_base_client_dll { 5 | public: 6 | client_class * get_client_classes( ) { 7 | using original_fn = client_class * ( __thiscall* )( i_base_client_dll* ); 8 | return ( *( original_fn** ) this ) [ 8 ]( this ); 9 | } 10 | }; -------------------------------------------------------------------------------- /dependencies/interfaces/icliententitylist.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class i_client_entity_list { 5 | public: 6 | void* get_client_entity( int index ) { 7 | using original_fn = void*( __thiscall* )( i_client_entity_list*, int ); 8 | return ( *( original_fn** ) this ) [ 3 ]( this, index ); 9 | } 10 | void* get_client_entity( uintptr_t handle ) { 11 | using original_fn = void*( __thiscall* )( i_client_entity_list*, uintptr_t ); 12 | return ( *( original_fn** ) this ) [ 4 ]( this, handle ); 13 | } 14 | }; -------------------------------------------------------------------------------- /dependencies/interfaces/iclientmode.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class i_client_mode { 4 | // todo 5 | }; -------------------------------------------------------------------------------- /dependencies/interfaces/iclientstate.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #pragma pack(push, 1) 4 | 5 | class i_net_channel { 6 | public: 7 | char pad_0000 [ 20 ]; 8 | bool is_processing_messages; 9 | bool should_delete; 10 | char pad_0016 [ 2 ]; 11 | int32_t out_sequence_nr; 12 | int32_t in_sequence_nr; 13 | int32_t out_sequence_nr_ack; 14 | int32_t out_reliable_state_count; 15 | int32_t in_reliable_state_count; 16 | int32_t choked_packets; 17 | char pad_0030 [ 1044 ]; 18 | 19 | bool transmit( bool only_reliable ) { 20 | using fn = bool( __thiscall* )( void *, bool ); 21 | return ( *( fn** ) this ) [ 49 ]( this, only_reliable ); 22 | } 23 | }; 24 | 25 | class i_client_state { 26 | public: 27 | char pad_0000 [ 156 ]; 28 | uint32_t net_channel; 29 | uint32_t challenge_count; 30 | double reconnect_time; 31 | int32_t retry_count; 32 | char pad_00A8 [ 88 ]; 33 | int32_t signon_state_count; 34 | char pad_0104 [ 8 ]; 35 | float next_cmd_time; 36 | int32_t server_count; 37 | uint32_t current_sequence; 38 | char pad_0118 [ 8 ]; 39 | char pad_0120 [ 0x4C ]; 40 | int32_t delta_tick; 41 | bool is_paused; 42 | char pad_0171 [ 3 ]; 43 | int32_t view_entity; 44 | int32_t player_slot; 45 | char pad_017C [ 4 ]; 46 | char level_name [ 260 ]; 47 | char level_name_short [ 40 ]; 48 | char pad_02AC [ 92 ]; 49 | int32_t max_clients; 50 | char pad_030C [ 4083 ]; 51 | uint32_t string_table_container; 52 | char pad_1303 [ 14737 ]; 53 | float last_server_tick_time; 54 | bool is_in_simulation; 55 | char pad_4C99 [ 3 ]; 56 | uint32_t old_tick_count; 57 | float tick_remainder; 58 | float frame_time; 59 | int32_t last_outgoing_command; 60 | int32_t choked_commands; 61 | int32_t last_command_ack; 62 | int32_t command_ack; 63 | int32_t sound_sequence; 64 | char pad_4CBC [ 80 ]; 65 | vec3_t view_angles; 66 | 67 | void full_update( ) { 68 | delta_tick = -1; 69 | } 70 | }; 71 | 72 | #pragma pack(pop) -------------------------------------------------------------------------------- /dependencies/interfaces/iconsole.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../source-sdk/classes/convar.hpp" 3 | #include "../../source-sdk/misc/color.hpp" 4 | 5 | class i_console { 6 | public: 7 | convar * get_convar( const char* name ) { 8 | using original_fn = convar * ( __thiscall* )( i_console*, const char* ); 9 | return ( *( original_fn** ) this ) [ 16 ]( this, name ); 10 | } 11 | }; -------------------------------------------------------------------------------- /dependencies/interfaces/igameeventmanager.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../source-sdk/classes/gameevent.hpp" 3 | 4 | class i_game_event_manager { 5 | public: 6 | // to do 7 | }; -------------------------------------------------------------------------------- /dependencies/interfaces/iinput.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../source-sdk/classes/c_usercmd.hpp" 3 | 4 | class i_input { 5 | public: 6 | c_usercmd * get_user_cmd( int slot, int sequence_num ) { 7 | using original_fn = c_usercmd * ( __thiscall* )( void*, int, int ); 8 | return ( *( original_fn** ) this )[ 8 ]( this, slot, sequence_num ); 9 | } 10 | }; -------------------------------------------------------------------------------- /dependencies/interfaces/ilocalize.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class i_localize { 4 | public: 5 | wchar_t* find( const char* token_name ) { 6 | using original_fn = wchar_t*( __thiscall* )( i_localize*, const char* ); 7 | return ( *( original_fn** ) this ) [ 11 ]( this, token_name ); 8 | } 9 | }; -------------------------------------------------------------------------------- /dependencies/interfaces/imaterialsystem.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../source-sdk/structs/materials.hpp" 3 | 4 | class i_material_system { 5 | public: 6 | i_material * find_material( char const* material_name, const char* group_name, bool complain = true, const char* complain_prefix = 0 ) { 7 | using original_fn = i_material * ( __thiscall* )( i_material_system*, char const*, const char*, bool, const char* ); 8 | return ( *( original_fn** ) this ) [ 84 ]( this, material_name, group_name, complain, complain_prefix ); 9 | } 10 | material_handle_t first_material( ) { 11 | using original_fn = material_handle_t( __thiscall* )( i_material_system* ); 12 | return ( *( original_fn** ) this ) [ 86 ]( this ); 13 | } 14 | material_handle_t next_material( material_handle_t handle ) { 15 | using original_fn = material_handle_t( __thiscall* )( i_material_system*, material_handle_t ); 16 | return ( *( original_fn** ) this ) [ 87 ]( this, handle ); 17 | } 18 | material_handle_t invalid_material_handle( ) { 19 | using original_fn = material_handle_t( __thiscall* )( i_material_system* ); 20 | return ( *( original_fn** ) this ) [ 88 ]( this ); 21 | } 22 | i_material* get_material( material_handle_t handle ) { 23 | using original_fn = i_material * ( __thiscall* )( i_material_system*, material_handle_t ); 24 | return ( *( original_fn** ) this ) [ 89 ]( this, handle ); 25 | } 26 | int get_materials_count( ) { 27 | using original_fn = int( __thiscall* )( i_material_system* ); 28 | return ( *( original_fn** ) this ) [ 90 ]( this ); 29 | } 30 | }; -------------------------------------------------------------------------------- /dependencies/interfaces/interfaces.cpp: -------------------------------------------------------------------------------- 1 | #include "interfaces.hpp" 2 | #include "../common_includes.hpp" 3 | 4 | i_base_client_dll* interfaces::client = nullptr; 5 | i_input* interfaces::input = nullptr; 6 | i_client_entity_list* interfaces::entity_list = nullptr; 7 | iv_engine_client* interfaces::engine = nullptr; 8 | i_client_mode* interfaces::clientmode = nullptr; 9 | i_client_state* interfaces::clientstate = nullptr; 10 | i_panel* interfaces::panel = nullptr; 11 | i_surface* interfaces::surface = nullptr; 12 | c_global_vars_base* interfaces::globals = nullptr; 13 | i_material_system* interfaces::material_system = nullptr; 14 | iv_model_info* interfaces::model_info = nullptr; 15 | iv_model_render* interfaces::model_render = nullptr; 16 | void* interfaces::render_view = nullptr; 17 | iv_effects* interfaces::effects = nullptr; 18 | i_console* interfaces::console = nullptr; 19 | i_localize* interfaces::localize = nullptr; 20 | i_game_event_manager* interfaces::event_manager = nullptr; 21 | iv_debug_overlay* interfaces::debug_overlay = nullptr; 22 | IDirect3DDevice9* interfaces::directx = nullptr; 23 | 24 | void interfaces::initialize( ) { 25 | client = reinterpret_cast< i_base_client_dll* >( utilities::game::capture_interface( "client_panorama.dll", "VClient018" ) ); 26 | entity_list = reinterpret_cast< i_client_entity_list* >( utilities::game::capture_interface( "client_panorama.dll", "VClientEntityList003" ) ); 27 | engine = reinterpret_cast< iv_engine_client* >( utilities::game::capture_interface( "engine.dll", "VEngineClient014" ) ); 28 | panel = reinterpret_cast< i_panel* >( utilities::game::capture_interface( "vgui2.dll", "VGUI_Panel009" ) ); 29 | surface = reinterpret_cast< i_surface* >( utilities::game::capture_interface( "vguimatsurface.dll", "VGUI_Surface031" ) ); 30 | material_system = reinterpret_cast< i_material_system* >( utilities::game::capture_interface( "materialsystem.dll", "VMaterialSystem080" ) ); 31 | model_info = reinterpret_cast< iv_model_info* >( utilities::game::capture_interface( "engine.dll", "VModelInfoClient004" ) ); 32 | model_render = reinterpret_cast< iv_model_render* >( utilities::game::capture_interface( "engine.dll", "VEngineModel016" ) ); 33 | render_view = reinterpret_cast< void* >( utilities::game::capture_interface( "engine.dll", "VEngineRenderView014" ) ); 34 | console = reinterpret_cast< i_console* >( utilities::game::capture_interface( "vstdlib.dll", "VEngineCvar007" ) ); 35 | localize = reinterpret_cast< i_localize* >( utilities::game::capture_interface( "localize.dll", "Localize_001" ) ); 36 | event_manager = reinterpret_cast< i_game_event_manager* >( utilities::game::capture_interface( "engine.dll", "GAMEEVENTSMANAGER002" ) ); 37 | debug_overlay = reinterpret_cast< iv_debug_overlay* >( utilities::game::capture_interface( "engine.dll", "VDebugOverlay004" ) ); 38 | effects = reinterpret_cast< iv_effects* >( utilities::game::capture_interface( "engine.dll", "VEngineEffects001" ) ); 39 | 40 | clientmode = **reinterpret_cast< i_client_mode*** >( ( *reinterpret_cast< uintptr_t** >( client ) ) [ 10 ] + 5 ); 41 | clientstate = **( i_client_state*** ) ( utilities::pattern_scan( GetModuleHandleA( "engine.dll" ), "A1 ? ? ? ? 8B 80 ? ? ? ? C3" ) + 1 ); 42 | globals = **reinterpret_cast< c_global_vars_base*** >( ( *reinterpret_cast< uintptr_t** >( client ) [ 0 ] + 27 ) ); 43 | directx = **( IDirect3DDevice9*** ) ( utilities::pattern_scan( GetModuleHandleA( "shaderapidx9.dll" ), "A1 ? ? ? ? 50 8B 08 FF 51 0C" ) + 1 ); 44 | input = *( i_input** ) ( utilities::pattern_scan( GetModuleHandleA( "client_panorama.dll" ), "B9 ? ? ? ? F3 0F 11 04 24 FF 50 10" ) + 1 ); 45 | } -------------------------------------------------------------------------------- /dependencies/interfaces/interfaces.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "ibaseclientdll.hpp" 3 | #include "icliententitylist.hpp" 4 | #include "ivengineclient.hpp" 5 | #include "iclientmode.hpp" 6 | #include "iclientstate.hpp" 7 | #include "ipanel.hpp" 8 | #include "isurface.hpp" 9 | #include "cglobalvarsbase.hpp" 10 | #include "imaterialsystem.hpp" 11 | #include "ivmodelinfo.hpp" 12 | #include "ivmodelrender.hpp" 13 | #include "ivdebugoverlay.hpp" 14 | #include "iconsole.hpp" 15 | #include "ilocalize.hpp" 16 | #include "igameeventmanager.hpp" 17 | #include "iinput.hpp" 18 | #include "iveffects.hpp" 19 | 20 | #include 21 | #include 22 | #pragma comment(lib, "d3d9.lib") 23 | #pragma comment(lib, "d3dx9.lib") 24 | 25 | namespace interfaces { 26 | extern i_base_client_dll* client; 27 | extern i_input* input; 28 | extern i_client_entity_list* entity_list; 29 | extern iv_engine_client* engine; 30 | extern i_client_mode* clientmode; 31 | extern i_client_state* clientstate; 32 | extern i_panel* panel; 33 | extern i_surface* surface; 34 | extern c_global_vars_base* globals; 35 | extern i_material_system* material_system; 36 | extern iv_model_info* model_info; 37 | extern iv_model_render* model_render; 38 | extern void* render_view; 39 | extern iv_effects* effects; 40 | extern iv_debug_overlay* debug_overlay; 41 | extern i_console* console; 42 | extern i_localize* localize; 43 | extern i_game_event_manager* event_manager; 44 | extern IDirect3DDevice9* directx; 45 | 46 | void initialize( ); 47 | } -------------------------------------------------------------------------------- /dependencies/interfaces/ipanel.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class i_panel { 4 | public: 5 | const char* get_panel_name( unsigned int panel_id ) { 6 | using original_fn = const char*( __thiscall* )( i_panel*, unsigned int ); 7 | return ( *( original_fn** ) this ) [ 36 ]( this, panel_id ); 8 | } 9 | }; -------------------------------------------------------------------------------- /dependencies/interfaces/isurface.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../source-sdk/structs/vertex_t.hpp" 3 | 4 | class i_surface { 5 | public: 6 | void set_drawing_color( int r, int g, int b, int a = 255 ) { 7 | using original_fn = void( __thiscall* )( i_surface*, int, int, int, int ); 8 | return ( *( original_fn** ) this )[ 15 ]( this, r, g, b, a ); 9 | } 10 | void set_text_color( int r, int g, int b, int a = 255 ) { 11 | using original_fn = void( __thiscall* )( i_surface*, int, int, int, int ); 12 | return ( *( original_fn** ) this )[ 25 ]( this, r, g, b, a ); 13 | } 14 | void draw_polygon( int n, vertex_t *vertice, bool clip_vertices = true ) { 15 | using original_fn = void( __thiscall* )( i_surface*, int, vertex_t*, bool ); 16 | return ( *( original_fn** ) this )[ 106 ]( this, n, vertice, clip_vertices ); 17 | } 18 | void draw_filled_rectangle( int x, int y, int x1, int y1 ) { 19 | using original_fn = void( __thiscall* )( i_surface*, int, int, int, int ); 20 | return ( *( original_fn** ) this )[ 16 ]( this, x, y, x + x1, y + y1 ); 21 | } 22 | void set_texture( int id ) { 23 | using original_fn = void( __thiscall* )( i_surface*, int ); 24 | return ( *( original_fn** ) this )[ 38 ]( this, id ); 25 | } 26 | void set_texture_rgba( int id, const unsigned char *rgba, int wide, int tall ) { 27 | using original_fn = void( __thiscall* )( i_surface*, int, const unsigned char *, int, int, int, bool ); 28 | return ( *( original_fn** ) this )[ 37 ]( this, id, rgba, wide, tall, 0, false ); 29 | } 30 | int create_new_texture_id( bool procedural = false ) { 31 | using original_fn = int( __thiscall* )( i_surface*, bool ); 32 | return ( *( original_fn** ) this )[ 43 ]( this, procedural ); 33 | } 34 | void draw_outlined_rect( int x, int y, int x1, int y1 ) { 35 | using original_fn = void( __thiscall* )( i_surface*, int, int, int, int ); 36 | return ( *( original_fn** ) this )[ 18 ]( this, x, y, x + x1, y+y1); 37 | } 38 | void draw_line( int x1, int y1, int x2, int y2 ) { 39 | using original_fn = void( __thiscall* )( i_surface*, int, int, int, int ); 40 | return ( *( original_fn** ) this )[ 19 ]( this, x1, y1, x2, y2 ); 41 | } 42 | void draw_text_font( unsigned long font ) { 43 | using original_fn = void( __thiscall* )( i_surface*, unsigned long ); 44 | return ( *( original_fn** ) this )[ 23 ]( this, font ); 45 | } 46 | void draw_text_pos( int x, int y ) { 47 | using original_fn = void( __thiscall* )( i_surface*, int, int ); 48 | return ( *( original_fn** ) this )[ 26 ]( this, x, y ); 49 | } 50 | void draw_render_text( const wchar_t* text, int textLen ) { 51 | using original_fn = void( __thiscall* )( i_surface*, const wchar_t*, int, int ); 52 | return ( *( original_fn** ) this )[ 28 ]( this, text, textLen, 0 ); 53 | } 54 | unsigned long font_create( ) { 55 | using original_fn = unsigned int( __thiscall* )( i_surface* ); 56 | return ( *( original_fn** ) this )[ 71 ]( this ); 57 | } 58 | void set_font_glyph( unsigned long font, const char* windowsFontName, int tall, int weight, int blur, int scanlines, int flags ) { 59 | using original_fn = void( __thiscall* )( i_surface*, unsigned long, const char*, int, int, int, int, int, int, int ); 60 | return ( *( original_fn** ) this )[ 72 ]( this, font, windowsFontName, tall, weight, blur, scanlines, flags, 0, 0 ); 61 | } 62 | void get_text_size( unsigned long font, const wchar_t* text, int& wide, int& tall ) { 63 | using original_fn = void( __thiscall* )( i_surface*, unsigned long, const wchar_t*, int&, int& ); 64 | return ( *( original_fn** ) this )[ 79 ]( this, font, text, wide, tall ); 65 | } 66 | }; -------------------------------------------------------------------------------- /dependencies/interfaces/ivdebugoverlay.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../source-sdk/math/vector3d.hpp" 3 | 4 | class iv_debug_overlay { 5 | public: 6 | bool world_to_screen( const vec3_t& in, vec3_t& out ) { 7 | using original_fn = int( __thiscall* )( iv_debug_overlay*, const vec3_t&, vec3_t& ); 8 | int return_value = ( *( original_fn** ) this ) [ 13 ]( this, in, out ); 9 | return static_cast< bool >( return_value != 1 ); 10 | } 11 | }; -------------------------------------------------------------------------------- /dependencies/interfaces/iveffects.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../source-sdk/structs/dlight.hpp" 3 | 4 | class iv_effects { 5 | public: 6 | dlight_t * alloc( int key ) { 7 | using original_fn = dlight_t * ( __thiscall* )( void*, int ); 8 | return ( *( original_fn** ) this ) [ 4 ]( this, key ); 9 | } 10 | }; -------------------------------------------------------------------------------- /dependencies/interfaces/ivengineclient.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "../../source-sdk/math/vector3d.hpp" 4 | 5 | struct player_info_t { 6 | int64_t __pad0; 7 | union { 8 | int64_t xuid; 9 | struct { 10 | int xuidlow; 11 | int xuidhigh; 12 | }; 13 | }; 14 | char name [ 128 ]; 15 | int userid; 16 | char guid [ 33 ]; 17 | unsigned int friendsid; 18 | char friendsname [ 128 ]; 19 | bool fakeplayer; 20 | bool ishltv; 21 | unsigned int customfiles [ 4 ]; 22 | unsigned char filesdownloaded; 23 | }; 24 | 25 | class iv_engine_client { 26 | public: 27 | int get_local_player( ) { 28 | using original_fn = int( __thiscall* )( iv_engine_client* ); 29 | return ( *( original_fn** ) this ) [ 12 ]( this ); 30 | } 31 | int get_player_for_user_id( int user_id ) { 32 | using original_fn = int( __thiscall* )( iv_engine_client*, int ); 33 | return ( *( original_fn** ) this ) [ 9 ]( this, user_id ); 34 | } 35 | void get_player_info( int index, player_info_t* info ) { 36 | using original_fn = void( __thiscall* )( iv_engine_client*, int, player_info_t* ); 37 | return ( *( original_fn** ) this ) [ 8 ]( this, index, info ); 38 | } 39 | void get_screen_size( int& width, int& height ) { 40 | using original_fn = void( __thiscall* )( iv_engine_client*, int&, int& ); 41 | return ( *( original_fn** ) this ) [ 5 ]( this, width, height ); 42 | } 43 | void execute_cmd( const char* cmd ) { 44 | using original_fn = void( __thiscall* )( iv_engine_client*, const char* ); 45 | return ( *( original_fn** ) this ) [ 108 ]( this, cmd ); // this always seems to crash whilst debugging, just feel free to continue. 46 | } 47 | void set_view_angles( vec3_t& angles ) { 48 | using original_fn = void( __thiscall* )( iv_engine_client*, vec3_t& ); 49 | return ( *( original_fn** ) this ) [ 19 ]( this, angles ); 50 | } 51 | vec3_t get_view_angles( ) { 52 | vec3_t temp; 53 | using original_fn = void( __thiscall* )( iv_engine_client*, vec3_t& ); 54 | ( *( original_fn** ) this ) [ 18 ]( this, temp ); 55 | return temp; 56 | } 57 | }; -------------------------------------------------------------------------------- /dependencies/interfaces/ivmodelinfo.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../source-sdk/structs/models.hpp" 3 | #include "../../source-sdk/classes/studio.hpp" 4 | 5 | class iv_model_info { 6 | public: 7 | model_t * get_model( int index ) { 8 | using original_fn = model_t * ( __thiscall* )( iv_model_info*, int ); 9 | return ( *( original_fn** ) this ) [ 1 ]( this, index ); 10 | } 11 | int get_model_index( const char* filename ) { 12 | using original_fn = int( __thiscall* )( iv_model_info*, const char* ); 13 | return ( *( original_fn** ) this ) [ 2 ]( this, filename ); 14 | } 15 | const char* get_model_name( const model_t* model ) { 16 | using original_fn = const char*( __thiscall* )( iv_model_info*, const model_t* ); 17 | return ( *( original_fn** ) this ) [ 3 ]( this, model ); 18 | } 19 | studio_hdr_t* get_studio_model( const model_t* model ) { 20 | using original_fn = studio_hdr_t * ( __thiscall* )( iv_model_info*, const model_t* ); 21 | return ( *( original_fn** ) this ) [ 32 ]( this, model ); 22 | } 23 | }; -------------------------------------------------------------------------------- /dependencies/interfaces/ivmodelrender.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../source-sdk/structs/materials.hpp" 3 | 4 | class iv_model_render { 5 | public: 6 | void override_material( i_material* material ) { 7 | using original_fn = void( __thiscall* )( iv_model_render*, i_material*, int, int ); 8 | return ( *( original_fn** ) this ) [ 1 ]( this, material, 0, 0 ); 9 | } 10 | }; -------------------------------------------------------------------------------- /dependencies/utilities/fnv.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class fnv_hash { 5 | private: 6 | struct wrapper { 7 | wrapper( const char* str ) : str( str ) { } 8 | const char* str; 9 | }; 10 | 11 | static const unsigned int prime = 16777619u; 12 | static const unsigned int basis = 2166136261u; 13 | 14 | template 15 | static constexpr unsigned int fnv_hash_const( const char( &str ) [ n ], unsigned int i = n ) { 16 | return i == 1 ? ( basis ^ str [ 0 ] ) * prime : ( fnv_hash_const( str, i - 1 ) ^ str [ i - 1 ] ) * prime; 17 | } 18 | static unsigned int hash( const char* str ) { 19 | const size_t length = strlen( str ) + 1; 20 | unsigned int hash = basis; 21 | 22 | for ( size_t i = 0; i < length; ++i ) { 23 | hash ^= *str++; 24 | hash *= prime; 25 | } 26 | 27 | return hash; 28 | } 29 | 30 | unsigned int hash_value; 31 | public: 32 | fnv_hash( wrapper wrap ) : hash_value( hash( wrap.str ) ) { } 33 | 34 | template 35 | constexpr fnv_hash( const char( &str ) [ n ] ) : hash_value( fnv_hash_const( str ) ) { } 36 | 37 | constexpr operator unsigned int( ) const { 38 | return this->hash_value; 39 | } 40 | }; -------------------------------------------------------------------------------- /dependencies/utilities/hook.cpp: -------------------------------------------------------------------------------- 1 | #include "hook.hpp" 2 | #include "../common_includes.hpp" 3 | 4 | void prop_hook::setup( recv_prop* prop ) { 5 | this->prop = prop; 6 | this->original_fn = prop->proxy_fn; 7 | } 8 | 9 | void prop_hook::swap( recv_var_proxy_fn new_proxy ) { 10 | this->prop->proxy_fn = new_proxy; 11 | } 12 | 13 | void prop_hook::release( ) { 14 | this->prop->proxy_fn = this->original_fn; 15 | } 16 | 17 | recv_var_proxy_fn prop_hook::get_original( ) { 18 | return this->original_fn; 19 | } 20 | 21 | /*Okay this is a word from Oneshot. This code is not all mine but it wasnt functional until i changed some stuff, if 22 | you wanna know what i changed then go and check the original code from exphck. This should be UD vmthooking 23 | but it might not be that stable because .data area*/ 24 | auto table_is_hooked(void* table, const char* module_table_dst) -> const bool { 25 | // Because of this probable check you can make a VEH Hook by forcing the pointer to 0 26 | if (table == nullptr) // Not initialized or invalid table to check 27 | return false; 28 | 29 | const auto module_base = GetModuleHandleA(module_table_dst); 30 | 31 | // Get module end 32 | const auto dos_header = reinterpret_cast< PIMAGE_DOS_HEADER > (module_base); 33 | const auto nt_headers = reinterpret_cast< PIMAGE_NT_HEADERS > (reinterpret_cast< std::uint8_t* >(module_base) + dos_header->e_lfanew); 34 | 35 | const auto module_end = reinterpret_cast< std::uintptr_t >(module_base) + nt_headers->OptionalHeader.SizeOfImage - sizeof(std::uintptr_t); 36 | 37 | const auto table_dst = *reinterpret_cast< std::uintptr_t* >(table); 38 | 39 | // Check the destination of the table, if the destination of the table is outside the region of the module, it is because it has been changed(hooked) 40 | return (table_dst < reinterpret_cast< std::uintptr_t >(module_base) || table_dst > module_end); 41 | } 42 | uintptr_t* vmt_hook::search_free_data_page(const char* module_name, const std::size_t vmt_size) //Modified code from exphck https://www.unknowncheats.me/forum/2128832-post43.html 43 | { 44 | auto check_data_section = [&] (LPCVOID address, const std::size_t vmt_size) { 45 | const DWORD DataProtection = (PAGE_EXECUTE_READWRITE | PAGE_READWRITE); 46 | MEMORY_BASIC_INFORMATION mbi = {0}; 47 | 48 | if (VirtualQuery(address, &mbi, sizeof(mbi)) == sizeof(mbi) && mbi.AllocationBase && mbi.BaseAddress && 49 | mbi.State == MEM_COMMIT && !(mbi.Protect & PAGE_GUARD) && mbi.Protect != PAGE_NOACCESS) { 50 | if ((mbi.Protect & DataProtection) && mbi.RegionSize >= vmt_size) { 51 | return ((mbi.Protect & DataProtection) && mbi.RegionSize >= vmt_size) ? true : false; 52 | } 53 | } 54 | return false; 55 | }; 56 | 57 | auto module_addr = GetModuleHandleA(module_name); 58 | 59 | if (module_addr == nullptr) 60 | return nullptr; 61 | 62 | const auto dos_header = reinterpret_cast< PIMAGE_DOS_HEADER > (module_addr); 63 | const auto nt_headers = reinterpret_cast< PIMAGE_NT_HEADERS > (reinterpret_cast< std::uint8_t* >(module_addr) + dos_header->e_lfanew); 64 | 65 | const auto module_end = reinterpret_cast< std::uintptr_t >(module_addr) + nt_headers->OptionalHeader.SizeOfImage - sizeof(std::uintptr_t); 66 | 67 | for (auto current_address = module_end; current_address > (DWORD) module_addr; current_address -= sizeof(std::uintptr_t)) { 68 | if (*reinterpret_cast< std::uintptr_t* >(current_address) == 0 && check_data_section(reinterpret_cast< LPCVOID >(current_address), vmt_size)) { 69 | bool is_good_vmt = true; 70 | auto page_count = 0u; 71 | 72 | for (; page_count < vmt_size && is_good_vmt; page_count += sizeof(std::uintptr_t)) { 73 | if (*reinterpret_cast< std::uintptr_t* >(current_address + page_count) != 0) 74 | is_good_vmt = false; 75 | } 76 | 77 | if (is_good_vmt && page_count >= vmt_size) 78 | return (uintptr_t*) current_address; 79 | } 80 | } 81 | return nullptr; 82 | } 83 | 84 | vmt_hook::vmt_hook() 85 | : class_base(nullptr), vftbl_len(0), new_vftb1(nullptr), old_vftbl(nullptr) { 86 | } 87 | vmt_hook::vmt_hook(void* base) 88 | : class_base(base), vftbl_len(0), new_vftb1(nullptr), old_vftbl(nullptr) { 89 | } 90 | vmt_hook::~vmt_hook() { 91 | release(); 92 | if (was_allocated) 93 | delete[] new_vftb1; 94 | } 95 | 96 | bool vmt_hook::setup(void* base, const char * module_name) { 97 | if (base != nullptr) 98 | class_base = base; 99 | 100 | if (class_base == nullptr) 101 | return false; 102 | 103 | old_vftbl = *(std::uintptr_t**)class_base; 104 | vftbl_len = estimate_vftbl_length(old_vftbl) * sizeof(std::uintptr_t); 105 | 106 | if (vftbl_len == 0) 107 | return false; 108 | 109 | 110 | if (module_name)// If provided a module name then we will find a place in that module 111 | { 112 | new_vftb1 = search_free_data_page(module_name, vftbl_len + sizeof(std::uintptr_t)); 113 | std::memset(new_vftb1, NULL, vftbl_len + sizeof(std::uintptr_t)); 114 | std::memcpy(&new_vftb1[1], old_vftbl, vftbl_len); 115 | new_vftb1[0] = old_vftbl[-1]; 116 | try { 117 | auto guard = detail::protect_guard {class_base, sizeof(std::uintptr_t), PAGE_READWRITE}; 118 | 119 | *(std::uintptr_t**)class_base = &new_vftb1[1]; 120 | was_allocated = false; 121 | if (table_is_hooked(base, module_name)) { 122 | Beep(500, 500); 123 | } 124 | } catch (...) { 125 | delete[] new_vftb1; 126 | return false; 127 | } 128 | } else // If not then we do regular vmthookinh 129 | { 130 | new_vftb1 = new std::uintptr_t[vftbl_len + 1](); 131 | std::memcpy(&new_vftb1[1], old_vftbl, vftbl_len); 132 | try { 133 | auto guard = detail::protect_guard {class_base, sizeof(std::uintptr_t), PAGE_READWRITE}; 134 | new_vftb1[0] = old_vftbl[-1]; 135 | *(std::uintptr_t**)class_base = &new_vftb1[1]; 136 | was_allocated = true; 137 | } catch (...) { 138 | delete[] new_vftb1; 139 | return false; 140 | } 141 | } 142 | 143 | 144 | return true; 145 | } 146 | 147 | std::size_t vmt_hook::estimate_vftbl_length(std::uintptr_t* vftbl_start) { 148 | MEMORY_BASIC_INFORMATION memInfo = {NULL}; 149 | int m_nSize = -1; 150 | do { 151 | m_nSize++; 152 | VirtualQuery(reinterpret_cast(vftbl_start[m_nSize]), &memInfo, sizeof(memInfo)); 153 | 154 | } while (memInfo.Protect == PAGE_EXECUTE_READ || memInfo.Protect == PAGE_EXECUTE_READWRITE); 155 | 156 | return m_nSize; 157 | } 158 | 159 | void vmt_hook::hook_index( size_t fn_index, void* fn_pointer ) { 160 | assert(fn_index >= 0 && fn_index <= (int) vftbl_len); 161 | new_vftb1[fn_index + 1] = reinterpret_cast(fn_pointer); 162 | } 163 | 164 | void vmt_hook::release( ) { 165 | try { 166 | if (old_vftbl != nullptr) { 167 | auto guard = detail::protect_guard {class_base, sizeof(std::uintptr_t), PAGE_READWRITE}; 168 | *(std::uintptr_t**)class_base = old_vftbl; 169 | old_vftbl = nullptr; 170 | } 171 | } catch (...) { 172 | } 173 | } 174 | 175 | void* vmt_hook::get_original( size_t fn_index ) { 176 | return reinterpret_cast< void* >(old_vftbl[fn_index]); 177 | } -------------------------------------------------------------------------------- /dependencies/utilities/hook.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "../../source-sdk/classes/client_class.hpp" 4 | #define NOMINMAX 5 | #include 6 | #include 7 | #include 8 | 9 | namespace detail { 10 | class protect_guard { 11 | public: 12 | protect_guard(void* base, size_t len, std::uint32_t flags) { 13 | _base = base; 14 | _length = len; 15 | if (!VirtualProtect(base, len, flags, (PDWORD) &_old)) 16 | throw std::runtime_error("failed to protect region."); 17 | } 18 | ~protect_guard() { 19 | VirtualProtect(_base, _length, _old, (PDWORD) &_old); 20 | } 21 | 22 | private: 23 | void* _base; 24 | size_t _length; 25 | std::uint32_t _old; 26 | }; 27 | } 28 | 29 | class prop_hook { 30 | private: 31 | recv_var_proxy_fn original_fn; 32 | recv_prop* prop; 33 | 34 | public: 35 | void setup( recv_prop* prop ); 36 | void swap( recv_var_proxy_fn new_proxy ); 37 | void release( ); 38 | recv_var_proxy_fn get_original( ); 39 | }; 40 | 41 | class vmt_hook { 42 | private: 43 | static inline std::size_t estimate_vftbl_length(std::uintptr_t* vftbl_start); 44 | 45 | void* class_base; 46 | std::size_t vftbl_len; 47 | std::uintptr_t* new_vftb1; 48 | std::uintptr_t* old_vftbl; 49 | LPCVOID search_base = nullptr; 50 | bool was_allocated = false; 51 | 52 | public: 53 | uintptr_t * search_free_data_page(const char * module_name, const std::size_t vmt_size); 54 | vmt_hook(); 55 | vmt_hook(void* base); 56 | ~vmt_hook(); 57 | 58 | bool setup(void * base, const char * module_name = nullptr); 59 | 60 | void hook_index( size_t fn_index, void* fn_pointer ); 61 | void release( ); 62 | 63 | void* get_original( size_t fn_index ); 64 | }; -------------------------------------------------------------------------------- /dependencies/utilities/netvars.cpp: -------------------------------------------------------------------------------- 1 | #include "netvars.hpp" 2 | #include 3 | #include 4 | 5 | netvar_manager g_netvar_mgr; 6 | 7 | void netvar_manager::dump_table_recursive( recv_table* table ) { 8 | for ( auto i = 0; i < table->props_count; ++i ) { 9 | auto prop = &table->props [ i ]; 10 | 11 | if ( !prop || isdigit( prop->prop_name [ 0 ] ) ) 12 | continue; 13 | if ( strcmp( prop->prop_name, "baseclass" ) == 0 ) 14 | continue; 15 | 16 | if ( prop->prop_type == send_prop_type::_data_table && prop->data_table != nullptr && prop->data_table->table_name [ 0 ] == 'D' ) { 17 | dump_table_recursive( prop->data_table ); 18 | } 19 | 20 | std::string hash_string = table->table_name; 21 | hash_string.append( "->" ); 22 | hash_string.append( prop->prop_name ); 23 | 24 | netvars_map [ fnv_hash( hash_string.c_str( ) ) ] = prop; 25 | } 26 | } 27 | 28 | void netvar_manager::dump_table_to_file_recursive( recv_table* table, std::ofstream& file ) { 29 | for ( auto i = 0; i < table->props_count; ++i ) { 30 | auto prop = &table->props [ i ]; 31 | 32 | if ( !prop || isdigit( prop->prop_name [ 0 ] ) ) 33 | continue; 34 | if ( strcmp( prop->prop_name, "baseclass" ) == 0 ) 35 | continue; 36 | 37 | if ( prop->prop_type == send_prop_type::_data_table && prop->data_table != nullptr && prop->data_table->table_name [ 0 ] == 'D' ) { 38 | dump_table_to_file_recursive( prop->data_table, file ); 39 | } 40 | 41 | std::string hash_string = table->table_name; 42 | hash_string.append( " -> " ); 43 | hash_string.append( prop->prop_name ); 44 | 45 | auto hash = fnv_hash( hash_string.c_str( ) ); 46 | 47 | hash_string.append( " (" ); 48 | hash_string.append( std::to_string( unsigned int( hash ) ) ); 49 | hash_string.append( ") [" ); 50 | std::stringstream stream; 51 | stream << "0x" 52 | << std::setfill( '0' ) << std::setw( sizeof( int ) * 2 ) 53 | << std::hex << prop->offset; 54 | hash_string.append( stream.str( ) ); 55 | hash_string.append( "]" ); 56 | 57 | file << hash_string << std::endl; 58 | } 59 | } 60 | 61 | void netvar_manager::initialize( client_class* client_data ) { 62 | for ( auto data = client_data; data; data = data->next_ptr ) { 63 | if ( data->recvtable_ptr ) { 64 | dump_table_recursive( data->recvtable_ptr ); 65 | } 66 | } 67 | } 68 | 69 | void netvar_manager::dump_netvars( client_class* client_data ) { 70 | std::ofstream output( "netvars_dump.txt" ); 71 | 72 | for ( auto data = client_data; data; data = data->next_ptr ) { 73 | if ( data->recvtable_ptr ) { 74 | dump_table_to_file_recursive( data->recvtable_ptr, output ); 75 | } 76 | } 77 | } 78 | 79 | unsigned short netvar_manager::get_offset( unsigned int hash ) { 80 | if ( !netvars_map [ hash ] ) return 0; 81 | return netvars_map [ hash ]->offset; 82 | } 83 | 84 | recv_prop* netvar_manager::get_prop( unsigned int hash ) { 85 | return netvars_map [ hash ]; 86 | } -------------------------------------------------------------------------------- /dependencies/utilities/netvars.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "fnv.hpp" 3 | 4 | #include "../../source-sdk/classes/recv_props.hpp" 5 | #include "../../source-sdk/classes/client_class.hpp" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class netvar_manager { 13 | private: 14 | std::map netvars_map; 15 | void dump_table_recursive( recv_table* table ); 16 | void dump_table_to_file_recursive( recv_table* table, std::ofstream& file ); 17 | 18 | public: 19 | void initialize( client_class* client_data ); 20 | void dump_netvars( client_class* client_data ); 21 | 22 | unsigned short get_offset( unsigned int hash ); 23 | recv_prop* get_prop( unsigned int hash ); 24 | }; 25 | 26 | extern netvar_manager g_netvar_mgr; 27 | 28 | #define offset_fn(type, var, offset) \ 29 | type& var() { \ 30 | return *(type*)(uintptr_t(this) + offset); \ 31 | } \ 32 | 33 | #define netvar_fn(type, var, hash) \ 34 | type& var() { \ 35 | static auto _offset = g_netvar_mgr.get_offset(fnv_hash(hash)); \ 36 | return *(type*)(uintptr_t(this) + _offset); \ 37 | } \ 38 | 39 | #define netvar_ptr_fn(type, var, hash) \ 40 | type* var() { \ 41 | static auto _offset = g_netvar_mgr.get_offset(fnv_hash(hash)); \ 42 | return (type*)(uintptr_t(this) + _offset); \ 43 | } \ 44 | 45 | #define netvar_offset_fn(type, var, hash, offset) \ 46 | type& var() { \ 47 | static auto _offset = g_netvar_mgr.get_offset(fnv_hash(hash)); \ 48 | return *(type*)(uintptr_t(this) + _offset + offset); \ 49 | } \ 50 | 51 | #define netvar_original(type, var, offset) \ 52 | type& var() { \ 53 | return *(type*)(uintptr_t(this) + offset); \ 54 | } \ -------------------------------------------------------------------------------- /dependencies/utilities/render.cpp: -------------------------------------------------------------------------------- 1 | #include "render.hpp" 2 | 3 | unsigned long render::main_font; 4 | 5 | void render::setup_fonts() { 6 | main_font = interfaces::surface->font_create(); 7 | 8 | interfaces::surface->set_font_glyph(main_font, "Tahoma", 12, 500, 0, 0, font_flags::fontflag_outline); 9 | } 10 | 11 | void render::line(int x, int y, int x2, int y2, color c) noexcept { 12 | interfaces::surface->set_drawing_color(c.r, c.g, c.b, c.a); 13 | interfaces::surface->draw_line(x, y, x2, y2); 14 | } 15 | 16 | void render::rect(int x, int y, int x2, int y2, color c) noexcept { 17 | interfaces::surface->set_drawing_color(c.r, c.g, c.b, c.a); 18 | interfaces::surface->draw_outlined_rect(x, y, x2, y2); 19 | } 20 | 21 | void render::filled_rect(int x, int y, int x2, int y2, color c) noexcept { 22 | interfaces::surface->set_drawing_color(c.r, c.g, c.b, c.a); 23 | interfaces::surface->draw_filled_rectangle(x, y, x2, y2); 24 | } 25 | 26 | void render::text(int x, int y, color color, int font, bool center, std::string str) noexcept { 27 | std::wstring text = std::wstring(str.begin(), str.end()); 28 | const wchar_t* converted_text = text.c_str(); 29 | 30 | int width, height; 31 | interfaces::surface->get_text_size(font, converted_text, width, height); 32 | 33 | interfaces::surface->set_text_color(color.r, color.g, color.b, color.a); 34 | interfaces::surface->draw_text_font(font); 35 | if (center) 36 | interfaces::surface->draw_text_pos(x - (width / 2), y); 37 | else 38 | interfaces::surface->draw_text_pos(x, y); 39 | 40 | interfaces::surface->draw_render_text(converted_text, wcslen(converted_text)); 41 | } 42 | 43 | void render::get_text_size(unsigned long font, std::string str, int& width, int& height) noexcept { 44 | std::wstring text = std::wstring(str.begin(), str.end()); 45 | const wchar_t* out = text.c_str(); 46 | 47 | interfaces::surface->get_text_size(font, out, width, height); 48 | } 49 | 50 | float render::get_frametime() noexcept { 51 | return interfaces::globals->frame_time; 52 | } -------------------------------------------------------------------------------- /dependencies/utilities/render.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "../interfaces/interfaces.hpp" 4 | #include "..//..//source-sdk/misc/color.hpp" 5 | 6 | namespace render { 7 | enum font_flags { 8 | fontflag_none, 9 | fontflag_italic = 0x001, 10 | fontflag_underline = 0x002, 11 | fontflag_strikeout = 0x004, 12 | fontflag_symbol = 0x008, 13 | fontflag_antialias = 0x010, 14 | fontflag_gaussianblur = 0x020, 15 | fontflag_rotary = 0x040, 16 | fontflag_dropshadow = 0x080, 17 | fontflag_additive = 0x100, 18 | fontflag_outline = 0x200, 19 | fontflag_custom = 0x400, 20 | fontflag_bitmap = 0x800, 21 | }; 22 | 23 | extern unsigned long main_font; 24 | 25 | void setup_fonts(); 26 | 27 | void line(int x, int y, int x2, int y2, color c) noexcept; 28 | void rect(int x, int y, int x2, int y2, color c) noexcept; 29 | void filled_rect(int x, int y, int x2, int y2, color c) noexcept; 30 | void text(int x, int y, color color, int font, bool center, std::string str) noexcept; 31 | void get_text_size(unsigned long font, std::string str, int& width, int& height) noexcept; 32 | float get_frametime() noexcept; 33 | }; -------------------------------------------------------------------------------- /dependencies/utilities/utilities.cpp: -------------------------------------------------------------------------------- 1 | #include "utilities.hpp" 2 | #include "../common_includes.hpp" 3 | #include 4 | 5 | std::uint8_t* utilities::pattern_scan( void* module, const char* signature ) { 6 | static auto pattern_to_byte = [ ] ( const char* pattern ) { 7 | auto bytes = std::vector {}; 8 | auto start = const_cast< char* >( pattern ); 9 | auto end = const_cast< char* >( pattern ) + strlen( pattern ); 10 | 11 | for ( auto current = start; current < end; ++current ) { 12 | if ( *current == '?' ) { 13 | ++current; 14 | if ( *current == '?' ) 15 | ++current; 16 | bytes.push_back( -1 ); 17 | } 18 | else { 19 | bytes.push_back( strtoul( current, ¤t, 16 ) ); 20 | } 21 | } 22 | return bytes; 23 | }; 24 | 25 | auto dos_headers = ( PIMAGE_DOS_HEADER ) module; 26 | auto nt_headers = ( PIMAGE_NT_HEADERS ) ( ( std::uint8_t* )module + dos_headers->e_lfanew ); 27 | 28 | auto size_of_image = nt_headers->OptionalHeader.SizeOfImage; 29 | auto pattern_bytes = pattern_to_byte( signature ); 30 | auto scan_bytes = reinterpret_cast< std::uint8_t* >( module ); 31 | 32 | auto s = pattern_bytes.size( ); 33 | auto d = pattern_bytes.data( ); 34 | 35 | for ( auto i = 0ul; i < size_of_image - s; ++i ) { 36 | bool found = true; 37 | for ( auto j = 0ul; j < s; ++j ) { 38 | if (scan_bytes[ i + j ] != d [ j ] && d [ j ] != -1 ) { 39 | found = false; 40 | break; 41 | } 42 | } 43 | if ( found ) { 44 | return &scan_bytes[ i ]; 45 | } 46 | } 47 | return nullptr; 48 | } 49 | 50 | void* utilities::game::capture_interface( const char* mod, const char* iface ) { 51 | using fn_capture_iface_t = void*( *)( const char*, int* ); 52 | auto fn_addr = ( fn_capture_iface_t ) GetProcAddress( GetModuleHandleA( mod ), "CreateInterface" ); 53 | 54 | auto iface_addr = fn_addr( iface, nullptr ); 55 | printf( "found %s at 0x%p\n", iface, fn_addr( iface, nullptr ) ); 56 | 57 | return iface_addr; 58 | } 59 | -------------------------------------------------------------------------------- /dependencies/utilities/utilities.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "../../source-sdk/math/vector3d.hpp" 4 | 5 | #define M_PI 3.14159265358979323846 6 | 7 | namespace utilities { 8 | namespace math { 9 | template t clamp_value( t value, t min, t max ) { 10 | if ( value > max ) { 11 | return max; 12 | } 13 | if ( value < min ) { 14 | return min; 15 | } 16 | return value; 17 | } 18 | } 19 | namespace game { 20 | void* capture_interface( const char* mod, const char* iface ); 21 | } 22 | std::uint8_t* pattern_scan( void* module, const char* signature ); 23 | } -------------------------------------------------------------------------------- /source-sdk/classes/c_usercmd.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum cmd_buttons { 4 | in_attack = ( 1 << 0 ), 5 | in_jump = ( 1 << 1 ), 6 | in_duck = ( 1 << 2 ), 7 | in_forward = ( 1 << 3 ), 8 | in_back = ( 1 << 4 ), 9 | in_use = ( 1 << 5 ), 10 | in_cancel = ( 1 << 6 ), 11 | in_left = ( 1 << 7 ), 12 | in_right = ( 1 << 8 ), 13 | in_moveleft = ( 1 << 9 ), 14 | in_moveright = ( 1 << 10 ), 15 | in_attack2 = ( 1 << 11 ), 16 | in_run = ( 1 << 12 ), 17 | in_reload = ( 1 << 13 ), 18 | in_alt1 = ( 1 << 14 ), 19 | in_alt2 = ( 1 << 15 ), 20 | in_score = ( 1 << 16 ), 21 | in_speed = ( 1 << 17 ), 22 | in_walk = ( 1 << 18 ), 23 | in_zoom = ( 1 << 19 ), 24 | in_weapon1 = ( 1 << 20 ), 25 | in_weapon2 = ( 1 << 21 ), 26 | in_bullrush = ( 1 << 22 ), 27 | in_grenade1 = ( 1 << 23 ), 28 | in_grenade2 = ( 1 << 24 ), 29 | in_attack3 = ( 1 << 25 ) 30 | }; 31 | 32 | class c_usercmd { 33 | public: 34 | c_usercmd( ) { }; 35 | virtual ~c_usercmd( ) { }; 36 | 37 | int command_number; 38 | int tick_count; 39 | vec3_t view_angles; 40 | vec3_t aim_direction; 41 | float forward_move; 42 | float side_move; 43 | float up_move; 44 | int buttons; 45 | unsigned char impulse; 46 | int weapon_select; 47 | int weapon_subtype; 48 | int random_seed; 49 | short mouse_dx; 50 | short mouse_dy; 51 | bool has_been_predicted; 52 | char pad_0x4c [ 0x18 ]; 53 | }; -------------------------------------------------------------------------------- /source-sdk/classes/client_class.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "recv_props.hpp" 3 | 4 | class client_class; 5 | class i_client_networkable; 6 | 7 | typedef i_client_networkable* ( *create_client_class_fn )( int ent_number, int serial_number ); 8 | typedef i_client_networkable* ( *create_event_fn )( ); 9 | 10 | enum class_ids { 11 | ctesttraceline = 196, 12 | cteworlddecal = 197, 13 | ctespritespray = 194, 14 | ctesprite = 193, 15 | ctesparks = 192, 16 | ctesmoke = 191, 17 | cteshowline = 189, 18 | cteprojecteddecal = 186, 19 | cfeplayerdecal = 61, 20 | cteplayerdecal = 185, 21 | ctephysicsprop = 182, 22 | cteparticlesystem = 181, 23 | ctemuzzleflash = 180, 24 | ctelargefunnel = 178, 25 | ctekillplayerattachments = 177, 26 | cteimpact = 176, 27 | cteglowsprite = 175, 28 | cteshattersurface = 188, 29 | ctefootprintdecal = 172, 30 | ctefizz = 171, 31 | cteexplosion = 169, 32 | cteenergysplash = 168, 33 | cteeffectdispatch = 167, 34 | ctedynamiclight = 166, 35 | ctedecal = 164, 36 | cteclientprojectile = 163, 37 | ctebubbletrail = 162, 38 | ctebubbles = 161, 39 | ctebspdecal = 160, 40 | ctebreakmodel = 159, 41 | ctebloodstream = 158, 42 | ctebloodsprite = 157, 43 | ctebeamspline = 156, 44 | ctebeamringpoint = 155, 45 | ctebeamring = 154, 46 | ctebeampoints = 153, 47 | ctebeamlaser = 152, 48 | ctebeamfollow = 151, 49 | ctebeaments = 150, 50 | ctebeamentpoint = 149, 51 | ctebasebeam = 148, 52 | ctearmorricochet = 147, 53 | ctemetalsparks = 179, 54 | csteamjet = 142, 55 | csmokestack = 135, 56 | dusttrail = 246, 57 | cfiretrail = 64, 58 | sporetrail = 252, 59 | sporeexplosion = 251, 60 | rockettrail = 249, 61 | smoketrail = 250, 62 | cpropvehicledriveable = 122, 63 | particlesmokegrenade = 248, 64 | cparticlefire = 100, 65 | movieexplosion = 247, 66 | ctegaussexplosion = 174, 67 | cenvquadraticbeam = 56, 68 | cembers = 46, 69 | cenvwind = 60, 70 | cprecipitation = 116, 71 | cprecipitationblocker = 117, 72 | cbasetempentity = 18, 73 | nextbotcombatcharacter = 0, 74 | ceconwearable = 45, 75 | cbaseattributableitem = 4, 76 | ceconentity = 44, 77 | cweaponxm1014 = 244, 78 | cweapontaser = 239, 79 | csmokegrenade = 133, 80 | cweaponsg552 = 236, 81 | csensorgrenade = 129, 82 | cweaponsawedoff = 232, 83 | cweaponnova = 228, 84 | cincendiarygrenade = 87, 85 | cmolotovgrenade = 97, 86 | cweaponm3 = 220, 87 | cknifegg = 94, 88 | cknife = 93, 89 | chegrenade = 84, 90 | cflashbang = 66, 91 | cweaponelite = 211, 92 | cdecoygrenade = 40, 93 | cdeagle = 39, 94 | cweaponusp = 243, 95 | cweaponm249 = 219, 96 | cweaponump45 = 242, 97 | cweapontmp = 241, 98 | cweapontec9 = 240, 99 | cweaponssg08 = 238, 100 | cweaponsg556 = 237, 101 | cweaponsg550 = 235, 102 | cweaponscout = 234, 103 | cweaponscar20 = 233, 104 | cscar17 = 127, 105 | cweaponp90 = 231, 106 | cweaponp250 = 230, 107 | cweaponp228 = 229, 108 | cweaponnegev = 227, 109 | cweaponmp9 = 226, 110 | cweaponmp7 = 225, 111 | cweaponmp5navy = 224, 112 | cweaponmag7 = 223, 113 | cweaponmac10 = 222, 114 | cweaponm4a1 = 221, 115 | cweaponhkp2000 = 218, 116 | cweaponglock = 217, 117 | cweapongalilar = 216, 118 | cweapongalil = 215, 119 | cweapong3sg1 = 214, 120 | cweaponfiveseven = 213, 121 | cweaponfamas = 212, 122 | cweaponbizon = 207, 123 | cweaponawp = 205, 124 | cweaponaug = 204, 125 | cak47 = 1, 126 | cweaponcsbasegun = 209, 127 | cweaponcsbase = 208, 128 | cc4 = 29, 129 | cweaponbaseitem = 206, 130 | cbasecsgrenade = 8, 131 | csmokegrenadeprojectile = 134, 132 | csensorgrenadeprojectile = 130, 133 | cmolotovprojectile = 98, 134 | citem_healthshot = 91, 135 | citemdogtags = 92, 136 | cdecoyprojectile = 41, 137 | cfirecrackerblast = 62, 138 | cinferno = 88, 139 | cchicken = 31, 140 | cfootstepcontrol = 68, 141 | ccsgamerulesproxy = 34, 142 | cweaponcubemap = 0, 143 | cweaponcycler = 210, 144 | cteplantbomb = 183, 145 | ctefirebullets = 170, 146 | cteradioicon = 187, 147 | cplantedc4 = 108, 148 | ccsteam = 38, 149 | ccsplayerresource = 36, 150 | ccsplayer = 35, 151 | ccsragdoll = 37, 152 | cteplayeranimevent = 184, 153 | chostage = 85, 154 | chostagecarriableprop = 86, 155 | cbasecsgrenadeprojectile = 9, 156 | chandletest = 83, 157 | cteamplayroundbasedrulesproxy = 146, 158 | cspritetrail = 140, 159 | cspriteoriented = 139, 160 | csprite = 138, 161 | cragdollpropattached = 125, 162 | cragdollprop = 124, 163 | cpredictedviewmodel = 118, 164 | cposecontroller = 114, 165 | cgamerulesproxy = 82, 166 | cinfoladderdismount = 89, 167 | cfuncladder = 74, 168 | ctefoundryhelpers = 173, 169 | cenvdetailcontroller = 52, 170 | cworld = 245, 171 | cwaterlodcontrol = 203, 172 | cwaterbullet = 202, 173 | cvotecontroller = 201, 174 | cvguiscreen = 200, 175 | cpropjeep = 121, 176 | cpropvehiclechoreogeneric = 0, 177 | ctriggersoundoperator = 199, 178 | cbasevphysicstrigger = 22, 179 | ctriggerplayermovement = 198, 180 | cbasetrigger = 20, 181 | ctest_proxytoggle_networkable = 195, 182 | ctesla = 190, 183 | cbaseteamobjectiveresource = 17, 184 | cteam = 145, 185 | csunlightshadowcontrol = 144, 186 | csun = 143, 187 | cparticleperformancemonitor = 101, 188 | cspotlightend = 137, 189 | cspatialentity = 136, 190 | cslideshowdisplay = 132, 191 | cshadowcontrol = 131, 192 | csceneentity = 128, 193 | cropekeyframe = 126, 194 | cragdollmanager = 123, 195 | cphysicspropmultiplayer = 106, 196 | cphysboxmultiplayer = 104, 197 | cpropdoorrotating = 120, 198 | cbasepropdoor = 16, 199 | cdynamicprop = 43, 200 | cprop_hallucination = 119, 201 | cpostprocesscontroller = 115, 202 | cpointworldtext = 113, 203 | cpointcommentarynode = 112, 204 | cpointcamera = 111, 205 | cplayerresource = 110, 206 | cplasma = 109, 207 | cphysmagnet = 107, 208 | cphysicsprop = 105, 209 | cstatueprop = 141, 210 | cphysbox = 103, 211 | cparticlesystem = 102, 212 | cmoviedisplay = 99, 213 | cmaterialmodifycontrol = 96, 214 | clightglow = 95, 215 | citemassaultsuituseable = 0, 216 | citem = 0, 217 | cinfooverlayaccessor = 90, 218 | cfunctracktrain = 81, 219 | cfuncsmokevolume = 80, 220 | cfuncrotating = 79, 221 | cfuncreflectiveglass = 78, 222 | cfuncoccluder = 77, 223 | cfuncmovelinear = 76, 224 | cfuncmonitor = 75, 225 | cfunc_lod = 70, 226 | ctedust = 165, 227 | cfunc_dust = 69, 228 | cfuncconveyor = 73, 229 | cfuncbrush = 72, 230 | cbreakablesurface = 28, 231 | cfuncareaportalwindow = 71, 232 | cfish = 65, 233 | cfiresmoke = 63, 234 | cenvtonemapcontroller = 59, 235 | cenvscreeneffect = 57, 236 | cenvscreenoverlay = 58, 237 | cenvprojectedtexture = 55, 238 | cenvparticlescript = 54, 239 | cfogcontroller = 67, 240 | cenvdofcontroller = 53, 241 | ccascadelight = 30, 242 | cenvambientlight = 51, 243 | centityparticletrail = 50, 244 | centityfreezing = 49, 245 | centityflame = 48, 246 | centitydissolve = 47, 247 | cdynamiclight = 42, 248 | ccolorcorrectionvolume = 33, 249 | ccolorcorrection = 32, 250 | cbreakableprop = 27, 251 | cbeamspotlight = 25, 252 | cbasebutton = 5, 253 | cbasetoggle = 19, 254 | cbaseplayer = 15, 255 | cbaseflex = 12, 256 | cbaseentity = 11, 257 | cbasedoor = 10, 258 | cbasecombatcharacter = 6, 259 | cbaseanimatingoverlay = 3, 260 | cbonefollower = 26, 261 | cbaseanimating = 2, 262 | cai_basenpc = 0, 263 | cbeam = 24, 264 | cbaseviewmodel = 21, 265 | cbaseparticleentity = 14, 266 | cbasegrenade = 13, 267 | cbasecombatweapon = 7, 268 | cbaseweaponworldmodel = 23 269 | }; 270 | 271 | class client_class { 272 | public: 273 | create_client_class_fn create_fn; 274 | create_event_fn create_event_fn; 275 | char* network_name; 276 | recv_table* recvtable_ptr; 277 | client_class* next_ptr; 278 | class_ids class_id; 279 | }; -------------------------------------------------------------------------------- /source-sdk/classes/collideable.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class collideable_t { 4 | public: 5 | vec3_t & mins( ) { 6 | using original_fn = vec3_t & ( __thiscall* )( void* ); 7 | return ( *( original_fn** ) this ) [ 1 ]( this ); 8 | } 9 | vec3_t& maxs( ) { 10 | using original_fn = vec3_t & ( __thiscall* )( void* ); 11 | return ( *( original_fn** ) this ) [ 2 ]( this ); 12 | } 13 | }; -------------------------------------------------------------------------------- /source-sdk/classes/convar.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class convar; 5 | using fn_change_callback_t = void( *)( convar* var, const char* pOldValue, float flOldValue ); 6 | 7 | inline int UtlMemory_CalcNewAllocationCount( int nAllocationCount, int nGrowSize, int nNewSize, int nBytesItem ) { 8 | if ( nGrowSize ) 9 | nAllocationCount = ( ( 1 + ( ( nNewSize - 1 ) / nGrowSize ) ) * nGrowSize ); 10 | else { 11 | if ( !nAllocationCount ) 12 | nAllocationCount = ( 31 + nBytesItem ) / nBytesItem; 13 | 14 | while ( nAllocationCount < nNewSize ) 15 | nAllocationCount *= 2; 16 | } 17 | 18 | return nAllocationCount; 19 | } 20 | 21 | template< class T, class I = int > 22 | class CUtlMemory { 23 | public: 24 | T & operator[]( I i ) { 25 | return m_pMemory [ i ]; 26 | } 27 | 28 | T* Base( ) { 29 | return m_pMemory; 30 | } 31 | 32 | int NumAllocated( ) const { 33 | return m_nAllocationCount; 34 | } 35 | 36 | bool IsExternallyAllocated( ) const { 37 | return m_nGrowSize < 0; 38 | } 39 | 40 | protected: 41 | T * m_pMemory; 42 | int m_nAllocationCount; 43 | int m_nGrowSize; 44 | }; 45 | 46 | template 47 | inline T* Construct( T* pMemory ) { 48 | return ::new( pMemory ) T; 49 | } 50 | 51 | template 52 | inline void Destruct( T* pMemory ) { 53 | pMemory->~T( ); 54 | } 55 | 56 | template< class T, class A = CUtlMemory > 57 | class CUtlVector { 58 | typedef A CAllocator; 59 | public: 60 | T & operator[]( int i ) { 61 | return m_Memory [ i ]; 62 | } 63 | 64 | T& Element( int i ) { 65 | return m_Memory [ i ]; 66 | } 67 | 68 | T* Base( ) { 69 | return m_Memory.Base( ); 70 | } 71 | 72 | int Count( ) const { 73 | return m_Size; 74 | } 75 | 76 | void RemoveAll( ) { 77 | for ( int i = m_Size; --i >= 0; ) 78 | Destruct( &Element( i ) ); 79 | 80 | m_Size = 0; 81 | } 82 | 83 | int AddToTail( ) { 84 | return InsertBefore( m_Size ); 85 | } 86 | 87 | void SetSize( int size ) { 88 | m_Size = size; 89 | } 90 | 91 | int InsertBefore( int elem ) { 92 | GrowVector( ); 93 | ShiftElementsRight( elem ); 94 | Construct( &Element( elem ) ); 95 | 96 | return elem; 97 | } 98 | 99 | protected: 100 | void GrowVector( int num = 1 ) { 101 | if ( m_Size + num > m_Memory.NumAllocated( ) ) 102 | m_Memory.Grow( m_Size + num - m_Memory.NumAllocated( ) ); 103 | 104 | m_Size += num; 105 | ResetDbgInfo( ); 106 | } 107 | 108 | void ShiftElementsRight( int elem, int num = 1 ) { 109 | int numToMove = m_Size - elem - num; 110 | if ( ( numToMove > 0 ) && ( num > 0 ) ) 111 | memmove( &Element( elem + num ), &Element( elem ), numToMove * sizeof( T ) ); 112 | } 113 | 114 | CAllocator m_Memory; 115 | int m_Size; 116 | 117 | T* m_pElements; 118 | 119 | inline void ResetDbgInfo( ) { 120 | m_pElements = Base( ); 121 | } 122 | }; 123 | 124 | enum cvar_flags { 125 | fcvar_none = 0, 126 | fcvar_unregistered = ( 1 << 0 ), 127 | fcvar_developmentonly = ( 1 << 1 ), 128 | fcvar_gamedll = ( 1 << 2 ), 129 | fcvar_clientdll = ( 1 << 3 ), 130 | fcvar_hidden = ( 1 << 4 ), 131 | fcvar_protected = ( 1 << 5 ), 132 | fcvar_sponly = ( 1 << 6 ), 133 | fcvar_archive = ( 1 << 7 ), 134 | fcvar_notify = ( 1 << 8 ), 135 | fcvar_userinfo = ( 1 << 9 ), 136 | fcvar_printableonly = ( 1 << 10 ), 137 | fcvar_unlogged = ( 1 << 11 ), 138 | fcvar_never_as_string = ( 1 << 12 ), 139 | fcvar_replicated = ( 1 << 13 ), 140 | fcvar_cheat = ( 1 << 14 ), 141 | fcvar_ss = ( 1 << 15 ), 142 | fcvar_demo = ( 1 << 16 ), 143 | fcvar_dontrecord = ( 1 << 17 ), 144 | fcvar_ss_added = ( 1 << 18 ), 145 | fcvar_release = ( 1 << 19 ), 146 | fcvar_reload_materials = ( 1 << 20 ), 147 | fcvar_reload_textures = ( 1 << 21 ), 148 | fcvar_not_connected = ( 1 << 22 ), 149 | fcvar_material_system_thread = ( 1 << 23 ), 150 | fcvar_archive_xbox = ( 1 << 24 ), 151 | fcvar_accessible_from_threads = ( 1 << 25 ), 152 | fcvar_server_can_execute = ( 1 << 28 ), 153 | fcvar_server_cannot_query = ( 1 << 29 ), 154 | fcvar_clientcmd_can_execute = ( 1 << 30 ), 155 | fcvar_meme_dll = ( 1 << 31 ), 156 | fcvar_material_thread_mask = ( fcvar_reload_materials | fcvar_reload_textures | fcvar_material_system_thread ) 157 | }; 158 | 159 | class convar { 160 | public: 161 | void set_value( const char* value ) { 162 | using original_fn = void( __thiscall* )( convar*, const char* ); 163 | return ( *( original_fn** ) this ) [ 14 ]( this, value ); 164 | } 165 | void set_value( float value ) { 166 | using original_fn = void( __thiscall* )( convar*, float ); 167 | return ( *( original_fn** ) this ) [ 15 ]( this, value ); 168 | } 169 | void set_value( int value ) { 170 | using original_fn = void( __thiscall* )( convar*, int ); 171 | return ( *( original_fn** ) this ) [ 16 ]( this, value ); 172 | } 173 | void set_value( bool value ) { 174 | using original_fn = void( __thiscall* )( convar*, int ); 175 | return ( *( original_fn** ) this ) [ 16 ]( this, static_cast< int >( value ) ); 176 | } 177 | 178 | private: 179 | char pad_0x0000 [ 0x4 ]; 180 | 181 | public: 182 | convar * next; 183 | __int32 is_registered; 184 | char* name; 185 | char* help_string; 186 | __int32 flags; 187 | 188 | private: 189 | char pad_0x0018 [ 0x4 ]; 190 | 191 | public: 192 | convar * parent; 193 | char* default_value; 194 | char* string; 195 | __int32 string_length; 196 | float float_value; 197 | __int32 numerical_value; 198 | __int32 has_min; 199 | float min; 200 | __int32 has_max; 201 | float max; 202 | CUtlVector callbacks; 203 | }; -------------------------------------------------------------------------------- /source-sdk/classes/entities.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "collideable.hpp" 3 | 4 | enum entity_flags { 5 | fl_onground = ( 1 << 0 ), 6 | fl_ducking = ( 1 << 1 ), 7 | fl_waterjump = ( 1 << 2 ), 8 | fl_ontrain = ( 1 << 3 ), 9 | fl_inrain = ( 1 << 4 ), 10 | fl_frozen = ( 1 << 5 ), 11 | fl_atcontrols = ( 1 << 6 ), 12 | fl_client = ( 1 << 7 ), 13 | fl_fakeclient = ( 1 << 8 ), 14 | fl_inwater = ( 1 << 9 ), 15 | fl_fly = ( 1 << 10 ), 16 | fl_swim = ( 1 << 11 ), 17 | fl_conveyor = ( 1 << 12 ), 18 | fl_npc = ( 1 << 13 ), 19 | fl_godmode = ( 1 << 14 ), 20 | fl_notarget = ( 1 << 15 ), 21 | fl_aimtarget = ( 1 << 16 ), 22 | fl_partialground = ( 1 << 17 ), 23 | fl_staticprop = ( 1 << 18 ), 24 | fl_graphed = ( 1 << 19 ), 25 | fl_grenade = ( 1 << 20 ), 26 | fl_stepmovement = ( 1 << 21 ), 27 | fl_donttouch = ( 1 << 22 ), 28 | fl_basevelocity = ( 1 << 23 ), 29 | fl_worldbrush = ( 1 << 24 ), 30 | fl_object = ( 1 << 25 ), 31 | fl_killme = ( 1 << 26 ), 32 | fl_onfire = ( 1 << 27 ), 33 | fl_dissolving = ( 1 << 28 ), 34 | fl_transragdoll = ( 1 << 29 ), 35 | fl_unblockable_by_player = ( 1 << 30 ) 36 | }; 37 | 38 | enum item_definition_indexes { 39 | item_none = 0, 40 | weapon_deagle = 1, 41 | weapon_duals = 2, 42 | weapon_five7 = 3, 43 | weapon_glock = 4, 44 | weapon_ak47 = 7, 45 | weapon_aug = 8, 46 | weapon_awp = 9, 47 | weapon_famas = 10, 48 | weapon_g3sg1 = 11, 49 | weapon_galil = 13, 50 | weapon_m249 = 14, 51 | weapon_m4a1 = 16, 52 | weapon_mac10 = 17, 53 | weapon_p90 = 19, 54 | weapon_ump45 = 24, 55 | weapon_xm1014 = 25, 56 | weapon_bizon = 26, 57 | weapon_mag7 = 27, 58 | weapon_negev = 28, 59 | weapon_sawedoff = 29, 60 | weapon_tec9 = 30, 61 | weapon_taser = 31, 62 | weapon_p2000 = 32, 63 | weapon_mp7 = 33, 64 | weapon_mp9 = 34, 65 | weapon_nova = 35, 66 | weapon_p250 = 36, 67 | weapon_scar20 = 38, 68 | weapon_sg553 = 39, 69 | weapon_scout = 40, 70 | weapon_knife_t = 42, 71 | weapon_flash = 43, 72 | weapon_he = 44, 73 | weapon_smoke = 45, 74 | weapon_molotov = 46, 75 | weapon_decoy = 47, 76 | weapon_inc = 48, 77 | weapon_c4 = 49, 78 | weapon_knife_ct = 59, 79 | weapon_m4a1s = 60, 80 | weapon_usps = 61, 81 | weapon_cz75 = 63, 82 | weapon_revolver = 64, 83 | weapon_knife_bayonet = 500, 84 | weapon_knife_flip = 505, 85 | weapon_knife_gut = 506, 86 | weapon_knife_karambit = 507, 87 | weapon_knife_m9bayonet = 508, 88 | weapon_knife_huntsman = 509, 89 | weapon_knife_falchion = 512, 90 | weapon_knife_bowie = 514, 91 | weapon_knife_butterfly = 515, 92 | weapon_knife_dagger = 516, 93 | weapon_max 94 | }; 95 | 96 | class entity_t { 97 | public: 98 | void* animating( ) { 99 | return reinterpret_cast< void* >( uintptr_t( this ) + 0x4 ); 100 | } 101 | 102 | void* networkable( ) { 103 | return reinterpret_cast< void* >( uintptr_t( this ) + 0x8 ); 104 | } 105 | 106 | collideable_t* collideable( ) { 107 | using original_fn = collideable_t * ( __thiscall* )( void* ); 108 | return ( *( original_fn** ) this )[ 3 ]( this ); 109 | } 110 | 111 | client_class* clientclass( ) { 112 | using original_fn = client_class * ( __thiscall* )( void* ); 113 | return ( *( original_fn** ) networkable( ) )[ 2 ]( networkable( ) ); 114 | } 115 | 116 | bool is_player( ) { 117 | using original_fn = bool( __thiscall* )( entity_t* ); 118 | return ( *( original_fn** ) this )[ 152 ]( this ); 119 | } 120 | 121 | bool is_weapon( ) { 122 | using original_fn = bool( __thiscall* )( entity_t* ); 123 | return ( *( original_fn** ) this )[ 160 ]( this ); 124 | } 125 | 126 | bool setup_bones( matrix_t* out, int max_bones, int mask, float time ) { 127 | using original_fn = bool( __thiscall* )( void*, matrix_t*, int, int, float ); 128 | return ( *( original_fn** ) animating( ) )[ 13 ]( animating( ), out, max_bones, mask, time ); 129 | } 130 | 131 | model_t* model( ) { 132 | using original_fn = model_t * ( __thiscall* )( void* ); 133 | return ( *( original_fn** ) animating( ) )[ 8 ]( animating( ) ); 134 | } 135 | 136 | void update( ) { 137 | using original_fn = void( __thiscall* )( entity_t* ); 138 | ( *( original_fn** ) this )[ 218 ]( this ); 139 | } 140 | 141 | int draw_model( int flags, uint8_t alpha ) { 142 | using original_fn = int( __thiscall* )( void*, int, uint8_t ); 143 | return ( *( original_fn** ) animating( ) )[ 9 ]( animating( ), flags, alpha ); 144 | } 145 | 146 | void set_angles( vec3_t angles ) { 147 | using original_fn = void( __thiscall* )( void*, const vec3_t& ); 148 | static original_fn set_angles_fn = ( original_fn ) ( ( DWORD ) utilities::pattern_scan( GetModuleHandleA( "client_panorama.dll" ), "55 8B EC 83 E4 F8 83 EC 64 53 56 57 8B F1" ) ); 149 | set_angles_fn( this, angles ); 150 | } 151 | 152 | void set_position( vec3_t position ) { 153 | using original_fn = void( __thiscall* )( void*, const vec3_t& ); 154 | static original_fn set_position_fn = ( original_fn ) ( ( DWORD ) utilities::pattern_scan( GetModuleHandleA( "client_panorama.dll" ), "55 8B EC 83 E4 F8 51 53 56 57 8B F1 E8" ) ); 155 | set_position_fn( this, position ); 156 | } 157 | 158 | netvar_fn( int, flags, "DT_BasePlayer->m_fFlags" ); 159 | netvar_fn( unsigned long, owner_handle, "DT_BaseEntity->m_hOwnerEntity" ); 160 | offset_fn( bool, dormant, 0xE9 ); 161 | netvar_fn( float, simulation_time, "DT_BaseEntity->m_flSimulationTime" ); 162 | offset_fn( vec3_t, origin, 0x134 ); 163 | offset_fn( vec3_t, view_offset, 0x104 ); 164 | netvar_fn( int, team, "DT_BaseEntity->m_iTeamNum" ); 165 | netvar_fn( bool, spotted, "DT_BaseEntity->m_bSpotted" ); 166 | }; 167 | 168 | class viewmodel_t : public entity_t { 169 | public: 170 | netvar_ptr_fn( int, model_index, "DT_BaseViewModel->m_nModelIndex" ); 171 | netvar_ptr_fn( int, viewmodel_index, "DT_BaseViewModel->m_nViewModelIndex" ); 172 | }; 173 | 174 | class weapon_t : public entity_t { 175 | public: 176 | netvar_fn( float, next_primary_attack, "DT_BaseCombatWeapon->m_flNextPrimaryAttack" ); 177 | netvar_fn( float, next_secondary_attack, "DT_BaseCombatWeapon->m_flNextSecondaryAttack" ); 178 | netvar_fn( int, clip1_count, "DT_BaseCombatWeapon->m_iClip1" ); 179 | netvar_fn( int, clip2_count, "DT_BaseCombatWeapon->m_iClip2" ); 180 | netvar_fn( float, recoil_index, "DT_WeaponCSBase->m_flRecoilIndex" ); 181 | 182 | float get_innacuracy( ) { 183 | using original_fn = float( __thiscall* )( void* ); 184 | return ( *( original_fn** ) this )[ 479 ]( this ); 185 | } 186 | 187 | float get_spread( ) { 188 | using original_fn = float( __thiscall* )( void* ); 189 | return ( *( original_fn** ) this )[ 449 ]( this ); 190 | } 191 | 192 | void update_accuracy_penalty( ) { 193 | using original_fn = void( __thiscall* )( void* ); 194 | ( *( original_fn** ) this )[ 480 ]( this ); 195 | } 196 | 197 | weapon_info_t* get_weapon_data( ) { 198 | using original_fn = weapon_info_t * ( __thiscall* )( void* ); 199 | static original_fn return_func = ( original_fn ) ( ( DWORD ) utilities::pattern_scan( GetModuleHandleA( "client_panorama.dll" ), "55 8B EC 81 EC ? ? ? ? 53 8B D9 56 57 8D 8B" ) ); 200 | 201 | return return_func( this ); 202 | 203 | } 204 | 205 | bool is_knife( ) { 206 | return clientclass( )->class_id == cknife || clientclass( )->class_id == cknifegg; 207 | } 208 | }; 209 | 210 | class econ_view_item_t { 211 | public: 212 | netvar_offset_fn( bool, is_initialized, "DT_ScriptCreatedItem->m_bInitialized", g_netvar_mgr.get_offset( fnv_hash( "DT_AttributeContainer->m_Item" ) ) + g_netvar_mgr.get_offset( fnv_hash( "DT_BaseAttributableItem->m_AttributeManager" ) ) ); 213 | netvar_offset_fn( short, item_definition_index, "DT_ScriptCreatedItem->m_iItemDefinitionIndex", g_netvar_mgr.get_offset( fnv_hash( "DT_AttributeContainer->m_Item" ) ) + g_netvar_mgr.get_offset( fnv_hash( "DT_BaseAttributableItem->m_AttributeManager" ) ) ); 214 | netvar_offset_fn( int, entity_level, "DT_ScriptCreatedItem->m_iEntityLevel", g_netvar_mgr.get_offset( fnv_hash( "DT_AttributeContainer->m_Item" ) ) + g_netvar_mgr.get_offset( fnv_hash( "DT_BaseAttributableItem->m_AttributeManager" ) ) ); 215 | netvar_offset_fn( int, account_id, "DT_ScriptCreatedItem->m_iAccountID", g_netvar_mgr.get_offset( fnv_hash( "DT_AttributeContainer->m_Item" ) ) + g_netvar_mgr.get_offset( fnv_hash( "DT_BaseAttributableItem->m_AttributeManager" ) ) ); 216 | netvar_offset_fn( int, item_id_low, "DT_ScriptCreatedItem->m_iItemIDLow", g_netvar_mgr.get_offset( fnv_hash( "DT_AttributeContainer->m_Item" ) ) + g_netvar_mgr.get_offset( fnv_hash( "DT_BaseAttributableItem->m_AttributeManager" ) ) ); 217 | netvar_offset_fn( int, item_id_high, "DT_ScriptCreatedItem->m_iItemIDHigh", g_netvar_mgr.get_offset( fnv_hash( "DT_AttributeContainer->m_Item" ) ) + g_netvar_mgr.get_offset( fnv_hash( "DT_BaseAttributableItem->m_AttributeManager" ) ) ); 218 | netvar_offset_fn( int, entity_quality, "DT_ScriptCreatedItem->m_iEntityQuality", g_netvar_mgr.get_offset( fnv_hash( "DT_AttributeContainer->m_Item" ) ) + g_netvar_mgr.get_offset( fnv_hash( "DT_BaseAttributableItem->m_AttributeManager" ) ) ); 219 | }; 220 | 221 | class attributable_item_t : public entity_t { 222 | public: 223 | netvar_fn( unsigned long, original_owner_xuid, "DT_BaseAttributableItem->m_OriginalOwnerXuidLow" ); 224 | netvar_fn( int, original_owner_xuid_low, "DT_BaseAttributableItem->m_OriginalOwnerXuidLow" ); 225 | netvar_fn( int, original_owner_xuid_high, "DT_BaseAttributableItem->m_OriginalOwnerXuidHigh" ); 226 | netvar_fn( int, fallback_stattrak, "DT_BaseAttributableItem->m_nFallbackStatTrak" ); 227 | netvar_fn( int, fallback_paint_kit, "DT_BaseAttributableItem->m_nFallbackPaintKit" ); 228 | netvar_fn( int, fallback_seed, "DT_BaseAttributableItem->m_nFallbackSeed" ); 229 | netvar_fn( float, fallback_wear, "DT_BaseAttributableItem->m_flFallbackWear" ); 230 | netvar_fn( unsigned long, world_model_handle, "DT_BaseCombatWeapon->m_hWeaponWorldModel" ); 231 | 232 | econ_view_item_t& item( ) { 233 | return *( econ_view_item_t* ) this; 234 | } 235 | }; 236 | 237 | class player_t : public entity_t { 238 | public: 239 | netvar_fn( bool, has_defuser, "DT_CSPlayer->m_bHasDefuser" ); 240 | netvar_fn( bool, has_gun_game_immunity, "DT_CSPlayer->m_bGunGameImmunity" ); 241 | netvar_fn( int, shots_fired, "DT_CSPlayer->m_iShotsFired" ); 242 | netvar_fn( vec3_t, eye_angles, "DT_CSPlayer->m_angEyeAngles[0]" ); 243 | netvar_fn( int, armor, "DT_CSPlayer->m_ArmorValue" ); 244 | netvar_fn( bool, has_helmet, "DT_CSPlayer->m_bHasHelmet" ); 245 | netvar_fn( bool, is_scoped, "DT_CSPlayer->m_bIsScoped" );; 246 | netvar_fn( float, lower_body_yaw, "DT_CSPlayer->m_flLowerBodyYawTarget" ); 247 | netvar_fn( float, flash_duration, "DT_CSPlayer->m_flFlashDuration" ); 248 | netvar_fn( int, health, "DT_BasePlayer->m_iHealth" ); 249 | netvar_fn( int, life_state, "DT_BasePlayer->m_lifeState" ); 250 | netvar_fn( int, flags, "DT_BasePlayer->m_fFlags" ); 251 | netvar_fn( int, tick_base, "DT_BasePlayer->m_nTickBase" ); 252 | netvar_fn( vec3_t, punch_angle, "DT_BasePlayer->m_viewPunchAngle" ); 253 | netvar_fn( vec3_t, aim_punch_angle, "DT_BasePlayer->m_aimPunchAngle" ); 254 | netvar_fn( vec3_t, velocity, "DT_BasePlayer->m_vecVelocity[0]" ); 255 | netvar_fn( float, max_speed, "DT_BasePlayer->m_flMaxspeed" ); 256 | netvar_fn( unsigned long, observer_target, "DT_BasePlayer->m_hObserverTarget" ); 257 | netvar_fn( unsigned long, active_weapon_handle, "DT_BaseCombatCharacter->m_hActiveWeapon" ); 258 | 259 | weapon_t* active_weapon( void ) { 260 | uintptr_t handle = active_weapon_handle( ); 261 | return ( weapon_t* ) interfaces::entity_list->get_client_entity( handle ); 262 | } 263 | 264 | int* weapons( ) { 265 | return ( int* ) ( uintptr_t( this ) + 0x2DE8 ); 266 | } 267 | }; -------------------------------------------------------------------------------- /source-sdk/classes/gameevent.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class game_event { 4 | public: 5 | const char* get_name( ) { 6 | using original_fn = const char*( __thiscall* )( game_event* ); 7 | return ( *( original_fn** ) this ) [ 1 ]( this ); 8 | } 9 | int get_int( const char* name ) { 10 | using original_fn = int( __thiscall* )( game_event*, const char*, int ); 11 | return ( *( original_fn** ) this ) [ 6 ]( this, name, 0 ); 12 | } 13 | }; 14 | 15 | class game_event_listener { 16 | public: 17 | virtual ~game_event_listener( ) { } 18 | 19 | virtual void fire_game_event( game_event* event ) = 0; 20 | virtual int get_debug_id( ) = 0; 21 | 22 | public: 23 | int debug_id; 24 | }; -------------------------------------------------------------------------------- /source-sdk/classes/recv_props.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class d_variant; 4 | class recv_table; 5 | class recv_prop; 6 | class c_recv_proxy_data; 7 | 8 | using recv_var_proxy_fn = void( *)( const c_recv_proxy_data* data, void* struct_ptr, void* out_ptr ); 9 | using array_length_recv_proxy_fn = void( *)( void* struct_ptr, int object_id, int current_array_length ); 10 | using data_table_recv_var_proxy_fn = void( *)( const recv_prop* prop, void** out_ptr, void* data_ptr, int object_id ); 11 | 12 | enum send_prop_type { 13 | _int = 0, 14 | _float, 15 | _vec, 16 | _vec_xy, 17 | _string, 18 | _array, 19 | _data_table, 20 | _int_64, 21 | }; 22 | class d_variant { 23 | public: 24 | union { 25 | float m_float; 26 | long m_int; 27 | char* m_string; 28 | void* m_data; 29 | float m_vector [ 3 ]; 30 | __int64 m_int64; 31 | }; 32 | send_prop_type type; 33 | }; 34 | class c_recv_proxy_data { 35 | public: 36 | const recv_prop* recv_prop; 37 | d_variant value; 38 | int element_index; 39 | int object_id; 40 | }; 41 | class recv_prop { 42 | public: 43 | char* prop_name; 44 | send_prop_type prop_type; 45 | int prop_flags; 46 | int buffer_size; 47 | int is_inside_of_array; 48 | const void* extra_data_ptr; 49 | recv_prop* array_prop; 50 | array_length_recv_proxy_fn array_length_proxy; 51 | recv_var_proxy_fn proxy_fn; 52 | data_table_recv_var_proxy_fn data_table_proxy_fn; 53 | recv_table* data_table; 54 | int offset; 55 | int element_stride; 56 | int elements_count; 57 | const char* parent_array_prop_name; 58 | }; 59 | class recv_table { 60 | public: 61 | recv_prop * props; 62 | int props_count; 63 | void* decoder_ptr; 64 | char* table_name; 65 | bool is_initialized; 66 | bool is_in_main_list; 67 | }; -------------------------------------------------------------------------------- /source-sdk/classes/studio.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | using quaternion = float [ 4 ]; 5 | using rad_euler = float [ 3 ]; 6 | 7 | enum bone_flags { 8 | bone_calculate_mask = 0x1f, 9 | bone_physically_simulated = 0x01, 10 | bone_physics_procedural = 0x02, 11 | bone_always_procedural = 0x04, 12 | bone_screen_align_sphere = 0x08, 13 | bone_screen_align_cylinder = 0x10, 14 | bone_used_mask = 0x0007ff00, 15 | bone_used_by_anything = 0x0007ff00, 16 | bone_used_by_hitbox = 0x00000100, 17 | bone_used_by_attachment = 0x00000200, 18 | bone_used_by_vertex_mask = 0x0003fc00, 19 | bone_used_by_vertex_lod0 = 0x00000400, 20 | bone_used_by_vertex_lod1 = 0x00000800, 21 | bone_used_by_vertex_lod2 = 0x00001000, 22 | bone_used_by_vertex_lod3 = 0x00002000, 23 | bone_used_by_vertex_lod4 = 0x00004000, 24 | bone_used_by_vertex_lod5 = 0x00008000, 25 | bone_used_by_vertex_lod6 = 0x00010000, 26 | bone_used_by_vertex_lod7 = 0x00020000, 27 | bone_used_by_bone_merge = 0x00040000, 28 | bone_type_mask = 0x00f00000, 29 | bone_fixed_alignment = 0x00100000, 30 | bone_has_saveframe_pos = 0x00200000, 31 | bone_has_saveframe_rot = 0x00400000 32 | }; 33 | 34 | enum hitgroups { 35 | hitgroup_generic = 0, 36 | hitgroup_head = 1, 37 | hitgroup_chest = 2, 38 | hitgroup_stomach = 3, 39 | hitgroup_leftarm = 4, 40 | hitgroup_rightarm = 5, 41 | hitgroup_leftleg = 6, 42 | hitgroup_rightleg = 7, 43 | hitgroup_gear = 10 44 | }; 45 | 46 | enum modtypes { 47 | mod_bad = 0, 48 | mod_brush, 49 | mod_sprite, 50 | mod_studio 51 | }; 52 | 53 | enum hitboxes { 54 | hitbox_head, 55 | hitbox_neck, 56 | hitbox_lower_neck, 57 | hitbox_pelvis, 58 | hitbox_stomach, 59 | hitbox_lower_chest, 60 | hitbox_chest, 61 | hitbox_upper_chest, 62 | hitbox_right_thigh, 63 | hitbox_left_thigh, 64 | hitbox_right_calf, 65 | hitbox_left_calf, 66 | hitbox_right_foot, 67 | hitbox_left_foot, 68 | hitbox_right_hand, 69 | hitbox_left_hand, 70 | hitbox_right_upper_arm, 71 | hitbox_right_forearm, 72 | hitbox_left_upper_arm, 73 | hitbox_left_forearm, 74 | hitbox_max 75 | }; 76 | 77 | struct studio_bone_t { 78 | int name_index; 79 | inline char *const name( void ) const { 80 | return ( ( char* ) this ) + name_index; 81 | } 82 | int parent; 83 | int bone_controller [ 6 ]; 84 | 85 | vec3_t pos; 86 | quaternion quat; 87 | rad_euler rotation; 88 | 89 | vec3_t pos_scale; 90 | vec3_t rot_scale; 91 | 92 | matrix_t pose_to_bone; 93 | quaternion quat_alignement; 94 | int flags; 95 | int proc_type; 96 | int proc_index; 97 | mutable int physics_bone; 98 | 99 | inline void *procedure( ) const { 100 | if ( proc_index == 0 ) return NULL; 101 | else return( void * ) ( ( ( unsigned char* ) this ) + proc_index ); 102 | }; 103 | 104 | int surface_prop_idx; 105 | inline char *const surface_prop( void ) const { 106 | return ( ( char* ) this ) + surface_prop_idx; 107 | } 108 | inline int get_surface_prop( void ) const { 109 | return surf_prop_lookup; 110 | } 111 | 112 | int contents; 113 | int surf_prop_lookup; 114 | int unused [ 7 ]; 115 | }; 116 | 117 | struct studio_box_t { 118 | int bone; 119 | int group; 120 | vec3_t mins; 121 | vec3_t maxs; 122 | int name_index; 123 | int pad01 [ 3 ]; 124 | float radius; 125 | int pad02 [ 4 ]; 126 | }; 127 | 128 | struct studio_hitbox_set_t { 129 | int name_index; 130 | int hitbox_count; 131 | int hitbox_index; 132 | 133 | inline char *const name( void ) const { 134 | return ( ( char* ) this ) + name_index; 135 | } 136 | inline studio_box_t *hitbox( int i ) const { 137 | return ( studio_box_t* ) ( ( ( unsigned char* ) this ) + hitbox_index ) + i; 138 | } 139 | }; 140 | 141 | class studio_hdr_t { 142 | public: 143 | int id; 144 | int version; 145 | long checksum; 146 | char name_char_array [ 64 ]; 147 | int length; 148 | vec3_t eye_pos; 149 | vec3_t illium_pos; 150 | vec3_t hull_mins; 151 | vec3_t hull_maxs; 152 | vec3_t mins; 153 | vec3_t maxs; 154 | int flags; 155 | int bones_count; 156 | int bone_index; 157 | int bone_controllers_count; 158 | int bone_controller_index; 159 | int hitbox_sets_count; 160 | int hitbox_set_index; 161 | int local_anim_count; 162 | int local_anim_index; 163 | int local_seq_count; 164 | int local_seq_index; 165 | int activity_list_version; 166 | int events_indexed; 167 | int textures_count; 168 | int texture_index; 169 | 170 | studio_hitbox_set_t* hitbox_set( int i ) { 171 | if ( i > hitbox_sets_count ) return nullptr; 172 | return ( studio_hitbox_set_t* ) ( ( uint8_t* ) this + hitbox_set_index ) + i; 173 | } 174 | studio_bone_t* bone( int i ) { 175 | if ( i > bones_count ) return nullptr; 176 | return ( studio_bone_t* ) ( ( uint8_t* ) this + bone_index ) + i; 177 | } 178 | 179 | }; -------------------------------------------------------------------------------- /source-sdk/math/vector2d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "vector3d.hpp" 4 | class vec2_t { 5 | public: 6 | float x, y; 7 | 8 | vec2_t() { 9 | x = 0; y = 0; 10 | }; 11 | vec2_t(float X, float Y) { 12 | x = X; y = Y; 13 | }; 14 | vec2_t(vec3_t vec) { 15 | x = vec.x; y = vec.y; 16 | } 17 | 18 | inline vec2_t operator*(const float n) const { 19 | return vec2_t(x*n, y*n); 20 | } 21 | inline vec2_t operator+(const vec2_t& v) const { 22 | return vec2_t(x + v.x, y + v.y); 23 | } 24 | inline vec2_t operator-(const vec2_t& v) const { 25 | return vec2_t(x - v.x, y - v.y); 26 | } 27 | inline void operator+=(const vec2_t& v) { 28 | x += v.x; 29 | y += v.y; 30 | } 31 | inline void operator-=(const vec2_t& v) { 32 | x -= v.x; 33 | y -= v.y; 34 | } 35 | 36 | bool operator==(const vec2_t& v) const { 37 | return (v.x == x && v.y == y); 38 | } 39 | bool operator!=(const vec2_t& v) const { 40 | return (v.x != x || v.y != y); 41 | } 42 | 43 | inline float length() { 44 | return sqrt((x * x) + (y * y)); 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /source-sdk/math/vector3d.cpp: -------------------------------------------------------------------------------- 1 | #include "vector3d.hpp" 2 | #include 3 | 4 | vec3_t::vec3_t( void ) { 5 | x = y = z = 0.0f; 6 | } 7 | 8 | vec3_t::vec3_t( float fx, float fy, float fz ) { 9 | x = fx; 10 | y = fy; 11 | z = fz; 12 | } 13 | 14 | vec3_t::~vec3_t( void ) { 15 | 16 | }; 17 | 18 | void vec3_t::clamp( void ) { 19 | x = clip_number( x, -89.0f, 89.0f ); 20 | y = clip_number( std::remainder( y, 360.0f ), -180.0f, 180.0f ); 21 | z = clip_number( z, -50.0f, 50.0f ); 22 | } 23 | 24 | void vec3_t::normalize( void ) { 25 | auto vec_normalize = [ & ] ( vec3_t& v ) { 26 | auto l = v.length( ); 27 | 28 | if ( l != 0.0f ) { 29 | v.x /= l; 30 | v.y /= l; 31 | v.z /= l; 32 | } 33 | else { 34 | v.x = v.y = 0.0f; v.z = 1.0f; 35 | } 36 | 37 | return l; 38 | }; 39 | 40 | vec_normalize( *this ); 41 | } 42 | 43 | vec3_t vec3_t::normalized( void ) { 44 | vec3_t vec( *this ); 45 | vec.normalize( ); 46 | 47 | return vec; 48 | } 49 | 50 | float vec3_t::length( void ) { 51 | float root = 0.0f, sqsr = this->length_sqr( ); 52 | 53 | __asm sqrtss xmm0, sqsr 54 | __asm movss root, xmm0 55 | 56 | return root; 57 | } 58 | 59 | float vec3_t::length_sqr( void ) { 60 | auto sqr = [ ] ( float n ) { 61 | return static_cast< float >( n * n ); 62 | }; 63 | 64 | return ( sqr( x ) + sqr( y ) + sqr( z ) ); 65 | } 66 | 67 | float vec3_t::dot( const vec3_t other ) { 68 | return ( x * other.x + y * other.y + z * other.z ); 69 | } -------------------------------------------------------------------------------- /source-sdk/math/vector3d.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | template 5 | T clip_number( const T& n, const T& lower, const T& upper ) { 6 | if ( n < lower ) return lower; 7 | if ( n > upper ) return upper; 8 | return n; 9 | } 10 | 11 | class vec3_t { 12 | public: 13 | vec3_t( ); 14 | vec3_t( float, float, float ); 15 | ~vec3_t( ); 16 | 17 | float x, y, z; 18 | 19 | vec3_t& operator+=( const vec3_t& v ) { 20 | x += v.x; y += v.y; z += v.z; return *this; 21 | } 22 | vec3_t& operator-=( const vec3_t& v ) { 23 | x -= v.x; y -= v.y; z -= v.z; return *this; 24 | } 25 | vec3_t& operator*=( float v ) { 26 | x *= v; y *= v; z *= v; return *this; 27 | } 28 | vec3_t operator+( const vec3_t& v ) { 29 | return vec3_t { x + v.x, y + v.y, z + v.z }; 30 | } 31 | vec3_t operator-( const vec3_t& v ) { 32 | return vec3_t { x - v.x, y - v.y, z - v.z }; 33 | } 34 | vec3_t operator*( float v ) const { 35 | return vec3_t { x * v, y * v, z * v }; 36 | } 37 | 38 | float& operator[]( int i ) { 39 | return ( ( float* ) this ) [ i ]; 40 | } 41 | float operator[]( int i ) const { 42 | return ( ( float* ) this ) [ i ]; 43 | } 44 | 45 | void clamp( ); 46 | vec3_t normalized( ); 47 | void normalize( ); 48 | float length( ); 49 | float length_sqr( ); 50 | float dot( const vec3_t other ); 51 | }; 52 | typedef float matrix_t [ 3 ] [ 4 ]; -------------------------------------------------------------------------------- /source-sdk/misc/color.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | struct color { 6 | int a, r, g, b; 7 | color( ) = default; 8 | color( int r, int g, int b, int a = 255 ) { 9 | this->r = r; 10 | this->g = g; 11 | this->b = b; 12 | this->a = a; 13 | } 14 | color( uint32_t color ) { 15 | this->a = ( color >> 24 ) & 0xff; 16 | this->r = ( color >> 16 ) & 0xff; 17 | this->g = ( color >> 8 ) & 0xff; 18 | this->b = ( color & 0xff ); 19 | } 20 | color from_uint( uint32_t uint ) { 21 | return color( uint ); 22 | } 23 | D3DCOLOR from_color( color col ) { 24 | return D3DCOLOR_ARGB( col.a, col.r, col.g, col.b ); 25 | } 26 | }; -------------------------------------------------------------------------------- /source-sdk/sdk.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "math/vector3d.hpp" 4 | #include "misc/color.hpp" 5 | 6 | #include "classes/c_usercmd.hpp" 7 | #include "classes/recv_props.hpp" 8 | #include "classes/client_class.hpp" 9 | #include "classes/convar.hpp" 10 | #include "classes/studio.hpp" 11 | #include "classes/gameevent.hpp" 12 | #include "structs/dlight.hpp" 13 | #include "structs/weaponinfo.hpp" 14 | 15 | #include "classes/entities.hpp" -------------------------------------------------------------------------------- /source-sdk/structs/dlight.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | enum dlight_flags { 4 | dlight_no_world_illumination = 0x1, 5 | dlight_no_model_illumination = 0x2, 6 | dlight_add_displacement_alpha = 0x4, 7 | dlight_subtract_displacement_alpha = 0x8, 8 | dlight_displacement_mask = ( dlight_add_displacement_alpha | dlight_subtract_displacement_alpha ), 9 | }; 10 | 11 | struct dlight_t { 12 | int flags; 13 | vec3_t origin; 14 | float radius; 15 | color color; 16 | float die_time; 17 | float decay; 18 | float min_light; 19 | int key; 20 | int style; 21 | vec3_t direction; 22 | float inner_angle; 23 | float outer_angle; 24 | }; -------------------------------------------------------------------------------- /source-sdk/structs/materials.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | using material_handle_t = unsigned short; 4 | class i_material { 5 | public: 6 | const char* get_name( ) { 7 | using original_fn = const char*( __thiscall* )( i_material* ); 8 | return ( *( original_fn** ) this ) [ 0 ]( this ); 9 | } 10 | const char* get_group_name( ) { 11 | using original_fn = const char*( __thiscall* )( i_material* ); 12 | return ( *( original_fn** ) this ) [ 1 ]( this ); 13 | } 14 | void set_alpha( float alpha ) { 15 | using original_fn = void( __thiscall* )( i_material*, float ); 16 | return ( *( original_fn** ) this ) [ 27 ]( this, alpha ); 17 | } 18 | void set_alpha( int alpha ) { 19 | using original_fn = void( __thiscall* )( i_material*, float ); 20 | return ( *( original_fn** ) this ) [ 27 ]( this, static_cast< float >( alpha ) / 255.f ); 21 | } 22 | void set_color( float r, float g, float b ) { 23 | using original_fn = void( __thiscall* )( i_material*, float, float, float ); 24 | return ( *( original_fn** ) this ) [ 28 ]( this, r, g, b ); 25 | } 26 | 27 | void set_color( int r, int g, int b ) { 28 | using original_fn = void( __thiscall* )( i_material*, float, float, float ); 29 | return ( *( original_fn** ) this ) [ 28 ]( this, r / 255.f, g / 255.f, b / 255.f ); 30 | } 31 | void set_color( int color32 ) { 32 | int r1 = ( color32 >> 16 ) & 0xff; 33 | int g1 = ( color32 >> 8 ) & 0xff; 34 | int b1 = color32 & 0xff; 35 | i_material::set_color( r1, g1, b1 ); 36 | } 37 | void set_flag( int flag, bool on ) { 38 | using original_fn = void( __thiscall* )( i_material*, int, bool ); 39 | return ( *( original_fn** ) this ) [ 29 ]( this, flag, on ); 40 | } 41 | }; -------------------------------------------------------------------------------- /source-sdk/structs/models.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../math/vector3d.hpp" 3 | 4 | struct model_t; 5 | 6 | struct model_render_info_t { 7 | vec3_t origin; 8 | vec3_t angles; 9 | char pad [ 0x4 ]; // added this 10 | void *renderable; // this 11 | const void *model; // and this 12 | const matrix_t* model_to_world; 13 | const matrix_t* lighting_offset; 14 | const vec3_t* lighting_origin; 15 | int flags; 16 | int entity_index; 17 | int skin; 18 | int body; 19 | int hitboxset; 20 | unsigned short instance; 21 | 22 | model_render_info_t( ) { 23 | model_to_world = NULL; 24 | lighting_offset = NULL; 25 | lighting_origin = NULL; 26 | } 27 | }; -------------------------------------------------------------------------------- /source-sdk/structs/vertex_t.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../math/vector2d.hpp" 3 | struct vertex_t { 4 | vertex_t( ) {} 5 | vertex_t( const vec2_t &pos, const vec2_t &coord = vec2_t( 0, 0 ) ) { 6 | position = pos; 7 | tex_coord = coord; 8 | } 9 | void initialize( const vec2_t &pos, const vec2_t &coord = vec2_t( 0, 0 ) ) { 10 | position = pos; 11 | tex_coord = coord; 12 | } 13 | 14 | vec2_t position; 15 | vec2_t tex_coord; 16 | }; 17 | -------------------------------------------------------------------------------- /source-sdk/structs/weaponinfo.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class weapon_info_t { 4 | public: 5 | virtual ~weapon_info_t( ) { }; 6 | 7 | char _0x0000[20]; 8 | __int32 max_clip; //0x0014 9 | char _0x0018[12]; 10 | __int32 max_reserved_ammo; //0x0024 11 | char _0x0028[96]; 12 | char* hud_name; //0x0088 13 | char* weapon_name; //0x008C 14 | char _0x0090[60]; 15 | __int32 type; //0x00CC 16 | __int32 price; //0x00D0 17 | __int32 reward; //0x00D4 18 | char _0x00D8[20]; 19 | BYTE full_auto; //0x00EC 20 | char _0x00ED[3]; 21 | __int32 damage; //0x00F0 22 | float armor_ratio; //0x00F4 23 | __int32 bullets; //0x00F8 24 | float penetration; //0x00FC 25 | char _0x0100[8]; 26 | float range; //0x0108 27 | float range_modifier; //0x010C 28 | char _0x0110[16]; 29 | BYTE silencer; //0x0120 30 | char _0x0121[15]; 31 | float max_speed; //0x0130 32 | float max_speed_alt; //0x0134 33 | char _0x0138[76]; 34 | __int32 recoil_seed; //0x0184 35 | char _0x0188[32]; 36 | }; --------------------------------------------------------------------------------