-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.cpp
114 lines (104 loc) · 2.38 KB
/
utils.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
#include "utils.h"
#include "extension.h"
// windows LTCG optimize to const char*
string_t AllocPooledString(const char* pszValue)
{
CBaseEntity* pEntity = ((IServerUnknown*)servertools->FirstEntity())->GetBaseEntity();
static int iNameOffset = -1;
if (iNameOffset == -1)
{
auto* pDataMap = gamehelpers->GetDataMap(pEntity);
assert(pDataMap);
sm_datatable_info_t info;
bool found = gamehelpers->FindDataMapInfo(pDataMap, "m_iName", &info);
assert(found);
iNameOffset = info.actual_offset;
}
string_t* pProp = (string_t*)((intp)pEntity + iNameOffset);
string_t backup = *pProp;
servertools->SetKeyValue(pEntity, "targetname", pszValue);
string_t newString = *pProp;
*pProp = backup;
return newString;
}
void GuessDataPropTypes(typedescription_t* td, cell_t* pSize, cell_t* pType)
{
switch (td->fieldType)
{
case FIELD_TICK:
case FIELD_MODELINDEX:
case FIELD_MATERIALINDEX:
case FIELD_INTEGER:
case FIELD_COLOR32:
{
*pType = PropField_Integer;
*pSize = 32;
return;
}
case FIELD_VECTOR:
case FIELD_POSITION_VECTOR:
{
*pType = PropField_Vector;
*pSize = 96;
return;
}
case FIELD_SHORT:
{
*pType = PropField_Integer;
*pSize = 16;
return;
}
case FIELD_BOOLEAN:
{
*pType = PropField_Integer;
*pSize = 1;
return;
}
case FIELD_CHARACTER:
{
if (td->fieldSize == 1)
{
*pType = PropField_Integer;
*pSize = 8;
}
else
{
*pType = PropField_String;
*pSize = 8 * td->fieldSize;
}
return;
}
case FIELD_MODELNAME:
case FIELD_SOUNDNAME:
case FIELD_STRING:
{
*pSize = sizeof(string_t);
*pType = PropField_String_T;
return;
}
case FIELD_FLOAT:
case FIELD_TIME:
{
*pType = PropField_Float;
*pSize = 32;
return;
}
case FIELD_EHANDLE:
{
*pType = PropField_Entity;
*pSize = 32;
return;
}
case FIELD_CUSTOM:
{
if ((td->flags & FTYPEDESC_OUTPUT) == FTYPEDESC_OUTPUT)
{
*pType = PropField_Variant;
*pSize = 0;
return;
}
}
}
*pType = PropField_Unsupported;
*pSize = 0;
}