From 7675b605673c827db8f7987ecb5f92b880aedaf2 Mon Sep 17 00:00:00 2001 From: rtldg <55846624+rtldg@users.noreply.github.com> Date: Sun, 9 Jan 2022 10:48:48 +0000 Subject: [PATCH] hud forward stuff --- .../scripting/include/shavit/hud.inc | 33 +---- addons/sourcemod/scripting/shavit-hud.sp | 121 ++++++++++-------- 2 files changed, 71 insertions(+), 83 deletions(-) diff --git a/addons/sourcemod/scripting/include/shavit/hud.inc b/addons/sourcemod/scripting/include/shavit/hud.inc index 198e79f5..f9d99b93 100644 --- a/addons/sourcemod/scripting/include/shavit/hud.inc +++ b/addons/sourcemod/scripting/include/shavit/hud.inc @@ -116,19 +116,6 @@ forward Action Shavit_OnTopLeftHUD(int client, int target, char[] topleft, int t */ forward Action Shavit_PreOnTopLeftHUD(int client, int target, char[] topleft, int topleftlength, int track, int style); -/** - * Called when the center hud updates. - * - * @param client Client index that recieves the hud. - * @param target Target entity that is either the client or what the client is spectating. - * @param buffer Reference to the HUD buffer. - * @param buflen Max length of the buffer. - * @param data huddata_t which contains target info. - * - * @return Plugin_Handled or Plugin_Stop to block the HUD message from appearing. Plugin_Changed if you modify the buffer string. - */ -forward Action Shavit_OnDrawCenterHUD(int client, int target, char[] buffer, int buflen, huddata_t data); - /** * Called before the center hud updates. * @@ -142,21 +129,6 @@ forward Action Shavit_OnDrawCenterHUD(int client, int target, char[] buffer, int */ forward Action Shavit_PreOnDrawCenterHUD(int client, int target, char[] buffer, int buflen, huddata_t data); -/** - * Called when the !keys hud updates. - * - * @param client Client index that recieves the hud. - * @param target Target entity that is either the client or what the client is spectating. - * @param style The target's style. - * @param buttons The target's buttons. - * @param anglediff The difference from the target's last angles and current angles. - * @param buffer Reference to the HUD buffer. - * @param buflen Max length of the buffer. - * - * @return Plugin_Handled or Plugin_Stop to block the HUD message from appearing. Plugin_Changed if you modify the buffer string. - */ -forward Action Shavit_OnDrawKeysHUD(int client, int target, int style, int buttons, float anglediff, char[] buffer, int buflen); - /** * Called before the !keys hud updates. * @@ -167,10 +139,13 @@ forward Action Shavit_OnDrawKeysHUD(int client, int target, int style, int butto * @param anglediff The difference from the target's last angles and current angles. * @param buffer Reference to the HUD buffer. * @param buflen Max length of the buffer. + * @param scrolls How many scrolls the player has so far (relevant for non-auto styles). + * @param prevscrolls How many scrolls previously. + * @param alternate_center_keys True when you should draw a Linux-specific format since fonts & alignment are different. * * @return Plugin_Handled or Plugin_Stop to block the HUD message from appearing. Plugin_Changed if you modify the buffer string. */ -forward Action Shavit_PreOnDrawKeysHUD(int client, int target, int style, int buttons, float anglediff, char[] buffer, int buflen); +forward Action Shavit_PreOnDrawKeysHUD(int client, int target, int style, int buttons, float anglediff, char[] buffer, int buflen, int scrolls, int prevscrolls, bool alternate_center_keys); /** * Force an HUD update for a player. Requires shavit-hud. diff --git a/addons/sourcemod/scripting/shavit-hud.sp b/addons/sourcemod/scripting/shavit-hud.sp index c21135bf..63cf3e6b 100644 --- a/addons/sourcemod/scripting/shavit-hud.sp +++ b/addons/sourcemod/scripting/shavit-hud.sp @@ -58,9 +58,7 @@ EngineVersion gEV_Type = Engine_Unknown; // forwards Handle gH_Forwards_OnTopLeftHUD = null; Handle gH_Forwards_PreOnTopLeftHUD = null; -Handle gH_Forwards_OnDrawCenterHUD = null; Handle gH_Forwards_PreOnDrawCenterHUD = null; -Handle gH_Forwards_OnDrawKeysHUD = null; Handle gH_Forwards_PreOnDrawKeysHUD = null; // modules @@ -126,10 +124,8 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max // forwards gH_Forwards_OnTopLeftHUD = CreateGlobalForward("Shavit_OnTopLeftHUD", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_Cell, Param_Cell); gH_Forwards_PreOnTopLeftHUD = CreateGlobalForward("Shavit_PreOnTopLeftHUD", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_Cell, Param_Cell); - gH_Forwards_OnDrawCenterHUD = CreateGlobalForward("Shavit_OnDrawCenterHUD", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_Array); gH_Forwards_PreOnDrawCenterHUD = CreateGlobalForward("Shavit_PreOnDrawCenterHUD", ET_Event, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_Array); - gH_Forwards_OnDrawKeysHUD = CreateGlobalForward("Shavit_OnDrawKeysHUD", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_String, Param_Cell); - gH_Forwards_PreOnDrawKeysHUD = CreateGlobalForward("Shavit_PreOnDrawKeysHUD", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_String, Param_Cell); + gH_Forwards_PreOnDrawKeysHUD = CreateGlobalForward("Shavit_PreOnDrawKeysHUD", ET_Event, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_String, Param_Cell, Param_Cell, Param_Cell, Param_Cell); // natives CreateNative("Shavit_ForceHUDUpdate", Native_ForceHUDUpdate); @@ -1679,10 +1675,10 @@ void UpdateMainHUD(int client) return; } - int lines = 0; - if (preresult == Plugin_Continue) { + int lines = 0; + if (IsSource2013(gEV_Type)) { lines = AddHUDToBuffer_Source2013(client, huddata, sBuffer, sizeof(sBuffer)); @@ -1691,25 +1687,11 @@ void UpdateMainHUD(int client) { lines = AddHUDToBuffer_CSGO(client, huddata, sBuffer, sizeof(sBuffer)); } - } - Action postresult = Plugin_Continue; - Call_StartForward(gH_Forwards_OnDrawCenterHUD); - Call_PushCell(client); - Call_PushCell(target); - Call_PushStringEx(sBuffer, sizeof(sBuffer), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); - Call_PushCell(sizeof(sBuffer)); - Call_PushArray(huddata, sizeof(huddata)); - Call_Finish(postresult); - - if (postresult == Plugin_Handled || postresult == Plugin_Stop) - { - return; - } - - if (preresult == Plugin_Continue && postresult == Plugin_Continue && lines < 1) - { - return; + if (lines < 1) + { + return; + } } if (IsSource2013(gEV_Type)) @@ -1831,44 +1813,21 @@ void UpdateCenterKeys(int client) float fAngleDiff; int buttons; + int scrolls = -1; + int prevscrolls = -1; if (IsValidClient(target)) { fAngleDiff = gF_AngleDiff[target]; buttons = gI_Buttons[target]; + scrolls = gI_ScrollCount[target]; + prevscrolls = gI_LastScrollCount[target]; } else { buttons = Shavit_GetReplayButtons(target, fAngleDiff); } - char sCenterText[254]; - - if (gEV_Type == Engine_CSGO) - { - FormatEx(sCenterText, sizeof(sCenterText), "%s %s\n%s %s %s\n%s  %s  %s\n %s  %s", - (buttons & IN_JUMP) > 0? "J":"ー", (buttons & IN_DUCK) > 0? "C":"ー", - (fAngleDiff > 0) ? "<":"ー", (buttons & IN_FORWARD) > 0 ? "W":"ー", (fAngleDiff < 0) ? ">":"ー", - (buttons & IN_MOVELEFT) > 0? "A":"ー", (buttons & IN_BACK) > 0? "S":"ー", (buttons & IN_MOVERIGHT) > 0? "D":"ー", - (buttons & IN_LEFT) > 0? "L":" ", (buttons & IN_RIGHT) > 0? "R":" "); - } - else if (gB_AlternateCenterKeys[client]) - { - FormatEx(sCenterText, sizeof(sCenterText), " %s  %s\n%s %s %s\n%s  %s  %s\n %s  %s", - (buttons & IN_JUMP) > 0? "J":"_", (buttons & IN_DUCK) > 0? "C":"_", - (fAngleDiff > 0) ? "<":" ", (buttons & IN_FORWARD) > 0 ? "W":" _", (fAngleDiff < 0) ? ">":"", - (buttons & IN_MOVELEFT) > 0? "A":"_", (buttons & IN_BACK) > 0? "S":"_", (buttons & IN_MOVERIGHT) > 0? "D":"_", - (buttons & IN_LEFT) > 0? "L":" ", (buttons & IN_RIGHT) > 0? "R":" "); - } - else - { - FormatEx(sCenterText, sizeof(sCenterText), "  %s  %s\n %s %s %s\n %s  %s  %s\n  %s  %s", - (buttons & IN_JUMP) > 0? "J":"ー", (buttons & IN_DUCK) > 0? "C":"ー", - (fAngleDiff > 0) ? "<":" ", (buttons & IN_FORWARD) > 0 ? "W":" ー", (fAngleDiff < 0) ? ">":"", - (buttons & IN_MOVELEFT) > 0? "A":"ー", (buttons & IN_BACK) > 0? "S":"ー", (buttons & IN_MOVERIGHT) > 0? "D":"ー", - (buttons & IN_LEFT) > 0? "L":" ", (buttons & IN_RIGHT) > 0? "R":" "); - } - int style = (gB_ReplayPlayback && Shavit_IsReplayEntity(target))? Shavit_GetReplayBotStyle(target):Shavit_GetBhopStyle(target); if(!(0 <= style < gI_Styles)) @@ -1876,9 +1835,30 @@ void UpdateCenterKeys(int client) style = 0; } - if(!Shavit_GetStyleSettingBool(style, "autobhop") && IsValidClient(target)) + char sCenterText[254]; + + Action preresult = Plugin_Continue; + Call_StartForward(gH_Forwards_PreOnDrawKeysHUD); + Call_PushCell(client); + Call_PushCell(target); + Call_PushCell(style); + Call_PushCell(buttons); + Call_PushCell(fAngleDiff); + Call_PushStringEx(sCenterText, sizeof(sCenterText), SM_PARAM_STRING_COPY, SM_PARAM_COPYBACK); + Call_PushCell(sizeof(sCenterText)); + Call_PushCell(scrolls); + Call_PushCell(prevscrolls); + Call_PushCell(gB_AlternateCenterKeys[client]); + Call_Finish(preresult); + + if (preresult == Plugin_Handled || preresult == Plugin_Stop) { - Format(sCenterText, sizeof(sCenterText), "%s\n  %s%d %s%s%d", sCenterText, gI_ScrollCount[target] < 10 ? " " : "", gI_ScrollCount[target], gI_ScrollCount[target] < 10 ? " " : "", gI_LastScrollCount[target] < 10 ? " " : "", gI_LastScrollCount[target]); + return; + } + + if (preresult == Plugin_Continue) + { + FillCenterKeys(client, target, style, buttons, fAngleDiff, sCenterText, sizeof(sCenterText)); } if (IsSource2013(gEV_Type)) @@ -1891,6 +1871,39 @@ void UpdateCenterKeys(int client) } } +void FillCenterKeys(int client, int target, int style, int buttons, float fAngleDiff, char[] buffer, int buflen) +{ + if (gEV_Type == Engine_CSGO) + { + FormatEx(buffer, buflen, "%s %s\n%s %s %s\n%s  %s  %s\n %s  %s", + (buttons & IN_JUMP) > 0? "J":"ー", (buttons & IN_DUCK) > 0? "C":"ー", + (fAngleDiff > 0) ? "<":"ー", (buttons & IN_FORWARD) > 0 ? "W":"ー", (fAngleDiff < 0) ? ">":"ー", + (buttons & IN_MOVELEFT) > 0? "A":"ー", (buttons & IN_BACK) > 0? "S":"ー", (buttons & IN_MOVERIGHT) > 0? "D":"ー", + (buttons & IN_LEFT) > 0? "L":" ", (buttons & IN_RIGHT) > 0? "R":" "); + } + else if (gB_AlternateCenterKeys[client]) + { + FormatEx(buffer, buflen, " %s  %s\n%s %s %s\n%s  %s  %s\n %s  %s", + (buttons & IN_JUMP) > 0? "J":"_", (buttons & IN_DUCK) > 0? "C":"_", + (fAngleDiff > 0) ? "<":" ", (buttons & IN_FORWARD) > 0 ? "W":" _", (fAngleDiff < 0) ? ">":"", + (buttons & IN_MOVELEFT) > 0? "A":"_", (buttons & IN_BACK) > 0? "S":"_", (buttons & IN_MOVERIGHT) > 0? "D":"_", + (buttons & IN_LEFT) > 0? "L":" ", (buttons & IN_RIGHT) > 0? "R":" "); + } + else + { + FormatEx(buffer, buflen, "  %s  %s\n %s %s %s\n %s  %s  %s\n  %s  %s", + (buttons & IN_JUMP) > 0? "J":"ー", (buttons & IN_DUCK) > 0? "C":"ー", + (fAngleDiff > 0) ? "<":" ", (buttons & IN_FORWARD) > 0 ? "W":" ー", (fAngleDiff < 0) ? ">":"", + (buttons & IN_MOVELEFT) > 0? "A":"ー", (buttons & IN_BACK) > 0? "S":"ー", (buttons & IN_MOVERIGHT) > 0? "D":"ー", + (buttons & IN_LEFT) > 0? "L":" ", (buttons & IN_RIGHT) > 0? "R":" "); + } + + if(!Shavit_GetStyleSettingBool(style, "autobhop") && IsValidClient(target)) + { + Format(buffer, buflen, "%s\n  %s%d %s%s%d", buffer, gI_ScrollCount[target] < 10 ? " " : "", gI_ScrollCount[target], gI_ScrollCount[target] < 10 ? " " : "", gI_LastScrollCount[target] < 10 ? " " : "", gI_LastScrollCount[target]); + } +} + void PrintCSGOCenterText(int client, const char[] text) { SetHudTextParams(