102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference |
GitLab repository
Toggle main menu visibility
Loading...
Searching...
No Matches
window.c
Go to the documentation of this file.
1
/* Recovered game implementation; original addresses identify provenance. */
2
#include "
pcdogs/graphics/constants.h
"
3
#include "
pcdogs/debug/functions.h
"
4
#include "
pcdogs/game/globals.h
"
5
#include "
pcdogs/graphics/globals.h
"
6
#include "
pcdogs/image/globals.h
"
7
#include "
pcdogs/input/functions.h
"
8
#include "
pcdogs/input/globals.h
"
9
#include "
pcdogs/menu/functions.h
"
10
#include "
pcdogs/package/functions.h
"
11
#include "
pcdogs/platform/enums.h
"
12
#include "
pcdogs/platform/functions.h
"
13
#include "
pcdogs/platform/globals.h
"
14
#include "
pcdogs/runtime/functions.h
"
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.
21
LRESULT __stdcall
Game_MainWindowProc
(HWND hwnd, UINT u_msg, WPARAM w_param, LPARAM l_param)
22
{
23
g_windowMessageState
= 0;
24
25
switch
(u_msg)
26
{
27
case
WM_KEYDOWN:
28
Input_SetKeyDown
((
char
)(l_param >> 16));
29
g_windowMessageState
= 1;
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
61
if
(
Window_ProcessGameProc_Initialized
)
62
{
63
Pkg_UnloadResourceGameData
();
64
PKG_CleanupResourceGameState
();
65
Debug_Log
(
"UninitGameInterface"
, NULL);
66
Menu_ShutdownResources
();
67
Debug_Log
(
"KillGame"
, NULL);
68
Display_ReleaseMode
();
69
}
70
71
Debug_Log
(
"DirectInputRelease"
, NULL);
72
DInput_ReleaseResources
();
73
Debug_Log
(
"UninitGame"
, NULL);
74
75
if
(
Window_ProcessGameProc_Initialized
)
76
Pkg_CleanupFinalResourceGame
();
77
78
Input_ProcessWindowMessages_ShouldQuit
= 1;
79
Debug_Log
(
"DestroyWindow"
, NULL);
80
Input_ProcessWindowMessages_ShouldQuit
= 1;
81
Game_FrameTransitionFlags
= 0;
82
Window_ProcessGameProc_Initialized
= 1;
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.
94
HWND
Window_GetMainHandle
()
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.
101
void
Window_RequestClose
()
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.
111
BOOL
Display_IsActive
()
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.
119
int32_t
Display_SetMode
(HWND hwnd)
120
{
121
BOOL changed = hwnd !=
Display_CurrentWindowHandle
;
122
if
(!changed ||
D3D_InitDirectDrawAndDirect3D
(hwnd))
123
{
124
Display_CurrentWindowHandle
= hwnd;
125
Input_ResetState
();
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.
132
void
Display_ReleaseMode
()
133
{
134
if
(
Display_CurrentWindowHandle
)
135
D3D_ReleaseAllAndReportLeaks
();
136
}
137
138
// Original pcdogs.exe: 0x445100
139
// Sets the default resolution to 640 by 480 and ignores its reserved argument.
140
void
Window_SetDefaultResolution
(int32_t reserved_zero)
141
{
142
(void)reserved_zero;
143
Graphics_WindowWidth
=
GRAPHICS_DEFAULT_WIDTH
;
144
Graphics_WindowHeight
=
GRAPHICS_DEFAULT_HEIGHT
;
145
}
functions.h
Debug_Log
void Debug_Log(char const *category, char const *message)
Definition
diagnostics.c:17
globals.h
Game_FrameTransitionFlags
#define Game_FrameTransitionFlags
Definition
globals.h:47
constants.h
GRAPHICS_DEFAULT_WIDTH
#define GRAPHICS_DEFAULT_WIDTH
Definition
constants.h:25
GRAPHICS_DEFAULT_HEIGHT
#define GRAPHICS_DEFAULT_HEIGHT
Definition
constants.h:26
globals.h
Graphics_WindowWidth
#define Graphics_WindowWidth
Definition
globals.h:140
Graphics_WindowHeight
#define Graphics_WindowHeight
Definition
globals.h:143
globals.h
functions.h
Input_ResetState
void Input_ResetState(void)
Definition
state.c:422
Input_SetKeyDown
void Input_SetKeyDown(uint8_t scan_code)
Definition
state.c:669
DInput_ReleaseResources
void DInput_ReleaseResources(void)
Definition
devices.c:354
Input_SetKeyUp
void Input_SetKeyUp(uint8_t scan_code)
Definition
state.c:676
globals.h
Input_ProcessWindowMessages_ShouldQuit
#define Input_ProcessWindowMessages_ShouldQuit
Definition
globals.h:56
functions.h
Menu_ShutdownResources
void Menu_ShutdownResources(void)
Definition
state.c:86
functions.h
PKG_CleanupResourceGameState
void PKG_CleanupResourceGameState(void)
Definition
resources.c:155
Pkg_CleanupFinalResourceGame
void Pkg_CleanupFinalResourceGame(void)
Definition
resources.c:355
Pkg_UnloadResourceGameData
void Pkg_UnloadResourceGameData(void)
Definition
resources.c:43
enums.h
functions.h
D3D_ReleaseAllAndReportLeaks
void D3D_ReleaseAllAndReportLeaks()
Definition
graphics_system.c:359
D3D_InitDirectDrawAndDirect3D
BOOL D3D_InitDirectDrawAndDirect3D(HWND hwnd)
Definition
graphics_system.c:22
globals.h
Window_MainHandle
#define Window_MainHandle
Definition
globals.h:213
g_windowMessageState
#define g_windowMessageState
Definition
globals.h:195
Window_ProcessGameProc_Initialized
#define Window_ProcessGameProc_Initialized
Definition
globals.h:210
Display_CurrentWindowHandle
#define Display_CurrentWindowHandle
Definition
globals.h:201
functions.h
CRT_exit
void CRT_exit(int32_t status)
Definition
startup.c:135
SPI_SETSCREENSAVERRUNNING
@ SPI_SETSCREENSAVERRUNNING
Definition
win32_system.h:229
Display_ReleaseMode
void Display_ReleaseMode()
Definition
window.c:132
Display_SetMode
int32_t Display_SetMode(HWND hwnd)
Definition
window.c:119
Window_SetDefaultResolution
void Window_SetDefaultResolution(int32_t reserved_zero)
Definition
window.c:140
Window_RequestClose
void Window_RequestClose()
Definition
window.c:101
Window_GetMainHandle
HWND Window_GetMainHandle()
Definition
window.c:94
Game_MainWindowProc
LRESULT Game_MainWindowProc(HWND hwnd, UINT u_msg, WPARAM w_param, LPARAM l_param)
Definition
window.c:21
Display_IsActive
BOOL Display_IsActive()
Definition
window.c:111
src
platform
window.c
Generated by
1.17.0