Skip to content

Commit

Permalink
ChaosMod/Voting: Delay starting of voting proxy
Browse files Browse the repository at this point in the history
Appears to fix OnFailureToReceiveJoinConfirmation being called which then led to the "Invalid Twitch channel" error popup on newer versions
  • Loading branch information
pongo1231 committed Feb 4, 2024
1 parent f8198fa commit b09bf92
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 34 deletions.
81 changes: 48 additions & 33 deletions ChaosMod/Components/Voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,6 @@ Voting::Voting(const std::array<BYTE, 3> &textColor) : Component(), m_TextColor(
m_EnableVoting =
g_OptionsManager.GetVotingValue({ "EnableVoting", "EnableTwitchVoting" }, OPTION_DEFAULT_TWITCH_VOTING_ENABLED);
m_VoteablePrefix = g_OptionsManager.GetVotingValue<std::string>({ "VoteablePrefix" }, "");

if (m_EnableVoting && !Init())
{
return;
}

m_PipeHandle =
CreateNamedPipe(L"\\\\.\\pipe\\ChaosModVVotingPipe", PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_NOWAIT, 1, BUFFER_SIZE, BUFFER_SIZE, 0, NULL);

if (m_PipeHandle == INVALID_HANDLE_VALUE)
{
ErrorOutWithMsg("Error while creating a named pipe, previous instance of voting proxy might be running. Try "
"reloading the mod. Reverting to normal mode.");

return;
}

ConnectNamedPipe(m_PipeHandle, NULL);

if (m_EnableVoting)
{
if ((m_OverlayMode == OverlayMode::OverlayIngame || m_OverlayMode == OverlayMode::OverlayOBS)
&& ComponentExists<EffectDispatcher>())
{
GetComponent<EffectDispatcher>()->EnableEffectTextExtraTopSpace = true;
}

if (ComponentExists<SplashTexts>())
{
GetComponent<SplashTexts>()->ShowVotingSplash();
}
}
}

Voting::~Voting()
Expand All @@ -77,6 +44,54 @@ void Voting::OnRun()
return;
}

if (!m_HasInitializedVoting)
{
// Only initialize voting proxy after we are fully loaded in, otherwise some weird behaviour can occur from the
// voting proxy, e.g. OnFailureToReceiveJoinConfirmation being raised for whatever reason
if (GET_IS_LOADING_SCREEN_ACTIVE())
{
return;
}

m_HasInitializedVoting = true;

if (!Init())
{
return;
}

m_PipeHandle = CreateNamedPipe(L"\\\\.\\pipe\\ChaosModVVotingPipe", PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_NOWAIT, 1, BUFFER_SIZE,
BUFFER_SIZE, 0, NULL);

if (m_PipeHandle == INVALID_HANDLE_VALUE)
{
ErrorOutWithMsg(
"Error while creating a named pipe, previous instance of voting proxy might be running. Try "
"reloading the mod. Reverting to normal mode.");

return;
}

ConnectNamedPipe(m_PipeHandle, NULL);

if (m_EnableVoting)
{
if ((m_OverlayMode == OverlayMode::OverlayIngame || m_OverlayMode == OverlayMode::OverlayOBS)
&& ComponentExists<EffectDispatcher>())
{
GetComponent<EffectDispatcher>()->EnableEffectTextExtraTopSpace = true;
}

if (ComponentExists<SplashTexts>())
{
GetComponent<SplashTexts>()->ShowVotingSplash();
}
}

return;
}

// Check if there's been no ping for too long and error out
// Also if the chance system is enabled, get current vote status every second (if shown on screen)
auto curTick = GetTickCount64();
Expand Down
3 changes: 2 additions & 1 deletion ChaosMod/Components/Voting.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class Voting : public Component

std::array<std::uint8_t, 3> m_TextColor;

bool m_EnableVoting;
bool m_EnableVoting = false;
bool m_HasInitializedVoting = false;

bool m_ReceivedHello = false;
bool m_HasReceivedResult = false;
Expand Down

0 comments on commit b09bf92

Please sign in to comment.