├── patoke-sdk-cs16 ├── dependencies │ ├── precompiled.cpp │ ├── libraries │ │ ├── minhook │ │ │ ├── buffer.cpp │ │ │ ├── hde │ │ │ │ ├── pstdint.h │ │ │ │ ├── hde32.h │ │ │ │ ├── hde64.h │ │ │ │ ├── table32.h │ │ │ │ ├── table64.h │ │ │ │ ├── hde32.cpp │ │ │ │ └── hde64.cpp │ │ │ ├── buffer.h │ │ │ ├── trampoline.h │ │ │ ├── minhook.h │ │ │ └── trampoline.cpp │ │ ├── wrappers │ │ │ └── hooking.hpp │ │ └── imgui │ │ │ ├── imgui_impl_opengl3.h │ │ │ ├── imgui_impl_win32.h │ │ │ └── imconfig.h │ ├── precompiled.hpp │ └── utilities │ │ ├── pattern │ │ ├── char_queue.hpp │ │ ├── simd_scanner.hpp │ │ └── pattern.hpp │ │ └── utilities.hpp ├── main │ ├── features │ │ ├── misc │ │ │ ├── misc.hpp │ │ │ ├── movement.hpp │ │ │ └── movement.cpp │ │ ├── visuals │ │ │ ├── visuals.hpp │ │ │ ├── esp.hpp │ │ │ └── esp.cpp │ │ └── features.hpp │ ├── ui │ │ ├── ui.hpp │ │ └── ui.cpp │ ├── game │ │ ├── sdk │ │ │ ├── hlsdk.hpp │ │ │ └── classes │ │ │ │ ├── cmd.hpp │ │ │ │ ├── triapi.hpp │ │ │ │ ├── bspfile.hpp │ │ │ │ ├── r_studioint.hpp │ │ │ │ ├── model.hpp │ │ │ │ ├── entity.hpp │ │ │ │ ├── playermove.hpp │ │ │ │ └── studio.hpp │ │ └── interfaces.hpp │ ├── hooks │ │ ├── hooked │ │ │ ├── createmove.cpp │ │ │ ├── wndproc.cpp │ │ │ └── swap_buffers.cpp │ │ ├── hooks.hpp │ │ └── hooks.cpp │ ├── initialization │ │ ├── initialization.hpp │ │ └── initialization.cpp │ └── main.cpp ├── other │ ├── math │ │ ├── math.hpp │ │ └── math.cpp │ ├── position │ │ ├── g_pos.cpp │ │ └── g_pos.hpp │ ├── memory.hpp │ └── globals.hpp └── patoke-sdk-cs16.vcxproj.filters ├── patoke-sdk-cs16.sln ├── .gitattributes └── .gitignore /patoke-sdk-cs16/dependencies/precompiled.cpp: -------------------------------------------------------------------------------- 1 | #include "precompiled.hpp" -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/features/misc/misc.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "movement.hpp" -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/features/visuals/visuals.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "esp.hpp" -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/features/features.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "misc/misc.hpp" 3 | #include "visuals/visuals.hpp" -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/features/visuals/esp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | struct s_esp { 5 | 6 | void tracers(); 7 | 8 | } static esp_i; -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/minhook/buffer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Patoke/patoke-sdk-cs16/HEAD/patoke-sdk-cs16/dependencies/libraries/minhook/buffer.cpp -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/features/misc/movement.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | struct s_movement { 5 | 6 | void bhop(usercmd_s* cmd); 7 | 8 | } static movement_i; -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/ui/ui.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | struct s_ui { 5 | 6 | // main 7 | void draw(); 8 | 9 | // containers 10 | void main_container(); 11 | 12 | // variables 13 | bool is_open = true; 14 | int current_tab = 0; 15 | 16 | } extern ui_i; -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/game/sdk/hlsdk.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "classes/cdll.hpp" 3 | #include "classes/cmd.hpp" 4 | #include "classes/bspfile.hpp" 5 | #include "classes/const.hpp" 6 | #include "classes/entity.hpp" 7 | #include "classes/model.hpp" 8 | #include "classes/playermove.hpp" 9 | #include "classes/studio.hpp" 10 | #include "classes/r_studioint.hpp" -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/hooks/hooked/createmove.cpp: -------------------------------------------------------------------------------- 1 | #include "../hooks.hpp" 2 | 3 | void n_hooked::hk_createmove(float frametime, usercmd_s* cmd, int active) { 4 | static auto o_hook = n_detour::get(hk_createmove); 5 | 6 | o_hook(frametime, cmd, active); 7 | 8 | globals_i.local_player.update(interfaces_i.engine->GetLocalPlayer(), true); 9 | 10 | movement_i.bhop(cmd); 11 | } -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/ui/ui.cpp: -------------------------------------------------------------------------------- 1 | #include "ui.hpp" 2 | 3 | // ui instance 4 | s_ui ui_i; 5 | 6 | void s_ui::draw() { 7 | if (!is_open) 8 | return; 9 | 10 | ImGui::SetNextWindowSize({ 300, 200 }, ImGuiCond_Once); 11 | ImGui::Begin("patoke-sdk", 0); { 12 | 13 | // draw containers (tabs) 14 | switch (current_tab) { 15 | case 0: main_container(); break; 16 | default: break; 17 | } 18 | 19 | } ImGui::End(); 20 | } 21 | 22 | // containers 23 | void s_ui::main_container() { 24 | 25 | } -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/features/misc/movement.cpp: -------------------------------------------------------------------------------- 1 | #include "movement.hpp" 2 | 3 | void s_movement::bhop(usercmd_s* cmd) { 4 | if (!globals_i.local_player.is_valid || !globals_i.local_player.is_alive) 5 | return; 6 | 7 | bool is_bad_movetype = globals_i.local_player.movetype == MOVETYPE_NOCLIP || globals_i.local_player.movetype == MOVETYPE_FLY; 8 | bool in_water = globals_i.local_player.waterlevel >= 2; 9 | 10 | if (is_bad_movetype || in_water) 11 | return; 12 | 13 | if (cmd->buttons & IN_JUMP && !(globals_i.local_player.flags & FL_ONGROUND)) 14 | cmd->buttons &= ~IN_JUMP; 15 | } -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/features/visuals/esp.cpp: -------------------------------------------------------------------------------- 1 | #include "esp.hpp" 2 | 3 | void s_esp::tracers() { 4 | if (!interfaces_i.engine || !globals_i.local_player.is_valid) 5 | return; 6 | 7 | for (int i = 1; i < interfaces_i.engine->GetMaxClients(); i++) { 8 | s_entity entity; 9 | entity.update(interfaces_i.engine->GetEntityByIndex(i), false); 10 | 11 | if (!entity.is_valid || !entity.is_alive) 12 | continue; 13 | 14 | s_vec2 screen_pos; 15 | if (!interfaces_i.engine->world_to_screen(entity.origin, screen_pos)) 16 | continue; 17 | 18 | render_i.line(s_vec2(ImGui::GetIO().DisplaySize.x / 2, ImGui::GetIO().DisplaySize.y), screen_pos, s_color(1.f, 1.f, 1.f)); 19 | } 20 | } -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/hooks/hooked/wndproc.cpp: -------------------------------------------------------------------------------- 1 | #include "../hooks.hpp" 2 | 3 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 4 | LRESULT __stdcall n_hooked::hk_wndproc(HWND hwnd, unsigned int msg, WPARAM wparam, LPARAM lparam) { 5 | const auto get_button_toggle = [msg, wparam](bool& button, int key) { 6 | if (wparam != key) 7 | return; 8 | 9 | if (msg == WM_KEYUP) 10 | button = !button; 11 | }; 12 | 13 | get_button_toggle(ui_i.is_open, VK_INSERT); 14 | 15 | if (ui_i.is_open && ImGui_ImplWin32_WndProcHandler(hwnd, msg, wparam, lparam)) 16 | return true; 17 | 18 | return CallWindowProc(ofn_wndproc, hwnd, msg, wparam, lparam); 19 | } -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/hooks/hooked/swap_buffers.cpp: -------------------------------------------------------------------------------- 1 | #include "../hooks.hpp" 2 | 3 | bool __stdcall n_hooked::hk_swap_buffers(HDC hdc) { 4 | static auto o_hook = n_detour::get(hk_swap_buffers); 5 | 6 | auto game_window_dc = WindowFromDC(hdc); 7 | 8 | if (!render_i.did_initialize) 9 | ofn_wndproc = reinterpret_cast(SetWindowLong(game_window_dc, GWL_WNDPROC, reinterpret_cast(hk_wndproc))); 10 | 11 | // initialize imgui 12 | render_i.setup(game_window_dc); 13 | 14 | render_i.new_frame(); 15 | { 16 | esp_i.tracers(); 17 | 18 | // do imgui stuff here 19 | ui_i.draw(); 20 | } 21 | render_i.end_frame(); 22 | 23 | return o_hook(hdc); 24 | } -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/hooks/hooks.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "../initialization/initialization.hpp" 5 | 6 | // feature includes 7 | #include "../features/features.hpp" 8 | 9 | struct s_hooks { 10 | 11 | // init 12 | bool initialize(); 13 | 14 | // cleanup 15 | void cleanup(); 16 | 17 | } extern hooks_i; 18 | 19 | namespace n_hooked { 20 | // hook definitions 21 | typedef bool(__stdcall* swap_buffers_fn)(HDC); 22 | typedef void(__cdecl* createmove_fn)(float, usercmd_s*, int); 23 | 24 | // ohook declarations 25 | inline WNDPROC ofn_wndproc{}; 26 | 27 | // hook declarations 28 | bool __stdcall hk_swap_buffers(HDC hdc); 29 | LRESULT __stdcall hk_wndproc(HWND hwnd, unsigned int msg, WPARAM wparam, LPARAM lparam); 30 | void hk_createmove(float frametime, usercmd_s* cmd, int active); 31 | } -------------------------------------------------------------------------------- /patoke-sdk-cs16/other/math/math.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | // angle functions 6 | constexpr float rad2deg(const float x) { 7 | return x * (180.f / std::numbers::pi_v); 8 | } 9 | 10 | constexpr float deg2rad(const float x) { 11 | return x * (std::numbers::pi_v / 180.f); 12 | } 13 | 14 | struct s_math { 15 | inline void sin_cos(float radians, float* sine, float* cosine) const; 16 | inline float normalize_angle(float angle, float start = -180.f, float end = 180.f) const; 17 | s_angle calculate_angle(const s_vec3& source, const s_vec3& destination); 18 | s_angle calculate_angle(const s_vec3& source, const s_vec3& destination, const s_angle& viewangles); 19 | s_vec3 vector_transform(const s_vec3& in_vec, const s_matrix3x4& in_matrix, s_vec3& out); 20 | }; 21 | 22 | extern s_math math_i; -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/hooks/hooks.cpp: -------------------------------------------------------------------------------- 1 | #include "hooks.hpp" 2 | 3 | bool s_hooks::initialize() { 4 | // hook addresses 5 | auto adr_swap_buffers = reinterpret_cast(n_utilities::get_export_from_table(m[OPENGL32].get(), HASH("wglSwapBuffers"))); 6 | auto adr_create_move = reinterpret_cast(interfaces_i.client->CL_CreateMove); 7 | 8 | if (!n_detour::init()) 9 | return false; 10 | 11 | CREATE_HOOK(adr_swap_buffers, n_hooked::hk_swap_buffers); 12 | CREATE_HOOK(adr_create_move, n_hooked::hk_createmove); 13 | 14 | n_detour::enable(); 15 | 16 | return true; 17 | } 18 | 19 | // @todo: fix crash on detach 20 | void s_hooks::cleanup() { 21 | // unhook wndproc 22 | SetWindowLong(globals_i.get_game_window(), GWL_WNDPROC, reinterpret_cast(n_hooked::ofn_wndproc)); 23 | 24 | // remove hooks and uninitialize minhook 25 | MH_DisableHook(MH_ALL_HOOKS); 26 | MH_Uninitialize(); 27 | } -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/precompiled.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // windows headers 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include // needed for undocumented functions 10 | 11 | // std headers 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | // sdk includes 25 | #include 26 | 27 | // defines 28 | #define strong_inline __pragma(warning(suppress : 4714)) inline __forceinline 29 | #define mem_likely(x) static_cast(x) 30 | #define mem_unlikely(x) static_cast(x) 31 | 32 | #define IS_CS16 1 // ofc it's gonna be cs 1.6 in this project, it's just for compatibility :P -------------------------------------------------------------------------------- /patoke-sdk-cs16/other/position/g_pos.cpp: -------------------------------------------------------------------------------- 1 | #include "g_pos.hpp" 2 | #include 3 | 4 | #pragma region s_angle 5 | inline s_angle s_angle::normalize() { 6 | this->x = math_i.normalize_angle(this->x); 7 | this->y = math_i.normalize_angle(this->y); 8 | this->z = this->z < 50 && this->z > -50 ? this->z : 0.f; 9 | 10 | return *this; 11 | } 12 | #pragma endregion 13 | 14 | #pragma region s_vec3 15 | inline s_vec3 s_vec3::normalize() { 16 | this->x = std::isfinite(this->x) ? std::remainderf(this->x, 360.0f) : 0.0f; 17 | this->y = std::isfinite(this->y) ? std::remainderf(this->y, 360.0f) : 0.0f; 18 | this->z = 0.0f; 19 | 20 | return *this; 21 | } 22 | 23 | inline float s_vec3::normalize_in_place() { 24 | float radius = sqrt(x * x + y * y + z * z); 25 | 26 | // FLT_EPSILON is added to the radius to eliminate the possibility of division by zero (syn tax eror :3) 27 | float iradius = 1.f / (radius + FLT_EPSILON); 28 | 29 | this->x *= iradius; 30 | this->y *= iradius; 31 | this->z *= iradius; 32 | 33 | return radius; 34 | } 35 | #pragma endregion -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/game/sdk/classes/cmd.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef int (*pfnUserMsgHook)(const char*, int, void*); 4 | #define MAX_ALIAS_NAME 32 5 | 6 | typedef struct ClientUserMsg 7 | { 8 | int msg; 9 | int size; 10 | char name[16]; 11 | struct ClientUserMsg* next; 12 | pfnUserMsgHook pfn; 13 | } *PClientUserMsg; 14 | 15 | typedef struct cmdalias_s 16 | { 17 | struct cmdalias_s* next; 18 | char name[MAX_ALIAS_NAME]; 19 | char* value; 20 | } cmdalias_t; 21 | 22 | typedef struct usercmd_s 23 | { 24 | short lerp_msec; // Interpolation time on client 25 | byte msec; // Duration in ms of command 26 | s_angle viewangles; // Command view angles. 27 | 28 | // intended velocities 29 | float forwardmove; // Forward velocity. 30 | float sidemove; // Sideways velocity. 31 | float upmove; // Upward velocity. 32 | byte lightlevel; // Light level at spot where we are standing. 33 | unsigned short buttons; // Attack buttons 34 | byte impulse; // Impulse command issued. 35 | byte weaponselect; // Current weapon id 36 | 37 | // Experimental player impact stuff. 38 | int impact_index; 39 | s_vec3 impact_position; 40 | 41 | } usercmd_t; -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/initialization/initialization.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | struct s_initialization { 5 | 6 | // init 7 | void init_main(); 8 | 9 | // data init 10 | void init_interfaces(); 11 | void init_static(); 12 | bool init_modules(); 13 | 14 | // cleanup 15 | void cleanup_main(); 16 | 17 | // modules 18 | HMODULE hl_exe; 19 | HMODULE hardware_dll; 20 | HMODULE client_dll; 21 | uintptr_t hl_size; 22 | uintptr_t hardware_size; 23 | uintptr_t client_size; 24 | 25 | // signatures 26 | s_sighelper client_str = s_sighelper(0x13, "ScreenFade"); 27 | s_sighelper engine_str = s_sighelper(0x12, "sprites/%s.spr"); 28 | s_sighelper pmove_str = s_sighelper(0x18, "ScreenFade"); 29 | 30 | } extern initialization_i; 31 | 32 | // modules 33 | extern std::map g_module_list; // global accessor for module list (slow.) 34 | extern std::vector m; // global accessor for modules (fast.) 35 | 36 | // modules to grab 37 | enum e_modules { 38 | GAME, 39 | CLIENT, 40 | HARDWARE, 41 | OPENGL32, 42 | SOFTWARE 43 | }; 44 | 45 | #define DEFINE_MODULE(idx, module_name) m.insert(m.begin() + idx, g_module_list.find(HASH(module_name))->second); -------------------------------------------------------------------------------- /patoke-sdk-cs16/other/memory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // this file shall only be included for addresses grabbed in the s_initialization::init_static function 3 | 4 | // helper for making signature scanning more convenient 5 | struct s_sighelper { 6 | int offset{}; 7 | const char* sig{}; 8 | 9 | constexpr s_sighelper() : offset(0x0), sig("") {} 10 | constexpr s_sighelper(const char* sig) : offset(0x0), sig(sig) {} 11 | constexpr s_sighelper(int offset, const char* sig) : offset(offset), sig(sig) {} 12 | }; 13 | 14 | #define MEMORY_INIT(name, sig_pattern) \ 15 | uintptr_t adr_##name = 0x0; \ 16 | s_sighelper name##_sig = s_sighelper(sig_pattern); 17 | 18 | #define OMEMORY_INIT(name, sig_pattern, sig_offset) \ 19 | uintptr_t adr_##name = 0x0; \ 20 | s_sighelper name##_sig = s_sighelper(sig_offset, sig_pattern); 21 | 22 | struct s_memory { 23 | 24 | // examples (source engine): 25 | //OMEMORY_INIT(prediction_player, "A3 ? ? ? ? 66 ? ? 86", 0x1); 26 | //OMEMORY_INIT(prediction_random_seed, "89 35 ? ? ? ? F3 0F 10 48", 0x2); 27 | 28 | 29 | 30 | } extern memory_i; -------------------------------------------------------------------------------- /patoke-sdk-cs16.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.1.31911.260 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "patoke-sdk-cs16", "patoke-sdk-cs16\patoke-sdk-cs16.vcxproj", "{54570475-7B2F-4949-B398-EA503B30609E}" 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 | {54570475-7B2F-4949-B398-EA503B30609E}.Debug|x64.ActiveCfg = Debug|x64 17 | {54570475-7B2F-4949-B398-EA503B30609E}.Debug|x64.Build.0 = Debug|x64 18 | {54570475-7B2F-4949-B398-EA503B30609E}.Debug|x86.ActiveCfg = Debug|Win32 19 | {54570475-7B2F-4949-B398-EA503B30609E}.Debug|x86.Build.0 = Debug|Win32 20 | {54570475-7B2F-4949-B398-EA503B30609E}.Release|x64.ActiveCfg = Release|x64 21 | {54570475-7B2F-4949-B398-EA503B30609E}.Release|x64.Build.0 = Release|x64 22 | {54570475-7B2F-4949-B398-EA503B30609E}.Release|x86.ActiveCfg = Release|Win32 23 | {54570475-7B2F-4949-B398-EA503B30609E}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {08579FA2-A0A7-4A4A-ADF3-6D73BF117C59} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "initialization/initialization.hpp" 3 | 4 | // create globals instance 5 | s_globals globals_i; 6 | 7 | unsigned long __stdcall main_thread(void* hmodule) { 8 | n_utilities::attach_console("patoke cs 1.6 sdk [debug console]"); 9 | 10 | while (!initialization_i.init_modules()) 11 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); 12 | 13 | while (!globals_i.initialize_window(m[GAME].get())) 14 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); 15 | 16 | initialization_i.init_main(); 17 | 18 | // detach if the end key is pressed 19 | while (!GetAsyncKeyState(VK_HOME)) 20 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); 21 | 22 | FreeLibraryAndExitThread(reinterpret_cast(hmodule), TRUE); 23 | } 24 | 25 | void __stdcall on_detach_module() { 26 | initialization_i.cleanup_main(); 27 | } 28 | 29 | int __stdcall DllMain(HMODULE hmodule, DWORD reason, LPVOID reserved) { 30 | DisableThreadLibraryCalls(hmodule); 31 | 32 | switch (reason) { 33 | case DLL_PROCESS_ATTACH: { 34 | HANDLE thread_instance = CreateThread(nullptr, NULL, main_thread, hmodule, NULL, nullptr); 35 | 36 | if (thread_instance) 37 | CloseHandle(thread_instance); 38 | else 39 | return FALSE; 40 | 41 | } break; 42 | case DLL_PROCESS_DETACH: 43 | if (!reserved) // don't do cleanup when the app is in a closing scenario 44 | on_detach_module(); 45 | break; 46 | } 47 | 48 | return TRUE; 49 | } -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/game/sdk/classes/triapi.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | typedef enum 4 | { 5 | TRI_FRONT = 0, 6 | TRI_NONE = 1, 7 | } TRICULLSTYLE; 8 | 9 | #define TRI_API_VERSION 1 10 | 11 | #define TRI_TRIANGLES 0 12 | #define TRI_TRIANGLE_FAN 1 13 | #define TRI_QUADS 2 14 | #define TRI_POLYGON 3 15 | #define TRI_LINES 4 16 | #define TRI_TRIANGLE_STRIP 5 17 | #define TRI_QUAD_STRIP 6 18 | 19 | typedef struct triangleapi_s { 20 | int version; 21 | 22 | void (*RenderMode)(int mode); 23 | void (*Begin)(int primitiveCode); 24 | void (*End) (void); 25 | 26 | void (*Color4f) (float r, float g, float b, float a); 27 | void (*Color4ub) (unsigned char r, unsigned char g, unsigned char b, unsigned char a); 28 | void (*TexCoord2f) (float u, float v); 29 | void (*Vertex3fv) (float* worldPnt); 30 | void (*Vertex3f) (float x, float y, float z); 31 | void (*Brightness) (float brightness); 32 | void (*CullFace) (TRICULLSTYLE style); 33 | int (*SpriteTexture) (struct model_s* pSpriteModel, int frame); 34 | int (*WorldToScreen) (float* world, float* screen); // Returns 1 if it's z clipped 35 | void (*Fog) (float flFogColor[3], float flStart, float flEnd, int bOn); // Works just like GL_FOG, flFogColor is r/g/b. 36 | void (*ScreenToWorld) (float* screen, float* world); 37 | void (*GetMatrix) (const int pname, float* matrix); 38 | int (*BoxInPVS) (float* mins, float* maxs); 39 | void (*LightAtPoint) (float* pos, float* value); 40 | void (*Color4fRendermode) (float r, float g, float b, float a, int rendermode); 41 | void (*FogParams) (float flDensity, int iFogSkybox); // Used with Fog()...sets fog density and whether the fog should be applied to the skybox 42 | 43 | } triangleapi_t; -------------------------------------------------------------------------------- /patoke-sdk-cs16/other/math/math.cpp: -------------------------------------------------------------------------------- 1 | #include "math.hpp" 2 | 3 | // create math container instance 4 | s_math math_i; 5 | 6 | inline void s_math::sin_cos(float radians, float* sine, float* cosine) const { 7 | *sine = sinf(radians); 8 | *cosine = cosf(radians); 9 | } 10 | 11 | inline float s_math::normalize_angle(float angle, float start, float end) const { 12 | const float width = end - start; 13 | const float offset_angle = angle - start; 14 | 15 | return (offset_angle - (floor(offset_angle / width) * width)) + start; 16 | } 17 | 18 | s_angle s_math::calculate_angle(const s_vec3& source, const s_vec3& destination) { 19 | s_vec3 delta = source - destination; 20 | s_angle angles; 21 | 22 | angles.x = rad2deg(asinf(delta.z / delta.length())); 23 | angles.y = rad2deg(atanf(delta.y / delta.x)); 24 | angles.z = 0.0f; 25 | 26 | if (delta.x >= 0.0) 27 | angles.y += 180.0f; 28 | 29 | return angles; 30 | } 31 | 32 | s_angle s_math::calculate_angle(const s_vec3& source, const s_vec3& destination, const s_angle& viewangles) { 33 | s_vec3 delta = source - destination; 34 | s_angle angles; 35 | 36 | angles.x = rad2deg(asinf(delta.z / delta.length())) - viewangles.x; 37 | angles.y = rad2deg(atanf(delta.y / delta.x)) - viewangles.y; 38 | angles.z = 0.0f; 39 | 40 | if (delta.x >= 0.0) 41 | angles.y += 180.0f; 42 | 43 | return angles; 44 | } 45 | 46 | s_vec3 s_math::vector_transform(const s_vec3& in_vec, const s_matrix3x4& in_matrix, s_vec3& out) { 47 | out.x = in_vec.dot(in_matrix[0]) + in_matrix[0][3]; 48 | out.y = in_vec.dot(in_matrix[1]) + in_matrix[1][3]; 49 | out.z = in_vec.dot(in_matrix[2]) + in_matrix[2][3]; 50 | 51 | return out; 52 | } -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/minhook/hde/pstdint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | // Integer types for HDE. 32 | typedef INT8 int8_t; 33 | typedef INT16 int16_t; 34 | typedef INT32 int32_t; 35 | typedef INT64 int64_t; 36 | typedef UINT8 uint8_t; 37 | typedef UINT16 uint16_t; 38 | typedef UINT32 uint32_t; 39 | typedef UINT64 uint64_t; 40 | -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/minhook/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #pragma once 30 | 31 | // Size of each memory slot. 32 | #if defined(_M_X64) || defined(__x86_64__) 33 | #define MEMORY_SLOT_SIZE 64 34 | #else 35 | #define MEMORY_SLOT_SIZE 32 36 | #endif 37 | 38 | VOID InitializeBuffer(VOID); 39 | VOID UninitializeBuffer(VOID); 40 | LPVOID AllocateBuffer(LPVOID pOrigin); 41 | VOID FreeBuffer(LPVOID pBuffer); 42 | BOOL IsExecutableAddress(LPVOID pAddress); 43 | -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/utilities/pattern/char_queue.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace mem { 5 | class char_queue { 6 | private: 7 | const char* start{ nullptr }; 8 | const char* end{ nullptr }; 9 | const char* current{ nullptr }; 10 | 11 | public: 12 | char_queue(const char* string); 13 | constexpr char_queue(const char* string, std::size_t length); 14 | 15 | constexpr int peek() const noexcept; 16 | 17 | constexpr void pop() noexcept; 18 | constexpr std::size_t pos() const noexcept; 19 | 20 | constexpr explicit operator bool() const noexcept; 21 | }; 22 | 23 | constexpr int xctoi(int value) noexcept; 24 | constexpr int dctoi(int value) noexcept; 25 | constexpr int octoi(int value) noexcept; 26 | 27 | strong_inline char_queue::char_queue(const char* string) 28 | : char_queue(string, std::strlen(string)) 29 | {} 30 | 31 | strong_inline constexpr char_queue::char_queue(const char* string, std::size_t length) 32 | : start(string) 33 | , end(start + length) 34 | , current(start) 35 | {} 36 | 37 | strong_inline constexpr int char_queue::peek() const noexcept { 38 | return (current < end) ? static_cast(*current) : -1; 39 | } 40 | 41 | strong_inline constexpr void char_queue::pop() noexcept { 42 | if (current < end) 43 | ++current; 44 | } 45 | 46 | strong_inline constexpr std::size_t char_queue::pos() const noexcept { 47 | return static_cast(current - start); 48 | } 49 | 50 | strong_inline constexpr char_queue::operator bool() const noexcept { 51 | return current < end; 52 | } 53 | 54 | strong_inline constexpr int xctoi(int value) noexcept { 55 | return (value >= '0' && value <= '9') ? (value - '0') 56 | : (value >= 'a' && value <= 'f') ? (value - 'a' + 10) 57 | : (value >= 'A' && value <= 'F') ? (value - 'A' + 10) 58 | : -1; 59 | } 60 | 61 | strong_inline constexpr int dctoi(int value) noexcept { 62 | return (value >= '0' && value <= '9') ? (value - '0') : -1; 63 | } 64 | 65 | strong_inline constexpr int octoi(int value) noexcept { 66 | return (value >= '0' && value <= '7') ? (value - '0') : -1; 67 | } 68 | } -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/wrappers/hooking.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | // little helper to make the hook function take up only 1 line and less chars 5 | #ifdef _DEBUG 6 | #define CREATE_HOOK(adr, hk_fn) \ 7 | if (!n_detour::hook(adr, hk_fn)) { \ 8 | printf("[x] failed to hook %s: 0x%X\n", #hk_fn, uintptr_t(##adr)); \ 9 | return false; \ 10 | } else \ 11 | printf("[+] hooked %s: 0x%X\n", #hk_fn, uintptr_t(##adr)); 12 | #else 13 | #define CREATE_HOOK(adr, hk_fn) \ 14 | if (!n_detour::hook(adr, hk_fn)) \ 15 | return false 16 | #endif 17 | 18 | namespace n_detour { 19 | struct s_hook { 20 | void *function; 21 | void *original; 22 | }; 23 | 24 | inline std::unordered_map detours; 25 | 26 | static bool hook(void *target, void *fn) { 27 | if (!target || !fn) 28 | return false; 29 | 30 | detours[fn].function = target; 31 | 32 | return MH_CreateHook(target, fn, &detours[fn].original) == MH_OK; 33 | } 34 | 35 | strong_inline bool init() { 36 | return MH_Initialize() == MH_OK; 37 | } 38 | 39 | strong_inline void enable() { 40 | for (auto &detour : detours) 41 | MH_EnableHook(detour.second.function); 42 | } 43 | 44 | strong_inline void restore() { 45 | for (auto &detour : detours) { 46 | MH_DisableHook(detour.second.function); 47 | MH_RemoveHook(detour.second.function); 48 | } 49 | 50 | MH_Uninitialize(); 51 | } 52 | 53 | template 54 | inline t get(void *fn) { 55 | return static_cast(detours[fn].original); 56 | } 57 | } // namespace n_detour -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/minhook/hde/hde32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 3 | * Copyright (c) 2006-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde32.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE32_H_ 11 | #define _HDE32_H_ 12 | 13 | /* stdint.h - C99 standard header 14 | * http://en.wikipedia.org/wiki/stdint.h 15 | * 16 | * if your compiler doesn't contain "stdint.h" header (for 17 | * example, Microsoft Visual C++), you can download file: 18 | * http://www.azillionmonkeys.com/qed/pstdint.h 19 | * and change next line to: 20 | * #include "pstdint.h" 21 | */ 22 | #include "pstdint.h" 23 | 24 | #define F_MODRM 0x00000001 25 | #define F_SIB 0x00000002 26 | #define F_IMM8 0x00000004 27 | #define F_IMM16 0x00000008 28 | #define F_IMM32 0x00000010 29 | #define F_DISP8 0x00000020 30 | #define F_DISP16 0x00000040 31 | #define F_DISP32 0x00000080 32 | #define F_RELATIVE 0x00000100 33 | #define F_2IMM16 0x00000800 34 | #define F_ERROR 0x00001000 35 | #define F_ERROR_OPCODE 0x00002000 36 | #define F_ERROR_LENGTH 0x00004000 37 | #define F_ERROR_LOCK 0x00008000 38 | #define F_ERROR_OPERAND 0x00010000 39 | #define F_PREFIX_REPNZ 0x01000000 40 | #define F_PREFIX_REPX 0x02000000 41 | #define F_PREFIX_REP 0x03000000 42 | #define F_PREFIX_66 0x04000000 43 | #define F_PREFIX_67 0x08000000 44 | #define F_PREFIX_LOCK 0x10000000 45 | #define F_PREFIX_SEG 0x20000000 46 | #define F_PREFIX_ANY 0x3f000000 47 | 48 | #define PREFIX_SEGMENT_CS 0x2e 49 | #define PREFIX_SEGMENT_SS 0x36 50 | #define PREFIX_SEGMENT_DS 0x3e 51 | #define PREFIX_SEGMENT_ES 0x26 52 | #define PREFIX_SEGMENT_FS 0x64 53 | #define PREFIX_SEGMENT_GS 0x65 54 | #define PREFIX_LOCK 0xf0 55 | #define PREFIX_REPNZ 0xf2 56 | #define PREFIX_REPX 0xf3 57 | #define PREFIX_OPERAND_SIZE 0x66 58 | #define PREFIX_ADDRESS_SIZE 0x67 59 | 60 | #pragma pack(push,1) 61 | 62 | typedef struct { 63 | uint8_t len; 64 | uint8_t p_rep; 65 | uint8_t p_lock; 66 | uint8_t p_seg; 67 | uint8_t p_66; 68 | uint8_t p_67; 69 | uint8_t opcode; 70 | uint8_t opcode2; 71 | uint8_t modrm; 72 | uint8_t modrm_mod; 73 | uint8_t modrm_reg; 74 | uint8_t modrm_rm; 75 | uint8_t sib; 76 | uint8_t sib_scale; 77 | uint8_t sib_index; 78 | uint8_t sib_base; 79 | union { 80 | uint8_t imm8; 81 | uint16_t imm16; 82 | uint32_t imm32; 83 | } imm; 84 | union { 85 | uint8_t disp8; 86 | uint16_t disp16; 87 | uint32_t disp32; 88 | } disp; 89 | uint32_t flags; 90 | } hde32s; 91 | 92 | #pragma pack(pop) 93 | 94 | #ifdef __cplusplus 95 | extern "C" { 96 | #endif 97 | 98 | /* __cdecl */ 99 | unsigned int hde32_disasm(const void* code, hde32s* hs); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif /* _HDE32_H_ */ 106 | -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/imgui/imgui_impl_opengl3.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline 2 | // - Desktop GL: 2.x 3.x 4.x 3 | // - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0) 4 | // This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..) 5 | 6 | // Implemented features: 7 | // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! 8 | // [x] Renderer: Desktop GL only: Support for large meshes (64k+ vertices) with 16-bit indices. 9 | 10 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 11 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 12 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 13 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 14 | 15 | // About GLSL version: 16 | // The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string. 17 | // On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es" 18 | // Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp. 19 | 20 | #pragma once 21 | #include "imgui.h" // IMGUI_IMPL_API 22 | 23 | // Backend API 24 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL); 25 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); 26 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame(); 27 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data); 28 | 29 | // (Optional) Called by Init/NewFrame/Shutdown 30 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture(); 31 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture(); 32 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects(); 33 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); 34 | 35 | // Specific OpenGL ES versions 36 | //#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten 37 | //#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android 38 | 39 | // You can explicitly select GLES2 or GLES3 API by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line. 40 | #if !defined(IMGUI_IMPL_OPENGL_ES2) \ 41 | && !defined(IMGUI_IMPL_OPENGL_ES3) 42 | 43 | // Try to detect GLES on matching platforms 44 | #if defined(__APPLE__) 45 | #include 46 | #endif 47 | #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__)) 48 | #define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es" 49 | #elif defined(__EMSCRIPTEN__) || defined(__amigaos4__) 50 | #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" 51 | #else 52 | // Otherwise imgui_impl_opengl3_loader.h will be used. 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/minhook/hde/hde64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde64.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE64_H_ 11 | #define _HDE64_H_ 12 | 13 | /* stdint.h - C99 standard header 14 | * http://en.wikipedia.org/wiki/stdint.h 15 | * 16 | * if your compiler doesn't contain "stdint.h" header (for 17 | * example, Microsoft Visual C++), you can download file: 18 | * http://www.azillionmonkeys.com/qed/pstdint.h 19 | * and change next line to: 20 | * #include "pstdint.h" 21 | */ 22 | #include "pstdint.h" 23 | 24 | #define F_MODRM 0x00000001 25 | #define F_SIB 0x00000002 26 | #define F_IMM8 0x00000004 27 | #define F_IMM16 0x00000008 28 | #define F_IMM32 0x00000010 29 | #define F_IMM64 0x00000020 30 | #define F_DISP8 0x00000040 31 | #define F_DISP16 0x00000080 32 | #define F_DISP32 0x00000100 33 | #define F_RELATIVE 0x00000200 34 | #define F_ERROR 0x00001000 35 | #define F_ERROR_OPCODE 0x00002000 36 | #define F_ERROR_LENGTH 0x00004000 37 | #define F_ERROR_LOCK 0x00008000 38 | #define F_ERROR_OPERAND 0x00010000 39 | #define F_PREFIX_REPNZ 0x01000000 40 | #define F_PREFIX_REPX 0x02000000 41 | #define F_PREFIX_REP 0x03000000 42 | #define F_PREFIX_66 0x04000000 43 | #define F_PREFIX_67 0x08000000 44 | #define F_PREFIX_LOCK 0x10000000 45 | #define F_PREFIX_SEG 0x20000000 46 | #define F_PREFIX_REX 0x40000000 47 | #define F_PREFIX_ANY 0x7f000000 48 | 49 | #define PREFIX_SEGMENT_CS 0x2e 50 | #define PREFIX_SEGMENT_SS 0x36 51 | #define PREFIX_SEGMENT_DS 0x3e 52 | #define PREFIX_SEGMENT_ES 0x26 53 | #define PREFIX_SEGMENT_FS 0x64 54 | #define PREFIX_SEGMENT_GS 0x65 55 | #define PREFIX_LOCK 0xf0 56 | #define PREFIX_REPNZ 0xf2 57 | #define PREFIX_REPX 0xf3 58 | #define PREFIX_OPERAND_SIZE 0x66 59 | #define PREFIX_ADDRESS_SIZE 0x67 60 | 61 | #pragma pack(push,1) 62 | 63 | typedef struct { 64 | uint8_t len; 65 | uint8_t p_rep; 66 | uint8_t p_lock; 67 | uint8_t p_seg; 68 | uint8_t p_66; 69 | uint8_t p_67; 70 | uint8_t rex; 71 | uint8_t rex_w; 72 | uint8_t rex_r; 73 | uint8_t rex_x; 74 | uint8_t rex_b; 75 | uint8_t opcode; 76 | uint8_t opcode2; 77 | uint8_t modrm; 78 | uint8_t modrm_mod; 79 | uint8_t modrm_reg; 80 | uint8_t modrm_rm; 81 | uint8_t sib; 82 | uint8_t sib_scale; 83 | uint8_t sib_index; 84 | uint8_t sib_base; 85 | union { 86 | uint8_t imm8; 87 | uint16_t imm16; 88 | uint32_t imm32; 89 | uint64_t imm64; 90 | } imm; 91 | union { 92 | uint8_t disp8; 93 | uint16_t disp16; 94 | uint32_t disp32; 95 | } disp; 96 | uint32_t flags; 97 | } hde64s; 98 | 99 | #pragma pack(pop) 100 | 101 | #ifdef __cplusplus 102 | extern "C" { 103 | #endif 104 | 105 | /* __cdecl */ 106 | unsigned int hde64_disasm(const void* code, hde64s* hs); 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif /* _HDE64_H_ */ 113 | -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/imgui/imgui_impl_win32.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for Windows (standard windows API for 32 and 64 bits applications) 2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) 3 | 4 | // Implemented features: 5 | // [X] Platform: Clipboard support (for Win32 this is actually part of core dear imgui) 6 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy VK_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] 7 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 8 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 9 | 10 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 11 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 12 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 13 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 14 | 15 | #pragma once 16 | #include "imgui.h" // IMGUI_IMPL_API 17 | 18 | IMGUI_IMPL_API bool ImGui_ImplWin32_Init(void* hwnd); 19 | IMGUI_IMPL_API void ImGui_ImplWin32_Shutdown(); 20 | IMGUI_IMPL_API void ImGui_ImplWin32_NewFrame(); 21 | 22 | // Win32 message handler your application need to call. 23 | // - Intentionally commented out in a '#if 0' block to avoid dragging dependencies on from this helper. 24 | // - You should COPY the line below into your .cpp code to forward declare the function and then you can call it. 25 | // - Call from your application's message handler. Keep calling your message handler unless this function returns TRUE. 26 | 27 | #if 0 28 | extern IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); 29 | #endif 30 | 31 | // DPI-related helpers (optional) 32 | // - Use to enable DPI awareness without having to create an application manifest. 33 | // - Your own app may already do this via a manifest or explicit calls. This is mostly useful for our examples/ apps. 34 | // - In theory we could call simple functions from Windows SDK such as SetProcessDPIAware(), SetProcessDpiAwareness(), etc. 35 | // but most of the functions provided by Microsoft require Windows 8.1/10+ SDK at compile time and Windows 8/10+ at runtime, 36 | // neither we want to require the user to have. So we dynamically select and load those functions to avoid dependencies. 37 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableDpiAwareness(); 38 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForHwnd(void* hwnd); // HWND hwnd 39 | IMGUI_IMPL_API float ImGui_ImplWin32_GetDpiScaleForMonitor(void* monitor); // HMONITOR monitor 40 | 41 | // Transparency related helpers (optional) [experimental] 42 | // - Use to enable alpha compositing transparency with the desktop. 43 | // - Use together with e.g. clearing your framebuffer with zero-alpha. 44 | IMGUI_IMPL_API void ImGui_ImplWin32_EnableAlphaCompositing(void* hwnd); // HWND hwnd 45 | -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/game/sdk/classes/bspfile.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define BSPVERSION 30 4 | #define MAX_MAP_HULLS 4 5 | 6 | #define CONTENTS_ORIGIN -7 // removed at csg time 7 | #define CONTENTS_CLIP -8 // changed to contents_solid 8 | #define CONTENTS_CURRENT_0 -9 9 | #define CONTENTS_CURRENT_90 -10 10 | #define CONTENTS_CURRENT_180 -11 11 | #define CONTENTS_CURRENT_270 -12 12 | #define CONTENTS_CURRENT_UP -13 13 | #define CONTENTS_CURRENT_DOWN -14 14 | 15 | #define CONTENTS_TRANSLUCENT -15 16 | 17 | #define LUMP_ENTITIES 0 18 | #define LUMP_PLANES 1 19 | #define LUMP_TEXTURES 2 20 | #define LUMP_VERTEXES 3 21 | #define LUMP_VISIBILITY 4 22 | #define LUMP_NODES 5 23 | #define LUMP_TEXINFO 6 24 | #define LUMP_FACES 7 25 | #define LUMP_LIGHTING 8 26 | #define LUMP_CLIPNODES 9 27 | #define LUMP_LEAFS 10 28 | #define LUMP_MARKSURFACES 11 29 | #define LUMP_EDGES 12 30 | #define LUMP_SURFEDGES 13 31 | #define LUMP_MODELS 14 32 | 33 | #define HEADER_LUMPS 15 34 | 35 | /* ../engine/bspfile.h:41 */ 36 | typedef struct lump_s 37 | { 38 | int fileofs; 39 | int filelen; 40 | 41 | } lump_t; 42 | 43 | /* ../engine/bspfile.h:64 */ 44 | typedef struct dmodel_s 45 | { 46 | float mins[3], maxs[3]; 47 | float origin[3]; 48 | int headnode[MAX_MAP_HULLS]; 49 | int visleafs; // not including the solid leaf 0 50 | int firstface, numfaces; 51 | 52 | } dmodel_t; 53 | 54 | /* ../engine/bspfile.h:73 */ 55 | typedef struct dheader_s 56 | { 57 | int version; 58 | lump_t lumps[15]; 59 | 60 | } dheader_t; 61 | 62 | /* <485b2> ../engine/bspfile.h:79 */ 63 | typedef struct dmiptexlump_s 64 | { 65 | int _nummiptex; 66 | int dataofs[4]; 67 | 68 | } dmiptexlump_t; 69 | 70 | /* <1ce18> ../engine/bspfile.h:86 */ 71 | typedef struct miptex_s 72 | { 73 | char name[16]; 74 | unsigned width; 75 | unsigned height; 76 | unsigned offsets[4]; 77 | 78 | } miptex_t; 79 | 80 | /* <48652> ../engine/bspfile.h:94 */ 81 | typedef struct dvertex_s 82 | { 83 | float point[3]; 84 | 85 | } dvertex_t; 86 | 87 | /* <48674> ../engine/bspfile.h:110 */ 88 | typedef struct dplane_s 89 | { 90 | float normal[3]; 91 | float dist; 92 | int type; 93 | 94 | } dplane_t; 95 | 96 | /* <486b2> ../engine/bspfile.h:132 */ 97 | typedef struct dnode_s 98 | { 99 | int planenum; 100 | short children[2]; 101 | short mins[3]; 102 | short maxs[3]; 103 | unsigned short firstface; 104 | unsigned short numfaces; 105 | 106 | } dnode_t; 107 | 108 | /* ../engine/bspfile.h:142 */ 109 | typedef struct dclipnode_s 110 | { 111 | int planenum; 112 | short children[2]; // negative numbers are contents 113 | 114 | } dclipnode_t; 115 | 116 | /* <4876a> ../engine/bspfile.h:149 */ 117 | typedef struct texinfo_s 118 | { 119 | float vecs[2][4]; 120 | int _miptex; 121 | int flags; 122 | 123 | } texinfo_t; 124 | 125 | /* <487c2> ../engine/bspfile.h:159 */ 126 | typedef struct dedge_s 127 | { 128 | unsigned short v[2]; 129 | 130 | } dedge_t; 131 | 132 | /* <487f2> ../engine/bspfile.h:165 */ 133 | typedef struct dface_s 134 | { 135 | short planenum; 136 | short side; 137 | int firstedge; 138 | short numedges; 139 | short texinfo; 140 | byte styles[4]; 141 | int lightofs; 142 | 143 | } dface_t; 144 | 145 | typedef struct dleaf_s 146 | { 147 | int contents; 148 | int visofs; 149 | short mins[3]; 150 | short maxs[3]; 151 | unsigned short firstmarksurface; 152 | unsigned short nummarksurfaces; 153 | byte ambient_level[4]; 154 | 155 | } dleaf_t; -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/minhook/hde/table32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #define C_NONE 0x00 9 | #define C_MODRM 0x01 10 | #define C_IMM8 0x02 11 | #define C_IMM16 0x04 12 | #define C_IMM_P66 0x10 13 | #define C_REL8 0x20 14 | #define C_REL32 0x40 15 | #define C_GROUP 0x80 16 | #define C_ERROR 0xff 17 | 18 | #define PRE_ANY 0x00 19 | #define PRE_NONE 0x01 20 | #define PRE_F2 0x02 21 | #define PRE_F3 0x04 22 | #define PRE_66 0x08 23 | #define PRE_67 0x10 24 | #define PRE_LOCK 0x20 25 | #define PRE_SEG 0x40 26 | #define PRE_ALL 0xff 27 | 28 | #define DELTA_OPCODES 0x4a 29 | #define DELTA_FPU_REG 0xf1 30 | #define DELTA_FPU_MODRM 0xf8 31 | #define DELTA_PREFIXES 0x130 32 | #define DELTA_OP_LOCK_OK 0x1a1 33 | #define DELTA_OP2_LOCK_OK 0x1b9 34 | #define DELTA_OP_ONLY_MEM 0x1cb 35 | #define DELTA_OP2_ONLY_MEM 0x1da 36 | 37 | unsigned char hde32_table[] = { 38 | 0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3, 39 | 0xa8,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xac,0xaa,0xb2,0xaa,0x9f,0x9f, 40 | 0x9f,0x9f,0xb5,0xa3,0xa3,0xa4,0xaa,0xaa,0xba,0xaa,0x96,0xaa,0xa8,0xaa,0xc3, 41 | 0xc3,0x96,0x96,0xb7,0xae,0xd6,0xbd,0xa3,0xc5,0xa3,0xa3,0x9f,0xc3,0x9c,0xaa, 42 | 0xaa,0xac,0xaa,0xbf,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0x90, 43 | 0x82,0x7d,0x97,0x59,0x59,0x59,0x59,0x59,0x7f,0x59,0x59,0x60,0x7d,0x7f,0x7f, 44 | 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x9a,0x88,0x7d, 45 | 0x59,0x50,0x50,0x50,0x50,0x59,0x59,0x59,0x59,0x61,0x94,0x61,0x9e,0x59,0x59, 46 | 0x85,0x59,0x92,0xa3,0x60,0x60,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59, 47 | 0x59,0x59,0x9f,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xcc,0x01,0xbc,0x03,0xf0, 48 | 0x10,0x10,0x10,0x10,0x50,0x50,0x50,0x50,0x14,0x20,0x20,0x20,0x20,0x01,0x01, 49 | 0x01,0x01,0xc4,0x02,0x10,0x00,0x00,0x00,0x00,0x01,0x01,0xc0,0xc2,0x10,0x11, 50 | 0x02,0x03,0x11,0x03,0x03,0x04,0x00,0x00,0x14,0x00,0x02,0x00,0x00,0xc6,0xc8, 51 | 0x02,0x02,0x02,0x02,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0xca, 52 | 0x01,0x01,0x01,0x00,0x06,0x00,0x04,0x00,0xc0,0xc2,0x01,0x01,0x03,0x01,0xff, 53 | 0xff,0x01,0x00,0x03,0xc4,0xc4,0xc6,0x03,0x01,0x01,0x01,0xff,0x03,0x03,0x03, 54 | 0xc8,0x40,0x00,0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00, 55 | 0x00,0x00,0x00,0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00, 56 | 0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 57 | 0x00,0xff,0xff,0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 58 | 0x7f,0x00,0x00,0xff,0x4a,0x4a,0x4a,0x4a,0x4b,0x52,0x4a,0x4a,0x4a,0x4a,0x4f, 59 | 0x4c,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x55,0x45,0x40,0x4a,0x4a,0x4a, 60 | 0x45,0x59,0x4d,0x46,0x4a,0x5d,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a, 61 | 0x4a,0x4a,0x4a,0x4a,0x4a,0x61,0x63,0x67,0x4e,0x4a,0x4a,0x6b,0x6d,0x4a,0x4a, 62 | 0x45,0x6d,0x4a,0x4a,0x44,0x45,0x4a,0x4a,0x00,0x00,0x00,0x02,0x0d,0x06,0x06, 63 | 0x06,0x06,0x0e,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x00,0x06,0x06,0x02,0x06, 64 | 0x00,0x0a,0x0a,0x07,0x07,0x06,0x02,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04, 65 | 0x04,0x04,0x00,0x00,0x00,0x0e,0x05,0x06,0x06,0x06,0x01,0x06,0x00,0x00,0x08, 66 | 0x00,0x10,0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01, 67 | 0x86,0x00,0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba, 68 | 0xf8,0xbb,0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00, 69 | 0xc4,0xff,0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00, 70 | 0x13,0x09,0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07, 71 | 0xb2,0xff,0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf, 72 | 0xe7,0x08,0x00,0xf0,0x02,0x00 73 | }; 74 | -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/minhook/hde/table64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #define C_NONE 0x00 9 | #define C_MODRM 0x01 10 | #define C_IMM8 0x02 11 | #define C_IMM16 0x04 12 | #define C_IMM_P66 0x10 13 | #define C_REL8 0x20 14 | #define C_REL32 0x40 15 | #define C_GROUP 0x80 16 | #define C_ERROR 0xff 17 | 18 | #define PRE_ANY 0x00 19 | #define PRE_NONE 0x01 20 | #define PRE_F2 0x02 21 | #define PRE_F3 0x04 22 | #define PRE_66 0x08 23 | #define PRE_67 0x10 24 | #define PRE_LOCK 0x20 25 | #define PRE_SEG 0x40 26 | #define PRE_ALL 0xff 27 | 28 | #define DELTA_OPCODES 0x4a 29 | #define DELTA_FPU_REG 0xfd 30 | #define DELTA_FPU_MODRM 0x104 31 | #define DELTA_PREFIXES 0x13c 32 | #define DELTA_OP_LOCK_OK 0x1ae 33 | #define DELTA_OP2_LOCK_OK 0x1c6 34 | #define DELTA_OP_ONLY_MEM 0x1d8 35 | #define DELTA_OP2_ONLY_MEM 0x1e7 36 | 37 | unsigned char hde64_table[] = { 38 | 0xa5,0xaa,0xa5,0xb8,0xa5,0xaa,0xa5,0xaa,0xa5,0xb8,0xa5,0xb8,0xa5,0xb8,0xa5, 39 | 0xb8,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xac,0xc0,0xcc,0xc0,0xa1,0xa1, 40 | 0xa1,0xa1,0xb1,0xa5,0xa5,0xa6,0xc0,0xc0,0xd7,0xda,0xe0,0xc0,0xe4,0xc0,0xea, 41 | 0xea,0xe0,0xe0,0x98,0xc8,0xee,0xf1,0xa5,0xd3,0xa5,0xa5,0xa1,0xea,0x9e,0xc0, 42 | 0xc0,0xc2,0xc0,0xe6,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0xab, 43 | 0x8b,0x90,0x64,0x5b,0x5b,0x5b,0x5b,0x5b,0x92,0x5b,0x5b,0x76,0x90,0x92,0x92, 44 | 0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x6a,0x73,0x90, 45 | 0x5b,0x52,0x52,0x52,0x52,0x5b,0x5b,0x5b,0x5b,0x77,0x7c,0x77,0x85,0x5b,0x5b, 46 | 0x70,0x5b,0x7a,0xaf,0x76,0x76,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b, 47 | 0x5b,0x5b,0x86,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xd5,0x03,0xcc,0x01,0xbc, 48 | 0x03,0xf0,0x03,0x03,0x04,0x00,0x50,0x50,0x50,0x50,0xff,0x20,0x20,0x20,0x20, 49 | 0x01,0x01,0x01,0x01,0xc4,0x02,0x10,0xff,0xff,0xff,0x01,0x00,0x03,0x11,0xff, 50 | 0x03,0xc4,0xc6,0xc8,0x02,0x10,0x00,0xff,0xcc,0x01,0x01,0x01,0x00,0x00,0x00, 51 | 0x00,0x01,0x01,0x03,0x01,0xff,0xff,0xc0,0xc2,0x10,0x11,0x02,0x03,0x01,0x01, 52 | 0x01,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x10, 53 | 0x10,0x10,0x10,0x02,0x10,0x00,0x00,0xc6,0xc8,0x02,0x02,0x02,0x02,0x06,0x00, 54 | 0x04,0x00,0x02,0xff,0x00,0xc0,0xc2,0x01,0x01,0x03,0x03,0x03,0xca,0x40,0x00, 55 | 0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00,0x00,0x00,0x00, 56 | 0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0xff,0x00, 57 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff, 58 | 0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x00, 59 | 0xff,0x40,0x40,0x40,0x40,0x41,0x49,0x40,0x40,0x40,0x40,0x4c,0x42,0x40,0x40, 60 | 0x40,0x40,0x40,0x40,0x40,0x40,0x4f,0x44,0x53,0x40,0x40,0x40,0x44,0x57,0x43, 61 | 0x5c,0x40,0x60,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, 62 | 0x40,0x40,0x64,0x66,0x6e,0x6b,0x40,0x40,0x6a,0x46,0x40,0x40,0x44,0x46,0x40, 63 | 0x40,0x5b,0x44,0x40,0x40,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x01,0x06, 64 | 0x06,0x02,0x06,0x06,0x00,0x06,0x00,0x0a,0x0a,0x00,0x00,0x00,0x02,0x07,0x07, 65 | 0x06,0x02,0x0d,0x06,0x06,0x06,0x0e,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04, 66 | 0x04,0x04,0x05,0x06,0x06,0x06,0x00,0x00,0x00,0x0e,0x00,0x00,0x08,0x00,0x10, 67 | 0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01,0x86,0x00, 68 | 0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba,0xf8,0xbb, 69 | 0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00,0xc4,0xff, 70 | 0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00,0x13,0x09, 71 | 0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07,0xb2,0xff, 72 | 0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf,0xe7,0x08, 73 | 0x00,0xf0,0x02,0x00 74 | }; 75 | -------------------------------------------------------------------------------- /patoke-sdk-cs16/other/globals.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include <../main/ui/ui.hpp> 6 | #include <../main/game/interfaces.hpp> 7 | 8 | struct s_entity { 9 | cl_entity_s* ent; 10 | 11 | int index; 12 | int message_num; 13 | int observer_state; 14 | int observer_index; 15 | int use_hull; 16 | int flags; 17 | int movetype; 18 | int waterlevel; 19 | 20 | bool is_valid; 21 | bool is_local; 22 | bool is_alive; 23 | bool is_dormant; // in pvs 24 | 25 | s_vec3 origin; 26 | s_vec3 velocity; 27 | s_vec3 eye_pos; 28 | s_matrix3x4 bone_matrix[MAXSTUDIOBONES]; 29 | s_vec3 hitboxes[HITBOX_MAX]; 30 | 31 | void update_bones() { 32 | // @todo: reimplement this 33 | // do better entity list stuff and get bones and all that's possible in StudioDrawModel 34 | } 35 | 36 | void update_local() { 37 | if (!interfaces_i.pmove) 38 | return; 39 | 40 | this->use_hull = interfaces_i.pmove->usehull; 41 | this->origin = interfaces_i.pmove->origin; 42 | this->velocity = interfaces_i.pmove->velocity; 43 | this->eye_pos = this->origin + interfaces_i.pmove->view_ofs; 44 | this->flags = interfaces_i.pmove->flags; 45 | this->movetype = interfaces_i.pmove->movetype; 46 | this->waterlevel = interfaces_i.pmove->waterlevel; 47 | 48 | // the local player can't go dormant, we assume it's dormant when we die but this is incorrect 49 | if (this->is_alive) 50 | this->is_dormant = true; 51 | else 52 | this->is_dormant = false; 53 | } 54 | 55 | void update(cl_entity_s* ent, bool is_local) { 56 | if (!ent) 57 | return; 58 | 59 | this->ent = ent; 60 | this->index = this->ent->index; 61 | 62 | // don't update the local player over 1 time 63 | cl_entity_s* local = interfaces_i.engine->GetLocalPlayer(); // only used for some stuff 64 | if (!is_local && this->index == local->index) { 65 | this->is_valid = false; 66 | return; 67 | } 68 | 69 | this->is_valid = this->ent && this->ent->model && this->ent->player && this->index && this->index > 0 && this->index < MAX_CLIENTS; 70 | 71 | if (!this->is_valid) 72 | return; 73 | 74 | this->message_num = this->ent->curstate.messagenum; 75 | this->observer_state = this->ent->curstate.iuser1; 76 | this->observer_index = this->ent->curstate.iuser2; 77 | 78 | this->is_alive = !this->observer_state; 79 | 80 | this->is_local = is_local; 81 | if (this->is_local) 82 | return update_local(); 83 | 84 | // player is dormant, don't update 85 | if (this->message_num < local->curstate.messagenum) { 86 | this->is_valid = false; 87 | this->is_dormant = true; 88 | return; 89 | } 90 | 91 | this->is_dormant = false; 92 | this->use_hull = this->ent->curstate.usehull; 93 | this->origin = this->ent->origin; 94 | // calculate their velocity (i don't think it's networked?) 95 | this->velocity = (this->ent->curstate.origin - this->ent->prevstate.origin) / (this->ent->curstate.animtime - this->ent->prevstate.animtime); 96 | this->eye_pos = this->origin + s_vec3(0, 0, this->use_hull == DUCKED_HULL ? PM_VEC_DUCK_VIEW : PM_VEC_VIEW); 97 | } 98 | }; 99 | 100 | struct s_globals { 101 | 102 | // don't use this raw, please use the get_game_window() wrapper 103 | void* game_window; 104 | unsigned long game_pid; 105 | 106 | // game specific 107 | s_entity local_player; 108 | std::array entity_list; 109 | 110 | bool initialize_window(uintptr_t game_base) { 111 | game_window = reinterpret_cast(game_base); 112 | 113 | if (!game_window) 114 | return false; 115 | 116 | game_pid = _getpid(); 117 | 118 | if (!game_pid) 119 | return false; 120 | 121 | return true; 122 | } 123 | 124 | template 125 | constexpr type get_game_window() { 126 | return reinterpret_cast(game_window); 127 | } 128 | 129 | } extern globals_i; -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/game/interfaces.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "sdk/hlsdk.hpp" 3 | 4 | struct s_module { 5 | template 6 | constexpr type get() { 7 | return reinterpret_cast(module_address); 8 | } 9 | constexpr uintptr_t get() { 10 | return module_address; 11 | } 12 | 13 | template 14 | void* find_signature(s_sighelper& sig) { 15 | if (relative) 16 | return n_utilities::find_signature((HMODULE)this->module_address, sig).relative(); 17 | else 18 | return n_utilities::find_signature((HMODULE)this->module_address, sig).cast(); 19 | } 20 | 21 | template 22 | strong_inline type find_signature(s_sighelper& sig) { 23 | return reinterpret_cast(this->find_signature(sig)); 24 | } 25 | 26 | strong_inline bool address_in_module(uintptr_t addr) { 27 | return addr > this->module_address 28 | #if IS_CS16 29 | && addr < (this->module_address + this->module_size) 30 | #endif 31 | ; 32 | } 33 | 34 | #if IS_CS16 35 | template 36 | type get_interface(const char* interface_name) { 37 | auto create_interface_fn = n_utilities::get_export_from_table(this->module_address, HASH("CreateInterface")); 38 | return create_interface_fn(interface_name, NULL); 39 | } 40 | #endif 41 | 42 | #ifdef _DEBUG 43 | char module_name[64]; // just make it 64 bytes, we don't need more... 44 | #endif 45 | uintptr_t module_address; 46 | #if IS_CS16 47 | uintptr_t module_size; 48 | #endif 49 | }; 50 | 51 | struct s_interfaces { 52 | 53 | cl_clientfunc_t* client; 54 | cl_enginefunc_t* engine; 55 | playermove_t* pmove; 56 | engine_studio_api_t* studio; 57 | r_studio_interface_t* studio_api; 58 | c_studiomodelrenderer* studio_model; 59 | 60 | template 61 | static type grab(uintptr_t address) { 62 | #ifdef _DEBUG 63 | const char* type_name = typeid(type).name(); 64 | #endif 65 | 66 | auto iface = reinterpret_cast(address); 67 | 68 | for (unsigned int i = 0; i < dereference_count; i++) 69 | iface = *reinterpret_cast(iface); 70 | 71 | #ifdef _DEBUG 72 | printf("[+] %s: 0x%X\n", type_name, uintptr_t(iface)); 73 | #endif 74 | 75 | // fix for protected regions 76 | memcpy(&iface, iface, sizeof(iface)); 77 | 78 | return iface; 79 | } 80 | 81 | template 82 | static type grab(s_module mod, uintptr_t start_addr, std::vector addresses) { 83 | #ifdef _DEBUG 84 | const char* type_name = typeid(type).name(); 85 | #endif 86 | 87 | type iface = reinterpret_cast(start_addr); 88 | for (size_t i = 0; i < addresses.size(); i++) { 89 | // make sure we point to the right thing 90 | type iface_copy = *reinterpret_cast(start_addr + addresses.at(i));; 91 | 92 | // we found the interface 93 | if (mod.address_in_module((uintptr_t)iface_copy)) { 94 | iface = reinterpret_cast(start_addr + addresses.at(i)); 95 | break; 96 | } 97 | #ifdef _DEBUG 98 | else 99 | printf("[!] didn't find %s (offset: 0x%X)\n", type_name, addresses.at(i)); 100 | #endif 101 | } 102 | 103 | for (unsigned int i = 0; i < dereference_count; i++) 104 | iface = *reinterpret_cast(iface); 105 | 106 | #ifdef _DEBUG 107 | printf("[+] %s: 0x%X\n", type_name, uintptr_t(iface)); 108 | #endif 109 | 110 | // fix for protected regions 111 | memcpy(&iface, iface, sizeof(iface)); 112 | 113 | return iface; 114 | } 115 | 116 | } extern interfaces_i; -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/minhook/trampoline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #pragma once 30 | 31 | #pragma pack(push, 1) 32 | 33 | // Structs for writing x86/x64 instructions. 34 | 35 | // 8-bit relative jump. 36 | typedef struct _JMP_REL_SHORT 37 | { 38 | UINT8 opcode; // EB xx: JMP +2+xx 39 | UINT8 operand; 40 | } JMP_REL_SHORT, * PJMP_REL_SHORT; 41 | 42 | // 32-bit direct relative jump/call. 43 | typedef struct _JMP_REL 44 | { 45 | UINT8 opcode; // E9/E8 xxxxxxxx: JMP/CALL +5+xxxxxxxx 46 | UINT32 operand; // Relative destination address 47 | } JMP_REL, * PJMP_REL, CALL_REL; 48 | 49 | // 64-bit indirect absolute jump. 50 | typedef struct _JMP_ABS 51 | { 52 | UINT8 opcode0; // FF25 00000000: JMP [+6] 53 | UINT8 opcode1; 54 | UINT32 dummy; 55 | UINT64 address; // Absolute destination address 56 | } JMP_ABS, * PJMP_ABS; 57 | 58 | // 64-bit indirect absolute call. 59 | typedef struct _CALL_ABS 60 | { 61 | UINT8 opcode0; // FF15 00000002: CALL [+6] 62 | UINT8 opcode1; 63 | UINT32 dummy0; 64 | UINT8 dummy1; // EB 08: JMP +10 65 | UINT8 dummy2; 66 | UINT64 address; // Absolute destination address 67 | } CALL_ABS; 68 | 69 | // 32-bit direct relative conditional jumps. 70 | typedef struct _JCC_REL 71 | { 72 | UINT8 opcode0; // 0F8* xxxxxxxx: J** +6+xxxxxxxx 73 | UINT8 opcode1; 74 | UINT32 operand; // Relative destination address 75 | } JCC_REL; 76 | 77 | // 64bit indirect absolute conditional jumps that x64 lacks. 78 | typedef struct _JCC_ABS 79 | { 80 | UINT8 opcode; // 7* 0E: J** +16 81 | UINT8 dummy0; 82 | UINT8 dummy1; // FF25 00000000: JMP [+6] 83 | UINT8 dummy2; 84 | UINT32 dummy3; 85 | UINT64 address; // Absolute destination address 86 | } JCC_ABS; 87 | 88 | #pragma pack(pop) 89 | 90 | typedef struct _TRAMPOLINE 91 | { 92 | LPVOID pTarget; // [In] Address of the target function. 93 | LPVOID pDetour; // [In] Address of the detour function. 94 | LPVOID pTrampoline; // [In] Buffer address for the trampoline and relay function. 95 | 96 | #if defined(_M_X64) || defined(__x86_64__) 97 | LPVOID pRelay; // [Out] Address of the relay function. 98 | #endif 99 | BOOL patchAbove; // [Out] Should use the hot patch area? 100 | UINT nIP; // [Out] Number of the instruction boundaries. 101 | UINT8 oldIPs[8]; // [Out] Instruction boundaries of the target function. 102 | UINT8 newIPs[8]; // [Out] Instruction boundaries of the trampoline function. 103 | } TRAMPOLINE, * PTRAMPOLINE; 104 | 105 | BOOL CreateTrampolineFunction(PTRAMPOLINE ct); 106 | -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/initialization/initialization.cpp: -------------------------------------------------------------------------------- 1 | #include "initialization.hpp" 2 | #include "../hooks/hooks.hpp" 3 | #include "../game/interfaces.hpp" 4 | 5 | // create init variables 6 | s_initialization initialization_i; 7 | s_interfaces interfaces_i; 8 | s_hooks hooks_i; 9 | s_render render_i; 10 | 11 | // initialize module list 12 | std::map g_module_list; // global accessor for module list (slow.) 13 | std::vector m; // global accessor for modules (fast.) 14 | 15 | void s_initialization::init_main() { 16 | 17 | init_interfaces(); 18 | //init_static(); 19 | 20 | if (!hooks_i.initialize()) 21 | ; // do something 22 | } 23 | 24 | void s_initialization::cleanup_main() { 25 | hooks_i.cleanup(); 26 | n_utilities::detach_console(); 27 | } 28 | 29 | bool s_initialization::init_modules() { 30 | // the size of an int is 4 in 32 bits, 8 in 64 bits, and so on, this will work for any build arch 31 | constexpr unsigned int peb_offset = 0x30 * (sizeof(unsigned int) / 4); 32 | auto peb = reinterpret_cast(__readfsdword(peb_offset)); 33 | 34 | LIST_ENTRY list_head = peb->Ldr->InMemoryOrderModuleList; 35 | LIST_ENTRY list_curr = list_head; 36 | 37 | // get modules every time we know the game hasn't fully loaded 38 | while (g_module_list.find(HASH("serverbrowser.dll")) == g_module_list.end()) { 39 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); // don't kill pc pls 40 | 41 | for (auto list_curr = list_head; list_curr.Flink != &peb->Ldr->InMemoryOrderModuleList; list_curr = *list_curr.Flink) { 42 | auto mod = CONTAINING_RECORD(list_curr.Flink, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks); 43 | 44 | // module has a valid name 45 | if (mod->BaseDllName.Buffer) { 46 | // convert unicode to multibyte 47 | char mod_name[128]; 48 | wcstombs(mod_name, mod->BaseDllName.Buffer, mod->BaseDllName.Length); 49 | 50 | auto mod_name_hash = HASH(mod_name); 51 | 52 | // if this module already exists in our map 53 | if (g_module_list.find(mod_name_hash) != g_module_list.end()) 54 | continue; 55 | 56 | s_module new_module{}; 57 | #ifdef _DEBUG 58 | strcpy(new_module.module_name, mod_name); 59 | #endif 60 | new_module.module_address = reinterpret_cast(mod->DllBase); 61 | 62 | #if IS_CS16 63 | new_module.module_size = mod->SizeOfImage; 64 | #endif 65 | 66 | g_module_list.insert({ mod_name_hash, new_module }); 67 | } 68 | } 69 | } 70 | 71 | // add new modules here (please wait until i figure out a way to get them all in 1 shot) 72 | DEFINE_MODULE(GAME, "hl.exe"); // get this using the first grabbed module index, some anticheats change the module name :P 73 | DEFINE_MODULE(CLIENT, "client.dll"); 74 | DEFINE_MODULE(HARDWARE, "hw.dll"); // probably call this engine? 75 | DEFINE_MODULE(OPENGL32, "OPENGL32.dll"); 76 | 77 | // do this another way if possible, this is only a placeholder until i fix crash on module definition 78 | if (!m[HARDWARE].get()) 79 | DEFINE_MODULE(SOFTWARE, "sw.dll"); // this isn't ever going to be used as hardware replaces all these 80 | 81 | // fix modules 82 | char hardware_fallback = 0; // (for hardcoded sizes) 0 = hardware, 1 = software, 2 = neither (under version 3k) 83 | if (!m[HARDWARE].get() && m[SOFTWARE].get()) 84 | m[HARDWARE] = m[SOFTWARE]; // for cross compatibility 85 | 86 | if (!m[HARDWARE].get()) 87 | m[HARDWARE] = m[GAME]; // for cross compatibility 88 | 89 | if (!m[HARDWARE].module_size) { 90 | // set it to values we already knew beforehand 91 | switch (hardware_fallback) { 92 | case 0: m[HARDWARE].module_size = 0x122A000; break; // hardware 93 | case 1: m[HARDWARE].module_size = 0xB53000; break; // software 94 | case 2: m[HARDWARE].module_size = 0x2116000; break; // neither 95 | } 96 | } 97 | 98 | if (!m[CLIENT].get()) 99 | m[CLIENT] = m[HARDWARE]; // for cross compatibility 100 | 101 | bool failed_to_grab_modules = false; 102 | for (auto& hmodule : m) { 103 | if (!hmodule.get()) { 104 | failed_to_grab_modules = true; 105 | #ifdef _DEBUG 106 | #if IS_CS16 107 | printf("[-] failed to grab %s (size: 0x%X)\n", hmodule.module_name, hmodule.module_size); 108 | } 109 | else { 110 | printf("[+] %s: 0x%X (size: 0x%X)\n", hmodule.module_name, hmodule.get(), hmodule.module_size); 111 | #else 112 | printf("[-] failed to grab %s\n", hmodule.module_name); 113 | } 114 | else { 115 | printf("[+] %s: 0x%X\n", hmodule.module_name, hmodule.get()); 116 | #endif 117 | #endif 118 | } 119 | } 120 | 121 | return !failed_to_grab_modules; 122 | } 123 | 124 | void s_initialization::init_interfaces() { 125 | if (!init_modules()) 126 | return; 127 | 128 | interfaces_i.client = s_interfaces::grab(n_utilities::find_str_ref(m[HARDWARE].get(), m[HARDWARE].module_size, client_str)); 129 | interfaces_i.engine = s_interfaces::grab(n_utilities::find_str_ref(m[CLIENT].get(), m[HARDWARE].module_size, engine_str)); 130 | interfaces_i.pmove = s_interfaces::grab(n_utilities::find_str_ref(m[HARDWARE].get(), m[HARDWARE].module_size, pmove_str)); 131 | 132 | interfaces_i.studio = s_interfaces::grab(m[CLIENT], (uintptr_t)interfaces_i.client->HUD_GetStudioModelInterface, { 0x30, 0x1A }); 133 | interfaces_i.studio_api = s_interfaces::grab(m[CLIENT], (uintptr_t)interfaces_i.client->HUD_GetStudioModelInterface, { 0x36, 0x20 }); 134 | interfaces_i.studio_model = s_interfaces::grab(m[CLIENT], (uintptr_t)interfaces_i.studio_api->StudioDrawModel, { 0x5 }); 135 | } 136 | 137 | void s_initialization::init_static() { 138 | 139 | } -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/game/sdk/classes/r_studioint.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "const.hpp" 3 | 4 | typedef struct engine_studio_api_s 5 | { 6 | // Allocate number*size bytes and zero it 7 | void* (*Mem_Calloc) (int number, size_t size); 8 | // Check to see if pointer is in the cache 9 | void* (*Cache_Check) (struct cache_user_s* c); 10 | // Load file into cache ( can be swapped out on demand ) 11 | void (*LoadCacheFile) (char* path, struct cache_user_s* cu); 12 | // Retrieve model pointer for the named model 13 | struct model_s* (*Mod_ForName) (const char* name, int crash_if_missing); 14 | // Retrieve pointer to studio model data block from a model 15 | void* (*Mod_Extradata) (struct model_s* mod); 16 | // Retrieve indexed model from client side model precache list 17 | struct model_s* (*GetModelByIndex) (int index); 18 | // Get entity that is set for rendering 19 | struct cl_entity_s* (*GetCurrentEntity) (void); 20 | // Get referenced player_info_t 21 | struct player_info_s* (*PlayerInfo) (int index); 22 | // Get most recently received player state data from network system 23 | struct entity_state_s* (*GetPlayerState) (int index); 24 | // Get viewentity 25 | struct cl_entity_s* (*GetViewEntity) (void); 26 | // Get current frame count, and last two timestampes on client 27 | void (*GetTimes) (int* framecount, double* current, double* old); 28 | // Get a pointer to a cvar by name 29 | struct cvar_s* (*GetCvar) (const char* name); 30 | // Get current render origin and view vectors ( up, right and vpn ) 31 | void (*GetViewInfo) (float* origin, float* upv, float* rightv, float* vpnv); 32 | // Get sprite model used for applying chrome effect 33 | struct model_s* (*GetChromeSprite) (void); 34 | // Get model counters so we can incement instrumentation 35 | void (*GetModelCounters) (int** s, int** a); 36 | // Get software scaling coefficients 37 | void (*GetAliasScale) (float* x, float* y); 38 | 39 | // Get bone, light, alias, and rotation matrices 40 | float**** (*StudioGetBoneTransform) (void); 41 | float**** (*StudioGetLightTransform)(void); 42 | float*** (*StudioGetAliasTransform) (void); 43 | float*** (*StudioGetRotationMatrix) (void); 44 | 45 | // Set up body part, and get submodel pointers 46 | void (*StudioSetupModel) (int bodypart, void** ppbodypart, void** ppsubmodel); 47 | // Check if entity's bbox is in the view frustum 48 | int (*StudioCheckBBox) (void); 49 | // Apply lighting effects to model 50 | void (*StudioDynamicLight) (struct cl_entity_s* ent, struct alight_s* plight); 51 | void (*StudioEntityLight) (struct alight_s* plight); 52 | void (*StudioSetupLighting) (struct alight_s* plighting); 53 | 54 | // Draw mesh vertices 55 | void (*StudioDrawPoints) (void); 56 | 57 | // Draw hulls around bones 58 | void (*StudioDrawHulls) (void); 59 | // Draw bbox around studio models 60 | void (*StudioDrawAbsBBox) (void); 61 | // Draws bones 62 | void (*StudioDrawBones) (void); 63 | // Loads in appropriate texture for model 64 | void (*StudioSetupSkin) (void* ptexturehdr, int index); 65 | // Sets up for remapped colors 66 | void (*StudioSetRemapColors) (int top, int bottom); 67 | // Set's player model and returns model pointer 68 | struct model_s* (*SetupPlayerModel) (int index); 69 | // Fires any events embedded in animation 70 | void (*StudioClientEvents) (void); 71 | // Retrieve/set forced render effects flags 72 | int (*GetForceFaceFlags) (void); 73 | void (*SetForceFaceFlags) (int flags); 74 | // Tell engine the value of the studio model header 75 | void (*StudioSetHeader) (void* header); 76 | // Tell engine which model_t * is being renderered 77 | void (*SetRenderModel) (struct model_s* model); 78 | 79 | // Final state setup and restore for rendering 80 | void (*SetupRenderer) (int rendermode); 81 | void (*RestoreRenderer) (void); 82 | 83 | // Set render origin for applying chrome effect 84 | void (*SetChromeOrigin) (void); 85 | 86 | // True if using D3D/OpenGL 87 | int (*IsHardware) (void); 88 | 89 | // Only called by hardware interface 90 | void (*GL_StudioDrawShadow) (void); 91 | void (*GL_SetRenderMode) (int mode); 92 | 93 | void (*StudioSetRenderamt) (int iRenderamt); //!!!CZERO added for rendering glass on viewmodels 94 | void (*StudioSetCullState) (int iCull); 95 | void (*StudioRenderShadow) (int iSprite, float* p1, float* p2, float* p3, float* p4); 96 | } engine_studio_api_t; 97 | 98 | typedef struct server_studio_api_s 99 | { 100 | // Allocate number*size bytes and zero it 101 | void* (*Mem_Calloc) (int number, size_t size); 102 | // Check to see if pointer is in the cache 103 | void* (*Cache_Check) (struct cache_user_s* c); 104 | // Load file into cache ( can be swapped out on demand ) 105 | void (*LoadCacheFile) (char* path, struct cache_user_s* cu); 106 | // Retrieve pointer to studio model data block from a model 107 | void* (*Mod_Extradata) (struct model_s* mod); 108 | } server_studio_api_t; 109 | 110 | 111 | // client blending 112 | typedef struct r_studio_interface_s 113 | { 114 | int version; 115 | int (*StudioDrawModel) (int flags); 116 | int (*StudioDrawPlayer) (int flags, struct entity_state_s* pplayer); 117 | } r_studio_interface_t; 118 | 119 | //extern r_studio_interface_t *pStudioAPI; 120 | 121 | // server blending 122 | #define SV_BLENDING_INTERFACE_VERSION 1 123 | 124 | typedef struct sv_blending_interface_s 125 | { 126 | int version; 127 | 128 | void (*SV_StudioSetupBones)(struct model_s* pModel, 129 | float frame, 130 | int sequence, 131 | const s_vec3 angles, 132 | const s_vec3 origin, 133 | const byte* pcontroller, 134 | const byte* pblending, 135 | int iBone, 136 | const edict_t* pEdict); 137 | } sv_blending_interface_t; -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/utilities/pattern/simd_scanner.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "pattern.hpp" 3 | 4 | #define MEM_SIMD_SCANNER_USE_MEMCHR 5 | 6 | namespace mem { 7 | class simd_scanner : public scanner_base { 8 | private: 9 | const pattern* pattern_{ nullptr }; 10 | std::size_t skip_pos_{ SIZE_MAX }; 11 | 12 | public: 13 | simd_scanner() = default; 14 | 15 | simd_scanner(const pattern& pattern); 16 | simd_scanner(const pattern& pattern, const byte* frequencies); 17 | 18 | pointer scan(region range) const; 19 | 20 | static const byte* default_frequencies() noexcept; 21 | }; 22 | 23 | const byte* find_byte(const byte* ptr, byte value, std::size_t num); 24 | 25 | inline simd_scanner::simd_scanner(const pattern& _pattern) 26 | : simd_scanner(_pattern, default_frequencies()) 27 | {} 28 | 29 | inline simd_scanner::simd_scanner(const pattern& _pattern, const byte* frequencies) 30 | : pattern_(&_pattern) 31 | , skip_pos_(_pattern.get_skip_pos(frequencies)) 32 | {} 33 | 34 | strong_inline const byte* simd_scanner::default_frequencies() noexcept { 35 | static constexpr const byte frequencies[256] { 36 | 0xFF,0xFB,0xF2,0xEE,0xEC,0xE7,0xDC,0xC8,0xED,0xB7,0xCC,0xC0,0xD3,0xCD,0x89,0xFA, 37 | 0xF3,0xD6,0x8D,0x83,0xC1,0xAA,0x7A,0x72,0xC6,0x60,0x3E,0x2E,0x98,0x69,0x39,0x7C, 38 | 0xEB,0x76,0x24,0x34,0xF9,0x50,0x04,0x07,0xE5,0xAC,0x53,0x65,0x9B,0x4D,0x6D,0x5C, 39 | 0xDA,0x93,0x7F,0xCB,0x92,0x49,0x43,0x09,0xBA,0x8E,0x1E,0x91,0x8A,0x5B,0x11,0xA1, 40 | 0xE8,0xF5,0x9E,0xAD,0xEF,0xE6,0x79,0x7B,0xFE,0xE0,0x1F,0x54,0xE4,0xBD,0x7D,0x6A, 41 | 0xDF,0x67,0x7E,0xA4,0xB6,0xAF,0x88,0xA0,0xC3,0xA9,0x26,0x77,0xD1,0x71,0x61,0xC2, 42 | 0x9A,0xCA,0x29,0x9F,0xD8,0xE2,0xD0,0x6E,0xB4,0xB8,0x25,0x3C,0xBF,0x73,0xB5,0xCF, 43 | 0xD4,0x01,0xCE,0xBE,0xF1,0xDB,0x52,0x37,0x9D,0x63,0x02,0x6B,0x80,0x45,0x2B,0x95, 44 | 0xE1,0xC4,0x36,0xF0,0xD5,0xE3,0x57,0x9C,0xB1,0xF7,0x82,0xFC,0x42,0xF6,0x18,0x33, 45 | 0xD2,0x48,0x05,0x0F,0x41,0x1D,0x03,0x27,0x70,0x10,0x00,0x08,0x55,0x16,0x2F,0x0E, 46 | 0x94,0x35,0x2C,0x40,0x6F,0x3B,0x1C,0x28,0x90,0x68,0x81,0x4B,0x56,0x30,0x2A,0x3D, 47 | 0x97,0x17,0x06,0x13,0x32,0x0B,0x5A,0x75,0xA5,0x86,0x78,0x4F,0x2D,0x51,0x46,0x5F, 48 | 0xE9,0xDE,0xA2,0xDD,0xC9,0x4C,0xAB,0xBB,0xC7,0xB9,0x74,0x8F,0xF8,0x6C,0x85,0x8B, 49 | 0xC5,0x84,0x8C,0x66,0x21,0x23,0x64,0x59,0xA3,0x87,0x44,0x58,0x3A,0x0D,0x12,0x19, 50 | 0xAE,0x5E,0x3F,0x38,0x31,0x22,0x0A,0x14,0xF4,0xD9,0x20,0xB0,0xB2,0x1A,0x0C,0x15, 51 | 0xB3,0x47,0x5D,0xEA,0x4A,0x1B,0x99,0xBC,0xD7,0xA6,0x62,0x4E,0xA8,0x96,0xA7,0xFD, 52 | }; 53 | 54 | return frequencies; 55 | } 56 | 57 | inline pointer simd_scanner::scan(region range) const { 58 | const std::size_t trimmed_size = pattern_->trimmed_size(); 59 | 60 | if (!trimmed_size) 61 | return nullptr; 62 | 63 | const std::size_t original_size = pattern_->size(); 64 | const std::size_t region_size = range.size; 65 | 66 | if (original_size > region_size) 67 | return nullptr; 68 | 69 | const byte* const region_base = range.start.as(); 70 | const byte* const region_end = region_base + region_size; 71 | 72 | const byte* current = region_base; 73 | const byte* const end = region_end - original_size + 1; 74 | 75 | const std::size_t last = trimmed_size - 1; 76 | 77 | const byte* const pat_bytes = pattern_->bytes(); 78 | 79 | const std::size_t skip_pos = skip_pos_; 80 | 81 | if (skip_pos != SIZE_MAX) { 82 | if (pattern_->needs_masks()) { 83 | const byte* const pat_masks = pattern_->masks(); 84 | 85 | while (mem_likely(current < end)) { 86 | [[likely]]; 87 | 88 | for (std::size_t i = last; mem_likely((current[i] & pat_masks[i]) == pat_bytes[i]); --i) { 89 | [[likely]]; 90 | 91 | if (mem_unlikely(i == 0)) [[unlikely]] 92 | return current; 93 | } 94 | 95 | ++current; 96 | current = 97 | find_byte(current + skip_pos, pat_bytes[skip_pos], static_cast(end - current)) - 98 | skip_pos; 99 | } 100 | 101 | return nullptr; 102 | } 103 | else { 104 | while (mem_likely(current < end)) { 105 | [[likely]]; 106 | 107 | for (std::size_t i = last; mem_likely(current[i] == pat_bytes[i]); --i) { 108 | [[likely]]; 109 | 110 | if (mem_unlikely(i == 0)) [[unlikely]] 111 | return current; 112 | } 113 | 114 | ++current; 115 | current = 116 | find_byte(current + skip_pos, pat_bytes[skip_pos], static_cast(end - current)) - 117 | skip_pos; 118 | } 119 | 120 | return nullptr; 121 | } 122 | } 123 | else { 124 | const byte* const pat_masks = pattern_->masks(); 125 | 126 | while (mem_likely(current < end)) { 127 | [[likely]]; 128 | 129 | for (std::size_t i = last; mem_likely((current[i] & pat_masks[i]) == pat_bytes[i]); --i) { 130 | [[likely]]; 131 | 132 | if (mem_unlikely(i == 0)) [[unlikely]] 133 | return current; 134 | } 135 | 136 | ++current; 137 | } 138 | 139 | return nullptr; 140 | } 141 | } 142 | 143 | strong_inline const byte* find_byte(const byte* ptr, byte value, std::size_t num) { 144 | const byte* result = static_cast(std::memchr(ptr, value, num)); 145 | 146 | if (mem_unlikely(result == nullptr)) [[unlikely]] 147 | result = ptr + num; 148 | 149 | return result; 150 | } 151 | } -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/game/sdk/classes/model.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "const.hpp" 3 | #include "bspfile.hpp" 4 | 5 | #define TEX_SPECIAL 1 // sky or slime, no lightmap or 256 subdivision 6 | 7 | #define SURF_PLANEBACK 2 8 | #define SURF_DRAWSKY 4 9 | #define SURF_DRAWSPRITE 8 10 | #define SURF_DRAWTURB 0x10 11 | #define SURF_DRAWTILED 0x20 12 | #define SURF_DRAWBACKGROUND 0x40 13 | 14 | #define MAX_MODEL_NAME 64 15 | #define MIPLEVELS 4 16 | #define NUM_AMBIENTS 4 17 | #define MAXLIGHTMAPS 4 18 | #define MAX_KNOWN_MODELS 1024 19 | 20 | typedef enum 21 | { 22 | ST_SYNC = 0, 23 | ST_RAND 24 | } synctype_t; 25 | 26 | typedef struct cache_user_s 27 | { 28 | void* data; 29 | } cache_user_t; 30 | 31 | /* <6816> ../engine/model.h:27 */ 32 | typedef struct mvertex_s 33 | { 34 | s_vec3 position; 35 | } mvertex_t; 36 | 37 | /* <6838> ../engine/model.h:39 */ 38 | typedef struct mplane_s 39 | { 40 | s_vec3 normal; // surface normal 41 | float dist; // closest appoach to origin 42 | byte type; // for texture axis selection and fast side tests 43 | byte signbits; // signx + signy<<1 + signz<<1 44 | byte pad[2]; 45 | } mplane_t; 46 | 47 | /* <68a6> ../engine/model.h:48 */ 48 | typedef struct texture_s 49 | { 50 | char name[16]; 51 | unsigned width, height; 52 | int anim_total; // total tenths in sequence ( 0 = no) 53 | int anim_min, anim_max; // time for this frame min <=time< max 54 | struct texture_s* anim_next; // in the animation sequence 55 | struct texture_s* alternate_anims; // bmodels in frame 1 use these 56 | unsigned offsets[MIPLEVELS]; // four mip maps stored 57 | unsigned paloffset; 58 | } texture_t; 59 | 60 | /* <6950> ../engine/model.h:71 */ 61 | typedef struct medge_s 62 | { 63 | unsigned short v[2]; 64 | unsigned int cachededgeoffset; 65 | } medge_t; 66 | 67 | /* <697e> ../engine/model.h:78 */ 68 | typedef struct mtexinfo_s 69 | { 70 | float vecs[2][4]; // [s/t] unit vectors in world space. 71 | float mipadjust; // ?? mipmap limits for very small surfaces 72 | texture_t* texture; 73 | int flags; // sky or slime, no lightmap or 256 subdivision 74 | } mtexinfo_t; 75 | 76 | /* <69d0> ../engine/model.h:91 */ 77 | typedef struct msurface_s msurface_t; 78 | 79 | /* <1db66> ../engine/model.h:92 */ 80 | typedef struct decal_s decal_t; 81 | 82 | // JAY: Compress this as much as possible 83 | /* <1db71> ../engine/model.h:96 */ 84 | struct decal_s 85 | { 86 | decal_t* pnext; // linked list for each surface 87 | msurface_t* psurface; // Surface id for persistence / unlinking 88 | short dx; // Offsets into surface texture (in texture coordinates, so we don't need floats) 89 | short dy; 90 | short texture; // Decal texture 91 | byte scale; // Pixel scale 92 | byte flags; // Decal flags 93 | short entityIndex; // Entity this is attached to 94 | }; 95 | 96 | /* <69db> ../engine/model.h:118 */ 97 | struct msurface_s 98 | { 99 | int visframe; // should be drawn when node is crossed 100 | int dlightframe; // last frame the surface was checked by an animated light 101 | int dlightbits; // dynamically generated. Indicates if the surface illumination 102 | // is modified by an animated light. 103 | mplane_t* plane; // pointer to shared plane 104 | int flags; // see SURF_ #defines 105 | 106 | int firstedge; // look up in model->surfedges[], negative numbers 107 | int numedges; // are backwards edges 108 | 109 | // surface generation data 110 | struct surfcache_s* cachespots[MIPLEVELS]; 111 | short texturemins[2]; // smallest s/t position on the surface. 112 | short extents[2]; // ?? s/t texture size, 1..256 for all non-sky surfaces 113 | mtexinfo_t* texinfo; 114 | byte styles[MAXLIGHTMAPS]; // index into d_lightstylevalue[] for animated lights 115 | // no one surface can be effected by more than 4 116 | // animated lights. 117 | color24* samples; 118 | decal_t* pdecals; 119 | }; 120 | 121 | /* <6b6c> ../engine/model.h:149 */ 122 | typedef struct mnode_s 123 | { 124 | // common with leaf 125 | int contents; // 0, to differentiate from leafs 126 | int visframe; // node needs to be traversed if current 127 | short minmaxs[6]; // for bounding box culling 128 | struct mnode_s* parent; 129 | 130 | // node specific 131 | mplane_t* plane; 132 | struct mnode_s* children[2]; 133 | unsigned short firstsurface; 134 | unsigned short numsurfaces; 135 | } mnode_t; 136 | 137 | /* <1dcd4> ../engine/model.h:169 */ 138 | typedef struct mleaf_s 139 | { 140 | // common with node 141 | int contents; // wil be a negative contents number 142 | int visframe; // node needs to be traversed if current 143 | short minmaxs[6]; // for bounding box culling 144 | struct mnode_s* parent; 145 | byte* compressed_vis; 146 | struct efrag_s* efrags; 147 | msurface_t** firstmarksurface; 148 | int nummarksurfaces; 149 | int key; // BSP sequence number for leaf's contents 150 | byte ambient_sound_level[NUM_AMBIENTS]; 151 | } mleaf_t; 152 | 153 | /* <1ddbe> ../engine/model.h:190 */ 154 | typedef struct hull_s 155 | { 156 | dclipnode_t* clipnodes; 157 | mplane_t* planes; 158 | int firstclipnode; 159 | int lastclipnode; 160 | s_vec3 clip_mins, clip_maxs; 161 | } hull_t; 162 | 163 | /* <1de30> ../engine/model.h:315 */ 164 | typedef enum modtype_e 165 | { 166 | mod_brush, 167 | mod_sprite, 168 | mod_alias, 169 | mod_studio, 170 | } modtype_t; 171 | 172 | /* <1de5e> ../engine/model.h:331 */ 173 | typedef struct model_s 174 | { 175 | char name[MAX_MODEL_NAME]; 176 | int needload; 177 | modtype_t type; 178 | int numframes; 179 | synctype_t synctype; 180 | int flags; 181 | s_vec3 mins, maxs; 182 | float radius; 183 | int firstmodelsurface; 184 | int nummodelsurfaces; 185 | int numsubmodels; 186 | dmodel_t* submodels; 187 | int numplanes; 188 | mplane_t* planes; 189 | int numleafs; 190 | struct mleaf_s* leafs; 191 | int numvertexes; 192 | mvertex_t* vertexes; 193 | int numedges; 194 | medge_t* edges; 195 | int numnodes; 196 | mnode_t* nodes; 197 | int numtexinfo; 198 | mtexinfo_t* texinfo; 199 | int numsurfaces; 200 | msurface_t* surfaces; 201 | int numsurfedges; 202 | int* surfedges; 203 | int numclipnodes; 204 | dclipnode_t* clipnodes; 205 | int nummarksurfaces; 206 | msurface_t** marksurfaces; 207 | hull_t hulls[MAX_MAP_HULLS]; 208 | int numtextures; 209 | texture_t** textures; 210 | byte* visdata; 211 | color24* lightdata; 212 | char* entities; 213 | cache_user_t cache; 214 | } model_t; 215 | 216 | typedef struct mod_known_info_s 217 | { 218 | int shouldCRC; 219 | int firstCRCDone; 220 | unsigned int initialCRC; 221 | } mod_known_info_t; -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/game/sdk/classes/entity.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "const.hpp" 3 | #include "playermove.hpp" 4 | #include "model.hpp" 5 | 6 | #define HISTORY_MAX 64 // Must be power of 2 7 | #define HISTORY_MASK ( HISTORY_MAX - 1 ) 8 | 9 | #define ENTITY_NORMAL (1<<0) 10 | #define ENTITY_BEAM (1<<1) 11 | 12 | #define REGULAR_HULL 0 13 | #define DUCKED_HULL 1 14 | #define POINT_HULL 2 15 | 16 | enum { 17 | HITBOX_STOMACH, 18 | HITBOX_LEFT_FOOT, 19 | HITBOX_LEFT_CALF, 20 | HITBOX_LEFT_THIGH, 21 | HITBOX_RIGHT_FOOT, 22 | HITBOX_RIGHT_CALF, 23 | HITBOX_RIGHT_THIGH, 24 | HITBOX_LOWER_CHEST, 25 | HITBOX_CHEST, 26 | HITBOX_UPPER_CHEST, 27 | HITBOX_NECK, 28 | HITBOX_HEAD, 29 | HITBOX_LEFT_UPPER_ARM, 30 | HITBOX_LEFT_HAND, 31 | HITBOX_LEFT_FOREARM, 32 | HITBOX_LEFT_WRIST, 33 | HITBOX_RIGHT_UPPER_ARM, 34 | HITBOX_RIGHT_HAND, 35 | HITBOX_RIGHT_FOREARM, 36 | HITBOX_RIGHT_WRIST, 37 | HITBOX_SHIELD, 38 | HITBOX_MAX 39 | }; 40 | 41 | typedef struct entity_state_s 42 | { 43 | int entityType; 44 | int number; // Index into cl_entities array for this entity. 45 | float msg_time; 46 | int messagenum; // Message number last time the player/entity state was updated. 47 | s_vec3 origin; // Fields which can be transitted and reconstructed over the network stream 48 | s_angle angles; 49 | int modelindex; 50 | int sequence; 51 | float frame; 52 | int colormap; 53 | short skin; 54 | short solid; 55 | int effects; 56 | float scale; 57 | byte eflags; 58 | int rendermode; // Render information 59 | int renderamt; 60 | color24 rendercolor; 61 | int renderfx; 62 | int movetype; 63 | float animtime; 64 | float framerate; 65 | int body; 66 | byte controller[4]; 67 | byte blending[4]; 68 | s_vec3 velocity; 69 | s_vec3 mins; // Send bbox down to client for use during prediction. 70 | s_vec3 maxs; 71 | int aiment; 72 | int owner; // If owned by a player, the index of that player ( for projectiles ). 73 | float friction; // Friction, for prediction. 74 | float gravity; // Gravity multiplier 75 | int team; 76 | int playerclass; 77 | int health; 78 | int spectator; 79 | int weaponmodel; 80 | int gaitsequence; 81 | s_vec3 basevelocity; // If standing on conveyor, e.g. 82 | int usehull; // Use the crouched hull, or the regular player hull. 83 | int oldbuttons; // Latched buttons last time state updated. 84 | int onground; // -1 = in air, else pmove entity number 85 | int iStepLeft; 86 | float flFallVelocity; // How fast we are falling 87 | float fov; 88 | int weaponanim; 89 | s_vec3 startpos; // Parametric movement overrides 90 | s_vec3 endpos; 91 | float impacttime; 92 | float starttime; 93 | int iuser1; 94 | int iuser2; 95 | int iuser3; 96 | int iuser4; 97 | float fuser1; 98 | float fuser2; 99 | float fuser3; 100 | float fuser4; 101 | s_vec3 vuser1; 102 | s_vec3 vuser2; 103 | s_vec3 vuser3; 104 | s_vec3 vuser4; 105 | } entity_state_t; 106 | 107 | typedef struct clientdata_s 108 | { 109 | s_vec3 origin; 110 | s_vec3 velocity; 111 | int viewmodel; 112 | s_angle punchangle; 113 | int flags; 114 | int waterlevel; 115 | int watertype; 116 | s_vec3 view_ofs; 117 | float health; 118 | int bInDuck; 119 | int weapons; 120 | int flTimeStepSound; 121 | int flDuckTime; 122 | int flSwimTime; 123 | int waterjumptime; 124 | float maxspeed; 125 | float fov; 126 | int weaponanim; 127 | int m_iId; 128 | int ammo_shells; 129 | int ammo_nails; 130 | int ammo_cells; 131 | int ammo_rockets; 132 | float m_flNextAttack; 133 | int tfstate; 134 | int pushmsec; 135 | int deadflag; 136 | char physinfo[MAX_PHYSINFO_STRING]; 137 | int iuser1; 138 | int iuser2; 139 | int iuser3; 140 | int iuser4; 141 | float fuser1; 142 | float fuser2; 143 | float fuser3; 144 | float fuser4; 145 | s_vec3 vuser1; 146 | s_vec3 vuser2; 147 | s_vec3 vuser3; 148 | s_vec3 vuser4; 149 | 150 | } clientdata_t; 151 | 152 | typedef struct efrag_s 153 | { 154 | struct mleaf_s* leaf; 155 | struct efrag_s* leafnext; 156 | struct cl_entity_s* entity; 157 | struct efrag_s* entnext; 158 | } efrag_t; 159 | 160 | typedef struct 161 | { 162 | byte mouthopen; // 0 = mouth closed, 255 = mouth agape 163 | byte sndcount; // counter for running average 164 | int sndavg; // running average 165 | } mouth_t; 166 | 167 | typedef struct 168 | { 169 | float prevanimtime; 170 | float sequencetime; 171 | byte prevseqblending[2]; 172 | s_vec3 prevorigin; 173 | s_angle prevangles; 174 | 175 | int prevsequence; 176 | float prevframe; 177 | 178 | byte prevcontroller[4]; 179 | byte prevblending[2]; 180 | } latchedvars_t; 181 | 182 | typedef struct 183 | { 184 | // Time stamp for this movement 185 | float animtime; 186 | 187 | s_vec3 origin; 188 | s_angle angles; 189 | } position_history_t; 190 | 191 | typedef struct cl_entity_s 192 | { 193 | int index; // Index into cl_entities ( should match actual slot, but not necessarily ) 194 | 195 | int player; // True if this entity is a "player" 196 | 197 | entity_state_t baseline; // The original state from which to delta during an uncompressed message 198 | entity_state_t prevstate; // The state information from the penultimate message received from the server 199 | entity_state_t curstate; // The state information from the last message received from server 200 | 201 | int current_position; // Last received history update index 202 | position_history_t ph[HISTORY_MAX]; // History of position and angle updates for this player 203 | 204 | mouth_t mouth; // For synchronizing mouth movements. 205 | 206 | latchedvars_t latched; // Variables used by studio model rendering routines 207 | 208 | // Information based on interplocation, extrapolation, prediction, or just copied from last msg received. 209 | // 210 | float lastmove; 211 | 212 | // Actual render position and angles 213 | s_vec3 origin; 214 | s_angle angles; 215 | 216 | // Attachment points 217 | s_vec3 attachment[4]; 218 | 219 | // Other entity local information 220 | int trivial_accept; 221 | 222 | struct model_s* model; // cl.model_precache[ curstate.modelindes ]; all visible entities have a model 223 | struct efrag_s* efrag; // linked list of efrags 224 | struct mnode_s* topnode; // for bmodels, first world node that splits bmodel, or NULL if not split 225 | 226 | float syncbase; // for client-side animations -- used by obsolete alias animation system, remove? 227 | int visframe; // last frame this entity was found in an active leaf 228 | colorVec cvFloorColor; 229 | } cl_entity_t; -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/minhook/minhook.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #pragma once 30 | 31 | #if !(defined _M_IX86) && !(defined _M_X64) && !(defined __i386__) && !(defined __x86_64__) 32 | #error MinHook supports only x86 and x64 systems. 33 | #endif 34 | 35 | #include 36 | 37 | // MinHook Error Codes. 38 | typedef enum MH_STATUS 39 | { 40 | // Unknown error. Should not be returned. 41 | MH_UNKNOWN = -1, 42 | 43 | // Successful. 44 | MH_OK = 0, 45 | 46 | // MinHook is already initialized. 47 | MH_ERROR_ALREADY_INITIALIZED, 48 | 49 | // MinHook is not initialized yet, or already uninitialized. 50 | MH_ERROR_NOT_INITIALIZED, 51 | 52 | // The hook for the specified target function is already created. 53 | MH_ERROR_ALREADY_CREATED, 54 | 55 | // The hook for the specified target function is not created yet. 56 | MH_ERROR_NOT_CREATED, 57 | 58 | // The hook for the specified target function is already enabled. 59 | MH_ERROR_ENABLED, 60 | 61 | // The hook for the specified target function is not enabled yet, or already 62 | // disabled. 63 | MH_ERROR_DISABLED, 64 | 65 | // The specified pointer is invalid. It points the address of non-allocated 66 | // and/or non-executable region. 67 | MH_ERROR_NOT_EXECUTABLE, 68 | 69 | // The specified target function cannot be hooked. 70 | MH_ERROR_UNSUPPORTED_FUNCTION, 71 | 72 | // Failed to allocate memory. 73 | MH_ERROR_MEMORY_ALLOC, 74 | 75 | // Failed to change the memory protection. 76 | MH_ERROR_MEMORY_PROTECT, 77 | 78 | // The specified module is not loaded. 79 | MH_ERROR_MODULE_NOT_FOUND, 80 | 81 | // The specified function is not found. 82 | MH_ERROR_FUNCTION_NOT_FOUND 83 | } 84 | MH_STATUS; 85 | 86 | // Can be passed as a parameter to MH_EnableHook, MH_DisableHook, 87 | // MH_QueueEnableHook or MH_QueueDisableHook. 88 | #define MH_ALL_HOOKS NULL 89 | 90 | #ifdef __cplusplus 91 | extern "C" { 92 | #endif 93 | 94 | // Initialize the MinHook library. You must call this function EXACTLY ONCE 95 | // at the beginning of your program. 96 | MH_STATUS WINAPI MH_Initialize(VOID); 97 | 98 | // Uninitialize the MinHook library. You must call this function EXACTLY 99 | // ONCE at the end of your program. 100 | MH_STATUS WINAPI MH_Uninitialize(VOID); 101 | 102 | // Creates a Hook for the specified target function, in disabled state. 103 | // Parameters: 104 | // pTarget [in] A pointer to the target function, which will be 105 | // overridden by the detour function. 106 | // pDetour [in] A pointer to the detour function, which will override 107 | // the target function. 108 | // ppOriginal [out] A pointer to the trampoline function, which will be 109 | // used to call the original target function. 110 | // This parameter can be NULL. 111 | MH_STATUS WINAPI MH_CreateHook(LPVOID pTarget, LPVOID pDetour, LPVOID* ppOriginal); 112 | 113 | // Creates a Hook for the specified API function, in disabled state. 114 | // Parameters: 115 | // pszModule [in] A pointer to the loaded module name which contains the 116 | // target function. 117 | // pszTarget [in] A pointer to the target function name, which will be 118 | // overridden by the detour function. 119 | // pDetour [in] A pointer to the detour function, which will override 120 | // the target function. 121 | // ppOriginal [out] A pointer to the trampoline function, which will be 122 | // used to call the original target function. 123 | // This parameter can be NULL. 124 | MH_STATUS WINAPI MH_CreateHookApi( 125 | LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID* ppOriginal); 126 | 127 | // Creates a Hook for the specified API function, in disabled state. 128 | // Parameters: 129 | // pszModule [in] A pointer to the loaded module name which contains the 130 | // target function. 131 | // pszTarget [in] A pointer to the target function name, which will be 132 | // overridden by the detour function. 133 | // pDetour [in] A pointer to the detour function, which will override 134 | // the target function. 135 | // ppOriginal [out] A pointer to the trampoline function, which will be 136 | // used to call the original target function. 137 | // This parameter can be NULL. 138 | // ppTarget [out] A pointer to the target function, which will be used 139 | // with other functions. 140 | // This parameter can be NULL. 141 | MH_STATUS WINAPI MH_CreateHookApiEx( 142 | LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID* ppOriginal, LPVOID* ppTarget); 143 | 144 | // Removes an already created hook. 145 | // Parameters: 146 | // pTarget [in] A pointer to the target function. 147 | MH_STATUS WINAPI MH_RemoveHook(LPVOID pTarget); 148 | 149 | // Enables an already created hook. 150 | // Parameters: 151 | // pTarget [in] A pointer to the target function. 152 | // If this parameter is MH_ALL_HOOKS, all created hooks are 153 | // enabled in one go. 154 | MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget); 155 | 156 | // Disables an already created hook. 157 | // Parameters: 158 | // pTarget [in] A pointer to the target function. 159 | // If this parameter is MH_ALL_HOOKS, all created hooks are 160 | // disabled in one go. 161 | MH_STATUS WINAPI MH_DisableHook(LPVOID pTarget); 162 | 163 | // Queues to enable an already created hook. 164 | // Parameters: 165 | // pTarget [in] A pointer to the target function. 166 | // If this parameter is MH_ALL_HOOKS, all created hooks are 167 | // queued to be enabled. 168 | MH_STATUS WINAPI MH_QueueEnableHook(LPVOID pTarget); 169 | 170 | // Queues to disable an already created hook. 171 | // Parameters: 172 | // pTarget [in] A pointer to the target function. 173 | // If this parameter is MH_ALL_HOOKS, all created hooks are 174 | // queued to be disabled. 175 | MH_STATUS WINAPI MH_QueueDisableHook(LPVOID pTarget); 176 | 177 | // Applies all queued changes in one go. 178 | MH_STATUS WINAPI MH_ApplyQueued(VOID); 179 | 180 | // Translates the MH_STATUS to its name as a string. 181 | const char* WINAPI MH_StatusToString(MH_STATUS status); 182 | 183 | #ifdef __cplusplus 184 | } 185 | #endif 186 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/minhook/hde/hde32.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #if defined(_M_IX86) || defined(__i386__) 9 | 10 | #include "hde32.h" 11 | #include "table32.h" 12 | 13 | unsigned int hde32_disasm(const void* code, hde32s* hs) 14 | { 15 | uint8_t x, c, * p = (uint8_t*)code, cflags, opcode, pref = 0; 16 | uint8_t* ht = hde32_table, m_mod, m_reg, m_rm, disp_size = 0; 17 | 18 | // Avoid using memset to reduce the footprint. 19 | #ifndef _MSC_VER 20 | memset((LPBYTE)hs, 0, sizeof(hde32s)); 21 | #else 22 | __stosb((LPBYTE)hs, 0, sizeof(hde32s)); 23 | #endif 24 | 25 | for (x = 16; x; x--) 26 | switch (c = *p++) { 27 | case 0xf3: 28 | hs->p_rep = c; 29 | pref |= PRE_F3; 30 | break; 31 | case 0xf2: 32 | hs->p_rep = c; 33 | pref |= PRE_F2; 34 | break; 35 | case 0xf0: 36 | hs->p_lock = c; 37 | pref |= PRE_LOCK; 38 | break; 39 | case 0x26: case 0x2e: case 0x36: 40 | case 0x3e: case 0x64: case 0x65: 41 | hs->p_seg = c; 42 | pref |= PRE_SEG; 43 | break; 44 | case 0x66: 45 | hs->p_66 = c; 46 | pref |= PRE_66; 47 | break; 48 | case 0x67: 49 | hs->p_67 = c; 50 | pref |= PRE_67; 51 | break; 52 | default: 53 | goto pref_done; 54 | } 55 | pref_done: 56 | 57 | hs->flags = (uint32_t)pref << 23; 58 | 59 | if (!pref) 60 | pref |= PRE_NONE; 61 | 62 | if ((hs->opcode = c) == 0x0f) { 63 | hs->opcode2 = c = *p++; 64 | ht += DELTA_OPCODES; 65 | } 66 | else if (c >= 0xa0 && c <= 0xa3) { 67 | if (pref & PRE_67) 68 | pref |= PRE_66; 69 | else 70 | pref &= ~PRE_66; 71 | } 72 | 73 | opcode = c; 74 | cflags = ht[ht[opcode / 4] + (opcode % 4)]; 75 | 76 | if (cflags == C_ERROR) { 77 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 78 | cflags = 0; 79 | if ((opcode & -3) == 0x24) 80 | cflags++; 81 | } 82 | 83 | x = 0; 84 | if (cflags & C_GROUP) { 85 | uint16_t t; 86 | t = *(uint16_t*)(ht + (cflags & 0x7f)); 87 | cflags = (uint8_t)t; 88 | x = (uint8_t)(t >> 8); 89 | } 90 | 91 | if (hs->opcode2) { 92 | ht = hde32_table + DELTA_PREFIXES; 93 | if (ht[ht[opcode / 4] + (opcode % 4)] & pref) 94 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 95 | } 96 | 97 | if (cflags & C_MODRM) { 98 | hs->flags |= F_MODRM; 99 | hs->modrm = c = *p++; 100 | hs->modrm_mod = m_mod = c >> 6; 101 | hs->modrm_rm = m_rm = c & 7; 102 | hs->modrm_reg = m_reg = (c & 0x3f) >> 3; 103 | 104 | if (x && ((x << m_reg) & 0x80)) 105 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 106 | 107 | if (!hs->opcode2 && opcode >= 0xd9 && opcode <= 0xdf) { 108 | uint8_t t = opcode - 0xd9; 109 | if (m_mod == 3) { 110 | ht = hde32_table + DELTA_FPU_MODRM + t * 8; 111 | t = ht[m_reg] << m_rm; 112 | } 113 | else { 114 | ht = hde32_table + DELTA_FPU_REG; 115 | t = ht[t] << m_reg; 116 | } 117 | if (t & 0x80) 118 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 119 | } 120 | 121 | if (pref & PRE_LOCK) { 122 | if (m_mod == 3) { 123 | hs->flags |= F_ERROR | F_ERROR_LOCK; 124 | } 125 | else { 126 | uint8_t* table_end, op = opcode; 127 | if (hs->opcode2) { 128 | ht = hde32_table + DELTA_OP2_LOCK_OK; 129 | table_end = ht + DELTA_OP_ONLY_MEM - DELTA_OP2_LOCK_OK; 130 | } 131 | else { 132 | ht = hde32_table + DELTA_OP_LOCK_OK; 133 | table_end = ht + DELTA_OP2_LOCK_OK - DELTA_OP_LOCK_OK; 134 | op &= -2; 135 | } 136 | for (; ht != table_end; ht++) 137 | if (*ht++ == op) { 138 | if (!((*ht << m_reg) & 0x80)) 139 | goto no_lock_error; 140 | else 141 | break; 142 | } 143 | hs->flags |= F_ERROR | F_ERROR_LOCK; 144 | no_lock_error: 145 | ; 146 | } 147 | } 148 | 149 | if (hs->opcode2) { 150 | switch (opcode) { 151 | case 0x20: case 0x22: 152 | m_mod = 3; 153 | if (m_reg > 4 || m_reg == 1) 154 | goto error_operand; 155 | else 156 | goto no_error_operand; 157 | case 0x21: case 0x23: 158 | m_mod = 3; 159 | if (m_reg == 4 || m_reg == 5) 160 | goto error_operand; 161 | else 162 | goto no_error_operand; 163 | } 164 | } 165 | else { 166 | switch (opcode) { 167 | case 0x8c: 168 | if (m_reg > 5) 169 | goto error_operand; 170 | else 171 | goto no_error_operand; 172 | case 0x8e: 173 | if (m_reg == 1 || m_reg > 5) 174 | goto error_operand; 175 | else 176 | goto no_error_operand; 177 | } 178 | } 179 | 180 | if (m_mod == 3) { 181 | uint8_t* table_end; 182 | if (hs->opcode2) { 183 | ht = hde32_table + DELTA_OP2_ONLY_MEM; 184 | table_end = ht + sizeof(hde32_table) - DELTA_OP2_ONLY_MEM; 185 | } 186 | else { 187 | ht = hde32_table + DELTA_OP_ONLY_MEM; 188 | table_end = ht + DELTA_OP2_ONLY_MEM - DELTA_OP_ONLY_MEM; 189 | } 190 | for (; ht != table_end; ht += 2) 191 | if (*ht++ == opcode) { 192 | if (*ht++ & pref && !((*ht << m_reg) & 0x80)) 193 | goto error_operand; 194 | else 195 | break; 196 | } 197 | goto no_error_operand; 198 | } 199 | else if (hs->opcode2) { 200 | switch (opcode) { 201 | case 0x50: case 0xd7: case 0xf7: 202 | if (pref & (PRE_NONE | PRE_66)) 203 | goto error_operand; 204 | break; 205 | case 0xd6: 206 | if (pref & (PRE_F2 | PRE_F3)) 207 | goto error_operand; 208 | break; 209 | case 0xc5: 210 | goto error_operand; 211 | } 212 | goto no_error_operand; 213 | } 214 | else 215 | goto no_error_operand; 216 | 217 | error_operand: 218 | hs->flags |= F_ERROR | F_ERROR_OPERAND; 219 | no_error_operand: 220 | 221 | c = *p++; 222 | if (m_reg <= 1) { 223 | if (opcode == 0xf6) 224 | cflags |= C_IMM8; 225 | else if (opcode == 0xf7) 226 | cflags |= C_IMM_P66; 227 | } 228 | 229 | switch (m_mod) { 230 | case 0: 231 | if (pref & PRE_67) { 232 | if (m_rm == 6) 233 | disp_size = 2; 234 | } 235 | else 236 | if (m_rm == 5) 237 | disp_size = 4; 238 | break; 239 | case 1: 240 | disp_size = 1; 241 | break; 242 | case 2: 243 | disp_size = 2; 244 | if (!(pref & PRE_67)) 245 | disp_size <<= 1; 246 | } 247 | 248 | if (m_mod != 3 && m_rm == 4 && !(pref & PRE_67)) { 249 | hs->flags |= F_SIB; 250 | p++; 251 | hs->sib = c; 252 | hs->sib_scale = c >> 6; 253 | hs->sib_index = (c & 0x3f) >> 3; 254 | if ((hs->sib_base = c & 7) == 5 && !(m_mod & 1)) 255 | disp_size = 4; 256 | } 257 | 258 | p--; 259 | switch (disp_size) { 260 | case 1: 261 | hs->flags |= F_DISP8; 262 | hs->disp.disp8 = *p; 263 | break; 264 | case 2: 265 | hs->flags |= F_DISP16; 266 | hs->disp.disp16 = *(uint16_t*)p; 267 | break; 268 | case 4: 269 | hs->flags |= F_DISP32; 270 | hs->disp.disp32 = *(uint32_t*)p; 271 | } 272 | p += disp_size; 273 | } 274 | else if (pref & PRE_LOCK) 275 | hs->flags |= F_ERROR | F_ERROR_LOCK; 276 | 277 | if (cflags & C_IMM_P66) { 278 | if (cflags & C_REL32) { 279 | if (pref & PRE_66) { 280 | hs->flags |= F_IMM16 | F_RELATIVE; 281 | hs->imm.imm16 = *(uint16_t*)p; 282 | p += 2; 283 | goto disasm_done; 284 | } 285 | goto rel32_ok; 286 | } 287 | if (pref & PRE_66) { 288 | hs->flags |= F_IMM16; 289 | hs->imm.imm16 = *(uint16_t*)p; 290 | p += 2; 291 | } 292 | else { 293 | hs->flags |= F_IMM32; 294 | hs->imm.imm32 = *(uint32_t*)p; 295 | p += 4; 296 | } 297 | } 298 | 299 | if (cflags & C_IMM16) { 300 | if (hs->flags & F_IMM32) { 301 | hs->flags |= F_IMM16; 302 | hs->disp.disp16 = *(uint16_t*)p; 303 | } 304 | else if (hs->flags & F_IMM16) { 305 | hs->flags |= F_2IMM16; 306 | hs->disp.disp16 = *(uint16_t*)p; 307 | } 308 | else { 309 | hs->flags |= F_IMM16; 310 | hs->imm.imm16 = *(uint16_t*)p; 311 | } 312 | p += 2; 313 | } 314 | if (cflags & C_IMM8) { 315 | hs->flags |= F_IMM8; 316 | hs->imm.imm8 = *p++; 317 | } 318 | 319 | if (cflags & C_REL32) { 320 | rel32_ok: 321 | hs->flags |= F_IMM32 | F_RELATIVE; 322 | hs->imm.imm32 = *(uint32_t*)p; 323 | p += 4; 324 | } 325 | else if (cflags & C_REL8) { 326 | hs->flags |= F_IMM8 | F_RELATIVE; 327 | hs->imm.imm8 = *p++; 328 | } 329 | 330 | disasm_done: 331 | 332 | if ((hs->len = (uint8_t)(p - (uint8_t*)code)) > 15) { 333 | hs->flags |= F_ERROR | F_ERROR_LENGTH; 334 | hs->len = 15; 335 | } 336 | 337 | return (unsigned int)hs->len; 338 | } 339 | 340 | #endif // defined(_M_IX86) || defined(__i386__) -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/minhook/hde/hde64.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #if defined(_M_X64) || defined(__x86_64__) 9 | 10 | #include "hde64.h" 11 | #include "table64.h" 12 | 13 | unsigned int hde64_disasm(const void* code, hde64s* hs) 14 | { 15 | uint8_t x, c, * p = (uint8_t*)code, cflags, opcode, pref = 0; 16 | uint8_t* ht = hde64_table, m_mod, m_reg, m_rm, disp_size = 0; 17 | uint8_t op64 = 0; 18 | 19 | // Avoid using memset to reduce the footprint. 20 | #ifndef _MSC_VER 21 | memset((LPBYTE)hs, 0, sizeof(hde64s)); 22 | #else 23 | __stosb((LPBYTE)hs, 0, sizeof(hde64s)); 24 | #endif 25 | 26 | for (x = 16; x; x--) 27 | switch (c = *p++) { 28 | case 0xf3: 29 | hs->p_rep = c; 30 | pref |= PRE_F3; 31 | break; 32 | case 0xf2: 33 | hs->p_rep = c; 34 | pref |= PRE_F2; 35 | break; 36 | case 0xf0: 37 | hs->p_lock = c; 38 | pref |= PRE_LOCK; 39 | break; 40 | case 0x26: case 0x2e: case 0x36: 41 | case 0x3e: case 0x64: case 0x65: 42 | hs->p_seg = c; 43 | pref |= PRE_SEG; 44 | break; 45 | case 0x66: 46 | hs->p_66 = c; 47 | pref |= PRE_66; 48 | break; 49 | case 0x67: 50 | hs->p_67 = c; 51 | pref |= PRE_67; 52 | break; 53 | default: 54 | goto pref_done; 55 | } 56 | pref_done: 57 | 58 | hs->flags = (uint32_t)pref << 23; 59 | 60 | if (!pref) 61 | pref |= PRE_NONE; 62 | 63 | if ((c & 0xf0) == 0x40) { 64 | hs->flags |= F_PREFIX_REX; 65 | if ((hs->rex_w = (c & 0xf) >> 3) && (*p & 0xf8) == 0xb8) 66 | op64++; 67 | hs->rex_r = (c & 7) >> 2; 68 | hs->rex_x = (c & 3) >> 1; 69 | hs->rex_b = c & 1; 70 | if (((c = *p++) & 0xf0) == 0x40) { 71 | opcode = c; 72 | goto error_opcode; 73 | } 74 | } 75 | 76 | if ((hs->opcode = c) == 0x0f) { 77 | hs->opcode2 = c = *p++; 78 | ht += DELTA_OPCODES; 79 | } 80 | else if (c >= 0xa0 && c <= 0xa3) { 81 | op64++; 82 | if (pref & PRE_67) 83 | pref |= PRE_66; 84 | else 85 | pref &= ~PRE_66; 86 | } 87 | 88 | opcode = c; 89 | cflags = ht[ht[opcode / 4] + (opcode % 4)]; 90 | 91 | if (cflags == C_ERROR) { 92 | error_opcode: 93 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 94 | cflags = 0; 95 | if ((opcode & -3) == 0x24) 96 | cflags++; 97 | } 98 | 99 | x = 0; 100 | if (cflags & C_GROUP) { 101 | uint16_t t; 102 | t = *(uint16_t*)(ht + (cflags & 0x7f)); 103 | cflags = (uint8_t)t; 104 | x = (uint8_t)(t >> 8); 105 | } 106 | 107 | if (hs->opcode2) { 108 | ht = hde64_table + DELTA_PREFIXES; 109 | if (ht[ht[opcode / 4] + (opcode % 4)] & pref) 110 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 111 | } 112 | 113 | if (cflags & C_MODRM) { 114 | hs->flags |= F_MODRM; 115 | hs->modrm = c = *p++; 116 | hs->modrm_mod = m_mod = c >> 6; 117 | hs->modrm_rm = m_rm = c & 7; 118 | hs->modrm_reg = m_reg = (c & 0x3f) >> 3; 119 | 120 | if (x && ((x << m_reg) & 0x80)) 121 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 122 | 123 | if (!hs->opcode2 && opcode >= 0xd9 && opcode <= 0xdf) { 124 | uint8_t t = opcode - 0xd9; 125 | if (m_mod == 3) { 126 | ht = hde64_table + DELTA_FPU_MODRM + t * 8; 127 | t = ht[m_reg] << m_rm; 128 | } 129 | else { 130 | ht = hde64_table + DELTA_FPU_REG; 131 | t = ht[t] << m_reg; 132 | } 133 | if (t & 0x80) 134 | hs->flags |= F_ERROR | F_ERROR_OPCODE; 135 | } 136 | 137 | if (pref & PRE_LOCK) { 138 | if (m_mod == 3) { 139 | hs->flags |= F_ERROR | F_ERROR_LOCK; 140 | } 141 | else { 142 | uint8_t* table_end, op = opcode; 143 | if (hs->opcode2) { 144 | ht = hde64_table + DELTA_OP2_LOCK_OK; 145 | table_end = ht + DELTA_OP_ONLY_MEM - DELTA_OP2_LOCK_OK; 146 | } 147 | else { 148 | ht = hde64_table + DELTA_OP_LOCK_OK; 149 | table_end = ht + DELTA_OP2_LOCK_OK - DELTA_OP_LOCK_OK; 150 | op &= -2; 151 | } 152 | for (; ht != table_end; ht++) 153 | if (*ht++ == op) { 154 | if (!((*ht << m_reg) & 0x80)) 155 | goto no_lock_error; 156 | else 157 | break; 158 | } 159 | hs->flags |= F_ERROR | F_ERROR_LOCK; 160 | no_lock_error: 161 | ; 162 | } 163 | } 164 | 165 | if (hs->opcode2) { 166 | switch (opcode) { 167 | case 0x20: case 0x22: 168 | m_mod = 3; 169 | if (m_reg > 4 || m_reg == 1) 170 | goto error_operand; 171 | else 172 | goto no_error_operand; 173 | case 0x21: case 0x23: 174 | m_mod = 3; 175 | if (m_reg == 4 || m_reg == 5) 176 | goto error_operand; 177 | else 178 | goto no_error_operand; 179 | } 180 | } 181 | else { 182 | switch (opcode) { 183 | case 0x8c: 184 | if (m_reg > 5) 185 | goto error_operand; 186 | else 187 | goto no_error_operand; 188 | case 0x8e: 189 | if (m_reg == 1 || m_reg > 5) 190 | goto error_operand; 191 | else 192 | goto no_error_operand; 193 | } 194 | } 195 | 196 | if (m_mod == 3) { 197 | uint8_t* table_end; 198 | if (hs->opcode2) { 199 | ht = hde64_table + DELTA_OP2_ONLY_MEM; 200 | table_end = ht + sizeof(hde64_table) - DELTA_OP2_ONLY_MEM; 201 | } 202 | else { 203 | ht = hde64_table + DELTA_OP_ONLY_MEM; 204 | table_end = ht + DELTA_OP2_ONLY_MEM - DELTA_OP_ONLY_MEM; 205 | } 206 | for (; ht != table_end; ht += 2) 207 | if (*ht++ == opcode) { 208 | if (*ht++ & pref && !((*ht << m_reg) & 0x80)) 209 | goto error_operand; 210 | else 211 | break; 212 | } 213 | goto no_error_operand; 214 | } 215 | else if (hs->opcode2) { 216 | switch (opcode) { 217 | case 0x50: case 0xd7: case 0xf7: 218 | if (pref & (PRE_NONE | PRE_66)) 219 | goto error_operand; 220 | break; 221 | case 0xd6: 222 | if (pref & (PRE_F2 | PRE_F3)) 223 | goto error_operand; 224 | break; 225 | case 0xc5: 226 | goto error_operand; 227 | } 228 | goto no_error_operand; 229 | } 230 | else 231 | goto no_error_operand; 232 | 233 | error_operand: 234 | hs->flags |= F_ERROR | F_ERROR_OPERAND; 235 | no_error_operand: 236 | 237 | c = *p++; 238 | if (m_reg <= 1) { 239 | if (opcode == 0xf6) 240 | cflags |= C_IMM8; 241 | else if (opcode == 0xf7) 242 | cflags |= C_IMM_P66; 243 | } 244 | 245 | switch (m_mod) { 246 | case 0: 247 | if (pref & PRE_67) { 248 | if (m_rm == 6) 249 | disp_size = 2; 250 | } 251 | else 252 | if (m_rm == 5) 253 | disp_size = 4; 254 | break; 255 | case 1: 256 | disp_size = 1; 257 | break; 258 | case 2: 259 | disp_size = 2; 260 | if (!(pref & PRE_67)) 261 | disp_size <<= 1; 262 | } 263 | 264 | if (m_mod != 3 && m_rm == 4) { 265 | hs->flags |= F_SIB; 266 | p++; 267 | hs->sib = c; 268 | hs->sib_scale = c >> 6; 269 | hs->sib_index = (c & 0x3f) >> 3; 270 | if ((hs->sib_base = c & 7) == 5 && !(m_mod & 1)) 271 | disp_size = 4; 272 | } 273 | 274 | p--; 275 | switch (disp_size) { 276 | case 1: 277 | hs->flags |= F_DISP8; 278 | hs->disp.disp8 = *p; 279 | break; 280 | case 2: 281 | hs->flags |= F_DISP16; 282 | hs->disp.disp16 = *(uint16_t*)p; 283 | break; 284 | case 4: 285 | hs->flags |= F_DISP32; 286 | hs->disp.disp32 = *(uint32_t*)p; 287 | } 288 | p += disp_size; 289 | } 290 | else if (pref & PRE_LOCK) 291 | hs->flags |= F_ERROR | F_ERROR_LOCK; 292 | 293 | if (cflags & C_IMM_P66) { 294 | if (cflags & C_REL32) { 295 | if (pref & PRE_66) { 296 | hs->flags |= F_IMM16 | F_RELATIVE; 297 | hs->imm.imm16 = *(uint16_t*)p; 298 | p += 2; 299 | goto disasm_done; 300 | } 301 | goto rel32_ok; 302 | } 303 | if (op64) { 304 | hs->flags |= F_IMM64; 305 | hs->imm.imm64 = *(uint64_t*)p; 306 | p += 8; 307 | } 308 | else if (!(pref & PRE_66)) { 309 | hs->flags |= F_IMM32; 310 | hs->imm.imm32 = *(uint32_t*)p; 311 | p += 4; 312 | } 313 | else 314 | goto imm16_ok; 315 | } 316 | 317 | if (cflags & C_IMM16) { 318 | imm16_ok: 319 | hs->flags |= F_IMM16; 320 | hs->imm.imm16 = *(uint16_t*)p; 321 | p += 2; 322 | } 323 | if (cflags & C_IMM8) { 324 | hs->flags |= F_IMM8; 325 | hs->imm.imm8 = *p++; 326 | } 327 | 328 | if (cflags & C_REL32) { 329 | rel32_ok: 330 | hs->flags |= F_IMM32 | F_RELATIVE; 331 | hs->imm.imm32 = *(uint32_t*)p; 332 | p += 4; 333 | } 334 | else if (cflags & C_REL8) { 335 | hs->flags |= F_IMM8 | F_RELATIVE; 336 | hs->imm.imm8 = *p++; 337 | } 338 | 339 | disasm_done: 340 | 341 | if ((hs->len = (uint8_t)(p - (uint8_t*)code)) > 15) { 342 | hs->flags |= F_ERROR | F_ERROR_LENGTH; 343 | hs->len = 15; 344 | } 345 | 346 | return (unsigned int)hs->len; 347 | } 348 | 349 | #endif // defined(_M_X64) || defined(__x86_64__) -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/utilities/utilities.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "pattern/pattern.hpp" 3 | #include 4 | #include 5 | 6 | // helper for signature scanning results 7 | struct s_pattern { 8 | uintptr_t address; 9 | 10 | constexpr s_pattern() : address(0) {} 11 | 12 | constexpr s_pattern(uintptr_t address) : address(address) {} 13 | 14 | template 15 | constexpr t cast() { 16 | return reinterpret_cast(address); 17 | } 18 | 19 | template 20 | constexpr t scast() { 21 | return static_cast(address); 22 | } 23 | 24 | template 25 | constexpr t ccast() { 26 | return const_cast(address); 27 | } 28 | 29 | template 30 | t relative(size_t offset = 0x1) { 31 | if (!address) 32 | return t(); 33 | 34 | size_t new_address = address + offset; 35 | int32_t relative_offset = *reinterpret_cast(new_address); 36 | 37 | if (!relative_offset) 38 | return t(); 39 | 40 | return reinterpret_cast(new_address + sizeof(size_t) + relative_offset); 41 | } 42 | }; 43 | 44 | // helper for memory region data 45 | struct s_memoryregion { 46 | uintptr_t base; 47 | size_t region_size; 48 | uintptr_t state; 49 | uintptr_t protect; 50 | uintptr_t type; 51 | 52 | s_memoryregion(MEMORY_BASIC_INFORMATION32 mbi) { 53 | base = mbi.BaseAddress; 54 | region_size = mbi.RegionSize; 55 | state = mbi.State; 56 | protect = mbi.Protect; 57 | type = mbi.Type; 58 | } 59 | }; 60 | 61 | namespace n_utilities { 62 | // helpers for virtual functions 63 | template 64 | constexpr t call_vfunc(void* thisptr, args... arg_list) { 65 | using fn = t(__thiscall*)(void*, decltype(arg_list)...); 66 | return (*static_cast(thisptr))[idx](thisptr, arg_list...); 67 | } 68 | 69 | template 70 | constexpr t get_vfunc(void* class_pointer, size_t index) { 71 | return (t)(*(t**)class_pointer)[index]; 72 | } 73 | 74 | unsigned constexpr hash_str(char const* input) { 75 | constexpr unsigned int past_char_additive = 33; 76 | constexpr unsigned int default_output = 5381; 77 | 78 | return *input ? static_cast(*input) + past_char_additive * hash_str(input + 1) : default_output; 79 | } 80 | 81 | static s_pattern find_signature(uintptr_t start, uintptr_t length, s_sighelper& signature) { 82 | mem::region range; 83 | range.start = start; 84 | range.size = length; 85 | 86 | mem::pattern pattern_to_search(signature.sig); 87 | mem::default_scanner scanner(pattern_to_search); 88 | uintptr_t return_value{}; 89 | 90 | scanner(range, [&](mem::pointer address) { 91 | return_value = address.add(signature.offset).as(); 92 | 93 | return false; 94 | }); 95 | 96 | return return_value; 97 | } 98 | 99 | static s_pattern find_signature(HMODULE hmodule, s_sighelper& signature) { 100 | MODULEINFO mod_info{}; 101 | GetModuleInformation(GetCurrentProcess(), hmodule, &mod_info, sizeof(MODULEINFO)); 102 | 103 | return find_signature(reinterpret_cast(hmodule), mod_info.SizeOfImage, signature); 104 | } 105 | 106 | static s_pattern find_signature(s_sighelper& signature) { 107 | std::list memory_regions{}; 108 | uintptr_t return_value{}; 109 | 110 | // dump memory regions 111 | [&memory_regions]() -> void { 112 | memory_regions.clear(); 113 | 114 | MEMORY_BASIC_INFORMATION32 mbi{}; 115 | LPCVOID address = 0; 116 | 117 | while (VirtualQueryEx(GetCurrentProcess(), address, reinterpret_cast(&mbi), sizeof(mbi)) != 0) { 118 | if (mbi.State == MEM_COMMIT && mbi.Protect >= 0x10 && mbi.Protect <= 0x80) 119 | memory_regions.push_back(*new s_memoryregion(mbi)); 120 | 121 | address = reinterpret_cast(mbi.BaseAddress + mbi.RegionSize); 122 | } 123 | }(); 124 | 125 | for (const auto& region : memory_regions) { 126 | if (return_value) 127 | break; 128 | 129 | return_value = find_signature(region.base, region.region_size, signature).address; 130 | } 131 | 132 | return return_value; 133 | } 134 | 135 | strong_inline s_pattern find_signature(const char* hmodule, s_sighelper& signature) { 136 | return find_signature(GetModuleHandle(hmodule), signature); 137 | } 138 | 139 | static uintptr_t find_pattern_down(HMODULE hmodule, uintptr_t size, s_sighelper& signature) { 140 | if (!hmodule) 141 | return 0x0; 142 | 143 | const auto pattern_length = strlen(signature.sig); 144 | 145 | for (auto i = reinterpret_cast(hmodule); i < (reinterpret_cast(hmodule) + size) - pattern_length; i++) { 146 | bool found = true; 147 | 148 | for (size_t idx = 0; idx < pattern_length; idx++) { 149 | if (signature.sig[idx] != *(char*)(i + idx)) { 150 | found = false; 151 | break; 152 | } 153 | } 154 | 155 | if (found) 156 | return i + signature.offset; 157 | } 158 | 159 | return 0x0; 160 | } 161 | 162 | strong_inline uintptr_t find_str_ref(HMODULE hmodule, uintptr_t size, s_sighelper& signature) { 163 | // push null_address 164 | char push_address[] = { 0x68, 0x00, 0x00, 0x00, 0x00, 0x00 }; 165 | 166 | s_sighelper txt(signature.sig); 167 | uintptr_t str_def = find_pattern_down(hmodule, size, txt); 168 | 169 | if (!str_def) 170 | return 0x0; 171 | 172 | // push str_def 173 | *(uintptr_t*)&push_address[1] = str_def; 174 | 175 | txt.sig = push_address; 176 | uintptr_t str_ref = find_pattern_down(hmodule, size, txt); 177 | 178 | return str_ref ? str_ref + signature.offset : 0x0; 179 | } 180 | 181 | static uintptr_t get_export_from_table(uintptr_t module_base, unsigned int export_hash) { 182 | auto dos_headers = reinterpret_cast(module_base); 183 | auto nt_headers = reinterpret_cast(module_base + dos_headers->e_lfanew); 184 | IMAGE_OPTIONAL_HEADER* optional_header = &nt_headers->OptionalHeader; 185 | 186 | uintptr_t exportdir_address = optional_header->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress; 187 | 188 | // we aint got no exports :c 189 | if (optional_header->DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size <= 0U) 190 | return 0x0; 191 | 192 | auto export_directory = reinterpret_cast(module_base + exportdir_address); 193 | auto names_rva = reinterpret_cast(module_base + export_directory->AddressOfNames); 194 | auto functions_rva = reinterpret_cast(module_base + export_directory->AddressOfFunctions); 195 | auto name_ordinals = reinterpret_cast(module_base + export_directory->AddressOfNameOrdinals); 196 | 197 | // perform binary search 198 | for (size_t i = 0; i < export_directory->AddressOfFunctions; i++) { 199 | const char* export_name = reinterpret_cast(module_base + names_rva[i]); 200 | 201 | if (export_hash == hash_str(export_name)) 202 | return module_base + functions_rva[name_ordinals[i]]; 203 | } 204 | 205 | return 0x0; 206 | } 207 | template 208 | strong_inline type get_export_from_table(uintptr_t module_base, unsigned int export_hash) { 209 | return reinterpret_cast(get_export_from_table(module_base, export_hash)); 210 | } 211 | 212 | strong_inline void attach_console(const char* name) { 213 | #ifdef _DEBUG 214 | AllocConsole(); 215 | freopen_s(reinterpret_cast(stdin), "CONIN$", "r", stdin); 216 | freopen_s(reinterpret_cast(stdout), "CONOUT$", "w", stdout); 217 | SetConsoleTitleA(name); 218 | #endif 219 | } 220 | 221 | strong_inline void detach_console() { 222 | #ifdef _DEBUG 223 | fclose(reinterpret_cast(stdin)); 224 | fclose(reinterpret_cast(stdout)); 225 | FreeConsole(); 226 | PostMessageW(GetConsoleWindow(), WM_CLOSE, 0, 0); 227 | #endif 228 | } 229 | } // namespace n_utilities 230 | 231 | // utility helpers 232 | #define HASH(input) n_utilities::hash_str(input) -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // COMPILE-TIME OPTIONS FOR DEAR IMGUI 3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. 4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. 5 | //----------------------------------------------------------------------------- 6 | // A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it) 7 | // B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template. 8 | //----------------------------------------------------------------------------- 9 | // You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp 10 | // files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures. 11 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. 12 | // Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using. 13 | //----------------------------------------------------------------------------- 14 | 15 | #pragma once 16 | 17 | //---- Define assertion handler. Defaults to calling assert(). 18 | // If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. 19 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 20 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts 21 | 22 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows 23 | // Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. 24 | // DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions() 25 | // for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details. 26 | //#define IMGUI_API __declspec( dllexport ) 27 | //#define IMGUI_API __declspec( dllimport ) 28 | 29 | //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. 30 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 31 | //#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions. 32 | 33 | //---- Disable all of Dear ImGui or don't implement standard windows/tools. 34 | // It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp. 35 | //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. 36 | //#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. 37 | //#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88). 38 | 39 | //---- Don't implement some functions to reduce linkage requirements. 40 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a) 41 | //#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW) 42 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a) 43 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime). 44 | //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). 45 | //#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) 46 | //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. 47 | //#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies) 48 | //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. 49 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). 50 | //#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available 51 | 52 | //---- Include imgui_user.h at the end of imgui.h as a convenience 53 | //#define IMGUI_INCLUDE_IMGUI_USER_H 54 | 55 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 56 | //#define IMGUI_USE_BGRA_PACKED_COLOR 57 | 58 | //---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...) 59 | //#define IMGUI_USE_WCHAR32 60 | 61 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 62 | // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. 63 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 64 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 65 | //#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if enabled 66 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 67 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 68 | 69 | //---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) 70 | // Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h. 71 | //#define IMGUI_USE_STB_SPRINTF 72 | 73 | //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) 74 | // Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided). 75 | // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. 76 | //#define IMGUI_ENABLE_FREETYPE 77 | 78 | //---- Use stb_truetype to build and rasterize the font atlas (default) 79 | // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. 80 | //#define IMGUI_ENABLE_STB_TRUETYPE 81 | 82 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 83 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 84 | /* 85 | #define IM_VEC2_CLASS_EXTRA \ 86 | constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ 87 | operator MyVec2() const { return MyVec2(x,y); } 88 | 89 | #define IM_VEC4_CLASS_EXTRA \ 90 | constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ 91 | operator MyVec4() const { return MyVec4(x,y,z,w); } 92 | */ 93 | 94 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. 95 | // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). 96 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. 97 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. 98 | //#define ImDrawIdx unsigned int 99 | 100 | //---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) 101 | //struct ImDrawList; 102 | //struct ImDrawCmd; 103 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); 104 | //#define ImDrawCallback MyImDrawCallback 105 | 106 | //---- Debug Tools: Macro to break in Debugger 107 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) 108 | //#define IM_DEBUG_BREAK IM_ASSERT(0) 109 | //#define IM_DEBUG_BREAK __debugbreak() 110 | 111 | //---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(), 112 | // (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.) 113 | // This adds a small runtime cost which is why it is not enabled by default. 114 | //#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX 115 | 116 | //---- Debug Tools: Enable slower asserts 117 | //#define IMGUI_DEBUG_PARANOID 118 | 119 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files. 120 | /* 121 | namespace ImGui 122 | { 123 | void MyFunction(const char* name, const MyMatrix44& v); 124 | } 125 | */ 126 | -------------------------------------------------------------------------------- /patoke-sdk-cs16/patoke-sdk-cs16.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | Header Files 41 | 42 | 43 | Header Files 44 | 45 | 46 | Header Files 47 | 48 | 49 | Header Files 50 | 51 | 52 | Header Files 53 | 54 | 55 | Header Files 56 | 57 | 58 | Header Files 59 | 60 | 61 | Header Files 62 | 63 | 64 | Header Files 65 | 66 | 67 | Header Files 68 | 69 | 70 | Header Files 71 | 72 | 73 | Header Files 74 | 75 | 76 | Header Files 77 | 78 | 79 | Header Files 80 | 81 | 82 | Header Files 83 | 84 | 85 | Header Files 86 | 87 | 88 | Header Files 89 | 90 | 91 | Header Files 92 | 93 | 94 | Header Files 95 | 96 | 97 | Header Files 98 | 99 | 100 | Header Files 101 | 102 | 103 | Header Files 104 | 105 | 106 | Header Files 107 | 108 | 109 | Header Files 110 | 111 | 112 | Header Files 113 | 114 | 115 | Header Files 116 | 117 | 118 | Header Files 119 | 120 | 121 | Header Files 122 | 123 | 124 | Header Files 125 | 126 | 127 | Header Files 128 | 129 | 130 | Header Files 131 | 132 | 133 | Header Files 134 | 135 | 136 | Header Files 137 | 138 | 139 | Header Files 140 | 141 | 142 | Header Files 143 | 144 | 145 | Header Files 146 | 147 | 148 | Header Files 149 | 150 | 151 | Header Files 152 | 153 | 154 | Header Files 155 | 156 | 157 | Header Files 158 | 159 | 160 | Header Files 161 | 162 | 163 | Header Files 164 | 165 | 166 | Header Files 167 | 168 | 169 | 170 | 171 | Source Files 172 | 173 | 174 | Source Files 175 | 176 | 177 | Source Files 178 | 179 | 180 | Source Files 181 | 182 | 183 | Source Files 184 | 185 | 186 | Source Files 187 | 188 | 189 | Source Files 190 | 191 | 192 | Source Files 193 | 194 | 195 | Source Files 196 | 197 | 198 | Source Files 199 | 200 | 201 | Source Files 202 | 203 | 204 | Source Files 205 | 206 | 207 | Source Files 208 | 209 | 210 | Source Files 211 | 212 | 213 | Source Files 214 | 215 | 216 | Source Files 217 | 218 | 219 | Source Files 220 | 221 | 222 | Source Files 223 | 224 | 225 | Source Files 226 | 227 | 228 | Source Files 229 | 230 | 231 | Source Files 232 | 233 | 234 | Source Files 235 | 236 | 237 | Source Files 238 | 239 | 240 | Source Files 241 | 242 | 243 | -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/libraries/minhook/trampoline.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | 32 | #ifndef ARRAYSIZE 33 | #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0])) 34 | #endif 35 | 36 | #if defined(_M_X64) || defined(__x86_64__) 37 | #include "./hde/hde64.h" 38 | typedef hde64s HDE; 39 | #define HDE_DISASM(code, hs) hde64_disasm(code, hs) 40 | #else 41 | #include "./hde/hde32.h" 42 | typedef hde32s HDE; 43 | #define HDE_DISASM(code, hs) hde32_disasm(code, hs) 44 | #endif 45 | 46 | #include "trampoline.h" 47 | #include "buffer.h" 48 | 49 | // Maximum size of a trampoline function. 50 | #if defined(_M_X64) || defined(__x86_64__) 51 | #define TRAMPOLINE_MAX_SIZE (MEMORY_SLOT_SIZE - sizeof(JMP_ABS)) 52 | #else 53 | #define TRAMPOLINE_MAX_SIZE MEMORY_SLOT_SIZE 54 | #endif 55 | 56 | //------------------------------------------------------------------------- 57 | static BOOL IsCodePadding(LPBYTE pInst, UINT size) 58 | { 59 | UINT i; 60 | 61 | if (pInst[0] != 0x00 && pInst[0] != 0x90 && pInst[0] != 0xCC) 62 | return FALSE; 63 | 64 | for (i = 1; i < size; ++i) 65 | { 66 | if (pInst[i] != pInst[0]) 67 | return FALSE; 68 | } 69 | return TRUE; 70 | } 71 | 72 | //------------------------------------------------------------------------- 73 | BOOL CreateTrampolineFunction(PTRAMPOLINE ct) 74 | { 75 | #if defined(_M_X64) || defined(__x86_64__) 76 | CALL_ABS call = { 77 | 0xFF, 0x15, 0x00000002, // FF15 00000002: CALL [RIP+8] 78 | 0xEB, 0x08, // EB 08: JMP +10 79 | 0x0000000000000000ULL // Absolute destination address 80 | }; 81 | JMP_ABS jmp = { 82 | 0xFF, 0x25, 0x00000000, // FF25 00000000: JMP [RIP+6] 83 | 0x0000000000000000ULL // Absolute destination address 84 | }; 85 | JCC_ABS jcc = { 86 | 0x70, 0x0E, // 7* 0E: J** +16 87 | 0xFF, 0x25, 0x00000000, // FF25 00000000: JMP [RIP+6] 88 | 0x0000000000000000ULL // Absolute destination address 89 | }; 90 | #else 91 | CALL_REL call = { 92 | 0xE8, // E8 xxxxxxxx: CALL +5+xxxxxxxx 93 | 0x00000000 // Relative destination address 94 | }; 95 | JMP_REL jmp = { 96 | 0xE9, // E9 xxxxxxxx: JMP +5+xxxxxxxx 97 | 0x00000000 // Relative destination address 98 | }; 99 | JCC_REL jcc = { 100 | 0x0F, 0x80, // 0F8* xxxxxxxx: J** +6+xxxxxxxx 101 | 0x00000000 // Relative destination address 102 | }; 103 | #endif 104 | 105 | UINT8 oldPos = 0; 106 | UINT8 newPos = 0; 107 | ULONG_PTR jmpDest = 0; // Destination address of an internal jump. 108 | BOOL finished = FALSE; // Is the function completed? 109 | #if defined(_M_X64) || defined(__x86_64__) 110 | UINT8 instBuf[16]; 111 | #endif 112 | 113 | ct->patchAbove = FALSE; 114 | ct->nIP = 0; 115 | 116 | do 117 | { 118 | HDE hs; 119 | UINT copySize; 120 | LPVOID pCopySrc; 121 | ULONG_PTR pOldInst = (ULONG_PTR)ct->pTarget + oldPos; 122 | ULONG_PTR pNewInst = (ULONG_PTR)ct->pTrampoline + newPos; 123 | 124 | copySize = HDE_DISASM((LPVOID)pOldInst, &hs); 125 | if (hs.flags & F_ERROR) 126 | return FALSE; 127 | 128 | pCopySrc = (LPVOID)pOldInst; 129 | if (oldPos >= sizeof(JMP_REL)) 130 | { 131 | // The trampoline function is long enough. 132 | // Complete the function with the jump to the target function. 133 | #if defined(_M_X64) || defined(__x86_64__) 134 | jmp.address = pOldInst; 135 | #else 136 | jmp.operand = (UINT32)(pOldInst - (pNewInst + sizeof(jmp))); 137 | #endif 138 | pCopySrc = &jmp; 139 | copySize = sizeof(jmp); 140 | 141 | finished = TRUE; 142 | } 143 | #if defined(_M_X64) || defined(__x86_64__) 144 | else if ((hs.modrm & 0xC7) == 0x05) 145 | { 146 | // Instructions using RIP relative addressing. (ModR/M = 00???101B) 147 | 148 | // Modify the RIP relative address. 149 | PUINT32 pRelAddr; 150 | 151 | // Avoid using memcpy to reduce the footprint. 152 | #ifndef _MSC_VER 153 | memcpy(instBuf, (LPBYTE)pOldInst, copySize); 154 | #else 155 | __movsb(instBuf, (LPBYTE)pOldInst, copySize); 156 | #endif 157 | pCopySrc = instBuf; 158 | 159 | // Relative address is stored at (instruction length - immediate value length - 4). 160 | pRelAddr = (PUINT32)(instBuf + hs.len - ((hs.flags & 0x3C) >> 2) - 4); 161 | *pRelAddr 162 | = (UINT32)((pOldInst + hs.len + (INT32)hs.disp.disp32) - (pNewInst + hs.len)); 163 | 164 | // Complete the function if JMP (FF /4). 165 | if (hs.opcode == 0xFF && hs.modrm_reg == 4) 166 | finished = TRUE; 167 | } 168 | #endif 169 | else if (hs.opcode == 0xE8) 170 | { 171 | // Direct relative CALL 172 | ULONG_PTR dest = pOldInst + hs.len + (INT32)hs.imm.imm32; 173 | #if defined(_M_X64) || defined(__x86_64__) 174 | call.address = dest; 175 | #else 176 | call.operand = (UINT32)(dest - (pNewInst + sizeof(call))); 177 | #endif 178 | pCopySrc = &call; 179 | copySize = sizeof(call); 180 | } 181 | else if ((hs.opcode & 0xFD) == 0xE9) 182 | { 183 | // Direct relative JMP (EB or E9) 184 | ULONG_PTR dest = pOldInst + hs.len; 185 | 186 | if (hs.opcode == 0xEB) // isShort jmp 187 | dest += (INT8)hs.imm.imm8; 188 | else 189 | dest += (INT32)hs.imm.imm32; 190 | 191 | // Simply copy an internal jump. 192 | if ((ULONG_PTR)ct->pTarget <= dest 193 | && dest < ((ULONG_PTR)ct->pTarget + sizeof(JMP_REL))) 194 | { 195 | if (jmpDest < dest) 196 | jmpDest = dest; 197 | } 198 | else 199 | { 200 | #if defined(_M_X64) || defined(__x86_64__) 201 | jmp.address = dest; 202 | #else 203 | jmp.operand = (UINT32)(dest - (pNewInst + sizeof(jmp))); 204 | #endif 205 | pCopySrc = &jmp; 206 | copySize = sizeof(jmp); 207 | 208 | // Exit the function If it is not in the branch 209 | finished = (pOldInst >= jmpDest); 210 | } 211 | } 212 | else if ((hs.opcode & 0xF0) == 0x70 213 | || (hs.opcode & 0xFC) == 0xE0 214 | || (hs.opcode2 & 0xF0) == 0x80) 215 | { 216 | // Direct relative Jcc 217 | ULONG_PTR dest = pOldInst + hs.len; 218 | 219 | if ((hs.opcode & 0xF0) == 0x70 // Jcc 220 | || (hs.opcode & 0xFC) == 0xE0) // LOOPNZ/LOOPZ/LOOP/JECXZ 221 | dest += (INT8)hs.imm.imm8; 222 | else 223 | dest += (INT32)hs.imm.imm32; 224 | 225 | // Simply copy an internal jump. 226 | if ((ULONG_PTR)ct->pTarget <= dest 227 | && dest < ((ULONG_PTR)ct->pTarget + sizeof(JMP_REL))) 228 | { 229 | if (jmpDest < dest) 230 | jmpDest = dest; 231 | } 232 | else if ((hs.opcode & 0xFC) == 0xE0) 233 | { 234 | // LOOPNZ/LOOPZ/LOOP/JCXZ/JECXZ to the outside are not supported. 235 | return FALSE; 236 | } 237 | else 238 | { 239 | UINT8 cond = ((hs.opcode != 0x0F ? hs.opcode : hs.opcode2) & 0x0F); 240 | #if defined(_M_X64) || defined(__x86_64__) 241 | // Invert the condition in x64 mode to simplify the conditional jump logic. 242 | jcc.opcode = 0x71 ^ cond; 243 | jcc.address = dest; 244 | #else 245 | jcc.opcode1 = 0x80 | cond; 246 | jcc.operand = (UINT32)(dest - (pNewInst + sizeof(jcc))); 247 | #endif 248 | pCopySrc = &jcc; 249 | copySize = sizeof(jcc); 250 | } 251 | } 252 | else if ((hs.opcode & 0xFE) == 0xC2) 253 | { 254 | // RET (C2 or C3) 255 | 256 | // Complete the function if not in a branch. 257 | finished = (pOldInst >= jmpDest); 258 | } 259 | 260 | // Can't alter the instruction length in a branch. 261 | if (pOldInst < jmpDest && copySize != hs.len) 262 | return FALSE; 263 | 264 | // Trampoline function is too large. 265 | if ((newPos + copySize) > TRAMPOLINE_MAX_SIZE) 266 | return FALSE; 267 | 268 | // Trampoline function has too many instructions. 269 | if (ct->nIP >= ARRAYSIZE(ct->oldIPs)) 270 | return FALSE; 271 | 272 | ct->oldIPs[ct->nIP] = oldPos; 273 | ct->newIPs[ct->nIP] = newPos; 274 | ct->nIP++; 275 | 276 | // Avoid using memcpy to reduce the footprint. 277 | #ifndef _MSC_VER 278 | memcpy((LPBYTE)ct->pTrampoline + newPos, pCopySrc, copySize); 279 | #else 280 | __movsb((LPBYTE)ct->pTrampoline + newPos, (const unsigned char*)pCopySrc, copySize); 281 | #endif 282 | newPos += copySize; 283 | oldPos += hs.len; 284 | } while (!finished); 285 | 286 | // Is there enough place for a long jump? 287 | if (oldPos < sizeof(JMP_REL) 288 | && !IsCodePadding((LPBYTE)ct->pTarget + oldPos, sizeof(JMP_REL) - oldPos)) 289 | { 290 | // Is there enough place for a short jump? 291 | if (oldPos < sizeof(JMP_REL_SHORT) 292 | && !IsCodePadding((LPBYTE)ct->pTarget + oldPos, sizeof(JMP_REL_SHORT) - oldPos)) 293 | { 294 | return FALSE; 295 | } 296 | 297 | // Can we place the long jump above the function? 298 | if (!IsExecutableAddress((LPBYTE)ct->pTarget - sizeof(JMP_REL))) 299 | return FALSE; 300 | 301 | if (!IsCodePadding((LPBYTE)ct->pTarget - sizeof(JMP_REL), sizeof(JMP_REL))) 302 | return FALSE; 303 | 304 | ct->patchAbove = TRUE; 305 | } 306 | 307 | #if defined(_M_X64) || defined(__x86_64__) 308 | // Create a relay function. 309 | jmp.address = (ULONG_PTR)ct->pDetour; 310 | 311 | ct->pRelay = (LPBYTE)ct->pTrampoline + newPos; 312 | memcpy(ct->pRelay, &jmp, sizeof(jmp)); 313 | #endif 314 | 315 | return TRUE; 316 | } 317 | -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/game/sdk/classes/playermove.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "const.hpp" 3 | #include "cmd.hpp" 4 | 5 | #define MAX_PHYSENTS 600 // Must have room for all entities in the world. 6 | #define MAX_MOVEENTS 64 7 | #define MAX_CLIP_PLANES 5 8 | 9 | #define PM_NORMAL 0x00000000 10 | #define PM_STUDIO_IGNORE 0x00000001 // Skip studio models 11 | #define PM_STUDIO_BOX 0x00000002 // Use boxes for non-complex studio models (even in traceline) 12 | #define PM_GLASS_IGNORE 0x00000004 // Ignore entities with non-normal rendermode 13 | #define PM_WORLD_ONLY 0x00000008 // Only trace against the world 14 | 15 | #define PM_TRACELINE_PHYSENTSONLY 0 16 | #define PM_TRACELINE_ANYVISIBLE 1 17 | 18 | #define MAX_PHYSINFO_STRING 256 19 | 20 | #define CTEXTURESMAX 1024 // max number of textures loaded 21 | #define CBTEXTURENAMEMAX 17 // only load first n chars of name 22 | 23 | #define CHAR_TEX_CONCRETE 'C' // texture types 24 | #define CHAR_TEX_METAL 'M' 25 | #define CHAR_TEX_DIRT 'D' 26 | #define CHAR_TEX_VENT 'V' 27 | #define CHAR_TEX_GRATE 'G' 28 | #define CHAR_TEX_TILE 'T' 29 | #define CHAR_TEX_SLOSH 'S' 30 | #define CHAR_TEX_WOOD 'W' 31 | #define CHAR_TEX_COMPUTER 'P' 32 | #define CHAR_TEX_GRASS 'X' 33 | #define CHAR_TEX_GLASS 'Y' 34 | #define CHAR_TEX_FLESH 'F' 35 | #define CHAR_TEX_SNOW 'N' 36 | 37 | #define PM_DEAD_VIEWHEIGHT -8 38 | 39 | #define OBS_NONE 0 40 | #define OBS_CHASE_LOCKED 1 41 | #define OBS_CHASE_FREE 2 42 | #define OBS_ROAMING 3 43 | #define OBS_IN_EYE 4 44 | #define OBS_MAP_FREE 5 45 | #define OBS_MAP_CHASE 6 46 | 47 | #define STEP_CONCRETE 0 48 | #define STEP_METAL 1 49 | #define STEP_DIRT 2 50 | #define STEP_VENT 3 51 | #define STEP_GRATE 4 52 | #define STEP_TILE 5 53 | #define STEP_SLOSH 6 54 | #define STEP_WADE 7 55 | #define STEP_LADDER 8 56 | #define STEP_SNOW 9 57 | 58 | #define WJ_HEIGHT 8 59 | #define STOP_EPSILON 0.1 60 | #define MAX_CLIMB_SPEED 200 61 | #define PLAYER_DUCKING_MULTIPLIER 0.333 62 | #define PM_CHECKSTUCK_MINTIME 0.05 // Don't check again too quickly. 63 | 64 | #define PLAYER_LONGJUMP_SPEED 350.0f // how fast we longjump 65 | 66 | // Ducking time 67 | #define TIME_TO_DUCK 0.4 68 | #define STUCK_MOVEUP 1 69 | 70 | #define PM_VEC_DUCK_HULL_MIN -18.f 71 | #define PM_VEC_HULL_MIN -36.f 72 | #define PM_VEC_DUCK_VIEW 12.f 73 | #define PM_VEC_VIEW 17.f 74 | 75 | #define PM_PLAYER_MAX_SAFE_FALL_SPEED 504.8F // approx 20 feet 76 | #define PM_PLAYER_MIN_BOUNCE_SPEED 350 77 | #define PM_PLAYER_FALL_PUNCH_THRESHHOLD 250 // won't punch player's screen/make scrape noise unless player falling at least this fast. 78 | #define PM_PLAYER_FATAL_FALL_SPEED 980.0F 79 | #define PM_DAMAGE_FOR_FALL_SPEED 100.0F / (PM_PLAYER_FATAL_FALL_SPEED - PM_PLAYER_MAX_SAFE_FALL_SPEED); 80 | 81 | // Only allow bunny jumping up to 1.2x server / player maxspeed setting 82 | #define BUNNYJUMP_MAX_SPEED_FACTOR 1.2f 83 | 84 | typedef struct 85 | { 86 | s_vec3 normal; 87 | float dist; 88 | } pmplane_t; 89 | 90 | typedef struct pmtrace_s pmtrace_t; 91 | 92 | struct pmtrace_s 93 | { 94 | int allsolid; // if true, plane is not valid 95 | int startsolid; // if true, the initial point was in a solid area 96 | int inopen, inwater; // End point is in empty space or in water 97 | float fraction; // time completed, 1.0 = didn't hit anything 98 | s_vec3 endpos; // final position 99 | pmplane_t plane; // surface normal at impact 100 | int ent; // entity at impact 101 | s_vec3 deltavelocity; // Change in player's velocity caused by impact. 102 | // Only run on server. 103 | int hitgroup; 104 | }; 105 | 106 | typedef struct movevars_s 107 | { 108 | float gravity; // Gravity for map 109 | float stopspeed; // Deceleration when not moving 110 | float maxspeed; // Max allowed speed 111 | float spectatormaxspeed; 112 | float accelerate; // Acceleration factor 113 | float airaccelerate; // Same for when in open air 114 | float wateraccelerate; // Same for when in water 115 | float friction; 116 | float edgefriction; // Extra friction near dropofs 117 | float waterfriction; // Less in water 118 | float entgravity; // 1.0 119 | float bounce; // Wall bounce value. 1.0 120 | float stepsize; // sv_stepsize; 121 | float maxvelocity; // maximum server velocity. 122 | float zmax; // Max z-buffer range (for GL) 123 | float waveHeight; // Water wave height (for GL) 124 | int footsteps; // Play footstep sounds 125 | char skyName[32]; // Name of the sky map 126 | float rollangle; 127 | float rollspeed; 128 | float skycolor_r; // Sky color 129 | float skycolor_g; 130 | float skycolor_b; 131 | float skyvec_x; // Sky s_vec3 132 | float skyvec_y; 133 | float skyvec_z; 134 | 135 | } movevars_t; 136 | 137 | typedef struct physent_s 138 | { 139 | char name[32]; // Name of model, or "player" or "world". 140 | int player; 141 | s_vec3 origin; // Model's origin in world coordinates. 142 | struct model_s* model; // only for bsp models 143 | struct model_s* studiomodel; // SOLID_BBOX, but studio clip intersections. 144 | s_vec3 mins, maxs; // only for non-bsp models 145 | int info; // For client or server to use to identify (index into edicts or cl_entities) 146 | s_angle angles; // rotated entities need this info for hull testing to work. 147 | 148 | int solid; // Triggers and func_door type WATER brushes are SOLID_NOT 149 | int skin; // BSP Contents for such things like fun_door water brushes. 150 | int rendermode; // So we can ignore glass 151 | 152 | float frame; 153 | int sequence; 154 | byte controller[4]; 155 | byte blending[2]; 156 | 157 | int movetype; 158 | int takedamage; 159 | int blooddecal; 160 | int team; 161 | int classnumber; 162 | 163 | int iuser1; 164 | int iuser2; 165 | int iuser3; 166 | int iuser4; 167 | float fuser1; 168 | float fuser2; 169 | float fuser3; 170 | float fuser4; 171 | s_vec3 vuser1; 172 | s_vec3 vuser2; 173 | s_vec3 vuser3; 174 | s_vec3 vuser4; 175 | 176 | } physent_t; 177 | 178 | typedef struct playermove_s 179 | { 180 | int player_index; // So we don't try to run the PM_CheckStuck nudging too quickly. 181 | int server; // For debugging, are we running physics code on server side? 182 | int multiplayer; // 1 == multiplayer server 183 | float time; // realtime on host, for reckoning duck timing 184 | float frametime; // Duration of this frame 185 | s_vec3 forward, right, up; // s_vec3s for angles 186 | s_vec3 origin; // Movement origin. 187 | s_angle angles; // Movement view angles. 188 | s_angle oldangles; // Angles before movement view angles were looked at. 189 | s_vec3 velocity; // Current movement direction. 190 | s_vec3 movedir; // For waterjumping, a forced forward velocity so we can fly over lip of ledge. 191 | s_vec3 basevelocity; // Velocity of the conveyor we are standing, e.g. 192 | s_vec3 view_ofs; // For ducking/dead 193 | // Our eye position. 194 | float flDuckTime; // Time we started duck 195 | int bInDuck; // In process of ducking or ducked already? 196 | int flTimeStepSound; // For walking/falling 197 | // Next time we can play a step sound 198 | int iStepLeft; 199 | float flFallVelocity; 200 | s_angle punchangle; 201 | float flSwimTime; 202 | float flNextPrimaryAttack; 203 | int effects; // MUZZLE FLASH, e.g. 204 | int flags; // FL_ONGROUND, FL_DUCKING, etc. 205 | int usehull; // 0 = regular player hull, 1 = ducked player hull, 2 = point hull 206 | float gravity; // Our current gravity and friction. 207 | float friction; 208 | int oldbuttons; // Buttons last usercmd 209 | float waterjumptime; // Amount of time left in jumping out of water cycle. 210 | int dead; // Are we a dead player? 211 | int deadflag; 212 | int spectator; // Should we use spectator physics model? 213 | int movetype; // Our movement type, NOCLIP, WALK, FLY 214 | int onground; // -1 = in air, else pmove entity number 215 | int waterlevel; 216 | int watertype; 217 | int oldwaterlevel; 218 | char sztexturename[256]; 219 | char chtexturetype; 220 | float maxspeed; 221 | float clientmaxspeed; 222 | int iuser1; 223 | int iuser2; 224 | int iuser3; 225 | int iuser4; 226 | float fuser1; 227 | float fuser2; 228 | float fuser3; 229 | float fuser4; 230 | s_vec3 vuser1; 231 | s_vec3 vuser2; 232 | s_vec3 vuser3; 233 | s_vec3 vuser4; 234 | int numphysent; // world state 235 | // Number of entities to clip against. 236 | physent_t physents[MAX_PHYSENTS]; 237 | int nummoveent; // Number of momvement entities (ladders) 238 | physent_t moveents[MAX_MOVEENTS]; // just a list of ladders 239 | int numvisent; // All things being rendered, for tracing against things you don't actually collide with 240 | physent_t visents[MAX_PHYSENTS]; 241 | usercmd_t cmd; // input to run through physics. 242 | int numtouch; // Trace results for objects we collided with. 243 | pmtrace_t touchindex[MAX_PHYSENTS]; 244 | char physinfo[MAX_PHYSINFO_STRING]; // Physics info string 245 | struct movevars_s* movevars; 246 | float player_mins[4][3]; 247 | float player_maxs[4][3]; 248 | 249 | const char* (*PM_Info_ValueForKey)(const char* s, const char* key); 250 | void (*PM_Particle)(float* origin, int color, float life, int zpos, int zvel); 251 | int (*PM_TestPlayerPosition)(float* pos, pmtrace_t* ptrace); 252 | void (*Con_NPrintf)(int idx, char* fmt, ...); 253 | void (*Con_DPrintf)(char* fmt, ...); 254 | void (*Con_Printf)(char* fmt, ...); 255 | double (*Sys_FloatTime)(); 256 | void (*PM_StuckTouch)(int hitent, pmtrace_t* ptraceresult); 257 | int (*PM_PointContents)(float* p, int* truecontents); 258 | int (*PM_TruePointContents)(float* p); 259 | int (*PM_HullPointContents)(struct hull_s* hull, int num, float* p); 260 | pmtrace_t(*PM_PlayerTrace)(float* start, float* end, int traceFlags, int ignore_pe); 261 | struct pmtrace_s* (*PM_TraceLine)(float* start, float* end, int flags, int usehulll, int ignore_pe); 262 | int(*RandomLong)(int lLow, int lHigh); 263 | float (*RandomFloat)(float flLow, float flHigh); 264 | int (*PM_GetModelType)(struct model_s* mod); 265 | void (*PM_GetModelBounds)(struct model_s* mod, float* mins, float* maxs); 266 | void* (*PM_HullForBsp)(physent_t* pe, float* offset); 267 | float (*PM_TraceModel)(physent_t* pEnt, float* start, float* end, trace_t* trace); 268 | int (*COM_FileSize)(char* filename); 269 | byte* (*COM_LoadFile)(char* path, int usehunk, int* pLength); 270 | void (*COM_FreeFile)(void* buffer); 271 | char* (*memfgets)(byte* pMemFile, int fileSize, int* pFilePos, char* pBuffer, int bufferSize); 272 | int runfuncs; 273 | void (*PM_PlaySound)(int channel, const char* sample, float volume, float attenuation, int fFlags, int pitch); 274 | const char* (*PM_TraceTexture)(int ground, float* vstart, float* vend); 275 | void (*PM_PlaybackEventFull)(int flags, int clientindex, unsigned short eventindex, float delay, float* origin, float* angles, float fparam1, float fparam2, int iparam1, int iparam2, int bparam1, int bparam2); 276 | 277 | pmtrace_t(*PM_PlayerTraceEx)(float* start, float* end, int traceFlags, int (*pfnIgnore)(physent_t* pe)); 278 | int (*PM_TestPlayerPositionEx)(float* pos, pmtrace_t* ptrace, int (*pfnIgnore)(physent_t* pe)); 279 | struct pmtrace_s* (*PM_TraceLineEx)(float* start, float* end, int flags, int usehulll, int (*pfnIgnore)(physent_t* pe)); 280 | 281 | } playermove_t; -------------------------------------------------------------------------------- /patoke-sdk-cs16/other/position/g_pos.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // g_pos stands for global position, this is the global position header 3 | 4 | // imgui declarations 5 | #define IM_VEC2_CLASS_EXTRA \ 6 | constexpr ImVec2(const s_vec2 &f) : x(f.x), y(f.y) {} \ 7 | constexpr ImVec2(const s_position &f) : x(f.x), y(f.y) {} \ 8 | operator s_vec2() const { return s_vec2(x, y); } \ 9 | operator s_position() const { return s_position(x, y); } 10 | 11 | #define IM_VEC4_CLASS_EXTRA \ 12 | constexpr ImVec4(const s_rect &f) : x(f.x), y(f.y), z(f.width), w(f.height) {} \ 13 | operator s_rect() const { return s_rect(x, y, w, z); } 14 | 15 | // raw defines for position and size, these don't have any usage more than define the variables they contain and operators 16 | struct s_position { 17 | float x, y; 18 | 19 | s_position(float x, float y) : x(x), y(y) {} 20 | 21 | float& operator[](int i) { 22 | return ((float*)this)[i]; 23 | } 24 | 25 | float operator[](int i) const { 26 | return ((float*)this)[i]; 27 | } 28 | 29 | inline s_position operator+(const s_position& other) const { 30 | return s_position(this->x + other.x, this->y + other.y); 31 | } 32 | 33 | inline s_position operator-(const s_position& other) const { 34 | return s_position(this->x - other.x, this->y - other.y); 35 | } 36 | 37 | inline s_position operator/(const float& val) const { 38 | return s_position(this->x / val, this->y / val); 39 | } 40 | 41 | inline s_position operator-=(const s_position& other) { 42 | this->x -= other.x; 43 | this->y -= other.y; 44 | return *this; 45 | } 46 | }; 47 | 48 | struct s_position3d : public s_position { 49 | float z; 50 | 51 | s_position3d(float x, float y, float z) : s_position(x, y), z(z) {} 52 | 53 | inline s_position3d operator+(const s_position3d& other) const { 54 | return s_position3d(this->x + other.x, this->y + other.y, this->z + other.z); 55 | } 56 | 57 | inline s_position3d operator-(const s_position3d& other) const { 58 | return s_position3d(this->x - other.x, this->y - other.y, this->z - other.z); 59 | } 60 | 61 | inline s_position3d operator-=(const s_position3d& other) { 62 | this->x -= other.x; 63 | this->y -= other.y; 64 | this->z -= other.z; 65 | return *this; 66 | } 67 | 68 | inline s_position3d operator*=(const s_position3d& other) { 69 | this->x *= other.x; 70 | this->y *= other.y; 71 | this->z *= other.z; 72 | return *this; 73 | } 74 | 75 | inline s_position3d operator/(const float& val) const { 76 | return s_position3d(this->x / val, this->y / val, this->z / val); 77 | } 78 | 79 | inline s_position3d operator*=(const float& val) { 80 | this->x *= val; 81 | this->y *= val; 82 | this->z *= val; 83 | return *this; 84 | } 85 | 86 | inline float length() const { 87 | return sqrt((x * x) + (y * y) + (z * z)); 88 | } 89 | 90 | inline float length_sqr() const { 91 | return ((x * x) + (y * y) + (z * z)); 92 | } 93 | 94 | inline float length_2d() const { 95 | return sqrt((x * x) + (y * y)); 96 | } 97 | 98 | inline bool is_zero(float tolerance) const { 99 | return (x > -tolerance && x < tolerance&& y > -tolerance && y < tolerance&& z > -tolerance && z < tolerance); 100 | } 101 | 102 | inline bool is_valid() const { 103 | return (std::isfinite(x) && std::isfinite(y) && std::isfinite(z)); 104 | } 105 | }; 106 | 107 | struct s_size { 108 | float width, height; 109 | 110 | s_size(float width, float height) : width(width), height(height) {} 111 | 112 | inline s_size operator+(const s_size& other) const { 113 | return s_size(this->width + other.width, this->height + other.height); 114 | } 115 | 116 | inline s_size operator-(const s_size& other) const { 117 | return s_size(this->width - other.width, this->height - other.height); 118 | } 119 | 120 | inline s_size operator/(const float& val) const { 121 | return s_size(this->width / val, this->height / val); 122 | } 123 | 124 | inline s_size operator-=(const s_size& other) { 125 | this->width -= other.width; 126 | this->height -= other.height; 127 | return *this; 128 | } 129 | }; 130 | 131 | // usage defines, these contain all the helpers for these specific types unlike raw defines 132 | struct s_rect : public s_position, s_size { 133 | s_rect() : s_position(0, 0), s_size(0, 0) {} 134 | s_rect(float x, float y, float width, float height) : s_position(x, y), s_size(width, height) {} 135 | s_rect(const s_position& other_pos, const s_size& other_size) 136 | : s_position(other_pos.x, other_pos.y), s_size(other_size.width, other_size.height) {} 137 | }; 138 | 139 | struct s_vec2 : public s_position { 140 | s_vec2() : s_position(0, 0) {} 141 | s_vec2(float x, float y) : s_position(x, y) {} 142 | s_vec2(int x, int y) : s_position(float(x), float(y)) {} 143 | s_vec2(const s_position& other) : s_vec2(other.x, other.y) {} 144 | }; 145 | 146 | struct s_angle : public s_position3d { 147 | s_angle() : s_position3d(0, 0, 0) {} 148 | s_angle(float x, float y, float z) : s_position3d(x, y, z) {} 149 | s_angle(const s_position3d& other) : s_angle(other.x, other.y, other.z) {} 150 | 151 | inline s_angle normalize(); 152 | }; 153 | 154 | struct s_vec3 : public s_position3d { 155 | s_vec3() : s_position3d(0, 0, 0) {} 156 | s_vec3(float x, float y, float z) : s_position3d(x, y, z) {} 157 | s_vec3(const s_position3d& other) : s_vec3(other.x, other.y, other.z) {} 158 | s_vec3(const float* other) : s_vec3(other[0], other[1], other[2]) {} 159 | 160 | inline float dot(const s_vec3& other) const { 161 | const s_vec3& a = *this; 162 | 163 | return (a.x * other.x + a.y * other.y + a.z * other.z); 164 | } 165 | 166 | inline s_vec3 normalize(); 167 | inline float normalize_in_place(); 168 | }; 169 | 170 | // source engine specific 171 | class __declspec(align(16)) s_vec_aligned : public s_vec3 { 172 | public: 173 | inline s_vec_aligned(void) : s_vec3(0, 0, 0) {} 174 | inline s_vec_aligned(float _x, float _y, float _z) : s_vec3(_x, _y, _z) {} 175 | explicit s_vec_aligned(const s_vec3& other) : s_vec3(other.x, other.y, other.z) {} 176 | 177 | s_vec_aligned& operator=(const s_vec3& other) { 178 | this->x = other.x; 179 | this->y = other.y; 180 | this->z = other.z; 181 | return *this; 182 | } 183 | 184 | float w; 185 | }; 186 | 187 | // matrix defines, these are separated from everything else due to their nature 188 | // used for bone matrices and stuff 189 | class s_matrix3x4 { 190 | public: 191 | s_matrix3x4() { 192 | mat_val[0][0] = 0; 193 | mat_val[0][1] = 0; 194 | mat_val[0][2] = 0; 195 | mat_val[0][3] = 0; 196 | mat_val[1][0] = 0; 197 | mat_val[1][1] = 0; 198 | mat_val[1][2] = 0; 199 | mat_val[1][3] = 0; 200 | mat_val[2][0] = 0; 201 | mat_val[2][1] = 0; 202 | mat_val[2][2] = 0; 203 | mat_val[2][3] = 0; 204 | } 205 | 206 | s_matrix3x4(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23) { 207 | mat_val[0][0] = m00; 208 | mat_val[0][1] = m01; 209 | mat_val[0][2] = m02; 210 | mat_val[0][3] = m03; 211 | mat_val[1][0] = m10; 212 | mat_val[1][1] = m11; 213 | mat_val[1][2] = m12; 214 | mat_val[1][3] = m13; 215 | mat_val[2][0] = m20; 216 | mat_val[2][1] = m21; 217 | mat_val[2][2] = m22; 218 | mat_val[2][3] = m23; 219 | } 220 | 221 | inline s_matrix3x4 operator=(float** other) { 222 | mat_val[0][0] = other[0][0]; 223 | mat_val[0][1] = other[0][1]; 224 | mat_val[0][2] = other[0][2]; 225 | mat_val[0][3] = other[0][3]; 226 | mat_val[1][0] = other[1][0]; 227 | mat_val[1][1] = other[1][1]; 228 | mat_val[1][2] = other[1][2]; 229 | mat_val[1][3] = other[1][3]; 230 | mat_val[2][0] = other[2][0]; 231 | mat_val[2][1] = other[2][1]; 232 | mat_val[2][2] = other[2][2]; 233 | mat_val[2][3] = other[2][3]; 234 | 235 | return *this; 236 | } 237 | 238 | void init(const s_vec3& x_axis, const s_vec3& y_axis, const s_vec3& z_axis, const s_vec3& vec_origin) { 239 | mat_val[0][0] = x_axis.x; 240 | mat_val[0][1] = y_axis.x; 241 | mat_val[0][2] = z_axis.x; 242 | mat_val[0][3] = vec_origin.x; 243 | mat_val[1][0] = x_axis.y; 244 | mat_val[1][1] = y_axis.y; 245 | mat_val[1][2] = z_axis.y; 246 | mat_val[1][3] = vec_origin.y; 247 | mat_val[2][0] = x_axis.z; 248 | mat_val[2][1] = y_axis.z; 249 | mat_val[2][2] = z_axis.z; 250 | mat_val[2][3] = vec_origin.z; 251 | } 252 | 253 | s_matrix3x4(const s_vec3& x_axis, const s_vec3& y_axis, const s_vec3& z_axis, const s_vec3& vec_origin) { 254 | init(x_axis, y_axis, z_axis, vec_origin); 255 | } 256 | 257 | inline void set_origin(s_vec3 const& p) { 258 | mat_val[0][3] = p.x; 259 | mat_val[1][3] = p.y; 260 | mat_val[2][3] = p.z; 261 | } 262 | 263 | inline void invalidate(void) { 264 | for (int i = 0; i < 3; i++) 265 | for (int j = 0; j < 4; j++) 266 | mat_val[i][j] = std::numeric_limits::infinity(); 267 | ; 268 | } 269 | 270 | float* operator[](int i) { 271 | return mat_val[i]; 272 | } 273 | const float* operator[](int i) const { 274 | return mat_val[i]; 275 | } 276 | float* base() { 277 | return &mat_val[0][0]; 278 | } 279 | const float* base() const { 280 | return &mat_val[0][0]; 281 | } 282 | 283 | float mat_val[3][4]; 284 | }; 285 | 286 | // used for stuff like the viewmatrix and stuff (this is also known in the source engine as vmatrix) 287 | class s_matrix4x4 { 288 | public: 289 | s_matrix4x4(); 290 | s_matrix4x4(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, 291 | float m30, float m31, float m32, float m33); 292 | 293 | s_matrix4x4(const s_vec3& forward, const s_vec3& left, const s_vec3& up); 294 | 295 | s_matrix4x4(const s_matrix3x4& matrix); 296 | 297 | void init(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, float m20, float m21, float m22, float m23, 298 | float m30, float m31, float m32, float m33); 299 | 300 | void init(const s_matrix3x4& matrix); 301 | 302 | inline float* operator[](int i) { 303 | return m[i]; 304 | } 305 | 306 | inline const float* operator[](int i) const { 307 | return m[i]; 308 | } 309 | 310 | inline float* base() { 311 | return &m[0][0]; 312 | } 313 | 314 | inline const float* base() const { 315 | return &m[0][0]; 316 | } 317 | public: 318 | float m[4][4]; 319 | }; -------------------------------------------------------------------------------- /patoke-sdk-cs16/dependencies/utilities/pattern/pattern.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "char_queue.hpp" 3 | #include "mem.hpp" 4 | 5 | #include 6 | #include 7 | 8 | namespace mem { 9 | class region; 10 | 11 | class pattern { 12 | private: 13 | std::vector bytes_{}; 14 | std::vector masks_{}; 15 | std::size_t trimmed_size_{ 0 }; 16 | bool needs_masks_{ true }; 17 | 18 | void finalize(); 19 | 20 | bool parse_chunk(char_queue& input, char wildcard); 21 | 22 | public: 23 | explicit pattern() = default; 24 | 25 | enum class wildcard_t : char 26 | { 27 | }; 28 | 29 | explicit pattern(const char* string, wildcard_t wildcard = static_cast('?')); 30 | explicit pattern(const void* bytes, const char* masks, wildcard_t wildcard = static_cast('?')); 31 | 32 | explicit pattern(const void* bytes, const void* masks, std::size_t length); 33 | 34 | bool match(pointer address) const noexcept; 35 | 36 | const byte* bytes() const noexcept; 37 | const byte* masks() const noexcept; 38 | 39 | std::size_t size() const noexcept; 40 | std::size_t trimmed_size() const noexcept; 41 | 42 | bool needs_masks() const noexcept; 43 | 44 | std::size_t get_skip_pos(const byte* frequencies) const noexcept; 45 | 46 | explicit operator bool() const noexcept; 47 | 48 | std::string to_string() const; 49 | }; 50 | 51 | mem::pointer scan(const mem::pattern& pattern, mem::region range); 52 | std::vector scan_all(const mem::pattern& pattern, mem::region range); 53 | 54 | inline bool pattern::parse_chunk(char_queue& input, char wildcard) { 55 | byte value = 0x00; 56 | byte mask = 0x00; 57 | 58 | std::size_t count = 1; 59 | 60 | int current = -1; 61 | int temp = -1; 62 | 63 | // clang-format off 64 | current = input.peek(); 65 | if ((temp = xctoi(current)) != -1) { input.pop(); value = static_cast(temp); mask = 0xFF; } 66 | else if (current == wildcard) { input.pop(); value = 0x00; mask = 0x00; } 67 | else { return false; } 68 | 69 | current = input.peek(); 70 | if ((temp = xctoi(current)) != -1) { input.pop(); value = (value << 4) | static_cast(temp); mask = (mask << 4) | 0x0F; } 71 | else if (current == wildcard) { input.pop(); value = (value << 4); mask = (mask << 4); } 72 | 73 | if (input.peek() == '&') { 74 | input.pop(); 75 | 76 | byte expl_mask = 0xFF; 77 | 78 | if ((temp = xctoi(input.peek())) != -1) { input.pop(); expl_mask = static_cast(temp); } 79 | else { return false; } 80 | 81 | if ((temp = xctoi(input.peek())) != -1) { input.pop(); expl_mask = (expl_mask << 4) | static_cast(temp); } 82 | 83 | mask &= expl_mask; 84 | } 85 | 86 | if (input.peek() == '#') { 87 | input.pop(); 88 | 89 | count = 0; 90 | 91 | while (true) { 92 | if ((temp = dctoi(input.peek())) != -1) { input.pop(); count = (count * 10) + static_cast(temp); } 93 | else if (count > 0) { break; } 94 | else { return false; } 95 | } 96 | } 97 | // clang-format on 98 | 99 | value &= mask; 100 | 101 | for (std::size_t i = 0; i < count; ++i) { 102 | bytes_.push_back(value); 103 | masks_.push_back(mask); 104 | } 105 | 106 | return true; 107 | } 108 | 109 | inline pattern::pattern(const char* string, wildcard_t wildcard) { 110 | char_queue input(string); 111 | 112 | while (input) { 113 | if (input.peek() == ' ') { 114 | input.pop(); 115 | 116 | continue; 117 | } 118 | 119 | if (!parse_chunk(input, static_cast(wildcard))) { 120 | masks_.clear(); 121 | bytes_.clear(); 122 | 123 | break; 124 | } 125 | } 126 | 127 | finalize(); 128 | } 129 | 130 | inline pattern::pattern(const void* bytes, const char* mask, wildcard_t wildcard) { 131 | if (mask) { 132 | const std::size_t size = std::strlen(mask); 133 | 134 | bytes_.resize(size); 135 | masks_.resize(size); 136 | 137 | for (std::size_t i = 0; i < size; ++i) { 138 | if (mask[i] == static_cast(wildcard)) { 139 | bytes_[i] = 0x00; 140 | masks_[i] = 0x00; 141 | } 142 | else { 143 | bytes_[i] = static_cast(bytes)[i]; 144 | masks_[i] = 0xFF; 145 | } 146 | } 147 | } 148 | else { 149 | const std::size_t size = std::strlen(static_cast(bytes)); 150 | 151 | bytes_.resize(size); 152 | masks_.resize(size); 153 | 154 | for (std::size_t i = 0; i < size; ++i) { 155 | bytes_[i] = static_cast(bytes)[i]; 156 | masks_[i] = 0xFF; 157 | } 158 | } 159 | 160 | finalize(); 161 | } 162 | 163 | inline pattern::pattern(const void* bytes, const void* mask, std::size_t length) { 164 | if (mask) { 165 | bytes_.resize(length); 166 | masks_.resize(length); 167 | 168 | for (std::size_t i = 0; i < length; ++i) { 169 | const byte v = static_cast(bytes)[i]; 170 | const byte m = static_cast(mask)[i]; 171 | 172 | bytes_[i] = v & m; 173 | masks_[i] = m; 174 | } 175 | } 176 | else { 177 | bytes_.resize(length); 178 | masks_.resize(length); 179 | 180 | for (std::size_t i = 0; i < length; ++i) { 181 | bytes_[i] = static_cast(bytes)[i]; 182 | masks_[i] = 0xFF; 183 | } 184 | } 185 | 186 | finalize(); 187 | } 188 | 189 | inline void pattern::finalize() { 190 | if (bytes_.size() != masks_.size()) { 191 | bytes_.clear(); 192 | masks_.clear(); 193 | trimmed_size_ = 0; 194 | needs_masks_ = false; 195 | 196 | return; 197 | } 198 | 199 | for (std::size_t i = 0; i < bytes_.size(); ++i) 200 | bytes_[i] &= masks_[i]; 201 | 202 | std::size_t trimmed_size = bytes_.size(); 203 | 204 | while (trimmed_size && (masks_[trimmed_size - 1] == 0x00)) 205 | --trimmed_size; 206 | 207 | trimmed_size_ = trimmed_size; 208 | 209 | needs_masks_ = false; 210 | 211 | for (std::size_t i = trimmed_size_; i--;) { 212 | if (masks_[i] != 0xFF) { 213 | needs_masks_ = true; 214 | 215 | break; 216 | } 217 | } 218 | } 219 | 220 | inline bool pattern::match(pointer address) const noexcept { 221 | const byte* const pat_bytes = bytes(); 222 | 223 | if (!pat_bytes) 224 | return false; 225 | 226 | const byte* current = address.as(); 227 | 228 | const std::size_t last = trimmed_size() - 1; 229 | 230 | if (needs_masks()) { 231 | const byte* const pat_masks = masks(); 232 | 233 | for (std::size_t i = last; mem_likely((current[i] & pat_masks[i]) != pat_bytes[i]); --i) { 234 | if (mem_unlikely(i == 0)) 235 | return true; 236 | } 237 | 238 | return false; 239 | } 240 | else { 241 | for (std::size_t i = last; mem_likely(current[i] != pat_bytes[i]); --i) { 242 | if (mem_unlikely(i == 0)) 243 | return true; 244 | } 245 | 246 | return false; 247 | } 248 | } 249 | 250 | strong_inline const byte* pattern::bytes() const noexcept { 251 | return !bytes_.empty() ? bytes_.data() : nullptr; 252 | } 253 | 254 | strong_inline const byte* pattern::masks() const noexcept { 255 | return !masks_.empty() ? masks_.data() : nullptr; 256 | } 257 | 258 | strong_inline std::size_t pattern::size() const noexcept { 259 | return bytes_.size(); 260 | } 261 | 262 | strong_inline std::size_t pattern::trimmed_size() const noexcept { 263 | return trimmed_size_; 264 | } 265 | 266 | strong_inline bool pattern::needs_masks() const noexcept { 267 | return needs_masks_; 268 | } 269 | 270 | strong_inline std::size_t pattern::get_skip_pos(const byte* frequencies) const noexcept { 271 | std::size_t min = SIZE_MAX; 272 | std::size_t result = SIZE_MAX; 273 | 274 | for (std::size_t i = 0; i < size(); ++i) { 275 | if (masks_[i] == 0xFF) { 276 | std::size_t f = frequencies[bytes_[i]]; 277 | 278 | if (f <= min) { 279 | result = i; 280 | min = f; 281 | } 282 | } 283 | } 284 | 285 | return result; 286 | } 287 | 288 | strong_inline pattern::operator bool() const noexcept { 289 | return !bytes_.empty() && !masks_.empty(); 290 | } 291 | 292 | inline std::string pattern::to_string() const { 293 | const char* const hex_chars = "0123456789ABCDEF"; 294 | 295 | std::string result; 296 | 297 | for (std::size_t i = 0; i < size(); ++i) { 298 | if (i) 299 | result += ' '; 300 | 301 | const byte mask = masks_[i]; 302 | const byte value = bytes_[i]; 303 | 304 | if (mask != 0x00) { 305 | result += hex_chars[static_cast(value >> 4)]; 306 | result += hex_chars[static_cast(value & 0xF)]; 307 | 308 | if (mask != 0xFF) { 309 | result += '&'; 310 | result += hex_chars[static_cast(mask >> 4)]; 311 | result += hex_chars[static_cast(mask & 0xF)]; 312 | } 313 | } 314 | else 315 | result += '?'; 316 | } 317 | 318 | return result; 319 | } 320 | 321 | template 322 | class scanner_base { 323 | public: 324 | pointer operator()(region range) const; 325 | 326 | template 327 | pointer operator()(region range, Func func) const; 328 | 329 | std::vector scan_all(region range) const; 330 | }; 331 | 332 | template 333 | strong_inline pointer scanner_base::operator()(region range) const { 334 | return static_cast(this)->scan(range); 335 | } 336 | 337 | template 338 | template 339 | inline pointer scanner_base::operator()(region range, Func func) const { 340 | while (true) { 341 | const pointer result = static_cast(this)->scan(range); 342 | 343 | if (result) { 344 | if (func(result)) 345 | return result; 346 | 347 | range = range.sub_region(result + 1); 348 | } 349 | else 350 | break; 351 | } 352 | 353 | return nullptr; 354 | } 355 | 356 | template 357 | inline std::vector scanner_base::scan_all(region range) const { 358 | std::vector results; 359 | 360 | (*this)(range, [&results](pointer result) { 361 | results.emplace_back(result); 362 | 363 | return false; 364 | }); 365 | 366 | return results; 367 | } 368 | } 369 | 370 | #include "simd_scanner.hpp" 371 | 372 | namespace mem { 373 | using default_scanner = class simd_scanner; 374 | 375 | inline mem::pointer scan(const mem::pattern& pattern, mem::region range) { 376 | return mem::default_scanner(pattern).scan(range); 377 | } 378 | 379 | inline std::vector scan_all(const mem::pattern& pattern, mem::region range) { 380 | return mem::default_scanner(pattern).scan_all(range); 381 | } 382 | } -------------------------------------------------------------------------------- /patoke-sdk-cs16/main/game/sdk/classes/studio.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define MAXSTUDIOTRIANGLES 20000 // TODO: tune this 4 | #define MAXSTUDIOVERTS 2048 // TODO: tune this 5 | #define MAXSTUDIOSEQUENCES 2048 // total animation sequences 6 | #define MAXSTUDIOSKINS 100 // total textures 7 | #define MAXSTUDIOSRCBONES 512 // bones allowed at source movement 8 | #define MAXSTUDIOBONES 128 // total bones actually used 9 | #define MAXSTUDIOMODELS 32 // sub-models per model 10 | #define MAXSTUDIOBODYPARTS 32 11 | #define MAXSTUDIOGROUPS 16 12 | #define MAXSTUDIOANIMATIONS 2048 // per sequence 13 | #define MAXSTUDIOMESHES 256 14 | #define MAXSTUDIOEVENTS 1024 15 | #define MAXSTUDIOPIVOTS 256 16 | #define MAXSTUDIOCONTROLLERS 8 17 | 18 | #define STUDIO_DYNAMIC_LIGHT 0x0100 // dynamically get lighting from floor or ceil (flying monsters) 19 | #define STUDIO_TRACE_HITBOX 0x0200 // always use hitbox trace instead of bbox 20 | 21 | // lighting options 22 | #define STUDIO_NF_FLATSHADE 0x0001 23 | #define STUDIO_NF_CHROME 0x0002 24 | #define STUDIO_NF_FULLBRIGHT 0x0004 25 | #define STUDIO_NF_NOMIPS 0x0008 26 | #define STUDIO_NF_ALPHA 0x0010 27 | #define STUDIO_NF_ADDITIVE 0x0020 28 | #define STUDIO_NF_MASKED 0x0040 29 | 30 | // motion flags 31 | #define STUDIO_X 0x0001 32 | #define STUDIO_Y 0x0002 33 | #define STUDIO_Z 0x0004 34 | #define STUDIO_XR 0x0008 35 | #define STUDIO_YR 0x0010 36 | #define STUDIO_ZR 0x0020 37 | #define STUDIO_LX 0x0040 38 | #define STUDIO_LY 0x0080 39 | #define STUDIO_LZ 0x0100 40 | #define STUDIO_AX 0x0200 41 | #define STUDIO_AY 0x0400 42 | #define STUDIO_AZ 0x0800 43 | #define STUDIO_AXR 0x1000 44 | #define STUDIO_AYR 0x2000 45 | #define STUDIO_AZR 0x4000 46 | #define STUDIO_TYPES 0x7FFF 47 | #define STUDIO_RLOOP 0x8000 // controller that wraps shortest distance 48 | 49 | // sequence flags 50 | #define STUDIO_LOOPING 0x0001 51 | 52 | // bone flags 53 | #define STUDIO_HAS_NORMALS 0x0001 54 | #define STUDIO_HAS_VERTICES 0x0002 55 | #define STUDIO_HAS_BBOX 0x0004 56 | #define STUDIO_HAS_CHROME 0x0008 // if any of the textures have chrome on them 57 | 58 | #define RAD_TO_STUDIO (32768.0/M_PI) 59 | #define STUDIO_TO_RAD (M_PI/32768.0) 60 | 61 | 62 | #define STUDIO_NUM_HULLS 128 63 | #define STUDIO_NUM_PLANES (STUDIO_NUM_HULLS * 6) 64 | #define STUDIO_CACHE_SIZE 16 65 | 66 | typedef struct 67 | { 68 | int id; 69 | int version; 70 | 71 | char name[64]; 72 | int length; 73 | 74 | s_vec3 eyeposition; // ideal eye position 75 | s_vec3 min; // ideal movement hull size 76 | s_vec3 max; 77 | 78 | s_vec3 bbmin; // clipping bounding box 79 | s_vec3 bbmax; 80 | 81 | int flags; 82 | 83 | int numbones; // bones 84 | int boneindex; 85 | 86 | int numbonecontrollers; // bone controllers 87 | int bonecontrollerindex; 88 | 89 | int numhitboxes; // complex bounding boxes 90 | int hitboxindex; 91 | 92 | int numseq; // animation sequences 93 | int seqindex; 94 | 95 | int numseqgroups; // demand loaded sequences 96 | int seqgroupindex; 97 | 98 | int numtextures; // raw textures 99 | int textureindex; 100 | int texturedataindex; 101 | 102 | int numskinref; // replaceable textures 103 | int numskinfamilies; 104 | int skinindex; 105 | 106 | int numbodyparts; 107 | int bodypartindex; 108 | 109 | int numattachments; // queryable attachable points 110 | int attachmentindex; 111 | 112 | int soundtable; 113 | int soundindex; 114 | int soundgroups; 115 | int soundgroupindex; 116 | 117 | int numtransitions; // animation node to animation node transition graph 118 | int transitionindex; 119 | } studiohdr_t; 120 | 121 | // header for demand loaded sequence group data 122 | typedef struct 123 | { 124 | int id; 125 | int version; 126 | 127 | char name[64]; 128 | int length; 129 | } studioseqhdr_t; 130 | 131 | // bones 132 | typedef struct 133 | { 134 | char name[32]; // bone name for symbolic links 135 | int parent; // parent bone 136 | int flags; // ?? 137 | int bonecontroller[6]; // bone controller index, -1 == none 138 | float value[6]; // default DoF values 139 | float scale[6]; // scale for delta DoF values 140 | } mstudiobone_t; 141 | 142 | 143 | // bone controllers 144 | typedef struct 145 | { 146 | int bone; // -1 == 0 147 | int type; // X, Y, Z, XR, YR, ZR, M 148 | float start; 149 | float end; 150 | int rest; // byte index value at rest 151 | int index; // 0-3 user set controller, 4 mouth 152 | } mstudiobonecontroller_t; 153 | 154 | // intersection boxes 155 | typedef struct 156 | { 157 | int bone; 158 | int group; // intersection group 159 | s_vec3 bbmin; // bounding box 160 | s_vec3 bbmax; 161 | } mstudiobbox_t; 162 | 163 | // demand loaded sequence groups 164 | typedef struct 165 | { 166 | char label[32]; // textual name 167 | char name[64]; // file name 168 | int32_t unused1; // was "cache" - index pointer 169 | int unused2; // was "data" - hack for group 0 170 | } mstudioseqgroup_t; 171 | 172 | // sequence descriptions 173 | typedef struct 174 | { 175 | char label[32]; // sequence label 176 | 177 | float fps; // frames per second 178 | int flags; // looping/non-looping flags 179 | 180 | int activity; 181 | int actweight; 182 | 183 | int numevents; 184 | int eventindex; 185 | 186 | int numframes; // number of frames per sequence 187 | 188 | int numpivots; // number of foot pivots 189 | int pivotindex; 190 | 191 | int motiontype; 192 | int motionbone; 193 | s_vec3 linearmovement; 194 | int automoveposindex; 195 | int automoveangleindex; 196 | 197 | s_vec3 bbmin; // per sequence bounding box 198 | s_vec3 bbmax; 199 | 200 | int numblends; 201 | int animindex; // mstudioanim_t pointer relative to start of sequence group data 202 | // [blend][bone][X, Y, Z, XR, YR, ZR] 203 | 204 | int blendtype[2]; // X, Y, Z, XR, YR, ZR 205 | float blendstart[2]; // starting value 206 | float blendend[2]; // ending value 207 | int blendparent; 208 | 209 | int seqgroup; // sequence group for demand loading 210 | 211 | int entrynode; // transition node at entry 212 | int exitnode; // transition node at exit 213 | int nodeflags; // transition rules 214 | 215 | int nextseq; // auto advancing sequences 216 | } mstudioseqdesc_t; 217 | 218 | // events 219 | //#include "studio_event.h" 220 | /* 221 | typedef struct 222 | { 223 | int frame; 224 | int event; 225 | int type; 226 | char options[64]; 227 | } mstudioevent_t; 228 | */ 229 | 230 | // pivots 231 | typedef struct 232 | { 233 | s_vec3 org; // pivot point 234 | int start; 235 | int end; 236 | } mstudiopivot_t; 237 | 238 | // attachment 239 | typedef struct 240 | { 241 | char name[32]; 242 | int type; 243 | int bone; 244 | s_vec3 org; // attachment point 245 | s_vec3 s_vec3s[3]; 246 | } mstudioattachment_t; 247 | 248 | typedef struct 249 | { 250 | unsigned short offset[6]; 251 | } mstudioanim_t; 252 | 253 | // animation frames 254 | typedef union 255 | { 256 | struct { 257 | byte valid; 258 | byte total; 259 | } num; 260 | short value; 261 | } mstudioanimvalue_t; 262 | 263 | 264 | 265 | // body part index 266 | typedef struct 267 | { 268 | char name[64]; 269 | int nummodels; 270 | int base; 271 | int modelindex; // index into models array 272 | } mstudiobodyparts_t; 273 | 274 | 275 | 276 | // skin info 277 | typedef struct 278 | { 279 | char name[64]; 280 | int flags; 281 | int width; 282 | int height; 283 | int index; 284 | } mstudiotexture_t; 285 | 286 | 287 | // skin families 288 | // short index[skinfamilies][skinref] 289 | 290 | // studio models 291 | typedef struct 292 | { 293 | char name[64]; 294 | 295 | int type; 296 | 297 | float boundingradius; 298 | 299 | int nummesh; 300 | int meshindex; 301 | 302 | int numverts; // number of unique vertices 303 | int vertinfoindex; // vertex bone info 304 | int vertindex; // vertex vec3_t 305 | int numnorms; // number of unique surface normals 306 | int norminfoindex; // normal bone info 307 | int normindex; // normal vec3_t 308 | 309 | int numgroups; // deformation groups 310 | int groupindex; 311 | } mstudiomodel_t; 312 | 313 | 314 | // vec3_t boundingbox[model][bone][2]; // complex intersection info 315 | 316 | 317 | // meshes 318 | typedef struct 319 | { 320 | int numtris; 321 | int triindex; 322 | int skinref; 323 | int numnorms; // per mesh normals 324 | int normindex; // normal vec3_t 325 | } mstudiomesh_t; 326 | 327 | // triangles 328 | #if 0 329 | typedef struct 330 | { 331 | short vertindex; // index into vertex array 332 | short normindex; // index into normal array 333 | short s, t; // s,t position on skin 334 | } mstudiotrivert_t; 335 | #endif 336 | 337 | class c_studiomodelrenderer { 338 | public: 339 | // Construction/Destruction 340 | c_studiomodelrenderer(void); 341 | virtual ~c_studiomodelrenderer(void) = 0; 342 | 343 | // Initialization 344 | virtual void Init(void) = 0; 345 | 346 | public: 347 | // Public Interfaces 348 | virtual int StudioDrawModel(int flags) = 0; 349 | virtual int StudioDrawPlayer(int flags, struct entity_state_s* pplayer) = 0; 350 | 351 | public: 352 | // Local interfaces 353 | // 354 | 355 | // Look up animation data for sequence 356 | virtual mstudioanim_t* StudioGetAnim(model_t* m_pSubModel, mstudioseqdesc_t* pseqdesc) = 0; 357 | 358 | // Interpolate model position and angles and set up matrices 359 | virtual void StudioSetUpTransform(int trivial_accept) = 0; 360 | 361 | // Set up model bone positions 362 | virtual void StudioSetupBones(void) = 0; 363 | 364 | // Find final attachment points 365 | virtual void StudioCalcAttachments(void) = 0; 366 | 367 | // Save bone matrices and names 368 | virtual void StudioSaveBones(void) = 0; 369 | 370 | // Merge cached bones with current bones for model 371 | virtual void StudioMergeBones(model_t* m_pSubModel) = 0; 372 | 373 | // Determine interpolation fraction 374 | virtual float StudioEstimateInterpolant(void) = 0; 375 | 376 | // Determine current frame for rendering 377 | virtual float StudioEstimateFrame(mstudioseqdesc_t* pseqdesc) = 0; 378 | 379 | // Apply special effects to transform matrix 380 | virtual void StudioFxTransform(cl_entity_t* ent, float transform[3][4]) = 0; 381 | 382 | // Spherical interpolation of bones 383 | virtual void StudioSlerpBones(s_rect q1[], float pos1[][3], s_rect q2[], float pos2[][3], float s) = 0; 384 | 385 | // Compute bone adjustments ( bone controllers ) 386 | virtual void StudioCalcBoneAdj(float dadt, float* adj, const byte* pcontroller1, const byte* pcontroller2, byte mouthopen) = 0; 387 | 388 | // Get bone quaternions 389 | virtual void StudioCalcBoneQuaterion(int frame, float s, mstudiobone_t* pbone, mstudioanim_t* panim, float* adj, float* q) = 0; 390 | 391 | // Get bone positions 392 | virtual void StudioCalcBonePosition(int frame, float s, mstudiobone_t* pbone, mstudioanim_t* panim, float* adj, float* pos) = 0; 393 | 394 | // Compute rotations 395 | virtual void StudioCalcRotations(float pos[][3], s_rect* q, mstudioseqdesc_t* pseqdesc, mstudioanim_t* panim, float f) = 0; 396 | 397 | // Send bones and verts to renderer 398 | virtual void StudioRenderModel(void) = 0; 399 | 400 | // Finalize rendering 401 | virtual void StudioRenderFinal(void) = 0; 402 | 403 | // GL&D3D vs. Software renderer finishing functions 404 | virtual void StudioRenderFinal_Software(void) = 0; 405 | virtual void StudioRenderFinal_Hardware(void) = 0; 406 | 407 | // Player specific data 408 | // Determine pitch and blending amounts for players 409 | virtual void StudioPlayerBlend(mstudioseqdesc_t* pseqdesc, int* pBlend, float* pPitch) = 0; 410 | 411 | // Estimate gait frame for player 412 | virtual void StudioEstimateGait(entity_state_t* pplayer) = 0; 413 | 414 | // Process movement of player 415 | virtual void StudioProcessGait(entity_state_t* pplayer) = 0; 416 | 417 | public: 418 | 419 | // Client clock 420 | double m_clTime; 421 | // Old Client clock 422 | double m_clOldTime; 423 | 424 | // Do interpolation? 425 | int m_fDoInterp; 426 | // Do gait estimation? 427 | int m_fGaitEstimation; 428 | 429 | // Current render frame # 430 | int m_nFrameCount; 431 | 432 | // Cvars that studio model code needs to reference 433 | // 434 | // Use high quality models? 435 | cvar_t* m_pCvarHiModels; 436 | // Developer debug output desired? 437 | cvar_t* m_pCvarDeveloper; 438 | // Draw entities bone hit boxes, etc? 439 | cvar_t* m_pCvarDrawEntities; 440 | 441 | // The entity which we are currently rendering. 442 | cl_entity_t* m_pCurrentEntity; 443 | 444 | // The model for the entity being rendered 445 | model_t* m_pRenderModel; 446 | 447 | // Player info for current player, if drawing a player 448 | player_info_t* m_pPlayerInfo; 449 | 450 | // The index of the player being drawn 451 | int m_nPlayerIndex; 452 | 453 | // The player's gait movement 454 | float m_flGaitMovement; 455 | 456 | // Pointer to header block for studio model data 457 | studiohdr_t* m_pStudioHeader; 458 | 459 | // Pointers to current body part and submodel 460 | mstudiobodyparts_t* m_pBodyPart; 461 | mstudiomodel_t* m_pSubModel; 462 | 463 | // Palette substition for top and bottom of model 464 | int m_nTopColor; 465 | int m_nBottomColor; 466 | 467 | // 468 | // Sprite model used for drawing studio model chrome 469 | model_t* m_pChromeSprite; 470 | 471 | // Caching 472 | // Number of bones in bone cache 473 | int m_nCachedBones; 474 | // Names of cached bones 475 | char m_nCachedBoneNames[MAXSTUDIOBONES][32]; 476 | // Cached bone & light transformation matrices 477 | float m_rgCachedBoneTransform[MAXSTUDIOBONES][3][4]; 478 | float m_rgCachedLightTransform[MAXSTUDIOBONES][3][4]; 479 | 480 | // Software renderer scale factors 481 | float m_fSoftwareXScale, m_fSoftwareYScale; 482 | 483 | // Current view vectors and render origin 484 | float m_vUp[3]; 485 | float m_vRight[3]; 486 | float m_vNormal[3]; 487 | 488 | float m_vRenderOrigin[3]; 489 | 490 | // Model render counters ( from engine ) 491 | int* m_pStudioModelCount; 492 | int* m_pModelsDrawn; 493 | 494 | // Matrices 495 | // Model to world transformation 496 | float(*m_protationmatrix)[3][4]; 497 | // Model to view transformation 498 | float(*m_paliastransform)[3][4]; 499 | 500 | // Concatenated bone and light transforms 501 | float(*m_pbonetransform)[MAXSTUDIOBONES][3][4]; 502 | float(*m_plighttransform)[MAXSTUDIOBONES][3][4]; 503 | }; --------------------------------------------------------------------------------