3 * =============================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEPAWN_BASECONTEXT_H_
33 #define _INCLUDE_SOURCEPAWN_BASECONTEXT_H_
35 #include "sp_vm_api.h"
36 #include "sp_vm_function.h"
39 * :TODO: Make functions allocate as a lump instead of individual allocations!
45 public IPluginContext,
46 public IPluginDebugInfo
49 BaseContext(sp_context_t *ctx);
51 public: //IPluginContext
52 IVirtualMachine *GetVirtualMachine();
53 sp_context_t *GetContext();
55 int SetDebugBreak(SPVM_DEBUGBREAK newpfn, SPVM_DEBUGBREAK *oldpfn);
56 IPluginDebugInfo *GetDebugInfo();
57 int HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr);
58 int HeapPop(cell_t local_addr);
59 int HeapRelease(cell_t local_addr);
60 int FindNativeByName(const char *name, uint32_t *index);
61 int GetNativeByIndex(uint32_t index, sp_native_t **native);
62 uint32_t GetNativesNum();
63 int FindPublicByName(const char *name, uint32_t *index);
64 int GetPublicByIndex(uint32_t index, sp_public_t **publicptr);
65 uint32_t GetPublicsNum();
66 int GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar);
67 int FindPubvarByName(const char *name, uint32_t *index);
68 int GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr);
69 uint32_t GetPubVarsNum();
70 int LocalToPhysAddr(cell_t local_addr, cell_t **phys_addr);
71 int LocalToString(cell_t local_addr, char **addr);
72 int StringToLocal(cell_t local_addr, size_t chars, const char *source);
73 int StringToLocalUTF8(cell_t local_addr, size_t maxbytes, const char *source, size_t *wrtnbytes);
74 int PushCell(cell_t value);
75 int PushCellArray(cell_t *local_addr, cell_t **phys_addr, cell_t array[], unsigned int numcells);
76 int PushString(cell_t *local_addr, char **phys_addr, const char *string);
77 int PushCellsFromArray(cell_t array[], unsigned int numcells);
78 int BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite);
79 int BindNative(const sp_nativeinfo_t *native);
80 int BindNativeToAny(SPVM_NATIVE_FUNC native);
81 int Execute(uint32_t code_addr, cell_t *result);
82 cell_t ThrowNativeErrorEx(int error, const char *msg, ...);
83 cell_t ThrowNativeError(const char *msg, ...);
84 IPluginFunction *GetFunctionByName(const char *public_name);
85 IPluginFunction *GetFunctionById(funcid_t func_id);
86 #if defined SOURCEMOD_BUILD
87 SourceMod::IdentityToken_t *GetIdentity();
88 void SetIdentity(SourceMod::IdentityToken_t *token);
89 cell_t *GetNullRef(SP_NULL_TYPE type);
90 int LocalToStringNULL(cell_t local_addr, char **addr);
92 int BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC native);
93 public: //IPluginDebugInfo
94 int LookupFile(ucell_t addr, const char **filename);
95 int LookupFunction(ucell_t addr, const char **name);
96 int LookupLine(ucell_t addr, uint32_t *line);
98 void SetContext(sp_context_t *_ctx);
100 void SetErrorMessage(const char *msg, va_list ap);
101 void FlushFunctionCache();
102 void RefreshFunctionCache();
105 #if defined SOURCEMOD_BUILD
106 SourceMod::IdentityToken_t *m_pToken;
108 cell_t *m_pNullString;
110 char m_MsgCache[1024];
113 unsigned int m_funcsnum;
115 CFunction **m_priv_funcs;
117 CFunction **m_pub_funcs;
121 #endif //_INCLUDE_SOURCEPAWN_BASECONTEXT_H_