From 08766e37a295afc0746afeaa4030b7fdeea50e0c Mon Sep 17 00:00:00 2001 From: rr- Date: Wed, 24 Feb 2021 21:00:34 +0100 Subject: [PATCH] port TestLaraPosition --- docs/progress.svg | 12 ++++++------ docs/progress.txt | 2 +- src/game/collide.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/game/collide.h | 2 ++ 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/docs/progress.svg b/docs/progress.svg index 1e126714a..278f82956 100644 --- a/docs/progress.svg +++ b/docs/progress.svg @@ -147,7 +147,7 @@ - + @@ -973,7 +973,7 @@ - + @@ -1459,10 +1459,10 @@ -Functions decompiled (count): 31.14% -Functions decompiled (bytesize): 30.72% -Functions not decompiled, but with known names (count): 54.87% -Functions not decompiled, but with known names (bytesize): 53.31% +Functions decompiled (count): 31.28% +Functions decompiled (bytesize): 30.84% +Functions not decompiled, but with known names (count): 54.73% +Functions not decompiled, but with known names (bytesize): 53.19% 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 e46d64b68..c49464e7a 100644 --- a/docs/progress.txt +++ b/docs/progress.txt @@ -185,7 +185,7 @@ DoorCollision 0x004129F0 0x0000007B + TrapCollision 0x00412A70 0x00000096 + ItemPushLara 0x00412B10 0x00000335 + TestBoundsCollide 0x00412E50 0x000000D1 + -TestLaraPosition 0x00412F30 0x00000137 - +TestLaraPosition 0x00412F30 0x00000137 + AlignLaraPosition 0x00413070 0x000000C1 - MoveLaraPosition 0x00413140 0x000000E4 - Move3DPosTo3DPos 0x00413230 0x00000172 - diff --git a/src/game/collide.c b/src/game/collide.c index 2d1af9a38..7fa600d38 100644 --- a/src/game/collide.c +++ b/src/game/collide.c @@ -1,3 +1,4 @@ +#include "3dsystem/3d_gen.h" #include "3dsystem/phd_math.h" #include "game/collide.h" #include "game/const.h" @@ -793,6 +794,44 @@ int32_t TestBoundsCollide(ITEM_INFO* item, ITEM_INFO* lara_item, int32_t radius) return 0; } +int32_t TestLaraPosition(int16_t* bounds, ITEM_INFO* item, ITEM_INFO* lara_item) +{ + PHD_ANGLE xrotrel = lara_item->pos.x_rot - item->pos.x_rot; + PHD_ANGLE yrotrel = lara_item->pos.y_rot - item->pos.y_rot; + PHD_ANGLE zrotrel = lara_item->pos.z_rot - item->pos.z_rot; + if (xrotrel < bounds[6] || xrotrel > bounds[7]) { + return 0; + } + if (yrotrel < bounds[8] || yrotrel > bounds[9]) { + return 0; + } + if (zrotrel < bounds[10] || zrotrel > bounds[11]) { + return 0; + } + + int32_t x = lara_item->pos.x - item->pos.x; + int32_t y = lara_item->pos.y - item->pos.y; + int32_t z = lara_item->pos.z - item->pos.z; + phd_PushUnitMatrix(); + phd_RotYXZ(item->pos.y_rot, item->pos.x_rot, item->pos.z_rot); + PHD_MATRIX* mptr = PhdMatrixPtr; + int32_t rx = (mptr->_00 * x + mptr->_10 * y + mptr->_20 * z) >> W2V_SHIFT; + int32_t ry = (mptr->_01 * x + mptr->_11 * y + mptr->_21 * z) >> W2V_SHIFT; + int32_t rz = (mptr->_02 * x + mptr->_12 * y + mptr->_22 * z) >> W2V_SHIFT; + phd_PopMatrix(); + if (rx < bounds[0] || rx > bounds[1]) { + return 0; + } + if (ry < bounds[2] || ry > bounds[3]) { + return 0; + } + if (rz < bounds[4] || rz > bounds[5]) { + return 0; + } + + return 1; +} + void T1MInjectGameCollide() { INJECT(0x00411780, GetCollisionInfo); @@ -807,4 +846,5 @@ void T1MInjectGameCollide() INJECT(0x00412A70, TrapCollision); INJECT(0x00412B10, ItemPushLara); INJECT(0x00412E50, TestBoundsCollide); + INJECT(0x00412F30, TestLaraPosition); } diff --git a/src/game/collide.h b/src/game/collide.h index 3d0091662..7abf5bb04 100644 --- a/src/game/collide.h +++ b/src/game/collide.h @@ -28,6 +28,8 @@ void ItemPushLara( int32_t bigpush); int32_t TestBoundsCollide(ITEM_INFO* item, ITEM_INFO* lara_item, int32_t radius); +int32_t +TestLaraPosition(int16_t* bounds, ITEM_INFO* item, ITEM_INFO* lara_item); void T1MInjectGameCollide();