diff --git a/src/game/bg.c b/src/game/bg.c index 3f211e57..0cc699d2 100644 --- a/src/game/bg.c +++ b/src/game/bg.c @@ -3358,6 +3358,38 @@ bool bgTestRayIntersectsBbox(coord3d *origin, coord3d *dir, s32 *bbox_min, s32 * } +#ifdef PORT +#include "image.h" + +/* The image id of a room triangle's texture, read like the N64 does: texLoad + * stores the id in the 8 bytes before the texture data, and the room's + * G_SETTIMG points at that data (a full host pointer in w1 on PC). Room GDLs + * load into the default pool, so anything outside it is not a texture. + * The id selects the impact decal, sound and dust puff (HIT_WATER: no decal, + * no puff, splash sound). */ +static s32 bgTexnumFromSetTimg(Gfx *settimg) +{ + struct texpool *pool = &ptr_texture_alloc_start; + u8 *data = (u8 *)settimg->words.w1; + s32 texnum; + + if (data < pool->start + 8 || data >= (u8 *)pool->end) + { + return -1; + } + + texnum = *(s16 *)(data - 8); + + if (texnum < 0 || texnum >= MAX_TEXTURES) + { + return -1; + } + + return texnum; +} +#endif + + bool bgTestRayIntersectionInRoom(coord3d *from, coord3d *to, coord3d *dir, RoomVtxBatchBounds *point, s32 roomnum, struct HitThing *hitthing) { Vertex *vtxbase; @@ -3555,6 +3587,11 @@ bool bgTestRayIntersectionInRoom(coord3d *from, coord3d *to, coord3d *dir, RoomV #ifdef PORT /* D154: KSEG0 texnum deref invalid for converted GDLs (cf. D135). D431 (#119): light fixtures are the one texture class the game acts on, so recover their image id from the fixture table. */ texnum = lightFixtureTexnumForGfx(gdl, roomnum); + + if (texnum < 0) + { + texnum = bgTexnumFromSetTimg(tcmd); + } #else temp.word = ((u32 *) tcmd)[1] - 8; texnum = *((u16 *) (temp.word | 0x80000000)); @@ -3737,6 +3774,11 @@ bool bgTestRayIntersectionInRoom(coord3d *from, coord3d *to, coord3d *dir, RoomV #ifdef PORT /* D154: KSEG0 texnum deref invalid for converted GDLs (cf. D135). D431 (#119): light fixtures are the one texture class the game acts on, so recover their image id from the fixture table. */ texnum = lightFixtureTexnumForGfx(gdl, roomnum); + + if (texnum < 0) + { + texnum = bgTexnumFromSetTimg(tcmd); + } #else temp.word = ((u32 *) tcmd)[1] - 8; texnum = *((u16 *) (temp.word | 0x80000000));