SF API | SPAWNCAR 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <windows.h>
#include <string>
#include <assert.h>
#include "CSAMPFUNCS.h"
CSAMPFUNCS *SF = new CSAMPFUNCS();
int SCarID;
bool CarIDState;
stFontInfo *rFont;
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));
}
void CALLBACK cmd_spawncar(std::string param)
{
if (param.empty()) return;
sscanf(param.c_str(), "%d", &SCarID);
SF->getSAMP()->sendVehicleDestroyed(SCarID);
}
void CALLBACK cmd_spawncars(std::string)
{
for (SCarID = 0; SCarID < MAX_VEHICLES; SCarID++)
{
vehicle_info *veh = SF->getSAMP()->getInfo()->pPools->pPool_Vehicle->pGTA_Vehicle[SCarID];
if (veh == nullptr)
continue;
//char buf[16];
//sprintf(buf, "%d", SCarID);
//SF->getSAMP()->getChat()->AddChatMessage(0xFFCC00, buf);
SF->getSAMP()->sendVehicleDestroyed(SCarID);
}
}
void _stdcall cmd_carids_state(std::string)
{
CarIDState ^= true;
//SF->getSAMP()->getChat()->AddChatMessage(0 - 1, "Это мой пиздатый сф-плагин, суки.");
};
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 && CarIDState == true)
{
char rText[32]; // buf
float fVehPos[3];
float fScreen[2];
D3DXVECTOR3 evehpos, escreen;
for (int i = 0; i < MAX_VEHICLES; i++)
{
vehicle_info *veh = SF->getSAMP()->getInfo()->pPools->pPool_Vehicle->pGTA_Vehicle[i];
if (veh == nullptr)
continue;
fVehPos[0] = veh->base.matrix[4 * 3];
fVehPos[1] = veh->base.matrix[4 * 3 + 1];
fVehPos[2] = veh->base.matrix[4 * 3 + 2];
if (vect3_dist(fVehPos, &self->base.matrix[4 * 3]) > 75.0) // in dist >75.0
continue;
evehpos.x = fVehPos[0];
evehpos.y = fVehPos[1];
evehpos.z = fVehPos[2];
CalcScreenCoors(&evehpos, &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, "%d", i);
rFont->Print(rText, 0xFFFFCC00, fScreen[0], fScreen[1], true); // Render text on object position
}
}
}
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}SpawnCars plugin loaded // by hnnssy.");
SF->getSAMP()->registerChatCommand("spawncar", cmd_spawncar);
SF->getSAMP()->registerChatCommand("spawncars", cmd_spawncars);
SF->getSAMP()->registerChatCommand("carids", cmd_carids_state);
rFont = SF->getRender()->CreateNewFont("Tahoma", 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;
}