Repository navigation
Expand file tree
/
Copy pathnatives.cpp
More file actions
201 lines (149 loc) · 6.78 KB
/
Copy pathnatives.cpp
File metadata and controls
201 lines (149 loc) · 6.78 KB
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
/**
* vim: set ts=4 sw=4 tw=99 noet :
* ======================================================
* TF2 Dynamic Schema Injector
* Written by nosoop
* ======================================================
*/
#include <stdio.h>
#include "mmsplugin.h"
#include "natives.h"
#include "econmanager.h"
HandleType_t g_EconInjectedAttributeType{};
EconInjectedAttributeHandler g_EconInjectedAttributeHandler;
void EconInjectedAttributeHandler::OnHandleDestroy(HandleType_t type, void* object) {
if (type == g_EconInjectedAttributeType) {
delete reinterpret_cast<AutoKeyValues*>(object);
}
}
cell_t sm_EconAttributeCreate(IPluginContext *pContext, const cell_t *params) {
AutoKeyValues *pContainer = new AutoKeyValues();
return g_pHandleSys->CreateHandle(g_EconInjectedAttributeType, pContainer,
pContext->GetIdentity(), myself->GetIdentity(), NULL);
}
// void TF2EconDynAttribute.SetClass(const char[] attrClass)
cell_t sm_EconAttributeSetClass(IPluginContext *pContext, const cell_t *params) {
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
HandleError err;
Handle_t hndl = static_cast<Handle_t>(params[1]);
AutoKeyValues *pContainer = nullptr;
if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
}
char *value;
pContext->LocalToString(params[2], &value);
(*pContainer)->SetString("attribute_class", value);
return 0;
}
// void TF2EconDynAttribute.SetName(const char[] attrName)
cell_t sm_EconAttributeSetName(IPluginContext *pContext, const cell_t *params) {
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
HandleError err;
Handle_t hndl = static_cast<Handle_t>(params[1]);
AutoKeyValues *pContainer = nullptr;
if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
}
char *value;
pContext->LocalToString(params[2], &value);
(*pContainer)->SetString("name", value);
return 0;
}
// void TF2EconDynAttribute.SetDescriptionFormat(const char[] attrDescFmt)
cell_t sm_EconAttributeSetDescriptionFormat(IPluginContext *pContext, const cell_t *params) {
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
HandleError err;
Handle_t hndl = static_cast<Handle_t>(params[1]);
AutoKeyValues *pContainer = nullptr;
if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
}
char *value;
pContext->LocalToString(params[2], &value);
(*pContainer)->SetString("description_format", value);
return 0;
}
// void TF2EconDynAttribute.SetCustom(const char[] key, const char[] value)
cell_t sm_EconAttributeSetCustomKeyValue(IPluginContext *pContext, const cell_t *params) {
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
HandleError err;
Handle_t hndl = static_cast<Handle_t>(params[1]);
AutoKeyValues *pContainer = nullptr;
if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
}
char *key, *value;
pContext->LocalToString(params[2], &key);
pContext->LocalToString(params[3], &value);
(*pContainer)->SetString(key, value);
return 0;
}
// void TF2EconDynAttribute.SetDefIndex(int attrdef)
cell_t sm_EconAttributeSetDefIndex(IPluginContext *pContext, const cell_t *params) {
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
HandleError err;
Handle_t hndl = static_cast<Handle_t>(params[1]);
AutoKeyValues *pContainer = nullptr;
if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
}
(*pContainer)->SetName(std::to_string(params[2]).c_str());
return 0;
}
// void TF2EconDynAttribute.ClearDefIndex()
cell_t sm_EconAttributeClearDefIndex(IPluginContext *pContext, const cell_t *params) {
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
HandleError err;
Handle_t hndl = static_cast<Handle_t>(params[1]);
AutoKeyValues *pContainer = nullptr;
if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
}
(*pContainer)->SetName("auto");
return 0;
}
// bool TF2EconDynAttribute.Register()
cell_t sm_EconAttributeRegister(IPluginContext *pContext, const cell_t *params) {
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
HandleError err;
Handle_t hndl = static_cast<Handle_t>(params[1]);
AutoKeyValues *pContainer = nullptr;
if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
}
if (!g_EconManager.RegisterAttribute(*pContainer) || !g_EconManager.InsertOrReplaceAttribute(*pContainer)) {
return false;
}
return true;
}
// void TF2EconDynAttribute.Clear();
cell_t sm_EconAttributeClear(IPluginContext *pContext, const cell_t *params) {
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
HandleError err;
Handle_t hndl = static_cast<Handle_t>(params[1]);
AutoKeyValues *pContainer = nullptr;
if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
}
KeyValues::AutoDelete empty("auto");
pContainer->Assign(empty);
return 0;
}
// bool TF2EconDynAttribute.Import(const char[] name);
cell_t sm_EconAttributeImport(IPluginContext *pContext, const cell_t *params) {
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
HandleError err;
Handle_t hndl = static_cast<Handle_t>(params[1]);
AutoKeyValues *pContainer = nullptr;
if ((err = g_pHandleSys->ReadHandle(hndl, g_EconInjectedAttributeType, &sec, (void**) &pContainer)) != HandleError_None) {
return pContext->ThrowNativeError("Invalid TF2EconDynAttribute handle %x (error: %d)", hndl, err);
}
char *name;
pContext->LocalToString(params[2], &name);
KeyValues *pKeyValues = g_EconManager.GetAttributeDefinitionKeyValuesByName(name);
if (!pKeyValues) {
return false;
}
pContainer->Assign(pKeyValues);
return true;
}