Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ CGameEntitySystem *GameEntitySystem()
}

class GameSessionConfiguration_t { };
SH_DECL_HOOK3_void(IServerGameDLL, GameFrame, SH_NOATTRIB, 0, bool, bool, bool);
SH_DECL_HOOK3_void(INetworkServerService, StartupServer, SH_NOATTRIB, 0, const GameSessionConfiguration_t&, ISource2WorldSession*, const char*);
#if defined _LINUX
KHook::Virtual<IServerGameDLL, void, bool, bool, bool> gameFrameHook(&IServerGameDLL::GameFrame, &g_AcceleratorCS2, nullptr, &AcceleratorCS2::GameFrame);
#endif
KHook::Virtual<INetworkServerService, void, const GameSessionConfiguration_t&, ISource2WorldSession*, const char*> startupServerHook(&INetworkServerService::StartupServer, &g_AcceleratorCS2, nullptr, &AcceleratorCS2::StartupServer);

google_breakpad::ExceptionHandler* exceptionHandler = nullptr;

Expand Down Expand Up @@ -459,7 +461,7 @@ bool AcceleratorCS2::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen
sigaction(SIGSEGV, NULL, &oact);
SignalHandler = oact.sa_sigaction;

SH_ADD_HOOK(IServerGameDLL, GameFrame, g_pSource2Server, SH_MEMBER(this, &AcceleratorCS2::GameFrame), true);
gameFrameHook.Add(g_pSource2Server);
#else
wchar_t* buf = new wchar_t[sizeof(dumpStoragePath)];
size_t num_chars = mbstowcs(buf, dumpStoragePath, sizeof(dumpStoragePath));
Expand All @@ -473,12 +475,12 @@ bool AcceleratorCS2::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen
delete buf;
#endif

SH_ADD_HOOK(INetworkServerService, StartupServer, g_pNetworkServerService, SH_MEMBER(this, &AcceleratorCS2::StartupServer), true);
startupServerHook.Add(g_pNetworkServerService);

strncpy(crashCommandLine, CommandLine()->GetCmdLine(), sizeof(crashCommandLine) - 1);

if (late)
StartupServer({}, nullptr, nullptr);
StartupServer(nullptr, {}, nullptr, nullptr);

LoadServerId();
LoadConfig();
Expand All @@ -492,9 +494,9 @@ bool AcceleratorCS2::Load(PluginId id, ISmmAPI* ismm, char* error, size_t maxlen
bool AcceleratorCS2::Unload(char* error, size_t maxlen)
{
#if defined _LINUX
SH_REMOVE_HOOK(IServerGameDLL, GameFrame, g_pSource2Server, SH_MEMBER(this, &AcceleratorCS2::GameFrame), true);
gameFrameHook.Remove(g_pSource2Server);
#endif
SH_REMOVE_HOOK(INetworkServerService, StartupServer, g_pNetworkServerService, SH_MEMBER(this, &AcceleratorCS2::StartupServer), true);
startupServerHook.Remove(g_pNetworkServerService);

delete exceptionHandler;

Expand All @@ -503,7 +505,7 @@ bool AcceleratorCS2::Unload(char* error, size_t maxlen)

#if defined _LINUX

void AcceleratorCS2::GameFrame(bool simulating, bool bFirstTick, bool bLastTick)
KHook::Return<void> AcceleratorCS2::GameFrame(IServerGameDLL* pThis, bool simulating, bool bFirstTick, bool bLastTick)
{
bool weHaveBeenFuckedOver = false;
struct sigaction oact;
Expand All @@ -520,7 +522,7 @@ void AcceleratorCS2::GameFrame(bool simulating, bool bFirstTick, bool bLastTick)
}

if (!weHaveBeenFuckedOver)
return;
return {KHook::Action::Ignore};

struct sigaction act;
memset(&act, 0, sizeof(act));
Expand All @@ -534,13 +536,17 @@ void AcceleratorCS2::GameFrame(bool simulating, bool bFirstTick, bool bLastTick)

for (int i = 0; i < kNumHandledSignals; ++i)
sigaction(kExceptionSignals[i], &act, NULL);

return {KHook::Action::Ignore};
}

#endif

void AcceleratorCS2::StartupServer(const GameSessionConfiguration_t& config, ISource2WorldSession*, const char*)
KHook::Return<void> AcceleratorCS2::StartupServer(INetworkServerService* pThis, const GameSessionConfiguration_t& config, ISource2WorldSession*, const char*)
{
strncpy(crashMap, g_pNetworkServerService->GetIGameServer()->GetMapName(), sizeof(crashMap) - 1);

return {KHook::Action::Ignore};
}

const char* AcceleratorCS2::GetLicense()
Expand All @@ -550,7 +556,7 @@ const char* AcceleratorCS2::GetLicense()

const char* AcceleratorCS2::GetVersion()
{
return "2.0.6";
return "3.0";
}

const char* AcceleratorCS2::GetDate()
Expand Down
8 changes: 4 additions & 4 deletions extension.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include "khook.hpp"
#include <ISmmPlugin.h>
#include <igameevents.h>
#include <sh_vector.h>
#include <iserver.h>

class AcceleratorCS2 : public ISmmPlugin, public IMetamodListener
Expand All @@ -18,7 +18,7 @@ class AcceleratorCS2 : public ISmmPlugin, public IMetamodListener
const char* GetVersion();
const char* GetDate();
const char* GetLogTag();
private: // Hooks
void GameFrame(bool simulating, bool bFirstTick, bool bLastTick);
void StartupServer(const GameSessionConfiguration_t& config, ISource2WorldSession*, const char*);
public: // Hooks
KHook::Return<void> GameFrame(IServerGameDLL* pThis, bool simulating, bool bFirstTick, bool bLastTick);
KHook::Return<void> StartupServer(INetworkServerService* pThis, const GameSessionConfiguration_t& config, ISource2WorldSession*, const char*);
};
7 changes: 1 addition & 6 deletions premake/mm-linux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ files {
path.join(SDK_PATH, "tier1", "convar.cpp"),
path.join(SDK_PATH, "entity2", "entityidentity.cpp"),
path.join(SDK_PATH, "entity2", "entitysystem.cpp"),
path.join(MM_PATH, "core", "sourcehook", "sourcehook.cpp"),
path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_chookidman.cpp"),
path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_chookmaninfo.cpp"),
path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_cvfnptr.cpp"),
path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_cproto.cpp"),
}

libdirs {
Expand Down Expand Up @@ -37,7 +32,7 @@ includedirs {
path.join(SDK_PATH, "public", "public", "entity2"),
-- metamod
path.join(MM_PATH, "core"),
path.join(MM_PATH, "core", "sourcehook"),
path.join(MM_PATH, "third_party", "khook", "include"),
}

defines {
Expand Down
7 changes: 1 addition & 6 deletions premake/mm-windows.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ files {
path.join(SDK_PATH, "tier1", "convar.cpp"),
path.join(SDK_PATH, "entity2", "entityidentity.cpp"),
path.join(SDK_PATH, "entity2", "entitysystem.cpp"),
path.join(MM_PATH, "core", "sourcehook", "sourcehook.cpp"),
path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_chookidman.cpp"),
path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_chookmaninfo.cpp"),
path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_cvfnptr.cpp"),
path.join(MM_PATH, "core", "sourcehook", "sourcehook_impl_cproto.cpp"),
}

links {
Expand All @@ -32,7 +27,7 @@ includedirs {
path.join(SDK_PATH, "public", "public", "entity2"),
-- metamod
path.join(MM_PATH, "core"),
path.join(MM_PATH, "core", "sourcehook"),
path.join(MM_PATH, "third_party", "khook", "include"),
}

defines {
Expand Down
Loading