-
Notifications
You must be signed in to change notification settings - Fork 0
/
cef.cpp
150 lines (118 loc) · 3.52 KB
/
cef.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "cef.h"
using namespace SourceHook;
CEF g_CEF;
PLUGIN_EXPOSE(CEF, g_CEF);
IVEngineServer *engine = NULL;
CGlobalVars *gpGlobals = NULL;
SH_DECL_HOOK1(IVEngineServer, CreateEdict, SH_NOATTRIB, 0, edict_t *, int);
#if !defined ORANGEBOX_BUILD
ICvar* g_pCVar = NULL;
#endif
ICvar* GetICVar()
{
#if defined METAMOD_PLAPI_VERSION
#if SOURCE_ENGINE==SE_ORANGEBOX || SOURCE_ENGINE==SE_LEFT4DEAD || SOURCE_ENGINE==SE_LEFT4DEAD2 || SOURCE_ENGINE==SE_TF2 || SOURCE_ENGINE==SE_DODS || SOURCE_ENGINE==SE_HL2DM || SOURCE_ENGINE==SE_NUCLEARDAWN || \
SOURCE_ENGINE==SE_ALIENSWARM || SOURCE_ENGINE==SE_BLOODYGOODTIME || SOURCE_ENGINE==SE_CSGO || SOURCE_ENGINE==SE_CSS || SOURCE_ENGINE==SE_INSURGENCY || SOURCE_ENGINE==SE_SDK2013 || SOURCE_ENGINE== SE_BMS
return (ICvar *)((g_SMAPI->GetEngineFactory())(CVAR_INTERFACE_VERSION, NULL));
#else
return (ICvar *)((g_SMAPI->GetEngineFactory())(VENGINE_CVAR_INTERFACE_VERSION, NULL));
#endif
#else
return (ICvar *)((g_SMAPI->engineFactory())(VENGINE_CVAR_INTERFACE_VERSION, NULL));
#endif
}
ConVar cvar_cef_log("cef_log", "0", FCVAR_NONE, "Log edict indexes");
bool CEF::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
{
PLUGIN_SAVEVARS();
GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
SH_ADD_HOOK(IVEngineServer, CreateEdict, engine, SH_STATIC(Hook_CreateEdict), false);
gpGlobals = ismm->GetCGlobals();
META_LOG(g_PLAPI, "Starting plugin.");
#if SOURCE_ENGINE==SE_ORANGEBOX || SOURCE_ENGINE==SE_LEFT4DEAD || SOURCE_ENGINE==SE_LEFT4DEAD2 || SOURCE_ENGINE==SE_TF2 || SOURCE_ENGINE==SE_DODS || SOURCE_ENGINE==SE_HL2DM || SOURCE_ENGINE==SE_NUCLEARDAWN || \
SOURCE_ENGINE==SE_ALIENSWARM || SOURCE_ENGINE==SE_BLOODYGOODTIME || SOURCE_ENGINE==SE_CSGO || SOURCE_ENGINE==SE_CSS || SOURCE_ENGINE==SE_INSURGENCY || SOURCE_ENGINE==SE_SDK2013 || SOURCE_ENGINE== SE_BMS
g_pCVar = GetICVar();
ConVar_Register(0, this);
#else
ConCommandBaseMgr::OneTimeInit(this);
#endif
return true;
}
bool CEF::Unload(char *error, size_t maxlen)
{
SH_REMOVE_HOOK(IVEngineServer, CreateEdict, engine, SH_STATIC(Hook_CreateEdict), false);
return true;
}
edict_t * Hook_CreateEdict(int iIndex)
{
if (iIndex > 0)
{
RETURN_META_VALUE(MRES_IGNORED, 0);
}
int i = 0;
while (PEntityOfEntIndex(i) != NULL)
{
i++;
}
if (i >= 2048) /* Maybe we should do something about 2047? */
{
RETURN_META_VALUE(MRES_IGNORED, 0);
}
if (cvar_cef_log.GetBool())
{
g_SMAPI->LogMsg(g_PLAPI, "CEF: %d", i);
}
edict_t * pEdict = ENGINE_CALL(CreateEdict)(i);
if (pEdict == NULL)
{
RETURN_META_VALUE(MRES_IGNORED, 0);
}
RETURN_META_VALUE(MRES_SUPERCEDE, pEdict);
}
bool CEF::RegisterConCommandBase(ConCommandBase *pVar)
{
return META_REGCVAR(pVar);
}
bool CEF::Pause(char *error, size_t maxlen)
{
return true;
}
bool CEF::Unpause(char *error, size_t maxlen)
{
return true;
}
void CEF::AllPluginsLoaded()
{
}
const char *CEF::GetLicense()
{
return "GPL";
}
const char *CEF::GetVersion()
{
return "1.1.5";
}
const char *CEF::GetDate()
{
return __DATE__;
}
const char *CEF::GetLogTag()
{
return "CEF";
}
const char *CEF::GetAuthor()
{
return "Kyle Sanderson";
}
const char *CEF::GetDescription()
{
return "Fixes the currently messed up CreateEdict implementation.";
}
const char *CEF::GetName()
{
return "Create Edict Fixer";
}
const char *CEF::GetURL()
{
return "http://www.SourceMod.net/";
}