102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
resources.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
10#include "pcdogs/audio/types.h"
12#include "pcdogs/game/globals.h"
18#include "pcdogs/level/types.h"
24#include "pcdogs/menu/globals.h"
34#include "pcdogs/ui/constants.h"
35#include "pcdogs/ui/functions.h"
36#include "pcdogs/ui/globals.h"
37#include <math.h>
38#include <stdarg.h>
39#include <string.h>
40
41// Original pcdogs.exe: 0x412f50
42// Stops audio, destroys actors, clears eligible timed events and transition flags, and resets level initialization callbacks.
44{
46 // Destroy all active actor instances
48 // Clean up level-specific actor data
50
52 {
53 // Clear linked list and remove state flags 2 and 0x10
55
56 uint32_t game_frame_transition_flags = Game_FrameTransitionFlags;
57
58 game_frame_transition_flags &= ~(GAME_TRANSITION_RUNNING | GAME_TRANSITION_SCRIPT_PAUSED);
59 Game_FrameTransitionFlags = game_frame_transition_flags;
60 }
61
62 // Clear level initialization callbacks
65}
66
67// Original pcdogs.exe: 0x427750
68// Loads shared textures, audio, and metadata once, then fixes sound, string, material, and font references. A failed later load leaves earlier allocations retained.
70{
72 return;
73
76 return;
77
80 return;
81
84 return;
85
86 uint8_t *base = (uint8_t *)g_resourceDataBuffer;
87 g_soundDefinitionTable = (struct Audio_SoundDefinition *)(base + g_resourceDataBuffer->sound_table_offset);
89
90 base = (uint8_t *)g_resourceDataBuffer;
91 struct PKG_StringSection *strings = (struct PKG_StringSection *)(base + g_resourceDataBuffer->string_section_offset);
92 String_SetTable((struct Text_StringEntry *)((uint8_t *)&strings->table_offset + strings->table_offset));
93
94 base = (uint8_t *)g_resourceDataBuffer;
95 struct Material_SectionHeaderRaw *materials = (struct Material_SectionHeaderRaw *)(base + g_resourceDataBuffer->material_section_offset);
98
100 Shared_TextureDataRefsCursor = (struct Material_RefEntry *)(section + 1);
101 Shared_FontDataCursor = (struct Material_RefEntry *)(section + 2);
102 Shared_MaterialFrameSetCursor = (struct Material_FrameSet *)(section + 8);
104 (int32_t)Shared_TextureDataRefsCursor->material_table_entry);
106 (int32_t)Shared_FontDataCursor->material_table_entry);
107}
108
109// Original pcdogs.exe: 0x42c810
110// Initializes the handle allocator and invokes graphics initialization, returning its result.
112{
114
115 /* tailcall */
117}
118
119// Original pcdogs.exe: 0x42c819
120// Returns false through the recovered engine-initialization failure entry.
122{
123 return 0;
124}
125
126// Original pcdogs.exe: 0x42c81c
127// Invokes DirectDraw initialization and returns true without inspecting its result.
129{
131
132 return 1;
133}
134
135// Original pcdogs.exe: 0x42c830
136// Releases the DirectDraw device and frees all allocator extents.
143
144// Original pcdogs.exe: 0x42cd90
145// Frees the resource allocation and always returns false.
147{
148 Pkg_FreeResourceMemory(mem_ptr);
149
150 return 0;
151}
152
153// Original pcdogs.exe: 0x42cde0
154// Unloads the current level or tears down the active title screen, then clears level roots and sets the current level ID to its sentinel.
156{
157 struct Level_DataHeader *level_resource_handle = g_levelResourceHandle;
158
159 // If in title screen state (2), update it and reset to state 0
160 if (level_resource_handle)
161 {
162 Level_UnloadResources(level_resource_handle);
164 }
166 {
169 }
170
171 g_objectNodeRoot = NULL;
174}
175
176// Original pcdogs.exe: 0x42d0e0
177// Advances loading-image selection, fade-in, resource readiness, and fade-out, returning whether loading may proceed. Source pixels are freed before fade-out while uploaded blend textures remain until its completion.
178bool PKG_UpdateLoadingScreen(int32_t level_index)
179{
180 char loading_screen_state = g_loadingScreenState;
181
182 if (loading_screen_state == PKG_LOADING_SELECT_IMAGE)
183 {
184 int32_t loading_image_index;
185 do
186 {
187 loading_image_index = Math_GenerateRandom(PKG_LOADING_IMAGE_COUNT);
188 } while (loading_image_index == g_lastLoadingImageIndex);
189
190 g_lastLoadingImageIndex = (uint8_t)loading_image_index;
191
192 uint8_t *pixel_data = PKG_LoadEntryAlloc(loading_image_index + PKG_LOADING_IMAGE_FIRST_ENTRY, 0);
193
194 g_loadingImageResourcePtr = pixel_data;
195
196 if (pixel_data)
197 {
199
203 }
204
206 }
207
208 if (loading_screen_state == PKG_LOADING_FADE_IN)
209 {
211
213
215 int32_t graphics_window_height = Graphics_WindowHeight;
216 int32_t window_width_half = Graphics_WindowWidth / 2;
217
219 ((int64_t)(graphics_window_height * PKG_LOADING_HEADER_Y) / graphics_window_height) << 0x10 | (uint32_t)(uint16_t)window_width_half,
220 text, UI_TEXT_ALIGN_CENTER, NULL);
221
222 int32_t string_id;
223
224 if (level_index >= LEVEL_CAMPAIGN_FIRST && level_index <= LEVEL_AFTER_BONUS)
225 {
226 if (level_index < LEVEL_BONUS_FIRST)
227 string_id = level_index + PKG_STRING_CAMPAIGN_LEVEL_OFFSET;
228 else if (level_index < LEVEL_AFTER_BONUS)
229 string_id = level_index + PKG_STRING_BONUS_LEVEL_OFFSET;
230 else
231 string_id = PKG_STRING_AFTER_BONUS;
232
233 char *text_1 = String_GetByIndex(string_id);
234 int32_t graphics_window_height_2 = Graphics_WindowHeight;
235 int32_t caption_window_width_half = Graphics_WindowWidth / 2;
236
238 ((int64_t)(graphics_window_height_2 * PKG_LOADING_CAPTION_Y) / graphics_window_height_2) << 0x10 | (uint32_t)(uint16_t)caption_window_width_half,
239 text_1, UI_TEXT_ALIGN_CENTER, NULL);
240 }
241
242 char next_fade_counter = g_loadingFadeCounter + 1;
243
244 g_loadingFadeCounter = next_fade_counter;
245
246 if (next_fade_counter >= PKG_LOADING_FADE_FRAMES)
247 {
250
252 }
253
256
258 }
259
260 if (loading_screen_state == PKG_LOADING_WAIT_RESOURCE)
261 {
262 void *loading_image_resource_ptr = g_loadingImageResourcePtr;
263
264 if (loading_image_resource_ptr)
265 {
266 // The always-false free result retains uploaded textures for state-3 fading after source pixels are freed.
267 if (Pkg_FreeResourceAndReturnFalse(loading_image_resource_ptr))
269
271 }
272
274 {
276
278
280
281 return result;
282 }
283 }
284 else if (loading_screen_state == PKG_LOADING_FADE_OUT)
285 {
288
291 else
292 {
295 }
296
298
300 {
301 struct Material_BlendTextureSet *loading_blend_texture_ptr = g_loadingBlendTexturePtr;
302
303 if (loading_blend_texture_ptr)
304 Graphics_FreeTextureBlend(loading_blend_texture_ptr);
305
307
308 return 1;
309 }
310 }
311
313}
314
315// Original pcdogs.exe: 0x42e670
316// Allocates resource storage with a handle header for nonzero sizes and returns null for size zero.
317void *Pkg_AllocateResourceMemory(uint32_t size)
318{
319 if (size)
321
322 return NULL;
323}
324
325// Original pcdogs.exe: 0x42e690
326// Allocates a handle-backed block with a four-byte handle header and returns the following user storage, or null when pointer resolution fails. Size addition retains unsigned 32-bit wrap.
328{
329 uint32_t handle = Mem_AllocateHandle(size + 4);
330 uint32_t *allocation = Mem_GetPointerByHandle(handle);
331
332 if (!allocation)
333 return NULL;
334
335 *allocation = handle;
336
337 return allocation + 1;
338}
339
340// Original pcdogs.exe: 0x42e6c0
341// Reads the handle preceding a nonnull resource pointer, invokes handle validation, and releases the handle regardless of the validation result.
342void Pkg_FreeResourceMemory(void *user_ptr)
343{
344 if (!user_ptr)
345 return;
346
347 uint32_t mem_handle = ((struct PKG_ResourceAllocationHeader *)user_ptr)[-1].memory_handle;
348
349 Mem_IsValidHandle(mem_handle);
350 Mem_ReleaseHandle(mem_handle);
351}
352
353// Original pcdogs.exe: 0x43e560
354// Shuts down audio, closes the package, and releases graphics and allocator resources.
356{
358 PKG_Close();
359
360 /* tailcall */
362}
363
364// Original pcdogs.exe: 0x43e860
365// Opens package metadata, initializes audio and graphics dispatch, and sets camera range and graphics capability bits. The window and instance parameters are unused.
377
378// Original pcdogs.exe: 0x43ec20
379// Forwards resource cleanup to the resource-data free wrapper.
380void Pkg_CleanupResourceHandle(void *resource_data)
381{
382 Pkg_FreeResourceData(resource_data);
383}
384
385// Original pcdogs.exe: 0x43ee80
386// Frees the supplied handle-backed resource allocation.
387void Pkg_FreeResourceData(void *resource_data)
388{
389 Pkg_FreeResourceMemory(resource_data);
390}
391
392// Original pcdogs.exe: 0x43ee90
393// Returns the byte value one without accessing resource state.
395{
396 return 1;
397}
398
399// Original pcdogs.exe: 0x443db0
400// Loads title textures, audio, and metadata, then binds materials, music, and sound definitions. Returns false on a failed load without freeing earlier allocations.
402{
403 void *title_texture_blob = PKG_LoadEntryAlloc(PKG_ENTRY_TITLE_TEXTURES, 0); // TOC[0]: Title screen background textures
404
405 Title_ResourceHandle0 = title_texture_blob;
406
407 if (!title_texture_blob)
408 {
409 return 0;
410 }
411
412 void *title_audio_blob = PKG_LoadEntryAlloc(PKG_ENTRY_TITLE_AUDIO, 0);
413
414 Title_ResourceHandle1 = title_audio_blob;
415
416 if (!title_audio_blob)
417 {
418 return 0;
419 }
420
421 // TOC[2]: Title screen package (materials, sounds, fireworks data)
422 struct PKG_TitlePackage *title_package = PKG_LoadEntry(PKG_ENTRY_TITLE_PACKAGE, NULL, 1);
423
424 PKG_ResourceTitlePackage = title_package;
425
426 if (!title_package)
427 {
428 return 0;
429 }
430
431 struct Material_SectionHeaderRaw *material_section_raw = (struct Material_SectionHeaderRaw *)(title_package->material_section_offset + (char *)title_package);
432 uint8_t *title_resource_handle0 = Title_ResourceHandle0;
433
435 Material_LoadAndFixup(material_section_raw, title_resource_handle0);
436
437 struct Material_SectionHeader *pkg_resource_title_material_base = PKG_ResourceTitleMaterialBase;
438
439 g_titleSpotsMaterialIndex = (global_type_g_titleSpotsMaterialIndex)(uintptr_t)(&pkg_resource_title_material_base[1]);
440 Shared_MaterialFrameSetCursor = (global_type_Shared_MaterialFrameSetCursor)(uintptr_t)(&pkg_resource_title_material_base[4]);
441 Material_BuildTextureArray(pkg_resource_title_material_base,
442 (struct Material_RefEntry *)(&pkg_resource_title_material_base[1]), PKG_TITLE_MATERIAL_COUNT,
443 (int32_t)((struct Material_RefEntry *)(pkg_resource_title_material_base + 1))->material_table_entry);
444
445 struct PKG_TitlePackage *pkg_resource_title_package = PKG_ResourceTitlePackage;
446 void *title_resource_handle1 = Title_ResourceHandle1;
447
449 (global_type_g_titleMusicStreamRecord)(uintptr_t)(pkg_resource_title_package->music_data_offset + (char *)pkg_resource_title_package);
450
451 struct Audio_SoundDefinition *sound_table =
452 (struct Audio_SoundDefinition *)(pkg_resource_title_package->sound_table_offset + (char *)pkg_resource_title_package);
453
454 g_titleSoundDefTable = sound_table;
455 Audio_FixupSoundDefinitions(sound_table, PKG_TITLE_SOUND_COUNT, title_resource_handle1);
456
457 return 1;
458}
void Actor_DestroyAll(void)
Definition lifecycle.c:287
void Audio_FixupSoundDefinitions(struct Audio_SoundDefinition *sound_defs, int32_t count, void *sample_data_base)
Definition system.c:173
void Audio_ShutdownSystem(void)
Definition system.c:123
void Audio_UpdateSoundChannels(int32_t channel_mask)
Definition channels.c:275
void Audio_InitializeSystem(void)
Definition system.c:16
#define g_soundDefinitionTable
Definition globals.h:54
#define g_cameraData
Definition globals.h:63
#define GAME_TRANSITION_RUNNING
Definition constants.h:17
#define GAME_TRANSITION_SCRIPT_PAUSED
Definition constants.h:20
#define Game_FrameTransitionFlags
Definition globals.h:47
#define GRAPHICS_CAP_DEPTH_BUFFER
Definition constants.h:16
#define GRAPHICS_CAP_TEXTURE_REPEAT
Definition constants.h:50
#define GRAPHICS_CAP_FAR_LOD
Definition constants.h:22
#define GRAPHICS_CAP_NEAR_LOD
Definition constants.h:19
void Graphics_DrawFullscreenFadeOverlay(int32_t opacity12)
Definition effects.c:307
void Graphics_FreeTextureBlend(struct Material_BlendTextureSet *blend_textures)
Definition textures.c:101
void Graphics_InitializeDispatchTables(void)
Definition frame.c:310
void Graphics_EndRendering(void)
Definition frame.c:156
struct Material_BlendTextureSet * Graphics_InitializeTextureBlendTextures(uint8_t *pixel_data)
Definition textures.c:92
bool Graphics_DisabledFadeBackendStub(int32_t fade_level)
Definition effects.c:315
void Graphics_DrawFullscreenTextureQuadrants(struct Material_BlendTextureSet *texture_set)
Definition primitives.c:732
void Graphics_IncrementPassCounter(void)
Definition frame.c:141
#define Graphics_WindowWidth
Definition globals.h:140
#define g_graphicsCapabilities
Definition globals.h:284
#define Graphics_WindowHeight
Definition globals.h:143
@ LEVEL_CAMPAIGN_FIRST
Definition constants.h:85
@ LEVEL_AFTER_BONUS
Definition constants.h:95
@ LEVEL_BONUS_FIRST
Definition constants.h:90
@ LEVEL_LOAD_INITIALIZE
Definition constants.h:35
@ LEVEL_LOAD_TITLE
Definition constants.h:37
#define LEVEL_ID_NONE
Definition constants.h:115
void Level_UnloadResources(struct Level_DataHeader *level_resource_data)
Definition loading.c:478
void Level_CleanupActors(void)
Definition loading.c:168
#define g_levelResourceHandle
Definition globals.h:76
#define g_levelInitCallback1
Definition globals.h:91
#define g_currentLevelID
Definition globals.h:43
#define g_levelInitCallback2
Definition globals.h:88
void Material_BuildTextureArray(struct Material_SectionHeader *material_section, struct Material_RefEntry *material_refs, int32_t material_count, int32_t first_material_index)
Definition textures.c:311
#define g_loadingBlendTexturePtr
Definition globals.h:12
void Material_LoadAndFixup(struct Material_SectionHeaderRaw *section, uint8_t *texture_data)
Definition resources.c:65
#define MATH_Q12_SHIFT
Definition constants.h:8
#define MATH_Q12_ONE
Definition constants.h:9
uint32_t Math_GenerateRandom(uint32_t range)
BOOL Mem_ReleaseHandle(uint32_t handle)
Definition handles.c:136
BOOL Mem_FreeAllExtents(void)
Definition handles.c:104
BOOL Mem_InitializeAllocator(void)
Definition handles.c:84
BOOL Mem_IsValidHandle(uint32_t handle)
Definition handles.c:188
void * Mem_GetPointerByHandle(uint32_t handle)
Definition handles.c:176
uint32_t Mem_AllocateHandle(uint32_t size)
Definition handles.c:48
#define Menu_LoadState
Definition globals.h:153
@ PKG_LOADING_FADE_OUT
Definition constants.h:51
@ PKG_LOADING_SELECT_IMAGE
Definition constants.h:48
@ PKG_LOADING_WAIT_RESOURCE
Definition constants.h:50
@ PKG_LOADING_FADE_IN
Definition constants.h:49
#define PKG_SHARED_SOUND_COUNT
Definition constants.h:63
#define PKG_LOADING_FADE_FRAMES
Definition constants.h:61
@ PKG_STRING_BONUS_LEVEL_OFFSET
Definition constants.h:74
@ PKG_STRING_LOADING_HEADER
Definition constants.h:72
@ PKG_STRING_AFTER_BONUS
Definition constants.h:75
@ PKG_STRING_CAMPAIGN_LEVEL_OFFSET
Definition constants.h:73
#define PKG_LOADING_IMAGE_FIRST_ENTRY
Definition constants.h:60
#define PKG_TITLE_SOUND_COUNT
Definition constants.h:86
#define PKG_CAMERA_UNBOUNDED_FAR_DISTANCE
Definition constants.h:68
#define PKG_LOADING_IMAGE_COUNT
Definition constants.h:59
#define PKG_TITLE_MATERIAL_COUNT
Definition constants.h:85
#define PKG_LOADING_DISABLED_BACKEND_FADE_Q12
Definition constants.h:67
#define PKG_DEFAULT_GRAPHICS_RESERVED_BIT_10
Definition constants.h:44
#define PKG_SHARED_BASE_MATERIAL_COUNT
Definition constants.h:84
@ PKG_ENTRY_TITLE_PACKAGE
Definition constants.h:33
@ PKG_ENTRY_TITLE_TEXTURES
Definition constants.h:31
@ PKG_ENTRY_TITLE_AUDIO
Definition constants.h:32
@ PKG_ENTRY_SHARED_AUDIO
Definition constants.h:35
@ PKG_ENTRY_SHARED_PACKAGE
Definition constants.h:36
@ PKG_ENTRY_SHARED_TEXTURES
Definition constants.h:34
#define PKG_LOADING_HEADER_Y
Definition constants.h:65
#define PKG_LOADING_CAPTION_Y
Definition constants.h:66
#define PKG_SHARED_FONT_MATERIAL_COUNT
Definition constants.h:64
#define PKG_DEFAULT_GRAPHICS_RESERVED_BIT_1
Definition constants.h:43
void * PKG_LoadEntryAlloc(int32_t toc_index, int32_t unused_zero)
Definition archive.c:11
void PKG_Close(void)
Definition archive.c:106
void * Pkg_AllocateResourceMemory(uint32_t size)
Definition resources.c:317
void PKG_OpenAndReadTOC(void)
Definition archive.c:91
void * PKG_LoadEntry(int32_t toc_index, void *dest_buffer, int32_t unused_mode)
Definition archive.c:18
#define PKG_ResourceTitleMaterialBase
Definition globals.h:93
#define g_sharedSoundDataBase
Definition globals.h:84
#define Shared_FontDataCursor
Definition globals.h:111
struct Material_FrameSet * global_type_Shared_MaterialFrameSetCursor
Definition globals.h:104
struct Material_SectionHeader * global_type_PKG_ResourceTitleMaterialBase
Definition globals.h:92
#define g_sharedMaterialSection
Definition globals.h:108
#define Shared_MaterialFrameSetCursor
Definition globals.h:105
#define PKG_ResourceTitlePackage
Definition globals.h:96
#define g_resourceDataBuffer
Definition globals.h:81
#define pkg_resource_current_level_data
Definition globals.h:117
#define Shared_TextureDataRefsCursor
Definition globals.h:114
void PKG_CleanupResourceGameState()
Definition resources.c:155
uint8_t PKG_LoadTitleScreenResources()
Definition resources.c:401
void Shared_LoadCommonResources(void)
Definition resources.c:69
void Pkg_CleanupFinalResourceGame()
Definition resources.c:355
bool Pkg_InitializeResourceGameEngine()
Definition resources.c:111
void Pkg_UnloadResourceGameData()
Definition resources.c:43
bool Pkg_InitializeGraphicsForGameEngine()
Definition resources.c:128
void Pkg_FreeResourceMemory(void *user_ptr)
Definition resources.c:342
void PKG_InitializeSystem(HWND hwnd, HINSTANCE h_instance)
Definition resources.c:366
void Pkg_CleanupResourceHandle(void *resource_data)
Definition resources.c:380
bool PKG_UpdateLoadingScreen(int32_t level_index)
Definition resources.c:178
bool Pkg_FreeResourceAndReturnFalse(void *mem_ptr)
Definition resources.c:146
bool Pkg_ReturnEngineInitializationFailure()
Definition resources.c:121
void * Pkg_AllocateResourceWithHeader(uint32_t size)
Definition resources.c:327
uint8_t Pkg_ReturnResourceAlwaysTrue()
Definition resources.c:394
void PKG_ShutdownResourceGameSubsystems()
Definition resources.c:137
void Pkg_FreeResourceData(void *resource_data)
Definition resources.c:387
ULONG D3D_ReleaseDirectDrawDevice()
void D3D_InitializeDirectDraw()
#define g_objectNodeRoot
Definition globals.h:12
void Signal_ClearTimedEventList(void)
Definition signals.c:103
uint32_t table_offset
Definition types.h:120
uint32_t music_data_offset
Definition types.h:132
uint32_t sound_table_offset
Definition types.h:131
uint32_t material_section_offset
Definition types.h:130
void String_SetTable(struct Text_StringEntry *string_table)
Definition strings.c:40
char * String_GetByIndex(int32_t string_id)
Definition strings.c:66
#define UI_TITLE_COMMAND_RESET
Definition constants.h:87
#define UI_TEXT_ALIGN_CENTER
Definition constants.h:6
uint8_t Title_UpdateAndRenderScreen(int32_t command)
Definition title.c:251
void UI_RenderText(uint32_t packed_xy, char const *text, uint32_t text_flags, void *font_context)
Definition text.c:226
#define g_titleMusicStreamRecord
Definition globals.h:56
struct Audio_MusicStreamRecord * global_type_g_titleMusicStreamRecord
Definition globals.h:55
#define Title_ResourceHandle0
Definition globals.h:80
#define Title_ResourceHandle1
Definition globals.h:77
struct Material_RefEntry * global_type_g_titleSpotsMaterialIndex
Definition globals.h:64
#define g_titleSpotsMaterialIndex
Definition globals.h:65
#define g_titleSoundDefTable
Definition globals.h:83
#define g_resourceHandle1
Definition values.h:408
#define g_loadingScreenState
Definition values.h:435
#define g_loadingFadeCounter
Definition values.h:441
#define g_lastLoadingImageIndex
Definition values.h:444
#define g_loadingImageResourcePtr
Definition values.h:447