diff --git a/TR5Main/Game/draw.cpp b/TR5Main/Game/draw.cpp index 0437788c7..25eef26c1 100644 --- a/TR5Main/Game/draw.cpp +++ b/TR5Main/Game/draw.cpp @@ -289,6 +289,7 @@ void _phd_DxRotYXZpack(int rangle) void phd_PopMatrix(void) { MatrixPtr -= 12; + DxMatrixPtr -= 48; } void _phd_PopMatrix_I(void) diff --git a/TR5Main/Game/sphere.cpp b/TR5Main/Game/sphere.cpp index cf45c07de..c0d80f4cc 100644 --- a/TR5Main/Game/sphere.cpp +++ b/TR5Main/Game/sphere.cpp @@ -1 +1,103 @@ -#include "sphere.h" \ No newline at end of file +#include "sphere.h" +#include "..\Global\global.h" +#include "draw.h" + +int GetSpheres(ITEM_INFO* item, SPHERE* ptr, char worldSpace) +{ + int x, y, z; + + if (!item) + return 0; + + if (worldSpace & 1) + { + x = item->pos.xPos; + y = item->pos.yPos; + z = item->pos.zPos; + + phd_PushUnitMatrix(); + + MatrixPtr[M03] = 0; + MatrixPtr[M13] = 0; + MatrixPtr[M23] = 0; + } + else + { + z = 0; + y = 0; + x = 0; + + phd_PushMatrix(); + phd_TranslateAbs(item->pos.xPos, item->pos.yPos, item->pos.zPos); + } + + phd_RotYXZ(item->pos.yRot, item->pos.xRot, item->pos.zRot); + + short *frame = GetBestFrame(item); + phd_TranslateRel(frame[6], frame[7], frame[8]); + short* rotation = &frame[9]; + gar_RotYXZsuperpack(&rotation, 0); + + OBJECT_INFO* obj = &Objects[item->objectNumber]; + short** meshPtr = &Meshes[obj->meshIndex]; + int* bone = &Bones[obj->boneIndex]; + + phd_PushMatrix(); + + short* objPtr = *(meshPtr++); // Get Sphere stuff Now... + + if (!(worldSpace & 2)) + phd_TranslateRel(objPtr[0], objPtr[1], objPtr[2]); + + ptr->x = x + (MatrixPtr[M03] >> W2V_SHIFT); + ptr->y = y + (MatrixPtr[M13] >> W2V_SHIFT); + ptr->z = z + (MatrixPtr[M23] >> W2V_SHIFT); + ptr->r = (int)objPtr[3]; + + phd_PopMatrix(); + + short* extraRotation = (short*)item->data; + + for (int i = obj->nmeshes - 1; i > 0; i--, bone += 3) + { + int poppush = *(bone++); + if (poppush & 1) + phd_PopMatrix(); + if (poppush & 2) + phd_PushMatrix(); + + phd_TranslateRel(*(bone), *(bone + 1), *(bone + 2)); + gar_RotYXZsuperpack(&rotation, 0); + + if ((poppush & (ROT_X | ROT_Y | ROT_Z)) && extraRotation) + { + if (poppush & ROT_Y) + phd_RotY(*(extraRotation++)); + if (poppush & ROT_X) + phd_RotX(*(extraRotation++)); + if (poppush & ROT_Z) + phd_RotZ(*(extraRotation++)); + } + + objPtr = *(meshPtr++); + + phd_PushMatrix(); + if (!(worldSpace & 2)) + phd_TranslateRel(objPtr[0], objPtr[1], objPtr[2]); + + ptr->x = x + (MatrixPtr[M03] >> W2V_SHIFT); + ptr->y = y + (MatrixPtr[M13] >> W2V_SHIFT); + ptr->z = z + (MatrixPtr[M23] >> W2V_SHIFT); + ptr->r = (int)objPtr[3]; + ptr++; + phd_PopMatrix(); + } + + phd_PopMatrix(); + return obj->nmeshes; +} + +void Inject_Sphere() +{ + INJECT(0x00479380, GetSpheres); +} \ No newline at end of file diff --git a/TR5Main/Game/sphere.h b/TR5Main/Game/sphere.h index 6a2e33c0d..dfe6c40c2 100644 --- a/TR5Main/Game/sphere.h +++ b/TR5Main/Game/sphere.h @@ -4,4 +4,8 @@ #define TestCollision ((int (__cdecl*)(ITEM_INFO*, ITEM_INFO*)) 0x00479170) #define GetJointAbsPosition ((int (__cdecl*)(ITEM_INFO*, PHD_VECTOR*, int)) 0x00479780) -#define GetSpheres ((int (__cdecl*)(ITEM_INFO*, SPHERE*, int)) 0x00479380) \ No newline at end of file +//#define GetSpheres ((int (__cdecl*)(ITEM_INFO*, SPHERE*, int)) 0x00479380) + +int GetSpheres(ITEM_INFO* item, SPHERE* ptr, char worldSpace); + +void Inject_Sphere(); \ No newline at end of file diff --git a/TR5Main/Specific/roomload.cpp b/TR5Main/Specific/roomload.cpp index 9e781e014..61642ec56 100644 --- a/TR5Main/Specific/roomload.cpp +++ b/TR5Main/Specific/roomload.cpp @@ -264,7 +264,7 @@ void LoadObjects() } // HACK: until we don't decompile everything, this simple hack allows us to use legacy stuff correctly - for (int i = 0; i <= 518; i++) + for (int i = 0; i <= ID_HAIR; i++) { memcpy(&LegacyObjects[i], &Objects[i], sizeof(OBJECT_INFO)); } diff --git a/TR5Main/dllmain.cpp b/TR5Main/dllmain.cpp index e705b6253..47c782d1d 100644 Binary files a/TR5Main/dllmain.cpp and b/TR5Main/dllmain.cpp differ