SourceMod SDK  1.7
compat_wrappers.h
1 
32 #ifndef _INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_
33 #define _INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_
34 
35 #include <datamap.h>
36 
37 #if SOURCE_ENGINE >= SE_ORANGEBOX
38  #define CONVAR_REGISTER(object) ConVar_Register(0, object)
39 
40  inline bool IsFlagSet(ConCommandBase *cmd, int flag)
41  {
42  return cmd->IsFlagSet(flag);
43  }
44  inline ConCommandBase *FindCommandBase(const char *name)
45  {
46  return icvar->FindCommandBase(name);
47  }
48  inline ConCommand *FindCommand(const char *name)
49  {
50  return icvar->FindCommand(name);
51  }
52 #else
53  class CCommand
54  {
55  public:
56  inline const char *ArgS() const
57  {
58  return engine->Cmd_Args();
59  }
60  inline int ArgC() const
61  {
62  return engine->Cmd_Argc();
63  }
64  inline const char *Arg(int index) const
65  {
66  return engine->Cmd_Argv(index);
67  }
68 
69  static int MaxCommandLength() { return 512; }
70  };
71 
72  inline bool IsFlagSet(ConCommandBase *cmd, int flag)
73  {
74  return cmd->IsBitSet(flag);
75  }
76  inline ConCommandBase *FindCommandBase(const char *name)
77  {
78  ConCommandBase *pBase = icvar->GetCommands();
79  while (pBase)
80  {
81  if (strcmp(pBase->GetName(), name) == 0)
82  {
83  if (!pBase->IsCommand())
84  {
85  return NULL;
86  }
87 
88  return pBase;
89  }
90  pBase = const_cast<ConCommandBase *>(pBase->GetNext());
91  }
92  return NULL;
93  }
94  inline ConCommand *FindCommand(const char *name)
95  {
96  ConCommandBase *pBase = icvar->GetCommands();
97  while (pBase)
98  {
99  if (strcmp(pBase->GetName(), name) == 0)
100  {
101  if (!pBase->IsCommand())
102  {
103  return NULL;
104  }
105 
106  return static_cast<ConCommand *>(pBase);
107  }
108  pBase = const_cast<ConCommandBase *>(pBase->GetNext());
109  }
110  return NULL;
111  }
112 
113  #define CVAR_INTERFACE_VERSION VENGINE_CVAR_INTERFACE_VERSION
114 
115  #define CONVAR_REGISTER(object) ConCommandBaseMgr::OneTimeInit(object)
116  typedef FnChangeCallback FnChangeCallback_t;
117 #endif //SOURCE_ENGINE >= SE_ORANGEBOX
118 
119 #if SOURCE_ENGINE >= SE_LEFT4DEAD
120  inline int IndexOfEdict(const edict_t *pEdict)
121  {
122  return (int)(pEdict - gpGlobals->pEdicts);
123  }
124  inline edict_t *PEntityOfEntIndex(int iEntIndex)
125  {
126  if (iEntIndex >= 0 && iEntIndex < gpGlobals->maxEntities)
127  {
128  return (edict_t *)(gpGlobals->pEdicts + iEntIndex);
129  }
130  return NULL;
131  }
132  inline int GetTypeDescOffs(typedescription_t *td)
133  {
134  return td->fieldOffset;
135  }
136 #else
137  inline int IndexOfEdict(const edict_t *pEdict)
138  {
139  return engine->IndexOfEdict(pEdict);
140  }
141  inline edict_t *PEntityOfEntIndex(int iEntIndex)
142  {
143  return engine->PEntityOfEntIndex(iEntIndex);
144  }
145  inline int GetTypeDescOffs(typedescription_t *td)
146  {
147  return td->fieldOffset[TD_OFFSET_NORMAL];
148  }
149 #endif //SOURCE_ENGINE >= SE_LEFT4DEAD
150 
151 #if SOURCE_ENGINE == SE_DOTA
152  inline int GetPlayerUserId(edict_t *pEdict)
153  {
154  return engine->GetPlayerUserId(IndexOfEdict(pEdict) - 1);
155  }
156 
157  inline int GetPlayerUserId(int client)
158  {
159  return engine->GetPlayerUserId(client - 1);
160  }
161 #else
162  inline int GetPlayerUserId(edict_t *pEdict)
163  {
164  return engine->GetPlayerUserId(pEdict);
165  }
166 
167  inline int GetPlayerUserId(int client)
168  {
169  return engine->GetPlayerUserId(PEntityOfEntIndex(client));
170  }
171 #endif //SOURCE_ENGINE >= SE_DOTA
172 
173 #endif //_INCLUDE_SOURCEMOD_COMPAT_WRAPPERS_H_
IVEngineServer * engine
Definition: smsdk_ext.cpp:310