102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference |
GitLab repository
Toggle main menu visibility
Loading...
Searching...
No Matches
application.c
Go to the documentation of this file.
1
/* Recovered game implementation; original addresses identify provenance. */
2
#include "
pcdogs/platform/constants.h
"
3
#include "
pcdogs/graphics/functions.h
"
4
#include "
pcdogs/graphics/globals.h
"
5
#include "
pcdogs/image/globals.h
"
6
#include "
pcdogs/input/functions.h
"
7
#include "
pcdogs/input/globals.h
"
8
#include "
pcdogs/package/functions.h
"
9
#include "
pcdogs/platform/enums.h
"
10
#include "
pcdogs/platform/functions.h
"
11
#include "
pcdogs/platform/globals.h
"
12
#include "
pcdogs/runtime/functions.h
"
13
#include "
pcdogs/settings/functions.h
"
14
#include "
pcdogs/video/functions.h
"
15
#include "
pcdogs/video/globals.h
"
16
#include <math.h>
17
#include <stdarg.h>
18
#include <string.h>
19
20
// Original pcdogs.exe: 0x43e590
21
// Creates the main window, initializes the game and runs the process loop. Package-location failure does not abort initialization, and normal shutdown terminates through exit.
22
int32_t __stdcall
Game_WinMain
(HINSTANCE h_instance, HINSTANCE h_prev_instance, LPSTR lp_cmd_line, int32_t n_cmd_show)
23
{
24
(void)h_prev_instance;
25
(void)lp_cmd_line;
26
HINSTANCE application_instance = h_instance;
27
28
WNDCLASSA wnd_class;
29
wnd_class.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS | CS_CLASSDC;
30
wnd_class.lpfnWndProc =
Game_MainWindowProc
;
31
wnd_class.cbClsExtra = 0;
32
wnd_class.cbWndExtra = 0;
33
wnd_class.hInstance = application_instance;
34
// LPCSTR lpIconName for LoadIconA
35
// HINSTANCE hInstance for LoadIconA
36
wnd_class.hIcon = LoadIconA(NULL, (LPCSTR)(
WINDOW_ICON_RESOURCE_ID
));
37
wnd_class.hCursor = LoadCursorA(NULL, IDC_ARROW);
38
39
HGDIOBJ background_brush = GetStockObject(
BLACK_BRUSH
);
40
41
wnd_class.lpszMenuName = 0;
42
wnd_class.lpszClassName =
"102 Dalmatians"
;
43
wnd_class.hbrBackground = background_brush;
44
45
// Register the window class with Windows
46
if
(!RegisterClassA(&wnd_class))
47
{
48
// Registration failed - show error and CRT_exit
49
//
50
MessageBoxA(NULL,
"This program requires Windows NT!"
,
"102 Dalmatians"
,
MB_ICONHAND
);
51
52
return
0;
53
}
54
55
Window_ProcessGameProc_Initialized
= 0;
56
ACCEL paccel = (ACCEL){
57
.fVirt = FALT,
58
.key =
'A'
,
59
.cmd =
WINDOW_ACCELERATOR_COMMAND_ID
};
60
61
// Create Alt+A accelerator table
62
//
63
g_acceleratorTable
= (
global_type_g_acceleratorTable
)(CreateAcceleratorTableA(&paccel, 1));
64
Window_SetDefaultResolution
(0);
// Set initial window resolution (640x480)
65
RECT rect = (RECT){
66
.left = 0,
67
.top = 0,
68
.right =
Graphics_WindowWidth
,
69
.bottom =
Graphics_WindowHeight
};
70
71
AdjustWindowRect(&rect, (
WS_POPUP
|
WS_MAXIMIZE
|
WINDOW_ORIGINAL_STYLE_RESERVED
), 0);
// Adjust rect to account for window decorations
72
73
int32_t n_height = rect.bottom - rect.top;
74
int32_t n_width = rect.right - rect.left;
75
76
rect = (RECT){
77
.right = n_width,
78
.bottom = n_height,
79
.left = 0,
80
.top = 0};
81
82
// Create the main game window
83
HWND created_window = CreateWindowExA(
WS_EX_LEFT
,
"102 Dalmatians"
,
"102 Dalmatians"
, (
WS_POPUP
|
WS_MAXIMIZE
|
WINDOW_ORIGINAL_STYLE_RESERVED
), 0, 0,
84
n_width, n_height, NULL, NULL, application_instance, NULL);
85
86
Window_MainHandle
= created_window;
87
Window_RunWinMain_SecondaryWindowHandle
= created_window;
88
ShowCursor(0);
// Hide the mouse cursor
89
ShowWindow(
Window_MainHandle
, n_cmd_show);
90
UpdateWindow(
Window_MainHandle
);
91
Window_RunWinMain_RenderingEnabled
= 1;
92
93
// Keep hiding cursor until count reaches 0
94
while
(ShowCursor(0) > 0)
95
{
96
}
97
98
PKG_LocatePackagePath
();
// Locate and load the game's PAK file
99
Pkg_InitializeResourceGameEngine
();
// Initialize core game engine subsystems
100
101
HWND input_window =
Window_MainHandle
;
102
103
g_winMainShowCmd
= (
global_type_g_winMainShowCmd
)(application_instance);
104
// Initialize DirectDraw/Direct3D graphics
105
Input_InitializeInputSubsystem
(input_window, application_instance);
106
// Maximize the window
107
//
108
ShowWindow(
Window_MainHandle
,
SW_SHOWMAXIMIZED
);
109
110
Video_PlayMovieIntro
(0);
// Play intro movies (0-3) unless skipped
111
112
if
(!
g_videoSkipRequested
)
113
{
114
Video_PlayMovieIntro
(1);
115
116
if
(!
g_videoSkipRequested
)
117
{
118
Video_PlayMovieIntro
(2);
119
120
if
(!
g_videoSkipRequested
)
121
{
122
Video_PlayMovieIntro
(3);
123
}
124
}
125
}
126
127
if
(
Window_ProcessGameProc_Initialized
)
128
{
129
// Early CRT_exit if init failed during movies
130
CRT_exit
(0);
131
/* no return */
132
}
133
134
HWND package_window =
Window_MainHandle
;
135
136
Window_ProcessGameProc_Initialized
= 1;
137
PKG_InitializeSystem
(package_window, application_instance);
// Finalize graphics capabilities setup
138
139
HWND display_window =
Window_MainHandle
;
140
141
g_winMainInstanceHandle
= (
global_type_g_winMainInstanceHandle
)(display_window);
142
Display_SetMode
(display_window);
143
Config_InitializeInputMappingsAndLoadSettings
();
// Initialize remaining game systems (input, audio, etc)
144
Input_ProcessWindowMessages_ShouldQuit
= 0;
145
// Disable screensaver during gameplay
146
SystemParametersInfoA(
SPI_SETSCREENSAVERRUNNING
, 1, &h_instance, 0);
147
148
// ===== MAIN GAME LOOP =====
149
if
(
Input_ProcessWindowMessages
())
150
{
151
while
(!
Input_ProcessWindowMessages_ShouldQuit
)
152
{
153
if
(
Window_RunWinMain_RenderingEnabled
)
154
{
155
// Check if it's time to render a new frame
156
if
(
Display_IsActive
())
157
Graphics_RenderFrame
();
// Render the current frame
158
159
// Check for Alt+F4 hotkey to quit
160
if
(!
g_inputProcessedFlag
&&
Input_IsKeyPressed
(DIK_LMENU) &&
Input_IsKeyPressed
(DIK_F4))
161
{
162
SendMessageA(
Window_MainHandle
, WM_CLOSE, 0, 0);
// Send WM_CLOSE to trigger shutdown
163
Input_ProcessWindowMessages_ShouldQuit
= 1;
164
Window_ProcessGameProc_Initialized
= 1;
165
}
166
}
167
168
g_inputProcessedFlag
= 0;
169
170
if
(!
Input_ProcessWindowMessages
())
171
break
;
172
}
173
}
174
175
CRT_exit
(0);
// Cleanup and CRT_exit the program
176
/* no return */
177
}
Game_WinMain
int32_t Game_WinMain(HINSTANCE h_instance, HINSTANCE h_prev_instance, LPSTR lp_cmd_line, int32_t n_cmd_show)
Definition
application.c:22
functions.h
Graphics_RenderFrame
uint8_t Graphics_RenderFrame(void)
Definition
frame.c:180
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_ProcessWindowMessages
BOOL Input_ProcessWindowMessages(void)
Definition
state.c:371
Input_IsKeyPressed
uint8_t Input_IsKeyPressed(uint8_t scan_code)
Definition
state.c:640
Input_InitializeInputSubsystem
void Input_InitializeInputSubsystem(HWND hwnd, HINSTANCE h_instance)
Definition
state.c:195
globals.h
g_inputProcessedFlag
#define g_inputProcessedFlag
Definition
globals.h:59
Input_ProcessWindowMessages_ShouldQuit
#define Input_ProcessWindowMessages_ShouldQuit
Definition
globals.h:56
functions.h
PKG_LocatePackagePath
void PKG_LocatePackagePath(void)
Definition
archive.c:50
Pkg_InitializeResourceGameEngine
bool Pkg_InitializeResourceGameEngine(void)
Definition
resources.c:111
PKG_InitializeSystem
void PKG_InitializeSystem(HWND hwnd, HINSTANCE h_instance)
Definition
resources.c:366
constants.h
WINDOW_ACCELERATOR_COMMAND_ID
#define WINDOW_ACCELERATOR_COMMAND_ID
Definition
constants.h:7
WINDOW_ORIGINAL_STYLE_RESERVED
#define WINDOW_ORIGINAL_STYLE_RESERVED
Definition
constants.h:5
WINDOW_ICON_RESOURCE_ID
#define WINDOW_ICON_RESOURCE_ID
Definition
constants.h:6
enums.h
functions.h
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
Display_IsActive
BOOL Display_IsActive(void)
Definition
window.c:111
Game_MainWindowProc
LRESULT Game_MainWindowProc(HWND hwnd, UINT u_msg, WPARAM w_param, LPARAM l_param)
Definition
window.c:21
globals.h
Window_MainHandle
#define Window_MainHandle
Definition
globals.h:213
Window_RunWinMain_RenderingEnabled
#define Window_RunWinMain_RenderingEnabled
Definition
globals.h:207
Window_ProcessGameProc_Initialized
#define Window_ProcessGameProc_Initialized
Definition
globals.h:210
Window_RunWinMain_SecondaryWindowHandle
#define Window_RunWinMain_SecondaryWindowHandle
Definition
globals.h:198
functions.h
CRT_exit
void CRT_exit(int32_t status)
Definition
startup.c:135
functions.h
Config_InitializeInputMappingsAndLoadSettings
void Config_InitializeInputMappingsAndLoadSettings(void)
Definition
config.c:117
g_acceleratorTable
#define g_acceleratorTable
Definition
values.h:546
g_winMainShowCmd
#define g_winMainShowCmd
Definition
values.h:549
global_type_g_winMainInstanceHandle
int32_t global_type_g_winMainInstanceHandle
Definition
values.h:539
g_winMainInstanceHandle
#define g_winMainInstanceHandle
Definition
values.h:540
global_type_g_acceleratorTable
int32_t global_type_g_acceleratorTable
Definition
values.h:545
global_type_g_winMainShowCmd
int32_t global_type_g_winMainShowCmd
Definition
values.h:548
functions.h
Video_PlayMovieIntro
void Video_PlayMovieIntro(int32_t movie_index)
Definition
playback.c:215
globals.h
g_videoSkipRequested
#define g_videoSkipRequested
Definition
globals.h:65
BLACK_BRUSH
@ BLACK_BRUSH
Definition
win32_gdi.h:10
SPI_SETSCREENSAVERRUNNING
@ SPI_SETSCREENSAVERRUNNING
Definition
win32_system.h:229
MB_ICONHAND
#define MB_ICONHAND
Definition
win32_window.h:79
WS_MAXIMIZE
#define WS_MAXIMIZE
Definition
win32_window.h:359
WS_POPUP
#define WS_POPUP
Definition
win32_window.h:338
SW_SHOWMAXIMIZED
@ SW_SHOWMAXIMIZED
Definition
win32_window.h:210
WS_EX_LEFT
#define WS_EX_LEFT
Definition
win32_window.h:282
src
platform
application.c
Generated by
1.17.0