Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Shutdown Dialog 1.0.0 #360

Merged
merged 3 commits into from
Nov 5, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions mods/custom-shutdown-dialog.wh.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// ==WindhawkMod==
// @id custom-shutdown-dialog
// @name Custom Shutdown Dialog
// @description Override the classic shutdown dialog in Explorer with your own
// @version 1.0.0
// @author aubymori
// @github https://github.com/aubymori
// @include explorer.exe
// @architecture x86-64
// ==/WindhawkMod==

// ==WindhawkModReadme==
/*
# Custom Shutdown Dialog
Override the classic shutdown dialog in Explorer
which is invoked with `ALT`+`F4` with your own program.
**This mod will only work on Windows 10 or greater and Windhawk v1.4 or greater.**
*/
// ==/WindhawkModReadme==

// ==WindhawkModSettings==
/*
- exe: C:\Classic\ClassicShutdown\ClassicShutdown.exe
$name: Executable
$description: Path to executable to open instead of dialog.
- args: /style classic
$name: Arguments
$description: Arguments to pass to the executable, if any.
*/
// ==/WindhawkModSettings==

#include <windhawk_utils.h>
#include <versionhelpers.h>

LPCWSTR g_szExe, g_szArgs;

typedef __int64 (* _ShutdownDialogEx_t)(HWND, int, int, UINT);
_ShutdownDialogEx_t _ShutdownDialogEx_orig;
__int64 _ShutdownDialogEx_hook(
HWND hWndParent,
int i1,
int i2,
UINT i3
)
{
ShellExecuteW(
hWndParent,
L"open",
g_szExe,
g_szArgs,
NULL,
SW_NORMAL
);
return 0;
}

void LoadSettings(void)
{
g_szExe = Wh_GetStringSetting(L"exe");
g_szArgs = Wh_GetStringSetting(L"args");
}

BOOL Wh_ModInit(void)
{
if (!IsWindows10OrGreater())
{
Wh_Log(L"This mod was designed for Windows 10 and up.");
return FALSE;
}

LoadSettings();

HMODULE hShutdownUx = LoadLibraryW(L"shutdownux.dll");
if (!hShutdownUx)
{
Wh_Log(L"Failed to load shutdownux.dll");
return FALSE;
}

WindhawkUtils::SYMBOL_HOOK hook = {
{
L"static _ShutdownDialogEx()"
},
&_ShutdownDialogEx_orig,
_ShutdownDialogEx_hook
};

if (!HookSymbols(hShutdownUx, &hook, 1))
{
Wh_Log(L"Failed to hook _ShutdownDialogEx");
return FALSE;
}

return TRUE;
}

void Wh_ModSettingsChanged(void)
{
LoadSettings();
aubymori marked this conversation as resolved.
Show resolved Hide resolved
}

void Wh_ModUninit(void)
{
Wh_FreeStringSetting(g_szExe);
Wh_FreeStringSetting(g_szArgs);
}
Loading