Add example event listener on player_footstep.

Signed-off-by: aixxe <me@aixxe.net>
This commit is contained in:
aixxe 2016-12-23 12:19:12 +00:00
parent c1738ce42b
commit afc72efcd8
3 changed files with 31 additions and 0 deletions

View File

@ -5,9 +5,11 @@ Internal project base for Counter-Strike: Source on Linux. Includes full OpenGL
### Features ### Features
* Retrieves interfaces directly from the *s_pInterfaceRegs* linked list. * Retrieves interfaces directly from the *s_pInterfaceRegs* linked list.
* ImGui drawing and input handling via *ILauncherMgr* virtual hooks. * 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. * *IBaseClientDLL::CreateMove* hook with *CUserCmd* checksum validation.
* *CInput* and *CGlobalVars* pointers retrieved from IBaseClientDLL virtuals. * *CInput* and *CGlobalVars* pointers retrieved from IBaseClientDLL virtuals.
* Can easily be unloaded, modified and reloaded without restarting the game. * Can easily be unloaded, modified and reloaded without restarting the game.
* Includes an example game event listener in a self-contained class.
### Requirements ### Requirements

View File

@ -20,6 +20,7 @@
#include "Basehook.h" #include "Basehook.h"
#include "Hooks/Hooks.h" #include "Hooks/Hooks.h"
#include "Events/TestListener.h"
ICvar* cvar = nullptr; ICvar* cvar = nullptr;
IPanel* panel = nullptr; IPanel* panel = nullptr;
@ -51,6 +52,8 @@ std::unique_ptr<VMTHook> enginevgui_hook;
std::unique_ptr<VMTHook> modelrender_hook; std::unique_ptr<VMTHook> modelrender_hook;
std::unique_ptr<VMTHook> inputinternal_hook; std::unique_ptr<VMTHook> inputinternal_hook;
std::unique_ptr<TestEventListener> testevent;
extern "C" void __attribute__((constructor)) css_basehook_open() { extern "C" void __attribute__((constructor)) css_basehook_open() {
// Get class pointers from game libraries using partial interface versions. // Get class pointers from game libraries using partial interface versions.
cvar = GetInterface<ICvar>("bin/libvstdlib.so", "VEngineCvar0"); cvar = GetInterface<ICvar>("bin/libvstdlib.so", "VEngineCvar0");
@ -118,6 +121,9 @@ extern "C" void __attribute__((constructor)) css_basehook_open() {
globalvars = **reinterpret_cast<CGlobalVarsBase***>( globalvars = **reinterpret_cast<CGlobalVarsBase***>(
clientdll_hook->GetOriginalFunction<uintptr_t>(11) + 8 clientdll_hook->GetOriginalFunction<uintptr_t>(11) + 8
); );
// Register an event listener.
testevent = std::make_unique<TestEventListener>("player_footstep");
} }
extern "C" void __attribute__((destructor)) css_basehook_close() { extern "C" void __attribute__((destructor)) css_basehook_close() {

23
src/Events/TestListener.h Normal file
View File

@ -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;
};
};