Skip to content

Commit 0c6f1d0

Browse files
committed
Add native 'IsCustomDamageTypeDOT'
1 parent 404f934 commit 0c6f1d0

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

gamedata/tf2.utils.nosoop.txt

+10
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@
5656
}
5757
}
5858
}
59+
"Keys"
60+
{
61+
// space-separated set of hex values corresponding to damage types that are 'damage over time'
62+
// the game inlines this functionality so we'll have to implement this ourselves
63+
// 0x03 = TF_CUSTOM_BURNING
64+
// 0x08 = TF_CUSTOM_BURNING_FLARE
65+
// 0x11 = TF_CUSTOM_BURNING_ARROW
66+
// 0x22 = TF_CUSTOM_BLEEDING
67+
"DOTDamageTypes" "03 08 11 22"
68+
}
5969
"Offsets"
6070
{
6171
// virtual offsets

scripting/include/tf2utils.inc

+11
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,17 @@ native void TF2Util_UpdatePlayerSpeed(int client, bool immediate = false);
339339
native bool TF2Util_IsPointInRespawnRoom(const float position[3],
340340
int entity = INVALID_ENT_REFERENCE, bool bRestrictToSameTeam = false);
341341

342+
/**
343+
* Returns whether or not the given custom damage type is for a "damage over time" effect.
344+
* This is provided to allow plugins to identify periodic damage events without hardcoding that
345+
* information themselves.
346+
*
347+
* @param damagecustom Custom damage type. This is provided by the SDKHooks OnTakeDamage
348+
* set of hooks as 'damagecustom', among other places.
349+
* @return True if the given value matches a known DOT effect; false otherwise.
350+
*/
351+
native bool TF2Util_IsCustomDamageTypeDOT(int damagecustom);
352+
342353
/**
343354
* Given the address of a CTFPlayerShared instance, returns the player associated with it.
344355
*

scripting/tf2utils.sp

+37-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <stocksoup/convars>
1313
#include <stocksoup/memory>
1414

15-
#define PLUGIN_VERSION "1.0.0"
15+
#define PLUGIN_VERSION "1.1.0"
1616
public Plugin myinfo = {
1717
name = "TF2 Utils",
1818
author = "nosoop",
@@ -67,6 +67,9 @@ int sizeof_TFCondInfo;
6767

6868
int g_nConditions;
6969

70+
#define MAX_DOT_DAMAGE_TYPES 16
71+
int g_nDOTDamageTypes, g_DOTDamageTypes[MAX_DOT_DAMAGE_TYPES];
72+
7073
public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) {
7174
RegPluginLibrary("nosoop_tf2utils");
7275

@@ -114,6 +117,8 @@ public APLRes AskPluginLoad2(Handle self, bool late, char[] error, int maxlen) {
114117

115118
CreateNative("TF2Util_IsPointInRespawnRoom", Native_IsPointInRespawnRoom);
116119

120+
CreateNative("TF2Util_IsCustomDamageTypeDOT", Native_IsCustomDamageTypeDOT);
121+
117122
CreateNative("TF2Util_GetPlayerFromSharedAddress", Native_GetPlayerFromSharedAddress);
118123

119124
// deprecated name for backcompat
@@ -364,6 +369,26 @@ public void OnPluginStart() {
364369
offs_CTFPlayer_flLastDamageTime = GameConfGetAddressOffset(hGameConf,
365370
"CTFPlayer::m_flLastDamageTime");
366371

372+
// allocate 5 chars for each value + delimiter
373+
char damageTypes[MAX_DOT_DAMAGE_TYPES * 5];
374+
if (!GameConfGetKeyValue(hGameConf, "DOTDamageTypes", damageTypes, sizeof(damageTypes))) {
375+
SetFailState("Could not retrieve DOTDamageTypes values");
376+
} else for (int c, i, res; (i = StringToIntEx(damageTypes[c], res, 0x10)); c += i) {
377+
/**
378+
* Parse numeric values from the list.
379+
* I don't expect the game to ever have as many DOT damage types as the hardcoded
380+
* limit of 16 I've initally assigned here, but if it does, don't silently fail.
381+
*/
382+
if (g_nDOTDamageTypes == MAX_DOT_DAMAGE_TYPES) {
383+
SetFailState("Not enough space allocated to parse damage types (limit %d) - "
384+
... "update MAX_DOT_DAMAGE_TYPES and recompile", MAX_DOT_DAMAGE_TYPES);
385+
} else if (res == 0) {
386+
continue;
387+
}
388+
389+
g_DOTDamageTypes[g_nDOTDamageTypes++] = res;
390+
}
391+
367392
delete hGameConf;
368393

369394
CreateVersionConVar("tf2utils_version", "TF2 Utils version.");
@@ -865,6 +890,17 @@ any Native_SetPlayerRespawnTimeOverride(Handle plugin, int numParams) {
865890
return;
866891
}
867892

893+
// bool(int damagecustom);
894+
any Native_IsCustomDamageTypeDOT(Handle plugin, int numParams) {
895+
int damagecustom = GetNativeCell(1);
896+
for (int i; i < g_nDOTDamageTypes; i++) {
897+
if (g_DOTDamageTypes[i] == damagecustom) {
898+
return true;
899+
}
900+
}
901+
return false;
902+
}
903+
868904
// int(Address pShared);
869905
any Native_GetPlayerFromSharedAddress(Handle plugin, int numParams) {
870906
Address pShared = GetNativeCell(1);

0 commit comments

Comments
 (0)