SF API | PICKUP SOURCE

  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
#include <windows.h>
#include <string>
#include <assert.h>
#include "CSAMPFUNCS.h"
CSAMPFUNCS *SF = new CSAMPFUNCS();
stFontInfo *rFont;
bool rendPickState = false;
int PickUpID;
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];
}
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));
}
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 _stdcall cmd_rendpick_state(std::string)
{
rendPickState ^= true;
//SF->getSAMP()->getChat()->AddChatMessage(0 - 1, "Это мой пиздатый сф-плагин, суки.");
};
void CALLBACK cmd_sendpick(std::string param)
{
if (param.empty()) return;
sscanf(param.c_str(), "%d", &PickUpID);
SF->getSAMP()->sendPickedUpPickup(PickUpID);
}
bool CALLBACK Present(CONST RECT *pSourceRect, CONST RECT *pDestRect, HWND hDestWindowOverride, CONST RGNDATA *pDirtyRegion)
{
if (SUCCEEDED(SF->getRender()->BeginRender()))
{
if (!SF->getGame()->isGTAMenuActive())
{
actor_info *self = SF->getSAMP()->getPlayers()->pLocalPlayer->pSAMP_Actor->pGTA_Ped;
if (self != nullptr && rendPickState == true)
{
char rText[32]; // buf
float fPickPos[3];
float fScreen[2];
D3DXVECTOR3 epickpos, escreen;
for (int i = 0; i < MAX_PICKUPS; i++)
{
if (SF->getSAMP()->getInfo()->pPools->pPool_Pickup->IsPickupExists(i))
{
stPickup *pick = &SF->getSAMP()->getInfo()->pPools->pPool_Pickup->pickup[i];
if (pick == nullptr)
continue;
fPickPos[0] = pick->fPosition[0];
fPickPos[1] = pick->fPosition[1];
fPickPos[2] = pick->fPosition[2];
if (vect3_dist(fPickPos, &self->base.matrix[4 * 3]) > 30.0)
continue;
epickpos.x = fPickPos[0];
epickpos.y = fPickPos[1];
epickpos.z = fPickPos[2];
CalcScreenCoors(&epickpos, &escreen);
fScreen[0] = escreen.x;
fScreen[1] = escreen.y;
fScreen[2] = escreen.z;
if (fScreen[2] < 1.f)
continue;
sprintf(rText, "%d", i);
rFont->Print(rText, 0xFFFFCC00, fScreen[0], fScreen[1], true);
}
}
}
}
SF->getRender()->EndRender();
}
return 1;
}
void CALLBACK mainloop(void)
{
static bool init = false;
if (!init)
{
if (!SF->getSAMP()->IsInitialized())
return;
SF->getSAMP()->getChat()->AddChatMessage(0xFFCC00, "[BLASTHACK] {EAEAEA}PickUp plugin loaded // by hnnssy.");
SF->getSAMP()->registerChatCommand("sendpick", cmd_sendpick);
SF->getSAMP()->registerChatCommand("rendpick", cmd_rendpick_state);
rFont = SF->getRender()->CreateNewFont("Comic Sans MS", 9, 5);
SF->getRender()->registerD3DCallback(eDirect3DDeviceMethods::D3DMETHOD_PRESENT, Present);
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;
}