GlosSITarget: Add HttpServer: Get launched pids

pull/192/head
Peter Repukat 2 years ago
parent ab575c1e29
commit c9c6a32432

3
.gitmodules vendored

@ -34,3 +34,6 @@
[submodule "deps/Shortcuts_VDF"]
path = deps/Shortcuts_VDF
url = git@github.com:Alia5/Shortcuts_VDF.git
[submodule "deps/cpp-httplib"]
path = deps/cpp-httplib
url = git@github.com:yhirose/cpp-httplib.git

@ -23,6 +23,8 @@ limitations under the License.
#include <tlhelp32.h>
#include <Propsys.h>
#include <propkey.h>
#include <shellapi.h>
#pragma comment(lib, "Shell32.lib")
#endif
@ -67,6 +69,7 @@ void AppLauncher::launchApp(const std::wstring& path, const std::wstring& args)
void AppLauncher::update()
{
if (process_check_clock_.getElapsedTime().asMilliseconds() > 250) {
pid_mutex_.lock();
#ifdef _WIN32
if (!pids_.empty() && pids_[0] > 0) {
if (Settings::launch.waitForChildProcs) {
@ -98,6 +101,7 @@ void AppLauncher::update()
}
getProcessHwnds();
#endif
pid_mutex_.unlock();
process_check_clock_.restart();
}
}
@ -112,6 +116,16 @@ void AppLauncher::close()
#endif
}
std::vector<DWORD> AppLauncher::launchedPids()
{
pid_mutex_.lock();
std::vector<DWORD> res = pids_;
std::ranges::copy(pids_.begin(), pids_.end(),
std::back_inserter(res));
pid_mutex_.unlock();
return res;
}
#ifdef _WIN32
bool AppLauncher::IsProcessRunning(DWORD pid)
{
@ -213,7 +227,9 @@ void AppLauncher::launchWin32App(const std::wstring& path, const std::wstring& a
// spdlog::info(L"Started Program: \"{}\" in directory: \"{}\"", native_seps_path, launch_dir);
spdlog::info(L"Started Program: \"{}\"; PID: {}", native_seps_path, process_info.dwProcessId);
if (!watchdog) {
pid_mutex_.lock();
pids_.push_back(process_info.dwProcessId);
pid_mutex_.unlock();
}
}
else {
@ -243,7 +259,7 @@ void AppLauncher::launchUWPApp(const LPCWSTR package_full_name, const std::wstri
if (!SUCCEEDED(result)) {
spdlog::warn("CoAllowSetForegroundWindow failed. Code: {}", result);
}
pid_mutex_.lock();
pids_.push_back(0);
// Launch the app
result = sp_app_activation_manager->ActivateApplication(
@ -258,6 +274,7 @@ void AppLauncher::launchUWPApp(const LPCWSTR package_full_name, const std::wstri
else {
spdlog::info(L"Launched UWP Package \"{}\"; PID: {}", package_full_name, pids_[0]);
}
pid_mutex_.unlock();
}
else {
spdlog::error("CoCreateInstance failed: Code {}", result);
@ -298,8 +315,10 @@ void AppLauncher::launchURL(const std::wstring& url, const std::wstring& args, c
if (execute_info.hProcess != nullptr) {
if (const auto pid = GetProcessId(execute_info.hProcess); pid > 0) {
pid_mutex_.lock();
pids_.push_back(pid);
spdlog::trace("Launched URL; PID: {}", pid);
pid_mutex_.unlock();
return;
}
}

@ -17,9 +17,11 @@ limitations under the License.
#ifdef _WIN32
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#endif
#include <functional>
#include <mutex>
#include <string>
#include <unordered_set>
#include <SFML/System/Clock.hpp>
@ -33,10 +35,13 @@ class AppLauncher {
void launchApp(const std::wstring& path, const std::wstring& args = L"");
void update();
void close();
std::vector<DWORD> launchedPids();
private:
std::function<void()> shutdown_;
sf::Clock process_check_clock_;
std::mutex pid_mutex_;
#ifdef _WIN32
static bool IsProcessRunning(DWORD pid);

@ -80,7 +80,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<ExternalIncludePath>..\deps\SFML\include;..\deps\WinReg;..\deps\spdlog\include;..\deps\ValveFileVDF;..\deps\subhook;..\deps\ViGEmClient\include;..\deps\imgui;..\deps\imgui-sfml;..\deps\json\include;..\deps\traypp\tray\include;$(ExternalIncludePath)</ExternalIncludePath>
<ExternalIncludePath>..\deps\SFML\include;..\deps\WinReg;..\deps\spdlog\include;..\deps\ValveFileVDF;..\deps\subhook;..\deps\ViGEmClient\include;..\deps\imgui;..\deps\imgui-sfml;..\deps\json\include;..\deps\traypp\tray\include;..\deps\cpp-httplib;$(ExternalIncludePath)</ExternalIncludePath>
<LibraryPath>..\deps\SFML\out\Debug\lib\Debug;..\deps\ViGEmClient\lib\debug\x64;$(LibraryPath)</LibraryPath>
<CopyLocalProjectReference>false</CopyLocalProjectReference>
<CopyLocalDeploymentContent>true</CopyLocalDeploymentContent>
@ -88,7 +88,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<ExternalIncludePath>..\deps\SFML\include;..\deps\WinReg;..\deps\spdlog\include;..\deps\ValveFileVDF;..\deps\subhook;..\deps\ViGEmClient\include;..\deps\imgui;..\deps\imgui-sfml;..\deps\json\include;..\deps\traypp\tray\include;$(ExternalIncludePath)</ExternalIncludePath>
<ExternalIncludePath>..\deps\SFML\include;..\deps\WinReg;..\deps\spdlog\include;..\deps\ValveFileVDF;..\deps\subhook;..\deps\ViGEmClient\include;..\deps\imgui;..\deps\imgui-sfml;..\deps\json\include;..\deps\traypp\tray\include;..\deps\cpp-httplib;$(ExternalIncludePath)</ExternalIncludePath>
<LibraryPath>..\deps\SFML\out\Release\lib\RelWithDebInfo;..\deps\ViGEmClient\lib\release\x64;$(LibraryPath)</LibraryPath>
<CustomBuildBeforeTargets>ResourceCompile</CustomBuildBeforeTargets>
<CopyLocalDeploymentContent>true</CopyLocalDeploymentContent>
@ -188,6 +188,7 @@
<ClCompile Include="..\deps\traypp\tray\src\core\windows\tray.cpp" />
<ClCompile Include="AppLauncher.cpp" />
<ClCompile Include="HidHide.cpp" />
<ClCompile Include="HttpServer.cpp" />
<ClCompile Include="InputRedirector.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="Overlay.cpp" />
@ -204,6 +205,7 @@
<ClInclude Include="DllInjector.h" />
<ClInclude Include="GlosSI_logo.h" />
<ClInclude Include="HidHide.h" />
<ClInclude Include="HttpServer.h" />
<ClInclude Include="imconfig.h" />
<ClInclude Include="InputRedirector.h" />
<ClInclude Include="Overlay.h" />

@ -117,6 +117,9 @@
<ClCompile Include="UnhookUtil.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="HttpServer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="SteamTarget.h">
@ -185,6 +188,9 @@
<ClInclude Include="util.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="HttpServer.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\deps\SFML\out\Debug\lib\Debug\sfml-system-d-2.dll" />

@ -24,11 +24,10 @@ limitations under the License.
#include <spdlog/spdlog.h>
#include <vector>
#include <initguid.h>
// Device configuration related
#include <cfgmgr32.h>
#include <initguid.h>
//
#ifndef WATCHDOG
#include "Overlay.h"
#endif
@ -38,9 +37,14 @@ limitations under the License.
#include <devguid.h>
#include <devpkey.h>
#include <regex>
#include <cguid.h>
#include <atlbase.h>
#include "UnhookUtil.h"
#pragma comment(lib, "Setupapi.lib")
// {D61CA365-5AF4-4486-998B-9DB4734C6CA3}add the XUSB class GUID as it is missing in the public interfaces
DEFINE_GUID(GUID_DEVCLASS_XUSBCLASS, 0xD61CA365, 0x5AF4, 0x4486, 0x99, 0x8B, 0x9D, 0xB4, 0x73, 0x4C, 0x6C, 0xA3);
// {EC87F1E3-C13B-4100-B5F7-8B84D54260CB} add the XUSB interface class GUID as it is missing in the public interfaces

@ -15,7 +15,10 @@ limitations under the License.
*/
#pragma once
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <ntddscsi.h>
#include <winioctl.h>
#include <hidsdi.h>
@ -25,6 +28,7 @@ limitations under the License.
#include <map>
#include <string>
#include <vector>
#ifndef WATCHDOG
#include <SFML/System/Clock.hpp>
#endif

@ -0,0 +1,47 @@
/*
Copyright 2021-2022 Peter Repukat - FlatspotSoftware
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.
*/
#include "HttpServer.h"
#include <spdlog/spdlog.h>
#include <nlohmann/json.hpp>
#include "AppLauncher.h"
HttpServer::HttpServer(AppLauncher& app_launcher) : app_launcher_(app_launcher)
{}
void HttpServer::run()
{
server_.Get("/launched-pids", [this](const httplib::Request& req, httplib::Response& res) {
const nlohmann::json j = app_launcher_.launchedPids();
res.set_content(j.dump(), "text/json");
});
server_thread_ = std::thread([this]() {
if (!server_.listen("0.0.0.0", port_)) {
spdlog::error("Couldn't start http-server");
return;
}
spdlog::debug("Started http-server on port");
});
}
void HttpServer::stop()
{
server_.stop();
if (server_thread_.joinable())
server_thread_.join();
}

@ -0,0 +1,37 @@
/*
Copyright 2021-2022 Peter Repukat - FlatspotSoftware
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.
*/
#pragma once
#include <thread>
#include <httplib.h>
class AppLauncher;
class HttpServer {
public:
explicit HttpServer(AppLauncher& app_launcher);
void run();
void stop();
private:
httplib::Server server_;
std::thread server_thread_;
uint16_t port_ = 8756;
AppLauncher& app_launcher_;
};

@ -17,6 +17,7 @@ limitations under the License.
#include <thread>
#ifdef _WIN32
#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <Xinput.h>
#include <ViGEm/Client.h>

@ -51,8 +51,8 @@ END
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,0,9,1040000008386
PRODUCTVERSION 0,0,9,1040000008386
FILEVERSION 0,1,0,203000008020
PRODUCTVERSION 0,1,0,203000008020
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -69,12 +69,12 @@ BEGIN
BEGIN
VALUE "CompanyName", "Peter Repukat - FlatspotSoftware"
VALUE "FileDescription", "GlosSI - SteamTarget"
VALUE "FileVersion", "0.0.9.1-40-gdae8386"
VALUE "FileVersion", "0.1.0.2-3-gcea802b"
VALUE "InternalName", "GlosSITarget"
VALUE "LegalCopyright", "Copyright (C) 2021-2022 Peter Repukat - FlatspotSoftware"
VALUE "OriginalFilename", "GlosSITarget.exe"
VALUE "ProductName", "GlosSI"
VALUE "ProductVersion", "0.0.9.1-40-gdae8386"
VALUE "ProductVersion", "0.1.0.2-3-gcea802b"
END
END
BLOCK "VarFileInfo"
@ -160,6 +160,66 @@ IDI_ICON1 ICON "..\\GlosSI_Icon.ico"

@ -30,6 +30,7 @@ limitations under the License.
#include <tray.hpp>
#endif
SteamTarget::SteamTarget()
: window_(
[this] { run_ = false; },
@ -44,13 +45,15 @@ SteamTarget::SteamTarget()
launcher_(force_config_hwnds_, [this] {
delayed_shutdown_ = true;
delay_shutdown_clock_.restart();
})
}),
server_(launcher_)
{
target_window_handle_ = window_.getSystemHandle();
#ifdef _WIN32
if (Settings::cli.no_uwp_overlay) {
UWPOverlayEnabler::AddUwpOverlayOvWidget();
} else {
}
else {
UWPOverlayEnabler::EnableUwpOverlay();
}
#endif
@ -81,7 +84,7 @@ Application will not function!");
std::wstring watchDogPath(buff);
watchDogPath = watchDogPath.substr(0, 1 + watchDogPath.find_last_of(L'\\')) + L"GlosSIWatchdog.dll";
DllInjector::injectDllInto(watchDogPath, L"explorer.exe");
DllInjector::injectDllInto(watchDogPath, L"explorer.exe");
}
#endif
}
@ -124,6 +127,8 @@ Application will not function!");
run_ = false;
}});
server_.run();
while (run_) {
detector_.update();
overlayHotkeyWorkaround();
@ -140,6 +145,7 @@ Application will not function!");
}
tray.exit();
server_.stop();
#ifdef _WIN32
input_redirector_.stop();
hidhide_.disableHidHide();

@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#define WIN32_LEAN_AND_MEAN
#include "SteamOverlayDetector.h"
@ -27,6 +28,8 @@ limitations under the License.
#include "AppLauncher.h"
#include "Overlay.h"
#include "HttpServer.h"
#include <filesystem>
@ -81,6 +84,7 @@ class SteamTarget {
std::weak_ptr<Overlay> overlay_;
SteamOverlayDetector detector_;
AppLauncher launcher_;
HttpServer server_;
WindowHandle last_foreground_window_ = nullptr;
static inline WindowHandle target_window_handle_ = nullptr;

@ -14,11 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <Windows.h>
#include <DbgHelp.h>
#include <ShlObj.h>
#include <shellapi.h>
#endif
#include <httplib.h>
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>

1
deps/cpp-httplib vendored

@ -0,0 +1 @@
Subproject commit cae5a8be1c9ef8399f45b89f6fc55afb122808cb
Loading…
Cancel
Save