|
faluco@1441
|
1 |
/** |
|
faluco@1441
|
2 |
* vim: set ts=4 : |
|
faluco@1441
|
3 |
* ============================================================================= |
|
faluco@1441
|
4 |
* SourceMod Counter-Strike:Source Extension |
|
faluco@1441
|
5 |
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. |
|
faluco@1441
|
6 |
* ============================================================================= |
|
faluco@1441
|
7 |
* |
|
faluco@1441
|
8 |
* This program is free software; you can redistribute it and/or modify it under |
|
faluco@1441
|
9 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
faluco@1441
|
10 |
* Free Software Foundation. |
|
faluco@1441
|
11 |
* |
|
faluco@1441
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
faluco@1441
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
faluco@1441
|
14 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
faluco@1441
|
15 |
* details. |
|
faluco@1441
|
16 |
* |
|
faluco@1441
|
17 |
* You should have received a copy of the GNU General Public License along with |
|
faluco@1441
|
18 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
faluco@1441
|
19 |
* |
|
faluco@1441
|
20 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
faluco@1441
|
21 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
faluco@1441
|
22 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
faluco@1441
|
23 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
faluco@1441
|
24 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
faluco@1441
|
25 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
faluco@1441
|
26 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
faluco@1441
|
27 |
* or <http://www.sourcemod.net/license.php>. |
|
faluco@1441
|
28 |
* |
|
faluco@1441
|
29 |
* Version: $Id$ |
|
faluco@1441
|
30 |
*/ |
|
faluco@1441
|
31 |
|
|
faluco@1441
|
32 |
#include "extension.h" |
|
faluco@1441
|
33 |
#include "RegNatives.h" |
|
dvander@1459
|
34 |
#include "timeleft.h" |
|
faluco@1441
|
35 |
|
|
faluco@1441
|
36 |
/** |
|
faluco@1441
|
37 |
* @file extension.cpp |
|
faluco@1441
|
38 |
* @brief Implement extension code here. |
|
faluco@1441
|
39 |
*/ |
|
faluco@1441
|
40 |
|
|
dvander@1459
|
41 |
SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool); |
|
dvander@1459
|
42 |
|
|
faluco@1441
|
43 |
CStrike g_CStrike; /**< Global singleton for extension's main interface */ |
|
faluco@1441
|
44 |
IBinTools *g_pBinTools = NULL; |
|
faluco@1441
|
45 |
IGameConfig *g_pGameConf = NULL; |
|
dvander@1459
|
46 |
IGameEventManager2 *gameevents = NULL; |
|
dvander@1459
|
47 |
bool hooked_everything = false; |
|
faluco@1441
|
48 |
|
|
faluco@1441
|
49 |
SMEXT_LINK(&g_CStrike); |
|
faluco@1441
|
50 |
|
|
faluco@1441
|
51 |
extern sp_nativeinfo_t g_CSNatives[]; |
|
faluco@1441
|
52 |
|
|
faluco@1441
|
53 |
bool CStrike::SDK_OnLoad(char *error, size_t maxlength, bool late) |
|
faluco@1441
|
54 |
{ |
|
faluco@1441
|
55 |
sharesys->AddDependency(myself, "bintools.ext", true, true); |
|
faluco@1441
|
56 |
|
|
dvander@1459
|
57 |
char conf_error[255]; |
|
dvander@1459
|
58 |
if (!gameconfs->LoadGameConfigFile("sm-cstrike.games", &g_pGameConf, conf_error, sizeof(conf_error))) |
|
faluco@1441
|
59 |
{ |
|
dvander@1459
|
60 |
if (error) |
|
dvander@1459
|
61 |
{ |
|
dvander@1459
|
62 |
snprintf(error, maxlength, "Could not read sm-cstrike.games.txt: %s", conf_error); |
|
dvander@1459
|
63 |
} |
|
faluco@1441
|
64 |
return false; |
|
faluco@1441
|
65 |
} |
|
faluco@1441
|
66 |
|
|
faluco@1441
|
67 |
sharesys->AddNatives(myself, g_CSNatives); |
|
faluco@1441
|
68 |
|
|
faluco@1441
|
69 |
return true; |
|
faluco@1441
|
70 |
} |
|
faluco@1441
|
71 |
|
|
dvander@1459
|
72 |
bool CStrike::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late) |
|
dvander@1459
|
73 |
{ |
|
faluco@1552
|
74 |
GET_V_IFACE_CURRENT(GetEngineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2); |
|
faluco@1552
|
75 |
GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER); |
|
dvander@1459
|
76 |
|
|
dvander@1459
|
77 |
return true; |
|
dvander@1459
|
78 |
} |
|
dvander@1459
|
79 |
|
|
faluco@1441
|
80 |
void CStrike::SDK_OnUnload() |
|
faluco@1441
|
81 |
{ |
|
dvander@1459
|
82 |
if (hooked_everything) |
|
dvander@1459
|
83 |
{ |
|
dvander@1459
|
84 |
gameevents->RemoveListener(&g_TimeLeftEvents); |
|
dvander@1459
|
85 |
SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, &g_TimeLeftEvents, &TimeLeftEvents::LevelInit, true); |
|
dvander@1459
|
86 |
hooked_everything = false; |
|
dvander@1459
|
87 |
} |
|
faluco@1441
|
88 |
g_RegNatives.UnregisterAll(); |
|
faluco@1441
|
89 |
gameconfs->CloseGameConfigFile(g_pGameConf); |
|
faluco@1441
|
90 |
} |
|
faluco@1441
|
91 |
|
|
faluco@1441
|
92 |
void CStrike::SDK_OnAllLoaded() |
|
faluco@1441
|
93 |
{ |
|
dvander@1459
|
94 |
gameevents->AddListener(&g_TimeLeftEvents, "round_start", true); |
|
dvander@1459
|
95 |
gameevents->AddListener(&g_TimeLeftEvents, "round_end", true); |
|
dvander@1459
|
96 |
SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, &g_TimeLeftEvents, &TimeLeftEvents::LevelInit, true); |
|
dvander@1459
|
97 |
hooked_everything = true; |
|
dvander@1459
|
98 |
|
|
faluco@1441
|
99 |
SM_GET_LATE_IFACE(BINTOOLS, g_pBinTools); |
|
faluco@1441
|
100 |
} |
|
faluco@1441
|
101 |
|
|
faluco@1441
|
102 |
bool CStrike::QueryRunning(char *error, size_t maxlength) |
|
faluco@1441
|
103 |
{ |
|
faluco@1441
|
104 |
SM_CHECK_IFACE(BINTOOLS, g_pBinTools); |
|
faluco@1441
|
105 |
|
|
faluco@1441
|
106 |
return true; |
|
faluco@1441
|
107 |
} |
|
faluco@1441
|
108 |
|
|
faluco@1441
|
109 |
bool CStrike::QueryInterfaceDrop(SMInterface *pInterface) |
|
faluco@1441
|
110 |
{ |
|
faluco@1441
|
111 |
if (pInterface == g_pBinTools) |
|
faluco@1441
|
112 |
{ |
|
faluco@1441
|
113 |
return false; |
|
faluco@1441
|
114 |
} |
|
faluco@1441
|
115 |
|
|
faluco@1441
|
116 |
return IExtensionInterface::QueryInterfaceDrop(pInterface); |
|
faluco@1441
|
117 |
} |
|
faluco@1441
|
118 |
|
|
faluco@1441
|
119 |
void CStrike::NotifyInterfaceDrop(SMInterface *pInterface) |
|
faluco@1441
|
120 |
{ |
|
faluco@1441
|
121 |
g_RegNatives.UnregisterAll(); |
|
faluco@1441
|
122 |
} |