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
20 changes: 16 additions & 4 deletions managed/CounterStrikeSharp.API/Core/Listeners.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

namespace CounterStrikeSharp.API.Core
{
public class Listeners {
public class Listeners
{
/// <summary>
/// Called when an entity is spawned.
/// </summary>
Expand Down Expand Up @@ -44,6 +44,18 @@ public class Listeners {
[ListenerName("OnTick")]
public delegate void OnTick();

/// <summary>
/// Called on every server frame before entities think.
/// </summary>
[ListenerName("OnServerPreEntityThink")]
public delegate void OnServerPreEntityThink();

/// <summary>
/// Called on every server frame after entities think.
/// </summary>
[ListenerName("OnServerPostEntityThink")]
public delegate void OnServerPostEntityThink();

/// <summary>
/// Called when a new map is loaded.
/// </summary>
Expand Down Expand Up @@ -107,7 +119,7 @@ public class Listeners {
/// <param name="playerSlot">The player slot of the authorized client.</param>
/// <param name="steamId">The Steam ID of the authorized client.</param>
[ListenerName("OnClientAuthorized")]
public delegate void OnClientAuthorized(int playerSlot, [CastFrom(typeof(ulong))]SteamID steamId);
public delegate void OnClientAuthorized(int playerSlot, [CastFrom(typeof(ulong))] SteamID steamId);

/// <summary>
/// Called when the server is updating the hibernation state.
Expand Down Expand Up @@ -169,7 +181,7 @@ public class Listeners {
/// </summary>
/// <param name="infoList">Transmit info list</param>
[ListenerName("CheckTransmit")]
public delegate void CheckTransmit([CastFrom(typeof(nint))]CCheckTransmitInfoList infoList);
public delegate void CheckTransmit([CastFrom(typeof(nint))] CCheckTransmitInfoList infoList);

/// <summary>
/// Called when all metamod plugins are loaded.
Expand Down
27 changes: 26 additions & 1 deletion src/core/game_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
#include "core/globals.h"
#include "core/gameconfig.h"
#include "core/game_system.h"

#include "core/managers/server_manager.h"
#include "scripting/callback_manager.h"
#include <tier0/vprof.h>

CBaseGameSystemFactory** CBaseGameSystemFactory::sm_pFirst = nullptr;

Expand Down Expand Up @@ -65,3 +66,27 @@ GS_EVENT_MEMBER(CGameSystem, BuildGameSessionManifest)

counterstrikesharp::globals::serverManager.OnPrecacheResources(pResourceManifest);
}

GS_EVENT_MEMBER(CGameSystem, ServerPreEntityThink)
{
VPROF_BUDGET("CS#::CGameSystem::ServerPreEntityThink", "CS# On Frame");
auto callback = counterstrikesharp::globals::serverManager.on_server_pre_entity_think;

if (callback && callback->GetFunctionCount())
{
callback->ScriptContext().Reset();
callback->Execute();
}
}

GS_EVENT_MEMBER(CGameSystem, ServerPostEntityThink)
{
VPROF_BUDGET("CS#::CGameSystem::ServerPostEntityThink", "CS# On Frame");
auto callback = counterstrikesharp::globals::serverManager.on_server_post_entity_think;

if (callback && callback->GetFunctionCount())
{
callback->ScriptContext().Reset();
callback->Execute();
}
}
2 changes: 2 additions & 0 deletions src/core/game_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class CGameSystem : public CBaseGameSystem
{
public:
GS_EVENT(BuildGameSessionManifest);
GS_EVENT(ServerPreEntityThink);
GS_EVENT(ServerPostEntityThink);

void Shutdown() override
{
Expand Down
4 changes: 4 additions & 0 deletions src/core/managers/server_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ void ServerManager::OnAllInitialized()
on_server_pre_fatal_shutdown = globals::callbackManager.CreateCallback("OnPreFatalShutdown");
on_server_update_when_not_in_game = globals::callbackManager.CreateCallback("OnUpdateWhenNotInGame");
on_server_pre_world_update = globals::callbackManager.CreateCallback("OnServerPreWorldUpdate");
on_server_pre_entity_think = globals::callbackManager.CreateCallback("OnServerPreEntityThink");
on_server_post_entity_think = globals::callbackManager.CreateCallback("OnServerPostEntityThink");

on_server_precache_resources = globals::callbackManager.CreateCallback("OnServerPrecacheResources");
}
Expand All @@ -79,6 +81,8 @@ void ServerManager::OnShutdown()
globals::callbackManager.ReleaseCallback(on_server_pre_fatal_shutdown);
globals::callbackManager.ReleaseCallback(on_server_update_when_not_in_game);
globals::callbackManager.ReleaseCallback(on_server_pre_world_update);
globals::callbackManager.ReleaseCallback(on_server_pre_entity_think);
globals::callbackManager.ReleaseCallback(on_server_post_entity_think);

globals::callbackManager.ReleaseCallback(on_server_precache_resources);
}
Expand Down
3 changes: 3 additions & 0 deletions src/core/managers/server_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class ServerManager : public GlobalClass
void AddTaskForNextWorldUpdate(std::function<void()>&& task);
void OnPrecacheResources(IEntityResourceManifest* pResourceManifest);

ScriptCallback* on_server_pre_entity_think;
ScriptCallback* on_server_post_entity_think;

private:
void ServerHibernationUpdate(bool bHibernating);
void GameServerSteamAPIActivated();
Expand Down
Loading