forked from daemon32/tickrate_enabler
-
Notifications
You must be signed in to change notification settings - Fork 4
/
TickrateEnabler.cpp
100 lines (86 loc) · 3.13 KB
/
TickrateEnabler.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#include <stdio.h>
#include <sourcehook/sourcehook_impl.h>
#include <eiface.h>
#include <tier0/icommandline.h>
class TickrateEnabler: public IServerPluginCallbacks
{
public:
TickrateEnabler() {}
~TickrateEnabler() {}
virtual bool Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory);
virtual void Unload(void);
virtual void Pause(void) {}
virtual void UnPause(void) {}
virtual const char *GetPluginDescription(void)
{
return "Tickrate Enabler 0.5, updated, original by Didrole";
}
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)
{
return PLUGIN_CONTINUE;
}
virtual PLUGIN_RESULT ClientCommand(edict_t *pEntity, const CCommand &args)
{
return PLUGIN_CONTINUE;
}
virtual PLUGIN_RESULT NetworkIDValidated(const char *pszUserName, const char *pszNetworkID)
{
return PLUGIN_CONTINUE;
}
virtual void OnQueryCvarValueFinished(QueryCvarCookie_t iCookie, edict_t *pPlayerEntity, EQueryCvarValueStatus eStatus, const char *pCvarName, const char *pCvarValue) {}
virtual void OnEdictAllocated(edict_t *edict) {}
virtual void OnEdictFreed(const edict_t *edict) {}
};
IServerGameDLL *server = nullptr;
SourceHook::Impl::CSourceHookImpl g_SourceHook;
SourceHook::ISourceHook *g_SHPtr = &g_SourceHook;
int g_PLID = 0;
TickrateEnabler g_TickrateEnabler;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(TickrateEnabler, IServerPluginCallbacks, INTERFACEVERSION_ISERVERPLUGINCALLBACKS, g_TickrateEnabler);
SH_DECL_HOOK0(IServerGameDLL, GetTickInterval, const, 0, float);
float GetTickInterval()
{
#ifndef TICK_INTERVAL
float tickinterval = DEFAULT_TICK_INTERVAL;
if (CommandLine()->CheckParm("-tickrate"))
{
float tickrate = CommandLine()->ParmValue("-tickrate", 0.0f);
if (tickrate > 10)
tickinterval = 1.0f / tickrate;
}
RETURN_META_VALUE(MRES_SUPERCEDE, tickinterval);
#else
RETURN_META_VALUE(MRES_SUPERCEDE, 1.0f / TICK_INTERVAL);
#endif
}
bool TickrateEnabler::Load(CreateInterfaceFn interfaceFactory, CreateInterfaceFn gameServerFactory)
{
server = reinterpret_cast<IServerGameDLL*>(gameServerFactory("ServerGameDLL010", nullptr));
if (!server)
{
Warning("Failed to get a pointer on ServerGameDLL.");
return false;
}
SH_ADD_HOOK(IServerGameDLL, GetTickInterval, server, SH_STATIC(GetTickInterval), false);
return true;
}
void TickrateEnabler::Unload(void)
{
SH_REMOVE_HOOK(IServerGameDLL, GetTickInterval, server, SH_STATIC(GetTickInterval), false);
}