From 7176c264addf64eea75b454166490db02f12513b Mon Sep 17 00:00:00 2001 From: ScriptedSnark <51358194+ScriptedSnark@users.noreply.github.com> Date: Sun, 17 Mar 2024 13:32:49 +0500 Subject: [PATCH] Change writing timing a little bit, fix deinitializing Twitch connection --- GSChaos/CChaos.cpp | 16 ++++++++-------- GSChaos/CChaos.h | 4 +++- GSChaos/GSChaos.cpp | 3 ++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/GSChaos/CChaos.cpp b/GSChaos/CChaos.cpp index 760349db..3e4383c4 100644 --- a/GSChaos/CChaos.cpp +++ b/GSChaos/CChaos.cpp @@ -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); @@ -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; @@ -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"); @@ -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() diff --git a/GSChaos/CChaos.h b/GSChaos/CChaos.h index ee2d1af4..3a43d5ae 100644 --- a/GSChaos/CChaos.h +++ b/GSChaos/CChaos.h @@ -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 @@ -30,7 +33,6 @@ struct TwitchVoter int value; }; - class CChaos { public: diff --git a/GSChaos/GSChaos.cpp b/GSChaos/GSChaos.cpp index b13fe858..6bca299a 100644 --- a/GSChaos/GSChaos.cpp +++ b/GSChaos/GSChaos.cpp @@ -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; @@ -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(); } /*