Skip to content

Commit

Permalink
Change writing timing a little bit, fix deinitializing Twitch connection
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedSnark committed Mar 17, 2024
1 parent 873523a commit 7176c26
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
16 changes: 8 additions & 8 deletions GSChaos/CChaos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ void CChaos::Init()
{
twitch = new Twitch();
twitch->OnConnected = [this] {
pEngfuncs->Con_Printf("Connected to Twitch.\n");
printf("Connected to Twitch.\n");
twitch->SendChatMessage("GSChaos: connected!");
m_bTwitchVoting = true;
InitVotingSystem();
};
twitch->OnDisconnected = [this] {
pEngfuncs->Con_Printf("Disconnected from Twitch.\n");
printf("Disconnected from Twitch.\n");
m_bTwitchVoting = false;
};
twitch->OnError = [this](int errorCode, const std::string& error) {
pEngfuncs->Con_Printf("Twitch error. Code: %i | Error: %s\n", errorCode, error.c_str());
printf("Twitch error. Code: %i | Error: %s\n", errorCode, error.c_str());
};
twitch->OnMessage = [this](const std::string& user, const std::string& msg) {
Vote(user, msg);
Expand Down Expand Up @@ -288,11 +288,11 @@ void CChaos::VoteThink()

if (m_bStartedVoting)
{
static double timeToWrite = GetGlobalTime() + 1.0;
static double timeToWrite = GetGlobalTime() + CHAOS_VOTING_PROGRESS_UPDATE_TIME;
if (timeToWrite <= GetGlobalTime())
{
WriteVotingProgress();
timeToWrite = GetGlobalTime() + 1.0;
timeToWrite = GetGlobalTime() + CHAOS_VOTING_PROGRESS_UPDATE_TIME;
}

return;
Expand All @@ -307,7 +307,7 @@ void CChaos::VoteThink()
void CChaos::WriteVotingProgress()
{
std::ofstream outFile(CHAOS_VOTING_PROGRESS_FILE, std::ofstream::trunc);

if (!outFile)
{
pEngfuncs->Con_Printf("[CHAOS] Failed to open " CHAOS_VOTING_PROGRESS_FILE " for writing!\n");
Expand Down Expand Up @@ -378,8 +378,8 @@ void CChaos::Reset()

void CChaos::Shutdown()
{
if (twitch && twitch->status != TWITCH_DISCONNECTED)
twitch->Disconnect();
if (twitch)
delete twitch;
}

void CChaos::PrintVersion()
Expand Down
4 changes: 3 additions & 1 deletion GSChaos/CChaos.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

// Settings
#define CHAOS_ACTIVATE_TIMER 30.0

#define CHAOS_TWITCH_SETTINGS_FILE "chaos/twitch.ini"

#define CHAOS_VOTING_PROGRESS_UPDATE_TIME 0.75
#define CHAOS_VOTING_PROGRESS_FILE "chaos/voting_progress.txt"

struct TwitchVoter
Expand All @@ -30,7 +33,6 @@ struct TwitchVoter
int value;
};


class CChaos
{
public:
Expand Down
3 changes: 2 additions & 1 deletion GSChaos/GSChaos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ extern "C" __declspec(dllexport) void ASIMain()

if (status != MH_OK)
{
printf("MH_STATUS: %s\n", MH_StatusToString(status));
MessageBoxA(NULL, "Failed to initialize MinHook. Exiting...", "GSChaos", MB_OK | MB_ICONERROR);
exit(1);
return;
Expand All @@ -453,9 +454,9 @@ extern "C" __declspec(dllexport) void ASIMain()

extern "C" __declspec(dllexport) void ASIShutdown()
{
gChaos.Shutdown();
ma_engine_uninit(&miniAudio);
MH_Uninitialize();
gChaos.Shutdown();
}

/*
Expand Down

0 comments on commit 7176c26

Please sign in to comment.