mirror of
https://github.com/alliedmodders/sourcemod.git
synced 2025-12-06 18:08:36 +00:00
Fix storing garbage strings (#2257)
This commit is contained in:
parent
6cd5bf87d8
commit
3b9c74ce96
@ -240,15 +240,10 @@ void CreateHashMaps()
|
||||
if (!pSchema)
|
||||
return;
|
||||
|
||||
static const char *pPriceKey = NULL;
|
||||
|
||||
const char *pPriceKey = g_pGameConf->GetKeyValue("PriceKey");
|
||||
if (!pPriceKey)
|
||||
{
|
||||
pPriceKey = g_pGameConf->GetKeyValue("PriceKey");
|
||||
if (!pPriceKey)
|
||||
{
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
static int iHashMapOffset = -1;
|
||||
|
||||
@ -33,11 +33,16 @@
|
||||
#include "gamerulesnatives.h"
|
||||
#include "vglobals.h"
|
||||
|
||||
const char *g_szGameRulesProxy;
|
||||
char g_szGameRulesProxy[64] = { 0 };
|
||||
|
||||
void GameRulesNativesInit()
|
||||
{
|
||||
g_szGameRulesProxy = g_pGameConf->GetKeyValue("GameRulesProxy");
|
||||
auto key = g_pGameConf->GetKeyValue("GameRulesProxy");
|
||||
if (key)
|
||||
{
|
||||
strncpy(g_szGameRulesProxy, key, sizeof(g_szGameRulesProxy));
|
||||
g_szGameRulesProxy[sizeof(g_szGameRulesProxy) - 1] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
static CBaseEntity *FindEntityByNetClass(int start, const char *classname)
|
||||
@ -202,7 +207,7 @@ static cell_t GameRules_GetProp(IPluginContext *pContext, const cell_t *params)
|
||||
|
||||
void *pGameRules = GameRules();
|
||||
|
||||
if (!pGameRules || !g_szGameRulesProxy || !strcmp(g_szGameRulesProxy, ""))
|
||||
if (!pGameRules || !g_szGameRulesProxy[0])
|
||||
return pContext->ThrowNativeError("Gamerules lookup failed.");
|
||||
|
||||
pContext->LocalToString(params[1], &prop);
|
||||
@ -274,7 +279,7 @@ static cell_t GameRules_SetProp(IPluginContext *pContext, const cell_t *params)
|
||||
if ((pProxy = GetGameRulesProxyEnt()) == NULL)
|
||||
return pContext->ThrowNativeError("Couldn't find gamerules proxy entity");
|
||||
|
||||
if (!pGameRules || !g_szGameRulesProxy || !strcmp(g_szGameRulesProxy, ""))
|
||||
if (!pGameRules || !g_szGameRulesProxy[0])
|
||||
return pContext->ThrowNativeError("Gamerules lookup failed");
|
||||
|
||||
pContext->LocalToString(params[1], &prop);
|
||||
@ -335,7 +340,7 @@ static cell_t GameRules_GetPropFloat(IPluginContext *pContext, const cell_t *par
|
||||
|
||||
void *pGameRules = GameRules();
|
||||
|
||||
if (!pGameRules || !g_szGameRulesProxy || !strcmp(g_szGameRulesProxy, ""))
|
||||
if (!pGameRules || !g_szGameRulesProxy[0])
|
||||
return pContext->ThrowNativeError("Gamerules lookup failed.");
|
||||
|
||||
pContext->LocalToString(params[1], &prop);
|
||||
@ -360,7 +365,7 @@ static cell_t GameRules_SetPropFloat(IPluginContext *pContext, const cell_t *par
|
||||
if ((pProxy = GetGameRulesProxyEnt()) == NULL)
|
||||
return pContext->ThrowNativeError("Couldn't find gamerules proxy entity.");
|
||||
|
||||
if (!pGameRules || !g_szGameRulesProxy || !strcmp(g_szGameRulesProxy, ""))
|
||||
if (!pGameRules || !g_szGameRulesProxy[0])
|
||||
return pContext->ThrowNativeError("Gamerules lookup failed.");
|
||||
|
||||
pContext->LocalToString(params[1], &prop);
|
||||
@ -394,7 +399,7 @@ static cell_t GameRules_GetPropEnt(IPluginContext *pContext, const cell_t *param
|
||||
|
||||
void *pGameRules = GameRules();
|
||||
|
||||
if (!pGameRules || !g_szGameRulesProxy || !strcmp(g_szGameRulesProxy, ""))
|
||||
if (!pGameRules || !g_szGameRulesProxy[0])
|
||||
return pContext->ThrowNativeError("Gamerules lookup failed.");
|
||||
|
||||
pContext->LocalToString(params[1], &prop);
|
||||
@ -425,7 +430,7 @@ static cell_t GameRules_SetPropEnt(IPluginContext *pContext, const cell_t *param
|
||||
if ((pProxy = GetGameRulesProxyEnt()) == NULL)
|
||||
return pContext->ThrowNativeError("Couldn't find gamerules proxy entity.");
|
||||
|
||||
if (!pGameRules || !g_szGameRulesProxy || !strcmp(g_szGameRulesProxy, ""))
|
||||
if (!pGameRules || !g_szGameRulesProxy[0])
|
||||
return pContext->ThrowNativeError("Gamerules lookup failed.");
|
||||
|
||||
pContext->LocalToString(params[1], &prop);
|
||||
@ -475,7 +480,7 @@ static cell_t GameRules_GetPropVector(IPluginContext *pContext, const cell_t *pa
|
||||
|
||||
void *pGameRules = GameRules();
|
||||
|
||||
if (!pGameRules || !g_szGameRulesProxy || !strcmp(g_szGameRulesProxy, ""))
|
||||
if (!pGameRules || !g_szGameRulesProxy[0])
|
||||
return pContext->ThrowNativeError("Gamerules lookup failed.");
|
||||
|
||||
pContext->LocalToString(params[1], &prop);
|
||||
@ -507,7 +512,7 @@ static cell_t GameRules_SetPropVector(IPluginContext *pContext, const cell_t *pa
|
||||
if ((pProxy = GetGameRulesProxyEnt()) == NULL)
|
||||
return pContext->ThrowNativeError("Couldn't find gamerules proxy entity.");
|
||||
|
||||
if (!pGameRules || !g_szGameRulesProxy || !strcmp(g_szGameRulesProxy, ""))
|
||||
if (!pGameRules || !g_szGameRulesProxy[0])
|
||||
return pContext->ThrowNativeError("Gamerules lookup failed.");
|
||||
|
||||
pContext->LocalToString(params[1], &prop);
|
||||
@ -551,7 +556,7 @@ static cell_t GameRules_GetPropString(IPluginContext *pContext, const cell_t *pa
|
||||
|
||||
void *pGameRules = GameRules();
|
||||
|
||||
if (!pGameRules || !g_szGameRulesProxy || !strcmp(g_szGameRulesProxy, ""))
|
||||
if (!pGameRules || !g_szGameRulesProxy[0])
|
||||
return pContext->ThrowNativeError("Gamerules lookup failed.");
|
||||
|
||||
pContext->LocalToString(params[1], &prop);
|
||||
@ -600,7 +605,7 @@ static cell_t GameRules_SetPropString(IPluginContext *pContext, const cell_t *pa
|
||||
if ((pProxy = GetGameRulesProxyEnt()) == NULL)
|
||||
return pContext->ThrowNativeError("Couldn't find gamerules proxy entity.");
|
||||
|
||||
if (!pGameRules || !g_szGameRulesProxy || !strcmp(g_szGameRulesProxy, ""))
|
||||
if (!pGameRules || !g_szGameRulesProxy[0])
|
||||
return pContext->ThrowNativeError("Gamerules lookup failed.");
|
||||
|
||||
pContext->LocalToString(params[1], &prop);
|
||||
|
||||
@ -39,7 +39,7 @@ struct TeamInfo
|
||||
CBaseEntity *pEnt;
|
||||
};
|
||||
|
||||
const char *m_iScore;
|
||||
char m_iScore[64] = { 0 };
|
||||
|
||||
SourceHook::CVector<TeamInfo> g_Teams;
|
||||
|
||||
@ -137,13 +137,15 @@ static cell_t GetTeamScore(IPluginContext *pContext, const cell_t *params)
|
||||
return pContext->ThrowNativeError("Team index %d is invalid", teamindex);
|
||||
}
|
||||
|
||||
if (!m_iScore)
|
||||
if (!m_iScore[0])
|
||||
{
|
||||
m_iScore = g_pGameConf->GetKeyValue("m_iScore");
|
||||
if (!m_iScore)
|
||||
auto key = g_pGameConf->GetKeyValue("m_iScore");
|
||||
if (!key || !key[0])
|
||||
{
|
||||
return pContext->ThrowNativeError("Failed to get m_iScore key");
|
||||
}
|
||||
strncpy(m_iScore, key, sizeof(m_iScore));
|
||||
m_iScore[sizeof(m_iScore) - 1] = '\0';
|
||||
}
|
||||
|
||||
static int offset = -1;
|
||||
@ -175,13 +177,15 @@ static cell_t SetTeamScore(IPluginContext *pContext, const cell_t *params)
|
||||
return pContext->ThrowNativeError("Team index %d is invalid", teamindex);
|
||||
}
|
||||
|
||||
if (m_iScore == NULL)
|
||||
if (!m_iScore[0])
|
||||
{
|
||||
m_iScore = g_pGameConf->GetKeyValue("m_iScore");
|
||||
if (m_iScore == NULL)
|
||||
auto key = g_pGameConf->GetKeyValue("m_iScore");
|
||||
if (!key || !key[0])
|
||||
{
|
||||
return pContext->ThrowNativeError("Failed to get m_iScore key");
|
||||
}
|
||||
strncpy(m_iScore, key, sizeof(m_iScore));
|
||||
m_iScore[sizeof(m_iScore) - 1] = '\0';
|
||||
}
|
||||
|
||||
static int offset = -1;
|
||||
|
||||
@ -34,6 +34,7 @@
|
||||
#include <datamap.h>
|
||||
|
||||
variant_t g_Variant_t;
|
||||
char g_Variant_str_Value[128];
|
||||
|
||||
// copy this definition as the original file includes cbase.h which explodes in a shower of compile errors
|
||||
void variant_t::SetEntity( CBaseEntity *val )
|
||||
@ -59,7 +60,9 @@ static cell_t SetVariantString(IPluginContext *pContext, const cell_t *params)
|
||||
{
|
||||
char *str;
|
||||
pContext->LocalToString(params[1], &str);
|
||||
g_Variant_t.SetString(MAKE_STRING(str));
|
||||
strncpy(g_Variant_str_Value, str, sizeof(g_Variant_str_Value));
|
||||
g_Variant_str_Value[sizeof(g_Variant_str_Value) - 1] = '\0';
|
||||
g_Variant_t.SetString(MAKE_STRING(g_Variant_str_Value));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user