From 69ab44426ea4406dc0d2468c3ac928451dcdb2f1 Mon Sep 17 00:00:00 2001 From: nosoop Date: Wed, 22 Jun 2022 02:24:49 -0700 Subject: [PATCH 1/6] pain --- addons/sourcemod/scripting/nativevotes.sp | 6 +++ .../sourcemod/scripting/nativevotes/game.sp | 46 +++++++++++++++++-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/addons/sourcemod/scripting/nativevotes.sp b/addons/sourcemod/scripting/nativevotes.sp index c419096..a049da6 100644 --- a/addons/sourcemod/scripting/nativevotes.sp +++ b/addons/sourcemod/scripting/nativevotes.sp @@ -655,6 +655,12 @@ public void OnMapEnd() public Action Command_Vote(int client, const char[] command, int argc) { +#if defined LOG + char voteString[128]; + GetCmdArgString(voteString, sizeof(voteString)); + LogMessage("Client %N ran a vote command: %s", client, voteString); +#endif + // If we're not running a vote, return the vote control back to the server if (!Internal_IsVoteInProgress() || g_ClientVotes[client] != VOTE_PENDING) { diff --git a/addons/sourcemod/scripting/nativevotes/game.sp b/addons/sourcemod/scripting/nativevotes/game.sp index 0f63128..c831c2f 100644 --- a/addons/sourcemod/scripting/nativevotes/game.sp +++ b/addons/sourcemod/scripting/nativevotes/game.sp @@ -361,6 +361,14 @@ static ConVar g_Cvar_AutoBalance; static ConVar g_Cvar_HideDisabledIssues; +/** + * TODO(UPDATE): For now we only support one vote from NativeVotes at a time. + * + * Ideally we peek and poke at the game's `s_nVoteIdx` and increment it accordingly, but we also + * have to store an internal list of active votes. + */ +static int s_nNativeVoteIdx = 0; + bool Game_IsGameSupported(char[] engineName="", int maxlength=0) { g_EngineVersion = GetEngineVersion(); @@ -828,9 +836,13 @@ void Game_ClientSelectedItem(NativeVote vote, int client, int item) L4DL4D2_ClientSelectedItem(client, item); } - case Engine_CSGO, Engine_TF2: + case Engine_CSGO: { - TF2CSGO_ClientSelectedItem(vote, client, item); + CSGO_ClientSelectedItem(vote, client, item); + } + case Engine_TF2: + { + TF2_ClientSelectedItem(vote, client, item); } /* case Engine_Left4Dead: @@ -2113,7 +2125,7 @@ static int TF2CSGO_ParseVote(const char[] option) return StringToInt(option[6]) - 1; } -static void TF2CSGO_ClientSelectedItem(NativeVote vote, int client, int item) +static void CSGO_ClientSelectedItem(NativeVote vote, int client, int item) { Event castEvent = CreateEvent("vote_cast"); @@ -2123,6 +2135,17 @@ static void TF2CSGO_ClientSelectedItem(NativeVote vote, int client, int item) castEvent.Fire(); } +static void TF2_ClientSelectedItem(NativeVote vote, int client, int item) +{ + Event castEvent = CreateEvent("vote_cast"); + + castEvent.SetInt("team", Data_GetTeam(vote)); + castEvent.SetInt("voteidx", s_nNativeVoteIdx); // TODO(UPDATE): this was added in 2022-06-22 - figure out what the client voted for + castEvent.SetInt("entityid", client); + castEvent.SetInt("vote_option", item); + castEvent.Fire(); +} + static void TF2CSGO_UpdateVoteCounts(ArrayList votes) { if (CheckVoteController()) @@ -2221,6 +2244,14 @@ static void TF2CSGO_DisplayVote(NativeVote vote, int[] clients, int num_clients) { SetEntProp(g_VoteController, Prop_Send, "m_nVoteOptionCount", 0, _, i); } + + // TODO(UPDATE): M-M-M-MULTIVOTE + // s_nNativeVoteIdx = GetEntProp(g_VoteController, Prop_Send, "m_nVoteIdx"); + s_nNativeVoteIdx = 0; +#if defined LOG + PrintToServer("Starting vote index: %d", s_nNativeVoteIdx); +#endif + // SetEntProp(g_VoteController, Prop_Send, "m_nVoteIdx", s_nNativeVoteIdx + 1); // TODO(UPDATE) } // According to Source SDK 2013, vote_options is only sent for a multiple choice vote. @@ -2244,6 +2275,7 @@ static void TF2CSGO_DisplayVote(NativeVote vote, int[] clients, int num_clients) optionsEvent.SetString(option, display); } optionsEvent.SetInt("count", itemCount); + optionsEvent.SetInt("voteidx", s_nNativeVoteIdx); // TODO(UPDATE) optionsEvent.Fire(); } @@ -2297,7 +2329,8 @@ static void TF2CSGO_DisplayVote(NativeVote vote, int[] clients, int num_clients) else { BfWrite bfStart = UserMessageToBfWrite(voteStart); - bfStart.WriteByte(team); + bfStart.WriteByte(team); + bfStart.WriteNum(s_nNativeVoteIdx); bfStart.WriteByte(Data_GetInitiator(vote)); bfStart.WriteString(translation); if (bCustom && changeTitle == Plugin_Changed) @@ -2367,6 +2400,7 @@ static void TF2CSGO_SendOptionsToClient(NativeVote vote, int client) optionsEvent.SetString(option, display); } optionsEvent.SetInt("count", itemCount); + optionsEvent.SetInt("voteidx", s_nNativeVoteIdx); // TODO(UPDATE) optionsEvent.FireToClient(client); } @@ -2426,6 +2460,7 @@ static void TF2_VoteFail(int[] clients, int numClients, int reason, int team) BfWrite voteFailed = UserMessageToBfWrite(StartMessage("VoteFailed", clients, numClients, USERMSG_RELIABLE)); voteFailed.WriteByte(team); + voteFailed.WriteNum(s_nNativeVoteIdx); // TODO(UPDATE) voteFailed.WriteByte(reason); EndMessage(); @@ -2506,7 +2541,10 @@ static void TF2CSGO_ResetVote() if (CheckVoteController()) { if (g_EngineVersion == Engine_TF2) + { SetEntProp(g_VoteController, Prop_Send, "m_iActiveIssueIndex", INVALID_ISSUE); + SetEntProp(g_VoteController, Prop_Send, "m_nVoteIdx", -1); // TODO(UPDATE) + } for (int i = 0; i < 5; i++) { From 76f209bbf40c136cb8bd7bbc0c00e0490f11d048 Mon Sep 17 00:00:00 2001 From: nosoop Date: Wed, 22 Jun 2022 06:41:45 -0700 Subject: [PATCH 2/6] Add voteidx to VotePass usermsg This was subtly broken --- addons/sourcemod/scripting/nativevotes/game.sp | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/sourcemod/scripting/nativevotes/game.sp b/addons/sourcemod/scripting/nativevotes/game.sp index c831c2f..5d72608 100644 --- a/addons/sourcemod/scripting/nativevotes/game.sp +++ b/addons/sourcemod/scripting/nativevotes/game.sp @@ -2439,6 +2439,7 @@ static void TF2_VotePass(const char[] translation, const char[] details, int tea } votePass.WriteByte(team); + votePass.WriteNum(s_nNativeVoteIdx); votePass.WriteString(translation); votePass.WriteString(details); From dc4a68bdee15c5aded33b2ddfa49ceb06cc12c21 Mon Sep 17 00:00:00 2001 From: nosoop Date: Wed, 22 Jun 2022 06:43:48 -0700 Subject: [PATCH 3/6] Use correct default voteidx --- addons/sourcemod/scripting/nativevotes/game.sp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sourcemod/scripting/nativevotes/game.sp b/addons/sourcemod/scripting/nativevotes/game.sp index 5d72608..ddf3251 100644 --- a/addons/sourcemod/scripting/nativevotes/game.sp +++ b/addons/sourcemod/scripting/nativevotes/game.sp @@ -2247,7 +2247,7 @@ static void TF2CSGO_DisplayVote(NativeVote vote, int[] clients, int num_clients) // TODO(UPDATE): M-M-M-MULTIVOTE // s_nNativeVoteIdx = GetEntProp(g_VoteController, Prop_Send, "m_nVoteIdx"); - s_nNativeVoteIdx = 0; + s_nNativeVoteIdx = -1; #if defined LOG PrintToServer("Starting vote index: %d", s_nNativeVoteIdx); #endif From 1de18a2d1c55e4c3b0e142bd2126532628d91072 Mon Sep 17 00:00:00 2001 From: nosoop Date: Wed, 22 Jun 2022 08:20:43 -0700 Subject: [PATCH 4/6] Parse multivote command syntax Thanks to Mikusch for the reminder --- addons/sourcemod/scripting/nativevotes.sp | 8 +++- .../sourcemod/scripting/nativevotes/game.sp | 40 ++++++++++++++++--- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/addons/sourcemod/scripting/nativevotes.sp b/addons/sourcemod/scripting/nativevotes.sp index a049da6..a11b7ad 100644 --- a/addons/sourcemod/scripting/nativevotes.sp +++ b/addons/sourcemod/scripting/nativevotes.sp @@ -667,8 +667,8 @@ public Action Command_Vote(int client, const char[] command, int argc) return Plugin_Continue; } - char option[32]; - GetCmdArg(1, option, sizeof(option)); + char option[64]; + GetCmdArgString(option, sizeof(option)); int item = Game_ParseVote(option); @@ -1125,6 +1125,10 @@ void EndVoting() NativeVote vote = g_hCurVote; Internal_Reset(); +#if defined LOG + LogMessage("Voting done"); +#endif + /* Send vote info */ OnVoteResults(vote, votes, num_votes, num_items, client_list, num_clients); OnEnd(vote, MenuEnd_VotingDone); diff --git a/addons/sourcemod/scripting/nativevotes/game.sp b/addons/sourcemod/scripting/nativevotes/game.sp index ddf3251..50e1d78 100644 --- a/addons/sourcemod/scripting/nativevotes/game.sp +++ b/addons/sourcemod/scripting/nativevotes/game.sp @@ -493,6 +493,10 @@ int Game_ParseVote(const char[] option) { int item = NATIVEVOTES_VOTE_INVALID; +#if defined LOG + LogMessage("Parsing vote option %s", option); +#endif + switch(g_EngineVersion) { case Engine_Left4Dead, Engine_Left4Dead2: @@ -500,9 +504,13 @@ int Game_ParseVote(const char[] option) item = L4DL4D2_ParseVote(option); } - case Engine_CSGO, Engine_TF2: + case Engine_CSGO: { - item = TF2CSGO_ParseVote(option); + item = CSGO_ParseVote(option); + } + case Engine_TF2: + { + item = TF2_ParseVote(option); } } @@ -829,6 +837,9 @@ void Game_DisplayCallVoteFail(int client, NativeVotesCallFailType reason, int ti void Game_ClientSelectedItem(NativeVote vote, int client, int item) { +#if defined LOG + LogMessage("Client %N selected item %d", client, item); +#endif switch(g_EngineVersion) { case Engine_Left4Dead, Engine_Left4Dead2: @@ -2114,7 +2125,7 @@ static bool L4D2_CheckVotePassType(NativeVotesPassType passType) // TF2 and CSGO functions are still together in case Valve moves TF2 to protobufs. // NATIVEVOTES_VOTE_INVALID means parse failed -static int TF2CSGO_ParseVote(const char[] option) +static int CSGO_ParseVote(const char[] option) { // option1 <-- 7 characters exactly if (strlen(option) != 7) @@ -2125,6 +2136,25 @@ static int TF2CSGO_ParseVote(const char[] option) return StringToInt(option[6]) - 1; } +// NATIVEVOTES_VOTE_INVALID means parse failed +static int TF2_ParseVote(const char[] option) +{ + char arg1[8]; + int iArg2 = BreakString(option, arg1, sizeof(arg1)); + + char argOption[64]; + strcopy(argOption, sizeof(argOption), option[iArg2]); + + int voteidx = StringToInt(arg1); + // option1 <-- 7 characters exactly + if (strlen(argOption) != 7) + { + return NATIVEVOTES_VOTE_INVALID; + } + + return StringToInt(argOption[6]) - 1; +} + static void CSGO_ClientSelectedItem(NativeVote vote, int client, int item) { Event castEvent = CreateEvent("vote_cast"); @@ -2249,9 +2279,9 @@ static void TF2CSGO_DisplayVote(NativeVote vote, int[] clients, int num_clients) // s_nNativeVoteIdx = GetEntProp(g_VoteController, Prop_Send, "m_nVoteIdx"); s_nNativeVoteIdx = -1; #if defined LOG - PrintToServer("Starting vote index: %d", s_nNativeVoteIdx); + PrintToServer("Starting vote index: %d (controller: %d)", s_nNativeVoteIdx, GetEntProp(g_VoteController, Prop_Send, "m_nVoteIdx")); #endif - // SetEntProp(g_VoteController, Prop_Send, "m_nVoteIdx", s_nNativeVoteIdx + 1); // TODO(UPDATE) + SetEntProp(g_VoteController, Prop_Send, "m_nVoteIdx", s_nNativeVoteIdx + 1); // TODO(UPDATE) } // According to Source SDK 2013, vote_options is only sent for a multiple choice vote. From 002119d08a7289939da1db9ccd53169d69de6e46 Mon Sep 17 00:00:00 2001 From: nosoop Date: Wed, 22 Jun 2022 19:40:13 -0700 Subject: [PATCH 5/6] doc --- addons/sourcemod/scripting/nativevotes/game.sp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/sourcemod/scripting/nativevotes/game.sp b/addons/sourcemod/scripting/nativevotes/game.sp index 50e1d78..8303798 100644 --- a/addons/sourcemod/scripting/nativevotes/game.sp +++ b/addons/sourcemod/scripting/nativevotes/game.sp @@ -2139,6 +2139,9 @@ static int CSGO_ParseVote(const char[] option) // NATIVEVOTES_VOTE_INVALID means parse failed static int TF2_ParseVote(const char[] option) { + // the update on 2022-06-22 changed the params passed to the `vote` command + // previously it was a single string "optionN", where N was the option to be selected + // now it's two arguments "X optionN", where X is the vote index being acted on char arg1[8]; int iArg2 = BreakString(option, arg1, sizeof(arg1)); @@ -2276,8 +2279,9 @@ static void TF2CSGO_DisplayVote(NativeVote vote, int[] clients, int num_clients) } // TODO(UPDATE): M-M-M-MULTIVOTE - // s_nNativeVoteIdx = GetEntProp(g_VoteController, Prop_Send, "m_nVoteIdx"); - s_nNativeVoteIdx = -1; + // we need unique vote indices; HUD elements for previous votes aren't cleaned up (?) + // the game implements this as `this->m_nVoteIdx = s_nVoteIdx++` + s_nNativeVoteIdx = GetEntProp(g_VoteController, Prop_Send, "m_nVoteIdx"); #if defined LOG PrintToServer("Starting vote index: %d (controller: %d)", s_nNativeVoteIdx, GetEntProp(g_VoteController, Prop_Send, "m_nVoteIdx")); #endif From da64e52bb0cf493bef701d0425bab43c5be70e93 Mon Sep 17 00:00:00 2001 From: nosoop Date: Thu, 23 Jun 2022 14:58:17 -0700 Subject: [PATCH 6/6] Replicate sv_vote_holder_may_vote_no to vote on self-initiated raised issues --- addons/sourcemod/scripting/nativevotes.sp | 4 ++++ addons/sourcemod/scripting/nativevotes/game.sp | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/addons/sourcemod/scripting/nativevotes.sp b/addons/sourcemod/scripting/nativevotes.sp index a11b7ad..a4c086c 100644 --- a/addons/sourcemod/scripting/nativevotes.sp +++ b/addons/sourcemod/scripting/nativevotes.sp @@ -112,6 +112,8 @@ int g_ClientVotes[MAXPLAYERS+1]; bool g_bRevoting[MAXPLAYERS+1]; char g_LeaderList[1024]; +ConVar sv_vote_holder_may_vote_no; + // Map list stuffs #define STRINGTABLE_NAME "ServerMapCycle" @@ -262,6 +264,8 @@ public void OnPluginStart() AddCommandListener(Command_Vote, "vote"); // All games, command listeners aren't case sensitive + sv_vote_holder_may_vote_no = FindConVar("sv_vote_holder_may_vote_no"); + // The new version of the CallVote system is TF2 only if (Game_AreVoteCommandsSupported()) { diff --git a/addons/sourcemod/scripting/nativevotes/game.sp b/addons/sourcemod/scripting/nativevotes/game.sp index 8303798..ecf9273 100644 --- a/addons/sourcemod/scripting/nativevotes/game.sp +++ b/addons/sourcemod/scripting/nativevotes/game.sp @@ -2320,6 +2320,13 @@ static void TF2CSGO_DisplayVote(NativeVote vote, int[] clients, int num_clients) SetEntProp(g_VoteController, Prop_Send, "m_nPotentialVotes", num_clients); } + // required to allow the initiator to vote on their own issue + // ValveSoftware/Source-1-Games#3934 + if (sv_vote_holder_may_vote_no && vote.Initiator <= MaxClients) + { + sv_vote_holder_may_vote_no.ReplicateToClient(vote.Initiator, "1"); + } + MenuAction actions = Data_GetActions(vote); for (int i = 0; i < num_clients; ++i) @@ -2377,6 +2384,7 @@ static void TF2CSGO_DisplayVote(NativeVote vote, int[] clients, int num_clients) } bfStart.WriteBool(bYesNo); } + EndMessage(); }