From afc72efcd81fb7742a74edcb5938847ac748ccdf Mon Sep 17 00:00:00 2001 From: aixxe Date: Fri, 23 Dec 2016 12:19:12 +0000 Subject: [PATCH] Add example event listener on player_footstep. Signed-off-by: aixxe --- README.md | 2 ++ src/Basehook.cpp | 6 ++++++ src/Events/TestListener.h | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 src/Events/TestListener.h diff --git a/README.md b/README.md index 8cc9b4e..b309f01 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,11 @@ Internal project base for Counter-Strike: Source on Linux. Includes full OpenGL ### Features * Retrieves interfaces directly from the *s_pInterfaceRegs* linked list. * ImGui drawing and input handling via *ILauncherMgr* virtual hooks. +* Engine drawing with *ISurface* functions via *IEngineVGui::Paint* hook. * *IBaseClientDLL::CreateMove* hook with *CUserCmd* checksum validation. * *CInput* and *CGlobalVars* pointers retrieved from IBaseClientDLL virtuals. * Can easily be unloaded, modified and reloaded without restarting the game. +* Includes an example game event listener in a self-contained class. ### Requirements diff --git a/src/Basehook.cpp b/src/Basehook.cpp index dd60df8..e3e516d 100644 --- a/src/Basehook.cpp +++ b/src/Basehook.cpp @@ -20,6 +20,7 @@ #include "Basehook.h" #include "Hooks/Hooks.h" +#include "Events/TestListener.h" ICvar* cvar = nullptr; IPanel* panel = nullptr; @@ -51,6 +52,8 @@ 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"); @@ -118,6 +121,9 @@ extern "C" void __attribute__((constructor)) css_basehook_open() { 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() { diff --git a/src/Events/TestListener.h b/src/Events/TestListener.h new file mode 100644 index 0000000..c1271fe --- /dev/null +++ b/src/Events/TestListener.h @@ -0,0 +1,23 @@ +#pragma once + +class TestEventListener: public IGameEventListener2 { + public: + TestEventListener(const char* name) { + // Register self as an event listener. + gameevents->AddListener(this, name, false); + }; + + ~TestEventListener() { + // Unregister when destructor is called. + gameevents->RemoveListener(this); + } + + void FireGameEvent(IGameEvent* event) { + // Print text to console when event is fired. + cvar->ConsoleColorPrintf(Color(150, 255, 150), "Event fired: %s\n", event->GetName()); + } + + int GetEventDebugID() override { + return EVENT_DEBUG_ID_INIT; + }; +}; \ No newline at end of file