/* JNetHack Copyright */
/* (c) Issei Numata, Naoki Hamada, Shigehiro Miyashita, 1994-2000 */
-/* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2016 */
+/* For 3.4-, Copyright (c) SHIRAKATA Kentaro, 2002-2022 */
/* JNetHack may be freely redistributed. See license for details. */
#include "winMS.h"
'b', 'n', 'm', ',', '.', '?' /* ... */
};
+#define IDT_FUZZ_TIMER 100
+
/*
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
LRESULT CALLBACK
MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- PNHMainWindow data;
+ PNHMainWindow data = (PNHMainWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
#if 1 /*JP*/
static int doublebyte = 0;
#endif
break;
case WM_KEYDOWN: {
- data = (PNHMainWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
/* translate arrow keys into nethack commands */
switch (wParam) {
NHEVENT_KBD(KEYTABLE(KEY_PLUS));
return 0;
+#if defined(DEBUG) && defined(_MSC_VER)
+ case VK_PAUSE:
+ if (IsDebuggerPresent()) {
+ iflags.debug_fuzzer = !iflags.debug_fuzzer;
+ return 0;
+ }
+ break;
+#endif
+
case VK_CLEAR: /* This is the '5' key */
NHEVENT_KBD(KEYTABLE(KEY_GOINTERESTING));
return 0;
bail((char *) 0);
} else {
/* prompt user for action */
-/*JP
+#if 0 /*JP*/
switch (NHMessageBox(hWnd, TEXT("Save?"),
-*/
- switch (NHMessageBox(hWnd, TEXT("\95Û\91¶\82µ\82Ä\8fI\97¹\82µ\82Ü\82·\82©\81H"),
+#else
+ switch (NHMessageBox(hWnd, TEXT("\95Û\91¶\82µ\82Ä\8fI\97¹\82µ\82Ü\82·\82©\81H"),
+#endif
MB_YESNOCANCEL | MB_ICONQUESTION)) {
case IDYES:
#ifdef SAFERHANGUP
exit(1);
break;
+ case WM_DPICHANGED: {
+ mswin_layout_main_window(NULL);
+ } break;
+
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
child = GetNHApp()->windowlist[msg_param->wid].win;
} break;
+
+ case MSNH_MSG_RANDOM_INPUT: {
+ nhassert(iflags.debug_fuzzer);
+ NHEVENT_KBD(randomkey());
+ } break;
+
}
}
GetNHApp()->rtInvenWindow.bottom = GetNHApp()->rtMenuWindow.bottom;
/* adjust map window size only if perm_invent is set */
- if (flags.perm_invent)
+ if (iflags.perm_invent)
GetNHApp()->rtMapWindow.right = GetNHApp()->rtMenuWindow.left;
}
/* kludge - inventory window should have its own type (same as
menu-text
as a matter of fact) */
- if (flags.perm_invent && i == WIN_INVEN) {
+ if (iflags.perm_invent && i == WIN_INVEN) {
mswin_get_window_placement(NHW_INVEN, &rt);
} else {
mswin_get_window_placement(GetNHApp()->windowlist[i].type,
SetForegroundWindow(changed_child);
}
+VOID CALLBACK FuzzTimerProc(
+ _In_ HWND hwnd,
+ _In_ UINT uMsg,
+ _In_ UINT_PTR idEvent,
+ _In_ DWORD dwTime
+ )
+{
+ INPUT input[16];
+ int i_pos = 0;
+ int c = randomkey();
+ SHORT k = VkKeyScanA(c);
+ BOOL gen_alt = (rn2(50) == 0) && isalpha(c);
+
+ if (!iflags.debug_fuzzer) {
+ KillTimer(hwnd, IDT_FUZZ_TIMER);
+ return;
+ }
+
+ if (!GetFocus())
+ return;
+
+ ZeroMemory(input, sizeof(input));
+ if (gen_alt) {
+ input[i_pos].type = INPUT_KEYBOARD;
+ input[i_pos].ki.dwFlags = KEYEVENTF_SCANCODE;
+ input[i_pos].ki.wScan = MapVirtualKey(VK_MENU, 0);
+ i_pos++;
+ }
+
+ if (HIBYTE(k) & 1) {
+ input[i_pos].type = INPUT_KEYBOARD;
+ input[i_pos].ki.dwFlags = KEYEVENTF_SCANCODE;
+ input[i_pos].ki.wScan = MapVirtualKey(VK_LSHIFT, 0);
+ i_pos++;
+ }
+
+ input[i_pos].type = INPUT_KEYBOARD;
+ input[i_pos].ki.dwFlags = KEYEVENTF_SCANCODE;
+ input[i_pos].ki.wScan = MapVirtualKey(LOBYTE(k), 0);
+ i_pos++;
+
+ if (HIBYTE(k) & 1) {
+ input[i_pos].type = INPUT_KEYBOARD;
+ input[i_pos].ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
+ input[i_pos].ki.wScan = MapVirtualKey(VK_LSHIFT, 0);
+ i_pos++;
+ }
+ if (gen_alt) {
+ input[i_pos].type = INPUT_KEYBOARD;
+ input[i_pos].ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP;
+ input[i_pos].ki.wScan = MapVirtualKey(VK_MENU, 0);
+ i_pos++;
+ }
+ SendInput(i_pos, input, sizeof(input[0]));
+}
+
LRESULT
onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
mswin_display_splash_window(TRUE);
break;
+ case IDM_FUZZ:
+ if (iflags.debug_fuzzer)
+ KillTimer(hWnd, IDT_FUZZ_TIMER);
+ else
+ SetTimer(hWnd, IDT_FUZZ_TIMER, 10, FuzzTimerProc);
+ iflags.debug_fuzzer = !iflags.debug_fuzzer;
+ break;
case IDM_EXIT:
+ if (iflags.debug_fuzzer)
+ break;
done2();
break;
case IDM_SAVE:
+ if (iflags.debug_fuzzer)
+ break;
if (!program_state.gameover && !program_state.done_hup)
dosave();
else
if (!OpenClipboard(hWnd)) {
NHMessageBox(hWnd, TEXT("Cannot open clipboard"),
MB_OK | MB_ICONERROR);
+ free(p);
return 0;
}
hglbCopy = GlobalAlloc(GMEM_MOVEABLE, (len + 1) * sizeof(char));
if (hglbCopy == NULL) {
CloseClipboard();
+ free(p);
return FALSE;
}
wchar_t *wtext;
int tlen = 0;
+ if (iflags.debug_fuzzer)
+ break;
+
ZeroMemory(filename, sizeof(filename));
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);