Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Relevant parts:
- Calling the function:
- //////////////
- playerElement[elementID].SetPlayerElement(x, (y-graphsSizeY/2.0f), (wepX+((float)weapon.width/2.0f)), (y+graphsSizeY/2.0f), i, elementID);
- elementID++;
- //////////////
- Linking:
- //////////////
- #include "C_cursor.h" //this is the problematic class
- //////////////
- */
- #include "stdafx.h"
- #include "Csprite.h"
- #include "Cplayers.h"
- #include "Ctimer.h"
- #include "dllmain.h"
- #include "Cdynamic_graph.h"
- #include "C_cursor.h"
- #include <fstream>
- #include <tuple>
- #include <math.h>
- Sprites sir;
- Sprites icon;
- Sprites grid1;
- Sprites frame;//main frame for grid
- Sprites frame2;//small long for shooting state
- Sprites frame3;//small short for id of damagers
- Sprites frameID;
- Sprites cursorNoClick;
- Sprites cursorClick;
- Sprites cursorRotate;
- Sprites weapon(MAX_WEAPON);
- Sprites skin(MAX_SKIN);
- Sprites vincent(100);
- Sprites bellsprout(11);
- Sprites pulseButton(15);
- Sprites adjArrow;
- Sprites ruler;
- float graphsSizeY = 70.0f;
- int graphsSizeX = 299;
- int lastCursorX=NULL;
- int lastCursorY=NULL;
- bool showNames = true;
- //void DrawPersonalizedTextures();
- //void DrawAllPersonalizedTextures();
- void DrawPersonalizedGraph(int persID, float x, float y, int allignType, int playerID);
- //void DrawOnRadar(int);
- float GetSpeedMultiplier();
- void DrawWeapon(float x, float y, float sizeMult, int playerID);
- void DrawSkin(float x, float y, float sizeMult, int playerID);
- XY PlayerToRadarXY(int, float, float);//XYZ DISTANCE_MULTIPLIER MAX_DISTANCE
- tuple<float, float> Positioning(float x, float y, bool notStream);//for drawing all textures
- void ImageDimensionsAdjustment(int* x, int* y, int sizeLimit);
- Sprites personalized;
- short personalizedID[MAX_PERSONALIZED];
- string personalName[MAX_PERSONALIZED];
- int personalizedWidth[MAX_PERSONALIZED];
- int personalizedHeight[MAX_PERSONALIZED];
- int personalizedCount=NULL;//to know how many names+textures are saved
- float divider=100.0f; //needed to adjust the value
- union ARGB
- {
- DWORD value;
- unsigned char component[4];
- };
- Sprites::Sprites()
- {
- pos.x = 1.0f;
- pos.y = 1.0f;
- pos.z = 1.0f;
- spos.x = 1.0f;
- spos.y = 1.0f;
- spos.z = 1.0f;
- scaleVal.x = 1.0f;
- scaleVal.y = 1.0f;
- scaleVal.z = 1.0f;
- pulse = 1.0f;
- color = D3DCOLOR_ARGB(255,255,255,255);
- initialized = false;
- width = 1;
- height = 1;
- sprite = NULL;
- tex = NULL;
- }
- Sprites::Sprites(int frame_number) //gif
- {
- pos.x = 1.0f;
- pos.y = 1.0f;
- pos.z = 1.0f;
- spos.x = 1.0f;
- spos.y = 1.0f;
- spos.z = 1.0f;
- scaleVal.x = 1.0f;
- scaleVal.y = 1.0f;
- scaleVal.z = 1.0f;
- pulse = 1.0f;
- color = D3DCOLOR_ARGB(255,255,255,255);
- initialized = false;
- width = 1;
- height = 1;
- sprite = NULL;
- tex = NULL;
- frameCount = frame_number;
- noLoopCheck = NULL;
- nextFrame = 1;
- currentFrame = 0;
- }
- bool Sprites::Initialize(LPDIRECT3DDEVICE9 device, string file, int w, int h)
- {
- width = w;
- height = h;
- //same functionality as D3DXCreateTextureFromFile
- if(!SUCCEEDED(D3DXCreateTextureFromFileEx(device, file.c_str(), width, height, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
- D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &tex)))
- {
- string s = "There was an issue creating texture. Make sure the requested image is available. Requested image: " + file;
- MessageBox(NULL, s.c_str(), NULL, NULL);
- return false;
- }
- //Attempt to create the sprite
- if(!SUCCEEDED(D3DXCreateSprite(device, &sprite)))
- {
- MessageBox(NULL, "There was an issue creating the sprite.",NULL,NULL);
- return false;
- }
- initialized = true;
- return true;
- }
- bool Sprites::InitializeGif(LPDIRECT3DDEVICE9 device, string filename1, string filename2, int w, int h)
- {
- width = w;
- height = h;
- stringstream sso;
- string s;
- LPCSTR path;
- int i=0;
- while(i < frameCount)
- {
- sso.clear();
- sso.str(string());
- sso << filename1 << i<< filename2;
- s = sso.str();
- path = s.c_str();
- if(!SUCCEEDED(D3DXCreateTextureFromFileEx(device, path, width, height, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
- D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &frameTex[i])))
- {
- string s = "There was an issue creating texture. Make sure the requested image is available. Requested image: " + s;
- MessageBox(NULL, s.c_str(), NULL, NULL);
- return false;
- }
- i++;
- }
- if(!SUCCEEDED(D3DXCreateSprite(device, &sprite)))
- {
- MessageBox(NULL, "There was an issue creating the sprite.",NULL,NULL);
- return false;
- }
- initialized = true;
- return true;
- }
- bool Sprites::InitializePersonalizedTextures(LPDIRECT3DDEVICE9 device, int sizeLimit)
- {
- int x=0;
- int y=0;
- stringstream sso;
- string s;
- system("dir images\\personalized /b *.png > images/personalized/self_updating_list.txt");//update list of personalised sprites
- HWND hWnd = ::FindWindow(NULL, "GTA:SA:MP");
- if (hWnd)
- {
- // move to foreground
- ::SetForegroundWindow(hWnd);
- }
- string line;
- ifstream file("images/personalized/self_updating_list.txt");
- int i=0;
- while(getline(file,line))
- {
- if(line.compare("self_updating_list.txt") != 0 && line.compare("mouse.png") != 0 && line.compare("sampgui.png") != 0)
- {
- personalName[i] = line.substr(0, line.size()-4); //get the name to compare it later (removes ".png" at the end)
- sso.clear();sso.str(string());sso << "images/personalized/" << line;s = sso.str();//empties the string and fills again
- if(GetImageSize(s.c_str(), &x, &y))
- {
- //image dimensions adjustment
- ImageDimensionsAdjustment(&x, &y, sizeLimit);//to make sure that the longest dimension is always 512 and the other is relatively smaller
- personalizedWidth[i] = x;
- personalizedHeight[i] = y;
- if(!SUCCEEDED(D3DXCreateTextureFromFileEx(device, s.c_str(), x, y, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
- D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &frameTex[i])))
- {
- string s = "There was an issue creating texture. Make sure the requested image is available. Requested image: " + s;
- MessageBox(NULL, s.c_str(), NULL, NULL);
- return false;
- }
- }
- i++;
- }
- }
- if(!SUCCEEDED(D3DXCreateSprite(device, &sprite)))
- {
- MessageBox(NULL, "There was an issue creating the sprite.",NULL,NULL);
- return false;
- }
- personalizedCount = i;
- initialized = true;
- return true;
- }
- bool InitializeWeapons(PDIRECT3DDEVICE9 device)
- {
- weapon.width = 103;
- weapon.height = 103;
- stringstream sso;
- int i=0;
- while(i < MAX_WEAPON)
- {
- sso.clear();
- sso.str(string());
- sso << "images/weapons/" << i<< ".png";//
- ifstream fl(sso.str().c_str());if(fl.good()){fl.close();}else{fl.close();weapon.frameTex[i]=NULL;i++;continue;}//if file exists
- if(!SUCCEEDED(D3DXCreateTextureFromFileEx(device, sso.str().c_str(), weapon.width, weapon.height, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
- D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &weapon.frameTex[i])))
- {
- string s = "There was an issue creating texture. Make sure the requested image is available. Requested image: " + sso.str();
- MessageBox(NULL, sso.str().c_str(), NULL, NULL);
- return false;
- }
- i++;
- }
- if(!SUCCEEDED(D3DXCreateSprite(device, &weapon.sprite)))
- {
- MessageBox(NULL, "There was an issue creating the sprite.",NULL,NULL);
- return false;
- }
- weapon.initialized = true;
- return true;
- }
- bool InitializeSkins(PDIRECT3DDEVICE9 device)
- {
- skin.width = 57;
- skin.height = 103;
- stringstream sso;
- int i=0;
- while(i < MAX_SKIN)
- {
- sso.clear();
- sso.str(string());
- sso << "images/skins/" << i<< ".png";//
- ifstream fl(sso.str().c_str());if(fl.good()){fl.close();}else{fl.close();skin.frameTex[i] = NULL; i++;continue;}//if file exists
- if(!SUCCEEDED(D3DXCreateTextureFromFileEx(device, sso.str().c_str(), skin.width, skin.height, D3DX_DEFAULT, 0, D3DFMT_UNKNOWN,
- D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL, &skin.frameTex[i])))
- {
- string s = "There was an issue creating texture. Make sure the requested image is available. Requested image: " + sso.str();
- MessageBox(NULL, sso.str().c_str(), NULL, NULL);
- return false;
- }
- i++;
- }
- if(!SUCCEEDED(D3DXCreateSprite(device, &skin.sprite)))
- {
- MessageBox(NULL, "There was an issue creating the sprite.",NULL,NULL);
- return false;
- }
- skin.initialized = true;
- return true;
- }
- void ImageDimensionsAdjustment(int* x, int* y, int sizeLimit)
- {
- float xf=(float)*x;
- float yf=(float)*y;
- if(xf>yf)
- {
- yf /= xf;
- yf *= (float)sizeLimit;
- xf /= xf;
- xf *= (float)sizeLimit;
- }
- else
- {
- xf /= yf;
- xf *= (float)sizeLimit;
- yf /= yf;
- yf *= (float)sizeLimit;
- }
- *x = (int)xf;
- *y = (int)yf;
- }
- bool Sprites::IsInitialized()
- {
- return initialized;
- }
- void Sprites::SetPosition(float x, float y, float spd, int personalizedID)
- {
- if(personalizedID){width = personalizedWidth[personalizedID]; height = personalizedHeight[personalizedID];}
- if(spd)
- {
- 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;}
- 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;}
- }
- pos.x = x;
- pos.y = y;
- spos.x = (x - width / 2 * scaleVal.x) / scaleVal.x; //scaled position
- spos.y = (y - height / 2 * scaleVal.y) / scaleVal.y; //
- }
- void Sprites::Scale(float x, float y, float z, int personalizedID)
- {
- if(personalizedID){width = personalizedWidth[personalizedID]; height = personalizedHeight[personalizedID];}
- scaleVal.x = x;
- scaleVal.y = y;
- scaleVal.z = z;
- spos.x = (pos.x - width / 2 * scaleVal.x) / scaleVal.x;//pos - original, spos - scaled
- spos.y = (pos.y - height / 2 * scaleVal.y) / scaleVal.y;
- spos.z = pos.z / scaleVal.z;
- D3DXMATRIX matScale;
- //sprite->GetTransform(&matScale);
- D3DXMatrixScaling(&matScale, scaleVal.x, scaleVal.y, scaleVal.z);
- sprite->SetTransform(&matScale);
- }
- void Sprites::Pulse(float range, float spd, int personalizedID)
- {
- if(!speed) //should be done only once
- {
- speed = spd;
- }
- if(pulse < (1.0f * range) && pulse > (1.0f / range))
- {
- pulse *= speed;
- }
- else
- {
- speed = 1.0f / speed;
- pulse *= speed;
- }
- Scale(pulse*scaleVal.x, pulse*scaleVal.y, 1.0f, personalizedID);
- }
- void Sprites::SetColor(int alpha, DWORD c, int type)//0-255
- {
- if(type == CUSTOM_TYPE)
- {
- color = c;
- }
- else
- {
- SetColorAlpha(alpha , &c, type);
- color = c;
- }
- }
- void Sprites::Update()
- {
- //Update logic here
- }
- void Sprites::Draw()
- {
- if(initialized)
- {
- if(sprite && tex)
- {
- sprite->Begin(D3DXSPRITE_ALPHABLEND);
- sprite->Draw(tex, NULL, NULL, &spos, color);
- sprite->End();
- }
- }
- }
- void Sprites::DrawGif(int timerID, int delay, bool reverse)
- {
- if(initialized)
- {
- if(!(currentFrame < GetFrameCount()) || !(currentFrame > -1))
- {
- if(reverse)//forward+reverse
- {
- nextFrame = nextFrame * -1;
- currentFrame += nextFrame;
- }
- else
- {
- nextFrame = 1;
- currentFrame = 0;
- }
- }
- if(sprite && frameTex[currentFrame])
- {
- sprite->Begin(D3DXSPRITE_ALPHABLEND);
- sprite->Draw(frameTex[currentFrame], NULL, NULL, &spos, color);
- sprite->End();
- if(!delay){currentFrame += nextFrame;}else if(timer.set(timerID,delay)){currentFrame += nextFrame;}
- }
- }
- }
- void Sprites::DrawGifFrame(int frameNumber)
- {
- if(initialized)
- {
- if(sprite && frameTex[frameNumber])
- {
- sprite->Begin(D3DXSPRITE_ALPHABLEND);
- sprite->Draw(frameTex[frameNumber], NULL, NULL, &spos, color);
- sprite->End();
- }
- }
- }
- void Sprites::SetCurrentFrame(int i)
- {
- currentFrame = i;
- }
- Sprites::~Sprites()
- {
- if(sprite)
- {
- sprite->Release();
- sprite = 0;
- }
- if(tex)
- {
- tex->Release();
- tex = 0;
- }
- }
- int Sprites::GetFrameCount()
- {
- return frameCount;
- }
- void DrawPersonalizedTextures()
- {
- if(personalized.initialized)
- {
- personalized.sprite->Begin(D3DXSPRITE_ALPHABLEND);
- int i=0;
- while(i < personalizedCount)
- {
- if(!(player[personalizedID[i]].IsOnline())){personalizedID[i]=1005; i++; continue;}//reset if not online
- if(player[personalizedID[i]].IsStreamed())
- {
- DrawOnRadar(i, NULL);
- if(player[personalizedID[i]].IsOnScreen())//
- {
- tuple<float, float> result = player[personalizedID[i]].GetScreenPos();
- 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)
- float dist = GetDistanceBetween2Players(1004,personalizedID[i], true);
- personalized.SetPosition(get<0>(result) + adjuster, get<1>(result) - personalizedHeight[i]*4.0f/dist - 50.0f, NULL, i);// x,y,spd,personalizedID
- if(dist > 60.0f){dist = 60.0f;}else{if(dist < 10.0f){dist = 10.0f;}}//to limit how big/small the texture can be
- personalized.Scale(4.0f/dist, 4.0f/dist, 1.0f, i);
- //personalized.Pulse(1.05f, 1.02f, i);
- if(personalized.sprite && personalized.frameTex[i])
- {
- personalized.sprite->Draw(personalized.frameTex[i], NULL, NULL, &personalized.spos, personalized.color);
- }
- }
- }
- i++;
- }
- personalized.sprite->End();
- }
- }
- void DrawOnRadar(int persID, int playerID)
- {
- if(!playerID)
- {
- XY radarPos = PlayerToRadarXY(personalizedID[persID], GetSpeedMultiplier(), 130.0f);
- personalized.SetPosition(radarPos.x , radarPos.y, NULL, persID);
- personalized.Scale(0.075f, 0.075f, 1.0f, persID);
- if(personalized.sprite && personalized.frameTex[persID])
- {
- personalized.sprite->Draw(personalized.frameTex[persID], NULL, NULL, &personalized.spos, personalized.color);
- }
- }
- else
- {
- XY radarPos = PlayerToRadarXY(playerID, GetSpeedMultiplier(), 130.0f);
- RECT rect = { (int)radarPos.x, (int)radarPos.y, (int)radarPos.x, (int)radarPos.y};
- stringstream sso;
- sso << playerID;
- pFont->DrawTextA(NULL, sso.str().c_str(), -1, &rect, DT_CENTER | DT_VCENTER | DT_NOCLIP, player[playerID].GetColor());
- }
- }
- XY PlayerToRadarXY(int playerID, float mult, float maxDist)////XYZ DISTANCE_MULTIPLIER MAX_DISTANCE
- {
- XYZ p = player[1004].GetPos();
- XYZ p2 = player[playerID].GetPos();
- if(!radarPosX)
- {
- radarPosX = resolutionX * 0.1333333f;// ?? not sure, it may be absolute
- radarPosY = resolutionY * 0.85333333f;// 0.85523809f ?? 0B60: convert_game_screen_coords 86.0 383.0 to_window_screen_coords 6@ 7@
- }
- //log << "CameraX=" << 4*(asin(GetCameraXAngle()) *180.0f/PI);
- //log << " radarX=" << radarPosX;
- //log << " radarY=" << radarPosY;
- //log << " dist=" << dist;
- //log << " mult=" << mult;
- //log << " angle1=" << angle;
- //log << " angle+camera=" << angle;
- //log << " rpos.x1=" << rPos.x;
- //log << " rpos.y1=" << rPos.y;
- float dist = GetDistanceBetween2Players(1004, playerID, false);
- if(dist>maxDist){dist = maxDist;}
- dist *= mult * resolutionY / resolutionX;//0.625 just to decrease distance
- float angle = GetCameraXAngle() - GetAngleBetween2Players(1004, playerID);
- angle -= 180.0f;
- if(angle < 0.0f){angle += 360.0f;}
- //if(angle < 0.0f){angle += 360.0f;}
- //angle = angle - 180.0f;
- //if(angle < 0.0f){angle += 360.0f;}
- //if(angle > 360){angle -= 360;}
- //if(angle < 360){angle += 360;}
- XY rPos;
- //x adjustment
- //angle *= -1.0f;
- rPos.x = sinf(angle*PI/180);
- rPos.x *= dist;
- rPos.x += radarPosX;
- //y adjustment
- rPos.y = cosf(angle*PI/180);
- rPos.y *= dist * resolutionY / resolutionX;
- rPos.y += radarPosY;
- return rPos;
- }
- float GetSpeedMultiplier()
- {
- float mySpeed = player[1004].GetSpeed();
- if(mySpeed > 50.0f)
- {
- mySpeed = 50.0f;
- }
- mySpeed *= mySpeed;
- return (float)((-0.514f/2500.0f * mySpeed) + 1.0f);
- /*
- if 0021: 21@ > 50.0
- then
- 21@ = 50.0
- end
- 006B: 21@ *= 21@
- 17@ = -0.514
- 0017: 17@ /= 2500.0
- 006B: 17@ *= 21@
- 000B: 17@ += 1.0
- */
- }
- void DrawAllPersonalizedTextures()//player[personalizedID[i]].GetName();
- {
- float x=(horizontalOffset?horizontalOffset:60.0f);
- float y=(lowerThreshold?lowerThreshold:270.0f);//make it relative
- float scale = 0.08f * graphsSizeY/70.0f;//clickable cursor elements size must rely on this
- float yMult = graphsSizeY/70.0f;
- float xMult = (float)graphsSizeX/299.0f ;//299.0f
- if(personalized.initialized)
- {
- personalized.sprite->Begin(D3DXSPRITE_ALPHABLEND);
- int i=0;
- while(i < personalizedCount)
- {
- if(personalizedID[i]==1005){i++; continue;}
- personalized.SetPosition( x, y , NULL, i); //personalized.Scale(scale, scale, 1.0f, i);
- if(personalized.sprite && personalized.frameTex[i])
- {
- if(player[personalizedID[i]].IsStreamed() || player[personalizedID[i]].IsWasted())//(isPersonalizedStreamedIn[i])
- {
- personalized.Scale(scale*2.1f, scale*2.1f, 1.0f, i);
- //here I could add some effects if low hp/armor like pulsating or turning red, or effect based on shooting
- personalized.sprite->Draw(personalized.frameTex[i], NULL, NULL, &personalized.spos, D3DCOLOR_ARGB(255,255,255,255));
- //draw graphs only for streamed in players
- //x+= 20.0f * graphsSizeX/299.0f;
- float graphX = x+(37.5f*yMult);
- DrawPersonalizedGraph(i, graphX, y, GRAPH_LEFT_CENTER_Y, NULL);
- if(showNames && pFont)
- {
- //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;
- RECT rect = { (int)graphX, (int)y, (int)(graphX + (87.0f*yMult)), (int)y};
- stringstream sso;
- sso <<personalizedID[i];
- pFont->DrawTextA(NULL, sso.str().c_str(), -1, &rect, DT_CENTER | DT_VCENTER | DT_NOCLIP, player[personalizedID[i]].GetColor());
- }
- float skinX = x + (float)graphsSizeX + (80.0f*yMult) + (87.0f * yMult); // + (40.0f * xMult)
- DrawSkin(skinX, y, yMult*1.2f, personalizedID[i]);
- //draw weapon
- float wepX = skinX + (100.0f*yMult);
- DrawWeapon(wepX, y, yMult, personalizedID[i]);
- //when drawings are done change position
- tuple<float, float> result = Positioning(x, y, false);x = get<0>(result);y = get<1>(result);//change position
- }
- /*
- else if(player[personalizedID[i]].IsOnline())
- {
- personalized.sprite->Draw(personalized.frameTex[i], NULL, NULL, &personalized.spos, D3DCOLOR_ARGB(150,100,100,100));
- tuple<float, float> result = Positioning(x, y);x = get<0>(result);y = get<1>(result);//change position
- }
- */
- //else //if offline
- //{
- // personalized.sprite->Draw(personalized.frameTex[i], NULL, NULL, &personalized.spos, D3DCOLOR_ARGB(120,50,50,50));//if offline
- //}
- i++;
- }
- }
- x=(horizontalOffset?horizontalOffset:60.0f);
- i=0;
- while(i < personalizedCount)
- {
- if(personalizedID[i]==1005){i++; continue;}
- personalized.SetPosition( x, y , NULL, i); personalized.Scale(scale* 1.4f, scale * 1.4f, 1.0f, i);
- if(personalized.sprite && personalized.frameTex[i])
- {
- if(player[personalizedID[i]].IsStreamed() || player[personalizedID[i]].IsWasted())//(isPersonalizedStreamedIn[i])
- {
- }
- else if(player[personalizedID[i]].IsOnline())
- {
- personalized.sprite->Draw(personalized.frameTex[i], NULL, NULL, &personalized.spos, D3DCOLOR_ARGB(150,100,100,100));
- if(showNames && pFont)
- {
- 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;
- stringstream sso;
- sso << personalizedID[i];
- pFont->DrawTextA(NULL, sso.str().c_str(), -1, &rect, DT_CENTER | DT_VCENTER | DT_NOCLIP, player[personalizedID[i]].GetColor());
- }
- //at the end
- tuple<float, float> result = Positioning(x, y, true);x = get<0>(result);y = get<1>(result);//change position
- }
- i++;
- }
- }
- personalized.sprite->End();
- }
- if(timer.set(11,50))//this could be in sampThread instead of direct present hook
- {
- for(int i=0;i<personalizedCount;i++)
- {
- if(personalizedID[i]==1005){continue;}
- //int hp = (int)((player[personalizedID[i]].GetHp() + player[personalizedID[i]].GetArmor()) / 200.0f * 40.0f);
- if(player[personalizedID[i]].IsWasted())
- {
- personalizedGraph[i].addNewVal(WASTED_STATE, DATA_LINE_HP, false);
- personalizedGraph[i].addNewVal(WASTED_STATE, DATA_LINE_ARMOR, false);
- personalizedGraph[i].addNewVal(WASTED_STATE, DATA_LINE_SHOOTING_STATE, false);
- }
- else
- {
- int hp = (int)(player[personalizedID[i]].GetHp() / 100.0f * graphsSizeY);
- personalizedGraph[i].addNewVal(hp, DATA_LINE_HP, false);
- int armor = (int)(player[personalizedID[i]].GetArmor() / 100.0f * graphsSizeY);
- personalizedGraph[i].addNewVal(armor, DATA_LINE_ARMOR, false);
- personalizedGraph[i].addNewVal(player[personalizedID[i]].GetShootingState(), DATA_LINE_SHOOTING_STATE, false);
- }
- /*
- if(player[personalizedID[i]].IsStreamed())
- {
- //(timer.set(15,1000))
- //{
- //personalizedGraph[i].addNewVal(rand()%300, DATA_LINE_CAUSED_DAMAGE, false);
- //}else{personalizedGraph[i].addNewVal(NOT_DAMAGED, DATA_LINE_CAUSED_DAMAGE, false);}
- //ofstream log("logfile.txt", ios_base::app | ios_base::out);
- //log << "working";
- }
- */
- if(player[personalizedID[i]].CausedDamage())
- {
- personalizedGraph[i].addNewVal(player[personalizedID[i]].GetLastMyShotReceiverID(0), DATA_LINE_CAUSED_DAMAGE, false);
- }
- else{personalizedGraph[i].addNewVal(NOT_DAMAGED, DATA_LINE_CAUSED_DAMAGE, false);}
- if(player[personalizedID[i]].WasDamaged())
- {
- personalizedGraph[i].addNewVal(player[personalizedID[i]].GetLastDamagerID(0), DATA_LINE_GOT_HIT, false);
- }
- else{personalizedGraph[i].addNewVal(NOT_DAMAGED, DATA_LINE_GOT_HIT, false);}
- }
- for(int i=0; i<SAMP_MAX_PLAYERS;i++)
- {
- if(player[i==myID?1004:i].damagerToBeResetted)
- {
- player[i==myID?1004:i].damagerToBeResetted = false;
- player[i==myID?1004:i].ResetLastHit();
- }
- }
- }
- }
- void DrawStreamedPlayersData()// need to add a check to disable drawing if the player is included as personalized
- {
- int elementID=0;
- float x=(horizontalOffset?horizontalOffset:60.0f);//make it relative (or semi-relative because samp chat is absolute)
- float y= (lowerThreshold?lowerThreshold:270.0f);//think about making it adjustable in settings
- float scale = 0.08f * graphsSizeY/70.0f;//clickable cursor elements size must rely on this
- float yMult = graphsSizeY/70.0f;
- float xMult = (float)graphsSizeX/299.0f ;//299.0f
- int i=0;
- while(i < SAMP_MAX_PLAYERS)
- {
- if(player[i].IsStreamed() || player[i].IsWasted())//(isPersonalizedStreamedIn[i])
- {
- //draw graphs only for streamed in players
- //x+= 20.0f * graphsSizeX/299.0f;
- DrawSkin(x, y, yMult*1.2f, i);
- float graphX = x + (37.5f*yMult);
- DrawPersonalizedGraph(i, graphX, y, GRAPH_LEFT_CENTER_Y, i);
- if(pFont)
- {
- 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;
- stringstream sso;
- sso <<i;
- pFont->DrawTextA(NULL, sso.str().c_str(), -1, &rect, DT_CENTER | DT_VCENTER | DT_NOCLIP, player[i].GetColor());
- if(namesOnOff)
- {
- sso.clear();
- sso.str(string());
- sso << player[i].GetName();
- rect.left = (int)x;
- rect.right = rect.left;
- rect.top = (int)y - (int)(yMult*graphsSizeY/2.0f) - 38;
- rect.bottom = rect.top;
- pFont->DrawTextA(NULL, sso.str().c_str(), -1, &rect, DT_LEFT | DT_NOCLIP, player[i].GetColor());
- }
- }
- //draw weapon
- float wepX = graphX + (float)graphsSizeX + (75.0f*yMult) + (87.0f * yMult);//(int)(87.0f * yMult) to add frameID
- DrawWeapon(wepX, y, yMult, i);
- playerElement[elementID].SetPlayerElement(x, (y-graphsSizeY/2.0f), (wepX+((float)weapon.width/2.0f)), (y+graphsSizeY/2.0f), i, elementID);
- elementID++;
- DrawOnRadar(NULL, i);
- //when drawings are done change position
- if(namesOnOff)
- {
- y += 38.0f;
- }
- tuple<float, float> result = Positioning(x, y, false);x = get<0>(result);y = get<1>(result);//change position
- }
- i++;
- }
- //reset all the unused playerElements
- for(int k=elementID;k<MAX_PLAYER_ELEMENTS;k++)
- {
- playerElement[k].SetPlayerElement(0.1f,0.1f,0.1f,0.1f, INVALID_ELEMENT, k);
- }
- if(timer.set(11,50))//this could be in sampThread instead of direct present hook
- {
- for(int i=0;i<SAMP_MAX_PLAYERS;i++)
- {
- if(!player[i].IsOnline()){continue;}
- if(!player[i].IsStreamed() && !player[i].IsWasted()){continue;}
- if(player[i].IsWasted())
- {
- personalizedGraph[i].addNewVal(WASTED_STATE, DATA_LINE_HP, false);
- personalizedGraph[i].addNewVal(WASTED_STATE, DATA_LINE_ARMOR, false);
- personalizedGraph[i].addNewVal(WASTED_STATE, DATA_LINE_SHOOTING_STATE, false);
- }
- else
- {
- int hp = (int)(player[i].GetHp() / 100.0f * graphsSizeY);
- personalizedGraph[i].addNewVal(hp, DATA_LINE_HP, false);
- int armor = (int)(player[i].GetArmor() / 100.0f * graphsSizeY);
- personalizedGraph[i].addNewVal(armor, DATA_LINE_ARMOR, false);
- personalizedGraph[i].addNewVal(player[i].GetShootingState(), DATA_LINE_SHOOTING_STATE, false);
- }
- if(player[i].WasDamaged())
- {
- personalizedGraph[i].addNewVal(player[i].GetLastDamagerID(0), DATA_LINE_GOT_HIT, false);
- }
- else{personalizedGraph[i].addNewVal(NOT_DAMAGED, DATA_LINE_GOT_HIT, false);}
- if(player[i].CausedDamage())
- {
- personalizedGraph[i].addNewVal(player[i].GetLastMyShotReceiverID(0), DATA_LINE_CAUSED_DAMAGE, false);
- }
- else{personalizedGraph[i].addNewVal(NOT_DAMAGED, DATA_LINE_CAUSED_DAMAGE, false);}
- }
- for(int i=0; i<SAMP_MAX_PLAYERS;i++)
- {
- if(player[i==myID?1004:i].damagerToBeResetted)
- {
- player[i==myID?1004:i].damagerToBeResetted = false;
- player[i==myID?1004:i].ResetLastHit();
- }
- }
- }
- }
- void DrawSkin(float x, float y, float sizeMult, int playerID)//add switch in menu for this
- {
- if(skin.IsInitialized())
- {
- int skinID = player[playerID].GetSkin();
- if(skinID >= 0 && skinID < 300)
- {
- if(skin.sprite && skin.frameTex[skinID])
- {
- skin.sprite->Begin(D3DXSPRITE_ALPHABLEND);
- skin.SetPosition(x,y,NULL,NULL);
- skin.Scale(sizeMult,sizeMult,1.0f, NULL);
- skin.sprite->Draw(skin.frameTex[skinID], NULL, NULL, &skin.spos, D3DCOLOR_RGBA(255, 255, 255, 255));
- skin.sprite->End();
- }
- }
- }
- }
- void DrawWeapon(float x, float y, float sizeMult, int playerID)
- {
- if(weapon.IsInitialized())
- {
- int wepID = NULL;
- if(!player[playerID].IsDriving())
- {
- wepID = player[playerID].GetWeapon();
- }
- else
- {
- wepID = 47;
- }
- if(wepID >= 0 && wepID < 48)
- {
- if(weapon.sprite && weapon.frameTex[wepID])
- {
- weapon.sprite->Begin(D3DXSPRITE_ALPHABLEND);
- weapon.SetPosition(x,y,NULL,NULL);
- weapon.Scale(sizeMult,sizeMult,1.0f, NULL);
- weapon.sprite->Draw(weapon.frameTex[wepID], NULL, NULL, &weapon.spos, D3DCOLOR_RGBA(255, 255, 255, 255));//wepID == 47?player[playerID].GetColor():
- weapon.sprite->End();
- }
- }
- }
- }
- void DrawPersonalizedGraph(int persID, float x, float y, int allign, int playerID)
- {
- int i=NULL;
- if(!playerID)
- {
- i = personalizedID[persID];
- }
- else
- {
- i = playerID;
- }
- personalizedGraph[!playerID?persID:playerID].setParams((int)(x), (int)(y),graphsSizeX,1, (int)graphsSizeY);//object of dynamic_graph class
- personalizedGraph[!playerID?persID:playerID].Draw(d3device, allign, true, player[i].GetColor(), DATA_LINE_CAUSED_DAMAGE, false);
- personalizedGraph[!playerID?persID:playerID].Draw(d3device, allign, true, player[i].GetColor(), DATA_LINE_GOT_HIT, false);
- if (player[personalizedID[!playerID?persID:playerID]].GetHp() < player[personalizedID[persID]].GetArmor())
- {
- personalizedGraph[!playerID?persID:playerID].Draw(d3device, allign, true, player[i].GetColor(), DATA_LINE_ARMOR, BOXSTATE_FIRST);
- personalizedGraph[!playerID?persID:playerID].Draw(d3device, allign, true, player[i].GetColor(), DATA_LINE_HP, BOXSTATE_LAST);
- }
- else
- {
- personalizedGraph[!playerID?persID:playerID].Draw(d3device, allign, true, player[i].GetColor(), DATA_LINE_HP, BOXSTATE_FIRST);
- personalizedGraph[!playerID?persID:playerID].Draw(d3device, allign, true, player[i].GetColor(), DATA_LINE_ARMOR, BOXSTATE_LAST);
- }
- personalizedGraph[!playerID?persID:playerID].Draw(d3device, allign, true, player[i].GetColor(), DATA_LINE_SHOOTING_STATE, false);
- }
- tuple<float, float> Positioning(float x, float y, bool notStream)//make it relative
- {
- float yMult = graphsSizeY / 70.0f;
- if(notStream)
- {
- x += graphsSizeY;
- if(x > (float)graphsSizeX + (75.0f * yMult))
- {
- x = (horizontalOffset?horizontalOffset:60.0f);
- y += graphsSizeY;
- if(y > (upperThreshold?upperThreshold:(resolutionY - 250.0)))//was 800.0f
- {
- y = (lowerThreshold?lowerThreshold:270.0f);//was 270.0f
- x += (float)graphsSizeX + (160.0f * yMult);//additional check if mode == MODE_PERSONALIZED or MODE_STREAMED (streamed take less space -55.0f)
- }
- }
- }
- else
- {
- y += 70.0f + (80.0f * yMult);
- if(y > (upperThreshold?upperThreshold:(resolutionY - 250.0)))//was 800.0f
- {
- y = (lowerThreshold?lowerThreshold:270.0f);//was 270.0f
- x += (float)graphsSizeX + ((!streamedOnOff?402.0f:322.0f) * yMult);//was 315.0f:235.0f), +(87.0f * yMult) to add frameID
- }
- }
- return make_tuple(x,y);
- }
- void DrawCursor()
- {
- if(allowCameraMove)
- {
- cursorRotate.SetPosition((float)lastCursorX, (float)lastCursorY, NULL, NULL);
- cursorRotate.Draw();
- }
- else if(isCursorEnabled)
- {
- GetCursorPos(&cursor);
- if(KeyPressed(VK_LBUTTON))
- {
- cursorClick.SetPosition((float)cursor.x, (float)cursor.y, NULL, NULL);
- cursorClick.Draw();
- }
- else
- {
- cursorNoClick.SetPosition((float)cursor.x, (float)cursor.y, NULL, NULL);
- cursorNoClick.Draw();
- }
- }
- }
- void SetColorAlpha(int alpha, DWORD* clr, int type)
- {
- ARGB col;
- col.value = *clr;
- if(type == RGBA_ARGB)
- {
- *clr = D3DCOLOR_ARGB(alpha,col.component[2],col.component[1],col.component[0]);
- }
- if(type == RGBA_RGBA)
- {
- *clr = D3DCOLOR_RGBA(col.component[2],col.component[1],col.component[0], alpha);
- }
- }
- /*
- 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
- {
- if (!KeyPressed(VK_RBUTTON) && !allowCameraMove)
- {
- lastCursorX = (float)cursor.x;
- lastCursorY = (float)cursor.y;
- allowCameraMove = true;
- if (g_SAMP == NULL) return;
- if (g_Input->iInputEnabled) return;
- void *obj = *(void **) (SampDLL + SAMP_MISC_INFO);
- ((void(__thiscall *) (void *, int, bool)) (SampDLL + SAMP_FUNC_TOGGLECURSOR))(obj, 3, false); //(obj, 3,false)(obj, 0,true)
- ((void(__thiscall *) (void *)) (SampDLL + SAMP_FUNC_CURSORUNLOCKACTORCAM))(obj);
- }
- if(allowCameraMove && KeyPressed(VK_RBUTTON))
- {
- cursor.x = (int)lastCursorX;
- cursor.y = (int)lastCursorY;
- allowCameraMove=false;
- void *obj = *(void **) (SampDLL + SAMP_MISC_INFO);
- ((void(__thiscall *) (void *, int, bool)) (SampDLL + SAMP_FUNC_TOGGLECURSOR))(obj, 0, true); //(obj, 3,false)(obj, 0,true)
- }
- }
- */
- /*
- if (g_SAMP == NULL) return;
- if (g_Input->iInputEnabled) return;
- isCursorEnabled = iToggle;
- void *obj = *(void **) (SampDLL + SAMP_MISC_INFO);
- ((void(__thiscall *) (void *, int, bool)) (SampDLL + SAMP_FUNC_TOGGLECURSOR))(obj, iToggle ? 3 : 0, !iToggle);
- if (!iToggle)
- ((void(__thiscall *) (void *)) (SampDLL + SAMP_FUNC_CURSORUNLOCKACTORCAM))(obj);
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement