|
pred@2224
|
1 |
/** |
|
pred@2224
|
2 |
* vim: set ts=4 : |
|
pred@2224
|
3 |
* ============================================================================= |
|
pred@2224
|
4 |
* SourceMod Sample Extension |
|
pred@2224
|
5 |
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. |
|
pred@2224
|
6 |
* ============================================================================= |
|
pred@2224
|
7 |
* |
|
pred@2224
|
8 |
* This program is free software; you can redistribute it and/or modify it under |
|
pred@2224
|
9 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
pred@2224
|
10 |
* Free Software Foundation. |
|
pred@2224
|
11 |
* |
|
pred@2224
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
pred@2224
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
pred@2224
|
14 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
pred@2224
|
15 |
* details. |
|
pred@2224
|
16 |
* |
|
pred@2224
|
17 |
* You should have received a copy of the GNU General Public License along with |
|
pred@2224
|
18 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
pred@2224
|
19 |
* |
|
pred@2224
|
20 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
pred@2224
|
21 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
pred@2224
|
22 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
pred@2224
|
23 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
pred@2224
|
24 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
pred@2224
|
25 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
pred@2224
|
26 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
pred@2224
|
27 |
* or <http://www.sourcemod.net/license.php>. |
|
pred@2224
|
28 |
* |
|
pred@2224
|
29 |
* Version: $Id$ |
|
pred@2224
|
30 |
*/ |
|
pred@2224
|
31 |
|
|
pred@2224
|
32 |
#ifndef _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_ |
|
pred@2224
|
33 |
#define _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_ |
|
pred@2224
|
34 |
|
|
pred@2224
|
35 |
/** |
|
pred@2224
|
36 |
* @file extension.h |
|
pred@2224
|
37 |
* @brief Sample extension code header. |
|
pred@2224
|
38 |
*/ |
|
pred@2224
|
39 |
|
|
pred@2224
|
40 |
#include "smsdk_ext.h" |
|
pred@2224
|
41 |
#include "StructManager.h" |
|
pred@2224
|
42 |
#include "StructHandle.h" |
|
pred@2224
|
43 |
#include "Struct.h" |
|
pred@2224
|
44 |
|
|
pred@2224
|
45 |
/** |
|
pred@2224
|
46 |
* @brief Sample implementation of the SDK Extension. |
|
pred@2224
|
47 |
* Note: Uncomment one of the pre-defined virtual functions in order to use it. |
|
pred@2224
|
48 |
*/ |
|
pred@2224
|
49 |
class Structs : |
|
pred@2224
|
50 |
public SDKExtension, |
|
pred@2224
|
51 |
public ITextListener_SMC |
|
pred@2224
|
52 |
{ |
|
pred@2224
|
53 |
public: |
|
pred@2224
|
54 |
/** |
|
pred@2224
|
55 |
* @brief This is called after the initial loading sequence has been processed. |
|
pred@2224
|
56 |
* |
|
pred@2224
|
57 |
* @param error Error message buffer. |
|
pred@2224
|
58 |
* @param maxlength Size of error message buffer. |
|
pred@2224
|
59 |
* @param late Whether or not the module was loaded after map load. |
|
pred@2224
|
60 |
* @return True to succeed loading, false to fail. |
|
pred@2224
|
61 |
*/ |
|
pred@2224
|
62 |
virtual bool SDK_OnLoad(char *error, size_t maxlength, bool late); |
|
pred@2224
|
63 |
|
|
pred@2224
|
64 |
/** |
|
pred@2224
|
65 |
* @brief This is called right before the extension is unloaded. |
|
pred@2224
|
66 |
*/ |
|
pred@2224
|
67 |
virtual void SDK_OnUnload(); |
|
pred@2224
|
68 |
|
|
pred@2224
|
69 |
/** |
|
pred@2224
|
70 |
* @brief This is called once all known extensions have been loaded. |
|
pred@2224
|
71 |
* Note: It is is a good idea to add natives here, if any are provided. |
|
pred@2224
|
72 |
*/ |
|
pred@2224
|
73 |
virtual void SDK_OnAllLoaded(); |
|
pred@2224
|
74 |
|
|
pred@2224
|
75 |
/** |
|
pred@2224
|
76 |
* @brief Called when the pause state is changed. |
|
pred@2224
|
77 |
*/ |
|
pred@2224
|
78 |
//virtual void SDK_OnPauseChange(bool paused); |
|
pred@2224
|
79 |
|
|
pred@2224
|
80 |
/** |
|
pred@2224
|
81 |
* @brief this is called when Core wants to know if your extension is working. |
|
pred@2224
|
82 |
* |
|
pred@2224
|
83 |
* @param error Error message buffer. |
|
pred@2224
|
84 |
* @param maxlength Size of error message buffer. |
|
pred@2224
|
85 |
* @return True if working, false otherwise. |
|
pred@2224
|
86 |
*/ |
|
pred@2224
|
87 |
//virtual bool QueryRunning(char *error, size_t maxlength); |
|
pred@2224
|
88 |
public: |
|
pred@2224
|
89 |
#if defined SMEXT_CONF_METAMOD |
|
pred@2224
|
90 |
/** |
|
pred@2224
|
91 |
* @brief Called when Metamod is attached, before the extension version is called. |
|
pred@2224
|
92 |
* |
|
pred@2224
|
93 |
* @param error Error buffer. |
|
pred@2224
|
94 |
* @param maxlength Maximum size of error buffer. |
|
pred@2224
|
95 |
* @param late Whether or not Metamod considers this a late load. |
|
pred@2224
|
96 |
* @return True to succeed, false to fail. |
|
pred@2224
|
97 |
*/ |
|
pred@2224
|
98 |
//virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlength, bool late); |
|
pred@2224
|
99 |
|
|
pred@2224
|
100 |
/** |
|
pred@2224
|
101 |
* @brief Called when Metamod is detaching, after the extension version is called. |
|
pred@2224
|
102 |
* NOTE: By default this is blocked unless sent from SourceMod. |
|
pred@2224
|
103 |
* |
|
pred@2224
|
104 |
* @param error Error buffer. |
|
pred@2224
|
105 |
* @param maxlength Maximum size of error buffer. |
|
pred@2224
|
106 |
* @return True to succeed, false to fail. |
|
pred@2224
|
107 |
*/ |
|
pred@2224
|
108 |
//virtual bool SDK_OnMetamodUnload(char *error, size_t maxlength); |
|
pred@2224
|
109 |
|
|
pred@2224
|
110 |
/** |
|
pred@2224
|
111 |
* @brief Called when Metamod's pause state is changing. |
|
pred@2224
|
112 |
* NOTE: By default this is blocked unless sent from SourceMod. |
|
pred@2224
|
113 |
* |
|
pred@2224
|
114 |
* @param paused Pause state being set. |
|
pred@2224
|
115 |
* @param error Error buffer. |
|
pred@2224
|
116 |
* @param maxlength Maximum size of error buffer. |
|
pred@2224
|
117 |
* @return True to succeed, false to fail. |
|
pred@2224
|
118 |
*/ |
|
pred@2224
|
119 |
//virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlength); |
|
pred@2224
|
120 |
#endif |
|
pred@2224
|
121 |
|
|
pred@2224
|
122 |
public: |
|
pred@2224
|
123 |
//ITextListener_SMC |
|
pred@2224
|
124 |
SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name); |
|
pred@2224
|
125 |
SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value); |
|
pred@2224
|
126 |
SMCResult ReadSMC_LeavingSection(const SMCStates *states); |
|
pred@2224
|
127 |
void ReadSMC_ParseStart(); |
|
pred@2224
|
128 |
|
|
pred@2224
|
129 |
private: |
|
pred@2224
|
130 |
bool m_bInStruct; |
|
pred@2224
|
131 |
StructInfo *m_currentStruct; |
|
pred@2224
|
132 |
bool m_bInMember; |
|
pred@2224
|
133 |
MemberInfo *m_currentMember; |
|
pred@2224
|
134 |
|
|
pred@2224
|
135 |
KTrie<MemberType> m_typeLookup; |
|
pred@2224
|
136 |
}; |
|
pred@2224
|
137 |
|
|
pred@2224
|
138 |
size_t UTIL_Format(char *buffer, size_t maxlength, const char *fmt, ...); |
|
pred@2224
|
139 |
|
|
pred@2224
|
140 |
class StructHandler : public IHandleTypeDispatch |
|
pred@2224
|
141 |
{ |
|
pred@2224
|
142 |
public: |
|
pred@2224
|
143 |
void OnHandleDestroy(HandleType_t type, void *object) |
|
pred@2224
|
144 |
{ |
|
pred@2224
|
145 |
StructHandle *pHandle = (StructHandle *)object; |
|
pred@2224
|
146 |
|
|
pred@2224
|
147 |
if (pHandle->canDelete) |
|
pred@2224
|
148 |
{ |
|
pred@2224
|
149 |
//delete pHandle->data; |
|
pred@2224
|
150 |
} |
|
pred@2224
|
151 |
|
|
pred@2224
|
152 |
delete pHandle; |
|
pred@2224
|
153 |
} |
|
pred@2224
|
154 |
}; |
|
pred@2224
|
155 |
|
|
pred@2224
|
156 |
extern HandleType_t g_StructHandle; |
|
pred@2224
|
157 |
extern StructHandler g_StructHandler; |
|
pred@2224
|
158 |
|
|
pred@2224
|
159 |
extern StructManager g_StructManager; |
|
pred@2224
|
160 |
|
|
pred@2224
|
161 |
extern const sp_nativeinfo_t MyNatives[]; |
|
pred@2224
|
162 |
|
|
pred@2224
|
163 |
extern IGameConfig *conf; |
|
pred@2224
|
164 |
|
|
pred@2224
|
165 |
#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_ |