Skip to content

Commit 96d7e03

Browse files
committed
Merge 'Fix ice trap chests lacking smoke by object loading' (#2568)
# Conflicts: # ASM/build/asm_symbols.txt # ASM/build/bundle.o # ASM/build/c_symbols.txt # ASM/ootSymbols.ld # ASM/src/build.asm # ASM/src/hacks.asm # data/generated/patch_symbols.json # data/generated/rom_patch.txt # data/generated/symbols.json
2 parents cc2df94 + c773aa3 commit 96d7e03

23 files changed

Lines changed: 44130 additions & 43730 deletions

ASM/build/asm_symbols.txt

Lines changed: 786 additions & 777 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ASM/build/bundle.o

1.2 KB
Binary file not shown.

ASM/build/c_symbols.txt

Lines changed: 684 additions & 676 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ASM/c/chests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typedef void (*EnBoxActionFunc)(struct EnBox*, z64_game_t*);
1717
typedef struct EnBox
1818
{
1919
/* 0x0000 */ DynaPolyActor dyna;
20-
/* 0x0154 */ uint8_t skelanime[0x44];
20+
/* 0x0154 */ SkelAnime skelAnime;
2121
/* 0x0198 */ int32_t unk_198; // related to animation delays for types 3 and 8
2222
/* 0x019C */ int32_t sub_cam_id;
2323
/* 0x01A0 */ float unk_1A0; // 0-1, rotation-related, apparently unused (in z_en_box.c at least)

ASM/c/debug.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ void draw_debug_menu(z64_disp_buf_t* db) {
680680
}
681681
if (current_menu_indexes.sub_menu_index == 2) {
682682
uint8_t nbActors = 0;
683-
z64_actor_t* actor = z64_game.actor_list[current_menu_indexes.actor_index].first;
683+
z64_actor_t* actor = z64_game.actorLists[current_menu_indexes.actor_index].head;
684684
while (actor != NULL) {
685685
nbActors++;
686686
actor = actor->next;
@@ -993,7 +993,7 @@ void draw_debug_menu(z64_disp_buf_t* db) {
993993
}
994994
else {
995995
uint8_t nbActors = 0;
996-
z64_actor_t* actor = z64_game.actor_list[current_menu_indexes.actor_index].first;
996+
z64_actor_t* actor = z64_game.actorLists[current_menu_indexes.actor_index].head;
997997
uint8_t currentActorPage = current_menu_indexes.specific_actor_index / 10;
998998
// Display actor list in 10 by 10 pages.
999999
while (actor != NULL) {

ASM/c/en_box.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "z64.h"
2+
#include "chests.h"
3+
#include "object.h"
4+
#include "get_items.h"
5+
#include "debug.h"
6+
7+
// Macro for original get item id + if opened or not
8+
#define ENBOX_GET_GET_ITEM_ID(thisx) ((thisx).variable >> 5) & ((1 << 7) - 1)
9+
#define ENBOX_GET_TREASURE_FLAG(thisx) ((thisx).variable >> 0) & ((1 << 5) - 1)
10+
11+
#define OBJECT_FZ 0x114
12+
13+
// Get this chest's new randomized GI id
14+
int16_t EnBox_GetNewGetItemId(EnBox* this, z64_game_t* play) {
15+
int16_t oldId = ENBOX_GET_GET_ITEM_ID(this->dyna.actor);
16+
override_t override = lookup_override(&this->dyna.actor, z64_game.scene_index, ABS(oldId));
17+
18+
return override.value.base.item_id;
19+
}
20+
21+
// Load the necessary extra object if new GI id is a trap
22+
void EnBox_LoadObject(EnBox* this, z64_game_t* play) {
23+
int16_t giId = EnBox_GetNewGetItemId(this, play);
24+
bool opened = Flags_GetTreasure(play, ENBOX_GET_TREASURE_FLAG(this->dyna.actor));
25+
26+
if(!opened) {
27+
if (giId == GI_ICE_TRAP) {
28+
Object_LoadExtra(play, OBJECT_FZ, 0); // Freezard object
29+
}
30+
}
31+
}

ASM/c/item_effects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ void open_gate_and_mask_shop(z64_file_t* save, int16_t arg1, int16_t arg2) {
234234
// Check if we're in kak and actually open the gate
235235
if (z64_game.scene_index == 82) {
236236
// Loop through the actors looking for the gate
237-
z64_actor_t* curr = z64_game.actor_list[7].first;
237+
z64_actor_t* curr = z64_game.actorLists[7].head;
238238
while (curr != NULL) {
239239
if (curr->actor_id == 0x100) { // Check for BG_GATE_SHUTTER
240240
// Set the openingState so it starts to open

ASM/c/misc_colors.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void update_bombchu_trail_colors()
9898
colorRGB8_t rainbow_color_outer_start = get_rainbow_color(frames, BOMBCHU_CYCLE_FRAMES_OUTER);
9999
colorRGB8_t rainbow_color_outer_end = get_rainbow_color(frames + 2 * BOMBCHU_CYCLE_FRAMES_OUTER, BOMBCHU_CYCLE_FRAMES_OUTER);
100100

101-
z64_actor_t* explosive = z64_game.actor_list[ACTORTYPE_EXPLOSIVES].first;
101+
z64_actor_t* explosive = z64_game.actorLists[ACTORTYPE_EXPLOSIVES].head;
102102
while (explosive != NULL)
103103
{
104104
if (explosive->main_proc != NULL && explosive->actor_id == 0xDA) // En_Bom_Chu

ASM/c/object.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include "z64.h"
2+
#include "object.h"
3+
4+
// Function that adds an object to an object slot and sets up data for the object
5+
// to be loaded by Object_UpdateEntries() (which is run every frame).
6+
extern void* func_800982FC(z64_obj_ctxt_t* objectCtx, int32_t slot, int16_t objectId);
7+
extern int32_t DmaMgr_RequestSync(void* ram, uintptr_t vrom, size_t size);
8+
9+
/**
10+
* Loads an extra object that no previously loaded actor has a dependency on.
11+
* Will get deloaded upon room/scene change, as it is not part of the room object list.
12+
* @param syncDma true if the object should be synchronously DMA transferred this frame.
13+
* Otherwise, it is loaded asynchronously on next frame by Object_UpdateEntries.
14+
* @return: Slot number (if already loaded, or loaded into a new slot), else -1
15+
* NOTE:
16+
* - Crash risk if trying to sync DMA during En_Holl room transition, if an actor
17+
* in the previous room depends on object data that will be overwritten by the DMA
18+
* before the actor is properly deleted (see: GTG Lava room to Chest maze with SoT block).
19+
* Async DMA is OK because of the extra frame delay.
20+
* - Objects are otherwise not unloaded/loaded on demand, so extra loading is OK.
21+
* - If crashing, if async DMA ensure that the object is loaded before the actor
22+
* is trying to draw (try sync DMA). Ensure that there is actually object slot and space
23+
* available for new object before drawing or doing anything else that requires object.
24+
*
25+
*/
26+
int16_t Object_LoadExtra(z64_game_t* play, int16_t objectId, uint8_t syncDma) {
27+
uint8_t i;
28+
int16_t slot = -1;
29+
30+
// Check if object is already loaded, and for first available slot
31+
for (i = 0; i < ARRAY_COUNT(play->obj_ctxt.objects); i++) {
32+
33+
// Already loaded (abs is needed - negative id if object not yet DMA:ed)
34+
if (ABS((play->obj_ctxt.objects[i].id)) == objectId) {
35+
return i;
36+
37+
} else if (slot == -1 && play->obj_ctxt.objects[i].id == 0) {
38+
slot = i;
39+
break;
40+
}
41+
}
42+
43+
if (slot != -1) {
44+
// Take the found slot
45+
z64_mem_obj_t* newEntry = &play->obj_ctxt.objects[slot]; // The new object
46+
z64_mem_obj_t* lastEntry = &play->obj_ctxt.objects[play->obj_ctxt.n_objects-1]; // Previous last added object
47+
RomFile* lastObjectFile = &gObjectTable[ABS(lastEntry->id)]; // Get previous object start pointer and size
48+
uint32_t lastSize = lastObjectFile->vromEnd - lastObjectFile->vromStart;
49+
newEntry->data = (void*)ALIGN16((uintptr_t)lastEntry->data + lastSize); // Gives pointer to start for the new object data
50+
51+
// Set up data for adding the object to the slot on next update or now
52+
if (func_800982FC(&play->obj_ctxt, slot, objectId) != NULL) {
53+
play->obj_ctxt.n_objects++;
54+
55+
if (syncDma) {
56+
play->obj_ctxt.objects[slot].id = objectId; // Uninvert the id because it will get loaded now
57+
RomFile* objectFile = &gObjectTable[objectId]; // Get object start pointer and size
58+
uint32_t size = objectFile->vromEnd - objectFile->vromStart;
59+
DmaMgr_RequestSync(newEntry->data, objectFile->vromStart, size);
60+
}
61+
62+
} else { // Loading new object would exceed object space
63+
#ifdef DEBUG_MODE
64+
char msg[256];
65+
sprintf(msg, "Obj %d slot %d", objectId, slot);
66+
Fault_AddHungupAndCrashImpl("Object_LoadExtra: No memory", msg);
67+
#endif
68+
69+
return -1; // Don't crash non-debug mode for now but this should not happen!
70+
}
71+
}
72+
73+
return slot;
74+
}

ASM/c/object.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef OBJECT_H
2+
#define OBJECT_H
3+
4+
#define ALIGN16(x) (((x) + 0xF) & ~0xF)
5+
#define ARRAY_COUNT(arr) (int32_t)(sizeof(arr) / sizeof(arr[0]))
6+
7+
typedef struct RomFile {
8+
/* 0x00 */ uintptr_t vromStart;
9+
/* 0x04 */ uintptr_t vromEnd;
10+
} RomFile; // size = 0x8
11+
12+
extern RomFile gObjectTable[];
13+
14+
int16_t Object_LoadExtra(z64_game_t* play, int16_t objectId, uint8_t syncDma);
15+
16+
#endif

0 commit comments

Comments
 (0)