/* cstrike-basehook-linux -- Internal base for Counter-Strike: Source. Copyright (C) 2017, aixxe. (www.aixxe.net) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with cstrike-basehook-linux. If not, see . */ #include "Basehook.h" #include "Hooks/Hooks.h" #include "Events/TestListener.h" ICvar* cvar = nullptr; IPanel* panel = nullptr; ISurface* matsurface = nullptr; IEngineVGui* enginevgui = nullptr; IVModelInfoClient* modelinfo = nullptr; ILauncherMgr* launchermgr = nullptr; IInputSystem* inputsystem = nullptr; IInputInternal* inputinternal = nullptr; IVEngineClient* engine = nullptr; IVModelRender* modelrender = nullptr; IVDebugOverlay* debugoverlay = nullptr; IBaseClientDLL* clientdll = nullptr; IMaterialSystem* matsystem = nullptr; IClientEntityList* entitylist = nullptr; IGameEventManager2* gameevents = nullptr; CInput* input = nullptr; CGlobalVarsBase* globalvars = nullptr; CRC32_ProcessBufferFn CRC32_ProcessBuffer = NULL; StartDrawing_t StartDrawing = NULL; FinishDrawing_t FinishDrawing = NULL; std::unique_ptr sdl_hook; std::unique_ptr clientdll_hook; std::unique_ptr enginevgui_hook; std::unique_ptr modelrender_hook; std::unique_ptr inputinternal_hook; std::unique_ptr testevent; extern "C" void __attribute__((constructor)) css_basehook_open() { // Get class pointers from game libraries using partial interface versions. cvar = GetInterface("bin/libvstdlib.so", "VEngineCvar0"); panel = GetInterface("bin/vgui2.so", "VGUI_Panel0"); matsurface = GetInterface("bin/vguimatsurface.so", "VGUI_Surface0"); enginevgui = GetInterface("bin/engine.so", "VEngineVGui0"); modelinfo = GetInterface("bin/engine.so", "VModelInfoClient0"); inputsystem = GetInterface("bin/inputsystem.so", "InputSystemVersion0"); inputinternal = GetInterface("bin/vgui2.so", "VGUI_InputInternal0"); engine = GetInterface("bin/engine.so", "VEngineClient0"); modelrender = GetInterface("bin/engine.so", "VEngineModel0"); debugoverlay = GetInterface("bin/engine.so", "VDebugOverlay0"); clientdll = GetInterface("bin/client.so", "VClient0"); matsystem = GetInterface("bin/materialsystem.so", "VMaterialSystem0"); entitylist = GetInterface("bin/client.so", "VClientEntityList0"); gameevents = GetInterface("bin/engine.so", "GAMEEVENTSMANAGER002"); // Scan for the 'CRC32_ProcessBuffer' function. (overkill, but why not?) CRC32_ProcessBuffer = reinterpret_cast( FindPattern("bin/client.so", "\x55\x89\xE5\x57\x56\x53\x83\xEC\x08\x8B\x4D\x10", "xxxxxxxxxxxx") ); // Hook 'FrameStageNotify' and 'CreateMove' from IBaseClientDLL. clientdll_hook = std::make_unique(clientdll); clientdll_hook->HookFunction(reinterpret_cast(Hooks::CreateMove), 21); clientdll_hook->HookFunction(reinterpret_cast(Hooks::FrameStageNotify), 35); // Scan for 'StartDrawing' and 'FinishDrawing' from CMatSystemSurface. StartDrawing = reinterpret_cast( FindPattern("bin/vguimatsurface.so", "\x55\x89\xE5\x53\x83\xEC\x74\x80\x3D\x00\x00\x00\x00\x00", "xxxxxxxxx????x") ); FinishDrawing = reinterpret_cast( FindPattern("bin/vguimatsurface.so", "\x55\x89\xE5\x53\x83\xEC\x24\xC7\x04\x00\x00\x00\x00\x00\xE8\x00\x00\x00\x00\xA1", "xxxxxxxxx????xx????x") ); // Hook 'Paint' from IEngineVGui. enginevgui_hook = std::make_unique(enginevgui); enginevgui_hook->HookFunction(reinterpret_cast(Hooks::Paint), 14); // Hook 'DrawModelExecute' from IVModelRender. modelrender_hook = std::make_unique(modelrender); modelrender_hook->HookFunction(reinterpret_cast(Hooks::DrawModelExecute), 19); // Hook 'PumpWindowsMessageLoop' and 'ShowPixels' from ILauncherMgr. launchermgr = **reinterpret_cast( FindPattern("bin/launcher.so", "\x24\x8B\x1D\x00\x00\x00\x00", "xxx????") + 3 ); sdl_hook = std::make_unique(launchermgr); sdl_hook->HookFunction(reinterpret_cast(Hooks::PumpWindowsMessageLoop), 15); sdl_hook->HookFunction(reinterpret_cast(Hooks::ShowPixels), 29); // Hook 'SetKeyCodeState' and 'SetMouseCodeState' from IInputInternal. inputinternal_hook = std::make_unique(inputinternal); inputinternal_hook->HookFunction(reinterpret_cast(Hooks::SetKeyCodeState), 83); inputinternal_hook->HookFunction(reinterpret_cast(Hooks::SetMouseCodeState), 84); // Get a pointer to CInput from 'IN_ActivateMouse' in IBaseClientDLL. input = **reinterpret_cast( clientdll_hook->GetOriginalFunction(14) + 1 ); // Get a pointer to CGlobalVarsBase from 'HUDUpdate' in IBaseClientDLL. globalvars = **reinterpret_cast( clientdll_hook->GetOriginalFunction(11) + 8 ); // Register an event listener. testevent = std::make_unique("player_footstep"); } extern "C" void __attribute__((destructor)) css_basehook_close() { cvar->ConsoleColorPrintf(Color(255, 150, 150), "Unloaded from game successfully.\n"); }