102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
application.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
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.
22int32_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
56 ACCEL paccel = (ACCEL){
57 .fVirt = FALT,
58 .key = 'A',
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;
88 ShowCursor(0); // Hide the mouse cursor
89 ShowWindow(Window_MainHandle, n_cmd_show);
90 UpdateWindow(Window_MainHandle);
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 //
109
110 Video_PlayMovieIntro(0); // Play intro movies (0-3) unless skipped
111
113 {
115
117 {
119
121 {
123 }
124 }
125 }
126
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
137 PKG_InitializeSystem(package_window, application_instance); // Finalize graphics capabilities setup
138
139 HWND display_window = Window_MainHandle;
140
142 Display_SetMode(display_window);
143 Config_InitializeInputMappingsAndLoadSettings(); // Initialize remaining game systems (input, audio, etc)
145 // Disable screensaver during gameplay
146 SystemParametersInfoA(SPI_SETSCREENSAVERRUNNING, 1, &h_instance, 0);
147
148 // ===== MAIN GAME LOOP =====
150 {
152 {
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
165 }
166 }
167
169
171 break;
172 }
173 }
174
175 CRT_exit(0); // Cleanup and CRT_exit the program
176 /* no return */
177}
int32_t Game_WinMain(HINSTANCE h_instance, HINSTANCE h_prev_instance, LPSTR lp_cmd_line, int32_t n_cmd_show)
Definition application.c:22
uint8_t Graphics_RenderFrame(void)
Definition frame.c:180
#define Graphics_WindowWidth
Definition globals.h:140
#define Graphics_WindowHeight
Definition globals.h:143
BOOL Input_ProcessWindowMessages(void)
Definition state.c:371
uint8_t Input_IsKeyPressed(uint8_t scan_code)
Definition state.c:640
void Input_InitializeInputSubsystem(HWND hwnd, HINSTANCE h_instance)
Definition state.c:195
#define g_inputProcessedFlag
Definition globals.h:59
#define Input_ProcessWindowMessages_ShouldQuit
Definition globals.h:56
void PKG_LocatePackagePath(void)
Definition archive.c:50
bool Pkg_InitializeResourceGameEngine(void)
Definition resources.c:111
void PKG_InitializeSystem(HWND hwnd, HINSTANCE h_instance)
Definition resources.c:366
#define WINDOW_ACCELERATOR_COMMAND_ID
Definition constants.h:7
#define WINDOW_ORIGINAL_STYLE_RESERVED
Definition constants.h:5
#define WINDOW_ICON_RESOURCE_ID
Definition constants.h:6
int32_t Display_SetMode(HWND hwnd)
Definition window.c:119
void Window_SetDefaultResolution(int32_t reserved_zero)
Definition window.c:140
BOOL Display_IsActive(void)
Definition window.c:111
LRESULT Game_MainWindowProc(HWND hwnd, UINT u_msg, WPARAM w_param, LPARAM l_param)
Definition window.c:21
#define Window_MainHandle
Definition globals.h:213
#define Window_RunWinMain_RenderingEnabled
Definition globals.h:207
#define Window_ProcessGameProc_Initialized
Definition globals.h:210
#define Window_RunWinMain_SecondaryWindowHandle
Definition globals.h:198
void CRT_exit(int32_t status)
Definition startup.c:135
void Config_InitializeInputMappingsAndLoadSettings(void)
Definition config.c:117
#define g_acceleratorTable
Definition values.h:546
#define g_winMainShowCmd
Definition values.h:549
int32_t global_type_g_winMainInstanceHandle
Definition values.h:539
#define g_winMainInstanceHandle
Definition values.h:540
int32_t global_type_g_acceleratorTable
Definition values.h:545
int32_t global_type_g_winMainShowCmd
Definition values.h:548
void Video_PlayMovieIntro(int32_t movie_index)
Definition playback.c:215
#define g_videoSkipRequested
Definition globals.h:65
@ BLACK_BRUSH
Definition win32_gdi.h:10
@ SPI_SETSCREENSAVERRUNNING
#define MB_ICONHAND
#define WS_MAXIMIZE
#define WS_POPUP
@ SW_SHOWMAXIMIZED
#define WS_EX_LEFT