From 9ac8b2869bd448baa6bb8d4d5f5ee5051faf0f06 Mon Sep 17 00:00:00 2001 From: Sergey Gut Date: Tue, 10 Mar 2020 18:03:27 +0400 Subject: [PATCH] Pass success flag to plugins, include changes --- package/scripting/include/env_variables.inc | 11 ++++++++++- src/natives.cpp | 7 +++++++ src/smsdk_config.h | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/package/scripting/include/env_variables.inc b/package/scripting/include/env_variables.inc index f660c40..a2cbb16 100644 --- a/package/scripting/include/env_variables.inc +++ b/package/scripting/include/env_variables.inc @@ -40,9 +40,11 @@ * @param szName The environment variable name. * @param szBuffer Buffer where value should be written. * @param iBufferLength Maximum size of the buffer. + * @param bExists The ref to variable where will be written + * information about presence environment variable. * @return The written bytes count. */ -native int GetEnvironmentVariable(const char[] szName, char[] szBuffer, int iBufferLength); +native int GetEnvironmentVariable(const char[] szName, char[] szBuffer, int iBufferLength, bool &bExists = false); /** * Do not edit below this line! @@ -62,3 +64,10 @@ public Extension __ext_env_variables = required = 0, #endif }; + +#if !defined REQUIRE_EXTENSIONS +public void __ext_env_variables_SetNTVOptional() +{ + MarkNativeAsOptional("GetEnvironmentVariable"); +} +#endif diff --git a/src/natives.cpp b/src/natives.cpp index ea97767..ba82f55 100644 --- a/src/natives.cpp +++ b/src/natives.cpp @@ -40,6 +40,13 @@ static cell_t sm_getenv(SourcePawn::IPluginContext *pContext, const cell_t *para char *value = getenv(name); cell_t is_success = (value != NULL) ? 1 : 0; + if (params[0] > 3) + { + cell_t *addr; + pContext->LocalToPhysAddr(params[4], &addr); + *addr = is_success; + } + if (value != NULL) { size_t numBytes; diff --git a/src/smsdk_config.h b/src/smsdk_config.h index 1d7ea14..058dc09 100644 --- a/src/smsdk_config.h +++ b/src/smsdk_config.h @@ -40,7 +40,7 @@ /* Basic information exposed publicly */ #define SMEXT_CONF_NAME "Environment Variables" #define SMEXT_CONF_DESCRIPTION "Extension what implements getenv() for SourcePawn plugins" -#define SMEXT_CONF_VERSION "1.0.0.0" +#define SMEXT_CONF_VERSION "1.0.0.1" #define SMEXT_CONF_AUTHOR "CrazyHackGUT aka Kruzya" #define SMEXT_CONF_URL "https://kruzya.me/" #define SMEXT_CONF_LOGTAG "ENV"