-
Notifications
You must be signed in to change notification settings - Fork 6
/
DllMain.c
111 lines (96 loc) · 3.84 KB
/
DllMain.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include <windows.h>
DWORD WINAPI ThreadProc(LPVOID);
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static NOTIFYICONDATAW s_Data = {.cbSize = sizeof(NOTIFYICONDATAW),
.uCallbackMessage = WM_USER,
.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP,
.szTip = L"NoSteamWebHelper"};
static UINT s_uTaskbarRestart = WM_NULL;
switch (uMsg)
{
case WM_CREATE:
s_uTaskbarRestart = RegisterWindowMessageW(L"TaskbarCreated");
s_Data.hWnd = hWnd;
s_Data.hIcon = LoadIconW(NULL, IDI_APPLICATION);
Shell_NotifyIconW(NIM_ADD, &s_Data);
break;
case WM_USER:
if (lParam == WM_RBUTTONDOWN)
{
POINT Point = {};
HMENU hMenu = CreatePopupMenu();
GetCursorPos(&Point);
AppendMenuW(hMenu, MF_STRING, 1, L"On");
AppendMenuW(hMenu, MF_STRING, 2, L"Off");
SetForegroundWindow(hWnd);
RegSetKeyValueW(
HKEY_CURRENT_USER, L"SOFTWARE\\Valve\\Steam", L"RunningAppID", REG_DWORD,
&((DWORD){TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON | TPM_RETURNCMD, Point.x,
Point.y, 0, hWnd, NULL) == 2
? 1
: 0}),
sizeof(DWORD));
DestroyMenu(hMenu);
}
break;
default:
if (uMsg == s_uTaskbarRestart)
Shell_NotifyIconW(NIM_ADD, &s_Data);
break;
}
return DefWindowProcW(hWnd, uMsg, wParam, lParam);
}
VOID CALLBACK WinEventProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG idChild,
DWORD dwEventThread, DWORD dwmsEventTime)
{
WCHAR szClassName[16] = {};
GetClassNameW(hwnd, szClassName, 16);
if (CompareStringOrdinal(L"vguiPopupWindow", -1, szClassName, -1, FALSE) != CSTR_EQUAL ||
GetWindowTextLengthW(hwnd) < 1)
return;
CloseHandle(CreateThread(NULL, 0, ThreadProc, (LPVOID)TRUE, 0, NULL));
HANDLE hThread = OpenThread(THREAD_SUSPEND_RESUME, FALSE, dwEventThread);
HKEY hKey = NULL;
RegOpenKeyExW(HKEY_CURRENT_USER, L"SOFTWARE\\Valve\\Steam", REG_OPTION_NON_VOLATILE, KEY_NOTIFY | KEY_QUERY_VALUE,
&hKey);
while (!RegNotifyChangeKeyValue(hKey, FALSE, REG_NOTIFY_CHANGE_LAST_SET, NULL, FALSE))
{
DWORD dwRunningAppID = 0;
RegGetValueW(hKey, NULL, L"RunningAppID", RRF_RT_REG_DWORD, NULL, (PVOID)&dwRunningAppID,
&((DWORD){sizeof(DWORD)}));
(dwRunningAppID ? SuspendThread : ResumeThread)(hThread);
if (dwRunningAppID)
EndTask(FindWindowW(L"SDL_app", L"Steam"), FALSE, TRUE);
}
}
DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
MSG msg = {};
if (lpParameter)
{
HINSTANCE hInstance = GetModuleHandleW(NULL);
RegisterClassW(&((WNDCLASSW){
.lpszClassName = L"NoSteamWebHelper", .hInstance = hInstance, .lpfnWndProc = (WNDPROC)WndProc}));
CreateWindowExW(WS_EX_LEFT | WS_EX_LTRREADING, L"NoSteamWebHelper", NULL, WS_OVERLAPPED, 0, 0, 0, 0, NULL, NULL,
hInstance, NULL);
}
else
SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_OBJECT_CREATE, NULL, WinEventProc, GetCurrentProcessId(), 0,
WINEVENT_OUTOFCONTEXT);
while (GetMessageW(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return 0;
}
BOOL WINAPI DllMainCRTStartup(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if (fdwReason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hinstDLL);
CloseHandle(CreateThread(NULL, 0, ThreadProc, (LPVOID)FALSE, 0, NULL));
}
return TRUE;
}