102 Dalmatians: Puppies to the Rescue
Decompilation Source Reference | GitLab repository
Loading...
Searching...
No Matches
fixups.c
Go to the documentation of this file.
1/* Recovered game implementation; original addresses identify provenance. */
12#include "pcdogs/level/types.h"
15#include "pcdogs/math/types.h"
17#include "pcdogs/trail/types.h"
21#include "pcdogs/scene/types.h"
23#include <math.h>
24#include <stdarg.h>
25#include <string.h>
26
27// Original pcdogs.exe: 0x43b990
28// Relocates sibling and child links, dispatches type-specific fixups, and recursively visits children. Type 2 stops after its sibling fixup, while type 3 returns after its specialized fixup.
66
67// Original pcdogs.exe: 0x43ba20
68// Relocates mesh buffers, material references, render entries, animation data, and auxiliary lists in a type-1 node. Relocation is in place and relies on valid counts and terminated offset lists.
70{
71 void *normals_or_list_1 = node->normals_or_list;
72
73 if (normals_or_list_1)
74 {
75 node->normals_or_list = (char *)normals_or_list_1 + (uintptr_t)g_levelBlobPtr;
76
78
80 node->uv_or_child_list = (char *)uv_or_child_list + (uintptr_t)g_levelBlobPtr;
81 }
82
83 void *aux_84_1 = node->aux_84;
84
85 if (aux_84_1)
86 node->aux_84 = (char *)aux_84_1 + (uintptr_t)g_levelBlobPtr;
87
88 void *aux_80 = node->aux_80;
89
90 if (aux_80)
91 node->aux_80 = (char *)aux_80 + (uintptr_t)g_levelBlobPtr;
92
93 void *material_refs_1 = node->material_refs;
94
95 if (material_refs_1)
96 {
97 struct Pkg_MaterialRefFixupView *material_refs_2 = (struct Pkg_MaterialRefFixupView *)((char *)material_refs_1 + (uintptr_t)g_levelBlobPtr);
98 bool material_ref_fixup_disabled = !(*(const volatile uint8_t *)&node->flags_88 & PKG_NODE_HAS_MATERIAL_REFERENCES);
99
100 ((volatile struct PKG_ObjectNodeFixupView *)node)->material_refs = material_refs_2;
101
102 if (!material_ref_fixup_disabled)
103 {
104 /* Native argument reads remain observable even though the callees ignore these fields. */
105 const volatile struct PKG_ObjectNodeFixupView *native_node = node;
106
107 (void)native_node->aux_84;
108 (void)native_node->normals_or_list;
109 Pkg_FixUpResourceMaterialRefs(material_refs_2, (int32_t)native_node->material_ref_count);
110
111 if (native_node->aux_80)
112 {
113 (void)native_node->material_refs;
114 (void)native_node->material_ref_count;
115 }
116 }
117 }
118
119 void *entries_94 = node->entries_94;
120
121 if (entries_94)
122 node->entries_94 = (char *)entries_94 + (uintptr_t)g_levelBlobPtr;
123
124 struct Mesh_RenderNodeEntry *render_entries = node->render_entries;
125
126 if (render_entries)
127 {
128 int32_t entry_count = (uint8_t)(node->render_entry_count);
129 struct Mesh_RenderNodeEntry *entries = (struct Mesh_RenderNodeEntry *)((char *)render_entries + (uintptr_t)g_levelBlobPtr);
130
131 node->render_entries = entries;
132 Pkg_FixUpResourceRenderNodeEntries(entries, entry_count);
133 }
134
135 struct Animation_StateTable *animation_state_table = node->animation_state_table;
136
137 if (animation_state_table)
138 {
139 struct Animation_StateTable *animation_data = (struct Animation_StateTable *)((char *)animation_state_table + (uintptr_t)g_levelBlobPtr);
140
141 node->animation_state_table = animation_data;
143 }
144
146
147 void *material_indices_or_polygons = node->material_indices_or_polygons;
148
149 if (material_indices_or_polygons)
150 {
151 struct PKG_MaterialIndexList *index_list_raw =
152 (struct PKG_MaterialIndexList *)((char *)material_indices_or_polygons + (uintptr_t)g_levelBlobPtr);
153
154 node->material_indices_or_polygons = index_list_raw;
155 Pkg_FixUpResourceMaterialIndices(index_list_raw);
156 }
157
158 int32_t *relocation_list_b0 = node->relocation_list_b0;
159
160 if (relocation_list_b0)
161 {
162 int32_t *relative_pointer_cursor = (int32_t *)((char *)relocation_list_b0 + (uintptr_t)g_levelBlobPtr);
163
164 node->relocation_list_b0 = relative_pointer_cursor;
165
166 for (void *relative_pointer_offset = (void *)(*(uint32_t *)relative_pointer_cursor); relative_pointer_offset; relative_pointer_offset = (void *)(*(uint32_t *)relative_pointer_cursor))
167 {
168 relative_pointer_cursor = &relative_pointer_cursor[1];
169 relative_pointer_cursor[-1] = (uintptr_t)relative_pointer_offset + (uintptr_t)node->relocation_list_b0;
170 }
171 }
172
174 node->extra_d8 += (uintptr_t)g_levelBlobPtr;
175}
176
177// Original pcdogs.exe: 0x43bbb0
178// Relocates six animation channel groups and nested channel payloads, marking visited blocks and channels. Top-level channel data preserves null and minus-one sentinels, while nested nonnull payloads are relocated without a minus-one check.
179void Pkg_FixUpResourceAnimationData(struct Animation_DataBlock *animation_data, uint8_t *blob_base)
180{
181 // Reads Animation_DataBlock::fixup_flags at +7; +6 is not consumed by this relocation path.
182 Animation_DataBlockFixupFlags fixup_flags = animation_data->fixup_flags;
183
184 // PKG ANIMATION POINTER FIXUP: Converts relative offsets to absolute addresses during load. Bit 1 of
185 // flags (offset 7) marks if already fixed up.
186 if (fixup_flags & ANIMATION_DATA_RELOCATION_VISITED)
187 return;
188
189 animation_data->fixup_flags = fixup_flags | ANIMATION_DATA_RELOCATION_VISITED;
190
191 int32_t channel_index = 0;
192
193 // Animation_DataBlock channel fixup loops count indices +0..+5 and pointer slots +0x0c..+0x20; byte +6 is
194 // skipped, while byte +7 is fixup_flags (bit 1 marks already relocated).
195 struct Animation_SplineChannelVec3 **channel_array_slot = &animation_data->position_channels;
196
197 do
198 {
199 /* Native MOVSX at 0x43bbd6 sign-extends the count before decrementing. */
200 int32_t frame_count = (int32_t)animation_data->channel_counts[channel_index];
201
202 if (frame_count)
203 {
204 // Convert relative offset to absolute pointer: keyframePtr = (offset + baseAddr). PKG files store
205 // offsets relative to resource start for relocatability.
206 struct Animation_SplineChannelVec3 *channel_cursor = (struct Animation_SplineChannelVec3 *)(blob_base + (uintptr_t)*channel_array_slot);
207
208 *channel_array_slot = channel_cursor;
209
210 do
211 {
212 struct Animation_Vec3Keyframe *keyframes_or_minus_one_sentinel =
213 channel_cursor->keyframes_or_minus_one_sentinel;
214
215 if (keyframes_or_minus_one_sentinel && (uintptr_t)keyframes_or_minus_one_sentinel != UINT32_MAX
216 // Keyframe array fixup: If pointer valid (not 0 or -1) and not already fixed (bit 15 of flags), add base and
217 // mark as fixed. Bit 15 prevents double-fixup.
219 {
221
222 void *channel_data = blob_base + (uintptr_t)channel_cursor->keyframes_or_minus_one_sentinel;
223 bool channel_is_not_nested = !((char)channel_cursor->channel_flags & ANIMATION_SPLINE_NESTED_CHANNEL_ARRAY);
224
225 channel_cursor->keyframes_or_minus_one_sentinel = channel_data;
226
227 if (!channel_is_not_nested)
228 {
229 struct Animation_SplineChannel *nested_channel = channel_data;
230 int32_t nested_channel_index = 0;
231
232 // Morph target nested fixup: Bit 6 (0x40) of flags indicates morph channel has nested
233 // pointers that also need base address added.
234 if (channel_cursor->keyframe_count > 0)
235 {
236 int32_t nested_channel_count;
237
238 do
239 {
242
244 nested_channel->channel_data_or_minus_one_sentinel =
245 blob_base + (uintptr_t)channel_data_or_minus_one_sentinel;
246
247 nested_channel_index += 1;
248 nested_channel_count = (uint8_t)channel_cursor->keyframe_count;
249 nested_channel = &nested_channel[1];
250 } while (nested_channel_index < nested_channel_count);
251 }
252 }
253 }
254
255 channel_cursor = &channel_cursor[1];
256 } while (--frame_count);
257 }
258
259 channel_index += 1;
260 channel_array_slot = &channel_array_slot[1];
261 } while (channel_index < PKG_ANIMATION_CHANNEL_GROUP_COUNT);
262}
263
264// Original pcdogs.exe: 0x43bc50
265// Resolves material indices and optional face-normal offsets in place. The loop executes at least once and requires a positive reference count.
266void Pkg_FixUpResourceMaterialRefs(struct Pkg_MaterialRefFixupView *material_refs, int32_t ref_count)
267{
268 int32_t refs_remaining = ref_count;
269 struct Pkg_MaterialRefFixupView *material_ref = material_refs;
270
271 do
272 {
273 material_ref->material_index_or_ptr =
274 (uint32_t)(&g_levelMaterialSection->material_entries[material_ref->material_index_or_ptr]);
275
276 if (material_ref->face_normal_offset_or_ptr)
277 material_ref->face_normal_offset_or_ptr =
278 (uint32_t)(&g_levelBlobPtr[material_ref->face_normal_offset_or_ptr]);
279
280 material_ref = &material_ref[1];
281 } while (--refs_remaining);
282}
283
284// Original pcdogs.exe: 0x43bc90
285// Relocates an enabled material-index list and its entries, including the extra payloads for kind 1. The skip flag is checked but not set, so repeated calls are not automatically safe.
287{
288 if (index_list_raw->flags & PKG_MATERIAL_INDEX_SKIP_FIXUP)
289 return;
290
291 int32_t entry_index = 0;
292 bool no_material_indices = index_list_raw->entry_count <= 0;
293
294 index_list_raw->entries_offset += (uint32_t)(uintptr_t)g_levelBlobPtr;
295
296 if (no_material_indices)
297 return;
298
299 do
300 {
301 struct PKG_MaterialIndexEntry **entries = (struct PKG_MaterialIndexEntry **)index_list_raw->entries_offset;
302 struct PKG_MaterialIndexEntry *material_index_entry = (struct PKG_MaterialIndexEntry *)(g_levelBlobPtr + (uintptr_t)entries[entry_index]);
303
304 entries[entry_index] = material_index_entry;
305
306 if (material_index_entry->entry_kind == PKG_MATERIAL_ENTRY_EXTRA_PAYLOAD)
307 {
308 material_index_entry->payload_14_offset_or_pointer += (uint32_t)(uintptr_t)g_levelBlobPtr;
309 material_index_entry->payload_10 = &g_levelBlobPtr[(uintptr_t)material_index_entry->payload_10];
310 }
311
312 entry_index += 1;
313 } while (entry_index < (int32_t)index_list_raw->entry_count);
314}
315
316// Original pcdogs.exe: 0x43bcf0
317// Fixes each render entry's sprite layer and relocates its tail pointer, returning immediately for a zero count. Negative counts are not rejected.
318void Pkg_FixUpResourceRenderNodeEntries(struct Mesh_RenderNodeEntry *entries, int32_t entry_count)
319{
320 if (!entry_count)
321 return;
322
323 int32_t remaining_entries = entry_count;
324 void **tail_ptr_field = &entries->relocated_tail_ptr;
325
326 do
327 {
328 Pkg_FixUpResourceSpriteEntry((struct PKG_SpriteMaterialLayerRaw *)(&tail_ptr_field[-4]));
329 *(uint32_t *)tail_ptr_field += (uintptr_t)g_levelBlobPtr;
330 tail_ptr_field = &tail_ptr_field[8];
331 } while (--remaining_entries);
332}
333
334// Original pcdogs.exe: 0x43bd30
335// Binds the level material section, resolves a nonnegative material index, and fixes an optional material-index list. Negative material indices become null bindings.
337{
338 sprite_material_raw->texture_db = (struct Material_Entry *)(g_levelMaterialSection);
339
340 int32_t material = sprite_material_raw->material;
341
342 if (material >= 0)
343 sprite_material_raw->material = (int32_t)(&g_levelMaterialSection->material_entries[material]);
344 else
345 sprite_material_raw->material = 0;
346
347 if (!sprite_material_raw->material)
348 return;
349
350 uint32_t material_indices_rel = sprite_material_raw->material_indices_rel;
351
352 if (!material_indices_rel)
353 return;
354
355 uint32_t index_list_raw = (uint32_t)(&g_levelBlobPtr[material_indices_rel]);
356
357 sprite_material_raw->material_indices_rel = index_list_raw;
359}
360
361// Original pcdogs.exe: 0x43bd80
362// Relocates type-3 mesh and component data, material bindings, auxiliary arrays, and terminated relocation lists in place. The first relocation list preserves sentinel 1, and populated counted arrays require valid positive counts.
364{
365 void *normals_or_list = node->normals_or_list;
366
367 if (normals_or_list)
368 {
369 node->normals_or_list = (char *)normals_or_list + (uintptr_t)g_levelBlobPtr;
370
371 void *uv_or_child_list = node->uv_or_child_list;
372
373 if (uv_or_child_list)
374 node->uv_or_child_list = (char *)uv_or_child_list + (uintptr_t)g_levelBlobPtr;
375 }
376
377 void *aux_84 = node->aux_84;
378
379 if (aux_84)
380 node->aux_84 = (char *)aux_84 + (uintptr_t)g_levelBlobPtr;
381
382 void *material_refs = node->material_refs;
383
384 if (material_refs)
385 {
386 /* Preserve native reads of the unused material-fixup arguments. */
387 const volatile struct PKG_ObjectNodeFixupView *native_node = node;
388
389 (void)native_node->aux_84;
390
391 struct Pkg_MaterialRefFixupView *material_refs_2 = (struct Pkg_MaterialRefFixupView *)((char *)material_refs + (uintptr_t)g_levelBlobPtr);
392 int32_t material_ref_count_1 = (int32_t)native_node->material_ref_count;
393
394 (void)native_node->normals_or_list;
395
396 ((volatile struct PKG_ObjectNodeFixupView *)node)->material_refs = material_refs_2;
397
398 Pkg_FixUpResourceMaterialRefs(material_refs_2, material_ref_count_1);
399 }
400
401 void *entries_90 = node->entries_90;
402
403 if (entries_90)
404 node->entries_90 = (char *)entries_90 + (uintptr_t)g_levelBlobPtr;
405
406 void *entries_94 = node->entries_94;
407
408 if (entries_94)
409 {
410 int32_t entry_count_f2 = (int32_t)node->entry_count_f2;
411 struct PKG_TypedMaterialEntry *typed_entry_cursor = (struct PKG_TypedMaterialEntry *)((char *)entries_94 + (uintptr_t)g_levelBlobPtr);
412
413 node->entries_94 = typed_entry_cursor;
414
415 do
416 {
417 if (typed_entry_cursor->entry_kind == PKG_MATERIAL_ENTRY_TABLE_REFERENCE)
418 typed_entry_cursor->material_index_or_pointer =
419 (uint32_t)(&g_levelMaterialSection->material_entries[typed_entry_cursor->material_index_or_pointer]);
420
421 typed_entry_cursor = &typed_entry_cursor[1];
422 } while (--entry_count_f2);
423 }
424
425 void *aux_80 = node->aux_80;
426
427 if (aux_80)
428 {
429 /* The native no-op call still evaluates its material arguments. */
430 const volatile struct PKG_ObjectNodeFixupView *native_node = node;
431 void *material_refs_for_noop = native_node->material_refs;
432 void *relocated_aux80 = (char *)aux_80 + (uintptr_t)g_levelBlobPtr;
433
434 ((volatile struct PKG_ObjectNodeFixupView *)node)->aux_80 = relocated_aux80;
435
436 if (material_refs_for_noop)
437 (void)native_node->material_ref_count;
438 }
439
440 struct Mesh_RenderNodeEntry *render_entries = node->render_entries;
441
442 if (render_entries)
443 {
444 int32_t entry_count = (uint8_t)(node->render_entry_count);
445 struct Mesh_RenderNodeEntry *entries = (struct Mesh_RenderNodeEntry *)((char *)render_entries + (uintptr_t)g_levelBlobPtr);
446
447 node->render_entries = entries;
448 Pkg_FixUpResourceRenderNodeEntries(entries, entry_count);
449 }
450
451 void *secondary_entries = node->secondary_entries;
452
453 if (secondary_entries)
454 {
455 void *relocated_secondary_entries = (char *)secondary_entries + (uintptr_t)g_levelBlobPtr;
456 int32_t secondary_entries_remaining = (uint8_t)(node->secondary_entry_count);
457
458 node->secondary_entries = relocated_secondary_entries;
459
460 struct PKG_SecondaryEntry *secondary_entry_cursor = relocated_secondary_entries;
461
462 do
463 {
464 secondary_entry_cursor->ptr_24 += (uintptr_t)g_levelBlobPtr;
465 secondary_entry_cursor = &secondary_entry_cursor[1];
466 } while (--secondary_entries_remaining);
467 }
468
470
471 void *material_indices_or_polygons = node->material_indices_or_polygons;
472
473 if (material_indices_or_polygons)
474 {
475 struct PKG_MaterialIndexList *index_list_raw =
476 (struct PKG_MaterialIndexList *)((char *)material_indices_or_polygons + (uintptr_t)g_levelBlobPtr);
477
478 node->material_indices_or_polygons = index_list_raw;
479 Pkg_FixUpResourceMaterialIndices(index_list_raw);
480 }
481
482 int32_t *relocation_list_b0 = node->relocation_list_b0;
483
484 if (relocation_list_b0)
485 {
486 int32_t *relocation_b0_cursor = (int32_t *)((char *)relocation_list_b0 + (uintptr_t)g_levelBlobPtr);
487
488 node->relocation_list_b0 = relocation_b0_cursor;
489
490 int32_t relative_offset_or_sentinel = *(uint32_t *)relocation_b0_cursor;
491
492 while (relative_offset_or_sentinel)
493 {
494 if (relative_offset_or_sentinel != PKG_RELOCATION_POINTER_SENTINEL)
495 *(uint32_t *)relocation_b0_cursor = (uint32_t)((uint8_t *)node->relocation_list_b0 + relative_offset_or_sentinel);
496 else
497 *(uint32_t *)relocation_b0_cursor = relative_offset_or_sentinel;
498
499 relative_offset_or_sentinel = relocation_b0_cursor[1];
500 relocation_b0_cursor = &relocation_b0_cursor[1];
501 }
502 }
503
504 int32_t *relocation_list_100 = node->relocation_list_100;
505
506 if (relocation_list_100)
507 {
508 int32_t *relocation_100_cursor = (int32_t *)((char *)relocation_list_100 + (uintptr_t)g_levelBlobPtr);
509
510 node->relocation_list_100 = relocation_100_cursor;
511
512 for (void *relative_record_offset = (void *)(*(uint32_t *)relocation_100_cursor); relative_record_offset; relative_record_offset = (void *)(*(uint32_t *)relocation_100_cursor))
513 {
514 relocation_100_cursor = &relocation_100_cursor[1];
515 relocation_100_cursor[-1] = (uintptr_t)relative_record_offset + (uintptr_t)node->relocation_list_100;
516 }
517 }
518
519 int32_t *linked_records = node->linked_records;
520
521 if (linked_records)
522 {
523 int32_t *linked_record_array = (int32_t *)((char *)linked_records + (uintptr_t)g_levelBlobPtr);
524
525 node->linked_records = linked_record_array;
526
527 int32_t linked_record_offset = *(uint32_t *)linked_record_array;
528 int32_t *linked_record_cursor = &linked_record_array[1];
529
530 for (; linked_record_offset; linked_record_offset = (uint32_t)linked_record_cursor[-1])
531 {
532 linked_record_cursor += 1;
533
534 void *relocated_linked_record = &g_levelBlobPtr[linked_record_offset];
535
536 linked_record_cursor[-2] = (uint32_t)(relocated_linked_record);
537 ((struct PKG_LinkedPayloadFixupView *)relocated_linked_record)->payload_offset_or_pointer += (uintptr_t)g_levelBlobPtr;
538 }
539 }
540
541 void *component_or_owner = node->component_or_owner;
542
543 if (component_or_owner)
544 {
545 void *relocated_component_owner = (char *)component_or_owner + (uintptr_t)g_levelBlobPtr;
546
547 node->component_or_owner = relocated_component_owner;
548
550 {
551 struct PKG_OwnerPayloadFixupRecord *owner_payload_records;
552
553 if (!node->secondary_entry_count)
554 owner_payload_records = ((struct PKG_PrimaryOwnerFixupView *)relocated_component_owner)->payload_records;
555 else
556 owner_payload_records = ((struct PKG_SecondaryOwnerFixupView *)relocated_component_owner)->payload_records;
557
558 struct PKG_OwnerPayloadFixupRecord *owner_payload_cursor = owner_payload_records;
559 int32_t component_records_remaining = PKG_COMPONENT_RECORD_COUNT;
560
561 do
562 {
563 void *component_record_offset = (void *)(owner_payload_cursor->blob_payload);
564
565 if (component_record_offset)
566 owner_payload_cursor->blob_payload = (uint32_t)((char *)component_record_offset + (uintptr_t)g_levelBlobPtr);
567
568 owner_payload_cursor = &owner_payload_cursor[1];
569 } while (--component_records_remaining);
570 }
571 }
572
573 void *extra_c8 = node->extra_c8;
574
575 if (extra_c8)
576 node->extra_c8 = (char *)extra_c8 + (uintptr_t)g_levelBlobPtr;
577
578 void *global_texture_refs = node->global_texture_refs;
579
580 if (!global_texture_refs)
581 return;
582
583 void *relocated_global_texture_refs = (char *)global_texture_refs + (uintptr_t)g_levelBlobPtr;
584
585 node->global_texture_refs = relocated_global_texture_refs;
586 Material_GetGlobalTextureRefs(&((struct PKG_GlobalMaterialBindingView *)relocated_global_texture_refs)->shared_material);
587}
588
589// Original pcdogs.exe: 0x43c040
590// Relocates a type-8 node's nonnull material-reference pointer against the level blob.
592{
593 void *material_refs = node->material_refs;
594
595 if (material_refs)
596 node->material_refs = (uintptr_t)material_refs + g_levelBlobPtr;
597}
598
599// Original pcdogs.exe: 0x43c060
600// Fixes the sprite material layer embedded at the type-7 node's material-reference fields.
605
606// Original pcdogs.exe: 0x43c070
607// Relocates hierarchy lists, nested object nodes, polygon-node references, and six auxiliary linked lists. Requires valid blob offsets and terminating list links.
609{
610 void *normals_or_list = node->normals_or_list;
611
612 if (normals_or_list)
613 {
614 int32_t *normal_list_cursor = (int32_t *)((char *)normals_or_list + (uintptr_t)g_levelBlobPtr);
615
616 node->normals_or_list = normal_list_cursor;
617
618 for (; normal_list_cursor; normal_list_cursor = (int32_t *)(*(uint32_t *)normal_list_cursor))
619 {
620 void *normal_list_next_offset = (void *)(*(uint32_t *)normal_list_cursor);
621
622 if (normal_list_next_offset)
623 *(uint32_t *)normal_list_cursor = (uint32_t)(uintptr_t)((char *)normal_list_next_offset + (uintptr_t)g_levelBlobPtr);
624 }
625 }
626
627 void *uv_or_child_list = node->uv_or_child_list;
628
629 if (uv_or_child_list)
630 {
631 struct PKG_ObjectNodeFixupView *node_type_1 = (struct PKG_ObjectNodeFixupView *)((char *)uv_or_child_list + (uintptr_t)g_levelBlobPtr);
632
633 node->uv_or_child_list = node_type_1;
634
635 do
636 {
638
639 uint32_t node_type = node_type_1->node_type;
640
641 if (node_type)
642 node_type_1->node_type = (uint32_t)(uintptr_t)(&g_levelBlobPtr[node_type]);
643
644 node_type_1->extra_d8 = (char *)g_levelBlobPtr + (uintptr_t)node_type_1->extra_d8;
645 node_type_1 = (struct PKG_ObjectNodeFixupView *)(node_type_1->node_type);
646 } while (node_type_1);
647 }
648
649 if (node->material_section_or_list)
650 {
651 void *aux_80 = node->aux_80;
652
653 if (aux_80)
654 {
655 struct PKG_MaterialIndexList *index_list_raw = (struct PKG_MaterialIndexList *)((char *)aux_80 + (uintptr_t)g_levelBlobPtr);
656
657 node->aux_80 = index_list_raw;
658 Pkg_FixUpResourceMaterialIndices(index_list_raw);
659 }
660
661 uint32_t *rel_node_list = node->material_section_or_list + (uintptr_t)g_levelBlobPtr;
662
663 node->material_section_or_list = rel_node_list;
664 Pkg_FixUpResourcePolygonList(rel_node_list, 1);
665 }
666
669
670 int32_t *list_head_a4 = node->list_head_a4;
671
672 if (list_head_a4)
673 {
674 int32_t *list_a4_cursor = (int32_t *)((char *)list_head_a4 + (uintptr_t)g_levelBlobPtr);
675
676 node->list_head_a4 = list_a4_cursor;
677
678 for (; list_a4_cursor; list_a4_cursor = (int32_t *)(*(uint32_t *)list_a4_cursor))
679 {
680 void *list_a4_next_offset = (void *)(*(uint32_t *)list_a4_cursor);
681
682 if (list_a4_next_offset)
683 *(uint32_t *)list_a4_cursor = (uint32_t)(uintptr_t)((char *)list_a4_next_offset + (uintptr_t)g_levelBlobPtr);
684 }
685 }
686
687 int32_t *list_head_9c = node->list_head_9c;
688
689 if (list_head_9c)
690 {
691 int32_t *list_9c_cursor = (int32_t *)((char *)list_head_9c + (uintptr_t)g_levelBlobPtr);
692
693 node->list_head_9c = list_9c_cursor;
694
695 for (; list_9c_cursor; list_9c_cursor = (int32_t *)(*(uint32_t *)list_9c_cursor))
696 {
697 void *list_9c_next_offset = (void *)(*(uint32_t *)list_9c_cursor);
698
699 if (list_9c_next_offset)
700 *(uint32_t *)list_9c_cursor = (uint32_t)(uintptr_t)((char *)list_9c_next_offset + (uintptr_t)g_levelBlobPtr);
701 }
702 }
703
704 void **auxiliary_list_slot = &node->aux_84;
705 int32_t lists_remaining = PKG_NODE_AUXILIARY_LIST_COUNT;
706
707 do
708 {
709 void *aux_84 = *auxiliary_list_slot;
710
711 if (aux_84)
712 {
713 void **auxiliary_list_cursor = (void **)((char *)aux_84 + (uintptr_t)g_levelBlobPtr);
714
715 *auxiliary_list_slot = auxiliary_list_cursor;
716
717 for (; auxiliary_list_cursor; auxiliary_list_cursor = (void **)(*(uint32_t *)auxiliary_list_cursor))
718 {
719 void *auxiliary_next_offset = (void *)(*(uint32_t *)auxiliary_list_cursor);
720
721 if (auxiliary_next_offset)
722 *(uint32_t *)auxiliary_list_cursor = (uint32_t)(uintptr_t)((char *)auxiliary_next_offset + (uintptr_t)g_levelBlobPtr);
723 }
724 }
725
726 auxiliary_list_slot = &auxiliary_list_slot[1];
727 } while (--lists_remaining);
728}
729
730// Original pcdogs.exe: 0x43c1f0
731// Relocates mesh-sized nodes from either an inline pointer array or a linked list and fixes their geometry and materials. Sprite nodes use the sprite-specific path; the input is not an array of compact collision polygons.
732void Pkg_FixUpResourcePolygonList(uint32_t *rel_node_list, BOOL list_entries_are_inline)
733{
734 struct Pkg_ObjectNodeFixupView **node_pointer_cursor = (struct Pkg_ObjectNodeFixupView **)(rel_node_list);
735
736 for (uint32_t node_offset = *(uint32_t *)node_pointer_cursor; node_offset; node_offset = *(uint32_t *)node_pointer_cursor)
737 {
738 struct Pkg_ObjectNodeFixupView *node = (struct Pkg_ObjectNodeFixupView *)(&g_levelBlobPtr[node_offset]);
739
740 *(uint32_t *)node_pointer_cursor = (uint32_t)(node);
741
742 if (list_entries_are_inline)
743 {
745
746 if (first_child)
747 node->first_child = (struct Pkg_ObjectNodeFixupView *)((char *)first_child + (uintptr_t)g_levelBlobPtr);
748
749 node_pointer_cursor = &node_pointer_cursor[1];
750 }
751 else
752 node_pointer_cursor = (struct Pkg_ObjectNodeFixupView **)(node);
753
754 if (node->node_fixup_type != PKG_NODE_SPRITE)
755 {
756 void *normals_or_list_1 = node->normals_or_list;
757
758 if (normals_or_list_1)
759 {
760 node->normals_or_list = (char *)normals_or_list_1 + (uintptr_t)g_levelBlobPtr;
761
763
765 node->uv_or_child_list = (char *)uv_or_child_list + (uintptr_t)g_levelBlobPtr;
766 }
767
768 void *aux_84_1 = node->aux_84;
769
770 if (aux_84_1)
771 node->aux_84 = (char *)aux_84_1 + (uintptr_t)g_levelBlobPtr;
772
773 void *material_refs_1 = node->material_refs;
774
775 if (material_refs_1)
776 {
777 struct Pkg_MaterialRefFixupView *material_refs_2 =
778 (struct Pkg_MaterialRefFixupView *)((char *)material_refs_1 + (uintptr_t)g_levelBlobPtr);
779 bool material_ref_count_nonpositive = *(const volatile int16_t *)&node->field_68 <= 0;
780
781 ((volatile struct Pkg_ObjectNodeFixupView *)node)->material_refs = material_refs_2;
782
783 if (!material_ref_count_nonpositive)
784 {
785 const volatile struct Pkg_ObjectNodeFixupView *native_node = node;
786
787 (void)native_node->aux_84;
788 (void)native_node->normals_or_list;
789 Pkg_FixUpResourceMaterialRefs(material_refs_2,
790 (int32_t)native_node->material_ref_count);
791 }
792 }
793
795
797
799 {
800 struct PKG_MaterialIndexList *relocated_polygon_list = (struct PKG_MaterialIndexList *)((char *)material_indices_or_polygons + (uintptr_t)g_levelBlobPtr);
801
802 node->material_indices_or_polygons = relocated_polygon_list;
803 relocated_polygon_list->entries_offset += (uintptr_t)g_levelBlobPtr;
804
805 struct PKG_MaterialIndexList *material_indices_or_polygons_1 = node->material_indices_or_polygons;
806 int32_t j = 0;
807
808 if (material_indices_or_polygons_1->entry_count > 0)
809 {
810 do
811 {
812 uint32_t *polygon_pointer_array = (uint32_t *)material_indices_or_polygons_1->entries_offset;
813
814 polygon_pointer_array[j] =
815 (uint32_t)(&g_levelBlobPtr[polygon_pointer_array[j]]);
816 j += 1;
817 material_indices_or_polygons_1 = node->material_indices_or_polygons;
818 } while (j < (int32_t)material_indices_or_polygons_1->entry_count);
819 }
820 }
821
822 void *aux_80 = node->aux_80;
823
824 if (aux_80)
825 {
826 /* Keep the native condition and argument reads before its no-op call. */
827 const volatile struct Pkg_ObjectNodeFixupView *native_node = node;
828 void *relocated_aux80 = (char *)aux_80 + (uintptr_t)g_levelBlobPtr;
829 bool auxiliary_ref_count_nonpositive = *(const volatile int16_t *)&native_node->field_68 <= 0;
830
831 ((volatile struct Pkg_ObjectNodeFixupView *)node)->aux_80 = relocated_aux80;
832
833 if (!auxiliary_ref_count_nonpositive)
834 {
835 (void)native_node->material_ref_count;
836 (void)native_node->material_refs;
837 }
838 }
839 }
840 else
842 }
843}
844
845// Original pcdogs.exe: 0x43c340
846// Relocates 384-byte package actor records, sounds, variables, powerups, sprites, themes, trails, navigation, and usable materials in place. Alias indices copy currently stored values without bounds checks, and diagnostics do not make null inputs safe.
848{
850
851 Debug_Log("start FixUpLevel", NULL);
852
853 if (!level)
854
855 Debug_Log("FixUpLevel(): level == NULL!", (const char *)(level));
856
857 if (!g_levelBlobPtr)
858 Debug_Log("FixUpLevel(): levelBase == NULL!", NULL);
859
861 Debug_Log("level->cam_default = ABS_ADDR(...);", NULL);
862
863 int32_t debug_logging_enabled = g_debugLoggingEnabled;
864 char *camera_fixup_message;
865
866 if (level->cam_default_offset)
867 {
868 if (debug_logging_enabled)
869
870 Debug_Log("level->cam_default: get abs address.", NULL);
871
872 level->cam_default_offset = (uint32_t)(&g_levelBlobPtr[level->cam_default_offset]);
873
875 {
876 camera_fixup_message = "level->cam_default != NULL";
877
878 Debug_Log(camera_fixup_message, NULL);
879
881
882 Debug_Log("level->actor_ct...", NULL);
883 }
884 }
885 else if (debug_logging_enabled)
886 {
887 camera_fixup_message = "level->cam_default = NULL";
888
889 Debug_Log(camera_fixup_message, NULL);
890
892
893 Debug_Log("level->actor_ct...", NULL);
894 }
895
896 int32_t entity_count = (uint16_t)(level->entity_count);
897
898 if (entity_count <= 0)
899 Debug_Log("level->actor_ct <= 0!", NULL);
900
901 if (entity_count)
902 {
903 uint8_t *level_blob_ptr = g_levelBlobPtr;
904 uint32_t entity_array_offset = level->entity_array_offset;
905
906 level->entity_array_offset = (uint32_t)(&level_blob_ptr[entity_array_offset]);
907
908 if (entity_array_offset == -(uintptr_t)(level_blob_ptr))
909 {
911 }
912 else if (g_debugLoggingEnabled)
913 {
914 Debug_Log("level->actor_list != NULL", NULL);
915 }
916
917 struct Pkg_ActorRecord *actor_record_array = (struct Pkg_ActorRecord *)(level->entity_array_offset);
918
920 Debug_Log("cycle thru actor list.", NULL);
921
922 if (entity_count > 0)
923 {
924 struct Pkg_ActorRecord *actor_record = actor_record_array;
925 int32_t entities_remaining = entity_count;
926
927 do
928 {
929 struct Math_Vec3I32 *bonus_respawn_target_pos = actor_record->bonus_respawn_target_pos;
930
931 if (bonus_respawn_target_pos)
932
933 actor_record->bonus_respawn_target_pos = (struct Math_Vec3I32 *)((uintptr_t)bonus_respawn_target_pos + g_levelBlobPtr);
934
935 void *actor_template_header_ref = actor_record->actor_template_header_ref;
936
937 if (actor_template_header_ref)
938 {
939 if (!((uintptr_t)actor_template_header_ref & PKG_REFERENCE_ALIAS_TAG))
940 {
941 struct Pkg_ActorTemplate *actor_template =
942
943 (struct Pkg_ActorTemplate *)((uintptr_t)actor_template_header_ref + g_levelBlobPtr);
944
945 actor_record->actor_template_header_ref = actor_template;
947 }
948 else
949
950 actor_record->actor_template_header_ref = ((struct Pkg_ActorRecord *)level->entity_array_offset)[(uintptr_t)actor_template_header_ref >> PKG_REFERENCE_ALIAS_INDEX_SHIFT].actor_template_header_ref;
951 }
952
953 void *script_base_ptr = actor_record->script_base_ptr;
954
955 if (script_base_ptr)
956 {
957 if (!((uintptr_t)script_base_ptr & PKG_REFERENCE_ALIAS_TAG))
958 // Resolve direct component pointers and their nested data.
959 actor_record->script_base_ptr = g_levelBlobPtr + (uintptr_t)script_base_ptr;
960 else
961
962 actor_record->script_base_ptr = ((struct Pkg_ActorRecord *)level->entity_array_offset)[(uintptr_t)script_base_ptr >> PKG_REFERENCE_ALIAS_INDEX_SHIFT].script_base_ptr;
963 }
964
965 void **component_ref_slot = &actor_record->shared_ref_50;
966 int32_t component_refs_remaining = PKG_ACTOR_SHARED_COMPONENT_COUNT;
967
968 do
969 {
970 void *shared_ref_50 = (*component_ref_slot);
971
972 if (shared_ref_50)
973 {
974 if (!((uintptr_t)shared_ref_50 & PKG_REFERENCE_ALIAS_TAG))
975 {
976 struct Pkg_ComponentData *component_data =
977
978 (struct Pkg_ComponentData *)((uintptr_t)shared_ref_50 + g_levelBlobPtr);
979
980 (*component_ref_slot) = component_data;
981 Pkg_FixUpResourceComponentNodes(component_data);
982 }
983 else
984 {
985 uint32_t component_alias_index = (uintptr_t)shared_ref_50 >> PKG_REFERENCE_ALIAS_INDEX_SHIFT;
986
987 (*component_ref_slot) = ((struct Pkg_ActorRecord *)level->entity_array_offset)[component_alias_index >> 2].component_alias_slots[component_alias_index & 3];
988 }
989 }
990
991 component_ref_slot = &component_ref_slot[1];
992 } while (--component_refs_remaining);
993
994 actor_record = &actor_record[1];
995 } while (--entities_remaining);
996 }
997 }
998
1000 Debug_Log("level->sound_list", NULL);
1001
1002 uint32_t sound_definition_list_offset = level->sound_definition_list_offset;
1003
1004 if (sound_definition_list_offset)
1005 level->sound_definition_list_offset = (uint32_t)(&g_levelBlobPtr[sound_definition_list_offset]);
1006
1008 Debug_Log("level->var_list", NULL);
1009
1010 uint32_t var_list_offset = level->var_list_offset;
1011
1012 if (var_list_offset)
1013 level->var_list_offset = (uint32_t)(&g_levelBlobPtr[var_list_offset]);
1014
1016
1017 Debug_Log("level->powerup_ct ... ", NULL);
1018
1019 int32_t powerups_remaining = (uint16_t)(level->powerup_count);
1020
1021 if (powerups_remaining)
1022 {
1023 int32_t *powerup_list = (int32_t *)(&g_levelBlobPtr[level->powerup_list_offset]);
1024
1025 level->powerup_list_offset = (uint32_t)(powerup_list);
1026
1027 int32_t *powerup_record_cursor = powerup_list;
1028
1029 if (powerups_remaining > 0)
1030 {
1031 do
1032 {
1033 void *powerup_node_offset = (void *)(*(uint32_t *)powerup_record_cursor);
1034
1035 if (powerup_node_offset)
1036 *(uint32_t *)powerup_record_cursor = (uint32_t)((uintptr_t)powerup_node_offset + g_levelBlobPtr);
1037
1038 powerup_record_cursor = &powerup_record_cursor[7];
1039 } while (--powerups_remaining);
1040 }
1041 }
1042
1044 Debug_Log("level->sprite_list", NULL);
1045
1046 uint32_t sprite_list_offset = level->sprite_list_offset;
1047
1048 if (sprite_list_offset)
1049 {
1050 void *sprite_list = &g_levelBlobPtr[sprite_list_offset];
1051
1052 level->sprite_list_offset = (uint32_t)(sprite_list);
1053
1054 struct PKG_SpriteEntry *sprite_cursor = sprite_list;
1055 struct PKG_SpriteMaterialLayerRaw *sprite_material_raw = (struct PKG_SpriteMaterialLayerRaw *)&sprite_cursor->texture_db1;
1056 char sprite_list_flags;
1057
1058 do
1059 {
1060 if (sprite_material_raw->texture_db)
1061 {
1062 sprite_material_raw->texture_db = (struct Material_Entry *)(g_sharedMaterialSection);
1063 sprite_material_raw->material = (int32_t)(Shared_FontDataCursor[sprite_material_raw->material].material_table_entry);
1064 }
1065 else
1066 {
1067 Pkg_FixUpResourceSpriteEntry(sprite_material_raw);
1068 Pkg_FixUpResourceSpriteEntry(&sprite_material_raw[1]);
1069 }
1070
1071 sprite_list_flags = (char)sprite_cursor->state_flags;
1072 sprite_cursor = &sprite_cursor[1];
1073 sprite_material_raw = (struct PKG_SpriteMaterialLayerRaw *)&sprite_cursor->texture_db1;
1074 } while (!(sprite_list_flags & PKG_SPRITE_LIST_END));
1075 }
1076
1078
1079 Debug_Log("MAX_LEVEL_THEMES", NULL);
1080
1081 /* Five theme slots: even values are blob offsets; odd values encode slot indexes.
1082 Indexed references remain unchecked and copy the slot's current value once. */
1083 uint32_t *theme_slot = level->theme_offsets;
1084 int32_t themes_remaining = PKG_LEVEL_THEME_COUNT;
1085
1086 do
1087 {
1088 uint32_t theme_reference = (*theme_slot);
1089
1090 if (theme_reference)
1091 {
1092 if (!((uint8_t)theme_reference & PKG_REFERENCE_ALIAS_TAG))
1093 (*theme_slot) = (uint32_t)(&g_levelBlobPtr[theme_reference]);
1094 else
1095 (*theme_slot) = level->theme_offsets[theme_reference >> PKG_REFERENCE_ALIAS_INDEX_SHIFT];
1096 }
1097
1098 theme_slot = &theme_slot[1];
1099 } while (--themes_remaining);
1100
1102 Debug_Log("level->trail_list", NULL);
1103
1104 int32_t trail_index = 0;
1105
1106 level->trail_list_offset = (uint32_t)(&g_levelBlobPtr[level->trail_list_offset]);
1107
1108 do
1109 {
1110 struct Trail_Entry *trail_list = (struct Trail_Entry *)level->trail_list_offset;
1111 void *trail_payload_offset = trail_list[trail_index].data_ptr;
1112
1113 if (trail_payload_offset)
1114 {
1115 trail_list[trail_index].data_ptr = (uintptr_t)trail_payload_offset + g_levelBlobPtr;
1116
1117 struct Trail_Entry *trail_record = &((struct Trail_Entry *)level->trail_list_offset)[trail_index];
1118
1119 if (trail_record->data_type == PKG_TRAIL_DATA_SCENE_NODE)
1120 {
1121 struct PKG_ObjectNodeFixupView *node = (struct PKG_ObjectNodeFixupView *)(trail_record->data_ptr);
1122
1124
1125 struct Animation_StateTable *animation_state_table = node->animation_state_table;
1126
1127 if (animation_state_table)
1128 {
1129 struct Animation_StateTable *trail_animations = (struct Animation_StateTable *)((uintptr_t)animation_state_table + g_levelBlobPtr);
1130
1131 node->animation_state_table = trail_animations;
1132 trail_animations->anim_ptrs[0] = (struct Animation_DataBlock *)((uintptr_t)trail_animations->anim_ptrs[0] + g_levelBlobPtr);
1133
1136 }
1137 }
1138 else
1139
1141 }
1142
1143 trail_index += 1;
1144 } while (trail_index < PKG_LEVEL_TRAIL_COUNT);
1145
1147 Debug_Log("level->powerup_ct", NULL);
1148
1149 if (level->powerup_count)
1150 {
1151 uint32_t *powerup_template_slot = level->powerup_actor_template_offsets;
1152 int32_t templates_remaining = PKG_POWERUP_TEMPLATE_COUNT;
1153
1154 do
1155 {
1156 uint32_t powerup_template_offset = *powerup_template_slot;
1157
1158 if (powerup_template_offset)
1159 {
1160 struct Pkg_ActorTemplate *actor_template_1 = (struct Pkg_ActorTemplate *)(&g_levelBlobPtr[powerup_template_offset]);
1161
1162 *powerup_template_slot = (uint32_t)(actor_template_1);
1163 Pkg_FixUpResourceActorRecordPointers(actor_template_1);
1164 }
1165
1166 ++powerup_template_slot;
1167 } while (--templates_remaining);
1168 }
1169
1171 Debug_Log("level->nav_net", NULL);
1172
1173 uint32_t nav_net_offset = level->nav_net_offset;
1174
1175 if (nav_net_offset)
1176 {
1177 struct Nav_Network *navigation_header = (struct Nav_Network *)(&g_levelBlobPtr[nav_net_offset]);
1178
1179 level->nav_net_offset = (uint32_t)(navigation_header);
1180
1181 void *navigation_nodes_offset = (void *)(navigation_header->nodes);
1182
1183 if (navigation_nodes_offset)
1184 {
1185 uint32_t navigation_node_index = 0;
1186
1187 navigation_header->nodes = (struct Nav_Node *)((uintptr_t)navigation_nodes_offset + g_levelBlobPtr);
1188
1189 if ((uint32_t)navigation_header->node_count > 0)
1190 {
1191 do
1192 {
1193 struct Nav_Node *navigation_nodes = navigation_header->nodes;
1194 void *navigation_links_offset = navigation_nodes[navigation_node_index].neighbor_list;
1195
1196 if (navigation_links_offset)
1197 navigation_nodes[navigation_node_index].neighbor_list = (struct Nav_NeighborEntry *)((uintptr_t)navigation_links_offset + g_levelBlobPtr);
1198
1199 navigation_node_index += 1;
1200 } while (navigation_node_index < (uint32_t)navigation_header->node_count);
1201 }
1202 }
1203 }
1204
1206 Debug_Log("level->useable_mats", NULL);
1207
1208 uint32_t usable_materials_offset = level->usable_materials_offset;
1209
1210 if (usable_materials_offset)
1211 {
1212 int32_t usable_material_byte_offset = 0;
1213
1214 level->usable_materials_offset = (uint32_t)(&g_levelBlobPtr[usable_materials_offset]);
1215
1216 do
1217 {
1218 int32_t *useable_mat_entry = (int32_t *)(level->usable_materials_offset + usable_material_byte_offset);
1219 int32_t usable_material_index = useable_mat_entry[1];
1220
1221 if (usable_material_index)
1222 {
1223 useable_mat_entry[1] = (int32_t)(&g_levelMaterialSection->material_entries[usable_material_index]);
1224
1225 int32_t usable_frame_set_offset = *(uint32_t *)useable_mat_entry;
1226
1227 if (usable_frame_set_offset)
1228 {
1229 struct Material_FrameSet *frame_set = (struct Material_FrameSet *)(&g_levelBlobPtr[usable_frame_set_offset]);
1230
1231 *(uint32_t *)useable_mat_entry = (uint32_t)(frame_set);
1232 Material_BuildStructure(g_levelMaterialSection, (struct Material_RefEntry *)(useable_mat_entry), frame_set);
1233 }
1234 }
1235
1236 usable_material_byte_offset += 0xc;
1237 } while (usable_material_byte_offset < 0x60);
1238 }
1239
1240 int32_t debug_logging_enabled_2 = g_debugLoggingEnabled;
1241
1243
1244 if (debug_logging_enabled_2)
1245 Debug_Log("end FixUpLevel", NULL);
1246}
1247
1248// Original pcdogs.exe: 0x43c8b0
1249// Relocates 43 animation slots and three LOD nodes, then binds the primary node to its animation table and optional owner template. Odd animation references copy unchecked current slot values, and special node processing applies only to the first LOD.
1251{
1252 if (actor_template->anim_table)
1253 {
1254 actor_template->anim_table = (struct Animation_StateTable *)(g_levelBlobPtr + (uintptr_t)actor_template->anim_table);
1255 for (unsigned int i = 0; i < PKG_ACTOR_ANIMATION_SLOT_COUNT; ++i)
1256 {
1257 struct Animation_StateTable *table = actor_template->anim_table;
1258 uintptr_t ref = (uintptr_t)table->anim_ptrs[i];
1259 if (!ref)
1260 continue;
1261
1262 if (ref & PKG_REFERENCE_ALIAS_TAG)
1263 table->anim_ptrs[i] = table->anim_ptrs[ref >> PKG_REFERENCE_ALIAS_INDEX_SHIFT];
1264 else
1265 {
1266 table->anim_ptrs[i] = (struct Animation_DataBlock *)(g_levelBlobPtr + ref);
1268 }
1269 }
1270 }
1271
1272 for (int i = 0; i < PKG_ACTOR_LOD_COUNT; ++i)
1273 {
1274 uintptr_t offset = (uintptr_t)actor_template->lod_node_array[i];
1275 if (!offset)
1276 continue;
1277
1278 actor_template->lod_node_array[i] = (struct PKG_ObjectNodeFixupView *)(g_levelBlobPtr + offset);
1279 if (i == 0)
1283 }
1284
1285 struct PKG_ObjectNodeFixupView *primary = actor_template->lod_nodes;
1286 if (primary)
1287 {
1288 primary->animation_state_table = actor_template->anim_table;
1289 primary->owner_template = actor_template->alternate_lod_node ? actor_template : NULL;
1290 }
1291}
1292
1293// Original pcdogs.exe: 0x43c980
1294// Relocates four component subnodes, binds their owner records, and fixes each present animation table's first animation. Referenced owner records and blob offsets must be valid.
1296{
1297 int32_t remaining_slots = PKG_COMPONENT_SUBNODE_COUNT;
1298 struct Pkg_ObjectNodeFixupView **sub_node_slot = (struct Pkg_ObjectNodeFixupView **)(&component_data->sub_nodes);
1299
1300 do
1301 {
1302 struct Pkg_ObjectNodeFixupView *sub_node_offset = *sub_node_slot;
1303
1304 if (sub_node_offset)
1305 {
1306 struct Pkg_ObjectNodeFixupView *node = (struct Pkg_ObjectNodeFixupView *)((char *)sub_node_offset + (uintptr_t)g_levelBlobPtr);
1307
1308 *sub_node_slot = node;
1309 // Link component to parent via back-reference at node+0xF4
1311 // Fix animation data at node+0xAC if present
1312 ((struct PKG_ComponentOwnerBinding *)(*sub_node_slot)->component_or_owner)->component_data = component_data;
1313
1314 struct Pkg_ObjectNodeFixupView *relocated_sub_node = *sub_node_slot;
1315 void *animation_data_1 = relocated_sub_node->animation_data;
1316
1317 if (animation_data_1)
1318 {
1319 relocated_sub_node->animation_data = (char *)animation_data_1 + (uintptr_t)g_levelBlobPtr;
1320
1321 struct Animation_StateTable *animation_data = (*sub_node_slot)->animation_data;
1322
1323 animation_data->anim_ptrs[0] = (struct Animation_DataBlock *)((uintptr_t)animation_data->anim_ptrs[0] + g_levelBlobPtr);
1325 ((struct Animation_StateTable *)(*sub_node_slot)->animation_data)->anim_ptrs[0], g_levelBlobPtr);
1326 }
1327 }
1328
1329 sub_node_slot = &sub_node_slot[1];
1330 } while (--remaining_slots);
1331}
#define ANIMATION_SPLINE_NESTED_CHANNEL_ARRAY
Definition enums.h:49
#define ANIMATION_DATA_RELOCATION_VISITED
Definition enums.h:9
#define ANIMATION_SPLINE_RELOCATION_VISITED
Definition enums.h:52
uint8_t Animation_DataBlockFixupFlags
Definition enums.h:6
void Debug_Log(char const *category, char const *message)
Definition diagnostics.c:17
#define g_debugLoggingEnabled
Definition globals.h:9
void Pkg_FixUpResourceObjectNodeType1MeshNode(struct PKG_ObjectNodeFixupView *node)
Definition fixups.c:69
void Pkg_FixUpResourceSpriteEntry(struct PKG_SpriteMaterialLayerRaw *sprite_material_raw)
Definition fixups.c:336
void Pkg_FixUpResourceObjectNodeType0Hierarchy(struct PKG_ObjectNodeFixupView *node)
Definition fixups.c:608
void Pkg_FixUpResourceObjectNodeType7SpriteEntry(struct PKG_ObjectNodeFixupView *node)
Definition fixups.c:601
void Pkg_FixUpResourceActorRecordPointers(struct Pkg_ActorTemplate *actor_template)
Definition fixups.c:1250
void Pkg_FixUpResourceRenderNodeEntries(struct Mesh_RenderNodeEntry *entries, int32_t entry_count)
Definition fixups.c:318
void Pkg_FixUpResourceMaterialIndices(struct PKG_MaterialIndexList *index_list_raw)
Definition fixups.c:286
void Pkg_FixUpResourceObjectNodeType8MaterialPointer(struct PKG_ObjectNodeFixupView *node)
Definition fixups.c:591
void Pkg_FixUpResourceComponentNodes(struct Pkg_ComponentData *component_data)
Definition fixups.c:1295
void Pkg_FixUpResourcePolygonList(uint32_t *rel_node_list, BOOL list_entries_are_inline)
Definition fixups.c:732
void Pkg_FixUpResourceLevelPointers(struct Pkg_LevelHeader *level)
Definition fixups.c:847
void Pkg_FixUpResourceMaterialRefs(struct Pkg_MaterialRefFixupView *material_refs, int32_t ref_count)
Definition fixups.c:266
void Pkg_FixUpResourceObjectNodeDispatchByType(struct PKG_ObjectNodeFixupView *node)
Definition fixups.c:29
void Pkg_FixUpResourceObjectNodeType3MeshAndComponentNode(struct PKG_ObjectNodeFixupView *node)
Definition fixups.c:363
void Pkg_FixUpResourceAnimationData(struct Animation_DataBlock *animation_data, uint8_t *blob_base)
Definition fixups.c:179
#define g_levelBlobPtr
Definition globals.h:97
#define g_levelMaterialSection
Definition globals.h:94
int32_t Material_BuildStructure(struct Material_SectionHeader *section, struct Material_RefEntry *ref, struct Material_FrameSet *frame_set)
Definition resources.c:28
void Material_GetGlobalTextureRefs(struct Material_RefEntry *out_ref)
Definition textures.c:357
#define PKG_ACTOR_SHARED_COMPONENT_COUNT
Definition constants.h:91
@ PKG_MATERIAL_ENTRY_TABLE_REFERENCE
Definition constants.h:19
@ PKG_MATERIAL_ENTRY_EXTRA_PAYLOAD
Definition constants.h:18
#define PKG_SPRITE_LIST_END
Definition constants.h:24
#define PKG_NODE_AUXILIARY_LIST_COUNT
Definition constants.h:90
#define PKG_LEVEL_THEME_COUNT
Definition constants.h:92
#define PKG_NODE_HAS_MATERIAL_REFERENCES
Definition constants.h:22
#define PKG_RELOCATION_POINTER_SENTINEL
Definition constants.h:81
#define PKG_ANIMATION_CHANNEL_GROUP_COUNT
Definition constants.h:88
#define PKG_REFERENCE_ALIAS_TAG
Definition constants.h:79
@ PKG_MESH_WITH_EXTRA_POINTER
Definition constants.h:56
@ PKG_NODE_HIERARCHY
Definition constants.h:8
@ PKG_NODE_MATERIAL_POINTER
Definition constants.h:13
@ PKG_NODE_MESH
Definition constants.h:9
@ PKG_NODE_SPRITE
Definition constants.h:12
@ PKG_NODE_SIBLING_ONLY
Definition constants.h:10
@ PKG_NODE_MESH_COMPONENTS
Definition constants.h:11
#define PKG_MATERIAL_INDEX_SKIP_FIXUP
Definition constants.h:23
#define PKG_COMPONENT_SUBNODE_COUNT
Definition constants.h:94
@ PKG_TRAIL_DATA_SCENE_NODE
Definition constants.h:98
#define PKG_LEVEL_TRAIL_COUNT
Definition constants.h:93
#define PKG_REFERENCE_ALIAS_INDEX_SHIFT
Definition constants.h:80
#define PKG_ACTOR_LOD_COUNT
Definition constants.h:83
#define PKG_ACTOR_ANIMATION_SLOT_COUNT
Definition constants.h:82
#define PKG_POWERUP_TEMPLATE_COUNT
Definition constants.h:27
#define PKG_COMPONENT_RECORD_COUNT
Definition constants.h:89
#define Shared_FontDataCursor
Definition globals.h:111
#define g_sharedMaterialSection
Definition globals.h:108
#define pkg_resource_fix_up_actor_list_null
Definition globals.h:48
Animation_DataBlockFixupFlags fixup_flags
Definition types.h:761
struct Animation_SplineChannelVec3 * position_channels
Definition types.h:764
int8_t channel_counts[6]
Definition types.h:756
Animation_SplineChannelFlags channel_flags
Definition types.h:385
struct Animation_Vec3Keyframe * keyframes_or_minus_one_sentinel
Definition types.h:380
uint8_t * channel_data_or_minus_one_sentinel
Definition types.h:293
struct Animation_DataBlock * anim_ptrs[0x2b]
Definition types.h:422
Definition types.h:219
void * relocated_tail_ptr
Definition types.h:1101
struct Nav_Node * nodes
Definition types.h:35
int32_t node_count
Definition types.h:34
struct Nav_NeighborEntry * neighbor_list
Definition types.h:107
struct Pkg_ComponentData * component_data
Definition types.h:1377
uint32_t payload_offset_or_pointer
Definition types.h:1365
uint32_t payload_14_offset_or_pointer
Definition types.h:58
int16_t entry_count
Definition types.h:73
uint32_t entries_offset
Definition types.h:74
int32_t * linked_records
Definition types.h:951
uint8_t render_entry_count
Definition types.h:942
int32_t * relocation_list_100
Definition types.h:959
int32_t * relocation_list_b0
Definition types.h:940
struct Animation_StateTable * animation_state_table
Definition types.h:939
struct Pkg_ActorTemplate * owner_template
Definition types.h:960
uint8_t node_fixup_type
Definition types.h:918
struct PKG_ObjectNodeFixupView * first_child
Definition types.h:908
void * global_texture_refs
Definition types.h:957
int32_t * list_head_9c
Definition types.h:935
void * material_section_or_list
Definition types.h:926
void * material_indices_or_polygons
Definition types.h:927
int32_t * list_head_a4
Definition types.h:937
uint8_t secondary_entry_count
Definition types.h:943
struct PKG_ObjectNodeFixupView * next_sibling
Definition types.h:907
void * component_or_owner
Definition types.h:956
int16_t material_ref_count
Definition types.h:920
struct Mesh_RenderNodeEntry * render_entries
Definition types.h:944
struct PKG_OwnerPayloadFixupRecord payload_records[2]
Definition types.h:1402
uint32_t ptr_24
Definition types.h:85
struct PKG_OwnerPayloadFixupRecord payload_records[2]
Definition types.h:1414
uint8_t state_flags
Definition types.h:1008
struct Material_Entry * texture_db1
Definition types.h:984
uint32_t material_indices_rel
Definition types.h:109
struct Material_Entry * texture_db
Definition types.h:107
uint32_t material_index_or_pointer
Definition types.h:1352
void * shared_ref_50
Definition types.h:1070
void * actor_template_header_ref
Definition types.h:1064
void * script_base_ptr
Definition types.h:1063
void * component_alias_slots[4]
Definition types.h:1076
struct Math_Vec3I32 * bonus_respawn_target_pos
Definition types.h:1059
struct PKG_ObjectNodeFixupView * lod_node_array[3]
Definition types.h:163
struct Animation_StateTable * anim_table
Definition types.h:168
struct PKG_ObjectNodeFixupView * alternate_lod_node
Definition types.h:159
struct PKG_ObjectNodeFixupView * lod_nodes
Definition types.h:158
struct Mesh_Node * sub_nodes[0x4]
Definition types.h:242
uint32_t sprite_list_offset
Definition types.h:358
uint32_t trail_list_offset
Definition types.h:357
uint32_t powerup_actor_template_offsets[0x10]
Definition types.h:340
uint32_t powerup_list_offset
Definition types.h:339
uint32_t nav_net_offset
Definition types.h:359
uint32_t usable_materials_offset
Definition types.h:360
uint32_t var_list_offset
Definition types.h:336
uint32_t sound_definition_list_offset
Definition types.h:333
int16_t entity_count
Definition types.h:331
uint32_t cam_default_offset
Definition types.h:327
uint32_t theme_offsets[5]
Definition types.h:344
uint32_t entity_array_offset
Definition types.h:332
int16_t powerup_count
Definition types.h:337
uint32_t material_index_or_ptr
Definition types.h:408
uint32_t face_normal_offset_or_ptr
Definition types.h:410
struct Pkg_ObjectNodeFixupView * first_child
Definition types.h:563
int16_t material_ref_count
Definition types.h:567
void * material_indices_or_polygons
Definition types.h:573
uint8_t node_fixup_type
Definition types.h:565
void * material_section_or_list
Definition types.h:572
Definition types.h:37
void * data_ptr
Definition types.h:40
uint16_t data_type
Definition types.h:39
#define g_currentUseableMats
Definition values.h:750
#define g_specialNodeProcessingFlag
Definition values.h:477