diff --git a/src/Components/Loader.cpp b/src/Components/Loader.cpp index 39a33a42..9da5dfe9 100644 --- a/src/Components/Loader.cpp +++ b/src/Components/Loader.cpp @@ -18,12 +18,18 @@ namespace Components return Loader::Postgame; } + bool Loader::IsComInitialized() + { + return Loader::ComInitialized; + } + void Loader::Initialize() { Loader::Pregame = true; Loader::Postgame = false; Loader::MemAllocator.clear(); + Loader::ComInitialized = false; if (!Loader::PerformingUnitTests()) Loader::ComInitialized = (CoInitialize(nullptr) == S_OK); Loader::Register(new Flags()); diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index dfdb92bf..f7b79ab5 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -32,6 +32,7 @@ namespace Components static bool IsPregame(); static bool IsPostgame(); + static bool IsComInitialized(); static Utils::Memory::Allocator* GetAlloctor(); diff --git a/src/Components/Modules/Toast.cpp b/src/Components/Modules/Toast.cpp index b2efc50d..267afea1 100644 --- a/src/Components/Modules/Toast.cpp +++ b/src/Components/Modules/Toast.cpp @@ -16,7 +16,7 @@ namespace Components bool Toast::ShowNative(const WinToastLib::WinToastTemplate& toast) { - if (!Toast::ToastHandler) return false; + if (!Loader::IsComInitialized() || !Toast::ToastHandler) return false; return WinToastLib::WinToast::instance()->showToast(toast, Toast::ToastHandler); } @@ -146,13 +146,16 @@ namespace Components Toast::Toast() { - if (Dedicated::IsEnabled() || Monitor::IsEnabled() || Loader::PerformingUnitTests()) return; + if (Dedicated::IsEnabled() || Monitor::IsEnabled()) return; - Toast::ToastHandler = new WinToastLib::WinToastHandler; + if (Loader::IsComInitialized()) + { + Toast::ToastHandler = new WinToastLib::WinToastHandler; - WinToastLib::WinToast::instance()->setAppName(L"IW4x"); - WinToastLib::WinToast::instance()->setAppUserModelId(WinToastLib::WinToast::configureAUMI(L"IW4x", L"IW4x", L"IW4x", L"0")); - WinToastLib::WinToast::instance()->initialize(); + WinToastLib::WinToast::instance()->setAppName(L"IW4x"); + WinToastLib::WinToast::instance()->setAppUserModelId(WinToastLib::WinToast::configureAUMI(L"IW4x", L"IW4x", L"IW4x", L"0")); + WinToastLib::WinToast::instance()->initialize(); + } QuickPatch::OnReady([]() { @@ -172,7 +175,7 @@ namespace Components void Toast::preDestroy() { - if (Dedicated::IsEnabled() || Monitor::IsEnabled() || Loader::PerformingUnitTests()) return; + if (Dedicated::IsEnabled() || Monitor::IsEnabled() || !Loader::IsComInitialized()) return; // Destroying that on the main thread deadlocks. // I did not write the library, so whatever.