Skip to content

Commit

Permalink
Throw error in ShowHudText or ShowSyncHudText if HudText params not y…
Browse files Browse the repository at this point in the history
…et set (#1890)
  • Loading branch information
psychonic committed Dec 20, 2022
1 parent c5e6990 commit 515df38
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/smn_hudtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ struct hud_text_parms
float holdTime;
float fxTime;
int channel;
bool isSet = false;
};

class HudMsgHelpers :
Expand Down Expand Up @@ -282,6 +283,7 @@ static cell_t SetHudTextParams(IPluginContext *pContext, const cell_t *params)
g_hud_params.g2 = 255;
g_hud_params.b2 = 250;
g_hud_params.a2 = 0;
g_hud_params.isSet = true;

return 1;
}
Expand All @@ -308,6 +310,7 @@ static cell_t SetHudTextParamsEx(IPluginContext *pContext, const cell_t *params)
g_hud_params.g2 = static_cast<byte>(color2[1]);
g_hud_params.b2 = static_cast<byte>(color2[2]);
g_hud_params.a2 = static_cast<byte>(color2[3]);
g_hud_params.isSet = true;

return 1;
}
Expand Down Expand Up @@ -384,6 +387,11 @@ static cell_t ShowSyncHudText(IPluginContext *pContext, const cell_t *params)
return -1;
}

if (!g_hud_params.isSet)
{
return pContext->ThrowNativeError("ShowSyncHudText first requires a call to SetHudTextParams or SetHudTextParamsEx");
}

if ((err = s_HudMsgHelpers.ReadHudSyncObj(params[2], pContext->GetIdentity(), &obj)) != HandleError_None)
{
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[2], err);
Expand Down Expand Up @@ -468,6 +476,11 @@ static cell_t ShowHudText(IPluginContext *pContext, const cell_t *params)
return -1;
}

if (!g_hud_params.isSet)
{
return pContext->ThrowNativeError("ShowHudText first requires a call to SetHudTextParams or SetHudTextParamsEx");
}

client = params[1];
if ((pPlayer = g_Players.GetPlayerByIndex(client)) == NULL)
{
Expand Down

0 comments on commit 515df38

Please sign in to comment.