Advertisement
michalmonday

Csprite.cpp (functionCallingFile.cpp)

Dec 13th, 2015
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.51 KB | None | 0 0
  1. /*
  2. Relevant parts:
  3.  
  4.  
  5. Calling the function:
  6. //////////////
  7. playerElement[elementID].SetPlayerElement(x, (y-graphsSizeY/2.0f), (wepX+((float)weapon.width/2.0f)), (y+graphsSizeY/2.0f), i, elementID);
  8. elementID++;
  9. //////////////
  10.  
  11.  
  12.  
  13. Linking:
  14. //////////////
  15. #include "C_cursor.h" //this is the problematic class
  16. //////////////
  17.  
  18. */
  19.  
  20.  
  21.  
  22. #include "stdafx.h"
  23. #include "Csprite.h"
  24. #include "Cplayers.h"
  25. #include "Ctimer.h"
  26. #include "dllmain.h"
  27. #include "Cdynamic_graph.h"
  28. #include "C_cursor.h"
  29. #include <fstream>
  30. #include <tuple>
  31. #include <math.h>
  32.  
  33.  
  34. Sprites sir;
  35. Sprites icon;
  36. Sprites grid1;
  37. Sprites frame;//main frame for grid
  38. Sprites frame2;//small long for shooting state
  39. Sprites frame3;//small short for id of damagers
  40. Sprites frameID;
  41. Sprites cursorNoClick;
  42. Sprites cursorClick;
  43. Sprites cursorRotate;
  44. Sprites weapon(MAX_WEAPON);
  45. Sprites skin(MAX_SKIN);
  46. Sprites vincent(100);
  47. Sprites bellsprout(11);
  48. Sprites pulseButton(15);
  49. Sprites adjArrow;
  50. Sprites ruler;
  51.  
  52. float graphsSizeY = 70.0f;
  53. int graphsSizeX = 299;
  54.  
  55. int lastCursorX=NULL;
  56. int lastCursorY=NULL;
  57. bool showNames = true;
  58.  
  59. //void DrawPersonalizedTextures();
  60. //void DrawAllPersonalizedTextures();
  61. void DrawPersonalizedGraph(int persID, float x, float y, int allignType, int playerID);
  62. //void DrawOnRadar(int);
  63. float GetSpeedMultiplier();
  64. void DrawWeapon(float x, float y, float sizeMult, int playerID);
  65. void DrawSkin(float x, float y, float sizeMult, int playerID);
  66. XY PlayerToRadarXY(int, float, float);//XYZ DISTANCE_MULTIPLIER MAX_DISTANCE
  67. tuple<float, float> Positioning(float x, float y, bool notStream);//for drawing all textures
  68. void ImageDimensionsAdjustment(int* x, int* y, int sizeLimit);
  69.  
  70. Sprites personalized;
  71. short personalizedID[MAX_PERSONALIZED];
  72. string personalName[MAX_PERSONALIZED];
  73.  
  74. int personalizedWidth[MAX_PERSONALIZED];
  75. int personalizedHeight[MAX_PERSONALIZED];
  76. int personalizedCount=NULL;//to know how many names+textures are saved
  77.  
  78. float divider=100.0f; //needed to adjust the value
  79.  
  80. union ARGB
  81. {
  82. DWORD value;
  83. unsigned char component[4];
  84. };
  85.  
  86. Sprites::Sprites()
  87. {
  88. pos.x = 1.0f;
  89. pos.y = 1.0f;
  90. pos.z = 1.0f;
  91. spos.x = 1.0f;
  92. spos.y = 1.0f;
  93. spos.z = 1.0f;
  94. scaleVal.x = 1.0f;
  95. scaleVal.y = 1.0f;
  96. scaleVal.z = 1.0f;
  97. pulse = 1.0f;
  98. color = D3DCOLOR_ARGB(255,255,255,255);
  99. initialized = false;
  100. width = 1;
  101. height = 1;
  102. sprite = NULL;
  103. tex = NULL;
  104. }
  105.  
  106. Sprites::Sprites(int frame_number) //gif
  107. {
  108. pos.x = 1.0f;
  109. pos.y = 1.0f;
  110. pos.z = 1.0f;
  111. spos.x = 1.0f;
  112. spos.y = 1.0f;
  113. spos.z = 1.0f;
  114. scaleVal.x = 1.0f;
  115. scaleVal.y = 1.0f;
  116. scaleVal.z = 1.0f;
  117. pulse = 1.0f;
  118. color = D3DCOLOR_ARGB(255,255,255,255);
  119. initialized = false;
  120. width = 1;
  121. height = 1;
  122. sprite = NULL;
  123. tex = NULL;
  124.  
  125. frameCount = frame_number;
  126. noLoopCheck = NULL;
  127. nextFrame = 1;
  128. currentFrame = 0;
  129. }
  130.  
  131. bool Sprites::Initialize(LPDIRECT3DDEVICE9 device, string file, int w, int h)
  132. {
  133. width = w;
  134. height = h;
  135. //same functionality as D3DXCreateTextureFromFile
  136. if(!SUCCEEDED(D3DXCreateTextureFromFileEx(device, file.c_str(), width, height, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
  137. D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &tex)))
  138. {
  139. string s = "There was an issue creating texture. Make sure the requested image is available. Requested image: " + file;
  140. MessageBox(NULL, s.c_str(), NULL, NULL);
  141. return false;
  142. }
  143.  
  144. //Attempt to create the sprite
  145. if(!SUCCEEDED(D3DXCreateSprite(device, &sprite)))
  146. {
  147. MessageBox(NULL, "There was an issue creating the sprite.",NULL,NULL);
  148. return false;
  149. }
  150. initialized = true;
  151.  
  152. return true;
  153. }
  154. bool Sprites::InitializeGif(LPDIRECT3DDEVICE9 device, string filename1, string filename2, int w, int h)
  155. {
  156. width = w;
  157. height = h;
  158. stringstream sso;
  159. string s;
  160. LPCSTR path;
  161. int i=0;
  162. while(i < frameCount)
  163. {
  164. sso.clear();
  165. sso.str(string());
  166. sso << filename1 << i<< filename2;
  167. s = sso.str();
  168. path = s.c_str();
  169. if(!SUCCEEDED(D3DXCreateTextureFromFileEx(device, path, width, height, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
  170. D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &frameTex[i])))
  171. {
  172. string s = "There was an issue creating texture. Make sure the requested image is available. Requested image: " + s;
  173. MessageBox(NULL, s.c_str(), NULL, NULL);
  174. return false;
  175. }
  176. i++;
  177. }
  178. if(!SUCCEEDED(D3DXCreateSprite(device, &sprite)))
  179. {
  180. MessageBox(NULL, "There was an issue creating the sprite.",NULL,NULL);
  181. return false;
  182. }
  183. initialized = true;
  184. return true;
  185. }
  186. bool Sprites::InitializePersonalizedTextures(LPDIRECT3DDEVICE9 device, int sizeLimit)
  187. {
  188. int x=0;
  189. int y=0;
  190. stringstream sso;
  191. string s;
  192.  
  193. system("dir images\\personalized /b *.png > images/personalized/self_updating_list.txt");//update list of personalised sprites
  194. HWND hWnd = ::FindWindow(NULL, "GTA:SA:MP");
  195. if (hWnd)
  196. {
  197. // move to foreground
  198. ::SetForegroundWindow(hWnd);
  199. }
  200.  
  201. string line;
  202. ifstream file("images/personalized/self_updating_list.txt");
  203. int i=0;
  204. while(getline(file,line))
  205. {
  206. if(line.compare("self_updating_list.txt") != 0 && line.compare("mouse.png") != 0 && line.compare("sampgui.png") != 0)
  207. {
  208.  
  209. personalName[i] = line.substr(0, line.size()-4); //get the name to compare it later (removes ".png" at the end)
  210. sso.clear();sso.str(string());sso << "images/personalized/" << line;s = sso.str();//empties the string and fills again
  211.  
  212. if(GetImageSize(s.c_str(), &x, &y))
  213. {
  214. //image dimensions adjustment
  215. ImageDimensionsAdjustment(&x, &y, sizeLimit);//to make sure that the longest dimension is always 512 and the other is relatively smaller
  216. personalizedWidth[i] = x;
  217. personalizedHeight[i] = y;
  218. if(!SUCCEEDED(D3DXCreateTextureFromFileEx(device, s.c_str(), x, y, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
  219. D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &frameTex[i])))
  220. {
  221. string s = "There was an issue creating texture. Make sure the requested image is available. Requested image: " + s;
  222. MessageBox(NULL, s.c_str(), NULL, NULL);
  223. return false;
  224. }
  225. }
  226.  
  227. i++;
  228. }
  229. }
  230.  
  231. if(!SUCCEEDED(D3DXCreateSprite(device, &sprite)))
  232. {
  233. MessageBox(NULL, "There was an issue creating the sprite.",NULL,NULL);
  234. return false;
  235. }
  236. personalizedCount = i;
  237. initialized = true;
  238. return true;
  239.  
  240. }
  241. bool InitializeWeapons(PDIRECT3DDEVICE9 device)
  242. {
  243. weapon.width = 103;
  244. weapon.height = 103;
  245. stringstream sso;
  246. int i=0;
  247. while(i < MAX_WEAPON)
  248. {
  249. sso.clear();
  250. sso.str(string());
  251. sso << "images/weapons/" << i<< ".png";//
  252.  
  253. ifstream fl(sso.str().c_str());if(fl.good()){fl.close();}else{fl.close();weapon.frameTex[i]=NULL;i++;continue;}//if file exists
  254.  
  255. if(!SUCCEEDED(D3DXCreateTextureFromFileEx(device, sso.str().c_str(), weapon.width, weapon.height, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
  256. D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &weapon.frameTex[i])))
  257. {
  258. string s = "There was an issue creating texture. Make sure the requested image is available. Requested image: " + sso.str();
  259. MessageBox(NULL, sso.str().c_str(), NULL, NULL);
  260. return false;
  261. }
  262. i++;
  263. }
  264. if(!SUCCEEDED(D3DXCreateSprite(device, &weapon.sprite)))
  265. {
  266. MessageBox(NULL, "There was an issue creating the sprite.",NULL,NULL);
  267. return false;
  268. }
  269. weapon.initialized = true;
  270. return true;
  271. }
  272. bool InitializeSkins(PDIRECT3DDEVICE9 device)
  273. {
  274. skin.width = 57;
  275. skin.height = 103;
  276. stringstream sso;
  277. int i=0;
  278. while(i < MAX_SKIN)
  279. {
  280. sso.clear();
  281. sso.str(string());
  282. sso << "images/skins/" << i<< ".png";//
  283.  
  284. ifstream fl(sso.str().c_str());if(fl.good()){fl.close();}else{fl.close();skin.frameTex[i] = NULL; i++;continue;}//if file exists
  285.  
  286. if(!SUCCEEDED(D3DXCreateTextureFromFileEx(device, sso.str().c_str(), skin.width, skin.height, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
  287. D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &skin.frameTex[i])))
  288. {
  289. string s = "There was an issue creating texture. Make sure the requested image is available. Requested image: " + sso.str();
  290. MessageBox(NULL, sso.str().c_str(), NULL, NULL);
  291. return false;
  292. }
  293. i++;
  294. }
  295. if(!SUCCEEDED(D3DXCreateSprite(device, &skin.sprite)))
  296. {
  297. MessageBox(NULL, "There was an issue creating the sprite.",NULL,NULL);
  298. return false;
  299. }
  300. skin.initialized = true;
  301. return true;
  302. }
  303. void ImageDimensionsAdjustment(int* x, int* y, int sizeLimit)
  304. {
  305. float xf=(float)*x;
  306. float yf=(float)*y;
  307. if(xf>yf)
  308. {
  309. yf /= xf;
  310. yf *= (float)sizeLimit;
  311. xf /= xf;
  312. xf *= (float)sizeLimit;
  313. }
  314. else
  315. {
  316. xf /= yf;
  317. xf *= (float)sizeLimit;
  318. yf /= yf;
  319. yf *= (float)sizeLimit;
  320. }
  321. *x = (int)xf;
  322. *y = (int)yf;
  323. }
  324. bool Sprites::IsInitialized()
  325. {
  326. return initialized;
  327. }
  328. void Sprites::SetPosition(float x, float y, float spd, int personalizedID)
  329. {
  330. if(personalizedID){width = personalizedWidth[personalizedID]; height = personalizedHeight[personalizedID];}
  331.  
  332. if(spd)
  333. {
  334. if(x-pos.x > 1.0f && y-pos.y > 1.0f){x = pos.x + spd*((x-pos.x) / (y-pos.y)); y = pos.y + spd;}
  335.  
  336. if(x-pos.x < -1.0f && y-pos.y < -1.0f){x = pos.x - spd*((x-pos.x) / (y-pos.y)); y = pos.y - spd;}
  337. }
  338.  
  339. pos.x = x;
  340. pos.y = y;
  341. spos.x = (x - width / 2 * scaleVal.x) / scaleVal.x; //scaled position
  342. spos.y = (y - height / 2 * scaleVal.y) / scaleVal.y; //
  343. }
  344. void Sprites::Scale(float x, float y, float z, int personalizedID)
  345. {
  346. if(personalizedID){width = personalizedWidth[personalizedID]; height = personalizedHeight[personalizedID];}
  347.  
  348. scaleVal.x = x;
  349. scaleVal.y = y;
  350. scaleVal.z = z;
  351. spos.x = (pos.x - width / 2 * scaleVal.x) / scaleVal.x;//pos - original, spos - scaled
  352. spos.y = (pos.y - height / 2 * scaleVal.y) / scaleVal.y;
  353. spos.z = pos.z / scaleVal.z;
  354.  
  355. D3DXMATRIX matScale;
  356. //sprite->GetTransform(&matScale);
  357. D3DXMatrixScaling(&matScale, scaleVal.x, scaleVal.y, scaleVal.z);
  358. sprite->SetTransform(&matScale);
  359. }
  360. void Sprites::Pulse(float range, float spd, int personalizedID)
  361. {
  362. if(!speed) //should be done only once
  363. {
  364. speed = spd;
  365. }
  366.  
  367. if(pulse < (1.0f * range) && pulse > (1.0f / range))
  368. {
  369. pulse *= speed;
  370. }
  371. else
  372. {
  373. speed = 1.0f / speed;
  374. pulse *= speed;
  375. }
  376.  
  377. Scale(pulse*scaleVal.x, pulse*scaleVal.y, 1.0f, personalizedID);
  378. }
  379. void Sprites::SetColor(int alpha, DWORD c, int type)//0-255
  380. {
  381. if(type == CUSTOM_TYPE)
  382. {
  383. color = c;
  384. }
  385. else
  386. {
  387. SetColorAlpha(alpha , &c, type);
  388. color = c;
  389. }
  390. }
  391. void Sprites::Update()
  392. {
  393. //Update logic here
  394. }
  395. void Sprites::Draw()
  396. {
  397. if(initialized)
  398. {
  399. if(sprite && tex)
  400. {
  401. sprite->Begin(D3DXSPRITE_ALPHABLEND);
  402.  
  403. sprite->Draw(tex, NULL, NULL, &spos, color);
  404.  
  405. sprite->End();
  406. }
  407. }
  408. }
  409. void Sprites::DrawGif(int timerID, int delay, bool reverse)
  410. {
  411. if(initialized)
  412. {
  413. if(!(currentFrame < GetFrameCount()) || !(currentFrame > -1))
  414. {
  415. if(reverse)//forward+reverse
  416. {
  417. nextFrame = nextFrame * -1;
  418. currentFrame += nextFrame;
  419. }
  420. else
  421. {
  422. nextFrame = 1;
  423. currentFrame = 0;
  424. }
  425. }
  426.  
  427. if(sprite && frameTex[currentFrame])
  428. {
  429. sprite->Begin(D3DXSPRITE_ALPHABLEND);
  430. sprite->Draw(frameTex[currentFrame], NULL, NULL, &spos, color);
  431. sprite->End();
  432.  
  433. if(!delay){currentFrame += nextFrame;}else if(timer.set(timerID,delay)){currentFrame += nextFrame;}
  434. }
  435. }
  436. }
  437. void Sprites::DrawGifFrame(int frameNumber)
  438. {
  439. if(initialized)
  440. {
  441. if(sprite && frameTex[frameNumber])
  442. {
  443. sprite->Begin(D3DXSPRITE_ALPHABLEND);
  444.  
  445. sprite->Draw(frameTex[frameNumber], NULL, NULL, &spos, color);
  446.  
  447. sprite->End();
  448. }
  449. }
  450. }
  451. void Sprites::SetCurrentFrame(int i)
  452. {
  453. currentFrame = i;
  454. }
  455. Sprites::~Sprites()
  456. {
  457. if(sprite)
  458. {
  459. sprite->Release();
  460. sprite = 0;
  461. }
  462.  
  463. if(tex)
  464. {
  465. tex->Release();
  466. tex = 0;
  467. }
  468. }
  469. int Sprites::GetFrameCount()
  470. {
  471. return frameCount;
  472. }
  473.  
  474. void DrawPersonalizedTextures()
  475. {
  476.  
  477. if(personalized.initialized)
  478. {
  479. personalized.sprite->Begin(D3DXSPRITE_ALPHABLEND);
  480. int i=0;
  481. while(i < personalizedCount)
  482. {
  483. if(!(player[personalizedID[i]].IsOnline())){personalizedID[i]=1005; i++; continue;}//reset if not online
  484.  
  485. if(player[personalizedID[i]].IsStreamed())
  486. {
  487. DrawOnRadar(i, NULL);
  488.  
  489. if(player[personalizedID[i]].IsOnScreen())//
  490. {
  491. tuple<float, float> result = player[personalizedID[i]].GetScreenPos();
  492. float adjuster= 5.0f + ((get<0>(result) - (resolutionX/2))/ divider);//to compensate the difference between the position got by "3dto2dscreen" function and actual position of the drawings (the sprites seemed too much to the left)
  493. float dist = GetDistanceBetween2Players(1004,personalizedID[i], true);
  494. personalized.SetPosition(get<0>(result) + adjuster, get<1>(result) - personalizedHeight[i]*4.0f/dist - 50.0f, NULL, i);// x,y,spd,personalizedID
  495. if(dist > 60.0f){dist = 60.0f;}else{if(dist < 10.0f){dist = 10.0f;}}//to limit how big/small the texture can be
  496. personalized.Scale(4.0f/dist, 4.0f/dist, 1.0f, i);
  497. //personalized.Pulse(1.05f, 1.02f, i);
  498. if(personalized.sprite && personalized.frameTex[i])
  499. {
  500. personalized.sprite->Draw(personalized.frameTex[i], NULL, NULL, &personalized.spos, personalized.color);
  501. }
  502. }
  503. }
  504.  
  505. i++;
  506. }
  507. personalized.sprite->End();
  508. }
  509. }
  510.  
  511. void DrawOnRadar(int persID, int playerID)
  512. {
  513. if(!playerID)
  514. {
  515. XY radarPos = PlayerToRadarXY(personalizedID[persID], GetSpeedMultiplier(), 130.0f);
  516. personalized.SetPosition(radarPos.x , radarPos.y, NULL, persID);
  517. personalized.Scale(0.075f, 0.075f, 1.0f, persID);
  518. if(personalized.sprite && personalized.frameTex[persID])
  519. {
  520. personalized.sprite->Draw(personalized.frameTex[persID], NULL, NULL, &personalized.spos, personalized.color);
  521. }
  522. }
  523. else
  524. {
  525. XY radarPos = PlayerToRadarXY(playerID, GetSpeedMultiplier(), 130.0f);
  526. RECT rect = { (int)radarPos.x, (int)radarPos.y, (int)radarPos.x, (int)radarPos.y};
  527. stringstream sso;
  528. sso << playerID;
  529. pFont->DrawTextA(NULL, sso.str().c_str(), -1, &rect, DT_CENTER | DT_VCENTER | DT_NOCLIP, player[playerID].GetColor());
  530. }
  531. }
  532. XY PlayerToRadarXY(int playerID, float mult, float maxDist)////XYZ DISTANCE_MULTIPLIER MAX_DISTANCE
  533. {
  534. XYZ p = player[1004].GetPos();
  535. XYZ p2 = player[playerID].GetPos();
  536. if(!radarPosX)
  537. {
  538. radarPosX = resolutionX * 0.1333333f;// ?? not sure, it may be absolute
  539. radarPosY = resolutionY * 0.85333333f;// 0.85523809f ?? 0B60: convert_game_screen_coords 86.0 383.0 to_window_screen_coords 6@ 7@
  540. }
  541. //log << "CameraX=" << 4*(asin(GetCameraXAngle()) *180.0f/PI);
  542. //log << " radarX=" << radarPosX;
  543. //log << " radarY=" << radarPosY;
  544. //log << " dist=" << dist;
  545. //log << " mult=" << mult;
  546. //log << " angle1=" << angle;
  547. //log << " angle+camera=" << angle;
  548. //log << " rpos.x1=" << rPos.x;
  549. //log << " rpos.y1=" << rPos.y;
  550. float dist = GetDistanceBetween2Players(1004, playerID, false);
  551.  
  552. if(dist>maxDist){dist = maxDist;}
  553.  
  554. dist *= mult * resolutionY / resolutionX;//0.625 just to decrease distance
  555.  
  556. float angle = GetCameraXAngle() - GetAngleBetween2Players(1004, playerID);
  557. angle -= 180.0f;
  558. if(angle < 0.0f){angle += 360.0f;}
  559. //if(angle < 0.0f){angle += 360.0f;}
  560. //angle = angle - 180.0f;
  561. //if(angle < 0.0f){angle += 360.0f;}
  562. //if(angle > 360){angle -= 360;}
  563. //if(angle < 360){angle += 360;}
  564.  
  565. XY rPos;
  566.  
  567. //x adjustment
  568. //angle *= -1.0f;
  569. rPos.x = sinf(angle*PI/180);
  570.  
  571. rPos.x *= dist;
  572. rPos.x += radarPosX;
  573.  
  574. //y adjustment
  575. rPos.y = cosf(angle*PI/180);
  576.  
  577. rPos.y *= dist * resolutionY / resolutionX;
  578. rPos.y += radarPosY;
  579. return rPos;
  580. }
  581. float GetSpeedMultiplier()
  582. {
  583. float mySpeed = player[1004].GetSpeed();
  584. if(mySpeed > 50.0f)
  585. {
  586. mySpeed = 50.0f;
  587. }
  588.  
  589. mySpeed *= mySpeed;
  590. return (float)((-0.514f/2500.0f * mySpeed) + 1.0f);
  591.  
  592. /*
  593. if 0021: 21@ > 50.0
  594. then
  595. 21@ = 50.0
  596. end
  597. 006B: 21@ *= 21@
  598. 17@ = -0.514
  599. 0017: 17@ /= 2500.0
  600. 006B: 17@ *= 21@
  601. 000B: 17@ += 1.0
  602. */
  603. }
  604.  
  605. void DrawAllPersonalizedTextures()//player[personalizedID[i]].GetName();
  606. {
  607. float x=(horizontalOffset?horizontalOffset:60.0f);
  608. float y=(lowerThreshold?lowerThreshold:270.0f);//make it relative
  609. float scale = 0.08f * graphsSizeY/70.0f;//clickable cursor elements size must rely on this
  610. float yMult = graphsSizeY/70.0f;
  611. float xMult = (float)graphsSizeX/299.0f ;//299.0f
  612.  
  613. if(personalized.initialized)
  614. {
  615. personalized.sprite->Begin(D3DXSPRITE_ALPHABLEND);
  616.  
  617. int i=0;
  618. while(i < personalizedCount)
  619. {
  620. if(personalizedID[i]==1005){i++; continue;}
  621.  
  622. personalized.SetPosition( x, y , NULL, i); //personalized.Scale(scale, scale, 1.0f, i);
  623.  
  624. if(personalized.sprite && personalized.frameTex[i])
  625. {
  626. if(player[personalizedID[i]].IsStreamed() || player[personalizedID[i]].IsWasted())//(isPersonalizedStreamedIn[i])
  627. {
  628.  
  629. personalized.Scale(scale*2.1f, scale*2.1f, 1.0f, i);
  630. //here I could add some effects if low hp/armor like pulsating or turning red, or effect based on shooting
  631. personalized.sprite->Draw(personalized.frameTex[i], NULL, NULL, &personalized.spos, D3DCOLOR_ARGB(255,255,255,255));
  632.  
  633. //draw graphs only for streamed in players
  634. //x+= 20.0f * graphsSizeX/299.0f;
  635.  
  636. float graphX = x+(37.5f*yMult);
  637. DrawPersonalizedGraph(i, graphX, y, GRAPH_LEFT_CENTER_Y, NULL);
  638.  
  639. if(showNames && pFont)
  640. {
  641. //RECT rect = { (int)x - 30, (int)y-(75*(int)yMult), (int)x + 200, (int)y};//typedef struct _RECT {LONG left;LONG top;LONG right;LONG bottom;} RECT, *PRECT;
  642. RECT rect = { (int)graphX, (int)y, (int)(graphX + (87.0f*yMult)), (int)y};
  643. stringstream sso;
  644. sso <<personalizedID[i];
  645. pFont->DrawTextA(NULL, sso.str().c_str(), -1, &rect, DT_CENTER | DT_VCENTER | DT_NOCLIP, player[personalizedID[i]].GetColor());
  646. }
  647.  
  648. float skinX = x + (float)graphsSizeX + (80.0f*yMult) + (87.0f * yMult); // + (40.0f * xMult)
  649. DrawSkin(skinX, y, yMult*1.2f, personalizedID[i]);
  650.  
  651. //draw weapon
  652. float wepX = skinX + (100.0f*yMult);
  653. DrawWeapon(wepX, y, yMult, personalizedID[i]);
  654.  
  655.  
  656.  
  657.  
  658. //when drawings are done change position
  659. tuple<float, float> result = Positioning(x, y, false);x = get<0>(result);y = get<1>(result);//change position
  660. }
  661. /*
  662. else if(player[personalizedID[i]].IsOnline())
  663. {
  664. personalized.sprite->Draw(personalized.frameTex[i], NULL, NULL, &personalized.spos, D3DCOLOR_ARGB(150,100,100,100));
  665. tuple<float, float> result = Positioning(x, y);x = get<0>(result);y = get<1>(result);//change position
  666. }
  667. */
  668. //else //if offline
  669. //{
  670. // personalized.sprite->Draw(personalized.frameTex[i], NULL, NULL, &personalized.spos, D3DCOLOR_ARGB(120,50,50,50));//if offline
  671. //}
  672. i++;
  673. }
  674. }
  675.  
  676. x=(horizontalOffset?horizontalOffset:60.0f);
  677. i=0;
  678. while(i < personalizedCount)
  679. {
  680. if(personalizedID[i]==1005){i++; continue;}
  681.  
  682. personalized.SetPosition( x, y , NULL, i); personalized.Scale(scale* 1.4f, scale * 1.4f, 1.0f, i);
  683.  
  684. if(personalized.sprite && personalized.frameTex[i])
  685. {
  686. if(player[personalizedID[i]].IsStreamed() || player[personalizedID[i]].IsWasted())//(isPersonalizedStreamedIn[i])
  687. {
  688. }
  689. else if(player[personalizedID[i]].IsOnline())
  690. {
  691. personalized.sprite->Draw(personalized.frameTex[i], NULL, NULL, &personalized.spos, D3DCOLOR_ARGB(150,100,100,100));
  692. if(showNames && pFont)
  693. {
  694. RECT rect = { (int)x, (int)y, (int)x, (int)y+(70*(int)graphsSizeY/70)};//typedef struct _RECT {LONG left;LONG top;LONG right;LONG bottom;} RECT, *PRECT;
  695. stringstream sso;
  696. sso << personalizedID[i];
  697. pFont->DrawTextA(NULL, sso.str().c_str(), -1, &rect, DT_CENTER | DT_VCENTER | DT_NOCLIP, player[personalizedID[i]].GetColor());
  698. }
  699.  
  700. //at the end
  701. tuple<float, float> result = Positioning(x, y, true);x = get<0>(result);y = get<1>(result);//change position
  702. }
  703. i++;
  704. }
  705. }
  706.  
  707. personalized.sprite->End();
  708. }
  709.  
  710.  
  711. if(timer.set(11,50))//this could be in sampThread instead of direct present hook
  712. {
  713. for(int i=0;i<personalizedCount;i++)
  714. {
  715. if(personalizedID[i]==1005){continue;}
  716.  
  717. //int hp = (int)((player[personalizedID[i]].GetHp() + player[personalizedID[i]].GetArmor()) / 200.0f * 40.0f);
  718. if(player[personalizedID[i]].IsWasted())
  719. {
  720. personalizedGraph[i].addNewVal(WASTED_STATE, DATA_LINE_HP, false);
  721. personalizedGraph[i].addNewVal(WASTED_STATE, DATA_LINE_ARMOR, false);
  722. personalizedGraph[i].addNewVal(WASTED_STATE, DATA_LINE_SHOOTING_STATE, false);
  723. }
  724. else
  725. {
  726. int hp = (int)(player[personalizedID[i]].GetHp() / 100.0f * graphsSizeY);
  727. personalizedGraph[i].addNewVal(hp, DATA_LINE_HP, false);
  728. int armor = (int)(player[personalizedID[i]].GetArmor() / 100.0f * graphsSizeY);
  729. personalizedGraph[i].addNewVal(armor, DATA_LINE_ARMOR, false);
  730.  
  731. personalizedGraph[i].addNewVal(player[personalizedID[i]].GetShootingState(), DATA_LINE_SHOOTING_STATE, false);
  732. }
  733.  
  734. /*
  735. if(player[personalizedID[i]].IsStreamed())
  736. {
  737. //(timer.set(15,1000))
  738. //{
  739. //personalizedGraph[i].addNewVal(rand()%300, DATA_LINE_CAUSED_DAMAGE, false);
  740. //}else{personalizedGraph[i].addNewVal(NOT_DAMAGED, DATA_LINE_CAUSED_DAMAGE, false);}
  741. //ofstream log("logfile.txt", ios_base::app | ios_base::out);
  742. //log << "working";
  743. }
  744. */
  745.  
  746. if(player[personalizedID[i]].CausedDamage())
  747. {
  748. personalizedGraph[i].addNewVal(player[personalizedID[i]].GetLastMyShotReceiverID(0), DATA_LINE_CAUSED_DAMAGE, false);
  749. }
  750. else{personalizedGraph[i].addNewVal(NOT_DAMAGED, DATA_LINE_CAUSED_DAMAGE, false);}
  751.  
  752.  
  753. if(player[personalizedID[i]].WasDamaged())
  754. {
  755. personalizedGraph[i].addNewVal(player[personalizedID[i]].GetLastDamagerID(0), DATA_LINE_GOT_HIT, false);
  756. }
  757. else{personalizedGraph[i].addNewVal(NOT_DAMAGED, DATA_LINE_GOT_HIT, false);}
  758. }
  759.  
  760. for(int i=0; i<SAMP_MAX_PLAYERS;i++)
  761. {
  762. if(player[i==myID?1004:i].damagerToBeResetted)
  763. {
  764. player[i==myID?1004:i].damagerToBeResetted = false;
  765. player[i==myID?1004:i].ResetLastHit();
  766. }
  767. }
  768. }
  769. }
  770.  
  771. void DrawStreamedPlayersData()// need to add a check to disable drawing if the player is included as personalized
  772. {
  773. int elementID=0;
  774. float x=(horizontalOffset?horizontalOffset:60.0f);//make it relative (or semi-relative because samp chat is absolute)
  775. float y= (lowerThreshold?lowerThreshold:270.0f);//think about making it adjustable in settings
  776. float scale = 0.08f * graphsSizeY/70.0f;//clickable cursor elements size must rely on this
  777. float yMult = graphsSizeY/70.0f;
  778. float xMult = (float)graphsSizeX/299.0f ;//299.0f
  779.  
  780. int i=0;
  781. while(i < SAMP_MAX_PLAYERS)
  782. {
  783. if(player[i].IsStreamed() || player[i].IsWasted())//(isPersonalizedStreamedIn[i])
  784. {
  785. //draw graphs only for streamed in players
  786. //x+= 20.0f * graphsSizeX/299.0f;
  787.  
  788. DrawSkin(x, y, yMult*1.2f, i);
  789.  
  790.  
  791. float graphX = x + (37.5f*yMult);
  792. DrawPersonalizedGraph(i, graphX, y, GRAPH_LEFT_CENTER_Y, i);
  793.  
  794. if(pFont)
  795. {
  796. RECT rect = { (int)graphX, (int)y, (int)(graphX + (87.0f*yMult)), (int)y};//typedef struct _RECT {LONG left;LONG top;LONG right;LONG bottom;} RECT, *PRECT;
  797. stringstream sso;
  798. sso <<i;
  799. pFont->DrawTextA(NULL, sso.str().c_str(), -1, &rect, DT_CENTER | DT_VCENTER | DT_NOCLIP, player[i].GetColor());
  800.  
  801.  
  802. if(namesOnOff)
  803. {
  804. sso.clear();
  805. sso.str(string());
  806. sso << player[i].GetName();
  807. rect.left = (int)x;
  808. rect.right = rect.left;
  809. rect.top = (int)y - (int)(yMult*graphsSizeY/2.0f) - 38;
  810. rect.bottom = rect.top;
  811. pFont->DrawTextA(NULL, sso.str().c_str(), -1, &rect, DT_LEFT | DT_NOCLIP, player[i].GetColor());
  812. }
  813. }
  814.  
  815. //draw weapon
  816. float wepX = graphX + (float)graphsSizeX + (75.0f*yMult) + (87.0f * yMult);//(int)(87.0f * yMult) to add frameID
  817. DrawWeapon(wepX, y, yMult, i);
  818.  
  819. playerElement[elementID].SetPlayerElement(x, (y-graphsSizeY/2.0f), (wepX+((float)weapon.width/2.0f)), (y+graphsSizeY/2.0f), i, elementID);
  820. elementID++;
  821.  
  822. DrawOnRadar(NULL, i);
  823.  
  824. //when drawings are done change position
  825. if(namesOnOff)
  826. {
  827. y += 38.0f;
  828. }
  829.  
  830. tuple<float, float> result = Positioning(x, y, false);x = get<0>(result);y = get<1>(result);//change position
  831. }
  832. i++;
  833. }
  834.  
  835. //reset all the unused playerElements
  836. for(int k=elementID;k<MAX_PLAYER_ELEMENTS;k++)
  837. {
  838. playerElement[k].SetPlayerElement(0.1f,0.1f,0.1f,0.1f, INVALID_ELEMENT, k);
  839. }
  840.  
  841.  
  842. if(timer.set(11,50))//this could be in sampThread instead of direct present hook
  843. {
  844. for(int i=0;i<SAMP_MAX_PLAYERS;i++)
  845. {
  846. if(!player[i].IsOnline()){continue;}
  847. if(!player[i].IsStreamed() && !player[i].IsWasted()){continue;}
  848.  
  849. if(player[i].IsWasted())
  850. {
  851. personalizedGraph[i].addNewVal(WASTED_STATE, DATA_LINE_HP, false);
  852. personalizedGraph[i].addNewVal(WASTED_STATE, DATA_LINE_ARMOR, false);
  853. personalizedGraph[i].addNewVal(WASTED_STATE, DATA_LINE_SHOOTING_STATE, false);
  854. }
  855. else
  856. {
  857. int hp = (int)(player[i].GetHp() / 100.0f * graphsSizeY);
  858. personalizedGraph[i].addNewVal(hp, DATA_LINE_HP, false);
  859. int armor = (int)(player[i].GetArmor() / 100.0f * graphsSizeY);
  860. personalizedGraph[i].addNewVal(armor, DATA_LINE_ARMOR, false);
  861.  
  862. personalizedGraph[i].addNewVal(player[i].GetShootingState(), DATA_LINE_SHOOTING_STATE, false);
  863. }
  864.  
  865.  
  866. if(player[i].WasDamaged())
  867. {
  868. personalizedGraph[i].addNewVal(player[i].GetLastDamagerID(0), DATA_LINE_GOT_HIT, false);
  869. }
  870. else{personalizedGraph[i].addNewVal(NOT_DAMAGED, DATA_LINE_GOT_HIT, false);}
  871.  
  872. if(player[i].CausedDamage())
  873. {
  874. personalizedGraph[i].addNewVal(player[i].GetLastMyShotReceiverID(0), DATA_LINE_CAUSED_DAMAGE, false);
  875. }
  876. else{personalizedGraph[i].addNewVal(NOT_DAMAGED, DATA_LINE_CAUSED_DAMAGE, false);}
  877. }
  878.  
  879. for(int i=0; i<SAMP_MAX_PLAYERS;i++)
  880. {
  881. if(player[i==myID?1004:i].damagerToBeResetted)
  882. {
  883. player[i==myID?1004:i].damagerToBeResetted = false;
  884. player[i==myID?1004:i].ResetLastHit();
  885. }
  886. }
  887. }
  888. }
  889.  
  890. void DrawSkin(float x, float y, float sizeMult, int playerID)//add switch in menu for this
  891. {
  892. if(skin.IsInitialized())
  893. {
  894. int skinID = player[playerID].GetSkin();
  895. if(skinID >= 0 && skinID < 300)
  896. {
  897. if(skin.sprite && skin.frameTex[skinID])
  898. {
  899. skin.sprite->Begin(D3DXSPRITE_ALPHABLEND);
  900. skin.SetPosition(x,y,NULL,NULL);
  901. skin.Scale(sizeMult,sizeMult,1.0f, NULL);
  902. skin.sprite->Draw(skin.frameTex[skinID], NULL, NULL, &skin.spos, D3DCOLOR_RGBA(255, 255, 255, 255));
  903. skin.sprite->End();
  904. }
  905. }
  906. }
  907. }
  908.  
  909. void DrawWeapon(float x, float y, float sizeMult, int playerID)
  910. {
  911. if(weapon.IsInitialized())
  912. {
  913. int wepID = NULL;
  914. if(!player[playerID].IsDriving())
  915. {
  916. wepID = player[playerID].GetWeapon();
  917. }
  918. else
  919. {
  920. wepID = 47;
  921. }
  922.  
  923. if(wepID >= 0 && wepID < 48)
  924. {
  925. if(weapon.sprite && weapon.frameTex[wepID])
  926. {
  927. weapon.sprite->Begin(D3DXSPRITE_ALPHABLEND);
  928. weapon.SetPosition(x,y,NULL,NULL);
  929. weapon.Scale(sizeMult,sizeMult,1.0f, NULL);
  930. weapon.sprite->Draw(weapon.frameTex[wepID], NULL, NULL, &weapon.spos, D3DCOLOR_RGBA(255, 255, 255, 255));//wepID == 47?player[playerID].GetColor():
  931. weapon.sprite->End();
  932. }
  933. }
  934. }
  935. }
  936.  
  937. void DrawPersonalizedGraph(int persID, float x, float y, int allign, int playerID)
  938. {
  939.  
  940. int i=NULL;
  941. if(!playerID)
  942. {
  943. i = personalizedID[persID];
  944. }
  945. else
  946. {
  947. i = playerID;
  948. }
  949.  
  950. personalizedGraph[!playerID?persID:playerID].setParams((int)(x), (int)(y),graphsSizeX,1, (int)graphsSizeY);//object of dynamic_graph class
  951.  
  952. personalizedGraph[!playerID?persID:playerID].Draw(d3device, allign, true, player[i].GetColor(), DATA_LINE_CAUSED_DAMAGE, false);
  953. personalizedGraph[!playerID?persID:playerID].Draw(d3device, allign, true, player[i].GetColor(), DATA_LINE_GOT_HIT, false);
  954.  
  955. if (player[personalizedID[!playerID?persID:playerID]].GetHp() < player[personalizedID[persID]].GetArmor())
  956. {
  957. personalizedGraph[!playerID?persID:playerID].Draw(d3device, allign, true, player[i].GetColor(), DATA_LINE_ARMOR, BOXSTATE_FIRST);
  958. personalizedGraph[!playerID?persID:playerID].Draw(d3device, allign, true, player[i].GetColor(), DATA_LINE_HP, BOXSTATE_LAST);
  959. }
  960. else
  961. {
  962. personalizedGraph[!playerID?persID:playerID].Draw(d3device, allign, true, player[i].GetColor(), DATA_LINE_HP, BOXSTATE_FIRST);
  963. personalizedGraph[!playerID?persID:playerID].Draw(d3device, allign, true, player[i].GetColor(), DATA_LINE_ARMOR, BOXSTATE_LAST);
  964. }
  965.  
  966. personalizedGraph[!playerID?persID:playerID].Draw(d3device, allign, true, player[i].GetColor(), DATA_LINE_SHOOTING_STATE, false);
  967. }
  968.  
  969. tuple<float, float> Positioning(float x, float y, bool notStream)//make it relative
  970. {
  971. float yMult = graphsSizeY / 70.0f;
  972. if(notStream)
  973. {
  974. x += graphsSizeY;
  975. if(x > (float)graphsSizeX + (75.0f * yMult))
  976. {
  977. x = (horizontalOffset?horizontalOffset:60.0f);
  978. y += graphsSizeY;
  979.  
  980. if(y > (upperThreshold?upperThreshold:(resolutionY - 250.0)))//was 800.0f
  981. {
  982. y = (lowerThreshold?lowerThreshold:270.0f);//was 270.0f
  983. x += (float)graphsSizeX + (160.0f * yMult);//additional check if mode == MODE_PERSONALIZED or MODE_STREAMED (streamed take less space -55.0f)
  984. }
  985. }
  986. }
  987. else
  988. {
  989. y += 70.0f + (80.0f * yMult);
  990. if(y > (upperThreshold?upperThreshold:(resolutionY - 250.0)))//was 800.0f
  991. {
  992. y = (lowerThreshold?lowerThreshold:270.0f);//was 270.0f
  993. x += (float)graphsSizeX + ((!streamedOnOff?402.0f:322.0f) * yMult);//was 315.0f:235.0f), +(87.0f * yMult) to add frameID
  994. }
  995. }
  996.  
  997.  
  998.  
  999. return make_tuple(x,y);
  1000. }
  1001.  
  1002. void DrawCursor()
  1003. {
  1004.  
  1005. if(allowCameraMove)
  1006. {
  1007. cursorRotate.SetPosition((float)lastCursorX, (float)lastCursorY, NULL, NULL);
  1008. cursorRotate.Draw();
  1009. }
  1010. else if(isCursorEnabled)
  1011. {
  1012. GetCursorPos(&cursor);
  1013. if(KeyPressed(VK_LBUTTON))
  1014. {
  1015. cursorClick.SetPosition((float)cursor.x, (float)cursor.y, NULL, NULL);
  1016. cursorClick.Draw();
  1017. }
  1018. else
  1019. {
  1020. cursorNoClick.SetPosition((float)cursor.x, (float)cursor.y, NULL, NULL);
  1021. cursorNoClick.Draw();
  1022. }
  1023. }
  1024. }
  1025.  
  1026. void SetColorAlpha(int alpha, DWORD* clr, int type)
  1027. {
  1028. ARGB col;
  1029. col.value = *clr;
  1030. if(type == RGBA_ARGB)
  1031. {
  1032. *clr = D3DCOLOR_ARGB(alpha,col.component[2],col.component[1],col.component[0]);
  1033. }
  1034.  
  1035. if(type == RGBA_RGBA)
  1036. {
  1037. *clr = D3DCOLOR_RGBA(col.component[2],col.component[1],col.component[0], alpha);
  1038. }
  1039. }
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045.  
  1046.  
  1047.  
  1048. /*
  1049. void ControlActorCam()//kinda useless right, camera can't be unlocked with cursoron so i'll have to save the last cursor position before right click, then toggle cursor off (continue drawing at the last saved position), loop check "isRMBDepressed", then toggle again and set cursor position
  1050. {
  1051. if (!KeyPressed(VK_RBUTTON) && !allowCameraMove)
  1052. {
  1053. lastCursorX = (float)cursor.x;
  1054. lastCursorY = (float)cursor.y;
  1055. allowCameraMove = true;
  1056.  
  1057. if (g_SAMP == NULL) return;
  1058. if (g_Input->iInputEnabled) return;
  1059.  
  1060.  
  1061. void *obj = *(void **) (SampDLL + SAMP_MISC_INFO);
  1062. ((void(__thiscall *) (void *, int, bool)) (SampDLL + SAMP_FUNC_TOGGLECURSOR))(obj, 3, false); //(obj, 3,false)(obj, 0,true)
  1063. ((void(__thiscall *) (void *)) (SampDLL + SAMP_FUNC_CURSORUNLOCKACTORCAM))(obj);
  1064. }
  1065.  
  1066. if(allowCameraMove && KeyPressed(VK_RBUTTON))
  1067. {
  1068. cursor.x = (int)lastCursorX;
  1069. cursor.y = (int)lastCursorY;
  1070. allowCameraMove=false;
  1071.  
  1072. void *obj = *(void **) (SampDLL + SAMP_MISC_INFO);
  1073. ((void(__thiscall *) (void *, int, bool)) (SampDLL + SAMP_FUNC_TOGGLECURSOR))(obj, 0, true); //(obj, 3,false)(obj, 0,true)
  1074.  
  1075. }
  1076. }
  1077. */
  1078.  
  1079. /*
  1080. if (g_SAMP == NULL) return;
  1081. if (g_Input->iInputEnabled) return;
  1082.  
  1083. isCursorEnabled = iToggle;
  1084.  
  1085. void *obj = *(void **) (SampDLL + SAMP_MISC_INFO);
  1086. ((void(__thiscall *) (void *, int, bool)) (SampDLL + SAMP_FUNC_TOGGLECURSOR))(obj, iToggle ? 3 : 0, !iToggle);
  1087. if (!iToggle)
  1088. ((void(__thiscall *) (void *)) (SampDLL + SAMP_FUNC_CURSORUNLOCKACTORCAM))(obj);
  1089. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement