From 2129bb6d92168c73e468d6f7abc086c8a91db80b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 25 Jan 2007 06:21:20 +0000 Subject: [PATCH] changed the API - funcid_t is now index only rather than a code address --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40353 --- core/vm/sp_vm_basecontext.cpp | 47 ++++------------------------------- core/vm/sp_vm_basecontext.h | 2 +- core/vm/sp_vm_function.cpp | 10 ++++---- core/vm/sp_vm_function.h | 6 ++--- plugins/include/admin.inc | 1 + public/IAdminSystem.h | 1 + public/sourcepawn/sp_vm_api.h | 5 ++-- 7 files changed, 18 insertions(+), 54 deletions(-) diff --git a/core/vm/sp_vm_basecontext.cpp b/core/vm/sp_vm_basecontext.cpp index 8e132a4e..ed6ca5c9 100644 --- a/core/vm/sp_vm_basecontext.cpp +++ b/core/vm/sp_vm_basecontext.cpp @@ -128,7 +128,7 @@ IPluginDebugInfo *BaseContext::GetDebugInfo() return this; } -int BaseContext::Execute(funcid_t funcid, cell_t *result) +int BaseContext::Execute(uint32_t code_addr, cell_t *result) { if (!m_Runnable) { @@ -138,25 +138,8 @@ int BaseContext::Execute(funcid_t funcid, cell_t *result) IVirtualMachine *vm = (IVirtualMachine *)ctx->vmbase; uint32_t pushcount = ctx->pushcount; - uint32_t code_addr; int err; - if (funcid & 1) - { - sp_public_t *pubfunc; - if ((err=GetPublicByIndex((funcid>>1), &pubfunc)) != SP_ERROR_NONE) - { - return err; - } - code_addr = pubfunc->code_offs; - } else { -#if 0 - code_addr = funcid >> 1; -#endif - assert(false); - return SP_ERROR_INVALID_ADDRESS; - } - PushCell(pushcount++); ctx->pushcount = 0; @@ -331,25 +314,6 @@ int BaseContext::FindNativeByName(const char *name, uint32_t *index) high = ctx->plugin->info.natives_num - 1; -#if 0 - while (low <= high) - { - mid = (low + high) / 2; - diff = strcmp(ctx->natives[mid].name, name); - if (diff == 0) - { - if (index) - { - *index = mid; - } - return SP_ERROR_NONE; - } else if (diff < 0) { - low = mid + 1; - } else { - high = mid - 1; - } - } -#else for (uint32_t i=0; iplugin->info.natives_num; i++) { if (strcmp(ctx->natives[i].name, name) == 0) @@ -361,7 +325,6 @@ int BaseContext::FindNativeByName(const char *name, uint32_t *index) return SP_ERROR_NONE; } } -#endif return SP_ERROR_NOT_FOUND; } @@ -863,7 +826,6 @@ int BaseContext::LookupLine(ucell_t addr, uint32_t *line) IPluginFunction *BaseContext::GetFunctionById(funcid_t func_id) { CFunction *pFunc = NULL; - funcid_t save = func_id; if (func_id & 1) { @@ -875,10 +837,11 @@ IPluginFunction *BaseContext::GetFunctionById(funcid_t func_id) pFunc = m_pub_funcs[func_id]; if (!pFunc) { - m_pub_funcs[func_id] = new CFunction(save, this); + m_pub_funcs[func_id] = new CFunction(ctx->publics[func_id].code_offs, this); pFunc = m_pub_funcs[func_id]; } } else { + /* :TODO: currently not used */ #if 0 func_id >>= 1; unsigned int index; @@ -892,7 +855,7 @@ IPluginFunction *BaseContext::GetFunctionById(funcid_t func_id) m_priv_funcs[func_id] = new CFunction(save, this); pFunc = m_priv_funcs[func_id]; } -#endif +#endif 0 assert(false); } @@ -915,7 +878,7 @@ IPluginFunction *BaseContext::GetFunctionByName(const char *public_name) GetPublicByIndex(index, &pub); if (pub) { - m_pub_funcs[index] = new CFunction(pub->funcid, this); + m_pub_funcs[index] = new CFunction(pub->code_offs, this); } pFunc = m_pub_funcs[index]; } diff --git a/core/vm/sp_vm_basecontext.h b/core/vm/sp_vm_basecontext.h index d2625686..8f9f1239 100644 --- a/core/vm/sp_vm_basecontext.h +++ b/core/vm/sp_vm_basecontext.h @@ -47,7 +47,7 @@ namespace SourcePawn virtual int BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite); virtual int BindNative(const sp_nativeinfo_t *native); virtual int BindNativeToAny(SPVM_NATIVE_FUNC native); - virtual int Execute(funcid_t funcid, cell_t *result); + virtual int Execute(uint32_t code_addr, cell_t *result); virtual void ThrowNativeErrorEx(int error, const char *msg, ...); virtual cell_t ThrowNativeError(const char *msg, ...); virtual IPluginFunction *GetFunctionByName(const char *public_name); diff --git a/core/vm/sp_vm_function.cpp b/core/vm/sp_vm_function.cpp index 523a85a3..13b419b4 100644 --- a/core/vm/sp_vm_function.cpp +++ b/core/vm/sp_vm_function.cpp @@ -5,9 +5,9 @@ * FUNCTION CALLING * ********************/ -void CFunction::Set(funcid_t funcid, IPluginContext *plugin) +void CFunction::Set(uint32_t code_addr, IPluginContext *plugin) { - m_funcid = funcid; + m_codeaddr = code_addr; m_pContext = plugin; m_curparam = 0; m_errorstate = SP_ERROR_NONE; @@ -20,7 +20,7 @@ int CFunction::CallFunction(const cell_t *params, unsigned int num_params, cell_ m_pContext->PushCell(params[num_params]); } - return m_pContext->Execute(m_funcid, result); + return m_pContext->Execute(m_codeaddr, result); } IPluginContext *CFunction::GetParentContext() @@ -28,8 +28,8 @@ IPluginContext *CFunction::GetParentContext() return m_pContext; } -CFunction::CFunction(funcid_t funcid, IPluginContext *plugin) : - m_funcid(funcid), m_pContext(plugin), m_curparam(0), +CFunction::CFunction(uint32_t code_addr, IPluginContext *plugin) : + m_codeaddr(code_addr), m_pContext(plugin), m_curparam(0), m_errorstate(SP_ERROR_NONE) { } diff --git a/core/vm/sp_vm_function.h b/core/vm/sp_vm_function.h index ad688c1c..d94df739 100644 --- a/core/vm/sp_vm_function.h +++ b/core/vm/sp_vm_function.h @@ -19,7 +19,7 @@ class CFunction : public IPluginFunction { friend class SourcePawnEngine; public: - CFunction(funcid_t funcid, IPluginContext *pContext); + CFunction(uint32_t code_addr, IPluginContext *pContext); public: virtual int PushCell(cell_t cell); virtual int PushCellByRef(cell_t *cell, int flags); @@ -34,7 +34,7 @@ public: virtual int CallFunction(const cell_t *params, unsigned int num_params, cell_t *result); virtual IPluginContext *GetParentContext(); public: - void Set(funcid_t funcid, IPluginContext *plugin); + void Set(uint32_t code_addr, IPluginContext *plugin); private: int _PushString(const char *string, int sz_flags, int cp_flags, size_t len); inline int SetError(int err) @@ -43,7 +43,7 @@ private: return err; } private: - funcid_t m_funcid; + uint32_t m_codeaddr; IPluginContext *m_pContext; cell_t m_params[SP_MAX_EXEC_PARAMS]; ParamInfo m_info[SP_MAX_EXEC_PARAMS]; diff --git a/plugins/include/admin.inc b/plugins/include/admin.inc index 99a8d04a..df2d83d0 100644 --- a/plugins/include/admin.inc +++ b/plugins/include/admin.inc @@ -19,6 +19,7 @@ enum AdminFlag Admin_Password, /* Set a server password */ Admin_RCON, /* Use RCON */ Admin_Cheats, /* Change sv_cheats and use its commands */ + Admin_Root, /* Root access */ /* --- */ AdminFlags_TOTAL, }; diff --git a/public/IAdminSystem.h b/public/IAdminSystem.h index bbf02632..f2c80e8b 100644 --- a/public/IAdminSystem.h +++ b/public/IAdminSystem.h @@ -44,6 +44,7 @@ namespace SourceMod Admin_Password, /* Set a server password */ Admin_RCON, /* Use RCON */ Admin_Cheats, /* Change sv_cheats and use its commands */ + Admin_Root, /* All access by default */ /* --- */ AdminFlags_TOTAL, }; diff --git a/public/sourcepawn/sp_vm_api.h b/public/sourcepawn/sp_vm_api.h index a8232f6e..41a7d09b 100644 --- a/public/sourcepawn/sp_vm_api.h +++ b/public/sourcepawn/sp_vm_api.h @@ -461,12 +461,11 @@ namespace SourcePawn /** * @brief Executes a function ID located in this context. * - * @param funcid Function id to execute. + * @param code_addr Address to execute at. * @param result Pointer to store the return value (required). * @return Error code (if any) from the VM. */ - virtual int Execute(uint32_t funcid, cell_t *result) =0; - + virtual int Execute(uint32_t code_addr, cell_t *result) =0; /** * @brief Throws a error and halts any current execution.