Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.68 KB | None | 0 0
  1. #include <Windows.h>
  2. #include "plugin.h"
  3. #include <game_sa\CVehicle.h>
  4. #include <game_sa\RenderWare.h>
  5. #include <game_sa\CSprite.h>
  6. #include <game_sa\CFont.h>
  7. #include "VehicleExtender.h"
  8.  
  9. using namespace plugin;
  10.  
  11. class VehicleColor{
  12. public:
  13.     unsigned char red, green, blue;
  14.     VehicleColor(CVehicle *vehicle){
  15.         red = rand() % 255; green = rand() % 255; blue = rand() % 255;
  16.     }
  17. };
  18.  
  19. VehicleExtendedData<VehicleColor> vehicleColorData;
  20.  
  21. RpMaterial *MaterialCallback(RpMaterial *material, VehicleColor *color){
  22.     material->color.red = color->red; material->color.green = color->green; material->color.blue = color->blue;
  23.     return material;
  24. }
  25.  
  26. RpAtomic *AtomicCallback(RpAtomic *atomic, VehicleColor *color){
  27.     if (atomic->geometry)
  28.         RpGeometryForAllMaterials(atomic->geometry, MaterialCallback, color);
  29.     return atomic;
  30. }
  31.  
  32. void OnVehicleRender(CVehicle *vehicle){
  33.     if (vehicle->m_pRwObject && vehicle->m_pRwObject->type == rpCLUMP)
  34.         RpClumpForAllAtomics(reinterpret_cast<RpClump*>(vehicle->m_pRwObject), AtomicCallback, vehicleColorData.Get(vehicle));
  35. }
  36.  
  37. void OnScreenDrawing()
  38. {
  39.     for (int i = 0; i < CPools::ms_pVehiclePool->m_Size; i++)
  40.     {
  41.         if (!CPools::ms_pVehiclePool->IsFreeSlotAtIndex(i))
  42.         {
  43.             CVehicle *vehicle = reinterpret_cast<CVehicle *>(&CPools::ms_pVehiclePool->m_Objects[i]);
  44.             CVector &posn = vehicle->m_pCoords ? vehicle->m_pCoords->pos : vehicle->m_Placement.m_vPosn;
  45.             RwV3d rwp = { posn.x, posn.y, posn.z + 1.0f };
  46.             RwV3d screenCoors; float w, h;
  47.             if (CSprite::CalcScreenCoors(rwp, &screenCoors, &w, &h, true, true))
  48.             {
  49.                 CFont::SetAlignment(ALIGN_CENTER);
  50.                 CFont::SetColor(CRGBA(vehicleColorData.Get(vehicle)->red, vehicleColorData.Get(vehicle)->green, vehicleColorData.Get(vehicle)->blue, 255));
  51.                 CFont::SetOutlinePosition(1);
  52.                 CFont::SetBackground(false, false);
  53.                 CFont::SetWrapx(500.0);
  54.                 CFont::SetScale(0.5, 1.0);
  55.                 CFont::SetFontStyle(FONT_SUBTITLES);
  56.                 CFont::SetProp(true);
  57.                 char text[16];
  58.                 sprintf(text, "%d %d %d", vehicleColorData.Get(vehicle)->red, vehicleColorData.Get(vehicle)->green, vehicleColorData.Get(vehicle)->blue);
  59.                 CFont::PrintString(screenCoors.x, screenCoors.y, text);
  60.             }
  61.            
  62.         }
  63.     }
  64. }
  65.  
  66. BOOL APIENTRY DllMain(HMODULE module, DWORD reason, LPVOID reserved){
  67.     if (reason == DLL_PROCESS_ATTACH){
  68.         Events::drawingEvent += OnScreenDrawing;
  69.         Events::vehicleRenderEvent += OnVehicleRender;
  70.     }
  71.     return TRUE;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement