-
Notifications
You must be signed in to change notification settings - Fork 33
/
weaponnatives.cpp
253 lines (229 loc) · 7.77 KB
/
weaponnatives.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/**
* vim: set ts=4 :
* =============================================================================
* Left 4 Downtown 2 SourceMod Extension
* Copyright (C) 2010 Michael "ProdigySim" Busby.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* As a special exception, AlliedModders LLC gives you permission to link the
* code of this program (as well as its derivative works) to "Half-Life 2," the
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
* by the Valve Corporation. You must obey the GNU General Public License in
* all respects for all other code used. Additionally, AlliedModders LLC grants
* this exception to all derivative works. AlliedModders LLC defines further
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
* or <http://www.sourcemod.net/license.php>.
*
* Version: $Id$
*/
#include "extension.h"
#include "vglobals.h"
enum L4D2IntWeaponAttributes
{
L4D2IWA_Damage,
L4D2IWA_Bullets,
L4D2IWA_ClipSize
};
enum L4D2FloatWeaponAttributes
{
L4D2FWA_MaxPlayerSpeed,
L4D2FWA_SpreadPerShot,
L4D2FWA_MaxSpread,
L4D2FWA_SpreadDecay,
L4D2FWA_MinDuckingSpread,
L4D2FWA_MinStandingSpread,
L4D2FWA_MinInAirSpread,
L4D2FWA_MaxMovementSpread,
L4D2FWA_PenetrationNumLayers,
L4D2FWA_PenetrationPower,
L4D2FWA_PenetrationMaxDist,
L4D2FWA_CharPenetrationMaxDist,
L4D2FWA_Range,
L4D2FWA_RangeModifier,
L4D2FWA_CycleTime,
L4D2FWA_PelletScatterPitch,
L4D2FWA_PelletScatterYaw
};
int * IntIdToAttr(CTerrorWeaponInfo *pInfo, int id)
{
if(pInfo == NULL) return NULL;
switch(id)
{
case L4D2IWA_Damage:
return &pInfo->m_iDamage;
case L4D2IWA_Bullets:
return &pInfo->m_iBullets;
case L4D2IWA_ClipSize:
return &pInfo->iMaxClip1;
default:
return NULL;
}
}
float * FloatIdToAttr(CTerrorWeaponInfo *pInfo, int id)
{
if(pInfo == NULL) return NULL;
switch(id)
{
case L4D2FWA_MaxPlayerSpeed:
return &pInfo->m_fMaxPlayerSpeed;
case L4D2FWA_SpreadPerShot:
return &pInfo->m_fSpreadPerShot;
case L4D2FWA_MaxSpread:
return &pInfo->m_fMaxSpread;
case L4D2FWA_SpreadDecay:
return &pInfo->m_fSpreadDecay;
case L4D2FWA_MinDuckingSpread:
return &pInfo->m_fMinDuckingSpread;
case L4D2FWA_MinStandingSpread:
return &pInfo->m_fMinStandingSpread;
case L4D2FWA_MinInAirSpread:
return &pInfo->m_fMinInAirSpread;
case L4D2FWA_MaxMovementSpread:
return &pInfo->m_fMaxMovementSpread;
case L4D2FWA_PenetrationNumLayers:
return &pInfo->m_fPenetrationNumLayers;
case L4D2FWA_PenetrationPower:
return &pInfo->m_fPenetrationPower;
case L4D2FWA_PenetrationMaxDist:
return &pInfo->m_fPenetrationMaxDistance;
case L4D2FWA_CharPenetrationMaxDist:
return &pInfo->m_fCharacterPenetrationMaxDistance;
case L4D2FWA_Range:
return &pInfo->m_fRange;
case L4D2FWA_RangeModifier:
return &pInfo->m_fRangeModifier;
case L4D2FWA_CycleTime:
return &pInfo->m_fCycleTime;
case L4D2FWA_PelletScatterPitch:
return &pInfo->m_fPelletScatterPitch;
case L4D2FWA_PelletScatterYaw:
return &pInfo->m_fPelletScatterYaw;
default:
return NULL;
}
}
/*************************************
WeaponInfo Natives
***********************************/
// native bool:L4D2_IsValidWeapon(const String:weaponName[]);
cell_t L4D2_IsValidWeapon(IPluginContext *pContext, const cell_t *params)
{
if (g_pWeaponInfoDatabase == NULL)
{
return pContext->ThrowNativeError("WeaponInfoDatabase unavailable or unsupported. File a bug report.");
}
char * weapon = NULL;
pContext->LocalToString(params[1], &weapon);
return g_pWeaponInfoDatabase->IsValidIndex(g_pWeaponInfoDatabase->Find(weapon));
}
// native L4D2_GetIntWeaponAttribute(const String:weaponName[], L4D2IntWeaponAttribute:attr);
cell_t L4D2_GetIntWeaponAttribute(IPluginContext *pContext, const cell_t *params)
{
if (g_pWeaponInfoDatabase == NULL)
{
return pContext->ThrowNativeError("WeaponInfoDatabase unavailable or unsupported. File a bug report.");
}
char * weapon = NULL;
pContext->LocalToString(params[1], &weapon);
int iIndex = g_pWeaponInfoDatabase->Find(weapon);
if (!g_pWeaponInfoDatabase->IsValidIndex(iIndex))
{
return pContext->ThrowNativeError("Invalid weapon name or weapon unavailable");
}
CTerrorWeaponInfo *pInfo = g_pWeaponInfoDatabase->Element(iIndex);
int * attr = IntIdToAttr(pInfo, params[2]);
if(attr == NULL)
{
return pContext->ThrowNativeError("Invalid attribute id");
}
return *attr;
}
// native Float:L4D2_GetFloatWeaponAttribute(const String:weaponName[], L4D2IntWeaponAttribute:attr);
cell_t L4D2_GetFloatWeaponAttribute(IPluginContext *pContext, const cell_t *params)
{
if (g_pWeaponInfoDatabase == NULL)
{
return pContext->ThrowNativeError("WeaponInfoDatabase unavailable or unsupported. File a bug report.");
}
char * weapon = NULL;
pContext->LocalToString(params[1], &weapon);
int iIndex = g_pWeaponInfoDatabase->Find(weapon);
if (!g_pWeaponInfoDatabase->IsValidIndex(iIndex))
{
return pContext->ThrowNativeError("Invalid weapon name or weapon unavailable");
}
CTerrorWeaponInfo *pInfo = g_pWeaponInfoDatabase->Element(iIndex);
float * attr = FloatIdToAttr(pInfo, params[2]);
if(attr == NULL)
{
return pContext->ThrowNativeError("Invalid attribute id");
}
return sp_ftoc(*attr);
}
// native L4D2_SetIntWeaponAttribute(const String:weaponName[], L4D2IntWeaponAttribute:attr, value);
cell_t L4D2_SetIntWeaponAttribute(IPluginContext *pContext, const cell_t *params)
{
if (g_pWeaponInfoDatabase == NULL)
{
return pContext->ThrowNativeError("WeaponInfoDatabase unavailable or unsupported. File a bug report.");
}
char * weapon = NULL;
pContext->LocalToString(params[1], &weapon);
int iIndex = g_pWeaponInfoDatabase->Find(weapon);
if (!g_pWeaponInfoDatabase->IsValidIndex(iIndex))
{
return pContext->ThrowNativeError("Invalid weapon name or weapon unavailable");
}
CTerrorWeaponInfo *pInfo = g_pWeaponInfoDatabase->Element(iIndex);
int * attr = IntIdToAttr(pInfo, params[2]);
if(attr == NULL)
{
return pContext->ThrowNativeError("Invalid attribute id");
}
*attr=params[3];
return 0;
}
// native Float:L4D2_SetFloatWeaponAttribute(const String:weaponName[], L4D2IntWeaponAttribute:attr, Float:value);
cell_t L4D2_SetFloatWeaponAttribute(IPluginContext *pContext, const cell_t *params)
{
if (g_pWeaponInfoDatabase == NULL)
{
return pContext->ThrowNativeError("WeaponInfoDatabase unavailable or unsupported. File a bug report.");
}
char * weapon = NULL;
pContext->LocalToString(params[1], &weapon);
int iIndex = g_pWeaponInfoDatabase->Find(weapon);
if (!g_pWeaponInfoDatabase->IsValidIndex(iIndex))
{
return pContext->ThrowNativeError("Invalid weapon name or weapon unavailable");
}
CTerrorWeaponInfo *pInfo = g_pWeaponInfoDatabase->Element(iIndex);
float * attr = FloatIdToAttr(pInfo, params[2]);
if(attr == NULL)
{
return pContext->ThrowNativeError("Invalid attribute id");
}
*attr=sp_ctof(params[3]);
return 0;
}
sp_nativeinfo_t g_L4DoWeaponNatives[] =
{
{"L4D2_IsValidWeapon", L4D2_IsValidWeapon},
{"L4D2_GetIntWeaponAttribute", L4D2_GetIntWeaponAttribute},
{"L4D2_GetFloatWeaponAttribute", L4D2_GetFloatWeaponAttribute},
{"L4D2_SetIntWeaponAttribute", L4D2_SetIntWeaponAttribute},
{"L4D2_SetFloatWeaponAttribute", L4D2_SetFloatWeaponAttribute},
{NULL, NULL}
};