Add example event listener on player_footstep.
Signed-off-by: aixxe <me@aixxe.net>
This commit is contained in:
parent
c1738ce42b
commit
afc72efcd8
|
@ -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
|
||||
|
||||
|
|
|
@ -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<VMTHook> enginevgui_hook;
|
|||
std::unique_ptr<VMTHook> modelrender_hook;
|
||||
std::unique_ptr<VMTHook> inputinternal_hook;
|
||||
|
||||
std::unique_ptr<TestEventListener> testevent;
|
||||
|
||||
extern "C" void __attribute__((constructor)) css_basehook_open() {
|
||||
// Get class pointers from game libraries using partial interface versions.
|
||||
cvar = GetInterface<ICvar>("bin/libvstdlib.so", "VEngineCvar0");
|
||||
|
@ -118,6 +121,9 @@ extern "C" void __attribute__((constructor)) css_basehook_open() {
|
|||
globalvars = **reinterpret_cast<CGlobalVarsBase***>(
|
||||
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() {
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
};
|
Loading…
Reference in New Issue