102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
window.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
15#include <math.h>
16#include <stdarg.h>
17#include <string.h>
18
19// Original pcdogs.exe: 0x43e330
20// Dispatches main-window input and lifecycle messages. WM_CLOSE tears down game subsystems, posts quit and terminates the process.
21LRESULT __stdcall Game_MainWindowProc(HWND hwnd, UINT u_msg, WPARAM w_param, LPARAM l_param)
22{
24
25 switch (u_msg)
26 {
27 case WM_KEYDOWN:
28 Input_SetKeyDown((char)(l_param >> 16));
30
31 return 0;
32
33 case WM_KEYUP:
34 Input_SetKeyUp((char)(l_param >> 16));
35
36 return 0;
37
38 case WM_SYSKEYDOWN:
39 case WM_SYSKEYUP:
40 case WM_MOVE:
41 case WM_SIZE:
42 return 0;
43
44 case WM_SYSCOMMAND:
45 if (w_param == SC_SCREENSAVE || w_param == SC_MONITORPOWER || w_param == SC_PREVWINDOW || w_param == SC_NEXTWINDOW ||
46 w_param == SC_MINIMIZE || w_param == SC_KEYMENU || w_param == SC_MOUSEMENU || w_param == SC_SIZE ||
47 w_param == SC_TASKLIST || w_param == SC_CLOSE)
48 return 0;
49
50 break;
51
52 case WM_DESTROY:
53 PostQuitMessage(0);
54
55 break;
56
57 case WM_CLOSE:
58 Debug_Log("---------Begin Shutdown Sequence--------", NULL);
59 Debug_Log("Unload Data", NULL);
60
62 {
65 Debug_Log("UninitGameInterface", NULL);
67 Debug_Log("KillGame", NULL);
69 }
70
71 Debug_Log("DirectInputRelease", NULL);
73 Debug_Log("UninitGame", NULL);
74
77
79 Debug_Log("DestroyWindow", NULL);
83 PostQuitMessage(0);
84 Debug_Log("------------Shutdown Complete-----------", NULL);
85 CRT_exit(0);
86 /* no return */
87 }
88
89 return DefWindowProcA(hwnd, u_msg, w_param, l_param);
90}
91
92// Original pcdogs.exe: 0x43e580
93// Returns the cached main-window handle without validation or transferring ownership.
95{
96 return Window_MainHandle;
97}
98
99// Original pcdogs.exe: 0x43e890
100// Clears the screen-saver-running setting and sends WM_CLOSE to the main window to request shutdown.
102{
103 int32_t screen_saver_previous_state;
104
105 SystemParametersInfoA(SPI_SETSCREENSAVERRUNNING, 0, &screen_saver_previous_state, 0);
106 SendMessageA(Window_MainHandle, WM_CLOSE, 0, 0);
107}
108
109// Original pcdogs.exe: 0x445090
110// Returns whether a current display window handle is recorded.
112{
113 /* 0x445096..0x44509a: XOR EAX,EAX; TEST ECX,ECX; SETNE AL. */
114 return Display_CurrentWindowHandle != NULL;
115}
116
117// Original pcdogs.exe: 0x4450a0
118// Requests display initialization for a different window and resets input state on success. The result reports whether the window differed, even if initialization failed.
119int32_t Display_SetMode(HWND hwnd)
120{
121 BOOL changed = hwnd != Display_CurrentWindowHandle;
122 if (!changed || D3D_InitDirectDrawAndDirect3D(hwnd))
123 {
126 }
127 return changed;
128}
129
130// Original pcdogs.exe: 0x4450e0
131// Releases graphics resources when a display window is recorded, leaving the cached window handle unchanged.
137
138// Original pcdogs.exe: 0x445100
139// Sets the default resolution to 640 by 480 and ignores its reserved argument.
140void Window_SetDefaultResolution(int32_t reserved_zero)
141{
142 (void)reserved_zero;
145}
void Debug_Log(char const *category, char const *message)
Definition diagnostics.c:17
#define Game_FrameTransitionFlags
Definition globals.h:47
#define GRAPHICS_DEFAULT_WIDTH
Definition constants.h:25
#define GRAPHICS_DEFAULT_HEIGHT
Definition constants.h:26
#define Graphics_WindowWidth
Definition globals.h:140
#define Graphics_WindowHeight
Definition globals.h:143
void Input_ResetState(void)
Definition state.c:422
void Input_SetKeyDown(uint8_t scan_code)
Definition state.c:669
void DInput_ReleaseResources(void)
Definition devices.c:354
void Input_SetKeyUp(uint8_t scan_code)
Definition state.c:676
#define Input_ProcessWindowMessages_ShouldQuit
Definition globals.h:56
void Menu_ShutdownResources(void)
Definition state.c:86
void PKG_CleanupResourceGameState(void)
Definition resources.c:155
void Pkg_CleanupFinalResourceGame(void)
Definition resources.c:355
void Pkg_UnloadResourceGameData(void)
Definition resources.c:43
void D3D_ReleaseAllAndReportLeaks()
BOOL D3D_InitDirectDrawAndDirect3D(HWND hwnd)
#define Window_MainHandle
Definition globals.h:213
#define g_windowMessageState
Definition globals.h:195
#define Window_ProcessGameProc_Initialized
Definition globals.h:210
#define Display_CurrentWindowHandle
Definition globals.h:201
void CRT_exit(int32_t status)
Definition startup.c:135
@ SPI_SETSCREENSAVERRUNNING
void Display_ReleaseMode()
Definition window.c:132
int32_t Display_SetMode(HWND hwnd)
Definition window.c:119
void Window_SetDefaultResolution(int32_t reserved_zero)
Definition window.c:140
void Window_RequestClose()
Definition window.c:101
HWND Window_GetMainHandle()
Definition window.c:94
LRESULT Game_MainWindowProc(HWND hwnd, UINT u_msg, WPARAM w_param, LPARAM l_param)
Definition window.c:21
BOOL Display_IsActive()
Definition window.c:111