diff --git a/docs/progress.svg b/docs/progress.svg index 47aa152..3b4ea37 100644 --- a/docs/progress.svg +++ b/docs/progress.svg @@ -69,10 +69,10 @@ Tomb2.exe progress according to the physical function order: -45.07% (549) · 52.46% (639) · 0% (0) · 2.46% (30) +45.16% (550) · 52.38% (638) · 0% (0) · 2.46% (30) - - + + @@ -223,7 +223,7 @@ void __cdecl CutscenePlayerGen_Initialise(int16_t item_num); void __cdecl Camera_LoadCutsceneFrame(void); void __cdecl Collide_GetCollisionInfo(COLL_INFO *coll, int32_t xpos, int32_t ypos, int32_t zpos, int16_t room_num, int32_t obj_height); -int32_t __cdecl Room_FindGridShift(int32_t src, int32_t dst); +int32_t __cdecl Room_FindGridShift(int32_t src, int32_t dst); int32_t __cdecl Collide_CollideStaticObjects(COLL_INFO *coll, int32_t x, int32_t y, int32_t z, int16_t room_num, int32_t height); void __cdecl Room_GetNearbyRooms(int32_t x, int32_t y, int32_t z, int32_t r, int32_t h, int16_t room_num); void __cdecl Room_GetNewRoom(int32_t x, int32_t y, int32_t z, int16_t room_num); @@ -1298,10 +1298,10 @@ Tomb2.exe progress according to the function sizes: -42.15% · 57.52% · 0% · 0.33% +42.17% · 57.51% · 0% · 0.33% - - + + @@ -2292,7 +2292,7 @@ void __cdecl CleanupTextures(void); BOOL __cdecl OpenRegistryKey(LPCTSTR lpSubKey); void __cdecl Creature_Initialise(int16_t item_num); -int32_t __cdecl Room_FindGridShift(int32_t src, int32_t dst); +int32_t __cdecl Room_FindGridShift(int32_t src, int32_t dst); void __cdecl Inv_Ring_RotateLeft(RING_INFO *ring); void __cdecl Inv_Ring_RotateRight(RING_INFO *ring); void __cdecl Lara_State_SwanDive(ITEM_INFO *item, COLL_INFO *coll); diff --git a/docs/progress.txt b/docs/progress.txt index cfb7fd4..e61e5af 100644 --- a/docs/progress.txt +++ b/docs/progress.txt @@ -2738,7 +2738,7 @@ typedef struct { # game/collide.c 0x004128F0 0x067C + void __cdecl Collide_GetCollisionInfo(COLL_INFO *coll, int32_t xpos, int32_t ypos, int32_t zpos, int16_t room_num, int32_t obj_height); -0x00412FB0 0x002F - int32_t __cdecl Room_FindGridShift(int32_t src, int32_t dst); +0x00412FB0 0x002F + int32_t __cdecl Room_FindGridShift(int32_t src, int32_t dst); 0x00412FE0 0x03D2 - int32_t __cdecl Collide_CollideStaticObjects(COLL_INFO *coll, int32_t x, int32_t y, int32_t z, int16_t room_num, int32_t height); 0x004133D0 0x00C8 - void __cdecl Room_GetNearbyRooms(int32_t x, int32_t y, int32_t z, int32_t r, int32_t h, int16_t room_num); 0x004134A0 0x0055 - void __cdecl Room_GetNewRoom(int32_t x, int32_t y, int32_t z, int16_t room_num); diff --git a/src/game/room.c b/src/game/room.c index 566e21a..62d71f9 100644 --- a/src/game/room.c +++ b/src/game/room.c @@ -19,3 +19,19 @@ int16_t Room_GetIndexFromPos(const int32_t x, const int32_t y, const int32_t z) } return NO_ROOM; } + +int32_t __cdecl Room_FindGridShift(int32_t src, const int32_t dst) +{ + const int32_t src_w = src >> WALL_SHIFT; + const int32_t dst_w = dst >> WALL_SHIFT; + if (src_w == dst_w) { + return 0; + } + + src &= WALL_L - 1; + if (dst_w > src_w) { + return WALL_L - (src - 1); + } else { + return -(src + 1); + } +} diff --git a/src/game/room.h b/src/game/room.h index 35d163b..22b458c 100644 --- a/src/game/room.h +++ b/src/game/room.h @@ -3,3 +3,4 @@ #include int16_t Room_GetIndexFromPos(int32_t x, int32_t y, int32_t z); +int32_t __cdecl Room_FindGridShift(int32_t src, int32_t dst); diff --git a/src/global/funcs.h b/src/global/funcs.h index 1fe1f0a..2c8c772 100644 --- a/src/global/funcs.h +++ b/src/global/funcs.h @@ -6,7 +6,6 @@ // clang-format off #define Output_InsertInventoryBackground ((void __cdecl (*)(const int16_t *obj_ptr))0x00401D50) -#define Room_FindGridShift ((int32_t __cdecl (*)(int32_t src, int32_t dst))0x00412FB0) #define Collide_CollideStaticObjects ((int32_t __cdecl (*)(COLL_INFO *coll, int32_t x, int32_t y, int32_t z, int16_t room_num, int32_t height))0x00412FE0) #define Room_GetNearbyRooms ((void __cdecl (*)(int32_t x, int32_t y, int32_t z, int32_t r, int32_t h, int16_t room_num))0x004133D0) #define Room_GetNewRoom ((void __cdecl (*)(int32_t x, int32_t y, int32_t z, int16_t room_num))0x004134A0) diff --git a/src/inject_exec.c b/src/inject_exec.c index 2ed3b5c..be3a617 100644 --- a/src/inject_exec.c +++ b/src/inject_exec.c @@ -26,6 +26,7 @@ #include "game/output.h" #include "game/overlay.h" #include "game/random.h" +#include "game/room.h" #include "game/shell.h" #include "game/sound.h" #include "game/text.h" @@ -39,6 +40,7 @@ static void Inject_HWR(bool enable); static void Inject_Camera(bool enable); static void Inject_Collide(bool enable); +static void Inject_Room(bool enable); static void Inject_Math(bool enable); static void Inject_Matrix(bool enable); static void Inject_Shell(bool enable); @@ -228,6 +230,11 @@ static void Inject_Collide(const bool enable) INJECT(enable, 0x004128F0, Collide_GetCollisionInfo); } +static void Inject_Room(const bool enable) +{ + INJECT(enable, 0x00412FB0, Room_FindGridShift); +} + static void Inject_Matrix(const bool enable) { INJECT(enable, 0x00401000, Matrix_GenerateW2V); @@ -732,6 +739,7 @@ void Inject_Exec(void) Inject_Camera(true); Inject_Collide(true); + Inject_Room(true); Inject_Math(true); Inject_Matrix(true); Inject_Shell(true);