From 18a3322f9768272ea3e8520cecebee1969bc275d Mon Sep 17 00:00:00 2001 From: rr- Date: Wed, 24 Feb 2021 18:11:51 +0100 Subject: [PATCH] port GetNearByRooms and GetNewRoom --- docs/progress.svg | 12 ++++++------ docs/progress.txt | 4 ++-- src/game/collide.c | 37 +++++++++++++++++++++++++++++++++++++ src/game/collide.h | 3 +++ src/game/const.h | 1 + src/game/vars.h | 2 +- 6 files changed, 50 insertions(+), 9 deletions(-) diff --git a/docs/progress.svg b/docs/progress.svg index d2b3e822a..091810b05 100644 --- a/docs/progress.svg +++ b/docs/progress.svg @@ -137,7 +137,7 @@ - + @@ -821,7 +821,7 @@ - + @@ -1459,10 +1459,10 @@ -Functions decompiled (count): 29.63% -Functions decompiled (bytesize): 29.17% -Functions not decompiled, but with known names (count): 56.38% -Functions not decompiled, but with known names (bytesize): 54.86% +Functions decompiled (count): 29.77% +Functions decompiled (bytesize): 29.46% +Functions not decompiled, but with known names (count): 56.24% +Functions not decompiled, but with known names (bytesize): 54.57% Functions not decompiled, with unknown names (count): 13.99% Functions not decompiled, with unknown names (bytesize): 15.97% diff --git a/docs/progress.txt b/docs/progress.txt index acf7b504a..e8131154d 100644 --- a/docs/progress.txt +++ b/docs/progress.txt @@ -172,8 +172,8 @@ InGameCinematicCamera 0x004115F0 0x00000190 * GetCollisionInfo 0x00411780 0x000007DD + FindGridShift ---------- ---------- + CollideStaticObjects 0x00411FA0 0x000003D6 * -GetNearByRooms 0x00412390 0x000002CC - -GetNewRoom ---------- ---------- - +GetNearByRooms 0x00412390 0x000002CC + +GetNewRoom ---------- ---------- + ShiftItem 0x00412660 0x00000037 * UpdateLaraRoom 0x004126A0 0x0000005F * GetTiltType ---------- ---------- + diff --git a/src/game/collide.c b/src/game/collide.c index 5f75434ae..8a913adc8 100644 --- a/src/game/collide.c +++ b/src/game/collide.c @@ -283,6 +283,42 @@ int32_t FindGridShift(int32_t src, int32_t dst) } } +void GetNearByRooms( + int32_t x, int32_t y, int32_t z, int32_t r, int32_t h, int16_t room_num) +{ + RoomsToDraw[0] = room_num; + RoomsToDrawNum = 1; + GetNewRoom(x + r, y, z + r, room_num); + GetNewRoom(x - r, y, z + r, room_num); + GetNewRoom(x + r, y, z - r, room_num); + GetNewRoom(x - r, y, z - r, room_num); + GetNewRoom(x + r, y - h, z + r, room_num); + GetNewRoom(x - r, y - h, z + r, room_num); + GetNewRoom(x + r, y - h, z - r, room_num); + GetNewRoom(x - r, y - h, z - r, room_num); +} + +void GetNewRoom(int32_t x, int32_t y, int32_t z, int16_t room_num) +{ + GetFloor(x, y, z, &room_num); + + int i; + for (i = 0; i < RoomsToDrawNum; i++) { + if (RoomsToDraw[i] == room_num) { + break; + } + } + + // NOTE: this access violation check was not present in the original code + if (i >= MAX_ROOMS_TO_DRAW) { + return; + } + + if (i == RoomsToDrawNum) { + RoomsToDraw[RoomsToDrawNum++] = room_num; + } +} + int16_t GetTiltType(FLOOR_INFO* floor, int32_t x, int32_t y, int32_t z) { ROOM_INFO* r; @@ -311,4 +347,5 @@ int16_t GetTiltType(FLOOR_INFO* floor, int32_t x, int32_t y, int32_t z) void T1MInjectGameCollide() { INJECT(0x00411780, GetCollisionInfo); + INJECT(0x00412390, GetNearByRooms); } diff --git a/src/game/collide.h b/src/game/collide.h index ff2ea753b..3afbdeb79 100644 --- a/src/game/collide.h +++ b/src/game/collide.h @@ -17,6 +17,9 @@ void GetCollisionInfo( COLL_INFO* coll, int32_t xpos, int32_t ypos, int32_t zpos, int16_t room_num, int32_t objheight); int32_t FindGridShift(int32_t src, int32_t dst); +void GetNearByRooms( + int32_t x, int32_t y, int32_t z, int32_t r, int32_t h, int16_t room_num); +void GetNewRoom(int32_t x, int32_t y, int32_t z, int16_t room_num); int16_t GetTiltType(FLOOR_INFO* floor, int32_t x, int32_t y, int32_t z); void T1MInjectGameCollide(); diff --git a/src/game/const.h b/src/game/const.h index a1aa68dc4..08890e492 100644 --- a/src/game/const.h +++ b/src/game/const.h @@ -6,6 +6,7 @@ #define NUM_PU 3 #define NUM_SLOTS 8 #define MAX_ROOMS 1024 +#define MAX_ROOMS_TO_DRAW 100 #define MAX_FRAMES 10 #define MAX_TEXTURES 2048 #define NUMBER_ITEMS 256 diff --git a/src/game/vars.h b/src/game/vars.h index 0baa1c34b..e7f70237f 100644 --- a/src/game/vars.h +++ b/src/game/vars.h @@ -138,7 +138,7 @@ extern char TextStrings[MAX_TEXT_STRINGS][MAX_STRING_SIZE]; #define InterpolatedBounds ARRAY_(0x00462BF0, int16_t, [6]) #define W2VMatrix VAR_U_(0x006CADA0, PHD_MATRIX) #define DoorVBuf ARRAY_(0x00462540, DOOR_VBUF, [4]) -#define RoomsToDraw ARRAY_(0x00462580, int16_t, [100]) +#define RoomsToDraw ARRAY_(0x00462580, int16_t, [MAX_ROOMS_TO_DRAW]) #define RoomsToDrawNum VAR_U_(0x00461F38, int32_t) #define Weapons ARRAY_(0x004563A8, WEAPON_INFO, [NUM_WEAPONS]) #define DemoLevels ARRAY_(0x00453538, int8_t, [])