-
Notifications
You must be signed in to change notification settings - Fork 0
/
Extension.cpp
159 lines (121 loc) · 5.38 KB
/
Extension.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
151
152
153
154
155
156
157
158
159
#include <sourcemod_version.h>
#include "Extension.h"
#include "ConnectOperation.h"
#include "ConnectCallback.h"
#include "Clientlistener.h"
#include "Globals.h"
#include "ClientCommandListener.h"
#include <engine\ivdebugoverlay.h>
#include "CompatWrappers.h"
#include "SayCommandListener.h"
using namespace SourceHook;
SMEXT_LINK(&g_War3SourceExtension);
IVDebugOverlay *debugOverlay = NULL;
#if SOURCE_ENGINE >= SE_ORANGEBOX
SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &);
#else
SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);
#endif
#if SOURCE_ENGINE >= SE_ORANGEBOX
SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &);
#else
SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
#endif
SH_DECL_HOOK1_void(IServerGameClients, SetCommandClient, SH_NOATTRIB, false, int);
/* :HACKHACK: We can't SH_DECL here because ConCmdManager.cpp does.
* While the OB build only runs on MM:S 1.6.0+ (SH 5+), the older one
* can technically be compiled against any MM:S version after 1.4.2.
*/
#if SOURCE_ENGINE >= SE_ORANGEBOX
extern bool __SourceHook_FHRemoveConCommandDispatch(void *, bool, class fastdelegate::FastDelegate1<const CCommand &, void>);
extern int __SourceHook_FHAddConCommandDispatch(void *, ISourceHook::AddHookMode, bool, class fastdelegate::FastDelegate1<const CCommand &, void>);
#else
extern bool __SourceHook_FHRemoveConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0<void>);
#if SH_IMPL_VERSION >= 5
extern int __SourceHook_FHAddConCommandDispatch(void *, ISourceHook::AddHookMode, bool, class fastdelegate::FastDelegate0<void>);
#elif SH_IMPL_VERSION == 4
extern int __SourceHook_FHAddConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0<void>);
#elif SH_IMPL_VERSION == 3
extern bool __SourceHook_FHAddConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0<void>);
#endif //SH_IMPL_VERSION
#endif //SE_ORANGEBOX
namespace War3Source {
bool Extension::SDK_OnLoad(char *error, size_t err_max, bool late) {
const DatabaseInfo *dbInfo = dbi->FindDatabaseConf("war3source");
if(NULL == dbInfo) {
dbInfo = dbi->FindDatabaseConf("default");
if(dbInfo == NULL) {
StrCopy(error, err_max, "Unable to find database configuration for war3source or default.");
return false;
}
}
IDBDriver *dbDriver = NULL;
if(dbInfo->driver[0] == '\0') {
dbDriver = dbi->GetDefaultDriver();
}
else {
dbDriver = dbi->FindOrLoadDriver(dbInfo->driver);
}
if(NULL == dbDriver) {
StrCopy(error, err_max, "Unable to load database driver.");
return false;
}
META_CONPRINTF("Connecting to DB...\n");
IConnectCallback *connectCallback = new ConnectCallback();
ConnectOperation *connectOperation = new ConnectOperation(dbDriver, dbInfo, connectCallback);
dbi->AddToThreadQueue(connectOperation, PrioQueue_Normal);
return true;
}
void Extension::SDK_OnUnload() {
ConCommand *sayCommand = FindCommand("say");
ConCommand *sayTeamCommand = FindCommand("say_team");
if(sayCommand) {
SH_REMOVE_HOOK_MEMFUNC(ConCommand, Dispatch, sayCommand, g_SayCommandListener, &ISayCommandListener::OnSayCommand, false);
}
if(sayTeamCommand) {
SH_REMOVE_HOOK_MEMFUNC(ConCommand, Dispatch, sayTeamCommand, g_SayCommandListener, &ISayCommandListener::OnSayCommand, false);
}
SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientCommand, g_ServerGameClients, g_ClientCommandListener, &IClientCommandListener::OnClientCommand, false);
}
const char *Extension::GetExtensionVerString() {
return SMEXT_CONF_VERSION;
}
const char *Extension::GetExtensionDateString() {
return SM_BUILD_TIMESTAMP;
}
bool Extension::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late) {
GET_V_IFACE_CURRENT(GetEngineFactory, g_CVar,
ICvar, CVAR_INTERFACE_VERSION);
GET_V_IFACE_ANY(GetServerFactory, g_ServerGameClients,
IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
if(g_ServerGameClients == NULL) {
StrFormat(error, maxlen, "%s", "WAR3 FATAL ERROR: Unable to find IServerGameClients\n");
return false;
}
if(g_CVar == NULL) {
StrFormat(error, maxlen, "%s", "WAR3 FATAL ERROR: Unable to find ICvar\n");
return false;
}
icvar = g_CVar;
g_Globals = ismm->GetCGlobals();
gpGlobals = g_Globals;
ConCommand *sayCommand = FindCommand("say");
ConCommand *sayTeamCommand = FindCommand("say_team");
g_SayCommandListener = new SayCommandListener();
if(sayCommand) {
SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, sayCommand, g_SayCommandListener, &ISayCommandListener::OnSayCommand, false);
}
if(sayTeamCommand) {
SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, sayTeamCommand, g_SayCommandListener, &ISayCommandListener::OnSayCommand, false);
}
return true;
}
bool Extension::QueryRunning(char *error, size_t maxlength) {
return true;
}
void Extension::SDK_OnAllLoaded() {
g_ClientCommandListener = new ClientCommandListener();
SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientCommand, g_ServerGameClients, g_ClientCommandListener, &IClientCommandListener::OnClientCommand, false);
SH_ADD_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, g_ServerGameClients, g_ClientCommandListener, &IClientCommandListener::OnSetCommandClient, false);
}
}