[Proxy] Remove steam start

This commit is contained in:
momo5502 2017-06-07 11:22:38 +02:00
parent dc15f92b8b
commit 445c7825c0
7 changed files with 2 additions and 133 deletions

View File

@ -5,7 +5,6 @@ namespace Components
bool Loader::Pregame = true;
bool Loader::Postgame = false;
bool Loader::Uninitializing = false;
bool Loader::ComInitialized = false;
std::vector<Component*> Loader::Components;
bool Loader::IsPregame()
@ -23,11 +22,6 @@ namespace Components
return Loader::Uninitializing;
}
bool Loader::IsComInitialized()
{
return Loader::ComInitialized;
}
void Loader::Initialize()
{
Loader::Pregame = true;
@ -35,9 +29,6 @@ namespace Components
Loader::Uninitializing = false;
Utils::Memory::GetAllocator()->clear();
Loader::ComInitialized = false;
if (!Loader::PerformingUnitTests() && !Utils::IsWineEnvironment()) Loader::ComInitialized = (CoInitialize(nullptr) == S_OK);
Loader::Register(new Flags());
Loader::Register(new Singleton());
Loader::Register(new Exception()); // install our exception handler as early as posssible to get better debug dumps from startup crashes
@ -130,8 +121,6 @@ namespace Components
Loader::Components.clear();
Utils::Memory::GetAllocator()->clear();
if (!Loader::PerformingUnitTests() && !Utils::IsWineEnvironment() && Loader::ComInitialized) CoUninitialize();
Loader::Uninitializing = false;
}

View File

@ -38,7 +38,6 @@ namespace Components
static bool IsPregame();
static bool IsPostgame();
static bool IsUninitializing();
static bool IsComInitialized();
template <typename T>
static T* GetInstance()
@ -58,7 +57,6 @@ namespace Components
static bool Pregame;
static bool Postgame;
static bool Uninitializing;
static bool ComInitialized;
static std::vector<Component*> Components;
};
}

View File

@ -5,8 +5,6 @@ namespace Components
std::queue<Toast::UIToast> Toast::Queue;
std::mutex Toast::Mutex;
Toast::WinToastHandler* Toast::ToastHandler = nullptr;
void Toast::Show(std::string image, std::string title, std::string description, int length, Utils::Slot<void()> callback)
{
Game::Material* material = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, image.data()).material;
@ -20,12 +18,6 @@ namespace Components
Toast::Mutex.unlock();
}
bool Toast::ShowNative(const WinToastLib::WinToastTemplate& toast)
{
if (!Loader::IsComInitialized() || !Toast::ToastHandler) return false;
return WinToastLib::WinToast::instance()->showToast(toast, Toast::ToastHandler) != 0;
}
std::string Toast::GetIcon()
{
char ourPath[MAX_PATH] = { 0 };
@ -156,15 +148,6 @@ namespace Components
{
if (Dedicated::IsEnabled() || Monitor::IsEnabled()) return;
if (Loader::IsComInitialized())
{
Toast::ToastHandler = new Toast::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();
}
Scheduler::OnReady([]()
{
Scheduler::OnFrame(Toast::Handler);
@ -180,31 +163,4 @@ namespace Components
{
Toast::Queue = std::queue<Toast::UIToast>();
}
void Toast::preDestroy()
{
if (Dedicated::IsEnabled() || Monitor::IsEnabled() || !Loader::IsComInitialized()) return;
// Destroying that on the main thread deadlocks.
// I did not write the library, so whatever.
// If we are not in the postgame state,
// we are not allowed to spawn threads,
// so just don't uninitialize the library.
// That means we did not uninitialize the game
// correctly anyways.
if (Loader::IsPostgame())
{
std::thread([]()
{
delete WinToastLib::WinToast::instance();
delete Toast::ToastHandler;
Toast::ToastHandler = nullptr;
}).join();
}
else
{
delete Toast::ToastHandler;
Toast::ToastHandler = nullptr;
}
}
}

View File

@ -7,13 +7,9 @@ namespace Components
public:
Toast();
~Toast();
void preDestroy() override;
typedef WinToastLib::WinToastTemplate Template;
static void Show(std::string image, std::string title, std::string description, int length, Utils::Slot<void()> callback = Utils::Slot<void()>());
static void Show(Game::Material* material, std::string title, std::string description, int length, Utils::Slot<void()> callback = Utils::Slot<void()>());
static bool ShowNative(const WinToastLib::WinToastTemplate& toast);
static std::string GetIcon();
@ -29,20 +25,10 @@ namespace Components
Utils::Slot<void()> callback;
};
class WinToastHandler: public WinToastLib::IWinToastHandler
{
public:
void toastActivated() const override {};
void toastDismissed(WinToastLib::IWinToastHandler::WinToastDismissalReason /*state*/) const override {};
void toastFailed() const override {};
};
static void Handler();
static void Draw(UIToast* toast);
static std::queue<UIToast> Queue;
static std::mutex Mutex;
static WinToastHandler* ToastHandler;
};
}

View File

@ -20,6 +20,7 @@
#include <Aclapi.h>
#include <Psapi.h>
#include <tlhelp32.h>
#include <Shlwapi.h>
#pragma warning(push)
#pragma warning(disable: 4091)
@ -76,7 +77,6 @@ template <size_t S> class Sizer { };
#include <mongoose.h>
#include <json11.hpp>
#include <tomcrypt.h>
#include <wintoastlib.h>
#include <udis86.h>
#ifdef max

View File

@ -364,65 +364,6 @@ namespace Steam
});
}
void Proxy::StartSteamIfNecessary()
{
if (Proxy::GetSteamDirectory().empty() || !Steam::Enabled()) return;
HKEY hRegKey;
DWORD pid = 0;
if (RegOpenKeyExA(HKEY_CURRENT_USER, STEAM_REGISTRY_PROCESS_PATH, 0, KEY_QUERY_VALUE, &hRegKey) != ERROR_SUCCESS) return;
DWORD dwLength = sizeof(pid);
RegQueryValueExA(hRegKey, "pid", nullptr, nullptr, reinterpret_cast<BYTE*>(&pid), &dwLength);
RegCloseKey(hRegKey);
if (pid)
{
HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION, 0, pid);
if (process)
{
::Utils::Memory::Allocator allocator;
allocator.reference(process, [](HANDLE hProcess)
{
CloseHandle(hProcess);
});
allocator.reference(allocator.allocate(1), [](void*)
{
Proxy::LaunchWatchGuard();
});
DWORD exitCode;
if (!GetExitCodeProcess(process, &exitCode)) return;
if (exitCode == STILL_ACTIVE) return;
}
}
std::string steamExe = Proxy::GetSteamDirectory() + "\\steam.exe";
if (::Utils::IO::FileExists(steamExe))
{
Components::Toast::Template templ = Components::Toast::Template(Components::Toast::Template::ImageAndText02);
templ.setTextField(L"Please wait", Components::Toast::Template::FirstLine);
templ.setTextField(L"Starting Steam...", Components::Toast::Template::SecondLine);
std::string icon = Components::Toast::GetIcon();
templ.setImagePath(std::wstring(icon.begin(), icon.end()));
Components::Toast::ShowNative(templ);
// If steam has crashed, the user is not null, so we reset it to be able to check if steam started
if (Proxy::GetActiveUser()) Proxy::ResetActiveUser();
ShellExecuteA(nullptr, nullptr, steamExe.data(), "-silent", nullptr, 1);
::Utils::Time::Interval interval;
while (!interval.elapsed(15s) && !Proxy::GetActiveUser()) std::this_thread::sleep_for(10ms);
std::this_thread::sleep_for(1s);
}
Proxy::LaunchWatchGuard();
}
bool Proxy::Inititalize()
{
std::string directoy = Proxy::GetSteamDirectory();
@ -432,7 +373,7 @@ namespace Steam
if (!Components::Dedicated::IsEnabled() && !Components::ZoneBuilder::IsEnabled())
{
Proxy::StartSteamIfNecessary();
Proxy::LaunchWatchGuard();
Proxy::Overlay = ::Utils::Library(GAMEOVERLAY_LIB, false);
if (!Proxy::Overlay.valid()) return false;

View File

@ -354,7 +354,6 @@ namespace Steam
static void RunCallback(int32_t callId, void* data, size_t size);
static void UnregisterCalls();
static void StartSteamIfNecessary();
static void LaunchWatchGuard();
static void ResetActiveUser();