Skip to content

Commit

Permalink
Settings work properly + more
Browse files Browse the repository at this point in the history
Hook will no longer bring to font if auto_hook is on
  • Loading branch information
BttrDrgn committed May 12, 2022
1 parent 86d9236 commit 7727e49
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 25 deletions.
56 changes: 45 additions & 11 deletions src/app/hook/hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ bool hook::load(process_t proc)
#ifdef _M_AMD64
if (!proc.arch.compare("x86"))
{
ShellExecuteA(0, "open", "x86\\helper.exe", &logger::va("--pid %i --arch %s --hwnd %u", proc.pid, &proc.arch[0], proc.hwnd)[0], 0, 1);
ShellExecuteA(0, "open", "x86\\helper.exe", &logger::va("--pid %i --arch %s --hwnd %u --auto %i", proc.pid, &proc.arch[0], proc.hwnd, hook::auto_refresh)[0], 0, 1);
hook::injected_apps.emplace_back(proc);
return true;
}
#else
Expand Down Expand Up @@ -65,15 +66,20 @@ bool hook::load(process_t proc)
}
}

//Not sure one does the trick but they all sound nice
BringWindowToTop(proc.hwnd);
SetForegroundWindow(proc.hwnd);
SetFocus(proc.hwnd);
//Set to top most temporarily
SetWindowPos(proc.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
//Set back
SetWindowPos(proc.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
ShowWindow(proc.hwnd, SW_NORMAL);
if (!hook::auto_refresh)
{
//Not sure one does the trick but they all sound nice
BringWindowToTop(proc.hwnd);
SetForegroundWindow(proc.hwnd);
SetFocus(proc.hwnd);
//Set to top most temporarily
SetWindowPos(proc.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
//Set back
SetWindowPos(proc.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
ShowWindow(proc.hwnd, SW_NORMAL);
}

hook::injected_apps.emplace_back(proc);

return true;
}
Expand Down Expand Up @@ -145,6 +151,32 @@ int CALLBACK hook::get_window(HWND hWnd, LPARAM lparam)
if (!do_not_add)
{
hook::processes.emplace_back(process_t{ window_title, arch, std::string(exe), proc_id, hWnd });

if (hook::auto_refresh)
{
for (const std::string& hook : hook::auto_hook)
{
process_t proc = hook::processes[hook::processes.size() - 1];

if (proc.exe.find(hook))
{
if (hook::injected_apps.size() > 0)
{
for (const process_t& app : hook::injected_apps)
{
if (app.pid != proc_id)
{
hook::load(proc);
}
}
}
else if (hook::injected_apps.size() == 0)
{
hook::load(proc);
}
}
}
}
}
}

Expand Down Expand Up @@ -185,4 +217,6 @@ std::initializer_list<std::string> hook::dlls
#endif
};

bool hook::auto_refresh = false;
bool hook::auto_refresh = false;
std::vector<std::string> hook::auto_hook;
std::vector<process_t> hook::injected_apps;
2 changes: 2 additions & 0 deletions src/app/hook/hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ class hook
static bool load(process_t proc);
static void get_procs();
static bool auto_refresh;
static std::vector<std::string> auto_hook;

private:
static int CALLBACK get_window(HWND hWnd, LPARAM lparam);
static std::initializer_list<std::string> blacklist;
static std::initializer_list<std::string> dlls;
static std::vector<process_t> injected_apps;
};
1 change: 0 additions & 1 deletion src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ void init_app()

audio::init();
menus::init();
hook::get_procs();

while (!global::shutdown)
{
Expand Down
5 changes: 3 additions & 2 deletions src/app/menus/menus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class menus
static std::vector<vec2> snow;
static std::int32_t max_points;
static bool show_snow;

static void render_snow();
static void enumerate_snow();
#endif

static bool show_all_stations;
Expand All @@ -37,7 +40,5 @@ class menus

#ifndef OVERLAY
static void overlay();
static void render_snow();
static void enumerate_snow();
#endif
};
34 changes: 32 additions & 2 deletions src/app/settings/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "settings.hpp"
#include "menus/menus.hpp"
#include "api/api.hpp"
#include "hook/hook.hpp"
#include "drpc/drpc.hpp"

void settings::init()
{
Expand All @@ -22,19 +24,41 @@ void settings::update()
"UseGPU = false\n"
"[startup]\n"
"Refresh = false\n"
#ifdef _WIN32
"Discord = false\n"
"AutoHook = false\n"
#endif
"Snow = false\n";

settings::config = ini_create(ini_default, strlen(ini_default));

ini_save(settings::config, &settings::config_file[0]);
}

menus::show_drpc = settings::get_boolean(ini_get(settings::config, "startup", "Discord"));
#ifdef _WIN32
if (menus::show_drpc = settings::get_boolean(ini_get(settings::config, "startup", "Discord")))
{
drpc::init();
}

#ifndef OVERLAY
if (hook::auto_refresh = settings::get_boolean(ini_get(settings::config, "startup", "AutoHook")))
{
hook::get_procs();
}
#endif
#endif

#ifndef OVERLAY
global::use_hardware = settings::get_boolean(ini_get(settings::config, "core", "UseGPU"));
menus::show_snow = settings::get_boolean(ini_get(settings::config, "startup", "Snow"));
if (menus::show_snow = settings::get_boolean(ini_get(settings::config, "startup", "Snow")))
{
if (menus::snow.empty())
{
menus::enumerate_snow();
}
menus::render_snow();
}
#endif

if (settings::get_boolean(ini_get(settings::config, "startup", "Refresh")))
Expand All @@ -43,6 +67,11 @@ void settings::update()
}

ini_free(settings::config);

#ifndef OVERLAY
if (!fs::exists(settings::auto_hook_file)) fs::write(settings::auto_hook_file, "", false);
hook::auto_hook = logger::split(fs::read(settings::auto_hook_file), ',');
#endif
}

void settings::favorites_update()
Expand Down Expand Up @@ -152,4 +181,5 @@ bool settings::get_boolean(const char* bool_text)

std::string settings::config_file = logger::va("%s%s", &fs::get_pref_dir()[0], "config.ini");
std::string settings::favorites_file = logger::va("%s%s", &fs::get_pref_dir()[0], "stations.fav");;
std::string settings::auto_hook_file = logger::va("%s%s", &fs::get_pref_dir()[0], "auto_hook.list");;
ini_t* settings::config;
1 change: 1 addition & 0 deletions src/app/settings/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ class settings
private:
static std::string config_file;
static std::string favorites_file;
static std::string auto_hook_file;
static ini_t* config;
};
27 changes: 18 additions & 9 deletions src/helper/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ std::initializer_list<std::string> dlls
};

bool failed = false;
bool manual = true;

void load()
{
Expand Down Expand Up @@ -62,15 +63,18 @@ void load()
exit(0);
}

//Not sure one does the trick but they all sound nice
BringWindowToTop(proc.hwnd);
SetForegroundWindow(proc.hwnd);
SetFocus(proc.hwnd);
//Set to top most temporarily
SetWindowPos(proc.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
//Set back
SetWindowPos(proc.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
ShowWindow(proc.hwnd, SW_NORMAL);
if (manual)
{
//Not sure one does the trick but they all sound nice
BringWindowToTop(proc.hwnd);
SetForegroundWindow(proc.hwnd);
SetFocus(proc.hwnd);
//Set to top most temporarily
SetWindowPos(proc.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
//Set back
SetWindowPos(proc.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
ShowWindow(proc.hwnd, SW_NORMAL);
}
}

int __stdcall WinMain(HINSTANCE instance, HINSTANCE prev_instance, char* cmd_line, int cmd_show)
Expand Down Expand Up @@ -104,6 +108,11 @@ int __stdcall WinMain(HINSTANCE instance, HINSTANCE prev_instance, char* cmd_lin
HWND value = reinterpret_cast<HWND>(std::stoul(__argv[i + 1], nullptr, 0));
proc.hwnd = value;
}
else if (args[i].find("--auto") != std::string::npos)
{
int value = std::stoi(__argv[i + 1]);
manual = value;
}
}

if (!proc.pid || proc.arch.size() == 0 || proc.hwnd == 0)
Expand Down

0 comments on commit 7727e49

Please sign in to comment.