Skip to content

Commit

Permalink
Decompiled MoveLaraPosition()
Browse files Browse the repository at this point in the history
  • Loading branch information
TokyoSU committed Mar 15, 2022
1 parent 2251d44 commit 0ab69dd
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
47 changes: 42 additions & 5 deletions game/collide.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ BOOL __cdecl TestLaraPosition(__int16* bounds, ITEM_INFO* item, ITEM_INFO* larai
&& zBound <= bounds[5];
}

void __cdecl AlignLaraPosition(PHD_VECTOR* vec, ITEM_INFO* item, ITEM_INFO* laraitem) {
void __cdecl AlignLaraPosition(PHD_VECTOR* pos, ITEM_INFO* item, ITEM_INFO* laraitem) {
FLOOR_INFO* floor;
int x, y, z;
int height, ceiling;
Expand All @@ -537,9 +537,9 @@ void __cdecl AlignLaraPosition(PHD_VECTOR* vec, ITEM_INFO* item, ITEM_INFO* lara

phd_PushUnitMatrix();
phd_RotYXZ(item->pos.rotY, item->pos.rotX, item->pos.rotZ);
x = item->pos.x + ((vec->x * PhdMatrixPtr->_00 + vec->y * PhdMatrixPtr->_01 + vec->z * PhdMatrixPtr->_02) >> W2V_SHIFT);
y = item->pos.y + ((vec->x * PhdMatrixPtr->_10 + vec->y * PhdMatrixPtr->_11 + vec->z * PhdMatrixPtr->_12) >> W2V_SHIFT);
z = item->pos.z + ((vec->x * PhdMatrixPtr->_20 + vec->y * PhdMatrixPtr->_21 + vec->z * PhdMatrixPtr->_22) >> W2V_SHIFT);
x = item->pos.x + ((pos->x * PhdMatrixPtr->_00 + pos->y * PhdMatrixPtr->_01 + pos->z * PhdMatrixPtr->_02) >> W2V_SHIFT);
y = item->pos.y + ((pos->x * PhdMatrixPtr->_10 + pos->y * PhdMatrixPtr->_11 + pos->z * PhdMatrixPtr->_12) >> W2V_SHIFT);
z = item->pos.z + ((pos->x * PhdMatrixPtr->_20 + pos->y * PhdMatrixPtr->_21 + pos->z * PhdMatrixPtr->_22) >> W2V_SHIFT);
phd_PopMatrix();

roomID = laraitem->roomNumber;
Expand All @@ -554,6 +554,43 @@ void __cdecl AlignLaraPosition(PHD_VECTOR* vec, ITEM_INFO* item, ITEM_INFO* lara
}
}

BOOL __cdecl MoveLaraPosition(PHD_VECTOR* pos, ITEM_INFO* item, ITEM_INFO* laraitem) {
PHD_3DPOS newpos;
FLOOR_INFO* floor;
int height, distance;
int xDist, yDist, zDist;
__int16 roomID;

newpos.rotX = item->pos.rotX;
newpos.rotY = item->pos.rotY;
newpos.rotZ = item->pos.rotZ;

phd_PushUnitMatrix();
phd_RotYXZ(item->pos.rotY, item->pos.rotX, item->pos.rotZ);
newpos.x = item->pos.x + ((pos->x * PhdMatrixPtr->_00 + pos->y * PhdMatrixPtr->_01 + pos->z * PhdMatrixPtr->_02) >> W2V_SHIFT);
newpos.y = item->pos.y + ((pos->x * PhdMatrixPtr->_10 + pos->y * PhdMatrixPtr->_11 + pos->z * PhdMatrixPtr->_12) >> W2V_SHIFT);
newpos.z = item->pos.z + ((pos->x * PhdMatrixPtr->_20 + pos->y * PhdMatrixPtr->_21 + pos->z * PhdMatrixPtr->_22) >> W2V_SHIFT);
phd_PopMatrix();

if (item->objectID != ID_FLARE_ITEM) {
return Move3DPosTo3DPos(&laraitem->pos, &newpos, 16, 2 * PHD_DEGREE);
}

roomID = laraitem->roomNumber;
floor = GetFloor(newpos.x, newpos.y, newpos.z, &roomID);
height = GetHeight(floor, newpos.x, newpos.y, newpos.z);

if (ABS(height - laraitem->pos.y) > 512) {
return FALSE;
}

zDist = SQR(newpos.z - laraitem->pos.z);
yDist = SQR(newpos.y - laraitem->pos.y);
xDist = SQR(newpos.x - laraitem->pos.z);
distance = phd_sqrt(xDist + yDist + zDist);
return distance < 128 || Move3DPosTo3DPos(&laraitem->pos, &newpos, 16, 2 * PHD_DEGREE);
}

/*
* Inject function
*/
Expand All @@ -578,6 +615,6 @@ void Inject_Collide() {
INJECT(0x00413D20, TestBoundsCollide);
INJECT(0x00413DF0, TestLaraPosition);
INJECT(0x00413F30, AlignLaraPosition);
// INJECT(0x00414070, MoveLaraPosition);
INJECT(0x00414070, MoveLaraPosition);
// INJECT(0x00414200, Move3DPosTo3DPos);
}
4 changes: 2 additions & 2 deletions game/collide.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ void __cdecl TrapCollision(__int16 itemID, ITEM_INFO* laraitem, COLL_INFO* coll)
void __cdecl ItemPushLara(ITEM_INFO* item, ITEM_INFO* laraitem, COLL_INFO* coll, BOOL spazon, BOOL bigpush); // 0x00413A10
BOOL __cdecl TestBoundsCollide(ITEM_INFO* item, ITEM_INFO* laraitem, int radius); // 0x00413D20
BOOL __cdecl TestLaraPosition(__int16* bounds, ITEM_INFO* item, ITEM_INFO* laraitem); // 0x00413DF0
void __cdecl AlignLaraPosition(PHD_VECTOR* vec, ITEM_INFO* item, ITEM_INFO* laraitem); // 0x00413F30
#define MoveLaraPosition ((BOOL(__cdecl*)(PHD_VECTOR*, ITEM_INFO*, ITEM_INFO*)) 0x00414070)
void __cdecl AlignLaraPosition(PHD_VECTOR* pos, ITEM_INFO* item, ITEM_INFO* laraitem); // 0x00413F30
BOOL __cdecl MoveLaraPosition(PHD_VECTOR* pos, ITEM_INFO* item, ITEM_INFO* laraitem); // 0x00414070
#define Move3DPosTo3DPos ((BOOL(__cdecl*)(PHD_3DPOS*, PHD_3DPOS*, int, __int16)) 0x00414200)

#endif // COLLIDE_H_INCLUDED

0 comments on commit 0ab69dd

Please sign in to comment.