102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
playback.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
15
16// Original pcdogs.exe: 0x41a810
17// Initializes video and sound playback systems, storing the latest error and shutting both systems down if either initialization fails.
18BOOL Video_InitPlayer(HWND hwnd)
19{
20 int32_t video_init_error = Movie_InitVideoSystem(hwnd, 1);
21
22 g_videoPlayerErrorCode = video_init_error;
23
24 if (video_init_error)
25 {
27
28 return 0;
29 }
30
31 int32_t sound_init_error = Movie_InitSoundSystem(hwnd);
32
33 g_videoPlayerErrorCode = sound_init_error;
34
35 if (!sound_init_error)
36 return 1;
37
39
40 return 0;
41}
42
43// Original pcdogs.exe: 0x41a860
44// Stops the movie timer, restores playback mode, shuts down sound, video, and movie handles, and returns success.
55
56// Original pcdogs.exe: 0x41a8a0
57// Selects the playback rectangle and initializes the movie, video, sound, and synchronization state. Each failed initialization records its error and shuts down the player systems.
58BOOL Video_OpenMovieFile(HWND hwnd, char const *movie_path, IDirectDraw7 *unused_ddraw, char use_alt_video_rect)
59{
60 (void)unused_ddraw;
61 g_videoCurrentRect = use_alt_video_rect == 1 ? g_videoAltRect : g_videoDefaultRect;
62
63 int32_t movie_init_error = Movie_InitMovie(&g_videoMovieHandle, NULL, 0, movie_path, VIDEO_MOVIE_OPEN_OPTION);
64
65 g_videoPlayerErrorCode = movie_init_error;
66
67 if (movie_init_error)
68 {
70
71 return 0;
72 }
73
74 int32_t movie_height = Video_GetMovieYSize(g_videoMovieHandle);
75 int32_t movie_width = Video_GetMovieXSize(g_videoMovieHandle);
76 int32_t video_init_error = Movie_InitVideo(&g_videoSurfaceHandle, g_videoMovieHandle, movie_width,
78
79 g_videoPlayerErrorCode = video_init_error;
80
81 if (video_init_error)
82 {
84
85 return 0;
86 }
87
88 int32_t playback_mode_error = Movie_InitPlaybackMode(hwnd, g_videoSurfaceHandle, 1, 0);
89
90 g_videoPlayerErrorCode = playback_mode_error;
91
92 if (playback_mode_error)
93 {
95
96 return 0;
97 }
98
100 {
101 int32_t sample_precision = Video_GetMovieSoundPrecision(g_videoMovieHandle);
102 int32_t sample_rate = Video_GetMovieSoundRate(g_videoMovieHandle);
107 : 1;
108 int32_t sound_init_error = Movie_InitSound(&g_videoSoundHandle, VIDEO_SOUND_BUFFER_SIZE, bytes_per_sample,
109 precision_is_not_four_bytes, VIDEO_SOUND_BLOCK_SIZE, channels, sample_rate, sample_precision, VIDEO_SOUND_CHANNEL_CONFIGURATION);
110
111 g_videoPlayerErrorCode = sound_init_error;
112
113 if (sound_init_error)
114 {
116
117 return 0;
118 }
119 }
120
122
123 int32_t playback_init_error =
125
126 g_videoPlayerErrorCode = playback_init_error;
127
128 if (playback_init_error)
129 {
131
132 return 0;
133 }
134
137
138 return 1;
139}
140
141// Original pcdogs.exe: 0x41aaf0
142// Plays movie frames until completion, playback error, or user input. Escape returns 2, Alt-F4 returns 3, and completion or other stop conditions return 1.
144{
145 int32_t initial_frame_count = Video_GetMovieTotalFrames(g_videoMovieHandle);
146
147 if (Video_GetMovieCurrentFrame(g_videoMovieHandle) >= initial_frame_count)
149
151 {
154
156 break;
157
160
161 struct Input_State input_state;
162
163 input_state.button_bits = 0;
164 Input_ReadGamepad(&input_state);
165
166 if (input_state.button_bits)
167 break;
168
170 g_videoSoundHandle, NULL, &g_videoCurrentRect, 0, 0, 0);
171
172 int32_t current_frame_count = Video_GetMovieTotalFrames(g_videoMovieHandle);
173
174 if (Video_GetMovieCurrentFrame(g_videoMovieHandle) >= current_frame_count)
175 break;
176 }
177
179}
180
181// Original pcdogs.exe: 0x41abf0
182// Shuts down the video system followed by the sound system.
188
189// Original pcdogs.exe: 0x43cd40
190// Opens and plays a movie, closes its resources, and handles skip or close requests. Escape and Alt-F4 also shut down the player systems, and Alt-F4 requests window closure.
191void Video_PlayMovieFile(char const *movie_path, char use_alt_video_rect)
192{
193 if (!Video_OpenMovieFile(Window_MainHandle, movie_path, g_directDraw7, use_alt_video_rect))
194 return;
195
196 int32_t playback_exit_reason = Video_PlayMovieLoop();
197
198 if (playback_exit_reason != VIDEO_PLAYBACK_SKIPPED && playback_exit_reason != VIDEO_PLAYBACK_CLOSE_REQUESTED)
199 {
201
202 return;
203 }
204
208
209 if (playback_exit_reason == VIDEO_PLAYBACK_CLOSE_REQUESTED)
211}
212
213// Original pcdogs.exe: 0x43cda0
214// Builds the selected intro movie path and uses either the movie backend or fullscreen MCI AVI playback, managing initialization, skip state, and cleanup. The MCI loop waits without a timeout until playback has been observed and subsequently ceases, so a movie that never reports playing can leave it spinning.
215void Video_PlayMovieIntro(int32_t movie_index)
216{
218 String_FormatCRTString(g_introMoviePath, "%s%s%s", g_pkgBasePath, "data\\movies\\", g_introMovieFileNames[movie_index]);
219
220 if (g_introMovieUseRplFlags[movie_index])
221 {
222 if (movie_index == VIDEO_INTRO_FIRST)
224
226
227 if (movie_index == VIDEO_INTRO_LAST && !g_videoSkipRequested)
229
230 return;
231 }
232
233 HWND movie_window = Window_MainHandle;
234
236 String_FormatCRTString(g_windowHandleText, "%d", (int32_t)(intptr_t)movie_window);
237
238 BOOL avi_initialized = Video_InitializeAVIPlayer(g_windowHandleText);
239
240 if (!avi_initialized)
241 {
242 Debug_Log("Error: OpenMovie();", NULL);
243
244 return;
245 }
246
247 BOOL avi_opened = Video_OpenAVIFile(g_introMoviePath);
248
249 if (!avi_opened)
250 {
251 Debug_Log("Error: OpenMovie();", NULL);
253
254 return;
255 }
256
257 BOOL avi_play_started = Video_PlayAVIFullscreen();
258
259 if (avi_play_started)
260 {
262
263 while (true)
264 {
265 bool avi_playing = Video_IsAVIPlaying();
266 BOOL playback_previously_observed = g_aviPlaybackStarted;
267
268 if (avi_playing)
269 {
270 if (playback_previously_observed)
271 continue;
272 }
273 else if (playback_previously_observed)
274 break;
275
276 if (Video_IsAVIPlaying())
278 }
279 }
280 else
281 Debug_Log("Error: PlayMovie();", NULL);
282
285}
286
287// Original pcdogs.exe: 0x445e40
288// Forwards the movie, sound, and synchronization adjustment to the movie backend and returns its result.
289int32_t Video_SetMovieSyncAdjust(int32_t movie_handle, int32_t sound_handle, int32_t sync_adjust)
290{
291 return Movie_SetSyncAdjust(movie_handle, sound_handle, sync_adjust);
292}
293
294// Original pcdogs.exe: 0x445e46
295// Returns the sound sample rate reported by the movie backend.
296int32_t Video_GetMovieSoundRate(int32_t movie_handle)
297{
298 return Movie_GetSoundRate(movie_handle);
299}
300
301// Original pcdogs.exe: 0x445e4c
302// Returns the sound sample precision reported by the movie backend.
303int32_t Video_GetMovieSoundPrecision(int32_t movie_handle)
304{
305 return Movie_GetSoundPrecision(movie_handle);
306}
307
308// Original pcdogs.exe: 0x445e52
309// Returns the sound channel count reported by the movie backend.
310int32_t Video_GetMovieSoundChannels(int32_t movie_handle)
311{
312 return Movie_GetSoundChannels(movie_handle);
313}
314
315// Original pcdogs.exe: 0x445e58
316// Returns the movie width reported by the backend.
317int32_t Video_GetMovieXSize(int32_t movie_handle)
318{
319 return Movie_GetXSize(movie_handle);
320}
321
322// Original pcdogs.exe: 0x445e5e
323// Returns the movie height reported by the backend.
324int32_t Video_GetMovieYSize(int32_t movie_handle)
325{
326 return Movie_GetYSize(movie_handle);
327}
328
329// Original pcdogs.exe: 0x445e64
330// Returns the current movie frame index reported by the backend.
331int32_t Video_GetMovieCurrentFrame(int32_t movie_handle)
332{
333 return Movie_GetCurrentFrame(movie_handle);
334}
335
336// Original pcdogs.exe: 0x445e6a
337// Returns the total movie frame count reported by the backend.
338int32_t Video_GetMovieTotalFrames(int32_t movie_handle)
339{
340 return Movie_GetTotalFrames(movie_handle);
341}
void Debug_Log(char const *category, char const *message)
Definition diagnostics.c:17
#define Video_PlayMovieLoop_GetAsyncKeyStateThunk
int32_t Movie_GetCurrentFrame(int32_t movie_handle)
int32_t Movie_GetSoundRate(int32_t movie_handle)
int32_t Movie_GetSoundPrecision(int32_t movie_handle)
int32_t Movie_SetSyncAdjust(int32_t movie_handle, int32_t sound_handle, int32_t sync_adjust)
int32_t Movie_GetTotalFrames(int32_t movie_handle)
int32_t Movie_GetYSize(int32_t movie_handle)
int32_t Movie_GetXSize(int32_t movie_handle)
int32_t Movie_GetSoundChannels(int32_t movie_handle)
void Input_ReadGamepad(struct Input_State *state)
Definition state.c:233
#define g_pkgBasePath
Definition globals.h:102
void Window_RequestClose()
Definition window.c:101
#define Window_MainHandle
Definition globals.h:213
#define g_windowHandleText
Definition globals.h:192
int32_t Video_GetMovieCurrentFrame(int32_t movie_handle)
Definition playback.c:331
void Video_ShutdownPlayerSystems(void)
Definition playback.c:183
int32_t Video_GetMovieTotalFrames(int32_t movie_handle)
Definition playback.c:338
BOOL Video_OpenMovieFile(HWND hwnd, char const *movie_path, IDirectDraw7 *unused_ddraw, char use_alt_video_rect)
Definition playback.c:58
void Video_PlayMovieFile(char const *movie_path, char use_alt_video_rect)
Definition playback.c:191
int32_t Video_GetMovieYSize(int32_t movie_handle)
Definition playback.c:324
void Video_PlayMovieIntro(int32_t movie_index)
Definition playback.c:215
int32_t Video_GetMovieSoundPrecision(int32_t movie_handle)
Definition playback.c:303
int32_t Video_PlayMovieLoop(void)
Definition playback.c:143
int32_t Video_GetMovieSoundChannels(int32_t movie_handle)
Definition playback.c:310
BOOL Video_CloseMovieFile(void)
Definition playback.c:45
int32_t Video_SetMovieSyncAdjust(int32_t movie_handle, int32_t sound_handle, int32_t sync_adjust)
Definition playback.c:289
int32_t Video_GetMovieSoundRate(int32_t movie_handle)
Definition playback.c:296
BOOL Video_InitPlayer(HWND hwnd)
Definition playback.c:18
int32_t Video_GetMovieXSize(int32_t movie_handle)
Definition playback.c:317
int32_t String_FormatCRTString(char *buffer, char const *format,...)
Definition formatting.c:18
#define g_configFilePath
Definition globals.h:34
uint32_t button_bits
Definition types.h:83
#define g_directDraw7
Definition values.h:810
#define g_aviPlaybackStarted
Definition values.h:480
@ VIDEO_PLAYBACK_SKIPPED
Definition constants.h:7
@ VIDEO_PLAYBACK_FINISHED
Definition constants.h:6
@ VIDEO_PLAYBACK_CLOSE_REQUESTED
Definition constants.h:8
#define VIDEO_SOUND_PRECISION_FOUR_BYTES
Definition constants.h:19
#define VIDEO_STREAMER_OPTION_SECONDARY
Definition constants.h:23
#define VIDEO_SOUND_SYNC_ADJUSTMENT
Definition constants.h:16
@ VIDEO_INTRO_ALTERNATE_RECT
Definition constants.h:30
@ VIDEO_INTRO_FIRST
Definition constants.h:29
@ VIDEO_INTRO_LAST
Definition constants.h:31
#define VIDEO_OUTPUT_HEIGHT
Definition constants.h:12
#define VIDEO_SOUND_BLOCK_SIZE
Definition constants.h:15
#define VIDEO_MOVIE_OPEN_OPTION
Definition constants.h:21
#define VIDEO_OUTPUT_WIDTH
Definition constants.h:11
#define VIDEO_SOUND_CHANNEL_CONFIGURATION
Definition constants.h:17
#define VIDEO_SOUND_BUFFER_SIZE
Definition constants.h:14
#define VIDEO_STREAMER_OPTION_PRIMARY
Definition constants.h:22
int32_t Movie_ReturnPlaybackMode(void)
BOOL Video_PlayAVIFullscreen(void)
Definition avi.c:58
int32_t Movie_MapVideo(int32_t surface_handle, int32_t flags)
BOOL Video_OpenAVIFile(char const *movie_path)
Definition avi.c:37
int32_t Movie_InitVideoSystem(HWND hwnd, BOOL fullscreen_exclusive)
int32_t Movie_PlayFrame(int32_t movie_handle, int32_t surface_handle, int32_t sound_handle, void *alpha_effects_handle, RECT const *destination_rect, uint32_t codec_frame_arg6, uint32_t codec_frame_arg7, uint32_t codec_start_arg15)
int32_t Movie_InitVideo(int32_t *surface_handle_out, int32_t movie_handle, int32_t movie_width, int32_t movie_height, int32_t mapping_x, int32_t mapping_y, uint32_t mapping_arg7, uint32_t mapping_arg8, uint32_t output_width, uint32_t output_height, BOOL zero_mapping_origin, BOOL preserve_destination_mapping, uint32_t streamer_flags)
int32_t Movie_StopTimer(int32_t movie_handle)
int32_t Movie_InitMoviePlayback(int32_t movie_handle, int32_t surface_handle, int32_t sound_handle)
int32_t Movie_ShutdownVideo(int32_t *surface_handle)
int32_t Movie_ShutdownSound(int32_t *sound_handle)
int32_t Movie_InitMovie(int32_t *movie_handle_out, void(*streaming_callback)(), uint32_t callback_interval_bytes, char const *movie_path, uint32_t buffer_size)
int32_t Movie_ShutdownSoundSystem(void)
int32_t Movie_ShutdownMovie(int32_t *movie_handle)
int32_t Movie_InitPlaybackMode(HWND hwnd, int32_t surface_handle, BOOL force640x480x16, BOOL attach_window_clipper)
int32_t Movie_ShutdownVideoSystem(void)
BOOL Video_InitializeAVIPlayer(char const *window_handle_text)
Definition avi.c:12
MCIERROR Video_CloseAVIFile(void)
Definition avi.c:50
int32_t Movie_StartTimer(int32_t movie_handle)
MCIERROR Video_ShutdownAVIPlayer(void)
Definition avi.c:27
int32_t Movie_InitSoundSystem(HWND hwnd)
int32_t Movie_InitSound(int32_t *sound_handle_out, uint32_t buffer_bytes, uint32_t bytes_per_sample, BOOL precision_is_not_four_bytes, uint32_t block_bytes, int32_t channels, int32_t sample_rate, int32_t sample_precision, uint32_t sound_sync_mode)
BOOL Video_IsAVIPlaying(void)
Definition avi.c:66
#define g_videoCurrentRect
Definition globals.h:17
#define g_videoSoundHandle
Definition globals.h:59
#define g_videoDefaultRect
Definition globals.h:20
#define g_videoSkipRequested
Definition globals.h:65
#define g_introMovieFileNames
Definition globals.h:26
#define g_introMovieUseRplFlags
Definition globals.h:29
#define g_videoAltRect
Definition globals.h:23
#define g_videoMovieHandle
Definition globals.h:53
#define g_videoSurfaceHandle
Definition globals.h:56
#define g_introMoviePath
Definition globals.h:62
#define g_videoPlayerErrorCode
Definition globals.h:68