hlsdk

LOL PROC

Dec 31st, 2010
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.83 KB | None | 0 0
  1. #include "..\Interfaces.h"
  2. #include "..\..\NewNetvar.h"
  3. #include "TexGen.h"
  4. #include <convar.h>
  5.  
  6. int team = 0;
  7. int health = 0;
  8. void CProceduralRegenerator::RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect )
  9. {
  10.     CPixelWriter pixelWriter;
  11.     pixelWriter.SetPixelMemory( pVTFTexture->Format(),
  12.         pVTFTexture->ImageData( 0, 0, 0 ), pVTFTexture->RowSizeInBytes( 0 ) );
  13.  
  14.     // Now upload the part we've been asked for
  15.     int xmax = pSubRect->x + pSubRect->width;
  16.     int ymax = pSubRect->y + pSubRect->height;
  17.     int x, y;
  18.    
  19.     int tt = ConVarRef("ms_chams_color_team", false).GetInt();
  20.     float hh = ConVarRef("ms_chams_color_health", false).GetFloat();
  21.  
  22.     for( y = pSubRect->y; y < ymax; ++y )
  23.     {
  24.         pixelWriter.Seek( pSubRect->x, y );
  25.  
  26.         for( x=pSubRect->x; x < xmax; ++x )
  27.         {
  28.             if (team == 3)//blue
  29.                 pixelWriter.WritePixel( 255-tt, hh * health, tt, 255 );
  30.             else
  31.                 pixelWriter.WritePixel( tt, hh * health, 255-tt, 255 );
  32.         }
  33.     }
  34. }
  35.  
  36. void CProceduralRegenerator::Release()
  37. {
  38.     //delete stuff
  39. }
  40. CProceduralProxy::CProceduralProxy()
  41. {
  42.     m_pTextureVar = NULL;
  43.     m_pTexture = NULL;
  44.     m_pTextureRegen = NULL;
  45. }
  46. CProceduralProxy::~CProceduralProxy()
  47. {
  48.     if (m_pTexture != NULL)
  49.     {
  50.         m_pTexture->SetTextureRegenerator( NULL );
  51.     }
  52. }
  53.  
  54. IMaterial* CProceduralProxy::GetMaterial()
  55. {
  56.     return m_pTextureVar->GetOwningMaterial();
  57. }
  58.  
  59. bool CProceduralProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  60. {
  61.     bool found;
  62.    
  63.     m_pTextureVar = pMaterial->FindVar("$basetexture", &found, false);  // Get a reference to our base texture variable
  64.     if( !found )
  65.     {
  66.         m_pTextureVar = NULL;
  67.         return false;
  68.     }
  69.  
  70.     m_pTexture = m_pTextureVar->GetTextureValue();  // Now grab a ref to the actual texture
  71.     if (m_pTexture != NULL)
  72.     {
  73.         m_pTextureRegen = new CProceduralRegenerator( );  // Here we create our regenerator
  74.         m_pTexture->SetTextureRegenerator(m_pTextureRegen); // And here we attach it to the texture.
  75.     }
  76.  
  77.     return true;
  78. }
  79.  
  80. void CProceduralProxy::OnBind( void *pEntity )
  81. {
  82.     if( !m_pTexture )  // Make sure we have a texture
  83.         return;
  84.  
  85.     if(!m_pTextureVar->IsTexture() || !m_pTexture->IsProcedural())  // Make sure it is a texture
  86.         return;
  87.    
  88.     const char* debugName = m_pTexture->GetName();
  89.  
  90.     IClientRenderable* pRender = (IClientRenderable*)pEntity;
  91.     if (pRender && pRender->GetIClientUnknown()->GetIClientEntity())
  92.     {
  93.         int index = pRender->GetIClientUnknown()->GetIClientEntity()->entindex();
  94.         if ((index < engine->GetMaxClients()) && (index > 0))
  95.         {
  96.             team = TF2::BasePlayer::iTeamNum(pRender->GetIClientUnknown()->GetIClientEntity());
  97.             health = TF2::BasePlayer::iHealth(pRender->GetIClientUnknown()->GetIClientEntity());
  98.         }
  99.     }
  100.     else
  101.     {
  102.         team = 0;
  103.         health = 0;
  104.     }
  105.     //THIS PUSH IS ACTUALLY VERY IMPORTANT
  106.     __asm push 0
  107.     m_pTexture->Download(); // Force the regenerator to redraw
  108. }
Add Comment
Please, Sign In to add comment