[FIRST SFP] Render objects[0.0]

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <windows.h>
#include <string>
#include <assert.h>
#include "CSAMPFUNCS.h"
CSAMPFUNCS *SF = new CSAMPFUNCS();
stFontInfo *rFont;
bool init = false; // Load status
float vect3_length(const float in[3])
{
return sqrtf(in[0] * in[0] + in[1] * in[1] + in[2] * in[2]);
}
void vect3_vect3_sub(const float in1[3], const float in2[3], float out[3])
{
int i;
for (i = 0; i < 3; i++)
out[i] = in1[i] - in2[i];
}
float vect3_dist(const float in1[3], const float in2[3])
{
float dist[3];
vect3_vect3_sub(in1, in2, dist);
return vect3_length(dist);
}
void CalcScreenCoors(D3DXVECTOR3 *vecWorld, D3DXVECTOR3 *vecScreen)
{
/** C++-ifyed function 0x71DA00, formerly called by CHudSA::CalcScreenCoors **/
// Get the static view matrix as D3DXMATRIX
D3DXMATRIX m((float *)(0xB6FA2C));
// Get the static virtual screen (x,y)-sizes
DWORD *dwLenX = (DWORD *)(0xC17044);
DWORD *dwLenY = (DWORD *)(0xC17048);
//DWORD *dwLenZ = (DWORD*)(0xC1704C);
//double aspectRatio = (*dwLenX) / (*dwLenY);
// Do a transformation
vecScreen->x = (vecWorld->z * m._31) + (vecWorld->y * m._21) + (vecWorld->x * m._11) + m._41;
vecScreen->y = (vecWorld->z * m._32) + (vecWorld->y * m._22) + (vecWorld->x * m._12) + m._42;
vecScreen->z = (vecWorld->z * m._33) + (vecWorld->y * m._23) + (vecWorld->x * m._13) + m._43;
// Get the correct screen coordinates
double fRecip = (double)1.0 / vecScreen->z; //(vecScreen->z - (*dwLenZ));
vecScreen->x *= (float)(fRecip * (*dwLenX));
vecScreen->y *= (float)(fRecip * (*dwLenY));
}
bool CALLBACK Present(CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion)
// Render
{
if (SUCCEEDED(SF->getRender()->BeginRender()))
{
if (!SF->getGame()->isGTAMenuActive())
{
actor_info *self = SF->getGame()->actorInfoGet(ACTOR_SELF, ACTOR_ALIVE);
if (self != nullptr)
{
char rText[32]; // buf
float fObjPos[3]; // object positions
float fScreen[3]; //
D3DXVECTOR3 eobjpos, escreen;
for (int i = 0; i < MAX_OBJECTS; i++)
{
if (!SF->getSAMP()->getInfo()->pPools->pPool_Object->IsObjectExists(i))
continue;
object_info *obj = SF->getSAMP()->getInfo()->pPools->pPool_Object->object[i]->pGTAObject;
if (obj == nullptr)
continue;
fObjPos[0] = obj->base.matrix[4 * 3];
fObjPos[1] = obj->base.matrix[4 * 3 + 1];
fObjPos[2] = obj->base.matrix[4 * 3 + 2];
if (vect3_dist(fObjPos, &self->base.matrix[4 * 3]) > 30.0) // in dist >30.0
continue;
eobjpos.x = fObjPos[0];
eobjpos.y = fObjPos[1];
eobjpos.z = fObjPos[2];
CalcScreenCoors(&eobjpos, &escreen);
fScreen[0] = escreen.x;
fScreen[1] = escreen.y;
fScreen[2] = escreen.z;
if (fScreen[2] < 1.f) // object position behind player
continue; // search next object
sprintf(rText, "Object %d, model %d", i, obj->base.model_alt_id);
rFont->Print(rText, D3DCOLOR_XRGB(255, 255, 255), fScreen[0], fScreen[1], true); // Render text on object position
}
}
}
SF->getRender()->EndRender();
}
return 1;
}
void CALLBACK mainloop( void )
{
if( !init )
{
if( !SF->getSAMP()->IsInitialized() )
return;
rFont = SF->getRender()->CreateNewFont("Trebuchet MS", 9, FCR_BORDER|FCR_BOLD); //
SF->getRender()->registerD3DCallback(eDirect3DDeviceMethods::D3DMETHOD_PRESENT, Present); // Render
init = true;
}
}
BOOL APIENTRY DllMain( HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved )
{
switch ( dwReasonForCall )
{
case DLL_PROCESS_ATTACH:
SF->initPlugin( mainloop, hModule );
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}