2021-10-16 20:36:30 +00:00
|
|
|
/*
|
2022-01-06 23:38:21 +00:00
|
|
|
Copyright 2021-2022 Peter Repukat - FlatspotSoftware
|
2021-10-16 20:36:30 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2021-10-21 17:58:58 +00:00
|
|
|
#include "SteamOverlayDetector.h"
|
2021-10-16 20:36:30 +00:00
|
|
|
|
|
|
|
#include <spdlog/spdlog.h>
|
|
|
|
|
2022-09-20 18:00:50 +00:00
|
|
|
#include "Settings.h"
|
|
|
|
|
2021-10-16 20:36:30 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#define NOMINMAX
|
|
|
|
#include <Windows.h>
|
|
|
|
#endif
|
|
|
|
|
2021-10-21 17:58:58 +00:00
|
|
|
SteamOverlayDetector::SteamOverlayDetector(std::function<void(bool)> overlay_changed)
|
2021-10-16 20:36:30 +00:00
|
|
|
: overlay_changed_(std::move(overlay_changed))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-10-21 17:58:58 +00:00
|
|
|
void SteamOverlayDetector::update()
|
2021-10-16 20:36:30 +00:00
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
2021-10-16 23:38:11 +00:00
|
|
|
// Steam hooks into Windows messages
|
|
|
|
// as long as the overlay is open, every msg (except for input messages?)
|
|
|
|
// get's the message field set to `0`
|
|
|
|
// to detect the overlay, just exploit this.
|
|
|
|
// if the message is 0 3 frames consecutively -> overlay is open
|
|
|
|
// not -> closed
|
|
|
|
//
|
|
|
|
// i'm guessing something very similar is done on linux
|
|
|
|
// however
|
|
|
|
// reversing on linux SUUUUUUUCKS!
|
|
|
|
MSG msg;
|
2021-10-17 01:45:21 +00:00
|
|
|
// okey to use nullptr as hwnd. get EVERY message
|
|
|
|
if (PeekMessage(&msg, nullptr, 0, 0, PM_NOREMOVE)) {
|
2021-10-16 23:38:11 +00:00
|
|
|
// filter out some messages as not all get altered by steam...
|
2022-09-20 18:00:50 +00:00
|
|
|
|
2022-09-20 18:18:40 +00:00
|
|
|
if (Settings::extendedLogging && msg.message != 512 && msg.message != 5374) {
|
2022-09-20 18:00:50 +00:00
|
|
|
spdlog::trace("PeekMessage: Window msg: {}", msg.message);
|
|
|
|
}
|
|
|
|
|
2021-10-16 23:38:11 +00:00
|
|
|
if (msg.message < 1000 && msg.message > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (msg.message == 0 && !overlay_open_) {
|
|
|
|
msg_count_++;
|
|
|
|
if (msg_count_ >= 3) {
|
|
|
|
msg_count_ = 0;
|
|
|
|
overlay_open_ = true;
|
2022-03-05 14:34:23 +00:00
|
|
|
spdlog::debug("Overlay opened");
|
2021-10-16 23:38:11 +00:00
|
|
|
overlay_changed_(overlay_open_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (msg.message != 0 && overlay_open_) {
|
|
|
|
msg_count_++;
|
|
|
|
if (msg_count_ >= 3) {
|
|
|
|
msg_count_ = 0;
|
|
|
|
overlay_open_ = false;
|
2022-03-05 14:34:23 +00:00
|
|
|
spdlog::debug("Overlay closed");
|
2021-10-16 23:38:11 +00:00
|
|
|
overlay_changed_(overlay_open_);
|
|
|
|
}
|
|
|
|
}
|
2021-10-16 20:36:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
2021-10-22 13:40:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SteamOverlayDetector::IsSteamInjected()
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
return GetModuleHandle(L"GameOverlayRenderer64.dll") != nullptr;
|
|
|
|
#endif
|
|
|
|
}
|