forked from alliedmodders/sourcepawn
/
base-context.cpp
251 lines (214 loc) · 4.58 KB
/
base-context.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
// vim: set sts=2 ts=8 sw=2 tw=99 et:
//
// Copyright (C) 2006-2015 AlliedModders LLC
//
// This file is part of SourcePawn. SourcePawn is free software: you can
// redistribute it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// You should have received a copy of the GNU General Public License along with
// SourcePawn. If not, see http://www.gnu.org/licenses/.
//
#include "base-context.h"
#include "environment.h"
using namespace sp;
using namespace SourcePawn;
BasePluginContext::BasePluginContext()
: env_(Environment::get())
{
}
BasePluginContext::~BasePluginContext()
{
}
void
BasePluginContext::SetKey(int k, void* value)
{
if (k < 1 || k > 4)
return;
m_keys[k - 1] = value;
m_keys_set[k - 1] = true;
}
bool
BasePluginContext::GetKey(int k, void** value)
{
if (k < 1 || k > 4 || m_keys_set[k - 1] == false)
return false;
*value = m_keys[k - 1];
return true;
}
SourceMod::IdentityToken_t*
BasePluginContext::GetIdentity()
{
SourceMod::IdentityToken_t* tok;
if (GetKey(1, (void**)&tok))
return tok;
return NULL;
}
IVirtualMachine*
BasePluginContext::GetVirtualMachine()
{
return NULL;
}
sp_context_t*
BasePluginContext::GetContext()
{
return reinterpret_cast<sp_context_t*>((IPluginContext * )this);
}
bool
BasePluginContext::IsDebugging()
{
return true;
}
int
BasePluginContext::SetDebugBreak(SPVM_DEBUGBREAK newpfn, SPVM_DEBUGBREAK* oldpfn)
{
return SP_ERROR_ABORTED;
}
IPluginDebugInfo*
BasePluginContext::GetDebugInfo()
{
return NULL;
}
int
BasePluginContext::Execute(uint32_t code_addr, cell_t* result)
{
return SP_ERROR_ABORTED;
}
int
BasePluginContext::BindNatives(const sp_nativeinfo_t* natives, unsigned int num, int overwrite)
{
return SP_ERROR_ABORTED;
}
int
BasePluginContext::BindNative(const sp_nativeinfo_t* native)
{
return SP_ERROR_ABORTED;
}
int
BasePluginContext::BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC func)
{
return SP_ERROR_ABORTED;
}
int
BasePluginContext::BindNativeToAny(SPVM_NATIVE_FUNC native)
{
return SP_ERROR_ABORTED;
}
int
BasePluginContext::PushCell(cell_t value)
{
return SP_ERROR_ABORTED;
}
int
BasePluginContext::PushCellsFromArray(cell_t array[], unsigned int numcells)
{
return SP_ERROR_ABORTED;
}
int
BasePluginContext::PushCellArray(cell_t* local_addr, cell_t** phys_addr, cell_t array[], unsigned int numcells)
{
return SP_ERROR_ABORTED;
}
int
BasePluginContext::PushString(cell_t* local_addr, char** phys_addr, const char* string)
{
return SP_ERROR_ABORTED;
}
int
BasePluginContext::Execute2(IPluginFunction* function, const cell_t* params, unsigned int num_params, cell_t* result)
{
ReportErrorNumber(SP_ERROR_ABORTED);
return SP_ERROR_ABORTED;
}
ISourcePawnEngine2*
BasePluginContext::APIv2()
{
return env_->APIv2();
}
void
BasePluginContext::ReportError(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
env_->ReportErrorVA(fmt, ap);
va_end(ap);
}
void
BasePluginContext::ReportErrorVA(const char* fmt, va_list ap)
{
env_->ReportErrorVA(fmt, ap);
}
void
BasePluginContext::ReportFatalError(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
env_->ReportErrorVA(SP_ERROR_FATAL, fmt, ap);
va_end(ap);
}
void
BasePluginContext::ReportFatalErrorVA(const char* fmt, va_list ap)
{
env_->ReportErrorVA(SP_ERROR_FATAL, fmt, ap);
}
void
BasePluginContext::ReportErrorNumber(int error)
{
env_->ReportError(error);
}
void
BasePluginContext::ClearLastNativeError()
{
if (env_->hasPendingException())
env_->clearPendingException();
}
cell_t
BasePluginContext::ThrowNativeErrorEx(int error, const char* msg, ...)
{
va_list ap;
va_start(ap, msg);
if (msg)
env_->ReportErrorVA(error, msg, ap);
else
env_->ReportError(error);
va_end(ap);
return 0;
}
cell_t
BasePluginContext::ThrowNativeError(const char* msg, ...)
{
va_list ap;
va_start(ap, msg);
env_->ReportErrorVA(SP_ERROR_NATIVE, msg, ap);
va_end(ap);
return 0;
}
int
BasePluginContext::GetLastNativeError()
{
Environment* env = env_;
if (!env->hasPendingException())
return SP_ERROR_NONE;
return env->getPendingExceptionCode();
}
cell_t
BasePluginContext::BlamePluginError(SourcePawn::IPluginFunction* pf, const char* msg, ...)
{
va_list ap;
va_start(ap, msg);
env_->BlamePluginErrorVA(pf, msg, ap);
va_end(ap);
return 0;
}
IFrameIterator*
BasePluginContext::CreateFrameIterator()
{
FrameIterator* it = new FrameIterator();
return it;
}
void
BasePluginContext::DestroyFrameIterator(IFrameIterator* it)
{
delete static_cast<FrameIterator*>(it);
}