mirror of
https://github.com/daemon32/tickrate_enabler.git
synced 2025-12-06 18:08:32 +00:00
- Updated sourcehook_source to the latest css branch
- Created a VS2013 project/solution for tickrate_enabler
258 lines
10 KiB
C++
258 lines
10 KiB
C++
//===== Copyright © 1996-2008, Valve Corporation, All rights reserved. ======//
|
|
//
|
|
// Purpose:
|
|
//
|
|
// $NoKeywords: $
|
|
//
|
|
//===========================================================================//
|
|
|
|
|
|
#include "igameevents.h"
|
|
#include "eiface.h"
|
|
#include "tier0/icommandline.h"
|
|
|
|
#include "sourcehook/sourcehook_impl.h"
|
|
|
|
|
|
// memdbgon must be the last include file in a .cpp file!!!
|
|
#include "tier0/memdbgon.h"
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: a sample 3rd party plugin class
|
|
//---------------------------------------------------------------------------------
|
|
class CEmptyServerPlugin: public IServerPluginCallbacks, public IGameEventListener
|
|
{
|
|
public:
|
|
CEmptyServerPlugin();
|
|
~CEmptyServerPlugin();
|
|
|
|
// IServerPluginCallbacks methods
|
|
virtual bool Load( CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory );
|
|
virtual void Unload( void );
|
|
virtual void Pause( void );
|
|
virtual void UnPause( void );
|
|
virtual const char *GetPluginDescription( void );
|
|
virtual void LevelInit( char const *pMapName );
|
|
virtual void ServerActivate( edict_t *pEdictList, int edictCount, int clientMax );
|
|
virtual void GameFrame( bool simulating );
|
|
virtual void LevelShutdown( void );
|
|
virtual void ClientActive( edict_t *pEntity );
|
|
virtual void ClientDisconnect( edict_t *pEntity );
|
|
virtual void ClientPutInServer( edict_t *pEntity, char const *playername );
|
|
virtual void SetCommandClient( int index );
|
|
virtual void ClientSettingsChanged( edict_t *pEdict );
|
|
virtual PLUGIN_RESULT ClientConnect( bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen );
|
|
virtual PLUGIN_RESULT ClientCommand( edict_t *pEntity, const CCommand &args );
|
|
virtual PLUGIN_RESULT NetworkIDValidated( const char *pszUserName, const char *pszNetworkID );
|
|
virtual void OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue );
|
|
|
|
// added with version 3 of the interface.
|
|
virtual void OnEdictAllocated( edict_t *edict );
|
|
virtual void OnEdictFreed( const edict_t *edict );
|
|
|
|
// IGameEventListener Interface
|
|
virtual void FireGameEvent( KeyValues * event );
|
|
|
|
virtual int GetCommandIndex() { return m_iClientCommandIndex; }
|
|
private:
|
|
int m_iClientCommandIndex;
|
|
};
|
|
|
|
|
|
//
|
|
// The plugin is a static singleton that is exported as an interface
|
|
//
|
|
CEmptyServerPlugin g_EmtpyServerPlugin;
|
|
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(CEmptyServerPlugin, IServerPluginCallbacks, INTERFACEVERSION_ISERVERPLUGINCALLBACKS, g_EmtpyServerPlugin );
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: constructor/destructor
|
|
//---------------------------------------------------------------------------------
|
|
CEmptyServerPlugin::CEmptyServerPlugin()
|
|
{
|
|
m_iClientCommandIndex = 0;
|
|
}
|
|
|
|
CEmptyServerPlugin::~CEmptyServerPlugin()
|
|
{
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called once per server frame, do recurring work here (like checking for timeouts)
|
|
//---------------------------------------------------------------------------------
|
|
void CEmptyServerPlugin::GameFrame( bool simulating )
|
|
{
|
|
}
|
|
|
|
SourceHook::Impl::CSourceHookImpl g_SourceHook;
|
|
SourceHook::ISourceHook *g_SHPtr = &g_SourceHook;
|
|
int g_PLID = 0;
|
|
|
|
SH_DECL_HOOK0(IServerGameDLL, GetTickInterval, const, 0, float);
|
|
|
|
float GetTickInterval()
|
|
{
|
|
float tickinterval = DEFAULT_TICK_INTERVAL;
|
|
|
|
if ( CommandLine()->CheckParm( "-tickrate" ) )
|
|
{
|
|
float tickrate = CommandLine()->ParmValue( "-tickrate", 0 );
|
|
if ( tickrate > 10 )
|
|
tickinterval = 1.0f / tickrate;
|
|
}
|
|
|
|
RETURN_META_VALUE(MRES_SUPERCEDE, tickinterval );
|
|
}
|
|
|
|
|
|
IServerGameDLL *gamedll = NULL;
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called when the plugin is loaded, load the interface we need from the engine
|
|
//---------------------------------------------------------------------------------
|
|
bool CEmptyServerPlugin::Load( CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory )
|
|
{
|
|
gamedll = (IServerGameDLL*)gameServerFactory("ServerGameDLL010",NULL);
|
|
if(!gamedll)
|
|
{
|
|
Warning("Failed to get a pointer on ServerGameDLL.\n");
|
|
return false;
|
|
}
|
|
|
|
SH_ADD_HOOK(IServerGameDLL, GetTickInterval, gamedll, SH_STATIC(GetTickInterval), false);
|
|
|
|
return true;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called when the plugin is unloaded (turned off)
|
|
//---------------------------------------------------------------------------------
|
|
void CEmptyServerPlugin::Unload( void )
|
|
{
|
|
SH_REMOVE_HOOK(IServerGameDLL, GetTickInterval, gamedll, SH_STATIC(GetTickInterval), false);
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called when the plugin is paused (i.e should stop running but isn't unloaded)
|
|
//---------------------------------------------------------------------------------
|
|
void CEmptyServerPlugin::Pause( void )
|
|
{
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called when the plugin is unpaused (i.e should start executing again)
|
|
//---------------------------------------------------------------------------------
|
|
void CEmptyServerPlugin::UnPause( void )
|
|
{
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: the name of this plugin, returned in "plugin_print" command
|
|
//---------------------------------------------------------------------------------
|
|
const char *CEmptyServerPlugin::GetPluginDescription( void )
|
|
{
|
|
return "Tickrate_Enabler 0.5, updated, original by Didrole";
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called on level start
|
|
//---------------------------------------------------------------------------------
|
|
void CEmptyServerPlugin::LevelInit( char const *pMapName )
|
|
{
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called on level start, when the server is ready to accept client connections
|
|
// edictCount is the number of entities in the level, clientMax is the max client count
|
|
//---------------------------------------------------------------------------------
|
|
void CEmptyServerPlugin::ServerActivate( edict_t *pEdictList, int edictCount, int clientMax )
|
|
{
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called on level end (as the server is shutting down or going to a new map)
|
|
//---------------------------------------------------------------------------------
|
|
void CEmptyServerPlugin::LevelShutdown( void ) // !!!!this can get called multiple times per map change
|
|
{
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called when a client spawns into a server (i.e as they begin to play)
|
|
//---------------------------------------------------------------------------------
|
|
void CEmptyServerPlugin::ClientActive( edict_t *pEntity )
|
|
{
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called when a client leaves a server (or is timed out)
|
|
//---------------------------------------------------------------------------------
|
|
void CEmptyServerPlugin::ClientDisconnect( edict_t *pEntity )
|
|
{
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called on
|
|
//---------------------------------------------------------------------------------
|
|
void CEmptyServerPlugin::ClientPutInServer( edict_t *pEntity, char const *playername )
|
|
{
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called on level start
|
|
//---------------------------------------------------------------------------------
|
|
void CEmptyServerPlugin::SetCommandClient( int index )
|
|
{
|
|
m_iClientCommandIndex = index;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called on level start
|
|
//---------------------------------------------------------------------------------
|
|
void CEmptyServerPlugin::ClientSettingsChanged( edict_t *pEdict )
|
|
{
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called when a client joins a server
|
|
//---------------------------------------------------------------------------------
|
|
PLUGIN_RESULT CEmptyServerPlugin::ClientConnect( bool *bAllowConnect, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen )
|
|
{
|
|
return PLUGIN_CONTINUE;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called when a client types in a command (only a subset of commands however, not CON_COMMAND's)
|
|
//---------------------------------------------------------------------------------
|
|
PLUGIN_RESULT CEmptyServerPlugin::ClientCommand( edict_t *pEntity, const CCommand &args )
|
|
{
|
|
return PLUGIN_CONTINUE;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called when a client is authenticated
|
|
//---------------------------------------------------------------------------------
|
|
PLUGIN_RESULT CEmptyServerPlugin::NetworkIDValidated( const char *pszUserName, const char *pszNetworkID )
|
|
{
|
|
return PLUGIN_CONTINUE;
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called when a cvar value query is finished
|
|
//---------------------------------------------------------------------------------
|
|
void CEmptyServerPlugin::OnQueryCvarValueFinished( QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue )
|
|
{
|
|
}
|
|
void CEmptyServerPlugin::OnEdictAllocated( edict_t *edict )
|
|
{
|
|
}
|
|
void CEmptyServerPlugin::OnEdictFreed( const edict_t *edict )
|
|
{
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------
|
|
// Purpose: called when an event is fired
|
|
//---------------------------------------------------------------------------------
|
|
void CEmptyServerPlugin::FireGameEvent( KeyValues * event )
|
|
{
|
|
}
|