From 6acaaac7692561c19a544c505d79917d7ecad70f Mon Sep 17 00:00:00 2001 From: David Anderson Date: Fri, 15 Jun 2007 20:23:40 +0000 Subject: [PATCH] added a hacky way to get NULL references --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40944 --- core/sourcemod.cpp | 3 ++- core/vm/sp_vm_basecontext.cpp | 21 +++++++++++++++++++++ core/vm/sp_vm_basecontext.h | 2 ++ plugins/include/core.inc | 10 ++++++---- public/sourcepawn/sp_vm_api.h | 21 ++++++++++++++++++++- 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index d21467a5..2544bde1 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -200,7 +200,8 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late } unsigned int api = g_pVM->GetAPIVersion(); - if (api != SOURCEPAWN_VM_API_VERSION) + /* :TODO: clean this up (see amb398) */ + if (api > SOURCEPAWN_VM_API_VERSION || api < 2) { ShutdownJIT(); if (error && maxlength) diff --git a/core/vm/sp_vm_basecontext.cpp b/core/vm/sp_vm_basecontext.cpp index dbd4f07a..da987ed5 100644 --- a/core/vm/sp_vm_basecontext.cpp +++ b/core/vm/sp_vm_basecontext.cpp @@ -72,6 +72,17 @@ BaseContext::BaseContext(sp_context_t *_ctx) } else { m_pub_funcs = NULL; } + + /* Initialize the null references */ + uint32_t index; + if (FindPubvarByName("NULL_VECTOR", &index) == SP_ERROR_NONE) + { + sp_pubvar_t *pubvar; + GetPubvarByIndex(index, &pubvar); + m_pNullVec = pubvar->offs; + } else { + m_pNullVec = NULL; + } } void BaseContext::FlushFunctionCache() @@ -991,4 +1002,14 @@ void BaseContext::SetIdentity(SourceMod::IdentityToken_t *token) { m_pToken = token; } + +cell_t *BaseContext::GetNullRef(SP_NULL_TYPE type) +{ + if (type == SP_NULL_VECTOR) + { + return m_pNullVec; + } + + return NULL; +} #endif diff --git a/core/vm/sp_vm_basecontext.h b/core/vm/sp_vm_basecontext.h index 15977543..938b9f55 100644 --- a/core/vm/sp_vm_basecontext.h +++ b/core/vm/sp_vm_basecontext.h @@ -69,6 +69,7 @@ namespace SourcePawn #if defined SOURCEMOD_BUILD SourceMod::IdentityToken_t *GetIdentity(); void SetIdentity(SourceMod::IdentityToken_t *token); + cell_t *GetNullRef(SP_NULL_TYPE type); #endif public: //IPluginDebugInfo int LookupFile(ucell_t addr, const char **filename); @@ -84,6 +85,7 @@ namespace SourcePawn sp_context_t *ctx; #if defined SOURCEMOD_BUILD SourceMod::IdentityToken_t *m_pToken; + cell_t *m_pNullVec; #endif char m_MsgCache[1024]; bool m_CustomMsg; diff --git a/plugins/include/core.inc b/plugins/include/core.inc index 5fd5634a..4e56a03f 100644 --- a/plugins/include/core.inc +++ b/plugins/include/core.inc @@ -85,11 +85,13 @@ enum PluginInfo */ struct Extension { - const String:name[], /* Short name */ - const String:file[], /* Default file name */ - bool:autoload, /* Whether or not to auto-load */ - bool:required, /* Whether or not to require */ + const String:name[], /**< Short name */ + const String:file[], /**< Default file name */ + bool:autoload, /**< Whether or not to auto-load */ + bool:required, /**< Whether or not to require */ }; +public Float:NULL_VECTOR[3]; /**< Pass this into certain functions to act as a C++ NULL */ + #define AUTOLOAD_EXTENSIONS #define REQUIRE_EXTENSIONS diff --git a/public/sourcepawn/sp_vm_api.h b/public/sourcepawn/sp_vm_api.h index f4da9310..66584910 100644 --- a/public/sourcepawn/sp_vm_api.h +++ b/public/sourcepawn/sp_vm_api.h @@ -28,7 +28,7 @@ #include "sp_vm_types.h" /** SourcePawn VM API Version */ -#define SOURCEPAWN_VM_API_VERSION 2 +#define SOURCEPAWN_VM_API_VERSION 3 #if !defined SOURCEMOD_BUILD #define SOURCEMOD_BUILD @@ -49,6 +49,16 @@ namespace SourcePawn #define SM_PARAM_STRING_UTF8 (1<<0) /**< String should be UTF-8 handled */ #define SM_PARAM_STRING_COPY (1<<1) /**< String should be copied into the plugin */ +#if defined SOURCEMOD_BUILD + /** + * @brief Pseudo-NULL reference types. + */ + enum SP_NULL_TYPE + { + SP_NULL_VECTOR = 0, /**< Float[3] reference */ + }; +#endif + /** * @brief Represents what a function needs to implement in order to be callable. */ @@ -536,6 +546,15 @@ namespace SourcePawn * @return Identity token. */ virtual SourceMod::IdentityToken_t *GetIdentity() =0; + + /** + * @brief Returns a NULL reference based on one of the available NULL + * reference types. + * + * @param type NULL reference type. + * @return cell_t address to compare to. + */ + virtual cell_t *GetNullRef(SP_NULL_TYPE type) =0; #endif };