Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alia5 committed Oct 5, 2022
2 parents 29b630d + eacd05b commit 1c18e84
Show file tree
Hide file tree
Showing 20 changed files with 193 additions and 121 deletions.
29 changes: 25 additions & 4 deletions GlosSIConfig/UIModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ limitations under the License.
#ifdef _WIN32
#include "UWPFetch.h"
#include <Windows.h>
#include <shlobj.h>
#endif

#include "../version.hpp"

UIModel::UIModel() : QObject(nullptr)
{
auto path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
wchar_t* localAppDataFolder;
std::filesystem::path path;
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
path = std::filesystem::path(localAppDataFolder).parent_path();
}

path /= "Roaming";
path /= "GlosSI";
Expand Down Expand Up @@ -307,7 +315,14 @@ void UIModel::updateCheck()

QVariantMap UIModel::getDefaultConf() const
{
auto path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
wchar_t* localAppDataFolder;
std::filesystem::path path;
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
path = std::filesystem::path(localAppDataFolder).parent_path();
}

path /= "Roaming";
path /= "GlosSI";
Expand Down Expand Up @@ -371,8 +386,14 @@ QVariantMap UIModel::getDefaultConf() const

void UIModel::saveDefaultConf(QVariantMap conf) const
{
auto path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();

wchar_t* localAppDataFolder;
std::filesystem::path path;
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
path = std::filesystem::path(localAppDataFolder).parent_path();
}
path /= "Roaming";
path /= "GlosSI";
path /= "default.json";
Expand Down
26 changes: 17 additions & 9 deletions GlosSIConfig/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ limitations under the License.
#include <Windows.h>
#include <VersionHelpers.h>
#include <dwmapi.h>
#include <ShlObj.h>
#pragma comment(lib, "Dwmapi.lib")
#include "ExeImageProvider.h"
#endif
Expand Down Expand Up @@ -89,10 +90,14 @@ void myMessageHandler(QtMsgType type, const QMessageLogContext&, const QString&
break;
}

auto path = std::filesystem::temp_directory_path()
.parent_path()
.parent_path()
.parent_path();
wchar_t* localAppDataFolder;
std::filesystem::path path;
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
path = std::filesystem::path(localAppDataFolder).parent_path();
}

path /= "Roaming";
path /= "GlosSI";
Expand All @@ -115,11 +120,14 @@ int main(int argc, char* argv[])
#endif

if (argc < 3) {
auto path = std::filesystem::temp_directory_path()
.parent_path()
.parent_path()
.parent_path();

wchar_t* localAppDataFolder;
std::filesystem::path path;
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
path = std::filesystem::path(localAppDataFolder).parent_path();
}
path /= "Roaming";
path /= "GlosSI";
if (!std::filesystem::exists(path))
Expand Down
2 changes: 1 addition & 1 deletion GlosSIConfig/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ Window {
titleText: qsTr("New version available!")
text: uiModel.newVersionName + "\n\n" + qsTr("Would you like to visit the download page now?")
onConfirmed: function (callback) {
Qt.openUrlExternally(`https://glossi.flatspot.pictures/#downloads${ uiModel.newVersionName.includes('snapshot') ? '-snapshots' : '' }-${uiModel.newVersionName}`);
callback();
Qt.openUrlExternally(`https://glossi.flatspot.pictures/#downloads-${uiModel.newVersionName}`);
}
buttonText: qsTr("Yes")
extraButton: true
Expand Down
24 changes: 0 additions & 24 deletions GlosSITarget/AppLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,30 +112,6 @@ void AppLauncher::close()
#endif
}

void AppLauncher::launchWatchdog()
{
// wchar_t buff[MAX_PATH];
// GetModuleFileName(GetModuleHandle(NULL), buff, MAX_PATH);
// const std::wstring glossipath(buff);

// GetWindowsDirectory(buff, MAX_PATH);
// const std::wstring winpath(buff);

// launchWin32App(
// (glossipath.substr(0, 1 + glossipath.find_last_of(L'\\')) + L"GlosSIWatchdog.exe"),
// L"",
// true);

spdlog::debug("Launching GlosSIWatchdog");

char buff[MAX_PATH];
GetModuleFileNameA(GetModuleHandle(NULL), buff, MAX_PATH);
const std::string glossipath(buff);
// hack to start a TRULY detached process...
const auto launchString = ("start /b cmd.exe /c \"" + (glossipath.substr(0, 1 + glossipath.find_last_of(L'\\')) + "GlosSIWatchdog.exe" + "\""));
system(launchString.data());
}

#ifdef _WIN32
bool AppLauncher::IsProcessRunning(DWORD pid)
{
Expand Down
4 changes: 1 addition & 3 deletions GlosSITarget/AppLauncher.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ class AppLauncher {
void launchApp(const std::wstring& path, const std::wstring& args = L"");
void update();
void close();

void launchWatchdog();


private:
std::function<void()> shutdown_;
sf::Clock process_check_clock_;
Expand Down
23 changes: 23 additions & 0 deletions GlosSITarget/DllInjector.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <tlhelp32.h>
#include <spdlog/spdlog.h>

#include "util.h"

namespace DllInjector {

inline bool TakeDebugPrivilege()
Expand Down Expand Up @@ -107,4 +109,25 @@ inline bool findModule(DWORD pid, std::wstring& lib_path, HMODULE& hMod)
return false;
}

inline void injectDllInto(std::filesystem::path dllPath, const std::wstring& processName)
{
if (std::filesystem::exists(dllPath)) {
const auto explorer_pid = glossi_util::PidByName(processName);
if (explorer_pid != 0) {
if (DllInjector::TakeDebugPrivilege()) {
// No need to eject, as the dll is self-ejecting.
if (DllInjector::Inject(explorer_pid, dllPath.wstring())) {
spdlog::info(L"Successfully injected {} into {}", dllPath.filename().wstring(), processName);
}
}
}
else {
spdlog::error(L"{} not found", processName); // needs loglevel WTF
}
}
else {
spdlog::error(L"{} not found", dllPath.wstring());
}
}

}; // namespace DllInjector
1 change: 1 addition & 0 deletions GlosSITarget/GlosSITarget.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@
<ClInclude Include="steam_sf_keymap.h" />
<ClInclude Include="TargetWindow.h" />
<ClInclude Include="UnhookUtil.h" />
<ClInclude Include="util.h" />
<ClInclude Include="UWPOverlayEnabler.h" />
</ItemGroup>
<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions GlosSITarget/GlosSITarget.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@
<ClInclude Include="UnhookUtil.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="util.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\deps\SFML\out\Debug\lib\Debug\sfml-system-d-2.dll" />
Expand Down
2 changes: 1 addition & 1 deletion GlosSITarget/InputRedirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void InputRedirector::runLoop()
unplugVigemPad(i);
}
}
sf::sleep(sf::milliseconds(1));
sf::sleep(sf::milliseconds(4));

#endif
}
Expand Down
13 changes: 9 additions & 4 deletions GlosSITarget/Overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License.
#include <locale>
#include <codecvt>
#include <regex>
#include <shlobj_core.h>

#include "Roboto.h"
#include "Settings.h"
Expand Down Expand Up @@ -51,10 +52,14 @@ Overlay::Overlay(
ImGui::SFML::UpdateFontTexture();

#ifdef _WIN32
auto config_path = std::filesystem::temp_directory_path()
.parent_path()
.parent_path()
.parent_path();
wchar_t* localAppDataFolder;
std::filesystem::path config_path;
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
config_path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
config_path = std::filesystem::path(localAppDataFolder).parent_path();
}

config_path /= "Roaming";
config_path /= "GlosSI";
Expand Down
14 changes: 10 additions & 4 deletions GlosSITarget/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ limitations under the License.
#ifdef WIN32
#define NOMINMAX
#include <Windows.h>
#include <ShlObj.h>
#include <KnownFolders.h>
#endif

namespace Settings {
Expand Down Expand Up @@ -122,10 +124,14 @@ inline void Parse(std::wstring arg1)
arg1 += L".json";
}
}
std::filesystem::path path = std::filesystem::temp_directory_path()
.parent_path()
.parent_path()
.parent_path();
wchar_t* localAppDataFolder;
std::filesystem::path path;
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, NULL, &localAppDataFolder) != S_OK) {
path = std::filesystem::temp_directory_path().parent_path().parent_path().parent_path();
}
else {
path = std::filesystem::path(localAppDataFolder).parent_path();
}

path /= "Roaming";
path /= "GlosSI";
Expand Down
20 changes: 14 additions & 6 deletions GlosSITarget/SteamTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ Application will not function!");
if (!overlay_.expired())
overlay_.lock()->setEnabled(false);
steam_overlay_present_ = true;
launcher_.launchWatchdog();

#ifdef WIN32
wchar_t buff[MAX_PATH];
GetModuleFileName(GetModuleHandle(NULL), buff, MAX_PATH);
std::wstring watchDogPath(buff);
watchDogPath = watchDogPath.substr(0, 1 + watchDogPath.find_last_of(L'\\')) + L"GlosSIWatchdog.dll";

DllInjector::injectDllInto(watchDogPath, L"explorer.exe");
#endif
}
getXBCRebindingEnabled();

Expand Down Expand Up @@ -214,7 +222,7 @@ void SteamTarget::focusWindow(WindowHandle hndl)

AttachThreadInput(current_thread, fg_thread, FALSE);

//try to forcefully set foreground window at least a few times
// try to forcefully set foreground window at least a few times
sf::Clock clock;
while (!SetForegroundWindow(hndl) && clock.getElapsedTime().asMilliseconds() < 20) {
SetActiveWindow(hndl);
Expand Down Expand Up @@ -310,23 +318,23 @@ std::vector<std::string> SteamTarget::getScreenshotHotkey()
const auto config_path = std::wstring(steam_path_) + std::wstring(user_data_path_) + steam_user_id_ + std::wstring(config_file_name_);
if (!std::filesystem::exists(config_path)) {
spdlog::warn(L"Couldn't read Steam config file: \"{}\"", config_path);
return {"KEY_F12"}; //default
return {"KEY_F12"}; // default
}
std::ifstream config_file(config_path);
auto root = tyti::vdf::read(config_file);

std::shared_ptr<tyti::vdf::basic_object<char>> children = root.childs["system"];
if (!children || children->attribs.empty() || !children->attribs.contains("InGameOverlayScreenshotHotKey")) {
spdlog::warn("Couldn't detect overlay hotkey, using default: F12");
return {"KEY_F12"}; //default
return {"KEY_F12"}; // default
}
auto hotkeys = children->attribs.at("InGameOverlayScreenshotHotKey");

// has anyone more than 4 keys to screenshot?!
std::smatch m;
if (!std::regex_match(hotkeys, m, std::regex(R"((\w*)\s*(\w*)\s*(\w*)\s*(\w*))"))) {
spdlog::warn("Couldn't detect overlay hotkey, using default: F12");
return {"KEY_F12"}; //default
return {"KEY_F12"}; // default
}

std::vector<std::string> res;
Expand All @@ -338,7 +346,7 @@ std::vector<std::string> SteamTarget::getScreenshotHotkey()
}
if (res.empty()) {
spdlog::warn("Couldn't detect overlay hotkey, using default: F12");
return {"KEY_F12"}; //default
return {"KEY_F12"}; // default
}
spdlog::info("Detected screenshot hotkey(s): {}", std::accumulate(
res.begin() + 1, res.end(), res[0],
Expand Down
34 changes: 2 additions & 32 deletions GlosSITarget/UWPOverlayEnabler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "DllInjector.h"
#include "Overlay.h"
#include "util.h"

namespace UWPOverlayEnabler {

Expand All @@ -18,44 +19,13 @@ inline std::filesystem::path EnablerPath()
return path.substr(0, 1 + path.find_last_of(L'\\')) + L"UWPOverlayEnablerDLL.dll";
}

inline DWORD ExplorerPid()
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE) {
while (Process32Next(snapshot, &entry) == TRUE) {
if (std::wstring(entry.szExeFile).find(L"explorer.exe") != std::string::npos) {
return entry.th32ProcessID;
}
}
}
CloseHandle(snapshot);
return 0;
}

} // namespace internal

inline void EnableUwpOverlay()
{
const auto enabler_path = internal::EnablerPath();
if (std::filesystem::exists(enabler_path)) {
const auto explorer_pid = internal::ExplorerPid();
if (explorer_pid != 0) {
if (DllInjector::TakeDebugPrivilege()) {
// No need to eject, as the dll is self-ejecting.
if (DllInjector::Inject(explorer_pid, enabler_path.wstring())) {
spdlog::info("Successfully injected UWPOverlay enabler into explorer.exe");
}
}
}
else {
spdlog::error("explorer not found"); // needs loglevel WTF
}
}
else {
spdlog::error("UWPOverlayEnablerDLL not found");
}
DllInjector::injectDllInto(enabler_path, L"explorer.exe");
}

inline void AddUwpOverlayOvWidget()
Expand Down
Loading

0 comments on commit 1c18e84

Please sign in to comment.