Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #192 from BitCrackers/FixVoting
Browse files Browse the repository at this point in the history
Fix Voting Events
  • Loading branch information
v0idp authored Jun 5, 2021
2 parents 549c534 + 71f7737 commit ba3c318
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion hooks/MeetingHud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "_hooks.h"
#include "state.hpp"
#include "game.h"
#include "logger.h"

void dMeetingHud_Awake(MeetingHud* __this, MethodInfo* method) {
State.voteMonitor.reset();
Expand All @@ -24,6 +25,7 @@ void dMeetingHud_Update(MeetingHud* __this, MethodInfo* method) {
auto localData = GetPlayerData(*Game::pLocalPlayer);
auto playerNameTMP = playerVoteArea->fields.NameText;


if (playerData && localData) {
Color32 faceColor = app::Color32_op_Implicit(Palette__TypeInfo->static_fields->Black, NULL);
if (State.RevealImpostors || localData->fields.IsImpostor) {
Expand All @@ -40,13 +42,25 @@ void dMeetingHud_Update(MeetingHud* __this, MethodInfo* method) {
app::TextMeshPro_SetFaceColor(playerNameTMP, c, NULL);
app::TextMeshPro_SetOutlineColor(playerNameTMP, faceColor, NULL);
}
}
//This is to not show the "Force skip all" that a host does at the end of a meeting
bool isDiscussionState = (__this->fields.discussionTimer < (*Game::pGameOptionsData)->fields.DiscussionTime);
bool isVotingState = !isDiscussionState &&
((__this->fields.discussionTimer - (*Game::pGameOptionsData)->fields.DiscussionTime) < (*Game::pGameOptionsData)->fields.VotingTime); //Voting phase

if (playerVoteArea && playerData)
{
// We are goign to check to see if they voted, then we are going to check to see who they voted for, finally we are going to check to see if we already recorded a vote for them
// votedFor will either contain the id of the person they voted for, -1 if they skipped, or -2 if they didn't vote. We don't want to record people who didn't vote
if (playerVoteArea->fields.didVote && playerVoteArea->fields.votedFor != -2 && !State.voteMonitor[playerData->fields.PlayerId]) {
if (isVotingState && playerVoteArea->fields.didVote && playerVoteArea->fields.votedFor != -2 && !State.voteMonitor[playerData->fields.PlayerId]) {
State.events[playerVoteArea->fields._TargetPlayerId_k__BackingField][EVENT_VOTE].push_back(new CastVoteEvent(*GetEventPlayer(playerData), GetEventPlayer(GetPlayerDataById(playerVoteArea->fields.votedFor))));
State.consoleEvents.push_back(new CastVoteEvent(*GetEventPlayer(playerData), GetEventPlayer(GetPlayerDataById(playerVoteArea->fields.votedFor))));
State.voteMonitor[playerData->fields.PlayerId] = true;
STREAM_DEBUG("Id " << +playerData->fields.PlayerId << " voted for " << +playerVoteArea->fields.votedFor);
}
else if (!playerVoteArea->fields.didVote && State.voteMonitor[playerData->fields.PlayerId])
{
State.voteMonitor[playerData->fields.PlayerId] = false; //Likely disconnected player
}
}
}
Expand Down

0 comments on commit ba3c318

Please sign in to comment.