diff --git a/core/logic/smn_core.cpp b/core/logic/smn_core.cpp index 8ba74ad7..d12e0fca 100644 --- a/core/logic/smn_core.cpp +++ b/core/logic/smn_core.cpp @@ -759,6 +759,27 @@ static cell_t StoreToAddress(IPluginContext *pContext, const cell_t *params) return 0; } +static cell_t IsNullVector(IPluginContext *pContext, const cell_t *params) +{ + cell_t *pNullVec = pContext->GetNullRef(SP_NULL_VECTOR); + if (!pNullVec) + return 0; + + cell_t *addr; + pContext->LocalToPhysAddr(params[1], &addr); + + return addr == pNullVec; +} + +static cell_t IsNullString(IPluginContext *pContext, const cell_t *params) +{ + char *str; + if (pContext->LocalToStringNULL(params[1], &str) != SP_ERROR_NONE) + return 0; + + return str == nullptr; +} + REGISTER_NATIVES(coreNatives) { {"ThrowError", ThrowError}, @@ -787,5 +808,7 @@ REGISTER_NATIVES(coreNatives) {"RequireFeature", RequireFeature}, {"LoadFromAddress", LoadFromAddress}, {"StoreToAddress", StoreToAddress}, + {"IsNullVector", IsNullVector}, + {"IsNullString", IsNullString}, {NULL, NULL}, }; diff --git a/plugins/include/core.inc b/plugins/include/core.inc index 315f79de..47f05e1c 100644 --- a/plugins/include/core.inc +++ b/plugins/include/core.inc @@ -143,6 +143,22 @@ struct SharedPlugin public float NULL_VECTOR[3]; /**< Pass this into certain functions to act as a C++ NULL */ public const char NULL_STRING[1]; /**< pass this into certain functions to act as a C++ NULL */ +/** + * Check if the given vector is the NULL_VECTOR. + * + * @param vec The vector to test. + * @return True if NULL_VECTOR, false otherwise. + */ +native bool IsNullVector(const float vec[3]); + +/** + * Check if the given string is the NULL_STRING. + * + * @param str The string to test. + * @return True if NULL_STRING, false otherwise. + */ +native bool IsNullString(const char[] str); + /** * Horrible compatibility shim. */